From 7351aebe37781e121a19bc64af8159c6e6a5d715 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Tue, 26 Jan 2021 15:43:08 +0100 Subject: [PATCH 0001/1623] [nrf noup] ci: set `ZEPHYR__KCONFIG` for NCS modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit sets `ZEPHYR__KCONFIG` variable for each Kconfig file discovered in `nrf/modules//Kconfig`. This is not meant as a permanent solution; we should do more careful consideration on the optimal approach forward that will allow compliance_check.py to be used downstream with custom module_ext_roots, and at the same time keep current flexibility for module glue code handling intact. Signed-off-by: Torsten Rasmussen Signed-off-by: Martí Bolívar (cherry picked from commit c78a6eaec795464633b7fa68a8bc3a1ef4bf35c4) (cherry picked from commit 67e3d5e54b697a309b6095425d2fcb6971778dee) --- scripts/ci/check_compliance.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 8a70ffabeeb..74ddf19b2fb 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -310,6 +310,13 @@ def get_modules(self, modules_file): modules = [name for name in os.listdir(modules_dir) if os.path.exists(os.path.join(modules_dir, name, 'Kconfig'))] + nrf_modules_dir = ZEPHYR_BASE + '/../nrf/modules' + nrf_modules = [] + if os.path.exists(nrf_modules_dir): + nrf_modules = [name for name in os.listdir(nrf_modules_dir) if + os.path.exists(os.path.join(nrf_modules_dir, name, + 'Kconfig'))] + with open(modules_file, 'r') as fp_module_file: content = fp_module_file.read() @@ -319,6 +326,15 @@ def get_modules(self, modules_file): re.sub('[^a-zA-Z0-9]', '_', module).upper(), modules_dir + '/' + module + '/Kconfig' )) + for module in nrf_modules: + fp_module_file.write("ZEPHYR_{}_KCONFIG = {}\n".format( + re.sub('[^a-zA-Z0-9]', '_', module).upper(), + nrf_modules_dir + '/' + module + '/Kconfig' + )) + fp_module_file.write("NCS_{}_KCONFIG = {}\n".format( + re.sub('[^a-zA-Z0-9]', '_', module).upper(), + modules_dir + '/' + module + '/Kconfig' + )) fp_module_file.write(content) def get_kconfig_dts(self, kconfig_dts_file): From ed6a2048c3ab68de67b3fc37275fff453bfe5dfa Mon Sep 17 00:00:00 2001 From: Sebastian Wezel Date: Tue, 15 Mar 2022 13:12:25 +0100 Subject: [PATCH 0002/1623] [nrf noup] ci: add .github/test-spec.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This file is used for NCS-specific testing configuration based on modifications to files in this repository. Signed-off-by: Alperen Sener Signed-off-by: Dominik Ermel Signed-off-by: Elisabeth Solheim Klakken Signed-off-by: Mariusz Poslinski Signed-off-by: Markus Swarowsky Signed-off-by: Robert Lubos Signed-off-by: Sebastian Wezel Signed-off-by: Tomasz Tyzenhauz Signed-off-by: Fredrik Ås Signed-off-by: Michał Szablowski Signed-off-by: Tony Le Signed-off-by: Krishna T (cherry picked from commit 2a59fbdf425895a357fc6bff919d3108b6e35469) (cherry picked from commit acb96b140c95e933546acc41cc6df22b609342db) (cherry picked from commit e102ad15b3804c9d71447dda2bf4e321ec4185fb) (cherry picked from commit f9eac37be8ef89db5b2cbb06e38aef09e13fc448) --- .github/test-spec.yml | 147 ++++++++++++++++++++++++++++++++++++++++++ CODEOWNERS | 1 + 2 files changed, 148 insertions(+) create mode 100644 .github/test-spec.yml diff --git a/.github/test-spec.yml b/.github/test-spec.yml new file mode 100644 index 00000000000..3fe9ba5fbec --- /dev/null +++ b/.github/test-spec.yml @@ -0,0 +1,147 @@ +# This is the Jenkins ci variant of the .github/labler.yaml +"CI-iot-zephyr-lwm2m-test": + - "drivers/console/**/*" + - "drivers/flash/**/*" + - "subsys/dfu/boot/**/*" + - "subsys/net/ip/**/*" + - "subsys/net/lib/http/**/*" + - "subsys/net/lib/lwm2m//**/*" + - "subsys/net/**/*" + +"CI-iot-samples-test": + - "boards/arm/nrf9160dk_nrf9160/**/*" + - "dts/arm/nordic/nrf9160*" + - "include/net/**/*" + - "subsys/net/lib/**/*" + +"CI-iot-libraries-test": + - "boards/arm/nrf9160dk_nrf9160/**/*" + - "dts/arm/nordic/nrf9160*" + - "include/net/socket_ncs.h" + - "subsys/testsuite/ztest/**/*" + +"CI-lwm2m-test": + - "**/*" + +"CI-boot-dfu-test": + - "subsys/mgmt/mcumgr/**/*" + - "subsys/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "include/dfu/**/*" + - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" + +"CI-tfm-test": + - "**/*" + +"CI-ble-test": + - "**/*" + +"CI-mesh-test": + - "subsys/bluetooth/mesh/**/*" + - "include/bluetooth/mesh/**/*" + - "samples/bluetooth/mesh/**/*" + - "samples/bluetooth/mesh_demo/**/*" + - "samples/bluetooth/mesh_provisioner/**/*" + - "tests/bluetooth/mesh/**/*" + - "tests/bluetooth/mesh_shell/**/*" + +"CI-zigbee-test": + - "subsys/mgmt/mcumgr/**/*" + - "subsys/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "include/dfu/**/*" + +"CI-thingy91-test": + - "**/*" + +"CI-desktop-test": + - "**/*" + +"CI-crypto-test": + - "**/*" + +"CI-rs-test": + - "**/*" + +"CI-homekit-test": + - "include/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/dfu/**/*" + - "subsys/settings/**/*" + - "subsys/net/lib/openthread/**/*" + - "subsys/mgmt/mcumgr/**/*" + - "samples/hci_rpmsg/**/*" + - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" + - any: + - "subsys/bluetooth/**/*" + - "!subsys/bluetooth/mesh/**/*" + +"CI-thread-test": + - "**/*" + +"CI-nfc-test": + - "**/*" + +"CI-matter-test": + - "include/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/dfu/**/*" + - "subsys/settings/**/*" + - "subsys/net/**/*" + - "subsys/mgmt/mcumgr/**/*" + - "drivers/net/**/*" + - "samples/hci_rpmsg/**/*" + - any: + - "subsys/bluetooth/**/*" + - "!subsys/bluetooth/mesh/**/*" + - "!subsys/bluetooth/audio/**/*" + +"CI-find-my-test": + - "**/*" + +"CI-gazell-test": + - "**/*" + +"CI-rpc-test": + - "**/*" + +"CI-modemshell-test": + - "include/net/**/*" + - "include/posix/**/*" + - "include/shell/**/*" + - "drivers/net/**/*" + - "drivers/serial/**/*" + - "drivers/wifi/**/*" + - "subsys/shell/**/*" + - "subsys/net/**/*" + - "subsys/settings/**/*" + +"CI-positioning-test": + - "include/net/**/*" + - "include/posix/**/*" + - "drivers/net/**/*" + - "drivers/wifi/**/*" + - "subsys/net/**/*" + - "subsys/settings/**/*" + +"CI-cloud-test": + - "include/zephyr/dfu/**/*" + - "include/zephyr/net/**/*" + - "include/zephyr/posix/**/*" + - "include/zephyr/settings/**/*" + - "drivers/led/**/*" + - "drivers/net/**/*" + - "drivers/sensor/**/*" + - "drivers/serial/**/*" + - "drivers/wifi/**/*" + - "lib/posix/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/dfu/**/*" + - "subsys/net/**/*" + - "subsys/settings/**/*" + +"CI-wifi": + - "subsys/net/l2/wifi/**/*" + - "subsys/net/l2/ethernet/**/*" diff --git a/CODEOWNERS b/CODEOWNERS index 25cf3791114..a670048c779 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -14,6 +14,7 @@ # * @galak @nashif /.github/ @nashif @stephanosio +/.github/test-spec.yml @nrfconnect/ncs-test-leads /.github/workflows/ @galak @nashif /MAINTAINERS.yml @MaureenHelm /arch/arc/ @abrodkin @ruuddw @evgeniy-paltsev From 9b9ec58b0c575e15c57cb1e5de2d1c4ac5266a1f Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Fri, 30 Nov 2018 14:07:56 +0100 Subject: [PATCH 0003/1623] [nrf noup] ci: NCS-specific CI tweaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Necessary changes for NCS CI. - Add a Jenkinsfile - compliance.yml: Disable check for merge commits, since we have upmerges downstream. Add an additional check for sauce tags (details in scripts/gitlint) Also, since in the code we refer to Kconfig symbols that are defined in the sdk-nrf repository, the Kconfig checks (Kconfig and KconfigBasic) will not pass so exclude them. - Extend the max commit line lengths for Gitlint to account for sauce tags - Add a commit-tags workflow: This enables sauce tag checking in sdk-zephyr - scripts/gitlint: Add support for sauce tags checks. In order to not interfere with CI in other repos (namely sdk-nrf) this is run as an independent gitlint invocation and not as part of check_compliance.py. This invocation enables the ncs-sauce-tags rule and, since it runs before rebasing and thus will run on merge commits, disables the title-starts-with-subsystem rule by setting a catch-all regex. Signed-off-by: Carles Cufi Signed-off-by: Dominik Ermel Signed-off-by: Martí Bolívar Signed-off-by: Vinayak Kariappa Chettimada Signed-off-by: Krishna T (cherry picked from commit d34b035bcc569431b7008c72edc55db1b29bccf3) (cherry picked from commit 4a6d5fc57fe7589b2585ee5e44341f50821cc653) (cherry picked from commit a01c3a4caccb6964a29078172ba7f590bcdbe790) --- .github/workflows/commit-tags.yml | 31 +++++++++++++++++++++++++++++++ .github/workflows/compliance.yml | 8 ++++---- .gitlint | 4 ++-- Jenkinsfile | 5 +++++ 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/commit-tags.yml create mode 100644 Jenkinsfile diff --git a/.github/workflows/commit-tags.yml b/.github/workflows/commit-tags.yml new file mode 100644 index 00000000000..9e0323f9498 --- /dev/null +++ b/.github/workflows/commit-tags.yml @@ -0,0 +1,31 @@ +name: Commit tags + +on: pull_request + +jobs: + commit_tags: + runs-on: ubuntu-22.04 + name: Run commit tags checks on patch series (PR) + steps: + - name: Update PATH for west + run: | + echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: Checkout the code + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + + - name: Install python dependencies + run: | + pip3 install setuptools + pip3 install wheel + pip3 install gitlint + + - name: Run the commit tags + uses: nrfconnect/action-commit-tags@main + with: + target: '.' + baserev: origin/${{ github.base_ref }} + revrange: 'none' diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index f84faff3e4a..f17780c38e3 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -38,8 +38,8 @@ jobs: git config --global user.name "Your Name" git remote -v # Ensure there's no merge commits in the PR - [[ "$(git rev-list --merges --count origin/${BASE_REF}..)" == "0" ]] || \ - (echo "::error ::Merge commits not allowed, rebase instead";false) + #[[ "$(git rev-list --merges --count origin/${BASE_REF}..)" == "0" ]] || \ + #(echo "::error ::Merge commits not allowed, rebase instead";false) git rebase origin/${BASE_REF} # debug git log --pretty=oneline | head -n 10 @@ -56,8 +56,8 @@ jobs: # debug ls -la git log --pretty=oneline | head -n 10 - ./scripts/ci/check_compliance.py --annotate -e KconfigBasic \ - -c origin/${BASE_REF}.. + ./scripts/ci/check_compliance.py --annotate -e KconfigBasic -e Kconfig \ + -e KconfigBasicNoModules -c origin/${BASE_REF}.. - name: upload-results uses: actions/upload-artifact@v3 diff --git a/.gitlint b/.gitlint index b8d25ce49b9..8a33f140b2a 100644 --- a/.gitlint +++ b/.gitlint @@ -16,7 +16,7 @@ debug = false extra-path=scripts/gitlint [title-max-length-no-revert] -line-length=75 +line-length=120 [body-min-line-count] min-line-count=1 @@ -42,7 +42,7 @@ words=wip [max-line-length-with-exceptions] # B1 = body-max-line-length -line-length=75 +line-length=120 [body-min-length] min-length=3 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000000..3b9cf002239 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,5 @@ +@Library("CI_LIB") _ + +def pipeline = new ncs.sdk_zephyr.Main() + +pipeline.run(JOB_NAME) From 0f53ec25dcb9dc3fef27bcd024690ec69f3e85db Mon Sep 17 00:00:00 2001 From: Piotr Golyzniak Date: Mon, 1 Aug 2022 13:06:01 +0200 Subject: [PATCH 0004/1623] [nrf noup] ci: scripts: add quarantine file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add scripts/quarantine.yaml file, which will be used in CI. Signed-off-by: Piotr Golyzniak Signed-off-by: Andrzej Głąbek Signed-off-by: Maciej Perkowski Signed-off-by: Robert Lubos (cherry picked from commit d08f81fe56931040f77ce9a2f703bf445b0c0bdc) (cherry picked from commit 9a7ce33cfd8cfcbbf0ab2cedd8c94f09b9c4e9d2) (cherry picked from commit b1766970c8cf3309ef93597a52c6999a864883eb) (cherry picked from commit 1667b8f0abd8095b2593420e14ba3f4b68c33e59) --- scripts/quarantine.yaml | 88 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 scripts/quarantine.yaml diff --git a/scripts/quarantine.yaml b/scripts/quarantine.yaml new file mode 100644 index 00000000000..20c4f9248ea --- /dev/null +++ b/scripts/quarantine.yaml @@ -0,0 +1,88 @@ +# The configurations resulting as a product of scenarios and platforms +# will be skipped if quarantine is used. More details here: +# https://docs.zephyrproject.org/latest/guides/test/twister.html#quarantine + +- scenarios: + - testing.ztest.busy_sim + - testing.ztest.busy_sim_nrf52840dk_pin + platforms: + - nrf52840dk_nrf52840 + +# Already reported, but will not be fixed (look at the discussion): +# https://github.com/zephyrproject-rtos/zephyr/issues/44947 +- scenarios: + - libraries.cmsis_dsp.matrix.unary_f64 + platforms: + - nrf5340dk_nrf5340_cpunet + - qemu_cortex_m3 + comment: "Flash overflows" + +# Already reported, but will not be fixed (look at the discussion): +# https://github.com/zephyrproject-rtos/zephyr/issues/44947 +- scenarios: + - libraries.cmsis_dsp.matrix.binary_f16 + - libraries.cmsis_dsp.matrix.binary_f16.fpu + platforms: + - nrf5340dk_nrf5340_cpuapp_ns + comment: "Flash overflows" + +# Already reported, but will not be fixed (look at the discussion): +# https://github.com/zephyrproject-rtos/zephyr/issues/44947 +- scenarios: + - libraries.cmsis_dsp.matrix.binary_q15 + - libraries.cmsis_dsp.matrix.binary_q15.fpu + - libraries.cmsis_dsp.matrix.unary_f32 + - libraries.cmsis_dsp.matrix.unary_f32.fpu + - libraries.cmsis_dsp.matrix.unary_f64 + - libraries.cmsis_dsp.matrix.unary_f64.fpu + platforms: + - nrf5340dk_nrf5340_cpuapp_ns + - nrf9160dk_nrf9160_ns + comment: "Flash overflows" + +# libsdl2-dev package should be added into docker image +- scenarios: + - sample.boards.nrf.nrf_led_matrix + - sample.display.lvgl.gui + platforms: + - native_posix + comment: "libsdl2-dev package not available" + +- scenarios: + - sample.net.sockets.echo_server.usbnet + - sample.net.sockets.echo_server.usbnet_composite + platforms: + - nrf5340dk_nrf5340_cpuapp_ns + comment: "Ram/flash overflows, also in the upstream" + +- scenarios: + - sample.net.zperf.netusb_ecm + - sample.net.zperf.netusb_eem + - sample.net.zperf.netusb_rndis + platforms: + - nrf52833dk_nrf52833 + - nrf5340dk_nrf5340_cpuapp_ns + comment: "Ram/flash overflows, also in the upstream" + +- scenarios: + - net.mqtt.tls + platforms: + - nrf5340dk_nrf5340_cpuapp_ns + - nrf9160dk_nrf9160_ns + comment: "Ram/flash overflows, also in the upstream" + +- scenarios: + - kernel.common.picolibc + - libraries.picolibc + - libraries.libc.picolibc.mem_alloc + - libraries.picolibc.sprintf_new + platforms: + - nrf52dk_nrf52832 + comment: "Ram overflows, also in the upstream" + +- scenarios: + - sample.psa_crypto + platforms: + - nrf5340dk_nrf5340_cpuapp_ns + - nrf9160dk_nrf9160_ns + comment: "Due to using sdk-zephyr manifest instead of nrf. Should be fixed after the change" From 69bfcfb11e2be0951163506b689daa881a21c441 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 3 Mar 2022 15:28:16 +0100 Subject: [PATCH 0005/1623] [nrf noup] doc: remove Kconfig search Kconfig search is handled in a separate docset in NCS, so remove the page. This is a long-term noup patch. Signed-off-by: Gerard Marull-Paretas Signed-off-by: Krishna T (cherry picked from commit 89babe6a30bb3e5c4fa411168cd4135dbb99e70f) (cherry picked from commit fdbdd8017796455cba30971c153289aa17236b9b) (cherry picked from commit aa9e63340ee7824e1d9294eea4629e8dabd9ffd9) --- MAINTAINERS.yml | 1 - doc/build/kconfig/setting.rst | 6 ++---- doc/develop/application/index.rst | 5 ++--- doc/kconfig.rst | 8 -------- 4 files changed, 4 insertions(+), 16 deletions(-) delete mode 100644 doc/kconfig.rst diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 8d581406981..08ad5c8d61b 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -611,7 +611,6 @@ Documentation: - doc/images/Zephyr-Kite-in-tree.png - doc/index-tex.rst - doc/index.rst - - doc/kconfig.rst - doc/known-warnings.txt - doc/templates/sample.tmpl - doc/templates/board.tmpl diff --git a/doc/build/kconfig/setting.rst b/doc/build/kconfig/setting.rst index 2fd78ff463b..5f37e831e9e 100644 --- a/doc/build/kconfig/setting.rst +++ b/doc/build/kconfig/setting.rst @@ -7,8 +7,7 @@ The :ref:`menuconfig and guiconfig interfaces ` can be used to test out configurations during application development. This page explains how to make settings permanent. -All Kconfig options can be searched in the :ref:`Kconfig search page -`. +All Kconfig options can be searched in the Kconfig search page. .. note:: @@ -115,8 +114,7 @@ Assignments in configuration files are only respected if the dependencies for the symbol are satisfied. A warning is printed otherwise. To figure out what the dependencies of a symbol are, use one of the :ref:`interactive configuration interfaces ` (you can jump directly to a symbol with -:kbd:`/`), or look up the symbol in the :ref:`Kconfig search page -`. +:kbd:`/`), or look up the symbol in the Kconfig search page. .. _initial-conf: diff --git a/doc/develop/application/index.rst b/doc/develop/application/index.rst index 7307d6c572c..3fd971ad945 100644 --- a/doc/develop/application/index.rst +++ b/doc/develop/application/index.rst @@ -640,9 +640,8 @@ started. See :ref:`setting_configuration_values` for detailed documentation on setting Kconfig configuration values. The :ref:`initial-conf` section on the same page -explains how the initial configuration is derived. See :ref:`kconfig-search` -for a complete list of configuration options. -See :ref:`hardening` for security information related with Kconfig options. +explains how the initial configuration is derived. See :ref:`hardening` for +security information related with Kconfig options. The other pages in the :ref:`Kconfig section of the manual ` are also worth going through, especially if you planning to add new configuration diff --git a/doc/kconfig.rst b/doc/kconfig.rst deleted file mode 100644 index 1123de2adbd..00000000000 --- a/doc/kconfig.rst +++ /dev/null @@ -1,8 +0,0 @@ -:orphan: - -.. _kconfig-search: - -Kconfig Search -============== - -.. kconfig:search:: From 910bb5fe9e14e8afcf0c8b65c846e294821d693e Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Mon, 16 Jan 2023 14:15:22 +0100 Subject: [PATCH 0006/1623] [nrf noup] dts: choose cryptocell for entropy when available This is a long-term noup patch because driver support is NCS-only. Set HAS_HW_NRF_CC3XX to be defined in NS build when cryptocell is accessed through the PSA API. We need to know which CC3XX features are available. Signed-off-by: Georgios Vasilakis Signed-off-by: Joakim Andersson (cherry picked from commit c76cf8776d7bcbb7eef8023191a941f8e9410cb4) (cherry picked from commit 214533fa69601f52933977a39fff855d955c886f) (cherry picked from commit 3819c4ae701f0b4265bbd3409e37e5bba5c4abcb) --- dts/arm/nordic/nrf52840.dtsi | 2 +- dts/arm/nordic/nrf5340_cpuapp.dtsi | 2 +- dts/arm/nordic/nrf91.dtsi | 1 + soc/arm/nordic_nrf/Kconfig.peripherals | 6 ++++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index 8c89968c108..f4209c67d19 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -5,7 +5,7 @@ / { chosen { - zephyr,entropy = &rng; + zephyr,entropy = &cryptocell; zephyr,flash-controller = &flash_controller; }; diff --git a/dts/arm/nordic/nrf5340_cpuapp.dtsi b/dts/arm/nordic/nrf5340_cpuapp.dtsi index 7a32c5398db..1294203f00a 100644 --- a/dts/arm/nordic/nrf5340_cpuapp.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp.dtsi @@ -33,7 +33,7 @@ }; chosen { - zephyr,entropy = &rng_hci; + zephyr,entropy = &cryptocell; zephyr,flash-controller = &flash_controller; }; diff --git a/dts/arm/nordic/nrf91.dtsi b/dts/arm/nordic/nrf91.dtsi index d872680fb20..a2a490ab0b1 100644 --- a/dts/arm/nordic/nrf91.dtsi +++ b/dts/arm/nordic/nrf91.dtsi @@ -28,6 +28,7 @@ }; chosen { + zephyr,entropy = &cryptocell; zephyr,flash-controller = &flash_controller; }; diff --git a/soc/arm/nordic_nrf/Kconfig.peripherals b/soc/arm/nordic_nrf/Kconfig.peripherals index c7bfb552409..1645cf34ea0 100644 --- a/soc/arm/nordic_nrf/Kconfig.peripherals +++ b/soc/arm/nordic_nrf/Kconfig.peripherals @@ -13,10 +13,12 @@ config HAS_HW_NRF_BPROT def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_BPROT)) config HAS_HW_NRF_CC310 - def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_CC310)) + def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_CC310)) || \ + ($(dt_nodelabel_enabled,psa_rng) && SOC_SERIES_NRF91X) config HAS_HW_NRF_CC312 - def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_CC312)) + def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_CC312)) || \ + ($(dt_nodelabel_enabled,psa_rng) && SOC_NRF5340_CPUAPP) config HAS_HW_NRF_CCM def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_CCM)) From 8e9c90fce4c36d8ba326e34a5e4fab4ce0c86f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Audun=20Kvamtr=C3=B8?= Date: Tue, 30 Nov 2021 09:41:05 +0100 Subject: [PATCH 0007/1623] [nrf noup] modules: mbedtls: add PSA configurations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -Adds Kconfig.psa -Add standardized algorithms, curve types etc as Kconfig variables -Add configurations for internal logic to see if a feature is enabled by PSA_WANTS_XXX ref: NCSDK-11689 ref: NCSDK-17840 ref: NCSDK-17840 Signed-off-by: Frank Audun Kvamtrø Signed-off-by: Joakim Andersson (cherry picked from commit c913e3aaa7c59737c9f25a7c58cfbb20503f791c) (cherry picked from commit 6ae8ab054126778fcc0054d5243580e72197359c) (cherry picked from commit a7d1b3ddd1b740db3e04e967e12bfdf6e76e4d48) --- drivers/entropy/Kconfig.psa_crypto | 1 + modules/mbedtls/Kconfig | 5 +- modules/mbedtls/Kconfig.psa | 484 +++++++++++++++++++++++++++++ 3 files changed, 489 insertions(+), 1 deletion(-) create mode 100644 modules/mbedtls/Kconfig.psa diff --git a/drivers/entropy/Kconfig.psa_crypto b/drivers/entropy/Kconfig.psa_crypto index 50f31509004..455a2c9b55b 100644 --- a/drivers/entropy/Kconfig.psa_crypto +++ b/drivers/entropy/Kconfig.psa_crypto @@ -8,6 +8,7 @@ config ENTROPY_PSA_CRYPTO_RNG depends on BUILD_WITH_TFM depends on DT_HAS_ZEPHYR_PSA_CRYPTO_RNG_ENABLED select ENTROPY_HAS_DRIVER + select PSA_WANT_GENERATE_RANDOM default y help Enable the PSA Crypto source Entropy driver. diff --git a/modules/mbedtls/Kconfig b/modules/mbedtls/Kconfig index 67277fb24c4..6e59709323e 100644 --- a/modules/mbedtls/Kconfig +++ b/modules/mbedtls/Kconfig @@ -5,6 +5,7 @@ config ZEPHYR_MBEDTLS_MODULE bool + config MBEDTLS_PROMPTLESS bool help @@ -13,7 +14,6 @@ config MBEDTLS_PROMPTLESS mbed TLS menu prompt and instead handle the selection of MBEDTLS from dependent sub-configurations and thus prevent stuck symbol behavior. - menuconfig MBEDTLS bool "mbed TLS Support" if !MBEDTLS_PROMPTLESS help @@ -233,3 +233,6 @@ config APP_LINK_WITH_MBEDTLS issues for 'app'. endif # MBEDTLS + +# Add PSA configurations +rsource "Kconfig.psa" diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa new file mode 100644 index 00000000000..399d18a3797 --- /dev/null +++ b/modules/mbedtls/Kconfig.psa @@ -0,0 +1,484 @@ +# +# Copyright (c) 2022 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 +# +menu "PSA RNG support" + +config PSA_WANT_GENERATE_RANDOM + bool + prompt "PSA RNG support" + help + Provide random number generator (RNG) support. + +config PSA_WANT_ALG_CTR_DRBG + bool + prompt "PSA RNG using CTR-DRBG as PRNG" + help + Provide random number generator (RNG) using CTR-DRBG as the + pseudo-random number generator (PRNG), seeded by a true random + number generator (TRNG). + +config PSA_WANT_ALG_HMAC_DRBG + bool + prompt "PSA RNG using HMAC-DRBG as PRNG" + help + Provide random number generator (RNG) using HMAC-DRBG as the + pseudo-random number generator (PRNG), seeded by a true random + number generator (TRNG). + +endmenu # RNG support + +menu "PSA key type support" + +config PSA_HAS_KEY_SUPPORT + bool + default y + depends on PSA_WANT_KEY_TYPE_DERIVE || \ + PSA_WANT_KEY_TYPE_HMAC || \ + PSA_WANT_KEY_TYPE_RAW_DATA || \ + PSA_WANT_KEY_TYPE_PASSWORD || \ + PSA_WANT_KEY_TYPE_PASSWORD_HASH || \ + PSA_WANT_KEY_TYPE_PEPPER || \ + PSA_WANT_KEY_TYPE_AES || \ + PSA_WANT_KEY_TYPE_CHACHA20 || \ + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR || \ + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY || \ + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR || \ + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY || \ + PSA_WANT_KEY_TYPE_DH_KEY_PAIR || \ + PSA_WANT_KEY_TYPE_DH_KEY_PAIR + +config PSA_WANT_KEY_TYPE_DERIVE + bool "PSA derive key type support" + help + This key type is for high-entropy secrets only. + For low-entropy secrets, password key type should be used instead. + +config PSA_WANT_KEY_TYPE_RAW_DATA + bool "PSA raw data key type support" + help + A "key" of this type cannot be used for any cryptographic operation. + Applications can use this type to store arbitrary data in the keystore. + +config PSA_WANT_KEY_TYPE_HMAC + bool "PSA HMAC key type support" + help + HMAC key. + +config PSA_WANT_KEY_TYPE_PASSWORD + bool "PSA password key type support" + help + A low-entropy secret for password hashing or key derivation. + +config PSA_WANT_KEY_TYPE_PASSWORD_HASH + bool "PSA password hash key type support" + help + A secret value that can be used to verify a password hash. + +config PSA_WANT_KEY_TYPE_PEPPER + bool "PSA pepper key type support" + help + A secret value that can be used when computing a password hash. + +config PSA_WANT_KEY_TYPE_AES + bool "PSA AES key type support" + help + Key for cipher, AEAD or MAC algorithm based on the AES block cipher. + +config PSA_WANT_KEY_TYPE_CHACHA20 + bool "PSA ChaCha20 key type support" + default y + depends on PSA_WANT_ALG_CHACHA20_POLY1305 || \ + PSA_WANT_ALG_STREAM_CIPHER + help + Key for the ChaCha20 stream cipher or the ChaCha20-Poly1305 AEAD algorithm. + +config PSA_WANT_KEY_TYPE_ECC_KEY_PAIR + bool "PSA ECC key pair support" + select PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY + help + Elliptic curve key pair: both the private and public key. + +config PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY + bool "PSA ECC public key support" + help + Elliptic curve public key. + +config PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + bool "PSA RSA key pair type support" + select PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + help + RSA key pair: both the private and public key. + +config PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + bool "PSA RSA public key support" + help + RSA public key. + +config PSA_WANT_KEY_TYPE_DH_KEY_PAIR + bool "PSA DH key pair type support" + select PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY + help + Finite-field Diffie-Hellman key pair: both the private key and public key. + +config PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY + bool "PSA DH public key support" + help + Finite-field Diffie-Hellman public key. + +endmenu # PSA Key type support + +menu "PSA AEAD support" + +config PSA_HAS_AEAD_SUPPORT + bool + default y + depends on PSA_WANT_ALG_CCM || \ + PSA_WANT_ALG_CCM_STAR_NO_TAG || \ + PSA_WANT_ALG_GCM || \ + PSA_WANT_ALG_CHACHA20_POLY1305 + help + Prompt-less configuration that states that AEAD is supported. + +config PSA_WANT_ALG_CCM + bool + prompt "PSA CCM support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_CCM_STAR_NO_TAG + bool + prompt "PSA AES CCM star with no tag support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_GCM + bool + prompt "PSA GCM support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_CHACHA20_POLY1305 + bool + prompt "PSA ChaCha20-Poly1305 support" if !PSA_PROMPTLESS + +endmenu # PSA AEAD support + + +menu "PSA MAC support" + +config PSA_HAS_MAC_SUPPORT + bool + default y + depends on PSA_WANT_ALG_CBC_MAC || \ + PSA_WANT_ALG_CMAC || \ + PSA_WANT_ALG_HMAC + help + Prompt-less configuration that states that MAC is supported. + +config PSA_WANT_ALG_CBC_MAC + bool + help + CBC-MAC is not yet supported via the PSA API in Mbed TLS. + +config PSA_WANT_ALG_CMAC + bool + prompt "PSA CMAC support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_HMAC + bool + prompt "PSA HMAC support" if !PSA_PROMPTLESS + +endmenu # PSA MAC support + + +menu "PSA Hash support" + +config PSA_HAS_HASH_SUPPORT + bool + default y + depends on PSA_WANT_ALG_SHA_1 || \ + PSA_WANT_ALG_SHA_224 || \ + PSA_WANT_ALG_SHA_256 || \ + PSA_WANT_ALG_SHA_384 || \ + PSA_WANT_ALG_SHA_512 || \ + PSA_WANT_ALG_RIPEMD160 || \ + PSA_WANT_ALG_MD5 + help + Prompt-less configuration that states that hash is supported. + +config PSA_WANT_ALG_SHA_1 + bool + prompt "PSA SHA-1 support (weak)" if !PSA_PROMPTLESS + help + Warning: The SHA-1 hash is weak and deprecated and is only recommended + for use in legacy protocols. + +config PSA_WANT_ALG_SHA_224 + bool + prompt "PSA SHA-224 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SHA_256 + bool + prompt "PSA SHA-256 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SHA_384 + bool + prompt "PSA SHA-384 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SHA_512 + bool + prompt "PSA SHA-512 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_RIPEMD160 + bool + prompt "PSA RIPEMD-160 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_MD5 + bool + prompt "PSA MD5 support (weak)" if !PSA_PROMPTLESS + help + Warning: The MD5 hash is weak and deprecated and is only recommended + for use in legacy protocols. + +endmenu # PSA Hash support + +menu "PSA Cipher support" + +config PSA_HAS_CIPHER_SUPPORT + bool + default y + depends on PSA_WANT_ALG_ECB_NO_PADDING || \ + PSA_WANT_ALG_CBC_NO_PADDING || \ + PSA_WANT_ALG_CBC_PKCS7 || \ + PSA_WANT_ALG_CFB || \ + PSA_WANT_ALG_CTR || \ + PSA_WANT_ALG_OFB || \ + PSA_WANT_ALG_CTR || \ + PSA_WANT_ALG_XTS || \ + PSA_WANT_ALG_STREAM_CIPHER + help + Prompt-less configuration that states that cipher is supported. + +config PSA_WANT_ALG_ECB_NO_PADDING + bool + prompt "PSA ECB block cipher mode support (with no padding)" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_CBC_NO_PADDING + bool + prompt "PSA CBC block cipher mode support (with no padding)" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_CBC_PKCS7 + bool + prompt "PSA CBC block cipher mode support (with PKCS#7 padding)" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_CFB + bool + prompt "PSA stream cipher using CFB block cipher mode support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_CTR + bool + prompt "PSA stream cipher using CTR block cipher mode support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_OFB + bool + prompt "PSA stream cipher using OFB block cipher mode support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_XTS + bool + prompt "PSA XTS block cipher mode support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_STREAM_CIPHER + bool + prompt "PSA stream cipher support" if !PSA_PROMPTLESS + +endmenu # PSA Cipher Support + + +menu "PSA Key derivation support" + +config PSA_HAS_KEY_DERIVATION + bool + default y + depends on PSA_WANT_ALG_HKDF || \ + PSA_WANT_ALG_HKDF_EXPAND || \ + PSA_WANT_ALG_HKDF_EXTRACT || \ + PSA_WANT_ALG_PBKDF2_HMAC || \ + PSA_WANT_ALG_TLS12_PRF || \ + PSA_WANT_ALG_TLS12_PSK_TO_MS + help + Prompt-less configuration that states that key derivation is supported. + +config PSA_WANT_ALG_HKDF + bool + prompt "PSA HKDF support" if !PSA_PROMPTLESS + depends on PSA_WANT_ALG_HMAC + +config PSA_WANT_ALG_HKDF_EXTRACT + bool + prompt "PSA HKDF extract support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_HKDF_EXPAND + bool + prompt "PSA HKDF expand support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_PBKDF2_HMAC + bool + depends on PSA_WANT_ALG_HMAC + help + PBKDF2-HMAC is not yet supported via the PSA APIs in Mbed TLS. + +config PSA_WANT_ALG_TLS12_PRF + bool + prompt "PSA PRF support (TLS1.2)" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_TLS12_PSK_TO_MS + bool + prompt "PSA TLS 1.2 PSK to MS support" if !PSA_PROMPTLESS + +endmenu # PSA Key derivation support + + +menu "PSA Asymmetric support" + +config PSA_HAS_ASYM_ENCRYPT_SUPPORT + bool + default y + depends on PSA_WANT_ALG_RSA_OAEP || \ + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + help + Prompt-less configuration that states that asymmetric encryption + is supported. + + +config PSA_HAS_ASYM_SIGN_SUPPORT + bool + default y + depends on PSA_WANT_ALG_DETERMINISTIC_ECDSA || \ + PSA_WANT_ALG_ECDSA || \ + PSA_WANT_ALG_RSA_PKCS1V15_SIGN || \ + PSA_WANT_ALG_RSA_PSS + help + Prompt-less configuration that states that asymmetric signing + is supported. + +config PSA_HAS_ECC_SUPPORT + bool + depends on PSA_WANT_ALG_ECDH || \ + PSA_WANT_ALG_ECDSA || \ + PSA_WANT_ALG_DETERMINISTIC_ECDSA || \ + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR || \ + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY + default y + help + Prompt-less configuration that states that ECC is supported. + +config PSA_WANT_ALG_ECDH + bool + prompt "PSA ECDH support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_ECDSA + bool + prompt "PSA ECDSA support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_DETERMINISTIC_ECDSA + bool + prompt "PSA ECDSA support (deterministic mode)" if !PSA_PROMPTLESS + +menu "Elliptic Curve type support" + depends on PSA_HAS_ECC_SUPPORT + +config PSA_WANT_ECC_BRAINPOOL_P_R1_256 + bool + prompt "PSA ECC Brainpool256r1 support" + +config PSA_WANT_ECC_BRAINPOOL_P_R1_384 + bool "PSA ECC Brainpool384r1 support" + +config PSA_WANT_ECC_BRAINPOOL_P_R1_512 + bool "PSA ECC Brainpool512r1 support" + +config PSA_WANT_ECC_MONTGOMERY_255 + bool "PSA ECC Curve25519 (X25519) support" + +config PSA_WANT_ECC_MONTGOMERY_448 + bool "PSA ECC Curve448 (X448) support" + +config PSA_WANT_ECC_TWISTED_EDWARDS_255 + bool "PSA ECC Edwards25519 (Ed25519) support" + +config PSA_WANT_ECC_SECP_K1_192 + bool "PSA ECC secp192k1 support" + +config PSA_WANT_ECC_SECP_K1_224 + bool + help + SECP224K1 is buggy via the PSA API in Mbed TLS + See https://github.com/ARMmbed/mbedtls/issues/3541 + +config PSA_WANT_ECC_SECP_K1_256 + bool + prompt "PSA ECC secp256k1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECP_R1_192 + bool + prompt "PSA ECC secp192r1" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECP_R1_224 + bool + prompt "PSA ECC secp224r1" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECP_R1_256 + bool + prompt "PSA ECC secp256r1" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECP_R1_384 + bool + prompt "PSA ECC secp384r1" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECP_R1_521 + bool + prompt "PSA ECC secp521r1" if !PSA_PROMPTLESS + +endmenu # Elliptic Curve type support + +config PSA_HAS_RSA_SUPPORT + bool + depends on PSA_WANT_ALG_RSA_OAEP || \ + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT || \ + PSA_WANT_ALG_RSA_PKCS1V15_SIGN || \ + PSA_WANT_ALG_RSA_PSS || \ + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR || \ + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + default y + help + Prompt-less configuration that states that RSA is supported. + +config PSA_WANT_ALG_RSA_OAEP + bool + prompt "PSA RSA OAEP support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + bool + prompt "PSA RSA crypt support (PKCS#1 v1.5 mode)" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_RSA_PKCS1V15_SIGN + bool + prompt "PSA RSA signature support (PKCS#1 v1.5 mode)" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_RSA_PSS + bool + prompt "PSA RSA (PSS mode)" if !PSA_PROMPTLESS + +endmenu # PSA Asymmetric support + +config PSA_WANT_ALG_JPAKE + bool + prompt "PSA EC J-PAKE support" if !PSA_PROMPTLESS + select EXPERIMENTAL + +config PSA_WANT_ALG_SPAKE2P + bool + prompt "PSA SPAKE2+ support" if !PSA_PROMPTLESS + select EXPERIMENTAL + +config PSA_WANT_ALG_SRP + bool + prompt "PSA SRP support" if !PSA_PROMPTLESS + default n + select EXPERIMENTAL From 746136896ba8cb66f41742690e1021e7e83c0997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Sat, 29 Jan 2022 13:03:08 +0100 Subject: [PATCH 0008/1623] [nrf noup] modules: mbedtls: Allow MBEDTLS_BUILTIN to be deselected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Out-of-tree crypto subsystems need to deselect MBEDTLS_BUILTIN, but deselection is not supported. It is however supported to select a dependency in a ! expression. Signed-off-by: Sebastian Bøe (cherry picked from commit d2eb105082a6df51584e6cd49838cce7ac39d20c) (cherry picked from commit 1a12d6cd21e3dc31472694881a027e19b3283db2) --- modules/mbedtls/Kconfig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/mbedtls/Kconfig b/modules/mbedtls/Kconfig index 6e59709323e..2a05ee28d36 100644 --- a/modules/mbedtls/Kconfig +++ b/modules/mbedtls/Kconfig @@ -27,6 +27,7 @@ choice MBEDTLS_IMPLEMENTATION config MBEDTLS_BUILTIN bool "Use Zephyr in-tree mbedTLS version" + depends on ! DISABLE_MBEDTLS_BUILTIN help Link with mbedTLS sources included with Zephyr distribution. Included mbedTLS version is well integrated with and supported @@ -40,6 +41,11 @@ config MBEDTLS_LIBRARY endchoice +# subsystems cannot deselect MBEDTLS_BUILTIN, but they can select +# DISABLE_MBEDTLS_BUILTIN. +config DISABLE_MBEDTLS_BUILTIN + bool + config CUSTOM_MBEDTLS_CFG_FILE bool "Custom mbed TLS configuration file" help From 77360dd3f121c37f9df9399ff2c5c0b09d50c8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Audun=20Kvamtr=C3=B8?= Date: Thu, 13 Jan 2022 11:37:18 +0100 Subject: [PATCH 0009/1623] [nrf noup] modules: tf-m: use of PSA_HAS_XXXX_SUPPORT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -This allows configurations enabled by PSA_WANTS_ALG_XXXX to be used to control which TF-M module is enabled -If the TF-M image doesn't support e.g. the MAC APIs, then the MAC interface is not enabled Note: This functionality requires that nrf_security is enabled ref: NCSDK-11689 Signed-off-by: Frank Audun Kvamtrø (cherry picked from commit 55015d61ea589ab77987c3e74d9d2c8ed73d1590) (cherry picked from commit 4ab6d30e95770e5dabc601d5a491733a097a763b) --- modules/trusted-firmware-m/Kconfig.tfm.crypto_modules | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules b/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules index 1d70a2c44d2..89893686143 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules +++ b/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules @@ -17,6 +17,7 @@ config TFM_CRYPTO_RNG_MODULE_ENABLED config TFM_CRYPTO_KEY_MODULE_ENABLED bool "KEY crypto module" default y + depends on PSA_HAS_KEY_SUPPORT && NRF_SECURITY help Enables the KEY crypto module within the crypto partition. Unset this option if the functionality provided by 'crypto_key_management.c' @@ -25,6 +26,7 @@ config TFM_CRYPTO_KEY_MODULE_ENABLED config TFM_CRYPTO_AEAD_MODULE_ENABLED bool "AEAD crypto module" default y + depends on PSA_HAS_AEAD_SUPPORT && NRF_SECURITY help Enables the AEAD crypto module within the crypto partition. Unset this option if the functionality provided by 'crypto_aead.c' @@ -33,6 +35,7 @@ config TFM_CRYPTO_AEAD_MODULE_ENABLED config TFM_CRYPTO_MAC_MODULE_ENABLED bool "MAC crypto module" default y + depends on PSA_HAS_MAC_SUPPORT && NRF_SECURITY help Enables the MAC crypto module within the crypto partition. Unset this option if the functionality provided by 'crypto_mac.c' @@ -41,6 +44,7 @@ config TFM_CRYPTO_MAC_MODULE_ENABLED config TFM_CRYPTO_HASH_MODULE_ENABLED bool "HASH crypto module" default y + depends on PSA_HAS_HASH_SUPPORT && NRF_SECURITY help Enables the HASH crypto module within the crypto partition. Unset this option if the functionality provided by 'crypto_hash.c' @@ -49,6 +53,7 @@ config TFM_CRYPTO_HASH_MODULE_ENABLED config TFM_CRYPTO_CIPHER_MODULE_ENABLED bool "CIPHER crypto module" default y + depends on PSA_HAS_CIPHER_SUPPORT && NRF_SECURITY help Enables the CIPHER crypto module within the crypto partition. Unset this option if the functionality provided by 'crypto_cipher.c' @@ -57,6 +62,7 @@ config TFM_CRYPTO_CIPHER_MODULE_ENABLED config TFM_CRYPTO_ASYM_ENCRYPT_MODULE_ENABLED bool "ASYM ENCRYPT crypto module" default y + depends on PSA_HAS_ASYM_ENCRYPT_SUPPORT && NRF_SECURITY help Enables the ASYM ENCRYPT crypto module within the crypto partition. Unset this option if the encrypt functionality provided by 'crypto_asymmetric.c' @@ -65,6 +71,7 @@ config TFM_CRYPTO_ASYM_ENCRYPT_MODULE_ENABLED config TFM_CRYPTO_ASYM_SIGN_MODULE_ENABLED bool "ASYM SIGN crypto module" default y + depends on PSA_HAS_ASYM_SIGN_SUPPORT && NRF_SECURITY help Enables the ASYM SIGN crypto module within the crypto partition. Unset this option if the sign functionality provided by 'crypto_asymmetric.c' @@ -73,6 +80,7 @@ config TFM_CRYPTO_ASYM_SIGN_MODULE_ENABLED config TFM_CRYPTO_KEY_DERIVATION_MODULE_ENABLED bool "KEY DERIVATION crypto module" default y + depends on PSA_HAS_KEY_DERIVATION && NRF_SECURITY help Enables the KEY_DERIVATION crypto module within the crypto partition. Unset this option if the functionality provided by 'crypto_key_derivation.c' From 05e424a60315d7083c1b2c3391010b54bd42443a Mon Sep 17 00:00:00 2001 From: Jan Tore Guggedal Date: Mon, 18 May 2020 20:50:13 +0200 Subject: [PATCH 0010/1623] [nrf noup] net: mqtt: Provide option to enable TLS session caching Provides an option to enable TLS session caching for an MQTT client's secure socket. Signed-off-by: Jan Tore Guggedal Signed-off-by: Robert Lubos Signed-off-by: Dominik Ermel Signed-off-by: Johann Fischer (cherry picked from commit 97e75e91a3ffaa585c69052c14134f13ea9c54fc) (cherry picked from commit 60fed8dbcb765eea06cd02fc2e080fa77a3c7310) --- include/zephyr/net/mqtt.h | 3 +++ subsys/net/lib/mqtt/mqtt_transport_socket_tls.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/zephyr/net/mqtt.h b/include/zephyr/net/mqtt.h index 1980b95bbea..b28e9e87612 100644 --- a/include/zephyr/net/mqtt.h +++ b/include/zephyr/net/mqtt.h @@ -356,6 +356,9 @@ struct mqtt_sec_config { /** Indicates the list of security tags to be used for the session. */ sec_tag_t *sec_tag_list; + /** Indicates the preference for enabling TLS session caching. */ + int session_cache; + /** Peer hostname for ceritificate verification. * May be NULL to skip hostname verification. */ diff --git a/subsys/net/lib/mqtt/mqtt_transport_socket_tls.c b/subsys/net/lib/mqtt/mqtt_transport_socket_tls.c index c835656b6cf..363ff51afef 100644 --- a/subsys/net/lib/mqtt/mqtt_transport_socket_tls.c +++ b/subsys/net/lib/mqtt/mqtt_transport_socket_tls.c @@ -78,6 +78,16 @@ int mqtt_client_tls_connect(struct mqtt_client *client) } } + if (tls_config->session_cache == TLS_SESSION_CACHE_ENABLED) { + ret = zsock_setsockopt(client->transport.tls.sock, SOL_TLS, + TLS_SESSION_CACHE, + &tls_config->session_cache, + sizeof(tls_config->session_cache)); + if (ret < 0) { + goto error; + } + } + if (tls_config->cert_nocopy != TLS_CERT_NOCOPY_NONE) { ret = zsock_setsockopt(client->transport.tls.sock, SOL_TLS, TLS_CERT_NOCOPY, &tls_config->cert_nocopy, From 63940d988b3879983d2c36270e703422c5dd7d05 Mon Sep 17 00:00:00 2001 From: Mirko Covizzi Date: Thu, 10 Mar 2022 00:25:50 -0800 Subject: [PATCH 0011/1623] [nrf noup] net: mqtt: add native TLS support This commit adds an extra parameter in the configuration structure to configure native TLS support at runtime. Signed-off-by: Mirko Covizzi (cherry picked from commit a719cd235202700bf2a874abce66a41fe715954e) (cherry picked from commit 30140d610d67a52e7ed830b81f042be696fe74b6) --- doc/connectivity/networking/api/mqtt.rst | 3 +++ include/zephyr/net/mqtt.h | 3 +++ subsys/net/lib/mqtt/mqtt_transport_socket_tls.c | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/connectivity/networking/api/mqtt.rst b/doc/connectivity/networking/api/mqtt.rst index b1090c8d394..dcc71e3320b 100644 --- a/doc/connectivity/networking/api/mqtt.rst +++ b/doc/connectivity/networking/api/mqtt.rst @@ -149,6 +149,7 @@ additional configuration information: tls_config->sec_tag_list = m_sec_tags; tls_config->sec_tag_count = ARRAY_SIZE(m_sec_tags); tls_config->hostname = MQTT_BROKER_HOSTNAME; + tls_config->set_native_tls = true; In this sample code, the ``m_sec_tags`` array holds a list of tags, referencing TLS credentials that the MQTT library should use for authentication. We do not specify @@ -161,6 +162,8 @@ Note, that TLS credentials referenced by the ``m_sec_tags`` array must be registered in the system first. For more information on how to do that, refer to :ref:`secure sockets documentation `. +Finally, ``set_native_tls`` can be optionally set to enable native TLS support instead of offloading TLS operations to the modem. + An example of how to use TLS with MQTT is also present in :ref:`mqtt-publisher-sample`. diff --git a/include/zephyr/net/mqtt.h b/include/zephyr/net/mqtt.h index b28e9e87612..ecdefea120b 100644 --- a/include/zephyr/net/mqtt.h +++ b/include/zephyr/net/mqtt.h @@ -366,6 +366,9 @@ struct mqtt_sec_config { /** Indicates the preference for copying certificates to the heap. */ int cert_nocopy; + + /** Set socket to native TLS */ + bool set_native_tls; }; /** @brief MQTT transport type. */ diff --git a/subsys/net/lib/mqtt/mqtt_transport_socket_tls.c b/subsys/net/lib/mqtt/mqtt_transport_socket_tls.c index 363ff51afef..8e9cc87239a 100644 --- a/subsys/net/lib/mqtt/mqtt_transport_socket_tls.c +++ b/subsys/net/lib/mqtt/mqtt_transport_socket_tls.c @@ -22,10 +22,15 @@ int mqtt_client_tls_connect(struct mqtt_client *client) { const struct sockaddr *broker = client->broker; struct mqtt_sec_config *tls_config = &client->transport.tls.config; + int type = SOCK_STREAM; int ret; + if (tls_config->set_native_tls) { + type |= SOCK_NATIVE_TLS; + } + client->transport.tls.sock = zsock_socket(broker->sa_family, - SOCK_STREAM, IPPROTO_TLS_1_2); + type, IPPROTO_TLS_1_2); if (client->transport.tls.sock < 0) { return -errno; } From a3139d834c6bd8ee1228ec5f054661683f21612a Mon Sep 17 00:00:00 2001 From: Kamil Piszczek Date: Fri, 18 Mar 2022 14:46:42 +0100 Subject: [PATCH 0012/1623] [nrf noup] ipc: backends: rpmsg: initialize shared memory to zero Added a code for initializing shared memory to zero. This operation normalizes the memory state so that the IPC service is no longer prone to reading status bits from the previous reset session. Signed-off-by: Kamil Piszczek Signed-off-by: Dominik Ermel (cherry picked from commit 5e850cf31fc07d3e9f8042bb45845c4ad17d949a) (cherry picked from commit 22a279bf1d28f83ae9ea6bc4a5e0bf7e04e7589f) --- .../backends/ipc_rpmsg_static_vrings.c | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c b/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c index 41f0a77ea22..5d04d029e8c 100644 --- a/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c +++ b/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c @@ -774,8 +774,8 @@ static int backend_init(const struct device *instance) return 0; } -#define DEFINE_BACKEND_DEVICE(i) \ - static struct backend_config_t backend_config_##i = { \ +#define BACKEND_CONFIG_POPULATE(i) \ + { \ .role = DT_ENUM_IDX_OR(DT_DRV_INST(i), role, ROLE_HOST), \ .shm_size = DT_REG_SIZE(DT_INST_PHANDLE(i, memory_region)), \ .shm_addr = DT_REG_ADDR(DT_INST_PHANDLE(i, memory_region)), \ @@ -790,8 +790,10 @@ static int backend_init(const struct device *instance) .buffer_size = DT_INST_PROP_OR(i, zephyr_buffer_size, \ RPMSG_BUFFER_SIZE), \ .id = i, \ - }; \ - \ + } + +#define BACKEND_DEVICE_DEFINE(i) \ + static struct backend_config_t backend_config_##i = BACKEND_CONFIG_POPULATE(i); \ static struct backend_data_t backend_data_##i; \ \ DEVICE_DT_INST_DEFINE(i, \ @@ -803,20 +805,23 @@ static int backend_init(const struct device *instance) CONFIG_IPC_SERVICE_REG_BACKEND_PRIORITY, \ &backend_ops); -DT_INST_FOREACH_STATUS_OKAY(DEFINE_BACKEND_DEVICE) +DT_INST_FOREACH_STATUS_OKAY(BACKEND_DEVICE_DEFINE) -#define BACKEND_CONFIG_INIT(n) &backend_config_##n, +#define BACKEND_CONFIG_DEFINE(i) BACKEND_CONFIG_POPULATE(i), #if defined(CONFIG_IPC_SERVICE_BACKEND_RPMSG_SHMEM_RESET) static int shared_memory_prepare(void) { - static const struct backend_config_t *config[] = { - DT_INST_FOREACH_STATUS_OKAY(BACKEND_CONFIG_INIT) + const struct backend_config_t *backend_config; + const struct backend_config_t backend_configs[] = { + DT_INST_FOREACH_STATUS_OKAY(BACKEND_CONFIG_DEFINE) }; - for (int i = 0; i < DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT); i++) { - if (config[i]->role == ROLE_HOST) { - memset((void *) config[i]->shm_addr, 0, VDEV_STATUS_SIZE); + for (backend_config = backend_configs; + backend_config < backend_configs + ARRAY_SIZE(backend_configs); + backend_config++) { + if (backend_config->role == ROLE_HOST) { + memset((void *) backend_config->shm_addr, 0, VDEV_STATUS_SIZE); } } From 5f2514e36a2b5da0fb2a477bb92fec23d88519f2 Mon Sep 17 00:00:00 2001 From: Azizah Ibrahim Date: Wed, 7 Apr 2021 13:03:19 +0100 Subject: [PATCH 0013/1623] [nrf noup] samples: bluetooth: hci_pwr_ctrl: add dynamic control Enable dynamic power control in hci_pwr_ctrl sample for platforms using hci_rpmsg as controller Signed-off-by: Azizah Ibrahim Signed-off-by: Trond Einar Snekvik (cherry picked from commit 14f6d9c0682df75df177253797bb5c904860e632) (cherry picked from commit cda81c03ba45ec242fac84666759ec360968aa29) --- samples/bluetooth/hci_pwr_ctrl/child_image/hci_rpmsg.conf | 1 + 1 file changed, 1 insertion(+) create mode 100644 samples/bluetooth/hci_pwr_ctrl/child_image/hci_rpmsg.conf diff --git a/samples/bluetooth/hci_pwr_ctrl/child_image/hci_rpmsg.conf b/samples/bluetooth/hci_pwr_ctrl/child_image/hci_rpmsg.conf new file mode 100644 index 00000000000..e6749ae6399 --- /dev/null +++ b/samples/bluetooth/hci_pwr_ctrl/child_image/hci_rpmsg.conf @@ -0,0 +1 @@ +CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y From 51f1731ef438b20bffa00c56c0fdd19fb8118a1a Mon Sep 17 00:00:00 2001 From: Kamil Piszczek Date: Mon, 20 Jun 2022 10:14:39 +0200 Subject: [PATCH 0014/1623] [nrf noup] samples: mgmt: mcumgr: add hci_rpmsg child image config Added a configuration file for the HCI RPMsg child image that is necessary for multi-core targets. Signed-off-by: Kamil Piszczek (cherry picked from commit 761f5fd8491635bb3a72006d83a2071c7c379b1f) (cherry picked from commit 5689592f52a43cd26d1d5ae3fb6e662a5cf98780) --- .../mgmt/mcumgr/smp_svr/child_image/hci_rpmsg.conf | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 samples/subsys/mgmt/mcumgr/smp_svr/child_image/hci_rpmsg.conf diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/child_image/hci_rpmsg.conf b/samples/subsys/mgmt/mcumgr/smp_svr/child_image/hci_rpmsg.conf new file mode 100644 index 00000000000..98260877332 --- /dev/null +++ b/samples/subsys/mgmt/mcumgr/smp_svr/child_image/hci_rpmsg.conf @@ -0,0 +1,10 @@ +# +# Copyright (c) 2022 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 +# + +CONFIG_BT_MAX_CONN=2 +CONFIG_BT_BUF_ACL_RX_SIZE=502 +CONFIG_BT_BUF_ACL_TX_SIZE=502 +CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 From 9eb6436610f0a0cde6d1ffc6c1cfd70ec1377a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Thu, 1 Dec 2022 14:41:13 +0100 Subject: [PATCH 0015/1623] [nrf noup] samples&tests: Restore a few CONFIG_NEWLIB_LIBC_NANO=n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up to commit 9dd570f8a2207a02c886480b0065cd5a0e3a2e94. Since in NCS, unlike in vanilla Zephyr, the nano variant of newlib is the default one, restore entries that disable the nano variant in one sample and one test that require the full newlib variant. This patch is supposed to be removed when picolibc becomes the default. Signed-off-by: Andrzej Głąbek (cherry picked from commit 56204202e86fb7fa89f7ae74c916f73a00a22044) (cherry picked from commit 4edd3681905057c345eb622ffe144fac958593e0) --- samples/posix/eventfd/prj.conf | 1 + tests/lib/newlib/heap_listener/prj.conf | 1 + 2 files changed, 2 insertions(+) diff --git a/samples/posix/eventfd/prj.conf b/samples/posix/eventfd/prj.conf index 7ff74543b2f..a0bfcdf747b 100644 --- a/samples/posix/eventfd/prj.conf +++ b/samples/posix/eventfd/prj.conf @@ -1,5 +1,6 @@ # General config CONFIG_NEWLIB_LIBC=y +CONFIG_NEWLIB_LIBC_NANO=n CONFIG_POSIX_API=y CONFIG_EVENTFD=y diff --git a/tests/lib/newlib/heap_listener/prj.conf b/tests/lib/newlib/heap_listener/prj.conf index 31bc1ca7e76..8d8ebf99baf 100644 --- a/tests/lib/newlib/heap_listener/prj.conf +++ b/tests/lib/newlib/heap_listener/prj.conf @@ -1,4 +1,5 @@ CONFIG_ZTEST=y CONFIG_NEWLIB_LIBC=y +CONFIG_NEWLIB_LIBC_NANO=n CONFIG_NEWLIB_LIBC_HEAP_LISTENER=y CONFIG_ZTEST_NEW_API=y From cb04671ad6e0de80e4441e996cc29416af40caaa Mon Sep 17 00:00:00 2001 From: Marek Pieta Date: Mon, 14 Nov 2022 11:22:06 +0100 Subject: [PATCH 0016/1623] [nrf noup] boards: thingy53_nrf5340: Add common partition map Change introduces common static Partition Manager configuration. The tfm_nonsecure partition must be SPU region aligned. Ref: NCSDK-18033 Ref: NCSDK-19515 Signed-off-by: Marek Pieta Signed-off-by: Markus Swarowsky (cherry picked from commit 6a9eba74bdc36576bdc6f562380912ee44f38bf8) (cherry picked from commit a722c66f997db0f1a74004c3f5c424808938abac) --- .../pm_static_thingy53_nrf5340_cpuapp.yml | 55 ++++++++++++++ .../pm_static_thingy53_nrf5340_cpuapp_ns.yml | 73 +++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 boards/arm/thingy53_nrf5340/pm_static_thingy53_nrf5340_cpuapp.yml create mode 100644 boards/arm/thingy53_nrf5340/pm_static_thingy53_nrf5340_cpuapp_ns.yml diff --git a/boards/arm/thingy53_nrf5340/pm_static_thingy53_nrf5340_cpuapp.yml b/boards/arm/thingy53_nrf5340/pm_static_thingy53_nrf5340_cpuapp.yml new file mode 100644 index 00000000000..7a48d51ec33 --- /dev/null +++ b/boards/arm/thingy53_nrf5340/pm_static_thingy53_nrf5340_cpuapp.yml @@ -0,0 +1,55 @@ +app: + address: 0x10200 + region: flash_primary + size: 0xdfe00 +mcuboot: + address: 0x0 + region: flash_primary + size: 0x10000 +mcuboot_pad: + address: 0x10000 + region: flash_primary + size: 0x200 +mcuboot_primary: + address: 0x10000 + orig_span: &id001 + - mcuboot_pad + - app + region: flash_primary + size: 0xe0000 + span: *id001 +mcuboot_primary_app: + address: 0x10200 + orig_span: &id002 + - app + region: flash_primary + size: 0xdfe00 + span: *id002 +settings_storage: + address: 0xf0000 + region: flash_primary + size: 0x10000 +mcuboot_primary_1: + address: 0x0 + size: 0x40000 + device: flash_ctrl + region: ram_flash +mcuboot_secondary: + address: 0x00000 + size: 0xe0000 + device: MX25R64 + region: external_flash +mcuboot_secondary_1: + address: 0xe0000 + size: 0x40000 + device: MX25R64 + region: external_flash +external_flash: + address: 0x120000 + size: 0x6e0000 + device: MX25R64 + region: external_flash +pcd_sram: + address: 0x20000000 + size: 0x2000 + region: sram_primary diff --git a/boards/arm/thingy53_nrf5340/pm_static_thingy53_nrf5340_cpuapp_ns.yml b/boards/arm/thingy53_nrf5340/pm_static_thingy53_nrf5340_cpuapp_ns.yml new file mode 100644 index 00000000000..70ffe6d9c12 --- /dev/null +++ b/boards/arm/thingy53_nrf5340/pm_static_thingy53_nrf5340_cpuapp_ns.yml @@ -0,0 +1,73 @@ +mcuboot: + address: 0x0 + region: flash_primary + size: 0x10000 +mcuboot_pad: + address: 0x10000 + region: flash_primary + size: 0x200 +tfm_secure: + address: 0x10000 + size: 0xc000 + span: [mcuboot_pad, tfm] +tfm_nonsecure: + address: 0x1c000 + size: 0xd4000 + span: [app] +tfm: + address: 0x10200 + region: flash_primary + size: 0xbe00 +app: + address: 0x1c000 + region: flash_primary + size: 0xd4000 +mcuboot_primary: + address: 0x10000 + orig_span: &id001 + - mcuboot_pad + - tfm + - app + region: flash_primary + size: 0xe0000 + span: *id001 +mcuboot_primary_app: + address: 0x10200 + orig_span: &id002 + - tfm + - app + region: flash_primary + size: 0xdfe00 + span: *id002 +nonsecure_storage: + address: 0xf0000 + size: 0x10000 + span: [settings_storage] +settings_storage: + address: 0xf0000 + region: flash_primary + size: 0x10000 +mcuboot_primary_1: + address: 0x0 + size: 0x40000 + device: flash_ctrl + region: ram_flash +mcuboot_secondary: + address: 0x00000 + size: 0xe0000 + device: MX25R64 + region: external_flash +mcuboot_secondary_1: + address: 0xe0000 + size: 0x40000 + device: MX25R64 + region: external_flash +external_flash: + address: 0x120000 + size: 0x6e0000 + device: MX25R64 + region: external_flash +pcd_sram: + address: 0x20000000 + size: 0x2000 + region: sram_primary From 468009977970899f2d250231847e160671f74d18 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Tue, 7 Feb 2023 12:39:12 +0100 Subject: [PATCH 0017/1623] [nrf noup] Bluetooth: Mesh: zero randomization for friend's adv Friend's replies on LPN's polls do not assume randomization in advertiser. Zero randomization will help to optimize time when LPN keeps receiving window open and save power. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 88d5ef9efab511212a171fe67faf82468bcd0531) (cherry picked from commit a5ab323470201713ded500729f8cd34fc13c96f0) --- subsys/bluetooth/mesh/Kconfig | 2 +- subsys/bluetooth/mesh/adv_ext.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 945b45c12cc..9b0c4bd80f0 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -926,7 +926,7 @@ config BT_MESH_LPN_INIT_POLL_TIMEOUT config BT_MESH_LPN_SCAN_LATENCY int "Latency for enabling scanning" range 0 50 - default 15 + default 2 help Latency in milliseconds that it takes to enable scanning. This is in practice how much time in advance before the Receive Window diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 88c631a5867..831149bf79e 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -13,6 +13,9 @@ #include #include #include +#if defined(CONFIG_BT_LL_SOFTDEVICE) +#include +#endif #include "common/bt_str.h" @@ -137,6 +140,28 @@ static inline struct bt_mesh_ext_adv *gatt_adv_get(void) #endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ } +static int set_adv_randomness(uint8_t handle, int rand_us) +{ +#if defined(CONFIG_BT_LL_SOFTDEVICE) + struct net_buf *buf; + sdc_hci_cmd_vs_set_adv_randomness_t *cmd_params; + + buf = bt_hci_cmd_create(SDC_HCI_OPCODE_CMD_VS_SET_ADV_RANDOMNESS, sizeof(*cmd_params)); + if (!buf) { + LOG_ERR("Could not allocate command buffer"); + return -ENOMEM; + } + + cmd_params = net_buf_add(buf, sizeof(*cmd_params)); + cmd_params->adv_handle = handle; + cmd_params->rand_us = rand_us; + + return bt_hci_cmd_send_sync(SDC_HCI_OPCODE_CMD_VS_SET_ADV_RANDOMNESS, buf, NULL); +#else + return 0; +#endif /* defined(CONFIG_BT_LL_SOFTDEVICE) */ +} + static int adv_start(struct bt_mesh_ext_adv *adv, const struct bt_le_adv_param *param, struct bt_le_ext_adv_start_param *start, @@ -473,6 +498,13 @@ int bt_mesh_adv_enable(void) if (err) { return err; } + + if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE) && adv->tag & BT_MESH_FRIEND_ADV) { + err = set_adv_randomness(adv->instance->handle, 0); + if (err) { + LOG_ERR("Failed to set zero randomness: %d", err); + } + } } return 0; From c88a4a6ae2ee15bc449ce00435dfa323ce4a179f Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 20 Nov 2020 14:44:03 +0100 Subject: [PATCH 0018/1623] [nrf noup] Bluetooth: update experimental for qualification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update Kconfig options for qualification: - Remove experimental on qualified feature. - Add experimental on unqualified feature. - BT_L2CAP_ECRED is not marked as experimental upstream and we qualify it downstream. Signed-off-by: Joakim Andersson Signed-off-by: Trond Einar Snekvik Signed-off-by: Martí Bolívar Signed-off-by: Robert Lubos Signed-off-by: Dominik Ermel Signed-off-by: Ingar Kulbrandstad Signed-off-by: Torsten Rasmussen Signed-off-by: Herman Berget Signed-off-by: Tomasz Moń (cherry picked from commit a6c2e3bbc24b7f565e3a8c0cc3d2d83b6d442487) (cherry picked from commit b182da7fcd6efed1fb177f87328f597cb14662e4) --- subsys/bluetooth/controller/Kconfig | 3 ++- subsys/bluetooth/host/Kconfig.l2cap | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 404d89cbf06..59ec86d5efe 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -114,7 +114,8 @@ choice BT_LL_CHOICE Select the Bluetooth Link Layer to compile. config BT_LL_SW_SPLIT - bool "Software-based BLE Link Layer" + bool "Software-based BLE Link Layer [EXPERIMENTAL]" + select EXPERIMENTAL select ENTROPY_GENERATOR help Use Zephyr software BLE Link Layer ULL LLL split implementation. diff --git a/subsys/bluetooth/host/Kconfig.l2cap b/subsys/bluetooth/host/Kconfig.l2cap index acb948c425a..f8d602acd57 100644 --- a/subsys/bluetooth/host/Kconfig.l2cap +++ b/subsys/bluetooth/host/Kconfig.l2cap @@ -66,7 +66,7 @@ config BT_L2CAP_DYNAMIC_CHANNEL allowing the creation of dynamic L2CAP Channels. config BT_L2CAP_ECRED - bool "L2CAP Enhanced Credit Based Flow Control support" + bool "L2CAP Enhanced Credit Based Flow Control support [EXPERIMENTAL]" depends on BT_L2CAP_DYNAMIC_CHANNEL help This option enables support for LE Connection oriented Channels with From 62a4cadefae85308a801698f8a164eaecaea2358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Wed, 8 Mar 2023 12:17:09 +0100 Subject: [PATCH 0019/1623] [nrf noup] Bluetooth: Mesh: Fix adv randomness bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes issue where randomness can be removed for advertising sets that have to handle other adv types than the BT_MESH_FRIEND_ADV tag type. Signed-off-by: Anders Storrø (cherry picked from commit f8f113382356934cb6d1ef4cdad95a843f922085) (cherry picked from commit 996037de254a91a9b2da4a288f48c09e90427501) --- subsys/bluetooth/mesh/adv_ext.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 831149bf79e..5c1a2bc3c32 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -499,7 +499,9 @@ int bt_mesh_adv_enable(void) return err; } - if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE) && adv->tag & BT_MESH_FRIEND_ADV) { + if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE) && + IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && + adv->tag == BT_MESH_FRIEND_ADV) { err = set_adv_randomness(adv->instance->handle, 0); if (err) { LOG_ERR("Failed to set zero randomness: %d", err); From 778b2a956086de2f6aec01f39651a25e3613cdae Mon Sep 17 00:00:00 2001 From: Mateusz Kapala Date: Thu, 2 Feb 2023 11:04:23 +0100 Subject: [PATCH 0020/1623] [nrf noup] boards: arm: thingy53: Disable USB CDC added by MCUBoot Enabling USB CDC by default in Thingy:53 board configuration caused that there were two instances of USB CDC in MCUBoot. Change disables one instance which was added automatically by NCS if MCUBoot bootloader was built as a child image. Jira: NCSDK-18596 Signed-off-by: Mateusz Kapala Signed-off-by: Johann Fischer (cherry picked from commit 5193278031897be51edfac12ac8cb250f9b8ff93) (cherry picked from commit 7f45aa42295533c14994fe1c449da643fa7d6399) --- boards/arm/thingy53_nrf5340/Kconfig.defconfig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/boards/arm/thingy53_nrf5340/Kconfig.defconfig b/boards/arm/thingy53_nrf5340/Kconfig.defconfig index e4d9e63b7f1..b34d118e59c 100644 --- a/boards/arm/thingy53_nrf5340/Kconfig.defconfig +++ b/boards/arm/thingy53_nrf5340/Kconfig.defconfig @@ -135,6 +135,12 @@ endif # LOG endif # BOARD_SERIAL_BACKEND_CDC_ACM +# By default, a USB CDC ACM instance is already enabled in the board's DTS. +# It is not necessary for nRF Connect SDK to add another instance if MCUBoot +# bootloader is built as a child image. +config MCUBOOT_USB_SUPPORT + default n + endif # BOARD_THINGY53_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP_NS if BOARD_THINGY53_NRF5340_CPUNET From aa00769d7243809601ea7480a6f7c0cc72ebe82d Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 5 May 2022 12:04:26 +0200 Subject: [PATCH 0021/1623] [nrf noup] boards: Enable TF-M by default for nordic SoC NS boards Enable TF-M by default for nordic nRF5340 and nrf9160 SoC boards. NCSDK-14811 Signed-off-by: Joakim Andersson Signed-off-by: Jamie McCrae Signed-off-by: Alex Tsamakos Signed-off-by: Johann Fischer (cherry picked from commit 1f9e520d7518322c0cfd40d91f299cfa28ad07fb) (cherry picked from commit 79993350d8494c3cba1e9947925890249aaedde2) --- boards/arm/actinius_icarus/Kconfig.defconfig | 15 +++++++++++++++ boards/arm/actinius_icarus_bee/Kconfig.defconfig | 15 +++++++++++++++ boards/arm/actinius_icarus_som/Kconfig.defconfig | 15 +++++++++++++++ .../circuitdojo_feather_nrf9160/Kconfig.defconfig | 15 +++++++++++++++ .../sparkfun_thing_plus_nrf9160/Kconfig.defconfig | 15 +++++++++++++++ boards/arm/thingy53_nrf5340/Kconfig.defconfig | 15 +++++++++++++++ 6 files changed, 90 insertions(+) diff --git a/boards/arm/actinius_icarus/Kconfig.defconfig b/boards/arm/actinius_icarus/Kconfig.defconfig index 6994aac280d..3b8093275da 100644 --- a/boards/arm/actinius_icarus/Kconfig.defconfig +++ b/boards/arm/actinius_icarus/Kconfig.defconfig @@ -8,6 +8,21 @@ if BOARD_ACTINIUS_ICARUS || BOARD_ACTINIUS_ICARUS_NS config BOARD default "actinius_icarus" +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_ACTINIUS_ICARUS_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + source "boards/common/actinius/Kconfig" # For the secure version of the board the firmware is linked at the beginning diff --git a/boards/arm/actinius_icarus_bee/Kconfig.defconfig b/boards/arm/actinius_icarus_bee/Kconfig.defconfig index 309a45a61d4..7b733d910d9 100644 --- a/boards/arm/actinius_icarus_bee/Kconfig.defconfig +++ b/boards/arm/actinius_icarus_bee/Kconfig.defconfig @@ -8,6 +8,21 @@ if BOARD_ACTINIUS_ICARUS_BEE || BOARD_ACTINIUS_ICARUS_BEE_NS config BOARD default "actinius_icarus_bee" +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_ACTINIUS_ICARUS_BEE_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + source "boards/common/actinius/Kconfig" # For the secure version of the board the firmware is linked at the beginning diff --git a/boards/arm/actinius_icarus_som/Kconfig.defconfig b/boards/arm/actinius_icarus_som/Kconfig.defconfig index 473acfea29f..cc92427d24c 100644 --- a/boards/arm/actinius_icarus_som/Kconfig.defconfig +++ b/boards/arm/actinius_icarus_som/Kconfig.defconfig @@ -8,6 +8,21 @@ if BOARD_ACTINIUS_ICARUS_SOM || BOARD_ACTINIUS_ICARUS_SOM_NS config BOARD default "actinius_icarus_som" +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_ACTINIUS_ICARUS_SOM_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + source "boards/common/actinius/Kconfig" # For the secure version of the board the firmware is linked at the beginning diff --git a/boards/arm/circuitdojo_feather_nrf9160/Kconfig.defconfig b/boards/arm/circuitdojo_feather_nrf9160/Kconfig.defconfig index 73648be3ef1..f37bfbf84fb 100644 --- a/boards/arm/circuitdojo_feather_nrf9160/Kconfig.defconfig +++ b/boards/arm/circuitdojo_feather_nrf9160/Kconfig.defconfig @@ -9,6 +9,21 @@ if BOARD_CIRCUITDOJO_FEATHER_NRF9160 || BOARD_CIRCUITDOJO_FEATHER_NRF9160_NS config BOARD default "circuitdojo_feather_nrf9160" +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_CIRCUITDOJO_FEATHER_NRF9160_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + # For the secure version of the board the firmware is linked at the beginning # of the flash, or into the code-partition defined in DT if it is intended to # be loaded by MCUboot. If the secure firmware is to be combined with a non- diff --git a/boards/arm/sparkfun_thing_plus_nrf9160/Kconfig.defconfig b/boards/arm/sparkfun_thing_plus_nrf9160/Kconfig.defconfig index 8ae5b832d89..3d98b1b4cb4 100644 --- a/boards/arm/sparkfun_thing_plus_nrf9160/Kconfig.defconfig +++ b/boards/arm/sparkfun_thing_plus_nrf9160/Kconfig.defconfig @@ -9,6 +9,21 @@ if BOARD_SPARKFUN_THING_PLUS_NRF9160 || BOARD_SPARKFUN_THING_PLUS_NRF9160_NS config BOARD default "sparkfun_thing_plus_nrf9160" +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_SPARKFUN_THING_PLUS_NRF9160_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + # For the secure version of the board the firmware is linked at the beginning # of the flash, or into the code-partition defined in DT if it is intended to # be loaded by MCUboot. If the secure firmware is to be combined with a non- diff --git a/boards/arm/thingy53_nrf5340/Kconfig.defconfig b/boards/arm/thingy53_nrf5340/Kconfig.defconfig index b34d118e59c..0afe06dacb9 100644 --- a/boards/arm/thingy53_nrf5340/Kconfig.defconfig +++ b/boards/arm/thingy53_nrf5340/Kconfig.defconfig @@ -8,6 +8,21 @@ if BOARD_THINGY53_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP_NS config BOARD default "thingy53_nrf5340_cpuapp" +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_THINGY53_NRF5340_CPUAPP_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + # Code Partition: # # For the secure version of the board the firmware is linked at the beginning From 542ff4901b820fd0d8fc1e6264059962ebbf96bf Mon Sep 17 00:00:00 2001 From: Marek Pieta Date: Mon, 28 Nov 2022 15:31:33 +0100 Subject: [PATCH 0022/1623] [nrf noup] boards: thingy53_nrf5340: Enable MCUboot by default Change enables MCUboot bootloader by default to allow programming samples and applications without external programmer (using MCUboot serial recovery). Change also enables network core to prevent build failures when building MCUboot with nRF53 multi image DFU. Jira: NCSDK-18263 Signed-off-by: Marek Pieta Signed-off-by: Vinayak Kariappa Chettimada Signed-off-by: Johann Fischer (cherry picked from commit 46895493bf1b0988e44ea344f4420b543e307eae) (cherry picked from commit ff1db43269579e2a0bdc28c55f2c83d3ad58ebb7) --- boards/arm/thingy53_nrf5340/Kconfig.defconfig | 6 ++++++ boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi | 1 + 2 files changed, 7 insertions(+) diff --git a/boards/arm/thingy53_nrf5340/Kconfig.defconfig b/boards/arm/thingy53_nrf5340/Kconfig.defconfig index 0afe06dacb9..c79eb908c21 100644 --- a/boards/arm/thingy53_nrf5340/Kconfig.defconfig +++ b/boards/arm/thingy53_nrf5340/Kconfig.defconfig @@ -8,6 +8,12 @@ if BOARD_THINGY53_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP_NS config BOARD default "thingy53_nrf5340_cpuapp" +config BOOTLOADER_MCUBOOT + default y if !MCUBOOT + +config BOARD_ENABLE_CPUNET + default y if !MCUBOOT + # By default, if we build for a Non-Secure version of the board, # enable building with TF-M as the Secure Execution Environment. config BUILD_WITH_TFM diff --git a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi index 341bb1305e1..515fc3bea7b 100644 --- a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi +++ b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi @@ -16,6 +16,7 @@ zephyr,bt-hci-rpmsg-ipc = &ipc0; nordic,802154-spinel-ipc = &ipc0; zephyr,ieee802154 = &ieee802154; + nordic,pm-ext-flash = &mx25r64; }; buttons { From 16ac80df1b7210957d8c325573326ec6f3d0b931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Tue, 9 May 2023 12:10:13 +0200 Subject: [PATCH 0023/1623] [nrf noup] cmake: modules: Add ZEPHYR_NRF_MODULE_DIR to snippets root MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add nRF directory to snippets root to allow placing snippets in the sdk-nrf/snippets directory. CmakeLists.txt in nRF directory is handled after the snippets so that adding the directory in sdk-nrf will not work. Signed-off-by: Eivind Jølsgard (cherry picked from commit b4672df6bb9bb2e3ea44eae8f39051c083f3f124) --- cmake/modules/snippets.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/modules/snippets.cmake b/cmake/modules/snippets.cmake index 550d236a2f4..6f8950c5f64 100644 --- a/cmake/modules/snippets.cmake +++ b/cmake/modules/snippets.cmake @@ -59,6 +59,7 @@ function(zephyr_process_snippets) # Set SNIPPET_ROOT. list(APPEND SNIPPET_ROOT ${APPLICATION_SOURCE_DIR}) list(APPEND SNIPPET_ROOT ${ZEPHYR_BASE}) + list(APPEND SNIPPET_ROOT ${ZEPHYR_NRF_MODULE_DIR}) unset(real_snippet_root) foreach(snippet_dir ${SNIPPET_ROOT}) # The user might have put a symbolic link in here, for example. From 07385636ee190aefce8405776eb76d836c791808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20Lilleb=C3=B8?= Date: Tue, 9 May 2023 16:21:35 +0200 Subject: [PATCH 0024/1623] [nrf noup] modules: mbedtls: Add PSA symbols for Oberon PSA extension Add PSA symbols for Oberon extension to the PSA specification. Noup commit until we can decide a better way to include PSA extension options, or these are accepted to be included in PSA specification with naming for the configurations that are compatible with Mbed TLS project. Signed-off-by: Joakim Andersson (cherry picked from commit 0b32fd2743f574aaa293122545caeadd3b01fd41) --- modules/mbedtls/Kconfig.psa | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 399d18a3797..9f93771584c 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -300,7 +300,8 @@ config PSA_HAS_KEY_DERIVATION PSA_WANT_ALG_HKDF_EXTRACT || \ PSA_WANT_ALG_PBKDF2_HMAC || \ PSA_WANT_ALG_TLS12_PRF || \ - PSA_WANT_ALG_TLS12_PSK_TO_MS + PSA_WANT_ALG_TLS12_PSK_TO_MS || \ + PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS help Prompt-less configuration that states that key derivation is supported. @@ -331,6 +332,10 @@ config PSA_WANT_ALG_TLS12_PSK_TO_MS bool prompt "PSA TLS 1.2 PSK to MS support" if !PSA_PROMPTLESS +config PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS + bool + prompt "PSA TLS 1.2 EC J-PAKE to PMS support" if !PSA_PROMPTLESS + endmenu # PSA Key derivation support @@ -477,8 +482,19 @@ config PSA_WANT_ALG_SPAKE2P prompt "PSA SPAKE2+ support" if !PSA_PROMPTLESS select EXPERIMENTAL -config PSA_WANT_ALG_SRP +config PSA_WANT_ALG_SRP_6 bool - prompt "PSA SRP support" if !PSA_PROMPTLESS - default n + prompt "PSA SRP-6 support" if !PSA_PROMPTLESS select EXPERIMENTAL + +config PSA_WANT_ALG_PURE_EDDSA + bool + prompt "PSA PURE_EDDSA support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_ED25519PH + bool + prompt "PSA ED25519PH support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_ED448PH + bool + prompt "PSA ED448PH support" if !PSA_PROMPTLESS From 4d76b6a7403a5d3c14098d4d67e26e284e3c5757 Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Fri, 28 Jan 2022 12:02:58 +0100 Subject: [PATCH 0025/1623] [nrf noup] ci: clang: parallel execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bring back parallel execution to the clang action. In the upstream they went to use a single dedicated powerful agent to run this. We need to keep this as we have to base on agents available in github's cloud. zephyr_runner is upstream's proprietary agent inaccessible outside of upstream's CI. Use ubuntu-latest instead. Signed-off-by: Maciej Perkowski Signed-off-by: Gerard Marull-Paretas Signed-off-by: Dominik Ermel Signed-off-by: Torsten Rasmussen Signed-off-by: Tomasz Moń Signed-off-by: Stephanos Ioannidis Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 5b3d0ff9ab29e66d52fd7c3ffbd50e9e97b1d7d5) (cherry picked from commit 5e2f4ecc0bd4171ff60bfbc9f60271d0a30142cc) Signed-off-by: Dominik Ermel (cherry picked from commit 0948638f2e3a857bdfcd4bad0e1b5bd6d4760fb6) --- .github/workflows/clang.yaml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/clang.yaml b/.github/workflows/clang.yaml index 9108d31b45b..402cbae9f95 100644 --- a/.github/workflows/clang.yaml +++ b/.github/workflows/clang.yaml @@ -8,8 +8,7 @@ concurrency: jobs: clang-build: - if: github.repository_owner == 'zephyrproject-rtos' - runs-on: zephyr-runner-linux-x64-4xlarge + runs-on: ubuntu-latest container: image: ghcr.io/zephyrproject-rtos/ci:v0.26.4 options: '--entrypoint /bin/bash' @@ -19,11 +18,13 @@ jobs: fail-fast: false matrix: platform: ["native_posix"] + subset: [1, 2, 3, 4, 5] env: ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.16.1 LLVM_TOOLCHAIN_PATH: /usr/lib/llvm-16 COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} BASE_REF: ${{ github.base_ref }} + MATRIX_SIZE: 5 outputs: report_needed: ${{ steps.twister.outputs.report_needed }} steps: @@ -85,7 +86,7 @@ jobs: id: cache-ccache uses: zephyrproject-rtos/action-s3-cache@v1.2.0 with: - key: ${{ steps.ccache_cache_timestamp.outputs.repo }}-${{ github.ref_name }}-clang-${{ matrix.platform }}-ccache + key: ${{ steps.ccache_cache_timestamp.outputs.repo }}-${{ github.ref_name }}-clang-${{ matrix.subset }}-ccache path: /github/home/.cache/ccache aws-s3-bucket: ccache.zephyrproject.org aws-access-key-id: ${{ vars.AWS_CCACHE_ACCESS_KEY_ID }} @@ -98,6 +99,16 @@ jobs: test -d github/home/.cache/ccache && rm -rf /github/home/.cache/ccache && mv github/home/.cache/ccache /github/home/.cache/ccache ccache -M 10G -s + - name: Build test plan with Twister + id: twister_test_plan + run: | + export ZEPHYR_BASE=${PWD} + export ZEPHYR_TOOLCHAIN_VARIANT=llvm + + # check if we need to run a full twister or not based on files changed + python3 ./scripts/ci/test_plan.py -p native_posix -c origin/${BASE_REF}.. + + - name: Run Tests with Twister id: twister run: | @@ -111,7 +122,7 @@ jobs: if [ -s testplan.json ]; then echo "report_needed=1" >> $GITHUB_OUTPUT # Full twister but with options based on changes - ./scripts/twister --force-color --inline-logs -M -N -v --load-tests testplan.json --retry-failed 2 + ./scripts/twister --inline-logs -M -N -v --load-tests testplan.json --retry-failed 2 --subset ${{matrix.subset}}/${MATRIX_SIZE} else # if nothing is run, skip reporting step echo "report_needed=0" >> $GITHUB_OUTPUT @@ -126,7 +137,7 @@ jobs: if: always() && steps.twister.outputs.report_needed != 0 uses: actions/upload-artifact@v3 with: - name: Unit Test Results (Subset ${{ matrix.platform }}) + name: Unit Test Results (Subset ${{ matrix.subset }}) path: twister-out/twister.xml clang-build-results: From 8b234720cb043930a80ebf3aa00b18a82ed9d821 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 1 Jun 2023 15:58:56 +0200 Subject: [PATCH 0026/1623] [nrf noup] tests: drivers: build_all: regulator: use old schema New Twister schema is not supported yet in sdk-zephyr, drop this patch once Twister is updated. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 4618cfe53df3154a6ee4101c2e68e98531fdda98) Signed-off-by: Dominik Ermel (cherry picked from commit c01ee451273ccb33c211f5b10fa2858ff8a271b9) --- tests/drivers/build_all/regulator/testcase.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/drivers/build_all/regulator/testcase.yaml b/tests/drivers/build_all/regulator/testcase.yaml index 9b9c25511c4..c5dbda1913f 100644 --- a/tests/drivers/build_all/regulator/testcase.yaml +++ b/tests/drivers/build_all/regulator/testcase.yaml @@ -3,8 +3,6 @@ tests: drivers.regulator.build: - tags: - - drivers - - regulator + tags: drivers regulator build_only: true platform_allow: native_posix From f3aa7126214fdf6a77afd316a5c0f3e48257f62f Mon Sep 17 00:00:00 2001 From: Dawid Przybylo Date: Fri, 23 Jun 2023 08:15:25 +0200 Subject: [PATCH 0027/1623] [nrf noup] ci: Update test-spec.yml with adding FEM to CI Extend sdk-zephyr CI with FEM test label. Signed-off-by: Dawid Przybylo (cherry picked from commit d2bc2c3c6ce3d08628a93c3bd246fd688dc6a446) --- .github/test-spec.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 3fe9ba5fbec..5dd281919bc 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -60,6 +60,9 @@ "CI-crypto-test": - "**/*" +"CI-fem-test": + - "**/*" + "CI-rs-test": - "**/*" From 34f5012ee258e0d090581ed1caf7ba752e327cd5 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Mon, 19 Jun 2023 12:19:05 +0200 Subject: [PATCH 0028/1623] [nrf noup] Revert "twister: Use natural sort when generating hardware map" This reverts commit c37deeb0c4602dc3eeb700a7dc3ed317283fff17. This is only a temporary change, until we align our CI. To be removed once natsort is avaialble in the NCS CI. Signed-off-by: Robert Lubos (cherry picked from commit cc84ffea7210488ec24db09db25dd6df107f0209) --- scripts/pylib/twister/twisterlib/hardwaremap.py | 3 +-- scripts/requirements-run-test.txt | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/hardwaremap.py b/scripts/pylib/twister/twisterlib/hardwaremap.py index 5e90b7c84c6..a0ea7c59a8e 100644 --- a/scripts/pylib/twister/twisterlib/hardwaremap.py +++ b/scripts/pylib/twister/twisterlib/hardwaremap.py @@ -13,7 +13,6 @@ import scl import logging from pathlib import Path -from natsort import natsorted from twisterlib.environment import ZEPHYR_BASE @@ -322,7 +321,7 @@ def readlink(link): def save(self, hwm_file): # use existing map - self.detected = natsorted(self.detected, key=lambda x: x.serial or '') + self.detected.sort(key=lambda x: x.serial or '') if os.path.exists(hwm_file): with open(hwm_file, 'r') as yaml_file: hwm = yaml.load(yaml_file, Loader=SafeLoader) diff --git a/scripts/requirements-run-test.txt b/scripts/requirements-run-test.txt index 83692128110..3bb0b21c44e 100644 --- a/scripts/requirements-run-test.txt +++ b/scripts/requirements-run-test.txt @@ -7,7 +7,6 @@ pyocd>=0.35.0 # used by twister for board/hardware map tabulate -natsort # used by mcuboot cbor>=1.0.0 From 51bef37071aad3301b4223a59991af71614a13ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Tue, 20 Jun 2023 13:27:15 +0200 Subject: [PATCH 0029/1623] [nrf noup] mbedtls: Add config support for PBKDF2_HMAC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add config support for PBKDF2_HMAC. This patches an existing noup commit and is therefore also noup. Signed-off-by: Sebastian Bøe (cherry picked from commit 1ff52962ebce37d536949bcc1804fcf502011af6) --- modules/mbedtls/Kconfig.psa | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 9f93771584c..5e8e9a8ead0 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -320,9 +320,8 @@ config PSA_WANT_ALG_HKDF_EXPAND config PSA_WANT_ALG_PBKDF2_HMAC bool + prompt "PSA PBKDF2 HMAC support" if !PSA_PROMPTLESS depends on PSA_WANT_ALG_HMAC - help - PBKDF2-HMAC is not yet supported via the PSA APIs in Mbed TLS. config PSA_WANT_ALG_TLS12_PRF bool From 192697c16cc5908a88d0b75440ec319e2c5d211a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Tue, 20 Jun 2023 15:04:46 +0200 Subject: [PATCH 0030/1623] [nrf noup] mbedtls: Add config support for PBKDF2_AES_CMAC_PRF_128 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add config support for PBKDF2_AES_CMAC_PRF_128 Signed-off-by: Sebastian Bøe (cherry picked from commit 743f99947369088ecba6820a720ede8054893866) --- modules/mbedtls/Kconfig.psa | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 5e8e9a8ead0..b0d21685f70 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -299,6 +299,7 @@ config PSA_HAS_KEY_DERIVATION PSA_WANT_ALG_HKDF_EXPAND || \ PSA_WANT_ALG_HKDF_EXTRACT || \ PSA_WANT_ALG_PBKDF2_HMAC || \ + PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 || \ PSA_WANT_ALG_TLS12_PRF || \ PSA_WANT_ALG_TLS12_PSK_TO_MS || \ PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS @@ -323,6 +324,11 @@ config PSA_WANT_ALG_PBKDF2_HMAC prompt "PSA PBKDF2 HMAC support" if !PSA_PROMPTLESS depends on PSA_WANT_ALG_HMAC +config PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 + bool + prompt "PSA PBKDF2-AES-CMAC-PRF-128 support" if !PSA_PROMPTLESS + depends on PSA_WANT_ALG_CMAC + config PSA_WANT_ALG_TLS12_PRF bool prompt "PSA PRF support (TLS1.2)" if !PSA_PROMPTLESS From 6fba504e5e4026e1b563013ac6e7858ca73ea260 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Thu, 13 Jul 2023 13:42:10 +0000 Subject: [PATCH 0031/1623] [nrf noup] drivers/flashdisk: Add support for Partition Manager The commits adds support for generating flash disks from Partition Manager defined partitions. Signed-off-by: Dominik Ermel (cherry picked from commit 60166d9f304b48febbbaad58a210d0017ed8fdd3) --- drivers/disk/flashdisk.c | 78 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/drivers/disk/flashdisk.c b/drivers/disk/flashdisk.c index 6336ad4dfd0..3e43716c2b3 100644 --- a/drivers/disk/flashdisk.c +++ b/drivers/disk/flashdisk.c @@ -420,6 +420,8 @@ static const struct disk_operations flash_disk_ops = { .ioctl = disk_flash_access_ioctl, }; +#ifndef USE_PARTITION_MANAGER +/* The non-Partition manager, DTS based generators below */ #define DT_DRV_COMPAT zephyr_flash_disk #define PARTITION_PHANDLE(n) DT_PHANDLE_BY_IDX(DT_DRV_INST(n), partition, 0) @@ -461,6 +463,82 @@ DT_INST_FOREACH_STATUS_OKAY(VERIFY_CACHE_SIZE_IS_NOT_ZERO_IF_NOT_READ_ONLY) "Devicetree node " DT_NODE_PATH(DT_DRV_INST(n)) \ " has cache size which is not a multiple of its sector size"); DT_INST_FOREACH_STATUS_OKAY(VERIFY_CACHE_SIZE_IS_MULTIPLY_OF_SECTOR_SIZE) +#else /* ifndef USE_PARTITION_MANAGER */ +/* Partition Manager based generators below */ + +/* Gets the PM_..._EXTRA_PARAM_##param value */ +#define PM_FLASH_DISK_ENTRY_EXTRA_PARAM(name, param) PM_##name##_EXTRA_PARAM_disk_##param + +/* Gets the PM_..._NAME value which is originally cased, as in yaml, partition name */ +#define PM_FLASH_DISK_ENTRY_PARTITION_NAME(name) PM_##name##_NAME + +/* Generates flashdiskN_cache variable name, where N is partition ID */ +#define PM_FLASH_DISK_CACHE_VARIABLE(n) UTIL_CAT(flashdisk, UTIL_CAT(FIXED_PARTITION_ID(n), _cache)) + +/* Generate cache buffers */ +#define CACHE_SIZE(n) (COND_CODE_1(PM_FLASH_DISK_ENTRY_EXTRA_PARAM(n, read_only), (0), (1)) * \ + PM_FLASH_DISK_ENTRY_EXTRA_PARAM(n, cache_size)) +#define DEFINE_FLASHDISKS_CACHE(n) \ + static uint8_t __aligned(4) PM_FLASH_DISK_CACHE_VARIABLE(n)[CACHE_SIZE(n)]; + +PM_FOREACH_AFFILIATED_TO_disk(DEFINE_FLASHDISKS_CACHE) + +/* Generated single Flash Disk device data from Partition Manager partition. + * Partition is required to have type set to disk in partition definitions: + * type: disk + * and following extra params can be provided: + * extra_params: { + * name = "", + * cache_size = , + * sector_size = , + * read_only = + * } + * where: + * is mandatory device name that will be used by Disk Access and FAT FS to mount device; + * is cache r/w cache size, which is mandatory if read_only = 0 or not present, + * and should be multiple of ; + * is mandatory device sector size information, usually should be erase page size, + * for flash devices, for example 4096 bytes; + * read_only is optional, if not present then assumed false; can be 0(false) or 1(true). + */ +#define DEFINE_FLASHDISKS_DEVICE(n) \ +{ \ + .info = { \ + .ops = &flash_disk_ops, \ + .name = STRINGIFY(PM_FLASH_DISK_ENTRY_EXTRA_PARAM(n, name)), \ + }, \ + .area_id = FIXED_PARTITION_ID(n), \ + .offset = FIXED_PARTITION_OFFSET(n), \ + .cache = PM_FLASH_DISK_CACHE_VARIABLE(n), \ + .cache_size = sizeof(PM_FLASH_DISK_CACHE_VARIABLE(n)), \ + .size = FIXED_PARTITION_SIZE(n), \ + .sector_size = PM_FLASH_DISK_ENTRY_EXTRA_PARAM(n, sector_size), \ +}, + +/* The bellow used PM_FOREACH_TYPE_disk is generated by Partition Manager foreach + * loop macro. The lower case _disk is type name for which the macro has been generated; + * partition entry can have multiple types set and foreach macro will be generated + * for every type found across partition definitions. + */ +static struct flashdisk_data flash_disks[] = { + PM_FOREACH_AFFILIATED_TO_disk(DEFINE_FLASHDISKS_DEVICE) +}; + +#define VERIFY_CACHE_SIZE_IS_NOT_ZERO_IF_NOT_READ_ONLY(n) \ + COND_CODE_1(PM_FLASH_DISK_ENTRY_EXTRA_PARAM(n, read_only), \ + (/* cache-size is not used for read-only disks */), \ + (BUILD_ASSERT(PM_FLASH_DISK_ENTRY_EXTRA_PARAM(n, cache_size) != 0, \ + "Flash disk partition " STRINGIFY(PM_FLASH_DISK_ENTRY_PARTITION_NAME(n))\ + " must have non-zero cache-size");)) +PM_FOREACH_AFFILIATED_TO_disk(VERIFY_CACHE_SIZE_IS_NOT_ZERO_IF_NOT_READ_ONLY) + +#define VERIFY_CACHE_SIZE_IS_MULTIPLY_OF_SECTOR_SIZE(n) \ + BUILD_ASSERT(PM_FLASH_DISK_ENTRY_EXTRA_PARAM(n, cache_size) % \ + PM_FLASH_DISK_ENTRY_EXTRA_PARAM(n, sector_size) == 0, \ + "Devicetree node " STRINGIFY(PM_FLASH_DISK_ENTRY_PARTITION_NAME(n)) \ + " has cache size which is not a multiple of its sector size"); +PM_FOREACH_AFFILIATED_TO_disk(VERIFY_CACHE_SIZE_IS_MULTIPLY_OF_SECTOR_SIZE) +#endif /* USE_PARTITION_MANAGER */ static int disk_flash_init(void) { From 0539e2d67b72e5072e5bb04c4cec562c1fab5872 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Thu, 13 Jul 2023 15:32:45 +0200 Subject: [PATCH 0032/1623] [nrf noup] samples: net: Add support for nRF700x Add support for nRF700x to selected networking samples, by providing appropriate overlay configuration files. Signed-off-by: Robert Lubos (cherry picked from commit 4579f028e1e6139786491e352c50bc9528b09c7d) --- .../net/dhcpv4_client/overlay-nrf700x.conf | 14 ++++++++++ samples/net/dns_resolve/overlay-nrf700x.conf | 18 +++++++++++++ .../net/ipv4_autoconf/overlay-nrf700x.conf | 14 ++++++++++ .../net/mdns_responder/overlay-nrf700x.conf | 18 +++++++++++++ .../net/mqtt_publisher/overlay-nrf700x.conf | 19 ++++++++++++++ .../mqtt_sn_publisher/overlay-nrf700x.conf | 20 ++++++++++++++ .../sockets/coap_client/overlay-nrf700x.conf | 16 ++++++++++++ .../sockets/coap_server/overlay-nrf700x.conf | 26 +++++++++++++++++++ samples/net/sockets/echo/overlay-nrf700x.conf | 18 +++++++++++++ .../sockets/echo_async/overlay-nrf700x.conf | 18 +++++++++++++ .../sockets/echo_client/overlay-nrf700x.conf | 20 ++++++++++++++ .../sockets/echo_server/overlay-nrf700x.conf | 20 ++++++++++++++ .../net/sockets/http_get/overlay-nrf700x.conf | 18 +++++++++++++ .../sockets/sntp_client/overlay-nrf700x.conf | 18 +++++++++++++ samples/net/syslog_net/overlay-nrf700x.conf | 18 +++++++++++++ samples/net/telnet/overlay-nrf700x.conf | 18 +++++++++++++ 16 files changed, 293 insertions(+) create mode 100644 samples/net/dhcpv4_client/overlay-nrf700x.conf create mode 100644 samples/net/dns_resolve/overlay-nrf700x.conf create mode 100644 samples/net/ipv4_autoconf/overlay-nrf700x.conf create mode 100644 samples/net/mdns_responder/overlay-nrf700x.conf create mode 100644 samples/net/mqtt_publisher/overlay-nrf700x.conf create mode 100644 samples/net/mqtt_sn_publisher/overlay-nrf700x.conf create mode 100644 samples/net/sockets/coap_client/overlay-nrf700x.conf create mode 100644 samples/net/sockets/coap_server/overlay-nrf700x.conf create mode 100644 samples/net/sockets/echo/overlay-nrf700x.conf create mode 100644 samples/net/sockets/echo_async/overlay-nrf700x.conf create mode 100644 samples/net/sockets/echo_client/overlay-nrf700x.conf create mode 100644 samples/net/sockets/echo_server/overlay-nrf700x.conf create mode 100644 samples/net/sockets/http_get/overlay-nrf700x.conf create mode 100644 samples/net/sockets/sntp_client/overlay-nrf700x.conf create mode 100644 samples/net/syslog_net/overlay-nrf700x.conf create mode 100644 samples/net/telnet/overlay-nrf700x.conf diff --git a/samples/net/dhcpv4_client/overlay-nrf700x.conf b/samples/net/dhcpv4_client/overlay-nrf700x.conf new file mode 100644 index 00000000000..2d552e9c623 --- /dev/null +++ b/samples/net/dhcpv4_client/overlay-nrf700x.conf @@ -0,0 +1,14 @@ +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/dns_resolve/overlay-nrf700x.conf b/samples/net/dns_resolve/overlay-nrf700x.conf new file mode 100644 index 00000000000..aa59e5d5ea2 --- /dev/null +++ b/samples/net/dns_resolve/overlay-nrf700x.conf @@ -0,0 +1,18 @@ +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/ipv4_autoconf/overlay-nrf700x.conf b/samples/net/ipv4_autoconf/overlay-nrf700x.conf new file mode 100644 index 00000000000..2d552e9c623 --- /dev/null +++ b/samples/net/ipv4_autoconf/overlay-nrf700x.conf @@ -0,0 +1,14 @@ +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/mdns_responder/overlay-nrf700x.conf b/samples/net/mdns_responder/overlay-nrf700x.conf new file mode 100644 index 00000000000..aa59e5d5ea2 --- /dev/null +++ b/samples/net/mdns_responder/overlay-nrf700x.conf @@ -0,0 +1,18 @@ +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/mqtt_publisher/overlay-nrf700x.conf b/samples/net/mqtt_publisher/overlay-nrf700x.conf new file mode 100644 index 00000000000..a812c7896f6 --- /dev/null +++ b/samples/net/mqtt_publisher/overlay-nrf700x.conf @@ -0,0 +1,19 @@ +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_CONFIG_NEED_IPV4=y +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/mqtt_sn_publisher/overlay-nrf700x.conf b/samples/net/mqtt_sn_publisher/overlay-nrf700x.conf new file mode 100644 index 00000000000..cbc47b96572 --- /dev/null +++ b/samples/net/mqtt_sn_publisher/overlay-nrf700x.conf @@ -0,0 +1,20 @@ +CONFIG_POSIX_MAX_FDS=16 + +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/sockets/coap_client/overlay-nrf700x.conf b/samples/net/sockets/coap_client/overlay-nrf700x.conf new file mode 100644 index 00000000000..a0e436e3537 --- /dev/null +++ b/samples/net/sockets/coap_client/overlay-nrf700x.conf @@ -0,0 +1,16 @@ +CONFIG_HEAP_MEM_POOL_SIZE=153000 + +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/sockets/coap_server/overlay-nrf700x.conf b/samples/net/sockets/coap_server/overlay-nrf700x.conf new file mode 100644 index 00000000000..4817a4f73ba --- /dev/null +++ b/samples/net/sockets/coap_server/overlay-nrf700x.conf @@ -0,0 +1,26 @@ +CONFIG_HEAP_MEM_POOL_SIZE=153000 + +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# The sample can run either IPv4 or IPv6, not both +CONFIG_NET_IPV6=n +CONFIG_NET_CONFIG_NEED_IPV6=n +CONFIG_NET_IPV4=y +CONFIG_NET_CONFIG_NEED_IPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/sockets/echo/overlay-nrf700x.conf b/samples/net/sockets/echo/overlay-nrf700x.conf new file mode 100644 index 00000000000..aa59e5d5ea2 --- /dev/null +++ b/samples/net/sockets/echo/overlay-nrf700x.conf @@ -0,0 +1,18 @@ +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/sockets/echo_async/overlay-nrf700x.conf b/samples/net/sockets/echo_async/overlay-nrf700x.conf new file mode 100644 index 00000000000..aa59e5d5ea2 --- /dev/null +++ b/samples/net/sockets/echo_async/overlay-nrf700x.conf @@ -0,0 +1,18 @@ +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/sockets/echo_client/overlay-nrf700x.conf b/samples/net/sockets/echo_client/overlay-nrf700x.conf new file mode 100644 index 00000000000..cbc47b96572 --- /dev/null +++ b/samples/net/sockets/echo_client/overlay-nrf700x.conf @@ -0,0 +1,20 @@ +CONFIG_POSIX_MAX_FDS=16 + +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/sockets/echo_server/overlay-nrf700x.conf b/samples/net/sockets/echo_server/overlay-nrf700x.conf new file mode 100644 index 00000000000..cbc47b96572 --- /dev/null +++ b/samples/net/sockets/echo_server/overlay-nrf700x.conf @@ -0,0 +1,20 @@ +CONFIG_POSIX_MAX_FDS=16 + +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/sockets/http_get/overlay-nrf700x.conf b/samples/net/sockets/http_get/overlay-nrf700x.conf new file mode 100644 index 00000000000..aa59e5d5ea2 --- /dev/null +++ b/samples/net/sockets/http_get/overlay-nrf700x.conf @@ -0,0 +1,18 @@ +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/sockets/sntp_client/overlay-nrf700x.conf b/samples/net/sockets/sntp_client/overlay-nrf700x.conf new file mode 100644 index 00000000000..aa59e5d5ea2 --- /dev/null +++ b/samples/net/sockets/sntp_client/overlay-nrf700x.conf @@ -0,0 +1,18 @@ +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/syslog_net/overlay-nrf700x.conf b/samples/net/syslog_net/overlay-nrf700x.conf new file mode 100644 index 00000000000..aa59e5d5ea2 --- /dev/null +++ b/samples/net/syslog_net/overlay-nrf700x.conf @@ -0,0 +1,18 @@ +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" diff --git a/samples/net/telnet/overlay-nrf700x.conf b/samples/net/telnet/overlay-nrf700x.conf new file mode 100644 index 00000000000..aa59e5d5ea2 --- /dev/null +++ b/samples/net/telnet/overlay-nrf700x.conf @@ -0,0 +1,18 @@ +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WPA_SUPP=y +CONFIG_NET_L2_ETHERNET=y + +# DHCPv4 +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_DHCPV4=y + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" From 132cee61e6ce404b25dbc626b57b5df149c136a8 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Fri, 18 Aug 2023 10:20:45 +0200 Subject: [PATCH 0033/1623] [nrf noup] modules: mbedtls: Fix key support Kconfig PSA_HAS_KEY_SUPPORT was missing the DH_PUBLIC_KEY only Kconfig as the KEY_PAIR was double in there Signed-off-by: Markus Swarowsky (cherry picked from commit 53c4b20c15611a9d13b91e5dc025733d6dd65adb) --- modules/mbedtls/Kconfig.psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index b0d21685f70..0d43f112aeb 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -47,7 +47,7 @@ config PSA_HAS_KEY_SUPPORT PSA_WANT_KEY_TYPE_RSA_KEY_PAIR || \ PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY || \ PSA_WANT_KEY_TYPE_DH_KEY_PAIR || \ - PSA_WANT_KEY_TYPE_DH_KEY_PAIR + PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY config PSA_WANT_KEY_TYPE_DERIVE bool "PSA derive key type support" From d44fdf9127f611edd051a893c85992d0ace9be7f Mon Sep 17 00:00:00 2001 From: Rubin Gerritsen Date: Fri, 11 Aug 2023 15:37:25 +0200 Subject: [PATCH 0034/1623] [nrf noup] ci: Only run lwm2m tests when needed There is no need to run those for all PRs. For example: When there are only changes to Bluetooth, we don't want this CI to run. Adding these filters may speedup the time to merge for PRs to sdk-nrf Signed-off-by: Rubin Gerritsen (cherry picked from commit 78106c74f4ac7936ef78dcddb8c6e1e578fe41dd) --- .github/test-spec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 5dd281919bc..53b811f9ae0 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -21,7 +21,7 @@ - "subsys/testsuite/ztest/**/*" "CI-lwm2m-test": - - "**/*" +# Not necessary to run tests on changes to this repo. "CI-boot-dfu-test": - "subsys/mgmt/mcumgr/**/*" From 00175bd6e6a27a9b52875cf417398f657889c535 Mon Sep 17 00:00:00 2001 From: Jorgen Kvalvaag Date: Thu, 24 Aug 2023 10:03:43 +0200 Subject: [PATCH 0035/1623] [nrf noup] ci: Update Thingy91 test-spec entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thingy91 CI tests dependencies added. Signed-off-by: Jørgen Kvalvaag (cherry picked from commit 6a0df6f20645130ef3bf90b8c2ec605510d9b125) --- .github/test-spec.yml | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 53b811f9ae0..ce1d40b330e 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -52,7 +52,37 @@ - "include/dfu/**/*" "CI-thingy91-test": - - "**/*" + - "boards/arm/nrf9160dk_nrf9160/**/*" + - "arch/x86/core/**/*" + - "arch/x86/include/**/*" + - "drivers/console/**/*" + - "drivers/ethernet/**/*" + - "drivers/flash/**/*" + - "drivers/hwinfo/**/*" + - "drivers/interrupt_controller/**/*" + - "drivers/net/**/*" + - "drivers/serial/**/*" + - "drivers/timer/**/*" + - "include/**/*" + - "kernel/**/*" + - "lib/libc/common/source/stdlib/**/*" + - "lib/libc/newlib/**/*" + - "lib/libc/picolibc/**/*" + - "lib/os/**/*" + - "lib/posix/**/*" + - "misc/**/*" + - "modules/mbedtls/**/*" + - "soc/x86/ia32/**/*" + - "subsys/fs/fcb/**/*" + - "subsys/logging/**/*" + - "subsys/net/**/*" + - "subsys/random/**/*" + - "subsys/settings/include/**/*" + - "subsys/settings/src/**/*" + - "subsys/stats/**/*" + - "subsys/storage/flash_map/**/*" + - "subsys/storage/stream/**/*" + - "subsys/tracing/**/*" "CI-desktop-test": - "**/*" From fe45e34a7acb0709bbe9d0acf15d35405fdb03e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magne=20V=C3=A6rnes?= Date: Wed, 23 Aug 2023 16:10:42 +0200 Subject: [PATCH 0036/1623] [nrf noup] ci: Only run crypto and tf-m tests when needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extended the github CI filter for crypto and TF-M tests to reduce the CI load and possibly speed up PRs. Signed-off-by: Magne Værnes (cherry picked from commit c0d21ea8df1bce0d1bc2774a8e7348f3fc90271f) --- .github/test-spec.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index ce1d40b330e..102642d4216 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -31,7 +31,13 @@ - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" "CI-tfm-test": - - "**/*" + - "boards/arm/nrf5340dk_nrf5340/**/*" + - "boards/arm/nrf9160dk_nrf9160/**/*" + - "drivers/entropy/*" + - "dts/arm/nordic/nrf5340*" + - "dts/arm/nordic/nrf9160*" + - "modules/trusted-firmware-m/**/*" + - "samples/tfm_integration/**/*" "CI-ble-test": - "**/*" @@ -88,7 +94,16 @@ - "**/*" "CI-crypto-test": - - "**/*" + - "boards/arm/nrf52840dk_nrf52840/**/*" + - "boards/arm/nrf5340dk_nrf5340/**/*" + - "boards/arm/nrf9160dk_nrf9160/**/*" + - "drivers/entropy/*" + - "drivers/serial/**/*" + - "dts/arm/nordic/nrf52840*" + - "dts/arm/nordic/nrf5340*" + - "dts/arm/nordic/nrf9160*" + - "include/drivers/serial/**/*" + - "modules/mbedtls/**/*" "CI-fem-test": - "**/*" From 090fedd22fbc95498a3540ed63832934d0e66da6 Mon Sep 17 00:00:00 2001 From: Tomasz Tyzenhauz Date: Fri, 25 Aug 2023 13:27:53 +0200 Subject: [PATCH 0037/1623] [nrf noup] ci: Add Sidewalk to test-spec Add Sidewalk to be trigger on changes in this repo. Correct entry path for hci_rpmsg samples for Matter and Homekit. Signed-off-by: Tomasz Tyzenhauz (cherry picked from commit cd4e36f63fd444d1e850894ca743ee8e9654fc1a) --- .github/test-spec.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 102642d4216..7c4d93cd038 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -119,7 +119,7 @@ - "subsys/settings/**/*" - "subsys/net/lib/openthread/**/*" - "subsys/mgmt/mcumgr/**/*" - - "samples/hci_rpmsg/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" - any: - "subsys/bluetooth/**/*" @@ -140,7 +140,7 @@ - "subsys/net/**/*" - "subsys/mgmt/mcumgr/**/*" - "drivers/net/**/*" - - "samples/hci_rpmsg/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" - any: - "subsys/bluetooth/**/*" - "!subsys/bluetooth/mesh/**/*" @@ -193,3 +193,16 @@ "CI-wifi": - "subsys/net/l2/wifi/**/*" - "subsys/net/l2/ethernet/**/*" + +"CI-sidewalk-test": + - "include/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/dfu/**/*" + - "subsys/settings/**/*" + - "subsys/mgmt/mcumgr/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" + - any: + - "subsys/bluetooth/**/*" + - "!subsys/bluetooth/mesh/**/*" + - "!subsys/bluetooth/audio/**/*" From d6bb133392a74f9e71a39f8d8cd0ff99501edd8a Mon Sep 17 00:00:00 2001 From: Lang Xie Date: Fri, 8 Sep 2023 13:13:41 +0200 Subject: [PATCH 0038/1623] [nrf noup] ci: Update ble and mesh test-spec entry Add BLE CI test dependency and update the include path of mesh. Signed-off-by: Lang Xie (cherry picked from commit 02956222c991e2c036810a5e39fd60e72aa75866) --- .github/test-spec.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 7c4d93cd038..f81ac31cf75 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -40,11 +40,31 @@ - "samples/tfm_integration/**/*" "CI-ble-test": - - "**/*" + - any: + - "drivers/bluetooth/**/*" + - any: + - "dts/arm/nordic/nrf5*" + - any: + - "subsys/bluetooth/**/*" + - "!subsys/bluetooth/mesh/**/*" + - "!subsys/bluetooth/audio/**/*" + - any: + - "include/zephyr/bluetooth/**/*" + - "!include/zephyr/bluetooth/mesh/**/*" + - any: + - "samples/bluetooth/**/*" + - "!samples/bluetooth/mesh/**/*" + - "!samples/bluetooth/mesh_demo/**/*" + - "!samples/bluetooth/mesh_provisioner/**/*" + - any: + - "tests/bluetooth/**/*" + - "!tests/bluetooth/mesh/**/*" + - "!tests/bluetooth/mesh_shell/**/*" + - "!tests/bluetooth/audio/**/*" "CI-mesh-test": - "subsys/bluetooth/mesh/**/*" - - "include/bluetooth/mesh/**/*" + - "include/zephyr/bluetooth/mesh/**/*" - "samples/bluetooth/mesh/**/*" - "samples/bluetooth/mesh_demo/**/*" - "samples/bluetooth/mesh_provisioner/**/*" From 83d5224ee0287aa5a9fe75a3cf90263a5f6fa8f0 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 5 Sep 2023 22:13:03 +0530 Subject: [PATCH 0039/1623] [nrf fromlist] net: Add priority to ping This is handy in testing of setting priority directly rather than deriving from DSCP. Please note ICMP doesn't use net context. This is applicable for both shell and API. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/62313 Signed-off-by: Chaitanya Tata (cherry picked from commit fac11d30f21e445af7b40625c285e66614a22cfb) --- subsys/net/ip/icmpv4.c | 15 +++++++++++++-- subsys/net/ip/icmpv4.h | 3 +++ subsys/net/ip/icmpv6.c | 15 +++++++++++++-- subsys/net/ip/icmpv6.h | 3 +++ subsys/net/ip/net_shell.c | 15 ++++++++++++++- subsys/net/lib/zperf/zperf_shell.c | 2 +- 6 files changed, 47 insertions(+), 6 deletions(-) diff --git a/subsys/net/ip/icmpv4.c b/subsys/net/ip/icmpv4.c index 5c3d844be8a..058233a7f97 100644 --- a/subsys/net/ip/icmpv4.c +++ b/subsys/net/ip/icmpv4.c @@ -507,6 +507,7 @@ int net_icmpv4_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tos, + int priority, const void *data, size_t data_size) { @@ -537,8 +538,18 @@ int net_icmpv4_send_echo_request(struct net_if *iface, return -ENOMEM; } - net_pkt_set_ip_dscp(pkt, net_ipv4_get_dscp(tos)); - net_pkt_set_ip_ecn(pkt, net_ipv4_get_ecn(tos)); + if (priority > NET_MAX_PRIORITIES) { + NET_ERR("Priority %d is too large, maximum is %d", + priority, NET_MAX_PRIORITIES); + return -EINVAL; + } + + if (priority < 0) { + net_pkt_set_ip_dscp(pkt, net_ipv4_get_dscp(tos)); + net_pkt_set_ip_ecn(pkt, net_ipv4_get_ecn(tos)); + } else { + net_pkt_set_priority(pkt, priority); + } if (net_ipv4_create(pkt, src, dst) || icmpv4_create(pkt, NET_ICMPV4_ECHO_REQUEST, 0)) { diff --git a/subsys/net/ip/icmpv4.h b/subsys/net/ip/icmpv4.h index bfce2e8d9e6..492fc6e84a0 100644 --- a/subsys/net/ip/icmpv4.h +++ b/subsys/net/ip/icmpv4.h @@ -82,6 +82,7 @@ int net_icmpv4_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tos, + int priority, const void *data, size_t data_size); #else @@ -90,6 +91,7 @@ static inline int net_icmpv4_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tos, + int priority, const void *data, size_t data_size) { @@ -98,6 +100,7 @@ static inline int net_icmpv4_send_echo_request(struct net_if *iface, ARG_UNUSED(identifier); ARG_UNUSED(sequence); ARG_UNUSED(tos); + ARG_UNUSED(priority); ARG_UNUSED(data); ARG_UNUSED(data_size); diff --git a/subsys/net/ip/icmpv6.c b/subsys/net/ip/icmpv6.c index 95252a7c156..f1286229536 100644 --- a/subsys/net/ip/icmpv6.c +++ b/subsys/net/ip/icmpv6.c @@ -341,6 +341,7 @@ int net_icmpv6_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tc, + int priority, const void *data, size_t data_size) { @@ -362,8 +363,18 @@ int net_icmpv6_send_echo_request(struct net_if *iface, return -ENOMEM; } - net_pkt_set_ip_dscp(pkt, net_ipv6_get_dscp(tc)); - net_pkt_set_ip_ecn(pkt, net_ipv6_get_ecn(tc)); + if (priority > NET_MAX_PRIORITIES) { + NET_ERR("Priority %d is too large, maximum is %d", + priority, NET_MAX_PRIORITIES); + return -EINVAL; + } + + if (priority < 0) { + net_pkt_set_ip_dscp(pkt, net_ipv6_get_dscp(tc)); + net_pkt_set_ip_ecn(pkt, net_ipv6_get_ecn(tc)); + } else { + net_pkt_set_priority(pkt, priority); + } if (net_ipv6_create(pkt, src, dst) || net_icmpv6_create(pkt, NET_ICMPV6_ECHO_REQUEST, 0)) { diff --git a/subsys/net/ip/icmpv6.h b/subsys/net/ip/icmpv6.h index f0c586a7cf8..d71d9959c14 100644 --- a/subsys/net/ip/icmpv6.h +++ b/subsys/net/ip/icmpv6.h @@ -222,6 +222,7 @@ int net_icmpv6_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tc, + int priority, const void *data, size_t data_size); #else @@ -230,6 +231,7 @@ static inline int net_icmpv6_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tc, + int priority, const void *data, size_t data_size) { @@ -238,6 +240,7 @@ static inline int net_icmpv6_send_echo_request(struct net_if *iface, ARG_UNUSED(identifier); ARG_UNUSED(sequence); ARG_UNUSED(tc); + ARG_UNUSED(priority); ARG_UNUSED(data); ARG_UNUSED(data_size); diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index 286d0eca8a9..c5b07afd6aa 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -4279,6 +4279,7 @@ static struct ping_context { uint32_t sequence; uint16_t payload_size; uint8_t tos; + int priority; } ping_ctx; static void ping_done(struct ping_context *ctx); @@ -4504,6 +4505,7 @@ static void ping_work(struct k_work *work) sys_rand32_get(), ctx->sequence, ctx->tos, + ctx->priority, NULL, ctx->payload_size); } else { @@ -4512,6 +4514,7 @@ static void ping_work(struct k_work *work) sys_rand32_get(), ctx->sequence, ctx->tos, + ctx->priority, NULL, ctx->payload_size); } @@ -4612,6 +4615,7 @@ static int cmd_net_ping(const struct shell *sh, size_t argc, char *argv[]) int iface_idx = -1; int tos = 0; int payload_size = 4; + int priority = -1; for (size_t i = 1; i < argc; ++i) { @@ -4647,6 +4651,14 @@ static int cmd_net_ping(const struct shell *sh, size_t argc, char *argv[]) } break; + case 'p': + priority = parse_arg(&i, argc, argv); + if (priority < 0 || priority > UINT8_MAX) { + PR_WARNING("Parse error: %s\n", argv[i]); + return -ENOEXEC; + } + break; + case 'Q': tos = parse_arg(&i, argc, argv); if (tos < 0 || tos > UINT8_MAX) { @@ -4683,6 +4695,7 @@ static int cmd_net_ping(const struct shell *sh, size_t argc, char *argv[]) ping_ctx.sh = sh; ping_ctx.count = count; ping_ctx.interval = interval; + ping_ctx.priority = priority; ping_ctx.tos = tos; ping_ctx.payload_size = payload_size; @@ -6584,7 +6597,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_vlan, SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_ping, SHELL_CMD(--help, NULL, "'net ping [-c count] [-i interval ms] [-I ] " - "[-Q tos] [-s payload size] ' " + "[-Q tos] [-s payload size] [-p priority] ' " "Send ICMPv4 or ICMPv6 Echo-Request to a network host.", cmd_net_ping), SHELL_SUBCMD_SET_END diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index a30caf08074..d3bf11a7b33 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -526,7 +526,7 @@ static int execute_upload(const struct shell *sh, * some time and start the test after that. */ net_icmpv6_send_echo_request(net_if_get_default(), - &ipv6->sin6_addr, 0, 0, 0, NULL, 0); + &ipv6->sin6_addr, 0, 0, 0, -1, NULL, 0); k_sleep(K_SECONDS(1)); } From 1675a8a5e9536587b9225953e08dcb286425d79d Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 8 Sep 2023 00:37:27 +0530 Subject: [PATCH 0040/1623] [nrf fromlist] net: Add configuration option to allow any priority This adds support to allow any priority from the user instead of limiting to the protocol values (0-7). This is useful in conveying custom priorities from application to the driver/chipset. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/62313 Signed-off-by: Chaitanya Tata (cherry picked from commit 1977a04ac80bfe471c534eab0214ea48d5d09b63) --- subsys/net/ip/Kconfig | 6 ++++++ subsys/net/ip/icmpv4.c | 3 ++- subsys/net/ip/icmpv6.c | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/subsys/net/ip/Kconfig b/subsys/net/ip/Kconfig index d7edb988553..d2ca36b845c 100644 --- a/subsys/net/ip/Kconfig +++ b/subsys/net/ip/Kconfig @@ -290,6 +290,12 @@ config NET_RX_DEFAULT_PRIORITY What is the default network RX packet priority if user has not set one. The value 0 means lowest priority and 7 is the highest. +config NET_ALLOW_ANY_PRIORITY + bool "Allow any network packet priority to be used" + help + If this is set, then any user given network packet priority can be used. Otherwise + the network packet priorities are limited to 0-7 range. + config NET_IP_ADDR_CHECK bool "Check IP address validity before sending IP packet" default y diff --git a/subsys/net/ip/icmpv4.c b/subsys/net/ip/icmpv4.c index 058233a7f97..ed69903bd8e 100644 --- a/subsys/net/ip/icmpv4.c +++ b/subsys/net/ip/icmpv4.c @@ -538,12 +538,13 @@ int net_icmpv4_send_echo_request(struct net_if *iface, return -ENOMEM; } +#if !defined(CONFIG_NET_ALLOW_ANY_PRIORITY) if (priority > NET_MAX_PRIORITIES) { NET_ERR("Priority %d is too large, maximum is %d", priority, NET_MAX_PRIORITIES); return -EINVAL; } - +#endif /* !CONFIG_NET_ALLOW_ANY_PRIORITY */ if (priority < 0) { net_pkt_set_ip_dscp(pkt, net_ipv4_get_dscp(tos)); net_pkt_set_ip_ecn(pkt, net_ipv4_get_ecn(tos)); diff --git a/subsys/net/ip/icmpv6.c b/subsys/net/ip/icmpv6.c index f1286229536..9abc034e1fb 100644 --- a/subsys/net/ip/icmpv6.c +++ b/subsys/net/ip/icmpv6.c @@ -363,11 +363,13 @@ int net_icmpv6_send_echo_request(struct net_if *iface, return -ENOMEM; } +#if !defined(CONFIG_NET_ALLOW_ANY_PRIORITY) if (priority > NET_MAX_PRIORITIES) { NET_ERR("Priority %d is too large, maximum is %d", priority, NET_MAX_PRIORITIES); return -EINVAL; } +#endif /* !CONFIG_NET_ALLOW_ANY_PRIORITY */ if (priority < 0) { net_pkt_set_ip_dscp(pkt, net_ipv6_get_dscp(tc)); From 427badb22bfd80c63a691163b2d355bb1e3028a5 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 8 Sep 2023 00:57:26 +0530 Subject: [PATCH 0041/1623] [nrf fromlist] zperf: Add support to configure context priority This is handy in setting a custom priority for the context either through shell or API. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/62313 Signed-off-by: Chaitanya Tata (cherry picked from commit f48f184514f8fb2adbc92d03e6a3a44c5b56d1e0) --- include/zephyr/net/zperf.h | 1 + subsys/net/lib/zperf/zperf_common.c | 20 +++++++++++- subsys/net/lib/zperf/zperf_internal.h | 2 +- subsys/net/lib/zperf/zperf_shell.c | 39 +++++++++++++++++++++++ subsys/net/lib/zperf/zperf_tcp_uploader.c | 2 +- subsys/net/lib/zperf/zperf_udp_uploader.c | 2 +- 6 files changed, 62 insertions(+), 4 deletions(-) diff --git a/include/zephyr/net/zperf.h b/include/zephyr/net/zperf.h index 447ffec670c..cd86541721e 100644 --- a/include/zephyr/net/zperf.h +++ b/include/zephyr/net/zperf.h @@ -37,6 +37,7 @@ struct zperf_upload_params { struct { uint8_t tos; int tcp_nodelay; + int priority; } options; }; diff --git a/subsys/net/lib/zperf/zperf_common.c b/subsys/net/lib/zperf/zperf_common.c index aa29bc99043..efe36cf69cd 100644 --- a/subsys/net/lib/zperf/zperf_common.c +++ b/subsys/net/lib/zperf/zperf_common.c @@ -131,7 +131,7 @@ const struct in6_addr *zperf_get_default_if_in6_addr(void) } int zperf_prepare_upload_sock(const struct sockaddr *peer_addr, int tos, - int proto) + int priority, int proto) { socklen_t addrlen = peer_addr->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : @@ -192,6 +192,24 @@ int zperf_prepare_upload_sock(const struct sockaddr *peer_addr, int tos, return -EINVAL; } + if (IS_ENABLED(CONFIG_NET_CONTEXT_PRIORITY) && priority >= 0) { + uint8_t prio = priority; + + if (!IS_ENABLED(CONFIG_NET_ALLOW_ANY_PRIORITY) && + (prio > NET_MAX_PRIORITIES)) { + NET_ERR("Priority %d is too large, maximum is %d", + priority, NET_MAX_PRIORITIES); + return -EINVAL; + } + + if (zsock_setsockopt(sock, SOL_SOCKET, SO_PRIORITY, + &prio, + sizeof(prio)) != 0) { + NET_WARN("Failed to set SOL_SOCKET - SO_PRIORITY socket option."); + return -EINVAL; + } + } + ret = zsock_connect(sock, peer_addr, addrlen); if (ret < 0) { NET_ERR("Connect failed (%d)", errno); diff --git a/subsys/net/lib/zperf/zperf_internal.h b/subsys/net/lib/zperf/zperf_internal.h index 5bef0331f6f..96dd9ea9123 100644 --- a/subsys/net/lib/zperf/zperf_internal.h +++ b/subsys/net/lib/zperf/zperf_internal.h @@ -99,7 +99,7 @@ const struct in_addr *zperf_get_default_if_in4_addr(void); const struct in6_addr *zperf_get_default_if_in6_addr(void); int zperf_prepare_upload_sock(const struct sockaddr *peer_addr, int tos, - int proto); + int priority, int proto); uint32_t zperf_packet_duration(uint32_t packet_size, uint32_t rate_in_kbps); diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index d3bf11a7b33..3a8a9c61c4b 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -642,6 +642,7 @@ static int shell_cmd_upload(const struct shell *sh, size_t argc, int start = 0; size_t opt_cnt = 0; + param.options.priority = -1; is_udp = proto == IPPROTO_UDP; /* Parse options */ @@ -680,6 +681,19 @@ static int shell_cmd_upload(const struct shell *sh, size_t argc, opt_cnt += 1; break; +#ifdef CONFIG_NET_CONTEXT_PRIORITY + case 'p': + param.options.priority = parse_arg(&i, argc, argv); + if (param.options.priority < 0 || + param.options.priority > UINT8_MAX) { + shell_fprintf(sh, SHELL_WARNING, + "Parse error: %s\n", argv[i]); + return -ENOEXEC; + } + opt_cnt += 2; + break; +#endif /* CONFIG_NET_CONTEXT_PRIORITY */ + default: shell_fprintf(sh, SHELL_WARNING, "Unrecognized argument: %s\n", argv[i]); @@ -853,6 +867,19 @@ static int shell_cmd_upload2(const struct shell *sh, size_t argc, opt_cnt += 1; break; +#ifdef CONFIG_NET_CONTEXT_PRIORITY + case 'p': + param.options.priority = parse_arg(&i, argc, argv); + if (param.options.priority == -1 || + param.options.priority > UINT8_MAX) { + shell_fprintf(sh, SHELL_WARNING, + "Parse error: %s\n", argv[i]); + return -ENOEXEC; + } + opt_cnt += 2; + break; +#endif /* CONFIG_NET_CONTEXT_PRIORITY */ + default: shell_fprintf(sh, SHELL_WARNING, "Unrecognized argument: %s\n", argv[i]); @@ -1146,6 +1173,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_tcp, "-S tos: Specify IPv4/6 type of service\n" "-a: Asynchronous call (shell will not block for the upload)\n" "-n: Disable Nagle's algorithm\n" +#ifdef CONFIG_NET_CONTEXT_PRIORITY + "-p: Specify custom packet priority\n" +#endif /* CONFIG_NET_CONTEXT_PRIORITY */ "Example: tcp upload 192.0.2.2 1111 1 1K\n" "Example: tcp upload 2001:db8::2\n", cmd_tcp_upload), @@ -1159,6 +1189,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_tcp, "Available options:\n" "-S tos: Specify IPv4/6 type of service\n" "-a: Asynchronous call (shell will not block for the upload)\n" +#ifdef CONFIG_NET_CONTEXT_PRIORITY + "-p: Specify custom packet priority\n" +#endif /* CONFIG_NET_CONTEXT_PRIORITY */ "Example: tcp upload2 v6 1 1K\n" "Example: tcp upload2 v4\n" "-n: Disable Nagle's algorithm\n" @@ -1198,6 +1231,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp, "Available options:\n" "-S tos: Specify IPv4/6 type of service\n" "-a: Asynchronous call (shell will not block for the upload)\n" +#ifdef CONFIG_NET_CONTEXT_PRIORITY + "-p: Specify custom packet priority\n" +#endif /* CONFIG_NET_CONTEXT_PRIORITY */ "Example: udp upload 192.0.2.2 1111 1 1K 1M\n" "Example: udp upload 2001:db8::2\n", cmd_udp_upload), @@ -1212,6 +1248,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp, "Available options:\n" "-S tos: Specify IPv4/6 type of service\n" "-a: Asynchronous call (shell will not block for the upload)\n" +#ifdef CONFIG_NET_CONTEXT_PRIORITY + "-p: Specify custom packet priority\n" +#endif /* CONFIG_NET_CONTEXT_PRIORITY */ "Example: udp upload2 v4 1 1K 1M\n" "Example: udp upload2 v6\n" #if defined(CONFIG_NET_IPV6) && defined(MY_IP6ADDR_SET) diff --git a/subsys/net/lib/zperf/zperf_tcp_uploader.c b/subsys/net/lib/zperf/zperf_tcp_uploader.c index 97fd4f57f71..3e72f81e54b 100644 --- a/subsys/net/lib/zperf/zperf_tcp_uploader.c +++ b/subsys/net/lib/zperf/zperf_tcp_uploader.c @@ -117,7 +117,7 @@ int zperf_tcp_upload(const struct zperf_upload_params *param, } sock = zperf_prepare_upload_sock(¶m->peer_addr, param->options.tos, - IPPROTO_TCP); + param->options.priority, IPPROTO_TCP); if (sock < 0) { return sock; } diff --git a/subsys/net/lib/zperf/zperf_udp_uploader.c b/subsys/net/lib/zperf/zperf_udp_uploader.c index 1310063437b..e7e2efb9a08 100644 --- a/subsys/net/lib/zperf/zperf_udp_uploader.c +++ b/subsys/net/lib/zperf/zperf_udp_uploader.c @@ -284,7 +284,7 @@ int zperf_udp_upload(const struct zperf_upload_params *param, } sock = zperf_prepare_upload_sock(¶m->peer_addr, param->options.tos, - IPPROTO_UDP); + param->options.priority, IPPROTO_UDP); if (sock < 0) { return sock; } From 6340daeb1824fa7f92d2e847d0eb68be53b21d51 Mon Sep 17 00:00:00 2001 From: Mariusz Poslinski Date: Tue, 5 Sep 2023 09:43:10 +0200 Subject: [PATCH 0042/1623] [nrf noup] ci: Update Thread test-spec entry Update Thread test-spec entry. Signed-off-by: Mariusz Poslinski (cherry picked from commit 81c640bcccce83f83573234ca1725e6d5576e9c2) --- .github/test-spec.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index f81ac31cf75..03e02441069 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -146,7 +146,11 @@ - "!subsys/bluetooth/mesh/**/*" "CI-thread-test": - - "**/*" + - "subsys/net/**/*" + - "modules/mbedtls/**/*" + - "include/zephyr/net/**/*" + - "modules/openthread/**/*" + - "samples/net/openthread/**/*" "CI-nfc-test": - "**/*" From 488716469816d193dd5b7ffb53d9eb57dfa36c5a Mon Sep 17 00:00:00 2001 From: Mariusz Poslinski Date: Mon, 18 Sep 2023 12:48:52 +0200 Subject: [PATCH 0043/1623] [nrf noup] ci: Update Thread test-spec entry Update Thread and HomeKit test-spec entries. Signed-off-by: Mariusz Poslinski (cherry picked from commit 4c741f1e2d2542ab23891fff46ed93add2893740) --- .github/test-spec.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 03e02441069..62b92e74d0f 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -132,25 +132,24 @@ - "**/*" "CI-homekit-test": - - "include/dfu/**/*" - - "include/mgmt/mcumgr/**/*" + - "modules/openthread/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" - "soc/arm/nordic_nrf/**/*" - - "subsys/dfu/**/*" + - "subsys/net/**/*" - "subsys/settings/**/*" - - "subsys/net/lib/openthread/**/*" - - "subsys/mgmt/mcumgr/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" - - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" - any: - "subsys/bluetooth/**/*" - "!subsys/bluetooth/mesh/**/*" + - "!subsys/bluetooth/audio/**/*" "CI-thread-test": - - "subsys/net/**/*" - - "modules/mbedtls/**/*" - "include/zephyr/net/**/*" + - "modules/mbedtls/**/*" - "modules/openthread/**/*" - "samples/net/openthread/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/net/**/*" + - "subsys/settings/**/*" "CI-nfc-test": - "**/*" From 41b1428e720e72bdbea7b811840038b41be5e12b Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 8 Sep 2023 14:57:48 +0100 Subject: [PATCH 0044/1623] [nrf fromtree] bluetooth: Make long workqueue init priority configurable Makes the long workqueue init priority configurable and sets the default to 50, this is to allow for relocating bluetooth libraries to other parts of memory e.g. external flash, and allows for those flash drivers to be initialised prior to calling functions residing in them. Signed-off-by: Jamie McCrae (cherry picked from commit da967225528ab7dee89b9696fd8020d80ef76a9a) (cherry picked from commit 347e737db454531065216034597db91bd4696c2a) --- subsys/bluetooth/host/Kconfig | 7 +++++++ subsys/bluetooth/host/long_wq.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 19754705200..a4cf2e0959b 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -23,6 +23,13 @@ config BT_LONG_WQ_PRIO int "Long workqueue priority. Should be pre-emptible." default 10 range 0 NUM_PREEMPT_PRIORITIES + +config BT_LONG_WQ_INIT_PRIO + int "Long workqueue init priority" + default 50 + help + Init priority level to setup the long workqueue. + endif # BT_LONG_WQ config BT_HCI_HOST diff --git a/subsys/bluetooth/host/long_wq.c b/subsys/bluetooth/host/long_wq.c index 61f86d0c909..2136739c243 100644 --- a/subsys/bluetooth/host/long_wq.c +++ b/subsys/bluetooth/host/long_wq.c @@ -40,4 +40,4 @@ static int long_wq_init(void) return 0; } -SYS_INIT(long_wq_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); +SYS_INIT(long_wq_init, POST_KERNEL, CONFIG_BT_LONG_WQ_INIT_PRIO); From f769ab6e3e3a96d83aa9ba22bf827840da97e5b9 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 8 Sep 2023 14:53:45 +0100 Subject: [PATCH 0045/1623] [nrf fromtree] drivers: flash: nrf_qspi_nor: Add support for XIP at boot Adds support for forcing XIP support at boot time, and reduces the init priority of the driver so that it inits earlier. Signed-off-by: Jamie McCrae (cherry picked from commit 72167f2acfe12acf58040e63888159062e20145e) (cherry picked from commit 5cf24875cf668a6377bff18a26e195e1ef069299) --- drivers/flash/Kconfig.nordic_qspi_nor | 14 ++++++++++++-- drivers/flash/nrf_qspi_nor.c | 21 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/drivers/flash/Kconfig.nordic_qspi_nor b/drivers/flash/Kconfig.nordic_qspi_nor index 16252e0812c..7b9fa05eb7f 100644 --- a/drivers/flash/Kconfig.nordic_qspi_nor +++ b/drivers/flash/Kconfig.nordic_qspi_nor @@ -14,8 +14,8 @@ menuconfig NORDIC_QSPI_NOR if NORDIC_QSPI_NOR config NORDIC_QSPI_NOR_INIT_PRIORITY - int - default 80 + int "Init priority" + default 41 help Device driver initialization priority. @@ -39,4 +39,14 @@ config NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE if the data is larger than the configured size. Must be a multiple of 4. When set to 0, the feature is disabled. +config NORDIC_QSPI_NOR_XIP + bool "XIP (eXecute in place)" + depends on SOC_NRF5340_CPUAPP + help + Enable setting up the QSPI NOR driver to allow for execution of code + stored in QSPI XIP region. Note that for this functionality to work, + the QSPI NOR init priority must be set so that no XIP code in the + QSPI NOR flash chip is executed until the driver has been setup. + This will also disable power management for the QSPI NOR flash chip. + endif # NORDIC_QSPI_NOR diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index b2455ba3c6f..e2ce6e6a706 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -179,6 +179,8 @@ static bool qspi_initialized; static int qspi_device_init(const struct device *dev); static void qspi_device_uninit(const struct device *dev); +void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable); +void z_vrfy_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable); #define WORD_SIZE 4 @@ -1229,6 +1231,7 @@ static int qspi_nor_configure(const struct device *dev) */ static int qspi_nor_init(const struct device *dev) { + int rc; const struct qspi_nor_config *dev_config = dev->config; int ret = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); @@ -1238,7 +1241,19 @@ static int qspi_nor_init(const struct device *dev) IRQ_CONNECT(DT_IRQN(QSPI_NODE), DT_IRQ(QSPI_NODE, priority), nrfx_isr, nrfx_qspi_irq_handler, 0); - return qspi_nor_configure(dev); + + rc = qspi_nor_configure(dev); + +#ifdef CONFIG_NORDIC_QSPI_NOR_XIP + if (!rc) { + /* Enable XIP mode for QSPI NOR flash, this will prevent the + * flash from being powered down + */ + z_impl_nrf_qspi_nor_xip_enable(dev, true); + } +#endif + + return rc; } #if defined(CONFIG_FLASH_PAGE_LAYOUT) @@ -1369,6 +1384,10 @@ static int qspi_nor_pm_action(const struct device *dev, } #endif + if (dev_data->xip_enabled) { + return -EBUSY; + } + if (nrfx_qspi_mem_busy_check() != NRFX_SUCCESS) { return -EBUSY; } From ca0298cc20b632388a8cf75e166dde4a09987847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Audun=20Kvamtr=C3=B8?= Date: Mon, 31 Jan 2022 03:48:11 +0100 Subject: [PATCH 0046/1623] [nrf noup] modules: mbedtls: Disable configurations in Kconfig.tls-generic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -This commit prevents legacy mbed TLS configurations from being in conflict with PSA Configurations while using nrf_security -Removing use of unsupported TLS protocols (TLS 1.0, 1.1) -Required configurations are duplicated inside nrf_security Kconfig -Ensured that mbedtls_platform_zeroize is not duplicated when CONFIG_NRF_CC3XX_PLATFORM is set ref: NCSDK-13503 Signed-off-by: Frank Audun Kvamtrø Signed-off-by: Andrzej Głąbek (cherry picked from commit 84ee8c8015d1362b7888aeb7e0991e3f7092b35a) (cherry picked from commit ea5314da140b632aad85d39ea2dad02929ac83a5) Signed-off-by: Dominik Ermel (cherry picked from commit 8022c47f2ee2ca8c998bc44412ef2742535dcb74) [nrf noup] modules: mbedtls: Disable mbedtls_hardware_poll with CC3xx enabled Precompiled CC3xx libraries silently provide mbedtls_hardware_poll function (used internally by the library on initialization), which creates ambiguity with Zephyr-provided implementation. In result, the CC3xx entropy source is broken when CONFIG_MBEDTLS_ZEPHYR_ENTROPY is enabled. Workaround this, by disabling the Zephyr implementation if CC3xx is enabled, and let mbed TLS use the implementation from the CC library instead. Signed-off-by: Robert Lubos (cherry picked from commit e2ad826809bbcdeaa04f1edc2a57f21a0b2151ff) --- modules/mbedtls/Kconfig.tls-generic | 31 ++++++++++++++++++++ modules/mbedtls/configs/config-tls-generic.h | 4 +++ modules/mbedtls/zephyr_init.c | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/modules/mbedtls/Kconfig.tls-generic b/modules/mbedtls/Kconfig.tls-generic index 3c0e17c0fe3..d629c1b1d2a 100644 --- a/modules/mbedtls/Kconfig.tls-generic +++ b/modules/mbedtls/Kconfig.tls-generic @@ -9,6 +9,8 @@ menu "TLS configuration" menu "Supported TLS version" +if !(NRF_SECURITY || NORDIC_SECURITY_BACKEND) + config MBEDTLS_TLS_VERSION_1_0 bool "Support for TLS 1.0" select MBEDTLS_CIPHER @@ -33,6 +35,8 @@ config MBEDTLS_DTLS bool "Support for DTLS" depends on MBEDTLS_TLS_VERSION_1_1 || MBEDTLS_TLS_VERSION_1_2 +endif + config MBEDTLS_SSL_EXPORT_KEYS bool "Support for exporting SSL key block and master secret" depends on MBEDTLS_TLS_VERSION_1_0 || MBEDTLS_TLS_VERSION_1_1 || MBEDTLS_TLS_VERSION_1_2 @@ -47,6 +51,8 @@ menu "Ciphersuite configuration" comment "Supported key exchange modes" +if !(NRF_SECURITY || NORDIC_SECURITY_BACKEND) + config MBEDTLS_KEY_EXCHANGE_ALL_ENABLED bool "All available ciphersuite modes" select MBEDTLS_KEY_EXCHANGE_PSK_ENABLED @@ -81,6 +87,8 @@ config MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED || \ MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED +endif + config MBEDTLS_PSK_MAX_LEN int "Max size of TLS pre-shared keys" default 32 @@ -88,6 +96,8 @@ config MBEDTLS_PSK_MAX_LEN help Max size of TLS pre-shared keys, in bytes. +if !(NRF_SECURITY || NORDIC_SECURITY_BACKEND) + config MBEDTLS_KEY_EXCHANGE_RSA_ENABLED bool "RSA-only based ciphersuite modes" default y if !NET_L2_OPENTHREAD @@ -202,6 +212,7 @@ config MBEDTLS_ECP_NIST_OPTIM bool "NSIT curves optimization" endif +endif # !(NRF_SECURITY || NORDIC_SECURITY_BACKEND) comment "Supported hash" @@ -226,6 +237,8 @@ config MBEDTLS_HASH_SHA512_ENABLED comment "Supported cipher modes" +if !(NRF_SECURITY || NORDIC_SECURITY_BACKEND) + config MBEDTLS_CIPHER_ALL_ENABLED bool "All available ciphers" select MBEDTLS_CIPHER_AES_ENABLED @@ -299,8 +312,12 @@ config MBEDTLS_CHACHAPOLY_AEAD_ENABLED bool "ChaCha20-Poly1305 AEAD algorithm" depends on MBEDTLS_CIPHER_CHACHA20_ENABLED || MBEDTLS_MAC_POLY1305_ENABLED +endif + comment "Supported message authentication methods" +if !(NRF_SECURITY || NORDIC_SECURITY_BACKEND) + config MBEDTLS_MAC_ALL_ENABLED bool "All available MAC methods" select MBEDTLS_MAC_MD4_ENABLED @@ -349,10 +366,14 @@ config MBEDTLS_MAC_CMAC_ENABLED bool "CMAC (Cipher-based Message Authentication Code) mode for block ciphers." depends on MBEDTLS_CIPHER_AES_ENABLED || MBEDTLS_CIPHER_DES_ENABLED +endif + endmenu comment "Random number generators" +if !(NRF_SECURITY || NORDIC_SECURITY_BACKEND) + config MBEDTLS_CTR_DRBG_ENABLED bool "CTR_DRBG AES-256-based random generator" depends on MBEDTLS_CIPHER_AES_ENABLED @@ -362,14 +383,20 @@ config MBEDTLS_HMAC_DRBG_ENABLED bool "HMAC_DRBG random generator" select MBEDTLS_MD +endif + comment "Other configurations" config MBEDTLS_CIPHER bool "generic cipher layer." +if !(NRF_SECURITY || NORDIC_SECURITY_BACKEND) + config MBEDTLS_MD bool "generic message digest layer." +endif + config MBEDTLS_GENPRIME_ENABLED bool "prime-number generation code." @@ -387,11 +414,15 @@ config MBEDTLS_HAVE_ASM of asymmetric cryptography, however this might have an impact on the code size. +if !(NRF_SECURITY || NORDIC_SECURITY_BACKEND) + config MBEDTLS_ENTROPY_ENABLED bool "MbedTLS generic entropy pool" depends on MBEDTLS_MAC_SHA256_ENABLED || MBEDTLS_MAC_SHA384_ENABLED || MBEDTLS_MAC_SHA512_ENABLED default y if MBEDTLS_ZEPHYR_ENTROPY +endif + config MBEDTLS_OPENTHREAD_OPTIMIZATIONS_ENABLED bool "MbedTLS optimizations for OpenThread" depends on NET_L2_OPENTHREAD diff --git a/modules/mbedtls/configs/config-tls-generic.h b/modules/mbedtls/configs/config-tls-generic.h index 2268571abe0..7b437c23dcb 100644 --- a/modules/mbedtls/configs/config-tls-generic.h +++ b/modules/mbedtls/configs/config-tls-generic.h @@ -500,4 +500,8 @@ #include "mbedtls/check_config.h" #endif +#if defined(CONFIG_NRF_CC3XX_PLATFORM) +#define MBEDTLS_PLATFORM_ZEROIZE_ALT +#endif + #endif /* MBEDTLS_CONFIG_H */ diff --git a/modules/mbedtls/zephyr_init.c b/modules/mbedtls/zephyr_init.c index 70f7783e2ee..eec9d991c9b 100644 --- a/modules/mbedtls/zephyr_init.c +++ b/modules/mbedtls/zephyr_init.c @@ -45,7 +45,7 @@ static void init_heap(void) #define init_heap(...) #endif /* CONFIG_MBEDTLS_ENABLE_HEAP && MBEDTLS_MEMORY_BUFFER_ALLOC_C */ -#if defined(CONFIG_MBEDTLS_ZEPHYR_ENTROPY) +#if defined(CONFIG_MBEDTLS_ZEPHYR_ENTROPY) && !defined(CONFIG_NRF_CC3XX_PLATFORM) static const struct device *const entropy_dev = DEVICE_DT_GET_OR_NULL(DT_CHOSEN(zephyr_entropy)); From 063b584e78395eb02a1e7cbd82a0ed3251b383f3 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Thu, 23 Jun 2022 14:10:01 +0000 Subject: [PATCH 0047/1623] [nrf noup] mgmt/mcumgr: Bootutil hooks to handle image-1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The commit adds bootutil hook, for nrf5340, to allow it handling the non-accessible image-1/primary slot. Signed-off-by: Andrzej Głąbek Signed-off-by: Vinayak Kariappa Chettimada Signed-off-by: Johann Fischer (cherry picked from commit 840b8fa1dba3ddda02fa1652a9408b08b7c310de) (cherry picked from commit 9af7d7ad2f70cee26ccc98b4daadd2260662ff78) (cherry picked from commit 298d8037d2b60b4ca4dd8b2a7727196e33054dd8) Signed-off-by: Dominik Ermel (cherry picked from commit d3aa849948ce548ba46ddb7f6ec0b4422fa53db4) --- subsys/mgmt/mcumgr/CMakeLists.txt | 8 ++++++ subsys/mgmt/mcumgr/Kconfig | 1 + .../mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c | 27 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c diff --git a/subsys/mgmt/mcumgr/CMakeLists.txt b/subsys/mgmt/mcumgr/CMakeLists.txt index 39d4a4ca8ce..ad088eca067 100644 --- a/subsys/mgmt/mcumgr/CMakeLists.txt +++ b/subsys/mgmt/mcumgr/CMakeLists.txt @@ -16,3 +16,11 @@ add_subdirectory(transport) add_subdirectory_ifdef(CONFIG_SMP_CLIENT smp_client) zephyr_library_link_libraries(mgmt_mcumgr) + +if (CONFIG_BOOT_IMAGE_ACCESS_HOOKS) + zephyr_include_directories( + ${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/bootutil/include + ${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/zephyr/include + ) + zephyr_library_sources(bootutil_hooks/nrf53_hooks.c) +endif() diff --git a/subsys/mgmt/mcumgr/Kconfig b/subsys/mgmt/mcumgr/Kconfig index 8af4ffe2738..a25ee0dc625 100644 --- a/subsys/mgmt/mcumgr/Kconfig +++ b/subsys/mgmt/mcumgr/Kconfig @@ -7,6 +7,7 @@ menuconfig MCUMGR depends on NET_BUF depends on ZCBOR imply CRC + imply BOOT_IMAGE_ACCESS_HOOKS if (SOC_NRF5340_CPUAPP_QKAA && MCUMGR_GRP_IMG) help This option enables the mcumgr management library. diff --git a/subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c b/subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c new file mode 100644 index 00000000000..9971a4e0843 --- /dev/null +++ b/subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "bootutil/bootutil_public.h" + +int boot_read_swap_state_primary_slot_hook(int image_index, + struct boot_swap_state *state) +{ + if (image_index == 1) { + /* Pretend that primary slot of image 1 unpopulated */ + state->magic = BOOT_MAGIC_UNSET; + state->swap_type = BOOT_SWAP_TYPE_NONE; + state->image_num = image_index; + state->copy_done = BOOT_FLAG_UNSET; + state->image_ok = BOOT_FLAG_UNSET; + + /* Prevent bootutil from trying to obtain true info */ + return 0; + } + + return BOOT_HOOK_REGULAR; +} From a87c9bbd70a2baf0823a4e03e783375e243a4e11 Mon Sep 17 00:00:00 2001 From: Ravi Dondaputi Date: Tue, 16 May 2023 02:19:42 +0530 Subject: [PATCH 0048/1623] [nrf noup] net: Increase connection manager stack size Connection manager L2 Wi-Fi calls internally invoke WPA supplicant calls which requires higher stack size. Update the default stack size for such cases. Marking this "nrf noup" since supplicant is not upstream yet. Signed-off-by: Ravi Dondaputi (cherry picked from commit 1d11b7423aff13dc3afcac00e78ce73b07707a09) (cherry picked from commit 9c36cddb8834d94411c84e49a2696657a2e7655e) Signed-off-by: Dominik Ermel (cherry picked from commit 34db04f962b7496fb9fc10685529ff751f9fed60) --- subsys/net/conn_mgr/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/net/conn_mgr/Kconfig b/subsys/net/conn_mgr/Kconfig index e72e614d54c..05686a663eb 100644 --- a/subsys/net/conn_mgr/Kconfig +++ b/subsys/net/conn_mgr/Kconfig @@ -24,6 +24,7 @@ source "subsys/net/Kconfig.template.log_config.net" config NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE int "Size of the stack allocated for the conn_mgr_monitor thread" + default 8192 if WPA_SUPP default 512 help Sets the stack size which will be used by the connection manager for connectivity monitoring. From d1fa3da6c37763e1ae9306c43bfaf5cf965af594 Mon Sep 17 00:00:00 2001 From: Sigvart Hovland Date: Fri, 3 May 2019 14:21:52 +0200 Subject: [PATCH 0049/1623] [nrf noup] tree-wide: support NCS Partition Manager (PM) definitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Partition Manager (PM) is a component of the nRF Connect SDK (NCS) which uses yaml files to resolve flash partition placement with a holistic view of the entire device, including each firmware image present on the flash device, and various subsystems, such as settings and NFFS. When this NCS extension is used, various source files which would use partition information from devicetree in "vanilla" zephyr instead use defines generated by PM instead. This commit removes support for HEX_FILES_TO_MERGE, as it conflicts with PM. The settings subsystem pm.yml defines a partition 'settings_storage'. The nffs subsystem pm.yml defines 'nffs_storage'. Leverage label translation to avoid patching partition names. Refer to the NCS documentation page for this feature for more details. This is a long-running out of tree patch which has been worked on by several people. The following sign-offs are in alphabetical order by first name. Signed-off-by: Andrzej Głąbek Signed-off-by: Andrzej Puzdrowski Signed-off-by: Håkon Øye Amundsen Signed-off-by: Ioannis Glaropoulos Signed-off-by: Joakim Andersson Signed-off-by: Johann Fischer Signed-off-by: Martí Bolívar Signed-off-by: Ole Sæther Signed-off-by: Robert Lubos Signed-off-by: Sebastian Bøe Signed-off-by: Sigvart Hovland Signed-off-by: Thomas Stenersen Signed-off-by: Torsten Rasmussen Signed-off-by: Øyvind Rønningstad Signed-off-by: Trond Einar Snekvik Signed-off-by: Gerard Marull-Paretas Signed-off-by: Tomasz Moń (cherry picked from commit ba54fe88dcfe3b25aca4c02f01e47f232b0f8bf7) (cherry picked from commit 68110ee5a75167e8e2c65746211571315618a3e1) (cherry picked from commit 12d1ebfb98a4f89dc018af4e7872382222b3b74a) Signed-off-by: Dominik Ermel (cherry picked from commit 5e8e748917649fc0a4a44a02c2c91c581007856d) --- cmake/modules/kernel.cmake | 4 ++ drivers/flash/soc_flash_nrf.c | 11 +++++ .../arm/aarch32/cortex_m/scripts/linker.ld | 46 +++++++++++++++++++ include/zephyr/storage/flash_map.h | 6 +++ lib/libc/common/source/stdlib/malloc.c | 18 +++++++- lib/os/Kconfig.heap | 2 +- soc/arm/common/cortex_m/arm_mpu_regions.c | 13 ++++++ subsys/fs/littlefs_fs.c | 7 ++- subsys/ipc/rpmsg_service/rpmsg_backend.h | 27 +++++++++++ 9 files changed, 130 insertions(+), 4 deletions(-) diff --git a/cmake/modules/kernel.cmake b/cmake/modules/kernel.cmake index 7e65c9cd186..28ee922d40b 100644 --- a/cmake/modules/kernel.cmake +++ b/cmake/modules/kernel.cmake @@ -242,3 +242,7 @@ if("${CMAKE_EXTRA_GENERATOR}" STREQUAL "Eclipse CDT4") include(${ZEPHYR_BASE}/cmake/ide/eclipse_cdt4_generator_amendment.cmake) eclipse_cdt4_generator_amendment(1) endif() + +if(ZEPHYR_NRF_MODULE_DIR) + include(${ZEPHYR_NRF_MODULE_DIR}/cmake/partition_manager.cmake) +endif() diff --git a/drivers/flash/soc_flash_nrf.c b/drivers/flash/soc_flash_nrf.c index fa433d1044b..f38492a41d1 100644 --- a/drivers/flash/soc_flash_nrf.c +++ b/drivers/flash/soc_flash_nrf.c @@ -37,6 +37,11 @@ LOG_MODULE_REGISTER(flash_nrf); #define SOC_NV_FLASH_NODE DT_INST(0, soc_nv_flash) +#if CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER +#include +#include +#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER */ + #ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE #define FLASH_SLOT_WRITE 7500 #if defined(CONFIG_SOC_FLASH_NRF_PARTIAL_ERASE) @@ -137,6 +142,12 @@ static int flash_nrf_read(const struct device *dev, off_t addr, return 0; } +#if CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER && PM_APP_ADDRESS + if (addr < PM_APP_ADDRESS) { + return soc_secure_mem_read(data, (void *)addr, len); + } +#endif + nrf_nvmc_buffer_read(data, (uint32_t)addr, len); return 0; diff --git a/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld b/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld index 92b6f02d029..85d55b2de29 100644 --- a/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld +++ b/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld @@ -26,6 +26,35 @@ #endif #define RAMABLE_REGION RAM +#if USE_PARTITION_MANAGER + +#include + +#if CONFIG_NCS_IS_VARIANT_IMAGE && defined(PM_S0_ID) +/* We are linking against S1, create symbol containing the flash ID of S0. + * This is used when writing code operating on the "other" slot. + */ +_image_1_primary_slot_id = PM_S0_ID; + +#else /* ! CONFIG_NCS_IS_VARIANT_IMAGE */ + +#ifdef PM_S1_ID +/* We are linking against S0, create symbol containing the flash ID of S1. + * This is used when writing code operating on the "other" slot. + */ +_image_1_primary_slot_id = PM_S1_ID; +#endif /* PM_S1_ID */ + +#endif /* CONFIG_NCS_IS_VARIANT_IMAGE */ + +#define ROM_ADDR PM_ADDRESS +#define ROM_SIZE PM_SIZE + +#define RAM_SIZE PM_SRAM_SIZE +#define RAM_ADDR PM_SRAM_ADDRESS + +#else /* ! USE_PARTITION_MANAGER */ + #if !defined(CONFIG_XIP) && (CONFIG_FLASH_SIZE == 0) #define ROM_ADDR RAM_ADDR #else @@ -52,6 +81,23 @@ #define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS #endif +#endif /* USE_PARTITION_MANAGER */ + +#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay) +#define CCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ccm)) +#define CCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ccm)) +#endif + +#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay) +#define ITCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_itcm)) +#define ITCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_itcm)) +#endif + +#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) +#define DTCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_dtcm)) +#define DTCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_dtcm)) +#endif + #if defined(CONFIG_CUSTOM_SECTION_ALIGN) _region_min_align = CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE; #else diff --git a/include/zephyr/storage/flash_map.h b/include/zephyr/storage/flash_map.h index 380e58691e9..cc4a246105d 100644 --- a/include/zephyr/storage/flash_map.h +++ b/include/zephyr/storage/flash_map.h @@ -271,6 +271,10 @@ const char *flash_area_label(const struct flash_area *fa); */ uint8_t flash_area_erased_val(const struct flash_area *fa); +#if USE_PARTITION_MANAGER +#include +#else + #define FLASH_AREA_LABEL_EXISTS(label) __DEPRECATED_MACRO \ DT_HAS_FIXED_PARTITION_LABEL(label) @@ -343,6 +347,8 @@ uint8_t flash_area_erased_val(const struct flash_area *fa); #define FIXED_PARTITION_DEVICE(label) \ DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(label))) +#endif /* USE_PARTITION_MANAGER */ + #ifdef __cplusplus } #endif diff --git a/lib/libc/common/source/stdlib/malloc.c b/lib/libc/common/source/stdlib/malloc.c index 50c688fa7f2..47583982838 100644 --- a/lib/libc/common/source/stdlib/malloc.c +++ b/lib/libc/common/source/stdlib/malloc.c @@ -23,6 +23,20 @@ #include LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); +#if USE_PARTITION_MANAGER + +#include + +#define RAM_SIZE PM_SRAM_SIZE +#define RAM_ADDR PM_SRAM_ADDRESS + +#else /* ! USE_PARTITION_MANAGER */ + +#define RAM_SIZE (KB((size_t) CONFIG_SRAM_SIZE)) +#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS + +#endif /* USE_PARTITION_MANAGER */ + #ifdef CONFIG_COMMON_LIBC_MALLOC #if (CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE != 0) @@ -104,8 +118,8 @@ static POOL_SECTION unsigned char __aligned(HEAP_ALIGN) malloc_arena[HEAP_SIZE]; extern char _heap_sentry[]; # define HEAP_SIZE ROUND_DOWN((POINTER_TO_UINT(_heap_sentry) - HEAP_BASE), HEAP_ALIGN) # else -# define HEAP_SIZE ROUND_DOWN((KB((size_t) CONFIG_SRAM_SIZE) - \ - ((size_t) HEAP_BASE - (size_t) CONFIG_SRAM_BASE_ADDRESS)), HEAP_ALIGN) +# define HEAP_SIZE ROUND_DOWN((RAM_SIZE - \ + ((size_t) HEAP_BASE - (size_t) RAM_ADDR)), HEAP_ALIGN) # endif /* else CONFIG_XTENSA */ # endif /* else CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE > 0 */ diff --git a/lib/os/Kconfig.heap b/lib/os/Kconfig.heap index 14fba87470b..1fa84ff41db 100644 --- a/lib/os/Kconfig.heap +++ b/lib/os/Kconfig.heap @@ -51,7 +51,7 @@ config HEAP_LISTENER choice prompt "Supported heap sizes" depends on !64BIT - default SYS_HEAP_SMALL_ONLY if (SRAM_SIZE <= 256) + default SYS_HEAP_SMALL_ONLY if (SRAM_SIZE <= 256) && !PARTITION_MANAGER_ENABLED default SYS_HEAP_AUTO help Heaps using reduced-size chunk headers can accommodate so called diff --git a/soc/arm/common/cortex_m/arm_mpu_regions.c b/soc/arm/common/cortex_m/arm_mpu_regions.c index 557079ef5bc..a7df11a19e1 100644 --- a/soc/arm/common/cortex_m/arm_mpu_regions.c +++ b/soc/arm/common/cortex_m/arm_mpu_regions.c @@ -9,6 +9,9 @@ #include #include +#if USE_PARTITION_MANAGER +#include +#endif static const struct arm_mpu_region mpu_regions[] = { /* Region 0 */ @@ -22,6 +25,14 @@ static const struct arm_mpu_region mpu_regions[] = { #endif /* Region 1 */ MPU_REGION_ENTRY("SRAM_0", +#if USE_PARTITION_MANAGER + PM_SRAM_ADDRESS, +#if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE) + REGION_RAM_ATTR(PM_SRAM_ADDRESS, PM_SRAM_SIZE)), +#else + REGION_RAM_ATTR(REGION_SRAM_SIZE)), +#endif +#else CONFIG_SRAM_BASE_ADDRESS, #if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE) REGION_RAM_ATTR(CONFIG_SRAM_BASE_ADDRESS, \ @@ -30,6 +41,8 @@ static const struct arm_mpu_region mpu_regions[] = { REGION_RAM_ATTR(REGION_SRAM_SIZE)), #endif +#endif /* USE_PARTITION_MANAGER */ + /* DT-defined regions */ DT_MEMORY_ATTR_APPLY(ARM_MPU_REGION_INIT) }; diff --git a/subsys/fs/littlefs_fs.c b/subsys/fs/littlefs_fs.c index 3058f402d73..c4c75bb48c4 100644 --- a/subsys/fs/littlefs_fs.c +++ b/subsys/fs/littlefs_fs.c @@ -1054,7 +1054,12 @@ struct fs_mount_t FS_FSTAB_ENTRY(DT_DRV_INST(inst)) = { \ .type = FS_LITTLEFS, \ .mnt_point = DT_INST_PROP(inst, mount_point), \ .fs_data = &fs_data_##inst, \ - .storage_dev = (void *)DT_FIXED_PARTITION_ID(FS_PARTITION(inst)), \ + .storage_dev = (void *) \ + COND_CODE_1(USE_PARTITION_MANAGER, \ + (COND_CODE_1(FIXED_PARTITION_EXISTS(littlefs_storage), \ + (FIXED_PARTITION_ID(littlefs_storage)), \ + (FIXED_PARTITION_ID(storage)))), \ + (DT_FIXED_PARTITION_ID(FS_PARTITION(inst)))), \ .flags = FSTAB_ENTRY_DT_MOUNT_FLAGS(DT_DRV_INST(inst)), \ }; diff --git a/subsys/ipc/rpmsg_service/rpmsg_backend.h b/subsys/ipc/rpmsg_service/rpmsg_backend.h index a74e46b8520..9996e1d74d9 100644 --- a/subsys/ipc/rpmsg_service/rpmsg_backend.h +++ b/subsys/ipc/rpmsg_service/rpmsg_backend.h @@ -13,8 +13,35 @@ extern "C" { #endif +#if CONFIG_PARTITION_MANAGER_ENABLED + +#include "pm_config.h" + +#if defined(PM_RPMSG_NRF53_SRAM_ADDRESS) || defined(PM__RPMSG_NRF53_SRAM_ADDRESS) + +#if defined(PM_RPMSG_NRF53_SRAM_ADDRESS) +#define VDEV_START_ADDR PM_RPMSG_NRF53_SRAM_ADDRESS +#define VDEV_SIZE PM_RPMSG_NRF53_SRAM_SIZE +#else +/* The current image is a child image in a different domain than the image + * which defined the required values. To reach the values of the parent domain + * we use the 'PM__' variant of the define. + */ +#define VDEV_START_ADDR PM__RPMSG_NRF53_SRAM_ADDRESS +#define VDEV_SIZE PM__RPMSG_NRF53_SRAM_SIZE +#endif /* defined(PM_RPMSG_NRF53_SRAM_ADDRESS) */ + +#else #define VDEV_START_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ipc_shm)) #define VDEV_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ipc_shm)) +#endif /* defined(PM_RPMSG_NRF53_SRAM_ADDRESS) || defined(PM__RPMSG_NRF53_SRAM_ADDRESS) */ + +#else + +#define VDEV_START_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ipc_shm)) +#define VDEV_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ipc_shm)) + +#endif /* CONFIG_PARTITION_MANAGER_ENABLED */ #define VDEV_STATUS_ADDR VDEV_START_ADDR #define VDEV_STATUS_SIZE 0x400 From 3a641f9c4f14104c0f950b33b0b5d3731b431ec9 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Mon, 1 Oct 2018 10:27:32 +0200 Subject: [PATCH 0050/1623] [nrf noup] include: net: add NCS extensions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add some socket options and address family extensions to Zephyr headers, which will be useful for nRF Connect SDK. Add secure socket options: * Add CID socket options to NCS specific options. * Add TLS/DTLS tls ciphersuite chosen socket option to NCS specific options. * Add TLS/DTLS connection save/load socket options to NCS specific options. * Add TLS/DTLS handshake status socket option to NCS specific options. The "author" of this commit is a contact person; various people with s-o-b lines following here have contributed to the maintenance of this patch. Signed-off-by: Andreas Moltumyr Signed-off-by: Andrzej Głąbek Signed-off-by: Christopher Métrailler Signed-off-by: Emanuele Di Santo Signed-off-by: Glenn Ruben Bakke Signed-off-by: Håkon Alseth Signed-off-by: Ioannis Glaropoulos Signed-off-by: Jan Tore Guggedal Signed-off-by: Joakim Andersson Signed-off-by: Martí Bolívar Signed-off-by: Mirko Covizzi Signed-off-by: Petri Honkala Signed-off-by: Robert Lubos Signed-off-by: Tommi Mammela Signed-off-by: Trond Einar Snekvik Signed-off-by: Torsten Rasmussen Signed-off-by: Eivind Jølsgard Signed-off-by: Emanuele Di Santo (cherry picked from commit 11a73e1d2d9ce98d8610281c9b00da688dc31802) (cherry picked from commit 1fbee9f184e0047bc98fe96629dcafe45de5ab09) (cherry picked from commit cf7645feef8bb6dac4b37a689146d0bab3741a4c) (cherry picked from commit 46c99f885eda4b186366e10014c54409208c6679) Signed-off-by: Dominik Ermel (cherry picked from commit 5ce6491cddb4a171e15243eccdcfc77ba8605fa6) --- include/zephyr/net/socket.h | 1 + include/zephyr/net/socket_ncs.h | 148 ++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 include/zephyr/net/socket_ncs.h diff --git a/include/zephyr/net/socket.h b/include/zephyr/net/socket.h index ff7b2cc2281..50070f0c7a5 100644 --- a/include/zephyr/net/socket.h +++ b/include/zephyr/net/socket.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #ifdef __cplusplus diff --git a/include/zephyr/net/socket_ncs.h b/include/zephyr/net/socket_ncs.h new file mode 100644 index 00000000000..a80e1ddc238 --- /dev/null +++ b/include/zephyr/net/socket_ncs.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_NET_SOCKET_NCS_H_ +#define ZEPHYR_INCLUDE_NET_SOCKET_NCS_H_ + +/** + * @file + * @brief NCS specific additions to the BSD sockets API definitions + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* When CONFIG_NET_SOCKETS_OFFLOAD is enabled, offloaded sockets take precedence + * when creating a new socket. Combine this flag with a socket type when + * creating a socket, to enforce native socket creation (e. g. SOCK_STREAM | SOCK_NATIVE). + * If it's desired to create a native TLS socket, but still offload the + * underlying TCP/UDP socket, use e. g. SOCK_STREAM | SOCK_NATIVE_TLS. + */ +#define SOCK_NATIVE 0x80000000 +#define SOCK_NATIVE_TLS 0x40000000 + +/* NCS specific TLS level socket options */ + +/** Socket option to set DTLS handshake timeout, specifically for nRF sockets. + * The option accepts an integer, indicating the total handshake timeout, + * including retransmissions, in seconds. + * Accepted values for the option are: 1, 3, 7, 15, 31, 63, 123. + */ +#define TLS_DTLS_HANDSHAKE_TIMEO 18 + +/** Socket option to save DTLS connection, specifically for nRF sockets. + */ +#define TLS_DTLS_CONN_SAVE 19 + +/** Socket option to load DTLS connection, specifically for nRF sockets. + */ +#define TLS_DTLS_CONN_LOAD 20 + +/** Socket option to get result of latest TLS/DTLS completed handshakes end status, + * specifically for nRF sockets. + * The option accepts an integer, indicating the setting. + * Accepted vaules for the option are: 0 and 1. + */ +#define TLS_DTLS_HANDSHAKE_STATUS 21 + +/* Valid values for TLS_SESSION_CACHE option */ +#define TLS_SESSION_CACHE_DISABLED 0 /**< Disable TLS session caching. */ +#define TLS_SESSION_CACHE_ENABLED 1 /**< Enable TLS session caching. */ + +/* Valid values for TLS_DTLS_HANDSHAKE_TIMEO option */ +#define TLS_DTLS_HANDSHAKE_TIMEO_NONE 0 /**< No timeout */ +#define TLS_DTLS_HANDSHAKE_TIMEO_1S 1 /**< 1 second */ +#define TLS_DTLS_HANDSHAKE_TIMEO_3S 3 /**< 1s + 2s */ +#define TLS_DTLS_HANDSHAKE_TIMEO_7S 7 /**< 1s + 2s + 4s */ +#define TLS_DTLS_HANDSHAKE_TIMEO_15S 15 /**< 1s + 2s + 4s + 8s */ +#define TLS_DTLS_HANDSHAKE_TIMEO_31S 31 /**< 1s + 2s + 4s + 8s + 16s */ +#define TLS_DTLS_HANDSHAKE_TIMEO_63S 63 /**< 1s + 2s + 4s + 8s + 16s + 32s */ +#define TLS_DTLS_HANDSHAKE_TIMEO_123S 123 /**< 1s + 2s + 4s + 8s + 16s + 32s + 60s */ + +/* Valid values for TLS_DTLS_HANDSHAKE_STATUS option */ +#define TLS_DTLS_HANDSHAKE_STATUS_FULL 0 +#define TLS_DTLS_HANDSHAKE_STATUS_CACHED 1 + +/* NCS specific socket options */ + +/** sockopt: enable sending data as part of exceptional events */ +#define SO_EXCEPTIONAL_DATA 33 +/** sockopt: bind to PDN */ +#define SO_BINDTOPDN 40 +/** sockopt: Release Assistance Indication feature: This will indicate that the + * application will not send any more data. + */ +#define SO_RAI_NO_DATA 50 +/** sockopt: Release Assistance Indication feature: This will indicate that the + * next call to send/sendto will be the last one for some time. + */ +#define SO_RAI_LAST 51 +/** sockopt: Release Assistance Indication feature: This will indicate that + * after the next call to send/sendto, the application is expecting to receive + * one more data packet before this socket will not be used again for some time. + */ +#define SO_RAI_ONE_RESP 52 +/** sockopt: Release Assistance Indication feature: If a client application + * expects to use the socket more it can indicate that by setting this socket + * option before the next send call which will keep the network up longer. + */ +#define SO_RAI_ONGOING 53 +/** sockopt: Release Assistance Indication feature: If a server application + * expects to use the socket more it can indicate that by setting this socket + * option before the next send call. + */ +#define SO_RAI_WAIT_MORE 54 + +/* NCS specific IPPROTO_ALL level socket options */ + +/** IPv4 and IPv6 protocol level (pseudo-val) for nRF sockets. */ +#define IPPROTO_ALL 512 +/** sockopt: disable all replies to unexpected traffics */ +#define SO_SILENCE_ALL 30 + +/* NCS specific IPPROTO_IP level socket options */ + +/** sockopt: enable IPv4 ICMP replies */ +#define SO_IP_ECHO_REPLY 31 + +/* NCS specific IPPROTO_IPV6 level socket options */ + +/** sockopt: enable IPv6 ICMP replies */ +#define SO_IPV6_ECHO_REPLY 32 + +/* NCS specific TCP level socket options */ + +/** sockopt: Configurable TCP server session timeout in minutes. + * Range is 0 to 135. 0 is no timeout and 135 is 2 h 15 min. Default is 0 (no timeout). + */ +#define SO_TCP_SRV_SESSTIMEO 55 + +/* NCS specific gettaddrinfo() flags */ + +/** Assume `service` contains a Packet Data Network (PDN) ID. + * When specified together with the AI_NUMERICSERV flag, + * `service` shall be formatted as follows: "port:pdn_id" + * where "port" is the port number and "pdn_id" is the PDN ID. + * Example: "8080:1", port 8080 PDN ID 1. + * Example: "42:0", port 42 PDN ID 0. + */ +#define AI_PDNSERV 0x1000 + +/* NCS specific send() and sendto() flags */ + +/** Request a blocking send operation until the request is acknowledged. + * When used in send() or sendto(), the request will not return until the + * send operation is completed by lower layers, or until the timeout, given by the SO_SNDTIMEO + * socket option, is reached. Valid timeout values are 1 to 600 seconds. + */ +#define MSG_WAITACK 0x200 + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_NET_SOCKET_NCS_H_ */ From acd88713225a8bbd89b78b71cba176404cda74c0 Mon Sep 17 00:00:00 2001 From: Marek Pieta Date: Fri, 5 May 2023 11:12:26 +0200 Subject: [PATCH 0051/1623] [nrf noup] mcumgr: img_mgmt: Fix check for chosen code partition The "zephyr-code-partition" chosen DTS node cannot be used when build uses Partition Manager. In that case, mcumgr must rely on the definitions provided by the Partition Manager. Jira: NCSDK-21381 Signed-off-by: Marek Pieta (cherry picked from commit 394faafd215eaa2405f58f6aa7793afcc62b6e99) (cherry picked from commit 36961d6b72f53b9ff0eef1e398f08da84dae5032) (cherry picked from commit 76ad781c59d359eb4e100440c9ce558f188822ca) Signed-off-by: Dominik Ermel (cherry picked from commit 84b9a1446bea62afd5c2b7ab8b0515284d492fa1) --- subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c index 0d733ce7abc..b2bb39aca86 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c @@ -33,6 +33,23 @@ #include #endif +#if USE_PARTITION_MANAGER +#include + +#ifdef PM_MCUBOOT_SECONDARY_PAD_SIZE +BUILD_ASSERT(PM_MCUBOOT_PAD_SIZE == PM_MCUBOOT_SECONDARY_PAD_SIZE); +#endif + +#if CONFIG_BUILD_WITH_TFM + #define PM_ADDRESS_OFFSET (PM_MCUBOOT_PAD_SIZE + PM_TFM_SIZE) +#else + #define PM_ADDRESS_OFFSET (PM_MCUBOOT_PAD_SIZE) +#endif + +#define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(label) \ + (FIXED_PARTITION_OFFSET(label) == (PM_ADDRESS - PM_ADDRESS_OFFSET)) + +#else /* ! USE_PARTITION_MANAGER */ #ifndef CONFIG_FLASH_LOAD_OFFSET #error MCUmgr requires application to be built with CONFIG_FLASH_LOAD_OFFSET set \ to be able to figure out application running slot. @@ -40,6 +57,7 @@ #define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(label) \ (FIXED_PARTITION_OFFSET(label) == CONFIG_FLASH_LOAD_OFFSET) +#endif /* USE_PARTITION_MANAGER */ #if FIXED_PARTITION_EXISTS(slot0_partition) #if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_partition) From 1479b0fc10df3b7542bb56c8b760287eb58ed3f2 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Fri, 4 Aug 2023 13:01:24 +0200 Subject: [PATCH 0052/1623] [nrf noup] ci: doc-build: use ubuntu-22.04 runner We can't use Zephyr custom runners downstream. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 005068b638d29cc4bbc2d0e15b05255d81ca183d) Signed-off-by: Dominik Ermel (cherry picked from commit 5b374838ae82e4a26aef9c2f573567fb93025b36) --- .github/workflows/doc-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doc-build.yml b/.github/workflows/doc-build.yml index 40e170ddc8a..a18507e028d 100644 --- a/.github/workflows/doc-build.yml +++ b/.github/workflows/doc-build.yml @@ -35,7 +35,7 @@ env: jobs: doc-build-html: name: "Documentation Build (HTML)" - runs-on: zephyr-runner-linux-x64-4xlarge + runs-on: ubuntu-22.04 timeout-minutes: 45 concurrency: group: doc-build-html-${{ github.ref }} From be7e604c73b30a27bb9ff61353e2c833bb982f25 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Thu, 7 Sep 2023 12:47:44 +0200 Subject: [PATCH 0053/1623] [nrf fromlist] cmake: Zephyr kernel version.h and app_version.h creation Move the custom commands creating the version.h and app_version.h below the Zephyr modules sourcing. This allows custom user specific Zephyr modules to adjust the value of KERNEL_VERSION_CUSTOMIZATION and APP_VERSION_CUSTOMIZATION values and thereby make use of the functionality introduced with #61635. The creation of the version_h and app_version_h targets, which drives the custom commands, are kept at their current location. This ensure that the targets themselves are still defined when the Zephyr and Zephyr modules CMakeLists trees are sourced. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/62395 Signed-off-by: Torsten Rasmussen (cherry picked from commit 96a0d4e857edbbb03a336cbb06c027355bfb75fc) Signed-off-by: Dominik Ermel (cherry picked from commit 1f8d53dbc4e5af5b1f524163460cd44a6891ccb0) --- CMakeLists.txt | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d761a97d8b..8fc047610fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -551,31 +551,9 @@ if(ZEPHYR_GIT_INDEX) set(git_dependency ${ZEPHYR_GIT_INDEX}) endif() -add_custom_command( - OUTPUT ${PROJECT_BINARY_DIR}/include/generated/version.h - COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} - -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/version.h - -DVERSION_TYPE=KERNEL - -DVERSION_FILE=${ZEPHYR_BASE}/VERSION - -DKERNEL_VERSION_CUSTOMIZATION="${KERNEL_VERSION_CUSTOMIZATION}" - ${build_version_argument} - -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake - DEPENDS ${ZEPHYR_BASE}/VERSION ${git_dependency} -) add_custom_target(version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/version.h) if(EXISTS ${APPLICATION_SOURCE_DIR}/VERSION) - add_custom_command( - OUTPUT ${PROJECT_BINARY_DIR}/include/generated/app_version.h - COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} - -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/app_version.h - -DVERSION_TYPE=APP - -DVERSION_FILE=${APPLICATION_SOURCE_DIR}/VERSION - -DAPP_VERSION_CUSTOMIZATION="${APP_VERSION_CUSTOMIZATION}" - ${build_version_argument} - -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake - DEPENDS ${APPLICATION_SOURCE_DIR}/VERSION ${git_dependency} - ) add_custom_target(app_version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/app_version.h) add_dependencies(zephyr_interface app_version_h) endif() @@ -626,6 +604,32 @@ endforeach() set(ZEPHYR_CURRENT_MODULE_DIR) set(ZEPHYR_CURRENT_CMAKE_DIR) +add_custom_command( + OUTPUT ${PROJECT_BINARY_DIR}/include/generated/version.h + COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} + -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/version.h + -DVERSION_TYPE=KERNEL + -DVERSION_FILE=${ZEPHYR_BASE}/VERSION + -DKERNEL_VERSION_CUSTOMIZATION="${KERNEL_VERSION_CUSTOMIZATION}" + ${build_version_argument} + -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake + DEPENDS ${ZEPHYR_BASE}/VERSION ${git_dependency} +) + +if(EXISTS ${APPLICATION_SOURCE_DIR}/VERSION) + add_custom_command( + OUTPUT ${PROJECT_BINARY_DIR}/include/generated/app_version.h + COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} + -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/app_version.h + -DVERSION_TYPE=APP + -DVERSION_FILE=${APPLICATION_SOURCE_DIR}/VERSION + -DAPP_VERSION_CUSTOMIZATION="${APP_VERSION_CUSTOMIZATION}" + ${build_version_argument} + -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake + DEPENDS ${APPLICATION_SOURCE_DIR}/VERSION ${git_dependency} + ) +endif() + get_property(LIBC_LINK_LIBRARIES TARGET zephyr_interface PROPERTY LIBC_LINK_LIBRARIES) zephyr_link_libraries(${LIBC_LINK_LIBRARIES}) From 09864f357bd2a56dc37c693b7bfe8e47df788e1f Mon Sep 17 00:00:00 2001 From: Sachin D Kulkarni Date: Tue, 5 Sep 2023 18:29:38 +0530 Subject: [PATCH 0054/1623] [nrf fromtree] net: wifi: Fix crash in wifi_utils_parse_scan_bands wifi_utils_parse_scan_bands could cause a crash if a constant string is passed to it. Fix this by duplicating the input string parameter before parsing it with strtok_r. Signed-off-by: Sachin D Kulkarni (cherry picked from commit 0b92327fc31b031a04e3a48d9cbd2cecccb7ac18) Signed-off-by: Dominik Ermel (cherry picked from commit 4a4d63062033a2e8a45fe743b3258dede3b83d17) --- include/zephyr/net/wifi_mgmt.h | 2 ++ subsys/net/l2/wifi/wifi_utils.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 0bdb5753531..c7a17e930d6 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -41,6 +41,8 @@ extern "C" { #define WIFI_MGMT_SCAN_SSID_FILT_MAX 0 #endif /* CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX */ +#define WIFI_MGMT_BAND_STR_SIZE_MAX 8 + /** Wi-Fi management commands */ enum net_request_wifi_cmd { /** Scan for Wi-Fi networks */ diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index f7e9d9af4dc..6151f480d21 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -215,15 +215,30 @@ static int wifi_utils_validate_chan_str(char *chan_str) int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map) { + char parse_str[WIFI_MGMT_BAND_STR_SIZE_MAX + 1]; char *band_str = NULL; char *ctx = NULL; enum wifi_frequency_bands band = WIFI_FREQ_BAND_UNKNOWN; + int len; if (!scan_bands_str) { return -EINVAL; } - band_str = strtok_r(scan_bands_str, ",", &ctx); + len = strlen(scan_bands_str); + + if (len > WIFI_MGMT_BAND_STR_SIZE_MAX) { + NET_ERR("Band string (%s) size (%d) exceeds maximum allowed value (%d)", + scan_bands_str, + len, + WIFI_MGMT_BAND_STR_SIZE_MAX); + return -EINVAL; + } + + strncpy(parse_str, scan_bands_str, len); + parse_str[len] = '\0'; + + band_str = strtok_r(parse_str, ",", &ctx); while (band_str) { band = wifi_utils_map_band_str_to_idx(band_str); From e4ee01d63ffcf8405d868827ea7e1916b883c760 Mon Sep 17 00:00:00 2001 From: Sachin D Kulkarni Date: Tue, 5 Sep 2023 18:38:54 +0530 Subject: [PATCH 0055/1623] [nrf fromtree] net: wifi: Fix crash in wifi_utils_parse_scan_ssids wifi_utils_parse_scan_ssids could cause a crash if a constant string is passed to it. Fix this by duplicating the input string parameter before parsing it with strtok_r. Also limit the range of the CONFIG_WIFI_SCAN_SSID_FILT_MAX parameter from 1 to 4 to avoid stack overflow due to users specifying a large value for this parameter. Signed-off-by: Sachin D Kulkarni (cherry picked from commit 85b39b84492605c02daaac4b16227b983dc757f0) Signed-off-by: Dominik Ermel (cherry picked from commit 8cb7f16e1a4797e60deefc79ead837db3285d102) --- subsys/net/l2/wifi/Kconfig | 1 + subsys/net/l2/wifi/wifi_utils.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index e034a745b5e..6623456d84b 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -76,6 +76,7 @@ config WIFI_MGMT_SCAN_DWELL_TIME_PASSIVE config WIFI_MGMT_SCAN_SSID_FILT_MAX int "Maximum number of SSIDs that can be specified for SSID filtering" default 1 + range 1 4 help Maximum number of SSIDs that can be specified for SSID filtering. This can be set based on the underlying chipsets limitations. diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index 6151f480d21..ea0e42def47 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -259,15 +259,30 @@ int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map) int wifi_utils_parse_scan_ssids(char *scan_ssids_str, char ssids[][WIFI_SSID_MAX_LEN + 1]) { + char parse_str[(WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1)) + 1]; char *ssid = NULL; char *ctx = NULL; uint8_t i = 0; + int len; if (!scan_ssids_str) { return -EINVAL; } - ssid = strtok_r(scan_ssids_str, ",", &ctx); + len = strlen(scan_ssids_str); + + if (len > (WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1))) { + NET_ERR("SSID string (%s) size (%d) exceeds maximum allowed value (%d)", + scan_ssids_str, + len, + (WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1))); + return -EINVAL; + } + + strncpy(parse_str, scan_ssids_str, len); + parse_str[len] = '\0'; + + ssid = strtok_r(parse_str, ",", &ctx); while (ssid) { if (strlen(ssid) > WIFI_SSID_MAX_LEN) { From 0feef90eb0216678f3cfe10bbeae034d79ad9840 Mon Sep 17 00:00:00 2001 From: Vivekananda Uppunda Date: Fri, 1 Sep 2023 15:56:38 +0530 Subject: [PATCH 0056/1623] [nrf fromtree] net: l2: wifi: Add support for W-Fi mode setting and selection This change brings in support for setting various Wi-Fi modes and enables a specific Wi-Fi interface to be also placed into a sniffer operation via monitor mode and promiscuous mode. A raw TX- packet Injection mode is also introduced Signed-off-by: Vivekananda Uppunda (cherry picked from commit 450dbb15efcaccadf546b42931509e5c4581b5eb) (cherry picked from commit 9226e1f518cae9a99d98332a30d8b78673fbaa89) Signed-off-by: Dominik Ermel (cherry picked from commit 5d2baa76d183a9971899f68d4b49b3e7b9a1a77e) --- include/zephyr/net/wifi.h | 33 +++ include/zephyr/net/wifi_mgmt.h | 76 +++++++ subsys/net/l2/wifi/wifi_mgmt.c | 60 +++++ subsys/net/l2/wifi/wifi_shell.c | 388 +++++++++++++++++++++++++++++++- 4 files changed, 556 insertions(+), 1 deletion(-) diff --git a/include/zephyr/net/wifi.h b/include/zephyr/net/wifi.h index aa3096fc5ac..55bd8d71a3a 100644 --- a/include/zephyr/net/wifi.h +++ b/include/zephyr/net/wifi.h @@ -148,6 +148,7 @@ static inline const char *wifi_band_txt(enum wifi_frequency_bands band) #define WIFI_SAE_PSWD_MAX_LEN 128 #define WIFI_MAC_ADDR_LEN 6 +#define WIFI_CHANNEL_MIN 1 #define WIFI_CHANNEL_MAX 233 #define WIFI_CHANNEL_ANY 255 @@ -355,6 +356,38 @@ static const char * const wifi_ps_mode2str[] = { }; /** @endcond */ +/* Interface index Min and Max values */ +#define WIFI_INTERFACE_INDEX_MIN 1 +#define WIFI_INTERFACE_INDEX_MAX 255 + +/** Wifi operational mode */ +enum wifi_operational_modes { + /** STA mode setting enable */ + WIFI_STA_MODE = BIT(0), + /** Monitor mode setting enable */ + WIFI_MONITOR_MODE = BIT(1), + /** TX injection mode setting enable */ + WIFI_TX_INJECTION_MODE = BIT(2), + /** Promiscuous mode setting enable */ + WIFI_PROMISCUOUS_MODE = BIT(3), + /** AP mode setting enable */ + WIFI_AP_MODE = BIT(4), + /** Softap mode setting enable */ + WIFI_SOFTAP_MODE = BIT(5), +}; + +/** Mode filter settings */ +enum wifi_filter { + /** Support management, data and control packet sniffing */ + WIFI_PACKET_FILTER_ALL = BIT(0), + /** Support only sniffing of management packets */ + WIFI_PACKET_FILTER_MGMT = BIT(1), + /** Support only sniffing of data packets */ + WIFI_PACKET_FILTER_DATA = BIT(2), + /** Support only sniffing of control packets */ + WIFI_PACKET_FILTER_CTRL = BIT(3), +}; + /** Wi-Fi Target Wake Time (TWT) operations. */ enum wifi_twt_operation { /** TWT setup operation */ diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index c7a17e930d6..ab3225e1408 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -69,6 +69,12 @@ enum net_request_wifi_cmd { NET_REQUEST_WIFI_CMD_REG_DOMAIN, /** Set power save timeout */ NET_REQUEST_WIFI_CMD_PS_TIMEOUT, + /** Set or get Mode of operation */ + NET_REQUEST_WIFI_CMD_MODE, + /** Set or get packet filter setting for current mode */ + NET_REQUEST_WIFI_CMD_PACKET_FILTER, + /** Set or get Wi-Fi channel for Monitor or TX-Injection mode */ + NET_REQUEST_WIFI_CMD_CHANNEL, NET_REQUEST_WIFI_CMD_MAX }; @@ -131,6 +137,21 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_REG_DOMAIN); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PS_TIMEOUT); +#define NET_REQUEST_WIFI_MODE \ + (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_MODE) + +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_MODE); + +#define NET_REQUEST_WIFI_PACKET_FILTER \ + (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PACKET_FILTER) + +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PACKET_FILTER); + +#define NET_REQUEST_WIFI_CHANNEL \ + (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_CHANNEL) + +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL); + /** Wi-Fi management events */ enum net_event_wifi_cmd { /** Scan results available */ @@ -475,6 +496,37 @@ union wifi_mgmt_events { struct wifi_twt_params twt_params; }; +/** Wi-Fi mode setup */ +struct wifi_mode_info { + /** Mode setting for a specific mode of operation */ + uint8_t mode; + /** Interface index */ + uint8_t if_index; + /** Get or set operation */ + enum wifi_mgmt_op oper; +}; + +/** Wi-Fi filter setting for monitor, prmoiscuous, TX-injection modes */ +struct wifi_filter_info { + /** Filter setting */ + uint8_t filter; + /** Interface index */ + uint8_t if_index; + /** Filter buffer size */ + uint16_t buffer_size; + /** Get or set operation */ + enum wifi_mgmt_op oper; +}; + +/** Wi-Fi channel setting for monitor and TX-injection modes */ +struct wifi_channel_info { + /** Channel value to set */ + uint16_t channel; + /** Interface index */ + uint8_t if_index; + /** Get or set operation */ + enum wifi_mgmt_op oper; +}; #include @@ -596,6 +648,30 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*reg_domain)(const struct device *dev, struct wifi_reg_domain *reg_domain); + /** Set or get packet filter settings for monitor and promiscuous modes + * + * @param dev Pointer to the device structure for the driver instance. + * @param packet filter settings + * + * @return 0 if ok, < 0 if error + */ + int (*filter)(const struct device *dev, struct wifi_filter_info *filter); + /** Set or get mode of operation + * + * @param dev Pointer to the device structure for the driver instance. + * @param mode settings + * + * @return 0 if ok, < 0 if error + */ + int (*mode)(const struct device *dev, struct wifi_mode_info *mode); + /** Set or get current channel of operation + * + * @param dev Pointer to the device structure for the driver instance. + * @param channel settings + * + * @return 0 if ok, < 0 if error + */ + int (*channel)(const struct device *dev, struct wifi_channel_info *channel); }; /** Wi-Fi management offload API */ diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 22d54b926ab..7f0f30dc8c1 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -446,6 +446,66 @@ void wifi_mgmt_raise_twt_sleep_state(struct net_if *iface, sizeof(twt_sleep_state)); } +static int wifi_mode(uint32_t mgmt_request, struct net_if *iface, + void *data, size_t len) +{ + const struct device *dev = net_if_get_device(iface); + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); + struct wifi_mode_info *mode_info = data; + + if (dev == NULL) { + return -ENODEV; + } + + if (wifi_mgmt_api == NULL || wifi_mgmt_api->mode == NULL) { + return -ENOTSUP; + } + + return wifi_mgmt_api->mode(dev, mode_info); +} + +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_MODE, wifi_mode); + +static int wifi_packet_filter(uint32_t mgmt_request, struct net_if *iface, + void *data, size_t len) +{ + const struct device *dev = net_if_get_device(iface); + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); + struct wifi_filter_info *filter_info = data; + + if (dev == NULL) { + return -ENODEV; + } + + if (wifi_mgmt_api == NULL || wifi_mgmt_api->filter == NULL) { + return -ENOTSUP; + } + + return wifi_mgmt_api->filter(dev, filter_info); +} + +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PACKET_FILTER, wifi_packet_filter); + +static int wifi_channel(uint32_t mgmt_request, struct net_if *iface, + void *data, size_t len) +{ + const struct device *dev = net_if_get_device(iface); + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); + struct wifi_channel_info *channel_info = data; + + if (dev == NULL) { + return -ENODEV; + } + + if (wifi_mgmt_api == NULL || wifi_mgmt_api->channel == NULL) { + return -ENOTSUP; + } + + return wifi_mgmt_api->channel(dev, channel_info); +} + +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL, wifi_channel); + #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface, struct wifi_raw_scan_result *raw_scan_result) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 0b8c6a74983..21b1f551448 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -75,12 +75,20 @@ static bool parse_number(const struct shell *sh, long *param, char *str, long mi { char *endptr; char *str_tmp = str; - long num = strtol(str_tmp, &endptr, 10); + long num = 0; + + if ((str_tmp[0] == '0') && (str_tmp[1] == 'x')) { + /* Hexadecimal numbers take base 0 in strtol */ + num = strtol(str_tmp, &endptr, 0); + } else { + num = strtol(str_tmp, &endptr, 10); + } if (*endptr != '\0') { print(sh, SHELL_ERROR, "Invalid number: %s", str_tmp); return false; } + if ((num) < (min) || (num) > (max)) { print(sh, SHELL_WARNING, "Value out of range: %s, (%ld-%ld)", str_tmp, min, max); return false; @@ -1255,6 +1263,335 @@ static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *ar return 0; } +void parse_mode_args_to_params(const struct shell *sh, int argc, + char *argv[], struct wifi_mode_info *mode, + bool *do_mode_oper) +{ + int opt; + int option_index = 0; + + static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, + {"sta", no_argument, 0, 's'}, + {"monitor", no_argument, 0, 'm'}, + {"TX-injection", no_argument, 0, 't'}, + {"promiscuous", no_argument, 0, 'p'}, + {"ap", no_argument, 0, 'a'}, + {"softap", no_argument, 0, 'k'}, + {"get", no_argument, 0, 'g'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0}}; + + while ((opt = getopt_long(argc, argv, "i:smtpakgh", long_options, &option_index)) != -1) { + switch (opt) { + case 's': + mode->mode |= WIFI_STA_MODE; + break; + case 'm': + mode->mode |= WIFI_MONITOR_MODE; + break; + case 't': + mode->mode |= WIFI_TX_INJECTION_MODE; + break; + case 'p': + mode->mode |= WIFI_PROMISCUOUS_MODE; + break; + case 'a': + mode->mode |= WIFI_AP_MODE; + break; + case 'k': + mode->mode |= WIFI_SOFTAP_MODE; + break; + case 'g': + mode->oper = true; + break; + case 'i': + mode->if_index = (uint8_t)atoi(optarg); + break; + case 'h': + shell_help(sh); + *do_mode_oper = false; + break; + case '?': + default: + break; + } + } +} + +static int cmd_wifi_mode(const struct shell *sh, size_t argc, char *argv[]) +{ + struct net_if *iface; + struct wifi_mode_info mode_info = {0}; + int ret; + bool do_mode_oper = true; + + if (argc > 1) { + mode_info.oper = WIFI_MGMT_SET; + parse_mode_args_to_params(sh, argc, argv, &mode_info, &do_mode_oper); + } else { + shell_fprintf(sh, SHELL_ERROR, "Invalid number of arguments\n"); + return -EINVAL; + } + + if (do_mode_oper) { + /* Check interface index value. Mode validation must be performed by + * lower layer + */ + if (mode_info.if_index == 0) { + iface = net_if_get_first_wifi(); + if (iface == NULL) { + shell_fprintf(sh, SHELL_ERROR, + "Cannot find the default wifi interface\n"); + return -ENOEXEC; + } + mode_info.if_index = net_if_get_by_iface(iface); + } else { + iface = net_if_get_by_index(mode_info.if_index); + if (iface == NULL) { + shell_fprintf(sh, SHELL_ERROR, + "Cannot find interface for if_index %d\n", + mode_info.if_index); + return -ENOEXEC; + } + } + + ret = net_mgmt(NET_REQUEST_WIFI_MODE, iface, &mode_info, sizeof(mode_info)); + + if (ret) { + shell_fprintf(sh, SHELL_ERROR, "mode %s operation failed with reason %d\n", + mode_info.oper == WIFI_MGMT_GET ? "get" : "set", ret); + return -ENOEXEC; + } + + if (mode_info.oper == WIFI_MGMT_GET) { + shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi current mode is %x\n", + mode_info.mode); + } else { + shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi mode set to %x\n", mode_info.mode); + } + } + return 0; +} + +void parse_channel_args_to_params(const struct shell *sh, int argc, + char *argv[], struct wifi_channel_info *channel, + bool *do_channel_oper) +{ + int opt; + int option_index = 0; + + static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, + {"channel", required_argument, 0, 'c'}, + {"get", no_argument, 0, 'g'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0}}; + + while ((opt = getopt_long(argc, argv, "i:c:gh", long_options, &option_index)) != -1) { + switch (opt) { + case 'c': + channel->channel = (uint16_t)atoi(optarg); + break; + case 'i': + channel->if_index = (uint8_t)atoi(optarg); + break; + case 'g': + channel->oper = WIFI_MGMT_GET; + break; + case 'h': + shell_help(sh); + *do_channel_oper = false; + break; + case '?': + default: + break; + } + } +} + +static int cmd_wifi_channel(const struct shell *sh, size_t argc, char *argv[]) +{ + struct net_if *iface; + struct wifi_channel_info channel_info = {0}; + int ret; + bool do_channel_oper = true; + + if (argc > 1) { + channel_info.oper = WIFI_MGMT_SET; + parse_channel_args_to_params(sh, argc, argv, &channel_info, &do_channel_oper); + } else { + shell_fprintf(sh, SHELL_ERROR, "Invalid number of arguments\n"); + return -EINVAL; + } + + if (do_channel_oper) { + /* + * Validate parameters before sending to lower layer. + * Do it here instead of parse_channel_args_to_params + * as this is right before sending the parameters to + * the lower layer. + */ + + if (channel_info.if_index == 0) { + iface = net_if_get_first_wifi(); + if (iface == NULL) { + shell_fprintf(sh, SHELL_ERROR, + "Cannot find the default wifi interface\n"); + return -ENOEXEC; + } + channel_info.if_index = net_if_get_by_iface(iface); + } else { + iface = net_if_get_by_index(channel_info.if_index); + if (iface == NULL) { + shell_fprintf(sh, SHELL_ERROR, + "Cannot find interface for if_index %d\n", + channel_info.if_index); + return -ENOEXEC; + } + } + + if (channel_info.oper == WIFI_MGMT_SET) { + if ((channel_info.channel < WIFI_CHANNEL_MIN) || + (channel_info.channel > WIFI_CHANNEL_MAX)) { + shell_fprintf(sh, SHELL_ERROR, + "Invalid channel number. Range is (1-233)\n"); + return -ENOEXEC; + } + } + + ret = net_mgmt(NET_REQUEST_WIFI_CHANNEL, iface, + &channel_info, sizeof(channel_info)); + + if (ret) { + shell_fprintf(sh, SHELL_ERROR, + "channel %s operation failed with reason %d\n", + channel_info.oper == WIFI_MGMT_GET ? "get" : "set", ret); + return -ENOEXEC; + } + + if (channel_info.oper == WIFI_MGMT_GET) { + shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi current channel is: %d\n", + channel_info.channel); + } else { + shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi channel set to %d\n", + channel_info.channel); + } + } + return 0; +} + +void parse_filter_args_to_params(const struct shell *sh, int argc, + char *argv[], struct wifi_filter_info *filter, + bool *do_filter_oper) +{ + int opt; + int option_index = 0; + + static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, + {"capture_len", optional_argument, 0, 'b'}, + {"all", no_argument, 0, 'a'}, + {"mgmt", no_argument, 0, 'm'}, + {"ctrl", no_argument, 0, 'c'}, + {"data", no_argument, 0, 'd'}, + {"get", no_argument, 0, 'g'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0}}; + + while ((opt = getopt_long(argc, argv, "i:b:amcdgh", long_options, &option_index)) != -1) { + switch (opt) { + case 'a': + filter->filter |= WIFI_PACKET_FILTER_ALL; + break; + case 'm': + filter->filter |= WIFI_PACKET_FILTER_MGMT; + break; + case 'c': + filter->filter |= WIFI_PACKET_FILTER_DATA; + break; + case 'd': + filter->filter |= WIFI_PACKET_FILTER_CTRL; + break; + case 'i': + filter->if_index = (uint8_t)atoi(optarg); + break; + case 'b': + filter->buffer_size = (uint16_t)atoi(optarg); + break; + case 'h': + shell_help(sh); + *do_filter_oper = false; + break; + case 'g': + filter->oper = WIFI_MGMT_GET; + break; + case '?': + default: + break; + } + } +} + +static int cmd_wifi_packet_filter(const struct shell *sh, size_t argc, char *argv[]) +{ + struct net_if *iface; + struct wifi_filter_info packet_filter = {0}; + int ret; + bool do_filter_oper = true; + + if (argc > 1) { + packet_filter.oper = WIFI_MGMT_SET; + parse_filter_args_to_params(sh, argc, argv, &packet_filter, &do_filter_oper); + } else { + shell_fprintf(sh, SHELL_ERROR, "Invalid number of arguments\n"); + return -EINVAL; + } + + if (do_filter_oper) { + /* + * Validate parameters before sending to lower layer. + * Do it here instead of parse_filter_args_to_params + * as this is right before sending the parameters to + * the lower layer. filter and packet capture length + * value to be verified by the lower layer. + */ + if (packet_filter.if_index == 0) { + iface = net_if_get_first_wifi(); + if (iface == NULL) { + shell_fprintf(sh, SHELL_ERROR, + "Cannot find the default wifi interface\n"); + return -ENOEXEC; + } + packet_filter.if_index = net_if_get_by_iface(iface); + } else { + iface = net_if_get_by_index(packet_filter.if_index); + if (iface == NULL) { + shell_fprintf(sh, SHELL_ERROR, + "Cannot find interface for if_index %d\n", + packet_filter.if_index); + return -ENOEXEC; + } + } + + ret = net_mgmt(NET_REQUEST_WIFI_PACKET_FILTER, iface, + &packet_filter, sizeof(packet_filter)); + + if (ret) { + shell_fprintf(sh, SHELL_ERROR, + "Wi-Fi packet filter %s operation failed with reason %d\n", + packet_filter.oper == WIFI_MGMT_GET ? "get" : "set", ret); + return -ENOEXEC; + } + + if (packet_filter.oper == WIFI_MGMT_GET) { + shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi current mode packet filter is %d\n", + packet_filter.filter); + } else { + shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi mode packet filter set to %d\n", + packet_filter.filter); + } + } + return 0; +} + SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, SHELL_CMD(disable, NULL, "Disable Access Point mode", @@ -1328,6 +1665,55 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "-f: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain), + SHELL_CMD(mode, NULL, "mode operational setting\n" + "This command may be used to set the Wi-Fi device into a specific mode of operation\n" + "parameters:" + "[-i : Interface index - optional argument\n" + "[-s : Station mode.\n" + "[-m : Monitor mode.\n" + "[-p : Promiscuous mode.\n" + "[-t : TX-Injection mode.\n" + "[-a : AP mode.\n" + "[-k : Softap mode.\n" + "[-h : Help.\n" + "[-g : Get current mode for a specific interface index.\n" + "Usage: Get operation example for interface index 1\n" + "wifi mode -g -i1\n" + "Set operation example for interface index 1 - set station+promiscuous\n" + "wifi mode -i1 -sp\n", + cmd_wifi_mode), + SHELL_CMD(packet_filter, NULL, "mode filter setting\n" + "This command is used to set packet filter setting when\n" + "monitor, TX-Injection and promiscuous mode is enabled.\n" + "The different packet filter modes are control, management, data and enable all filters\n" + "parameters:" + "[-i : Interface index - optional argument.\n" + "[-a : Enable all packet filter modes\n" + "[-m : Enable management packets to allowed up the stack.\n" + "[-c : Enable control packets to be allowed up the stack.\n" + "[-d : Enable Data packets to be allowed up the stack.\n" + "[-g : Get current filter settings for a specific interface index.\n" + "<-b : Capture length buffer size for each packet to be captured - optional argument.\n" + "<-h : Help.\n" + "Usage: Get operation example for interface index 1\n" + "wifi packet_filter -g -i1\n" + "Set operation example for interface index 1 - set data+management frame filter\n" + "wifi packet_filter -i1 -md\n", + cmd_wifi_packet_filter), + SHELL_CMD(channel, NULL, "wifi channel setting\n" + "This command is used to set the channel when\n" + "monitor or TX-Injection mode is enabled.\n" + "Currently 20 MHz is only supported and no BW parameter is provided\n" + "parameters:" + "[-i : Interface index - optional argument.\n" + "[-c : Set a specific channel number to the lower layer.\n" + "[-g : Get current set channel number from the lower layer.\n" + "[-h : Help.\n" + "Usage: Get operation example for interface index 1\n" + "wifi channel -g -i1\n" + "Set operation example for interface index 1 (setting channel 5)\n" + "wifi -i1 -c5\n", + cmd_wifi_channel), SHELL_CMD_ARG(ps_timeout, NULL, " - PS inactivity timer(in ms)", From 4ea2d10cee590392888695101091446a4c4605d5 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 14 Sep 2023 23:34:45 +0530 Subject: [PATCH 0057/1623] [nrf fromtree] net: socketpair: Fix use after free In low memory conditions, its possible for socketpair memory allocation to fail and then the socketpair is freed but after that the remote semaphore is released causing a crash. Fix this by freeing the socketpair after releasing the semaphore. Add a test case to induce low memory conditions (low HEAP and high socketpair buffer size), with the fix issue is not seen. Signed-off-by: Chaitanya Tata (cherry picked from commit 40ee8791f21e47cadf2552386b9f16b18f3fb060) Signed-off-by: Dominik Ermel (cherry picked from commit 1878aa707df6b8be09fa1f81345281b7fcc0a57f) --- subsys/net/lib/sockets/socketpair.c | 8 ++++---- tests/net/socket/socketpair/testcase.yaml | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/subsys/net/lib/sockets/socketpair.c b/subsys/net/lib/sockets/socketpair.c index f3bbb46f6c8..9207f4b659e 100644 --- a/subsys/net/lib/sockets/socketpair.c +++ b/subsys/net/lib/sockets/socketpair.c @@ -191,6 +191,10 @@ static void spair_delete(struct spair *spair) res = k_poll_signal_raise(&spair->writeable, SPAIR_SIG_CANCEL); __ASSERT(res == 0, "k_poll_signal_raise() failed: %d", res); + if (remote != NULL && have_remote_sem) { + k_sem_give(&remote->sem); + } + /* ensure no private information is released to the memory pool */ memset(spair, 0, sizeof(*spair)); #ifdef CONFIG_NET_SOCKETPAIR_STATIC @@ -200,10 +204,6 @@ static void spair_delete(struct spair *spair) #else k_free(spair); #endif - - if (remote != NULL && have_remote_sem) { - k_sem_give(&remote->sem); - } } /** diff --git a/tests/net/socket/socketpair/testcase.yaml b/tests/net/socket/socketpair/testcase.yaml index e771e7c61d4..d2b4462ce2d 100644 --- a/tests/net/socket/socketpair/testcase.yaml +++ b/tests/net/socket/socketpair/testcase.yaml @@ -18,3 +18,11 @@ tests: extra_configs: - CONFIG_PICOLIBC=y platform_exclude: vmu_rt1170 mimxrt1160_evk_cm7 # See #61246 + net.socket.socketpair.high_mem: + min_ram: 64 + extra_configs: + # Low buffer sizes (e.g., 8192) will verify the crash fix, but tests will still + # fail due to insufficient memory. So, use high buffer sizes. + - CONFIG_NET_SOCKETPAIR_BUFFER_SIZE=4096 + - CONFIG_HEAP_MEM_POOL_SIZE=32768 + platform_exclude: vmu_rt1170 mimxrt1160_evk_cm7 # See #61246 From 5327c5408115ece4c62baaa0eb9fdd8086f78f1b Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 3 Aug 2023 10:56:41 +0100 Subject: [PATCH 0058/1623] [nrf fromtree] twister: Add support for required snippets Adds support for twister to require using snippets on tests Signed-off-by: Jamie McCrae (cherry picked from commit bc97d8fb1e40328ab32da108508e83e9d8792bf0) (cherry picked from commit a9d71eb9c5fd9d676c3a2493305bd06412f9de68) Signed-off-by: Dominik Ermel (cherry picked from commit 2ddf83d3189e253fc40e290808f55cc669cc79a4) --- .../pylib/twister/twisterlib/config_parser.py | 1 + scripts/pylib/twister/twisterlib/runner.py | 4 ++ scripts/pylib/twister/twisterlib/testplan.py | 42 +++++++++++++++++++ scripts/schemas/twister/testsuite-schema.yaml | 10 +++++ scripts/snippets.py | 16 +++++++ scripts/twister | 3 ++ scripts/west_commands/build.py | 11 ++++- 7 files changed, 86 insertions(+), 1 deletion(-) diff --git a/scripts/pylib/twister/twisterlib/config_parser.py b/scripts/pylib/twister/twisterlib/config_parser.py index c822e9dfc77..f431e2d57c2 100644 --- a/scripts/pylib/twister/twisterlib/config_parser.py +++ b/scripts/pylib/twister/twisterlib/config_parser.py @@ -48,6 +48,7 @@ class TwisterConfigParser: "extra_conf_files": {"type": "list", "default": []}, "extra_overlay_confs" : {"type": "list", "default": []}, "extra_dtc_overlay_files": {"type": "list", "default": []}, + "required_snippets": {"type": "list"}, "build_only": {"type": "bool", "default": False}, "build_on_all": {"type": "bool", "default": False}, "skip": {"type": "bool", "default": False}, diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index ad93145db38..bbbdb18d05a 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -359,6 +359,10 @@ def run_cmake(self, args="", filter_stages=[]): cmake_opts = ['-DBOARD={}'.format(self.platform.name)] cmake_args.extend(cmake_opts) + if self.instance.testsuite.required_snippets: + cmake_opts = ['-DSNIPPET={}'.format(';'.join(self.instance.testsuite.required_snippets))] + cmake_args.extend(cmake_opts) + cmake = shutil.which('cmake') cmd = [cmake] + cmake_args diff --git a/scripts/pylib/twister/twisterlib/testplan.py b/scripts/pylib/twister/twisterlib/testplan.py index 85340885dbb..1d9c625b28a 100755 --- a/scripts/pylib/twister/twisterlib/testplan.py +++ b/scripts/pylib/twister/twisterlib/testplan.py @@ -16,6 +16,8 @@ import copy import shutil import random +import snippets +from pathlib import Path logger = logging.getLogger('twister') logger.setLevel(logging.DEBUG) @@ -819,6 +821,46 @@ def apply_filters(self, **kwargs): if plat.only_tags and not set(plat.only_tags) & ts.tags: instance.add_filter("Excluded tags per platform (only_tags)", Filters.PLATFORM) + if ts.required_snippets: + missing_snippet = False + snippet_args = {"snippets": ts.required_snippets} + found_snippets = snippets.find_snippets_in_roots(snippet_args, [Path(ZEPHYR_BASE), Path(ts.source_dir)]) + + # Search and check that all required snippet files are found + for this_snippet in snippet_args['snippets']: + if this_snippet not in found_snippets: + logger.error(f"Can't find snippet '%s' for test '%s'", this_snippet, ts.name) + instance.status = "error" + instance.reason = f"Snippet {this_snippet} not found" + missing_snippet = True + break + + if not missing_snippet: + # Look for required snippets and check that they are applicable for these + # platforms/boards + for this_snippet in found_snippets: + matched_snippet_board = False + + # If the "appends" key is present with at least one entry then this + # snippet applies to all boards and further platform-specific checks + # are not required + if found_snippets[this_snippet].appends: + continue + + for this_board in found_snippets[this_snippet].board2appends: + if this_board.startswith('/'): + match = re.search(this_board[1:-1], plat.name) + if match is not None: + matched_snippet_board = True + break + elif this_board == plat.name: + matched_snippet_board = True + break + + if matched_snippet_board is False: + instance.add_filter("Snippet not supported", Filters.PLATFORM) + break + # platform_key is a list of unique platform attributes that form a unique key a test # will match against to determine if it should be scheduled to run. A key containing a # field name that the platform does not have will filter the platform. diff --git a/scripts/schemas/twister/testsuite-schema.yaml b/scripts/schemas/twister/testsuite-schema.yaml index 4d67fe71706..116c1a43379 100644 --- a/scripts/schemas/twister/testsuite-schema.yaml +++ b/scripts/schemas/twister/testsuite-schema.yaml @@ -145,6 +145,11 @@ mapping: matching: "all" sequence: - type: str + "required_snippets": + type: seq + required: false + sequence: + - type: str "tags": type: any required: false @@ -243,6 +248,11 @@ mapping: "extra_sections": type: any required: false + "required_snippets": + type: seq + required: false + sequence: + - type: str "filter": type: str required: false diff --git a/scripts/snippets.py b/scripts/snippets.py index 9662f3edcec..78ab896e85b 100644 --- a/scripts/snippets.py +++ b/scripts/snippets.py @@ -238,6 +238,22 @@ def process_snippets(args: argparse.Namespace) -> Snippets: return snippets +def find_snippets_in_roots(requested_snippets, snippet_roots) -> Snippets: + '''Process snippet.yml files under each *snippet_root* + by recursive search. Return a Snippets object describing + the results of the search. + ''' + # This will contain information about all the snippets + # we discover in each snippet_root element. + snippets = Snippets(requested=requested_snippets) + + # Process each path in snippet_root in order, adjusting + # snippets as needed for each one. + for root in snippet_roots: + process_snippets_in(root, snippets) + + return snippets + def process_snippets_in(root_dir: Path, snippets: Snippets) -> None: '''Process snippet.yml files in *root_dir*, updating *snippets* as needed.''' diff --git a/scripts/twister b/scripts/twister index 0f5e622011f..f41349871ed 100755 --- a/scripts/twister +++ b/scripts/twister @@ -44,6 +44,9 @@ pairs: Extra configuration options to be merged with a master prj.conf when building or running the test case. + required_snippets: + Snippets that must be applied for the test case to run. + sysbuild: (default False) If true, build the sample using the sysbuild infrastructure. Filtering will only be enabled for the main project, and is not supported for diff --git a/scripts/west_commands/build.py b/scripts/west_commands/build.py index 65dbe963cd4..bcc5106f8ca 100644 --- a/scripts/west_commands/build.py +++ b/scripts/west_commands/build.py @@ -293,6 +293,7 @@ def _parse_test_item(self, test_item): extra_dtc_overlay_files = [] extra_overlay_confs = [] extra_conf_files = [] + required_snippets = [] for section in [common, item]: if not section: continue @@ -302,7 +303,8 @@ def _parse_test_item(self, test_item): 'extra_configs', 'extra_conf_files', 'extra_overlay_confs', - 'extra_dtc_overlay_files' + 'extra_dtc_overlay_files', + 'required_snippets' ]: extra = section.get(data) if not extra: @@ -325,6 +327,9 @@ def _parse_test_item(self, test_item): elif data == 'extra_dtc_overlay_files': extra_dtc_overlay_files.extend(arg_list) continue + elif data == 'required_snippets': + required_snippets.extend(arg_list) + continue if self.args.cmake_opts: self.args.cmake_opts.extend(args) @@ -343,6 +348,10 @@ def _parse_test_item(self, test_item): if extra_overlay_confs: args.append(f"OVERLAY_CONFIG=\"{';'.join(extra_overlay_confs)}\"") + + if required_snippets: + args.append(f"SNIPPET=\"{';'.join(required_snippets)}\"") + # Build the final argument list args_expanded = ["-D{}".format(a.replace('"', '')) for a in args] From 45e05e2d8f3ffb0b46a0fa055cb5b3ded64e13f7 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 5 Sep 2023 01:47:48 +0530 Subject: [PATCH 0059/1623] [nrf fromtree] twister: handle quotes for configuration options Add support handling quotes for configuration options in extra args by escaping them properly instead of removing the quotes altogether. For other options in extra_args quotes are removes as usual. Add similar support in west build command also. Add a unit test to check this functionality. Signed-off-by: Chaitanya Tata (cherry picked from commit 6b05af6e4389cf10415b7c3bd83c0dd45b10ed26) (cherry picked from commit 81b838d57dc6997c14718c0dc94b778bcd6eeba5) Signed-off-by: Dominik Ermel (cherry picked from commit dbe7b7c5dd073df4c2a5680bab5d4783f79780ef) --- scripts/pylib/twister/twisterlib/runner.py | 10 ++++++++-- scripts/tests/twister/test_runner.py | 5 +++-- scripts/west_commands/build.py | 6 +++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index bbbdb18d05a..ef41084cdd4 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -978,9 +978,15 @@ def report_out(self, results): sys.stdout.flush() @staticmethod - def cmake_assemble_args(args, handler, extra_conf_files, extra_overlay_confs, + def cmake_assemble_args(extra_args, handler, extra_conf_files, extra_overlay_confs, extra_dtc_overlay_files, cmake_extra_args, build_dir): + # Retain quotes around config options + config_options = [arg for arg in extra_args if arg.startswith("CONFIG_")] + args = [arg for arg in extra_args if not arg.startswith("CONFIG_")] + + args_expanded = ["-D{}".format(a.replace('"', '\"')) for a in config_options] + if handler.ready: args.extend(handler.args) @@ -1003,7 +1009,7 @@ def cmake_assemble_args(args, handler, extra_conf_files, extra_overlay_confs, args.append("OVERLAY_CONFIG=\"%s\"" % (" ".join(overlays))) # Build the final argument list - args_expanded = ["-D{}".format(a.replace('"', '\"')) for a in cmake_extra_args] + args_expanded.extend(["-D{}".format(a.replace('"', '\"')) for a in cmake_extra_args]) args_expanded.extend(["-D{}".format(a.replace('"', '')) for a in args]) return args_expanded diff --git a/scripts/tests/twister/test_runner.py b/scripts/tests/twister/test_runner.py index 7540da04394..37c02b6d17b 100644 --- a/scripts/tests/twister/test_runner.py +++ b/scripts/tests/twister/test_runner.py @@ -90,7 +90,7 @@ class MockHandler: handler.ready = True assert(ProjectBuilder.cmake_assemble_args( - ["basearg1"], + ["basearg1", "CONFIG_t=\"test\"", "SNIPPET_t=\"test\""], handler, ["a.conf;b.conf", "c.conf"], ["extra_overlay.conf"], @@ -98,8 +98,9 @@ class MockHandler: ["cmake1=foo", "cmake2=bar"], "/builddir/", ) == [ + "-DCONFIG_t=\"test\"", "-Dcmake1=foo", "-Dcmake2=bar", - "-Dbasearg1", + "-Dbasearg1", "-DSNIPPET_t=test", "-Dhandler_arg1", "-Dhandler_arg2", "-DCONF_FILE=a.conf;b.conf;c.conf", "-DDTC_OVERLAY_FILE=x.overlay;y.overlay;z.overlay", diff --git a/scripts/west_commands/build.py b/scripts/west_commands/build.py index bcc5106f8ca..f7a605f4d7f 100644 --- a/scripts/west_commands/build.py +++ b/scripts/west_commands/build.py @@ -317,7 +317,11 @@ def _parse_test_item(self, test_item): if data == 'extra_configs': args = ["-D{}".format(arg.replace('"', '\"')) for arg in arg_list] elif data == 'extra_args': - args = ["-D{}".format(arg.replace('"', '')) for arg in arg_list] + # Retain quotes around config options + config_options = [arg for arg in arg_list if arg.startswith("CONFIG_")] + non_config_options = [arg for arg in arg_list if not arg.startswith("CONFIG_")] + args = ["-D{}".format(a.replace('"', '\"')) for a in config_options] + args.extend(["-D{}".format(arg.replace('"', '')) for arg in non_config_options]) elif data == 'extra_conf_files': extra_conf_files.extend(arg_list) continue From 622ccbce57fab78fd9527f0099207f84a2582459 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Fri, 23 Jun 2023 16:19:25 +0000 Subject: [PATCH 0060/1623] [nrf fromtree] mgmt/MCUmgr/grp/img: Add support for three image configuration The commit adds support for uploading images to secondary slots of three images. (cherry picked from commit ea6129cd7c21299c8cd65db5722f0a7d7aafaeae) Signed-off-by: Dominik Ermel (cherry picked from commit 0784ebb292ee95a82f12f86c12eef89845ff543e) --- subsys/dfu/Kconfig | 2 +- subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig | 2 +- .../mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c | 65 +++++++++---------- .../mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c | 36 ++++++++-- 4 files changed, 63 insertions(+), 42 deletions(-) diff --git a/subsys/dfu/Kconfig b/subsys/dfu/Kconfig index f998b2ef9f2..121fa3964f6 100644 --- a/subsys/dfu/Kconfig +++ b/subsys/dfu/Kconfig @@ -89,7 +89,7 @@ if !MCUBOOT config UPDATEABLE_IMAGE_NUMBER int "Number of updateable images" default 1 - range 1 2 + range 1 3 help If value is set to 2 or greater then, this enables support needed when application is combined with MCUboot multi-image boot. diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig b/subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig index 641e16bd703..81fc57d9238 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig @@ -46,7 +46,7 @@ endif config MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER int "Number of supported images" default UPDATEABLE_IMAGE_NUMBER - range 1 2 + range 1 3 help Sets how many application images are supported (pairs of secondary and primary slots). Setting this to 2 requires MCUMGR_TRANSPORT_NETBUF_SIZE to be at least 512b. diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c index b2bb39aca86..305cad41c44 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c @@ -59,43 +59,38 @@ BUILD_ASSERT(PM_MCUBOOT_PAD_SIZE == PM_MCUBOOT_SECONDARY_PAD_SIZE); (FIXED_PARTITION_OFFSET(label) == CONFIG_FLASH_LOAD_OFFSET) #endif /* USE_PARTITION_MANAGER */ -#if FIXED_PARTITION_EXISTS(slot0_partition) -#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_partition) -#define NUMBER_OF_ACTIVE_IMAGE 0 -#endif -#endif - -#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot0_ns_partition) -#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_ns_partition) -#define NUMBER_OF_ACTIVE_IMAGE 0 -#endif -#endif - -#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot1_partition) -#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot1_partition) -#define NUMBER_OF_ACTIVE_IMAGE 0 -#endif -#endif - -#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot2_partition) -#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot2_partition) -#define NUMBER_OF_ACTIVE_IMAGE 1 -#endif -#endif - -#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot3_partition) -#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot3_partition) -#define NUMBER_OF_ACTIVE_IMAGE 1 -#endif +BUILD_ASSERT(sizeof(struct image_header) == IMAGE_HEADER_SIZE, + "struct image_header not required size"); + +#if CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER >= 2 +#if FIXED_PARTITION_EXISTS(slot0_ns_partition) && \ + FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_ns_partition) +#define ACTIVE_IMAGE_IS 0 +#elif FIXED_PARTITION_EXISTS(slot0_partition) && \ + FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_partition) +#define ACTIVE_IMAGE_IS 0 +#elif FIXED_PARTITION_EXISTS(slot1_partition) && \ + FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot1_partition) +#define ACTIVE_IMAGE_IS 0 +#elif FIXED_PARTITION_EXISTS(slot2_partition) && \ + FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot2_partition) +#define ACTIVE_IMAGE_IS 1 +#elif FIXED_PARTITION_EXISTS(slot3_partition) && \ + FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot3_partition) +#define ACTIVE_IMAGE_IS 1 +#elif FIXED_PARTITION_EXISTS(slot4_partition) && \ + FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot4_partition) +#define ACTIVE_IMAGE_IS 2 +#elif FIXED_PARTITION_EXISTS(slot5_partition) && \ + FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot5_partition) +#define ACTIVE_IMAGE_IS 2 +#else +#define ACTIVE_IMAGE_IS 0 #endif - -#ifndef NUMBER_OF_ACTIVE_IMAGE -#error "Unsupported code parition is set as active application partition" +#else +#define ACTIVE_IMAGE_IS 0 #endif -_Static_assert(sizeof(struct image_header) == IMAGE_HEADER_SIZE, - "struct image_header not required size"); - LOG_MODULE_REGISTER(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL); struct img_mgmt_state g_img_mgmt_state; @@ -177,7 +172,7 @@ int img_mgmt_active_slot(int image) int img_mgmt_active_image(void) { - return NUMBER_OF_ACTIVE_IMAGE; + return ACTIVE_IMAGE_IS; } /* diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c index c3641986fd2..addde1e9a2c 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c @@ -25,12 +25,26 @@ LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL); #define SLOT1_PARTITION slot1_partition #define SLOT2_PARTITION slot2_partition #define SLOT3_PARTITION slot3_partition +#define SLOT4_PARTITION slot4_partition +#define SLOT5_PARTITION slot5_partition + +/* SLOT0_PARTITION and SLOT1_PARTITION are not checked because + * there is not conditional code that depends on them. If they do + * not exist compilation will fail, but in case if some of other + * partitions do not exist, code will compile and will not work + * properly. + */ +#if CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER >= 2 +BUILD_ASSERT(FIXED_PARTITION_EXISTS(SLOT2_PARTITION) && + FIXED_PARTITION_EXISTS(SLOT3_PARTITION), + "Missing partitions?"); +#endif -BUILD_ASSERT(CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 1 || - (CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 2 && - FIXED_PARTITION_EXISTS(SLOT2_PARTITION) && - FIXED_PARTITION_EXISTS(SLOT3_PARTITION)), +#if CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 3 +BUILD_ASSERT(FIXED_PARTITION_EXISTS(SLOT4_PARTITION) && + FIXED_PARTITION_EXISTS(SLOT5_PARTITION), "Missing partitions?"); +#endif /** * Determines if the specified area of flash is completely unwritten. @@ -137,6 +151,18 @@ img_mgmt_flash_area_id(int slot) break; #endif +#if FIXED_PARTITION_EXISTS(SLOT4_PARTITION) + case 4: + fa_id = FIXED_PARTITION_ID(SLOT4_PARTITION); + break; +#endif + +#if FIXED_PARTITION_EXISTS(SLOT5_PARTITION) + case 5: + fa_id = FIXED_PARTITION_ID(SLOT5_PARTITION); + break; +#endif + default: fa_id = -1; break; @@ -194,7 +220,7 @@ static int img_mgmt_get_unused_slot_area_id(int slot) return slot != -1 ? img_mgmt_flash_area_id(slot) : -1; #endif } -#elif CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 2 +#elif CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER >= 2 static int img_mgmt_get_unused_slot_area_id(int image) { int area_id = -1; From ff771d084177ffb3595bf855fb0fb26cef6c225e Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Wed, 20 Sep 2023 17:57:04 +0530 Subject: [PATCH 0061/1623] [nrf fromtree] net: l2: wifi: Change arrays to functions The header file contains mixture of functions and static arrays. Replacing static arrays to functions. Initialize functions in C file. Signed-off-by: Kapil Bhatt (cherry picked from commit 4b9f5cc455c1c018c506a94f8b4a5b2fa617e51e) (cherry picked from commit 1db99743a416e7a1eb407392567e5a562ea230ac) Signed-off-by: Dominik Ermel (cherry picked from commit bd51b50482fde641900df44752061b930ab208b9) --- include/zephyr/net/wifi.h | 187 +++-------------------- subsys/net/l2/wifi/wifi_shell.c | 258 +++++++++++++++++++++++++++++--- 2 files changed, 256 insertions(+), 189 deletions(-) diff --git a/include/zephyr/net/wifi.h b/include/zephyr/net/wifi.h index 55bd8d71a3a..294fdc53c5d 100644 --- a/include/zephyr/net/wifi.h +++ b/include/zephyr/net/wifi.h @@ -52,30 +52,7 @@ enum wifi_security_type { }; /** Helper function to get user-friendly security type name. */ -static inline const char *wifi_security_txt(enum wifi_security_type security) -{ - switch (security) { - case WIFI_SECURITY_TYPE_NONE: - return "OPEN"; - case WIFI_SECURITY_TYPE_WEP: - return "WEP"; - case WIFI_SECURITY_TYPE_WPA_PSK: - return "WPA-PSK"; - case WIFI_SECURITY_TYPE_PSK: - return "WPA2-PSK"; - case WIFI_SECURITY_TYPE_PSK_SHA256: - return "WPA2-PSK-SHA256"; - case WIFI_SECURITY_TYPE_SAE: - return "WPA3-SAE"; - case WIFI_SECURITY_TYPE_WAPI: - return "WAPI"; - case WIFI_SECURITY_TYPE_EAP: - return "EAP"; - case WIFI_SECURITY_TYPE_UNKNOWN: - default: - return "UNKNOWN"; - } -} +const char * const wifi_security_txt(enum wifi_security_type security); /** IEEE 802.11w - Management frame protection. */ enum wifi_mfp_options { @@ -92,20 +69,7 @@ enum wifi_mfp_options { }; /** Helper function to get user-friendly MFP name.*/ -static inline const char *wifi_mfp_txt(enum wifi_mfp_options mfp) -{ - switch (mfp) { - case WIFI_MFP_DISABLE: - return "Disable"; - case WIFI_MFP_OPTIONAL: - return "Optional"; - case WIFI_MFP_REQUIRED: - return "Required"; - case WIFI_MFP_UNKNOWN: - default: - return "UNKNOWN"; - } -} +const char * const wifi_mfp_txt(enum wifi_mfp_options mfp); /** * @brief IEEE 802.11 operational frequency bands (not exhaustive). @@ -127,20 +91,7 @@ enum wifi_frequency_bands { }; /** Helper function to get user-friendly frequency band name. */ -static inline const char *wifi_band_txt(enum wifi_frequency_bands band) -{ - switch (band) { - case WIFI_FREQ_BAND_2_4_GHZ: - return "2.4GHz"; - case WIFI_FREQ_BAND_5_GHZ: - return "5GHz"; - case WIFI_FREQ_BAND_6_GHZ: - return "6GHz"; - case WIFI_FREQ_BAND_UNKNOWN: - default: - return "UNKNOWN"; - } -} +const char * const wifi_band_txt(enum wifi_frequency_bands band); #define WIFI_SSID_MAX_LEN 32 #define WIFI_PSK_MIN_LEN 8 @@ -184,34 +135,7 @@ enum wifi_iface_state { }; /** Helper function to get user-friendly interface state name. */ -static inline const char *wifi_state_txt(enum wifi_iface_state state) -{ - switch (state) { - case WIFI_STATE_DISCONNECTED: - return "DISCONNECTED"; - case WIFI_STATE_INACTIVE: - return "INACTIVE"; - case WIFI_STATE_INTERFACE_DISABLED: - return "INTERFACE_DISABLED"; - case WIFI_STATE_SCANNING: - return "SCANNING"; - case WIFI_STATE_AUTHENTICATING: - return "AUTHENTICATING"; - case WIFI_STATE_ASSOCIATING: - return "ASSOCIATING"; - case WIFI_STATE_ASSOCIATED: - return "ASSOCIATED"; - case WIFI_STATE_4WAY_HANDSHAKE: - return "4WAY_HANDSHAKE"; - case WIFI_STATE_GROUP_HANDSHAKE: - return "GROUP_HANDSHAKE"; - case WIFI_STATE_COMPLETED: - return "COMPLETED"; - case WIFI_STATE_UNKNOWN: - default: - return "UNKNOWN"; - } -} +const char * const wifi_state_txt(enum wifi_iface_state state); /** Wi-Fi interface modes. * @@ -237,26 +161,7 @@ enum wifi_iface_mode { }; /** Helper function to get user-friendly interface mode name. */ -static inline const char *wifi_mode_txt(enum wifi_iface_mode mode) -{ - switch (mode) { - case WIFI_MODE_INFRA: - return "STATION"; - case WIFI_MODE_IBSS: - return "ADHOC"; - case WIFI_MODE_AP: - return "ACCESS POINT"; - case WIFI_MODE_P2P_GO: - return "P2P GROUP OWNER"; - case WIFI_MODE_P2P_GROUP_FORMATION: - return "P2P GROUP FORMATION"; - case WIFI_MODE_MESH: - return "MESH"; - case WIFI_MODE_UNKNOWN: - default: - return "UNKNOWN"; - } -} +const char * const wifi_mode_txt(enum wifi_iface_mode mode); /** Wi-Fi link operating modes * @@ -288,32 +193,7 @@ enum wifi_link_mode { }; /** Helper function to get user-friendly link mode name. */ -static inline const char *wifi_link_mode_txt(enum wifi_link_mode link_mode) -{ - switch (link_mode) { - case WIFI_0: - return "WIFI 0 (802.11)"; - case WIFI_1: - return "WIFI 1 (802.11b)"; - case WIFI_2: - return "WIFI 2 (802.11a)"; - case WIFI_3: - return "WIFI 3 (802.11g)"; - case WIFI_4: - return "WIFI 4 (802.11n/HT)"; - case WIFI_5: - return "WIFI 5 (802.11ac/VHT)"; - case WIFI_6: - return "WIFI 6 (802.11ax/HE)"; - case WIFI_6E: - return "WIFI 6E (802.11ax 6GHz/HE)"; - case WIFI_7: - return "WIFI 7 (802.11be/EHT)"; - case WIFI_LINK_MODE_UNKNOWN: - default: - return "UNKNOWN"; - } -} +const char * const wifi_link_mode_txt(enum wifi_link_mode link_mode); /** Wi-Fi scanning types. */ enum wifi_scan_type { @@ -331,12 +211,8 @@ enum wifi_ps { WIFI_PS_ENABLED, }; -/** @cond INTERNAL_HIDDEN */ -static const char * const wifi_ps2str[] = { - [WIFI_PS_DISABLED] = "Power save disabled", - [WIFI_PS_ENABLED] = "Power save enabled", -}; -/** @endcond */ +/** Helper function to get user-friendly ps name. */ +const char * const wifi_ps_txt(enum wifi_ps ps_name); /** Wi-Fi power save modes. */ enum wifi_ps_mode { @@ -349,12 +225,8 @@ enum wifi_ps_mode { WIFI_PS_MODE_WMM, }; -/** @cond INTERNAL_HIDDEN */ -static const char * const wifi_ps_mode2str[] = { - [WIFI_PS_MODE_LEGACY] = "Legacy power save", - [WIFI_PS_MODE_WMM] = "WMM power save", -}; -/** @endcond */ +/** Helper function to get user-friendly ps mode name. */ +const char * const wifi_ps_mode_txt(enum wifi_ps_mode ps_mode); /* Interface index Min and Max values */ #define WIFI_INTERFACE_INDEX_MIN 1 @@ -396,12 +268,8 @@ enum wifi_twt_operation { WIFI_TWT_TEARDOWN, }; -/** @cond INTERNAL_HIDDEN */ -static const char * const wifi_twt_operation2str[] = { - [WIFI_TWT_SETUP] = "TWT setup", - [WIFI_TWT_TEARDOWN] = "TWT teardown", -}; -/** @endcond */ +/** Helper function to get user-friendly twt operation name. */ +const char * const wifi_twt_operation_txt(enum wifi_twt_operation twt_operation); /** Wi-Fi Target Wake Time (TWT) negotiation types. */ enum wifi_twt_negotiation_type { @@ -413,13 +281,8 @@ enum wifi_twt_negotiation_type { WIFI_TWT_WAKE_TBTT }; -/** @cond INTERNAL_HIDDEN */ -static const char * const wifi_twt_negotiation_type2str[] = { - [WIFI_TWT_INDIVIDUAL] = "TWT individual negotiation", - [WIFI_TWT_BROADCAST] = "TWT broadcast negotiation", - [WIFI_TWT_WAKE_TBTT] = "TWT wake TBTT negotiation", -}; -/** @endcond */ +/** Helper function to get user-friendly twt negotiation type name. */ +const char * const wifi_twt_negotiation_type_txt(enum wifi_twt_negotiation_type twt_negotiation); /** Wi-Fi Target Wake Time (TWT) setup commands. */ enum wifi_twt_setup_cmd { @@ -441,18 +304,8 @@ enum wifi_twt_setup_cmd { WIFI_TWT_SETUP_CMD_REJECT, }; -/** @cond INTERNAL_HIDDEN */ -static const char * const wifi_twt_setup_cmd2str[] = { - [WIFI_TWT_SETUP_CMD_REQUEST] = "TWT request", - [WIFI_TWT_SETUP_CMD_SUGGEST] = "TWT suggest", - [WIFI_TWT_SETUP_CMD_DEMAND] = "TWT demand", - [WIFI_TWT_SETUP_CMD_GROUPING] = "TWT grouping", - [WIFI_TWT_SETUP_CMD_ACCEPT] = "TWT accept", - [WIFI_TWT_SETUP_CMD_ALTERNATE] = "TWT alternate", - [WIFI_TWT_SETUP_CMD_DICTATE] = "TWT dictate", - [WIFI_TWT_SETUP_CMD_REJECT] = "TWT reject", -}; -/** @endcond */ +/** Helper function to get user-friendly twt setup cmd name. */ +const char * const wifi_twt_setup_cmd_txt(enum wifi_twt_setup_cmd twt_setup); /** Wi-Fi Target Wake Time (TWT) negotiation status. */ enum wifi_twt_setup_resp_status { @@ -543,12 +396,8 @@ enum wifi_ps_wakeup_mode { WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL, }; -/** @cond INTERNAL_HIDDEN */ -static const char * const wifi_ps_wakeup_mode2str[] = { - [WIFI_PS_WAKEUP_MODE_DTIM] = "PS wakeup mode DTIM", - [WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL] = "PS wakeup mode listen interval", -}; -/** @endcond */ +/** Helper function to get user-friendly ps wakeup mode name. */ +const char * const wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode); /** Wi-Fi power save error codes. */ enum wifi_config_ps_param_fail_reason { diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 21b1f551448..74284e56e98 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -97,6 +97,224 @@ static bool parse_number(const struct shell *sh, long *param, char *str, long mi return true; } +const char * const wifi_security_txt(enum wifi_security_type security) +{ + switch (security) { + case WIFI_SECURITY_TYPE_NONE: + return "OPEN"; + case WIFI_SECURITY_TYPE_WEP: + return "WEP"; + case WIFI_SECURITY_TYPE_WPA_PSK: + return "WPA-PSK"; + case WIFI_SECURITY_TYPE_PSK: + return "WPA2-PSK"; + case WIFI_SECURITY_TYPE_PSK_SHA256: + return "WPA2-PSK-SHA256"; + case WIFI_SECURITY_TYPE_SAE: + return "WPA3-SAE"; + case WIFI_SECURITY_TYPE_WAPI: + return "WAPI"; + case WIFI_SECURITY_TYPE_EAP: + return "EAP"; + case WIFI_SECURITY_TYPE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_mfp_txt(enum wifi_mfp_options mfp) +{ + switch (mfp) { + case WIFI_MFP_DISABLE: + return "Disable"; + case WIFI_MFP_OPTIONAL: + return "Optional"; + case WIFI_MFP_REQUIRED: + return "Required"; + case WIFI_MFP_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_band_txt(enum wifi_frequency_bands band) +{ + switch (band) { + case WIFI_FREQ_BAND_2_4_GHZ: + return "2.4GHz"; + case WIFI_FREQ_BAND_5_GHZ: + return "5GHz"; + case WIFI_FREQ_BAND_6_GHZ: + return "6GHz"; + case WIFI_FREQ_BAND_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_state_txt(enum wifi_iface_state state) +{ + switch (state) { + case WIFI_STATE_DISCONNECTED: + return "DISCONNECTED"; + case WIFI_STATE_INACTIVE: + return "INACTIVE"; + case WIFI_STATE_INTERFACE_DISABLED: + return "INTERFACE_DISABLED"; + case WIFI_STATE_SCANNING: + return "SCANNING"; + case WIFI_STATE_AUTHENTICATING: + return "AUTHENTICATING"; + case WIFI_STATE_ASSOCIATING: + return "ASSOCIATING"; + case WIFI_STATE_ASSOCIATED: + return "ASSOCIATED"; + case WIFI_STATE_4WAY_HANDSHAKE: + return "4WAY_HANDSHAKE"; + case WIFI_STATE_GROUP_HANDSHAKE: + return "GROUP_HANDSHAKE"; + case WIFI_STATE_COMPLETED: + return "COMPLETED"; + case WIFI_STATE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_mode_txt(enum wifi_iface_mode mode) +{ + switch (mode) { + case WIFI_MODE_INFRA: + return "STATION"; + case WIFI_MODE_IBSS: + return "ADHOC"; + case WIFI_MODE_AP: + return "ACCESS POINT"; + case WIFI_MODE_P2P_GO: + return "P2P GROUP OWNER"; + case WIFI_MODE_P2P_GROUP_FORMATION: + return "P2P GROUP FORMATION"; + case WIFI_MODE_MESH: + return "MESH"; + case WIFI_MODE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_link_mode_txt(enum wifi_link_mode link_mode) +{ + switch (link_mode) { + case WIFI_0: + return "WIFI 0 (802.11)"; + case WIFI_1: + return "WIFI 1 (802.11b)"; + case WIFI_2: + return "WIFI 2 (802.11a)"; + case WIFI_3: + return "WIFI 3 (802.11g)"; + case WIFI_4: + return "WIFI 4 (802.11n/HT)"; + case WIFI_5: + return "WIFI 5 (802.11ac/VHT)"; + case WIFI_6: + return "WIFI 6 (802.11ax/HE)"; + case WIFI_6E: + return "WIFI 6E (802.11ax 6GHz/HE)"; + case WIFI_7: + return "WIFI 7 (802.11be/EHT)"; + case WIFI_LINK_MODE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_ps_txt(enum wifi_ps ps_name) +{ + switch (ps_name) { + case WIFI_PS_DISABLED: + return "Power save disabled"; + case WIFI_PS_ENABLED: + return "Power save enabled"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_ps_mode_txt(enum wifi_ps_mode ps_mode) +{ + switch (ps_mode) { + case WIFI_PS_MODE_LEGACY: + return "Legacy power save"; + case WIFI_PS_MODE_WMM: + return "WMM power save"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_twt_operation_txt(enum wifi_twt_operation twt_operation) +{ + switch (twt_operation) { + case WIFI_TWT_SETUP: + return "TWT setup"; + case WIFI_TWT_TEARDOWN: + return "TWT teardown"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_twt_negotiation_type_txt(enum wifi_twt_negotiation_type twt_negotiation) +{ + switch (twt_negotiation) { + case WIFI_TWT_INDIVIDUAL: + return "TWT individual negotiation"; + case WIFI_TWT_BROADCAST: + return "TWT broadcast negotiation"; + case WIFI_TWT_WAKE_TBTT: + return "TWT wake TBTT negotiation"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_twt_setup_cmd_txt(enum wifi_twt_setup_cmd twt_setup) +{ + switch (twt_setup) { + case WIFI_TWT_SETUP_CMD_REQUEST: + return "TWT request"; + case WIFI_TWT_SETUP_CMD_SUGGEST: + return "TWT suggest"; + case WIFI_TWT_SETUP_CMD_DEMAND: + return "TWT demand"; + case WIFI_TWT_SETUP_CMD_GROUPING: + return "TWT grouping"; + case WIFI_TWT_SETUP_CMD_ACCEPT: + return "TWT accept"; + case WIFI_TWT_SETUP_CMD_ALTERNATE: + return "TWT alternate"; + case WIFI_TWT_SETUP_CMD_DICTATE: + return "TWT dictate"; + case WIFI_TWT_SETUP_CMD_REJECT: + return "TWT reject"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode) +{ + switch (ps_wakeup_mode) { + case WIFI_PS_WAKEUP_MODE_DTIM: + return "PS wakeup mode DTIM"; + case WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL: + return "PS wakeup mode listen interval"; + default: + return "UNKNOWN"; + } +} + static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb) { const struct wifi_scan_result *entry = @@ -257,7 +475,7 @@ static void print_twt_params(uint8_t dialog_token, uint8_t flow_id, print(context.sh, SHELL_NORMAL, "TWT flow ID: %d\n", flow_id); print(context.sh, SHELL_NORMAL, "TWT negotiation type: %s\n", - wifi_twt_negotiation_type2str[negotiation_type]); + wifi_twt_negotiation_type_txt(negotiation_type)); print(context.sh, SHELL_NORMAL, "TWT responder: %s\n", responder ? "true" : "false"); print(context.sh, SHELL_NORMAL, "TWT implicit: %s\n", @@ -286,7 +504,7 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) if (resp->resp_status == WIFI_TWT_RESP_RECEIVED) { print(context.sh, SHELL_NORMAL, "TWT response: %s\n", - wifi_twt_setup_cmd2str[resp->setup_cmd]); + wifi_twt_setup_cmd_txt(resp->setup_cmd)); print(context.sh, SHELL_NORMAL, "== TWT negotiated parameters ==\n"); print_twt_params(resp->dialog_token, resp->flow_id, @@ -736,10 +954,10 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) } shell_fprintf(sh, SHELL_NORMAL, "PS status: %s\n", - wifi_ps2str[config.ps_params.enabled]); + wifi_ps_txt(config.ps_params.enabled)); if (config.ps_params.enabled) { shell_fprintf(sh, SHELL_NORMAL, "PS mode: %s\n", - wifi_ps_mode2str[config.ps_params.mode]); + wifi_ps_mode_txt(config.ps_params.mode)); } shell_fprintf(sh, SHELL_NORMAL, "PS listen_interval: %d\n", @@ -794,7 +1012,7 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "%s\n", wifi_ps2str[params.enabled]); + shell_fprintf(sh, SHELL_NORMAL, "%s\n", wifi_ps_txt(params.enabled)); return 0; } @@ -819,12 +1037,12 @@ static int cmd_wifi_ps_mode(const struct shell *sh, size_t argc, char *argv[]) if (net_mgmt(NET_REQUEST_WIFI_PS, iface, ¶ms, sizeof(params))) { shell_fprintf(sh, SHELL_WARNING, "%s failed Reason : %s\n", - wifi_ps_mode2str[params.mode], + wifi_ps_mode_txt(params.mode), wifi_ps_get_config_err_code_str(params.fail_reason)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "%s\n", wifi_ps_mode2str[params.mode]); + shell_fprintf(sh, SHELL_NORMAL, "%s\n", wifi_ps_mode_txt(params.mode)); return 0; } @@ -903,15 +1121,15 @@ static int cmd_wifi_twt_setup_quick(const struct shell *sh, size_t argc, if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n", - wifi_twt_operation2str[params.operation], - wifi_twt_negotiation_type2str[params.negotiation_type], + wifi_twt_operation_txt(params.operation), + wifi_twt_negotiation_type_txt(params.negotiation_type), wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s with dg: %d, flow_id: %d requested\n", - wifi_twt_operation2str[params.operation], + wifi_twt_operation_txt(params.operation), params.dialog_token, params.flow_id); return 0; @@ -990,15 +1208,15 @@ static int cmd_wifi_twt_setup(const struct shell *sh, size_t argc, if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { shell_fprintf(sh, SHELL_WARNING, "%s with %s failed. reason : %s\n", - wifi_twt_operation2str[params.operation], - wifi_twt_negotiation_type2str[params.negotiation_type], + wifi_twt_operation_txt(params.operation), + wifi_twt_negotiation_type_txt(params.negotiation_type), wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s with dg: %d, flow_id: %d requested\n", - wifi_twt_operation2str[params.operation], + wifi_twt_operation_txt(params.operation), params.dialog_token, params.flow_id); return 0; @@ -1046,15 +1264,15 @@ static int cmd_wifi_twt_teardown(const struct shell *sh, size_t argc, if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n", - wifi_twt_operation2str[params.operation], - wifi_twt_negotiation_type2str[params.negotiation_type], + wifi_twt_operation_txt(params.operation), + wifi_twt_negotiation_type_txt(params.negotiation_type), wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s with dg: %d, flow_id: %d success\n", - wifi_twt_operation2str[params.operation], + wifi_twt_operation_txt(params.operation), params.dialog_token, params.flow_id); return 0; @@ -1073,15 +1291,15 @@ static int cmd_wifi_twt_teardown_all(const struct shell *sh, size_t argc, if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n", - wifi_twt_operation2str[params.operation], - wifi_twt_negotiation_type2str[params.negotiation_type], + wifi_twt_operation_txt(params.operation), + wifi_twt_negotiation_type_txt(params.negotiation_type), wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s all flows success\n", - wifi_twt_operation2str[params.operation]); + wifi_twt_operation_txt(params.operation)); return 0; } @@ -1258,7 +1476,7 @@ static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *ar } shell_fprintf(sh, SHELL_NORMAL, "%s\n", - wifi_ps_wakeup_mode2str[params.wakeup_mode]); + wifi_ps_wakeup_mode_txt(params.wakeup_mode)); return 0; } From 4a36c92e39aae11a7736b872dd9f0c8d34235af5 Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Thu, 28 Sep 2023 10:32:02 +0530 Subject: [PATCH 0062/1623] [nrf fromtree] net: wifi: Move function from shell to mgmt The CONFIG_NET_L2_WIFI_SHELL isn't always enabled. But these functions might still be used, so need to move functions into mgmt. Signed-off-by: Kapil Bhatt (cherry picked from commit 29bbcb1e38f84b505c7fe7e3f7ab4bb3497eea4c) (cherry picked from commit a47925f081693cfef963af4f29b2f9f0ccc80768) Signed-off-by: Dominik Ermel (cherry picked from commit ed131f28ebff3cce80390855dc02cce45d06adc6) --- subsys/net/l2/wifi/wifi_mgmt.c | 218 ++++++++++++++++++++++++++++++++ subsys/net/l2/wifi/wifi_shell.c | 218 -------------------------------- 2 files changed, 218 insertions(+), 218 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 7f0f30dc8c1..65457427bda 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -18,6 +18,224 @@ LOG_MODULE_REGISTER(net_wifi_mgmt, CONFIG_NET_L2_WIFI_MGMT_LOG_LEVEL); #include #endif /* CONFIG_WIFI_NM */ +const char * const wifi_security_txt(enum wifi_security_type security) +{ + switch (security) { + case WIFI_SECURITY_TYPE_NONE: + return "OPEN"; + case WIFI_SECURITY_TYPE_WEP: + return "WEP"; + case WIFI_SECURITY_TYPE_WPA_PSK: + return "WPA-PSK"; + case WIFI_SECURITY_TYPE_PSK: + return "WPA2-PSK"; + case WIFI_SECURITY_TYPE_PSK_SHA256: + return "WPA2-PSK-SHA256"; + case WIFI_SECURITY_TYPE_SAE: + return "WPA3-SAE"; + case WIFI_SECURITY_TYPE_WAPI: + return "WAPI"; + case WIFI_SECURITY_TYPE_EAP: + return "EAP"; + case WIFI_SECURITY_TYPE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_mfp_txt(enum wifi_mfp_options mfp) +{ + switch (mfp) { + case WIFI_MFP_DISABLE: + return "Disable"; + case WIFI_MFP_OPTIONAL: + return "Optional"; + case WIFI_MFP_REQUIRED: + return "Required"; + case WIFI_MFP_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_band_txt(enum wifi_frequency_bands band) +{ + switch (band) { + case WIFI_FREQ_BAND_2_4_GHZ: + return "2.4GHz"; + case WIFI_FREQ_BAND_5_GHZ: + return "5GHz"; + case WIFI_FREQ_BAND_6_GHZ: + return "6GHz"; + case WIFI_FREQ_BAND_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_state_txt(enum wifi_iface_state state) +{ + switch (state) { + case WIFI_STATE_DISCONNECTED: + return "DISCONNECTED"; + case WIFI_STATE_INACTIVE: + return "INACTIVE"; + case WIFI_STATE_INTERFACE_DISABLED: + return "INTERFACE_DISABLED"; + case WIFI_STATE_SCANNING: + return "SCANNING"; + case WIFI_STATE_AUTHENTICATING: + return "AUTHENTICATING"; + case WIFI_STATE_ASSOCIATING: + return "ASSOCIATING"; + case WIFI_STATE_ASSOCIATED: + return "ASSOCIATED"; + case WIFI_STATE_4WAY_HANDSHAKE: + return "4WAY_HANDSHAKE"; + case WIFI_STATE_GROUP_HANDSHAKE: + return "GROUP_HANDSHAKE"; + case WIFI_STATE_COMPLETED: + return "COMPLETED"; + case WIFI_STATE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_mode_txt(enum wifi_iface_mode mode) +{ + switch (mode) { + case WIFI_MODE_INFRA: + return "STATION"; + case WIFI_MODE_IBSS: + return "ADHOC"; + case WIFI_MODE_AP: + return "ACCESS POINT"; + case WIFI_MODE_P2P_GO: + return "P2P GROUP OWNER"; + case WIFI_MODE_P2P_GROUP_FORMATION: + return "P2P GROUP FORMATION"; + case WIFI_MODE_MESH: + return "MESH"; + case WIFI_MODE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_link_mode_txt(enum wifi_link_mode link_mode) +{ + switch (link_mode) { + case WIFI_0: + return "WIFI 0 (802.11)"; + case WIFI_1: + return "WIFI 1 (802.11b)"; + case WIFI_2: + return "WIFI 2 (802.11a)"; + case WIFI_3: + return "WIFI 3 (802.11g)"; + case WIFI_4: + return "WIFI 4 (802.11n/HT)"; + case WIFI_5: + return "WIFI 5 (802.11ac/VHT)"; + case WIFI_6: + return "WIFI 6 (802.11ax/HE)"; + case WIFI_6E: + return "WIFI 6E (802.11ax 6GHz/HE)"; + case WIFI_7: + return "WIFI 7 (802.11be/EHT)"; + case WIFI_LINK_MODE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_ps_txt(enum wifi_ps ps_name) +{ + switch (ps_name) { + case WIFI_PS_DISABLED: + return "Power save disabled"; + case WIFI_PS_ENABLED: + return "Power save enabled"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_ps_mode_txt(enum wifi_ps_mode ps_mode) +{ + switch (ps_mode) { + case WIFI_PS_MODE_LEGACY: + return "Legacy power save"; + case WIFI_PS_MODE_WMM: + return "WMM power save"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_twt_operation_txt(enum wifi_twt_operation twt_operation) +{ + switch (twt_operation) { + case WIFI_TWT_SETUP: + return "TWT setup"; + case WIFI_TWT_TEARDOWN: + return "TWT teardown"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_twt_negotiation_type_txt(enum wifi_twt_negotiation_type twt_negotiation) +{ + switch (twt_negotiation) { + case WIFI_TWT_INDIVIDUAL: + return "TWT individual negotiation"; + case WIFI_TWT_BROADCAST: + return "TWT broadcast negotiation"; + case WIFI_TWT_WAKE_TBTT: + return "TWT wake TBTT negotiation"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_twt_setup_cmd_txt(enum wifi_twt_setup_cmd twt_setup) +{ + switch (twt_setup) { + case WIFI_TWT_SETUP_CMD_REQUEST: + return "TWT request"; + case WIFI_TWT_SETUP_CMD_SUGGEST: + return "TWT suggest"; + case WIFI_TWT_SETUP_CMD_DEMAND: + return "TWT demand"; + case WIFI_TWT_SETUP_CMD_GROUPING: + return "TWT grouping"; + case WIFI_TWT_SETUP_CMD_ACCEPT: + return "TWT accept"; + case WIFI_TWT_SETUP_CMD_ALTERNATE: + return "TWT alternate"; + case WIFI_TWT_SETUP_CMD_DICTATE: + return "TWT dictate"; + case WIFI_TWT_SETUP_CMD_REJECT: + return "TWT reject"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode) +{ + switch (ps_wakeup_mode) { + case WIFI_PS_WAKEUP_MODE_DTIM: + return "PS wakeup mode DTIM"; + case WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL: + return "PS wakeup mode listen interval"; + default: + return "UNKNOWN"; + } +} + static const struct wifi_mgmt_ops *const get_wifi_api(struct net_if *iface) { const struct device *dev = net_if_get_device(iface); diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 74284e56e98..7472d3fa984 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -97,224 +97,6 @@ static bool parse_number(const struct shell *sh, long *param, char *str, long mi return true; } -const char * const wifi_security_txt(enum wifi_security_type security) -{ - switch (security) { - case WIFI_SECURITY_TYPE_NONE: - return "OPEN"; - case WIFI_SECURITY_TYPE_WEP: - return "WEP"; - case WIFI_SECURITY_TYPE_WPA_PSK: - return "WPA-PSK"; - case WIFI_SECURITY_TYPE_PSK: - return "WPA2-PSK"; - case WIFI_SECURITY_TYPE_PSK_SHA256: - return "WPA2-PSK-SHA256"; - case WIFI_SECURITY_TYPE_SAE: - return "WPA3-SAE"; - case WIFI_SECURITY_TYPE_WAPI: - return "WAPI"; - case WIFI_SECURITY_TYPE_EAP: - return "EAP"; - case WIFI_SECURITY_TYPE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_mfp_txt(enum wifi_mfp_options mfp) -{ - switch (mfp) { - case WIFI_MFP_DISABLE: - return "Disable"; - case WIFI_MFP_OPTIONAL: - return "Optional"; - case WIFI_MFP_REQUIRED: - return "Required"; - case WIFI_MFP_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_band_txt(enum wifi_frequency_bands band) -{ - switch (band) { - case WIFI_FREQ_BAND_2_4_GHZ: - return "2.4GHz"; - case WIFI_FREQ_BAND_5_GHZ: - return "5GHz"; - case WIFI_FREQ_BAND_6_GHZ: - return "6GHz"; - case WIFI_FREQ_BAND_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_state_txt(enum wifi_iface_state state) -{ - switch (state) { - case WIFI_STATE_DISCONNECTED: - return "DISCONNECTED"; - case WIFI_STATE_INACTIVE: - return "INACTIVE"; - case WIFI_STATE_INTERFACE_DISABLED: - return "INTERFACE_DISABLED"; - case WIFI_STATE_SCANNING: - return "SCANNING"; - case WIFI_STATE_AUTHENTICATING: - return "AUTHENTICATING"; - case WIFI_STATE_ASSOCIATING: - return "ASSOCIATING"; - case WIFI_STATE_ASSOCIATED: - return "ASSOCIATED"; - case WIFI_STATE_4WAY_HANDSHAKE: - return "4WAY_HANDSHAKE"; - case WIFI_STATE_GROUP_HANDSHAKE: - return "GROUP_HANDSHAKE"; - case WIFI_STATE_COMPLETED: - return "COMPLETED"; - case WIFI_STATE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_mode_txt(enum wifi_iface_mode mode) -{ - switch (mode) { - case WIFI_MODE_INFRA: - return "STATION"; - case WIFI_MODE_IBSS: - return "ADHOC"; - case WIFI_MODE_AP: - return "ACCESS POINT"; - case WIFI_MODE_P2P_GO: - return "P2P GROUP OWNER"; - case WIFI_MODE_P2P_GROUP_FORMATION: - return "P2P GROUP FORMATION"; - case WIFI_MODE_MESH: - return "MESH"; - case WIFI_MODE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_link_mode_txt(enum wifi_link_mode link_mode) -{ - switch (link_mode) { - case WIFI_0: - return "WIFI 0 (802.11)"; - case WIFI_1: - return "WIFI 1 (802.11b)"; - case WIFI_2: - return "WIFI 2 (802.11a)"; - case WIFI_3: - return "WIFI 3 (802.11g)"; - case WIFI_4: - return "WIFI 4 (802.11n/HT)"; - case WIFI_5: - return "WIFI 5 (802.11ac/VHT)"; - case WIFI_6: - return "WIFI 6 (802.11ax/HE)"; - case WIFI_6E: - return "WIFI 6E (802.11ax 6GHz/HE)"; - case WIFI_7: - return "WIFI 7 (802.11be/EHT)"; - case WIFI_LINK_MODE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_ps_txt(enum wifi_ps ps_name) -{ - switch (ps_name) { - case WIFI_PS_DISABLED: - return "Power save disabled"; - case WIFI_PS_ENABLED: - return "Power save enabled"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_ps_mode_txt(enum wifi_ps_mode ps_mode) -{ - switch (ps_mode) { - case WIFI_PS_MODE_LEGACY: - return "Legacy power save"; - case WIFI_PS_MODE_WMM: - return "WMM power save"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_twt_operation_txt(enum wifi_twt_operation twt_operation) -{ - switch (twt_operation) { - case WIFI_TWT_SETUP: - return "TWT setup"; - case WIFI_TWT_TEARDOWN: - return "TWT teardown"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_twt_negotiation_type_txt(enum wifi_twt_negotiation_type twt_negotiation) -{ - switch (twt_negotiation) { - case WIFI_TWT_INDIVIDUAL: - return "TWT individual negotiation"; - case WIFI_TWT_BROADCAST: - return "TWT broadcast negotiation"; - case WIFI_TWT_WAKE_TBTT: - return "TWT wake TBTT negotiation"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_twt_setup_cmd_txt(enum wifi_twt_setup_cmd twt_setup) -{ - switch (twt_setup) { - case WIFI_TWT_SETUP_CMD_REQUEST: - return "TWT request"; - case WIFI_TWT_SETUP_CMD_SUGGEST: - return "TWT suggest"; - case WIFI_TWT_SETUP_CMD_DEMAND: - return "TWT demand"; - case WIFI_TWT_SETUP_CMD_GROUPING: - return "TWT grouping"; - case WIFI_TWT_SETUP_CMD_ACCEPT: - return "TWT accept"; - case WIFI_TWT_SETUP_CMD_ALTERNATE: - return "TWT alternate"; - case WIFI_TWT_SETUP_CMD_DICTATE: - return "TWT dictate"; - case WIFI_TWT_SETUP_CMD_REJECT: - return "TWT reject"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode) -{ - switch (ps_wakeup_mode) { - case WIFI_PS_WAKEUP_MODE_DTIM: - return "PS wakeup mode DTIM"; - case WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL: - return "PS wakeup mode listen interval"; - default: - return "UNKNOWN"; - } -} - static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb) { const struct wifi_scan_result *entry = From 2069e2a621432e875a488200ef7a4d95285f5864 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 5 Sep 2023 12:44:50 +0530 Subject: [PATCH 0063/1623] [nrf fromtree] Bluetooth: Controller: Fix missing PHY_CODED cond compile Fix missing Coded PHY implementation conditional compile causing compile error when disabling Coded PHY support in SoCs that have radio that support Coded PHY. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit e8fe144f3a0209569ea661520b65dee20e767c12) Signed-off-by: Dominik Ermel (cherry picked from commit 120b33f965d46bbedbf4e4e08e521fec64f432dc) --- samples/bluetooth/hci_rpmsg/sample.yaml | 10 ++++++++++ .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/samples/bluetooth/hci_rpmsg/sample.yaml b/samples/bluetooth/hci_rpmsg/sample.yaml index 3330002a59d..7cecb12be67 100644 --- a/samples/bluetooth/hci_rpmsg/sample.yaml +++ b/samples/bluetooth/hci_rpmsg/sample.yaml @@ -82,6 +82,16 @@ tests: platform_allow: nrf5340dk_nrf5340_cpunet integration_platforms: - nrf5340dk_nrf5340_cpunet + sample.bluetooth.hci_rpmsg.df.no_phy_coded.bt_ll_sw_split: + harness: bluetooth + tags: bluetooth + extra_args: + - CONF_FILE="nrf5340_cpunet_df-bt_ll_sw_split.conf" + - DTC_OVERLAY_FILE="nrf5340_cpunet_df-bt_ll_sw_split.overlay" + - CONFIG_BT_CTLR_PHY_CODED=n + platform_allow: nrf5340dk_nrf5340_cpunet + integration_platforms: + - nrf5340dk_nrf5340_cpunet sample.bluetooth.hci_rpmsg.mesh.bt_ll_sw_split: harness: bluetooth tags: bluetooth diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 085b881d47e..71e5ffa0e6f 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -582,6 +582,7 @@ static inline void hal_radio_sw_switch_coded_tx_config_set(uint8_t ppi_en, BIT(HAL_SW_SWITCH_TIMER_S8_DISABLE_PPI)); } +#if defined(CONFIG_BT_CTLR_PHY_CODED) && defined(CONFIG_HAS_HW_NRF_RADIO_BLE_CODED) static inline void hal_radio_sw_switch_coded_config_clear(uint8_t ppi_en, uint8_t ppi_dis, uint8_t cc_reg, uint8_t group_index) { @@ -594,6 +595,7 @@ static inline void hal_radio_sw_switch_coded_config_clear(uint8_t ppi_en, HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT( SW_SWITCH_TIMER_S2_EVTS_COMP(group_index)) = 0; } +#endif /* CONFIG_BT_CTLR_PHY_CODED && CONFIG_HAS_HW_NRF_RADIO_BLE_CODED */ static inline void hal_radio_sw_switch_disable_group_clear(uint8_t ppi_dis, uint8_t cc_reg, uint8_t group_index) From 61e999db7b38eff9939f51860a0a2e2a7fe87138 Mon Sep 17 00:00:00 2001 From: Huifeng Zhang Date: Fri, 8 Sep 2023 13:31:24 +0800 Subject: [PATCH 0064/1623] [nrf fromtree] tests: net: lib: lwm2m: fix the missing float support The tests `content_json` and `content_plain_test` depend on the float support of libc. After PR##57340, Picolibc would be selected in these two tests and the `PICOLIBC_IO_FLOAT` won't be selected if the platform doesn't select `FPU`. This commit select `CONFIG_PICOLIBC` and `CONFIG_PICOLIBC_IO_FLOAT` for these two tests. Signed-off-by: Huifeng Zhang (cherry picked from commit 5a1a1fe13d88c6429d2cf80975aaea3302441ce1) Signed-off-by: Dominik Ermel (cherry picked from commit fb04730a55116fb950719b81823acc0b41e7f98c) --- tests/net/lib/lwm2m/content_json/prj.conf | 2 ++ tests/net/lib/lwm2m/content_plain_text/prj.conf | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/net/lib/lwm2m/content_json/prj.conf b/tests/net/lib/lwm2m/content_json/prj.conf index 3f2cd3e60f2..7ff07df9897 100644 --- a/tests/net/lib/lwm2m/content_json/prj.conf +++ b/tests/net/lib/lwm2m/content_json/prj.conf @@ -9,3 +9,5 @@ CONFIG_LWM2M=y CONFIG_LWM2M_COAP_MAX_MSG_SIZE=512 CONFIG_LWM2M_RW_JSON_SUPPORT=y CONFIG_JSON_LIBRARY=y + +CONFIG_PICOLIBC_IO_FLOAT=y diff --git a/tests/net/lib/lwm2m/content_plain_text/prj.conf b/tests/net/lib/lwm2m/content_plain_text/prj.conf index 6041addad83..877c969958f 100644 --- a/tests/net/lib/lwm2m/content_plain_text/prj.conf +++ b/tests/net/lib/lwm2m/content_plain_text/prj.conf @@ -6,3 +6,5 @@ CONFIG_ZTEST_NEW_API=y CONFIG_ENTROPY_GENERATOR=y CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_LWM2M=y + +CONFIG_PICOLIBC_IO_FLOAT=y From 350e687dd5c75ac574fbea06200b8f02b854a7c7 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Wed, 27 Sep 2023 09:41:10 +0000 Subject: [PATCH 0065/1623] [nrf noup] test: schedule_api: Use Minimal C library There is no point to use PICOLIB here as it bloats the tests. Signed-off-by: Dominik Ermel (cherry picked from commit a52d1de722821b61f3338d9955015777489bf1e5) --- tests/kernel/sched/schedule_api/prj.conf | 1 + tests/kernel/sched/schedule_api/prj_dumb.conf | 1 + tests/kernel/sched/schedule_api/prj_multiq.conf | 1 + 3 files changed, 3 insertions(+) diff --git a/tests/kernel/sched/schedule_api/prj.conf b/tests/kernel/sched/schedule_api/prj.conf index b24271c4232..4178dc560a9 100644 --- a/tests/kernel/sched/schedule_api/prj.conf +++ b/tests/kernel/sched/schedule_api/prj.conf @@ -8,3 +8,4 @@ CONFIG_MAX_THREAD_BYTES=5 CONFIG_TEST_USERSPACE=y CONFIG_MP_MAX_NUM_CPUS=1 CONFIG_ZTEST_FATAL_HOOK=y +CONFIG_MINIMAL_LIBC=y diff --git a/tests/kernel/sched/schedule_api/prj_dumb.conf b/tests/kernel/sched/schedule_api/prj_dumb.conf index 9d996d2c9fb..5331db2daed 100644 --- a/tests/kernel/sched/schedule_api/prj_dumb.conf +++ b/tests/kernel/sched/schedule_api/prj_dumb.conf @@ -6,3 +6,4 @@ CONFIG_SCHED_DUMB=y CONFIG_MAX_THREAD_BYTES=5 CONFIG_MP_MAX_NUM_CPUS=1 CONFIG_ZTEST_FATAL_HOOK=y +CONFIG_MINIMAL_LIBC=y diff --git a/tests/kernel/sched/schedule_api/prj_multiq.conf b/tests/kernel/sched/schedule_api/prj_multiq.conf index d1074c07585..0c37654fd60 100644 --- a/tests/kernel/sched/schedule_api/prj_multiq.conf +++ b/tests/kernel/sched/schedule_api/prj_multiq.conf @@ -6,3 +6,4 @@ CONFIG_SCHED_MULTIQ=y CONFIG_MAX_THREAD_BYTES=5 CONFIG_MP_MAX_NUM_CPUS=1 CONFIG_ZTEST_FATAL_HOOK=y +CONFIG_MINIMAL_LIBC=y From 7ff9fc19e1337526ed731f643d716ddcc55c9e9a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Tue, 26 Sep 2023 14:36:51 +0000 Subject: [PATCH 0066/1623] [nrf fromlist] Bluetooth: Host: Use memcpy instad of strncpy in bt_set_name memcpy makes more sense here. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63112 Signed-off-by: Dominik Ermel (cherry picked from commit 1866b939dd15ec88d0e78f3a5fa57290bcc0b6db) --- subsys/bluetooth/host/hci_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index b3a7e05891a..8e1227c0bf5 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -4110,7 +4110,7 @@ int bt_set_name(const char *name) return 0; } - strncpy(bt_dev.name, name, len); + memcpy(bt_dev.name, name, len); bt_dev.name[len] = '\0'; if (IS_ENABLED(CONFIG_BT_SETTINGS)) { From 0985ab67282f633fe616fb499248c225a75cfe24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Mon, 25 Sep 2023 08:42:00 +0200 Subject: [PATCH 0067/1623] [nrf fromtree] manifest: hal_nordic: update to prevent USBD bad DMA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bad DMA request was observed as SPU FLASHACCERR when building for nrf5340dk_nrf5340_cpuapp_ns target. The bad DMA request would manifest itself as device failing to reconnect after USB cable was reconnected. The issue was especially visible with CDC ACM sample because SET LINE CODING request has 7 bytes payload. (cherry picked from commit c796e1bee2e312ede01f6889539e6fb4bcceb8d4) Signed-off-by: Tomasz Moń (cherry picked from commit c2572c301f24bc9ae799519ea74dcd68a7b085c7) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 727d6d807ab..b4f874a87c5 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 9ae7c765985ebdea3d9b98c0d3b154794f0b47cf + revision: 092eb78ed1b1551d8f480019b9c05d7371784578 path: modules/hal/nordic groups: - hal From 6799c02cb60196ac26ebc1c1aeee54ca105f8e75 Mon Sep 17 00:00:00 2001 From: Mateusz Kapala Date: Fri, 1 Sep 2023 16:52:55 +0200 Subject: [PATCH 0068/1623] [nrf noup] boards: arm: thingy53: Fix MCUBOOT_USB_SUPPORT def Add missing MCUBOOT_USB_SUPPORT Kconfig type to fix doc build. Signed-off-by: Mateusz Kapala (cherry picked from commit fe27a31ba8bee739590183133f54938c2fe87796) --- boards/arm/thingy53_nrf5340/Kconfig.defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/boards/arm/thingy53_nrf5340/Kconfig.defconfig b/boards/arm/thingy53_nrf5340/Kconfig.defconfig index c79eb908c21..ec17fcff34a 100644 --- a/boards/arm/thingy53_nrf5340/Kconfig.defconfig +++ b/boards/arm/thingy53_nrf5340/Kconfig.defconfig @@ -160,6 +160,7 @@ endif # BOARD_SERIAL_BACKEND_CDC_ACM # It is not necessary for nRF Connect SDK to add another instance if MCUBoot # bootloader is built as a child image. config MCUBOOT_USB_SUPPORT + bool default n endif # BOARD_THINGY53_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP_NS From 2e321f2c6155adc5d32142a5235bd72ea55df2c3 Mon Sep 17 00:00:00 2001 From: Yves Vandervennet Date: Fri, 1 Sep 2023 11:41:36 -0500 Subject: [PATCH 0069/1623] [nrf fromtree] linkserver: doc: updates for NXP's mimxrt1170 This commit adds the documentation details for the linkserver support on rt1170. Signed-off-by: Yves Vandervennet (cherry picked from commit 1477865a7a1ee6c1a869265d949ab63669dfe597) Signed-off-by: Dominik Ermel (cherry picked from commit 254c933b4e4722cdf0e9a3595f65e7ed4f2e5b17) --- boards/arm/mimxrt1170_evk/doc/index.rst | 102 ++++++++++++++++-------- doc/develop/flash_debug/host-tools.rst | 25 ++++-- doc/develop/flash_debug/probes.rst | 61 ++++++++++++++ 3 files changed, 148 insertions(+), 40 deletions(-) diff --git a/boards/arm/mimxrt1170_evk/doc/index.rst b/boards/arm/mimxrt1170_evk/doc/index.rst index 90f192c3870..51d5053e360 100644 --- a/boards/arm/mimxrt1170_evk/doc/index.rst +++ b/boards/arm/mimxrt1170_evk/doc/index.rst @@ -1,4 +1,4 @@ -.. _mimxrt1170_evk: +.. _mimxrt1170_evk: NXP MIMXRT1170-EVK/EVKB ####################### @@ -9,7 +9,7 @@ Overview The dual core i.MX RT1170 runs on the Cortex-M7 core at 1 GHz and on the Cortex-M4 at 400 MHz. The i.MX RT1170 MCU offers support over a wide temperature range and is qualified for consumer, industrial and automotive markets. Zephyr -supports the initial revision of this EVK, as well as EVK rev B. +supports the initial revision of this EVK, as well as rev EVKB. .. image:: mimxrt1170_evk.jpg :align: center @@ -59,7 +59,7 @@ Hardware - Debug - JTAG 20-pin connector - - OpenSDA with DAPLink + - on-board debugger - Sensor @@ -90,16 +90,17 @@ This platform has the following external memories: | Device | Controller | Status | +====================+============+=====================================+ | W9825G6KH | SEMC | Enabled via device configuration | -| | | data block, which sets up SEMC at | -| | | boot time | +| SDRAM | | data (DCD) block, which sets up | +| | | the SEMC at boot time | +--------------------+------------+-------------------------------------+ -| IS25WP128 | FLEXSPI | Enabled via flash configurationn | -| (RT1170 EVK) | | block, which sets up FLEXSPI at | -| | | boot time. | +| IS25WP128 | FLEXSPI | Enabled via flash configuration | +| QSPI flash | | block (FCB), which sets up the | +| (RT1170 EVK) | | FLEXSPI at boot time. | +--------------------+------------+-------------------------------------+ -| W25Q512NWEIQ | FLEXSPI | Enabled via flash configurationn | -| (RT1170 EVKB) | | block, which sets up FLEXSPI at | -| | | boot time. Supported for XIP only. | +| W25Q512NWEIQ | FLEXSPI | Enabled via flash configuration | +| QSPI flash | | block (FCB), which sets up the | +| (RT1170 EVKB) | | FLEXSPI at boot time. Supported for | +| | | XIP only. | +--------------------+------------+-------------------------------------+ Supported Features @@ -123,6 +124,8 @@ RT1170 EVKB (`mimxrt1170_evkb_cm7/cm4`) +-----------+------------+-------------------------------------+-----------------+-----------------+ | COUNTER | on-chip | gpt | Supported | Supported | +-----------+------------+-------------------------------------+-----------------+-----------------+ +| TIMER | on-chip | gpt | Supported | Supported | ++-----------+------------+-------------------------------------+-----------------+-----------------+ | CAN | on-chip | flexcan | Supported (M7) | Supported (M7) | +-----------+------------+-------------------------------------+-----------------+-----------------+ | SPI | on-chip | spi | Supported (M7) | Supported | @@ -139,11 +142,10 @@ RT1170 EVKB (`mimxrt1170_evkb_cm7/cm4`) +-----------+------------+-------------------------------------+-----------------+-----------------+ | DMA | on-chip | dma | Supported | Supported | +-----------+------------+-------------------------------------+-----------------+-----------------+ -| GPT | on-chip | gpt | Supported | Supported | -+-----------+------------+-------------------------------------+-----------------+-----------------+ | WATCHDOG | on-chip | watchdog | Supported (M7) | Supported (M7) | +-----------+------------+-------------------------------------+-----------------+-----------------+ -| ENET | on-chip | ethernet | Supported (M7) | No support | +| ENET | on-chip | ethernet - 10/100M (ENET_QOS or | Supported (M7) | No support | +| ENET1G | | GigE not supported yet) | | | +-----------+------------+-------------------------------------+-----------------+-----------------+ | SAI | on-chip | i2s | Supported | No support | +-----------+------------+-------------------------------------+-----------------+-----------------+ @@ -165,10 +167,9 @@ RT1170 EVKB (`mimxrt1170_evkb_cm7/cm4`) | SDHC | on-chip | SD host controller | Supported (M7) | Supported (M7) | +-----------+------------+-------------------------------------+-----------------+-----------------+ -The default configuration can be found in the defconfig file: +The default configuration can be found in the defconfig files: ``boards/arm/mimxrt1170_evk/mimxrt1170_evk_cm7_defconfig`` - -Other hardware features are not currently supported by the port. +``boards/arm/mimxrt1170_evk/mimxrt1170_evkb_cm7_defconfig`` Connections and I/Os ==================== @@ -310,33 +311,62 @@ secondary core should be placed into a loop, then a debugger can be attached Configuring a Debug Probe ========================= -A debug probe is used for both flashing and debugging the board. This board is -configured by default to use the :ref:`opensda-daplink-onboard-debug-probe`, -however the :ref:`pyocd-debug-host-tools` do not yet support programming the -external flashes on this board so you must reconfigure the board for one of the -following debug probes instead. +A debug probe is used for both flashing and debugging the board. The on-board +debugger listed below works with the LinkServer runner by default, or can be +reprogrammed with JLink firmware. +- MIMXRT1170-EVKB: :ref:`mcu-link-cmsis-onboard-debug-probe` +- MIMXRT1170-EVK: :ref:`opensda-daplink-onboard-debug-probe` .. _Using J-Link RT1170: Using J-Link --------------------------------- -Install the :ref:`jlink-debug-host-tools` and make sure they are in your search -path. +JLink is the default runner for this board. Install the +:ref:`jlink-debug-host-tools` and make sure they are in your search path. There are two options: the onboard debug circuit can be updated with Segger J-Link firmware, or :ref:`jlink-external-debug-probe` can be attached to the -EVK. See `Using J-Link with MIMXRT1160-EVK or MIMXRT1170-EVK`_ for more details. +EVK. See `Using J-Link with MIMXRT1170-EVKB`_ or +`Using J-Link with MIMXRT1160-EVK or MIMXRT1170-EVK`_ for more details. + +.. _Using LinkServer RT1170: + +Using LinkServer +---------------------------------- + +Known limitations with LinkServer and these boards include: +- ``west debug`` does not yet work correctly, and the application image is not +properly written to the memory. `NXP MCUXpresso for Visual Studio Code`_ +can be used to debug Zephyr applications with LinkServer. +- ``west flash`` will not write images to non-flash locations. The flash +command only works when all data in the image is written to flash memory +regions. + +Install the :ref:`linkserver-debug-host-tools` and make sure they are in your +search path. LinkServer works with the default CMSIS-DAP firmware included in +the on-board debugger. + +Use the ``-r linkserver`` option with West to use the LinkServer runner. + +.. code-block:: console + + west flash -r linkserver + Configuring a Console ===================== -Regardless of your choice in debug probe, we will use the OpenSDA -microcontroller as a usb-to-serial adapter for the serial console. Check that -jumpers J5 and J8 are **on** (they are on by default when boards ship from -the factory) to connect UART signals to the OpenSDA microcontroller. +We will use the on-board debugger +microcontroller as a usb-to-serial adapter for the serial console. The following +jumper settings are default on these boards, and are required to connect the +UART signals to the USB bridge circuit: +- MIMXRT1170-EVKB: JP2 open (default) +- MIMXRT1170-EVK: J31 and J32 shorted (default) -Connect a USB cable from your PC to J11. +Connect a USB cable from your PC to the on-board debugger USB port: +- MIMXRT1170-EVKB: J86 +- MIMXRT1170-EVK: J11 Use the following settings with your serial terminal of choice (minicom, putty, etc.): @@ -351,7 +381,7 @@ Flashing Here is an example for the :ref:`hello_world` application. -Before power on the board, make sure SW1 is set to 0001b +Before powering the board, make sure SW1 is set to 0001b .. zephyr-app-commands:: :zephyr-app: samples/hello_world @@ -364,7 +394,7 @@ see the following message in the terminal: .. code-block:: console - ***** Booting Zephyr OS v2.4.0-xxxx-xxxxxxxxxxxxx ***** + ***** Booting Zephyr OS v3.4.0-xxxx-xxxxxxxxxxxxx ***** Hello World! mimxrt1170_evk_cm7 Debugging @@ -382,7 +412,7 @@ should see the following message in the terminal: .. code-block:: console - ***** Booting Zephyr OS v2.4.0-xxxx-xxxxxxxxxxxxx ***** + ***** Booting Zephyr OS v3.4.0-xxxx-xxxxxxxxxxxxx ***** Hello World! mimxrt1170_evk_cm7 .. _MIMXRT1170-EVK Website: @@ -403,5 +433,11 @@ should see the following message in the terminal: .. _Using J-Link with MIMXRT1160-EVK or MIMXRT1170-EVK: https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/Using-J-Link-with-MIMXRT1160-EVK-or-MIMXRT1170-EVK/ta-p/1529760 +.. _Using J-Link with MIMXRT1170-EVKB: + https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/Using-J-Link-with-MIMXRT1170-EVKB/ta-p/1715138 + .. _AN13264: https://www.nxp.com/docs/en/application-note/AN13264.pdf + +.. _NXP MCUXpresso for Visual Studio Code: + https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-for-visual-studio-code:MCUXPRESSO-VSC diff --git a/doc/develop/flash_debug/host-tools.rst b/doc/develop/flash_debug/host-tools.rst index e93ee618f55..981c89ce686 100644 --- a/doc/develop/flash_debug/host-tools.rst +++ b/doc/develop/flash_debug/host-tools.rst @@ -206,17 +206,20 @@ LinkServer Debug Host Tools Linkserver is a utility for launching and managing GDB servers for NXP debug probes, which also provides a command-line target flash programming capabilities. -Linkserver can be used with NXP MCUXpresso for Visual Studio Code implementation, +Linkserver can be used with the `NXP MCUXpresso for Visual Studio Code`_ implementation, with custom debug configurations based on GNU tools or as part of a headless solution -for continuous integration and test. Linkserver can be used with MCU-Link, LPC-Link2, +for continuous integration and test. LinkServer can be used with MCU-Link, LPC-Link2, LPC11U35-based and OpenSDA based standalone or on-board debug probes from NXP. -The Linkserver installer also includes the firmware update utilities for MCU-Link and -the LPCScrypt utility for use with LPC-Link2. Linkserver can also be installed using -the MCUXpresso Installer. + +NXP recommends installing LinkServer by using NXP's `MCUXpresso Installer`_. +This method will also install the tools supporting the debug probes below, +including NXP's MCU-Link and LPCScrypt tools. LinkServer is compatible with the following debug probes: - :ref:`lpclink2-cmsis-onboard-debug-probe` +- :ref:`mcu-link-cmsis-onboard-debug-probe` +- :ref:`opensda-daplink-onboard-debug-probe` Supported west commands: @@ -234,13 +237,14 @@ Notes: LinkServer probes -2. Use the LinkServer west runner ``--probe`` option to pass the probe index. +2. With multiple debug probes attached to the host, use the +LinkServer west runner ``--probe`` option to pass the probe index. .. code-block:: console west flash --runner=linkserver --probe=3 -3. device specific settings can be overridden with the west runner for LinkServer with +3. Device-specific settings can be overridden with the west runner for LinkServer with the option '--override'. May be used multiple times. The format is dictated by LinkServer, e.g.: @@ -265,6 +269,7 @@ These debug host tools are compatible with the following debug probes: - :ref:`lpclink2-jlink-onboard-debug-probe` - :ref:`opensda-jlink-onboard-debug-probe` +- :ref:`mcu-link-jlink-onboard-debug-probe` - :ref:`jlink-external-debug-probe` - :ref:`stlink-v21-onboard-debug-probe` @@ -405,3 +410,9 @@ To enable Zephyr RTOS awareness follow the steps described in .. _BOSSA official releases: https://github.com/shumatech/BOSSA/releases + +.. _NXP MCUXpresso for Visual Studio Code: + https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-for-visual-studio-code:MCUXPRESSO-VSC + +.. _MCUXpresso Installer: + https://www.nxp.com/lgfiles/updates/mcuxpresso/MCUXpressoInstaller.exe diff --git a/doc/develop/flash_debug/probes.rst b/doc/develop/flash_debug/probes.rst index 78a068d6ac4..83f355aadba 100644 --- a/doc/develop/flash_debug/probes.rst +++ b/doc/develop/flash_debug/probes.rst @@ -58,6 +58,64 @@ onboard debug probe may have limitations, such as lack of support for advanced debuggers or high-speed tracing. You may need to adjust jumpers to prevent the onboard debug probe from interfering with the external debug probe. +.. _mcu-link-cmsis-onboard-debug-probe: + +MCU-Link CMSIS-DAP Onboard Debug Probe +*************************************** + +The CMSIS-DAP debug probes allow debugging from any compatible toolchain, +including IAR EWARM, Keil MDK, NXP’s MCUXpresso IDE and +MCUXpresso extension for VS Code. In addition to debug probe functionality, the +MCU-Link probes may also provide: + +1. SWO trace end point: this virtual device is used by MCUXpresso to retrieve + SWO trace data. See the MCUXpresso IDE documentation for more information. +#. Virtual COM (VCOM) port / UART bridge connected to the target processor +#. USB to UART, SPI and/or I2C interfaces (depending on MCU-Link + type/implementation) +#. Energy measurements of the target MCU + +This debug probe is compatible with the following debug host tools: + +- :ref:`linkserver-debug-host-tools` + +This probe is realized by programming the MCU-Link microcontroller with the +CMSIS-DAP MCU-Link firmware, which is already installed by default. NXP +recommends using NXP's `MCUXpresso Installer`_, which installs both the MCU-Link +host tools plus the :ref:`linkserver-debug-host-tools`. + +1. Put the MCU-Link microcontroller into DFU boot mode by attaching the DFU + jumper, then powering up the board. + +#. Run the ``program_CMSIS`` script, found in the installed MCU-Link ``scripts`` + folder. + +#. Remove the DFU jumper and power cycle the board. + +.. _mcu-link-jlink-onboard-debug-probe: + +MCU-Link JLink Onboard Debug Probe +************************************ + +The MCU-Link J-Link is an onboard debug probe and usb-to-serial adapter +supported on many NXP development boards. + +This debug probe is compatible with the following debug host tools: + +- :ref:`jlink-debug-host-tools` + +These probes do not have JLink firmware installed by default, and must be +updated. NXP recommends using NXP's `MCUXpresso Installer`_, which installs both +the :ref:`jlink-debug-host-tools` plus the MCU-Link host tools. + +1. Put the MCU-Link microcontroller into DFU boot mode by attaching the DFU + jumper, then powering up the board. + +#. Run the ``program_JLINK`` script, found in the installed MCU-Link ``scripts`` + folder. + +#. Remove the DFU jumper and power cycle the board. + .. _lpclink2-cmsis-onboard-debug-probe: LPC-LINK2 CMSIS DAP Onboard Debug Probe @@ -341,3 +399,6 @@ option. For more information about twister and available options, see .. _STM32CubeProgrammer Tool: https://www.st.com/en/development-tools/stm32cubeprog.html + +.. _MCUXpresso Installer: + https://www.nxp.com/lgfiles/updates/mcuxpresso/MCUXpressoInstaller.exe From 3f54ea307c5d2ff2b956ecb191a3bba57e457b63 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 7 Sep 2023 12:15:29 +0200 Subject: [PATCH 0070/1623] [nrf fromtree] boards: arm: (mimx|vmu_)rt1170: fix documentation issues - Remove duplicated labels (not sure why they were not spotted by doc CI?) - Fix titles Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 0371708ba4d067319c4a66f33489ebec8aedd0fc) Signed-off-by: Dominik Ermel (cherry picked from commit 3948fd35bc6feab39bcb31614dec64e43ec9aa01) --- boards/arm/mimxrt1170_evk/doc/index.rst | 8 ++------ boards/arm/vmu_rt1170/doc/index.rst | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/boards/arm/mimxrt1170_evk/doc/index.rst b/boards/arm/mimxrt1170_evk/doc/index.rst index 51d5053e360..1582861ffc9 100644 --- a/boards/arm/mimxrt1170_evk/doc/index.rst +++ b/boards/arm/mimxrt1170_evk/doc/index.rst @@ -317,10 +317,8 @@ reprogrammed with JLink firmware. - MIMXRT1170-EVKB: :ref:`mcu-link-cmsis-onboard-debug-probe` - MIMXRT1170-EVK: :ref:`opensda-daplink-onboard-debug-probe` -.. _Using J-Link RT1170: - Using J-Link ---------------------------------- +------------ JLink is the default runner for this board. Install the :ref:`jlink-debug-host-tools` and make sure they are in your search path. @@ -330,10 +328,8 @@ J-Link firmware, or :ref:`jlink-external-debug-probe` can be attached to the EVK. See `Using J-Link with MIMXRT1170-EVKB`_ or `Using J-Link with MIMXRT1160-EVK or MIMXRT1170-EVK`_ for more details. -.. _Using LinkServer RT1170: - Using LinkServer ----------------------------------- +---------------- Known limitations with LinkServer and these boards include: - ``west debug`` does not yet work correctly, and the application image is not diff --git a/boards/arm/vmu_rt1170/doc/index.rst b/boards/arm/vmu_rt1170/doc/index.rst index 3514bf15893..28d57464b4f 100644 --- a/boards/arm/vmu_rt1170/doc/index.rst +++ b/boards/arm/vmu_rt1170/doc/index.rst @@ -216,10 +216,8 @@ Configuring a Debug Probe A debug probe is used for both flashing and debugging the board. -.. _Using J-Link RT1170: - Using J-Link ---------------------------------- +------------ Install the :ref:`jlink-debug-host-tools` and make sure they are in your search path. From cf88137e48d93f97b16354ce0a41e1323478bbb7 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 7 Sep 2023 12:50:06 +0200 Subject: [PATCH 0071/1623] [nrf fromtree] drivers: gpio: fix optional operations usage Only provide implementations for optional operations if needed. This patch deletes quite a few dummy `pin_interrupt_configure` ops (now optional), and adjusts ifdeffery on some drivers so that optional ops are only provided if they implement real functionality. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 64968d74024ab4d43de731c1e7c265869c63f2a0) Signed-off-by: Dominik Ermel (cherry picked from commit bc1cd429d26860622fc5eae54f03af59a94231e7) --- drivers/gpio/gpio_ads114s0x.c | 12 ------------ drivers/gpio/gpio_axp192.c | 12 ------------ drivers/gpio/gpio_bd8lb600fs.c | 7 ------- drivers/gpio/gpio_creg_gpio.c | 9 --------- drivers/gpio/gpio_cy8c95xx.c | 9 --------- drivers/gpio/gpio_fxl6408.c | 10 ---------- drivers/gpio/gpio_lmp90xxx.c | 14 -------------- drivers/gpio/gpio_mcp23s17.c | 9 --------- drivers/gpio/gpio_mmio32.c | 13 ------------- drivers/gpio/gpio_neorv32.c | 14 -------------- drivers/gpio/gpio_npm1300.c | 12 ------------ drivers/gpio/gpio_npm6001.c | 14 -------------- drivers/gpio/gpio_nxp_s32.c | 29 +++-------------------------- drivers/gpio/gpio_pca95xx.c | 14 ++------------ drivers/gpio/gpio_sc18im704.c | 12 ------------ drivers/gpio/gpio_sn74hc595.c | 11 ----------- drivers/gpio/gpio_stmpe1600.c | 9 --------- drivers/gpio/gpio_sx1509b.c | 11 +++-------- drivers/gpio/gpio_test.c | 23 ----------------------- drivers/gpio/gpio_xlnx_axi.c | 4 +++- drivers/gpio/gpio_xmc4xxx.c | 15 +++++---------- 21 files changed, 16 insertions(+), 247 deletions(-) diff --git a/drivers/gpio/gpio_ads114s0x.c b/drivers/gpio/gpio_ads114s0x.c index 79383d38154..13f4f7f1266 100644 --- a/drivers/gpio/gpio_ads114s0x.c +++ b/drivers/gpio/gpio_ads114s0x.c @@ -106,17 +106,6 @@ static int gpio_ads114s0x_port_toggle_bits(const struct device *dev, gpio_port_p return ads114s0x_gpio_port_toggle_bits(config->parent, pins); } -static int gpio_ads114s0x_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, - enum gpio_int_mode mode, enum gpio_int_trig trig) -{ - ARG_UNUSED(dev); - ARG_UNUSED(pin); - ARG_UNUSED(mode); - ARG_UNUSED(trig); - - return -ENOTSUP; -} - static int gpio_ads114s0x_init(const struct device *dev) { const struct gpio_ads114s0x_config *config = dev->config; @@ -135,7 +124,6 @@ static const struct gpio_driver_api gpio_ads114s0x_api = { .port_set_bits_raw = gpio_ads114s0x_port_set_bits_raw, .port_clear_bits_raw = gpio_ads114s0x_port_clear_bits_raw, .port_toggle_bits = gpio_ads114s0x_port_toggle_bits, - .pin_interrupt_configure = gpio_ads114s0x_pin_interrupt_configure, .port_get_raw = gpio_ads114s0x_port_get_raw, }; diff --git a/drivers/gpio/gpio_axp192.c b/drivers/gpio/gpio_axp192.c index ee75fe9b276..95625d99dfe 100644 --- a/drivers/gpio/gpio_axp192.c +++ b/drivers/gpio/gpio_axp192.c @@ -159,17 +159,6 @@ static int gpio_axp192_port_toggle_bits(const struct device *dev, gpio_port_pins return ret; } -static int gpio_axp192_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, - enum gpio_int_mode mode, enum gpio_int_trig trig) -{ - ARG_UNUSED(dev); - ARG_UNUSED(pin); - ARG_UNUSED(mode); - ARG_UNUSED(trig); - - return -ENOTSUP; -} - #ifdef CONFIG_GPIO_GET_CONFIG static int gpio_axp192_get_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t *out_flags) { @@ -276,7 +265,6 @@ static const struct gpio_driver_api gpio_axp192_api = { .port_set_bits_raw = gpio_axp192_port_set_bits_raw, .port_clear_bits_raw = gpio_axp192_port_clear_bits_raw, .port_toggle_bits = gpio_axp192_port_toggle_bits, - .pin_interrupt_configure = gpio_axp192_pin_interrupt_configure, .manage_callback = gpio_axp192_manage_callback, #ifdef CONFIG_GPIO_GET_DIRECTION .port_get_direction = gpio_axp192_port_get_direction, diff --git a/drivers/gpio/gpio_bd8lb600fs.c b/drivers/gpio/gpio_bd8lb600fs.c index 555a63b91fd..30ae851d90b 100644 --- a/drivers/gpio/gpio_bd8lb600fs.c +++ b/drivers/gpio/gpio_bd8lb600fs.c @@ -193,12 +193,6 @@ static int bd8lb600fs_port_toggle_bits(const struct device *dev, uint32_t mask) return result; } -static int bd8lb600fs_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, - enum gpio_int_mode mode, enum gpio_int_trig trig) -{ - return -ENOTSUP; -} - static const struct gpio_driver_api api_table = { .pin_configure = bd8lb600fs_pin_configure, .port_get_raw = bd8lb600fs_port_get_raw, @@ -206,7 +200,6 @@ static const struct gpio_driver_api api_table = { .port_set_bits_raw = bd8lb600fs_port_set_bits_raw, .port_clear_bits_raw = bd8lb600fs_port_clear_bits_raw, .port_toggle_bits = bd8lb600fs_port_toggle_bits, - .pin_interrupt_configure = bd8lb600fs_pin_interrupt_configure, }; static int bd8lb600fs_init(const struct device *dev) diff --git a/drivers/gpio/gpio_creg_gpio.c b/drivers/gpio/gpio_creg_gpio.c index 05b09184df9..1b9f4d63a50 100644 --- a/drivers/gpio/gpio_creg_gpio.c +++ b/drivers/gpio/gpio_creg_gpio.c @@ -104,14 +104,6 @@ static int port_toggle_bits(const struct device *dev, return port_write(dev, 0, 0, pins); } -static int pin_interrupt_configure(const struct device *dev, - gpio_pin_t pin, - enum gpio_int_mode mode, - enum gpio_int_trig trig) -{ - return -ENOTSUP; -} - static int pin_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t flags) @@ -163,7 +155,6 @@ static const struct gpio_driver_api api_table = { .port_set_bits_raw = port_set_bits, .port_clear_bits_raw = port_clear_bits, .port_toggle_bits = port_toggle_bits, - .pin_interrupt_configure = pin_interrupt_configure, }; static const struct creg_gpio_config creg_gpio_cfg = { diff --git a/drivers/gpio/gpio_cy8c95xx.c b/drivers/gpio/gpio_cy8c95xx.c index b540a7b96bf..155bfb4988a 100644 --- a/drivers/gpio/gpio_cy8c95xx.c +++ b/drivers/gpio/gpio_cy8c95xx.c @@ -214,14 +214,6 @@ static int port_toggle_bits(const struct device *dev, return port_write(dev, 0, 0, pins); } -static int pin_interrupt_configure(const struct device *dev, - gpio_pin_t pin, - enum gpio_int_mode mode, - enum gpio_int_trig trig) -{ - return -ENOTSUP; -} - /** * @brief Initialization function of CY8C95XX * @@ -277,7 +269,6 @@ static const struct gpio_driver_api api_table = { .port_set_bits_raw = port_set_bits, .port_clear_bits_raw = port_clear_bits, .port_toggle_bits = port_toggle_bits, - .pin_interrupt_configure = pin_interrupt_configure, }; static struct k_sem cy8c95xx_lock = Z_SEM_INITIALIZER(cy8c95xx_lock, 1, 1); diff --git a/drivers/gpio/gpio_fxl6408.c b/drivers/gpio/gpio_fxl6408.c index 164a4396c13..7352390e371 100644 --- a/drivers/gpio/gpio_fxl6408.c +++ b/drivers/gpio/gpio_fxl6408.c @@ -377,15 +377,6 @@ static int gpio_fxl6408_port_toggle_bits(const struct device *dev, return ret; } -static int gpio_fxl6408_pin_interrupt_configure(const struct device *port, - gpio_pin_t pin, - enum gpio_int_mode mode, - enum gpio_int_trig trig) -{ - LOG_DBG("Pin interrupts not supported."); - return -ENOTSUP; -} - int gpio_fxl6408_init(const struct device *dev) { struct gpio_fxl6408_drv_data *const drv_data = @@ -409,7 +400,6 @@ static const struct gpio_driver_api gpio_fxl_driver = { .port_set_bits_raw = gpio_fxl6408_port_set_bits_raw, .port_clear_bits_raw = gpio_fxl6408_port_clear_bits_raw, .port_toggle_bits = gpio_fxl6408_port_toggle_bits, - .pin_interrupt_configure = gpio_fxl6408_pin_interrupt_configure }; #define GPIO_FXL6408_DEVICE_INSTANCE(inst) \ diff --git a/drivers/gpio/gpio_lmp90xxx.c b/drivers/gpio/gpio_lmp90xxx.c index 1bd99d88cf2..2514ef35211 100644 --- a/drivers/gpio/gpio_lmp90xxx.c +++ b/drivers/gpio/gpio_lmp90xxx.c @@ -122,19 +122,6 @@ static int gpio_lmp90xxx_port_toggle_bits(const struct device *dev, return lmp90xxx_gpio_port_toggle_bits(config->parent, pins); } -static int gpio_lmp90xxx_pin_interrupt_configure(const struct device *dev, - gpio_pin_t pin, - enum gpio_int_mode mode, - enum gpio_int_trig trig) -{ - ARG_UNUSED(dev); - ARG_UNUSED(pin); - ARG_UNUSED(mode); - ARG_UNUSED(trig); - - return -ENOTSUP; -} - static int gpio_lmp90xxx_init(const struct device *dev) { const struct gpio_lmp90xxx_config *config = dev->config; @@ -154,7 +141,6 @@ static const struct gpio_driver_api gpio_lmp90xxx_api = { .port_set_bits_raw = gpio_lmp90xxx_port_set_bits_raw, .port_clear_bits_raw = gpio_lmp90xxx_port_clear_bits_raw, .port_toggle_bits = gpio_lmp90xxx_port_toggle_bits, - .pin_interrupt_configure = gpio_lmp90xxx_pin_interrupt_configure, .port_get_raw = gpio_lmp90xxx_port_get_raw, }; diff --git a/drivers/gpio/gpio_mcp23s17.c b/drivers/gpio/gpio_mcp23s17.c index 96a266fdf6d..4849c3a02fe 100644 --- a/drivers/gpio/gpio_mcp23s17.c +++ b/drivers/gpio/gpio_mcp23s17.c @@ -340,14 +340,6 @@ static int mcp23s17_port_toggle_bits(const struct device *dev, uint32_t mask) return ret; } -static int mcp23s17_pin_interrupt_configure(const struct device *dev, - gpio_pin_t pin, - enum gpio_int_mode mode, - enum gpio_int_trig trig) -{ - return -ENOTSUP; -} - static const struct gpio_driver_api api_table = { .pin_configure = mcp23s17_config, .port_get_raw = mcp23s17_port_get_raw, @@ -355,7 +347,6 @@ static const struct gpio_driver_api api_table = { .port_set_bits_raw = mcp23s17_port_set_bits_raw, .port_clear_bits_raw = mcp23s17_port_clear_bits_raw, .port_toggle_bits = mcp23s17_port_toggle_bits, - .pin_interrupt_configure = mcp23s17_pin_interrupt_configure, }; static int mcp23s17_init(const struct device *dev) diff --git a/drivers/gpio/gpio_mmio32.c b/drivers/gpio/gpio_mmio32.c index e9e58373b5b..0fe5e9fedd8 100644 --- a/drivers/gpio/gpio_mmio32.c +++ b/drivers/gpio/gpio_mmio32.c @@ -147,18 +147,6 @@ static int gpio_mmio32_port_toggle_bits(const struct device *dev, return 0; } -static int gpio_mmio32_pin_interrupt_configure(const struct device *dev, - gpio_pin_t pin, - enum gpio_int_mode mode, - enum gpio_int_trig trig) -{ - if (mode != GPIO_INT_MODE_DISABLED) { - return -ENOTSUP; - } - - return 0; -} - const struct gpio_driver_api gpio_mmio32_api = { .pin_configure = gpio_mmio32_config, .port_get_raw = gpio_mmio32_port_get_raw, @@ -166,7 +154,6 @@ const struct gpio_driver_api gpio_mmio32_api = { .port_set_bits_raw = gpio_mmio32_port_set_bits_raw, .port_clear_bits_raw = gpio_mmio32_port_clear_bits_raw, .port_toggle_bits = gpio_mmio32_port_toggle_bits, - .pin_interrupt_configure = gpio_mmio32_pin_interrupt_configure, }; int gpio_mmio32_init(const struct device *dev) diff --git a/drivers/gpio/gpio_neorv32.c b/drivers/gpio/gpio_neorv32.c index b448962bde7..b14c51c1471 100644 --- a/drivers/gpio/gpio_neorv32.c +++ b/drivers/gpio/gpio_neorv32.c @@ -151,19 +151,6 @@ static int neorv32_gpio_port_toggle_bits(const struct device *dev, return 0; } -static int neorv32_gpio_pin_interrupt_configure(const struct device *dev, - gpio_pin_t pin, - enum gpio_int_mode mode, - enum gpio_int_trig trig) -{ - ARG_UNUSED(dev); - ARG_UNUSED(pin); - ARG_UNUSED(mode); - ARG_UNUSED(trig); - - return -ENOTSUP; -} - static int neorv32_gpio_manage_callback(const struct device *dev, struct gpio_callback *cb, bool set) @@ -215,7 +202,6 @@ static const struct gpio_driver_api neorv32_gpio_driver_api = { .port_set_bits_raw = neorv32_gpio_port_set_bits_raw, .port_clear_bits_raw = neorv32_gpio_port_clear_bits_raw, .port_toggle_bits = neorv32_gpio_port_toggle_bits, - .pin_interrupt_configure = neorv32_gpio_pin_interrupt_configure, .manage_callback = neorv32_gpio_manage_callback, .get_pending_int = neorv32_gpio_get_pending_int, }; diff --git a/drivers/gpio/gpio_npm1300.c b/drivers/gpio/gpio_npm1300.c index 37e7f99c936..65c3cdd6fda 100644 --- a/drivers/gpio/gpio_npm1300.c +++ b/drivers/gpio/gpio_npm1300.c @@ -185,17 +185,6 @@ static int gpio_npm1300_port_toggle_bits(const struct device *dev, gpio_port_pin return gpio_npm1300_port_set_masked_raw(dev, pins, ~value); } -static int gpio_npm1300_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, - enum gpio_int_mode mode, enum gpio_int_trig trig) -{ - ARG_UNUSED(dev); - ARG_UNUSED(pin); - ARG_UNUSED(mode); - ARG_UNUSED(trig); - - return -ENOTSUP; -} - static const struct gpio_driver_api gpio_npm1300_api = { .pin_configure = gpio_npm1300_configure, .port_get_raw = gpio_npm1300_port_get_raw, @@ -203,7 +192,6 @@ static const struct gpio_driver_api gpio_npm1300_api = { .port_set_bits_raw = gpio_npm1300_port_set_bits_raw, .port_clear_bits_raw = gpio_npm1300_port_clear_bits_raw, .port_toggle_bits = gpio_npm1300_port_toggle_bits, - .pin_interrupt_configure = gpio_npm1300_pin_interrupt_configure, }; static int gpio_npm1300_init(const struct device *dev) diff --git a/drivers/gpio/gpio_npm6001.c b/drivers/gpio/gpio_npm6001.c index 98bd4db49e0..f722c4275d6 100644 --- a/drivers/gpio/gpio_npm6001.c +++ b/drivers/gpio/gpio_npm6001.c @@ -192,19 +192,6 @@ static int gpio_npm6001_port_toggle_bits(const struct device *dev, ~val & NPM6001_PIN_MSK); } -static int gpio_npm6001_pin_interrupt_configure(const struct device *dev, - gpio_pin_t pin, - enum gpio_int_mode mode, - enum gpio_int_trig trig) -{ - ARG_UNUSED(dev); - ARG_UNUSED(pin); - ARG_UNUSED(mode); - ARG_UNUSED(trig); - - return -ENOTSUP; -} - static const struct gpio_driver_api gpio_npm6001_api = { .pin_configure = gpio_npm6001_configure, .port_get_raw = gpio_npm6001_port_get_raw, @@ -212,7 +199,6 @@ static const struct gpio_driver_api gpio_npm6001_api = { .port_set_bits_raw = gpio_npm6001_port_set_bits_raw, .port_clear_bits_raw = gpio_npm6001_port_clear_bits_raw, .port_toggle_bits = gpio_npm6001_port_toggle_bits, - .pin_interrupt_configure = gpio_npm6001_pin_interrupt_configure, }; static int gpio_npm6001_init(const struct device *dev) diff --git a/drivers/gpio/gpio_nxp_s32.c b/drivers/gpio/gpio_nxp_s32.c index 3bdf9f4599d..de5dbd39dd7 100644 --- a/drivers/gpio/gpio_nxp_s32.c +++ b/drivers/gpio/gpio_nxp_s32.c @@ -205,14 +205,12 @@ static void nxp_s32_gpio_isr(uint8_t pin, void *arg) gpio_fire_callbacks(&data->callbacks, dev, BIT(pin)); } -#endif /* CONFIG_NXP_S32_EIRQ */ static int nxp_s32_gpio_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, enum gpio_int_mode mode, enum gpio_int_trig trig) { -#ifdef CONFIG_NXP_S32_EIRQ const struct gpio_nxp_s32_config *config = dev->config; const struct eirq_nxp_s32_info *eirq_info = config->eirq_info; @@ -255,35 +253,18 @@ static int nxp_s32_gpio_pin_interrupt_configure(const struct device *dev, } return 0; -#else - ARG_UNUSED(dev); - ARG_UNUSED(pin); - ARG_UNUSED(mode); - ARG_UNUSED(trig); - - return -ENOTSUP; -#endif } static int nxp_s32_gpio_manage_callback(const struct device *dev, struct gpio_callback *cb, bool set) { -#ifdef CONFIG_NXP_S32_EIRQ struct gpio_nxp_s32_data *data = dev->data; return gpio_manage_callback(&data->callbacks, cb, set); -#else - ARG_UNUSED(dev); - ARG_UNUSED(cb); - ARG_UNUSED(set); - - return -ENOTSUP; -#endif } static uint32_t nxp_s32_gpio_get_pending_int(const struct device *dev) { -#ifdef CONFIG_NXP_S32_EIRQ const struct gpio_nxp_s32_config *config = dev->config; const struct eirq_nxp_s32_info *eirq_info = config->eirq_info; @@ -300,14 +281,8 @@ static uint32_t nxp_s32_gpio_get_pending_int(const struct device *dev) * that GPIO port belongs to */ return eirq_nxp_s32_get_pending(eirq_info->eirq_dev); - -#else - ARG_UNUSED(dev); - - return -ENOTSUP; -#endif } - +#endif /* CONFIG_NXP_S32_EIRQ */ #ifdef CONFIG_GPIO_GET_CONFIG static int nxp_s32_gpio_pin_get_config(const struct device *dev, @@ -400,9 +375,11 @@ static const struct gpio_driver_api gpio_nxp_s32_driver_api = { .port_set_bits_raw = nxp_s32_gpio_port_set_bits_raw, .port_clear_bits_raw = nxp_s32_gpio_port_clear_bits_raw, .port_toggle_bits = nxp_s32_gpio_port_toggle_bits, +#ifdef CONFIG_NXP_S32_EIRQ .pin_interrupt_configure = nxp_s32_gpio_pin_interrupt_configure, .manage_callback = nxp_s32_gpio_manage_callback, .get_pending_int = nxp_s32_gpio_get_pending_int, +#endif #ifdef CONFIG_GPIO_GET_CONFIG .pin_get_config = nxp_s32_gpio_pin_get_config, #endif diff --git a/drivers/gpio/gpio_pca95xx.c b/drivers/gpio/gpio_pca95xx.c index 66b21fd5b88..f8489128332 100644 --- a/drivers/gpio/gpio_pca95xx.c +++ b/drivers/gpio/gpio_pca95xx.c @@ -644,7 +644,6 @@ static void gpio_pca95xx_interrupt_callback(const struct device *dev, /* Cannot read PCA95xx registers from ISR context, queue worker */ k_work_submit(&drv_data->interrupt_worker); } -#endif /* CONFIG_GPIO_PCA95XX_INTERRUPT */ static int gpio_pca95xx_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, @@ -652,13 +651,6 @@ static int gpio_pca95xx_pin_interrupt_configure(const struct device *dev, enum gpio_int_trig trig) { int ret = 0; - - if (!IS_ENABLED(CONFIG_GPIO_PCA95XX_INTERRUPT) - && (mode != GPIO_INT_MODE_DISABLED)) { - return -ENOTSUP; - } - -#ifdef CONFIG_GPIO_PCA95XX_INTERRUPT const struct gpio_pca95xx_config * const config = dev->config; struct gpio_pca95xx_drv_data * const drv_data = (struct gpio_pca95xx_drv_data * const)dev->data; @@ -742,11 +734,9 @@ static int gpio_pca95xx_pin_interrupt_configure(const struct device *dev, err: k_sem_give(&drv_data->lock); -#endif /* CONFIG_GPIO_PCA95XX_INTERRUPT */ return ret; } -#ifdef CONFIG_GPIO_PCA95XX_INTERRUPT static int gpio_pca95xx_manage_callback(const struct device *dev, struct gpio_callback *callback, bool set) @@ -766,7 +756,7 @@ static int gpio_pca95xx_manage_callback(const struct device *dev, k_sem_give(&drv_data->lock); return 0; } -#endif +#endif /* CONFIG_GPIO_PCA95XX_INTERRUPT */ static const struct gpio_driver_api gpio_pca95xx_drv_api_funcs = { .pin_configure = gpio_pca95xx_config, @@ -775,8 +765,8 @@ static const struct gpio_driver_api gpio_pca95xx_drv_api_funcs = { .port_set_bits_raw = gpio_pca95xx_port_set_bits_raw, .port_clear_bits_raw = gpio_pca95xx_port_clear_bits_raw, .port_toggle_bits = gpio_pca95xx_port_toggle_bits, - .pin_interrupt_configure = gpio_pca95xx_pin_interrupt_configure, #ifdef CONFIG_GPIO_PCA95XX_INTERRUPT + .pin_interrupt_configure = gpio_pca95xx_pin_interrupt_configure, .manage_callback = gpio_pca95xx_manage_callback, #endif }; diff --git a/drivers/gpio/gpio_sc18im704.c b/drivers/gpio/gpio_sc18im704.c index 96fd56cadb6..c45e9d51a60 100644 --- a/drivers/gpio/gpio_sc18im704.c +++ b/drivers/gpio/gpio_sc18im704.c @@ -239,17 +239,6 @@ static int gpio_sc18im_port_toggle_bits(const struct device *port, gpio_port_pin return gpio_sc18im_port_set_raw(port, 0, 0, (uint8_t)pins); } -static int gpio_sc18im_pin_interrupt_configure(const struct device *port, gpio_pin_t pin, - enum gpio_int_mode mode, enum gpio_int_trig trig) -{ - ARG_UNUSED(port); - ARG_UNUSED(pin); - ARG_UNUSED(mode); - ARG_UNUSED(trig); - - return -ENOTSUP; -} - static int gpio_sc18im_init(const struct device *dev) { const struct gpio_sc18im_config *cfg = dev->config; @@ -272,7 +261,6 @@ static const struct gpio_driver_api gpio_sc18im_driver_api = { .port_set_bits_raw = gpio_sc18im_port_set_bits_raw, .port_clear_bits_raw = gpio_sc18im_port_clear_bits_raw, .port_toggle_bits = gpio_sc18im_port_toggle_bits, - .pin_interrupt_configure = gpio_sc18im_pin_interrupt_configure, }; #define CHECK_COMPAT(node) \ diff --git a/drivers/gpio/gpio_sn74hc595.c b/drivers/gpio/gpio_sn74hc595.c index 38f5de94d38..16eb35bb690 100644 --- a/drivers/gpio/gpio_sn74hc595.c +++ b/drivers/gpio/gpio_sn74hc595.c @@ -134,16 +134,6 @@ static int gpio_sn74hc595_port_toggle_bits(const struct device *dev, uint32_t ma return ret; } -static int gpio_sn74hc595_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, - enum gpio_int_mode mode, enum gpio_int_trig trig) -{ - ARG_UNUSED(dev); - ARG_UNUSED(pin); - ARG_UNUSED(mode); - ARG_UNUSED(trig); - return -ENOTSUP; -} - static const struct gpio_driver_api gpio_sn74hc595_drv_api_funcs = { .pin_configure = gpio_sn74hc595_config, .port_get_raw = gpio_sn74hc595_port_get_raw, @@ -151,7 +141,6 @@ static const struct gpio_driver_api gpio_sn74hc595_drv_api_funcs = { .port_set_bits_raw = gpio_sn74hc595_port_set_bits_raw, .port_clear_bits_raw = gpio_sn74hc595_port_clear_bits_raw, .port_toggle_bits = gpio_sn74hc595_port_toggle_bits, - .pin_interrupt_configure = gpio_sn74hc595_pin_interrupt_configure, }; /** diff --git a/drivers/gpio/gpio_stmpe1600.c b/drivers/gpio/gpio_stmpe1600.c index 518b41c7c57..2331fdf9fed 100644 --- a/drivers/gpio/gpio_stmpe1600.c +++ b/drivers/gpio/gpio_stmpe1600.c @@ -249,14 +249,6 @@ static int stmpe1600_port_toggle_bits(const struct device *dev, uint32_t mask) return ret; } -static int stmpe1600_pin_interrupt_configure(const struct device *dev, - gpio_pin_t pin, - enum gpio_int_mode mode, - enum gpio_int_trig trig) -{ - return -ENOTSUP; -} - static int stmpe1600_init(const struct device *dev) { const struct stmpe1600_config *const config = dev->config; @@ -300,7 +292,6 @@ static const struct gpio_driver_api stmpe1600_drv_api = { .port_set_bits_raw = stmpe1600_port_set_bits_raw, .port_clear_bits_raw = stmpe1600_port_clear_bits_raw, .port_toggle_bits = stmpe1600_port_toggle_bits, - .pin_interrupt_configure = stmpe1600_pin_interrupt_configure, }; #define STMPE1600_INIT(inst) \ diff --git a/drivers/gpio/gpio_sx1509b.c b/drivers/gpio/gpio_sx1509b.c index c62f803e307..b8ecdf4d772 100644 --- a/drivers/gpio/gpio_sx1509b.c +++ b/drivers/gpio/gpio_sx1509b.c @@ -468,6 +468,7 @@ static int port_toggle_bits(const struct device *dev, return port_write(dev, 0, 0, pins); } +#ifdef CONFIG_GPIO_SX1509B_INTERRUPT static int pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, enum gpio_int_mode mode, @@ -475,12 +476,6 @@ static int pin_interrupt_configure(const struct device *dev, { int rc = 0; - if (!IS_ENABLED(CONFIG_GPIO_SX1509B_INTERRUPT) - && (mode != GPIO_INT_MODE_DISABLED)) { - return -ENOTSUP; - } - -#ifdef CONFIG_GPIO_SX1509B_INTERRUPT /* Device does not support level-triggered interrupts. */ if (mode == GPIO_INT_MODE_LEVEL) { return -ENOTSUP; @@ -531,10 +526,10 @@ static int pin_interrupt_configure(const struct device *dev, rc = i2c_write_dt(&cfg->bus, &irq_buf.reg, sizeof(irq_buf)); k_sem_give(&drv_data->lock); -#endif /* CONFIG_GPIO_SX1509B_INTERRUPT */ return rc; } +#endif /* CONFIG_GPIO_SX1509B_INTERRUPT */ /** * @brief Initialization function of SX1509B @@ -647,8 +642,8 @@ static const struct gpio_driver_api api_table = { .port_set_bits_raw = port_set_bits, .port_clear_bits_raw = port_clear_bits, .port_toggle_bits = port_toggle_bits, - .pin_interrupt_configure = pin_interrupt_configure, #ifdef CONFIG_GPIO_SX1509B_INTERRUPT + .pin_interrupt_configure = pin_interrupt_configure, .manage_callback = gpio_sx1509b_manage_callback, #endif }; diff --git a/drivers/gpio/gpio_test.c b/drivers/gpio/gpio_test.c index 192028acac0..3befab37fc2 100644 --- a/drivers/gpio/gpio_test.c +++ b/drivers/gpio/gpio_test.c @@ -63,26 +63,6 @@ static int vnd_gpio_port_toggle_bits(const struct device *port, return -ENOTSUP; } -static int vnd_gpio_pin_interrupt_configure(const struct device *port, - gpio_pin_t pin, - enum gpio_int_mode mode, - enum gpio_int_trig trig) -{ - return -ENOTSUP; -} - -static int vnd_gpio_manage_callback(const struct device *port, - struct gpio_callback *cb, - bool set) -{ - return -ENOTSUP; -} - -static uint32_t vnd_gpio_get_pending_int(const struct device *dev) -{ - return 0; -} - static const struct gpio_driver_api vnd_gpio_api = { .pin_configure = vnd_gpio_pin_configure, .port_get_raw = vnd_gpio_port_get_raw, @@ -90,9 +70,6 @@ static const struct gpio_driver_api vnd_gpio_api = { .port_set_bits_raw = vnd_gpio_port_set_bits_raw, .port_clear_bits_raw = vnd_gpio_port_clear_bits_raw, .port_toggle_bits = vnd_gpio_port_toggle_bits, - .pin_interrupt_configure = vnd_gpio_pin_interrupt_configure, - .manage_callback = vnd_gpio_manage_callback, - .get_pending_int = vnd_gpio_get_pending_int }; #define VND_GPIO_INIT(n) \ diff --git a/drivers/gpio/gpio_xlnx_axi.c b/drivers/gpio/gpio_xlnx_axi.c index 99e9e350aa2..f070e691e5d 100644 --- a/drivers/gpio/gpio_xlnx_axi.c +++ b/drivers/gpio/gpio_xlnx_axi.c @@ -198,6 +198,7 @@ static int gpio_xlnx_axi_port_toggle_bits(const struct device *dev, gpio_port_pi return 0; } +#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(interrupts) /** * Enables interrupts for the given pins on the channel * The axi gpio can only enable interrupts for an entire port, so we need to track @@ -206,7 +207,6 @@ static int gpio_xlnx_axi_port_toggle_bits(const struct device *dev, gpio_port_pi static int gpio_xlnx_axi_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, enum gpio_int_mode mode, enum gpio_int_trig trig) { -#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(interrupts) const struct gpio_xlnx_axi_config *config = dev->config; struct gpio_xlnx_axi_data *data = dev->data; const uint32_t pin_mask = BIT(pin); @@ -390,9 +390,11 @@ static const struct gpio_driver_api gpio_xlnx_axi_driver_api = { .port_set_bits_raw = gpio_xlnx_axi_port_set_bits_raw, .port_clear_bits_raw = gpio_xlnx_axi_port_clear_bits_raw, .port_toggle_bits = gpio_xlnx_axi_port_toggle_bits, +#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(interrupts) .pin_interrupt_configure = gpio_xlnx_axi_pin_interrupt_configure, .manage_callback = gpio_xlnx_axi_manage_callback, .get_pending_int = gpio_xlnx_axi_get_pending_int, +#endif }; #define GPIO_XLNX_AXI_GPIO2_HAS_COMPAT_STATUS_OKAY(n) \ diff --git a/drivers/gpio/gpio_xmc4xxx.c b/drivers/gpio/gpio_xmc4xxx.c index 29462308481..d90f68d3b32 100644 --- a/drivers/gpio/gpio_xmc4xxx.c +++ b/drivers/gpio/gpio_xmc4xxx.c @@ -117,10 +117,10 @@ static void gpio_xmc4xxx_isr(const struct device *dev, int pin) } #endif +#ifdef CONFIG_XMC4XXX_INTC static int gpio_xmc4xxx_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, enum gpio_int_mode mode, enum gpio_int_trig trig) { -#if defined(CONFIG_XMC4XXX_INTC) const struct gpio_xmc4xxx_config *config = dev->config; int port_id = PORT_TO_PORT_ID(config->port); @@ -132,15 +132,8 @@ static int gpio_xmc4xxx_pin_interrupt_configure(const struct device *dev, gpio_p } else { return -EINVAL; } -#else - ARG_UNUSED(dev); - ARG_UNUSED(pin); - ARG_UNUSED(mode); - ARG_UNUSED(trig); - - return -ENOTSUP; -#endif } +#endif static int gpio_xmc4xxx_get_raw(const struct device *dev, gpio_port_value_t *value) { @@ -215,8 +208,10 @@ static const struct gpio_driver_api gpio_xmc4xxx_driver_api = { .port_set_bits_raw = gpio_xmc4xxx_set_bits_raw, .port_clear_bits_raw = gpio_xmc4xxx_clear_bits_raw, .port_toggle_bits = gpio_xmc4xxx_toggle_bits, +#ifdef CONFIG_XMC4XXX_INTC .pin_interrupt_configure = gpio_xmc4xxx_pin_interrupt_configure, - .manage_callback = IS_ENABLED(CONFIG_XMC4XXX_INTC) ? gpio_xmc4xxx_manage_callback : NULL, + .manage_callback = gpio_xmc4xxx_manage_callback, +#endif }; #define GPIO_XMC4XXX_INIT(index) \ From 1cba00a409f64a96f3a0c75bd3cb15c146829077 Mon Sep 17 00:00:00 2001 From: Marek Pieta Date: Tue, 5 Sep 2023 12:28:45 +0200 Subject: [PATCH 0072/1623] [nrf fromtree] drivers: gpio_nrfx: Allow to disable interrupt support Change introduces a new configuration option that can be used to disable GPIO interrupt support to reduce memory footprint. Signed-off-by: Marek Pieta (cherry picked from commit 44c723e65d659a222b8744eba97a62335962d197) Signed-off-by: Dominik Ermel (cherry picked from commit 0a55c2ea2679237081b6b777fe8fcb71db5894ba) --- drivers/gpio/Kconfig.nrfx | 11 +++++++++- drivers/gpio/gpio_nrfx.c | 42 +++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/gpio/Kconfig.nrfx b/drivers/gpio/Kconfig.nrfx index 6757b6b12e9..356c43cb5fa 100644 --- a/drivers/gpio/Kconfig.nrfx +++ b/drivers/gpio/Kconfig.nrfx @@ -1,10 +1,19 @@ # Copyright (c) 2018 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -config GPIO_NRFX +menuconfig GPIO_NRFX bool "nRF GPIO driver" default y depends on DT_HAS_NORDIC_NRF_GPIO_ENABLED select NRFX_GPIOTE help Enable GPIO driver for nRF line of MCUs. + +config GPIO_NRFX_INTERRUPT + bool "Interrupt support" + depends on GPIO_NRFX + default y + help + The option can be used to disable the GPIO interrupt support to + significantly reduce memory footprint in case of application that does + not need GPIO interrupts. diff --git a/drivers/gpio/gpio_nrfx.c b/drivers/gpio/gpio_nrfx.c index 1683b8b2cea..0aa282dda37 100644 --- a/drivers/gpio/gpio_nrfx.c +++ b/drivers/gpio/gpio_nrfx.c @@ -85,17 +85,19 @@ static nrf_gpio_pin_pull_t get_pull(gpio_flags_t flags) static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin, gpio_flags_t flags) { - nrfx_err_t err; + nrfx_err_t err = NRFX_SUCCESS; uint8_t ch; - bool free_ch; + bool free_ch = false; const struct gpio_nrfx_cfg *cfg = get_port_cfg(port); nrfx_gpiote_pin_t abs_pin = NRF_GPIO_PIN_MAP(cfg->port_num, pin); /* Get the GPIOTE channel associated with this pin, if any. It needs * to be freed when the pin is reconfigured or disconnected. */ - err = nrfx_gpiote_channel_get(abs_pin, &ch); - free_ch = (err == NRFX_SUCCESS); + if (IS_ENABLED(CONFIG_GPIO_NRFX_INTERRUPT)) { + err = nrfx_gpiote_channel_get(abs_pin, &ch); + free_ch = (err == NRFX_SUCCESS); + } if ((flags & (GPIO_INPUT | GPIO_OUTPUT)) == GPIO_DISCONNECTED) { /* Ignore the error code. The pin may not have been used. */ @@ -109,19 +111,21 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin, return 0; } - nrfx_gpiote_trigger_config_t trigger_config = { - .trigger = NRFX_GPIOTE_TRIGGER_NONE - }; + if (IS_ENABLED(CONFIG_GPIO_NRFX_INTERRUPT)) { + nrfx_gpiote_trigger_config_t trigger_config = { + .trigger = NRFX_GPIOTE_TRIGGER_NONE + }; - /* Remove previously configured trigger when pin is reconfigured. */ - err = nrfx_gpiote_input_configure(abs_pin, NULL, &trigger_config, NULL); - if (err != NRFX_SUCCESS) { - return -EINVAL; - } + /* Remove previously configured trigger when pin is reconfigured. */ + err = nrfx_gpiote_input_configure(abs_pin, NULL, &trigger_config, NULL); + if (err != NRFX_SUCCESS) { + return -EINVAL; + } - if (free_ch) { - err = nrfx_gpiote_channel_free(ch); - __ASSERT_NO_MSG(err == NRFX_SUCCESS); + if (free_ch) { + err = nrfx_gpiote_channel_free(ch); + __ASSERT_NO_MSG(err == NRFX_SUCCESS); + } } if (flags & GPIO_OUTPUT) { @@ -219,6 +223,7 @@ static int gpio_nrfx_port_toggle_bits(const struct device *port, return 0; } +#ifdef CONFIG_GPIO_NRFX_INTERRUPT static nrfx_gpiote_trigger_t get_trigger(enum gpio_int_mode mode, enum gpio_int_trig trig) { @@ -285,6 +290,7 @@ static int gpio_nrfx_manage_callback(const struct device *port, return gpio_manage_callback(&get_port_data(port)->callbacks, callback, set); } +#endif /* CONFIG_GPIO_NRFX_INTERRUPT */ #ifdef CONFIG_GPIO_GET_DIRECTION static int gpio_nrfx_port_get_direction(const struct device *port, @@ -322,6 +328,7 @@ static int gpio_nrfx_port_get_direction(const struct device *port, } #endif /* CONFIG_GPIO_GET_DIRECTION */ +#ifdef CONFIG_GPIO_NRFX_INTERRUPT /* Get port device from port id. */ static const struct device *get_dev(uint32_t port_id) { @@ -358,6 +365,7 @@ static void nrfx_gpio_handler(nrfx_gpiote_pin_t abs_pin, gpio_fire_callbacks(list, port, BIT(pin)); } +#endif /* CONFIG_GPIO_NRFX_INTERRUPT */ #define GPIOTE_NODE DT_INST(0, nordic_nrf_gpiote) @@ -374,10 +382,12 @@ static int gpio_nrfx_init(const struct device *port) return -EIO; } +#ifdef CONFIG_GPIO_NRFX_INTERRUPT nrfx_gpiote_global_callback_set(nrfx_gpio_handler, NULL); IRQ_CONNECT(DT_IRQN(GPIOTE_NODE), DT_IRQ(GPIOTE_NODE, priority), nrfx_isr, nrfx_gpiote_irq_handler, 0); +#endif /* CONFIG_GPIO_NRFX_INTERRUPT */ return 0; } @@ -389,8 +399,10 @@ static const struct gpio_driver_api gpio_nrfx_drv_api_funcs = { .port_set_bits_raw = gpio_nrfx_port_set_bits_raw, .port_clear_bits_raw = gpio_nrfx_port_clear_bits_raw, .port_toggle_bits = gpio_nrfx_port_toggle_bits, +#ifdef CONFIG_GPIO_NRFX_INTERRUPT .pin_interrupt_configure = gpio_nrfx_pin_interrupt_configure, .manage_callback = gpio_nrfx_manage_callback, +#endif #ifdef CONFIG_GPIO_GET_DIRECTION .port_get_direction = gpio_nrfx_port_get_direction, #endif From 9aa9bb98607f6f7232adedb5e7e15f7663f58498 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Wed, 13 Sep 2023 15:13:48 +0000 Subject: [PATCH 0073/1623] [nrf fromtree] net: Fix usage of strncpy in net_if_get_name and net_if_set_name Replaced with memcpy. (cherry picked from commit 47396e18e12ae859b9858cb439e531a5611255b8) Signed-off-by: Dominik Ermel (cherry picked from commit ee35c807af0d2253acdecaccec3d5ecebc2db195) --- subsys/net/ip/net_if.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index e6e3512e4b2..828e48ecf78 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -4747,7 +4747,8 @@ int net_if_get_name(struct net_if *iface, char *buf, int len) return -ERANGE; } - strncpy(buf, net_if_get_config(iface)->name, name_len); + /* Copy string and null terminator */ + memcpy(buf, net_if_get_config(iface)->name, name_len + 1); return name_len; #else @@ -4769,7 +4770,8 @@ int net_if_set_name(struct net_if *iface, const char *buf) return -ENAMETOOLONG; } - strncpy(net_if_get_config(iface)->name, buf, name_len); + /* Copy string and null terminator */ + memcpy(net_if_get_config(iface)->name, buf, name_len + 1); return 0; #else From b0cfad5a121d46969e682eb77ea91b1a2720960d Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Tue, 29 Aug 2023 07:44:54 +0100 Subject: [PATCH 0074/1623] [nrf fromtree] mgmt: mcumgr: Split mgmt defines to new file This splits defines to a separate file, which are commonly needed by out-of-tree projects whereby the full MCUmgr include cannot be used due to undefined types being used. Signed-off-by: Jamie McCrae (cherry picked from commit a15752c79cba648541b87fd54d58379daa61c6db) Signed-off-by: Dominik Ermel (cherry picked from commit a6007b6804cf6db979d46954072f1f21691785a6) --- include/zephyr/mgmt/mcumgr/mgmt/mgmt.h | 119 +------------- .../zephyr/mgmt/mcumgr/mgmt/mgmt_defines.h | 150 ++++++++++++++++++ 2 files changed, 151 insertions(+), 118 deletions(-) create mode 100644 include/zephyr/mgmt/mcumgr/mgmt/mgmt_defines.h diff --git a/include/zephyr/mgmt/mcumgr/mgmt/mgmt.h b/include/zephyr/mgmt/mcumgr/mgmt/mgmt.h index eb9ecfcf2a9..e681ea2b939 100644 --- a/include/zephyr/mgmt/mcumgr/mgmt/mgmt.h +++ b/include/zephyr/mgmt/mcumgr/mgmt/mgmt.h @@ -11,6 +11,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -23,124 +24,6 @@ extern "C" { * @{ */ -/** - * Used at end of MCUmgr handlers to return an error if the message size limit was reached, - * or OK if it was not - */ -#define MGMT_RETURN_CHECK(ok) ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE - -/** Opcodes; encoded in first byte of header. */ -enum mcumgr_op_t { - /** Read op-code */ - MGMT_OP_READ = 0, - - /** Read response op-code */ - MGMT_OP_READ_RSP, - - /** Write op-code */ - MGMT_OP_WRITE, - - /** Write response op-code */ - MGMT_OP_WRITE_RSP, -}; - -/** - * MCUmgr groups. The first 64 groups are reserved for system level mcumgr - * commands. Per-user commands are then defined after group 64. - */ -enum mcumgr_group_t { - /** OS (operating system) group */ - MGMT_GROUP_ID_OS = 0, - - /** Image management group, used for uploading firmware images */ - MGMT_GROUP_ID_IMAGE, - - /** Statistic management group, used for retieving statistics */ - MGMT_GROUP_ID_STAT, - - /** Settings management (config) group, used for reading/writing settings */ - MGMT_GROUP_ID_SETTINGS, - - /** Log management group (unused) */ - MGMT_GROUP_ID_LOG, - - /** Crash group (unused) */ - MGMT_GROUP_ID_CRASH, - - /** Split image management group (unused) */ - MGMT_GROUP_ID_SPLIT, - - /** Run group (unused) */ - MGMT_GROUP_ID_RUN, - - /** FS (file system) group, used for performing file IO operations */ - MGMT_GROUP_ID_FS, - - /** Shell management group, used for executing shell commands */ - MGMT_GROUP_ID_SHELL, - - /** User groups defined from 64 onwards */ - MGMT_GROUP_ID_PERUSER = 64, - - /** Zephyr-specific groups decrease from PERUSER to avoid collision with upstream and - * user-defined groups. - * Zephyr-specific: Basic group - */ - ZEPHYR_MGMT_GRP_BASIC = (MGMT_GROUP_ID_PERUSER - 1), -}; - -/** - * MCUmgr error codes. - */ -enum mcumgr_err_t { - /** No error (success). */ - MGMT_ERR_EOK = 0, - - /** Unknown error. */ - MGMT_ERR_EUNKNOWN, - - /** Insufficient memory (likely not enough space for CBOR object). */ - MGMT_ERR_ENOMEM, - - /** Error in input value. */ - MGMT_ERR_EINVAL, - - /** Operation timed out. */ - MGMT_ERR_ETIMEOUT, - - /** No such file/entry. */ - MGMT_ERR_ENOENT, - - /** Current state disallows command. */ - MGMT_ERR_EBADSTATE, - - /** Response too large. */ - MGMT_ERR_EMSGSIZE, - - /** Command not supported. */ - MGMT_ERR_ENOTSUP, - - /** Corrupt */ - MGMT_ERR_ECORRUPT, - - /** Command blocked by processing of other command */ - MGMT_ERR_EBUSY, - - /** Access to specific function, command or resource denied */ - MGMT_ERR_EACCESSDENIED, - - /** Requested SMP MCUmgr protocol version is not supported (too old) */ - MGMT_ERR_UNSUPPORTED_TOO_OLD, - - /** Requested SMP MCUmgr protocol version is not supported (too new) */ - MGMT_ERR_UNSUPPORTED_TOO_NEW, - - /** User errors defined from 256 onwards */ - MGMT_ERR_EPERUSER = 256 -}; - -#define MGMT_HDR_SIZE 8 - /** @typedef mgmt_alloc_rsp_fn * @brief Allocates a buffer suitable for holding a response. * diff --git a/include/zephyr/mgmt/mcumgr/mgmt/mgmt_defines.h b/include/zephyr/mgmt/mcumgr/mgmt/mgmt_defines.h new file mode 100644 index 00000000000..2f33b6d22a1 --- /dev/null +++ b/include/zephyr/mgmt/mcumgr/mgmt/mgmt_defines.h @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2018-2021 mcumgr authors + * Copyright (c) 2022-2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef H_MGMT_MGMT_DEFINES_ +#define H_MGMT_MGMT_DEFINES_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief MCUmgr mgmt API + * @defgroup mcumgr_mgmt_api MCUmgr mgmt API + * @ingroup mcumgr + * @{ + */ + +/** + * Used at end of MCUmgr handlers to return an error if the message size limit was reached, + * or OK if it was not + */ +#define MGMT_RETURN_CHECK(ok) ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE + +/** Opcodes; encoded in first byte of header. */ +enum mcumgr_op_t { + /** Read op-code */ + MGMT_OP_READ = 0, + + /** Read response op-code */ + MGMT_OP_READ_RSP, + + /** Write op-code */ + MGMT_OP_WRITE, + + /** Write response op-code */ + MGMT_OP_WRITE_RSP, +}; + +/** + * MCUmgr groups. The first 64 groups are reserved for system level mcumgr + * commands. Per-user commands are then defined after group 64. + */ +enum mcumgr_group_t { + /** OS (operating system) group */ + MGMT_GROUP_ID_OS = 0, + + /** Image management group, used for uploading firmware images */ + MGMT_GROUP_ID_IMAGE, + + /** Statistic management group, used for retieving statistics */ + MGMT_GROUP_ID_STAT, + + /** Settings management (config) group, used for reading/writing settings */ + MGMT_GROUP_ID_SETTINGS, + + /** Log management group (unused) */ + MGMT_GROUP_ID_LOG, + + /** Crash group (unused) */ + MGMT_GROUP_ID_CRASH, + + /** Split image management group (unused) */ + MGMT_GROUP_ID_SPLIT, + + /** Run group (unused) */ + MGMT_GROUP_ID_RUN, + + /** FS (file system) group, used for performing file IO operations */ + MGMT_GROUP_ID_FS, + + /** Shell management group, used for executing shell commands */ + MGMT_GROUP_ID_SHELL, + + /** User groups defined from 64 onwards */ + MGMT_GROUP_ID_PERUSER = 64, + + /** Zephyr-specific groups decrease from PERUSER to avoid collision with upstream and + * user-defined groups. + * Zephyr-specific: Basic group + */ + ZEPHYR_MGMT_GRP_BASIC = (MGMT_GROUP_ID_PERUSER - 1), +}; + +/** + * MCUmgr error codes. + */ +enum mcumgr_err_t { + /** No error (success). */ + MGMT_ERR_EOK = 0, + + /** Unknown error. */ + MGMT_ERR_EUNKNOWN, + + /** Insufficient memory (likely not enough space for CBOR object). */ + MGMT_ERR_ENOMEM, + + /** Error in input value. */ + MGMT_ERR_EINVAL, + + /** Operation timed out. */ + MGMT_ERR_ETIMEOUT, + + /** No such file/entry. */ + MGMT_ERR_ENOENT, + + /** Current state disallows command. */ + MGMT_ERR_EBADSTATE, + + /** Response too large. */ + MGMT_ERR_EMSGSIZE, + + /** Command not supported. */ + MGMT_ERR_ENOTSUP, + + /** Corrupt */ + MGMT_ERR_ECORRUPT, + + /** Command blocked by processing of other command */ + MGMT_ERR_EBUSY, + + /** Access to specific function, command or resource denied */ + MGMT_ERR_EACCESSDENIED, + + /** Requested SMP MCUmgr protocol version is not supported (too old) */ + MGMT_ERR_UNSUPPORTED_TOO_OLD, + + /** Requested SMP MCUmgr protocol version is not supported (too new) */ + MGMT_ERR_UNSUPPORTED_TOO_NEW, + + /** User errors defined from 256 onwards */ + MGMT_ERR_EPERUSER = 256 +}; + +#define MGMT_HDR_SIZE 8 + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* MGMT_MGMT_DEFINES_H_ */ From c606de126612153b2c036b730d66ec622c88aec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 20 Sep 2023 10:16:50 +0200 Subject: [PATCH 0075/1623] [nrf fromtree] drivers: serial: uart_nrfx_uarte: coexisting async and interrupt API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes an issue with the nrfx uarte driver to allow the async and interrupt driven UART APIs to coexist on different uart instances. As both APIs cannot be used simultaneously for a given instance, there is no need to handle CONFIG_UART_EXCLUSIVE_API_CALLBACKS in this driver. Signed-off-by: Eivind Jølsgard (cherry picked from commit 66069b3b397dbd68fe47ab54579501b9fc365425) Signed-off-by: Dominik Ermel (cherry picked from commit 1c5e17f1ea603f2bea44c9d0d49817d293f6f45b) --- drivers/serial/uart_nrfx_uarte.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index bdafe6c7d4c..017efa6a2e5 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -937,11 +937,6 @@ static int uarte_nrfx_callback_set(const struct device *dev, data->async->user_callback = callback; data->async->user_data = user_data; -#if defined(CONFIG_UART_EXCLUSIVE_API_CALLBACKS) && defined(UARTE_INTERRUPT_DRIVEN) - data->int_driven->cb = NULL; - data->int_driven->cb_data = NULL; -#endif - return 0; } @@ -1680,11 +1675,6 @@ static void uarte_nrfx_irq_callback_set(const struct device *dev, data->int_driven->cb = cb; data->int_driven->cb_data = cb_data; - -#if defined(UARTE_ANY_ASYNC) && defined(CONFIG_UART_EXCLUSIVE_API_CALLBACKS) - data->async->user_callback = NULL; - data->async->user_data = NULL; -#endif } #endif /* UARTE_INTERRUPT_DRIVEN */ From 83e1ffa903da471f7d065edfeb59c990b695ae25 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 12 Sep 2023 23:28:34 +0200 Subject: [PATCH 0076/1623] [nrf fromtree] tests: Bluetooth: Audio: Modify bsim tests to use bt_le_scan_cb_register Update the tests to use bt_le_scan_cb_register and the "new" scan callback, as that is better suited to handle extended advertising. Signed-off-by: Emil Gydesen (cherry picked from commit 9064170cf85c8ac71961ff01c018cadc03d742d7) Signed-off-by: Dominik Ermel (cherry picked from commit ea578d4eb182174fcd5c5ca6b29265249beaa83e) --- .../audio/src/bap_broadcast_assistant_test.c | 3 ++- .../audio/src/bap_unicast_client_test.c | 17 ++++++++++++++++- tests/bsim/bluetooth/audio/src/common.c | 19 +++++++++++-------- tests/bsim/bluetooth/audio/src/common.h | 3 +-- .../bluetooth/audio/src/has_client_test.c | 4 +++- .../bluetooth/audio/src/ias_client_test.c | 4 +++- tests/bsim/bluetooth/audio/src/mcc_test.c | 4 +++- .../audio/src/media_controller_test.c | 4 +++- .../bluetooth/audio/src/micp_mic_ctlr_test.c | 4 +++- .../audio/src/pacs_notify_client_test.c | 6 ++++-- tests/bsim/bluetooth/audio/src/tbs_test.c | 3 ++- .../bluetooth/audio/src/vcp_vol_ctlr_test.c | 3 ++- 12 files changed, 53 insertions(+), 21 deletions(-) diff --git a/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c b/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c index 381810d68db..9964bd29c0a 100644 --- a/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c @@ -490,9 +490,10 @@ static int common_init(void) bt_gatt_cb_register(&gatt_callbacks); bt_bap_broadcast_assistant_register_cb(&broadcast_assistant_cbs); bt_le_per_adv_sync_cb_register(&sync_callbacks); + bt_le_scan_cb_register(&common_scan_cb); printk("Starting scan\n"); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return err; diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c index e31c092684a..72aa1cfcd96 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c @@ -320,6 +320,7 @@ static void init(void) g_streams[i].ops = &stream_ops; } + bt_le_scan_cb_register(&common_scan_cb); bt_gatt_cb_register(&gatt_callbacks); err = bt_bap_unicast_client_register_cb(&unicast_client_cbs); @@ -333,7 +334,7 @@ static void scan_and_connect(void) { int err; - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return; @@ -343,6 +344,19 @@ static void scan_and_connect(void) WAIT_FOR_FLAG(flag_connected); } +static void disconnect_acl(void) +{ + int err; + + err = bt_conn_disconnect(default_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); + if (err != 0) { + FAIL("Failed to disconnect (err %d)\n", err); + return; + } + + WAIT_FOR_UNSET_FLAG(flag_connected); +} + static void exchange_mtu(void) { WAIT_FOR_FLAG(flag_mtu_exchanged); @@ -748,6 +762,7 @@ static void test_main(void) unicast_group = NULL; } + disconnect_acl(); PASS("Unicast client passed\n"); } diff --git a/tests/bsim/bluetooth/audio/src/common.c b/tests/bsim/bluetooth/audio/src/common.c index 30758e01732..90a8cb98efa 100644 --- a/tests/bsim/bluetooth/audio/src/common.c +++ b/tests/bsim/bluetooth/audio/src/common.c @@ -16,8 +16,7 @@ const struct bt_data ad[AD_SIZE] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)) }; -void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) +static void device_found(const struct bt_le_scan_recv_info *info, struct net_buf_simple *ad) { char addr_str[BT_ADDR_LE_STR_LEN]; int err; @@ -27,15 +26,15 @@ void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, } /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { + if ((info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) == 0) { return; } - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, rssi); + bt_addr_le_to_str(info->addr, addr_str, sizeof(addr_str)); + printk("Device found: %s (RSSI %d)\n", addr_str, info->rssi); /* connect only to devices in close proximity */ - if (rssi < -70) { + if (info->rssi < -70) { FAIL("RSSI too low"); return; } @@ -46,13 +45,17 @@ void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, return; } - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, &default_conn); + err = bt_conn_le_create(info->addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, + &default_conn); if (err) { FAIL("Could not connect to peer: %d", err); } } +struct bt_le_scan_cb common_scan_cb = { + .recv = device_found, +}; + static void connected(struct bt_conn *conn, uint8_t err) { char addr[BT_ADDR_LE_STR_LEN]; diff --git a/tests/bsim/bluetooth/audio/src/common.h b/tests/bsim/bluetooth/audio/src/common.h index 917a024b724..14d6dbbc092 100644 --- a/tests/bsim/bluetooth/audio/src/common.h +++ b/tests/bsim/bluetooth/audio/src/common.h @@ -65,13 +65,12 @@ #define SYNC_RETRY_COUNT 6 /* similar to retries for connections */ #define PA_SYNC_SKIP 5 +extern struct bt_le_scan_cb common_scan_cb; extern const struct bt_data ad[AD_SIZE]; extern struct bt_conn *default_conn; extern atomic_t flag_connected; extern atomic_t flag_conn_updated; -void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad); void disconnected(struct bt_conn *conn, uint8_t reason); void test_tick(bs_time_t HW_device_time); void test_init(void); diff --git a/tests/bsim/bluetooth/audio/src/has_client_test.c b/tests/bsim/bluetooth/audio/src/has_client_test.c index 9d63463e0ce..6690c6b032e 100644 --- a/tests/bsim/bluetooth/audio/src/has_client_test.c +++ b/tests/bsim/bluetooth/audio/src/has_client_test.c @@ -157,7 +157,9 @@ static void test_main(void) return; } - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + bt_le_scan_cb_register(&common_scan_cb); + + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err < 0) { FAIL("Scanning failed to start (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/ias_client_test.c b/tests/bsim/bluetooth/audio/src/ias_client_test.c index 2c5dbd40bd0..7c24b1a172a 100644 --- a/tests/bsim/bluetooth/audio/src/ias_client_test.c +++ b/tests/bsim/bluetooth/audio/src/ias_client_test.c @@ -83,7 +83,9 @@ static void test_main(void) return; } - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + bt_le_scan_cb_register(&common_scan_cb); + + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err < 0) { FAIL("Scanning failed to start (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/mcc_test.c b/tests/bsim/bluetooth/audio/src/mcc_test.c index 8a32e33bf16..9e8cd95806b 100644 --- a/tests/bsim/bluetooth/audio/src/mcc_test.c +++ b/tests/bsim/bluetooth/audio/src/mcc_test.c @@ -2396,6 +2396,8 @@ void test_main(void) printk("Bluetooth initialized\n"); + bt_le_scan_cb_register(&common_scan_cb); + /* Initialize MCC ********************************************/ err = do_mcc_init(); if (err != 0) { @@ -2414,7 +2416,7 @@ void test_main(void) printk("\n########### Running iteration #%u\n\n", i); UNSET_FLAG(flag_connected); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err != 0) { FAIL("Failed to start scanning (err %d\n)", err); } else { diff --git a/tests/bsim/bluetooth/audio/src/media_controller_test.c b/tests/bsim/bluetooth/audio/src/media_controller_test.c index 9c1df656fd1..ad91cffb939 100644 --- a/tests/bsim/bluetooth/audio/src/media_controller_test.c +++ b/tests/bsim/bluetooth/audio/src/media_controller_test.c @@ -1585,6 +1585,8 @@ void initialize_bluetooth(void) WAIT_FOR_FLAG(ble_is_initialized); printk("Bluetooth initialized\n"); + + bt_le_scan_cb_register(&common_scan_cb); } void scan_and_connect(void) @@ -1592,7 +1594,7 @@ void scan_and_connect(void) char addr[BT_ADDR_LE_STR_LEN]; int err; - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err) { FAIL("Failed to start scanning (err %d\n)", err); return; diff --git a/tests/bsim/bluetooth/audio/src/micp_mic_ctlr_test.c b/tests/bsim/bluetooth/audio/src/micp_mic_ctlr_test.c index 1074c8c2cef..5cefd31d099 100644 --- a/tests/bsim/bluetooth/audio/src/micp_mic_ctlr_test.c +++ b/tests/bsim/bluetooth/audio/src/micp_mic_ctlr_test.c @@ -357,11 +357,13 @@ static void test_main(void) return; } + bt_le_scan_cb_register(&common_scan_cb); + bt_micp_mic_ctlr_cb_register(&micp_mic_ctlr_cbs); WAIT_FOR_COND(g_bt_init); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/pacs_notify_client_test.c b/tests/bsim/bluetooth/audio/src/pacs_notify_client_test.c index 7cbe5feaa22..9910f6f2c8c 100644 --- a/tests/bsim/bluetooth/audio/src/pacs_notify_client_test.c +++ b/tests/bsim/bluetooth/audio/src/pacs_notify_client_test.c @@ -490,8 +490,10 @@ static void test_main(void) return; } + bt_le_scan_cb_register(&common_scan_cb); + printk("Starting scan\n"); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err != 0) { FAIL("Could not start scanning (err %d)\n", err); return; @@ -536,7 +538,7 @@ static void test_main(void) WAIT_FOR_UNSET_FLAG(flag_connected); printk("Starting scan\n"); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err != 0) { FAIL("Could not start scanning (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/tbs_test.c b/tests/bsim/bluetooth/audio/src/tbs_test.c index b20dca26608..a1bf1e035c0 100644 --- a/tests/bsim/bluetooth/audio/src/tbs_test.c +++ b/tests/bsim/bluetooth/audio/src/tbs_test.c @@ -331,9 +331,10 @@ static void test_main(void) printk("Audio Client: Bluetooth initialized\n"); bt_conn_cb_register(&conn_callbacks); + bt_le_scan_cb_register(&common_scan_cb); bt_tbs_register_cb(&tbs_cbs); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/vcp_vol_ctlr_test.c b/tests/bsim/bluetooth/audio/src/vcp_vol_ctlr_test.c index 52ba2f072ab..77feaa4bfb5 100644 --- a/tests/bsim/bluetooth/audio/src/vcp_vol_ctlr_test.c +++ b/tests/bsim/bluetooth/audio/src/vcp_vol_ctlr_test.c @@ -1153,9 +1153,10 @@ static void test_main(void) return; } + bt_le_scan_cb_register(&common_scan_cb); test_cb_register(); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return; From 44ae4b554d43483324be575a189a4640a98437b6 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 13 Sep 2023 16:58:54 +0200 Subject: [PATCH 0077/1623] [nrf fromtree] tests: bsim: Bluetooth: Add BAP unicast disconnect test The purpose of this test is to verify that the stack has the correct behavior if the ACL disconnects while one or more streams are in the streaming state. The main point it validates is that unicast server device can restart advertising using a simple k_work in the disconnected callback. The number of connections supported by the test suite has also been reduced to 3, to avoid some seen issues with scheduling when CONFIG_BT_MAX_CONN=5. A part of implementing the test for this purpose, the unicast client and unicast server have been extended to also advertise and scan for proper ASCS advertising data. Signed-off-by: Emil Gydesen (cherry picked from commit 01f7d108f3d1982549535f6fe4c7096b188cb3ed) Signed-off-by: Dominik Ermel (cherry picked from commit be34d58d76f42791990927f628beef1623a6cd54) --- tests/bsim/bluetooth/audio/prj.conf | 5 +- .../audio/src/bap_unicast_client_test.c | 149 ++++++++++++- .../audio/src/bap_unicast_server_test.c | 201 +++++++++++++----- .../bap_unicast_audio_acl_disconnect.sh | 27 +++ 4 files changed, 328 insertions(+), 54 deletions(-) create mode 100755 tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio_acl_disconnect.sh diff --git a/tests/bsim/bluetooth/audio/prj.conf b/tests/bsim/bluetooth/audio/prj.conf index 2077143452b..8f2d6a585a9 100644 --- a/tests/bsim/bluetooth/audio/prj.conf +++ b/tests/bsim/bluetooth/audio/prj.conf @@ -9,8 +9,9 @@ CONFIG_BT_DEVICE_NAME="bsim_test_audio" # TBS Client may require up to 12 buffers CONFIG_BT_L2CAP_TX_BUF_COUNT=12 CONFIG_BT_ATT_PREPARE_COUNT=5 -CONFIG_BT_MAX_CONN=5 -CONFIG_BT_MAX_PAIRED=5 +CONFIG_BT_MAX_CONN=3 +CONFIG_BT_MAX_PAIRED=3 +CONFIG_BT_EXT_ADV_MAX_ADV_SET=3 CONFIG_BT_GATT_DYNAMIC_DB=y CONFIG_BT_SMP=y CONFIG_BT_L2CAP_TX_MTU=100 diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c index 72aa1cfcd96..3fbd70458b9 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c @@ -306,6 +306,92 @@ static struct bt_gatt_cb gatt_callbacks = { .att_mtu_updated = att_mtu_updated, }; +static bool parse_ascs_ad_data(struct bt_data *data, void *user_data) +{ + const struct bt_le_scan_recv_info *info = user_data; + uint16_t available_source_context; + uint16_t available_sink_context; + struct net_buf_simple net_buf; + struct bt_uuid_16 adv_uuid; + uint8_t announcement_type; + void *uuid; + int err; + + const size_t min_data_len = BT_UUID_SIZE_16 + sizeof(announcement_type) + + sizeof(available_sink_context) + + sizeof(available_source_context); + + if (data->type != BT_DATA_SVC_DATA16) { + return true; + } + + if (data->data_len < min_data_len) { + + return true; + } + + net_buf_simple_init_with_data(&net_buf, (void *)data->data, data->data_len); + + uuid = net_buf_simple_pull_mem(&net_buf, BT_UUID_SIZE_16); + if (!bt_uuid_create(&adv_uuid.uuid, uuid, BT_UUID_SIZE_16)) { + return true; + } + + if (bt_uuid_cmp(&adv_uuid.uuid, BT_UUID_ASCS)) { + return true; + } + + announcement_type = net_buf_simple_pull_u8(&net_buf); + available_sink_context = net_buf_simple_pull_le16(&net_buf); + available_source_context = net_buf_simple_pull_le16(&net_buf); + + printk("Found ASCS with announcement type 0x%02X, sink ctx 0x%04X, source ctx 0x%04X\n", + announcement_type, available_sink_context, available_source_context); + + printk("Stopping scan\n"); + if (bt_le_scan_stop()) { + FAIL("Could not stop scan"); + return false; + } + + err = bt_conn_le_create(info->addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, + &default_conn); + if (err) { + FAIL("Could not connect to peer: %d", err); + return false; + } + + /* Stop parsing */ + return false; +} + +static void broadcast_scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_simple *ad) +{ + char addr_str[BT_ADDR_LE_STR_LEN]; + + if (default_conn) { + return; + } + + /* We're only interested in connectable events */ + if ((info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) == 0) { + return; + } + /* connect only to devices in close proximity */ + if (info->rssi < -70) { + return; + } + + bt_addr_le_to_str(info->addr, addr_str, sizeof(addr_str)); + printk("Device found: %s (RSSI %d)\n", addr_str, info->rssi); + + bt_data_parse(ad, parse_ascs_ad_data, (void *)info); +} + +static struct bt_le_scan_cb bap_scan_cb = { + .recv = broadcast_scan_recv, +}; + static void init(void) { int err; @@ -320,7 +406,7 @@ static void init(void) g_streams[i].ops = &stream_ops; } - bt_le_scan_cb_register(&common_scan_cb); + bt_le_scan_cb_register(&bap_scan_cb); bt_gatt_cb_register(&gatt_callbacks); err = bt_bap_unicast_client_register_cb(&unicast_client_cbs); @@ -767,14 +853,71 @@ static void test_main(void) PASS("Unicast client passed\n"); } +static void test_main_acl_disconnect(void) +{ + struct bt_bap_unicast_group *unicast_group; + size_t stream_cnt; + + init(); + + scan_and_connect(); + + exchange_mtu(); + + discover_sinks(); + + discover_sources(); + + /* Run the stream setup multiple time to ensure states are properly + * set and reset + */ + + printk("Creating unicast group\n"); + stream_cnt = create_unicast_group(&unicast_group); + + printk("Codec configuring streams\n"); + codec_configure_streams(stream_cnt); + + printk("QoS configuring streams\n"); + qos_configure_streams(unicast_group, stream_cnt); + + printk("Enabling streams\n"); + enable_streams(stream_cnt); + + printk("Metadata update streams\n"); + metadata_update_streams(stream_cnt); + + printk("Starting streams\n"); + start_streams(); + + disconnect_acl(); + + printk("Deleting unicast group\n"); + delete_unicast_group(unicast_group); + unicast_group = NULL; + + /* Reconnect */ + scan_and_connect(); + + disconnect_acl(); + + PASS("Unicast client ACL disconnect passed\n"); +} + static const struct bst_test_instance test_unicast_client[] = { { .test_id = "unicast_client", .test_post_init_f = test_init, .test_tick_f = test_tick, - .test_main_f = test_main + .test_main_f = test_main, + }, + { + .test_id = "unicast_client_acl_disconnect", + .test_post_init_f = test_init, + .test_tick_f = test_tick, + .test_main_f = test_main_acl_disconnect, }, - BSTEST_END_MARKER + BSTEST_END_MARKER, }; struct bst_test_list *test_unicast_client_install(struct bst_test_list *tests) diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c index c302ec320ab..58acdc1726c 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c @@ -48,11 +48,20 @@ static struct bt_bap_stream streams[CONFIG_BT_ASCS_ASE_SNK_COUNT + CONFIG_BT_ASC static const struct bt_audio_codec_qos_pref qos_pref = BT_AUDIO_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, 0x02, 10, 40000, 40000, 40000, 40000); -/* TODO: Expand with BAP data */ +static uint8_t unicast_server_addata[] = { + BT_UUID_16_ENCODE(BT_UUID_ASCS_VAL), /* ASCS UUID */ + BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED, /* Target Announcement */ + BT_BYTES_LIST_LE16(PREF_CONTEXT), + BT_BYTES_LIST_LE16(PREF_CONTEXT), + 0x00, /* Metadata length */ +}; + static const struct bt_data unicast_server_ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_ASCS_VAL)), + BT_DATA(BT_DATA_SVC_DATA16, unicast_server_addata, ARRAY_SIZE(unicast_server_addata)), }; +static struct bt_le_ext_adv *ext_adv; CREATE_FLAG(flag_stream_configured); @@ -230,47 +239,6 @@ static struct bt_bap_stream_ops stream_ops = { .recv = stream_recv }; -static void init(void) -{ - static struct bt_pacs_cap cap = { - .codec_cap = &lc3_codec_cap, - }; - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth enable failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - bt_bap_unicast_server_register_cb(&unicast_server_cb); - - err = bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &cap); - if (err != 0) { - FAIL("Failed to register capabilities: %d", err); - return; - } - - err = bt_pacs_cap_register(BT_AUDIO_DIR_SOURCE, &cap); - if (err != 0) { - FAIL("Failed to register capabilities: %d", err); - return; - } - - for (size_t i = 0; i < ARRAY_SIZE(streams); i++) { - bt_bap_stream_cb_register(&streams[i], &stream_ops); - } - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, unicast_server_ad, ARRAY_SIZE(unicast_server_ad), - NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } -} - static void set_location(void) { int err; @@ -332,25 +300,160 @@ static void set_available_contexts(void) printk("Available contexts successfully set\n"); } -static void test_main(void) +static void init(void) { - init(); + static struct bt_pacs_cap cap = { + .codec_cap = &lc3_codec_cap, + }; + int err; + + err = bt_enable(NULL); + if (err != 0) { + FAIL("Bluetooth enable failed (err %d)\n", err); + return; + } + + printk("Bluetooth initialized\n"); + + bt_bap_unicast_server_register_cb(&unicast_server_cb); + + err = bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &cap); + if (err != 0) { + FAIL("Failed to register capabilities: %d", err); + return; + } + + err = bt_pacs_cap_register(BT_AUDIO_DIR_SOURCE, &cap); + if (err != 0) { + FAIL("Failed to register capabilities: %d", err); + return; + } set_location(); set_available_contexts(); + for (size_t i = 0; i < ARRAY_SIZE(streams); i++) { + bt_bap_stream_cb_register(&streams[i], &stream_ops); + } + + /* Create a non-connectable non-scannable advertising set */ + err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_NAME, NULL, &ext_adv); + if (err != 0) { + FAIL("Failed to create advertising set (err %d)\n", err); + return; + } + + err = bt_le_ext_adv_set_data(ext_adv, unicast_server_ad, ARRAY_SIZE(unicast_server_ad), + NULL, 0); + if (err != 0) { + FAIL("Failed to set advertising data (err %d)\n", err); + return; + } + + err = bt_le_ext_adv_start(ext_adv, BT_LE_EXT_ADV_START_DEFAULT); + if (err != 0) { + FAIL("Failed to start advertising set (err %d)\n", err); + return; + } + printk("Advertising started\n"); +} + +static void test_main(void) +{ + init(); + /* TODO: When babblesim supports ISO, wait for audio stream to pass */ WAIT_FOR_FLAG(flag_connected); WAIT_FOR_FLAG(flag_stream_configured); + + WAIT_FOR_UNSET_FLAG(flag_connected); + PASS("Unicast server passed\n"); } -static const struct bst_test_instance test_unicast_server[] = {{.test_id = "unicast_server", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main}, - BSTEST_END_MARKER}; +static void restart_adv_cb(struct k_work *work) +{ + int err; + + printk("Restarting ext_adv after disconnect\n"); + + err = bt_le_ext_adv_start(ext_adv, BT_LE_EXT_ADV_START_DEFAULT); + if (err != 0) { + FAIL("Failed to start advertising set (err %d)\n", err); + return; + } +} + +static K_WORK_DEFINE(restart_adv_work, restart_adv_cb); + +static void acl_disconnected(struct bt_conn *conn, uint8_t reason) +{ + if (conn != default_conn) { + return; + } + + k_work_submit(&restart_adv_work); +} + +static void test_main_acl_disconnect(void) +{ + struct bt_le_ext_adv *dummy_ext_adv[CONFIG_BT_MAX_CONN - 1]; + static struct bt_conn_cb conn_callbacks = { + .disconnected = acl_disconnected, + }; + + init(); + + /* Create CONFIG_BT_MAX_CONN - 1 dummy advertising sets, to ensure that we only have 1 free + * connection when attempting to restart advertising, which should ensure that the + * bt_conn object is properly unref'ed by the stack + */ + for (size_t i = 0U; i < ARRAY_SIZE(dummy_ext_adv); i++) { + const struct bt_le_adv_param param = BT_LE_ADV_PARAM_INIT( + (BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CONNECTABLE), + BT_GAP_ADV_SLOW_INT_MAX, BT_GAP_ADV_SLOW_INT_MAX, NULL); + int err; + + err = bt_le_ext_adv_create(¶m, NULL, &dummy_ext_adv[i]); + if (err != 0) { + FAIL("Failed to create advertising set[%zu] (err %d)\n", i, err); + return; + } + + err = bt_le_ext_adv_start(dummy_ext_adv[i], BT_LE_EXT_ADV_START_DEFAULT); + if (err != 0) { + FAIL("Failed to start advertising set[%zu] (err %d)\n", i, err); + return; + } + } + + bt_conn_cb_register(&conn_callbacks); + + WAIT_FOR_FLAG(flag_connected); + WAIT_FOR_FLAG(flag_stream_configured); + + /* The client will reconnect */ + WAIT_FOR_UNSET_FLAG(flag_connected); + WAIT_FOR_FLAG(flag_connected); + PASS("Unicast server ACL disconnect passed\n"); +} + +static const struct bst_test_instance test_unicast_server[] = { + { + .test_id = "unicast_server", + .test_post_init_f = test_init, + .test_tick_f = test_tick, + .test_main_f = test_main, + }, + { + .test_id = "unicast_server_acl_disconnect", + .test_post_init_f = test_init, + .test_tick_f = test_tick, + .test_main_f = test_main_acl_disconnect, + }, + BSTEST_END_MARKER, +}; struct bst_test_list *test_unicast_server_install(struct bst_test_list *tests) { diff --git a/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio_acl_disconnect.sh b/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio_acl_disconnect.sh new file mode 100755 index 00000000000..875a2b752dc --- /dev/null +++ b/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio_acl_disconnect.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +SIMULATION_ID="unicast_audio_acl_disconnect" +VERBOSITY_LEVEL=2 +EXECUTE_TIMEOUT=20 + +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + +cd ${BSIM_OUT_PATH}/bin + +printf "\n\n======== Unicast Audio ACL Disconnect test =========\n\n" + +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ + -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=unicast_client_acl_disconnect -rs=23 + +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ + -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=unicast_server_acl_disconnect -rs=28 + +# Simulation time should be larger than the WAIT_TIME in common.h +Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ + -D=2 -sim_length=60e6 $@ + +wait_for_background_jobs From 71c7ace4d8da9c5e88b729e3f1dabde5f330f184 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 13 Sep 2023 17:02:45 +0200 Subject: [PATCH 0078/1623] [nrf fromtree] Bluetooth: ASCS: Modify the ACL disconnect behavior Instead of calling ase_release for each ASE in the ACL disconnected callback, we now call the state_transition_work_handler directly. This is to ensure that when the disconnected callback returns, the bt_conn object has been properly unref'ed in a timely manner. Signed-off-by: Emil Gydesen (cherry picked from commit c3c83c7049337f2ab1b6889ad83cb922457a3185) Signed-off-by: Dominik Ermel (cherry picked from commit df75d0300edec2fd1935fb5f7103b9e30f8e2942) --- subsys/bluetooth/audio/ascs.c | 14 +++++++++++++- tests/bluetooth/audio/ascs/src/main.c | 4 ---- tests/bluetooth/audio/mocks/src/kernel.c | 7 +++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 9b45754fe90..d85a90ec77a 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -119,6 +119,8 @@ static void ase_free(struct bt_ascs_ase *ase) bt_conn_unref(ase->conn); ase->conn = NULL; + + (void)k_work_cancel(&ase->state_transition_work); } static void ase_status_changed(struct bt_ascs_ase *ase, uint8_t state) @@ -1094,7 +1096,17 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) } if (ase->ep.status.state != BT_BAP_EP_STATE_IDLE) { - ase_release(ase, reason, BT_BAP_ASCS_RSP_NULL); + /* We must set the state to idle when the ACL is disconnected immediately, + * as when the ACL disconnect callbacks have been called, the application + * should expect there to be only a single reference to the bt_conn pointer + * from the stack. + * We trigger the work handler directly rather than e.g. calling + * ase_set_state_idle to trigger "regular" state change behavior (such) as + * calling stream->stopped when leaving the streaming state. + */ + ase->ep.reason = reason; + ase->state_pending = BT_BAP_EP_STATE_IDLE; + state_transition_work_handler(&ase->state_transition_work); /* At this point, `ase` object have been free'd */ } } diff --git a/tests/bluetooth/audio/ascs/src/main.c b/tests/bluetooth/audio/ascs/src/main.c index b0bc7f88150..126c82d63bb 100644 --- a/tests/bluetooth/audio/ascs/src/main.c +++ b/tests/bluetooth/audio/ascs/src/main.c @@ -250,7 +250,6 @@ ZTEST_F(ascs_test_suite, test_release_ase_on_acl_disconnection_client_terminates mock_bt_iso_disconnected(chan, BT_HCI_ERR_REMOTE_USER_TERM_CONN); /* Expected to notify the upper layers */ - expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_released_called_once(stream); bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); @@ -288,7 +287,6 @@ ZTEST_F(ascs_test_suite, test_release_ase_on_acl_disconnection_server_terminates k_sleep(K_MSEC(CONFIG_BT_ASCS_ISO_DISCONNECT_DELAY)); /* Expected to notify the upper layers */ - expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_released_called_once(stream); bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); @@ -351,7 +349,6 @@ ZTEST_F(ascs_test_suite, test_release_stream_pair_on_acl_disconnection_client_te const struct bt_bap_stream *streams[2] = { &snk_stream, &src_stream }; expect_bt_bap_stream_ops_released_called_twice(streams); - expect_bt_bap_unicast_server_cb_release_called_twice(streams); bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); } @@ -413,7 +410,6 @@ ZTEST_F(ascs_test_suite, test_release_stream_pair_on_acl_disconnection_server_te const struct bt_bap_stream *streams[2] = { &snk_stream, &src_stream }; expect_bt_bap_stream_ops_released_called_twice(streams); - expect_bt_bap_unicast_server_cb_release_called_twice(streams); bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); } diff --git a/tests/bluetooth/audio/mocks/src/kernel.c b/tests/bluetooth/audio/mocks/src/kernel.c index ce9dcab5d3a..03dc2cf582d 100644 --- a/tests/bluetooth/audio/mocks/src/kernel.c +++ b/tests/bluetooth/audio/mocks/src/kernel.c @@ -56,6 +56,13 @@ int k_work_cancel_delayable(struct k_work_delayable *dwork) return 0; } +int k_work_cancel(struct k_work *work) +{ + (void)sys_slist_find_and_remove(&work_pending, &work->node); + + return 0; +} + void k_work_init(struct k_work *work, k_work_handler_t handler) { work->handler = handler; From 5bb619da835338caa595cdfb90453e8f833effaa Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Thu, 21 Sep 2023 18:51:32 +0000 Subject: [PATCH 0079/1623] [nrf noup] modules: mbedtls: Use psa_util.c only with non-nRF Adds the psa_util.c conditionally, where needed. Signed-off-by: Dominik Ermel (cherry picked from commit edf807fd47cd6c3ab71c020363888fe73f2cc776) --- modules/mbedtls/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/mbedtls/CMakeLists.txt b/modules/mbedtls/CMakeLists.txt index f061605c027..c1c8e076b83 100644 --- a/modules/mbedtls/CMakeLists.txt +++ b/modules/mbedtls/CMakeLists.txt @@ -76,7 +76,6 @@ zephyr_interface_library_named(mbedTLS) ${ZEPHYR_CURRENT_MODULE_DIR}/library/mps_reader.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/mps_trace.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/poly1305.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_util.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ripemd160.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/rsa_alt_helpers.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/rsa.c @@ -89,6 +88,10 @@ zephyr_interface_library_named(mbedTLS) zephyr_init.c ) + if (NOT DEFINED ZEPHYR_NRF_MODULE_DIR) + list(APPEND mbedtls_base_src ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_util.c) + endif() + zephyr_library_sources(${mbedtls_base_src}) zephyr_library_sources_ifdef(CONFIG_MBEDTLS_DEBUG debug.c) From 0b79df6d821b2f77d65f80c5fe411ec15b273768 Mon Sep 17 00:00:00 2001 From: Florian Grandel Date: Fri, 11 Aug 2023 16:50:28 +0200 Subject: [PATCH 0080/1623] [nrf fromtree] modules: openthread: radio: OT now uses standard TX timestamp Synchronizes with the new upstream RX/TX timestamp definition in OpenThread based on the standard's SFD. This change is synchronized with the upstream OpenThread implementation via west.yml. Signed-off-by: Florian Grandel (cherry picked from commit e2005b6e48d3b578f83fdfaaff547d1f8082ce35) Signed-off-by: Maciej Baczmanski (cherry picked from commit d62a2c576ac0a2bd164b355cbd95aa00ede869c5) --- modules/openthread/CMakeLists.txt | 12 ++++++++++++ modules/openthread/Kconfig.features | 13 +++++++++++++ modules/openthread/platform/radio.c | 4 +--- tests/subsys/openthread/radio_test.c | 10 ++++------ west.yml | 2 +- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index 67acbe00dec..826d9b31590 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -154,6 +154,12 @@ else() set(OT_DATASET_UPDATER OFF CACHE BOOL "Enable Dataset updater" FORCE) endif() +if(CONFIG_OPENTHREAD_DEVICE_PROP_LEADER_WEIGHT) + set(OT_DEVICE_PROP_LEADER_WEIGHT ON CACHE BOOL "Enable device props for leader weight" FORCE) +else() + set(OT_DEVICE_PROP_LEADER_WEIGHT OFF CACHE BOOL "Enable device props for leader weight" FORCE) +endif() + if(CONFIG_OPENTHREAD_DHCP6_CLIENT) set(OT_DHCP6_CLIENT ON CACHE BOOL "Enable DHCPv6 Client" FORCE) else() @@ -274,6 +280,12 @@ else() set(OT_LINK_METRICS_INITIATOR OFF CACHE BOOL "Enable Link Metrics initiator for Thread 1.2" FORCE) endif() +if(CONFIG_OPENTHREAD_LINK_METRICS_MANAGER) + set(OT_LINK_METRICS_MANAGER ON CACHE BOOL "Enable Link Metrics manager for Thread 1.2" FORCE) +else() + set(OT_LINK_METRICS_MANAGER OFF CACHE BOOL "Enable Link Metrics manager for Thread 1.2" FORCE) +endif() + if(CONFIG_OPENTHREAD_LINK_METRICS_SUBJECT) set(OT_LINK_METRICS_SUBJECT ON CACHE BOOL "Enable Link Metrics subject for Thread 1.2" FORCE) else() diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index 61b0efc921b..87c220944a4 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -92,6 +92,16 @@ config OPENTHREAD_CSL_RECEIVER help Enable CSL Receiver support for Thread 1.2 +config OPENTHREAD_DEVICE_PROP_LEADER_WEIGHT + bool "Device props for leader weight" + default n if (OPENTHREAD_THREAD_VERSION_1_1 || \ + OPENTHREAD_THREAD_VERSION_1_2 || \ + OPENTHREAD_THREAD_VERSION_1_3) + default y + help + Enable the device properties which are then used to determine and set + the Leader Weight. + config OPENTHREAD_DATASET_UPDATER bool "Dataset updater" @@ -165,6 +175,9 @@ config OPENTHREAD_LEGACY config OPENTHREAD_LINK_METRICS_INITIATOR bool "Link Metrics initiator" +config OPENTHREAD_LINK_METRICS_MANAGER + bool "Link Metrics manager" + config OPENTHREAD_LINK_METRICS_SUBJECT bool "Link Metrics subject" diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index 94b79ddfed6..9d50e445714 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -58,8 +58,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_OPENTHREAD_L2_LOG_LEVEL); #define CHANNEL_COUNT OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MAX - OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MIN + 1 -#define PHY_SHR_DURATION 160 /* duration of SHR in us */ - enum pending_events { PENDING_EVENT_FRAME_TO_SEND, /* There is a tx frame to send */ PENDING_EVENT_FRAME_RECEIVED, /* Radio has received new frame */ @@ -397,7 +395,7 @@ void transmit_message(struct k_work *tx_job) (sTransmitFrame.mInfo.mTxInfo.mTxDelay != 0)) { #if defined(CONFIG_NET_PKT_TXTIME) uint32_t tx_at = sTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime + - sTransmitFrame.mInfo.mTxInfo.mTxDelay + PHY_SHR_DURATION; + sTransmitFrame.mInfo.mTxInfo.mTxDelay; struct net_ptp_time timestamp = ns_to_net_ptp_time(convert_32bit_us_wrapped_to_64bit_ns(tx_at)); net_pkt_set_timestamp(tx_pkt, ×tamp); diff --git a/tests/subsys/openthread/radio_test.c b/tests/subsys/openthread/radio_test.c index fb6c8755039..87a7013a0d5 100644 --- a/tests/subsys/openthread/radio_test.c +++ b/tests/subsys/openthread/radio_test.c @@ -30,8 +30,6 @@ DEFINE_FFF_GLOBALS; #define FRAME_TYPE_MASK 0x07 #define FRAME_TYPE_ACK 0x02 -#define PHY_SHR_DURATION 160 - K_SEM_DEFINE(ot_sem, 0, 1); /** @@ -295,10 +293,10 @@ ZTEST(openthread_radio, test_tx_test) get_time_mock_fake.return_val = (int64_t)UINT32_MAX * NSEC_PER_USEC + 1000; frm->mInfo.mTxInfo.mTxDelayBaseTime = 3U; frm->mInfo.mTxInfo.mTxDelay = 5U; - expected_target_time = get_time_mock_fake.return_val + - (frm->mInfo.mTxInfo.mTxDelayBaseTime + - frm->mInfo.mTxInfo.mTxDelay + PHY_SHR_DURATION) * - NSEC_PER_USEC; + expected_target_time = + get_time_mock_fake.return_val + + (frm->mInfo.mTxInfo.mTxDelayBaseTime + frm->mInfo.mTxInfo.mTxDelay) * + NSEC_PER_USEC; } /* ACKed frame */ diff --git a/west.yml b/west.yml index b4f874a87c5..bed3b47cfe5 100644 --- a/west.yml +++ b/west.yml @@ -303,7 +303,7 @@ manifest: revision: 42b7c577714b8f22ce82a901e19c1814af4609a8 path: modules/lib/open-amp - name: openthread - revision: f7690fe7e9d638341921808cba6a3e695ec0131e + revision: d62167ee34b091e7025c9ec2820aae71e17a3944 path: modules/lib/openthread - name: picolibc path: modules/lib/picolibc From 9df3b459e3b507bccc1cbedc43617fdd56b98c93 Mon Sep 17 00:00:00 2001 From: Vivekananda Uppunda Date: Mon, 2 Oct 2023 07:19:05 +0530 Subject: [PATCH 0081/1623] [nrf fromtree] net: l2: wifi: Fix Wi-Fi mode get command bug The mode command operation has to be set to WIFI_MGMT_GET when the option -g is provided. It was mistakenly set to true. Correcting the same This PR fixes #63424 and sets the proper value for the get command Signed-off-by: Vivekananda Uppunda (cherry picked from commit b0c96580298ac47715fdb1d1ba5ede766676d643) (cherry picked from commit 06088342cb531ee470c7f64c8c7c0e10d75de8fc) --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 7472d3fa984..592ac50cd8e 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1302,7 +1302,7 @@ void parse_mode_args_to_params(const struct shell *sh, int argc, mode->mode |= WIFI_SOFTAP_MODE; break; case 'g': - mode->oper = true; + mode->oper = WIFI_MGMT_GET; break; case 'i': mode->if_index = (uint8_t)atoi(optarg); From 1b5ab89ed6d031cea80269cb38a512800e46fb59 Mon Sep 17 00:00:00 2001 From: Al Semjonovs Date: Thu, 14 Sep 2023 10:56:46 -0600 Subject: [PATCH 0082/1623] [nrf fromtree] logging: Unused arg in log_msg_get_tid Resolve unused arg compiler error Signed-off-by: Al Semjonovs (cherry picked from commit b1b4932373c6a9b2665432b68df520223243886f) Signed-off-by: Kacper Radoszewski (cherry picked from commit 47f8b98ba0efe5fee10fcc3ed08842ba2e83fd55) --- include/zephyr/logging/log_msg.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/zephyr/logging/log_msg.h b/include/zephyr/logging/log_msg.h index 4eee566bdc5..0279fb0d2cd 100644 --- a/include/zephyr/logging/log_msg.h +++ b/include/zephyr/logging/log_msg.h @@ -669,6 +669,7 @@ static inline void *log_msg_get_tid(struct log_msg *msg) #if CONFIG_LOG_THREAD_ID_PREFIX return msg->hdr.tid; #else + ARG_UNUSED(msg); return NULL; #endif } From 3d2da670428f177fdbe761db49783cdff83503ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Fri, 23 Jun 2023 09:06:51 +0200 Subject: [PATCH 0083/1623] [nrf fromtree] nrf53: Add RTC pretick MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add RTC pretick option that triggers HW activity one tick before and RTC event that leads to the interrupt. Option is active only on nrf53 network core. Signed-off-by: Krzysztof Chruściński (cherry picked from commit 31eaffdf0552ee967b371644869223d9e901de00) (cherry picked from commit da8a9678540b2649c75cd816355aa4b04a01e08f) --- drivers/timer/nrf_rtc_timer.c | 17 ++- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 21 ++++ soc/arm/nordic_nrf/nrf53/soc.c | 164 +++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 1 deletion(-) diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index 4410529608b..e8ba5bd42a5 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -25,6 +25,11 @@ #define RTC_LABEL rtc1 #define RTC_CH_COUNT RTC1_CC_NUM +#define RTC_PRETICK (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK) && \ + IS_ENABLED(CONFIG_SOC_NRF5340_CPUNET)) + +BUILD_ASSERT(!RTC_PRETICK || !(RTC_PRETICK && (CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT > 0)), + "Cannot use user channels when RTC pretick is used"); BUILD_ASSERT(CHAN_COUNT <= RTC_CH_COUNT, "Not enough compare channels"); /* Ensure that counter driver for RTC1 is not enabled. */ BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(RTC_LABEL), disabled), @@ -44,6 +49,9 @@ BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(RTC_LABEL), disabled), #define ANCHOR_RANGE_END (7 * COUNTER_SPAN / 8) #define TARGET_TIME_INVALID (UINT64_MAX) +extern void rtc_pretick_rtc1_cc0_set_hook(uint32_t val); +extern void rtc_pretick_rtc1_isr_hook(void); + static volatile uint32_t overflow_cnt; static volatile uint64_t anchor; static uint64_t last_count; @@ -260,7 +268,7 @@ static int set_alarm(int32_t chan, uint32_t req_cc, bool exact) * This never happens when the written value is N+3. Use 3 cycles as * the nearest possible scheduling then. */ - enum { MIN_CYCLES_FROM_NOW = 3 }; + enum { MIN_CYCLES_FROM_NOW = RTC_PRETICK ? 4 : 3 }; uint32_t cc_val = req_cc; uint32_t cc_inc = MIN_CYCLES_FROM_NOW; @@ -277,6 +285,9 @@ static int set_alarm(int32_t chan, uint32_t req_cc, bool exact) for (;;) { uint32_t now; + if (RTC_PRETICK) { + rtc_pretick_rtc1_cc0_set_hook(cc_val); + } set_comparator(chan, cc_val); /* Enable event routing after the required CC value was set. * Even though the above operation may get repeated (see below), @@ -559,6 +570,10 @@ void rtc_nrf_isr(const void *arg) { ARG_UNUSED(arg); + if (RTC_PRETICK) { + rtc_pretick_rtc1_isr_hook(); + } + if (nrf_rtc_int_enable_check(RTC, NRF_RTC_INT_OVERFLOW_MASK) && nrf_rtc_event_check(RTC, NRF_RTC_EVENT_OVERFLOW)) { nrf_rtc_event_clear(RTC, NRF_RTC_EVENT_OVERFLOW); diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 122c36988e5..b84985d57eb 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -10,11 +10,13 @@ config SOC_NRF5340_CPUAPP select CPU_HAS_FPU select ARMV8_M_DSP select HAS_POWEROFF + imply SOC_NRF53_RTC_PRETICK config SOC_NRF5340_CPUNET bool select ARM_ON_EXIT_CPU_IDLE imply SOC_NRF53_ANOMALY_160_WORKAROUND_NEEDED + imply SOC_NRF53_RTC_PRETICK choice prompt "nRF53x MCU Selection" @@ -47,6 +49,25 @@ config SOC_NRF53_ANOMALY_160_WORKAROUND depends on SYS_CLOCK_EXISTS select ARM_ON_ENTER_CPU_IDLE_HOOK +config SOC_NRF53_RTC_PRETICK + bool + depends on !NRF_802154_RADIO_DRIVER + select NRFX_DPPI + +if SOC_NRF53_RTC_PRETICK + +config SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET + int "IPC 0 channel for RTC pretick" + range 0 15 + default 10 + +config SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET + int "IPC 1 channel for RTC pretick" + range 0 15 + default 11 + +endif + if SOC_NRF5340_CPUAPP config SOC_DCDC_NRF53X_APP diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index 6552f9d4bb1..50f00932be9 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #if defined(CONFIG_SOC_NRF5340_CPUAPP) #include #include @@ -31,6 +33,8 @@ #if defined(CONFIG_PM_S2RAM) #include #endif +#include +#include #include #include @@ -38,6 +42,9 @@ #define PIN_XL1 0 #define PIN_XL2 1 +#define RTC1_PRETICK_CC_CHAN 1 +#define RTC1_PRETICK_OVERFLOW_CHAN 2 + #if defined(CONFIG_SOC_NRF_GPIO_FORWARDER_FOR_NRF5340) #define GPIOS_PSEL_BY_IDX(node_id, prop, idx) \ NRF_DT_GPIOS_TO_PSEL_BY_IDX(node_id, prop, idx), @@ -137,11 +144,164 @@ bool z_arm_on_enter_cpu_idle(void) suppress_message = true; } #endif +#if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) + if (ok_to_sleep) { + NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] |= + IPC_PUBLISH_RECEIVE_EN_Msk; + if (!nrf_rtc_event_check(NRF_RTC0, NRF_RTC_CHANNEL_EVENT_ADDR(3)) && + !nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)) && + !nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN))) { + NRF_WDT->TASKS_STOP = 1; + /* Check if any event did not occur after we checked for + * stopping condition. If yes, we might have stopped WDT + * when it should be running. Restart it. + */ + if (nrf_rtc_event_check(NRF_RTC0, NRF_RTC_CHANNEL_EVENT_ADDR(3)) || + nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)) || + nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN))) { + NRF_WDT->TASKS_START = 1; + } + } + } +#endif return ok_to_sleep; } #endif /* CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND */ +#if CONFIG_SOC_NRF53_RTC_PRETICK +#ifdef CONFIG_SOC_NRF5340_CPUAPP +/* RTC pretick - application core part. */ +static int rtc_pretick_cpuapp_init(void) +{ + uint8_t ch; + nrfx_err_t err; + nrf_ipc_event_t ipc_event = + nrf_ipc_receive_event_get(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET); + nrf_ipc_task_t ipc_task = + nrf_ipc_send_task_get(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET); + uint32_t task_ipc = nrf_ipc_task_address_get(NRF_IPC, ipc_task); + uint32_t evt_ipc = nrf_ipc_event_address_get(NRF_IPC, ipc_event); + + err = nrfx_gppi_channel_alloc(&ch); + if (err != NRFX_SUCCESS) { + return -ENOMEM; + } + + nrf_ipc_receive_config_set(NRF_IPC, CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET, + BIT(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET)); + nrf_ipc_send_config_set(NRF_IPC, CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET, + BIT(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET)); + + nrfx_gppi_task_endpoint_setup(ch, task_ipc); + nrfx_gppi_event_endpoint_setup(ch, evt_ipc); + nrfx_gppi_channels_enable(BIT(ch)); + + return 0; +} +#else /* CONFIG_SOC_NRF5340_CPUNET */ + +static void rtc_pretick_rtc_isr_hook(void) +{ + NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] &= + ~IPC_PUBLISH_RECEIVE_EN_Msk; +} + +void rtc_pretick_rtc0_isr_hook(void) +{ + rtc_pretick_rtc_isr_hook(); +} + +void rtc_pretick_rtc1_cc0_set_hook(uint32_t val) +{ + nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_CC_CHAN, val - 1); +} + +void rtc_pretick_rtc1_isr_hook(void) +{ + rtc_pretick_rtc_isr_hook(); + + if (nrf_rtc_event_check(NRF_RTC1, NRF_RTC_EVENT_OVERFLOW)) { + if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { + nrf_rtc_event_clear(NRF_RTC1, + NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); + } + } + if (nrf_rtc_event_check(NRF_RTC1, NRF_RTC_EVENT_COMPARE_0)) { + if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); + } + } +} + +static int rtc_pretick_cpunet_init(void) +{ + uint8_t ppi_ch; + nrf_ipc_task_t ipc_task = + nrf_ipc_send_task_get(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET); + nrf_ipc_event_t ipc_event = + nrf_ipc_receive_event_get(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET); + uint32_t task_ipc = nrf_ipc_task_address_get(NRF_IPC, ipc_task); + uint32_t evt_ipc = nrf_ipc_event_address_get(NRF_IPC, ipc_event); + uint32_t task_wdt = nrf_wdt_task_address_get(NRF_WDT, NRF_WDT_TASK_START); + uint32_t evt_mpsl_cc = nrf_rtc_event_address_get(NRF_RTC0, NRF_RTC_EVENT_COMPARE_3); + uint32_t evt_cc = nrf_rtc_event_address_get(NRF_RTC1, + NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); + uint32_t evt_overflow = nrf_rtc_event_address_get(NRF_RTC1, + NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); + + /* Configure Watchdog to allow stopping. */ + nrf_wdt_behaviour_set(NRF_WDT, WDT_CONFIG_STOPEN_Msk | BIT(4)); + *((volatile uint32_t *)0x41203120) = 0x14; + + /* Configure IPC */ + nrf_ipc_receive_config_set(NRF_IPC, CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET, + BIT(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET)); + nrf_ipc_send_config_set(NRF_IPC, CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET, + BIT(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET)); + + /* Allocate PPI channel for RTC Compare event publishers that starts WDT. */ + nrfx_err_t err = nrfx_gppi_channel_alloc(&ppi_ch); + + if (err != NRFX_SUCCESS) { + return -ENOMEM; + } + + /* Setup a PPI connection between RTC "pretick" events and IPC task. */ + if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE)) { + nrfx_gppi_event_endpoint_setup(ppi_ch, evt_mpsl_cc); + } + nrfx_gppi_event_endpoint_setup(ppi_ch, evt_cc); + nrfx_gppi_event_endpoint_setup(ppi_ch, evt_overflow); + nrfx_gppi_task_endpoint_setup(ppi_ch, task_ipc); + nrfx_gppi_event_endpoint_setup(ppi_ch, evt_ipc); + nrfx_gppi_task_endpoint_setup(ppi_ch, task_wdt); + nrfx_gppi_channels_enable(BIT(ppi_ch)); + + nrf_rtc_event_enable(NRF_RTC1, NRF_RTC_CHANNEL_INT_MASK(RTC1_PRETICK_CC_CHAN)); + nrf_rtc_event_enable(NRF_RTC1, NRF_RTC_CHANNEL_INT_MASK(RTC1_PRETICK_OVERFLOW_CHAN)); + + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); + /* Set event 1 tick before overflow. */ + nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_OVERFLOW_CHAN, 0x00FFFFFF); + + return 0; +} +#endif /* CONFIG_SOC_NRF5340_CPUNET */ + +static int rtc_pretick_init(void) +{ + ARG_UNUSED(unused); +#ifdef CONFIG_SOC_NRF5340_CPUAPP + return rtc_pretick_cpuapp_init(); +#else + return rtc_pretick_cpunet_init(); +#endif +} +#endif /* CONFIG_SOC_NRF53_RTC_PRETICK */ + + static int nordicsemi_nrf53_init(void) { #if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(CONFIG_NRF_ENABLE_CACHE) @@ -242,3 +402,7 @@ void arch_busy_wait(uint32_t time_us) } SYS_INIT(nordicsemi_nrf53_init, PRE_KERNEL_1, 0); + +#ifdef CONFIG_SOC_NRF53_RTC_PRETICK +SYS_INIT(rtc_pretick_init, POST_KERNEL, 0); +#endif From b2a1ffbe848082f67c50e094dc065d6d17f5dcc6 Mon Sep 17 00:00:00 2001 From: Andrzej Kuros Date: Tue, 26 Sep 2023 14:28:36 +0200 Subject: [PATCH 0084/1623] [nrf fromtree] arch: arm: aarch32: Introduce z_arm_on_enter_cpu_idle_prepare() hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce an optional hook to be called when the CPU is made idle. If needed, this hook can be used to prepare data for upcoming call to z_arm_on_enter_cpu_idle(). The main difference is that z_arm_on_enter_cpu_idle_prepare() hook is called before interrupts are disabled. Signed-off-by: Andrzej Kuroś (cherry picked from commit 3d89d58cb87843470a6b57b5a5b56b7e29b0d84f) (cherry picked from commit b0c6d4f7c17b232ea688d1621e5162582380b73a) --- arch/arm/Kconfig | 10 ++++++++++ arch/arm/core/aarch32/cpu_idle.S | 25 ++++++++++++++++++++----- include/zephyr/arch/arm/aarch32/misc.h | 9 +++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index e17cf3f9b31..ef9a20d0cc9 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -53,6 +53,16 @@ config ARM_ON_ENTER_CPU_IDLE_HOOK If needed, this hook can be used to prevent the CPU from actually entering sleep by skipping the WFE/WFI instruction. +config ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK + bool + help + Enables a hook (z_arm_on_enter_cpu_idle_prepare()) that is called when + the CPU is made idle (by k_cpu_idle() or k_cpu_atomic_idle()). + If needed, this hook can prepare data to upcoming call to + z_arm_on_enter_cpu_idle(). The z_arm_on_enter_cpu_idle_prepare differs + from z_arm_on_enter_cpu_idle because it is called before interrupts are + disabled. + config ARM_ON_EXIT_CPU_IDLE bool help diff --git a/arch/arm/core/aarch32/cpu_idle.S b/arch/arm/core/aarch32/cpu_idle.S index 8164959ab29..95e37917180 100644 --- a/arch/arm/core/aarch32/cpu_idle.S +++ b/arch/arm/core/aarch32/cpu_idle.S @@ -85,16 +85,24 @@ _skip_\@: .endm SECTION_FUNC(TEXT, arch_cpu_idle) -#ifdef CONFIG_TRACING +#if defined(CONFIG_TRACING) || \ + defined(CONFIG_ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK) push {r0, lr} + +#ifdef CONFIG_TRACING bl sys_trace_idle +#endif +#ifdef CONFIG_ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK + bl z_arm_on_enter_cpu_idle_prepare +#endif + #if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE) pop {r0, r1} mov lr, r1 #else pop {r0, lr} #endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */ -#endif /* CONFIG_TRACING */ +#endif #if defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE) /* @@ -138,17 +146,24 @@ SECTION_FUNC(TEXT, arch_cpu_idle) bx lr SECTION_FUNC(TEXT, arch_cpu_atomic_idle) -#ifdef CONFIG_TRACING +#if defined(CONFIG_TRACING) || \ + defined(CONFIG_ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK) push {r0, lr} + +#ifdef CONFIG_TRACING bl sys_trace_idle +#endif +#ifdef CONFIG_ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK + bl z_arm_on_enter_cpu_idle_prepare +#endif + #if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE) pop {r0, r1} mov lr, r1 #else pop {r0, lr} #endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */ -#endif /* CONFIG_TRACING */ - +#endif /* * Lock PRIMASK while sleeping: wfe will still get interrupted by * incoming interrupts but the CPU will not service them right away. diff --git a/include/zephyr/arch/arm/aarch32/misc.h b/include/zephyr/arch/arm/aarch32/misc.h index 24ed69f663c..ab67a35e94c 100644 --- a/include/zephyr/arch/arm/aarch32/misc.h +++ b/include/zephyr/arch/arm/aarch32/misc.h @@ -51,6 +51,15 @@ extern bool z_arm_thread_is_in_user_mode(void); bool z_arm_on_enter_cpu_idle(void); #endif +#if defined(CONFIG_ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK) +/* Prototype of a hook that can be enabled to be called every time the CPU is + * made idle (the calls will be done from k_cpu_idle() and k_cpu_atomic_idle()). + * The function is called before interrupts are disabled and can prepare to + * upcoming call to z_arm_on_enter_cpu_idle. + */ +void z_arm_on_enter_cpu_idle_prepare(void); +#endif + #endif #ifdef __cplusplus From 0704fb1e49aef4c6d9f892b0d46c771f0081e360 Mon Sep 17 00:00:00 2001 From: Andrzej Kuros Date: Mon, 18 Sep 2023 10:06:22 +0200 Subject: [PATCH 0085/1623] [nrf fromtree] nrf53: RTC pretick allows user channels and require just one CC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The nrf53 pretick can be used with non-zero `NRF_RTC_TIMER_USER_CHAN_COUNT` Kconfig option. The nrf53 pretick requires just one RTC1 CC channel. The nrf53 pretick handles also RTC1 and RTC0 both CCs and OVERFLOW events by examination of events scheduled on them. The pretick is set based on number of ticks to the closest event scheduled that can trigger an interrupt. Because the operation in `z_arm_on_enter_cpu_idle` hook would take too much time with interrupts disabled, the `z_arm_on_enter_cpu_idle_prepare` hook enabled by Kconfig option `ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK` is used. It performs RTC0 and RTC1 examination, and sets pretick without interrupts being blocked. The LDREX/STREX are leveraged to detect if exception took place between start of `z_arm_on_enter_cpu_idle_prepare` and `z_arm_on_enter_cpu_idle`. If exception has not been taken, the pretick calculation can be trusted because source data could not changed and too much time could not pass. Otherwise the sleep attempt is disallowed, the idle will loop again and try later. Prompt for `SOC_NRF53_RTC_PRETICK` Kconfig option allows to control this option by an user and turn the feature off if necessary. Signed-off-by: Andrzej Kuroś (cherry picked from commit e03d5d4c6dd5d08b0126153203b6dd0331f47507) (cherry picked from commit 835b92d5782fe40b729f8927baba1930ebd92ddb) --- drivers/timer/nrf_rtc_timer.c | 18 +- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 9 +- soc/arm/nordic_nrf/nrf53/soc.c | 274 ++++++++++++++++++++++----- 3 files changed, 239 insertions(+), 62 deletions(-) diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index e8ba5bd42a5..9241c5b7a10 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -17,20 +17,18 @@ #include #include +#define RTC_PRETICK (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK) && \ + IS_ENABLED(CONFIG_SOC_NRF5340_CPUNET)) + #define EXT_CHAN_COUNT CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT #define CHAN_COUNT (EXT_CHAN_COUNT + 1) #define RTC NRF_RTC1 #define RTC_IRQn NRFX_IRQ_NUMBER_GET(RTC) #define RTC_LABEL rtc1 -#define RTC_CH_COUNT RTC1_CC_NUM +#define CHAN_COUNT_MAX (RTC1_CC_NUM - (RTC_PRETICK ? 1 : 0)) -#define RTC_PRETICK (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK) && \ - IS_ENABLED(CONFIG_SOC_NRF5340_CPUNET)) - -BUILD_ASSERT(!RTC_PRETICK || !(RTC_PRETICK && (CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT > 0)), - "Cannot use user channels when RTC pretick is used"); -BUILD_ASSERT(CHAN_COUNT <= RTC_CH_COUNT, "Not enough compare channels"); +BUILD_ASSERT(CHAN_COUNT <= CHAN_COUNT_MAX, "Not enough compare channels"); /* Ensure that counter driver for RTC1 is not enabled. */ BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(RTC_LABEL), disabled), "Counter for RTC1 must be disabled"); @@ -49,7 +47,6 @@ BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(RTC_LABEL), disabled), #define ANCHOR_RANGE_END (7 * COUNTER_SPAN / 8) #define TARGET_TIME_INVALID (UINT64_MAX) -extern void rtc_pretick_rtc1_cc0_set_hook(uint32_t val); extern void rtc_pretick_rtc1_isr_hook(void); static volatile uint32_t overflow_cnt; @@ -268,7 +265,7 @@ static int set_alarm(int32_t chan, uint32_t req_cc, bool exact) * This never happens when the written value is N+3. Use 3 cycles as * the nearest possible scheduling then. */ - enum { MIN_CYCLES_FROM_NOW = RTC_PRETICK ? 4 : 3 }; + enum { MIN_CYCLES_FROM_NOW = 3 }; uint32_t cc_val = req_cc; uint32_t cc_inc = MIN_CYCLES_FROM_NOW; @@ -285,9 +282,6 @@ static int set_alarm(int32_t chan, uint32_t req_cc, bool exact) for (;;) { uint32_t now; - if (RTC_PRETICK) { - rtc_pretick_rtc1_cc0_set_hook(cc_val); - } set_comparator(chan, cc_val); /* Enable event routing after the required CC value was set. * Even though the above operation may get repeated (see below), diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index b84985d57eb..9bb4caf2bb9 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -16,7 +16,7 @@ config SOC_NRF5340_CPUNET bool select ARM_ON_EXIT_CPU_IDLE imply SOC_NRF53_ANOMALY_160_WORKAROUND_NEEDED - imply SOC_NRF53_RTC_PRETICK + imply SOC_NRF53_RTC_PRETICK if !WDT_NRFX choice prompt "nRF53x MCU Selection" @@ -50,9 +50,14 @@ config SOC_NRF53_ANOMALY_160_WORKAROUND select ARM_ON_ENTER_CPU_IDLE_HOOK config SOC_NRF53_RTC_PRETICK - bool + bool "Pre-tick workaround for nRF5340 anomaly 165" depends on !NRF_802154_RADIO_DRIVER select NRFX_DPPI + select ARM_ON_ENTER_CPU_IDLE_HOOK if SOC_NRF5340_CPUNET + select ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK if SOC_NRF5340_CPUNET + help + Indicates that the pre-tick workaround for the anomaly 165 that affects + the nRF5340 SoC should be applied. if SOC_NRF53_RTC_PRETICK diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index 50f00932be9..aa93dfd4b54 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -42,8 +43,11 @@ #define PIN_XL1 0 #define PIN_XL2 1 -#define RTC1_PRETICK_CC_CHAN 1 -#define RTC1_PRETICK_OVERFLOW_CHAN 2 +#define RTC1_PRETICK_CC_CHAN (RTC1_CC_NUM - 1) + +/* Mask of CC channels capable of generating interrupts, see nrf_rtc_timer.c */ +#define RTC1_PRETICK_SELECTED_CC_MASK BIT_MASK(CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT + 1U) +#define RTC0_PRETICK_SELECTED_CC_MASK BIT_MASK(NRF_RTC_CC_COUNT_MAX) #if defined(CONFIG_SOC_NRF_GPIO_FORWARDER_FOR_NRF5340) #define GPIOS_PSEL_BY_IDX(node_id, prop, idx) \ @@ -130,39 +134,240 @@ static bool nrf53_anomaly_160_check(void) return true; } -bool z_arm_on_enter_cpu_idle(void) +#if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) + +BUILD_ASSERT(!IS_ENABLED(CONFIG_WDT_NRFX), + "For CONFIG_SOC_NRF53_RTC_PRETICK watchdog is used internally for the pre-tick workaround on nRF5340 cpunet. Application cannot use the watchdog."); + +static inline uint32_t rtc_counter_sub(uint32_t a, uint32_t b) { - bool ok_to_sleep = nrf53_anomaly_160_check(); + return (a - b) & NRF_RTC_COUNTER_MAX; +} -#if (LOG_LEVEL >= LOG_LEVEL_DBG) - static bool suppress_message; +static bool rtc_ticks_to_next_event_get(NRF_RTC_Type *rtc, uint32_t selected_cc_mask, uint32_t cntr, + uint32_t *ticks_to_next_event) +{ + bool result = false; - if (ok_to_sleep) { - suppress_message = false; - } else if (!suppress_message) { - LOG_DBG("Anomaly 160 trigger conditions detected."); - suppress_message = true; + /* Let's preload register to speed-up. */ + uint32_t reg_intenset = rtc->INTENSET; + + /* Note: TICK event not handled. */ + + if (reg_intenset & NRF_RTC_INT_OVERFLOW_MASK) { + /* Overflow can generate an interrupt. */ + *ticks_to_next_event = NRF_RTC_COUNTER_MAX + 1U - cntr; + result = true; } -#endif -#if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) + + for (uint32_t chan = 0; chan < NRF_RTC_CC_COUNT_MAX; chan++) { + if ((selected_cc_mask & (1U << chan)) && + (reg_intenset & NRF_RTC_CHANNEL_INT_MASK(chan))) { + /* The CC is in selected mask and is can generate an interrupt. */ + uint32_t cc = nrf_rtc_cc_get(rtc, chan); + uint32_t ticks_to_fire = rtc_counter_sub(cc, cntr); + + if (ticks_to_fire == 0U) { + /* When ticks_to_fire == 0, the event should have been just + * generated the interrupt can be already handled or be pending. + * However the next event is expected to be after counter wraps. + */ + ticks_to_fire = NRF_RTC_COUNTER_MAX + 1U; + } + + if (!result) { + *ticks_to_next_event = ticks_to_fire; + result = true; + } else if (ticks_to_fire < *ticks_to_next_event) { + *ticks_to_next_event = ticks_to_fire; + result = true; + } else { + /* CC that fires no earlier than already found. */ + } + } + } + + return result; +} + +static void rtc_counter_synchronized_get(NRF_RTC_Type *rtc_a, NRF_RTC_Type *rtc_b, + uint32_t *counter_a, uint32_t *counter_b) +{ + do { + *counter_a = nrf_rtc_counter_get(rtc_a); + barrier_dmem_fence_full(); + *counter_b = nrf_rtc_counter_get(rtc_b); + barrier_dmem_fence_full(); + } while (*counter_a != nrf_rtc_counter_get(rtc_a)); +} + +static uint8_t cpu_idle_prepare_monitor_dummy; +static bool cpu_idle_prepare_allows_sleep; + +static void cpu_idle_prepare_monitor_begin(void) +{ + __LDREXB(&cpu_idle_prepare_monitor_dummy); +} + +/* Returns 0 if no exception preempted since the last call to cpu_idle_prepare_monitor_begin. */ +static bool cpu_idle_prepare_monitor_end(void) +{ + /* The value stored is irrelevant. If any exception took place after + * cpu_idle_prepare_monitor_begin, the the local monitor is cleared and + * the store fails returning 1. + * See Arm v8-M Architecture Reference Manual: + * Chapter B9.2 The local monitors + * Chapter B9.4 Exclusive access instructions and the monitors + * See Arm Cortex-M33 Processor Technical Reference Manual + * Chapter 3.5 Exclusive monitor + */ + return __STREXB(0U, &cpu_idle_prepare_monitor_dummy); +} + +void z_arm_on_enter_cpu_idle_prepare(void) +{ + bool ok_to_sleep = true; + + cpu_idle_prepare_monitor_begin(); + + uint32_t rtc_counter = 0U; + uint32_t rtc_ticks_to_next_event = 0U; + uint32_t rtc0_counter = 0U; + uint32_t rtc0_ticks_to_next_event = 0U; + + rtc_counter_synchronized_get(NRF_RTC1, NRF_RTC0, &rtc_counter, &rtc0_counter); + + bool rtc_scheduled = rtc_ticks_to_next_event_get(NRF_RTC1, RTC1_PRETICK_SELECTED_CC_MASK, + rtc_counter, &rtc_ticks_to_next_event); + + if (rtc_ticks_to_next_event_get(NRF_RTC0, RTC0_PRETICK_SELECTED_CC_MASK, rtc0_counter, + &rtc0_ticks_to_next_event)) { + /* An event is scheduled on RTC0. */ + if (!rtc_scheduled) { + rtc_ticks_to_next_event = rtc0_ticks_to_next_event; + rtc_scheduled = true; + } else if (rtc0_ticks_to_next_event < rtc_ticks_to_next_event) { + rtc_ticks_to_next_event = rtc0_ticks_to_next_event; + } else { + /* Event on RTC0 will not happen earlier than already found. */ + } + } + + if (rtc_scheduled) { + static bool rtc_pretick_cc_set_on_time; + /* The pretick should happen 1 tick before the earliest scheduled event + * that can trigger an interrupt. + */ + uint32_t rtc_pretick_cc_val = (rtc_counter + rtc_ticks_to_next_event - 1U) + & NRF_RTC_COUNTER_MAX; + + if (rtc_pretick_cc_val != nrf_rtc_cc_get(NRF_RTC1, RTC1_PRETICK_CC_CHAN)) { + /* The CC for pretick needs to be updated. */ + nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_CC_CHAN, rtc_pretick_cc_val); + + if (rtc_ticks_to_next_event >= NRF_RTC_COUNTER_MAX/2) { + /* Pretick is scheduled so far in the future, assumed on time. */ + rtc_pretick_cc_set_on_time = true; + } else { + /* Let's check if we updated CC on time, so that the CC can + * take effect. + */ + barrier_dmem_fence_full(); + rtc_counter = nrf_rtc_counter_get(NRF_RTC1); + uint32_t pretick_cc_to_counter = + rtc_counter_sub(rtc_pretick_cc_val, rtc_counter); + + if ((pretick_cc_to_counter < 3) || + (pretick_cc_to_counter >= NRF_RTC_COUNTER_MAX/2)) { + /* The COUNTER value is close enough to the expected + * pretick CC or has just expired, so the pretick event + * generation is not guaranteed. + */ + rtc_pretick_cc_set_on_time = false; + } else { + /* The written rtc_pretick_cc is guaranteed to to trigger + * compare event. + */ + rtc_pretick_cc_set_on_time = true; + } + } + } else { + /* The CC for pretick doesn't need to be updated, however + * rtc_pretick_cc_set_on_time still holds if we managed to set it on time. + */ + } + + /* If the CC for pretick is set on time, so the pretick CC event can be reliably + * generated then allow to sleep. Otherwise (the CC for pretick cannot be reliably + * generated, because CC was set very short to it's fire time) sleep not at all. + */ + ok_to_sleep = rtc_pretick_cc_set_on_time; + } else { + /* No events on any RTC timers are scheduled. */ + } + if (ok_to_sleep) { NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] |= IPC_PUBLISH_RECEIVE_EN_Msk; - if (!nrf_rtc_event_check(NRF_RTC0, NRF_RTC_CHANNEL_EVENT_ADDR(3)) && - !nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)) && - !nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN))) { + if (!nrf_rtc_event_check(NRF_RTC1, + NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN))) { NRF_WDT->TASKS_STOP = 1; /* Check if any event did not occur after we checked for * stopping condition. If yes, we might have stopped WDT * when it should be running. Restart it. */ - if (nrf_rtc_event_check(NRF_RTC0, NRF_RTC_CHANNEL_EVENT_ADDR(3)) || - nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)) || - nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN))) { + if (nrf_rtc_event_check(NRF_RTC1, + NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN))) { NRF_WDT->TASKS_START = 1; } } } + + cpu_idle_prepare_allows_sleep = ok_to_sleep; +} +#endif /* CONFIG_SOC_NRF53_RTC_PRETICK && CONFIG_SOC_NRF5340_CPUNET */ + +bool z_arm_on_enter_cpu_idle(void) +{ + bool ok_to_sleep = true; + +#if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) + if (cpu_idle_prepare_monitor_end() == 0) { + /* No exception happened since cpu_idle_prepare_monitor_begin. + * We can trust the outcome of. z_arm_on_enter_cpu_idle_prepare + */ + ok_to_sleep = cpu_idle_prepare_allows_sleep; + } else { + /* Exception happened since cpu_idle_prepare_monitor_begin. + * The values which z_arm_on_enter_cpu_idle_prepare could be changed + * by the exception, so we can not trust to it's outcome. + * Do not sleep at all, let's try in the next iteration of idle loop. + */ + ok_to_sleep = false; + } +#endif + + if (ok_to_sleep) { + ok_to_sleep = nrf53_anomaly_160_check(); + +#if (LOG_LEVEL >= LOG_LEVEL_DBG) + static bool suppress_message; + + if (ok_to_sleep) { + suppress_message = false; + } else if (!suppress_message) { + LOG_DBG("Anomaly 160 trigger conditions detected."); + suppress_message = true; + } +#endif + } + +#if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) + if (!ok_to_sleep) { + NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] &= + ~IPC_PUBLISH_RECEIVE_EN_Msk; + NRF_WDT->TASKS_STOP = 1; + } #endif return ok_to_sleep; @@ -212,25 +417,12 @@ void rtc_pretick_rtc0_isr_hook(void) rtc_pretick_rtc_isr_hook(); } -void rtc_pretick_rtc1_cc0_set_hook(uint32_t val) -{ - nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_CC_CHAN, val - 1); -} - void rtc_pretick_rtc1_isr_hook(void) { rtc_pretick_rtc_isr_hook(); - if (nrf_rtc_event_check(NRF_RTC1, NRF_RTC_EVENT_OVERFLOW)) { - if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { - nrf_rtc_event_clear(NRF_RTC1, - NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); - } - } - if (nrf_rtc_event_check(NRF_RTC1, NRF_RTC_EVENT_COMPARE_0)) { - if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); - } + if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); } } @@ -244,11 +436,8 @@ static int rtc_pretick_cpunet_init(void) uint32_t task_ipc = nrf_ipc_task_address_get(NRF_IPC, ipc_task); uint32_t evt_ipc = nrf_ipc_event_address_get(NRF_IPC, ipc_event); uint32_t task_wdt = nrf_wdt_task_address_get(NRF_WDT, NRF_WDT_TASK_START); - uint32_t evt_mpsl_cc = nrf_rtc_event_address_get(NRF_RTC0, NRF_RTC_EVENT_COMPARE_3); uint32_t evt_cc = nrf_rtc_event_address_get(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); - uint32_t evt_overflow = nrf_rtc_event_address_get(NRF_RTC1, - NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); /* Configure Watchdog to allow stopping. */ nrf_wdt_behaviour_set(NRF_WDT, WDT_CONFIG_STOPEN_Msk | BIT(4)); @@ -267,24 +456,14 @@ static int rtc_pretick_cpunet_init(void) return -ENOMEM; } - /* Setup a PPI connection between RTC "pretick" events and IPC task. */ - if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE)) { - nrfx_gppi_event_endpoint_setup(ppi_ch, evt_mpsl_cc); - } nrfx_gppi_event_endpoint_setup(ppi_ch, evt_cc); - nrfx_gppi_event_endpoint_setup(ppi_ch, evt_overflow); nrfx_gppi_task_endpoint_setup(ppi_ch, task_ipc); nrfx_gppi_event_endpoint_setup(ppi_ch, evt_ipc); nrfx_gppi_task_endpoint_setup(ppi_ch, task_wdt); nrfx_gppi_channels_enable(BIT(ppi_ch)); nrf_rtc_event_enable(NRF_RTC1, NRF_RTC_CHANNEL_INT_MASK(RTC1_PRETICK_CC_CHAN)); - nrf_rtc_event_enable(NRF_RTC1, NRF_RTC_CHANNEL_INT_MASK(RTC1_PRETICK_OVERFLOW_CHAN)); - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); - /* Set event 1 tick before overflow. */ - nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_OVERFLOW_CHAN, 0x00FFFFFF); return 0; } @@ -292,7 +471,6 @@ static int rtc_pretick_cpunet_init(void) static int rtc_pretick_init(void) { - ARG_UNUSED(unused); #ifdef CONFIG_SOC_NRF5340_CPUAPP return rtc_pretick_cpuapp_init(); #else From d4e8b1eeae72a627d38c3cf08736dfe436efdac5 Mon Sep 17 00:00:00 2001 From: Andrzej Kuros Date: Mon, 25 Sep 2023 11:51:15 +0200 Subject: [PATCH 0086/1623] [nrf fromtree] nrf53: pretick with NRF_802154_RADIO_DRIVER MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `SOC_NRF53_RTC_PRETICK` option is now allowed to be used with `NRF_802154_RADIO_DRIVER`. Signed-off-by: Andrzej Kuroś (cherry picked from commit d44e96e486ae442d523c3b88ba1ec39b6d5891bd) (cherry picked from commit 01d3f9bba6f9f36374014915e9afbb4cb28d232c) --- drivers/timer/Kconfig.nrf_rtc | 1 + soc/arm/nordic_nrf/nrf53/Kconfig.soc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/timer/Kconfig.nrf_rtc b/drivers/timer/Kconfig.nrf_rtc index cda05d4dabe..acb6f123afe 100644 --- a/drivers/timer/Kconfig.nrf_rtc +++ b/drivers/timer/Kconfig.nrf_rtc @@ -19,6 +19,7 @@ if NRF_RTC_TIMER config NRF_RTC_TIMER_USER_CHAN_COUNT int "Additional channels that can be used" + default 2 if NRF_802154_RADIO_DRIVER && SOC_NRF5340_CPUNET default 3 if NRF_802154_RADIO_DRIVER default 0 help diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 9bb4caf2bb9..2ad4a7add66 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -51,7 +51,6 @@ config SOC_NRF53_ANOMALY_160_WORKAROUND config SOC_NRF53_RTC_PRETICK bool "Pre-tick workaround for nRF5340 anomaly 165" - depends on !NRF_802154_RADIO_DRIVER select NRFX_DPPI select ARM_ON_ENTER_CPU_IDLE_HOOK if SOC_NRF5340_CPUNET select ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK if SOC_NRF5340_CPUNET @@ -202,6 +201,7 @@ config NRF53_SYNC_RTC_INIT_PRIORITY nRF53 Synchronized RTC initialization priority. config NRF_RTC_TIMER_USER_CHAN_COUNT + default 2 if NRF_802154_RADIO_DRIVER && SOC_NRF5340_CPUNET default 3 if NRF_802154_RADIO_DRIVER default 1 From 09bcf9d88014ee367f0db56ff244754b306efe31 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Tue, 5 Sep 2023 13:37:04 +0300 Subject: [PATCH 0087/1623] [nrf fromtree] test: lwm2m: Fix minor timing issue RD client tests work well on emulated (fast) environments but tend to fail on real HW with real time sleeps. This change refactors wait_for_service() to be a bit more syncronous on background service, instead of relying hardcoded sleeps. Fixes #61824 Signed-off-by: Seppo Takalo (cherry picked from commit 4798187801104fc3aa991617bdf1e9d730b00ca3) (cherry picked from commit 4f66f8223ae5c6c79a79d8a6c7532cb80145527a) --- tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt | 2 +- tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt b/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt index 5f29bdad0dd..81e129c56c1 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt @@ -23,7 +23,7 @@ add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_ENDPOINT_NAME_MAX_LENGTH=32) add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_MAX_RETRIES=2) add_compile_definitions(CONFIG_LWM2M_COAP_BLOCK_SIZE=256) add_compile_definitions(CONFIG_LWM2M_COAP_MAX_MSG_SIZE=512) -add_compile_definitions(CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=60) +add_compile_definitions(CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=20) add_compile_definitions(CONFIG_LWM2M_SECURITY_INSTANCE_COUNT=1) add_compile_definitions(CONFIG_LWM2M_SECONDS_TO_UPDATE_EARLY=10) add_compile_definitions(CONFIG_LWM2M_QUEUE_MODE_UPTIME=10) diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c index 58f64f4984d..41789e20340 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c @@ -117,10 +117,12 @@ uint16_t counter = RD_CLIENT_MAX_SERVICE_ITERATIONS; struct lwm2m_message *pending_message; void *(*pending_message_cb)(); static bool running; +K_SEM_DEFINE(srv_sem, 0, 1); static void service_work_fn(struct k_work *work) { while (running) { + k_sleep(K_MSEC(10)); if (pending_message != NULL && pending_message_cb != NULL) { pending_message_cb(pending_message); pending_message = NULL; @@ -129,8 +131,9 @@ static void service_work_fn(struct k_work *work) if (next && next < k_uptime_get()) { next = 0; service(NULL); + k_sem_give(&srv_sem); } - k_sleep(K_MSEC(10)); + counter--; /* avoid endless loop if rd client is stuck somewhere */ @@ -143,10 +146,8 @@ static void service_work_fn(struct k_work *work) void wait_for_service(uint16_t cycles) { - uint16_t end = counter - cycles; - - while (counter > end) { - k_sleep(K_MSEC(10)); + while (cycles--) { + k_sem_take(&srv_sem, K_MSEC(100)); } } @@ -157,6 +158,7 @@ void test_lwm2m_engine_start_service(void) running = true; counter = RD_CLIENT_MAX_SERVICE_ITERATIONS; k_work_submit(&service_work); + k_sem_reset(&srv_sem); } void test_lwm2m_engine_stop_service(void) From 8ff85348030453c3562bf8edcc4f9a583f168f22 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Mon, 11 Sep 2023 15:23:53 +0300 Subject: [PATCH 0088/1623] [nrf fromtree] net: lwm2m: Add timeouts to state machine Allow certain RD-client states to timeout. As stated in LwM2M specification: The bootstrap procedure failed when the LwM2M Client did not receive the "Bootstrap-Finish" operation after the EXCHANGE_LIFETIME time period expired. The EXCHANGE_LIFETIME parameter is defined in RFC 7252 We must handle the case where Bootstrap server is not sending information towards us. Signed-off-by: Seppo Takalo (cherry picked from commit f49309cf52eb97b2f6556ad044c725c595aed2e5) (cherry picked from commit b6b14807f6093988c3d3d6d32c7308322c3d2790) --- subsys/net/lib/lwm2m/lwm2m_rd_client.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.c b/subsys/net/lib/lwm2m/lwm2m_rd_client.c index 0f4405bfc92..fca3f7d560f 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.c +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.c @@ -70,6 +70,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #define CLIENT_QUEUE_LEN sizeof("Q") #define DELAY_BEFORE_CLOSING (1 * MSEC_PER_SEC) #define DELAY_FOR_ACK 100U +#define EXCHANGE_LIFETIME 247U static void sm_handle_registration_update_failure(void); static int sm_send_registration_msg(void); @@ -120,6 +121,7 @@ struct lwm2m_rd_client_info { int64_t last_update; int64_t last_tx; int64_t next_event; + int64_t last_state_change; char ep_name[CLIENT_EP_LEN]; char server_ep[CLIENT_EP_LEN]; @@ -172,6 +174,7 @@ void engine_update_tx_time(void) static void next_event_at(int64_t timestamp) { + client.next_event = timestamp; (void)lwm2m_engine_call_at(lwm2m_rd_client_service, timestamp); } @@ -236,6 +239,7 @@ static void set_sm_state_delayed(uint8_t sm_state, int64_t delay_ms) lwm2m_close_socket(client.ctx); } } + client.last_state_change = k_uptime_get(); next_event_at(k_uptime_get() + delay_ms); k_mutex_unlock(&client.mutex); } @@ -1288,8 +1292,11 @@ static void lwm2m_rd_client_service(struct k_work *work) { k_mutex_lock(&client.mutex, K_FOREVER); + int64_t timeout = 0; + if (client.ctx) { LOG_DBG("State: %d", get_sm_state()); + client.next_event = INT64_MAX; switch (get_sm_state()) { case ENGINE_IDLE: if (client.ctx->sock_fd > -1) { @@ -1312,10 +1319,12 @@ static void lwm2m_rd_client_service(struct k_work *work) case ENGINE_BOOTSTRAP_REG_SENT: /* wait for bootstrap registration done */ + timeout = EXCHANGE_LIFETIME; break; case ENGINE_BOOTSTRAP_REG_DONE: /* wait for transfer done */ + timeout = EXCHANGE_LIFETIME; break; case ENGINE_BOOTSTRAP_TRANS_DONE: @@ -1333,6 +1342,7 @@ static void lwm2m_rd_client_service(struct k_work *work) case ENGINE_REGISTRATION_SENT: /* wait registration to be done or timeout */ + timeout = EXCHANGE_LIFETIME; break; case ENGINE_REGISTRATION_DONE: @@ -1346,6 +1356,7 @@ static void lwm2m_rd_client_service(struct k_work *work) case ENGINE_UPDATE_SENT: /* wait update to be done or abort */ + timeout = EXCHANGE_LIFETIME; break; case ENGINE_DEREGISTER: @@ -1354,6 +1365,7 @@ static void lwm2m_rd_client_service(struct k_work *work) case ENGINE_DEREGISTER_SENT: /* wait for deregister to be done or reset */ + timeout = EXCHANGE_LIFETIME; break; case ENGINE_DEREGISTERED: @@ -1369,6 +1381,17 @@ static void lwm2m_rd_client_service(struct k_work *work) LOG_ERR("Unhandled state: %d", get_sm_state()); } + + if (timeout) { + int64_t end = client.last_state_change + timeout * MSEC_PER_SEC; + + if (end < k_uptime_get()) { + LOG_DBG("State machine have timed out"); + sm_handle_timeout_state(NULL, ENGINE_INIT); + } else if (client.next_event > end) { + next_event_at(end); + } + } } k_mutex_unlock(&client.mutex); From 2a642c8d8dace1cfe3ea52f80dcfd41bd0832d92 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Tue, 12 Sep 2023 11:39:37 +0300 Subject: [PATCH 0089/1623] [nrf fromtree] net: lwm2m: Allow Bootstrap server to close DTLS connection Allow Bootstrap server to close the DTLS connection immediately after receiving Ack to Bootstrap-Finish command. This is not an error as either parties are allowed to tear down the connection. Signed-off-by: Seppo Takalo (cherry picked from commit da1463756ebe524b3fcaa40b2a3c3fde32bd2592) (cherry picked from commit 73235503bfc6edc503ce988a3ecef49ab11a1aeb) --- subsys/net/lib/lwm2m/lwm2m_rd_client.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.c b/subsys/net/lib/lwm2m/lwm2m_rd_client.c index fca3f7d560f..feebcaeea17 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.c +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.c @@ -89,12 +89,10 @@ static void set_sm_state(uint8_t sm_state); enum sm_engine_state { ENGINE_IDLE, ENGINE_INIT, -#if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) ENGINE_DO_BOOTSTRAP_REG, ENGINE_BOOTSTRAP_REG_SENT, ENGINE_BOOTSTRAP_REG_DONE, ENGINE_BOOTSTRAP_TRANS_DONE, -#endif ENGINE_DO_REGISTRATION, ENGINE_SEND_REGISTRATION, ENGINE_REGISTRATION_SENT, @@ -355,14 +353,20 @@ static void sm_handle_failure_state(enum sm_engine_state sm_state) static void socket_fault_cb(int error) { LOG_ERR("RD Client socket error: %d", error); + lwm2m_socket_close(client.ctx); - if (sm_is_bootstrap()) { + if (IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) && sm_is_bootstrap()) { client.ctx->sec_obj_inst = -1; /* force full registration */ client.last_update = 0; - } - lwm2m_socket_close(client.ctx); + if (get_sm_state() == ENGINE_BOOTSTRAP_TRANS_DONE) { + /* Ignore the error, some servers close the connection immediately + * after receiving Ack to Bootstrap-Finish command. + */ + return; + } + } /* Network error state causes engine to re-register, * so only trigger that state if we are not stopping the From 2ea372c8833205e30b5986a1567ab48e735f1726 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Wed, 20 Sep 2023 10:08:50 +0300 Subject: [PATCH 0090/1623] [nrf fromtree] net: lwm2m: Fix build warning on access-control object With bootstrap one function is unused. Fix by changing ifdef to if (IS_ENABLED()) so linker can drop it. Signed-off-by: Seppo Takalo (cherry picked from commit d8d81a8075679cb04b8706de873ecfa1ae9ce438) (cherry picked from commit 777cc86cbb16a45f588bc1ee57cad605b75c0ac4) --- subsys/net/lib/lwm2m/lwm2m_obj_access_control.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_access_control.c b/subsys/net/lib/lwm2m/lwm2m_obj_access_control.c index 1a83ef5ad29..383dbe9b539 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_access_control.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_access_control.c @@ -432,10 +432,10 @@ static int ac_control_init(void) ac_obj.create_cb = ac_create; lwm2m_register_obj(&ac_obj); -#if !IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) - /* add the objects/object instances that were created before the ac control object */ - add_existing_objects(); -#endif /* CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP */ + if (!IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)) { + /* add the objects/object instances that were created before the ac control */ + add_existing_objects(); + } return 0; } From 98a073881f16b6f656f52c697e333a38a25c0d3d Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Wed, 20 Sep 2023 13:26:41 +0300 Subject: [PATCH 0091/1623] [nrf fromtree] net: lwm2m: Don't allow operations on security object In spec: The LwM2M Client MUST reject any LwM2M Server operation on the Security Object (ID: 0) with an "4.01 Unauthorized" response code. Signed-off-by: Seppo Takalo (cherry picked from commit b0303f5bd37bb1af8152a6910f70fbd569724ebb) (cherry picked from commit f2b8747d0ec91cb8d24fc4d923b0684a0ded77de) --- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 952a3d9c130..1a7d023ceb2 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -2330,6 +2330,11 @@ int handle_request(struct coap_packet *request, struct lwm2m_message *msg) goto error; } #endif + if (msg->path.obj_id == LWM2M_OBJECT_SECURITY_ID && !msg->ctx->bootstrap_mode) { + r = -EACCES; + goto error; + } + switch (msg->operation) { case LWM2M_OP_READ: From 52d120825d49c1d37430162fbf9c1d4a8edd1bb9 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Tue, 19 Sep 2023 10:27:22 +0300 Subject: [PATCH 0092/1623] [nrf fromtree] net: lwm2m: Add shell command to create object instances Some testcases might need to be able to create object instances, so add shell command for it. Signed-off-by: Seppo Takalo (cherry picked from commit 0a982c3617dbc7e98bfa51357c8644fe3e44ae4f) (cherry picked from commit 8b2651be500988d68c15a6000046c5c90335a6a1) --- subsys/net/lib/lwm2m/lwm2m_shell.c | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/subsys/net/lib/lwm2m/lwm2m_shell.c b/subsys/net/lib/lwm2m/lwm2m_shell.c index f8374eb34f2..2a86aa88d69 100644 --- a/subsys/net/lib/lwm2m/lwm2m_shell.c +++ b/subsys/net/lib/lwm2m/lwm2m_shell.c @@ -40,6 +40,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); "-sX\tWrite value as intX_t\n" \ "-f \tWrite value as float\n" \ "-t \tWrite value as time_t\n" +#define LWM2M_HELP_CREATE "Create object instance\ncreate PATH\n" #define LWM2M_HELP_START "Start the LwM2M RD (Registration / Discovery) Client\n" \ "start EP_NAME [BOOTSTRAP FLAG]\n" \ "-b \tSet the bootstrap flag (default 0)\n" @@ -372,6 +373,40 @@ static int cmd_write(const struct shell *sh, size_t argc, char **argv) return 0; } +static int cmd_create(const struct shell *sh, size_t argc, char **argv) +{ + struct lwm2m_obj_path path; + struct lwm2m_engine_obj_inst *obj_inst; + int ret; + + if (argc < 2) { + shell_error(sh, "No object ID given\n"); + shell_help(sh); + return -EINVAL; + } + + ret = lwm2m_string_to_path(argv[1], &path, '/'); + if (ret < 0) { + shell_error(sh, "failed to read path (%d)\n", ret); + return -ENOEXEC; + } + + if (path.level != LWM2M_PATH_LEVEL_OBJECT_INST) { + shell_error(sh, "path is not an object instance\n"); + shell_help(sh); + return -EINVAL; + } + + ret = lwm2m_create_obj_inst(path.obj_id, path.obj_inst_id, &obj_inst); + if (ret < 0) { + shell_error(sh, "Failed to create object instance %d/%d, ret=%d", path.obj_id, + path.obj_inst_id, ret); + return -ENOEXEC; + } + + return 0; +} + static int cmd_start(const struct shell *sh, size_t argc, char **argv) { struct lwm2m_ctx *ctx = lwm2m_rd_client_ctx(); @@ -561,6 +596,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD_ARG(exec, NULL, LWM2M_HELP_EXEC, cmd_exec, 2, 1), SHELL_CMD_ARG(read, NULL, LWM2M_HELP_READ, cmd_read, 2, 1), SHELL_CMD_ARG(write, NULL, LWM2M_HELP_WRITE, cmd_write, 3, 1), + SHELL_CMD_ARG(create, NULL, LWM2M_HELP_CREATE, cmd_create, 2, 0), SHELL_CMD_ARG(start, NULL, LWM2M_HELP_START, cmd_start, 2, 2), SHELL_CMD_ARG(stop, NULL, LWM2M_HELP_STOP, cmd_stop, 1, 1), SHELL_CMD_ARG(update, NULL, LWM2M_HELP_UPDATE, cmd_update, 1, 0), From 70a65804527ea66bf30a353d12ab4a348cf54cd8 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 1 Jun 2023 12:00:44 +0300 Subject: [PATCH 0093/1623] [nrf fromtree] net: lwm2m: Add functional tests for LwM2M against Leshan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the new Pytest integration to run testcases against Leshan. Test with: twister -T tests/net/lib/lwm2m/functional -p native_posix -vv This requires Leshan running in localhost using following setup: tcp/8080 Leshan web interface and REST API tcp/8081 Leshan bootstrap server REST API udp/5683 Leshan non-secure CoAP udp/5684 Leshan DTLS CoAP udp/5783 non-secure Bootstrap CoAP udp/5684 DTLS Bootstrap CoAP Leshan and Boostrap server must be reachable from native_posix run using IP address 192.0.2.2 as in most of the examples. Tests are written from test spec; OMA Enabler Test Specification (Interoperability) for Lightweight M2M Following tests are implemented in this commit: * LightweightM2M-1.1-int-0 – Client Initiated Bootstrap * LightweightM2M-1.1-int-1 – Client Initiated Bootstrap Full (PSK) * LightweightM2M-1.1-int-101 – Initial Registration * LightweightM2M-1.1-int-102 – Registration Update * LightweightM2M-1.1-int-104 – Registration Update Trigge * LightweightM2M-1.1-int-105 - Discarded Register Update * LightweightM2M-1.1-int-107 – Extending the lifetime of a registration * LightweightM2M-1.1-int-108 – Turn on Queue Mode * LightweightM2M-1.1-int-109 – Behavior in Queue Mode * LightweightM2M-1.1-int-201 – Querying basic information in Plain Text * LightweightM2M-1.1-int-203 – Querying basic information in TLV format * LightweightM2M-1.1-int-204 – Querying basic information in JSON format * LightweightM2M-1.1-int-205 – Setting basic information in Plain Text * LightweightM2M-1.1-int-211 – Querying basic information in CBOR format * LightweightM2M-1.1-int-212 – Setting basic information in CBOR format * LightweightM2M-1.1-int-215 – Setting basic information in TLV format * LightweightM2M-1.1-int-220 – Setting basic information in JSON format * LightweightM2M-1.1-int-221 – Attempt to perform operations on Security * LightweightM2M-1.1-int-401 – UDP Channel Security – PSK Mode Signed-off-by: Seppo Takalo (cherry picked from commit 7b4f22edd17acafa55add96da96cdae6d90ce973) (cherry picked from commit 66b555d0b5c8d2d6209319a0ea4fe48c5dd7807d) --- tests/net/lib/lwm2m/interop/CMakeLists.txt | 10 + tests/net/lib/lwm2m/interop/README.md | 103 ++++ .../lwm2m/interop/boards/native_posix.conf | 7 + .../lwm2m/interop/boards/qemu_cortex_m3.conf | 20 + tests/net/lib/lwm2m/interop/prj.conf | 90 ++++ tests/net/lib/lwm2m/interop/pytest/leshan.py | 104 ++++ .../lib/lwm2m/interop/pytest/test_lwm2m.py | 446 ++++++++++++++++++ tests/net/lib/lwm2m/interop/requirements.txt | 1 + .../net/lib/lwm2m/interop/src/lwm2m-client.c | 171 +++++++ tests/net/lib/lwm2m/interop/testcase.yaml | 14 + 10 files changed, 966 insertions(+) create mode 100644 tests/net/lib/lwm2m/interop/CMakeLists.txt create mode 100644 tests/net/lib/lwm2m/interop/README.md create mode 100644 tests/net/lib/lwm2m/interop/boards/native_posix.conf create mode 100644 tests/net/lib/lwm2m/interop/boards/qemu_cortex_m3.conf create mode 100644 tests/net/lib/lwm2m/interop/prj.conf create mode 100644 tests/net/lib/lwm2m/interop/pytest/leshan.py create mode 100644 tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py create mode 100644 tests/net/lib/lwm2m/interop/requirements.txt create mode 100644 tests/net/lib/lwm2m/interop/src/lwm2m-client.c create mode 100644 tests/net/lib/lwm2m/interop/testcase.yaml diff --git a/tests/net/lib/lwm2m/interop/CMakeLists.txt b/tests/net/lib/lwm2m/interop/CMakeLists.txt new file mode 100644 index 00000000000..89c4d33e43e --- /dev/null +++ b/tests/net/lib/lwm2m/interop/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(lwm2m_interop_tests) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) + +include(${ZEPHYR_BASE}/samples/net/common/common.cmake) diff --git a/tests/net/lib/lwm2m/interop/README.md b/tests/net/lib/lwm2m/interop/README.md new file mode 100644 index 00000000000..858f5007f64 --- /dev/null +++ b/tests/net/lib/lwm2m/interop/README.md @@ -0,0 +1,103 @@ +# LwM2M Interoperability tests using Leshan demo server + +This directory contains list of testcases that use +the Twister's Pytest integration to run testcases against Leshan demo server. +These tests use emulated hardware (native_posix). + +These tests require setup that is not done in Twister run, so follow this documentation to set +up the test environment. + +## Network setup + +As with typical network samples, host machine uses IP address `192.0.2.2` and the emulated device +running Zephyr is using address `192.0.2.1`. + +Follow [Networking with the host system](https://docs.zephyrproject.org/latest/connectivity/networking/networking_with_host.html#networking-with-the-host-system) +from Zephyr's documentation how to set it up, or follow [Create NAT and routing for Zephyr native network on Linux](https://github.com/zephyrproject-rtos/net-tools/blob/master/README%20NAT.md). + +### Leshan server setup + +* Leshan server must be reachable from the device using IP address `192.0.2.2`. + Configure the port forwarding, if you use Docker to run Leshan. +* Leshan demo server REST API must be reachable from localhost. +* tcp/8080 Leshan web interface and REST API +* tcp/8081 Leshan bootstrap server REST API +* udp/5683 Leshan non-secure CoAP +* udp/5684 Leshan DTLS CoAP +* udp/5783 non-secure Bootstrap CoAP +* udp/5684 DTLS Bootstrap CoAP +* Download Leshan JAR file from https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-server-demo.jar +* Download Leshan Bootstrap server JAR file from https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-bsserver-demo.jar + +Both server can be started like this: +``` +java -jar ./leshan-server-demo.jar -wp 8080 -vv +java -jar ./leshan-bsserver-demo.jar -lp=5783 -slp=5784 -wp 8081 +``` + +Or create a helper script that does everything, including download: +``` +#!/bin/sh -eu + +# Download Leshan if needed +if [ ! -f leshan-server-demo.jar ]; then + wget https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-server-demo.jar +fi + +if [ ! -f leshan-bsserver-demo.jar ]; then + wget 'https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-bsserver-demo.jar' +fi + +mkdir -p log + +start-stop-daemon --make-pidfile --pidfile log/leshan.pid --chdir $(pwd) --background --start \ + --startas /bin/bash -- -c "exec java -jar ./leshan-server-demo.jar -wp 8080 -vv --models-folder objects >log/leshan.log 2>&1" + +start-stop-daemon --make-pidfile --pidfile log/leshan_bs.pid --chdir $(pwd) --background --start \ + --startas /bin/bash -- -c "exec java -jar ./leshan-bsserver-demo.jar -lp=5783 -slp=5784 -wp 8081 -vv >log/leshan_bs.log 2>&1" +``` + +Then stopping would require similar script: +``` +#!/bin/sh -eu + +start-stop-daemon --remove-pidfile --pidfile log/leshan.pid --stop +start-stop-daemon --remove-pidfile --pidfile log/leshan_bs.pid --stop +``` + +## Python package requirements + +These tests require extra package that is not installed when you follow the Zephyr's setup. +Install with `pip install CoAPthon3` + +## Running tests + +``` +twister -p native_posix -vv --enable-slow -T tests/net/lib/lwm2m/interop +`````` + +## Test specification + +Tests are written from test spec; +[OMA Enabler Test Specification (Interoperability) for Lightweight M2M](https://www.openmobilealliance.org/release/LightweightM2M/ETS/OMA-ETS-LightweightM2M-V1_1-20190912-D.pdf) + +Following tests are implemented: +* LightweightM2M-1.1-int-0 – Client Initiated Bootstrap +* LightweightM2M-1.1-int-1 – Client Initiated Bootstrap Full (PSK) +* LightweightM2M-1.1-int-101 – Initial Registration +* LightweightM2M-1.1-int-102 – Registration Update +* LightweightM2M-1.1-int-104 – Registration Update Trigge +* LightweightM2M-1.1-int-105 - Discarded Register Update +* LightweightM2M-1.1-int-107 – Extending the lifetime of a registration +* LightweightM2M-1.1-int-108 – Turn on Queue Mode +* LightweightM2M-1.1-int-109 – Behavior in Queue Mode +* LightweightM2M-1.1-int-201 – Querying basic information in Plain Text +* LightweightM2M-1.1-int-203 – Querying basic information in TLV format +* LightweightM2M-1.1-int-204 – Querying basic information in JSON format +* LightweightM2M-1.1-int-205 – Setting basic information in Plain Text +* LightweightM2M-1.1-int-211 – Querying basic information in CBOR format +* LightweightM2M-1.1-int-212 – Setting basic information in CBOR format +* LightweightM2M-1.1-int-215 – Setting basic information in TLV format +* LightweightM2M-1.1-int-220 – Setting basic information in JSON format +* LightweightM2M-1.1-int-221 – Attempt to perform operations on Security +* LightweightM2M-1.1-int-401 – UDP Channel Security – PSK Mode diff --git a/tests/net/lib/lwm2m/interop/boards/native_posix.conf b/tests/net/lib/lwm2m/interop/boards/native_posix.conf new file mode 100644 index 00000000000..44346db12ed --- /dev/null +++ b/tests/net/lib/lwm2m/interop/boards/native_posix.conf @@ -0,0 +1,7 @@ +CONFIG_DNS_RESOLVER=y +CONFIG_DNS_SERVER_IP_ADDRESSES=y +CONFIG_DNS_SERVER1="192.0.2.2" +CONFIG_LWM2M_DNS_SUPPORT=y +CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2" +CONFIG_NATIVE_POSIX_SLOWDOWN_TO_REAL_TIME=y +CONFIG_NATIVE_UART_0_ON_STDINOUT=y diff --git a/tests/net/lib/lwm2m/interop/boards/qemu_cortex_m3.conf b/tests/net/lib/lwm2m/interop/boards/qemu_cortex_m3.conf new file mode 100644 index 00000000000..7a3fd344e50 --- /dev/null +++ b/tests/net/lib/lwm2m/interop/boards/qemu_cortex_m3.conf @@ -0,0 +1,20 @@ +CONFIG_NET_L2_ETHERNET=y +CONFIG_ETH_DRIVER=y +CONFIG_ETH_STELLARIS=y +CONFIG_NET_QEMU_ETHERNET=y + +# RAM/ROM tuning +CONFIG_IDLE_STACK_SIZE=128 +CONFIG_MBEDTLS_HEAP_SIZE=7000 +CONFIG_ISR_STACK_SIZE=512 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1024 +CONFIG_LWM2M_ENGINE_STACK_SIZE=2000 +CONFIG_LWM2M_LOG_LEVEL_INF=y +CONFIG_LWM2M_ENGINE_MAX_MESSAGES=3 +CONFIG_LWM2M_ENGINE_VALIDATION_BUFFER_SIZE=0 +CONFIG_LWM2M_ENGINE_MAX_OBSERVER=5 +CONFIG_LWM2M_SECURITY_DTLS_TLS_CIPHERSUITE_MAX=3 +CONFIG_LWM2M_DEVICE_PWRSRC_MAX=2 +CONFIG_LWM2M_DEVICE_ERROR_CODE_MAX=5 +CONFIG_LWM2M_DEVICE_EXT_DEV_INFO_MAX=2 +CONFIG_LWM2M_NUM_ATTR=10 diff --git a/tests/net/lib/lwm2m/interop/prj.conf b/tests/net/lib/lwm2m/interop/prj.conf new file mode 100644 index 00000000000..5d255e0513e --- /dev/null +++ b/tests/net/lib/lwm2m/interop/prj.conf @@ -0,0 +1,90 @@ +CONFIG_NETWORKING=y +CONFIG_LOG=y +CONFIG_LWM2M_LOG_LEVEL_DBG=y +CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_NET_IPV6=y +CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 +CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2 +CONFIG_NET_IPV4=y +CONFIG_NET_DHCPV4=n +CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=3 +CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT=2 +CONFIG_PRINTK=y +CONFIG_NET_PKT_RX_COUNT=10 +CONFIG_NET_PKT_TX_COUNT=10 +CONFIG_NET_BUF_RX_COUNT=10 +CONFIG_NET_BUF_TX_COUNT=10 +CONFIG_NET_MAX_CONTEXTS=5 +CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" +CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2" +CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" +CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2" + +CONFIG_NET_LOG=y + +CONFIG_NET_CONFIG_NEED_IPV6=y +CONFIG_NET_CONFIG_NEED_IPV4=y +CONFIG_NET_CONFIG_SETTINGS=y + +CONFIG_LWM2M=y +CONFIG_LWM2M_COAP_BLOCK_SIZE=512 +CONFIG_LWM2M_IPSO_SUPPORT=y +CONFIG_LWM2M_SHELL=y +CONFIG_LWM2M_ACCESS_CONTROL_ENABLE=n + +#Enable Portfolio object +CONFIG_LWM2M_PORTFOLIO_OBJ_SUPPORT=y + +#LwM2M v1.1 configure +CONFIG_LWM2M_VERSION_1_1=y +CONFIG_LWM2M_DTLS_SUPPORT=y +CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP=y + +#Enable SenML JSON content format +CONFIG_JSON_LIBRARY=y +CONFIG_BASE64=y +CONFIG_LWM2M_RW_SENML_JSON_SUPPORT=y + +#Enable SenML CBOR content format +CONFIG_LWM2M_RW_SENML_CBOR_SUPPORT=y +CONFIG_LWM2M_RW_SENML_CBOR_RECORDS=60 +CONFIG_ZCBOR_CANONICAL=y + +#Enable legacy content formats +CONFIG_LWM2M_RW_JSON_SUPPORT=y +CONFIG_LWM2M_RW_OMA_TLV_SUPPORT=y + +# Longer endpoint name might be returned in a registration reply +CONFIG_COAP_EXTENDED_OPTIONS_LEN=y +CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=40 + +# Use QUEUE mode by default +CONFIG_LWM2M_QUEUE_MODE_ENABLED=y +CONFIG_LWM2M_QUEUE_MODE_UPTIME=20 + +# LwM2M configuration as OMA-ETS-LightweightM2M_INT-V1_1-20190912-D Configuration 3 +CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=30 +CONFIG_LWM2M_SERVER_DEFAULT_PMIN=1 +CONFIG_LWM2M_SERVER_DEFAULT_PMAX=10 + +CONFIG_MBEDTLS=y +CONFIG_MBEDTLS_TLS_VERSION_1_2=y + +# Special MbedTLS changes +CONFIG_MBEDTLS_ENABLE_HEAP=y +CONFIG_MBEDTLS_HEAP_SIZE=8192 +CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=1500 +CONFIG_MBEDTLS_CIPHER_CCM_ENABLED=y + +# Disable RSA, we don't parse certs: saves flash/memory +CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED=n +# Enable PSK instead +CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED=y + +CONFIG_NET_SOCKETS_SOCKOPT_TLS=y +CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=4 +CONFIG_NET_SOCKETS_ENABLE_DTLS=y + +# MbedTLS needs a larger stack +CONFIG_MAIN_STACK_SIZE=2048 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 diff --git a/tests/net/lib/lwm2m/interop/pytest/leshan.py b/tests/net/lib/lwm2m/interop/pytest/leshan.py new file mode 100644 index 00000000000..4d69a3a977f --- /dev/null +++ b/tests/net/lib/lwm2m/interop/pytest/leshan.py @@ -0,0 +1,104 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +from __future__ import annotations + +import json +import requests +import binascii + +class Leshan: + def __init__(self, url: str): + self.api_url = url + self.timeout = 10 + self.format = 'TLV' + # self.format = "SENML_CBOR" + try: + resp = self.get('/security/clients') + if not isinstance(resp, list): + raise RuntimeError('Did not receive list of endpoints') + except requests.exceptions.ConnectionError: + raise RuntimeError('Leshan not responding') + + @staticmethod + def handle_response(resp: requests.models.Response): + """Generic response handler for all queries""" + if resp.status_code >= 300 or resp.status_code < 200: + raise RuntimeError(f'Error {resp.status_code}: {resp.text}') + if len(resp.text): + obj = json.loads(resp.text) + return obj + else: + return None + + def get(self, path: str): + """Send HTTP GET query""" + resp = requests.get(f'{self.api_url}{path}?timeout={self.timeout}&format={self.format}') + return Leshan.handle_response(resp) + + def put_raw(self, path: str, data: str | dict | None = None, headers: dict | None = None): + resp = requests.put(f'{self.api_url}{path}', data=data, headers=headers) + return Leshan.handle_response(resp) + + def put(self, path: str, data: str | dict, uri_options: str = ''): + if isinstance(data, dict): + data = json.dumps(data) + return self.put_raw(f'{path}?timeout={self.timeout}&format={self.format}' + uri_options, data=data, headers={'content-type': 'application/json'}) + + def post(self, path: str, data: str | dict | None = None): + resp = requests.post(f'{self.api_url}{path}', data=data, headers={'content-type': 'application/json'}) + return Leshan.handle_response(resp) + + def delete(self, path: str): + resp = requests.delete(f'{self.api_url}{path}') + return Leshan.handle_response(resp) + + def execute(self, endpoint: str, path: str): + return self.post(f'/clients/{endpoint}/{path}') + + def write(self, endpoint: str, path: str, value: bool | int | str): + if isinstance(value, bool): + type = 'boolean' + value = "true" if value else "false" + elif isinstance(value, int): + type = 'integer' + value = str(value) + elif isinstance(value, str): + type = 'string' + value = '"' + value + '"' + id = path.split('/')[2] + return self.put(f'/clients/{endpoint}/{path}', f'{{"id":{id},"kind":"singleResource","value":{value},"type":"{type}"}}') + + def read(self, endpoint: str, path: str): + resp = self.get(f'/clients/{endpoint}/{path}') + if not resp['success']: + return resp + content = resp['content'] + if content['kind'] == 'instance': + return content['resources'] + elif content['kind'] == 'singleResource': + return content['value'] + elif content['kind'] == 'multiResource': + return content['values'] + raise RuntimeError(f'Unhandled type {content["kind"]}') + + def create_psk_device(self, endpoint: str, passwd: str): + psk = binascii.b2a_hex(passwd.encode()).decode() + self.put('/security/clients/', f'{{"endpoint":"{endpoint}","tls":{{"mode":"psk","details":{{"identity":"{endpoint}","key":"{psk}"}} }} }}') + + def delete_device(self, endpoint: str): + self.delete(f'/security/clients/{endpoint}') + + def create_bs_device(self, endpoint: str, server_uri: str, passwd: str): + psk = binascii.b2a_hex(passwd.encode()).decode() + data = f'{{"tls":{{"mode":"psk","details":{{"identity":"{endpoint}","key":"{psk}"}}}},"endpoint":"{endpoint}"}}' + self.put('/security/clients/', data) + id = str([ord(n) for n in endpoint]) + key = str([ord(n) for n in passwd]) + content = '{"servers":{"0":{"binding":"U","defaultMinPeriod":1,"lifetime":86400,"notifIfDisabled":false,"shortId":1}},"security":{"1":{"bootstrapServer":false,"clientOldOffTime":1,"publicKeyOrId":' + id + ',"secretKey":' + key + ',"securityMode":"PSK","serverId":1,"serverSmsNumber":"","smsBindingKeyParam":[],"smsBindingKeySecret":[],"smsSecurityMode":"NO_SEC","uri":"'+server_uri+'"}},"oscore":{},"toDelete":["/0","/1"]}' + self.post(f'/bootstrap/{endpoint}', content) + + def delete_bs_device(self, endpoint: str): + self.delete(f'/security/clients/{endpoint}') + self.delete(f'/bootstrap/{endpoint}') diff --git a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py new file mode 100644 index 00000000000..21ed51ef1e6 --- /dev/null +++ b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py @@ -0,0 +1,446 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +import time +import logging +import pytest +from leshan import Leshan +import os +import binascii +import random +import string + +from twister_harness import Shell + +LESHAN_IP: str = '192.0.2.2' +COAP_PORT: int = 5683 +COAPS_PORT: int = 5684 +BOOTSTRAP_COAPS_PORT: int = 5784 + +logger = logging.getLogger(__name__) + +@pytest.fixture(scope='module') +def helperclient() -> object: + try: + from coapthon.client.helperclient import HelperClient + except ModuleNotFoundError: + pytest.skip('CoAPthon3 package not installed') + return HelperClient(server=('127.0.0.1', COAP_PORT)) + +@pytest.fixture(scope='session') +def leshan() -> Leshan: + try: + return Leshan("http://localhost:8080/api") + except RuntimeError: + pytest.skip('Leshan server not available') + +@pytest.fixture(scope='session') +def leshan_bootstrap() -> Leshan: + try: + return Leshan("http://localhost:8081/api") + except RuntimeError: + pytest.skip('Leshan Bootstrap server not available') + +# +# Test specification: +# https://www.openmobilealliance.org/release/LightweightM2M/ETS/OMA-ETS-LightweightM2M-V1_1-20190912-D.pdf +# + +def verify_LightweightM2M_1_1_int_0(shell: Shell): + logger.info("LightweightM2M-1.1-int-0 - Client Initiated Bootstrap") + shell._device.readlines_until(regex='.*Bootstrap started with endpoint', timeout=5.0) + shell._device.readlines_until(regex='.*Bootstrap registration done', timeout=5.0) + shell._device.readlines_until(regex='.*Bootstrap data transfer done', timeout=5.0) + +def verify_LightweightM2M_1_1_int_1(shell: Shell, leshan: Leshan, endpoint: str): + logger.info("LightweightM2M-1.1-int-1 - Client Initiated Bootstrap Full (PSK)") + verify_LightweightM2M_1_1_int_0(shell) + verify_LightweightM2M_1_1_int_101(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_401(shell, leshan, endpoint) + +def verify_LightweightM2M_1_1_int_101(shell: Shell, leshan: Leshan, endpoint: str): + logger.info("LightweightM2M-1.1-int-101 - Initial Registration") + shell._device.readlines_until(regex='.*Registration Done', timeout=5.0) + assert leshan.get(f'/clients/{endpoint}') + +def verify_LightweightM2M_1_1_int_102(shell: Shell, leshan: Leshan, endpoint: str): + logger.info("LightweightM2M-1.1-int-102 - Registration Update") + lines = shell.get_filtered_output(shell.exec_command('lwm2m read 1/0/1 -u32')) + litetime = int(lines[0]) + lifetime = litetime + 10 + start_time = time.time() * 1000 + leshan.write(endpoint, '1/0/1', lifetime) + shell._device.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=5.0) + latest = leshan.get(f'/clients/{endpoint}') + assert latest["lastUpdate"] > start_time + assert latest["lastUpdate"] <= time.time()*1000 + assert latest["lifetime"] == lifetime + shell.exec_command('lwm2m write 1/0/1 -u32 86400') + +def verify_LightweightM2M_1_1_int_103(): + """LightweightM2M-1.1-int-103 - Deregistration""" + # Unsupported. We don't have "disabled" functionality in server object + +def verify_LightweightM2M_1_1_int_104(shell: Shell, leshan: Leshan, endpoint: str): + logger.info("LightweightM2M-1.1-int-104 - Registration Update Trigger") + shell.exec_command('lwm2m update') + shell._device.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=5.0) + leshan.execute(endpoint, '1/0/8') + shell._device.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=5.0) + +def verify_LightweightM2M_1_1_int_105(shell: Shell, leshan: Leshan, endpoint: str, helperclient: object): + logger.info("LightweightM2M-1.1-int-105 - Discarded Register Update") + status = leshan.get(f'/clients/{endpoint}') + if status["secure"]: + logger.debug("Skip, requires non-secure connection") + return + id = status["registrationId"] + assert id + # Fake unregister message + helperclient.delete(f'rd/{id}', timeout=0.1) + helperclient.stop() + time.sleep(1) + shell.exec_command('lwm2m update') + shell._device.readlines_until(regex=r'.*Failed with code 4\.4', timeout=5.0) + shell._device.readlines_until(regex='.*Registration Done', timeout=10.0) + +def verify_LightweightM2M_1_1_int_107(shell: Shell, leshan: Leshan, endpoint: str): + logger.info("LightweightM2M-1.1-int-107 - Extending the lifetime of a registration") + leshan.write(endpoint, '1/0/1', 120) + shell._device.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=5.0) + lines = shell.get_filtered_output(shell.exec_command('lwm2m read 1/0/1 -u32')) + lifetime = int(lines[0]) + assert lifetime == 120 + logger.debug(f'sleeping for {lifetime} s') + shell._device.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=lifetime) + assert leshan.get(f'/clients/{endpoint}') + +def verify_LightweightM2M_1_1_int_108(leshan, endpoint): + logger.info("LightweightM2M-1.1-int-108 - Turn on Queue Mode") + assert leshan.get(f'/clients/{endpoint}')["queuemode"] + +def verify_LightweightM2M_1_1_int_109(shell: Shell, leshan: Leshan, endpoint: str): + logger.info("LightweightM2M-1.1-int-109 - Behavior in Queue Mode") + verify_LightweightM2M_1_1_int_107(shell, leshan, endpoint) + shell._device.readlines_until(regex='.*Queue mode RX window closed', timeout=120) + # Restore previous value + shell.exec_command('lwm2m write 1/0/1 -u32 86400') + shell._device.readlines_until(regex='.*Registration update complete', timeout=10) + +def verify_LightweightM2M_1_1_int_201(shell: Shell, leshan: Leshan, endpoint: str): + + logger.info("LightweightM2M-1.1-int-201 - Querying basic information in Plain Text format") + fmt = leshan.format + leshan.format = 'TEXT' + assert leshan.get(f'/clients/{endpoint}/3/0/0')['content']['value'] == 'Zephyr' + assert leshan.get(f'/clients/{endpoint}/3/0/1')['content']['value'] == 'client-1' + assert leshan.get(f'/clients/{endpoint}/3/0/2')['content']['value'] == 'serial-1' + leshan.format = fmt + +def verify_device_object(resp): + ''' Verify that Device object match Configuration 3 ''' + assert resp['valid'] is True + found = 0 + for res in resp['content']['resources']: + if res['id'] == 0: + assert res['value'] == 'Zephyr' + found += 1 + elif res['id'] == 1: + assert res['value'] == 'client-1' + found += 1 + elif res['id'] == 2: + assert res['value'] == 'serial-1' + found += 1 + elif res['id'] == 3: + assert res['value'] == '1.2.3' + found += 1 + elif res['id'] == 11: + assert res['kind'] == 'multiResource' + assert res['values']['0'] == '0' + found += 1 + elif res['id'] == 16: + assert res['value'] == 'U' + found += 1 + assert found == 6 + +def verify_server_object(obj): + ''' Verify that server object match Configuration 3 ''' + found = 0 + for res in obj['resources']: + if res['id'] == 0: + assert res['value'] == '1' + found += 1 + elif res['id'] == 1: + assert res['value'] == '86400' + found += 1 + elif res['id'] == 2: + assert res['value'] == '1' + found += 1 + elif res['id'] == 3: + assert res['value'] == '10' + found += 1 + elif res['id'] == 5: + assert res['value'] == '86400' + found += 1 + elif res['id'] == 6: + assert res['value'] is False + found += 1 + elif res['id'] == 7: + assert res['value'] == 'U' + found += 1 + assert found == 7 + +def verify_LightweightM2M_1_1_int_203(shell: Shell, leshan: Leshan, endpoint: str): + shell.exec_command('lwm2m update') + logger.info('LightweightM2M-1.1-int-203 - Querying basic information in TLV format') + fmt = leshan.format + leshan.format = 'TLV' + resp = leshan.get(f'/clients/{endpoint}/3/0') + verify_device_object(resp) + leshan.format = fmt + +def verify_LightweightM2M_1_1_int_204(shell: Shell, leshan: Leshan, endpoint: str): + shell.exec_command('lwm2m update') + logger.info('LightweightM2M-1.1-int-204 - Querying basic information in JSON format') + fmt = leshan.format + leshan.format = 'JSON' + resp = leshan.get(f'/clients/{endpoint}/3/0') + verify_device_object(resp) + leshan.format = fmt + +def verify_LightweightM2M_1_1_int_205(shell: Shell, leshan: Leshan, endpoint: str): + logger.info('LightweightM2M-1.1-int-205 - Setting basic information in Plain Text format') + fmt = leshan.format + leshan.format = 'TEXT' + leshan.write(endpoint, '1/0/2', 101) + leshan.write(endpoint, '1/0/3', 1010) + leshan.write(endpoint, '1/0/5', 2000) + assert leshan.read(endpoint, '1/0/2') == '101' + assert leshan.read(endpoint, '1/0/3') == '1010' + assert leshan.read(endpoint, '1/0/5') == '2000' + leshan.write(endpoint, '1/0/2', 1) + leshan.write(endpoint, '1/0/3', 10) + leshan.write(endpoint, '1/0/5', 86400) + assert leshan.read(endpoint, '1/0/2') == '1' + assert leshan.read(endpoint, '1/0/3') == '10' + assert leshan.read(endpoint, '1/0/5') == '86400' + leshan.format = fmt + +def verify_LightweightM2M_1_1_int_211(shell: Shell, leshan: Leshan, endpoint: str): + logger.info('LightweightM2M-1.1-int-211 - Querying basic information in CBOR format') + fmt = leshan.format + leshan.format = 'CBOR' + lines = shell.get_filtered_output(shell.exec_command('lwm2m read 1/0/0 -u16')) + id = lines[0] + assert leshan.read(endpoint, '1/0/0') == id + assert leshan.read(endpoint, '1/0/6') is False + assert leshan.read(endpoint, '1/0/7') == 'U' + leshan.format = fmt + +def verify_LightweightM2M_1_1_int_212(shell: Shell, leshan: Leshan, endpoint: str): + logger.info('LightweightM2M-1.1-int-212 - Setting basic information in CBOR format') + fmt = leshan.format + leshan.format = 'CBOR' + leshan.write(endpoint, '1/0/2', 101) + leshan.write(endpoint, '1/0/3', 1010) + leshan.write(endpoint, '1/0/6', True) + assert leshan.read(endpoint, '1/0/2') == '101' + assert leshan.read(endpoint, '1/0/3') == '1010' + assert leshan.read(endpoint, '1/0/6') is True + leshan.write(endpoint, '1/0/2', 1) + leshan.write(endpoint, '1/0/3', 10) + leshan.write(endpoint, '1/0/6', False) + leshan.format = fmt + +def verify_setting_basic_in_format(shell, leshan, endpoint, format): + fmt = leshan.format + leshan.format = format + server_obj = leshan.get(f'/clients/{endpoint}/1/0')['content'] + verify_server_object(server_obj) + # Remove Read-Only resources, so we don't end up writing those + for res in server_obj['resources']: + if res['id'] in (0, 11, 12): + server_obj['resources'].remove(res) + data = '''{ + "kind": "instance", + "id": 0, + "resources": [ + { + "id": 2, + "kind": "singleResource", + "value": "101", + "type": "integer" + }, + { + "id": 3, + "kind": "singleResource", + "value": "1010", + "type": "integer" + }, + { + "id": 5, + "kind": "singleResource", + "value": "2000", + "type": "integer" + }, + { + "id": 6, + "kind": "singleResource", + "value": true, + "type": "boolean" + }, + { + "id": 7, + "kind": "singleResource", + "value": "U", + "type": "string" + } + ] + }''' + assert leshan.put(f'/clients/{endpoint}/1/0', data, uri_options = '&replace=false')['status'] == 'CHANGED(204)' + resp = leshan.get(f'/clients/{endpoint}/1/0') + assert resp['valid'] is True + found = 0 + for res in resp['content']['resources']: + if res['id'] == 2: + assert res['value'] == '101' + found += 1 + elif res['id'] == 3: + assert res['value'] == '1010' + found += 1 + elif res['id'] == 5: + assert res['value'] == '2000' + found += 1 + elif res['id'] == 6: + assert res['value'] is True + found += 1 + elif res['id'] == 7: + assert res['value'] == 'U' + found += 1 + assert found == 5 + assert leshan.put(f'/clients/{endpoint}/1/0', data = server_obj, uri_options = '&replace=true')['status'] == 'CHANGED(204)' + server_obj = leshan.get(f'/clients/{endpoint}/1/0')['content'] + verify_server_object(server_obj) + leshan.format = fmt + +def verify_LightweightM2M_1_1_int_215(shell: Shell, leshan: Leshan, endpoint: str): + logger.info('LightweightM2M-1.1-int-215 - Setting basic information in TLV format') + verify_setting_basic_in_format(shell, leshan, endpoint, 'TLV') + +def verify_LightweightM2M_1_1_int_220(shell: Shell, leshan: Leshan, endpoint: str): + logger.info('LightweightM2M-1.1-int-220 - Setting basic information in JSON format') + verify_setting_basic_in_format(shell, leshan, endpoint, 'JSON') + +def verify_LightweightM2M_1_1_int_221(shell: Shell, leshan: Leshan, endpoint: str): + logger.info('LightweightM2M-1.1-int-221 - Attempt to perform operations on Security') + assert leshan.read(endpoint, '0/0')['status'] == 'UNAUTHORIZED(401)' + assert leshan.write(endpoint, '0/0/0', 'coap://localhost')['status'] == 'UNAUTHORIZED(401)' + assert leshan.put_raw(f'/clients/{endpoint}/0/attributes?pmin=10')['status'] == 'UNAUTHORIZED(401)' + +def verify_LightweightM2M_1_1_int_401(shell: Shell, leshan: Leshan, endpoint: str): + logger.info("LightweightM2M-1.1-int-401 - UDP Channel Security - Pre-shared Key Mode") + lines = shell.get_filtered_output(shell.exec_command('lwm2m read 0/0/0 -s')) + host = lines[0] + assert 'coaps://' in host + lines = shell.get_filtered_output(shell.exec_command('lwm2m read 0/0/2 -u8')) + mode = int(lines[0]) + assert mode == 0 + resp = leshan.get(f'/clients/{endpoint}') + assert resp["secure"] + +def test_lwm2m_bootstrap_psk(shell: Shell, leshan, leshan_bootstrap): + try: + # Generate randon device id and password (PSK key) + endpoint = 'client_' + binascii.b2a_hex(os.urandom(1)).decode() + passwd = ''.join(random.choice(string.ascii_lowercase) for i in range(16)) + + + # Create device entries in Leshan and Bootstrap server + leshan_bootstrap.create_bs_device(endpoint, f'coaps://{LESHAN_IP}:{COAPS_PORT}', passwd) + leshan.create_psk_device(endpoint, passwd) + + # Allow engine to start & stop once. + time.sleep(2) + + # + # Verify PSK security using Bootstrap + # + + # Write bootsrap server information and PSK keys + shell.exec_command(f'lwm2m write 0/0/0 -s coaps://{LESHAN_IP}:{BOOTSTRAP_COAPS_PORT}') + shell.exec_command('lwm2m write 0/0/1 -b 1') + shell.exec_command('lwm2m write 0/0/2 -u8 0') + shell.exec_command(f'lwm2m write 0/0/3 -s {endpoint}') + shell.exec_command(f'lwm2m write 0/0/5 -s {passwd}') + shell.exec_command(f'lwm2m start {endpoint} -b 1') + + + # + # Bootstrap Interface test cases + # LightweightM2M-1.1-int-0 (included) + # LightweightM2M-1.1-int-401 (included) + verify_LightweightM2M_1_1_int_1(shell, leshan, endpoint) + + # + # Registration Interface test cases (using PSK security) + # + verify_LightweightM2M_1_1_int_102(shell, leshan, endpoint) + # skip, not implemented verify_LightweightM2M_1_1_int_103() + verify_LightweightM2M_1_1_int_104(shell, leshan, endpoint) + # skip, included in 109: verify_LightweightM2M_1_1_int_107(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_108(leshan, endpoint) + verify_LightweightM2M_1_1_int_109(shell, leshan, endpoint) + + # + # Device management & Service Enablement Interface test cases + # + verify_LightweightM2M_1_1_int_201(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_203(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_204(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_205(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_211(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_212(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_215(shell, leshan, endpoint) + + shell.exec_command('lwm2m stop') + shell._device.readlines_until(regex=r'.*Deregistration success', timeout=10.0) + + finally: + # Remove device and bootstrap information + # Leshan does not accept non-secure connection if device information is provided with PSK + leshan.delete_device(endpoint) + leshan_bootstrap.delete_bs_device(endpoint) + + +def test_lwm2m_nosecure(shell: Shell, leshan, helperclient): + + # Allow engine to start & stop once. + time.sleep(2) + + # Generate randon device id and password (PSK key) + endpoint = 'client_' + binascii.b2a_hex(os.urandom(1)).decode() + + # + # Registration Interface test cases (using Non-secure mode) + # + shell.exec_command(f'lwm2m write 0/0/0 -s coap://{LESHAN_IP}:{COAP_PORT}') + shell.exec_command('lwm2m write 0/0/1 -b 0') + shell.exec_command('lwm2m write 0/0/2 -u8 3') + shell.exec_command(f'lwm2m write 0/0/3 -s {endpoint}') + shell.exec_command('lwm2m create 1/0') + shell.exec_command('lwm2m write 0/0/10 -u16 1') + shell.exec_command('lwm2m write 1/0/0 -u16 1') + shell.exec_command('lwm2m write 1/0/1 -u32 86400') + shell.exec_command(f'lwm2m start {endpoint} -b 0') + shell._device.readlines_until(regex=f"RD Client started with endpoint '{endpoint}'", timeout=10.0) + + verify_LightweightM2M_1_1_int_101(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_105(shell, leshan, endpoint, helperclient) # needs no-security + verify_LightweightM2M_1_1_int_215(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_220(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_221(shell, leshan, endpoint) + + # All done + shell.exec_command('lwm2m stop') + shell._device.readlines_until(regex=r'.*Deregistration success', timeout=10.0) diff --git a/tests/net/lib/lwm2m/interop/requirements.txt b/tests/net/lib/lwm2m/interop/requirements.txt new file mode 100644 index 00000000000..38c501218ee --- /dev/null +++ b/tests/net/lib/lwm2m/interop/requirements.txt @@ -0,0 +1 @@ +CoAPthon3 diff --git a/tests/net/lib/lwm2m/interop/src/lwm2m-client.c b/tests/net/lib/lwm2m/interop/src/lwm2m-client.c new file mode 100644 index 00000000000..1278d807b71 --- /dev/null +++ b/tests/net/lib/lwm2m/interop/src/lwm2m-client.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2017 Linaro Limited + * Copyright (c) 2017-2019 Foundries.io + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define LOG_MODULE_NAME net_lwm2m_client_app +#define LOG_LEVEL LOG_LEVEL_DBG + +#include +LOG_MODULE_REGISTER(LOG_MODULE_NAME); +#include +#include +#include +#include +#include +#include + +#define APP_BANNER "Run LWM2M client" + +#define WAIT_TIME K_SECONDS(10) +#define CONNECT_TIME K_SECONDS(10) + +#define NAME "Zephyr" +#define MODEL "client-1" +#define SERIAL "serial-1" +#define VERSION "1.2.3" + +static struct lwm2m_ctx client; + +static int device_reboot_cb(uint16_t obj_inst_id, + uint8_t *args, uint16_t args_len) +{ + LOG_INF("DEVICE: REBOOT"); + return 0; +} + + +static int lwm2m_setup(void) +{ + /* setup DEVICE object */ + + lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 0), NAME, sizeof(NAME), + sizeof(NAME), LWM2M_RES_DATA_FLAG_RO); + lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 1), MODEL, sizeof(MODEL), + sizeof(MODEL), LWM2M_RES_DATA_FLAG_RO); + lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 2), SERIAL, sizeof(SERIAL), + sizeof(SERIAL), LWM2M_RES_DATA_FLAG_RO); + lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 3), VERSION, sizeof(VERSION), + sizeof(VERSION), LWM2M_RES_DATA_FLAG_RO); + lwm2m_register_exec_callback(&LWM2M_OBJ(3, 0, 4), device_reboot_cb); + lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 17), CONFIG_BOARD, sizeof(CONFIG_BOARD), + sizeof(CONFIG_BOARD), LWM2M_RES_DATA_FLAG_RO); + + return 0; +} + +static void rd_client_event(struct lwm2m_ctx *client, + enum lwm2m_rd_client_event client_event) +{ + switch (client_event) { + + case LWM2M_RD_CLIENT_EVENT_NONE: + /* do nothing */ + break; + + case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE: + LOG_DBG("Bootstrap registration failure!"); + break; + + case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_COMPLETE: + LOG_DBG("Bootstrap registration complete"); + break; + + case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_TRANSFER_COMPLETE: + LOG_DBG("Bootstrap transfer complete"); + break; + + case LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE: + LOG_DBG("Registration failure!"); + break; + + case LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE: + LOG_DBG("Registration complete"); + break; + + case LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT: + LOG_DBG("Registration timeout!"); + break; + + case LWM2M_RD_CLIENT_EVENT_REG_UPDATE_COMPLETE: + LOG_DBG("Registration update complete"); + break; + + case LWM2M_RD_CLIENT_EVENT_DEREGISTER_FAILURE: + LOG_DBG("Deregister failure!"); + break; + + case LWM2M_RD_CLIENT_EVENT_DISCONNECT: + LOG_DBG("Disconnected"); + break; + + case LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF: + LOG_DBG("Queue mode RX window closed"); + break; + + case LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED: + LOG_DBG("LwM2M engine suspended"); + break; + + case LWM2M_RD_CLIENT_EVENT_NETWORK_ERROR: + LOG_ERR("LwM2M engine reported a network error."); + lwm2m_rd_client_stop(client, rd_client_event, true); + break; + + case LWM2M_RD_CLIENT_EVENT_REG_UPDATE: + LOG_DBG("Registration update"); + break; + } +} + +static void observe_cb(enum lwm2m_observe_event event, + struct lwm2m_obj_path *path, void *user_data) +{ + char buf[LWM2M_MAX_PATH_STR_SIZE]; + + switch (event) { + + case LWM2M_OBSERVE_EVENT_OBSERVER_ADDED: + LOG_INF("Observer added for %s", lwm2m_path_log_buf(buf, path)); + break; + + case LWM2M_OBSERVE_EVENT_OBSERVER_REMOVED: + LOG_INF("Observer removed for %s", lwm2m_path_log_buf(buf, path)); + break; + + case LWM2M_OBSERVE_EVENT_NOTIFY_ACK: + LOG_INF("Notify acknowledged for %s", lwm2m_path_log_buf(buf, path)); + break; + + case LWM2M_OBSERVE_EVENT_NOTIFY_TIMEOUT: + LOG_INF("Notify timeout for %s, trying registration update", + lwm2m_path_log_buf(buf, path)); + + lwm2m_rd_client_update(); + break; + } +} + +int main(void) +{ + int ret; + +#if defined(CONFIG_BOARD_NATIVE_POSIX) + srandom(time(NULL)); +#endif + + ret = lwm2m_setup(); + if (ret < 0) { + LOG_ERR("Cannot setup LWM2M fields (%d)", ret); + return 0; + } + + client.tls_tag = 1; + + lwm2m_rd_client_start(&client, CONFIG_BOARD, 0, rd_client_event, observe_cb); + lwm2m_rd_client_stop(&client, rd_client_event, false); + + return 0; +} diff --git a/tests/net/lib/lwm2m/interop/testcase.yaml b/tests/net/lib/lwm2m/interop/testcase.yaml new file mode 100644 index 00000000000..aeba64748df --- /dev/null +++ b/tests/net/lib/lwm2m/interop/testcase.yaml @@ -0,0 +1,14 @@ +tests: + net.lwm2m.interop: + harness: pytest + timeout: 300 + slow: true + integration_platforms: + - native_posix + platform_allow: + - native_posix + - qemu_cortex_m3 + tags: + - testing + - pytest + - shell From 79d70889263c4965c760e5835d1b2d1f7e69fbe9 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Tue, 26 Sep 2023 14:06:16 +0300 Subject: [PATCH 0094/1623] [nrf fromtree] net: lwm2m: Clean up shell documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move commands that require parameters first into the list. Move syntax line first, command documentation second, flags last. This is much like Unix commands do ❯ /bin/ls --help Usage: /bin/ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Compared to: uart:~$ lwm2m lwm2m - LwM2M commands Subcommands: read :read PATH [OPTIONS] Read value from LwM2M resource -x Read value as hex stream (default) -s Read value as string Signed-off-by: Seppo Takalo (cherry picked from commit ebfbf831531c182ecd9de6878d6e63f2ec3155cf) (cherry picked from commit 5c8c3d6815e4541ba0f93b433c388c699b8e1da2) --- doc/connectivity/networking/api/lwm2m.rst | 68 ++++++++++++++--------- subsys/net/lib/lwm2m/lwm2m_shell.c | 22 ++++---- 2 files changed, 53 insertions(+), 37 deletions(-) diff --git a/doc/connectivity/networking/api/lwm2m.rst b/doc/connectivity/networking/api/lwm2m.rst index 6d26205511e..c630ea7785a 100644 --- a/doc/connectivity/networking/api/lwm2m.rst +++ b/doc/connectivity/networking/api/lwm2m.rst @@ -633,40 +633,58 @@ required actions from the server side. .. code-block:: console - uart:~$ lwm2m - lwm2m - LwM2M commands - Subcommands: - exec :Execute a resource - exec PATH - - read :Read value from LwM2M resource - read PATH [OPTIONS] - -s Read value as string (default) + uart:~$ lwm2m + lwm2m - LwM2M commands + Subcommands: + send :send PATHS + LwM2M SEND operation + + exec :exec PATH [PARAM] + Execute a resource + + read :read PATH [OPTIONS] + Read value from LwM2M resource + -x Read value as hex stream (default) + -s Read value as string -b Read value as bool (1/0) -uX Read value as uintX_t -sX Read value as intX_t -f Read value as float - - write :Write into LwM2M resource - write PATH [OPTIONS] VALUE - -s Value as string (default) - -b Value as bool - -uX Value as uintX_t - -sX Value as intX_t - -f Value as float - - start :Start the LwM2M RD (Registration / Discovery) Client - start EP_NAME [BOOTSTRAP FLAG] + -t Read value as time_t + + write :write PATH [OPTIONS] VALUE + Write into LwM2M resource + -s Write value as string (default) + -b Write value as bool + -uX Write value as uintX_t + -sX Write value as intX_t + -f Write value as float + -t Write value as time_t + + create :create PATH + Create object instance + + cache :cache PATH NUM + Enable data cache for resource + PATH is LwM2M path + NUM how many elements to cache + + start :start EP_NAME [BOOTSTRAP FLAG] + Start the LwM2M RD (Registration / Discovery) Client -b Set the bootstrap flag (default 0) - stop :Stop the LwM2M RD (De-register) Client - stop [OPTIONS] + stop :stop [OPTIONS] + Stop the LwM2M RD (De-register) Client -f Force close the connection - update :Trigger Registration Update of the LwM2M RD Client + update :Trigger Registration Update of the LwM2M RD Client + + pause :LwM2M engine thread pause + resume :LwM2M engine thread resume + lock :Lock the LwM2M registry + unlock :Unlock the LwM2M registry + - pause :LwM2M engine thread pause - resume :LwM2M engine thread resume .. _lwm2m_api_reference: diff --git a/subsys/net/lib/lwm2m/lwm2m_shell.c b/subsys/net/lib/lwm2m/lwm2m_shell.c index 2a86aa88d69..335004ec5d5 100644 --- a/subsys/net/lib/lwm2m/lwm2m_shell.c +++ b/subsys/net/lib/lwm2m/lwm2m_shell.c @@ -22,10 +22,9 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #define LWM2M_HELP_CMD "LwM2M commands" -#define LWM2M_HELP_SEND "LwM2M SEND operation\nsend [OPTION]... [PATH]...\n" \ - "Root-level operation is unsupported" -#define LWM2M_HELP_EXEC "Execute a resource\nexec PATH [PARAM]\n" -#define LWM2M_HELP_READ "Read value from LwM2M resource\nread PATH [OPTIONS]\n" \ +#define LWM2M_HELP_SEND "send PATHS\nLwM2M SEND operation\n" +#define LWM2M_HELP_EXEC "exec PATH [PARAM]\nExecute a resource\n" +#define LWM2M_HELP_READ "read PATH [OPTIONS]\nRead value from LwM2M resource\n" \ "-x \tRead value as hex stream (default)\n" \ "-s \tRead value as string\n" \ "-b \tRead value as bool (1/0)\n" \ @@ -33,26 +32,25 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); "-sX\tRead value as intX_t\n" \ "-f \tRead value as float\n" \ "-t \tRead value as time_t\n" -#define LWM2M_HELP_WRITE "Write into LwM2M resource\nwrite PATH [OPTIONS] VALUE\n" \ +#define LWM2M_HELP_WRITE "write PATH [OPTIONS] VALUE\nWrite into LwM2M resource\n" \ "-s \tWrite value as string (default)\n" \ "-b \tWrite value as bool\n" \ "-uX\tWrite value as uintX_t\n" \ "-sX\tWrite value as intX_t\n" \ "-f \tWrite value as float\n" \ "-t \tWrite value as time_t\n" -#define LWM2M_HELP_CREATE "Create object instance\ncreate PATH\n" -#define LWM2M_HELP_START "Start the LwM2M RD (Registration / Discovery) Client\n" \ - "start EP_NAME [BOOTSTRAP FLAG]\n" \ +#define LWM2M_HELP_CREATE "create PATH\nCreate object instance\n" +#define LWM2M_HELP_START "start EP_NAME [BOOTSTRAP FLAG]\n" \ + "Start the LwM2M RD (Registration / Discovery) Client\n" \ "-b \tSet the bootstrap flag (default 0)\n" -#define LWM2M_HELP_STOP "Stop the LwM2M RD (De-register) Client\nstop [OPTIONS]\n" \ +#define LWM2M_HELP_STOP "stop [OPTIONS]\nStop the LwM2M RD (De-register) Client\n" \ "-f \tForce close the connection\n" #define LWM2M_HELP_UPDATE "Trigger Registration Update of the LwM2M RD Client\n" #define LWM2M_HELP_PAUSE "LwM2M engine thread pause" #define LWM2M_HELP_RESUME "LwM2M engine thread resume" #define LWM2M_HELP_LOCK "Lock the LwM2M registry" #define LWM2M_HELP_UNLOCK "Unlock the LwM2M registry" -#define LWM2M_HELP_CACHE "Enable data cache for resource\n" \ - "cache PATH NUM\n" \ +#define LWM2M_HELP_CACHE "cache PATH NUM\nEnable data cache for resource\n" \ "PATH is LwM2M path\n" \ "NUM how many elements to cache\n" \ @@ -597,6 +595,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD_ARG(read, NULL, LWM2M_HELP_READ, cmd_read, 2, 1), SHELL_CMD_ARG(write, NULL, LWM2M_HELP_WRITE, cmd_write, 3, 1), SHELL_CMD_ARG(create, NULL, LWM2M_HELP_CREATE, cmd_create, 2, 0), + SHELL_CMD_ARG(cache, NULL, LWM2M_HELP_CACHE, cmd_cache, 3, 0), SHELL_CMD_ARG(start, NULL, LWM2M_HELP_START, cmd_start, 2, 2), SHELL_CMD_ARG(stop, NULL, LWM2M_HELP_STOP, cmd_stop, 1, 1), SHELL_CMD_ARG(update, NULL, LWM2M_HELP_UPDATE, cmd_update, 1, 0), @@ -604,7 +603,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD_ARG(resume, NULL, LWM2M_HELP_RESUME, cmd_resume, 1, 0), SHELL_CMD_ARG(lock, NULL, LWM2M_HELP_LOCK, cmd_lock, 1, 0), SHELL_CMD_ARG(unlock, NULL, LWM2M_HELP_UNLOCK, cmd_unlock, 1, 0), - SHELL_CMD_ARG(cache, NULL, LWM2M_HELP_CACHE, cmd_cache, 3, 0), SHELL_SUBCMD_SET_END); SHELL_COND_CMD_ARG_REGISTER(CONFIG_LWM2M_SHELL, lwm2m, &sub_lwm2m, From 5f6827522ce81d9091dcd0bf43d48e2e45ee1150 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Tue, 8 Aug 2023 13:28:11 +0300 Subject: [PATCH 0095/1623] [nrf fromtree] net: lwm2m: Allow content formats to support only some data types Partial content format support is required to have a proper support for content format OPAQUE instead of threading it as a part of plain text format. Signed-off-by: Seppo Takalo (cherry picked from commit 42ce4bbfd76535765c1837734f39aff805714815) (cherry picked from commit 851b1391623d065bfbfdeb3bfc28219fad102172) --- subsys/net/lib/lwm2m/lwm2m_object.h | 143 ++++++++++++++++++---------- 1 file changed, 91 insertions(+), 52 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_object.h b/subsys/net/lib/lwm2m/lwm2m_object.h index ca8fdf12fd0..05bc818c99c 100644 --- a/subsys/net/lib/lwm2m/lwm2m_object.h +++ b/subsys/net/lib/lwm2m/lwm2m_object.h @@ -705,71 +705,95 @@ static inline int engine_put_end_ri(struct lwm2m_output_context *out, return 0; } -static inline int engine_put_s8(struct lwm2m_output_context *out, - struct lwm2m_obj_path *path, int8_t value) +static inline int engine_put_s8(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, + int8_t value) { - return out->writer->put_s8(out, path, value); + if (out->writer->put_s8) { + return out->writer->put_s8(out, path, value); + } + return -ENOTSUP; } -static inline int engine_put_s16(struct lwm2m_output_context *out, - struct lwm2m_obj_path *path, int16_t value) +static inline int engine_put_s16(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, + int16_t value) { - return out->writer->put_s16(out, path, value); + if (out->writer->put_s16) { + return out->writer->put_s16(out, path, value); + } + return -ENOTSUP; } -static inline int engine_put_s32(struct lwm2m_output_context *out, - struct lwm2m_obj_path *path, int32_t value) +static inline int engine_put_s32(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, + int32_t value) { - return out->writer->put_s32(out, path, value); + if (out->writer->put_s32) { + return out->writer->put_s32(out, path, value); + } + return -ENOTSUP; } -static inline int engine_put_s64(struct lwm2m_output_context *out, - struct lwm2m_obj_path *path, int64_t value) +static inline int engine_put_s64(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, + int64_t value) { - return out->writer->put_s64(out, path, value); + if (out->writer->put_s64) { + return out->writer->put_s64(out, path, value); + } + return -ENOTSUP; } -static inline int engine_put_string(struct lwm2m_output_context *out, - struct lwm2m_obj_path *path, char *buf, - size_t buflen) +static inline int engine_put_string(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, + char *buf, size_t buflen) { - return out->writer->put_string(out, path, buf, buflen); + if (out->writer->put_string) { + return out->writer->put_string(out, path, buf, buflen); + } + return -ENOTSUP; } -static inline int engine_put_float(struct lwm2m_output_context *out, - struct lwm2m_obj_path *path, double *value) +static inline int engine_put_float(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, + double *value) { - return out->writer->put_float(out, path, value); + if (out->writer->put_float) { + return out->writer->put_float(out, path, value); + } + return -ENOTSUP; } -static inline int engine_put_time(struct lwm2m_output_context *out, - struct lwm2m_obj_path *path, time_t value) +static inline int engine_put_time(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, + time_t value) { - return out->writer->put_time(out, path, value); + if (out->writer->put_time) { + return out->writer->put_time(out, path, value); + } + return -ENOTSUP; } -static inline int engine_put_bool(struct lwm2m_output_context *out, - struct lwm2m_obj_path *path, bool value) +static inline int engine_put_bool(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, + bool value) { - return out->writer->put_bool(out, path, value); + if (out->writer->put_bool) { + return out->writer->put_bool(out, path, value); + } + return -ENOTSUP; } -static inline int engine_put_opaque(struct lwm2m_output_context *out, - struct lwm2m_obj_path *path, char *buf, - size_t buflen) +static inline int engine_put_opaque(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, + char *buf, size_t buflen) { if (out->writer->put_opaque) { return out->writer->put_opaque(out, path, buf, buflen); } - return 0; + return -ENOTSUP; } -static inline int engine_put_objlnk(struct lwm2m_output_context *out, - struct lwm2m_obj_path *path, +static inline int engine_put_objlnk(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, struct lwm2m_objlnk *value) { - return out->writer->put_objlnk(out, path, value); + if (out->writer->put_objlnk) { + return out->writer->put_objlnk(out, path, value); + } + return -ENOTSUP; } static inline int engine_put_corelink(struct lwm2m_output_context *out, @@ -793,53 +817,68 @@ static inline int engine_put_timestamp(struct lwm2m_output_context *out, time_t static inline int engine_get_s32(struct lwm2m_input_context *in, int32_t *value) { - return in->reader->get_s32(in, value); + if (in->reader->get_s32) { + return in->reader->get_s32(in, value); + } + return -ENOTSUP; } static inline int engine_get_s64(struct lwm2m_input_context *in, int64_t *value) { - return in->reader->get_s64(in, value); + if (in->reader->get_s64) { + return in->reader->get_s64(in, value); + } + return -ENOTSUP; } -static inline int engine_get_string(struct lwm2m_input_context *in, - uint8_t *buf, size_t buflen) +static inline int engine_get_string(struct lwm2m_input_context *in, uint8_t *buf, size_t buflen) { - return in->reader->get_string(in, buf, buflen); + if (in->reader->get_string) { + return in->reader->get_string(in, buf, buflen); + } + return -ENOTSUP; } static inline int engine_get_time(struct lwm2m_input_context *in, time_t *value) { - return in->reader->get_time(in, value); + if (in->reader->get_time) { + return in->reader->get_time(in, value); + } + return -ENOTSUP; } -static inline int engine_get_float(struct lwm2m_input_context *in, - double *value) +static inline int engine_get_float(struct lwm2m_input_context *in, double *value) { - return in->reader->get_float(in, value); + if (in->reader->get_float) { + return in->reader->get_float(in, value); + } + return -ENOTSUP; } static inline int engine_get_bool(struct lwm2m_input_context *in, bool *value) { - return in->reader->get_bool(in, value); + if (in->reader->get_bool) { + return in->reader->get_bool(in, value); + } + return -ENOTSUP; } -static inline int engine_get_opaque(struct lwm2m_input_context *in, - uint8_t *buf, size_t buflen, - struct lwm2m_opaque_context *opaque, - bool *last_block) +static inline int engine_get_opaque(struct lwm2m_input_context *in, uint8_t *buf, size_t buflen, + struct lwm2m_opaque_context *opaque, bool *last_block) { if (in->reader->get_opaque) { - return in->reader->get_opaque(in, buf, buflen, - opaque, last_block); + return in->reader->get_opaque(in, buf, buflen, opaque, last_block); } - return 0; + return -ENOTSUP; } -static inline int engine_get_objlnk(struct lwm2m_input_context *in, - struct lwm2m_objlnk *value) +static inline int engine_get_objlnk(struct lwm2m_input_context *in, struct lwm2m_objlnk *value) { - return in->reader->get_objlnk(in, value); + if (in->reader->get_objlnk) { + return in->reader->get_objlnk(in, value); + } + return -ENOTSUP; } #endif /* LWM2M_OBJECT_H_ */ From 6f6fd46e43ba5b13d47f4940d82652bfe91a4fee Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Tue, 8 Aug 2023 13:31:40 +0300 Subject: [PATCH 0096/1623] [nrf fromtree] net: lwm2m: Separate opaque content format into its own Opaque content format is not part of clear-text, so it should be separated into its own file. Signed-off-by: Seppo Takalo (cherry picked from commit f227b5679221a57c85d0ad39ebb2024cb8590105) (cherry picked from commit 6b602c5803078e5fdcbb26c7b13224bd03152491) --- subsys/net/lib/lwm2m/CMakeLists.txt | 1 + subsys/net/lib/lwm2m/lwm2m_message_handling.c | 12 ++ subsys/net/lib/lwm2m/lwm2m_rw_opaque.c | 165 ++++++++++++++++++ subsys/net/lib/lwm2m/lwm2m_rw_opaque.h | 18 ++ subsys/net/lib/lwm2m/lwm2m_rw_plain_text.c | 44 ----- .../lib/lwm2m/content_plain_text/src/main.c | 31 ---- 6 files changed, 196 insertions(+), 75 deletions(-) create mode 100644 subsys/net/lib/lwm2m/lwm2m_rw_opaque.c create mode 100644 subsys/net/lib/lwm2m/lwm2m_rw_opaque.h diff --git a/subsys/net/lib/lwm2m/CMakeLists.txt b/subsys/net/lib/lwm2m/CMakeLists.txt index 5cb0ab158d5..2e895ec381b 100644 --- a/subsys/net/lib/lwm2m/CMakeLists.txt +++ b/subsys/net/lib/lwm2m/CMakeLists.txt @@ -14,6 +14,7 @@ zephyr_library_sources( lwm2m_obj_device.c lwm2m_rw_link_format.c lwm2m_rw_plain_text.c + lwm2m_rw_opaque.c lwm2m_util.c lwm2m_rd_client.c ) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 1a7d023ceb2..8b18f918752 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -47,6 +47,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "lwm2m_rw_link_format.h" #include "lwm2m_rw_oma_tlv.h" #include "lwm2m_rw_plain_text.h" +#include "lwm2m_rw_opaque.h" #include "lwm2m_util.h" #include "lwm2m_rd_client.h" #if defined(CONFIG_LWM2M_RW_SENML_JSON_SUPPORT) @@ -807,6 +808,10 @@ static int select_writer(struct lwm2m_output_context *out, uint16_t accept) out->writer = &link_format_writer; break; + case LWM2M_FORMAT_APP_OCTET_STREAM: + out->writer = &opaque_writer; + break; + case LWM2M_FORMAT_PLAIN_TEXT: case LWM2M_FORMAT_OMA_PLAIN_TEXT: out->writer = &plain_text_writer; @@ -857,6 +862,9 @@ static int select_reader(struct lwm2m_input_context *in, uint16_t format) switch (format) { case LWM2M_FORMAT_APP_OCTET_STREAM: + in->reader = &opaque_reader; + break; + case LWM2M_FORMAT_PLAIN_TEXT: case LWM2M_FORMAT_OMA_PLAIN_TEXT: in->reader = &plain_text_reader; @@ -1537,6 +1545,8 @@ static int do_read_op(struct lwm2m_message *msg, uint16_t content_format) switch (content_format) { case LWM2M_FORMAT_APP_OCTET_STREAM: + return do_read_op_opaque(msg, content_format); + case LWM2M_FORMAT_PLAIN_TEXT: case LWM2M_FORMAT_OMA_PLAIN_TEXT: return do_read_op_plain_text(msg, content_format); @@ -1919,6 +1929,8 @@ static int do_write_op(struct lwm2m_message *msg, uint16_t format) switch (format) { case LWM2M_FORMAT_APP_OCTET_STREAM: + return do_write_op_opaque(msg); + case LWM2M_FORMAT_PLAIN_TEXT: case LWM2M_FORMAT_OMA_PLAIN_TEXT: return do_write_op_plain_text(msg); diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_opaque.c b/subsys/net/lib/lwm2m/lwm2m_rw_opaque.c new file mode 100644 index 00000000000..90cb4619d9a --- /dev/null +++ b/subsys/net/lib/lwm2m/lwm2m_rw_opaque.c @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * Copyright (c) 2015, Yanzi Networks AB. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define LOG_MODULE_NAME net_lwm2m_opaque +#define LOG_LEVEL CONFIG_LWM2M_LOG_LEVEL + +#include +LOG_MODULE_REGISTER(LOG_MODULE_NAME); + +#include +#include +#include +#include +#include + +#include "lwm2m_object.h" +#include "lwm2m_rw_opaque.h" +#include "lwm2m_engine.h" +#include "lwm2m_util.h" + +static int get_opaque(struct lwm2m_input_context *in, uint8_t *value, + size_t buflen, struct lwm2m_opaque_context *opaque, + bool *last_block) +{ + uint16_t in_len; + + if (opaque->remaining == 0) { + coap_packet_get_payload(in->in_cpkt, &in_len); + + if (in_len == 0) { + return -ENODATA; + } + + if (in->block_ctx != NULL) { + uint32_t block_num = + in->block_ctx->ctx.current / + coap_block_size_to_bytes( + in->block_ctx->ctx.block_size); + + if (block_num == 0) { + opaque->len = in->block_ctx->ctx.total_size; + } + + if (opaque->len == 0) { + /* No size1 option provided, use current + * payload size. This will reset on next packet + * received. + */ + opaque->remaining = in_len; + } else { + opaque->remaining = opaque->len; + } + + } else { + opaque->len = in_len; + opaque->remaining = in_len; + } + } + + return lwm2m_engine_get_opaque_more(in, value, buflen, + opaque, last_block); +} + +static int put_opaque(struct lwm2m_output_context *out, + struct lwm2m_obj_path *path, char *buf, + size_t buflen) +{ + int ret; + + ret = buf_append(CPKT_BUF_WRITE(out->out_cpkt), buf, buflen); + if (ret < 0) { + return ret; + } + + return buflen; +} + + +const struct lwm2m_writer opaque_writer = { + .put_opaque = put_opaque, +}; + +const struct lwm2m_reader opaque_reader = { + .get_opaque = get_opaque, +}; + +int do_read_op_opaque(struct lwm2m_message *msg, int content_format) +{ + /* Opaque can only return single resource (instance) */ + if (msg->path.level < LWM2M_PATH_LEVEL_RESOURCE) { + return -EPERM; + } else if (msg->path.level > LWM2M_PATH_LEVEL_RESOURCE) { + if (!IS_ENABLED(CONFIG_LWM2M_VERSION_1_1)) { + return -ENOENT; + } else if (msg->path.level > LWM2M_PATH_LEVEL_RESOURCE_INST) { + return -ENOENT; + } + } + + return lwm2m_perform_read_op(msg, content_format); +} + +int do_write_op_opaque(struct lwm2m_message *msg) +{ + struct lwm2m_engine_obj_inst *obj_inst = NULL; + struct lwm2m_engine_obj_field *obj_field; + struct lwm2m_engine_res *res = NULL; + struct lwm2m_engine_res_inst *res_inst = NULL; + int ret; + uint8_t created = 0U; + + ret = lwm2m_get_or_create_engine_obj(msg, &obj_inst, &created); + if (ret < 0) { + return ret; + } + + ret = lwm2m_engine_validate_write_access(msg, obj_inst, &obj_field); + if (ret < 0) { + return ret; + } + + ret = lwm2m_engine_get_create_res_inst(&msg->path, &res, &res_inst); + if (ret < 0) { + return -ENOENT; + } + + if (msg->path.level < LWM2M_PATH_LEVEL_RESOURCE) { + msg->path.level = LWM2M_PATH_LEVEL_RESOURCE; + } + + return lwm2m_write_handler(obj_inst, res, res_inst, obj_field, msg); +} diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_opaque.h b/subsys/net/lib/lwm2m/lwm2m_rw_opaque.h new file mode 100644 index 00000000000..4118049efe8 --- /dev/null +++ b/subsys/net/lib/lwm2m/lwm2m_rw_opaque.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LWM2M_RW_OPAQUE_H_ +#define LWM2M_RW_OPAQUE_H_ + +#include "lwm2m_object.h" + +extern const struct lwm2m_writer opaque_writer; +extern const struct lwm2m_reader opaque_reader; + +int do_read_op_opaque(struct lwm2m_message *msg, int content_format); +int do_write_op_opaque(struct lwm2m_message *msg); + +#endif /* LWM2M_RW_OPAQUE_H_ */ diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_plain_text.c b/subsys/net/lib/lwm2m/lwm2m_rw_plain_text.c index 9650b33fc29..3ec69e8db82 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rw_plain_text.c +++ b/subsys/net/lib/lwm2m/lwm2m_rw_plain_text.c @@ -341,49 +341,6 @@ static int get_bool(struct lwm2m_input_context *in, bool *value) return sizeof(uint8_t); } -static int get_opaque(struct lwm2m_input_context *in, uint8_t *value, - size_t buflen, struct lwm2m_opaque_context *opaque, - bool *last_block) -{ - uint16_t in_len; - - if (opaque->remaining == 0) { - coap_packet_get_payload(in->in_cpkt, &in_len); - - if (in_len == 0) { - return -ENODATA; - } - - if (in->block_ctx != NULL) { - uint32_t block_num = - in->block_ctx->ctx.current / - coap_block_size_to_bytes( - in->block_ctx->ctx.block_size); - - if (block_num == 0) { - opaque->len = in->block_ctx->ctx.total_size; - } - - if (opaque->len == 0) { - /* No size1 option provided, use current - * payload size. This will reset on next packet - * received. - */ - opaque->remaining = in_len; - } else { - opaque->remaining = opaque->len; - } - - } else { - opaque->len = in_len; - opaque->remaining = in_len; - } - } - - return lwm2m_engine_get_opaque_more(in, value, buflen, - opaque, last_block); -} - static int get_objlnk(struct lwm2m_input_context *in, struct lwm2m_objlnk *value) { @@ -432,7 +389,6 @@ const struct lwm2m_reader plain_text_reader = { .get_time = get_time, .get_float = get_float, .get_bool = get_bool, - .get_opaque = get_opaque, .get_objlnk = get_objlnk, }; diff --git a/tests/net/lib/lwm2m/content_plain_text/src/main.c b/tests/net/lib/lwm2m/content_plain_text/src/main.c index c7cc857224c..7bc77a82327 100644 --- a/tests/net/lib/lwm2m/content_plain_text/src/main.c +++ b/tests/net/lib/lwm2m/content_plain_text/src/main.c @@ -470,37 +470,6 @@ ZTEST(net_content_plain_text_nodata, test_get_bool_nodata) zassert_equal(ret, -ENODATA, "Invalid error code returned"); } -ZTEST(net_content_plain_text, test_get_opaque) -{ - int ret; - const char *payload = "test_payload"; - uint8_t buf[16]; - bool last_block; - struct lwm2m_opaque_context ctx = { 0 }; - - test_payload_set(payload); - - ret = plain_text_reader.get_opaque(&test_in, buf, sizeof(buf), - &ctx, &last_block); - zassert_equal(ret, strlen(payload), "Invalid length returned"); - zassert_mem_equal(buf, payload, strlen(payload), - "Invalid value parsed"); - zassert_equal(test_in.offset, strlen(payload) + 1, - "Invalid packet offset"); -} - -ZTEST(net_content_plain_text_nodata, test_get_opaque_nodata) -{ - int ret; - uint8_t value[4]; - bool last_block; - struct lwm2m_opaque_context ctx = { 0 }; - - ret = plain_text_reader.get_opaque(&test_in, value, sizeof(value), - &ctx, &last_block); - zassert_equal(ret, 0, "Invalid error code returned"); -} - ZTEST(net_content_plain_text, test_get_objlnk) { int ret; From 142c5e169eaff5e0ef611f95556e5bc8b3ee2d9b Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Wed, 9 Aug 2023 15:34:23 +0300 Subject: [PATCH 0097/1623] [nrf fromtree] net: lwm2m: Only parse block1 option for WRITE operation In reality, single-write is the only operation that handles BLOCK1 operations when receiving paylod. Signed-off-by: Seppo Takalo (cherry picked from commit 4e97607c27b5dfff3ab5d0ee7075ee6249c5174b) (cherry picked from commit 44300fbeb01474d8f7d4107f709684379c1cb2cd) --- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 398 ++++++++++-------- 1 file changed, 213 insertions(+), 185 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 8b18f918752..299b0330c0b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -1926,50 +1926,179 @@ static int do_discover_op(struct lwm2m_message *msg, uint16_t content_format) static int do_write_op(struct lwm2m_message *msg, uint16_t format) { + int r; + switch (format) { case LWM2M_FORMAT_APP_OCTET_STREAM: - return do_write_op_opaque(msg); + r = do_write_op_opaque(msg); + break; case LWM2M_FORMAT_PLAIN_TEXT: case LWM2M_FORMAT_OMA_PLAIN_TEXT: - return do_write_op_plain_text(msg); + r = do_write_op_plain_text(msg); + break; #ifdef CONFIG_LWM2M_RW_OMA_TLV_SUPPORT case LWM2M_FORMAT_OMA_TLV: case LWM2M_FORMAT_OMA_OLD_TLV: - return do_write_op_tlv(msg); + r = do_write_op_tlv(msg); + break; #endif #ifdef CONFIG_LWM2M_RW_JSON_SUPPORT case LWM2M_FORMAT_OMA_JSON: case LWM2M_FORMAT_OMA_OLD_JSON: - return do_write_op_json(msg); + r = do_write_op_json(msg); + break; #endif #if defined(CONFIG_LWM2M_RW_SENML_JSON_SUPPORT) case LWM2M_FORMAT_APP_SEML_JSON: - return do_write_op_senml_json(msg); + r = do_write_op_senml_json(msg); + break; #endif #ifdef CONFIG_LWM2M_RW_CBOR_SUPPORT case LWM2M_FORMAT_APP_CBOR: - return do_write_op_cbor(msg); + r = do_write_op_cbor(msg); + break; #endif #ifdef CONFIG_LWM2M_RW_SENML_CBOR_SUPPORT case LWM2M_FORMAT_APP_SENML_CBOR: - return do_write_op_senml_cbor(msg); + r = do_write_op_senml_cbor(msg); + break; #endif default: LOG_ERR("Unsupported format: %u", format); - return -ENOMSG; + r = -ENOMSG; + break; + } + + return r; +} + +static int parse_write_op(struct lwm2m_message *msg, uint16_t format) +{ + int block_opt, block_num; + struct lwm2m_block_context *block_ctx = NULL; + enum coap_block_size block_size; + bool last_block = false; + int r; + uint16_t payload_len = 0U; + const uint8_t *payload_start; + + /* setup incoming data */ + payload_start = coap_packet_get_payload(msg->in.in_cpkt, &payload_len); + if (payload_len > 0) { + msg->in.offset = payload_start - msg->in.in_cpkt->data; + } else { + msg->in.offset = msg->in.in_cpkt->offset; + } + + /* Check for block transfer */ + block_opt = coap_get_option_int(msg->in.in_cpkt, COAP_OPTION_BLOCK1); + if (block_opt > 0) { + last_block = !GET_MORE(block_opt); + + /* RFC7252: 4.6. Message Size */ + block_size = GET_BLOCK_SIZE(block_opt); + if (!last_block && coap_block_size_to_bytes(block_size) > payload_len) { + LOG_DBG("Trailing payload is discarded!"); + return -EFBIG; + } + + block_num = GET_BLOCK_NUM(block_opt); + + /* Try to retrieve existing block context. If one not exists, + * and we've received first block, allocate new context. + */ + r = get_block_ctx(&msg->path, &block_ctx); + if (r < 0 && block_num == 0) { + r = init_block_ctx(&msg->path, &block_ctx); + } + + if (r < 0) { + LOG_ERR("Cannot find block context"); + return r; + } + + msg->in.block_ctx = block_ctx; + + if (block_num < block_ctx->expected) { + LOG_WRN("Block already handled %d, expected %d", block_num, + block_ctx->expected); + return 0; + } + if (block_num > block_ctx->expected) { + LOG_WRN("Block out of order %d, expected %d", block_num, + block_ctx->expected); + r = -EFAULT; + return r; + } + r = coap_update_from_block(msg->in.in_cpkt, &block_ctx->ctx); + if (r < 0) { + LOG_ERR("Error from block update: %d", r); + return r; + } + + block_ctx->last_block = last_block; + + /* Initial block sent by the server might be larger than + * our block size therefore it is needed to take this + * into account when calculating next expected block + * number. + */ + block_ctx->expected += GET_BLOCK_SIZE(block_opt) - block_ctx->ctx.block_size + 1; + + /* Handle blockwise 1 (Part 1): Set response code */ + if (!last_block) { + msg->code = COAP_RESPONSE_CODE_CONTINUE; + } + } + + r = do_write_op(msg, format); + + /* Handle blockwise 1 (Part 2): Append BLOCK1 option / free context */ + if (block_ctx) { + if (r >= 0 && !last_block) { + /* More to come, ack with correspond block # */ + r = coap_append_block1_option(msg->out.out_cpkt, &block_ctx->ctx); + if (r < 0) { + /* report as internal server error */ + LOG_ERR("Fail adding block1 option: %d", r); + r = -EINVAL; + } + } + if (r < 0 || last_block) { + /* Free context when finished or when there is error */ + free_block_ctx(block_ctx); + + } } + + return r; } static int do_composite_write_op(struct lwm2m_message *msg, uint16_t format) { + uint16_t payload_len = 0U; + const uint8_t *payload_start; + + /* setup incoming data */ + payload_start = coap_packet_get_payload(msg->in.in_cpkt, &payload_len); + if (payload_len > 0) { + msg->in.offset = payload_start - msg->in.in_cpkt->data; + } else { + msg->in.offset = msg->in.in_cpkt->offset; + } + + if (coap_get_option_int(msg->in.in_cpkt, COAP_OPTION_BLOCK1) >= 0) { + return -ENOTSUP; + } + switch (format) { #if defined(CONFIG_LWM2M_RW_SENML_JSON_SUPPORT) case LWM2M_FORMAT_APP_SEML_JSON: @@ -2074,13 +2203,6 @@ int handle_request(struct coap_packet *request, struct lwm2m_message *msg) uint8_t tkl = 0U; uint16_t format = LWM2M_FORMAT_NONE, accept; int observe = -1; /* default to -1, 0 = ENABLE, 1 = DISABLE */ - int block_opt, block_num; - struct lwm2m_block_context *block_ctx = NULL; - enum coap_block_size block_size; - uint16_t payload_len = 0U; - bool last_block = false; - bool ignore = false; - const uint8_t *payload_start; /* set CoAP request / message */ msg->in.in_cpkt = request; @@ -2252,202 +2374,111 @@ int handle_request(struct coap_packet *request, struct lwm2m_message *msg) break; } - /* setup incoming data */ - payload_start = coap_packet_get_payload(msg->in.in_cpkt, &payload_len); - if (payload_len > 0) { - msg->in.offset = payload_start - msg->in.in_cpkt->data; - } else { - msg->in.offset = msg->in.in_cpkt->offset; - } - - /* Check for block transfer */ - - block_opt = coap_get_option_int(msg->in.in_cpkt, COAP_OPTION_BLOCK1); - if (block_opt > 0) { - last_block = !GET_MORE(block_opt); - - /* RFC7252: 4.6. Message Size */ - block_size = GET_BLOCK_SIZE(block_opt); - if (!last_block && coap_block_size_to_bytes(block_size) > payload_len) { - LOG_DBG("Trailing payload is discarded!"); - r = -EFBIG; - goto error; - } - - block_num = GET_BLOCK_NUM(block_opt); - - /* Try to retrieve existing block context. If one not exists, - * and we've received first block, allocate new context. - */ - r = get_block_ctx(&msg->path, &block_ctx); - if (r < 0 && block_num == 0) { - r = init_block_ctx(&msg->path, &block_ctx); - } - - if (r < 0) { - LOG_ERR("Cannot find block context"); - goto error; - } - - msg->in.block_ctx = block_ctx; - - if (block_num < block_ctx->expected) { - LOG_WRN("Block already handled %d, expected %d", block_num, - block_ctx->expected); - ignore = true; - } else if (block_num > block_ctx->expected) { - LOG_WRN("Block out of order %d, expected %d", block_num, - block_ctx->expected); - r = -EFAULT; - goto error; - } else { - r = coap_update_from_block(msg->in.in_cpkt, &block_ctx->ctx); - if (r < 0) { - LOG_ERR("Error from block update: %d", r); - goto error; - } - - block_ctx->last_block = last_block; - - /* Initial block sent by the server might be larger than - * our block size therefore it is needed to take this - * into account when calculating next expected block - * number. - */ - block_ctx->expected += - GET_BLOCK_SIZE(block_opt) - block_ctx->ctx.block_size + 1; - } - - /* Handle blockwise 1 (Part 1): Set response code */ - if (!last_block) { - msg->code = COAP_RESPONSE_CODE_CONTINUE; - } - } - /* render CoAP packet header */ r = lwm2m_init_message(msg); if (r < 0) { goto error; } - if (!ignore) { #if defined(CONFIG_LWM2M_ACCESS_CONTROL_ENABLE) - r = access_control_check_access(msg->path.obj_id, msg->path.obj_inst_id, - msg->ctx->srv_obj_inst, msg->operation, - msg->ctx->bootstrap_mode); - if (r < 0) { - LOG_ERR("Access denied - Server obj %u does not have proper access to " - "resource", - msg->ctx->srv_obj_inst); - goto error; - } + r = access_control_check_access(msg->path.obj_id, msg->path.obj_inst_id, + msg->ctx->srv_obj_inst, msg->operation, + msg->ctx->bootstrap_mode); + if (r < 0) { + LOG_ERR("Access denied - Server obj %u does not have proper access to " + "resource", + msg->ctx->srv_obj_inst); + goto error; + } #endif - if (msg->path.obj_id == LWM2M_OBJECT_SECURITY_ID && !msg->ctx->bootstrap_mode) { - r = -EACCES; - goto error; - } + if (msg->path.obj_id == LWM2M_OBJECT_SECURITY_ID && !msg->ctx->bootstrap_mode) { + r = -EACCES; + goto error; + } + + switch (msg->operation) { - switch (msg->operation) { + case LWM2M_OP_READ: + if (observe >= 0) { + /* Validate That Token is valid for Observation */ + if (!msg->token) { + LOG_ERR("OBSERVE request missing token"); + r = -EINVAL; + goto error; + } - case LWM2M_OP_READ: - if (observe >= 0) { - /* Validate That Token is valid for Observation */ - if (!msg->token) { - LOG_ERR("OBSERVE request missing token"); - r = -EINVAL; + if ((code & COAP_REQUEST_MASK) == COAP_METHOD_GET) { + /* Normal Observation Request or Cancel */ + r = lwm2m_engine_observation_handler(msg, observe, accept, + false); + if (r < 0) { goto error; } - if ((code & COAP_REQUEST_MASK) == COAP_METHOD_GET) { - /* Normal Observation Request or Cancel */ - r = lwm2m_engine_observation_handler(msg, observe, accept, - false); - if (r < 0) { - goto error; - } - - r = do_read_op(msg, accept); - } else { - /* Composite Observation request & cancel handler */ - r = lwm2m_engine_observation_handler(msg, observe, accept, - true); - if (r < 0) { - goto error; - } - } + r = do_read_op(msg, accept); } else { - if ((code & COAP_REQUEST_MASK) == COAP_METHOD_GET) { - r = do_read_op(msg, accept); - } else { - r = do_composite_read_op(msg, accept); + /* Composite Observation request & cancel handler */ + r = lwm2m_engine_observation_handler(msg, observe, accept, + true); + if (r < 0) { + goto error; } } - break; - - case LWM2M_OP_DISCOVER: - r = do_discover_op(msg, accept); - break; - - case LWM2M_OP_WRITE: - case LWM2M_OP_CREATE: - if ((code & COAP_REQUEST_MASK) == COAP_METHOD_IPATCH) { - /* iPATCH is for Composite purpose */ - r = do_composite_write_op(msg, format); + } else { + if ((code & COAP_REQUEST_MASK) == COAP_METHOD_GET) { + r = do_read_op(msg, accept); } else { - /* Single resource write Operation */ - r = do_write_op(msg, format); + r = do_composite_read_op(msg, accept); } + } + break; + + case LWM2M_OP_DISCOVER: + r = do_discover_op(msg, accept); + break; + + case LWM2M_OP_WRITE: + case LWM2M_OP_CREATE: + if ((code & COAP_REQUEST_MASK) == COAP_METHOD_IPATCH) { + /* iPATCH is for Composite purpose */ + r = do_composite_write_op(msg, format); + } else { + /* Single resource write Operation */ + r = parse_write_op(msg, format); + } #if defined(CONFIG_LWM2M_ACCESS_CONTROL_ENABLE) - if (msg->operation == LWM2M_OP_CREATE && r >= 0) { - access_control_add(msg->path.obj_id, msg->path.obj_inst_id, - msg->ctx->srv_obj_inst); - } + if (msg->operation == LWM2M_OP_CREATE && r >= 0) { + access_control_add(msg->path.obj_id, msg->path.obj_inst_id, + msg->ctx->srv_obj_inst); + } #endif - break; + break; - case LWM2M_OP_WRITE_ATTR: - r = lwm2m_write_attr_handler(obj, msg); - break; + case LWM2M_OP_WRITE_ATTR: + r = lwm2m_write_attr_handler(obj, msg); + break; - case LWM2M_OP_EXECUTE: - r = lwm2m_exec_handler(msg); - break; + case LWM2M_OP_EXECUTE: + r = lwm2m_exec_handler(msg); + break; - case LWM2M_OP_DELETE: + case LWM2M_OP_DELETE: #if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) - if (msg->ctx->bootstrap_mode) { - r = bootstrap_delete(msg); - break; - } -#endif - r = lwm2m_delete_handler(msg); + if (msg->ctx->bootstrap_mode) { + r = bootstrap_delete(msg); break; - - default: - LOG_ERR("Unknown operation: %u", msg->operation); - r = -EINVAL; } +#endif + r = lwm2m_delete_handler(msg); + break; - if (r < 0) { - goto error; - } + default: + LOG_ERR("Unknown operation: %u", msg->operation); + r = -EINVAL; } - /* Handle blockwise 1 (Part 2): Append BLOCK1 option / free context */ - if (block_ctx) { - if (!last_block) { - /* More to come, ack with correspond block # */ - r = coap_append_block1_option(msg->out.out_cpkt, &block_ctx->ctx); - if (r < 0) { - /* report as internal server error */ - LOG_ERR("Fail adding block1 option: %d", r); - r = -EINVAL; - goto error; - } - } else { - /* Free context when finished */ - free_block_ctx(block_ctx); - } + if (r < 0) { + goto error; } return 0; @@ -2482,9 +2513,6 @@ int handle_request(struct coap_packet *request, struct lwm2m_message *msg) LOG_ERR("Error recreating message: %d", r); } - /* Free block context when error happened */ - free_block_ctx(block_ctx); - return 0; } From 58210f1e7f681cd8faf5f4a1a0d273bb7d7ec43f Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Fri, 11 Aug 2023 15:39:58 +0300 Subject: [PATCH 0098/1623] [nrf fromtree] net: lwm2m: Remove unneeded function pointer parameter lwm2m_udp_receive() is only called with same function pointer, so there no need to carry that in the parameter. Signed-off-by: Seppo Takalo (cherry picked from commit b9028bb7222bd15ba31b3e7d310fc60537a60422) (cherry picked from commit 78fbe138393f9c74c8df8aef1eb8fadbe97073f7) --- subsys/net/lib/lwm2m/lwm2m_engine.c | 2 +- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 14 +++++--------- subsys/net/lib/lwm2m/lwm2m_message_handling.h | 6 +----- tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c | 4 ++-- tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h | 2 +- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 91d8c3bd605..d38c081ed34 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -642,7 +642,7 @@ static int socket_recv_message(struct lwm2m_ctx *client_ctx) } in_buf[len] = 0U; - lwm2m_udp_receive(client_ctx, in_buf, len, &from_addr, handle_request); + lwm2m_udp_receive(client_ctx, in_buf, len, &from_addr); return 0; } diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 299b0330c0b..4eea849750b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -97,6 +97,7 @@ sys_slist_t *lwm2m_engine_obj_list(void); sys_slist_t *lwm2m_engine_obj_inst_list(void); +static int handle_request(struct coap_packet *request, struct lwm2m_message *msg); #if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER) struct coap_block_context *lwm2m_output_block_context(void); #endif @@ -2193,7 +2194,7 @@ static int lwm2m_exec_handler(struct lwm2m_message *msg) return -ENOENT; } -int handle_request(struct coap_packet *request, struct lwm2m_message *msg) +static int handle_request(struct coap_packet *request, struct lwm2m_message *msg) { int r; uint8_t code; @@ -2557,7 +2558,7 @@ static int lwm2m_response_promote_to_con(struct lwm2m_message *msg) } void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_len, - struct sockaddr *from_addr, udp_request_handler_cb_t udp_request_handler) + struct sockaddr *from_addr) { struct lwm2m_message *msg = NULL; struct coap_pending *pending; @@ -2684,12 +2685,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ return; } - /* - * If no normal response handler is found, then this is - * a new request coming from the server. Let's look - * at registered objects to find a handler. - */ - if (udp_request_handler && coap_header_get_type(&response) == COAP_TYPE_CON) { + if (coap_header_get_type(&response) == COAP_TYPE_CON) { msg = lwm2m_get_message(client_ctx); if (!msg) { LOG_ERR("Unable to get a lwm2m message!"); @@ -2707,7 +2703,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ lwm2m_registry_lock(); /* process the response to this request */ - r = udp_request_handler(&response, msg); + r = handle_request(&response, msg); lwm2m_registry_unlock(); if (r < 0) { return; diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.h b/subsys/net/lib/lwm2m/lwm2m_message_handling.h index 12ba9e762fd..a98be3f8dc2 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.h +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.h @@ -39,8 +39,6 @@ #define NUM_OUTPUT_BLOCK_CONTEXT CONFIG_LWM2M_NUM_OUTPUT_BLOCK_CONTEXT #endif -/* Establish a request handler callback type */ -typedef int (*udp_request_handler_cb_t)(struct coap_packet *request, struct lwm2m_message *msg); /* LwM2M message functions */ struct lwm2m_message *lwm2m_get_message(struct lwm2m_ctx *client_ctx); struct lwm2m_message *find_msg(struct coap_pending *pending, struct coap_reply *reply); @@ -49,10 +47,8 @@ void lm2m_message_clear_allocations(struct lwm2m_message *msg); int lwm2m_init_message(struct lwm2m_message *msg); int lwm2m_send_message_async(struct lwm2m_message *msg); -int handle_request(struct coap_packet *request, struct lwm2m_message *msg); - void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_len, - struct sockaddr *from_addr, udp_request_handler_cb_t udp_request_handler); + struct sockaddr *from_addr); int generate_notify_message(struct lwm2m_ctx *ctx, struct observe_node *obs, void *user_data); /* Notification and Send operation */ diff --git a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c index 93f5cce1012..5db155f1e29 100644 --- a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c +++ b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c @@ -24,8 +24,8 @@ DEFINE_FAKE_VALUE_FUNC(int, generate_notify_message, struct lwm2m_ctx *, struct DEFINE_FAKE_VALUE_FUNC(int64_t, engine_observe_shedule_next_event, struct observe_node *, uint16_t, const int64_t); DEFINE_FAKE_VALUE_FUNC(int, handle_request, struct coap_packet *, struct lwm2m_message *); -DEFINE_FAKE_VOID_FUNC(lwm2m_udp_receive, struct lwm2m_ctx *, uint8_t *, uint16_t, struct sockaddr *, - udp_request_handler_cb_t); +DEFINE_FAKE_VOID_FUNC(lwm2m_udp_receive, struct lwm2m_ctx *, uint8_t *, uint16_t, + struct sockaddr *); DEFINE_FAKE_VALUE_FUNC(bool, lwm2m_rd_client_is_registred, struct lwm2m_ctx *); DEFINE_FAKE_VOID_FUNC(lwm2m_engine_context_close, struct lwm2m_ctx *); DEFINE_FAKE_VALUE_FUNC(int, lwm2m_get_res_buf, const struct lwm2m_obj_path *, void **, uint16_t *, diff --git a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h index 088d72d4623..7b8ca481f85 100644 --- a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h +++ b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h @@ -39,7 +39,7 @@ DECLARE_FAKE_VALUE_FUNC(int64_t, engine_observe_shedule_next_event, struct obser const int64_t); DECLARE_FAKE_VALUE_FUNC(int, handle_request, struct coap_packet *, struct lwm2m_message *); DECLARE_FAKE_VOID_FUNC(lwm2m_udp_receive, struct lwm2m_ctx *, uint8_t *, uint16_t, - struct sockaddr *, udp_request_handler_cb_t); + struct sockaddr *); DECLARE_FAKE_VALUE_FUNC(bool, lwm2m_rd_client_is_registred, struct lwm2m_ctx *); DECLARE_FAKE_VOID_FUNC(lwm2m_engine_context_close, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_get_res_buf, const struct lwm2m_obj_path *, void **, uint16_t *, From a65e10df9b91edd5198495d3bc13e928c314aa38 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 10 Aug 2023 16:39:49 +0300 Subject: [PATCH 0099/1623] [nrf fromtree] net: lwm2m: Refactor blockwise SEND to support GET and FETCH Allow blockwise-send buffers to be used with GET and FETCH queries as well. When outgoing packet is split into multiple blocks, don't free it when first block is send. Keep it in memory until some other requests come. Following queries to next block are matched using CoAP token. However, this required Leshan to use COAP.BLOCKWISE_REUSE_TOKEN=true option from Californium. Signed-off-by: Seppo Takalo (cherry picked from commit 69cd5978875329e4eac6c55626e51f9f008e9eb3) (cherry picked from commit b992972e11e065fa1cc53567e757d63f204abeb5) --- include/zephyr/net/coap.h | 14 +++ subsys/net/lib/coap/coap.c | 13 +++ subsys/net/lib/lwm2m/lwm2m_engine.c | 4 +- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 92 +++++++++++++++++-- subsys/net/lib/lwm2m/lwm2m_message_handling.h | 1 + subsys/net/lib/lwm2m/lwm2m_object.h | 5 +- 6 files changed, 121 insertions(+), 8 deletions(-) diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index 95bb0b45c65..55776bfc6d8 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -713,6 +713,20 @@ int coap_get_option_int(const struct coap_packet *cpkt, uint16_t code); */ int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint8_t *block_number); +/** + * @brief Get values from CoAP block2 option. + * + * Decode block number and block size from option. Ignore the has_more flag + * as it should always be zero on queries. + * + * @param cpkt Packet to be inspected + * @param block_number Is set to the number of the block + * + * @return Integer value of the block size in case of success + * or negative in case of error. + */ +int coap_get_block2_option(const struct coap_packet *cpkt, uint8_t *block_number); + /** * @brief Retrieves BLOCK{1,2} and SIZE{1,2} from @a cpkt and updates * @a ctx accordingly. diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index a5c300bf0e2..e3427844bb5 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -1303,6 +1303,19 @@ int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint8 return ret; } +int coap_get_block2_option(const struct coap_packet *cpkt, uint8_t *block_number) +{ + int ret = coap_get_option_int(cpkt, COAP_OPTION_BLOCK2); + + if (ret < 0) { + return ret; + } + + *block_number = GET_NUM(ret); + ret = 1 << (GET_BLOCK_SIZE(ret) + 4); + return ret; +} + int insert_option(struct coap_packet *cpkt, uint16_t code, const uint8_t *value, uint16_t len) { uint16_t offset = cpkt->hdr_len; diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index d38c081ed34..651baa30ff6 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -675,7 +675,9 @@ static int socket_send_message(struct lwm2m_ctx *client_ctx) } if (msg->type != COAP_TYPE_CON) { - lwm2m_reset_message(msg, true); + if (!lwm2m_outgoing_is_part_of_blockwise(msg)) { + lwm2m_reset_message(msg, true); + } } return rc; diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 4eea849750b..df940cf4adb 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -81,6 +81,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); /* Shared set of in-flight LwM2M messages */ static struct lwm2m_message messages[CONFIG_LWM2M_ENGINE_MAX_MESSAGES]; static struct lwm2m_block_context block1_contexts[NUM_BLOCK1_CONTEXT]; +static struct lwm2m_message *ongoing_block2_tx; #if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER) /* we need 1 more buffer as the payload is encoded in that buffer first even if @@ -99,6 +100,7 @@ sys_slist_t *lwm2m_engine_obj_inst_list(void); static int handle_request(struct coap_packet *request, struct lwm2m_message *msg); #if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER) +STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_num); struct coap_block_context *lwm2m_output_block_context(void); #endif @@ -301,10 +303,16 @@ STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_nu } msg->cpkt.hdr_len = msg->body_encode_buffer.hdr_len; } else { - /* reuse message for next block */ - tkl = coap_header_get_token(&msg->cpkt, token); + /* reuse message for next block. Copy token from the new query to allow + * CoAP clients to use new token for every query of ongoing transaction + */ + tkl = coap_header_get_token(msg->in.in_cpkt, token); lwm2m_reset_message(msg, false); - msg->mid = coap_next_id(); + if (msg->type == COAP_TYPE_ACK) { + msg->mid = coap_header_get_id(msg->in.in_cpkt); + } else { + msg->mid = coap_next_id(); + } msg->token = token; msg->tkl = tkl; ret = lwm2m_init_message(msg); @@ -333,10 +341,14 @@ STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_nu return ret; } ret = coap_block_transfer_init(msg->out.block_ctx, lwm2m_default_block_size(), - msg->body_encode_buffer.offset); + complete_payload_len); if (ret < 0) { return ret; } + if (msg->type == COAP_TYPE_ACK) { + ongoing_block2_tx = msg; + } + msg->block_send = true; } else { /* update block context */ msg->out.block_ctx->current = block_num * block_size_bytes; @@ -402,8 +414,15 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg) return 0; } + #endif +bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg) +{ + return msg->block_send; +} + + void lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx) { struct lwm2m_message *msg; @@ -2557,6 +2576,56 @@ static int lwm2m_response_promote_to_con(struct lwm2m_message *msg) return ret; } +static struct lwm2m_message *find_ongoing_block2_tx(void) +{ + /* TODO: I could try to check if there is Request-Tags attached, and then match queries + * for those, but currently popular LwM2M servers don't attach those tags, so in reality + * I have no way of properly matching query with BLOCK2 option to a previous query. + * Therefore we can only support one ongoing BLOCK2 transfer and assume all BLOCK2 requests + * are part of currently ongoing one. + */ + return ongoing_block2_tx; +} + +static void clear_ongoing_block2_tx(void) +{ + if (ongoing_block2_tx) { + LOG_DBG("clear"); + lwm2m_reset_message(ongoing_block2_tx, true); + ongoing_block2_tx = NULL; + } +} + +static void handle_ongoing_block2_tx(struct lwm2m_message *msg, struct coap_packet *cpkt) +{ +#if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER) + int r; + uint8_t block; + + r = coap_get_block2_option(cpkt, &block); + if (r < 0) { + LOG_ERR("Failed to parse BLOCK2"); + return; + } + + msg->in.in_cpkt = cpkt; + + r = build_msg_block_for_send(msg, block); + if (r < 0) { + clear_ongoing_block2_tx(); + LOG_ERR("Unable to build next block of lwm2m message! r=%d", r); + return; + } + + r = lwm2m_send_message_async(msg); + if (r < 0) { + clear_ongoing_block2_tx(); + LOG_ERR("Unable to send next block of lwm2m message!"); + return; + } +#endif +} + void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_len, struct sockaddr *from_addr) { @@ -2565,12 +2634,12 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ struct coap_reply *reply; struct coap_packet response; int r; - uint8_t token[8]; #if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER) bool more_blocks = false; uint8_t block_num; uint8_t last_block_num; #endif + bool has_block2; r = coap_packet_parse(&response, buf, buf_len, NULL, 0); if (r < 0) { @@ -2578,7 +2647,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ return; } - (void)coap_header_get_token(&response, token); + has_block2 = coap_get_option_int(&response, COAP_OPTION_BLOCK2) > 0 ? true : false; pending = coap_pending_received(&response, client_ctx->pendings, ARRAY_SIZE(client_ctx->pendings)); if (pending && coap_header_get_type(&response) == COAP_TYPE_ACK) { @@ -2686,6 +2755,17 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ } if (coap_header_get_type(&response) == COAP_TYPE_CON) { + if (has_block2 && IS_ENABLED(CONFIG_LWM2M_COAP_BLOCK_TRANSFER)) { + msg = find_ongoing_block2_tx(); + if (msg) { + return handle_ongoing_block2_tx(msg, &response); + } + return; + } + + /* Clear out existing Block2 transfers when new requests come */ + clear_ongoing_block2_tx(); + msg = lwm2m_get_message(client_ctx); if (!msg) { LOG_ERR("Unable to get a lwm2m message!"); diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.h b/subsys/net/lib/lwm2m/lwm2m_message_handling.h index a98be3f8dc2..fd6c4470d84 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.h +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.h @@ -75,5 +75,6 @@ enum coap_block_size lwm2m_default_block_size(void); int lwm2m_parse_peerinfo(char *url, struct lwm2m_ctx *client_ctx, bool is_firmware_uri); void lwm2m_clear_block_contexts(void); +bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg); #endif /* LWM2M_MESSAGE_HANDLING_H */ diff --git a/subsys/net/lib/lwm2m/lwm2m_object.h b/subsys/net/lib/lwm2m/lwm2m_object.h index 05bc818c99c..170a99c023d 100644 --- a/subsys/net/lib/lwm2m/lwm2m_object.h +++ b/subsys/net/lib/lwm2m/lwm2m_object.h @@ -521,8 +521,11 @@ struct lwm2m_message { /** Incoming message action */ uint8_t operation; - /* Information whether the message was acknowledged. */ + /** Information whether the message was acknowledged. */ bool acknowledged : 1; + + /** Indicate that this is part of outgoing block transfer. */ + bool block_send : 1; }; /* LWM2M format writer for the various formats supported */ From 73a6d196160abe543c52944c07953dafdc338ea6 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 24 Aug 2023 16:42:00 +0300 Subject: [PATCH 0100/1623] [nrf fromtree] net: lwm2m: Fix composite read on SenML-CBOR Composite read was incorrectly trying to parse CoAP packet instead of payload of the packet. Signed-off-by: Seppo Takalo (cherry picked from commit ebb90c5184cf296d324685862bd8a02a02e6bd23) (cherry picked from commit 7b61e70d81da42d1a7c5a92fcc8143e0971d05a2) --- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 6 ------ subsys/net/lib/lwm2m/lwm2m_message_handling.h | 6 +++++- subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c | 5 ++++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index df940cf4adb..06cc1b5ecf8 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -417,12 +417,6 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg) #endif -bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg) -{ - return msg->block_send; -} - - void lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx) { struct lwm2m_message *msg; diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.h b/subsys/net/lib/lwm2m/lwm2m_message_handling.h index fd6c4470d84..c41fbbac0ee 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.h +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.h @@ -75,6 +75,10 @@ enum coap_block_size lwm2m_default_block_size(void); int lwm2m_parse_peerinfo(char *url, struct lwm2m_ctx *client_ctx, bool is_firmware_uri); void lwm2m_clear_block_contexts(void); -bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg); + +static inline bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg) +{ + return msg->block_send; +} #endif /* LWM2M_MESSAGE_HANDLING_H */ diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c index d62af88200b..15dc9a9451e 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c +++ b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c @@ -836,12 +836,15 @@ static uint8_t parse_composite_read_paths(struct lwm2m_message *msg, uint_fast8_t dret; int len; int ret; + char *payload; + uint16_t in_len; setup_in_fmt_data(msg); fd = engine_get_in_user_data(&msg->in); + payload = (char *)coap_packet_get_payload(msg->in.in_cpkt, &in_len); - dret = cbor_decode_lwm2m_senml(ICTX_BUF_R_REGION(&msg->in), &fd->dcd, &isize); + dret = cbor_decode_lwm2m_senml(payload, in_len, &fd->dcd, &isize); if (dret != ZCBOR_SUCCESS) { __ASSERT_NO_MSG(false); From 821e53edec9e15d97e6248342daed14ebb97b5ee Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Fri, 8 Sep 2023 14:21:18 +0300 Subject: [PATCH 0101/1623] [nrf fromtree] net: lwm2m: Append CoAP Etag to protect integrity of blockwise To protect the integrity of outgoing block-wise transfers, append Etag option that allows client to see if the received block is generated from same content as it is expecting. Signed-off-by: Seppo Takalo (cherry picked from commit 1606d352e1c3a108762c54681bee1e9133877c06) (cherry picked from commit 47a6c5cd9d6a9284cf4a28144cbaca2766d85ad2) --- subsys/net/lib/lwm2m/Kconfig | 2 ++ subsys/net/lib/lwm2m/lwm2m_message_handling.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/lwm2m/Kconfig b/subsys/net/lib/lwm2m/Kconfig index 41ac5bcf1ce..d826e5cd599 100644 --- a/subsys/net/lib/lwm2m/Kconfig +++ b/subsys/net/lib/lwm2m/Kconfig @@ -83,6 +83,8 @@ config LWM2M_COAP_BLOCK_TRANSFER help LwM2M messages with a big body that exceed the block size will be split into blocks for sending. + To append CoAP ETag option into outgoing block transfers, CONFIG_SYS_HASH_FUNC32 should + be enabled. config LWM2M_CANCEL_OBSERVE_BY_PATH bool "Use path matching as fallback for cancel-observe" diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 06cc1b5ecf8..7aaa42c20ab 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -33,6 +33,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #include #include +#include #if defined(CONFIG_LWM2M_DTLS_SUPPORT) #include @@ -378,6 +379,7 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg) { int ret; uint16_t len; + const uint8_t *payload; /* save the big buffer for later use (splitting blocks) */ msg->body_encode_buffer = msg->cpkt; @@ -387,7 +389,7 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg) msg->cpkt.offset = 0; msg->cpkt.max_len = MAX_PACKET_SIZE; - coap_packet_get_payload(&msg->body_encode_buffer, &len); + payload = coap_packet_get_payload(&msg->body_encode_buffer, &len); if (len <= CONFIG_LWM2M_COAP_MAX_MSG_SIZE) { /* copy the packet */ @@ -406,6 +408,16 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg) NET_ASSERT(msg->out.block_ctx == NULL, "Expecting to have no context to release"); } else { + /* Before splitting the content, append Etag option to protect the integrity of + * the payload. + */ + if (IS_ENABLED(CONFIG_SYS_HASH_FUNC32)) { + uint32_t hash = sys_hash32(payload, len); + + coap_packet_append_option(&msg->body_encode_buffer, COAP_OPTION_ETAG, + (const uint8_t *)&hash, sizeof(hash)); + } + ret = build_msg_block_for_send(msg, 0); if (ret != 0) { return ret; From d96b34effcd3ec9010f7e80a564e5fbd93e4c995 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 21 Sep 2023 16:34:11 +0300 Subject: [PATCH 0102/1623] [nrf fromtree] net: lwm2m: Generate new tokens for LwM2M SEND blocks Previously each piece of LwM2M SEND was using token length of zero. I think this was unintentional. Signed-off-by: Seppo Takalo (cherry picked from commit a8f977758637d1cf3f246e2bc330b0f6382e4d52) (cherry picked from commit ce0f62fc027bcb0b46b7cc4632e827290186d1aa) --- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 7aaa42c20ab..678f358d1ee 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -307,12 +307,13 @@ STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_nu /* reuse message for next block. Copy token from the new query to allow * CoAP clients to use new token for every query of ongoing transaction */ - tkl = coap_header_get_token(msg->in.in_cpkt, token); lwm2m_reset_message(msg, false); if (msg->type == COAP_TYPE_ACK) { msg->mid = coap_header_get_id(msg->in.in_cpkt); + tkl = coap_header_get_token(msg->in.in_cpkt, token); } else { msg->mid = coap_next_id(); + tkl = LWM2M_MSG_TOKEN_GENERATE_NEW; } msg->token = token; msg->tkl = tkl; From b65d00b7190dbccc6b7998f6ef868c19fc9f982f Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Thu, 28 Sep 2023 10:09:26 +0300 Subject: [PATCH 0103/1623] [nrf fromtree] net: coap: Fix coap client timeout Fix bug in timeout_expired() function. Coap client was resending pending messages after 500 ms (COAP_PERIODIC_TIMEOUT) and didn't wait for retransmission timeout. Use 64-bit k_uptime_get() Signed-off-by: Juha Ylinen (cherry picked from commit 3ffa1d5550928180cf24fcc5eb218bbc90d0eee1) (cherry picked from commit 7edfd81f85f19fa5e8345fbf9cbde1b9502b77cb) --- subsys/net/lib/coap/coap_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/coap/coap_client.c b/subsys/net/lib/coap/coap_client.c index f8ba4283648..d096e39c62f 100644 --- a/subsys/net/lib/coap/coap_client.c +++ b/subsys/net/lib/coap/coap_client.c @@ -369,7 +369,7 @@ static void report_callback_error(struct coap_client_internal_request *internal_ static bool timeout_expired(struct coap_client_internal_request *internal_req) { return (internal_req->request_ongoing && - internal_req->pending.timeout <= k_uptime_get_32()); + internal_req->pending.timeout <= (k_uptime_get() - internal_req->pending.t0)); } static int resend_request(struct coap_client *client, @@ -649,7 +649,7 @@ static int handle_response(struct coap_client *client, const struct coap_packet /* Separate response coming */ if (payload_len == 0 && response_type == COAP_TYPE_ACK && response_code == COAP_CODE_EMPTY) { - internal_req->pending.t0 = k_uptime_get_32(); + internal_req->pending.t0 = k_uptime_get(); internal_req->pending.timeout = internal_req->pending.t0 + COAP_SEPARATE_TIMEOUT; internal_req->pending.retries = 0; return 1; From a63c627ac67cc7b2849f508113bebbf5db3370de Mon Sep 17 00:00:00 2001 From: Juha Heiskanen Date: Thu, 28 Sep 2023 17:19:45 +0300 Subject: [PATCH 0104/1623] [nrf fromtree] net: lwm2m: RD client Deregister event indicate Added a new event for LWM2M_RD_CLIENT_EVENT_DEREGISTER for indicate LwM2M client dereistartion. Updated unit test and sample for new event type Signed-off-by: Juha Heiskanen (cherry picked from commit 647fb4dc8f4f0cc09a38e223606dc239033ad8f5) (cherry picked from commit 6ce7ce6f775c45b422809cee6a05b0af93e82e21) --- doc/connectivity/networking/api/lwm2m.rst | 8 ++++++++ doc/releases/release-notes-3.5.rst | 1 + include/zephyr/net/lwm2m.h | 1 + samples/net/lwm2m_client/src/lwm2m-client.c | 3 +++ subsys/net/lib/lwm2m/lwm2m_rd_client.c | 2 ++ tests/net/lib/lwm2m/interop/src/lwm2m-client.c | 3 +++ tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c | 6 ++++++ 7 files changed, 24 insertions(+) diff --git a/doc/connectivity/networking/api/lwm2m.rst b/doc/connectivity/networking/api/lwm2m.rst index c630ea7785a..8d727d48bf5 100644 --- a/doc/connectivity/networking/api/lwm2m.rst +++ b/doc/connectivity/networking/api/lwm2m.rst @@ -318,6 +318,14 @@ events, setup a callback function: LOG_DBG("Disconnected"); break; + case LWM2M_RD_CLIENT_EVENT_REG_UPDATE: + LOG_DBG("Registration update"); + break; + + case LWM2M_RD_CLIENT_EVENT_DEREGISTER: + LOG_DBG("Deregistration client"); + break; + } } diff --git a/doc/releases/release-notes-3.5.rst b/doc/releases/release-notes-3.5.rst index 1c2a38edcf2..4f9a8ab1793 100644 --- a/doc/releases/release-notes-3.5.rst +++ b/doc/releases/release-notes-3.5.rst @@ -255,6 +255,7 @@ Networking * Added support for tickless mode. This removes the 500 ms timeout from the socket loop so the engine does not constantly wake up the CPU. This can be enabled by :kconfig:option:`CONFIG_LWM2M_TICKLESS`. + * Added new :c:macro:`LWM2M_RD_CLIENT_EVENT_DEREGISTER` event. * Wi-Fi * Added Passive scan support. diff --git a/include/zephyr/net/lwm2m.h b/include/zephyr/net/lwm2m.h index e94297d3550..6262f6d103d 100644 --- a/include/zephyr/net/lwm2m.h +++ b/include/zephyr/net/lwm2m.h @@ -2073,6 +2073,7 @@ enum lwm2m_rd_client_event { LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED, LWM2M_RD_CLIENT_EVENT_NETWORK_ERROR, LWM2M_RD_CLIENT_EVENT_REG_UPDATE, + LWM2M_RD_CLIENT_EVENT_DEREGISTER, }; /** diff --git a/samples/net/lwm2m_client/src/lwm2m-client.c b/samples/net/lwm2m_client/src/lwm2m-client.c index e20008c2f66..748f654d9ee 100644 --- a/samples/net/lwm2m_client/src/lwm2m-client.c +++ b/samples/net/lwm2m_client/src/lwm2m-client.c @@ -231,6 +231,9 @@ static void rd_client_event(struct lwm2m_ctx *client, case LWM2M_RD_CLIENT_EVENT_REG_UPDATE: LOG_DBG("Registration update"); break; + case LWM2M_RD_CLIENT_EVENT_DEREGISTER: + LOG_DBG("Client De-register"); + break; } } diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.c b/subsys/net/lib/lwm2m/lwm2m_rd_client.c index feebcaeea17..db8a84ce0b8 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.c +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.c @@ -215,6 +215,8 @@ static void set_sm_state_delayed(uint8_t sm_state, int64_t delay_ms) } } else if (sm_state == ENGINE_UPDATE_REGISTRATION) { event = LWM2M_RD_CLIENT_EVENT_REG_UPDATE; + } else if (sm_state == ENGINE_DEREGISTER) { + event = LWM2M_RD_CLIENT_EVENT_DEREGISTER; } if (sm_is_suspended()) { diff --git a/tests/net/lib/lwm2m/interop/src/lwm2m-client.c b/tests/net/lib/lwm2m/interop/src/lwm2m-client.c index 1278d807b71..983fea79f3e 100644 --- a/tests/net/lib/lwm2m/interop/src/lwm2m-client.c +++ b/tests/net/lib/lwm2m/interop/src/lwm2m-client.c @@ -117,6 +117,9 @@ static void rd_client_event(struct lwm2m_ctx *client, case LWM2M_RD_CLIENT_EVENT_REG_UPDATE: LOG_DBG("Registration update"); break; + case LWM2M_RD_CLIENT_EVENT_DEREGISTER: + LOG_DBG("Deregistration client"); + break; } } diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c b/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c index 08c0820d5e9..03d0dce7f49 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c @@ -106,6 +106,9 @@ static void lwm2m_event_cb(struct lwm2m_ctx *client, enum lwm2m_rd_client_event case LWM2M_RD_CLIENT_EVENT_REG_UPDATE: LOG_INF("*** LWM2M_RD_CLIENT_EVENT_REG_UPDATE"); break; + case LWM2M_RD_CLIENT_EVENT_DEREGISTER: + LOG_INF("*** LWM2M_RD_CLIENT_EVENT_DEREGISTER"); + break; } show_lwm2m_event(client_event); @@ -211,6 +214,7 @@ ZTEST(lwm2m_rd_client, test_start_registration_ok) coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_deleted; zassert_true(lwm2m_rd_client_stop(&ctx, lwm2m_event_cb, true) == 0, NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DEREGISTER), NULL); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DISCONNECT), NULL); zassert_true(!lwm2m_rd_client_is_registred(&ctx), NULL); } @@ -425,6 +429,7 @@ ZTEST(lwm2m_rd_client, test_deregistration_timeout) test_prepare_pending_message_cb(&message_reply_timeout_cb_default); zassert_true(lwm2m_rd_client_stop(&ctx, lwm2m_event_cb, true) == 0, NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DEREGISTER), NULL); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DEREGISTER_FAILURE)); } @@ -529,6 +534,7 @@ ZTEST(lwm2m_rd_client, test_suspend_stop_resume) zassert_equal(lwm2m_rd_client_stop(&ctx, lwm2m_event_cb, false), 0); zassert_true(lwm2m_rd_client_resume() == 0, NULL); + zassert_false(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DEREGISTER), NULL); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DISCONNECT), NULL); } From 4baf98b57ba7177839d831e35aa56696f50a598a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Thu, 24 Aug 2023 15:25:34 +0200 Subject: [PATCH 0105/1623] [nrf fromtree] net: coap: Capitalize and document COAP_MAKE_RESPONSE_CODE macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Capitalize COAP_MAKE_RESPONSE_CODE macro to align better with coding style - Added missing Doxygen comments Signed-off-by: Benjamin Cabé (cherry picked from commit fea507faee78a3927d45a700370db5c1fed19ca9) (cherry picked from commit 5585de60583fd0bb60b06cb23076e36a93f2b0e6) --- include/zephyr/net/coap.h | 62 +++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index 55776bfc6d8..5952cf77d83 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -115,7 +115,13 @@ enum coap_msgtype { COAP_TYPE_RESET = 3 }; -#define coap_make_response_code(class, det) ((class << 5) | (det)) +/** + * Utility macro to create a CoAP response code. + * @param class Class of the response code (ex. 2, 4, 5, ...) + * @param det Detail of the response code + * @return Response code literal +*/ +#define COAP_MAKE_RESPONSE_CODE(class, det) ((class << 5) | (det)) /** * @brief Set of response codes available for a response packet. @@ -123,35 +129,35 @@ enum coap_msgtype { * To be used when creating a response. */ enum coap_response_code { - COAP_RESPONSE_CODE_OK = coap_make_response_code(2, 0), - COAP_RESPONSE_CODE_CREATED = coap_make_response_code(2, 1), - COAP_RESPONSE_CODE_DELETED = coap_make_response_code(2, 2), - COAP_RESPONSE_CODE_VALID = coap_make_response_code(2, 3), - COAP_RESPONSE_CODE_CHANGED = coap_make_response_code(2, 4), - COAP_RESPONSE_CODE_CONTENT = coap_make_response_code(2, 5), - COAP_RESPONSE_CODE_CONTINUE = coap_make_response_code(2, 31), - COAP_RESPONSE_CODE_BAD_REQUEST = coap_make_response_code(4, 0), - COAP_RESPONSE_CODE_UNAUTHORIZED = coap_make_response_code(4, 1), - COAP_RESPONSE_CODE_BAD_OPTION = coap_make_response_code(4, 2), - COAP_RESPONSE_CODE_FORBIDDEN = coap_make_response_code(4, 3), - COAP_RESPONSE_CODE_NOT_FOUND = coap_make_response_code(4, 4), - COAP_RESPONSE_CODE_NOT_ALLOWED = coap_make_response_code(4, 5), - COAP_RESPONSE_CODE_NOT_ACCEPTABLE = coap_make_response_code(4, 6), - COAP_RESPONSE_CODE_INCOMPLETE = coap_make_response_code(4, 8), - COAP_RESPONSE_CODE_CONFLICT = coap_make_response_code(4, 9), - COAP_RESPONSE_CODE_PRECONDITION_FAILED = coap_make_response_code(4, 12), - COAP_RESPONSE_CODE_REQUEST_TOO_LARGE = coap_make_response_code(4, 13), + COAP_RESPONSE_CODE_OK = COAP_MAKE_RESPONSE_CODE(2, 0), + COAP_RESPONSE_CODE_CREATED = COAP_MAKE_RESPONSE_CODE(2, 1), + COAP_RESPONSE_CODE_DELETED = COAP_MAKE_RESPONSE_CODE(2, 2), + COAP_RESPONSE_CODE_VALID = COAP_MAKE_RESPONSE_CODE(2, 3), + COAP_RESPONSE_CODE_CHANGED = COAP_MAKE_RESPONSE_CODE(2, 4), + COAP_RESPONSE_CODE_CONTENT = COAP_MAKE_RESPONSE_CODE(2, 5), + COAP_RESPONSE_CODE_CONTINUE = COAP_MAKE_RESPONSE_CODE(2, 31), + COAP_RESPONSE_CODE_BAD_REQUEST = COAP_MAKE_RESPONSE_CODE(4, 0), + COAP_RESPONSE_CODE_UNAUTHORIZED = COAP_MAKE_RESPONSE_CODE(4, 1), + COAP_RESPONSE_CODE_BAD_OPTION = COAP_MAKE_RESPONSE_CODE(4, 2), + COAP_RESPONSE_CODE_FORBIDDEN = COAP_MAKE_RESPONSE_CODE(4, 3), + COAP_RESPONSE_CODE_NOT_FOUND = COAP_MAKE_RESPONSE_CODE(4, 4), + COAP_RESPONSE_CODE_NOT_ALLOWED = COAP_MAKE_RESPONSE_CODE(4, 5), + COAP_RESPONSE_CODE_NOT_ACCEPTABLE = COAP_MAKE_RESPONSE_CODE(4, 6), + COAP_RESPONSE_CODE_INCOMPLETE = COAP_MAKE_RESPONSE_CODE(4, 8), + COAP_RESPONSE_CODE_CONFLICT = COAP_MAKE_RESPONSE_CODE(4, 9), + COAP_RESPONSE_CODE_PRECONDITION_FAILED = COAP_MAKE_RESPONSE_CODE(4, 12), + COAP_RESPONSE_CODE_REQUEST_TOO_LARGE = COAP_MAKE_RESPONSE_CODE(4, 13), COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT = - coap_make_response_code(4, 15), - COAP_RESPONSE_CODE_UNPROCESSABLE_ENTITY = coap_make_response_code(4, 22), - COAP_RESPONSE_CODE_TOO_MANY_REQUESTS = coap_make_response_code(4, 29), - COAP_RESPONSE_CODE_INTERNAL_ERROR = coap_make_response_code(5, 0), - COAP_RESPONSE_CODE_NOT_IMPLEMENTED = coap_make_response_code(5, 1), - COAP_RESPONSE_CODE_BAD_GATEWAY = coap_make_response_code(5, 2), - COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE = coap_make_response_code(5, 3), - COAP_RESPONSE_CODE_GATEWAY_TIMEOUT = coap_make_response_code(5, 4), + COAP_MAKE_RESPONSE_CODE(4, 15), + COAP_RESPONSE_CODE_UNPROCESSABLE_ENTITY = COAP_MAKE_RESPONSE_CODE(4, 22), + COAP_RESPONSE_CODE_TOO_MANY_REQUESTS = COAP_MAKE_RESPONSE_CODE(4, 29), + COAP_RESPONSE_CODE_INTERNAL_ERROR = COAP_MAKE_RESPONSE_CODE(5, 0), + COAP_RESPONSE_CODE_NOT_IMPLEMENTED = COAP_MAKE_RESPONSE_CODE(5, 1), + COAP_RESPONSE_CODE_BAD_GATEWAY = COAP_MAKE_RESPONSE_CODE(5, 2), + COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE = COAP_MAKE_RESPONSE_CODE(5, 3), + COAP_RESPONSE_CODE_GATEWAY_TIMEOUT = COAP_MAKE_RESPONSE_CODE(5, 4), COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED = - coap_make_response_code(5, 5) + COAP_MAKE_RESPONSE_CODE(5, 5) }; #define COAP_CODE_EMPTY (0) From 2158801356d3cfc3ed113afdc34b0e149446d9a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Thu, 24 Aug 2023 15:35:22 +0200 Subject: [PATCH 0106/1623] [nrf fromtree] net: coap: Improve CoAP Doxygen comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve the Doxygen comments for coap.h by adding missing documentation for most of the compilation units. Signed-off-by: Benjamin Cabé (cherry picked from commit 9c7672bfbc4688b933420264170235d491c28b43) (cherry picked from commit 90f5e65dacd203db62f3e2b8b657148f06561f47) --- include/zephyr/net/coap.h | 156 +++++++++++++++++++++++--------------- 1 file changed, 95 insertions(+), 61 deletions(-) diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index 5952cf77d83..6fc21a6280b 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -42,25 +42,25 @@ extern "C" { * Refer to RFC 7252, section 12.2 for more information. */ enum coap_option_num { - COAP_OPTION_IF_MATCH = 1, - COAP_OPTION_URI_HOST = 3, - COAP_OPTION_ETAG = 4, - COAP_OPTION_IF_NONE_MATCH = 5, - COAP_OPTION_OBSERVE = 6, - COAP_OPTION_URI_PORT = 7, - COAP_OPTION_LOCATION_PATH = 8, - COAP_OPTION_URI_PATH = 11, - COAP_OPTION_CONTENT_FORMAT = 12, - COAP_OPTION_MAX_AGE = 14, - COAP_OPTION_URI_QUERY = 15, - COAP_OPTION_ACCEPT = 17, - COAP_OPTION_LOCATION_QUERY = 20, - COAP_OPTION_BLOCK2 = 23, - COAP_OPTION_BLOCK1 = 27, - COAP_OPTION_SIZE2 = 28, - COAP_OPTION_PROXY_URI = 35, - COAP_OPTION_PROXY_SCHEME = 39, - COAP_OPTION_SIZE1 = 60, + COAP_OPTION_IF_MATCH = 1, /**< If-Match */ + COAP_OPTION_URI_HOST = 3, /**< Uri-Host */ + COAP_OPTION_ETAG = 4, /**< ETag */ + COAP_OPTION_IF_NONE_MATCH = 5, /**< If-None-Match */ + COAP_OPTION_OBSERVE = 6, /**< Observe (RFC 7641) */ + COAP_OPTION_URI_PORT = 7, /**< Uri-Port */ + COAP_OPTION_LOCATION_PATH = 8, /**< Location-Path */ + COAP_OPTION_URI_PATH = 11, /**< Uri-Path */ + COAP_OPTION_CONTENT_FORMAT = 12, /**< Content-Format */ + COAP_OPTION_MAX_AGE = 14, /**< Max-Age */ + COAP_OPTION_URI_QUERY = 15, /**< Uri-Query */ + COAP_OPTION_ACCEPT = 17, /**< Accept */ + COAP_OPTION_LOCATION_QUERY = 20, /**< Location-Query */ + COAP_OPTION_BLOCK2 = 23, /**< Block2 (RFC 7959) */ + COAP_OPTION_BLOCK1 = 27, /**< Block1 (RFC 7959) */ + COAP_OPTION_SIZE2 = 28, /**< Size2 (RFC 7959) */ + COAP_OPTION_PROXY_URI = 35, /**< Proxy-Uri */ + COAP_OPTION_PROXY_SCHEME = 39, /**< Proxy-Scheme */ + COAP_OPTION_SIZE1 = 60 /**< Size1 */ }; /** @@ -69,13 +69,13 @@ enum coap_option_num { * To be used when creating a request or a response. */ enum coap_method { - COAP_METHOD_GET = 1, - COAP_METHOD_POST = 2, - COAP_METHOD_PUT = 3, - COAP_METHOD_DELETE = 4, - COAP_METHOD_FETCH = 5, - COAP_METHOD_PATCH = 6, - COAP_METHOD_IPATCH = 7, + COAP_METHOD_GET = 1, /**< GET */ + COAP_METHOD_POST = 2, /**< POST */ + COAP_METHOD_PUT = 3, /**< PUT */ + COAP_METHOD_DELETE = 4, /**< DELETE */ + COAP_METHOD_FETCH = 5, /**< FETCH */ + COAP_METHOD_PATCH = 6, /**< PATCH */ + COAP_METHOD_IPATCH = 7, /**< IPATCH */ }; #define COAP_REQUEST_MASK 0x07 @@ -120,7 +120,7 @@ enum coap_msgtype { * @param class Class of the response code (ex. 2, 4, 5, ...) * @param det Detail of the response code * @return Response code literal -*/ + */ #define COAP_MAKE_RESPONSE_CODE(class, det) ((class << 5) | (det)) /** @@ -129,33 +129,60 @@ enum coap_msgtype { * To be used when creating a response. */ enum coap_response_code { + /** 2.00 - OK */ COAP_RESPONSE_CODE_OK = COAP_MAKE_RESPONSE_CODE(2, 0), + /** 2.01 - Created */ COAP_RESPONSE_CODE_CREATED = COAP_MAKE_RESPONSE_CODE(2, 1), + /** 2.02 - Deleted */ COAP_RESPONSE_CODE_DELETED = COAP_MAKE_RESPONSE_CODE(2, 2), + /** 2.03 - Valid */ COAP_RESPONSE_CODE_VALID = COAP_MAKE_RESPONSE_CODE(2, 3), + /** 2.04 - Changed */ COAP_RESPONSE_CODE_CHANGED = COAP_MAKE_RESPONSE_CODE(2, 4), + /** 2.05 - Content */ COAP_RESPONSE_CODE_CONTENT = COAP_MAKE_RESPONSE_CODE(2, 5), + /** 2.31 - Continue */ COAP_RESPONSE_CODE_CONTINUE = COAP_MAKE_RESPONSE_CODE(2, 31), + /** 4.00 - Bad Request */ COAP_RESPONSE_CODE_BAD_REQUEST = COAP_MAKE_RESPONSE_CODE(4, 0), + /** 4.01 - Unauthorized */ COAP_RESPONSE_CODE_UNAUTHORIZED = COAP_MAKE_RESPONSE_CODE(4, 1), + /** 4.02 - Bad Option */ COAP_RESPONSE_CODE_BAD_OPTION = COAP_MAKE_RESPONSE_CODE(4, 2), + /** 4.03 - Forbidden */ COAP_RESPONSE_CODE_FORBIDDEN = COAP_MAKE_RESPONSE_CODE(4, 3), + /** 4.04 - Not Found */ COAP_RESPONSE_CODE_NOT_FOUND = COAP_MAKE_RESPONSE_CODE(4, 4), + /** 4.05 - Method Not Allowed */ COAP_RESPONSE_CODE_NOT_ALLOWED = COAP_MAKE_RESPONSE_CODE(4, 5), + /** 4.06 - Not Acceptable */ COAP_RESPONSE_CODE_NOT_ACCEPTABLE = COAP_MAKE_RESPONSE_CODE(4, 6), + /** 4.08 - Request Entity Incomplete */ COAP_RESPONSE_CODE_INCOMPLETE = COAP_MAKE_RESPONSE_CODE(4, 8), + /** 4.12 - Precondition Failed */ COAP_RESPONSE_CODE_CONFLICT = COAP_MAKE_RESPONSE_CODE(4, 9), + /** 4.12 - Precondition Failed */ COAP_RESPONSE_CODE_PRECONDITION_FAILED = COAP_MAKE_RESPONSE_CODE(4, 12), + /** 4.13 - Request Entity Too Large */ COAP_RESPONSE_CODE_REQUEST_TOO_LARGE = COAP_MAKE_RESPONSE_CODE(4, 13), + /** 4.15 - Unsupported Content-Format */ COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT = COAP_MAKE_RESPONSE_CODE(4, 15), + /** 4.22 - Unprocessable Entity */ COAP_RESPONSE_CODE_UNPROCESSABLE_ENTITY = COAP_MAKE_RESPONSE_CODE(4, 22), + /** 4.29 - Too Many Requests */ COAP_RESPONSE_CODE_TOO_MANY_REQUESTS = COAP_MAKE_RESPONSE_CODE(4, 29), + /** 5.00 - Internal Server Error */ COAP_RESPONSE_CODE_INTERNAL_ERROR = COAP_MAKE_RESPONSE_CODE(5, 0), + /** 5.01 - Not Implemented */ COAP_RESPONSE_CODE_NOT_IMPLEMENTED = COAP_MAKE_RESPONSE_CODE(5, 1), + /** 5.02 - Bad Gateway */ COAP_RESPONSE_CODE_BAD_GATEWAY = COAP_MAKE_RESPONSE_CODE(5, 2), + /** 5.03 - Service Unavailable */ COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE = COAP_MAKE_RESPONSE_CODE(5, 3), + /** 5.04 - Gateway Timeout */ COAP_RESPONSE_CODE_GATEWAY_TIMEOUT = COAP_MAKE_RESPONSE_CODE(5, 4), + /** 5.05 - Proxying Not Supported */ COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED = COAP_MAKE_RESPONSE_CODE(5, 5) }; @@ -170,15 +197,15 @@ enum coap_response_code { * To be used when encoding or decoding a Content-Format option. */ enum coap_content_format { - COAP_CONTENT_FORMAT_TEXT_PLAIN = 0, /* charset=urf-8 */ - COAP_CONTENT_FORMAT_APP_LINK_FORMAT = 40, - COAP_CONTENT_FORMAT_APP_XML = 41, - COAP_CONTENT_FORMAT_APP_OCTET_STREAM = 42, - COAP_CONTENT_FORMAT_APP_EXI = 47, - COAP_CONTENT_FORMAT_APP_JSON = 50, - COAP_CONTENT_FORMAT_APP_JSON_PATCH_JSON = 51, - COAP_CONTENT_FORMAT_APP_MERGE_PATCH_JSON = 52, - COAP_CONTENT_FORMAT_APP_CBOR = 60, + COAP_CONTENT_FORMAT_TEXT_PLAIN = 0, /**< text/plain;charset=utf-8 */ + COAP_CONTENT_FORMAT_APP_LINK_FORMAT = 40, /**< application/link-format */ + COAP_CONTENT_FORMAT_APP_XML = 41, /**< application/xml */ + COAP_CONTENT_FORMAT_APP_OCTET_STREAM = 42, /**< application/octet-stream */ + COAP_CONTENT_FORMAT_APP_EXI = 47, /**< application/exi */ + COAP_CONTENT_FORMAT_APP_JSON = 50, /**< application/json */ + COAP_CONTENT_FORMAT_APP_JSON_PATCH_JSON = 51, /**< application/json-patch+json */ + COAP_CONTENT_FORMAT_APP_MERGE_PATCH_JSON = 52, /**< application/merge-patch+json */ + COAP_CONTENT_FORMAT_APP_CBOR = 60 /**< application/cbor */ }; /* block option helper */ @@ -239,25 +266,32 @@ struct coap_observer { * @brief Representation of a CoAP Packet. */ struct coap_packet { - uint8_t *data; /* User allocated buffer */ - uint16_t offset; /* CoAP lib maintains offset while adding data */ - uint16_t max_len; /* Max CoAP packet data length */ - uint8_t hdr_len; /* CoAP header length */ - uint16_t opt_len; /* Total options length (delta + len + value) */ - uint16_t delta; /* Used for delta calculation in CoAP packet */ -#if defined(CONFIG_COAP_KEEP_USER_DATA) - void *user_data; /* Application specific user data */ + uint8_t *data; /**< User allocated buffer */ + uint16_t offset; /**< CoAP lib maintains offset while adding data */ + uint16_t max_len; /**< Max CoAP packet data length */ + uint8_t hdr_len; /**< CoAP header length */ + uint16_t opt_len; /**< Total options length (delta + len + value) */ + uint16_t delta; /**< Used for delta calculation in CoAP packet */ +#if defined(CONFIG_COAP_KEEP_USER_DATA) || defined(DOXGEN) + /** + * Application specific user data. + * Only available when @kconfig{CONFIG_COAP_KEEP_USER_DATA} is enabled. + */ + void *user_data; #endif }; +/** + * @brief Representation of a CoAP option. + */ struct coap_option { - uint16_t delta; + uint16_t delta; /**< Option delta */ #if defined(CONFIG_COAP_EXTENDED_OPTIONS_LEN) uint16_t len; uint8_t value[CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE]; #else - uint8_t len; - uint8_t value[12]; + uint8_t len; /**< Option length */ + uint8_t value[12]; /**< Option value */ #endif }; @@ -277,13 +311,13 @@ typedef int (*coap_reply_t)(const struct coap_packet *response, * @brief Represents a request awaiting for an acknowledgment (ACK). */ struct coap_pending { - struct sockaddr addr; - int64_t t0; - uint32_t timeout; - uint16_t id; - uint8_t *data; - uint16_t len; - uint8_t retries; + struct sockaddr addr; /**< Remote address */ + int64_t t0; /**< Time when the request was sent */ + uint32_t timeout; /**< Timeout in ms */ + uint16_t id; /**< Message id */ + uint8_t *data; /**< User allocated buffer */ + uint16_t len; /**< Length of the CoAP packet */ + uint8_t retries; /**< Number of times the request has been sent */ }; /** @@ -563,13 +597,13 @@ int coap_handle_request(struct coap_packet *cpkt, * https://tools.ietf.org/html/rfc7959 */ enum coap_block_size { - COAP_BLOCK_16, - COAP_BLOCK_32, - COAP_BLOCK_64, - COAP_BLOCK_128, - COAP_BLOCK_256, - COAP_BLOCK_512, - COAP_BLOCK_1024, + COAP_BLOCK_16, /**< 16-byte block size */ + COAP_BLOCK_32, /**< 32-byte block size */ + COAP_BLOCK_64, /**< 64-byte block size */ + COAP_BLOCK_128, /**< 128-byte block size */ + COAP_BLOCK_256, /**< 256-byte block size */ + COAP_BLOCK_512, /**< 512-byte block size */ + COAP_BLOCK_1024, /**< 1024-byte block size */ }; /** From 7f84783145206883918b27572dcd32f25698e265 Mon Sep 17 00:00:00 2001 From: Juha Heiskanen Date: Tue, 19 Sep 2023 13:53:10 +0300 Subject: [PATCH 0107/1623] [nrf fromtree] mgmt: mcumgr: Image management client fix Fix broken MCUmgr image group client. Signed-off-by: Juha Heiskanen (cherry picked from commit 0c6a3faeb4ae0973aaa31980f8e8fbef8f5b28b3) (cherry picked from commit 964580907ec9c9618256a3b1ce2d534b01305c78) --- .../mgmt/mcumgr/grp/img_mgmt/img_mgmt_client.h | 4 ++-- .../mgmt/mcumgr/grp/img_mgmt_client/CMakeLists.txt | 1 + .../mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/zephyr/mgmt/mcumgr/grp/img_mgmt/img_mgmt_client.h b/include/zephyr/mgmt/mcumgr/grp/img_mgmt/img_mgmt_client.h index 6ee12fb5a61..8cede40d64e 100644 --- a/include/zephyr/mgmt/mcumgr/grp/img_mgmt/img_mgmt_client.h +++ b/include/zephyr/mgmt/mcumgr/grp/img_mgmt/img_mgmt_client.h @@ -40,7 +40,7 @@ struct mcumgr_image_data { /** Image number */ uint32_t img_num; /** Image SHA256 checksum */ - char hash[IMG_MGMT_HASH_LEN]; + char hash[IMG_MGMT_DATA_SHA_LEN]; /** Image Version */ char version[IMG_MGMT_VER_MAX_STR_LEN + 1]; /** Image Flags */ @@ -76,7 +76,7 @@ struct mcumgr_image_upload { */ struct img_gr_upload { /** Image 256-bit hash */ - char sha256[IMG_MGMT_HASH_LEN]; + char sha256[IMG_MGMT_DATA_SHA_LEN]; /** True when Hash is configured, false when not */ bool hash_initialized; /** Image size */ diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt_client/CMakeLists.txt b/subsys/mgmt/mcumgr/grp/img_mgmt_client/CMakeLists.txt index 693891896d8..cae17e865ff 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt_client/CMakeLists.txt +++ b/subsys/mgmt/mcumgr/grp/img_mgmt_client/CMakeLists.txt @@ -13,3 +13,4 @@ zephyr_library_sources( ) zephyr_library_include_directories(include) +zephyr_library_link_libraries(MCUBOOT_BOOTUTIL) diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c b/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c index b0e38640e8c..9ab8ee02dcd 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c @@ -126,7 +126,7 @@ static int image_state_res_fn(struct net_buf *nb, void *user_data) goto out; } /* Check that mandatory parameters have decoded */ - if (hash.len != IMG_MGMT_HASH_LEN || !version.len || + if (hash.len != IMG_MGMT_DATA_SHA_LEN || !version.len || !zcbor_map_decode_bulk_key_found(list_res_decode, ARRAY_SIZE(list_res_decode), "slot")) { LOG_ERR("Missing mandatory parametrs"); @@ -138,7 +138,7 @@ static int image_state_res_fn(struct net_buf *nb, void *user_data) image_info->image_list[image_info->image_list_length].img_num = img_num; image_info->image_list[image_info->image_list_length].slot_num = slot_num; memcpy(image_info->image_list[image_info->image_list_length].hash, - hash.value, IMG_MGMT_HASH_LEN); + hash.value, IMG_MGMT_DATA_SHA_LEN); if (version.len > IMG_MGMT_VER_MAX_STR_LEN) { LOG_WRN("Version truncated len %d -> %d", version.len, IMG_MGMT_VER_MAX_STR_LEN); @@ -277,7 +277,7 @@ static size_t upload_message_header_size(struct img_gr_upload *upload_state) /* Write hash when it defined and offset is 0 */ if (ok && upload_state->hash_initialized) { ok = zcbor_tstr_put_lit(zse, "sha") && - zcbor_bstr_encode_ptr(zse, upload_state->sha256, IMG_MGMT_HASH_LEN); + zcbor_bstr_encode_ptr(zse, upload_state->sha256, IMG_MGMT_DATA_SHA_LEN); } if (ok) { @@ -311,7 +311,7 @@ int img_mgmt_client_upload_init(struct img_mgmt_client *client, size_t image_siz client->upload.offset = 0; client->upload.image_num = image_num; if (image_hash) { - memcpy(client->upload.sha256, image_hash, IMG_MGMT_HASH_LEN); + memcpy(client->upload.sha256, image_hash, IMG_MGMT_DATA_SHA_LEN); client->upload.hash_initialized = true; } else { client->upload.hash_initialized = false; @@ -395,7 +395,7 @@ int img_mgmt_client_upload(struct img_mgmt_client *client, const uint8_t *data, if (ok && active_client->upload.hash_initialized) { ok = zcbor_tstr_put_lit(zse, "sha") && zcbor_bstr_encode_ptr(zse, active_client->upload.sha256, - IMG_MGMT_HASH_LEN); + IMG_MGMT_DATA_SHA_LEN); } } @@ -485,7 +485,7 @@ int img_mgmt_client_state_write(struct img_mgmt_client *client, char *hash, bool /* Write hash data */ if (ok && hash) { ok = zcbor_tstr_put_lit(zse, "hash") && - zcbor_bstr_encode_ptr(zse, hash, IMG_MGMT_HASH_LEN); + zcbor_bstr_encode_ptr(zse, hash, IMG_MGMT_DATA_SHA_LEN); } /* Close map */ if (ok) { From 63548546a8126ab0b0c7c780cf9add80d00c2c73 Mon Sep 17 00:00:00 2001 From: Juha Heiskanen Date: Tue, 19 Sep 2023 13:57:25 +0300 Subject: [PATCH 0108/1623] [nrf fromtree] tests: mcumgr: Updated MCUmg & smp client tests Fixed broken MCUmgr client unit test. Added test_ -prefix to tests. Added testcase.yaml to test trigger test run. Signed-off-by: Juha Heiskanen (cherry picked from commit 3e0ed42427046d988601b2222f63e16669657c2d) (cherry picked from commit 39a684cf591712aa0c5669217e818d295f070179) --- .../subsys/mgmt/mcumgr/mcumgr_client/CMakeLists.txt | 2 +- tests/subsys/mgmt/mcumgr/mcumgr_client/prj.conf | 7 +++++-- .../mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c | 10 ++++++++-- tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c | 12 ++++++------ tests/subsys/mgmt/mcumgr/mcumgr_client/testcase.yaml | 11 +++++++++++ tests/subsys/mgmt/mcumgr/smp_client/src/main.c | 6 +++--- tests/subsys/mgmt/mcumgr/smp_client/testcase.yaml | 11 +++++++++++ 7 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 tests/subsys/mgmt/mcumgr/mcumgr_client/testcase.yaml create mode 100644 tests/subsys/mgmt/mcumgr/smp_client/testcase.yaml diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/CMakeLists.txt b/tests/subsys/mgmt/mcumgr/mcumgr_client/CMakeLists.txt index a0f76554629..20a96480514 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/CMakeLists.txt +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/CMakeLists.txt @@ -14,4 +14,4 @@ FILE(GLOB app_sources target_sources(app PRIVATE ${app_sources}) -add_compile_definitions(CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER=1) +zephyr_library_link_libraries(MCUBOOT_BOOTUTIL) diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/prj.conf b/tests/subsys/mgmt/mcumgr/mcumgr_client/prj.conf index 46835a49dc7..461a0ec9477 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/prj.conf +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/prj.conf @@ -12,14 +12,17 @@ CONFIG_NET_BUF=y CONFIG_BASE64=y CONFIG_ZCBOR=y CONFIG_CRC=y -# Enable mcumgr +# Enable MCUboot util library +CONFIG_MCUBOOT_BOOTUTIL_LIB=y +# Enable mcumgr client CONFIG_MCUMGR=y CONFIG_SMP_CLIENT=y -CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER=1 CONFIG_MCUMGR_GRP_OS_CLIENT=y CONFIG_MCUMGR_GRP_IMG_CLIENT=y CONFIG_MCUMGR_GRP_OS_CLIENT_ECHO=y CONFIG_MCUMGR_GRP_OS_CLIENT_RESET=y +# disable default image group build +CONFIG_IMG_MANAGER=n # Extend System Workqueue stack size CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304 diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c index 5bd784a3954..aea03935fe6 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c @@ -24,6 +24,12 @@ static struct mcumgr_image_data image_dummy_info[2]; static size_t test_offset; static uint8_t *image_hash_ptr; +#ifdef CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER +#define IMG_UPDATABLE_IMAGE_COUNT CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER +#else +#define IMG_UPDATABLE_IMAGE_COUNT 1 +#endif + #define ZCBOR_ENCODE_FLAG(zse, label, value) \ (zcbor_tstr_put_lit(zse, label) && zcbor_bool_put(zse, value)) @@ -117,7 +123,7 @@ void img_read_response(int count) zcbor_tstr_put_term(zse, image_dummy_info[i].version) && zcbor_tstr_put_term(zse, "hash") && - zcbor_bstr_encode_ptr(zse, image_dummy_info[i].hash, IMG_MGMT_HASH_LEN) && + zcbor_bstr_encode_ptr(zse, image_dummy_info[i].hash, IMG_MGMT_DATA_SHA_LEN) && ZCBOR_ENCODE_FLAG(zse, "bootable", image_dummy_info[i].flags.bootable) && ZCBOR_ENCODE_FLAG(zse, "pending", image_dummy_info[i].flags.pending) && ZCBOR_ENCODE_FLAG(zse, "confirmed", image_dummy_info[i].flags.confirmed) && @@ -126,7 +132,7 @@ void img_read_response(int count) zcbor_map_end_encode(zse, 15); } - ok = ok && zcbor_list_end_encode(zse, 2 * CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER); + ok = ok && zcbor_list_end_encode(zse, 2 * IMG_UPDATABLE_IMAGE_COUNT); ok = ok && zcbor_map_end_encode(zse, 15); diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c index a15e82f17a6..bf70f178fe7 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c @@ -27,7 +27,7 @@ static struct smp_client_object smp_client; static struct img_mgmt_client img_client; static struct os_mgmt_client os_client; -ZTEST(mcumgr_client, img_upload) +ZTEST(mcumgr_client, test_img_upload) { int rc; struct mcumgr_image_upload response; @@ -108,7 +108,7 @@ ZTEST(mcumgr_client, img_upload) response.image_upload_offset); } -ZTEST(mcumgr_client, img_erase) +ZTEST(mcumgr_client, test_img_erase) { int rc; @@ -130,7 +130,7 @@ ZTEST(mcumgr_client, img_erase) zassert_equal(MGMT_ERR_EOK, rc, "Expected to receive %d response %d", MGMT_ERR_EOK, rc); } -ZTEST(mcumgr_client, image_state_read) +ZTEST(mcumgr_client, test_image_state_read) { int rc; struct mcumgr_image_state res_buf; @@ -153,7 +153,7 @@ ZTEST(mcumgr_client, image_state_read) res_buf.image_list_length); } -ZTEST(mcumgr_client, image_state_set) +ZTEST(mcumgr_client, test_image_state_set) { int rc; char hash[32]; @@ -199,7 +199,7 @@ ZTEST(mcumgr_client, image_state_set) true, image_info[0].flags.confirmed); } -ZTEST(mcumgr_client, os_reset) +ZTEST(mcumgr_client, test_os_reset) { int rc; @@ -217,7 +217,7 @@ ZTEST(mcumgr_client, os_reset) zassert_equal(MGMT_ERR_EOK, rc, "Expected to receive %d response %d", MGMT_ERR_EOK, rc); } -ZTEST(mcumgr_client, os_echo) +ZTEST(mcumgr_client, test_os_echo) { int rc; diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/testcase.yaml b/tests/subsys/mgmt/mcumgr/mcumgr_client/testcase.yaml new file mode 100644 index 00000000000..99b9fac34ad --- /dev/null +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/testcase.yaml @@ -0,0 +1,11 @@ +# +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# +tests: + mgmt.mcumgr.mcumgr.client: + platform_allow: native_posix + tags: + - mcumgr + - mcumgr_client diff --git a/tests/subsys/mgmt/mcumgr/smp_client/src/main.c b/tests/subsys/mgmt/mcumgr/smp_client/src/main.c index be1a3968274..7b6ad8eafa8 100644 --- a/tests/subsys/mgmt/mcumgr/smp_client/src/main.c +++ b/tests/subsys/mgmt/mcumgr/smp_client/src/main.c @@ -32,7 +32,7 @@ int smp_client_res_cb(struct net_buf *nb, void *user_data) return 0; } -ZTEST(smp_client, buf_alloc) +ZTEST(smp_client, test_buf_alloc) { struct smp_client_object smp_client; @@ -56,7 +56,7 @@ ZTEST(smp_client, buf_alloc) } } -ZTEST(smp_client, msg_send_timeout) +ZTEST(smp_client, test_msg_send_timeout) { struct net_buf *nb; @@ -72,7 +72,7 @@ ZTEST(smp_client, msg_send_timeout) zassert_equal_ptr(response_ptr, &testing_user_data, "User data not returned correctly"); } -ZTEST(smp_client, msg_response_handler) +ZTEST(smp_client, test_msg_response_handler) { struct smp_hdr dst_hdr; int rc; diff --git a/tests/subsys/mgmt/mcumgr/smp_client/testcase.yaml b/tests/subsys/mgmt/mcumgr/smp_client/testcase.yaml new file mode 100644 index 00000000000..49971116251 --- /dev/null +++ b/tests/subsys/mgmt/mcumgr/smp_client/testcase.yaml @@ -0,0 +1,11 @@ +# +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# +tests: + mgmt.mcumgr.smp.client: + platform_allow: native_posix + tags: + - mcumgr + - smp_client From db7577339d36b3f44997d478cb10207df51fc23a Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Mon, 2 Oct 2023 14:53:41 +0300 Subject: [PATCH 0109/1623] [nrf fromlist] net: coap: release non-confirmable messages Only confirmable messages need pending tracking. Non-confirmable messages are released after sending. Match incoming packets with token, not message ID. Ignore responses with non-matching tokens. Remove unused function send_reset(). Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63378 Signed-off-by: Juha Ylinen (cherry picked from commit ae072e80c219d5fc81b8ad885fd7c9f22e3d84af) --- subsys/net/lib/coap/coap_client.c | 79 +++++++++------------------- tests/net/lib/coap_client/src/main.c | 4 +- 2 files changed, 25 insertions(+), 58 deletions(-) diff --git a/subsys/net/lib/coap/coap_client.c b/subsys/net/lib/coap/coap_client.c index d096e39c62f..e78aafd6829 100644 --- a/subsys/net/lib/coap/coap_client.c +++ b/subsys/net/lib/coap/coap_client.c @@ -308,12 +308,6 @@ int coap_client_req(struct coap_client *client, int sock, const struct sockaddr reset_internal_request(internal_req); - if (retries == -1) { - internal_req->retry_count = DEFAULT_RETRY_AMOUNT; - } else { - internal_req->retry_count = retries; - } - if (k_mutex_lock(&client->send_mutex, K_NO_WAIT)) { return -EAGAIN; } @@ -332,16 +326,25 @@ int coap_client_req(struct coap_client *client, int sock, const struct sockaddr goto out; } - ret = coap_pending_init(&internal_req->pending, &internal_req->request, &client->address, - internal_req->retry_count); + /* only TYPE_CON messages need pending tracking */ + if (coap_header_get_type(&internal_req->request) == COAP_TYPE_CON) { + if (retries == -1) { + internal_req->retry_count = DEFAULT_RETRY_AMOUNT; + } else { + internal_req->retry_count = retries; + } - if (ret < 0) { - LOG_ERR("Failed to initialize pending struct"); - k_mutex_unlock(&client->send_mutex); - goto out; - } + ret = coap_pending_init(&internal_req->pending, &internal_req->request, + &client->address, internal_req->retry_count); + + if (ret < 0) { + LOG_ERR("Failed to initialize pending struct"); + k_mutex_unlock(&client->send_mutex); + goto out; + } - coap_pending_cycle(&internal_req->pending); + coap_pending_cycle(&internal_req->pending); + } ret = send_request(sock, internal_req->request.data, internal_req->request.offset, 0, &client->address, client->socklen); @@ -368,6 +371,10 @@ static void report_callback_error(struct coap_client_internal_request *internal_ static bool timeout_expired(struct coap_client_internal_request *internal_req) { + if (internal_req->pending.timeout == 0) { + return false; + } + return (internal_req->request_ongoing && internal_req->pending.timeout <= (k_uptime_get() - internal_req->pending.t0)); } @@ -547,35 +554,6 @@ static int send_ack(struct coap_client *client, const struct coap_packet *req, return 0; } -static int send_reset(struct coap_client *client, const struct coap_packet *req, - uint8_t response_code) -{ - int ret; - uint16_t id; - uint8_t token[COAP_TOKEN_MAX_LEN]; - uint8_t tkl; - struct coap_packet reset; - - id = coap_header_get_id(req); - tkl = response_code ? coap_header_get_token(req, token) : 0; - ret = coap_packet_init(&reset, client->send_buf, MAX_COAP_MSG_LEN, COAP_VERSION, - COAP_TYPE_RESET, tkl, token, response_code, id); - - if (ret < 0) { - LOG_ERR("Error creating CoAP reset message"); - return ret; - } - - ret = send_request(client->fd, reset.data, reset.offset, 0, - &client->address, client->socklen); - if (ret < 0) { - LOG_ERR("Error sending CoAP reset message"); - return ret; - } - - return 0; -} - struct coap_client_internal_request *get_request_with_id(struct coap_client *client, uint16_t message_id) { @@ -631,7 +609,7 @@ static int handle_response(struct coap_client *client, const struct coap_packet */ response_type = coap_header_get_type(response); - internal_req = get_request_with_id(client, coap_header_get_id(response)); + internal_req = get_request_with_token(client, response); /* Reset and Ack need to match the message ID with request */ if ((response_type == COAP_TYPE_ACK || response_type == COAP_TYPE_RESET) && internal_req == NULL) { @@ -655,17 +633,8 @@ static int handle_response(struct coap_client *client, const struct coap_packet return 1; } - /* Check for tokens - * Separate response doesn't match with message ID, - * check if there is a separate request waiting with matching token - */ - if (internal_req == NULL) { - internal_req = get_request_with_token(client, response); - } - if (internal_req == NULL || !token_compare(internal_req, response)) { - LOG_ERR("Not matching tokens, respond with reset"); - ret = send_reset(client, response, COAP_RESPONSE_CODE_NOT_FOUND); + LOG_WRN("Not matching tokens"); return 1; } @@ -795,7 +764,7 @@ void coap_client_recv(void *coap_cl, void *a, void *b) ret = handle_response(clients[i], &response); if (ret < 0) { - LOG_ERR("Error handling respnse"); + LOG_ERR("Error handling response"); } clients[i]->response_ready = false; diff --git a/tests/net/lib/coap_client/src/main.c b/tests/net/lib/coap_client/src/main.c index a3862852c21..bb9d9fc38c5 100644 --- a/tests/net/lib/coap_client/src/main.c +++ b/tests/net/lib/coap_client/src/main.c @@ -392,7 +392,5 @@ ZTEST(coap_client, test_unmatching_tokens) k_sleep(K_MSEC(1)); k_sleep(K_MSEC(1)); clear_socket_events(); - zassert_equal(last_response_code, COAP_RESPONSE_CODE_NOT_FOUND, "Unexpected response %d", - last_response_code); - k_sleep(K_MSEC(1)); + k_sleep(K_MSEC(1000)); } From bd268c7f0e0b6c301a34df53c0d41075dd844d3d Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 28 Sep 2023 13:28:33 +0300 Subject: [PATCH 0110/1623] [nrf fromlist] net: lwm2m: Allow configuring update period Add new configuration value CONFIG_LWM2M_UPDATE_PERIOD that allows calculating update period from last update, instead of calculating it from the lifetime. In runtime, server is allowed to change the lifetime of the registration which causes update perdiod to be effected. When fixed update period is preferred, UPDATE_PERIOD config is then used. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63216/ Signed-off-by: Seppo Takalo (cherry picked from commit fcbf3786cd8f40829dfe4cd3b1421c63437a47b6) --- .../api/images/lwm2m_lifetime_both.png | Bin 0 -> 17612 bytes .../images/lwm2m_lifetime_seconds_early.png | Bin 0 -> 14563 bytes doc/connectivity/networking/api/lwm2m.rst | 47 ++++++++++++++++++ samples/net/lwm2m_client/overlay-queue.conf | 6 ++- subsys/net/lib/lwm2m/Kconfig | 12 ++++- subsys/net/lib/lwm2m/lwm2m_rd_client.c | 22 +++++--- tests/net/lib/lwm2m/interop/prj.conf | 2 + .../lib/lwm2m/lwm2m_rd_client/CMakeLists.txt | 1 + 8 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 doc/connectivity/networking/api/images/lwm2m_lifetime_both.png create mode 100644 doc/connectivity/networking/api/images/lwm2m_lifetime_seconds_early.png diff --git a/doc/connectivity/networking/api/images/lwm2m_lifetime_both.png b/doc/connectivity/networking/api/images/lwm2m_lifetime_both.png new file mode 100644 index 0000000000000000000000000000000000000000..1cdf0bbb662965d525b6b24f6dade674d9b2f0fe GIT binary patch literal 17612 zcmd^n2Ut|wk}e`Bh)PZ>N=BmOAVG3&K!P*^LIX`~GBh~~LK9VjWDyZ0C&@X9f|7HP zBp_KpBniIN2|T5ATC1x53ae^=qSRF6E?u~C0Rsc$l7hUn zItB(N1YGCfoCDt;uCLd?pEHi?a*`PNo!1sIFi7m2WS~yguBH|UI0gfc)UPWBZccMs zM<)gzX$Ed?n4KMmi3QBe0cP#UVFPypL*Tx(t%-%H1>EG<9Bxi-9(GP4c5XpUP9X*! z30_|C#m&dT&%=5D*L;{6+~$NJ#Ma#cfq*e^%kpt>0#Y}jTwDx1lHf|&!p7MZ{B;%N zH{j=G23Hbxb_lpO+(^j+tSigMBf!DKkA6f+UK66sz%2!?5f)Z(@J9}AY-NjnM9SR3 z)*6h+a&ZZ8aH9W#K@FHG%)#O}5@;Tfa0f>VTbmOWxH$MZgnn%n?gTSCVO~?n#K^(S zK?UMyWzS{cqNIa>{+i?DW(WT@#{`bFFa`^9Gw{eTa7qBe=ns$7iO|3g8yMKou`tzu z9N4*jQLs1>9=o|SmjKMjQXOhyq-HOtaNo`OSjfLqJEdvuD(3*RGl$rkz!8A3iR;Pc z1vmwM5jAo9HNwR!c*2aC!|6gN>!JrVEZk3a#07SX7KWL#g$dm8L;Q7A+rq@j{MTGTzLV{t zXUoGa%*;<$=HfiLV+}iUd@p8 zOwgt$>0)l-1lO>GfzZGs?E<_u82hu;nA+Mn{T1(Mg78yh{Mxx4?B9?0(@4R?_h+o} zoM7!Yi{KJC8T;KNPUoFs@^|$A?*Q`OrD@*3Xj)56T0&FiFN$?Ax3xBM1_t^M#s8b1 z`(3pR+&m^QxS**qcr`f;Lgbw{_ko>=tS}-X35R_SM8iy?(fPu9s4g) z&IzD?GsC~A1%%||Y{?V>cRdLc=vZ(XF^mx~M@I{^_#)7{n z{`4&HTP)x{O@)4UH~*!v;N+n5&)kg}@Evw1fcUGwJ~_d_j7~G;6Ce8@7-j!Hqx-{( zf0yj3nf)%=Q&T*(_W#r^GOxrH*-Dl#%eO^3aaSi&;OXz{NIY((=*s#b3LyAD(`!ot^W(vk<%02-wIK` z+v@S%)6&v2=g@W)a zGcAS0hck4h7gJMHgDJ$_QYpkq&Zg25DO2yagyEj04L+l$Ol>N2G0t_K?Z|3qe>uOd zIUvQuY#zDeSxTk^bI;B}zAESx($ZLd?sK%)7A-A~^~a}}=ru!6`gK}NTI!QeC9XX0 zoM}4KA5)|o=o9*J|Mrs_>kKM`;PJO$oM7LRk34S{{vSVr#c?o+AT-pAgoFfVPCk## z)o=XqgTRjfi#|b8yqE4hLjxbY)N&vjiH#SdT8gLcd-18}Gt4P9GW2%TB*fDcl3(1! zx_94#;oxAso^`Iaoh1kQ@Z2TDq}NUNq7orJghHLN#gT9Hk-Ov4rSvktLyD5jJ`kM-K}nGr%d zS;3UgIrM1R&8di|WsQ4?KUs=2zx}o0?CP*_WS(pDt@es&BnYtC4q( z3L77uul_MwW^Fa;xfQ;>IyO}H$=%9oC||#GC;dXf`5T_yr9;uo8V=st$GQ;j1&U;- z4YYdg9h|Y%Dcq$asjl%{%nR}P-IMPF+6Fp@``cEp158_qAg{93vdtB}*5?y#ZO&6U zJ=XVFEqxIh&5|JLa~D4ZC|R76;ITQ&L)m;3izzV#D#=mvRq|ja^j0oVLB1>4T*X28 z-qwOJ%|M>6z|IcoJ?M+HUE{Z5MLGFZ?P3QjJY#MP$*Z5ERLf=~?|iB|+PBKlF8Jg? zi-Y$b?8F-Cy?YI>zx#!h^?;Uk>1e6d7*N{U<|o(L@Kx|Y8Q+jzA4lb9qN{hjYaA^$ zCXFM6-o~tMcHAo0Ht-s#yjC=-ha7<;8_t{;ygOX)^D~6|llyXB*=pGs$3jYTwrp+I zc~~ zWKiF$O~#@3CHKLIpz&d|=t7^|4KEXDg8!OO0He)E@S|T850vtf+`q3_@R)VJkqy66 ziM+j1*vztdp|6gwM|E2T4gYsRzS0_EZ@wYSF@qV&dd{3Zr|G${@Z6_Nr^Iwb$1EAn zu3PqIA;lwKlGAx*xaYFaX9A{xPi_lTOmS5%>uYT4^jO`@nMp=wDQ+2|DEBWff|4qz z2N{#iY1b!QCMWE42(`a`AF~w}AjK2G`~rqb2lI5RU8WSrocbWi7|=3AJnIeG<#%+E zZ&dFb_9Mrv1$J!4eeN9Xz6@=X4EQ=?;Bz<^Kq)x`SavbOE+P!Gs5<;UmZ$WLV-4T! z>x9I^b0gP1R$%yde%J+?(~{wC@Y+p@?_3Wc#k}PAG}3%#Z|9Rom;I2p`bJS+HY#)moTc8$g? zGLw@i(jPqc+(hM7uT`nMp0k|nrc(L^zDq=p&9fzT6}+9R#O;=pI4cYgMY)d&D6mYr zQbem~=*K<^Os@FH6=4)n8(WXSpXsl33a{rjJZcaZc?HlKO~9=b%f{6%*>s`hJ!b$V z^MGiOIql_l=bg4bgbRE!j}-k5eYKk-J1)!^N0!pK|?{50|$vL@#teV0oEbqd$akYYreofo>Lx8rgzDmYwN&M!xfSY)Zi~z}7zD7HPr)18uekviKe=x& z%^h8O5z>0eirD&Dj+a}(Q?&DM@dMz#cAxnXT$#Mj3HaUH9q$333*(4%e6igIRERQa zonWjl19H{l`-oYd*THwvNFzdEjkVlwd8ad)oCAC%)2VChm{#k59&toErQw$AsMQea z_P>NE&U(O?G=FR}{ zNV3yrhZZ(qOVf!95=HXOr-gDjFx9H}ox6&dV$-^6Q}F_lA~MoSx#tAbC$tR75V!kz zE$v|{d?t~M{l1BT_ui|L&2(Z&%beX(7gN5n>rz&xo-*l7xcI8Tq-S5*h-so)8py8NuRR|Iydm86Xm5dBpEqzi%=vY98p^d;Z#D7Co9oSM`Lva#_M$xx;l6LJoolm+BQ>fD$2OwXM*WU+1%pD%Sy)clcdEgtwGV5L`45CakEDS=VL$X`At#??9$tu$G+FR%#MtGHhf_2u%wMXe_shPlg|&Qo>XeX$3QS)Y+P4I* zpXD$F+`5v5hbl3cJ(jv&Qxn;@63TZT5YpGMx~gh?Wm3CoKx3TXnYb_$CNI-q&vMyM zJ~^8;!PO;yCpJxWiRw82(Z|Flh9qGc5l-P(Ycdetq(6g&)i|Y#D3XyWgGN-mBP7f? z&OBOaQ@8V=CbQ29q&0qw=CUb$VCJ*=Zo1i|&SU#YgsGEIrSWQI2T=qIJ4mWDL2@S3 zdNt<*LxRzO-kdJfzg#GxQ-Oc&nq_Y~DpY1>$$x4>X--L=kNgbbO)?-iqbK18bwrR2 zE1nqWapssB0P;6Q9O0RQr{*E9XR}<7Lx;DiP$a<)s*zNZQRK^vl0&)QHzd4R9UU;-Q%O$hglgSxiveBrW%uQsY4DlVI#=CY$i3t_dc5lNd z*W|RfD|cV}Xfmd5yx5c2GUgpRkIJBZ9T{h;W7mTfq)e_izvQ|va)A9}hE8mRB1R>$Y05D^sO^G3GL;p8de-V>2;?Gb}>kn1E{HcNHCvXCp=D&ZyI10^TybYb@Zl} z0imN4Wj_%R9p=ukPDi%)Mt?nbZ~NE6*>Yer?mwP>TlGg}&`aFa|65v~YQ84)g7h@u zCh(&te*B90eO^u#>NHCy2?M^mQH_P}G%rWbF;{e0&bIlbK=6%CN8O{z8Qm^_!jv@i zd%)P!@hWu4`b9{*5p0e0;wx^V)5YYu0ZQo0^OqRW0z-e)I04GArLw~Q*xyrS;B@~3 zx1(E%E3)~HZm`I>&2r)8MQQ3Am`g5u-MuBWYPZ4KuZ;5qTEoN_I+IuZ&R;L=xK%&C z|80@Dq&KI+o`KV-1?Qm4=g2sS3K<7U;APGqP^*-oegZfp8p+Mpq`}d1c+c=1q!q*C zm5zDN%Y(?~O9CXcx^py`l(^rP209*i@4?4lK~%X9YTfzGyQzDCEP@Gu6ma++g%GiW zM6b8O@9b)Nlu9x1U!yklhe)g8LfD%N*}W|(4Nn=A^ls!B)YmN=KRl0*bOu)B)t8Nl z3uGT%cuvdtf?Pu=W4)ce=SC|!LoI*3TD6=X=<&pX#R{{;^rM6SVhgcqE`dUpS3&NX ztW8=18o)83CY7y-NO=`XZC{=hZ4Ut!vnvKpX~sgjI%_n2nSEY~*JH~ta@X9GI;GR1*ohb{^w z9aR;KBOL`$#5*SQDg?t1fj89qN-0?w9?myt7y4jzw3JTGh?M3smiNJ`08^FE-W>Um z%Tj+MhqzFTVEL#tWm{@N4w!}B|n zsMYVQV`E>Zn|b_k`gYo%rCD-d@}Z$WKfL^rkcj{}eTC05dV76x5|?Rh@Gg;`6IR6* z9$p_fLac`IbiTX5jF=?009MqCUXIP-ub5p@gLU3o?G0%3gjw}0B$o&hL z+WO8h`i>v@_+d?0V`k629O}5A*FEFm5&Z>YY*NTYrwBMJN?aYM`+4)Hm@RN#xUJMQ zsB3EtPB;n|Fb7^HV5x|1YwA|my(p1JA2T&=5|pH1EQ?ZmAFvtN;~v~o$HXRwM2oG^ zYV;;7!D-cKG4-pFr81#pl`_Tlvu_#Pa~=@$VTO|5Lejd=h6|MG+Sc+}wraR-Qd4&r zTrVU#dM&NdbQL;~Ly7t0!30EL;&XsT&}Ayi3<7tnaKbn-uPVo(?<*sHhY?BYHQ?CS zT77sy#~qa+*{k`0mVlbmZPUceqGGLTIoD%n%}9e0>um&;m07ZLEb#|9Dre33{@Wu1 z(dLTCgLw^MREDSdq7LD^sD>K1tt7iqpPz@;0J?78x{+<+;`QE#D;sS$T>P`Na_-r) z*0m>s1Td=V5fk;Xhm&Fay0`GW+8}S?om(Qmb;u8XxPb=N{D=72{G>QxmwY~O7RU&B zu|tMV8wpe2@+zS+;`oz7sPKUYY<-!0K}%65;erhJ{XKbJnH*8eVqPK$pMt@<3h$X4 zeY_5z{GEr*EW>Uj}vcb#O%2>kLd@y zGn4H1-vr-X)$C88=JYx8WJ&_(WwYiW{4Qt!r&j@Edx1-ccqQ=bEIZdz_q8pi?^iix z>HfH9;N@%v%hsm@caY(`e5_-B> zW-Ey0^(%IT*GR}J^j#+S)&?~8=p+pXb9GdLpW8Lz&KDq_n1{&EzNVmkED6G{z9g0d zG~wLkYhTDp(JmG@06M&hdha9saSO+Of_lez z!65L9qu@aL2y5t`Rw$+)@aQ8TTp)y33Lg&SXsf0%UkFd*4i@)C$?I*}KO(ar@y$we^f74#9N>zdJ#e=Wvgr~#$aVhG z-I(IO#5`MxKG=Q#Ul~*wn!XfSe&as881vR}_1Z-Bs76LTBrZwI#wH!&X%D4EK zC{V7UDmqYwTumrT#`$L5|N05K{_!0c>sWS9{!+^9QMB^p1|^m2l;0!D)u3olovN;0 z#ogqP>^x{szN~NGN;+5!?+B@xYMb*oB8mLzdn1Ek-XHI}&*8Qst?UP{(Wp zu&Tdt=w#iNHor>up{kz`KOBIwa@{I8o*_X6M+mt` zpN|^0E}uaA%yJ+f+scBbN0mtn@_KhS0VQqsh&|g-_A0Mfq@+xs67_-X)&qobTSVz4{^5p8h=2%k$k9%cYXoWrR6Xq;MqQ3sD^JO< zUb{Wp1%jn%`M5(UmB&iany9ZN^{!Kw=*}>Zzyk$oUhC2R%VN8RO!A*V1PNx-_p5<8&J&$atYIl$0MLQt{qIh~)<-#M31fDbqEuUskaU|ISG zj#pKv&u_2VzR|j;(>lI95ZG>9V#)6NEBQ!6zd*d5e6CxKw8^{gH6LXMGv>!kIi;&2 zZjU(C14FY}g+-;<9GUt3{Mw8^ArdO+y3tC`I@ml_)#&~%hV-+a_zp8$rpu()&^8m+ z;XPgJn6jlej!PM0#4odRL*oaHe_rlNh5&;&To2JM8Ket?mQYIJz|;(>Dq~%JIAbduKI7*#!V@E?psMV%+`<~f^ z;$bCb#M8dJU!pIjD3iUsF6us9yYp!oc{7VSahq+ZLG^GP{|b`iC{6h12T-gw)U~O6 zWo3dS@lJz(o!eh6LBP{X8Xu$1vJxrTP&i?X`B}Dt^jmeiO_U4-JBum>Z}0KK ztc}VWY(f=iqs%ce&pyP%rHpQTk5_W-A!-7@t5B+W)E}FfPey|GF5`!}XiCDUF6qR) zvj-8bpoTTV)pjlF9xoS^FlI%$Zxze7ZqL-rNX0oXBT@OVyi?nECv+YN)E6F{I^!j0bHr z7h8J9&Cm?aWqXdbT*tzV*fPB|l=F=TU(W9H)36q{ScaBoff85;S6H6;X6(iKm+g!R zulZsh7u4;yLwLn{&e*%1q0}aw8h(|2KsczEhU+NcvY)P`EWS8ywwUsf-<(3TVq8UR z&xE{Vis}CC;KG zB*(+*GQ@7al<={)WycQJ5HcHU-JV5{sX*W0Osf3t=+i6ZA|6;9x8$Q?2{PAl?@FSp zin+HuZ$6Hv!PH~n=d~^ZbXwnQFzgW=tzHD0>kvhTXl)HcMJ(Q1kFzGX(3I#5OJzPPK&6* z=)$x6py?BP^s{Wl5Z zl=WKpHVmHor{R9W`sh~gk>Rc;=RaV7<1-Ot_HDT1nSEsvthdM3Ur15>#8A@gT1f?= zYq*R61uG$v?O;N1w(UH=+3cfI6qQq%uZ7PS>>YyH@lZxGVlpGWO+?vc!71Mwc1YH2 z682@9*0&+8*Ojh0QpR$znN&7ik2V*+t{1-PvVA$=z2D%11CKCe3+f+ z+Hec8$J=wRU%Fq|KstbcLkLAWUA}13*DwV$@Ye-jVN=PqekmJXoFeLRFI$D8Cpzn> z#lJ_pDMQb1s?nKi#XX6cAc=c=-ZVMG$8E@#qNl|LRX|r3R@dZ00Et(BFGI|PQ5a_; zEZXM3{E$FHwQDcLP{ovBw`+?O(kSBvj`7YTz0~L)-Bpnv0&xx~#@j5WeNMP{yoaNV z7FAStMYMIT`N)G;Rb_WkvA9C|cGoe_ku#z$huKb^Z=QYB(km54PDQ`nuc*d5{gm!Y zM5+R&0uO`#cDxfqLX!%sd%hk{AqCGuVPzBiQLqs3!mFSFfV}sm&^R7KYagEUj?Pd( zdxk2QW`>4`fz0Nu^X;C1YW!zc$j;747s_t!^!GW&kAIElmupEj;G70UkF>aG5Vkt86|R-ya7zL)QvYK0b&sAF*GB)~pkO2eTR>5?JE1+a zr)4xaF~XVmON5H{(9=*xB#AObLGAZZhq=b~W}9=ZL6e^zw)D%+DQJdBw9Z^}a+@Q9 zfU<=nqvg*BGl@82%Fl++5OGo{1Hfijku)JWedST`X?B8kZ@KSAjD1GWaLp;u_L9b(ZOLiDO{kAEDm`5Lysq<#xQm zWYWjLZxm)7KsYO6ZZYGQ&r2(bOwHF%wE%Gd=hxJMYS96i!hoHuuO z9DJF#?*|*|m{+G_T%b$f)_+OxNa<_5CuU=Fe%m6OXBd-z8LW9hB2od`BVD<;lUtC* zB&)Hk@6Z#V^awlQOhQ7OJSR^tpt)$}FrJKEHOXMDxTf>A*c?e>~J^pguRZ$ud7 z^_&{1RI_9>fV#74npEC+-qJX4s@}RE5GnYMcKh44v?%^&t!KBVpWNZlbmdks)ae*N zI;jPia=vAol*n3;p>D^rJD44%jU^D!w50VWAZ&8n3xmIC7OO5_yB3a~Y_%Dc{EzmE= z0Bs77W8eI~vyZ)HmM`b3*2ZaXW`k~_=YzP^J%Mxhjj>`3TD;RN47-=` zt_y3f%PNyX;<_t^Lpr_+qKHIFn|BJKJuso##;K2k$One@3XDa%pr9a)`G7wCDo+a~ zES!2bI^0Ao?Y)6egCD7X#Y5a>;-7ElBOw>@1h-gdl#HdhvTuOt6*jGyXs2?=^tTzqge-^6m zc8K($vX$X9*Zf!+pzj_|lh=9q+nWUvKt7Z}e+c$}#;3Y_PJ}?hZ@D8B2Yy}F(9Oz> zL`Fkw*}e?QeZz;Gq!>j2i8JF`H-a^gbSz%vEZg?y zC4g_~U?+SE{q~iChuWUlu+vl^P%8q}ofyKSZ=;}Vmx&XF(-lyAll`KwC>`cqx`rAq z(+?Eog@o=6Gwn6aX>F!~kaKwV#f;-`8%a=KK37g;e+}vrzigK`wS;p{)UiM15`JdD z2pg>mP7`A+A*_udvEqxTB2&U{SOsD3yL8Q-X!lBZhJ6I}O#iieSN!|;Zf%Jfo#T?t zWi4XZ%Rm_U))+RsHz#4A#e7x7IjtpLNb_~`5N2a!4$X<%dW|Qsl56#bJ(TZajS{ax z4@u2!XawjShEY1&d=R3vG+$8M4CEA{QcR+0j!fg38*m>$bq^UgC*aLpF{G8 zhM3?nrQ;@bdyF`wGbSL&q*^G6zmffsN0FY!ZEZsqyvv@iszYdSKY-$3e@F|-S0-Ir zbIuif+1S^^?&0VjO>{K+$(A2>?YDGiTCUkc=Mn^=k6AZ#17WwEI%Bl^#h#gm+z)*% z^2Z*Y(1U{1d(*ow{@7<4C`d6|vZrmH^n84Aq@RL19etuq;2&L|;47e1__{Q>o$j>j zL!bayd4eD#WwF2_^Zb?vNiG@wZq+xOAdr>#W+_YTxHCkCZabvKYrRjP_cg3qY!t|| z4h=_q|Dl@O_JW-u$+B4Dn+>`Q_L>%uXYubFlBT|R=2qNgo5^whk<mM7ozPF&U!f^W`cmo; znj>*SbPMZDb}^eRW+hfsfQH)+{=fq)Y3e$#xtTE}iyIbh0I4#O3L!#-^jIAZps}Y; zPUwe8_)eQsL68)urWoD3^CKbzl~zLYTE-EqY?e6sq^A?NG=;&q2^d$r=aJ3NC!Sh` zUi#b>NC64@2^K&p8d21~?G5|m|bxw&GNT?)kE1bPNC<<^?TIE1g6!4o7eR8rH>P!a{3DqhFLd>kqcK|i3! zp5BG7TBh=%i_^_IwkT%5*Erxt9Fm$;7YOh!7$+J?%2uYqm4=`NRqPz|42{aqpjXQ5 zW4bR(Nf4ZE_|%T&VP_@_c(+VC7U0SxQ5HLg8S^eV;G1uN=i39og#&0QXs(HhZx={Y za{vh{P-&y3p$Obicq%Omf4wmF>hM8~7}G;i?fdWVmru01 z@6-+-O=Lq}St{4;ovTKO-$?xNWvguUyY*_g_QI%r(8^lMp2x^!*~)tTgonHw)#OLy za$)4Q;6`_d&sO|^ZFhG@{SUu`<+kVSrOZ5J&`2rW`&*38p@ERS<2Uhi&>gJ~Q|(tY zk1b*Q(+BI4sEn&Y_(jZp^IGDbhMQQ`={~lJT&56s&1RBV^woy--ir*MuNFq?pa2AFis%wCxqXxxlYB0_&h)Ae~D~uJzPO8 zkegVG1C-jLQF`+-0K|-)Rz4xq<4y)`tsZHuM1cnrYi=vp2PQq|W2B?n>{PmD^K5F* z@lO?7P2BnD4SST__p(Iv>*s4@C97oLKZoL3AIgTazSffCeLq98(U~~|8q_Ul6d)2+ zunSoHl)03(2qEB2)u0KFg*^V5c8TvRtT#r(EFv>WA?1 zTr+Nm71P;$oG2J^cRqq!mycAaPx$O_oVO}orkTjKEzKP&N(hBdt>~Rui>o{vGza@R41?YWjNhlC z9IZo5*;k5~cZO5zGRHn>-zgioXV6?*UKPt|usdSQR($K(k>SGiTI-S05*9YJBMk)I z0ZsF?_FJ1++&T&9!najX&z0}pZ?q95>QrptSu zp*vdnlM?YVp9&#xxqkdgZh76oD5$-!%7%vUUm9RA?GbJZj{Vp08W{F7#mGPxTG2-Oewr&K;`4fWDDYQ}k|=^aa39`tJt zUm$SPiB%@Ow_^0Ydn&(=e`8u5GVn&)%P~1G!;`C1)&$|j^q`1Rv3@VFHsK(1v{buf zehgt|W?&azI$l;PD(W1f-}_V9!?e>QCjav8(ZNrhpuxn^(wFOn6Fax5Uz*Rf`;F%0 z)#)XQZZ}Ci{a zZ{dB#qAm|Sp9+z3Ai{d?_?44s5S;>N(=*#2i)#i(VQEkzWwmqwYKeezrR}-MBCQFW ztDpj>Oljt8J+SN?c%d!p+I=18Tr%K|!GwxyuYdHOH?4BC31U<;O zjrO|9z~1_G<>x{#`Xvy7wVy0vvVa%5#pBVP!>!AyOAB(T{piisfA8r7OVFw*17WnL z=hP4@q-vsXJeiP-LBI9D1-PIPNC|o12%=CDeH?Hx+oou~-$|q2j*-I3mQRJE#Ts%c ztpNQl${(sw<@b}s1G_cZAso2`Q`#AeN#j zVT7l$p@Eh94m=TZ5jye=-!J4kGNH8k{qOhW>!j9ijiUd;nF{;cEf$OJ?=9%%*YolW? zd;$IX4=&+NT0hNcfOP5McF?gE#|i;2xn#Zbjj6?Po$fDdmF4$1Vj7(7jvcH~(D(cG zu1_!}kXIaET*y^bOq|RtN3t<*>nlo}ttGfxmgpT8{yh5@Gw^6UKztnh_aqn!GAh#f Il7{~O3l2&u4FCWD literal 0 HcmV?d00001 diff --git a/doc/connectivity/networking/api/images/lwm2m_lifetime_seconds_early.png b/doc/connectivity/networking/api/images/lwm2m_lifetime_seconds_early.png new file mode 100644 index 0000000000000000000000000000000000000000..119005ce5c7f0ea96030961a6f8c04cbf6ec4d11 GIT binary patch literal 14563 zcmeHu2UwF^wT$?!Eua+&eSR%rnpNA<6#MxAxkrulM^-xUr$mfqlpJ z(a_Kwfa_|R($LT$!1p4CJ>YME-@RGzLF;9zqd`;Ba$VQFyQfu4Ax{XeTtvaf?P;Qd&k_QeIs8 zteK=dL`EGdL;VAlfXYFww&?AgQSRFe5m7P%;o*j|MA_@3!M@tEGG`=YzW}9Akv!PyBpdS1wM384z5`0 zEt)PkEC#G-OG%xPkfi^$ZrXY!rM7-tr|*V zpzcmG($e-wOC6M*yt=Nr{uT|M;DOqraYXr`9l(at5E&RmQXMd+{*%$%RvP%>ZU+R~ zRHiY|gSgZd2lTe`&Y~q{^-xf0O+ybuf;q+r^xi$SVxo_VC?9( zE&LhDGh0j@30o^t(6ifzamMXzw7oBN0g3kCmPiUnOI3!mH`)>9wSDu}5*~|n!=pX^ zy6Av)cSkvFn{u0@9S(=}{VSOh)@}QE+cX~FOVSS;Z8o7H~5yhDWX(?q#Z zwY{Uq?R|hZ{g2=Kr#5hZ#>0Px9kAS{C)>GsZ|iYu!3$5=Q7p>cQJrcZpb&dIFO-&@ z7tpPSBly^iUTWyM;4yCCGW9EU-PjI~N8zY(0i=}#p{(JB$6;MjJ9Yt%u7SgPyE|?& z0Im+M+u`v4#x9%d+928iFDf07<*&cC{ZLA7hso~?TSq}T{>^dzp}S3W{>KLVhZ%KH zATi)^1aK(df4JC=hq?UbT{~+yl$#wM?ekX`wcGY|=Reu~HS+)NL%*+3bF48I4U!?q zb3iTNkW$p^R5R|xuH5$Tot?a}-Z%%;_FYuMf9-nzVoTYbE&jbNfkB;7`2UG5Wk62W z25D+XIsdV7wy8G*>|as-Ee>V2wC3{<=Ql+;qk*pin}M`WEe%d6Jepbzs7m`SCh#af z5cj|P{g#JoV%@MfU=(+(JFvM1sETg?v}EUocBV##0|;LfAk_dx1dj%3Onv(T2JPrb z4LuEC7c?G)^sob^K}O3LWNona*QjyAy5s-u?^K4U9naX3+{5la@9{g8LPqwlz9zHn zYrjQ=)S2zI-$P=DZpSBo_x}GLhx|`j8u~X&n;UDXo5B8OSey$MWA6`;NaE zekc3i0p0 zjA9Sv3B+Vei`~5`E$~9t>Hg1FU*%SnR)Uf9hcV^#CtnBGuXHag_7^=~p|}Qi`&(zO zR0aj4i@Nrd*toJYsL{}|T&1Dsr3txDU&xDi$MWY&bSe!wK9$w-PYPPilw|rXVp;~Z zr+aCMO?w3-LZ~-`-!yc(Y+gIeXc@lqUWKk+ZG`+uPlL8U_zzY*^wEMm(NzNV^mv2w z38LovW-l2pvG+&Qh=w6A(mhq@px$=~5D99UFt|NX;Ru7TlM)5ivmL~#UI~Z z%=~fO{lPKW%k*p0;uRmBmsAbyTX}7CRLcIkd9hWO|H|yl*!-=YD~s(q-E{%JsWQ&D zYrnid^RY~M`NIp_pjA|#YiZrSLdCxKJr{%PCR*>P{v4N>YReAYn0w75=k>*4<)hbF zOS$_%P4E2Z+nHN3Ee{?#y#C_$w!=sjb4O*(Wr)(AtD~4vm_!FopVi68i^x;i710?C z?`YTI!4zcpUmjvCvM7FJX-jxHTeo7XI23l$ZEbNPL}jCq&8W;UU7=bvNUuINfz)F5 z@cT%d(e#gn)-xL$Es9^K3q(e11kF=Q>Xxn6r%D^#-bC}2)XQNgAACOsItQ*Vm)rOb zbWtiWsSEO?p{4J`cWUQS_la##fPov>}Qde%v@?30b zVJv-&-&FKamRGBCj|3n|Vw3frG!r`9Tn-mP6s}+0bx;y>UZixqZe`G`&&=u*M2+Xl zw~%tTUb3>LHCl1{K`7f*S=a8WW%wgQg$aT6p~%y2zcyBUTf3J(o^JRtH2+Y5Z*4j= z_@}46V2s~Xab?gNF&zPg|yKD16hc)A=J+@8BIZCm~ zOCWEgPsEC`UIB)~FBNh(q#-NEOxFdSnxp1%X=N`9J>#$3J}UD{S%+M7FR{_PVPkng zw%+sS`7A7m(JKtRh`FP0jhD2TelZHAU2@J0tcV=cJy_-^Hcu3nEFFJ;8g`O>!$jbX z*dad5fy|90x{8w46~hbp-6Q1C)3~V841H?y zXW31si)7apxrQ-F>VRJP?r~VYdNk3xUoN%zHBay~kssNv+&qIGs3})o>G$d`v8ip$ zi(ufwz2Q6Rl~RVtD?Z5>F8~|Ln<1XOqeSkCF-$4LB%Z=Hi%+)a-ei*-l_4D*J%z|n z>cuFEFbk(b!!;pPovL)i1{nkAl!_e%o#xY}+2g z_}IDCN8UX44CHddLW^R>`fTlbtYEr+UVm1nZrtrX#>dN|{8mSk4%?*s@UXxOyP!=~ z&X>#~5LS0S;R~98gM_oFrRX_kiPfau9n3(gM01*ox7<-)PIgV4zgQNPKOSWnZx%TB z@^G!VGNx!^i2yk&cKD5$zr)n$n>>bM2>)D!yhemH;idkY41ni6Z-Q*`LWdDdN-!y3IQChe+j1dBZe|UlRG@AA^6@MJkz> z+78rxDLqLiAij11+rZ^No-L87i}gXjHRzeb&yBokzkmMmh5DF7@devq3kiMztgBsu;AdMda<}VgisWCOeoxGGG^DRUR>swwns#VBPiJPphiN@ zj&rn+x{--8(V#>Kt&ElT*m^ljiA)lEK9pmGR%5;iXNnM}v|lp|>%hZb`41alJ>ezz z>8p*R-n9sMb%oQqr62X5;x(%IEh*B-n0LbV#4*>mhKz4XG5MwSYt3BntSh261t)11 z4Vseajg~}0ti4ZLmA%2x7S50^=JLZkEz%A(EnQ&@&q%mph@7{~x)-Sa1xj$phM2be!kj+9KX#Nx?ij3^iTG;Fhvv5Gs32#*mjC4|-LywhFC8MF&(4j%^8;CZu z3XRU!(`*f;_8Mxu`{<+dg>RX@EMr9%9%)h9BIVbkK}U=~<;d<0(T}UgX_Q`@3PwgA zWJo)M%~&U!tK4K>$UQ|Hr1E_wB$($#wF)l+_TWyK#nCE|De`wocp;QjT7%StuY8J| zp*jC$??UKm%<9!qjUW}=!14B_OsAw!wNGR%qDWeU2-=;ci8oeVAT-m6e`ED4o)|@Y zUQfo&4mnm?`XGsVfszQ=q1s_l<^C9Rne7WLj3+;Xm7U26YXi;ihj6HGldw1g_Gvmv^?xoL0g){kZ$`h_)PwV;QM*ZQo3%YV3zvYIo*J97 z?lk_Mf>)t03HXWQI}0JKYAJM@aM;eCjdyAO3x&{%eY!Z&Q4HGP7&pbJKYo`_>-N*} z_S_lOU#oY#r$4j{8m1koUhcTW@S6Z?M25x5uD7;~ewU#yA5Dk{ zYclBP*zzT8Y6Jw(pk38PR{as)t@adXA(?@y1JUrO-{*#lL60m^(^>5`rX>cv{um24 zQ^*N0;^Z>`y@lxUwlxF?rz#O1vE_qKKORj>He=lN{3PF}P#W^cu0u&wPh*I9$`kzK zbH%VlvDN5xl6KUwDYGc(Zdj^6FUu)lwsRSsR4ehG40#!OxVAsfXNJ;y&m>pc_9j#+ zoR`HAnELGN8y3LSQYR%*&FqKmKx`-5cs$#EKHw(wrQ5d&LpR`950C08fT`ws!qccT zgDxkvZ#`gS6Z~LzlPmG@U0tN1)&(Fg-&LsjJ|FIVU`E&%LYX)MY8Q=p z?LFB^8X+{&0_)v0*`Lp>i z`SZrZ+|+)(cdV$Fo4F>ue(?!ULH zi&Wz!?ExaG3DR9zIpMX7ZVt@ZFC9)yfU~gR=#cpao&>`ee;jzsBvHld>e_p7-|8ju zlUR`36QYI=Khh+j{sc6lD0j6K z+`{la2D3e2aFo8cU_d>llU&dbzbQ(25nDk^x}s1rFT#MC;d&fk)8d&8HUzy6HH7*~ z6o+rg7?hS5fzmAf9WR3eR)2Hg=z%|I=!di~y^P>6OuO7uGLvJd`Nw`wn-h|k)cR}m zf_Yicz^{on@4Nzq$&#4uF&&0M@w{`jD1X=g~4*(5NT5%3NASdiK^Xun|YDdx@)#VQk z%e~H-y@}TD6S414*MGNH{PuL$+Y7ZlwgJ6h#>RYovT%Fm!Ha_^m4(>Ov6gh#y(c`b zDlfc~@fpv)nOL0fYz+HVuZ2V_AHR)2s?p>y#En7CRhdYz7gf%C;Q6>6BC7f}$j z2a{&yQ5mNXtU4ziwiMehfV-1RkiFQ3jp>(%FP`#BuY#hORTT#dq_> z&^c$(BwK&d0Kf`RD&19`#nwG?eQq-AlSQR&xlwYW3)Qcc%MBmizt~W(IAw72mA|TG z?My}LOx5u1WzbtDRl@=Y0#^nGNI&$GB+7#~rY@pXdRk}d*Jr1KECvHtZ2IgY#Sdkk zMAZM08A&z&h>_Z_tFGB9YvZ|?%)n)-4F@Icpi-)GKt&u8U`pNQlkm7kL36*wYR>ma zBW2lk8u17#kFqx;_ohE4yBLRSW<&OJ>z+CRrY;iKm2c0M0W4GXI15;ndHv`5*O?d{ zZciLh?t*uhd3X&30R~-<72SwfeL*z&dFe~|D409FublyCKwrSux*6aIvf=T~@9xUj z1e7OxkGDM&e;WJv*LuS*uPXu$gV&NGmjOoLs`~54<648rRoR{k4nk=j*Vx!g(?HKl z1=9j1Nd?mYlEPm+pPS27_B0~0{+0F&M>hyM+7#;8njqZER@L#US}-lp_5{py_jUrz{Sc+1 znS$GJoR_C&cN|OGP~OK&Myeb5<1$VLcaOCwuUx2PxXjmueV747^DWVz>^R9G9(!Ux zw^G%u>G3rHfTaY5W`77A?)#pRRh$g)m%u&~+#+al&N_es zdja5dLF=8^U1C$D5~T9{7-C`&%uIvqFjEsp9Si~BRL!UAsc@6`1Ub(@ab8{GcEkzv zoIWR8SN3kd9vfe8Rw40gO);^cu(vN+n+ONqeUx(|NRL2-OW&8$l?dKgN&-O6yQozF zt|deROyfzYVck@h3j7|?n6+ete^p_&YB&w5Ymos|P-c?rmWEquVon-y?L5dhAy)ci zXx$c`xN&wFK)r2uKW=cW3YR65*L*qGIyM;~WI@RWR*gl5BiDahbC- z=ESBI4;&v*BJD5w#XI#CM`QE&2((YeG6MSLA~+|n5aCP({HLt6kh#)DmZd(dOyXIG ziV8A=D6muP@OGc`m)moScWXTVjDf&YD*D_NS8jpy^d56j*eW;n4s^o5i#qWo=Nu6o zTt$*1>nYjeY6XVr%~}yZ$Ss1q0BV{Sbwuhprkog;!>szF4Q7E)_r2#*GWO-rEqtHX z1QFgEqvm>rU3{Tpj0}$}F~1J8PQ7?#?ndM(0<1sr^u^g6<6}nQkBGA6*UzUwTLmg3 zwDp`gP^QE}lU(g^_mLq96Sm{0$%*mCaW%!2q*l@4%V1m*W!P?`X#k?w{2fgbwrL~ME!WZ z0qd!9gnfay;-~_FOzb}bQ!i7VYtv*-&`&8_5~BUS+=sQ{Da#W!F@x%|o`rFi8FN@Y zYPy=kOzHOjeB-dRineuV#JmXImx2+iCkruxu-j#R`q#YRas0Y7lyZHoLtPdy`tosC zYrPAyr=gkbQtcPu5kfFstb zkW_)&4JeQoKZP<2;^x@xVw3fiI0Cy8tA1KSlAseQIy`}$8yeYRML{ZE?x#&tOFrwy zeLVWqo7x)83uL`CmSMz!vhPN4x{OAwCJ5Fsj*W7n`~wW9pNw17 zRE~9WVoLS0ATJ{%6LnI|Ds$8_qDi*!9DZktEkYuQAE9@z=PexxwqUf-hK+&3Kb55? zmk2k!4|q%tU_uUmd_wT@t)`yt+w+%_!^&+h#+U09_j%3ChjU{$s_;@tMyIxz-Xz+_2CU;y0VXHf_41G;)gMw zA__4j!ld)oJpQ?}vHB7Z6=$nnU|KQY!4A5V2kH{7uaI~IE*X0gQKPPNOjt)d=0KCV z3Yob3oHZnt6|;ek>F`OrZL2F0%K~u}BiMvjuO_-lXWg(hVW@kVL=s*rkkdP{!4A)u z?COroVJGE*rgZl1Ax91@Q_I`Cv8Uj8_CVxfyI3_59@u6bHRzQfneKl|3ug`WX`&m^ zNs;Et{d7}*UUpUB+LW`}>0LxI3bzGagI*0oW>7|anYi3qzoNZH&w7HOO%b6~3LfYH zEl21g>t#ZwsA=LmZx&_`1~cL9g3-+5tmBqoZ1)Dr@-D;lb$5}5=}g(4m0yLreQ1NU zUS^%+JP+eD1WyyZDOng+@l#fx%9THhbH_?xS_!b&e4j~g56te>C{U(MHJ((Au`jh< zOZ<^a^eWYLS1nWQn7-#yy*NZ!Le1`)NusD`b|K6 zukPebvEwt7jF=o&Jr(m7BNg%pmwXoed5EXbVOZv(ua#RF1DZC;QRJ{TmLARYPHfE} ze5m=fp2{6TSu%0T+b^G!7naLjK7SIS$8C9had%_j+M?&)^LkdDdtjGhnIDU#l5S^r$H(A}=L%)Pj# zCqHT(V_+%s8}K22YNwx|s}@cIk1>+0Kg8=6zciO;vszrtzirFfb1iYoL*H8+UN@NP z9lP(eM1rR>6wO0gL7;f{c==!CmTaE@}qr#N}A7c@F%#uF1 zOc`0H+Gi0RV5iw%Mn8amo8P$RINByGogx5QV-GBMC@6db8lvw6Uv!6-V z;lq&j&S$xo8-!Ty=7cFsn^a$jJp_ZA|IkHNyb$N8Yp&o*R&uXCSZPKy7xJ4@fJH2N z#gvRY>$K~IH&l4aq&G?!Dm+pfCb^b(-S=!eEvC@TSMKtpZrAyxqkUehKRZ3CpcRlcpM26b}2yAxVm;GqI zcI+oTXcAGFk^|EykS$n0me4sP&m5T)5If^))~StQ)w?a=Pm;IMqp=)8L^jNal~tiX zcec~72BnAhlw1G~R2Dt?W*1|8MNb(-KwhM^=bm3{mql)cc)~CdBbc5}JRyW(6l|Ey zEQLahG{Y-iX|hVe_S7xh6*$wpi)`&TQBTowzDT;GAg5uX-9V0?(cwiNw5$oh)hP=R zl1{nmBVN<{6$}@2kHVtMx=yXOEHB9p&e1j>?zDJBY*HMTE+6c4*d3jJ_19dk!p>-@ zmr4`Kt?oy2(G+zbke-RjyTBnv-J{vwKn%i= zZ}vuiQO^SJEFfvWRRLuPi_-<&VDuC%Ca7ce!Bbl^1qXx?!1m}EM#KO)?SpC#IzE7+ z+`wOQ;RGt@rW@rDY!p#)(ADQ(nA%79X(b2c58GP%aZRcwK;yqNpPTVR|~ies@G%GZ6ADi*TYOpP^?m z*J5@&&`F-s+9Cj=&fQdd2!ymJtMk?X8;sxP62A$s8bMzo z3urJ^4aUSa#6G*KHpLr#n}*!@1bB;Hh8l{IZOCjM$xOovY!7pL>LLLSbSk8o6CCKn z98r#e9UwDi1~r`rsAf<*2PEIO1kLtj(WQdg`+-Zq4>6;Xz10Z*y{N^E0gs0HNNsnSpeI=5D-z2J!ClPnzI=z3Up@~{gF zFPS~cGbaJC4x!Hx1PTw?)iT2(44yHO7>r4WfH@C`+}j5ZQ$o;k1&G%si*syYHGu8I zj10VlJ_?Y+F;i!6p8P~3NLLOkb97bSuP(8+)HV&E|chZu>Q6B z{hpPEH{67Im}|ZB@qqOxm=DEsZ>3IzJtP$XJO76MI39&fU0Ewwo@Z*cnjZrLN&$l4ckRIO4?WzOb#E%Loo78inqYh@ZBk_` z!2tML`{UB3qe^jtgAPcZbQfj=g52DSm$NFmhk4rBsG&+gOs`SIO(tqN{t!@Zymo56 zMwS)>u`gDv6v}wM!~b|6vB35bDl_1RL@8e9gT+5~HVyVaLHJ-wOS8 z=JM`g46Mc7DDQimt*qi2BioBQ6L6U#aJ+5hO2E&k z*86L(Qme)|kD=#}HGG6y0v^+g{~W+fE8?oMtDzU*~uS=?gbJ(FdjX!SK{*YtH{ ziyr>lm*aaVaY&wr1!Jc@u_GME&>G1RXMFD+rRxPz{*D=7r-}6B@Q#&_#bwz&7cQTE zmyT*EU3)*umEK#PvHWF2;}(GUoX#IUz(qq2g%zIVGYB!$@*tA!x!DM# z+7gSf5TH)`RCNG6AeRey5CJ5aA;6}F5deH%`A$~cMD`zqvpsLb-%zUpnf)_2j}@3B z+3%{IYh<(&omWFD)6;gP&IWiVy?3;2#+y;k%aT^!jRC@{zb2Y@23(#WdI3VEcWn+xRrxD=n=-Y~Qpq7hz z79F&+UsLBz0i-Usj~9cr2!pJ1;Dn?%yL7-=_`zAiJV?hj&yw|$(Jo^7O4bs!2JG5= zsC9|TAVr;b4KNtL!>0_Y3t-R&)NeLIo8!-5#sU~zQ(HI!PEDb27NZLBI=x$y7d#DY zyh80 client.lifetime) { + early = client.lifetime; + } + + next = MIN(period, client.lifetime - early); + next = MAX(next, MINIMUM_PERIOD); + + return client.last_update + next * MSEC_PER_SEC; } static int64_t next_rx_off(void) diff --git a/tests/net/lib/lwm2m/interop/prj.conf b/tests/net/lib/lwm2m/interop/prj.conf index 5d255e0513e..66d6334264f 100644 --- a/tests/net/lib/lwm2m/interop/prj.conf +++ b/tests/net/lib/lwm2m/interop/prj.conf @@ -61,6 +61,8 @@ CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=40 # Use QUEUE mode by default CONFIG_LWM2M_QUEUE_MODE_ENABLED=y CONFIG_LWM2M_QUEUE_MODE_UPTIME=20 +CONFIG_LWM2M_UPDATE_PERIOD=30 +CONFIG_LWM2M_SECONDS_TO_UPDATE_EARLY=10 # LwM2M configuration as OMA-ETS-LightweightM2M_INT-V1_1-20190912-D Configuration 3 CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=30 diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt b/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt index 81e129c56c1..2a8e8959c25 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt @@ -32,3 +32,4 @@ add_compile_definitions(CONFIG_LWM2M_QUEUE_MODE_ENABLED=1) add_compile_definitions(CONFIG_LWM2M_TLS_SESSION_CACHING=1) add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_LISTEN_AT_IDLE=1) add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP=1) +add_compile_definitions(CONFIG_LWM2M_UPDATE_PERIOD=0) From 1907327297f59993d41f2f7f5af50968b0316289 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Fri, 1 Sep 2023 09:25:27 +0200 Subject: [PATCH 0111/1623] [nrf fromtree] net: tcp: Fix goto condition in case of RST/packet error In case RST packet is received or malformed packet is received, the TCP should not proceed with the state machine execution (which may process the invalid packet) but rather jump directly to exit, where the connection will be closed. Signed-off-by: Robert Lubos (cherry picked from commit 370096e4f5b3dc9c9565b0d9322e94c58803a9d3) (cherry picked from commit 100d814995d1a1ac34e78e03572b4b09026304b9) --- subsys/net/ip/tcp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index c90f7b92c20..ad9cd1e4c98 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -2276,7 +2276,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) tcp_out(conn, RST); do_close = true; close_status = -ECONNRESET; - goto next_state; + goto out; } if (FL(&fl, &, RST)) { @@ -2292,7 +2292,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) net_stats_update_tcp_seg_rst(net_pkt_iface(pkt)); do_close = true; close_status = -ECONNRESET; - goto next_state; + goto out; } if (tcp_options_len && !tcp_options_check(&conn->recv_options, pkt, @@ -2301,7 +2301,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) tcp_out(conn, RST); do_close = true; close_status = -ECONNRESET; - goto next_state; + goto out; } if (th && (conn->state != TCP_LISTEN) && (conn->state != TCP_SYN_SENT) && @@ -2316,7 +2316,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) tcp_out(conn, RST); do_close = true; close_status = -ECONNRESET; - goto next_state; + goto out; } if (th) { @@ -2904,6 +2904,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) tcp_state_to_str(conn->state, true)); } +out: if (pkt) { if (verdict == NET_OK) { net_pkt_unref(pkt); From 355032b839e85838fdd50baee5b645fb038c5068 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 29 Sep 2023 19:07:12 +0200 Subject: [PATCH 0112/1623] [nrf fromtree] Bluetooth: Controller: Fix num cmplt for BIS HCI ISO Data fragments Fix number of completed packets generated when BIS HCI ISO Data packets sent to Controller are in fragments. Use the ISOAL stored sdu_fragment count to generate the number of completed packets count. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 48c83a1f4268e539afa03abe2ecaed43a0650b7e) (cherry picked from commit 31a885296ae3ac4e38bb13f679440ec99977baaa) --- subsys/bluetooth/controller/ll_sw/ull.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 2f325f1a86b..6be8bc4759e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -2582,18 +2582,10 @@ static uint8_t tx_cmplt_get(uint16_t *handle, uint8_t *first, uint8_t last) /* We must count each SDU HCI fragment */ tx_node = tx->node; if (IS_NODE_TX_PTR(tx_node)) { - if (IS_ADV_ISO_HANDLE(tx->handle)) { - /* FIXME: ADV_ISO shall be updated to - * use ISOAL for TX. Until then, assume - * 1 node equals 1 fragment. - */ - sdu_fragments = 1U; - } else { - /* We count each SDU fragment completed - * by this PDU. - */ - sdu_fragments = tx_node->sdu_fragments; - } + /* We count each SDU fragment completed + * by this PDU. + */ + sdu_fragments = tx_node->sdu_fragments; /* Replace node reference with fragments * count From 865d0bb25b68360e203d68069c2f964041944a12 Mon Sep 17 00:00:00 2001 From: Ivan Iushkov Date: Thu, 28 Sep 2023 16:21:14 +0200 Subject: [PATCH 0113/1623] [nrf fromtree] Bluetooth: fix HCI ISO Data packets fragmentation this commit partially reverts e460847b6083c0bc57bd63f63bc13c756207c2c9 According to Core Spec 5.4, Vol. 4, Part E, 5.4.5, Data_Total_Length field contains length of the whole packet including optional fields of SDU (Time_Stamp, Packet_Sequence_Number, ISO_SDU_Length, RFU and Packet_Status_Flag). In Zephyr Host, Data_Total_Length value is stored in bt_dev.le.iso_mtu field. Therefore, there is no need to calculate iso_hdr_len(), this length is already taken into account in conn_mtu(conn). This commits removes iso_hdr_len() function and fixes calculation of HCI ISO Data packet length calculations. Signed-off-by: Ivan Iushkov (cherry picked from commit 4f5323a1cf5eab0182166ece2079ad8f0bb94efd) (cherry picked from commit 64826a0ac9a5d32ffede7d6c906485c523e174ba) --- subsys/bluetooth/host/conn.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 5e69c8006c9..f56db35e837 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -655,21 +655,6 @@ static int do_send_frag(struct bt_conn *conn, struct net_buf *buf, uint8_t flags return err; } -static size_t iso_hdr_len(struct net_buf *buf, struct bt_conn *conn) -{ -#if defined(CONFIG_BT_ISO) - if (conn->type == BT_CONN_TYPE_ISO) { - if (tx_data(buf)->iso_has_ts) { - return BT_HCI_ISO_TS_DATA_HDR_SIZE; - } else { - return BT_HCI_ISO_DATA_HDR_SIZE; - } - } -#endif - - return 0; -} - static int send_frag(struct bt_conn *conn, struct net_buf *buf, struct net_buf *frag, uint8_t flags) @@ -682,9 +667,7 @@ static int send_frag(struct bt_conn *conn, /* Add the data to the buffer */ if (frag) { - size_t iso_hdr = flags == FRAG_START ? iso_hdr_len(buf, conn) : 0; - uint16_t frag_len = MIN(conn_mtu(conn) + iso_hdr, - net_buf_tailroom(frag)); + uint16_t frag_len = MIN(conn_mtu(conn), net_buf_tailroom(frag)); net_buf_add_mem(frag, buf->data, frag_len); net_buf_pull(buf, frag_len); @@ -732,11 +715,6 @@ static struct net_buf *create_frag(struct bt_conn *conn, struct net_buf *buf) return frag; } -static bool fits_single_ctlr_buf(struct net_buf *buf, struct bt_conn *conn) -{ - return buf->len - iso_hdr_len(buf, conn) <= conn_mtu(conn); -} - static int send_buf(struct bt_conn *conn, struct net_buf *buf) { struct net_buf *frag; @@ -746,7 +724,7 @@ static int send_buf(struct bt_conn *conn, struct net_buf *buf) LOG_DBG("conn %p buf %p len %u", conn, buf, buf->len); /* Send directly if the packet fits the ACL MTU */ - if (fits_single_ctlr_buf(buf, conn) && !tx_data(buf)->is_cont) { + if (buf->len <= conn_mtu(conn) && !tx_data(buf)->is_cont) { LOG_DBG("send single"); return send_frag(conn, buf, NULL, FRAG_SINGLE); } From f70cd160196e6e346321bb88243743eeb1c807a1 Mon Sep 17 00:00:00 2001 From: Ivan Iushkov Date: Thu, 28 Sep 2023 16:34:46 +0200 Subject: [PATCH 0114/1623] [nrf fromtree] Bluetooth: fix iso_has_ts field for SDU fragmented to multiple HCI packets iso_has_ts wasn't set correcrly for fragments of HCI ISO Data packets, now it is set depending on timestamp provided in the original buffer provided by host user Signed-off-by: Ivan Iushkov (cherry picked from commit a4a196f0027b11a5debd9025fb0ba8099ea6a3c0) (cherry picked from commit 0905dee30850bb16898006977957d5fbb4614962) --- subsys/bluetooth/host/conn.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index f56db35e837..155b1a041a0 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -711,6 +711,7 @@ static struct net_buf *create_frag(struct bt_conn *conn, struct net_buf *buf) /* Fragments never have a TX completion callback */ tx_data(frag)->tx = NULL; tx_data(frag)->is_cont = false; + tx_data(frag)->iso_has_ts = tx_data(buf)->iso_has_ts; return frag; } From a977ac68d2b32f2c1c326c82467a6b3bf0d5882f Mon Sep 17 00:00:00 2001 From: Ivan Iushkov Date: Fri, 29 Sep 2023 12:08:10 +0200 Subject: [PATCH 0115/1623] [nrf fromtree] Bluetooth: documentation change of kconfig.iso configs Added comment to KConfig.iso file to make description of BT_ISO_TX_MTU and BT_ISO_RX_MTU more clear Signed-off-by: Ivan Iushkov (cherry picked from commit c650f6aea0bc5e6c4fcacb521435b1673553f221) (cherry picked from commit 328411d85839340607fe033fa4de4f59cb2eb038) --- subsys/bluetooth/Kconfig.iso | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subsys/bluetooth/Kconfig.iso b/subsys/bluetooth/Kconfig.iso index 553ff3a7fb4..304c408f42f 100644 --- a/subsys/bluetooth/Kconfig.iso +++ b/subsys/bluetooth/Kconfig.iso @@ -99,6 +99,10 @@ config BT_ISO_TX_MTU range 1 4095 help Maximum MTU for Isochronous channels TX buffers. + This is the actual data payload. It doesn't include the optional + HCI ISO Data packet fields (e.g. `struct bt_hci_iso_ts_data_hdr`). + Set this value to 247 to fit 247 bytes of data within a single + HCI ISO Data packet with a size of 255, without utilizing timestamps. config BT_ISO_RX_BUF_COUNT int "Number of Isochronous RX buffers" @@ -113,6 +117,8 @@ config BT_ISO_RX_MTU range 23 4095 help Maximum MTU for Isochronous channels RX buffers. + This is the actual data payload. It doesn't include the optional + HCI ISO Data packet fields (e.g. `struct bt_hci_iso_ts_data_hdr`) config BT_ISO_ADVANCED bool "Advanced ISO parameters" From 59c0a7cb2c0dcdeea2794ee389e37a1b0e9da1be Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Mon, 25 Sep 2023 16:41:15 +0200 Subject: [PATCH 0116/1623] [nrf noup] settings: nvs: use dedicated lookup cache hash function Introduce NVS_LOOKUP_CACHE_FOR_SETTINGS Kconfig option that enables a dedicated hash function for the NVS lookup cache that takes advantage of the NVS ID allocation scheme used by the NVS settings backend. As such, this option should only be used if an application uses NVS via the settings layer. Signed-off-by: Damian Krolik (cherry picked from commit 72fbc3cde4f3dfabdaa80cd7bf78943ea174ca86) --- subsys/fs/nvs/Kconfig | 9 +++++++++ subsys/fs/nvs/nvs.c | 46 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/subsys/fs/nvs/Kconfig b/subsys/fs/nvs/Kconfig index de4f282ee98..df0329a7c41 100644 --- a/subsys/fs/nvs/Kconfig +++ b/subsys/fs/nvs/Kconfig @@ -27,6 +27,15 @@ config NVS_LOOKUP_CACHE_SIZE Number of entries in Non-volatile Storage lookup cache. It is recommended that it be a power of 2. +config NVS_LOOKUP_CACHE_FOR_SETTINGS + bool "Non-volatile Storage lookup cache optimized for settings" + depends on NVS_LOOKUP_CACHE + help + Use the lookup cache hash function that results in the least number of + collissions and, in turn, the best NVS performance provided that the NVS + is used as the settings backend only. This option should NOT be enabled + if the NVS is also written to directly, outside the settings layer. + module = NVS module-str = nvs source "subsys/logging/Kconfig.template.log_config" diff --git a/subsys/fs/nvs/nvs.c b/subsys/fs/nvs/nvs.c index 8c4575700a8..14a4db5e347 100644 --- a/subsys/fs/nvs/nvs.c +++ b/subsys/fs/nvs/nvs.c @@ -13,6 +13,11 @@ #include #include "nvs_priv.h" +#ifdef CONFIG_NVS_LOOKUP_CACHE_FOR_SETTINGS +#include +#include +#endif + #include LOG_MODULE_REGISTER(fs_nvs, CONFIG_NVS_LOG_LEVEL); @@ -21,6 +26,45 @@ static int nvs_ate_valid(struct nvs_fs *fs, const struct nvs_ate *entry); #ifdef CONFIG_NVS_LOOKUP_CACHE +#ifdef CONFIG_NVS_LOOKUP_CACHE_FOR_SETTINGS + +static inline size_t nvs_lookup_cache_pos(uint16_t id) +{ + /* + * 1. The NVS settings backend uses up to (NVS_NAME_ID_OFFSET - 1) NVS IDs to + store keys and equal number of NVS IDs to store values. + * 2. For each key-value pair, the value is stored at NVS ID greater by exactly + * NVS_NAME_ID_OFFSET than NVS ID that holds the key. + * 3. The backend tries to minimize the range of NVS IDs used to store keys. + * That is, NVS IDs are allocated sequentially, and freed NVS IDs are reused + * before allocating new ones. + * + * Therefore, to assure the least number of collisions in the lookup cache, + * the least significant bit of the hash indicates whether the given NVS ID + * represents a key or a value, and remaining bits of the hash are set to + * the ordinal number of the key-value pair. Consequently, the hash function + * provides the following mapping: + * + * 1st settings key => hash 0 + * 1st settings value => hash 1 + * 2nd settings key => hash 2 + * 2nd settings value => hash 3 + * ... + */ + BUILD_ASSERT(IS_POWER_OF_TWO(NVS_NAMECNT_ID), "NVS_NAMECNT_ID is not power of 2"); + BUILD_ASSERT(IS_POWER_OF_TWO(NVS_NAME_ID_OFFSET), "NVS_NAME_ID_OFFSET is not power of 2"); + + uint16_t key_value_bit; + uint16_t key_value_ord; + + key_value_bit = (id >> LOG2(NVS_NAME_ID_OFFSET)) & 1; + key_value_ord = id & (NVS_NAME_ID_OFFSET - 1); + + return ((key_value_ord << 1) | key_value_bit) % CONFIG_NVS_LOOKUP_CACHE_SIZE; +} + +#else /* CONFIG_NVS_LOOKUP_CACHE_FOR_SETTINGS */ + static inline size_t nvs_lookup_cache_pos(uint16_t id) { uint16_t hash; @@ -36,6 +80,8 @@ static inline size_t nvs_lookup_cache_pos(uint16_t id) return hash % CONFIG_NVS_LOOKUP_CACHE_SIZE; } +#endif /* CONFIG_NVS_LOOKUP_CACHE_FOR_SETTINGS */ + static int nvs_lookup_cache_rebuild(struct nvs_fs *fs) { int rc; From 020dcdc2ab9118bf2960ef1feb396b79e6924b77 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Mon, 25 Sep 2023 12:45:10 +0200 Subject: [PATCH 0117/1623] [nrf fromtree] sysbuild: Do not exclude images from domains.yaml The recent support for BUILD_ONLY images was implemented by excluding them from `domains.yaml`, in order to crudely prevent them from being picked up by `west flash`. Arguably, this is incorrect or unexpected, because the sysbuild documentation defines a "domain" as: Every Zephyr CMake build system managed by sysbuild. Another consequence is that, given a build-only ``, this makes it impossible to pass `--domain ` to `west flash`, `west debug`, and ironically `west build`. To fix that, `domains.yaml` should again represent all domains, and the build-only ones should be indicated in another way. Enter `flash_order`: a new top-level key in the domains YAML schema. It contains the default sequence of images used by `west flash`, where the build-only images are excluded, and the order is influenced by `sysbuild_add_dependencies()`. Signed-off-by: Grzegorz Swiderski (cherry picked from commit 05d77690736b5ad022ee1d0f7dc9b4fea2bd2c24) (cherry picked from commit 92164b7c7793a9fda801319fb0e862016114d51f) --- scripts/pylib/build_helpers/domains.py | 43 +++++++++++++------------- scripts/west_commands/build_helpers.py | 3 +- scripts/west_commands/flash.py | 3 +- share/sysbuild/cmake/domains.cmake | 11 ++++--- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/scripts/pylib/build_helpers/domains.py b/scripts/pylib/build_helpers/domains.py index c748a94a14f..8cacac7b4e8 100644 --- a/scripts/pylib/build_helpers/domains.py +++ b/scripts/pylib/build_helpers/domains.py @@ -38,6 +38,11 @@ build_dir: required: true type: str + flash_order: + required: false + type: seq + sequence: + - type: str ''' schema = yaml.safe_load(DOMAINS_SCHEMA) @@ -52,21 +57,19 @@ class Domains: def __init__(self, data): - self._domains = [] - self._domain_names = [] - self._domain_default = [] - self._build_dir = data.get('build_dir') - domain_list = data.get('domains') + domain_list = data.get('domains') or [] if not domain_list: logger.warning("no domains defined; this probably won't work") - for d in domain_list: - domain = Domain(d['name'], d['build_dir']) - self._domains.append(domain) - self._domain_names.append(domain.name) - if domain.name == data['default']: - self._default_domain = domain + self._domains = { + d['name']: Domain(d['name'], d['build_dir']) + for d in domain_list + } + self._default_domain = self._domains.get(data['default']) + + domains_flash_order = data.get('flash_order') or [] + self._flash_order = list(map(self._domains.get, domains_flash_order)) @staticmethod def from_file(domains_file): @@ -97,25 +100,21 @@ def from_data(domains_data): ''' return Domains(domains_data) - def get_domains(self, names=None): + def get_domains(self, names=None, default_flash_order=False): ret = [] if not names: - return self._domains + if default_flash_order: + return self._flash_order + return list(self._domains.values()) for n in names: - found = False - for d in self._domains: - if n == d.name: - ret.append(d) - found = True - break - # Getting here means the domain was not found. - # Todo: throw an error. + found = self._domains.get(n) if not found: logger.critical(f'domain {n} not found, ' - f'valid domains are:', *self._domain_names) + f'valid domains are: {", ".join(self._domains)}') exit(1) + ret.append(found) return ret def get_default_domain(self): diff --git a/scripts/west_commands/build_helpers.py b/scripts/west_commands/build_helpers.py index e4352ff1f28..88845e50f4b 100644 --- a/scripts/west_commands/build_helpers.py +++ b/scripts/west_commands/build_helpers.py @@ -153,6 +153,7 @@ def load_domains(path): if not domains_file.is_file(): return Domains.from_data({'default': 'app', 'build_dir': path, - 'domains': [{'name': 'app', 'build_dir': path}]}) + 'domains': [{'name': 'app', 'build_dir': path}], + 'flash_order': ['app']}) return Domains.from_file(domains_file) diff --git a/scripts/west_commands/flash.py b/scripts/west_commands/flash.py index 073a1ab2a28..4f173535be8 100644 --- a/scripts/west_commands/flash.py +++ b/scripts/west_commands/flash.py @@ -28,5 +28,6 @@ def do_add_parser(self, parser_adder): def do_run(self, my_args, runner_args): build_dir = get_build_dir(my_args) - domains = load_domains(build_dir).get_domains(my_args.domain) + domains = load_domains(build_dir).get_domains(my_args.domain, + default_flash_order=True) do_run_common(self, my_args, runner_args, domains=domains) diff --git a/share/sysbuild/cmake/domains.cmake b/share/sysbuild/cmake/domains.cmake index c46d261aff2..1d197059bf1 100644 --- a/share/sysbuild/cmake/domains.cmake +++ b/share/sysbuild/cmake/domains.cmake @@ -7,12 +7,13 @@ sysbuild_images_order(IMAGES_FLASHING_ORDER FLASH IMAGES ${IMAGES}) set(domains_yaml "default: ${DEFAULT_IMAGE}") set(domains_yaml "${domains_yaml}\nbuild_dir: ${CMAKE_BINARY_DIR}") set(domains_yaml "${domains_yaml}\ndomains:") -foreach(image ${IMAGES_FLASHING_ORDER}) - get_target_property(image_is_build_only ${image} BUILD_ONLY) - if(image_is_build_only) - continue() - endif() +foreach(image ${IMAGES}) set(domains_yaml "${domains_yaml}\n - name: ${image}") set(domains_yaml "${domains_yaml}\n build_dir: $") endforeach() +set(domains_yaml "${domains_yaml}\nflash_order:") +foreach(image ${IMAGES_FLASHING_ORDER}) + set(flash_cond "$>>") + set(domains_yaml "${domains_yaml}$<${flash_cond}:\n - ${image}>") +endforeach() file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/domains.yaml CONTENT "${domains_yaml}") From 49df79f70077cc7a69125e7c9812c2764c24a501 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Mon, 25 Sep 2023 12:45:24 +0200 Subject: [PATCH 0118/1623] [nrf fromtree] doc: sysbuild: Update documentation about BUILD_ONLY It is now possible to `west flash` or `west debug` a build-only image. Signed-off-by: Grzegorz Swiderski (cherry picked from commit 8b273a45a678a62bcf3fa7e90cdb4c8faddf4553) (cherry picked from commit ec4ee96d4703e002e9c79cc2ab7fb3edeef1ac65) --- doc/build/sysbuild/index.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/build/sysbuild/index.rst b/doc/build/sysbuild/index.rst index 2c53cb0e88a..e09ee3e5617 100644 --- a/doc/build/sysbuild/index.rst +++ b/doc/build/sysbuild/index.rst @@ -569,13 +569,19 @@ You can mark ``my_sample`` as a build-only application in this manner: ) As a result, ``my_sample`` will be built as part of the sysbuild build invocation, -but neither ``west flash`` nor ``west debug`` will be aware of this application. +but it will be excluded from the default image sequence used by ``west flash``. Instead, you may use the outputs of this domain for other purposes - for example, to produce a secondary image for DFU, or to merge multiple images together. You can also replace ``TRUE`` with another boolean constant in CMake, such as a Kconfig option, which would make ``my_sample`` conditionally build-only. +.. note:: + + Applications marked as build-only can still be flashed manually, using + ``west flash --domain my_sample``. As such, the ``BUILD_ONLY`` option only + controls the default behavior of ``west flash``. + Zephyr application configuration ================================ From 6df09b137cd799e5fdc1ef2371a70609f175e8c4 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Thu, 28 Sep 2023 09:36:01 +0200 Subject: [PATCH 0119/1623] [nrf fromtree] scripts: domains: Tighten up initialization Do extra checks to reject inconsistent `domains.yaml` contents early: default: app build_dir: /path/to/build domains: - name: image_1 build_dir: /path/to/build/image_1 - name: image_2 build_dir: /path/to/build/image_2 flash_order: - image_1 - image_2 - unknown This example lists "image_1" and "image_2" as known domains, but an entry for the default "app" is missing, which should never be allowed. A valid `domains.yaml` file shall also not contain extra domains under `flash_order`, such as "unknown", which doesn't appear under `domains`. Either of these cases can now be caught while initializing an instance of the Domains class. It follows that a valid `domains.yaml` file must always contain a list of domains with at least one entry - the default image. Since `default` is a required key in the YAML schema, `domains` should be required too. Thus, empty lists will be rejected by pykwalify, so the questionable warning for "no domains defined; this probably won't work" can be axed. Fixes #63166 Signed-off-by: Grzegorz Swiderski (cherry picked from commit f82e2ef043ea40c648094955b4a0c54c42a98d5a) (cherry picked from commit d87c3c5d73014b38fab1b3455b5d6cadc95af9f3) --- scripts/pylib/build_helpers/domains.py | 39 ++++++++++++-------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/scripts/pylib/build_helpers/domains.py b/scripts/pylib/build_helpers/domains.py index 8cacac7b4e8..f4c2f085fd2 100644 --- a/scripts/pylib/build_helpers/domains.py +++ b/scripts/pylib/build_helpers/domains.py @@ -27,7 +27,7 @@ required: true type: str domains: - required: false + required: true type: seq sequence: - type: map @@ -57,19 +57,18 @@ class Domains: def __init__(self, data): - self._build_dir = data.get('build_dir') - domain_list = data.get('domains') or [] - if not domain_list: - logger.warning("no domains defined; this probably won't work") - + self._build_dir = data['build_dir'] self._domains = { d['name']: Domain(d['name'], d['build_dir']) - for d in domain_list + for d in data['domains'] } - self._default_domain = self._domains.get(data['default']) - domains_flash_order = data.get('flash_order') or [] - self._flash_order = list(map(self._domains.get, domains_flash_order)) + # In the YAML data, the values for "default" and "flash_order" + # must not name any domains that aren't listed under "domains". + # Now that self._domains has been initialized, we can leverage + # the common checks in self.get_domain to verify this. + self._default_domain = self.get_domain(data['default']) + self._flash_order = self.get_domains(data['flash_order'] or []) @staticmethod def from_file(domains_file): @@ -101,21 +100,19 @@ def from_data(domains_data): return Domains(domains_data) def get_domains(self, names=None, default_flash_order=False): - ret = [] - - if not names: + if names is None: if default_flash_order: return self._flash_order return list(self._domains.values()) + return list(map(self.get_domain, names)) - for n in names: - found = self._domains.get(n) - if not found: - logger.critical(f'domain {n} not found, ' - f'valid domains are: {", ".join(self._domains)}') - exit(1) - ret.append(found) - return ret + def get_domain(self, name): + found = self._domains.get(name) + if not found: + logger.critical(f'domain "{name}" not found, ' + f'valid domains are: {", ".join(self._domains)}') + exit(1) + return found def get_default_domain(self): return self._default_domain From f943f54c83a9ae04467dccdb01b33707bdcfffc0 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Thu, 28 Sep 2023 09:36:18 +0200 Subject: [PATCH 0120/1623] [nrf fromtree] scripts: domains: Support initialization only from YAML By requiring a full-on YAML fragment, the Domains class can rely on pykwalify to do the heavy lifting with validating types and structure. Remove support for loading domains from a dictionary, so that we don't ever have to replicate the same checks on the input, and we can instead have a single entry point. Signed-off-by: Grzegorz Swiderski (cherry picked from commit 652b0a8a985481cb40d680a4864599d9294a296c) (cherry picked from commit a3b1b0f368e27339bfee6637fc2f03e0dbf30ac8) --- scripts/pylib/build_helpers/domains.py | 32 ++++++++++++-------------- scripts/west_commands/build_helpers.py | 13 +++++++---- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/scripts/pylib/build_helpers/domains.py b/scripts/pylib/build_helpers/domains.py index f4c2f085fd2..475844e9a61 100644 --- a/scripts/pylib/build_helpers/domains.py +++ b/scripts/pylib/build_helpers/domains.py @@ -56,7 +56,15 @@ class Domains: - def __init__(self, data): + def __init__(self, domains_yaml): + try: + data = yaml.safe_load(domains_yaml) + pykwalify.core.Core(source_data=data, + schema_data=schema).validate() + except (yaml.YAMLError, pykwalify.errors.SchemaError): + logger.critical(f'malformed domains.yaml') + exit(1) + self._build_dir = data['build_dir'] self._domains = { d['name']: Domain(d['name'], d['build_dir']) @@ -72,32 +80,22 @@ def __init__(self, data): @staticmethod def from_file(domains_file): - '''Load domains from domains.yaml. - - Exception raised: - - ``FileNotFoundError`` if the domains file is not found. + '''Load domains from a domains.yaml file. ''' try: with open(domains_file, 'r') as f: - domains = yaml.safe_load(f.read()) + domains_yaml = f.read() except FileNotFoundError: logger.critical(f'domains.yaml file not found: {domains_file}') exit(1) - try: - pykwalify.core.Core(source_data=domains, schema_data=schema)\ - .validate() - except pykwalify.errors.SchemaError: - logger.critical(f'ERROR: Malformed yaml in file: {domains_file}') - exit(1) - - return Domains(domains) + return Domains(domains_yaml) @staticmethod - def from_data(domains_data): - '''Load domains from domains dictionary. + def from_yaml(domains_yaml): + '''Load domains from a string with YAML contents. ''' - return Domains(domains_data) + return Domains(domains_yaml) def get_domains(self, names=None, default_flash_order=False): if names is None: diff --git a/scripts/west_commands/build_helpers.py b/scripts/west_commands/build_helpers.py index 88845e50f4b..ca6845f01da 100644 --- a/scripts/west_commands/build_helpers.py +++ b/scripts/west_commands/build_helpers.py @@ -151,9 +151,14 @@ def load_domains(path): domains_file = Path(path) / 'domains.yaml' if not domains_file.is_file(): - return Domains.from_data({'default': 'app', - 'build_dir': path, - 'domains': [{'name': 'app', 'build_dir': path}], - 'flash_order': ['app']}) + return Domains.from_yaml(f'''\ +default: app +build_dir: {path} +domains: + - name: app + build_dir: {path} +flash_order: + - app +''') return Domains.from_file(domains_file) From 2cdbabc898855f447b8f17cd81548b16dfb6d045 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Thu, 28 Sep 2023 09:36:36 +0200 Subject: [PATCH 0121/1623] [nrf fromtree] scripts: domains: Convert Domain to a dataclass For conciseness. Signed-off-by: Grzegorz Swiderski (cherry picked from commit 9bbf7e5a4806c158e0d5c19b816379ef02e0f3e3) (cherry picked from commit 9cf087a4d8274112ab1daa6f9cc2f943f9cb2256) --- scripts/pylib/build_helpers/domains.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/scripts/pylib/build_helpers/domains.py b/scripts/pylib/build_helpers/domains.py index 475844e9a61..978569d9547 100644 --- a/scripts/pylib/build_helpers/domains.py +++ b/scripts/pylib/build_helpers/domains.py @@ -8,6 +8,8 @@ Domain class. ''' +from dataclasses import dataclass + import yaml import pykwalify.core import logging @@ -119,24 +121,8 @@ def get_top_build_dir(self): return self._build_dir +@dataclass class Domain: - def __init__(self, name, build_dir): - self.name = name - self.build_dir = build_dir - - @property - def name(self): - return self._name - - @name.setter - def name(self, value): - self._name = value - - @property - def build_dir(self): - return self._build_dir - - @build_dir.setter - def build_dir(self, value): - self._build_dir = value + name: str + build_dir: str From 90d276b0cd557bf7f3e35119e43106b09681194e Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Tue, 19 Sep 2023 15:07:21 +0200 Subject: [PATCH 0122/1623] [nrf fromtree] twister: pytest: Fix problems with no prompt in tests with shell Only impacts on twister-pytest scenarios. Exec command is waiting for the prompt message, but in some cases, e.g. after reseting the DUT, prompt can be followed by another strings. Solution is to clear internal serial buffer and to not request the prompt string before executing a command. Signed-off-by: Grzegorz Chwierut (cherry picked from commit 6c86af0331f2cd0f2e410b88c6ee290ea7648f83) (cherry picked from commit 938510fbf113906509c27e4af8d12ce9b1366a79) --- .../src/twister_harness/device/hardware_adapter.py | 1 + .../pytest-twister-harness/src/twister_harness/helpers/shell.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py index 3a3f242fa85..403978eed9a 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py @@ -250,6 +250,7 @@ def _clear_internal_resources(self) -> None: super()._clear_internal_resources() self._serial_connection = None self._serial_pty_proc = None + self._serial_buffer.clear() @staticmethod def _run_custom_script(script_path: str | Path, timeout: float) -> None: diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/shell.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/shell.py index fc8009d12fe..37f8ad432cf 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/shell.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/shell.py @@ -57,7 +57,7 @@ def exec_command(self, command: str, timeout: float | None = None, print_output: timeout = timeout or self.base_timeout command_ext = f'{command}\n\n' regex_prompt = re.escape(self.prompt) - regex_command = f'{regex_prompt}.*{command}' + regex_command = f'.*{command}' self._device.clear_buffer() self._device.write(command_ext.encode()) lines: list[str] = [] From 801a64e6d1acfaac7bf1f5ebb2d647500464186e Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Thu, 14 Sep 2023 15:38:34 +0200 Subject: [PATCH 0123/1623] [nrf fromtree] twister: doc: Update pytest and twister docs Document how to use pytest_root keyword. Update docs with changes in pytest-twister-harness plugin. Signed-off-by: Grzegorz Chwierut (cherry picked from commit 033afe1c0c3c047b36c86ca9a1d225129e3e5315) (cherry picked from commit 7f2feef444a94ac58cd1c6a1d64e977d6828a317) --- doc/develop/test/pytest.rst | 55 +++++++++++++++++++++++------------- doc/develop/test/twister.rst | 26 +++++++++++------ 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/doc/develop/test/pytest.rst b/doc/develop/test/pytest.rst index 97737ce0ae2..d0fad4d6be6 100644 --- a/doc/develop/test/pytest.rst +++ b/doc/develop/test/pytest.rst @@ -49,28 +49,47 @@ How to create a pytest test An example of a pytest test is given at :zephyr_file:`samples/subsys/testsuite/pytest/shell/pytest/test_shell.py`. Twister calls pytest for each configuration from the .yaml file which uses ``harness: pytest``. By default, it points to ``pytest`` directory, located next to a directory with binary sources. -A keyword ``pytest_root`` placed under ``harness_config`` section can be used to point to another -location. +A keyword ``pytest_root`` placed under ``harness_config`` section can be used to point to other +files, directories or subtests. -Pytest scans the given folder looking for tests, following its default +Pytest scans the given locations looking for tests, following its default `discovery rules `_ One can also pass some extra arguments to the pytest from yaml file using ``pytest_args`` keyword under ``harness_config``, e.g.: ``pytest_args: [‘-k=test_method’, ‘--log-level=DEBUG’]``. -Following import is required to include in .py sources: +Helpers & fixtures +================== + +dut +--- + +Give access to a DeviceAdapter type object, that represents Device Under Test. +This fixture is the core of pytest harness plugin. It is required to launch +DUT (initialize logging, flash device, connect serial etc). +This fixture yields a device prepared according to the requested type +(native posix, qemu, hardware, etc.). All types of devices share the same API. +This allows for writing tests which are device-type-agnostic. .. code-block:: python - from twister_harness import Device + from twister_harness import DeviceAdapter -It is important for type checking and enabling IDE hints for ``dut`` s (objects representing -Devices Under Test). The ``dut`` fixture is the core of pytest harness plugin. When used as an -argument of a test function it gives access to a DeviceAbstract type object. The fixture yields a -device prepared according to the requested type (native posix, qemu, hardware, etc.). All types of -devices share the same API. This allows for writing tests which are device-type-agnostic. + def test_sample(dut: DeviceAdapter): + dut.readlines_until('Hello world') -Helpers & fixtures -================== +shell +----- + +Provide an object with methods used to interact with shell application. +It calls `wait_for_promt` method, to not start scenario until DUT is ready. +Note that it uses `dut` fixture, so `dut` can be skipped when `shell` is used. + +.. code-block:: python + + from twister_harness import Shell + + def test_shell(shell: Shell): + shell.exec_command('help') mcumgr ------ @@ -82,16 +101,15 @@ More information about MCUmgr can be found here :ref:`mcu_mgr`. This fixture requires the ``mcumgr`` available in the system PATH Only selected functionality of MCUmgr is wrapped by this fixture. - For example, here is a test with a fixture ``mcumgr`` .. code-block:: python - from twister_harness import Device, McuMgr + from twister_harness import DeviceAdapter, Shell, McuMgr - def test_upgrade(dut: Device, mcumgr: McuMgr): - # wait for dut is up - time.sleep(2) + def test_upgrade(dut: DeviceAdapter, shell: Shell, mcumgr: McuMgr): + # free the serial port for mcumgr + dut.disconnect() # upload the signed image mcumgr.image_upload('path/to/zephyr.signed.bin') # obtain the hash of uploaded image from the device @@ -105,7 +123,4 @@ For example, here is a test with a fixture ``mcumgr`` Limitations *********** -* Device adapters in pytest plugin provide `iter_stdout` method to read from devices. In some - cases, it is not the most convenient way, and it will be considered how to improve this - (for example replace it with a simple read function with a given byte size and timeout arguments). * Not every platform type is supported in the plugin (yet). diff --git a/doc/develop/test/twister.rst b/doc/develop/test/twister.rst index a29890c7899..4456386b77c 100644 --- a/doc/develop/test/twister.rst +++ b/doc/develop/test/twister.rst @@ -492,10 +492,11 @@ harness_config: Only one fixture can be defined per testcase and the fixture name has to be unique across all tests in the test suite. - pytest_root: (default pytest) - Specify a pytest directory which need to execute when test case begin to running, - default pytest directory name is pytest, after pytest finished, twister will - check if this case pass or fail according the pytest report. + pytest_root: (default pytest) + Specify a list of pytest directories, files or subtests that need to be executed + when test case begin to running, default pytest directory is pytest. + After pytest finished, twister will check if this case pass or fail according + to the pytest report. pytest_args: (default empty) Specify a list of additional arguments to pass to ``pytest``. @@ -526,15 +527,24 @@ harness_config: The following is an example yaml file with pytest harness_config options, default pytest_root name "pytest" will be used if pytest_root not specified. - please refer the example in samples/subsys/testsuite/pytest/. + please refer the examples in samples/subsys/testsuite/pytest/. :: + common: + harness: pytest tests: - pytest.example: - harness: pytest + pytest.example.directories: + harness_config: + pytest_root: + - pytest_dir1 + - $ENV_VAR/samples/test/pytest_dir2 + pytest.example.files_and_subtests: harness_config: - pytest_root: [pytest directory name] + pytest_root: + - pytest/test_file_1.py + - test_file_2.py::test_A + - test_file_2.py::test_B[param_a] The following is an example yaml file with robot harness_config options. From 29ccece157fa10782a41b8fa1eee15759174e24d Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Thu, 14 Sep 2023 15:34:07 +0200 Subject: [PATCH 0124/1623] [nrf fromtree] twister: pytest: Allow list of pytest testpaths Allow to specify a list of pytest directories, files or subtests with pytest_root keyword in test yaml. Signed-off-by: Grzegorz Chwierut (cherry picked from commit 5bb306794232d4e391987448bbf73724e21d5a08) (cherry picked from commit be22816677ec99e6deb93b9977c403b625ab0448) --- scripts/pylib/twister/twisterlib/harness.py | 5 +- scripts/schemas/twister/testsuite-schema.yaml | 8 ++- .../pytest_integration/test_harness_pytest.py | 61 +++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index 96b4a2e3461..6ae2622c810 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -245,19 +245,20 @@ def pytest_run(self, timeout): def generate_command(self): config = self.instance.testsuite.harness_config - pytest_root = config.get('pytest_root', 'pytest') if config else 'pytest' + pytest_root = config.get('pytest_root', ['pytest']) if config else ['pytest'] pytest_args = config.get('pytest_args', []) if config else [] command = [ 'pytest', '--twister-harness', '-s', '-v', - os.path.join(self.source_dir, pytest_root), f'--build-dir={self.running_dir}', f'--junit-xml={self.report_file}', '--log-file-level=DEBUG', '--log-file-format=%(asctime)s.%(msecs)d:%(levelname)s:%(name)s: %(message)s', f'--log-file={self.pytest_log_file_path}' ] + command.extend([os.path.normpath(os.path.join( + self.source_dir, os.path.expanduser(os.path.expandvars(src)))) for src in pytest_root]) command.extend(pytest_args) handler: Handler = self.instance.handler diff --git a/scripts/schemas/twister/testsuite-schema.yaml b/scripts/schemas/twister/testsuite-schema.yaml index 116c1a43379..96a121767a5 100644 --- a/scripts/schemas/twister/testsuite-schema.yaml +++ b/scripts/schemas/twister/testsuite-schema.yaml @@ -95,8 +95,10 @@ mapping: type: int required: false "pytest_root": - type: str + type: seq required: false + sequence: + - type: str "pytest_args": type: seq required: false @@ -293,8 +295,10 @@ mapping: type: int required: false "pytest_root": - type: str + type: seq required: false + sequence: + - type: str "pytest_args": type: seq required: false diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index db7bf389fbd..e1b27a0cf02 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -48,6 +48,67 @@ def test_pytest_command(testinstance: TestInstance, device_type): assert c in command +@pytest.mark.parametrize( + ('pytest_root', 'expected'), + [ + ( + ['pytest/test_shell_help.py'], + ['samples/hello/pytest/test_shell_help.py'] + ), + ( + ['pytest/test_shell_help.py', 'pytest/test_shell_version.py', 'test_dir'], + ['samples/hello/pytest/test_shell_help.py', + 'samples/hello/pytest/test_shell_version.py', + 'samples/hello/test_dir'] + ), + ( + ['../shell/pytest/test_shell.py'], + ['samples/shell/pytest/test_shell.py'] + ), + ( + ['/tmp/test_temp.py'], + ['/tmp/test_temp.py'] + ), + ( + ['~/tmp/test_temp.py'], + ['/home/joe/tmp/test_temp.py'] + ), + ( + ['$ZEPHYR_BASE/samples/subsys/testsuite/pytest/shell/pytest'], + ['/zephyr_base/samples/subsys/testsuite/pytest/shell/pytest'] + ), + ( + ['pytest/test_shell_help.py::test_A', 'pytest/test_shell_help.py::test_B'], + ['samples/hello/pytest/test_shell_help.py::test_A', + 'samples/hello/pytest/test_shell_help.py::test_B'] + ), + ( + ['pytest/test_shell_help.py::test_A[param_a]'], + ['samples/hello/pytest/test_shell_help.py::test_A[param_a]'] + ) + ], + ids=[ + 'one_file', + 'more_files', + 'relative_path', + 'absollute_path', + 'user_dir', + 'with_env_var', + 'subtests', + 'subtest_with_param' + ] +) +def test_pytest_handle_source_list(testinstance: TestInstance, monkeypatch, pytest_root, expected): + monkeypatch.setenv('ZEPHYR_BASE', '/zephyr_base') + monkeypatch.setenv('HOME', '/home/joe') + testinstance.testsuite.harness_config['pytest_root'] = pytest_root + pytest_harness = Pytest() + pytest_harness.configure(testinstance) + command = pytest_harness.generate_command() + for pytest_src in expected: + assert pytest_src in command + + def test_if_report_is_parsed(pytester, testinstance: TestInstance): test_file_content = textwrap.dedent(""" def test_1(): From 885245b9c1eb4ecd0a3eb6825a70e97422ea2db9 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Wed, 20 Sep 2023 19:17:26 +0000 Subject: [PATCH 0125/1623] [nrf fromtree] drivers/flash/nrf: Workaround for nrf91 errata 7 Fix UICR read access. (cherry picked from commit 1f3605de21ef1ace85ba4aeced725411c1ed8ef4) Signed-off-by: Dominik Ermel (cherry picked from commit de6799beb339d5df40d65ef2ab76167c9ba50a98) --- drivers/flash/soc_flash_nrf.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/flash/soc_flash_nrf.c b/drivers/flash/soc_flash_nrf.c index f38492a41d1..ea76ae1e3f8 100644 --- a/drivers/flash/soc_flash_nrf.c +++ b/drivers/flash/soc_flash_nrf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 Nordic Semiconductor ASA + * Copyright (c) 2017-2023 Nordic Semiconductor ASA * Copyright (c) 2016 Linaro Limited * Copyright (c) 2016 Intel Corporation * @@ -121,6 +121,26 @@ static inline bool is_uicr_addr_valid(off_t addr, size_t len) #endif /* CONFIG_SOC_FLASH_NRF_UICR */ } +#if CONFIG_SOC_FLASH_NRF_UICR && IS_ENABLED(NRF91_ERRATA_7_ENABLE_WORKAROUND) +static inline void nrf91_errata_7_enter(void) +{ + __disable_irq(); +} + +static inline void nrf91_errata_7_exit(void) +{ + __DSB(); + __enable_irq(); +} + +static void nrf_buffer_read_91_uicr(void *data, off_t addr, size_t len) +{ + nrf91_errata_7_enter(); + nrf_nvmc_buffer_read(data, (uint32_t)addr, len); + nrf91_errata_7_exit(); +} +#endif + static void nvmc_wait_ready(void) { while (!nrfx_nvmc_write_done_check()) { @@ -130,9 +150,11 @@ static void nvmc_wait_ready(void) static int flash_nrf_read(const struct device *dev, off_t addr, void *data, size_t len) { + const bool within_uicr = is_uicr_addr_valid(addr, len); + if (is_regular_addr_valid(addr, len)) { addr += DT_REG_ADDR(SOC_NV_FLASH_NODE); - } else if (!is_uicr_addr_valid(addr, len)) { + } else if (!within_uicr) { LOG_ERR("invalid address: 0x%08lx:%zu", (unsigned long)addr, len); return -EINVAL; @@ -147,6 +169,12 @@ static int flash_nrf_read(const struct device *dev, off_t addr, return soc_secure_mem_read(data, (void *)addr, len); } #endif +#if CONFIG_SOC_FLASH_NRF_UICR && IS_ENABLED(NRF91_ERRATA_7_ENABLE_WORKAROUND) + if (within_uicr) { + nrf_buffer_read_91_uicr(data, (uint32_t)addr, len); + return 0; + } +#endif nrf_nvmc_buffer_read(data, (uint32_t)addr, len); From 38f9d7e6f240c55d996e510e9a9d5deca27753cd Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Fri, 2 Jun 2023 19:40:24 +0000 Subject: [PATCH 0126/1623] [nrf fromtree] mgmt/MCUmgr/grp/img: Add support for DirectXIP with revert The commit adds support for uploading image to board with MCUboot configured with DirectXIP with revert. It allows to set uploaded image either for test or as permanent boot application, until newer image gets confirmed. Note that in DirectXIP with revert MCUboot will remove image that has not been set for test nor confirmed and MCUmgr does not set either mode unless image has the mode set within uploaded binary. The commit adds Kconfig option CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT that enabled the new mode of operation within MCUmgr. (cherry picked from commit f3067f2364b2051990575e2dc849d02b391b518d) Signed-off-by: Dominik Ermel (cherry picked from commit 2d442e924d62a8fb1714f904cdca20aa49780343) --- modules/Kconfig.mcuboot | 24 +++ .../mcumgr/grp/img_mgmt/src/img_mgmt_state.c | 201 ++++++++++++++---- 2 files changed, 185 insertions(+), 40 deletions(-) diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index 0bb47d8854c..5f83098a577 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -176,6 +176,21 @@ config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP means major.minor.patch triple, unless BOOT_VERSION_CMP_USE_BUILD_NUMBER is also selected that enables comparison of build number. +config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT + bool "MCUboot has been configured for DirectXIP with revert" + select MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP + help + MCUboot expects slot0_partition and slot1_partition to exist in DT. + In this mode MCUboot will boot the application with the higher version + from either slot, as long as it has been marked to be boot + next time for test or permanently. In case when application is marked + for test it needs to confirm itself, on the first boot, or it will + be removed and MCUboot will revert to booting previously approved + application. + This mode does not allow freely switching between application + versions, as, once higher version application is approved, it is + not possible to select lower version for boot. + endchoice # MCUBOOT_BOOTLOADER_MODE endif # BOOTLOADER_MCUBOOT @@ -208,4 +223,13 @@ config BOOT_IMAGE_ACCESS_HOOKS It is up to the application project to add source file which implements hooks to the build. +if MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT + +config MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP + bool + help + Adds support for setting for test and confirming images + when bootloader is in DirectXIP-revert mode. +endif + endif # MCUBOOT_BOOTUTIL_LIB diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c index a782acb92ee..0968694c614 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c @@ -55,6 +55,14 @@ LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL); #define REPORT_SLOT_PENDING BIT(1) #define REPORT_SLOT_CONFIRMED BIT(2) #define REPORT_SLOT_PERMANENT BIT(3) + +#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) +#define DIRECT_XIP_BOOT_UNSET 0 +#define DIRECT_XIP_BOOT_ONCE 1 +#define DIRECT_XIP_BOOT_REVERT 2 +#define DIRECT_XIP_BOOT_FOREVER 3 +#endif + /** * Collects information about the specified image slot. */ @@ -139,7 +147,8 @@ img_mgmt_state_flags(int query_slot) } #endif -#ifndef CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP +#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) && \ + !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) { const int active_slot = img_mgmt_active_slot(image); @@ -188,27 +197,115 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) return slot; } #else + +#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) + +static int read_directxip_state(int slot) +{ + struct boot_swap_state bss; + int fa_id = img_mgmt_flash_area_id(slot); + const struct flash_area *fa; + int rc = 0; + + __ASSERT(fa_id != -1, "Could not map slot to area ID"); + + rc = flash_area_open(fa_id, &fa); + if (rc < 0) { + return rc; + } + rc = boot_read_swap_state(fa, &bss); + flash_area_close(fa); + if (rc != 0) { + LOG_ERR("Failed to read state of slot %d with error %d", slot, rc); + return -1; + } + + if (bss.magic == BOOT_MAGIC_GOOD) { + if (bss.image_ok == BOOT_FLAG_SET) { + return DIRECT_XIP_BOOT_FOREVER; + } else if (bss.copy_done == BOOT_FLAG_SET) { + return DIRECT_XIP_BOOT_REVERT; + } + return DIRECT_XIP_BOOT_ONCE; + } + return DIRECT_XIP_BOOT_UNSET; +} +#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */ + int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) { struct image_version aver; struct image_version over; int active_slot = img_mgmt_active_slot(image); int other_slot = img_mgmt_get_opposite_slot(active_slot); +#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) + int active_slot_state; + int other_slot_state; +#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */ + enum img_mgmt_next_boot_type lt = NEXT_BOOT_TYPE_NORMAL; + int return_slot = active_slot; - if (type != NULL) { - *type = NEXT_BOOT_TYPE_NORMAL; - } int rcs = img_mgmt_read_info(other_slot, &over, NULL, NULL); int rca = img_mgmt_read_info(active_slot, &aver, NULL, NULL); +#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) + active_slot_state = read_directxip_state(active_slot); + other_slot_state = read_directxip_state(other_slot); + if (rca != 0 || + (rcs != 0 && rcs != IMG_MGMT_ERR_NO_IMAGE)) { + /* We do not really know what will happen, as we can not + * read states from bootloader. + */ + LOG_ERR("img_mgmt_read_info_failed rca = %d, rcs = %d", + rca, rcs); + goto out; + } + if (other_slot_state < 0 || active_slot_state < 0) { + LOG_ERR("Slot state read failed with status: active %d, other %d", + active_slot_state, other_slot_state); + /* We do not really know what will happen, as we can not + * read states from bootloader. + */ + goto out; + } + + /* There is not other image, the active one will boot next time */ + if (rcs == IMG_MGMT_ERR_NO_IMAGE) { + goto out; + } + + if (active_slot_state == DIRECT_XIP_BOOT_REVERT) { + lt = NEXT_BOOT_TYPE_REVERT; + return_slot = other_slot; + } else if (other_slot_state == DIRECT_XIP_BOOT_UNSET) { + if (active_slot_state == DIRECT_XIP_BOOT_ONCE) { + lt = NEXT_BOOT_TYPE_TEST; + } + } else if (img_mgmt_vercmp(&aver, &over) < 0) { + if (other_slot_state == DIRECT_XIP_BOOT_FOREVER) { + return_slot = other_slot; + } else if (other_slot_state == DIRECT_XIP_BOOT_ONCE) { + lt = NEXT_BOOT_TYPE_TEST; + return_slot = other_slot; + } + } +#else if (rcs == 0 && rca == 0 && img_mgmt_vercmp(&aver, &over) < 0) { - return other_slot; + return_slot = other_slot; } +#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */ - return active_slot; +out: + if (type != NULL) { + *type = lt; + } + + return return_slot; } -#endif +#endif /* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) && \ + * !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) + */ /** @@ -422,11 +519,53 @@ img_mgmt_state_read(struct smp_streamer *ctxt) return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE; } -int img_mgmt_set_next_boot_slot(int slot, bool confirm) +static int img_mgmt_set_next_boot_slot_common(int slot, int active_slot, bool confirm) { const struct flash_area *fa; int area_id = img_mgmt_flash_area_id(slot); int rc = 0; + + if (flash_area_open(area_id, &fa) != 0) { + return IMG_MGMT_ERR_FLASH_OPEN_FAILED; + } + + rc = boot_set_next(fa, slot == active_slot, confirm); + if (rc != 0) { + /* Failed to set next slot for boot as desired */ + LOG_ERR("Faled boot_set_next with code %d, for slot %d," + " with active slot %d and confirm %d", + rc, slot, active_slot, confirm); + + /* Translate from boot util error code to IMG mgmt group error code */ + if (rc == BOOT_EFLASH) { + rc = IMG_MGMT_ERR_FLASH_WRITE_FAILED; + } else if (rc == BOOT_EBADVECT) { + rc = IMG_MGMT_ERR_INVALID_IMAGE_VECTOR_TABLE; + } else if (rc == BOOT_EBADIMAGE) { + rc = IMG_MGMT_ERR_INVALID_IMAGE_HEADER_MAGIC; + } else { + rc = IMG_MGMT_ERR_UNKNOWN; + } + } + flash_area_close(fa); + +#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS) + if (rc == 0 && slot == active_slot && confirm) { + int32_t err_rc; + uint16_t err_group; + + /* Confirm event is only sent for active slot */ + (void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_CONFIRMED, NULL, 0, &err_rc, + &err_group); + } +#endif + + return rc; +} + +#ifndef CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT +int img_mgmt_set_next_boot_slot(int slot, bool confirm) +{ /* image the requested slot is defined within */ int image = img_mgmt_slot_to_image(slot); /* active_slot is slot that is considered active/primary/executing @@ -498,43 +637,25 @@ int img_mgmt_set_next_boot_slot(int slot, bool confirm) /* Allow confirming slot == active_slot */ } - if (flash_area_open(area_id, &fa) != 0) { - return IMG_MGMT_ERR_FLASH_OPEN_FAILED; - } - - rc = boot_set_next(fa, slot == active_slot, confirm); - if (rc != 0) { - /* Failed to set next slot for boot as desired */ - LOG_ERR("Faled boot_set_next with code %d, for slot %d," - " with active slot %d and confirm %d", - rc, slot, active_slot, confirm); - - /* Translate from boot util error code to IMG mgmt group error code */ - if (rc == BOOT_EFLASH) { - rc = IMG_MGMT_ERR_FLASH_WRITE_FAILED; - } else if (rc == BOOT_EBADVECT) { - rc = IMG_MGMT_ERR_INVALID_IMAGE_VECTOR_TABLE; - } else if (rc == BOOT_EBADIMAGE) { - rc = IMG_MGMT_ERR_INVALID_IMAGE_HEADER_MAGIC; - } else { - rc = IMG_MGMT_ERR_UNKNOWN; - } - } - flash_area_close(fa); + return img_mgmt_set_next_boot_slot_common(slot, active_slot, confirm); +} +#else +int img_mgmt_set_next_boot_slot(int slot, bool confirm) +{ + int active_image = img_mgmt_active_image(); + int active_slot = img_mgmt_active_slot(active_image); -#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS) - if (slot == active_slot && confirm) { - int32_t err_rc; - uint16_t err_group; + LOG_DBG("(%d, %s)", slot, confirm ? "confirm" : "test"); + LOG_DBG("aimg = %d, aslot = %d, slot = %d", + active_image, active_slot, slot); - /* Confirm event is only sent for active slot */ - (void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_CONFIRMED, NULL, 0, &err_rc, - &err_group); + if (slot == active_slot && !confirm) { + return IMG_MGMT_ERR_IMAGE_SETTING_TEST_TO_ACTIVE_DENIED; } -#endif - return rc; + return img_mgmt_set_next_boot_slot_common(slot, active_slot, confirm); } +#endif /** * Command handler: image state write From 0e63631f6734ba12b8d5a8c02eeb706796d9f046 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Wed, 21 Jun 2023 11:42:05 +0000 Subject: [PATCH 0127/1623] [nrf fromtree] samples/mcumgr/smp_svr: Build for DirectXIP with revert Adds sample build for CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT=y (cherry picked from commit 11ab88f10c83e2bc5ed4120f19a6babf85ea2572) Signed-off-by: Dominik Ermel (cherry picked from commit 7079db0163693bec0c5dbdf62f32841df9cb783e) --- samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml b/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml index ed7ffe8f33e..a13270e5845 100644 --- a/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml +++ b/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml @@ -43,6 +43,19 @@ tests: - mg100 integration_platforms: - nrf52840dk_nrf52840 + # In mcuboot_flags test overlay-serial.conf is used for convenience as it is the simplest + # transport. Transport does not affect flags so it does not really matter which is selected, + # flags should affect any transport the same way. + sample.mcumgr.smp_svr.mcuboot_flags.direct_xip_withrevert: + extra_args: OVERLAY_CONFIG="overlay-serial.conf" + extra_configs: + - CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT=y + platform_allow: + - nrf52840dk_nrf52840 + - pinnacle_100_dvk + - mg100 + integration_platforms: + - nrf52840dk_nrf52840 sample.mcumgr.smp_svr.serial-console: extra_args: OVERLAY_CONFIG="overlay-serial-console.conf" platform_allow: From 8f6ede70c0db2e328b72e350ec5e6b79040d557c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 25 Sep 2023 13:38:15 +0000 Subject: [PATCH 0128/1623] [nrf fromtree] modules/MCUboot: Add new Kconfig indicating downgrade prevention Add the MCUBOOT_BOOTLOADER_NO_DOWNGRADE Kconfig option that allows, when paired with MCUboot mode Kconfig, to indicate that the MCUboot has been configured with downgrade prevention, which means that only application with version higher than running can be swapped on next boot. (cherry picked from commit f17e4f1b76dd10bcf464dbc718073284e61d16fa) Signed-off-by: Dominik Ermel (cherry picked from commit 9bdf8883a69a689b57cd6b85674f4c822bf3b7ad) --- modules/Kconfig.mcuboot | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index 5f83098a577..ab1dd44fbd5 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -116,7 +116,7 @@ config MCUBOOT_EXTRA_IMGTOOL_ARGS help When signing (CONFIG_MCUBOOT_SIGNATURE_KEY_FILE is a non-empty string) you can use this option to pass extra options to - imgtool. For example, you could set this to "--version 1.2". + imgtool. For example, you could set this to "--version 1.2". config MCUBOOT_GENERATE_UNSIGNED_IMAGE bool "Generate unsigned binary image bootable with MCUboot" @@ -136,6 +136,8 @@ config MCUBOOT_GENERATE_CONFIRMED_IMAGE The existence of bin and hex files depends on CONFIG_BUILD_OUTPUT_BIN and CONFIG_BUILD_OUTPUT_HEX. +menu "On board MCUboot operation mode" + choice MCUBOOT_BOOTLOADER_MODE prompt "Application assumed MCUboot mode of operation" default MCUBOOT_BOOTLOADER_MODE_SWAP_WITHOUT_SCRATCH # MCUBOOT_BOOTLOADER_MODE @@ -154,31 +156,43 @@ config MCUBOOT_BOOTLOADER_MODE_SINGLE_APP config MCUBOOT_BOOTLOADER_MODE_SWAP_WITHOUT_SCRATCH bool "MCUboot has been configured for swap without scratch operation" + select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE help MCUboot expects slot0_partition and slot1_partition to be present in DT and application will boot from slot0_partition. + MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected + if MCUboot has been built with MCUBOOT_DOWNGRADE_PREVENTION. config MCUBOOT_BOOTLOADER_MODE_SWAP_SCRATCH bool "MCUboot has been configured for swap using scratch operation" + select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE help MCUboot expects slot0_partition, slot1_partition and scratch_partition to be present in DT, and application will boot from slot0_partition. In this mode scratch_partition is used as temporary storage when MCUboot swaps application from the secondary slot to the primary slot. + MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected + if MCUboot has been built with MCUBOOT_DOWNGRADE_PREVENTION. config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP bool "MCUboot has been configured for DirectXIP operation" + select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE + select MCUBOOT_BOOTLOADER_NO_DOWNGRADE help MCUboot expects slot0_partition and slot1_partition to exist in DT. In this mode MCUboot can boot from either partition and will select one with higher application image version, which usually means major.minor.patch triple, unless BOOT_VERSION_CMP_USE_BUILD_NUMBER is also selected that enables comparison of build number. + This option automatically selectes + MCUBOOT_BOOTLOADER_NO_DOWNGRADE as it is not possible + to swap back to older version of application. config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT bool "MCUboot has been configured for DirectXIP with revert" select MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP + select MCUBOOT_BOOTLOADER_NO_DOWNGRADE help MCUboot expects slot0_partition and slot1_partition to exist in DT. In this mode MCUboot will boot the application with the higher version @@ -190,9 +204,30 @@ config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT This mode does not allow freely switching between application versions, as, once higher version application is approved, it is not possible to select lower version for boot. + This mode selects MCUBOOT_BOOTLOADER_NO_DOWNGRADE as it is not possible + to downgrade running application, but note that MCUboot may do that + if application with higher version will not get confirmed. endchoice # MCUBOOT_BOOTLOADER_MODE +config MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE + bool + help + Selected mode supports downgrade prevention, where you cannot switch to + an application with lower version than the currently running application. + +if MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE +config MCUBOOT_BOOTLOADER_NO_DOWNGRADE + bool "MCUboot mode has downgrade prevention enabled" + help + Selected MCUboot mode has downgrade prevention enabled, where you are not + able to change back to image with lower version number. + This options should be selected when MCUboot has been built with + MCUBOOT_DOWNGRADE_PREVENTION option enabled. +endif + +endmenu # On board MCUboot operation mode + endif # BOOTLOADER_MCUBOOT menuconfig MCUBOOT_BOOTUTIL_LIB From c43324fe1614052517c8037351231e715c7f7d18 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 25 Sep 2023 13:47:32 +0000 Subject: [PATCH 0129/1623] [nrf fromtree] doc/release-notes: Add info on downgrade prevention Kconfig Adds note on addition of MCUBOOT_BOOTLOADER_MODE_WITH_DOWNGRADE_PREVENTION to MCUboot Kconfig module. (cherry picked from commit a43107299f6d4217f6730ccccf6a0e771357c3ca) Signed-off-by: Dominik Ermel (cherry picked from commit c0efcb71cf08290c193cf180e75d8005c01206d7) --- doc/releases/release-notes-3.5.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/releases/release-notes-3.5.rst b/doc/releases/release-notes-3.5.rst index 4f9a8ab1793..d22978d8a84 100644 --- a/doc/releases/release-notes-3.5.rst +++ b/doc/releases/release-notes-3.5.rst @@ -339,6 +339,11 @@ HALs MCUboot ******* + * Added :kconfig:option:`CONFIG_MCUBOOT_BOOTLOADER_NO_DOWNGRADE` + that allows to inform application that the on-board MCUboot has been configured + with downgrade prevention enabled. This option is automatically selected for + DirectXIP mode and is available for both swap modes. + Storage ******* From 8b829dcc8fdcd8d95fea171110fb3bec07a6f616 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Tue, 26 Sep 2023 17:45:55 +0000 Subject: [PATCH 0130/1623] [nrf fromtree] modules/MCUboot: Fix missing dependency The CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP has been missing select of CONFIG_MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE. (cherry picked from commit a2b238eee77cf9137db858618eb2881c53963330) Signed-off-by: Dominik Ermel (cherry picked from commit 64dc62fd2c921fb7a76542801f958411a5534f90) --- modules/Kconfig.mcuboot | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index ab1dd44fbd5..1679bfeb8a9 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -192,6 +192,7 @@ config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT bool "MCUboot has been configured for DirectXIP with revert" select MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP + select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE select MCUBOOT_BOOTLOADER_NO_DOWNGRADE help MCUboot expects slot0_partition and slot1_partition to exist in DT. From 45ac1f809fef282566c124dc676c951428d707bc Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Thu, 28 Sep 2023 11:10:55 +0000 Subject: [PATCH 0131/1623] [nrf noup] mgmt/MCUmgr/grp/img: Move out label to make compiler happy Move it inside ifdef. Signed-off-by: Dominik Ermel (cherry picked from commit 2fb8d761dbe3aeecc9285205cb9760701134463a) --- subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c index 0968694c614..61515c14655 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c @@ -290,13 +290,14 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) return_slot = other_slot; } } +out: + #else if (rcs == 0 && rca == 0 && img_mgmt_vercmp(&aver, &over) < 0) { return_slot = other_slot; } #endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */ -out: if (type != NULL) { *type = lt; } From 04cd082a7d7b34ee66b07682e158ccbfafd93d8f Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 23 Aug 2023 13:31:48 +0200 Subject: [PATCH 0132/1623] [nrf fromtree] net: dhcpv6: Add Zephyr DHCPv6 client Add a DHCPv6 client implementation for Zephyr (RFC 8415). The implementation allows to request IPv6 address and/or prefix from the DHCPv6 server, and for now supports only the mandatory set of DHCPv6 options needed to achieve this. Currently the implementation supports the following scenarios: * Requesting new IPv6 address/prefix with Solicit/Request exchange * Refreshing existing leases with Confirm, Renew or Rebind (depending on the context). For now, no Information Request (the case where neither IPv6 address or prefix are requested) is supported. No support for Reconfigure was added either, as this is optional (the client manifests clearly to the server that it does not support Reconfigure). Support for these can be added later if needed. Signed-off-by: Robert Lubos (cherry picked from commit e73e78a550870d593e244226320dcd1c0acbcd41) (cherry picked from commit 793fcb68f839f64cd121894d9031cb149f08854d) --- include/zephyr/net/dhcpv6.h | 116 ++ include/zephyr/net/net_if.h | 70 + subsys/net/ip/CMakeLists.txt | 1 + subsys/net/ip/Kconfig.ipv6 | 14 + subsys/net/ip/dhcpv6.c | 2196 +++++++++++++++++++++++++++++++ subsys/net/ip/dhcpv6_internal.h | 196 +++ subsys/net/ip/net_core.c | 6 + 7 files changed, 2599 insertions(+) create mode 100644 include/zephyr/net/dhcpv6.h create mode 100644 subsys/net/ip/dhcpv6.c create mode 100644 subsys/net/ip/dhcpv6_internal.h diff --git a/include/zephyr/net/dhcpv6.h b/include/zephyr/net/dhcpv6.h new file mode 100644 index 00000000000..95b59f530b5 --- /dev/null +++ b/include/zephyr/net/dhcpv6.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** @file + * @brief DHCPv6 client + */ + +#ifndef ZEPHYR_INCLUDE_NET_DHCPV6_H_ +#define ZEPHYR_INCLUDE_NET_DHCPV6_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief DHCPv6 + * @defgroup dhcpv6 DHCPv6 + * @ingroup networking + * @{ + */ + +/** @cond INTERNAL_HIDDEN */ + +/** Current state of DHCPv6 client address/prefix negotiation. */ +enum net_dhcpv6_state { + NET_DHCPV6_DISABLED, + NET_DHCPV6_INIT, + NET_DHCPV6_SOLICITING, + NET_DHCPV6_REQUESTING, + NET_DHCPV6_CONFIRMING, + NET_DHCPV6_RENEWING, + NET_DHCPV6_REBINDING, + NET_DHCPV6_INFO_REQUESTING, + NET_DHCPV6_BOUND, +} __packed; + +#define DHCPV6_TID_SIZE 3 +#define DHCPV6_DUID_MAX_SIZE 20 + +struct net_dhcpv6_duid_raw { + uint16_t type; + uint8_t buf[DHCPV6_DUID_MAX_SIZE]; +} __packed; + +struct net_dhcpv6_duid_storage { + struct net_dhcpv6_duid_raw duid; + uint8_t length; +}; + +struct net_if; + +/** @endcond */ + +/** @brief DHCPv6 client configuration parameters. */ +struct net_dhcpv6_params { + bool request_addr : 1; /**< Request IPv6 address. */ + bool request_prefix : 1; /**< Request IPv6 prefix. */ +}; + +/** + * @brief Start DHCPv6 client on an iface + * + * @details Start DHCPv6 client on a given interface. DHCPv6 client will start + * negotiation for IPv6 address and/or prefix, depending on the configuration. + * Once the negotiation is complete, IPv6 address/prefix details will be added + * to the interface. + * + * @param iface A valid pointer to a network interface + * @param params DHCPv6 client configuration parameters. + */ +void net_dhcpv6_start(struct net_if *iface, struct net_dhcpv6_params *params); + +/** + * @brief Stop DHCPv6 client on an iface + * + * @details Stop DHCPv6 client on a given interface. DHCPv6 client + * will remove all configuration obtained from a DHCP server from the + * interface and stop any further negotiation with the server. + * + * @param iface A valid pointer to a network interface + */ +void net_dhcpv6_stop(struct net_if *iface); + +/** + * @brief Restart DHCPv6 client on an iface + * + * @details Restart DHCPv6 client on a given interface. DHCPv6 client + * will restart the state machine without any of the initial delays. + * + * @param iface A valid pointer to a network interface + */ +void net_dhcpv6_restart(struct net_if *iface); + +/** @cond INTERNAL_HIDDEN */ + +/** + * @brief DHCPv6 state name + * + * @internal + */ +const char *net_dhcpv6_state_name(enum net_dhcpv6_state state); + +/** @endcond */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_NET_DHCPV6_H_ */ diff --git a/include/zephyr/net/net_if.h b/include/zephyr/net/net_if.h index cced3557b84..b06bf74de03 100644 --- a/include/zephyr/net/net_if.h +++ b/include/zephyr/net/net_if.h @@ -33,6 +33,9 @@ #if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4) #include #endif +#if defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6) +#include +#endif #if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4) #include #endif @@ -275,6 +278,69 @@ struct net_if_ipv6 { uint8_t hop_limit; }; +#if defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6) +struct net_if_dhcpv6 { + /** Used for timer list. */ + sys_snode_t node; + + /** Generated Client ID. */ + struct net_dhcpv6_duid_storage clientid; + + /** Server ID of the selected server. */ + struct net_dhcpv6_duid_storage serverid; + + /** DHCPv6 client state. */ + enum net_dhcpv6_state state; + + /** DHCPv6 client configuration parameters. */ + struct net_dhcpv6_params params; + + /** Timeout for the next event, absolute time, milliseconds. */ + uint64_t timeout; + + /** Time of the current exchange start, absolute time, milliseconds */ + uint64_t exchange_start; + + /** Renewal time, absolute time, milliseconds. */ + uint64_t t1; + + /** Rebinding time, absolute time, milliseconds. */ + uint64_t t2; + + /** The time when the last lease expires (terminates rebinding, + * DHCPv6 RFC8415, ch. 18.2.5). Absolute time, milliseconds. + */ + uint64_t expire; + + /** Generated IAID for IA_NA. */ + uint32_t addr_iaid; + + /** Generated IAID for IA_PD. */ + uint32_t prefix_iaid; + + /** Retransmit timeout for the current message, milliseconds. */ + uint32_t retransmit_timeout; + + /** Current best server preference received. */ + int16_t server_preference; + + /** Retransmission counter. */ + uint8_t retransmissions; + + /** Transaction ID for current exchange. */ + uint8_t tid[DHCPV6_TID_SIZE]; + + /** Prefix length. */ + uint8_t prefix_len; + + /** Assigned IPv6 prefix. */ + struct in6_addr prefix; + + /** Assigned IPv6 address. */ + struct in6_addr addr; +}; +#endif /* defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6) */ + /** @cond INTERNAL_HIDDEN */ #if defined(CONFIG_NET_NATIVE_IPV4) #define NET_IF_MAX_IPV4_ADDR CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT @@ -413,6 +479,10 @@ struct net_if_config { struct net_if_dhcpv4 dhcpv4; #endif /* CONFIG_NET_DHCPV4 */ +#if defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6) + struct net_if_dhcpv6 dhcpv6; +#endif /* CONFIG_NET_DHCPV6 */ + #if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4) struct net_if_ipv4_autoconf ipv4auto; #endif /* CONFIG_NET_IPV4_AUTO */ diff --git a/subsys/net/ip/CMakeLists.txt b/subsys/net/ip/CMakeLists.txt index 70655e2f61c..7dc54935c5c 100644 --- a/subsys/net/ip/CMakeLists.txt +++ b/subsys/net/ip/CMakeLists.txt @@ -31,6 +31,7 @@ zephyr_library_sources(net_tc.c) zephyr_library_sources_ifdef(CONFIG_NET_IP connection.c) zephyr_library_sources_ifdef(CONFIG_NET_6LO 6lo.c) zephyr_library_sources_ifdef(CONFIG_NET_DHCPV4 dhcpv4.c) +zephyr_library_sources_ifdef(CONFIG_NET_DHCPV6 dhcpv6.c) zephyr_library_sources_ifdef(CONFIG_NET_IPV4_AUTO ipv4_autoconf.c) zephyr_library_sources_ifdef(CONFIG_NET_IPV4 icmpv4.c ipv4.c) zephyr_library_sources_ifdef(CONFIG_NET_IPV4_IGMP igmp.c) diff --git a/subsys/net/ip/Kconfig.ipv6 b/subsys/net/ip/Kconfig.ipv6 index b776d3756eb..18fb4b0ccc4 100644 --- a/subsys/net/ip/Kconfig.ipv6 +++ b/subsys/net/ip/Kconfig.ipv6 @@ -166,6 +166,12 @@ config NET_MAX_6LO_CONTEXTS 6lowpan context options table size. The value depends on your network and memory consumption. More 6CO options uses more memory. +config NET_DHCPV6 + bool "DHCPv6 client" + select NET_MGMT + select NET_MGMT_EVENT + depends on NET_UDP + if NET_6LO module = NET_6LO module-dep = NET_LOG @@ -192,5 +198,13 @@ module-str = Log level for IPv6 neighbor cache module-help = Enables IPv6 Neighbor Cache code to output debug messages. source "subsys/net/Kconfig.template.log_config.net" +if NET_DHCPV6 +module = NET_DHCPV6 +module-dep = NET_LOG +module-str = Log level for DHCPv6 client +module-help = Enables DHCPv6 client code to output debug messages. +source "subsys/net/Kconfig.template.log_config.net" +endif # NET_DHCPV6 + endif # NET_NATIVE_IPV6 endif # NET_IPV6 diff --git a/subsys/net/ip/dhcpv6.c b/subsys/net/ip/dhcpv6.c new file mode 100644 index 00000000000..040c9fa0e06 --- /dev/null +++ b/subsys/net/ip/dhcpv6.c @@ -0,0 +1,2196 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** @file + * @brief DHCPv6 client implementation + */ + +#include +LOG_MODULE_REGISTER(net_dhcpv6, CONFIG_NET_DHCPV6_LOG_LEVEL); + +#include +#include +#include +#include + +#include "dhcpv6_internal.h" +#include "ipv6.h" +#include "net_private.h" +#include "udp_internal.h" + +/* Maximum number of options client can request. */ +#define DHCPV6_MAX_OPTION_REQUEST 2 + +struct dhcpv6_options_include { + bool clientid : 1; + bool serverid : 1; + bool elapsed_time : 1; + bool ia_na : 1; + bool iaaddr : 1; + bool ia_pd : 1; + bool iaprefix : 1; + uint16_t oro[DHCPV6_MAX_OPTION_REQUEST]; +}; + +static K_MUTEX_DEFINE(lock); + +/* All_DHCP_Relay_Agents_and_Servers (ff02::1:2) */ +static const struct in6_addr all_dhcpv6_ra_and_servers = { { { 0xff, 0x02, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0x01, 0, 0x02 } } }; + +static sys_slist_t dhcpv6_ifaces = SYS_SLIST_STATIC_INIT(&dhcpv6_ifaces); +static struct k_work_delayable dhcpv6_timeout_work; +static struct net_mgmt_event_callback dhcpv6_mgmt_cb; + +const char *net_dhcpv6_state_name(enum net_dhcpv6_state state) +{ + static const char * const name[] = { + "disabled", + "init", + "soliciting", + "requesting", + "confirming", + "renewing", + "rebinding", + "information requesting", + "bound", + }; + + __ASSERT_NO_MSG(state >= 0 && state < sizeof(name)); + return name[state]; +} + +static void dhcpv6_generate_tid(struct net_if *iface) +{ + sys_rand_get(iface->config.dhcpv6.tid, sizeof(iface->config.dhcpv6.tid)); +} + +static void dhcvp6_update_deadlines(struct net_if *iface, int64_t now, + uint32_t t1, uint32_t t2, + uint32_t preferred_lifetime, + uint32_t valid_lifetime) +{ + uint64_t t1_abs, t2_abs, expire_abs; + + /* In case server does not set T1/T2 values, the time choice is left to + * the client discretion. + * Here, we use recommendations for the servers, where it's advised to + * set T1/T2 as 0.5 and 0.8 of the preferred lifetime. + */ + if (t1 == 0 && t2 == 0) { + if (preferred_lifetime == DHCPV6_INFINITY) { + t1 = DHCPV6_INFINITY; + t2 = DHCPV6_INFINITY; + } else { + t1 = preferred_lifetime * 0.5; + t2 = preferred_lifetime * 0.8; + } + } else if (t1 == 0) { + if (t2 == DHCPV6_INFINITY) { + t1 = DHCPV6_INFINITY; + } else { + t1 = t2 * 0.625; /* 0.5 / 0.8 */ + } + } else if (t2 == 0) { + if (t1 == DHCPV6_INFINITY) { + t2 = DHCPV6_INFINITY; + } else { + t2 = t1 * 1.6; /* 0.8 / 0.5 */ + /* Overflow check. */ + if (t2 < t1) { + t2 = DHCPV6_INFINITY; + } + } + } else if (t1 >= t2) { + NET_ERR("Invalid T1(%u)/T2(%u) values.", t1, t2); + return; + } + + if (t1 == DHCPV6_INFINITY || + u64_add_overflow(now, 1000ULL * t1, &t1_abs)) { + t1_abs = UINT64_MAX; + } + + if (t2 == DHCPV6_INFINITY || + u64_add_overflow(now, 1000ULL * t2, &t2_abs)) { + t2_abs = UINT64_MAX; + } + + if (valid_lifetime == DHCPV6_INFINITY || + u64_add_overflow(now, 1000ULL * valid_lifetime, &expire_abs)) { + expire_abs = UINT64_MAX; + } + + if (iface->config.dhcpv6.t1 > t1_abs) { + iface->config.dhcpv6.t1 = t1_abs; + } + + if (iface->config.dhcpv6.t2 > t2_abs) { + iface->config.dhcpv6.t2 = t2_abs; + } + + if (iface->config.dhcpv6.expire < expire_abs) { + iface->config.dhcpv6.expire = expire_abs; + } +} + +static void dhcpv6_set_timeout(struct net_if *iface, uint64_t timeout) +{ + int64_t now = k_uptime_get(); + + NET_DBG("sched dhcpv6 timeout iface=%p timeout=%llums", iface, timeout); + + if (u64_add_overflow(now, timeout, &iface->config.dhcpv6.timeout)) { + iface->config.dhcpv6.timeout = UINT64_MAX; + } +} + +static void dhcpv6_reschedule(void) +{ + k_work_reschedule(&dhcpv6_timeout_work, K_NO_WAIT); +} + +static int randomize_timeout(int multiplier, int timeout) +{ + int factor; + + /* DHCPv6 RFC8415, ch. 15. the randomization factor should be a random + * number between -0.1 nand +0.1. As we operate on integers here, we + * scale it to -100 and +100, and divide the result by 1000. + */ + factor = (int)(sys_rand32_get() % 201) - 100; + + return (multiplier * timeout) + ((factor * timeout) / 1000); +} + +static int dhcpv6_initial_retransmit_time(int init_retransmit_time) +{ + /* DHCPv6 RFC8415, ch. 15. Retransmission time for the first msg. */ + return randomize_timeout(1, init_retransmit_time); +} + +static uint32_t dhcpv6_next_retransmit_time(int prev_retransmit_time, + int max_retransmit_time) +{ + int retransmit_time; + + /* DHCPv6 RFC8415, ch. 15. Retransmission time for the subsequent msg. */ + retransmit_time = randomize_timeout(2, prev_retransmit_time); + + if (max_retransmit_time == 0) { + return retransmit_time; + } + + if (retransmit_time > max_retransmit_time) { + retransmit_time = randomize_timeout(1, max_retransmit_time); + } + + return retransmit_time; +} + +/* DHCPv6 packet encoding functions */ + +static int dhcpv6_add_header(struct net_pkt *pkt, enum dhcpv6_msg_type type, + uint8_t *tid) +{ + int ret; + + ret = net_pkt_write_u8(pkt, type); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write(pkt, tid, DHCPV6_TID_SIZE); + + return ret; +} + +static int dhcpv6_add_option_header(struct net_pkt *pkt, + enum dhcpv6_option_code code, + uint16_t length) +{ + int ret; + + ret = net_pkt_write_be16(pkt, code); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_be16(pkt, length); + + return ret; +} + +static int dhcpv6_add_option_clientid(struct net_pkt *pkt, + struct net_dhcpv6_duid_storage *clientid) +{ + int ret; + + ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_CLIENTID, + clientid->length); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write(pkt, &clientid->duid, clientid->length); + + return ret; +} + +static int dhcpv6_add_option_serverid(struct net_pkt *pkt, + struct net_dhcpv6_duid_storage *serverid) +{ + int ret; + + ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_SERVERID, + serverid->length); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write(pkt, &serverid->duid, serverid->length); + + return ret; +} + + +static int dhcpv6_add_option_elapsed_time(struct net_pkt *pkt, uint64_t since) +{ + uint64_t elapsed; + int ret; + + ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_ELAPSED_TIME, + DHCPV6_OPTION_ELAPSED_TIME_SIZE); + if (ret < 0) { + return ret; + } + + /* Elapsed time should be expressed in hundredths of a second. */ + elapsed = (k_uptime_get() - since) / 10ULL; + if (elapsed > 0xFFFF) { + elapsed = 0xFFFF; + } + + ret = net_pkt_write_be16(pkt, (uint16_t)elapsed); + + return ret; +} + +static int dhcpv6_add_option_ia_na(struct net_pkt *pkt, struct dhcpv6_ia_na *ia_na, + bool include_addr) +{ + uint16_t optlen; + int ret; + + if (!include_addr) { + optlen = DHCPV6_OPTION_IA_NA_HEADER_SIZE; + } else { + optlen = DHCPV6_OPTION_IA_NA_HEADER_SIZE + + DHCPV6_OPTION_HEADER_SIZE + + DHCPV6_OPTION_IAADDR_HEADER_SIZE; + } + + ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_IA_NA, optlen); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_be32(pkt, ia_na->iaid); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_be32(pkt, ia_na->t1); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_be32(pkt, ia_na->t2); + if (ret < 0) { + return ret; + } + + if (!include_addr) { + return 0; + } + + ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_IAADDR, + DHCPV6_OPTION_IAADDR_HEADER_SIZE); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write(pkt, &ia_na->iaaddr.addr, sizeof(ia_na->iaaddr.addr)); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_be32(pkt, ia_na->iaaddr.preferred_lifetime); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_be32(pkt, ia_na->iaaddr.valid_lifetime); + + return ret; +} + +static int dhcpv6_add_option_ia_pd(struct net_pkt *pkt, struct dhcpv6_ia_pd *ia_pd, + bool include_prefix) +{ + uint16_t optlen; + int ret; + + if (!include_prefix) { + optlen = DHCPV6_OPTION_IA_PD_HEADER_SIZE; + } else { + optlen = DHCPV6_OPTION_IA_PD_HEADER_SIZE + + DHCPV6_OPTION_HEADER_SIZE + + DHCPV6_OPTION_IAPREFIX_HEADER_SIZE; + } + + ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_IA_PD, + optlen); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_be32(pkt, ia_pd->iaid); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_be32(pkt, ia_pd->t1); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_be32(pkt, ia_pd->t2); + if (ret < 0) { + return ret; + } + + if (!include_prefix) { + return 0; + } + + ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_IAPREFIX, + DHCPV6_OPTION_IAPREFIX_HEADER_SIZE); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_be32(pkt, ia_pd->iaprefix.preferred_lifetime); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_be32(pkt, ia_pd->iaprefix.valid_lifetime); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write_u8(pkt, ia_pd->iaprefix.prefix_len); + if (ret < 0) { + return ret; + } + + ret = net_pkt_write(pkt, &ia_pd->iaprefix.prefix, + sizeof(ia_pd->iaprefix.prefix)); + + return ret; +} + +static int dhcpv6_add_option_oro(struct net_pkt *pkt, uint16_t *codes, + int code_cnt) +{ + int ret; + + ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_ORO, + sizeof(uint16_t) * code_cnt); + if (ret < 0) { + return ret; + } + + for (int i = 0; i < code_cnt; i++) { + ret = net_pkt_write_be16(pkt, codes[i]); + if (ret < 0) { + return ret; + } + } + + return ret; +} + +static size_t dhcpv6_calculate_message_size(struct dhcpv6_options_include *options) +{ + size_t msg_size = sizeof(struct dhcpv6_msg_hdr); + uint8_t oro_cnt = 0; + + if (options->clientid) { + msg_size += DHCPV6_OPTION_HEADER_SIZE; + msg_size += sizeof(struct net_dhcpv6_duid_storage); + } + + if (options->serverid) { + msg_size += DHCPV6_OPTION_HEADER_SIZE; + msg_size += sizeof(struct net_dhcpv6_duid_storage); + } + + if (options->elapsed_time) { + msg_size += DHCPV6_OPTION_HEADER_SIZE; + msg_size += DHCPV6_OPTION_ELAPSED_TIME_SIZE; + } + + if (options->ia_na) { + msg_size += DHCPV6_OPTION_HEADER_SIZE; + msg_size += DHCPV6_OPTION_IA_NA_HEADER_SIZE; + } + + if (options->iaaddr) { + msg_size += DHCPV6_OPTION_HEADER_SIZE; + msg_size += DHCPV6_OPTION_IAADDR_HEADER_SIZE; + } + + if (options->ia_pd) { + msg_size += DHCPV6_OPTION_HEADER_SIZE; + msg_size += DHCPV6_OPTION_IA_PD_HEADER_SIZE; + } + + if (options->iaprefix) { + msg_size += DHCPV6_OPTION_HEADER_SIZE; + msg_size += DHCPV6_OPTION_IAPREFIX_HEADER_SIZE; + } + + for (uint8_t i = 0; i < ARRAY_SIZE(options->oro); i++) { + if (options->oro[i] == 0) { + break; + } + + oro_cnt++; + } + + if (oro_cnt > 0) { + msg_size += DHCPV6_OPTION_HEADER_SIZE; + msg_size += oro_cnt * sizeof(uint16_t); + } + + return msg_size; +} + +static int dhcpv6_add_options(struct net_if *iface, struct net_pkt *pkt, + struct dhcpv6_options_include *options) +{ + uint8_t oro_cnt = 0; + int ret; + + if (options->clientid) { + ret = dhcpv6_add_option_clientid( + pkt, &iface->config.dhcpv6.clientid); + if (ret < 0) { + goto fail; + } + } + + if (options->serverid) { + ret = dhcpv6_add_option_serverid( + pkt, &iface->config.dhcpv6.serverid); + if (ret < 0) { + goto fail; + } + } + + if (options->elapsed_time) { + ret = dhcpv6_add_option_elapsed_time( + pkt, iface->config.dhcpv6.exchange_start); + if (ret < 0) { + goto fail; + } + } + + if (options->ia_na) { + struct dhcpv6_ia_na ia_na = { + .iaid = iface->config.dhcpv6.addr_iaid, + }; + + if (options->iaaddr) { + memcpy(&ia_na.iaaddr.addr, &iface->config.dhcpv6.addr, + sizeof(ia_na.iaaddr.addr)); + } + + ret = dhcpv6_add_option_ia_na(pkt, &ia_na, options->iaaddr); + if (ret < 0) { + goto fail; + } + } + + if (options->ia_pd) { + struct dhcpv6_ia_pd ia_pd = { + .iaid = iface->config.dhcpv6.prefix_iaid, + }; + + if (options->iaprefix) { + memcpy(&ia_pd.iaprefix.prefix, &iface->config.dhcpv6.prefix, + sizeof(ia_pd.iaprefix.prefix)); + ia_pd.iaprefix.prefix_len = iface->config.dhcpv6.prefix_len; + } + + ret = dhcpv6_add_option_ia_pd(pkt, &ia_pd, options->iaprefix); + if (ret < 0) { + goto fail; + } + } + + for (uint8_t i = 0; i < ARRAY_SIZE(options->oro); i++) { + if (options->oro[i] == 0) { + break; + } + + oro_cnt++; + } + + if (oro_cnt > 0) { + ret = dhcpv6_add_option_oro(pkt, options->oro, oro_cnt); + if (ret < 0) { + goto fail; + } + } + + return 0; + +fail: + return ret; +} + +static struct net_pkt *dhcpv6_create_message(struct net_if *iface, + enum dhcpv6_msg_type msg_type, + struct dhcpv6_options_include *options) +{ + struct in6_addr *local_addr; + struct net_pkt *pkt; + size_t msg_size; + + local_addr = net_if_ipv6_get_ll(iface, NET_ADDR_ANY_STATE); + if (local_addr == NULL) { + NET_ERR("No LL address"); + return NULL; + } + + msg_size = dhcpv6_calculate_message_size(options); + + pkt = net_pkt_alloc_with_buffer(iface, msg_size, AF_INET6, + IPPROTO_UDP, K_FOREVER); + if (pkt == NULL) { + return NULL; + } + + if (net_ipv6_create(pkt, local_addr, &all_dhcpv6_ra_and_servers) < 0 || + net_udp_create(pkt, htons(DHCPV6_CLIENT_PORT), + htons(DHCPV6_SERVER_PORT)) < 0) { + goto fail; + } + + dhcpv6_generate_tid(iface); + + if (dhcpv6_add_header(pkt, msg_type, iface->config.dhcpv6.tid) < 0) { + goto fail; + } + + if (dhcpv6_add_options(iface, pkt, options) < 0) { + goto fail; + } + + net_pkt_cursor_init(pkt); + net_ipv6_finalize(pkt, IPPROTO_UDP); + + return pkt; + +fail: + net_pkt_unref(pkt); + + return NULL; +} + +static int dhcpv6_send_solicit(struct net_if *iface) +{ + int ret; + struct net_pkt *pkt; + struct dhcpv6_options_include options = { + .clientid = true, + .elapsed_time = true, + .ia_na = iface->config.dhcpv6.params.request_addr, + .ia_pd = iface->config.dhcpv6.params.request_prefix, + .oro = { DHCPV6_OPTION_CODE_SOL_MAX_RT }, + }; + + pkt = dhcpv6_create_message(iface, DHCPV6_MSG_TYPE_SOLICIT, &options); + if (pkt == NULL) { + return -ENOMEM; + } + + ret = net_send_data(pkt); + if (ret < 0) { + net_pkt_unref(pkt); + } + + return ret; +} + +static int dhcpv6_send_request(struct net_if *iface) +{ + int ret; + struct net_pkt *pkt; + struct dhcpv6_options_include options = { + .clientid = true, + .serverid = true, + .elapsed_time = true, + .ia_na = iface->config.dhcpv6.params.request_addr, + .ia_pd = iface->config.dhcpv6.params.request_prefix, + .oro = { DHCPV6_OPTION_CODE_SOL_MAX_RT }, + }; + + pkt = dhcpv6_create_message(iface, DHCPV6_MSG_TYPE_REQUEST, &options); + if (pkt == NULL) { + return -ENOMEM; + } + + ret = net_send_data(pkt); + if (ret < 0) { + net_pkt_unref(pkt); + } + + return ret; +} + +static int dhcpv6_send_renew(struct net_if *iface) +{ + int ret; + struct net_pkt *pkt; + struct dhcpv6_options_include options = { + .clientid = true, + .serverid = true, + .elapsed_time = true, + .ia_na = iface->config.dhcpv6.params.request_addr, + .iaaddr = iface->config.dhcpv6.params.request_addr, + .ia_pd = iface->config.dhcpv6.params.request_prefix, + .iaprefix = iface->config.dhcpv6.params.request_prefix, + .oro = { DHCPV6_OPTION_CODE_SOL_MAX_RT }, + }; + + pkt = dhcpv6_create_message(iface, DHCPV6_MSG_TYPE_RENEW, &options); + if (pkt == NULL) { + return -ENOMEM; + } + + ret = net_send_data(pkt); + if (ret < 0) { + net_pkt_unref(pkt); + } + + return ret; +} + +static int dhcpv6_send_rebind(struct net_if *iface) +{ + int ret; + struct net_pkt *pkt; + struct dhcpv6_options_include options = { + .clientid = true, + .elapsed_time = true, + .ia_na = iface->config.dhcpv6.params.request_addr, + .iaaddr = iface->config.dhcpv6.params.request_addr, + .ia_pd = iface->config.dhcpv6.params.request_prefix, + .iaprefix = iface->config.dhcpv6.params.request_prefix, + .oro = { DHCPV6_OPTION_CODE_SOL_MAX_RT }, + }; + + pkt = dhcpv6_create_message(iface, DHCPV6_MSG_TYPE_REBIND, &options); + if (pkt == NULL) { + return -ENOMEM; + } + + ret = net_send_data(pkt); + if (ret < 0) { + net_pkt_unref(pkt); + } + + return ret; +} + +static int dhcpv6_send_confirm(struct net_if *iface) +{ + int ret; + struct net_pkt *pkt; + struct dhcpv6_options_include options = { + .clientid = true, + .elapsed_time = true, + .ia_na = true, + .iaaddr = true, + }; + + pkt = dhcpv6_create_message(iface, DHCPV6_MSG_TYPE_CONFIRM, &options); + if (pkt == NULL) { + return -ENOMEM; + } + + ret = net_send_data(pkt); + if (ret < 0) { + net_pkt_unref(pkt); + } + + return ret; +} + +/* DHCPv6 packet parsing functions */ + +static int dhcpv6_parse_option_clientid(struct net_pkt *pkt, uint16_t length, + struct net_dhcpv6_duid_storage *clientid) +{ + struct net_dhcpv6_duid_raw duid; + int ret; + + if (length > sizeof(struct net_dhcpv6_duid_raw)) { + NET_ERR("DUID too large to handle"); + return -EMSGSIZE; + } + + ret = net_pkt_read(pkt, &duid, length); + if (ret < 0) { + return ret; + } + + clientid->length = length; + memcpy(&clientid->duid, &duid, length); + + return 0; +} + +static int dhcpv6_parse_option_serverid(struct net_pkt *pkt, uint16_t length, + struct net_dhcpv6_duid_storage *serverid) +{ + struct net_dhcpv6_duid_raw duid; + int ret; + + if (length > sizeof(struct net_dhcpv6_duid_raw)) { + NET_ERR("DUID too large to handle"); + return -EMSGSIZE; + } + + ret = net_pkt_read(pkt, &duid, length); + if (ret < 0) { + return ret; + } + + serverid->length = length; + memcpy(&serverid->duid, &duid, length); + + return 0; +} + +static int dhcpv6_parse_option_preference(struct net_pkt *pkt, uint16_t length, + uint8_t *preference) +{ + if (length != DHCPV6_OPTION_PREFERENCE_SIZE) { + return -EBADMSG; + } + + if (net_pkt_read_u8(pkt, preference) < 0) { + return -EBADMSG; + } + + return 0; +} + +static int dhcpv6_parse_option_status_code(struct net_pkt *pkt, + uint16_t length, uint16_t *status) +{ + int ret; + + if (length < DHCPV6_OPTION_STATUS_CODE_HEADER_SIZE) { + NET_ERR("Invalid IAADDR option size"); + return -EMSGSIZE; + } + + ret = net_pkt_read_be16(pkt, status); + if (ret < 0) { + return ret; + } + + NET_DBG("status code %d", *status); + + length -= DHCPV6_OPTION_STATUS_CODE_HEADER_SIZE; + if (length > 0) { + /* Ignore status message */ + ret = net_pkt_skip(pkt, length); + } + + return ret; +} + +static int dhcpv6_parse_option_iaaddr(struct net_pkt *pkt, uint16_t length, + struct dhcpv6_iaaddr *iaaddr) +{ + int ret; + + if (length < DHCPV6_OPTION_IAADDR_HEADER_SIZE) { + NET_ERR("Invalid IAADDR option size"); + return -EMSGSIZE; + } + + ret = net_pkt_read(pkt, &iaaddr->addr, sizeof(iaaddr->addr)); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_be32(pkt, &iaaddr->preferred_lifetime); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_be32(pkt, &iaaddr->valid_lifetime); + if (ret < 0) { + return ret; + } + + /* DHCPv6 RFC8415, ch. 21.6 The client MUST discard any addresses for + * which the preferred lifetime is greater than the valid lifetime. + */ + if (iaaddr->preferred_lifetime > iaaddr->valid_lifetime) { + return -EBADMSG; + } + + NET_DBG("addr %s preferred_lifetime %d valid_lifetime %d", + net_sprint_ipv6_addr(&iaaddr->addr), iaaddr->preferred_lifetime, + iaaddr->valid_lifetime); + + iaaddr->status = DHCPV6_STATUS_SUCCESS; + + length -= DHCPV6_OPTION_IAADDR_HEADER_SIZE; + while (length > 0) { + uint16_t code, sublen; + + ret = net_pkt_read_be16(pkt, &code); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_be16(pkt, &sublen); + if (ret < 0) { + return ret; + } + + switch (code) { + case DHCPV6_OPTION_CODE_STATUS_CODE: + ret = dhcpv6_parse_option_status_code(pkt, sublen, + &iaaddr->status); + if (ret < 0) { + return ret; + } + + break; + default: + net_pkt_skip(pkt, sublen); + NET_DBG("Unexpected option %d length %d", code, sublen); + break; + } + + length -= (sublen + 4); + } + + return 0; +} + +static int dhcpv6_parse_option_ia_na(struct net_pkt *pkt, uint16_t length, + struct dhcpv6_ia_na *ia_na) +{ + int ret; + + if (length < DHCPV6_OPTION_IA_NA_HEADER_SIZE) { + NET_ERR("Invalid IA_NA option size"); + return -EMSGSIZE; + } + + ret = net_pkt_read_be32(pkt, &ia_na->iaid); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_be32(pkt, &ia_na->t1); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_be32(pkt, &ia_na->t2); + if (ret < 0) { + return ret; + } + + /* DHCPv6 RFC8415, ch. 21.4 If a client receives an IA_NA with T1 + * greater than T2 and both T1 and T2 are greater than 0, the client + * discards the IA_NA option and processes the remainder of the message + * as though the server had not included the invalid IA_NA option. + */ + if (ia_na->t1 != 0 && ia_na->t2 != 0 && ia_na->t1 > ia_na->t2) { + return -ENOENT; + } + + NET_DBG("iaid %d t1 %d t2 %d", ia_na->iaid, ia_na->t1, ia_na->t2); + + /* In case there's no IAADDR option, make this visible be setting + * error status. If the option is present, option parser will overwrite + * the value. + */ + ia_na->iaaddr.status = DHCPV6_STATUS_NO_ADDR_AVAIL; + ia_na->status = DHCPV6_STATUS_SUCCESS; + + length -= DHCPV6_OPTION_IA_NA_HEADER_SIZE; + while (length > 0) { + uint16_t code, sublen; + + ret = net_pkt_read_be16(pkt, &code); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_be16(pkt, &sublen); + if (ret < 0) { + return ret; + } + + switch (code) { + case DHCPV6_OPTION_CODE_IAADDR: + ret = dhcpv6_parse_option_iaaddr(pkt, sublen, + &ia_na->iaaddr); + if (ret < 0) { + return ret; + } + + break; + + case DHCPV6_OPTION_CODE_STATUS_CODE: + ret = dhcpv6_parse_option_status_code(pkt, sublen, + &ia_na->status); + if (ret < 0) { + return ret; + } + + break; + + default: + net_pkt_skip(pkt, sublen); + NET_DBG("Unexpected option %d length %d", code, sublen); + break; + } + + length -= (sublen + 4); + } + + return 0; +} + +static int dhcpv6_parse_option_iaprefix(struct net_pkt *pkt, uint16_t length, + struct dhcpv6_iaprefix *iaprefix) +{ + int ret; + + if (length < DHCPV6_OPTION_IAPREFIX_HEADER_SIZE) { + NET_ERR("Invalid IAPREFIX option size"); + return -EMSGSIZE; + } + + ret = net_pkt_read_be32(pkt, &iaprefix->preferred_lifetime); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_be32(pkt, &iaprefix->valid_lifetime); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_u8(pkt, &iaprefix->prefix_len); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read(pkt, &iaprefix->prefix, sizeof(iaprefix->prefix)); + if (ret < 0) { + return ret; + } + + /* DHCPv6 RFC8415, ch. 21.22 The client MUST discard any prefixes for + * which the preferred lifetime is greater than the valid lifetime. + */ + if (iaprefix->preferred_lifetime > iaprefix->valid_lifetime) { + return -EBADMSG; + } + + NET_DBG("prefix %s/%u preferred_lifetime %d valid_lifetime %d", + net_sprint_ipv6_addr(&iaprefix->prefix), iaprefix->prefix_len, + iaprefix->preferred_lifetime, iaprefix->valid_lifetime); + + iaprefix->status = DHCPV6_STATUS_SUCCESS; + + length -= DHCPV6_OPTION_IAPREFIX_HEADER_SIZE; + while (length > 0) { + uint16_t code, sublen; + + ret = net_pkt_read_be16(pkt, &code); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_be16(pkt, &sublen); + if (ret < 0) { + return ret; + } + + switch (code) { + case DHCPV6_OPTION_CODE_STATUS_CODE: + ret = dhcpv6_parse_option_status_code(pkt, sublen, + &iaprefix->status); + if (ret < 0) { + return ret; + } + + break; + default: + net_pkt_skip(pkt, sublen); + NET_DBG("Unexpected option %d length %d", code, sublen); + break; + } + + length -= (sublen + 4); + } + + return 0; +} + +static int dhcpv6_parse_option_ia_pd(struct net_pkt *pkt, uint16_t length, + struct dhcpv6_ia_pd *ia_pd) +{ + int ret; + + if (length < DHCPV6_OPTION_IA_PD_HEADER_SIZE) { + NET_ERR("Invalid IA_PD option size"); + return -EMSGSIZE; + } + + ret = net_pkt_read_be32(pkt, &ia_pd->iaid); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_be32(pkt, &ia_pd->t1); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_be32(pkt, &ia_pd->t2); + if (ret < 0) { + return ret; + } + + /* DHCPv6 RFC8415, ch. 21.21 If a client receives an IA_PD with T1 + * greater than T2 and both T1 and T2 are greater than 0, the client + * discards the IA_PD option and processes the remainder of the message + * as though the server had not included the IA_PD option. + */ + if (ia_pd->t1 != 0 && ia_pd->t2 != 0 && ia_pd->t1 > ia_pd->t2) { + return -ENOENT; + } + + NET_DBG("iaid %d t1 %d t2 %d", ia_pd->iaid, ia_pd->t1, ia_pd->t2); + + /* In case there's no IAPREFIX option, make this visible be setting + * error status. If the option is present, option parser will overwrite + * the value. + */ + ia_pd->iaprefix.status = DHCPV6_STATUS_NO_PREFIX_AVAIL; + ia_pd->status = DHCPV6_STATUS_SUCCESS; + + length -= DHCPV6_OPTION_IA_PD_HEADER_SIZE; + while (length > 0) { + uint16_t code, sublen; + + ret = net_pkt_read_be16(pkt, &code); + if (ret < 0) { + return ret; + } + + ret = net_pkt_read_be16(pkt, &sublen); + if (ret < 0) { + return ret; + } + + switch (code) { + case DHCPV6_OPTION_CODE_IAPREFIX: + ret = dhcpv6_parse_option_iaprefix(pkt, sublen, + &ia_pd->iaprefix); + if (ret < 0) { + return ret; + } + + break; + + case DHCPV6_OPTION_CODE_STATUS_CODE: + ret = dhcpv6_parse_option_status_code(pkt, sublen, + &ia_pd->status); + if (ret < 0) { + return ret; + } + + break; + default: + net_pkt_skip(pkt, sublen); + NET_DBG("Unexpected option %d length %d", code, sublen); + break; + } + + length -= (sublen + 4); + } + + return 0; +} + +static int dhcpv6_find_option(struct net_pkt *pkt, enum dhcpv6_option_code opt_code, + uint16_t *opt_len) +{ + uint16_t length; + uint16_t code; + + while (net_pkt_read_be16(pkt, &code) == 0) { + if (net_pkt_read_be16(pkt, &length) < 0) { + return -EBADMSG; + } + + if (code == opt_code) { + *opt_len = length; + return 0; + } + + net_pkt_skip(pkt, length); + } + + return -ENOENT; +} + +static int dhcpv6_find_clientid(struct net_pkt *pkt, + struct net_dhcpv6_duid_storage *clientid) +{ + struct net_pkt_cursor backup; + uint16_t length; + int ret; + + net_pkt_cursor_backup(pkt, &backup); + + ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_CLIENTID, &length); + if (ret == 0) { + ret = dhcpv6_parse_option_clientid(pkt, length, clientid); + } + + net_pkt_cursor_restore(pkt, &backup); + + return ret; +} + +static int dhcpv6_find_serverid(struct net_pkt *pkt, + struct net_dhcpv6_duid_storage *serverid) +{ + struct net_pkt_cursor backup; + uint16_t length; + int ret; + + net_pkt_cursor_backup(pkt, &backup); + + ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_SERVERID, &length); + if (ret == 0) { + ret = dhcpv6_parse_option_serverid(pkt, length, serverid); + } + + net_pkt_cursor_restore(pkt, &backup); + + return ret; +} + +static int dhcpv6_find_server_preference(struct net_pkt *pkt, + uint8_t *preference) +{ + struct net_pkt_cursor backup; + uint16_t length; + int ret; + + net_pkt_cursor_backup(pkt, &backup); + + ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_PREFERENCE, &length); + if (ret == 0) { + ret = dhcpv6_parse_option_preference(pkt, length, preference); + } else if (ret == -ENOENT) { + /* In case no preference option is present, default to 0. + * DHCPv6 RFC8415, ch. 18.2.1. + */ + *preference = 0; + ret = 0; + } + + net_pkt_cursor_restore(pkt, &backup); + + return ret; +} + +static int dhcpv6_find_ia_na(struct net_pkt *pkt, struct dhcpv6_ia_na *ia_na) +{ + struct net_pkt_cursor backup; + uint16_t length; + int ret; + + net_pkt_cursor_backup(pkt, &backup); + + ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_IA_NA, &length); + if (ret == 0) { + ret = dhcpv6_parse_option_ia_na(pkt, length, ia_na); + } + + net_pkt_cursor_restore(pkt, &backup); + + return ret; +} + +static int dhcpv6_find_ia_pd(struct net_pkt *pkt, struct dhcpv6_ia_pd *ia_pd) +{ + struct net_pkt_cursor backup; + uint16_t length; + int ret; + + net_pkt_cursor_backup(pkt, &backup); + + ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_IA_PD, &length); + if (ret == 0) { + ret = dhcpv6_parse_option_ia_pd(pkt, length, ia_pd); + } + + net_pkt_cursor_restore(pkt, &backup); + + return ret; +} + +static int dhcpv6_find_status_code(struct net_pkt *pkt, uint16_t *status) +{ + struct net_pkt_cursor backup; + uint16_t length; + int ret; + + net_pkt_cursor_backup(pkt, &backup); + + ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_STATUS_CODE, &length); + if (ret == 0) { + ret = dhcpv6_parse_option_status_code(pkt, length, status); + } else if (ret == -ENOENT) { + /* In case no status option is present, default to success. + * DHCPv6 RFC8415, ch. 21.13. + */ + *status = DHCPV6_STATUS_SUCCESS; + ret = 0; + } + + net_pkt_cursor_restore(pkt, &backup); + + return ret; +} + +/* DHCPv6 state changes */ + +static void dhcpv6_enter_init(struct net_if *iface) +{ + uint32_t timeout; + + /* RFC8415 requires to wait a random period up to 1 second before + * sending the initial solicit/information request/confirm. + */ + timeout = sys_rand32_get() % DHCPV6_SOL_MAX_DELAY; + + dhcpv6_set_timeout(iface, timeout); +} + +static void dhcpv6_enter_soliciting(struct net_if *iface) +{ + iface->config.dhcpv6.retransmit_timeout = + dhcpv6_initial_retransmit_time(DHCPV6_SOL_TIMEOUT); + iface->config.dhcpv6.retransmissions = 0; + iface->config.dhcpv6.server_preference = -1; + iface->config.dhcpv6.exchange_start = k_uptime_get(); + + (void)dhcpv6_send_solicit(iface); + dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); +} + +static void dhcpv6_enter_requesting(struct net_if *iface) +{ + iface->config.dhcpv6.retransmit_timeout = + dhcpv6_initial_retransmit_time(DHCPV6_REQ_TIMEOUT); + iface->config.dhcpv6.retransmissions = 0; + iface->config.dhcpv6.exchange_start = k_uptime_get(); + + (void)dhcpv6_send_request(iface); + dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); +} + +static void dhcpv6_enter_renewing(struct net_if *iface) +{ + iface->config.dhcpv6.retransmit_timeout = + dhcpv6_initial_retransmit_time(DHCPV6_REN_TIMEOUT); + iface->config.dhcpv6.retransmissions = 0; + iface->config.dhcpv6.exchange_start = k_uptime_get(); + + (void)dhcpv6_send_renew(iface); + dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); +} + +static void dhcpv6_enter_rebinding(struct net_if *iface) +{ + iface->config.dhcpv6.retransmit_timeout = + dhcpv6_initial_retransmit_time(DHCPV6_REB_TIMEOUT); + iface->config.dhcpv6.retransmissions = 0; + iface->config.dhcpv6.exchange_start = k_uptime_get(); + + (void)dhcpv6_send_rebind(iface); + dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); +} + +static void dhcpv6_enter_confirming(struct net_if *iface) +{ + iface->config.dhcpv6.retransmit_timeout = + dhcpv6_initial_retransmit_time(DHCPV6_CNF_TIMEOUT); + iface->config.dhcpv6.retransmissions = 0; + iface->config.dhcpv6.exchange_start = k_uptime_get(); + + (void)dhcpv6_send_confirm(iface); + dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); +} + +static void dhcpv6_enter_bound(struct net_if *iface) +{ + iface->config.dhcpv6.timeout = iface->config.dhcpv6.t1; +} + +static void dhcpv6_enter_state(struct net_if *iface, enum net_dhcpv6_state state) +{ + iface->config.dhcpv6.state = state; + + NET_DBG("enter state=%s", + net_dhcpv6_state_name(iface->config.dhcpv6.state)); + + switch (iface->config.dhcpv6.state) { + case NET_DHCPV6_DISABLED: + break; + case NET_DHCPV6_INIT: + return dhcpv6_enter_init(iface); + case NET_DHCPV6_SOLICITING: + return dhcpv6_enter_soliciting(iface); + case NET_DHCPV6_REQUESTING: + return dhcpv6_enter_requesting(iface); + case NET_DHCPV6_CONFIRMING: + return dhcpv6_enter_confirming(iface); + case NET_DHCPV6_RENEWING: + return dhcpv6_enter_renewing(iface); + case NET_DHCPV6_REBINDING: + return dhcpv6_enter_rebinding(iface); + case NET_DHCPV6_INFO_REQUESTING: + break; + case NET_DHCPV6_BOUND: + return dhcpv6_enter_bound(iface); + } +} + +/* DHCPv6 input processing */ + +static int dhcpv6_handle_advertise(struct net_if *iface, struct net_pkt *pkt, + uint8_t *tid) +{ + struct net_dhcpv6_duid_storage duid = { 0 }; + struct dhcpv6_ia_pd ia_pd = { 0 }; + struct dhcpv6_ia_na ia_na = { 0 }; + uint8_t server_preference = 0; + uint16_t status = 0; + int ret; + + if (iface->config.dhcpv6.state != NET_DHCPV6_SOLICITING) { + return -EINVAL; + } + + /* Verify client ID. */ + ret = dhcpv6_find_clientid(pkt, &duid); + if (ret < 0) { + NET_ERR("Client ID missing"); + return ret; + } + + if (iface->config.dhcpv6.clientid.length != duid.length || + memcmp(&iface->config.dhcpv6.clientid.duid, &duid.duid, + iface->config.dhcpv6.clientid.length) != 0) { + NET_ERR("Client ID mismatch"); + return -EBADMSG; + } + + /* Verify server ID is present. */ + memset(&duid, 0, sizeof(duid)); + ret = dhcpv6_find_serverid(pkt, &duid); + if (ret < 0) { + NET_ERR("Server ID missing"); + return ret; + } + + /* Verify TID. */ + if (memcmp(iface->config.dhcpv6.tid, tid, + sizeof(iface->config.dhcpv6.tid)) != 0) { + NET_INFO("TID mismatch"); + return -EBADMSG; + } + + /* Verify status code. */ + ret = dhcpv6_find_status_code(pkt, &status); + if (ret < 0) { + return ret; + } + + if (status != DHCPV6_STATUS_SUCCESS) { + /* Ignore. */ + return 0; + } + + /* TODO Process SOL_MAX_RT/INF_MAX_RT options. */ + + /* Verify server preference. */ + ret = dhcpv6_find_server_preference(pkt, &server_preference); + if (ret < 0) { + return ret; + } + + if ((int16_t)server_preference < iface->config.dhcpv6.server_preference) { + /* Ignore. */ + return 0; + } + + /* Find/verify address. */ + if (iface->config.dhcpv6.params.request_addr) { + ret = dhcpv6_find_ia_na(pkt, &ia_na); + if (ret < 0) { + NET_ERR("Address missing"); + return ret; + } + + if (ia_na.status != DHCPV6_STATUS_SUCCESS || + ia_na.iaaddr.status != DHCPV6_STATUS_SUCCESS) { + /* Ignore. */ + return 0; + } + } + + /* Find/verify prefix. */ + if (iface->config.dhcpv6.params.request_prefix) { + ret = dhcpv6_find_ia_pd(pkt, &ia_pd); + if (ret < 0) { + NET_ERR("Prefix missing"); + return ret; + } + + if (ia_pd.status != DHCPV6_STATUS_SUCCESS || + ia_pd.iaprefix.status != DHCPV6_STATUS_SUCCESS) { + /* Ignore. */ + return 0; + } + } + + /* Valid advertisement received, store received offer. */ + memcpy(&iface->config.dhcpv6.serverid, &duid, + sizeof(iface->config.dhcpv6.serverid)); + iface->config.dhcpv6.server_preference = server_preference; + + /* DHCPv6 RFC8415, ch. 18.2.1, if client received Advertise + * message with maximum preference, or after the first + * retransmission period, it should proceed with the exchange, + * w/o further wait. + */ + if (server_preference == DHCPV6_MAX_SERVER_PREFERENCE || + iface->config.dhcpv6.retransmissions > 0) { + /* Reschedule immediately */ + dhcpv6_enter_state(iface, NET_DHCPV6_REQUESTING); + dhcpv6_reschedule(); + } + + return 0; +} + +static int dhcpv6_handle_reply(struct net_if *iface, struct net_pkt *pkt, + uint8_t *tid) +{ + struct net_dhcpv6_duid_storage duid = { 0 }; + struct dhcpv6_ia_pd ia_pd = { 0 }; + struct dhcpv6_ia_na ia_na = { 0 }; + int64_t now = k_uptime_get(); + uint16_t status = 0; + bool rediscover = false; + int ret; + + if (iface->config.dhcpv6.state != NET_DHCPV6_REQUESTING && + iface->config.dhcpv6.state != NET_DHCPV6_CONFIRMING && + iface->config.dhcpv6.state != NET_DHCPV6_RENEWING && + iface->config.dhcpv6.state != NET_DHCPV6_REBINDING) { + return -EINVAL; + } + + /* Verify client ID. */ + ret = dhcpv6_find_clientid(pkt, &duid); + if (ret < 0) { + NET_ERR("Client ID missing"); + return ret; + } + + if (iface->config.dhcpv6.clientid.length != duid.length || + memcmp(&iface->config.dhcpv6.clientid.duid, &duid.duid, + iface->config.dhcpv6.clientid.length) != 0) { + NET_ERR("Client ID mismatch"); + return -EBADMSG; + } + + /* Verify server ID is present. */ + memset(&duid, 0, sizeof(duid)); + ret = dhcpv6_find_serverid(pkt, &duid); + if (ret < 0) { + NET_ERR("Server ID missing"); + return ret; + } + + /* Verify TID. */ + if (memcmp(iface->config.dhcpv6.tid, tid, + sizeof(iface->config.dhcpv6.tid)) != 0) { + NET_INFO("TID mismatch"); + return -EBADMSG; + } + + /* TODO Process SOL_MAX_RT/INF_MAX_RT options. */ + + /* Verify status code. */ + ret = dhcpv6_find_status_code(pkt, &status); + if (ret < 0) { + return ret; + } + + if (status == DHCPV6_STATUS_UNSPEC_FAIL) { + /* Ignore and try again later. */ + return 0; + } + + /* DHCPv6 RFC8415, ch. 18.2.10.1. If the client receives a NotOnLink + * status from the server in response to (...) Request, the client can + * either reissue the message without specifying any addresses or + * restart the DHCP server discovery process. + * + * Restart discovery for our case. + */ + if (iface->config.dhcpv6.state == NET_DHCPV6_REQUESTING && + status == DHCPV6_STATUS_NOT_ON_LINK) { + rediscover = true; + goto out; + } + + /* In case of Confirm Reply, status success indicates the client can + * still use the address. + */ + if (iface->config.dhcpv6.state == NET_DHCPV6_CONFIRMING) { + if (status != DHCPV6_STATUS_SUCCESS) { + rediscover = true; + } + + goto out; + } + + /* Find/verify address. */ + if (iface->config.dhcpv6.params.request_addr) { + ret = dhcpv6_find_ia_na(pkt, &ia_na); + if (ret < 0) { + NET_ERR("Address missing"); + return ret; + } + + if (iface->config.dhcpv6.addr_iaid != ia_na.iaid) { + return -EBADMSG; + } + } + + /* Find/verify prefix. */ + if (iface->config.dhcpv6.params.request_prefix) { + ret = dhcpv6_find_ia_pd(pkt, &ia_pd); + if (ret < 0) { + NET_ERR("Prefix missing"); + return ret; + } + + if (iface->config.dhcpv6.prefix_iaid != ia_pd.iaid) { + return -EBADMSG; + } + } + + /* Valid response received, store received data. */ + iface->config.dhcpv6.t1 = UINT64_MAX; + iface->config.dhcpv6.t2 = UINT64_MAX; + iface->config.dhcpv6.expire = now; + + if (iface->config.dhcpv6.params.request_addr) { + struct net_if_addr *ifaddr; + + if (ia_na.status == DHCPV6_STATUS_NO_ADDR_AVAIL || + ia_na.iaaddr.status == DHCPV6_STATUS_NO_ADDR_AVAIL || + ia_na.iaaddr.valid_lifetime == 0) { + /* Remove old lease. */ + net_if_ipv6_addr_rm(iface, &iface->config.dhcpv6.addr); + memset(&iface->config.dhcpv6.addr, 0, sizeof(struct in6_addr)); + rediscover = true; + goto prefix; + } + + /* TODO On nobiding (renew/rebind) go to requesting */ + + if (!net_ipv6_addr_cmp(&iface->config.dhcpv6.addr, + net_ipv6_unspecified_address()) && + !net_ipv6_addr_cmp(&iface->config.dhcpv6.addr, + &ia_na.iaaddr.addr)) { + /* Remove old lease. */ + net_if_ipv6_addr_rm(iface, &iface->config.dhcpv6.addr); + } + + memcpy(&iface->config.dhcpv6.addr, &ia_na.iaaddr.addr, + sizeof(iface->config.dhcpv6.addr)); + + dhcvp6_update_deadlines(iface, now, ia_na.t1, ia_na.t2, + ia_na.iaaddr.preferred_lifetime, + ia_na.iaaddr.valid_lifetime); + + ifaddr = net_if_ipv6_addr_lookup_by_iface(iface, &ia_na.iaaddr.addr); + if (ifaddr != NULL) { + net_if_ipv6_addr_update_lifetime( + ifaddr, ia_na.iaaddr.valid_lifetime); + } else if (net_if_ipv6_addr_add(iface, &ia_na.iaaddr.addr, NET_ADDR_DHCP, + ia_na.iaaddr.valid_lifetime) == NULL) { + NET_ERR("Failed to configure DHCPv6 address"); + net_dhcpv6_stop(iface); + return -EFAULT; + } + } + +prefix: + if (iface->config.dhcpv6.params.request_prefix) { + struct net_if_ipv6_prefix *ifprefix; + + if (ia_pd.status == DHCPV6_STATUS_NO_PREFIX_AVAIL || + ia_pd.iaprefix.status == DHCPV6_STATUS_NO_PREFIX_AVAIL || + ia_pd.iaprefix.valid_lifetime == 0) { + /* Remove old lease. */ + net_if_ipv6_prefix_rm(iface, &iface->config.dhcpv6.prefix, + iface->config.dhcpv6.prefix_len); + memset(&iface->config.dhcpv6.prefix, 0, sizeof(struct in6_addr)); + iface->config.dhcpv6.prefix_len = 0; + rediscover = true; + goto out; + } + + if (!net_ipv6_addr_cmp(&iface->config.dhcpv6.prefix, + net_ipv6_unspecified_address()) && + (!net_ipv6_addr_cmp(&iface->config.dhcpv6.prefix, + &ia_pd.iaprefix.prefix) || + iface->config.dhcpv6.prefix_len != ia_pd.iaprefix.prefix_len)) { + /* Remove old lease. */ + net_if_ipv6_prefix_rm(iface, &iface->config.dhcpv6.prefix, + iface->config.dhcpv6.prefix_len); + } + + iface->config.dhcpv6.prefix_len = ia_pd.iaprefix.prefix_len; + + memcpy(&iface->config.dhcpv6.prefix, &ia_pd.iaprefix.prefix, + sizeof(iface->config.dhcpv6.prefix)); + + dhcvp6_update_deadlines(iface, now, ia_pd.t1, ia_pd.t2, + ia_pd.iaprefix.preferred_lifetime, + ia_pd.iaprefix.valid_lifetime); + + ifprefix = net_if_ipv6_prefix_lookup(iface, &ia_pd.iaprefix.prefix, + ia_pd.iaprefix.prefix_len); + if (ifprefix != NULL) { + net_if_ipv6_prefix_set_timer(ifprefix, ia_pd.iaprefix.valid_lifetime); + } else if (net_if_ipv6_prefix_add(iface, &ia_pd.iaprefix.prefix, + ia_pd.iaprefix.prefix_len, + ia_pd.iaprefix.valid_lifetime) == NULL) { + NET_ERR("Failed to configure DHCPv6 prefix"); + net_dhcpv6_stop(iface); + return -EFAULT; + } + } + +out: + if (rediscover) { + dhcpv6_enter_state(iface, NET_DHCPV6_SOLICITING); + } else { + dhcpv6_enter_state(iface, NET_DHCPV6_BOUND); + } + + dhcpv6_reschedule(); + + return 0; +} + +static int dhcpv6_handle_reconfigure(struct net_if *iface, struct net_pkt *pkt) +{ + /* Reconfigure not supported yet. */ + return -ENOTSUP; +} + +static enum net_verdict dhcpv6_input(struct net_conn *conn, + struct net_pkt *pkt, + union net_ip_header *ip_hdr, + union net_proto_header *proto_hdr, + void *user_data) +{ + struct net_if *iface; + uint8_t msg_type; + uint8_t tid[DHCPV6_TID_SIZE]; + int ret; + + if (!conn) { + NET_ERR("Invalid connection"); + return NET_DROP; + } + + if (!pkt) { + NET_ERR("Invalid packet"); + return NET_DROP; + } + + iface = net_pkt_iface(pkt); + if (!iface) { + NET_ERR("No interface"); + return NET_DROP; + } + + net_pkt_cursor_init(pkt); + + if (net_pkt_skip(pkt, NET_IPV6UDPH_LEN)) { + NET_ERR("Missing IPv6/UDP header"); + return NET_DROP; + } + + if (net_pkt_read_u8(pkt, &msg_type) < 0) { + NET_ERR("Missing message type"); + return NET_DROP; + } + + if (net_pkt_read(pkt, tid, sizeof(tid)) < 0) { + NET_ERR("Missing transaction ID"); + return NET_DROP; + } + + NET_DBG("Received DHCPv6 packet [type=%d, tid=0x%02x%02x%02x]", + msg_type, tid[0], tid[1], tid[2]); + + switch (msg_type) { + case DHCPV6_MSG_TYPE_ADVERTISE: + ret = dhcpv6_handle_advertise(iface, pkt, tid); + break; + case DHCPV6_MSG_TYPE_REPLY: + ret = dhcpv6_handle_reply(iface, pkt, tid); + break; + case DHCPV6_MSG_TYPE_RECONFIGURE: + ret = dhcpv6_handle_reconfigure(iface, pkt); + break; + case DHCPV6_MSG_TYPE_SOLICIT: + case DHCPV6_MSG_TYPE_REQUEST: + case DHCPV6_MSG_TYPE_CONFIRM: + case DHCPV6_MSG_TYPE_RENEW: + case DHCPV6_MSG_TYPE_REBIND: + case DHCPV6_MSG_TYPE_RELEASE: + case DHCPV6_MSG_TYPE_DECLINE: + case DHCPV6_MSG_TYPE_INFORMATION_REQUEST: + case DHCPV6_MSG_TYPE_RELAY_FORW: + case DHCPV6_MSG_TYPE_RELAY_REPL: + default: + goto drop; + } + + if (ret < 0) { + goto drop; + } + + net_pkt_unref(pkt); + + return NET_OK; + +drop: + return NET_DROP; +} + +/* DHCPv6 timer management */ + +static uint64_t dhcpv6_timeleft(struct net_if *iface, int64_t now) +{ + uint64_t timeout = iface->config.dhcpv6.timeout; + + if (timeout > now) { + return timeout - now; + } + + return 0; +} + +static uint64_t dhcpv6_manage_timers(struct net_if *iface, int64_t now) +{ + uint64_t timeleft = dhcpv6_timeleft(iface, now); + + NET_DBG("iface %p state=%s timeleft=%llu", iface, + net_dhcpv6_state_name(iface->config.dhcpv6.state), timeleft); + + if (timeleft != 0U) { + return iface->config.dhcpv6.timeout; + } + + if (!net_if_is_up(iface)) { + /* An interface is down, the registered event handler will + * restart DHCP procedure when the interface is back up. + */ + return UINT64_MAX; + } + + switch (iface->config.dhcpv6.state) { + case NET_DHCPV6_DISABLED: + break; + case NET_DHCPV6_INIT: { + bool have_addr = false; + bool have_prefix = false; + + if (iface->config.dhcpv6.params.request_addr && + !net_ipv6_addr_cmp(&iface->config.dhcpv6.addr, + net_ipv6_unspecified_address())) { + have_addr = true; + } + + if (iface->config.dhcpv6.params.request_prefix && + !net_ipv6_addr_cmp(&iface->config.dhcpv6.prefix, + net_ipv6_unspecified_address())) { + have_prefix = true; + } + + if ((have_addr || have_prefix) && now < iface->config.dhcpv6.expire) { + /* Try to confirm the address/prefix. In case + * prefix is requested, Rebind is used with + * Confirm timings. + */ + iface->config.dhcpv6.expire = now + DHCPV6_CNF_MAX_RD; + + if (!iface->config.dhcpv6.params.request_prefix) { + dhcpv6_enter_state(iface, NET_DHCPV6_CONFIRMING); + } else { + dhcpv6_enter_state(iface, NET_DHCPV6_REBINDING); + } + } else { + dhcpv6_enter_state(iface, NET_DHCPV6_SOLICITING); + } + + return iface->config.dhcpv6.timeout; + } + case NET_DHCPV6_SOLICITING: + if (iface->config.dhcpv6.server_preference >= 0) { + dhcpv6_enter_state(iface, NET_DHCPV6_REQUESTING); + return iface->config.dhcpv6.timeout; + } + + iface->config.dhcpv6.retransmissions++; + iface->config.dhcpv6.retransmit_timeout = + dhcpv6_next_retransmit_time( + iface->config.dhcpv6.retransmit_timeout, + DHCPV6_SOL_MAX_RT); + + (void)dhcpv6_send_solicit(iface); + dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); + + return iface->config.dhcpv6.timeout; + case NET_DHCPV6_REQUESTING: + if (iface->config.dhcpv6.retransmissions >= DHCPV6_REQ_MAX_RC) { + /* Back to soliciting. */ + dhcpv6_enter_state(iface, NET_DHCPV6_SOLICITING); + return iface->config.dhcpv6.timeout; + } + + iface->config.dhcpv6.retransmissions++; + iface->config.dhcpv6.retransmit_timeout = + dhcpv6_next_retransmit_time( + iface->config.dhcpv6.retransmit_timeout, + DHCPV6_REQ_MAX_RT); + + (void)dhcpv6_send_request(iface); + dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); + + return iface->config.dhcpv6.timeout; + case NET_DHCPV6_CONFIRMING: + if (now >= iface->config.dhcpv6.expire) { + dhcpv6_enter_state(iface, NET_DHCPV6_SOLICITING); + return iface->config.dhcpv6.timeout; + } + + iface->config.dhcpv6.retransmissions++; + iface->config.dhcpv6.retransmit_timeout = + dhcpv6_next_retransmit_time( + iface->config.dhcpv6.retransmit_timeout, + DHCPV6_CNF_MAX_RT); + + (void)dhcpv6_send_confirm(iface); + dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); + + if (iface->config.dhcpv6.timeout > iface->config.dhcpv6.expire) { + iface->config.dhcpv6.timeout = iface->config.dhcpv6.expire; + } + + return iface->config.dhcpv6.timeout; + case NET_DHCPV6_RENEWING: + if (now >= iface->config.dhcpv6.t2) { + dhcpv6_enter_state(iface, NET_DHCPV6_REBINDING); + return iface->config.dhcpv6.timeout; + } + + iface->config.dhcpv6.retransmissions++; + iface->config.dhcpv6.retransmit_timeout = + dhcpv6_next_retransmit_time( + iface->config.dhcpv6.retransmit_timeout, + DHCPV6_REN_MAX_RT); + + (void)dhcpv6_send_renew(iface); + dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); + + if (iface->config.dhcpv6.timeout > iface->config.dhcpv6.t2) { + iface->config.dhcpv6.timeout = iface->config.dhcpv6.t2; + } + + return iface->config.dhcpv6.timeout; + case NET_DHCPV6_REBINDING: + if (now >= iface->config.dhcpv6.expire) { + dhcpv6_enter_state(iface, NET_DHCPV6_SOLICITING); + return iface->config.dhcpv6.timeout; + } + + iface->config.dhcpv6.retransmissions++; + iface->config.dhcpv6.retransmit_timeout = + dhcpv6_next_retransmit_time( + iface->config.dhcpv6.retransmit_timeout, + DHCPV6_REB_MAX_RT); + + (void)dhcpv6_send_rebind(iface); + dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); + + if (iface->config.dhcpv6.timeout > iface->config.dhcpv6.expire) { + iface->config.dhcpv6.timeout = iface->config.dhcpv6.expire; + } + + return iface->config.dhcpv6.timeout; + case NET_DHCPV6_INFO_REQUESTING: + break; + case NET_DHCPV6_BOUND: + dhcpv6_enter_state(iface, NET_DHCPV6_RENEWING); + return iface->config.dhcpv6.timeout; + } + + return UINT64_MAX; +} + +static void dhcpv6_timeout(struct k_work *work) +{ + uint64_t timeout_update = UINT64_MAX; + int64_t now = k_uptime_get(); + struct net_if_dhcpv6 *current, *next; + + ARG_UNUSED(work); + + k_mutex_lock(&lock, K_FOREVER); + + SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&dhcpv6_ifaces, current, next, node) { + struct net_if *iface = CONTAINER_OF( + CONTAINER_OF(current, struct net_if_config, dhcpv6), + struct net_if, config); + uint64_t next_timeout; + + next_timeout = dhcpv6_manage_timers(iface, now); + if (next_timeout < timeout_update) { + timeout_update = next_timeout; + } + } + + k_mutex_unlock(&lock); + + if (timeout_update != UINT64_MAX) { + if (now > timeout_update) { + timeout_update = 0ULL; + } else { + timeout_update -= now; + } + + NET_DBG("Waiting for %llums", timeout_update); + k_work_reschedule(&dhcpv6_timeout_work, K_MSEC(timeout_update)); + } +} + +static void dhcpv6_iface_event_handler(struct net_mgmt_event_callback *cb, + uint32_t mgmt_event, struct net_if *iface) +{ + sys_snode_t *node = NULL; + + k_mutex_lock(&lock, K_FOREVER); + + SYS_SLIST_FOR_EACH_NODE(&dhcpv6_ifaces, node) { + if (node == &iface->config.dhcpv6.node) { + break; + } + } + + if (node == NULL) { + goto out; + } + + if (mgmt_event == NET_EVENT_IF_DOWN) { + NET_DBG("Interface %p going down", iface); + dhcpv6_set_timeout(iface, UINT64_MAX); + } else if (mgmt_event == NET_EVENT_IF_UP) { + NET_DBG("Interface %p coming up", iface); + dhcpv6_enter_state(iface, NET_DHCPV6_INIT); + } + + dhcpv6_reschedule(); + +out: + k_mutex_unlock(&lock); +} + +static void dhcpv6_generate_client_duid(struct net_if *iface) +{ + struct net_linkaddr *lladdr = net_if_get_link_addr(iface); + struct net_dhcpv6_duid_storage *clientid = &iface->config.dhcpv6.clientid; + struct dhcpv6_duid_ll *duid_ll = + (struct dhcpv6_duid_ll *)&clientid->duid.buf; + + memset(clientid, 0, sizeof(*clientid)); + + UNALIGNED_PUT(htons(DHCPV6_DUID_TYPE_LL), &clientid->duid.type); + UNALIGNED_PUT(htons(DHCPV6_HARDWARE_ETHERNET_TYPE), &duid_ll->hw_type); + memcpy(duid_ll->ll_addr, lladdr->addr, lladdr->len); + + clientid->length = DHCPV6_DUID_LL_HEADER_SIZE + lladdr->len; +} + +/* DHCPv6 public API */ + +void net_dhcpv6_start(struct net_if *iface, struct net_dhcpv6_params *params) +{ + k_mutex_lock(&lock, K_FOREVER); + + if (iface->config.dhcpv6.state != NET_DHCPV6_DISABLED) { + NET_ERR("DHCPv6 already running on iface %p, state %s", iface, + net_dhcpv6_state_name(iface->config.dhcpv6.state)); + goto out; + } + + if (!params->request_addr && !params->request_addr) { + NET_ERR("Information Request not supported yet"); + goto out; + } + + NET_DBG("Starting DHCPv6 on iface %p", iface); + + iface->config.dhcpv6.params = *params; + + if (sys_slist_is_empty(&dhcpv6_ifaces)) { + net_mgmt_add_event_callback(&dhcpv6_mgmt_cb); + } + + sys_slist_append(&dhcpv6_ifaces, &iface->config.dhcpv6.node); + + if (params->request_addr) { + iface->config.dhcpv6.addr_iaid = net_if_get_by_iface(iface); + } + + if (params->request_prefix) { + iface->config.dhcpv6.prefix_iaid = net_if_get_by_iface(iface); + } + + dhcpv6_generate_client_duid(iface); + dhcpv6_enter_state(iface, NET_DHCPV6_INIT); + dhcpv6_reschedule(); + +out: + k_mutex_unlock(&lock); +} + +void net_dhcpv6_stop(struct net_if *iface) +{ + k_mutex_lock(&lock, K_FOREVER); + + switch (iface->config.dhcpv6.state) { + case NET_DHCPV6_DISABLED: + NET_INFO("DHCPv6 already disabled on iface %p", iface); + break; + + case NET_DHCPV6_INIT: + case NET_DHCPV6_SOLICITING: + case NET_DHCPV6_REQUESTING: + case NET_DHCPV6_CONFIRMING: + case NET_DHCPV6_RENEWING: + case NET_DHCPV6_REBINDING: + case NET_DHCPV6_INFO_REQUESTING: + case NET_DHCPV6_BOUND: + NET_DBG("Stopping DHCPv6 on iface %p, state %s", iface, + net_dhcpv6_state_name(iface->config.dhcpv6.state)); + + (void)dhcpv6_enter_state(iface, NET_DHCPV6_DISABLED); + + sys_slist_find_and_remove(&dhcpv6_ifaces, + &iface->config.dhcpv6.node); + + if (sys_slist_is_empty(&dhcpv6_ifaces)) { + (void)k_work_cancel_delayable(&dhcpv6_timeout_work); + net_mgmt_del_event_callback(&dhcpv6_mgmt_cb); + } + + break; + } + + k_mutex_unlock(&lock); +} + +void net_dhcpv6_restart(struct net_if *iface) +{ + struct net_dhcpv6_params params = iface->config.dhcpv6.params; + + net_dhcpv6_stop(iface); + net_dhcpv6_start(iface, ¶ms); +} + +int net_dhcpv6_init(void) +{ + struct sockaddr unspec_addr; + int ret; + + net_ipaddr_copy(&net_sin6(&unspec_addr)->sin6_addr, + net_ipv6_unspecified_address()); + unspec_addr.sa_family = AF_INET6; + + ret = net_udp_register(AF_INET6, NULL, &unspec_addr, + DHCPV6_SERVER_PORT, DHCPV6_CLIENT_PORT, + NULL, dhcpv6_input, NULL, NULL); + if (ret < 0) { + NET_DBG("UDP callback registration failed"); + return ret; + } + + k_work_init_delayable(&dhcpv6_timeout_work, dhcpv6_timeout); + net_mgmt_init_event_callback(&dhcpv6_mgmt_cb, dhcpv6_iface_event_handler, + NET_EVENT_IF_DOWN | NET_EVENT_IF_UP); + + return 0; +} diff --git a/subsys/net/ip/dhcpv6_internal.h b/subsys/net/ip/dhcpv6_internal.h new file mode 100644 index 00000000000..5ec129e601f --- /dev/null +++ b/subsys/net/ip/dhcpv6_internal.h @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** @file + * @brief DHCPv6 internal header + * + * This header should not be included by the application. + */ + +#ifndef DHCPV6_INTERNAL_H_ +#define DHCPV6_INTERNAL_H_ + +#include + +#define DHCPV6_DUID_TYPE_SIZE 2 +#define DHVPV6_DUID_LL_HW_TYPE_SIZE 2 +#define DHCPV6_DUID_LL_HEADER_SIZE (DHCPV6_DUID_TYPE_SIZE + \ + DHVPV6_DUID_LL_HW_TYPE_SIZE) + +#define DHCPV6_MSG_TYPE_SIZE 1 +#define DHCPV6_HEADER_SIZE (DHCPV6_MSG_TYPE_SIZE + DHCPV6_TID_SIZE) + +#define DHCPV6_OPTION_CODE_SIZE 2 +#define DHCPV6_OPTION_LENGTH_SIZE 2 +#define DHCPV6_OPTION_HEADER_SIZE (DHCPV6_OPTION_CODE_SIZE + \ + DHCPV6_OPTION_LENGTH_SIZE) + +#define DHCPV6_OPTION_PREFERENCE_SIZE 1 +#define DHCPV6_OPTION_ELAPSED_TIME_SIZE 2 +#define DHCPV6_OPTION_ELAPSED_TIME_SIZE 2 +#define DHCPV6_OPTION_IA_NA_HEADER_SIZE 12 +#define DHCPV6_OPTION_IAADDR_HEADER_SIZE 24 +#define DHCPV6_OPTION_IA_PD_HEADER_SIZE 12 +#define DHCPV6_OPTION_IAPREFIX_HEADER_SIZE 25 +#define DHCPV6_OPTION_IAADDR_HEADER_SIZE 24 +#define DHCPV6_OPTION_IAPREFIX_HEADER_SIZE 25 +#define DHCPV6_OPTION_STATUS_CODE_HEADER_SIZE 2 + +#define DHCPV6_INFINITY UINT32_MAX +#define DHCPV6_MAX_SERVER_PREFERENCE 255 + +#define DHCPV6_HARDWARE_ETHERNET_TYPE 1 + +#define DHCPV6_CLIENT_PORT 546 +#define DHCPV6_SERVER_PORT 547 + +/* DHCPv6 Transmission/retransmission timeouts */ +#define DHCPV6_SOL_MAX_DELAY 1000 /* Max delay of first Solicit, milliseconds */ +#define DHCPV6_SOL_TIMEOUT 1000 /* Initial Solicit timeout, milliseconds */ +#define DHCPV6_SOL_MAX_RT 3600000 /* Max Solicit timeout value, milliseconds */ +#define DHCPV6_REQ_TIMEOUT 1000 /* Initial Request timeout, milliseconds */ +#define DHCPV6_REQ_MAX_RT 30000 /* Max Request timeout value, milliseconds */ +#define DHCPV6_REQ_MAX_RC 10 /* Max Request retry attempts */ +#define DHCPV6_CNF_MAX_DELAY 1000 /* Max delay of first Confirm, milliseconds */ +#define DHCPV6_CNF_TIMEOUT 1000 /* Initial Confirm timeout, milliseconds */ +#define DHCPV6_CNF_MAX_RT 4000 /* Max Confirm timeout, milliseconds */ +#define DHCPV6_CNF_MAX_RD 10000 /* Max Confirm duration, milliseconds */ +#define DHCPV6_REN_TIMEOUT 10000 /* Initial Renew timeout, milliseconds */ +#define DHCPV6_REN_MAX_RT 600000 /* Max Renew timeout value, milliseconds */ +#define DHCPV6_REB_TIMEOUT 10000 /* Initial Rebind timeout, milliseconds */ +#define DHCPV6_REB_MAX_RT 600000 /* Max Rebind timeout value, milliseconds */ + +/* DUID structures */ +struct dhcpv6_duid_llt { + uint16_t hw_type; + uint32_t time; + uint8_t ll_addr[]; +} __packed; + +struct dhcpv6_duid_en { + uint32_t enterprise_number; + uint8_t identifier[]; +} __packed; + +struct dhcpv6_duid_ll { + uint16_t hw_type; + uint8_t ll_addr[]; +} __packed; + +struct dhcpv6_duid_uuid { + uint8_t uuid[16]; +} __packed; + +struct dhcpv6_msg_hdr { + uint8_t type; /* Message type */ + uint8_t tid[3]; /* Transaction ID */ +} __packed; + +struct dhcpv6_iaaddr { + uint32_t preferred_lifetime; + uint32_t valid_lifetime; + struct in6_addr addr; + uint16_t status; +}; + +struct dhcpv6_ia_na { + uint32_t iaid; + uint32_t t1; + uint32_t t2; + uint16_t status; + struct dhcpv6_iaaddr iaaddr; +}; + +struct dhcpv6_iaprefix { + uint32_t preferred_lifetime; + uint32_t valid_lifetime; + struct in6_addr prefix; + uint8_t prefix_len; + uint16_t status; +}; + +struct dhcpv6_ia_pd { + uint32_t iaid; + uint32_t t1; + uint32_t t2; + uint16_t status; + struct dhcpv6_iaprefix iaprefix; +}; + +/* DHCPv6 message types, RFC8415, ch. 7.3. */ +enum dhcpv6_msg_type { + DHCPV6_MSG_TYPE_SOLICIT = 1, + DHCPV6_MSG_TYPE_ADVERTISE = 2, + DHCPV6_MSG_TYPE_REQUEST = 3, + DHCPV6_MSG_TYPE_CONFIRM = 4, + DHCPV6_MSG_TYPE_RENEW = 5, + DHCPV6_MSG_TYPE_REBIND = 6, + DHCPV6_MSG_TYPE_REPLY = 7, + DHCPV6_MSG_TYPE_RELEASE = 8, + DHCPV6_MSG_TYPE_DECLINE = 9, + DHCPV6_MSG_TYPE_RECONFIGURE = 10, + DHCPV6_MSG_TYPE_INFORMATION_REQUEST = 11, + DHCPV6_MSG_TYPE_RELAY_FORW = 12, + DHCPV6_MSG_TYPE_RELAY_REPL = 13, +}; + +/* DHCPv6 option codes, RFC8415, ch. 21. */ +enum dhcpv6_option_code { + DHCPV6_OPTION_CODE_CLIENTID = 1, + DHCPV6_OPTION_CODE_SERVERID = 2, + DHCPV6_OPTION_CODE_IA_NA = 3, + DHCPV6_OPTION_CODE_IA_TA = 4, + DHCPV6_OPTION_CODE_IAADDR = 5, + DHCPV6_OPTION_CODE_ORO = 6, + DHCPV6_OPTION_CODE_PREFERENCE = 7, + DHCPV6_OPTION_CODE_ELAPSED_TIME = 8, + DHCPV6_OPTION_CODE_RELAY_MSG = 9, + DHCPV6_OPTION_CODE_AUTH = 11, + DHCPV6_OPTION_CODE_UNICAST = 12, + DHCPV6_OPTION_CODE_STATUS_CODE = 13, + DHCPV6_OPTION_CODE_RAPID_COMMIT = 14, + DHCPV6_OPTION_CODE_USER_CLASS = 15, + DHCPV6_OPTION_CODE_VENDOR_CLASS = 16, + DHCPV6_OPTION_CODE_VENDOR_OPTS = 17, + DHCPV6_OPTION_CODE_INTERFACE_ID = 18, + DHCPV6_OPTION_CODE_RECONF_MSG = 19, + DHCPV6_OPTION_CODE_RECONF_ACCEPT = 20, + DHCPV6_OPTION_CODE_IA_PD = 25, + DHCPV6_OPTION_CODE_IAPREFIX = 26, + DHCPV6_OPTION_CODE_INFORMATION_REFRESH_TIME = 32, + DHCPV6_OPTION_CODE_SOL_MAX_RT = 82, + DHCPV6_OPTION_CODE_INF_MAX_RT = 83, +}; + +/* DHCPv6 option codes, RFC8415, ch. 21.13. */ +enum dhcpv6_status_code { + DHCPV6_STATUS_SUCCESS = 0, + DHCPV6_STATUS_UNSPEC_FAIL = 1, + DHCPV6_STATUS_NO_ADDR_AVAIL = 2, + DHCPV6_STATUS_NO_BINDING = 3, + DHCPV6_STATUS_NOT_ON_LINK = 4, + DHCPV6_STATUS_USE_MULTICAST = 5, + DHCPV6_STATUS_NO_PREFIX_AVAIL = 6, +}; + +/* DHCPv6 Unique Identifier types, RFC8415, ch. 11.1. */ +enum dhcpv6_duid_type { + DHCPV6_DUID_TYPE_LLT = 1, /* Based on Link-Layer Address Plus Time */ + DHCPV6_DUID_TYPE_EN = 2, /* Assigned by Vendor Based on Enterprise Number */ + DHCPV6_DUID_TYPE_LL = 3, /* Based on Link-Layer Address */ + DHCPV6_DUID_TYPE_UUID = 4, /* Based on Universally Unique Identifier */ +}; + +#if defined(CONFIG_NET_DHCPV6) +int net_dhcpv6_init(void); +#else +static inline int net_dhcpv6_init(void) +{ + return 0; +} +#endif /* CONFIG_NET_DHCPV6 */ + +#endif /* DHCPV6_INTERNAL_H_ */ diff --git a/subsys/net/ip/net_core.c b/subsys/net/ip/net_core.c index 00829dfcf90..c94607b4485 100644 --- a/subsys/net/ip/net_core.c +++ b/subsys/net/ip/net_core.c @@ -45,6 +45,7 @@ LOG_MODULE_REGISTER(net_core, CONFIG_NET_CORE_LOG_LEVEL); #include "ipv4.h" #include "dhcpv4.h" +#include "dhcpv6_internal.h" #include "route.h" @@ -475,6 +476,11 @@ static inline int services_init(void) return status; } + status = net_dhcpv6_init(); + if (status != 0) { + return status; + } + dns_init_resolver(); websocket_init(); From 542166fc77cf4c9d8eb90bdfcb27984b17668017 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 23 Aug 2023 13:41:25 +0200 Subject: [PATCH 0133/1623] [nrf fromtree] net: dhcpv6: Introduce net events for DHCPv6 Add net events for DHCPv6, in similar fashion as it's done for DHCPv4. Signed-off-by: Robert Lubos (cherry picked from commit afa5887b700db5d6aef773ea07e5ceb1bde4c9c1) (cherry picked from commit 324c985e0384c5e8ec07082e396cdee6c54f3131) --- include/zephyr/net/net_event.h | 12 ++++++++++++ subsys/net/ip/dhcpv6.c | 8 ++++++++ subsys/net/ip/net_private.h | 3 +++ 3 files changed, 23 insertions(+) diff --git a/include/zephyr/net/net_event.h b/include/zephyr/net/net_event.h index 819a5ae6639..34856aec6af 100644 --- a/include/zephyr/net/net_event.h +++ b/include/zephyr/net/net_event.h @@ -79,6 +79,9 @@ enum net_event_ipv6_cmd { NET_EVENT_IPV6_CMD_DAD_FAILED, NET_EVENT_IPV6_CMD_NBR_ADD, NET_EVENT_IPV6_CMD_NBR_DEL, + NET_EVENT_IPV6_CMD_DHCP_START, + NET_EVENT_IPV6_CMD_DHCP_BOUND, + NET_EVENT_IPV6_CMD_DHCP_STOP, }; #define NET_EVENT_IPV6_ADDR_ADD \ @@ -129,6 +132,15 @@ enum net_event_ipv6_cmd { #define NET_EVENT_IPV6_NBR_DEL \ (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_NBR_DEL) +#define NET_EVENT_IPV6_DHCP_START \ + (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV6_CMD_DHCP_START) + +#define NET_EVENT_IPV6_DHCP_BOUND \ + (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV6_CMD_DHCP_BOUND) + +#define NET_EVENT_IPV6_DHCP_STOP \ + (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV6_CMD_DHCP_STOP) + /* IPv4 Events*/ #define _NET_IPV4_LAYER NET_MGMT_LAYER_L3 #define _NET_IPV4_CORE_CODE 0x004 diff --git a/subsys/net/ip/dhcpv6.c b/subsys/net/ip/dhcpv6.c index 040c9fa0e06..6fae4f320bf 100644 --- a/subsys/net/ip/dhcpv6.c +++ b/subsys/net/ip/dhcpv6.c @@ -1374,6 +1374,10 @@ static void dhcpv6_enter_confirming(struct net_if *iface) static void dhcpv6_enter_bound(struct net_if *iface) { iface->config.dhcpv6.timeout = iface->config.dhcpv6.t1; + + net_mgmt_event_notify_with_info(NET_EVENT_IPV6_DHCP_BOUND, iface, + &iface->config.dhcpv6, + sizeof(iface->config.dhcpv6)); } static void dhcpv6_enter_state(struct net_if *iface, enum net_dhcpv6_state state) @@ -2101,6 +2105,8 @@ void net_dhcpv6_start(struct net_if *iface, struct net_dhcpv6_params *params) goto out; } + net_mgmt_event_notify(NET_EVENT_IPV6_DHCP_START, iface); + NET_DBG("Starting DHCPv6 on iface %p", iface); iface->config.dhcpv6.params = *params; @@ -2160,6 +2166,8 @@ void net_dhcpv6_stop(struct net_if *iface) break; } + net_mgmt_event_notify(NET_EVENT_IPV6_DHCP_STOP, iface); + k_mutex_unlock(&lock); } diff --git a/subsys/net/ip/net_private.h b/subsys/net/ip/net_private.h index be0466fc98b..c2b80aa4f05 100644 --- a/subsys/net/ip/net_private.h +++ b/subsys/net/ip/net_private.h @@ -30,6 +30,9 @@ union net_mgmt_events { #if defined(CONFIG_NET_DHCPV4) struct net_if_dhcpv4 dhcpv4; #endif /* CONFIG_NET_DHCPV4 */ +#if defined(CONFIG_NET_DHCPV6) + struct net_if_dhcpv6 dhcpv6; +#endif /* CONFIG_NET_DHCPV6 */ #if defined(CONFIG_NET_L2_WIFI_MGMT) union wifi_mgmt_events wifi; #endif /* CONFIG_NET_L2_WIFI_MGMT */ From 7b858ff1a5bb1cd919249412bdb1c8be3f7424d9 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 23 Aug 2023 13:41:32 +0200 Subject: [PATCH 0134/1623] [nrf fromtree] net: config: Add DHCPv6 support Add DHCPv6 support to the net config library. In case DHCPv6 is enabled, net config will attempt to acquire IPv6 address and/or prefix when used. The user can select with Kconfig whether to request address or prefix (or both). Signed-off-by: Robert Lubos (cherry picked from commit 72cf06ada44992d018cd4675292f6395ad2b0710) (cherry picked from commit 4bfd0dba783f4cd133ccf59b188d0d2d933f7c21) --- subsys/net/lib/config/Kconfig | 17 +++++++++++++ subsys/net/lib/config/init.c | 46 +++++++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/subsys/net/lib/config/Kconfig b/subsys/net/lib/config/Kconfig index 0f1e3c50544..5ca788cebf1 100644 --- a/subsys/net/lib/config/Kconfig +++ b/subsys/net/lib/config/Kconfig @@ -188,6 +188,23 @@ config NET_CONFIG_BT_NODE endif # NET_CONFIG_SETTINGS +if NET_DHCPV6 + +config NET_CONFIG_DHCPV6_REQUEST_ADDR + bool "Request IPv6 address when configuring DHCPv6 client" + default y + help + When DHCPv6 is enabled this will configure the DHCPv6 client to + request IPv6 address from the DHCPv6 server. + +config NET_CONFIG_DHCPV6_REQUEST_PREFIX + bool "Request IPv6 prefix when configuring DHCPv6 client" + help + When DHCPv6 is enabled this will configure the DHCPv6 client to + request IPv6 prefix from the DHCPv6 server. + +endif # NET_DHCPV6 + config NET_CONFIG_CLOCK_SNTP_INIT bool "Initialize system clock using SNTP on application startup" depends on SNTP && POSIX_CLOCK diff --git a/subsys/net/lib/config/init.c b/subsys/net/lib/config/init.c index cd2bf711a7d..098003b79b3 100644 --- a/subsys/net/lib/config/init.c +++ b/subsys/net/lib/config/init.c @@ -21,6 +21,7 @@ LOG_MODULE_REGISTER(net_config, CONFIG_NET_CONFIG_LOG_LEVEL); #include #include #include +#include #include #include @@ -203,8 +204,26 @@ static void setup_ipv4(struct net_if *iface) #endif /* CONFIG_NET_IPV4 && !CONFIG_NET_DHCPV4 */ #if defined(CONFIG_NET_NATIVE_IPV6) -#if !defined(CONFIG_NET_CONFIG_MY_IPV6_ADDR) -#error "You need to define an IPv6 address!" + +#if defined(CONFIG_NET_DHCPV6) +static void setup_dhcpv6(struct net_if *iface) +{ + struct net_dhcpv6_params params = { + .request_addr = IS_ENABLED(CONFIG_NET_CONFIG_DHCPV6_REQUEST_ADDR), + .request_prefix = IS_ENABLED(CONFIG_NET_CONFIG_DHCPV6_REQUEST_PREFIX), + }; + + NET_INFO("Running dhcpv6 client..."); + + net_dhcpv6_start(iface, ¶ms); +} +#else /* CONFIG_NET_DHCPV6 */ +#define setup_dhcpv6(...) +#endif /* CONFIG_NET_DHCPV6 */ + +#if !defined(CONFIG_NET_CONFIG_DHCPV6_REQUEST_ADDR) && \ + !defined(CONFIG_NET_CONFIG_MY_IPV6_ADDR) +#error "You need to define an IPv6 address or enable DHCPv6!" #endif static struct net_mgmt_event_callback mgmt6_cb; @@ -249,6 +268,21 @@ static void ipv6_event_handler(struct net_mgmt_event_callback *cb, #if CONFIG_NET_CONFIG_LOG_LEVEL >= LOG_LEVEL_INF NET_INFO("IPv6 address: %s", net_addr_ntop(AF_INET6, &laddr, hr_addr, NET_IPV6_ADDR_LEN)); + + if (ifaddr->addr_type == NET_ADDR_DHCP) { + char remaining_str[] = "infinite"; + uint32_t remaining; + + remaining = net_timeout_remaining(&ifaddr->lifetime, + k_uptime_get_32()); + + if (!ifaddr->is_infinite) { + snprintk(remaining_str, sizeof(remaining_str), + "%u", remaining); + } + + NET_INFO("Lifetime: %s seconds", remaining_str); + } #endif services_notify_ready(NET_CONFIG_NEED_IPV6); @@ -264,6 +298,9 @@ static void setup_ipv6(struct net_if *iface, uint32_t flags) struct net_if_addr *ifaddr; uint32_t mask = NET_EVENT_IPV6_DAD_SUCCEED; + net_mgmt_init_event_callback(&mgmt6_cb, ipv6_event_handler, mask); + net_mgmt_add_event_callback(&mgmt6_cb); + if (sizeof(CONFIG_NET_CONFIG_MY_IPV6_ADDR) == 1) { /* Empty address, skip setting ANY address in this case */ goto exit; @@ -279,9 +316,6 @@ static void setup_ipv6(struct net_if *iface, uint32_t flags) mask |= NET_EVENT_IPV6_ROUTER_ADD; } - net_mgmt_init_event_callback(&mgmt6_cb, ipv6_event_handler, mask); - net_mgmt_add_event_callback(&mgmt6_cb); - /* * check for CMD_ADDR_ADD bit here, NET_EVENT_IPV6_ADDR_ADD is * a combination of _NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ADDR_ADD @@ -310,6 +344,7 @@ static void setup_ipv6(struct net_if *iface, uint32_t flags) #else #define setup_ipv6(...) +#define setup_dhcpv6(...) #endif /* CONFIG_NET_IPV6 */ #if defined(CONFIG_NET_NATIVE) @@ -400,6 +435,7 @@ int net_config_init_by_iface(struct net_if *iface, const char *app_info, setup_ipv4(iface); setup_dhcpv4(iface); setup_ipv6(iface, flags); + setup_dhcpv6(iface); /* Network interface did not come up. */ if (timeout > 0 && count < 0) { From 0258a9960c452a3e0f69004ed421a8838108ad9c Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 23 Aug 2023 13:43:49 +0200 Subject: [PATCH 0135/1623] [nrf fromtree] net: shell: Add DHCPv6 support Print DHCPv6 status in net shell (with "net iface" command). Signed-off-by: Robert Lubos (cherry picked from commit 6fb19bc7f03cdbae897b09c3718722853a86b8b3) (cherry picked from commit d27251057f2a990a669c32e8069c064ed0852d4a) --- subsys/net/ip/net_shell.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index c5b07afd6aa..e7af6e16632 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -719,6 +719,19 @@ static void iface_cb(struct net_if *iface, void *user_data) iface->config.dhcpv4.attempts); #endif /* CONFIG_NET_DHCPV4 */ +#if defined(CONFIG_NET_DHCPV6) + PR("DHCPv6 address requested : %s\n", + iface->config.dhcpv6.params.request_addr ? + net_sprint_ipv6_addr(&iface->config.dhcpv6.addr) : "none"); + PR("DHCPv6 prefix requested : %s\n", + iface->config.dhcpv6.params.request_prefix ? + net_sprint_ipv6_addr(&iface->config.dhcpv6.prefix) : "none"); + PR("DHCPv6 state : %s\n", + net_dhcpv6_state_name(iface->config.dhcpv6.state)); + PR("DHCPv6 attempts : %d\n", + iface->config.dhcpv6.retransmissions + 1); +#endif /* CONFIG_NET_DHCPV6 */ + #else ARG_UNUSED(iface); ARG_UNUSED(user_data); @@ -2513,6 +2526,29 @@ static char *get_l3_desc(struct event_msg *msg, info = net_addr_ntop(AF_INET6, msg->data, extra_info, extra_info_len); break; + case NET_EVENT_IPV6_DHCP_START: + *desc = "DHCPv6"; + *desc2 = "start"; + break; + case NET_EVENT_IPV6_DHCP_BOUND: + *desc = "DHCPv6"; + *desc2 = "bound"; +#if defined(CONFIG_NET_DHCPV6) + struct net_if_dhcpv6 *data = (struct net_if_dhcpv6 *)msg->data; + + if (data->params.request_addr) { + info = net_addr_ntop(AF_INET6, &data->addr, extra_info, + extra_info_len); + } else if (data->params.request_prefix) { + info = net_addr_ntop(AF_INET6, &data->prefix, extra_info, + extra_info_len); + } +#endif + break; + case NET_EVENT_IPV6_DHCP_STOP: + *desc = "DHCPv6"; + *desc2 = "stop"; + break; case NET_EVENT_IPV4_ADDR_ADD: *desc = "IPv4 address"; *desc2 = "add"; From 3c8028b93d9392629b9b5a123850d1ddea6b66a3 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Mon, 2 Oct 2023 18:22:29 +0300 Subject: [PATCH 0136/1623] [nrf fromtree] net: dhcpv6: Fix params check Fix params check. Signed-off-by: Andrei Emeltchenko (cherry picked from commit d68db1ecfa512bc416bfa906d74f441cba2ab8fb) Signed-off-by: Robert Lubos (cherry picked from commit 972c7c3ca30d782e797c4ed304239b547057f3e6) --- subsys/net/ip/dhcpv6.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/ip/dhcpv6.c b/subsys/net/ip/dhcpv6.c index 6fae4f320bf..fdfef3c5147 100644 --- a/subsys/net/ip/dhcpv6.c +++ b/subsys/net/ip/dhcpv6.c @@ -2100,7 +2100,7 @@ void net_dhcpv6_start(struct net_if *iface, struct net_dhcpv6_params *params) goto out; } - if (!params->request_addr && !params->request_addr) { + if (!params->request_addr && !params->request_prefix) { NET_ERR("Information Request not supported yet"); goto out; } From 577db5cae9568f33fb5a1bb3fc6ab1a4725813f7 Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Tue, 26 Sep 2023 16:37:26 +0200 Subject: [PATCH 0137/1623] [nrf fromtree] Bluetooth: att: don't re-use the ATT buffer for confirmations If the peer is a zephyr host, there is no problem, as the Zephyr host limits sending parallel REQs and INDs. But the spec allows sending those in parallel, and it may end up that the re-used REQ buffer hasn't been destroyed when an indication comes. Only re-use the buffer when enqueuing ATT responses. This means that we may run out of buffers if the peer sends too many indications and our application also sends a lot of commands/notifications. The rationale for this is that having to handle a lot of requests is a more plausible scenario (e.g. being discovered by multiple peers) than handling lots of parallel indications. Signed-off-by: Jonathan Rico (cherry picked from commit 7093538c425b1bd3dd4bce3dfd3708a8281bd033) (cherry picked from commit 168b413c38b2cbee8f20800e7c76db9b31a5a978) --- subsys/bluetooth/host/att.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index d2c41eaa928..f5ae3768cec 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -670,11 +670,13 @@ static struct net_buf *bt_att_chan_create_pdu(struct bt_att_chan *chan, uint8_t switch (att_op_get_type(op)) { case ATT_RESPONSE: - case ATT_CONFIRMATION: - /* Use a timeout only when responding/confirming */ + /* Use a timeout only when responding */ timeout = BT_ATT_TIMEOUT; re_use = true; break; + case ATT_CONFIRMATION: + timeout = BT_ATT_TIMEOUT; + break; default: timeout = K_FOREVER; } @@ -701,7 +703,7 @@ static struct net_buf *bt_att_chan_create_pdu(struct bt_att_chan *chan, uint8_t * This is better than an assert as an assert would * allow a peer to DoS us. */ - LOG_ERR("already processing a transaction on chan %p", chan); + LOG_ERR("already processing a REQ/RSP on chan %p", chan); return NULL; } From 079d1b105a61c46f7a8ffea881de673092a44b65 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Fri, 1 Sep 2023 15:17:52 +0200 Subject: [PATCH 0138/1623] [nrf fromtree] Bluetooth: Mesh: Fix Opcode Aggregator Server compilation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove ifdef around `srcs` and let linker exclude it when Opcode Aggregator Client model is not enabled. Signed-off-by: Pavel Vasilyev (cherry picked from commit 2a472b8b477ce4f46c88978d0970ea6cb65dea15) Signed-off-by: Alperen Şener (cherry picked from commit a3173f0e03058f75f75296e46c4b986af48239d9) --- subsys/bluetooth/mesh/op_agg.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/subsys/bluetooth/mesh/op_agg.c b/subsys/bluetooth/mesh/op_agg.c index 4f6baacc898..1580c7f0847 100644 --- a/subsys/bluetooth/mesh/op_agg.c +++ b/subsys/bluetooth/mesh/op_agg.c @@ -17,10 +17,7 @@ LOG_MODULE_REGISTER(bt_mesh_op_agg); #define LENGTH_SHORT_MAX BIT_MASK(7) NET_BUF_SIMPLE_DEFINE_STATIC(sdu, BT_MESH_TX_SDU_MAX); - -#if IS_ENABLED(CONFIG_BT_MESH_OP_AGG_CLI) NET_BUF_SIMPLE_DEFINE_STATIC(srcs, BT_MESH_TX_SDU_MAX); -#endif static struct op_agg_ctx agg_ctx = { .sdu = &sdu, From 4d987d3dcba621380f6714dd2cfa405dc78ad6fa Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Fri, 1 Sep 2023 15:19:13 +0200 Subject: [PATCH 0139/1623] [nrf fromtree] Bluetooth: Mesh: Fix Solicitation RPL PDU Server compilation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A pointer to the key struct should be passed after the PSA support has been added. Signed-off-by: Pavel Vasilyev (cherry picked from commit d36b7f4de0b2feec55a5fcca30dec608cb7df8ad) Signed-off-by: Alperen Şener (cherry picked from commit c58978510a533613fc12746502af000857bf5ae7) --- subsys/bluetooth/mesh/solicitation.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/solicitation.c b/subsys/bluetooth/mesh/solicitation.c index 3f639fbf0d6..1bf9f9a465a 100644 --- a/subsys/bluetooth/mesh/solicitation.c +++ b/subsys/bluetooth/mesh/solicitation.c @@ -153,12 +153,12 @@ static bool sol_pdu_decrypt(struct bt_mesh_subnet *sub, void *data) net_buf_simple_init(out, 0); net_buf_simple_add_mem(out, in->data, in->len); - err = bt_mesh_net_obfuscate(out->data, 0, sub->keys[i].msg.privacy); + err = bt_mesh_net_obfuscate(out->data, 0, &sub->keys[i].msg.privacy); if (err) { LOG_DBG("obfuscation err %d", err); continue; } - err = bt_mesh_net_decrypt(sub->keys[i].msg.enc, out, + err = bt_mesh_net_decrypt(&sub->keys[i].msg.enc, out, 0, BT_MESH_NONCE_SOLICITATION); if (!err) { LOG_DBG("Decrypted PDU %s", bt_hex(out->data, out->len)); From 915c64c22fc212ef2f5b25e62682179159ce97c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Wed, 6 Sep 2023 10:06:38 +0200 Subject: [PATCH 0140/1623] [nrf fromtree] Bluetooth: Mesh: Send od priv proxy with devkey MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to the mesh 1.1 spec, section 4.4.14.1: “. The access layer security on the On-Demand Private Proxy Client model shall use the device key of the node supporting the On-Demand Private Proxy Server model.“ This commit alters the API and implementation to reflect this. Signed-off-by: Anders Storrø (cherry picked from commit 01a6ecb6bf4cef76bfd042eb5ab351347a1444f6) Signed-off-by: Alperen Şener (cherry picked from commit f51ca3b314489cc47bfef005816a729348b47c72) --- include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h | 11 ++++++----- subsys/bluetooth/mesh/od_priv_proxy_cli.c | 12 +++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h b/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h index 89e63c177a0..f9734d78d3e 100644 --- a/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h +++ b/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h @@ -47,7 +47,6 @@ struct bt_mesh_od_priv_proxy_cli { _bt_mesh_od_priv_proxy_cli_op, NULL, cli_data, \ &_bt_mesh_od_priv_proxy_cli_cb) - /** @brief Get the target's On-Demand Private GATT Proxy state. * * This method can be used asynchronously by setting @p val_rsp as NULL. @@ -57,12 +56,13 @@ struct bt_mesh_od_priv_proxy_cli { * To process the response arguments of an async method, register * the @c od_status callback in @c bt_mesh_od_priv_proxy_cli struct. * - * @param ctx Message context for the message. + * @param net_idx Network index to encrypt with. + * @param addr Target node address. * @param val_rsp Response buffer for On-Demand Private GATT Proxy value. * * @return 0 on success, or (negative) error code otherwise. */ -int bt_mesh_od_priv_proxy_cli_get(struct bt_mesh_msg_ctx *ctx, uint8_t *val_rsp); +int bt_mesh_od_priv_proxy_cli_get(uint16_t net_idx, uint16_t addr, uint8_t *val_rsp); /** @brief Set the target's On-Demand Private GATT Proxy state. * @@ -73,13 +73,14 @@ int bt_mesh_od_priv_proxy_cli_get(struct bt_mesh_msg_ctx *ctx, uint8_t *val_rsp) * To process the response arguments of an async method, register * the @c od_status callback in @c bt_mesh_od_priv_proxy_cli struct. * - * @param ctx Message context for the message. + * @param net_idx Network index to encrypt with. + * @param addr Target node address. * @param val On-Demand Private GATT Proxy state to be set * @param val_rsp Response buffer for On-Demand Private GATT Proxy value. * * @return 0 on success, or (negative) error code otherwise. */ -int bt_mesh_od_priv_proxy_cli_set(struct bt_mesh_msg_ctx *ctx, uint8_t val, uint8_t *val_rsp); +int bt_mesh_od_priv_proxy_cli_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *val_rsp); /** @brief Set the transmission timeout value. * diff --git a/subsys/bluetooth/mesh/od_priv_proxy_cli.c b/subsys/bluetooth/mesh/od_priv_proxy_cli.c index 3dc8722ff72..67f5ac961ad 100644 --- a/subsys/bluetooth/mesh/od_priv_proxy_cli.c +++ b/subsys/bluetooth/mesh/od_priv_proxy_cli.c @@ -54,23 +54,25 @@ const struct bt_mesh_model_op _bt_mesh_od_priv_proxy_cli_op[] = { BT_MESH_MODEL_OP_END }; -int bt_mesh_od_priv_proxy_cli_get(struct bt_mesh_msg_ctx *ctx, uint8_t *val) +int bt_mesh_od_priv_proxy_cli_get(uint16_t net_idx, uint16_t addr, uint8_t *val_rsp) { + struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr); const struct bt_mesh_msg_rsp_ctx rsp = { .ack = &cli->ack_ctx, .op = OP_OD_PRIV_PROXY_STATUS, - .user_data = val, + .user_data = val_rsp, .timeout = msg_timeout, }; BT_MESH_MODEL_BUF_DEFINE(msg, OP_OD_PRIV_PROXY_GET, 0); bt_mesh_model_msg_init(&msg, OP_OD_PRIV_PROXY_GET); - return bt_mesh_msg_ackd_send(cli->model, ctx, &msg, val ? &rsp : NULL); + return bt_mesh_msg_ackd_send(cli->model, &ctx, &msg, val_rsp ? &rsp : NULL); } -int bt_mesh_od_priv_proxy_cli_set(struct bt_mesh_msg_ctx *ctx, uint8_t val, uint8_t *val_rsp) +int bt_mesh_od_priv_proxy_cli_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *val_rsp) { + struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr); const struct bt_mesh_msg_rsp_ctx rsp = { .ack = &cli->ack_ctx, .op = OP_OD_PRIV_PROXY_STATUS, @@ -83,7 +85,7 @@ int bt_mesh_od_priv_proxy_cli_set(struct bt_mesh_msg_ctx *ctx, uint8_t val, uint net_buf_simple_add_u8(&msg, val); - return bt_mesh_msg_ackd_send(cli->model, ctx, &msg, val_rsp ? &rsp : NULL); + return bt_mesh_msg_ackd_send(cli->model, &ctx, &msg, val_rsp ? &rsp : NULL); } void bt_mesh_od_priv_proxy_cli_timeout_set(int32_t timeout) From ced31ee9859ad299cf1a154124adef5bd9d25cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Wed, 30 Aug 2023 14:16:46 +0200 Subject: [PATCH 0141/1623] [nrf fromtree] Bluetooth: Mesh: Support for comp data page 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds support for composition data page 2 & 130. In this implementation the responsibillity for filling the page 2 buffer is left to the application through the new comp page 2 cb API. Only the application can know/decide if the device is NLC compliant, and must thus be given the responsibillity for cheking the NLC profile requirements, defined in the NLC specs, and filling the response buffer for comp data page 2. Signed-off-by: Anders Storrø (cherry picked from commit 9d849736ef6da918fc8685d6fa79a66d69d866e4) Signed-off-by: Alperen Şener (cherry picked from commit cbbfec95d121cd1de482fc7c4055b48639ab7517) --- include/zephyr/bluetooth/mesh/access.h | 45 ++++++++++++++++++ subsys/bluetooth/mesh/Kconfig | 5 ++ subsys/bluetooth/mesh/access.c | 66 +++++++++++++++++++++++++- subsys/bluetooth/mesh/access.h | 1 - subsys/bluetooth/mesh/cfg_srv.c | 8 +++- 5 files changed, 121 insertions(+), 4 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/access.h b/include/zephyr/bluetooth/mesh/access.h index f3b6c373128..5b1653c2487 100644 --- a/include/zephyr/bluetooth/mesh/access.h +++ b/include/zephyr/bluetooth/mesh/access.h @@ -1137,6 +1137,51 @@ struct bt_mesh_comp { struct bt_mesh_elem *elem; /**< List of elements. */ }; +/** Composition data page 2 record. */ +struct bt_mesh_comp2_record { + /** Mesh profile ID. */ + uint16_t id; + /** Mesh Profile Version. */ + struct { + /** Major version. */ + uint8_t x; + /** Minor version. */ + uint8_t y; + /** Z version. */ + uint8_t z; + } version; + /** Element offset count. */ + uint8_t elem_offset_cnt; + /** Element offset list. */ + const uint8_t *elem_offset; + /** Length of additional data. */ + uint16_t data_len; + /** Additional data. */ + const void *data; +}; + +/** Node Composition data page 2 */ +struct bt_mesh_comp2 { + /** The number of Mesh Profile records on a device. */ + size_t record_cnt; + /** List of records. */ + const struct bt_mesh_comp2_record *record; +}; + +/** @brief Register composition data page 2 of the device. + * + * Register Mesh Profiles information (Ref section 3.12 in + * Bluetooth SIG Assigned Numbers) for composition data + * page 2 of the device. + * + * @note There must be at least one record present in @c comp2 + * + * @param comp2 Pointer to composition data page 2. + * + * @return Zero on success or (negative) error code otherwise. + */ +int bt_mesh_comp2_register(const struct bt_mesh_comp2 *comp2); + #ifdef __cplusplus } #endif diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 9b0c4bd80f0..b8e26309a28 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1373,6 +1373,11 @@ config BT_MESH_COMP_PAGE_1 help Enable support for Composition Data Page 1. +config BT_MESH_COMP_PAGE_2 + bool "Support for Composition Data Page 2" + help + Enable support for Composition Data Page 2. + config BT_MESH_MODEL_EXTENSION_LIST_SIZE int "Model extensions list size" depends on BT_MESH_COMP_PAGE_1 diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index c022eedbadc..b6dab2d67a7 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -53,6 +53,7 @@ struct comp_foreach_model_arg { }; static const struct bt_mesh_comp *dev_comp; +static const struct bt_mesh_comp2 *dev_comp2; static uint16_t dev_primary_addr; static void (*msg_cb)(uint32_t opcode, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf); @@ -112,6 +113,9 @@ static const struct { #if IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) { "bt/mesh/cmp/1", 1, }, #endif +#if IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) + { "bt/mesh/cmp/2", 2, }, +#endif }; void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod, @@ -609,7 +613,7 @@ static size_t page1_elem_size(struct bt_mesh_elem *elem) return temp_size; } -int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf) +static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf) { const struct bt_mesh_comp *comp; uint8_t cor_id = 0; @@ -660,6 +664,51 @@ int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf) return 0; } +static int bt_mesh_comp_data_get_page_2(struct net_buf_simple *buf) +{ + if (!dev_comp2) { + LOG_ERR("Composition data P2 not registered"); + return -ENODEV; + } + + for (int i = 0; i < dev_comp2->record_cnt; i++) { + if (net_buf_simple_tailroom(buf) < + (8 + dev_comp2->record[i].elem_offset_cnt + dev_comp2->record[i].data_len + + BT_MESH_MIC_SHORT)) { + if (IS_ENABLED(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)) { + /* Mesh Profile 1.1 Section 4.4.1.2.2: + * If the complete list of models does not fit in the Data field, + * the element shall not be reported. + */ + LOG_DBG("Record 0x%04x didn't fit in the Data field", + i); + return 0; + } + + LOG_ERR("Too large device composition"); + return -E2BIG; + } + + net_buf_simple_add_le16(buf, dev_comp2->record[i].id); + net_buf_simple_add_u8(buf, dev_comp2->record[i].version.x); + net_buf_simple_add_u8(buf, dev_comp2->record[i].version.y); + net_buf_simple_add_u8(buf, dev_comp2->record[i].version.z); + net_buf_simple_add_u8(buf, dev_comp2->record[i].elem_offset_cnt); + if (dev_comp2->record[i].elem_offset_cnt) { + net_buf_simple_add_mem(buf, dev_comp2->record[i].elem_offset, + dev_comp2->record[i].elem_offset_cnt); + } + + net_buf_simple_add_le16(buf, dev_comp2->record[i].data_len); + if (dev_comp2->record[i].data_len) { + net_buf_simple_add_mem(buf, dev_comp2->record[i].data, + dev_comp2->record[i].data_len); + } + } + + return 0; +} + int32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod) { int32_t period; @@ -994,6 +1043,17 @@ int bt_mesh_comp_register(const struct bt_mesh_comp *comp) return err; } +int bt_mesh_comp2_register(const struct bt_mesh_comp2 *comp2) +{ + if (!IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { + return -EINVAL; + } + + dev_comp2 = comp2; + + return 0; +} + void bt_mesh_comp_provision(uint16_t addr) { int i; @@ -2151,8 +2211,10 @@ int bt_mesh_comp_data_get_page(struct net_buf_simple *buf, size_t page, size_t o { if (page == 0 || page == 128) { return bt_mesh_comp_data_get_page_0(buf, offset); - } else if (page == 1 || page == 129) { + } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && (page == 1 || page == 129)) { return bt_mesh_comp_data_get_page_1(buf); + } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && (page == 2 || page == 130)) { + return bt_mesh_comp_data_get_page_2(buf); } return -EINVAL; diff --git a/subsys/bluetooth/mesh/access.h b/subsys/bluetooth/mesh/access.h index a7d3ffe5865..4740963dd21 100644 --- a/subsys/bluetooth/mesh/access.h +++ b/subsys/bluetooth/mesh/access.h @@ -27,7 +27,6 @@ size_t bt_mesh_comp_page_0_size(void); int bt_mesh_comp_data_get_page_0(struct net_buf_simple *buf, size_t offset); size_t bt_mesh_metadata_page_0_size(void); int bt_mesh_metadata_get_page_0(struct net_buf_simple *buf, size_t offset); -int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf); /* Find local element based on unicast address */ struct bt_mesh_elem *bt_mesh_elem_find(uint16_t addr); diff --git a/subsys/bluetooth/mesh/cfg_srv.c b/subsys/bluetooth/mesh/cfg_srv.c index 2fba9360206..eb732a34910 100644 --- a/subsys/bluetooth/mesh/cfg_srv.c +++ b/subsys/bluetooth/mesh/cfg_srv.c @@ -61,13 +61,19 @@ static int dev_comp_data_get(struct bt_mesh_model *model, page = net_buf_simple_pull_u8(buf); - if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && + if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && + (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 130U; + } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { page = 129U; } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { page = 128U; + } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { + page = 2U; } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { page = 1U; } else if (page != 0U) { From c227d927cb85b7bf66c151063a15092a06a7850d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Wed, 30 Aug 2023 14:16:46 +0200 Subject: [PATCH 0142/1623] [nrf fromtree] Bluetooth: Mesh: Shell support for comp data page2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds shell support for composition data page 2 and 130 Signed-off-by: Anders Storrø (cherry picked from commit 6b627771c898ce2086cc69369eaec34302079e8f) Signed-off-by: Alperen Şener (cherry picked from commit 85fdab49a5550230e4259c6b58dd8485f1f61398) --- include/zephyr/bluetooth/mesh/cfg_cli.h | 34 ++++++++++++++++++++ subsys/bluetooth/mesh/cfg_cli.c | 35 +++++++++++++++++++++ subsys/bluetooth/mesh/shell/cfg.c | 42 +++++++++++++++++++++++-- 3 files changed, 108 insertions(+), 3 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/cfg_cli.h b/include/zephyr/bluetooth/mesh/cfg_cli.h index e6fd31d7c3a..d2221da38da 100644 --- a/include/zephyr/bluetooth/mesh/cfg_cli.h +++ b/include/zephyr/bluetooth/mesh/cfg_cli.h @@ -1786,6 +1786,40 @@ struct bt_mesh_comp_p1_model_item *bt_mesh_comp_p1_item_pull( struct bt_mesh_comp_p1_ext_item *bt_mesh_comp_p1_pull_ext_item( struct bt_mesh_comp_p1_model_item *item, struct bt_mesh_comp_p1_ext_item *ext_item); +/** Composition data page 2 record parsing structure. */ +struct bt_mesh_comp_p2_record { + /** Mesh profile ID. */ + uint16_t id; + /** Mesh Profile Version. */ + struct { + /** Major version. */ + uint8_t x; + /** Minor version. */ + uint8_t y; + /** Z version. */ + uint8_t z; + } version; + /** Element offset buffer. */ + struct net_buf_simple *elem_buf; + /** Additional data buffer. */ + struct net_buf_simple *data_buf; +}; + +/** @brief Pull a Composition Data Page 2 Record from a composition data page 2 + * instance. + * + * Each call to this function will pull out a new element from the composition + * data page, until all elements have been pulled. + * + * @param buf Composition data page 2 buffer + * @param record Record to fill. + * + * @return A pointer to @c record on success, or NULL if no more elements could + * be pulled. + */ +struct bt_mesh_comp_p2_record *bt_mesh_comp_p2_record_pull(struct net_buf_simple *buf, + struct bt_mesh_comp_p2_record *record); + /** @brief Unpack a list of key index entries from a buffer. * * On success, @c dst_cnt is set to the amount of unpacked key index entries. diff --git a/subsys/bluetooth/mesh/cfg_cli.c b/subsys/bluetooth/mesh/cfg_cli.c index a5ad80193f3..68af4fae59d 100644 --- a/subsys/bluetooth/mesh/cfg_cli.c +++ b/subsys/bluetooth/mesh/cfg_cli.c @@ -2443,3 +2443,38 @@ struct bt_mesh_comp_p1_ext_item *bt_mesh_comp_p1_pull_ext_item( } return ext_item; } + +struct bt_mesh_comp_p2_record *bt_mesh_comp_p2_record_pull(struct net_buf_simple *buf, + struct bt_mesh_comp_p2_record *record) +{ + if (buf->len < 8) { + LOG_DBG("No more elements to pull or missing data"); + return NULL; + } + + uint8_t elem_offset_cnt; + uint16_t data_len; + + record->id = net_buf_simple_pull_le16(buf); + record->version.x = net_buf_simple_pull_u8(buf); + record->version.y = net_buf_simple_pull_u8(buf); + record->version.z = net_buf_simple_pull_u8(buf); + elem_offset_cnt = net_buf_simple_pull_u8(buf); + if (buf->len < elem_offset_cnt + 2) { + LOG_WRN("Invalid composition data offset count"); + return NULL; + } + + net_buf_simple_init_with_data(record->elem_buf, + net_buf_simple_pull_mem(buf, elem_offset_cnt), + elem_offset_cnt); + data_len = net_buf_simple_pull_le16(buf); + if (buf->len < data_len) { + LOG_WRN("Invalid composition data additional data length"); + return NULL; + } + + net_buf_simple_init_with_data(record->data_buf, + net_buf_simple_pull_mem(buf, data_len), data_len); + return record; +} diff --git a/subsys/bluetooth/mesh/shell/cfg.c b/subsys/bluetooth/mesh/shell/cfg.c index d47f04bcc00..c4a62a996e3 100644 --- a/subsys/bluetooth/mesh/shell/cfg.c +++ b/subsys/bluetooth/mesh/shell/cfg.c @@ -98,9 +98,10 @@ static int cmd_get_comp(const struct shell *sh, size_t argc, char *argv[]) return 0; } - if (page != 0 && page != 1 && page != 128 && page != 129) { - shell_print(sh, "Got page %d. No parser available.", - page); + if (page != 0 && page != 128 && + ((page != 1 && page != 129) || !IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) && + ((page != 2 && page != 130) || !IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2))) { + shell_print(sh, "Got page %d. No parser available.", page); return 0; } @@ -254,6 +255,41 @@ static int cmd_get_comp(const struct shell *sh, size_t argc, char *argv[]) } } + if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && (page == 2 || page == 130)) { + /* size of 32 is chosen arbitrary, as sufficient for testing purposes */ + NET_BUF_SIMPLE_DEFINE(p2_elem_offset_buf, 32); + NET_BUF_SIMPLE_DEFINE(p2_data_buf, 32); + struct bt_mesh_comp_p2_record p2_elem = { + .elem_buf = &p2_elem_offset_buf, + .data_buf = &p2_data_buf + }; + + if (!buf.len) { + shell_error(sh, "Composition data empty"); + return 0; + } + shell_print(sh, "Got Composition Data for 0x%04x, page: %d:", + bt_mesh_shell_target_ctx.dst, page); + + while (bt_mesh_comp_p2_record_pull(&buf, &p2_elem)) { + + shell_print(sh, "\tMesh Profile id: %04x ", p2_elem.id); + shell_print(sh, "\t\tVersion: %d.%d.%d ", p2_elem.version.x, + p2_elem.version.y, p2_elem.version.z); + shell_print(sh, "\t\tElement offsets:"); + + while (p2_elem.elem_buf->len) { + shell_print(sh, "\t\t\t%d ", + net_buf_simple_pull_u8(p2_elem.elem_buf)); + } + + if (p2_elem.data_buf->len) { + shell_print(sh, "\t\t%d bytes of additional data is available", + p2_elem.data_buf->len); + } + } + } + if (buf.len) { shell_print(sh, "\t\t...truncated data!"); } From e99b89aedb7c7f2ece20244d5283d858b31ab29a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alperen=20=C5=9Eener?= Date: Thu, 7 Sep 2023 17:46:24 +0200 Subject: [PATCH 0143/1623] [nrf fromtree] Bluetooth: Mesh: Fix Solicitation Mesh crypto API use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pointer of the keys should be send to mesh en/decryption APIs. Signed-off-by: Alperen Şener (cherry picked from commit 66bf33f0900854a3df968e8a93a8dba4bd676c3f) Signed-off-by: Alperen Şener (cherry picked from commit 5b69fd4353195fc0e1cd8c452431828044a7fd1a) --- subsys/bluetooth/mesh/solicitation.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/solicitation.c b/subsys/bluetooth/mesh/solicitation.c index 1bf9f9a465a..f6543dcb320 100644 --- a/subsys/bluetooth/mesh/solicitation.c +++ b/subsys/bluetooth/mesh/solicitation.c @@ -304,7 +304,7 @@ static int sol_pdu_create(struct bt_mesh_subnet *sub, struct net_buf_simple *pdu /* DST = 0x0000 */ net_buf_simple_add_le16(pdu, 0x0000); - err = bt_mesh_net_encrypt(sub->keys[SUBNET_KEY_TX_IDX(sub)].msg.enc, + err = bt_mesh_net_encrypt(&sub->keys[SUBNET_KEY_TX_IDX(sub)].msg.enc, pdu, 0, BT_MESH_NONCE_SOLICITATION); if (err) { @@ -313,7 +313,7 @@ static int sol_pdu_create(struct bt_mesh_subnet *sub, struct net_buf_simple *pdu } err = bt_mesh_net_obfuscate(pdu->data, 0, - sub->keys[SUBNET_KEY_TX_IDX(sub)].msg.privacy); + &sub->keys[SUBNET_KEY_TX_IDX(sub)].msg.privacy); if (err) { LOG_ERR("Obfuscation failed, err=%d", err); return err; From 6e082b4141d1dc295dbf9359cacb342fba06aa9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Wed, 6 Sep 2023 13:06:40 +0200 Subject: [PATCH 0144/1623] [nrf fromtree] Bluetooth: Mesh: Store priv beacon in sep entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stores persistent private beacon state in separate settings entry. This is implemented to avoid issues related to backwards compatibility between device firmware updates. Signed-off-by: Anders Storrø (cherry picked from commit c80a52a1e31eaf74d83c1d4e2a47f82936ce4bc5) Signed-off-by: Alperen Şener (cherry picked from commit f93d50086c43854eb41f0616c79c3a387b3d8f24) --- subsys/bluetooth/mesh/cfg.c | 27 ++------- subsys/bluetooth/mesh/priv_beacon.h | 7 +++ subsys/bluetooth/mesh/priv_beacon_srv.c | 74 +++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 21 deletions(-) create mode 100644 subsys/bluetooth/mesh/priv_beacon.h diff --git a/subsys/bluetooth/mesh/cfg.c b/subsys/bluetooth/mesh/cfg.c index 287023afa68..4a59f76bbbd 100644 --- a/subsys/bluetooth/mesh/cfg.c +++ b/subsys/bluetooth/mesh/cfg.c @@ -16,6 +16,7 @@ #include "friend.h" #include "adv.h" #include "cfg.h" +#include "priv_beacon.h" #define LOG_LEVEL CONFIG_BT_MESH_CFG_LOG_LEVEL #include @@ -30,11 +31,6 @@ struct cfg_val { uint8_t gatt_proxy; uint8_t frnd; uint8_t default_ttl; -#if defined(CONFIG_BT_MESH_PRIV_BEACONS) - uint8_t priv_beacon; - uint8_t priv_beacon_int; - uint8_t priv_gatt_proxy; -#endif #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) uint8_t on_demand_state; #endif @@ -109,9 +105,9 @@ int bt_mesh_priv_beacon_set(enum bt_mesh_feat_state priv_beacon) /* Beacon timer will stop automatically when all beacons are disabled. */ } - if (IS_ENABLED(CONFIG_BT_SETTINGS) && + if (IS_ENABLED(CONFIG_BT_SETTINGS) && IS_ENABLED(CONFIG_BT_MESH_PRIV_BEACON_SRV) && atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) { - bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_CFG_PENDING); + bt_mesh_priv_beacon_srv_store_schedule(); } return 0; @@ -244,9 +240,9 @@ int bt_mesh_priv_gatt_proxy_set(enum bt_mesh_feat_state priv_gatt_proxy) bt_mesh_adv_gatt_update(); } - if (IS_ENABLED(CONFIG_BT_SETTINGS) && + if (IS_ENABLED(CONFIG_BT_SETTINGS) && IS_ENABLED(CONFIG_BT_MESH_PRIV_BEACON_SRV) && atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) { - bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_CFG_PENDING); + bt_mesh_priv_beacon_srv_store_schedule(); } return 0; @@ -261,7 +257,6 @@ enum bt_mesh_feat_state bt_mesh_priv_gatt_proxy_get(void) return feature_get(BT_MESH_PRIV_GATT_PROXY); } - int bt_mesh_default_ttl_set(uint8_t default_ttl) { if (default_ttl == 1 || default_ttl > BT_MESH_TTL_MAX) { @@ -454,11 +449,6 @@ static int cfg_set(const char *name, size_t len_rd, bt_mesh_gatt_proxy_set(cfg.gatt_proxy); bt_mesh_friend_set(cfg.frnd); bt_mesh_default_ttl_set(cfg.default_ttl); -#if defined(CONFIG_BT_MESH_PRIV_BEACONS) - bt_mesh_priv_beacon_set(cfg.priv_beacon); - bt_mesh_priv_beacon_update_interval_set(cfg.priv_beacon_int); - bt_mesh_priv_gatt_proxy_set(cfg.priv_gatt_proxy); -#endif #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) bt_mesh_od_priv_proxy_set(cfg.on_demand_state); #endif @@ -476,7 +466,7 @@ static void clear_cfg(void) err = settings_delete("bt/mesh/Cfg"); if (err) { - LOG_ERR("Failed to clear configuration"); + LOG_ERR("Failed to clear configuration (err: %d)", err); } else { LOG_DBG("Cleared configuration"); } @@ -494,11 +484,6 @@ static void store_pending_cfg(void) val.gatt_proxy = bt_mesh_gatt_proxy_get(); val.frnd = bt_mesh_friend_get(); val.default_ttl = bt_mesh_default_ttl_get(); -#if defined(CONFIG_BT_MESH_PRIV_BEACONS) - val.priv_beacon = bt_mesh_priv_beacon_get(); - val.priv_beacon_int = bt_mesh_priv_beacon_update_interval_get(); - val.priv_gatt_proxy = bt_mesh_priv_gatt_proxy_get(); -#endif #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) val.on_demand_state = bt_mesh_od_priv_proxy_get(); #endif diff --git a/subsys/bluetooth/mesh/priv_beacon.h b/subsys/bluetooth/mesh/priv_beacon.h new file mode 100644 index 00000000000..0cbbdafd0b1 --- /dev/null +++ b/subsys/bluetooth/mesh/priv_beacon.h @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +void bt_mesh_priv_beacon_srv_store_schedule(void); diff --git a/subsys/bluetooth/mesh/priv_beacon_srv.c b/subsys/bluetooth/mesh/priv_beacon_srv.c index a1478efff80..377703e8352 100644 --- a/subsys/bluetooth/mesh/priv_beacon_srv.c +++ b/subsys/bluetooth/mesh/priv_beacon_srv.c @@ -11,11 +11,33 @@ #include "foundation.h" #include "beacon.h" #include "cfg.h" +#include "settings.h" #define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL #include LOG_MODULE_REGISTER(bt_mesh_priv_beacon_srv); +static struct bt_mesh_model *priv_beacon_srv; + +/* Private Beacon configuration server model states */ +struct { + uint8_t state; + uint8_t interval; + uint8_t proxy_state; +} priv_beacon_state; + +static int priv_beacon_store(bool delete) +{ + if (!IS_ENABLED(CONFIG_BT_SETTINGS)) { + return 0; + } + + const void *data = delete ? NULL : &priv_beacon_state; + size_t len = delete ? 0 : sizeof(priv_beacon_state); + + return bt_mesh_model_data_store(priv_beacon_srv, false, "pb", data, len); +} + static int beacon_status_rsp(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx) { @@ -179,11 +201,63 @@ static int priv_beacon_srv_init(struct bt_mesh_model *mod) return -EINVAL; } + priv_beacon_srv = mod; mod->keys[0] = BT_MESH_KEY_DEV_LOCAL; return 0; } +static void priv_beacon_srv_reset(struct bt_mesh_model *model) +{ + (void)memset(&priv_beacon_state, 0, sizeof(priv_beacon_state)); + priv_beacon_store(true); +} + +#ifdef CONFIG_BT_SETTINGS +static int priv_beacon_srv_settings_set(struct bt_mesh_model *model, const char *name, + size_t len_rd, settings_read_cb read_cb, void *cb_data) +{ + int err; + + if (len_rd == 0) { + LOG_DBG("Cleared configuration state"); + return 0; + } + + err = bt_mesh_settings_set(read_cb, cb_data, &priv_beacon_state, sizeof(priv_beacon_state)); + if (err) { + LOG_ERR("Failed to set Private Beacon state"); + return err; + } + + bt_mesh_priv_beacon_set(priv_beacon_state.state); + bt_mesh_priv_beacon_update_interval_set(priv_beacon_state.interval); + bt_mesh_priv_gatt_proxy_set(priv_beacon_state.proxy_state); + return 0; +} + +static void priv_beacon_srv_pending_store(struct bt_mesh_model *model) +{ + priv_beacon_state.state = bt_mesh_priv_beacon_get(); + priv_beacon_state.interval = bt_mesh_priv_beacon_update_interval_get(); + priv_beacon_state.proxy_state = bt_mesh_priv_gatt_proxy_get(); + + priv_beacon_store(false); +} +#endif + const struct bt_mesh_model_cb bt_mesh_priv_beacon_srv_cb = { .init = priv_beacon_srv_init, + .reset = priv_beacon_srv_reset, +#ifdef CONFIG_BT_SETTINGS + .settings_set = priv_beacon_srv_settings_set, + .pending_store = priv_beacon_srv_pending_store, +#endif }; + +void bt_mesh_priv_beacon_srv_store_schedule(void) +{ + if (IS_ENABLED(CONFIG_BT_SETTINGS)) { + bt_mesh_model_data_store_schedule(priv_beacon_srv); + } +} From fbbfa43fae8509eef87eb3151281c3f10ed6265a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Wed, 6 Sep 2023 13:06:40 +0200 Subject: [PATCH 0145/1623] [nrf fromtree] Bluetooth: Mesh: Store priv proxy in sep entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stores persistent on-demand private GATT proxy state in separate settings entry. This is implemented to avoid issues related to backwards compatibility between device firmware updates. Signed-off-by: Anders Storrø (cherry picked from commit 6559de3238d3ff6f5da5535811457ad29b6e9677) Signed-off-by: Alperen Şener (cherry picked from commit 6ec9512a51bd6edc73dfc26a089e345800726647) --- subsys/bluetooth/mesh/cfg.c | 15 ++---- subsys/bluetooth/mesh/od_priv_proxy.h | 7 +++ subsys/bluetooth/mesh/od_priv_proxy_srv.c | 65 +++++++++++++++++++++++ 3 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 subsys/bluetooth/mesh/od_priv_proxy.h diff --git a/subsys/bluetooth/mesh/cfg.c b/subsys/bluetooth/mesh/cfg.c index 4a59f76bbbd..c7bea0d29b0 100644 --- a/subsys/bluetooth/mesh/cfg.c +++ b/subsys/bluetooth/mesh/cfg.c @@ -16,6 +16,7 @@ #include "friend.h" #include "adv.h" #include "cfg.h" +#include "od_priv_proxy.h" #include "priv_beacon.h" #define LOG_LEVEL CONFIG_BT_MESH_CFG_LOG_LEVEL @@ -31,9 +32,6 @@ struct cfg_val { uint8_t gatt_proxy; uint8_t frnd; uint8_t default_ttl; -#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) - uint8_t on_demand_state; -#endif }; void bt_mesh_beacon_set(bool beacon) @@ -157,9 +155,9 @@ int bt_mesh_od_priv_proxy_set(uint8_t on_demand_proxy) bt_mesh.on_demand_state = on_demand_proxy; } - if (IS_ENABLED(CONFIG_BT_SETTINGS) && + if (IS_ENABLED(CONFIG_BT_SETTINGS) && IS_ENABLED(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) && atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) { - bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_CFG_PENDING); + bt_mesh_od_priv_proxy_srv_store_schedule(); } return 0; #endif @@ -449,9 +447,6 @@ static int cfg_set(const char *name, size_t len_rd, bt_mesh_gatt_proxy_set(cfg.gatt_proxy); bt_mesh_friend_set(cfg.frnd); bt_mesh_default_ttl_set(cfg.default_ttl); -#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) - bt_mesh_od_priv_proxy_set(cfg.on_demand_state); -#endif LOG_DBG("Restored configuration state"); @@ -484,10 +479,6 @@ static void store_pending_cfg(void) val.gatt_proxy = bt_mesh_gatt_proxy_get(); val.frnd = bt_mesh_friend_get(); val.default_ttl = bt_mesh_default_ttl_get(); -#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) - val.on_demand_state = bt_mesh_od_priv_proxy_get(); -#endif - err = settings_save_one("bt/mesh/Cfg", &val, sizeof(val)); if (err) { diff --git a/subsys/bluetooth/mesh/od_priv_proxy.h b/subsys/bluetooth/mesh/od_priv_proxy.h new file mode 100644 index 00000000000..7baa7f067fc --- /dev/null +++ b/subsys/bluetooth/mesh/od_priv_proxy.h @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +void bt_mesh_od_priv_proxy_srv_store_schedule(void); diff --git a/subsys/bluetooth/mesh/od_priv_proxy_srv.c b/subsys/bluetooth/mesh/od_priv_proxy_srv.c index 32f5ea44179..b18a8ec7530 100644 --- a/subsys/bluetooth/mesh/od_priv_proxy_srv.c +++ b/subsys/bluetooth/mesh/od_priv_proxy_srv.c @@ -9,11 +9,28 @@ #include "access.h" #include "cfg.h" #include "foundation.h" +#include "settings.h" #define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL #include LOG_MODULE_REGISTER(bt_mesh_od_priv_proxy_srv); + +static struct bt_mesh_model *od_priv_proxy_srv; +static uint8_t on_demand_state; + +static int od_priv_proxy_store(bool delete) +{ + if (!IS_ENABLED(CONFIG_BT_SETTINGS)) { + return 0; + } + + const void *data = delete ? NULL : &on_demand_state; + size_t len = delete ? 0 : sizeof(uint8_t); + + return bt_mesh_model_data_store(od_priv_proxy_srv, false, "pp", data, len); +} + static int proxy_status_rsp(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx) { @@ -64,6 +81,8 @@ const struct bt_mesh_model_op _bt_mesh_od_priv_proxy_srv_op[] = { static int od_priv_proxy_srv_init(struct bt_mesh_model *mod) { + od_priv_proxy_srv = mod; + struct bt_mesh_model *priv_beacon_srv = bt_mesh_model_find( bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_PRIV_BEACON_SRV); struct bt_mesh_model *sol_pdu_rpl_srv = bt_mesh_model_find( @@ -89,6 +108,52 @@ static int od_priv_proxy_srv_init(struct bt_mesh_model *mod) return 0; } +static void od_priv_proxy_srv_reset(struct bt_mesh_model *model) +{ + on_demand_state = 0; + od_priv_proxy_store(true); +} + +#ifdef CONFIG_BT_SETTINGS +static int od_priv_proxy_srv_settings_set(struct bt_mesh_model *model, const char *name, + size_t len_rd, settings_read_cb read_cb, void *cb_data) +{ + int err; + + if (len_rd == 0) { + LOG_DBG("Cleared configuration state"); + return 0; + } + + err = bt_mesh_settings_set(read_cb, cb_data, &on_demand_state, sizeof(uint8_t)); + if (err) { + LOG_ERR("Failed to set OD private proxy state"); + return err; + } + + bt_mesh_od_priv_proxy_set(on_demand_state); + return 0; +} + +static void od_priv_proxy_srv_pending_store(struct bt_mesh_model *model) +{ + on_demand_state = bt_mesh_od_priv_proxy_get(); + od_priv_proxy_store(false); +} +#endif + const struct bt_mesh_model_cb _bt_mesh_od_priv_proxy_srv_cb = { .init = od_priv_proxy_srv_init, + .reset = od_priv_proxy_srv_reset, +#ifdef CONFIG_BT_SETTINGS + .settings_set = od_priv_proxy_srv_settings_set, + .pending_store = od_priv_proxy_srv_pending_store, +#endif }; + +void bt_mesh_od_priv_proxy_srv_store_schedule(void) +{ + if (IS_ENABLED(CONFIG_BT_SETTINGS)) { + bt_mesh_model_data_store_schedule(od_priv_proxy_srv); + } +} From 96ac408fa71a6310e2a7565377854c1886cf5e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alperen=20=C5=9Eener?= Date: Mon, 11 Sep 2023 15:47:39 +0200 Subject: [PATCH 0146/1623] [nrf fromtree] Bluetooth: Mesh: add optional OOB info to ext scan report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even though the OOB information is optional we can add it to extended scan reports in cases there is detected unprovisoned devices. Referring to MshPRT section 4.4.5.3: When the Remote Provisioning Extended Scan procedure completes without receiving an advertisement from the unprovisioned device, the OOBInformation and AdvStructures fields shall be skipped. When the obtained data is empty, the AdvStructures field shall be skipped. The Status field shall be set to Success. and referring to MshPRT section 4.3.4.9: The OOBInformation field contains the OOB Information of either the unprovisioned device or the Remote Provisioning Server. Signed-off-by: Alperen Şener (cherry picked from commit f6a9fc12025264f010eee4200bb4fd34a6a07e22) Signed-off-by: Alperen Şener (cherry picked from commit e28ae8300000b8fef7f139536693ffc16c44a7f9) --- subsys/bluetooth/mesh/rpr_srv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/rpr_srv.c b/subsys/bluetooth/mesh/rpr_srv.c index b38bec4cd40..c8639d8b514 100644 --- a/subsys/bluetooth/mesh/rpr_srv.c +++ b/subsys/bluetooth/mesh/rpr_srv.c @@ -267,13 +267,15 @@ static void scan_ext_report_send(void) bt_mesh_model_msg_init(&buf, RPR_OP_EXTENDED_SCAN_REPORT); net_buf_simple_add_u8(&buf, BT_MESH_RPR_SUCCESS); net_buf_simple_add_mem(&buf, srv.scan.dev->uuid, 16); - if (!(srv.scan.dev->flags & BT_MESH_RPR_UNPROV_FOUND)) { + + if (srv.scan.dev->flags & BT_MESH_RPR_UNPROV_FOUND) { + net_buf_simple_add_le16(&buf, srv.scan.dev->oob); + } else { LOG_DBG("not found"); goto send; } if (srv.scan.dev->flags & BT_MESH_RPR_UNPROV_EXT_ADV_RXD) { - net_buf_simple_add_le16(&buf, srv.scan.dev->oob); net_buf_simple_add_mem(&buf, srv.scan.adv_data->data, srv.scan.adv_data->len); LOG_DBG("adv data: %s", From 34e20954d8d64805a6e1cd0c804361ce713da363 Mon Sep 17 00:00:00 2001 From: Ludvig Samuelsen Jordet Date: Wed, 9 Aug 2023 09:30:29 +0200 Subject: [PATCH 0147/1623] [nrf fromtree] Bluetooth: Mesh: Add support for Upload OOB Start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds support for the Upload OOB Start message to the DFD server, by providing callbacks that the application can use to hook any OOB scheme into the model behavior. There are also extensive changes to the dfu_slot module, to accomodate the new needs that appeared with the support for OOB transfer (mainly, fwid, size and metadata are no longer available when the slot is allocated, they appear later in the handling). Signed-off-by: Ludvig Samuelsen Jordet (cherry picked from commit b990a74f8b41b91634061ee366c1005541f319eb) Signed-off-by: Alperen Şener (cherry picked from commit e7b8ff578bb605b7071e8ba220e5633e7f9c42b0) --- doc/connectivity/bluetooth/api/mesh/shell.rst | 5 +- include/zephyr/bluetooth/mesh/dfd_srv.h | 163 +++++++++- include/zephyr/bluetooth/mesh/dfu.h | 13 +- subsys/bluetooth/mesh/Kconfig | 8 + subsys/bluetooth/mesh/dfd_srv.c | 270 +++++++++++++--- subsys/bluetooth/mesh/dfu_slot.c | 294 ++++++++++-------- subsys/bluetooth/mesh/dfu_slot.h | 87 ++++-- subsys/bluetooth/mesh/shell/dfd.c | 9 +- subsys/bluetooth/mesh/shell/dfu.c | 53 ++-- tests/bsim/bluetooth/mesh/prj_mesh1d1.conf | 3 +- tests/bsim/bluetooth/mesh/src/test_dfu.c | 185 +++++++---- .../tests_scripts/dfu/dfu_slot_idempotency.sh | 14 + .../tests_scripts/dfu/dfu_slot_reservation.sh | 14 + 13 files changed, 792 insertions(+), 326 deletions(-) create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh diff --git a/doc/connectivity/bluetooth/api/mesh/shell.rst b/doc/connectivity/bluetooth/api/mesh/shell.rst index f9acf24d277..e6609f40e5c 100644 --- a/doc/connectivity/bluetooth/api/mesh/shell.rst +++ b/doc/connectivity/bluetooth/api/mesh/shell.rst @@ -1034,15 +1034,14 @@ Firmware Update Client model The Firmware Update Client model can be added to the mesh shell by enabling configuration options :kconfig:option:`CONFIG_BT_MESH_BLOB_CLI` and :kconfig:option:`CONFIG_BT_MESH_DFU_CLI`. The Firmware Update Client demonstrates the firmware update Distributor role by transferring a dummy firmware update to a set of Target nodes. -``mesh models dfu slot add [ [ []]]`` +``mesh models dfu slot add []`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add a virtual DFU image slot that can be transferred as a DFU image. The image slot will be assigned an image slot index, which is printed as a response, and can be used to reference the slot in other commands. To update the image slot, remove it using the ``mesh models dfu slot del`` shell command and then add it again. * ``Size``: DFU image slot size in bytes. - * ``FwID``: Optional firmware ID, formatted as a hexstring. + * ``FwID``: Firmware ID, formatted as a hexstring. * ``Metadata``: Optional firmware metadata, formatted as a hexstring. - * ``URI``: Optional URI for the firmware. ``mesh models dfu slot del `` diff --git a/include/zephyr/bluetooth/mesh/dfd_srv.h b/include/zephyr/bluetooth/mesh/dfd_srv.h index 0e281b29186..da339c57ec6 100644 --- a/include/zephyr/bluetooth/mesh/dfd_srv.h +++ b/include/zephyr/bluetooth/mesh/dfd_srv.h @@ -29,11 +29,47 @@ extern "C" { #define CONFIG_BT_MESH_DFD_SRV_TARGETS_MAX 0 #endif +#ifndef CONFIG_BT_MESH_DFD_SRV_SLOT_MAX_SIZE +#define CONFIG_BT_MESH_DFD_SRV_SLOT_MAX_SIZE 0 +#endif + +#ifndef CONFIG_BT_MESH_DFD_SRV_SLOT_SPACE +#define CONFIG_BT_MESH_DFD_SRV_SLOT_SPACE 0 +#endif + struct bt_mesh_dfd_srv; +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD +/** + * + * @brief Initialization parameters for the @ref bt_mesh_dfd_srv with OOB + * upload support. + * + * @param[in] _cb Pointer to a @ref bt_mesh_dfd_srv_cb instance. + * @param[in] _oob_schemes Array of OOB schemes supported by the server, + * each scheme being a code point from the + * Bluetooth SIG Assigned Numbers document. + * @param[in] _oob_schemes_count Number of schemes in @c _oob_schemes. + */ +#define BT_MESH_DFD_SRV_OOB_INIT(_cb, _oob_schemes, _oob_schemes_count) \ + { \ + .cb = _cb, \ + .dfu = BT_MESH_DFU_CLI_INIT(&_bt_mesh_dfd_srv_dfu_cb), \ + .upload = { \ + .blob = { .cb = &_bt_mesh_dfd_srv_blob_cb }, \ + }, \ + .oob_schemes = { \ + .schemes = _oob_schemes, \ + .count = _oob_schemes_count, \ + }, \ + } +#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ + /** * * @brief Initialization parameters for the @ref bt_mesh_dfd_srv. + * + * @param[in] _cb Pointer to a @ref bt_mesh_dfd_srv_cb instance. */ #define BT_MESH_DFD_SRV_INIT(_cb) \ { \ @@ -75,6 +111,64 @@ struct bt_mesh_dfd_srv_cb { const struct bt_mesh_dfu_slot *slot, const struct bt_mesh_blob_io **io); +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + /** @brief Firmware upload OOB start callback. + * + * Called at the start of an OOB firmware upload. The application must + * start a firmware check using an OOB mechanism, and then call + * @ref bt_mesh_dfd_srv_oob_check_complete. Depending on the return + * value of this function, the application must then start storing the + * firmware image using an OOB mechanism, and call + * @ref bt_mesh_dfd_srv_oob_store_complete. This callback is mandatory + * to support OOB uploads. + * + * @param srv Firmware Distribution Server model instance. + * @param slot Slot to be used for the upload. + * @param uri Pointer to buffer containing the URI used to + * check for new firmware. + * @param uri_len Length of the URI buffer. + * @param fwid Pointer to buffer containing the current + * firmware ID to be used when checking for + * availability of new firmware. + * @param fwid_len Length of the current firmware ID. Must be set + * to the length of the new firmware ID if it is + * available, or to 0 if new firmware is not + * available. + * + * @return BT_MESH_DFD_SUCCESS on success, or error code otherwise. + */ + int (*start_oob_upload)(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot, + const char *uri, uint8_t uri_len, + const uint8_t *fwid, uint16_t fwid_len); + + /** @brief Cancel store OOB callback + * + * Called when an OOB store is cancelled. The application must stop + * any ongoing OOB image transfer. This callback is mandatory to + * support OOB uploads. + * + * @param srv Firmware Distribution Server model instance. + * @param slot DFU image slot to cancel + */ + void (*cancel_oob_upload)(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot); + + /** @brief Get the progress of an ongoing OOB store + * + * Called by the Firmware Distribution Server model when it needs to + * get the current progress of an ongoing OOB store from the + * application. This callback is mandatory to support OOB uploads. + * + * @param srv Firmware Distribution Server model instance. + * @param slot DFU image slot to get progress for. + * + * @return The current progress of the ongoing OOB store, in percent. + */ + uint8_t (*oob_progress_get)(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot); +#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ + /** @brief Slot delete callback. * * Called when the Firmware Distribution Server is about to delete a DFU image slot. @@ -129,12 +223,79 @@ struct bt_mesh_dfd_srv { struct { enum bt_mesh_dfd_upload_phase phase; - const struct bt_mesh_dfu_slot *slot; + struct bt_mesh_dfu_slot *slot; const struct flash_area *area; struct bt_mesh_blob_srv blob; +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + bool is_oob; + struct { + uint8_t uri_len; + uint8_t uri[CONFIG_BT_MESH_DFU_URI_MAXLEN]; + uint16_t current_fwid_len; + uint8_t current_fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; + struct bt_mesh_msg_ctx ctx; + } oob; +#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ } upload; + +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + struct { + const uint8_t *schemes; + const uint8_t count; + } oob_schemes; +#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ }; +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD +/** @brief Call when an OOB check has completed or failed + * + * This should be called by the application after an OOB check started by the @c start_oob_upload + * callback has completed or failed. The @p status param should be set to one of the following + * values: + * + * * @c BT_MESH_DFD_SUCCESS if the check was succesfull and a new firmware ID was found. + * * @c BT_MESH_DFD_ERR_URI_MALFORMED if the URI is not formatted correctly. + * * @c BT_MESH_DFD_ERR_URI_NOT_SUPPORTED if the URI scheme is not supported by the node. + * * @c BT_MESH_DFD_ERR_URI_UNREACHABLE if the URI can't be reached. + * * @c BT_MESH_DFD_ERR_NEW_FW_NOT_AVAILABLE if the check completes successfully but no new + * firmware is available. + * + * If this function returns 0, the application should then download the firmware to the + * slot. If an error code is returned, the application should abort the OOB upload. + * + * @param srv Firmware Distribution Server model instance. + * @param slot The slot used in the OOB upload. + * @param status The result of the firmware check. + * @param fwid If the check was successful and new firmware found, this should point to a + * buffer containing the new firmware ID to store. + * @param fwid_len The length of the firmware ID pointed to by @p fwid. + * + * @return 0 on success, (negative) error code otherwise. + */ +int bt_mesh_dfd_srv_oob_check_complete(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot, int status, + uint8_t *fwid, size_t fwid_len); + +/** @brief Call when an OOB store has completed or failed + * + * This should be called by the application after an OOB store started after a succesfull call to + * @c bt_mesh_dfd_srv_oob_check_complete has completed successfully or failed. + * + * @param srv Firmware Distribution Server model instance. + * @param slot The slot used when storing the firmware image. + * @param success @c true if the OOB store completed successfully, @c false otherwise. + * @param size The size of the stored firmware image, in bytes. + * @param metadata Pointer to the metadata received OOB, or @c NULL if no metadata was + * received. + * @param metadata_len Size of the metadata pointed to by @p metadata. + * + * @return 0 on success, (negative) error code otherwise. + */ +int bt_mesh_dfd_srv_oob_store_complete(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot, bool success, + size_t size, const uint8_t *metadata, size_t metadata_len); +#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ + /** @cond INTERNAL_HIDDEN */ extern const struct bt_mesh_model_op _bt_mesh_dfd_srv_op[]; extern const struct bt_mesh_model_cb _bt_mesh_dfd_srv_cb; diff --git a/include/zephyr/bluetooth/mesh/dfu.h b/include/zephyr/bluetooth/mesh/dfu.h index 91f36cdbaeb..4745355f039 100644 --- a/include/zephyr/bluetooth/mesh/dfu.h +++ b/include/zephyr/bluetooth/mesh/dfu.h @@ -34,6 +34,10 @@ extern "C" { #define CONFIG_BT_MESH_DFU_URI_MAXLEN 0 #endif +#ifndef CONFIG_BT_MESH_DFU_SLOT_CNT +#define CONFIG_BT_MESH_DFU_SLOT_CNT 0 +#endif + /** DFU transfer phase. */ enum bt_mesh_dfu_phase { /** Ready to start a Receive Firmware procedure. */ @@ -140,10 +144,7 @@ struct bt_mesh_dfu_img { /** Length of the firmware ID. */ size_t fwid_len; - /** Update URI, or NULL. - * - * Must use one of the http: or https: schemes. - */ + /** Update URI, or NULL. */ const char *uri; }; @@ -155,14 +156,10 @@ struct bt_mesh_dfu_slot { size_t fwid_len; /** Length of the metadata. */ size_t metadata_len; - /** Length of the image URI. */ - size_t uri_len; /** Firmware ID. */ uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; /** Metadata. */ uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN]; - /** Image URI. */ - char uri[CONFIG_BT_MESH_DFU_URI_MAXLEN]; }; /** @} */ diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index b8e26309a28..2dfc125b8fd 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1235,6 +1235,14 @@ config BT_MESH_DFD_SRV_TARGETS_MAX This value defines the maximum number of Target nodes the Firmware Distribution Server can target simultaneously. +config BT_MESH_DFD_SRV_OOB_UPLOAD + bool "Support for DFU image OOB upload" + help + This enables support for OOB upload of firmware images for + distribution. This makes several callbacks and use of the init + macro BT_MESH_DFD_SRV_INIT_OOB mandatory. See the API documentation + for bt_mesh_dfd_srv_cb for details about the mandatory callbacks. + endif config BT_MESH_RPR_SRV diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 2898ca39a39..54de343c94a 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -224,7 +224,20 @@ static int handle_capabilities_get(struct bt_mesh_model *mod, struct bt_mesh_msg size = MIN(size, CONFIG_BT_MESH_DFD_SRV_SLOT_SPACE); net_buf_simple_add_le32(&rsp, CONFIG_BT_MESH_DFD_SRV_SLOT_SPACE - size); - net_buf_simple_add_u8(&rsp, 0U); /* OOB retrieval not supported */ + +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + struct bt_mesh_dfd_srv *srv = mod->user_data; + + if (srv->oob_schemes.count > 0) { + net_buf_simple_add_u8(&rsp, 1); + net_buf_simple_add_mem(&rsp, srv->oob_schemes.schemes, + srv->oob_schemes.count); + } else +#else + { + net_buf_simple_add_u8(&rsp, 0); + } +#endif bt_mesh_model_send(mod, ctx, &rsp, NULL, NULL); @@ -346,10 +359,19 @@ static void upload_status_rsp(struct bt_mesh_dfd_srv *srv, return; } - net_buf_simple_add_u8(&rsp, - bt_mesh_blob_srv_progress(&srv->upload.blob)); - net_buf_simple_add_mem(&rsp, srv->upload.slot->fwid, - srv->upload.slot->fwid_len); +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + if (srv->upload.is_oob) { + net_buf_simple_add_u8(&rsp, + srv->cb->oob_progress_get(srv, srv->upload.slot) | BIT(7)); + net_buf_simple_add_mem(&rsp, srv->upload.oob.current_fwid, + srv->upload.oob.current_fwid_len); + } else +#endif + { + net_buf_simple_add_u8(&rsp, bt_mesh_blob_srv_progress(&srv->upload.blob)); + net_buf_simple_add_mem(&rsp, srv->upload.slot->fwid, + srv->upload.slot->fwid_len); + } bt_mesh_model_send(srv->mod, ctx, &rsp, NULL, NULL); } @@ -364,16 +386,42 @@ static int handle_upload_get(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx * return 0; } +static inline int set_upload_fwid(struct bt_mesh_dfd_srv *srv, struct bt_mesh_msg_ctx *ctx, + const uint8_t *fwid, size_t fwid_len) +{ + int err = bt_mesh_dfu_slot_fwid_set(srv->upload.slot, fwid, fwid_len); + + switch (err) { + case -EFBIG: /* Fwid too long */ + case -EALREADY: /* Other server is in progress with this fwid */ + bt_mesh_dfu_slot_release(srv->upload.slot); + upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); + break; + case -EEXIST: /* Img with this fwid already is in list */ + srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; + bt_mesh_dfu_slot_release(srv->upload.slot); + upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); + break; + case 0: + srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE; + break; + case -EINVAL: /* Slot in wrong state. */ + default: + break; + } + + return err; +} + static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { struct bt_mesh_dfd_srv *srv = mod->user_data; - const struct bt_mesh_dfu_slot *old_slot = srv->upload.slot; size_t meta_len, fwid_len, size; const uint8_t *meta, *fwid; uint16_t timeout_base; uint64_t blob_id; - int err, idx; + int err; uint8_t ttl; ttl = net_buf_simple_pull_u8(buf); @@ -392,9 +440,7 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx LOG_DBG("Upload Start: size: %d, fwid: %s, metadata: %s", size, bt_hex(fwid, fwid_len), bt_hex(meta, meta_len)); - if (size > CONFIG_BT_MESH_DFD_SRV_SLOT_MAX_SIZE || - fwid_len > CONFIG_BT_MESH_DFU_FWID_MAXLEN || - meta_len > CONFIG_BT_MESH_DFU_METADATA_MAXLEN) { + if (size > CONFIG_BT_MESH_DFD_SRV_SLOT_MAX_SIZE) { upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INSUFFICIENT_RESOURCES); return 0; @@ -413,7 +459,11 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx !memcmp(srv->upload.slot->metadata, meta, meta_len) && srv->upload.blob.state.xfer.id == blob_id && srv->upload.blob.state.ttl == ttl && - srv->upload.blob.state.timeout_base == timeout_base) { + srv->upload.blob.state.timeout_base == timeout_base +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + && !srv->upload.is_oob +#endif + ) { LOG_DBG("Duplicate upload start"); upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); return 0; @@ -424,23 +474,16 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx return 0; } - idx = bt_mesh_dfu_slot_get(fwid, fwid_len, &srv->upload.slot); - if (idx >= 0 && bt_mesh_dfu_slot_is_valid(srv->upload.slot)) { - LOG_DBG("Already received image"); - srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; - upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); - return 0; - } + /* This will be a no-op if the slot state isn't RESERVED, which is + * what we want. + */ + bt_mesh_dfu_slot_release(srv->upload.slot); - if (old_slot && !bt_mesh_dfu_slot_is_valid(old_slot)) { - LOG_DBG("Deleting old invalid slot"); - slot_del(srv, old_slot); - } +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + srv->upload.is_oob = false; +#endif + srv->upload.slot = bt_mesh_dfu_slot_reserve(); - /* TODO Store transfer state before slot is added. */ - - srv->upload.slot = bt_mesh_dfu_slot_add(size, fwid, fwid_len, meta, - meta_len, NULL, 0); if (!srv->upload.slot) { LOG_WRN("No space for slot"); upload_status_rsp(srv, ctx, @@ -448,11 +491,27 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx return 0; } + err = set_upload_fwid(srv, ctx, fwid, fwid_len); + if (err) { + return err; + } + + err = bt_mesh_dfu_slot_info_set(srv->upload.slot, size, meta, meta_len); + switch (err) { + case -EFBIG: + upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); + break; + case 0: + break; + default: + return err; + } + srv->io = NULL; err = srv->cb->recv(srv, srv->upload.slot, &srv->io); if (err || !srv->io) { LOG_ERR("App rejected upload. err: %d io: %p", err, srv->io); - slot_del(srv, srv->upload.slot); + bt_mesh_dfu_slot_release(srv->upload.slot); upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); return 0; } @@ -461,7 +520,7 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx timeout_base); if (err) { LOG_ERR("BLOB Server rejected upload (err: %d)", err); - slot_del(srv, srv->upload.slot); + bt_mesh_dfu_slot_release(srv->upload.slot); upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); return 0; } @@ -478,10 +537,71 @@ static int handle_upload_start_oob(struct bt_mesh_model *mod, struct bt_mesh_msg struct net_buf_simple *buf) { struct bt_mesh_dfd_srv *srv = mod->user_data; + uint8_t uri_len; + uint8_t *uri; + uint16_t fwid_len; + uint8_t *fwid; - LOG_DBG(""); + uri_len = net_buf_simple_pull_u8(buf); + + if (uri_len > buf->len) { + return -EINVAL; + } + + uri = net_buf_simple_pull_mem(buf, uri_len); + fwid_len = buf->len; + fwid = net_buf_simple_pull_mem(buf, fwid_len); + if (upload_is_busy(srv)) { +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + if (srv->upload.is_oob && + uri_len == srv->upload.oob.uri_len && + fwid_len == srv->upload.oob.current_fwid_len && + !memcmp(uri, srv->upload.oob.uri, uri_len) && + !memcmp(fwid, srv->upload.oob.current_fwid, fwid_len)) { + /* Same image, return SUCCESS for idempotency */ + upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); + return 0; + } +#endif + upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_BUSY_WITH_UPLOAD); + return 0; + } + +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + if (uri_len > CONFIG_BT_MESH_DFU_URI_MAXLEN || + fwid_len > CONFIG_BT_MESH_DFU_FWID_MAXLEN) { + upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); + return 0; + } + + struct bt_mesh_dfu_slot *slot = bt_mesh_dfu_slot_reserve(); + + if (slot == NULL) { + upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INSUFFICIENT_RESOURCES); + return 0; + } + + srv->upload.is_oob = true; + srv->upload.slot = slot; + memcpy(srv->upload.oob.uri, uri, uri_len); + srv->upload.oob.uri_len = uri_len; + memcpy(srv->upload.oob.current_fwid, fwid, fwid_len); + srv->upload.oob.current_fwid_len = fwid_len; + memcpy(&srv->upload.oob.ctx, ctx, sizeof(struct bt_mesh_msg_ctx)); + + int status = srv->cb->start_oob_upload(srv, srv->upload.slot, srv->upload.oob.uri, + srv->upload.oob.uri_len, + srv->upload.oob.current_fwid, + srv->upload.oob.current_fwid_len); + + if (status != BT_MESH_DFD_SUCCESS) { + upload_status_rsp(srv, ctx, status); + bt_mesh_dfu_slot_release(srv->upload.slot); + } +#else upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_URI_NOT_SUPPORTED); +#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ return 0; } @@ -492,7 +612,14 @@ static int handle_upload_cancel(struct bt_mesh_model *mod, struct bt_mesh_msg_ct struct bt_mesh_dfd_srv *srv = mod->user_data; srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_IDLE; - (void)bt_mesh_blob_srv_cancel(&srv->upload.blob); +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + if (srv->upload.is_oob) { + srv->cb->cancel_oob_upload(srv, srv->upload.slot); + } else +#endif + { + (void)bt_mesh_blob_srv_cancel(&srv->upload.blob); + } upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); return 0; @@ -508,7 +635,7 @@ static void fw_status_rsp(struct bt_mesh_dfd_srv *srv, bt_mesh_model_msg_init(&rsp, BT_MESH_DFD_OP_FW_STATUS); net_buf_simple_add_u8(&rsp, status); - net_buf_simple_add_le16(&rsp, bt_mesh_dfu_slot_foreach(NULL, NULL)); + net_buf_simple_add_le16(&rsp, bt_mesh_dfu_slot_count()); net_buf_simple_add_le16(&rsp, idx); if (fwid) { @@ -522,7 +649,7 @@ static int handle_fw_get(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { struct bt_mesh_dfd_srv *srv = mod->user_data; - const struct bt_mesh_dfu_slot *slot; + struct bt_mesh_dfu_slot *slot; const uint8_t *fwid; size_t fwid_len; int idx; @@ -531,7 +658,7 @@ static int handle_fw_get(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, fwid = net_buf_simple_pull_mem(buf, fwid_len); idx = bt_mesh_dfu_slot_get(fwid, fwid_len, &slot); - if (idx >= 0 && bt_mesh_dfu_slot_is_valid(slot)) { + if (idx >= 0) { fw_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS, idx, fwid, fwid_len); } else { @@ -552,7 +679,7 @@ static int handle_fw_get_by_index(struct bt_mesh_model *mod, struct bt_mesh_msg_ idx = net_buf_simple_pull_le16(buf); slot = bt_mesh_dfu_slot_at(idx); - if (slot && bt_mesh_dfu_slot_is_valid(slot)) { + if (slot) { fw_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS, idx, slot->fwid, slot->fwid_len); } else { @@ -729,8 +856,7 @@ static void upload_end(struct bt_mesh_blob_srv *b, uint64_t id, bool success) LOG_DBG("%u", success); - if (success) { - bt_mesh_dfu_slot_valid_set(srv->upload.slot, true); + if (success && (bt_mesh_dfu_slot_commit(srv->upload.slot) == 0)) { srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; return; } @@ -850,7 +976,7 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_start(struct bt_mesh_dfd_srv *srv, xfer.mode = params->xfer_mode; xfer.slot = bt_mesh_dfu_slot_at(params->slot_idx); - if (!xfer.slot || !bt_mesh_dfu_slot_is_valid(xfer.slot)) { + if (!xfer.slot) { return BT_MESH_DFD_ERR_FW_NOT_FOUND; } @@ -1013,7 +1139,7 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_apply(struct bt_mesh_dfd_srv *srv) enum bt_mesh_dfd_status bt_mesh_dfd_srv_fw_delete(struct bt_mesh_dfd_srv *srv, size_t *fwid_len, const uint8_t **fwid) { - const struct bt_mesh_dfu_slot *slot; + struct bt_mesh_dfu_slot *slot; int idx, err; if (srv->phase != BT_MESH_DFD_PHASE_IDLE) { @@ -1023,7 +1149,7 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_fw_delete(struct bt_mesh_dfd_srv *srv, s } idx = bt_mesh_dfu_slot_get(*fwid, *fwid_len, &slot); - if (idx < 0 || !bt_mesh_dfu_slot_is_valid(slot)) { + if (idx < 0) { return BT_MESH_DFD_SUCCESS; } @@ -1049,3 +1175,69 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_fw_delete_all(struct bt_mesh_dfd_srv *sr return BT_MESH_DFD_SUCCESS; } + +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD +int bt_mesh_dfd_srv_oob_check_complete(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot, int status, + uint8_t *fwid, size_t fwid_len) +{ + int err; + + if (slot != srv->upload.slot || !srv->upload.is_oob || + srv->upload.phase == BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE) { + /* This should not happen, unless the application calls the function with a + * "wrong" pointer or at a wrong time. + */ + return -EINVAL; + } + + if (status != BT_MESH_DFD_SUCCESS) { + bt_mesh_dfu_slot_release(srv->upload.slot); + upload_status_rsp(srv, &srv->upload.oob.ctx, status); + return -ECANCELED; + } + + err = set_upload_fwid(srv, &srv->upload.oob.ctx, fwid, fwid_len); + + if (err) { + return err; + } + + upload_status_rsp(srv, &srv->upload.oob.ctx, BT_MESH_DFD_SUCCESS); + return 0; +} + +int bt_mesh_dfd_srv_oob_store_complete(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot, bool success, + size_t size, const uint8_t *metadata, size_t metadata_len) +{ + int err = 0; + + if (srv->upload.phase != BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE || + srv->upload.slot != slot || !srv->upload.is_oob) { + return -EINVAL; + } + + if (!success) { + goto error; + } + + err = bt_mesh_dfu_slot_info_set(srv->upload.slot, size, metadata, metadata_len); + if (err) { + goto error; + } + + err = bt_mesh_dfu_slot_commit(srv->upload.slot); + if (err) { + goto error; + } + + srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; + return 0; + +error: + srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ERROR; + bt_mesh_dfu_slot_release(srv->upload.slot); + return err; +} +#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ diff --git a/subsys/bluetooth/mesh/dfu_slot.c b/subsys/bluetooth/mesh/dfu_slot.c index 16628793457..097d5abcc82 100644 --- a/subsys/bluetooth/mesh/dfu_slot.c +++ b/subsys/bluetooth/mesh/dfu_slot.c @@ -20,23 +20,22 @@ LOG_MODULE_REGISTER(bt_mesh_dfu_slot); #define DFU_SLOT_SETTINGS_PATH "bt/mesh-dfu/slot" -#define HEADER_SIZE offsetof(struct bt_mesh_dfu_slot, fwid) +#define HEADER_SIZE offsetof(struct slot, slot.fwid) #define PROP_HEADER "h" #define PROP_FWID "id" #define PROP_METADATA "m" -#define PROP_URI "u" -#define VALID_SLOTS_TAG "v" -#define SLOT_IN_ARRAY(_slot) PART_OF_ARRAY(slots, CONTAINER_OF(_slot, struct slot, slot)) - -static ATOMIC_DEFINE(valid_slots, CONFIG_BT_MESH_DFU_SLOT_CNT); static sys_slist_t list; + static struct slot { - sys_snode_t n; + uint32_t idx; struct bt_mesh_dfu_slot slot; + sys_snode_t n; } slots[CONFIG_BT_MESH_DFU_SLOT_CNT]; +static uint32_t slot_index; + static char *slot_entry_encode(uint16_t idx, char buf[SLOT_ENTRY_BUFLEN], const char *property) { @@ -46,32 +45,29 @@ static char *slot_entry_encode(uint16_t idx, char buf[SLOT_ENTRY_BUFLEN], return buf; } -static inline bool slot_in_use(const struct bt_mesh_dfu_slot *slot) +static bool slot_eq(const struct bt_mesh_dfu_slot *slot, + const uint8_t *fwid, size_t fwid_len) { - return slot->size > 0U; + return (slot->fwid_len == fwid_len) && + !memcmp(fwid, slot->fwid, fwid_len); } -static inline uint16_t slot_idx(const struct bt_mesh_dfu_slot *slot) +static bool is_slot_committed(struct slot *slot_to_check) { - return CONTAINER_OF(slot, struct slot, slot) - &slots[0]; -} + struct slot *s; -static inline void slot_invalidate(struct slot *slot_to_invalidate) -{ - slot_to_invalidate->slot.size = 0U; - atomic_clear_bit(valid_slots, slot_to_invalidate - &slots[0]); -} + SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { + if (s == slot_to_check) { + return true; + } + } -static bool slot_eq(const struct bt_mesh_dfu_slot *slot, - const uint8_t *fwid, size_t fwid_len) -{ - return (slot->fwid_len == fwid_len) && - !memcmp(fwid, slot->fwid, fwid_len); + return false; } static int slot_store(const struct slot *slot_to_store) { - uint16_t idx = slot_to_store - &slots[0]; + uint16_t idx = ARRAY_INDEX(slots, slot_to_store); char buf[SLOT_ENTRY_BUFLEN]; int err; @@ -90,55 +86,51 @@ static int slot_store(const struct slot *slot_to_store) err = settings_save_one(slot_entry_encode(idx, buf, PROP_METADATA), slot_to_store->slot.metadata, slot_to_store->slot.metadata_len); - if (err) { - return err; - } - return settings_save_one(slot_entry_encode(idx, buf, PROP_URI), - slot_to_store->slot.uri, slot_to_store->slot.uri_len); + return err; } static void slot_erase(struct slot *slot_to_erase) { - uint16_t idx = slot_to_erase - &slots[0]; + uint16_t idx = ARRAY_INDEX(slots, slot_to_erase); char buf[SLOT_ENTRY_BUFLEN]; settings_delete(slot_entry_encode(idx, buf, PROP_HEADER)); settings_delete(slot_entry_encode(idx, buf, PROP_FWID)); settings_delete(slot_entry_encode(idx, buf, PROP_METADATA)); - settings_delete(slot_entry_encode(idx, buf, PROP_URI)); } -static int valid_slots_store(void) +static void slot_index_defrag(void) { - return settings_save_one(DFU_SLOT_SETTINGS_PATH "/" VALID_SLOTS_TAG, - valid_slots, sizeof(valid_slots)); + slot_index = 0; + struct slot *s; + + SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { + s->idx = ++slot_index; + slot_store(s); + } } -const struct bt_mesh_dfu_slot * -bt_mesh_dfu_slot_add(size_t size, const uint8_t *fwid, - size_t fwid_len, const uint8_t *metadata, - size_t metadata_len, const char *uri, size_t uri_len) +int bt_mesh_dfu_slot_count(void) { - struct slot *slot = NULL; - int err, i; + int cnt = 0; + sys_snode_t *n; - if (size == 0 || fwid_len > CONFIG_BT_MESH_DFU_FWID_MAXLEN || - metadata_len > CONFIG_BT_MESH_DFU_METADATA_MAXLEN || - uri_len > CONFIG_BT_MESH_DFU_URI_MAXLEN) { - LOG_WRN("Param too large: (size: %d, fwid: %d, metadata: %d, uri: %d)", - size, fwid_len, metadata_len, uri_len); - return NULL; + SYS_SLIST_FOR_EACH_NODE(&list, n) { + cnt++; } - for (i = 0; i < ARRAY_SIZE(slots); ++i) { - if (!slot_in_use(&slots[i].slot)) { - slot = &slots[i]; - continue; - } + return cnt; +} - if (slot_eq(&slots[i].slot, fwid, fwid_len)) { - return &slots[i].slot; +struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_reserve(void) +{ + struct slot *slot = NULL; + + for (int i = 0; i < ARRAY_SIZE(slots); ++i) { + if (slots[i].idx == 0) { + slot = &slots[i]; + break; } } @@ -147,110 +139,136 @@ bt_mesh_dfu_slot_add(size_t size, const uint8_t *fwid, return NULL; } - slot->slot.fwid_len = fwid_len; - slot->slot.metadata_len = metadata_len; - slot->slot.uri_len = uri_len; - memcpy(slot->slot.fwid, fwid, fwid_len); - memcpy(slot->slot.metadata, metadata, metadata_len); - memcpy(slot->slot.uri, uri, uri_len); - slot->slot.size = size; - - err = slot_store(slot); - if (err) { - slot_invalidate(slot); - LOG_WRN("Store failed (err: %d)", err); - return NULL; + if (slot_index == UINT32_MAX) { + slot_index_defrag(); } - sys_slist_append(&list, &slot->n); + slot->slot.fwid_len = 0; + slot->slot.metadata_len = 0; + slot->slot.size = 0; + slot->idx = ++slot_index; + + LOG_DBG("Reserved slot #%u", slot - &slots[0]); - LOG_DBG("Added slot #%u: %s", slot - &slots[0], - bt_hex(slot->slot.fwid, slot->slot.fwid_len)); return &slot->slot; } -int bt_mesh_dfu_slot_valid_set(const struct bt_mesh_dfu_slot *slot, bool valid) +int bt_mesh_dfu_slot_info_set(struct bt_mesh_dfu_slot *dfu_slot, size_t size, + const uint8_t *metadata, size_t metadata_len) { - uint16_t idx; - bool prev; - int err; + struct slot *slot = CONTAINER_OF(dfu_slot, struct slot, slot); + + if (metadata_len > CONFIG_BT_MESH_DFU_METADATA_MAXLEN) { + return -EFBIG; + } - if (!SLOT_IN_ARRAY(slot) || !slot_in_use(slot)) { - return -ENOENT; + if (slot->idx == 0 || is_slot_committed(slot)) { + return -EINVAL; } - idx = slot_idx(slot); + slot->slot.size = size; + slot->slot.metadata_len = metadata_len; + memcpy(slot->slot.metadata, metadata, metadata_len); + return 0; +} + +int bt_mesh_dfu_slot_fwid_set(struct bt_mesh_dfu_slot *dfu_slot, + const uint8_t *fwid, size_t fwid_len) +{ + struct slot *slot = CONTAINER_OF(dfu_slot, struct slot, slot); - LOG_DBG("%u: %u", idx, valid); + if (fwid_len > CONFIG_BT_MESH_DFU_FWID_MAXLEN) { + return -EFBIG; + } - if (valid) { - prev = atomic_test_and_set_bit(valid_slots, idx); - } else { - prev = atomic_test_and_clear_bit(valid_slots, idx); + if (slot->idx == 0 || is_slot_committed(slot)) { + return -EINVAL; } - if (valid == prev) { - return 0; + for (int i = 0; i < ARRAY_SIZE(slots); i++) { + if (slots[i].idx != 0 && + slot_eq(&slots[i].slot, fwid, fwid_len)) { + return is_slot_committed(&slots[i]) ? + -EEXIST : -EALREADY; + } + } + + slot->slot.fwid_len = fwid_len; + memcpy(slot->slot.fwid, fwid, fwid_len); + return 0; +} + +int bt_mesh_dfu_slot_commit(struct bt_mesh_dfu_slot *dfu_slot) +{ + int err; + struct slot *slot = CONTAINER_OF(dfu_slot, struct slot, slot); + + if (slot->idx == 0 || + slot->slot.fwid_len == 0 || + slot->slot.size == 0 || + is_slot_committed(slot)) { + return -EINVAL; } - err = valid_slots_store(); + err = slot_store(slot); if (err) { - LOG_WRN("Storage failed. err: %d", err); - atomic_set_bit_to(valid_slots, idx, prev); + LOG_WRN("Store failed (err: %d)", err); + return err; } - return err; + sys_slist_append(&list, &slot->n); + + LOG_DBG("Stored slot #%u: %s", ARRAY_INDEX(slots, slot), + bt_hex(slot->slot.fwid, slot->slot.fwid_len)); + return 0; } -bool bt_mesh_dfu_slot_is_valid(const struct bt_mesh_dfu_slot *slot) +void bt_mesh_dfu_slot_release(const struct bt_mesh_dfu_slot *dfu_slot) { - uint16_t idx; + struct slot *slot = CONTAINER_OF(dfu_slot, struct slot, slot); - if (!SLOT_IN_ARRAY(slot) || !slot_in_use(slot)) { - return false; + if (is_slot_committed(slot)) { + return; } - idx = slot_idx(slot); - return atomic_test_bit(valid_slots, idx); + slot->idx = 0; } -int bt_mesh_dfu_slot_del(const struct bt_mesh_dfu_slot *slot) +int bt_mesh_dfu_slot_del(const struct bt_mesh_dfu_slot *dfu_slot) { - struct slot *s = CONTAINER_OF(slot, struct slot, slot); + struct slot *slot = CONTAINER_OF(dfu_slot, struct slot, slot); - if (!SLOT_IN_ARRAY(slot) || !slot_in_use(slot)) { - return -ENOENT; + if (!sys_slist_find_and_remove(&list, &slot->n)) { + return -EINVAL; } - LOG_DBG("%u", s - &slots[0]); + int idx = ARRAY_INDEX(slots, slot); - slot_erase(s); - slot_invalidate(s); - sys_slist_find_and_remove(&list, &s->n); + LOG_DBG("%u", idx); + + slot_erase(slot); + slot->idx = 0; return 0; } -int bt_mesh_dfu_slot_del_all(void) +void bt_mesh_dfu_slot_del_all(void) { struct slot *s; - SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { slot_erase(s); - slot_invalidate(s); + s->idx = 0; } sys_slist_init(&list); - - return 0; } -const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t idx) +const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t img_idx) { struct slot *s; SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { - if (!idx--) { + if (!img_idx--) { return &s->slot; } } @@ -258,34 +276,33 @@ const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t idx) return NULL; } -int bt_mesh_dfu_slot_get(const uint8_t *fwid, size_t fwid_len, - const struct bt_mesh_dfu_slot **slot) +int bt_mesh_dfu_slot_get(const uint8_t *fwid, size_t fwid_len, struct bt_mesh_dfu_slot **slot) { struct slot *s; int idx = 0; SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { if (slot_eq(&s->slot, fwid, fwid_len)) { - *slot = &s->slot; + if (slot) { + *slot = &s->slot; + } return idx; } - idx++; } return -ENOENT; } -int bt_mesh_dfu_slot_idx_get(const struct bt_mesh_dfu_slot *slot) +int bt_mesh_dfu_slot_img_idx_get(const struct bt_mesh_dfu_slot *dfu_slot) { struct slot *s; int idx = 0; SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { - if (&s->slot == slot) { + if (&s->slot == dfu_slot) { return idx; } - idx++; } @@ -295,11 +312,12 @@ int bt_mesh_dfu_slot_idx_get(const struct bt_mesh_dfu_slot *slot) size_t bt_mesh_dfu_slot_foreach(bt_mesh_dfu_slot_cb_t cb, void *user_data) { enum bt_mesh_dfu_iter iter; - struct slot *s; size_t cnt = 0; + struct slot *s; SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { cnt++; + if (!cb) { continue; } @@ -320,15 +338,6 @@ static int slot_data_load(const char *key, size_t len_rd, size_t len; uint16_t idx; - if (!strncmp(key, VALID_SLOTS_TAG, 1)) { - if (read_cb(cb_arg, valid_slots, - MIN(sizeof(valid_slots), len_rd)) < 0) { - return -EINVAL; - } - - return 0; - } - idx = strtol(key, NULL, 16); if (idx >= ARRAY_SIZE(slots)) { @@ -339,16 +348,34 @@ static int slot_data_load(const char *key, size_t len_rd, if (!strncmp(prop, PROP_HEADER, len)) { if (read_cb(cb_arg, &slots[idx], HEADER_SIZE) > 0) { - sys_slist_append(&list, &slots[idx].n); - } + struct slot *s, *prev = NULL; + + SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { + if (s->idx > slots[idx].idx) { + break; + } + + prev = s; + } + if (prev == NULL) { + sys_slist_prepend(&list, &slots[idx].n); + } else { + sys_slist_insert(&list, &prev->n, &slots[idx].n); + } + + if (slots[idx].idx >= slot_index) { + slot_index = slots[idx].idx + 1; + } + } return 0; } if (!strncmp(prop, PROP_FWID, len)) { if (read_cb(cb_arg, &slots[idx].slot.fwid, sizeof(slots[idx].slot.fwid)) < 0) { - slot_invalidate(&slots[idx]); + slots[idx].idx = 0; + sys_slist_find_and_remove(&list, &slots[idx].n); return 0; } @@ -359,7 +386,8 @@ static int slot_data_load(const char *key, size_t len_rd, if (!strncmp(prop, PROP_METADATA, len)) { if (read_cb(cb_arg, &slots[idx].slot.metadata, sizeof(slots[idx].slot.metadata)) < 0) { - slot_invalidate(&slots[idx]); + slots[idx].idx = 0; + sys_slist_find_and_remove(&list, &slots[idx].n); return 0; } @@ -367,16 +395,6 @@ static int slot_data_load(const char *key, size_t len_rd, return 0; } - if (!strncmp(prop, PROP_URI, len)) { - if (read_cb(cb_arg, &slots[idx].slot.uri, - sizeof(slots[idx].slot.uri)) < 0) { - slot_invalidate(&slots[idx]); - return 0; - } - - slots[idx].slot.uri_len = len_rd; - } - return 0; } diff --git a/subsys/bluetooth/mesh/dfu_slot.h b/subsys/bluetooth/mesh/dfu_slot.h index 1bc58f64de9..969c6d3d25b 100644 --- a/subsys/bluetooth/mesh/dfu_slot.h +++ b/subsys/bluetooth/mesh/dfu_slot.h @@ -16,50 +16,69 @@ typedef enum bt_mesh_dfu_iter (*bt_mesh_dfu_slot_cb_t)( const struct bt_mesh_dfu_slot *slot, void *user_data); -/** @brief Register a new DFU image slot for a distributable image. +/** @brief Get the number of slots committed to the firmware list. + * + * @return Number of committed slots. + */ +int bt_mesh_dfu_slot_count(void); + +/** @brief Reserve a new DFU image slot for a distributable image. * * A DFU image slot represents a single distributable DFU image with all its - * metadata. + * metadata. The slot data must be set using @ref bt_mesh_dfu_slot_info_set and + * @ref bt_mesh_dfu_slot_fwid_set, and the slot committed using + * @ref bt_mesh_dfu_slot_commit for the slot to be considered part of the slot + * list. * - * @note The slot is allocated as invalid. Call - * @ref bt_mesh_dfu_slot_valid_set to make it valid. + * @return A pointer to the reserved slot, or NULL if allocation failed. + */ +struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_reserve(void); + +/** @brief Set the size and metadata for a reserved slot. * - * @param size Size of the image in bytes. - * @param fwid Firmware ID. - * @param fwid_len Length of the firmware ID, at most @c - * CONFIG_BT_MESH_DFU_FWID_MAXLEN. + * @param dfu_slot Pointer to the reserved slot for which to set the + * metadata. + * @param size The size of the image. * @param metadata Metadata or NULL. * @param metadata_len Length of the metadata, at most @c * CONFIG_BT_MESH_DFU_METADATA_MAXLEN. - * @param uri Image URI or NULL. - * @param uri_len Length of the image URI, at most @c - * CONFIG_BT_MESH_DFU_URI_MAXLEN. * - * @return A pointer to the allocated slot, or NULL if allocation failed. + * @return 0 on success, (negative) error code otherwise. */ -const struct bt_mesh_dfu_slot * -bt_mesh_dfu_slot_add(size_t size, const uint8_t *fwid, size_t fwid_len, - const uint8_t *metadata, size_t metadata_len, - const char *uri, size_t uri_len); +int bt_mesh_dfu_slot_info_set(struct bt_mesh_dfu_slot *dfu_slot, size_t size, + const uint8_t *metadata, size_t metadata_len); -/** @brief Set whether the given slot is valid. +/** @brief Set the new fwid for the incoming image for a reserved slot. * - * @param slot Allocated DFU image slot. - * @param valid New valid state of the slot. + * @param dfu_slot Pointer to the reserved slot for which to set the fwid. + * @param fwid Fwid to set. + * @param fwid_len Length of the fwid, at most @c + * CONFIG_BT_MESH_DFU_FWID_MAXLEN. * - * @return 0 on success, or (negative) error code on failure. + * @return 0 on success, (negative) error code otherwise. */ -int bt_mesh_dfu_slot_valid_set(const struct bt_mesh_dfu_slot *slot, bool valid); +int bt_mesh_dfu_slot_fwid_set(struct bt_mesh_dfu_slot *dfu_slot, + const uint8_t *fwid, size_t fwid_len); -/** @brief Check whether a slot is valid. +/** @brief Commit the reserved slot to the list of slots, and store it + * persistently. + * + * If the commit fails for any reason, the slot will still be in the reserved + * state after this call. + * + * @param dfu_slot Pointer to the reserved slot. * - * @param slot Slot to check. + * @return 0 on success, (negative) error code otherwise. + */ +int bt_mesh_dfu_slot_commit(struct bt_mesh_dfu_slot *dfu_slot); + +/** @brief Release a reserved slot so that it can be reserved again. * - * @return true if the slot is valid, false otherwise. + * @param dfu_slot Pointer to the reserved slot. */ -bool bt_mesh_dfu_slot_is_valid(const struct bt_mesh_dfu_slot *slot); +void bt_mesh_dfu_slot_release(const struct bt_mesh_dfu_slot *dfu_slot); -/** @brief Delete an allocated DFU image slot. +/** @brief Delete a committed DFU image slot. * * @param slot Slot to delete. Must be a valid pointer acquired from this * module. @@ -72,18 +91,19 @@ int bt_mesh_dfu_slot_del(const struct bt_mesh_dfu_slot *slot); * * @return 0 on success, or (negative) error code on failure. */ -int bt_mesh_dfu_slot_del_all(void); +void bt_mesh_dfu_slot_del_all(void); -/** @brief Get the DFU image slot at the given index. +/** @brief Get the DFU image slot at the given firmware image list index. * * @param idx DFU image slot index. * * @return The DFU image slot at the given index, or NULL if no slot exists with the * given index. */ -const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t idx); +const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t img_idx); -/** @brief Get the DFU image slot for the image with the given firmware ID. +/** @brief Get the committed DFU image slot for the image with the given + * firmware ID. * * @param fwid Firmware ID. * @param fwid_len Firmware ID length. @@ -91,16 +111,15 @@ const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t idx); * * @return Slot index on success, or negative error code on failure. */ -int bt_mesh_dfu_slot_get(const uint8_t *fwid, size_t fwid_len, - const struct bt_mesh_dfu_slot **slot); +int bt_mesh_dfu_slot_get(const uint8_t *fwid, size_t fwid_len, struct bt_mesh_dfu_slot **slot); -/** @brief Get the DFU image slot index of the given slot. +/** @brief Get the index in the firmware image list for the given slot. * * @param slot Slot to find. * * @return Slot index on success, or negative error code on failure. */ -int bt_mesh_dfu_slot_idx_get(const struct bt_mesh_dfu_slot *slot); +int bt_mesh_dfu_slot_img_idx_get(const struct bt_mesh_dfu_slot *slot); /** @brief Iterate through all DFU image slots. * diff --git a/subsys/bluetooth/mesh/shell/dfd.c b/subsys/bluetooth/mesh/shell/dfd.c index 94d656f3689..b7daf42af1c 100644 --- a/subsys/bluetooth/mesh/shell/dfd.c +++ b/subsys/bluetooth/mesh/shell/dfd.c @@ -43,7 +43,7 @@ static void print_fw_status(const struct shell *sh, enum bt_mesh_dfd_status stat uint16_t idx, const uint8_t *fwid, size_t fwid_len) { shell_fprintf(sh, SHELL_NORMAL, "{ \"status\": %d, \"slot_cnt\": %d, \"idx\": %d", - status, bt_mesh_dfu_slot_foreach(NULL, NULL), idx); + status, bt_mesh_dfu_slot_count(), idx); if (fwid) { shell_fprintf(sh, SHELL_NORMAL, ", \"fwid\": \""); for (size_t i = 0; i < fwid_len; i++) { @@ -325,10 +325,9 @@ static int cmd_dfd_fw_get(const struct shell *sh, size_t argc, char *argv[]) return -EINVAL; } - const struct bt_mesh_dfu_slot *slot; - int idx = bt_mesh_dfu_slot_get(fwid, fwid_len, &slot); + int idx = bt_mesh_dfu_slot_get(fwid, fwid_len, NULL); - if (idx >= 0 && bt_mesh_dfu_slot_is_valid(slot)) { + if (idx >= 0) { print_fw_status(sh, BT_MESH_DFD_SUCCESS, idx, fwid, fwid_len); } else { print_fw_status(sh, BT_MESH_DFD_ERR_FW_NOT_FOUND, 0xffff, fwid, fwid_len); @@ -349,7 +348,7 @@ static int cmd_dfd_fw_get_by_idx(const struct shell *sh, size_t argc, char *argv return err; } - if (slot && bt_mesh_dfu_slot_is_valid(slot)) { + if (slot) { print_fw_status(sh, BT_MESH_DFD_SUCCESS, idx, slot->fwid, slot->fwid_len); } else { print_fw_status(sh, BT_MESH_DFD_ERR_FW_NOT_FOUND, idx, NULL, 0); diff --git a/subsys/bluetooth/mesh/shell/dfu.c b/subsys/bluetooth/mesh/shell/dfu.c index 71d27b158e4..8d7fc96e014 100644 --- a/subsys/bluetooth/mesh/shell/dfu.c +++ b/subsys/bluetooth/mesh/shell/dfu.c @@ -375,13 +375,12 @@ static int cmd_dfu_metadata_encode(const struct shell *sh, size_t argc, char *ar static int cmd_dfu_slot_add(const struct shell *sh, size_t argc, char *argv[]) { - const struct bt_mesh_dfu_slot *slot; + struct bt_mesh_dfu_slot *slot; size_t size; uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; size_t fwid_len = 0; uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN]; size_t metadata_len = 0; - const char *uri = ""; int err = 0; size = shell_strtoul(argv[1], 0, &err); @@ -390,32 +389,33 @@ static int cmd_dfu_slot_add(const struct shell *sh, size_t argc, char *argv[]) return err; } - if (argc > 2) { - fwid_len = hex2bin(argv[2], strlen(argv[2]), fwid, - sizeof(fwid)); + shell_print(sh, "Adding slot (size: %u)", size); + slot = bt_mesh_dfu_slot_reserve(); + + if (!slot) { + shell_print(sh, "Failed to reserve slot."); + return 0; } + fwid_len = hex2bin(argv[2], strlen(argv[2]), fwid, + sizeof(fwid)); + bt_mesh_dfu_slot_fwid_set(slot, fwid, fwid_len); + if (argc > 3) { metadata_len = hex2bin(argv[3], strlen(argv[3]), metadata, sizeof(metadata)); } - if (argc > 4) { - uri = argv[4]; - } + bt_mesh_dfu_slot_info_set(slot, size, metadata, metadata_len); - shell_print(sh, "Adding slot (size: %u)", size); - - slot = bt_mesh_dfu_slot_add(size, fwid, fwid_len, metadata, - metadata_len, uri, strlen(uri)); - if (!slot) { - shell_print(sh, "Failed."); - return 0; + err = bt_mesh_dfu_slot_commit(slot); + if (err) { + shell_print(sh, "Failed to commit slot: %d", err); + bt_mesh_dfu_slot_release(slot); + return err; } - bt_mesh_dfu_slot_valid_set(slot, true); - - shell_print(sh, "Slot added. ID: %u", bt_mesh_dfu_slot_idx_get(slot)); + shell_print(sh, "Slot added. Index: %u", bt_mesh_dfu_slot_img_idx_get(slot)); return 0; } @@ -451,14 +451,7 @@ static int cmd_dfu_slot_del(const struct shell *sh, size_t argc, char *argv[]) static int cmd_dfu_slot_del_all(const struct shell *sh, size_t argc, char *argv[]) { - int err; - - err = bt_mesh_dfu_slot_del_all(); - if (err) { - shell_print(sh, "Failed deleting all slots (err: %d)", err); - return 0; - } - + bt_mesh_dfu_slot_del_all(); shell_print(sh, "All slots deleted."); return 0; } @@ -468,7 +461,6 @@ static void slot_info_print(const struct shell *sh, const struct bt_mesh_dfu_slo { char fwid[2 * CONFIG_BT_MESH_DFU_FWID_MAXLEN + 1]; char metadata[2 * CONFIG_BT_MESH_DFU_METADATA_MAXLEN + 1]; - char uri[CONFIG_BT_MESH_DFU_URI_MAXLEN + 1]; size_t len; len = bin2hex(slot->fwid, slot->fwid_len, fwid, sizeof(fwid)); @@ -476,8 +468,6 @@ static void slot_info_print(const struct shell *sh, const struct bt_mesh_dfu_slo len = bin2hex(slot->metadata, slot->metadata_len, metadata, sizeof(metadata)); metadata[len] = '\0'; - memcpy(uri, slot->uri, slot->uri_len); - uri[slot->uri_len] = '\0'; if (idx != NULL) { shell_print(sh, "Slot %u:", *idx); @@ -487,7 +477,6 @@ static void slot_info_print(const struct shell *sh, const struct bt_mesh_dfu_slo shell_print(sh, "\tSize: %u bytes", slot->size); shell_print(sh, "\tFWID: %s", fwid); shell_print(sh, "\tMetadata: %s", metadata); - shell_print(sh, "\tURI: %s", uri); } static int cmd_dfu_slot_get(const struct shell *sh, size_t argc, char *argv[]) @@ -970,8 +959,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_STATIC_SUBCMD_SET_CREATE( dfu_slot_cmds, SHELL_CMD_ARG(add, NULL, - " [ [ []]]", - cmd_dfu_slot_add, 2, 3), + " []", + cmd_dfu_slot_add, 3, 1), SHELL_CMD_ARG(del, NULL, "", cmd_dfu_slot_del, 2, 0), SHELL_CMD_ARG(del-all, NULL, NULL, cmd_dfu_slot_del_all, 1, 0), SHELL_CMD_ARG(get, NULL, "", cmd_dfu_slot_get, 2, 0), diff --git a/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf b/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf index e870e190481..2e08329b7ef 100644 --- a/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf +++ b/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf @@ -58,7 +58,8 @@ CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y CONFIG_BT_MESH_DFU_SRV=y CONFIG_BT_MESH_DFU_CLI=y CONFIG_BT_MESH_DFD_SRV=y -CONFIG_BT_MESH_DFU_SLOT_CNT=3 +CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD=y +CONFIG_BT_MESH_DFU_SLOT_CNT=4 CONFIG_BT_MESH_PRIV_BEACON_SRV=y CONFIG_BT_MESH_PRIV_BEACON_CLI=y CONFIG_BT_MESH_COMP_PAGE_1=y diff --git a/tests/bsim/bluetooth/mesh/src/test_dfu.c b/tests/bsim/bluetooth/mesh/src/test_dfu.c index f7c4ca6f4f0..a235e86eeec 100644 --- a/tests/bsim/bluetooth/mesh/src/test_dfu.c +++ b/tests/bsim/bluetooth/mesh/src/test_dfu.c @@ -434,25 +434,50 @@ static void target_prov_and_conf_default(void) target_prov_and_conf(addr, bind_params, ARRAY_SIZE(bind_params)); } +static struct bt_mesh_dfu_slot *slot_reserve_and_set(size_t size, uint8_t *fwid, size_t fwid_len, + uint8_t *metadata, size_t metadata_len) +{ + struct bt_mesh_dfu_slot *new_slot = bt_mesh_dfu_slot_reserve(); + + if (!new_slot) { + LOG_WRN("Reserving slot failed"); + return NULL; + } + + int err = bt_mesh_dfu_slot_fwid_set(new_slot, fwid, fwid_len); + + if (err) { + return NULL; + } + + err = bt_mesh_dfu_slot_info_set(new_slot, size, metadata, metadata_len); + + if (err) { + return NULL; + } + + return new_slot; +} + static bool slot_add(const struct bt_mesh_dfu_slot **slot) { - const struct bt_mesh_dfu_slot *new_slot; + struct bt_mesh_dfu_slot *new_slot; size_t size = 100; uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0xAA, 0xBB, 0xCC, 0xDD }; size_t fwid_len = 4; uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0xAA, 0xBB, 0xCC, 0xDD }; size_t metadata_len = 4; - const char *uri = ""; ASSERT_EQUAL(sizeof(target_fw_ver_new), fwid_len); - new_slot = bt_mesh_dfu_slot_add(size, fwid, fwid_len, metadata, metadata_len, uri, - strlen(uri)); + new_slot = slot_reserve_and_set(size, fwid, fwid_len, metadata, metadata_len); if (!new_slot) { return false; } - bt_mesh_dfu_slot_valid_set(new_slot, true); + if (bt_mesh_dfu_slot_commit(new_slot) != 0) { + return false; + } if (slot) { *slot = new_slot; @@ -568,13 +593,12 @@ static void test_dist_dfu_self_update(void) static void test_dist_dfu_slot_create(void) { - const struct bt_mesh_dfu_slot *slot[3]; + struct bt_mesh_dfu_slot *slot[CONFIG_BT_MESH_DFU_SLOT_CNT]; size_t size = 100; uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0 }; size_t fwid_len = 4; uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0 }; size_t metadata_len = 4; - const char *uri = "test"; int err, i; ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3, @@ -584,36 +608,26 @@ static void test_dist_dfu_slot_create(void) bt_mesh_device_setup(&prov, &dist_comp); dist_prov_and_conf(DIST_ADDR); - for (i = CONFIG_BT_MESH_DFU_SLOT_CNT - 1; i >= 0; i--) { + for (i = 0; i < CONFIG_BT_MESH_DFU_SLOT_CNT; i++) { fwid[0] = i; metadata[0] = i; - slot[i] = bt_mesh_dfu_slot_add(size, fwid, fwid_len, metadata, metadata_len, uri, - strlen(uri)); + slot[i] = slot_reserve_and_set(size, fwid, fwid_len, metadata, metadata_len); ASSERT_FALSE(slot[i] == NULL, "Failed to add slot"); - } - - /* First slot is set as valid */ - err = bt_mesh_dfu_slot_valid_set(slot[0], true); - if (err) { - FAIL("Setting slot to valid state failed (err %d)", err); - return; - } - ASSERT_TRUE(bt_mesh_dfu_slot_is_valid(slot[0])); - /* Second slot is set as invalid */ - err = bt_mesh_dfu_slot_valid_set(slot[1], false); - if (err) { - FAIL("Setting slot to invalid state failed (err %d)", err); - return; + if (i > 0) { + /* All but first slot are committed */ + err = bt_mesh_dfu_slot_commit(slot[i]); + if (err) { + FAIL("Committing slot failed (err %d)", err); + } + } } - ASSERT_TRUE(!bt_mesh_dfu_slot_is_valid(slot[1])); - /* Last slot is deleted */ - err = bt_mesh_dfu_slot_del(slot[CONFIG_BT_MESH_DFU_SLOT_CNT - 1]); + /* Second slot is deleted */ + err = bt_mesh_dfu_slot_del(slot[1]); if (err) { FAIL("Slot delete failed (err %d)", err); - return; } PASS(); @@ -626,20 +640,17 @@ enum bt_mesh_dfu_iter check_slot(const struct bt_mesh_dfu_slot *slot, void *data size_t fwid_len = 4; uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0 }; size_t metadata_len = 4; - const char *uri = "test"; - int idx = bt_mesh_dfu_slot_idx_get(slot); - - ASSERT_TRUE(idx >= 0, "Failed to retrieve slot index"); + int idx = bt_mesh_dfu_slot_img_idx_get(slot); + int *i = data; + ASSERT_EQUAL(idx, (*i)++); ASSERT_EQUAL(size, slot->size); - ASSERT_TRUE(strcmp(uri, slot->uri) == 0); - - fwid[0] = idx; + fwid[0] = idx + 2; ASSERT_EQUAL(fwid_len, slot->fwid_len); ASSERT_TRUE(memcmp(fwid, slot->fwid, fwid_len) == 0); - metadata[0] = idx; + metadata[0] = idx + 2; ASSERT_EQUAL(metadata_len, slot->metadata_len); ASSERT_TRUE(memcmp(metadata, slot->metadata, metadata_len) == 0); @@ -649,13 +660,12 @@ enum bt_mesh_dfu_iter check_slot(const struct bt_mesh_dfu_slot *slot, void *data static void test_dist_dfu_slot_create_recover(void) { size_t slot_count; - const struct bt_mesh_dfu_slot *slot; + struct bt_mesh_dfu_slot *slot; size_t size = 100; uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0 }; size_t fwid_len = 4; uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0 }; size_t metadata_len = 4; - const char *uri = "test"; int i, idx; ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3, @@ -664,26 +674,17 @@ static void test_dist_dfu_slot_create_recover(void) bt_mesh_test_cfg_set(NULL, WAIT_TIME); bt_mesh_device_setup(&prov, &dist_comp); - slot_count = bt_mesh_dfu_slot_foreach(check_slot, NULL); - ASSERT_EQUAL(CONFIG_BT_MESH_DFU_SLOT_CNT - 1, slot_count); - - slot = bt_mesh_dfu_slot_at(0); - ASSERT_EQUAL(true, bt_mesh_dfu_slot_is_valid(slot)); + i = 0; + slot_count = bt_mesh_dfu_slot_foreach(check_slot, &i); + ASSERT_EQUAL(CONFIG_BT_MESH_DFU_SLOT_CNT - 2, slot_count); - slot = bt_mesh_dfu_slot_at(1); - ASSERT_TRUE(slot != NULL); - ASSERT_EQUAL(false, bt_mesh_dfu_slot_is_valid(slot)); - - for (i = 0; i < (CONFIG_BT_MESH_DFU_SLOT_CNT - 1); i++) { + for (i = 2; i < CONFIG_BT_MESH_DFU_SLOT_CNT; i++) { fwid[0] = i; idx = bt_mesh_dfu_slot_get(fwid, fwid_len, &slot); - ASSERT_TRUE(idx >= 0); - ASSERT_EQUAL(idx, bt_mesh_dfu_slot_idx_get(slot)); - + ASSERT_EQUAL(idx, i - 2); ASSERT_EQUAL(size, slot->size); - ASSERT_TRUE(strcmp(uri, slot->uri) == 0); - metadata[0] = idx; + metadata[0] = i; ASSERT_EQUAL(metadata_len, slot->metadata_len); ASSERT_TRUE(memcmp(metadata, slot->metadata, metadata_len) == 0); } @@ -693,7 +694,7 @@ static void test_dist_dfu_slot_create_recover(void) static void check_delete_all(void) { - int i, idx, err; + int i; const struct bt_mesh_dfu_slot *slot; size_t slot_count; @@ -706,14 +707,6 @@ static void check_delete_all(void) for (i = 0; i < CONFIG_BT_MESH_DFU_SLOT_CNT - 1; i++) { slot = bt_mesh_dfu_slot_at(i); ASSERT_TRUE(slot == NULL); - - idx = bt_mesh_dfu_slot_idx_get(slot); - ASSERT_TRUE(idx < 0); - - err = bt_mesh_dfu_slot_valid_set(slot, true); - ASSERT_EQUAL(err, -ENOENT); - - ASSERT_TRUE(!bt_mesh_dfu_slot_is_valid(slot)); } } @@ -726,7 +719,6 @@ static void test_dist_dfu_slot_delete_all(void) bt_mesh_device_setup(&prov, &dist_comp); bt_mesh_dfu_slot_del_all(); - check_delete_all(); PASS(); @@ -742,6 +734,63 @@ static void test_dist_dfu_slot_check_delete_all(void) PASS(); } +static void test_dist_dfu_slot_reservation(void) +{ + int i; + struct bt_mesh_dfu_slot *slots[CONFIG_BT_MESH_DFU_SLOT_CNT]; + + bt_mesh_test_cfg_set(NULL, WAIT_TIME); + bt_mesh_device_setup(&prov, &dist_comp); + + for (i = 0; i < CONFIG_BT_MESH_DFU_SLOT_CNT; i++) { + slots[i] = bt_mesh_dfu_slot_reserve(); + ASSERT_TRUE(slots[i] != NULL); + } + + ASSERT_EQUAL(NULL, bt_mesh_dfu_slot_reserve()); + bt_mesh_dfu_slot_release(slots[0]); + /* Release twice to check idempotency with empty pool */ + bt_mesh_dfu_slot_release(slots[0]); + ASSERT_TRUE(bt_mesh_dfu_slot_reserve() != NULL); + ASSERT_EQUAL(NULL, bt_mesh_dfu_slot_reserve()); + + PASS(); +} + +static void test_dist_dfu_slot_idempotency(void) +{ + uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0 }; + size_t fwid_len = 4; + struct bt_mesh_dfu_slot *slot; + + ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 1, + "CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 1"); + + bt_mesh_test_cfg_set(NULL, WAIT_TIME); + bt_mesh_device_setup(&prov, &dist_comp); + dist_prov_and_conf(DIST_ADDR); + + slot = bt_mesh_dfu_slot_reserve(); + ASSERT_TRUE(slot != NULL); + + bt_mesh_dfu_slot_release(slot); + bt_mesh_dfu_slot_release(slot); + + slot = bt_mesh_dfu_slot_reserve(); + ASSERT_TRUE(slot != NULL); + + ASSERT_EQUAL(0, bt_mesh_dfu_slot_fwid_set(slot, fwid, fwid_len)); + ASSERT_EQUAL(0, bt_mesh_dfu_slot_info_set(slot, 100, NULL, 0)); + + ASSERT_EQUAL(0, bt_mesh_dfu_slot_commit(slot)); + ASSERT_EQUAL(-EINVAL, bt_mesh_dfu_slot_commit(slot)); + + ASSERT_EQUAL(0, bt_mesh_dfu_slot_del(slot)); + ASSERT_EQUAL(-EINVAL, bt_mesh_dfu_slot_del(slot)); + + PASS(); +} + static void target_test_effect(enum bt_mesh_dfu_effect effect) { dfu_target_effect = effect; @@ -921,12 +970,14 @@ static void cli_common_fail_on_init(void) static void cli_common_init_recover(void) { - const struct bt_mesh_dfu_slot *slot; + struct bt_mesh_dfu_slot *slot; + uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0xAA, 0xBB, 0xCC, 0xDD }; + size_t fwid_len = 4; bt_mesh_test_cfg_set(NULL, 300); bt_mesh_device_setup(&prov, &cli_comp); - ASSERT_TRUE(slot_add(&slot)); + ASSERT_TRUE(bt_mesh_dfu_slot_get(fwid, fwid_len, &slot) >= 0); dfu_cli_inputs_prepare(0); dfu_cli_xfer.xfer.mode = BT_MESH_BLOB_XFER_MODE_PUSH; @@ -1595,6 +1646,10 @@ static const struct bst_test_instance test_dfu[] = { TEST_CASE(dist, dfu_slot_delete_all, "Distributor deletes all image slots"), TEST_CASE(dist, dfu_slot_check_delete_all, "Distributor checks if all slots are removed from persistent storage"), + TEST_CASE(dist, dfu_slot_reservation, + "Distributor checks that the correct number of slots can be reserved"), + TEST_CASE(dist, dfu_slot_idempotency, + "Distributor checks that the the DFU slot APIs are idempotent"), TEST_CASE(cli, stop, "DFU Client stops at configured point of Firmware Distribution"), TEST_CASE(cli, fail_on_persistency, "DFU Client doesn't give up DFU Transfer"), TEST_CASE(cli, all_targets_lost_on_metadata, diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh new file mode 100755 index 00000000000..3f18f1a2651 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test DFU Slot API. This test tests that the APIs are idempotent. +conf=prj_mesh1d1_conf +overlay=overlay_pst_conf +RunTest dfu_slot_idempotency dfu_dist_dfu_slot_idempotency + +conf=prj_mesh1d1_conf +overlay="overlay_pst_conf_overlay_psa_conf" +RunTest dfu_slot_idempotency_psa dfu_dist_dfu_slot_idempotency diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh new file mode 100755 index 00000000000..ddd7d0123f5 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test DFU Slot API. This test tests slot reservation APIs. +conf=prj_mesh1d1_conf +overlay=overlay_pst_conf +RunTest dfu_slot_reservation dfu_dist_dfu_slot_reservation + +conf=prj_mesh1d1_conf +overlay="overlay_pst_conf_overlay_psa_conf" +RunTest dfu_slot_reservation_psa dfu_dist_dfu_slot_reservation From 7e3caf9f788b375b0eacf2b3c501606d95038ab0 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Fri, 15 Sep 2023 16:02:21 +0200 Subject: [PATCH 0148/1623] [nrf fromtree] Bluetooth: Mesh: Fix printing device UUID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IS_ENABLED was incorrectly used here. Signed-off-by: Pavel Vasilyev (cherry picked from commit ac050455c51e542e6dd852ceaff82c8f58de99c9) Signed-off-by: Alperen Şener (cherry picked from commit 2e3cf5a81536ed97ceffe6b36f322e56852ebaf6) --- subsys/bluetooth/mesh/prov_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/prov_device.c index 48d852cb1a7..20735f49fa5 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/prov_device.c @@ -675,7 +675,7 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers) return -EALREADY; } -#if IS_ENABLED(CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL) +#if defined(CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL) if (CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL > 2) { struct bt_uuid_128 uuid = { .uuid = { BT_UUID_TYPE_128 } }; From cd7dfd7466119b3764545e4af9ae825ee577397e Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Fri, 15 Sep 2023 14:42:57 +0200 Subject: [PATCH 0149/1623] [nrf fromtree] Bluetooth: Mesh: Use decimals instead of hex nums in DFD shell cmds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JSON doesn't support hexdecimals as numbers. Signed-off-by: Pavel Vasilyev (cherry picked from commit 6267259f91d2561666a97dd836e4ea7e2aabbc3a) Signed-off-by: Alperen Şener (cherry picked from commit e08b07667b533ff7f311d79c037e6dff8b77a0ac) --- subsys/bluetooth/mesh/shell/dfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/shell/dfd.c b/subsys/bluetooth/mesh/shell/dfd.c index b7daf42af1c..0415929dfec 100644 --- a/subsys/bluetooth/mesh/shell/dfd.c +++ b/subsys/bluetooth/mesh/shell/dfd.c @@ -29,7 +29,7 @@ static void print_dfd_status(const struct shell *sh, struct bt_mesh_dfd_srv *srv srv->phase); if (srv->phase != BT_MESH_DFD_PHASE_IDLE && srv->dfu.xfer.slot) { - shell_fprintf(sh, SHELL_NORMAL, ", \"group\": 0x%04x, \"app_idx\": %d, " + shell_fprintf(sh, SHELL_NORMAL, ", \"group\": %d, \"app_idx\": %d, " "\"ttl\": %d, \"timeout_base\": %d, \"xfer_mode\": %d, " "\"apply\": %d, \"slot_idx\": %d", srv->inputs.group, srv->inputs.app_idx, srv->inputs.ttl, srv->inputs.timeout_base, @@ -165,7 +165,7 @@ static int cmd_dfd_receivers_get(const struct shell *sh, size_t argc, char *argv for (int i = 0; i < cnt; i++) { const struct bt_mesh_dfu_target *t = &dfd_srv->targets[i + first]; - shell_print(sh, "\t\t\"%d\": { \"blob_addr\": 0x%04x, \"phase\": %d, " + shell_print(sh, "\t\t\"%d\": { \"blob_addr\": %d, \"phase\": %d, " "\"status\": %d, \"blob_status\": %d, \"progress\": %d, " "\"img_idx\": %d }%s", i + first, t->blob.addr, t->phase, t->status, t->blob.status, progress, t->img_idx, (i == cnt - 1) ? "" : ","); From efc4e52f347da84ba172e23935f3786d9612a781 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Tue, 26 Sep 2023 12:11:00 +0200 Subject: [PATCH 0150/1623] [nrf fromtree] Bluetooth: Mesh: fix static oob setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to specification it is possible to provide static oob value with any length. Mesh should trim or append\prepend by zeroes if it is longer\shorter than required value. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 707d1ed81941e425c77a9fd77db43a68d92f76be) Signed-off-by: Alperen Şener (cherry picked from commit 6b2f413d0dc9509685a9bf14804f37c1c9fbcdbd) --- subsys/bluetooth/mesh/prov_device.c | 11 ++++++++--- subsys/bluetooth/mesh/provisioner.c | 15 +++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/prov_device.c index 20735f49fa5..a83ace178db 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/prov_device.c @@ -183,9 +183,14 @@ static void prov_start(const uint8_t *data) } if (atomic_test_bit(bt_mesh_prov_link.flags, OOB_STATIC_KEY)) { - memcpy(bt_mesh_prov_link.auth + auth_size - bt_mesh_prov->static_val_len, - bt_mesh_prov->static_val, bt_mesh_prov->static_val_len); - memset(bt_mesh_prov_link.auth, 0, auth_size - bt_mesh_prov->static_val_len); + + uint8_t tail_size = bt_mesh_prov->static_val_len < auth_size + ? auth_size - bt_mesh_prov->static_val_len + : 0; + + memcpy(bt_mesh_prov_link.auth + tail_size, bt_mesh_prov->static_val, + tail_size ? bt_mesh_prov->static_val_len : auth_size); + memset(bt_mesh_prov_link.auth, 0, tail_size); } } diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index 25f0a299480..673e14578d2 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -254,8 +254,7 @@ static void prov_capabilities(const uint8_t *data) return; } - if (IS_ENABLED(CONFIG_BT_MESH_OOB_AUTH_REQUIRED) && - (caps.oob_type & BT_MESH_OOB_AUTH_REQUIRED)) { + if (caps.oob_type & BT_MESH_OOB_AUTH_REQUIRED) { bool oob_availability = caps.output_size > 0 || caps.input_size > 0 || (caps.oob_type & BT_MESH_STATIC_OOB_AVAILABLE); @@ -752,18 +751,18 @@ int bt_mesh_auth_method_set_output(bt_mesh_output_action_t action, uint8_t size) int bt_mesh_auth_method_set_static(const uint8_t *static_val, uint8_t size) { - uint8_t auth_size = bt_mesh_prov_auth_size_get(); + uint8_t tail_size = size < PROV_AUTH_MAX_LEN ? PROV_AUTH_MAX_LEN - size : 0; - if (!size || !static_val || size > auth_size) { + if (!size || !static_val) { return -EINVAL; } prov_set_method(AUTH_METHOD_STATIC, 0, 0); - memcpy(bt_mesh_prov_link.auth + auth_size - size, static_val, size); - if (size < auth_size) { - (void)memset(bt_mesh_prov_link.auth, 0, auth_size - size); - } + memcpy(bt_mesh_prov_link.auth + tail_size, static_val, + tail_size ? size : PROV_AUTH_MAX_LEN); + memset(bt_mesh_prov_link.auth, 0, tail_size); + return 0; } From 609c593b26ea626d88909f09b7b6df4d26f88363 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Tue, 26 Sep 2023 12:15:40 +0200 Subject: [PATCH 0151/1623] [nrf fromtree] Bluetooth: Mesh: shell supports 32 bytes static oob MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit adds support of 32 bytes static oob in mesh shell. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 236e3b64db062b7ae9e5c9abfc964ea188345db7) Signed-off-by: Alperen Şener (cherry picked from commit 82f1d7e67edc476bf6e6d75d7f4ae46481b555ce) --- doc/connectivity/bluetooth/api/mesh/shell.rst | 4 ++-- subsys/bluetooth/mesh/shell/shell.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/connectivity/bluetooth/api/mesh/shell.rst b/doc/connectivity/bluetooth/api/mesh/shell.rst index e6609f40e5c..6f102b5490f 100644 --- a/doc/connectivity/bluetooth/api/mesh/shell.rst +++ b/doc/connectivity/bluetooth/api/mesh/shell.rst @@ -297,7 +297,7 @@ To allow a device to provision devices over GATT, the :kconfig:option:`CONFIG_BT * ``String``: Unquoted alphanumeric authentication string. -``mesh prov static-oob [Val(1-16 hex)]`` +``mesh prov static-oob [Val(1-32 hex)]`` ---------------------------------------- Set or clear the static OOB authentication value. The static OOB authentication value must be set before provisioning starts to have any effect. The static OOB value must be same on both participants in the provisioning. To enable this command, the :kconfig:option:`BT_MESH_SHELL_PROV_CTX_INSTANCE` option must be enabled. @@ -358,7 +358,7 @@ To allow a device to provision devices over GATT, the :kconfig:option:`CONFIG_BT ------------------------------------------------ From the provisioner device, instruct the unprovisioned device to use static OOB authentication, and use the given static authentication value when provisioning. - * ``Val`` - Static OOB value. Providing a hex-string shorter than 16 bytes will populate the N most significant bytes of the array and zero-pad the rest. + * ``Val`` - Static OOB value. Providing a hex-string shorter than 32 bytes will populate the N most significant bytes of the array and zero-pad the rest. ``mesh prov auth-method none`` ------------------------------ diff --git a/subsys/bluetooth/mesh/shell/shell.c b/subsys/bluetooth/mesh/shell/shell.c index 243166441fe..c5592db02cf 100644 --- a/subsys/bluetooth/mesh/shell/shell.c +++ b/subsys/bluetooth/mesh/shell/shell.c @@ -611,7 +611,7 @@ static void link_close(bt_mesh_prov_bearer_t bearer) shell_print_ctx("Provisioning link closed on %s", bearer2str(bearer)); } -static uint8_t static_val[16]; +static uint8_t static_val[32]; struct bt_mesh_prov bt_mesh_shell_prov = { .uuid = dev_uuid, @@ -645,7 +645,7 @@ static int cmd_static_oob(const struct shell *sh, size_t argc, char *argv[]) bt_mesh_shell_prov.static_val_len = 0U; } else { bt_mesh_shell_prov.static_val_len = hex2bin(argv[1], strlen(argv[1]), - static_val, 16); + static_val, 32); if (bt_mesh_shell_prov.static_val_len) { bt_mesh_shell_prov.static_val = static_val; } else { @@ -886,7 +886,7 @@ static int cmd_auth_method_set_output(const struct shell *sh, size_t argc, char static int cmd_auth_method_set_static(const struct shell *sh, size_t argc, char *argv[]) { size_t len; - uint8_t static_oob_auth[16]; + uint8_t static_oob_auth[32]; int err = 0; len = hex2bin(argv[1], strlen(argv[1]), static_oob_auth, sizeof(static_oob_auth)); From 2ec2e076210bd6c281ead3e1daebbc5ffcb54fc2 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Tue, 26 Sep 2023 12:17:21 +0200 Subject: [PATCH 0152/1623] [nrf fromtree] Bluetooth: Mesh: refactor mandatory oob for mesh1d1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Provisioner should be able to manage received capabilities unconditionally. Mandatory oob authentication is the node feature and it is still compile time feature. Split handling of this feature on provisioner and node part. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 0e98a35e39f001d9e5a4c4f0b9f348668bc1451b) Signed-off-by: Alperen Şener (cherry picked from commit 201ce3e031443dd018c642ebcaaab8c7d14405f0) --- subsys/bluetooth/mesh/prov.c | 6 ------ subsys/bluetooth/mesh/prov_device.c | 13 +++++++++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/subsys/bluetooth/mesh/prov.c b/subsys/bluetooth/mesh/prov.c index f44fffde649..fbbcde58185 100644 --- a/subsys/bluetooth/mesh/prov.c +++ b/subsys/bluetooth/mesh/prov.c @@ -181,12 +181,6 @@ int bt_mesh_prov_auth(bool is_provisioner, uint8_t method, uint8_t action, uint8 uint8_t auth_size = bt_mesh_prov_auth_size_get(); int err; - if (IS_ENABLED(CONFIG_BT_MESH_OOB_AUTH_REQUIRED) && - (method == AUTH_METHOD_NO_OOB || - bt_mesh_prov_link.algorithm == BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM)) { - return -EINVAL; - } - switch (method) { case AUTH_METHOD_NO_OOB: if (action || size) { diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/prov_device.c index a83ace178db..0184463568f 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/prov_device.c @@ -94,15 +94,16 @@ static void prov_invite(const uint8_t *data) bt_mesh_prov->input_size > 0 || bt_mesh_prov->static_val; if (IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM)) { - algorithm_bm |= BIT(BT_MESH_PROV_AUTH_HMAC_SHA256_AES_CCM); + WRITE_BIT(algorithm_bm, BT_MESH_PROV_AUTH_HMAC_SHA256_AES_CCM, 1); } if (IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_CMAC_AES128_AES_CCM)) { - algorithm_bm |= BIT(BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM); + WRITE_BIT(algorithm_bm, BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM, 1); } if (oob_availability && IS_ENABLED(CONFIG_BT_MESH_OOB_AUTH_REQUIRED)) { oob_type |= BT_MESH_OOB_AUTH_REQUIRED; + WRITE_BIT(algorithm_bm, BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM, 0); } /* Supported algorithms */ @@ -176,10 +177,18 @@ static void prov_start(const uint8_t *data) bt_mesh_prov_link.oob_action = data[3]; bt_mesh_prov_link.oob_size = data[4]; + if (IS_ENABLED(CONFIG_BT_MESH_OOB_AUTH_REQUIRED) && + (bt_mesh_prov_link.oob_method == AUTH_METHOD_NO_OOB || + bt_mesh_prov_link.algorithm == BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM)) { + prov_fail(PROV_ERR_NVAL_FMT); + return; + } + if (bt_mesh_prov_auth(false, data[2], data[3], data[4]) < 0) { LOG_ERR("Invalid authentication method: 0x%02x; " "action: 0x%02x; size: 0x%02x", data[2], data[3], data[4]); prov_fail(PROV_ERR_NVAL_FMT); + return; } if (atomic_test_bit(bt_mesh_prov_link.flags, OOB_STATIC_KEY)) { From b6a8f040d960f817bc4abbb5806aa23d50c4bd07 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Tue, 26 Sep 2023 12:20:28 +0200 Subject: [PATCH 0153/1623] [nrf fromtree] tests: Bluetooth: tester: fix mesh1d1 EHP pts tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mesh1d1 uses EHP wth SHA256 algorithm as the main one. This mandates to use 32 bytes static oob if static oob has been chosen. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 4cf78b1e6da90f80bd6449ae01abbcbaccbabbbc) Signed-off-by: Alperen Şener (cherry picked from commit b44b736ef01a0c85727e25fe538acbdd53326a16) --- tests/bluetooth/tester/src/btp/btp_mesh.h | 10 ++++++++-- tests/bluetooth/tester/src/btp_mesh.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index d7d2b2cdc7b..bf73d6839d2 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -30,9 +30,15 @@ struct btp_mesh_read_supported_commands_rp { #define BTP_MESH_CONFIG_PROVISIONING 0x02 +#if IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM) +#define BTP_MESH_PROV_AUTH_MAX_LEN 32 +#else +#define BTP_MESH_PROV_AUTH_MAX_LEN 16 +#endif + struct btp_mesh_config_provisioning_cmd { uint8_t uuid[16]; - uint8_t static_auth[16]; + uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; uint8_t out_size; uint16_t out_actions; uint8_t in_size; @@ -41,7 +47,7 @@ struct btp_mesh_config_provisioning_cmd { } __packed; struct btp_mesh_config_provisioning_cmd_v2 { uint8_t uuid[16]; - uint8_t static_auth[16]; + uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; uint8_t out_size; uint16_t out_actions; uint8_t in_size; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index c922c812631..c56c0ff9c1c 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -43,7 +43,7 @@ static uint8_t priv_key[32]; /* Configured provisioning data */ static uint8_t dev_uuid[16]; -static uint8_t static_auth[16]; +static uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; /* Vendor Model data */ #define VND_MODEL_ID_1 0x1234 From ab1eb73243f14658b3d50ff2b541516a857ace70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Narajowski?= Date: Mon, 16 Nov 2020 12:01:54 +0100 Subject: [PATCH 0154/1623] [nrf fromtree] Bluetooth: tester: Use Model Receive testing callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Send a BTP event to the automation framework that a model message has been received. Signed-off-by: Michal Narajowski (cherry picked from commit 0efc66df5e62078ba9560070c6bafd7e7d122c78) Signed-off-by: Alperen Şener (cherry picked from commit 17f09b553dffd4022567ce0511a6382e5614e04a) --- tests/bluetooth/tester/src/btp/btp_mesh.h | 8 ++++++++ tests/bluetooth/tester/src/btp_mesh.c | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index bf73d6839d2..e17d8481500 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -864,3 +864,11 @@ struct btp_mesh_prov_node_added_ev { uint8_t uuid[16]; uint8_t num_elems; } __packed; + +#define BTP_MESH_EV_MODEL_RECV 0x8f +struct btp_mesh_model_recv_ev { + uint16_t src; + uint16_t dst; + uint8_t payload_len; + uint8_t payload[]; +} __packed; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index c56c0ff9c1c..2796f6418e4 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -2963,6 +2963,28 @@ void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const voi tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_NET_RECV, buf.data, buf.len); } +void model_recv_ev(uint16_t src, uint16_t dst, const void *payload, + size_t payload_len) +{ + NET_BUF_SIMPLE_DEFINE(buf, UINT8_MAX); + struct btp_mesh_model_recv_ev *ev; + + LOG_DBG("src 0x%04x dst 0x%04x payload_len %zu", src, dst, payload_len); + + if (payload_len > net_buf_simple_tailroom(&buf)) { + LOG_ERR("Payload size exceeds buffer size"); + return; + } + + ev = net_buf_simple_add(&buf, sizeof(*ev)); + ev->src = sys_cpu_to_le16(src); + ev->dst = sys_cpu_to_le16(dst); + ev->payload_len = payload_len; + net_buf_simple_add_mem(&buf, payload, payload_len); + + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_MODEL_RECV, buf.data, buf.len); +} + static void model_bound_cb(uint16_t addr, struct bt_mesh_model *model, uint16_t key_idx) { @@ -3023,6 +3045,7 @@ static void incomp_timer_exp_cb(void) static struct bt_test_cb bt_test_cb = { .mesh_net_recv = net_recv_ev, + .mesh_model_recv = model_recv_ev, .mesh_model_bound = model_bound_cb, .mesh_model_unbound = model_unbound_cb, .mesh_prov_invalid_bearer = invalid_bearer_cb, From 83280e62bcf2d4f9ab18ce82c79ad6103a46cd62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Narajowski?= Date: Wed, 18 Nov 2020 12:52:59 +0100 Subject: [PATCH 0155/1623] [nrf fromtree] Bluetooth: tester: Add ttl param to Model Send CMD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some test cases require more control over transmission parameters used when sending access messages. Signed-off-by: Michal Narajowski (cherry picked from commit 959e55cdc07100bda633aab65f577e572e8dd36d) Signed-off-by: Alperen Şener (cherry picked from commit dd60cb7adb16cd6839da09a0f1debd0559610669) --- tests/bluetooth/tester/src/btp/btp_mesh.h | 1 + tests/bluetooth/tester/src/btp_mesh.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index e17d8481500..bd7af172744 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -127,6 +127,7 @@ struct btp_mesh_lpn_set_cmd { #define BTP_MESH_MODEL_SEND 0x0f struct btp_mesh_model_send_cmd { + uint8_t ttl; uint16_t src; uint16_t dst; uint8_t payload_len; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 2796f6418e4..b6ac4d91e1c 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -861,7 +861,7 @@ static uint8_t model_send(const void *cmd, uint16_t cmd_len, .net_idx = net.net_idx, .app_idx = BT_MESH_KEY_DEV, .addr = sys_le16_to_cpu(cp->dst), - .send_ttl = BT_MESH_TTL_DEFAULT, + .send_ttl = cp->ttl, }; if (BT_MESH_ADDR_IS_VIRTUAL(ctx.addr)) { From 4b5500c758e19a5338dc0bc778975ed94024f0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Narajowski?= Date: Thu, 25 Mar 2021 15:33:18 +0100 Subject: [PATCH 0156/1623] [nrf fromtree] tester: Add Large Comp Data models MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Adds Large Comp Data Server and Client - Defines some dummy metadata for Health Server Signed-off-by: Michal Narajowski (cherry picked from commit 11bdcb859e921a79e50dc41c30167bc544dcbcda) Signed-off-by: Alperen Şener (cherry picked from commit f7c4008a2c541985bb00c63e0374990b37ebd2d0) --- tests/bluetooth/tester/overlay-mesh.conf | 5 + tests/bluetooth/tester/src/btp/btp_mesh.h | 22 +++++ tests/bluetooth/tester/src/btp_mesh.c | 111 ++++++++++++++++++++-- 3 files changed, 129 insertions(+), 9 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 840af06c1c0..937f4d1270e 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -1,4 +1,5 @@ CONFIG_BT_MESH=y +CONFIG_BT_MESH_V1d1=y CONFIG_BT_MESH_RELAY=y CONFIG_BT_MESH_PB_ADV=y CONFIG_BT_MESH_PB_GATT=y @@ -12,6 +13,8 @@ CONFIG_BT_MESH_APP_KEY_COUNT=4 CONFIG_BT_MESH_IV_UPDATE_TEST=y CONFIG_BT_MESH_CFG_CLI=y CONFIG_BT_MESH_HEALTH_CLI=y +CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y +CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y CONFIG_BT_MESH_FRIEND=y CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=32 CONFIG_BT_MESH_RX_SEG_MAX=13 @@ -23,3 +26,5 @@ CONFIG_BT_MESH_CDB_NODE_COUNT=3 CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y CONFIG_BT_MESH_MSG_CACHE_SIZE=10 CONFIG_BT_MESH_PROXY_CLIENT=y + +CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index bd7af172744..63984f0b61f 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -773,6 +773,28 @@ struct btp_proxy_connect_cmd { uint16_t net_idx; } __packed; +#define BTP_MESH_LARGE_COMP_DATA_GET 0x53 +struct btp_mesh_large_comp_data_get_cmd { + uint16_t net_idx; + uint16_t addr; + uint8_t page; + uint16_t offset; +} __packed; +struct btp_mesh_large_comp_data_get_rp { + uint8_t data[0]; +} __packed; + +#define BTP_MESH_MODELS_METADATA_GET 0x54 +struct btp_mesh_models_metadata_get_cmd { + uint16_t net_idx; + uint16_t addr; + uint8_t page; + uint16_t offset; +} __packed; +struct btp_mesh_models_metadata_get_rp { + uint8_t data[0]; +} __packed; + /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index b6ac4d91e1c..a6ccd319b2d 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -22,6 +22,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_BTTESTER_LOG_LEVEL); #include "btp/btp.h" #define CID_LOCAL 0x05F1 +#define COMPANY_ID_LF 0x05F1 +#define COMPANY_ID_NORDIC_SEMI 0x05F9 /* Health server data */ #define CUR_FAULTS_MAX 4 @@ -254,15 +256,6 @@ static const struct bt_mesh_health_srv_cb health_srv_cb = { .fault_test = fault_test, }; -static struct bt_mesh_health_srv health_srv = { - .cb = &health_srv_cb, -}; - -BT_MESH_HEALTH_PUB_DEFINE(health_pub, CUR_FAULTS_MAX); - -static struct bt_mesh_cfg_cli cfg_cli = { -}; - static void show_faults(uint8_t test_id, uint16_t cid, uint8_t *faults, size_t fault_count) { size_t i; @@ -289,15 +282,52 @@ static void health_current_status(struct bt_mesh_health_cli *cli, uint16_t addr, show_faults(test_id, cid, faults, fault_count); } +#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) +static struct bt_mesh_large_comp_data_cli lcd_cli = { +}; +#endif + static struct bt_mesh_health_cli health_cli = { .current_status = health_current_status, }; + +#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV +static uint8_t health_tests[] = { + BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_LF, 6, 0x01, 0x02, 0x03, 0x04, 0x34, + 0x15), + BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_NORDIC_SEMI, 3, 0x01, 0x02, 0x03), +}; + +static struct bt_mesh_models_metadata_entry health_srv_meta[] = { + BT_MESH_HEALTH_TEST_INFO_METADATA(health_tests), + BT_MESH_MODELS_METADATA_END, +}; +#endif + +static struct bt_mesh_health_srv health_srv = { + .cb = &health_srv_cb, +#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV + .metadata = health_srv_meta, +#endif +}; + +BT_MESH_HEALTH_PUB_DEFINE(health_pub, CUR_FAULTS_MAX); + +static struct bt_mesh_cfg_cli cfg_cli = { +}; + static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub), BT_MESH_MODEL_HEALTH_CLI(&health_cli), +#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV) + BT_MESH_MODEL_LARGE_COMP_DATA_SRV, +#endif +#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) + BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&lcd_cli), +#endif }; static struct bt_mesh_model vnd_models[] = { @@ -986,6 +1016,56 @@ static uint8_t proxy_connect(const void *cmd, uint16_t cmd_len, } #endif +#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) +static uint8_t large_comp_data_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mesh_large_comp_data_get_cmd *cp = cmd; + struct btp_mesh_large_comp_data_get_rp *rp = rsp; + int err; + + struct bt_mesh_large_comp_data_rsp comp; + + err = bt_mesh_large_comp_data_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->addr), cp->page, + sys_le16_to_cpu(cp->offset), &comp); + if (err) { + LOG_ERR("Large Composition Data Get failed (err %d)", err); + + return BTP_STATUS_FAILED; + } + + memcpy(rp->data, comp.data->data, comp.data->len); + *rsp_len = comp.data->len; + + return BTP_STATUS_SUCCESS; +} + +static uint8_t models_metadata_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mesh_models_metadata_get_cmd *cp = cmd; + struct btp_mesh_models_metadata_get_rp *rp = rsp; + int err; + + struct bt_mesh_large_comp_data_rsp metadata; + + err = bt_mesh_models_metadata_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->addr), cp->page, + sys_le16_to_cpu(cp->offset), &metadata); + + if (err) { + LOG_ERR("Models Metadata Get failed (err %d)", err); + return BTP_STATUS_FAILED; + } + + memcpy(rp->data, metadata.data->data, metadata.data->len); + *rsp_len = metadata.data->len; + + return BTP_STATUS_SUCCESS; +} +#endif + static uint8_t composition_data_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -2936,8 +3016,21 @@ static const struct btp_handler handlers[] = { .func = proxy_connect }, #endif +#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) + { + .opcode = BTP_MESH_LARGE_COMP_DATA_GET, + .expect_len = sizeof(struct btp_mesh_large_comp_data_get_cmd), + .func = large_comp_data_get + }, + { + .opcode = BTP_MESH_MODELS_METADATA_GET, + .expect_len = sizeof(struct btp_mesh_models_metadata_get_cmd), + .func = models_metadata_get + }, +#endif }; + void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload, size_t payload_len) { From 9c7ac78741416f601ad8f453f76f5edab0b4d110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Narajowski?= Date: Tue, 31 Jan 2023 14:29:16 +0100 Subject: [PATCH 0157/1623] [nrf fromtree] Bluetooth: tester: Add Transport SAR Configuration models MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for testing the new SAR Configuration models in tester application. Signed-off-by: Michal Narajowski (cherry picked from commit a73727c2fe8c7ac6972b7f2844d2949936ecc5fe) Signed-off-by: Alperen Şener (cherry picked from commit 5e6d6501d8348bcea388e2ef3a903efec1fe1662) --- tests/bluetooth/tester/overlay-mesh.conf | 2 + tests/bluetooth/tester/src/btp/btp_mesh.h | 40 +++++++ tests/bluetooth/tester/src/btp_mesh.c | 133 +++++++++++++++++++++- 3 files changed, 174 insertions(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 937f4d1270e..43e666d0eb3 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -15,6 +15,8 @@ CONFIG_BT_MESH_CFG_CLI=y CONFIG_BT_MESH_HEALTH_CLI=y CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y +CONFIG_BT_MESH_SAR_CFG_SRV=y +CONFIG_BT_MESH_SAR_CFG_CLI=y CONFIG_BT_MESH_FRIEND=y CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=32 CONFIG_BT_MESH_RX_SEG_MAX=13 diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 63984f0b61f..67ce612c2ac 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -773,6 +773,46 @@ struct btp_proxy_connect_cmd { uint16_t net_idx; } __packed; +struct sar_transmitter { + uint8_t seg_int_step; + uint8_t unicast_retrans_count; + uint8_t unicast_retrans_without_prog_count; + uint8_t unicast_retrans_int_step; + uint8_t unicast_retrans_int_inc; + uint8_t multicast_retrans_count; + uint8_t multicast_retrans_int; +} __packed; + +struct sar_receiver { + uint8_t seg_thresh; + uint8_t ack_delay_inc; + uint8_t ack_retrans_count; + uint8_t discard_timeout; + uint8_t rx_seg_int_step; +} __packed; + +#define BTP_MESH_SAR_TRANSMITTER_GET 0x4f +struct btp_mesh_sar_transmitter_get_cmd { + uint16_t dst; +} __packed; + +#define BTP_MESH_SAR_TRANSMITTER_SET 0x50 +struct btp_mesh_sar_transmitter_set_cmd { + uint16_t dst; + struct sar_transmitter tx; +} __packed; + +#define BTP_MESH_SAR_RECEIVER_GET 0x51 +struct btp_mesh_sar_receiver_get_cmd { + uint16_t dst; +} __packed; + +#define BTP_MESH_SAR_RECEIVER_SET 0x52 +struct btp_mesh_sar_receiver_set_cmd { + uint16_t dst; + struct sar_receiver rx; +} __packed; + #define BTP_MESH_LARGE_COMP_DATA_GET 0x53 struct btp_mesh_large_comp_data_get_cmd { uint16_t net_idx; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index a6ccd319b2d..232e3d7d8b4 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #define LOG_MODULE_NAME bttester_mesh @@ -317,11 +318,21 @@ BT_MESH_HEALTH_PUB_DEFINE(health_pub, CUR_FAULTS_MAX); static struct bt_mesh_cfg_cli cfg_cli = { }; +#if defined(CONFIG_BT_MESH_SAR_CFG_CLI) +static struct bt_mesh_sar_cfg_cli sar_cfg_cli; +#endif + static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub), BT_MESH_MODEL_HEALTH_CLI(&health_cli), +#if defined(CONFIG_BT_MESH_SAR_CFG_SRV) + BT_MESH_MODEL_SAR_CFG_SRV, +#endif +#if defined(CONFIG_BT_MESH_SAR_CFG_CLI) + BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), +#endif #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV) BT_MESH_MODEL_LARGE_COMP_DATA_SRV, #endif @@ -1016,6 +1027,105 @@ static uint8_t proxy_connect(const void *cmd, uint16_t cmd_len, } #endif +#if defined(CONFIG_BT_MESH_SAR_CFG_CLI) +static uint8_t sar_transmitter_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mesh_sar_transmitter_get_cmd *cp = cmd; + struct bt_mesh_sar_tx tx_rsp; + int err; + + LOG_DBG(""); + + bt_mesh_sar_cfg_cli_timeout_set(5000); + + err = bt_mesh_sar_cfg_cli_transmitter_get( + net_key_idx, sys_le16_to_cpu(cp->dst), &tx_rsp); + if (err) { + LOG_ERR("err=%d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t sar_transmitter_set(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mesh_sar_transmitter_set_cmd *cp = cmd; + struct bt_mesh_sar_tx set, tx_rsp; + int err; + + LOG_DBG(""); + + bt_mesh_sar_cfg_cli_timeout_set(5000); + + set.seg_int_step = cp->tx.seg_int_step; + set.unicast_retrans_count = cp->tx.unicast_retrans_count; + set.unicast_retrans_int_inc = cp->tx.unicast_retrans_int_inc; + set.unicast_retrans_int_step = cp->tx.unicast_retrans_int_step; + set.unicast_retrans_without_prog_count = + cp->tx.unicast_retrans_without_prog_count; + set.multicast_retrans_count = cp->tx.multicast_retrans_count; + set.multicast_retrans_int = cp->tx.multicast_retrans_int; + + err = bt_mesh_sar_cfg_cli_transmitter_set(net_key_idx, + sys_le16_to_cpu(cp->dst), + &set, &tx_rsp); + if (err) { + LOG_ERR("err=%d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t sar_receiver_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mesh_sar_receiver_get_cmd *cp = cmd; + struct bt_mesh_sar_rx rx_rsp; + int err; + + LOG_DBG(""); + + err = bt_mesh_sar_cfg_cli_receiver_get(net_key_idx, + sys_le16_to_cpu(cp->dst), &rx_rsp); + if (err) { + LOG_ERR("err=%d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t sar_receiver_set(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mesh_sar_receiver_set_cmd *cp = cmd; + struct bt_mesh_sar_rx set, rx_rsp; + int err; + + LOG_DBG(""); + + set.ack_delay_inc = cp->rx.ack_delay_inc; + set.ack_retrans_count = cp->rx.ack_retrans_count; + set.discard_timeout = cp->rx.discard_timeout; + set.seg_thresh = cp->rx.seg_thresh; + set.rx_seg_int_step = cp->rx.rx_seg_int_step; + + err = bt_mesh_sar_cfg_cli_receiver_set(net_key_idx, + sys_le16_to_cpu(cp->dst), &set, + &rx_rsp); + if (err) { + LOG_ERR("err=%d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} +#endif + #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) static uint8_t large_comp_data_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -3016,6 +3126,28 @@ static const struct btp_handler handlers[] = { .func = proxy_connect }, #endif +#if defined(CONFIG_BT_MESH_SAR_CFG_CLI) + { + .opcode = BTP_MESH_SAR_TRANSMITTER_GET, + .expect_len = sizeof(struct btp_mesh_sar_transmitter_get_cmd), + .func = sar_transmitter_get + }, + { + .opcode = BTP_MESH_SAR_TRANSMITTER_SET, + .expect_len = sizeof(struct btp_mesh_sar_transmitter_set_cmd), + .func = sar_transmitter_set + }, + { + .opcode = BTP_MESH_SAR_RECEIVER_GET, + .expect_len = sizeof(struct btp_mesh_sar_receiver_get_cmd), + .func = sar_receiver_get + }, + { + .opcode = BTP_MESH_SAR_RECEIVER_SET, + .expect_len = sizeof(struct btp_mesh_sar_receiver_set_cmd), + .func = sar_receiver_set + }, +#endif #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) { .opcode = BTP_MESH_LARGE_COMP_DATA_GET, @@ -3030,7 +3162,6 @@ static const struct btp_handler handlers[] = { #endif }; - void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload, size_t payload_len) { From 2560e34ef5baf2d9a4c0ddadc36e4037a39d5569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Fri, 28 Jan 2022 08:03:51 +0100 Subject: [PATCH 0158/1623] [nrf fromtree] Tests: Bluetooth: tester: enable Remote Provisioning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This enables Remote Provisioning in tester application. Adds basic setup and required structures/functions. add BTP API for Remote Provisioning Client This adds BTP commands for RPR Client API. Signed-off-by: Krzysztof Kopyściński (cherry picked from commit 68928e050f365306d92fc08f3bec91fa0e207cad) Signed-off-by: Alperen Şener (cherry picked from commit bff665d6dcf11c9a461b955be185e58b5d76faf3) --- tests/bluetooth/tester/overlay-mesh.conf | 4 + tests/bluetooth/tester/src/btp/btp_mesh.h | 61 +++ tests/bluetooth/tester/src/btp_mesh.c | 434 +++++++++++++++++++++- 3 files changed, 495 insertions(+), 4 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 43e666d0eb3..b537ae0001e 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -28,5 +28,9 @@ CONFIG_BT_MESH_CDB_NODE_COUNT=3 CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y CONFIG_BT_MESH_MSG_CACHE_SIZE=10 CONFIG_BT_MESH_PROXY_CLIENT=y +CONFIG_BT_MESH_PROVISIONER=y +CONFIG_BT_MESH_RPR_SRV=y +CONFIG_BT_MESH_RPR_CLI=y +CONFIG_BT_MESH_RPR_AD_TYPES_MAX=2 CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 67ce612c2ac..29523d02d8c 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -835,6 +835,66 @@ struct btp_mesh_models_metadata_get_rp { uint8_t data[0]; } __packed; +#define BTP_MESH_COMP_CHANGE_PREPARE 0x57 + +#define BTP_MESH_SET_COMP_ALT 0x58 + +#define BTP_MESH_RPR_SCAN_START 0x59 +struct btp_rpr_scan_start_cmd { + uint16_t dst; + uint8_t timeout; + uint8_t uuid[16]; +} __packed; + +#define BTP_MESH_RPR_EXT_SCAN_START 0x5a +struct btp_rpr_ext_scan_start_cmd { + uint16_t dst; + uint8_t timeout; + uint8_t uuid[16]; + uint8_t ad_count; + uint8_t ad_types[]; +} __packed; + +#define BTP_MESH_RPR_SCAN_CAPS_GET 0x5b +struct btp_rpr_scan_caps_get_cmd { + uint16_t dst; +} __packed; + +#define BTP_MESH_RPR_SCAN_GET 0x5c +struct btp_rpr_scan_get_cmd { + uint16_t dst; +} __packed; + +#define BTP_MESH_RPR_SCAN_STOP 0x5d +struct btp_rpr_scan_stop_cmd { + uint16_t dst; +} __packed; + +#define BTP_MESH_RPR_LINK_GET 0x5e +struct btp_rpr_link_get_cmd { + uint16_t dst; +} __packed; + +#define BTP_MESH_RPR_LINK_CLOSE 0x5f +struct btp_rpr_link_close_cmd { + uint16_t dst; +} __packed; + +#define BTP_MESH_RPR_PROV_REMOTE 0x60 +struct btp_rpr_prov_remote_cmd { + uint16_t dst; + uint8_t uuid[16]; + uint16_t net_idx; + uint16_t addr; +} __packed; + +#define BTP_MESH_RPR_REPROV_REMOTE 0x61 +struct btp_rpr_reprov_remote_cmd { + uint16_t dst; + uint16_t addr; + bool comp_change; +} __packed; + /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { @@ -858,6 +918,7 @@ struct btp_mesh_in_action_ev { #define BTP_MESH_PROV_BEARER_PB_ADV 0x00 #define BTP_MESH_PROV_BEARER_PB_GATT 0x01 +#define BTP_MESH_PROV_BEARER_REMOTE 0x04 #define BTP_MESH_EV_PROV_LINK_OPEN 0x84 struct btp_mesh_prov_link_open_ev { uint8_t bearer; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 232e3d7d8b4..40ae3a6f038 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -76,6 +76,7 @@ static struct { .dst = BT_MESH_ADDR_UNASSIGNED, }; +static bool default_comp = true; static uint8_t supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -322,6 +323,49 @@ static struct bt_mesh_cfg_cli cfg_cli = { static struct bt_mesh_sar_cfg_cli sar_cfg_cli; #endif +#if defined(CONFIG_BT_MESH_RPR_CLI) +static void rpr_scan_report(struct bt_mesh_rpr_cli *cli, + const struct bt_mesh_rpr_node *srv, + struct bt_mesh_rpr_unprov *unprov, + struct net_buf_simple *adv_data) +{ + char uuid_hex_str[32 + 1]; + + bin2hex(unprov->uuid, 16, uuid_hex_str, sizeof(uuid_hex_str)); + + LOG_DBG("Server 0x%04x:\n" + "\tuuid: %s\n" + "\tOOB: 0x%04x", + srv->addr, uuid_hex_str, unprov->oob); + + while (adv_data && adv_data->len > 2) { + uint8_t len, type; + uint8_t data[31]; + + len = net_buf_simple_pull_u8(adv_data) - 1; + type = net_buf_simple_pull_u8(adv_data); + memcpy(data, net_buf_simple_pull_mem(adv_data, len), len); + data[len] = '\0'; + + if (type == BT_DATA_URI) { + LOG_DBG("\tURI: \"\\x%02x%s\"", + data[0], &data[1]); + } else if (type == BT_DATA_NAME_COMPLETE) { + LOG_DBG("\tName: \"%s\"", data); + } else { + char string[64 + 1]; + + bin2hex(data, len, string, sizeof(string)); + LOG_DBG("\t0x%02x: %s", type, string); + } + } +} + +static struct bt_mesh_rpr_cli rpr_cli = { + .scan_report = rpr_scan_report, +}; +#endif + static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), @@ -339,6 +383,12 @@ static struct bt_mesh_model root_models[] = { #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&lcd_cli), #endif +#if defined(CONFIG_BT_MESH_RPR_CLI) + BT_MESH_MODEL_RPR_CLI(&rpr_cli), +#endif +#if defined(CONFIG_BT_MESH_RPR_SRV) + BT_MESH_MODEL_RPR_SRV, +#endif }; static struct bt_mesh_model vnd_models[] = { @@ -363,6 +413,9 @@ static void link_open(bt_mesh_prov_bearer_t bearer) case BT_MESH_PROV_GATT: ev.bearer = BTP_MESH_PROV_BEARER_PB_GATT; break; + case BT_MESH_PROV_REMOTE: + ev.bearer = BTP_MESH_PROV_BEARER_REMOTE; + break; default: LOG_ERR("Invalid bearer"); @@ -385,6 +438,9 @@ static void link_close(bt_mesh_prov_bearer_t bearer) case BT_MESH_PROV_GATT: ev.bearer = BTP_MESH_PROV_BEARER_PB_GATT; break; + case BT_MESH_PROV_REMOTE: + ev.bearer = BTP_MESH_PROV_BEARER_REMOTE; + break; default: LOG_ERR("Invalid bearer"); @@ -476,12 +532,24 @@ static void prov_reset(void) LOG_DBG(""); bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT); + + if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV)) { + bt_mesh_prov_enable(BT_MESH_PROV_REMOTE); + } } static const struct bt_mesh_comp comp = { .cid = CID_LOCAL, .elem = elements, .elem_count = ARRAY_SIZE(elements), + .vid = 1, +}; + +static const struct bt_mesh_comp comp_alt = { + .cid = CID_LOCAL, + .elem = elements, + .elem_count = ARRAY_SIZE(elements), + .vid = 2, }; static struct bt_mesh_prov prov = { @@ -496,6 +564,7 @@ static struct bt_mesh_prov prov = { .complete = prov_complete, .node_added = prov_node_added, .reset = prov_reset, + .uri = "Tester", }; static uint8_t config_prov(const void *cmd, uint16_t cmd_len, @@ -617,19 +686,26 @@ static uint8_t init(const void *cmd, uint16_t cmd_len, LOG_DBG(""); - err = bt_mesh_init(&prov, &comp); - if (err) { - return BTP_STATUS_FAILED; + if (IS_ENABLED(CONFIG_BT_SETTINGS)) { + printk("Loading stored settings\n"); + settings_load(); } if (addr) { err = bt_mesh_provision(net_key, net_key_idx, flags, iv_index, addr, dev_key); - if (err) { + if (err && err != -EALREADY) { return BTP_STATUS_FAILED; } } else { err = bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT); + if (err && err != -EALREADY) { + return BTP_STATUS_FAILED; + } + } + + if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV)) { + err = bt_mesh_prov_enable(BT_MESH_PROV_REMOTE); if (err) { return BTP_STATUS_FAILED; } @@ -1205,6 +1281,62 @@ static uint8_t composition_data_get(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } +static uint8_t change_prepare(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + int err; + + LOG_DBG(""); + + err = bt_mesh_comp_change_prepare(); + if (err < 0) { + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +#if IS_ENABLED(CONFIG_BT_SETTINGS) +static int comp_alt_set(const char *name, size_t len_rd, + settings_read_cb read_cb, void *store) +{ + ssize_t len; + bool alt_comp_value; + + if (len_rd == 0) { + LOG_DBG("Default composition"); + } + + len = read_cb(store, &alt_comp_value, sizeof(alt_comp_value)); + if (len < 0 || len != len_rd) { + LOG_ERR("Failed to read value (err %zd)", len); + return len; + } + + if (alt_comp_value) { + default_comp = false; + } + + return 0; +} + +SETTINGS_STATIC_HANDLER_DEFINE(tester_comp_alt, "tester/comp_alt", NULL, comp_alt_set, NULL, NULL); +#endif + +static uint8_t set_comp_alt(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ +#if !IS_ENABLED(CONFIG_BT_SETTINGS) + return BTP_STATUS_FAILED; +#else + bool comp_alt_val = true; + + settings_save_one("tester/comp_alt", &comp_alt_val, sizeof(comp_alt_val)); + + return BTP_STATUS_SUCCESS; +#endif +} + static uint8_t config_krp_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -2730,6 +2862,233 @@ static uint8_t health_attention_set(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } +#if defined(CONFIG_BT_MESH_RPR_CLI) +static uint8_t rpr_scan_start(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_rpr_scan_start_cmd *cp = cmd; + + struct bt_mesh_rpr_scan_status status; + const struct bt_mesh_rpr_node srv = { + .addr = cp->dst, + .net_idx = net.net_idx, + .ttl = BT_MESH_TTL_DEFAULT, + }; + uint8_t uuid[16] = {0}; + int err; + + err = bt_mesh_rpr_scan_start(&rpr_cli, &srv, + memcmp(uuid, cp->uuid, 16) ? cp->uuid : NULL, + cp->timeout, + BT_MESH_RPR_SCAN_MAX_DEVS_ANY, &status); + + if (err) { + LOG_ERR("Scan start failed: %d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t rpr_ext_scan_start(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_rpr_ext_scan_start_cmd *cp = cmd; + const struct bt_mesh_rpr_node srv = { + .addr = cp->dst, + .net_idx = net.net_idx, + .ttl = BT_MESH_TTL_DEFAULT, + }; + int err; + + err = bt_mesh_rpr_scan_start_ext(&rpr_cli, &srv, cp->uuid, + cp->timeout, cp->ad_types, + cp->ad_count); + if (err) { + LOG_ERR("Scan start failed: %d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t rpr_scan_caps_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_rpr_scan_caps_get_cmd *cp = cmd; + struct bt_mesh_rpr_caps caps; + const struct bt_mesh_rpr_node srv = { + .addr = cp->dst, + .net_idx = net.net_idx, + .ttl = BT_MESH_TTL_DEFAULT, + }; + int err; + + err = bt_mesh_rpr_scan_caps_get(&rpr_cli, &srv, &caps); + if (err) { + LOG_ERR("Scan capabilities get failed: %d", err); + return BTP_STATUS_FAILED; + } + + LOG_DBG("Remote Provisioning scan capabilities of 0x%04x:", + net.dst); + LOG_DBG("\tMax devices: %u", caps.max_devs); + LOG_DBG("\tActive scanning: %s", + caps.active_scan ? "true" : "false"); + + return BTP_STATUS_SUCCESS; +} + +static uint8_t rpr_scan_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_rpr_scan_get_cmd *cp = cmd; + struct bt_mesh_rpr_scan_status status; + const struct bt_mesh_rpr_node srv = { + .addr = cp->dst, + .net_idx = net.net_idx, + .ttl = BT_MESH_TTL_DEFAULT, + }; + int err; + + err = bt_mesh_rpr_scan_get(&rpr_cli, &srv, &status); + if (err) { + LOG_ERR("Scan get failed: %d", err); + return BTP_STATUS_FAILED; + } + + LOG_DBG("Remote Provisioning scan on 0x%04x:", cp->dst); + LOG_DBG("\tStatus: %u", status.status); + LOG_DBG("\tScan type: %u", status.scan); + LOG_DBG("\tMax devices: %u", status.max_devs); + LOG_DBG("\tRemaining time: %u", status.timeout); + + return BTP_STATUS_SUCCESS; +} + +static uint8_t rpr_scan_stop(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_rpr_scan_stop_cmd *cp = cmd; + struct bt_mesh_rpr_scan_status status; + const struct bt_mesh_rpr_node srv = { + .addr = cp->dst, + .net_idx = net.net_idx, + .ttl = BT_MESH_TTL_DEFAULT, + }; + int err; + + err = bt_mesh_rpr_scan_stop(&rpr_cli, &srv, &status); + if (err || status.status) { + LOG_DBG("Scan stop failed: %d %u", err, status.status); + return BTP_STATUS_FAILED; + } + + LOG_DBG("Remote Provisioning scan on 0x%04x stopped.", + net.dst); + + return BTP_STATUS_SUCCESS; +} + +static uint8_t rpr_link_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_rpr_link_get_cmd *cp = cmd; + struct bt_mesh_rpr_link link; + const struct bt_mesh_rpr_node srv = { + .addr = cp->dst, + .net_idx = net.net_idx, + .ttl = BT_MESH_TTL_DEFAULT, + }; + int err; + + err = bt_mesh_rpr_link_get(&rpr_cli, &srv, &link); + if (err) { + LOG_ERR("Link get failed: %d %u", err, link.status); + return BTP_STATUS_FAILED; + } + + LOG_DBG("Remote Provisioning Link on 0x%04x:", cp->dst); + LOG_DBG("\tStatus: %u", link.status); + LOG_DBG("\tState: %u", link.state); + + return BTP_STATUS_SUCCESS; +} + +static uint8_t rpr_link_close(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_rpr_link_close_cmd *cp = cmd; + struct bt_mesh_rpr_link link; + const struct bt_mesh_rpr_node srv = { + .addr = cp->dst, + .net_idx = net.net_idx, + .ttl = BT_MESH_TTL_DEFAULT, + }; + int err; + + err = bt_mesh_rpr_link_close(&rpr_cli, &srv, &link); + if (err) { + LOG_ERR("Link close failed: %d %u", err, link.status); + return BTP_STATUS_FAILED; + } + + LOG_DBG("Remote Provisioning Link on 0x%04x:", cp->dst); + LOG_DBG("\tStatus: %u", link.status); + LOG_DBG("\tState: %u", link.state); + + return BTP_STATUS_SUCCESS; +} + +static uint8_t rpr_prov_remote(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_rpr_prov_remote_cmd *cp = cmd; + struct bt_mesh_rpr_node srv = { + .addr = cp->dst, + .net_idx = net.net_idx, + .ttl = BT_MESH_TTL_DEFAULT, + }; + int err; + + err = bt_mesh_provision_remote(&rpr_cli, &srv, cp->uuid, + cp->net_idx, cp->addr); + if (err) { + LOG_ERR("Prov remote start failed: %d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t rpr_reprov_remote(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_rpr_reprov_remote_cmd *cp = cmd; + struct bt_mesh_rpr_node srv = { + .addr = cp->dst, + .net_idx = net.net_idx, + .ttl = BT_MESH_TTL_DEFAULT, + }; + int err; + + if (!BT_MESH_ADDR_IS_UNICAST(cp->addr)) { + LOG_ERR("Must be a valid unicast address"); + err = -EINVAL; + return BTP_STATUS_FAILED; + } + + err = bt_mesh_reprovision_remote(&rpr_cli, &srv, cp->addr, + cp->comp_change); + if (err) { + LOG_ERR("Reprovisioning failed: %d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} +#endif + static const struct btp_handler handlers[] = { { .opcode = BTP_MESH_READ_SUPPORTED_COMMANDS, @@ -3160,6 +3519,62 @@ static const struct btp_handler handlers[] = { .func = models_metadata_get }, #endif + { + .opcode = BTP_MESH_COMP_CHANGE_PREPARE, + .expect_len = 0, + .func = change_prepare + }, + { + .opcode = BTP_MESH_SET_COMP_ALT, + .expect_len = 0, + .func = set_comp_alt + }, +#if defined(CONFIG_BT_MESH_RPR_CLI) + { + .opcode = BTP_MESH_RPR_SCAN_START, + .expect_len = sizeof(struct btp_rpr_scan_start_cmd), + .func = rpr_scan_start + }, + { + .opcode = BTP_MESH_RPR_EXT_SCAN_START, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = rpr_ext_scan_start + }, + { + .opcode = BTP_MESH_RPR_SCAN_CAPS_GET, + .expect_len = sizeof(struct btp_rpr_scan_caps_get_cmd), + .func = rpr_scan_caps_get + }, + { + .opcode = BTP_MESH_RPR_SCAN_GET, + .expect_len = sizeof(struct btp_rpr_scan_get_cmd), + .func = rpr_scan_get + }, + { + .opcode = BTP_MESH_RPR_SCAN_STOP, + .expect_len = sizeof(struct btp_rpr_scan_stop_cmd), + .func = rpr_scan_stop + }, + { + .opcode = BTP_MESH_RPR_LINK_GET, + .expect_len = sizeof(struct btp_rpr_link_get_cmd), + .func = rpr_link_get + }, + { + .opcode = BTP_MESH_RPR_LINK_CLOSE, + .expect_len = sizeof(struct btp_rpr_link_close_cmd), + .func = rpr_link_close + }, + { + .opcode = BTP_MESH_RPR_PROV_REMOTE, + .expect_len = sizeof(struct btp_rpr_prov_remote_cmd), + .func = rpr_prov_remote + }, + { + .opcode = BTP_MESH_RPR_REPROV_REMOTE, + .expect_len = sizeof(struct btp_rpr_reprov_remote_cmd), + .func = rpr_reprov_remote + }, }; void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload, @@ -3345,12 +3760,23 @@ BT_MESH_LPN_CB_DEFINE(lpn_cb) = { uint8_t tester_init_mesh(void) { + int err; + if (IS_ENABLED(CONFIG_BT_TESTING)) { bt_test_cb_register(&bt_test_cb); } tester_register_command_handlers(BTP_SERVICE_ID_MESH, handlers, ARRAY_SIZE(handlers)); + if (default_comp) { + err = bt_mesh_init(&prov, &comp); + } else { + err = bt_mesh_init(&prov, &comp_alt); + } + + if (err) { + return BTP_STATUS_FAILED; + } return BTP_STATUS_SUCCESS; } From 26290321c5f585ca469dd52076fe458045a55d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Wed, 4 May 2022 08:05:03 +0200 Subject: [PATCH 0159/1623] [nrf fromtree] Bluetooth: Tester: Add Blob, DFU and DFD tests support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding support for automatic testing BLOB, DFU and DFD models. Co-authored-by: Agata Ponitka Co-authored-by: Pavel Vasilyev Signed-off-by: Krzysztof Kopyściński Signed-off-by: Pavel Vasilyev (cherry picked from commit 51ec2462d60aded26a5ba4736dde0e17dfc38af1) Signed-off-by: Alperen Şener (cherry picked from commit a4517ed57ebfbfb6c5ca765bdbefac1af492c901) --- tests/bluetooth/tester/overlay-mesh.conf | 8 +- tests/bluetooth/tester/src/btp/btp_mesh.h | 68 ++ tests/bluetooth/tester/src/btp/bttester.h | 3 + tests/bluetooth/tester/src/btp_core.c | 6 + tests/bluetooth/tester/src/btp_mesh.c | 1277 ++++++++++++++++++--- 5 files changed, 1221 insertions(+), 141 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index b537ae0001e..3352e36f3a4 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -20,7 +20,7 @@ CONFIG_BT_MESH_SAR_CFG_CLI=y CONFIG_BT_MESH_FRIEND=y CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=32 CONFIG_BT_MESH_RX_SEG_MAX=13 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=3 +CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 CONFIG_BT_MESH_LPN_POLL_TIMEOUT=100 CONFIG_BT_MESH_PROVISIONER=y CONFIG_BT_MESH_CDB=y @@ -32,5 +32,11 @@ CONFIG_BT_MESH_PROVISIONER=y CONFIG_BT_MESH_RPR_SRV=y CONFIG_BT_MESH_RPR_CLI=y CONFIG_BT_MESH_RPR_AD_TYPES_MAX=2 +CONFIG_BT_MESH_BLOB_CLI=y +CONFIG_BT_MESH_DFU_CLI=y +CONFIG_BT_MESH_BLOB_SRV=y +CONFIG_BT_MESH_DFU_SRV=y +CONFIG_BT_MESH_DFD_SRV=y +CONFIG_BT_MESH_DFU_SLOT_CNT=2 CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 29523d02d8c..66a86bbb128 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -895,6 +895,72 @@ struct btp_rpr_reprov_remote_cmd { bool comp_change; } __packed; +#define BTP_MMDL_DFU_INFO_GET 0x5f +struct btp_mmdl_dfu_info_get_cmd { + uint8_t limit; +} __packed; + +#define BTP_MMDL_BLOB_INFO_GET 0x60 +struct btp_mmdl_blob_info_get_cmd { + uint8_t addr_cnt; + uint8_t addr[]; +} __packed; + +#define BTP_MMDL_DFU_UPDATE_METADATA_CHECK 0x61 +struct btp_mmdl_dfu_metadata_check_cmd { + uint8_t index; + uint8_t slot_idx; + uint8_t slot_size; + uint8_t fwid_len; + uint8_t metadata_len; + uint8_t data[]; +} __packed; + +struct btp_mmdl_dfu_metadata_check_rp { + uint8_t idx; + uint8_t status; + uint8_t effect; +} __packed; + +#define BTP_MMDL_DFU_FIRMWARE_UPDATE_GET 0x62 +#define BTP_MMDL_DFU_FIRMWARE_UPDATE_CANCEL 0x63 +#define BTP_MMDL_DFU_FIRMWARE_UPDATE_START 0x64 +struct btp_mmdl_dfu_firmware_update_cmd { + uint8_t addr_cnt; + uint8_t slot_idx; + uint8_t slot_size; + uint8_t fwid_len; + uint8_t metadata_len; + uint8_t block_size; + uint16_t chunk_size; + uint8_t data[]; +} __packed; + +struct btp_mmdl_dfu_firmware_update_rp { + uint8_t status; +} __packed; + +#define BTP_MMDL_BLOB_SRV_RECV 0x65 +struct btp_mmdl_blob_srv_recv_cmd { + uint64_t id; + uint16_t timeout; +} __packed; + +#define BTP_MMDL_BLOB_TRANSFER_START 0x66 +struct btp_mmdl_blob_transfer_start_cmd { + uint64_t id; + uint16_t size; + uint8_t block_size; + uint16_t chunk_size; + uint16_t timeout; +} __packed; + +#define BTP_MMDL_BLOB_TRANSFER_CANCEL 0x67 +#define BTP_MMDL_BLOB_TRANSFER_GET 0x68 +#define BTP_MMDL_BLOB_SRV_CANCEL 0x69 +#define BTP_MMDL_DFU_FIRMWARE_UPDATE_APPLY 0x6A +#define BTP_MMDL_DFU_SRV_APPLY 0x6B + /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { @@ -996,3 +1062,5 @@ struct btp_mesh_model_recv_ev { uint8_t payload_len; uint8_t payload[]; } __packed; + +#define MESH_EV_BLOB_LOST_TARGET 0x90 diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index b30eee70d44..84d4722a913 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -73,6 +73,9 @@ uint8_t tester_unregister_vocs(void); uint8_t tester_init_ias(void); uint8_t tester_unregister_ias(void); +uint8_t tester_init_mmdl(void); +uint8_t tester_unregister_mmdl(void); + uint8_t tester_init_gap(void); uint8_t tester_unregister_gap(void); diff --git a/tests/bluetooth/tester/src/btp_core.c b/tests/bluetooth/tester/src/btp_core.c index 36f92619bfc..7ece1224ed0 100644 --- a/tests/bluetooth/tester/src/btp_core.c +++ b/tests/bluetooth/tester/src/btp_core.c @@ -118,6 +118,9 @@ static uint8_t register_service(const void *cmd, uint16_t cmd_len, case BTP_SERVICE_ID_MESH: status = tester_init_mesh(); break; + case BTP_SERVICE_ID_MESH_MDL: + status = tester_init_mmdl(); + break; #endif /* CONFIG_BT_MESH */ #if defined(CONFIG_BT_VCP_VOL_REND) case BTP_SERVICE_ID_VCS: @@ -201,6 +204,9 @@ static uint8_t unregister_service(const void *cmd, uint16_t cmd_len, case BTP_SERVICE_ID_MESH: status = tester_unregister_mesh(); break; + case BTP_SERVICE_ID_MESH_MDL: + status = tester_unregister_mmdl(); + break; #endif /* CONFIG_BT_MESH */ #if defined(CONFIG_BT_VCP_VOL_REND) case BTP_SERVICE_ID_VCS: diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 40ae3a6f038..8c637320a11 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -12,15 +12,18 @@ #include #include #include +#include #include #include #include +#include #include #define LOG_MODULE_NAME bttester_mesh LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_BTTESTER_LOG_LEVEL); #include "btp/btp.h" +#include "dfu_slot.h" #define CID_LOCAL 0x05F1 #define COMPANY_ID_LF 0x05F1 @@ -54,7 +57,245 @@ static uint8_t vnd_app_key[16]; static uint16_t vnd_app_key_idx = 0x000f; /* Model send data */ -#define MODEL_BOUNDS_MAX 2 +#define MODEL_BOUNDS_MAX 100 + +#if defined(CONFIG_BT_MESH_BLOB_SRV) || defined(CONFIG_BT_MESH_BLOB_CLI) +/* BLOB Model data*/ +static uint8_t blob_rx_sum; +static bool blob_valid; +static const char *blob_data = "11111111111111111111111111111111"; + +static int blob_io_open(const struct bt_mesh_blob_io *io, + const struct bt_mesh_blob_xfer *xfer, + enum bt_mesh_blob_io_mode mode) +{ + blob_rx_sum = 0; + blob_valid = true; + return 0; +} + +static int blob_chunk_wr(const struct bt_mesh_blob_io *io, + const struct bt_mesh_blob_xfer *xfer, + const struct bt_mesh_blob_block *block, + const struct bt_mesh_blob_chunk *chunk) +{ + for (int i = 0; i < chunk->size; ++i) { + blob_rx_sum += chunk->data[i]; + if (chunk->data[i] != + blob_data[(i + chunk->offset) % strlen(blob_data)]) { + blob_valid = false; + } + } + + return 0; +} + +static int blob_chunk_rd(const struct bt_mesh_blob_io *io, + const struct bt_mesh_blob_xfer *xfer, + const struct bt_mesh_blob_block *block, + const struct bt_mesh_blob_chunk *chunk) +{ + for (int i = 0; i < chunk->size; ++i) { + chunk->data[i] = + blob_data[(i + chunk->offset) % strlen(blob_data)]; + } + + return 0; +} + +static const struct bt_mesh_blob_io dummy_blob_io = { + .open = blob_io_open, + .rd = blob_chunk_rd, + .wr = blob_chunk_wr, +}; +#endif + +#if defined(CONFIG_BT_MESH_DFD_SRV) +/* DFD Model data*/ +static int dfd_srv_recv(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot, + const struct bt_mesh_blob_io **io) +{ + LOG_DBG("Uploading new firmware image to the distributor."); + + *io = &dummy_blob_io; + + return 0; +} + +static void dfd_srv_del(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot) +{ + LOG_DBG("Deleting the firmware image from the distributor."); +} + +static int dfd_srv_send(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot, + const struct bt_mesh_blob_io **io) +{ + LOG_DBG("Starting the firmware distribution."); + + *io = &dummy_blob_io; + + return 0; +} + +static struct bt_mesh_dfd_srv_cb dfd_srv_cb = { + .recv = dfd_srv_recv, + .del = dfd_srv_del, + .send = dfd_srv_send, +}; + +static struct bt_mesh_dfd_srv dfd_srv = BT_MESH_DFD_SRV_INIT(&dfd_srv_cb); +#endif + +#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) +static struct { + struct bt_mesh_blob_cli_inputs inputs; + struct bt_mesh_blob_target targets[32]; + struct bt_mesh_blob_target_pull pull[32]; + uint8_t target_count; + struct bt_mesh_blob_xfer xfer; +} blob_cli_xfer; + +static void blob_cli_lost_target(struct bt_mesh_blob_cli *cli, + struct bt_mesh_blob_target *target, + enum bt_mesh_blob_status reason) +{ + LOG_DBG("Mesh Blob: Lost target 0x%04x (reason: %u)", target->addr, + reason); + tester_event(BTP_SERVICE_ID_MESH, MESH_EV_BLOB_LOST_TARGET, NULL, 0); +} + +static void blob_cli_caps(struct bt_mesh_blob_cli *cli, + const struct bt_mesh_blob_cli_caps *caps) +{ + const char *const modes[] = { + "none", + "push", + "pull", + "all", + }; + + if (!caps) { + LOG_DBG("None of the targets can be used for BLOB transfer"); + return; + } + + LOG_DBG("Mesh BLOB: capabilities:"); + LOG_DBG("\tMax BLOB size: %u bytes", caps->max_size); + LOG_DBG("\tBlock size: %u-%u (%u-%u bytes)", caps->min_block_size_log, + caps->max_block_size_log, 1 << caps->min_block_size_log, + 1 << caps->max_block_size_log); + LOG_DBG("\tMax chunks: %u", caps->max_chunks); + LOG_DBG("\tChunk size: %u", caps->max_chunk_size); + LOG_DBG("\tMTU size: %u", caps->mtu_size); + LOG_DBG("\tModes: %s", modes[caps->modes]); +} + +static void blob_cli_end(struct bt_mesh_blob_cli *cli, + const struct bt_mesh_blob_xfer *xfer, bool success) +{ + if (success) { + LOG_DBG("Mesh BLOB transfer complete."); + } else { + LOG_DBG("Mesh BLOB transfer failed."); + } +} + +static const struct bt_mesh_blob_cli_cb blob_cli_handlers = { + .lost_target = blob_cli_lost_target, + .caps = blob_cli_caps, + .end = blob_cli_end, +}; + +static struct bt_mesh_blob_cli blob_cli = { .cb = &blob_cli_handlers }; +#endif + +#if defined(CONFIG_BT_MESH_DFU_SRV) +const char *metadata_data = "1100000000000011"; + +static uint8_t dfu_fwid[] = { + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static struct bt_mesh_dfu_img dfu_imgs[] = { { + .fwid = &dfu_fwid, + .fwid_len = sizeof(dfu_fwid), +} }; + +static int dfu_meta_check(struct bt_mesh_dfu_srv *srv, + const struct bt_mesh_dfu_img *img, + struct net_buf_simple *metadata, + enum bt_mesh_dfu_effect *effect) +{ + char string[2 * CONFIG_BT_MESH_DFU_METADATA_MAXLEN + 1]; + int i; + size_t len; + + len = bin2hex(metadata->data, metadata->len, string, sizeof(string)); + string[len] = '\0'; + + for (i = 0; i <= len; i++) { + if (string[i] != metadata_data[i]) { + LOG_ERR("Wrong Firmware Metadata"); + return -EINVAL; + } + } + + return 0; +} + +static int dfu_start(struct bt_mesh_dfu_srv *srv, + const struct bt_mesh_dfu_img *img, + struct net_buf_simple *metadata, + const struct bt_mesh_blob_io **io) +{ + LOG_DBG("DFU setup"); + + *io = &dummy_blob_io; + + return 0; +} + +static void dfu_end(struct bt_mesh_dfu_srv *srv, + const struct bt_mesh_dfu_img *img, bool success) +{ + if (!success) { + LOG_ERR("DFU failed"); + return; + } + + if (!blob_valid) { + bt_mesh_dfu_srv_rejected(srv); + return; + } + + bt_mesh_dfu_srv_verified(srv); +} + +static int dfu_apply(struct bt_mesh_dfu_srv *srv, + const struct bt_mesh_dfu_img *img) +{ + if (!blob_valid) { + return -EINVAL; + } + + LOG_DBG("Applying DFU transfer..."); + + return 0; +} + +static const struct bt_mesh_dfu_srv_cb dfu_handlers = { + .check = dfu_meta_check, + .start = dfu_start, + .end = dfu_end, + .apply = dfu_apply, +}; + +static struct bt_mesh_dfu_srv dfu_srv = + BT_MESH_DFU_SRV_INIT(&dfu_handlers, dfu_imgs, ARRAY_SIZE(dfu_imgs)); +#endif /* CONFIG_BT_MESH_DFU_SRV */ /* Model Authentication Method */ #define AUTH_METHOD_STATIC 0x01 @@ -366,6 +607,16 @@ static struct bt_mesh_rpr_cli rpr_cli = { }; #endif +#if defined(CONFIG_BT_MESH_DFU_SRV) +static uint8_t dfu_srv_apply(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + LOG_DBG("Applying image on server"); + bt_mesh_dfu_srv_applied(&dfu_srv); + return BTP_STATUS_SUCCESS; +} +#endif + static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), @@ -389,8 +640,28 @@ static struct bt_mesh_model root_models[] = { #if defined(CONFIG_BT_MESH_RPR_SRV) BT_MESH_MODEL_RPR_SRV, #endif +#if defined(CONFIG_BT_MESH_DFD_SRV) + BT_MESH_MODEL_DFD_SRV(&dfd_srv), +#endif +#if defined(CONFIG_BT_MESH_DFU_SRV) + BT_MESH_MODEL_DFU_SRV(&dfu_srv), +#endif +#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) + BT_MESH_MODEL_BLOB_CLI(&blob_cli), +#endif }; +struct model_data *lookup_model_bound(uint16_t id) +{ + int i; + for (i = 0; i < ARRAY_SIZE(model_bound); i++) { + if (model_bound[i].model && model_bound[i].model->id == id) { + return &model_bound[i]; + } + } + + return NULL; +} static struct bt_mesh_model vnd_models[] = { BT_MESH_MODEL_VND(CID_LOCAL, VND_MODEL_ID_1, BT_MESH_MODEL_NO_OPS, NULL, NULL), @@ -3089,145 +3360,782 @@ static uint8_t rpr_reprov_remote(const void *cmd, uint16_t cmd_len, } #endif -static const struct btp_handler handlers[] = { - { - .opcode = BTP_MESH_READ_SUPPORTED_COMMANDS, - .index = BTP_INDEX_NONE, - .expect_len = 0, - .func = supported_commands, - }, - { - .opcode = BTP_MESH_CONFIG_PROVISIONING, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = config_prov, - }, - { - .opcode = BTP_MESH_PROVISION_NODE, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = provision_node, - }, - { - .opcode = BTP_MESH_INIT, - .expect_len = 0, - .func = init, - }, - { - .opcode = BTP_MESH_RESET, - .expect_len = 0, - .func = reset, - }, - { - .opcode = BTP_MESH_INPUT_NUMBER, - .expect_len = sizeof(struct btp_mesh_input_number_cmd), - .func = input_number, - }, - { - .opcode = BTP_MESH_INPUT_STRING, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = input_string, - }, - { - .opcode = BTP_MESH_IVU_TEST_MODE, - .expect_len = sizeof(struct btp_mesh_ivu_test_mode_cmd), - .func = ivu_test_mode, - }, - { - .opcode = BTP_MESH_IVU_TOGGLE_STATE, - .expect_len = 0, - .func = ivu_toggle_state, - }, - { - .opcode = BTP_MESH_LPN, - .expect_len = sizeof(struct btp_mesh_lpn_set_cmd), - .func = lpn, - }, - { - .opcode = BTP_MESH_LPN_POLL, - .expect_len = 0, - .func = lpn_poll, - }, - { - .opcode = BTP_MESH_NET_SEND, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = net_send, - }, - { - .opcode = BTP_MESH_HEALTH_GENERATE_FAULTS, - .expect_len = 0, - .func = health_generate_faults, - }, - { - .opcode = BTP_MESH_HEALTH_CLEAR_FAULTS, - .expect_len = 0, - .func = health_clear_faults, - }, - { - .opcode = BTP_MESH_MODEL_SEND, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = model_send, - }, - { - .opcode = BTP_MESH_COMP_DATA_GET, - .expect_len = sizeof(struct btp_mesh_comp_data_get_cmd), - .func = composition_data_get, - }, - { - .opcode = BTP_MESH_CFG_BEACON_GET, - .expect_len = sizeof(struct btp_mesh_cfg_beacon_get_cmd), - .func = config_beacon_get, - }, - { - .opcode = BTP_MESH_CFG_BEACON_SET, - .expect_len = sizeof(struct btp_mesh_cfg_beacon_set_cmd), - .func = config_beacon_set, - }, - { - .opcode = BTP_MESH_CFG_DEFAULT_TTL_GET, - .expect_len = sizeof(struct btp_mesh_cfg_default_ttl_get_cmd), - .func = config_default_ttl_get, - }, - { - .opcode = BTP_MESH_CFG_DEFAULT_TTL_SET, - .expect_len = sizeof(struct btp_mesh_cfg_default_ttl_set_cmd), - .func = config_default_ttl_set, - }, - { - .opcode = BTP_MESH_CFG_GATT_PROXY_GET, - .expect_len = sizeof(struct btp_mesh_cfg_gatt_proxy_get_cmd), - .func = config_gatt_proxy_get, - }, - { - .opcode = BTP_MESH_CFG_GATT_PROXY_SET, - .expect_len = sizeof(struct btp_mesh_cfg_gatt_proxy_set_cmd), - .func = config_gatt_proxy_set, - }, - { - .opcode = BTP_MESH_CFG_FRIEND_GET, - .expect_len = sizeof(struct btp_mesh_cfg_friend_get_cmd), - .func = config_friend_get, - }, - { - .opcode = BTP_MESH_CFG_FRIEND_SET, - .expect_len = sizeof(struct btp_mesh_cfg_friend_set_cmd), - .func = config_friend_set, - }, - { - .opcode = BTP_MESH_CFG_RELAY_GET, - .expect_len = sizeof(struct btp_mesh_cfg_relay_get_cmd), - .func = config_relay_get, - }, - { - .opcode = BTP_MESH_CFG_RELAY_SET, - .expect_len = sizeof(struct btp_mesh_cfg_relay_set_cmd), - .func = config_relay_set, - }, - { - .opcode = BTP_MESH_CFG_MODEL_PUB_GET, - .expect_len = sizeof(struct btp_mesh_cfg_model_pub_get_cmd), - .func = config_mod_pub_get, - }, - { - .opcode = BTP_MESH_CFG_MODEL_PUB_SET, +#if defined(CONFIG_BT_MESH_DFD_SRV) +static struct { + struct bt_mesh_dfu_target targets[32]; + struct bt_mesh_blob_target_pull pull[32]; + size_t target_cnt; + struct bt_mesh_blob_cli_inputs inputs; +} dfu_tx; + +static void dfu_tx_prepare(void) +{ + sys_slist_init(&dfu_tx.inputs.targets); + + for (int i = 0; i < dfu_tx.target_cnt; i++) { + /* Reset target context. */ + uint16_t addr = dfu_tx.targets[i].blob.addr; + + memset(&dfu_tx.targets[i].blob, 0, + sizeof(struct bt_mesh_blob_target)); + memset(&dfu_tx.pull[i], 0, + sizeof(struct bt_mesh_blob_target_pull)); + dfu_tx.targets[i].blob.addr = addr; + dfu_tx.targets[i].blob.pull = &dfu_tx.pull[i]; + + sys_slist_append(&dfu_tx.inputs.targets, + &dfu_tx.targets[i].blob.n); + } +} + +static void dfu_target(uint8_t img_idx, uint16_t addr) +{ + if (dfu_tx.target_cnt == ARRAY_SIZE(dfu_tx.targets)) { + LOG_ERR("No room."); + return; + } + + for (int i = 0; i < dfu_tx.target_cnt; i++) { + if (dfu_tx.targets[i].blob.addr == addr) { + LOG_ERR("Target 0x%04x already exists", addr); + return; + } + } + + dfu_tx.targets[dfu_tx.target_cnt].blob.addr = addr; + dfu_tx.targets[dfu_tx.target_cnt].img_idx = img_idx; + sys_slist_append(&dfu_tx.inputs.targets, + &dfu_tx.targets[dfu_tx.target_cnt].blob.n); + dfu_tx.target_cnt++; + + LOG_DBG("Added target 0x%04x", addr); +} +static void dfu_slot_add(size_t size, uint8_t *fwid, size_t fwid_len, + uint8_t *metadata, size_t metadata_len) +{ + struct bt_mesh_dfu_slot *slot; + int err; + + slot = bt_mesh_dfu_slot_reserve(); + err = bt_mesh_dfu_slot_info_set(slot, size, metadata, metadata_len); + if (err) { + LOG_ERR("Failed to set slot info: %d", err); + return; + } + + err = bt_mesh_dfu_slot_fwid_set(slot, fwid, fwid_len); + if (err) { + LOG_ERR("Failed to set slot fwid: %d", err); + return; + } + + bt_mesh_dfu_slot_commit(slot); + if (err) { + LOG_ERR("Failed to commit slot: %d", err); + return; + } + + LOG_DBG("Slot added."); +} +static enum bt_mesh_dfu_iter dfu_img_cb(struct bt_mesh_dfu_cli *cli, + struct bt_mesh_msg_ctx *ctx, + uint8_t idx, uint8_t total, + const struct bt_mesh_dfu_img *img, + void *cb_data) +{ + char fwid[2 * CONFIG_BT_MESH_DFU_FWID_MAXLEN + 1]; + size_t len; + + idx = 0xff; + + if (img->fwid_len <= sizeof(fwid)) { + len = bin2hex(img->fwid, img->fwid_len, fwid, sizeof(fwid)); + } else { + LOG_ERR("FWID is too big"); + return BT_MESH_DFU_ITER_STOP; + } + + fwid[len] = '\0'; + + LOG_DBG("Image %u:", idx); + LOG_DBG("\tFWID: "); + if (img->uri) { + LOG_DBG("\tURI: "); + } + + return BT_MESH_DFU_ITER_CONTINUE; +} + +static uint8_t dfu_info_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mmdl_dfu_info_get_cmd *cp = cmd; + struct model_data *model_bound; + struct bt_mesh_msg_ctx ctx = { + .net_idx = net.net_idx, + .send_ttl = BT_MESH_TTL_DEFAULT, + }; + uint8_t max_count; + int err = 0; + + LOG_DBG(""); + + model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); + if (!model_bound) { + LOG_ERR("Model not found"); + return BTP_STATUS_FAILED; + } + ctx.addr = model_bound->addr; + ctx.app_idx = model_bound->appkey_idx; + + max_count = cp->limit; + + err = bt_mesh_dfu_cli_imgs_get(&dfd_srv.dfu, &ctx, dfu_img_cb, NULL, + max_count); + if (err) { + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t dfu_update_metadata_check(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mmdl_dfu_metadata_check_cmd *cp = cmd; + struct btp_mmdl_dfu_metadata_check_rp *rp = rsp; + const struct bt_mesh_dfu_slot *slot; + struct model_data *model_bound; + struct bt_mesh_msg_ctx ctx = { + .net_idx = net.net_idx, + .send_ttl = BT_MESH_TTL_DEFAULT, + }; + struct bt_mesh_dfu_metadata_status rsp_data; + uint8_t img_idx, slot_idx; + size_t size; + size_t fwid_len; + size_t metadata_len; + uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; + uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN]; + int err; + + LOG_DBG(""); + + model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); + if (!model_bound) { + LOG_ERR("Model not found"); + return BTP_STATUS_FAILED; + } + + ctx.addr = model_bound->addr; + ctx.app_idx = model_bound->appkey_idx; + img_idx = cp->index; + slot_idx = cp->slot_idx; + size = cp->slot_size; + fwid_len = cp->fwid_len; + metadata_len = cp->metadata_len; + + if ((metadata_len > 0) && + (metadata_len < CONFIG_BT_MESH_DFU_METADATA_MAXLEN)) { + memcpy(&metadata, cp->data, metadata_len); + } + + dfu_slot_add(size, fwid, fwid_len, metadata, metadata_len); + + slot = bt_mesh_dfu_slot_at(slot_idx); + if (!slot) { + LOG_ERR("No image in slot %u", slot_idx); + return BTP_STATUS_FAILED; + } + + err = bt_mesh_dfu_cli_metadata_check(&dfd_srv.dfu, &ctx, img_idx, slot, + &rsp_data); + + if (err) { + LOG_ERR("ERR %d", err); + return BTP_STATUS_FAILED; + } + + rp->idx = rsp_data.idx; + rp->status = rsp_data.status; + rp->effect = rsp_data.effect; + + *rsp_len = sizeof(struct btp_mmdl_dfu_metadata_check_rp); + + return BTP_STATUS_SUCCESS; +} + +static uint8_t dfu_firmware_update_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + struct model_data *model_bound; + struct bt_mesh_msg_ctx ctx = { + .net_idx = net.net_idx, + .send_ttl = BT_MESH_TTL_DEFAULT, + }; + struct bt_mesh_dfu_target_status rsp_data; + struct btp_mmdl_dfu_firmware_update_rp *rp = rsp; + int err; + + LOG_DBG(""); + + model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); + if (!model_bound) { + LOG_ERR("Model not found"); + return BTP_STATUS_FAILED; + } + + ctx.addr = model_bound->addr; + ctx.app_idx = model_bound->appkey_idx; + + err = bt_mesh_dfu_cli_status_get(&dfd_srv.dfu, &ctx, &rsp_data); + if (err) { + LOG_ERR("err %d", err); + return BTP_STATUS_FAILED; + } + + rp->status = rsp_data.status; + *rsp_len = sizeof(struct btp_mmdl_dfu_firmware_update_rp); + return BTP_STATUS_SUCCESS; +} + +static uint8_t dfu_firmware_update_cancel(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + struct model_data *model_bound; + struct bt_mesh_msg_ctx ctx = { + .net_idx = net.net_idx, + .send_ttl = BT_MESH_TTL_DEFAULT, + }; + int err; + + LOG_DBG(""); + + model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); + if (!model_bound) { + LOG_ERR("Model not found"); + return BTP_STATUS_FAILED; + } + + ctx.addr = model_bound->addr; + ctx.app_idx = model_bound->appkey_idx; + + err = bt_mesh_dfu_cli_cancel(&dfd_srv.dfu, &ctx); + if (err) { + LOG_ERR("err %d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t dfu_firmware_update_start(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mmdl_dfu_firmware_update_cmd *cp = cmd; + struct model_data *model_bound; + struct bt_mesh_dfu_cli_xfer xfer; + uint8_t addr_cnt; + uint16_t addr = BT_MESH_ADDR_UNASSIGNED; + uint8_t slot_idx; + size_t size; + size_t fwid_len; + size_t metadata_len; + uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; + uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN]; + int err = 0; + int i = 0; + + LOG_DBG(""); + + model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); + if (!model_bound) { + LOG_ERR("Model not found"); + return BTP_STATUS_FAILED; + } + + struct bt_mesh_dfu_cli_xfer_blob_params blob = { + .block_size_log = cp->block_size, + .chunk_size = cp->chunk_size, + }; + + addr_cnt = cp->addr_cnt; + slot_idx = cp->slot_idx; + size = cp->slot_size; + fwid_len = cp->fwid_len; + metadata_len = cp->metadata_len; + xfer.mode = BT_MESH_BLOB_XFER_MODE_PUSH; + xfer.blob_params = &blob; + + if ((metadata_len > 0) && + (metadata_len < CONFIG_BT_MESH_DFU_METADATA_MAXLEN)) { + memcpy(&metadata, cp->data, metadata_len); + } + + bt_mesh_dfu_slot_del_all(); + + dfu_slot_add(size, fwid, fwid_len, metadata, metadata_len); + + xfer.slot = bt_mesh_dfu_slot_at(slot_idx); + if (!xfer.slot) { + LOG_ERR("No image in slot %u", slot_idx); + return BTP_STATUS_FAILED; + } + + for (i = 0; i < addr_cnt; i++) { + addr = cp->data[metadata_len + 1 + i * sizeof(uint16_t)] | + (cp->data[metadata_len + i * sizeof(uint16_t)] << 8); + dfu_target(slot_idx, addr); + } + + dfu_tx_prepare(); + + if (!dfu_tx.target_cnt) { + LOG_ERR("No targets."); + return BTP_STATUS_FAILED; + } + + if (addr_cnt > 1) { + dfu_tx.inputs.group = BT_MESH_ADDR_UNASSIGNED; + } else { + dfu_tx.inputs.group = addr; + } + + dfu_tx.inputs.app_idx = model_bound->appkey_idx; + dfu_tx.inputs.ttl = BT_MESH_TTL_DEFAULT; + + err = bt_mesh_dfu_cli_send(&dfd_srv.dfu, &dfu_tx.inputs, &dummy_blob_io, &xfer); + + if (err) { + LOG_ERR("err %d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t dfu_firmware_update_apply(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + struct model_data *model_bound; + int err; + + LOG_DBG(""); + + model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); + if (!model_bound) { + LOG_ERR("Model not found"); + return BTP_STATUS_FAILED; + } + + err = bt_mesh_dfu_cli_apply(&dfd_srv.dfu); + if (err) { + LOG_ERR("err %d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} +#endif + +#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) +static void blob_cli_inputs_prepare(uint16_t group, uint16_t app_idx) +{ + int i; + + blob_cli_xfer.inputs.ttl = BT_MESH_TTL_DEFAULT; + blob_cli_xfer.inputs.group = group; + blob_cli_xfer.inputs.app_idx = app_idx; + sys_slist_init(&blob_cli_xfer.inputs.targets); + + for (i = 0; i < blob_cli_xfer.target_count; ++i) { + /* Reset target context. */ + uint16_t addr = blob_cli_xfer.targets[i].addr; + + memset(&blob_cli_xfer.targets[i], 0, + sizeof(struct bt_mesh_blob_target)); + memset(&blob_cli_xfer.pull[i], 0, + sizeof(struct bt_mesh_blob_target_pull)); + blob_cli_xfer.targets[i].addr = addr; + blob_cli_xfer.targets[i].pull = &blob_cli_xfer.pull[i]; + + sys_slist_append(&blob_cli_xfer.inputs.targets, + &blob_cli_xfer.targets[i].n); + } +} + +static int cmd_blob_target(uint16_t addr) +{ + struct bt_mesh_blob_target *t; + + if (blob_cli_xfer.target_count == ARRAY_SIZE(blob_cli_xfer.targets)) { + LOG_ERR("No more room"); + return 0; + } + + t = &blob_cli_xfer.targets[blob_cli_xfer.target_count]; + + t->addr = addr; + + LOG_DBG("Added target 0x%04x", t->addr); + + blob_cli_xfer.target_count++; + return 0; +} + +static uint8_t blob_info_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mmdl_blob_info_get_cmd *cp = cmd; + struct model_data *model_bound; + uint16_t addr = BT_MESH_ADDR_UNASSIGNED; + uint16_t group = BT_MESH_ADDR_UNASSIGNED; + int err; + + LOG_DBG(""); + + model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_CLI); + if (!model_bound) { + LOG_ERR("Model not found"); + return BTP_STATUS_FAILED; + } + + for (int i = 0; i < cp->addr_cnt; i++) { + addr = cp->addr[1 + i * sizeof(uint16_t)] | + (cp->addr[i * sizeof(uint16_t)] << 8); + err = cmd_blob_target(addr); + if (err) { + LOG_ERR("err target %d", err); + return BTP_STATUS_FAILED; + } + } + + if (cp->addr_cnt > 1) { + group = BT_MESH_ADDR_UNASSIGNED; + } else { + group = addr; + } + + if (!blob_cli_xfer.target_count) { + LOG_ERR("Failed: No targets"); + return BTP_STATUS_FAILED; + } + + blob_cli_inputs_prepare(group, model_bound->appkey_idx); + + err = bt_mesh_blob_cli_caps_get(&blob_cli, &blob_cli_xfer.inputs); + + if (err) { + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t blob_transfer_start(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mmdl_blob_transfer_start_cmd *cp = cmd; + struct model_data *model_bound; + int err = 0; + + LOG_DBG(""); + + model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_CLI); + if (!model_bound) { + LOG_ERR("Model not found"); + return BTP_STATUS_FAILED; + } + + if (!blob_cli_xfer.target_count) { + LOG_ERR("Failed: No targets"); + return BTP_STATUS_FAILED; + } + blob_cli_xfer.xfer.id = cp->id; + blob_cli_xfer.xfer.size = cp->size; + blob_cli_xfer.xfer.block_size_log = cp->block_size; + blob_cli_xfer.xfer.chunk_size = cp->chunk_size; + + if (blob_cli.caps.modes) { + blob_cli_xfer.xfer.mode = blob_cli.caps.modes; + } else { + blob_cli_xfer.xfer.mode = BT_MESH_BLOB_XFER_MODE_PUSH; + } + + if (cp->timeout) { + blob_cli_xfer.inputs.timeout_base = cp->timeout; + } + + err = bt_mesh_blob_cli_send(&blob_cli, &blob_cli_xfer.inputs, + &blob_cli_xfer.xfer, &dummy_blob_io); + + if (err) { + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t blob_transfer_cancel(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + LOG_DBG(""); + + bt_mesh_blob_cli_cancel(&blob_cli); + + return BTP_STATUS_SUCCESS; +} + +static uint8_t blob_transfer_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + struct model_data *model_bound; + uint16_t group; + int err; + + LOG_DBG(""); + + model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_CLI); + if (!model_bound) { + LOG_ERR("Model not found"); + return BTP_STATUS_FAILED; + } + + group = model_bound->addr; + + err = cmd_blob_target(group); + if (err) { + LOG_ERR("err target %d", err); + return BTP_STATUS_FAILED; + } + + if (!blob_cli_xfer.target_count) { + LOG_ERR("Failed: No targets"); + return BTP_STATUS_FAILED; + } + + blob_cli_inputs_prepare(group, model_bound->appkey_idx); + + err = bt_mesh_blob_cli_xfer_progress_get(&blob_cli, &blob_cli_xfer.inputs); + + if (err) { + LOG_ERR("ERR %d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} +#endif /* CONFIG_BT_MESH_BLOB_CLI */ + +#if defined(CONFIG_BT_MESH_BLOB_SRV) +static uint8_t blob_srv_recv(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mmdl_blob_srv_recv_cmd *cp = cmd; + struct model_data *model_bound; + int err; + +#if defined(CONFIG_BT_MESH_DFU_SRV) + struct bt_mesh_blob_srv *srv = &dfu_srv.blob; +#elif defined(CONFIG_BT_MESH_DFD_SRV) + struct bt_mesh_blob_srv *srv = &dfd_srv.upload.blob; +#endif + + model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_SRV); + if (!model_bound) { + LOG_ERR("Model not found"); + return BTP_STATUS_FAILED; + } + + uint16_t timeout_base; + uint64_t id; + + LOG_DBG(""); + + id = cp->id; + timeout_base = cp->timeout; + + err = bt_mesh_blob_srv_recv(srv, id, &dummy_blob_io, BT_MESH_TTL_MAX, + timeout_base); + + if (err) { + LOG_ERR("ERR %d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t blob_srv_cancel(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + struct model_data *model_bound; + int err; + +#if defined(CONFIG_BT_MESH_DFU_SRV) + struct bt_mesh_blob_srv *srv = &dfu_srv.blob; +#elif defined(CONFIG_BT_MESH_DFD_SRV) + struct bt_mesh_blob_srv *srv = &dfd_srv.upload.blob; +#endif + + model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_SRV); + if (!model_bound) { + LOG_ERR("Model not found"); + return BTP_STATUS_FAILED; + } + + LOG_DBG(""); + + err = bt_mesh_blob_srv_cancel(srv); + + if (err) { + LOG_ERR("ERR %d", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} +#endif + +static const struct btp_handler handlers[] = { + { + .opcode = BTP_MESH_READ_SUPPORTED_COMMANDS, + .index = BTP_INDEX_NONE, + .expect_len = 0, + .func = supported_commands, + }, + { + .opcode = BTP_MESH_CONFIG_PROVISIONING, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = config_prov, + }, + { + .opcode = BTP_MESH_PROVISION_NODE, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = provision_node, + }, + { + .opcode = BTP_MESH_INIT, + .expect_len = 0, + .func = init, + }, + { + .opcode = BTP_MESH_RESET, + .expect_len = 0, + .func = reset, + }, + { + .opcode = BTP_MESH_INPUT_NUMBER, + .expect_len = sizeof(struct btp_mesh_input_number_cmd), + .func = input_number, + }, + { + .opcode = BTP_MESH_INPUT_STRING, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = input_string, + }, + { + .opcode = BTP_MESH_IVU_TEST_MODE, + .expect_len = sizeof(struct btp_mesh_ivu_test_mode_cmd), + .func = ivu_test_mode, + }, + { + .opcode = BTP_MESH_IVU_TOGGLE_STATE, + .expect_len = 0, + .func = ivu_toggle_state, + }, + { + .opcode = BTP_MESH_LPN, + .expect_len = sizeof(struct btp_mesh_lpn_set_cmd), + .func = lpn, + }, + { + .opcode = BTP_MESH_LPN_POLL, + .expect_len = 0, + .func = lpn_poll, + }, + { + .opcode = BTP_MESH_NET_SEND, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = net_send, + }, + { + .opcode = BTP_MESH_HEALTH_GENERATE_FAULTS, + .expect_len = 0, + .func = health_generate_faults, + }, + { + .opcode = BTP_MESH_HEALTH_CLEAR_FAULTS, + .expect_len = 0, + .func = health_clear_faults, + }, + { + .opcode = BTP_MESH_MODEL_SEND, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = model_send, + }, + { + .opcode = BTP_MESH_COMP_DATA_GET, + .expect_len = sizeof(struct btp_mesh_comp_data_get_cmd), + .func = composition_data_get, + }, + { + .opcode = BTP_MESH_CFG_BEACON_GET, + .expect_len = sizeof(struct btp_mesh_cfg_beacon_get_cmd), + .func = config_beacon_get, + }, + { + .opcode = BTP_MESH_CFG_BEACON_SET, + .expect_len = sizeof(struct btp_mesh_cfg_beacon_set_cmd), + .func = config_beacon_set, + }, + { + .opcode = BTP_MESH_CFG_DEFAULT_TTL_GET, + .expect_len = sizeof(struct btp_mesh_cfg_default_ttl_get_cmd), + .func = config_default_ttl_get, + }, + { + .opcode = BTP_MESH_CFG_DEFAULT_TTL_SET, + .expect_len = sizeof(struct btp_mesh_cfg_default_ttl_set_cmd), + .func = config_default_ttl_set, + }, + { + .opcode = BTP_MESH_CFG_GATT_PROXY_GET, + .expect_len = sizeof(struct btp_mesh_cfg_gatt_proxy_get_cmd), + .func = config_gatt_proxy_get, + }, + { + .opcode = BTP_MESH_CFG_GATT_PROXY_SET, + .expect_len = sizeof(struct btp_mesh_cfg_gatt_proxy_set_cmd), + .func = config_gatt_proxy_set, + }, + { + .opcode = BTP_MESH_CFG_FRIEND_GET, + .expect_len = sizeof(struct btp_mesh_cfg_friend_get_cmd), + .func = config_friend_get, + }, + { + .opcode = BTP_MESH_CFG_FRIEND_SET, + .expect_len = sizeof(struct btp_mesh_cfg_friend_set_cmd), + .func = config_friend_set, + }, + { + .opcode = BTP_MESH_CFG_RELAY_GET, + .expect_len = sizeof(struct btp_mesh_cfg_relay_get_cmd), + .func = config_relay_get, + }, + { + .opcode = BTP_MESH_CFG_RELAY_SET, + .expect_len = sizeof(struct btp_mesh_cfg_relay_set_cmd), + .func = config_relay_set, + }, + { + .opcode = BTP_MESH_CFG_MODEL_PUB_GET, + .expect_len = sizeof(struct btp_mesh_cfg_model_pub_get_cmd), + .func = config_mod_pub_get, + }, + { + .opcode = BTP_MESH_CFG_MODEL_PUB_SET, .expect_len = sizeof(struct btp_mesh_cfg_model_pub_set_cmd), .func = config_mod_pub_set, }, @@ -3577,6 +4485,83 @@ static const struct btp_handler handlers[] = { }, }; + +static const struct btp_handler mdl_handlers[] = { +#if defined(CONFIG_BT_MESH_DFD_SRV) + { + .opcode = BTP_MMDL_DFU_INFO_GET, + .expect_len = sizeof(struct btp_mmdl_dfu_info_get_cmd), + .func = dfu_info_get, + }, + { + .opcode = BTP_MMDL_DFU_UPDATE_METADATA_CHECK, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = dfu_update_metadata_check, + }, + { + .opcode = BTP_MMDL_DFU_FIRMWARE_UPDATE_GET, + .expect_len = 0, + .func = dfu_firmware_update_get, + }, + { + .opcode = BTP_MMDL_DFU_FIRMWARE_UPDATE_CANCEL, + .expect_len = 0, + .func = dfu_firmware_update_cancel, + }, + { + .opcode = BTP_MMDL_DFU_FIRMWARE_UPDATE_START, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = dfu_firmware_update_start, + }, + { + .opcode = BTP_MMDL_DFU_FIRMWARE_UPDATE_APPLY, + .expect_len = 0, + .func = dfu_firmware_update_apply, + }, +#endif +#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) + { + .opcode = BTP_MMDL_BLOB_INFO_GET, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = blob_info_get, + }, + { + .opcode = BTP_MMDL_BLOB_TRANSFER_START, + .expect_len = sizeof(struct btp_mmdl_blob_transfer_start_cmd), + .func = blob_transfer_start, + }, + { + .opcode = BTP_MMDL_BLOB_TRANSFER_CANCEL, + .expect_len = 0, + .func = blob_transfer_cancel, + }, + { + .opcode = BTP_MMDL_BLOB_TRANSFER_GET, + .expect_len = 0, + .func = blob_transfer_get, + }, +#endif +#if defined(CONFIG_BT_MESH_BLOB_SRV) + { + .opcode = BTP_MMDL_BLOB_SRV_RECV, + .expect_len = sizeof(struct btp_mmdl_blob_srv_recv_cmd), + .func = blob_srv_recv + }, + { + .opcode = BTP_MMDL_BLOB_SRV_CANCEL, + .expect_len = 0, + .func = blob_srv_cancel + }, +#endif +#if defined(CONFIG_BT_MESH_DFU_SRV) + { + .opcode = BTP_MMDL_DFU_SRV_APPLY, + .expect_len = 0, + .func = dfu_srv_apply + }, +#endif +}; + void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload, size_t payload_len) { @@ -3785,3 +4770,15 @@ uint8_t tester_unregister_mesh(void) { return BTP_STATUS_SUCCESS; } + +uint8_t tester_init_mmdl(void) +{ + tester_register_command_handlers(BTP_SERVICE_ID_MESH_MDL, mdl_handlers, + ARRAY_SIZE(mdl_handlers)); + return BTP_STATUS_SUCCESS; +} + +uint8_t tester_unregister_mmdl(void) +{ + return BTP_STATUS_SUCCESS; +} From 14e69effb12eee44178feadc4d8e9d0cac0b9cbd Mon Sep 17 00:00:00 2001 From: Michal Narajowski Date: Mon, 13 Jun 2022 14:09:32 +0200 Subject: [PATCH 0160/1623] [nrf fromtree] tests: bluetooth: tester: Add Opcodes Aggregator support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add entry for client and server in composition data. - Add Client commands to aggregate and send messages. MESH/SR/AGG/BV-02-C requires more key slots. Signed-off-by: Michal Narajowski (cherry picked from commit 1e5eeb83f41ae2c0dc50062ccfd921101cadaa1b) Signed-off-by: Alperen Şener (cherry picked from commit 05d9c3c2840602ba3c276986e3294482acbeb20a) --- tests/bluetooth/tester/overlay-mesh.conf | 5 + tests/bluetooth/tester/src/btp/btp_mesh.h | 10 ++ tests/bluetooth/tester/src/btp_mesh.c | 115 +++++++++++++++++++--- 3 files changed, 119 insertions(+), 11 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 3352e36f3a4..60f809f77e5 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -9,6 +9,11 @@ CONFIG_BT_MESH_GATT_PROXY=y CONFIG_BT_MESH_LABEL_COUNT=2 CONFIG_BT_MESH_SUBNET_COUNT=2 CONFIG_BT_MESH_MODEL_GROUP_COUNT=2 +CONFIG_BT_MESH_OP_AGG_CLI=y +CONFIG_BT_MESH_OP_AGG_SRV=y +# PTS requires more key slots. +# First one is implicitly taken by Device Key. +CONFIG_BT_MESH_MODEL_KEY_COUNT=3 CONFIG_BT_MESH_APP_KEY_COUNT=4 CONFIG_BT_MESH_IV_UPDATE_TEST=y CONFIG_BT_MESH_CFG_CLI=y diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 66a86bbb128..63fb2adcf12 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -835,6 +835,16 @@ struct btp_mesh_models_metadata_get_rp { uint8_t data[0]; } __packed; +#define BTP_MESH_OPCODES_AGGREGATOR_INIT 0x55 +struct btp_mesh_opcodes_aggregator_init_cmd { + uint16_t net_idx; + uint16_t app_idx; + uint16_t dst; + uint16_t elem_addr; +} __packed; + +#define BTP_MESH_OPCODES_AGGREGATOR_SEND 0x56 + #define BTP_MESH_COMP_CHANGE_PREPARE 0x57 #define BTP_MESH_SET_COMP_ALT 0x58 diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 8c637320a11..4f3d181fd1d 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -634,6 +634,12 @@ static struct bt_mesh_model root_models[] = { #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&lcd_cli), #endif +#if defined(CONFIG_BT_MESH_OP_AGG_SRV) + BT_MESH_MODEL_OP_AGG_SRV, +#endif +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) + BT_MESH_MODEL_OP_AGG_CLI, +#endif #if defined(CONFIG_BT_MESH_RPR_CLI) BT_MESH_MODEL_RPR_CLI(&rpr_cli), #endif @@ -2491,6 +2497,8 @@ static uint8_t config_model_app_bind(const void *cmd, uint16_t cmd_len, LOG_DBG(""); + bt_mesh_cfg_cli_timeout_set(5000); + err = bt_mesh_cfg_cli_mod_app_bind(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -2934,7 +2942,7 @@ static uint8_t health_fault_clear(const void *cmd, uint16_t cmd_len, .addr = sys_le16_to_cpu(cp->address), .app_idx = sys_le16_to_cpu(cp->app_idx), }; - uint8_t test_id; + uint8_t test_id = 0; size_t fault_count = 16; uint8_t faults[fault_count]; int err; @@ -2944,7 +2952,20 @@ static uint8_t health_fault_clear(const void *cmd, uint16_t cmd_len, if (cp->ack) { err = bt_mesh_health_cli_fault_clear(&health_cli, &ctx, sys_le16_to_cpu(cp->cid), - &test_id, faults, +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) + bt_mesh_op_agg_cli_seq_is_started() ? + NULL : +#endif + &test_id, +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) + bt_mesh_op_agg_cli_seq_is_started() ? + NULL : +#endif + faults, +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) + bt_mesh_op_agg_cli_seq_is_started() ? + NULL : +#endif &fault_count); } else { err = bt_mesh_health_cli_fault_clear_unack(&health_cli, &ctx, @@ -2977,20 +2998,37 @@ static uint8_t health_fault_test(const void *cmd, uint16_t cmd_len, }; size_t fault_count = 16; uint8_t faults[fault_count]; - uint8_t test_id; - uint16_t cid; int err; LOG_DBG(""); - test_id = cp->test_id; - cid = sys_le16_to_cpu(cp->cid); - if (cp->ack) { - err = bt_mesh_health_cli_fault_test(&health_cli, &ctx, cid, test_id, faults, + err = bt_mesh_health_cli_fault_test(&health_cli, &ctx, + sys_le16_to_cpu(cp->cid), +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) + bt_mesh_op_agg_cli_seq_is_started() ? + 0 : +#endif + cp->test_id, +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) + bt_mesh_op_agg_cli_seq_is_started() ? + NULL : +#endif + faults, +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) + bt_mesh_op_agg_cli_seq_is_started() ? + NULL : +#endif &fault_count); +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) + if (bt_mesh_op_agg_cli_seq_is_started()) { + fault_count = 0; + } +#endif } else { - err = bt_mesh_health_cli_fault_test_unack(&health_cli, &ctx, cid, test_id); + err = bt_mesh_health_cli_fault_test_unack(&health_cli, &ctx, + sys_le16_to_cpu(cp->cid), + cp->test_id); } if (err) { @@ -3001,8 +3039,8 @@ static uint8_t health_fault_test(const void *cmd, uint16_t cmd_len, if (cp->ack) { struct btp_mesh_health_fault_test_rp *rp = rsp; - rp->test_id = test_id; - rp->cid = sys_cpu_to_le16(cid); + rp->test_id = cp->test_id; + rp->cid = cp->cid; (void)memcpy(rp->faults, faults, fault_count); *rsp_len = sizeof(*rp) + fault_count; @@ -3051,6 +3089,10 @@ static uint8_t health_period_set(const void *cmd, uint16_t cmd_len, if (cp->ack) { err = bt_mesh_health_cli_period_set(&health_cli, &ctx, cp->divisor, +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) + bt_mesh_op_agg_cli_seq_is_started() ? + NULL : +#endif &updated_divisor); } else { err = bt_mesh_health_cli_period_set_unack(&health_cli, &ctx, cp->divisor); @@ -3112,6 +3154,10 @@ static uint8_t health_attention_set(const void *cmd, uint16_t cmd_len, if (cp->ack) { err = bt_mesh_health_cli_attention_set(&health_cli, &ctx, cp->attention, +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) + bt_mesh_op_agg_cli_seq_is_started() ? + NULL : +#endif &updated_attention); } else { err = bt_mesh_health_cli_attention_set_unack(&health_cli, &ctx, cp->attention); @@ -3133,6 +3179,41 @@ static uint8_t health_attention_set(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) +static uint8_t opcodes_aggregator_init(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_mesh_opcodes_aggregator_init_cmd *cp = cmd; + int err; + + LOG_DBG(""); + + err = bt_mesh_op_agg_cli_seq_start(cp->net_idx, cp->app_idx, cp->dst, cp->elem_addr); + if (err) { + LOG_ERR("Failed to init Opcodes Aggregator Context (err %d)", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t opcodes_aggregator_send(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + int err; + + LOG_DBG(""); + + err = bt_mesh_op_agg_cli_seq_send(); + if (err) { + LOG_ERR("Failed to send Opcodes Aggregator message (err %d)", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} +#endif + #if defined(CONFIG_BT_MESH_RPR_CLI) static uint8_t rpr_scan_start(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -4426,6 +4507,18 @@ static const struct btp_handler handlers[] = { .expect_len = sizeof(struct btp_mesh_models_metadata_get_cmd), .func = models_metadata_get }, +#endif +#if defined(CONFIG_BT_MESH_OP_AGG_CLI) + { + .opcode = BTP_MESH_OPCODES_AGGREGATOR_INIT, + .expect_len = sizeof(struct btp_mesh_opcodes_aggregator_init_cmd), + .func = opcodes_aggregator_init + }, + { + .opcode = BTP_MESH_OPCODES_AGGREGATOR_SEND, + .expect_len = 0, + .func = opcodes_aggregator_send + }, #endif { .opcode = BTP_MESH_COMP_CHANGE_PREPARE, From c77879087eaaae5206ba1274c86636d903ae119c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Thu, 23 Jun 2022 10:32:50 +0200 Subject: [PATCH 0161/1623] [nrf fromtree] Tests: Bluetooth: Tester: Add BTP command to enable Private NID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows to advertise beacons with Private Node Identity on demand, like was available for regular Node Identity. Signed-off-by: Krzysztof Kopyściński (cherry picked from commit 7b69f8faf0ee6457702fd6a37d020ceec8f9f9bc) Signed-off-by: Alperen Şener (cherry picked from commit f9c487715816b076127acaf0a98a5f37a9b490c5) --- tests/bluetooth/tester/overlay-mesh.conf | 3 + tests/bluetooth/tester/src/btp/btp_mesh.h | 38 +++++ tests/bluetooth/tester/src/btp_mesh.c | 177 ++++++++++++++++++++++ 3 files changed, 218 insertions(+) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 60f809f77e5..95a61769a1a 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -43,5 +43,8 @@ CONFIG_BT_MESH_BLOB_SRV=y CONFIG_BT_MESH_DFU_SRV=y CONFIG_BT_MESH_DFD_SRV=y CONFIG_BT_MESH_DFU_SLOT_CNT=2 +CONFIG_BT_MESH_PRIV_BEACONS=y +CONFIG_BT_MESH_PRIV_BEACON_SRV=y +CONFIG_BT_MESH_PRIV_BEACON_CLI=y CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 63fb2adcf12..e93c2ceeb3d 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -971,6 +971,44 @@ struct btp_mmdl_blob_transfer_start_cmd { #define BTP_MMDL_DFU_FIRMWARE_UPDATE_APPLY 0x6A #define BTP_MMDL_DFU_SRV_APPLY 0x6B +#define BTP_MESH_PRIV_BEACON_GET 0x6c +struct btp_priv_beacon_get_cmd { + uint16_t dst; +} __packed; + +#define BTP_MESH_PRIV_BEACON_SET 0x6d +struct btp_priv_beacon_set_cmd { + uint16_t dst; + uint8_t enabled; + uint8_t rand_interval; +} __packed; + +#define BTP_MESH_PRIV_GATT_PROXY_GET 0x6e +struct btp_priv_gatt_proxy_get_cmd { + uint16_t dst; +} __packed; + +#define BTP_MESH_PRIV_GATT_PROXY_SET 0x6f +struct btp_priv_gatt_proxy_set_cmd { + uint16_t dst; + uint8_t state; +} __packed; + +#define BTP_MESH_PRIV_NODE_ID_GET 0x70 +struct btp_priv_node_id_get_cmd { + uint16_t dst; + uint16_t key_net_idx; +} __packed; + +#define BTP_MESH_PRIV_NODE_ID_SET 0x71 +struct btp_priv_node_id_set_cmd { + uint16_t dst; + uint16_t net_idx; + uint8_t state; +} __packed; + +#define BTP_MESH_PROXY_PRIVATE_IDENTITY 0x72 + /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 4f3d181fd1d..5a7b4bb5fd7 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -617,6 +617,139 @@ static uint8_t dfu_srv_apply(const void *cmd, uint16_t cmd_len, } #endif +#ifdef CONFIG_BT_MESH_PRIV_BEACON_CLI +static struct bt_mesh_priv_beacon_cli priv_beacon_cli; + +static uint8_t priv_beacon_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_priv_beacon_get_cmd *cp = cmd; + + struct bt_mesh_priv_beacon val; + int err; + + err = bt_mesh_priv_beacon_cli_get(net.net_idx, cp->dst, &val); + if (err) { + LOG_ERR("Failed to send Private Beacon Get (err %d)", err); + return BTP_STATUS_FAILED; + } + + LOG_DBG("Private Beacon state: %u, %u", val.enabled, val.rand_interval); + return BTP_STATUS_SUCCESS; +} + +static uint8_t priv_beacon_set(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_priv_beacon_set_cmd *cp = cmd; + struct bt_mesh_priv_beacon val; + int err; + + val.enabled = cp->enabled; + val.rand_interval = cp->rand_interval; + + err = bt_mesh_priv_beacon_cli_set(net.net_idx, cp->dst, &val); + if (err) { + LOG_ERR("Failed to send Private Beacon Set (err %d)", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t priv_gatt_proxy_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_priv_gatt_proxy_get_cmd *cp = cmd; + + uint8_t state; + int err; + + err = bt_mesh_priv_beacon_cli_gatt_proxy_get(net.net_idx, cp->dst, &state); + if (err) { + LOG_ERR("Failed to send Private GATT Proxy Get (err %d)", err); + return BTP_STATUS_FAILED; + } + + LOG_DBG("Private GATT Proxy state: %u", state); + return BTP_STATUS_SUCCESS; +} + +static uint8_t priv_gatt_proxy_set(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_priv_gatt_proxy_set_cmd *cp = cmd; + + uint8_t state; + int err; + + state = cp->state; + + err = bt_mesh_priv_beacon_cli_gatt_proxy_set(net.net_idx, cp->dst, &state); + if (err) { + LOG_ERR("Failed to send Private GATT Proxy Set (err %d)", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t priv_node_id_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_priv_node_id_get_cmd *cp = cmd; + struct bt_mesh_priv_node_id val; + uint16_t key_net_idx; + int err; + + key_net_idx = cp->key_net_idx; + + err = bt_mesh_priv_beacon_cli_node_id_get(net.net_idx, cp->dst, key_net_idx, &val); + if (err) { + LOG_ERR("Failed to send Private Node Identity Get (err %d)", err); + return BTP_STATUS_FAILED; + } + + LOG_DBG("Private Node Identity state: %u %u %u", val.net_idx, val.state, val.status); + return BTP_STATUS_SUCCESS; +} + +static uint8_t priv_node_id_set(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_priv_node_id_set_cmd *cp = cmd; + struct bt_mesh_priv_node_id val; + int err; + + val.net_idx = cp->net_idx; + val.state = cp->state; + + err = bt_mesh_priv_beacon_cli_node_id_set(net.net_idx, cp->dst, &val); + if (err) { + LOG_ERR("Failed to send Private Node Identity Set (err %d)", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + +static uint8_t proxy_private_identity_enable(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + int err; + + LOG_DBG(""); + + err = bt_mesh_proxy_private_identity_enable(); + if (err) { + LOG_ERR("Failed to enable proxy private identity (err %d)", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} +#endif + static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), @@ -655,6 +788,12 @@ static struct bt_mesh_model root_models[] = { #if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) BT_MESH_MODEL_BLOB_CLI(&blob_cli), #endif +#if defined(CONFIG_BT_MESH_PRIV_BEACON_SRV) + BT_MESH_MODEL_PRIV_BEACON_SRV, +#endif +#if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI) + BT_MESH_MODEL_PRIV_BEACON_CLI(&priv_beacon_cli), +#endif }; struct model_data *lookup_model_bound(uint16_t id) { @@ -4576,6 +4715,44 @@ static const struct btp_handler handlers[] = { .expect_len = sizeof(struct btp_rpr_reprov_remote_cmd), .func = rpr_reprov_remote }, +#endif +#if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI) + { + .opcode = BTP_MESH_PRIV_BEACON_GET, + .expect_len = sizeof(struct btp_priv_beacon_get_cmd), + .func = priv_beacon_get + }, + { + .opcode = BTP_MESH_PRIV_BEACON_SET, + .expect_len = sizeof(struct btp_priv_beacon_set_cmd), + .func = priv_beacon_set + }, + { + .opcode = BTP_MESH_PRIV_GATT_PROXY_GET, + .expect_len = sizeof(struct btp_priv_gatt_proxy_get_cmd), + .func = priv_gatt_proxy_get + }, + { + .opcode = BTP_MESH_PRIV_GATT_PROXY_SET, + .expect_len = sizeof(struct btp_priv_gatt_proxy_set_cmd), + .func = priv_gatt_proxy_set + }, + { + .opcode = BTP_MESH_PRIV_NODE_ID_GET, + .expect_len = sizeof(struct btp_priv_node_id_get_cmd), + .func = priv_node_id_get + }, + { + .opcode = BTP_MESH_PRIV_NODE_ID_SET, + .expect_len = sizeof(struct btp_priv_node_id_set_cmd), + .func = priv_node_id_set + }, + { + .opcode = BTP_MESH_PROXY_PRIVATE_IDENTITY, + .expect_len = 0, + .func = proxy_private_identity_enable + }, +#endif }; From d629e26fb5e4ffc8e70de557700d6f98285a9db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Fri, 9 Sep 2022 11:40:32 +0200 Subject: [PATCH 0162/1623] [nrf fromtree] tests: Bluetooth: tester: enable Composition Data Page 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows to tests this page using BTP protocol. Signed-off-by: Krzysztof Kopyściński (cherry picked from commit 26e697bd04ccb702268949490733d93eeab3a303) Signed-off-by: Alperen Şener (cherry picked from commit 56bcf9cdb405ad62f768b51d057d0eb04eb78b8f) --- tests/bluetooth/tester/overlay-mesh.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 95a61769a1a..fe4c9a62fef 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -46,5 +46,7 @@ CONFIG_BT_MESH_DFU_SLOT_CNT=2 CONFIG_BT_MESH_PRIV_BEACONS=y CONFIG_BT_MESH_PRIV_BEACON_SRV=y CONFIG_BT_MESH_PRIV_BEACON_CLI=y +CONFIG_BT_MESH_MODEL_EXTENSIONS=y +CONFIG_BT_MESH_COMP_PAGE_1=y CONFIG_SETTINGS=y From 5237cdd07078a0064c3808f31d263e07f1d9ee42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Narajowski?= Date: Tue, 31 Jan 2023 14:44:41 +0100 Subject: [PATCH 0163/1623] [nrf fromtree] tests: Bluetooth: tester: Add Models Metadata Page 128 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Models Metadata Page 128 support to tester. Signed-off-by: Michal Narajowski Signed-off-by: Pavel Vasilyev (cherry picked from commit 2ad0eaa9ab548336fd37f064315f5427650a8c4f) Signed-off-by: Alperen Şener (cherry picked from commit c724d4f3a6a4d73e2b9ad8629e7fb4cc79dba1c6) --- tests/bluetooth/tester/src/btp_mesh.c | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 5a7b4bb5fd7..2c837bfb198 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -542,8 +542,31 @@ static uint8_t health_tests[] = { BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_NORDIC_SEMI, 3, 0x01, 0x02, 0x03), }; +static uint8_t zero_metadata[100]; + static struct bt_mesh_models_metadata_entry health_srv_meta[] = { BT_MESH_HEALTH_TEST_INFO_METADATA(health_tests), + { + .len = ARRAY_SIZE(zero_metadata), + .id = 0xABCD, + .data = zero_metadata, + }, + BT_MESH_MODELS_METADATA_END, +}; + +static uint8_t health_tests_alt[] = { + BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_LF, 6, 0x11, 0x22, 0x33, 0x44, 0x55, + 0x66), + BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_NORDIC_SEMI, 3, 0x11, 0x22, 0x33), +}; + +static struct bt_mesh_models_metadata_entry health_srv_meta_alt[] = { + BT_MESH_HEALTH_TEST_INFO_METADATA(health_tests_alt), + { + .len = ARRAY_SIZE(zero_metadata), + .id = 0xFEED, + .data = zero_metadata, + }, BT_MESH_MODELS_METADATA_END, }; #endif @@ -1709,6 +1732,13 @@ static uint8_t change_prepare(const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } +#if CONFIG_BT_MESH_LARGE_COMP_DATA_SRV + err = bt_mesh_models_metadata_change_prepare(); + if (err < 0) { + return BTP_STATUS_FAILED; + } +#endif + return BTP_STATUS_SUCCESS; } @@ -5026,6 +5056,9 @@ uint8_t tester_init_mesh(void) if (default_comp) { err = bt_mesh_init(&prov, &comp); } else { +#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV + health_srv.metadata = health_srv_meta_alt; +#endif err = bt_mesh_init(&prov, &comp_alt); } From fd0886b30723ba0a0309fd4d6c0e01442dc7dc4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Fri, 19 May 2023 14:29:50 +0200 Subject: [PATCH 0164/1623] [nrf fromtree] tests: Bluetooth: tester: add support for Proxy Solicitation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds BTP commands implemantation needed to pass tests for Proxy Solicitation. Signed-off-by: Krzysztof Kopyściński (cherry picked from commit a8334210c1fa59a662a07a8189c7313c9d0af218) Signed-off-by: Alperen Şener (cherry picked from commit 5bc10ca1d9c44d0811d02ac01aaffbe9f9ac6507) --- tests/bluetooth/tester/src/btp/btp_mesh.h | 27 +++++ tests/bluetooth/tester/src/btp_mesh.c | 138 ++++++++++++++++++++++ 2 files changed, 165 insertions(+) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index e93c2ceeb3d..ea5d89de07a 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -1009,6 +1009,33 @@ struct btp_priv_node_id_set_cmd { #define BTP_MESH_PROXY_PRIVATE_IDENTITY 0x72 +#define BTP_MESH_OD_PRIV_PROXY_GET 0x73 +struct btp_od_priv_proxy_get_cmd { + uint16_t dst; +} __packed; + +#define BTP_MESH_OD_PRIV_PROXY_SET 0x74 + +struct btp_od_priv_proxy_set_cmd { + uint16_t dst; + uint8_t val; +} __packed; + +#define BTP_MESH_SRPL_CLEAR 0x75 + +struct btp_srpl_clear_cmd { + uint16_t dst; + uint16_t range_start; + uint8_t range_len; + uint8_t acked; +} __packed; + +#define BTP_MESH_PROXY_SOLICIT 0x76 + +struct btp_proxy_solicit_cmd { + uint16_t net_idx; +} __packed; + /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 2c837bfb198..b9297474860 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -773,6 +773,108 @@ static uint8_t proxy_private_identity_enable(const void *cmd, uint16_t cmd_len, } #endif +#if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI) +static struct bt_mesh_sol_pdu_rpl_cli srpl_cli; +#endif + + +#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI) +static struct bt_mesh_od_priv_proxy_cli od_priv_proxy_cli; + +static uint8_t od_priv_proxy_get(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_od_priv_proxy_get_cmd *cp = cmd; + uint8_t val_rsp; + int err; + + LOG_DBG(""); + + err = bt_mesh_od_priv_proxy_cli_get(net.net_idx, cp->dst, &val_rsp); + if (err) { + LOG_ERR("Failed to get On-Demand Private Proxy state (err %d)", err); + return BTP_STATUS_FAILED; + } + + LOG_DBG("On-Demand Private Proxy state: %u", val_rsp); + + return BTP_STATUS_SUCCESS; +} + +static uint8_t od_priv_proxy_set(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_od_priv_proxy_set_cmd *cp = cmd; + uint8_t val_rsp; + int err; + + LOG_DBG(""); + + err = bt_mesh_od_priv_proxy_cli_set(net.net_idx, cp->dst, cp->val, &val_rsp); + if (err) { + LOG_ERR("Failed to set On-Demand Private Proxy state (err %d)", err); + return BTP_STATUS_FAILED; + } + + LOG_DBG("On-Demand Private Proxy set state: %u", val_rsp); + + return BTP_STATUS_SUCCESS; +} + +#endif + +#if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI) +static uint8_t srpl_clear(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_srpl_clear_cmd *cp = cmd; + uint16_t app_idx = BT_MESH_KEY_UNUSED; + uint16_t start_rsp; + uint8_t len_rsp; + int err; + + /* Lookup source address */ + for (int i = 0; i < ARRAY_SIZE(model_bound); i++) { + if (model_bound[i].model->id == BT_MESH_MODEL_ID_SOL_PDU_RPL_CLI) { + app_idx = model_bound[i].appkey_idx; + break; + } + } + + struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, cp->dst); + + if (cp->acked) { + err = bt_mesh_sol_pdu_rpl_clear(&ctx, cp->range_start, cp->range_len, &start_rsp, + &len_rsp); + } else { + err = bt_mesh_sol_pdu_rpl_clear_unack(&ctx, cp->range_start, cp->range_len); + } + if (err) { + LOG_ERR("Failed to clear SRPL (err %d)", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} +#endif + +#if defined(CONFIG_BT_MESH_PROXY_SOLICITATION) +static uint8_t proxy_solicit(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_proxy_solicit_cmd *cp = cmd; + int err; + + err = bt_mesh_proxy_solicit(cp->net_idx); + if (err) { + LOG_ERR("Failed to advertise solicitation PDU (err %d)", err); + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} +#endif /* CONFIG_BT_MESH_PROXY_SOLICITATION */ + static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), @@ -817,6 +919,16 @@ static struct bt_mesh_model root_models[] = { #if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI) BT_MESH_MODEL_PRIV_BEACON_CLI(&priv_beacon_cli), #endif +#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI) + BT_MESH_MODEL_OD_PRIV_PROXY_CLI(&od_priv_proxy_cli), +#endif +#if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI) + BT_MESH_MODEL_SOL_PDU_RPL_CLI(&srpl_cli), +#endif +#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) + BT_MESH_MODEL_OD_PRIV_PROXY_SRV, +#endif + }; struct model_data *lookup_model_bound(uint16_t id) { @@ -4783,6 +4895,32 @@ static const struct btp_handler handlers[] = { .func = proxy_private_identity_enable }, #endif +#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI) + { + .opcode = BTP_MESH_OD_PRIV_PROXY_GET, + .expect_len = sizeof(struct btp_od_priv_proxy_get_cmd), + .func = od_priv_proxy_get + }, + { + .opcode = BTP_MESH_OD_PRIV_PROXY_SET, + .expect_len = sizeof(struct btp_od_priv_proxy_set_cmd), + .func = od_priv_proxy_set + }, +#endif +#if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI) + { + .opcode = BTP_MESH_SRPL_CLEAR, + .expect_len = sizeof(struct btp_srpl_clear_cmd), + .func = srpl_clear + }, +#endif +#if defined(CONFIG_BT_MESH_SOLICITATION) + { + .opcode = BTP_MESH_PROXY_SOLICIT, + .expect_len = sizeof(struct btp_proxy_solicit_cmd), + .func = proxy_solicit + }, +#endif }; From 991f7b9e250d62a4df1e3322b28127e7ff3cd69e Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Fri, 22 Sep 2023 14:22:42 +0200 Subject: [PATCH 0165/1623] [nrf fromtree] tests: bluetooth: tester: Move mesh-1.1 features to a separate conf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows to compile mesh tester for 1.0.1 and 1.1 specs sepately. Signed-off-by: Pavel Vasilyev (cherry picked from commit b7579065f95535f16a1b5aaffed14437b51f7520) Signed-off-by: Alperen Şener (cherry picked from commit 0bdbe0cd58d2c7ff87db28c0215f0fb47a7d0c40) --- tests/bluetooth/tester/overlay-mesh-v1d1.conf | 29 +++++++++++++++++++ tests/bluetooth/tester/overlay-mesh.conf | 29 +------------------ tests/bluetooth/tester/testcase.yaml | 9 ++++++ 3 files changed, 39 insertions(+), 28 deletions(-) create mode 100644 tests/bluetooth/tester/overlay-mesh-v1d1.conf diff --git a/tests/bluetooth/tester/overlay-mesh-v1d1.conf b/tests/bluetooth/tester/overlay-mesh-v1d1.conf new file mode 100644 index 00000000000..7a3907cc78c --- /dev/null +++ b/tests/bluetooth/tester/overlay-mesh-v1d1.conf @@ -0,0 +1,29 @@ +CONFIG_ENTROPY_GENERATOR=y + +CONFIG_BT_MESH_V1d1=y +CONFIG_BT_MESH_OP_AGG_CLI=y +CONFIG_BT_MESH_OP_AGG_SRV=y +# PTS requires more key slots. +# First one is implicitly taken by Device Key. +CONFIG_BT_MESH_MODEL_KEY_COUNT=3 +CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y +CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y +CONFIG_BT_MESH_SAR_CFG_SRV=y +CONFIG_BT_MESH_SAR_CFG_CLI=y +CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 +CONFIG_BT_MESH_RPR_SRV=y +CONFIG_BT_MESH_RPR_CLI=y +CONFIG_BT_MESH_RPR_AD_TYPES_MAX=2 +CONFIG_BT_MESH_BLOB_CLI=y +CONFIG_BT_MESH_DFU_CLI=y +CONFIG_BT_MESH_BLOB_SRV=y +CONFIG_BT_MESH_DFU_SRV=y +CONFIG_BT_MESH_DFD_SRV=y +CONFIG_BT_MESH_DFU_SLOT_CNT=2 +CONFIG_BT_MESH_PRIV_BEACONS=y +CONFIG_BT_MESH_PRIV_BEACON_SRV=y +CONFIG_BT_MESH_PRIV_BEACON_CLI=y +CONFIG_BT_MESH_MODEL_EXTENSIONS=y +CONFIG_BT_MESH_COMP_PAGE_1=y + +CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index fe4c9a62fef..840af06c1c0 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -1,5 +1,4 @@ CONFIG_BT_MESH=y -CONFIG_BT_MESH_V1d1=y CONFIG_BT_MESH_RELAY=y CONFIG_BT_MESH_PB_ADV=y CONFIG_BT_MESH_PB_GATT=y @@ -9,23 +8,14 @@ CONFIG_BT_MESH_GATT_PROXY=y CONFIG_BT_MESH_LABEL_COUNT=2 CONFIG_BT_MESH_SUBNET_COUNT=2 CONFIG_BT_MESH_MODEL_GROUP_COUNT=2 -CONFIG_BT_MESH_OP_AGG_CLI=y -CONFIG_BT_MESH_OP_AGG_SRV=y -# PTS requires more key slots. -# First one is implicitly taken by Device Key. -CONFIG_BT_MESH_MODEL_KEY_COUNT=3 CONFIG_BT_MESH_APP_KEY_COUNT=4 CONFIG_BT_MESH_IV_UPDATE_TEST=y CONFIG_BT_MESH_CFG_CLI=y CONFIG_BT_MESH_HEALTH_CLI=y -CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y -CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y -CONFIG_BT_MESH_SAR_CFG_SRV=y -CONFIG_BT_MESH_SAR_CFG_CLI=y CONFIG_BT_MESH_FRIEND=y CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=32 CONFIG_BT_MESH_RX_SEG_MAX=13 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 +CONFIG_BT_MESH_TX_SEG_MSG_COUNT=3 CONFIG_BT_MESH_LPN_POLL_TIMEOUT=100 CONFIG_BT_MESH_PROVISIONER=y CONFIG_BT_MESH_CDB=y @@ -33,20 +23,3 @@ CONFIG_BT_MESH_CDB_NODE_COUNT=3 CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y CONFIG_BT_MESH_MSG_CACHE_SIZE=10 CONFIG_BT_MESH_PROXY_CLIENT=y -CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_RPR_SRV=y -CONFIG_BT_MESH_RPR_CLI=y -CONFIG_BT_MESH_RPR_AD_TYPES_MAX=2 -CONFIG_BT_MESH_BLOB_CLI=y -CONFIG_BT_MESH_DFU_CLI=y -CONFIG_BT_MESH_BLOB_SRV=y -CONFIG_BT_MESH_DFU_SRV=y -CONFIG_BT_MESH_DFD_SRV=y -CONFIG_BT_MESH_DFU_SLOT_CNT=2 -CONFIG_BT_MESH_PRIV_BEACONS=y -CONFIG_BT_MESH_PRIV_BEACON_SRV=y -CONFIG_BT_MESH_PRIV_BEACON_CLI=y -CONFIG_BT_MESH_MODEL_EXTENSIONS=y -CONFIG_BT_MESH_COMP_PAGE_1=y - -CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/testcase.yaml b/tests/bluetooth/tester/testcase.yaml index 65588568994..dba67716af1 100644 --- a/tests/bluetooth/tester/testcase.yaml +++ b/tests/bluetooth/tester/testcase.yaml @@ -25,3 +25,12 @@ tests: extra_args: OVERLAY_CONFIG="overlay-mesh.conf" tags: bluetooth harness: bluetooth + bluetooth.general.tester_mesh_v1d1: + build_only: true + platform_allow: + - qemu_x86 + - native_posix + - nrf52840dk_nrf52840 + extra_args: OVERLAY_CONFIG="overlay-mesh.conf;overlay-mesh-v1d1.conf" + tags: bluetooth + harness: bluetooth From 954d54fef79f1a2f7400098e2a58bf7b64ec9b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alperen=20=C5=9Eener?= Date: Wed, 6 Sep 2023 18:57:08 +0200 Subject: [PATCH 0166/1623] [nrf fromtree] tests: bluetooth: tester: add transfer ttl to mbt inputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit adding transfer ttl ixit value to be used as input for mbt test cases Signed-off-by: Alperen Şener (cherry picked from commit 90fac3045db59585f724fadc63adcaea9fcafd69) Signed-off-by: Alperen Şener (cherry picked from commit 591bc197f08512593a556c27ca1a4ca157f55b34) --- tests/bluetooth/tester/src/btp/btp_mesh.h | 2 ++ tests/bluetooth/tester/src/btp_mesh.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index ea5d89de07a..6c4a5e90106 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -954,6 +954,7 @@ struct btp_mmdl_dfu_firmware_update_rp { struct btp_mmdl_blob_srv_recv_cmd { uint64_t id; uint16_t timeout; + uint8_t ttl; } __packed; #define BTP_MMDL_BLOB_TRANSFER_START 0x66 @@ -963,6 +964,7 @@ struct btp_mmdl_blob_transfer_start_cmd { uint8_t block_size; uint16_t chunk_size; uint16_t timeout; + uint8_t ttl; } __packed; #define BTP_MMDL_BLOB_TRANSFER_CANCEL 0x67 diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index b9297474860..ffd4b69db84 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -4228,6 +4228,10 @@ static uint8_t blob_transfer_start(const void *cmd, uint16_t cmd_len, blob_cli_xfer.inputs.timeout_base = cp->timeout; } + if (cp->ttl) { + blob_cli_xfer.inputs.ttl = cp->ttl; + } + err = bt_mesh_blob_cli_send(&blob_cli, &blob_cli_xfer.inputs, &blob_cli_xfer.xfer, &dummy_blob_io); @@ -4311,13 +4315,15 @@ static uint8_t blob_srv_recv(const void *cmd, uint16_t cmd_len, uint16_t timeout_base; uint64_t id; + uint8_t ttl; LOG_DBG(""); id = cp->id; timeout_base = cp->timeout; + ttl = cp->ttl; - err = bt_mesh_blob_srv_recv(srv, id, &dummy_blob_io, BT_MESH_TTL_MAX, + err = bt_mesh_blob_srv_recv(srv, id, &dummy_blob_io, ttl, timeout_base); if (err) { From 0f4ef37e9e32afb8c4a006df4876d3d27146a75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alperen=20=C5=9Eener?= Date: Sat, 9 Sep 2023 19:41:26 +0200 Subject: [PATCH 0167/1623] [nrf fromtree] tests: bluetooth: tester: fix improper large comp rsp struct init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Large composition data response struct should have a data buffer to store the reponse data to Signed-off-by: Alperen Şener (cherry picked from commit a54c18ad31943d113b10bdebfbee7e9928ae7862) Signed-off-by: Alperen Şener (cherry picked from commit 092b4c26095cf34eec03970bfa7adc430ada76a5) --- tests/bluetooth/tester/src/btp_mesh.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index ffd4b69db84..f02d51c905a 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1761,7 +1761,12 @@ static uint8_t large_comp_data_get(const void *cmd, uint16_t cmd_len, struct btp_mesh_large_comp_data_get_rp *rp = rsp; int err; - struct bt_mesh_large_comp_data_rsp comp; + NET_BUF_SIMPLE_DEFINE(data, 500); + net_buf_simple_init(&data, 0); + + struct bt_mesh_large_comp_data_rsp comp = { + .data = &data, + }; err = bt_mesh_large_comp_data_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->addr), cp->page, @@ -1785,7 +1790,12 @@ static uint8_t models_metadata_get(const void *cmd, uint16_t cmd_len, struct btp_mesh_models_metadata_get_rp *rp = rsp; int err; - struct bt_mesh_large_comp_data_rsp metadata; + NET_BUF_SIMPLE_DEFINE(data, 500); + net_buf_simple_init(&data, 0); + + struct bt_mesh_large_comp_data_rsp metadata = { + .data = &data, + }; err = bt_mesh_models_metadata_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->addr), cp->page, From 1d3d0be5a5684572f422e1b5c9ee3afabe77c7a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alperen=20=C5=9Eener?= Date: Thu, 28 Sep 2023 15:48:04 +0200 Subject: [PATCH 0168/1623] [nrf fromtree] bluetooth: mesh: check upload slot before release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check if the slot is not reseved, NULL before try to releas it. Signed-off-by: Alperen Şener (cherry picked from commit 05e806d31d8ad7a37d20a07cdc32f7d68b044e5b) Signed-off-by: Alperen Şener (cherry picked from commit fc9b8d8ab912c3df2cd2bbf87b837830f4545496) --- subsys/bluetooth/mesh/dfd_srv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 54de343c94a..59fe5b830d1 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -477,7 +477,9 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx /* This will be a no-op if the slot state isn't RESERVED, which is * what we want. */ - bt_mesh_dfu_slot_release(srv->upload.slot); + if (srv->upload.slot) { + bt_mesh_dfu_slot_release(srv->upload.slot); + } #ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD srv->upload.is_oob = false; From cbeb833f4470fa050c5c43429298ec72e7a656b2 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Mon, 2 Oct 2023 18:52:30 +0300 Subject: [PATCH 0169/1623] [nrf fromtree] tests: btp_mesh: Check correct error code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check actual error code. Signed-off-by: Andrei Emeltchenko (cherry picked from commit ca1de2fc3961147269cc189c65e99f6f23fee3ce) Signed-off-by: Alperen Şener (cherry picked from commit 6246fab755e3d3cf68d6d5e2b58f35c94d886792) --- tests/bluetooth/tester/src/btp_mesh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index f02d51c905a..1d94eb43cb5 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -3801,7 +3801,7 @@ static void dfu_slot_add(size_t size, uint8_t *fwid, size_t fwid_len, return; } - bt_mesh_dfu_slot_commit(slot); + err = bt_mesh_dfu_slot_commit(slot); if (err) { LOG_ERR("Failed to commit slot: %d", err); return; From 058c19c5a8644dcb0817d720876bb5265776a7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alperen=20=C5=9Eener?= Date: Mon, 2 Oct 2023 01:14:16 +0200 Subject: [PATCH 0170/1623] [nrf fromtree] bluetooth: mesh: fix static oob auth padding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The remaining bit should be zero if auth is shorter than PROV_AUTH_MAX_LEN and it should be trimmed by removing octets with indexes higher than PROV_AUTH_MAX_LEN. Signed-off-by: Alperen Şener (cherry picked from commit fe6fb0f467c4b47cc33e1ffdd99ea976850d02a0) Signed-off-by: Alperen Şener (cherry picked from commit 6b356f778807f1e39c79ee83c260ff761ef0d5b1) --- subsys/bluetooth/mesh/prov_device.c | 18 ++++++++++-------- subsys/bluetooth/mesh/provisioner.c | 13 ++++++++----- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/prov_device.c index 0184463568f..992bf656202 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/prov_device.c @@ -192,14 +192,16 @@ static void prov_start(const uint8_t *data) } if (atomic_test_bit(bt_mesh_prov_link.flags, OOB_STATIC_KEY)) { - - uint8_t tail_size = bt_mesh_prov->static_val_len < auth_size - ? auth_size - bt_mesh_prov->static_val_len - : 0; - - memcpy(bt_mesh_prov_link.auth + tail_size, bt_mesh_prov->static_val, - tail_size ? bt_mesh_prov->static_val_len : auth_size); - memset(bt_mesh_prov_link.auth, 0, tail_size); + /* Trim the Auth if it is longer than required length */ + memcpy(bt_mesh_prov_link.auth, bt_mesh_prov->static_val, + bt_mesh_prov->static_val_len > auth_size ? auth_size + : bt_mesh_prov->static_val_len); + + /* Padd with zeros if the Auth is shorter the required length*/ + if (bt_mesh_prov->static_val_len < auth_size) { + memset(bt_mesh_prov_link.auth + bt_mesh_prov->static_val_len, 0, + auth_size - bt_mesh_prov->static_val_len); + } } } diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index 673e14578d2..361f373cb7b 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -751,17 +751,20 @@ int bt_mesh_auth_method_set_output(bt_mesh_output_action_t action, uint8_t size) int bt_mesh_auth_method_set_static(const uint8_t *static_val, uint8_t size) { - uint8_t tail_size = size < PROV_AUTH_MAX_LEN ? PROV_AUTH_MAX_LEN - size : 0; - if (!size || !static_val) { return -EINVAL; } prov_set_method(AUTH_METHOD_STATIC, 0, 0); - memcpy(bt_mesh_prov_link.auth + tail_size, static_val, - tail_size ? size : PROV_AUTH_MAX_LEN); - memset(bt_mesh_prov_link.auth, 0, tail_size); + /* Trim the Auth if it is longer than required length */ + memcpy(bt_mesh_prov_link.auth, static_val, + size > PROV_AUTH_MAX_LEN ? PROV_AUTH_MAX_LEN : size); + + /* Padd with zeros if the Auth is shorter the required length*/ + if (size < PROV_AUTH_MAX_LEN) { + memset(bt_mesh_prov_link.auth + size, 0, PROV_AUTH_MAX_LEN - size); + } return 0; } From 5cb1ed20ab2c98d0e0856219a355a7e7dd51394c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alperen=20=C5=9Eener?= Date: Fri, 29 Sep 2023 16:49:16 +0200 Subject: [PATCH 0171/1623] [nrf fromlist] bluetooth: tester: Enable composition data page 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enabling the composition data page 2 feature and adding tester support. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63441 Signed-off-by: Alperen Şener (cherry picked from commit 170558aa94d7f82a8852aea19a83f7dcc5f14ae3) --- tests/bluetooth/tester/overlay-mesh-v1d1.conf | 2 +- tests/bluetooth/tester/src/btp_mesh.c | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/overlay-mesh-v1d1.conf b/tests/bluetooth/tester/overlay-mesh-v1d1.conf index 7a3907cc78c..978d1acd3df 100644 --- a/tests/bluetooth/tester/overlay-mesh-v1d1.conf +++ b/tests/bluetooth/tester/overlay-mesh-v1d1.conf @@ -25,5 +25,5 @@ CONFIG_BT_MESH_PRIV_BEACON_SRV=y CONFIG_BT_MESH_PRIV_BEACON_CLI=y CONFIG_BT_MESH_MODEL_EXTENSIONS=y CONFIG_BT_MESH_COMP_PAGE_1=y - +CONFIG_BT_MESH_COMP_PAGE_2=y CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 1d94eb43cb5..af41c1518d5 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1103,6 +1103,22 @@ static const struct bt_mesh_comp comp_alt = { .vid = 2, }; +#if defined(CONFIG_BT_MESH_COMP_PAGE_2) +static const uint8_t cmp2_elem_offset[1] = {0}; + +static const struct bt_mesh_comp2_record comp_rec = { + .id = 0x1600, + .version.x = 1, + .version.y = 0, + .version.z = 0, + .elem_offset_cnt = 1, + .elem_offset = cmp2_elem_offset, + .data_len = 0 +}; + +static const struct bt_mesh_comp2 comp_p2 = {.record_cnt = 1, .record = &comp_rec}; +#endif + static struct bt_mesh_prov prov = { .uuid = dev_uuid, .static_val = static_auth, @@ -5205,6 +5221,10 @@ uint8_t tester_init_mesh(void) bt_test_cb_register(&bt_test_cb); } +#if defined(CONFIG_BT_MESH_COMP_PAGE_2) + bt_mesh_comp2_register(&comp_p2); +#endif + tester_register_command_handlers(BTP_SERVICE_ID_MESH, handlers, ARRAY_SIZE(handlers)); if (default_comp) { From 6319f2cfbe21cd9cac956922ad70595b149220a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alperen=20=C5=9Eener?= Date: Fri, 29 Sep 2023 15:10:10 +0200 Subject: [PATCH 0172/1623] [nrf fromlist] bluetooth: tester: add support for variable static oob size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding variable static auth size support to be compatible both mesh 1.0.1 and mesh 1.1. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63440 Signed-off-by: Alperen Şener (cherry picked from commit cafad7403fb4eaf5939c73db2fdfecff2bf65b11) --- tests/bluetooth/tester/src/btp/btp_mesh.h | 8 +++----- tests/bluetooth/tester/src/btp_mesh.c | 13 +++++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 6c4a5e90106..826f0fd0408 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -30,15 +30,12 @@ struct btp_mesh_read_supported_commands_rp { #define BTP_MESH_CONFIG_PROVISIONING 0x02 -#if IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM) -#define BTP_MESH_PROV_AUTH_MAX_LEN 32 -#else -#define BTP_MESH_PROV_AUTH_MAX_LEN 16 -#endif +#define BTP_MESH_PROV_AUTH_MAX_LEN 32 struct btp_mesh_config_provisioning_cmd { uint8_t uuid[16]; uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; + uint8_t static_auth_size; uint8_t out_size; uint16_t out_actions; uint8_t in_size; @@ -48,6 +45,7 @@ struct btp_mesh_config_provisioning_cmd { struct btp_mesh_config_provisioning_cmd_v2 { uint8_t uuid[16]; uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; + uint8_t static_auth_size; uint8_t out_size; uint16_t out_actions; uint8_t in_size; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index af41c1518d5..e83f1a67ba1 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -50,6 +50,7 @@ static uint8_t priv_key[32]; /* Configured provisioning data */ static uint8_t dev_uuid[16]; static uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; +static uint8_t static_auth_size; /* Vendor Model data */ #define VND_MODEL_ID_1 0x1234 @@ -1143,13 +1144,21 @@ static uint8_t config_prov(const void *cmd, uint16_t cmd_len, /* TODO consider fix BTP commands to avoid this */ if (cmd_len != sizeof(*cp) && cmd_len != (sizeof(*cp2))) { + LOG_DBG("wrong cmd size"); return BTP_STATUS_FAILED; } LOG_DBG(""); + static_auth_size = cp->static_auth_size; + + if (static_auth_size > BTP_MESH_PROV_AUTH_MAX_LEN || static_auth_size == 0) { + LOG_DBG("wrong static auth length"); + return BTP_STATUS_FAILED; + } + memcpy(dev_uuid, cp->uuid, sizeof(dev_uuid)); - memcpy(static_auth, cp->static_auth, sizeof(static_auth)); + memcpy(static_auth, cp->static_auth, cp->static_auth_size); prov.output_size = cp->out_size; prov.output_actions = sys_le16_to_cpu(cp->out_actions); @@ -1168,7 +1177,7 @@ static uint8_t config_prov(const void *cmd, uint16_t cmd_len, } else if (cp->auth_method == AUTH_METHOD_INPUT) { err = bt_mesh_auth_method_set_input(prov.input_actions, prov.input_size); } else if (cp->auth_method == AUTH_METHOD_STATIC) { - err = bt_mesh_auth_method_set_static(static_auth, sizeof(static_auth)); + err = bt_mesh_auth_method_set_static(static_auth, static_auth_size); } if (err) { From 27f8c5cbafa199be5c1945ab95bc5cbcff9ab8cd Mon Sep 17 00:00:00 2001 From: Mateusz Kapala Date: Wed, 4 Oct 2023 11:58:46 +0200 Subject: [PATCH 0173/1623] [nrf fromtree] bluetooth: host: smp: Add runtime check for central-specific path Added run-time BT_CENTRAL role check for the path that was central specific and did not have such check. When multi-role BT device tried to pair without bonding (peripheral role) while already previously bonded with the same device on another Bluetooth identity, pairing failed. It executed central-specific code, which should not be executed in case when the device acts as peripheral (as it is even opt-out from code when CONFIG_BT_CENTRAL is not enabled). Signed-off-by: Mateusz Kapala (cherry picked from commit 7a1b194a97e697578e459535752e6c3b1a75bdd9) (cherry picked from commit bbb68430f9586648b9f47ec01f96e19adf4edeb5) --- subsys/bluetooth/host/smp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index add06660bf6..9643982c421 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -4706,6 +4706,7 @@ static void bt_smp_encrypt_change(struct bt_l2cap_chan *chan, */ if (IS_ENABLED(CONFIG_BT_CENTRAL) && IS_ENABLED(CONFIG_BT_PRIVACY) && + conn->role == BT_HCI_ROLE_CENTRAL && !(smp->remote_dist & BT_SMP_DIST_ID_KEY)) { uint8_t smp_err; From 55f4b17ea515edd707dd2fc3a907911f270e088a Mon Sep 17 00:00:00 2001 From: Mateusz Kapala Date: Wed, 4 Oct 2023 11:59:06 +0200 Subject: [PATCH 0174/1623] [nrf fromtree] bluetooth: tests: Improve bondable_per_connection bsim test Added fail on pairing_failed callback for both central and peripheral. Added pairing status checks in peripheral. It has been done to test the case when multi-role BT device tried to pair without bonding (peripheral role) while already previously bonded with the same device on another Bluetooth identity as it seems that there was an issue with it previously. Signed-off-by: Mateusz Kapala (cherry picked from commit 3c0c6343407106e6ff4705a464bc93912ca37929) (cherry picked from commit 1f6d361cdbd5e112583cb217267783e9cb294130) --- .../host/security/bond_per_connection/src/bs_bt_utils.c | 6 ++++++ .../host/security/bond_per_connection/src/peripheral.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/tests/bsim/bluetooth/host/security/bond_per_connection/src/bs_bt_utils.c b/tests/bsim/bluetooth/host/security/bond_per_connection/src/bs_bt_utils.c index 1523e10d8a5..94b27a50b33 100644 --- a/tests/bsim/bluetooth/host/security/bond_per_connection/src/bs_bt_utils.c +++ b/tests/bsim/bluetooth/host/security/bond_per_connection/src/bs_bt_utils.c @@ -88,6 +88,11 @@ DEFINE_FLAG(flag_pairing_complete); DEFINE_FLAG(flag_bonded); DEFINE_FLAG(flag_not_bonded); +static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason) +{ + FAIL("Pairing failed (unexpected): reason %u\n", reason); +} + static void pairing_complete(struct bt_conn *conn, bool bonded) { SET_FLAG(flag_pairing_complete); @@ -100,6 +105,7 @@ static void pairing_complete(struct bt_conn *conn, bool bonded) } static struct bt_conn_auth_info_cb bt_conn_auth_info_cb = { + .pairing_failed = pairing_failed, .pairing_complete = pairing_complete, }; diff --git a/tests/bsim/bluetooth/host/security/bond_per_connection/src/peripheral.c b/tests/bsim/bluetooth/host/security/bond_per_connection/src/peripheral.c index 5e11d6ac712..01956d251df 100644 --- a/tests/bsim/bluetooth/host/security/bond_per_connection/src/peripheral.c +++ b/tests/bsim/bluetooth/host/security/bond_per_connection/src/peripheral.c @@ -33,6 +33,8 @@ void peripheral(void) wait_connected(); /* Central should bond here and trigger a disconnect. */ wait_disconnected(); + TAKE_FLAG(flag_pairing_complete); + TAKE_FLAG(flag_bonded); unpair(id_a); clear_g_conn(); @@ -43,6 +45,8 @@ void peripheral(void) wait_connected(); /* Central should bond here and trigger a disconnect. */ wait_disconnected(); + TAKE_FLAG(flag_pairing_complete); + TAKE_FLAG(flag_bonded); clear_g_conn(); printk("== Bonding id b - bond per-connection false ==\n"); @@ -51,6 +55,8 @@ void peripheral(void) wait_connected(); /* Central should pair without bond here and trigger a disconnect. */ wait_disconnected(); + TAKE_FLAG(flag_pairing_complete); + TAKE_FLAG(flag_not_bonded); PASS("PASS\n"); } From d73788b2457d22003d435da88143ee67881bdc43 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Thu, 28 Sep 2023 11:39:32 +0000 Subject: [PATCH 0175/1623] [nrf fromtree] modules/MCUboot: Add overwrite mode for MCUboot Add MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY mode. (cherry picked from commit 5d28fdea63b513582b975a276a20b2d5faff7a7a) Signed-off-by: Dominik Ermel (cherry picked from commit 0d08e4d5f29c903c619b0b74dcff3ba830b778fb) --- modules/Kconfig.mcuboot | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index 1679bfeb8a9..8df4bde8829 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -175,6 +175,18 @@ config MCUBOOT_BOOTLOADER_MODE_SWAP_SCRATCH MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected if MCUboot has been built with MCUBOOT_DOWNGRADE_PREVENTION. +config MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY + bool "MCUboot has been configured to just overwrite primary slot" + select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE + help + MCUboot will take contents of secondary slot of an image and will + overwrite primary slot with it. + In this mode it is not possible to revert back to previous version + as it is not stored in the secondary slot. + This mode supports MCUBOOT_BOOTLOADER_NO_DOWNGRADE which means + that the overwrite will not happen unless the version of secondary + slot is higher than the version in primary slot. + config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP bool "MCUboot has been configured for DirectXIP operation" select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE From 3d0052713f45333aa094a8c6d8896bd3b9c051ce Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Thu, 11 May 2023 15:15:08 +0000 Subject: [PATCH 0176/1623] [nrf fromtree] doc/services/device_mgmt: Bootloader info request definition Specification for MCUmgr OS group command allowing to query for bootloader information. Provide information on supported MCUboot parameters query by MCUmgr group OS. (cherry picked from commit 7668b4fbb35b98ca1c61029aedf72ff544b70236) Signed-off-by: Dominik Ermel (cherry picked from commit ccae85c1d48469cb22bd4f19cea322de502adc5f) --- .../device_mgmt/smp_groups/smp_group_0.rst | 211 +++++++++++++++++- 1 file changed, 208 insertions(+), 3 deletions(-) diff --git a/doc/services/device_mgmt/smp_groups/smp_group_0.rst b/doc/services/device_mgmt/smp_groups/smp_group_0.rst index 839b0e06be3..53907f33bcc 100644 --- a/doc/services/device_mgmt/smp_groups/smp_group_0.rst +++ b/doc/services/device_mgmt/smp_groups/smp_group_0.rst @@ -28,6 +28,8 @@ OS management group defines following commands: +-------------------+-----------------------------------------------+ | ``7`` | OS/Application info | +-------------------+-----------------------------------------------+ + | ``8`` | Bootloader information | + +-------------------+-----------------------------------------------+ Echo command ************ @@ -660,12 +662,215 @@ CBOR data of response: where: +.. table:: + :align: center + + +------------------+-------------------------------------------------------------------------+ + | "output" | Text response including requested parameters. | + +------------------+-------------------------------------------------------------------------+ + | "err" -> "group" | :c:enum:`mcumgr_group_t` group of the group-based error code. Only | + | | appears if an error is returned when using SMP version 2. | + +------------------+-------------------------------------------------------------------------+ + | "err" -> "rc" | contains the index of the group-based error code. Only appears if | + | | non-zero (error condition) when using SMP version 2. | + +------------------+-------------------------------------------------------------------------+ + | "rc" | :c:enum:`mcumgr_err_t` only appears if non-zero (error condition) when | + | | using SMP version 1 or for SMP errors when using SMP version 2. | + +------------------+-------------------------------------------------------------------------+ + +Bootloader Information +********************** + +Allows retrieving information about the on-board bootloader and its parameters. + +Bootloader Information Request +============================== + +Bootloader information request header: + +.. table:: + :align: center + + +--------+--------------+----------------+ + | ``OP`` | ``Group ID`` | ``Command ID`` | + +========+==============+================+ + | ``0`` | ``0`` | ``8`` | + +--------+--------------+----------------+ + +CBOR data of request: + +.. code-block:: none + + { + (str,opt)"query" : (str) + } + +where: + .. table:: :align: center +--------------+-----------------------------------------------+ - | "output" | Text response including requested parameters. | + | "query" | Is string representing query for parameters, | + | | with no restrictions how the query looks like | + | | as processing of query is left for bootloader | + | | backend. | + | | If there is no query, then response will | + | | return string identifying the bootloader. | +--------------+-----------------------------------------------+ - | "rc" | :c:enum:`mcumgr_err_t` | - | | only appears if non-zero (error condition). | + +Bootloader Information Response +=============================== + +Bootloader information response header: + +.. table:: + :align: center + + +--------+--------------+----------------+ + | ``OP`` | ``Group ID`` | ``Command ID`` | + +========+==============+================+ + | ``1`` | ``0`` | ``8`` | + +--------+--------------+----------------+ + +In case when no "query" has been provided in request, +CBOR data of response: + +.. code-block:: none + + { + (str)"bootloader" : (str) + } + +where: + +.. table:: + :align: center + + +--------------+-----------------------------------------------+ + | "bootloader" | String representing bootloader name | +--------------+-----------------------------------------------+ + +In case when "query" is provided: + +.. code-block:: none + + { + (str,opt) : () + ... + } + +where: + +.. table:: + :align: center + + +------------------+-------------------------------------------------------------------------+ + | | Response to "query". This is optional and may be left out in case when | + | | query yields no response, SMP version 2 error code of | + | | `OS_MGMT_ERR_QUERY_YIELDS_NO_ANSWER` is expected. | + | | Response may have more than one parameter reported back or it may be | + | | a map, that is dependent on bootloader backednd and query. | + +------------------+-------------------------------------------------------------------------+ + | ... | Parameter characteristic information. | + +------------------+-------------------------------------------------------------------------+ + +Parameter may be accompanied by additional, parameter specific, information keywords with +assigned values. + +In case of error the CBOR data takes the form: + +.. tabs:: + + .. group-tab:: SMP version 2 + + .. code-block:: none + + { + (str)"err" : { + (str)"group" : (uint) + (str)"rc" : (uint) + } + } + + .. group-tab:: SMP version 1 (and non-group SMP version 2) + + .. code-block:: none + + { + (str)"rc" : (int) + } + +where: + +.. table:: + :align: center + + +------------------+-------------------------------------------------------------------------+ + | "err" -> "group" | :c:enum:`mcumgr_group_t` group of the group-based error code. Only | + | | appears if an error is returned when using SMP version 2. | + +------------------+-------------------------------------------------------------------------+ + | "err" -> "rc" | contains the index of the group-based error code. Only appears if | + | | non-zero (error condition) when using SMP version 2. | + +------------------+-------------------------------------------------------------------------+ + | "rc" | :c:enum:`mcumgr_err_t` only appears if non-zero (error condition) when | + | | using SMP version 1 or for SMP errors when using SMP version 2. | + +------------------+-------------------------------------------------------------------------+ + +Bootloader Information: MCUboot +=============================== + +In case when MCUboot is application bootloader empty request will +be responded with: + +.. code-block:: none + + { + (str)"bootloader" : (str)"MCUboot" + } + +Currently "MCUboot" supports querying for mode of operation: + +.. code-block:: none + + { + (str)"query" : (str)"mode" + } + +Response to "mode" is: + +.. code-block:: none + + { + (str)"mode" : (int) + (str,opt)"no-downgrade" : (bool) + } + +where "mode" is one of: + +.. table:: + :align: center + + +-----+-----------------------------------------------------+ + | -1 | Unknown mode of MCUboot. | + +-----+-----------------------------------------------------+ + | 0 | MCUboot is in single application mode. | + +-----+-----------------------------------------------------+ + | 1 | MCUboot is in swap using scratch partition mode. | + +-----+-----------------------------------------------------+ + | 2 | MCUboot is in overwrite (upgrade-only) mode. | + +-----+-----------------------------------------------------+ + | 3 | MCUboot is in swap without scratch mode. | + +-----+-----------------------------------------------------+ + | 4 | MCUboot is in DirectXIP without revert mode. | + +-----+-----------------------------------------------------+ + | 5 | MCUboot is in DirectXIP with revert mode. | + +-----+-----------------------------------------------------+ + | 6 | MCUboot is in RAM loader mode. | + +-----+-----------------------------------------------------+ + +The "no-downgrade" is a flag, which is always sent when true, indicating that +mode has downgrade prevention enabled; downgrade prevention means that +if uploaded image has lower version than running, it will notbe taken +for exectuion by MCUboot. +MCUmgr may reject image with lower version in that MCUboot configuration. From b1ab980959dac1486bd6d781ec8b9c80bba21fac Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Thu, 28 Sep 2023 11:44:39 +0000 Subject: [PATCH 0177/1623] [nrf fromtree] doc/release-notes: MCUboot overwrite mode Kconfig info Note on CONFIG_MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY. (cherry picked from commit 83d69f50ada1fb22bee848a501e82a1683fc0aef) Signed-off-by: Dominik Ermel (cherry picked from commit 58706ac8d24d55d67c5e6c1427e3c36fe0839274) --- doc/releases/release-notes-3.5.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/releases/release-notes-3.5.rst b/doc/releases/release-notes-3.5.rst index d22978d8a84..82d2698849b 100644 --- a/doc/releases/release-notes-3.5.rst +++ b/doc/releases/release-notes-3.5.rst @@ -344,6 +344,11 @@ MCUboot with downgrade prevention enabled. This option is automatically selected for DirectXIP mode and is available for both swap modes. + * Added :kconfig:option:`CONFIG_MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY` + that allows to inform application that the on-board MCUboot will overwrite + the primary slot with secondary slot contents, without saving the original + image in primary slot. + Storage ******* From 8bef82541c679398d9886f211db6a8eb34f34760 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 15 May 2023 12:48:14 +0000 Subject: [PATCH 0178/1623] [nrf fromtree] mgmt/MCUmgr/grp/os: Add booloader info support Adds command allowing to query information on bootloader. In this case support is provided to query MCUboot information. (cherry picked from commit e48354455acbea481c102cf97be46d0abc720268) Signed-off-by: Dominik Ermel (cherry picked from commit cbe3d5fb40a7a737e4d17d81864335c7e1623508) --- .../zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h | 4 ++ subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt | 8 ++- subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig | 10 +++ subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c | 70 ++++++++++++++++++- 4 files changed, 90 insertions(+), 2 deletions(-) diff --git a/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h b/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h index 9c541e11c29..e1ac45e6389 100644 --- a/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h +++ b/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h @@ -24,6 +24,7 @@ extern "C" { #define OS_MGMT_ID_RESET 5 #define OS_MGMT_ID_MCUMGR_PARAMS 6 #define OS_MGMT_ID_INFO 7 +#define OS_MGMT_ID_BOOTLOADER_INFO 8 /** * Command result codes for OS management group. @@ -37,6 +38,9 @@ enum os_mgmt_err_code_t { /** The provided format value is not valid. */ OS_MGMT_ERR_INVALID_FORMAT, + + /** Query was not recognized. */ + OS_MGMT_ERR_QUERY_YIELDS_NO_ANSWER, }; /* Bitmask values used by the os info command handler. Note that the width of this variable is diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt b/subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt index e712acf6e94..35123fa1159 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt +++ b/subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt @@ -1,6 +1,6 @@ # # Copyright (c) 2018-2021 mcumgr authors -# Copyright (c) 2022 Nordic Semiconductor ASA +# Copyright (c) 2022-2023 Nordic Semiconductor ASA # # SPDX-License-Identifier: Apache-2.0 # @@ -12,6 +12,12 @@ zephyr_library_sources(src/os_mgmt.c) zephyr_library_include_directories(include) +if (CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO) + zephyr_include_directories( + ${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/bootutil/include + ) +endif() + if(DEFINED CONFIG_MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME) set(MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME_DIR ${PROJECT_BINARY_DIR}/os_mgmt_auto) file(MAKE_DIRECTORY ${MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME_DIR}) diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig b/subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig index 897db735982..fa743b53caf 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig +++ b/subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig @@ -173,6 +173,16 @@ config MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME endif +if BOOTLOADER_MCUBOOT + +config MCUMGR_GRP_OS_BOOTLOADER_INFO + bool "Bootloader information" + help + Allows to query MCUmgr about bootloader used by device and various bootloader + parameters. + +endif # BOOTLOADER_MCUBOOT + module = MCUMGR_GRP_OS module-str = mcumgr_grp_os source "subsys/logging/Kconfig.template.log_config" diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c b/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c index 55a6fa81564..a42e2f4022f 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c @@ -33,10 +33,15 @@ #include #endif -#ifdef CONFIG_MCUMGR_GRP_OS_INFO +#if defined(CONFIG_MCUMGR_GRP_OS_INFO) || defined(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO) #include #include +#if defined(CONFIG_MCUMGR_GRP_OS_INFO) #include +#endif +#if defined(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO) +#include +#endif #include #if defined(CONFIG_NET_HOSTNAME_ENABLE) #include @@ -370,6 +375,64 @@ os_mgmt_mcumgr_params(struct smp_streamer *ctxt) } #endif +#if defined(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO) + +#if IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP) +#define BOOTLOADER_MODE MCUBOOT_MODE_SINGLE_SLOT +#elif IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_SCRATCH) +#define BOOTLOADER_MODE MCUBOOT_MODE_SWAP_USING_SCRATCH +#elif IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY) +#define BOOTLOADER_MODE MCUBOOT_MODE_UPGRADE_ONLY +#elif IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_WITHOUT_SCRATCH) +#define BOOTLOADER_MODE MCUBOOT_MODE_SWAP_USING_MOVE +#elif IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) +#define BOOTLOADER_MODE MCUBOOT_MODE_DIRECT_XIP +#elif IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) +#define BOOTLOADER_MODE MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT +#else +#define BOOTLOADER_MODE -1 +#endif + +static int +os_mgmt_bootloader_info(struct smp_streamer *ctxt) +{ + zcbor_state_t *zse = ctxt->writer->zs; + zcbor_state_t *zsd = ctxt->reader->zs; + struct zcbor_string query = { 0 }; + size_t decoded; + bool ok; + + struct zcbor_map_decode_key_val bootloader_info[] = { + ZCBOR_MAP_DECODE_KEY_DECODER("query", zcbor_tstr_decode, &query), + }; + + if (zcbor_map_decode_bulk(zsd, bootloader_info, ARRAY_SIZE(bootloader_info), &decoded)) { + return MGMT_ERR_EINVAL; + } + + /* If no parameter is recognized then just introduce the bootloader. */ + if (decoded == 0) { + ok = zcbor_tstr_put_lit(zse, "bootloader") && + zcbor_tstr_put_lit(zse, "MCUboot"); + } else if (zcbor_map_decode_bulk_key_found(bootloader_info, ARRAY_SIZE(bootloader_info), + "query") && + (sizeof("mode") - 1) == query.len && + memcmp("mode", query.value, query.len) == 0) { + + ok = zcbor_tstr_put_lit(zse, "mode") && + zcbor_int32_put(zse, BOOTLOADER_MODE); +#if IS_ENABLED(MCUBOOT_BOOTLOADER_NO_DOWNGRADE) + ok = zcbor_tstr_put_lit(zse, "no-downgrade") && + zcbor_bool_encode(zse, true); +#endif + } else { + return OS_MGMT_ERR_QUERY_YIELDS_NO_ANSWER; + } + + return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE; +} +#endif + #ifdef CONFIG_MCUMGR_GRP_OS_INFO /** * Command handler: os info @@ -733,6 +796,11 @@ static const struct mgmt_handler os_mgmt_group_handlers[] = { os_mgmt_info, NULL }, #endif +#ifdef CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO + [OS_MGMT_ID_BOOTLOADER_INFO] = { + os_mgmt_bootloader_info, NULL + }, +#endif }; #define OS_MGMT_GROUP_SZ ARRAY_SIZE(os_mgmt_group_handlers) From 7d27517258a04103755733c102e74f11841a1318 Mon Sep 17 00:00:00 2001 From: Andrzej Kuros Date: Fri, 6 Oct 2023 08:41:49 +0200 Subject: [PATCH 0179/1623] [nrf fromlist] nrf53: fix RTC pretick power usage for events on RTC0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For RTC0 events the RTC1 pretick event was not cleared what caused the WDT to be not stopped. This resulted in increased power usage. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63597 Signed-off-by: Andrzej Kuroś (cherry picked from commit 6b30e02121a9852c98ba0c7600e041da24b2c1fd) --- soc/arm/nordic_nrf/nrf53/soc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index aa93dfd4b54..c18228ac4fa 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -410,6 +410,8 @@ static void rtc_pretick_rtc_isr_hook(void) { NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] &= ~IPC_PUBLISH_RECEIVE_EN_Msk; + + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); } void rtc_pretick_rtc0_isr_hook(void) @@ -420,10 +422,6 @@ void rtc_pretick_rtc0_isr_hook(void) void rtc_pretick_rtc1_isr_hook(void) { rtc_pretick_rtc_isr_hook(); - - if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); - } } static int rtc_pretick_cpunet_init(void) From aa88cae57f098f7caf7ed4aac6ba2abafbf0afe0 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 14 Sep 2023 14:25:18 +0200 Subject: [PATCH 0180/1623] [nrf fromtree] dts: bindings: arm: nordic,nrf-uicr add nfct-pins-as-gpios Allow configuring NFCT pins as GPIOs from devicetree. This setting is part of the UICR. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 1213ed4e8fdaf75a3d8eb3e9f9dc7b4d69d83722) (cherry picked from commit 8e6fa5754d9b77f0a68b7ffd8d3465561c6793cf) --- dts/bindings/arm/nordic,nrf-uicr.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/dts/bindings/arm/nordic,nrf-uicr.yaml b/dts/bindings/arm/nordic,nrf-uicr.yaml index 82ac8fc2089..dbbb34e1265 100644 --- a/dts/bindings/arm/nordic,nrf-uicr.yaml +++ b/dts/bindings/arm/nordic,nrf-uicr.yaml @@ -7,3 +7,15 @@ include: base.yaml properties: reg: required: true + + nfct-pins-as-gpios: + type: boolean + description: | + When enabled this property will configure pins dedicated to NFCT + peripheral as regular GPIOs. + + NFC pins in nRF52 series: P0.09 and P0.10 + NFC pins in nRF5340: P0.02 and P0.03 + + This setting, once applied, can only be unset by erasing the UICR + registers. Refer to the reference manual for more details. From 6f482d8e6f99115d9bd09d94855f76f491afc03c Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 14 Sep 2023 14:32:51 +0200 Subject: [PATCH 0181/1623] [nrf fromtree] modules: hal_nordic: inject CONFIG_NFCT_PINS_AS_GPIOS If the users configures this option in devicetree, ie, ``` &uicr { nfct-pins-as-gpios; }; ``` CMake will inject the HAL-specific CONFIG_NFCT_PINS_AS_GPIOS definition, so that the necessary operations are performed during system init. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit e43c2f3eb58cb98b0fcdbde3dba810a501747200) (cherry picked from commit 0e3c0a4d50aad34f045f228fc30da217f3a3ed92) --- modules/hal_nordic/nrfx/CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index 5842ae45ad5..98ba1961396 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -109,3 +109,16 @@ zephyr_library_sources_ifdef(CONFIG_NRFX_WDT ${SRC_DIR}/nrfx_wdt.c) if(CONFIG_NRFX_TWI OR CONFIG_NRFX_TWIM) zephyr_library_sources(${SRC_DIR}/nrfx_twi_twim.c) endif() + +# Inject HAL "CONFIG_NFCT_PINS_AS_GPIOS" definition if user requests to +# configure the NFCT pins as GPIOS. This way, the HAL will take care of doing +# the proper configuration sequence during system init + +dt_nodelabel(uicr_path NODELABEL "uicr") +if(${uicr_path}) + dt_prop(nfct_pins_as_gpios PATH ${uicr_path} PROPERTY "nfct-pins-as-gpios") + + if(${nfct_pins_as_gpios}) + zephyr_library_compile_definitions(CONFIG_NFCT_PINS_AS_GPIOS) + endif() +endif() From dda4a3bf0be6c10a1c48516f579b1ae5d6b9ff98 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 14 Sep 2023 14:39:01 +0200 Subject: [PATCH 0182/1623] [nrf fromtree] boards: arm: nrf: use UICR nfc-pins-as-gpios devicetree property Instead of CONFIG_NFCT_PINS_AS_GPIOS (about to be deprecated). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit dd568d01b89eb9e021027df140ae148144830663) (cherry picked from commit 848f5bf88c400b401a62779fb1993e5a5c853c39) --- boards/arm/bt610/bt610.dts | 4 ++++ boards/arm/bt610/bt610_defconfig | 1 - .../arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts | 4 ++++ .../nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig | 1 - .../arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts | 4 ++++ .../nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig | 1 - .../nrf5340_audio_dk_nrf5340_cpuapp.dts | 4 ++++ .../nrf5340_audio_dk_nrf5340_cpuapp_defconfig | 1 - boards/arm/pinetime_devkit0/pinetime_devkit0.dts | 4 ++++ boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig | 3 --- 10 files changed, 20 insertions(+), 7 deletions(-) diff --git a/boards/arm/bt610/bt610.dts b/boards/arm/bt610/bt610.dts index 3c047a50fcd..6bbe8d57fe3 100644 --- a/boards/arm/bt610/bt610.dts +++ b/boards/arm/bt610/bt610.dts @@ -143,6 +143,10 @@ status = "okay"; }; +&uicr { + nfct-pins-as-gpios; +}; + &gpio0 { status = "okay"; }; diff --git a/boards/arm/bt610/bt610_defconfig b/boards/arm/bt610/bt610_defconfig index 64f0fcb85ed..1c77ed9e37b 100644 --- a/boards/arm/bt610/bt610_defconfig +++ b/boards/arm/bt610/bt610_defconfig @@ -9,7 +9,6 @@ CONFIG_ARM_MPU=y # Enable GPIO CONFIG_GPIO=y -CONFIG_NFCT_PINS_AS_GPIOS=y # Enable uart driver CONFIG_SERIAL=y diff --git a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts index 616af71443c..8e835597c78 100644 --- a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts +++ b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts @@ -87,6 +87,10 @@ status = "okay"; }; +&uicr { + nfct-pins-as-gpios; +}; + &gpio0 { status = "okay"; }; diff --git a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig index 92ec1dc7885..90850c10e0a 100644 --- a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig +++ b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig @@ -15,6 +15,5 @@ CONFIG_GPIO=y # additional board options CONFIG_GPIO_AS_PINRESET=y -CONFIG_NFCT_PINS_AS_GPIOS=y CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts index f17ecb8e18a..93b59baa920 100644 --- a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts +++ b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts @@ -99,6 +99,10 @@ status = "okay"; }; +&uicr { + nfct-pins-as-gpios; +}; + &gpio0 { status = "okay"; }; diff --git a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig index f38880961d5..32a9d03b44e 100644 --- a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig +++ b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig @@ -15,7 +15,6 @@ CONFIG_GPIO=y # additional board options CONFIG_GPIO_AS_PINRESET=y -CONFIG_NFCT_PINS_AS_GPIOS=y CONFIG_PINCTRL=y diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp.dts b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp.dts index 8fe46bdd7a3..be871800332 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp.dts +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp.dts @@ -20,3 +20,7 @@ zephyr,sram-non-secure-partition = &sram0_ns; }; }; + +&uicr { + nfct-pins-as-gpios; +}; diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_defconfig b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_defconfig index 0f5f1991b6d..d1b5f551c9b 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_defconfig +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_defconfig @@ -12,7 +12,6 @@ CONFIG_HW_STACK_PROTECTION=y CONFIG_ARM_TRUSTZONE_M=y CONFIG_GPIO=y -CONFIG_NFCT_PINS_AS_GPIOS=y CONFIG_SERIAL=y diff --git a/boards/arm/pinetime_devkit0/pinetime_devkit0.dts b/boards/arm/pinetime_devkit0/pinetime_devkit0.dts index baad177740c..fb377fd89e1 100644 --- a/boards/arm/pinetime_devkit0/pinetime_devkit0.dts +++ b/boards/arm/pinetime_devkit0/pinetime_devkit0.dts @@ -87,6 +87,10 @@ status = "okay"; }; +&uicr { + nfct-pins-as-gpios; +}; + &gpio0 { status = "okay"; diff --git a/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig b/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig index 4e48c259730..ad7442afe0d 100644 --- a/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig +++ b/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig @@ -13,9 +13,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# use P0.09 and P0.10 as GPIOs -CONFIG_NFCT_PINS_AS_GPIOS=y - # use P0.21 as RST CONFIG_GPIO_AS_PINRESET=y From f18175381579045b4cf9ef9a9cb3d09c33832c70 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 14 Sep 2023 14:40:59 +0200 Subject: [PATCH 0183/1623] [nrf fromtree] soc: arm: nordic_nrf: deprecate CONFIG_NFCT_PINS_AS_GPIOS In favor of the new UICR nfct-pins-as-gpios devicetree property. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 0762008586976290d7a2f23b39489227b088e1fa) (cherry picked from commit 9332b9bbcaac7cfc8c34081da173548cf2498d54) --- soc/arm/nordic_nrf/Kconfig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/soc/arm/nordic_nrf/Kconfig b/soc/arm/nordic_nrf/Kconfig index 2c386f99a53..c2129db64b3 100644 --- a/soc/arm/nordic_nrf/Kconfig +++ b/soc/arm/nordic_nrf/Kconfig @@ -47,8 +47,9 @@ config NRF_ACL_FLASH_REGION_SIZE FLASH region size for the NRF_ACL peripheral. config NFCT_PINS_AS_GPIOS - bool "NFCT pins as GPIOs" + bool "[DEPRECATED] NFCT pins as GPIOs" depends on $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_NFCT)) + select DEPRECATED help Two pins are usually reserved for NFC in SoCs that implement the NFCT peripheral. This option switches them to normal GPIO mode. @@ -60,6 +61,13 @@ config NFCT_PINS_AS_GPIOS NFC pins in nRF52 series: P0.09 and P0.10 NFC pins in nRF5340: P0.02 and P0.03 + This option is deprecated, please use devicetree to configure NFCT + pins as GPIOS like this: + + &uicr { + nfct-pins-as-gpios; + }; + choice NRF_APPROTECT_HANDLING bool "APPROTECT handling" depends on SOC_SERIES_NRF52X || SOC_NRF5340_CPUNET || \ From d2aacb763ce42db6b11a46d7617e9a8f9fc5f745 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 14 Sep 2023 14:45:33 +0200 Subject: [PATCH 0184/1623] [nrf fromtree] doc: migration-guide: add notes on CONFIG_NFCT_PINS_AS_GPIOS changes So that users know how to migrate to the new option. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit c0bf310ac87e5339978e7d4072e2b93652830c7a) (cherry picked from commit 008212f5475b450f61b064313b85b571e2384a95) --- doc/releases/migration-guide-3.5.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/releases/migration-guide-3.5.rst b/doc/releases/migration-guide-3.5.rst index 7ffb16319d1..3f367ec5e35 100644 --- a/doc/releases/migration-guide-3.5.rst +++ b/doc/releases/migration-guide-3.5.rst @@ -42,3 +42,14 @@ Recommended Changes :kconfig:option:`CONFIG_GIC_V3` directly in Kconfig has been deprecated. The GIC version should now be specified by adding the appropriate compatible, for example :dtcompatible:`arm,gic-v2`, to the GIC node in the device tree. + +* Nordic nRF based boards using :kconfig:option:`CONFIG_NFCT_PINS_AS_GPIOS` + to configure NFCT pins as GPIOs, should instead set the new UICR + ``nfct-pins-as-gpios`` property in devicetree. It can be set like this in the + board devicetree files: + + .. code-block:: devicetree + + &uicr { + nfct-pins-as-gpios; + }; From 9fd2a0dff20d7b02531259295db889590566996e Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 18 Sep 2023 10:59:27 +0200 Subject: [PATCH 0185/1623] [nrf fromtree] dts: bindings: arm: nordic,nrf-uicr: add gpio-as-nreset So that the reset GPIO can be configured as nRESET from devicetree. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 55ec77cac7a8fc0e6b859c260812ef81b7d4d911) (cherry picked from commit 2cc08226dc04b2a08e456635c1f9e9e1fc14d253) --- dts/bindings/arm/nordic,nrf-uicr.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dts/bindings/arm/nordic,nrf-uicr.yaml b/dts/bindings/arm/nordic,nrf-uicr.yaml index dbbb34e1265..b39a6ed6855 100644 --- a/dts/bindings/arm/nordic,nrf-uicr.yaml +++ b/dts/bindings/arm/nordic,nrf-uicr.yaml @@ -19,3 +19,14 @@ properties: This setting, once applied, can only be unset by erasing the UICR registers. Refer to the reference manual for more details. + + gpio-as-nreset: + type: boolean + description: | + When enabled, this property will configure the reset GPIO as nRESET. + + nRESET pin in nRF52805/52810/52811/52832 series: P0.21 + nRESET pin in nRF52820/52833/52840 series: P0.18 + + This setting, once applied, can only be unset by erasing the UICR + registers. Refer to the reference manual for more details. From 23001717f6451eb5b14588a044525bc7dd7f07a5 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 18 Sep 2023 11:06:23 +0200 Subject: [PATCH 0186/1623] [nrf fromtree] modules: hal_nordic: nrfx: add support for 'gpio-as-nreset' So that the HAL's system init function configures the reset GPIO as nRESET if requested by the user. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 4d7d5ce226951d7bd54af38d7613e07b30641f09) (cherry picked from commit b8209dd8bb1a48dce10b34f33ca0aedf7f9b7dc6) --- modules/hal_nordic/nrfx/CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index 98ba1961396..e98db561906 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -111,14 +111,19 @@ if(CONFIG_NRFX_TWI OR CONFIG_NRFX_TWIM) endif() # Inject HAL "CONFIG_NFCT_PINS_AS_GPIOS" definition if user requests to -# configure the NFCT pins as GPIOS. This way, the HAL will take care of doing -# the proper configuration sequence during system init +# configure the NFCT pins as GPIOS. Do the same with "CONFIG_GPIO_AS_PINRESET" +# to configure the reset GPIO as nRESET. This way, the HAL will take care of +# doing the proper configuration sequence during system init dt_nodelabel(uicr_path NODELABEL "uicr") if(${uicr_path}) dt_prop(nfct_pins_as_gpios PATH ${uicr_path} PROPERTY "nfct-pins-as-gpios") - if(${nfct_pins_as_gpios}) zephyr_library_compile_definitions(CONFIG_NFCT_PINS_AS_GPIOS) endif() + + dt_prop(gpio_as_nreset PATH ${uicr_path} PROPERTY "gpio-as-nreset") + if(${gpio_as_nreset}) + zephyr_library_compile_definitions(CONFIG_GPIO_AS_PINRESET) + endif() endif() From 8c4003eacd144e0d1e593dd333d5bfa6c7a4d473 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 18 Sep 2023 11:34:15 +0200 Subject: [PATCH 0187/1623] [nrf fromtree] boards: arm: nrf-based: move all boards to gpio-as-nreset dt property Instead of using the about to be deprecated CONFIG_GPIO_AS_PINRESET option. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 012fa5c5ef2b314c92bf4f31634d71560d81d081) (cherry picked from commit 0a37f20794ee515d580c5d28e9b63555b945a7fe) --- boards/arm/96b_nitrogen/96b_nitrogen.dts | 4 ++++ boards/arm/96b_nitrogen/96b_nitrogen_defconfig | 3 --- boards/arm/acn52832/acn52832.dts | 4 ++++ boards/arm/acn52832/acn52832_defconfig | 3 --- .../adafruit_feather_nrf52840/adafruit_feather_nrf52840.dts | 4 ++++ .../adafruit_feather_nrf52840_defconfig | 3 --- .../adafruit_itsybitsy_nrf52840.dts | 4 ++++ .../adafruit_itsybitsy_nrf52840_defconfig | 2 -- .../arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi | 4 ++++ boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_defconfig | 3 --- .../arduino_nano_33_ble/arduino_nano_33_ble_sense_defconfig | 3 --- boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me.dts | 4 ++++ .../arduino_nicla_sense_me/arduino_nicla_sense_me_defconfig | 3 --- boards/arm/bl652_dvk/bl652_dvk.dts | 4 ++++ boards/arm/bl652_dvk/bl652_dvk_defconfig | 3 --- boards/arm/bl653_dvk/bl653_dvk.dts | 4 ++++ boards/arm/bl653_dvk/bl653_dvk_defconfig | 3 --- boards/arm/bl654_dvk/bl654_dvk.dts | 4 ++++ boards/arm/bl654_dvk/bl654_dvk_defconfig | 3 --- boards/arm/bl654_sensor_board/bl654_sensor_board.dts | 4 ++++ boards/arm/bl654_sensor_board/bl654_sensor_board_defconfig | 3 --- boards/arm/bl654_usb/bl654_usb.dts | 4 ++++ boards/arm/bl654_usb/bl654_usb_defconfig | 3 --- .../blueclover_plt_demo_v2_nrf52832.dts | 4 ++++ .../blueclover_plt_demo_v2_nrf52832_defconfig | 3 --- boards/arm/bt510/bt510.dts | 4 ++++ boards/arm/bt510/bt510_defconfig | 3 --- boards/arm/bt610/bt610.dts | 1 + boards/arm/bt610/bt610_defconfig | 3 --- .../contextualelectronics_abc/contextualelectronics_abc.dts | 4 ++++ .../contextualelectronics_abc_defconfig | 3 --- boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev.dts | 4 ++++ .../arm/decawave_dwm1001_dev/decawave_dwm1001_dev_defconfig | 3 --- boards/arm/degu_evk/degu_evk.dts | 4 ++++ boards/arm/degu_evk/degu_evk_defconfig | 1 - boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832.dts | 4 ++++ .../ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832_defconfig | 3 --- boards/arm/mg100/mg100.dts | 4 ++++ boards/arm/mg100/mg100_defconfig | 3 --- boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840.dts | 4 ++++ boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840_defconfig | 3 --- boards/arm/nrf52832_mdk/nrf52832_mdk.dts | 4 ++++ boards/arm/nrf52832_mdk/nrf52832_mdk_defconfig | 3 --- boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820.dts | 4 ++++ boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820_defconfig | 3 --- boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833.dts | 4 ++++ boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833_defconfig | 3 --- boards/arm/nrf52840_blip/nrf52840_blip.dts | 4 ++++ boards/arm/nrf52840_blip/nrf52840_blip_defconfig | 3 --- boards/arm/nrf52840_mdk/nrf52840_mdk.dts | 4 ++++ boards/arm/nrf52840_mdk/nrf52840_mdk_defconfig | 3 --- .../arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts | 1 + .../nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig | 3 --- boards/arm/nrf52840_papyr/nrf52840_papyr.dts | 4 ++++ boards/arm/nrf52840_papyr/nrf52840_papyr_defconfig | 3 --- boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811.dts | 4 ++++ boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811_defconfig | 3 --- boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts | 4 ++++ boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig | 3 --- .../arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts | 1 + .../nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig | 3 --- boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather.dts | 4 ++++ .../nrf52_adafruit_feather/nrf52_adafruit_feather_defconfig | 3 --- boards/arm/nrf52_sparkfun/nrf52_sparkfun.dts | 4 ++++ boards/arm/nrf52_sparkfun/nrf52_sparkfun_defconfig | 3 --- boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts | 4 ++++ boards/arm/nrf52_vbluno52/nrf52_vbluno52_defconfig | 3 --- boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805.dts | 4 ++++ boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805_defconfig | 3 --- boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810.dts | 4 ++++ boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810_defconfig | 3 --- boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts | 4 ++++ boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig | 3 --- boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840.dts | 4 ++++ boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840_defconfig | 3 --- boards/arm/pan1770_evb/pan1770_evb.dts | 4 ++++ boards/arm/pan1770_evb/pan1770_evb_defconfig | 3 --- boards/arm/pan1780_evb/pan1780_evb.dts | 4 ++++ boards/arm/pan1780_evb/pan1780_evb_defconfig | 3 --- boards/arm/pan1781_evb/pan1781_evb.dts | 4 ++++ boards/arm/pan1781_evb/pan1781_evb_defconfig | 3 --- boards/arm/pan1782_evb/pan1782_evb.dts | 4 ++++ boards/arm/pan1782_evb/pan1782_evb_defconfig | 3 --- boards/arm/particle_argon/particle_argon.dts | 4 ++++ boards/arm/particle_argon/particle_argon_defconfig | 3 --- boards/arm/particle_boron/particle_boron.dts | 4 ++++ boards/arm/particle_boron/particle_boron_defconfig | 3 --- boards/arm/particle_xenon/particle_xenon.dts | 4 ++++ boards/arm/particle_xenon/particle_xenon_defconfig | 3 --- boards/arm/pinetime_devkit0/pinetime_devkit0.dts | 4 ++++ boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig | 3 --- boards/arm/pinnacle_100_dvk/pinnacle_100_dvk.dts | 4 ++++ boards/arm/pinnacle_100_dvk/pinnacle_100_dvk_defconfig | 3 --- boards/arm/rak4631_nrf52840/rak4631_nrf52840.dts | 4 ++++ boards/arm/rak4631_nrf52840/rak4631_nrf52840_defconfig | 3 --- .../raytac_mdbt50q_db_33_nrf52833.dts | 4 ++++ .../raytac_mdbt50q_db_33_nrf52833_defconfig | 3 --- .../raytac_mdbt50q_db_40_nrf52840.dts | 4 ++++ .../raytac_mdbt50q_db_40_nrf52840_defconfig | 3 --- boards/arm/reel_board/dts/reel_board.dtsi | 4 ++++ boards/arm/reel_board/reel_board_defconfig | 3 --- boards/arm/reel_board/reel_board_v2_defconfig | 3 --- .../arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832.dts | 4 ++++ .../ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832_defconfig | 3 --- .../arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810.dts | 4 ++++ .../ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810_defconfig | 3 --- .../arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840.dts | 4 ++++ .../ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840_defconfig | 3 --- .../arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840.dts | 4 ++++ .../ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840_defconfig | 3 --- .../arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811.dts | 4 ++++ .../ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811_defconfig | 3 --- .../arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840.dts | 4 ++++ .../ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840_defconfig | 3 --- boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832.dts | 4 ++++ .../ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832_defconfig | 3 --- boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832.dts | 4 ++++ .../ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832_defconfig | 3 --- boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840.dts | 4 ++++ .../ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840_defconfig | 3 --- boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833.dts | 4 ++++ .../ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833_defconfig | 3 --- boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805.dts | 4 ++++ .../we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805_defconfig | 3 --- boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832.dts | 4 ++++ .../we_proteus2ev_nrf52832/we_proteus2ev_nrf52832_defconfig | 3 --- boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840.dts | 4 ++++ .../we_proteus3ev_nrf52840/we_proteus3ev_nrf52840_defconfig | 3 --- boards/arm/xiao_ble/xiao_ble_common.dtsi | 4 ++++ boards/arm/xiao_ble/xiao_ble_defconfig | 3 --- boards/arm/xiao_ble/xiao_ble_sense_defconfig | 3 --- 131 files changed, 247 insertions(+), 198 deletions(-) diff --git a/boards/arm/96b_nitrogen/96b_nitrogen.dts b/boards/arm/96b_nitrogen/96b_nitrogen.dts index d5bac1cd6d3..69148a032d7 100644 --- a/boards/arm/96b_nitrogen/96b_nitrogen.dts +++ b/boards/arm/96b_nitrogen/96b_nitrogen.dts @@ -58,6 +58,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/96b_nitrogen/96b_nitrogen_defconfig b/boards/arm/96b_nitrogen/96b_nitrogen_defconfig index 500c469813b..e804b43da5c 100644 --- a/boards/arm/96b_nitrogen/96b_nitrogen_defconfig +++ b/boards/arm/96b_nitrogen/96b_nitrogen_defconfig @@ -16,7 +16,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/acn52832/acn52832.dts b/boards/arm/acn52832/acn52832.dts index 1e01221f652..ca9f5046fba 100644 --- a/boards/arm/acn52832/acn52832.dts +++ b/boards/arm/acn52832/acn52832.dts @@ -45,6 +45,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/acn52832/acn52832_defconfig b/boards/arm/acn52832/acn52832_defconfig index 6b1ae1a7ba7..2bb13882f8c 100644 --- a/boards/arm/acn52832/acn52832_defconfig +++ b/boards/arm/acn52832/acn52832_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# Enable P0_21 as RST -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840.dts b/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840.dts index 5024f43fd81..284a4d24542 100644 --- a/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840.dts +++ b/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840.dts @@ -61,6 +61,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840_defconfig b/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840_defconfig index 8d892db30f2..1f42d1a0aa4 100644 --- a/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840_defconfig +++ b/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840.dts b/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840.dts index 6e827388aef..103e18d8328 100644 --- a/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840.dts +++ b/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840.dts @@ -55,6 +55,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840_defconfig b/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840_defconfig index bc27efcdd29..e5a88c27fb3 100644 --- a/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840_defconfig +++ b/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840_defconfig @@ -17,8 +17,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y CONFIG_PINCTRL=y # Flashing diff --git a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi index 60c0d63920c..200db7f94c7 100644 --- a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi +++ b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi @@ -177,6 +177,10 @@ arduino_spi: &spi2 { pinctrl-names = "default", "sleep"; }; +&uicr { + gpio-as-nreset; +}; + &gpio0 { status = "okay"; }; diff --git a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_defconfig b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_defconfig index 2d91725aaf9..dcdc0c8a836 100644 --- a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_defconfig +++ b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_defconfig @@ -20,7 +20,4 @@ CONFIG_UART_CONSOLE=y CONFIG_BOOTLOADER_BOSSA=y CONFIG_BOOTLOADER_BOSSA_LEGACY=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_sense_defconfig b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_sense_defconfig index 8ef8ece861c..4604c6bf386 100644 --- a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_sense_defconfig +++ b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_sense_defconfig @@ -20,7 +20,4 @@ CONFIG_UART_CONSOLE=y CONFIG_BOOTLOADER_BOSSA=y CONFIG_BOOTLOADER_BOSSA_LEGACY=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me.dts b/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me.dts index ada4c76441c..2329853a1a3 100644 --- a/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me.dts +++ b/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me.dts @@ -45,6 +45,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me_defconfig b/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me_defconfig index 396d37d36e0..c2f2b95cc72 100644 --- a/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me_defconfig +++ b/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me_defconfig @@ -18,8 +18,5 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # enable pin controller CONFIG_PINCTRL=y diff --git a/boards/arm/bl652_dvk/bl652_dvk.dts b/boards/arm/bl652_dvk/bl652_dvk.dts index 5569f1323c0..f2cffbd819b 100644 --- a/boards/arm/bl652_dvk/bl652_dvk.dts +++ b/boards/arm/bl652_dvk/bl652_dvk.dts @@ -68,6 +68,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/bl652_dvk/bl652_dvk_defconfig b/boards/arm/bl652_dvk/bl652_dvk_defconfig index 1ca971e2546..5302fa8d53f 100644 --- a/boards/arm/bl652_dvk/bl652_dvk_defconfig +++ b/boards/arm/bl652_dvk/bl652_dvk_defconfig @@ -21,9 +21,6 @@ CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y CONFIG_RTT_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # 32kHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y diff --git a/boards/arm/bl653_dvk/bl653_dvk.dts b/boards/arm/bl653_dvk/bl653_dvk.dts index ceb91aeb96f..ba8fa3658d2 100644 --- a/boards/arm/bl653_dvk/bl653_dvk.dts +++ b/boards/arm/bl653_dvk/bl653_dvk.dts @@ -91,6 +91,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/bl653_dvk/bl653_dvk_defconfig b/boards/arm/bl653_dvk/bl653_dvk_defconfig index 4933055c93c..83b73ef4435 100644 --- a/boards/arm/bl653_dvk/bl653_dvk_defconfig +++ b/boards/arm/bl653_dvk/bl653_dvk_defconfig @@ -20,9 +20,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # 32kHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y diff --git a/boards/arm/bl654_dvk/bl654_dvk.dts b/boards/arm/bl654_dvk/bl654_dvk.dts index b99435696d1..7ede69427de 100644 --- a/boards/arm/bl654_dvk/bl654_dvk.dts +++ b/boards/arm/bl654_dvk/bl654_dvk.dts @@ -91,6 +91,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/bl654_dvk/bl654_dvk_defconfig b/boards/arm/bl654_dvk/bl654_dvk_defconfig index aa2238cda87..976495f7e88 100644 --- a/boards/arm/bl654_dvk/bl654_dvk_defconfig +++ b/boards/arm/bl654_dvk/bl654_dvk_defconfig @@ -21,9 +21,6 @@ CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y CONFIG_RTT_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # 32kHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y diff --git a/boards/arm/bl654_sensor_board/bl654_sensor_board.dts b/boards/arm/bl654_sensor_board/bl654_sensor_board.dts index 1c2949ee2e8..c43354f2705 100644 --- a/boards/arm/bl654_sensor_board/bl654_sensor_board.dts +++ b/boards/arm/bl654_sensor_board/bl654_sensor_board.dts @@ -56,6 +56,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/bl654_sensor_board/bl654_sensor_board_defconfig b/boards/arm/bl654_sensor_board/bl654_sensor_board_defconfig index 259fac9d309..e92c2c4005f 100644 --- a/boards/arm/bl654_sensor_board/bl654_sensor_board_defconfig +++ b/boards/arm/bl654_sensor_board/bl654_sensor_board_defconfig @@ -17,9 +17,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# Additional board options -CONFIG_GPIO_AS_PINRESET=y - # 32KHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM=y diff --git a/boards/arm/bl654_usb/bl654_usb.dts b/boards/arm/bl654_usb/bl654_usb.dts index 2cc6850a468..80600290dbf 100644 --- a/boards/arm/bl654_usb/bl654_usb.dts +++ b/boards/arm/bl654_usb/bl654_usb.dts @@ -47,6 +47,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &gpio0 { status = "okay"; }; diff --git a/boards/arm/bl654_usb/bl654_usb_defconfig b/boards/arm/bl654_usb/bl654_usb_defconfig index 59c26ddb4d7..983150c35d9 100644 --- a/boards/arm/bl654_usb/bl654_usb_defconfig +++ b/boards/arm/bl654_usb/bl654_usb_defconfig @@ -19,9 +19,6 @@ CONFIG_GPIO=y # Enable USB CONFIG_USB_DEVICE_STACK=y -# Additional board options -CONFIG_GPIO_AS_PINRESET=y - # 32KHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM=y diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts index cf7dd7a52de..4c49979bb0a 100644 --- a/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts @@ -48,6 +48,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status ="okay"; }; diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig index 52f089ba0d6..301a23af362 100644 --- a/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig @@ -24,7 +24,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/bt510/bt510.dts b/boards/arm/bt510/bt510.dts index 74818be0d7c..984b098e5d5 100644 --- a/boards/arm/bt510/bt510.dts +++ b/boards/arm/bt510/bt510.dts @@ -72,6 +72,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/bt510/bt510_defconfig b/boards/arm/bt510/bt510_defconfig index fd86ea3f0f2..eb769cc9465 100644 --- a/boards/arm/bt510/bt510_defconfig +++ b/boards/arm/bt510/bt510_defconfig @@ -17,9 +17,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# Additional board options -CONFIG_GPIO_AS_PINRESET=y - # 32KHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM=y diff --git a/boards/arm/bt610/bt610.dts b/boards/arm/bt610/bt610.dts index 6bbe8d57fe3..489401a5fb3 100644 --- a/boards/arm/bt610/bt610.dts +++ b/boards/arm/bt610/bt610.dts @@ -145,6 +145,7 @@ &uicr { nfct-pins-as-gpios; + gpio-as-nreset; }; &gpio0 { diff --git a/boards/arm/bt610/bt610_defconfig b/boards/arm/bt610/bt610_defconfig index 1c77ed9e37b..d1d7226fade 100644 --- a/boards/arm/bt610/bt610_defconfig +++ b/boards/arm/bt610/bt610_defconfig @@ -17,9 +17,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# Additional board options -CONFIG_GPIO_AS_PINRESET=y - # Enable hardware stack protection CONFIG_HW_STACK_PROTECTION=y diff --git a/boards/arm/contextualelectronics_abc/contextualelectronics_abc.dts b/boards/arm/contextualelectronics_abc/contextualelectronics_abc.dts index ebc866afeff..6f60b1ddfed 100644 --- a/boards/arm/contextualelectronics_abc/contextualelectronics_abc.dts +++ b/boards/arm/contextualelectronics_abc/contextualelectronics_abc.dts @@ -25,6 +25,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/contextualelectronics_abc/contextualelectronics_abc_defconfig b/boards/arm/contextualelectronics_abc/contextualelectronics_abc_defconfig index bb841469339..7a3055b9c82 100644 --- a/boards/arm/contextualelectronics_abc/contextualelectronics_abc_defconfig +++ b/boards/arm/contextualelectronics_abc/contextualelectronics_abc_defconfig @@ -20,7 +20,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# Additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev.dts b/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev.dts index 75510faf4a6..a1c415fc299 100644 --- a/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev.dts +++ b/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev.dts @@ -84,6 +84,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev_defconfig b/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev_defconfig index 89d31bfd45b..4cb6022e7ae 100644 --- a/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev_defconfig +++ b/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev_defconfig @@ -21,7 +21,4 @@ CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y CONFIG_RTT_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/degu_evk/degu_evk.dts b/boards/arm/degu_evk/degu_evk.dts index caa134752e0..eb3329726e9 100644 --- a/boards/arm/degu_evk/degu_evk.dts +++ b/boards/arm/degu_evk/degu_evk.dts @@ -92,6 +92,10 @@ status ="okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status ="okay"; }; diff --git a/boards/arm/degu_evk/degu_evk_defconfig b/boards/arm/degu_evk/degu_evk_defconfig index 7b9d7737481..e003438c3dc 100644 --- a/boards/arm/degu_evk/degu_evk_defconfig +++ b/boards/arm/degu_evk/degu_evk_defconfig @@ -17,7 +17,6 @@ CONFIG_USB_DEVICE_STACK=y # additional board options CONFIG_GPIO=y -CONFIG_GPIO_AS_PINRESET=y # required to enable 3V3 power rail and Vin1 monitor CONFIG_REGULATOR=y diff --git a/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832.dts b/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832.dts index 9fa240cb5ae..31eb0cc7524 100644 --- a/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832.dts +++ b/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832.dts @@ -75,6 +75,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832_defconfig b/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832_defconfig index 3e1778de525..05acf2ca945 100644 --- a/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832_defconfig +++ b/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832_defconfig @@ -23,7 +23,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# Additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/mg100/mg100.dts b/boards/arm/mg100/mg100.dts index 512ca901010..0d33fd32151 100644 --- a/boards/arm/mg100/mg100.dts +++ b/boards/arm/mg100/mg100.dts @@ -65,6 +65,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/mg100/mg100_defconfig b/boards/arm/mg100/mg100_defconfig index 93f55f3d0a4..bb7d09dabf2 100644 --- a/boards/arm/mg100/mg100_defconfig +++ b/boards/arm/mg100/mg100_defconfig @@ -18,9 +18,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# Additional board options -CONFIG_GPIO_AS_PINRESET=y - # 32KHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM=y diff --git a/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840.dts b/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840.dts index 077eb4a1657..af0ea59794c 100644 --- a/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840.dts +++ b/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840.dts @@ -150,6 +150,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840_defconfig b/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840_defconfig index 56d8497b43a..af230adb18a 100644 --- a/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840_defconfig +++ b/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840_defconfig @@ -23,7 +23,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52832_mdk/nrf52832_mdk.dts b/boards/arm/nrf52832_mdk/nrf52832_mdk.dts index 348a5b79745..c51002c6497 100644 --- a/boards/arm/nrf52832_mdk/nrf52832_mdk.dts +++ b/boards/arm/nrf52832_mdk/nrf52832_mdk.dts @@ -86,6 +86,10 @@ }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52832_mdk/nrf52832_mdk_defconfig b/boards/arm/nrf52832_mdk/nrf52832_mdk_defconfig index 2c283bda97e..8993b59f938 100644 --- a/boards/arm/nrf52832_mdk/nrf52832_mdk_defconfig +++ b/boards/arm/nrf52832_mdk/nrf52832_mdk_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820.dts b/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820.dts index f70d6649aa8..4942dd6daa0 100644 --- a/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820.dts +++ b/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820.dts @@ -99,6 +99,10 @@ clock-prescaler = <8>; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820_defconfig b/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820_defconfig index 9bbc4da98cb..9ef66860ab3 100644 --- a/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820_defconfig +++ b/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820_defconfig @@ -23,7 +23,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833.dts b/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833.dts index 0d1725d5bbb..b488b5d1ff3 100644 --- a/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833.dts +++ b/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833.dts @@ -127,6 +127,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833_defconfig b/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833_defconfig index 7fe9f4e480c..9cbee72b2e7 100644 --- a/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833_defconfig +++ b/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833_defconfig @@ -23,7 +23,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840_blip/nrf52840_blip.dts b/boards/arm/nrf52840_blip/nrf52840_blip.dts index 112d22799bc..e641c60bd1f 100644 --- a/boards/arm/nrf52840_blip/nrf52840_blip.dts +++ b/boards/arm/nrf52840_blip/nrf52840_blip.dts @@ -66,6 +66,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52840_blip/nrf52840_blip_defconfig b/boards/arm/nrf52840_blip/nrf52840_blip_defconfig index 82c0146ecf1..811a88de939 100644 --- a/boards/arm/nrf52840_blip/nrf52840_blip_defconfig +++ b/boards/arm/nrf52840_blip/nrf52840_blip_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840_mdk/nrf52840_mdk.dts b/boards/arm/nrf52840_mdk/nrf52840_mdk.dts index 0ed4addb069..2439b0c2aca 100644 --- a/boards/arm/nrf52840_mdk/nrf52840_mdk.dts +++ b/boards/arm/nrf52840_mdk/nrf52840_mdk.dts @@ -90,6 +90,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52840_mdk/nrf52840_mdk_defconfig b/boards/arm/nrf52840_mdk/nrf52840_mdk_defconfig index f0ed2a2fbad..e4c79a2bf88 100644 --- a/boards/arm/nrf52840_mdk/nrf52840_mdk_defconfig +++ b/boards/arm/nrf52840_mdk/nrf52840_mdk_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts index 8e835597c78..4e13783d656 100644 --- a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts +++ b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts @@ -89,6 +89,7 @@ &uicr { nfct-pins-as-gpios; + gpio-as-nreset; }; &gpio0 { diff --git a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig index 90850c10e0a..8701863e99a 100644 --- a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig +++ b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig @@ -13,7 +13,4 @@ CONFIG_HW_STACK_PROTECTION=y # enable GPIO CONFIG_GPIO=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840_papyr/nrf52840_papyr.dts b/boards/arm/nrf52840_papyr/nrf52840_papyr.dts index acbb09d2df2..0a9d8ff4724 100644 --- a/boards/arm/nrf52840_papyr/nrf52840_papyr.dts +++ b/boards/arm/nrf52840_papyr/nrf52840_papyr.dts @@ -85,6 +85,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52840_papyr/nrf52840_papyr_defconfig b/boards/arm/nrf52840_papyr/nrf52840_papyr_defconfig index 0ad48d7f940..4a5e737cd14 100644 --- a/boards/arm/nrf52840_papyr/nrf52840_papyr_defconfig +++ b/boards/arm/nrf52840_papyr/nrf52840_papyr_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811.dts b/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811.dts index eb99beca22f..a53a174be15 100644 --- a/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811.dts +++ b/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811.dts @@ -97,6 +97,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811_defconfig b/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811_defconfig index 36553a757eb..2c6b7f2fc82 100644 --- a/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811_defconfig +++ b/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811_defconfig @@ -22,9 +22,6 @@ CONFIG_UART_CONSOLE=y # enable GPIO CONFIG_GPIO=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # Bluetooth not enabled by default on nRF52811 due to RAM limitations when # running the default set of kernel tests. # Enable this on your prj.conf to include Bluetooth support diff --git a/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts b/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts index ba5d94738a6..96006ec4722 100644 --- a/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts +++ b/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts @@ -139,6 +139,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig b/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig index 100d91ed320..9f1232a8f0a 100644 --- a/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig +++ b/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig @@ -23,7 +23,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts index 93b59baa920..dcf9fb690d1 100644 --- a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts +++ b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts @@ -101,6 +101,7 @@ &uicr { nfct-pins-as-gpios; + gpio-as-nreset; }; &gpio0 { diff --git a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig index 32a9d03b44e..c367a90d5ef 100644 --- a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig +++ b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig @@ -13,9 +13,6 @@ CONFIG_HW_STACK_PROTECTION=y # enable GPIO CONFIG_GPIO=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y # Board Kconfig.defconfig enables USB CDC ACM and should disable USB remote diff --git a/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather.dts b/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather.dts index 4412d3c492d..c29ca8000dc 100644 --- a/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather.dts +++ b/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather.dts @@ -70,6 +70,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather_defconfig b/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather_defconfig index 42948633b2f..19aaa3825d1 100644 --- a/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather_defconfig +++ b/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52_sparkfun/nrf52_sparkfun.dts b/boards/arm/nrf52_sparkfun/nrf52_sparkfun.dts index 618bd670ad1..60de01f0bb0 100644 --- a/boards/arm/nrf52_sparkfun/nrf52_sparkfun.dts +++ b/boards/arm/nrf52_sparkfun/nrf52_sparkfun.dts @@ -50,6 +50,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52_sparkfun/nrf52_sparkfun_defconfig b/boards/arm/nrf52_sparkfun/nrf52_sparkfun_defconfig index 944fc20b9c8..2a21dc07192 100644 --- a/boards/arm/nrf52_sparkfun/nrf52_sparkfun_defconfig +++ b/boards/arm/nrf52_sparkfun/nrf52_sparkfun_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# Enable P0_21 as RST -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts b/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts index 8b276c5fed7..b622a1a23ea 100644 --- a/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts +++ b/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts @@ -49,6 +49,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52_vbluno52/nrf52_vbluno52_defconfig b/boards/arm/nrf52_vbluno52/nrf52_vbluno52_defconfig index 97f4efbc236..fac5419e6f6 100644 --- a/boards/arm/nrf52_vbluno52/nrf52_vbluno52_defconfig +++ b/boards/arm/nrf52_vbluno52/nrf52_vbluno52_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805.dts b/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805.dts index 29257e7a0b2..e0eaa911a06 100644 --- a/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805.dts +++ b/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805.dts @@ -89,6 +89,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpio0 { status = "okay"; }; diff --git a/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805_defconfig b/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805_defconfig index 31571f10fb4..6e275e63f35 100644 --- a/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805_defconfig +++ b/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805_defconfig @@ -20,9 +20,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# Additional board options -CONFIG_GPIO_AS_PINRESET=y - # Bluetooth not enabled by default on nRF52805 due to RAM limitations when # running the default set of kernel tests. diff --git a/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810.dts b/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810.dts index 823a3db7f7e..4d4600f1222 100644 --- a/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810.dts +++ b/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810.dts @@ -91,6 +91,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810_defconfig b/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810_defconfig index 5873f1d2e9a..93706e89d0a 100644 --- a/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810_defconfig +++ b/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810_defconfig @@ -20,9 +20,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # Bluetooth not enabled by default on nRF52810 due to RAM limitations when # running the default set of kernel tests. # Enable this on your prj.conf to include Bluetooth support diff --git a/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts b/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts index 3002a1841c9..687bba9254a 100644 --- a/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts +++ b/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts @@ -138,6 +138,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig b/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig index 547ff67c348..23e1f4c249a 100644 --- a/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig +++ b/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig @@ -23,7 +23,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840.dts b/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840.dts index c8cc706750c..07dc648b853 100644 --- a/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840.dts +++ b/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840.dts @@ -141,6 +141,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840_defconfig b/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840_defconfig index c15e39669ea..073409dbba1 100644 --- a/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840_defconfig +++ b/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/pan1770_evb/pan1770_evb.dts b/boards/arm/pan1770_evb/pan1770_evb.dts index d8fbe8fe9df..2b2a9d561a7 100644 --- a/boards/arm/pan1770_evb/pan1770_evb.dts +++ b/boards/arm/pan1770_evb/pan1770_evb.dts @@ -137,6 +137,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/pan1770_evb/pan1770_evb_defconfig b/boards/arm/pan1770_evb/pan1770_evb_defconfig index 1192aca064e..1d90cb82c25 100644 --- a/boards/arm/pan1770_evb/pan1770_evb_defconfig +++ b/boards/arm/pan1770_evb/pan1770_evb_defconfig @@ -26,8 +26,5 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # using pinctrl CONFIG_PINCTRL=y diff --git a/boards/arm/pan1780_evb/pan1780_evb.dts b/boards/arm/pan1780_evb/pan1780_evb.dts index 4f4dbca98ac..da9a7e7fdb8 100644 --- a/boards/arm/pan1780_evb/pan1780_evb.dts +++ b/boards/arm/pan1780_evb/pan1780_evb.dts @@ -137,6 +137,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/pan1780_evb/pan1780_evb_defconfig b/boards/arm/pan1780_evb/pan1780_evb_defconfig index 0c459f39aac..ca1a58c3b74 100644 --- a/boards/arm/pan1780_evb/pan1780_evb_defconfig +++ b/boards/arm/pan1780_evb/pan1780_evb_defconfig @@ -26,8 +26,5 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # using pinctrl CONFIG_PINCTRL=y diff --git a/boards/arm/pan1781_evb/pan1781_evb.dts b/boards/arm/pan1781_evb/pan1781_evb.dts index 7d9b7028e35..8ab6af51ea9 100644 --- a/boards/arm/pan1781_evb/pan1781_evb.dts +++ b/boards/arm/pan1781_evb/pan1781_evb.dts @@ -98,6 +98,10 @@ clock-prescaler = <8>; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/pan1781_evb/pan1781_evb_defconfig b/boards/arm/pan1781_evb/pan1781_evb_defconfig index 76436dd2ccd..dacffd42175 100644 --- a/boards/arm/pan1781_evb/pan1781_evb_defconfig +++ b/boards/arm/pan1781_evb/pan1781_evb_defconfig @@ -26,8 +26,5 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # using pinctrl CONFIG_PINCTRL=y diff --git a/boards/arm/pan1782_evb/pan1782_evb.dts b/boards/arm/pan1782_evb/pan1782_evb.dts index cf169e41d87..fdc86f792ec 100644 --- a/boards/arm/pan1782_evb/pan1782_evb.dts +++ b/boards/arm/pan1782_evb/pan1782_evb.dts @@ -98,6 +98,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/pan1782_evb/pan1782_evb_defconfig b/boards/arm/pan1782_evb/pan1782_evb_defconfig index 0bdeb9d9127..e6a6cc1d4a5 100644 --- a/boards/arm/pan1782_evb/pan1782_evb_defconfig +++ b/boards/arm/pan1782_evb/pan1782_evb_defconfig @@ -26,9 +26,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # using pinctrl CONFIG_PINCTRL=y diff --git a/boards/arm/particle_argon/particle_argon.dts b/boards/arm/particle_argon/particle_argon.dts index fa2314b6fb2..a88199fe40b 100644 --- a/boards/arm/particle_argon/particle_argon.dts +++ b/boards/arm/particle_argon/particle_argon.dts @@ -32,6 +32,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &uart1 { /* ESP32 */ compatible = "nordic,nrf-uarte"; current-speed = <921600>; diff --git a/boards/arm/particle_argon/particle_argon_defconfig b/boards/arm/particle_argon/particle_argon_defconfig index 784364e9edc..c29f62babd4 100644 --- a/boards/arm/particle_argon/particle_argon_defconfig +++ b/boards/arm/particle_argon/particle_argon_defconfig @@ -21,7 +21,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/particle_boron/particle_boron.dts b/boards/arm/particle_boron/particle_boron.dts index 3e20eddb94f..06e75a5a52e 100644 --- a/boards/arm/particle_boron/particle_boron.dts +++ b/boards/arm/particle_boron/particle_boron.dts @@ -36,6 +36,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &i2c1 { /* power monitoring */ compatible = "nordic,nrf-twi"; status = "okay"; diff --git a/boards/arm/particle_boron/particle_boron_defconfig b/boards/arm/particle_boron/particle_boron_defconfig index 6963e9d9393..622a3169073 100644 --- a/boards/arm/particle_boron/particle_boron_defconfig +++ b/boards/arm/particle_boron/particle_boron_defconfig @@ -20,9 +20,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y # Fix the priority to enable the modem line's serial buffer diff --git a/boards/arm/particle_xenon/particle_xenon.dts b/boards/arm/particle_xenon/particle_xenon.dts index 22252c077f3..2d64ba119b2 100644 --- a/boards/arm/particle_xenon/particle_xenon.dts +++ b/boards/arm/particle_xenon/particle_xenon.dts @@ -33,6 +33,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &uart1 { /* feather UART2 */ compatible = "nordic,nrf-uarte"; current-speed = <115200>; diff --git a/boards/arm/particle_xenon/particle_xenon_defconfig b/boards/arm/particle_xenon/particle_xenon_defconfig index 5f90beabba0..2495d886b41 100644 --- a/boards/arm/particle_xenon/particle_xenon_defconfig +++ b/boards/arm/particle_xenon/particle_xenon_defconfig @@ -20,7 +20,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/pinetime_devkit0/pinetime_devkit0.dts b/boards/arm/pinetime_devkit0/pinetime_devkit0.dts index fb377fd89e1..207c8934880 100644 --- a/boards/arm/pinetime_devkit0/pinetime_devkit0.dts +++ b/boards/arm/pinetime_devkit0/pinetime_devkit0.dts @@ -83,6 +83,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig b/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig index ad7442afe0d..fc8f45eceaa 100644 --- a/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig +++ b/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig @@ -13,7 +13,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# use P0.21 as RST -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk.dts b/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk.dts index 62664e67b5e..19f9e6ff41e 100644 --- a/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk.dts +++ b/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk.dts @@ -88,6 +88,10 @@ status ="okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status ="okay"; }; diff --git a/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk_defconfig b/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk_defconfig index 7f11757ab5d..010c72e8c07 100644 --- a/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk_defconfig +++ b/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk_defconfig @@ -22,9 +22,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# Additional board options -CONFIG_GPIO_AS_PINRESET=y - # 32KHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM=y diff --git a/boards/arm/rak4631_nrf52840/rak4631_nrf52840.dts b/boards/arm/rak4631_nrf52840/rak4631_nrf52840.dts index 43b2dd0de28..454c4bb84b1 100644 --- a/boards/arm/rak4631_nrf52840/rak4631_nrf52840.dts +++ b/boards/arm/rak4631_nrf52840/rak4631_nrf52840.dts @@ -48,6 +48,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/rak4631_nrf52840/rak4631_nrf52840_defconfig b/boards/arm/rak4631_nrf52840/rak4631_nrf52840_defconfig index 80da4e05041..4cc2863efab 100644 --- a/boards/arm/rak4631_nrf52840/rak4631_nrf52840_defconfig +++ b/boards/arm/rak4631_nrf52840/rak4631_nrf52840_defconfig @@ -22,7 +22,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833.dts b/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833.dts index 6a530e687f6..a3ada26e811 100644 --- a/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833.dts +++ b/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833.dts @@ -93,6 +93,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833_defconfig b/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833_defconfig index 7ed9a1ffe8b..1212ba8928f 100644 --- a/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833_defconfig +++ b/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833_defconfig @@ -26,7 +26,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840.dts b/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840.dts index 2414b8ea517..bd1a2f06855 100644 --- a/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840.dts +++ b/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840.dts @@ -93,6 +93,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840_defconfig b/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840_defconfig index 973b83c9d62..438343c6d9b 100644 --- a/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840_defconfig +++ b/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840_defconfig @@ -26,7 +26,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/reel_board/dts/reel_board.dtsi b/boards/arm/reel_board/dts/reel_board.dtsi index 6289cf0ec6d..028a5d86a78 100644 --- a/boards/arm/reel_board/dts/reel_board.dtsi +++ b/boards/arm/reel_board/dts/reel_board.dtsi @@ -94,6 +94,10 @@ }; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/reel_board/reel_board_defconfig b/boards/arm/reel_board/reel_board_defconfig index 7ec7b36871b..850506692ba 100644 --- a/boards/arm/reel_board/reel_board_defconfig +++ b/boards/arm/reel_board/reel_board_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/reel_board/reel_board_v2_defconfig b/boards/arm/reel_board/reel_board_v2_defconfig index a7f80f970e8..2ac0610f78c 100644 --- a/boards/arm/reel_board/reel_board_v2_defconfig +++ b/boards/arm/reel_board/reel_board_v2_defconfig @@ -17,7 +17,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832.dts b/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832.dts index a248d8f650e..9594b760488 100644 --- a/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832.dts +++ b/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832.dts @@ -137,6 +137,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832_defconfig b/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832_defconfig index 769e28f5846..801393790fe 100644 --- a/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832_defconfig +++ b/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832_defconfig @@ -23,7 +23,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810.dts b/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810.dts index 5afd4960694..c65221eb38c 100644 --- a/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810.dts +++ b/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810.dts @@ -137,6 +137,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810_defconfig b/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810_defconfig index 6fd69454784..4f8a5c5a8da 100644 --- a/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810_defconfig +++ b/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810_defconfig @@ -26,7 +26,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840.dts b/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840.dts index f7fbee05909..070730c69d2 100644 --- a/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840.dts +++ b/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840.dts @@ -136,6 +136,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840_defconfig b/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840_defconfig index 4a1d3a6075c..37271c2ce81 100644 --- a/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840_defconfig +++ b/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840_defconfig @@ -26,7 +26,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840.dts b/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840.dts index 2db4e005b04..68b3755123b 100644 --- a/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840.dts +++ b/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840.dts @@ -152,6 +152,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840_defconfig b/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840_defconfig index 6a6d80f1b2b..4a35f6e612f 100644 --- a/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840_defconfig +++ b/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840_defconfig @@ -26,7 +26,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811.dts b/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811.dts index 842c882ac7f..5b8679cc065 100644 --- a/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811.dts +++ b/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811.dts @@ -137,6 +137,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811_defconfig b/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811_defconfig index b2996dba82d..7a63bc69bf2 100644 --- a/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811_defconfig +++ b/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811_defconfig @@ -26,7 +26,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840.dts b/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840.dts index 1c4623b52fe..d7a21c98b44 100644 --- a/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840.dts +++ b/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840.dts @@ -97,6 +97,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840_defconfig b/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840_defconfig index d0a583edbe8..c20dc6fe9f3 100644 --- a/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840_defconfig +++ b/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840_defconfig @@ -27,7 +27,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832.dts b/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832.dts index b183b17bc41..2c0f051d25f 100644 --- a/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832.dts +++ b/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832.dts @@ -133,6 +133,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832_defconfig b/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832_defconfig index 4a289cc2597..93127beefef 100644 --- a/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832_defconfig +++ b/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832_defconfig @@ -26,7 +26,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832.dts b/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832.dts index 691705b3a91..849c96c5e6f 100644 --- a/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832.dts +++ b/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832.dts @@ -133,6 +133,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832_defconfig b/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832_defconfig index b7064633b25..b44e54e3d18 100644 --- a/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832_defconfig +++ b/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832_defconfig @@ -26,7 +26,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840.dts b/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840.dts index 19b4e25a5af..5e15c5cc232 100644 --- a/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840.dts +++ b/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840.dts @@ -129,6 +129,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840_defconfig b/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840_defconfig index ca03d00a8e7..f9cabe94b4a 100644 --- a/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840_defconfig +++ b/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840_defconfig @@ -26,7 +26,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833.dts b/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833.dts index 783d69b4788..521f9f6aa9e 100644 --- a/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833.dts +++ b/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833.dts @@ -134,6 +134,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833_defconfig b/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833_defconfig index 96d99738526..c06ad795868 100644 --- a/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833_defconfig +++ b/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833_defconfig @@ -26,7 +26,4 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805.dts b/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805.dts index b9b9bfcedb2..4d7c3d8cc0b 100644 --- a/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805.dts +++ b/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805.dts @@ -61,6 +61,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpio0 { status = "okay"; }; diff --git a/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805_defconfig b/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805_defconfig index d1a44910ced..88c4ddb2023 100644 --- a/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805_defconfig +++ b/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805_defconfig @@ -21,9 +21,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# Additional board options -CONFIG_GPIO_AS_PINRESET=y - # Use internal oscillator CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y diff --git a/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832.dts b/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832.dts index 4cd193c4162..ef7eede1f75 100644 --- a/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832.dts +++ b/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832.dts @@ -56,6 +56,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832_defconfig b/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832_defconfig index ab2356cf412..249c4a8e394 100644 --- a/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832_defconfig +++ b/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832_defconfig @@ -24,9 +24,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # Use internal oscillator CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y diff --git a/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840.dts b/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840.dts index 4c64bcaa4d0..62cecf7066e 100644 --- a/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840.dts +++ b/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840.dts @@ -57,6 +57,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840_defconfig b/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840_defconfig index b232a355e40..cca27094e6a 100644 --- a/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840_defconfig +++ b/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840_defconfig @@ -24,9 +24,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - # Use internal oscillator CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y diff --git a/boards/arm/xiao_ble/xiao_ble_common.dtsi b/boards/arm/xiao_ble/xiao_ble_common.dtsi index 588f381868a..d031ce4b5b3 100644 --- a/boards/arm/xiao_ble/xiao_ble_common.dtsi +++ b/boards/arm/xiao_ble/xiao_ble_common.dtsi @@ -62,6 +62,10 @@ status = "okay"; }; +&uicr { + gpio-as-nreset; +}; + &gpiote { status = "okay"; }; diff --git a/boards/arm/xiao_ble/xiao_ble_defconfig b/boards/arm/xiao_ble/xiao_ble_defconfig index faef5befa1f..6b6aa3168ec 100644 --- a/boards/arm/xiao_ble/xiao_ble_defconfig +++ b/boards/arm/xiao_ble/xiao_ble_defconfig @@ -29,7 +29,4 @@ CONFIG_USB_DEVICE_STACK=y CONFIG_BUILD_OUTPUT_UF2=y CONFIG_USE_DT_CODE_PARTITION=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y diff --git a/boards/arm/xiao_ble/xiao_ble_sense_defconfig b/boards/arm/xiao_ble/xiao_ble_sense_defconfig index f549e4173dc..269f6f7915b 100644 --- a/boards/arm/xiao_ble/xiao_ble_sense_defconfig +++ b/boards/arm/xiao_ble/xiao_ble_sense_defconfig @@ -29,9 +29,6 @@ CONFIG_USB_DEVICE_STACK=y CONFIG_BUILD_OUTPUT_UF2=y CONFIG_USE_DT_CODE_PARTITION=y -# additional board options -CONFIG_GPIO_AS_PINRESET=y - CONFIG_PINCTRL=y # required to enable LSM6DS3TR-C power From 11cbd4dd27bdabd5191901422a694a273a4afc53 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 18 Sep 2023 11:37:32 +0200 Subject: [PATCH 0188/1623] [nrf fromtree] boards: arm: nrf9160dk_nrf52840: use UICR gpio-as-nreset property Instead of the about to be deprecated GPIO_AS_PINRESET. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 5d6d6f5b65ca5696dd27d1c266d6eb4f257d7a45) (cherry picked from commit 4b28e8dbfd7465bce59348851e729476a2356897) --- boards/arm/nrf9160dk_nrf52840/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/arm/nrf9160dk_nrf52840/board.c b/boards/arm/nrf9160dk_nrf52840/board.c index e01b8eb64e7..cdf00f8f3dd 100644 --- a/boards/arm/nrf9160dk_nrf52840/board.c +++ b/boards/arm/nrf9160dk_nrf52840/board.c @@ -27,7 +27,7 @@ LOG_MODULE_REGISTER(board_control, CONFIG_BOARD_NRF9160DK_LOG_LEVEL); * exposes the nRESET function (P0.18 in nRF52840), there is no need to * provide any additional GPIO configuration for it. */ -#define RESET_INPUT_IS_PINRESET (IS_ENABLED(CONFIG_GPIO_AS_PINRESET) && \ +#define RESET_INPUT_IS_PINRESET (DT_PROP(DT_NODELABEL(uicr), gpio_as_nreset) && \ GET_PORT(reset_input, gpios, 0) == 0 && \ GET_PIN(reset_input, gpios, 0) == 18) #define USE_RESET_GPIO \ From 4c425de49697cf8629615c7f7b25feee45180cf6 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 18 Sep 2023 11:02:25 +0200 Subject: [PATCH 0189/1623] [nrf fromtree] soc: arm: nordic_nrf: nrf52: deprecate GPIO_AS_PINRESET In favor of devicetree property in the UICR node. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit efb8408ba2e9a2cb1de638441ec60de495ee0f0d) (cherry picked from commit 03d992d8f6f5c59992e12777b82d31900d4720c4) --- soc/arm/nordic_nrf/nrf52/Kconfig.soc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf52/Kconfig.soc b/soc/arm/nordic_nrf/nrf52/Kconfig.soc index 13a2fef932b..b2a915f168e 100644 --- a/soc/arm/nordic_nrf/nrf52/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf52/Kconfig.soc @@ -94,8 +94,15 @@ config SOC_DCDC_NRF52X_HV Enable nRF52 series System on Chip High Voltage DC/DC converter. config GPIO_AS_PINRESET - bool "GPIO as pin reset (reset button)" - default y + bool "[DEPRECATED] GPIO as pin reset (reset button)" + select DEPRECATED + help + This option is deprecated, use devicetree instead. Example + configuration: + + &uicr { + gpio-as-nreset; + }; config NRF_ENABLE_ICACHE bool "The instruction cache (I-Cache)" From 12bfbfc7d6751e17c63cf190e8bce8eac056c29f Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 18 Sep 2023 11:38:09 +0200 Subject: [PATCH 0190/1623] [nrf fromtree] boards: arm: nrf-based: remove redundant GPIO_AS_PINRESET=n Because the option is disabled by default now that it is deprecated. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit c572228aa0fc157197207841250ca5e71696b05a) (cherry picked from commit 23975f1397f1a3202be17f44c9b7dbd61a31d426) --- boards/arm/holyiot_yj16019/Kconfig.defconfig | 3 --- boards/arm/ruuvi_ruuvitag/ruuvi_ruuvitag_defconfig | 4 ---- 2 files changed, 7 deletions(-) diff --git a/boards/arm/holyiot_yj16019/Kconfig.defconfig b/boards/arm/holyiot_yj16019/Kconfig.defconfig index 99373ad286a..de2d63ad7c8 100644 --- a/boards/arm/holyiot_yj16019/Kconfig.defconfig +++ b/boards/arm/holyiot_yj16019/Kconfig.defconfig @@ -8,9 +8,6 @@ if BOARD_HOLYIOT_YJ16019 config BOARD default "holyiot_yj16019" -config GPIO_AS_PINRESET - default n - config BT_CTLR default BT diff --git a/boards/arm/ruuvi_ruuvitag/ruuvi_ruuvitag_defconfig b/boards/arm/ruuvi_ruuvitag/ruuvi_ruuvitag_defconfig index bd247788458..7e28dde8423 100644 --- a/boards/arm/ruuvi_ruuvitag/ruuvi_ruuvitag_defconfig +++ b/boards/arm/ruuvi_ruuvitag/ruuvi_ruuvitag_defconfig @@ -14,8 +14,4 @@ CONFIG_USE_SEGGER_RTT=y # Enable GPIO CONFIG_GPIO=y -# additional board options -# set y to disable R button -CONFIG_GPIO_AS_PINRESET=n - CONFIG_PINCTRL=y From 532564650101b3c9a9ccbde8ceb3afe4973fc096 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 18 Sep 2023 11:41:42 +0200 Subject: [PATCH 0191/1623] [nrf fromtree] doc: migration-guide: inform about GPIO_AS_PINRESET deprecation In favor of the new devicetree 'gpio-as-nreset' property. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 9019e468392a22e274282517a037c079ab1592c0) (cherry picked from commit eabe4393f184a797044e3f7e52a23e1a4428e17d) --- doc/releases/migration-guide-3.5.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/releases/migration-guide-3.5.rst b/doc/releases/migration-guide-3.5.rst index 3f367ec5e35..8c059b630c6 100644 --- a/doc/releases/migration-guide-3.5.rst +++ b/doc/releases/migration-guide-3.5.rst @@ -53,3 +53,14 @@ Recommended Changes &uicr { nfct-pins-as-gpios; }; + +* Nordic nRF based boards using :kconfig:option:`CONFIG_GPIO_AS_PINRESET` + to configure reset GPIO as nRESET, should instead set the new UICR + ``gpio-as-nreset`` property in devicetree. It can be set like this in the + board devicetree files: + + .. code-block:: devicetree + + &uicr { + gpio-as-nreset; + }; From f25764149e1e0ce62254cd1759909641077becb5 Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Tue, 5 Sep 2023 07:32:03 +0200 Subject: [PATCH 0192/1623] [nrf fromtree] modules: openthread: fix unused variable during `otPlatCryptoInit` If asserts are disabled, there is a warning in 'otPlatCryptoInit' regarding unused variable `err`. This commit fixes that. Signed-off-by: Maciej Baczmanski (cherry picked from commit d2495b14f25a49b7247d1d325bd97ecb5530851c) (cherry picked from commit 9f513ec4ec1520912f65e7d7d938e373b5e04bcd) --- modules/openthread/platform/crypto_psa.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/openthread/platform/crypto_psa.c b/modules/openthread/platform/crypto_psa.c index e61177ef4c4..e5b234ce030 100644 --- a/modules/openthread/platform/crypto_psa.c +++ b/modules/openthread/platform/crypto_psa.c @@ -137,9 +137,8 @@ void otPlatCryptoInit(void) * PSA with emulated TFM, Settings have to be initialized at the end of otPlatCryptoInit(), * to be available before storing Network Key. */ - int err = settings_subsys_init(); - - __ASSERT(!err, "Failed to initialize settings"); + __ASSERT_EVAL((void) settings_subsys_init(), int err = settings_subsys_init(), + !err, "Failed to initialize settings"); #endif } From 860096c05abbb93e27d3ca0c3a14518cd3a69c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Fri, 15 Sep 2023 10:57:38 +0200 Subject: [PATCH 0193/1623] [nrf fromtree] Bluetooth: Test: SC Indication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test that SC Indication is correctly sent when the client reconnect and the server updated the GATT database since last connection. Test that the indication is sent even if the bond is not restored. Signed-off-by: Théo Battrel (cherry picked from commit 888a8c644cc955e55d6b4ce4bbedf0e006e0f9d8) (cherry picked from commit e1762127cf123f5cba94939d30c8f42506be1b69) --- tests/bsim/bluetooth/host/compile.sh | 1 + .../host/gatt/sc_indicate/CMakeLists.txt | 25 +++ .../bluetooth/host/gatt/sc_indicate/prj.conf | 20 ++ .../host/gatt/sc_indicate/src/bs_bt_utils.c | 182 ++++++++++++++++ .../host/gatt/sc_indicate/src/bs_bt_utils.h | 67 ++++++ .../host/gatt/sc_indicate/src/central.c | 195 ++++++++++++++++++ .../host/gatt/sc_indicate/src/main.c | 58 ++++++ .../host/gatt/sc_indicate/src/peripheral.c | 86 ++++++++ .../gatt/sc_indicate/test_scripts/_compile.sh | 18 ++ .../sc_indicate/test_scripts/sc_indicate.sh | 24 +++ 10 files changed, 676 insertions(+) create mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/CMakeLists.txt create mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/prj.conf create mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.c create mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.h create mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/src/central.c create mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/src/main.c create mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/src/peripheral.c create mode 100755 tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/_compile.sh create mode 100755 tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/sc_indicate.sh diff --git a/tests/bsim/bluetooth/host/compile.sh b/tests/bsim/bluetooth/host/compile.sh index a54dbd26507..98d6c79e3ef 100755 --- a/tests/bsim/bluetooth/host/compile.sh +++ b/tests/bsim/bluetooth/host/compile.sh @@ -44,6 +44,7 @@ app=tests/bsim/bluetooth/host/gatt/settings compile app=tests/bsim/bluetooth/host/gatt/settings conf_file=prj_2.conf compile app=tests/bsim/bluetooth/host/gatt/ccc_store compile app=tests/bsim/bluetooth/host/gatt/ccc_store conf_file=prj_2.conf compile +app=tests/bsim/bluetooth/host/gatt/sc_indicate compile app=tests/bsim/bluetooth/host/l2cap/general compile app=tests/bsim/bluetooth/host/l2cap/userdata compile diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/CMakeLists.txt b/tests/bsim/bluetooth/host/gatt/sc_indicate/CMakeLists.txt new file mode 100644 index 00000000000..d734b3c054e --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/sc_indicate/CMakeLists.txt @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) + message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set \ + the environment variable BSIM_COMPONENTS_PATH to point to its \ + components folder. More information can be found in \ + https://babblesim.github.io/folder_structure_and_env.html") +endif() + +find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) +project(bsim_test_auto_seq_req) + +target_sources(app PRIVATE + src/main.c + src/central.c + src/peripheral.c + src/bs_bt_utils.c +) + +zephyr_include_directories( + $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ + $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ +) diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/prj.conf b/tests/bsim/bluetooth/host/gatt/sc_indicate/prj.conf new file mode 100644 index 00000000000..7edaf36d10e --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/sc_indicate/prj.conf @@ -0,0 +1,20 @@ +CONFIG_BT=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_PERIPHERAL=y +CONFIG_BT_DEVICE_NAME="SC Indication Test" + +CONFIG_LOG=y +CONFIG_BT_EXT_ADV=y + +CONFIG_BT_SMP=y +CONFIG_BT_GATT_CLIENT=y + +CONFIG_SETTINGS=y +CONFIG_BT_SETTINGS=y +CONFIG_FLASH=y +CONFIG_FLASH_PAGE_LAYOUT=y +CONFIG_NVS=y +CONFIG_FLASH_MAP=y +CONFIG_SETTINGS_NVS=y + +CONFIG_BT_GATT_DYNAMIC_DB=y diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.c b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.c new file mode 100644 index 00000000000..31952cbe330 --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.c @@ -0,0 +1,182 @@ +/** + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include +#include + +#include +LOG_MODULE_REGISTER(test_utils, LOG_LEVEL_DBG); + +#include "bs_bt_utils.h" + +struct bt_conn *g_conn; +DEFINE_FLAG(flag_is_connected); + +void wait_connected(void) +{ + LOG_DBG("Wait for connection..."); + WAIT_FOR_FLAG(flag_is_connected); +} + +void wait_disconnected(void) +{ + LOG_DBG("Wait for disconnection..."); + WAIT_FOR_FLAG_UNSET(flag_is_connected); +} + +static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err) +{ + LOG_DBG("security changed"); +} + +static void disconnected(struct bt_conn *conn, uint8_t reason) +{ + UNSET_FLAG(flag_is_connected); +} + +struct bt_conn *get_g_conn(void) +{ + return g_conn; +} + +void clear_g_conn(void) +{ + struct bt_conn *conn; + + conn = g_conn; + g_conn = NULL; + BSIM_ASSERT(conn, "Test error: no g_conn!\n"); + bt_conn_unref(conn); +} + +static void connected(struct bt_conn *conn, uint8_t err) +{ + BSIM_ASSERT((!g_conn || (conn == g_conn)), "Unexpected new connection."); + + if (!g_conn) { + g_conn = bt_conn_ref(conn); + } + + if (err != 0) { + clear_g_conn(); + return; + } + + SET_FLAG(flag_is_connected); +} + +BT_CONN_CB_DEFINE(conn_callbacks) = { + .connected = connected, + .disconnected = disconnected, + .security_changed = security_changed, +}; + +static void stop_scan_and_connect(const bt_addr_le_t *addr, + int8_t rssi, + uint8_t type, + struct net_buf_simple *ad) +{ + char addr_str[BT_ADDR_LE_STR_LEN]; + int err; + + if (g_conn != NULL) { + return; + } + + bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); + printk("Got scan result, connecting.. dst %s, RSSI %d\n", addr_str, rssi); + + err = bt_le_scan_stop(); + BSIM_ASSERT(!err, "Err bt_le_scan_stop %d", err); + + err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, &g_conn); + BSIM_ASSERT(!err, "Err bt_conn_le_create %d", err); +} + +void scan_connect_to_first_result(void) +{ + int err; + + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, stop_scan_and_connect); + BSIM_ASSERT(!err, "Err bt_le_scan_start %d", err); +} + +void disconnect(void) +{ + int err; + + err = bt_conn_disconnect(g_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); + BSIM_ASSERT(!err, "bt_conn_disconnect failed (%d)\n", err); +} + +void set_security(bt_security_t sec) +{ + int err; + + err = bt_conn_set_security(g_conn, sec); + BSIM_ASSERT(!err, "Err bt_conn_set_security %d", err); +} + +void create_adv(struct bt_le_ext_adv **adv) +{ + int err; + struct bt_le_adv_param params = {}; + + params.options |= BT_LE_ADV_OPT_CONNECTABLE; + params.options |= BT_LE_ADV_OPT_EXT_ADV; + + params.id = BT_ID_DEFAULT; + params.sid = 0; + params.interval_min = BT_GAP_ADV_FAST_INT_MIN_2; + params.interval_max = BT_GAP_ADV_FAST_INT_MAX_2; + + err = bt_le_ext_adv_create(¶ms, NULL, adv); + BSIM_ASSERT(!err, "bt_le_ext_adv_create failed (%d)\n", err); +} + +void start_adv(struct bt_le_ext_adv *adv) +{ + int err; + + err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT); + BSIM_ASSERT(!err, "bt_le_ext_adv_start failed (%d)\n", err); +} + +void stop_adv(struct bt_le_ext_adv *adv) +{ + int err; + + err = bt_le_ext_adv_stop(adv); + BSIM_ASSERT(!err, "bt_le_ext_adv_stop failed (%d)\n", err); +} + +/* The following flags are raised by events and lowered by test code. */ +DEFINE_FLAG(flag_pairing_complete); +DEFINE_FLAG(flag_bonded); +DEFINE_FLAG(flag_not_bonded); + +void pairing_complete(struct bt_conn *conn, bool bonded) +{ + LOG_DBG("pairing complete"); + SET_FLAG(flag_pairing_complete); + + if (bonded) { + SET_FLAG(flag_bonded); + LOG_DBG("Bonded status: true"); + } else { + SET_FLAG(flag_not_bonded); + LOG_DBG("Bonded status: false"); + } +} + +void pairing_failed(struct bt_conn *conn, enum bt_security_err err) +{ + FAIL("Pairing failed\n"); +} diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.h b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.h new file mode 100644 index 00000000000..5ec34005e9f --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.h @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "bstests.h" +#include "bs_tracing.h" + +#include +#include + +extern enum bst_result_t bst_result; + +#define DECLARE_FLAG(flag) extern atomic_t flag +#define DEFINE_FLAG(flag) atomic_t flag = (atomic_t) false +#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) +#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) +#define WAIT_FOR_FLAG(flag) \ + while (!(bool)atomic_get(&flag)) { \ + (void)k_sleep(K_MSEC(1)); \ + } +#define WAIT_FOR_FLAG_UNSET(flag) \ + while ((bool)atomic_get(&flag)) { \ + (void)k_sleep(K_MSEC(1)); \ + } +#define TAKE_FLAG(flag) \ + while (!(bool)atomic_cas(&flag, true, false)) { \ + (void)k_sleep(K_MSEC(1)); \ + } +#define GET_FLAG(flag) (bool)atomic_get(&flag) + +#define BSIM_ASSERT(expr, ...) \ + do { \ + if (!(expr)) { \ + FAIL(__VA_ARGS__); \ + } \ + } while (0) + +#define FAIL(...) \ + do { \ + bst_result = Failed; \ + bs_trace_error_time_line(__VA_ARGS__); \ + } while (0) + +#define PASS(...) \ + do { \ + bst_result = Passed; \ + bs_trace_info_time(1, __VA_ARGS__); \ + } while (0) + +DECLARE_FLAG(flag_pairing_complete); +DECLARE_FLAG(flag_bonded); +DECLARE_FLAG(flag_not_bonded); + +void scan_connect_to_first_result(void); +struct bt_conn *get_g_conn(void); +void clear_g_conn(void); +void disconnect(void); +void wait_connected(void); +void wait_disconnected(void); +void create_adv(struct bt_le_ext_adv **adv); +void start_adv(struct bt_le_ext_adv *adv); +void stop_adv(struct bt_le_ext_adv *adv); +void set_security(bt_security_t sec); +void pairing_complete(struct bt_conn *conn, bool bonded); +void pairing_failed(struct bt_conn *conn, enum bt_security_err err); diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/central.c b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/central.c new file mode 100644 index 00000000000..ca45874e9cb --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/central.c @@ -0,0 +1,195 @@ +/** + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + * + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +LOG_MODULE_REGISTER(test_central, LOG_LEVEL_DBG); + +#include "bs_bt_utils.h" + +DEFINE_FLAG(flag_discovered); +DEFINE_FLAG(flag_subscribed); +DEFINE_FLAG(flag_indicated); + +enum GATT_HANDLES { + SC, + CCC, + NUM_HANDLES, +}; + +static uint16_t gatt_handles[NUM_HANDLES] = {0}; + +static struct bt_gatt_subscribe_params subscribe_params; + +static void sc_subscribed(struct bt_conn *conn, + uint8_t err, + struct bt_gatt_subscribe_params *params) +{ + LOG_DBG("subscribed"); + SET_FLAG(flag_subscribed); +} + +static uint8_t sc_indicated(struct bt_conn *conn, + struct bt_gatt_subscribe_params *params, + const void *data, + uint16_t length) +{ + LOG_DBG("indication received"); + + SET_FLAG(flag_indicated); + + return BT_GATT_ITER_CONTINUE; +} + +static void subscribe(void) +{ + int err; + + subscribe_params.ccc_handle = gatt_handles[CCC]; + subscribe_params.value_handle = gatt_handles[SC]; + subscribe_params.value = BT_GATT_CCC_INDICATE; + subscribe_params.subscribe = sc_subscribed; + subscribe_params.notify = sc_indicated; + + err = bt_gatt_subscribe(get_g_conn(), &subscribe_params); + BSIM_ASSERT(!err, "bt_gatt_subscribe failed (%d)\n", err); + + WAIT_FOR_FLAG(flag_subscribed); +} + +static uint8_t discover_func(struct bt_conn *conn, + const struct bt_gatt_attr *attr, + struct bt_gatt_discover_params *params) +{ + if (attr == NULL) { + for (size_t i = 0U; i < ARRAY_SIZE(gatt_handles); i++) { + LOG_DBG("handle[%d] = 0x%x", i, gatt_handles[i]); + BSIM_ASSERT(gatt_handles[i] != 0, "did not find all handles\n"); + } + + (void)memset(params, 0, sizeof(*params)); + SET_FLAG(flag_discovered); + + return BT_GATT_ITER_STOP; + } + + if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { + const struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; + static const struct bt_uuid_16 ccc_uuid = BT_UUID_INIT_16(BT_UUID_GATT_CCC_VAL); + + if (bt_uuid_cmp(chrc->uuid, BT_UUID_GATT_SC) == 0) { + int err; + + LOG_DBG("found sc"); + gatt_handles[SC] = chrc->value_handle; + + params->uuid = &ccc_uuid.uuid; + params->start_handle = attr->handle + 2; + params->type = BT_GATT_DISCOVER_DESCRIPTOR; + + err = bt_gatt_discover(conn, params); + BSIM_ASSERT(!err, "bt_gatt_discover failed (%d)\n", err); + + return BT_GATT_ITER_STOP; + } + + } else if (params->type == BT_GATT_DISCOVER_DESCRIPTOR && + bt_uuid_cmp(params->uuid, BT_UUID_GATT_CCC) == 0) { + LOG_DBG("found ccc"); + gatt_handles[CCC] = attr->handle; + SET_FLAG(flag_discovered); + + return BT_GATT_ITER_STOP; + } + + return BT_GATT_ITER_CONTINUE; +} + +static void gatt_discover(void) +{ + int err; + static struct bt_gatt_discover_params discover_params; + + discover_params.uuid = NULL; + discover_params.func = discover_func; + discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; + discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; + discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; + + err = bt_gatt_discover(get_g_conn(), &discover_params); + BSIM_ASSERT(!err, "bt_gatt_discover failed (%d)\n", err); + + WAIT_FOR_FLAG(flag_discovered); + + LOG_DBG("sc handle: %d", gatt_handles[SC]); + LOG_DBG("ccc handle: %d", gatt_handles[CCC]); +} + +void central(void) +{ + /* + * test goal: check that service changed indication is sent on + * reconnection when the server's GATT database has been updated since + * last connection + * + * the central will connect, bond with the peripheral and then + * disconnect after doing that, the central will try to connect again, + * this time it will not elevate the security + * + * to pass the test, the central will wait to receive the service + * changed indication + */ + + int err; + struct bt_conn_auth_info_cb bt_conn_auth_info_cb = { + .pairing_failed = pairing_failed, + .pairing_complete = pairing_complete, + }; + + err = bt_enable(NULL); + BSIM_ASSERT(!err, "bt_enable failed (%d)\n", err); + + err = bt_conn_auth_info_cb_register(&bt_conn_auth_info_cb); + BSIM_ASSERT(!err, "bt_conn_auth_info_cb_register failed.\n"); + + err = settings_load(); + BSIM_ASSERT(!err, "settings_load failed (%d)\n", err); + + scan_connect_to_first_result(); + wait_connected(); + + set_security(BT_SECURITY_L2); + + TAKE_FLAG(flag_pairing_complete); + TAKE_FLAG(flag_bonded); + + /* subscribe to the service changed indication */ + gatt_discover(); + subscribe(); + + disconnect(); + wait_disconnected(); + clear_g_conn(); + + scan_connect_to_first_result(); + wait_connected(); + + /* wait for service change indication */ + WAIT_FOR_FLAG(flag_indicated); + + PASS("PASS\n"); +} diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/main.c b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/main.c new file mode 100644 index 00000000000..f5ffbbc4677 --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/main.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "bstests.h" +#include "bs_bt_utils.h" + +#define BS_SECONDS_TO_US(dur_sec) ((bs_time_t)dur_sec * USEC_PER_SEC) +#define TEST_TIMEOUT_SIMULATED BS_SECONDS_TO_US(60) + +extern void central(void); +extern void peripheral(void); + +static void test_tick(bs_time_t HW_device_time) +{ + bs_trace_debug_time(0, "Simulation ends now.\n"); + if (bst_result != Passed) { + bst_result = Failed; + bs_trace_error("Test did not pass before simulation ended.\n"); + } +} + +static void test_init(void) +{ + bst_ticker_set_next_tick_absolute(TEST_TIMEOUT_SIMULATED); + bst_result = In_progress; +} + +static const struct bst_test_instance test_to_add[] = { + { + .test_id = "central", + .test_post_init_f = test_init, + .test_tick_f = test_tick, + .test_main_f = central, + }, + { + .test_id = "peripheral", + .test_post_init_f = test_init, + .test_tick_f = test_tick, + .test_main_f = peripheral, + }, + BSTEST_END_MARKER, +}; + +static struct bst_test_list *install(struct bst_test_list *tests) +{ + return bst_add_tests(tests, test_to_add); +}; + +bst_test_install_t test_installers[] = {install, NULL}; + +int main(void) +{ + bst_main(); + return 0; +} diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/peripheral.c b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/peripheral.c new file mode 100644 index 00000000000..e15c00b60d7 --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/peripheral.c @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + * + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include +LOG_MODULE_REGISTER(test_peripheral, LOG_LEVEL_DBG); + +#include "bs_bt_utils.h" + +#define UUID_1 BT_UUID_DECLARE_128(0xdb, 0x1f, 0xe2, 0x52, 0xf3, 0xc6, 0x43, 0x66, \ + 0xb3, 0x92, 0x5d, 0xc6, 0xe7, 0xc9, 0x59, 0x9d) +#define UUID_2 BT_UUID_DECLARE_128(0x3f, 0xa4, 0x7f, 0x44, 0x2e, 0x2a, 0x43, 0x05, \ + 0xab, 0x38, 0x07, 0x8d, 0x16, 0xbf, 0x99, 0xf1) + +static void new_svc_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) +{ + ARG_UNUSED(attr); + + bool notif_enabled = (value == BT_GATT_CCC_NOTIFY); + + LOG_DBG("CCC Update: notification %s", notif_enabled ? "enabled" : "disabled"); +} + +static struct bt_gatt_attr attrs[] = { + BT_GATT_PRIMARY_SERVICE(UUID_1), + BT_GATT_CHARACTERISTIC(UUID_2, BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_NONE, NULL, NULL, NULL), + BT_GATT_CCC(new_svc_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), +}; + +static struct bt_gatt_service svc = { + .attrs = attrs, + .attr_count = ARRAY_SIZE(attrs), +}; + +void peripheral(void) +{ + /* + * test goal: check that service changed indication is sent on + * reconnection when the server's GATT database has been updated since + * last connection + * + * the peripheral will wait for connection/disconnection, when + * disconnected it will register a new service, when reconnecting, the + * central should receive an indication + */ + + int err; + struct bt_le_ext_adv *adv = NULL; + + err = bt_enable(NULL); + BSIM_ASSERT(!err, "bt_enable failed (%d)\n", err); + + err = settings_load(); + BSIM_ASSERT(!err, "settings_load failed (%d)\n", err); + + create_adv(&adv); + start_adv(adv); + wait_connected(); + + stop_adv(adv); + + wait_disconnected(); + clear_g_conn(); + + /* add a new service to trigger the service changed indication */ + err = bt_gatt_service_register(&svc); + BSIM_ASSERT(!err, "bt_gatt_service_register failed (%d)\n", err); + LOG_DBG("New service added"); + + start_adv(adv); + wait_connected(); + + PASS("Done\n"); +} diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/_compile.sh new file mode 100755 index 00000000000..b07577a9878 --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/_compile.sh @@ -0,0 +1,18 @@ +#!/bin/env bash +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +set -eu + +# Terminate running simulations (if any) +${BSIM_COMPONENTS_PATH}/common/stop_bsim.sh + +test_name='sc_indicate' + +: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +bsim_bin="${BSIM_OUT_PATH}/bin" +BOARD="${BOARD:-nrf52_bsim}" +test_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_gatt_${test_name}_prj_conf" + +west build -b nrf52_bsim -d build && \ + cp -v build/zephyr/zephyr.exe "${test_exe}" diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/sc_indicate.sh b/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/sc_indicate.sh new file mode 100755 index 00000000000..b46ae13929c --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/sc_indicate.sh @@ -0,0 +1,24 @@ +#!/bin/env bash +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + +test_name='sc_indicate' +test_exe="bs_${BOARD}_tests_bsim_bluetooth_host_gatt_${test_name}_prj_conf" +simulation_id="${test_name}" +verbosity_level=2 +EXECUTE_TIMEOUT=30 + +cd ${BSIM_OUT_PATH}/bin + +Execute "./${test_exe}" \ + -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central + +Execute "./${test_exe}" \ + -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral + +Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ + -D=2 -sim_length=60e6 + +wait_for_background_jobs From c33d528a791c5aa4995e998b07ed8921ac2c04b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Mon, 18 Sep 2023 13:59:45 +0200 Subject: [PATCH 0194/1623] [nrf fromtree] Revert "Bluetooth: Host: Fix GATT server handling of CCC" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit cfd368fef1b72e9468626ee03ed1992ceb1e8965. Signed-off-by: Théo Battrel (cherry picked from commit c2b99c0123b4bbb8e70843604e855c5e8fd0211c) (cherry picked from commit 72d67fbaee7d4173e37513309d9f4b8d534da77b) --- include/zephyr/bluetooth/gatt.h | 5 ---- subsys/bluetooth/host/gatt.c | 43 ++++++--------------------------- 2 files changed, 7 insertions(+), 41 deletions(-) diff --git a/include/zephyr/bluetooth/gatt.h b/include/zephyr/bluetooth/gatt.h index e4aae4e4d41..f0ee8d5981a 100644 --- a/include/zephyr/bluetooth/gatt.h +++ b/include/zephyr/bluetooth/gatt.h @@ -736,11 +736,6 @@ struct bt_gatt_ccc_cfg { uint8_t id; /** Remote peer address. */ bt_addr_le_t peer; - /** - * Separate storage for encrypted and unencrypted context. This - * indicate that the link was encrypted when the CCC was written. - */ - bool link_encrypted; /** Configuration value. */ uint16_t value; }; diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index 39f01bc45b4..93dfe555580 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -1318,7 +1318,6 @@ static void clear_ccc_cfg(struct bt_gatt_ccc_cfg *cfg) bt_addr_le_copy(&cfg->peer, BT_ADDR_LE_ANY); cfg->id = 0U; cfg->value = 0U; - cfg->link_encrypted = false; } static void gatt_store_ccc_cf(uint8_t id, const bt_addr_le_t *peer_addr); @@ -2050,34 +2049,6 @@ struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr) return next; } -static bool bt_gatt_ccc_cfg_is_matching_conn(const struct bt_conn *conn, - const struct bt_gatt_ccc_cfg *cfg) -{ - bool conn_encrypted = bt_conn_get_security(conn) >= BT_SECURITY_L2; - - if (cfg->link_encrypted && !conn_encrypted) { - return false; - } - - return bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer); -} - -static struct bt_conn *bt_gatt_ccc_cfg_conn_lookup(const struct bt_gatt_ccc_cfg *cfg) -{ - struct bt_conn *conn; - - conn = bt_conn_lookup_addr_le(cfg->id, &cfg->peer); - if (conn) { - if (bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) { - return conn; - } - - bt_conn_unref(conn); - } - - return NULL; -} - static struct bt_gatt_ccc_cfg *find_ccc_cfg(const struct bt_conn *conn, struct _bt_gatt_ccc *ccc) { @@ -2085,7 +2056,8 @@ static struct bt_gatt_ccc_cfg *find_ccc_cfg(const struct bt_conn *conn, struct bt_gatt_ccc_cfg *cfg = &ccc->cfg[i]; if (conn) { - if (bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) { + if (bt_conn_is_peer_addr_le(conn, cfg->id, + &cfg->peer)) { return cfg; } } else if (bt_addr_le_eq(&cfg->peer, BT_ADDR_LE_ANY)) { @@ -2179,7 +2151,6 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn, bt_addr_le_copy(&cfg->peer, &conn->le.dst); cfg->id = conn->id; - cfg->link_encrypted = (bt_conn_get_security(conn) >= BT_SECURITY_L2); } /* Confirm write if cfg is managed by application */ @@ -3259,7 +3230,8 @@ static uint8_t update_ccc(const struct bt_gatt_attr *attr, uint16_t handle, struct bt_gatt_ccc_cfg *cfg = &ccc->cfg[i]; /* Ignore configuration for different peer or not active */ - if (!cfg->value || !bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) { + if (!cfg->value || + !bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer)) { continue; } @@ -3333,11 +3305,11 @@ static uint8_t disconnected_cb(const struct bt_gatt_attr *attr, uint16_t handle, continue; } - if (!bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) { + if (!bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer)) { struct bt_conn *tmp; /* Skip if there is another peer connected */ - tmp = bt_gatt_ccc_cfg_conn_lookup(cfg); + tmp = bt_conn_lookup_addr_le(cfg->id, &cfg->peer); if (tmp) { if (tmp->state == BT_CONN_CONNECTED) { value_used = true; @@ -3427,7 +3399,7 @@ bool bt_gatt_is_subscribed(struct bt_conn *conn, for (size_t i = 0; i < BT_GATT_CCC_MAX; i++) { const struct bt_gatt_ccc_cfg *cfg = &ccc->cfg[i]; - if (bt_gatt_ccc_cfg_is_matching_conn(conn, cfg) && + if (bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer) && (ccc_type & ccc->cfg[i].value)) { return true; } @@ -5578,7 +5550,6 @@ static uint8_t ccc_load(const struct bt_gatt_attr *attr, uint16_t handle, } bt_addr_le_copy(&cfg->peer, load->addr_with_id.addr); cfg->id = load->addr_with_id.id; - cfg->link_encrypted = true; } cfg->value = load->entry->value; From c65b964187a631bd6bce52995599b29ba455b8dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Fri, 22 Sep 2023 13:16:37 +0200 Subject: [PATCH 0195/1623] [nrf fromtree] Bluetooth: Test: Update `security/ccc_update` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous commit reverted the `link_encrypted` filed of CCC config. Update the test to match the new expected behavior. Signed-off-by: Théo Battrel (cherry picked from commit 2e13802a38469d5cb9a7fbbca8c029a9ce9e9f6b) (cherry picked from commit c991ee360e64a82bb0f396d3c731654905239e02) --- .../host/security/ccc_update/src/central.c | 9 ++---- .../host/security/ccc_update/src/peripheral.c | 28 ++++++++++++------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/tests/bsim/bluetooth/host/security/ccc_update/src/central.c b/tests/bsim/bluetooth/host/security/ccc_update/src/central.c index fbdf7ee0108..8f2d2c17dd4 100644 --- a/tests/bsim/bluetooth/host/security/ccc_update/src/central.c +++ b/tests/bsim/bluetooth/host/security/ccc_update/src/central.c @@ -248,7 +248,7 @@ static void connect_unsubscribe(void) backchannel_sync_wait(SERVER_CLIENT_CHAN, SERVER_ID); } -static void connect_restore_sec_unsubscribe(void) +static void connect_restore_sec(void) { int err; @@ -270,10 +270,7 @@ static void connect_restore_sec_unsubscribe(void) /* wait for server to check that the subscribtion has been restored */ backchannel_sync_wait(SERVER_CLIENT_CHAN, SERVER_ID); - /* send unsubscribtion request */ - ccc_unsubscribe(); - - /* wait for server to check that the unsubscribtion has been well registered */ + /* wait for server to check that the subscription no longer exist */ backchannel_sync_send(SERVER_CLIENT_CHAN, SERVER_ID); } @@ -347,7 +344,7 @@ void run_central(void) backchannel_sync_send(CLIENT_CLIENT_CHAN, BAD_CLIENT_ID); backchannel_sync_wait(CLIENT_CLIENT_CHAN, BAD_CLIENT_ID); - connect_restore_sec_unsubscribe(); + connect_restore_sec(); disconnect(); PASS("Central test passed\n"); diff --git a/tests/bsim/bluetooth/host/security/ccc_update/src/peripheral.c b/tests/bsim/bluetooth/host/security/ccc_update/src/peripheral.c index b9070361577..ac6307dae6a 100644 --- a/tests/bsim/bluetooth/host/security/ccc_update/src/peripheral.c +++ b/tests/bsim/bluetooth/host/security/ccc_update/src/peripheral.c @@ -194,9 +194,9 @@ static void connect_wait_unsubscribtion(struct bt_le_ext_adv *adv) stop_adv(adv); - /* check that subscribtion is not restored for bad client */ - if (is_peer_subscribed(default_conn)) { - FAIL("Subscribtion has been restored for bad client\n"); + /* check that subscribtion is restored for bad client */ + if (!is_peer_subscribed(default_conn)) { + FAIL("Subscribtion has not been restored for bad client\n"); } /* confirm to bad client that the subscribtion had not been restored */ @@ -204,12 +204,12 @@ static void connect_wait_unsubscribtion(struct bt_le_ext_adv *adv) /* wait for confirmation that bad client requested unsubscribtion */ backchannel_sync_wait(BAD_CLIENT_CHAN, BAD_CLIENT_ID); - /* check that unsubscribtion request failed */ - if (GET_FLAG(ccc_cfg_changed_flag)) { - FAIL("Bad client updated CCC config\n"); + /* check that unsubscribtion request didn't fail */ + if (!GET_FLAG(ccc_cfg_changed_flag)) { + FAIL("Bad client didn't manage to update CCC config\n"); } - /* confirm to bad client that unsubscribtion request has been ignored */ + /* confirm to bad client that unsubscribtion request has been well registered */ backchannel_sync_send(BAD_CLIENT_CHAN, BAD_CLIENT_ID); } @@ -225,9 +225,9 @@ static void connect_restore_sec_check_subscribtion(struct bt_le_ext_adv *adv) /* wait for good client end of security update */ backchannel_sync_wait(GOOD_CLIENT_CHAN, GOOD_CLIENT_ID); - /* check that subscribtion has been restored */ - if (!is_peer_subscribed(default_conn)) { - FAIL("Good client is not subscribed\n"); + /* check that subscribtion hasn't been restored */ + if (is_peer_subscribed(default_conn)) { + FAIL("Good client is subscribed\n"); } /* confirm to good client that the subscribtion has been well restored */ @@ -285,6 +285,14 @@ static void check_ccc_handle(void) void run_peripheral(void) { + /* + * test goal: demonstrate the expected behavior of the GATT server when + * a non-bonded peer try to unsubscribe from a previously subscription + * done in a bonded context + * + * test pass if the bad client manage to unsubscribe + */ + int err; struct bt_le_ext_adv *adv = NULL; From 33a728fe359097894cd94598f2f09f7d883f6b8e Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Fri, 15 Sep 2023 10:50:13 +0200 Subject: [PATCH 0196/1623] [nrf fromtree] boards: arm: nrf9161dk: update SPI flash This patch updates the SPI flash to the one currently used in the latest board version. Since these are still 0.X.X board versions, old configurations are not explicitly supported. (cherry picked from commit 3a34840957a186fe5956c5714eda4072b469a707) Signed-off-by: Maximilian Deubel (cherry picked from commit 04666ef4578116e692ae4ae038f8ff46941b609e) --- .../nrf9161dk_nrf9161_common.dtsi | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common.dtsi b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common.dtsi index 1dee5b1b1a3..a6aeccf34b9 100644 --- a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common.dtsi +++ b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common.dtsi @@ -128,7 +128,7 @@ mcuboot-button0 = &button0; mcuboot-led0 = &led0; watchdog0 = &wdt0; - spi-flash0 = &gd25lb256; + spi-flash0 = &gd25wb256; }; }; @@ -195,22 +195,22 @@ arduino_spi: &spi3 { pinctrl-1 = <&spi3_sleep>; pinctrl-names = "default", "sleep"; - gd25lb256: gd25lb256e3ir@1 { + gd25wb256: gd25wb256e3ir@1 { compatible = "jedec,spi-nor"; status = "disabled"; reg = <1>; - spi-max-frequency = <60000000>; - jedec-id = [c8 67 19]; - sfdp-bfp = [ - e5 20 ea ff ff ff ff 0f 44 eb 08 6b 00 3b 00 bb - fe ff ff ff ff ff 00 ff ff ff 44 eb 0c 20 0f 52 - 10 d8 00 ff d5 31 b1 fe 82 e4 14 4c ec 60 06 33 - 7a 75 7a 75 04 bd d5 5c 29 06 74 00 08 50 00 01 - ]; + spi-max-frequency = <8000000>; size = <268435456>; has-dpd; t-enter-dpd = <3000>; - t-exit-dpd = <30000>; + t-exit-dpd = <40000>; + sfdp-bfp = [ + e5 20 f3 ff ff ff ff 0f 44 eb 08 6b 08 3b 42 bb + ee ff ff ff ff ff 00 ff ff ff 00 ff 0c 20 0f 52 + 10 d8 00 ff 44 7a c9 fe 83 67 26 62 ec 82 18 44 + 7a 75 7a 75 04 c4 d5 5c 00 06 74 00 08 50 00 01 + ]; + jedec-id = [c8 65 19]; }; }; From 10b0106a4e8771c99908d2b9c783fd9eee2e40bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Wed, 4 Oct 2023 09:41:33 +0200 Subject: [PATCH 0197/1623] =?UTF-8?q?[nrf=20fromtree]=C2=A0boards:=20arm:?= =?UTF-8?q?=20nrf9161dk=5Fnrf9161:=20Add=20ext=20flash=20support=20for=200?= =?UTF-8?q?.7.0=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for external flash on the 0.7.0 DK version. (cherry picked from commit 8203646cc48c5bfe224b5b5dd2e7dec78e0b1b45) Signed-off-by: Eivind Jølsgard (cherry picked from commit 8c7463b5230ce09b74d75e1b963d0c262d92fa73) --- .../nrf9161dk_nrf9161_0_7_0.overlay | 7 +++++ .../nrf9161dk_nrf9161_common_0_7_0.dtsi | 31 +++++++++++++++++++ .../nrf9161dk_nrf9161_ns_0_7_0.overlay | 7 +++++ boards/arm/nrf9161dk_nrf9161/revision.cmake | 8 +++++ 4 files changed, 53 insertions(+) create mode 100644 boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_0_7_0.overlay create mode 100644 boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common_0_7_0.dtsi create mode 100644 boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_ns_0_7_0.overlay create mode 100644 boards/arm/nrf9161dk_nrf9161/revision.cmake diff --git a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_0_7_0.overlay b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_0_7_0.overlay new file mode 100644 index 00000000000..22e9f970dab --- /dev/null +++ b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_0_7_0.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf9161dk_nrf9161_common_0_7_0.dtsi" diff --git a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common_0_7_0.dtsi b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common_0_7_0.dtsi new file mode 100644 index 00000000000..ae67df77b22 --- /dev/null +++ b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common_0_7_0.dtsi @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&spi3 { + gd25lb256: gd25lb256e3ir@1 { + compatible = "jedec,spi-nor"; + status = "okay"; + reg = <1>; + spi-max-frequency = <60000000>; + jedec-id = [c8 67 19]; + sfdp-bfp = [ + e5 20 ea ff ff ff ff 0f 44 eb 08 6b 00 3b 00 bb + fe ff ff ff ff ff 00 ff ff ff 44 eb 0c 20 0f 52 + 10 d8 00 ff d5 31 b1 fe 82 e4 14 4c ec 60 06 33 + 7a 75 7a 75 04 bd d5 5c 29 06 74 00 08 50 00 01 + ]; + size = <268435456>; + has-dpd; + t-enter-dpd = <3000>; + t-exit-dpd = <30000>; + }; +}; + +/ { + aliases { + spi-flash0 = &gd25lb256; + }; +}; diff --git a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_ns_0_7_0.overlay b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_ns_0_7_0.overlay new file mode 100644 index 00000000000..22e9f970dab --- /dev/null +++ b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_ns_0_7_0.overlay @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "nrf9161dk_nrf9161_common_0_7_0.dtsi" diff --git a/boards/arm/nrf9161dk_nrf9161/revision.cmake b/boards/arm/nrf9161dk_nrf9161/revision.cmake new file mode 100644 index 00000000000..2a899f61a83 --- /dev/null +++ b/boards/arm/nrf9161dk_nrf9161/revision.cmake @@ -0,0 +1,8 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +board_check_revision( + FORMAT MAJOR.MINOR.PATCH + DEFAULT_REVISION 0.9.0 + VALID_REVISIONS 0.7.0 0.9.0 +) From 7bc30a2760c9c536cd24b1ebe040d1cdcbed6f08 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Wed, 4 Oct 2023 16:41:39 +0200 Subject: [PATCH 0198/1623] [nrf fromtree] Bluetooth: Mesh: fix settings work queue size for rpr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If RPR server is used then Mesh settings work queue requires more size during provisioning procedure. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 0ba6e80a12b94aa09d47889e3cb0b08024a9cde6) Signed-off-by: Alperen Şener (cherry picked from commit f825ca8452fee34aac58d79656f51afd9a3fc121) --- subsys/bluetooth/mesh/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 2dfc125b8fd..9f24ff81975 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1718,6 +1718,7 @@ config BT_MESH_SETTINGS_WORKQ_PRIO config BT_MESH_SETTINGS_WORKQ_STACK_SIZE int "Stack size of the settings workq" + default 1200 if BT_MESH_RPR_SRV default 880 help Size of the settings workqueue stack. From b0b28e641a6591433abfdff68770fac327995e35 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Wed, 4 Oct 2023 15:29:10 +0200 Subject: [PATCH 0199/1623] [nrf fromtree] tests: bluetooth: tester: Move bt_mesh_init call to BTP_MESH_INIT cmd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some RPR tests we need to pass alternative composition data when testing CDP128. When bt_mesh_init is called from mesh service registration callback, we can't pass any arguments. Therefore we need to move bt_mesh_init call out from mesh service registration to BTP_MESH_INIT command. Signed-off-by: Pavel Vasilyev (cherry picked from commit 2445e55cd4ddaa2b3863bdedb4dca520a93e1b93) Signed-off-by: Alperen Şener (cherry picked from commit 0d70886943e83a250b9aea92e31932fa4f372410) --- tests/bluetooth/tester/src/btp/btp_mesh.h | 4 +++ tests/bluetooth/tester/src/btp_mesh.c | 32 ++++++++++++----------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 826f0fd0408..bb26524246e 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -77,6 +77,10 @@ struct btp_mesh_provision_node_cmd_v2 { } __packed; #define BTP_MESH_INIT 0x04 +struct btp_mesh_init_cmd { + bool comp_alt; +} __packed; + #define BTP_MESH_RESET 0x05 #define BTP_MESH_INPUT_NUMBER 0x06 struct btp_mesh_input_number_cmd { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index e83f1a67ba1..eea03b0936e 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1258,8 +1258,24 @@ static uint8_t provision_adv(const void *cmd, uint16_t cmd_len, static uint8_t init(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { + const struct btp_mesh_init_cmd *cp = cmd; int err; + if (!cp->comp_alt) { + LOG_WRN("Loading default comp data"); + err = bt_mesh_init(&prov, &comp); + } else { + LOG_WRN("Loading alternative comp data"); +#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV + health_srv.metadata = health_srv_meta_alt; +#endif + err = bt_mesh_init(&prov, &comp_alt); + } + + if (err) { + return BTP_STATUS_FAILED; + } + LOG_DBG(""); if (IS_ENABLED(CONFIG_BT_SETTINGS)) { @@ -4419,7 +4435,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_MESH_INIT, - .expect_len = 0, + .expect_len = sizeof(struct btp_mesh_init_cmd), .func = init, }, { @@ -5224,8 +5240,6 @@ BT_MESH_LPN_CB_DEFINE(lpn_cb) = { uint8_t tester_init_mesh(void) { - int err; - if (IS_ENABLED(CONFIG_BT_TESTING)) { bt_test_cb_register(&bt_test_cb); } @@ -5236,18 +5250,6 @@ uint8_t tester_init_mesh(void) tester_register_command_handlers(BTP_SERVICE_ID_MESH, handlers, ARRAY_SIZE(handlers)); - if (default_comp) { - err = bt_mesh_init(&prov, &comp); - } else { -#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV - health_srv.metadata = health_srv_meta_alt; -#endif - err = bt_mesh_init(&prov, &comp_alt); - } - - if (err) { - return BTP_STATUS_FAILED; - } return BTP_STATUS_SUCCESS; } From 2814689b0005730341054fb7b7de91c0488f320a Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Wed, 4 Oct 2023 15:32:28 +0200 Subject: [PATCH 0200/1623] [nrf fromtree] tests: bluetooth: tester: Remove comp_alt_set command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove this command as composition can only be set in bt_mesh_init call which is called before settings are loaded. Signed-off-by: Pavel Vasilyev (cherry picked from commit bd82ff245a92ea15a4d938621c4c977d11c07177) Signed-off-by: Alperen Şener (cherry picked from commit 630017033c61fd3148e099035b82113a540c640b) --- tests/bluetooth/tester/src/btp/btp_mesh.h | 2 - tests/bluetooth/tester/src/btp_mesh.c | 48 ----------------------- 2 files changed, 50 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index bb26524246e..6b58d1515dc 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -849,8 +849,6 @@ struct btp_mesh_opcodes_aggregator_init_cmd { #define BTP_MESH_COMP_CHANGE_PREPARE 0x57 -#define BTP_MESH_SET_COMP_ALT 0x58 - #define BTP_MESH_RPR_SCAN_START 0x59 struct btp_rpr_scan_start_cmd { uint16_t dst; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index eea03b0936e..dd16e98367b 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -318,8 +318,6 @@ static struct { .dst = BT_MESH_ADDR_UNASSIGNED, }; -static bool default_comp = true; - static uint8_t supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -1905,47 +1903,6 @@ static uint8_t change_prepare(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -#if IS_ENABLED(CONFIG_BT_SETTINGS) -static int comp_alt_set(const char *name, size_t len_rd, - settings_read_cb read_cb, void *store) -{ - ssize_t len; - bool alt_comp_value; - - if (len_rd == 0) { - LOG_DBG("Default composition"); - } - - len = read_cb(store, &alt_comp_value, sizeof(alt_comp_value)); - if (len < 0 || len != len_rd) { - LOG_ERR("Failed to read value (err %zd)", len); - return len; - } - - if (alt_comp_value) { - default_comp = false; - } - - return 0; -} - -SETTINGS_STATIC_HANDLER_DEFINE(tester_comp_alt, "tester/comp_alt", NULL, comp_alt_set, NULL, NULL); -#endif - -static uint8_t set_comp_alt(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ -#if !IS_ENABLED(CONFIG_BT_SETTINGS) - return BTP_STATUS_FAILED; -#else - bool comp_alt_val = true; - - settings_save_one("tester/comp_alt", &comp_alt_val, sizeof(comp_alt_val)); - - return BTP_STATUS_SUCCESS; -#endif -} - static uint8_t config_krp_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -4863,11 +4820,6 @@ static const struct btp_handler handlers[] = { .expect_len = 0, .func = change_prepare }, - { - .opcode = BTP_MESH_SET_COMP_ALT, - .expect_len = 0, - .func = set_comp_alt - }, #if defined(CONFIG_BT_MESH_RPR_CLI) { .opcode = BTP_MESH_RPR_SCAN_START, From 0d5459354aa7383a99c7c7681fea795166061817 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 5 Oct 2023 11:20:45 +0200 Subject: [PATCH 0201/1623] [nrf fromtree] tests: bluetooth: tester: Allow to pass int instead of bool in comp cmd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will allow to choose more variants of cdp in future if needed. Signed-off-by: Pavel Vasilyev (cherry picked from commit 8b4994f22fe9185cafff84fae33d392837f6d81e) Signed-off-by: Alperen Şener (cherry picked from commit 247c268c6e90316c361fcc4b1f57656515452f4d) --- tests/bluetooth/tester/src/btp/btp_mesh.h | 2 +- tests/bluetooth/tester/src/btp_mesh.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 6b58d1515dc..c2636d1445d 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -78,7 +78,7 @@ struct btp_mesh_provision_node_cmd_v2 { #define BTP_MESH_INIT 0x04 struct btp_mesh_init_cmd { - bool comp_alt; + uint8_t comp; } __packed; #define BTP_MESH_RESET 0x05 diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index dd16e98367b..2a74bb03828 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1259,7 +1259,7 @@ static uint8_t init(const void *cmd, uint16_t cmd_len, const struct btp_mesh_init_cmd *cp = cmd; int err; - if (!cp->comp_alt) { + if (cp->comp == 0) { LOG_WRN("Loading default comp data"); err = bt_mesh_init(&prov, &comp); } else { From b043570e6e1a2721b9c4ac566a5f768366196f80 Mon Sep 17 00:00:00 2001 From: Ingar Kulbrandstad Date: Mon, 2 Oct 2023 17:41:31 +0200 Subject: [PATCH 0202/1623] [nrf fromtree] Bluetooth: Mesh: Fixed issue with RPR server and client. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed issue when reprovisioning is done on a device with both RPR client and server on the same device. Signed-off-by: Ingar Kulbrandstad (cherry picked from commit a5d15ec01737e9f555c370533f358847877cbb94) Signed-off-by: Alperen Şener (cherry picked from commit 327e3899d585342bd99c1e7d988ac1a707b6d800) --- subsys/bluetooth/mesh/provisioner.c | 71 +++ .../bsim/bluetooth/mesh/src/test_provision.c | 490 +++++++++++++----- .../pb_remote_client_server_same_dev.sh | 32 ++ 3 files changed, 470 insertions(+), 123 deletions(-) create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index 361f373cb7b..717cdbee610 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -857,6 +857,72 @@ int bt_mesh_pb_remote_open(struct bt_mesh_rpr_cli *cli, return link_open(uuid, &pb_remote_cli, net_idx, addr, 0, &ctx, 0); } +/* Remote Provision done where client and server is on same node, skip open link + * and sending of reprovision message, just execute reprovisioning on it self. + */ +static int reprovision_local_client_server(uint16_t addr) +{ + int err; + const uint8_t *pub_key; + const uint8_t *priv_key = NULL; + + if (atomic_test_and_set_bit(bt_mesh_prov_link.flags, LINK_ACTIVE)) { + return -EBUSY; + } + + LOG_DBG("net_idx %u iv_index 0x%08x, addr 0x%04x", + prov_device.node->net_idx, bt_mesh_cdb.iv_index, addr); + + atomic_set_bit(bt_mesh_prov_link.flags, REPROVISION); + atomic_set_bit(bt_mesh_prov_link.flags, PROVISIONER); + bt_mesh_prov_link.addr = addr; + bt_mesh_prov_link.bearer = &pb_remote_cli; + bt_mesh_prov_link.role = &role_provisioner; + prov_device.net_idx = prov_device.node->net_idx; + prov_device.attention_duration = 0; + + if (IS_ENABLED(CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY) && + bt_mesh_prov->public_key_be && bt_mesh_prov->private_key_be) { + LOG_DBG("Use OOB Public and Private key"); + pub_key = bt_mesh_prov->public_key_be; + priv_key = bt_mesh_prov->private_key_be; + } else { + pub_key = bt_mesh_pub_key_get(); + } + + if (!pub_key) { + LOG_ERR("No public key available"); + return -ENOEXEC; + } + + if (bt_mesh_dhkey_gen(pub_key, priv_key, bt_mesh_prov_link.dhkey)) { + LOG_ERR("Failed to generate DHKey"); + return -ENOEXEC; + } + LOG_DBG("DHkey: %s", bt_hex(bt_mesh_prov_link.dhkey, DH_KEY_SIZE)); + + err = bt_mesh_dev_key(bt_mesh_prov_link.dhkey, + bt_mesh_prov_link.prov_salt, prov_device.new_dev_key); + if (err) { + LOG_ERR("Unable to generate device key"); + return err; + } + + bt_mesh_dev_key_cand(prov_device.new_dev_key); + /* Mark the link that was never opened as closed. */ + atomic_set_bit(bt_mesh_prov_link.flags, COMPLETE); + bt_mesh_reprovision(addr); + bt_mesh_dev_key_cand_activate(); + + if (bt_mesh_prov->reprovisioned) { + LOG_DBG("Application reprovisioned callback 0x%04x", bt_mesh_primary_addr()); + bt_mesh_prov->reprovisioned(bt_mesh_primary_addr()); + } + + prov_link_closed(PROV_BEARER_LINK_STATUS_SUCCESS); + return 0; +} + int bt_mesh_pb_remote_open_node(struct bt_mesh_rpr_cli *cli, struct bt_mesh_rpr_node *srv, uint16_t addr, bool composition_change) @@ -877,6 +943,11 @@ int bt_mesh_pb_remote_open_node(struct bt_mesh_rpr_cli *cli, return -ENOENT; } + /* Check if server is on same device as client */ + if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) && bt_mesh_has_addr(srv->addr)) { + return reprovision_local_client_server(addr); + } + return link_open(NULL, &pb_remote_cli, prov_device.node->net_idx, addr, 0, &ctx, 0); } diff --git a/tests/bsim/bluetooth/mesh/src/test_provision.c b/tests/bsim/bluetooth/mesh/src/test_provision.c index 171f8cccbbd..c78fe8dc87d 100644 --- a/tests/bsim/bluetooth/mesh/src/test_provision.c +++ b/tests/bsim/bluetooth/mesh/src/test_provision.c @@ -139,6 +139,19 @@ static const struct bt_mesh_comp rpr_srv_comp = { .elem_count = 1, }; +static const struct bt_mesh_comp rpr_cli_srv_comp = { + .elem = + (struct bt_mesh_elem[]){ + BT_MESH_ELEM(1, + MODEL_LIST(BT_MESH_MODEL_CFG_SRV, + BT_MESH_MODEL_CFG_CLI(&(struct bt_mesh_cfg_cli){}), + BT_MESH_MODEL_RPR_CLI(&rpr_cli), + BT_MESH_MODEL_RPR_SRV), + BT_MESH_MODEL_NONE), + }, + .elem_count = 1, +}; + static int mock_pdu_send(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { @@ -1043,18 +1056,127 @@ static void test_provisioner_pb_remote_client_provision_timeout(void) PASS(); } +static void reprovision_remote_devkey_client(struct bt_mesh_rpr_node *srv, + struct bt_mesh_cdb_node *node) +{ + uint8_t status; + uint8_t prev_node_dev_key[16]; + + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), + "Can't export device key from cdb"); + + bt_mesh_reprovision_remote(&rpr_cli, srv, current_dev_addr, false); + + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); + + /* Check that CDB has updated Device Key for the node. */ + ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), + "Can't export device key from cdb"); + + /* Check device key by adding appkey. */ + ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, + &status)); + ASSERT_OK(status); + + /* Let RPR Server verify Device Key. */ + k_sleep(K_SECONDS(2)); +} + +static void reprovision_remote_comp_data_client(struct bt_mesh_rpr_node *srv, + struct bt_mesh_cdb_node *node, + struct net_buf_simple *dev_comp) +{ + NET_BUF_SIMPLE_DEFINE(new_dev_comp, BT_MESH_RX_SDU_MAX); + uint8_t prev_node_dev_key[16]; + uint8_t page; + + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), + "Can't export device key from cdb"); + + bt_mesh_reprovision_remote(&rpr_cli, srv, current_dev_addr, true); + + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); + + /* Check that CDB has updated Device Key for the node. */ + ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), + "Can't export device key from cdb"); + + /* Check that Composition Data Page 128 is now Page 0. */ + net_buf_simple_reset(&new_dev_comp); + ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, current_dev_addr, 0, &page, + &new_dev_comp)); + + ASSERT_EQUAL(0, page); + ASSERT_EQUAL(dev_comp->len, new_dev_comp.len); + if (memcmp(dev_comp->data, new_dev_comp.data, dev_comp->len)) { + FAIL("Wrong composition data page 0"); + } + + /* Let RPR Server verify Device Key. */ + k_sleep(K_SECONDS(2)); +} + +static void reprovision_remote_address_client(struct bt_mesh_rpr_node *srv, + struct bt_mesh_cdb_node *node) +{ + uint8_t status; + uint8_t prev_node_dev_key[16]; + + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), + "Can't export device key from cdb"); + + bt_mesh_reprovision_remote(&rpr_cli, srv, current_dev_addr + 1, false); + + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); + + current_dev_addr++; + srv->addr++; + + /* Check that device doesn't respond to old address with old and new device key. */ + struct bt_mesh_cdb_node *prev_node; + uint8_t tmp[16]; + + prev_node = bt_mesh_cdb_node_alloc((uint8_t[16]) {}, current_dev_addr - 1, 1, 0); + ASSERT_TRUE(node); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_import(prev_node, prev_node_dev_key), + "Can't import device key into cdb"); + ASSERT_EQUAL(-ETIMEDOUT, bt_mesh_cfg_cli_app_key_add(0, current_dev_addr - 1, 0, 0, + test_app_key, &status)); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, tmp), + "Can't export device key from cdb"); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_import(prev_node, tmp), + "Can't import device key into cdb"); + ASSERT_EQUAL(-ETIMEDOUT, bt_mesh_cfg_cli_app_key_add(0, current_dev_addr - 1, 0, 0, + test_app_key, &status)); + bt_mesh_cdb_node_del(prev_node, false); + + /* Check that CDB has updated Device Key for the node. */ + ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), + "Can't export device key from cdb"); + + /* Check new device address by adding appkey. */ + ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, + &status)); + ASSERT_OK(status); + + /* Let RPR Server verify Device Key. */ + k_sleep(K_SECONDS(2)); + +} + /** @brief Verify robustness of NPPI procedures on a RPR Client by running Device Key Refresh, * Node Composition Refresh and Node Address Refresh procedures. */ static void test_provisioner_pb_remote_client_nppi_robustness(void) { NET_BUF_SIMPLE_DEFINE(dev_comp, BT_MESH_RX_SDU_MAX); - NET_BUF_SIMPLE_DEFINE(new_dev_comp, BT_MESH_RX_SDU_MAX); uint8_t page; uint16_t pb_remote_server_addr; uint8_t status; struct bt_mesh_cdb_node *node; - uint8_t prev_node_dev_key[16]; provisioner_pb_remote_client_setup(); @@ -1082,96 +1204,23 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void) node = bt_mesh_cdb_node_get(current_dev_addr); ASSERT_TRUE(node); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), - "Can't export device key from cdb"); LOG_INF("Testing DevKey refresh..."); for (int i = 0; i < PROV_REPROV_COUNT; i++) { LOG_INF("Refreshing device key #%d...\n", i); - bt_mesh_reprovision_remote(&rpr_cli, &srv, current_dev_addr, false); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); - - /* Check that CDB has updated Device Key for the node. */ - ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), - "Can't export device key from cdb"); - - /* Check device key by adding appkey. */ - ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, - &status)); - ASSERT_OK(status); - - /* Let RPR Server verify Device Key. */ - k_sleep(K_SECONDS(2)); + reprovision_remote_devkey_client(&srv, node); } LOG_INF("Testing Composition Data refresh..."); for (int i = 0; i < PROV_REPROV_COUNT; i++) { LOG_INF("Changing Composition Data #%d...\n", i); - bt_mesh_reprovision_remote(&rpr_cli, &srv, current_dev_addr, true); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); - - /* Check that CDB has updated Device Key for the node. */ - ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), - "Can't export device key from cdb"); - - /* Check that Composition Data Page 128 is now Page 0. */ - net_buf_simple_reset(&new_dev_comp); - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, current_dev_addr, 0, &page, - &new_dev_comp)); - ASSERT_EQUAL(0, page); - ASSERT_EQUAL(dev_comp.len, new_dev_comp.len); - if (memcmp(dev_comp.data, new_dev_comp.data, dev_comp.len)) { - FAIL("Wrong composition data page 0"); - } - - /* Let RPR Server verify Device Key. */ - k_sleep(K_SECONDS(2)); + reprovision_remote_comp_data_client(&srv, node, &dev_comp); } LOG_INF("Testing address refresh..."); for (int i = 0; i < PROV_REPROV_COUNT; i++) { LOG_INF("Changing address #%d...\n", i); - bt_mesh_reprovision_remote(&rpr_cli, &srv, current_dev_addr + 1, false); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); - - current_dev_addr++; - srv.addr++; - - /* Check that device doesn't respond to old address with old and new device key. */ - struct bt_mesh_cdb_node *prev_node; - uint8_t tmp[16]; - - prev_node = bt_mesh_cdb_node_alloc((uint8_t[16]) {}, current_dev_addr - 1, 1, 0); - ASSERT_TRUE(node); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_import(prev_node, prev_node_dev_key), - "Can't import device key into cdb"); - ASSERT_EQUAL(-ETIMEDOUT, bt_mesh_cfg_cli_app_key_add(0, current_dev_addr - 1, 0, 0, - test_app_key, &status)); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, tmp), - "Can't export device key from cdb"); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_import(prev_node, tmp), - "Can't import device key into cdb"); - ASSERT_EQUAL(-ETIMEDOUT, bt_mesh_cfg_cli_app_key_add(0, current_dev_addr - 1, 0, 0, - test_app_key, &status)); - bt_mesh_cdb_node_del(prev_node, false); - - /* Check that CDB has updated Device Key for the node. */ - ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), - "Can't export device key from cdb"); - - /* Check new device address by adding appkey. */ - ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, - &status)); - ASSERT_OK(status); - - /* Let RPR Server verify Device Key. */ - k_sleep(K_SECONDS(2)); + reprovision_remote_address_client(&srv, node); } PASS(); @@ -1211,13 +1260,78 @@ static void test_device_pb_remote_server_proved(void) PASS(); } +static void reprovision_remote_devkey_server(const uint16_t initial_addr) +{ + uint8_t prev_dev_key[16]; + uint8_t dev_key[16]; + + ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); + + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); + ASSERT_EQUAL(initial_addr, bt_mesh_primary_addr()); + + /* Let Configuration Client activate the new Device Key and verify that it has + * been changed. + */ + k_sleep(K_SECONDS(2)); + ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); + ASSERT_TRUE(memcmp(&prev_dev_key, dev_key, sizeof(dev_key))); +} + +static void reprovision_remote_comp_data_server(const uint16_t initial_addr) +{ + u_int8_t prev_dev_key[16]; + u_int8_t dev_key[16]; + + /* The RPR Server won't let to run Node Composition Refresh procedure without first + * setting the BT_MESH_COMP_DIRTY flag. The flag is set on a boot if there is a + * "bt/mesh/cmp" entry in settings. The entry is added by the + * `bt_mesh_comp_change_prepare() call. The test suite is not compiled + * with CONFIG_BT_SETTINGS, so the flag will never be set. Since the purpose of the + * test is to check RPR Server behavior, but not the actual swap of the Composition + * Data, the flag is toggled directly from the test. + */ + atomic_set_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY); + ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); + + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); + + /* Drop the flag manually as CONFIG_BT_SETTINGS is not enabled. */ + atomic_clear_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY); + + ASSERT_EQUAL(initial_addr, bt_mesh_primary_addr()); + + /* Let Configuration Client activate the new Device Key and verify that it has + * been changed. + */ + k_sleep(K_SECONDS(2)); + ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); + ASSERT_TRUE(memcmp(prev_dev_key, dev_key, sizeof(dev_key))); +} + +static void reprovision_remote_address_server(const uint16_t initial_addr) +{ + uint8_t prev_dev_key[16]; + uint8_t dev_key[16]; + + ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); + + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); + ASSERT_EQUAL(initial_addr + 1, bt_mesh_primary_addr()); + + /* Let Configuration Client activate the new Device Key and verify that it has + * been changed. + */ + k_sleep(K_SECONDS(2)); + ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); + ASSERT_TRUE(memcmp(prev_dev_key, dev_key, sizeof(dev_key))); +} + /** @brief Verify robustness of NPPI procedures on a RPR Server by running Device Key Refresh, * Node Composition Refresh and Node Address Refresh procedures multiple times each. */ static void test_device_pb_remote_server_nppi_robustness(void) { - struct bt_mesh_key prev_dev_key; - k_sem_init(&prov_sem, 0, 1); k_sem_init(&reprov_sem, 0, 1); @@ -1230,65 +1344,25 @@ static void test_device_pb_remote_server_nppi_robustness(void) ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); const uint16_t initial_addr = bt_mesh_primary_addr(); - memcpy(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key)); - LOG_INF("Enabling PB-Remote server"); ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_REMOTE)); /* Test Device Key Refresh procedure robustness. */ for (int i = 0; i < PROV_REPROV_COUNT; i++) { LOG_INF("Devkey refresh loop #%d, waiting for being reprov ...\n", i); - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); - ASSERT_EQUAL(initial_addr, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key and verify that it has - * been changed. - */ - k_sleep(K_SECONDS(2)); - ASSERT_TRUE(memcmp(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key))); - memcpy(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key)); + reprovision_remote_devkey_server(initial_addr); } /* Test Node Composition Refresh procedure robustness. */ for (int i = 0; i < PROV_REPROV_COUNT; i++) { - /* The RPR Server won't let to run Node Composition Refresh procedure without first - * setting the BT_MESH_COMP_DIRTY flag. The flag is set on a boot if there is a - * "bt/mesh/cmp" entry in settings. The entry is added by the - * `bt_mesh_comp_change_prepare() call. The test suite is not compiled - * with CONFIG_BT_SETTINGS, so the flag will never be set. Since the purpose of the - * test is to check RPR Server behavior, but not the actual swap of the Composition - * Data, the flag is toggled directly from the test. - */ - atomic_set_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY); - LOG_INF("Composition data refresh loop #%d, waiting for being reprov ...\n", i); - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); - - /* Drop the flag manually as CONFIG_BT_SETTINGS is not enabled. */ - atomic_clear_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY); - - ASSERT_EQUAL(initial_addr, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key and verify that it has - * been changed. - */ - k_sleep(K_SECONDS(2)); - ASSERT_TRUE(memcmp(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key))); - memcpy(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key)); + reprovision_remote_comp_data_server(initial_addr); } /* Node Address Refresh robustness. */ for (int i = 0; i < PROV_REPROV_COUNT; i++) { LOG_INF("Address refresh loop #%d, waiting for being reprov ...\n", i); - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); - ASSERT_EQUAL(initial_addr + 1 + i, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key and verify that it has - * been changed. - */ - k_sleep(K_SECONDS(2)); - ASSERT_TRUE(memcmp(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key))); - memcpy(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key)); + reprovision_remote_address_server(initial_addr+i); } PASS(); @@ -1325,6 +1399,172 @@ static void test_provisioner_pb_remote_client_ncrp_provision(void) PASS(); } +/** @brief A device running a Remote Provisioning client and server that is used to reprovision + * another device and it self with the client. + */ +static void test_device_pb_remote_client_server_same_dev(void) +{ + NET_BUF_SIMPLE_DEFINE(dev_comp, BT_MESH_RX_SDU_MAX); + uint8_t status; + struct bt_mesh_cdb_node *node; + uint8_t page; + uint8_t prev_dev_key[16]; + uint16_t test_vector[] = { 0x0002, 0x0001 }; + + k_sem_init(&prov_sem, 0, 1); + k_sem_init(&reprov_sem, 0, 1); + + bt_mesh_device_setup(&prov, &rpr_cli_srv_comp); + + ASSERT_OK(bt_mesh_cdb_create(test_net_key)); + ASSERT_OK(bt_mesh_provision(test_net_key, 0, 0, 0, 0x0001, dev_key)); + + LOG_INF("Enabling PB-Remote server"); + ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_REMOTE)); + + /* Provision a remote device with RPR Client and Server with local RPR Server. */ + current_dev_addr = 0x0001; + struct bt_mesh_rpr_node srv = { + .addr = current_dev_addr, + .net_idx = 0, + .ttl = 3, + }; + + LOG_INF("Provisioner prov, waiting for prov ...\n"); + ASSERT_OK(provision_remote(&srv, 1, &srv.addr)); + + ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); + + /* Check device key by adding bt_mesh_reprovision_remote appkey. */ + ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, &status)); + ASSERT_OK(status); + + /* Swap callback to catch when device reprovisioned. */ + prov.node_added = prov_node_added_rpr; + + /* Reprovision a device with both RPR Client and Server. */ + for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { + current_dev_addr = test_vector[i]; + srv.addr = current_dev_addr; + bool self_reprov = (bool)(current_dev_addr == bt_mesh_primary_addr()); + + /* Store initial Composition Data Page 0. */ + net_buf_simple_reset(&dev_comp); + ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, current_dev_addr, 0, &page, &dev_comp)); + + node = bt_mesh_cdb_node_get(current_dev_addr); + ASSERT_TRUE(node); + + LOG_INF("Refreshing 0x%04x device key ...\n", srv.addr); + ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); + reprovision_remote_devkey_client(&srv, node); + if (self_reprov) { + uint8_t dev_key[16]; + + ASSERT_EQUAL(current_dev_addr, bt_mesh_primary_addr()); + + /* Let Configuration Client activate the new Device Key + * and verify that it has been changed. + */ + ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); + ASSERT_TRUE(memcmp(prev_dev_key, dev_key, sizeof(dev_key))); + } + + LOG_INF("Changing 0x%04x Composition Data ...\n", srv.addr); + ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); + reprovision_remote_comp_data_client(&srv, node, &dev_comp); + if (self_reprov) { + uint8_t dev_key[16]; + + ASSERT_EQUAL(current_dev_addr, bt_mesh_primary_addr()); + + /* Let Configuration Client activate the new Device Key + * and verify that it has been changed. + */ + ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); + ASSERT_TRUE(memcmp(prev_dev_key, dev_key, sizeof(struct bt_mesh_key))); + } + + LOG_INF("Changing 0x%04x address ...\n", srv.addr); + ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); + reprovision_remote_address_client(&srv, node); + if (self_reprov) { + uint8_t dev_key[16]; + + ASSERT_EQUAL(current_dev_addr, bt_mesh_primary_addr()); + + /* Let Configuration Client activate the new Device Key + * and verify that it has been changed. + */ + ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); + ASSERT_TRUE(memcmp(prev_dev_key, dev_key, sizeof(dev_key))); + } + } + + PASS(); +} + +/** @brief Verify that the Remote Provisioning client and server is able to be reprovision + * by another device with a Remote Provisioning client and server. + */ +static void test_device_pb_remote_server_same_dev(void) +{ + k_sem_init(&prov_sem, 0, 1); + k_sem_init(&reprov_sem, 0, 1); + + bt_mesh_device_setup(&prov, &rpr_cli_srv_comp); + + ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_ADV)); + + LOG_INF("Waiting for being provisioned..."); + ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); + + LOG_INF("Enabling PB-Remote server"); + ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_REMOTE)); + + /* Swap callback to catch when device reprovisioned. */ + prov.node_added = prov_node_added_rpr; + + const uint16_t initial_addr = bt_mesh_primary_addr(); + + LOG_INF("Devkey refresh, waiting for being reprov ...\n"); + reprovision_remote_devkey_server(initial_addr); + + LOG_INF("Composition data refresh, waiting for being reprov ...\n"); + reprovision_remote_comp_data_server(initial_addr); + + LOG_INF("Address refresh, waiting for being reprov ...\n"); + reprovision_remote_address_server(initial_addr); + + PASS(); +} + +static void comp_data_get(uint16_t server_addr, uint8_t page, struct net_buf_simple *comp) +{ + uint8_t page_rsp; + + net_buf_simple_reset(comp); + ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, server_addr, page, &page_rsp, comp)); + ASSERT_EQUAL(page, page_rsp); +} + +static void comp_data_compare(struct net_buf_simple *comp1, struct net_buf_simple *comp2, + bool expect_equal) +{ + if (expect_equal) { + ASSERT_EQUAL(comp1->len, comp2->len); + if (memcmp(comp1->data, comp2->data, comp1->len)) { + FAIL("Composition data is not equal"); + } + } else { + if (comp1->len == comp2->len) { + if (!memcmp(comp1->data, comp2->data, comp1->len)) { + FAIL("Composition data is equal"); + } + } + } +} + /** @brief Test Node Composition Refresh procedure on Remote Provisioning client: * - initiate Node Composition Refresh procedure on a 3rd device. */ @@ -1543,6 +1783,10 @@ static const struct bst_test_instance test_connect[] = { "Device: pb-remote reprovisioning, NPPI robustness"), TEST_CASE(device, pb_remote_server_unproved_unresponsive, "Device: used for remote provisioning, starts unprovisioned, stops responding"), + TEST_CASE(device, pb_remote_client_server_same_dev, + "Device: used for remote provisioning, with both client and server"), + TEST_CASE(device, pb_remote_server_same_dev, + "Device: used for remote reprovisioning, with both client and server"), #endif TEST_CASE(provisioner, pb_adv_no_oob, diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh new file mode 100755 index 00000000000..33de74370e1 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test a node re-provisioning through Remote Provisioning models. Procedure: +# 1. Device (prov_device_pb_remote_client_server_same_dev) provisions it self +# and start scanning for an upprovisioned device, and provisions the the +# second device (prov_device_pb_remote_server_same_dev) with local RPR server. +# 2. The first device (prov_device_pb_remote_client_server_same_dev) execute +# device key refresh procedure the second device (prov_device_pb_remote_server_same_dev). +# 3. The first device (prov_device_pb_remote_client_server_same_dev) execute +# composition refresh procedure the second device (prov_device_pb_remote_server_same_dev). +# 4. The first device (prov_device_pb_remote_client_server_same_dev) execute +# address refresh procedure the second device (prov_device_pb_remote_server_same_dev). +# 5. The first device (prov_device_pb_remote_client_server_same_dev) execute +# device key refresh procedure on it self with local RPR client and server. +# 6. The first device (prov_device_pb_remote_client_server_same_dev) execute +# composition refresh procedure on it self with local RPR client and server. +# 7. The first device (prov_device_pb_remote_client_server_same_dev) execute +# address refresh procedure on it self with local RPR client and server. +conf=prj_mesh1d1_conf +RunTest mesh_prov_pb_remote_client_server_same_dev \ + prov_device_pb_remote_client_server_same_dev \ + prov_device_pb_remote_server_same_dev + +conf=prj_mesh1d1_conf +overlay=overlay_psa_conf +RunTest mesh_prov_pb_remote_client_server_same_dev \ + prov_device_pb_remote_client_server_same_dev \ + prov_device_pb_remote_server_same_dev From 60dc14e371af10a1f549fb3541b5be922217e524 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Fri, 6 Oct 2023 14:12:18 +0200 Subject: [PATCH 0203/1623] [nrf fromtree] tests: bluetooth: tester: Fix self-update test DFU/SR/FD/BV-59-C MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DFU/SR/FD/BV-59-C tests Distributor self-update. Because the actuall firmware swapping doesn't happen, we need to just simulate the swapping by setting new Firmware ID sent by LT. We use slot to take firmware id as by procedure, Fw Update Server doesn't know about it. Signed-off-by: Pavel Vasilyev (cherry picked from commit 0eb027ab7cc2f372d969f7c5a1fbac39294163e8) Signed-off-by: Alperen Şener (cherry picked from commit 6ae93608a6e001dd1563740855afdda1bad45dce) --- tests/bluetooth/tester/src/btp_mesh.c | 33 ++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 2a74bb03828..c191ed54568 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -17,6 +17,7 @@ #include #include #include +#include "mesh/access.h" #include #define LOG_MODULE_NAME bttester_mesh @@ -112,6 +113,19 @@ static const struct bt_mesh_blob_io dummy_blob_io = { #endif #if defined(CONFIG_BT_MESH_DFD_SRV) +static const struct bt_mesh_dfu_slot *dfu_self_update_slot; + +static bool is_self_update(struct bt_mesh_dfd_srv *srv) +{ + for (int i = 0; i < ARRAY_SIZE(srv->targets); i++) { + if (bt_mesh_has_addr(srv->targets[i].blob.addr)) { + return true; + } + } + + return false; +} + /* DFD Model data*/ static int dfd_srv_recv(struct bt_mesh_dfd_srv *srv, const struct bt_mesh_dfu_slot *slot, @@ -138,6 +152,13 @@ static int dfd_srv_send(struct bt_mesh_dfd_srv *srv, *io = &dummy_blob_io; + dfu_self_update_slot = NULL; + + if (is_self_update(srv)) { + LOG_DBG("DFD server starts self-update..."); + dfu_self_update_slot = slot; + } + return 0; } @@ -216,7 +237,7 @@ static struct bt_mesh_blob_cli blob_cli = { .cb = &blob_cli_handlers }; #if defined(CONFIG_BT_MESH_DFU_SRV) const char *metadata_data = "1100000000000011"; -static uint8_t dfu_fwid[] = { +static uint8_t dfu_fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -284,6 +305,16 @@ static int dfu_apply(struct bt_mesh_dfu_srv *srv, LOG_DBG("Applying DFU transfer..."); +#if defined(CONFIG_BT_MESH_DFD_SRV) + if (is_self_update(&dfd_srv) && dfu_self_update_slot != NULL) { + LOG_DBG("Swapping fwid for self-update"); + /* Simulate self-update by swapping fwid. */ + memcpy(&dfu_fwid[0], dfu_self_update_slot->fwid, dfu_self_update_slot->fwid_len); + dfu_imgs[0].fwid_len = dfu_self_update_slot->fwid_len; + } + +#endif + return 0; } From 14095d899da44030014ce550dcc2b7fb4b910d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Thu, 5 Oct 2023 13:19:51 +0200 Subject: [PATCH 0204/1623] [nrf fromtree] Bluetooth: Mesh: Add missing comp pages to LCD mod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds support for all composition data pages to the Large Composition Data model. Signed-off-by: Anders Storrø (cherry picked from commit 57cb1b1ccb11a47c911772678b05cb309c9dcaf4) Signed-off-by: Alperen Şener (cherry picked from commit b8ebbe98e0b36b736fb4dac722d390dd5da23a13) --- subsys/bluetooth/mesh/Kconfig | 10 + subsys/bluetooth/mesh/access.c | 228 ++++++++++++-------- subsys/bluetooth/mesh/access.h | 2 +- subsys/bluetooth/mesh/large_comp_data_srv.c | 53 ++++- 4 files changed, 199 insertions(+), 94 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 9f24ff81975..605e4608be7 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1375,6 +1375,16 @@ config BT_MESH_PRIV_BEACON_CLI endif # BT_MESH_PRIV_BEACONS +config BT_MESH_COMP_PST_BUF_SIZE + int "Composition Data Page persistence buffer size" + default 100 + help + Stack allocated buffer used to temporarily hold Composition + Data Pages during flash operations. Should reflect the size + of the largest Composition Data Page present in the application. + Note that this buffer should still be large enough to restore previously stored + pages after a performed device firmware update. + config BT_MESH_COMP_PAGE_1 bool "Support for Composition Data Page 1" depends on BT_MESH_MODEL_EXTENSIONS diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index b6dab2d67a7..24259165e05 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -173,6 +173,18 @@ static void data_buf_add_le16_offset(struct net_buf_simple *buf, } } +static void data_buf_add_mem_offset(struct net_buf_simple *buf, uint8_t *data, size_t len, + size_t *offset) +{ + if (*offset >= len) { + *offset -= len; + return; + } + + net_buf_simple_add_mem(buf, data + *offset, len - *offset); + *offset = 0; +} + static void comp_add_model(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, bool vnd, void *user_data) { @@ -187,20 +199,6 @@ static void comp_add_model(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, } #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV) -static void data_buf_add_mem_offset(struct net_buf_simple *buf, - const void *mem, size_t len, - size_t *offset) -{ - if (*offset >= len) { - *offset -= len; - return; - } else if (*offset > 0) { - net_buf_simple_add_mem(buf, ((uint8_t *)mem), (len - *offset)); - - } else { - net_buf_simple_add_mem(buf, mem, len); - } -} static size_t metadata_model_size(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, bool vnd) @@ -366,23 +364,6 @@ int bt_mesh_metadata_get_page_0(struct net_buf_simple *buf, size_t offset) } #endif -size_t bt_mesh_comp_page_0_size(void) -{ - const struct bt_mesh_comp *comp; - const struct bt_mesh_elem *elem; - size_t size = 10; - int i; - - comp = bt_mesh_comp_get(); - - for (i = 0; i < comp->elem_count; i++) { - elem = &comp->elem[i]; - size += bt_mesh_comp_elem_size(elem); - } - - return size; -} - static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem, size_t *offset) { @@ -398,7 +379,7 @@ static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem, return 0; } - if (net_buf_simple_tailroom(buf) < (elem_size + BT_MESH_MIC_SHORT)) { + if (net_buf_simple_tailroom(buf) < ((elem_size - *offset) + BT_MESH_MIC_SHORT)) { if (IS_ENABLED(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)) { /* Mesh Profile 1.1 Section 4.4.1.2.2: * If the complete list of models does not fit in the Data field, @@ -516,8 +497,8 @@ static bool is_cor_present(struct bt_mesh_model *mod, uint8_t *cor_id) return false; } -static void prep_model_item_header(struct bt_mesh_model *mod, uint8_t *cor_id, - uint8_t *mod_cnt, struct net_buf_simple *buf) +static void prep_model_item_header(struct bt_mesh_model *mod, uint8_t *cor_id, uint8_t *mod_cnt, + struct net_buf_simple *buf, size_t *offset) { uint8_t ext_mod_cnt; bool cor_present; @@ -536,41 +517,41 @@ static void prep_model_item_header(struct bt_mesh_model *mod, uint8_t *cor_id, if (cor_present) { mod_elem_info |= BIT(0); } - net_buf_simple_add_u8(buf, mod_elem_info); + data_buf_add_u8_offset(buf, mod_elem_info, offset); if (cor_present) { - net_buf_simple_add_u8(buf, *cor_id); + data_buf_add_u8_offset(buf, *cor_id, offset); } memset(mod_cnt, ext_mod_cnt, sizeof(uint8_t)); } static void add_items_to_page(struct net_buf_simple *buf, struct bt_mesh_model *mod, - uint8_t ext_mod_cnt) + uint8_t ext_mod_cnt, size_t *offset) { - int i, offset; + int i, elem_offset; uint8_t mod_idx; MOD_REL_LIST_FOR_EACH(i) { if (IS_MOD_EXTENSION(mod, i)) { - offset = mod->elem_idx - mod_rel_list[i].elem_base; + elem_offset = mod->elem_idx - mod_rel_list[i].elem_base; mod_idx = mod_rel_list[i].idx_base; if (ext_mod_cnt < 32 && - offset < 4 && - offset > -5) { + elem_offset < 4 && + elem_offset > -5) { /* short format */ - if (offset < 0) { - offset += 8; + if (elem_offset < 0) { + elem_offset += 8; } - offset |= mod_idx << 3; - net_buf_simple_add_u8(buf, offset); + elem_offset |= mod_idx << 3; + data_buf_add_u8_offset(buf, elem_offset, offset); } else { /* long format */ - if (offset < 0) { - offset += 256; + if (elem_offset < 0) { + elem_offset += 256; } - net_buf_simple_add_u8(buf, offset); - net_buf_simple_add_u8(buf, mod_idx); + data_buf_add_u8_offset(buf, elem_offset, offset); + data_buf_add_u8_offset(buf, mod_idx, offset); } } } @@ -613,7 +594,7 @@ static size_t page1_elem_size(struct bt_mesh_elem *elem) return temp_size; } -static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf) +static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf, size_t offset) { const struct bt_mesh_comp *comp; uint8_t cor_id = 0; @@ -623,8 +604,14 @@ static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf) comp = bt_mesh_comp_get(); for (i = 0; i < comp->elem_count; i++) { - if (net_buf_simple_tailroom(buf) < - (page1_elem_size(&comp->elem[i]) + BT_MESH_MIC_SHORT)) { + size_t elem_size = page1_elem_size(&comp->elem[i]); + + if (offset >= elem_size) { + offset -= elem_size; + continue; + } + + if (net_buf_simple_tailroom(buf) < ((elem_size - offset) + BT_MESH_MIC_SHORT)) { if (IS_ENABLED(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)) { /* Mesh Profile 1.1 Section 4.4.1.2.2: * If the complete list of models does not fit in the Data field, @@ -639,49 +626,53 @@ static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf) return -E2BIG; } - net_buf_simple_add_u8(buf, comp->elem[i].model_count); - net_buf_simple_add_u8(buf, comp->elem[i].vnd_model_count); + data_buf_add_u8_offset(buf, comp->elem[i].model_count, &offset); + data_buf_add_u8_offset(buf, comp->elem[i].vnd_model_count, &offset); for (j = 0; j < comp->elem[i].model_count; j++) { - prep_model_item_header(&comp->elem[i].models[j], - &cor_id, &ext_mod_cnt, buf); + prep_model_item_header(&comp->elem[i].models[j], &cor_id, &ext_mod_cnt, buf, + &offset); if (ext_mod_cnt != 0) { - add_items_to_page(buf, - &comp->elem[i].models[j], - ext_mod_cnt); + add_items_to_page(buf, &comp->elem[i].models[j], ext_mod_cnt, + &offset); } } for (j = 0; j < comp->elem[i].vnd_model_count; j++) { - prep_model_item_header(&comp->elem[i].vnd_models[j], - &cor_id, &ext_mod_cnt, buf); + prep_model_item_header(&comp->elem[i].vnd_models[j], &cor_id, &ext_mod_cnt, + buf, &offset); if (ext_mod_cnt != 0) { - add_items_to_page(buf, - &comp->elem[i].vnd_models[j], - ext_mod_cnt); + add_items_to_page(buf, &comp->elem[i].vnd_models[j], ext_mod_cnt, + &offset); } } } return 0; } -static int bt_mesh_comp_data_get_page_2(struct net_buf_simple *buf) +static int bt_mesh_comp_data_get_page_2(struct net_buf_simple *buf, size_t offset) { if (!dev_comp2) { LOG_ERR("Composition data P2 not registered"); return -ENODEV; } + size_t elem_size; + for (int i = 0; i < dev_comp2->record_cnt; i++) { - if (net_buf_simple_tailroom(buf) < - (8 + dev_comp2->record[i].elem_offset_cnt + dev_comp2->record[i].data_len + - BT_MESH_MIC_SHORT)) { + elem_size = + 8 + dev_comp2->record[i].elem_offset_cnt + dev_comp2->record[i].data_len; + if (offset >= elem_size) { + offset -= elem_size; + continue; + } + + if (net_buf_simple_tailroom(buf) < ((elem_size - offset) + BT_MESH_MIC_SHORT)) { if (IS_ENABLED(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)) { /* Mesh Profile 1.1 Section 4.4.1.2.2: * If the complete list of models does not fit in the Data field, * the element shall not be reported. */ - LOG_DBG("Record 0x%04x didn't fit in the Data field", - i); + LOG_DBG("Record 0x%04x didn't fit in the Data field", i); return 0; } @@ -689,20 +680,20 @@ static int bt_mesh_comp_data_get_page_2(struct net_buf_simple *buf) return -E2BIG; } - net_buf_simple_add_le16(buf, dev_comp2->record[i].id); - net_buf_simple_add_u8(buf, dev_comp2->record[i].version.x); - net_buf_simple_add_u8(buf, dev_comp2->record[i].version.y); - net_buf_simple_add_u8(buf, dev_comp2->record[i].version.z); - net_buf_simple_add_u8(buf, dev_comp2->record[i].elem_offset_cnt); + data_buf_add_le16_offset(buf, dev_comp2->record[i].id, &offset); + data_buf_add_u8_offset(buf, dev_comp2->record[i].version.x, &offset); + data_buf_add_u8_offset(buf, dev_comp2->record[i].version.y, &offset); + data_buf_add_u8_offset(buf, dev_comp2->record[i].version.z, &offset); + data_buf_add_u8_offset(buf, dev_comp2->record[i].elem_offset_cnt, &offset); if (dev_comp2->record[i].elem_offset_cnt) { - net_buf_simple_add_mem(buf, dev_comp2->record[i].elem_offset, - dev_comp2->record[i].elem_offset_cnt); + data_buf_add_mem_offset(buf, (uint8_t *)dev_comp2->record[i].elem_offset, + dev_comp2->record[i].elem_offset_cnt, &offset); } - net_buf_simple_add_le16(buf, dev_comp2->record[i].data_len); + data_buf_add_le16_offset(buf, dev_comp2->record[i].data_len, &offset); if (dev_comp2->record[i].data_len) { - net_buf_simple_add_mem(buf, dev_comp2->record[i].data, - dev_comp2->record[i].data_len); + data_buf_add_mem_offset(buf, (uint8_t *)dev_comp2->record[i].data, + dev_comp2->record[i].data_len, &offset); } } @@ -2212,20 +2203,89 @@ int bt_mesh_comp_data_get_page(struct net_buf_simple *buf, size_t page, size_t o if (page == 0 || page == 128) { return bt_mesh_comp_data_get_page_0(buf, offset); } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && (page == 1 || page == 129)) { - return bt_mesh_comp_data_get_page_1(buf); + return bt_mesh_comp_data_get_page_1(buf, offset); } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && (page == 2 || page == 130)) { - return bt_mesh_comp_data_get_page_2(buf); + return bt_mesh_comp_data_get_page_2(buf, offset); } return -EINVAL; } +size_t comp_page_0_size(void) +{ + const struct bt_mesh_comp *comp; + const struct bt_mesh_elem *elem; + size_t size = 10; /* Non-variable length params of comp page 0. */ + + comp = bt_mesh_comp_get(); + + for (int i = 0; i < comp->elem_count; i++) { + elem = &comp->elem[i]; + size += bt_mesh_comp_elem_size(elem); + } + + return size; +} + +size_t comp_page_1_size(void) +{ + const struct bt_mesh_comp *comp; + size_t size = 0; + + comp = bt_mesh_comp_get(); + + for (int i = 0; i < comp->elem_count; i++) { + + size += page1_elem_size(&comp->elem[i]); + } + + return size; +} + +size_t comp_page_2_size(void) +{ + size_t size = 0; + + if (!dev_comp2) { + LOG_ERR("Composition data P2 not registered"); + return size; + } + + for (int i = 0; i < dev_comp2->record_cnt; i++) { + size += 8 + dev_comp2->record[i].elem_offset_cnt + dev_comp2->record[i].data_len; + } + return size; +} + +size_t bt_mesh_comp_page_size(uint8_t page) +{ + if (page == 0 || page == 128) { + return comp_page_0_size(); + } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && (page == 1 || page == 129)) { + return comp_page_1_size(); + } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && (page == 2 || page == 130)) { + return comp_page_2_size(); + } + + return 0; +} + int bt_mesh_comp_store(void) { - NET_BUF_SIMPLE_DEFINE(buf, BT_MESH_TX_SDU_MAX); +#if IS_ENABLED(CONFIG_BT_MESH_V1d1) + NET_BUF_SIMPLE_DEFINE(buf, CONFIG_BT_MESH_COMP_PST_BUF_SIZE); int err; for (int i = 0; i < ARRAY_SIZE(comp_data_pages); i++) { + size_t page_size = bt_mesh_comp_page_size(i); + + if (page_size > CONFIG_BT_MESH_COMP_PST_BUF_SIZE) { + LOG_WRN("CDP%d is larger than the CDP persistence buffer. " + "Please increase the CDP persistence buffer size " + "to the required size (%d bytes)", + i, page_size); + } + net_buf_simple_reset(&buf); err = bt_mesh_comp_data_get_page(&buf, comp_data_pages[i].page, 0); @@ -2242,7 +2302,7 @@ int bt_mesh_comp_store(void) LOG_DBG("Stored CDP%d", comp_data_pages[i].page); } - +#endif return 0; } diff --git a/subsys/bluetooth/mesh/access.h b/subsys/bluetooth/mesh/access.h index 4740963dd21..6027768ea94 100644 --- a/subsys/bluetooth/mesh/access.h +++ b/subsys/bluetooth/mesh/access.h @@ -23,7 +23,7 @@ enum { void bt_mesh_elem_register(struct bt_mesh_elem *elem, uint8_t count); uint8_t bt_mesh_elem_count(void); -size_t bt_mesh_comp_page_0_size(void); +size_t bt_mesh_comp_page_size(uint8_t page); int bt_mesh_comp_data_get_page_0(struct net_buf_simple *buf, size_t offset); size_t bt_mesh_metadata_page_0_size(void); int bt_mesh_metadata_get_page_0(struct net_buf_simple *buf, size_t offset); diff --git a/subsys/bluetooth/mesh/large_comp_data_srv.c b/subsys/bluetooth/mesh/large_comp_data_srv.c index 9f097f4355a..12497d053a2 100644 --- a/subsys/bluetooth/mesh/large_comp_data_srv.c +++ b/subsys/bluetooth/mesh/large_comp_data_srv.c @@ -59,24 +59,59 @@ static int handle_large_comp_data_get(struct bt_mesh_model *model, struct bt_mes LOG_DBG("page %u offset %u", page, offset); bt_mesh_model_msg_init(&rsp, OP_LARGE_COMP_DATA_STATUS); - - if (page != 0U) { + if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && + (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 130U; + } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && + (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 129U; + } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 128U; + } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { + page = 2U; + } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { + page = 1U; + } else if (page != 0U) { LOG_DBG("Composition page %u not available", page); page = 0U; } net_buf_simple_add_u8(&rsp, page); - - total_size = bt_mesh_comp_page_0_size(); net_buf_simple_add_le16(&rsp, offset); - net_buf_simple_add_le16(&rsp, total_size); - if (offset < total_size) { - err = bt_mesh_comp_data_get_page_0(&rsp, offset); - if (err && err != -E2BIG) { - LOG_ERR("comp_get_page_0 returned error"); + if (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) && page < 128) { + size_t msg_space; + + NET_BUF_SIMPLE_DEFINE(temp_buf, CONFIG_BT_MESH_COMP_PST_BUF_SIZE); + err = bt_mesh_comp_read(&temp_buf, page); + if (err) { + LOG_ERR("Could not read comp data p%d, err: %d", page, err); return err; } + + net_buf_simple_add_le16(&rsp, temp_buf.len); + if (offset > temp_buf.len) { + return 0; + } + + msg_space = net_buf_simple_tailroom(&rsp) - BT_MESH_MIC_SHORT; + net_buf_simple_add_mem( + &rsp, temp_buf.data + offset, + (msg_space < (temp_buf.len - offset)) ? msg_space : temp_buf.len - offset); + } else { + total_size = bt_mesh_comp_page_size(page); + net_buf_simple_add_le16(&rsp, total_size); + + if (offset < total_size) { + err = bt_mesh_comp_data_get_page(&rsp, page, offset); + if (err && err != -E2BIG) { + LOG_ERR("Could not read comp data p%d, err: %d", page, err); + return err; + } + } } if (bt_mesh_model_send(model, ctx, &rsp, NULL, NULL)) { From 688605c9b2174c0086e86c235b0377d54ff0b09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Fri, 6 Oct 2023 08:56:49 +0200 Subject: [PATCH 0205/1623] [nrf fromtree] Bluetooth: Mesh: Common comp page parse func MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create common composition page parser function. Signed-off-by: Anders Storrø (cherry picked from commit 65f029e1850090887317efa37fc37758c2bffa93) Signed-off-by: Alperen Şener (cherry picked from commit 646cce25f0247f9a925e4145e57b83c71755f5d0) --- subsys/bluetooth/mesh/access.c | 27 +++++++++++++++++++++ subsys/bluetooth/mesh/access.h | 1 + subsys/bluetooth/mesh/cfg_srv.c | 22 +---------------- subsys/bluetooth/mesh/large_comp_data_srv.c | 22 +---------------- 4 files changed, 30 insertions(+), 42 deletions(-) diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 24259165e05..2ea7ece90df 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -2562,3 +2562,30 @@ void bt_mesh_model_data_store_schedule(struct bt_mesh_model *mod) mod->flags |= BT_MESH_MOD_DATA_PENDING; bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_MOD_PENDING); } + +uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf) +{ + uint8_t page = net_buf_simple_pull_u8(buf); + + if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && + (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 130U; + } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && + (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 129U; + } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 128U; + } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { + page = 2U; + } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { + page = 1U; + } else if (page != 0U) { + LOG_DBG("Composition page %u not available", page); + page = 0U; + } + + return page; +} diff --git a/subsys/bluetooth/mesh/access.h b/subsys/bluetooth/mesh/access.h index 6027768ea94..f58c6f1d449 100644 --- a/subsys/bluetooth/mesh/access.h +++ b/subsys/bluetooth/mesh/access.h @@ -64,6 +64,7 @@ int bt_mesh_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf); int bt_mesh_comp_register(const struct bt_mesh_comp *comp); int bt_mesh_comp_store(void); int bt_mesh_comp_read(struct net_buf_simple *buf, uint8_t page); +uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf); int bt_mesh_models_metadata_store(void); int bt_mesh_models_metadata_read(struct net_buf_simple *buf, size_t offset); diff --git a/subsys/bluetooth/mesh/cfg_srv.c b/subsys/bluetooth/mesh/cfg_srv.c index eb732a34910..f65d2cba3c7 100644 --- a/subsys/bluetooth/mesh/cfg_srv.c +++ b/subsys/bluetooth/mesh/cfg_srv.c @@ -59,27 +59,7 @@ static int dev_comp_data_get(struct bt_mesh_model *model, LOG_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, bt_hex(buf->data, buf->len)); - page = net_buf_simple_pull_u8(buf); - - if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 130U; - } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 129U; - } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 128U; - } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { - page = 2U; - } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { - page = 1U; - } else if (page != 0U) { - LOG_DBG("Composition page %u not available", page); - page = 0U; - } + page = bt_mesh_comp_parse_page(buf); LOG_DBG("Preparing Composition data page %d", page); bt_mesh_model_msg_init(&sdu, OP_DEV_COMP_DATA_STATUS); diff --git a/subsys/bluetooth/mesh/large_comp_data_srv.c b/subsys/bluetooth/mesh/large_comp_data_srv.c index 12497d053a2..4ee591d9efd 100644 --- a/subsys/bluetooth/mesh/large_comp_data_srv.c +++ b/subsys/bluetooth/mesh/large_comp_data_srv.c @@ -53,32 +53,12 @@ static int handle_large_comp_data_get(struct bt_mesh_model *model, struct bt_mes ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, bt_hex(buf->data, buf->len)); - page = net_buf_simple_pull_u8(buf); + page = bt_mesh_comp_parse_page(buf); offset = net_buf_simple_pull_le16(buf); LOG_DBG("page %u offset %u", page, offset); bt_mesh_model_msg_init(&rsp, OP_LARGE_COMP_DATA_STATUS); - if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 130U; - } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 129U; - } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 128U; - } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { - page = 2U; - } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { - page = 1U; - } else if (page != 0U) { - LOG_DBG("Composition page %u not available", page); - page = 0U; - } - net_buf_simple_add_u8(&rsp, page); net_buf_simple_add_le16(&rsp, offset); From 598c6d18cfb77ca4aa47e8699e830a1dce1cea05 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Wed, 4 Oct 2023 14:47:39 +0200 Subject: [PATCH 0206/1623] [nrf fromtree] Bluetooth: Mesh: Don't reset mod pointer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't reset values set in init callback as it is called only once by bt_mesh_init call. The reset callback is called on every node reset. Signed-off-by: Pavel Vasilyev (cherry picked from commit f4a592f3bb9223fa09a34de3ef150076f1ce237b) Signed-off-by: Alperen Şener (cherry picked from commit d77003f09f5d73739fa01cffa32c8b8daa09dd44) --- subsys/bluetooth/mesh/rpr_srv.c | 1 - 1 file changed, 1 deletion(-) diff --git a/subsys/bluetooth/mesh/rpr_srv.c b/subsys/bluetooth/mesh/rpr_srv.c index c8639d8b514..8fb28e56472 100644 --- a/subsys/bluetooth/mesh/rpr_srv.c +++ b/subsys/bluetooth/mesh/rpr_srv.c @@ -1337,7 +1337,6 @@ static void rpr_srv_reset(struct bt_mesh_model *mod) atomic_clear(srv.flags); srv.link.dev = NULL; srv.scan.dev = NULL; - srv.mod = NULL; } const struct bt_mesh_model_cb _bt_mesh_rpr_srv_cb = { From 2da2829689578d541ec3cd43e4e35a6644d385b5 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Fri, 6 Oct 2023 20:15:08 +0200 Subject: [PATCH 0207/1623] [nrf fromtree] tests: bluetooth: tester: Fix prov ctx init in PTS tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes regression introduced in https://github.com/zephyrproject-rtos/zephyr/pull/63556 In the PR above `bt_mesh_init()` call was moved to `BTP_MESH_INIT` command to allow to select alternative composition data when starting the stack. AutoPTS sends `BTP_MESH_CONFIG_PROVISIONING` command before `BTP_MESH_INIT` to prepare the provisioning context. But because `bt_mesh_init()` is now called after `BTP_MESH_CONFIG_PROVISIONING` command is sent, this configuration is reset to the default which makes PTS tests to fail. To solve this, this commit calls introduces a new command, `BTP_MESH_START`, which will replace the original `BTP_MESH_INIT` command. `bt_mesh_init()` will stay in `BTP_MESH_INIT` while the stack will be started in `BTP_MESH_START` command. Signed-off-by: Pavel Vasilyev (cherry picked from commit 94bd09b1f8a7152bef9a4b4f628da5c5288bbefe) Signed-off-by: Alperen Şener (cherry picked from commit 83ea0749300b962a17e004961749d9b6f445edfe) --- tests/bluetooth/tester/src/btp/btp_mesh.h | 2 ++ tests/bluetooth/tester/src/btp_mesh.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index c2636d1445d..b5ab169b263 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -1038,6 +1038,8 @@ struct btp_proxy_solicit_cmd { uint16_t net_idx; } __packed; +#define BTP_MESH_START 0x78 + /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index c191ed54568..662dca238c1 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1305,6 +1305,14 @@ static uint8_t init(const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } + return BTP_STATUS_SUCCESS; +} + +static uint8_t start(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + int err; + LOG_DBG(""); if (IS_ENABLED(CONFIG_BT_SETTINGS)) { @@ -4961,6 +4969,11 @@ static const struct btp_handler handlers[] = { .func = proxy_solicit }, #endif + { + .opcode = BTP_MESH_START, + .expect_len = 0, + .func = start + }, }; From 3aa391df864261dbb6c527265634dfdb02682ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Mon, 9 Oct 2023 08:28:26 +0200 Subject: [PATCH 0208/1623] [nrf fromtree] Bluetooth: mesh: Change cfg_cli buffer length check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed buffer length check in bt_mesh_comp_p1_elem_pull. The previous threshold would result in the method not detecting the final element when it consisted of just one model. Signed-off-by: Håvard Reierstad (cherry picked from commit ea753eb52a475fc1f518d00f8f2caac07223aebc) Signed-off-by: Alperen Şener (cherry picked from commit 3f4f2ca1d20caaabccdae23df31db28be05b4a6b) --- subsys/bluetooth/mesh/cfg_cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/cfg_cli.c b/subsys/bluetooth/mesh/cfg_cli.c index 68af4fae59d..c9f4f98f39d 100644 --- a/subsys/bluetooth/mesh/cfg_cli.c +++ b/subsys/bluetooth/mesh/cfg_cli.c @@ -2320,7 +2320,7 @@ struct bt_mesh_mod_id_vnd bt_mesh_comp_p0_elem_mod_vnd(struct bt_mesh_comp_p0_el struct bt_mesh_comp_p1_elem *bt_mesh_comp_p1_elem_pull(struct net_buf_simple *buf, struct bt_mesh_comp_p1_elem *elem) { - if (buf->len < 6) { + if (buf->len < 4) { LOG_DBG("No more elements to pull or missing data"); return NULL; } From 0a1f19bfdc8b030f67b8b2ac0c499dc06d2d64d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Mon, 9 Oct 2023 08:28:26 +0200 Subject: [PATCH 0209/1623] [nrf fromtree] Bluetooth: mesh: access: Fix model relation register MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added offset to the model relation register for vendor models to find correct model index for Composition Data Page 1. The previous implementation used the 'mod_idx' from the 'bt_mesh_model' struct, which led to issues in the model relation register due to SIG and vender models having the same model index. Modified existing functions related to the model relation register to take in the offset. Modified macros for determining if a model is a base- or extending model. Added check in 'add_items_to_page' to check whether the model relation is an extension. Signed-off-by: Håvard Reierstad (cherry picked from commit 3d40d91f8682d023e939af4ef2cfe6509d17a3f6) Signed-off-by: Alperen Şener (cherry picked from commit 8db15583254176f6b7096744631441e8c8389827) --- subsys/bluetooth/mesh/access.c | 92 +++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 2ea7ece90df..63c4f76c392 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -91,17 +91,13 @@ static struct mod_relation mod_rel_list[MOD_REL_LIST_SIZE]; mod_rel_list[(idx)].idx_ext == 0); \ (idx)++) -#define IS_MOD_BASE(mod, idx) \ +#define IS_MOD_BASE(mod, idx, offset) \ (mod_rel_list[(idx)].elem_base == (mod)->elem_idx && \ - mod_rel_list[(idx)].idx_base == (mod)->mod_idx && \ - !(mod_rel_list[(idx)].elem_ext != (mod)->elem_idx && \ - mod_rel_list[(idx)].idx_ext != (mod)->mod_idx)) + mod_rel_list[(idx)].idx_base == (mod)->mod_idx + (offset)) -#define IS_MOD_EXTENSION(mod, idx) \ +#define IS_MOD_EXTENSION(mod, idx, offset) \ (mod_rel_list[(idx)].elem_ext == (mod)->elem_idx && \ - mod_rel_list[(idx)].idx_ext == (mod)->mod_idx && \ - !(mod_rel_list[(idx)].elem_base != (mod)->elem_idx && \ - mod_rel_list[(idx)].idx_base != (mod)->mod_idx)) + mod_rel_list[(idx)].idx_ext == (mod)->mod_idx + (offset)) #define RELATION_TYPE_EXT 0xFF @@ -456,14 +452,14 @@ int bt_mesh_comp_data_get_page_0(struct net_buf_simple *buf, size_t offset) return 0; } -static uint8_t count_mod_ext(struct bt_mesh_model *mod, uint8_t *max_offset) +static uint8_t count_mod_ext(struct bt_mesh_model *mod, uint8_t *max_offset, uint8_t sig_offset) { int i; uint8_t extensions = 0; int8_t offset, offset_record = 0; MOD_REL_LIST_FOR_EACH(i) { - if (IS_MOD_EXTENSION(mod, i) && + if (IS_MOD_EXTENSION(mod, i, sig_offset) && mod_rel_list[i].type == RELATION_TYPE_EXT) { extensions++; offset = mod_rel_list[i].elem_ext - @@ -480,17 +476,18 @@ static uint8_t count_mod_ext(struct bt_mesh_model *mod, uint8_t *max_offset) return extensions; } -static bool is_cor_present(struct bt_mesh_model *mod, uint8_t *cor_id) +static bool is_cor_present(struct bt_mesh_model *mod, uint8_t *cor_id, uint8_t sig_offset) { int i; - MOD_REL_LIST_FOR_EACH(i) { - if ((IS_MOD_BASE(mod, i) || IS_MOD_EXTENSION(mod, i)) && + MOD_REL_LIST_FOR_EACH(i) + { + if ((IS_MOD_BASE(mod, i, sig_offset) || + IS_MOD_EXTENSION(mod, i, sig_offset)) && mod_rel_list[i].type < RELATION_TYPE_EXT) { if (cor_id) { memcpy(cor_id, &mod_rel_list[i].type, sizeof(uint8_t)); } - return true; } } @@ -498,15 +495,15 @@ static bool is_cor_present(struct bt_mesh_model *mod, uint8_t *cor_id) } static void prep_model_item_header(struct bt_mesh_model *mod, uint8_t *cor_id, uint8_t *mod_cnt, - struct net_buf_simple *buf, size_t *offset) + struct net_buf_simple *buf, size_t *offset, uint8_t sig_offset) { uint8_t ext_mod_cnt; bool cor_present; uint8_t mod_elem_info = 0; int8_t max_offset; - ext_mod_cnt = count_mod_ext(mod, &max_offset); - cor_present = is_cor_present(mod, cor_id); + ext_mod_cnt = count_mod_ext(mod, &max_offset, sig_offset); + cor_present = is_cor_present(mod, cor_id, sig_offset); mod_elem_info = ext_mod_cnt << 2; if (ext_mod_cnt > 31 || @@ -526,13 +523,14 @@ static void prep_model_item_header(struct bt_mesh_model *mod, uint8_t *cor_id, u } static void add_items_to_page(struct net_buf_simple *buf, struct bt_mesh_model *mod, - uint8_t ext_mod_cnt, size_t *offset) + uint8_t ext_mod_cnt, size_t *offset, uint8_t sig_offset) { int i, elem_offset; uint8_t mod_idx; MOD_REL_LIST_FOR_EACH(i) { - if (IS_MOD_EXTENSION(mod, i)) { + if (IS_MOD_EXTENSION(mod, i, sig_offset) && + mod_rel_list[i].type == RELATION_TYPE_EXT) { elem_offset = mod->elem_idx - mod_rel_list[i].elem_base; mod_idx = mod_rel_list[i].idx_base; if (ext_mod_cnt < 32 && @@ -557,18 +555,18 @@ static void add_items_to_page(struct net_buf_simple *buf, struct bt_mesh_model * } } -static size_t mod_items_size(struct bt_mesh_model *mod) +static size_t mod_items_size(struct bt_mesh_model *mod, uint8_t sig_offset) { int i, offset; size_t temp_size = 0; - int ext_mod_cnt = count_mod_ext(mod, NULL); + int ext_mod_cnt = count_mod_ext(mod, NULL, sig_offset); if (!ext_mod_cnt) { return 0; } MOD_REL_LIST_FOR_EACH(i) { - if (IS_MOD_EXTENSION(mod, i)) { + if (IS_MOD_EXTENSION(mod, i, sig_offset)) { offset = mod->elem_idx - mod_rel_list[i].elem_base; temp_size += (ext_mod_cnt < 32 && offset < 4 && offset > -5) ? 1 : 2; } @@ -582,13 +580,13 @@ static size_t page1_elem_size(struct bt_mesh_elem *elem) size_t temp_size = 2; for (int i = 0; i < elem->model_count; i++) { - temp_size += is_cor_present(&elem->models[i], NULL) ? 2 : 1; - temp_size += mod_items_size(&elem->models[i]); + temp_size += is_cor_present(&elem->models[i], NULL, 0) ? 2 : 1; + temp_size += mod_items_size(&elem->models[i], 0); } for (int i = 0; i < elem->vnd_model_count; i++) { - temp_size += is_cor_present(&elem->vnd_models[i], NULL) ? 2 : 1; - temp_size += mod_items_size(&elem->vnd_models[i]); + temp_size += is_cor_present(&elem->vnd_models[i], NULL, elem->model_count) ? 2 : 1; + temp_size += mod_items_size(&elem->vnd_models[i], elem->model_count); } return temp_size; @@ -630,19 +628,22 @@ static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf, size_t offse data_buf_add_u8_offset(buf, comp->elem[i].vnd_model_count, &offset); for (j = 0; j < comp->elem[i].model_count; j++) { prep_model_item_header(&comp->elem[i].models[j], &cor_id, &ext_mod_cnt, buf, - &offset); + &offset, 0); if (ext_mod_cnt != 0) { add_items_to_page(buf, &comp->elem[i].models[j], ext_mod_cnt, - &offset); + &offset, + 0); } } for (j = 0; j < comp->elem[i].vnd_model_count; j++) { prep_model_item_header(&comp->elem[i].vnd_models[j], &cor_id, &ext_mod_cnt, - buf, &offset); + buf, &offset, + comp->elem[i].model_count); if (ext_mod_cnt != 0) { add_items_to_page(buf, &comp->elem[i].vnd_models[j], ext_mod_cnt, - &offset); + &offset, + comp->elem[i].model_count); } } } @@ -1616,6 +1617,22 @@ void bt_mesh_model_extensions_walk(struct bt_mesh_model *model, } #ifdef CONFIG_BT_MESH_MODEL_EXTENSIONS +/* For vendor models, determine the offset within the model relation list + * by counting the number of standard SIG models in the associated element. + */ +static uint8_t get_sig_offset(struct bt_mesh_model *mod) +{ + const struct bt_mesh_elem *elem = bt_mesh_model_elem(mod); + uint8_t i; + + for (i = 0U; i < elem->vnd_model_count; i++) { + if (&elem->vnd_models[i] == mod) { + return elem->model_count; + } + } + return 0; +} + static int mod_rel_register(struct bt_mesh_model *base, struct bt_mesh_model *ext, uint8_t type) @@ -1623,9 +1640,9 @@ static int mod_rel_register(struct bt_mesh_model *base, LOG_DBG(""); struct mod_relation extension = { base->elem_idx, - base->mod_idx, + base->mod_idx + get_sig_offset(base), ext->elem_idx, - ext->mod_idx, + ext->mod_idx + get_sig_offset(ext), type, }; int i; @@ -1696,16 +1713,19 @@ int bt_mesh_model_correspond(struct bt_mesh_model *corresponding_mod, return -ENOTSUP; } + uint8_t base_offset = get_sig_offset(base_mod); + uint8_t corresponding_offset = get_sig_offset(corresponding_mod); + MOD_REL_LIST_FOR_EACH(i) { if (mod_rel_list[i].type < RELATION_TYPE_EXT && mod_rel_list[i].type > cor_id) { cor_id = mod_rel_list[i].type; } - if ((IS_MOD_BASE(base_mod, i) || - IS_MOD_EXTENSION(base_mod, i) || - IS_MOD_BASE(corresponding_mod, i) || - IS_MOD_EXTENSION(corresponding_mod, i)) && + if ((IS_MOD_BASE(base_mod, i, base_offset) || + IS_MOD_EXTENSION(base_mod, i, base_offset) || + IS_MOD_BASE(corresponding_mod, i, corresponding_offset) || + IS_MOD_EXTENSION(corresponding_mod, i, corresponding_offset)) && mod_rel_list[i].type < RELATION_TYPE_EXT) { return mod_rel_register(base_mod, corresponding_mod, mod_rel_list[i].type); } From 7baae6c87ada53b681730c226d58a37a8ed6c382 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Mon, 9 Oct 2023 09:47:17 +0200 Subject: [PATCH 0210/1623] [nrf fromtree] Bluetooth: Mesh: Reset targets state before starting DFU on DFD srv MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The list of receives in the Firmware Distribution Server model and and the Firmware Update Client model are 2 different lists. In the Firmware Update Client model it is called the Update Receives state and the Active Update Receivers state which is a subset of receivers from the Update Receivers State. In the Firmware Distribution Server model it is called the Distribution Receivers List state. When Distribute Firmware procedure starts, in the Initiate step, the Receivers List input (which is the input for the Update Receivers state), is composed of the Distribution Receives List state. During DFU, the Update Receivers state becomes the Active Update Receivers state which keeps only active nodes. Timed out or failed nodes dropped out from this list. The Distribution Receivers List state stays unchanged and thus don't need to be populated again after every successfull and failed DFU. Signed-off-by: Pavel Vasilyev (cherry picked from commit 68365d5b67057c8e960a5168c2cf99f4b8c457c1) Signed-off-by: Alperen Şener (cherry picked from commit d6191e479e6e63a7768c0e4ac003fe834d5eacda) --- subsys/bluetooth/mesh/dfd_srv.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 59fe5b830d1..5d3ada4b4aa 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -1015,6 +1015,13 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_start(struct bt_mesh_dfd_srv *srv, sys_slist_init(&srv->inputs.targets); for (i = 0; i < srv->target_cnt; i++) { + uint16_t addr = srv->targets[i].blob.addr; + + memset(&srv->targets[i].blob, 0, sizeof(struct bt_mesh_blob_target)); + memset(&srv->pull_ctxs[i], 0, sizeof(struct bt_mesh_blob_target_pull)); + srv->targets[i].blob.addr = addr; + srv->targets[i].blob.pull = &srv->pull_ctxs[i]; + sys_slist_append(&srv->inputs.targets, &srv->targets[i].blob.n); } From 78ec3b1294a711606b8302f3f95eef0a7095cb51 Mon Sep 17 00:00:00 2001 From: Morten Priess Date: Thu, 29 Jun 2023 09:16:26 +0200 Subject: [PATCH 0211/1623] [nrf fromtree] Bluetooth: controller: Introduce config for avoiding SDU fragmentation The CIS Central uses the algorithm described in BT Core 5.4 Vol 6, Part G, Section 2.2 to calculate the Max_PDU value for framed mode. However, HAP needs the Max_PDU to be calculated according to "Core enhancement for ISOAL CR" coming with the "Atlanta" update. With this update, the fragmentation is controlled via a parameter at CIG creation. Enabling CONFIG_BT_CTLR_CONN_ISO_AVOID_SEGMENTATION will set the ISO_Interval to 7.5 ms for a 10 ms framed CIG, and calculate Max_PDU to 45/65 for 16/24 kHz. Signed-off-by: Morten Priess (cherry picked from commit 79ab982f468096f6c06776a93fe154ca35d33f8f) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 8687b84bd8ba5779b5f3145af994fdefa870a3be) --- subsys/bluetooth/controller/Kconfig | 11 ++++ .../controller/ll_sw/ull_central_iso.c | 59 ++++++++++++++----- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 59ec86d5efe..51890bf51ed 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -903,6 +903,17 @@ config BT_CTLR_CONN_ISO_STREAMS_MAX_FT help Maximum number of CIS flush timeout events. +config BT_CTLR_CONN_ISO_AVOID_SEGMENTATION + bool "Avoid SDU fragmentation for framed mode" + depends on BT_CTLR_CENTRAL_ISO + help + When creating a CIG, the Max_PDU size is calculated according to BT + Core 5.4 Vol 6, Part G, Section 2.2. However, HAP specifies a need for + avoiding segmentation by forcing the Max_PDU to the appropriate value. + Since there is no way to control the Max_PDU using the non-test + interface, the config provides a way to force the Max_PDU to Max_SDU + + 5 (header + offset). + config BT_CTLR_ISO bool default BT_CTLR_BROADCAST_ISO || BT_CTLR_CONN_ISO diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 0c7a8e5ef35..49ab4909e3e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -234,6 +234,15 @@ uint8_t ll_cig_parameters_commit(uint8_t cig_id, uint16_t *handles) cig->iso_interval = BT_HCI_ISO_INTERVAL_MIN; } +#if defined(CONFIG_BT_CTLR_CONN_ISO_AVOID_SEGMENTATION) + /* Check if this is a HAP usecase which requires higher link bandwidth to ensure + * segmentation is not invoked in ISO-AL. + */ + if (cig->central.framing && cig->c_sdu_interval == 10000U) { + cig->iso_interval = 6; /* 7500 us */ + } +#endif + if (!cig->central.framing && (cig->c_sdu_interval % ISO_INT_UNIT_US)) { /* Framing not requested but requirement for unframed is not met. Force * CIG into framed mode. @@ -1131,29 +1140,51 @@ static void set_bn_max_pdu(bool framed, uint32_t iso_interval, uint8_t *max_pdu) { if (framed) { - uint32_t ceil_f_x_max_sdu; - uint16_t max_pdu_bn1; - uint32_t max_drift; + uint32_t max_drift_us; uint32_t ceil_f; - /* Framed (From ES-18002): + /* BT Core 5.4 Vol 6, Part G, Section 2.2: * Max_PDU >= ((ceil(F) x 5 + ceil(F x Max_SDU)) / BN) + 2 * F = (1 + MaxDrift) x ISO_Interval / SDU_Interval * SegmentationHeader + TimeOffset = 5 bytes * Continuation header = 2 bytes * MaxDrift (Max. allowed SDU delivery timing drift) = 100 ppm */ - max_drift = DIV_ROUND_UP(SDU_MAX_DRIFT_PPM * sdu_interval, 1000000U); - ceil_f = DIV_ROUND_UP(iso_interval + max_drift, sdu_interval); - ceil_f_x_max_sdu = DIV_ROUND_UP(max_sdu * (iso_interval + max_drift), - sdu_interval); - - /* Strategy: Keep lowest possible BN. - * TODO: Implement other strategies, possibly as policies. + max_drift_us = DIV_ROUND_UP(SDU_MAX_DRIFT_PPM * sdu_interval, USEC_PER_SEC); + ceil_f = DIV_ROUND_UP((USEC_PER_SEC + max_drift_us) * (uint64_t)iso_interval, + USEC_PER_SEC * (uint64_t)sdu_interval); + if (false) { +#if defined(CONFIG_BT_CTLR_CONN_ISO_AVOID_SEGMENTATION) + /* To avoid segmentation according to HAP, if the ISO_Interval is less than + * the SDU_Interval, we assume BN=1 and calculate the Max_PDU as: + * Max_PDU = celi(F / BN) x (5 / Max_SDU) + * + * This is in accordance with the "Core enhancement for ISOAL CR". + * + * This ensures that the drift can be contained in the difference between + * SDU_Interval and link bandwidth. For BN=1, ceil(F) == ceil(F/BN). */ - max_pdu_bn1 = ceil_f * 5 + ceil_f_x_max_sdu; - *bn = DIV_ROUND_UP(max_pdu_bn1, LL_CIS_OCTETS_TX_MAX); - *max_pdu = DIV_ROUND_UP(max_pdu_bn1, *bn) + 2; + } else if (iso_interval < sdu_interval) { + *bn = 1; + *max_pdu = ceil_f * (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE + + max_sdu); +#endif + } else { + uint32_t ceil_f_x_max_sdu; + uint16_t max_pdu_bn1; + + ceil_f_x_max_sdu = DIV_ROUND_UP(max_sdu * ((USEC_PER_SEC + max_drift_us) * + (uint64_t)iso_interval), + USEC_PER_SEC * (uint64_t)sdu_interval); + + /* Strategy: Keep lowest possible BN. + * TODO: Implement other strategies, possibly as policies. + */ + max_pdu_bn1 = ceil_f * (PDU_ISO_SEG_HDR_SIZE + + PDU_ISO_SEG_TIMEOFFSET_SIZE) + ceil_f_x_max_sdu; + *bn = DIV_ROUND_UP(max_pdu_bn1, LL_CIS_OCTETS_TX_MAX); + *max_pdu = DIV_ROUND_UP(max_pdu_bn1, *bn) + PDU_ISO_SEG_HDR_SIZE; + } } else { /* For unframed, ISO_Interval must be N x SDU_Interval */ LL_ASSERT(iso_interval % sdu_interval == 0); From c5545cd918742435c48186f39e70fe806a037c0d Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 7 Sep 2023 11:01:46 +0200 Subject: [PATCH 0212/1623] [nrf fromtree] Bluetooth: Controller: Nordic LLL: Use HAL to clear RTC event Use the HAL event clear function to clear the RTC EVENT instead of accessing the register directly. This allows using an updated version of the RTC HW models which generate level interrupts (as the real HW) and in which if the EVEN register is not properly cleared, the interrupts are kept high, resulting in the interrupt handler reentering immediately after exiting. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 7082222ac6606c537c18639ede88286b4a3e575a) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit cbd608b0bf35569de217332e6bcb562d3d3e42ae) --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index bc71bbcd5a6..1f8031a7c07 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -8,6 +8,8 @@ #include #include +#include + #include #include @@ -106,7 +108,7 @@ static void rtc0_nrf5_isr(const void *arg) /* On compare0 run ticker worker instance0 */ if (NRF_RTC0->EVENTS_COMPARE[0]) { - NRF_RTC0->EVENTS_COMPARE[0] = 0; + nrf_rtc_event_clear(NRF_RTC0, NRF_RTC_EVENT_COMPARE_0); ticker_trigger(0); } From e0313b730459f788f15f9e8745f90404ccad1f28 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 7 Sep 2023 11:04:33 +0200 Subject: [PATCH 0213/1623] [nrf fromtree] Bluetooth: Controller: Nordic LLL: Use HAL to clear EVENTs Use the HAL event clear functions to clear EVENTS instead of accessing the registers directly. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit bb811a1e1d7c7662bbfb9278c8994b32dc61b55b) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 99ed0b6d46ca7b8eeffa7f6aef65e979f373546d) --- .../ll_sw/nordic/hal/nrf5/radio/radio.c | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 7b72b1a4b93..1875dca7896 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -568,18 +568,18 @@ void radio_status_reset(void) * register value, PPI task will be triggered. Hence, other * EVENT_* registers are not reset to save code and CPU time. */ - NRF_RADIO->EVENTS_READY = 0; - NRF_RADIO->EVENTS_END = 0; + nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_READY); + nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_END); #if defined(CONFIG_BT_CTLR_DF_SUPPORT) && !defined(CONFIG_ZTEST) /* Clear it only for SoCs supporting DF extension */ - NRF_RADIO->EVENTS_PHYEND = 0; - NRF_RADIO->EVENTS_CTEPRESENT = 0; - NRF_RADIO->EVENTS_BCMATCH = 0; + nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_PHYEND); + nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_CTEPRESENT); + nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_BCMATCH); #endif /* CONFIG_BT_CTLR_DF_SUPPORT && !CONFIG_ZTEST */ - NRF_RADIO->EVENTS_DISABLED = 0; + nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_DISABLED); #if defined(CONFIG_BT_CTLR_PHY_CODED) #if defined(CONFIG_HAS_HW_NRF_RADIO_BLE_CODED) - NRF_RADIO->EVENTS_RATEBOOST = 0; + nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_RATEBOOST); #endif /* CONFIG_HAS_HW_NRF_RADIO_BLE_CODED */ #endif /* CONFIG_BT_CTLR_PHY_CODED */ } @@ -1019,7 +1019,7 @@ uint32_t radio_rssi_get(void) void radio_rssi_status_reset(void) { - NRF_RADIO->EVENTS_RSSIEND = 0; + nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_RSSIEND); } uint32_t radio_rssi_is_ready(void) @@ -1051,7 +1051,7 @@ void radio_filter_disable(void) void radio_filter_status_reset(void) { - NRF_RADIO->EVENTS_DEVMATCH = 0; + nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_DEVMATCH); } uint32_t radio_filter_has_match(void) @@ -1072,7 +1072,7 @@ void radio_bc_configure(uint32_t n) void radio_bc_status_reset(void) { - NRF_RADIO->EVENTS_BCMATCH = 0; + nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_BCMATCH); } uint32_t radio_bc_has_match(void) @@ -1356,7 +1356,7 @@ uint32_t radio_tmr_start_us(uint8_t trx, uint32_t start_us) start_us = (now_us << 1) - start_us; /* Setup compare event with min. 1 us offset */ - EVENT_TIMER->EVENTS_COMPARE[0] = 0U; + nrf_timer_event_clear(EVENT_TIMER, NRF_TIMER_EVENT_COMPARE0); nrf_timer_cc_set(EVENT_TIMER, 0, start_us + 1U); /* Capture the current time */ @@ -1749,9 +1749,9 @@ static void *radio_ccm_ext_rx_pkt_set(struct ccm *cnf, uint8_t phy, uint8_t pdu_ NRF_CCM->OUTPTR = (uint32_t)pkt; NRF_CCM->SCRATCHPTR = (uint32_t)_ccm_scratch; NRF_CCM->SHORTS = 0; - NRF_CCM->EVENTS_ENDKSGEN = 0; - NRF_CCM->EVENTS_ENDCRYPT = 0; - NRF_CCM->EVENTS_ERROR = 0; + nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ENDKSGEN); + nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ENDCRYPT); + nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ERROR); nrf_ccm_task_trigger(NRF_CCM, NRF_CCM_TASK_KSGEN); @@ -1820,9 +1820,9 @@ static void *radio_ccm_ext_tx_pkt_set(struct ccm *cnf, uint8_t pdu_type, void *p NRF_CCM->OUTPTR = (uint32_t)_pkt_scratch; NRF_CCM->SCRATCHPTR = (uint32_t)_ccm_scratch; NRF_CCM->SHORTS = CCM_SHORTS_ENDKSGEN_CRYPT_Msk; - NRF_CCM->EVENTS_ENDKSGEN = 0; - NRF_CCM->EVENTS_ENDCRYPT = 0; - NRF_CCM->EVENTS_ERROR = 0; + nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ENDKSGEN); + nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ENDCRYPT); + nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ERROR); nrf_ccm_task_trigger(NRF_CCM, NRF_CCM_TASK_KSGEN); @@ -1899,9 +1899,9 @@ void radio_ar_configure(uint32_t nirk, void *irk, uint8_t flags) NRF_AAR->ADDRPTR = addrptr; NRF_AAR->SCRATCHPTR = (uint32_t)&_aar_scratch[0]; - NRF_AAR->EVENTS_END = 0; - NRF_AAR->EVENTS_RESOLVED = 0; - NRF_AAR->EVENTS_NOTRESOLVED = 0; + nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_END); + nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_RESOLVED); + nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_NOTRESOLVED); radio_bc_configure(bcc); radio_bc_status_reset(); @@ -1957,9 +1957,9 @@ uint8_t radio_ar_resolve(const uint8_t *addr) NRF_AAR->ADDRPTR = (uint32_t)addr - 3; - NRF_AAR->EVENTS_END = 0; - NRF_AAR->EVENTS_RESOLVED = 0; - NRF_AAR->EVENTS_NOTRESOLVED = 0; + nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_END); + nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_RESOLVED); + nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_NOTRESOLVED); NVIC_ClearPendingIRQ(nrfx_get_irq_number(NRF_AAR)); From f98dcccd9c67ed0c9c8e8d03e6b5fa795489ebce Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 13 Sep 2023 12:37:29 +0530 Subject: [PATCH 0214/1623] [nrf fromtree] Bluetooth: Controller: Fix some compiler instruction re-ordering Fix some compiler instruction re-ordering. Mayfly code with cpu_dmb() help avoid stalled memq_ull_rx processing when rx_demux is to be executed using mayfly. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit f2069530ee9d73d2c5c3a65bd3b146b0631593fb) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit eed5fba328b838861c9947d8608ef3ff02b1a25c) --- subsys/bluetooth/controller/ticker/ticker.c | 1 + subsys/bluetooth/controller/util/mayfly.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index 679467d148c..ead148e85ba 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -3149,6 +3149,7 @@ void ticker_job(void *param) instance->job_guard = 0U; /* trigger worker if deferred */ + cpu_dmb(); if (instance->worker_trigger || compare_trigger) { instance->sched_cb(TICKER_CALL_ID_JOB, TICKER_CALL_ID_WORKER, 1, instance); diff --git a/subsys/bluetooth/controller/util/mayfly.c b/subsys/bluetooth/controller/util/mayfly.c index e8de3acfd80..d45569c6a35 100644 --- a/subsys/bluetooth/controller/util/mayfly.c +++ b/subsys/bluetooth/controller/util/mayfly.c @@ -6,8 +6,13 @@ */ #include + +#include #include #include + +#include "hal/cpu.h" + #include "memq.h" #include "mayfly.h" @@ -154,10 +159,12 @@ static void dequeue(uint8_t callee_id, uint8_t caller_id, memq_link_t *link, m->_link = link; /* reset mayfly state to idle */ + cpu_dmb(); ack = m->_ack; m->_ack = req; /* re-insert, if re-pended by interrupt */ + cpu_dmb(); if (((m->_req - ack) & 0x03) == 1U) { #if defined(MAYFLY_UT) printk("%s: RACE\n", __func__); From f3560c3ff5a62f3c8a90ad03cb623c2dea3c9d04 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 16 Jun 2023 18:36:10 +0530 Subject: [PATCH 0215/1623] [nrf fromtree] Bluetooth: Controller: Minor clean up of redundant initialization Minor clean up of redundant initialization. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit afd48e03d064568a536e89038d1a31a50cd76349) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit a11b48a35028caeda7a62f6c0713604e979ca7a5) --- subsys/bluetooth/controller/ll_sw/ull_central_iso.c | 10 +--------- subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c | 4 ---- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 49ab4909e3e..71b8d742a76 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -690,15 +690,6 @@ void ll_cis_create(uint16_t cis_handle, uint16_t acl_handle) /* Initialize stream states */ cis->established = 0; cis->teardown = 0; - cis->lll.event_count = LLL_CONN_ISO_EVENT_COUNT_MAX; - cis->lll.sn = 0; - cis->lll.nesn = 0; - cis->lll.cie = 0; - cis->lll.flush = LLL_CIS_FLUSH_NONE; - cis->lll.active = 0; - cis->lll.datapath_ready_rx = 0; - cis->lll.tx.bn_curr = 1U; - cis->lll.rx.bn_curr = 1U; (void)memset(&cis->hdr, 0U, sizeof(cis->hdr)); @@ -875,6 +866,7 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, #endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ cis->central.instant = instant; + cis->lll.event_count = LLL_CONN_ISO_EVENT_COUNT_MAX; cis->lll.next_subevent = 0U; cis->lll.sn = 0U; cis->lll.nesn = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index 5bbac2528d0..d45d89aa009 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -259,15 +259,11 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl, cis->lll.rx.bn = req->c_bn; cis->lll.rx.ft = req->c_ft; cis->lll.rx.max_pdu = sys_le16_to_cpu(req->c_max_pdu); - cis->lll.rx.payload_count = 0; - cis->lll.rx.bn_curr = 1U; cis->lll.tx.phy = req->p_phy; cis->lll.tx.bn = req->p_bn; cis->lll.tx.ft = req->p_ft; cis->lll.tx.max_pdu = sys_le16_to_cpu(req->p_max_pdu); - cis->lll.tx.payload_count = 0; - cis->lll.tx.bn_curr = 1U; if (!cis->lll.link_tx_free) { cis->lll.link_tx_free = &cis->lll.link_tx; From f6496260fc1dc3e873cb55cce34ab1814df1a004 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 14 Sep 2023 15:33:26 +0530 Subject: [PATCH 0216/1623] [nrf fromtree] Bluetooth: Controller: Fix initialization of lazy_active Fix initialization of CIS lazy_active event count used when first CIS event is active. Now initialization for first and any subsequent CISes made active. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 1291e4b6868d81518167a99dd48108ed48e1abd4) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 4dd81a515bbe870224092d5abd7875a01165fb5b) --- subsys/bluetooth/controller/ll_sw/ull_conn_iso.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index 8b79100d942..cc76c5219cb 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -851,6 +851,10 @@ void ull_conn_iso_start(struct ll_conn *conn, uint16_t cis_handle, */ if (cig->state == CIG_STATE_ACTIVE) { #if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) + /* Initialize CIS event lazy at CIS create */ + cis->lll.lazy_active = 0U; + + /* Deferred fill CIS event lazy value at CIS create */ cis_lazy_fill(cis); #else /* CONFIG_BT_CTLR_JIT_SCHEDULING */ /* Set CIS active in already active CIG */ @@ -996,6 +1000,9 @@ void ull_conn_iso_start(struct ll_conn *conn, uint16_t cis_handle, } ticks_slot = cig->ull.ticks_slot + ticks_slot_overhead; + + /* Initialize CIS event lazy at CIS create */ + cis->lll.lazy_active = 0U; #endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ /* Start CIS peripheral CIG ticker */ @@ -1014,11 +1021,6 @@ void ull_conn_iso_start(struct ll_conn *conn, uint16_t cis_handle, /* Set CIG and the first CIS state as active */ cig->state = CIG_STATE_ACTIVE; cis->lll.active = 1U; - -#if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) - /* CIS event lazy at CIS create */ - cis->lll.lazy_active = 0U; -#endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ } #if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) From 1cd5c0c6039be61db9eb5e5f0c95586854fdec52 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 14 Sep 2023 15:35:53 +0530 Subject: [PATCH 0217/1623] [nrf fromtree] Bluetooth: Controller: Fix missing lazy calculation for Central ISO Fix missing lazy calculation when using ticker interface required for Central CIS create. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit d42d14e392e70a846abe5baaceb849ef21a50584) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit a5bd81633ca8f20ea30729463920f1b5c8cfa896) --- subsys/bluetooth/controller/Kconfig.ll_sw_split | 2 +- subsys/bluetooth/controller/ll_sw/ull_conn_iso.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 84db5fddb10..910c3819f0c 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -53,7 +53,7 @@ config BT_LLL_VENDOR_NORDIC (BT_OBSERVER && BT_CTLR_ADV_EXT) select BT_TICKER_REMAINDER if BT_CTLR_CENTRAL_ISO select BT_TICKER_REMAINDER_GET if BT_BROADCASTER && BT_CTLR_ADV_EXT - select BT_TICKER_LAZY_GET if BT_CTLR_ADV_PERIODIC + select BT_TICKER_LAZY_GET if BT_CTLR_ADV_PERIODIC || BT_CTLR_CENTRAL_ISO default y help diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index cc76c5219cb..2ee5905b23b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -1042,8 +1042,8 @@ static void mfy_cis_lazy_fill(void *param) uint32_t ticks_to_expire; uint32_t ticks_current; uint32_t remainder; + uint16_t lazy = 0U; uint8_t ticker_id; - uint16_t lazy; uint8_t retry; uint8_t id; From 4259135d4de0b463e3b9e10ab03982d92321e8ca Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 13 Sep 2023 16:11:40 +0200 Subject: [PATCH 0218/1623] [nrf fromtree] bluetooth: controller: coex: convert to DT device Convert the driver to a dt-based device. Also update Kconfig so that it depends on the right compatible being enabled, initialize in POST_KERNEL (APPLICATION should not be used for devices) and remove one redundant include. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 4f80e50b55d325999f6749354a6c8519b1d54096) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit a226209c81b1a579a5490fe2710a9e27230b5db0) --- samples/bluetooth/beacon/prj-coex.conf | 1 - subsys/bluetooth/controller/coex/Kconfig | 4 ++-- subsys/bluetooth/controller/coex/coex_ticker.c | 18 ++++++------------ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/samples/bluetooth/beacon/prj-coex.conf b/samples/bluetooth/beacon/prj-coex.conf index b16487f3999..eb9cd4bb16e 100644 --- a/samples/bluetooth/beacon/prj-coex.conf +++ b/samples/bluetooth/beacon/prj-coex.conf @@ -3,5 +3,4 @@ CONFIG_LOG=y CONFIG_BT_DEVICE_NAME="Test beacon" CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_CTLR_COEX_DRIVERS=y CONFIG_BT_CTLR_COEX_TICKER=y diff --git a/subsys/bluetooth/controller/coex/Kconfig b/subsys/bluetooth/controller/coex/Kconfig index 31754fbf52c..b7bc7d30681 100644 --- a/subsys/bluetooth/controller/coex/Kconfig +++ b/subsys/bluetooth/controller/coex/Kconfig @@ -5,8 +5,8 @@ menuconfig BT_CTLR_COEX_DRIVERS bool "Bluetooth Co-existence Drivers" - default n - depends on BT_CTLR + default y + depends on BT_CTLR && DT_HAS_GPIO_RADIO_COEX_ENABLED if BT_CTLR_COEX_DRIVERS diff --git a/subsys/bluetooth/controller/coex/coex_ticker.c b/subsys/bluetooth/controller/coex/coex_ticker.c index 229e2f9e125..be349622ecd 100644 --- a/subsys/bluetooth/controller/coex/coex_ticker.c +++ b/subsys/bluetooth/controller/coex/coex_ticker.c @@ -4,12 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ +#define DT_DRV_COMPAT gpio_radio_coex + #include #include #include #include -#include #include #include #include @@ -195,18 +196,11 @@ static int coex_ticker_init(const struct device *dev) return 0; } -#define RADIO_NODE DT_NODELABEL(radio) -#define COEX_NODE DT_PROP(RADIO_NODE, coex) - -#if DT_NODE_EXISTS(COEX_NODE) static struct coex_ticker_config config = { - .grant_spec = GPIO_DT_SPEC_GET(COEX_NODE, grant_gpios), - .grant_delay_us = DT_PROP(COEX_NODE, grant_delay_us) + .grant_spec = GPIO_DT_SPEC_INST_GET(0, grant_gpios), + .grant_delay_us = DT_INST_PROP(0, grant_delay_us) }; static struct coex_ticker_data data; -DEVICE_DEFINE(coex_ticker, "COEX_TICKER", &coex_ticker_init, NULL, - &data, &config, - APPLICATION, 90, - NULL); -#endif +DEVICE_DT_INST_DEFINE(0, &coex_ticker_init, NULL, &data, &config, + POST_KERNEL, 90, NULL); From 1845278ad53c15a557ca81895e9e5c89721d573b Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 30 Jun 2023 07:07:38 +0530 Subject: [PATCH 0219/1623] [nrf fromtree] Bluetooth: Controller: Revert EVENT_OVERHEAD_END_US to original value Revert back the EVENT_OVERHEAD_END_US value to original value in initial commit 5c3709c13fd8 ("bluetooth: controller: Add def's re. update to slot reservation calc"). 40 us is a sufficient margin considering ~30 us being the worst case Rx chain delay for S8 Coded PHY on nRF5x SoCs. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit c986104485914a0adbcfb5cf96dcb152e82fa87d) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 6e412944b0ef8b6925efa31ea4a36edc8d1dd620) --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h index 5ee063e4d53..7df39f65c8a 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h @@ -42,7 +42,7 @@ /* Worst-case time margin needed after event end-time in the air * (done/preempt race margin + power-down/chain delay) */ -#define EVENT_OVERHEAD_END_US 100 +#define EVENT_OVERHEAD_END_US 40 /* Sleep Clock Accuracy */ #define EVENT_JITTER_US 16 From 1734da8febc892c0ad4231495b3425acd192668f Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 30 Jun 2023 08:18:53 +0530 Subject: [PATCH 0220/1623] [nrf fromtree] Bluetooth: Controller: Make openisa and test hal ticker.h consistent Make openisa and unit test hal ticker.h consistent with nrf hal ticker.h. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 01314b2e434e5759327bcf78c38089e6750c54c4) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit ce4fd380c13264ae16bc3c3805a50ffe19196d0c) --- .../controller/ll_sw/nordic/hal/nrf5/ticker.h | 3 +- .../ll_sw/openisa/hal/RV32M1/ticker.h | 36 ++++++++++---- .../mock_ctrl/include/hal/ticker_vendor_hal.h | 49 +++++++++++++------ 3 files changed, 62 insertions(+), 26 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h index 5845d15145a..315601ce203 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h @@ -26,7 +26,8 @@ #define HAL_TICKER_US_TO_TICKS(x) \ ( \ ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & HAL_TICKER_CNTR_MASK \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + HAL_TICKER_CNTR_MASK \ ) /* Macro to translate tick units to microseconds. */ diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h index 642ca1e608f..e4d162eb9d2 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h @@ -6,37 +6,53 @@ */ #define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U +#define HAL_TICKER_CNTR_CLK_UNIT_FS 30517578125UL +/* Macro defining the minimum counter compare offset */ #define HAL_TICKER_CNTR_CMP_OFFSET_MIN 2 +/* Macro defining the max. counter update latency in ticks */ #define HAL_TICKER_CNTR_SET_LATENCY 1 + +/* Macro defines the h/w supported most significant bit */ +#define HAL_TICKER_CNTR_MSBIT 31 + +/* Macro defining the HW supported counter bits */ +#define HAL_TICKER_CNTR_MASK 0xFFFFFFFF + /* * When the LPTMR is enabled, the first increment will take an additional * one or two prescaler clock cycles due to synchronization logic. */ +/* Macro to translate microseconds to tick units. + * NOTE: This returns the floor value. + */ #define HAL_TICKER_US_TO_TICKS(x) \ ( \ - ((uint32_t)(((uint64_t) (x) * 1000000000UL) / 30517578125UL)) \ - & HAL_TICKER_CNTR_MASK \ + ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + HAL_TICKER_CNTR_MASK \ + ) + +/* Macro to translate tick units to microseconds. */ +#define HAL_TICKER_TICKS_TO_US(x) \ + ( \ + ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FS) / \ + 1000000000UL)) \ ) +/* Macro returning remainder in picoseconds (to fit in 32-bits) */ #define HAL_TICKER_REMAINDER(x) \ ( \ ( \ ((uint64_t) (x) * 1000000000UL) \ - - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * 30517578125UL) \ + - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * \ + HAL_TICKER_CNTR_CLK_UNIT_FS) \ ) \ / 1000UL \ ) -#define HAL_TICKER_TICKS_TO_US(x) \ - ((uint32_t)(((uint64_t)(x) * 30517578125UL) / 1000000000UL)) - -#define HAL_TICKER_CNTR_MSBIT 31 - -#define HAL_TICKER_CNTR_MASK 0xFFFFFFFF - /* Macro defining the remainder resolution/range * ~ 1000000 * HAL_TICKER_TICKS_TO_US(1) */ diff --git a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h index bbd4b3e462c..7c3792d848c 100644 --- a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h +++ b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h @@ -3,7 +3,9 @@ * * SPDX-License-Identifier: Apache-2.0 */ + #define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U +#define HAL_TICKER_CNTR_CLK_UNIT_FS 30517578125UL /* Macro defining the minimum counter compare offset */ #define HAL_TICKER_CNTR_CMP_OFFSET_MIN 3 @@ -11,30 +13,47 @@ /* Macro defining the max. counter update latency in ticks */ #define HAL_TICKER_CNTR_SET_LATENCY 0 +/* Macro defines the h/w supported most significant bit */ +#define HAL_TICKER_CNTR_MSBIT 23 + +/* Macro defining the HW supported counter bits */ +#define HAL_TICKER_CNTR_MASK 0x00FFFFFF + /* Macro to translate microseconds to tick units. * NOTE: This returns the floor value. */ -#define HAL_TICKER_US_TO_TICKS(x) \ - (((uint32_t)(((uint64_t)(x) * 1000000000UL) / 30517578125UL)) & HAL_TICKER_CNTR_MASK) +#define HAL_TICKER_US_TO_TICKS(x) \ + ( \ + ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + HAL_TICKER_CNTR_MASK \ + ) -/* Macro returning remainder in nanoseconds */ -#define HAL_TICKER_REMAINDER(x) \ - ((((uint64_t)(x) * 1000000000UL) - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * 30517578125UL)) /\ - 1000UL) /* Macro to translate tick units to microseconds. */ -#define HAL_TICKER_TICKS_TO_US(x) ((uint32_t)(((uint64_t)(x) * 30517578125UL) / 1000000000UL)) - -/* Macro defines the h/w supported most significant bit */ -#define HAL_TICKER_CNTR_MSBIT 23 - -/* Macro defining the HW supported counter bits */ -#define HAL_TICKER_CNTR_MASK 0x00FFFFFF +#define HAL_TICKER_TICKS_TO_US(x) \ + ( \ + ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FS) / \ + 1000000000UL)) \ + ) + +/* Macro returning remainder in picoseconds (to fit in 32-bits) */ +#define HAL_TICKER_REMAINDER(x) \ + ( \ + ( \ + ((uint64_t) (x) * 1000000000UL) \ + - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * \ + HAL_TICKER_CNTR_CLK_UNIT_FS) \ + ) \ + / 1000UL \ + ) /* Macro defining the remainder resolution/range * ~ 1000000 * HAL_TICKER_TICKS_TO_US(1) */ -#define HAL_TICKER_REMAINDER_RANGE HAL_TICKER_TICKS_TO_US(1000000) +#define HAL_TICKER_REMAINDER_RANGE \ + HAL_TICKER_TICKS_TO_US(1000000) /* Macro defining the margin for positioning re-scheduled nodes */ -#define HAL_TICKER_RESCHEDULE_MARGIN HAL_TICKER_US_TO_TICKS(150) +#define HAL_TICKER_RESCHEDULE_MARGIN \ + HAL_TICKER_US_TO_TICKS(150) From 4604cde52079bb44a3d2fcfd08c7362969cf3a40 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 13 Jun 2023 09:07:19 +0530 Subject: [PATCH 0221/1623] [nrf fromtree] Bluetooth: Controller: Use HAL_TICKER_US_TO_TICKS_CEIL for ticks_slot Use HAL_TICKER_US_TO_TICKS_CEIL for ticks_slot calculations. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 333ff94e6bd19f7b2bc7c9c3ddb1f84fb84bff80) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 8412da5360660f100a0d5ae894b222b736756270) --- .../controller/ll_sw/nordic/hal/nrf5/ticker.h | 11 +++++++++++ .../controller/ll_sw/openisa/hal/RV32M1/ticker.h | 11 +++++++++++ subsys/bluetooth/controller/ll_sw/ull_adv.c | 4 ++-- subsys/bluetooth/controller/ll_sw/ull_adv_aux.c | 6 +++--- subsys/bluetooth/controller/ll_sw/ull_adv_iso.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_adv_sync.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_central.c | 11 ++++------- subsys/bluetooth/controller/ll_sw/ull_central_iso.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_conn.c | 10 ++++------ subsys/bluetooth/controller/ll_sw/ull_conn_iso.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_peripheral.c | 11 ++++------- subsys/bluetooth/controller/ll_sw/ull_scan_aux.c | 10 ++++------ subsys/bluetooth/controller/ll_sw/ull_sched.c | 10 ++++++---- subsys/bluetooth/controller/ll_sw/ull_sync.c | 10 ++++------ subsys/bluetooth/controller/ll_sw/ull_sync_iso.c | 10 +++++----- .../mock_ctrl/include/hal/ticker_vendor_hal.h | 10 ++++++++++ 16 files changed, 72 insertions(+), 50 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h index 315601ce203..f179dbd0035 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h @@ -30,6 +30,17 @@ HAL_TICKER_CNTR_MASK \ ) +/* Macro to translate microseconds to tick units. + * NOTE: This returns the ceil value. + */ +#define HAL_TICKER_US_TO_TICKS_CEIL(x) \ + ( \ + ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ + HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + HAL_TICKER_CNTR_MASK \ + ) + /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ ( \ diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h index e4d162eb9d2..1f491739185 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h @@ -35,6 +35,17 @@ HAL_TICKER_CNTR_MASK \ ) +/* Macro to translate microseconds to tick units. + * NOTE: This returns the ceil value. + */ +#define HAL_TICKER_US_TO_TICKS_CEIL(x) \ + ( \ + ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ + HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + HAL_TICKER_CNTR_MASK \ + ) + /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ ( \ diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index 3797acdc541..d7d5b23f63e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -1251,7 +1251,7 @@ uint8_t ll_adv_enable(uint8_t enable) HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); adv->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - adv->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); + adv->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); ticks_slot_offset = MAX(adv->ull.ticks_active_to_start, adv->ull.ticks_prepare_to_start); @@ -2145,7 +2145,7 @@ uint8_t ull_adv_time_update(struct ll_adv_set *adv, struct pdu_adv *pdu, chan_map = lll->chan_map; chan_cnt = util_ones_count_get(&chan_map, sizeof(chan_map)); time_us = adv_time_get(pdu, pdu_scan, chan_cnt, phy, phy_flags); - time_ticks = HAL_TICKER_US_TO_TICKS(time_us); + time_ticks = HAL_TICKER_US_TO_TICKS_CEIL(time_us); #if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) uint32_t volatile ret_cb; diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c index 907a69b05c7..5349b21dd9f 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c @@ -2454,7 +2454,7 @@ uint32_t ull_adv_aux_evt_init(struct ll_adv_aux_set *aux, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); aux->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - aux->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); + aux->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { ticks_slot_overhead = MAX(aux->ull.ticks_active_to_start, @@ -2471,7 +2471,7 @@ uint32_t ull_adv_aux_evt_init(struct ll_adv_aux_set *aux, #if defined(CONFIG_BT_CTLR_ADV_RESERVE_MAX) time_us = ull_adv_aux_time_get(aux, PDU_AC_PAYLOAD_SIZE_MAX, PDU_AC_PAYLOAD_SIZE_MAX); - ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); + ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); #else ticks_slot = aux->ull.ticks_slot; #endif @@ -2997,7 +2997,7 @@ static uint8_t aux_time_update(struct ll_adv_aux_set *aux, struct pdu_adv *pdu, uint32_t time_us; time_us = aux_time_min_get(aux); - time_ticks = HAL_TICKER_US_TO_TICKS(time_us); + time_ticks = HAL_TICKER_US_TO_TICKS_CEIL(time_us); #if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) uint32_t volatile ret_cb; diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index 765e911b208..89e66ff99e5 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -977,7 +977,7 @@ static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); adv_iso->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - adv_iso->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(slot_us); + adv_iso->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); ticks_slot_offset = MAX(adv_iso->ull.ticks_active_to_start, adv_iso->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c index 178116a54ec..bbb1b351848 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c @@ -1136,7 +1136,7 @@ uint32_t ull_adv_sync_evt_init(struct ll_adv_set *adv, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); sync->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - sync->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); + sync->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); ticks_slot_offset = MAX(sync->ull.ticks_active_to_start, sync->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_central.c b/subsys/bluetooth/controller/ll_sw/ull_central.c index 5effe2ae676..de14395f840 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central.c @@ -360,13 +360,10 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, #endif /* CONFIG_BT_CTLR_ADV_EXT */ #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - conn->ull.ticks_slot = - HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + - EVENT_OVERHEAD_END_US + - ready_delay_us + - max_tx_time + - EVENT_IFS_US + - max_rx_time); + conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( + EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + + ready_delay_us + max_tx_time + EVENT_IFS_US + max_rx_time + + (EVENT_CLOCK_JITTER_US << 1)); #if defined(CONFIG_BT_CTLR_PRIVACY) ull_filter_scan_update(filter_policy); diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 71b8d742a76..2a19e03bde5 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -559,7 +559,7 @@ uint8_t ll_cig_parameters_commit(uint8_t cig_id, uint16_t *handles) HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); cig->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - cig->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(slot_us); + cig->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); #endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ /* Reset params cache */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 0b54a5dee79..a8d3178e020 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -1257,12 +1257,10 @@ void ull_conn_done(struct node_rx_event_done *done) tx_time = PDU_DC_MAX_US(lll->dle.eff.max_tx_octets, 0); rx_time = PDU_DC_MAX_US(lll->dle.eff.max_rx_octets, 0); #endif /* CONFIG_BT_CTLR_PHY */ - ticks_slot = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + - ready_delay + - EVENT_IFS_US + - rx_time + - tx_time + - 4); + ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( + EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + + ready_delay + EVENT_IFS_US + rx_time + tx_time + + (EVENT_CLOCK_JITTER_US << 1)); if (ticks_slot > conn->ull.ticks_slot) { ticks_slot_plus = ticks_slot - conn->ull.ticks_slot; } else { diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index 2ee5905b23b..46c00c305fe 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -987,7 +987,7 @@ void ull_conn_iso_start(struct ll_conn *conn, uint16_t cis_handle, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); cig->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - cig->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(slot_us); + cig->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); } ticks_slot_offset = MAX(cig->ull.ticks_active_to_start, diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c index f1716c06573..8b813fda9fd 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c @@ -371,13 +371,10 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); conn->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - conn->ull.ticks_slot = - HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + - EVENT_OVERHEAD_END_US + - ready_delay_us + - max_rx_time + - EVENT_IFS_US + - max_tx_time); + conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( + EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + + ready_delay_us + max_rx_time + EVENT_IFS_US + max_tx_time + + (EVENT_CLOCK_JITTER_US << 1)); ticks_slot_offset = MAX(conn->ull.ticks_active_to_start, conn->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c b/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c index 26fc6d4806b..316cec7fec7 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c @@ -666,12 +666,10 @@ void ull_scan_aux_setup(memq_link_t *link, struct node_rx_hdr *rx) HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); aux->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - aux->ull.ticks_slot = - HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + - ready_delay_us + - PDU_AC_MAX_US(PDU_AC_EXT_PAYLOAD_RX_SIZE, - lll_aux->phy) + - EVENT_OVERHEAD_END_US); + aux->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( + EVENT_OVERHEAD_START_US + ready_delay_us + + PDU_AC_MAX_US(PDU_AC_EXT_PAYLOAD_RX_SIZE, lll_aux->phy) + + EVENT_OVERHEAD_END_US); ticks_slot_offset = MAX(aux->ull.ticks_active_to_start, aux->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_sched.c b/subsys/bluetooth/controller/ll_sw/ull_sched.c index a445d986248..e7ca8a0358b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sched.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sched.c @@ -656,7 +656,7 @@ static struct ull_hdr *ull_hdr_get_cb(uint8_t ticker_id, uint32_t *ticks_slot) time_us = ull_adv_aux_time_get(aux, PDU_AC_PAYLOAD_SIZE_MAX, PDU_AC_PAYLOAD_SIZE_MAX); - *ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); + *ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); } else { *ticks_slot = aux->ull.ticks_slot; @@ -686,7 +686,7 @@ static struct ull_hdr *ull_hdr_get_cb(uint8_t ticker_id, uint32_t *ticks_slot) uint32_t time_us; time_us = ull_adv_sync_time_get(sync, PDU_AC_PAYLOAD_SIZE_MAX); - *ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); + *ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); } else { *ticks_slot = sync->ull.ticks_slot; } @@ -745,9 +745,11 @@ static struct ull_hdr *ull_hdr_get_cb(uint8_t ticker_id, uint32_t *ticks_slot) #endif /* !CONFIG_BT_CTLR_PHY_CODED */ time_us = EVENT_OVERHEAD_START_US + + EVENT_OVERHEAD_END_US + ready_delay_us + max_rx_time + - EVENT_IFS_US + max_tx_time; - *ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); + EVENT_IFS_US + max_tx_time + + (EVENT_CLOCK_JITTER_US << 1); + *ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); } else { *ticks_slot = conn->ull.ticks_slot; } diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync.c b/subsys/bluetooth/controller/ll_sw/ull_sync.c index 6c674885810..265475196fd 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sync.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sync.c @@ -826,12 +826,10 @@ void ull_sync_setup(struct ll_scan_set *scan, struct ll_scan_aux_set *aux, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); sync->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - sync->ull.ticks_slot = - HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + - ready_delay_us + - PDU_AC_MAX_US(PDU_AC_EXT_PAYLOAD_RX_SIZE, - lll->phy) + - EVENT_OVERHEAD_END_US); + sync->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( + EVENT_OVERHEAD_START_US + ready_delay_us + + PDU_AC_MAX_US(PDU_AC_EXT_PAYLOAD_RX_SIZE, lll->phy) + + EVENT_OVERHEAD_END_US); ticks_slot_offset = MAX(sync->ull.ticks_active_to_start, sync->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c index fbacb56f8b4..ff3327ce393 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c @@ -509,11 +509,11 @@ void ull_sync_iso_setup(struct ll_sync_iso_set *sync_iso, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); sync_iso->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - sync_iso->ull.ticks_slot = HAL_TICKER_US_TO_TICKS( - EVENT_OVERHEAD_START_US + ready_delay_us + - PDU_BIS_MAX_US(PDU_AC_EXT_PAYLOAD_SIZE_MAX, lll->enc, - lll->phy) + - EVENT_OVERHEAD_END_US); + sync_iso->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( + EVENT_OVERHEAD_START_US + ready_delay_us + + PDU_BIS_MAX_US(PDU_AC_EXT_PAYLOAD_SIZE_MAX, lll->enc, + lll->phy) + + EVENT_OVERHEAD_END_US); ticks_slot_offset = MAX(sync_iso->ull.ticks_active_to_start, sync_iso->ull.ticks_prepare_to_start); diff --git a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h index 7c3792d848c..67a46515033 100644 --- a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h +++ b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h @@ -29,6 +29,16 @@ HAL_TICKER_CNTR_MASK \ ) +/* Macro to translate microseconds to tick units. + * NOTE: This returns the ceil value. + */ +#define HAL_TICKER_US_TO_TICKS_CEIL(x) \ + ( \ + ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ + HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + HAL_TICKER_CNTR_MASK \ + ) /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ From fb5d216e14172be3d897607f7e0928459c3b0dd9 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 14 Sep 2023 18:47:25 +0530 Subject: [PATCH 0222/1623] [nrf fromtree] Bluetooth: Controller: Use defines for femto and pico seconds Use defines for femto and pico seconds in HAL ticker calculations. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 34100cb7ea9d398a10281eb76fc97218569f94f1) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit f1517bc6cf2eec146405fccbd896205cb71f9d6a) --- .../controller/ll_sw/nordic/hal/nrf5/ticker.h | 41 ++++++++++--------- .../ll_sw/openisa/hal/RV32M1/ticker.h | 29 +++++++------ .../mock_ctrl/include/hal/ticker_vendor_hal.h | 29 +++++++------ 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h index f179dbd0035..cbb8ae6a8ce 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h @@ -5,8 +5,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U -#define HAL_TICKER_CNTR_CLK_UNIT_FS 30517578125UL +#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U +#define HAL_TICKER_CNTR_CLK_UNIT_FSEC 30517578125UL +#define HAL_TICKER_FSEC_PER_USEC 1000000000UL +#define HAL_TICKER_PSEC_PER_USEC 1000000UL +#define HAL_TICKER_FSEC_PER_PSEC 1000UL /* Macro defining the minimum counter compare offset */ #define HAL_TICKER_CNTR_CMP_OFFSET_MIN 3 @@ -25,8 +28,8 @@ */ #define HAL_TICKER_US_TO_TICKS(x) \ ( \ - ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + ((uint32_t)(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) / \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ HAL_TICKER_CNTR_MASK \ ) @@ -35,35 +38,35 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ - HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ HAL_TICKER_CNTR_MASK \ ) /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ ( \ - ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FS) / \ - 1000000000UL)) \ + ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FSEC) / \ + HAL_TICKER_FSEC_PER_USEC)) \ ) /* Macro returning remainder in picoseconds (to fit in 32-bits) */ #define HAL_TICKER_REMAINDER(x) \ ( \ ( \ - ((uint64_t) (x) * 1000000000UL) \ + ((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) \ - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * \ - HAL_TICKER_CNTR_CLK_UNIT_FS) \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC) \ ) \ - / 1000UL \ + / HAL_TICKER_FSEC_PER_PSEC \ ) /* Macro defining the remainder resolution/range * ~ 1000000 * HAL_TICKER_TICKS_TO_US(1) */ #define HAL_TICKER_REMAINDER_RANGE \ - HAL_TICKER_TICKS_TO_US(1000000) + HAL_TICKER_TICKS_TO_US(HAL_TICKER_PSEC_PER_USEC) /* Macro defining the margin for positioning re-scheduled nodes */ #define HAL_TICKER_RESCHEDULE_MARGIN \ @@ -74,24 +77,24 @@ static inline void hal_ticker_remove_jitter(uint32_t *ticks, uint32_t *remainder) { /* Is remainder less than 1 us */ - if ((*remainder & BIT(31)) || !(*remainder / 1000000UL)) { + if ((*remainder & BIT(31)) || !(*remainder / HAL_TICKER_PSEC_PER_USEC)) { *ticks -= 1U; - *remainder += HAL_TICKER_CNTR_CLK_UNIT_FS / 1000UL; + *remainder += HAL_TICKER_CNTR_CLK_UNIT_FSEC / HAL_TICKER_FSEC_PER_PSEC; } /* pico seconds to micro seconds unit */ - *remainder /= 1000000UL; + *remainder /= HAL_TICKER_PSEC_PER_USEC; } /* Add ticks and return positive remainder value in microseconds */ static inline void hal_ticker_add_jitter(uint32_t *ticks, uint32_t *remainder) { /* Is remainder less than 1 us */ - if ((*remainder & BIT(31)) || !(*remainder / 1000000UL)) { + if ((*remainder & BIT(31)) || !(*remainder / HAL_TICKER_PSEC_PER_USEC)) { *ticks += 1U; - *remainder += HAL_TICKER_CNTR_CLK_UNIT_FS / 1000UL; + *remainder += HAL_TICKER_CNTR_CLK_UNIT_FSEC / HAL_TICKER_FSEC_PER_PSEC; } /* pico seconds to micro seconds unit */ - *remainder /= 1000000UL; + *remainder /= HAL_TICKER_PSEC_PER_USEC; } diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h index 1f491739185..78aa6362595 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h @@ -5,8 +5,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U -#define HAL_TICKER_CNTR_CLK_UNIT_FS 30517578125UL +#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U +#define HAL_TICKER_CNTR_CLK_UNIT_FSEC 30517578125UL +#define HAL_TICKER_FSEC_PER_USEC 1000000000UL +#define HAL_TICKER_PSEC_PER_USEC 1000000UL +#define HAL_TICKER_FSEC_PER_PSEC 1000UL /* Macro defining the minimum counter compare offset */ #define HAL_TICKER_CNTR_CMP_OFFSET_MIN 2 @@ -30,8 +33,8 @@ */ #define HAL_TICKER_US_TO_TICKS(x) \ ( \ - ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + ((uint32_t)(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) / \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ HAL_TICKER_CNTR_MASK \ ) @@ -40,35 +43,35 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ - HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ HAL_TICKER_CNTR_MASK \ ) /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ ( \ - ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FS) / \ - 1000000000UL)) \ + ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FSEC) / \ + HAL_TICKER_FSEC_PER_USEC)) \ ) /* Macro returning remainder in picoseconds (to fit in 32-bits) */ #define HAL_TICKER_REMAINDER(x) \ ( \ ( \ - ((uint64_t) (x) * 1000000000UL) \ + ((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) \ - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * \ - HAL_TICKER_CNTR_CLK_UNIT_FS) \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC) \ ) \ - / 1000UL \ + / HAL_TICKER_FSEC_PER_PSEC \ ) /* Macro defining the remainder resolution/range * ~ 1000000 * HAL_TICKER_TICKS_TO_US(1) */ #define HAL_TICKER_REMAINDER_RANGE \ - HAL_TICKER_TICKS_TO_US(1000000) + HAL_TICKER_TICKS_TO_US(HAL_TICKER_PSEC_PER_USEC) /* Macro defining the margin for positioning re-scheduled nodes */ #define HAL_TICKER_RESCHEDULE_MARGIN \ diff --git a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h index 67a46515033..c2b20050caa 100644 --- a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h +++ b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h @@ -4,8 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U -#define HAL_TICKER_CNTR_CLK_UNIT_FS 30517578125UL +#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U +#define HAL_TICKER_CNTR_CLK_UNIT_FSEC 30517578125UL +#define HAL_TICKER_FSEC_PER_USEC 1000000000UL +#define HAL_TICKER_PSEC_PER_USEC 1000000UL +#define HAL_TICKER_FSEC_PER_PSEC 1000UL /* Macro defining the minimum counter compare offset */ #define HAL_TICKER_CNTR_CMP_OFFSET_MIN 3 @@ -24,8 +27,8 @@ */ #define HAL_TICKER_US_TO_TICKS(x) \ ( \ - ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + ((uint32_t)(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) / \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ HAL_TICKER_CNTR_MASK \ ) @@ -34,35 +37,35 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ - HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ + ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ HAL_TICKER_CNTR_MASK \ ) /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ ( \ - ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FS) / \ - 1000000000UL)) \ + ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FSEC) / \ + HAL_TICKER_FSEC_PER_USEC)) \ ) /* Macro returning remainder in picoseconds (to fit in 32-bits) */ #define HAL_TICKER_REMAINDER(x) \ ( \ ( \ - ((uint64_t) (x) * 1000000000UL) \ + ((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) \ - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * \ - HAL_TICKER_CNTR_CLK_UNIT_FS) \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC) \ ) \ - / 1000UL \ + / HAL_TICKER_FSEC_PER_PSEC \ ) /* Macro defining the remainder resolution/range * ~ 1000000 * HAL_TICKER_TICKS_TO_US(1) */ #define HAL_TICKER_REMAINDER_RANGE \ - HAL_TICKER_TICKS_TO_US(1000000) + HAL_TICKER_TICKS_TO_US(HAL_TICKER_PSEC_PER_USEC) /* Macro defining the margin for positioning re-scheduled nodes */ #define HAL_TICKER_RESCHEDULE_MARGIN \ From f5d51232a709225b77d6a2e9bfe25213e74637d5 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 14 Sep 2023 19:04:22 +0530 Subject: [PATCH 0223/1623] [nrf fromtree] Bluetooth: Controller: Use DIV_ROUND_UP macro in HAL ticker Use DIV_ROUND_UP macro in HAL ticker. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 5daa864b5e7b21d840b3fdb51c238a009a24c8f1) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 96ebab1b3ce374543a83ae745a00418968c534fc) --- subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h | 5 ++--- .../bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h | 5 ++--- .../controller/mock_ctrl/include/hal/ticker_vendor_hal.h | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h index cbb8ae6a8ce..10d780a559c 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h @@ -38,9 +38,8 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ + DIV_ROUND_UP(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC), \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC) & \ HAL_TICKER_CNTR_MASK \ ) diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h index 78aa6362595..ab9b14207c1 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h @@ -43,9 +43,8 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ + DIV_ROUND_UP(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC), \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC) & \ HAL_TICKER_CNTR_MASK \ ) diff --git a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h index c2b20050caa..8cb4e791a30 100644 --- a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h +++ b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h @@ -37,9 +37,8 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ + DIV_ROUND_UP(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC), \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC) & \ HAL_TICKER_CNTR_MASK \ ) From 788c7ff8e63a7ddcd0e7c8850628c29f208e8937 Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Fri, 30 Jun 2023 09:17:36 +0200 Subject: [PATCH 0224/1623] [nrf fromtree] Bluetooth: controller: Use consecutive event for framed TX and RX bugfix Changes: -- Disregards target event after segmenting the first TX SDU and instead decide event based on the next payload and feasibility to fragment for that event (time-offset > 0) -- Corrected error SDU release logic when an error occurs while expecting the start of a new SDU, to avoid releasing an SDU which could be received in the next payload or event -- Included additional debug logging Signed-off-by: Nirosharn Amarasinghe (cherry picked from commit e318a3032b0d09ef9439b2a9b1c792a3cae203d6) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 40fdecb4fc18d92b4425101a0f6de873ff001a36) --- subsys/bluetooth/controller/ll_sw/isoal.c | 408 +++++++++++++++------- subsys/bluetooth/controller/ll_sw/isoal.h | 4 +- 2 files changed, 292 insertions(+), 120 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index 0a500cfd05e..110a7aa901e 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -50,6 +50,11 @@ LOG_MODULE_REGISTER(bt_ctlr_isoal, LOG_LEVEL_INF); (s == ISOAL_CONTINUE ? "CONTINUE" : \ (s == ISOAL_ERR_SPOOL ? "ERR SPOOL" : "???"))) +#define STATE_TO_STR(s) (s == BT_ISO_SINGLE ? "SINGLE" : \ + (s == BT_ISO_START ? "START" : \ + (s == BT_ISO_CONT ? "CONT" : \ + (s == BT_ISO_END ? "END" : "???")))) + #if defined(CONFIG_BT_CTLR_ADV_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO) /* Given the minimum payload, this defines the minimum number of bytes that * should be remaining in a TX PDU such that it would make inserting a new @@ -186,7 +191,7 @@ static bool isoal_get_time_diff(uint32_t time_before, uint32_t time_after, uint3 #define SET_RX_SDU_TIMESTAMP(_sink, _timestamp, _value) \ _timestamp = _value; \ - ISOAL_LOG_DBGV("[%p] %s updated (%ld)", _sink, #_timestamp, _value); + ISOAL_LOG_DBGV("[%p] %s updated (%lu)", _sink, #_timestamp, _value); static void isoal_rx_framed_update_sdu_release(struct isoal_sink *sink); @@ -415,7 +420,7 @@ static isoal_status_t isoal_rx_allocate_sdu(struct isoal_sink *sink, ); if (err == ISOAL_STATUS_OK) { - sp->sdu_allocated = true; + sp->sdu_allocated = 1U; } /* Nothing has been written into buffer yet */ @@ -599,7 +604,7 @@ static isoal_status_t isoal_rx_try_emit_sdu(struct isoal_sink *sink, bool end_of sdu->status = sp->sdu_status; err = isoal_rx_buffered_emit_sdu(sink, end_of_sdu); - sp->sdu_allocated = false; + sp->sdu_allocated = 0U; if (end_of_sdu) { isoal_rx_framed_update_sdu_release(sink); @@ -729,9 +734,9 @@ static isoal_status_t isoal_rx_unframed_consume(struct isoal_sink *sink, next_state = ISOAL_START; /* If status is not ISOAL_PDU_STATUS_VALID, length and LLID cannot be trusted */ - llid = pdu_meta->pdu->ll_id; + llid = pdu->ll_id; pdu_err = (pdu_meta->meta->status != ISOAL_PDU_STATUS_VALID); - length = pdu_meta->pdu->len; + length = pdu->len; /* A zero length PDU with LLID 0b01 (PDU_BIS_LLID_START_CONTINUE) would be a padding PDU. * However if there are errors in the PDU, it could be an incorrectly receive non-padding * PDU. Therefore only consider a PDU with errors as padding if received after the end @@ -937,7 +942,7 @@ static isoal_status_t isoal_rx_unframed_consume(struct isoal_sink *sink, sp->prev_pdu_is_end = !pdu_err && llid == PDU_BIS_LLID_COMPLETE_END; sp->prev_pdu_is_padding = !pdu_err && pdu_padding; - sp->initialized = true; + sp->initialized = 1U; return err; } @@ -1293,6 +1298,8 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, } if (pdu_err || seq_err || seg_err) { + bool error_sdu_pending = false; + /* When one or more ISO Data PDUs are not received, the receiving device may * discard all SDUs affected by the missing PDUs. Any partially received SDU * may also be discarded. @@ -1321,14 +1328,28 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, switch (sp->fsm) { case ISOAL_START: - /* First release lost SDUs and then release a new SDU - * with errors. Since we have an SDU to release - * following any lost SDUs, lost SDUs handling should be - * similar to when a valid timestamp exists. + /* If errors occur while waiting for the start of an SDU + * then an SDU should should only be released if there + * is confirmation that a reception occurred + * unsuccessfully. In the case of STATUS_LOST_DATA which + * could result from a flush, an SDU should not be + * released as the flush does not necessarily mean that + * part of an SDU has been lost. In this case Lost SDU + * release defaults to the lost SDU detection based on + * the SDU interval. If we have a SDU to release + * following any lost SDUs, lost SDU handling should be + * similar to when a valid timestamp for the next SDU + * exists. */ - err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, true, timestamp); - sp->sdu_status = next_sdu_status; - err |= isoal_rx_append_to_sdu(sink, pdu_meta, 0, 0, true, false); + error_sdu_pending = seg_err || + (pdu_err && meta->status == ISOAL_SDU_STATUS_ERRORS); + err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, + error_sdu_pending, timestamp); + + if (error_sdu_pending) { + sp->sdu_status = next_sdu_status; + err |= isoal_rx_append_to_sdu(sink, pdu_meta, 0, 0, true, false); + } break; case ISOAL_CONTINUE: @@ -1339,11 +1360,13 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, */ sp->sdu_status = next_sdu_status; err |= isoal_rx_append_to_sdu(sink, pdu_meta, 0, 0, true, false); - err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, false, timestamp); + err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, + error_sdu_pending, timestamp); break; case ISOAL_ERR_SPOOL: - err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, false, timestamp); + err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, + error_sdu_pending, timestamp); break; } @@ -1353,7 +1376,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, } sp->prev_pdu_id = meta->payload_number; - sp->initialized = true; + sp->initialized = 1U; return err; } @@ -1610,6 +1633,10 @@ static isoal_status_t isoal_tx_pdu_emit(const struct isoal_source *source_ctx, /* Attempt to enqueue the node towards the LL */ status = source_ctx->session.pdu_emit(node_tx, handle); + ISOAL_LOG_DBG("[%p] PDU %llu err=%X len=%u frags=%u released", + source_ctx, node_tx->payload_count, status, + produced_pdu->contents.pdu->len, sdu_fragments); + if (status != ISOAL_STATUS_OK) { /* If it fails, the node will be released and no further attempt * will be possible @@ -1666,6 +1693,7 @@ static isoal_status_t isoal_tx_allocate_pdu(struct isoal_source *source, /* Nothing has been written into buffer yet */ pp->pdu_written = 0; pp->pdu_available = available_len; + pp->pdu_allocated = 1U; LL_ASSERT(available_len > 0); pp->pdu_cnt++; @@ -1708,6 +1736,7 @@ static isoal_status_t isoal_tx_try_emit_pdu(struct isoal_source *source, pp->pdu_written); pp->payload_number++; pp->sdu_fragments = 0; + pp->pdu_allocated = 0U; } return err; @@ -1751,7 +1780,7 @@ uint16_t isoal_tx_unframed_get_next_payload_number(isoal_source_handle_t source_ time_diff = 0; /* Adjust payload number */ - if (IS_ENABLED(CONFIG_BT_CTLR_ISOAL_SN_STRICT) && session->sn) { + if (IS_ENABLED(CONFIG_BT_CTLR_ISOAL_SN_STRICT) && pp->initialized) { /* Not the first SDU in this session, so reference * information should be valid. At this point, the * current payload number should be at the first PDU of @@ -1806,15 +1835,26 @@ uint16_t isoal_tx_unframed_get_next_payload_number(isoal_source_handle_t source_ return sdus_skipped; } -/* NOTE: Use of target_event and grp_ref_point as input from upper layer. +/** + * @brief Fragment received SDU and produce unframed PDUs + * @details Destination source may have an already partially built PDU * - * For unframed: + * @param source_hdl[in] Destination source handle + * @param tx_sdu[in] SDU with packet boundary information + * + * @return Status + * + * @note + * PSN in SDUs for unframed TX: + * + * @par * Before the modification to use the PSN to decide the position of an SDU in a * stream of SDU, the target event was what was used in deciding the event for * each SDU. This meant that there would possibly have been skews on the - * receiver for each SDU and we had trouble with LL/CIS/PER/BV-39-C which + * receiver for each SDU and there were problems with LL/CIS/PER/BV-39-C which * expects clustering within an event. * + * @par * After the change, the PSN is used to decide the position of an SDU in the * stream anchored at the first PSN received. However for the first SDU * (assume that PSN=0), it will be the target event that decides which event @@ -1823,6 +1863,7 @@ uint16_t isoal_tx_unframed_get_next_payload_number(isoal_source_handle_t source_ * impacts the event chosen for the first SDU and all subsequent SDUs will be * decided relative to the first. * + * @par * The target event and related group reference point is still used to provide * the ISO-AL with a notion of time, for example when storing information * required for the TX Sync command. For example if for PSN 4, target event is @@ -1832,26 +1873,17 @@ uint16_t isoal_tx_unframed_get_next_payload_number(isoal_source_handle_t source_ * for event 7. It is also expected that this value is the latest reference and * is drift compensated. * - * The PSN alone is not sufficient for this because as far as I am aware, host - * and controller have no common reference time for when CIG/BIG event 0 starts. - * Therefore I would expect it is possible to receive PSN 0 in event 2 for - * example. If the target event provided is event 3, then PSN 0 will be - * fragmented into payloads for event 3 and that will serve as the anchor for - * the stream and subsequent SDUs. If for example target event provided was - * event 2 instead, then it could very well be that PSN 0 might not be - * transmitted as is was received midway through event 2 and the payloads - * expired. If this happens then subsequent SDUs might also all be late for - * their transmission slots as they are positioned relative to PSN 0. - */ - -/** - * @brief Fragment received SDU and produce unframed PDUs - * @details Destination source may have an already partially built PDU - * - * @param source_hdl[in] Destination source handle - * @param tx_sdu[in] SDU with packet boundary information - * - * @return Status + * @par + * The PSN alone is not sufficient for this because host and controller have no + * common reference time for when CIG / BIG event 0 starts. Therefore it is + * expected that it is possible to receive PSN 0 in event 2 for example. If the + * target event provided is event 3, then PSN 0 will be fragmented into payloads + * for event 3 and that will serve as the anchor for the stream and subsequent + * SDUs. If for example target event provided was event 2 instead, then it could + * very well be that PSN 0 might not be transmitted as is was received midway + * through event 2 and the payloads expired. If this happens then subsequent + * SDUs might also all be late for their transmission slots as they are + * positioned relative to PSN 0. */ static isoal_status_t isoal_tx_unframed_produce(isoal_source_handle_t source_hdl, const struct isoal_sdu_tx *tx_sdu) @@ -1881,7 +1913,6 @@ static isoal_status_t isoal_tx_unframed_produce(isoal_source_handle_t source_hdl if (tx_sdu->sdu_state == BT_ISO_START || tx_sdu->sdu_state == BT_ISO_SINGLE) { - /* Initialize to info provided in SDU */ uint32_t actual_grp_ref_point; uint64_t next_payload_number; uint16_t sdus_skipped; @@ -2062,6 +2093,8 @@ static isoal_status_t isoal_tx_unframed_produce(isoal_source_handle_t source_hdl zero_length_sdu = false; } + pp->initialized = 1U; + return err; } @@ -2126,6 +2159,9 @@ static isoal_status_t isoal_insert_seg_header_timeoffset(struct isoal_source *so pp->pdu_written += write_size; pp->pdu_available -= write_size; + ISOAL_LOG_DBGV("[%p] Seg header write size=%u sc=%u cmplt=%u TO=%u len=%u", + source, write_size, sc, cmplt, time_offset, seg_hdr.len); + return err; } @@ -2163,6 +2199,155 @@ static isoal_status_t isoal_update_seg_header_cmplt_length(struct isoal_source * pp->last_seg_hdr_loc, (uint8_t *) &seg_hdr, PDU_ISO_SEG_HDR_SIZE); + + ISOAL_LOG_DBGV("[%p] Seg header write size=%u sc=%u cmplt=%u len=%u", + source, PDU_ISO_SEG_HDR_SIZE, seg_hdr.sc, cmplt, seg_hdr.len); +} + +/** + * Find the earliest feasible event for transmission capacity is not wasted and + * return information based on that event. + * @param[in] source_hdl Destination source handle + * @param[in] tx_sdu SDU with meta data information + * @param[out] payload_number Updated payload number for the selected event + * @param[out] grp_ref_point Group reference point for the selected event + * @param[out] time_offset Segmentation Time offset to selected event + * @return The number SDUs skipped from the last + */ +static uint16_t isoal_tx_framed_find_correct_tx_event(isoal_source_handle_t source_hdl, + const struct isoal_sdu_tx *tx_sdu, + uint64_t *payload_number, + uint32_t *grp_ref_point, + uint32_t *time_offset) +{ + struct isoal_source_session *session; + struct isoal_pdu_production *pp; + uint32_t actual_grp_ref_point; + uint64_t next_payload_number; + struct isoal_source *source; + uint16_t sdus_skipped; + uint64_t actual_event; + bool time_diff_valid; + uint32_t time_diff; + + source = &isoal_global.source_state[source_hdl]; + session = &source->session; + pp = &source->pdu_production; + + sdus_skipped = 0; + + /* Continue with the current payload unless there is need to change */ + next_payload_number = pp->payload_number; + actual_event = pp->payload_number / session->burst_number; + + ISOAL_LOG_DBGV("[%p] Start PL=%llu Evt=%lu.", source, next_payload_number, actual_event); + + /* Get the drift updated group reference point for this event based on + * the actual event being set. This might introduce some errors as the + * group refernce point for future events could drift. However as the + * time offset calculation requires an absolute value, this seems to be + * the best candidate. + */ + if (actual_event != tx_sdu->target_event) { + actual_grp_ref_point = isoal_get_wrapped_time_us(tx_sdu->grp_ref_point, + ((actual_event - tx_sdu->target_event) * session->iso_interval * + ISO_INT_UNIT_US)); + } else { + actual_grp_ref_point = tx_sdu->grp_ref_point; + } + + ISOAL_LOG_DBGV("[%p] Current PL=%llu Evt=%llu Ref=%lu", + source, next_payload_number, actual_event, actual_grp_ref_point); + + if (tx_sdu->sdu_state == BT_ISO_START || + tx_sdu->sdu_state == BT_ISO_SINGLE) { + /* Start of a new SDU */ + + /* Adjust payload number */ + if (pp->initialized) { + /* Not the first SDU in this session, so reference + * information should be valid. . + */ + time_diff_valid = isoal_get_time_diff(session->last_input_time_stamp, + tx_sdu->time_stamp, + &time_diff); + + /* Priority is given to the sequence number */ + if (tx_sdu->packet_sn > session->last_input_sn + 1) { + ISOAL_LOG_DBGV("[%p] Using packet_sn for skipped SDUs", source); + sdus_skipped = (tx_sdu->packet_sn - session->last_input_sn) - 1; + + } else if (tx_sdu->packet_sn == session->last_input_sn && + time_diff_valid && time_diff > session->sdu_interval) { + ISOAL_LOG_DBGV("[%p] Using time_stamp for skipped SDUs", source); + /* Round at mid-point */ + sdus_skipped = ((time_diff + (session->sdu_interval / 2)) / + session->sdu_interval) - 1; + } else { + /* SDU is next in sequence */ + } + + } else { + /* First SDU, align with target event */ + actual_event = tx_sdu->target_event; + actual_grp_ref_point = tx_sdu->grp_ref_point; + + ISOAL_LOG_DBGV("[%p] Use target_event", source); + } + + /* Selecting the event for transmission is done solely based on + * the time stamp and the ability to calculate a valid time + * offset. + */ + + /* Check if time stamp on packet is later than the group + * reference point and find next feasible event for transmission. + * + * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: + * 3.1 Time_Offset in framed PDUs : + * The Time_Offset shall be a positive value. + */ + while (!isoal_get_time_diff(tx_sdu->time_stamp, actual_grp_ref_point, &time_diff) || + time_diff == 0) { + /* Advance target to next event */ + actual_event++; + actual_grp_ref_point = isoal_get_wrapped_time_us(actual_grp_ref_point, + session->iso_interval * ISO_INT_UNIT_US); + } + + ISOAL_LOG_DBGV("[%p] Chosen PL=%llu Evt=%llu Ref=%lu", + source, (actual_event * session->burst_number), actual_event, + actual_grp_ref_point); + + /* If the event selected is the last event segmented for, then + * it is possible that that some payloads have already been + * released for this event. Segmentation should continue from + * that payload. + */ + next_payload_number = MAX(pp->payload_number, + (actual_event * session->burst_number)); + } + + ISOAL_LOG_DBGV("[%p] Final Evt=%llu (PL=%llu) Ref.=%lu Next PL=%llu", + source, actual_event, (actual_event * session->burst_number), + actual_grp_ref_point, next_payload_number); + + /* Calculate the time offset */ + time_diff_valid = isoal_get_time_diff(tx_sdu->time_stamp, + actual_grp_ref_point, &time_diff); + + LL_ASSERT(time_diff_valid); + LL_ASSERT(time_diff > 0); + /* Time difference must be less than the maximum possible + * time-offset of 24-bits. + */ + LL_ASSERT(time_diff <= 0x00FFFFFF); + + *payload_number = next_payload_number; + *grp_ref_point = actual_grp_ref_point; + *time_offset = time_diff; + + return sdus_skipped; } /** @@ -2186,7 +2371,6 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, bool zero_length_sdu; isoal_status_t err; bool padding_pdu; - uint8_t ll_id; source = &isoal_global.source_state[source_hdl]; session = &source->session; @@ -2202,15 +2386,53 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, zero_length_sdu = (packet_available == 0 && tx_sdu->sdu_state == BT_ISO_SINGLE); + ISOAL_LOG_DBGV("[%p] SDU %u len=%u TS=%lu Ref=%lu Evt=%llu Frag=%u", + source, tx_sdu->packet_sn, tx_sdu->iso_sdu_length, tx_sdu->time_stamp, + tx_sdu->grp_ref_point, tx_sdu->target_event, tx_sdu->sdu_state); + if (tx_sdu->sdu_state == BT_ISO_START || tx_sdu->sdu_state == BT_ISO_SINGLE) { + uint32_t actual_grp_ref_point; + uint64_t next_payload_number; + uint16_t sdus_skipped; + /* Start of a new SDU */ - /* Initialize to info provided in SDU */ - uint32_t actual_grp_ref_point = tx_sdu->grp_ref_point; - uint64_t actual_event = tx_sdu->target_event; - bool time_diff_valid = false; - uint32_t time_diff = 0; + /* Find the best transmission event */ + sdus_skipped = isoal_tx_framed_find_correct_tx_event(source_hdl, tx_sdu, + &next_payload_number, + &actual_grp_ref_point, + &time_offset); + + ISOAL_LOG_DBGV("[%p] %u SDUs skipped.", source, sdus_skipped); + ISOAL_LOG_DBGV("[%p] Starting SDU %u PL=(%llu->%llu) Grp Ref=%lu TO=%lu", + source, tx_sdu->packet_sn, pp->payload_number, next_payload_number, + actual_grp_ref_point, time_offset); + + + if (next_payload_number > pp->payload_number) { + /* Moving to a new payload */ + if (pp->pdu_allocated) { + /* Current PDU in production should be released before + * moving to new event. + */ + ISOAL_LOG_DBGV("[%p] Pending PDU released.\n"); + err |= isoal_tx_try_emit_pdu(source, true, PDU_BIS_LLID_FRAMED); + } + + while (err == ISOAL_STATUS_OK && next_payload_number > pp->payload_number && + (pp->payload_number % session->burst_number)) { + /* Release padding PDUs for this event */ + err |= isoal_tx_allocate_pdu(source, tx_sdu); + err |= isoal_tx_try_emit_pdu(source, true, PDU_BIS_LLID_FRAMED); + } + } + + /* Reset PDU production state */ + pp->pdu_state = BT_ISO_START; + + /* Update to new payload number */ + pp->payload_number = next_payload_number; /* Update sequence number for received SDU * @@ -2224,67 +2446,8 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, * with the sequence number in the ISOAL once the Datapath is * configured and the link is established. */ - session->sn++; - - /* Reset PDU production state */ - pp->pdu_state = BT_ISO_START; - - /* Update payload counter in case time has passed since the last - * SDU. This should mean that event count * burst number should - * be greater than the current payload number. In the event of - * an SDU interval smaller than the ISO interval, multiple SDUs - * will be sent in the same event. As such the current payload - * number should be retained. Payload numbers are indexed at 0 - * and valid until the PDU is emitted. - */ - pp->payload_number = MAX(pp->payload_number, - (tx_sdu->target_event * session->burst_number)); - - /* Get actual event for this payload number */ - actual_event = pp->payload_number / session->burst_number; - - /* Get group reference point for this PDU based on the actual - * event being set. This might introduce some errors as the - * group refernce point for future events could drift. However - * as the time offset calculation requires an absolute value, - * this seems to be the best candidate. - */ - if (actual_event > tx_sdu->target_event) { - actual_grp_ref_point = isoal_get_wrapped_time_us(tx_sdu->grp_ref_point, - ((actual_event - tx_sdu->target_event) * session->iso_interval * - ISO_INT_UNIT_US)); - } - - /* Check if time stamp on packet is later than the group - * reference point and adjust targets. This could happen if the - * SDU has been time-stampped at the controller when received - * via HCI. - * - * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: - * 3.1 Time_Offset in framed PDUs : - * The Time_Offset shall be a positive value. - */ - if (!isoal_get_time_diff(tx_sdu->time_stamp, actual_grp_ref_point, &time_diff) || - time_diff == 0) { - /* Advance target to next event */ - actual_event++; - actual_grp_ref_point = isoal_get_wrapped_time_us(actual_grp_ref_point, - session->iso_interval * ISO_INT_UNIT_US); - - /* Set payload number */ - pp->payload_number = actual_event * session->burst_number; - } - /* Calculate the time offset */ - time_diff_valid = isoal_get_time_diff(tx_sdu->time_stamp, - actual_grp_ref_point, &time_diff); - LL_ASSERT(time_diff_valid); - LL_ASSERT(time_diff > 0); - /* Time difference must be less than the maximum possible - * time-offset of 24-bits. - */ - LL_ASSERT(time_diff <= 0x00FFFFFF); - time_offset = time_diff; + session->sn += sdus_skipped + 1; /* Store timing info for TX Sync command */ session->tx_time_stamp = actual_grp_ref_point; @@ -2292,6 +2455,10 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, /* Reset PDU fragmentation count for this SDU */ pp->pdu_cnt = 0; + + /* Update input packet number and time stamp */ + session->last_input_sn = tx_sdu->packet_sn; + session->last_input_time_stamp = tx_sdu->time_stamp; } /* PDUs should be created until the SDU fragment has been fragmented or if @@ -2305,6 +2472,7 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, err |= err_alloc; + ISOAL_LOG_DBGV("[%p] State %s", source, STATE_TO_STR(pp->pdu_state)); if (pp->pdu_state == BT_ISO_START) { /* Start of a new SDU. Segmentation header and time-offset * should be inserted. @@ -2366,15 +2534,13 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, /* Update complete flag in last segmentation header */ err |= isoal_update_seg_header_cmplt_length(source, end_of_sdu, consume_len); - /* LLID is fixed for framed PDUs */ - ll_id = PDU_BIS_LLID_FRAMED; - /* If there isn't sufficient usable space then release the * PDU when the end of the SDU is reached, instead of waiting * for the next SDU. */ bool release_pdu = end_of_sdu && (pp->pdu_available <= ISOAL_TX_SEGMENT_MIN_SIZE); - const isoal_status_t err_emit = isoal_tx_try_emit_pdu(source, release_pdu, ll_id); + const isoal_status_t err_emit = isoal_tx_try_emit_pdu(source, release_pdu, + PDU_BIS_LLID_FRAMED); err |= err_emit; @@ -2392,6 +2558,8 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, zero_length_sdu = false; } + pp->initialized = 1U; + return err; } @@ -2424,9 +2592,9 @@ static isoal_status_t isoal_tx_framed_event_prepare_handle(isoal_source_handle_t first_event_payload = (session->burst_number * event_count); last_event_payload = (session->burst_number * (event_count + 1ULL)) - 1ULL; - if (pp->pdu_available > 0 && - pp->payload_number <= last_event_payload) { + if (pp->pdu_allocated && pp->payload_number <= last_event_payload) { /* Pending PDU that should be released for framed TX */ + ISOAL_LOG_DBGV("[%p] Prepare PDU released.", source); err = isoal_tx_try_emit_pdu(source, true, PDU_BIS_LLID_FRAMED); } @@ -2462,6 +2630,7 @@ static isoal_status_t isoal_tx_framed_event_prepare_handle(isoal_source_handle_t if (release_padding) { while (!err && !err_alloc && (pp->payload_number < last_event_payload + 1ULL)) { + ISOAL_LOG_DBGV("[%p] Prepare padding PDU release.", source); err_alloc = isoal_tx_allocate_pdu(source, NULL); err = isoal_tx_try_emit_pdu(source, true, PDU_BIS_LLID_FRAMED); @@ -2473,6 +2642,7 @@ static isoal_status_t isoal_tx_framed_event_prepare_handle(isoal_source_handle_t if (pp->payload_number < last_event_payload + 1ULL) { pp->payload_number = last_event_payload + 1ULL; + ISOAL_LOG_DBGV("[%p] Prepare PL updated to %lu.", source, pp->payload_number); } return err; @@ -2500,7 +2670,7 @@ isoal_status_t isoal_tx_sdu_fragment(isoal_source_handle_t source_hdl, /* Set source context active to mutually exclude ISO Event prepare * kick. */ - source->context_active = true; + source->context_active = 1U; if (source->pdu_production.mode != ISOAL_PRODUCTION_MODE_DISABLED) { /* BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: @@ -2520,11 +2690,12 @@ isoal_status_t isoal_tx_sdu_fragment(isoal_source_handle_t source_hdl, } } - source->context_active = false; + source->context_active = 0U; if (source->timeout_trigger) { - source->timeout_trigger = false; + source->timeout_trigger = 0U; if (session->framed) { + ISOAL_LOG_DBGV("[%p] Prepare cb flag trigger", source); isoal_tx_framed_event_prepare_handle(source_hdl, source->timeout_event_count); } @@ -2599,13 +2770,14 @@ void isoal_tx_event_prepare(isoal_source_handle_t source_hdl, * is active. */ source->timeout_event_count = event_count; - source->timeout_trigger = true; + source->timeout_trigger = 1U; if (source->context_active) { return; } - source->timeout_trigger = false; + source->timeout_trigger = 0U; if (session->framed) { + ISOAL_LOG_DBGV("[%p] Prepare call back", source); isoal_tx_framed_event_prepare_handle(source_hdl, event_count); } } diff --git a/subsys/bluetooth/controller/ll_sw/isoal.h b/subsys/bluetooth/controller/ll_sw/isoal.h index 44f3504f1a6..cc69e4a5d53 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.h +++ b/subsys/bluetooth/controller/ll_sw/isoal.h @@ -376,8 +376,6 @@ struct isoal_source_session { uint8_t burst_number; uint8_t pdus_per_sdu; uint8_t max_pdu_size; - int32_t latency_unframed; - int32_t latency_framed; }; struct isoal_pdu_production { @@ -392,6 +390,8 @@ struct isoal_pdu_production { uint64_t seg_hdr_sc:1; uint64_t seg_hdr_length:8; uint64_t sdu_fragments:8; + uint64_t initialized:1; + uint64_t pdu_allocated:1; isoal_pdu_len_t pdu_written; isoal_pdu_len_t pdu_available; /* Location (byte index) of last segmentation header */ From 1fd74b1654859ac2f7c936a6b855667ef34184b2 Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Fri, 14 Jul 2023 16:57:37 +0200 Subject: [PATCH 0225/1623] [nrf fromtree] Bluetooth: controller: corrected time-offset for endianness Changes: -- Corrected reading and writing time offset in framed segment header to account for endianness -- Corrected bit positioning of time offset bit field in the segment header structure definition -- Fixed upstream Zephyr BSIM test build failure due to debug logging 39-bit variable Signed-off-by: Nirosharn Amarasinghe (cherry picked from commit 31df0ef80b50cad0cd28cac82888b49eaf80ee2b) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit e0122d75a70d7e584f0063d6554fde096e102e77) --- subsys/bluetooth/controller/ll_sw/isoal.c | 12 +++++++----- subsys/bluetooth/controller/ll_sw/pdu.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index 110a7aa901e..00bc40504f7 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -16,6 +16,8 @@ #include #include +#include + #include "util/memq.h" #include "hal/ccm.h" @@ -1158,7 +1160,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, case ISOAL_START: if (!sc) { /* Start segment, included time-offset */ - timeoffset = seg_hdr->timeoffset; + timeoffset = sys_le24_to_cpu(seg_hdr->timeoffset); anchorpoint = meta->timestamp; latency = session->sdu_sync_const; timestamp = isoal_get_wrapped_time_us(anchorpoint, @@ -1215,7 +1217,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, if (!sc) { /* Start segment, included time-offset */ - timeoffset = seg_hdr->timeoffset; + timeoffset = sys_le24_to_cpu(seg_hdr->timeoffset); anchorpoint = meta->timestamp; latency = session->sdu_sync_const; timestamp = isoal_get_wrapped_time_us(anchorpoint, @@ -1634,7 +1636,7 @@ static isoal_status_t isoal_tx_pdu_emit(const struct isoal_source *source_ctx, status = source_ctx->session.pdu_emit(node_tx, handle); ISOAL_LOG_DBG("[%p] PDU %llu err=%X len=%u frags=%u released", - source_ctx, node_tx->payload_count, status, + source_ctx, payload_number, status, produced_pdu->contents.pdu->len, sdu_fragments); if (status != ISOAL_STATUS_OK) { @@ -2479,7 +2481,7 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, */ err |= isoal_insert_seg_header_timeoffset(source, false, false, - time_offset); + sys_cpu_to_le24(time_offset)); pp->pdu_state = BT_ISO_CONT; } else if (!padding_pdu && pp->pdu_state == BT_ISO_CONT && pp->pdu_written == 0) { /* Continuing an SDU in a new PDU. Segmentation header @@ -2487,7 +2489,7 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, */ err |= isoal_insert_seg_header_timeoffset(source, true, false, - 0); + sys_cpu_to_le24(0)); } /* diff --git a/subsys/bluetooth/controller/ll_sw/pdu.h b/subsys/bluetooth/controller/ll_sw/pdu.h index ceeb9ca12e7..93e50e1ebcc 100644 --- a/subsys/bluetooth/controller/ll_sw/pdu.h +++ b/subsys/bluetooth/controller/ll_sw/pdu.h @@ -1018,8 +1018,8 @@ struct pdu_iso_sdu_sh { uint8_t len; /* Note, timeoffset only available in first segment of sdu */ - uint32_t payload:8; uint32_t timeoffset:24; + uint32_t payload:8; #endif /* CONFIG_LITTLE_ENDIAN */ } __packed; From 4ef38a538433f2ca8df60c605d4047f43f1a529b Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Tue, 18 Jul 2023 16:32:29 +0200 Subject: [PATCH 0226/1623] [nrf fromtree] Bluetooth: Controller: ISO-AL validation and selection of TX time stamps Intent is to pass Ellisys ISOAL quality tests for framed TX scenarios where the TX SDU includes a time stamp that is not based on the controller's clock. Changes: -- Include controller's reception time as a separate field in the TX SDU information -- Include decision on whether SDU time stamp is valid and based on the controller's clock -- Arbitrate and select / compute time stamp for the SDU Signed-off-by: Nirosharn Amarasinghe (cherry picked from commit d414cab87a87c63a70266a83256a77ae6abaa052) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 9c58cfc07250e5803e4920ac8e30bbba46fe445a) --- subsys/bluetooth/controller/hci/hci.c | 14 +- subsys/bluetooth/controller/ll_sw/isoal.c | 212 +++++++++++++++----- subsys/bluetooth/controller/ll_sw/isoal.h | 2 + subsys/bluetooth/controller/ll_sw/ull_iso.c | 3 +- 4 files changed, 176 insertions(+), 55 deletions(-) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 9ca905c44e0..30fb363fc9c 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -5700,17 +5700,21 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) * -- A captured time stamp of the SDU * -- A time stamp provided by the higher layer * -- A computed time stamp based on a sequence counter provided by the - * higher layer (Not implemented) - * -- Any other method of determining Time_Offset (Not implemented) + * higher layer + * -- Any other method of determining Time_Offset + * (Uses a timestamp computed from the difference in provided + * timestamps, if the timestamp is deemed not based on the + * controller's clock) */ + sdu_frag_tx.cntr_time_stamp = HAL_TICKER_TICKS_TO_US(ticker_ticks_now_get()); if (ts_flag) { - /* Overwrite time stamp with HCI provided time stamp */ + /* Use HCI provided time stamp */ time_stamp = net_buf_pull_mem(buf, sizeof(*time_stamp)); len -= sizeof(*time_stamp); sdu_frag_tx.time_stamp = sys_le32_to_cpu(*time_stamp); } else { - sdu_frag_tx.time_stamp = - HAL_TICKER_TICKS_TO_US(ticker_ticks_now_get()); + /* Use controller's capture time */ + sdu_frag_tx.time_stamp = sdu_frag_tx.cntr_time_stamp; } /* Extract ISO data header if included (PB_Flag 0b00 or 0b10) */ diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index 00bc40504f7..d4cc61cea6c 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -1282,7 +1282,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, } /* Update next state */ - ISOAL_LOG_DBGV("[%p] Decoding: Next State %s", sink, FSM_TO_STR(next_state)); + ISOAL_LOG_DBGV("[%p] FSM Next State %s", sink, FSM_TO_STR(next_state)); sp->fsm = next_state; /* Find next segment header, set to null if past end of PDU */ @@ -1350,7 +1350,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, if (error_sdu_pending) { sp->sdu_status = next_sdu_status; - err |= isoal_rx_append_to_sdu(sink, pdu_meta, 0, 0, true, false); + err |= isoal_rx_append_to_sdu(sink, pdu_meta, 0U, 0U, true, false); } break; @@ -1373,8 +1373,8 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, } /* Update next state */ - ISOAL_LOG_DBGV("[%p] Error: Next State %s", sink, FSM_TO_STR(next_state)); - sink->sdu_production.fsm = next_state; + ISOAL_LOG_DBGV("[%p] FSM Error Next State %s", sink, FSM_TO_STR(next_state)); + sp->fsm = next_state; } sp->prev_pdu_id = meta->payload_number; @@ -1591,6 +1591,46 @@ void isoal_source_destroy(isoal_source_handle_t hdl) isoal_source_deallocate(hdl); } +static bool isoal_is_time_stamp_valid(const struct isoal_source *source_ctx, + const uint32_t cntr_time, + const uint32_t time_stamp) +{ + const struct isoal_source_session *session; + uint32_t time_diff; + + session = &source_ctx->session; + + /* This is an arbitrarily defined range. The purpose is to + * decide if the time stamp provided by the host is sensible + * within the controller's clock domain. An SDU interval plus ISO + * interval is expected to provide a good balance between situations + * where either could be significantly larger than the other. + * + * BT Core V5.4 : Vol 6 Low Energy Controller : Part G IS0-AL: + * 3.3 Time Stamp for SDU : + * When an HCI ISO Data packet sent by the Host does not contain + * a Time Stamp or the Time_Stamp value is not based on the + * Controller's clock, the Controller should determine the CIS + * or BIS event to be used to transmit the SDU contained in that + * packet based on the time of arrival of that packet. + */ + const uint32_t sdu_interval_us = session->sdu_interval; + const uint32_t iso_interval_us = session->iso_interval * ISO_INT_UNIT_US; + /* ISO Interval 0x0000_0004 ~ 0x0000_0C80 x 1250 + + * SDU Interval 0x0000_00FF ~ 0x000F_FFFF <= 004D_08FF + */ + const int32_t time_stamp_valid_half_range = sdu_interval_us + iso_interval_us; + const uint32_t time_stamp_valid_min = isoal_get_wrapped_time_us(cntr_time, + (-time_stamp_valid_half_range)); + const uint32_t time_stamp_valid_range = 2 * time_stamp_valid_half_range; + const bool time_stamp_is_valid = isoal_get_time_diff(time_stamp_valid_min, + time_stamp, + &time_diff) && + time_diff <= time_stamp_valid_range; + + return time_stamp_is_valid; +} + /** * Queue the PDU in production in the relevant LL transmit queue. If the * attmept to release the PDU fails, the buffer linked to the PDU will be released @@ -1636,8 +1676,8 @@ static isoal_status_t isoal_tx_pdu_emit(const struct isoal_source *source_ctx, status = source_ctx->session.pdu_emit(node_tx, handle); ISOAL_LOG_DBG("[%p] PDU %llu err=%X len=%u frags=%u released", - source_ctx, payload_number, status, - produced_pdu->contents.pdu->len, sdu_fragments); + source_ctx, payload_number, status, + produced_pdu->contents.pdu->len, sdu_fragments); if (status != ISOAL_STATUS_OK) { /* If it fails, the node will be released and no further attempt @@ -1841,8 +1881,8 @@ uint16_t isoal_tx_unframed_get_next_payload_number(isoal_source_handle_t source_ * @brief Fragment received SDU and produce unframed PDUs * @details Destination source may have an already partially built PDU * - * @param source_hdl[in] Destination source handle - * @param tx_sdu[in] SDU with packet boundary information + * @param[in] source_hdl Destination source handle + * @param[in] tx_sdu SDU with packet boundary information * * @return Status * @@ -2162,7 +2202,7 @@ static isoal_status_t isoal_insert_seg_header_timeoffset(struct isoal_source *so pp->pdu_available -= write_size; ISOAL_LOG_DBGV("[%p] Seg header write size=%u sc=%u cmplt=%u TO=%u len=%u", - source, write_size, sc, cmplt, time_offset, seg_hdr.len); + source, write_size, sc, cmplt, time_offset, seg_hdr.len); return err; } @@ -2203,46 +2243,48 @@ static isoal_status_t isoal_update_seg_header_cmplt_length(struct isoal_source * PDU_ISO_SEG_HDR_SIZE); ISOAL_LOG_DBGV("[%p] Seg header write size=%u sc=%u cmplt=%u len=%u", - source, PDU_ISO_SEG_HDR_SIZE, seg_hdr.sc, cmplt, seg_hdr.len); + source, PDU_ISO_SEG_HDR_SIZE, seg_hdr.sc, cmplt, seg_hdr.len); } /** * Find the earliest feasible event for transmission capacity is not wasted and * return information based on that event. - * @param[in] source_hdl Destination source handle + * + * @param[in] *source_ctx Destination source context * @param[in] tx_sdu SDU with meta data information * @param[out] payload_number Updated payload number for the selected event * @param[out] grp_ref_point Group reference point for the selected event * @param[out] time_offset Segmentation Time offset to selected event * @return The number SDUs skipped from the last */ -static uint16_t isoal_tx_framed_find_correct_tx_event(isoal_source_handle_t source_hdl, +static uint16_t isoal_tx_framed_find_correct_tx_event(const struct isoal_source *source_ctx, const struct isoal_sdu_tx *tx_sdu, uint64_t *payload_number, uint32_t *grp_ref_point, uint32_t *time_offset) { - struct isoal_source_session *session; - struct isoal_pdu_production *pp; + const struct isoal_source_session *session; + const struct isoal_pdu_production *pp; uint32_t actual_grp_ref_point; uint64_t next_payload_number; - struct isoal_source *source; uint16_t sdus_skipped; uint64_t actual_event; bool time_diff_valid; uint32_t time_diff; + uint32_t time_stamp_selected; - source = &isoal_global.source_state[source_hdl]; - session = &source->session; - pp = &source->pdu_production; + session = &source_ctx->session; + pp = &source_ctx->pdu_production; - sdus_skipped = 0; + sdus_skipped = 0U; + time_diff = 0U; /* Continue with the current payload unless there is need to change */ next_payload_number = pp->payload_number; actual_event = pp->payload_number / session->burst_number; - ISOAL_LOG_DBGV("[%p] Start PL=%llu Evt=%lu.", source, next_payload_number, actual_event); + ISOAL_LOG_DBGV("[%p] Start PL=%llu Evt=%lu.", source_ctx, next_payload_number, + actual_event); /* Get the drift updated group reference point for this event based on * the actual event being set. This might introduce some errors as the @@ -2259,29 +2301,35 @@ static uint16_t isoal_tx_framed_find_correct_tx_event(isoal_source_handle_t sour } ISOAL_LOG_DBGV("[%p] Current PL=%llu Evt=%llu Ref=%lu", - source, next_payload_number, actual_event, actual_grp_ref_point); + source_ctx, next_payload_number, actual_event, actual_grp_ref_point); if (tx_sdu->sdu_state == BT_ISO_START || tx_sdu->sdu_state == BT_ISO_SINGLE) { /* Start of a new SDU */ + const bool time_stamp_is_valid = isoal_is_time_stamp_valid(source_ctx, + tx_sdu->cntr_time_stamp, + tx_sdu->time_stamp); + /* Adjust payload number */ if (pp->initialized) { /* Not the first SDU in this session, so reference * information should be valid. . */ + time_diff_valid = isoal_get_time_diff(session->last_input_time_stamp, tx_sdu->time_stamp, &time_diff); /* Priority is given to the sequence number */ if (tx_sdu->packet_sn > session->last_input_sn + 1) { - ISOAL_LOG_DBGV("[%p] Using packet_sn for skipped SDUs", source); + ISOAL_LOG_DBGV("[%p] Using packet_sn for skipped SDUs", source_ctx); sdus_skipped = (tx_sdu->packet_sn - session->last_input_sn) - 1; } else if (tx_sdu->packet_sn == session->last_input_sn && - time_diff_valid && time_diff > session->sdu_interval) { - ISOAL_LOG_DBGV("[%p] Using time_stamp for skipped SDUs", source); + time_diff_valid && time_diff > session->sdu_interval) { + ISOAL_LOG_DBGV("[%p] Using time_stamp for skipped SDUs", + source_ctx); /* Round at mid-point */ sdus_skipped = ((time_diff + (session->sdu_interval / 2)) / session->sdu_interval) - 1; @@ -2289,12 +2337,58 @@ static uint16_t isoal_tx_framed_find_correct_tx_event(isoal_source_handle_t sour /* SDU is next in sequence */ } + if (time_stamp_is_valid) { + /* Use provided time stamp for time offset + * calcutation + */ + time_stamp_selected = tx_sdu->time_stamp; + ISOAL_LOG_DBGV("[%p] Selecting Time Stamp (%lu) from SDU", + source_ctx, time_stamp_selected); + } else if (time_diff_valid) { + /* Project a time stamp based on the last time + * stamp and the difference in input time stamps + */ + time_stamp_selected = isoal_get_wrapped_time_us( + session->tx_time_stamp, + time_diff - session->tx_time_offset); + ISOAL_LOG_DBGV("[%p] Projecting Time Stamp (%lu) from SDU delta", + source_ctx, time_stamp_selected); + } else { + /* Project a time stamp based on the last time + * stamp and the number of skipped SDUs + */ + time_stamp_selected = isoal_get_wrapped_time_us( + session->tx_time_stamp, + ((sdus_skipped + 1) * session->sdu_interval) + - session->tx_time_offset); + ISOAL_LOG_DBGV("[%p] Projecting Time Stamp (%lu) from skipped SDUs", + source_ctx, time_stamp_selected); + } + } else { /* First SDU, align with target event */ - actual_event = tx_sdu->target_event; - actual_grp_ref_point = tx_sdu->grp_ref_point; + if (actual_event < tx_sdu->target_event) { + actual_event = tx_sdu->target_event; + actual_grp_ref_point = tx_sdu->grp_ref_point; + } - ISOAL_LOG_DBGV("[%p] Use target_event", source); + ISOAL_LOG_DBGV("[%p] Use target_event", source_ctx); + + if (time_stamp_is_valid) { + /* Time stamp is within valid range - + * use provided time stamp + */ + time_stamp_selected = tx_sdu->time_stamp; + ISOAL_LOG_DBGV("[%p] Selecting Time Stamp (%lu) from SDU", + source_ctx, time_stamp_selected); + } else { + /* Time stamp is out of range - + * use controller's capture time + */ + time_stamp_selected = tx_sdu->cntr_time_stamp; + ISOAL_LOG_DBGV("[%p] Selecting Time Stamp (%lu) from controller", + source_ctx, time_stamp_selected); + } } /* Selecting the event for transmission is done solely based on @@ -2309,8 +2403,8 @@ static uint16_t isoal_tx_framed_find_correct_tx_event(isoal_source_handle_t sour * 3.1 Time_Offset in framed PDUs : * The Time_Offset shall be a positive value. */ - while (!isoal_get_time_diff(tx_sdu->time_stamp, actual_grp_ref_point, &time_diff) || - time_diff == 0) { + while (!isoal_get_time_diff(time_stamp_selected, actual_grp_ref_point, &time_diff) + || time_diff == 0) { /* Advance target to next event */ actual_event++; actual_grp_ref_point = isoal_get_wrapped_time_us(actual_grp_ref_point, @@ -2318,8 +2412,8 @@ static uint16_t isoal_tx_framed_find_correct_tx_event(isoal_source_handle_t sour } ISOAL_LOG_DBGV("[%p] Chosen PL=%llu Evt=%llu Ref=%lu", - source, (actual_event * session->burst_number), actual_event, - actual_grp_ref_point); + source_ctx, (actual_event * session->burst_number), actual_event, + actual_grp_ref_point); /* If the event selected is the last event segmented for, then * it is possible that that some payloads have already been @@ -2327,23 +2421,23 @@ static uint16_t isoal_tx_framed_find_correct_tx_event(isoal_source_handle_t sour * that payload. */ next_payload_number = MAX(pp->payload_number, - (actual_event * session->burst_number)); - } + (actual_event * session->burst_number)); - ISOAL_LOG_DBGV("[%p] Final Evt=%llu (PL=%llu) Ref.=%lu Next PL=%llu", - source, actual_event, (actual_event * session->burst_number), - actual_grp_ref_point, next_payload_number); + ISOAL_LOG_DBGV("[%p] Final Evt=%llu (PL=%llu) Ref.=%lu Next PL=%llu", + source, actual_event, (actual_event * session->burst_number), + actual_grp_ref_point, next_payload_number); - /* Calculate the time offset */ - time_diff_valid = isoal_get_time_diff(tx_sdu->time_stamp, - actual_grp_ref_point, &time_diff); + /* Calculate the time offset */ + time_diff_valid = isoal_get_time_diff(time_stamp_selected, + actual_grp_ref_point, &time_diff); - LL_ASSERT(time_diff_valid); - LL_ASSERT(time_diff > 0); - /* Time difference must be less than the maximum possible - * time-offset of 24-bits. - */ - LL_ASSERT(time_diff <= 0x00FFFFFF); + LL_ASSERT(time_diff_valid); + LL_ASSERT(time_diff > 0); + /* Time difference must be less than the maximum possible + * time-offset of 24-bits. + */ + LL_ASSERT(time_diff <= 0x00FFFFFF); + } *payload_number = next_payload_number; *grp_ref_point = actual_grp_ref_point; @@ -2389,19 +2483,24 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, tx_sdu->sdu_state == BT_ISO_SINGLE); ISOAL_LOG_DBGV("[%p] SDU %u len=%u TS=%lu Ref=%lu Evt=%llu Frag=%u", - source, tx_sdu->packet_sn, tx_sdu->iso_sdu_length, tx_sdu->time_stamp, - tx_sdu->grp_ref_point, tx_sdu->target_event, tx_sdu->sdu_state); + source, tx_sdu->packet_sn, tx_sdu->iso_sdu_length, tx_sdu->time_stamp, + tx_sdu->grp_ref_point, tx_sdu->target_event, tx_sdu->sdu_state); if (tx_sdu->sdu_state == BT_ISO_START || tx_sdu->sdu_state == BT_ISO_SINGLE) { uint32_t actual_grp_ref_point; uint64_t next_payload_number; uint16_t sdus_skipped; + bool time_diff_valid; + uint32_t time_diff; /* Start of a new SDU */ + time_diff_valid = isoal_get_time_diff(session->last_input_time_stamp, + tx_sdu->time_stamp, + &time_diff); /* Find the best transmission event */ - sdus_skipped = isoal_tx_framed_find_correct_tx_event(source_hdl, tx_sdu, + sdus_skipped = isoal_tx_framed_find_correct_tx_event(source, tx_sdu, &next_payload_number, &actual_grp_ref_point, &time_offset); @@ -2460,7 +2559,22 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, /* Update input packet number and time stamp */ session->last_input_sn = tx_sdu->packet_sn; - session->last_input_time_stamp = tx_sdu->time_stamp; + + if (pp->initialized && tx_sdu->time_stamp == tx_sdu->cntr_time_stamp && + (!time_diff_valid || time_diff < session->sdu_interval)) { + /* If the time-stamp is invalid or the difference is + * less than an SDU interval, then set the reference + * time stamp to what should have been received. This is + * done to avoid incorrectly detecting a gap in time + * stamp inputs should there be a burst of SDUs + * clustered together. + */ + session->last_input_time_stamp = isoal_get_wrapped_time_us( + session->last_input_time_stamp, + session->sdu_interval); + } else { + session->last_input_time_stamp = tx_sdu->time_stamp; + } } /* PDUs should be created until the SDU fragment has been fragmented or if diff --git a/subsys/bluetooth/controller/ll_sw/isoal.h b/subsys/bluetooth/controller/ll_sw/isoal.h index cc69e4a5d53..61d3773c43d 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.h +++ b/subsys/bluetooth/controller/ll_sw/isoal.h @@ -189,6 +189,8 @@ struct isoal_sdu_tx { uint16_t iso_sdu_length; /** Time stamp from HCI or vendor specific path (us) */ uint32_t time_stamp; + /** Capture time stamp from controller (us) */ + uint32_t cntr_time_stamp; /** CIG Reference of target event (us, compensated for drift) */ uint32_t grp_ref_point; /** Target Event of SDU */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_iso.c b/subsys/bluetooth/controller/ll_sw/ull_iso.c index 1520bd76963..70d018e7e0c 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_iso.c @@ -1058,7 +1058,8 @@ void ll_iso_transmit_test_send_sdu(uint16_t handle, uint32_t ticks_at_expire) /* Send all SDU fragments */ do { - sdu.time_stamp = HAL_TICKER_TICKS_TO_US(ticks_at_expire); + sdu.cntr_time_stamp = HAL_TICKER_TICKS_TO_US(ticks_at_expire); + sdu.time_stamp = sdu.cntr_time_stamp; sdu.size = MIN(remaining_tx, ISO_TEST_TX_BUFFER_SIZE); memset(tx_buffer, 0, sdu.size); From 85f3925dbeea3ffb867ae802773eca323c096322 Mon Sep 17 00:00:00 2001 From: Erik Brockhoff Date: Thu, 10 Aug 2023 14:44:59 +0200 Subject: [PATCH 0227/1623] [nrf fromtree] Bluetooth: controller: disregard length field on pdu error In case of unframed iso rx, length field cannot be trusted in case of PDU error. Signed-off-by: Erik Brockhoff (cherry picked from commit 365a56ce87fa91eb3a059f0353a450c4408d0bf4) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit aff4981928a83b16a7c1b29f995d06e88b90d813) --- subsys/bluetooth/controller/ll_sw/isoal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index d4cc61cea6c..6c1dedd7b9d 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -738,7 +738,7 @@ static isoal_status_t isoal_rx_unframed_consume(struct isoal_sink *sink, /* If status is not ISOAL_PDU_STATUS_VALID, length and LLID cannot be trusted */ llid = pdu->ll_id; pdu_err = (pdu_meta->meta->status != ISOAL_PDU_STATUS_VALID); - length = pdu->len; + length = pdu_err ? 0U : pdu->len; /* A zero length PDU with LLID 0b01 (PDU_BIS_LLID_START_CONTINUE) would be a padding PDU. * However if there are errors in the PDU, it could be an incorrectly receive non-padding * PDU. Therefore only consider a PDU with errors as padding if received after the end From c88e67bb9ad3655d3a5bab013518bf11950eda92 Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Fri, 8 Sep 2023 16:37:40 +0200 Subject: [PATCH 0228/1623] [nrf fromtree] Bluetooth: controller: Included kconfigs for ISO-AL logging Included kconfigs to set the ISO-AL logging level and control debug logging verbosity. Signed-off-by: Nirosharn Amarasinghe (cherry picked from commit b96436296fc593329325a03689896d73193a1589) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 5951daa0dff93f4b59f8478e46f26a830f41d21e) --- subsys/bluetooth/Kconfig.logging | 17 +++++++++++++++++ subsys/bluetooth/controller/Kconfig | 7 +++++++ subsys/bluetooth/controller/ll_sw/isoal.c | 6 +++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/Kconfig.logging b/subsys/bluetooth/Kconfig.logging index 67a18afa919..addf8eb65fe 100644 --- a/subsys/bluetooth/Kconfig.logging +++ b/subsys/bluetooth/Kconfig.logging @@ -398,6 +398,16 @@ config BT_DEBUG_SERVICE This option enables debug support for the Bluetooth Services. +# CONTROLLER (subsys/bluetooth/controller/Kconfig) + +config BT_CTLR_DEBUG_ISOAL + bool "[DEPRECATED] Bluetooth ISO-AL debug" + select DEPRECATED + depends on BT_CTLR_ISO + help + This option enables debug support for the Bluetooth ISO-AL. + + endmenu # [DEPRECATED] Others menu "[DEPRECATED] BR/EDR" @@ -900,6 +910,13 @@ legacy-debug-sym = BT_DEBUG_SERVICE module-str = "Bluetooth Services" source "subsys/bluetooth/common/Kconfig.template.log_config_bt" +# CONTROLLER (subsys/bluetooth/controller/Kconfig) + +module = BT_CTLR_ISOAL +legacy-debug-sym = BT_CTLR_DEBUG_ISOAL +module-str = "Bluetooth Controller ISO-AL" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + endmenu # Others menu "BR/EDR" diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 51890bf51ed..467683705f3 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -207,6 +207,13 @@ config BT_CTLR_ISO_TX_BUFFER_SIZE Size of the Isochronous Tx buffers and the value returned in HCI LE Read Buffer Size V2 command response. +config BT_CTLR_ISOAL_LOG_DBG_VERBOSE + bool "ISO-AL verbose debug logging" + depends on BT_CTLR_ISOAL_LOG_LEVEL = 4 + default n + help + Use this option to enable ISO-AL verbose debug logging. + config BT_CTLR_ISOAL_SOURCES int "Number of Isochronous Adaptation Layer sources" depends on BT_CTLR_ADV_ISO || BT_CTLR_CONN_ISO diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index 6c1dedd7b9d..d43233f0289 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -36,15 +36,15 @@ #include -LOG_MODULE_REGISTER(bt_ctlr_isoal, LOG_LEVEL_INF); +LOG_MODULE_REGISTER(bt_ctlr_isoal, CONFIG_BT_CTLR_ISOAL_LOG_LEVEL); #define ISOAL_LOG_DBG(...) LOG_DBG(__VA_ARGS__) -#if defined(ISOAL_DEBUG_VERBOSE) +#if defined(CONFIG_BT_CTLR_ISOAL_LOG_DBG_VERBOSE) #define ISOAL_LOG_DBGV(...) LOG_DBG(__VA_ARGS__) #else #define ISOAL_LOG_DBGV(...) (void) 0 -#endif /* ISOAL_DEBUG_VERBOSE */ +#endif /* CONFIG_BT_CTLR_ISOAL_LOG_DBG_VERBOSE */ #include "hal/debug.h" From 3d9d12428797dd3d53f0d772c611be6e54cb934f Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sun, 17 Sep 2023 21:35:58 +0200 Subject: [PATCH 0229/1623] [nrf fromtree] Bluetooth: Controller: Fix ticker to prefer ticker node started Fix ticker implementation to prefer to keep ticker node started in case of race condition to start and stop. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit f4e05e3e5426b492b34073dd2acde0b164736f97) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 31efdfbf33f9cd2705f4ee7eee3c2f06523eade7) --- .../bluetooth/controller/Kconfig.ll_sw_split | 17 +++++ subsys/bluetooth/controller/ticker/ticker.c | 12 +++- tests/bluetooth/init/prj_ctlr_ticker.conf | 65 +++++++++++++++++++ tests/bluetooth/init/testcase.yaml | 9 +++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 tests/bluetooth/init/prj_ctlr_ticker.conf diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 910c3819f0c..5fb2c54d085 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -55,6 +55,8 @@ config BT_LLL_VENDOR_NORDIC select BT_TICKER_REMAINDER_GET if BT_BROADCASTER && BT_CTLR_ADV_EXT select BT_TICKER_LAZY_GET if BT_CTLR_ADV_PERIODIC || BT_CTLR_CENTRAL_ISO + select BT_TICKER_PREFER_START_BEFORE_STOP if BT_TICKER_SLOT_AGNOSTIC + default y help Use Nordic Lower Link Layer implementation. @@ -1036,6 +1038,21 @@ config BT_TICKER_SLOT_AGNOSTIC reservations and collision handling, and operates as a simple multi-instance programmable timer. +config BT_TICKER_PREFER_START_BEFORE_STOP + bool "Ticker prefer start before stop request" + help + Under race conditions wherein for a given ticker node if a number of + start and stop operations are enqueued towards ticker_job by a said + user execution context, then start operations is preferred to be + processed before stop operations. + + Without this option, the default behavior is to defer all start + requests after all stop requests enqueued by all user context having + been processed. The rationale for default behavior being that under + race conditions, start followed by stop requests, or start before stop + requests, the said ticker node is always scheduled and at timeout the + execution context can take decision based on its execution state. + config BT_CTLR_JIT_SCHEDULING bool "Just-in-Time Scheduling" select BT_TICKER_SLOT_AGNOSTIC diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index ead148e85ba..e5c89dca905 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -55,9 +55,11 @@ struct ticker_node { uint8_t force:1; /* If non-zero, node timeout should * be forced at next expiration */ +#if defined(CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP) uint8_t start_pending:1; /* If non-zero, start is pending for * bottom half of ticker_job. */ +#endif /* CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP */ uint32_t ticks_periodic; /* If non-zero, interval * between expirations */ @@ -1907,12 +1909,15 @@ static inline uint8_t ticker_job_list_manage(struct ticker_instance *instance, /* if op is start, then skip update and stop ops */ if (user_op->op < TICKER_USER_OP_TYPE_UPDATE) { +#if defined(CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP) if (user_op->op == TICKER_USER_OP_TYPE_START) { /* Set start pending to validate a * successive, inline stop operation. */ ticker->start_pending = 1U; } +#endif /* CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP */ + continue; } @@ -1923,7 +1928,10 @@ static inline uint8_t ticker_job_list_manage(struct ticker_instance *instance, * set status and continue. */ if ((user_op->op > TICKER_USER_OP_TYPE_STOP_ABS) || - (((state == 0U) && !ticker->start_pending) && + ((state == 0U) && +#if defined(CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP) + !ticker->start_pending && +#endif /* CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP */ (user_op->op != TICKER_USER_OP_TYPE_YIELD_ABS)) || ((user_op->op == TICKER_USER_OP_TYPE_UPDATE) && (user_op->params.update.ticks_drift_plus == 0U) && @@ -2731,7 +2739,9 @@ static inline void ticker_job_list_insert(struct ticker_instance *instance, continue; } +#if defined(CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP) ticker->start_pending = 0U; +#endif /* CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP */ if (((ticker->req - ticker->ack) & 0xff) != 0U) { diff --git a/tests/bluetooth/init/prj_ctlr_ticker.conf b/tests/bluetooth/init/prj_ctlr_ticker.conf new file mode 100644 index 00000000000..d77f519406b --- /dev/null +++ b/tests/bluetooth/init/prj_ctlr_ticker.conf @@ -0,0 +1,65 @@ +CONFIG_BT=y +CONFIG_BT_CTLR=y +CONFIG_BT_LL_SW_SPLIT=y +CONFIG_BT_CTLR_DUP_FILTER_LEN=16 +CONFIG_BT_CTLR_CONN_PARAM_REQ=y +CONFIG_BT_CTLR_LE_PING=y +CONFIG_BT_CTLR_PRIVACY=n +CONFIG_BT_CTLR_EXT_SCAN_FP=n +CONFIG_BT_DATA_LEN_UPDATE=n +CONFIG_BT_PHY_UPDATE=y +CONFIG_BT_CTLR_CHAN_SEL_2=y +CONFIG_BT_CTLR_MIN_USED_CHAN=y +CONFIG_BT_CTLR_ADV_EXT=y +CONFIG_BT_CTLR_DTM_HCI=y +CONFIG_BT_CTLR_ADVANCED_FEATURES=y +CONFIG_BT_CTLR_PHY_2M=y +CONFIG_BT_CTLR_PHY_2M_NRF=y +CONFIG_BT_CTLR_PHY_CODED=y +CONFIG_BT_CTLR_ADV_AUX_PDU_BACK2BACK=y +CONFIG_BT_CTLR_LLL_PRIO=0 +CONFIG_BT_CTLR_ULL_HIGH_PRIO=1 +CONFIG_BT_CTLR_XTAL_ADVANCED=n +CONFIG_BT_CTLR_SCHED_ADVANCED=n +CONFIG_BT_CTLR_RADIO_ENABLE_FAST=y +CONFIG_BT_CTLR_TIFS_HW=n +CONFIG_BT_CTLR_FAST_ENC=y +CONFIG_BT_CTLR_TX_RETRY_DISABLE=y +CONFIG_BT_CTLR_CONN_RSSI=y +CONFIG_BT_CTLR_ADV_INDICATION=y +CONFIG_BT_CTLR_SCAN_REQ_NOTIFY=y +CONFIG_BT_CTLR_SCAN_REQ_RSSI=y +CONFIG_BT_CTLR_SCAN_INDICATION=y +CONFIG_BT_CTLR_PROFILE_ISR=y +CONFIG_BT_CTLR_DEBUG_PINS=y +CONFIG_BT_CTLR_TEST=y +CONFIG_BT_TICKER_EXT=n +CONFIG_BT_TICKER_SLOT_AGNOSTIC=y +CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP=y +CONFIG_BT_HCI_VS_EXT=y +CONFIG_BT_HCI_MESH_EXT=n +CONFIG_BT_PERIPHERAL=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_SMP=y +CONFIG_BT_SIGNING=y +CONFIG_BT_SMP_SC_ONLY=y +CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_USE_DEBUG_KEYS=y +CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y +CONFIG_BT_GATT_CLIENT=y +CONFIG_BT_DEBUG_MONITOR_UART=y +CONFIG_BT_HCI_CORE_LOG_LEVEL_DBG=y +CONFIG_BT_CONN_LOG_LEVEL_DBG=y +CONFIG_BT_KEYS_LOG_LEVEL_DBG=y +CONFIG_BT_L2CAP_LOG_LEVEL_DBG=y +CONFIG_BT_SMP_LOG_LEVEL_DBG=y +CONFIG_BT_HCI_DRIVER_LOG_LEVEL_DBG=y +CONFIG_BT_SMP_SELFTEST=y +CONFIG_BT_ATT_LOG_LEVEL_DBG=y +CONFIG_BT_GATT_LOG_LEVEL_DBG=y +CONFIG_BT_BREDR=n +CONFIG_DEBUG=y +CONFIG_FLASH=y +CONFIG_SOC_FLASH_NRF_RADIO_SYNC_TICKER=n +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/bluetooth/init/testcase.yaml b/tests/bluetooth/init/testcase.yaml index 4c252115178..fa30920dc1e 100644 --- a/tests/bluetooth/init/testcase.yaml +++ b/tests/bluetooth/init/testcase.yaml @@ -122,6 +122,15 @@ tests: integration_platforms: - nrf52840dk_nrf52840 - nrf52dk_nrf52832 + bluetooth.init.test_ctlr_ticker: + extra_args: + - CONF_FILE=prj_ctlr_ticker.conf + platform_allow: + - nrf52840dk_nrf52840 + - nrf52dk_nrf52832 + integration_platforms: + - nrf52840dk_nrf52840 + - nrf52dk_nrf52832 bluetooth.init.test_ctlr_broadcaster: extra_args: CONF_FILE=prj_ctlr_broadcaster.conf platform_allow: From 8246e66a8ecaa438b87a025d7d02312ad239a0ce Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Mon, 18 Sep 2023 09:00:14 +0200 Subject: [PATCH 0230/1623] [nrf fromtree] Bluetooth: Controller: Fix order of preempt timeout requested flag Fix the order of setting the flag that indicates that preempt timeout has been successfully requested versus the request is waiting to be scheduled. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 4cefcb6fc7917a44c51cb4c16e06daefcd8d9ca2) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 439362352fdc840063b04b90da531970da11d445) --- .../controller/ll_sw/nordic/lll/lll.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index 1f8031a7c07..fe0a031d402 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -835,11 +835,17 @@ static void ticker_start_op_cb(uint32_t status, void *param) ARG_UNUSED(param); LL_ASSERT(status == TICKER_STATUS_SUCCESS); - LL_ASSERT(preempt_start_req != preempt_start_ack); - preempt_start_ack++; - + /* Increase preempt requested count before acknowledging that the + * ticker start operation for the preempt timeout has been handled. + */ LL_ASSERT(preempt_req == preempt_ack); preempt_req++; + + /* Increase preempt start ack count, to acknowledge that the ticker + * start operation has been handled. + */ + LL_ASSERT(preempt_start_req != preempt_start_ack); + preempt_start_ack++; } static uint32_t preempt_ticker_start(struct lll_event *first, @@ -854,7 +860,11 @@ static uint32_t preempt_ticker_start(struct lll_event *first, uint32_t preempt_to; uint32_t ret; - /* Do not request to start preempt timeout if already requested */ + /* Do not request to start preempt timeout if already requested. + * + * Check if there is pending preempt timeout start requested or if + * preempt timeout ticker has already been scheduled. + */ if ((preempt_start_req != preempt_start_ack) || (preempt_req != preempt_ack)) { uint32_t diff; From 4af51708076cf561df2c53eb8154f39426100718 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 19 Sep 2023 14:16:41 +0200 Subject: [PATCH 0231/1623] [nrf fromtree] Bluetooth: Controller: Fix LE Set Ext Adv Param Cmd invalid status Fix HCI LE Set Extended Advertising Parameter Command invalid status reason. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 879c611f58c2af8ed26af4cbb54a96ca42f52ad9) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit ae5d8e2eec5ee1b744f1b2d74a6220e4fcbd5ca8) --- subsys/bluetooth/controller/ll_sw/ull_adv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index d7d5b23f63e..b5595e5e9c2 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -690,7 +690,7 @@ uint8_t ll_adv_params_set(uint16_t interval, uint8_t adv_type, lll_adv_data_reset(&adv->lll.scan_rsp); err = lll_adv_aux_data_init(&adv->lll.scan_rsp); if (err) { - return err; + return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; } pdu = lll_adv_scan_rsp_peek(&adv->lll); @@ -710,7 +710,7 @@ uint8_t ll_adv_params_set(uint16_t interval, uint8_t adv_type, lll_adv_data_reset(&adv->lll.scan_rsp); err = lll_adv_data_init(&adv->lll.scan_rsp); if (err) { - return err; + return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; } pdu = lll_adv_scan_rsp_peek(&adv->lll); @@ -926,7 +926,7 @@ uint8_t ll_adv_enable(uint8_t enable) err = lll_adv_data_init(&adv->lll.scan_rsp); if (err) { - return err; + return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; } pdu_scan = lll_adv_scan_rsp_peek(lll); @@ -1873,7 +1873,7 @@ uint8_t ull_scan_rsp_set(struct ll_adv_set *adv, uint8_t len, err = lll_adv_data_init(&adv->lll.scan_rsp); if (err) { - return err; + return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; } prev = lll_adv_scan_rsp_peek(&adv->lll); From 1d6f3410fd50fe1b4920a95c3928f2e77e77c37d Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 1 Sep 2023 05:11:50 +0200 Subject: [PATCH 0232/1623] [nrf fromtree] Revert "Bluetooth: Controller: Fix ull_prepare_dequeue for skipped events" These change are reverted as part of fixing regression failure in LL/DDI/SCN/BV-21-C and LL/DDI/SCN/BV-25-C. This reverts commit 0d54ca876168b7d5d28219af3f3f1a247da49209. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 91781306e95c28ca9b96fff242e342acb86edf11) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 69d2075b285425dedd0b399bcce008494e03c4ba) --- .../controller/ll_sw/nordic/lll/lll.c | 6 +-- subsys/bluetooth/controller/ll_sw/ull.c | 48 +++++++------------ 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index fe0a031d402..cde3eaaa6ee 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -930,8 +930,8 @@ static uint32_t preempt_ticker_start(struct lll_event *first, TICKER_NULL_REMAINDER, TICKER_NULL_LAZY, TICKER_NULL_SLOT, - preempt_ticker_cb, first->prepare_param.param, - ticker_start_op_cb, NULL); + preempt_ticker_cb, first, + ticker_start_op_cb, first); return ret; } @@ -1007,7 +1007,7 @@ static void preempt(void *param) } /* Preemptor not in pipeline */ - if (next->prepare_param.param != param) { + if (next != param) { uint32_t ret; /* Start the preempt timeout */ diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 6be8bc4759e..29cf43cd6d9 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -2063,8 +2063,6 @@ void *ull_prepare_dequeue_iter(uint8_t *idx) void ull_prepare_dequeue(uint8_t caller_id) { - void *param_normal_head = NULL; - void *param_normal_next = NULL; void *param_resume_head = NULL; void *param_resume_next = NULL; struct lll_event *next; @@ -2105,41 +2103,31 @@ void ull_prepare_dequeue(uint8_t caller_id) /* The prepare element was not a resume event, it would * use the radio or was enqueued back into prepare * pipeline with a preempt timeout being set. - * - * Remember the first encountered and the next element - * in the prepare pipeline so that we do not infinitely - * loop through the resume events in prepare pipeline. */ if (!is_resume) { - if (!param_normal_head) { - param_normal_head = param; - } else if (!param_normal_next) { - param_normal_next = param; - } - } else { - if (!param_resume_head) { - param_resume_head = param; - } else if (!param_resume_next) { - param_resume_next = param; - } + break; + } + + /* Remember the first encountered resume and the next + * resume element in the prepare pipeline so that we do + * not infinitely loop through the resume events in + * prepare pipeline. + */ + if (!param_resume_head) { + param_resume_head = param; + } else if (!param_resume_next) { + param_resume_next = param; } /* Stop traversing the prepare pipeline when we reach - * back to the first or next event where we + * back to the first or next resume event where we * initially started processing the prepare pipeline. */ - if (!next->is_aborted && - ((!next->is_resume && - ((next->prepare_param.param == - param_normal_head) || - (next->prepare_param.param == - param_normal_next))) || - (next->is_resume && - !param_normal_next && - ((next->prepare_param.param == - param_resume_head) || - (next->prepare_param.param == - param_resume_next))))) { + if (next->is_resume && + ((next->prepare_param.param == + param_resume_head) || + (next->prepare_param.param == + param_resume_next))) { break; } } From cb9acc327517604cbdf672db7e60e09623c0b053 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 1 Sep 2023 05:18:47 +0200 Subject: [PATCH 0233/1623] [nrf fromtree] Bluetooth: Controller: Use the state/role param in prepare pipeline Use the state/role context parameter in prepare pipeline to identify the preempt timeout that was setup. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit dacadf2f1a987339cb4ec08e29fd88b77f8e5ae6) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 3494cea88c375065424b4c1873e184fefd48eea9) --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index cde3eaaa6ee..fe0a031d402 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -930,8 +930,8 @@ static uint32_t preempt_ticker_start(struct lll_event *first, TICKER_NULL_REMAINDER, TICKER_NULL_LAZY, TICKER_NULL_SLOT, - preempt_ticker_cb, first, - ticker_start_op_cb, first); + preempt_ticker_cb, first->prepare_param.param, + ticker_start_op_cb, NULL); return ret; } @@ -1007,7 +1007,7 @@ static void preempt(void *param) } /* Preemptor not in pipeline */ - if (next != param) { + if (next->prepare_param.param != param) { uint32_t ret; /* Start the preempt timeout */ From 146b77c3f11030a321efb7cf7eec51f76a13e0a8 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sat, 2 Sep 2023 09:18:23 +0530 Subject: [PATCH 0234/1623] [nrf fromtree] Bluetooth: Controller: Use ticker_ticks_diff_get to check short prepare Use ticker_ticks_diff_get consistently when calculating difference between ticker ticks when determining short prepare requests. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 67a2fc429320f4422faa35adbfc2fff14ee198de) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 0d3ec7701bc79d2131943c3de1cd57aa5130914d) --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index fe0a031d402..b127e60a9f4 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -869,6 +869,13 @@ static uint32_t preempt_ticker_start(struct lll_event *first, (preempt_req != preempt_ack)) { uint32_t diff; + /* preempt timeout already started but no role/state in the head + * of prepare pipeline. + */ + if (!prev || prev->is_aborted) { + return TICKER_STATUS_SUCCESS; + } + /* Calc the preempt timeout */ p = &next->prepare_param; ull = HDR_LLL2ULL(p->param); @@ -881,9 +888,9 @@ static uint32_t preempt_ticker_start(struct lll_event *first, ticks_at_preempt_new &= HAL_TICKER_CNTR_MASK; /* Check for short preempt timeouts */ - diff = ticks_at_preempt_new - ticks_at_preempt; - if (!prev || prev->is_aborted || - ((diff & BIT(HAL_TICKER_CNTR_MSBIT)) == 0U)) { + diff = ticker_ticks_diff_get(ticks_at_preempt_new, + ticks_at_preempt); + if ((diff & BIT(HAL_TICKER_CNTR_MSBIT)) == 0U) { return TICKER_STATUS_SUCCESS; } From 368963a73f394687b0fd9b648942d7674213d201 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 1 Sep 2023 05:35:19 +0200 Subject: [PATCH 0235/1623] [nrf fromtree] Bluetooth: Controller: Fix ticks_slot_window use in Observer Fix ticks_slot_window use in Observer, do not use for unreserved continuous scanning, and do not use when scanning on both 1M and Coded PHY simultaneously. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 377e2a1f48720a53e8b727eba32d40442c1ad46b) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 13b422479ccd0cce310059ec3b9c2b88fc1c798f) --- subsys/bluetooth/controller/ll_sw/ull_scan.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan.c b/subsys/bluetooth/controller/ll_sw/ull_scan.c index 1ee99565a13..21d6cc9c401 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_scan.c +++ b/subsys/bluetooth/controller/ll_sw/ull_scan.c @@ -500,6 +500,10 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan) * enabled. */ } + +#if defined(CONFIG_BT_TICKER_EXT) + ll_scan_ticker_ext[handle].ticks_slot_window = 0U; +#endif /* CONFIG_BT_TICKER_EXT */ } /* 1M scan window starts without any offset */ @@ -559,6 +563,10 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan) } else { ticks_offset = 0U; } + +#if defined(CONFIG_BT_TICKER_EXT) + ll_scan_ticker_ext[handle].ticks_slot_window = 0U; +#endif /* CONFIG_BT_TICKER_EXT */ } else { ticks_offset = 0U; } From 3cefcc0b7485c4bdf5c494b9dda99921d5a36ae7 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 18 Jan 2022 17:52:06 +0530 Subject: [PATCH 0236/1623] [nrf fromtree] Bluetooth: Controller: Fix short prepare when many enqueued in pipeline Fix short prepare handling when more than one event is enqueued in the pipeline and the short prepare is placed at the end of the prepare pipeline. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 7f388bb70a3dadb5b3d4a2b4d2a63d1837108492) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit f200aa6c187e72e344ca531c95717c6ba0d139eb) --- .../controller/ll_sw/nordic/lll/lll.c | 69 ++++++++++++------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index b127e60a9f4..9ccc36e49e5 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -899,15 +899,6 @@ static uint32_t preempt_ticker_start(struct lll_event *first, LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || (ret == TICKER_STATUS_BUSY)); - /* Set early as we get called again through the call to - * abort_cb(). - */ - ticks_at_preempt = ticks_at_preempt_new; - - /* Abort previous prepare that set the preempt timeout */ - prev->is_aborted = 1U; - prev->abort_cb(&prev->prepare_param, prev->prepare_param.param); - /* Schedule short preempt timeout */ first = next; } else { @@ -996,17 +987,11 @@ static void preempt(void *param) return; } - /* Check if any prepare in pipeline */ - idx = UINT8_MAX; - next = ull_prepare_dequeue_iter(&idx); - if (!next) { - return; - } - /* Find a prepare that is ready and not a resume */ - while (next && (next->is_aborted || next->is_resume)) { + idx = UINT8_MAX; + do { next = ull_prepare_dequeue_iter(&idx); - } + } while (next && (next->is_aborted || next->is_resume)); /* No ready prepare */ if (!next) { @@ -1015,14 +1000,52 @@ static void preempt(void *param) /* Preemptor not in pipeline */ if (next->prepare_param.param != param) { + struct lll_event *next_next = NULL; + struct lll_event *e; uint32_t ret; - /* Start the preempt timeout */ - ret = preempt_ticker_start(next, NULL, next); - LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || - (ret == TICKER_STATUS_BUSY)); + /* Find if a short prepare request in the pipeline */ + do { + e = ull_prepare_dequeue_iter(&idx); + if (!next_next && e && !e->is_aborted && + !e->is_resume) { + next_next = e; + } + } while (e && (e->is_aborted || e->is_resume || + (e->prepare_param.param != param))); - return; + /* No short prepare request in pipeline */ + if (!e) { + /* Start the preempt timeout for next event */ + ret = preempt_ticker_start(next, NULL, next); + LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || + (ret == TICKER_STATUS_BUSY)); + + return; + } + + /* FIXME: Abort all events in pipeline before the short + * prepare event. For now, lets assert when many + * enqueued prepares need aborting. + */ + LL_ASSERT(next_next == e); + + /* Abort the prepare that is present before the short prepare */ + next->is_aborted = 1; + next->abort_cb(&next->prepare_param, next->prepare_param.param); + + /* As the prepare queue has been refreshed due to the call of + * abort_cb which invokes the lll_done, find the latest prepare + */ + idx = UINT8_MAX; + do { + next = ull_prepare_dequeue_iter(&idx); + } while (next && (next->is_aborted || next->is_resume)); + + /* No ready prepare */ + if (!next) { + return; + } } /* Check if current event want to continue */ From 290662fbfd0c9aecf7067a2440db51b9d6260027 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 20 Sep 2023 09:54:23 +0200 Subject: [PATCH 0237/1623] [nrf fromtree] Bluetooth: Controller: Refactor prepare dequeue iteration code Refactor/rename prepare dequeue iteration code and reuse it. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit c1042dff408cb37947e069e963c4424a249db525) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 0a00dd78411e6b42f4dd9ada16196a1b44d900c1) --- .../controller/ll_sw/nordic/lll/lll.c | 165 +++++++++--------- 1 file changed, 82 insertions(+), 83 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index 9ccc36e49e5..db8f25a374c 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -65,7 +65,9 @@ static int init_reset(void); #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) static inline void done_inc(void); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ -static struct lll_event *resume_enqueue(lll_prepare_cb_t resume_cb); +static inline bool is_done_sync(void); +static inline struct lll_event *prepare_dequeue_iter_ready_get(uint8_t *idx); +static inline struct lll_event *resume_enqueue(lll_prepare_cb_t resume_cb); static void isr_race(void *param); #if !defined(CONFIG_BT_CTLR_LOW_LAT) @@ -643,52 +645,27 @@ void lll_isr_early_abort(void *param) lll_done(NULL); } -static int init_reset(void) -{ - return 0; -} - -#if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) -static inline void done_inc(void) -{ - event.done.lll_count++; - LL_ASSERT(event.done.lll_count != event.done.ull_count); -} -#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ - -static inline bool is_done_sync(void) -{ -#if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) - return event.done.lll_count == event.done.ull_count; -#else /* !CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ - return true; -#endif /* !CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ -} - int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, lll_prepare_cb_t prepare_cb, struct lll_prepare_param *prepare_param, uint8_t is_resume, uint8_t is_dequeue) { - struct lll_event *p; + struct lll_event *ready; + struct lll_event *next; uint8_t idx; int err; /* Find the ready prepare in the pipeline */ idx = UINT8_MAX; - p = ull_prepare_dequeue_iter(&idx); - while (p && (p->is_aborted || p->is_resume)) { - p = ull_prepare_dequeue_iter(&idx); - } + ready = prepare_dequeue_iter_ready_get(&idx); /* Current event active or another prepare is ready in the pipeline */ if ((!is_dequeue && !is_done_sync()) || event.curr.abort_cb || - (p && is_resume)) { + (ready && is_resume)) { #if defined(CONFIG_BT_CTLR_LOW_LAT) lll_prepare_cb_t resume_cb; #endif /* CONFIG_BT_CTLR_LOW_LAT */ - struct lll_event *next; if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT) && event.curr.param) { /* early abort */ @@ -706,29 +683,28 @@ int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, } /* Always start preempt timeout for first prepare in pipeline */ - struct lll_event *first = p ? p : next; + struct lll_event *first = ready ? ready : next; uint32_t ret; /* Start the preempt timeout */ - ret = preempt_ticker_start(first, p, next); + ret = preempt_ticker_start(first, ready, next); LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || (ret == TICKER_STATUS_BUSY)); #else /* CONFIG_BT_CTLR_LOW_LAT */ next = NULL; - while (p) { - if (!p->is_aborted) { - if (event.curr.param == - p->prepare_param.param) { - p->is_aborted = 1; - p->abort_cb(&p->prepare_param, - p->prepare_param.param); + while (ready) { + if (!ready->is_aborted) { + if (event.curr.param == ready->prepare_param.param) { + ready->is_aborted = 1; + ready->abort_cb(&ready->prepare_param, + ready->prepare_param.param); } else { - next = p; + next = ready; } } - p = ull_prepare_dequeue_iter(&idx); + ready = ull_prepare_dequeue_iter(&idx); } if (next) { @@ -749,7 +725,7 @@ int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, return -EINPROGRESS; } - LL_ASSERT(!p || &p->prepare_param == prepare_param); + LL_ASSERT(!ready || &ready->prepare_param == prepare_param); event.curr.param = prepare_param->param; event.curr.is_abort_cb = is_abort_cb; @@ -774,15 +750,13 @@ int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, */ /* Find next prepare needing preempt timeout to be setup */ - do { - p = ull_prepare_dequeue_iter(&idx); - if (!p) { - return err; - } - } while (p->is_aborted || p->is_resume); + next = prepare_dequeue_iter_ready_get(&idx); + if (!next) { + return err; + } /* Start the preempt timeout */ - ret = preempt_ticker_start(p, NULL, p); + ret = preempt_ticker_start(next, NULL, next); LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || (ret == TICKER_STATUS_BUSY)); #endif /* !CONFIG_BT_CTLR_LOW_LAT */ @@ -790,7 +764,40 @@ int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, return err; } -static struct lll_event *resume_enqueue(lll_prepare_cb_t resume_cb) +static int init_reset(void) +{ + return 0; +} + +#if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) +static inline void done_inc(void) +{ + event.done.lll_count++; + LL_ASSERT(event.done.lll_count != event.done.ull_count); +} +#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ + +static inline bool is_done_sync(void) +{ +#if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) + return event.done.lll_count == event.done.ull_count; +#else /* !CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ + return true; +#endif /* !CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ +} + +static inline struct lll_event *prepare_dequeue_iter_ready_get(uint8_t *idx) +{ + struct lll_event *ready; + + do { + ready = ull_prepare_dequeue_iter(idx); + } while (ready && (ready->is_aborted || ready->is_resume)); + + return ready; +} + +static inline struct lll_event *resume_enqueue(lll_prepare_cb_t resume_cb) { struct lll_prepare_param prepare_param = {0}; @@ -978,7 +985,7 @@ static void preempt_ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, static void preempt(void *param) { lll_prepare_cb_t resume_cb; - struct lll_event *next; + struct lll_event *ready; uint8_t idx; int err; @@ -989,35 +996,32 @@ static void preempt(void *param) /* Find a prepare that is ready and not a resume */ idx = UINT8_MAX; - do { - next = ull_prepare_dequeue_iter(&idx); - } while (next && (next->is_aborted || next->is_resume)); - - /* No ready prepare */ - if (!next) { + ready = prepare_dequeue_iter_ready_get(&idx); + if (!ready) { + /* No ready prepare */ return; } /* Preemptor not in pipeline */ - if (next->prepare_param.param != param) { - struct lll_event *next_next = NULL; - struct lll_event *e; + if (ready->prepare_param.param != param) { + struct lll_event *ready_next = NULL; + struct lll_event *preemptor; uint32_t ret; /* Find if a short prepare request in the pipeline */ do { - e = ull_prepare_dequeue_iter(&idx); - if (!next_next && e && !e->is_aborted && - !e->is_resume) { - next_next = e; + preemptor = ull_prepare_dequeue_iter(&idx); + if (!ready_next && preemptor && !preemptor->is_aborted && + !preemptor->is_resume) { + ready_next = preemptor; } - } while (e && (e->is_aborted || e->is_resume || - (e->prepare_param.param != param))); + } while (preemptor && (preemptor->is_aborted || preemptor->is_resume || + (preemptor->prepare_param.param != param))); /* No short prepare request in pipeline */ - if (!e) { - /* Start the preempt timeout for next event */ - ret = preempt_ticker_start(next, NULL, next); + if (!preemptor) { + /* Start the preempt timeout for ready event */ + ret = preempt_ticker_start(ready, NULL, ready); LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || (ret == TICKER_STATUS_BUSY)); @@ -1028,34 +1032,29 @@ static void preempt(void *param) * prepare event. For now, lets assert when many * enqueued prepares need aborting. */ - LL_ASSERT(next_next == e); + LL_ASSERT(preemptor == ready_next); /* Abort the prepare that is present before the short prepare */ - next->is_aborted = 1; - next->abort_cb(&next->prepare_param, next->prepare_param.param); + ready->is_aborted = 1; + ready->abort_cb(&ready->prepare_param, ready->prepare_param.param); /* As the prepare queue has been refreshed due to the call of * abort_cb which invokes the lll_done, find the latest prepare */ idx = UINT8_MAX; - do { - next = ull_prepare_dequeue_iter(&idx); - } while (next && (next->is_aborted || next->is_resume)); - - /* No ready prepare */ - if (!next) { + ready = prepare_dequeue_iter_ready_get(&idx); + if (!ready) { + /* No ready prepare */ return; } } /* Check if current event want to continue */ - err = event.curr.is_abort_cb(next->prepare_param.param, - event.curr.param, - &resume_cb); + err = event.curr.is_abort_cb(ready->prepare_param.param, event.curr.param, &resume_cb); if (!err) { /* Let preemptor LLL know about the cancelled prepare */ - next->is_aborted = 1; - next->abort_cb(&next->prepare_param, next->prepare_param.param); + ready->is_aborted = 1; + ready->abort_cb(&ready->prepare_param, ready->prepare_param.param); return; } From c86add5e2012481673862ff86407a15979280e0b Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sun, 26 Mar 2023 21:38:42 +0530 Subject: [PATCH 0238/1623] [nrf fromtree] Bluetooth: Controller: Reduce successive ticker_job() on Extended Scan Reduce number of successive calls to ticker_job() by disabling mayflies in the ULL_HIGH priority, enqueue ticker_yield_abs() and ticker_start() before re-enabling so that single ticker_job() handles both yield and start. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 02b1c768206291a8f4d105a34ab357b973240195) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 1902baed85baf58cf7f5436e06ce28efe0e05e58) --- subsys/bluetooth/controller/ll_sw/ull_scan_aux.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c b/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c index 316cec7fec7..ecdfdd60d07 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c @@ -682,6 +682,13 @@ void ull_scan_aux_setup(memq_link_t *link, struct node_rx_hdr *rx) ticks_aux_offset = HAL_TICKER_US_TO_TICKS(aux_offset_us); +#if (CONFIG_BT_CTLR_ULL_HIGH_PRIO == CONFIG_BT_CTLR_ULL_LOW_PRIO) + /* disable ticker job, in order to chain yield and start to reduce + * CPU use by reducing successive calls to ticker_job(). + */ + mayfly_enable(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_ULL_LOW, 0); +#endif + /* Yield the primary scan window or auxiliary or periodic sync event * in ticker. */ @@ -714,6 +721,13 @@ void ull_scan_aux_setup(memq_link_t *link, struct node_rx_hdr *rx) ((ticker_status == TICKER_STATUS_FAILURE) && IS_ENABLED(CONFIG_BT_TICKER_LOW_LAT))); +#if (CONFIG_BT_CTLR_ULL_HIGH_PRIO == CONFIG_BT_CTLR_ULL_LOW_PRIO) + /* enable ticker job, queued ticker operation will be handled + * thereafter. + */ + mayfly_enable(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_ULL_LOW, 1); +#endif + return; ull_scan_aux_rx_flush: From 064912923c684da6a02b32ebec9a895b4f2ae319 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Mon, 4 Sep 2023 15:26:18 +0530 Subject: [PATCH 0239/1623] [nrf fromtree] Bluetooth: Controller: Revert EVENT_OVERHEAD_START_US for Coded PHY Revert EVENT_OVERHEAD_START_US value for Coded PHY support, needed to pass LL/DDI/SCN/BV-21-C and LL/DDI/SCN/BV-25-C. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit d8f0006de5182d233ab1a438fe8594c2faa4372e) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 8418b5780f68c264214172a636f0bb87ddbfef21) --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h index 7df39f65c8a..db5f8e3f1d8 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h @@ -21,22 +21,22 @@ /* Active connection in peripheral role with extended scanning on 1M and Coded * PHY, scheduling and receiving auxiliary PDUs. */ -#define EVENT_OVERHEAD_START_US 458 +#define EVENT_OVERHEAD_START_US 733 /* 24 RTC ticks */ #else /* !CONFIG_BT_CTLR_PHY_CODED */ /* Active connection in peripheral role with extended scanning on 1M only, * scheduling and receiving auxiliary PDUs. */ -#define EVENT_OVERHEAD_START_US 428 +#define EVENT_OVERHEAD_START_US 428 /* 14 RTC ticks */ #endif /* !CONFIG_BT_CTLR_PHY_CODED */ #else /* !CONFIG_BT_OBSERVER */ /* Active connection in peripheral role with legacy scanning on 1M. */ -#define EVENT_OVERHEAD_START_US 275 +#define EVENT_OVERHEAD_START_US 275 /* 9 RTC ticks */ #endif /* !CONFIG_BT_OBSERVER */ #else /* !CONFIG_BT_CTLR_ADV_EXT */ /* Active connection in peripheral role with additional advertising state. */ -#define EVENT_OVERHEAD_START_US 275 +#define EVENT_OVERHEAD_START_US 275 /* 9 RTC ticks */ #endif /* !CONFIG_BT_CTLR_ADV_EXT */ /* Worst-case time margin needed after event end-time in the air From 46a5b07bbc1d5dd0ed2c5bb7a12d4996d6703795 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 6 Jul 2023 06:05:42 +0530 Subject: [PATCH 0240/1623] [nrf fromtree] Bluetooth: Controller: Minor rename ull_adv_sync_iso_created() Minor rename to ull_adv_sync_iso_created(). Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 5b4eb9bc76b68c50d1babdef988efcce2491ce4a) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 65ab80d42f80c8d7d8ee7c6a0e8e794b4cdaeafd) --- subsys/bluetooth/controller/ll_sw/ull_adv_internal.h | 2 +- subsys/bluetooth/controller/ll_sw/ull_adv_iso.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_adv_sync.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h index 00bf3c126df..f4d059e0cd3 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h @@ -205,7 +205,7 @@ ull_adv_aux_hdr_len_fill(struct pdu_adv_com_ext_adv *com_hdr, uint8_t len) void ull_adv_sync_started_stopped(struct ll_adv_aux_set *aux); /* notify adv_sync_set that an iso instance has been created for it */ -void ull_adv_iso_created(struct ll_adv_sync_set *sync); +void ull_adv_sync_iso_created(struct ll_adv_sync_set *sync); #endif /* CONFIG_BT_CTLR_ADV_EXT */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index 89e66ff99e5..cb53f913b01 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -487,7 +487,7 @@ uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis, #if defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO) /* Notify the sync instance */ - ull_adv_iso_created(HDR_LLL2ULL(lll_adv_sync)); + ull_adv_sync_iso_created(HDR_LLL2ULL(lll_adv_sync)); #endif /* CONFIG_BT_TICKER_EXT_EXPIRE_INFO */ /* Commit the BIGInfo in the ACAD field of Periodic Advertising */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c index bbb1b351848..f1f521ca235 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c @@ -222,7 +222,7 @@ uint8_t ll_adv_sync_param_set(uint8_t handle, uint16_t interval, uint16_t flags) } #if defined(CONFIG_BT_CTLR_ADV_ISO) && defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO) -void ull_adv_iso_created(struct ll_adv_sync_set *sync) +void ull_adv_sync_iso_created(struct ll_adv_sync_set *sync) { if (sync->lll.iso && sync->is_started) { uint8_t iso_handle = sync->lll.iso->handle; From 5066d19a144b3096e6ee5c6ceb755b7589938a5e Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 5 Jul 2023 05:29:24 +0530 Subject: [PATCH 0241/1623] [nrf fromtree] Bluetooth: Controller: Calculate Broadcast ISO event overheads Calculate Broadcast ISO event overheads due to extended and periodic advertising events. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 87138e7ee34a54e609f45f3fb1acb5475e745cea) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit cbc4b5ed65c4df3a7875bfa4b355dc3416a284cd) --- .../bluetooth/controller/ll_sw/ull_adv_iso.c | 52 ++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index cb53f913b01..4551fac228d 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -97,13 +97,19 @@ uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis, struct ll_adv_iso_set *adv_iso; struct pdu_adv *pdu_prev, *pdu; struct pdu_big_info *big_info; + uint32_t ticks_slot_overhead; + struct ll_adv_sync_set *sync; + struct ll_adv_aux_set *aux; uint32_t event_spacing_max; uint8_t pdu_big_info_size; uint32_t iso_interval_us; uint32_t latency_packing; + uint32_t ticks_slot_sync; + uint32_t ticks_slot_aux; memq_link_t *link_cmplt; memq_link_t *link_term; struct ll_adv_set *adv; + uint32_t slot_overhead; uint32_t event_spacing; uint16_t ctrl_spacing; uint8_t sdu_per_event; @@ -275,14 +281,48 @@ uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis, lll_adv_iso->num_bis; event_spacing = latency_packing + ctrl_spacing + EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; - /* FIXME: calculate overheads due to extended and periodic advertising. + + /* Calculate overheads due to extended advertising. */ + aux = HDR_LLL2ULL(adv->lll.aux); + ticks_slot_aux = aux->ull.ticks_slot; + if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { + ticks_slot_overhead = MAX(aux->ull.ticks_active_to_start, + aux->ull.ticks_prepare_to_start); + } else { + ticks_slot_overhead = 0U; + } + ticks_slot_aux += ticks_slot_overhead; + + /* Calculate overheads due to periodic advertising. */ + sync = HDR_LLL2ULL(lll_adv_sync); + ticks_slot_sync = sync->ull.ticks_slot; + if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { + ticks_slot_overhead = MAX(sync->ull.ticks_active_to_start, + sync->ull.ticks_prepare_to_start); + } else { + ticks_slot_overhead = 0U; + } + ticks_slot_sync += ticks_slot_overhead; + + /* Calculate total overheads due to extended and periodic advertising */ + if (CONFIG_BT_CTLR_ADV_AUX_SYNC_OFFSET > 0U) { + ticks_slot_overhead = MAX(ticks_slot_aux, ticks_slot_sync); + } else { + ticks_slot_overhead = ticks_slot_aux + ticks_slot_sync; + } + + /* Calculate max available ISO event spacing */ + slot_overhead = HAL_TICKER_TICKS_TO_US(ticks_slot_overhead); + if (slot_overhead < iso_interval_us) { + event_spacing_max = iso_interval_us - slot_overhead; + } else { + event_spacing_max = 0U; + } + + /* Check if ISO interval too small to fit the calculated BIG event + * timing required for the supplied BIG create parameters. */ - event_spacing_max = iso_interval_us - 2000U; if (event_spacing > event_spacing_max) { - /* ISO interval too small to fit the calculated BIG event - * timing required for the supplied BIG create parameters. - */ - /* Release allocated link buffers */ ll_rx_link_release(link_cmplt); ll_rx_link_release(link_term); From 15f89d667165914c90f6b5931e3d15b97f624f4a Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 31 Jan 2023 12:30:49 +0530 Subject: [PATCH 0242/1623] [nrf fromtree] Bluetooth: Controller: Maximize BIG event length and preempt PTO & CTRL Maximize BIG event length to extend upto ISO interval, and allow PTO and Control subevents to be pre-emptible. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 0f2980db15f3448533c8a978e71daffbde2cdbf2) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 10adc66508cc691039a69c0a7ae1b384dfee05f8) --- .../bluetooth/controller/Kconfig.ll_sw_split | 12 +++++ .../bluetooth/controller/ll_sw/ull_adv_iso.c | 51 +++++++++++++------ 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 5fb2c54d085..1fa9031d47f 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -386,6 +386,18 @@ config BT_CTLR_ADV_RESERVE_MAX corresponding to the Advertising Data present at the time of the start/enable of Advertising is used. +config BT_CTLR_ADV_ISO_RESERVE_MAX + bool "Use maximum Broadcast ISO event time reservation" + depends on BT_CTLR_ADV_ISO + default y + help + Use maximum Broadcast ISO event time reservation. If disabled, then + time reservation does not include the pre-transmissions of the last + BIS and any Control subevents. This will allow extended or periodic + advertising events to preempt the BIG events but allow higher radio + utilizations by allowing larger BIG events when not overlapping with + extended or periodic advertising. + config BT_CTLR_ADV_AUX_SYNC_OFFSET int "Pre-defined offset between AUX_ADV_IND and AUX_SYNC_IND" depends on BT_CTLR_ADV_PERIODIC diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index 4551fac228d..de78352baa2 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -282,27 +282,41 @@ uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis, event_spacing = latency_packing + ctrl_spacing + EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; + /* Check if aux context allocated before we are creating ISO */ + if (adv->lll.aux) { + aux = HDR_LLL2ULL(adv->lll.aux); + } else { + aux = NULL; + } + /* Calculate overheads due to extended advertising. */ - aux = HDR_LLL2ULL(adv->lll.aux); - ticks_slot_aux = aux->ull.ticks_slot; - if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { - ticks_slot_overhead = MAX(aux->ull.ticks_active_to_start, - aux->ull.ticks_prepare_to_start); + if (aux && aux->is_started) { + ticks_slot_aux = aux->ull.ticks_slot; + if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { + ticks_slot_overhead = MAX(aux->ull.ticks_active_to_start, + aux->ull.ticks_prepare_to_start); + } else { + ticks_slot_overhead = 0U; + } + ticks_slot_aux += ticks_slot_overhead; } else { - ticks_slot_overhead = 0U; + ticks_slot_aux = 0U; } - ticks_slot_aux += ticks_slot_overhead; /* Calculate overheads due to periodic advertising. */ sync = HDR_LLL2ULL(lll_adv_sync); - ticks_slot_sync = sync->ull.ticks_slot; - if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { - ticks_slot_overhead = MAX(sync->ull.ticks_active_to_start, - sync->ull.ticks_prepare_to_start); + if (sync->is_started) { + ticks_slot_sync = sync->ull.ticks_slot; + if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { + ticks_slot_overhead = MAX(sync->ull.ticks_active_to_start, + sync->ull.ticks_prepare_to_start); + } else { + ticks_slot_overhead = 0U; + } + ticks_slot_sync += ticks_slot_overhead; } else { - ticks_slot_overhead = 0U; + ticks_slot_sync = 0U; } - ticks_slot_sync += ticks_slot_overhead; /* Calculate total overheads due to extended and periodic advertising */ if (CONFIG_BT_CTLR_ADV_AUX_SYNC_OFFSET > 0U) { @@ -1008,8 +1022,15 @@ static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, EVENT_MSS_US; ctrl_spacing = PDU_BIS_US(sizeof(struct pdu_big_ctrl), lll_iso->enc, lll_iso->phy, lll_iso->phy_flags); - slot_us = (pdu_spacing * lll_iso->nse * lll_iso->num_bis) + - ctrl_spacing; + + if (IS_ENABLED(CONFIG_BT_CTLR_ADV_ISO_RESERVE_MAX)) { + slot_us = (pdu_spacing * lll_iso->nse * lll_iso->num_bis) + + ctrl_spacing; + } else { + slot_us = pdu_spacing * ((lll_iso->nse * lll_iso->num_bis) - + lll_iso->ptc); + } + slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; adv_iso->ull.ticks_active_to_start = 0U; From 5f4e7b0cc6f13cd4c8d659fc8833787d8997fa9e Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 6 Jul 2023 06:03:43 +0530 Subject: [PATCH 0243/1623] [nrf fromtree] Bluetooth: Controller: Use max time when scheduling Broadcast ISO Use maximum event time length when scheduling Broadcast ISO events. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 3fba1a18e70dbf6d2993ce9fb9d5424601ddce16) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 71e9b9f93028ba1420391a314748d364df13dc12) --- .../controller/ll_sw/ull_adv_internal.h | 3 + .../bluetooth/controller/ll_sw/ull_adv_iso.c | 63 +++++++++++++------ subsys/bluetooth/controller/ll_sw/ull_sched.c | 5 +- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h index f4d059e0cd3..a2a0db7391f 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h @@ -322,6 +322,9 @@ struct lll_adv_iso_stream *ull_adv_iso_stream_get(uint16_t handle); /* helper function to release stream instances */ void ull_adv_iso_stream_release(struct ll_adv_iso_set *adv_iso); +/* helper function to return time reservation for Broadcast ISO event */ +uint32_t ull_adv_iso_max_time_get(const struct ll_adv_iso_set *adv_iso); + #if defined(CONFIG_BT_CTLR_DF_ADV_CTE_TX) /* helper function to release unused DF configuration memory */ void ull_df_adv_cfg_release(struct lll_df_adv_cfg *df_adv_cfg); diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index de78352baa2..6191f811311 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -57,6 +57,7 @@ static struct stream *adv_iso_stream_acquire(void); static uint16_t adv_iso_stream_handle_get(struct lll_adv_iso_stream *stream); static uint8_t ptc_calc(const struct lll_adv_iso *lll, uint32_t event_spacing, uint32_t event_spacing_max); +static uint32_t adv_iso_time_get(const struct ll_adv_iso_set *adv_iso, bool max); static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, uint32_t iso_interval_us); static uint8_t adv_iso_chm_update(uint8_t big_handle); @@ -945,6 +946,11 @@ void ull_adv_iso_stream_release(struct ll_adv_iso_set *adv_iso) lll->adv = NULL; } +uint32_t ull_adv_iso_max_time_get(const struct ll_adv_iso_set *adv_iso) +{ + return adv_iso_time_get(adv_iso, true); +} + static int init_reset(void) { /* Add initializations common to power up initialization and HCI reset @@ -998,22 +1004,12 @@ static uint8_t ptc_calc(const struct lll_adv_iso *lll, uint32_t event_spacing, return 0U; } -static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, - uint32_t iso_interval_us) +static uint32_t adv_iso_time_get(const struct ll_adv_iso_set *adv_iso, bool max) { - uint32_t ticks_slot_overhead; - struct lll_adv_iso *lll_iso; - uint32_t ticks_slot_offset; - uint32_t volatile ret_cb; - uint32_t ticks_anchor; + const struct lll_adv_iso *lll_iso; uint32_t ctrl_spacing; uint32_t pdu_spacing; - uint32_t ticks_slot; - uint32_t slot_us; - uint32_t ret; - int err; - - ull_hdr_init(&adv_iso->ull); + uint32_t time_us; lll_iso = &adv_iso->lll; @@ -1023,15 +1019,46 @@ static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, ctrl_spacing = PDU_BIS_US(sizeof(struct pdu_big_ctrl), lll_iso->enc, lll_iso->phy, lll_iso->phy_flags); - if (IS_ENABLED(CONFIG_BT_CTLR_ADV_ISO_RESERVE_MAX)) { - slot_us = (pdu_spacing * lll_iso->nse * lll_iso->num_bis) + + /* 1. Maximum PDU transmission time in 1M/2M/S8 PHY is 17040 us, or + * represented in 15-bits. + * 2. NSE in the range 1 to 31 is represented in 5-bits + * 3. num_bis in the range 1 to 31 is represented in 5-bits + * + * Hence, worst case event time can be represented in 25-bits plus + * one each bit for added ctrl_spacing and radio event overheads. I.e. + * 27-bits required and sufficiently covered by using 32-bit data type + * for time_us. + */ + + if (IS_ENABLED(CONFIG_BT_CTLR_ADV_ISO_RESERVE_MAX) || max) { + time_us = (pdu_spacing * lll_iso->nse * lll_iso->num_bis) + ctrl_spacing; } else { - slot_us = pdu_spacing * ((lll_iso->nse * lll_iso->num_bis) - + time_us = pdu_spacing * ((lll_iso->nse * lll_iso->num_bis) - lll_iso->ptc); } - slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; + /* Add implementation defined radio event overheads */ + time_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; + + return time_us; +} + +static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, + uint32_t iso_interval_us) +{ + uint32_t ticks_slot_overhead; + uint32_t ticks_slot_offset; + volatile uint32_t ret_cb; + uint32_t ticks_anchor; + uint32_t ticks_slot; + uint32_t slot_us; + uint32_t ret; + int err; + + ull_hdr_init(&adv_iso->ull); + + slot_us = adv_iso_time_get(adv_iso, false); adv_iso->ull.ticks_active_to_start = 0U; adv_iso->ull.ticks_prepare_to_start = @@ -1066,7 +1093,7 @@ static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, ret_cb = TICKER_STATUS_BUSY; ret = ticker_start(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, - (TICKER_ID_ADV_ISO_BASE + lll_iso->handle), + (TICKER_ID_ADV_ISO_BASE + adv_iso->lll.handle), ticks_anchor, 0U, HAL_TICKER_US_TO_TICKS(iso_interval_us), HAL_TICKER_REMAINDER(iso_interval_us), diff --git a/subsys/bluetooth/controller/ll_sw/ull_sched.c b/subsys/bluetooth/controller/ll_sw/ull_sched.c index e7ca8a0358b..38589a2e644 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sched.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sched.c @@ -701,7 +701,10 @@ static struct ull_hdr *ull_hdr_get_cb(uint8_t ticker_id, uint32_t *ticks_slot) adv_iso = ull_adv_iso_get(ticker_id - TICKER_ID_ADV_ISO_BASE); if (adv_iso) { - *ticks_slot = adv_iso->ull.ticks_slot; + uint32_t time_us; + + time_us = ull_adv_iso_max_time_get(adv_iso); + *ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); return &adv_iso->ull; } From 18f4f8597ba8339cb26fde13ac9917d027fca9ec Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 17 Aug 2023 01:55:58 +0530 Subject: [PATCH 0244/1623] [nrf fromtree] Bluetooth: Controller: Fix PHY value in HCI LE CIS Established Event Fix PHY_C_TO_P and PHY_P_TO_C value in HCI LE CIS Established Event. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit e4cc5838fd8f32ffa73b808a9a6505bb1b0ae6a9) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 834626a2bf61c8c641bf8cc31d0172079067d59a) --- subsys/bluetooth/controller/hci/hci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 30fb363fc9c..0adbf5ff70c 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -4245,8 +4245,8 @@ static void le_cis_established(struct pdu_data *pdu_data, sys_put_le24(cis->sync_delay, sep->cis_sync_delay); sys_put_le24(cig->c_latency, sep->c_latency); sys_put_le24(cig->p_latency, sep->p_latency); - sep->c_phy = lll_cis_c->phy; - sep->p_phy = lll_cis_p->phy; + sep->c_phy = find_lsb_set(lll_cis_c->phy); + sep->p_phy = find_lsb_set(lll_cis_p->phy); sep->nse = lll_cis->nse; sep->c_bn = lll_cis_c->bn; sep->p_bn = lll_cis_p->bn; From ca85f44bdbc22337acd4b3ff64b7fab086443271 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sat, 19 Aug 2023 21:29:56 +0530 Subject: [PATCH 0245/1623] [nrf fromtree] Bluetooth: Controller: Fix assertion due to late PER CIS active set Fix assertion due to late Peripheral CIS active flag being initialized. CIS active flag shall be initialized when it is acquired. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit cb28104cb08b5f9f86d043bbc8bf9bac1347c693) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 796be5a12f47be2ee33a36cf15da79241e2bb32d) --- subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index d45d89aa009..f68ca66656f 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -250,7 +250,8 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl, cis->p_max_sdu = (uint16_t)(req->p_max_sdu[1] & 0x0F) << 8 | req->p_max_sdu[0]; - cis->lll.handle = 0xFFFF; + cis->lll.active = 0U; + cis->lll.handle = LLL_HANDLE_INVALID; cis->lll.acl_handle = acl->lll.handle; cis->lll.sub_interval = sys_get_le24(req->sub_interval); cis->lll.nse = req->nse; @@ -325,7 +326,6 @@ uint8_t ull_peripheral_iso_setup(struct pdu_data_llctrl_cis_ind *ind, cis->lll.cie = 0U; cis->lll.npi = 0U; cis->lll.flush = LLL_CIS_FLUSH_NONE; - cis->lll.active = 0U; cis->lll.datapath_ready_rx = 0U; cis->lll.tx.payload_count = 0U; cis->lll.rx.payload_count = 0U; From 0cbe44c1bf783f13cf6da1ede4e199771e97f3fd Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sun, 20 Aug 2023 10:48:43 +0530 Subject: [PATCH 0246/1623] [nrf fromtree] Bluetooth: Controller: Fix missing host feature reset Fix missing host feature reset on HCI reset command. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 94bd4837bbdc2036b60325772830fbe8c08f6870) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit b0a6f693ec8acb3cbbaf6c864f4e2139b9c28771) --- subsys/bluetooth/controller/ll_sw/ll_feat.c | 5 +++++ subsys/bluetooth/controller/ll_sw/ll_feat_internal.h | 7 +++++++ subsys/bluetooth/controller/ll_sw/ull.c | 7 ++++++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 subsys/bluetooth/controller/ll_sw/ll_feat_internal.h diff --git a/subsys/bluetooth/controller/ll_sw/ll_feat.c b/subsys/bluetooth/controller/ll_sw/ll_feat.c index a1aaa99ba6d..d2ba2fefba0 100644 --- a/subsys/bluetooth/controller/ll_sw/ll_feat.c +++ b/subsys/bluetooth/controller/ll_sw/ll_feat.c @@ -70,6 +70,11 @@ uint8_t ll_set_host_feature(uint8_t bit_number, uint8_t bit_value) return BT_HCI_ERR_SUCCESS; } +void ll_feat_reset(void) +{ + host_features = 0U; +} + uint64_t ll_feat_get(void) { return LL_FEAT | (host_features & LL_FEAT_HOST_BIT_MASK); diff --git a/subsys/bluetooth/controller/ll_sw/ll_feat_internal.h b/subsys/bluetooth/controller/ll_sw/ll_feat_internal.h new file mode 100644 index 00000000000..7c23cb1a4e5 --- /dev/null +++ b/subsys/bluetooth/controller/ll_sw/ll_feat_internal.h @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +void ll_feat_reset(void); diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 29cf43cd6d9..e6a736f939d 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -44,6 +44,7 @@ #include "lll_sync_iso.h" #include "lll_iso_tx.h" #include "lll_conn.h" +#include "lll_conn_iso.h" #include "lll_df.h" #include "ull_adv_types.h" @@ -60,6 +61,7 @@ #endif /* CONFIG_BT_CTLR_USER_EXT */ #include "isoal.h" +#include "ll_feat_internal.h" #include "ull_internal.h" #include "ull_iso_internal.h" #include "ull_adv_internal.h" @@ -69,7 +71,6 @@ #include "ull_central_internal.h" #include "ull_iso_types.h" #include "ull_conn_internal.h" -#include "lll_conn_iso.h" #include "ull_conn_iso_types.h" #include "ull_central_iso_internal.h" #include "ull_llcp.h" @@ -899,6 +900,10 @@ void ll_reset(void) LL_ASSERT(!err); #endif +#if defined(CONFIG_BT_CTLR_SET_HOST_FEATURE) + ll_feat_reset(); +#endif /* CONFIG_BT_CTLR_SET_HOST_FEATURE */ + /* clear static random address */ (void)ll_addr_set(1U, NULL); } From cd06b1c9d643c1b3591a925d03bcc48cd9cbc36e Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 21 Sep 2023 08:57:08 +0200 Subject: [PATCH 0247/1623] [nrf fromtree] Bluetooth controller: nrf: Switch to use SOC_COMPATIBLE Switch use of kconfig: * SOC_SERIES_NRF53X -> SOC_COPATIBLE_NRF53X * SOC_NRF5340_CPUNET -> SOC_COMPATIBLE_NRF5340_CPUNET to also select those options/code when building for the nrf53 simulated targets. Also switch three kconfig range dependencies from SOC_SERIES_NRF52X to SOC_COPATIBLE_NRF52X (IRQ priority related) for consistency. These sound not really have an impact. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit bab4ed16238e74f089932819de2edf3cbc1fc6c9) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 169087459e88e2f19a0792177ac295e635072a5a) --- .../bluetooth/controller/Kconfig.ll_sw_split | 10 +-- .../controller/hci/nordic/hci_vendor.h | 2 +- .../ll_sw/nordic/hal/nrf5/radio/radio.c | 72 +++++++++---------- .../nrf5/radio/radio_nrf5_dppi_resources.h | 4 +- .../controller/ll_sw/nordic/hal/nrf5/swi.h | 8 +-- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 1fa9031d47f..4cd8e200b63 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -643,7 +643,7 @@ config BT_CTLR_SLOT_RESERVATION_UPDATE config BT_CTLR_LLL_PRIO int "Lower Link Layer (Radio) IRQ priority" if (BT_CTLR_ULL_LLL_PRIO_SUPPORT && !BT_CTLR_ZLI) range 0 3 if SOC_SERIES_NRF51X - range 0 6 if (SOC_SERIES_NRF52X || SOC_SERIES_NRF53X) + range 0 6 if (SOC_COMPATIBLE_NRF52X || SOC_COMPATIBLE_NRF53X) default 0 help The interrupt priority for event preparation and radio IRQ. @@ -651,7 +651,7 @@ config BT_CTLR_LLL_PRIO config BT_CTLR_ULL_HIGH_PRIO int "Upper Link Layer High IRQ priority" if BT_CTLR_ULL_LLL_PRIO_SUPPORT range BT_CTLR_LLL_PRIO 3 if SOC_SERIES_NRF51X - range BT_CTLR_LLL_PRIO 6 if (SOC_SERIES_NRF52X || SOC_SERIES_NRF53X) + range BT_CTLR_LLL_PRIO 6 if (SOC_COMPATIBLE_NRF52X || SOC_COMPATIBLE_NRF53X) default BT_CTLR_LLL_PRIO if (!BT_CTLR_ULL_LLL_PRIO_SUPPORT || BT_CTLR_ZLI || BT_CTLR_LOW_LAT) default 1 help @@ -661,7 +661,7 @@ config BT_CTLR_ULL_HIGH_PRIO config BT_CTLR_ULL_LOW_PRIO int "Upper Link Layer Low IRQ priority" if BT_CTLR_ULL_LLL_PRIO_SUPPORT range BT_CTLR_ULL_HIGH_PRIO 3 if SOC_SERIES_NRF51X - range BT_CTLR_ULL_HIGH_PRIO 6 if (SOC_SERIES_NRF52X || SOC_SERIES_NRF53X) + range BT_CTLR_ULL_HIGH_PRIO 6 if (SOC_COMPATIBLE_NRF52X || SOC_COMPATIBLE_NRF53X) default BT_CTLR_ULL_HIGH_PRIO help The interrupt priority for Ticker's Job IRQ and Upper Link Layer @@ -705,7 +705,7 @@ config BT_CTLR_RX_PDU_META config BT_CTLR_RADIO_ENABLE_FAST bool "Use tTXEN/RXEN,FAST ramp-up" - depends on SOC_COMPATIBLE_NRF52X || SOC_SERIES_NRF53X + depends on SOC_COMPATIBLE_NRF52X || SOC_COMPATIBLE_NRF53X default y help Enable use of fast radio ramp-up mode. @@ -719,7 +719,7 @@ config BT_CTLR_TIFS_HW config BT_CTLR_SW_SWITCH_SINGLE_TIMER bool "Single TIMER tIFS Trx SW switching" - depends on (!BT_CTLR_TIFS_HW) && (SOC_COMPATIBLE_NRF52X || SOC_SERIES_NRF53X) + depends on (!BT_CTLR_TIFS_HW) && (SOC_COMPATIBLE_NRF52X || SOC_COMPATIBLE_NRF53X) help Implement the tIFS Trx SW switch with the same TIMER instance, as the one used for BLE event timing. Requires diff --git a/subsys/bluetooth/controller/hci/nordic/hci_vendor.h b/subsys/bluetooth/controller/hci/nordic/hci_vendor.h index 4d3245728ed..bea7004f9c9 100644 --- a/subsys/bluetooth/controller/hci/nordic/hci_vendor.h +++ b/subsys/bluetooth/controller/hci/nordic/hci_vendor.h @@ -10,7 +10,7 @@ #define BT_HCI_VS_HW_VAR BT_HCI_VS_HW_VAR_NORDIC_NRF51X #elif defined(CONFIG_SOC_COMPATIBLE_NRF52X) #define BT_HCI_VS_HW_VAR BT_HCI_VS_HW_VAR_NORDIC_NRF52X -#elif defined(CONFIG_SOC_SERIES_NRF53X) +#elif defined(CONFIG_SOC_COMPATIBLE_NRF53X) #define BT_HCI_VS_HW_VAR BT_HCI_VS_HW_VAR_NORDIC_NRF53X #endif #else diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 1875dca7896..3fc76a27bdf 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -311,7 +311,7 @@ void radio_phy_set(uint8_t phy, uint8_t flags) void radio_tx_power_set(int8_t power) { -#if defined(CONFIG_SOC_SERIES_NRF53X) +#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) uint32_t value; /* NOTE: TXPOWER register only accepts upto 0dBm, hence use the HAL @@ -322,12 +322,12 @@ void radio_tx_power_set(int8_t power) NRF_RADIO->TXPOWER = value; hal_radio_tx_power_high_voltage_set(power); -#else /* !CONFIG_SOC_SERIES_NRF53X */ +#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ /* NOTE: valid value range is passed by Kconfig define. */ NRF_RADIO->TXPOWER = (uint32_t)power; -#endif /* !CONFIG_SOC_SERIES_NRF53X */ +#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ } void radio_tx_power_max_set(void) @@ -345,25 +345,25 @@ int8_t radio_tx_power_min_get(void) int8_t radio_tx_power_max_get(void) { -#if defined(CONFIG_SOC_SERIES_NRF53X) +#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) return RADIO_TXPOWER_TXPOWER_Pos3dBm; -#else /* !CONFIG_SOC_SERIES_NRF53X */ +#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ return (int8_t)hal_radio_tx_power_max_get(); -#endif /* !CONFIG_SOC_SERIES_NRF53X */ +#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ } int8_t radio_tx_power_floor(int8_t power) { -#if defined(CONFIG_SOC_SERIES_NRF53X) +#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) /* NOTE: TXPOWER register only accepts upto 0dBm, +3dBm permitted by * use of high voltage being set for radio when TXPOWER register is set. */ if (power >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos3dBm) { return RADIO_TXPOWER_TXPOWER_Pos3dBm; } -#endif /* CONFIG_SOC_SERIES_NRF53X */ +#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ return (int8_t)hal_radio_tx_power_floor(power); } @@ -413,7 +413,7 @@ void radio_pkt_configure(uint8_t bits_len, uint8_t max_len, uint8_t flags) bits_s1 = RADIO_PKT_CONF_LENGTH_8BIT - bits_len; #elif defined(CONFIG_SOC_COMPATIBLE_NRF52X) || \ - defined(CONFIG_SOC_SERIES_NRF53X) + defined(CONFIG_SOC_COMPATIBLE_NRF53X) extra = 0U; phy = RADIO_PKT_CONF_PHY_GET(flags); @@ -510,7 +510,7 @@ uint32_t radio_rx_chain_delay_get(uint8_t phy, uint8_t flags) void radio_rx_enable(void) { #if !defined(CONFIG_BT_CTLR_TIFS_HW) -#if defined(CONFIG_SOC_SERIES_NRF53X) +#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) /* NOTE: Timer clear DPPI configuration is needed only for nRF53 * because of calls to radio_disable() and * radio_switch_complete_and_disable() inside a radio event call @@ -523,7 +523,7 @@ void radio_rx_enable(void) * radio event but when the radio event is done. */ hal_sw_switch_timer_clear_ppi_config(); -#endif /* CONFIG_SOC_SERIES_NRF53X */ +#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ #endif /* !CONFIG_BT_CTLR_TIFS_HW */ nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_RXEN); @@ -532,7 +532,7 @@ void radio_rx_enable(void) void radio_tx_enable(void) { #if !defined(CONFIG_BT_CTLR_TIFS_HW) -#if defined(CONFIG_SOC_SERIES_NRF53X) +#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) /* NOTE: Timer clear DPPI configuration is needed only for nRF53 * because of calls to radio_disable() and * radio_switch_complete_and_disable() inside a radio event call @@ -545,7 +545,7 @@ void radio_tx_enable(void) * radio event but when the radio event is done. */ hal_sw_switch_timer_clear_ppi_config(); -#endif /* CONFIG_SOC_SERIES_NRF53X */ +#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ #endif /* !CONFIG_BT_CTLR_TIFS_HW */ nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_TXEN); @@ -891,13 +891,13 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla * time-stamp. */ hal_radio_end_time_capture_ppi_config(); -#if !defined(CONFIG_SOC_SERIES_NRF53X) +#if !defined(CONFIG_SOC_COMPATIBLE_NRF53X) /* The function is not called for nRF5340 single timer configuration because * HAL_SW_SWITCH_TIMER_CLEAR_PPI is equal to HAL_RADIO_END_TIME_CAPTURE_PPI, * so channel is already enabled. */ hal_radio_nrf_ppi_channels_enable(BIT(HAL_RADIO_END_TIME_CAPTURE_PPI)); -#endif /* !CONFIG_SOC_SERIES_NRF53X */ +#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ #endif /* CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ sw_tifs_toggle += 1U; @@ -1186,38 +1186,38 @@ void radio_tmr_rx_status_reset(void) void radio_tmr_tx_enable(void) { -#if defined(CONFIG_SOC_SERIES_NRF53X) -#else /* !CONFIG_SOC_SERIES_NRF53X */ +#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ #if (HAL_RADIO_ENABLE_TX_ON_TICK_PPI == HAL_RADIO_ENABLE_RX_ON_TICK_PPI) hal_radio_enable_on_tick_ppi_config_and_enable(1U); #endif /* HAL_RADIO_ENABLE_TX_ON_TICK_PPI == HAL_RADIO_ENABLE_RX_ON_TICK_PPI */ -#endif /* !CONFIG_SOC_SERIES_NRF53X */ +#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ } void radio_tmr_rx_enable(void) { -#if defined(CONFIG_SOC_SERIES_NRF53X) -#else /* !CONFIG_SOC_SERIES_NRF53X */ +#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ #if (HAL_RADIO_ENABLE_TX_ON_TICK_PPI == HAL_RADIO_ENABLE_RX_ON_TICK_PPI) hal_radio_enable_on_tick_ppi_config_and_enable(0U); #endif /* HAL_RADIO_ENABLE_TX_ON_TICK_PPI == HAL_RADIO_ENABLE_RX_ON_TICK_PPI */ -#endif /* !CONFIG_SOC_SERIES_NRF53X */ +#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ } void radio_tmr_tx_disable(void) { -#if defined(CONFIG_SOC_SERIES_NRF53X) +#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) nrf_radio_subscribe_clear(NRF_RADIO, NRF_RADIO_TASK_TXEN); -#else /* !CONFIG_SOC_SERIES_NRF53X */ -#endif /* !CONFIG_SOC_SERIES_NRF53X */ +#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ } void radio_tmr_rx_disable(void) { -#if defined(CONFIG_SOC_SERIES_NRF53X) +#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) nrf_radio_subscribe_clear(NRF_RADIO, NRF_RADIO_TASK_RXEN); -#else /* !CONFIG_SOC_SERIES_NRF53X */ -#endif /* !CONFIG_SOC_SERIES_NRF53X */ +#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ } void radio_tmr_tifs_set(uint32_t tifs) @@ -1304,7 +1304,7 @@ uint32_t radio_tmr_start_tick(uint8_t trx, uint32_t tick) #if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) last_pdu_end_us = 0U; #endif /* CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ -#if defined(CONFIG_SOC_SERIES_NRF53X) +#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) /* NOTE: Timer clear DPPI configuration is needed only for nRF53 * because of calls to radio_disable() and * radio_switch_complete_and_disable() inside a radio event call @@ -1317,7 +1317,7 @@ uint32_t radio_tmr_start_tick(uint8_t trx, uint32_t tick) * radio event but when the radio event is done. */ hal_sw_switch_timer_clear_ppi_config(); -#endif /* CONFIG_SOC_SERIES_NRF53X */ +#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ #endif /* !CONFIG_BT_CTLR_TIFS_HW */ return remainder_us; @@ -1331,7 +1331,7 @@ uint32_t radio_tmr_start_us(uint8_t trx, uint32_t start_us) #if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) last_pdu_end_us = 0U; #endif /* CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ -#if defined(CONFIG_SOC_SERIES_NRF53X) +#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) /* NOTE: Timer clear DPPI configuration is needed only for nRF53 * because of calls to radio_disable() and * radio_switch_complete_and_disable() inside a radio event call @@ -1344,7 +1344,7 @@ uint32_t radio_tmr_start_us(uint8_t trx, uint32_t start_us) * radio event but when the radio event is done. */ hal_sw_switch_timer_clear_ppi_config(); -#endif /* CONFIG_SOC_SERIES_NRF53X */ +#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ #endif /* !CONFIG_BT_CTLR_TIFS_HW */ /* start_us could be the current count in the timer */ @@ -1464,12 +1464,12 @@ void radio_tmr_end_capture(void) * hal_sw_switch_timer_clear_ppi_config() and sw_switch(). There is no need to * configure the channel again in this function. */ -#if !defined(CONFIG_SOC_SERIES_NRF53X) || \ - (defined(CONFIG_SOC_SERIES_NRF53X) && !defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER)) +#if !defined(CONFIG_SOC_COMPATIBLE_NRF53X) || \ + (defined(CONFIG_SOC_COMPATIBLE_NRF53X) && !defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER)) hal_radio_end_time_capture_ppi_config(); hal_radio_nrf_ppi_channels_enable(BIT(HAL_RADIO_END_TIME_CAPTURE_PPI)); -#endif /* !CONFIG_SOC_SERIES_NRF53X || - * (CONFIG_SOC_SERIES_NRF53X && !CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) +#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X || + * (CONFIG_SOC_COMPATIBLE_NRF53X && !CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) */ } @@ -1776,7 +1776,7 @@ static void *radio_ccm_ext_tx_pkt_set(struct ccm *cnf, uint8_t pdu_type, void *p NRF_CCM->ENABLE = CCM_ENABLE_ENABLE_Enabled; mode = (CCM_MODE_MODE_Encryption << CCM_MODE_MODE_Pos) & CCM_MODE_MODE_Msk; -#if defined(CONFIG_SOC_COMPATIBLE_NRF52X) || defined(CONFIG_SOC_SERIES_NRF53X) +#if defined(CONFIG_SOC_COMPATIBLE_NRF52X) || defined(CONFIG_SOC_COMPATIBLE_NRF53X) /* Enable CCM support for 8-bit length field PDUs. */ mode |= (CCM_MODE_LENGTH_Extended << CCM_MODE_LENGTH_Pos) & CCM_MODE_LENGTH_Msk; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h index 74fb56d9b5c..e1b47d03fd7 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#if defined(CONFIG_SOC_NRF5340_CPUNET) || defined(DPPI_PRESENT) +#if defined(CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET) || defined(DPPI_PRESENT) /******************************************************************************* * Enable Radio on Event Timer tick: @@ -157,4 +157,4 @@ #define SW_SWITCH_TIMER_TASK_GROUP_BASE 0 #endif /* !CONFIG_BT_CTLR_TIFS_HW */ -#endif /* CONFIG_SOC_NRF5340_CPUNET || DPPI_PRESENT */ +#endif /* CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET || DPPI_PRESENT */ diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/swi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/swi.h index eb9da5652ff..6b364fd349a 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/swi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/swi.h @@ -18,10 +18,10 @@ #endif /* nRF53 Series IRQ mapping */ -#elif defined(CONFIG_SOC_SERIES_NRF53X) +#elif defined(CONFIG_SOC_COMPATIBLE_NRF53X) /* nRF53 Series Engineering D and Revision 1 IRQ mapping */ -#if defined(CONFIG_SOC_NRF5340_CPUNET) +#if defined(CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET) #define HAL_SWI_RADIO_IRQ SWI2_IRQn #define HAL_SWI_WORKER_IRQ RTC0_IRQn @@ -33,9 +33,9 @@ #define HAL_SWI_JOB_IRQ SWI3_IRQn #endif -#endif /* CONFIG_SOC_NRF5340_CPUNET */ +#endif /* CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET */ -#endif /* CONFIG_SOC_SERIES_NRF53X */ +#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ static inline void hal_swi_init(void) { From 6a7a93c5ff3a44b58457be8b140fec29fb13ebe1 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 21 Sep 2023 09:21:27 +0200 Subject: [PATCH 0248/1623] [nrf fromtree] Bluetooth controller nrf: ifdef some coded phy only code To avoid a build error when coded phy is not enabled for a nrf53: These three functions are only used for coded phy, and depend on macros which are only defined if coded phy is enabled. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit f1557804a93d61b0effe9f513985c0159144da79) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 5c5a3446b04fcfeb79b3389a7da50868ef5fda38) --- .../controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 71e5ffa0e6f..9ed66dc3442 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -551,6 +551,7 @@ static inline void hal_radio_sw_switch_cleanup(void) nrf_dppi_group_disable(NRF_DPPIC, SW_SWITCH_TIMER_TASK_GROUP(1)); } +#if defined(CONFIG_BT_CTLR_PHY_CODED) static inline void hal_radio_sw_switch_coded_tx_config_set(uint8_t ppi_en, uint8_t ppi_dis, uint8_t cc_s2, uint8_t group_index) { @@ -612,6 +613,7 @@ static inline void hal_radio_sw_switch_disable_group_clear(uint8_t ppi_dis, uint HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK( ppi_dis); } +#endif /* defined(CONFIG_BT_CTLR_PHY_CODED) */ static inline void hal_radio_sw_switch_ppi_group_setup(void) { From 5d1edf1e72deadd5680ed527feed12faeb2ee329 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 21 Sep 2023 09:50:56 +0200 Subject: [PATCH 0249/1623] [nrf fromtree] Bluetooth controller nrf: Rename bsim radio hal header Rename the bsim header in preparation for having more simulated targets. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit bae0dace163eddd6c60963d4cf3267125186fd99) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 6dfef35b08327580d01559bb38c07702aade8176) --- .../controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h | 4 ++-- .../hal/nrf5/radio/{radio_sim_nrfxx.h => radio_sim_nrf52.h} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/{radio_sim_nrfxx.h => radio_sim_nrf52.h} (100%) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h index a03e55f519d..9e29ab5f70b 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h @@ -15,8 +15,8 @@ #define HAL_RADIO_NS2US_ROUND(ns) ((ns + 500)/1000) /* SoC specific defines */ -#if defined(CONFIG_SOC_SERIES_BSIM_NRFXX) -#include "radio_sim_nrfxx.h" +#if defined(CONFIG_BOARD_NRF52_BSIM) +#include "radio_sim_nrf52.h" #elif defined(CONFIG_SOC_SERIES_NRF51X) #include "radio_nrf51.h" #elif defined(CONFIG_SOC_NRF52805) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h similarity index 100% rename from subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h rename to subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h From c3bc6faf52e3b301e91b62efc1a1763d28f29a46 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 22 Sep 2023 12:42:57 +0200 Subject: [PATCH 0250/1623] [nrf fromtree] Bluetooth: Controller: nRF53: Fix sw switch single timer id regression Fix regression in sw switch single timer id use for nRF53x series SoC. Regression introduced in commit cfcbe5d68ed3 ("Bluetooth: Controller: Remove redudant header file includes"). Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 8c9ac505dbe04585ebb6c3532c93c24884db70bb) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 0aa27c019b2d7407e61bf8cd533f5ffe646ed401) --- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5340.h | 14 ++++++++++++++ tests/bluetooth/init/testcase.yaml | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5340.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5340.h index e0f43014508..68267490129 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5340.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5340.h @@ -5,6 +5,20 @@ * SPDX-License-Identifier: Apache-2.0 */ +/* Override EVENT_TIMER_ID from 4 to 0, as nRF5340 does not have 4 timer + * instances. + */ +#if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) +#undef EVENT_TIMER_ID +#define EVENT_TIMER_ID 0 + +#undef EVENT_TIMER +#define EVENT_TIMER _CONCAT(NRF_TIMER, EVENT_TIMER_ID) + +#undef SW_SWITCH_TIMER +#define SW_SWITCH_TIMER EVENT_TIMER +#endif /* CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ + /* NRF Radio HW timing constants * - provided in US and NS (for higher granularity) * - based on empirical measurements and sniffer logs diff --git a/tests/bluetooth/init/testcase.yaml b/tests/bluetooth/init/testcase.yaml index fa30920dc1e..c38f5bed69e 100644 --- a/tests/bluetooth/init/testcase.yaml +++ b/tests/bluetooth/init/testcase.yaml @@ -122,6 +122,19 @@ tests: integration_platforms: - nrf52840dk_nrf52840 - nrf52dk_nrf52832 + bluetooth.init.test_ctlr_sw_switch_single_timer: + extra_args: + - CONF_FILE=prj_ctlr.conf + - CONFIG_BT_CTLR_ADVANCED_FEATURES=y + - CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER=y + platform_allow: + - nrf5340dk_nrf5340_cpunet + - nrf52840dk_nrf52840 + - nrf52dk_nrf52832 + integration_platforms: + - nrf5340dk_nrf5340_cpunet + - nrf52840dk_nrf52840 + - nrf52dk_nrf52832 bluetooth.init.test_ctlr_ticker: extra_args: - CONF_FILE=prj_ctlr_ticker.conf From 694b89fdbd9a78aedfd9e8521028622b9c54fd52 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 21 Sep 2023 15:37:45 +0200 Subject: [PATCH 0251/1623] [nrf fromtree] Bluetooth: Controller: nrf: Use HAL for DPPI configuration The following changes have been done: 1. HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(index) = HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK(channel) has been convered into HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(index, channel) 2. HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK(index) = HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_TASK Which was only used in one place, has been replaced with the equivalent HAL call 3. HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK(index) = 0 was replaced with the HAL subscribe clear function nrf_dppi_subscribe_clear(NRF_DPPIC, HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(index))); 4. NRF_DPPIC->SUBSCRIBE_CHG[group].EN/DIS = 0; have been replaced with the equivalent HAL clear call 5. NRF_DPPIC->TASKS_CHG[group].DIS = 1; have been replaced with the equivalent hal task_trigger() call 6. Manually setting the CHG registers, has been replaced with a clear + add (because the hal does not have a set function yet) So, NRF_DPPIC->CHG[group] = value has been replaced with nrf_dppi_group_clear(NRF_DPPIC, group); nrf_dppi_channels_include_in_group(NRF_DPPIC, value, group); (A set function has been requested from the HAL team) Note: There is other direct registes writes to the dppi subscribe and CHG registers in the coded phy parts which have not been changed yet. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit c5191ba5b78127d9b530d586c45fea58c2958155) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 8c16b538a6074bd030e9d14f092aebc3c19010fe) --- .../nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 102 ++++++++++-------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 9ed66dc3442..69069288141 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -317,6 +317,20 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) #define SW_SWITCH_TIMER_S2_EVTS_COMP(index) \ (SW_SWITCH_TIMER_EVTS_COMP_S2_BASE + (index)) +/* + * Convert a dppi channel group number into the *enable* task enumerate value + * the nrfx hal accepts + */ +#define HAL_SW_DPPI_TASK_EN_FROM_IDX(index) \ + (NRF_DPPI_TASK_CHG0_EN + ((index) * (NRF_DPPI_TASK_CHG1_EN - NRF_DPPI_TASK_CHG0_EN))) + +/* + * Convert a dppi channel group number into the *disable* task enumerate value + * the nrfx hal accepts + */ +#define HAL_SW_DPPI_TASK_DIS_FROM_IDX(index) \ + (NRF_DPPI_TASK_CHG0_DIS + ((index) * (NRF_DPPI_TASK_CHG1_EN - NRF_DPPI_TASK_CHG0_EN))) + /* Wire a SW SWITCH TIMER EVENTS_COMPARE[] event * to a PPI GROUP TASK DISABLE task (PPI group with index ). * 2 adjacent PPIs (8 & 9) and 2 adjacent PPI groups are used for this wiring; @@ -332,14 +346,10 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) & TIMER_PUBLISH_COMPARE_CHIDX_Msk) | \ ((TIMER_PUBLISH_COMPARE_EN_Enabled << TIMER_PUBLISH_COMPARE_EN_Pos) \ & TIMER_PUBLISH_COMPARE_EN_Msk)) -#define HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(index) \ - NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(index)].DIS -#define HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK(chan) \ - (((chan << DPPIC_SUBSCRIBE_CHG_DIS_CHIDX_Pos) \ - & DPPIC_SUBSCRIBE_CHG_DIS_CHIDX_Msk) | \ - ((DPPIC_SUBSCRIBE_CHG_DIS_EN_Enabled << \ - DPPIC_SUBSCRIBE_CHG_DIS_EN_Pos) \ - & DPPIC_SUBSCRIBE_CHG_DIS_EN_Msk)) +#define HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(index, channel) \ + nrf_dppi_subscribe_set(NRF_DPPIC, \ + HAL_SW_DPPI_TASK_DIS_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(index)), \ + channel); /* Enable the SW Switch PPI Group on RADIO END Event. * @@ -353,15 +363,6 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) & RADIO_PUBLISH_END_CHIDX_Msk) | \ ((RADIO_PUBLISH_END_EN_Enabled << RADIO_PUBLISH_END_EN_Pos) \ & RADIO_PUBLISH_END_EN_Msk)) -#define HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK(index) \ - (NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(index)].EN) -#define HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_TASK \ - (((HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI << \ - DPPIC_SUBSCRIBE_CHG_EN_CHIDX_Pos) \ - & DPPIC_SUBSCRIBE_CHG_EN_CHIDX_Msk) | \ - ((DPPIC_SUBSCRIBE_CHG_EN_EN_Enabled << \ - DPPIC_SUBSCRIBE_CHG_EN_EN_Pos) \ - & DPPIC_SUBSCRIBE_CHG_EN_EN_Msk)) /* Enable Radio on SW Switch timer event. * Wire a SW SWITCH TIMER EVENTS_COMPARE[] event @@ -473,12 +474,15 @@ static inline void hal_radio_sw_switch_setup( */ HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_EVT = HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_EVT; - HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK(ppi_group_index) = - HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_TASK; + nrf_dppi_subscribe_set(NRF_DPPIC, + HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(ppi_group_index)), + HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI); /* We need to un-subscribe the other group from the PPI channel. */ - HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK( - (ppi_group_index + 1) & 0x01) = 0; + uint8_t other_grp = (ppi_group_index + 1) & 0x01; + + nrf_dppi_subscribe_clear(NRF_DPPIC, + HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(other_grp))); /* Wire SW Switch timer event to the * PPI[] for enabling Radio. Do @@ -537,8 +541,10 @@ static inline void hal_radio_sw_switch_disable(void) * So we simply cancel the task subscription. */ nrf_timer_subscribe_clear(SW_SWITCH_TIMER, NRF_TIMER_TASK_CLEAR); - HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK(0) = 0; - HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK(1) = 0; + nrf_dppi_subscribe_clear(NRF_DPPIC, + HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(0))); + nrf_dppi_subscribe_clear(NRF_DPPIC, + HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(1))); } static inline void hal_radio_sw_switch_cleanup(void) @@ -567,8 +573,8 @@ static inline void hal_radio_sw_switch_coded_tx_config_set(uint8_t ppi_en, HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_EVT(cc_s2) = HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_EVT(ppi_dis); - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(group_index) = - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK(ppi_dis); + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(group_index, + ppi_dis); /* Capture CC to cancel the timer that has assumed * S8 reception, if packet will be received in S2. @@ -609,9 +615,7 @@ static inline void hal_radio_sw_switch_disable_group_clear(uint8_t ppi_dis, uint HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_EVT( ppi_dis); HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK( - group_index) = - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK( - ppi_dis); + group_index, ppi_dis); } #endif /* defined(CONFIG_BT_CTLR_PHY_CODED) */ @@ -624,21 +628,33 @@ static inline void hal_radio_sw_switch_ppi_group_setup(void) * registers are written, therefore, we clear the task registers * here. */ - NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(0)].EN = 0; - NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(0)].DIS = 0; - NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(1)].EN = 0; - NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(1)].DIS = 0; - - NRF_DPPIC->TASKS_CHG[SW_SWITCH_TIMER_TASK_GROUP(0)].DIS = 1; - NRF_DPPIC->TASKS_CHG[SW_SWITCH_TIMER_TASK_GROUP(1)].DIS = 1; + nrf_dppi_subscribe_clear(NRF_DPPIC, + HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(0))); + nrf_dppi_subscribe_clear(NRF_DPPIC, + HAL_SW_DPPI_TASK_DIS_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(0))); + nrf_dppi_subscribe_clear(NRF_DPPIC, + HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(1))); + nrf_dppi_subscribe_clear(NRF_DPPIC, + HAL_SW_DPPI_TASK_DIS_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(1))); + + nrf_dppi_task_trigger(NRF_DPPIC, + HAL_SW_DPPI_TASK_DIS_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(0))); + nrf_dppi_task_trigger(NRF_DPPIC, + HAL_SW_DPPI_TASK_DIS_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(1))); /* Include the appropriate PPI channels in the two PPI Groups. */ - NRF_DPPIC->CHG[SW_SWITCH_TIMER_TASK_GROUP(0)] = + nrf_dppi_group_clear(NRF_DPPIC, + SW_SWITCH_TIMER_TASK_GROUP(0)); + nrf_dppi_channels_include_in_group(NRF_DPPIC, BIT(HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(0)) | - BIT(HAL_SW_SWITCH_RADIO_ENABLE_PPI(0)); - NRF_DPPIC->CHG[SW_SWITCH_TIMER_TASK_GROUP(1)] = + BIT(HAL_SW_SWITCH_RADIO_ENABLE_PPI(0)), + SW_SWITCH_TIMER_TASK_GROUP(0)); + nrf_dppi_group_clear(NRF_DPPIC, + SW_SWITCH_TIMER_TASK_GROUP(1)); + nrf_dppi_channels_include_in_group(NRF_DPPIC, BIT(HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(1)) | - BIT(HAL_SW_SWITCH_RADIO_ENABLE_PPI(1)); + BIT(HAL_SW_SWITCH_RADIO_ENABLE_PPI(1)), + SW_SWITCH_TIMER_TASK_GROUP(1)); /* Sanity build-time check that RADIO Enable and Group Disable * tasks are going to be subscribed on the same PPIs. @@ -663,8 +679,7 @@ static inline void hal_radio_group_task_disable_ppi_setup(void) SW_SWITCH_TIMER_EVTS_COMP(0)) = HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_EVT( HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(0)); - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(0) = - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK( + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(0, HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(0)); /* Wire SW SWITCH TIMER event to @@ -674,9 +689,8 @@ static inline void hal_radio_group_task_disable_ppi_setup(void) SW_SWITCH_TIMER_EVTS_COMP(1)) = HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_EVT( HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(1)); - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(1) = - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK( - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(1)); + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(1, + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(1)); } #if defined(CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE) From 65eaabbf2ff41853284222cf9f6f2776ef3a794c Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 22 Sep 2023 09:50:22 +0200 Subject: [PATCH 0252/1623] [nrf fromtree] Bluetooth: Controller: nrf: HAL for DPPI configuration cleanup Remove a few macros which are not used anywhere in the tree. For the sake of simplifying the header and easing its understanding. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 07bb88d28ad366b0b3ba0ea0a9353140b7523efe) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 32d3dcd906d7e2c637f8864a42d61c20f6b09f47) --- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 69069288141..c28cc35a617 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -388,21 +388,6 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) & TIMER_PUBLISH_COMPARE_CHIDX_Msk) | \ ((TIMER_PUBLISH_COMPARE_EN_Enabled << TIMER_PUBLISH_COMPARE_EN_Pos) \ & TIMER_PUBLISH_COMPARE_EN_Msk)) -#define HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_TASK_TX \ - NRF_RADIO->SUBSCRIBE_TXEN -#define HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_TASK_RX \ - NRF_RADIO->SUBSCRIBE_RXEN -#define HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_TX_SET(chan) \ - (((chan << RADIO_SUBSCRIBE_TXEN_CHIDX_Pos) \ - & RADIO_SUBSCRIBE_TXEN_CHIDX_Msk) | \ - ((RADIO_SUBSCRIBE_TXEN_EN_Enabled << \ - RADIO_SUBSCRIBE_TXEN_EN_Pos) \ - & RADIO_SUBSCRIBE_TXEN_EN_Msk)) -#define HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_RX_SET(chan) \ - (((chan << RADIO_SUBSCRIBE_RXEN_CHIDX_Pos) \ - & RADIO_SUBSCRIBE_RXEN_CHIDX_Msk) | \ - ((RADIO_SUBSCRIBE_RXEN_EN_Enabled << RADIO_SUBSCRIBE_RXEN_EN_Pos) \ - & RADIO_SUBSCRIBE_RXEN_EN_Msk)) /* Cancel the SW switch timer running considering S8 timing: * wire the RADIO EVENTS_RATEBOOST event to SW_SWITCH_TIMER TASKS_CAPTURE task. From 5b8de9becc22ff98ef6eeaa36284417a670942d3 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 21 Sep 2023 10:09:47 +0200 Subject: [PATCH 0253/1623] [nrf fromtree] Bluetooth controller nrf: nrf52 bsim radio hal header minor updates Align the header a bit with the one for the real radio, adding missing Tx power levels and removing TODO which did not need doing. The old one originated as a copy of the nrf52833 one, and did not evolve like the real ones. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 865f3c161496a66d818e8bb2a59ecfc9ad77eae4) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 7dc07d4c24d1a482cfe7aa695685c7ce20f6ecc9) --- .../nordic/hal/nrf5/radio/radio_sim_nrf52.h | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h index a767fe1ab30..3d53462326a 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h @@ -185,14 +185,10 @@ static inline void hal_radio_reset(void) { - /* TODO: Add any required setup for each radio event - */ } static inline void hal_radio_stop(void) { - /* TODO: Add any required cleanup of actions taken in hal_radio_reset() - */ } static inline void hal_radio_ram_prio_setup(void) @@ -226,25 +222,39 @@ static inline uint32_t hal_radio_tx_power_min_get(void) static inline uint32_t hal_radio_tx_power_max_get(void) { -#if defined(RADIO_TXPOWER_TXPOWER_Pos4dBm) - return RADIO_TXPOWER_TXPOWER_Pos4dBm; -#else - return RADIO_TXPOWER_TXPOWER_0dBm; -#endif + return RADIO_TXPOWER_TXPOWER_Pos8dBm; } static inline uint32_t hal_radio_tx_power_floor(int8_t tx_power_lvl) { -#if defined(RADIO_TXPOWER_TXPOWER_Pos4dBm) + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos8dBm) { + return RADIO_TXPOWER_TXPOWER_Pos8dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos7dBm) { + return RADIO_TXPOWER_TXPOWER_Pos7dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos6dBm) { + return RADIO_TXPOWER_TXPOWER_Pos6dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos5dBm) { + return RADIO_TXPOWER_TXPOWER_Pos5dBm; + } + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos4dBm) { return RADIO_TXPOWER_TXPOWER_Pos4dBm; } -#endif -#if defined(RADIO_TXPOWER_TXPOWER_Pos3dBm) + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos3dBm) { return RADIO_TXPOWER_TXPOWER_Pos3dBm; } -#endif + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos2dBm) { + return RADIO_TXPOWER_TXPOWER_Pos2dBm; + } + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_0dBm) { return RADIO_TXPOWER_TXPOWER_0dBm; } @@ -269,10 +279,7 @@ static inline uint32_t hal_radio_tx_power_floor(int8_t tx_power_lvl) return RADIO_TXPOWER_TXPOWER_Neg20dBm; } - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg30dBm) { - return RADIO_TXPOWER_TXPOWER_Neg30dBm; - } - + /* Note: The -30 dBm power level is deprecated so ignore it! */ return RADIO_TXPOWER_TXPOWER_Neg40dBm; } From 35d5889e89181556ca0b4c16f2cb87ad2bbb51ee Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 22 Sep 2023 14:00:44 +0200 Subject: [PATCH 0254/1623] [nrf fromtree] Bluetooth controller nrf: nrf52 bsim radio hal fix hal_radio_tx_chain_delay_ns_get() was incorrectly returning the microsecond value, resulting in a 1us error in the timing => Fix it. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 292ca93795598e02210bc8c2114ed46db5ea4cc0) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit adeeb74a23a498d6be0fc680175898e944b3025c) --- .../ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h index 3d53462326a..1b8c1583547 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h @@ -14,7 +14,10 @@ /* NRF Radio HW timing constants * - provided in US and NS (for higher granularity) - * - based on empirical measurements and sniffer logs + * - based on the timings configured in the HW models, which are based + * on the product specification + * - Note that this timings are approx. the same as in the real HW, + * but tend to be rounded to the nearest microsecond */ /* TXEN->TXIDLE + TXIDLE->TX (with fast Radio ramp-up mode) @@ -361,7 +364,7 @@ static inline uint32_t hal_radio_tx_chain_delay_ns_get(uint8_t phy, uint8_t flag ARG_UNUSED(phy); ARG_UNUSED(flags); - return HAL_RADIO_NRF52833_TX_CHAIN_DELAY_US; + return HAL_RADIO_NRF52833_TX_CHAIN_DELAY_NS; } static inline uint32_t hal_radio_rx_chain_delay_ns_get(uint8_t phy, uint8_t flags) From ac999bd51ac7d24cb11df0171b137ef6444279a4 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sun, 17 Sep 2023 06:13:40 +0200 Subject: [PATCH 0255/1623] [nrf fromtree] Bluetooth: Controller: Use unique goto label in scan aux code Use unique goto label in scan aux connect response ISR. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit ed5883d9a07383a1651cb178f23b8c1c5bd7ab52) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit fbf506c371523e3dd404077af9d682aaeebf3a8b) --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c index 50bcb0e6662..c8188d87cb6 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c @@ -1510,7 +1510,7 @@ static void isr_rx_connect_rsp(void *param) rx = ftr->extra; rx->hdr.type = NODE_RX_TYPE_RELEASE; - goto isr_rx_do_close; + goto isr_rx_connect_rsp_do_close; } /* Update the max Tx and Rx time; and connection PHY based on the @@ -1548,7 +1548,7 @@ static void isr_rx_connect_rsp(void *param) } #endif /* CONFIG_BT_CTLR_PRIVACY */ -isr_rx_do_close: +isr_rx_connect_rsp_do_close: if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { lll_prof_cputime_capture(); } From 2528d7a49d30ff0334b4bf9af48618ddbf359373 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Mon, 25 Sep 2023 20:36:41 +0200 Subject: [PATCH 0256/1623] [nrf fromtree] Bluetooth: Controller: nRF53: Fix missing NRF_CCM subscribe clear Fix missing NRF_CCM subscribe clear which can lead to spurious trigger of TASK_CRYPT in NRF_CCM. This may lead to corruption of Rx PDU buffers. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 9e01c4df53370c5700f2d41a8d017f6e4f6925e8) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 1bcc5f707ad3b654495894901a9340ef5444978f) --- .../controller/ll_sw/nordic/hal/nrf5/radio/radio.c | 6 ++++++ .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 8 ++++++++ .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 3fc76a27bdf..0b41a9bbfb6 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -1084,6 +1084,8 @@ void radio_tmr_status_reset(void) { nrf_rtc_event_disable(NRF_RTC0, RTC_EVTENCLR_COMPARE2_Msk); + hal_trigger_crypt_ppi_disable(); + hal_radio_nrf_ppi_channels_disable( BIT(HAL_RADIO_ENABLE_TX_ON_TICK_PPI) | BIT(HAL_RADIO_ENABLE_RX_ON_TICK_PPI) | @@ -1116,6 +1118,8 @@ void radio_tmr_tx_status_reset(void) { nrf_rtc_event_disable(NRF_RTC0, RTC_EVTENCLR_COMPARE2_Msk); + hal_trigger_crypt_ppi_disable(); + hal_radio_nrf_ppi_channels_disable( #if (HAL_RADIO_ENABLE_TX_ON_TICK_PPI != HAL_RADIO_ENABLE_RX_ON_TICK_PPI) && \ !defined(DPPI_PRESENT) @@ -1152,6 +1156,8 @@ void radio_tmr_rx_status_reset(void) { nrf_rtc_event_disable(NRF_RTC0, RTC_EVTENCLR_COMPARE2_Msk); + hal_trigger_crypt_ppi_disable(); + hal_radio_nrf_ppi_channels_disable( #if (HAL_RADIO_ENABLE_TX_ON_TICK_PPI != HAL_RADIO_ENABLE_RX_ON_TICK_PPI) && \ !defined(DPPI_PRESENT) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index c28cc35a617..3792111292a 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -127,6 +127,14 @@ static inline void hal_trigger_crypt_ppi_config(void) nrf_ccm_subscribe_set(NRF_CCM, NRF_CCM_TASK_CRYPT, HAL_RADIO_RECV_TIMEOUT_CANCEL_PPI); } +/******************************************************************************* + * Disable trigger encryption task + */ +static inline void hal_trigger_crypt_ppi_disable(void) +{ + nrf_ccm_subscribe_clear(NRF_CCM, NRF_CCM_TASK_CRYPT); +} + #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX) /******************************************************************************* * Trigger encryption task on Bit counter match: diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h index 866769c95eb..d964129bfa1 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h @@ -205,6 +205,16 @@ static inline void hal_trigger_crypt_ppi_config(void) /* No need to configure anything for the pre-programmed channel. */ } +/******************************************************************************* + * Disable trigger encryption task + */ +static inline void hal_trigger_crypt_ppi_disable(void) +{ + /* No need to disable anything as ppi channel will be disabled in a + * separate disable ppi call by the caller of this function. + */ +} + #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX) /******************************************************************************* * Trigger encryption task on Bit counter match: From bce70f4a637c8efd602bd72c598182909f5697f0 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 10 Aug 2023 00:37:01 +0530 Subject: [PATCH 0257/1623] [nrf fromtree] Bluetooth: Controller: Fix CIS assymmetric PHY usage Fix CIS assymmetric PHY usage by adding implementation to use correct PHY in radio when switching transceiver. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 652544e3967161a66cf99a4202b9011343e2ec01) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 9e941c2c5eb15527a4bd195fe3a4860b09942345) --- .../controller/ll_sw/nordic/lll/lll_central_iso.c | 12 +++++++++--- .../controller/ll_sw/nordic/lll/lll_peripheral_iso.c | 11 ++++++++++- subsys/bluetooth/controller/ll_sw/ull_central_iso.c | 4 ++++ .../bluetooth/controller/ll_sw/ull_peripheral_iso.c | 2 ++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 6135cc9d863..d287bc794a6 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -488,14 +488,17 @@ static void isr_tx(void *param) /* Get reference to CIS LLL context */ cis_lll = param; + /* Acquire rx node for reception */ + node_rx = ull_iso_pdu_rx_alloc_peek(1U); + LL_ASSERT(node_rx); + #if defined(CONFIG_BT_CTLR_LE_ENC) /* Get reference to ACL context */ const struct lll_conn *conn_lll = ull_conn_lll_get(cis_lll->acl_handle); #endif /* CONFIG_BT_CTLR_LE_ENC */ - /* Acquire rx node for reception */ - node_rx = ull_iso_pdu_rx_alloc_peek(1U); - LL_ASSERT(node_rx); + /* PHY */ + radio_phy_set(cis_lll->rx.phy, PHY_FLAGS_S8); /* Encryption */ if (false) { @@ -1087,6 +1090,9 @@ static void isr_prepare_subevent(void *param) const struct lll_conn *conn_lll = ull_conn_lll_get(cis_lll->acl_handle); #endif /* CONFIG_BT_CTLR_LE_ENC */ + /* PHY */ + radio_phy_set(cis_lll->tx.phy, cis_lll->tx.phy_flags); + /* Encryption */ if (false) { diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 4796696ce73..f089a07bb0b 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -244,7 +244,7 @@ static int prepare_cb(struct lll_prepare_param *p) #endif /* !CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ phy = cis_lll->rx.phy; - radio_phy_set(phy, cis_lll->rx.phy_flags); + radio_phy_set(phy, PHY_FLAGS_S8); radio_aa_set(cis_lll->access_addr); radio_crc_configure(PDU_CRC_POLYNOMIAL, sys_get_le24(conn_lll->crc_init)); lll_chan_set(data_chan_use); @@ -738,6 +738,9 @@ static void isr_rx(void *param) pdu_tx->rfu0 = 0U; pdu_tx->rfu1 = 0U; + /* PHY */ + radio_phy_set(cis_lll->tx.phy, cis_lll->tx.phy_flags); + /* Encryption */ if (false) { @@ -880,6 +883,9 @@ static void isr_tx(void *param) const struct lll_conn *conn_lll = ull_conn_lll_get(cis_lll->acl_handle); #endif /* CONFIG_BT_CTLR_LE_ENC */ + /* PHY */ + radio_phy_set(cis_lll->rx.phy, PHY_FLAGS_S8); + /* Encryption */ if (false) { @@ -1094,6 +1100,9 @@ static void isr_prepare_subevent_common(void *param) const struct lll_conn *conn_lll = ull_conn_lll_get(cis_lll->acl_handle); #endif /* CONFIG_BT_CTLR_LE_ENC */ + /* PHY */ + radio_phy_set(cis_lll->rx.phy, PHY_FLAGS_S8); + /* Encryption */ if (false) { diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 2a19e03bde5..aac5d2057d2 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -136,7 +136,9 @@ uint8_t ll_cis_parameters_set(uint8_t cis_id, ll_iso_setup.stream[cis_idx].c_max_sdu = c_sdu; ll_iso_setup.stream[cis_idx].p_max_sdu = p_sdu; ll_iso_setup.stream[cis_idx].lll.tx.phy = c_phy; + ll_iso_setup.stream[cis_idx].lll.tx.phy_flags = PHY_FLAGS_S8; ll_iso_setup.stream[cis_idx].lll.rx.phy = p_phy; + ll_iso_setup.stream[cis_idx].lll.rx.phy_flags = PHY_FLAGS_S8; ll_iso_setup.stream[cis_idx].central.c_rtn = c_rtn; ll_iso_setup.stream[cis_idx].central.p_rtn = p_rtn; ll_iso_setup.cis_idx++; @@ -635,7 +637,9 @@ uint8_t ll_cis_parameters_test_set(uint8_t cis_id, uint8_t nse, ll_iso_setup.stream[cis_idx].lll.tx.max_pdu = c_bn ? c_pdu : 0U; ll_iso_setup.stream[cis_idx].lll.rx.max_pdu = p_bn ? p_pdu : 0U; ll_iso_setup.stream[cis_idx].lll.tx.phy = c_phy; + ll_iso_setup.stream[cis_idx].lll.tx.phy_flags = PHY_FLAGS_S8; ll_iso_setup.stream[cis_idx].lll.rx.phy = p_phy; + ll_iso_setup.stream[cis_idx].lll.rx.phy_flags = PHY_FLAGS_S8; ll_iso_setup.stream[cis_idx].lll.tx.bn = c_bn; ll_iso_setup.stream[cis_idx].lll.rx.bn = p_bn; ll_iso_setup.cis_idx++; diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index f68ca66656f..d2627502ac2 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -257,11 +257,13 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl, cis->lll.nse = req->nse; cis->lll.rx.phy = req->c_phy; + cis->lll.rx.phy_flags = PHY_FLAGS_S8; cis->lll.rx.bn = req->c_bn; cis->lll.rx.ft = req->c_ft; cis->lll.rx.max_pdu = sys_le16_to_cpu(req->c_max_pdu); cis->lll.tx.phy = req->p_phy; + cis->lll.tx.phy_flags = PHY_FLAGS_S8; cis->lll.tx.bn = req->p_bn; cis->lll.tx.ft = req->p_ft; cis->lll.tx.max_pdu = sys_le16_to_cpu(req->p_max_pdu); From 85b2b7136d56092617648e8bee0e0d860cfbf524 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sun, 24 Sep 2023 07:10:31 +0200 Subject: [PATCH 0258/1623] [nrf fromtree] Bluetooth: Controller: nRF53: Cleanup dppi and dppi resources file Minor cleanup typo, redundant conditional compile and refinition. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit e39d98302d9f9e7640b74f39335b9d59a9bf08ad) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit a0dd720eda6a895c2d4fb09b720e69561714d82d) --- .../controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 4 ++-- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h | 2 +- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_resources.h | 5 ----- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 3792111292a..787755866ab 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -341,7 +341,7 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) /* Wire a SW SWITCH TIMER EVENTS_COMPARE[] event * to a PPI GROUP TASK DISABLE task (PPI group with index ). - * 2 adjacent PPIs (8 & 9) and 2 adjacent PPI groups are used for this wiring; + * 2 adjacent PPIs (14 & 15) and 2 adjacent PPI groups are used for this wiring; * must be 0 or 1. must be a valid TIMER CC register offset. */ #define HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(index) \ @@ -429,10 +429,10 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) (SW_SWITCH_TIMER_EVTS_COMP_PHYEND_DELAY_COMPENSATION_BASE + (index)) #define HAL_SW_SWITCH_RADIO_ENABLE_PHYEND_DELAY_COMPENSATION_PPI(index) \ HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(index) + /* Cancel the SW switch timer running considering PHYEND delay compensation timing: * wire the RADIO EVENTS_CTEPRESENT event to SW_SWITCH_TIMER TASKS_CAPTURE task. */ -#define HAL_SW_SWITCH_TIMER_PHYEND_DELAY_COMPENSATION_DISABLE_PPI 16 #define HAL_SW_SWITCH_TIMER_PHYEND_DELAY_COMPENSATION_DISABLE_PPI_REGISTER_EVT \ NRF_RADIO->PUBLISH_CTEPRESENT diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h index e1b47d03fd7..a8bbe8e63b4 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h @@ -98,7 +98,7 @@ /* Wire a SW SWITCH TIMER EVENTS_COMPARE[] event * to a PPI GROUP TASK DISABLE task (PPI group with index ). - * 2 adjacent PPIs (8 & 9) and 2 adjacent PPI groups are used for this wiring; + * 2 adjacent PPIs (14 & 15) and 2 adjacent PPI groups are used for this wiring; * must be 0 or 1. must be a valid TIMER CC register offset. */ #define HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_BASE 14 diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_resources.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_resources.h index 5c5093f4b52..ab196e17d58 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_resources.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_resources.h @@ -143,9 +143,6 @@ #define HAL_SW_SWITCH_RADIO_ENABLE_PPI_BASE 12 #endif -#if defined(CONFIG_BT_CTLR_PHY_CODED) && \ - defined(CONFIG_HAS_HW_NRF_RADIO_BLE_CODED) - /* Wire the SW SWITCH TIMER EVENTS_COMPARE[] event * to RADIO TASKS_TXEN/RXEN task. */ @@ -156,8 +153,6 @@ */ #define HAL_SW_SWITCH_TIMER_S8_DISABLE_PPI 19 -#endif /* CONFIG_HAS_HW_NRF_RADIO_BLE_CODED */ - #if defined(CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE) /* Wire the SW SWITCH PHYEND delay compensation TIMER EVENTS_COMPARE[] event to software * switch TIMER0->CLEAR taks task. From a91031e38b7c7e412c23636630ae62c0744c6cc9 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Mon, 25 Sep 2023 10:17:22 +0200 Subject: [PATCH 0259/1623] [nrf fromtree] Bluetooth: Controller: nrf53: Fix back-to-back Tx Rx implementation Back-to-back Tx Rx implementation was incorrect for nRF53 that uses DPPI. Both current and next DPPI channels where enabled in the implementation which only worked correctly to have the right tIFS when current and next PDU length were same. Fix ensures that the correct current DPPI is subscribed to by the radio subscribe. The implementation has been refactor to be able to use the current sw_tifs_toggle value in the HAL implementation. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit b61bd2364c1a4267f489910987d7d2c0d14e62c2) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit fbf08870e25889dd450b614168da8a398e6eeb7f) --- .../ll_sw/nordic/hal/nrf5/radio/radio.c | 30 +++++- .../ll_sw/nordic/hal/nrf5/radio/radio.h | 2 + .../nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 100 ++++++++++++------ .../nordic/hal/nrf5/radio/radio_nrf5_ppi.h | 66 +++++++----- .../controller/ll_sw/nordic/lll/lll_adv_iso.c | 2 +- 5 files changed, 133 insertions(+), 67 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 0b41a9bbfb6..a657ab95dfe 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -718,7 +718,7 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla #endif /* CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE */ uint32_t delay; - hal_radio_sw_switch_setup(cc, ppi, sw_tifs_toggle); + hal_radio_sw_switch_setup(sw_tifs_toggle); /* NOTE: As constants are passed to dir_curr and dir_next, the * compiler should optimize out the redundant code path @@ -736,7 +736,7 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla hal_radio_tx_chain_delay_ns_get(phy_curr, flags_curr)); - hal_radio_b2b_txen_on_sw_switch(ppi); + hal_radio_b2b_txen_on_sw_switch(cc, ppi); } else { /* If RX PHY is LE Coded, calculate for S8 coding. * Assumption being, S8 has higher delay. @@ -746,7 +746,7 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla flags_next) + hal_radio_rx_chain_delay_ns_get(phy_curr, 1)); - hal_radio_txen_on_sw_switch(ppi); + hal_radio_txen_on_sw_switch(cc, ppi); } #if defined(CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE) @@ -839,7 +839,7 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla flags_curr)) + (EVENT_CLOCK_JITTER_US << 1); - hal_radio_rxen_on_sw_switch(ppi); + hal_radio_rxen_on_sw_switch(cc, ppi); } else { delay = HAL_RADIO_NS2US_CEIL( hal_radio_rx_ready_delay_ns_get(phy_next, @@ -848,7 +848,7 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla flags_curr)) + (EVENT_CLOCK_JITTER_US << 1); - hal_radio_b2b_rxen_on_sw_switch(ppi); + hal_radio_b2b_rxen_on_sw_switch(cc, ppi); } @@ -982,6 +982,26 @@ void radio_switch_complete_and_b2b_rx(uint8_t phy_curr, uint8_t flags_curr, #endif /* !CONFIG_BT_CTLR_TIFS_HW */ } +void radio_switch_complete_and_b2b_tx_disable(void) +{ +#if defined(CONFIG_BT_CTLR_TIFS_HW) + NRF_RADIO->SHORTS = (RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_DISABLE_Msk); +#else /* CONFIG_BT_CTLR_TIFS_HW */ + NRF_RADIO->SHORTS = (RADIO_SHORTS_READY_START_Msk | NRF_RADIO_SHORTS_PDU_END_DISABLE); + hal_radio_sw_switch_b2b_tx_disable(sw_tifs_toggle); +#endif /* !CONFIG_BT_CTLR_TIFS_HW */ +} + +void radio_switch_complete_and_b2b_rx_disable(void) +{ +#if defined(CONFIG_BT_CTLR_TIFS_HW) + NRF_RADIO->SHORTS = (RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_DISABLE_Msk); +#else /* CONFIG_BT_CTLR_TIFS_HW */ + NRF_RADIO->SHORTS = (RADIO_SHORTS_READY_START_Msk | NRF_RADIO_SHORTS_PDU_END_DISABLE); + hal_radio_sw_switch_b2b_rx_disable(sw_tifs_toggle); +#endif /* !CONFIG_BT_CTLR_TIFS_HW */ +} + void radio_switch_complete_and_disable(void) { #if defined(CONFIG_BT_CTLR_TIFS_HW) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h index 600d7e95481..4bf833b233a 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h @@ -106,6 +106,8 @@ void radio_switch_complete_and_b2b_tx(uint8_t phy_curr, uint8_t flags_curr, uint8_t phy_next, uint8_t flags_next); void radio_switch_complete_and_b2b_rx(uint8_t phy_curr, uint8_t flags_curr, uint8_t phy_next, uint8_t flags_next); +void radio_switch_complete_and_b2b_tx_disable(void); +void radio_switch_complete_and_b2b_rx_disable(void); void radio_switch_complete_and_disable(void); uint8_t radio_phy_flags_rx_get(void); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 787755866ab..1fdf7d90d30 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -455,10 +455,7 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) #endif /* CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE */ -static inline void hal_radio_sw_switch_setup( - uint8_t compare_reg, - uint8_t radio_enable_ppi, - uint8_t ppi_group_index) +static inline void hal_radio_sw_switch_setup(uint8_t ppi_group_index) { /* Set up software switch mechanism for next Radio switch. */ @@ -466,7 +463,7 @@ static inline void hal_radio_sw_switch_setup( * over PPI[] */ HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_EVT = - HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_EVT; + HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_EVT; nrf_dppi_subscribe_set(NRF_DPPIC, HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(ppi_group_index)), HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI); @@ -476,55 +473,70 @@ static inline void hal_radio_sw_switch_setup( nrf_dppi_subscribe_clear(NRF_DPPIC, HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(other_grp))); +} +static inline void hal_radio_txen_on_sw_switch(uint8_t compare_reg_index, uint8_t radio_enable_ppi) +{ /* Wire SW Switch timer event to the * PPI[] for enabling Radio. Do * not wire the task; it is done by the caller of * the function depending on the desired direction * (TX/RX). */ - HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT(compare_reg) = + HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT(compare_reg_index) = HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(radio_enable_ppi); -} -static inline void hal_radio_txen_on_sw_switch(uint8_t ppi) -{ - nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_TXEN, ppi); + nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_TXEN, radio_enable_ppi); } -static inline void hal_radio_b2b_txen_on_sw_switch(uint8_t ppi) +static inline void hal_radio_b2b_txen_on_sw_switch(uint8_t compare_reg_index, + uint8_t radio_enable_ppi) { - /* NOTE: Calling radio_tmr_start/radio_tmr_start_us/radio_tmr_start_now - * after the radio_switch_complete_and_b2b_tx() call would have - * changed the PPI channel to HAL_RADIO_ENABLE_ON_TICK_PPI as we - * cannot double buffer the subscribe buffer. Hence, lets have - * both DPPI channel enabled (other one was enabled by the DPPI - * group when the Radio End occurred) so that when both timer - * trigger one of the DPPI is correct in the radio tx - * subscription. + /* Wire SW Switch timer event to the + * PPI[] for enabling Radio. Do + * not wire the task; it is done by the caller of + * the function depending on the desired direction + * (TX/RX). */ - nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_TXEN, ppi); - nrf_dppi_channels_enable(NRF_DPPIC, BIT(ppi)); + HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT(compare_reg_index) = + HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(radio_enable_ppi); + + uint8_t prev_ppi_idx = (compare_reg_index + 0x01) & 0x01; + + radio_enable_ppi = HAL_SW_SWITCH_RADIO_ENABLE_PPI(prev_ppi_idx); + nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_TXEN, radio_enable_ppi); } -static inline void hal_radio_rxen_on_sw_switch(uint8_t ppi) +static inline void hal_radio_rxen_on_sw_switch(uint8_t compare_reg_index, uint8_t radio_enable_ppi) { - nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_RXEN, ppi); + /* Wire SW Switch timer event to the + * PPI[] for enabling Radio. Do + * not wire the task; it is done by the caller of + * the function depending on the desired direction + * (TX/RX). + */ + HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT(compare_reg_index) = + HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(radio_enable_ppi); + + nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_RXEN, radio_enable_ppi); } -static inline void hal_radio_b2b_rxen_on_sw_switch(uint8_t ppi) +static inline void hal_radio_b2b_rxen_on_sw_switch(uint8_t compare_reg_index, + uint8_t radio_enable_ppi) { - /* NOTE: Calling radio_tmr_start/radio_tmr_start_us/radio_tmr_start_now - * after the radio_switch_complete_and_b2b_rx() call would have - * changed the PPI channel to HAL_RADIO_ENABLE_ON_TICK_PPI as we - * cannot double buffer the subscribe buffer. Hence, lets have - * both DPPI channel enabled (other one was enabled by the DPPI - * group when the Radio End occurred) so that when both timer - * trigger one of the DPPI is correct in the radio rx - * subscription. + /* Wire SW Switch timer event to the + * PPI[] for enabling Radio. Do + * not wire the task; it is done by the caller of + * the function depending on the desired direction + * (TX/RX). */ - nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_RXEN, ppi); - nrf_dppi_channels_enable(NRF_DPPIC, BIT(ppi)); + HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT(compare_reg_index) = + HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(radio_enable_ppi); + + uint8_t prev_ppi_idx = (compare_reg_index + 0x01) & 0x01; + + radio_enable_ppi = HAL_SW_SWITCH_RADIO_ENABLE_PPI(prev_ppi_idx); + nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_RXEN, radio_enable_ppi); } static inline void hal_radio_sw_switch_disable(void) @@ -540,6 +552,26 @@ static inline void hal_radio_sw_switch_disable(void) HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(1))); } +static inline void hal_radio_sw_switch_b2b_tx_disable(uint8_t compare_reg_index) +{ + hal_radio_sw_switch_disable(); + + uint8_t prev_ppi_idx = (compare_reg_index + 0x01) & 0x01; + uint8_t radio_enable_ppi = HAL_SW_SWITCH_RADIO_ENABLE_PPI(prev_ppi_idx); + + nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_TXEN, radio_enable_ppi); +} + +static inline void hal_radio_sw_switch_b2b_rx_disable(uint8_t compare_reg_index) +{ + hal_radio_sw_switch_disable(); + + uint8_t prev_ppi_idx = (compare_reg_index + 0x01) & 0x01; + uint8_t radio_enable_ppi = HAL_SW_SWITCH_RADIO_ENABLE_PPI(prev_ppi_idx); + + nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_RXEN, radio_enable_ppi); +} + static inline void hal_radio_sw_switch_cleanup(void) { hal_radio_sw_switch_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h index d964129bfa1..44cec4621a3 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h @@ -420,10 +420,7 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) #define HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_RX \ ((uint32_t)&(NRF_RADIO->TASKS_RXEN)) -static inline void hal_radio_sw_switch_setup( - uint8_t compare_reg, - uint8_t radio_enable_ppi, - uint8_t ppi_group_index) +static inline void hal_radio_sw_switch_setup(uint8_t ppi_group_index) { /* Set up software switch mechanism for next Radio switch. */ @@ -435,53 +432,58 @@ static inline void hal_radio_sw_switch_setup( HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI, HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_EVT, HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_TASK(ppi_group_index)); +} +static inline void hal_radio_txen_on_sw_switch(uint8_t compare_reg_index, uint8_t radio_enable_ppi) +{ /* Wire SW Switch timer event to the * PPI[] for enabling Radio. Do * not wire the task; it is done by the caller of * the function depending on the desired direction * (TX/RX). */ - nrf_ppi_event_endpoint_setup( - NRF_PPI, - radio_enable_ppi, - HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(compare_reg)); -} + nrf_ppi_event_endpoint_setup(NRF_PPI, radio_enable_ppi, + HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(compare_reg_index)); -static inline void hal_radio_txen_on_sw_switch(uint8_t ppi) -{ - nrf_ppi_task_endpoint_setup( - NRF_PPI, - ppi, - HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_TX); + nrf_ppi_task_endpoint_setup(NRF_PPI, radio_enable_ppi, + HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_TX); } -static inline void hal_radio_b2b_txen_on_sw_switch(uint8_t ppi) +static inline void hal_radio_b2b_txen_on_sw_switch(uint8_t compare_reg_index, + uint8_t radio_enable_ppi) { /* NOTE: As independent PPI are used to trigger the Radio Tx task, * double buffers implementation works for sw_switch using PPIs, * simply reuse the hal_radio_txen_on_sw_switch() functon to set * the next PPIs task to be Radio Tx enable. */ - hal_radio_txen_on_sw_switch(ppi); + hal_radio_txen_on_sw_switch(compare_reg_index, radio_enable_ppi); } -static inline void hal_radio_rxen_on_sw_switch(uint8_t ppi) +static inline void hal_radio_rxen_on_sw_switch(uint8_t compare_reg_index, uint8_t radio_enable_ppi) { - nrf_ppi_task_endpoint_setup( - NRF_PPI, - ppi, - HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_RX); + /* Wire SW Switch timer event to the + * PPI[] for enabling Radio. Do + * not wire the task; it is done by the caller of + * the function depending on the desired direction + * (TX/RX). + */ + nrf_ppi_event_endpoint_setup(NRF_PPI, radio_enable_ppi, + HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(compare_reg_index)); + + nrf_ppi_task_endpoint_setup(NRF_PPI, radio_enable_ppi, + HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_RX); } -static inline void hal_radio_b2b_rxen_on_sw_switch(uint8_t ppi) +static inline void hal_radio_b2b_rxen_on_sw_switch(uint8_t compare_reg_index, + uint8_t radio_enable_ppi) { - /* NOTE: As independent PPI are used to trigger the Radio Rx task, + /* NOTE: As independent PPI are used to trigger the Radio Tx task, * double buffers implementation works for sw_switch using PPIs, - * simply reuse the hal_radio_rxen_on_sw_switch() functon to set - * the next PPIs task to be Radio Rx enable. + * simply reuse the hal_radio_txen_on_sw_switch() functon to set + * the next PPIs task to be Radio Tx enable. */ - hal_radio_rxen_on_sw_switch(ppi); + hal_radio_rxen_on_sw_switch(compare_reg_index, radio_enable_ppi); } static inline void hal_radio_sw_switch_disable(void) @@ -496,6 +498,16 @@ static inline void hal_radio_sw_switch_disable(void) BIT(HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI)); } +static inline void hal_radio_sw_switch_b2b_tx_disable(uint8_t compare_reg_index) +{ + hal_radio_sw_switch_disable(); +} + +static inline void hal_radio_sw_switch_b2b_rx_disable(uint8_t compare_reg_index) +{ + hal_radio_sw_switch_disable(); +} + static inline void hal_radio_sw_switch_cleanup(void) { hal_radio_sw_switch_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c index 87849d0e1fd..20e3fe528e1 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c @@ -717,7 +717,7 @@ static void isr_tx_common(void *param, pkt_flags); } - radio_switch_complete_and_disable(); + radio_switch_complete_and_b2b_tx_disable(); radio_isr_set(isr_done_term, lll); } else { From fd76eac8e690a1181d84cba6a89cdfc3808ef3e7 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 21 Sep 2023 13:18:19 +0200 Subject: [PATCH 0260/1623] [nrf fromtree] Bluetooth: Controller: Fix compile error when BT_CTLR_CENTRAL_SPACING=n Fix compile error when CONFIG_BT_CTLR_CENTRAL_SPACING is undefined. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 1ab007a2ba01bf5888eb13e700c4ecd526602f60) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 6f1be380e58da2555c4c1d4ff49ffc68b5b20cff) --- subsys/bluetooth/controller/ll_sw/ull_central_iso.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index aac5d2057d2..19dec37c937 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -857,13 +857,19 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, cis->offset = cis_offset; #else /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ - if (IS_ENABLED(CONFIG_BT_CTLR_CENTRAL_SPACING) && (CONFIG_BT_CTLR_CENTRAL_SPACING > 0)) { + + if (false) { + +#if defined(CONFIG_BT_CTLR_CENTRAL_SPACING) + } else if (CONFIG_BT_CTLR_CENTRAL_SPACING > 0) { uint32_t cis_offset; cis_offset = MAX((HAL_TICKER_TICKS_TO_US(conn->ull.ticks_slot) + (EVENT_TICKER_RES_MARGIN_US << 1U) + cig->sync_delay - cis->sync_delay), *cis_offset_min); cis->offset = cis_offset; +#endif /* CONFIG_BT_CTLR_CENTRAL_SPACING */ + } else { cis->offset = *cis_offset_min; } From 34f39e4fa35bfc3af1ba376d8bd04b791503e315 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 5 May 2023 10:15:02 +0530 Subject: [PATCH 0261/1623] [nrf fromtree] Bluetooth: Controller: Add BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX Kconfig Add BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX Kconfig to allow the omit of EVENT_OVERHEAD_START_US and EVENT_OVERHEAD_END_US in the time reservation calculations. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 3c2b1f952cdf982635cccf2164a42aa3ef08f814) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit ef922a5dafc0a32ce231ca6aa510d75c1f54418a) --- .../bluetooth/controller/Kconfig.ll_sw_split | 11 +++ .../bluetooth/controller/ll_sw/ull_central.c | 12 ++- .../controller/ll_sw/ull_central_iso.c | 18 +++-- subsys/bluetooth/controller/ll_sw/ull_conn.c | 18 +++-- .../bluetooth/controller/ll_sw/ull_conn_iso.c | 4 +- .../controller/ll_sw/ull_peripheral.c | 23 ++++-- .../controller/ll_sw/ull_peripheral_iso.c | 4 + tests/bluetooth/init/prj_ctlr_5_x_dbg.conf | 76 +++++++++++++++++++ tests/bluetooth/init/testcase.yaml | 10 +++ 9 files changed, 152 insertions(+), 24 deletions(-) create mode 100644 tests/bluetooth/init/prj_ctlr_5_x_dbg.conf diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 4cd8e200b63..3f6f3c10382 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -632,6 +632,17 @@ config BT_CTLR_CENTRAL_RESERVE_MAX Note, currently this value is only used to space multiple central connections and not for actual ticker time reservations. +config BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX + bool "Reserve maximum event overhead in time reservations" + default y + help + Use radio event scheduling CPU time overhead in calculations of event + time reservations. + + If this option is disabled, then Peripheral ACL and Peripheral ISO + role will not include CPU time overhead. Other role will continue to + use CPU overheads in their event time reservations. + config BT_CTLR_SLOT_RESERVATION_UPDATE bool "Update event length reservation after PHY or DLE update" depends on (BT_CTLR_DATA_LENGTH || BT_CTLR_PHY) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central.c b/subsys/bluetooth/controller/ll_sw/ull_central.c index de14395f840..b189c65fa21 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central.c @@ -97,6 +97,7 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, uint16_t max_tx_time; uint16_t max_rx_time; memq_link_t *link; + uint32_t slot_us; uint8_t hop; int err; @@ -360,10 +361,13 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, #endif /* CONFIG_BT_CTLR_ADV_EXT */ #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( - EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + - ready_delay_us + max_tx_time + EVENT_IFS_US + max_rx_time + - (EVENT_CLOCK_JITTER_US << 1)); + /* Calculate event time reservation */ + slot_us = max_tx_time + max_rx_time; + slot_us += EVENT_IFS_US + (EVENT_CLOCK_JITTER_US << 1); + slot_us += ready_delay_us; + slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; + + conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); #if defined(CONFIG_BT_CTLR_PRIVACY) ull_filter_scan_update(filter_policy); diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 19dec37c937..8c516826e06 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -864,9 +864,15 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, } else if (CONFIG_BT_CTLR_CENTRAL_SPACING > 0) { uint32_t cis_offset; - cis_offset = MAX((HAL_TICKER_TICKS_TO_US(conn->ull.ticks_slot) + - (EVENT_TICKER_RES_MARGIN_US << 1U) + cig->sync_delay - - cis->sync_delay), *cis_offset_min); + cis_offset = HAL_TICKER_TICKS_TO_US(conn->ull.ticks_slot) + + (EVENT_TICKER_RES_MARGIN_US << 1U); + + cis_offset += cig->sync_delay - cis->sync_delay; + + if (cis_offset < *cis_offset_min) { + cis_offset = *cis_offset_min; + } + cis->offset = cis_offset; #endif /* CONFIG_BT_CTLR_CENTRAL_SPACING */ @@ -942,8 +948,9 @@ int ull_central_iso_cis_offset_get(uint16_t cis_handle, #endif /* CONFIG_BT_CTLR_CENTRAL_SPACING != 0 */ *cis_offset_min = HAL_TICKER_TICKS_TO_US(conn->ull.ticks_slot) + - (EVENT_TICKER_RES_MARGIN_US << 1U) + - cig->sync_delay - cis->sync_delay; + (EVENT_TICKER_RES_MARGIN_US << 1U); + + *cis_offset_min += cig->sync_delay - cis->sync_delay; return 0; } @@ -984,7 +991,6 @@ static void mfy_cig_offset_get(void *param) offset_min_us += cig->sync_delay - cis->sync_delay; conn = ll_conn_get(cis->lll.acl_handle); - conn_interval_us = (uint32_t)conn->lll.interval * CONN_INT_UNIT_US; while (offset_min_us >= (conn_interval_us + PDU_CIS_OFFSET_MIN_US)) { offset_min_us -= conn_interval_us; diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index a8d3178e020..9d78af7acc1 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -1233,7 +1233,7 @@ void ull_conn_done(struct node_rx_event_done *done) #if defined(CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE) #if defined(CONFIG_BT_CTLR_DATA_LENGTH) || defined(CONFIG_BT_CTLR_PHY) if (lll->evt_len_upd) { - uint32_t ready_delay, rx_time, tx_time, ticks_slot; + uint32_t ready_delay, rx_time, tx_time, ticks_slot, slot_us; lll->evt_len_upd = 0; #if defined(CONFIG_BT_CTLR_PHY) @@ -1257,10 +1257,18 @@ void ull_conn_done(struct node_rx_event_done *done) tx_time = PDU_DC_MAX_US(lll->dle.eff.max_tx_octets, 0); rx_time = PDU_DC_MAX_US(lll->dle.eff.max_rx_octets, 0); #endif /* CONFIG_BT_CTLR_PHY */ - ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( - EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + - ready_delay + EVENT_IFS_US + rx_time + tx_time + - (EVENT_CLOCK_JITTER_US << 1)); + + /* Calculate event time reservation */ + slot_us = tx_time + rx_time; + slot_us += EVENT_IFS_US + (EVENT_CLOCK_JITTER_US << 1); + slot_us += ready_delay; + + if (IS_ENABLED(CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX) || + !conn->lll.role) { + slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; + } + + ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); if (ticks_slot > conn->ull.ticks_slot) { ticks_slot_plus = ticks_slot - conn->ull.ticks_slot; } else { diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index 46c00c305fe..2ec6a73b4a4 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -972,7 +972,9 @@ void ull_conn_iso_start(struct ll_conn *conn, uint16_t cis_handle, /* Below is time reservation for sequential packing */ slot_us = cis->lll.sub_interval * cis->lll.nse; - slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; + if (IS_ENABLED(CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX)) { + slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; + } /* FIXME: How to use ready_delay_us in the time reservation? * i.e. when CISes use different PHYs? Is that even diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c index 8b813fda9fd..5a34f787ec7 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c @@ -89,6 +89,7 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, uint16_t max_rx_time; uint16_t win_offset; memq_link_t *link; + uint32_t slot_us; uint8_t chan_sel; void *node; @@ -360,10 +361,19 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, #endif /* !CONFIG_BT_CTLR_DATA_LENGTH */ #if defined(CONFIG_BT_CTLR_PHY) - ready_delay_us = lll_radio_rx_ready_delay_get(lll->phy_rx, 1); -#else - ready_delay_us = lll_radio_rx_ready_delay_get(0, 0); -#endif + ready_delay_us = lll_radio_rx_ready_delay_get(lll->phy_rx, PHY_FLAGS_S8); +#else /* CONFIG_BT_CTLR_PHY */ + ready_delay_us = lll_radio_rx_ready_delay_get(0U, 0U); +#endif /* CONFIG_BT_CTLR_PHY */ + + /* Calculate event time reservation */ + slot_us = max_rx_time + max_tx_time; + slot_us += EVENT_IFS_US + (EVENT_CLOCK_JITTER_US << 1); + slot_us += ready_delay_us; + + if (IS_ENABLED(CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX)) { + slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; + } /* TODO: active_to_start feature port */ conn->ull.ticks_active_to_start = 0U; @@ -371,10 +381,7 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); conn->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( - EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + - ready_delay_us + max_rx_time + EVENT_IFS_US + max_tx_time + - (EVENT_CLOCK_JITTER_US << 1)); + conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); ticks_slot_offset = MAX(conn->ull.ticks_active_to_start, conn->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index d2627502ac2..eeef778734b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -110,6 +110,10 @@ uint8_t ll_cis_accept(uint16_t handle) } else { cis_offset_min = HAL_TICKER_TICKS_TO_US(conn->ull.ticks_slot) + (EVENT_TICKER_RES_MARGIN_US << 1U); + + if (!IS_ENABLED(CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX)) { + cis_offset_min += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; + } } /* Accept request */ diff --git a/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf b/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf new file mode 100644 index 00000000000..df0d006a13e --- /dev/null +++ b/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf @@ -0,0 +1,76 @@ +CONFIG_BT=y +CONFIG_BT_CTLR=y +CONFIG_BT_LL_SW_SPLIT=y +CONFIG_BT_CTLR_DUP_FILTER_LEN=16 +CONFIG_BT_CTLR_CONN_PARAM_REQ=y +CONFIG_BT_CTLR_LE_PING=y +CONFIG_BT_CTLR_PRIVACY=n +CONFIG_BT_CTLR_EXT_SCAN_FP=n +CONFIG_BT_DATA_LEN_UPDATE=n +CONFIG_BT_PHY_UPDATE=y +CONFIG_BT_CTLR_CHAN_SEL_2=y +CONFIG_BT_CTLR_MIN_USED_CHAN=y +CONFIG_BT_CTLR_ADV_EXT=y +CONFIG_BT_CTLR_ADV_PERIODIC=y +CONFIG_BT_CTLR_ADV_ISO=y +CONFIG_BT_CTLR_SYNC_PERIODIC=y +CONFIG_BT_CTLR_SYNC_ISO=y +CONFIG_BT_CTLR_CENTRAL_ISO=y +CONFIG_BT_CTLR_PERIPHERAL_ISO=y +CONFIG_BT_CTLR_DTM_HCI=y +CONFIG_BT_CTLR_ADVANCED_FEATURES=y +CONFIG_BT_CTLR_PHY_2M=y +CONFIG_BT_CTLR_PHY_2M_NRF=y +CONFIG_BT_CTLR_PHY_CODED=y +CONFIG_BT_CTLR_ADV_AUX_PDU_BACK2BACK=y +CONFIG_BT_CTLR_LLL_PRIO=0 +CONFIG_BT_CTLR_ULL_HIGH_PRIO=1 +CONFIG_BT_CTLR_XTAL_ADVANCED=n +CONFIG_BT_CTLR_SCHED_ADVANCED=y +CONFIG_BT_CTLR_RADIO_ENABLE_FAST=y +CONFIG_BT_CTLR_TIFS_HW=n +CONFIG_BT_CTLR_FAST_ENC=y +CONFIG_BT_CTLR_TX_RETRY_DISABLE=y +CONFIG_BT_CTLR_CONN_RSSI=y +CONFIG_BT_CTLR_ADV_INDICATION=y +CONFIG_BT_CTLR_SCAN_REQ_NOTIFY=y +CONFIG_BT_CTLR_SCAN_REQ_RSSI=y +CONFIG_BT_CTLR_SCAN_INDICATION=y +CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX=n +CONFIG_BT_CTLR_PROFILE_ISR=y +CONFIG_BT_CTLR_DEBUG_PINS=y +CONFIG_BT_CTLR_TEST=y +CONFIG_BT_HCI_VS_EXT=y +CONFIG_BT_HCI_MESH_EXT=n +CONFIG_BT_PERIPHERAL=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_EXT_ADV=y +CONFIG_BT_PER_ADV=y +CONFIG_BT_PER_ADV_SYNC=y +CONFIG_BT_ISO_BROADCASTER=y +CONFIG_BT_ISO_SYNC_RECEIVER=y +CONFIG_BT_ISO_CENTRAL=y +CONFIG_BT_ISO_PERIPHERAL=y +CONFIG_BT_SMP=y +CONFIG_BT_SIGNING=y +CONFIG_BT_SMP_SC_ONLY=y +CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_USE_DEBUG_KEYS=y +CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y +CONFIG_BT_GATT_CLIENT=y +CONFIG_BT_DEBUG_MONITOR_UART=y +CONFIG_BT_HCI_CORE_LOG_LEVEL_DBG=y +CONFIG_BT_CONN_LOG_LEVEL_DBG=y +CONFIG_BT_KEYS_LOG_LEVEL_DBG=y +CONFIG_BT_L2CAP_LOG_LEVEL_DBG=y +CONFIG_BT_SMP_LOG_LEVEL_DBG=y +CONFIG_BT_HCI_DRIVER_LOG_LEVEL_DBG=y +CONFIG_BT_SMP_SELFTEST=y +CONFIG_BT_ATT_LOG_LEVEL_DBG=y +CONFIG_BT_GATT_LOG_LEVEL_DBG=y +CONFIG_BT_BREDR=n +CONFIG_DEBUG=y +CONFIG_FLASH=y +CONFIG_SOC_FLASH_NRF_RADIO_SYNC_TICKER=n +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/bluetooth/init/testcase.yaml b/tests/bluetooth/init/testcase.yaml index c38f5bed69e..17d57ec9d47 100644 --- a/tests/bluetooth/init/testcase.yaml +++ b/tests/bluetooth/init/testcase.yaml @@ -122,6 +122,16 @@ tests: integration_platforms: - nrf52840dk_nrf52840 - nrf52dk_nrf52832 + bluetooth.init.test_ctlr_5_x_dbg: + extra_args: + - CONF_FILE=prj_ctlr_5_x_dbg.conf + - DTC_OVERLAY_FILE=pa_lna.overlay + platform_allow: + - nrf52840dk_nrf52840 + - nrf52dk_nrf52832 + integration_platforms: + - nrf52840dk_nrf52840 + - nrf52dk_nrf52832 bluetooth.init.test_ctlr_sw_switch_single_timer: extra_args: - CONF_FILE=prj_ctlr.conf From be0d9e0314e8bbf148d1eb054c04f003b4c04576 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 26 Sep 2023 22:41:33 +0200 Subject: [PATCH 0262/1623] [nrf fromtree] Bluetooth: Controller: Fix BIS payload sliding window overrun check Fix BIS implementation for checking overrun of the BIS PDU sliding window buffer overrun. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 7af967a2f5dff86f400d7f53be7da79cdc23f2d6) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit d219043b4107e7f6970025d6735bf3b07efb1ef7) --- .../bluetooth/controller/ll_sw/lll_sync_iso.h | 1 - .../ll_sw/nordic/lll/lll_sync_iso.c | 52 +++++++++++++++---- .../bluetooth/controller/ll_sw/ull_sync_iso.c | 3 +- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_sync_iso.h b/subsys/bluetooth/controller/ll_sw/lll_sync_iso.h index 2426f51105e..c47aa433c63 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_sync_iso.h +++ b/subsys/bluetooth/controller/ll_sw/lll_sync_iso.h @@ -74,7 +74,6 @@ struct lll_sync_iso { struct node_rx_pdu *payload[BT_CTLR_SYNC_ISO_STREAM_MAX] [PDU_BIG_PAYLOAD_COUNT_MAX]; uint8_t payload_count_max; - uint8_t payload_head; uint8_t payload_tail; uint32_t window_widening_periodic_us; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c index 5089c6ccde7..12e9fd342b9 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c @@ -489,7 +489,6 @@ static void isr_rx(void *param) uint8_t access_addr[4]; uint16_t data_chan_id; uint8_t data_chan_use; - uint8_t payload_index; uint8_t crc_init[3]; uint8_t rssi_ready; uint32_t start_us; @@ -556,6 +555,8 @@ static void isr_rx(void *param) if (crc_ok) { struct lll_sync_iso_stream *sync_stream; uint16_t stream_handle; + uint8_t payload_offset; + uint8_t payload_index; struct pdu_bis *pdu; /* Check if Control Subevent being received */ @@ -593,21 +594,28 @@ static void isr_rx(void *param) /* TODO: check same CSSN is used in every subevent */ } - /* calculate the payload index in the sliding window */ - payload_index = lll->payload_tail + (lll->bn_curr - 1U) + - (lll->ptc_curr * lll->pto); + /* Check payload buffer overflow */ + payload_offset = (lll->bn_curr - 1U) + + (lll->ptc_curr * lll->pto); + if (payload_offset > lll->payload_count_max) { + goto isr_rx_done; + } + + /* Calculate the payload index in the sliding window */ + payload_index = lll->payload_tail + payload_offset; if (payload_index >= lll->payload_count_max) { payload_index -= lll->payload_count_max; } + /* Get reference to stream context */ stream_handle = lll->stream_handle[lll->stream_curr]; sync_stream = ull_sync_iso_lll_stream_get(stream_handle); - /* store the received PDU */ + /* Store the received PDU if selected stream and not already + * received (say in previous event as pre-transmitted PDU. + */ if ((lll->bis_curr == sync_stream->bis_index) && pdu->len && - !lll->payload[bis_idx][payload_index] && - ((payload_index >= lll->payload_tail) || - (payload_index < lll->payload_head))) { + !lll->payload[bis_idx][payload_index]) { uint16_t handle; if (lll->enc) { @@ -644,10 +652,23 @@ static void isr_rx(void *param) /* Find the next (bn_curr)th subevent to receive PDU */ while (lll->bn_curr < lll->bn) { + uint8_t payload_offset; + uint8_t payload_index; + + /* Next burst number to check for reception required */ lll->bn_curr++; + /* Check payload buffer overflow */ + payload_offset = (lll->bn_curr - 1U); + if (payload_offset > lll->payload_count_max) { + /* (bn_curr)th Rx PDU skip subevent */ + skipped++; + + continue; + } + /* Find the index of the (bn_curr)th Rx PDU buffer */ - payload_index = lll->payload_tail + (lll->bn_curr - 1U); + payload_index = lll->payload_tail + payload_offset; if (payload_index >= lll->payload_count_max) { payload_index -= lll->payload_count_max; } @@ -667,6 +688,11 @@ static void isr_rx(void *param) /* Find the next repetition (irc_curr)th subevent to receive PDU */ if (lll->irc_curr < lll->irc) { if (!new_burst) { + uint8_t payload_index; + + /* Increment to next repetition count and be at first + * burst count for it. + */ lll->bn_curr = 1U; lll->irc_curr++; @@ -715,6 +741,10 @@ static void isr_rx(void *param) if (lll->ptc_curr < lll->ptc) { lll->ptc_curr++; + /* TODO: optimize to skip pre-transmission subevent in case + * of insufficient buffers in sliding window. + */ + /* Receive the (ptc_curr)th Rx PDU of bis_curr */ bis = lll->bis_curr; @@ -733,6 +763,7 @@ static void isr_rx(void *param) stream_handle = lll->stream_handle[lll->stream_curr]; sync_stream = ull_sync_iso_lll_stream_get(stream_handle); if (sync_stream->bis_index <= lll->num_bis) { + uint8_t payload_index; uint8_t bis_idx_new; lll->bis_curr = sync_stream->bis_index; @@ -1058,8 +1089,7 @@ static void isr_rx_done(void *param) bn = lll->bn; while (bn--) { if (lll->payload[bis_idx][payload_tail]) { - node_rx = - lll->payload[bis_idx][payload_tail]; + node_rx = lll->payload[bis_idx][payload_tail]; lll->payload[bis_idx][payload_tail] = NULL; iso_rx_put(node_rx->hdr.link, node_rx); diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c index ff3327ce393..513ee3cdbed 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c @@ -454,10 +454,9 @@ void ull_sync_iso_setup(struct ll_sync_iso_set *sync_iso, /* Initialize payload pointers */ lll->payload_count_max = PDU_BIG_PAYLOAD_COUNT_MAX; - lll->payload_head = 0U; lll->payload_tail = 0U; for (int i = 0; i < CONFIG_BT_CTLR_SYNC_ISO_STREAM_MAX; i++) { - for (int j = 0; j < PDU_BIG_PAYLOAD_COUNT_MAX; j++) { + for (int j = 0; j < lll->payload_count_max; j++) { lll->payload[i][j] = NULL; } } From cd4014a2feb3e7f3ca2aeec959506dd6002ffca0 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 27 Sep 2023 20:16:19 +0200 Subject: [PATCH 0263/1623] [nrf fromtree] Bluetooth: Controller: nRF53: Fix back-to-back PDU chaining Fix back-to-back PDU chaining using DPPI on nRF53x SoC. Relates to commit b61bd2364c1a ("Bluetooth: Controller: nrf53: Fix back-to-back Tx Rx implementation"). Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 1b0cb324f3827ed5dcd08b63de7b8168fc2a3ffa) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 1c6b81d1a2af8c8f5c3cb3306dc02aa6e4a9eacb) --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c | 2 +- subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c index ca566a04db4..6fa0204fb56 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c @@ -394,7 +394,7 @@ static void isr_tx_chain(void *param) lll->phy_s, lll->phy_flags); } else { radio_isr_set(isr_done, lll_aux); - radio_switch_complete_and_disable(); + radio_switch_complete_and_b2b_tx_disable(); } radio_pkt_tx_set(pdu); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c index 1e56f70493c..79a8c6b25cd 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c @@ -367,7 +367,7 @@ static void isr_tx(void *param) switch_radio_complete_and_b2b_tx(lll_sync, lll->phy_s); } else { radio_isr_set(isr_done, lll_sync); - radio_switch_complete_and_disable(); + radio_switch_complete_and_b2b_tx_disable(); } radio_pkt_tx_set(pdu); From 6df62154bb91974ca7dfd26683ec98dca62fef2e Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 28 Aug 2023 14:02:22 +0200 Subject: [PATCH 0264/1623] [nrf fromtree] Bluetooth: Controller: ISO: Fix compile issue with unicast There was a case where TICKER_ID_ADV_AUX_BASE was not available but was attempted to be used. Signed-off-by: Emil Gydesen (cherry picked from commit cbf7312e370eba63586fbd516ab9c54e62b0203f) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 33872e13426421588ace17a53c53aca825fe0722) --- subsys/bluetooth/controller/ll_sw/ull_sched.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_sched.c b/subsys/bluetooth/controller/ll_sw/ull_sched.c index 38589a2e644..4eb7687b97d 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sched.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sched.c @@ -321,7 +321,7 @@ static int group_free_slot_get(uint8_t user_id, uint32_t ticks_slot_abs, if (false) { -#if defined(CONFIG_BT_BROADCASTER) +#if defined(CONFIG_BT_BROADCASTER) && CONFIG_BT_CTLR_ADV_AUX_SET > 0 } else if (IN_RANGE(ticker_id, TICKER_ID_ADV_AUX_BASE, TICKER_ID_ADV_AUX_LAST)) { const struct ll_adv_aux_set *aux; @@ -391,7 +391,7 @@ static int group_free_slot_get(uint8_t user_id, uint32_t ticks_slot_abs, #endif /* CONFIG_BT_CTLR_ADV_ISO */ #endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ -#endif /* CONFIG_BT_BROADCASTER */ +#endif /* CONFIG_BT_BROADCASTER && CONFIG_BT_CTLR_ADV_AUX_SET > 0 */ #if defined(CONFIG_BT_CONN) } else if (IN_RANGE(ticker_id, TICKER_ID_CONN_BASE, From 6721814fdc868cdc5d4f9fb066c58915741ea9bf Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 27 Sep 2023 14:27:33 +0200 Subject: [PATCH 0265/1623] [nrf fromtree] Bluetooth: Controller: Fix ULL_HIGH ticker operations count Fix ULL_HIGH ticker operations count, it is discovered in new BabbleSim test implementations that mesh tests using Extended Advertising and Scanning enqueue upto 4 ticker operations before ULL_LOW ticker_job could process it. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 3bfeadfa4a68666a4e7ec5b8752860c6e9efe844) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit e606f4ed0d9199aa5f257490ef2bf8662c52f74d) --- subsys/bluetooth/controller/ll_sw/ull.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index e6a736f939d..9811076b9ba 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -278,22 +278,21 @@ #define TICKER_USER_ULL_LOW_OPS (1 + TICKER_USER_ULL_LOW_VENDOR_OPS + 1) -/* NOTE: When ULL_LOW priority is configured to lower than ULL_HIGH, then extra - * ULL_HIGH operations queue elements are required to buffer the - * requested ticker operations. +/* NOTE: Extended Advertising needs one extra ticker operation being enqueued + * for scheduling the auxiliary PDU reception while there can already + * be three other operations being enqueued. + * + * This value also covers the case were initiator with 1M and Coded PHY + * scan window is stopping the two scan tickers, stopping one scan stop + * ticker and starting one new ticker for establishing an ACL connection. */ -#if defined(CONFIG_BT_CENTRAL) && defined(CONFIG_BT_CTLR_ADV_EXT) && \ - defined(CONFIG_BT_CTLR_PHY_CODED) +#if defined(CONFIG_BT_CTLR_ADV_EXT) #define TICKER_USER_ULL_HIGH_OPS (4 + TICKER_USER_ULL_HIGH_VENDOR_OPS + \ TICKER_USER_ULL_HIGH_FLASH_OPS + 1) -#else /* !CONFIG_BT_CENTRAL || !CONFIG_BT_CTLR_ADV_EXT || - * !CONFIG_BT_CTLR_PHY_CODED - */ +#else /* !CONFIG_BT_CTLR_ADV_EXT */ #define TICKER_USER_ULL_HIGH_OPS (3 + TICKER_USER_ULL_HIGH_VENDOR_OPS + \ TICKER_USER_ULL_HIGH_FLASH_OPS + 1) -#endif /* !CONFIG_BT_CENTRAL || !CONFIG_BT_CTLR_ADV_EXT || - * !CONFIG_BT_CTLR_PHY_CODED - */ +#endif /* !CONFIG_BT_CTLR_ADV_EXT */ #define TICKER_USER_LLL_OPS (3 + TICKER_USER_LLL_VENDOR_OPS + 1) From 287777875f227f7ba6b1691973f5ae708ff90d16 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 27 Sep 2023 22:02:24 +0200 Subject: [PATCH 0266/1623] [nrf fromtree] Bluetooth: Controller: Fix connected ISO dynamic tx power Fix connected ISO dynamic tx power support compilation error. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 28ed48cbac70c8aaa3905b13040a658830b4d5b7) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit ad506ab73c578540d0e60903dac02e87e0097c5c) --- .../hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf | 3 +++ samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf | 3 +++ .../bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_peripheral_iso.c | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf index bb95b6ea74e..e9e5ac63483 100644 --- a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf @@ -112,3 +112,6 @@ CONFIG_BT_CTLR_ISOAL_SOURCES=2 # ISO Receptions CONFIG_BT_CTLR_ISO_RX_BUFFERS=8 CONFIG_BT_CTLR_ISOAL_SINKS=2 + +# Tx Power Dynamic Control +CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y diff --git a/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf b/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf index 1f976f75f22..3774532c424 100644 --- a/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf @@ -104,3 +104,6 @@ CONFIG_BT_CTLR_ISOAL_SOURCES=2 # ISO Receptions CONFIG_BT_CTLR_ISO_RX_BUFFERS=8 CONFIG_BT_CTLR_ISOAL_SINKS=2 + +# Tx Power Dynamic Control +CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index d287bc794a6..46360ef88d7 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -220,7 +220,7 @@ static int prepare_cb(struct lll_prepare_param *p) radio_reset(); #if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - radio_tx_power_set(cis_lll->tx_pwr_lvl); + radio_tx_power_set(conn_lll->tx_pwr_lvl); #else /* !CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ radio_tx_power_set(RADIO_TXP_DEFAULT); #endif /* !CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ @@ -986,7 +986,7 @@ static void isr_rx(void *param) next_cis_lll->rx.bn_curr = 1U; #if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - radio_tx_power_set(next_cis_lll->tx_pwr_lvl); + radio_tx_power_set(next_conn_lll->tx_pwr_lvl); #else radio_tx_power_set(RADIO_TXP_DEFAULT); #endif diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index f089a07bb0b..13238c081cf 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -238,7 +238,7 @@ static int prepare_cb(struct lll_prepare_param *p) radio_reset(); #if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - radio_tx_power_set(cis_lll->tx_pwr_lvl); + radio_tx_power_set(conn_lll->tx_pwr_lvl); #else /* !CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ radio_tx_power_set(RADIO_TXP_DEFAULT); #endif /* !CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ From 48accabe1924f7c77291a9cad93c26e92df14447 Mon Sep 17 00:00:00 2001 From: Erik Brockhoff Date: Wed, 16 Aug 2023 10:22:49 +0200 Subject: [PATCH 0267/1623] [nrf fromtree] Bluetooth: controller: add missing NTF alloc in central CIS Create If a CIS create is requested prior to having a complete feature exchange the central will initiate a feat exch before enqueing the CIS create. IF then the feature exchange results in peripheral NOT supporting CIS create the central needs to allocate an RX node for the NTF Signed-off-by: Erik Brockhoff (cherry picked from commit 730f7caa21ff178e928263c0f148f198df7be98a) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit f9fb6c01815f05a0db9eda71b764f1d0affa1d44) --- .../bluetooth/controller/ll_sw/ull_llcp_cc.c | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c b/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c index 387cc884dea..69dc80bda13 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c @@ -643,6 +643,7 @@ static void lp_cc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ /* LLCP Local Procedure FSM states */ enum { LP_CC_STATE_IDLE, + LP_CC_STATE_WAIT_NTF_AVAIL, LP_CC_STATE_WAIT_OFFSET_CALC, LP_CC_STATE_WAIT_OFFSET_CALC_TX_REQ, LP_CC_STATE_WAIT_TX_CIS_REQ, @@ -839,7 +840,7 @@ static void lp_cc_st_idle(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t ev } else { /* Peer doesn't support CIS Peripheral so report unsupported */ ctx->data.cis_create.error = BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; - lp_cc_complete(conn, ctx, evt, param); + ctx->state = LP_CC_STATE_WAIT_NTF_AVAIL; } break; default: @@ -854,6 +855,26 @@ static void lp_cc_st_idle(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t ev } } +static void lp_cc_state_wait_ntf_avail(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, + void *param) +{ + switch (evt) { + case LP_CC_EVT_RUN: + if (llcp_ntf_alloc_is_available()) { + ctx->node_ref.rx = llcp_ntf_alloc(); + /* Mark node as RETAIN to trigger put/sched */ + ctx->node_ref.rx->hdr.type = NODE_RX_TYPE_RETAIN; + + /* Now we're good to complete procedure*/ + lp_cc_complete(conn, ctx, evt, param); + } + break; + default: + /* Ignore other evts */ + break; + } +} + static void cc_prepare_cis_ind(struct ll_conn *conn, struct proc_ctx *ctx) { uint8_t err; @@ -1040,6 +1061,9 @@ static void lp_cc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ case LP_CC_STATE_IDLE: lp_cc_st_idle(conn, ctx, evt, param); break; + case LP_CC_STATE_WAIT_NTF_AVAIL: + lp_cc_state_wait_ntf_avail(conn, ctx, evt, param); + break; case LP_CC_STATE_WAIT_OFFSET_CALC_TX_REQ: lp_cc_st_wait_offset_calc_tx_req(conn, ctx, evt, param); break; From 340f46a013f08c35562f1aa1d75464e61246b77e Mon Sep 17 00:00:00 2001 From: Erik Brockhoff Date: Wed, 16 Aug 2023 14:50:04 +0200 Subject: [PATCH 0268/1623] [nrf fromtree] Bluetooth: controller: adding API for unmasking peer features For asymetrical features there needs to be a separate mechanism to unmask features in peer. This must be used in central for unmasking in case of 'unsupported in peer' condition for CIS Create. Signed-off-by: Erik Brockhoff (cherry picked from commit 1de8a76f58bf3f18a8c604d63e7e82070e324c0e) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 26455711ce52d61e86a4c313db7b93e51e7d8fc3) --- subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c | 4 ++-- subsys/bluetooth/controller/ll_sw/ull_llcp_features.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c b/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c index 69dc80bda13..59c23e7a0f6 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c @@ -921,14 +921,14 @@ static void lp_cc_st_wait_rx_cis_rsp(struct ll_conn *conn, struct proc_ctx *ctx, break; case LP_CC_EVT_UNKNOWN: /* Unsupported in peer, so disable locally for this connection */ - feature_unmask_features(conn, LL_FEAT_BIT_CIS_PERIPHERAL); + feature_unmask_peer_features(conn, LL_FEAT_BIT_CIS_PERIPHERAL); ctx->data.cis_create.error = BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; lp_cc_complete(conn, ctx, evt, param); break; case LP_CC_EVT_REJECT: if (pdu->llctrl.reject_ext_ind.error_code == BT_HCI_ERR_UNSUPP_REMOTE_FEATURE) { /* Unsupported in peer, so disable locally for this connection */ - feature_unmask_features(conn, LL_FEAT_BIT_CIS_PERIPHERAL); + feature_unmask_peer_features(conn, LL_FEAT_BIT_CIS_PERIPHERAL); } ctx->data.cis_create.error = pdu->llctrl.reject_ext_ind.error_code; lp_cc_complete(conn, ctx, evt, param); diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_features.h b/subsys/bluetooth/controller/ll_sw/ull_llcp_features.h index ac60206bc70..75d92d5524e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_features.h +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_features.h @@ -9,6 +9,11 @@ static inline void feature_unmask_features(struct ll_conn *conn, uint64_t ll_fea conn->llcp.fex.features_used &= ~ll_feat_mask; } +static inline void feature_unmask_peer_features(struct ll_conn *conn, uint64_t ll_feat_mask) +{ + conn->llcp.fex.features_peer &= ~ll_feat_mask; +} + static inline bool feature_le_encryption(struct ll_conn *conn) { #if defined(CONFIG_BT_CTLR_LE_ENC) From a993ec04f01370731fd9fbdb1eaec298d865beff Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 29 Sep 2023 13:27:51 +0200 Subject: [PATCH 0269/1623] [nrf fromtree] Bluetooth: Controller: Fix regression in Adv PDU overflow calculation Fix regression in Adv PDU payload length overflow calculation. Regression in commit de8c19da5ebf ("Bluetooth: controller: Handle fragmented AD without chaining PDUs"). Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 303ce143c2b8a097a6d0ae489f08ee9b7cea76cc) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit a2ef051537fb3a5e3a4d18baab99d8a0411a175d) --- subsys/bluetooth/controller/ll_sw/ull_adv_aux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c index 5349b21dd9f..302dc6da785 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c @@ -1804,7 +1804,7 @@ uint8_t ull_adv_aux_hdr_set_clear(struct ll_adv_set *adv, /* TODO: need aux_chain_ind support */ if ((sec_len + ad_len + ad_fragment_len) > PDU_AC_PAYLOAD_SIZE_MAX) { /* return excess length */ - *(uint8_t *)hdr_data = sec_len + ad_len - + *(uint8_t *)hdr_data = sec_len + ad_len + ad_fragment_len - PDU_AC_PAYLOAD_SIZE_MAX; if (pri_pdu == pri_pdu_prev) { @@ -2272,7 +2272,7 @@ uint8_t ull_adv_aux_pdu_set_clear(struct ll_adv_set *adv, /* Check AdvData overflow */ if ((len + ad_len + ad_fragment_len) > PDU_AC_PAYLOAD_SIZE_MAX) { /* return excess length */ - *(uint8_t *)hdr_data = len + ad_len - + *(uint8_t *)hdr_data = len + ad_len + ad_fragment_len - PDU_AC_PAYLOAD_SIZE_MAX; /* Will use packet too long error to determine fragmenting From 4b5aac399c721b01dfd7924ce565d367e526fa59 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 28 Sep 2023 14:00:12 +0200 Subject: [PATCH 0270/1623] [nrf fromtree] Bluetooth: Controller: Fix clang warning on ull Fix a clang warning ull.c:1235: warning: use of bitwise '|' with boolean operands The result of ({1/0} &&(int)) is either true(1) or false(0), not the int and therefore bm is not a bitmask, but just true(1) or false(0) all together. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 48f70eba2ba97cf9006bb7751eb35808f1bd2bfe) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 655f1b77f693adfb85ec5280623c47ca00a2ce43) --- subsys/bluetooth/controller/ll_sw/ull.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 9811076b9ba..3130978df4e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -1232,10 +1232,8 @@ void ll_rx_dequeue(void) /* FIXME: use the correct adv and scan set to get * enabled status bitmask */ - bm = (IS_ENABLED(CONFIG_BT_OBSERVER) && - (ull_scan_is_enabled(0) << 1)) | - (IS_ENABLED(CONFIG_BT_BROADCASTER) && - ull_adv_is_enabled(0)); + bm = (IS_ENABLED(CONFIG_BT_OBSERVER)?(ull_scan_is_enabled(0) << 1):0) | + (IS_ENABLED(CONFIG_BT_BROADCASTER)?ull_adv_is_enabled(0):0); if (!bm) { ull_filter_adv_scan_state_cb(0); From 10552082f75c89d7b69b7ad5b4ee815d84348761 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 21 Sep 2023 09:53:02 +0200 Subject: [PATCH 0271/1623] [nrf fromtree] Bluetooth controller nrf: Provide radio hal header for simulated nrf5340 Provide a radio HAL header for the new nrf53 bsim target Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 2243d7b717e090025c7915db23a7392f26d1b64f) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 313eed69c585067c7a9cd74b4d0751b29590f44a) --- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h | 2 + .../nordic/hal/nrf5/radio/radio_sim_nrf5340.h | 431 ++++++++++++++++++ 2 files changed, 433 insertions(+) create mode 100644 subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf5340.h diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h index 9e29ab5f70b..842b4189184 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h @@ -17,6 +17,8 @@ /* SoC specific defines */ #if defined(CONFIG_BOARD_NRF52_BSIM) #include "radio_sim_nrf52.h" +#elif defined(CONFIG_BOARD_NRF5340BSIM_NRF5340_CPUNET) +#include "radio_sim_nrf5340.h" #elif defined(CONFIG_SOC_SERIES_NRF51X) #include "radio_nrf51.h" #elif defined(CONFIG_SOC_NRF52805) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf5340.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf5340.h new file mode 100644 index 00000000000..c0cd88b30b0 --- /dev/null +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf5340.h @@ -0,0 +1,431 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * Copyright (c) 2019 Ioannis Glaropoulos + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* NRF Radio HW timing constants + * - provided in US and NS (for higher granularity) + * - based on the timings configured in the HW models, which are based + * on the product specification + * - Note that this timings are approx. the same as in the real HW, + * but tend to be rounded to the nearest microsecond + */ + +/* Override EVENT_TIMER_ID from 4 to 0, as nRF5340 does not have 4 timer + * instances. + */ +#if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) +#undef EVENT_TIMER_ID +#define EVENT_TIMER_ID 0 + +#undef EVENT_TIMER +#define EVENT_TIMER _CONCAT(NRF_TIMER, EVENT_TIMER_ID) + +#undef SW_SWITCH_TIMER +#define SW_SWITCH_TIMER EVENT_TIMER +#endif /* CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ + +/* TXEN->TXIDLE + TXIDLE->TX (with fast Radio ramp-up mode) + * in microseconds for LE 1M PHY. + */ +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_FAST_NS 41000 +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_FAST_US \ + HAL_RADIO_NS2US_ROUND(HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_FAST_NS) + +/* TXEN->TXIDLE + TXIDLE->TX (with default Radio ramp-up mode) + * in microseconds for LE 1M PHY. + */ +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NS 141000 +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_US \ + HAL_RADIO_NS2US_ROUND(HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NS) + +/* TXEN->TXIDLE + TXIDLE->TX (with default Radio ramp-up mode + * and no HW TIFS auto-switch) in microseconds for LE 1M PHY. + */ + /* 129.5 + 0.8 */ +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NO_HW_TIFS_NS 130000 +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NO_HW_TIFS_US \ + HAL_RADIO_NS2US_ROUND( \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NO_HW_TIFS_NS) + +/* TXEN->TXIDLE + TXIDLE->TX (with fast Radio ramp-up mode) + * in microseconds for LE 2M PHY. + */ +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_FAST_NS 40000 +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_FAST_US \ + HAL_RADIO_NS2US_ROUND(HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_FAST_NS) + +/* TXEN->TXIDLE + TXIDLE->TX (with default Radio ramp-up mode) + * in microseconds for LE 2M PHY. + */ +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NS 140000 +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_US \ + HAL_RADIO_NS2US_ROUND(HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NS) + +/* TXEN->TXIDLE + TXIDLE->TX (with default Radio ramp-up mode and + * no HW TIFS auto-switch) in microseconds for LE 2M PHY. + */ +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NO_HW_TIFS_NS 129000 +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NO_HW_TIFS_US \ + HAL_RADIO_NS2US_ROUND( \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NO_HW_TIFS_NS) + +/* RXEN->RXIDLE + RXIDLE->RX (with fast Radio ramp-up mode) + * in microseconds for LE 1M PHY. + */ +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_FAST_NS 40000 +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_FAST_US \ + HAL_RADIO_NS2US_CEIL(HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_FAST_NS) + +/* RXEN->RXIDLE + RXIDLE->RX (with default Radio ramp-up mode) + * in microseconds for LE 1M PHY. + */ +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NS 140000 +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_US \ + HAL_RADIO_NS2US_CEIL(HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NS) + +/* RXEN->RXIDLE + RXIDLE->RX (with default Radio ramp-up mode and + * no HW TIFS auto-switch) in microseconds for LE 1M PHY. + */ +/* 129.5 + 0.2 */ +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NO_HW_TIFS_NS 129000 +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NO_HW_TIFS_US \ + HAL_RADIO_NS2US_CEIL( \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NO_HW_TIFS_NS) + +/* RXEN->RXIDLE + RXIDLE->RX (with fast Radio ramp-up mode) + * in microseconds for LE 2M PHY. + */ +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_FAST_NS 40000 +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_FAST_US \ + HAL_RADIO_NS2US_CEIL(HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_FAST_NS) + +/* RXEN->RXIDLE + RXIDLE->RX (with default Radio ramp-up mode) + * in microseconds for LE 2M PHY. + */ +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NS 140000 +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_US \ + HAL_RADIO_NS2US_CEIL(HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NS) + +/* RXEN->RXIDLE + RXIDLE->RX (with default Radio ramp-up mode and + * no HW TIFS auto-switch) in microseconds for LE 2M PHY. + */ +/* 129.5 + 0.2 */ +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NO_HW_TIFS_NS 129000 +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NO_HW_TIFS_US \ + HAL_RADIO_NS2US_CEIL( \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NO_HW_TIFS_NS) + +#define HAL_RADIO_NRF5340_TX_CHAIN_DELAY_NS 1000 +#define HAL_RADIO_NRF5340_TX_CHAIN_DELAY_US \ + HAL_RADIO_NS2US_CEIL(HAL_RADIO_NRF5340_TX_CHAIN_DELAY_NS) + +#define HAL_RADIO_NRF5340_RX_CHAIN_DELAY_1M_US 9 +#define HAL_RADIO_NRF5340_RX_CHAIN_DELAY_1M_NS 9000 +#define HAL_RADIO_NRF5340_RX_CHAIN_DELAY_2M_US 5 +#define HAL_RADIO_NRF5340_RX_CHAIN_DELAY_2M_NS 5000 + +#if defined(CONFIG_BT_CTLR_RADIO_ENABLE_FAST) +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_US \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_FAST_US +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_NS \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_FAST_NS + +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_US \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_FAST_US +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_NS \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_FAST_NS + +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_US \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_FAST_US +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_NS \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_FAST_NS + +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_US \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_FAST_US +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_NS \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_FAST_NS + +#else /* !CONFIG_BT_CTLR_RADIO_ENABLE_FAST */ +#if defined(CONFIG_BT_CTLR_TIFS_HW) +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_US \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_US +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_NS \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NS + +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_US \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_US +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_NS \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NS + +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_US \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_US +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_NS \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NS + +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_US \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_US +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_NS \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NS + +#else /* !CONFIG_BT_CTLR_TIFS_HW */ +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_US \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NO_HW_TIFS_US +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_NS \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NO_HW_TIFS_NS + +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_US \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NO_HW_TIFS_US +#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_NS \ + HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NO_HW_TIFS_NS + +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_US \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NO_HW_TIFS_US +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_NS \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NO_HW_TIFS_NS + +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_US \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NO_HW_TIFS_US +#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_NS \ + HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NO_HW_TIFS_NS + +#endif /* !CONFIG_BT_CTLR_TIFS_HW */ +#endif /* !CONFIG_BT_CTLR_RADIO_ENABLE_FAST */ + +/* nRF5340 supports +3dBm Tx Power using high voltage request, define +3dBm + * value for Controller use. + */ +#ifndef RADIO_TXPOWER_TXPOWER_Pos3dBm +#define RADIO_TXPOWER_TXPOWER_Pos3dBm (0x03UL) +#endif + +/* SoC specific NRF_RADIO power-on reset value. Refer to Product Specification, + * RADIO Registers section for the documented reset values. + * + * NOTE: Only implementation used values defined here. + * In the future if MDK or nRFx header include these, use them instead. + */ +#define HAL_RADIO_RESET_VALUE_DFEMODE 0x00000000UL +#define HAL_RADIO_RESET_VALUE_CTEINLINECONF 0x00002800UL + +static inline void hal_radio_tx_power_high_voltage_clear(void); + +static inline void hal_radio_reset(void) +{ +} + +static inline void hal_radio_stop(void) +{ + /* If +3dBm Tx power was used, then turn off high voltage when radio not + * used. + */ + hal_radio_tx_power_high_voltage_clear(); +} + +static inline void hal_radio_ram_prio_setup(void) +{ +} + +static inline uint32_t hal_radio_phy_mode_get(uint8_t phy, uint8_t flags) +{ + uint32_t mode; + + switch (phy) { + case BIT(0): + default: + mode = RADIO_MODE_MODE_Ble_1Mbit; + break; + + case BIT(1): + mode = RADIO_MODE_MODE_Ble_2Mbit; + break; + +#if defined(CONFIG_BT_CTLR_PHY_CODED) + case BIT(2): + if (flags & 0x01) { + mode = RADIO_MODE_MODE_Ble_LR125Kbit; + } else { + mode = RADIO_MODE_MODE_Ble_LR500Kbit; + } + break; +#endif /* CONFIG_BT_CTLR_PHY_CODED */ + } + + return mode; +} + +static inline uint32_t hal_radio_tx_power_max_get(void) +{ + return RADIO_TXPOWER_TXPOWER_0dBm; +} + +static inline uint32_t hal_radio_tx_power_min_get(void) +{ + return RADIO_TXPOWER_TXPOWER_Neg40dBm; +} + +static inline uint32_t hal_radio_tx_power_floor(int8_t tx_power_lvl) +{ + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_0dBm) { + return RADIO_TXPOWER_TXPOWER_0dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg1dBm) { + return RADIO_TXPOWER_TXPOWER_Neg1dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg2dBm) { + return RADIO_TXPOWER_TXPOWER_Neg2dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg3dBm) { + return RADIO_TXPOWER_TXPOWER_Neg3dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg4dBm) { + return RADIO_TXPOWER_TXPOWER_Neg4dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg5dBm) { + return RADIO_TXPOWER_TXPOWER_Neg5dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg6dBm) { + return RADIO_TXPOWER_TXPOWER_Neg6dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg7dBm) { + return RADIO_TXPOWER_TXPOWER_Neg7dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg8dBm) { + return RADIO_TXPOWER_TXPOWER_Neg8dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg12dBm) { + return RADIO_TXPOWER_TXPOWER_Neg12dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg16dBm) { + return RADIO_TXPOWER_TXPOWER_Neg16dBm; + } + + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg20dBm) { + return RADIO_TXPOWER_TXPOWER_Neg20dBm; + } + + /* Note: The -30 dBm power level is deprecated so ignore it! */ + return RADIO_TXPOWER_TXPOWER_Neg40dBm; +} + +static inline void hal_radio_tx_power_high_voltage_set(int8_t tx_power_lvl) +{ + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos3dBm) { + nrf_vreqctrl_radio_high_voltage_set(NRF_VREQCTRL, true); + } +} + +static inline void hal_radio_tx_power_high_voltage_clear(void) +{ + nrf_vreqctrl_radio_high_voltage_set(NRF_VREQCTRL, false); +} + +static inline uint32_t hal_radio_tx_ready_delay_us_get(uint8_t phy, uint8_t flags) +{ + ARG_UNUSED(flags); + + switch (phy) { + default: + case BIT(0): + return HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_US; + case BIT(1): + return HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_US; + } +} + +static inline uint32_t hal_radio_rx_ready_delay_us_get(uint8_t phy, uint8_t flags) +{ + ARG_UNUSED(flags); + + switch (phy) { + default: + case BIT(0): + return HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_US; + case BIT(1): + return HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_US; + } +} + +static inline uint32_t hal_radio_tx_chain_delay_us_get(uint8_t phy, uint8_t flags) +{ + ARG_UNUSED(phy); + ARG_UNUSED(flags); + + return HAL_RADIO_NRF5340_TX_CHAIN_DELAY_US; +} + +static inline uint32_t hal_radio_rx_chain_delay_us_get(uint8_t phy, uint8_t flags) +{ + ARG_UNUSED(flags); + + switch (phy) { + default: + case BIT(0): + return HAL_RADIO_NRF5340_RX_CHAIN_DELAY_1M_US; + case BIT(1): + return HAL_RADIO_NRF5340_RX_CHAIN_DELAY_2M_US; + } +} + +static inline uint32_t hal_radio_tx_ready_delay_ns_get(uint8_t phy, uint8_t flags) +{ + ARG_UNUSED(flags); + + switch (phy) { + default: + case BIT(0): + return HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_NS; + case BIT(1): + return HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_NS; + } +} + +static inline uint32_t hal_radio_rx_ready_delay_ns_get(uint8_t phy, uint8_t flags) +{ + ARG_UNUSED(flags); + + switch (phy) { + default: + case BIT(0): + return HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_NS; + case BIT(1): + return HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_NS; + } +} + +static inline uint32_t hal_radio_tx_chain_delay_ns_get(uint8_t phy, uint8_t flags) +{ + ARG_UNUSED(phy); + ARG_UNUSED(flags); + + return HAL_RADIO_NRF5340_TX_CHAIN_DELAY_NS; +} + +static inline uint32_t hal_radio_rx_chain_delay_ns_get(uint8_t phy, uint8_t flags) +{ + ARG_UNUSED(flags); + + switch (phy) { + default: + case BIT(0): + return HAL_RADIO_NRF5340_RX_CHAIN_DELAY_1M_NS; + case BIT(1): + return HAL_RADIO_NRF5340_RX_CHAIN_DELAY_2M_NS; + + } +} From 495dce2550cd4bba79af1b4429d8ab8f377244d4 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 22 Jun 2023 22:49:14 +0530 Subject: [PATCH 0272/1623] [nrf fromtree] Bluetooth: Controller: Remove HCI ISO data with invalid status Remove incorrect implementation of HCI ISO data with invalid status. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 7a14830d85587d22bcf812f1ec6931c3c35ce02f) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit bd1490cd0d7f2239b4a9125cc86f7a903d25b95f) --- .../ll_sw/nordic/lll/lll_central_iso.c | 97 ++----------------- .../ll_sw/nordic/lll/lll_peripheral_iso.c | 43 -------- 2 files changed, 8 insertions(+), 132 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 46360ef88d7..936087369f1 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -845,7 +845,6 @@ static void isr_rx(void *param) struct lll_conn_iso_group *cig_lll; struct lll_conn *next_conn_lll; uint8_t phy; - uint8_t bn; /* Fetch next CIS */ /* TODO: Use a new ull_conn_iso_lll_stream_get_active_by_group() @@ -861,18 +860,6 @@ static void isr_rx(void *param) goto isr_rx_done; } - /* Adjust sn when flushing Tx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { - lll_flush_tx(cis_lll); - } - - /* Adjust nesn when flushing Rx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { - lll_flush_rx(cis_lll); - } - /* Get reference to ACL context */ next_conn_lll = ull_conn_lll_get(next_cis_lll->acl_handle); @@ -940,45 +927,17 @@ static void isr_rx(void *param) cis_lll = old_cis_lll; } - /* Generate ISO Data Invalid Status */ - bn = cis_lll->rx.bn_curr; - while (bn <= cis_lll->rx.bn) { - struct node_rx_iso_meta *iso_meta; - struct node_rx_pdu *status_node_rx; - - /* Ensure there is always one free for reception - * of ISO PDU by the radio h/w DMA, hence peek - * for two available ISO PDU when using one for - * generating invalid ISO data. - */ - status_node_rx = ull_iso_pdu_rx_alloc_peek(2U); - if (!status_node_rx) { - break; - } - - status_node_rx->hdr.type = NODE_RX_TYPE_ISO_PDU; - status_node_rx->hdr.handle = cis_lll->handle; - iso_meta = &status_node_rx->hdr.rx_iso_meta; - iso_meta->payload_number = (cis_lll->event_count * - cis_lll->rx.bn) + (bn - 1U); - iso_meta->timestamp = - HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + - radio_tmr_ready_restore(); - iso_meta->timestamp %= - HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); - iso_meta->status = 1U; - - ull_iso_pdu_rx_alloc(); - iso_rx_put(status_node_rx->hdr.link, status_node_rx); - - bn++; + /* Adjust sn when flushing Tx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { + lll_flush_tx(cis_lll); } -#if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) - if (bn != cis_lll->rx.bn_curr) { - iso_rx_sched(); + /* Adjust nesn when flushing Rx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { + lll_flush_rx(cis_lll); } -#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ /* Reset indices for the next CIS */ se_curr = 0U; /* isr_prepare_subevent() will increase se_curr */ @@ -1176,7 +1135,6 @@ static void isr_done(void *param) { struct lll_conn_iso_stream *cis_lll; struct event_done_extra *e; - uint8_t bn; lll_isr_status_reset(); @@ -1195,45 +1153,6 @@ static void isr_done(void *param) lll_flush_rx(cis_lll); } - /* Generate ISO Data Invalid Status */ - bn = cis_lll->rx.bn_curr; - while (bn <= cis_lll->rx.bn) { - struct node_rx_iso_meta *iso_meta; - struct node_rx_pdu *node_rx; - - /* Ensure there is always one free for reception of ISO PDU by - * the radio h/w DMA, hence peek for two available ISO PDU when - * using one for generating invalid ISO data. - */ - node_rx = ull_iso_pdu_rx_alloc_peek(2U); - if (!node_rx) { - break; - } - - node_rx->hdr.type = NODE_RX_TYPE_ISO_PDU; - node_rx->hdr.handle = cis_lll->handle; - iso_meta = &node_rx->hdr.rx_iso_meta; - iso_meta->payload_number = (cis_lll->event_count * - cis_lll->rx.bn) + (bn - 1U); - iso_meta->timestamp = - HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + - radio_tmr_ready_restore(); - iso_meta->timestamp %= - HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); - iso_meta->status = 1U; - - ull_iso_pdu_rx_alloc(); - iso_rx_put(node_rx->hdr.link, node_rx); - - bn++; - } - -#if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) - if (bn != cis_lll->rx.bn_curr) { - iso_rx_sched(); - } -#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ - e = ull_event_done_extra_get(); LL_ASSERT(e); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 13238c081cf..3bbdb5fbf90 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -1229,7 +1229,6 @@ static void isr_done(void *param) { struct lll_conn_iso_stream *cis_lll; struct event_done_extra *e; - uint8_t bn; lll_isr_status_reset(); @@ -1242,48 +1241,6 @@ static void isr_done(void *param) lll_flush_rx(cis_lll); } - /* Generate ISO Data Invalid Status */ - bn = cis_lll->rx.bn_curr; - while (bn <= cis_lll->rx.bn) { - struct node_rx_iso_meta *iso_meta; - struct node_rx_pdu *node_rx; - - node_rx = ull_iso_pdu_rx_alloc_peek(2U); - if (!node_rx) { - break; - } - - node_rx->hdr.type = NODE_RX_TYPE_ISO_PDU; - node_rx->hdr.handle = cis_lll->handle; - iso_meta = &node_rx->hdr.rx_iso_meta; - iso_meta->payload_number = (cis_lll->event_count * - cis_lll->rx.bn) + (bn - 1U); - if (trx_performed_bitmask) { - iso_meta->timestamp = cis_lll->offset + - HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + - radio_tmr_aa_restore() - cis_offset_first - - addr_us_get(cis_lll->rx.phy); - } else { - iso_meta->timestamp = cis_lll->offset + - HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + - radio_tmr_ready_restore() - cis_offset_first; - } - iso_meta->timestamp %= - HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); - iso_meta->status = 1U; - - ull_iso_pdu_rx_alloc(); - iso_rx_put(node_rx->hdr.link, node_rx); - - bn++; - } - -#if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) - if (bn != cis_lll->rx.bn_curr) { - iso_rx_sched(); - } -#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ - e = ull_event_done_extra_get(); LL_ASSERT(e); From 7c19e78ea41afa3f5b10c001af8bc84042620830 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sat, 17 Jun 2023 05:05:42 +0530 Subject: [PATCH 0273/1623] [nrf fromtree] Bluetooth: Controller: Use of payload_count for Flush Timeout Use of payload_count for supporting flush timeout in Central and Peripheral ISO Lower Link Layer. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 7fa77a67fc1c924899982bbcde3d87c80b3e13cb) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit ba03122ea83048f49921fe2738d472d4a8085327) --- .../bluetooth/controller/ll_sw/lll_conn_iso.h | 3 +- .../ll_sw/nordic/lll/lll_central_iso.c | 379 ++++++++++------ .../ll_sw/nordic/lll/lll_peripheral_iso.c | 405 +++++++++++------- 3 files changed, 503 insertions(+), 284 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h index 7fdf6bf48d5..9822066f513 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h +++ b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h @@ -16,8 +16,7 @@ struct lll_conn_iso_stream_rxtx { uint64_t bn:4; /* Burst number (BN) */ uint64_t phy:3; /* PHY */ uint64_t rfu:1; - uint8_t bn_curr:4; /* Current burst number */ - + uint8_t bn_curr:4; /* Current burst number */ #if defined(CONFIG_BT_CTLR_LE_ENC) struct ccm ccm; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 936087369f1..d4f4c8c3262 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -40,14 +40,15 @@ #include "hal/debug.h" static int init_reset(void); -static inline void lll_flush_tx(struct lll_conn_iso_stream *cis_lll); -static inline void lll_flush_rx(struct lll_conn_iso_stream *cis_lll); static int prepare_cb(struct lll_prepare_param *p); static void abort_cb(struct lll_prepare_param *prepare_param, void *param); static void isr_tx(void *param); static void isr_rx(void *param); static void isr_prepare_subevent(void *param); static void isr_done(void *param); +static void payload_count_flush(struct lll_conn_iso_stream *cis_lll); +static void payload_count_flush_or_inc_on_close(struct lll_conn_iso_stream *cis_lll); +static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy); static uint16_t next_cis_chan_remap_idx; static uint16_t next_cis_chan_prn_s; @@ -118,24 +119,6 @@ static int init_reset(void) return 0; } -static inline void lll_flush_tx(struct lll_conn_iso_stream *cis_lll) -{ - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - uint8_t sn_update = cis_lll->tx.bn + 1U - cis_lll->tx.bn_curr; - - /* we'll re-use sn_update when implementing flush timeout */ - cis_lll->sn += sn_update; -} - -static inline void lll_flush_rx(struct lll_conn_iso_stream *cis_lll) -{ - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - uint8_t nesn_update = cis_lll->rx.bn + 1U - cis_lll->rx.bn_curr; - - /* we'll re-use sn_update when implementing flush timeout */ - cis_lll->nesn += nesn_update; -} - static int prepare_cb(struct lll_prepare_param *p) { struct lll_conn_iso_group *cig_lll = p->param; @@ -197,24 +180,10 @@ static int prepare_cb(struct lll_prepare_param *p) /* Reset accumulated latencies */ cig_lll->latency_prepare = 0U; - /* Adjust the SN and NESN for skipped CIG events */ - if (cis_lll->event_count) { - uint16_t cis_lazy; - - if (lazy > cis_lll->event_count) { - cis_lazy = lazy - cis_lll->event_count; - } else { - cis_lazy = lazy; - } - - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->sn += cis_lll->tx.bn * cis_lazy; - cis_lll->nesn += cis_lll->rx.bn * cis_lazy; - } - se_curr = 1U; - cis_lll->tx.bn_curr = 1U; - cis_lll->rx.bn_curr = 1U; + + /* Adjust the SN and NESN for skipped CIG events */ + payload_count_lazy(cis_lll, lazy); /* Start setting up of Radio h/w */ radio_reset(); @@ -248,7 +217,8 @@ static int prepare_cb(struct lll_prepare_param *p) struct node_tx_iso *node_tx; memq_link_t *link; - payload_count = cis_lll->event_count * cis_lll->tx.bn; + payload_count = cis_lll->tx.payload_count + + cis_lll->tx.bn_curr - 1U; do { link = memq_peek(cis_lll->memq_tx.head, @@ -399,33 +369,12 @@ static int prepare_cb(struct lll_prepare_param *p) do { cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); if (cis_lll && cis_lll->active) { - if (cis_lll->event_count) { - uint16_t cis_lazy; - - if (lazy > cis_lll->event_count) { - cis_lazy = lazy - cis_lll->event_count; - } else { - cis_lazy = lazy; - } + /* Adjust sn and nesn for skipped CIG events */ + payload_count_lazy(cis_lll, lazy); - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->sn += cis_lll->tx.bn * cis_lazy; - cis_lll->nesn += cis_lll->rx.bn * cis_lazy; - - /* Adjust sn and nesn for canceled events */ - if (err) { - /* Adjust sn when flushing Tx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { - lll_flush_tx(cis_lll); - } - - /* Adjust nesn when flushing Rx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { - lll_flush_rx(cis_lll); - } - } + /* Adjust sn and nesn for canceled events */ + if (err) { + payload_count_flush_or_inc_on_close(cis_lll); } } } while (cis_lll); @@ -450,9 +399,21 @@ static void abort_cb(struct lll_prepare_param *prepare_param, void *param) /* NOTE: This is not a prepare being cancelled */ if (!prepare_param) { + struct lll_conn_iso_stream *next_cis_lll; struct lll_conn_iso_stream *cis_lll; + struct lll_conn_iso_group *cig_lll; cis_lll = ull_conn_iso_lll_stream_get(cis_handle_curr); + cig_lll = param; + + /* Adjust the SN, NESN and payload_count on abort for CISes */ + do { + next_cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, + &cis_handle_curr); + if (next_cis_lll && next_cis_lll->active) { + payload_count_flush_or_inc_on_close(next_cis_lll); + } + } while (next_cis_lll); /* Perform event abort here. * After event has been cleanly aborted, clean up resources @@ -508,8 +469,8 @@ static void isr_tx(void *param) uint64_t payload_count; uint8_t pkt_flags; - payload_count = (cis_lll->event_count * cis_lll->rx.bn) + - (cis_lll->rx.bn_curr - 1U); + payload_count = cis_lll->rx.payload_count + + cis_lll->rx.bn_curr - 1U; cis_lll->rx.ccm.counter = payload_count; @@ -652,7 +613,9 @@ static void isr_tx(void *param) cis_lll = next_cis_lll; /* Tx Ack stale ISO Data */ - payload_count = cis_lll->event_count * cis_lll->tx.bn; + payload_count = cis_lll->tx.payload_count + + cis_lll->tx.bn_curr - 1U; + do { link = memq_peek(cis_lll->memq_tx.head, cis_lll->memq_tx.tail, @@ -687,8 +650,6 @@ static void isr_tx(void *param) static void isr_rx(void *param) { struct lll_conn_iso_stream *cis_lll; - struct node_rx_pdu *node_rx; - struct pdu_cis *pdu_rx; uint8_t ack_pending; uint8_t trx_done; uint8_t crc_ok; @@ -714,6 +675,8 @@ static void isr_rx(void *param) /* No Rx */ if (!trx_done) { + payload_count_flush(cis_lll); + goto isr_rx_next_subevent; } @@ -723,23 +686,23 @@ static void isr_rx(void *param) /* Set the bit corresponding to CIS index */ trx_performed_bitmask |= (1U << LL_CIS_IDX_FROM_HANDLE(cis_lll->handle)); - /* Get reference to received PDU */ - node_rx = ull_iso_pdu_rx_alloc_peek(1U); - LL_ASSERT(node_rx); + if (crc_ok) { + struct node_rx_pdu *node_rx; + struct pdu_cis *pdu_rx; - pdu_rx = (void *)node_rx->pdu; + /* Get reference to received PDU */ + node_rx = ull_iso_pdu_rx_alloc_peek(1U); + LL_ASSERT(node_rx); + pdu_rx = (void *)node_rx->pdu; - if (crc_ok) { /* Tx ACK */ - if (pdu_rx->nesn != cis_lll->sn) { - /* Increment sequence number */ + if ((pdu_rx->nesn != cis_lll->sn) && (cis_lll->tx.bn_curr <= cis_lll->tx.bn)) { cis_lll->sn++; - - /* Increment burst number */ - if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { - - cis_lll->tx.bn_curr++; - + cis_lll->tx.bn_curr++; + if ((cis_lll->tx.bn_curr > cis_lll->tx.bn) && + ((cis_lll->tx.payload_count / cis_lll->tx.bn) < cis_lll->event_count)) { + cis_lll->tx.payload_count += cis_lll->tx.bn; + cis_lll->tx.bn_curr = 1U; } /* TODO: Implement early Tx Ack. Currently Tx Ack @@ -755,7 +718,6 @@ static void isr_rx(void *param) ull_iso_pdu_rx_alloc_peek(2U)) { struct node_rx_iso_meta *iso_meta; - /* Increment next expected sequence number */ cis_lll->nesn++; #if defined(CONFIG_BT_CTLR_LE_ENC) @@ -786,9 +748,8 @@ static void isr_rx(void *param) node_rx->hdr.type = NODE_RX_TYPE_ISO_PDU; node_rx->hdr.handle = cis_lll->handle; iso_meta = &node_rx->hdr.rx_iso_meta; - iso_meta->payload_number = (cis_lll->event_count * - cis_lll->rx.bn) + - (cis_lll->rx.bn_curr - 1U); + iso_meta->payload_number = cis_lll->rx.payload_count + + cis_lll->rx.bn_curr - 1U; iso_meta->timestamp = HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + radio_tmr_ready_restore(); @@ -803,36 +764,23 @@ static void isr_rx(void *param) iso_rx_sched(); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ - /* Increment burst number */ cis_lll->rx.bn_curr++; + if ((cis_lll->rx.bn_curr > cis_lll->rx.bn) && + ((cis_lll->rx.payload_count / cis_lll->rx.bn) < cis_lll->event_count)) { + cis_lll->rx.payload_count += cis_lll->rx.bn; + cis_lll->rx.bn_curr = 1U; + } /* Need to be acked */ ack_pending = 1U; - - /* Handle NULL PDU indication received */ - } else if (pdu_rx->npi) { - /* Source could not send ISO data, increment NESN as if - * we received and expect to receive the next PDU in the - * burst. - */ - if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { - /* Increment next expected serial number */ - cis_lll->nesn++; - - /* Increment burst number */ - cis_lll->rx.bn_curr++; - } - - /* Not NPI, or more than the BN, or no free Rx ISO PDU buffers. - */ - } else { - /* Do nothing, ignore the Rx buffer */ } /* Close Isochronous Event */ cie = cie || pdu_rx->cie; } + payload_count_flush(cis_lll); + /* Close Isochronous Event */ cie = cie || ((cis_lll->rx.bn_curr > cis_lll->rx.bn) && (cis_lll->tx.bn_curr > cis_lll->tx.bn) && @@ -893,7 +841,8 @@ static void isr_rx(void *param) old_cis_lll = cis_lll; cis_lll = next_cis_lll; - payload_count = cis_lll->event_count * cis_lll->tx.bn; + payload_count = cis_lll->tx.payload_count + + cis_lll->tx.bn_curr - 1U; do { link = memq_peek(cis_lll->memq_tx.head, @@ -927,22 +876,10 @@ static void isr_rx(void *param) cis_lll = old_cis_lll; } - /* Adjust sn when flushing Tx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { - lll_flush_tx(cis_lll); - } - - /* Adjust nesn when flushing Rx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { - lll_flush_rx(cis_lll); - } + payload_count_flush_or_inc_on_close(cis_lll); /* Reset indices for the next CIS */ se_curr = 0U; /* isr_prepare_subevent() will increase se_curr */ - next_cis_lll->tx.bn_curr = 1U; - next_cis_lll->rx.bn_curr = 1U; #if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) radio_tx_power_set(next_conn_lll->tx_pwr_lvl); @@ -1001,8 +938,7 @@ static void isr_prepare_subevent(void *param) memq_link_t *link; payload_index = cis_lll->tx.bn_curr - 1U; - payload_count = cis_lll->event_count * cis_lll->tx.bn + - payload_index; + payload_count = cis_lll->tx.payload_count + payload_index; link = memq_peek_n(cis_lll->memq_tx.head, cis_lll->memq_tx.tail, payload_index, (void **)&node_tx); @@ -1141,17 +1077,7 @@ static void isr_done(void *param) /* Get reference to CIS LLL context */ cis_lll = param; - /* Adjust sn when flushing Tx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { - lll_flush_tx(cis_lll); - } - - /* Adjust nesn when flushing Rx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { - lll_flush_rx(cis_lll); - } + payload_count_flush_or_inc_on_close(cis_lll); e = ull_event_done_extra_get(); LL_ASSERT(e); @@ -1166,3 +1092,190 @@ static void isr_done(void *param) lll_isr_cleanup(param); } + +static void payload_count_flush(struct lll_conn_iso_stream *cis_lll) +{ + if (cis_lll->tx.bn) { + uint64_t payload_count; + uint8_t u; + + payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * + (cis_lll->tx.bn - 1U - + (payload_count % cis_lll->tx.bn))); + if ((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) == + (cis_lll->event_count + 1U)) && (u <= se_curr) && + (((cis_lll->tx.bn_curr < cis_lll->tx.bn) && + ((cis_lll->tx.payload_count / cis_lll->tx.bn) <= cis_lll->event_count)) || + ((cis_lll->tx.bn_curr == cis_lll->tx.bn) && + ((cis_lll->tx.payload_count / cis_lll->tx.bn) < cis_lll->event_count)))) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->sn++; + cis_lll->tx.bn_curr++; + if (cis_lll->tx.bn_curr > cis_lll->tx.bn) { + cis_lll->tx.payload_count += cis_lll->tx.bn; + cis_lll->tx.bn_curr = 1U; + } + } + } + + if (cis_lll->rx.bn) { + uint64_t payload_count; + uint8_t u; + + payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * + (cis_lll->rx.bn - 1U - + (payload_count % cis_lll->rx.bn))); + if ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) == + (cis_lll->event_count + 1U)) && (u <= se_curr) && + (((cis_lll->rx.bn_curr < cis_lll->rx.bn) && + ((cis_lll->rx.payload_count / cis_lll->rx.bn) <= cis_lll->event_count)) || + ((cis_lll->rx.bn_curr == cis_lll->rx.bn) && + ((cis_lll->rx.payload_count / cis_lll->rx.bn) < cis_lll->event_count)))) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->nesn++; + cis_lll->rx.bn_curr++; + if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { + cis_lll->rx.payload_count += cis_lll->rx.bn; + cis_lll->rx.bn_curr = 1U; + } + } + } +} + +static void payload_count_flush_or_inc_on_close(struct lll_conn_iso_stream *cis_lll) +{ + if (cis_lll->tx.bn) { + uint64_t payload_count; + uint8_t u; + + if (((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.bn_curr) > + (cis_lll->event_count + cis_lll->tx.bn)) { + cis_lll->tx.payload_count += cis_lll->tx.bn; + cis_lll->tx.bn_curr = 1U; + + goto payload_count_flush_or_inc_on_close_rx; + } + + payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * + (cis_lll->tx.bn - 1U - + (payload_count % cis_lll->tx.bn))); + while ((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) < + (cis_lll->event_count + 1U)) || + ((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) == + (cis_lll->event_count + 1U)) && (u <= (cis_lll->nse + 1U)))) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->sn++; + cis_lll->tx.bn_curr++; + if (cis_lll->tx.bn_curr > cis_lll->tx.bn) { + cis_lll->tx.payload_count += cis_lll->tx.bn; + cis_lll->tx.bn_curr = 1U; + } + + payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * + (cis_lll->tx.bn - 1U - + (payload_count % cis_lll->tx.bn))); + } + } + +payload_count_flush_or_inc_on_close_rx: + if (cis_lll->rx.bn) { + uint64_t payload_count; + uint8_t u; + + if (((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.bn_curr) > + (cis_lll->event_count + cis_lll->rx.bn)) { + cis_lll->rx.payload_count += cis_lll->rx.bn; + cis_lll->rx.bn_curr = 1U; + + return; + } + + payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * + (cis_lll->rx.bn - 1U - + (payload_count % cis_lll->rx.bn))); + while ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) < + (cis_lll->event_count + 1U)) || + ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) == + (cis_lll->event_count + 1U)) && (u <= (cis_lll->nse + 1U)))) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->nesn++; + cis_lll->rx.bn_curr++; + if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { + cis_lll->rx.payload_count += cis_lll->rx.bn; + cis_lll->rx.bn_curr = 1U; + } + + payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * + (cis_lll->rx.bn - 1U - + (payload_count % cis_lll->rx.bn))); + } + } +} + +static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy) +{ + if (cis_lll->tx.bn) { + uint16_t tx_lazy; + + tx_lazy = lazy; + while (tx_lazy--) { + uint64_t payload_count; + uint8_t u; + + payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * + (cis_lll->tx.bn - 1U - + (payload_count % cis_lll->tx.bn))); + while (((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) < + (cis_lll->event_count + 1U)) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->sn++; + cis_lll->tx.bn_curr++; + if (cis_lll->tx.bn_curr > cis_lll->tx.bn) { + cis_lll->tx.payload_count += cis_lll->tx.bn; + cis_lll->tx.bn_curr = 1U; + } + + payload_count = cis_lll->tx.payload_count + + cis_lll->tx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * + (cis_lll->tx.bn - 1U - + (payload_count % cis_lll->tx.bn))); + } + } + } + + if (cis_lll->rx.bn) { + while (lazy--) { + uint64_t payload_count; + uint8_t u; + + payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * + (cis_lll->rx.bn - 1U - + (payload_count % cis_lll->rx.bn))); + while (((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) < + (cis_lll->event_count + 1U)) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->nesn++; + cis_lll->rx.bn_curr++; + if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { + cis_lll->rx.payload_count += cis_lll->rx.bn; + cis_lll->rx.bn_curr = 1U; + } + + payload_count = cis_lll->rx.payload_count + + cis_lll->rx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * + (cis_lll->rx.bn - 1U - + (payload_count % cis_lll->rx.bn))); + } + } + } +} diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 3bbdb5fbf90..75af765f9d0 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -49,8 +49,9 @@ static void isr_prepare_subevent(void *param); static void isr_prepare_subevent_next_cis(void *param); static void isr_prepare_subevent_common(void *param); static void isr_done(void *param); -static inline void lll_flush_tx(struct lll_conn_iso_stream *cis_lll); -static inline void lll_flush_rx(struct lll_conn_iso_stream *cis_lll); +static void payload_count_flush(struct lll_conn_iso_stream *cis_lll); +static void payload_count_rx_flush_or_txrx_inc(struct lll_conn_iso_stream *cis_lll); +static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy); static uint8_t next_chan_use; static uint16_t data_chan_id; @@ -61,7 +62,6 @@ static uint32_t trx_performed_bitmask; static uint16_t cis_offset_first; static uint16_t cis_handle_curr; static uint8_t se_curr; -static uint8_t has_tx; #if defined(CONFIG_BT_CTLR_LE_ENC) static uint8_t mic_state; @@ -135,24 +135,6 @@ static int init_reset(void) return 0; } -static inline void lll_flush_tx(struct lll_conn_iso_stream *cis_lll) -{ - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - uint8_t sn_update = cis_lll->tx.bn + 1U - cis_lll->tx.bn_curr; - - /* TODO we'll re-use sn_update when implementing flush timeout */ - cis_lll->sn += sn_update; -} - -static inline void lll_flush_rx(struct lll_conn_iso_stream *cis_lll) -{ - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - uint8_t nesn_update = cis_lll->rx.bn + 1U - cis_lll->rx.bn_curr; - - /* TODO we'll re-use nesn_update when implementing flush timeout */ - cis_lll->nesn += nesn_update; -} - static int prepare_cb(struct lll_prepare_param *p) { struct lll_conn_iso_group *cig_lll = p->param; @@ -225,14 +207,10 @@ static int prepare_cb(struct lll_prepare_param *p) EVENT_US_TO_US_FRAC(cig_lll->window_widening_max_us); } - /* Adjust sn and nesn for skipped CIG events */ - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->sn += (cis_lll->tx.bn * lazy); - cis_lll->nesn += cis_lll->rx.bn * lazy; - se_curr = 1U; - cis_lll->rx.bn_curr = 1U; - has_tx = 0U; + + /* Adjust sn and nesn for skipped CIG events */ + payload_count_lazy(cis_lll, lazy); /* Start setting up of Radio h/w */ radio_reset(); @@ -260,8 +238,9 @@ static int prepare_cb(struct lll_prepare_param *p) uint64_t payload_cnt; uint8_t pkt_flags; - payload_cnt = (cis_lll->event_count * cis_lll->rx.bn) + - (cis_lll->rx.bn_curr - 1U); + payload_cnt = cis_lll->rx.payload_count + + cis_lll->rx.bn_curr - 1U; + cis_lll->rx.ccm.counter = payload_cnt; pkt_flags = RADIO_PKT_CONF_FLAGS(RADIO_PKT_CONF_PDU_TYPE_CIS, @@ -372,9 +351,10 @@ static int prepare_cb(struct lll_prepare_param *p) /* Adjust the SN and NESN for skipped CIG events */ uint16_t cis_handle = cis_handle_curr; - while (true) { - /* FIXME: Update below implementation when supporting Flush Timeout */ - payload_count = cis_lll->event_count * cis_lll->tx.bn; + do { + payload_count = cis_lll->tx.payload_count + + cis_lll->tx.bn_curr - 1U; + do { link = memq_peek(cis_lll->memq_tx.head, cis_lll->memq_tx.tail, (void **)&tx); @@ -392,26 +372,22 @@ static int prepare_cb(struct lll_prepare_param *p) } } while (link); - cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); + do { + cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); + } while (cis_lll && !cis_lll->active); + if (!cis_lll) { break; } - if (cis_lll->active) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->sn += cis_lll->tx.bn * lazy; - cis_lll->nesn += cis_lll->rx.bn * lazy; - - /* Adjust sn and nesn for canceled events */ - if (err) { - /* Adjust nesn when flushing Rx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { - lll_flush_rx(cis_lll); - } - } + /* Adjust sn and nesn for skipped CIG events */ + payload_count_lazy(cis_lll, lazy); + + /* Adjust sn and nesn for canceled events */ + if (err) { + payload_count_rx_flush_or_txrx_inc(cis_lll); } - }; + } while (cis_lll); /* Return if prepare callback cancelled */ if (err) { @@ -433,24 +409,21 @@ static void abort_cb(struct lll_prepare_param *prepare_param, void *param) /* NOTE: This is not a prepare being cancelled */ if (!prepare_param) { - struct lll_conn_iso_group *cig_lll = param; + struct lll_conn_iso_stream *next_cis_lll; struct lll_conn_iso_stream *cis_lll; + struct lll_conn_iso_group *cig_lll; - cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, NULL); - - /* FIXME: Consider Flush Timeout when resetting current burst number */ - if (!has_tx) { - has_tx = 1U; + cis_lll = ull_conn_iso_lll_stream_get(cis_handle_curr); + cig_lll = param; - /* Adjust nesn when flushing Tx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { - lll_flush_tx(cis_lll); + /* Adjust the SN, NESN and payload_count on abort for CISes */ + do { + next_cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, + &cis_handle_curr); + if (next_cis_lll && next_cis_lll->active) { + payload_count_rx_flush_or_txrx_inc(next_cis_lll); } - - /* Set to last burst number in previous event */ - cis_lll->tx.bn_curr = cis_lll->tx.bn; - } + } while (next_cis_lll); /* Perform event abort here. * After event has been cleanly aborted, clean up resources @@ -500,20 +473,9 @@ static void isr_rx(void *param) /* No Rx */ if (!trx_done) { - /* FIXME: Consider Flush Timeout when resetting current burst number */ - if (!has_tx) { - has_tx = 1U; - - /* Adjust nesn when flushing Tx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { - lll_flush_tx(cis_lll); - } - - /* Start transmitting new burst */ - cis_lll->tx.bn_curr = cis_lll->tx.bn; - } + payload_count_flush(cis_lll); + /* Next subevent or next CIS */ if (se_curr < cis_lll->nse) { radio_isr_set(isr_prepare_subevent, param); } else { @@ -562,17 +524,20 @@ static void isr_rx(void *param) pdu_rx = (void *)node_rx->pdu; /* Tx ACK */ - if (pdu_rx->nesn != cis_lll->sn) { - /* Increment sequence number */ + if ((pdu_rx->nesn != cis_lll->sn) && (cis_lll->tx.bn_curr <= cis_lll->tx.bn)) { cis_lll->sn++; - - /* Increment burst number */ - if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { - cis_lll->tx.bn_curr++; + cis_lll->tx.bn_curr++; + if ((cis_lll->tx.bn_curr > cis_lll->tx.bn) && + ((cis_lll->tx.payload_count / cis_lll->tx.bn) < + cis_lll->event_count)) { + cis_lll->tx.payload_count += cis_lll->tx.bn; + cis_lll->tx.bn_curr = 1U; } - /* TODO: Tx Ack */ - + /* TODO: Implement early Tx Ack. Currently Tx Ack + * generated as stale Tx Ack when payload count + * has elapsed. + */ } /* Handle valid ISO data Rx */ @@ -582,7 +547,6 @@ static void isr_rx(void *param) ull_iso_pdu_rx_alloc_peek(2U)) { struct node_rx_iso_meta *iso_meta; - /* Increment next expected sequence number */ cis_lll->nesn++; #if defined(CONFIG_BT_CTLR_LE_ENC) @@ -614,9 +578,8 @@ static void isr_rx(void *param) node_rx->hdr.type = NODE_RX_TYPE_ISO_PDU; node_rx->hdr.handle = cis_lll->handle; iso_meta = &node_rx->hdr.rx_iso_meta; - iso_meta->payload_number = (cis_lll->event_count * - cis_lll->rx.bn) + - (cis_lll->rx.bn_curr - 1U); + iso_meta->payload_number = cis_lll->rx.payload_count + + cis_lll->rx.bn_curr - 1U; iso_meta->timestamp = cis_lll->offset + HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + radio_tmr_aa_restore() - cis_offset_first - @@ -632,46 +595,19 @@ static void isr_rx(void *param) iso_rx_sched(); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ - /* Increment burst number */ cis_lll->rx.bn_curr++; - - /* Handle NULL PDU indication received */ - } else if (pdu_rx->npi) { - /* Source could not send ISO data, increment NESN as if - * we received and expect to receive the next PDU in the - * burst. - */ - if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { - /* Increment next expected serial number */ - cis_lll->nesn++; - - /* Increment burst number */ - cis_lll->rx.bn_curr++; + if ((cis_lll->rx.bn_curr > cis_lll->rx.bn) && + ((cis_lll->rx.payload_count / cis_lll->rx.bn) < cis_lll->event_count)) { + cis_lll->rx.payload_count += cis_lll->rx.bn; + cis_lll->rx.bn_curr = 1U; } - - /* Not NPI, or more than the BN, or no free Rx ISO PDU buffers. - */ - } else { - /* Do nothing, ignore the Rx buffer */ } /* Close Isochronous Event */ cie = cie || pdu_rx->cie; } - /* FIXME: Consider Flush Timeout when resetting current burst number */ - if (!has_tx) { - has_tx = 1U; - - /* Adjust nesn when flushing Tx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { - lll_flush_tx(cis_lll); - } - - /* Start transmitting new burst */ - cis_lll->tx.bn_curr = 1U; - } + payload_count_flush(cis_lll); /* Close Isochronous Event */ cie = cie || ((cis_lll->rx.bn_curr > cis_lll->rx.bn) && @@ -696,8 +632,7 @@ static void isr_rx(void *param) memq_link_t *link; payload_index = cis_lll->tx.bn_curr - 1U; - payload_count = cis_lll->event_count * cis_lll->tx.bn + - payload_index; + payload_count = cis_lll->tx.payload_count + payload_index; link = memq_peek_n(cis_lll->memq_tx.head, cis_lll->memq_tx.tail, payload_index, (void **)&tx); @@ -801,6 +736,7 @@ static void isr_rx(void *param) &data_chan_prn_s, &data_chan_remap_idx); } else { + struct lll_conn_iso_stream *next_cis_lll; struct lll_conn_iso_group *cig_lll; uint16_t event_counter; uint16_t cis_handle; @@ -809,34 +745,34 @@ static void isr_rx(void *param) cig_lll = ull_conn_iso_lll_group_get_by_stream(cis_lll); cis_handle = cis_handle_curr; do { - cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); - } while (cis_lll && !cis_lll->active); + next_cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); + } while (next_cis_lll && !next_cis_lll->active); - if (!cis_lll) { + if (!next_cis_lll) { /* ISO Event Done */ radio_isr_set(isr_done, param); return; } + payload_count_rx_flush_or_txrx_inc(cis_lll); + cis_handle_curr = cis_handle; /* Event counter value, 0-15 bit of cisEventCounter */ - event_counter = cis_lll->event_count; + event_counter = next_cis_lll->event_count; /* Calculate the radio channel to use for next CIS ISO event */ - data_chan_id = lll_chan_id(cis_lll->access_addr); + data_chan_id = lll_chan_id(next_cis_lll->access_addr); next_chan_use = lll_chan_iso_event(event_counter, data_chan_id, conn_lll->data_chan_map, conn_lll->data_chan_count, &data_chan_prn_s, &data_chan_remap_idx); - /* Reset indices for the next CIS */ - se_curr = 0U; /* isr_tx() will increase se_curr */ - cis_lll->tx.bn_curr = 1U; /* FIXME: may be this should be previous event value? */ - cis_lll->rx.bn_curr = 1U; - has_tx = 0U; + /* Next CIS, se_curr is incremented in isr_tx() */ + cis_lll = next_cis_lll; + se_curr = 0U; } /* Schedule next subevent reception */ @@ -894,8 +830,9 @@ static void isr_tx(void *param) uint64_t payload_count; uint8_t pkt_flags; - payload_count = (cis_lll->event_count * cis_lll->rx.bn) + - (cis_lll->rx.bn_curr - 1U); + payload_count = cis_lll->rx.payload_count + + cis_lll->rx.bn_curr - 1U; + cis_lll->rx.ccm.counter = payload_count; pkt_flags = RADIO_PKT_CONF_FLAGS(RADIO_PKT_CONF_PDU_TYPE_CIS, @@ -996,6 +933,7 @@ static void isr_tx(void *param) static void next_cis_prepare(void *param) { + struct lll_conn_iso_stream *next_cis_lll; struct lll_conn_iso_stream *cis_lll; struct lll_conn_iso_group *cig_lll; uint16_t cis_handle; @@ -1005,12 +943,13 @@ static void next_cis_prepare(void *param) /* Check for next active CIS */ cig_lll = ull_conn_iso_lll_group_get_by_stream(cis_lll); + next_cis_lll = cis_lll; cis_handle = cis_handle_curr; do { - cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); - } while (cis_lll && !cis_lll->active); + next_cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); + } while (next_cis_lll && !next_cis_lll->active); - if (!cis_lll) { + if (!next_cis_lll) { /* ISO Event Done */ radio_isr_set(isr_done, param); @@ -1019,7 +958,7 @@ static void next_cis_prepare(void *param) cis_handle_curr = cis_handle; - radio_isr_set(isr_prepare_subevent_next_cis, cis_lll); + radio_isr_set(isr_prepare_subevent_next_cis, next_cis_lll); } static void isr_prepare_subevent(void *param) @@ -1071,11 +1010,8 @@ static void isr_prepare_subevent_next_cis(void *param) &data_chan_prn_s, &data_chan_remap_idx); - /* Reset indices for the next CIS */ - se_curr = 0U; /* isr_prepare_subevent_common() will increase se_curr */ - cis_lll->tx.bn_curr = 1U; /* FIXME: may be this should be previous event value? */ - cis_lll->rx.bn_curr = 1U; - has_tx = 0U; + /* se_curr is incremented in isr_prepare_subevent_common() */ + se_curr = 0U; isr_prepare_subevent_common(param); } @@ -1111,8 +1047,9 @@ static void isr_prepare_subevent_common(void *param) uint64_t payload_count; uint8_t pkt_flags; - payload_count = (cis_lll->event_count * cis_lll->rx.bn) + - (cis_lll->rx.bn_curr - 1U); + payload_count = cis_lll->rx.payload_count + + cis_lll->rx.bn_curr - 1U; + cis_lll->rx.ccm.counter = payload_count; pkt_flags = RADIO_PKT_CONF_FLAGS(RADIO_PKT_CONF_PDU_TYPE_CIS, @@ -1235,11 +1172,7 @@ static void isr_done(void *param) /* Get reference to CIS LLL context */ cis_lll = param; - /* Adjust nesn when flushing Rx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { - lll_flush_rx(cis_lll); - } + payload_count_rx_flush_or_txrx_inc(cis_lll); e = ull_event_done_extra_get(); LL_ASSERT(e); @@ -1275,3 +1208,177 @@ static void isr_done(void *param) lll_isr_cleanup(param); } + +static void payload_count_flush(struct lll_conn_iso_stream *cis_lll) +{ + if (cis_lll->tx.bn) { + uint64_t payload_count; + uint8_t u; + + payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * + (cis_lll->tx.bn - 1U - + (payload_count % cis_lll->tx.bn))); + while (((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) < + (cis_lll->event_count + 1U)) || + ((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) == + (cis_lll->event_count + 1U)) && (u < se_curr))) && + (((cis_lll->tx.bn_curr < cis_lll->tx.bn) && + ((cis_lll->tx.payload_count / cis_lll->tx.bn) <= cis_lll->event_count)) || + ((cis_lll->tx.bn_curr == cis_lll->tx.bn) && + ((cis_lll->tx.payload_count / cis_lll->tx.bn) < cis_lll->event_count)))) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->sn++; + cis_lll->tx.bn_curr++; + if (cis_lll->tx.bn_curr > cis_lll->tx.bn) { + cis_lll->tx.payload_count += cis_lll->tx.bn; + cis_lll->tx.bn_curr = 1U; + } + + payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * + (cis_lll->tx.bn - 1U - + (payload_count % cis_lll->tx.bn))); + } + } + + if (cis_lll->rx.bn) { + uint64_t payload_count; + uint8_t u; + + payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * + (cis_lll->rx.bn - 1U - + (payload_count % cis_lll->rx.bn))); + if ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) == + (cis_lll->event_count + 1U)) && (u <= se_curr) && + (((cis_lll->rx.bn_curr < cis_lll->rx.bn) && + ((cis_lll->rx.payload_count / cis_lll->rx.bn) <= cis_lll->event_count)) || + ((cis_lll->rx.bn_curr == cis_lll->rx.bn) && + ((cis_lll->rx.payload_count / cis_lll->rx.bn) < cis_lll->event_count)))) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->nesn++; + cis_lll->rx.bn_curr++; + if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { + cis_lll->rx.payload_count += cis_lll->rx.bn; + cis_lll->rx.bn_curr = 1U; + } + } + } +} + +static void payload_count_rx_flush_or_txrx_inc(struct lll_conn_iso_stream *cis_lll) +{ + if (cis_lll->tx.bn) { + if (((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.bn_curr) > + (cis_lll->event_count + cis_lll->tx.bn)) { + cis_lll->tx.payload_count += cis_lll->tx.bn; + cis_lll->tx.bn_curr = 1U; + } + } + + if (cis_lll->rx.bn) { + uint64_t payload_count; + uint8_t u; + + if (((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.bn_curr) > + (cis_lll->event_count + cis_lll->rx.bn)) { + cis_lll->rx.payload_count += cis_lll->rx.bn; + cis_lll->rx.bn_curr = 1U; + + return; + } + + payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * + (cis_lll->rx.bn - 1U - + (payload_count % cis_lll->rx.bn))); + while ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) < + (cis_lll->event_count + 1U)) || + ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) == + (cis_lll->event_count + 1U)) && (u <= (cis_lll->nse + 1U)))) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->nesn++; + cis_lll->rx.bn_curr++; + if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { + cis_lll->rx.payload_count += cis_lll->rx.bn; + cis_lll->rx.bn_curr = 1U; + } + + payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * + (cis_lll->rx.bn - 1U - + (payload_count % cis_lll->rx.bn))); + } + } +} + +static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy) +{ + if (cis_lll->tx.bn && lazy) { + uint16_t tx_lazy; + + tx_lazy = lazy; + while (tx_lazy--) { + uint64_t payload_count; + uint8_t u; + + payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * + (cis_lll->tx.bn - 1U - + (payload_count % cis_lll->tx.bn))); + while (((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) < + (cis_lll->event_count + 1U)) || + ((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) == + (cis_lll->event_count + 1U)) && (u < (cis_lll->nse + 1U)))) && + ((cis_lll->tx.payload_count / cis_lll->tx.bn) < + cis_lll->event_count)) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->sn++; + cis_lll->tx.bn_curr++; + if (cis_lll->tx.bn_curr > cis_lll->tx.bn) { + cis_lll->tx.payload_count += cis_lll->tx.bn; + cis_lll->tx.bn_curr = 1U; + } + + payload_count = cis_lll->tx.payload_count + + cis_lll->tx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * + (cis_lll->tx.bn - 1U - + (payload_count % cis_lll->tx.bn))); + } + } + } + + if (cis_lll->rx.bn) { + while (lazy--) { + uint64_t payload_count; + uint8_t u; + + payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * + (cis_lll->rx.bn - 1U - + (payload_count % cis_lll->rx.bn))); + while (((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) < + (cis_lll->event_count + 1U)) || + ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) == + (cis_lll->event_count + 1U)) && (u <= (cis_lll->nse + 1U)))) && + ((cis_lll->rx.payload_count / cis_lll->rx.bn) < + cis_lll->event_count)) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->nesn++; + cis_lll->rx.bn_curr++; + if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { + cis_lll->rx.payload_count += cis_lll->rx.bn; + cis_lll->rx.bn_curr = 1U; + } + + payload_count = cis_lll->rx.payload_count + + cis_lll->rx.bn_curr - 1U; + u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * + (cis_lll->rx.bn - 1U - + (payload_count % cis_lll->rx.bn))); + } + } + } +} From 2694658063e3e5667cd8871632c23b268f71b54a Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 22 Jun 2023 22:36:05 +0530 Subject: [PATCH 0274/1623] [nrf fromtree] Bluetooth: Controller: Fix ISO Data timestamp when FT > 1 Fix ISO data timestamp to reflect the SDU reference point and not the ISO event anchor point when PDUs received after retransmissions. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit e3ecab3142031383783764fbb9d9016931127e4a) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit a9e55d8302d01ec1f61433d6f91375a718d89785) --- subsys/bluetooth/controller/ll_sw/lll_conn_iso.h | 3 +++ .../controller/ll_sw/nordic/lll/lll_central_iso.c | 7 ++++++- .../controller/ll_sw/nordic/lll/lll_peripheral_iso.c | 5 +++++ subsys/bluetooth/controller/ll_sw/ull_central_iso.c | 1 + subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h index 9822066f513..0321b96f638 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h +++ b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h @@ -77,6 +77,9 @@ struct lll_conn_iso_group { uint8_t role:1; /* 0: CENTRAL, 1: PERIPHERAL*/ uint8_t paused:1; /* 1: CIG is paused */ + /* ISO interval to calculate timestamp under FT > 1 */ + uint32_t iso_interval_us; + /* Accumulates LLL prepare callback latencies */ uint16_t latency_prepare; uint16_t latency_event; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index d4f4c8c3262..4bf44a42cd9 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -716,6 +716,7 @@ static void isr_rx(void *param) (cis_lll->rx.bn_curr <= cis_lll->rx.bn) && (pdu_rx->sn == cis_lll->nesn) && ull_iso_pdu_rx_alloc_peek(2U)) { + struct lll_conn_iso_group *cig_lll; struct node_rx_iso_meta *iso_meta; cis_lll->nesn++; @@ -753,6 +754,10 @@ static void isr_rx(void *param) iso_meta->timestamp = HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + radio_tmr_ready_restore(); + cig_lll = ull_conn_iso_lll_group_get_by_stream(cis_lll); + iso_meta->timestamp -= (cis_lll->event_count - + (cis_lll->rx.payload_count / cis_lll->rx.bn)) * + cig_lll->iso_interval_us; iso_meta->timestamp %= HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); iso_meta->status = 0U; @@ -788,8 +793,8 @@ static void isr_rx(void *param) isr_rx_next_subevent: if (cie || (se_curr == cis_lll->nse)) { - struct lll_conn_iso_stream *old_cis_lll; struct lll_conn_iso_stream *next_cis_lll; + struct lll_conn_iso_stream *old_cis_lll; struct lll_conn_iso_group *cig_lll; struct lll_conn *next_conn_lll; uint8_t phy; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 75af765f9d0..25401f5564e 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -545,6 +545,7 @@ static void isr_rx(void *param) (cis_lll->rx.bn_curr <= cis_lll->rx.bn) && (pdu_rx->sn == cis_lll->nesn) && ull_iso_pdu_rx_alloc_peek(2U)) { + struct lll_conn_iso_group *cig_lll; struct node_rx_iso_meta *iso_meta; cis_lll->nesn++; @@ -584,6 +585,10 @@ static void isr_rx(void *param) HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + radio_tmr_aa_restore() - cis_offset_first - addr_us_get(cis_lll->rx.phy); + cig_lll = ull_conn_iso_lll_group_get_by_stream(cis_lll); + iso_meta->timestamp -= (cis_lll->event_count - + (cis_lll->rx.payload_count / cis_lll->rx.bn)) * + cig_lll->iso_interval_us; iso_meta->timestamp %= HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); iso_meta->status = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 8c516826e06..62a684bbfa9 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -254,6 +254,7 @@ uint8_t ll_cig_parameters_commit(uint8_t cig_id, uint16_t *handles) } iso_interval_us = cig->iso_interval * ISO_INT_UNIT_US; + cig->lll.iso_interval_us = iso_interval_us; lll_hdr_init(&cig->lll, cig); max_se_length = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index eeef778734b..a707341f41c 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -191,6 +191,7 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl, cig->iso_interval = sys_le16_to_cpu(req->iso_interval); iso_interval_us = cig->iso_interval * CONN_INT_UNIT_US; + cig->lll.iso_interval_us = iso_interval_us; cig->cig_id = req->cig_id; cig->lll.handle = LLL_HANDLE_INVALID; From 41b3a58b1641934eec748c66d57846f0e4ef56e0 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 8 Jun 2023 10:17:33 +0530 Subject: [PATCH 0275/1623] [nrf fromtree] Bluetooth: Controller: Option to ignore Tx ISO Data Packet Seq Num Kconfig option to turn off ISO Data Packet Sequence Number use to place the ISO Data in the correct radio event, instead simply buffer it to next radio event. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 61d00467b469e816dfd6933bfef038422ddf36c7) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 25d7b75e319814171d5ec32d9f47c5e103b0ad22) --- .../bluetooth/controller/Kconfig.ll_sw_split | 9 +- subsys/bluetooth/controller/hci/hci.c | 108 +++++++++++++++--- .../controller/ll_sw/ull_central_iso.c | 3 + .../controller/ll_sw/ull_conn_iso_types.h | 4 + .../controller/ll_sw/ull_peripheral_iso.c | 3 + 5 files changed, 111 insertions(+), 16 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 3f6f3c10382..a7dade7a1db 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -499,7 +499,8 @@ config BT_CTLR_SCAN_ENABLE_STRICT config BT_CTLR_ISOAL_SN_STRICT bool "Enforce Strict Tx ISO Data Sequence Number use" - depends on BT_CTLR_ADV_ISO || BT_CTLR_CONN_ISO + depends on !BT_CTLR_ISOAL_PSN_IGNORE && (BT_CTLR_ADV_ISO || \ + BT_CTLR_CONN_ISO) default y help Enforce strict sequencing of released payloads based on the TX SDU's @@ -517,6 +518,12 @@ config BT_CTLR_ISOAL_SN_STRICT dropped. This will result in better delivery of data to the receiver but at the cost of creating skews in the received stream of SDUs. +config BT_CTLR_ISOAL_PSN_IGNORE + bool "Ignore Tx ISO Data Packet Sequence Number use" + depends on BT_CTLR_ADV_ISO || BT_CTLR_CONN_ISO + help + Ignore the use of Tx ISO Data Packet Sequence Number. + config BT_CTLR_ZLI bool "Use Zero Latency IRQs" depends on ZERO_LATENCY_IRQS diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 0adbf5ff70c..b2c95271b2c 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -5657,8 +5657,6 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) struct bt_hci_iso_data_hdr *iso_data_hdr; struct isoal_sdu_tx sdu_frag_tx; struct bt_hci_iso_hdr *iso_hdr; - struct ll_iso_datapath *dp_in; - struct ll_iso_stream_hdr *hdr; uint32_t *time_stamp; uint16_t handle; uint8_t pb_flag; @@ -5668,8 +5666,6 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) iso_data_hdr = NULL; *evt = NULL; - hdr = NULL; - dp_in = NULL; if (buf->len < sizeof(*iso_hdr)) { LOG_ERR("No HCI ISO header"); @@ -5747,16 +5743,49 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) * data path */ } else if (IS_CIS_HANDLE(handle)) { - struct ll_conn_iso_stream *cis = - ll_iso_stream_connected_get(handle); + struct ll_conn_iso_stream *cis; + struct ll_conn_iso_group *cig; + struct ll_iso_stream_hdr *hdr; + struct ll_iso_datapath *dp_in; + + cis = ll_iso_stream_connected_get(handle); if (!cis) { return -EINVAL; } - struct ll_conn_iso_group *cig = cis->group; - uint8_t event_offset; + cig = cis->group; - hdr = &(cis->hdr); +#if defined(CONFIG_BT_CTLR_ISOAL_PSN_IGNORE) + uint64_t event_count; + uint64_t pkt_seq_num; + + /* Catch up local pkt_seq_num with internal pkt_seq_num */ + event_count = cis->lll.event_count; + pkt_seq_num = event_count + 1U; + if (!(pb_flag & 0x01) && + (((pkt_seq_num - cis->pkt_seq_num) & + BIT64_MASK(39)) <= BIT64_MASK(38))) { + cis->pkt_seq_num = pkt_seq_num; + } else { + pkt_seq_num = cis->pkt_seq_num; + } + + /* Pre-increment, for next ISO data packet seq num comparison */ + if (pb_flag & 0x10) { + cis->pkt_seq_num++; + } + + /* Target next event to avoid overlapping with current event */ + pkt_seq_num++; + sdu_frag_tx.target_event = pkt_seq_num; + sdu_frag_tx.grp_ref_point = + isoal_get_wrapped_time_us(cig->cig_ref_point, + ((pkt_seq_num - event_count) * + cig->iso_interval * + ISO_INT_UNIT_US)); + +#else /* !CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ + uint8_t event_offset; /* We must ensure sufficient time for ISO-AL to fragment SDU and * deliver PDUs to the TX queue. By checking ull_ref_get, we @@ -5780,11 +5809,15 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) } sdu_frag_tx.target_event = cis->lll.event_count + event_offset; - sdu_frag_tx.grp_ref_point = isoal_get_wrapped_time_us(cig->cig_ref_point, - (event_offset * cig->iso_interval * - ISO_INT_UNIT_US)); + sdu_frag_tx.grp_ref_point = + isoal_get_wrapped_time_us(cig->cig_ref_point, + (event_offset * + cig->iso_interval * + ISO_INT_UNIT_US)); +#endif /* !CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ /* Get controller's input data path for CIS */ + hdr = &(cis->hdr); dp_in = hdr->datapath_in; if (!dp_in || dp_in->path_id != BT_HCI_DATAPATH_ID_HCI) { LOG_ERR("Input data path not set for HCI"); @@ -5817,8 +5850,6 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) struct ll_adv_iso_set *adv_iso; struct lll_adv_iso *lll_iso; uint16_t stream_handle; - uint8_t target_event; - uint8_t event_offset; uint16_t slen; /* FIXME: Code only expects header present */ @@ -5844,6 +5875,53 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) return -EINVAL; } + lll_iso = &adv_iso->lll; + +#if defined(CONFIG_BT_CTLR_ISOAL_PSN_IGNORE) + uint64_t event_count; + uint64_t pkt_seq_num; + + /* Catch up local pkt_seq_num with internal pkt_seq_num */ + event_count = lll_iso->payload_count / lll_iso->bn; + pkt_seq_num = event_count; + if (!(pb_flag & 0x01) && + (((pkt_seq_num - stream->pkt_seq_num) & + BIT64_MASK(39)) <= BIT64_MASK(38))) { + stream->pkt_seq_num = pkt_seq_num; + } else { + pkt_seq_num = stream->pkt_seq_num; + } + + /* Pre-increment, for next ISO data packet seq num comparison */ + if (pb_flag & 0x10) { + stream->pkt_seq_num++; + } + + /* Target next event to avoid overlapping with current event */ + /* FIXME: Implement ISO Tx ack generation early in done compared + * to currently only in prepare. I.e. to ensure upper + * layer has the number of completed packet before the + * next BIG event, so as to supply new ISO data packets. + * Without which upper layers need extra buffers to + * buffer next ISO data packet. + * + * Enable below increment once early Tx ack is + * implemented. + * + * pkt_seq_num++; + */ + sdu_frag_tx.target_event = pkt_seq_num; + sdu_frag_tx.grp_ref_point = + isoal_get_wrapped_time_us(adv_iso->big_ref_point, + (((pkt_seq_num + 1U) - + event_count) * + lll_iso->iso_interval * + ISO_INT_UNIT_US)); + +#else /* !CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ + uint8_t target_event; + uint8_t event_offset; + /* Determine the target event and the first event offset after * datapath setup. * event_offset mitigates the possibility of first SDU being @@ -5861,7 +5939,6 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) * BIG event by incrementing the previous elapsed big_ref_point * by one additional ISO interval. */ - lll_iso = &adv_iso->lll; target_event = lll_iso->payload_count / lll_iso->bn; event_offset = ull_ref_get(&adv_iso->ull) ? 0U : 1U; event_offset += lll_iso->latency_prepare; @@ -5872,6 +5949,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) ((event_offset + 1U) * lll_iso->iso_interval * ISO_INT_UNIT_US)); +#endif /* !CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ /* Start Fragmentation */ /* FIXME: need to ensure ISO-AL returns proper isoal_status. diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 62a684bbfa9..474b8d0dbe9 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -883,6 +883,9 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, #endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ cis->central.instant = instant; +#if defined(CONFIG_BT_CTLR_ISOAL_PSN_IGNORE) + cis->pkt_seq_num = 0U; +#endif /* CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ cis->lll.event_count = LLL_CONN_ISO_EVENT_COUNT_MAX; cis->lll.next_subevent = 0U; cis->lll.sn = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h b/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h index e8ca29da7af..39cee21d0b1 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h @@ -48,6 +48,10 @@ struct ll_conn_iso_stream { */ uint8_t terminate_reason; uint8_t cis_id; + +#if defined(CONFIG_BT_CTLR_ISOAL_PSN_IGNORE) + uint64_t pkt_seq_num:39; +#endif /* CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ }; struct ll_conn_iso_group { diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index a707341f41c..843bf877935 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -326,6 +326,9 @@ uint8_t ull_peripheral_iso_setup(struct pdu_data_llctrl_cis_ind *ind, cis->sync_delay = sys_get_le24(ind->cis_sync_delay); cis->offset = cis_offset; memcpy(cis->lll.access_addr, ind->aa, sizeof(ind->aa)); +#if defined(CONFIG_BT_CTLR_ISOAL_PSN_IGNORE) + cis->pkt_seq_num = 0U; +#endif /* CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ cis->lll.event_count = LLL_CONN_ISO_EVENT_COUNT_MAX; cis->lll.next_subevent = 0U; cis->lll.sn = 0U; From 227cc39f8b9b67c4f3bce67a3e85df5d24a49073 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 4 Aug 2023 14:04:35 +0530 Subject: [PATCH 0276/1623] [nrf fromtree] tests: bsim: Bluetooth: Test RTN=2, FT=2, Per skip 2 SE in Controller Test RTN=2, FT=2 in Controller with 2 subevents dropped by peripheral. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 2935d3b731d551230c0dcdf13afed61f0716d601) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 29bd2a979f972f9dfa034d9c90d3e25d6b9cfa9e) --- .../ll_sw/nordic/lll/lll_peripheral_iso.c | 9 +++++- tests/bsim/bluetooth/ll/cis/Kconfig | 19 +++++++++++++ .../overlay-acl_first_ft_per_skip_2_se.conf | 9 ++++++ tests/bsim/bluetooth/ll/cis/prj.conf | 1 + tests/bsim/bluetooth/ll/cis/src/main.c | 28 ++++++++++++++----- ...onnected_iso_acl_first_ft_per_skip_2_se.sh | 24 ++++++++++++++++ tests/bsim/bluetooth/ll/compile.sh | 1 + 7 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_per_skip_2_se.conf create mode 100755 tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 25401f5564e..c33c82d4c70 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -472,7 +472,14 @@ static void isr_rx(void *param) cis_lll = param; /* No Rx */ - if (!trx_done) { + if (!trx_done || +#if defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) + ((((cis_lll->event_count % 3U) < CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT) && + ((se_curr > cis_lll->nse) || (se_curr <= 2U))) || + (((cis_lll->event_count % 3U) < (CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT + 1U)) && + ((se_curr > cis_lll->nse) || (se_curr <= 1U)))) || +#endif + false) { payload_count_flush(cis_lll); /* Next subevent or next CIS */ diff --git a/tests/bsim/bluetooth/ll/cis/Kconfig b/tests/bsim/bluetooth/ll/cis/Kconfig index b59a46be4fc..532a26f5d52 100644 --- a/tests/bsim/bluetooth/ll/cis/Kconfig +++ b/tests/bsim/bluetooth/ll/cis/Kconfig @@ -16,6 +16,25 @@ config TEST_MULTIPLE_PERIPERAL_CIS help Multiple Peripheral CIS establishment. +config TEST_FT_SKIP_SUBEVENTS + bool + help + Skip central and/or peripheral subevent reception to test flush + timeout implementation. + +config TEST_FT_PER_SKIP_SUBEVENTS + bool "Skip peripheral role subevents to test Flush Timeout" + select TEST_FT_SKIP_SUBEVENTS + help + Skip peripheral role subevent reception to test flush timeout + implementation. + +config TEST_FT_PER_SKIP_EVENTS_COUNT + int "Skip peripheral ISO events count, all subevents in them" + depends on TEST_FT_PER_SKIP_SUBEVENTS + help + Skip peripheral ISO events count where all subevents are skipped. + config BT_CTLR_SCAN_UNRESERVED default y if TEST_CONNECT_ACL_FIRST help diff --git a/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_per_skip_2_se.conf b/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_per_skip_2_se.conf new file mode 100644 index 00000000000..bfbe36115f5 --- /dev/null +++ b/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_per_skip_2_se.conf @@ -0,0 +1,9 @@ +CONFIG_TEST_USE_LEGACY_ADVERTISING=n +CONFIG_TEST_CONNECT_ACL_FIRST=y +CONFIG_TEST_FT_PER_SKIP_SUBEVENTS=y +CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT=1 +CONFIG_BT_MAX_CONN=1 +CONFIG_BT_ISO_MAX_CHAN=1 +CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=9 +CONFIG_BT_CTLR_ADVANCED_FEATURES=y +CONFIG_BT_CTLR_ISOAL_PSN_IGNORE=y diff --git a/tests/bsim/bluetooth/ll/cis/prj.conf b/tests/bsim/bluetooth/ll/cis/prj.conf index 0b6b764393b..a4d3c3e8c5f 100644 --- a/tests/bsim/bluetooth/ll/cis/prj.conf +++ b/tests/bsim/bluetooth/ll/cis/prj.conf @@ -13,6 +13,7 @@ CONFIG_BT_MAX_CONN=9 CONFIG_BT_ISO_MAX_CHAN=9 CONFIG_BT_ISO_TX_BUF_COUNT=18 CONFIG_BT_ISO_TX_MTU=120 +CONFIG_BT_ISO_RX_MTU=120 CONFIG_BT_BUF_CMD_TX_SIZE=255 CONFIG_BT_BUF_EVT_RX_SIZE=255 diff --git a/tests/bsim/bluetooth/ll/cis/src/main.c b/tests/bsim/bluetooth/ll/cis/src/main.c index a9538e3e9c6..720adc16ef9 100644 --- a/tests/bsim/bluetooth/ll/cis/src/main.c +++ b/tests/bsim/bluetooth/ll/cis/src/main.c @@ -53,6 +53,7 @@ static bt_addr_le_t peer_addr; #define ISO_INTERVAL_US 10000U #define ISO_LATENCY_MS DIV_ROUND_UP(ISO_INTERVAL_US, USEC_PER_MSEC) +#define ISO_LATENCY_FT_MS 20U #define BT_CONN_US_TO_INTERVAL(t) ((uint16_t)((t) * 4U / 5U / USEC_PER_MSEC)) @@ -103,7 +104,7 @@ static bt_addr_le_t peer_addr; #define NAME_LEN 30 -#define BUF_ALLOC_TIMEOUT (30) /* milliseconds */ +#define BUF_ALLOC_TIMEOUT (40) /* milliseconds */ NET_BUF_POOL_FIXED_DEFINE(tx_pool, CONFIG_BT_ISO_TX_BUF_COUNT, BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), 8, NULL); @@ -300,8 +301,11 @@ static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *in expected_seq_num[index] = seq_num; } - expected_seq_num[index]++; + expected_seq_num[index] += 1U; +#if defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) + expected_seq_num[index] += ((CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT - 1U) * 2U); +#endif } else if (expected_seq_num[index] && expected_seq_num[index] < SEQ_NUM_MAX) { FAIL("%s: Invalid ISO data after valid ISO data reception.\n" @@ -361,7 +365,11 @@ static void test_cis_central(void) for (int i = 0; i < CONFIG_BT_ISO_MAX_CHAN; i++) { iso_tx[i].sdu = CONFIG_BT_ISO_TX_MTU; iso_tx[i].phy = BT_GAP_LE_PHY_2M; - iso_tx[i].rtn = 0U; + if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { + iso_tx[i].rtn = 2U; + } else { + iso_tx[i].rtn = 0U; + } iso_tx[i].path = NULL; iso_qos[i].tx = &iso_tx[i]; @@ -381,7 +389,11 @@ static void test_cis_central(void) cig_param.sca = BT_GAP_SCA_UNKNOWN; cig_param.packing = 0U; cig_param.framing = 0U; - cig_param.latency = ISO_LATENCY_MS; + if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { + cig_param.latency = ISO_LATENCY_FT_MS; + } else { + cig_param.latency = ISO_LATENCY_MS; + } cig_param.interval = ISO_INTERVAL_US; printk("Create CIG..."); @@ -404,7 +416,7 @@ static void test_cis_central(void) uint8_t conn_index; uint8_t chan; - printk("Start scanning..."); + printk("Start scanning (%d)...", i); err = bt_le_scan_start(BT_LE_SCAN_CUSTOM, NULL); if (err) { FAIL("Could not start scan: %d\n", err); @@ -510,7 +522,7 @@ static void test_cis_central(void) ret = bt_iso_chan_send(&iso_chan[chan], buf, seq_num, BT_ISO_TIMESTAMP_NONE); if (ret < 0) { - FAIL("Unable to broadcast data on channel %u" + FAIL("Unable to send data on channel %u" " : %d\n", chan, ret); net_buf_unref(buf); return; @@ -522,7 +534,7 @@ static void test_cis_central(void) } } - k_sleep(K_MSEC(100)); + k_sleep(K_MSEC(1000)); for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { printk("ISO disconnect channel %u...", chan); @@ -587,6 +599,8 @@ static int iso_accept(const struct bt_iso_accept_info *info, *chan = &iso_chan_p[chan_count]; chan_count++; + printk("Accepted on channel %p\n", *chan); + return 0; } diff --git a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh new file mode 100755 index 00000000000..307d865a117 --- /dev/null +++ b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Copyright 2020 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + +# Basic Connected ISO test: a Central connects to 1 Peripheral and tests RTN=2, +# FT=2, skips 2 subevents in the peripheral +simulation_id="connected_iso_acl_first_ft_per_skip_2_se" +verbosity_level=2 +EXECUTE_TIMEOUT=60 + +cd ${BSIM_OUT_PATH}/bin + +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_cis_prj_conf_overlay-acl_first_ft_per_skip_2_se_conf \ + -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central + +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_cis_prj_conf_overlay-acl_first_ft_per_skip_2_se_conf \ + -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral + +Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ + -D=2 -sim_length=30e6 $@ + +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/compile.sh b/tests/bsim/bluetooth/ll/compile.sh index 2369192e0cc..28ca40b322c 100755 --- a/tests/bsim/bluetooth/ll/compile.sh +++ b/tests/bsim/bluetooth/ll/compile.sh @@ -39,6 +39,7 @@ app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-legacy_adv_acl_first.conf c app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_group.conf compile app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_group_acl_first.conf compile app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-peripheral_cis.conf compile +app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_first_ft_per_skip_2_se.conf compile app=tests/bsim/bluetooth/ll/edtt/hci_test_app \ conf_file=prj_dut_llcp.conf compile From 5e04a9f2a3a99b319901d0eca3cdc361c75acc45 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 4 Aug 2023 14:04:35 +0530 Subject: [PATCH 0277/1623] [nrf fromtree] tests: bsim: Bluetooth: Test RTN=2, FT=2, Cen skip 2 SE in Controller Test RTN=2, FT=2 in Controller with 2 subevents dropped by central. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 291cd03818e909c20fed720c4773c82c2eabbd71) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit b6158c0004470aeca9c36a7bf4eb04193d0fa3d0) --- .../ll_sw/nordic/lll/lll_central_iso.c | 9 +- tests/bsim/bluetooth/ll/cis/Kconfig | 13 ++ .../overlay-acl_first_ft_cen_skip_2_se.conf | 9 ++ tests/bsim/bluetooth/ll/cis/src/main.c | 114 +++++++++++++++++- ...onnected_iso_acl_first_ft_cen_skip_2_se.sh | 24 ++++ tests/bsim/bluetooth/ll/compile.sh | 2 + 6 files changed, 164 insertions(+), 7 deletions(-) create mode 100644 tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_cen_skip_2_se.conf create mode 100755 tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 4bf44a42cd9..9c2184b9942 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -674,7 +674,14 @@ static void isr_rx(void *param) cis_lll = param; /* No Rx */ - if (!trx_done) { + if (!trx_done || +#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) + ((((cis_lll->event_count % 3U) < CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT) && + ((se_curr > cis_lll->nse) || (se_curr <= 2U))) || + (((cis_lll->event_count % 3U) < (CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT + 1U)) && + ((se_curr > cis_lll->nse) || (se_curr <= 1U)))) || +#endif + false) { payload_count_flush(cis_lll); goto isr_rx_next_subevent; diff --git a/tests/bsim/bluetooth/ll/cis/Kconfig b/tests/bsim/bluetooth/ll/cis/Kconfig index 532a26f5d52..6076f88ae3c 100644 --- a/tests/bsim/bluetooth/ll/cis/Kconfig +++ b/tests/bsim/bluetooth/ll/cis/Kconfig @@ -35,6 +35,19 @@ config TEST_FT_PER_SKIP_EVENTS_COUNT help Skip peripheral ISO events count where all subevents are skipped. +config TEST_FT_CEN_SKIP_SUBEVENTS + bool "Skip central role subevents to test Flush Timeout" + select TEST_FT_SKIP_SUBEVENTS + help + Skip central role subevent reception to test flush timeout + implementation. + +config TEST_FT_CEN_SKIP_EVENTS_COUNT + int "Skip central ISO events count, all subevents in them" + depends on TEST_FT_CEN_SKIP_SUBEVENTS + help + Skip central ISO events count where all subevents are skipped. + config BT_CTLR_SCAN_UNRESERVED default y if TEST_CONNECT_ACL_FIRST help diff --git a/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_cen_skip_2_se.conf b/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_cen_skip_2_se.conf new file mode 100644 index 00000000000..194a23ffec6 --- /dev/null +++ b/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_cen_skip_2_se.conf @@ -0,0 +1,9 @@ +CONFIG_TEST_USE_LEGACY_ADVERTISING=n +CONFIG_TEST_CONNECT_ACL_FIRST=y +CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS=y +CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT=1 +CONFIG_BT_MAX_CONN=1 +CONFIG_BT_ISO_MAX_CHAN=1 +CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=9 +CONFIG_BT_CTLR_ADVANCED_FEATURES=y +CONFIG_BT_CTLR_ISOAL_PSN_IGNORE=y diff --git a/tests/bsim/bluetooth/ll/cis/src/main.c b/tests/bsim/bluetooth/ll/cis/src/main.c index 720adc16ef9..15e102981d6 100644 --- a/tests/bsim/bluetooth/ll/cis/src/main.c +++ b/tests/bsim/bluetooth/ll/cis/src/main.c @@ -296,15 +296,19 @@ static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *in seq_num = sys_get_le32(buf->data); if (info->flags & BT_ISO_FLAGS_VALID) { if (seq_num != expected_seq_num[index]) { - FAIL("ISO data miss match, expected %u actual %u\n", - expected_seq_num[index], seq_num); + if (expected_seq_num[index]) { + FAIL("ISO data miss match, expected %u actual %u\n", + expected_seq_num[index], seq_num); + } expected_seq_num[index] = seq_num; } expected_seq_num[index] += 1U; -#if defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) +#if defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) expected_seq_num[index] += ((CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT - 1U) * 2U); +#elif defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) + expected_seq_num[index] += ((CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT - 1U) * 2U); #endif } else if (expected_seq_num[index] && expected_seq_num[index] < SEQ_NUM_MAX) { @@ -342,6 +346,7 @@ static struct bt_iso_chan_ops iso_ops = { static void test_cis_central(void) { struct bt_iso_chan_io_qos iso_tx[CONFIG_BT_ISO_MAX_CHAN]; + struct bt_iso_chan_io_qos iso_rx[CONFIG_BT_ISO_MAX_CHAN]; struct bt_iso_chan_qos iso_qos[CONFIG_BT_ISO_MAX_CHAN]; struct bt_iso_chan *channels[CONFIG_BT_ISO_MAX_CHAN]; struct bt_conn *conn_list[CONFIG_BT_MAX_CONN]; @@ -372,8 +377,27 @@ static void test_cis_central(void) } iso_tx[i].path = NULL; - iso_qos[i].tx = &iso_tx[i]; - iso_qos[i].rx = NULL; + if (!IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS) || + IS_ENABLED(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS)) { + iso_qos[i].tx = &iso_tx[i]; + } else { + iso_qos[i].tx = NULL; + } + + iso_rx[i].sdu = CONFIG_BT_ISO_RX_MTU; + iso_rx[i].phy = BT_GAP_LE_PHY_2M; + if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { + iso_rx[i].rtn = 2U; + } else { + iso_rx[i].rtn = 0U; + } + iso_rx[i].path = NULL; + + if (IS_ENABLED(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS)) { + iso_qos[i].rx = &iso_rx[i]; + } else { + iso_qos[i].rx = NULL; + } iso_chan[i].ops = &iso_ops; iso_chan[i].qos = &iso_qos[i]; @@ -406,6 +430,12 @@ static void test_cis_central(void) conn_count = 0U; +#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) + for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + expected_seq_num[chan] = (CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT - 1U) * 2U; + } +#endif + #if !defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) for (int i = 0; i < CONFIG_BT_MAX_CONN; i++) { #else @@ -493,6 +523,7 @@ static void test_cis_central(void) printk("connected to peer %d ISO channel.\n", chan); } +#if !defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) || defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { @@ -535,6 +566,9 @@ static void test_cis_central(void) } k_sleep(K_MSEC(1000)); +#else + k_sleep(K_SECONDS(11)); +#endif for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { printk("ISO disconnect channel %u...", chan); @@ -573,6 +607,16 @@ static void test_cis_central(void) } #endif +#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) + for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + if (expected_seq_num[chan] < SEQ_NUM_MAX) { + FAIL("ISO Data reception incomplete %u (%u).\n", + expected_seq_num[chan], SEQ_NUM_MAX); + return; + } + } +#endif + PASS("Central ISO tests Passed\n"); } @@ -613,6 +657,7 @@ static struct bt_iso_server iso_server = { static void test_cis_peripheral(void) { + struct bt_iso_chan_io_qos iso_tx_p[CONFIG_BT_ISO_MAX_CHAN]; int err; printk("Bluetooth initializing..."); @@ -624,7 +669,18 @@ static void test_cis_peripheral(void) printk("success.\n"); for (int i = 0; i < CONFIG_BT_ISO_MAX_CHAN; i++) { - iso_rx_p[i].sdu = CONFIG_BT_ISO_TX_MTU; + iso_tx_p[i].sdu = CONFIG_BT_ISO_TX_MTU; + iso_tx_p[i].phy = BT_GAP_LE_PHY_2M; + if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { + iso_tx_p[i].rtn = 2U; + } else { + iso_tx_p[i].rtn = 0U; + } + iso_tx_p[i].path = NULL; + + iso_qos_p[i].tx = &iso_tx_p[i]; + + iso_rx_p[i].sdu = CONFIG_BT_ISO_RX_MTU; iso_qos_p[i].rx = &iso_rx_p[i]; @@ -698,7 +754,51 @@ static void test_cis_peripheral(void) #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) } +#endif + +#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) + for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { + for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + uint8_t iso_data[CONFIG_BT_ISO_TX_MTU] = { 0, }; + struct net_buf *buf; + int ret; + buf = net_buf_alloc(&tx_pool, + K_MSEC(BUF_ALLOC_TIMEOUT)); + if (!buf) { + FAIL("Data buffer allocate timeout on channel" + " %u\n", chan); + return; + } + net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); + sys_put_le32(seq_num, iso_data); + net_buf_add_mem(buf, iso_data, sizeof(iso_data)); + + ret = k_sem_take(&sem_iso_data, + K_MSEC(BUF_ALLOC_TIMEOUT)); + if (ret) { + FAIL("k_sem_take for ISO data sent failed.\n"); + return; + } + + printk("ISO send: seq_num %u, chan %u\n", seq_num, chan); + ret = bt_iso_chan_send(&iso_chan_p[chan], buf, + seq_num, BT_ISO_TIMESTAMP_NONE); + if (ret < 0) { + FAIL("Unable to send data on channel %u" + " : %d\n", chan, ret); + net_buf_unref(buf); + return; + } + } + + if ((seq_num % 100) == 0) { + printk("Sending value %u\n", seq_num); + } + } +#endif + +#if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { #endif @@ -722,6 +822,7 @@ static void test_cis_peripheral(void) } printk("disconnected from peer device.\n"); +#if !defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) || defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { #else @@ -734,6 +835,7 @@ static void test_cis_peripheral(void) } #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) } +#endif #endif PASS("Peripheral ISO tests Passed\n"); diff --git a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh new file mode 100755 index 00000000000..04ce474e812 --- /dev/null +++ b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Copyright 2020 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + +# Basic Connected ISO test: a Central connects to 1 Peripheral and tests RTN=2, +# FT=2, skips 2 subevents in the central +simulation_id="connected_iso_acl_first_ft_cen_skip_2_se" +verbosity_level=2 +EXECUTE_TIMEOUT=60 + +cd ${BSIM_OUT_PATH}/bin + +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_cis_prj_conf_overlay-acl_first_ft_cen_skip_2_se_conf \ + -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central + +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_cis_prj_conf_overlay-acl_first_ft_cen_skip_2_se_conf \ + -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral + +Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ + -D=2 -sim_length=30e6 $@ + +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/compile.sh b/tests/bsim/bluetooth/ll/compile.sh index 28ca40b322c..6d530d05d72 100755 --- a/tests/bsim/bluetooth/ll/compile.sh +++ b/tests/bsim/bluetooth/ll/compile.sh @@ -40,6 +40,8 @@ app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_group.conf compile app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_group_acl_first.conf compile app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-peripheral_cis.conf compile app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_first_ft_per_skip_2_se.conf compile +app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_first_ft_per_skip_4_se.conf compile +app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_first_ft_cen_skip_2_se.conf compile app=tests/bsim/bluetooth/ll/edtt/hci_test_app \ conf_file=prj_dut_llcp.conf compile From a96ce9920c747042b8d5bd3a86c2a854c8e49706 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 27 Sep 2023 11:21:26 +0200 Subject: [PATCH 0278/1623] [nrf fromtree] Bluetooth: Controller: Review rework flush timeout support Review rework changed related to flush timeout support. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit a178aa9855bd9f9f33d822f95d0eb0c3a35ab26c) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 95d12af31a5afb5eef80546b43e9739227471cd7) --- subsys/bluetooth/controller/hci/hci.c | 44 +++- .../bluetooth/controller/ll_sw/lll_conn_iso.h | 28 ++- .../ll_sw/nordic/lll/lll_central_iso.c | 19 +- .../ll_sw/nordic/lll/lll_peripheral_iso.c | 8 + tests/bsim/bluetooth/ll/cis/src/main.c | 206 +++++++++--------- ...onnected_iso_acl_first_ft_cen_skip_2_se.sh | 2 +- ...onnected_iso_acl_first_ft_per_skip_2_se.sh | 2 +- 7 files changed, 181 insertions(+), 128 deletions(-) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index b2c95271b2c..c3dd070720b 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -5762,6 +5762,18 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) /* Catch up local pkt_seq_num with internal pkt_seq_num */ event_count = cis->lll.event_count; pkt_seq_num = event_count + 1U; + /* If pb_flag is BT_ISO_START (0b00) or BT_ISO_SINGLE (0b10) + * then we simply check that the pb_flag is an even value, and + * then pkt_seq_num is a future sequence number value compare + * to last recorded number in cis->pkt_seq_num. + * + * When (pkt_seq_num - stream->pkt_seq_num) is negative then + * BIT64(39) will be set (2's compliment value). The diff value + * less than or equal to BIT64_MASK(38) means the diff value is + * positive and hence pkt_seq_num is greater than + * stream->pkt_seq_num. This calculation is valid for when value + * rollover too. + */ if (!(pb_flag & 0x01) && (((pkt_seq_num - cis->pkt_seq_num) & BIT64_MASK(39)) <= BIT64_MASK(38))) { @@ -5770,12 +5782,17 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) pkt_seq_num = cis->pkt_seq_num; } - /* Pre-increment, for next ISO data packet seq num comparison */ + /* Pre-increment, when pg_flag is BT_ISO_SINGLE (0b10) or + * BT_ISO_END (0b11) then we simple check if pb_flag has bit 1 + * is set, for next ISO data packet seq num comparison. + */ if (pb_flag & 0x10) { cis->pkt_seq_num++; } - /* Target next event to avoid overlapping with current event */ + /* Target next ISO event to avoid overlapping with, if any, + * current ISO event + */ pkt_seq_num++; sdu_frag_tx.target_event = pkt_seq_num; sdu_frag_tx.grp_ref_point = @@ -5817,7 +5834,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) #endif /* !CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ /* Get controller's input data path for CIS */ - hdr = &(cis->hdr); + hdr = &cis->hdr; dp_in = hdr->datapath_in; if (!dp_in || dp_in->path_id != BT_HCI_DATAPATH_ID_HCI) { LOG_ERR("Input data path not set for HCI"); @@ -5884,6 +5901,18 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) /* Catch up local pkt_seq_num with internal pkt_seq_num */ event_count = lll_iso->payload_count / lll_iso->bn; pkt_seq_num = event_count; + /* If pb_flag is BT_ISO_START (0b00) or BT_ISO_SINGLE (0b10) + * then we simply check that the pb_flag is an even value, and + * then pkt_seq_num is a future sequence number value compare + * to last recorded number in cis->pkt_seq_num. + * + * When (pkt_seq_num - stream->pkt_seq_num) is negative then + * BIT64(39) will be set (2's compliment value). The diff value + * less than or equal to BIT64_MASK(38) means the diff value is + * positive and hence pkt_seq_num is greater than + * stream->pkt_seq_num. This calculation is valid for when value + * rollover too. + */ if (!(pb_flag & 0x01) && (((pkt_seq_num - stream->pkt_seq_num) & BIT64_MASK(39)) <= BIT64_MASK(38))) { @@ -5892,12 +5921,17 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) pkt_seq_num = stream->pkt_seq_num; } - /* Pre-increment, for next ISO data packet seq num comparison */ + /* Pre-increment, when pg_flag is BT_ISO_SINGLE (0b10) or + * BT_ISO_END (0b11) then we simple check if pb_flag has bit 1 + * is set, for next ISO data packet seq num comparison. + */ if (pb_flag & 0x10) { stream->pkt_seq_num++; } - /* Target next event to avoid overlapping with current event */ + /* Target next ISO event to avoid overlapping with, if any, + * current ISO event + */ /* FIXME: Implement ISO Tx ack generation early in done compared * to currently only in prepare. I.e. to ensure upper * layer has the number of completed packet before the diff --git a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h index 0321b96f638..8a85ca7c6c9 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h +++ b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h @@ -15,8 +15,10 @@ struct lll_conn_iso_stream_rxtx { uint64_t ft:8; /* Flush timeout (FT) */ uint64_t bn:4; /* Burst number (BN) */ uint64_t phy:3; /* PHY */ - uint64_t rfu:1; - uint8_t bn_curr:4; /* Current burst number */ + uint64_t rfu0:1; + + uint8_t bn_curr:4; /* Current burst number */ + uint8_t rfu1:4; #if defined(CONFIG_BT_CTLR_LE_ENC) struct ccm ccm; @@ -73,20 +75,26 @@ struct lll_conn_iso_group { struct lll_hdr hdr; uint16_t handle; /* CIG handle (internal) */ - uint8_t num_cis:5; /* Number of CISes in this CIG */ - uint8_t role:1; /* 0: CENTRAL, 1: PERIPHERAL*/ - uint8_t paused:1; /* 1: CIG is paused */ - /* ISO interval to calculate timestamp under FT > 1 */ - uint32_t iso_interval_us; + /* Resumption information */ + uint16_t resume_cis; /* CIS handle to schedule at resume */ + + /* ISO group information */ + uint32_t num_cis:5; /* Number of CISes in this CIG */ + uint32_t role:1; /* 0: CENTRAL, 1: PERIPHERAL*/ + uint32_t paused:1; /* 1: CIG is paused */ + uint32_t rfu0:1; + + /* ISO interval to calculate timestamp under FT > 1, + * maximum ISO interval of 4 seconds can be represented in 22-bits. + */ + uint32_t iso_interval_us:22; + uint32_t rfu1:2; /* Accumulates LLL prepare callback latencies */ uint16_t latency_prepare; uint16_t latency_event; - /* Resumption information */ - uint16_t resume_cis; /* CIS handle to schedule at resume */ - #if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) /* Window widening. Relies on vendor specific conversion macros, e.g. * EVENT_US_FRAC_TO_TICKS(). diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 9c2184b9942..751c3915fc2 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -48,7 +48,7 @@ static void isr_prepare_subevent(void *param); static void isr_done(void *param); static void payload_count_flush(struct lll_conn_iso_stream *cis_lll); static void payload_count_flush_or_inc_on_close(struct lll_conn_iso_stream *cis_lll); -static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy); +static void payload_count_lazy_update(struct lll_conn_iso_stream *cis_lll, uint16_t lazy); static uint16_t next_cis_chan_remap_idx; static uint16_t next_cis_chan_prn_s; @@ -183,7 +183,7 @@ static int prepare_cb(struct lll_prepare_param *p) se_curr = 1U; /* Adjust the SN and NESN for skipped CIG events */ - payload_count_lazy(cis_lll, lazy); + payload_count_lazy_update(cis_lll, lazy); /* Start setting up of Radio h/w */ radio_reset(); @@ -370,7 +370,7 @@ static int prepare_cb(struct lll_prepare_param *p) cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); if (cis_lll && cis_lll->active) { /* Adjust sn and nesn for skipped CIG events */ - payload_count_lazy(cis_lll, lazy); + payload_count_lazy_update(cis_lll, lazy); /* Adjust sn and nesn for canceled events */ if (err) { @@ -676,11 +676,20 @@ static void isr_rx(void *param) /* No Rx */ if (!trx_done || #if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) + /* Used by test code, + * to skip a number of events in every 3 event count when current subevent is less than + * or equal to 2 or when current subevent has completed all its NSE number of subevents. + * OR + * to skip a (number + 1) of events in every 3 event count when current subevent is less + * than or equal to 1 or when current subevent has completed all its NSE number of + * subevents. + */ ((((cis_lll->event_count % 3U) < CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT) && ((se_curr > cis_lll->nse) || (se_curr <= 2U))) || + (((cis_lll->event_count % 3U) < (CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT + 1U)) && ((se_curr > cis_lll->nse) || (se_curr <= 1U)))) || -#endif +#endif /* CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS */ false) { payload_count_flush(cis_lll); @@ -1230,7 +1239,7 @@ static void payload_count_flush_or_inc_on_close(struct lll_conn_iso_stream *cis_ } } -static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy) +static void payload_count_lazy_update(struct lll_conn_iso_stream *cis_lll, uint16_t lazy) { if (cis_lll->tx.bn) { uint16_t tx_lazy; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index c33c82d4c70..27ed4d1e42c 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -474,6 +474,14 @@ static void isr_rx(void *param) /* No Rx */ if (!trx_done || #if defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) + /* Used by test code, + * to skip a number of events in every 3 event count when current subevent is less than + * or equal to 2 or when current subevent has completed all its NSE number of subevents. + * OR + * to skip a (number + 1) of events in every 3 event count when current subevent is less + * than or equal to 1 or when current subevent has completed all its NSE number of + * subevents. + */ ((((cis_lll->event_count % 3U) < CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT) && ((se_curr > cis_lll->nse) || (se_curr <= 2U))) || (((cis_lll->event_count % 3U) < (CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT + 1U)) && diff --git a/tests/bsim/bluetooth/ll/cis/src/main.c b/tests/bsim/bluetooth/ll/cis/src/main.c index 15e102981d6..b544546a404 100644 --- a/tests/bsim/bluetooth/ll/cis/src/main.c +++ b/tests/bsim/bluetooth/ll/cis/src/main.c @@ -352,7 +352,7 @@ static void test_cis_central(void) struct bt_conn *conn_list[CONFIG_BT_MAX_CONN]; struct bt_iso_cig_param cig_param; struct bt_iso_cig *cig; - uint8_t conn_count; + int conn_count; int err; printk("Bluetooth initializing..."); @@ -370,12 +370,12 @@ static void test_cis_central(void) for (int i = 0; i < CONFIG_BT_ISO_MAX_CHAN; i++) { iso_tx[i].sdu = CONFIG_BT_ISO_TX_MTU; iso_tx[i].phy = BT_GAP_LE_PHY_2M; + iso_tx[i].path = NULL; if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { iso_tx[i].rtn = 2U; } else { iso_tx[i].rtn = 0U; } - iso_tx[i].path = NULL; if (!IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS) || IS_ENABLED(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS)) { @@ -386,12 +386,12 @@ static void test_cis_central(void) iso_rx[i].sdu = CONFIG_BT_ISO_RX_MTU; iso_rx[i].phy = BT_GAP_LE_PHY_2M; + iso_rx[i].path = NULL; if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { iso_rx[i].rtn = 2U; } else { iso_rx[i].rtn = 0U; } - iso_rx[i].path = NULL; if (IS_ENABLED(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS)) { iso_qos[i].rx = &iso_rx[i]; @@ -413,12 +413,12 @@ static void test_cis_central(void) cig_param.sca = BT_GAP_SCA_UNKNOWN; cig_param.packing = 0U; cig_param.framing = 0U; + cig_param.interval = ISO_INTERVAL_US; if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { cig_param.latency = ISO_LATENCY_FT_MS; } else { cig_param.latency = ISO_LATENCY_MS; } - cig_param.interval = ISO_INTERVAL_US; printk("Create CIG..."); err = bt_iso_cig_create(&cig_param, &cig); @@ -428,10 +428,10 @@ static void test_cis_central(void) } printk("success.\n"); - conn_count = 0U; + conn_count = 0; #if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) - for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { expected_seq_num[chan] = (CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT - 1U) * 2U; } #endif @@ -443,8 +443,8 @@ static void test_cis_central(void) #endif struct bt_conn *conn; - uint8_t conn_index; - uint8_t chan; + int conn_index; + int chan; printk("Start scanning (%d)...", i); err = bt_le_scan_start(BT_LE_SCAN_CUSTOM, NULL); @@ -494,12 +494,12 @@ static void test_cis_central(void) #if defined(CONFIG_TEST_CONNECT_ACL_FIRST) } - for (uint8_t chan = 0U, conn_index = 0U; + for (int chan = 0, conn_index = 0; (conn_index < conn_count) && (chan < CONFIG_BT_ISO_MAX_CHAN); conn_index++, chan++) { #elif defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) - for (uint8_t chan = 0U, conn_index = 0U; + for (int chan = 0, conn_index = 0; (chan < CONFIG_BT_ISO_MAX_CHAN); chan++) { #endif @@ -523,70 +523,67 @@ static void test_cis_central(void) printk("connected to peer %d ISO channel.\n", chan); } -#if !defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) || defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) - for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { - - for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { - uint8_t iso_data[CONFIG_BT_ISO_TX_MTU] = { 0, }; - struct net_buf *buf; - int ret; - - buf = net_buf_alloc(&tx_pool, - K_MSEC(BUF_ALLOC_TIMEOUT)); - if (!buf) { - FAIL("Data buffer allocate timeout on channel" - " %u\n", chan); - return; - } - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - sys_put_le32(seq_num, iso_data); - net_buf_add_mem(buf, iso_data, sizeof(iso_data)); - - ret = k_sem_take(&sem_iso_data, - K_MSEC(BUF_ALLOC_TIMEOUT)); - if (ret) { - FAIL("k_sem_take for ISO data sent failed.\n"); - return; + if (!IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS) || + IS_ENABLED(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS)) { + for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { + + for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + uint8_t iso_data[CONFIG_BT_ISO_TX_MTU] = { 0, }; + struct net_buf *buf; + int ret; + + buf = net_buf_alloc(&tx_pool, K_MSEC(BUF_ALLOC_TIMEOUT)); + if (!buf) { + FAIL("Data buffer allocate timeout on channel %d\n", chan); + return; + } + + net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); + sys_put_le16(seq_num, iso_data); + net_buf_add_mem(buf, iso_data, sizeof(iso_data)); + + ret = k_sem_take(&sem_iso_data, K_MSEC(BUF_ALLOC_TIMEOUT)); + if (ret) { + FAIL("k_sem_take for ISO data sent failed.\n"); + return; + } + + printk("ISO send: seq_num %u, chan %d\n", seq_num, chan); + ret = bt_iso_chan_send(&iso_chan[chan], buf, + seq_num, BT_ISO_TIMESTAMP_NONE); + if (ret < 0) { + FAIL("Unable to send data on channel %d : %d\n", chan, ret); + net_buf_unref(buf); + return; + } } - printk("ISO send: seq_num %u, chan %u\n", seq_num, chan); - ret = bt_iso_chan_send(&iso_chan[chan], buf, - seq_num, BT_ISO_TIMESTAMP_NONE); - if (ret < 0) { - FAIL("Unable to send data on channel %u" - " : %d\n", chan, ret); - net_buf_unref(buf); - return; + if ((seq_num % 100) == 0) { + printk("Sending value %u\n", seq_num); } } - if ((seq_num % 100) == 0) { - printk("Sending value %u\n", seq_num); - } + k_sleep(K_MSEC(1000)); + } else { + k_sleep(K_SECONDS(11)); } - k_sleep(K_MSEC(1000)); -#else - k_sleep(K_SECONDS(11)); -#endif - - for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { - printk("ISO disconnect channel %u...", chan); + for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + printk("ISO disconnect channel %d...", chan); err = bt_iso_chan_disconnect(&iso_chan[chan]); if (err) { - FAIL("Failed to disconnect channel %u (%d)\n", - chan, err); + FAIL("Failed to disconnect channel %d (%d)\n", chan, err); return; } printk("success\n"); - printk("Waiting for ISO channel disconnect %u...", chan); + printk("Waiting for ISO channel disconnect %d...", chan); err = k_sem_take(&sem_iso_disc, K_FOREVER); if (err) { FAIL("failed (err %d)\n", err); return; } - printk("disconnected to peer %u ISO channel.\n", chan); + printk("disconnected to peer %d ISO channel.\n", chan); } bt_conn_foreach(BT_CONN_TYPE_LE, disconnect, NULL); @@ -607,15 +604,15 @@ static void test_cis_central(void) } #endif -#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) - for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { - if (expected_seq_num[chan] < SEQ_NUM_MAX) { - FAIL("ISO Data reception incomplete %u (%u).\n", - expected_seq_num[chan], SEQ_NUM_MAX); - return; + if (IS_ENABLED(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS)) { + for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + if (expected_seq_num[chan] < SEQ_NUM_MAX) { + FAIL("ISO Data reception incomplete %u (%u).\n", + expected_seq_num[chan], SEQ_NUM_MAX); + return; + } } } -#endif PASS("Central ISO tests Passed\n"); } @@ -671,12 +668,12 @@ static void test_cis_peripheral(void) for (int i = 0; i < CONFIG_BT_ISO_MAX_CHAN; i++) { iso_tx_p[i].sdu = CONFIG_BT_ISO_TX_MTU; iso_tx_p[i].phy = BT_GAP_LE_PHY_2M; + iso_tx_p[i].path = NULL; if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { iso_tx_p[i].rtn = 2U; } else { iso_tx_p[i].rtn = 0U; } - iso_tx_p[i].path = NULL; iso_qos_p[i].tx = &iso_tx_p[i]; @@ -741,7 +738,7 @@ static void test_cis_peripheral(void) printk("connected to peer central.\n"); #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) - for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { #endif printk("Waiting for ISO channel connection..."); @@ -756,50 +753,47 @@ static void test_cis_peripheral(void) } #endif -#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) - for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { - for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { - uint8_t iso_data[CONFIG_BT_ISO_TX_MTU] = { 0, }; - struct net_buf *buf; - int ret; - - buf = net_buf_alloc(&tx_pool, - K_MSEC(BUF_ALLOC_TIMEOUT)); - if (!buf) { - FAIL("Data buffer allocate timeout on channel" - " %u\n", chan); - return; - } - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - sys_put_le32(seq_num, iso_data); - net_buf_add_mem(buf, iso_data, sizeof(iso_data)); - - ret = k_sem_take(&sem_iso_data, - K_MSEC(BUF_ALLOC_TIMEOUT)); - if (ret) { - FAIL("k_sem_take for ISO data sent failed.\n"); - return; + if (IS_ENABLED(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS)) { + for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { + for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + uint8_t iso_data[CONFIG_BT_ISO_TX_MTU] = { 0, }; + struct net_buf *buf; + int ret; + + buf = net_buf_alloc(&tx_pool, K_MSEC(BUF_ALLOC_TIMEOUT)); + if (!buf) { + FAIL("Data buffer allocate timeout on channel %d\n", chan); + return; + } + + net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); + sys_put_le16(seq_num, iso_data); + net_buf_add_mem(buf, iso_data, sizeof(iso_data)); + + ret = k_sem_take(&sem_iso_data, K_MSEC(BUF_ALLOC_TIMEOUT)); + if (ret) { + FAIL("k_sem_take for ISO data sent failed.\n"); + return; + } + + printk("ISO send: seq_num %u, chan %d\n", seq_num, chan); + ret = bt_iso_chan_send(&iso_chan_p[chan], buf, seq_num, + BT_ISO_TIMESTAMP_NONE); + if (ret < 0) { + FAIL("Unable to send data on channel %d : %d\n", chan, ret); + net_buf_unref(buf); + return; + } } - printk("ISO send: seq_num %u, chan %u\n", seq_num, chan); - ret = bt_iso_chan_send(&iso_chan_p[chan], buf, - seq_num, BT_ISO_TIMESTAMP_NONE); - if (ret < 0) { - FAIL("Unable to send data on channel %u" - " : %d\n", chan, ret); - net_buf_unref(buf); - return; + if ((seq_num % 100) == 0) { + printk("Sending value %u\n", seq_num); } } - - if ((seq_num % 100) == 0) { - printk("Sending value %u\n", seq_num); - } } -#endif #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) - for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { #endif printk("Waiting for ISO channel disconnect..."); @@ -824,13 +818,13 @@ static void test_cis_peripheral(void) #if !defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) || defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) - for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { #else - uint8_t chan = 0U; + int chan = 0; #endif if (expected_seq_num[chan] < SEQ_NUM_MAX) { - FAIL("ISO Data reception incomplete %u (%u).\n", - expected_seq_num[chan], SEQ_NUM_MAX); + FAIL("ISO Data reception incomplete %u (%u).\n", expected_seq_num[chan], + SEQ_NUM_MAX); return; } #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) diff --git a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh index 04ce474e812..bb08f582574 100755 --- a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh +++ b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 2020 Nordic Semiconductor ASA +# Copyright 2023 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 source ${ZEPHYR_BASE}/tests/bsim/sh_common.source diff --git a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh index 307d865a117..84d3c5c4ed3 100755 --- a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh +++ b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 2020 Nordic Semiconductor ASA +# Copyright 2023 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 source ${ZEPHYR_BASE}/tests/bsim/sh_common.source From 49afbcceeb53e75ca2be62e895b2b18bd5742993 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 3 Oct 2023 16:23:00 +0200 Subject: [PATCH 0279/1623] [nrf fromtree] Bluetooth: Controller: Remove unused terminate_ack Remove the terminate_ack from struct ll_conn since it is not used anywhere, and results in dead code. Signed-off-by: Emil Gydesen (cherry picked from commit 89db200117aa4d0604060d65318dcc0ab30b073d) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 233a142db54fb619749615eb3af4919dce59cc2e) --- subsys/bluetooth/controller/ll_sw/ull_central.c | 2 -- subsys/bluetooth/controller/ll_sw/ull_conn.c | 6 ------ subsys/bluetooth/controller/ll_sw/ull_conn_types.h | 1 - 3 files changed, 9 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central.c b/subsys/bluetooth/controller/ll_sw/ull_central.c index b189c65fa21..7ea3c600ea6 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central.c @@ -291,8 +291,6 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, /* Setup the PRT reload */ ull_cp_prt_reload_set(conn, conn_interval_us); - conn->central.terminate_ack = 0U; - conn->llcp_terminate.reason_final = 0U; /* NOTE: use allocated link for generating dedicated * terminate ind rx node diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 9d78af7acc1..1640c00e87e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -1044,12 +1044,6 @@ void ull_conn_done(struct node_rx_event_done *done) lll->latency_event = lll->latency; } #endif /* CONFIG_BT_PERIPHERAL */ - -#if defined(CONFIG_BT_CENTRAL) - } else if (reason_final) { - conn->central.terminate_ack = 1; -#endif /* CONFIG_BT_CENTRAL */ - } /* Reset connection failed to establish countdown */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_types.h b/subsys/bluetooth/controller/ll_sw/ull_conn_types.h index 12e16488f38..8fabab03378 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_types.h +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_types.h @@ -202,7 +202,6 @@ struct ll_conn { #if defined(CONFIG_BT_CTLR_CONN_META) uint8_t is_must_expire:1; #endif /* CONFIG_BT_CTLR_CONN_META */ - uint8_t terminate_ack:1; } central; #endif /* CONFIG_BT_CENTRAL */ }; From 5e6ae9f1a206335f50da010532f106693e189ffa Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 3 Oct 2023 23:42:09 +0200 Subject: [PATCH 0280/1623] [nrf fromtree] Bluetooth: Controll: Fix dead code in ll_setup_iso_path In ll_setup_iso_path cis is only ever set if CONFIG_BT_CTLR_CONN_ISO is enabled, and similarly adv_stream is only ever set if CONFIG_BT_CTLR_ADV_ISO is enabled. The two assignments were reported as dead code by Coverity due to this, which has been fixed by guarding the code with the respective Kconfigs. Signed-off-by: Emil Gydesen (cherry picked from commit c6cecef12058b96ce9fe62b549e407c6b7c20949) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 512beaac5f83999ef76cc08c285d1ab479eccab1) --- subsys/bluetooth/controller/ll_sw/ull_iso.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_iso.c b/subsys/bluetooth/controller/ll_sw/ull_iso.c index 70d018e7e0c..b21a9d20721 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_iso.c @@ -491,11 +491,11 @@ uint8_t ll_setup_iso_path(uint16_t handle, uint8_t path_dir, uint8_t path_id, pdu_release, &source_handle); if (!err) { - if (cis) { + if (IS_ENABLED(CONFIG_BT_CTLR_CONN_ISO) && cis != NULL) { cis->hdr.datapath_in = dp; } - if (adv_stream) { + if (IS_ENABLED(CONFIG_BT_CTLR_ADV_ISO) && adv_stream != NULL) { adv_stream->dp = dp; } From 4eefd65d6bebfcfbb64b0a2fa0b3aa6c882d2452 Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Thu, 28 Sep 2023 13:35:34 +0200 Subject: [PATCH 0281/1623] [nrf fromtree] Bluetooth: controller: fix comparision of unsigned int to 0 Fix the coverity issue CWE570, comparison of unsigned int to 0 in the definition of IS_SYNC_ISO_HANDLE There is a potentially the same issue for IS_ADV_ISO_HANDLE, fixed that as well Signed-off-by: Andries Kruithof (cherry picked from commit c5d844fe41a78bcb361dbd1a11ffafe4de3de97e) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 7cd84fe1de54490028a92b73e8fe308c32e6712e) --- subsys/bluetooth/controller/ll_sw/ull_iso_types.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/subsys/bluetooth/controller/ll_sw/ull_iso_types.h b/subsys/bluetooth/controller/ll_sw/ull_iso_types.h index 18d9a0f7bfe..457ad1d2458 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_iso_types.h +++ b/subsys/bluetooth/controller/ll_sw/ull_iso_types.h @@ -9,11 +9,18 @@ #define LL_BIS_ADV_HANDLE_BASE BT_CTLR_ADV_ISO_STREAM_HANDLE_BASE #define LL_BIS_ADV_IDX_FROM_HANDLE(conn_handle) \ ((conn_handle) - (LL_BIS_ADV_HANDLE_BASE)) +/* Conditional compile to prevent coverity issue CWE570, comparison of unsigned int to 0 */ +#if (LL_BIS_ADV_HANDLE_BASE > 0) #define IS_ADV_ISO_HANDLE(conn_handle) \ (((conn_handle) >= (LL_BIS_ADV_HANDLE_BASE)) && \ ((conn_handle) <= ((LL_BIS_ADV_HANDLE_BASE) + \ (BT_CTLR_ADV_ISO_STREAM_MAX) - 1U))) #else +#define IS_ADV_ISO_HANDLE(conn_handle) \ + ((conn_handle) <= ((LL_BIS_ADV_HANDLE_BASE) + \ + (BT_CTLR_ADV_ISO_STREAM_MAX) - 1U)) +#endif /* LL_BIS_ADV_HANDLE_BASE */ +#else #define LL_BIS_ADV_IDX_FROM_HANDLE(conn_handle) 0U #define IS_ADV_ISO_HANDLE(conn_handle) 0U #endif /* CONFIG_BT_CTLR_ADV_ISO */ @@ -23,11 +30,18 @@ #define LL_BIS_SYNC_HANDLE_BASE BT_CTLR_SYNC_ISO_STREAM_HANDLE_BASE #define LL_BIS_SYNC_IDX_FROM_HANDLE(conn_handle) \ ((conn_handle) - (LL_BIS_SYNC_HANDLE_BASE)) +/* Conditional compile to prevent coverity issue CWE570, comparison of unsigned int to 0 */ +#if (LL_BIS_SYNC_HANDLE_BASE > 0) #define IS_SYNC_ISO_HANDLE(conn_handle) \ (((conn_handle) >= (LL_BIS_SYNC_HANDLE_BASE)) && \ ((conn_handle) <= ((LL_BIS_SYNC_HANDLE_BASE) + \ (BT_CTLR_SYNC_ISO_STREAM_MAX) - 1U))) #else +#define IS_SYNC_ISO_HANDLE(conn_handle) \ + ((conn_handle) <= ((LL_BIS_SYNC_HANDLE_BASE) + \ + (BT_CTLR_SYNC_ISO_STREAM_MAX) - 1U)) +#endif /* LL_BIS_SYNC_HANDLE_BASE */ +#else #define LL_BIS_SYNC_IDX_FROM_HANDLE(conn_handle) 0U #define IS_SYNC_ISO_HANDLE(conn_handle) 0U #endif /* CONFIG_BT_CTLR_SYNC_ISO */ From 9e70b2847662239880a1d0f6b69bde41298fbea7 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 4 Oct 2023 10:29:55 +0200 Subject: [PATCH 0282/1623] [nrf fromtree] Bluetooth: Controller: Make aa in radio_aa_set const Make the aa argument const to solve a Coverity issue that assumes that any value that is being byteswapped is tainted. Making the argument const should avoid this assumption from Coverity. Signed-off-by: Emil Gydesen (cherry picked from commit f4221d66c1985055319393dbc45bd7b519a23731) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 36940b6c9450b6fcee847a455a4c2c6967bb222d) --- subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c | 2 +- subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h | 2 +- .../bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.c | 2 +- .../bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index a657ab95dfe..c6becbe322f 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -382,7 +382,7 @@ void radio_whiten_iv_set(uint32_t iv) RADIO_PCNF1_WHITEEN_Msk; } -void radio_aa_set(uint8_t *aa) +void radio_aa_set(const uint8_t *aa) { NRF_RADIO->TXADDRESS = (((0UL) << RADIO_TXADDRESS_TXADDRESS_Pos) & diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h index 4bf833b233a..fc355af1edc 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h @@ -70,7 +70,7 @@ int8_t radio_tx_power_max_get(void); int8_t radio_tx_power_floor(int8_t power); void radio_freq_chan_set(uint32_t chan); void radio_whiten_iv_set(uint32_t iv); -void radio_aa_set(uint8_t *aa); +void radio_aa_set(const uint8_t *aa); void radio_pkt_configure(uint8_t bits_len, uint8_t max_len, uint8_t flags); void radio_pkt_rx_set(void *rx_packet); void radio_pkt_tx_set(void *tx_packet); diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.c b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.c index 6107bfc9c68..ecdf17bbe43 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.c @@ -684,7 +684,7 @@ void radio_whiten_iv_set(uint32_t iv) GENFSK->WHITEN_SZ_THR |= GENFSK_WHITEN_SZ_THR_WHITEN_SZ_THR(0); } -void radio_aa_set(uint8_t *aa) +void radio_aa_set(const uint8_t *aa) { /* Configure Access Address detection using NETWORK ADDRESS 0 */ GENFSK->NTW_ADR_0 = *((uint32_t *)aa); diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.h b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.h index 1168804bbd5..cc3fda99964 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.h +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.h @@ -20,7 +20,7 @@ void radio_tx_power_set(uint32_t power); void radio_tx_power_max_set(void); void radio_freq_chan_set(uint32_t chan); void radio_whiten_iv_set(uint32_t iv); -void radio_aa_set(uint8_t *aa); +void radio_aa_set(const uint8_t *aa); void radio_pkt_configure(uint8_t bits_len, uint8_t max_len, uint8_t flags); void radio_pkt_rx_set(void *rx_packet); void radio_pkt_tx_set(void *tx_packet); From cc06a1088c2186089719036a62762adb9a2d9585 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 3 Oct 2023 15:35:40 +0200 Subject: [PATCH 0283/1623] [nrf fromtree] Bluetooth: Controller: Add hdl checks in isoal.c Add checks to verify the `hdl` parameters before accessing the sink and source arrays. Signed-off-by: Emil Gydesen (cherry picked from commit 147cef6660f2f368457447a0fdc94ea06ce268dd) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit ad5350fc59100cd775cdc9bc09cf6030d0f1eccd) --- subsys/bluetooth/controller/ll_sw/isoal.c | 78 +++++++++++++++++------ 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index d43233f0289..48ad0835074 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -226,8 +226,17 @@ static isoal_status_t isoal_sink_allocate(isoal_sink_handle_t *hdl) */ static void isoal_sink_deallocate(isoal_sink_handle_t hdl) { - isoal_global.sink_allocated[hdl] = ISOAL_ALLOC_STATE_FREE; - (void)memset(&isoal_global.sink_state[hdl], 0, sizeof(struct isoal_sink)); + if (hdl < ARRAY_SIZE(isoal_global.sink_allocated)) { + isoal_global.sink_allocated[hdl] = ISOAL_ALLOC_STATE_FREE; + } else { + LL_ASSERT(0); + } + + if (hdl < ARRAY_SIZE(isoal_global.sink_state)) { + (void)memset(&isoal_global.sink_state[hdl], 0, sizeof(struct isoal_sink)); + } else { + LL_ASSERT(0); + } } /** @@ -365,12 +374,16 @@ isoal_status_t isoal_sink_create( */ void isoal_sink_enable(isoal_sink_handle_t hdl) { - /* Reset bookkeeping state */ - memset(&isoal_global.sink_state[hdl].sdu_production, 0, - sizeof(isoal_global.sink_state[hdl].sdu_production)); + if (hdl < ARRAY_SIZE(isoal_global.sink_state)) { + /* Reset bookkeeping state */ + memset(&isoal_global.sink_state[hdl].sdu_production, 0, + sizeof(isoal_global.sink_state[hdl].sdu_production)); - /* Atomically enable */ - isoal_global.sink_state[hdl].sdu_production.mode = ISOAL_PRODUCTION_MODE_ENABLED; + /* Atomically enable */ + isoal_global.sink_state[hdl].sdu_production.mode = ISOAL_PRODUCTION_MODE_ENABLED; + } else { + LL_ASSERT(0); + } } /** @@ -379,8 +392,12 @@ void isoal_sink_enable(isoal_sink_handle_t hdl) */ void isoal_sink_disable(isoal_sink_handle_t hdl) { - /* Atomically disable */ - isoal_global.sink_state[hdl].sdu_production.mode = ISOAL_PRODUCTION_MODE_DISABLED; + if (hdl < ARRAY_SIZE(isoal_global.sink_state)) { + /* Atomically disable */ + isoal_global.sink_state[hdl].sdu_production.mode = ISOAL_PRODUCTION_MODE_DISABLED; + } else { + LL_ASSERT(0); + } } /** @@ -1442,7 +1459,13 @@ static void isoal_source_deallocate(isoal_source_handle_t hdl) struct isoal_pdu_production *pp; struct isoal_source *source; - source = &isoal_global.source_state[hdl]; + if (hdl < ARRAY_SIZE(isoal_global.source_state)) { + source = &isoal_global.source_state[hdl]; + } else { + LL_ASSERT(0); + return; + } + pp = &source->pdu_production; if (pp->pdu_available > 0) { @@ -1454,8 +1477,13 @@ static void isoal_source_deallocate(isoal_source_handle_t hdl) } } - isoal_global.source_allocated[hdl] = ISOAL_ALLOC_STATE_FREE; - (void)memset(&isoal_global.source_state[hdl], 0, sizeof(struct isoal_source)); + if (hdl < ARRAY_SIZE(isoal_global.source_allocated)) { + isoal_global.source_allocated[hdl] = ISOAL_ALLOC_STATE_FREE; + } else { + LL_ASSERT(0); + } + + (void)memset(source, 0, sizeof(struct isoal_source)); } /** @@ -1465,8 +1493,8 @@ static void isoal_source_deallocate(isoal_source_handle_t hdl) */ static isoal_status_t isoal_check_source_hdl_valid(isoal_source_handle_t hdl) { - if (hdl < CONFIG_BT_CTLR_ISOAL_SOURCES && - isoal_global.source_allocated[hdl] == ISOAL_ALLOC_STATE_TAKEN) { + if (hdl < ARRAY_SIZE(isoal_global.source_allocated) && + isoal_global.source_allocated[hdl] == ISOAL_ALLOC_STATE_TAKEN) { return ISOAL_STATUS_OK; } @@ -1560,12 +1588,16 @@ isoal_status_t isoal_source_create( */ void isoal_source_enable(isoal_source_handle_t hdl) { - /* Reset bookkeeping state */ - memset(&isoal_global.source_state[hdl].pdu_production, 0, - sizeof(isoal_global.source_state[hdl].pdu_production)); + if (hdl < ARRAY_SIZE(isoal_global.source_state)) { + /* Reset bookkeeping state */ + memset(&isoal_global.source_state[hdl].pdu_production, 0, + sizeof(isoal_global.source_state[hdl].pdu_production)); - /* Atomically enable */ - isoal_global.source_state[hdl].pdu_production.mode = ISOAL_PRODUCTION_MODE_ENABLED; + /* Atomically enable */ + isoal_global.source_state[hdl].pdu_production.mode = ISOAL_PRODUCTION_MODE_ENABLED; + } else { + LL_ASSERT(0); + } } /** @@ -1574,8 +1606,12 @@ void isoal_source_enable(isoal_source_handle_t hdl) */ void isoal_source_disable(isoal_source_handle_t hdl) { - /* Atomically disable */ - isoal_global.source_state[hdl].pdu_production.mode = ISOAL_PRODUCTION_MODE_DISABLED; + if (hdl < ARRAY_SIZE(isoal_global.source_state)) { + /* Atomically disable */ + isoal_global.source_state[hdl].pdu_production.mode = ISOAL_PRODUCTION_MODE_DISABLED; + } else { + LL_ASSERT(0); + } } /** From 009025d45d384fd1eacf3669c9a859627058b684 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Thu, 5 Oct 2023 12:55:24 +0200 Subject: [PATCH 0284/1623] [nrf fromtree] Bluetooth: Controller: Remove legacy BT_CTLR_FAST_ENC option When the legacy LLCP implementation was removed this Kconfig option was mistakenly left over. Remove it now with all its users. Fixes #63212. Signed-off-by: Carles Cufi (cherry picked from commit a5e7ba356465cdf0b7f3387f5b46ddc016339250) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 62cc15553b6fc153b945c515a11a4976fbd22763) --- drivers/entropy/entropy_nrf5.c | 5 ----- drivers/entropy/entropy_smartbond.c | 5 ----- drivers/entropy/entropy_stm32.c | 9 +-------- subsys/bluetooth/controller/Kconfig.ll_sw_split | 12 ------------ tests/bluetooth/init/prj_ctlr_4_0.conf | 1 - tests/bluetooth/init/prj_ctlr_4_0_dbg.conf | 1 - tests/bluetooth/init/prj_ctlr_5_x_dbg.conf | 1 - tests/bluetooth/init/prj_ctlr_dbg.conf | 1 - tests/bluetooth/init/prj_ctlr_ticker.conf | 1 - tests/bluetooth/init/prj_ctlr_tiny.conf | 1 - 10 files changed, 1 insertion(+), 36 deletions(-) diff --git a/drivers/entropy/entropy_nrf5.c b/drivers/entropy/entropy_nrf5.c index 8febcfacb15..2f04bc06a37 100644 --- a/drivers/entropy/entropy_nrf5.c +++ b/drivers/entropy/entropy_nrf5.c @@ -116,10 +116,6 @@ static int random_byte_get(void) return retval; } -#pragma GCC push_options -#if defined(CONFIG_BT_CTLR_FAST_ENC) -#pragma GCC optimize ("Ofast") -#endif static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, uint16_t len) { uint32_t last = rngp->last; @@ -175,7 +171,6 @@ static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, uint16_t len) return len; } -#pragma GCC pop_options static int rng_pool_put(struct rng_pool *rngp, uint8_t byte) { diff --git a/drivers/entropy/entropy_smartbond.c b/drivers/entropy/entropy_smartbond.c index 0058baafce5..28b6f08e100 100644 --- a/drivers/entropy/entropy_smartbond.c +++ b/drivers/entropy/entropy_smartbond.c @@ -100,10 +100,6 @@ static int random_word_get(uint8_t buf[4]) return retval; } -#pragma GCC push_options -#if defined(CONFIG_BT_CTLR_FAST_ENC) -#pragma GCC optimize("Ofast") -#endif static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, uint16_t len) { uint32_t last = rngp->last; @@ -159,7 +155,6 @@ static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, uint16_t len) return len; } -#pragma GCC pop_options static int rng_pool_put(struct rng_pool *rngp, uint8_t byte) { diff --git a/drivers/entropy/entropy_stm32.c b/drivers/entropy/entropy_stm32.c index 9f2ad136203..7c342a09c23 100644 --- a/drivers/entropy/entropy_stm32.c +++ b/drivers/entropy/entropy_stm32.c @@ -377,13 +377,7 @@ static void pool_filling_work_handler(struct k_work *work) } } -#if defined(CONFIG_BT_CTLR_FAST_ENC) -#define __fast __attribute__((optimize("Ofast"))) -#else -#define __fast -#endif - -__fast static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, +static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, uint16_t len) { uint32_t last = rngp->last; @@ -448,7 +442,6 @@ __fast static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, return len; } -#undef __fast static int rng_pool_put(struct rng_pool *rngp, uint8_t byte) { diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index a7dade7a1db..e2975107f86 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -760,18 +760,6 @@ config BT_CTLR_PARAM_CHECK if BT_CONN -config BT_CTLR_FAST_ENC - bool "Fast Encryption Setup" - depends on BT_CTLR_LE_ENC - default y if BT_HCI_RAW - help - Enable connection encryption setup in 4 connection events. - Peripheral will respond to Encryption Request with Encryption Response - in the next connection event, and will transmit Start Encryption - Request PDU in the same connection event, hence completing encryption - setup in 4 connection events. Encrypted data would be transmitted as - fast as in 4th connection event from Encryption Request. - config BT_CTLR_LLCP_CONN int "Number of connections with worst-case overlapping procedures" default BT_MAX_CONN diff --git a/tests/bluetooth/init/prj_ctlr_4_0.conf b/tests/bluetooth/init/prj_ctlr_4_0.conf index ff3917be54b..4f9ec70d3bb 100644 --- a/tests/bluetooth/init/prj_ctlr_4_0.conf +++ b/tests/bluetooth/init/prj_ctlr_4_0.conf @@ -19,7 +19,6 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=y CONFIG_BT_CTLR_SCHED_ADVANCED=y CONFIG_BT_CTLR_RADIO_ENABLE_FAST=n CONFIG_BT_CTLR_TIFS_HW=y -CONFIG_BT_CTLR_FAST_ENC=n CONFIG_BT_CTLR_CONN_RSSI=n CONFIG_BT_CTLR_ADV_INDICATION=n CONFIG_BT_CTLR_SCAN_REQ_NOTIFY=n diff --git a/tests/bluetooth/init/prj_ctlr_4_0_dbg.conf b/tests/bluetooth/init/prj_ctlr_4_0_dbg.conf index 4c101cc6e16..5fc61cf98c6 100644 --- a/tests/bluetooth/init/prj_ctlr_4_0_dbg.conf +++ b/tests/bluetooth/init/prj_ctlr_4_0_dbg.conf @@ -21,7 +21,6 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=y CONFIG_BT_CTLR_SCHED_ADVANCED=y CONFIG_BT_CTLR_RADIO_ENABLE_FAST=n CONFIG_BT_CTLR_TIFS_HW=y -CONFIG_BT_CTLR_FAST_ENC=n CONFIG_BT_CTLR_CONN_RSSI=n CONFIG_BT_CTLR_ADV_INDICATION=n CONFIG_BT_CTLR_SCAN_REQ_NOTIFY=n diff --git a/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf b/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf index df0d006a13e..50f72889476 100644 --- a/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf +++ b/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf @@ -29,7 +29,6 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=n CONFIG_BT_CTLR_SCHED_ADVANCED=y CONFIG_BT_CTLR_RADIO_ENABLE_FAST=y CONFIG_BT_CTLR_TIFS_HW=n -CONFIG_BT_CTLR_FAST_ENC=y CONFIG_BT_CTLR_TX_RETRY_DISABLE=y CONFIG_BT_CTLR_CONN_RSSI=y CONFIG_BT_CTLR_ADV_INDICATION=y diff --git a/tests/bluetooth/init/prj_ctlr_dbg.conf b/tests/bluetooth/init/prj_ctlr_dbg.conf index 6aff0965ce9..2f8224cdfea 100644 --- a/tests/bluetooth/init/prj_ctlr_dbg.conf +++ b/tests/bluetooth/init/prj_ctlr_dbg.conf @@ -23,7 +23,6 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=n CONFIG_BT_CTLR_SCHED_ADVANCED=n CONFIG_BT_CTLR_RADIO_ENABLE_FAST=y CONFIG_BT_CTLR_TIFS_HW=n -CONFIG_BT_CTLR_FAST_ENC=y CONFIG_BT_CTLR_TX_RETRY_DISABLE=y CONFIG_BT_CTLR_CONN_RSSI=y CONFIG_BT_CTLR_ADV_INDICATION=y diff --git a/tests/bluetooth/init/prj_ctlr_ticker.conf b/tests/bluetooth/init/prj_ctlr_ticker.conf index d77f519406b..4e5b962231e 100644 --- a/tests/bluetooth/init/prj_ctlr_ticker.conf +++ b/tests/bluetooth/init/prj_ctlr_ticker.conf @@ -23,7 +23,6 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=n CONFIG_BT_CTLR_SCHED_ADVANCED=n CONFIG_BT_CTLR_RADIO_ENABLE_FAST=y CONFIG_BT_CTLR_TIFS_HW=n -CONFIG_BT_CTLR_FAST_ENC=y CONFIG_BT_CTLR_TX_RETRY_DISABLE=y CONFIG_BT_CTLR_CONN_RSSI=y CONFIG_BT_CTLR_ADV_INDICATION=y diff --git a/tests/bluetooth/init/prj_ctlr_tiny.conf b/tests/bluetooth/init/prj_ctlr_tiny.conf index 7679de9a661..ce75583da16 100644 --- a/tests/bluetooth/init/prj_ctlr_tiny.conf +++ b/tests/bluetooth/init/prj_ctlr_tiny.conf @@ -22,7 +22,6 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=n CONFIG_BT_CTLR_SCHED_ADVANCED=n CONFIG_BT_CTLR_RADIO_ENABLE_FAST=n CONFIG_BT_CTLR_TIFS_HW=y -CONFIG_BT_CTLR_FAST_ENC=n CONFIG_BT_CTLR_CONN_RSSI=n CONFIG_BT_CTLR_ADV_INDICATION=n CONFIG_BT_CTLR_SCAN_REQ_NOTIFY=n From 2b86f49ef42aec7d80c2842da5dc6414d0b0ecc1 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 5 Oct 2023 09:42:31 +0200 Subject: [PATCH 0285/1623] [nrf fromtree] Bluetooth: Controller: Rename ticker reschedule variables Rename ticker reschedule in window variable to improve readability. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 7495846b625be792c9c28a1d59eaad391f7be15d) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 489e43adfe41004ad84971fb5fb5b1833ab59ee2) --- subsys/bluetooth/controller/ticker/ticker.c | 123 +++++++++++--------- 1 file changed, 69 insertions(+), 54 deletions(-) diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index e5c89dca905..9b5bb53a625 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -2326,43 +2326,46 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, uint32_t ticks_elapsed) { struct ticker_node *nodes; - uint8_t rescheduling = 1U; - uint8_t rescheduled = 0U; + uint8_t rescheduling; + uint8_t rescheduled; nodes = &instance->nodes[0]; /* Do until all pending re-schedules handled */ + rescheduling = 1U; + rescheduled = 0U; while (rescheduling) { - uint32_t ticks_to_expire_offset = 0U; - uint32_t ticks_start_offset = 0U; - uint32_t window_start_ticks = 0U; - uint32_t ticks_slot_window = 0U; - uint32_t ticks_to_expire = 0U; + struct ticker_node *ticker_resched; + uint32_t ticks_to_expire_offset; struct ticker_ext *ext_data; - struct ticker_node *ticker; - uint8_t ticker_id_head; + uint32_t ticks_start_offset; + uint32_t window_start_ticks; + uint32_t ticks_slot_window; + uint8_t ticker_id_resched; + uint32_t ticks_to_expire; uint8_t ticker_id_prev; - uint8_t ticker_id_iter; + uint8_t ticker_id_next; uint32_t ticks_slot; rescheduling = 0U; /* Find first pending re-schedule */ - ticker_id_head = instance->ticker_id_head; - while (ticker_id_head != TICKER_NULL) { - ticker = &nodes[ticker_id_head]; - if (TICKER_RESCHEDULE_PENDING(ticker)) { + ticker_id_resched = instance->ticker_id_head; + while (ticker_id_resched != TICKER_NULL) { + ticker_resched = &nodes[ticker_id_resched]; + if (TICKER_RESCHEDULE_PENDING(ticker_resched)) { /* Pending reschedule found */ break; } - ticker_id_head = ticker->next; + ticker_id_resched = ticker_resched->next; } - if (ticker_id_head == TICKER_NULL) { + if (ticker_id_resched == TICKER_NULL) { /* Done */ break; } /* Check for intersection with already active node */ + window_start_ticks = 0U; if (instance->ticks_slot_previous > ticks_elapsed) { /* Active node intersects - window starts after end of * active slot @@ -2371,7 +2374,7 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, ticks_elapsed; } - ticker_id_iter = nodes[ticker_id_head].next; + ticker_id_next = ticker_resched->next; /* If drift was applied to this node, this must be * taken into consideration. Reduce the window with @@ -2382,43 +2385,50 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, * ticker would have the best possible window to re-schedule in * and not be restricted to ticks_slot_window - ticks_drift. */ - ext_data = ticker->ext_data; + ext_data = ticker_resched->ext_data; if (ext_data->ticks_drift < ext_data->ticks_slot_window) { ticks_slot_window = ext_data->ticks_slot_window - ext_data->ticks_drift; } else { /* Window has been exhausted - we can't reschedule */ - ticker_id_iter = TICKER_NULL; + ticker_id_next = TICKER_NULL; + + /* Assignment will be unused when TICKER_NULL */ + ticks_slot_window = 0U; } /* Use ticker's reserved time ticks_slot, else for unreserved * tickers use the reschedule margin as ticks_slot. */ - if (ticker->ticks_slot) { - ticks_slot = ticker->ticks_slot; + if (ticker_resched->ticks_slot) { + ticks_slot = ticker_resched->ticks_slot; } else { - LL_ASSERT(TICKER_HAS_SLOT_WINDOW(ticker)); + LL_ASSERT(TICKER_HAS_SLOT_WINDOW(ticker_resched)); ticks_slot = HAL_TICKER_RESCHEDULE_MARGIN; } /* Try to find available slot for re-scheduling */ - while ((ticker_id_iter != TICKER_NULL) && + ticks_to_expire_offset = 0U; + ticks_start_offset = 0U; + ticks_to_expire = 0U; + while ((ticker_id_next != TICKER_NULL) && ((ticks_start_offset + ticks_slot) <= ticks_slot_window)) { - uint32_t window_end_ticks = 0U; - struct ticker_node *node; + struct ticker_node *ticker_next; + uint32_t window_end_ticks; - node = &nodes[ticker_id_iter]; - ticks_to_expire_offset += node->ticks_to_expire; + ticker_next = &nodes[ticker_id_next]; + ticks_to_expire_offset += ticker_next->ticks_to_expire; /* Skip other pending re-schedule nodes and * tickers with no reservation or not periodic */ - if (TICKER_RESCHEDULE_PENDING(node) || - !node->ticks_slot || - !node->ticks_periodic) { - ticker_id_iter = node->next; + if (TICKER_RESCHEDULE_PENDING(ticker_next) || + !ticker_next->ticks_slot || + !ticker_next->ticks_periodic) { + ticker_id_next = ticker_next->next; + continue; } @@ -2444,7 +2454,7 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, */ if (window_end_ticks > (ticks_start_offset + ticks_slot)) { - if (!ticker->ticks_slot) { + if (!ticker_resched->ticks_slot) { /* Place at start of window */ ticks_to_expire = window_start_ticks; } else { @@ -2477,10 +2487,10 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, */ ticks_start_offset += ticks_to_expire_offset; window_start_ticks = ticks_start_offset + - node->ticks_slot; + ticker_next->ticks_slot; ticks_to_expire_offset = 0U; - if (!ticker->ticks_slot) { + if (!ticker_resched->ticks_slot) { /* Try at the end of the next node */ ticks_to_expire = window_start_ticks; } else { @@ -2493,56 +2503,61 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, ticks_slot; } - ticker_id_iter = node->next; + ticker_id_next = ticker_next->next; } ext_data->ticks_drift += ticks_to_expire - - ticker->ticks_to_expire; - ticker->ticks_to_expire = ticks_to_expire; - ticker_id_iter = nodes[ticker_id_head].next; - ticker_id_prev = TICKER_NULL; + ticker_resched->ticks_to_expire; + ticker_resched->ticks_to_expire = ticks_to_expire; /* Place the ticker node sorted by expiration time and adjust * delta times */ - while (ticker_id_iter != TICKER_NULL) { - struct ticker_node *node; + ticker_id_next = ticker_resched->next; + ticker_id_prev = TICKER_NULL; + while (ticker_id_next != TICKER_NULL) { + struct ticker_node *ticker_next; - node = &nodes[ticker_id_iter]; - if (ticker->ticks_to_expire > node->ticks_to_expire) { + ticker_next = &nodes[ticker_id_next]; + if (ticker_resched->ticks_to_expire > + ticker_next->ticks_to_expire) { /* Node is after this - adjust delta */ - ticker->ticks_to_expire -= - node->ticks_to_expire; + ticker_resched->ticks_to_expire -= + ticker_next->ticks_to_expire; } else { /* Node is before this one */ - node->ticks_to_expire -= - ticker->ticks_to_expire; + ticker_next->ticks_to_expire -= + ticker_resched->ticks_to_expire; break; } - ticker_id_prev = ticker_id_iter; - ticker_id_iter = node->next; + ticker_id_prev = ticker_id_next; + ticker_id_next = ticker_next->next; } + /* If the node moved in the list, insert it */ if (ticker_id_prev != TICKER_NULL) { + LL_ASSERT(instance->ticker_id_head == + ticker_id_resched); + /* Node did not become the first - update head and * insert node after 'previous' */ - instance->ticker_id_head = nodes[ticker_id_head].next; + instance->ticker_id_head = ticker_resched->next; /* Link inserted node */ - nodes[ticker_id_head].next = nodes[ticker_id_prev].next; - nodes[ticker_id_prev].next = ticker_id_head; + ticker_resched->next = nodes[ticker_id_prev].next; + nodes[ticker_id_prev].next = ticker_id_resched; } /* Remove latency added in ticker_worker */ - ticker->lazy_current--; + ticker_resched->lazy_current--; /* Prevent repeated re-scheduling */ ext_data->reschedule_state = TICKER_RESCHEDULE_STATE_DONE; #if defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO) - ticker_mark_expire_info_outdated(instance, ticker_id_head); + ticker_mark_expire_info_outdated(instance, ticker_id_resched); #endif /* CONFIG_BT_TICKER_EXT_EXPIRE_INFO */ /* Check for other pending re-schedules and set exit flag */ From 730249a34382716d6593e50bbd03aa0c3c1561ac Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 5 Oct 2023 10:35:03 +0200 Subject: [PATCH 0286/1623] [nrf fromtree] Bluetooth: Controller: Fix leak in scheduled ticker node Fix leak in scheduled ticker node when rescheduling ticker nodes. Applications having active Extended Advertising or Observer role with the use of ticker reschedule in window feature would experience assertion check failure due to delayed radio event preparation or stalled controller with no active roles. Fix updating of the ticker linked list when handling rescheduled tickers. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit e50748b67cd9d7d554d87bf27ceef0307f9d63ac) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 9cce789dee1302573d700ce391b24f0a55b7c7c7) --- subsys/bluetooth/controller/ticker/ticker.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index 9b5bb53a625..83bd6437d59 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -2337,6 +2337,7 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, while (rescheduling) { struct ticker_node *ticker_resched; uint32_t ticks_to_expire_offset; + uint8_t ticker_id_resched_prev; struct ticker_ext *ext_data; uint32_t ticks_start_offset; uint32_t window_start_ticks; @@ -2350,6 +2351,7 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, rescheduling = 0U; /* Find first pending re-schedule */ + ticker_id_resched_prev = TICKER_NULL; ticker_id_resched = instance->ticker_id_head; while (ticker_id_resched != TICKER_NULL) { ticker_resched = &nodes[ticker_id_resched]; @@ -2357,6 +2359,8 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, /* Pending reschedule found */ break; } + + ticker_id_resched_prev = ticker_id_resched; ticker_id_resched = ticker_resched->next; } if (ticker_id_resched == TICKER_NULL) { @@ -2536,13 +2540,15 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, /* If the node moved in the list, insert it */ if (ticker_id_prev != TICKER_NULL) { - LL_ASSERT(instance->ticker_id_head == - ticker_id_resched); - - /* Node did not become the first - update head and - * insert node after 'previous' - */ - instance->ticker_id_head = ticker_resched->next; + /* Remove node from its current position in list */ + if (ticker_id_resched_prev != TICKER_NULL) { + /* Node was not at the head of the list */ + nodes[ticker_id_resched_prev].next = + ticker_resched->next; + } else { + /* Node was at the head, move head forward */ + instance->ticker_id_head = ticker_resched->next; + } /* Link inserted node */ ticker_resched->next = nodes[ticker_id_prev].next; From 68a8baa59b3e58f0e88623996868009d4e5f3741 Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Thu, 8 Jun 2023 11:58:00 +0200 Subject: [PATCH 0287/1623] [nrf fromtree] Bluetooth: controller: fix failing EBQ advertising tests Updates the chaining for advertising. Instead of unconditionally adding a new PDU when new data is added we now instead fill the last PDU in the chain with the incoming data, only adding a new PDU when there is not enough room. This reduces the nr. of PDUs used for advertising, and also fixes some qualification failures Signed-off-by: Andries Kruithof (cherry picked from commit d00d44c92537938fe72e4cc19a05f8e752fb6097) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 8312c87dffa2661dbcc2b984bfe510412a283fca) --- .../src/broadcaster_multiple.c | 1 - .../bluetooth/controller/ll_sw/ull_adv_aux.c | 154 ++++++++++++------ tests/bsim/bluetooth/host/adv/chain/prj.conf | 5 +- 3 files changed, 111 insertions(+), 49 deletions(-) diff --git a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c index 56cc210de78..d1c6d792e95 100644 --- a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c +++ b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c @@ -75,7 +75,6 @@ int broadcaster_multiple(void) printk("Bluetooth init failed (err %d)\n", err); return err; } - for (int index = 0; index < CONFIG_BT_EXT_ADV_MAX_ADV_SET; index++) { /* Use advertising set instance index as SID */ adv_param.sid = index; diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c index 302dc6da785..0754a047207 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c @@ -117,6 +117,7 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, uint8_t ad_len_overflow; uint8_t ad_len_chain; struct pdu_adv *pdu; + uint8_t ad_len = 0U; #endif /* CONFIG_BT_CTLR_ADV_AUX_PDU_LINK */ /* Get the advertising set instance */ @@ -301,7 +302,7 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, struct pdu_adv *pdu_chain_prev; struct pdu_adv *pdu_chain; uint16_t ad_len_total; - uint8_t ad_len_prev; + uint8_t ad_len_prev = 0U; /* Traverse to next set clear hdr data parameter */ val_ptr += sizeof(data); @@ -317,28 +318,22 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, ad_len_total = 0U; pdu_chain_prev = pdu_prev; pdu_chain = pdu; + /* make a copy of the previous chain, until we reach the end */ do { - /* Prepare for aux ptr field reference to be returned, hence - * second parameter will be for AD data field. - */ - *val_ptr = 0U; - (void)memset((void *)&val_ptr[ULL_ADV_HDR_DATA_DATA_PTR_OFFSET], - 0U, ULL_ADV_HDR_DATA_DATA_PTR_SIZE); + val_ptr = hdr_data; + *val_ptr++ = 0U; + (void)memset((void *)val_ptr, 0U, + ULL_ADV_HDR_DATA_DATA_PTR_SIZE); pdu_prev = pdu_chain_prev; pdu = pdu_chain; - /* Add Aux Ptr field if not already present */ err = ull_adv_aux_pdu_set_clear(adv, pdu_prev, pdu, - (ULL_ADV_PDU_HDR_FIELD_AD_DATA | - ULL_ADV_PDU_HDR_FIELD_AUX_PTR), - 0, hdr_data); - LL_ASSERT(!err || (err == BT_HCI_ERR_PACKET_TOO_LONG)); + ULL_ADV_PDU_HDR_FIELD_AD_DATA, + 0U, hdr_data); + ad_len_prev = hdr_data[ULL_ADV_HDR_DATA_LEN_OFFSET]; - /* Get PDUs previous AD data length */ - ad_len_prev = - hdr_data[ULL_ADV_HDR_DATA_AUX_PTR_PTR_OFFSET + - ULL_ADV_HDR_DATA_AUX_PTR_PTR_SIZE]; + LL_ASSERT(!err || (err == BT_HCI_ERR_PACKET_TOO_LONG)); /* Check of max supported AD data len */ ad_len_total += ad_len_prev; @@ -365,31 +360,10 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, (!pdu_chain_prev && !pdu_chain)); } while (pdu_chain_prev); - if (err == BT_HCI_ERR_PACKET_TOO_LONG) { - ad_len_overflow = - hdr_data[ULL_ADV_HDR_DATA_AUX_PTR_PTR_OFFSET + - ULL_ADV_HDR_DATA_AUX_PTR_PTR_SIZE + - ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + - ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; - - /* Prepare for aux ptr field reference to be returned, - * hence second parameter will be for AD data field. - * Fill it with reduced AD data length. - */ - *val_ptr = ad_len_prev - ad_len_overflow; - - /* AD data len in chain PDU */ - ad_len_chain = len; - - /* Proceed to add chain PDU */ - err = 0U; - } else { - /* No AD data overflow */ - ad_len_overflow = 0U; - - /* No AD data in chain PDU */ - ad_len_chain = 0U; - } + /* No AD data overflow */ + ad_len_overflow = 0U; + /* No AD data in chain PDU */ + ad_len_chain = 0U; } #else /* !CONFIG_BT_CTLR_ADV_AUX_PDU_LINK */ } else { @@ -411,8 +385,88 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, #if defined(CONFIG_BT_CTLR_ADV_AUX_PDU_LINK) if ((op == BT_HCI_LE_EXT_ADV_OP_INTERM_FRAG) || - (op == BT_HCI_LE_EXT_ADV_OP_LAST_FRAG) || - ad_len_overflow) { + (op == BT_HCI_LE_EXT_ADV_OP_LAST_FRAG)) { + /* in the previous step we duplicated the chain + * the next step is to append new data in the last existing pdu in the chain, + */ + + uint8_t chain_err = 0U; + + val_ptr = hdr_data; + *val_ptr++ = len; + (void)memcpy(val_ptr, &data, sizeof(data)); + + /* Append data to the last PDU */ + chain_err = ull_adv_aux_pdu_set_clear(adv, pdu_prev, pdu, + ULL_ADV_PDU_HDR_FIELD_AD_DATA_APPEND, + 0U, hdr_data); + + LL_ASSERT((!chain_err) || (chain_err == BT_HCI_ERR_PACKET_TOO_LONG)); + + /* FIXME: the code has become quite complex, an alternative and simpler + * implementation would be to first fill an array with all data that + * must be send, and create the chained PDUs from this array + */ + if (chain_err == BT_HCI_ERR_PACKET_TOO_LONG) { + /* We could not fit all the data, append as much as possible + * ad_len_overflow is how much overflows with the AUX ptr + */ + uint8_t ad_len_overflow_first_try; + const uint16_t chain_add_fields = ULL_ADV_PDU_HDR_FIELD_AD_DATA_APPEND | + ULL_ADV_PDU_HDR_FIELD_AUX_PTR; + + ad_len_overflow_first_try = hdr_data[ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + + ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; + + val_ptr = hdr_data; + *val_ptr++ = len; + (void)memcpy(val_ptr, &data, sizeof(data)); + val_ptr += sizeof(data); + *val_ptr++ = len; + (void)memcpy(val_ptr, &data, sizeof(data)); + chain_err = ull_adv_aux_pdu_set_clear(adv, pdu_prev, pdu, + chain_add_fields, + 0U, hdr_data); + ad_len_overflow = hdr_data[ULL_ADV_HDR_DATA_AUX_PTR_PTR_OFFSET + + ULL_ADV_HDR_DATA_AUX_PTR_PTR_SIZE + + ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + + ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; + + /* ad_len_overflow - ad_len_overflow_first_try is the size of + * the aux pointer + * ad_len_prev is how much data is already present, ad_len is how + * much data we can add to this PDU + */ + ad_len = PDU_AC_PAYLOAD_SIZE_MAX - ad_len_prev - + (ad_len_overflow - ad_len_overflow_first_try) - 4; + + val_ptr = hdr_data; + *val_ptr++ = ad_len; + (void)memcpy(val_ptr, &data, sizeof(data)); + val_ptr += sizeof(data); + *val_ptr++ = ad_len; + (void)memcpy(val_ptr, &data, sizeof(data)); + + /* we now know how much data we can add to the + * last PDU without getting an overflow + */ + chain_err = ull_adv_aux_pdu_set_clear(adv, pdu_prev, pdu, + chain_add_fields, + 0U, hdr_data); + LL_ASSERT(chain_err == 0U); + /* + * in the next PDU we still need to add ad_len_chain bytes of data + * but we do not have overflow, since we already added + * the exact amount that would fit + */ + ad_len_chain = len - ad_len; + ad_len_overflow = 0U; + } else { + ad_len_overflow = 0U; + } + } + + if (ad_len_chain || ad_len_overflow) { struct pdu_adv_com_ext_adv *com_hdr_chain; struct pdu_adv_com_ext_adv *com_hdr; struct pdu_adv_ext_hdr *hdr_chain; @@ -425,6 +479,7 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, uint16_t sec_len; uint8_t *dptr; + len = ad_len_chain; /* Get reference to flags in superior PDU */ com_hdr = &pdu->adv_ext_ind; if (com_hdr->ext_hdr_len) { @@ -450,6 +505,7 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, hdr_chain = (void *)&com_hdr_chain->ext_hdr_adv_data[0]; dptr_chain = (void *)hdr_chain; + LL_ASSERT(dptr_chain); /* Flags */ *dptr_chain = 0U; @@ -498,6 +554,7 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, if (ad_len_overflow) { uint8_t *ad_overflow; + val_ptr = hdr_data; /* Copy overflowed AD data from previous PDU into this * new chain PDU */ @@ -505,6 +562,7 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, &val_ptr[ULL_ADV_HDR_DATA_DATA_PTR_OFFSET], sizeof(ad_overflow)); ad_overflow += *val_ptr; + (void)memcpy(dptr_chain, ad_overflow, ad_len_overflow); dptr_chain += ad_len_overflow; @@ -529,8 +587,6 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, return err; } - /* AD data len in chain PDU besides the overflow */ - len = ad_len_chain; } /* Check AdvData overflow */ @@ -555,7 +611,13 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, pdu_chain->len = sec_len + ad_len_overflow + len; /* Fill AD Data in chain PDU */ - (void)memcpy(dptr_chain, data, len); + if (ad_len_overflow != 0U) { + (void)memcpy(dptr_chain, data, ad_len_overflow); + } + + if (ad_len_chain != 0U) { + (void)memcpy(dptr_chain, &data[ad_len + ad_len_overflow], ad_len_chain); + } /* Get reference to aux ptr in superior PDU */ (void)memcpy(&aux_ptr, diff --git a/tests/bsim/bluetooth/host/adv/chain/prj.conf b/tests/bsim/bluetooth/host/adv/chain/prj.conf index 3e7f11009c2..85861dccd66 100644 --- a/tests/bsim/bluetooth/host/adv/chain/prj.conf +++ b/tests/bsim/bluetooth/host/adv/chain/prj.conf @@ -30,8 +30,9 @@ CONFIG_BT_EXT_SCAN_BUF_SIZE=1650 # Set maximum scan data length for Extended Scanning in Bluetooth LE Controller CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 -# Zephyr Bluetooth LE Controller needs 16 event buffers to generate Extended -# Advertising Report for receiving the complete 1650 bytes of data +# Zephyr Controller does not combine all the 1650 bytes before fragmenting them +# into 8 HCI reports, if a PDU has 255 bytes, it will generate 2 HCI reports +# and so we need to reserve 16 buffers CONFIG_BT_BUF_EVT_RX_COUNT=16 # Increase Zephyr Bluetooth LE Controller Rx buffer to receive complete chain From 8eefe7f80331b72b2bcf00113684fb60fbad906f Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Mon, 2 Oct 2023 12:15:47 +0200 Subject: [PATCH 0288/1623] [nrf fromtree] Bluetooth: controller: change calc for data in PDU The existing formula for the amount of data that can be filled in in the current PDU is correct but confusing. Replace it with a simpler formula. Signed-off-by: Andries Kruithof (cherry picked from commit e8716bf793c45b5cc562161cdde8669e96643178) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 39a88e6bd34bb87e94cc995337dfc2725838ddbe) --- .../bluetooth/controller/ll_sw/ull_adv_aux.c | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c index 0754a047207..2480c286e4b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c @@ -411,13 +411,9 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, /* We could not fit all the data, append as much as possible * ad_len_overflow is how much overflows with the AUX ptr */ - uint8_t ad_len_overflow_first_try; const uint16_t chain_add_fields = ULL_ADV_PDU_HDR_FIELD_AD_DATA_APPEND | ULL_ADV_PDU_HDR_FIELD_AUX_PTR; - ad_len_overflow_first_try = hdr_data[ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + - ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; - val_ptr = hdr_data; *val_ptr++ = len; (void)memcpy(val_ptr, &data, sizeof(data)); @@ -427,18 +423,18 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, chain_err = ull_adv_aux_pdu_set_clear(adv, pdu_prev, pdu, chain_add_fields, 0U, hdr_data); - ad_len_overflow = hdr_data[ULL_ADV_HDR_DATA_AUX_PTR_PTR_OFFSET + - ULL_ADV_HDR_DATA_AUX_PTR_PTR_SIZE + - ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + - ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; - - /* ad_len_overflow - ad_len_overflow_first_try is the size of - * the aux pointer - * ad_len_prev is how much data is already present, ad_len is how - * much data we can add to this PDU + ad_len_chain = hdr_data[ULL_ADV_HDR_DATA_AUX_PTR_PTR_OFFSET + + ULL_ADV_HDR_DATA_AUX_PTR_PTR_SIZE + + ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + + ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; + + /* len is the total amount of datawe want to add + * ad_len_chain is the amount of data that does + * not fit in the current PDU + * the difference of the two is the amount that + * we can fit in the current PDU */ - ad_len = PDU_AC_PAYLOAD_SIZE_MAX - ad_len_prev - - (ad_len_overflow - ad_len_overflow_first_try) - 4; + ad_len = len - ad_len_chain; val_ptr = hdr_data; *val_ptr++ = ad_len; @@ -457,9 +453,10 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, /* * in the next PDU we still need to add ad_len_chain bytes of data * but we do not have overflow, since we already added - * the exact amount that would fit + * the exact amount that would fit. We explicitly set overflow to 0. + * FIXME: ad_len_overflow already should be 0, to be verified. We wait + * fixing this until rewriting this whole function */ - ad_len_chain = len - ad_len; ad_len_overflow = 0U; } else { ad_len_overflow = 0U; From 96efa92108ad91cec08e0c23b557433cfc0d6ddb Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Tue, 18 Jul 2023 11:13:31 +0200 Subject: [PATCH 0289/1623] [nrf fromtree] Test: Bluetooth: controller: add CI testing for advertising chaining Update babblesim tests for testing chaining for advertising to ensure that we spill over to the next PDU Signed-off-by: Andries Kruithof (cherry picked from commit e04c963d9c2daf1c38e4498a19362cbed9375eea) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit a18d656e24fb1f99b8f52039f9e197a9162f15e5) --- .../broadcaster_multiple/src/broadcaster_multiple.c | 10 +++++++++- tests/bsim/bluetooth/host/adv/chain/prj.conf | 6 +++--- tests/bsim/bluetooth/host/adv/chain/src/main.c | 10 +++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c index d1c6d792e95..30fe35d3dec 100644 --- a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c +++ b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c @@ -47,11 +47,18 @@ BT_AD_DATA_FORMAT_LEN_SIZE - \ BT_AD_DATA_FORMAT_TYPE_SIZE - \ BT_DEVICE_NAME_AD_DATA_LEN))) - +/* + * Datalength is an integer, so BT_MFG_DATA_LEN can not be larger than 255. + * To ensure that we need to chain PDUs we therefore add manufacturer data + * twice when chaining is enabled + */ static uint8_t mfg_data[BT_MFG_DATA_LEN] = { 0xFF, 0xFF, }; static const struct bt_data ad[] = { BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, sizeof(mfg_data)), +#if defined(CONFIG_BT_CTLR_ADV_DATA_CHAIN) + BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, sizeof(mfg_data)), +#endif }; static struct bt_le_ext_adv *adv[CONFIG_BT_EXT_ADV_MAX_ADV_SET]; @@ -75,6 +82,7 @@ int broadcaster_multiple(void) printk("Bluetooth init failed (err %d)\n", err); return err; } + for (int index = 0; index < CONFIG_BT_EXT_ADV_MAX_ADV_SET; index++) { /* Use advertising set instance index as SID */ adv_param.sid = index; diff --git a/tests/bsim/bluetooth/host/adv/chain/prj.conf b/tests/bsim/bluetooth/host/adv/chain/prj.conf index 85861dccd66..82eb16e5db0 100644 --- a/tests/bsim/bluetooth/host/adv/chain/prj.conf +++ b/tests/bsim/bluetooth/host/adv/chain/prj.conf @@ -30,9 +30,9 @@ CONFIG_BT_EXT_SCAN_BUF_SIZE=1650 # Set maximum scan data length for Extended Scanning in Bluetooth LE Controller CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 -# Zephyr Controller does not combine all the 1650 bytes before fragmenting them -# into 8 HCI reports, if a PDU has 255 bytes, it will generate 2 HCI reports -# and so we need to reserve 16 buffers +# The Zephyr Controller does not combine all the 1650 bytes before +# fragmenting into 8 HCI reports, if a PDU has 255 bytes, +# it will generate 2 HCI reports and so we need to reserve 16 buffers CONFIG_BT_BUF_EVT_RX_COUNT=16 # Increase Zephyr Bluetooth LE Controller Rx buffer to receive complete chain diff --git a/tests/bsim/bluetooth/host/adv/chain/src/main.c b/tests/bsim/bluetooth/host/adv/chain/src/main.c index 4475a069535..d58d2a3890f 100644 --- a/tests/bsim/bluetooth/host/adv/chain/src/main.c +++ b/tests/bsim/bluetooth/host/adv/chain/src/main.c @@ -34,8 +34,12 @@ #define NAME_LEN 30 #define BT_AD_DATA_NAME_SIZE (sizeof(CONFIG_BT_DEVICE_NAME) - 1U + 2U) #define BT_AD_DATA_MFG_DATA_SIZE (254U + 2U) +/* + * for testing chaining the manufacturing data is duplicated, hence DATA_LEN needs to + * add twice the size for this element + */ #define DATA_LEN MIN((BT_AD_DATA_NAME_SIZE + \ - BT_AD_DATA_MFG_DATA_SIZE), \ + BT_AD_DATA_MFG_DATA_SIZE + BT_AD_DATA_MFG_DATA_SIZE), \ CONFIG_BT_CTLR_ADV_DATA_LEN_MAX) static K_SEM_DEFINE(sem_recv, 0, 1); @@ -94,6 +98,7 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, data_len = buf->len; if (data_len != DATA_LEN) { + printk("Received datalength: %d\n", data_len); return; } @@ -101,11 +106,13 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, bt_data_parse(buf, data_cb, name); if (strcmp(name, CONFIG_BT_DEVICE_NAME)) { + printk("Wrong name %s\n", name); return; } for (uint8_t i = 0; i < sid_count; i++) { if (sid[i] == info->sid) { + printk("Received SID %d\n", info->sid); return; } } @@ -113,6 +120,7 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, sid[sid_count++] = info->sid; if (sid_count < CONFIG_BT_EXT_ADV_MAX_ADV_SET) { + printk("Received advertising sets: %d\n", sid_count); return; } From 7b202de62b4f1ed8938747b4664972b02b565942 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 12 Sep 2023 09:43:08 +0200 Subject: [PATCH 0290/1623] [nrf fromtree] nrf5x_bsim: Add helper kconfig symbols for simulated nrf5340 Just like for the nrf52_bsim let's add helper kconfig symbols which can be used to identify we are running in a target that is compatible with the real HW but is not the real HW. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 0e8f97df49a497de4a71d681bc34f429b239862c) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 7f9da74cbc9552984bac1b7fc9d08823aaf2b90d) --- boards/posix/nrf52_bsim/Kconfig | 6 ++++++ soc/Kconfig | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/boards/posix/nrf52_bsim/Kconfig b/boards/posix/nrf52_bsim/Kconfig index ea1b49bea0a..566520fafa0 100644 --- a/boards/posix/nrf52_bsim/Kconfig +++ b/boards/posix/nrf52_bsim/Kconfig @@ -26,3 +26,9 @@ config SOC_SERIES_BSIM_NRF52X depends on SOC_SERIES_BSIM_NRFXX help Any NRF52 simulated SOC with BabbleSim, based on the POSIX arch + +config SOC_SERIES_BSIM_NRF53X + bool + depends on SOC_SERIES_BSIM_NRFXX + help + Any NRF53 simulated SOC with BabbleSim, based on the POSIX arch diff --git a/soc/Kconfig b/soc/Kconfig index 20734c0f51f..33c2d0c29a4 100644 --- a/soc/Kconfig +++ b/soc/Kconfig @@ -24,8 +24,7 @@ source "subsys/logging/Kconfig.template.log_config" endmenu # The helper symbols below are put here due to an unusual setup: The simulated -# nrf52_bsim board uses the POSIX arch, but is compatible with Nordic ARM -# boards +# nrf5x_bsim boards use the POSIX arch, but are compatible with Nordic ARM boards config SOC_COMPATIBLE_NRF bool @@ -33,9 +32,18 @@ config SOC_COMPATIBLE_NRF config SOC_COMPATIBLE_NRF52X bool +config SOC_COMPATIBLE_NRF53X + bool + config SOC_COMPATIBLE_NRF52833 bool +config SOC_COMPATIBLE_NRF5340_CPUNET + bool + +config SOC_COMPATIBLE_NRF5340_CPUAPP + bool + # # SOC_*_LD: SoC specific Linker script additions # From ff4e15ae36af8fc8abe680e8a418f882d97e731d Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 21 Sep 2023 08:45:38 +0200 Subject: [PATCH 0291/1623] [nrf fromtree] soc nordic_nrf: Select new compatible kconfig options Select the newly introduced nrf53 compatible kconfig options. These are common both for real HW and for simulated HW, allowing SW to behave appropriately for both. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit c7c3c82aa0104c7063879d8d4a27a0d5c6b29c0a) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 509f1bc70c6a0ff7d706de9c049d32875d54eea2) --- soc/arm/nordic_nrf/nrf53/Kconfig.series | 1 + soc/arm/nordic_nrf/nrf53/Kconfig.soc | 2 ++ 2 files changed, 3 insertions(+) diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.series b/soc/arm/nordic_nrf/nrf53/Kconfig.series index 03e47bacf63..8ab81ad310b 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.series +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.series @@ -6,6 +6,7 @@ config SOC_SERIES_NRF53X bool "Nordic Semiconductor nRF53 series MCU" select ARM + select SOC_COMPATIBLE_NRF53X select CPU_CORTEX_M33 select CPU_CORTEX_M_HAS_DWT select CPU_HAS_ARM_MPU diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 2ad4a7add66..87d8a6d0c7a 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -10,11 +10,13 @@ config SOC_NRF5340_CPUAPP select CPU_HAS_FPU select ARMV8_M_DSP select HAS_POWEROFF + select SOC_COMPATIBLE_NRF5340_CPUAPP imply SOC_NRF53_RTC_PRETICK config SOC_NRF5340_CPUNET bool select ARM_ON_EXIT_CPU_IDLE + select SOC_COMPATIBLE_NRF5340_CPUNET imply SOC_NRF53_ANOMALY_160_WORKAROUND_NEEDED imply SOC_NRF53_RTC_PRETICK if !WDT_NRFX From 9530f3bfb97b911974d607a58bd00cdab7887fa3 Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Wed, 5 Jul 2023 16:13:20 +0200 Subject: [PATCH 0292/1623] [nrf fromtree] tests: bluetooth: controller: Test for framed TX in consecutive events Changes: -- Included a test to check TX in concesecutive events irrespective of the input target event -- Updated expected output of current tests for change in framed RX error handling which waiting for the start of an event Signed-off-by: Nirosharn Amarasinghe (cherry picked from commit ec2093862784369892b2a386c9399a0c98267858) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 791b3edfb4af63a2ec79f8a0f006e3d56894014a) --- .../ctrl_isoal/src/sub_sets/isoal_test_rx.c | 109 +-- .../ctrl_isoal/src/sub_sets/isoal_test_tx.c | 754 ++++++++++++++---- 2 files changed, 682 insertions(+), 181 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c index 2ce8862e1d4..5a3c60e0854 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c @@ -8332,27 +8332,30 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1) */ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) { + const uint8_t test_data_size = 33; + const uint8_t max_sdu_burst = 2; + + struct rx_sdu_frag_buffer rx_sdu_frag_buf[max_sdu_burst]; + struct isoal_sdu_buffer sdu_buffer[max_sdu_burst]; + isoal_sdu_status_t collated_status[max_sdu_burst]; struct rx_pdu_meta_buffer rx_pdu_meta_buf; - struct rx_sdu_frag_buffer rx_sdu_frag_buf; - struct isoal_sdu_buffer sdu_buffer; - isoal_sdu_status_t collated_status; + isoal_sdu_len_t sdu_size[max_sdu_burst]; + uint16_t total_sdu_size[max_sdu_burst]; + uint32_t sdu_timestamp[max_sdu_burst]; + uint8_t testdata[test_data_size]; isoal_sink_handle_t sink_hdl; uint32_t stream_sync_delay; uint32_t group_sync_delay; - isoal_sdu_len_t sdu_size; uint8_t iso_interval_int; uint16_t pdu_data_loc[5]; uint32_t iso_interval_us; uint64_t payload_number; - uint16_t total_sdu_size; uint32_t sdu_timeoffset; uint32_t pdu_timestamp; - uint32_t sdu_timestamp; uint16_t testdata_indx; uint16_t testdata_size; uint32_t sdu_interval; isoal_sdu_cnt_t seqn; - uint8_t testdata[33]; isoal_status_t err; uint32_t latency; uint8_t role; @@ -8371,12 +8374,14 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); - isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); - init_test_data_buffer(testdata, 33); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); + init_test_data_buffer(testdata, test_data_size); memset(pdu_data_loc, 0, sizeof(pdu_data_loc)); - sdu_buffer.dbuf = &rx_sdu_frag_buf; - sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0]; + sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1]; + sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; payload_number = 1000 * BN; pdu_timestamp = 9249; latency = calc_rx_latency_by_role(role, @@ -8388,13 +8393,13 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; /* PDU will have errors. Time stamp is only an approximation */ - sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us); + sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us); seqn = 0; testdata_indx = 0; testdata_size = 23; - sdu_size = 0; - total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); - collated_status = + sdu_size[0] = 0; + total_sdu_size[0] = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); + collated_status[0] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */ @@ -8418,7 +8423,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ - push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; @@ -8428,25 +8433,14 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); /* Test recombine (Black Box) */ - /* A new SDU should be allocated */ - ZASSERT_ISOAL_SDU_ALLOC_TEST(val, - &isoal_global.sink_state[sink_hdl], /* Sink */ - &rx_pdu_meta_buf.pdu_meta); /* PDU */ + /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0); /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); - /* SDU should be emitted */ - ZASSERT_ISOAL_SDU_EMIT_TEST(val, - &isoal_global.sink_state[sink_hdl], /* Sink */ - BT_ISO_SINGLE, /* Frag state */ - sdu_size, /* Frag size */ - ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ - sdu_timestamp, /* Timestamp */ - seqn, /* Seq. number */ - sdu_buffer.dbuf, /* Buffer */ - sdu_buffer.size, /* Buffer size */ - total_sdu_size, /* Total size */ - collated_status); /* SDU status */ + /* SDU should not be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -8457,18 +8451,17 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) /* PDU 2 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); - isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]); payload_number++; sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); - sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); - seqn++; + sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); testdata_indx = testdata_size; testdata_size += 10; - sdu_size = 10; - total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); - collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); + sdu_size[1] = 10; + total_sdu_size[1] = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]); + collated_status[1] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); isoal_test_create_framed_pdu_base(payload_number, pdu_timestamp, @@ -8480,7 +8473,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ - push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; @@ -8490,14 +8483,38 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); /* Test recombine (Black Box) */ + /* SDU 0 -------------------------------------------------------------*/ + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(history[0], + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ + + /* SDU payload should not be written */ + + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(history[0], + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + sdu_size[0], /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp[0], /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer[0].dbuf, /* Buffer */ + sdu_buffer[0].size, /* Buffer size */ + total_sdu_size[0], /* Total size */ + collated_status[0]); /* SDU status */ + + /* SDU 1 -------------------------------------------------------------*/ + seqn++; /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ /* SDU payload should be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1); ZASSERT_ISOAL_SDU_WRITE_TEST(val, - &rx_sdu_frag_buf, /* SDU buffer */ + &rx_sdu_frag_buf[1], /* SDU buffer */ &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]], /* PDU payload */ (testdata_size - testdata_indx)); /* Size */ @@ -8506,14 +8523,14 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ BT_ISO_SINGLE, /* Frag state */ - sdu_size, /* Frag size */ + sdu_size[1], /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ - sdu_timestamp, /* Timestamp */ + sdu_timestamp[1], /* Timestamp */ seqn, /* Seq. number */ - sdu_buffer.dbuf, /* Buffer */ - sdu_buffer.size, /* Buffer size */ - total_sdu_size, /* Total size */ - collated_status); /* SDU status */ + sdu_buffer[1].dbuf, /* Buffer */ + sdu_buffer[1].size, /* Buffer size */ + total_sdu_size[1], /* Total size */ + collated_status[1]); /* SDU status */ /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c index fe375b7accd..dc21c9b5d61 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c @@ -111,7 +111,8 @@ static void push_custom_source_pdu_write_test_sdu_payload(const uint8_t *data, c } static void check_next_custom_source_pdu_write_test_sdu_payload(const uint8_t *data, - const size_t length) + const size_t length, + const uint32_t line) { size_t pos = custom_source_pdu_write_test_sdu_payloads.pos; size_t buffer_size = custom_source_pdu_write_test_sdu_payloads.buffer_size; @@ -125,7 +126,8 @@ static void check_next_custom_source_pdu_write_test_sdu_payload(const uint8_t *d for (size_t i = 0; i < custom_source_pdu_write_test_sdu_payloads.out_size[pos]; i++) { zassert_equal(custom_source_pdu_write_test_sdu_payloads.out[pos][i], data[i], - "deviation at index %u, expected %u, got %u", + "[Line %lu] deviation at index %u, expected %u, got %u", + line, i, data[i], custom_source_pdu_write_test_sdu_payloads.out[pos][i]); @@ -193,7 +195,7 @@ static isoal_status_t custom_source_pdu_write_test(struct isoal_pdu_buffer *pdu_ _consume_len, \ source_pdu_write_test_fake.arg3_##_typ); \ check_next_custom_source_pdu_write_test_sdu_payload((const uint8_t *)_sdu_payload, \ - _consume_len); + _consume_len, __LINE__); #define ZASSERT_PDU_WRITE_TEST_CALL_COUNT(_expected) \ zassert_equal(_expected, \ @@ -422,7 +424,7 @@ static isoal_source_handle_t basic_tx_test_setup(uint16_t handle, burst_number, flush_timeout, max_octets, - (iso_interval_int * CONN_INT_UNIT_US), + (iso_interval_int * ISO_INT_UNIT_US), sdu_interval, stream_sync_delay, group_sync_delay); @@ -536,8 +538,8 @@ ZTEST(test_tx_basics, test_source_isoal_test_create_destroy) max_octets = 40; sdu_interval_int = 1; iso_interval_int = 1; - iso_interval = iso_interval_int * CONN_INT_UNIT_US; - sdu_interval = sdu_interval_int * CONN_INT_UNIT_US; + iso_interval = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = sdu_interval_int * ISO_INT_UNIT_US; stream_sync_delay = iso_interval - 200; group_sync_delay = iso_interval - 50; @@ -606,8 +608,8 @@ ZTEST(test_tx_basics, test_source_isoal_test_create_destroy) max_octets += max_octets / 2; sdu_interval_int++; iso_interval_int = iso_interval_int * sdu_interval_int; - sdu_interval = (sdu_interval_int * CONN_INT_UNIT_US) - (framed ? 100 : 0); - iso_interval = iso_interval_int * CONN_INT_UNIT_US; + sdu_interval = (sdu_interval_int * ISO_INT_UNIT_US) - (framed ? 100 : 0); + iso_interval = iso_interval_int * ISO_INT_UNIT_US; stream_sync_delay = iso_interval - (200 * i); group_sync_delay = iso_interval - 50; } @@ -654,9 +656,9 @@ ZTEST(test_tx_basics, test_source_isoal_test_create_err) flush_timeout = 1; framed = false; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; - stream_sync_delay = CONN_INT_UNIT_US - 200; - group_sync_delay = CONN_INT_UNIT_US - 50; + sdu_interval = ISO_INT_UNIT_US; + stream_sync_delay = ISO_INT_UNIT_US - 200; + group_sync_delay = ISO_INT_UNIT_US - 50; res = isoal_init(); zassert_equal(res, ISOAL_STATUS_OK, "res = 0x%02x", res); @@ -747,12 +749,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_maxPDU) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -764,7 +766,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_maxPDU) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5; testdata_indx = 0; testdata_size = TEST_TX_PDU_PAYLOAD_MAX - 5; @@ -875,12 +877,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_bufSize) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -892,7 +894,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_bufSize) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX; testdata_indx = 0; testdata_size = TEST_TX_PDU_PAYLOAD_MAX; @@ -993,12 +995,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_3_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -1010,7 +1012,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_3_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = 100; testdata_indx = 0; testdata_size = 100; @@ -1152,12 +1154,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_1_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -1169,7 +1171,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_1_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX; testdata_indx = 0; testdata_size = TEST_TX_PDU_PAYLOAD_MAX / 3; @@ -1357,12 +1359,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_2_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 2; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -1378,7 +1380,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_2_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX * 2; testdata_indx = 0; testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3; @@ -1689,12 +1691,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_1_frag_2_pdu_ts_wrap1) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -1821,7 +1823,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_1_frag_2_pdu_ts_wrap1) /* Check TX Sync info */ tx_sync_seq_expected = 2; - tx_sync_timestamp_expected = (iso_interval_int * CONN_INT_UNIT_US) - 1; + tx_sync_timestamp_expected = (iso_interval_int * ISO_INT_UNIT_US) - 1; tx_sync_offset_expected = 0; err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset); @@ -1870,12 +1872,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 2; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 4; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -1891,7 +1893,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX * 2; testdata_indx = 0; testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3; @@ -2264,12 +2266,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 2; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 8; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -2289,7 +2291,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX * 2; testdata_indx = 0; testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3; @@ -2739,12 +2741,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_zero_sdu_1_frag_1_pdu_maxPDU_padding) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -2764,7 +2766,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_zero_sdu_1_frag_1_pdu_maxPDU_padding) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = 0; testdata_indx = 0; testdata_size = 0; @@ -2907,12 +2909,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_alloc_err) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -2924,7 +2926,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_alloc_err) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5; testdata_indx = 0; testdata_size = TEST_TX_PDU_PAYLOAD_MAX - 5; @@ -3024,12 +3026,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_emit_err) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -3041,7 +3043,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_emit_err) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5; testdata_indx = 0; testdata_size = TEST_TX_PDU_PAYLOAD_MAX - 5; @@ -3153,12 +3155,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US / 2; + sdu_interval = ISO_INT_UNIT_US / 2; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 2; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ /* Sets initial fragmentation status */ @@ -3171,7 +3173,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) event_number = 2000; sdu_packet_number = (event_number * BN); sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = 23; testdata_indx = 0; testdata_size = 23; @@ -3253,9 +3255,9 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); sdu_packet_number += 29; - sdu_timestamp += ((iso_interval_int * CONN_INT_UNIT_US) * 15) - sdu_interval; + sdu_timestamp += ((iso_interval_int * ISO_INT_UNIT_US) * 15) - sdu_interval; event_number += 15; - ref_point += (iso_interval_int * CONN_INT_UNIT_US) * 15; + ref_point += (iso_interval_int * ISO_INT_UNIT_US) * 15; sdu_total_size = 10; testdata_indx = testdata_size; testdata_size += 10; @@ -3303,7 +3305,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) /* Check TX Sync info */ tx_sync_seq_expected += 29; - tx_sync_timestamp_expected = ref_point - (iso_interval_int * CONN_INT_UNIT_US); + tx_sync_timestamp_expected = ref_point - (iso_interval_int * ISO_INT_UNIT_US); tx_sync_offset_expected = 0; err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset); @@ -3319,9 +3321,9 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); /* Same SDU packet sequence number for testing */ /* Time stamp just before the exact multiple of the SDU interval */ - sdu_timestamp += ((iso_interval_int * CONN_INT_UNIT_US) * 15) - 1; + sdu_timestamp += ((iso_interval_int * ISO_INT_UNIT_US) * 15) - 1; event_number += 15; - ref_point += (iso_interval_int * CONN_INT_UNIT_US) * 15; + ref_point += (iso_interval_int * ISO_INT_UNIT_US) * 15; sdu_total_size = 10; testdata_indx = testdata_size; testdata_size += 10; @@ -3369,7 +3371,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) /* Check TX Sync info */ tx_sync_seq_expected += 30; - tx_sync_timestamp_expected = ref_point - (iso_interval_int * CONN_INT_UNIT_US); + tx_sync_timestamp_expected = ref_point - (iso_interval_int * ISO_INT_UNIT_US); tx_sync_offset_expected = 0; err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset); @@ -3388,9 +3390,9 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) * +1 (reset to exact multiple of SDU interval from the last SDU) * +1 (push the time stamp 1us beyond the multiple mark) */ - sdu_timestamp += ((iso_interval_int * CONN_INT_UNIT_US) * 15) + 1 + 1; + sdu_timestamp += ((iso_interval_int * ISO_INT_UNIT_US) * 15) + 1 + 1; event_number += 15; - ref_point += (iso_interval_int * CONN_INT_UNIT_US) * 15; + ref_point += (iso_interval_int * ISO_INT_UNIT_US) * 15; sdu_total_size = 10; testdata_indx = testdata_size; testdata_size += 10; @@ -3438,7 +3440,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) /* Check TX Sync info */ tx_sync_seq_expected += 30; - tx_sync_timestamp_expected = ref_point - (iso_interval_int * CONN_INT_UNIT_US); + tx_sync_timestamp_expected = ref_point - (iso_interval_int * ISO_INT_UNIT_US); tx_sync_offset_expected = 0; err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset); @@ -3490,12 +3492,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_maxPDU) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -3510,7 +3512,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_maxPDU) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -3645,12 +3647,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_bufSize) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -3665,7 +3667,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_bufSize) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -3791,12 +3793,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -3810,7 +3812,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = 100 - ((3 * PDU_ISO_SEG_HDR_SIZE) + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; testdata_size = 100 - ((3 * PDU_ISO_SEG_HDR_SIZE) + PDU_ISO_SEG_TIMEOFFSET_SIZE); @@ -4022,12 +4024,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_1_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -4042,7 +4044,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_1_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -4281,12 +4283,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_2_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 2; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -4305,7 +4307,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_2_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) - ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -4583,12 +4585,12 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 2; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 4; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -4607,7 +4609,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = 9249 + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) - ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -4851,7 +4853,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_packet_number++; event_number = 2000; sdu_timestamp = 9249 + sdu_interval; - ref_point = 9249 + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) - ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -5115,12 +5117,12 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 2; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 6; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -5137,7 +5139,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = 9249 + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = testdata_size_max; testdata_indx = 0; testdata_size = testdata_size_max / number_of_sdu_frags; @@ -5374,7 +5376,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_packet_number++; event_number = 2000; sdu_timestamp = 9249 + sdu_interval; - ref_point = 9249 + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = testdata_size_max; testdata_indx = 0; testdata_size = testdata_size_max / number_of_sdu_frags; @@ -5661,12 +5663,12 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -5682,7 +5684,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -5800,7 +5802,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2) /* PDU 2 */ /* Advance the target event and the reference point to what it should be */ event_number++; - ref_point += iso_interval_int * CONN_INT_UNIT_US; + ref_point += iso_interval_int * ISO_INT_UNIT_US; payload_number++; seg_hdr[0].sc = 0; seg_hdr[0].cmplt = 0; @@ -5890,12 +5892,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_refPoint3) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -5955,7 +5957,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_refPoint3) /* PDU 1 */ /* Advance the target event and the reference point to what it should be */ event_number++; - ref_point += iso_interval_int * CONN_INT_UNIT_US; + ref_point += iso_interval_int * ISO_INT_UNIT_US; payload_number = event_number * BN; seg_hdr[0].sc = 0; seg_hdr[0].cmplt = 0; @@ -6046,12 +6048,12 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_ts_wrap1) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -6185,7 +6187,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_ts_wrap1) /* PDU 2 */ /* Advance the target event and the reference point to what it should be */ event_number++; - ref_point += iso_interval_int * CONN_INT_UNIT_US; + ref_point += iso_interval_int * ISO_INT_UNIT_US; payload_number++; seg_hdr[0].sc = 0; seg_hdr[0].cmplt = 0; @@ -6270,12 +6272,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_maxPDU) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -6288,7 +6290,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_maxPDU) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -6413,12 +6415,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -6439,7 +6441,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -6598,12 +6600,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_alloc_err) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -6618,7 +6620,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_alloc_err) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -6726,12 +6728,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_emit_err) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = CONN_INT_UNIT_US + 50; + sdu_interval = ISO_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -6746,7 +6748,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_emit_err) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -6879,8 +6881,8 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -6893,7 +6895,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) sdu_packet_number = 0; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -7056,7 +7058,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) event_number++; sdu_packet_number++; sdu_timestamp = sdu_timestamp + sdu_interval; - ref_point = ref_point + (iso_interval_int * CONN_INT_UNIT_US); + ref_point = ref_point + (iso_interval_int * ISO_INT_UNIT_US); sdu_total_size = 20; testdata_indx = testdata_size; testdata_size += 20; @@ -7129,6 +7131,488 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) isoal_global.source_state[source_hdl].session.handle); } +/** + * Test Suite : TX framed SDU segmentation + * + * Tests that consecutive events are used irrespective of the target event info + * as long as they are feasible. + */ +ZTEST(test_tx_framed, test_tx_framed_event_utilization_1) +{ + const uint8_t number_of_pdus = 3; + const uint8_t sdu_fragment_data_size = 25; + const uint8_t testdata_size_max = sdu_fragment_data_size * 4; + /* Two SDUs and one that would overflow into a new PDU */ + const uint8_t number_of_seg_hdr_buf = 3; + + struct tx_pdu_meta_buffer tx_pdu_meta_buf[number_of_pdus]; + struct pdu_iso_sdu_sh seg_hdr[number_of_seg_hdr_buf]; + struct isoal_pdu_buffer pdu_buffer[number_of_pdus]; + struct tx_sdu_frag_buffer tx_sdu_frag_buf; + uint8_t testdata[testdata_size_max]; + isoal_source_handle_t source_hdl; + isoal_sdu_len_t sdu_total_size; + isoal_pdu_len_t pdu_write_end; + uint32_t stream_sync_delay; + uint64_t sdu_packet_number; + uint32_t group_sync_delay; + uint64_t pdu_event_number; + uint8_t iso_interval_int; + uint32_t iso_interval_us; + uint64_t payload_number; + uint32_t pdu_ref_point; + uint32_t sdu_timestamp; + uint16_t testdata_indx; + uint16_t testdata_size; + uint16_t pdu_write_loc; + uint16_t sdu_read_loc; + uint64_t event_number; + uint32_t sdu_interval; + uint8_t sdu_fragments; + uint16_t pdu_hdr_loc; + uint32_t ref_point; + isoal_status_t err; + uint8_t max_octets; + uint8_t role; + uint8_t BN; + uint8_t FT; + + /* Settings */ + role = BT_CONN_ROLE_PERIPHERAL; + iso_interval_int = 1; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = ISO_INT_UNIT_US - 50; /* Less than an ISO interval */ + max_octets = TEST_TX_PDU_PAYLOAD_MAX; + BN = 2; + FT = 1; + stream_sync_delay = iso_interval_us - 200; + group_sync_delay = iso_interval_us - 50; + + /* SDU 0 -------------------------------------------------------------*/ + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]); + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]); + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + init_test_data_buffer(testdata, testdata_size_max); + (void)memset(&seg_hdr, 0, sizeof(seg_hdr)); + pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx; + pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu; + pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX; + pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx; + pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu; + pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX; + pdu_buffer[2].handle = (void *)&tx_pdu_meta_buf[2].node_tx; + pdu_buffer[2].pdu = (struct pdu_iso *)tx_pdu_meta_buf[2].node_tx.pdu; + pdu_buffer[2].size = TEST_TX_PDU_PAYLOAD_MAX; + sdu_packet_number = 0; + event_number = 5; + pdu_event_number = event_number; + sdu_timestamp = 9249; + ref_point = sdu_timestamp + iso_interval_us; + pdu_ref_point = ref_point; + sdu_total_size = sdu_fragment_data_size; + testdata_indx = 0; + testdata_size = sdu_fragment_data_size; + sdu_fragments = 0; + + source_hdl = basic_tx_test_setup(0xADAD, /* Handle */ + role, /* Role */ + true, /* Framed */ + BN, /* BN */ + FT, /* FT */ + max_octets, /* max_octets */ + sdu_interval, /* SDU Interval */ + iso_interval_int, /* ISO Interval */ + stream_sync_delay, /* Stream Sync Delay */ + group_sync_delay); /* Group Sync Delay */ + + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_total_size, + sdu_packet_number, + sdu_timestamp, + ref_point, + event_number, + &tx_sdu_frag_buf.sdu_tx); + + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[2]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]); + PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK); + PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK); + PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK); + PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK); + + err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test segmentation (Black Box) */ + /* Valid PDUs */ + /* PDU 0 */ + payload_number = event_number * BN; + seg_hdr[0].sc = 0; + seg_hdr[0].cmplt = 0; + seg_hdr[0].timeoffset = pdu_ref_point - sdu_timestamp; + seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE; + pdu_hdr_loc = 0; + pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE; + sdu_read_loc = 0; + pdu_write_end = sdu_fragment_data_size + pdu_write_loc; + sdu_fragments++; + + ZASSERT_PDU_WRITE_TEST(history[0], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[0], + (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)); + + ZASSERT_PDU_WRITE_TEST(history[1], + pdu_buffer[0], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_end - pdu_write_loc)); + + seg_hdr[0].cmplt = 1; + seg_hdr[0].len += (pdu_write_end - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[2], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[0], + PDU_ISO_SEG_HDR_SIZE); + + /* PDU should not be emitted */ + ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* SDU 1 -------------------------------------------------------------*/ + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + sdu_packet_number++; + event_number += 2; + ref_point += iso_interval_us * 2; + sdu_timestamp += sdu_interval; + testdata_indx = testdata_size; + testdata_size += sdu_fragment_data_size; + + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_total_size, + sdu_packet_number, + sdu_timestamp, + ref_point, + event_number, + &tx_sdu_frag_buf.sdu_tx); + + err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test segmentation (Black Box) */ + /* Valid PDUs */ + /* PDU 10 */ + pdu_hdr_loc = pdu_write_end; + seg_hdr[1].sc = 0; + seg_hdr[1].cmplt = 0; + seg_hdr[1].timeoffset = pdu_ref_point - sdu_timestamp; + seg_hdr[1].len = PDU_ISO_SEG_TIMEOFFSET_SIZE; + pdu_write_loc = pdu_write_end + (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); + pdu_write_end = TEST_TX_PDU_PAYLOAD_MAX; + sdu_read_loc = testdata_indx; + + ZASSERT_PDU_WRITE_TEST(history[3], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[1], + (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)); + + ZASSERT_PDU_WRITE_TEST(history[4], + pdu_buffer[0], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_end - pdu_write_loc)); + + /* PDU should not be allocated */ + + seg_hdr[1].len += (pdu_write_end - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[5], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[1], + PDU_ISO_SEG_HDR_SIZE); + + ZASSERT_PDU_EMIT_TEST(history[0], + &tx_pdu_meta_buf[0].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_end, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* PDU 11 */ + payload_number++; + seg_hdr[2].sc = 1; + seg_hdr[2].cmplt = 0; + seg_hdr[2].timeoffset = 0; + seg_hdr[2].len = 0; + sdu_read_loc += (pdu_write_end - pdu_write_loc); + pdu_hdr_loc = 0; + pdu_write_end = testdata_size - testdata_indx - (pdu_write_end - pdu_write_loc) + + PDU_ISO_SEG_HDR_SIZE; + pdu_write_loc = PDU_ISO_SEG_HDR_SIZE; + sdu_fragments = 1; + + ZASSERT_PDU_WRITE_TEST(history[6], + pdu_buffer[1], + pdu_hdr_loc, + &seg_hdr[2], + PDU_ISO_SEG_HDR_SIZE); + + ZASSERT_PDU_WRITE_TEST(history[7], + pdu_buffer[1], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_end - pdu_write_loc)); + + seg_hdr[2].cmplt = 1; + seg_hdr[2].len += (pdu_write_end - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[8], + pdu_buffer[1], + pdu_hdr_loc, + &seg_hdr[2], + PDU_ISO_SEG_HDR_SIZE); + + /* PDU should not be emitted */ + ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* SDU 2 -------------------------------------------------------------*/ + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + sdu_packet_number++; + event_number += 2; + ref_point += iso_interval_us * 2; + sdu_timestamp += sdu_interval; + testdata_indx = testdata_size; + testdata_size += sdu_fragment_data_size; + + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_total_size, + sdu_packet_number, + sdu_timestamp, + ref_point, + event_number, + &tx_sdu_frag_buf.sdu_tx); + + err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test segmentation (Black Box) */ + /* Valid PDUs */ + /* PDU 11 */ + + ZASSERT_PDU_EMIT_TEST(history[1], + &tx_pdu_meta_buf[1].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_end, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* PDU 12 */ + payload_number++; + pdu_event_number++; + pdu_ref_point += iso_interval_us; + seg_hdr[0].sc = 0; + seg_hdr[0].cmplt = 0; + seg_hdr[0].timeoffset = pdu_ref_point - sdu_timestamp; + seg_hdr[0].len = 3; + sdu_read_loc = testdata_indx; + pdu_hdr_loc = 0; + pdu_write_end = testdata_size - testdata_indx + PDU_ISO_SEG_HDR_SIZE + + PDU_ISO_SEG_TIMEOFFSET_SIZE; + pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE; + sdu_fragments = 1; + + ZASSERT_PDU_WRITE_TEST(history[9], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[0], + (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)); + + ZASSERT_PDU_WRITE_TEST(history[10], + pdu_buffer[0], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_end - pdu_write_loc)); + + seg_hdr[0].cmplt = 1; + seg_hdr[0].len += (pdu_write_end - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[11], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[0], + PDU_ISO_SEG_HDR_SIZE); + + /* PDU should not be emitted */ + ZASSERT_PDU_EMIT_TEST_CALL_COUNT(2); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* Send Event Timeout ----------------------------------------------- */ + isoal_tx_event_prepare(source_hdl, pdu_event_number - 1); + + /* PDU should not be emitted */ + ZASSERT_PDU_EMIT_TEST_CALL_COUNT(2); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* SDU 3 -------------------------------------------------------------*/ + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]); + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]); + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + sdu_packet_number++; + event_number += 2; + ref_point += iso_interval_us * 2; + sdu_timestamp += sdu_interval; + sdu_total_size = sdu_fragment_data_size; + testdata_indx = testdata_size; + testdata_size += sdu_fragment_data_size; + + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_total_size, + sdu_packet_number, + sdu_timestamp, + ref_point, + event_number, + &tx_sdu_frag_buf.sdu_tx); + + err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test segmentation (Black Box) */ + /* Valid PDUs */ + /* PDU 12 */ + ZASSERT_PDU_EMIT_TEST(history[2], + &tx_pdu_meta_buf[0].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_end, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU 13 */ + payload_number++; + + /* Padding PDU */ + ZASSERT_PDU_EMIT_TEST_CALL_COUNT(4); + ZASSERT_PDU_EMIT_TEST(history[3], + &tx_pdu_meta_buf[1].node_tx, + payload_number, + 0, + PDU_BIS_LLID_FRAMED, + 0, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* PDU 14 */ + payload_number++; + pdu_event_number++; + pdu_ref_point += iso_interval_us; + seg_hdr[1].sc = 0; + seg_hdr[1].cmplt = 0; + seg_hdr[1].timeoffset = pdu_ref_point - sdu_timestamp; + seg_hdr[1].len = 3; + sdu_read_loc = testdata_indx; + pdu_hdr_loc = 0; + pdu_write_end = testdata_size - testdata_indx + PDU_ISO_SEG_HDR_SIZE + + PDU_ISO_SEG_TIMEOFFSET_SIZE; + pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE; + sdu_fragments = 1; + + ZASSERT_PDU_WRITE_TEST(history[12], + pdu_buffer[2], + pdu_hdr_loc, + &seg_hdr[1], + PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); + + ZASSERT_PDU_WRITE_TEST(history[13], + pdu_buffer[2], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_end - pdu_write_loc)); + + seg_hdr[1].cmplt = 1; + seg_hdr[1].len += (pdu_write_end - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[14], + pdu_buffer[2], + pdu_hdr_loc, + &seg_hdr[1], + PDU_ISO_SEG_HDR_SIZE); + + /* PDU should not be emitted */ + ZASSERT_PDU_EMIT_TEST_CALL_COUNT(4); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* Send Event Timeout ----------------------------------------------- */ + isoal_tx_event_prepare(source_hdl, pdu_event_number); + + + ZASSERT_PDU_EMIT_TEST(history[4], + &tx_pdu_meta_buf[2].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_end, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU 5 */ + payload_number++; + + /* Padding PDU */ + ZASSERT_PDU_EMIT_TEST(history[5], + &tx_pdu_meta_buf[0].node_tx, + payload_number, + 0, + PDU_BIS_LLID_FRAMED, + 0, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); +} + /** * Test Suite : TX framed EBQ test IAL-CIS-FRA-PER-BV07C * @@ -7173,8 +7657,8 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -7187,7 +7671,7 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) sdu_packet_number = 0; event_number = 0; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; sdu_total_size = 10; testdata_indx = 0; testdata_size = 10; @@ -7350,7 +7834,7 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) event_number++; sdu_packet_number++; sdu_timestamp = sdu_timestamp + sdu_interval; - ref_point = ref_point + (iso_interval_int * CONN_INT_UNIT_US); + ref_point = ref_point + (iso_interval_int * ISO_INT_UNIT_US); sdu_total_size = 20; testdata_indx = testdata_size; testdata_size += 20; From 78f271634db1df8383b6e32e46e750c428e264fc Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Mon, 17 Jul 2023 16:19:46 +0200 Subject: [PATCH 0293/1623] [nrf fromtree] test: bluetooth: controller: Updated ISO-AL tests to cover endianness Changes: -- Changed RX tests and one TX test to cover endianness of the framed segment header fields -- Updated RX debug PDU print to include framed segment details Signed-off-by: Nirosharn Amarasinghe (cherry picked from commit 05ce650c856ec98ccbdaff7a72ccfe6ab33ad405) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 11a12a55149a39f01215593345448052bf812e4d) --- .../ctrl_isoal/src/isoal_test_common.c | 12 ++--- .../ctrl_isoal/src/isoal_test_debug.c | 44 ++++++++++++++++++- tests/bluetooth/ctrl_isoal/src/main.c | 2 + .../ctrl_isoal/src/sub_sets/isoal_test_tx.c | 36 ++++++++------- 4 files changed, 70 insertions(+), 24 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/src/isoal_test_common.c b/tests/bluetooth/ctrl_isoal/src/isoal_test_common.c index a20ba5fd084..35947656336 100644 --- a/tests/bluetooth/ctrl_isoal/src/isoal_test_common.c +++ b/tests/bluetooth/ctrl_isoal/src/isoal_test_common.c @@ -23,6 +23,7 @@ #include #include +#include #include "util/memq.h" @@ -109,7 +110,7 @@ void isoal_test_create_unframed_pdu(uint8_t llid, uint16_t isoal_test_insert_segment(bool sc, bool cmplt, uint32_t time_offset, uint8_t *dataptr, uint8_t length, struct isoal_pdu_rx *pdu_meta) { - struct pdu_iso_sdu_sh seg_hdr; + uint8_t seg_hdr[PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE]; uint16_t pdu_payload_size; uint8_t hdr_write_size; uint16_t pdu_data_loc; @@ -122,12 +123,13 @@ uint16_t isoal_test_insert_segment(bool sc, bool cmplt, uint32_t time_offset, ui zassert_true(pdu_payload_size <= TEST_RX_PDU_PAYLOAD_MAX, "pdu_payload_size (%d)", pdu_payload_size); - seg_hdr.sc = sc; - seg_hdr.cmplt = cmplt; - seg_hdr.len = length + (sc ? 0 : PDU_ISO_SEG_TIMEOFFSET_SIZE); + /* Write header independent of endian dependent structures */ + WRITE_BIT(seg_hdr[0], 0, sc); /* sc */ + WRITE_BIT(seg_hdr[0], 1, cmplt); /* cmplt */ + seg_hdr[1] = length + (sc ? 0 : PDU_ISO_SEG_TIMEOFFSET_SIZE); if (!sc) { - seg_hdr.timeoffset = time_offset; + sys_put_le24(time_offset, &seg_hdr[PDU_ISO_SEG_HDR_SIZE]); } memcpy(&pdu_meta->pdu->payload[pdu_meta->pdu->len], &seg_hdr, hdr_write_size); diff --git a/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c b/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c index 464d2586598..734af1ad7c0 100644 --- a/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c +++ b/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c @@ -52,6 +52,12 @@ void isoal_test_debug_print_rx_pdu(struct isoal_pdu_rx *pdu_meta) { zassert_not_null(pdu_meta, ""); + struct pdu_iso *pdu; + uint8_t seg_length; + + pdu = pdu_meta->pdu; + seg_length = 0; + PRINT("\n"); PRINT("PDU %04u (%10u) | %12s [%10s] %03u: ", (uint32_t) pdu_meta->meta->payload_number, @@ -60,8 +66,42 @@ void isoal_test_debug_print_rx_pdu(struct isoal_pdu_rx *pdu_meta) DU_ERR_TO_STR(pdu_meta->meta->status), pdu_meta->pdu->len); - for (int i = 0; i < pdu_meta->pdu->len; i++) { - PRINT("%02x ", pdu_meta->pdu->payload[i]); + for (uint8_t i = 0U; i < pdu->len; i++) { + if (seg_length == 0U && pdu->ll_id == PDU_BIS_LLID_FRAMED) { + seg_length = pdu->payload[i + 1U]; + PRINT("[%s %s %03u]", + pdu->payload[i] & BIT(0) ? "C" : "S", + pdu->payload[i] & BIT(1) ? "C" : "-", + pdu->payload[i + 1U]); + if ((pdu->payload[i] & BIT(0)) == 0U) { + PRINT("(%8uus)", + ((uint32_t)pdu->payload[i + 2U] + + ((uint32_t)pdu->payload[i + 3U] << 8) + + ((uint32_t)pdu->payload[i + 4U] << 16))); + } + + PRINT(" / "); + PRINT("[%02x %02x]", + pdu->payload[i], + pdu->payload[i + 1U]); + if ((pdu->payload[i] & BIT(0)) == 0U) { + PRINT("(%02x %02x %02x)", + (uint32_t)pdu->payload[i + 4U], + (uint32_t)pdu->payload[i + 3U], + (uint32_t)pdu->payload[i + 2U]); + } + + PRINT(" : "); + seg_length -= pdu->payload[i] & BIT(0) ? 0 : PDU_ISO_SEG_TIMEOFFSET_SIZE; + i += PDU_ISO_SEG_HDR_SIZE + + (pdu->payload[i] & BIT(0) ? 0 : PDU_ISO_SEG_TIMEOFFSET_SIZE); + } + + PRINT("%02x ", pdu->payload[i]); + seg_length--; + if (seg_length == 0 && pdu->ll_id == PDU_BIS_LLID_FRAMED) { + PRINT("\n%44s", ""); + } } PRINT("\n"); PRINT("\n"); diff --git a/tests/bluetooth/ctrl_isoal/src/main.c b/tests/bluetooth/ctrl_isoal/src/main.c index 92ca21ff199..08175eab153 100644 --- a/tests/bluetooth/ctrl_isoal/src/main.c +++ b/tests/bluetooth/ctrl_isoal/src/main.c @@ -18,6 +18,8 @@ #include #include +#include + #include DEFINE_FFF_GLOBALS; diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c index dc21c9b5d61..3f57d8bccbc 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c @@ -3757,7 +3757,8 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_bufSize) * Test Suite : TX framed SDU segmentation * * Tests segmentation of a single SDU contained in a single fragment - * into three PDUs where Max PDU is less than the PDU buffer size + * into three PDUs where Max PDU is less than the PDU buffer size. Also tests + * endianness of the segment header. */ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) { @@ -3854,10 +3855,11 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) /* Test segmentation (Black Box) */ /* Valid PDUs */ /* PDU 1 */ - seg_hdr[0].sc = 0; - seg_hdr[0].cmplt = 0; - seg_hdr[0].timeoffset = ref_point - sdu_timestamp; - seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE; + /* Test endianness */ + WRITE_BIT(((uint8_t *)&seg_hdr[0])[0], 0, 0); /* sc */ + WRITE_BIT(((uint8_t *)&seg_hdr[0])[0], 1, 0); /* cmplt */ + sys_put_le24(ref_point - sdu_timestamp, (uint8_t *)(&seg_hdr[0]) + PDU_ISO_SEG_HDR_SIZE); + ((uint8_t *)(&seg_hdr[0]))[1] = PDU_ISO_SEG_TIMEOFFSET_SIZE; /* len */ pdu_hdr_loc = 0; pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE; sdu_read_loc = 0; @@ -3877,7 +3879,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) (pdu_write_size - pdu_write_loc)); seg_hdr[1] = seg_hdr[0]; - seg_hdr[1].len += (pdu_write_size - pdu_write_loc); + ((uint8_t *)(&seg_hdr[1]))[1] += (pdu_write_size - pdu_write_loc); ZASSERT_PDU_WRITE_TEST(history[2], pdu_buffer, @@ -3895,10 +3897,10 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) /* PDU 2 */ payload_number++; - seg_hdr[2].sc = 1; - seg_hdr[2].cmplt = 0; - seg_hdr[2].timeoffset = 0; - seg_hdr[2].len = 0; + WRITE_BIT(((uint8_t *)&seg_hdr[2])[0], 0, 1); /* sc */ + WRITE_BIT(((uint8_t *)&seg_hdr[2])[0], 1, 0); /* cmplt */ + sys_put_le24(0, (uint8_t *)(&seg_hdr[2]) + PDU_ISO_SEG_HDR_SIZE); + ((uint8_t *)(&seg_hdr[2]))[1] = 0; /* len */ pdu_hdr_loc = 0; sdu_read_loc += (pdu_write_size - pdu_write_loc); pdu_write_loc = PDU_ISO_SEG_HDR_SIZE; @@ -3918,7 +3920,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) (pdu_write_size - pdu_write_loc)); seg_hdr[3] = seg_hdr[2]; - seg_hdr[3].len += (pdu_write_size - pdu_write_loc); + ((uint8_t *)(&seg_hdr[3]))[1] += (pdu_write_size - pdu_write_loc); /* len */ ZASSERT_PDU_WRITE_TEST(history[5], pdu_buffer, @@ -3936,10 +3938,10 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) /* PDU 3 */ payload_number++; - seg_hdr[4].sc = 1; - seg_hdr[4].cmplt = 0; - seg_hdr[4].timeoffset = 0; - seg_hdr[4].len = 0; + WRITE_BIT(((uint8_t *)&seg_hdr[4])[0], 0, 1); /* sc */ + WRITE_BIT(((uint8_t *)&seg_hdr[4])[0], 1, 0); /* cmplt */ + sys_put_le24(0, (uint8_t *)(&seg_hdr[4]) + PDU_ISO_SEG_HDR_SIZE); + ((uint8_t *)(&seg_hdr[4]))[1] = 0; /* len */ pdu_hdr_loc = 0; sdu_read_loc += (pdu_write_size - pdu_write_loc); pdu_write_loc = PDU_ISO_SEG_HDR_SIZE; @@ -3962,8 +3964,8 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) (pdu_write_size - pdu_write_loc)); seg_hdr[5] = seg_hdr[4]; - seg_hdr[5].cmplt = 1; - seg_hdr[5].len += (pdu_write_size - pdu_write_loc); + WRITE_BIT(((uint8_t *)&seg_hdr[5])[0], 1, 1); /* cmplt */ + ((uint8_t *)(&seg_hdr[5]))[1] += (pdu_write_size - pdu_write_loc); /* len */ ZASSERT_PDU_WRITE_TEST(history[8], pdu_buffer, From cd59d4f291540089700dc1c04e7dd82f8de345a5 Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Wed, 19 Jul 2023 12:20:42 +0200 Subject: [PATCH 0294/1623] [nrf fromtree] tests: bluetooth: controller: ISO-AL selection of TX time stamps Unit tests for TX time stamp related decisions. Signed-off-by: Nirosharn Amarasinghe (cherry picked from commit 2260b651b65be683fc1e82aafeef166d97dde64a) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit e95ce690ab6b5789f47871e98e549026143790d2) --- .../ctrl_isoal/src/isoal_test_debug.c | 1 + tests/bluetooth/ctrl_isoal/src/main.c | 2 +- .../ctrl_isoal/src/sub_sets/isoal_test_tx.c | 540 +++++++++++++++++- 3 files changed, 540 insertions(+), 3 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c b/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c index 734af1ad7c0..084677cf462 100644 --- a/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c +++ b/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c @@ -233,6 +233,7 @@ void isoal_test_debug_print_tx_sdu(struct isoal_sdu_tx *tx_sdu) PRINT("%02x ", buf[i]); } PRINT("\n"); + PRINT("Cntr TS. <%10u>\n", tx_sdu->cntr_time_stamp); PRINT(" Ref. <%10u>\n", tx_sdu->grp_ref_point); PRINT(" Event <%10u>\n", (uint32_t)tx_sdu->target_event); PRINT("\n"); diff --git a/tests/bluetooth/ctrl_isoal/src/main.c b/tests/bluetooth/ctrl_isoal/src/main.c index 08175eab153..8cbd36c509a 100644 --- a/tests/bluetooth/ctrl_isoal/src/main.c +++ b/tests/bluetooth/ctrl_isoal/src/main.c @@ -37,7 +37,7 @@ DEFINE_FFF_GLOBALS; ZTEST_SUITE(test_rx_basics, NULL, NULL, isoal_test_rx_common_before, NULL, NULL); ZTEST_SUITE(test_rx_unframed, NULL, NULL, isoal_test_rx_common_before, NULL, NULL); -ZTEST_SUITE(test_rx_framed, NULL, NULL, NULL, isoal_test_rx_common_before, NULL); +ZTEST_SUITE(test_rx_framed, NULL, NULL, isoal_test_rx_common_before, NULL, NULL); ZTEST_SUITE(test_tx_basics, NULL, NULL, isoal_test_tx_common_before, NULL, NULL); ZTEST_SUITE(test_tx_unframed, NULL, NULL, isoal_test_tx_common_before, NULL, NULL); diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c index 3f57d8bccbc..c9a6fe67637 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c @@ -195,14 +195,14 @@ static isoal_status_t custom_source_pdu_write_test(struct isoal_pdu_buffer *pdu_ _consume_len, \ source_pdu_write_test_fake.arg3_##_typ); \ check_next_custom_source_pdu_write_test_sdu_payload((const uint8_t *)_sdu_payload, \ - _consume_len, __LINE__); + _consume_len, __LINE__) #define ZASSERT_PDU_WRITE_TEST_CALL_COUNT(_expected) \ zassert_equal(_expected, \ source_pdu_write_test_fake.call_count, \ "Expected %u, got %u", \ _expected, \ - source_pdu_write_test_fake.call_count); + source_pdu_write_test_fake.call_count) /*------------------ PDU Emit Callback --------------------------------------*/ /** @@ -480,6 +480,7 @@ static void isoal_test_create_sdu_fagment(uint8_t sdu_state, uint16_t sdu_total_length, uint16_t packet_number, uint32_t timestamp, + uint32_t cntr_timestamp, uint32_t ref_point, uint64_t target_event, struct isoal_sdu_tx *sdu_tx) @@ -488,6 +489,7 @@ static void isoal_test_create_sdu_fagment(uint8_t sdu_state, sdu_tx->packet_sn = packet_number; sdu_tx->iso_sdu_length = sdu_total_length; sdu_tx->time_stamp = timestamp; + sdu_tx->cntr_time_stamp = cntr_timestamp; sdu_tx->grp_ref_point = ref_point; sdu_tx->target_event = target_event; memcpy(sdu_tx->dbuf, dataptr, length); @@ -792,6 +794,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_maxPDU) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -920,6 +923,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_bufSize) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1035,6 +1039,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_3_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1195,6 +1200,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1241,6 +1247,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1284,6 +1291,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1403,6 +1411,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1451,6 +1460,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1517,6 +1527,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1734,6 +1745,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_1_frag_2_pdu_ts_wrap1) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1787,6 +1799,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_1_frag_2_pdu_ts_wrap1) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1916,6 +1929,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1968,6 +1982,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2030,6 +2045,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2085,6 +2101,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2128,6 +2145,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2190,6 +2208,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2314,6 +2333,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2370,6 +2390,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2432,6 +2453,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2527,6 +2549,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2569,6 +2592,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2631,6 +2655,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2792,6 +2817,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_zero_sdu_1_frag_1_pdu_maxPDU_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2952,6 +2978,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_alloc_err) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3069,6 +3096,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_emit_err) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3199,6 +3227,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3269,6 +3298,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3335,6 +3365,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3404,6 +3435,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3451,6 +3483,470 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) zassert_equal(tx_sync_offset, tx_sync_offset_expected, "%u != %u", tx_sync_seq, 0); } +/** + * Test Suite : TX framed SDU segmentation + * + * Tests framed event selection + */ +#define RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT() \ + out_sdus_skipped = isoal_tx_framed_find_correct_tx_event(source, \ + &tx_sdu_frag_buf.sdu_tx, \ + &out_payload_number, \ + &out_ref_point, \ + &out_time_offset); \ + \ + zassert_equal(out_payload_number, expect_payload_number, "%llu != %llu", \ + out_payload_number, expect_payload_number); \ + zassert_equal(out_ref_point, expect_ref_point, "%u != %u", \ + out_ref_point, expect_ref_point); \ + zassert_equal(out_time_offset, expect_time_offset, "%u != %u", \ + out_time_offset, expect_time_offset); \ + zassert_equal(out_sdus_skipped, expect_sdus_skipped, "%u .!= %u", \ + out_sdus_skipped, expect_sdus_skipped) + +ZTEST(test_tx_framed, test_tx_framed_find_correct_tx_event) +{ + const uint8_t number_of_pdus = 1; + const uint8_t testdata_size_max = MAX_FRAMED_PDU_PAYLOAD(number_of_pdus); + + struct tx_sdu_frag_buffer tx_sdu_frag_buf; + struct isoal_source_session *session; + uint8_t testdata[testdata_size_max]; + isoal_sdu_len_t in_sdu_total_size; + isoal_source_handle_t source_hdl; + struct isoal_pdu_production *pp; + uint64_t expect_payload_number; + struct isoal_source *source; + uint64_t out_payload_number; + uint32_t expect_time_offset; + uint8_t expect_sdus_skipped; + uint32_t expected_timestamp; + uint32_t stream_sync_delay; + uint32_t in_cntr_timestamp; + uint32_t group_sync_delay; + uint64_t in_sdu_packet_sn; + uint32_t in_sdu_timestamp; + uint32_t expect_ref_point; + uint64_t in_target_event; + uint32_t iso_interval_us; + uint8_t iso_interval_int; + uint32_t out_time_offset; + uint8_t out_sdus_skipped; + uint16_t testdata_indx; + uint16_t testdata_size; + uint32_t out_ref_point; + uint32_t sdu_interval; + uint32_t in_ref_point; + uint8_t max_octets; + uint8_t role; + uint8_t BN; + uint8_t FT; + + /* Settings */ + role = BT_CONN_ROLE_PERIPHERAL; + iso_interval_int = 1; + iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = iso_interval_us + 50; + max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; + BN = 2; + FT = 1; + stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + + init_test_data_buffer(testdata, testdata_size_max); + + /* Create source */ + source_hdl = basic_tx_test_setup(0xADAD, /* Handle */ + role, /* Role */ + true, /* Framed */ + BN, /* BN */ + FT, /* FT */ + max_octets, /* max_octets */ + sdu_interval, /* SDU Interval */ + iso_interval_int, /* ISO Interval */ + stream_sync_delay, /* Stream Sync Delay */ + group_sync_delay); /* Group Sync Delay */ + + source = &isoal_global.source_state[source_hdl]; + session = &source->session; + pp = &source->pdu_production; + + in_sdu_total_size = testdata_size_max; + testdata_indx = 0; + testdata_size = testdata_size_max; + + /* Test : Selection of event for first SDU where + * -- Last SDU packet number is uninitialized + * -- Last SDU time stamp is uninitialized + * -- Payload number is uninitialized + * -- Target event and reference point are one event ahead + * -- Time stamp is valid + * -- Time stamp indicates that target event is feasible + * Expected: + * -- Target event is used for transmission and calculations are based + * on that + * -- Time offset is based on the SDUs time stamp + */ + in_sdu_packet_sn = 2000; + in_target_event = 2000; + in_sdu_timestamp = 9249; + in_cntr_timestamp = in_sdu_timestamp + 200; + in_ref_point = in_sdu_timestamp + iso_interval_us - 50; + + pp->initialized = 0U; + session->tx_time_stamp = 0; + session->tx_time_offset = 0; + session->last_input_sn = 0; + session->last_input_time_stamp = 0; + pp->payload_number = 0; + + expect_sdus_skipped = 0; + expect_payload_number = in_target_event * BN; + expect_ref_point = in_ref_point; + expected_timestamp = in_sdu_timestamp; + expect_time_offset = expect_ref_point - expected_timestamp; + + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + in_sdu_total_size, + in_sdu_packet_sn, + in_sdu_timestamp, + in_cntr_timestamp, + in_ref_point, + in_target_event, + &tx_sdu_frag_buf.sdu_tx); + + RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); + + /* Test : Selection of event for first SDU where + * -- Last SDU packet number is uninitialized + * -- Last SDU time stamp is uninitialized + * -- Payload number ahead of target event + * -- Target event and reference point are one event behind + * current payload + * -- Time stamp is valid + * -- Time stamp indicates that target event is feasible + * Expected: + * -- Target event + 1 is selected based on the payload being ahead and + * calculations are based on that reference + * -- Time offset is based on the SDUs time stamp + */ + in_sdu_packet_sn = 2000; + in_target_event = 2000; + in_sdu_timestamp = 9249; + in_cntr_timestamp = in_sdu_timestamp + 200; + in_ref_point = in_sdu_timestamp + iso_interval_us - 50; + + pp->initialized = 0U; + session->tx_time_stamp = 0; + session->tx_time_offset = 0; + session->last_input_sn = 0; + session->last_input_time_stamp = 0; + pp->payload_number = (in_target_event + 1) * BN; + + expect_sdus_skipped = 0; + expect_payload_number = (in_target_event + 1) * BN; + expect_ref_point = in_ref_point + iso_interval_us; + expected_timestamp = in_sdu_timestamp; + expect_time_offset = expect_ref_point - expected_timestamp; + + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + in_sdu_total_size, + in_sdu_packet_sn, + in_sdu_timestamp, + in_cntr_timestamp, + in_ref_point, + in_target_event, + &tx_sdu_frag_buf.sdu_tx); + + RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); + + /* Test : Selection of event for first SDU where + * -- Last SDU packet number is uninitialized + * -- Last SDU time stamp is uninitialized + * -- Payload number ahead of target event + * -- Target event and reference point are one event behind + * current payload + * -- Time stamp is invalid + * -- Controller time stamp indicates that target event is + * feasible + * Expected: + * -- Target event + 1 is selected based on the payload being ahead and + * calculations are based on that reference + * -- Time offset is based on the controller's capture time + */ + in_sdu_packet_sn = 2000; + in_target_event = 2000; + in_sdu_timestamp = 0; + in_cntr_timestamp = 9249 + 200; + in_ref_point = in_cntr_timestamp + iso_interval_us - 50; + + pp->initialized = 0U; + session->tx_time_stamp = 0; + session->tx_time_offset = 0; + session->last_input_sn = 0; + session->last_input_time_stamp = 0; + pp->payload_number = (in_target_event + 1) * BN; + + expect_sdus_skipped = 0; + expect_payload_number = (in_target_event + 1) * BN; + expect_ref_point = in_ref_point + iso_interval_us; + expected_timestamp = in_cntr_timestamp; + expect_time_offset = expect_ref_point - expected_timestamp; + + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + in_sdu_total_size, + in_sdu_packet_sn, + in_sdu_timestamp, + in_cntr_timestamp, + in_ref_point, + in_target_event, + &tx_sdu_frag_buf.sdu_tx); + + RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); + + /* Test : Selection of event for a subsequent SDU where + * -- Last SDU packet number is in sequence + * -- Last SDU time stamp is in sequence + * -- Payload number is in sequence + * -- Target event and reference point are one event ahead of + * current payload + * -- Time stamp is valid + * -- Time stamp indicates that target event is feasible + * Expected: + * -- Target event is selected based on the time stamp and calculations + * are based on that reference + * -- Time offset is based on the SDUs time stamp + */ + in_sdu_packet_sn = 2000; + in_target_event = 2000; + in_sdu_timestamp = 9249; + in_cntr_timestamp = 9249 + 200; + in_ref_point = in_sdu_timestamp + iso_interval_us - 50; + + pp->initialized = 1U; + session->tx_time_stamp = 0; + session->tx_time_offset = 0; + session->last_input_sn = in_sdu_packet_sn - 1; + session->last_input_time_stamp = in_sdu_timestamp - sdu_interval; + pp->payload_number = (in_target_event - 1) * BN; + + expect_sdus_skipped = 0; + expect_payload_number = in_target_event * BN; + expect_ref_point = in_ref_point; + expected_timestamp = in_sdu_timestamp; + expect_time_offset = expect_ref_point - expected_timestamp; + + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + in_sdu_total_size, + in_sdu_packet_sn, + in_sdu_timestamp, + in_cntr_timestamp, + in_ref_point, + in_target_event, + &tx_sdu_frag_buf.sdu_tx); + + RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); + + /* Test : Selection of event for a subsequent SDU where + * -- Last SDU packet number is not in sequence + * -- Last SDU time stamp is not in sequence + * -- Payload number is not in sequence + * -- Target event and reference point are two events ahead + * -- Time stamp is valid but at the border of the range + * -- Time stamp indicates that target event - 1 is feasible + * Expected: + * -- Target event - 1 is selected based on the time stamp and + * calculations are based on that reference + * -- Time offset is based on the SDUs time stamp + */ + in_sdu_packet_sn = 2000; + in_target_event = 2001; + in_sdu_timestamp = 9249; + in_cntr_timestamp = 9249 + sdu_interval + iso_interval_us; + in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50; + + pp->initialized = 1U; + session->tx_time_stamp = 0; + session->tx_time_offset = 0; + session->last_input_sn = in_sdu_packet_sn - 3; + session->last_input_time_stamp = in_sdu_timestamp - (sdu_interval * 2); + pp->payload_number = (in_target_event - 2) * BN; + + expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1; + expect_payload_number = (in_target_event - 1) * BN; + expect_ref_point = in_ref_point - iso_interval_us; + expected_timestamp = in_sdu_timestamp; + expect_time_offset = expect_ref_point - expected_timestamp; + + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + in_sdu_total_size, + in_sdu_packet_sn, + in_sdu_timestamp, + in_cntr_timestamp, + in_ref_point, + in_target_event, + &tx_sdu_frag_buf.sdu_tx); + + RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); + + /* Test : Selection of event for a subsequent SDU where + * -- Last SDU packet number is not in sequence + * -- Last SDU time stamp is not in sequence + * -- Payload number is not in sequence + * -- Target event and reference point are two events ahead + * -- Time stamp is invalid + * Expected: + * -- Target event is selected based on the time stamp calculated + * from the difference between time stamps and calculations are based + * on that reference + * -- Time offset is based on the SDUs time stamp + */ + in_sdu_packet_sn = 2000; + in_target_event = 2001; + in_sdu_timestamp = 9249; + in_cntr_timestamp = 9249 + sdu_interval + iso_interval_us + 1; + in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50; + + pp->initialized = 1U; + session->tx_time_stamp = in_ref_point - iso_interval_us; + session->tx_time_offset = session->tx_time_stamp - + (in_sdu_timestamp - sdu_interval); + session->last_input_sn = in_sdu_packet_sn - 3; + session->last_input_time_stamp = in_sdu_timestamp - (sdu_interval * 2); + pp->payload_number = (in_target_event - 2) * BN; + + expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1; + expect_payload_number = in_target_event * BN; + expect_ref_point = in_ref_point; + expected_timestamp = session->tx_time_stamp - session->tx_time_offset + + (in_sdu_timestamp - session->last_input_time_stamp); + expect_time_offset = expect_ref_point - expected_timestamp; + + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + in_sdu_total_size, + in_sdu_packet_sn, + in_sdu_timestamp, + in_cntr_timestamp, + in_ref_point, + in_target_event, + &tx_sdu_frag_buf.sdu_tx); + + RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); + + /* Test : Selection of event for a subsequent SDU where + * -- Last SDU packet number is not in sequence + * -- Last SDU time stamp has been projected as part of a + * burst + * -- Payload number is not in sequence + * -- Target event and reference point are two events ahead + * -- Time stamp is invalid + * -- Time stamp delta is invalid + * Expected: + * -- Target event + 1 is selected based on the time stamp calculated + * from the difference in packet sn and calculations are based + * on that reference + * -- Time offset is based on the SDUs time stamp + */ + in_sdu_packet_sn = 2000; + in_target_event = 2001; + in_sdu_timestamp = 9249; + in_cntr_timestamp = 9249 + sdu_interval + iso_interval_us + 1; + in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50; + + pp->initialized = 1U; + session->tx_time_stamp = in_ref_point - iso_interval_us; + session->tx_time_offset = session->tx_time_stamp - + (in_sdu_timestamp + sdu_interval); + session->last_input_sn = in_sdu_packet_sn - 1; + session->last_input_time_stamp = in_sdu_timestamp + (sdu_interval * 2); + pp->payload_number = (in_target_event - 2) * BN; + + expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1; + expect_payload_number = (in_target_event + 1) * BN; + expect_ref_point = in_ref_point + iso_interval_us; + expected_timestamp = session->tx_time_stamp - session->tx_time_offset + sdu_interval; + expect_time_offset = expect_ref_point - expected_timestamp; + + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + in_sdu_total_size, + in_sdu_packet_sn, + in_sdu_timestamp, + in_cntr_timestamp, + in_ref_point, + in_target_event, + &tx_sdu_frag_buf.sdu_tx); + + RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); + + /* Test : Selection of event for a subsequent SDU where + * -- Last SDU packet number is in sequence + * -- Last SDU time stamp has been projected as part of a + * burst + * -- Payload number is ahead of selected event + * -- Target event and reference point are two events ahead + * -- Time stamp is valid + * -- Time stamp indicates that target event - 1 is feasible + * Expected: + * -- Target event -1 is selected based on the time stamp and + * calculations are based on that reference + * -- Payload number continues from last + * -- Time offset is based on the SDUs time stamp + */ + in_sdu_packet_sn = 2000; + in_target_event = 2001; + in_sdu_timestamp = 9249; + in_cntr_timestamp = 9249; + in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50; + + pp->initialized = 1U; + session->tx_time_stamp = 0; + session->tx_time_offset = 0; + session->last_input_sn = in_sdu_packet_sn - 1; + session->last_input_time_stamp = in_sdu_timestamp - sdu_interval; + pp->payload_number = ((in_target_event - 1) * BN) + 1; + + expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1; + expect_payload_number = pp->payload_number; + expect_ref_point = in_ref_point - iso_interval_us; + expected_timestamp = in_sdu_timestamp; + expect_time_offset = expect_ref_point - expected_timestamp; + + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + in_sdu_total_size, + in_sdu_packet_sn, + in_sdu_timestamp, + in_cntr_timestamp, + in_ref_point, + in_target_event, + &tx_sdu_frag_buf.sdu_tx); + + RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); +} + /** * Test Suite : TX framed SDU segmentation * @@ -3537,6 +4033,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_maxPDU) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3692,6 +4189,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_bufSize) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3836,6 +4334,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4073,6 +4572,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4144,6 +4644,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4198,6 +4699,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4335,6 +4837,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4408,6 +4911,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4500,6 +5004,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4637,6 +5142,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4712,6 +5218,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4804,6 +5311,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4870,6 +5378,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4936,6 +5445,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5027,6 +5537,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5164,6 +5675,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5236,6 +5748,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5327,6 +5840,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5390,6 +5904,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5451,6 +5966,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5541,6 +6057,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5711,6 +6228,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5791,6 +6309,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5940,6 +6459,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_refPoint3) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6096,6 +6616,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_ts_wrap1) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6176,6 +6697,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_ts_wrap1) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6316,6 +6838,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_maxPDU) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6467,6 +6990,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6647,6 +7171,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_alloc_err) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6775,6 +7300,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_emit_err) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6921,6 +7447,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6997,6 +7524,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7071,6 +7599,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7234,6 +7763,7 @@ ZTEST(test_tx_framed, test_tx_framed_event_utilization_1) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7309,6 +7839,7 @@ ZTEST(test_tx_framed, test_tx_framed_event_utilization_1) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7418,6 +7949,7 @@ ZTEST(test_tx_framed, test_tx_framed_event_utilization_1) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7510,6 +8042,7 @@ ZTEST(test_tx_framed, test_tx_framed_event_utilization_1) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7696,6 +8229,7 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7767,6 +8301,7 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7847,6 +8382,7 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) sdu_total_size, sdu_packet_number, sdu_timestamp, + sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); From d1b4bbfe99dd4cf897c9d72d830ea99a894bc48c Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Mon, 14 Aug 2023 12:36:14 +0200 Subject: [PATCH 0295/1623] [nrf fromtree] tests: bluetooth: controller: Updated ISO-AL tests for length of err PDU Updated unit tests to match changes in ISO-AL that disregard the length of a received PDU with errors. Signed-off-by: Nirosharn Amarasinghe (cherry picked from commit 770f435e6881ea667466744c22d2ee9ca6f715ec) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit c8610f518ed2ea44c275bca1b0c21bd6c3ac7cc1) --- .../ctrl_isoal/src/sub_sets/isoal_test_rx.c | 115 ++++++++---------- 1 file changed, 51 insertions(+), 64 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c index 5a3c60e0854..fdb86af1f5c 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c @@ -60,19 +60,19 @@ static isoal_status_t custom_sink_sdu_alloc_test(const struct isoal_sink *sink_c #define ZASSERT_ISOAL_SDU_ALLOC_TEST(_typ, _sink, _pdu) \ zassert_equal_ptr(_sink, \ sink_sdu_alloc_test_fake.arg0_##_typ, \ - "\t\t%p != %p", \ + "\t\tExpected alloc sink at %p, got %p.", \ _sink, \ sink_sdu_alloc_test_fake.arg0_##_typ); \ zassert_equal_ptr(_pdu, \ sink_sdu_alloc_test_fake.arg1_##_typ, \ - "\t\t%p != %p", \ + "\t\tExpected alloc PDU buffer at %p, got %p.", \ _pdu, \ sink_sdu_alloc_test_fake.arg1_##_typ) #define ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(_expected) \ zassert_equal(_expected, \ sink_sdu_alloc_test_fake.call_count, \ - "Expected %u got %u", \ + "Expected alloc called %u times, actual %u.", \ _expected, \ sink_sdu_alloc_test_fake.call_count) @@ -125,59 +125,59 @@ static isoal_status_t custom_sink_sdu_emit_test(const struct isoal_sink *sink_ct _sdu_status) \ zassert_equal_ptr(_sink, \ sink_sdu_emit_test_fake.arg0_##_typ, \ - "\t\t%p != %p", \ + "\t\tExpected sink at %p, got %p.", \ _sink, \ sink_sdu_emit_test_fake.arg0_##_typ); \ zassert_equal(_state, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_state, \ - "\t\t%d != %d", \ - _state, \ - sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_state); \ + "\t\tExpected SDU state '%s', got '%s'.", \ + STATE_TO_STR(_state), \ + STATE_TO_STR(sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_state)); \ zassert_equal(_frag_sz, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_frag_size, \ - "\t\t%d != %d", \ + "\t\tExpected SDU frag of size %u, got %u.", \ _frag_sz, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_frag_size); \ zassert_equal(_frag_status, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.status, \ - "\t\t%d != %d", \ - _frag_status, \ - sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.status); \ + "\t\tExpected SDU with status '%s', got '%s'.", \ + DU_ERR_TO_STR(_frag_status), \ + DU_ERR_TO_STR(sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.status)); \ zassert_equal(_timestamp, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.timestamp, \ - "\t\t%d != %d", \ + "\t\tExpected SDU with timestamp %u, got %u.", \ _timestamp, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.timestamp); \ zassert_equal(_sn, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.sn, \ - "\t\t%d != %d", \ + "\t\tExpected SDU with sequence number %u, got %u.", \ _sn, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.sn); \ - zassert_equal(_dbuf, \ - sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.dbuf, \ - "\t\t%p != %p", \ - _dbuf, \ - sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.dbuf); \ + zassert_equal_ptr(_dbuf, \ + sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.dbuf, \ + "\t\tExpected SDU data buffer at %p, got %p.", \ + _dbuf, \ + sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.dbuf); \ zassert_equal(_dbuf_sz, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.size, \ - "\t\t%d != %d", \ + "\t\tExpected SDU data buffer of size %u, got %u.", \ _dbuf_sz, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.size); \ zassert_equal(_total_sz, \ sink_sdu_emit_test_handler_fake.arg2_##_typ.total_sdu_size, \ - "\t\t%d != %d", \ + "\t\tExpected total size of SDU %u,got %u.", \ _total_sz, \ sink_sdu_emit_test_handler_fake.arg2_##_typ.total_sdu_size); \ zassert_equal(_sdu_status, \ sink_sdu_emit_test_handler_fake.arg2_##_typ.collated_status, \ - "\t\t%d != %d", \ - _sdu_status, \ - sink_sdu_emit_test_handler_fake.arg2_##_typ.collated_status) + "\t\tExpected SDU with status '%s', got '%s'.", \ + DU_ERR_TO_STR(_sdu_status), \ + DU_ERR_TO_STR(sink_sdu_emit_test_handler_fake.arg2_##_typ.collated_status)) #define ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(_expected) \ zassert_equal(_expected, \ sink_sdu_emit_test_fake.call_count, \ - "Expected %u got %u", \ + "Expected emit called %u times, actual %u.", \ _expected, \ sink_sdu_emit_test_fake.call_count) @@ -212,24 +212,24 @@ custom_sink_sdu_write_test(void *dbuf, const uint8_t *pdu_payload, const size_t #define ZASSERT_ISOAL_SDU_WRITE_TEST(_typ, _frag_buf, _payload_buf, _length) \ zassert_equal_ptr(_frag_buf, \ sink_sdu_write_test_fake.arg0_##_typ, \ - "\t\t%p != %p", \ + "\t\tExpected write buffer at %p, got %p.", \ _frag_buf, \ sink_sdu_write_test_fake.arg0_##_typ); \ zassert_equal_ptr(_payload_buf, \ sink_sdu_write_test_fake.arg1_##_typ, \ - "\t\t%p != %p", \ + "\t\tExpected write source at %p, got %p.", \ _payload_buf, \ sink_sdu_write_test_fake.arg1_##_typ); \ zassert_equal(_length, \ sink_sdu_write_test_fake.arg2_##_typ, \ - "\t\t%d != %d", \ + "\t\tExpected write length of %u, got %u.", \ _length, \ sink_sdu_write_test_fake.arg2_##_typ) #define ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(_expected) \ zassert_equal(_expected, \ sink_sdu_write_test_fake.call_count, \ - "Expected %u got %u", \ + "Expected write called %u times, actual %u.", \ _expected, \ sink_sdu_write_test_fake.call_count) @@ -2767,7 +2767,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err) seqn = 0; testdata_indx = 0; testdata_size = 13; - sdu_size = 13; + sdu_size = 0; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); @@ -2804,11 +2804,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err) &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ - /* SDU payload should be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST(val, - &rx_sdu_frag_buf, /* SDU buffer */ - &rx_pdu_meta_buf.pdu[3], /* PDU payload */ - (testdata_size - testdata_indx)); /* Size */ + /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); + /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -2838,7 +2836,6 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err) sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); testdata_indx = testdata_size; testdata_size += 10; - sdu_size = 10; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); @@ -2866,11 +2863,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err) &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ - /* SDU payload should be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST(val, - &rx_sdu_frag_buf, /* SDU buffer */ - &rx_pdu_meta_buf.pdu[3], /* PDU payload */ - (testdata_size - testdata_indx)); /* Size */ + /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); + /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -3239,7 +3234,6 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err1) payload_number++; testdata_indx = testdata_size; testdata_size += 10; - sdu_size += 10; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); @@ -3263,12 +3257,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err1) /* Test recombine (Black Box) */ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); + + /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1); - /* SDU payload should be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST(val, - &rx_sdu_frag_buf, /* SDU buffer */ - &rx_pdu_meta_buf.pdu[3], /* PDU payload */ - (testdata_size - testdata_indx)); /* Size */ /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -3535,7 +3528,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err2) payload_number++; testdata_indx = testdata_size; testdata_size += 10; - sdu_size = 10; + sdu_size = 0; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, 50); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); @@ -3565,11 +3558,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err2) &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ - /* SDU payload should be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST(val, - &rx_sdu_frag_buf, /* SDU buffer */ - &rx_pdu_meta_buf.pdu[3], /* PDU payload */ - (testdata_size - testdata_indx)); /* Size */ + /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1); + /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -4569,7 +4560,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_error1) seqn = 0; testdata_indx = 0; testdata_size = 13; - sdu_size = 13; + sdu_size = 0; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); @@ -4607,11 +4598,9 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_error1) &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ - /* SDU payload should be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST(val, - &rx_sdu_frag_buf, /* SDU buffer */ - &rx_pdu_meta_buf.pdu[3], /* PDU payload */ - (testdata_size - testdata_indx)); /* Size */ + /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); + /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -5935,7 +5924,6 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid2_pdu_err) payload_number++; testdata_indx = testdata_size; testdata_size += 10; - sdu_size += 10; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); @@ -5958,12 +5946,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid2_pdu_err) /* Test recombine (Black Box) */ /* A new SDU should not be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); + + /* SDU payload should not be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1); - /* SDU payload should be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST(val, - &rx_sdu_frag_buf, /* SDU buffer */ - &rx_pdu_meta_buf.pdu[3], /* PDU payload */ - (testdata_size - testdata_indx)); /* Size */ /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ From d03d84372b9ee34a6d22066899041c0da203d168 Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Fri, 8 Sep 2023 17:03:06 +0200 Subject: [PATCH 0296/1623] [nrf fromtree] tests: bluetooth: controller: Included kconfigs for ISO-AL logging Included kconfigs to set the ISO-AL logging level and control debug logging verbosity in ISO-AL unit tests. Signed-off-by: Nirosharn Amarasinghe (cherry picked from commit 467ec2e6b7b4f4a235cc0c401e378a50f735dfe1) Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 5f8a4c085a3cbad114bc79fa80bdbc4c2b2790f0) --- tests/bluetooth/ctrl_isoal/Kconfig | 19 +++++++++++++++++++ tests/bluetooth/ctrl_isoal/prj.conf | 2 ++ 2 files changed, 21 insertions(+) diff --git a/tests/bluetooth/ctrl_isoal/Kconfig b/tests/bluetooth/ctrl_isoal/Kconfig index b7c10723b93..30049d53a5e 100644 --- a/tests/bluetooth/ctrl_isoal/Kconfig +++ b/tests/bluetooth/ctrl_isoal/Kconfig @@ -12,6 +12,25 @@ config BT_CTLR_CONN_ISO_GROUPS range 1 240 default 1 +config BT_CTLR_DEBUG_ISOAL + bool "[DEPRECATED] Bluetooth ISO-AL debug" + select DEPRECATED + depends on BT_CTLR_ISO + help + This option enables debug support for the Bluetooth ISO-AL. + +module = BT_CTLR_ISOAL +legacy-debug-sym = BT_CTLR_DEBUG_ISOAL +module-str = "Bluetooth Controller ISO-AL" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +config BT_CTLR_ISOAL_LOG_DBG_VERBOSE + bool "ISO-AL verbose debug logging" + depends on BT_CTLR_ISOAL_LOG_LEVEL = 4 + default n + help + Use this option to enable ISO-AL verbose debug logging. + config BT_CTLR_ISOAL_SINKS int "Number of Isochronous Adaptation Layer sinks (for unit tests)" diff --git a/tests/bluetooth/ctrl_isoal/prj.conf b/tests/bluetooth/ctrl_isoal/prj.conf index 5009e2785f8..2f429dd8c47 100644 --- a/tests/bluetooth/ctrl_isoal/prj.conf +++ b/tests/bluetooth/ctrl_isoal/prj.conf @@ -9,3 +9,5 @@ CONFIG_BT_CTLR_CONN_ISO=y CONFIG_BT_CTLR_ISOAL_SINKS=4 CONFIG_BT_CTLR_ISOAL_SOURCES=4 CONFIG_BT_CTLR_ISO_RX_SDU_BUFFERS=4 + +CONFIG_BT_CTLR_ISOAL_LOG_LEVEL_INF=y From fd1e8cfb37ef151b5421694bfde6857a8db18255 Mon Sep 17 00:00:00 2001 From: Andrzej Kuros Date: Tue, 10 Oct 2023 16:14:14 +0200 Subject: [PATCH 0297/1623] [nrf fromlist] nrf53: fix RTC pretick for RTC rescheduling by other interrupts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It might happen that while some interrupt handler other than for RTC0 or RTC1 (e.g. for RADIO) is executed, the scheduled pretick CC triggers. This starts pretick pulses due to the loop through IPC. The change in pretick schedule did not stop the pretick pulses going through IPC loop, what caused heavy increase in power consumption. This commit fixes this behavior. Added also clarifications for Kconfig option `SOC_NRF53_RTC_PRETICK`. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63597 Signed-off-by: Andrzej Kuroś (cherry picked from commit fe1202def42eda65ca5b3a0f41836e9599b0b9c2) --- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 6 +++++- soc/arm/nordic_nrf/nrf53/soc.c | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 87d8a6d0c7a..87d961d6fb3 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -58,7 +58,11 @@ config SOC_NRF53_RTC_PRETICK select ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK if SOC_NRF5340_CPUNET help Indicates that the pre-tick workaround for the anomaly 165 that affects - the nRF5340 SoC should be applied. + the nRF5340 SoC should be applied. The workaround applies to wake ups caused + by EVENTS_COMPARE and EVENTS_OVRFLW on RTC0 and RTC1 for which interrupts are + enabled through INTENSET register. The case when these events are generated + by EVTEN but without interrupts enabled through INTENSET is not handled. + The EVENTS_TICK event is not handled. if SOC_NRF53_RTC_PRETICK diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index c18228ac4fa..396ce79f49e 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -224,6 +224,15 @@ static bool cpu_idle_prepare_monitor_end(void) return __STREXB(0U, &cpu_idle_prepare_monitor_dummy); } +static void rtc_pretick_finish_previous(void) +{ + NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] &= + ~IPC_PUBLISH_RECEIVE_EN_Msk; + + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); +} + + void z_arm_on_enter_cpu_idle_prepare(void) { bool ok_to_sleep = true; @@ -263,6 +272,7 @@ void z_arm_on_enter_cpu_idle_prepare(void) if (rtc_pretick_cc_val != nrf_rtc_cc_get(NRF_RTC1, RTC1_PRETICK_CC_CHAN)) { /* The CC for pretick needs to be updated. */ + rtc_pretick_finish_previous(); nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_CC_CHAN, rtc_pretick_cc_val); if (rtc_ticks_to_next_event >= NRF_RTC_COUNTER_MAX/2) { @@ -406,22 +416,14 @@ static int rtc_pretick_cpuapp_init(void) } #else /* CONFIG_SOC_NRF5340_CPUNET */ -static void rtc_pretick_rtc_isr_hook(void) -{ - NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] &= - ~IPC_PUBLISH_RECEIVE_EN_Msk; - - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); -} - void rtc_pretick_rtc0_isr_hook(void) { - rtc_pretick_rtc_isr_hook(); + rtc_pretick_finish_previous(); } void rtc_pretick_rtc1_isr_hook(void) { - rtc_pretick_rtc_isr_hook(); + rtc_pretick_finish_previous(); } static int rtc_pretick_cpunet_init(void) From 009e4d56688790dce25ab360d5add0ef44e92bd5 Mon Sep 17 00:00:00 2001 From: Andrzej Kuros Date: Tue, 10 Oct 2023 20:14:30 +0200 Subject: [PATCH 0298/1623] [nrf fromlist] nrf5340: pretick decoupled from workaround anomaly 160 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Coupling in code between workarounds for anomaly 160 and anomaly 165 (pretick) is decreased. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63597 Signed-off-by: Andrzej Kuroś (cherry picked from commit 1d4a51c2a893f84d17fcf78adb0bdbabe33e71e7) --- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 1 + soc/arm/nordic_nrf/nrf53/soc.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 87d961d6fb3..2cd934af324 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -53,6 +53,7 @@ config SOC_NRF53_ANOMALY_160_WORKAROUND config SOC_NRF53_RTC_PRETICK bool "Pre-tick workaround for nRF5340 anomaly 165" + depends on (SYS_CLOCK_EXISTS && SOC_NRF5340_CPUNET) || SOC_NRF5340_CPUAPP select NRFX_DPPI select ARM_ON_ENTER_CPU_IDLE_HOOK if SOC_NRF5340_CPUNET select ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK if SOC_NRF5340_CPUNET diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index 396ce79f49e..39d64d72cc2 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -133,6 +133,7 @@ static bool nrf53_anomaly_160_check(void) return true; } +#endif /* CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND */ #if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) @@ -337,6 +338,8 @@ void z_arm_on_enter_cpu_idle_prepare(void) } #endif /* CONFIG_SOC_NRF53_RTC_PRETICK && CONFIG_SOC_NRF5340_CPUNET */ +#if defined(CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND) || \ + (defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET)) bool z_arm_on_enter_cpu_idle(void) { bool ok_to_sleep = true; @@ -357,6 +360,7 @@ bool z_arm_on_enter_cpu_idle(void) } #endif +#if defined(CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND) if (ok_to_sleep) { ok_to_sleep = nrf53_anomaly_160_check(); @@ -371,6 +375,7 @@ bool z_arm_on_enter_cpu_idle(void) } #endif } +#endif /* CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND */ #if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) if (!ok_to_sleep) { @@ -382,7 +387,9 @@ bool z_arm_on_enter_cpu_idle(void) return ok_to_sleep; } -#endif /* CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND */ +#endif /* CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND || + * (CONFIG_SOC_NRF53_RTC_PRETICK && CONFIG_SOC_NRF5340_CPUNET) + */ #if CONFIG_SOC_NRF53_RTC_PRETICK #ifdef CONFIG_SOC_NRF5340_CPUAPP From 495c47634d7c2105b7dd21734ef4a87eb25ea932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 20 Sep 2023 12:12:50 +0200 Subject: [PATCH 0299/1623] [nrf fromtree] drivers: spi_nrfx_spis: Handle empty spi_buf_set structures properly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SPI API allows `spi_buf_set` structures with no buffers linked to them (with `.buffers = NULL`). Correct the spi_nrfx_spis driver so that it is able to deal with such structures. Signed-off-by: Andrzej Głąbek (cherry picked from commit eafe6a9a3101c187849849c4e0f3c3f9696ccdb0) (cherry picked from commit d21b65201c9b7b56aa8f565c810266f5e720fc04) --- drivers/spi/spi_nrfx_spis.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi_nrfx_spis.c b/drivers/spi/spi_nrfx_spis.c index 6ba36a139a0..d2a61530f00 100644 --- a/drivers/spi/spi_nrfx_spis.c +++ b/drivers/spi/spi_nrfx_spis.c @@ -170,6 +170,8 @@ static int transceive(const struct device *dev, { struct spi_nrfx_data *dev_data = dev->data; const struct spi_nrfx_config *dev_config = dev->config; + const struct spi_buf *tx_buf = tx_bufs ? tx_bufs->buffers : NULL; + const struct spi_buf *rx_buf = rx_bufs ? rx_bufs->buffers : NULL; int error; spi_context_lock(&dev_data->ctx, asynchronous, cb, userdata, spi_cfg); @@ -181,8 +183,7 @@ static int transceive(const struct device *dev, (rx_bufs && rx_bufs->count > 1)) { LOG_ERR("Scattered buffers are not supported"); error = -ENOTSUP; - } else if (tx_bufs && tx_bufs->buffers[0].len && - !nrfx_is_in_ram(tx_bufs->buffers[0].buf)) { + } else if (tx_buf && tx_buf->len && !nrfx_is_in_ram(tx_buf->buf)) { LOG_ERR("Only buffers located in RAM are supported"); error = -ENOTSUP; } else { @@ -193,10 +194,10 @@ static int transceive(const struct device *dev, } error = prepare_for_transfer(dev, - tx_bufs ? tx_bufs->buffers[0].buf : NULL, - tx_bufs ? tx_bufs->buffers[0].len : 0, - rx_bufs ? rx_bufs->buffers[0].buf : NULL, - rx_bufs ? rx_bufs->buffers[0].len : 0); + tx_buf ? tx_buf->buf : NULL, + tx_buf ? tx_buf->len : 0, + rx_buf ? rx_buf->buf : NULL, + rx_buf ? rx_buf->len : 0); if (error == 0) { if (dev_config->wake_gpio.port) { /* Set the WAKE line low (tie it to ground) From a4670ff4eabc3517bda2bc34b25b97e2159c33dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Thu, 28 Sep 2023 11:24:12 +0200 Subject: [PATCH 0300/1623] [nrf fromtree] tests: kernel: timer: jitter_drift: Restore initial alignment to tick MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up to commit 4cc21e2f4aea2e37f4fea1216fe92ded9ba6d755. That short sleeping before starting the test was removed together with accuracy improvements (specifically, with moving of the first readout of the cycle counter). Nevertheless, this tick alignment it still needed, as without it in specific conditions the test may undesirably fail. Signed-off-by: Andrzej Głąbek (cherry picked from commit 222593f8c45683c29341e153fe518ba7ea22498e) (cherry picked from commit 7b739ac27ac6c1e26c48f6e9f144ec685a54149f) --- tests/kernel/timer/timer_behavior/src/jitter_drift.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/kernel/timer/timer_behavior/src/jitter_drift.c b/tests/kernel/timer/timer_behavior/src/jitter_drift.c index cd6afaea00d..6d3e78d514b 100644 --- a/tests/kernel/timer/timer_behavior/src/jitter_drift.c +++ b/tests/kernel/timer/timer_behavior/src/jitter_drift.c @@ -121,6 +121,17 @@ static void do_test_using(void (*sample_collection_fn)(void)) periodic_idx = 0; k_sem_init(&periodic_sem, 0, 1); + + /* Align to tick boundary. Otherwise the first handler execution + * might turn out to be significantly late and cause the test to + * fail. This can happen if k_timer_start() is called right before + * the upcoming tick boundary and in consequence the tick passes + * between the moment when the kernel decides what tick to use for + * the next timeout and the moment when the system timer actually + * sets up that timeout. + */ + k_sleep(K_TICKS(1)); + sample_collection_fn(); k_sem_take(&periodic_sem, K_FOREVER); From 7e3e8dea4ba07c5730b6d037ba50ddede860bc1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Fri, 6 Oct 2023 09:17:05 +0200 Subject: [PATCH 0301/1623] [nrf fromtree] bluetooth: common: Kconfig: Add missing dependency for BT_MONITOR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This module calls `log_output_*` functions so it should enable the `LOG_OUTPUT` Kconfig option explicitly. Signed-off-by: Andrzej Głąbek (cherry picked from commit cb1b1ce7d111fe830eade1dfbd95229f10f99005) (cherry picked from commit 8513132483676fad66bff03e4c9933744250f1b4) --- subsys/bluetooth/common/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index d72ce90afa6..bf4aee75e48 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -282,6 +282,7 @@ endif # BT_ASSERT config BT_MONITOR bool + select LOG_OUTPUT choice BT_DEBUG_TYPE prompt "Bluetooth debug type" From 74bdabf7e57a988ad740da44398cf93f7d5e0c79 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 10 Oct 2023 09:52:28 +0200 Subject: [PATCH 0302/1623] [nrf fromtree] Bluetooth: Mesh: Fix Upload Progress for already received fw In OOB upload, when Check Firmware OOB procedure completes successfully and the firmware is already received, we send Firmware Distribution Upload Status message with update Phase set to Transfer Success. In this case, we must set Upload Progress to 100%. This can't be done through the callback as the application layer doesn't yet know that the firmware is already received. This will happen by the exist from bt_mesh_dfd_srv_oob_check_complete function, which will return error code -EEXIST. Signed-off-by: Pavel Vasilyev (cherry picked from commit 9641864a200f83531fe0d0c866d53dda96c905ea) (cherry picked from commit 55152781e7bd1d3b361a6605dcad1e11ad27fcb9) --- subsys/bluetooth/mesh/dfd_srv.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 5d3ada4b4aa..a67a3a778ca 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -342,9 +342,10 @@ static int handle_apply(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, return 0; } -static void upload_status_rsp(struct bt_mesh_dfd_srv *srv, - struct bt_mesh_msg_ctx *ctx, - enum bt_mesh_dfd_status status) +static void upload_status_rsp_with_progress(struct bt_mesh_dfd_srv *srv, + struct bt_mesh_msg_ctx *ctx, + enum bt_mesh_dfd_status status, + uint8_t progress) { BT_MESH_MODEL_BUF_DEFINE(rsp, BT_MESH_DFD_OP_UPLOAD_STATUS, DFD_UPLOAD_STATUS_MSG_MAXLEN); @@ -361,14 +362,13 @@ static void upload_status_rsp(struct bt_mesh_dfd_srv *srv, #ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD if (srv->upload.is_oob) { - net_buf_simple_add_u8(&rsp, - srv->cb->oob_progress_get(srv, srv->upload.slot) | BIT(7)); + net_buf_simple_add_u8(&rsp, progress | BIT(7)); net_buf_simple_add_mem(&rsp, srv->upload.oob.current_fwid, srv->upload.oob.current_fwid_len); } else #endif { - net_buf_simple_add_u8(&rsp, bt_mesh_blob_srv_progress(&srv->upload.blob)); + net_buf_simple_add_u8(&rsp, progress); net_buf_simple_add_mem(&rsp, srv->upload.slot->fwid, srv->upload.slot->fwid_len); } @@ -376,6 +376,24 @@ static void upload_status_rsp(struct bt_mesh_dfd_srv *srv, bt_mesh_model_send(srv->mod, ctx, &rsp, NULL, NULL); } +static void upload_status_rsp(struct bt_mesh_dfd_srv *srv, + struct bt_mesh_msg_ctx *ctx, + enum bt_mesh_dfd_status status) +{ + uint8_t progress; + +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + if (srv->upload.is_oob) { + progress = srv->cb->oob_progress_get(srv, srv->upload.slot); + } else +#endif + { + progress = bt_mesh_blob_srv_progress(&srv->upload.blob); + } + + upload_status_rsp_with_progress(srv, ctx, status, progress); +} + static int handle_upload_get(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { @@ -400,7 +418,7 @@ static inline int set_upload_fwid(struct bt_mesh_dfd_srv *srv, struct bt_mesh_ms case -EEXIST: /* Img with this fwid already is in list */ srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; bt_mesh_dfu_slot_release(srv->upload.slot); - upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); + upload_status_rsp_with_progress(srv, ctx, BT_MESH_DFD_SUCCESS, 100); break; case 0: srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE; From 4491262ebf889bf6bcb1ff2aed0c504a9f3cb17a Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 10 Oct 2023 09:59:19 +0200 Subject: [PATCH 0303/1623] [nrf fromtree] Bluetooth: Mesh: Fix Fw Dist Upload OOB Start msg length check This message _at least_ 2 bytes long, but can be longer, thus BT_MESH_LEN_MIN should be used. Signed-off-by: Pavel Vasilyev (cherry picked from commit 1329a9d31292f3f2e5f4134e9cc61acb76daa5a9) (cherry picked from commit 96d61afdc45fd3f53b4a6ea85b74263002e7b6e7) --- subsys/bluetooth/mesh/dfd_srv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index a67a3a778ca..f060e263ace 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -761,7 +761,7 @@ const struct bt_mesh_model_op _bt_mesh_dfd_srv_op[] = { { BT_MESH_DFD_OP_APPLY, BT_MESH_LEN_EXACT(0), handle_apply }, { BT_MESH_DFD_OP_UPLOAD_GET, BT_MESH_LEN_EXACT(0), handle_upload_get }, { BT_MESH_DFD_OP_UPLOAD_START, BT_MESH_LEN_MIN(16), handle_upload_start }, - { BT_MESH_DFD_OP_UPLOAD_START_OOB, BT_MESH_LEN_EXACT(2), handle_upload_start_oob }, + { BT_MESH_DFD_OP_UPLOAD_START_OOB, BT_MESH_LEN_MIN(2), handle_upload_start_oob }, { BT_MESH_DFD_OP_UPLOAD_CANCEL, BT_MESH_LEN_EXACT(0), handle_upload_cancel }, { BT_MESH_DFD_OP_FW_GET, BT_MESH_LEN_MIN(0), handle_fw_get }, { BT_MESH_DFD_OP_FW_GET_BY_INDEX, BT_MESH_LEN_EXACT(2), handle_fw_get_by_index }, From a2744d2bdee2459cd9dd0ebec788a99d82b02f7b Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 10 Oct 2023 10:52:46 +0200 Subject: [PATCH 0304/1623] [nrf fromtree] Bluetooth: Mesh: Ignore duplicate OOB upload request If a Fw Distribution Client sends the Upload OOB Start message, but the application layer didn't call bt_mesh_dfd_srv_oob_check_complete yet, we have no other option other than ignore the message. The next phase in this case could be Transfer Active, Transfer Success or Failed and it will be set only after Check Firmware OOB procedure completes. Signed-off-by: Pavel Vasilyev (cherry picked from commit 7154f356af59c3a1b61168b885a7b9f23b3f6404) (cherry picked from commit 63d1a0ee7753ac0a338156167b36bafbbe230fe2) --- include/zephyr/bluetooth/mesh/dfd_srv.h | 1 + subsys/bluetooth/mesh/dfd_srv.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/zephyr/bluetooth/mesh/dfd_srv.h b/include/zephyr/bluetooth/mesh/dfd_srv.h index da339c57ec6..666e0d8ad3d 100644 --- a/include/zephyr/bluetooth/mesh/dfd_srv.h +++ b/include/zephyr/bluetooth/mesh/dfd_srv.h @@ -228,6 +228,7 @@ struct bt_mesh_dfd_srv { struct bt_mesh_blob_srv blob; #ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD bool is_oob; + bool is_pending_oob_check; struct { uint8_t uri_len; uint8_t uri[CONFIG_BT_MESH_DFU_URI_MAXLEN]; diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index f060e263ace..f8dfaf0b97f 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -586,6 +586,11 @@ static int handle_upload_start_oob(struct bt_mesh_model *mod, struct bt_mesh_msg #endif upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_BUSY_WITH_UPLOAD); return 0; +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + } else if (srv->upload.is_oob && srv->upload.is_pending_oob_check) { + /* Ignore the request if we didn't confirm the previous one. */ + return 0; +#endif } #ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD @@ -618,6 +623,8 @@ static int handle_upload_start_oob(struct bt_mesh_model *mod, struct bt_mesh_msg if (status != BT_MESH_DFD_SUCCESS) { upload_status_rsp(srv, ctx, status); bt_mesh_dfu_slot_release(srv->upload.slot); + } else { + srv->upload.is_pending_oob_check = true; } #else upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_URI_NOT_SUPPORTED); @@ -1211,13 +1218,16 @@ int bt_mesh_dfd_srv_oob_check_complete(struct bt_mesh_dfd_srv *srv, int err; if (slot != srv->upload.slot || !srv->upload.is_oob || - srv->upload.phase == BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE) { + srv->upload.phase == BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE || + !srv->upload.is_pending_oob_check) { /* This should not happen, unless the application calls the function with a * "wrong" pointer or at a wrong time. */ return -EINVAL; } + srv->upload.is_pending_oob_check = false; + if (status != BT_MESH_DFD_SUCCESS) { bt_mesh_dfu_slot_release(srv->upload.slot); upload_status_rsp(srv, &srv->upload.oob.ctx, status); From c97f38205f50eceac6b66359799e19df5b6aeb28 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 10 Oct 2023 07:57:32 +0200 Subject: [PATCH 0305/1623] [nrf fromtree] Bluetooth: Mesh: Release previously reserved slot before reserving again If the previous upload was in-band and it didn't complete, the slot will stay reserved. By design we release slot not at the end of the upload phase, but at the start of a new upload phase. This fixes DFU/SR/FD/BV-13-C. Signed-off-by: Pavel Vasilyev (cherry picked from commit d1c2ca252556fffd043dcdff2edb1277bcaedb31) (cherry picked from commit 2ab65215ceef910fffc81f74e67ae726306eb5f5) --- subsys/bluetooth/mesh/dfd_srv.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index f8dfaf0b97f..cfcc82eb8d1 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -607,6 +607,13 @@ static int handle_upload_start_oob(struct bt_mesh_model *mod, struct bt_mesh_msg return 0; } + /* This will be a no-op if the slot state isn't RESERVED, which is + * what we want. + */ + if (srv->upload.slot) { + bt_mesh_dfu_slot_release(srv->upload.slot); + } + srv->upload.is_oob = true; srv->upload.slot = slot; memcpy(srv->upload.oob.uri, uri, uri_len); From 5640e9e33ab1bfaca4ed341b0d752518ed181de2 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 10 Oct 2023 08:54:48 +0200 Subject: [PATCH 0306/1623] [nrf fromtree] tests: bluetooth: tester: Add Upload OOB support for mesh tester This allow to run the following PTS test: - DFU/SR/FD/BV-06-C - DFU/SR/FD/BV-13-C - DFU/SR/FD/BV-14-C - DFU/SR/FD/BV-15-C - DFU/SR/FD/BV-16-C - DFU/SR/FD/BV-17-C - DFU/SR/FD/BV-18-C - DFU/SR/FD/BV-22-C Signed-off-by: Pavel Vasilyev (cherry picked from commit 1c1c5e22b73a2f628696d7e10e78e08c7468176f) (cherry picked from commit 3b705c2885cec71eca48ccfeb5823e712730856f) --- tests/bluetooth/tester/src/btp_mesh.c | 119 ++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 662dca238c1..81c41dca708 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -162,13 +162,132 @@ static int dfd_srv_send(struct bt_mesh_dfd_srv *srv, return 0; } +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD +static struct { + uint8_t uri[CONFIG_BT_MESH_DFU_URI_MAXLEN]; + uint8_t uri_len; + uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; + uint8_t fwid_len; + const struct bt_mesh_dfu_slot *slot; + uint8_t progress; + bool started; +} dfd_srv_oob_ctx; + +static void oob_check_handler(struct k_work *work); +static K_WORK_DEFINE(oob_check, oob_check_handler); +static void oob_store_handler(struct k_work *work); +static K_WORK_DEFINE(oob_store, oob_store_handler); + +static int dfd_srv_start_oob_upload(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot, + const char *uri, uint8_t uri_len, + const uint8_t *fwid, uint16_t fwid_len) +{ + LOG_DBG("Start OOB Upload"); + + memcpy(dfd_srv_oob_ctx.uri, uri, uri_len); + dfd_srv_oob_ctx.uri_len = uri_len; + memcpy(dfd_srv_oob_ctx.fwid, fwid, fwid_len); + dfd_srv_oob_ctx.fwid_len = fwid_len; + dfd_srv_oob_ctx.slot = slot; + dfd_srv_oob_ctx.progress = 0; + dfd_srv_oob_ctx.started = true; + + k_work_submit(&oob_check); + + return BT_MESH_DFD_SUCCESS; +} + +static void dfd_srv_cancel_oob_upload(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot) +{ + LOG_DBG("Cancel OOB Upload"); + + dfd_srv_oob_ctx.started = false; +} + +static uint8_t dfd_srv_oob_progress_get(struct bt_mesh_dfd_srv *srv, + const struct bt_mesh_dfu_slot *slot) +{ + uint8_t progress; + + if (dfd_srv_oob_ctx.started) { + progress = dfd_srv_oob_ctx.progress; + + dfd_srv_oob_ctx.progress = MIN(dfd_srv_oob_ctx.progress + 25, 99); + + if (dfd_srv_oob_ctx.progress == 99) { + k_work_submit(&oob_store); + } + } else { + progress = 0; + } + + LOG_DBG("OOB Progress Get (%sstarted: %d %%)", dfd_srv_oob_ctx.started ? "" : "not ", + progress); + return progress; +} +#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ + static struct bt_mesh_dfd_srv_cb dfd_srv_cb = { .recv = dfd_srv_recv, .del = dfd_srv_del, .send = dfd_srv_send, +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD + .start_oob_upload = dfd_srv_start_oob_upload, + .cancel_oob_upload = dfd_srv_cancel_oob_upload, + .oob_progress_get = dfd_srv_oob_progress_get, +#endif }; static struct bt_mesh_dfd_srv dfd_srv = BT_MESH_DFD_SRV_INIT(&dfd_srv_cb); + +#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD +#define SUPPORTED_SCHEME "http" + +static void oob_check_handler(struct k_work *work) +{ + uint8_t scheme[10]; + int i; + int status; + int err; + + for (i = 0; i < MIN(dfd_srv_oob_ctx.uri_len, sizeof(scheme)); i++) { + if (IN_RANGE(dfd_srv_oob_ctx.uri[i], 48, 57) || /* DIGIT */ + IN_RANGE(dfd_srv_oob_ctx.uri[i], 65, 90) || /* ALPHA UPPER CASE */ + IN_RANGE(dfd_srv_oob_ctx.uri[i], 97, 122) || /* ALPHA LOWER CASE */ + dfd_srv_oob_ctx.uri[i] == '.' || + dfd_srv_oob_ctx.uri[i] == '+' || + dfd_srv_oob_ctx.uri[i] == '-') { + scheme[i] = dfd_srv_oob_ctx.uri[i]; + } else { + break; + } + } + + if (i == dfd_srv_oob_ctx.uri_len || dfd_srv_oob_ctx.uri[i] != ':') { + status = BT_MESH_DFD_ERR_URI_MALFORMED; + } else if (i != strlen(SUPPORTED_SCHEME) || + memcmp(scheme, SUPPORTED_SCHEME, strlen(SUPPORTED_SCHEME))) { + status = BT_MESH_DFD_ERR_URI_NOT_SUPPORTED; + } else { + status = BT_MESH_DFD_SUCCESS; + } + + err = bt_mesh_dfd_srv_oob_check_complete(&dfd_srv, dfd_srv_oob_ctx.slot, status, + dfd_srv_oob_ctx.fwid, dfd_srv_oob_ctx.fwid_len); + LOG_DBG("OOB check completed (err %d)", err); +} + +static void oob_store_handler(struct k_work *work) +{ + int err; + + err = bt_mesh_dfd_srv_oob_store_complete(&dfd_srv, dfd_srv_oob_ctx.slot, true, + 10000, "metadata", 8); + LOG_DBG("OOB store completed (err %d)", err); +} +#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ #endif #if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) From e5ab2f9978ecfdde887735f5e59d28912a5ddb4d Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 10 Oct 2023 09:50:18 +0200 Subject: [PATCH 0307/1623] [nrf fromtree] Bluetooth: Mesh: Print URI and FWID in Upload OOB Start msg this is useful for debugging. Signed-off-by: Pavel Vasilyev (cherry picked from commit 2c9fc043d712e23754f8605b04ef8d10e9fa8be6) (cherry picked from commit 49556cc0bdf2867ea58e854d1d97b4ba7f7fc0da) --- subsys/bluetooth/mesh/dfd_srv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index cfcc82eb8d1..2547c07a5b4 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -572,6 +572,10 @@ static int handle_upload_start_oob(struct bt_mesh_model *mod, struct bt_mesh_msg fwid_len = buf->len; fwid = net_buf_simple_pull_mem(buf, fwid_len); + LOG_DBG("Upload OOB Start"); + LOG_HEXDUMP_DBG(uri, uri_len, "URI"); + LOG_HEXDUMP_DBG(fwid, fwid_len, "FWID"); + if (upload_is_busy(srv)) { #ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD if (srv->upload.is_oob && From 6c895c5d3ee5b98453112f1855a646624211c68c Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Thu, 12 Oct 2023 09:51:12 +0200 Subject: [PATCH 0308/1623] [nrf fromlist] manifest: update hal_nordic rev to fix nRF91 anomaly 7 New hal_nordic revision contains updated nrfx with an improvement to nRF91 anomaly 7 workaround. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63841 Signed-off-by: Nikodem Kastelik (cherry picked from commit 86c95f4906c4caf3a5ad117d13f127b1381c18e8) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index bed3b47cfe5..f5366678a0e 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 092eb78ed1b1551d8f480019b9c05d7371784578 + revision: 568a5e90b858a2e5b640b3fe6ab9b59dd2ce9f7f path: modules/hal/nordic groups: - hal From 1fc4225e4d05cc510aef22d8b69b918f559533f4 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 12 Oct 2023 10:36:45 +0200 Subject: [PATCH 0309/1623] [nrf fromtree] Bluetooth: Mesh: Fix Capabilities Status message with OOB upload enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `else` case was incorrectly excluded by preprocessor. Signed-off-by: Pavel Vasilyev (cherry picked from commit 5cf6218c627d35560afaa70a2162a5952f055bdb) Signed-off-by: Alperen Şener (cherry picked from commit c60135ad3ca03db8c4ddf38d08ea542e80ba3082) --- subsys/bluetooth/mesh/dfd_srv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 2547c07a5b4..d225f67bb77 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -233,11 +233,10 @@ static int handle_capabilities_get(struct bt_mesh_model *mod, struct bt_mesh_msg net_buf_simple_add_mem(&rsp, srv->oob_schemes.schemes, srv->oob_schemes.count); } else -#else +#endif { net_buf_simple_add_u8(&rsp, 0); } -#endif bt_mesh_model_send(mod, ctx, &rsp, NULL, NULL); From a17674613fd86db048183888dc1f55f1b72875f2 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 12 Oct 2023 12:29:59 +0200 Subject: [PATCH 0310/1623] [nrf fromtree] Bluetooth: Mesh: Fix failing DFU/SR/FD/BV-08-C test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `upload_status_rsp_with_progress` function uses the currently set slot pointer to set firmware id field in the message. If another upload starts but the firmware is already received, the slot API won't let us to set the fwid and will return an error code. In this case, the slot pointer stays invalid as fwid wasn't set, and `upload_status_rsp_with_progress` will not add fwid as the lenght is zero. Signed-off-by: Pavel Vasilyev (cherry picked from commit 0af523eba75fc5afece9539f576cc15b8b914dfe) Signed-off-by: Alperen Şener (cherry picked from commit 0d0fabd564ad5f2b90aa6fe56e040add479ce7f6) --- subsys/bluetooth/mesh/dfd_srv.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index d225f67bb77..0a9ecba6cec 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -412,12 +412,20 @@ static inline int set_upload_fwid(struct bt_mesh_dfd_srv *srv, struct bt_mesh_ms case -EFBIG: /* Fwid too long */ case -EALREADY: /* Other server is in progress with this fwid */ bt_mesh_dfu_slot_release(srv->upload.slot); + srv->upload.slot = NULL; upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); break; case -EEXIST: /* Img with this fwid already is in list */ srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; bt_mesh_dfu_slot_release(srv->upload.slot); - upload_status_rsp_with_progress(srv, ctx, BT_MESH_DFD_SUCCESS, 100); + + err = bt_mesh_dfu_slot_get(fwid, fwid_len, &srv->upload.slot); + if (!err) { + upload_status_rsp_with_progress(srv, ctx, BT_MESH_DFD_SUCCESS, 100); + } else { + srv->upload.slot = NULL; + upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); + } break; case 0: srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE; From 5fed002128563c138ff679fdb35ac1b4f9ecb064 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Thu, 12 Oct 2023 13:13:40 +0200 Subject: [PATCH 0311/1623] [nrf fromtree] Bluetooth: Mesh: fix proxy solicitation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit makes workable proxy solicitation functionality only server part without dependencies on client part. Only on demand proxy server is required. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 625faa7f03e7ac4a8c9795bfc03ba278010973df) Signed-off-by: Alperen Şener (cherry picked from commit 009d335d6c660919a3bcde72fa54a2a5fb071861) --- include/zephyr/bluetooth/uuid.h | 2 +- subsys/bluetooth/mesh/crypto.c | 2 +- subsys/bluetooth/mesh/proxy_srv.c | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/zephyr/bluetooth/uuid.h b/include/zephyr/bluetooth/uuid.h index 1fa8ece6466..cab12eac74b 100644 --- a/include/zephyr/bluetooth/uuid.h +++ b/include/zephyr/bluetooth/uuid.h @@ -587,7 +587,7 @@ struct bt_uuid_128 { /** * @brief Proxy Solicitation UUID value */ -#define BT_UUID_MESH_PROXY_SOLICITATION_VAL 0x7fcb +#define BT_UUID_MESH_PROXY_SOLICITATION_VAL 0x1859 /** * @brief Reconnection Configuration Service UUID value */ diff --git a/subsys/bluetooth/mesh/crypto.c b/subsys/bluetooth/mesh/crypto.c index e42717475c0..b79458f7ea2 100644 --- a/subsys/bluetooth/mesh/crypto.c +++ b/subsys/bluetooth/mesh/crypto.c @@ -419,7 +419,7 @@ int bt_mesh_net_decrypt(const struct bt_mesh_key *key, struct net_buf_simple *bu if (IS_ENABLED(CONFIG_BT_MESH_PROXY) && type == BT_MESH_NONCE_PROXY) { create_proxy_nonce(nonce, buf->data, iv_index); - } else if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && + } else if (IS_ENABLED(CONFIG_BT_MESH_SOLICITATION) && type == BT_MESH_NONCE_SOLICITATION) { create_proxy_sol_nonce(nonce, buf->data); } else { diff --git a/subsys/bluetooth/mesh/proxy_srv.c b/subsys/bluetooth/mesh/proxy_srv.c index 62c46582fa0..12775b93651 100644 --- a/subsys/bluetooth/mesh/proxy_srv.c +++ b/subsys/bluetooth/mesh/proxy_srv.c @@ -698,9 +698,11 @@ static void gatt_proxy_solicited(struct bt_mesh_subnet *sub) if (sub->priv_net_id_sent > 0) { timeout = sub->priv_net_id_sent + MSEC_PER_SEC * bt_mesh_od_priv_proxy_get(); + remaining = MIN(timeout - now, INT32_MAX); + } else { + remaining = MSEC_PER_SEC * bt_mesh_od_priv_proxy_get(); } - remaining = MIN(timeout - now, INT32_MAX); if ((timeout > 0 && now > timeout) || (remaining / MSEC_PER_SEC < 1)) { LOG_DBG("Advertising Private Network ID timed out " "after solicitation"); From 7b5fbe1bc0b575d221003234f7772696fd9978cd Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Thu, 12 Oct 2023 13:17:01 +0200 Subject: [PATCH 0312/1623] [nrf fromtree] tests: bluetooth: tester: enable proxy solicitation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit enables proxy solicitation functionality (server part) for mesh proxy PTS tests. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 917a3e6e6418515b80459c9d3c4e5e650c81362f) Signed-off-by: Alperen Şener (cherry picked from commit ab53aaac739e1588fd2b246e10b26cca9785e91d) --- tests/bluetooth/tester/overlay-mesh-v1d1.conf | 1 + tests/bluetooth/tester/src/btp_mesh.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/overlay-mesh-v1d1.conf b/tests/bluetooth/tester/overlay-mesh-v1d1.conf index 978d1acd3df..52045ce34df 100644 --- a/tests/bluetooth/tester/overlay-mesh-v1d1.conf +++ b/tests/bluetooth/tester/overlay-mesh-v1d1.conf @@ -23,6 +23,7 @@ CONFIG_BT_MESH_DFU_SLOT_CNT=2 CONFIG_BT_MESH_PRIV_BEACONS=y CONFIG_BT_MESH_PRIV_BEACON_SRV=y CONFIG_BT_MESH_PRIV_BEACON_CLI=y +CONFIG_BT_MESH_OD_PRIV_PROXY_SRV=y CONFIG_BT_MESH_MODEL_EXTENSIONS=y CONFIG_BT_MESH_COMP_PAGE_1=y CONFIG_BT_MESH_COMP_PAGE_2=y diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 81c41dca708..1d6f696f729 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -5081,7 +5081,7 @@ static const struct btp_handler handlers[] = { .func = srpl_clear }, #endif -#if defined(CONFIG_BT_MESH_SOLICITATION) +#if defined(CONFIG_BT_MESH_PROXY_SOLICITATION) { .opcode = BTP_MESH_PROXY_SOLICIT, .expect_len = sizeof(struct btp_proxy_solicit_cmd), From 52be85e04f3633e508156f79c8e13e87362c5a38 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Thu, 12 Oct 2023 14:50:01 +0200 Subject: [PATCH 0313/1623] [nrf fromtree] Bluetooth: Mesh: improve solicitation debug logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commits adds debug logging for all reasons preventing of the proxy solicitation. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 00457ae6c629ef138fd7b7ce10bdd1c0b07e4286) Signed-off-by: Alperen Şener (cherry picked from commit cf03a36001d50046c097c0c1b0c16b2713d48ea1) --- subsys/bluetooth/mesh/solicitation.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/solicitation.c b/subsys/bluetooth/mesh/solicitation.c index f6543dcb320..e2100fa42db 100644 --- a/subsys/bluetooth/mesh/solicitation.c +++ b/subsys/bluetooth/mesh/solicitation.c @@ -190,13 +190,14 @@ void bt_mesh_sol_recv(struct net_buf_simple *buf, uint8_t uuid_list_len) if (bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED || bt_mesh_priv_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED || bt_mesh_od_priv_proxy_get() == 0) { + LOG_DBG("Not soliciting"); return; } /* Get rid of ad_type that was checked in bt_mesh_scan_cb */ type = net_buf_simple_pull_u8(buf); if (type != BT_DATA_UUID16_SOME && type != BT_DATA_UUID16_ALL) { - LOG_ERR("Invalid type 0x%x, expected 0x%x or 0x%x", + LOG_DBG("Invalid type 0x%x, expected 0x%x or 0x%x", type, BT_DATA_UUID16_SOME, BT_DATA_UUID16_ALL); return; } @@ -215,6 +216,7 @@ void bt_mesh_sol_recv(struct net_buf_simple *buf, uint8_t uuid_list_len) } if (!sol_uuid_found) { + LOG_DBG("No solicitation UUID found"); return; } @@ -230,6 +232,7 @@ void bt_mesh_sol_recv(struct net_buf_simple *buf, uint8_t uuid_list_len) } if (buf->len <= reported_len - 3) { + LOG_DBG("Invalid length (%u) Solicitation PDU", buf->len); return; } @@ -237,12 +240,13 @@ void bt_mesh_sol_recv(struct net_buf_simple *buf, uint8_t uuid_list_len) } if (!svc_data_found) { + LOG_DBG("No solicitation service data found"); return; } type = net_buf_simple_pull_u8(buf); if (type != 0) { - LOG_ERR("Invalid type %d, expected 0x00", type); + LOG_DBG("Invalid type %d, expected 0x00", type); return; } From ea44fcffcc107ced832752c7f8f91ffc559b8b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alperen=20=C5=9Eener?= Date: Thu, 12 Oct 2023 16:27:47 +0200 Subject: [PATCH 0314/1623] [nrf fromlist] tests: bluetooth: tester: add page number to response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PTS requires IUT to send requests with page number with 0xFF or the highest supported page number in order to retrieve all the composition data pages from the lower tester. This commit add the page number to the response, thus the upper tester can follow the last page number and send the next page request until page 0 is requested. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63872 Signed-off-by: Alperen Şener (cherry picked from commit 2410ec17fe829207e9d1a9a1d2b2bc9f3c64ab4c) --- tests/bluetooth/tester/src/btp_mesh.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 1d6f696f729..c43f19f04ce 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -2033,8 +2033,9 @@ static uint8_t composition_data_get(const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } - memcpy(rp->data, comp->data, comp->len); - *rsp_len = comp->len; + rp->data[0] = page; + memcpy(rp->data + 1, comp->data, comp->len); + *rsp_len = comp->len + 1; return BTP_STATUS_SUCCESS; } From a0d7c03a96a5ed77ca937491207044d0e538ac38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Fri, 13 Oct 2023 17:03:01 +0200 Subject: [PATCH 0315/1623] [nrf fromlist] modules: hal_nordic: cmake: Fix checking if uicr DT node is accessible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to cmake documentation, in the `if()` expression the string evaluates to false unless its value is one of the true constants. Thus, the commands under `if(${uicr_path})` are never executed. Use `if(DEFINED uicr_path)` instead, since `uicr_path` is returned by `dt_nodelabel()` and it will be undefined if such node does not exist. Signed-off-by: Andrzej Głąbek Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63929 (cherry picked from commit 41e471d2b5746e49ca1dd6c1ba91a45c1f6d269b) --- modules/hal_nordic/nrfx/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index e98db561906..ca325c31770 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -116,7 +116,7 @@ endif() # doing the proper configuration sequence during system init dt_nodelabel(uicr_path NODELABEL "uicr") -if(${uicr_path}) +if(DEFINED uicr_path) dt_prop(nfct_pins_as_gpios PATH ${uicr_path} PROPERTY "nfct-pins-as-gpios") if(${nfct_pins_as_gpios}) zephyr_library_compile_definitions(CONFIG_NFCT_PINS_AS_GPIOS) From fc7f82d468f64955083d0e8ed307965020c70326 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Thu, 28 Sep 2023 15:56:08 +0200 Subject: [PATCH 0316/1623] [nrf fromtree] dts: arm: nordic: Add support for ieee802154 in the nRF52820 radio The nRF52820 radio peripheral supports IEEE 802.15.4, add the required property and node to reflect this. See https://infocenter.nordicsemi.com/topic/ps_nrf52820/radio.html?cp=5_3_0_5_11 Signed-off-by: Carles Cufi (cherry picked from commit f39944933d8a3aa8761711e788cabfc07117377d) (cherry picked from commit 281acd0dacaa20711d68cbdabae48ebf76264b87) --- dts/arm/nordic/nrf52820.dtsi | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dts/arm/nordic/nrf52820.dtsi b/dts/arm/nordic/nrf52820.dtsi index 6d2f5eb02fe..c3d05fc6ec1 100644 --- a/dts/arm/nordic/nrf52820.dtsi +++ b/dts/arm/nordic/nrf52820.dtsi @@ -88,9 +88,15 @@ interrupts = <1 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; dfe-supported; + ieee802154-supported; ble-2mbps-supported; ble-coded-phy-supported; tx-high-power-supported; + + ieee802154: ieee802154 { + compatible = "nordic,nrf-ieee802154"; + status = "disabled"; + }; }; uart0: uart@40002000 { From 93c996c9b8653daee0e15d94ff81b8369d9efdeb Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Tue, 17 Oct 2023 09:35:58 +0200 Subject: [PATCH 0317/1623] [nrf fromlist] manifest: update hal_nordic to fix nRF52820 nrfx_gpiote New hal_nordic revision contains updated nrfx with a fix to GPIOTE driver array out-of-bounds access on nRF52820. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/64014 Signed-off-by: Nikodem Kastelik (cherry picked from commit ed0fc63d8fb4eeb2094ae802259bc87e8a88f5d1) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index f5366678a0e..909800d0aab 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 568a5e90b858a2e5b640b3fe6ab9b59dd2ce9f7f + revision: 427ee1a519e8a0844d0f78f7cbc8cdfc134ef00d path: modules/hal/nordic groups: - hal From d78ae6b7ad3e60ef3a63ad7b6e1ea8a01eb3f963 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 12 Oct 2023 16:07:08 +0200 Subject: [PATCH 0318/1623] [nrf fromlist] tests: bluetooth: tester: Fix BLOB server model pointer PTS uses BLOB server model instantiated by DFD server for MBT tests as it is the first BLOB server model in the device composition data. DFU server, which also has BLOB server model, is instantiated after DFD server. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63904 Signed-off-by: Pavel Vasilyev (cherry picked from commit 83bc1016752ca2a678683f538afba51740fe0880) --- tests/bluetooth/tester/src/btp_mesh.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index c43f19f04ce..5eff344540e 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -4468,10 +4468,10 @@ static uint8_t blob_srv_recv(const void *cmd, uint16_t cmd_len, struct model_data *model_bound; int err; -#if defined(CONFIG_BT_MESH_DFU_SRV) - struct bt_mesh_blob_srv *srv = &dfu_srv.blob; -#elif defined(CONFIG_BT_MESH_DFD_SRV) +#if defined(CONFIG_BT_MESH_DFD_SRV) struct bt_mesh_blob_srv *srv = &dfd_srv.upload.blob; +#elif defined(CONFIG_BT_MESH_DFU_SRV) + struct bt_mesh_blob_srv *srv = &dfu_srv.blob; #endif model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_SRV); From 834948da4a87ff41241bd325d685e4e474f511f4 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Mon, 16 Oct 2023 13:19:29 +0200 Subject: [PATCH 0319/1623] [nrf fromlist] Bluetooth: Mesh: Keep sending Partial Block Report message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the BLOB server is in Pull mode and all chunks were received for the current block, and the current block is the last block, then according to section 5.2.4 of MshMBTv1.0 the server should stop sending BLOB Partial Block Report messages if it determines that the client knows that the transfer is complete: ``` While the Pull BLOB State Machine is in the All Chunks Received state, the Pull BLOB State Machine continues to send the BLOB Partial Block Report messages until one of the following happens: • The Receive BLOB Timeout timer expires. • If the current block is not the last block, then the client starts a new block, in which case a new Pull BLOB State Machine is instantiated. • If the current block is the last block, then the server determines that the client knows the transfer is complete. For example, a higher-layer model may indicate that the client considers the transfer complete. ``` We currently don't have any OOB mean (for example, API) to determine whether the client knows that the transfer is complete. We also need to keep in mind that the Partial Block Report message can get lost so one transmission may not be enough. The client could immediately send BLOB Transfer Get message to get the transfer status, but this goes against its state machine defined in section 6.2.4.2, where a Block transmission completes when a BLOB Partial Block Report message is received with an empty list of requested chunks (table 6.4, figure 6.1). Because of this, we need to keep sending Partial Block Report messages. We can keep sending them at least until Block Report timer expires. If the client sends BLOB Transfer Get message, then it finished with sending the block and we can change the phase and finish the transfer. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63904 Signed-off-by: Pavel Vasilyev (cherry picked from commit 7bd44ad937d2beb38246385c96361b4979ec7f33) --- subsys/bluetooth/mesh/blob_srv.c | 70 +++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/subsys/bluetooth/mesh/blob_srv.c b/subsys/bluetooth/mesh/blob_srv.c index 56a89472ea6..1e6cb9bc91a 100644 --- a/subsys/bluetooth/mesh/blob_srv.c +++ b/subsys/bluetooth/mesh/blob_srv.c @@ -251,6 +251,37 @@ static void resume(struct bt_mesh_blob_srv *srv) reset_timer(srv); } +static void end(struct bt_mesh_blob_srv *srv) +{ + phase_set(srv, BT_MESH_BLOB_XFER_PHASE_COMPLETE); + k_work_cancel_delayable(&srv->rx_timeout); + k_work_cancel_delayable(&srv->pull.report); + io_close(srv); + erase_state(srv); + + if (srv->cb && srv->cb->end) { + srv->cb->end(srv, srv->state.xfer.id, true); + } +} + +static bool all_blocks_received(struct bt_mesh_blob_srv *srv) +{ + for (int i = 0; i < ARRAY_SIZE(srv->state.blocks); ++i) { + if (srv->state.blocks[i]) { + return false; + } + } + + return true; +} + +static bool pull_mode_xfer_complete(struct bt_mesh_blob_srv *srv) +{ + return srv->state.xfer.mode == BT_MESH_BLOB_XFER_MODE_PULL && + srv->phase == BT_MESH_BLOB_XFER_PHASE_WAITING_FOR_CHUNK && + all_blocks_received(srv); +} + static void timeout(struct k_work *work) { struct bt_mesh_blob_srv *srv = @@ -260,6 +291,8 @@ static void timeout(struct k_work *work) if (srv->phase == BT_MESH_BLOB_XFER_PHASE_WAITING_FOR_START) { cancel(srv); + } else if (pull_mode_xfer_complete(srv)) { + end(srv); } else { suspend(srv); } @@ -388,6 +421,15 @@ static int handle_xfer_get(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ct struct bt_mesh_blob_srv *srv = mod->user_data; LOG_DBG(""); + + if (pull_mode_xfer_complete(srv)) { + /* The client requested transfer. If we are in Pull mode and all blocks were + * received, we should change the Transfer state here to Complete so that the client + * receives the correct state. + */ + end(srv); + } + xfer_status_rsp(srv, ctx, BT_MESH_BLOB_SUCCESS); return 0; @@ -685,7 +727,7 @@ static int handle_chunk(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, struct bt_mesh_blob_chunk chunk; size_t expected_size = 0; uint16_t idx; - int i, err; + int err; idx = net_buf_simple_pull_le16(buf); chunk.size = buf->len; @@ -745,26 +787,26 @@ static int handle_chunk(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, atomic_clear_bit(srv->state.blocks, srv->block.number); - for (i = 0; i < ARRAY_SIZE(srv->state.blocks); ++i) { - if (!srv->state.blocks[i]) { - continue; - } - + if (!all_blocks_received(srv)) { phase_set(srv, BT_MESH_BLOB_XFER_PHASE_WAITING_FOR_BLOCK); store_state(srv); return 0; } - phase_set(srv, BT_MESH_BLOB_XFER_PHASE_COMPLETE); - k_work_cancel_delayable(&srv->rx_timeout); - k_work_cancel_delayable(&srv->pull.report); - io_close(srv); - erase_state(srv); - - if (srv->cb && srv->cb->end) { - srv->cb->end(srv, srv->state.xfer.id, true); + if (srv->state.xfer.mode == BT_MESH_BLOB_XFER_MODE_PULL) { + /* By spec (section 5.2.4), the BLOB Server stops sending BLOB Partial Block Report + * messages "If the current block is the last block, then the server determines that + * the client knows the transfer is complete. For example, a higher-layer model may + * indicate that the client considers the transfer complete." + * + * We don't have any way for higher-layer model to indicate that the transfer is + * complete. Therefore we need to keep sending Partial Block Report messages until + * the client sends BLOB Transfer Get message or the Block Timer expires. + */ + return 0; } + end(srv); return 0; } From 66324255acd8c12723aaf62b8a61c2e1fb17c8f5 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Wed, 18 Oct 2023 12:55:20 +0200 Subject: [PATCH 0320/1623] [nrf fromlist] tests: bluetooth: tester: Allow to compile mesh without LPN This can be needed to qualify features without LPN support. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63904 Signed-off-by: Pavel Vasilyev (cherry picked from commit 1866de22ccdd68a369470156839e3f0f18f51339) --- subsys/bluetooth/host/testing.c | 2 ++ tests/bluetooth/tester/src/btp_mesh.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/subsys/bluetooth/host/testing.c b/subsys/bluetooth/host/testing.c index c3121fd230d..3c118c51e0f 100644 --- a/subsys/bluetooth/host/testing.c +++ b/subsys/bluetooth/host/testing.c @@ -102,6 +102,7 @@ void bt_test_mesh_trans_incomp_timer_exp(void) } } +#if defined(CONFIG_BT_MESH_LOW_POWER) int bt_test_mesh_lpn_group_add(uint16_t group) { bt_mesh_lpn_group_add(group); @@ -115,6 +116,7 @@ int bt_test_mesh_lpn_group_remove(uint16_t *groups, size_t groups_count) return 0; } +#endif /* CONFIG_BT_MESH_LOW_POWER */ int bt_test_mesh_rpl_clear(void) { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 5eff344540e..bdc37c2f2e5 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1553,6 +1553,7 @@ static uint8_t ivu_toggle_state(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } +#if defined(CONFIG_BT_MESH_LOW_POWER) static uint8_t lpn(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -1584,6 +1585,7 @@ static uint8_t lpn_poll(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } +#endif /* CONFIG_BT_MESH_LOW_POWER */ static uint8_t net_send(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -1765,6 +1767,7 @@ static uint8_t model_send(const void *cmd, uint16_t cmd_len, } #if defined(CONFIG_BT_TESTING) +#if defined(CONFIG_BT_MESH_LOW_POWER) static uint8_t lpn_subscribe(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -1800,6 +1803,7 @@ static uint8_t lpn_unsubscribe(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } +#endif /* CONFIG_BT_MESH_LOW_POWER */ static uint8_t rpl_clear(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -4579,6 +4583,7 @@ static const struct btp_handler handlers[] = { .expect_len = 0, .func = ivu_toggle_state, }, +#if defined(CONFIG_BT_MESH_LOW_POWER) { .opcode = BTP_MESH_LPN, .expect_len = sizeof(struct btp_mesh_lpn_set_cmd), @@ -4589,6 +4594,7 @@ static const struct btp_handler handlers[] = { .expect_len = 0, .func = lpn_poll, }, +#endif /* CONFIG_BT_MESH_LOW_POWER */ { .opcode = BTP_MESH_NET_SEND, .expect_len = BTP_HANDLER_LENGTH_VARIABLE, @@ -4900,6 +4906,7 @@ static const struct btp_handler handlers[] = { .func = va_del, }, #if defined(CONFIG_BT_TESTING) +#if defined(CONFIG_BT_MESH_LOW_POWER) { .opcode = BTP_MESH_LPN_SUBSCRIBE, .expect_len = sizeof(struct btp_mesh_lpn_subscribe_cmd), @@ -4910,6 +4917,7 @@ static const struct btp_handler handlers[] = { .expect_len = sizeof(struct btp_mesh_lpn_unsubscribe_cmd), .func = lpn_unsubscribe, }, +#endif /* CONFIG_BT_MESH_LOW_POWER */ { .opcode = BTP_MESH_RPL_CLEAR, .expect_len = 0, From 979569b82b96246889e67a17a4a7987710c4802e Mon Sep 17 00:00:00 2001 From: Ludvig Jordet Date: Tue, 17 Oct 2023 15:37:44 +0200 Subject: [PATCH 0321/1623] [nrf fromlist] Bluetooth: Mesh: Fix issue where dfu_cli could get stuck This fixes an issue where the DFU client could get stuck trying to transmit a message to servers if the DFU client was misconfigured, for instance missing application key or network key. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/64034 Signed-off-by: Ludvig Jordet (cherry picked from commit 0e9155dc6d3358376d8b3bb7c00b4a408d9206f1) --- subsys/bluetooth/mesh/dfu_cli.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/mesh/dfu_cli.c b/subsys/bluetooth/mesh/dfu_cli.c index 3805a04e450..4db7779116b 100644 --- a/subsys/bluetooth/mesh/dfu_cli.c +++ b/subsys/bluetooth/mesh/dfu_cli.c @@ -305,6 +305,23 @@ static void tx_end(int err, void *cb_data) blob_cli_broadcast_tx_complete(&cli->blob); } +static int tx(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, + const struct bt_mesh_send_cb *cb, struct bt_mesh_dfu_cli *cli) +{ + int err; + + err = bt_mesh_model_send(mod, ctx, buf, cb, cli); + if (err) { + LOG_ERR("Send err: %d", err); + if (cb) { + cb->end(err, cli); + } + return err; + } + + return 0; +} + static int info_get(struct bt_mesh_dfu_cli *cli, struct bt_mesh_msg_ctx *ctx, uint8_t idx, uint8_t max_count, const struct bt_mesh_send_cb *cb) @@ -314,7 +331,7 @@ static int info_get(struct bt_mesh_dfu_cli *cli, struct bt_mesh_msg_ctx *ctx, net_buf_simple_add_u8(&buf, idx); net_buf_simple_add_u8(&buf, max_count); - return bt_mesh_model_send(cli->mod, ctx, &buf, cb, cli); + return tx(cli->mod, ctx, &buf, cb, cli); } static void send_info_get(struct bt_mesh_blob_cli *b, uint16_t dst) @@ -352,7 +369,7 @@ static void send_update_start(struct bt_mesh_blob_cli *b, uint16_t dst) net_buf_simple_add_mem(&buf, cli->xfer.slot->metadata, cli->xfer.slot->metadata_len); - bt_mesh_model_send(cli->mod, &ctx, &buf, &send_cb, cli); + (void)tx(cli->mod, &ctx, &buf, &send_cb, cli); } static void send_update_get(struct bt_mesh_blob_cli *b, uint16_t dst) @@ -363,7 +380,7 @@ static void send_update_get(struct bt_mesh_blob_cli *b, uint16_t dst) BT_MESH_MODEL_BUF_DEFINE(buf, BT_MESH_DFU_OP_UPDATE_GET, 0); bt_mesh_model_msg_init(&buf, BT_MESH_DFU_OP_UPDATE_GET); - bt_mesh_model_send(cli->mod, &ctx, &buf, &send_cb, cli); + (void)tx(cli->mod, &ctx, &buf, &send_cb, cli); } static void send_update_cancel(struct bt_mesh_blob_cli *b, uint16_t dst) @@ -374,7 +391,7 @@ static void send_update_cancel(struct bt_mesh_blob_cli *b, uint16_t dst) BT_MESH_MODEL_BUF_DEFINE(buf, BT_MESH_DFU_OP_UPDATE_CANCEL, 0); bt_mesh_model_msg_init(&buf, BT_MESH_DFU_OP_UPDATE_CANCEL); - bt_mesh_model_send(cli->mod, &ctx, &buf, &send_cb, cli); + (void)tx(cli->mod, &ctx, &buf, &send_cb, cli); } static void send_update_apply(struct bt_mesh_blob_cli *b, uint16_t dst) @@ -385,7 +402,7 @@ static void send_update_apply(struct bt_mesh_blob_cli *b, uint16_t dst) BT_MESH_MODEL_BUF_DEFINE(buf, BT_MESH_DFU_OP_UPDATE_APPLY, 0); bt_mesh_model_msg_init(&buf, BT_MESH_DFU_OP_UPDATE_APPLY); - bt_mesh_model_send(cli->mod, &ctx, &buf, &send_cb, cli); + (void)tx(cli->mod, &ctx, &buf, &send_cb, cli); } /******************************************************************************* From 32a51d982e0b7eba7e458678a8246440b25c3916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Wed, 18 Oct 2023 09:11:23 +0200 Subject: [PATCH 0322/1623] [nrf fromlist] Bluetooth: mesh: update model extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a goto statement to ensure that model extensions are registered in Composition Data Page 1 if it is enabled. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/64065 Signed-off-by: Håvard Reierstad (cherry picked from commit 24edc9d74bad637452bceb9322b3b6f1611db4cb) --- subsys/bluetooth/mesh/access.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 63c4f76c392..6ca7dbe580b 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -1678,7 +1678,7 @@ int bt_mesh_model_extend(struct bt_mesh_model *extending_mod, struct bt_mesh_mod /* Check if a's list contains b */ for (it = a; (it != NULL) && (it->next != a); it = it->next) { if (it == b) { - return 0; + goto register_extension; } } @@ -1695,7 +1695,7 @@ int bt_mesh_model_extend(struct bt_mesh_model *extending_mod, struct bt_mesh_mod a->next = b; } - +register_extension: if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { return mod_rel_register(base_mod, extending_mod, RELATION_TYPE_EXT); } From 7ac418187369487f6fa633dab6d6c0a99913f479 Mon Sep 17 00:00:00 2001 From: Omkar Kulkarni Date: Mon, 23 Oct 2023 14:07:48 +0200 Subject: [PATCH 0323/1623] [nrf fromlist] Bluetooth: Mesh: FU Server should not update internal state on error According to conditions in the DFU spec section 6.1.3.7 (Sending a Firmware Update Status message) and in 'Idempotency' part of section 6.1.3.4 (Receiving a Firmware Update Start message), the FU Server should not update internal state when 'Wrong Phase' error condition is triggered. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/64258 Signed-off-by: Omkar Kulkarni (cherry picked from commit b4eef4da68a5c1f4b02c4d10ee0340375f775a14) --- subsys/bluetooth/mesh/dfu_srv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/dfu_srv.c b/subsys/bluetooth/mesh/dfu_srv.c index 282a40074c9..462a777b46c 100644 --- a/subsys/bluetooth/mesh/dfu_srv.c +++ b/subsys/bluetooth/mesh/dfu_srv.c @@ -302,10 +302,10 @@ static int handle_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, status = BT_MESH_DFU_ERR_WRONG_PHASE; } else { status = BT_MESH_DFU_SUCCESS; + srv->update.ttl = ttl; + srv->blob.state.xfer.id = blob_id; } - srv->update.ttl = ttl; - srv->blob.state.xfer.id = blob_id; LOG_WRN("Busy. Phase: %u", srv->update.phase); goto rsp; } From 2e2523efe52a7ac89f0567b8798fd857b1e71ae3 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 9 Oct 2023 23:01:41 +0200 Subject: [PATCH 0324/1623] [nrf fromtree] tests: bluetooth: tester: Fix GATT read multiple Pass only speficied number of handler to read_params for GATT read multiple. This is to avoid sending invalid (zeros) handles in ATT_READ_MULTIPLE_REQ. This was affecting GATT/CL/GAR/BI-18-C and GATT/CL/GAR/BI-19-C qualification test cases. Signed-off-by: Szymon Janc (cherry picked from commit 4f57614cbddc66dbe264691352fe07223e3974e0) --- tests/bluetooth/tester/src/btp_gatt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index 4d046cc3aad..6509ca7fe4b 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -1651,11 +1651,11 @@ static uint8_t read_multiple(const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } - if (cp->handles_count > ARRAY_SIZE(handles)) { + if (cp->handles_count == 0 || cp->handles_count > ARRAY_SIZE(handles)) { return BTP_STATUS_FAILED; } - for (i = 0; i < ARRAY_SIZE(handles); i++) { + for (i = 0; i < cp->handles_count; i++) { handles[i] = sys_le16_to_cpu(cp->handles[i]); } @@ -1670,7 +1670,7 @@ static uint8_t read_multiple(const void *cmd, uint16_t cmd_len, } read_params.func = read_cb; - read_params.handle_count = i; + read_params.handle_count = cp->handles_count; read_params.multiple.handles = handles; /* not used in read func */ read_params.multiple.variable = false; read_params.chan_opt = BT_ATT_CHAN_OPT_NONE; From e806eda100b0d197eeb28be7716a0a4ed974cebf Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 16 Oct 2023 08:40:38 +0100 Subject: [PATCH 0325/1623] [nrf noup] samples: bluetooth: hci_pow_ctrl: Migrate child image config Migrates child image configuration for this sample over to sysbuild Signed-off-by: Jamie McCrae --- samples/bluetooth/hci_pwr_ctrl/sysbuild/hci_rpmsg.conf | 1 + 1 file changed, 1 insertion(+) create mode 100644 samples/bluetooth/hci_pwr_ctrl/sysbuild/hci_rpmsg.conf diff --git a/samples/bluetooth/hci_pwr_ctrl/sysbuild/hci_rpmsg.conf b/samples/bluetooth/hci_pwr_ctrl/sysbuild/hci_rpmsg.conf new file mode 100644 index 00000000000..e6749ae6399 --- /dev/null +++ b/samples/bluetooth/hci_pwr_ctrl/sysbuild/hci_rpmsg.conf @@ -0,0 +1 @@ +CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y From cb74dbeb3cb753bade9864233eb27bf229298e77 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 16 Oct 2023 08:41:27 +0100 Subject: [PATCH 0326/1623] [nrf noup] samples: mgmt: mcumgr smp_svr: Migrate child image config Migrates child image configuration for this sample over to sysbuild Signed-off-by: Jamie McCrae --- .../subsys/mgmt/mcumgr/smp_svr/sysbuild/hci_rpmsg.conf | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 samples/subsys/mgmt/mcumgr/smp_svr/sysbuild/hci_rpmsg.conf diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/sysbuild/hci_rpmsg.conf b/samples/subsys/mgmt/mcumgr/smp_svr/sysbuild/hci_rpmsg.conf new file mode 100644 index 00000000000..98260877332 --- /dev/null +++ b/samples/subsys/mgmt/mcumgr/smp_svr/sysbuild/hci_rpmsg.conf @@ -0,0 +1,10 @@ +# +# Copyright (c) 2022 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 +# + +CONFIG_BT_MAX_CONN=2 +CONFIG_BT_BUF_ACL_RX_SIZE=502 +CONFIG_BT_BUF_ACL_TX_SIZE=502 +CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 From 9058a859d67b19c9d307943d8f206d917a37752a Mon Sep 17 00:00:00 2001 From: Krishna T Date: Tue, 21 Mar 2023 21:25:45 +0530 Subject: [PATCH 0327/1623] [nrf fromtree] scripts: ci: Fix for compliance with multi-user machine If in a server multiple users are running compliance then it throws errors as the filename "Kconfig.modules" and "Kconfig.dts" is owned by someone else. Fix this by creating a randomized Kconfig file and delete after use. Signed-off-by: Krishna T (cherry picked from commit 85e3a4ca6ae1993be975317515ee431dca02aae1) --- scripts/ci/check_compliance.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 74ddf19b2fb..1499d92eaf9 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -16,6 +16,7 @@ import tempfile import traceback import shlex +import shutil from yamllint import config, linter @@ -369,6 +370,8 @@ def parse_kconfig(self): if not os.path.exists(kconfig_path): self.error(kconfig_path + " not found") + kconfiglib_dir = tempfile.mkdtemp(prefix="kconfiglib_") + sys.path.insert(0, kconfig_path) # Import globally so that e.g. kconfiglib.Symbol can be referenced in # tests @@ -383,7 +386,7 @@ def parse_kconfig(self): os.environ["ARCH_DIR"] = "arch/" os.environ["BOARD_DIR"] = "boards/*/*" os.environ["ARCH"] = "*" - os.environ["KCONFIG_BINARY_DIR"] = tempfile.gettempdir() + os.environ["KCONFIG_BINARY_DIR"] = kconfiglib_dir os.environ['DEVICETREE_CONF'] = "dummy" os.environ['TOOLCHAIN_HAS_NEWLIB'] = "y" @@ -392,10 +395,9 @@ def parse_kconfig(self): os.environ["GENERATED_DTS_BOARD_CONF"] = "dummy" # For multi repo support - self.get_modules(os.path.join(tempfile.gettempdir(), "Kconfig.modules")) - + self.get_modules(os.path.join(kconfiglib_dir, "Kconfig.modules")) # For Kconfig.dts support - self.get_kconfig_dts(os.path.join(tempfile.gettempdir(), "Kconfig.dts")) + self.get_kconfig_dts(os.path.join(kconfiglib_dir, "Kconfig.dts")) # Tells Kconfiglib to generate warnings for all references to undefined # symbols within Kconfig files @@ -410,6 +412,9 @@ def parse_kconfig(self): except kconfiglib.KconfigError as e: self.failure(str(e)) raise EndTest + finally: + # Clean up the temporary directory + shutil.rmtree(kconfiglib_dir) def get_defined_syms(self, kconf): # Returns a set() with the names of all defined Kconfig symbols (with no From 4936f55987b49cedd92288f686410f374ed345d2 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 17 Jul 2023 14:46:45 +0100 Subject: [PATCH 0328/1623] [nrf fromtree] sysbuild: Add support for MCUboot/app encryption keys Adds support for controlling the MCUboot (and application) signing key, and allows for generating encrypted updates. Signed-off-by: Jamie McCrae (cherry picked from commit 62f07c67d5689155c5bf649ac8653309e7f8bbad) --- .../MAIN_image_default.cmake | 3 +++ .../sysbuild/images/bootloader/CMakeLists.txt | 4 ++++ share/sysbuild/images/bootloader/Kconfig | 20 +++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/share/sysbuild/image_configurations/MAIN_image_default.cmake b/share/sysbuild/image_configurations/MAIN_image_default.cmake index a6bd72d7d1a..a2ae840ef97 100644 --- a/share/sysbuild/image_configurations/MAIN_image_default.cmake +++ b/share/sysbuild/image_configurations/MAIN_image_default.cmake @@ -9,6 +9,9 @@ set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOTLOADER_MCUBOOT "${SB_CONFIG_BOO set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_SIGNATURE_KEY_FILE "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}" ) +set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE + "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}" +) if(SB_CONFIG_BOOTLOADER_MCUBOOT) if("${SB_CONFIG_SIGNATURE_TYPE}" STREQUAL "NONE") diff --git a/share/sysbuild/images/bootloader/CMakeLists.txt b/share/sysbuild/images/bootloader/CMakeLists.txt index c00a8e97783..2a0f12f958d 100644 --- a/share/sysbuild/images/bootloader/CMakeLists.txt +++ b/share/sysbuild/images/bootloader/CMakeLists.txt @@ -15,4 +15,8 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT) sysbuild_add_dependencies(FLASH ${DEFAULT_IMAGE} ${image}) set_config_string(${image} CONFIG_BOOT_SIGNATURE_KEY_FILE "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}") + set_config_bool(${image} CONFIG_BOOT_ENCRYPT_IMAGE "${SB_CONFIG_BOOT_ENCRYPTION}") + if(SB_CONFIG_BOOT_ENCRYPTION) + set_config_string(${image} CONFIG_BOOT_ENCRYPTION_KEY_FILE "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}") + endif() endif() diff --git a/share/sysbuild/images/bootloader/Kconfig b/share/sysbuild/images/bootloader/Kconfig index 19924a6ca18..e8c788f72c5 100644 --- a/share/sysbuild/images/bootloader/Kconfig +++ b/share/sysbuild/images/bootloader/Kconfig @@ -56,12 +56,28 @@ config BOOT_SIGNATURE_TYPE_ED25519 endchoice config BOOT_SIGNATURE_KEY_FILE - string "PEM key file" + string "Signing PEM key file" default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-ec-p256.pem" if BOOT_SIGNATURE_TYPE_ECDSA_P256 default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-ed25519.pem" if BOOT_SIGNATURE_TYPE_ED25519 default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-rsa-2048.pem" if BOOT_SIGNATURE_TYPE_RSA default "" help - Absolute path to key file to use with MCUBoot. + Absolute path to signing key file to use with MCUBoot. + +config BOOT_ENCRYPTION + bool "Encrypted image support" + depends on !BOOT_SIGNATURE_TYPE_NONE + help + Support encrypted images. + +config BOOT_ENCRYPTION_KEY_FILE + string "Encryption PEM key file" + depends on BOOT_ENCRYPTION + default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/enc-ec256-priv.pem" if BOOT_SIGNATURE_TYPE_ECDSA_P256 + default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/enc-x25519-priv.pem" if BOOT_SIGNATURE_TYPE_ED25519 + default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/enc-rsa2048-priv.pem" if BOOT_SIGNATURE_TYPE_RSA + default "" + help + Absolute path to encryption key file to use with MCUBoot. endif From 335beb0032206badd6cef214bbd82cdc0c51d49f Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 17 Jul 2023 14:54:22 +0100 Subject: [PATCH 0329/1623] [nrf fromtree] scripts: ci: check_compliance: Add sysbuild Kconfig exceptions Adds exceptions for Kconfigs which sysbuild uses when configuring MCUboot. Signed-off-by: Jamie McCrae (cherry picked from commit 97123c4f4a558967b067a2da50bc72c5f2fdb48a) --- scripts/ci/check_compliance.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 1499d92eaf9..07d7431dd65 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -633,6 +633,8 @@ def check_no_undef_outside_kconfig(self, kconf): # toolchain Kconfig which is sourced based on # Zephyr toolchain variant and therefore not # visible to compliance. + "BOOT_ENCRYPTION_KEY_FILE", # Used in sysbuild + "BOOT_ENCRYPT_IMAGE", # Used in sysbuild "BOOT_UPGRADE_ONLY", # Used in example adjusting MCUboot config, but # symbol is defined in MCUboot itself. "BOOT_SERIAL_BOOT_MODE", # Used in (sysbuild-based) test/ From 2a12aea553568d2b1683c2b329f0ac648661110a Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Tue, 3 Oct 2023 16:04:43 +0200 Subject: [PATCH 0330/1623] [nrf fromtree] manifest: hal_nordic: Update hal_nordic revision Pull in nrfx 3.2.0 release Signed-off-by: Nikodem Kastelik (cherry picked from commit ec978348c5ea8e5a2a0f071cc6e6ca8e12fa8889) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 909800d0aab..44098dac030 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 427ee1a519e8a0844d0f78f7cbc8cdfc134ef00d + revision: 2ff8ce6e6ca131d87699dba260f3c0cc4a6cc365 path: modules/hal/nordic groups: - hal From 7931877e976a0a2a47a99a7701e7e1930b2bde0d Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Tue, 3 Oct 2023 17:17:22 +0200 Subject: [PATCH 0331/1623] [nrf fromtree] manifest: tf-m: update to have atomics for nrfx port Refactored nrfx_uarte driver uses atomic types internally, so glue layer in TF-M needs to include them. Signed-off-by: Nikodem Kastelik (cherry picked from commit f4fcc1dc4c6303b21b7fb8c3f2a346aeef8ebcaf) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 44098dac030..1847e94b37c 100644 --- a/west.yml +++ b/west.yml @@ -331,7 +331,7 @@ manifest: groups: - debug - name: trusted-firmware-m - revision: 8b6146261fe2c0ad61154e20c7e338601eae2208 + revision: 33c0f47bcb19721a5c33e6fe1eee9225d00bb5bc path: modules/tee/tf-m/trusted-firmware-m groups: - tee From 82e15a98880869aa4a80c2104988480330d8d326 Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Tue, 3 Oct 2023 16:52:55 +0200 Subject: [PATCH 0332/1623] [nrf fromtree] drivers: sensor: qdec_nrfx: Revert samplerdy workaround Underlying nrfx driver was modified so now it forwards the event to the user callback only if it was enabled. Signed-off-by: Nikodem Kastelik (cherry picked from commit 6a315a4b17c523f101a01fccde50967c02294650) --- drivers/sensor/qdec_nrfx/qdec_nrfx.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/sensor/qdec_nrfx/qdec_nrfx.c b/drivers/sensor/qdec_nrfx/qdec_nrfx.c index 81c3614fc05..b11ce70fb9c 100644 --- a/drivers/sensor/qdec_nrfx/qdec_nrfx.c +++ b/drivers/sensor/qdec_nrfx/qdec_nrfx.c @@ -135,13 +135,6 @@ static void qdec_nrfx_event_handler(nrfx_qdec_event_t event, void *p_context) unsigned int key; switch (event.type) { - case NRF_QDEC_EVENT_SAMPLERDY: - /* The underlying HAL driver may improperly forward an samplerdy event even if it's - * disabled in the configuration. Ignore the event to prevent error logs until the - * issue is fixed in HAL. - */ - break; - case NRF_QDEC_EVENT_REPORTRDY: accumulate(dev_data, event.data.report.acc); From 2831d726ec09ce354fca9ff83382f8bf94bfefb5 Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Tue, 3 Oct 2023 16:59:20 +0200 Subject: [PATCH 0333/1623] [nrf fromtree] soc: arm: nordic_nrf: nrf53: align nrf_regulators Now more generic regulators API is available. Signed-off-by: Nikodem Kastelik (cherry picked from commit f3f2c113d1323fa0a82d30a9f1cb957b87fd185a) --- soc/arm/nordic_nrf/nrf53/soc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index 39d64d72cc2..3542ef3e914 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -554,13 +554,13 @@ static int nordicsemi_nrf53_init(void) #endif #if defined(CONFIG_SOC_DCDC_NRF53X_APP) - nrf_regulators_dcdcen_set(NRF_REGULATORS, true); + nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_MAIN, true); #endif #if defined(CONFIG_SOC_DCDC_NRF53X_NET) - nrf_regulators_dcdcen_radio_set(NRF_REGULATORS, true); + nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_RADIO, true); #endif #if defined(CONFIG_SOC_DCDC_NRF53X_HV) - nrf_regulators_dcdcen_vddh_set(NRF_REGULATORS, true); + nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_HIGH, true); #endif #if defined(CONFIG_SOC_NRF_GPIO_FORWARDER_FOR_NRF5340) From 7b453aac8b078f938eefff92e5d0b4d9f481adfb Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Tue, 3 Oct 2023 17:00:20 +0200 Subject: [PATCH 0334/1623] [nrf fromtree] samples: boards: nrf: nrfx_prs: align to new nrfx_uarte One of the nrfx_uarte event structure members was renamed, so the sample code has to be aligned. Signed-off-by: Nikodem Kastelik (cherry picked from commit c0ff691a3ca66a6eae56e7d03c2382f27e4b0281) --- samples/boards/nrf/nrfx_prs/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/boards/nrf/nrfx_prs/src/main.c b/samples/boards/nrf/nrfx_prs/src/main.c index 618c0718143..934bbbe834d 100644 --- a/samples/boards/nrf/nrfx_prs/src/main.c +++ b/samples/boards/nrf/nrfx_prs/src/main.c @@ -191,7 +191,7 @@ static bool spim_transfer(const uint8_t *tx_data, size_t tx_data_len, static void uarte_handler(const nrfx_uarte_event_t *p_event, void *p_context) { if (p_event->type == NRFX_UARTE_EVT_RX_DONE) { - received = p_event->data.rx.bytes; + received = p_event->data.rx.length; k_sem_give(&transfer_finished); } else if (p_event->type == NRFX_UARTE_EVT_ERROR) { received = 0; From bc160058effb4a887acbad987ff44cf6b7db3494 Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Fri, 6 Oct 2023 09:55:58 +0200 Subject: [PATCH 0335/1623] [nrf fromtree] modules: hal_nordic: nrfx: enable GPIOTE1 for NS builds Now it is needed to explicitly use NRF_GPIOTE1 instance in nrfx_gpiote driver for non-secure builds. Signed-off-by: Nikodem Kastelik (cherry picked from commit 70db8cd12a794fa6f966c1e08a622ad5590a6880) --- modules/hal_nordic/nrfx/nrfx_config.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 4b7cabd7a98..29051ccf754 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -117,6 +117,12 @@ #ifdef CONFIG_NRFX_GPIOTE #define NRFX_GPIOTE_ENABLED 1 +#if (defined(CONFIG_SOC_SERIES_NRF91X) || defined(CONFIG_SOC_SERIES_NRF53X)) \ + && defined(NRF_TRUSTZONE_NONSECURE) +#define NRFX_GPIOTE1_ENABLED 1 +#else +#define NRFX_GPIOTE0_ENABLED 1 +#endif #endif #ifdef CONFIG_NRFX_GPIOTE_LOG #define NRFX_GPIOTE_CONFIG_LOG_ENABLED 1 From 729573484b5c74e6f4f83ccba5c63f80f96abad0 Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Mon, 9 Oct 2023 11:18:17 +0200 Subject: [PATCH 0336/1623] [nrf fromtree] soc: arm: nordic_nrf: align nrf_power calls to new scheme Now the API to manage GPREGRET register is unified for all devices having one or more GPREGRET entries. Signed-off-by: Nikodem Kastelik (cherry picked from commit a4cbe9e9c6f9efe37dcca13083b040172205a716) --- soc/arm/nordic_nrf/nrf51/soc.c | 2 +- soc/arm/nordic_nrf/nrf52/soc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf51/soc.c b/soc/arm/nordic_nrf/nrf51/soc.c index 078a422c06b..2b22c95679f 100644 --- a/soc/arm/nordic_nrf/nrf51/soc.c +++ b/soc/arm/nordic_nrf/nrf51/soc.c @@ -29,7 +29,7 @@ LOG_MODULE_REGISTER(soc); */ void sys_arch_reboot(int type) { - nrf_power_gpregret_set(NRF_POWER, (uint8_t)type); + nrf_power_gpregret_set(NRF_POWER, 0, (uint8_t)type); NVIC_SystemReset(); } #endif diff --git a/soc/arm/nordic_nrf/nrf52/soc.c b/soc/arm/nordic_nrf/nrf52/soc.c index 52b97164e72..5f310e5f945 100644 --- a/soc/arm/nordic_nrf/nrf52/soc.c +++ b/soc/arm/nordic_nrf/nrf52/soc.c @@ -31,7 +31,7 @@ LOG_MODULE_REGISTER(soc); */ void sys_arch_reboot(int type) { - nrf_power_gpregret_set(NRF_POWER, (uint8_t)type); + nrf_power_gpregret_set(NRF_POWER, 0, (uint8_t)type); NVIC_SystemReset(); } #endif From e73ebd314f6f8a8df179f11fd5f500522acc94e4 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Thu, 19 Oct 2023 10:59:03 +0200 Subject: [PATCH 0337/1623] [nrf fromtree] net: core: Set LL address on loopback packet In case packet is looped back to the stack, set LL address information on the packet, using the LL address set on the corresponding network interface, so that the information can be interpreted by the SOCK_DGRAM packet socket. Signed-off-by: Robert Lubos (cherry picked from commit dcf7b1905b9e2e3c4b277f6984d3fc166436d233) --- subsys/net/ip/net_core.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/subsys/net/ip/net_core.c b/subsys/net/ip/net_core.c index c94607b4485..1f6dac720af 100644 --- a/subsys/net/ip/net_core.c +++ b/subsys/net/ip/net_core.c @@ -211,6 +211,15 @@ static void init_rx_queues(void) /* Check if the IPv{4|6} addresses are proper. As this can be expensive, * make this optional. */ + +static inline void copy_ll_addr(struct net_pkt *pkt) +{ + memcpy(net_pkt_lladdr_src(pkt), net_pkt_lladdr_if(pkt), + sizeof(struct net_linkaddr)); + memcpy(net_pkt_lladdr_dst(pkt), net_pkt_lladdr_if(pkt), + sizeof(struct net_linkaddr)); +} + static inline int check_ip_addr(struct net_pkt *pkt) { uint8_t family = net_pkt_family(pkt); @@ -239,6 +248,9 @@ static inline int check_ip_addr(struct net_pkt *pkt) NET_IPV6_HDR(pkt)->dst); net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->dst, (uint8_t *)&addr); + net_pkt_set_ll_proto_type(pkt, ETH_P_IPV6); + copy_ll_addr(pkt); + return 1; } @@ -286,6 +298,9 @@ static inline int check_ip_addr(struct net_pkt *pkt) NET_IPV4_HDR(pkt)->dst); net_ipv4_addr_copy_raw(NET_IPV4_HDR(pkt)->dst, (uint8_t *)&addr); + net_pkt_set_ll_proto_type(pkt, ETH_P_IP); + copy_ll_addr(pkt); + return 1; } From 908794942947d049b61603b728f8f15af17e4873 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Thu, 19 Oct 2023 11:38:58 +0200 Subject: [PATCH 0338/1623] [nrf fromtree] net: shell: Fix unexpected timeout on loopback ping In case ping is sent to own address, the request is looped back to the stack and served before ping work had a chance to reschedule. In result, when the final ping reply has been server, and ping operation finalized with `ping_done()`, the work was rescheduled one last time, causing the ping timeout to be reported. Fix this by rescheduling the work before sending the actual request, so that the reply handler can cancel the work properly in such case. Signed-off-by: Robert Lubos (cherry picked from commit c6fd2b2d4492241a8e84421092f15d59db147d9e) --- subsys/net/ip/net_shell.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index e7af6e16632..87995ccabb3 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -4535,6 +4535,12 @@ static void ping_work(struct k_work *work) return; } + if (ctx->sequence < ctx->count) { + k_work_reschedule(&ctx->work, K_MSEC(ctx->interval)); + } else { + k_work_reschedule(&ctx->work, K_SECONDS(2)); + } + if (ctx->addr.family == AF_INET6) { ret = net_icmpv6_send_echo_request(ctx->iface, &ctx->addr.in6_addr, @@ -4560,12 +4566,6 @@ static void ping_work(struct k_work *work) ping_done(ctx); return; } - - if (ctx->sequence < ctx->count) { - k_work_reschedule(&ctx->work, K_MSEC(ctx->interval)); - } else { - k_work_reschedule(&ctx->work, K_SECONDS(2)); - } } #define ASCII_CTRL_C 0x03 From fabddf3a622625f39a71b9bb0377569e2fe230be Mon Sep 17 00:00:00 2001 From: Mariusz Poslinski Date: Thu, 26 Oct 2023 15:53:52 +0200 Subject: [PATCH 0339/1623] [nrf noup] testspec: remove HomeKit from NCS HomeKit Accessory Development Kit has been deprecated and removed from NCS. Signed-off-by: Mariusz Poslinski --- .github/test-spec.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 62b92e74d0f..c01ae703adf 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -131,17 +131,6 @@ "CI-rs-test": - "**/*" -"CI-homekit-test": - - "modules/openthread/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" - - "soc/arm/nordic_nrf/**/*" - - "subsys/net/**/*" - - "subsys/settings/**/*" - - any: - - "subsys/bluetooth/**/*" - - "!subsys/bluetooth/mesh/**/*" - - "!subsys/bluetooth/audio/**/*" - "CI-thread-test": - "include/zephyr/net/**/*" - "modules/mbedtls/**/*" From 5754cb6632da0d65c448362834f194ceb8b8493e Mon Sep 17 00:00:00 2001 From: Aleksander Wasaznik Date: Wed, 19 Jul 2023 15:35:12 +0200 Subject: [PATCH 0340/1623] [nrf fromtree] dts: bindings: Remove `reg` from `vnd,serial` `vnd,serial` is a virtual device which does not have an address. Signed-off-by: Aleksander Wasaznik (cherry picked from commit 0e83c66cefc5efe80675c0dcf13cfff5589d1fd0) --- dts/bindings/test/vnd,serial.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/dts/bindings/test/vnd,serial.yaml b/dts/bindings/test/vnd,serial.yaml index dc2327b4827..c2d931b0ed7 100644 --- a/dts/bindings/test/vnd,serial.yaml +++ b/dts/bindings/test/vnd,serial.yaml @@ -5,9 +5,6 @@ compatible: "vnd,serial" include: uart-controller.yaml properties: - reg: - required: true - baud-rate: type: int From 3c923c5a170c793f8d8582224e7d1c988237247b Mon Sep 17 00:00:00 2001 From: Aleksander Wasaznik Date: Wed, 19 Jul 2023 15:43:26 +0200 Subject: [PATCH 0341/1623] [nrf fromtree] drivers: serial_test: Implement interrupt and async APIs This allows testing code that uses the UART interrupt-driven API and UART asynchronous API. Signed-off-by: Aleksander Wasaznik (cherry picked from commit 4d926ac041cea9a1947390c8a34cb7906e3da30f) --- drivers/serial/serial_test.c | 319 +++++++++++++++++++++- include/zephyr/drivers/uart/serial_test.h | 2 +- 2 files changed, 318 insertions(+), 3 deletions(-) diff --git a/drivers/serial/serial_test.c b/drivers/serial/serial_test.c index 95e036e5992..2ce4fb50f38 100644 --- a/drivers/serial/serial_test.c +++ b/drivers/serial/serial_test.c @@ -9,12 +9,21 @@ * devices for the "vnd,serial" devicetree compatible used in test code. */ +#include + +#include #include #include #include #include +#include #include +LOG_MODULE_REGISTER(mock_serial, CONFIG_LOG_DEFAULT_LEVEL); + +BUILD_ASSERT(!IS_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN) || IS_ENABLED(CONFIG_RING_BUFFER)); +BUILD_ASSERT(!IS_ENABLED(CONFIG_UART_ASYNC_API) || IS_ENABLED(CONFIG_RING_BUFFER)); + #define DT_DRV_COMPAT vnd_serial struct serial_vnd_data { #ifdef CONFIG_RING_BUFFER @@ -23,8 +32,156 @@ struct serial_vnd_data { #endif serial_vnd_write_cb_t callback; void *callback_data; +#ifdef CONFIG_UART_INTERRUPT_DRIVEN + uart_irq_callback_user_data_t irq_isr; + bool irq_rx_enabled; + bool irq_tx_enabled; +#endif +#ifdef CONFIG_UART_ASYNC_API + uart_callback_t async_cb; + void *async_cb_user_data; + uint8_t *read_buf; + size_t read_size; + size_t read_position; +#endif }; +#ifdef CONFIG_UART_INTERRUPT_DRIVEN +static bool is_irq_rx_pending(const struct device *dev) +{ + struct serial_vnd_data *data = dev->data; + + return !ring_buf_is_empty(data->read_queue); +} + +static bool is_irq_tx_pending(const struct device *dev) +{ + struct serial_vnd_data *data = dev->data; + + return ring_buf_space_get(data->written) != 0; +} + +static void irq_process(const struct device *dev) +{ + struct serial_vnd_data *data = dev->data; + + for (;;) { + bool rx_rdy = is_irq_rx_pending(dev); + bool tx_rdy = is_irq_tx_pending(dev); + bool rx_int = rx_rdy && data->irq_rx_enabled; + bool tx_int = tx_rdy && data->irq_tx_enabled; + + LOG_DBG("rx_rdy %d tx_rdy %d", rx_rdy, tx_rdy); + LOG_DBG("rx_int %d tx_int %d", rx_int, tx_int); + + if (!(rx_int || tx_int)) { + break; + } + + LOG_DBG("isr"); + if (!data->irq_isr) { + LOG_ERR("no isr registered"); + break; + } + data->irq_isr(dev, NULL); + }; +} + +static void irq_rx_enable(const struct device *dev) +{ + struct serial_vnd_data *data = dev->data; + + data->irq_rx_enabled = true; + LOG_DBG("rx enabled"); + irq_process(dev); +} + +static void irq_rx_disable(const struct device *dev) +{ + struct serial_vnd_data *data = dev->data; + + data->irq_rx_enabled = false; + LOG_DBG("rx disabled"); +} + +static int irq_rx_ready(const struct device *dev) +{ + struct serial_vnd_data *data = dev->data; + bool ready = !ring_buf_is_empty(data->read_queue); + + LOG_DBG("rx ready: %d", ready); + return ready; +} + +static void irq_tx_enable(const struct device *dev) +{ + struct serial_vnd_data *data = dev->data; + + LOG_DBG("tx enabled"); + data->irq_tx_enabled = true; + irq_process(dev); +} + +static void irq_tx_disable(const struct device *dev) +{ + struct serial_vnd_data *data = dev->data; + + data->irq_tx_enabled = false; + LOG_DBG("tx disabled"); +} + +static int irq_tx_ready(const struct device *dev) +{ + struct serial_vnd_data *data = dev->data; + bool ready = (ring_buf_space_get(data->written) != 0); + + LOG_DBG("tx ready: %d", ready); + return ready; +} + +static void irq_callback_set(const struct device *dev, uart_irq_callback_user_data_t cb, + void *user_data) +{ + struct serial_vnd_data *data = dev->data; + + /* Not implemented. Ok because `user_data` is always NULL in the current + * implementation of core UART API. + */ + __ASSERT_NO_MSG(user_data == NULL); + +#if defined(CONFIG_UART_EXCLUSIVE_API_CALLBACKS) && defined(CONFIG_UART_ASYNC_API) + if (data->read_buf) { + LOG_ERR("Setting callback to NULL while asynchronous API is in use."); + } + data->async_cb = NULL; + data->async_cb_user_data = NULL; +#endif + + data->irq_isr = cb; + LOG_DBG("callback set"); +} + +static int fifo_fill(const struct device *dev, const uint8_t *tx_data, int size) +{ + struct serial_vnd_data *data = dev->data; + uint32_t write_len = ring_buf_put(data->written, tx_data, size); + + if (data->callback) { + data->callback(dev, data->callback_data); + } + return write_len; +} + +static int fifo_read(const struct device *dev, uint8_t *rx_data, const int size) +{ + struct serial_vnd_data *data = dev->data; + int read_len = ring_buf_get(data->read_queue, rx_data, size); + + LOG_HEXDUMP_DBG(rx_data, read_len, ""); + return read_len; +} +#endif /* CONFIG_UART_INTERRUPT_DRIVEN */ + static int serial_vnd_poll_in(const struct device *dev, unsigned char *c) { #ifdef CONFIG_RING_BUFFER @@ -59,15 +216,35 @@ static void serial_vnd_poll_out(const struct device *dev, unsigned char c) } } +#ifdef CONFIG_UART_ASYNC_API +static void async_rx_run(const struct device *dev); +#endif + #ifdef CONFIG_RING_BUFFER -int serial_vnd_queue_in_data(const struct device *dev, unsigned char *c, uint32_t size) +int serial_vnd_queue_in_data(const struct device *dev, const unsigned char *c, uint32_t size) { struct serial_vnd_data *data = dev->data; + int write_size; if (data == NULL || data->read_queue == NULL) { return -ENOTSUP; } - return ring_buf_put(data->read_queue, c, size); + write_size = ring_buf_put(data->read_queue, c, size); + + LOG_DBG("size %u write_size %u", size, write_size); + LOG_HEXDUMP_DBG(c, write_size, ""); + +#ifdef CONFIG_UART_INTERRUPT_DRIVEN + if (write_size > 0) { + irq_process(dev); + } +#endif + +#ifdef CONFIG_UART_ASYNC_API + async_rx_run(dev); +#endif + + return write_size; } uint32_t serial_vnd_out_data_size_get(const struct device *dev) @@ -130,6 +307,128 @@ static int serial_vnd_config_get(const struct device *dev, struct uart_config *c } #endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */ +#ifdef CONFIG_UART_ASYNC_API +static int serial_vnd_callback_set(const struct device *dev, uart_callback_t callback, + void *user_data) +{ + struct serial_vnd_data *data = dev->data; + + if (data == NULL) { + return -ENOTSUP; + } + +#if defined(CONFIG_UART_EXCLUSIVE_API_CALLBACKS) && defined(CONFIG_UART_INTERRUPT_DRIVEN) + data->irq_isr = cb; +#endif + + if (callback == NULL && data->read_buf) { + LOG_ERR("Setting callback to NULL while asynchronous API is in use."); + } + + data->async_cb = callback; + data->async_cb_user_data = user_data; + + return 0; +} + +static int serial_vnd_api_tx(const struct device *dev, const uint8_t *tx_data, size_t len, + int32_t timeout) +{ + struct serial_vnd_data *data = dev->data; + struct uart_event evt; + uint32_t write_len; + + if (data == NULL) { + return -ENOTSUP; + } + + if (data->async_cb == NULL) { + return -EINVAL; + } + + write_len = ring_buf_put(data->written, tx_data, len); + if (data->callback) { + data->callback(dev, data->callback_data); + } + + __ASSERT(write_len == len, "Ring buffer full. Async wait not implemented."); + + evt = (struct uart_event){ + .type = UART_TX_DONE, + .data.tx.buf = tx_data, + .data.tx.len = len, + }; + data->async_cb(dev, &evt, data->async_cb_user_data); + + return 0; +} + +static void async_rx_run(const struct device *dev) +{ + struct serial_vnd_data *data = dev->data; + struct uart_event evt; + uint32_t read_len; + uint32_t read_remaining; + + if (!data->read_buf) { + return; + } + + __ASSERT_NO_MSG(data->async_cb); + + read_remaining = data->read_size - data->read_position; + + read_len = ring_buf_get(data->read_queue, &data->read_buf[data->read_position], + read_remaining); + + if (read_len != 0) { + evt = (struct uart_event){ + .type = UART_RX_RDY, + .data.rx.buf = data->read_buf, + .data.rx.len = read_len, + .data.rx.offset = data->read_position, + }; + data->async_cb(dev, &evt, data->async_cb_user_data); + } + + data->read_position += read_len; + + if (data->read_position == data->read_size) { + data->read_buf = NULL; + evt = (struct uart_event){ + .type = UART_RX_DISABLED, + }; + data->async_cb(dev, &evt, data->async_cb_user_data); + } +} + +static int serial_vnd_rx_enable(const struct device *dev, uint8_t *read_buf, size_t read_size, + int32_t timeout) +{ + struct serial_vnd_data *data = dev->data; + + LOG_WRN("read_size %d", read_size); + + if (data == NULL) { + return -ENOTSUP; + } + + if (data->async_cb == NULL) { + return -EINVAL; + } + + __ASSERT(timeout == SYS_FOREVER_MS, "Async timeout not implemented."); + + data->read_buf = read_buf; + data->read_size = read_size; + data->read_position = 0; + + async_rx_run(dev); + + return 0; +} +#endif /* CONFIG_UART_ASYNC_API */ + static const struct uart_driver_api serial_vnd_api = { .poll_in = serial_vnd_poll_in, .poll_out = serial_vnd_poll_out, @@ -138,6 +437,22 @@ static const struct uart_driver_api serial_vnd_api = { .configure = serial_vnd_configure, .config_get = serial_vnd_config_get, #endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */ +#ifdef CONFIG_UART_INTERRUPT_DRIVEN + .irq_callback_set = irq_callback_set, + .irq_rx_enable = irq_rx_enable, + .irq_rx_disable = irq_rx_disable, + .irq_rx_ready = irq_rx_ready, + .irq_tx_enable = irq_tx_enable, + .irq_tx_disable = irq_tx_disable, + .irq_tx_ready = irq_tx_ready, + .fifo_read = fifo_read, + .fifo_fill = fifo_fill, +#endif /* CONFIG_UART_INTERRUPT_DRIVEN */ +#ifdef CONFIG_UART_ASYNC_API + .callback_set = serial_vnd_callback_set, + .tx = serial_vnd_api_tx, + .rx_enable = serial_vnd_rx_enable, +#endif /* CONFIG_UART_ASYNC_API */ }; #define VND_SERIAL_DATA_BUFFER(n) \ diff --git a/include/zephyr/drivers/uart/serial_test.h b/include/zephyr/drivers/uart/serial_test.h index 5e011d40321..ff1a2ad6181 100644 --- a/include/zephyr/drivers/uart/serial_test.h +++ b/include/zephyr/drivers/uart/serial_test.h @@ -29,7 +29,7 @@ extern "C" { * * @retval Number of bytes written. */ -int serial_vnd_queue_in_data(const struct device *dev, unsigned char *data, uint32_t size); +int serial_vnd_queue_in_data(const struct device *dev, const unsigned char *data, uint32_t size); /** * @brief Returns size of unread written data. From 237e871f948cb64089ec9d792d9cc5dd3377b85d Mon Sep 17 00:00:00 2001 From: Aleksander Wasaznik Date: Tue, 10 Jan 2023 10:11:09 +0100 Subject: [PATCH 0342/1623] [nrf fromtree] bluetooth: samples: Add hci_uart_async This sample is an alternative implementation of hci_uart. The new sample differs from the existing sample in that it uses the async UART API instead of the interrupt driven API. Included in this commit is a new test for HCI UART flow control. It's enabled for hci_uart_async. The test can excercise also the existing hci_uart sample (with some minimal changes to allow compiling in the mock controller and test suite). The existing hci_uart sample currently fails the flow control test. Signed-off-by: Aleksander Wasaznik (cherry picked from commit 347ce7aa7f6e4be8464a4c09c615ad7c4eaa6f9f) --- .../bluetooth/hci_uart_async/CMakeLists.txt | 10 + samples/bluetooth/hci_uart_async/README.rst | 158 +++++++ samples/bluetooth/hci_uart_async/app.overlay | 31 ++ .../bluetooth/hci_uart_async/debug.mixin.conf | 15 + samples/bluetooth/hci_uart_async/prj.conf | 25 ++ samples/bluetooth/hci_uart_async/sample.yaml | 19 + .../hci_uart_async/src/hci_uart_async.c | 403 ++++++++++++++++++ samples/bluetooth/hci_uart_async/src/main.c | 11 + tests/bluetooth/hci_uart_async/CMakeLists.txt | 15 + tests/bluetooth/hci_uart_async/app.overlay | 11 + .../hci_uart_async/boards/native_posix.conf | 3 + tests/bluetooth/hci_uart_async/prj.conf | 10 + .../hci_uart_async/src/test_hci_uart_async.c | 238 +++++++++++ tests/bluetooth/hci_uart_async/testcase.yaml | 6 + 14 files changed, 955 insertions(+) create mode 100644 samples/bluetooth/hci_uart_async/CMakeLists.txt create mode 100644 samples/bluetooth/hci_uart_async/README.rst create mode 100644 samples/bluetooth/hci_uart_async/app.overlay create mode 100644 samples/bluetooth/hci_uart_async/debug.mixin.conf create mode 100644 samples/bluetooth/hci_uart_async/prj.conf create mode 100644 samples/bluetooth/hci_uart_async/sample.yaml create mode 100644 samples/bluetooth/hci_uart_async/src/hci_uart_async.c create mode 100644 samples/bluetooth/hci_uart_async/src/main.c create mode 100644 tests/bluetooth/hci_uart_async/CMakeLists.txt create mode 100644 tests/bluetooth/hci_uart_async/app.overlay create mode 100644 tests/bluetooth/hci_uart_async/boards/native_posix.conf create mode 100644 tests/bluetooth/hci_uart_async/prj.conf create mode 100644 tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c create mode 100644 tests/bluetooth/hci_uart_async/testcase.yaml diff --git a/samples/bluetooth/hci_uart_async/CMakeLists.txt b/samples/bluetooth/hci_uart_async/CMakeLists.txt new file mode 100644 index 00000000000..fe45a9cc371 --- /dev/null +++ b/samples/bluetooth/hci_uart_async/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(hci_uart_async) +target_sources(app PRIVATE + src/hci_uart_async.c + src/main.c +) diff --git a/samples/bluetooth/hci_uart_async/README.rst b/samples/bluetooth/hci_uart_async/README.rst new file mode 100644 index 00000000000..75bf586868d --- /dev/null +++ b/samples/bluetooth/hci_uart_async/README.rst @@ -0,0 +1,158 @@ +.. _bluetooth-hci-uart-async-sample: + +Bluetooth: HCI UART based on ASYNC UART +####################################### + +Expose a Zephyr Bluetooth Controller over a standard Bluetooth HCI UART interface. + +This sample performs the same basic function as the HCI UART sample, but it uses the UART_ASYNC_API +instead of UART_INTERRUPT_DRIVEN API. Not all boards implement both UART APIs, so the board support +of the HCI UART sample may be different. + +Requirements +************ + +* A board with BLE support + +Default UART settings +********************* + +By default the controller builds use the following settings: + +* Baudrate: 1Mbit/s +* 8 bits, no parity, 1 stop bit +* Hardware Flow Control (RTS/CTS) enabled + +Building and Running +******************** + +This sample can be found under :zephyr_file:`samples/bluetooth/hci_uart_async` +in the Zephyr tree and is built as a standard Zephyr application. + +Using the controller with emulators and BlueZ +********************************************* + +The instructions below show how to use a Nordic nRF5x device as a Zephyr BLE +controller and expose it to Linux's BlueZ. + +First, make sure you have a recent BlueZ version installed by following the +instructions in the :ref:`bluetooth_bluez` section. + +Now build and flash the sample for the Nordic nRF5x board of your choice. +All of the Nordic Development Kits come with a Segger IC that provides a +debugger interface and a CDC ACM serial port bridge. More information can be +found in :ref:`nordic_segger`. + +For example, to build for the nRF52832 Development Kit: + +.. zephyr-app-commands:: + :zephyr-app: samples/bluetooth/hci_uart_async + :board: nrf52dk_nrf52832 + :goals: build flash + +.. _bluetooth-hci-uart-async-qemu-posix: + +Using the controller with QEMU and Native POSIX +=============================================== + +In order to use the HCI UART controller with QEMU or Native POSIX you will need +to attach it to the Linux Host first. To do so simply build the sample and +connect the UART to the Linux machine, and then attach it with this command: + +.. code-block:: console + + sudo btattach -B /dev/ttyACM0 -S 1000000 -R + +.. note:: + Depending on the serial port you are using you will need to modify the + ``/dev/ttyACM0`` string to point to the serial device your controller is + connected to. + +.. note:: + The ``-R`` flag passed to ``btattach`` instructs the kernel to avoid + interacting with the controller and instead just be aware of it in order + to proxy it to QEMU later. + +If you are running :file:`btmon` you should see a brief log showing how the +Linux kernel identifies the attached controller. + +Once the controller is attached follow the instructions in the +:ref:`bluetooth_qemu_posix` section to use QEMU with it. + +.. _bluetooth-hci-uart-async-bluez: + +Using the controller with BlueZ +=============================== + +In order to use the HCI UART controller with BlueZ you will need to attach it +to the Linux Host first. To do so simply build the sample and connect the +UART to the Linux machine, and then attach it with this command: + +.. code-block:: console + + sudo btattach -B /dev/ttyACM0 -S 1000000 + +.. note:: + Depending on the serial port you are using you will need to modify the + ``/dev/ttyACM0`` string to point to the serial device your controller is + connected to. + +If you are running :file:`btmon` you should see a comprehensive log showing how +BlueZ loads and initializes the attached controller. + +Once the controller is attached follow the instructions in the +:ref:`bluetooth_ctlr_bluez` section to use BlueZ with it. + +Debugging the controller +======================== + +The sample can be debugged using RTT since the UART is reserved used by this +application. To enable debug over RTT the debug configuration file can be used. + +.. code-block:: console + + west build samples/bluetooth/hci_uart_async -- -DEXTRA_CONFIG='debug.mixin.conf' + +Then attach RTT as described here: :ref:`Using Segger J-Link ` + +Using the controller with the Zephyr host +========================================= + +This describes how to hook up a board running this sample to a board running +an application that uses the Zephyr host. + +On the controller side, the `zephyr,bt-c2h-uart` DTS property (in the `chosen` +block) is used to select which uart device to use. For example if we want to +keep the console logs, we can keep console on uart0 and the HCI on uart1 like +so: + +.. code-block:: dts + + / { + chosen { + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + zephyr,bt-c2h-uart = &uart1; + }; + }; + +On the host application, some config options need to be used to select the H4 +driver instead of the built-in controller: + +.. code-block:: kconfig + + CONFIG_BT_HCI=y + CONFIG_BT_CTLR=n + CONFIG_BT_H4=y + +Similarly, the `zephyr,bt-uart` DTS property selects which uart to use: + +.. code-block:: dts + + / { + chosen { + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + zephyr,bt-uart = &uart1; + }; + }; diff --git a/samples/bluetooth/hci_uart_async/app.overlay b/samples/bluetooth/hci_uart_async/app.overlay new file mode 100644 index 00000000000..e9a282ad78c --- /dev/null +++ b/samples/bluetooth/hci_uart_async/app.overlay @@ -0,0 +1,31 @@ +/* This is the default app device tree overlay. This file is ignored if + * there is a board-specific overlay in `./boards`. + * + * Most boards define a convenient `&uart0`. It's used here to make the + * sample 'just work' automatically for those boards. + */ + +bt_c2h_uart: &uart0 { + status = "okay"; + current-speed = <1000000>; + hw-flow-control; +}; + +/ { + chosen { + zephyr,bt-c2h-uart = &bt_c2h_uart; + }; +}; + +/* Some boards are by default assigning the &uart0 to these other + * functions. Removing the assignments will ensure a compilation error + * instead of accidental interference. + */ +/ { + chosen { + /delete-property/ zephyr,console; + /delete-property/ zephyr,shell-uart; + /delete-property/ zephyr,uart-mcumgr; + /delete-property/ zephyr,bt-mon-uart; + }; +}; diff --git a/samples/bluetooth/hci_uart_async/debug.mixin.conf b/samples/bluetooth/hci_uart_async/debug.mixin.conf new file mode 100644 index 00000000000..3255df74018 --- /dev/null +++ b/samples/bluetooth/hci_uart_async/debug.mixin.conf @@ -0,0 +1,15 @@ +CONFIG_ASSERT_ON_ERRORS=y +CONFIG_ASSERT=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_OPTIMIZATIONS=y +CONFIG_DEBUG_THREAD_INFO=y + +# Enable RTT console +CONFIG_RTT_CONSOLE=y + +CONFIG_LOG=y +CONFIG_LOG_BUFFER_SIZE=10000 + +# This outputs all HCI traffic to a separate RTT channel. Use `btmon +# --jlink` to read it out. Add `--priority 7` for debug logs. +CONFIG_BT_DEBUG_MONITOR_RTT=y diff --git a/samples/bluetooth/hci_uart_async/prj.conf b/samples/bluetooth/hci_uart_async/prj.conf new file mode 100644 index 00000000000..1de1a46535e --- /dev/null +++ b/samples/bluetooth/hci_uart_async/prj.conf @@ -0,0 +1,25 @@ +# hci_uart_async +CONFIG_SERIAL=y +CONFIG_UART_ASYNC_API=y + +# hci_raw (dependency of hci_uart) +CONFIG_BT=y +CONFIG_BT_HCI_RAW=y +CONFIG_BT_HCI_RAW_H4=y +CONFIG_BT_HCI_RAW_H4_ENABLE=y + +# Controller configuration. Modify these for your application's needs. +CONFIG_BT_MAX_CONN=16 +CONFIG_BT_BUF_ACL_RX_SIZE=255 +CONFIG_BT_BUF_CMD_TX_SIZE=255 +CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255 + +# Send an initial HCI_Command_Complete event on boot without waiting for +# HCI_Reset. Make sure to use the same value for this setting in your +# host application. +#CONFIG_BT_WAIT_NOP=y + +# See `overlay.app`. The 'zephyr,console' chosen node is deleted there +# in case it has a interfering default. Those same boards set this +# config and it must be undone or the build will fail. +CONFIG_UART_CONSOLE=n diff --git a/samples/bluetooth/hci_uart_async/sample.yaml b/samples/bluetooth/hci_uart_async/sample.yaml new file mode 100644 index 00000000000..d0db2b90385 --- /dev/null +++ b/samples/bluetooth/hci_uart_async/sample.yaml @@ -0,0 +1,19 @@ +sample: + name: Bluetooth HCI UART Async + description: + This sample is a batteries-included example of a Bluetooth HCI UART + connectivity chip. + + It demonstrates a possible implementation of an HCI UART (H4) + interface on top of Zephyr's Bluetooth Raw API, and how to expose it + over a UART. + + This implementation is based on the Zephyr Asynchoronous UART API. +tests: + sample.bluetooth.hci_uart_async.nrf5: + harness: bluetooth + platform_allow: + - nrf52dk_nrf52832 + tags: + - uart + - bluetooth diff --git a/samples/bluetooth/hci_uart_async/src/hci_uart_async.c b/samples/bluetooth/hci_uart_async/src/hci_uart_async.c new file mode 100644 index 00000000000..4d276e42378 --- /dev/null +++ b/samples/bluetooth/hci_uart_async/src/hci_uart_async.c @@ -0,0 +1,403 @@ +/* Copyright (c) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(hci_uart_async, LOG_LEVEL_DBG); + +static const struct device *const hci_uart_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_c2h_uart)); + +static K_THREAD_STACK_DEFINE(h2c_thread_stack, CONFIG_BT_HCI_TX_STACK_SIZE); +static struct k_thread h2c_thread; + +enum h4_type { + H4_CMD = 0x01, + H4_ACL = 0x02, + H4_SCO = 0x03, + H4_EVT = 0x04, + H4_ISO = 0x05, +}; + +struct k_poll_signal uart_h2c_rx_sig; +struct k_poll_signal uart_c2h_tx_sig; + +static K_FIFO_DEFINE(c2h_queue); + +/** Send raw data on c2h UART. + * + * Blocks until completion. Not thread-safe. + * + * @retval 0 on success + * @retval -EBUSY Another transmission is in progress. This a + * thread-safety violation. + * @retval -errno @ref uart_tx error. + */ +static int uart_c2h_tx(const uint8_t *data, size_t size) +{ + int err; + struct k_poll_signal *sig = &uart_c2h_tx_sig; + struct k_poll_event done[] = { + K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, sig), + }; + + k_poll_signal_reset(sig); + err = uart_tx(hci_uart_dev, data, size, SYS_FOREVER_US); + + if (err) { + LOG_ERR("uart c2h tx: err %d", err); + return err; + } + + err = k_poll(done, ARRAY_SIZE(done), K_FOREVER); + __ASSERT_NO_MSG(err == 0); + + return 0; +} + +/* Function expects that type is validated and only CMD, ISO or ACL will be used. */ +static uint32_t hci_payload_size(const uint8_t *hdr_buf, enum h4_type type) +{ + switch (type) { + case H4_CMD: + return ((const struct bt_hci_cmd_hdr *)hdr_buf)->param_len; + case H4_ACL: + return sys_le16_to_cpu(((const struct bt_hci_acl_hdr *)hdr_buf)->len); + case H4_ISO: + return bt_iso_hdr_len( + sys_le16_to_cpu(((const struct bt_hci_iso_hdr *)hdr_buf)->len)); + default: + LOG_ERR("Invalid type: %u", type); + return 0; + } +} + +static uint8_t hci_hdr_size(enum h4_type type) +{ + switch (type) { + case H4_CMD: + return sizeof(struct bt_hci_cmd_hdr); + case H4_ACL: + return sizeof(struct bt_hci_acl_hdr); + case H4_ISO: + return sizeof(struct bt_hci_iso_hdr); + default: + LOG_ERR("Unexpected h4 type: %u", type); + return 0; + } +} + +/** Send raw data on c2h UART. + * + * Blocks until either @p size has been received or special UART + * condition occurs on the UART RX line, like an UART break or parity + * error. + * + * Not thread-safe. + * + * @retval 0 on success + * @retval -EBUSY Another transmission is in progress. This a + * thread-safety violation. + * @retval -errno @ref uart_rx_enable error. + * @retval +stop_reason Special condition @ref uart_rx_stop_reason. + */ +static int uart_h2c_rx(uint8_t *dst, size_t size) +{ + int err; + struct k_poll_signal *sig = &uart_h2c_rx_sig; + struct k_poll_event done[] = { + K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, sig), + }; + + k_poll_signal_reset(sig); + err = uart_rx_enable(hci_uart_dev, dst, size, SYS_FOREVER_US); + + if (err) { + LOG_ERR("uart h2c rx: err %d", err); + return err; + } + + k_poll(done, ARRAY_SIZE(done), K_FOREVER); + return sig->result; +} + +/** Inject a HCI EVT Hardware error into the c2h packet stream. + * + * This uses `bt_recv`, just as if the controller is sending the error. + */ +static void send_hw_error(void) +{ + const uint8_t err_code = 0; + const uint8_t hci_evt_hw_err[] = {BT_HCI_EVT_HARDWARE_ERROR, + sizeof(struct bt_hci_evt_hardware_error), err_code}; + + struct net_buf *buf = bt_buf_get_rx(BT_BUF_EVT, K_FOREVER); + + net_buf_add_mem(buf, hci_evt_hw_err, sizeof(hci_evt_hw_err)); + + /* Inject the message into the c2h queue. */ + bt_recv(buf); + + /* The c2h thread will send the message at some point. The host + * will receive it and reset the controller. + */ +} + +static void recover_sync_by_reset_pattern(void) +{ + /* { H4_CMD, le_16(HCI_CMD_OP_RESET), len=0 } */ + const uint8_t h4_cmd_reset[] = {0x01, 0x03, 0x0C, 0x00}; + const uint32_t reset_pattern = sys_get_be32(h4_cmd_reset); + int err; + struct net_buf *h2c_cmd_reset; + uint32_t shift_register = 0; + + LOG_DBG("Looking for reset pattern"); + + while (shift_register != reset_pattern) { + uint8_t read_byte; + + uart_h2c_rx(&read_byte, sizeof(uint8_t)); + LOG_DBG("h2c: 0x%02x", read_byte); + shift_register = (shift_register * 0x100) + read_byte; + } + + LOG_DBG("Pattern found"); + h2c_cmd_reset = bt_buf_get_tx(BT_BUF_H4, K_FOREVER, h4_cmd_reset, sizeof(h4_cmd_reset)); + LOG_DBG("Fowarding reset"); + + err = bt_send(h2c_cmd_reset); + __ASSERT(!err, "Failed to send reset: %d", err); +} + +static void h2c_h4_transport(void) +{ + /* When entering this function, the h2c stream should be + * 'synchronized'. I.e. The stream should be at a H4 packet + * boundary. + * + * This function returns to signal a desynchronization. + * When this happens, the caller should resynchronize before + * entering this function again. It's up to the caller to decide + * how to resynchronize. + */ + + for (;;) { + int err; + struct net_buf *buf; + uint8_t h4_type; + uint8_t hdr_size; + uint8_t *hdr_buf; + uint16_t payload_size; + + LOG_DBG("h2c: listening"); + + /* Read H4 type. */ + err = uart_h2c_rx(&h4_type, sizeof(uint8_t)); + + if (err) { + return; + } + LOG_DBG("h2c: h4_type %d", h4_type); + + /* Allocate buf. */ + buf = bt_buf_get_tx(BT_BUF_H4, K_FOREVER, &h4_type, sizeof(h4_type)); + LOG_DBG("h2c: buf %p", buf); + + if (!buf) { + /* `h4_type` was invalid. */ + __ASSERT_NO_MSG(hci_hdr_size(h4_type) == 0); + + LOG_WRN("bt_buf_get_tx failed h4_type %d", h4_type); + return; + } + + /* Read HCI header. */ + hdr_size = hci_hdr_size(h4_type); + hdr_buf = net_buf_add(buf, hdr_size); + + err = uart_h2c_rx(hdr_buf, hdr_size); + if (err) { + net_buf_unref(buf); + return; + } + LOG_HEXDUMP_DBG(hdr_buf, hdr_size, "h2c: hci hdr"); + + /* Read HCI payload. */ + payload_size = hci_payload_size(hdr_buf, h4_type); + + LOG_DBG("h2c: payload_size %u", payload_size); + + if (payload_size <= net_buf_tailroom(buf)) { + uint8_t *payload_dst = net_buf_add(buf, payload_size); + + err = uart_h2c_rx(payload_dst, payload_size); + if (err) { + net_buf_unref(buf); + return; + } + LOG_HEXDUMP_DBG(payload_dst, payload_size, "h2c: hci payload"); + } else { + /* Discard oversize packet. */ + uint8_t *discard_dst; + uint16_t discard_size; + + LOG_WRN("h2c: Discarding oversize h4_type %d payload_size %d.", h4_type, + payload_size); + + /* Reset `buf` so all of it is available. */ + net_buf_reset(buf); + discard_dst = net_buf_tail(buf); + discard_size = net_buf_max_len(buf); + + while (payload_size) { + uint16_t read_size = MIN(payload_size, discard_size); + + err = uart_h2c_rx(discard_dst, read_size); + if (err) { + net_buf_unref(buf); + return; + } + + payload_size -= read_size; + } + + net_buf_unref(buf); + buf = NULL; + } + + LOG_DBG("h2c: packet done"); + + /* Route buf to Controller. */ + if (buf) { + err = bt_send(buf); + if (err) { + /* This is not a transport error. */ + LOG_ERR("bt_send err %d", err); + net_buf_unref(buf); + buf = NULL; + } + } + + k_yield(); + } +} + +static void h2c_thread_entry(void *p1, void *p2, void *p3) +{ + k_thread_name_set(k_current_get(), "HCI TX (h2c)"); + + for (;;) { + LOG_DBG("Synchronized"); + h2c_h4_transport(); + LOG_WRN("Desynchronized"); + send_hw_error(); + recover_sync_by_reset_pattern(); + } +} + +void callback(const struct device *dev, struct uart_event *evt, void *user_data) +{ + ARG_UNUSED(user_data); + + if (evt->type == UART_RX_DISABLED) { + (void)k_poll_signal_raise(&uart_h2c_rx_sig, 0); + } else if (evt->type == UART_RX_STOPPED) { + (void)k_poll_signal_raise(&uart_h2c_rx_sig, evt->data.rx_stop.reason); + } else if (evt->type == UART_TX_DONE) { + (void)k_poll_signal_raise(&uart_c2h_tx_sig, 0); + } +} + +static int hci_uart_init(void) +{ + int err; + + k_poll_signal_init(&uart_h2c_rx_sig); + k_poll_signal_init(&uart_c2h_tx_sig); + + LOG_DBG(""); + + if (!device_is_ready(hci_uart_dev)) { + LOG_ERR("HCI UART %s is not ready", hci_uart_dev->name); + return -EINVAL; + } + + BUILD_ASSERT(IS_ENABLED(CONFIG_UART_ASYNC_API)); + err = uart_callback_set(hci_uart_dev, callback, NULL); + + /* Note: Asserts if CONFIG_UART_ASYNC_API is not enabled for `hci_uart_dev`. */ + __ASSERT(!err, "err %d", err); + + return 0; +} + +SYS_INIT(hci_uart_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); + +const struct { + uint8_t h4; + struct bt_hci_evt_hdr hdr; + struct bt_hci_evt_cmd_complete cc; +} __packed cc_evt = { + .h4 = H4_EVT, + .hdr = {.evt = BT_HCI_EVT_CMD_COMPLETE, .len = sizeof(struct bt_hci_evt_cmd_complete)}, + .cc = {.ncmd = 1, .opcode = sys_cpu_to_le16(BT_OP_NOP)}, +}; + +static void c2h_thread_entry(void) +{ + k_thread_name_set(k_current_get(), "HCI RX (c2h)"); + + if (IS_ENABLED(CONFIG_BT_WAIT_NOP)) { + uart_c2h_tx((char *)&cc_evt, sizeof(cc_evt)); + } + + for (;;) { + struct net_buf *buf; + + buf = net_buf_get(&c2h_queue, K_FOREVER); + uart_c2h_tx(buf->data, buf->len); + net_buf_unref(buf); + } +} + +void hci_uart_main(void) +{ + int err; + + err = bt_enable_raw(&c2h_queue); + __ASSERT_NO_MSG(!err); + + /* TX thread. */ + k_thread_create(&h2c_thread, h2c_thread_stack, K_THREAD_STACK_SIZEOF(h2c_thread_stack), + h2c_thread_entry, NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); + + /* Reuse current thread as RX thread. */ + c2h_thread_entry(); +} diff --git a/samples/bluetooth/hci_uart_async/src/main.c b/samples/bluetooth/hci_uart_async/src/main.c new file mode 100644 index 00000000000..2d38d83e45c --- /dev/null +++ b/samples/bluetooth/hci_uart_async/src/main.c @@ -0,0 +1,11 @@ +/* Copyright (c) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +extern int hci_uart_main(void); + +int main(void) +{ + hci_uart_main(); + return 0; +} diff --git a/tests/bluetooth/hci_uart_async/CMakeLists.txt b/tests/bluetooth/hci_uart_async/CMakeLists.txt new file mode 100644 index 00000000000..2380f9f1152 --- /dev/null +++ b/tests/bluetooth/hci_uart_async/CMakeLists.txt @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +set(EXTRA_CONF_FILE + ../../../samples/bluetooth/hci_uart_async/prj.conf +) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(test_samples_bluetooth_hci_uart_async) +target_sources(app PRIVATE + ../../../samples/bluetooth/hci_uart_async/src/hci_uart_async.c + src/test_hci_uart_async.c +) diff --git a/tests/bluetooth/hci_uart_async/app.overlay b/tests/bluetooth/hci_uart_async/app.overlay new file mode 100644 index 00000000000..d9186722ba6 --- /dev/null +++ b/tests/bluetooth/hci_uart_async/app.overlay @@ -0,0 +1,11 @@ +/ { + chosen { + zephyr,bt-c2h-uart = &test_uart; + }; + + test_uart: test_uart { + compatible = "vnd,serial"; + status = "okay"; + buffer-size = <100>; + }; +}; diff --git a/tests/bluetooth/hci_uart_async/boards/native_posix.conf b/tests/bluetooth/hci_uart_async/boards/native_posix.conf new file mode 100644 index 00000000000..e638cd6a0ef --- /dev/null +++ b/tests/bluetooth/hci_uart_async/boards/native_posix.conf @@ -0,0 +1,3 @@ +# Print logs and test results on stdout. For some reason, this not the +# default when SERIAL=y. +CONFIG_LOG_BACKEND_NATIVE_POSIX=y diff --git a/tests/bluetooth/hci_uart_async/prj.conf b/tests/bluetooth/hci_uart_async/prj.conf new file mode 100644 index 00000000000..b038c7c4312 --- /dev/null +++ b/tests/bluetooth/hci_uart_async/prj.conf @@ -0,0 +1,10 @@ +CONFIG_BT_NO_DRIVER=y + +CONFIG_RING_BUFFER=y + +CONFIG_ASSERT=y +CONFIG_LOG=y +CONFIG_TEST=y + +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c b/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c new file mode 100644 index 00000000000..1996aba177a --- /dev/null +++ b/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c @@ -0,0 +1,238 @@ +/* Copyright (c) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +LOG_MODULE_REGISTER(test, LOG_LEVEL_DBG); + +/* This is a mock UART. Using `serial_vnd_...` on this simulates + * traffic from the external Host. + */ +static const struct device *const zephyr_bt_c2h_uart = DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_c2h_uart)); + +/* The DUT is Sandwiched between the mock serial interface and a mock + * controller. {{{ + */ +static void serial_vnd_data_callback(const struct device *dev, void *user_data); +static int drv_send(struct net_buf *buf); +static int drv_open(void); +static const struct bt_hci_driver drv = { + .name = "Mock Controller", + .bus = BT_HCI_DRIVER_BUS_VIRTUAL, + .open = drv_open, + .send = drv_send, +}; +static int sys_init_hci_driver_register(void) +{ + serial_vnd_set_callback(zephyr_bt_c2h_uart, serial_vnd_data_callback, NULL); + bt_hci_driver_register(&drv); + return 0; +} +SYS_INIT(sys_init_hci_driver_register, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +/* }}} */ + +/* Start the DUT "main thread". The settings for this thread are selected as + * true as possible to the real main thread. {{{ + */ +static struct k_thread hci_uart_thread; +static K_THREAD_PINNED_STACK_DEFINE(hci_uart_thread_stack, CONFIG_MAIN_STACK_SIZE); +static void hci_uart_thread_entry(void *p1, void *p2, void *p3) +{ + extern void hci_uart_main(void); + hci_uart_main(); +} +static int sys_init_spawn_hci_uart(void) +{ + k_thread_name_set(&hci_uart_thread, "hci_uart_main"); + k_thread_create(&hci_uart_thread, hci_uart_thread_stack, + K_THREAD_STACK_SIZEOF(hci_uart_thread_stack), hci_uart_thread_entry, NULL, + NULL, NULL, CONFIG_MAIN_THREAD_PRIORITY, 0, K_NO_WAIT); + return 0; +} +SYS_INIT(sys_init_spawn_hci_uart, POST_KERNEL, 64); +/* }}} */ + +/* Mock controller callbacks. {{{ */ + +static int drv_open(void) +{ + LOG_DBG("drv_open"); + return 0; +} + +/** This FIFO holds the references to all h2c packets the DUT has sent + * to the controller using #bt_send. + * + * Each test should mock a controller by calling #net_buf_get on this + * FIFO and simulate a controller's #bt_hci_driver::drv_send. The mocks + * should use #bt_recv to send c2h packets to the DUT. + */ +K_FIFO_DEFINE(drv_send_fifo); /* elem T: net_buf */ +static int drv_send(struct net_buf *buf) +{ + LOG_DBG("buf %p type %d len %u", buf, bt_buf_get_type(buf), buf->len); + LOG_HEXDUMP_DBG(buf->data, buf->len, "buf"); + + __ASSERT_NO_MSG(buf); + net_buf_put(&drv_send_fifo, buf); + return 0; +} + +/* }}} */ + +/* Mock UART c2h TX handler. {{{ */ + +static void serial_vnd_data_callback(const struct device *dev, void *user_data) +{ + uint32_t size = serial_vnd_out_data_size_get(dev); + uint8_t data[size]; + + serial_vnd_read_out_data(dev, data, size); + LOG_HEXDUMP_DBG(data, size, "uart tx"); + + /* If a test needs to look at the c2h UART traffic, it can be + * captured here. + */ +} + +/* }}} */ + +#define HCI_NORMAL_CMD_BUF_COUNT (CONFIG_BT_BUF_CMD_TX_COUNT - 1) +#define TEST_PARAM_HOST_COMPLETE_COUNT 10 +#define TIMEOUT_PRESUME_STUCK K_SECONDS(1) + +/** Corresponds to: + * - #bt_hci_cmd_hdr + */ +const uint8_t h4_msg_cmd_dummy1[] = { + 0x01, /* H4: opcode = CMD */ + 0x01, 0x00, /* H4: CMD: opcode = 1 */ + 0x00, /* H4: CMD: len = 0 */ +}; + +/** Corresponds to: + * - #bt_hci_cmd_hdr + * - #bt_hci_cp_host_num_completed_packets + */ +const uint8_t h4_msg_cmd_host_num_complete[] = { + 0x01, /* H4: opcode = CMD */ + 0x35, 0x0c, /* H4: CMD: opcode = BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS */ + 0x05, /* H4: CMD: len = 5 */ + 0x01, /* H4: CMD: num_handles = 1 */ + 0x00, 0x00, /* H4: CMD: connection_handle = 0 */ + 0x01, 0x00, /* H4: CMD: num_complete = 1 */ +}; + +/** Corresponds to: + * - #bt_hci_evt_hdr + * - #bt_hci_evt_cmd_complete + */ +const uint8_t hci_msg_rx_evt_cmd_complete[] = { + BT_HCI_EVT_CMD_COMPLETE, /* EVT: opcode */ + 0x03, /* EVT: len */ + 0x01, /* EVT: CMDC: ncmd = 1 */ + /* EVT: CMDC: opcode */ + 0x00, + 0x00, +}; + +ZTEST_SUITE(hci_uart, NULL, NULL, NULL, NULL, NULL); +ZTEST(hci_uart, test_h2c_cmd_flow_control) +{ + /* This test assumes the DUT does not care about the contents of + * the HCI messages, other than the HCI type/endpoint and the + * size. This allows the test to cheat and skip the HCI Reset, + * connection setup etc and use dummy command-packets. + */ + + /* Send commands, saturating the controller's command pipeline. */ + for (uint16_t i = 0; i < HCI_NORMAL_CMD_BUF_COUNT; i++) { + int write_size = serial_vnd_queue_in_data(zephyr_bt_c2h_uart, h4_msg_cmd_dummy1, + sizeof(h4_msg_cmd_dummy1)); + __ASSERT_NO_MSG(write_size == sizeof(h4_msg_cmd_dummy1)); + } + + /* At this point, the HCI flow control limit for the cmd + * endpoint has been reached. It will remain so until the + * controller mock has sent a 'HCI Command Complete' event. + * + * But the 'HCI Host Number of Completed Packets' command is + * exempt from HCI flow control. (It's like it has its own + * endpoint, that has no flow control.) + * + * We now send several 'HCI Host Number of Completed Packets' + * packets before handling any commands in the controller. This + * tests whether the DUT is able to engage the lower transport + * flow controller (i.e. UART flow-control) or somehow handle + * the special packets out-of-order in real-time. + */ + for (uint16_t i = 0; i < TEST_PARAM_HOST_COMPLETE_COUNT; i++) { + int write_size = + serial_vnd_queue_in_data(zephyr_bt_c2h_uart, h4_msg_cmd_host_num_complete, + sizeof(h4_msg_cmd_host_num_complete)); + __ASSERT_NO_MSG(write_size == sizeof(h4_msg_cmd_host_num_complete)); + } + + LOG_DBG("All h2c packets queued on UART"); + + /* Then, we check that all packets are delivered without loss. */ + + /* Expect all the normal commands first. */ + for (uint16_t i = 0; i < HCI_NORMAL_CMD_BUF_COUNT; i++) { + /* The mock controller processes a command. */ + { + struct net_buf *buf = net_buf_get(&drv_send_fifo, TIMEOUT_PRESUME_STUCK); + + zassert_not_null(buf); + zassert_equal(buf->len, sizeof(h4_msg_cmd_dummy1) - 1, "Wrong length"); + zassert_mem_equal(buf->data, &h4_msg_cmd_dummy1[1], + sizeof(h4_msg_cmd_dummy1) - 1); + net_buf_unref(buf); + } + + /* The controller sends a HCI Command Complete response. */ + { + int err; + struct net_buf *buf = bt_buf_get_rx(BT_BUF_EVT, K_NO_WAIT); + + zassert_not_null(buf); + net_buf_add_mem(buf, hci_msg_rx_evt_cmd_complete, + sizeof(hci_msg_rx_evt_cmd_complete)); + err = bt_recv(buf); + zassert_equal(err, 0, "bt_recv failed"); + } + } + + /* Expect all the 'HCI Host Number of Completed Packets'. */ + for (uint16_t i = 0; i < TEST_PARAM_HOST_COMPLETE_COUNT; i++) { + /* The mock controller processes a 'HCI Host Number of Completed Packets'. */ + { + struct net_buf *buf = net_buf_get(&drv_send_fifo, TIMEOUT_PRESUME_STUCK); + + zassert_not_null(buf); + zassert_equal(buf->len, sizeof(h4_msg_cmd_host_num_complete) - 1, + "Wrong length"); + zassert_mem_equal(buf->data, &h4_msg_cmd_host_num_complete[1], + sizeof(h4_msg_cmd_dummy1) - 2); + net_buf_unref(buf); + } + + /* There is no response to 'HCI Host Number of Completed Packets'. */ + } + + LOG_DBG("All h2c packets received by controller."); +} diff --git a/tests/bluetooth/hci_uart_async/testcase.yaml b/tests/bluetooth/hci_uart_async/testcase.yaml new file mode 100644 index 00000000000..f7f4a6255eb --- /dev/null +++ b/tests/bluetooth/hci_uart_async/testcase.yaml @@ -0,0 +1,6 @@ +tests: + samples.bluetooth.hci_uart_async: + tags: bluetooth uart + harness: ztest + platform_allow: + - native_posix From 064421793433e85e7df854343f88d725673d3e14 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 28 Sep 2023 15:54:47 +0200 Subject: [PATCH 0343/1623] [nrf fromtree] tests: build_all: modem: Patch dependencies preventing build Some dependencies where missing from the build_all test for the modem_cellular.c driver. These have been added. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 7fb10c82cc90aab470fc6c2b502d8ffa20962302) --- tests/drivers/build_all/modem/modem_cellular.conf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/drivers/build_all/modem/modem_cellular.conf b/tests/drivers/build_all/modem/modem_cellular.conf index e541af07e2d..3366fcf32d4 100644 --- a/tests/drivers/build_all/modem/modem_cellular.conf +++ b/tests/drivers/build_all/modem/modem_cellular.conf @@ -1,7 +1,10 @@ CONFIG_TEST=y CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_SERIAL=y -CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_NETWORKING=y CONFIG_NET_L2_PPP=y CONFIG_MODEM=y +CONFIG_PM_DEVICE=y +CONFIG_MODEM_CELLULAR=y +CONFIG_UART_ASYNC_API=y +CONFIG_GPIO=y From 757f63ca7660671b008071e7e4eb504660b7c95d Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 28 Sep 2023 17:30:24 +0200 Subject: [PATCH 0344/1623] [nrf fromtree] drivers: serial: serial_test: Patch irq_isr set to undefined This commit fixes an error where the irq_isr callback is set to an undefined variable instead of NULL. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit ebd6681589711d1cc759ca3a90f5c54006a83b4d) --- drivers/serial/serial_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/serial/serial_test.c b/drivers/serial/serial_test.c index 2ce4fb50f38..f18421b00e5 100644 --- a/drivers/serial/serial_test.c +++ b/drivers/serial/serial_test.c @@ -318,7 +318,7 @@ static int serial_vnd_callback_set(const struct device *dev, uart_callback_t cal } #if defined(CONFIG_UART_EXCLUSIVE_API_CALLBACKS) && defined(CONFIG_UART_INTERRUPT_DRIVEN) - data->irq_isr = cb; + data->irq_isr = NULL; #endif if (callback == NULL && data->read_buf) { From 4748e5ed0abaa6e6d9c9e489e16608a9ae2216bf Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 28 Sep 2023 15:57:49 +0200 Subject: [PATCH 0345/1623] [nrf fromtree] drivers: serial: serial_test: Move ring buf dep to Kconfig This commit moves the dependency management between the RING_BUFFER and UART_ASYNC_API or UART_INTERRUPT_DRIVEN options to the Kconfig Kconfig.test. If either UART API options listed are selected, the RING_BUFFER option must be selected. This is now handled automatically by Kconfig instead of causing a build assert. The asserts where added with this PR #59880, and are removed in this commit. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit d118d19293658eb64ca2a9a36a2d3c2bd36d0065) --- drivers/serial/Kconfig.test | 1 + drivers/serial/serial_test.c | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/serial/Kconfig.test b/drivers/serial/Kconfig.test index 5e7353ba65a..e7f38edc591 100644 --- a/drivers/serial/Kconfig.test +++ b/drivers/serial/Kconfig.test @@ -8,3 +8,4 @@ config SERIAL_TEST select SERIAL_HAS_DRIVER select SERIAL_SUPPORT_INTERRUPT select SERIAL_SUPPORT_ASYNC + select RING_BUFFER if (UART_INTERRUPT_DRIVEN || UART_ASYNC_API) diff --git a/drivers/serial/serial_test.c b/drivers/serial/serial_test.c index f18421b00e5..b1661cdfeef 100644 --- a/drivers/serial/serial_test.c +++ b/drivers/serial/serial_test.c @@ -21,9 +21,6 @@ LOG_MODULE_REGISTER(mock_serial, CONFIG_LOG_DEFAULT_LEVEL); -BUILD_ASSERT(!IS_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN) || IS_ENABLED(CONFIG_RING_BUFFER)); -BUILD_ASSERT(!IS_ENABLED(CONFIG_UART_ASYNC_API) || IS_ENABLED(CONFIG_RING_BUFFER)); - #define DT_DRV_COMPAT vnd_serial struct serial_vnd_data { #ifdef CONFIG_RING_BUFFER From 2370c3921324b0f0a5b85979e4fdb13f5fb03f8a Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 28 Sep 2023 18:32:20 +0200 Subject: [PATCH 0346/1623] [nrf fromtree] tests: drivers: modem: Specify targets for cellular Many boards do not build properly if UART_ASYNC_API is enabled, which is causing an overly large list of targets to exclude for the build_all.modem.modem_cellular.build test suite. This commit instead specifies 4 emulated boards, two of 32-bit, two of 64-bit instead. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit b054d162f24f72c77ef14c6b52c6d40cceda801e) --- tests/drivers/build_all/modem/testcase.yaml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/drivers/build_all/modem/testcase.yaml b/tests/drivers/build_all/modem/testcase.yaml index 3614cb09655..8b42363b4ff 100644 --- a/tests/drivers/build_all/modem/testcase.yaml +++ b/tests/drivers/build_all/modem/testcase.yaml @@ -74,10 +74,9 @@ tests: - CONFIG_MODEM_IFACE_UART_ASYNC=y drivers.modem.modem_cellular.build: extra_args: CONF_FILE=modem_cellular.conf - platform_exclude: - - serpente - - particle_boron - - rak5010_nrf52840 - - litex_vexriscv - - ip_k66f + platform_allow: + - native_posix_64 + - native_posix + - qemu_x86 + - qemu_x86_64 min_ram: 36 From f1ee732cab5ebaa83ddf94f0d4c6f734d2684ea7 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 28 Sep 2023 18:37:15 +0200 Subject: [PATCH 0347/1623] [nrf fromtree] drivers: serial: serial_test.c: Patch 64-bit incompat The serial_test.c driver uses size_t to store read_size, which becomes a 64-bit type when built for 64-bit architectures. This is incompatible with the print format %d which is 32-bit. Updated to %zd Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit cc219c0132e31583ead7184c32d1af0283fb4637) --- drivers/serial/serial_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/serial/serial_test.c b/drivers/serial/serial_test.c index b1661cdfeef..b1bb46228be 100644 --- a/drivers/serial/serial_test.c +++ b/drivers/serial/serial_test.c @@ -404,7 +404,7 @@ static int serial_vnd_rx_enable(const struct device *dev, uint8_t *read_buf, siz { struct serial_vnd_data *data = dev->data; - LOG_WRN("read_size %d", read_size); + LOG_WRN("read_size %zd", read_size); if (data == NULL) { return -ENOTSUP; From be6be9bfb8076f29fc4f2be3a98074c8724e0c5f Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 27 Oct 2023 10:29:16 +0200 Subject: [PATCH 0348/1623] Revert "[nrf noup] boards: thingy53_nrf5340: Enable MCUboot by default" This reverts commit 542ff4901b820fd0d8fc1e6264059962ebbf96bf. This revert is only done to be able to revert another patch without conflict. This commit will be re-applied. Signed-off-by: Joakim Andersson --- boards/arm/thingy53_nrf5340/Kconfig.defconfig | 6 ------ boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi | 1 - 2 files changed, 7 deletions(-) diff --git a/boards/arm/thingy53_nrf5340/Kconfig.defconfig b/boards/arm/thingy53_nrf5340/Kconfig.defconfig index ec17fcff34a..3af93918add 100644 --- a/boards/arm/thingy53_nrf5340/Kconfig.defconfig +++ b/boards/arm/thingy53_nrf5340/Kconfig.defconfig @@ -8,12 +8,6 @@ if BOARD_THINGY53_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP_NS config BOARD default "thingy53_nrf5340_cpuapp" -config BOOTLOADER_MCUBOOT - default y if !MCUBOOT - -config BOARD_ENABLE_CPUNET - default y if !MCUBOOT - # By default, if we build for a Non-Secure version of the board, # enable building with TF-M as the Secure Execution Environment. config BUILD_WITH_TFM diff --git a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi index 515fc3bea7b..341bb1305e1 100644 --- a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi +++ b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi @@ -16,7 +16,6 @@ zephyr,bt-hci-rpmsg-ipc = &ipc0; nordic,802154-spinel-ipc = &ipc0; zephyr,ieee802154 = &ieee802154; - nordic,pm-ext-flash = &mx25r64; }; buttons { From ed2c94088c71c21e7606bc9cc3c1648c7c004dd0 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 27 Oct 2023 10:31:59 +0200 Subject: [PATCH 0349/1623] Revert "[nrf noup] boards: Enable TF-M by default for nordic SoC NS boards" This reverts commit aa00769d7243809601ea7480a6f7c0cc72ebe82d. Signed-off-by: Joakim Andersson --- boards/arm/actinius_icarus/Kconfig.defconfig | 15 --------------- boards/arm/actinius_icarus_bee/Kconfig.defconfig | 15 --------------- boards/arm/actinius_icarus_som/Kconfig.defconfig | 15 --------------- .../circuitdojo_feather_nrf9160/Kconfig.defconfig | 15 --------------- .../sparkfun_thing_plus_nrf9160/Kconfig.defconfig | 15 --------------- boards/arm/thingy53_nrf5340/Kconfig.defconfig | 15 --------------- 6 files changed, 90 deletions(-) diff --git a/boards/arm/actinius_icarus/Kconfig.defconfig b/boards/arm/actinius_icarus/Kconfig.defconfig index 3b8093275da..6994aac280d 100644 --- a/boards/arm/actinius_icarus/Kconfig.defconfig +++ b/boards/arm/actinius_icarus/Kconfig.defconfig @@ -8,21 +8,6 @@ if BOARD_ACTINIUS_ICARUS || BOARD_ACTINIUS_ICARUS_NS config BOARD default "actinius_icarus" -# By default, if we build for a Non-Secure version of the board, -# enable building with TF-M as the Secure Execution Environment. -config BUILD_WITH_TFM - default y if BOARD_ACTINIUS_ICARUS_NS - -if BUILD_WITH_TFM - -# By default, if we build with TF-M, instruct build system to -# flash the combined TF-M (Secure) & Zephyr (Non Secure) image -config TFM_FLASH_MERGED_BINARY - bool - default y - -endif # BUILD_WITH_TFM - source "boards/common/actinius/Kconfig" # For the secure version of the board the firmware is linked at the beginning diff --git a/boards/arm/actinius_icarus_bee/Kconfig.defconfig b/boards/arm/actinius_icarus_bee/Kconfig.defconfig index 7b733d910d9..309a45a61d4 100644 --- a/boards/arm/actinius_icarus_bee/Kconfig.defconfig +++ b/boards/arm/actinius_icarus_bee/Kconfig.defconfig @@ -8,21 +8,6 @@ if BOARD_ACTINIUS_ICARUS_BEE || BOARD_ACTINIUS_ICARUS_BEE_NS config BOARD default "actinius_icarus_bee" -# By default, if we build for a Non-Secure version of the board, -# enable building with TF-M as the Secure Execution Environment. -config BUILD_WITH_TFM - default y if BOARD_ACTINIUS_ICARUS_BEE_NS - -if BUILD_WITH_TFM - -# By default, if we build with TF-M, instruct build system to -# flash the combined TF-M (Secure) & Zephyr (Non Secure) image -config TFM_FLASH_MERGED_BINARY - bool - default y - -endif # BUILD_WITH_TFM - source "boards/common/actinius/Kconfig" # For the secure version of the board the firmware is linked at the beginning diff --git a/boards/arm/actinius_icarus_som/Kconfig.defconfig b/boards/arm/actinius_icarus_som/Kconfig.defconfig index cc92427d24c..473acfea29f 100644 --- a/boards/arm/actinius_icarus_som/Kconfig.defconfig +++ b/boards/arm/actinius_icarus_som/Kconfig.defconfig @@ -8,21 +8,6 @@ if BOARD_ACTINIUS_ICARUS_SOM || BOARD_ACTINIUS_ICARUS_SOM_NS config BOARD default "actinius_icarus_som" -# By default, if we build for a Non-Secure version of the board, -# enable building with TF-M as the Secure Execution Environment. -config BUILD_WITH_TFM - default y if BOARD_ACTINIUS_ICARUS_SOM_NS - -if BUILD_WITH_TFM - -# By default, if we build with TF-M, instruct build system to -# flash the combined TF-M (Secure) & Zephyr (Non Secure) image -config TFM_FLASH_MERGED_BINARY - bool - default y - -endif # BUILD_WITH_TFM - source "boards/common/actinius/Kconfig" # For the secure version of the board the firmware is linked at the beginning diff --git a/boards/arm/circuitdojo_feather_nrf9160/Kconfig.defconfig b/boards/arm/circuitdojo_feather_nrf9160/Kconfig.defconfig index f37bfbf84fb..73648be3ef1 100644 --- a/boards/arm/circuitdojo_feather_nrf9160/Kconfig.defconfig +++ b/boards/arm/circuitdojo_feather_nrf9160/Kconfig.defconfig @@ -9,21 +9,6 @@ if BOARD_CIRCUITDOJO_FEATHER_NRF9160 || BOARD_CIRCUITDOJO_FEATHER_NRF9160_NS config BOARD default "circuitdojo_feather_nrf9160" -# By default, if we build for a Non-Secure version of the board, -# enable building with TF-M as the Secure Execution Environment. -config BUILD_WITH_TFM - default y if BOARD_CIRCUITDOJO_FEATHER_NRF9160_NS - -if BUILD_WITH_TFM - -# By default, if we build with TF-M, instruct build system to -# flash the combined TF-M (Secure) & Zephyr (Non Secure) image -config TFM_FLASH_MERGED_BINARY - bool - default y - -endif # BUILD_WITH_TFM - # For the secure version of the board the firmware is linked at the beginning # of the flash, or into the code-partition defined in DT if it is intended to # be loaded by MCUboot. If the secure firmware is to be combined with a non- diff --git a/boards/arm/sparkfun_thing_plus_nrf9160/Kconfig.defconfig b/boards/arm/sparkfun_thing_plus_nrf9160/Kconfig.defconfig index 3d98b1b4cb4..8ae5b832d89 100644 --- a/boards/arm/sparkfun_thing_plus_nrf9160/Kconfig.defconfig +++ b/boards/arm/sparkfun_thing_plus_nrf9160/Kconfig.defconfig @@ -9,21 +9,6 @@ if BOARD_SPARKFUN_THING_PLUS_NRF9160 || BOARD_SPARKFUN_THING_PLUS_NRF9160_NS config BOARD default "sparkfun_thing_plus_nrf9160" -# By default, if we build for a Non-Secure version of the board, -# enable building with TF-M as the Secure Execution Environment. -config BUILD_WITH_TFM - default y if BOARD_SPARKFUN_THING_PLUS_NRF9160_NS - -if BUILD_WITH_TFM - -# By default, if we build with TF-M, instruct build system to -# flash the combined TF-M (Secure) & Zephyr (Non Secure) image -config TFM_FLASH_MERGED_BINARY - bool - default y - -endif # BUILD_WITH_TFM - # For the secure version of the board the firmware is linked at the beginning # of the flash, or into the code-partition defined in DT if it is intended to # be loaded by MCUboot. If the secure firmware is to be combined with a non- diff --git a/boards/arm/thingy53_nrf5340/Kconfig.defconfig b/boards/arm/thingy53_nrf5340/Kconfig.defconfig index 3af93918add..6384d163d93 100644 --- a/boards/arm/thingy53_nrf5340/Kconfig.defconfig +++ b/boards/arm/thingy53_nrf5340/Kconfig.defconfig @@ -8,21 +8,6 @@ if BOARD_THINGY53_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP_NS config BOARD default "thingy53_nrf5340_cpuapp" -# By default, if we build for a Non-Secure version of the board, -# enable building with TF-M as the Secure Execution Environment. -config BUILD_WITH_TFM - default y if BOARD_THINGY53_NRF5340_CPUAPP_NS - -if BUILD_WITH_TFM - -# By default, if we build with TF-M, instruct build system to -# flash the combined TF-M (Secure) & Zephyr (Non Secure) image -config TFM_FLASH_MERGED_BINARY - bool - default y - -endif # BUILD_WITH_TFM - # Code Partition: # # For the secure version of the board the firmware is linked at the beginning From e0fab0305912c36f631b3ad55f4e8ffbf53bb450 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 29 Sep 2023 09:09:58 +0200 Subject: [PATCH 0350/1623] [nrf fromtree] boards: nrf5340dk_nrf5340: Add default HW flow control pins to uart1 Add the default HW flow control pins to the uart1 node. Signed-off-by: Joakim Andersson (cherry picked from commit 9ac85254961012dd6f26962c2bc1cade8f2abd8d) Signed-off-by: Joakim Andersson --- .../nrf5340_cpuapp_common-pinctrl.dtsi | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common-pinctrl.dtsi b/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common-pinctrl.dtsi index 6db9767c0dc..f93e3a69402 100644 --- a/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common-pinctrl.dtsi +++ b/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common-pinctrl.dtsi @@ -84,10 +84,12 @@ uart1_default: uart1_default { group1 { - psels = ; + psels = , + ; }; group2 { - psels = ; + psels = , + ; bias-pull-up; }; }; @@ -95,7 +97,9 @@ uart1_sleep: uart1_sleep { group1 { psels = , - ; + , + , + ; low-power-enable; }; }; From cf504c0167559b0ed749e6fee8c07fb153658db9 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 5 Oct 2023 13:11:13 +0200 Subject: [PATCH 0351/1623] [nrf fromtree] boards: Add uart1 pinctrl assignment to nrf5340 Audio DK Add uart1 pinctrl assignment to nrf5340 Audio DK. Assigned according to Schematic for this board. Uart1 pins needed by TF-M when using the NS board variant. Signed-off-by: Joakim Andersson (cherry picked from commit 32a1c89e2e1accf24aa4df93d1b4e7e988a3df5c) Signed-off-by: Joakim Andersson --- ...udio_dk_nrf5340_cpuapp_common-pinctrl.dtsi | 22 +++++++++++++++++++ ...rf5340_audio_dk_nrf5340_cpuapp_common.dtsi | 8 +++++++ 2 files changed, 30 insertions(+) diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common-pinctrl.dtsi b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common-pinctrl.dtsi index 46359082edd..5247c04429b 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common-pinctrl.dtsi +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common-pinctrl.dtsi @@ -51,6 +51,28 @@ }; }; + uart1_default: uart1_default { + group1 { + psels = , + ; + }; + group2 { + psels = , + ; + bias-pull-up; + }; + }; + + uart1_sleep: uart1_sleep { + group1 { + psels = , + , + , + ; + low-power-enable; + }; + }; + i2c1_default: i2c1_default { group1 { psels = , diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi index f529f16fbe8..df028fb75a2 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi @@ -141,6 +141,14 @@ pinctrl-names = "default", "sleep"; }; +arduino_serial: &uart1 { + compatible = "nordic,nrf-uarte"; + current-speed = <115200>; + pinctrl-0 = <&uart1_default>; + pinctrl-1 = <&uart1_sleep>; + pinctrl-names = "default", "sleep"; +}; + &i2c1 { compatible = "nordic,nrf-twim"; status = "okay"; From 9184096bd977feb4c31608ab67a3a47468e748c5 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 3 Oct 2023 16:59:14 +0200 Subject: [PATCH 0352/1623] [nrf fromtree] tfm: nordic_nrf: Add generic SoC support for nordic SoCs Add generic SoC support for the supported nordic SoCs: - nrf5340 - nrf9160 - nrf9120 Add generic SoC support by taking board specific configurations from zephyr devicetree and kconfig. Signed-off-by: Joakim Andersson (cherry picked from commit 33a44d0ed8acf805782df8c9a4b47b752ea68e8f) Signed-off-by: Joakim Andersson --- modules/trusted-firmware-m/Kconfig.tfm | 6 +- .../nordic_nrf/CMakeLists.txt | 67 +++++++++++++++++++ .../nordic_nrf/include/RTE_Device.h | 52 ++++++++++++++ .../nordic_nrf/include/device_cfg.h | 32 +++++++++ .../nordic_nrf/include/tfm_ioctl_api.h | 32 +++++++++ .../include/tfm_peripherals_config.h | 40 +++++++++++ .../nordic_nrf/include/tfm_read_ranges.h | 60 +++++++++++++++++ .../nordic_nrf/include/util/array.h | 20 ++++++ .../nordic_nrf/nrf5340_cpuapp/CMakeLists.txt | 12 ++++ .../nordic_nrf/nrf5340_cpuapp/config.cmake | 8 +++ .../nordic_nrf/nrf5340_cpuapp/preload.cmake | 7 ++ .../nordic_nrf/nrf9120/CMakeLists.txt | 12 ++++ .../nordic_nrf/nrf9120/config.cmake | 8 +++ .../nordic_nrf/nrf9120/preload.cmake | 7 ++ .../nordic_nrf/nrf9160/CMakeLists.txt | 12 ++++ .../nordic_nrf/nrf9160/config.cmake | 8 +++ .../nordic_nrf/nrf9160/preload.cmake | 7 ++ .../nordic_nrf/src/tfm_hal_platform.c | 13 ++++ .../nordic_nrf/src/tfm_platform_system.c | 38 +++++++++++ soc/arm/nordic_nrf/CMakeLists.txt | 4 ++ soc/arm/nordic_nrf/Kconfig | 7 ++ 21 files changed, 449 insertions(+), 3 deletions(-) create mode 100644 modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt create mode 100644 modules/trusted-firmware-m/nordic_nrf/include/RTE_Device.h create mode 100644 modules/trusted-firmware-m/nordic_nrf/include/device_cfg.h create mode 100644 modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h create mode 100644 modules/trusted-firmware-m/nordic_nrf/include/tfm_peripherals_config.h create mode 100644 modules/trusted-firmware-m/nordic_nrf/include/tfm_read_ranges.h create mode 100644 modules/trusted-firmware-m/nordic_nrf/include/util/array.h create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/preload.cmake create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9120/preload.cmake create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9160/preload.cmake create mode 100644 modules/trusted-firmware-m/nordic_nrf/src/tfm_hal_platform.c create mode 100644 modules/trusted-firmware-m/nordic_nrf/src/tfm_platform_system.c diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index a7276d79374..7fd1b348a74 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -9,9 +9,6 @@ config ZEPHYR_TRUSTED_FIRMWARE_M_MODULE config TFM_BOARD string - default "nordic_nrf/nrf9160dk_nrf9160" if BOARD_NRF9160DK_NRF9160_NS - default "nordic_nrf/nrf9161dk_nrf9161" if BOARD_NRF9161DK_NRF9161_NS - default "nordic_nrf/nrf5340dk_nrf5340_cpuapp" if BOARD_NRF5340DK_NRF5340_CPUAPP_NS default "nxp/lpcxpresso55s69" if BOARD_LPCXPRESSO55S69_CPU0 default "arm/mps2/an521" if BOARD_MPS2_AN521_CPU0_NS default "arm/mps3/an547" if BOARD_MPS3_AN547 @@ -21,6 +18,9 @@ config TFM_BOARD default "arm/musca_b1" if BOARD_MUSCA_B1 default "arm/musca_s1" if BOARD_MUSCA_S1 default "lairdconnectivity/bl5340_dvk_cpuapp" if BOARD_BL5340_DVK_CPUAPP_NS + default "${ZEPHYR_BASE}/modules/trusted-firmware-m/nordic_nrf/nrf9160" if SOC_NRF9160 + default "${ZEPHYR_BASE}/modules/trusted-firmware-m/nordic_nrf/nrf9120" if SOC_NRF9120 + default "${ZEPHYR_BASE}/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp" if SOC_NRF5340_CPUAPP help The board name used for building TFM. Building with TFM requires that TFM has been ported to the given board/SoC. diff --git a/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt new file mode 100644 index 00000000000..41dca2f15a9 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt @@ -0,0 +1,67 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +cmake_policy(SET CMP0076 NEW) +set(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}) + +set(partition_includes + ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/${NRF_SOC_VARIANT}/partition + ${CMAKE_BINARY_DIR}/../zephyr/include/generated +) + +set(board_includes + ${CMAKE_BINARY_DIR}/../zephyr/misc/generated/syscalls_links/include + ${ZEPHYR_BASE}/include +) + +target_include_directories(platform_region_defs + INTERFACE + ${partition_includes} +) + + +target_sources(platform_s + PRIVATE + $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/tfm_platform_system.c> +) + +target_include_directories(platform_s + PUBLIC + services/include + include + ${partition_includes} + ${board_includes} +) + +target_include_directories(platform_ns + PUBLIC + include + include/util + ${partition_includes} + ${board_includes} +) + +if(BL2) + target_include_directories(platform_bl2 + PUBLIC + include + include/util + ${partition_includes} + ${board_includes} + ) +endif() + +if (TFM_PARTITION_PLATFORM) +install(FILES include/tfm_ioctl_api.h + DESTINATION ${TFM_INSTALL_PATH}/interface/include) +endif() + +#========================= tfm_spm ============================================# + +target_sources(tfm_spm + PRIVATE + src/tfm_hal_platform.c +) diff --git a/modules/trusted-firmware-m/nordic_nrf/include/RTE_Device.h b/modules/trusted-firmware-m/nordic_nrf/include/RTE_Device.h new file mode 100644 index 00000000000..ca886583fa9 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/include/RTE_Device.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __RTE_DEVICE_H +#define __RTE_DEVICE_H + +#include + +/* ARRAY_SIZE causes a conflict as it is defined both by TF-M and indirectly by devicetree.h */ +#undef ARRAY_SIZE +#include + +#define UART_PIN_INIT(node_id, prop, idx) \ + DT_PROP_BY_IDX(node_id, prop, idx), + +/* Configuration settings for Driver_USART0. */ +#if DOMAIN_NS == 1U + +#define RTE_USART0 1 + +#define RTE_USART0_PINS \ +{ \ + DT_FOREACH_CHILD_VARGS( \ + DT_PINCTRL_BY_NAME(DT_NODELABEL(uart0), default, 0), \ + DT_FOREACH_PROP_ELEM, psels, UART_PIN_INIT \ + ) \ +} + +#endif + +/* Configuration settings for Driver_USART1. */ +#if DT_PINCTRL_HAS_NAME(DT_NODELABEL(uart1), default) && DOMAIN_NS != 1U + +#define RTE_USART1 1 + +#define RTE_USART1_PINS \ +{ \ + DT_FOREACH_CHILD_VARGS( \ + DT_PINCTRL_BY_NAME(DT_NODELABEL(uart1), default, 0), \ + DT_FOREACH_PROP_ELEM, psels, UART_PIN_INIT \ + ) \ +} + +#endif + +/* Configuration settings for Driver_FLASH0. */ +#define RTE_FLASH0 1 + +#endif /* __RTE_DEVICE_H */ diff --git a/modules/trusted-firmware-m/nordic_nrf/include/device_cfg.h b/modules/trusted-firmware-m/nordic_nrf/include/device_cfg.h new file mode 100644 index 00000000000..9b766a35eb9 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/include/device_cfg.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef DEVICE_CFG_H__ +#define DEVICE_CFG_H__ + +#include + +/* ARRAY_SIZE causes a conflict as it is defined both by TF-M and indirectly by devicetree.h */ +#undef ARRAY_SIZE +#include + +#if DOMAIN_NS == 1U +#define TFM_UART uart0 +#endif + +#if DOMAIN_NS != 1U +#define TFM_UART uart1 +#endif + +#define DEFAULT_UART_BAUDRATE DT_PROP_OR(DT_NODELABEL(TFM_UART), current_speed, 115200) + +#if DT_PROP(DT_NODELABEL(TFM_UART), hw_flow_control) +#define DEFAULT_UART_CONTROL ARM_USART_FLOW_CONTROL_RTS_CTS +#else +#define DEFAULT_UART_CONTROL 0 +#endif + +#endif /* DEVICE_CFG_H__ */ diff --git a/modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h b/modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h new file mode 100644 index 00000000000..c6c36ee927f --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef TFM_IOCTL_API_H__ +#define TFM_IOCTL_API_H__ + +#include +#include +#include +#include + +/* Include core IOCTL services */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Board specific IOCTL services can be added here */ + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif /* TFM_IOCTL_API_H__ */ diff --git a/modules/trusted-firmware-m/nordic_nrf/include/tfm_peripherals_config.h b/modules/trusted-firmware-m/nordic_nrf/include/tfm_peripherals_config.h new file mode 100644 index 00000000000..577b583ad03 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/include/tfm_peripherals_config.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef TFM_PERIPHERALS_CONFIG_H__ +#define TFM_PERIPHERALS_CONFIG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SECURE_UART1 +#define TFM_PERIPHERAL_UARTE1_SECURE 1 +#endif + +#if TEST_NS_SLIH_IRQ || TEST_NS_FLIH_IRQ +#define TFM_PERIPHERAL_TIMER0_SECURE 1 +#endif + +#ifdef PSA_API_TEST_IPC +#define TFM_PERIPHERAL_EGU5_SECURE 1 + +#define TFM_PERIPHERAL_WDT_SECURE 1 +#endif + +#if defined(NRF91_SERIES) + #include +#elif defined(NRF5340_XXAA_APPLICATION) + #include +#else + #error "Unknown device." +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* TFM_PERIPHERAL_CONFIG_H__ */ diff --git a/modules/trusted-firmware-m/nordic_nrf/include/tfm_read_ranges.h b/modules/trusted-firmware-m/nordic_nrf/include/tfm_read_ranges.h new file mode 100644 index 00000000000..43468c7fa31 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/include/tfm_read_ranges.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef TFM_READ_RANGES_H__ +#define TFM_READ_RANGES_H__ + +#include + +#include + +#ifdef NRF_FICR_S_BASE + +#define FICR_BASE NRF_FICR_S_BASE + +#define FICR_INFO_ADDR (FICR_BASE + offsetof(NRF_FICR_Type, INFO)) +#define FICR_INFO_SIZE (sizeof(FICR_INFO_Type)) + +#if defined(FICR_NFC_TAGHEADER0_MFGID_Msk) +#define FICR_NFC_ADDR (FICR_BASE + offsetof(NRF_FICR_Type, NFC)) +#define FICR_NFC_SIZE (sizeof(FICR_NFC_Type)) +#endif + +#if defined(FICR_XOSC32MTRIM_SLOPE_Msk) +#define FICR_XOSC32MTRIM_ADDR (FICR_BASE + offsetof(NRF_FICR_Type, XOSC32MTRIM)) +#define FICR_XOSC32MTRIM_SIZE (sizeof(uint32_t)) +#endif + +/* Used by nrf_erratas.h */ +#define FICR_RESTRICTED_ADDR (FICR_BASE + 0x130) +#define FICR_RESTRICTED_SIZE 0x8 + +#if defined(FICR_SIPINFO_PARTNO_PARTNO_Pos) +#define FICR_SIPINFO_ADDR (FICR_BASE + offsetof(NRF_FICR_Type, SIPINFO)) +#define FICR_SIPINFO_SIZE (sizeof(FICR_SIPINFO_Type)) +#endif + +#endif /* NRF_FICR_S_BASE */ + +static const struct tfm_read_service_range ranges[] = { +#if defined(FICR_INFO_ADDR) + { .start = FICR_INFO_ADDR, .size = FICR_INFO_SIZE }, +#endif +#if defined(FICR_NFC_ADDR) + { .start = FICR_NFC_ADDR, .size = FICR_NFC_SIZE }, +#endif +#if defined(FICR_RESTRICTED_ADDR) + { .start = FICR_RESTRICTED_ADDR, .size = FICR_RESTRICTED_SIZE }, +#endif +#if defined(FICR_XOSC32MTRIM_ADDR) + { .start = FICR_XOSC32MTRIM_ADDR, .size = FICR_XOSC32MTRIM_SIZE }, +#endif +#if defined(FICR_SIPINFO_ADDR) + { .start = FICR_SIPINFO_ADDR, .size = FICR_SIPINFO_SIZE }, +#endif +}; + +#endif /* TFM_READ_RANGES_H__ */ diff --git a/modules/trusted-firmware-m/nordic_nrf/include/util/array.h b/modules/trusted-firmware-m/nordic_nrf/include/util/array.h new file mode 100644 index 00000000000..dc9a1f3dddf --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/include/util/array.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __ARRAY_H__ +#define __ARRAY_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#ifdef __cplusplus +} +#endif + +#endif /* __ARRAY_H__ */ diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt new file mode 100644 index 00000000000..279ea385996 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +set(NRF_BOARD_SELECTED True) +set(NRF_SOC_VARIANT nrf5340) + +add_subdirectory(${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/nrf5340 nrf5340) + +add_subdirectory(.. common) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake new file mode 100644 index 00000000000..b3e5d74181c --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake @@ -0,0 +1,8 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +set(PLATFORM_PATH platform/ext/target/nordic_nrf/) +include(${PLATFORM_PATH}/common/nrf5340/config.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/preload.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/preload.cmake new file mode 100644 index 00000000000..d9bd226eb65 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/preload.cmake @@ -0,0 +1,7 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +include(platform/ext/target/nordic_nrf/common/nrf5340/preload.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt new file mode 100644 index 00000000000..a84c6fd9fd5 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +set(NRF_BOARD_SELECTED True) +set(NRF_SOC_VARIANT nrf91) + +add_subdirectory(${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/nrf91 nrf91) + +add_subdirectory(.. common) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake new file mode 100644 index 00000000000..3f58e7b89eb --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake @@ -0,0 +1,8 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +set(PLATFORM_PATH platform/ext/target/nordic_nrf/) +include(${PLATFORM_PATH}/common/nrf91/config.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/preload.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9120/preload.cmake new file mode 100644 index 00000000000..4b3c6ee79ab --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9120/preload.cmake @@ -0,0 +1,7 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +include(platform/ext/target/nordic_nrf/common/nrf9120/preload.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt new file mode 100644 index 00000000000..a84c6fd9fd5 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +set(NRF_BOARD_SELECTED True) +set(NRF_SOC_VARIANT nrf91) + +add_subdirectory(${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/nrf91 nrf91) + +add_subdirectory(.. common) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake new file mode 100644 index 00000000000..3f58e7b89eb --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake @@ -0,0 +1,8 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +set(PLATFORM_PATH platform/ext/target/nordic_nrf/) +include(${PLATFORM_PATH}/common/nrf91/config.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/preload.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9160/preload.cmake new file mode 100644 index 00000000000..364480a6f7f --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9160/preload.cmake @@ -0,0 +1,7 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +include(platform/ext/target/nordic_nrf/common/nrf9160/preload.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/src/tfm_hal_platform.c b/modules/trusted-firmware-m/nordic_nrf/src/tfm_hal_platform.c new file mode 100644 index 00000000000..508c1945910 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/src/tfm_hal_platform.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "tfm_hal_defs.h" +#include "tfm_hal_platform_common.h" + +enum tfm_hal_status_t tfm_hal_platform_init(void) +{ + return tfm_hal_platform_common_init(); +} diff --git a/modules/trusted-firmware-m/nordic_nrf/src/tfm_platform_system.c b/modules/trusted-firmware-m/nordic_nrf/src/tfm_platform_system.c new file mode 100644 index 00000000000..b96e1fe1188 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/src/tfm_platform_system.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "platform/include/tfm_platform_system.h" +#include "cmsis.h" +#include "tfm_platform_hal_ioctl.h" +#include "tfm_ioctl_core_api.h" + +void tfm_platform_hal_system_reset(void) +{ + /* Reset the system */ + NVIC_SystemReset(); +} + +enum tfm_platform_err_t tfm_platform_hal_ioctl(tfm_platform_ioctl_req_t request, + psa_invec *in_vec, + psa_outvec *out_vec) +{ + /* Core IOCTL services */ + switch (request) { + case TFM_PLATFORM_IOCTL_READ_SERVICE: + return tfm_platform_hal_read_service(in_vec, out_vec); +#if defined(GPIO_PIN_CNF_MCUSEL_Msk) + case TFM_PLATFORM_IOCTL_GPIO_SERVICE: + return tfm_platform_hal_gpio_service(in_vec, out_vec); +#endif /* defined(GPIO_PIN_CNF_MCUSEL_Msk) */ + + + /* Board specific IOCTL services */ + + /* Not a supported IOCTL service.*/ + default: + return TFM_PLATFORM_ERR_NOT_SUPPORTED; + } +} diff --git a/soc/arm/nordic_nrf/CMakeLists.txt b/soc/arm/nordic_nrf/CMakeLists.txt index 4cfc162f7fd..47364b35ffb 100644 --- a/soc/arm/nordic_nrf/CMakeLists.txt +++ b/soc/arm/nordic_nrf/CMakeLists.txt @@ -21,4 +21,8 @@ if(CONFIG_BUILD_WITH_TFM) set_property(TARGET zephyr_property_target APPEND PROPERTY TFM_CMAKE_OPTIONS -DHAL_NORDIC_PATH=${ZEPHYR_HAL_NORDIC_MODULE_DIR} ) + + set_property(TARGET zephyr_property_target + APPEND PROPERTY TFM_CMAKE_OPTIONS -DZEPHYR_BASE=${ZEPHYR_BASE} + ) endif() diff --git a/soc/arm/nordic_nrf/Kconfig b/soc/arm/nordic_nrf/Kconfig index c2129db64b3..0e3b3e4ee6d 100644 --- a/soc/arm/nordic_nrf/Kconfig +++ b/soc/arm/nordic_nrf/Kconfig @@ -25,6 +25,13 @@ config NRF_SOC_SECURE_SUPPORTED For non-secure the functions must redirect to secure services exposed by the secure firmware. +config TFM_LOG_LEVEL_SILENCE + default y if !$(dt_nodelabel_has_prop,uart1,pinctrl-names) + depends on BUILD_WITH_TFM + help + Disable TF-M secure output if the uart1 node has not assigned GPIO + pins using pinctrl. + config NRF_MPU_FLASH_REGION_SIZE hex default 0x1000 From 4a3c39feef9ad6dcbb8fbe787f4aef5cc57fdbb3 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 5 May 2022 12:04:26 +0200 Subject: [PATCH 0353/1623] [nrf fromtree] boards: Enable TF-M by default for nordic SoC NS boards Enable TF-M by default for nordic nRF5340 and nrf9160 SoC boards. Signed-off-by: Joakim Andersson (cherry picked from commit 17fd1f8fba3bd862c53ca98f618ac574efef58dd) Signed-off-by: Joakim Andersson --- boards/arm/bl5340_dvk/Kconfig.defconfig | 15 --------------- boards/arm/nrf5340dk_nrf5340/Kconfig.defconfig | 15 --------------- boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig | 15 --------------- boards/arm/nrf9161dk_nrf9161/Kconfig.defconfig | 15 --------------- soc/arm/nordic_nrf/Kconfig | 18 +++++++++++++++++- 5 files changed, 17 insertions(+), 61 deletions(-) diff --git a/boards/arm/bl5340_dvk/Kconfig.defconfig b/boards/arm/bl5340_dvk/Kconfig.defconfig index 38a06c8b91d..e033f718dba 100644 --- a/boards/arm/bl5340_dvk/Kconfig.defconfig +++ b/boards/arm/bl5340_dvk/Kconfig.defconfig @@ -13,21 +13,6 @@ config BOARD config I2C default GPIO || DAC -# By default, if we build for a Non-Secure version of the board, -# enable building with TF-M as the Secure Execution Environment. -config BUILD_WITH_TFM - default y if BOARD_BL5340_DVK_CPUAPP_NS - -if BUILD_WITH_TFM - -# By default, if we build with TF-M, instruct build system to -# flash the combined TF-M (Secure) & Zephyr (Non Secure) image -config TFM_FLASH_MERGED_BINARY - bool - default y - -endif # BUILD_WITH_TFM - # Code Partition: # # For the secure version of the board the firmware is linked at the beginning diff --git a/boards/arm/nrf5340dk_nrf5340/Kconfig.defconfig b/boards/arm/nrf5340dk_nrf5340/Kconfig.defconfig index d337e2f1a1c..09ebfbf50ba 100644 --- a/boards/arm/nrf5340dk_nrf5340/Kconfig.defconfig +++ b/boards/arm/nrf5340dk_nrf5340/Kconfig.defconfig @@ -8,21 +8,6 @@ if BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_NRF5340DK_NRF5340_CPUAPP_NS config BOARD default "nrf5340dk_nrf5340_cpuapp" if BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_NRF5340DK_NRF5340_CPUAPP_NS -# By default, if we build for a Non-Secure version of the board, -# enable building with TF-M as the Secure Execution Environment. -config BUILD_WITH_TFM - default y if BOARD_NRF5340DK_NRF5340_CPUAPP_NS - -if BUILD_WITH_TFM - -# By default, if we build with TF-M, instruct build system to -# flash the combined TF-M (Secure) & Zephyr (Non Secure) image -config TFM_FLASH_MERGED_BINARY - bool - default y - -endif # BUILD_WITH_TFM - # Code Partition: # # For the secure version of the board the firmware is linked at the beginning diff --git a/boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig b/boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig index cd052dc7a20..7d9046f63b5 100644 --- a/boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig +++ b/boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig @@ -8,21 +8,6 @@ if BOARD_NRF9160DK_NRF9160 || BOARD_NRF9160DK_NRF9160_NS config BOARD default "nrf9160dk_nrf9160" -# By default, if we build for a Non-Secure version of the board, -# enable building with TF-M as the Secure Execution Environment. -config BUILD_WITH_TFM - default y if BOARD_NRF9160DK_NRF9160_NS - -if BUILD_WITH_TFM - -# By default, if we build with TF-M, instruct build system to -# flash the combined TF-M (Secure) & Zephyr (Non Secure) image -config TFM_FLASH_MERGED_BINARY - bool - default y - -endif # BUILD_WITH_TFM - # For the secure version of the board the firmware is linked at the beginning # of the flash, or into the code-partition defined in DT if it is intended to # be loaded by MCUboot. If the secure firmware is to be combined with a non- diff --git a/boards/arm/nrf9161dk_nrf9161/Kconfig.defconfig b/boards/arm/nrf9161dk_nrf9161/Kconfig.defconfig index 2674e87cad4..ea7150ede5f 100644 --- a/boards/arm/nrf9161dk_nrf9161/Kconfig.defconfig +++ b/boards/arm/nrf9161dk_nrf9161/Kconfig.defconfig @@ -8,21 +8,6 @@ if BOARD_NRF9161DK_NRF9161 || BOARD_NRF9161DK_NRF9161_NS config BOARD default "nrf9161dk_nrf9161" -# By default, if we build for a Non-Secure version of the board, -# enable building with TF-M as the Secure Execution Environment. -config BUILD_WITH_TFM - default y if BOARD_NRF9161DK_NRF9161_NS - -if BUILD_WITH_TFM - -# By default, if we build with TF-M, instruct build system to -# flash the combined TF-M (Secure) & Zephyr (Non Secure) image -config TFM_FLASH_MERGED_BINARY - bool - default y - -endif # BUILD_WITH_TFM - # For the secure version of the board the firmware is linked at the beginning # of the flash, or into the code-partition defined in DT if it is intended to # be loaded by MCUboot. If the secure firmware is to be combined with a non- diff --git a/soc/arm/nordic_nrf/Kconfig b/soc/arm/nordic_nrf/Kconfig index 0e3b3e4ee6d..19e49c05454 100644 --- a/soc/arm/nordic_nrf/Kconfig +++ b/soc/arm/nordic_nrf/Kconfig @@ -25,13 +25,29 @@ config NRF_SOC_SECURE_SUPPORTED For non-secure the functions must redirect to secure services exposed by the secure firmware. +config BUILD_WITH_TFM + default y if TRUSTED_EXECUTION_NONSECURE + help + By default, if we build for a Non-Secure version of the board, + enable building with TF-M as the Secure Execution Environment. + +if BUILD_WITH_TFM + +config TFM_FLASH_MERGED_BINARY + default y + help + By default, if we build with TF-M, instruct build system to + flash the combined TF-M (Secure) & Zephyr (Non Secure) image + config TFM_LOG_LEVEL_SILENCE default y if !$(dt_nodelabel_has_prop,uart1,pinctrl-names) - depends on BUILD_WITH_TFM help Disable TF-M secure output if the uart1 node has not assigned GPIO pins using pinctrl. +endif # BUILD_WITH_TFM + + config NRF_MPU_FLASH_REGION_SIZE hex default 0x1000 From 5d85f6db2d5ec50922e809238e3b088da5727dcf Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Wed, 4 Oct 2023 12:33:04 +0200 Subject: [PATCH 0354/1623] [nrf fromtree] doc: Remove note for missing tf-m/ns target support All nRF91 and nRF5340 boards (except the DKs) should support TF-M/_ns now. Signed-off-by: Joakim Andersson (cherry picked from commit 142dd9fb138d5156b2befe9bff340ffe975e8530) Signed-off-by: Joakim Andersson --- boards/arm/nrf5340_audio_dk_nrf5340/doc/index.rst | 3 --- boards/arm/nrf9160_innblue21/doc/index.rst | 3 --- boards/arm/nrf9160_innblue22/doc/index.rst | 3 --- boards/arm/sparkfun_thing_plus_nrf9160/doc/index.rst | 3 --- boards/arm/thingy53_nrf5340/doc/index.rst | 3 --- 5 files changed, 15 deletions(-) diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/doc/index.rst b/boards/arm/nrf5340_audio_dk_nrf5340/doc/index.rst index 7718258eec2..3d8d2413e91 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/doc/index.rst +++ b/boards/arm/nrf5340_audio_dk_nrf5340/doc/index.rst @@ -53,9 +53,6 @@ The nrf5340_audio_dk_nrf5340_cpuapp build target provides support for the applic core on the nRF5340 SoC. The nrf5340_audio_dk_nrf5340_cpunet build target provides support for the network core on the nRF5340 SoC. -.. note:: - Trusted Firmware-M (TF-M) and building the ``ns`` target is not supported for this board. - The `Nordic Semiconductor Infocenter`_ contains the processor's information and the datasheet. diff --git a/boards/arm/nrf9160_innblue21/doc/index.rst b/boards/arm/nrf9160_innblue21/doc/index.rst index 628166c409c..9ded085dc6f 100644 --- a/boards/arm/nrf9160_innblue21/doc/index.rst +++ b/boards/arm/nrf9160_innblue21/doc/index.rst @@ -104,9 +104,6 @@ have to set the IDAU (SPU) configuration to allow Non-Secure access to all CPU resources utilized by the Non-Secure application firmware. SPU configuration shall take place before jumping to the Non-Secure application. -.. note:: - Trusted Firmware-M (TF-M) and building the ``ns`` target is not supported for this board. - Building a Secure only application ================================== diff --git a/boards/arm/nrf9160_innblue22/doc/index.rst b/boards/arm/nrf9160_innblue22/doc/index.rst index ce3eb35d60f..06f6b6326f8 100644 --- a/boards/arm/nrf9160_innblue22/doc/index.rst +++ b/boards/arm/nrf9160_innblue22/doc/index.rst @@ -104,9 +104,6 @@ have to set the IDAU (SPU) configuration to allow Non-Secure access to all CPU resources utilized by the Non-Secure application firmware. SPU configuration shall take place before jumping to the Non-Secure application. -.. note:: - Trusted Firmware-M (TF-M) and building the ``ns`` target is not supported for this board. - Building a Secure only application ================================== diff --git a/boards/arm/sparkfun_thing_plus_nrf9160/doc/index.rst b/boards/arm/sparkfun_thing_plus_nrf9160/doc/index.rst index 44366c49a39..aa1a0e6279d 100644 --- a/boards/arm/sparkfun_thing_plus_nrf9160/doc/index.rst +++ b/boards/arm/sparkfun_thing_plus_nrf9160/doc/index.rst @@ -91,9 +91,6 @@ Building an application In most cases you'll want to use the ``ns`` target with any of the Zephyr or Nordic based examples. -.. note:: - Trusted Firmware-M (TF-M) and building the ``ns`` target is not supported for this board. - Some of the examples do not use secure mode, so they do not required the ``ns`` suffix. A great example of this is the `hello_world` below. diff --git a/boards/arm/thingy53_nrf5340/doc/index.rst b/boards/arm/thingy53_nrf5340/doc/index.rst index 3a77deee968..4544ea7ed79 100644 --- a/boards/arm/thingy53_nrf5340/doc/index.rst +++ b/boards/arm/thingy53_nrf5340/doc/index.rst @@ -22,9 +22,6 @@ The nrf5340dk_nrf5340_cpuapp build target provides support for the application core on the nRF5340 SoC. The nrf5340dk_nrf5340_cpunet build target provides support for the network core on the nRF5340 SoC. -.. note:: - Trusted Firmware-M (TF-M) and building the ``ns`` target is not supported for this board. - The `Nordic Semiconductor Infocenter`_ contains the processor's information and the datasheet. From f189c88320733cefc0dc25bff43bc854809fc81e Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 24 Oct 2023 13:30:50 +0200 Subject: [PATCH 0355/1623] [nrf fromtree] boards: Fix nrf9160 NS flash partition layout Fix secure and non-secure images overlapping because of incompatible flash layout configurations. Align the board configurations to match the nRF9160 DK default partition layout. This enforces that the SPU alignment requirement is satisfied for the nrf9160 MCU. Signed-off-by: Joakim Andersson (cherry picked from commit dc431a7397a629c9fb7e3a27a803d11bf1103389) Signed-off-by: Joakim Andersson --- .../circuitdojo_feather_nrf9160_common.dtsi | 13 +++++-------- .../circuitdojo_feather_nrf9160_ns.yaml | 2 +- ...itdojo_feather_nrf9160_partition_conf.dtsi | 8 ++++---- .../nrf9160_innblue21_common.dtsi | 18 +++++++----------- .../nrf9160_innblue21_ns.yaml | 2 +- .../nrf9160_innblue21_partition_conf.dtsi | 8 ++++---- .../nrf9160_innblue22_common.dtsi | 19 ++++++++----------- .../nrf9160_innblue22_ns.yaml | 2 +- .../nrf9160_innblue22_partition_conf.dtsi | 8 ++++---- .../sparkfun_thing_plus_nrf9160_common.dtsi | 13 +++++-------- .../sparkfun_thing_plus_nrf9160_ns.yaml | 2 +- ...fun_thing_plus_nrf9160_partition_conf.dtsi | 8 ++++---- 12 files changed, 45 insertions(+), 58 deletions(-) diff --git a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dtsi b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dtsi index 33fdba4d865..00ce5dcf6c0 100644 --- a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dtsi +++ b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dtsi @@ -187,22 +187,19 @@ slot0_partition: partition@10000 { label = "image-0"; }; - slot0_ns_partition: partition@40000 { + slot0_ns_partition: partition@50000 { label = "image-0-nonsecure"; }; slot1_partition: partition@80000 { label = "image-1"; }; - slot1_ns_partition: partition@b0000 { + slot1_ns_partition: partition@c0000 { label = "image-1-nonsecure"; }; - scratch_partition: partition@f0000 { - label = "image-scratch"; - reg = <0x000f0000 0xa000>; - }; - storage_partition: partition@fa000 { + /* 0xf0000 to 0xf7fff reserved for TF-M partitions */ + storage_partition: partition@f8000 { label = "storage"; - reg = <0x000fa000 0x00006000>; + reg = <0x000f8000 0x00008000>; }; }; }; diff --git a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_ns.yaml b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_ns.yaml index c358a1d87fe..56905972e9f 100644 --- a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_ns.yaml +++ b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_ns.yaml @@ -7,7 +7,7 @@ toolchain: - xtools - zephyr ram: 128 -flash: 256 +flash: 192 supported: - i2c - pwm diff --git a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_partition_conf.dtsi b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_partition_conf.dtsi index e8cb6fc586e..007975132d6 100644 --- a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_partition_conf.dtsi +++ b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_partition_conf.dtsi @@ -23,19 +23,19 @@ */ &slot0_partition { - reg = <0x00010000 0x30000>; + reg = <0x00010000 0x40000>; }; &slot0_ns_partition { - reg = <0x00040000 0x40000>; + reg = <0x00050000 0x30000>; }; &slot1_partition { - reg = <0x00080000 0x30000>; + reg = <0x00080000 0x40000>; }; &slot1_ns_partition { - reg = <0x000b0000 0x40000>; + reg = <0x000c0000 0x30000>; }; /* Default SRAM planning when building for nRF9160 with diff --git a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dtsi b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dtsi index 0abfd4d6b9c..0ec5de5dfb1 100644 --- a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dtsi +++ b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dtsi @@ -168,27 +168,23 @@ boot_partition: partition@0 { label = "mcuboot"; - reg = <0x00000000 0xc000>; + reg = <0x00000000 0x10000>; }; - slot0_partition: partition@c000 { + slot0_partition: partition@10000 { label = "image-0"; }; - slot0_ns_partition: partition@3e000 { + slot0_ns_partition: partition@50000 { label = "image-0-nonsecure"; }; - slot1_partition: partition@7e000 { + slot1_partition: partition@80000 { label = "image-1"; }; - slot1_ns_partition: partition@b0000 { + slot1_ns_partition: partition@c0000 { label = "image-1-nonsecure"; }; - scratch_partition: partition@f0000 { - label = "image-scratch"; - reg = <0x000f0000 0xa000>; - }; - storage_partition: partition@fa000 { + storage_partition: partition@f8000 { label = "storage"; - reg = <0x000fa000 0x00006000>; + reg = <0x000f8000 0x00008000>; }; }; }; diff --git a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_ns.yaml b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_ns.yaml index 096821d8364..4584ad0e6a4 100644 --- a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_ns.yaml +++ b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_ns.yaml @@ -7,7 +7,7 @@ toolchain: - xtools - zephyr ram: 128 -flash: 256 +flash: 192 supported: - i2c - pwm diff --git a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_partition_conf.dtsi b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_partition_conf.dtsi index d3a30abdc76..2c64ba67a8a 100644 --- a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_partition_conf.dtsi +++ b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_partition_conf.dtsi @@ -22,19 +22,19 @@ */ &slot0_partition { - reg = <0x0000c000 0x30000>; + reg = <0x00010000 0x40000>; }; &slot0_ns_partition { - reg = <0x0003e000 0x40000>; + reg = <0x00050000 0x30000>; }; &slot1_partition { - reg = <0x0007e000 0x30000>; + reg = <0x00080000 0x40000>; }; &slot1_ns_partition { - reg = <0x000b0000 0x40000>; + reg = <0x000c0000 0x30000>; }; /* Default SRAM planning when building for nRF9160 with diff --git a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dtsi b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dtsi index 4582f975f5d..4738dd84a63 100644 --- a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dtsi +++ b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dtsi @@ -171,27 +171,24 @@ boot_partition: partition@0 { label = "mcuboot"; - reg = <0x00000000 0xc000>; + reg = <0x00000000 0x10000>; }; - slot0_partition: partition@c000 { + slot0_partition: partition@10000 { label = "image-0"; }; - slot0_ns_partition: partition@3e000 { + slot0_ns_partition: partition@50000 { label = "image-0-nonsecure"; }; - slot1_partition: partition@7e000 { + slot1_partition: partition@80000 { label = "image-1"; }; - slot1_ns_partition: partition@b0000 { + slot1_ns_partition: partition@c0000 { label = "image-1-nonsecure"; }; - scratch_partition: partition@f0000 { - label = "image-scratch"; - reg = <0x000f0000 0xa000>; - }; - storage_partition: partition@fa000 { + /* 0xf0000 to 0xf7fff reserved for TF-M partitions */ + storage_partition: partition@f8000 { label = "storage"; - reg = <0x000fa000 0x00006000>; + reg = <0x000f8000 0x00008000>; }; }; }; diff --git a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_ns.yaml b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_ns.yaml index 2ce0d6e3db2..0186c26a377 100644 --- a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_ns.yaml +++ b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_ns.yaml @@ -7,7 +7,7 @@ toolchain: - xtools - zephyr ram: 128 -flash: 256 +flash: 192 supported: - i2c - pwm diff --git a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_partition_conf.dtsi b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_partition_conf.dtsi index 3588a6a7ce1..b14640a02ec 100644 --- a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_partition_conf.dtsi +++ b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_partition_conf.dtsi @@ -22,19 +22,19 @@ */ &slot0_partition { - reg = <0x0000c000 0x30000>; + reg = <0x00010000 0x40000>; }; &slot0_ns_partition { - reg = <0x0003e000 0x40000>; + reg = <0x00050000 0x30000>; }; &slot1_partition { - reg = <0x0007e000 0x30000>; + reg = <0x00080000 0x40000>; }; &slot1_ns_partition { - reg = <0x000b0000 0x40000>; + reg = <0x000c0000 0x30000>; }; /* Default SRAM planning when building for nRF9160 with diff --git a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dtsi b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dtsi index b85c00ea5b2..2658ee5eaa4 100644 --- a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dtsi +++ b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dtsi @@ -185,22 +185,19 @@ slot0_partition: partition@10000 { label = "image-0"; }; - slot0_ns_partition: partition@40000 { + slot0_ns_partition: partition@50000 { label = "image-0-nonsecure"; }; slot1_partition: partition@80000 { label = "image-1"; }; - slot1_ns_partition: partition@b0000 { + slot1_ns_partition: partition@c0000 { label = "image-1-nonsecure"; }; - scratch_partition: partition@f0000 { - label = "image-scratch"; - reg = <0x000f0000 0xa000>; - }; - storage_partition: partition@fa000 { + /* 0xf0000 to 0xf7fff reserved for TF-M partitions */ + storage_partition: partition@f8000 { label = "storage"; - reg = <0x000fa000 0x00006000>; + reg = <0x000f8000 0x00008000>; }; }; }; diff --git a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_ns.yaml b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_ns.yaml index e667a231774..adbef49e2b0 100644 --- a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_ns.yaml +++ b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_ns.yaml @@ -7,7 +7,7 @@ toolchain: - xtools - zephyr ram: 128 -flash: 256 +flash: 192 supported: - i2c - pwm diff --git a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_partition_conf.dtsi b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_partition_conf.dtsi index 2422b2fdc52..64591fbf900 100644 --- a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_partition_conf.dtsi +++ b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_partition_conf.dtsi @@ -23,19 +23,19 @@ */ &slot0_partition { - reg = <0x00010000 0x30000>; + reg = <0x00010000 0x40000>; }; &slot0_ns_partition { - reg = <0x00040000 0x40000>; + reg = <0x00050000 0x30000>; }; &slot1_partition { - reg = <0x00080000 0x30000>; + reg = <0x00080000 0x40000>; }; &slot1_ns_partition { - reg = <0x000b0000 0x40000>; + reg = <0x000c0000 0x30000>; }; /* Default SRAM planning when building for nRF9160 with From ad501cb7ca3ce9951ea4fb21b4c21291e0680664 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 26 Oct 2023 10:57:30 +0200 Subject: [PATCH 0356/1623] [nrf fromtree] tfm: Add BL2 log level configuration and disable it with TFM silent conf Add choice for BL2 log level configuration. Silence TF-M BL2 logging when TF-M is configured to be silent. Signed-off-by: Joakim Andersson (cherry picked from commit 96c5052733be0eb73da2c47eb2c85e18ec54fca9) Signed-off-by: Joakim Andersson --- modules/trusted-firmware-m/CMakeLists.txt | 19 +++++++++++++++++++ modules/trusted-firmware-m/Kconfig.tfm | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index 0c01858f34d..f00116cda2c 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -101,6 +101,25 @@ if (CONFIG_BUILD_WITH_TFM) list(APPEND TFM_CMAKE_ARGS -DTFM_EXCEPTION_INFO_DUMP=OFF) endif() + if (CONFIG_TFM_BL2) + if (CONFIG_TFM_BL2_LOG_LEVEL_DEBUG) + set(TFM_BL2_LOG_LEVEL "DEBUG") + elseif (CONFIG_TFM_BL2_LOG_LEVEL_INFO) + set(TFM_BL2_LOG_LEVEL "INFO") + elseif (CONFIG_TFM_BL2_LOG_LEVEL_WARNING) + set(TFM_BL2_LOG_LEVEL "WARNING") + elseif (CONFIG_TFM_BL2_LOG_LEVEL_ERROR) + set(TFM_BL2_LOG_LEVEL "ERROR") + elseif (CONFIG_TFM_BL2_LOG_LEVEL_OFF OR CONFIG_TFM_LOG_LEVEL_SILENCE) + set(TFM_BL2_LOG_LEVEL "OFF") + endif() + + if (DEFINED TFM_BL2_LOG_LEVEL) + # BL2 uses MCUBOOT_LOG_LEVEL configuration + list(APPEND TFM_CMAKE_ARGS -DMCUBOOT_LOG_LEVEL=${TFM_BL2_LOG_LEVEL}) + endif() + endif() + if (CONFIG_TFM_PARTITION_LOG_LEVEL_DEBUG) set(TFM_PARTITION_LOG_LEVEL "TFM_PARTITION_LOG_LEVEL_DEBUG") elseif (CONFIG_TFM_PARTITION_LOG_LEVEL_INFO) diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index 7fd1b348a74..bafa5cf0bab 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -397,6 +397,21 @@ config ROM_START_OFFSET needs to be updated if TF-M switches to use a different header size for BL2. +choice TFM_BL2_LOG_LEVEL + prompt "BL2 Log Level" if !TFM_LOG_LEVEL_SILENCE + default TFM_BL2_LOG_LEVEL_INFO + config TFM_BL2_LOG_LEVEL_DEBUG + bool "Debug" + config TFM_BL2_LOG_LEVEL_INFO + bool "Info" + config TFM_BL2_LOG_LEVEL_WARNING + bool "Warning" + config TFM_BL2_LOG_LEVEL_ERROR + bool "Error" + config TFM_BL2_LOG_LEVEL_OFF + bool "Off" +endchoice + endif # !TFM_BL2 # Option to instruct flashing a merged binary consisting of BL2 (optionally), From ff85910bf8ed1aac0571bca0e7f206782234efbb Mon Sep 17 00:00:00 2001 From: Marek Pieta Date: Mon, 28 Nov 2022 15:31:33 +0100 Subject: [PATCH 0357/1623] [nrf noup] boards: thingy53_nrf5340: Enable MCUboot by default Change enables MCUboot bootloader by default to allow programming samples and applications without external programmer (using MCUboot serial recovery). Change also enables network core to prevent build failures when building MCUboot with nRF53 multi image DFU. Jira: NCSDK-18263 Signed-off-by: Marek Pieta Signed-off-by: Vinayak Kariappa Chettimada Signed-off-by: Johann Fischer (cherry picked from commit 46895493bf1b0988e44ea344f4420b543e307eae) (cherry picked from commit ff1db43269579e2a0bdc28c55f2c83d3ad58ebb7) Signed-off-by: Joakim Andersson --- boards/arm/thingy53_nrf5340/Kconfig.defconfig | 6 ++++++ boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi | 1 + 2 files changed, 7 insertions(+) diff --git a/boards/arm/thingy53_nrf5340/Kconfig.defconfig b/boards/arm/thingy53_nrf5340/Kconfig.defconfig index 6384d163d93..b6080de9a80 100644 --- a/boards/arm/thingy53_nrf5340/Kconfig.defconfig +++ b/boards/arm/thingy53_nrf5340/Kconfig.defconfig @@ -8,6 +8,12 @@ if BOARD_THINGY53_NRF5340_CPUAPP || BOARD_THINGY53_NRF5340_CPUAPP_NS config BOARD default "thingy53_nrf5340_cpuapp" +config BOOTLOADER_MCUBOOT + default y if !MCUBOOT + +config BOARD_ENABLE_CPUNET + default y if !MCUBOOT + # Code Partition: # # For the secure version of the board the firmware is linked at the beginning diff --git a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi index 341bb1305e1..515fc3bea7b 100644 --- a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi +++ b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dtsi @@ -16,6 +16,7 @@ zephyr,bt-hci-rpmsg-ipc = &ipc0; nordic,802154-spinel-ipc = &ipc0; zephyr,ieee802154 = &ieee802154; + nordic,pm-ext-flash = &mx25r64; }; buttons { From b715be6b467b45eaa6f3688f2117a39a1e19985a Mon Sep 17 00:00:00 2001 From: Rodrigo Peixoto Date: Sat, 2 Sep 2023 13:35:14 -0300 Subject: [PATCH 0358/1623] [nrf fromtree] zbus: Add Message subscriber Besides the changed channel reference, the message subscribers receive a copy of the message during the VDED execution. ZBus guarantees message delivery for `MSG_SUBSCRIBERS`. Signed-off-by: Rodrigo Peixoto (cherry picked from commit 0b0aa435afc8b0102b437ae145203daada6c616b) Signed-off-by: Alexander Svensen --- include/zephyr/zbus/zbus.h | 68 +++++++++++++++++- subsys/zbus/Kconfig | 30 ++++++++ subsys/zbus/zbus.c | 144 +++++++++++++++++++++++++++++++------ 3 files changed, 219 insertions(+), 23 deletions(-) diff --git a/include/zephyr/zbus/zbus.h b/include/zephyr/zbus/zbus.h index 466a2ad9dcf..8a4188aa821 100644 --- a/include/zephyr/zbus/zbus.h +++ b/include/zephyr/zbus/zbus.h @@ -92,7 +92,8 @@ struct zbus_channel { */ enum __packed zbus_observer_type { ZBUS_OBSERVER_LISTENER_TYPE, - ZBUS_OBSERVER_SUBSCRIBER_TYPE + ZBUS_OBSERVER_SUBSCRIBER_TYPE, + ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE, }; /** @@ -127,6 +128,13 @@ struct zbus_observer { /** Observer callback function. It turns the observer into a listener. */ void (*const callback)(const struct zbus_channel *chan); + +#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) || defined(__DOXYGEN__) + /** Observer message FIFO. It turns the observer into a message subscriber. It only + * exists if the @kconfig{CONFIG_ZBUS_MSG_SUBSCRIBER} is enabled. + */ + struct k_fifo *const message_fifo; +#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ }; }; @@ -156,8 +164,10 @@ struct zbus_channel_observation { #if defined(CONFIG_ZBUS_CHANNEL_NAME) #define ZBUS_CHANNEL_NAME_INIT(_name) .name = #_name, +#define _ZBUS_CHAN_NAME(_chan) (_chan)->name #else #define ZBUS_CHANNEL_NAME_INIT(_name) +#define _ZBUS_CHAN_NAME(_chan) "" #endif #if defined(CONFIG_ZBUS_OBSERVER_NAME) @@ -379,6 +389,37 @@ k_timeout_t _zbus_timeout_remainder(uint64_t end_ticks); */ #define ZBUS_LISTENER_DEFINE(_name, _cb) ZBUS_LISTENER_DEFINE_WITH_ENABLE(_name, _cb, true) +/** + * @brief Define and initialize a message subscriber. + * + * This macro defines an observer of @ref ZBUS_OBSERVER_SUBSCRIBER_TYPE type. It defines a FIFO + * where the subscriber will receive the message asynchronously and initialize the @ref + * zbus_observer defining the subscriber. + * + * @param[in] _name The subscriber's name. + * @param[in] _enable The subscriber's initial state. + */ +#define ZBUS_MSG_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, _enable) \ + static K_FIFO_DEFINE(_zbus_observer_fifo_##_name); \ + STRUCT_SECTION_ITERABLE(zbus_observer, _name) = { \ + ZBUS_OBSERVER_NAME_INIT(_name) /* Name field */ \ + .type = ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE, \ + .enabled = _enable, \ + .message_fifo = &_zbus_observer_fifo_##_name, \ + } + +/** + * @brief Define and initialize an enabled message subscriber. + * + * This macro defines an observer of message subscriber type. It defines a FIFO where the + * subscriber will receive the message asynchronously and initialize the @ref + * zbus_observer defining the subscriber. The message subscribers are defined in the enabled state + * with this macro. + + * + * @param[in] _name The subscriber's name. + */ +#define ZBUS_MSG_SUBSCRIBER_DEFINE(_name) ZBUS_MSG_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, true) /** * * @brief Publish to a channel @@ -741,6 +782,31 @@ static inline const char *zbus_obs_name(const struct zbus_observer *obs) int zbus_sub_wait(const struct zbus_observer *sub, const struct zbus_channel **chan, k_timeout_t timeout); +#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) || defined(__DOXYGEN__) + +/** + * @brief Wait for a channel message. + * + * This routine makes the subscriber wait for the new message in case of channel publication. + * + * @param[in] sub The subscriber's reference. + * @param[out] chan The notification channel's reference. + * @param[out] msg A reference to a copy of the published message. + * @param[in] timeout Waiting period for a notification arrival, + * or one of the special values, K_NO_WAIT and K_FOREVER. + * + * @retval 0 Message received. + * @retval -EINVAL The observer is not a subscriber. + * @retval -ENOMSG Could not retrieve the net_buf from the subscriber FIFO. + * @retval -EILSEQ Received an invalid channel reference. + * @retval -EFAULT A parameter is incorrect, or the function context is invalid (inside an ISR). The + * function only returns this value when the @kconfig{CONFIG_ZBUS_ASSERT_MOCK} is enabled. + */ +int zbus_sub_wait_msg(const struct zbus_observer *sub, const struct zbus_channel **chan, void *msg, + k_timeout_t timeout); + +#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ + /** * * @brief Iterate over channels. diff --git a/subsys/zbus/Kconfig b/subsys/zbus/Kconfig index 622f89641a2..f250865b466 100644 --- a/subsys/zbus/Kconfig +++ b/subsys/zbus/Kconfig @@ -18,6 +18,36 @@ config ZBUS_CHANNEL_NAME config ZBUS_OBSERVER_NAME bool "Observer name field" +config ZBUS_MSG_SUBSCRIBER + select NET_BUF + bool "Message subscribers will receive all messages in sequence." + +if ZBUS_MSG_SUBSCRIBER + +choice + prompt "ZBus msg_subscribers buffer allocation" + +config ZBUS_MSG_SUBSCRIBER_NET_BUF_DYNAMIC + bool "Use heap to allocate msg_subscriber buffers data" + +config ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC + bool "Use fixed data size for msg_subscriber buffers pool" + +endchoice + +config ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_SIZE + default 16 + int "The count of net_buf available to be used simutaneously." + +if ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC + +config ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC_DATA_SIZE + int "The size of the biggest message used with ZBus." + +endif # ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC + +endif # ZBUS_MSG_SUBSCRIBER + config ZBUS_RUNTIME_OBSERVERS bool "Runtime observers support." default n diff --git a/subsys/zbus/zbus.c b/subsys/zbus/zbus.c index abaf92c8641..4ea2d986a3f 100644 --- a/subsys/zbus/zbus.c +++ b/subsys/zbus/zbus.c @@ -8,11 +8,47 @@ #include #include #include +#include #include LOG_MODULE_REGISTER(zbus, CONFIG_ZBUS_LOG_LEVEL); +#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) + +#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_DYNAMIC) + +NET_BUF_POOL_HEAP_DEFINE(_zbus_msg_subscribers_pool, CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_SIZE, + sizeof(struct zbus_channel *), NULL); +BUILD_ASSERT(CONFIG_HEAP_MEM_POOL_SIZE > 0, "MSG_SUBSCRIBER feature requires heap memory pool."); + +static inline struct net_buf *_zbus_create_net_buf(struct net_buf_pool *pool, size_t size, + k_timeout_t timeout) +{ + return net_buf_alloc_len(&_zbus_msg_subscribers_pool, size, timeout); +} + +#else + +NET_BUF_POOL_FIXED_DEFINE(_zbus_msg_subscribers_pool, + (CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC_DATA_SIZE), + (CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_SIZE), + sizeof(struct zbus_channel *), NULL); + +static inline struct net_buf *_zbus_create_net_buf(struct net_buf_pool *pool, size_t size, + k_timeout_t timeout) +{ + __ASSERT(size <= CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC_DATA_SIZE, + "CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC_DATA_SIZE must be greater or equal to " + "%d", + (int)size); + return net_buf_alloc(&_zbus_msg_subscribers_pool, timeout); +} +#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_DYNAMIC */ + +#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ + int _zbus_init(void) { + const struct zbus_channel *curr = NULL; const struct zbus_channel *prev = NULL; @@ -44,32 +80,62 @@ int _zbus_init(void) SYS_INIT(_zbus_init, APPLICATION, CONFIG_ZBUS_CHANNELS_SYS_INIT_PRIORITY); static inline int _zbus_notify_observer(const struct zbus_channel *chan, - const struct zbus_observer *obs, k_timepoint_t end_time) + const struct zbus_observer *obs, k_timepoint_t end_time, + struct net_buf *buf) { - int err = 0; - - if (obs->type == ZBUS_OBSERVER_LISTENER_TYPE) { + switch (obs->type) { + case ZBUS_OBSERVER_LISTENER_TYPE: { obs->callback(chan); + break; + } + case ZBUS_OBSERVER_SUBSCRIBER_TYPE: { + return k_msgq_put(obs->queue, &chan, sys_timepoint_timeout(end_time)); + } +#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) + case ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE: { + struct net_buf *cloned_buf = net_buf_clone(buf, sys_timepoint_timeout(end_time)); - } else if (obs->type == ZBUS_OBSERVER_SUBSCRIBER_TYPE) { - err = k_msgq_put(obs->queue, &chan, sys_timepoint_timeout(end_time)); - } else { - CODE_UNREACHABLE; + if (cloned_buf == NULL) { + return -ENOMEM; + } + memcpy(net_buf_user_data(cloned_buf), &chan, sizeof(struct zbus_channel *)); + + net_buf_put(obs->message_fifo, cloned_buf); + + break; } - return err; +#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ + + default: + _ZBUS_ASSERT(false, "Unreachable"); + } + return 0; } static inline int _zbus_vded_exec(const struct zbus_channel *chan, k_timepoint_t end_time) { int err = 0; int last_error = 0; - - _ZBUS_ASSERT(chan != NULL, "chan is required"); + struct net_buf *buf = NULL; /* Static observer event dispatcher logic */ struct zbus_channel_observation *observation; struct zbus_channel_observation_mask *observation_mask; +#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) + buf = _zbus_create_net_buf(&_zbus_msg_subscribers_pool, zbus_chan_msg_size(chan), + sys_timepoint_timeout(end_time)); + + _ZBUS_ASSERT(buf != NULL, "net_buf zbus_msg_subscribers_pool is " + "unavailable or heap is full"); + + net_buf_add_mem(buf, zbus_chan_msg(chan), zbus_chan_msg_size(chan)); +#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ + + LOG_DBG("Notifing %s's observers. Starting VDED:", _ZBUS_CHAN_NAME(chan)); + + int __maybe_unused index = 0; + for (int16_t i = chan->data->observers_start_idx, limit = chan->data->observers_end_idx; i < limit; ++i) { STRUCT_SECTION_GET(zbus_channel_observation, i, &observation); @@ -83,15 +149,21 @@ static inline int _zbus_vded_exec(const struct zbus_channel *chan, k_timepoint_t continue; } - err = _zbus_notify_observer(chan, obs, end_time); - - _ZBUS_ASSERT(err == 0, - "could not deliver notification to observer %s. Error code %d", - _ZBUS_OBS_NAME(obs), err); + err = _zbus_notify_observer(chan, obs, end_time, buf); if (err) { last_error = err; + LOG_ERR("could not deliver notification to observer %s. Error code %d", + _ZBUS_OBS_NAME(obs), err); + if (err == -ENOMEM) { + if (IS_ENABLED(CONFIG_ZBUS_MSG_SUBSCRIBER)) { + net_buf_unref(buf); + } + return err; + } } + + LOG_DBG(" %d -> %s", index++, _ZBUS_OBS_NAME(obs)); } #if defined(CONFIG_ZBUS_RUNTIME_OBSERVERS) @@ -100,15 +172,13 @@ static inline int _zbus_vded_exec(const struct zbus_channel *chan, k_timepoint_t SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&chan->data->observers, obs_nd, tmp, node) { - _ZBUS_ASSERT(obs_nd != NULL, "observer node is NULL"); - const struct zbus_observer *obs = obs_nd->obs; if (!obs->enabled) { continue; } - err = _zbus_notify_observer(chan, obs, end_time); + err = _zbus_notify_observer(chan, obs, end_time, buf); if (err) { last_error = err; @@ -116,6 +186,8 @@ static inline int _zbus_vded_exec(const struct zbus_channel *chan, k_timepoint_t } #endif /* CONFIG_ZBUS_RUNTIME_OBSERVERS */ + IF_ENABLED(CONFIG_ZBUS_MSG_SUBSCRIBER, (net_buf_unref(buf);)) + return last_error; } @@ -215,15 +287,43 @@ int zbus_sub_wait(const struct zbus_observer *sub, const struct zbus_channel **c { _ZBUS_ASSERT(!k_is_in_isr(), "zbus cannot be used inside ISRs"); _ZBUS_ASSERT(sub != NULL, "sub is required"); + _ZBUS_ASSERT(sub->type == ZBUS_OBSERVER_SUBSCRIBER_TYPE, "sub must be a SUBSCRIBER"); + _ZBUS_ASSERT(sub->queue != NULL, "sub queue is required"); + _ZBUS_ASSERT(chan != NULL, "chan is required"); + + return k_msgq_get(sub->queue, chan, timeout); +} + +#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) + +int zbus_sub_wait_msg(const struct zbus_observer *sub, const struct zbus_channel **chan, void *msg, + k_timeout_t timeout) +{ + _ZBUS_ASSERT(!k_is_in_isr(), "zbus subscribers cannot be used inside ISRs"); + _ZBUS_ASSERT(sub != NULL, "sub is required"); + _ZBUS_ASSERT(sub->type == ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE, + "sub must be a MSG_SUBSCRIBER"); + _ZBUS_ASSERT(sub->message_fifo != NULL, "sub message_fifo is required"); _ZBUS_ASSERT(chan != NULL, "chan is required"); + _ZBUS_ASSERT(msg != NULL, "msg is required"); + + struct net_buf *buf = net_buf_get(sub->message_fifo, timeout); - if (sub->queue == NULL) { - return -EINVAL; + if (buf == NULL) { + return -ENOMSG; } - return k_msgq_get(sub->queue, chan, timeout); + *chan = *((struct zbus_channel **)net_buf_user_data(buf)); + + memcpy(msg, net_buf_remove_mem(buf, zbus_chan_msg_size(*chan)), zbus_chan_msg_size(*chan)); + + net_buf_unref(buf); + + return 0; } +#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ + int zbus_obs_set_chan_notification_mask(const struct zbus_observer *obs, const struct zbus_channel *chan, bool masked) { From b552226dbe60943cd46e6ac598fbb81fda366317 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 11 Oct 2023 15:16:59 +0200 Subject: [PATCH 0359/1623] [nrf fromtree] Bluetooth: BAP: Broadcast Sink should not terminate the PA Sync When calling bt_bap_broadcast_sink_delete, the broadcast sink should not attempt to terminate the PA Sync. The PA sync can live on without the broadcast sink, just as the broadcast sink can live on without the PA sync (which is why the PA sync check was completely removed). Signed-off-by: Emil Gydesen (cherry picked from commit 73398490771970fc099f6f3724ef75fbb1fc8542) Signed-off-by: Alexander Svensen --- subsys/bluetooth/audio/bap_broadcast_sink.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/subsys/bluetooth/audio/bap_broadcast_sink.c b/subsys/bluetooth/audio/bap_broadcast_sink.c index 9866dfd1c57..0d92617f329 100644 --- a/subsys/bluetooth/audio/bap_broadcast_sink.c +++ b/subsys/bluetooth/audio/bap_broadcast_sink.c @@ -1076,8 +1076,6 @@ int bt_bap_broadcast_sink_stop(struct bt_bap_broadcast_sink *sink) int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink) { - int err; - CHECKIF(sink == NULL) { LOG_DBG("sink is NULL"); return -EINVAL; @@ -1099,17 +1097,6 @@ int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink) } } - if (sink->pa_sync == NULL) { - LOG_DBG("Broadcast sink is already deleted"); - return -EALREADY; - } - - err = bt_le_per_adv_sync_delete(sink->pa_sync); - if (err != 0) { - LOG_DBG("Failed to delete periodic advertising sync (err %d)", err); - return err; - } - /* Reset the broadcast sink */ broadcast_sink_cleanup(sink); From 7a9d7daf0af044b352a50feef529a5f45c285b91 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 12 Oct 2023 10:42:57 +0200 Subject: [PATCH 0360/1623] [nrf fromtree] Bluetooth: BAP: Broadcast sink: Clear pa_sync on PA terminated If the PA gets terminated, we clear the pa_sync field of the corresponding broadcast sink object. Signed-off-by: Emil Gydesen (cherry picked from commit c47b7f7936dc39b1d2369122c1ab669acef75bc9) Signed-off-by: Alexander Svensen --- subsys/bluetooth/audio/bap_broadcast_sink.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subsys/bluetooth/audio/bap_broadcast_sink.c b/subsys/bluetooth/audio/bap_broadcast_sink.c index 0d92617f329..4fad67ce539 100644 --- a/subsys/bluetooth/audio/bap_broadcast_sink.c +++ b/subsys/bluetooth/audio/bap_broadcast_sink.c @@ -566,6 +566,16 @@ static void pa_recv(struct bt_le_per_adv_sync *sync, bt_data_parse(buf, pa_decode_base, (void *)sink); } +static void pa_term_cb(struct bt_le_per_adv_sync *sync, + const struct bt_le_per_adv_sync_term_info *info) +{ + struct bt_bap_broadcast_sink *sink = broadcast_sink_get_by_pa(sync); + + if (sink != NULL) { + sink->pa_sync = NULL; + } +} + static void update_recv_state_encryption(const struct bt_bap_broadcast_sink *sink) { struct bt_bap_scan_delegator_mod_src_param mod_src_param = { 0 }; @@ -1108,6 +1118,7 @@ static int broadcast_sink_init(void) static struct bt_le_per_adv_sync_cb cb = { .recv = pa_recv, .biginfo = biginfo_recv, + .term = pa_term_cb, }; bt_le_per_adv_sync_cb_register(&cb); From bbc2731680cc1a7088ea5410d9ff81de4f4fe34a Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 25 Oct 2023 22:12:33 +0530 Subject: [PATCH 0361/1623] [nrf fromtree] net: zperf: Distinguish between IPv4 and IPv6 address set failures Using a generic IP for address set failures is confusing, esp. two same prints (one for v4 and the other for v6), so, use explicit version. Signed-off-by: Chaitanya Tata (cherry picked from commit 6bd47ffb10cef4f5733e9a7849ccb48988e61d4b) --- subsys/net/lib/zperf/zperf_shell.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index 3a8a9c61c4b..c1f0c6a4950 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -191,7 +191,7 @@ static int cmd_setip(const struct shell *sh, size_t argc, char *argv[]) if (zperf_get_ipv6_addr(argv[start + 1], argv[start + 2], &shell_ipv6) < 0) { shell_fprintf(sh, SHELL_WARNING, - "Unable to set IP\n"); + "Unable to set %s address (%s disabled)\n", "IPv6", "IPv4"); return 0; } @@ -208,7 +208,7 @@ static int cmd_setip(const struct shell *sh, size_t argc, char *argv[]) if (zperf_get_ipv4_addr(argv[start + 1], &shell_ipv4) < 0) { shell_fprintf(sh, SHELL_WARNING, - "Unable to set IP\n"); + "Unable to set %s address (%s disabled)\n", "IPv4", "IPv6"); return -ENOEXEC; } @@ -227,7 +227,7 @@ static int cmd_setip(const struct shell *sh, size_t argc, char *argv[]) if (zperf_get_ipv4_addr(argv[start + 1], &shell_ipv4) < 0) { shell_fprintf(sh, SHELL_WARNING, - "Unable to set IP\n"); + "Unable to set %s address\n", "IPv4"); return -ENOEXEC; } @@ -243,7 +243,7 @@ static int cmd_setip(const struct shell *sh, size_t argc, char *argv[]) if (zperf_get_ipv6_addr(argv[start + 1], argv[start + 2], &shell_ipv6) < 0) { shell_fprintf(sh, SHELL_WARNING, - "Unable to set IP\n"); + "Unable to set %s address\n", "IPv6"); return -ENOEXEC; } @@ -1114,7 +1114,7 @@ void zperf_shell_init(void) ret = net_addr_pton(AF_INET6, MY_IP6ADDR, &in6_addr_my.sin6_addr); if (ret < 0) { - NET_WARN("Unable to set IP"); + NET_WARN("Unable to set %s address\n", "IPv6"); } else { NET_INFO("Setting IP address %s", net_sprint_ipv6_addr(&in6_addr_my.sin6_addr)); @@ -1123,9 +1123,10 @@ void zperf_shell_init(void) ret = net_addr_pton(AF_INET6, DST_IP6ADDR, &in6_addr_dst.sin6_addr); if (ret < 0) { - NET_WARN("Unable to set IP %s", + NET_WARN("Unable to set destination %s address %s", + "IPv6", DST_IP6ADDR ? DST_IP6ADDR - : "(Default IPv6 destination address not set)"); + : "(not set)"); } else { NET_INFO("Setting destination IP address %s", net_sprint_ipv6_addr(&in6_addr_dst.sin6_addr)); @@ -1136,7 +1137,7 @@ void zperf_shell_init(void) ret = net_addr_pton(AF_INET, MY_IP4ADDR, &in4_addr_my.sin_addr); if (ret < 0) { - NET_WARN("Unable to set IP"); + NET_WARN("Unable to set %s address\n", "IPv4"); } else { NET_INFO("Setting IP address %s", net_sprint_ipv4_addr(&in4_addr_my.sin_addr)); @@ -1145,9 +1146,10 @@ void zperf_shell_init(void) ret = net_addr_pton(AF_INET, DST_IP4ADDR, &in4_addr_dst.sin_addr); if (ret < 0) { - NET_WARN("Unable to set IP %s", + NET_WARN("Unable to set destination %s address %s", + "IPv4", DST_IP4ADDR ? DST_IP4ADDR - : "(Default IPv4 destination address not set)"); + : "(not set)"); } else { NET_INFO("Setting destination IP address %s", net_sprint_ipv4_addr(&in4_addr_dst.sin_addr)); From b9b5d4751b8e10a932aec3fb8e658c27ac20bda7 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 25 Oct 2023 22:14:26 +0530 Subject: [PATCH 0362/1623] [nrf fromtree] net: zperf: Set default IP addresses only if configured If the user has not configured then we see the error prints for the defaults always. Signed-off-by: Chaitanya Tata (cherry picked from commit dee1f2deaa71ae2595c4121500a95f06f8ce1c48) --- subsys/net/lib/zperf/zperf_shell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index c1f0c6a4950..bcf60dcf037 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -1110,7 +1110,7 @@ void zperf_shell_init(void) { int ret; - if (IS_ENABLED(CONFIG_NET_IPV6) && MY_IP6ADDR) { + if (IS_ENABLED(MY_IP4ADDR_SET) && MY_IP6ADDR) { ret = net_addr_pton(AF_INET6, MY_IP6ADDR, &in6_addr_my.sin6_addr); if (ret < 0) { @@ -1133,7 +1133,7 @@ void zperf_shell_init(void) } } - if (IS_ENABLED(CONFIG_NET_IPV4) && MY_IP4ADDR) { + if (IS_ENABLED(MY_IP4ADDR_SET) && MY_IP4ADDR) { ret = net_addr_pton(AF_INET, MY_IP4ADDR, &in4_addr_my.sin_addr); if (ret < 0) { From 5fac2b050b54701f9d73fefaba6ecd585aacbe43 Mon Sep 17 00:00:00 2001 From: Rahul Singh Date: Mon, 17 Jul 2023 09:45:39 +0100 Subject: [PATCH 0363/1623] [nrf fromtree] net: zperf: Add support for bind to host option for tcp/udp download The current zperf tcp/udp download command doesn't provide the option to bind the server to a specific host address. If there is more than one interface, it will not be possible to test each interface with zperf tcp/udp download command without building the Zpehyr. This patch will add support for zperf tcp/udp download command to bind server to host interface address. Signed-off-by: Rahul Singh (cherry picked from commit 6ef75a26eae2afb75062de1931affd8dce83afa9) --- include/zephyr/net/zperf.h | 1 + subsys/net/lib/zperf/zperf_shell.c | 63 ++++++++++++++++++----- subsys/net/lib/zperf/zperf_tcp_receiver.c | 24 ++++++--- subsys/net/lib/zperf/zperf_udp_receiver.c | 16 +++++- 4 files changed, 84 insertions(+), 20 deletions(-) diff --git a/include/zephyr/net/zperf.h b/include/zephyr/net/zperf.h index cd86541721e..fc809ae9278 100644 --- a/include/zephyr/net/zperf.h +++ b/include/zephyr/net/zperf.h @@ -43,6 +43,7 @@ struct zperf_upload_params { struct zperf_download_params { uint16_t port; + struct sockaddr addr; }; struct zperf_results { diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index bcf60dcf037..b32654f44bc 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -178,6 +178,39 @@ static int parse_ipv4_addr(const struct shell *sh, char *host, char *port, return 0; } +static int zperf_bind_host(const struct shell *sh, + size_t argc, char *argv[], + struct zperf_download_params *param) +{ + int ret; + + /* Parse options */ + if (argc >= 2) { + param->port = strtoul(argv[1], NULL, 10); + } else { + param->port = DEF_PORT; + } + + if (argc >= 3) { + char *addr_str = argv[2]; + struct sockaddr addr; + + memset(&addr, 0, sizeof(addr)); + + ret = net_ipaddr_parse(addr_str, strlen(addr_str), &addr); + if (ret < 0) { + shell_fprintf(sh, SHELL_WARNING, + "Cannot parse address \"%s\"\n", + addr_str); + return ret; + } + + memcpy(¶m->addr, &addr, sizeof(struct sockaddr)); + } + + return 0; +} + static int cmd_setip(const struct shell *sh, size_t argc, char *argv[]) { int start = 0; @@ -333,10 +366,12 @@ static int cmd_udp_download(const struct shell *sh, size_t argc, struct zperf_download_params param = { 0 }; int ret; - if (argc >= 2) { - param.port = strtoul(argv[1], NULL, 10); - } else { - param.port = DEF_PORT; + ret = zperf_bind_host(sh, argc, argv, ¶m); + if (ret < 0) { + shell_fprintf(sh, SHELL_WARNING, + "Unable to bind host.\n"); + shell_help(sh); + return -ENOEXEC; } ret = zperf_udp_download(¶m, udp_session_cb, (void *)sh); @@ -1072,10 +1107,12 @@ static int cmd_tcp_download(const struct shell *sh, size_t argc, struct zperf_download_params param = { 0 }; int ret; - if (argc >= 2) { - param.port = strtoul(argv[1], NULL, 10); - } else { - param.port = DEF_PORT; + ret = zperf_bind_host(sh, argc, argv, ¶m); + if (ret < 0) { + shell_fprintf(sh, SHELL_WARNING, + "Unable to bind host.\n"); + shell_help(sh); + return -ENOEXEC; } ret = zperf_tcp_download(¶m, tcp_session_cb, (void *)sh); @@ -1208,8 +1245,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_tcp, , cmd_tcp_upload2), SHELL_CMD(download, &zperf_cmd_tcp_download, - "[]\n" - "Example: tcp download 5001\n", + "[]: Server port to listen on/connect to\n" + "[]: Bind to , an interface address\n" + "Example: tcp download 5001 192.168.0.1\n", cmd_tcp_download), SHELL_SUBCMD_SET_END ); @@ -1266,8 +1304,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp, , cmd_udp_upload2), SHELL_CMD(download, &zperf_cmd_udp_download, - "[]\n" - "Example: udp download 5001\n", + "[]: Server port to listen on/connect to\n" + "[]: Bind to , an interface address\n" + "Example: udp download 5001 192.168.0.1\n", cmd_udp_download), SHELL_SUBCMD_SET_END ); diff --git a/subsys/net/lib/zperf/zperf_tcp_receiver.c b/subsys/net/lib/zperf/zperf_tcp_receiver.c index 25f9adc3494..614e1af6d03 100644 --- a/subsys/net/lib/zperf/zperf_tcp_receiver.c +++ b/subsys/net/lib/zperf/zperf_tcp_receiver.c @@ -46,6 +46,7 @@ static void *tcp_user_data; static bool tcp_server_running; static bool tcp_server_stop; static uint16_t tcp_server_port; +static struct sockaddr tcp_server_addr; static K_SEM_DEFINE(tcp_server_run, 0, 1); static void tcp_received(const struct sockaddr *addr, size_t datalen) @@ -150,6 +151,7 @@ static void tcp_server_session(void) if (IS_ENABLED(CONFIG_NET_IPV4)) { struct sockaddr_in *in4_addr = zperf_get_sin(); + const struct in_addr *addr = NULL; fds[SOCK_ID_IPV4_LISTEN].fd = zsock_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); @@ -158,7 +160,12 @@ static void tcp_server_session(void) goto error; } - if (MY_IP4ADDR && strlen(MY_IP4ADDR)) { + addr = &net_sin(&tcp_server_addr)->sin_addr; + + if (!net_ipv4_is_addr_unspecified(addr)) { + memcpy(&in4_addr->sin_addr, addr, + sizeof(struct in_addr)); + } else if (MY_IP4ADDR && strlen(MY_IP4ADDR)) { /* Use Setting IP */ ret = zperf_get_ipv4_addr(MY_IP4ADDR, &in4_addr->sin_addr); @@ -167,9 +174,8 @@ static void tcp_server_session(void) goto use_existing_ipv4; } } else { - /* Use existing IP */ - const struct in_addr *addr; use_existing_ipv4: + /* Use existing IP */ addr = zperf_get_default_if_in4_addr(); if (!addr) { NET_ERR("Unable to get IPv4 by default"); @@ -197,6 +203,7 @@ static void tcp_server_session(void) if (IS_ENABLED(CONFIG_NET_IPV6)) { struct sockaddr_in6 *in6_addr = zperf_get_sin6(); + const struct in6_addr *addr = NULL; fds[SOCK_ID_IPV6_LISTEN].fd = zsock_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); @@ -205,7 +212,12 @@ static void tcp_server_session(void) goto error; } - if (MY_IP6ADDR && strlen(MY_IP6ADDR)) { + addr = &net_sin6(&tcp_server_addr)->sin6_addr; + + if (!net_ipv6_is_addr_unspecified(addr)) { + memcpy(&in6_addr->sin6_addr, addr, + sizeof(struct in6_addr)); + } else if (MY_IP6ADDR && strlen(MY_IP6ADDR)) { /* Use Setting IP */ ret = zperf_get_ipv6_addr(MY_IP6ADDR, MY_PREFIX_LEN_STR, @@ -215,9 +227,8 @@ static void tcp_server_session(void) goto use_existing_ipv6; } } else { - /* Use existing IP */ - const struct in6_addr *addr; use_existing_ipv6: + /* Use existing IP */ addr = zperf_get_default_if_in6_addr(); if (!addr) { NET_ERR("Unable to get IPv6 by default"); @@ -387,6 +398,7 @@ int zperf_tcp_download(const struct zperf_download_params *param, tcp_server_port = param->port; tcp_server_running = true; tcp_server_stop = false; + memcpy(&tcp_server_addr, ¶m->addr, sizeof(struct sockaddr)); k_sem_give(&tcp_server_run); diff --git a/subsys/net/lib/zperf/zperf_udp_receiver.c b/subsys/net/lib/zperf/zperf_udp_receiver.c index f96acde6f49..cf29760e1c6 100644 --- a/subsys/net/lib/zperf/zperf_udp_receiver.c +++ b/subsys/net/lib/zperf/zperf_udp_receiver.c @@ -48,6 +48,7 @@ static void *udp_user_data; static bool udp_server_running; static bool udp_server_stop; static uint16_t udp_server_port; +static struct sockaddr udp_server_addr; static K_SEM_DEFINE(udp_server_run, 0, 1); static inline void build_reply(struct zperf_udp_datagram *hdr, @@ -251,7 +252,12 @@ static void udp_server_session(void) goto error; } - if (MY_IP4ADDR && strlen(MY_IP4ADDR)) { + in4_addr = &net_sin(&udp_server_addr)->sin_addr; + + if (!net_ipv4_is_addr_unspecified(in4_addr)) { + memcpy(&in4_addr_my->sin_addr, in4_addr, + sizeof(struct in_addr)); + } else if (MY_IP4ADDR && strlen(MY_IP4ADDR)) { /* Use setting IP */ ret = zperf_get_ipv4_addr(MY_IP4ADDR, &in4_addr_my->sin_addr); @@ -301,7 +307,12 @@ static void udp_server_session(void) goto error; } - if (MY_IP6ADDR && strlen(MY_IP6ADDR)) { + in6_addr = &net_sin6(&udp_server_addr)->sin6_addr; + + if (!net_ipv6_is_addr_unspecified(in6_addr)) { + memcpy(&in6_addr_my->sin6_addr, in6_addr, + sizeof(struct in6_addr)); + } else if (MY_IP6ADDR && strlen(MY_IP6ADDR)) { /* Use setting IP */ ret = zperf_get_ipv6_addr(MY_IP6ADDR, MY_PREFIX_LEN_STR, @@ -441,6 +452,7 @@ int zperf_udp_download(const struct zperf_download_params *param, udp_server_port = param->port; udp_server_running = true; udp_server_stop = false; + memcpy(&udp_server_addr, ¶m->addr, sizeof(struct sockaddr)); k_sem_give(&udp_server_run); From 7ed5a305f4b4e741e855e3dbb89f3af30f2de115 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 25 Oct 2023 23:18:50 +0530 Subject: [PATCH 0364/1623] [nrf fromtree] net: zperf: By default bind to any IP address Default behaviour should only bind to port independent of IP, this allows even multicast/broadcast L4 traffic to be received. User can always specify a specific address to bind using shell or Kconfig or API. Signed-off-by: Chaitanya Tata (cherry picked from commit a1024f6aebd90b1a218bf003c8b97e5e7c9b0472) --- subsys/net/lib/zperf/zperf_common.c | 21 ----------------- subsys/net/lib/zperf/zperf_internal.h | 3 --- subsys/net/lib/zperf/zperf_tcp_receiver.c | 27 ++++++---------------- subsys/net/lib/zperf/zperf_udp_receiver.c | 28 +++++++---------------- 4 files changed, 15 insertions(+), 64 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_common.c b/subsys/net/lib/zperf/zperf_common.c index efe36cf69cd..29568eeef5b 100644 --- a/subsys/net/lib/zperf/zperf_common.c +++ b/subsys/net/lib/zperf/zperf_common.c @@ -109,27 +109,6 @@ int zperf_get_ipv4_addr(char *host, struct in_addr *addr) return 0; } - -const struct in_addr *zperf_get_default_if_in4_addr(void) -{ -#if CONFIG_NET_IPV4 - return net_if_ipv4_select_src_addr(NULL, - net_ipv4_unspecified_address()); -#else - return NULL; -#endif -} - -const struct in6_addr *zperf_get_default_if_in6_addr(void) -{ -#if CONFIG_NET_IPV6 - return net_if_ipv6_select_src_addr(NULL, - net_ipv6_unspecified_address()); -#else - return NULL; -#endif -} - int zperf_prepare_upload_sock(const struct sockaddr *peer_addr, int tos, int priority, int proto) { diff --git a/subsys/net/lib/zperf/zperf_internal.h b/subsys/net/lib/zperf/zperf_internal.h index 96dd9ea9123..592424a9446 100644 --- a/subsys/net/lib/zperf/zperf_internal.h +++ b/subsys/net/lib/zperf/zperf_internal.h @@ -95,9 +95,6 @@ struct sockaddr_in *zperf_get_sin(void); extern void connect_ap(char *ssid); -const struct in_addr *zperf_get_default_if_in4_addr(void); -const struct in6_addr *zperf_get_default_if_in6_addr(void); - int zperf_prepare_upload_sock(const struct sockaddr *peer_addr, int tos, int priority, int proto); diff --git a/subsys/net/lib/zperf/zperf_tcp_receiver.c b/subsys/net/lib/zperf/zperf_tcp_receiver.c index 614e1af6d03..6cc3374d0ae 100644 --- a/subsys/net/lib/zperf/zperf_tcp_receiver.c +++ b/subsys/net/lib/zperf/zperf_tcp_receiver.c @@ -171,18 +171,11 @@ static void tcp_server_session(void) &in4_addr->sin_addr); if (ret < 0) { NET_WARN("Unable to set IPv4"); - goto use_existing_ipv4; + goto use_any_ipv4; } } else { -use_existing_ipv4: - /* Use existing IP */ - addr = zperf_get_default_if_in4_addr(); - if (!addr) { - NET_ERR("Unable to get IPv4 by default"); - goto error; - } - memcpy(&in4_addr->sin_addr, addr, - sizeof(struct in_addr)); +use_any_ipv4: + in4_addr->sin_addr.s_addr = INADDR_ANY; } in4_addr->sin_port = htons(tcp_server_port); @@ -224,18 +217,12 @@ static void tcp_server_session(void) &in6_addr->sin6_addr); if (ret < 0) { NET_WARN("Unable to set IPv6"); - goto use_existing_ipv6; + goto use_any_ipv6; } } else { -use_existing_ipv6: - /* Use existing IP */ - addr = zperf_get_default_if_in6_addr(); - if (!addr) { - NET_ERR("Unable to get IPv6 by default"); - goto error; - } - memcpy(&in6_addr->sin6_addr, addr, - sizeof(struct in6_addr)); +use_any_ipv6: + memcpy(&in6_addr->sin6_addr, net_ipv6_unspecified_address(), + sizeof(struct in6_addr)); } in6_addr->sin6_port = htons(tcp_server_port); diff --git a/subsys/net/lib/zperf/zperf_udp_receiver.c b/subsys/net/lib/zperf/zperf_udp_receiver.c index cf29760e1c6..2724da4b1a9 100644 --- a/subsys/net/lib/zperf/zperf_udp_receiver.c +++ b/subsys/net/lib/zperf/zperf_udp_receiver.c @@ -263,18 +263,11 @@ static void udp_server_session(void) &in4_addr_my->sin_addr); if (ret < 0) { NET_WARN("Unable to set IPv4"); - goto use_existing_ipv4; + goto use_any_ipv4; } } else { - use_existing_ipv4: - /* Use existing IP */ - in4_addr = zperf_get_default_if_in4_addr(); - if (!in4_addr) { - NET_ERR("Unable to get IPv4 by default"); - goto error; - } - memcpy(&in4_addr_my->sin_addr, in4_addr, - sizeof(struct in_addr)); +use_any_ipv4: + in4_addr_my->sin_addr.s_addr = INADDR_ANY; } NET_INFO("Binding to %s", @@ -319,18 +312,13 @@ static void udp_server_session(void) &in6_addr_my->sin6_addr); if (ret < 0) { NET_WARN("Unable to set IPv6"); - goto use_existing_ipv6; + goto use_any_ipv6; } } else { - use_existing_ipv6: - /* Use existing IP */ - in6_addr = zperf_get_default_if_in6_addr(); - if (!in6_addr) { - NET_ERR("Unable to get IPv4 by default"); - goto error; - } - memcpy(&in6_addr_my->sin6_addr, in6_addr, - sizeof(struct in6_addr)); +use_any_ipv6: + memcpy(&in6_addr_my->sin6_addr, + net_ipv6_unspecified_address(), + sizeof(struct in6_addr)); } NET_INFO("Binding to %s", From f0b15a5617adc94c29466827aeac051f5f157e3f Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 2 Nov 2023 17:49:35 +0530 Subject: [PATCH 0365/1623] [nrf fromtree] net: zperf: Fix the check for IPv6 It was typo. Signed-off-by: Chaitanya Tata (cherry picked from commit d4d96b3df2e44b12aa64ee46edcf69339d5f63e2) --- subsys/net/lib/zperf/zperf_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index b32654f44bc..b61501d0e9e 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -1147,7 +1147,7 @@ void zperf_shell_init(void) { int ret; - if (IS_ENABLED(MY_IP4ADDR_SET) && MY_IP6ADDR) { + if (IS_ENABLED(MY_IP6ADDR_SET) && MY_IP6ADDR) { ret = net_addr_pton(AF_INET6, MY_IP6ADDR, &in6_addr_my.sin6_addr); if (ret < 0) { From 2b1d418a6c8b17e028204bbefe4500f0286d46d4 Mon Sep 17 00:00:00 2001 From: Alexander Svensen Date: Mon, 6 Nov 2023 10:39:08 +0100 Subject: [PATCH 0366/1623] [nrf noup] testspec: Add audio - Add filter for audio tests Signed-off-by: Alexander Svensen --- .github/test-spec.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index c01ae703adf..007f4307aa9 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -218,3 +218,25 @@ - "subsys/bluetooth/**/*" - "!subsys/bluetooth/mesh/**/*" - "!subsys/bluetooth/audio/**/*" + +"CI-audio-test": + - "boards/arm/nrf5340_audio_dk_nrf5340/**/*" + - "drivers/flash/**/*" + - "drivers/spi/**/*" + - "drivers/gpio/**/*" + - "drivers/i2c/**/*" + - "drivers/watchdog/**/*" + - "include/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/bluetooth/audio/**/*" + - "subsys/bluetooth/host/**/*" + - "subsys/dfu/**/*" + - "subsys/fs/**/*" + - "subsys/mgmt/mcumgr/**/*" + - "subsys/sd/**/*" + - "subsys/storage/**/*" + - "subsys/task_wdt/**/*" + - "subsys/usb/**/*" + - "subsys/zbus/**/*" From 902f4a417ae968e3fb1ebd97f72b1795c433a497 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 3 Nov 2023 00:38:43 +0530 Subject: [PATCH 0367/1623] [nrf fromtree] wifi: shell: Fix default band value The enum is mainly to print output of band, so, the default value is 0 which means 2.4GHz, which is not correct when using it to configure like in connect. Fix the default value to unknown i.e., no user preference. This way we can use same enum for both set and get. Signed-off-by: Chaitanya Tata (cherry picked from commit 8c179870d426b18d24c8c359c52f8a30dd1bc0e5) --- subsys/net/l2/wifi/wifi_shell.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 592ac50cd8e..7c7bb7b01f6 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -341,6 +341,8 @@ static int __wifi_args_to_params(size_t argc, char *argv[], return -EINVAL; } + params->band = WIFI_FREQ_BAND_UNKNOWN; + /* SSID */ params->ssid = argv[0]; params->ssid_length = strlen(params->ssid); From d36ea76f95b7b50cc31b45f207b2716ea4302cb8 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 3 Nov 2023 00:41:39 +0530 Subject: [PATCH 0368/1623] [nrf fromtree] wifi: shell: Move defaults to beginning This sets defaults first and then overrides if configured, easier to read. Signed-off-by: Chaitanya Tata (cherry picked from commit d12627e70f9f13d7dcdbac46886aede417a71cdd) --- subsys/net/l2/wifi/wifi_shell.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 7c7bb7b01f6..a9837bbaf6b 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -341,7 +341,10 @@ static int __wifi_args_to_params(size_t argc, char *argv[], return -EINVAL; } + /* Defaults */ params->band = WIFI_FREQ_BAND_UNKNOWN; + params->channel = WIFI_CHANNEL_ANY; + params->security = WIFI_SECURITY_TYPE_NONE; /* SSID */ params->ssid = argv[0]; @@ -362,8 +365,6 @@ static int __wifi_args_to_params(size_t argc, char *argv[], } idx++; - } else { - params->channel = WIFI_CHANNEL_ANY; } /* PSK (optional) */ @@ -402,8 +403,6 @@ static int __wifi_args_to_params(size_t argc, char *argv[], params->psk_length > WIFI_SAE_PSWD_MAX_LEN)) { return -EINVAL; } - } else { - params->security = WIFI_SECURITY_TYPE_NONE; } From df801013e317c988eb4a1fad2e8a6e2a438c10d5 Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Wed, 6 Sep 2023 16:52:16 +0200 Subject: [PATCH 0369/1623] [nrf fromtree] twister: Add "path" entry to json test report "Path" is a path (relative to zephyr) to a directory with test suite's definition. Such entry helps to locate a given test. (cherry picked from commit 4e4b743fe12266135b9e808215bb415a059b06d9) Signed-off-by: Maciej Perkowski --- scripts/pylib/twister/twisterlib/reports.py | 1 + scripts/pylib/twister/twisterlib/testsuite.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/scripts/pylib/twister/twisterlib/reports.py b/scripts/pylib/twister/twisterlib/reports.py index bd005d4319a..0b34a5d309b 100644 --- a/scripts/pylib/twister/twisterlib/reports.py +++ b/scripts/pylib/twister/twisterlib/reports.py @@ -258,6 +258,7 @@ def json_report(self, filename, version="NA"): "name": instance.testsuite.name, "arch": instance.platform.arch, "platform": instance.platform.name, + "path": instance.testsuite.source_dir_rel } if instance.run_id: suite['run_id'] = instance.run_id diff --git a/scripts/pylib/twister/twisterlib/testsuite.py b/scripts/pylib/twister/twisterlib/testsuite.py index 3f4a71e4a8c..faacf669c1d 100644 --- a/scripts/pylib/twister/twisterlib/testsuite.py +++ b/scripts/pylib/twister/twisterlib/testsuite.py @@ -373,6 +373,8 @@ def __init__(self, suite_root, suite_path, name, data=None): self.id = name self.source_dir = suite_path + self.source_dir_rel = os.path.relpath(os.path.realpath(suite_path), + start=canonical_zephyr_base) self.yamlfile = suite_path self.testcases = [] From b19ec69bf9ef2c7ac5d7fa37b6f4d934de6e567d Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Fri, 21 Jul 2023 16:09:39 +0200 Subject: [PATCH 0370/1623] [nrf fromtree] twister: Add options deciding if paths be included in tests' names Test suites names are not being handled uniformly for tests not in zephyr tree. Their names depend on -T arg used in twister's CLI. The newly added options allow to select if twister should add paths to suite names. This is needed if test plans are to be used for tests outside of zephyr tree. (cherry picked from commit 066cc2c9d2ee86c35cb10e38bc7ba152c1560602) Signed-off-by: Maciej Perkowski --- .../pylib/twister/twisterlib/environment.py | 15 +++++++ scripts/pylib/twister/twisterlib/reports.py | 10 +++-- .../pylib/twister/twisterlib/testinstance.py | 7 +++- scripts/pylib/twister/twisterlib/testplan.py | 2 +- scripts/pylib/twister/twisterlib/testsuite.py | 16 +++++--- scripts/tests/twister/test_harness.py | 1 + scripts/tests/twister/test_testsuite.py | 40 +++++++++++++++++++ 7 files changed, 81 insertions(+), 10 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index 160233a66fe..b5018bc1f01 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -437,6 +437,21 @@ def add_parse_arguments(parser = None): help="Re-use the outdir before building. Will result in " "faster compilation since builds will be incremental.") + parser.add_argument( + '--detailed-test-id', action='store_true', + help="Include paths to tests' locations in tests' names. Names will follow " + "PATH_TO_TEST/SCENARIO_NAME schema " + "e.g. samples/hello_world/sample.basic.helloworld") + + parser.add_argument( + "--no-detailed-test-id", dest='detailed_test_id', action="store_false", + help="Don't put paths into tests' names. " + "With this arg a test name will be a scenario name " + "e.g. sample.basic.helloworld.") + + # Include paths in names by default. + parser.set_defaults(detailed_test_id=True) + # To be removed in favor of --detailed-skipped-report parser.add_argument( "--no-skipped-report", action="store_true", diff --git a/scripts/pylib/twister/twisterlib/reports.py b/scripts/pylib/twister/twisterlib/reports.py index 0b34a5d309b..c1f160caad9 100644 --- a/scripts/pylib/twister/twisterlib/reports.py +++ b/scripts/pylib/twister/twisterlib/reports.py @@ -420,6 +420,7 @@ def footprint_reports(self, report, show_footprint, all_deltas, def synopsis(self): cnt = 0 example_instance = None + detailed_test_id = self.env.options.detailed_test_id for instance in self.instances.values(): if instance.status not in ["passed", "filtered", "skipped"]: cnt = cnt + 1 @@ -435,11 +436,14 @@ def synopsis(self): if cnt and example_instance: logger.info("") logger.info("To rerun the tests, call twister using the following commandline:") - logger.info("west twister -p -s , for example:") + extra_parameters = '' if detailed_test_id else ' --no-detailed-test-id' + logger.info(f"west twister -p -s {extra_parameters}, for example:") logger.info("") - logger.info(f"west twister -p {example_instance.platform.name} -s {example_instance.testsuite.name}") + logger.info(f"west twister -p {example_instance.platform.name} -s {example_instance.testsuite.name}" + f"{extra_parameters}") logger.info(f"or with west:") - logger.info(f"west build -p -b {example_instance.platform.name} -T {example_instance.testsuite.name}") + logger.info(f"west build -p -b {example_instance.platform.name} " + f"{example_instance.testsuite.source_dir_rel} -T {example_instance.testsuite.id}") logger.info("-+" * 40) def summary(self, results, unrecognized_sections, duration): diff --git a/scripts/pylib/twister/twisterlib/testinstance.py b/scripts/pylib/twister/twisterlib/testinstance.py index ccfc3cd06d4..b9e7d411cb5 100644 --- a/scripts/pylib/twister/twisterlib/testinstance.py +++ b/scripts/pylib/twister/twisterlib/testinstance.py @@ -55,7 +55,12 @@ def __init__(self, testsuite, platform, outdir): self.name = os.path.join(platform.name, testsuite.name) self.run_id = self._get_run_id() self.dut = None - self.build_dir = os.path.join(outdir, platform.name, testsuite.name) + if testsuite.detailed_test_id: + self.build_dir = os.path.join(outdir, platform.name, testsuite.name) + else: + # if suite is not in zephyr, keep only the part after ".." in reconstructed dir structure + source_dir_rel = testsuite.source_dir_rel.rsplit(os.pardir+os.path.sep, 1)[-1] + self.build_dir = os.path.join(outdir, platform.name, source_dir_rel, testsuite.name) self.domains = None diff --git a/scripts/pylib/twister/twisterlib/testplan.py b/scripts/pylib/twister/twisterlib/testplan.py index 1d9c625b28a..209b76c65d2 100755 --- a/scripts/pylib/twister/twisterlib/testplan.py +++ b/scripts/pylib/twister/twisterlib/testplan.py @@ -524,7 +524,7 @@ def add_testsuites(self, testsuite_filter=[]): for name in parsed_data.scenarios.keys(): suite_dict = parsed_data.get_scenario(name) - suite = TestSuite(root, suite_path, name, data=suite_dict) + suite = TestSuite(root, suite_path, name, data=suite_dict, detailed_test_id=self.options.detailed_test_id) suite.add_subcases(suite_dict, subcases, ztest_suite_names) if testsuite_filter: if suite.name and suite.name in testsuite_filter: diff --git a/scripts/pylib/twister/twisterlib/testsuite.py b/scripts/pylib/twister/twisterlib/testsuite.py index faacf669c1d..39c21098718 100644 --- a/scripts/pylib/twister/twisterlib/testsuite.py +++ b/scripts/pylib/twister/twisterlib/testsuite.py @@ -348,7 +348,7 @@ class TestSuite(DisablePyTestCollectionMixin): """Class representing a test application """ - def __init__(self, suite_root, suite_path, name, data=None): + def __init__(self, suite_root, suite_path, name, data=None, detailed_test_id=True): """TestSuite constructor. This gets called by TestPlan as it finds and reads test yaml files. @@ -369,12 +369,14 @@ def __init__(self, suite_root, suite_path, name, data=None): """ workdir = os.path.relpath(suite_path, suite_root) - self.name = self.get_unique(suite_root, workdir, name) + + assert self.check_suite_name(name, suite_root, workdir) + self.detailed_test_id = detailed_test_id + self.name = self.get_unique(suite_root, workdir, name) if self.detailed_test_id else name self.id = name self.source_dir = suite_path - self.source_dir_rel = os.path.relpath(os.path.realpath(suite_path), - start=canonical_zephyr_base) + self.source_dir_rel = os.path.relpath(os.path.realpath(suite_path), start=canonical_zephyr_base) self.yamlfile = suite_path self.testcases = [] @@ -427,10 +429,14 @@ def get_unique(testsuite_root, workdir, name): # workdir can be "." unique = os.path.normpath(os.path.join(relative_ts_root, workdir, name)) + return unique + + @staticmethod + def check_suite_name(name, testsuite_root, workdir): check = name.split(".") if len(check) < 2: raise TwisterException(f"""bad test name '{name}' in {testsuite_root}/{workdir}. \ Tests should reference the category and subsystem with a dot as a separator. """ ) - return unique + return True diff --git a/scripts/tests/twister/test_harness.py b/scripts/tests/twister/test_harness.py index a33d6431ab4..1da2aed3f46 100644 --- a/scripts/tests/twister/test_harness.py +++ b/scripts/tests/twister/test_harness.py @@ -40,6 +40,7 @@ def gtest(): mock_platform.name = "mock_platform" mock_testsuite = mock.Mock() mock_testsuite.name = "mock_testsuite" + mock_testsuite.detailed_test_id = True mock_testsuite.id = "id" mock_testsuite.testcases = [] instance = TestInstance(testsuite=mock_testsuite, platform=mock_platform, outdir="") diff --git a/scripts/tests/twister/test_testsuite.py b/scripts/tests/twister/test_testsuite.py index 49f19d0d0f8..23e4f8ed034 100644 --- a/scripts/tests/twister/test_testsuite.py +++ b/scripts/tests/twister/test_testsuite.py @@ -749,3 +749,43 @@ def test_testcase_dunders(): assert case_lesser < case_greater assert str(case_greater) == 'a greater name' assert repr(case_greater) == '' + + +TESTDATA_11 = [ + ( + ZEPHYR_BASE + '/scripts/tests/twister/test_data/testsuites', + ZEPHYR_BASE + '/scripts/tests/twister/test_data/testsuites/tests/test_a', + 'test_a.check_1', + 'test_a.check_1' + ), + ( + ZEPHYR_BASE, + ZEPHYR_BASE, + 'test_a.check_1', + 'test_a.check_1' + ), + ( + ZEPHYR_BASE, + ZEPHYR_BASE + '/scripts/tests/twister/test_data/testsuites/test_b', + 'test_b.check_1', + 'test_b.check_1' + ), + ( + os.path.join(ZEPHYR_BASE, 'scripts/tests'), + os.path.join(ZEPHYR_BASE, 'scripts/tests'), + 'test_b.check_1', + 'test_b.check_1' + ), + ( + ZEPHYR_BASE, + ZEPHYR_BASE, + 'test_a.check_1.check_2', + 'test_a.check_1.check_2' + ), +] +@pytest.mark.parametrize("testsuite_root, suite_path, name, expected", TESTDATA_11) +def test_get_no_detailed_test_id(testsuite_root, suite_path, name, expected): + '''Test to check if the name without path is given for each testsuite''' + suite = TestSuite(testsuite_root, suite_path, name, detailed_test_id=False) + print(suite.name) + assert suite.name == expected From e4052b3643de84d69f5d6fb5656295298d4aac62 Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Thu, 12 Oct 2023 13:15:00 +0200 Subject: [PATCH 0371/1623] [nrf fromtree] twister: Fix error for --device-testing with not runnable integration An urforseen error was introduce with #62713. When "--device-testing" or "--filter runnable" is used in CLI, twister will skip tests which cannot be executed (not just built) on a given platform. If a given platform is among integration platforms it will cause an error. However, it shouldn't be the case. Such skip is intentional and shouldn't be an error. Fixed by assigning an existing Filter.CMD_LINE, which is exempted from being turned to error. fixes: #63844 (cherry picked from commit 4cd7df2eec31969e84cae74cb49b0bb5710c200d) Signed-off-by: Maciej Perkowski --- scripts/pylib/twister/twisterlib/testplan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pylib/twister/twisterlib/testplan.py b/scripts/pylib/twister/twisterlib/testplan.py index 209b76c65d2..ae122862d1e 100755 --- a/scripts/pylib/twister/twisterlib/testplan.py +++ b/scripts/pylib/twister/twisterlib/testplan.py @@ -740,7 +740,7 @@ def apply_filters(self, **kwargs): instance.add_filter("Not part of requested test plan", Filters.TESTSUITE) if runnable and not instance.run: - instance.add_filter("Not runnable on device", Filters.PLATFORM) + instance.add_filter("Not runnable on device", Filters.CMD_LINE) if self.options.integration and ts.integration_platforms and plat.name not in ts.integration_platforms: instance.add_filter("Not part of integration platforms", Filters.TESTSUITE) From 55257c34d335471c33fc2469f1c562e412efb4ed Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Mon, 24 Jul 2023 13:24:51 +0200 Subject: [PATCH 0372/1623] [nrf fromtree] scripts: Add --no-detailed-test-id arg to test_plan.py script An option --no-detailed-test-id was added to twister to help align names for test outside of zephyr tree. This commit add this arg to test_plan.py script which is then propagated to twister. (cherry picked from commit f9178926a983acd507c183910721138456e3794b) Signed-off-by: Maciej Perkowski --- scripts/ci/test_plan.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 8f2f24b0825..6251104c32e 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -86,7 +86,7 @@ def __repr__(self): return "".format(self.name) class Filters: - def __init__(self, modified_files, pull_request=False, platforms=[]): + def __init__(self, modified_files, pull_request=False, platforms=[], detailed_test_id=True): self.modified_files = modified_files self.twister_options = [] self.full_twister = False @@ -95,6 +95,7 @@ def __init__(self, modified_files, pull_request=False, platforms=[]): self.pull_request = pull_request self.platforms = platforms self.default_run = False + self.detailed_test_id = detailed_test_id def process(self): self.find_modules() @@ -112,6 +113,8 @@ def process(self): def get_plan(self, options, integration=False): fname = "_test_plan_partial.json" cmd = ["scripts/twister", "-c"] + options + ["--save-tests", fname ] + if not self.detailed_test_id: + cmd += ["--no-detailed-test-id"] if integration: cmd.append("--integration") @@ -353,6 +356,13 @@ def parse_args(): help="Number of tests per builder") parser.add_argument('-n', '--default-matrix', default=10, type=int, help="Number of tests per builder") + parser.add_argument('--detailed-test-id', action='store_true', + help="Include paths to tests' locations in tests' names.") + parser.add_argument("--no-detailed-test-id", dest='detailed_test_id', action="store_false", + help="Don't put paths into tests' names.") + + # Include paths in names by default. + parser.set_defaults(detailed_test_id=True) return parser.parse_args() @@ -375,8 +385,7 @@ def parse_args(): print("\n".join(files)) print("=========") - - f = Filters(files, args.pull_request, args.platform) + f = Filters(files, args.pull_request, args.platform, args.detailed_test_id) f.process() # remove dupes and filtered cases From 26dfd71e944b74eb2ec73e41689cd26c128f3566 Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Mon, 31 Jul 2023 13:05:35 +0200 Subject: [PATCH 0373/1623] [nrf fromtree] scripts: Allow test_plan.py to work with other than zephyr repos The test_plan.py script has a path to repository to be scanned for changes hard coded to zephyr. This patch separates zephyr path from such repository's path and adds an arg to pass repo to scan (cherry picked from commit f7c4d5f9d44b7cec85427235cb508a77bdbd898a) Signed-off-by: Maciej Perkowski --- scripts/ci/test_plan.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 6251104c32e..9a6f50f57d0 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -19,10 +19,17 @@ if "ZEPHYR_BASE" not in os.environ: exit("$ZEPHYR_BASE environment variable undefined.") -repository_path = Path(os.environ['ZEPHYR_BASE']) +# These are globaly used variables. They are assigned in __main__ and are visible in further methods +# however, pylint complains that it doesn't recognized them when used (used-before-assignment). +zephyr_base = Path(os.environ['ZEPHYR_BASE']) +repository_path = zephyr_base +repo_to_scan = zephyr_base +args = None + + logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) -sys.path.append(os.path.join(repository_path, 'scripts')) +sys.path.append(os.path.join(zephyr_base, 'scripts')) import list_boards def _get_match_fn(globs, regexes): @@ -112,7 +119,7 @@ def process(self): def get_plan(self, options, integration=False): fname = "_test_plan_partial.json" - cmd = ["scripts/twister", "-c"] + options + ["--save-tests", fname ] + cmd = [f"{zephyr_base}/scripts/twister", "-c"] + options + ["--save-tests", fname ] if not self.detailed_test_id: cmd += ["--no-detailed-test-id"] if integration: @@ -131,7 +138,7 @@ def find_modules(self): if 'west.yml' in self.modified_files: print(f"Manifest file 'west.yml' changed") print("=========") - old_manifest_content = repo.git.show(f"{args.commits[:-2]}:west.yml") + old_manifest_content = repo_to_scan.git.show(f"{args.commits[:-2]}:west.yml") with open("west_old.yml", "w") as manifest: manifest.write(old_manifest_content) old_manifest = Manifest.from_file("west_old.yml") @@ -212,8 +219,12 @@ def find_boards(self): if p and p.groups(): boards.add(p.group(1)) - # Limit search to $ZEPHYR_BASE since this is where the changed files are - lb_args = argparse.Namespace(**{ 'arch_roots': [repository_path], 'board_roots': [repository_path] }) + roots = [zephyr_base] + if repository_path != zephyr_base: + roots.append(repository_path) + + # Look for boards in monitored repositories + lb_args = argparse.Namespace(**{ 'arch_roots': roots, 'board_roots': roots}) known_boards = list_boards.find_boards(lb_args) for b in boards: name_re = re.compile(b) @@ -268,7 +279,7 @@ def find_tests(self): def find_tags(self): - tag_cfg_file = os.path.join(repository_path, 'scripts', 'ci', 'tags.yaml') + tag_cfg_file = os.path.join(zephyr_base, 'scripts', 'ci', 'tags.yaml') with open(tag_cfg_file, 'r') as ymlfile: tags_config = yaml.safe_load(ymlfile) @@ -360,6 +371,8 @@ def parse_args(): help="Include paths to tests' locations in tests' names.") parser.add_argument("--no-detailed-test-id", dest='detailed_test_id', action="store_false", help="Don't put paths into tests' names.") + parser.add_argument('-r', '--repo-to-scan', default=None, + help="Repo to scan") # Include paths in names by default. parser.set_defaults(detailed_test_id=True) @@ -372,9 +385,11 @@ def parse_args(): args = parse_args() files = [] errors = 0 + if args.repo_to_scan: + repository_path = Path(args.repo_to_scan) if args.commits: - repo = Repo(repository_path) - commit = repo.git.diff("--name-only", args.commits) + repo_to_scan = Repo(repository_path) + commit = repo_to_scan.git.diff("--name-only", args.commits) files = commit.split("\n") elif args.modified_files: with open(args.modified_files, "r") as fp: From bd2c89e4a589eb0ad43c9a617d3308417b4ddda6 Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Tue, 25 Jul 2023 16:45:55 +0200 Subject: [PATCH 0374/1623] [nrf fromtree] scripts: Allow using alternative ignore-patters in test_plan.py Expand test_plan.py args with --ignore-path. This allows to provide an alternative lists of patterns for the script. Signed-off-by: Maciej Perkowski (cherry picked from commit 47405a114ad676abde2ac2e0d987aba916686576) Signed-off-by: Maciej Perkowski --- scripts/ci/test_plan.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 9a6f50f57d0..6ebcfc744bc 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -93,7 +93,7 @@ def __repr__(self): return "".format(self.name) class Filters: - def __init__(self, modified_files, pull_request=False, platforms=[], detailed_test_id=True): + def __init__(self, modified_files, ignore_path, pull_request=False, platforms=[], detailed_test_id=True): self.modified_files = modified_files self.twister_options = [] self.full_twister = False @@ -103,6 +103,7 @@ def __init__(self, modified_files, pull_request=False, platforms=[], detailed_te self.platforms = platforms self.default_run = False self.detailed_test_id = detailed_test_id + self.ignore_path = ignore_path def process(self): self.find_modules() @@ -317,7 +318,7 @@ def find_tags(self): logging.info(f'Potential tag based filters: {exclude_tags}') def find_excludes(self, skip=[]): - with open("scripts/ci/twister_ignore.txt", "r") as twister_ignore: + with open(self.ignore_path, "r") as twister_ignore: ignores = twister_ignore.read().splitlines() ignores = filter(lambda x: not x.startswith("#"), ignores) @@ -373,6 +374,9 @@ def parse_args(): help="Don't put paths into tests' names.") parser.add_argument('-r', '--repo-to-scan', default=None, help="Repo to scan") + parser.add_argument('--ignore-path', + default=os.path.join(zephyr_base, 'scripts', 'ci', 'twister_ignore.txt'), + help="Path to a text file with patterns of files to be matched against changed files") # Include paths in names by default. parser.set_defaults(detailed_test_id=True) @@ -400,7 +404,7 @@ def parse_args(): print("\n".join(files)) print("=========") - f = Filters(files, args.pull_request, args.platform, args.detailed_test_id) + f = Filters(files, args.ignore_path, args.pull_request, args.platform, args.detailed_test_id) f.process() # remove dupes and filtered cases From bff52954a69905e162abbbb49045b81cf8e7bee1 Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Wed, 2 Aug 2023 14:36:03 +0200 Subject: [PATCH 0375/1623] [nrf fromtree] scripts: Add arg to set_plan.py for alternative tag relation list Add --alt-tag arg for test_plan.py script. User can use it and point to an alternative file with tag-directories relations. If so, such file will be used instead of the default one. (cherry picked from commit 76926100048082cc559c85114f89dde2faa3ec3e) Signed-off-by: Maciej Perkowski --- scripts/ci/test_plan.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 6ebcfc744bc..6ee76b74aae 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -93,7 +93,7 @@ def __repr__(self): return "".format(self.name) class Filters: - def __init__(self, modified_files, ignore_path, pull_request=False, platforms=[], detailed_test_id=True): + def __init__(self, modified_files, ignore_path, alt_tags, pull_request=False, platforms=[], detailed_test_id=True): self.modified_files = modified_files self.twister_options = [] self.full_twister = False @@ -104,6 +104,7 @@ def __init__(self, modified_files, ignore_path, pull_request=False, platforms=[] self.default_run = False self.detailed_test_id = detailed_test_id self.ignore_path = ignore_path + self.tag_cfg_file = alt_tags def process(self): self.find_modules() @@ -280,8 +281,7 @@ def find_tests(self): def find_tags(self): - tag_cfg_file = os.path.join(zephyr_base, 'scripts', 'ci', 'tags.yaml') - with open(tag_cfg_file, 'r') as ymlfile: + with open(self.tag_cfg_file, 'r') as ymlfile: tags_config = yaml.safe_load(ymlfile) tags = {} @@ -377,6 +377,9 @@ def parse_args(): parser.add_argument('--ignore-path', default=os.path.join(zephyr_base, 'scripts', 'ci', 'twister_ignore.txt'), help="Path to a text file with patterns of files to be matched against changed files") + parser.add_argument('--alt-tags', + default=os.path.join(zephyr_base, 'scripts', 'ci', 'tags.yaml'), + help="Path to a file describing relations between directories and tags") # Include paths in names by default. parser.set_defaults(detailed_test_id=True) @@ -404,7 +407,7 @@ def parse_args(): print("\n".join(files)) print("=========") - f = Filters(files, args.ignore_path, args.pull_request, args.platform, args.detailed_test_id) + f = Filters(files, args.ignore_path, args.alt_tags, args.pull_request, args.platform, args.detailed_test_id) f.process() # remove dupes and filtered cases From dfbb9972f240c1e55d4e84dcdb941f91af552ea0 Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Wed, 2 Aug 2023 16:43:54 +0200 Subject: [PATCH 0376/1623] [nrf fromtree] scripts: Add arg to test_plan.py for alternative test locations The arg --testsuite-root was copied from twister. When it is used for test_plan.py it will be propagated to twister calls. This allows to make alternative test locations (e.g. from another repo) to work with test_plan.py (cherry picked from commit 0752d604430b2c77b535a51ad30735fb9f61ccbc) Signed-off-by: Maciej Perkowski --- scripts/ci/test_plan.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 6ee76b74aae..1388250716f 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -93,8 +93,10 @@ def __repr__(self): return "".format(self.name) class Filters: - def __init__(self, modified_files, ignore_path, alt_tags, pull_request=False, platforms=[], detailed_test_id=True): + def __init__(self, modified_files, ignore_path, alt_tags, testsuite_root, + pull_request=False, platforms=[], detailed_test_id=True): self.modified_files = modified_files + self.testsuite_root = testsuite_root self.twister_options = [] self.full_twister = False self.all_tests = [] @@ -119,11 +121,14 @@ def process(self): else: self.find_excludes() - def get_plan(self, options, integration=False): + def get_plan(self, options, integration=False, use_testsuite_root=True): fname = "_test_plan_partial.json" cmd = [f"{zephyr_base}/scripts/twister", "-c"] + options + ["--save-tests", fname ] if not self.detailed_test_id: cmd += ["--no-detailed-test-id"] + if self.testsuite_root and use_testsuite_root: + for root in self.testsuite_root: + cmd+=["-T", root] if integration: cmd.append("--integration") @@ -277,7 +282,7 @@ def find_tests(self): _options.extend(["-p", platform]) else: _options.append("--all") - self.get_plan(_options) + self.get_plan(_options, use_testsuite_root=False) def find_tags(self): @@ -380,6 +385,12 @@ def parse_args(): parser.add_argument('--alt-tags', default=os.path.join(zephyr_base, 'scripts', 'ci', 'tags.yaml'), help="Path to a file describing relations between directories and tags") + parser.add_argument( + "-T", "--testsuite-root", action="append", default=[], + help="Base directory to recursively search for test cases. All " + "testcase.yaml files under here will be processed. May be " + "called multiple times. Defaults to the 'samples/' and " + "'tests/' directories at the base of the Zephyr tree.") # Include paths in names by default. parser.set_defaults(detailed_test_id=True) @@ -407,7 +418,8 @@ def parse_args(): print("\n".join(files)) print("=========") - f = Filters(files, args.ignore_path, args.alt_tags, args.pull_request, args.platform, args.detailed_test_id) + f = Filters(files, args.ignore_path, args.alt_tags, args.testsuite_root, + args.pull_request, args.platform, args.detailed_test_id) f.process() # remove dupes and filtered cases From 158f0db91c3ab5455fb79e8fa3f07cb482c43b56 Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Thu, 17 Aug 2023 14:34:31 +0200 Subject: [PATCH 0377/1623] [nrf fromtree] scripts: Make workflow of test_plan.py script more robust The script was not resolving all detected changes uniformly: find_excludes() could skip or not certain patterns based on required testing scope. The idea was to not include files that were already handled by find_test() and find_boards() workflows. However, only boards and tests folders could be removed but not samples. This also led to blind spots: changes in some files were not triggering any tests. E.g. change in a test/common, where no corresponding yaml can be found by find_tests() which is also ignored by find_excludes(). In the new workflow a list of resolved files (for which find_arch(), find_tests() or find_boards() found scope) is created. Instead of using skip in find_excludes, files are excluded only if they were resolved. (cherry picked from commit 9f850010612f18925ea09fad3d99cadbd7c4b33f) Signed-off-by: Maciej Perkowski --- scripts/ci/test_plan.py | 39 +++++++++++++++++++++-------------- scripts/ci/twister_ignore.txt | 19 ----------------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 1388250716f..234d1302731 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -97,13 +97,13 @@ def __init__(self, modified_files, ignore_path, alt_tags, testsuite_root, pull_request=False, platforms=[], detailed_test_id=True): self.modified_files = modified_files self.testsuite_root = testsuite_root + self.resolved_files = [] self.twister_options = [] self.full_twister = False self.all_tests = [] self.tag_options = [] self.pull_request = pull_request self.platforms = platforms - self.default_run = False self.detailed_test_id = detailed_test_id self.ignore_path = ignore_path self.tag_cfg_file = alt_tags @@ -115,11 +115,7 @@ def process(self): if not self.platforms: self.find_archs() self.find_boards() - - if self.default_run: - self.find_excludes(skip=["tests/*", "boards/*/*/*"]) - else: - self.find_excludes() + self.find_excludes() def get_plan(self, options, integration=False, use_testsuite_root=True): fname = "_test_plan_partial.json" @@ -200,6 +196,8 @@ def find_archs(self): archs.add('riscv64') else: archs.add(p.group(1)) + # Modified file is treated as resolved, since a matching scope was found + self.resolved_files.append(f) _options = [] for arch in archs: @@ -218,6 +216,7 @@ def find_archs(self): def find_boards(self): boards = set() all_boards = set() + resolved = [] for f in self.modified_files: if f.endswith(".rst") or f.endswith(".png") or f.endswith(".jpg"): @@ -225,6 +224,7 @@ def find_boards(self): p = re.match(r"^boards\/[^/]+\/([^/]+)\/", f) if p and p.groups(): boards.add(p.group(1)) + resolved.append(f) roots = [zephyr_base] if repository_path != zephyr_base: @@ -239,10 +239,16 @@ def find_boards(self): if name_re.search(kb.name): all_boards.add(kb.name) + # If modified file is catched by "find_boards" workflow (change in "boards" dir AND board recognized) + # it means a proper testing scope for this file was found and this file can be removed + # from further consideration + for board in all_boards: + self.resolved_files.extend(list(filter(lambda f: board in f, resolved))) + _options = [] if len(all_boards) > 20: logging.warning(f"{len(boards)} boards changed, this looks like a global change, skipping test handling, revert to default.") - self.default_run = True + self.full_twister = True return for board in all_boards: @@ -262,6 +268,8 @@ def find_tests(self): if os.path.exists(os.path.join(d, "testcase.yaml")) or \ os.path.exists(os.path.join(d, "sample.yaml")): tests.add(d) + # Modified file is treated as resolved, since a matching scope was found + self.resolved_files.append(f) break else: d = os.path.dirname(d) @@ -272,7 +280,7 @@ def find_tests(self): if len(tests) > 20: logging.warning(f"{len(tests)} tests changed, this looks like a global change, skipping test handling, revert to default") - self.default_run = True + self.full_twister = True return if _options: @@ -328,21 +336,22 @@ def find_excludes(self, skip=[]): ignores = filter(lambda x: not x.startswith("#"), ignores) found = set() - files = list(filter(lambda x: x, self.modified_files)) + files_not_resolved = list(filter(lambda x: x not in self.resolved_files, self.modified_files)) for pattern in ignores: - if pattern in skip: - continue if pattern: - found.update(fnmatch.filter(files, pattern)) + found.update(fnmatch.filter(files_not_resolved, pattern)) logging.debug(found) - logging.debug(files) + logging.debug(files_not_resolved) - if sorted(files) != sorted(found): + # Full twister run can be ordered by detecting great number of tests/boards changed + # or if not all modified files were resolved (corresponding scope found) + self.full_twister = self.full_twister or sorted(files_not_resolved) != sorted(found) + + if self.full_twister: _options = [] logging.info(f'Need to run full or partial twister...') - self.full_twister = True if self.platforms: for platform in self.platforms: _options.extend(["-p", platform]) diff --git a/scripts/ci/twister_ignore.txt b/scripts/ci/twister_ignore.txt index 59f735495ca..4a0589f291c 100644 --- a/scripts/ci/twister_ignore.txt +++ b/scripts/ci/twister_ignore.txt @@ -17,25 +17,6 @@ CODEOWNERS MAINTAINERS.yml LICENSE Makefile -tests/* -samples/* -boards/*/*/* -arch/xtensa/* -arch/x86/* -arch/posix/* -arch/arc/* -arch/sparc/* -arch/arm/* -arch/nios2/* -arch/riscv/* -include/arch/xtensa/* -include/arch/x86/* -include/arch/posix/* -include/arch/arc/* -include/arch/sparc/* -include/arch/arm/* -include/arch/nios2/* -include/arch/riscv/* doc/* # GH action have no impact on code .github/* From 10ef01ba7924b88c6f3dc9d75409f679486eb4ba Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Fri, 18 Aug 2023 16:02:12 +0200 Subject: [PATCH 0378/1623] [nrf fromtree] scripts: Add workflow for "common" directories in find_tests() Some tests use a "common" directory to store pieces of code which are reused by different scenarios. In those cases, no test yaml is found within such director nor within its parents. If no test yaml is found in a directory, and the directory is called common, also look in collocated directories if they have test yamls. If so, add all those locations to the scope. E.g. tests/bluetooth/controller/common (cherry picked from commit 72f416f382f061199900096f50315608b75aae8b) Signed-off-by: Maciej Perkowski --- scripts/ci/test_plan.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 234d1302731..a308abe63ab 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -12,6 +12,7 @@ import json import logging import sys +import glob from pathlib import Path from git import Repo from west.manifest import Manifest @@ -264,13 +265,25 @@ def find_tests(self): if f.endswith(".rst"): continue d = os.path.dirname(f) - while d: + scope_found = False + while not scope_found and d: + head, tail = os.path.split(d) if os.path.exists(os.path.join(d, "testcase.yaml")) or \ os.path.exists(os.path.join(d, "sample.yaml")): tests.add(d) # Modified file is treated as resolved, since a matching scope was found self.resolved_files.append(f) - break + scope_found = True + elif tail == "common": + # Look for yamls in directories collocated with common + + yamls_found = [yaml for yaml in glob.iglob(head + '/**/testcase.yaml', recursive=True)] + yamls_found.extend([yaml for yaml in glob.iglob(head + '/**/sample.yaml', recursive=True)]) + if yamls_found: + for yaml in yamls_found: + tests.add(os.path.dirname(yaml)) + self.resolved_files.append(f) + scope_found = True else: d = os.path.dirname(d) From d8af055fc8c45815beaae06947d1625011451c88 Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Mon, 30 Oct 2023 15:24:09 +0100 Subject: [PATCH 0379/1623] [nrf fromtree] twister: bugfix: Fix infinite loop in test_plan.py script Commit 72f416f382f061199900096f50315608b75aae8b added a horizontal scan for .yaml files when a modification was made in "common" folder. If yamls were found in such way, the loop ended. However, the implementation didn't address what happens if such yamls are not found. This made the script going into an infinite loop. If yamls are not found next to "common", the script should proceed as before, i.e. go to the directory above an start looking there. (cherry picked from commit 3314b8e0c3fd8c8d717b5b718fb86acc7d1c9022) Signed-off-by: Maciej Perkowski --- scripts/ci/test_plan.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index a308abe63ab..21cac8e4914 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -284,6 +284,8 @@ def find_tests(self): tests.add(os.path.dirname(yaml)) self.resolved_files.append(f) scope_found = True + else: + d = os.path.dirname(d) else: d = os.path.dirname(d) From ac573c04413a1f16faf2a3b63936b0e91720820a Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Mon, 30 Oct 2023 16:03:52 +0100 Subject: [PATCH 0380/1623] [nrf fromtree] scripts: Add test_plan.py to twister_ignore.txt There is no point in running full twister scope when test_plan.py script is modified. (cherry picked from commit aa3e79a88ac635492c2baccf0f74dc26597dadf8) Signed-off-by: Maciej Perkowski --- scripts/ci/twister_ignore.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/ci/twister_ignore.txt b/scripts/ci/twister_ignore.txt index 4a0589f291c..fb267ed81f7 100644 --- a/scripts/ci/twister_ignore.txt +++ b/scripts/ci/twister_ignore.txt @@ -24,6 +24,7 @@ doc/* *.md # if we change this file or associated script, it should not trigger a full # twister. +scripts/ci/test_plan.py scripts/ci/twister_ignore.txt scripts/ci/what_changed.py scripts/ci/version_mgr.py From 2b912a70f905022a1ef891161b5f6c977980c87a Mon Sep 17 00:00:00 2001 From: Rubin Gerritsen Date: Mon, 6 Nov 2023 14:49:08 +0100 Subject: [PATCH 0381/1623] [nrf fromtree] Bluetooth: HCI: Add bt_hci_get_ver_str() This new API returns the version string corresponding to a given HCI version. The API can be used by applications to print out human-readable information about the controller being used. Adding this API removes possible code duplication. Signed-off-by: Rubin Gerritsen (cherry picked from commit 8b2dd61ebab8af6a1c17abee4b565f1d1c8222b6) --- include/zephyr/bluetooth/hci.h | 13 +++++++++++++ subsys/bluetooth/host/hci_core.c | 10 +++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/zephyr/bluetooth/hci.h b/include/zephyr/bluetooth/hci.h index 8dd7434e445..258f86519b6 100644 --- a/include/zephyr/bluetooth/hci.h +++ b/include/zephyr/bluetooth/hci.h @@ -97,6 +97,19 @@ int bt_hci_get_conn_handle(const struct bt_conn *conn, uint16_t *conn_handle); */ int bt_hci_get_adv_handle(const struct bt_le_ext_adv *adv, uint8_t *adv_handle); +/** @brief Obtain the version string given a core version number. + * + * The core version of a controller can be obtained by issuing + * the HCI Read Local Version Information command. + * + * See also the defines prefixed with BT_HCI_VERSION_. + * + * @param core_version The core version. + * + * @return Version string corresponding to the core version number. + */ +const char *bt_hci_get_ver_str(uint8_t core_version); + /** @typedef bt_hci_vnd_evt_cb_t * @brief Callback type for vendor handling of HCI Vendor-Specific Events. * diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 8e1227c0bf5..eb1d7195d5c 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -3425,15 +3425,15 @@ static int set_event_mask(void) return bt_hci_cmd_send_sync(BT_HCI_OP_SET_EVENT_MASK, buf, NULL); } -static const char *ver_str(uint8_t ver) +const char *bt_hci_get_ver_str(uint8_t core_version) { const char * const str[] = { "1.0b", "1.1", "1.2", "2.0", "2.1", "3.0", "4.0", "4.1", "4.2", "5.0", "5.1", "5.2", "5.3", "5.4" }; - if (ver < ARRAY_SIZE(str)) { - return str[ver]; + if (core_version < ARRAY_SIZE(str)) { + return str[core_version]; } return "unknown"; @@ -3474,9 +3474,9 @@ static void bt_dev_show_info(void) } LOG_INF("HCI: version %s (0x%02x) revision 0x%04x, manufacturer 0x%04x", - ver_str(bt_dev.hci_version), bt_dev.hci_version, bt_dev.hci_revision, + bt_hci_get_ver_str(bt_dev.hci_version), bt_dev.hci_version, bt_dev.hci_revision, bt_dev.manufacturer); - LOG_INF("LMP: version %s (0x%02x) subver 0x%04x", ver_str(bt_dev.lmp_version), + LOG_INF("LMP: version %s (0x%02x) subver 0x%04x", bt_hci_get_ver_str(bt_dev.lmp_version), bt_dev.lmp_version, bt_dev.lmp_subversion); } From ede86123951b7f824f91f6ebd1ea15f307f9a208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ga=C5=82da?= Date: Mon, 6 Nov 2023 18:44:48 +0100 Subject: [PATCH 0382/1623] [nrf noup] ci: Add CI-run-zephyr-twister test spec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI-run-zephyr-twister is used to determine if twister tests from sdk-zephyr should be run on PR to sdk-nrf repository. Signed-off-by: Jan Gałda --- .github/test-spec.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 007f4307aa9..789f1a4e235 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -1,4 +1,19 @@ # This is the Jenkins ci variant of the .github/labler.yaml + +"CI-run-zephyr-twister": + - any: + - "!.github/**/*" + - "!doc/**/*" + - "!CODEOWNERS" + - "!LICENSE" + - "!**/*.rst" + - "!VERSION" + - "!submanifests/**/*" + - "!MAINTAINERS.yml" + - "!version.h.in" + - "!Jenkinsfile" + - "!**/*.md" + "CI-iot-zephyr-lwm2m-test": - "drivers/console/**/*" - "drivers/flash/**/*" From 4a05f790ba8345cc348c2ca2f7fcf84dfa983e8d Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Fri, 8 Sep 2023 17:50:24 +0200 Subject: [PATCH 0383/1623] [nrf fromtree] twister: pytest: Move fixtures to one file Fixtures in pytest-twister-harness plugin are moved to one file to simplify adding new fixtures in the future - no need to add pytest_plugins entry and register asserts. Moved also shell fixture from sample dir, because that fixture can be reused in new tests. Signed-off-by: Grzegorz Chwierut (cherry picked from commit f6185221440b7fe9f0c1b17702c8231105edc06b) --- .../pytest/shell/pytest/test_shell.py | 12 +--------- .../src/twister_harness/__init__.py | 2 +- .../{fixtures/dut.py => fixtures.py} | 22 +++++++++++++++++++ .../src/twister_harness/fixtures/__init__.py | 8 ------- .../{fixtures => helpers}/mcumgr.py | 16 -------------- .../src/twister_harness/plugin.py | 3 +-- .../tests/fixtures/mcumgr_fixture_test.py | 4 ++-- 7 files changed, 27 insertions(+), 40 deletions(-) rename scripts/pylib/pytest-twister-harness/src/twister_harness/{fixtures/dut.py => fixtures.py} (72%) delete mode 100644 scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/__init__.py rename scripts/pylib/pytest-twister-harness/src/twister_harness/{fixtures => helpers}/mcumgr.py (88%) diff --git a/samples/subsys/testsuite/pytest/shell/pytest/test_shell.py b/samples/subsys/testsuite/pytest/shell/pytest/test_shell.py index 37efa74795b..84d16ec1e5a 100755 --- a/samples/subsys/testsuite/pytest/shell/pytest/test_shell.py +++ b/samples/subsys/testsuite/pytest/shell/pytest/test_shell.py @@ -4,21 +4,11 @@ import logging -import pytest -from twister_harness import DeviceAdapter, Shell +from twister_harness import Shell logger = logging.getLogger(__name__) -@pytest.fixture(scope='function') -def shell(dut: DeviceAdapter) -> Shell: - """Return ready to use shell interface""" - shell = Shell(dut, timeout=20.0) - logger.info('wait for prompt') - assert shell.wait_for_prompt() - return shell - - def test_shell_print_help(shell: Shell): logger.info('send "help" command') lines = shell.exec_command('help') diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/__init__.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/__init__.py index 251c5deb672..4897e2cf391 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/__init__.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/__init__.py @@ -5,7 +5,7 @@ # flake8: noqa from twister_harness.device.device_adapter import DeviceAdapter -from twister_harness.fixtures.mcumgr import MCUmgr +from twister_harness.helpers.mcumgr import MCUmgr from twister_harness.helpers.shell import Shell __all__ = ['DeviceAdapter', 'MCUmgr', 'Shell'] diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/dut.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py similarity index 72% rename from scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/dut.py rename to scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py index 0f34c05b252..e2e82674ada 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/dut.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py @@ -10,6 +10,8 @@ from twister_harness.device.device_adapter import DeviceAdapter from twister_harness.device.factory import DeviceFactory from twister_harness.twister_harness_config import DeviceConfig, TwisterHarnessConfig +from twister_harness.helpers.shell import Shell +from twister_harness.helpers.mcumgr import MCUmgr logger = logging.getLogger(__name__) @@ -44,3 +46,23 @@ def dut(request: pytest.FixtureRequest, device_object: DeviceAdapter) -> Generat yield device_object finally: # to make sure we close all running processes execution device_object.close() + + +@pytest.fixture(scope='function') +def shell(dut: DeviceAdapter) -> Shell: + """Return ready to use shell interface""" + shell = Shell(dut, timeout=20.0) + logger.info('Wait for prompt') + assert shell.wait_for_prompt() + return shell + + +@pytest.fixture(scope='session') +def is_mcumgr_available() -> None: + if not MCUmgr.is_available(): + pytest.skip('mcumgr not available') + + +@pytest.fixture() +def mcumgr(is_mcumgr_available: None, dut: DeviceAdapter) -> Generator[MCUmgr, None, None]: + yield MCUmgr.create_for_serial(dut.device_config.serial) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/__init__.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/__init__.py deleted file mode 100644 index ed61bf17b1c..00000000000 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2023 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -import pytest - -pytest.register_assert_rewrite('twister_harness.fixtures.dut') -pytest.register_assert_rewrite('twister_harness.fixtures.mcumgr') diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/mcumgr.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/mcumgr.py similarity index 88% rename from scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/mcumgr.py rename to scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/mcumgr.py index e0d85893792..b6cab6475c1 100755 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/mcumgr.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/mcumgr.py @@ -3,19 +3,14 @@ # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations -import pytest import logging import re import shlex -from typing import Generator from subprocess import check_output, getstatusoutput from pathlib import Path from dataclasses import dataclass -from twister_harness.device.device_adapter import DeviceAdapter - - logger = logging.getLogger(__name__) @@ -108,14 +103,3 @@ def image_confirm(self, hash: str | None = None): image_list = self.get_image_list() hash = image_list[0].hash self.run_command(f'image confirm {hash}') - - -@pytest.fixture(scope='session') -def is_mcumgr_available() -> None: - if not MCUmgr.is_available(): - pytest.skip('mcumgr not available') - - -@pytest.fixture() -def mcumgr(is_mcumgr_available: None, dut: DeviceAdapter) -> Generator[MCUmgr, None, None]: - yield MCUmgr.create_for_serial(dut.device_config.serial) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py index 59bec12955d..076d36d4cc9 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py @@ -14,8 +14,7 @@ logger = logging.getLogger(__name__) pytest_plugins = ( - 'twister_harness.fixtures.dut', - 'twister_harness.fixtures.mcumgr' + 'twister_harness.fixtures' ) diff --git a/scripts/pylib/pytest-twister-harness/tests/fixtures/mcumgr_fixture_test.py b/scripts/pylib/pytest-twister-harness/tests/fixtures/mcumgr_fixture_test.py index f294adba30a..f336311143a 100644 --- a/scripts/pylib/pytest-twister-harness/tests/fixtures/mcumgr_fixture_test.py +++ b/scripts/pylib/pytest-twister-harness/tests/fixtures/mcumgr_fixture_test.py @@ -6,7 +6,7 @@ import textwrap from unittest import mock -from twister_harness.fixtures.mcumgr import MCUmgr, MCUmgrException +from twister_harness.helpers.mcumgr import MCUmgr, MCUmgrException @pytest.fixture(name='mcumgr') @@ -14,7 +14,7 @@ def fixture_mcumgr() -> MCUmgr: return MCUmgr.create_for_serial('SERIAL_PORT') -@mock.patch('twister_harness.fixtures.mcumgr.MCUmgr.run_command', return_value='') +@mock.patch('twister_harness.helpers.mcumgr.MCUmgr.run_command', return_value='') def test_if_mcumgr_fixture_generate_proper_command( patched_run_command: mock.Mock, mcumgr: MCUmgr ) -> None: From 8186e5cf7cf25d3586896060730eddd6145589c5 Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Wed, 25 Oct 2023 12:33:23 +0200 Subject: [PATCH 0384/1623] [nrf fromtree] twister: pytest: Parametrize scope of the dut fixture Added pytest_dut_scope keyword under harness_config section. New keyword is used to determine the scope of dut and shell fixtures in pytest-twister-harness plugin. Signed-off-by: Grzegorz Chwierut (cherry picked from commit fffe0b9fadd6271b932fd8e382eff7be3c9b3c13) --- doc/develop/test/pytest.rst | 9 +++++++-- doc/develop/test/twister.rst | 5 +++++ .../src/twister_harness/fixtures.py | 13 +++++++++---- .../src/twister_harness/plugin.py | 5 +++++ scripts/pylib/twister/twisterlib/harness.py | 5 ++++- scripts/schemas/twister/testsuite-schema.yaml | 8 ++++++++ .../pytest_integration/test_harness_pytest.py | 19 +++++++++++++++++++ 7 files changed, 57 insertions(+), 7 deletions(-) diff --git a/doc/develop/test/pytest.rst b/doc/develop/test/pytest.rst index d0fad4d6be6..087c45bcce8 100644 --- a/doc/develop/test/pytest.rst +++ b/doc/develop/test/pytest.rst @@ -69,6 +69,9 @@ DUT (initialize logging, flash device, connect serial etc). This fixture yields a device prepared according to the requested type (native posix, qemu, hardware, etc.). All types of devices share the same API. This allows for writing tests which are device-type-agnostic. +Scope of this fixture is determined by the ``pytest_dut_scope`` +keyword placed under ``harness_config`` section. + .. code-block:: python @@ -81,8 +84,10 @@ shell ----- Provide an object with methods used to interact with shell application. -It calls `wait_for_promt` method, to not start scenario until DUT is ready. -Note that it uses `dut` fixture, so `dut` can be skipped when `shell` is used. +It calls ``wait_for_promt`` method, to not start scenario until DUT is ready. +Note that it uses ``dut`` fixture, so ``dut`` can be skipped when ``shell`` is used. +Scope of this fixture is determined by the ``pytest_dut_scope`` +keyword placed under ``harness_config`` section. .. code-block:: python diff --git a/doc/develop/test/twister.rst b/doc/develop/test/twister.rst index 4456386b77c..a61744eec6d 100644 --- a/doc/develop/test/twister.rst +++ b/doc/develop/test/twister.rst @@ -501,6 +501,11 @@ harness_config: pytest_args: (default empty) Specify a list of additional arguments to pass to ``pytest``. + pytest_dut_scope: (default function) + The scope for which ``dut`` and ``shell`` pytest fixtures are shared. + If the scope is set to ``function``, DUT is launched for every test case + in python script. For ``session`` scope, DUT is launched only once. + robot_test_path: (default empty) Specify a path to a file containing a Robot Framework test suite to be run. diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py index e2e82674ada..f2b1b53706c 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py @@ -36,11 +36,16 @@ def device_object(twister_harness_config: TwisterHarnessConfig) -> Generator[Dev device_object.close() -@pytest.fixture(scope='function') +def determine_scope(fixture_name, config): + if dut_scope := config.getoption("--dut-scope", None): + return dut_scope + return 'function' + + +@pytest.fixture(scope=determine_scope) def dut(request: pytest.FixtureRequest, device_object: DeviceAdapter) -> Generator[DeviceAdapter, None, None]: """Return launched device - with run application.""" - test_name = request.node.name - device_object.initialize_log_files(test_name) + device_object.initialize_log_files(request.node.name) try: device_object.launch() yield device_object @@ -48,7 +53,7 @@ def dut(request: pytest.FixtureRequest, device_object: DeviceAdapter) -> Generat device_object.close() -@pytest.fixture(scope='function') +@pytest.fixture(scope=determine_scope) def shell(dut: DeviceAdapter) -> Shell: """Return ready to use shell interface""" shell = Shell(dut, timeout=20.0) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py index 076d36d4cc9..dbd3465aba1 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py @@ -100,6 +100,11 @@ def pytest_addoption(parser: pytest.Parser): metavar='PATH', help='Script executed after closing serial connection.' ) + twister_harness_group.addoption( + '--dut-scope', + choices=('function', 'class', 'module', 'package', 'session'), + help='The scope for which `dut` and `shell` fixtures are shared.' + ) def pytest_configure(config: pytest.Config): diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index 6ae2622c810..951a8c40010 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -247,6 +247,7 @@ def generate_command(self): config = self.instance.testsuite.harness_config pytest_root = config.get('pytest_root', ['pytest']) if config else ['pytest'] pytest_args = config.get('pytest_args', []) if config else [] + pytest_dut_scope = config.get('pytest_dut_scope', None) if config else None command = [ 'pytest', '--twister-harness', @@ -260,6 +261,8 @@ def generate_command(self): command.extend([os.path.normpath(os.path.join( self.source_dir, os.path.expanduser(os.path.expandvars(src)))) for src in pytest_root]) command.extend(pytest_args) + if pytest_dut_scope: + command.append(f'--dut-scope={pytest_dut_scope}') handler: Handler = self.instance.handler @@ -406,7 +409,7 @@ def _parse_report_file(self, report): self.instance.execution_time = float(elem_ts.get('time')) for elem_tc in elem_ts.findall('testcase'): - tc = self.instance.get_case_or_create(f"{self.id}.{elem_tc.get('name')}") + tc = self.instance.add_testcase(f"{self.id}.{elem_tc.get('name')}") tc.duration = float(elem_tc.get('time')) elem = elem_tc.find('*') if elem is None: diff --git a/scripts/schemas/twister/testsuite-schema.yaml b/scripts/schemas/twister/testsuite-schema.yaml index 96a121767a5..1e198173c72 100644 --- a/scripts/schemas/twister/testsuite-schema.yaml +++ b/scripts/schemas/twister/testsuite-schema.yaml @@ -104,6 +104,10 @@ mapping: required: false sequence: - type: str + "pytest_dut_scope": + type: str + enum: ["function", "class", "module", "package", "session"] + required: false "regex": type: seq required: false @@ -304,6 +308,10 @@ mapping: required: false sequence: - type: str + "pytest_dut_scope": + type: str + enum: ["function", "class", "module", "package", "session"] + required: false "regex": type: seq required: false diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index e1b27a0cf02..ab4baf88656 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -48,6 +48,25 @@ def test_pytest_command(testinstance: TestInstance, device_type): assert c in command +def test_pytest_command_dut_scope(testinstance: TestInstance): + pytest_harness = Pytest() + dut_scope = 'session' + testinstance.testsuite.harness_config['pytest_dut_scope'] = dut_scope + pytest_harness.configure(testinstance) + command = pytest_harness.generate_command() + assert f'--dut-scope={dut_scope}' in command + + +def test_pytest_command_extra_args(testinstance: TestInstance): + pytest_harness = Pytest() + pytest_args = ['-k test1', '-m mark1'] + testinstance.testsuite.harness_config['pytest_args'] = pytest_args + pytest_harness.configure(testinstance) + command = pytest_harness.generate_command() + for c in pytest_args: + assert c in command + + @pytest.mark.parametrize( ('pytest_root', 'expected'), [ From ac5a9860b73bdbde2e8ba936fdc35a5e7654189c Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Thu, 26 Oct 2023 09:08:54 +0200 Subject: [PATCH 0385/1623] [nrf fromtree] twister: pytest: Improve reporting failed pytest scenarios When pytest scenario fails, then 'handler.log' is printed. Changed to print 'twister_harness.log' that is a log from pytest execution. That file tells much more when test fails. Signed-off-by: Grzegorz Chwierut (cherry picked from commit e466b7ac266b24fe4e1c27b01fef3a722e18ddd3) --- .../device/hardware_adapter.py | 1 - scripts/pylib/twister/twisterlib/harness.py | 2 ++ scripts/pylib/twister/twisterlib/reports.py | 5 +++- scripts/pylib/twister/twisterlib/runner.py | 26 +++++++++++++++---- .../pytest_integration/test_harness_pytest.py | 2 ++ 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py index 403978eed9a..3b7bf5d8214 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py @@ -116,7 +116,6 @@ def _flash_and_run(self) -> None: stdout_decoded = stdout.decode(errors='ignore') with open(self.device_log_path, 'a+') as log_file: log_file.write(stdout_decoded) - logger.debug(f'Flashing output:\n{stdout_decoded}') if self.device_config.post_flash_script: self._run_custom_script(self.device_config.post_flash_script, self.base_timeout) if process is not None and process.returncode == 0: diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index 951a8c40010..bd86df1b4df 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -400,8 +400,10 @@ def _parse_report_file(self, report): if elem_ts := root.find('testsuite'): if elem_ts.get('failures') != '0': self.state = 'failed' + self.instance.reason = f"{elem_ts.get('failures')}/{elem_ts.get('tests')} pytest scenario(s) failed" elif elem_ts.get('errors') != '0': self.state = 'error' + self.instance.reason = 'Error during pytest execution' elif elem_ts.get('skipped') == elem_ts.get('tests'): self.state = 'skipped' else: diff --git a/scripts/pylib/twister/twisterlib/reports.py b/scripts/pylib/twister/twisterlib/reports.py index c1f160caad9..be1bbb4dbd7 100644 --- a/scripts/pylib/twister/twisterlib/reports.py +++ b/scripts/pylib/twister/twisterlib/reports.py @@ -246,6 +246,7 @@ def json_report(self, filename, version="NA"): for instance in self.instances.values(): suite = {} handler_log = os.path.join(instance.build_dir, "handler.log") + pytest_log = os.path.join(instance.build_dir, "twister_harness.log") build_log = os.path.join(instance.build_dir, "build.log") device_log = os.path.join(instance.build_dir, "device.log") @@ -284,7 +285,9 @@ def json_report(self, filename, version="NA"): suite['status'] = instance.status suite["reason"] = instance.reason # FIXME - if os.path.exists(handler_log): + if os.path.exists(pytest_log): + suite["log"] = self.process_log(pytest_log) + elif os.path.exists(handler_log): suite["log"] = self.process_log(handler_log) elif os.path.exists(device_log): suite["log"] = self.process_log(device_log) diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index ef41084cdd4..4dbdb21f882 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -40,6 +40,9 @@ from twisterlib.log_helper import log_command from twisterlib.testinstance import TestInstance +from twisterlib.environment import TwisterEnv +from twisterlib.testsuite import TestSuite +from twisterlib.platform import Platform from twisterlib.testplan import change_skip_to_error_if_integration from twisterlib.harness import HarnessImporter, Pytest @@ -220,7 +223,7 @@ class CMake: config_re = re.compile('(CONFIG_[A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$') dt_re = re.compile('([A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$') - def __init__(self, testsuite, platform, source_dir, build_dir, jobserver): + def __init__(self, testsuite: TestSuite, platform: Platform, source_dir, build_dir, jobserver): self.cwd = None self.capture_output = True @@ -414,7 +417,7 @@ def run_cmake(self, args="", filter_stages=[]): class FilterBuilder(CMake): - def __init__(self, testsuite, platform, source_dir, build_dir, jobserver): + def __init__(self, testsuite: TestSuite, platform: Platform, source_dir, build_dir, jobserver): super().__init__(testsuite, platform, source_dir, build_dir, jobserver) self.log = "config-twister.log" @@ -517,7 +520,7 @@ def parse_generated(self, filter_stages=[]): class ProjectBuilder(FilterBuilder): - def __init__(self, instance, env, jobserver, **kwargs): + def __init__(self, instance: TestInstance, env: TwisterEnv, jobserver, **kwargs): super().__init__(instance.testsuite, instance.platform, instance.testsuite.source_dir, instance.build_dir, jobserver) self.log = "build.log" @@ -527,8 +530,7 @@ def __init__(self, instance, env, jobserver, **kwargs): self.env = env self.duts = None - @staticmethod - def log_info(filename, inline_logs): + def log_info(self, filename, inline_logs, log_testcases=False): filename = os.path.abspath(os.path.realpath(filename)) if inline_logs: logger.info("{:-^100}".format(filename)) @@ -542,6 +544,17 @@ def log_info(filename, inline_logs): logger.error(data) logger.info("{:-^100}".format(filename)) + + if log_testcases: + for tc in self.instance.testcases: + if not tc.reason: + continue + logger.info( + f"\n{str(tc.name).center(100, '_')}\n" + f"{tc.reason}\n" + f"{100*'_'}\n" + f"{tc.output}" + ) else: logger.error("see: " + Fore.YELLOW + filename + Fore.RESET) @@ -551,9 +564,12 @@ def log_info_file(self, inline_logs): b_log = "{}/build.log".format(build_dir) v_log = "{}/valgrind.log".format(build_dir) d_log = "{}/device.log".format(build_dir) + pytest_log = "{}/twister_harness.log".format(build_dir) if os.path.exists(v_log) and "Valgrind" in self.instance.reason: self.log_info("{}".format(v_log), inline_logs) + elif os.path.exists(pytest_log) and os.path.getsize(pytest_log) > 0: + self.log_info("{}".format(pytest_log), inline_logs, log_testcases=True) elif os.path.exists(h_log) and os.path.getsize(h_log) > 0: self.log_info("{}".format(h_log), inline_logs) elif os.path.exists(d_log) and os.path.getsize(d_log) > 0: diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index ab4baf88656..150980059b3 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -188,6 +188,8 @@ def test_err(): assert tc.status == "failed" assert tc.output assert tc.reason + assert testinstance.reason + assert '2/2' in testinstance.reason def test_if_report_with_skip(pytester, testinstance: TestInstance): From 196bab5029e3217952429c58f38a2be656dfee94 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Thu, 9 Nov 2023 18:15:32 +0100 Subject: [PATCH 0386/1623] [nrf fromtree] doc: gsg: macOS: Include instructions to add homebrew to the path Multiple users have failed to read the output from the Homebrew installation script, which instructs the user how to add it to the path. Include the instructions in the guide. Also add a step to include the Homebrew Python executable to the path, which allows then for invocation of python and pip as well as python3 and pip3. Signed-off-by: Carles Cufi (cherry picked from commit 318836af23aa1607342a019c01580fd87442f32b) --- doc/develop/getting_started/index.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/doc/develop/getting_started/index.rst b/doc/develop/getting_started/index.rst index 4a1b345ee62..f7a76a71585 100644 --- a/doc/develop/getting_started/index.rst +++ b/doc/develop/getting_started/index.rst @@ -118,12 +118,32 @@ The current minimum required version for the main dependencies are: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + #. After the Homebrew installation script completes, follow the on-screen + instructions to add the Homebrew installation to the path. + + * On macOS running on Apple Silicon, this is achieved with: + + .. code-block:: bash + + (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile + source ~/.zprofile + + * On macOS running on Intel, use the command for Apple Silicon, but replace ``/opt/homebrew/`` with ``/usr/local/``. + #. Use ``brew`` to install the required dependencies: .. code-block:: bash brew install cmake ninja gperf python3 ccache qemu dtc wget libmagic + #. Add the Homebrew Python folder to the path, in order to be able to + execute ``python`` and ``pip`` as well ``python3`` and ``pip3``. + + .. code-block:: bash + + (echo; echo 'export PATH="'$(brew --prefix)'/opt/python/libexec/bin:$PATH"') >> ~/.zprofile + source ~/.zprofile + .. group-tab:: Windows .. note:: From 2a8c218f530fcc80ef3209ca49d36dc7a68d2b59 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 8 Nov 2023 20:23:37 +0530 Subject: [PATCH 0387/1623] [nrf fromtree] net: Remove unnecessary lock The main action in this function it queueing the packet for transmission which doesn't need a lock and interface flags use atomic operations. So, remove the unnecessary lock. Signed-off-by: Chaitanya Tata (cherry picked from commit ed17320c3d2e43c76b09dc359d3b371e9d23732d) --- subsys/net/ip/net_if.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 828e48ecf78..035e18da74f 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -448,8 +448,6 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt) enum net_verdict verdict = NET_OK; int status = -EIO; - net_if_lock(iface); - if (!net_if_flag_is_set(iface, NET_IF_LOWER_UP) || net_if_flag_is_set(iface, NET_IF_SUSPENDED)) { /* Drop packet if interface is not up */ @@ -532,8 +530,6 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt) net_if_queue_tx(iface, pkt); } - net_if_unlock(iface); - return verdict; } From a707fc77ef2d80ce5f4bed6e5c9bdd6bc0cc3912 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Mon, 11 Sep 2023 17:54:13 +0300 Subject: [PATCH 0388/1623] [nrf fromtree] net: arp: Directly send the queued pkt We must send the packet without queueing it. The pkt has already been queued for sending, once by net_if and second time in the ARP queue. We must not queue it twice in net_if so that the statistics of the pkt are not counted twice and the packet filter callbacks are only called once. Fixes #62483 Signed-off-by: Jukka Rissanen (cherry picked from commit 0e5016e5026fb1f83bd32c1255a9edb2bdf53127) --- subsys/net/l2/ethernet/arp.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/subsys/net/l2/ethernet/arp.c b/subsys/net/l2/ethernet/arp.c index f26c2f7ba96..35a2ec63a64 100644 --- a/subsys/net/l2/ethernet/arp.c +++ b/subsys/net/l2/ethernet/arp.c @@ -514,6 +514,8 @@ static void arp_update(struct net_if *iface, sys_slist_prepend(&arp_table, &entry->node); while (!k_fifo_is_empty(&entry->pending_queue)) { + int ret; + pkt = k_fifo_get(&entry->pending_queue, K_FOREVER); /* Set the dst in the pending packet */ @@ -525,7 +527,17 @@ static void arp_update(struct net_if *iface, net_sprint_ipv4_addr(&entry->ip), pkt, pkt->frags); - net_if_queue_tx(iface, pkt); + /* We directly send the packet without first queueing it. + * The pkt has already been queued for sending, once by + * net_if and second time in the ARP queue. We must not + * queue it twice in net_if so that the statistics of + * the pkt are not counted twice and the packet filter + * callbacks are only called once. + */ + ret = net_if_l2(iface)->send(iface, pkt); + if (ret < 0) { + net_pkt_unref(pkt); + } } k_mutex_unlock(&arp_mutex); From 9ed7de1afad3ebc08a3ce379bee0bbbbd9702414 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Fri, 10 Nov 2023 10:23:34 +0100 Subject: [PATCH 0389/1623] [nrf fromlist] net: iface: Introduce TX mutex locking A recent iface lock removal in ed17320c3d2e43c76b09dc359d3b371e9d23732d exposed issues with concurrent access on TX to drivers that are not re-entrant. Reverting that commit does not really solve the problem, as it would still exist if multiple Traffic Class queues are in use. Therefore, introduce a separate mutex for TX data path, protecting the L2/driver from concurrent transfers from several threads. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65049 Signed-off-by: Robert Lubos --- include/zephyr/net/net_if.h | 29 +++++++++++++++++++++++++++++ subsys/net/ip/net_if.c | 3 +++ subsys/net/l2/ethernet/arp.c | 2 ++ 3 files changed, 34 insertions(+) diff --git a/include/zephyr/net/net_if.h b/include/zephyr/net/net_if.h index b06bf74de03..92a59ad3b73 100644 --- a/include/zephyr/net/net_if.h +++ b/include/zephyr/net/net_if.h @@ -212,6 +212,9 @@ enum net_if_flag { /** IPv6 Multicast Listener Discovery disabled. */ NET_IF_IPV6_NO_MLD, + /** Mutex locking on TX data path disabled on the interface. */ + NET_IF_NO_TX_LOCK, + /** @cond INTERNAL_HIDDEN */ /* Total number of flags - must be at the end of the enum */ NET_IF_NUM_FLAGS @@ -613,6 +616,7 @@ struct net_if { #endif struct k_mutex lock; + struct k_mutex tx_lock; }; static inline void net_if_lock(struct net_if *iface) @@ -629,6 +633,31 @@ static inline void net_if_unlock(struct net_if *iface) k_mutex_unlock(&iface->lock); } +static inline bool net_if_flag_is_set(struct net_if *iface, + enum net_if_flag value); + +static inline void net_if_tx_lock(struct net_if *iface) +{ + NET_ASSERT(iface); + + if (net_if_flag_is_set(iface, NET_IF_NO_TX_LOCK)) { + return; + } + + (void)k_mutex_lock(&iface->tx_lock, K_FOREVER); +} + +static inline void net_if_tx_unlock(struct net_if *iface) +{ + NET_ASSERT(iface); + + if (net_if_flag_is_set(iface, NET_IF_NO_TX_LOCK)) { + return; + } + + k_mutex_unlock(&iface->tx_lock); +} + /** * @brief Set a value in network interface flags * diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 035e18da74f..026eaa88b48 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -265,7 +265,9 @@ static bool net_if_tx(struct net_if *iface, struct net_pkt *pkt) } } + net_if_tx_lock(iface); status = net_if_l2(iface)->send(iface, pkt); + net_if_tx_unlock(iface); if (IS_ENABLED(CONFIG_NET_PKT_TXTIME_STATS)) { uint32_t end_tick = k_cycle_get_32(); @@ -437,6 +439,7 @@ static inline void init_iface(struct net_if *iface) #endif k_mutex_init(&iface->lock); + k_mutex_init(&iface->tx_lock); api->init(iface); } diff --git a/subsys/net/l2/ethernet/arp.c b/subsys/net/l2/ethernet/arp.c index 35a2ec63a64..39a06ed64a0 100644 --- a/subsys/net/l2/ethernet/arp.c +++ b/subsys/net/l2/ethernet/arp.c @@ -534,7 +534,9 @@ static void arp_update(struct net_if *iface, * the pkt are not counted twice and the packet filter * callbacks are only called once. */ + net_if_tx_lock(iface); ret = net_if_l2(iface)->send(iface, pkt); + net_if_tx_unlock(iface); if (ret < 0) { net_pkt_unref(pkt); } From 2c3b9c4f763085faa0c4654bc4cce8baaf32b89c Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Wed, 6 Sep 2023 16:11:20 +0800 Subject: [PATCH 0390/1623] [nrf fromlist] Bluetooth: Mesh: Remove bits for adv tag since tag for buf single only, no need for bit, also for save some memory for rfu. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/62331 Signed-off-by: Lingao Meng (cherry picked from commit b14d235c31e5e79c857e0e46a1a632f35e2ca77e) --- subsys/bluetooth/mesh/adv.c | 14 +++++------ subsys/bluetooth/mesh/adv.h | 17 +++++++++---- subsys/bluetooth/mesh/adv_ext.c | 42 +++++++++++++++---------------- subsys/bluetooth/mesh/statistic.c | 12 ++++----- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index 2132c14e151..e67d96414e7 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -138,7 +138,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, uint8_t xmit, k_timeout_t timeout) { #if defined(CONFIG_BT_MESH_RELAY) - if (tag & BT_MESH_RELAY_ADV) { + if (tag == BT_MESH_RELAY_ADV) { return bt_mesh_adv_create_from_pool(&relay_buf_pool, adv_relay_pool, type, tag, xmit, timeout); @@ -146,7 +146,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, #endif #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - if (tag & BT_MESH_FRIEND_ADV) { + if (tag == BT_MESH_FRIEND_ADV) { return bt_mesh_adv_create_from_pool(&friend_buf_pool, adv_friend_pool, type, tag, xmit, timeout); @@ -202,14 +202,14 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) return process_events(events, ARRAY_SIZE(events)); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(uint8_t tag, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) { - if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && tag & BT_MESH_FRIEND_ADV) { + if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && tags & BT_MESH_FRIEND_ADV_BIT) { return net_buf_get(&bt_mesh_friend_queue, timeout); } #if CONFIG_BT_MESH_RELAY_ADV_SETS - if (tag & BT_MESH_RELAY_ADV) { + if (tags & BT_MESH_RELAY_ADV_BIT) { return net_buf_get(&bt_mesh_relay_queue, timeout); } #endif @@ -222,9 +222,9 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) return net_buf_get(&bt_mesh_adv_queue, timeout); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(uint8_t tag, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) { - ARG_UNUSED(tag); + ARG_UNUSED(tags); return bt_mesh_adv_buf_get(timeout); } diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index 3d0acf8a7ac..22a8e0645e1 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -26,10 +26,17 @@ enum bt_mesh_adv_type { }; enum bt_mesh_adv_tag { - BT_MESH_LOCAL_ADV = BIT(0), - BT_MESH_RELAY_ADV = BIT(1), - BT_MESH_PROXY_ADV = BIT(2), - BT_MESH_FRIEND_ADV = BIT(3), + BT_MESH_LOCAL_ADV, + BT_MESH_RELAY_ADV, + BT_MESH_PROXY_ADV, + BT_MESH_FRIEND_ADV, +}; + +enum bt_mesh_adv_tags { + BT_MESH_LOCAL_ADV_BIT = BIT(BT_MESH_LOCAL_ADV), + BT_MESH_RELAY_ADV_BIT = BIT(BT_MESH_RELAY_ADV), + BT_MESH_PROXY_ADV_BIT = BIT(BT_MESH_PROXY_ADV), + BT_MESH_FRIEND_ADV_BIT = BIT(BT_MESH_FRIEND_ADV), }; struct bt_mesh_adv { @@ -57,7 +64,7 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout); -struct net_buf *bt_mesh_adv_buf_get_by_tag(uint8_t tag, k_timeout_t timeout); +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout); void bt_mesh_adv_gatt_update(void); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 5c1a2bc3c32..d347602ac09 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -60,7 +60,7 @@ enum { }; struct bt_mesh_ext_adv { - uint8_t tag; + enum bt_mesh_adv_tags tags; ATOMIC_DEFINE(flags, ADV_FLAGS_NUM); struct bt_le_ext_adv *instance; struct net_buf *buf; @@ -73,17 +73,17 @@ static void send_pending_adv(struct k_work *work); static bool schedule_send(struct bt_mesh_ext_adv *adv); static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { - .tag = ( + .tags = ( #if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - BT_MESH_FRIEND_ADV | + BT_MESH_FRIEND_ADV_BIT | #endif #if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - BT_MESH_PROXY_ADV | + BT_MESH_PROXY_ADV_BIT | #endif /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) - BT_MESH_RELAY_ADV | + BT_MESH_RELAY_ADV_BIT | #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ - BT_MESH_LOCAL_ADV), + BT_MESH_LOCAL_ADV_BIT), .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; @@ -91,7 +91,7 @@ static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { #if CONFIG_BT_MESH_RELAY_ADV_SETS static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_RELAY_ADV_SETS) = { [0 ... CONFIG_BT_MESH_RELAY_ADV_SETS - 1] = { - .tag = BT_MESH_RELAY_ADV, + .tags = BT_MESH_RELAY_ADV_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), } }; @@ -100,7 +100,7 @@ static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_ #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) #define ADV_EXT_FRIEND 1 static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { - .tag = BT_MESH_FRIEND_ADV, + .tags = BT_MESH_FRIEND_ADV_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; #else /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ @@ -110,7 +110,7 @@ static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { #if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) #define ADV_EXT_GATT 1 static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_gatt) = { - .tag = BT_MESH_PROXY_ADV, + .tags = BT_MESH_PROXY_ADV_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; #else /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ @@ -259,18 +259,18 @@ static int buf_send(struct bt_mesh_ext_adv *adv, struct net_buf *buf) return err; } -static const char *adv_tag_to_str(enum bt_mesh_adv_tag tag) +static const char *adv_tag_to_str(enum bt_mesh_adv_tags tags) { - if (tag & BT_MESH_LOCAL_ADV) { + if (tags & BT_MESH_LOCAL_ADV_BIT) { return "local adv"; - } else if (tag & BT_MESH_PROXY_ADV) { + } else if (tags & BT_MESH_PROXY_ADV_BIT) { return "proxy adv"; - } else if (tag & BT_MESH_RELAY_ADV) { + } else if (tags & BT_MESH_RELAY_ADV_BIT) { return "relay adv"; - } else if (tag & BT_MESH_FRIEND_ADV) { + } else if (tags & BT_MESH_FRIEND_ADV_BIT) { return "friend adv"; } else { - return "(unknown tag)"; + return "(unknown tags)"; } } @@ -289,8 +289,8 @@ static void send_pending_adv(struct k_work *work) */ int64_t duration = k_uptime_delta(&adv->timestamp); - LOG_DBG("Advertising stopped after %u ms for (%u) %s", (uint32_t)duration, adv->tag, - adv_tag_to_str(adv->tag)); + LOG_DBG("Advertising stopped after %u ms for (%u) %s", (uint32_t)duration, adv->tags, + adv_tag_to_str(adv->tags)); atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(adv->flags, ADV_FLAG_PROXY); @@ -308,7 +308,7 @@ static void send_pending_adv(struct k_work *work) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULED); - while ((buf = bt_mesh_adv_buf_get_by_tag(adv->tag, K_NO_WAIT))) { + while ((buf = bt_mesh_adv_buf_get_by_tag(adv->tags, K_NO_WAIT))) { /* busy == 0 means this was canceled */ if (!BT_MESH_ADV(buf)->busy) { net_buf_unref(buf); @@ -326,7 +326,7 @@ static void send_pending_adv(struct k_work *work) } if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || - !(adv->tag & BT_MESH_PROXY_ADV)) { + !(adv->tags & BT_MESH_RELAY_ADV_BIT)) { return; } @@ -369,8 +369,8 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); - if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && adv->tag & BT_MESH_FRIEND_ADV) || - (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tag == BT_MESH_RELAY_ADV)) { + if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && adv->tags & BT_MESH_FRIEND_ADV_BIT) || + (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_RELAY_ADV_BIT)) { k_work_reschedule(&adv->work, K_NO_WAIT); } else { /* The controller will send the next advertisement immediately. diff --git a/subsys/bluetooth/mesh/statistic.c b/subsys/bluetooth/mesh/statistic.c index 5b1ffe7e0f5..046fa3c0eeb 100644 --- a/subsys/bluetooth/mesh/statistic.c +++ b/subsys/bluetooth/mesh/statistic.c @@ -24,22 +24,22 @@ void bt_mesh_stat_reset(void) void bt_mesh_stat_planned_count(struct bt_mesh_adv *adv) { - if (adv->tag & BT_MESH_LOCAL_ADV) { + if (adv->tag == BT_MESH_LOCAL_ADV) { stat.tx_local_planned++; - } else if (adv->tag & BT_MESH_RELAY_ADV) { + } else if (adv->tag == BT_MESH_RELAY_ADV) { stat.tx_adv_relay_planned++; - } else if (adv->tag & BT_MESH_FRIEND_ADV) { + } else if (adv->tag == BT_MESH_FRIEND_ADV) { stat.tx_friend_planned++; } } void bt_mesh_stat_succeeded_count(struct bt_mesh_adv *adv) { - if (adv->tag & BT_MESH_LOCAL_ADV) { + if (adv->tag == BT_MESH_LOCAL_ADV) { stat.tx_local_succeeded++; - } else if (adv->tag & BT_MESH_RELAY_ADV) { + } else if (adv->tag == BT_MESH_RELAY_ADV) { stat.tx_adv_relay_succeeded++; - } else if (adv->tag & BT_MESH_FRIEND_ADV) { + } else if (adv->tag == BT_MESH_FRIEND_ADV) { stat.tx_friend_succeeded++; } } From 4d33c79aca6fab97c81dfc03228b997028989562 Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Wed, 6 Sep 2023 16:47:20 +0800 Subject: [PATCH 0391/1623] [nrf fromlist] Bluetooth: Mesh: Rename adv relay to adv simultaneous Since notice that simultaneous advertising is not only used by relay message, provision over pb-adv can also be used. so it was changed to a more general name. refs:https://github.com/zephyrproject-rtos/zephyr/pull/48903 Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/62331 Signed-off-by: Lingao Meng (cherry picked from commit 141467a2611bde904cacc7d3f6b89ac282c617ac) --- subsys/bluetooth/mesh/Kconfig | 40 +++++-- subsys/bluetooth/mesh/adv.c | 44 +++---- subsys/bluetooth/mesh/adv.h | 22 ++-- subsys/bluetooth/mesh/adv_ext.c | 109 ++++++++++++------ subsys/bluetooth/mesh/adv_legacy.c | 8 +- subsys/bluetooth/mesh/beacon.c | 6 +- subsys/bluetooth/mesh/friend.c | 2 +- subsys/bluetooth/mesh/net.c | 2 +- subsys/bluetooth/mesh/pb_adv.c | 19 ++- subsys/bluetooth/mesh/statistic.c | 12 +- subsys/bluetooth/mesh/transport.c | 4 +- subsys/bluetooth/mesh/transport_legacy.c | 4 +- tests/bluetooth/mesh/basic/multi_ext_adv.conf | 2 +- .../bsim/bluetooth/mesh/src/test_advertiser.c | 18 +-- 14 files changed, 185 insertions(+), 107 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 605e4608be7..a05d3917c1d 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -103,22 +103,22 @@ menuconfig BT_MESH_ADV_EXT if BT_MESH_ADV_EXT -config BT_MESH_RELAY_ADV_SETS - int "Maximum of simultaneous relay message support" +config BT_MESH_SIMULT_ADV_SETS + int "Maximum number of parallel advertising sets that can be used by the Bluetooth Mesh stack" default 0 range 0 BT_EXT_ADV_MAX_ADV_SET - depends on BT_MESH_RELAY + depends on BT_MESH_RELAY || BT_MESH_PB_ADV help - Maximum of simultaneous relay message support. Requires controller support + Maximum of simultaneous message support. Requires controller support multiple advertising sets. config BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET bool "Use the main advertising set to relay messages" - depends on BT_MESH_RELAY_ADV_SETS > 0 + depends on BT_MESH_SIMULT_ADV_SETS > 0 help When this option is enabled, there is a message that needs to be relayed, all relay advertising sets defined by - CONFIG_BT_MESH_RELAY_ADV_SETS are busy with relaying messages + CONFIG_BT_MESH_SIMULT_ADV_SETS are busy with relaying messages and the main advertising set is not busy with sending local messages, the stack will use the main advertising set to relay the message. This maximizes the utilization efficiency of @@ -199,6 +199,32 @@ config BT_MESH_PB_ADV_RETRANS_TIMEOUT help Timeout value of retransmit provisioning PDUs. +config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT + int "Link Open and Transaction PDU retransmit count" + default 7 if BT_MESH_SIMULT_ADV_SETS > 0 + default 0 + range 0 7 + help + Controls the number of retransmissions of original Link Open and Transaction PDU, + in addition to the first transmission. + +config BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT + int "Link Ack and Transaction Ack retransmit count" + default 2 + range 0 7 + help + Controls the number of retransmissions of original Link Open and Transaction Acknowledgment PDU, + in addition to the first transmission. + +config BT_MESH_PB_ADV_LINK_CLOSE_RETRANSMIT_COUNT + int "Link Close retransmit count" + default 7 if BT_MESH_SIMULT_ADV_SETS > 0 + default 2 + range 0 7 + help + Controls the number of retransmissions of original Link Close, + in addition to the first transmission. + endif # BT_MESH_PB_ADV if BT_CONN @@ -375,7 +401,7 @@ config BT_MESH_RELAY_BUF_COUNT of packet drops. When considering the message latency, also consider the values of BT_MESH_RELAY_RETRANSMIT_COUNT and BT_MESH_RELAY_RETRANSMIT_INTERVAL. A higher number of - BT_MESH_RELAY_ADV_SETS allows the increase in the number of buffers + BT_MESH_SIMULT_ADV_SETS allows the increase in the number of buffers while maintaining the latency. endif # BT_MESH_RELAY diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index e67d96414e7..c7abcd53d70 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -44,7 +44,7 @@ const uint8_t bt_mesh_adv_type[BT_MESH_ADV_TYPES] = { static bool active_scanning; static K_FIFO_DEFINE(bt_mesh_adv_queue); -static K_FIFO_DEFINE(bt_mesh_relay_queue); +static K_FIFO_DEFINE(bt_mesh_simult_queue); static K_FIFO_DEFINE(bt_mesh_friend_queue); void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv *adv) @@ -138,7 +138,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, uint8_t xmit, k_timeout_t timeout) { #if defined(CONFIG_BT_MESH_RELAY) - if (tag == BT_MESH_RELAY_ADV) { + if (tag == BT_MESH_ADV_TAG_RELAY) { return bt_mesh_adv_create_from_pool(&relay_buf_pool, adv_relay_pool, type, tag, xmit, timeout); @@ -146,7 +146,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, #endif #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - if (tag == BT_MESH_FRIEND_ADV) { + if (tag == BT_MESH_ADV_TAG_FRIEND) { return bt_mesh_adv_create_from_pool(&friend_buf_pool, adv_friend_pool, type, tag, xmit, timeout); @@ -157,7 +157,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, tag, xmit, timeout); } -#if CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE +#if CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE static struct net_buf *process_events(struct k_poll_event *ev, int count) { for (; count; ev++, count--) { @@ -189,7 +189,7 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, K_POLL_MODE_NOTIFY_ONLY, - &bt_mesh_relay_queue, + &bt_mesh_simult_queue, 0), #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ }; @@ -204,19 +204,20 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) { - if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && tags & BT_MESH_FRIEND_ADV_BIT) { + if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && + tags & BT_MESH_ADV_TAG_FRIEND_BIT) { return net_buf_get(&bt_mesh_friend_queue, timeout); } -#if CONFIG_BT_MESH_RELAY_ADV_SETS - if (tags & BT_MESH_RELAY_ADV_BIT) { - return net_buf_get(&bt_mesh_relay_queue, timeout); + if (tags & BT_MESH_ADV_TAG_LOCAL_BIT) { + return bt_mesh_adv_buf_get(timeout); } -#endif - return bt_mesh_adv_buf_get(timeout); +#if CONFIG_BT_MESH_SIMULT_ADV_SETS + return net_buf_get(&bt_mesh_simult_queue, timeout); +#endif } -#else /* !(CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) */ +#else /* !(CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) */ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) { return net_buf_get(&bt_mesh_adv_queue, timeout); @@ -228,7 +229,7 @@ struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout return bt_mesh_adv_buf_get(timeout); } -#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ +#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ void bt_mesh_adv_buf_get_cancel(void) { @@ -236,9 +237,9 @@ void bt_mesh_adv_buf_get_cancel(void) k_fifo_cancel_wait(&bt_mesh_adv_queue); -#if CONFIG_BT_MESH_RELAY_ADV_SETS - k_fifo_cancel_wait(&bt_mesh_relay_queue); -#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ +#if CONFIG_BT_MESH_SIMULT_ADV_SETS + k_fifo_cancel_wait(&bt_mesh_simult_queue); +#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { k_fifo_cancel_wait(&bt_mesh_friend_queue); @@ -260,16 +261,17 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, } if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - BT_MESH_ADV(buf)->tag == BT_MESH_FRIEND_ADV) { + BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_FRIEND) { net_buf_put(&bt_mesh_friend_queue, net_buf_ref(buf)); bt_mesh_adv_buf_friend_ready(); return; } -#if CONFIG_BT_MESH_RELAY_ADV_SETS - if (BT_MESH_ADV(buf)->tag == BT_MESH_RELAY_ADV) { - net_buf_put(&bt_mesh_relay_queue, net_buf_ref(buf)); - bt_mesh_adv_buf_relay_ready(); +#if CONFIG_BT_MESH_SIMULT_ADV_SETS + if (BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_RELAY || + BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV) { + net_buf_put(&bt_mesh_simult_queue, net_buf_ref(buf)); + bt_mesh_adv_buf_simult_ready(); return; } #endif diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index 22a8e0645e1..50c5b47604c 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -26,17 +26,19 @@ enum bt_mesh_adv_type { }; enum bt_mesh_adv_tag { - BT_MESH_LOCAL_ADV, - BT_MESH_RELAY_ADV, - BT_MESH_PROXY_ADV, - BT_MESH_FRIEND_ADV, + BT_MESH_ADV_TAG_LOCAL, + BT_MESH_ADV_TAG_RELAY, + BT_MESH_ADV_TAG_PROXY, + BT_MESH_ADV_TAG_FRIEND, + BT_MESH_ADV_TAG_PROV, }; enum bt_mesh_adv_tags { - BT_MESH_LOCAL_ADV_BIT = BIT(BT_MESH_LOCAL_ADV), - BT_MESH_RELAY_ADV_BIT = BIT(BT_MESH_RELAY_ADV), - BT_MESH_PROXY_ADV_BIT = BIT(BT_MESH_PROXY_ADV), - BT_MESH_FRIEND_ADV_BIT = BIT(BT_MESH_FRIEND_ADV), + BT_MESH_ADV_TAG_LOCAL_BIT = BIT(BT_MESH_ADV_TAG_LOCAL), + BT_MESH_ADV_TAG_RELAY_BIT = BIT(BT_MESH_ADV_TAG_RELAY), + BT_MESH_ADV_TAG_PROXY_BIT = BIT(BT_MESH_ADV_TAG_PROXY), + BT_MESH_ADV_TAG_FRIEND_BIT = BIT(BT_MESH_ADV_TAG_FRIEND), + BT_MESH_ADV_TAG_PROV_BIT = BIT(BT_MESH_ADV_TAG_PROV), }; struct bt_mesh_adv { @@ -80,7 +82,9 @@ int bt_mesh_adv_enable(void); void bt_mesh_adv_buf_local_ready(void); -void bt_mesh_adv_buf_relay_ready(void); +void bt_mesh_adv_buf_simult_ready(void); + +void bt_mesh_adv_buf_terminate(struct net_buf *buf); void bt_mesh_adv_buf_friend_ready(void); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index d347602ac09..2065de372a4 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -33,8 +33,8 @@ LOG_MODULE_REGISTER(bt_mesh_adv_ext); /* Convert from ms to 0.625ms units */ #define ADV_INT_FAST_MS 20 -#ifndef CONFIG_BT_MESH_RELAY_ADV_SETS -#define CONFIG_BT_MESH_RELAY_ADV_SETS 0 +#ifndef CONFIG_BT_MESH_SIMULT_ADV_SETS +#define CONFIG_BT_MESH_SIMULT_ADV_SETS 0 #endif enum { @@ -75,32 +75,40 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv); static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { .tags = ( #if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - BT_MESH_FRIEND_ADV_BIT | + BT_MESH_ADV_TAG_FRIEND_BIT | #endif #if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - BT_MESH_PROXY_ADV_BIT | + BT_MESH_ADV_TAG_PROXY_BIT | #endif /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) - BT_MESH_RELAY_ADV_BIT | + BT_MESH_ADV_TAG_RELAY_BIT | #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ - BT_MESH_LOCAL_ADV_BIT), + BT_MESH_ADV_TAG_LOCAL_BIT), .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; -#if CONFIG_BT_MESH_RELAY_ADV_SETS -static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_RELAY_ADV_SETS) = { - [0 ... CONFIG_BT_MESH_RELAY_ADV_SETS - 1] = { - .tags = BT_MESH_RELAY_ADV_BIT, +#if CONFIG_BT_MESH_SIMULT_ADV_SETS +static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_SIMULT_ADV_SETS) = { + [0 ... CONFIG_BT_MESH_SIMULT_ADV_SETS - 1] = { + .tags = ( +#if defined(CONFIG_BT_MESH_RELAY) + BT_MESH_ADV_TAG_RELAY_BIT | +#endif /* CONFIG_BT_MESH_RELAY */ +#if defined(CONFIG_BT_MESH_PB_ADV) + BT_MESH_ADV_TAG_PROV_BIT | +#endif /* CONFIG_BT_MESH_PB_ADV */ + 0), + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), } }; -#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ +#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) #define ADV_EXT_FRIEND 1 static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { - .tags = BT_MESH_FRIEND_ADV_BIT, + .tags = BT_MESH_ADV_TAG_FRIEND_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; #else /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ @@ -110,25 +118,25 @@ static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { #if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) #define ADV_EXT_GATT 1 static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_gatt) = { - .tags = BT_MESH_PROXY_ADV_BIT, + .tags = BT_MESH_ADV_TAG_PROXY_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; #else /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #define ADV_EXT_GATT 0 #endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ -#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_RELAY_ADV_SETS + ADV_EXT_FRIEND + ADV_EXT_GATT) +#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_SIMULT_ADV_SETS + ADV_EXT_FRIEND + ADV_EXT_GATT) BUILD_ASSERT(CONFIG_BT_EXT_ADV_MAX_ADV_SET >= BT_MESH_ADV_COUNT, "Insufficient adv instances"); static inline struct bt_mesh_ext_adv *relay_adv_get(void) { -#if CONFIG_BT_MESH_RELAY_ADV_SETS +#if CONFIG_BT_MESH_SIMULT_ADV_SETS return adv_relay; -#else /* !CONFIG_BT_MESH_RELAY_ADV_SETS */ +#else /* !CONFIG_BT_MESH_SIMULT_ADV_SETS */ return &adv_main; -#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ +#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ } static inline struct bt_mesh_ext_adv *gatt_adv_get(void) @@ -259,20 +267,13 @@ static int buf_send(struct bt_mesh_ext_adv *adv, struct net_buf *buf) return err; } -static const char *adv_tag_to_str(enum bt_mesh_adv_tags tags) -{ - if (tags & BT_MESH_LOCAL_ADV_BIT) { - return "local adv"; - } else if (tags & BT_MESH_PROXY_ADV_BIT) { - return "proxy adv"; - } else if (tags & BT_MESH_RELAY_ADV_BIT) { - return "relay adv"; - } else if (tags & BT_MESH_FRIEND_ADV_BIT) { - return "friend adv"; - } else { - return "(unknown tags)"; - } -} +static const char * const adv_tag_to_str[] = { + [BT_MESH_ADV_TAG_LOCAL] = "local adv", + [BT_MESH_ADV_TAG_RELAY] = "relay adv", + [BT_MESH_ADV_TAG_PROXY] = "proxy adv", + [BT_MESH_ADV_TAG_FRIEND] = "friend adv", + [BT_MESH_ADV_TAG_PROV] = "prov adv", +}; static void send_pending_adv(struct k_work *work) { @@ -289,8 +290,9 @@ static void send_pending_adv(struct k_work *work) */ int64_t duration = k_uptime_delta(&adv->timestamp); - LOG_DBG("Advertising stopped after %u ms for (%u) %s", (uint32_t)duration, adv->tags, - adv_tag_to_str(adv->tags)); + LOG_DBG("Advertising stopped after %u ms for %s", (uint32_t)duration, + adv->buf ? adv_tag_to_str[BT_MESH_ADV(adv->buf)->tag] : + adv_tag_to_str[BT_MESH_ADV_TAG_PROXY]); atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(adv->flags, ADV_FLAG_PROXY); @@ -326,7 +328,7 @@ static void send_pending_adv(struct k_work *work) } if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || - !(adv->tags & BT_MESH_RELAY_ADV_BIT)) { + !(adv->tags & BT_MESH_ADV_TAG_PROXY_BIT)) { return; } @@ -369,8 +371,9 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); - if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && adv->tags & BT_MESH_FRIEND_ADV_BIT) || - (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_RELAY_ADV_BIT)) { + if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && + adv->tags & BT_MESH_ADV_TAG_FRIEND_BIT) || + (CONFIG_BT_MESH_SIMULT_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_RELAY_BIT)) { k_work_reschedule(&adv->work, K_NO_WAIT); } else { /* The controller will send the next advertisement immediately. @@ -394,11 +397,11 @@ void bt_mesh_adv_buf_local_ready(void) (void)schedule_send(&adv_main); } -void bt_mesh_adv_buf_relay_ready(void) +void bt_mesh_adv_buf_simult_ready(void) { struct bt_mesh_ext_adv *adv = relay_adv_get(); - for (int i = 0; i < CONFIG_BT_MESH_RELAY_ADV_SETS; i++) { + for (int i = 0; i < CONFIG_BT_MESH_SIMULT_ADV_SETS; i++) { if (schedule_send(&adv[i])) { return; } @@ -417,6 +420,36 @@ void bt_mesh_adv_buf_friend_ready(void) #endif } +void bt_mesh_adv_buf_terminate(struct net_buf *buf) +{ + int err; + + STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { + if (adv->buf != buf) { + continue; + } + + if (!atomic_test_bit(adv->flags, ADV_FLAG_ACTIVE)) { + return; + } + + err = bt_le_ext_adv_stop(adv->instance); + if (err) { + LOG_ERR("Failed to stop adv %d", err); + return; + } + + /* Do not call `cb:end`, since this user action */ + BT_MESH_ADV(adv->buf)->cb = NULL; + + atomic_set_bit(adv->flags, ADV_FLAG_SENT); + + k_work_submit(&adv->work.work); + + break; + } +} + void bt_mesh_adv_init(void) { struct bt_le_adv_param adv_param = { diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index 8136aef9f22..cb4028662f9 100644 --- a/subsys/bluetooth/mesh/adv_legacy.c +++ b/subsys/bluetooth/mesh/adv_legacy.c @@ -195,7 +195,7 @@ void bt_mesh_adv_buf_local_ready(void) /* Will be handled automatically */ } -void bt_mesh_adv_buf_relay_ready(void) +void bt_mesh_adv_buf_simult_ready(void) { /* Will be handled automatically */ } @@ -205,6 +205,12 @@ void bt_mesh_adv_gatt_update(void) bt_mesh_adv_buf_get_cancel(); } +void bt_mesh_adv_buf_terminate(struct net_buf *buf) +{ + /* todo */ + ARG_UNUSED(buf); +} + void bt_mesh_adv_init(void) { k_thread_create(&adv_thread_data, adv_thread_stack, diff --git a/subsys/bluetooth/mesh/beacon.c b/subsys/bluetooth/mesh/beacon.c index 8c0ac3b54e9..afdea5b4c6a 100644 --- a/subsys/bluetooth/mesh/beacon.c +++ b/subsys/bluetooth/mesh/beacon.c @@ -271,7 +271,7 @@ static bool net_beacon_send(struct bt_mesh_subnet *sub, struct bt_mesh_beacon *b return false; } - buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, PROV_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate beacon buffer"); @@ -335,7 +335,7 @@ static int unprovisioned_beacon_send(void) LOG_DBG(""); - buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, UNPROV_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate beacon buffer"); @@ -362,7 +362,7 @@ static int unprovisioned_beacon_send(void) if (prov->uri) { size_t len; - buf = bt_mesh_adv_create(BT_MESH_ADV_URI, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_URI, BT_MESH_ADV_TAG_LOCAL, UNPROV_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate URI buffer"); diff --git a/subsys/bluetooth/mesh/friend.c b/subsys/bluetooth/mesh/friend.c index 179755d9706..73b75eadf4f 100644 --- a/subsys/bluetooth/mesh/friend.c +++ b/subsys/bluetooth/mesh/friend.c @@ -1281,7 +1281,7 @@ static void friend_timeout(struct k_work *work) frnd->queue_size--; send_last: - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_FRIEND_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_FRIEND, FRIEND_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate friend adv buffer"); diff --git a/subsys/bluetooth/mesh/net.c b/subsys/bluetooth/mesh/net.c index 2cfc709c648..61efaeb2c81 100644 --- a/subsys/bluetooth/mesh/net.c +++ b/subsys/bluetooth/mesh/net.c @@ -712,7 +712,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, transmit = bt_mesh_net_transmit_get(); } - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_RELAY_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_RELAY, transmit, K_NO_WAIT); if (!buf) { LOG_DBG("Out of relay buffers"); diff --git a/subsys/bluetooth/mesh/pb_adv.c b/subsys/bluetooth/mesh/pb_adv.c index 27d55763298..cb5f53f32b7 100644 --- a/subsys/bluetooth/mesh/pb_adv.c +++ b/subsys/bluetooth/mesh/pb_adv.c @@ -55,11 +55,11 @@ LOG_MODULE_REGISTER(bt_mesh_pb_adv); /* Acked messages, will do retransmissions manually, taking acks into account: */ -#define RETRANSMITS_RELIABLE 0 +#define RETRANSMITS_RELIABLE CONFIG_BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT /* PDU acks: */ -#define RETRANSMITS_ACK 2 +#define RETRANSMITS_ACK CONFIG_BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT /* Link close retransmits: */ -#define RETRANSMITS_LINK_CLOSE 2 +#define RETRANSMITS_LINK_CLOSE CONFIG_BT_MESH_PB_ADV_LINK_CLOSE_RETRANSMIT_COUNT enum { ADV_LINK_ACTIVE, /* Link has been opened */ @@ -178,8 +178,15 @@ static void free_segments(void) } link.tx.buf[i] = NULL; - /* Mark as canceled */ - BT_MESH_ADV(buf)->busy = 0U; + + /* Terminate active adv */ + if (BT_MESH_ADV(buf)->busy == 0U) { + bt_mesh_adv_buf_terminate(buf); + } else { + /* Mark as canceled */ + BT_MESH_ADV(buf)->busy = 0U; + } + net_buf_unref(buf); } } @@ -251,7 +258,7 @@ static struct net_buf *adv_buf_create(uint8_t retransmits) { struct net_buf *buf; - buf = bt_mesh_adv_create(BT_MESH_ADV_PROV, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_PROV, BT_MESH_ADV_TAG_PROV, BT_MESH_TRANSMIT(retransmits, 20), BUF_TIMEOUT); if (!buf) { diff --git a/subsys/bluetooth/mesh/statistic.c b/subsys/bluetooth/mesh/statistic.c index 046fa3c0eeb..21c451bee73 100644 --- a/subsys/bluetooth/mesh/statistic.c +++ b/subsys/bluetooth/mesh/statistic.c @@ -24,22 +24,22 @@ void bt_mesh_stat_reset(void) void bt_mesh_stat_planned_count(struct bt_mesh_adv *adv) { - if (adv->tag == BT_MESH_LOCAL_ADV) { + if (adv->tag == BT_MESH_ADV_TAG_LOCAL) { stat.tx_local_planned++; - } else if (adv->tag == BT_MESH_RELAY_ADV) { + } else if (adv->tag == BT_MESH_ADV_TAG_RELAY) { stat.tx_adv_relay_planned++; - } else if (adv->tag == BT_MESH_FRIEND_ADV) { + } else if (adv->tag == BT_MESH_ADV_TAG_FRIEND) { stat.tx_friend_planned++; } } void bt_mesh_stat_succeeded_count(struct bt_mesh_adv *adv) { - if (adv->tag == BT_MESH_LOCAL_ADV) { + if (adv->tag == BT_MESH_ADV_TAG_LOCAL) { stat.tx_local_succeeded++; - } else if (adv->tag == BT_MESH_RELAY_ADV) { + } else if (adv->tag == BT_MESH_ADV_TAG_RELAY) { stat.tx_adv_relay_succeeded++; - } else if (adv->tag == BT_MESH_FRIEND_ADV) { + } else if (adv->tag == BT_MESH_ADV_TAG_FRIEND) { stat.tx_friend_succeeded++; } } diff --git a/subsys/bluetooth/mesh/transport.c b/subsys/bluetooth/mesh/transport.c index 0343993e348..f4c49aa6856 100644 --- a/subsys/bluetooth/mesh/transport.c +++ b/subsys/bluetooth/mesh/transport.c @@ -124,7 +124,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, { struct net_buf *buf; - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, tx->xmit, BUF_TIMEOUT); if (!buf) { LOG_ERR("Out of network buffers"); @@ -414,7 +414,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx) continue; } - seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, tx->xmit, BUF_TIMEOUT); if (!seg) { LOG_DBG("Allocating segment failed"); diff --git a/subsys/bluetooth/mesh/transport_legacy.c b/subsys/bluetooth/mesh/transport_legacy.c index 475a0429f75..23e103b4370 100644 --- a/subsys/bluetooth/mesh/transport_legacy.c +++ b/subsys/bluetooth/mesh/transport_legacy.c @@ -131,7 +131,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, { struct net_buf *buf; - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, tx->xmit, BUF_TIMEOUT); if (!buf) { LOG_ERR("Out of network buffers"); @@ -401,7 +401,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx) continue; } - seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, tx->xmit, BUF_TIMEOUT); if (!seg) { LOG_DBG("Allocating segment failed"); diff --git a/tests/bluetooth/mesh/basic/multi_ext_adv.conf b/tests/bluetooth/mesh/basic/multi_ext_adv.conf index 610318f847b..0278bd557bd 100644 --- a/tests/bluetooth/mesh/basic/multi_ext_adv.conf +++ b/tests/bluetooth/mesh/basic/multi_ext_adv.conf @@ -51,5 +51,5 @@ CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y CONFIG_BT_EXT_ADV_MAX_ADV_SET=3 -CONFIG_BT_MESH_RELAY_ADV_SETS=1 +CONFIG_BT_MESH_SIMULT_ADV_SETS=1 CONFIG_BT_MESH_ADV_EXT=y diff --git a/tests/bsim/bluetooth/mesh/src/test_advertiser.c b/tests/bsim/bluetooth/mesh/src/test_advertiser.c index 590eed8eebc..911c5772f8b 100644 --- a/tests/bsim/bluetooth/mesh/src/test_advertiser.c +++ b/tests/bsim/bluetooth/mesh/src/test_advertiser.c @@ -81,7 +81,7 @@ static void adv_init(void) static void allocate_all_array(struct net_buf **buf, size_t num_buf, uint8_t xmit) { for (int i = 0; i < num_buf; i++) { - *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); ASSERT_FALSE(!*buf, "Out of buffers"); @@ -94,7 +94,7 @@ static void verify_adv_queue_overflow(void) struct net_buf *dummy_buf; /* Verity Queue overflow */ - dummy_buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + dummy_buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); ASSERT_TRUE(!dummy_buf, "Unexpected extra buffer"); } @@ -160,7 +160,7 @@ static void realloc_end_cb(int err, void *cb_data) struct net_buf *buf = (struct net_buf *)cb_data; ASSERT_EQUAL(0, err); - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); ASSERT_FALSE(!buf, "Out of buffers"); @@ -425,7 +425,7 @@ static void test_tx_cb_single(void) bt_init(); adv_init(); - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); ASSERT_FALSE(!buf, "Out of buffers"); @@ -530,7 +530,7 @@ static void test_tx_proxy_mixin(void) * Advertising the proxy service should be resumed after * finishing advertising the message. */ - struct net_buf *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + struct net_buf *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(5, 20), K_NO_WAIT); net_buf_add_mem(buf, txt_msg, sizeof(txt_msg)); bt_mesh_adv_send(buf, NULL, NULL); @@ -636,16 +636,16 @@ static void test_tx_random_order(void) /* Verify random order calls */ num_adv_sent = ARRAY_SIZE(buf); previous_checker = 0xff; - buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); - ASSERT_FALSE(!buf[0], "Out of buffers"); - buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + ASSERT_FALSE(!buf[0], "Out of buffers\n"); + buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); ASSERT_FALSE(!buf[1], "Out of buffers"); send_adv_buf(buf[0], 0, 0xff); - buf[2] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf[2] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); ASSERT_FALSE(!buf[2], "Out of buffers"); From d5bb75fa25114593f868352f0b6cfcc5af996a86 Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Thu, 7 Sep 2023 16:04:00 +0800 Subject: [PATCH 0392/1623] [nrf fromlist] Bluetooth: Mesh: Use system workqueue for dhkey gen Since the default process dhkey gen in bt rx, will block send Trans Ack, cause peer device send more package. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/62331 Signed-off-by: Lingao Meng (cherry picked from commit 1b22324317ceafc4fc3d1243eba0be371af22e2d) --- subsys/bluetooth/mesh/Kconfig | 2 +- subsys/bluetooth/mesh/prov_device.c | 9 ++++++++- subsys/bluetooth/mesh/provisioner.c | 11 ++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index a05d3917c1d..cb04b4dedfb 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -210,7 +210,7 @@ config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT config BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT int "Link Ack and Transaction Ack retransmit count" - default 2 + default 0 range 0 7 help Controls the number of retransmissions of original Link Open and Transaction Acknowledgment PDU, diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/prov_device.c index 992bf656202..6e56519eefb 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/prov_device.c @@ -358,6 +358,13 @@ static void prov_dh_key_gen(void) } } +static void prov_dh_key_gen_handler(struct k_work *work) +{ + prov_dh_key_gen(); +} + +static K_WORK_DEFINE(dh_gen_work, prov_dh_key_gen_handler); + static void prov_pub_key(const uint8_t *data) { LOG_DBG("Remote Public Key: %s", bt_hex(data, PUB_KEY_SIZE)); @@ -385,7 +392,7 @@ static void prov_pub_key(const uint8_t *data) PDU_LEN_PUB_KEY); } - prov_dh_key_gen(); + k_work_submit(&dh_gen_work); } static void notify_input_complete(void) diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index 717cdbee610..6bf759272dd 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -20,6 +20,8 @@ #include "common/bt_str.h" +#include "host/long_wq.h" + #include "crypto.h" #include "adv.h" #include "mesh.h" @@ -450,6 +452,13 @@ static void prov_dh_key_gen(void) send_confirm(); } +static void prov_dh_key_gen_handler(struct k_work *work) +{ + prov_dh_key_gen(); +} + +static K_WORK_DEFINE(dh_gen_work, prov_dh_key_gen_handler); + static void prov_pub_key(const uint8_t *data) { LOG_DBG("Remote Public Key: %s", bt_hex(data, PUB_KEY_SIZE)); @@ -460,7 +469,7 @@ static void prov_pub_key(const uint8_t *data) memcpy(bt_mesh_prov_link.conf_inputs.pub_key_device, data, PUB_KEY_SIZE); bt_mesh_prov_link.bearer->clear_tx(); - prov_dh_key_gen(); + k_work_submit(&dh_gen_work); } static void notify_input_complete(void) From 9c6d0f8a0bdca74bee70bea3746db945ac9d314a Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Fri, 8 Sep 2023 13:56:10 +0800 Subject: [PATCH 0393/1623] [nrf fromlist] Bluetooth: Mesh: Move ext adv sector to vector Obviously, it looks obscure by putting it in a sector, so, let's move to vector. refs: https://github.com/zephyrproject-rtos/zephyr/pull/57883 Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/62331 Signed-off-by: Lingao Meng (cherry picked from commit c2b2641fc18233df68e7cec3f0665aa1dbf29f5f) --- cmake/linker_script/common/common-ram.cmake | 3 - include/zephyr/linker/common-ram.ld | 4 - subsys/bluetooth/mesh/Kconfig | 38 +++-- subsys/bluetooth/mesh/adv.c | 41 ++--- subsys/bluetooth/mesh/adv.h | 18 +-- subsys/bluetooth/mesh/adv_ext.c | 151 +++++++++--------- subsys/bluetooth/mesh/adv_legacy.c | 5 +- subsys/bluetooth/mesh/provisioner.c | 2 - tests/bluetooth/mesh/basic/multi_ext_adv.conf | 2 +- .../bsim/bluetooth/mesh/src/test_advertiser.c | 2 +- 10 files changed, 129 insertions(+), 137 deletions(-) diff --git a/cmake/linker_script/common/common-ram.cmake b/cmake/linker_script/common/common-ram.cmake index e6ef59eaf29..9c051477d10 100644 --- a/cmake/linker_script/common/common-ram.cmake +++ b/cmake/linker_script/common/common-ram.cmake @@ -111,9 +111,6 @@ if(CONFIG_UVB) zephyr_iterable_section(NAME uvb_node GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) endif() -if(CONFIG_BT_MESH_ADV_EXT) - zephyr_iterable_section(NAME bt_mesh_ext_adv GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) -endif() if(CONFIG_LOG) zephyr_iterable_section(NAME log_mpsc_pbuf GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) diff --git a/include/zephyr/linker/common-ram.ld b/include/zephyr/linker/common-ram.ld index bfaa26ed400..8ae67c73257 100644 --- a/include/zephyr/linker/common-ram.ld +++ b/include/zephyr/linker/common-ram.ld @@ -12,10 +12,6 @@ #endif #endif /* NETWORKING */ -#if defined(CONFIG_BT_MESH) - ITERABLE_SECTION_RAM(bt_mesh_ext_adv, 4) -#endif - #if defined(CONFIG_GEN_SW_ISR_TABLE) && defined(CONFIG_DYNAMIC_INTERRUPTS) SECTION_DATA_PROLOGUE(sw_isr_table,,) { diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index cb04b4dedfb..63749a69d56 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -103,22 +103,22 @@ menuconfig BT_MESH_ADV_EXT if BT_MESH_ADV_EXT -config BT_MESH_SIMULT_ADV_SETS - int "Maximum number of parallel advertising sets that can be used by the Bluetooth Mesh stack" +config BT_MESH_RELAY_ADV_SETS + int "Maximum of simultaneous relay message support" default 0 range 0 BT_EXT_ADV_MAX_ADV_SET - depends on BT_MESH_RELAY || BT_MESH_PB_ADV + depends on BT_MESH_RELAY help - Maximum of simultaneous message support. Requires controller support + Maximum of simultaneous relay message support. Requires controller support multiple advertising sets. config BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET bool "Use the main advertising set to relay messages" - depends on BT_MESH_SIMULT_ADV_SETS > 0 + depends on BT_MESH_RELAY_ADV_SETS > 0 help When this option is enabled, there is a message that needs to be relayed, all relay advertising sets defined by - CONFIG_BT_MESH_SIMULT_ADV_SETS are busy with relaying messages + CONFIG_BT_MESH_RELAY_ADV_SETS are busy with relaying messages and the main advertising set is not busy with sending local messages, the stack will use the main advertising set to relay the message. This maximizes the utilization efficiency of @@ -192,16 +192,15 @@ config BT_MESH_UNPROV_BEACON_INT if BT_MESH_PB_ADV -config BT_MESH_PB_ADV_RETRANS_TIMEOUT - int "Timeout value of retransmit provisioning PDUs" - default 500 - range 100 800 +config BT_MESH_PB_ADV_USE_RELAY_SETS + bool "Use relay advertising sets to send provisioning PDUs" + depends on BT_MESH_RELAY_ADV_SETS > 0 help - Timeout value of retransmit provisioning PDUs. + Use relay advertising sets to send provisioning PDUs config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT int "Link Open and Transaction PDU retransmit count" - default 7 if BT_MESH_SIMULT_ADV_SETS > 0 + default 7 if BT_MESH_PB_ADV_USE_RELAY_SETS default 0 range 0 7 help @@ -210,21 +209,28 @@ config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT config BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT int "Link Ack and Transaction Ack retransmit count" - default 0 + default 2 range 0 7 help - Controls the number of retransmissions of original Link Open and Transaction Acknowledgment PDU, + Controls the number of retransmissions of original Link Ack and Transaction Acknowledgment PDU, in addition to the first transmission. config BT_MESH_PB_ADV_LINK_CLOSE_RETRANSMIT_COUNT int "Link Close retransmit count" - default 7 if BT_MESH_SIMULT_ADV_SETS > 0 + default 7 if BT_MESH_PB_ADV_USE_RELAY_SETS default 2 range 0 7 help Controls the number of retransmissions of original Link Close, in addition to the first transmission. +config BT_MESH_PB_ADV_RETRANS_TIMEOUT + int "Timeout value of retransmit provisioning PDUs" + default 500 + range 100 800 + help + Timeout value of retransmit provisioning PDUs. + endif # BT_MESH_PB_ADV if BT_CONN @@ -401,7 +407,7 @@ config BT_MESH_RELAY_BUF_COUNT of packet drops. When considering the message latency, also consider the values of BT_MESH_RELAY_RETRANSMIT_COUNT and BT_MESH_RELAY_RETRANSMIT_INTERVAL. A higher number of - BT_MESH_SIMULT_ADV_SETS allows the increase in the number of buffers + BT_MESH_RELAY_ADV_SETS allows the increase in the number of buffers while maintaining the latency. endif # BT_MESH_RELAY diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index c7abcd53d70..b24523aacf3 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -44,7 +44,7 @@ const uint8_t bt_mesh_adv_type[BT_MESH_ADV_TYPES] = { static bool active_scanning; static K_FIFO_DEFINE(bt_mesh_adv_queue); -static K_FIFO_DEFINE(bt_mesh_simult_queue); +static K_FIFO_DEFINE(bt_mesh_relay_queue); static K_FIFO_DEFINE(bt_mesh_friend_queue); void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv *adv) @@ -157,7 +157,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, tag, xmit, timeout); } -#if CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE +#if CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE static struct net_buf *process_events(struct k_poll_event *ev, int count) { for (; count; ev++, count--) { @@ -189,7 +189,7 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, K_POLL_MODE_NOTIFY_ONLY, - &bt_mesh_simult_queue, + &bt_mesh_relay_queue, 0), #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ }; @@ -202,34 +202,34 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) return process_events(events, ARRAY_SIZE(events)); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout) { if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - tags & BT_MESH_ADV_TAG_FRIEND_BIT) { + tags & BT_MESH_ADV_TAG_BIT_FRIEND) { return net_buf_get(&bt_mesh_friend_queue, timeout); } - if (tags & BT_MESH_ADV_TAG_LOCAL_BIT) { - return bt_mesh_adv_buf_get(timeout); +#if CONFIG_BT_MESH_RELAY_ADV_SETS + if (!(tags & BT_MESH_ADV_TAG_BIT_LOCAL)) { + return net_buf_get(&bt_mesh_relay_queue, timeout); } - -#if CONFIG_BT_MESH_SIMULT_ADV_SETS - return net_buf_get(&bt_mesh_simult_queue, timeout); #endif + + return bt_mesh_adv_buf_get(timeout); } -#else /* !(CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) */ +#else /* !(CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) */ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) { return net_buf_get(&bt_mesh_adv_queue, timeout); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout) { ARG_UNUSED(tags); return bt_mesh_adv_buf_get(timeout); } -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ +#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ void bt_mesh_adv_buf_get_cancel(void) { @@ -237,9 +237,9 @@ void bt_mesh_adv_buf_get_cancel(void) k_fifo_cancel_wait(&bt_mesh_adv_queue); -#if CONFIG_BT_MESH_SIMULT_ADV_SETS - k_fifo_cancel_wait(&bt_mesh_simult_queue); -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ +#if CONFIG_BT_MESH_RELAY_ADV_SETS + k_fifo_cancel_wait(&bt_mesh_relay_queue); +#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { k_fifo_cancel_wait(&bt_mesh_friend_queue); @@ -267,11 +267,12 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, return; } -#if CONFIG_BT_MESH_SIMULT_ADV_SETS +#if CONFIG_BT_MESH_RELAY_ADV_SETS if (BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_RELAY || - BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV) { - net_buf_put(&bt_mesh_simult_queue, net_buf_ref(buf)); - bt_mesh_adv_buf_simult_ready(); + (IS_ENABLED(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS) && + BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV)) { + net_buf_put(&bt_mesh_relay_queue, net_buf_ref(buf)); + bt_mesh_adv_buf_relay_ready(); return; } #endif diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index 50c5b47604c..a80ff7e8d4b 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -33,12 +33,12 @@ enum bt_mesh_adv_tag { BT_MESH_ADV_TAG_PROV, }; -enum bt_mesh_adv_tags { - BT_MESH_ADV_TAG_LOCAL_BIT = BIT(BT_MESH_ADV_TAG_LOCAL), - BT_MESH_ADV_TAG_RELAY_BIT = BIT(BT_MESH_ADV_TAG_RELAY), - BT_MESH_ADV_TAG_PROXY_BIT = BIT(BT_MESH_ADV_TAG_PROXY), - BT_MESH_ADV_TAG_FRIEND_BIT = BIT(BT_MESH_ADV_TAG_FRIEND), - BT_MESH_ADV_TAG_PROV_BIT = BIT(BT_MESH_ADV_TAG_PROV), +enum bt_mesh_adv_tag_bit { + BT_MESH_ADV_TAG_BIT_LOCAL = BIT(BT_MESH_ADV_TAG_LOCAL), + BT_MESH_ADV_TAG_BIT_RELAY = BIT(BT_MESH_ADV_TAG_RELAY), + BT_MESH_ADV_TAG_BIT_PROXY = BIT(BT_MESH_ADV_TAG_PROXY), + BT_MESH_ADV_TAG_BIT_FRIEND = BIT(BT_MESH_ADV_TAG_FRIEND), + BT_MESH_ADV_TAG_BIT_PROV = BIT(BT_MESH_ADV_TAG_PROV), }; struct bt_mesh_adv { @@ -66,7 +66,7 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout); -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout); +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout); void bt_mesh_adv_gatt_update(void); @@ -82,9 +82,9 @@ int bt_mesh_adv_enable(void); void bt_mesh_adv_buf_local_ready(void); -void bt_mesh_adv_buf_simult_ready(void); +void bt_mesh_adv_buf_relay_ready(void); -void bt_mesh_adv_buf_terminate(struct net_buf *buf); +void bt_mesh_adv_buf_terminate(const struct net_buf *buf); void bt_mesh_adv_buf_friend_ready(void); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 2065de372a4..525e5ee5066 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -33,8 +33,8 @@ LOG_MODULE_REGISTER(bt_mesh_adv_ext); /* Convert from ms to 0.625ms units */ #define ADV_INT_FAST_MS 20 -#ifndef CONFIG_BT_MESH_SIMULT_ADV_SETS -#define CONFIG_BT_MESH_SIMULT_ADV_SETS 0 +#ifndef CONFIG_BT_MESH_RELAY_ADV_SETS +#define CONFIG_BT_MESH_RELAY_ADV_SETS 0 #endif enum { @@ -60,7 +60,7 @@ enum { }; struct bt_mesh_ext_adv { - enum bt_mesh_adv_tags tags; + const enum bt_mesh_adv_tag_bit tags; ATOMIC_DEFINE(flags, ADV_FLAGS_NUM); struct bt_le_ext_adv *instance; struct net_buf *buf; @@ -72,80 +72,71 @@ struct bt_mesh_ext_adv { static void send_pending_adv(struct k_work *work); static bool schedule_send(struct bt_mesh_ext_adv *adv); -static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { - .tags = ( +static struct bt_mesh_ext_adv advs[] = { + [0] = { + .tags = ( #if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - BT_MESH_ADV_TAG_FRIEND_BIT | + BT_MESH_ADV_TAG_BIT_FRIEND | #endif #if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - BT_MESH_ADV_TAG_PROXY_BIT | + BT_MESH_ADV_TAG_BIT_PROXY | #endif /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) - BT_MESH_ADV_TAG_RELAY_BIT | + BT_MESH_ADV_TAG_BIT_RELAY | #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ - BT_MESH_ADV_TAG_LOCAL_BIT), - - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), -}; - -#if CONFIG_BT_MESH_SIMULT_ADV_SETS -static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_SIMULT_ADV_SETS) = { - [0 ... CONFIG_BT_MESH_SIMULT_ADV_SETS - 1] = { +#if defined(CONFIG_BT_MESH_PB_ADV) + BT_MESH_ADV_TAG_BIT_PROV | +#endif /* CONFIG_BT_MESH_PB_ADV */ + BT_MESH_ADV_TAG_BIT_LOCAL + ), + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), + }, +#if CONFIG_BT_MESH_RELAY_ADV_SETS + [1 ... CONFIG_BT_MESH_RELAY_ADV_SETS] = { .tags = ( #if defined(CONFIG_BT_MESH_RELAY) - BT_MESH_ADV_TAG_RELAY_BIT | + BT_MESH_ADV_TAG_BIT_RELAY | #endif /* CONFIG_BT_MESH_RELAY */ -#if defined(CONFIG_BT_MESH_PB_ADV) - BT_MESH_ADV_TAG_PROV_BIT | -#endif /* CONFIG_BT_MESH_PB_ADV */ +#if defined(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS) + BT_MESH_ADV_TAG_BIT_PROV | +#endif /* CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS */ 0), - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), - } -}; -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ - + }, +#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) -#define ADV_EXT_FRIEND 1 -static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { - .tags = BT_MESH_ADV_TAG_FRIEND_BIT, - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), -}; -#else /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ -#define ADV_EXT_FRIEND 0 + { + .tags = BT_MESH_ADV_TAG_BIT_FRIEND, + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), + }, #endif /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ - #if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) -#define ADV_EXT_GATT 1 -static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_gatt) = { - .tags = BT_MESH_ADV_TAG_PROXY_BIT, - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), -}; -#else /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ -#define ADV_EXT_GATT 0 + { + .tags = BT_MESH_ADV_TAG_BIT_PROXY, + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), + }, #endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ +}; -#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_SIMULT_ADV_SETS + ADV_EXT_FRIEND + ADV_EXT_GATT) - -BUILD_ASSERT(CONFIG_BT_EXT_ADV_MAX_ADV_SET >= BT_MESH_ADV_COUNT, +BUILD_ASSERT(ARRAY_SIZE(advs) <= CONFIG_BT_EXT_ADV_MAX_ADV_SET, "Insufficient adv instances"); static inline struct bt_mesh_ext_adv *relay_adv_get(void) { -#if CONFIG_BT_MESH_SIMULT_ADV_SETS - return adv_relay; -#else /* !CONFIG_BT_MESH_SIMULT_ADV_SETS */ - return &adv_main; -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ + if (!!(CONFIG_BT_MESH_RELAY_ADV_SETS)) { + return &advs[1]; + } else { + return &advs[0]; + } } static inline struct bt_mesh_ext_adv *gatt_adv_get(void) { -#if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - return &adv_gatt; -#else /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ - return &adv_main; -#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ + if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)) { + return &advs[ARRAY_SIZE(advs) - 1]; + } else { + return &advs[0]; + } } static int set_adv_randomness(uint8_t handle, int rand_us) @@ -328,7 +319,7 @@ static void send_pending_adv(struct k_work *work) } if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || - !(adv->tags & BT_MESH_ADV_TAG_PROXY_BIT)) { + !(adv->tags & BT_MESH_ADV_TAG_BIT_PROXY)) { return; } @@ -372,8 +363,8 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - adv->tags & BT_MESH_ADV_TAG_FRIEND_BIT) || - (CONFIG_BT_MESH_SIMULT_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_RELAY_BIT)) { + adv->tags & BT_MESH_ADV_TAG_BIT_FRIEND) || + (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_BIT_RELAY)) { k_work_reschedule(&adv->work, K_NO_WAIT); } else { /* The controller will send the next advertisement immediately. @@ -394,14 +385,14 @@ void bt_mesh_adv_gatt_update(void) void bt_mesh_adv_buf_local_ready(void) { - (void)schedule_send(&adv_main); + (void)schedule_send(advs); } -void bt_mesh_adv_buf_simult_ready(void) +void bt_mesh_adv_buf_relay_ready(void) { struct bt_mesh_ext_adv *adv = relay_adv_get(); - for (int i = 0; i < CONFIG_BT_MESH_SIMULT_ADV_SETS; i++) { + for (int i = 0; i < CONFIG_BT_MESH_RELAY_ADV_SETS; i++) { if (schedule_send(&adv[i])) { return; } @@ -409,22 +400,26 @@ void bt_mesh_adv_buf_simult_ready(void) /* Attempt to use the main adv set for the sending of relay messages. */ if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET)) { - (void)schedule_send(&adv_main); + (void)schedule_send(advs); } } void bt_mesh_adv_buf_friend_ready(void) { -#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - (void)schedule_send(&adv_friend); -#endif + if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { + schedule_send(&advs[1 + CONFIG_BT_MESH_RELAY_ADV_SETS]); + } else { + schedule_send(&advs[0]); + } } -void bt_mesh_adv_buf_terminate(struct net_buf *buf) +void bt_mesh_adv_buf_terminate(const struct net_buf *buf) { int err; - STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { + for (int i = 0; i < ARRAY_SIZE(advs); i++) { + struct bt_mesh_ext_adv *adv = &advs[i]; + if (adv->buf != buf) { continue; } @@ -446,7 +441,7 @@ void bt_mesh_adv_buf_terminate(struct net_buf *buf) k_work_submit(&adv->work.work); - break; + return; } } @@ -459,17 +454,18 @@ void bt_mesh_adv_init(void) #if defined(CONFIG_BT_MESH_DEBUG_USE_ID_ADDR) .options = BT_LE_ADV_OPT_USE_IDENTITY, #endif -}; - STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { - (void)memcpy(&adv->adv_param, &adv_param, sizeof(adv_param)); + }; + + for (int i = 0; i < ARRAY_SIZE(advs); i++) { + (void)memcpy(&advs[i].adv_param, &adv_param, sizeof(adv_param)); } } static struct bt_mesh_ext_adv *adv_instance_find(struct bt_le_ext_adv *instance) { - STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { - if (adv->instance == instance) { - return adv; + for (int i = 0; i < ARRAY_SIZE(advs); i++) { + if (advs[i].instance == instance) { + return &advs[i]; } } @@ -519,15 +515,14 @@ int bt_mesh_adv_enable(void) #endif /* CONFIG_BT_MESH_GATT_SERVER */ }; - if (adv_main.instance) { + if (advs[0].instance) { /* Already initialized */ return 0; } - - STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { - err = bt_le_ext_adv_create(&adv->adv_param, &adv_cb, - &adv->instance); + for (int i = 0; i < ARRAY_SIZE(advs); i++) { + err = bt_le_ext_adv_create(&advs[i].adv_param, &adv_cb, + &advs[i].instance); if (err) { return err; } @@ -566,5 +561,5 @@ int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, int bt_mesh_adv_bt_data_send(uint8_t num_events, uint16_t adv_interval, const struct bt_data *ad, size_t ad_len) { - return bt_data_send(&adv_main, num_events, adv_interval, ad, ad_len); + return bt_data_send(advs, num_events, adv_interval, ad, ad_len); } diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index cb4028662f9..a7d7dd1a320 100644 --- a/subsys/bluetooth/mesh/adv_legacy.c +++ b/subsys/bluetooth/mesh/adv_legacy.c @@ -195,7 +195,7 @@ void bt_mesh_adv_buf_local_ready(void) /* Will be handled automatically */ } -void bt_mesh_adv_buf_simult_ready(void) +void bt_mesh_adv_buf_relay_ready(void) { /* Will be handled automatically */ } @@ -205,9 +205,8 @@ void bt_mesh_adv_gatt_update(void) bt_mesh_adv_buf_get_cancel(); } -void bt_mesh_adv_buf_terminate(struct net_buf *buf) +void bt_mesh_adv_buf_terminate(const struct net_buf *buf) { - /* todo */ ARG_UNUSED(buf); } diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index 6bf759272dd..a65bd25ab53 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -20,8 +20,6 @@ #include "common/bt_str.h" -#include "host/long_wq.h" - #include "crypto.h" #include "adv.h" #include "mesh.h" diff --git a/tests/bluetooth/mesh/basic/multi_ext_adv.conf b/tests/bluetooth/mesh/basic/multi_ext_adv.conf index 0278bd557bd..610318f847b 100644 --- a/tests/bluetooth/mesh/basic/multi_ext_adv.conf +++ b/tests/bluetooth/mesh/basic/multi_ext_adv.conf @@ -51,5 +51,5 @@ CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y CONFIG_BT_EXT_ADV_MAX_ADV_SET=3 -CONFIG_BT_MESH_SIMULT_ADV_SETS=1 +CONFIG_BT_MESH_RELAY_ADV_SETS=1 CONFIG_BT_MESH_ADV_EXT=y diff --git a/tests/bsim/bluetooth/mesh/src/test_advertiser.c b/tests/bsim/bluetooth/mesh/src/test_advertiser.c index 911c5772f8b..6a171b499bf 100644 --- a/tests/bsim/bluetooth/mesh/src/test_advertiser.c +++ b/tests/bsim/bluetooth/mesh/src/test_advertiser.c @@ -638,7 +638,7 @@ static void test_tx_random_order(void) previous_checker = 0xff; buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); - ASSERT_FALSE(!buf[0], "Out of buffers\n"); + ASSERT_FALSE_MSG(!buf[0], "Out of buffers\n"); buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); ASSERT_FALSE(!buf[1], "Out of buffers"); From 6dde66941e658d5a73420e49ac96113c457ce072 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 17 Oct 2023 14:07:52 +0200 Subject: [PATCH 0394/1623] [nrf fromlist] bsim: bluetooth: mesh: Increase Net Transmit Count value on the node This is to increase probability of reception of responses (Config Status messages) from the node when the provisioner sends a Set message and the node response with a Status message at the same time so that the message collide. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/62331 Signed-off-by: Pavel Vasilyev (cherry picked from commit 7c7ea3847196c57dab9f85ed196cf02dad0c3747) --- tests/bsim/bluetooth/mesh/src/test_persistence.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/bsim/bluetooth/mesh/src/test_persistence.c b/tests/bsim/bluetooth/mesh/src/test_persistence.c index 6c510922330..90bf41f73a6 100644 --- a/tests/bsim/bluetooth/mesh/src/test_persistence.c +++ b/tests/bsim/bluetooth/mesh/src/test_persistence.c @@ -520,6 +520,17 @@ static void node_configure(void) uint16_t va; struct bt_mesh_cfg_cli_mod_pub pub_params; + /* Set Network Transmit Count state on the device greater than on provisioner to increase + * probability of reception responses. + */ + uint8_t net_transmit; + + net_transmit = BT_MESH_TRANSMIT(3, 20); + err = bt_mesh_cfg_cli_net_transmit_set(test_netkey_idx, TEST_ADDR, net_transmit, &status); + if (err || status != net_transmit) { + FAIL("Net transmit set failed (err %d, transmit %x)", err, status); + } + struct test_appkey_t test_appkeys[] = { { .idx = TEST_APPKEY_0_IDX, .key = TEST_APPKEY_0_KEY }, { .idx = TEST_APPKEY_1_IDX, .key = TEST_APPKEY_1_KEY }, From d466b521fbbdf602a32d92c8ff9f9371e624fa51 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Wed, 1 Nov 2023 15:44:23 +0100 Subject: [PATCH 0395/1623] [nrf fromlist] Bluetooth: Mesh: no more tinycrypt in ble mesh tfm image PR allows to get rid of tinycrypt objects from the final binary of the ble mesh apps based on PSA TFM crypto. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/64696 Signed-off-by: Aleksandr Khromykh (cherry picked from commit c5ee143d773e713901896319a4d116082ca0771d) --- .../boards/nrf5340dk_nrf5340_cpuapp_ns.conf | 5 +++ .../boards/nrf5340dk_nrf5340_cpuapp_ns.conf | 5 +++ .../boards/nrf5340dk_nrf5340_cpuapp_ns.conf | 3 ++ subsys/bluetooth/host/Kconfig | 7 ++-- subsys/bluetooth/mesh/crypto_psa.c | 10 ++++++ tests/bsim/bluetooth/mesh/overlay_psa.conf | 5 +++ tests/bsim/bluetooth/mesh/src/test_dfu.c | 35 ++++++++++--------- .../bluetooth/mesh/src/test_persistence.c | 2 +- .../bluetooth/mesh/src/test_replay_cache.c | 8 +++++ 9 files changed, 59 insertions(+), 21 deletions(-) diff --git a/samples/bluetooth/mesh/boards/nrf5340dk_nrf5340_cpuapp_ns.conf b/samples/bluetooth/mesh/boards/nrf5340dk_nrf5340_cpuapp_ns.conf index c638a292c91..4693e4d1f78 100644 --- a/samples/bluetooth/mesh/boards/nrf5340dk_nrf5340_cpuapp_ns.conf +++ b/samples/bluetooth/mesh/boards/nrf5340dk_nrf5340_cpuapp_ns.conf @@ -1,3 +1,8 @@ +# The option adds TinyCrypt based bt_rand. +CONFIG_BT_HOST_CRYPTO=n +# The option adds GATT caching feature that is based on TinyCrypt. +CONFIG_BT_GATT_CACHING=n + # Known issue: non secure platforms do not work with settings subsystem. CONFIG_SETTINGS=n CONFIG_BT_SETTINGS=n diff --git a/samples/bluetooth/mesh_demo/boards/nrf5340dk_nrf5340_cpuapp_ns.conf b/samples/bluetooth/mesh_demo/boards/nrf5340dk_nrf5340_cpuapp_ns.conf index c638a292c91..4693e4d1f78 100644 --- a/samples/bluetooth/mesh_demo/boards/nrf5340dk_nrf5340_cpuapp_ns.conf +++ b/samples/bluetooth/mesh_demo/boards/nrf5340dk_nrf5340_cpuapp_ns.conf @@ -1,3 +1,8 @@ +# The option adds TinyCrypt based bt_rand. +CONFIG_BT_HOST_CRYPTO=n +# The option adds GATT caching feature that is based on TinyCrypt. +CONFIG_BT_GATT_CACHING=n + # Known issue: non secure platforms do not work with settings subsystem. CONFIG_SETTINGS=n CONFIG_BT_SETTINGS=n diff --git a/samples/bluetooth/mesh_provisioner/boards/nrf5340dk_nrf5340_cpuapp_ns.conf b/samples/bluetooth/mesh_provisioner/boards/nrf5340dk_nrf5340_cpuapp_ns.conf index c638a292c91..c3d134592fc 100644 --- a/samples/bluetooth/mesh_provisioner/boards/nrf5340dk_nrf5340_cpuapp_ns.conf +++ b/samples/bluetooth/mesh_provisioner/boards/nrf5340dk_nrf5340_cpuapp_ns.conf @@ -1,3 +1,6 @@ +# The option adds TinyCrypt based bt_rand. +CONFIG_BT_HOST_CRYPTO=n + # Known issue: non secure platforms do not work with settings subsystem. CONFIG_SETTINGS=n CONFIG_BT_SETTINGS=n diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index a4cf2e0959b..2e740686b69 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -163,12 +163,13 @@ rsource "../mesh/Kconfig" rsource "../audio/Kconfig" config BT_HOST_CRYPTO - # Hidden option that compiles in AES encryption support using TinyCrypt - # library if this is not provided by the controller implementation. - bool + bool "Use crypto functionality implemented in the Bluetooth host" default y if !BT_CTLR_CRYPTO select TINYCRYPT select TINYCRYPT_AES + help + The option adds the AES encryption support using TinyCrypt + library if this is not provided by the controller implementation. config BT_HOST_CRYPTO_PRNG bool "Use Tinycrypt library for random number generation" diff --git a/subsys/bluetooth/mesh/crypto_psa.c b/subsys/bluetooth/mesh/crypto_psa.c index 450cde679a8..587c367a6bd 100644 --- a/subsys/bluetooth/mesh/crypto_psa.c +++ b/subsys/bluetooth/mesh/crypto_psa.c @@ -7,6 +7,7 @@ #include #include +#include #define LOG_LEVEL CONFIG_BT_MESH_CRYPTO_LOG_LEVEL #include @@ -510,3 +511,12 @@ int bt_mesh_key_compare(const uint8_t raw_key[16], const struct bt_mesh_key *key return memcmp(out, raw_key, 16); } + +__weak int bt_rand(void *buf, size_t len) +{ + CHECKIF(buf == NULL || len == 0) { + return -EINVAL; + } + + return psa_generate_random(buf, len) == PSA_SUCCESS ? 0 : -EIO; +} diff --git a/tests/bsim/bluetooth/mesh/overlay_psa.conf b/tests/bsim/bluetooth/mesh/overlay_psa.conf index ba81c1e0213..1957085b7e4 100644 --- a/tests/bsim/bluetooth/mesh/overlay_psa.conf +++ b/tests/bsim/bluetooth/mesh/overlay_psa.conf @@ -1,2 +1,7 @@ +# The option adds TinyCrypt based bt_rand. +CONFIG_BT_HOST_CRYPTO=n +# The option adds GATT caching feature that is based on TinyCrypt. +CONFIG_BT_GATT_CACHING=n + # Enable mbedTLS PSA as a crypto backend CONFIG_BT_MESH_USES_MBEDTLS_PSA=y diff --git a/tests/bsim/bluetooth/mesh/src/test_dfu.c b/tests/bsim/bluetooth/mesh/src/test_dfu.c index a235e86eeec..46ad4cecb41 100644 --- a/tests/bsim/bluetooth/mesh/src/test_dfu.c +++ b/tests/bsim/bluetooth/mesh/src/test_dfu.c @@ -23,6 +23,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); #define TARGET_ADDR 0x0100 #define IMPOSTER_MODEL_ID 0xe000 #define TEST_BLOB_ID 0xaabbccdd +#define SEMAPHORE_TIMEOUT 250 /* seconds */ struct bind_params { uint16_t model_id; @@ -1016,7 +1017,7 @@ static void test_cli_fail_on_persistency(void) FAIL("DFU Client send failed (err: %d)", err); } - if (k_sem_take(&dfu_ended, K_SECONDS(200))) { + if (k_sem_take(&dfu_ended, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Firmware transfer failed"); } @@ -1050,7 +1051,7 @@ static void test_cli_fail_on_persistency(void) FAIL("DFU Client apply failed (err: %d)", err); } - if (k_sem_take(&dfu_cli_applied_sem, K_SECONDS(200))) { + if (k_sem_take(&dfu_cli_applied_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Failed to apply firmware"); } @@ -1063,7 +1064,7 @@ static void test_cli_fail_on_persistency(void) FAIL("DFU Client confirm failed (err: %d)", err); } - if (k_sem_take(&dfu_cli_confirmed_sem, K_SECONDS(200))) { + if (k_sem_take(&dfu_cli_confirmed_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Failed to confirm firmware"); } @@ -1096,7 +1097,7 @@ static void test_cli_all_targets_lost_common(void) FAIL("DFU Client send failed (err: %d)", err); } - if (k_sem_take(&dfu_ended, K_SECONDS(200))) { + if (k_sem_take(&dfu_ended, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Firmware transfer failed"); } } @@ -1187,7 +1188,7 @@ static void test_cli_all_targets_lost_on_apply(void) FAIL("DFU Client apply failed (err: %d)", err); } - if (!k_sem_take(&dfu_cli_applied_sem, K_SECONDS(200))) { + if (!k_sem_take(&dfu_cli_applied_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Apply should not be successful on any target"); } @@ -1218,7 +1219,7 @@ static void test_cli_stop(void) FAIL("DFU Client send failed (err: %d)", err); } - if (k_sem_take(&dfu_started, K_SECONDS(200))) { + if (k_sem_take(&dfu_started, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Firmware transfer failed"); } @@ -1234,7 +1235,7 @@ static void test_cli_stop(void) FAIL("DFU Client resume failed (err: %d)", err); } - if (k_sem_take(&dfu_verifying, K_SECONDS(200))) { + if (k_sem_take(&dfu_verifying, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Firmware transfer failed"); } ASSERT_EQUAL(BT_MESH_DFU_ERR_INTERNAL, dfu_cli_xfer.targets[0].status); @@ -1253,7 +1254,7 @@ static void test_cli_stop(void) FAIL("DFU Client send failed (err: %d)", err); } - if (k_sem_take(&dfu_verify_failed, K_SECONDS(200))) { + if (k_sem_take(&dfu_verify_failed, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Firmware transfer failed"); } @@ -1269,12 +1270,12 @@ static void test_cli_stop(void) if (err) { FAIL("DFU Client send failed (err: %d)", err); } - if (k_sem_take(&dfu_ended, K_SECONDS(200))) { + if (k_sem_take(&dfu_ended, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Firmware transfer failed"); } bt_mesh_dfu_cli_apply(&dfu_cli); - if (k_sem_take(&dfu_cli_applied_sem, K_SECONDS(200))) { + if (k_sem_take(&dfu_cli_applied_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { /* This will time out as target will reboot before applying */ } ASSERT_EQUAL(BT_MESH_DFU_ERR_INTERNAL, dfu_cli_xfer.targets[0].status); @@ -1464,7 +1465,7 @@ static void test_target_fail_on_metadata(void) common_fail_on_target_init(&target_comp); target_prov_and_conf_default(); - if (k_sem_take(&dfu_metadata_check_sem, K_SECONDS(200))) { + if (k_sem_take(&dfu_metadata_check_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Metadata check CB wasn't called"); } @@ -1478,7 +1479,7 @@ static void test_target_fail_on_caps_get(void) common_fail_on_target_init(&srv_caps_broken_comp); target_prov_and_conf_with_imposer(); - if (k_sem_take(&caps_get_sem, K_SECONDS(200))) { + if (k_sem_take(&caps_get_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("BLOB Info Get msg handler wasn't called"); } @@ -1492,11 +1493,11 @@ static void test_target_fail_on_update_get(void) common_fail_on_target_init(&srv_update_get_broken_comp); target_prov_and_conf_with_imposer(); - if (k_sem_take(&dfu_verify_sem, K_SECONDS(200))) { + if (k_sem_take(&dfu_verify_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Transfer end CB wasn't triggered"); } - if (k_sem_take(&update_get_sem, K_SECONDS(200))) { + if (k_sem_take(&update_get_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Firmware Update Get msg handler wasn't called"); } @@ -1511,7 +1512,7 @@ static void test_target_fail_on_verify(void) common_fail_on_target_init(&target_comp); target_prov_and_conf_default(); - if (k_sem_take(&dfu_verify_sem, K_SECONDS(200))) { + if (k_sem_take(&dfu_verify_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Transfer end CB wasn't triggered"); } @@ -1525,7 +1526,7 @@ static void test_target_fail_on_apply(void) common_fail_on_target_init(&srv_update_apply_broken_comp); target_prov_and_conf_with_imposer(); - if (k_sem_take(&update_apply_sem, K_SECONDS(200))) { + if (k_sem_take(&update_apply_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("Firmware Update Apply msg handler wasn't called"); } @@ -1537,7 +1538,7 @@ static void test_target_fail_on_nothing(void) common_fail_on_target_init(&target_comp); target_prov_and_conf_default(); - if (k_sem_take(&dfu_ended, K_SECONDS(200))) { + if (k_sem_take(&dfu_ended, K_SECONDS(SEMAPHORE_TIMEOUT))) { FAIL("DFU failed"); } diff --git a/tests/bsim/bluetooth/mesh/src/test_persistence.c b/tests/bsim/bluetooth/mesh/src/test_persistence.c index 90bf41f73a6..aab9c6dd185 100644 --- a/tests/bsim/bluetooth/mesh/src/test_persistence.c +++ b/tests/bsim/bluetooth/mesh/src/test_persistence.c @@ -525,7 +525,7 @@ static void node_configure(void) */ uint8_t net_transmit; - net_transmit = BT_MESH_TRANSMIT(3, 20); + net_transmit = BT_MESH_TRANSMIT(3, 50); err = bt_mesh_cfg_cli_net_transmit_set(test_netkey_idx, TEST_ADDR, net_transmit, &status); if (err || status != net_transmit) { FAIL("Net transmit set failed (err %d, transmit %x)", err, status); diff --git a/tests/bsim/bluetooth/mesh/src/test_replay_cache.c b/tests/bsim/bluetooth/mesh/src/test_replay_cache.c index dbab05661cb..d7c140ab3ed 100644 --- a/tests/bsim/bluetooth/mesh/src/test_replay_cache.c +++ b/tests/bsim/bluetooth/mesh/src/test_replay_cache.c @@ -149,6 +149,8 @@ static void test_tx_immediate_replay_attack(void) } ASSERT_TRUE(is_tx_succeeded); + /* Let complete advertising of the previous transaction to prevent collisions. */ + k_sleep(K_SECONDS(1)); } bt_mesh.seq = seq; @@ -165,6 +167,8 @@ static void test_tx_immediate_replay_attack(void) } ASSERT_TRUE(!is_tx_succeeded); + /* Let complete advertising of the previous transaction to prevent collisions. */ + k_sleep(K_SECONDS(1)); } PASS(); @@ -208,6 +212,8 @@ static void test_tx_power_replay_attack(void) } ASSERT_TRUE(!is_tx_succeeded); + /* Let complete advertising of the previous transaction to prevent collisions. */ + k_sleep(K_SECONDS(1)); } for (int i = 0; i < 3; i++) { @@ -222,6 +228,8 @@ static void test_tx_power_replay_attack(void) } ASSERT_TRUE(is_tx_succeeded); + /* Let complete advertising of the previous transaction to prevent collisions. */ + k_sleep(K_SECONDS(1)); } PASS(); From 533baa16b5a6750cf59a7ce7257bc09bcac09637 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Thu, 9 Nov 2023 13:30:15 +0100 Subject: [PATCH 0396/1623] [nrf noup] Bluetooth: Mesh: adapt SDC specific api usage Usage of the Softdevice specific api has been adapted to upstream adv changes. Signed-off-by: Aleksandr Khromykh --- subsys/bluetooth/mesh/adv_ext.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 525e5ee5066..fe9fc4fd403 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -529,8 +529,8 @@ int bt_mesh_adv_enable(void) if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE) && IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - adv->tag == BT_MESH_FRIEND_ADV) { - err = set_adv_randomness(adv->instance->handle, 0); + advs[i].tags == BT_MESH_ADV_TAG_BIT_FRIEND) { + err = set_adv_randomness(advs[i].instance->handle, 0); if (err) { LOG_ERR("Failed to set zero randomness: %d", err); } From f6a5a29a18823fb2bfce70344bf8ba5bcb070388 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 7 Nov 2023 14:26:26 +0100 Subject: [PATCH 0397/1623] Revert "[nrf noup] modules: mbedtls: Add PSA symbols for Oberon PSA extension" This reverts commit 07385636ee190aefce8405776eb76d836c791808. Reverting to add !fixup line to the commit message Signed-off-by: Joakim Andersson --- modules/mbedtls/Kconfig.psa | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 0d43f112aeb..1bd37cedb0b 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -301,8 +301,7 @@ config PSA_HAS_KEY_DERIVATION PSA_WANT_ALG_PBKDF2_HMAC || \ PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 || \ PSA_WANT_ALG_TLS12_PRF || \ - PSA_WANT_ALG_TLS12_PSK_TO_MS || \ - PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS + PSA_WANT_ALG_TLS12_PSK_TO_MS help Prompt-less configuration that states that key derivation is supported. @@ -337,10 +336,6 @@ config PSA_WANT_ALG_TLS12_PSK_TO_MS bool prompt "PSA TLS 1.2 PSK to MS support" if !PSA_PROMPTLESS -config PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS - bool - prompt "PSA TLS 1.2 EC J-PAKE to PMS support" if !PSA_PROMPTLESS - endmenu # PSA Key derivation support @@ -487,19 +482,8 @@ config PSA_WANT_ALG_SPAKE2P prompt "PSA SPAKE2+ support" if !PSA_PROMPTLESS select EXPERIMENTAL -config PSA_WANT_ALG_SRP_6 +config PSA_WANT_ALG_SRP bool - prompt "PSA SRP-6 support" if !PSA_PROMPTLESS + prompt "PSA SRP support" if !PSA_PROMPTLESS + default n select EXPERIMENTAL - -config PSA_WANT_ALG_PURE_EDDSA - bool - prompt "PSA PURE_EDDSA support" if !PSA_PROMPTLESS - -config PSA_WANT_ALG_ED25519PH - bool - prompt "PSA ED25519PH support" if !PSA_PROMPTLESS - -config PSA_WANT_ALG_ED448PH - bool - prompt "PSA ED448PH support" if !PSA_PROMPTLESS From dc4c71ff44f1c67a52a8b786900c832e480b99e6 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 7 Nov 2023 14:27:16 +0100 Subject: [PATCH 0398/1623] Revert "[nrf noup] mbedtls: Add config support for PBKDF2_HMAC" This reverts commit 51bef37071aad3301b4223a59991af71614a13ed. Reverting to add !fixup line to the commit message Signed-off-by: Joakim Andersson --- modules/mbedtls/Kconfig.psa | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 1bd37cedb0b..0e321df6598 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -320,8 +320,9 @@ config PSA_WANT_ALG_HKDF_EXPAND config PSA_WANT_ALG_PBKDF2_HMAC bool - prompt "PSA PBKDF2 HMAC support" if !PSA_PROMPTLESS depends on PSA_WANT_ALG_HMAC + help + PBKDF2-HMAC is not yet supported via the PSA APIs in Mbed TLS. config PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 bool From bcd9dbacb4eaffedc22fbe53403528a36c056897 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 7 Nov 2023 14:28:00 +0100 Subject: [PATCH 0399/1623] Revert "[nrf noup] mbedtls: Add config support for PBKDF2_AES_CMAC_PRF_128" This reverts commit 192697c16cc5908a88d0b75440ec319e2c5d211a. Reverting to add !fixup line to commit message Signed-off-by: Joakim Andersson --- modules/mbedtls/Kconfig.psa | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 0e321df6598..c0c34aa0cce 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -299,7 +299,6 @@ config PSA_HAS_KEY_DERIVATION PSA_WANT_ALG_HKDF_EXPAND || \ PSA_WANT_ALG_HKDF_EXTRACT || \ PSA_WANT_ALG_PBKDF2_HMAC || \ - PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 || \ PSA_WANT_ALG_TLS12_PRF || \ PSA_WANT_ALG_TLS12_PSK_TO_MS help @@ -324,11 +323,6 @@ config PSA_WANT_ALG_PBKDF2_HMAC help PBKDF2-HMAC is not yet supported via the PSA APIs in Mbed TLS. -config PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 - bool - prompt "PSA PBKDF2-AES-CMAC-PRF-128 support" if !PSA_PROMPTLESS - depends on PSA_WANT_ALG_CMAC - config PSA_WANT_ALG_TLS12_PRF bool prompt "PSA PRF support (TLS1.2)" if !PSA_PROMPTLESS From c490eb32ce3d568f4a29112ebd04658bfcd962d6 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 7 Nov 2023 14:28:49 +0100 Subject: [PATCH 0400/1623] Revert "[nrf noup] modules: mbedtls: Fix key support Kconfig" This reverts commit 132cee61e6ce404b25dbc626b57b5df149c136a8. Reverting to add !fixup line to commit message Signed-off-by: Joakim Andersson --- modules/mbedtls/Kconfig.psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index c0c34aa0cce..399d18a3797 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -47,7 +47,7 @@ config PSA_HAS_KEY_SUPPORT PSA_WANT_KEY_TYPE_RSA_KEY_PAIR || \ PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY || \ PSA_WANT_KEY_TYPE_DH_KEY_PAIR || \ - PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY + PSA_WANT_KEY_TYPE_DH_KEY_PAIR config PSA_WANT_KEY_TYPE_DERIVE bool "PSA derive key type support" From 0a78b665e502695a7855178595c3c077ff2ce71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20Lilleb=C3=B8?= Date: Tue, 9 May 2023 16:21:35 +0200 Subject: [PATCH 0401/1623] [nrf noup] modules: mbedtls: Add PSA symbols for Oberon PSA extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixup! [nrf noup] modules: mbedtls: add PSA configurations Add PSA symbols for Oberon extension to the PSA specification. Mbed TLS has adopted the same naming, so while this is not part of the PSA specification it is fine to add it to the generic configuration for both implementations. Signed-off-by: Joakim Andersson Signed-off-by: Vidar Lillebø (cherry picked from commit 0b32fd2743f574aaa293122545caeadd3b01fd41) --- modules/mbedtls/Kconfig.psa | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 399d18a3797..9f93771584c 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -300,7 +300,8 @@ config PSA_HAS_KEY_DERIVATION PSA_WANT_ALG_HKDF_EXTRACT || \ PSA_WANT_ALG_PBKDF2_HMAC || \ PSA_WANT_ALG_TLS12_PRF || \ - PSA_WANT_ALG_TLS12_PSK_TO_MS + PSA_WANT_ALG_TLS12_PSK_TO_MS || \ + PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS help Prompt-less configuration that states that key derivation is supported. @@ -331,6 +332,10 @@ config PSA_WANT_ALG_TLS12_PSK_TO_MS bool prompt "PSA TLS 1.2 PSK to MS support" if !PSA_PROMPTLESS +config PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS + bool + prompt "PSA TLS 1.2 EC J-PAKE to PMS support" if !PSA_PROMPTLESS + endmenu # PSA Key derivation support @@ -477,8 +482,19 @@ config PSA_WANT_ALG_SPAKE2P prompt "PSA SPAKE2+ support" if !PSA_PROMPTLESS select EXPERIMENTAL -config PSA_WANT_ALG_SRP +config PSA_WANT_ALG_SRP_6 bool - prompt "PSA SRP support" if !PSA_PROMPTLESS - default n + prompt "PSA SRP-6 support" if !PSA_PROMPTLESS select EXPERIMENTAL + +config PSA_WANT_ALG_PURE_EDDSA + bool + prompt "PSA PURE_EDDSA support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_ED25519PH + bool + prompt "PSA ED25519PH support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_ED448PH + bool + prompt "PSA ED448PH support" if !PSA_PROMPTLESS From b850ab7cfc8161ba37194f9c7e1935051e3d206f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Tue, 20 Jun 2023 13:27:15 +0200 Subject: [PATCH 0402/1623] [nrf noup] mbedtls: Add config support for PBKDF2_HMAC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixup! [nrf noup] modules: mbedtls: add PSA configurations Add config support for PBKDF2_HMAC. This patches an existing noup commit and is therefore also noup. Signed-off-by: Sebastian Bøe (cherry picked from commit 1ff52962ebce37d536949bcc1804fcf502011af6) Signed-off-by: Joakim Andersson --- modules/mbedtls/Kconfig.psa | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 9f93771584c..5e8e9a8ead0 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -320,9 +320,8 @@ config PSA_WANT_ALG_HKDF_EXPAND config PSA_WANT_ALG_PBKDF2_HMAC bool + prompt "PSA PBKDF2 HMAC support" if !PSA_PROMPTLESS depends on PSA_WANT_ALG_HMAC - help - PBKDF2-HMAC is not yet supported via the PSA APIs in Mbed TLS. config PSA_WANT_ALG_TLS12_PRF bool From 33121ff883e93385eb12dddbed7077e8dcbb968d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Tue, 20 Jun 2023 15:04:46 +0200 Subject: [PATCH 0403/1623] [nrf noup] mbedtls: Add config support for PBKDF2_AES_CMAC_PRF_128 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixup! [nrf noup] modules: mbedtls: add PSA configurations Add config support for PBKDF2_AES_CMAC_PRF_128 Signed-off-by: Sebastian Bøe (cherry picked from commit 743f99947369088ecba6820a720ede8054893866) Signed-off-by: Joakim Andersson --- modules/mbedtls/Kconfig.psa | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 5e8e9a8ead0..b0d21685f70 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -299,6 +299,7 @@ config PSA_HAS_KEY_DERIVATION PSA_WANT_ALG_HKDF_EXPAND || \ PSA_WANT_ALG_HKDF_EXTRACT || \ PSA_WANT_ALG_PBKDF2_HMAC || \ + PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 || \ PSA_WANT_ALG_TLS12_PRF || \ PSA_WANT_ALG_TLS12_PSK_TO_MS || \ PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS @@ -323,6 +324,11 @@ config PSA_WANT_ALG_PBKDF2_HMAC prompt "PSA PBKDF2 HMAC support" if !PSA_PROMPTLESS depends on PSA_WANT_ALG_HMAC +config PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 + bool + prompt "PSA PBKDF2-AES-CMAC-PRF-128 support" if !PSA_PROMPTLESS + depends on PSA_WANT_ALG_CMAC + config PSA_WANT_ALG_TLS12_PRF bool prompt "PSA PRF support (TLS1.2)" if !PSA_PROMPTLESS From 1fab667892451f21114f87cf48863c0dbdfb9507 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Fri, 18 Aug 2023 10:20:45 +0200 Subject: [PATCH 0404/1623] [nrf noup] modules: mbedtls: Fix key support Kconfig fixup! [nrf noup] modules: mbedtls: add PSA configurations PSA_HAS_KEY_SUPPORT was missing the DH_PUBLIC_KEY only Kconfig as the KEY_PAIR was double in there Signed-off-by: Markus Swarowsky (cherry picked from commit 53c4b20c15611a9d13b91e5dc025733d6dd65adb) Signed-off-by: Joakim Andersson --- modules/mbedtls/Kconfig.psa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index b0d21685f70..0d43f112aeb 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -47,7 +47,7 @@ config PSA_HAS_KEY_SUPPORT PSA_WANT_KEY_TYPE_RSA_KEY_PAIR || \ PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY || \ PSA_WANT_KEY_TYPE_DH_KEY_PAIR || \ - PSA_WANT_KEY_TYPE_DH_KEY_PAIR + PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY config PSA_WANT_KEY_TYPE_DERIVE bool "PSA derive key type support" From 0708dc8e65603cca2abe7799bffe765f97d00bb4 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 7 Nov 2023 11:01:52 +0100 Subject: [PATCH 0405/1623] [nrf noup] modules: mbedtls: Add all PSA spec algorithms and key types fixup! [nrf noup] modules: mbedtls: add PSA configurations Add all of the PSA specification defined algorithms and key types. This makes the configurations independent of what is supported by the specific implementation. Fix CCM star no tag wrongly listed as an AEAD instead of Cipher algorithm. Remove the HAS_ECC and HAS_RSA support. They don't provide much information. ECC and RSA are both assymetric signing algorithms, while RSA is also an assymetric encryption algorithm. Signed-off-by: Joakim Andersson --- modules/mbedtls/Kconfig.psa | 296 ++++++++++++++---- .../Kconfig.tfm.crypto_modules | 3 +- 2 files changed, 244 insertions(+), 55 deletions(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 0d43f112aeb..42d2a48825b 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -41,6 +41,11 @@ config PSA_HAS_KEY_SUPPORT PSA_WANT_KEY_TYPE_PASSWORD_HASH || \ PSA_WANT_KEY_TYPE_PEPPER || \ PSA_WANT_KEY_TYPE_AES || \ + PSA_WANT_KEY_TYPE_ARIA || \ + PSA_WANT_KEY_TYPE_DES || \ + PSA_WANT_KEY_TYPE_CAMELLIA || \ + PSA_WANT_KEY_TYPE_SM4 || \ + PSA_WANT_KEY_TYPE_ARC4 || \ PSA_WANT_KEY_TYPE_CHACHA20 || \ PSA_WANT_KEY_TYPE_ECC_KEY_PAIR || \ PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY || \ @@ -86,6 +91,29 @@ config PSA_WANT_KEY_TYPE_AES help Key for cipher, AEAD or MAC algorithm based on the AES block cipher. +config PSA_WANT_KEY_TYPE_ARIA + bool "PSA ARIA key type support" + +config PSA_WANT_KEY_TYPE_DES + bool "PSA DES key type support (weak)" + help + Warning: Single DES and 2-key 3DES are weak and strongly deprecated + and are only recommended for decrypting legacy data. + 3-key 3DES is weak and deprecated and is only recommended for use in + legacy protocols. + +config PSA_WANT_KEY_TYPE_CAMELLIA + bool "PSA CAMELLIA key type support" + +config PSA_WANT_KEY_TYPE_SM4 + bool "PSA SM4 key type support" + +config PSA_WANT_KEY_TYPE_ARC4 + bool "PSA ARC4 key type support (weak)" + help + Warning: The ARC4 cipher is weak and deprecated and is only + recommended for use in legacy protocols. + config PSA_WANT_KEY_TYPE_CHACHA20 bool "PSA ChaCha20 key type support" default y @@ -135,7 +163,6 @@ config PSA_HAS_AEAD_SUPPORT bool default y depends on PSA_WANT_ALG_CCM || \ - PSA_WANT_ALG_CCM_STAR_NO_TAG || \ PSA_WANT_ALG_GCM || \ PSA_WANT_ALG_CHACHA20_POLY1305 help @@ -145,10 +172,6 @@ config PSA_WANT_ALG_CCM bool prompt "PSA CCM support" if !PSA_PROMPTLESS -config PSA_WANT_ALG_CCM_STAR_NO_TAG - bool - prompt "PSA AES CCM star with no tag support" if !PSA_PROMPTLESS - config PSA_WANT_ALG_GCM bool prompt "PSA GCM support" if !PSA_PROMPTLESS @@ -173,8 +196,7 @@ config PSA_HAS_MAC_SUPPORT config PSA_WANT_ALG_CBC_MAC bool - help - CBC-MAC is not yet supported via the PSA API in Mbed TLS. + prompt "PSA CBC-MAC support" if !PSA_PROMPTLESS config PSA_WANT_ALG_CMAC bool @@ -197,7 +219,17 @@ config PSA_HAS_HASH_SUPPORT PSA_WANT_ALG_SHA_256 || \ PSA_WANT_ALG_SHA_384 || \ PSA_WANT_ALG_SHA_512 || \ + PSA_WANT_ALG_SHA_512_224 || \ + PSA_WANT_ALG_SHA_512_256 || \ + PSA_WANT_ALG_SHA3_224 || \ + PSA_WANT_ALG_SHA3_256 || \ + PSA_WANT_ALG_SHA3_384 || \ + PSA_WANT_ALG_SHA3_512 || \ + PSA_WANT_ALG_SM3 || \ + PSA_WANT_ALG_SHAKE256_512 || \ PSA_WANT_ALG_RIPEMD160 || \ + PSA_WANT_ALG_MD2 || \ + PSA_WANT_ALG_MD4 || \ PSA_WANT_ALG_MD5 help Prompt-less configuration that states that hash is supported. @@ -225,10 +257,56 @@ config PSA_WANT_ALG_SHA_512 bool prompt "PSA SHA-512 support" if !PSA_PROMPTLESS +config PSA_WANT_ALG_SHA_512_224 + bool + prompt "PSA SHA-512/224 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SHA_512_256 + bool + prompt "PSA SHA-512/256 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SHA3_224 + bool + prompt "PSA SHA3-224 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SHA3_256 + bool + prompt "PSA SHA3-256 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SHA3_384 + bool + prompt "PSA SHA3-384 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SHA3_512 + bool + prompt "PSA SHA3-512 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SM3 + bool + prompt "PSA SM3 support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SHAKE256_512 + bool + prompt "PSA SHAKE256 512 bits support" if !PSA_PROMPTLESS + config PSA_WANT_ALG_RIPEMD160 bool prompt "PSA RIPEMD-160 support" if !PSA_PROMPTLESS +config PSA_WANT_ALG_MD2 + bool + prompt "PSA MD2 support (weak)" if !PSA_PROMPTLESS + help + Warning: The MD2 hash is weak and deprecated and is only recommended + for use in legacy protocols. + +config PSA_WANT_ALG_MD4 + bool + prompt "PSA MD4 support (weak)" if !PSA_PROMPTLESS + help + Warning: The MD4 hash is weak and deprecated and is only recommended + for use in legacy protocols. + config PSA_WANT_ALG_MD5 bool prompt "PSA MD5 support (weak)" if !PSA_PROMPTLESS @@ -246,10 +324,10 @@ config PSA_HAS_CIPHER_SUPPORT depends on PSA_WANT_ALG_ECB_NO_PADDING || \ PSA_WANT_ALG_CBC_NO_PADDING || \ PSA_WANT_ALG_CBC_PKCS7 || \ + PSA_WANT_ALG_CCM_STAR_NO_TAG || \ PSA_WANT_ALG_CFB || \ PSA_WANT_ALG_CTR || \ PSA_WANT_ALG_OFB || \ - PSA_WANT_ALG_CTR || \ PSA_WANT_ALG_XTS || \ PSA_WANT_ALG_STREAM_CIPHER help @@ -283,12 +361,38 @@ config PSA_WANT_ALG_XTS bool prompt "PSA XTS block cipher mode support" if !PSA_PROMPTLESS +config PSA_WANT_ALG_CCM_STAR_NO_TAG + bool + prompt "PSA CCM* with no tag support" if !PSA_PROMPTLESS + help + Unauthenticated version of CCM. Uses the cipher API instead of the AEAD API. + config PSA_WANT_ALG_STREAM_CIPHER bool prompt "PSA stream cipher support" if !PSA_PROMPTLESS endmenu # PSA Cipher Support +menu "PSA Key agreement support" + +config PSA_HAS_KEY_AGREEMENT + bool + default y + depends on PSA_WANT_ALG_ECDH + depends on PSA_WANT_ALG_FFDH + help + Promt-less configuration that states that key agreement is supported. + +config PSA_WANT_ALG_ECDH + bool + prompt "PSA ECDH support" if !PSA_PROMPTLESS + + +config PSA_WANT_ALG_FFDH + bool + prompt "PSA FFDH support" if !PSA_PROMPTLESS + +endmenu # PSA Key agreement support menu "PSA Key derivation support" @@ -361,65 +465,86 @@ config PSA_HAS_ASYM_SIGN_SUPPORT default y depends on PSA_WANT_ALG_DETERMINISTIC_ECDSA || \ PSA_WANT_ALG_ECDSA || \ + PSA_WANT_ALG_ECDSA_ANY || \ + PSA_WANT_ALG_PURE_EDDSA || \ + PSA_WANT_ALG_ED25519PH || \ + PSA_WANT_ALG_ED448PH || \ PSA_WANT_ALG_RSA_PKCS1V15_SIGN || \ - PSA_WANT_ALG_RSA_PSS + PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW || \ + PSA_WANT_ALG_RSA_PSS || \ + PSA_WANT_ALG_RSA_PSS_ANY_SALT help Prompt-less configuration that states that asymmetric signing is supported. -config PSA_HAS_ECC_SUPPORT - bool - depends on PSA_WANT_ALG_ECDH || \ - PSA_WANT_ALG_ECDSA || \ - PSA_WANT_ALG_DETERMINISTIC_ECDSA || \ - PSA_WANT_KEY_TYPE_ECC_KEY_PAIR || \ - PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY - default y - help - Prompt-less configuration that states that ECC is supported. - -config PSA_WANT_ALG_ECDH - bool - prompt "PSA ECDH support" if !PSA_PROMPTLESS - config PSA_WANT_ALG_ECDSA bool prompt "PSA ECDSA support" if !PSA_PROMPTLESS +config PSA_WANT_ALG_ECDSA_ANY + bool + prompt "PSA ECDSA support, without hashing" if !PSA_PROMPTLESS + config PSA_WANT_ALG_DETERMINISTIC_ECDSA bool prompt "PSA ECDSA support (deterministic mode)" if !PSA_PROMPTLESS menu "Elliptic Curve type support" - depends on PSA_HAS_ECC_SUPPORT + +config PSA_WANT_ECC_BRAINPOOL_P_R1_160 + bool + prompt "PSA ECC BrainpoolP160r1 support (weak)" if !PSA_PROMPTLESS + help + Warning: The 160-bit curve brainpoolP160r1 is weak and deprecated and + is only recommended for use in legacy protocols. + +config PSA_WANT_ECC_BRAINPOOL_P_R1_192 + bool + prompt "PSA ECC BrainpoolP192r1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_BRAINPOOL_P_R1_224 + bool + prompt "PSA ECC BrainpoolP224r1 support" if !PSA_PROMPTLESS config PSA_WANT_ECC_BRAINPOOL_P_R1_256 bool - prompt "PSA ECC Brainpool256r1 support" + prompt "PSA ECC BrainpoolP256r1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_BRAINPOOL_P_R1_320 + bool + prompt "PSA ECC BrainpoolP320r1 support" if !PSA_PROMPTLESS config PSA_WANT_ECC_BRAINPOOL_P_R1_384 - bool "PSA ECC Brainpool384r1 support" + bool + prompt "PSA ECC BrainpoolP384r1 support" if !PSA_PROMPTLESS config PSA_WANT_ECC_BRAINPOOL_P_R1_512 - bool "PSA ECC Brainpool512r1 support" + bool + prompt "PSA ECC BrainpoolP512r1 support" if !PSA_PROMPTLESS config PSA_WANT_ECC_MONTGOMERY_255 - bool "PSA ECC Curve25519 (X25519) support" + bool + prompt "PSA ECC Curve25519 (X25519) support" if !PSA_PROMPTLESS config PSA_WANT_ECC_MONTGOMERY_448 - bool "PSA ECC Curve448 (X448) support" + bool + prompt "PSA ECC Curve448 (X448) support" if !PSA_PROMPTLESS config PSA_WANT_ECC_TWISTED_EDWARDS_255 - bool "PSA ECC Edwards25519 (Ed25519) support" + bool + prompt "PSA ECC Edwards25519 (Ed25519) support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_TWISTED_EDWARDS_448 + bool + prompt "PSA ECC Edwards448 (Ed448) support" if !PSA_PROMPTLESS config PSA_WANT_ECC_SECP_K1_192 - bool "PSA ECC secp192k1 support" + bool + prompt "PSA ECC secp192k1 support" if !PSA_PROMPTLESS config PSA_WANT_ECC_SECP_K1_224 bool - help - SECP224K1 is buggy via the PSA API in Mbed TLS - See https://github.com/ARMmbed/mbedtls/issues/3541 + prompt "PSA ECC secp224k1 support" if !PSA_PROMPTLESS config PSA_WANT_ECC_SECP_K1_256 bool @@ -427,53 +552,116 @@ config PSA_WANT_ECC_SECP_K1_256 config PSA_WANT_ECC_SECP_R1_192 bool - prompt "PSA ECC secp192r1" if !PSA_PROMPTLESS + prompt "PSA ECC secp192r1 support" if !PSA_PROMPTLESS config PSA_WANT_ECC_SECP_R1_224 bool - prompt "PSA ECC secp224r1" if !PSA_PROMPTLESS + prompt "PSA ECC secp224r1 support" if !PSA_PROMPTLESS config PSA_WANT_ECC_SECP_R1_256 bool - prompt "PSA ECC secp256r1" if !PSA_PROMPTLESS + prompt "PSA ECC secp256r1 support" if !PSA_PROMPTLESS config PSA_WANT_ECC_SECP_R1_384 bool - prompt "PSA ECC secp384r1" if !PSA_PROMPTLESS + prompt "PSA ECC secp384r1 support" if !PSA_PROMPTLESS config PSA_WANT_ECC_SECP_R1_521 bool - prompt "PSA ECC secp521r1" if !PSA_PROMPTLESS + prompt "PSA ECC secp521r1 support" if !PSA_PROMPTLESS -endmenu # Elliptic Curve type support +config PSA_WANT_ECC_SECP_R2_160 + bool + prompt "PSA ECC secp160r2 support (weak)" if !PSA_PROMPTLESS + help + Warning: his family of curves is weak and deprecated. -config PSA_HAS_RSA_SUPPORT +config PSA_WANT_ECC_SECT_K1_163 bool - depends on PSA_WANT_ALG_RSA_OAEP || \ - PSA_WANT_ALG_RSA_PKCS1V15_CRYPT || \ - PSA_WANT_ALG_RSA_PKCS1V15_SIGN || \ - PSA_WANT_ALG_RSA_PSS || \ - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR || \ - PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY - default y + prompt "PSA ECC sect163k1 support (weak)" if !PSA_PROMPTLESS + help + Warning: The 163-bit curve sect163k1 is weak and deprecated and is + only recommended for use in legacy protocols. + +config PSA_WANT_ECC_SECT_K1_233 + bool + prompt "PSA ECC sect233k1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECT_K1_239 + bool + prompt "PSA ECC sect239k1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECT_K1_283 + bool + prompt "PSA ECC sect283k1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECT_K1_409 + bool + prompt "PSA ECC sect409k1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECT_K1_571 + bool + prompt "PSA ECC sect571k1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECT_R1_163 + bool + prompt "PSA ECC sect163r1 support (weak)" if !PSA_PROMPTLESS + help + Warning: The 163-bit curve sect163r1 is weak and deprecated and is + only recommended for use in legacy protocols. + +config PSA_WANT_ECC_SECT_R1_233 + bool + prompt "PSA ECC sect233r1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECT_R1_283 + bool + prompt "PSA ECC sect283r1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECT_R1_409 + bool + prompt "PSA ECC sect409r1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECT_R1_571 + bool + prompt "PSA ECC sect571r1 support" if !PSA_PROMPTLESS + +config PSA_WANT_ECC_SECT_R2_163 + bool + prompt "PSA ECC sect163r2 support (weak)" if !PSA_PROMPTLESS help - Prompt-less configuration that states that RSA is supported. + Warning: The 163-bit curve sect163r2 is weak and deprecated and is + only recommended for use in legacy protocols. + +config PSA_WANT_ECC_FRP_V1_256 + bool + prompt "PSA ECC FRP256v1 support" if !PSA_PROMPTLESS + +endmenu # Elliptic Curve type support config PSA_WANT_ALG_RSA_OAEP bool - prompt "PSA RSA OAEP support" if !PSA_PROMPTLESS + prompt "PSA RSA OAEP asymmetric encryption support" if !PSA_PROMPTLESS config PSA_WANT_ALG_RSA_PKCS1V15_CRYPT bool - prompt "PSA RSA crypt support (PKCS#1 v1.5 mode)" if !PSA_PROMPTLESS + prompt "PSA RSA PKCS#1 v1.5 asymmetric encryption support" if !PSA_PROMPTLESS config PSA_WANT_ALG_RSA_PKCS1V15_SIGN bool - prompt "PSA RSA signature support (PKCS#1 v1.5 mode)" if !PSA_PROMPTLESS + prompt "PSA RSA PKCS#1 v1.5 message signature support, with hashing" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW + bool + prompt "PSA RSA raw PKCS#1 v1.5 message signature support, without hashing)" if !PSA_PROMPTLESS config PSA_WANT_ALG_RSA_PSS bool - prompt "PSA RSA (PSS mode)" if !PSA_PROMPTLESS + prompt "PSA RSA PSS message signature support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_RSA_PSS_ANY_SALT + bool + prompt "PSA RSA PSS message signature support, any salt length" if !PSA_PROMPTLESS endmenu # PSA Asymmetric support diff --git a/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules b/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules index 89893686143..1f0ec52aed3 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules +++ b/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules @@ -80,11 +80,12 @@ config TFM_CRYPTO_ASYM_SIGN_MODULE_ENABLED config TFM_CRYPTO_KEY_DERIVATION_MODULE_ENABLED bool "KEY DERIVATION crypto module" default y - depends on PSA_HAS_KEY_DERIVATION && NRF_SECURITY + depends on (PSA_HAS_KEY_DERIVATION || PSA_HAS_KEY_AGREEMENT) && NRF_SECURITY help Enables the KEY_DERIVATION crypto module within the crypto partition. Unset this option if the functionality provided by 'crypto_key_derivation.c' is not used. + Note that key agreement is under key derivation in the current implementation. endif # TFM_PARTITION_CRYPTO From f8e27684ca11e884c1e8ae6e1903c815277137a6 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Tue, 31 Oct 2023 11:56:24 +0000 Subject: [PATCH 0406/1623] [nrf fromlist] cmake: Add support for sysbuild-set signing script Allows a sysbuild project to specify a signing script file to use instead of the default zephyr one Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63912 Signed-off-by: Jamie McCrae --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fc047610fc..e23650f262f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1824,8 +1824,15 @@ endif() # Generate and use MCUboot related artifacts as needed. if(CONFIG_BOOTLOADER_MCUBOOT) get_target_property(signing_script zephyr_property_target SIGNING_SCRIPT) + if(NOT signing_script) - set_target_properties(zephyr_property_target PROPERTIES SIGNING_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/cmake/mcuboot.cmake) + zephyr_get(signing_script VAR SIGNING_SCRIPT SYSBUILD) + + if(signing_script) + set_target_properties(zephyr_property_target PROPERTIES SIGNING_SCRIPT ${signing_script}) + else() + set_target_properties(zephyr_property_target PROPERTIES SIGNING_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/cmake/mcuboot.cmake) + endif() endif() endif() From c441a8dc1291faf8972964f2f944dfe2129a5ede Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Mon, 13 Nov 2023 13:36:44 +0100 Subject: [PATCH 0407/1623] [nrf fromlist] sysbuild: create sysbuild_cache function Create dedicated function, sysbuild_cache(), for handling sysbuild's image specific cache file. This provides a cleaner handling of said cache file, and provides a mechanism for updating the cache file at later sysbuild CMake stages. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65124 Signed-off-by: Torsten Rasmussen --- .../cmake/modules/sysbuild_extensions.cmake | 124 ++++++++++++------ 1 file changed, 82 insertions(+), 42 deletions(-) diff --git a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake index a3838415eee..ac8bac25f8c 100644 --- a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake +++ b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake @@ -107,6 +107,87 @@ function(sysbuild_get variable) endif() endfunction() +# Usage: +# sysbuild_cache(CREATE APPLICATION [CMAKE_RERUN]) +# +# This function works on the sysbuild cache for sysbuild managed applications. +# +# Arguments: +# CREATE : Create or update existing sysbuild cache file for the application. +# The sysbuild cache is only updated if it contain changes. +# APPLICATION : Name of the application. +# CMAKE_RERUN : Force a CMake rerun for the application during next build +# invocation if the sysbuild cache has changed. It is +# advised to always use this flag. Not using this flag can +# reduce build time, but only do so if application is +# guranteed to be up-to-date. +# +function(sysbuild_cache) + cmake_parse_arguments(SB_CACHE "CREATE;CMAKE_RERUN" "APPLICATION" "" ${ARGN}) + zephyr_check_arguments_required(sysbuild_cache SB_CACHE APPLICATION) + zephyr_check_flags_required(sysbuild_cache SB_CACHE CREATE) + + get_target_property(${SB_CACHE_APPLICATION}_MAIN_APP ${SB_CACHE_APPLICATION} MAIN_APP) + get_cmake_property(sysbuild_cache CACHE_VARIABLES) + + foreach(var_name ${sysbuild_cache}) + if(NOT "${var_name}" MATCHES "^(CMAKE_.*|BOARD)$") + # Perform a dummy read to prevent a false warning about unused variables + # being emitted due to a cmake bug: https://gitlab.kitware.com/cmake/cmake/-/issues/24555 + set(unused_tmp_var ${${var_name}}) + + # We don't want to pass internal CMake variables. + # Required CMake variable to be passed, like CMAKE_BUILD_TYPE must be + # passed using `-D` on command invocation. + get_property(var_type CACHE ${var_name} PROPERTY TYPE) + set(cache_entry "${var_name}:${var_type}=$CACHE{${var_name}}") + string(REPLACE ";" "\;" cache_entry "${cache_entry}") + list(APPEND sysbuild_cache_strings "${cache_entry}\n") + endif() + endforeach() + if(DEFINED BOARD_REVISION) + list(APPEND sysbuild_cache_strings "BOARD:STRING=${BOARD}@${BOARD_REVISION}\n") + else() + list(APPEND sysbuild_cache_strings "BOARD:STRING=${BOARD}\n") + endif() + list(APPEND sysbuild_cache_strings "SYSBUILD_NAME:STRING=${SB_CACHE_APPLICATION}\n") + + if(${SB_CACHE_APPLICATION}_MAIN_APP) + list(APPEND sysbuild_cache_strings "SYSBUILD_MAIN_APP:BOOL=True\n") + endif() + + if(${SB_CACHE_APPLICATION}_BOARD AND NOT DEFINED CACHE{${SB_CACHE_APPLICATION}_BOARD}) + # Only set image specific board if provided. + # The sysbuild BOARD is exported through sysbuild cache, and will be used + # unless _BOARD is defined. + list(APPEND sysbuild_cache_strings + "${SB_CACHE_APPLICATION}_BOARD:STRING=${${SB_CACHE_APPLICATION}_BOARD}\n" + ) + endif() + + get_target_property(${SB_CACHE_APPLICATION}_CACHE_FILE ${SB_CACHE_APPLICATION} CACHE_FILE) + file(WRITE ${${SB_CACHE_APPLICATION}_CACHE_FILE}.tmp ${sysbuild_cache_strings}) + if(SB_CACHE_CMAKE_RERUN) + execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files + ${${SB_CACHE_APPLICATION}_CACHE_FILE}.tmp + ${${SB_CACHE_APPLICATION}_CACHE_FILE} + RESULT_VARIABLE compare_res + ) + if(NOT compare_res EQUAL 0) + file(COPY_FILE ${${SB_CACHE_APPLICATION}_CACHE_FILE}.tmp + ${${SB_CACHE_APPLICATION}_CACHE_FILE} + ) + ExternalProject_Get_Property(${SB_CACHE_APPLICATION} BINARY_DIR) + file(TOUCH_NOCREATE ${BINARY_DIR}/CMakeCache.txt) + endif() + else() + zephyr_file_copy(${${SB_CACHE_APPLICATION}_CACHE_FILE}.tmp + ${${SB_CACHE_APPLICATION}_CACHE_FILE} ONLY_IF_DIFFERENT + ) + endif() + +endfunction() + # Usage: # ExternalZephyrProject_Add(APPLICATION # SOURCE_DIR @@ -372,9 +453,7 @@ function(ExternalZephyrProject_Cmake) ) ExternalProject_Get_Property(${ZCMAKE_APPLICATION} SOURCE_DIR BINARY_DIR CMAKE_ARGS) - get_target_property(${ZCMAKE_APPLICATION}_CACHE_FILE ${ZCMAKE_APPLICATION} CACHE_FILE) get_target_property(${ZCMAKE_APPLICATION}_BOARD ${ZCMAKE_APPLICATION} BOARD) - get_target_property(${ZCMAKE_APPLICATION}_MAIN_APP ${ZCMAKE_APPLICATION} MAIN_APP) get_property(${ZCMAKE_APPLICATION}_CONF_SCRIPT TARGET ${ZCMAKE_APPLICATION} PROPERTY IMAGE_CONF_SCRIPT @@ -390,46 +469,7 @@ function(ExternalZephyrProject_Cmake) endif() endforeach() - get_cmake_property(sysbuild_cache CACHE_VARIABLES) - foreach(var_name ${sysbuild_cache}) - if(NOT "${var_name}" MATCHES "^(CMAKE_.*|BOARD)$") - # Perform a dummy read to prevent a false warning about unused variables - # being emitted due to a cmake bug: https://gitlab.kitware.com/cmake/cmake/-/issues/24555 - set(unused_tmp_var ${${var_name}}) - - # We don't want to pass internal CMake variables. - # Required CMake variable to be passed, like CMAKE_BUILD_TYPE must be - # passed using `-D` on command invocation. - get_property(var_type CACHE ${var_name} PROPERTY TYPE) - set(cache_entry "${var_name}:${var_type}=$CACHE{${var_name}}") - string(REPLACE ";" "\;" cache_entry "${cache_entry}") - list(APPEND sysbuild_cache_strings "${cache_entry}\n") - endif() - endforeach() - if(DEFINED BOARD_REVISION) - list(APPEND sysbuild_cache_strings "BOARD:STRING=${BOARD}@${BOARD_REVISION}\n") - else() - list(APPEND sysbuild_cache_strings "BOARD:STRING=${BOARD}\n") - endif() - list(APPEND sysbuild_cache_strings "SYSBUILD_NAME:STRING=${ZCMAKE_APPLICATION}\n") - - if(${ZCMAKE_APPLICATION}_MAIN_APP) - list(APPEND sysbuild_cache_strings "SYSBUILD_MAIN_APP:BOOL=True\n") - endif() - - if(${ZCMAKE_APPLICATION}_BOARD AND NOT DEFINED CACHE{${ZCMAKE_APPLICATION}_BOARD}) - # Only set image specific board if provided. - # The sysbuild BOARD is exported through sysbuild cache, and will be used - # unless _BOARD is defined. - list(APPEND sysbuild_cache_strings - "${ZCMAKE_APPLICATION}_BOARD:STRING=${${ZCMAKE_APPLICATION}_BOARD}\n" - ) - endif() - - file(WRITE ${${ZCMAKE_APPLICATION}_CACHE_FILE}.tmp ${sysbuild_cache_strings}) - zephyr_file_copy(${${ZCMAKE_APPLICATION}_CACHE_FILE}.tmp - ${${ZCMAKE_APPLICATION}_CACHE_FILE} ONLY_IF_DIFFERENT - ) + sysbuild_cache(CREATE APPLICATION ${ZCMAKE_APPLICATION}) foreach(script ${${ZCMAKE_APPLICATION}_CONF_SCRIPT}) include(${script}) From fda9e48e5d953cf436fa0d0d50f0df9ca0127632 Mon Sep 17 00:00:00 2001 From: Jacob Preston Date: Wed, 18 Oct 2023 09:21:16 -0700 Subject: [PATCH 0408/1623] [nrf fromtree] drivers: uart: nrf: rx_timeout_slab incorrectly set When rx_timeout is set to a sufficiently small value, rx_timeout_slab could potentially get set to a greater than necessary value that causes spurious UART_RX_RDY events. Fixes #62828 Signed-off-by: Jacob Preston (cherry picked from commit 52c55177ba71af328c6069ea56c007e6eb5cdf1d) --- drivers/serial/uart_nrfx_uarte.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index 017efa6a2e5..b70af538abf 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -844,15 +844,7 @@ static int uarte_nrfx_rx_enable(const struct device *dev, uint8_t *buf, } data->async->rx_timeout = timeout; - /* Set minimum interval to 3 RTC ticks. 3 is used due to RTC limitation - * which cannot set timeout for next tick. Assuming delay in processing - * 3 instead of 2 is used. Note that lower value would work in a similar - * way but timeouts would always occur later than expected, most likely - * after ~3 ticks. - */ - data->async->rx_timeout_slab = - MAX(timeout / RX_TIMEOUT_DIV, - NRFX_CEIL_DIV(3 * 1000000, CONFIG_SYS_CLOCK_TICKS_PER_SEC)); + data->async->rx_timeout_slab = timeout / RX_TIMEOUT_DIV; data->async->rx_buf = buf; data->async->rx_buf_len = len; From e40ab3aeae65a78c7371113cfcb3bcf2d68d1845 Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Fri, 1 Sep 2023 11:20:03 +0200 Subject: [PATCH 0409/1623] [nrf fromtree] boards: arm: add nrf9131ek_nrf9131 This patch adds the nRF9131-EK board. (cherry picked from commit 386b65800896262779336e83552c8a44ba96f7a2) Signed-off-by: Maximilian Deubel --- boards/arm/nrf9131ek_nrf9131/Kconfig.board | 14 ++ .../arm/nrf9131ek_nrf9131/Kconfig.defconfig | 38 +++ boards/arm/nrf9131ek_nrf9131/board.cmake | 14 ++ .../nrf9131ek_nrf9131/nrf9131ek_nrf9131.dts | 19 ++ .../nrf9131ek_nrf9131/nrf9131ek_nrf9131.yaml | 17 ++ .../nrf9131ek_nrf9131_common-pinctrl.dtsi | 100 ++++++++ .../nrf9131ek_nrf9131_common.dtsi | 227 ++++++++++++++++++ .../nrf9131ek_nrf9131_defconfig | 26 ++ .../nrf9131ek_nrf9131_ns.dts | 22 ++ .../nrf9131ek_nrf9131_ns.yaml | 15 ++ .../nrf9131ek_nrf9131_ns_defconfig | 35 +++ .../nrf9131ek_nrf9131_partition_conf.dtsi | 60 +++++ .../arm/nrf9131ek_nrf9131/pre_dt_board.cmake | 7 + tests/lib/devicetree/devices/testcase.yaml | 2 + 14 files changed, 596 insertions(+) create mode 100644 boards/arm/nrf9131ek_nrf9131/Kconfig.board create mode 100644 boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig create mode 100644 boards/arm/nrf9131ek_nrf9131/board.cmake create mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.dts create mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.yaml create mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common-pinctrl.dtsi create mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi create mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_defconfig create mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.dts create mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.yaml create mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns_defconfig create mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_partition_conf.dtsi create mode 100644 boards/arm/nrf9131ek_nrf9131/pre_dt_board.cmake diff --git a/boards/arm/nrf9131ek_nrf9131/Kconfig.board b/boards/arm/nrf9131ek_nrf9131/Kconfig.board new file mode 100644 index 00000000000..4a237e3fb61 --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/Kconfig.board @@ -0,0 +1,14 @@ +# nRF9131-EK board configuration + +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_NRF9131_LACA + +config BOARD_NRF9131EK_NRF9131 + bool "nRF9131 EK NRF9131" + +config BOARD_NRF9131EK_NRF9131_NS + bool "nRF9131 EK NRF9131 non-secure" + +endif # SOC_NRF9131_LACA diff --git a/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig b/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig new file mode 100644 index 00000000000..0ece4f9a2ac --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig @@ -0,0 +1,38 @@ +# nRF9131 EK NRF9131 board configuration + +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_NRF9131EK_NRF9131 || BOARD_NRF9131EK_NRF9131_NS + +config BOARD + default "nrf9131ek_nrf9131" + +# For the secure version of the board the firmware is linked at the beginning +# of the flash, or into the code-partition defined in DT if it is intended to +# be loaded by MCUboot. If the secure firmware is to be combined with a non- +# secure image (TRUSTED_EXECUTION_SECURE=y), the secure FW image shall always +# be restricted to the size of its code partition. +# For the non-secure version of the board, the firmware +# must be linked into the code-partition (non-secure) defined in DT, regardless. +# Apply this configuration below by setting the Kconfig symbols used by +# the linker according to the information extracted from DT partitions. + +# Workaround for not being able to have commas in macro arguments +DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition + +config FLASH_LOAD_SIZE + default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) + depends on BOARD_NRF9131EK_NRF9131 && TRUSTED_EXECUTION_SECURE + +if BOARD_NRF9131EK_NRF9131_NS + +config FLASH_LOAD_OFFSET + default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) + +config FLASH_LOAD_SIZE + default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) + +endif # BOARD_NRF9131EK_NRF9131_NS + +endif # BOARD_NRF9131EK_NRF9131 || BOARD_NRF9131EK_NRF9131_NS diff --git a/boards/arm/nrf9131ek_nrf9131/board.cmake b/boards/arm/nrf9131ek_nrf9131/board.cmake new file mode 100644 index 00000000000..8293a428b40 --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/board.cmake @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: Apache-2.0 + +if(CONFIG_BOARD_NRF9131EK_NRF9131_NS) + set(TFM_PUBLIC_KEY_FORMAT "full") +endif() + +if(CONFIG_TFM_FLASH_MERGED_BINARY) + set_property(TARGET runners_yaml_props_target PROPERTY hex_file tfm_merged.hex) +endif() + +# TODO: change to nRF9131_xxAA when such device is available in JLink +board_runner_args(jlink "--device=nRF9160_xxAA" "--speed=4000") +include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) +include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.dts b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.dts new file mode 100644 index 00000000000..4b66e5348a0 --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.dts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include "nrf9131ek_nrf9131_common.dtsi" + +/ { + chosen { + zephyr,sram = &sram0_s; + zephyr,flash = &flash0; + zephyr,code-partition = &slot0_partition; + zephyr,sram-secure-partition = &sram0_s; + zephyr,sram-non-secure-partition = &sram0_ns; + }; +}; diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.yaml b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.yaml new file mode 100644 index 00000000000..d1b04054ce8 --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.yaml @@ -0,0 +1,17 @@ +identifier: nrf9131ek_nrf9131 +name: nRF9131-EK-NRF9131 +type: mcu +arch: arm +toolchain: + - gnuarmemb + - xtools + - zephyr +ram: 88 +flash: 1024 +supported: + - gpio + - i2c + - pwm + - spi + - watchdog + - counter diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common-pinctrl.dtsi b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common-pinctrl.dtsi new file mode 100644 index 00000000000..419e7c8d70c --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common-pinctrl.dtsi @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor + * SPDX-License-Identifier: Apache-2.0 + */ + +&pinctrl { + uart0_default: uart0_default { + group1 { + psels = , + ; + }; + group2 { + psels = , + ; + bias-pull-up; + }; + }; + + uart0_sleep: uart0_sleep { + group1 { + psels = , + , + , + ; + low-power-enable; + }; + }; + + uart1_default: uart1_default { + group1 { + psels = , + ; + }; + group2 { + psels = , + ; + bias-pull-up; + }; + }; + + uart1_sleep: uart1_sleep { + group1 { + psels = , + , + , + ; + low-power-enable; + }; + }; + + i2c2_default: i2c2_default { + group1 { + psels = , + ; + }; + }; + + i2c2_sleep: i2c2_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; + + pwm0_default: pwm0_default { + group1 { + psels = , + , + ; + }; + }; + + pwm0_sleep: pwm0_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; + + spi3_default: spi3_default { + group1 { + psels = , + , + ; + nordic,drive-mode = ; + }; + }; + + spi3_sleep: spi3_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; +}; diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi new file mode 100644 index 00000000000..35314cd0784 --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "nrf9131ek_nrf9131_common-pinctrl.dtsi" +#include + +/ { + model = "Nordic nRF9131 EK NRF9131"; + compatible = "nordic,nrf9131-ek-nrf9131"; + + chosen { + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + zephyr,uart-mcumgr = &uart0; + }; + + leds { + compatible = "gpio-leds"; + led0: led_0 { + gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; + label = "Green LED 1"; + }; + led1: led_1 { + gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; + label = "Green LED 2"; + }; + led2: led_2 { + gpios = <&gpio0 31 GPIO_ACTIVE_HIGH>; + label = "Green LED 3"; + }; + }; + + pwmleds { + compatible = "pwm-leds"; + pwm_led0: pwm_led_0 { + pwms = <&pwm0 0 PWM_MSEC(8) PWM_POLARITY_NORMAL>; + }; + pwm_led1: pwm_led_1 { + pwms = <&pwm0 1 PWM_MSEC(8) PWM_POLARITY_NORMAL>; + }; + pwm_led2: pwm_led_2 { + pwms = <&pwm0 2 PWM_MSEC(8) PWM_POLARITY_NORMAL>; + }; + }; + + buttons { + compatible = "gpio-keys"; + button0: button_0 { + gpios = <&gpio0 28 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 1"; + zephyr,code = ; + }; + }; + + /* These aliases are provided for compatibility with samples */ + aliases { + led0 = &led0; + led1 = &led1; + led2 = &led2; + pwm-led0 = &pwm_led0; + pwm-led1 = &pwm_led1; + pwm-led2 = &pwm_led2; + sw0 = &button0; + bootloader-led0 = &led0; + mcuboot-button0 = &button0; + mcuboot-led0 = &led0; + watchdog0 = &wdt0; + spi-flash0 = &gd25wb256; + }; +}; + +&adc { + status = "okay"; +}; + +&gpiote { + status = "okay"; +}; + +&gpio0 { + status = "okay"; +}; + +&uart0 { + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&uart0_default>; + pinctrl-1 = <&uart0_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&uart1 { + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&uart1_default>; + pinctrl-1 = <&uart1_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&i2c2 { + compatible = "nordic,nrf-twim"; + status = "okay"; + pinctrl-0 = <&i2c2_default>; + pinctrl-1 = <&i2c2_sleep>; + pinctrl-names = "default", "sleep"; + clock-frequency = ; + + pmic_main: npm1300@6b { + compatible = "nordic,npm1300"; + reg = <0x6b>; + pmic_charger: charger { + compatible = "nordic,npm1300-charger"; + term-microvolt = <4150000>; + term-warm-microvolt = <4000000>; + current-microamp = <150000>; + dischg-limit-microamp = <1000000>; + vbus-limit-microamp = <500000>; + thermistor-ohms = <10000>; + thermistor-beta = <3380>; + charging-enable; + }; + regulators { + compatible = "nordic,npm1300-regulator"; + BUCK1 { + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-boot-on; + }; + BUCK2 { + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-boot-on; + }; + }; + }; +}; + +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_default>; + pinctrl-1 = <&pwm0_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&spi3 { + compatible = "nordic,nrf-spim"; + status = "okay"; + cs-gpios = <&gpio0 26 GPIO_ACTIVE_LOW>; + pinctrl-0 = <&spi3_default>; + pinctrl-1 = <&spi3_sleep>; + pinctrl-names = "default", "sleep"; + + gd25wb256: gd25wb256e3ir@0 { + compatible = "jedec,spi-nor"; + status = "disabled"; + reg = <0>; + spi-max-frequency = <8000000>; + size = <268435456>; + has-dpd; + t-enter-dpd = <3000>; + t-exit-dpd = <40000>; + sfdp-bfp = [ + e5 20 f3 ff ff ff ff 0f 44 eb 08 6b 08 3b 42 bb + ee ff ff ff ff ff 00 ff ff ff 00 ff 0c 20 0f 52 + 10 d8 00 ff 44 7a c9 fe 83 67 26 62 ec 82 18 44 + 7a 75 7a 75 04 c4 d5 5c 00 06 74 00 08 50 00 01 + ]; + jedec-id = [c8 65 19]; + }; +}; + +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x10000>; + }; + slot0_partition: partition@10000 { + label = "image-0"; + }; + slot0_ns_partition: partition@50000 { + label = "image-0-nonsecure"; + }; + slot1_partition: partition@85000 { + label = "image-1"; + }; + slot1_ns_partition: partition@c5000 { + label = "image-1-nonsecure"; + }; + storage_partition: partition@fa000 { + label = "storage"; + reg = <0x000fa000 0x00006000>; + }; + }; +}; + + + +/ { + + reserved-memory { + #address-cells = <1>; + #size-cells = <1>; + ranges; + + sram0_s: image_s@20000000 { + /* Secure image memory */ + }; + + sram0_modem: image_modem@20016000 { + /* Modem (shared) memory */ + }; + + sram0_ns: image_ns@20020000 { + /* Non-Secure image memory */ + }; + }; +}; + +/* Include partition configuration file */ +#include "nrf9131ek_nrf9131_partition_conf.dtsi" diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_defconfig b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_defconfig new file mode 100644 index 00000000000..fc77ffe0d13 --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_defconfig @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_NRF91X=y +CONFIG_SOC_NRF9131_LACA=y +CONFIG_BOARD_NRF9131EK_NRF9131=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# Enable hardware stack protection +CONFIG_HW_STACK_PROTECTION=y + +# Enable TrustZone-M +CONFIG_ARM_TRUSTZONE_M=y + +# enable GPIO +CONFIG_GPIO=y + +# Enable uart driver +CONFIG_SERIAL=y + +# enable console +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y + +CONFIG_PINCTRL=y diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.dts b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.dts new file mode 100644 index 00000000000..9a652cd0aed --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.dts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include "nrf9131ek_nrf9131_common.dtsi" + +/ { + chosen { + zephyr,flash = &flash0; + zephyr,sram = &sram0_ns; + zephyr,code-partition = &slot0_ns_partition; + }; +}; + +/* Disable UART1, because it is used by default in TF-M */ +&uart1 { + status = "disabled"; +}; diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.yaml b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.yaml new file mode 100644 index 00000000000..cf33abd55da --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.yaml @@ -0,0 +1,15 @@ +identifier: nrf9131ek_nrf9131_ns +name: nRF9131-EK-NRF9131-Non-Secure +type: mcu +arch: arm +toolchain: + - gnuarmemb + - xtools + - zephyr +ram: 128 +flash: 212 +supported: + - i2c + - pwm + - watchdog + - netif:modem diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns_defconfig b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns_defconfig new file mode 100644 index 00000000000..83af1cf6b74 --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns_defconfig @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_NRF91X=y +CONFIG_SOC_NRF9131_LACA=y +CONFIG_BOARD_NRF9131EK_NRF9131_NS=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# Enable hardware stack protection +CONFIG_HW_STACK_PROTECTION=y + +# Enable TrustZone-M +CONFIG_ARM_TRUSTZONE_M=y + +# This Board implies building Non-Secure firmware +CONFIG_TRUSTED_EXECUTION_NONSECURE=y + +# enable GPIO +CONFIG_GPIO=y + +# Enable uart driver +CONFIG_SERIAL=y + +# enable console +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y + +CONFIG_PINCTRL=y + +# enable PMIC +CONFIG_I2C=y +CONFIG_REGULATOR=y +CONFIG_SENSOR=y +CONFIG_NPM1300_CHARGER=y diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_partition_conf.dtsi b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_partition_conf.dtsi new file mode 100644 index 00000000000..d14d8d95f75 --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_partition_conf.dtsi @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * Default Flash planning for nRF9131ek_nrf9131. + * + * Zephyr build for nRF9131 with ARM TrustZone-M support, + * implies building Secure and Non-Secure Zephyr images. + * + * Secure image will be placed, by default, in flash0 + * (or in slot0, if MCUboot is present). + * Secure image will use sram0 for system memory. + * + * Non-Secure image will be placed in slot0_ns, and use + * sram0_ns for system memory. + * + * Note that the Secure image only requires knowledge of + * the beginning of the Non-Secure image (not its size). + */ + +&slot0_partition { + reg = <0x00010000 0x40000>; +}; + +&slot0_ns_partition { + reg = <0x00050000 0x35000>; +}; + +&slot1_partition { + reg = <0x00085000 0x40000>; +}; + +&slot1_ns_partition { + reg = <0x000c5000 0x35000>; +}; + +/* Default SRAM planning when building for nRF9131 with + * ARM TrustZone-M support + * - Lowest 88 kB SRAM allocated to Secure image (sram0_s). + * - 40 kB SRAM reserved for and used by the modem library + * (sram0_modem). This memory is Non-Secure. + * - Upper 128 kB allocated to Non-Secure image (sram0_ns). + * When building with TF-M, both sram0_modem and sram0_ns + * are allocated to the Non-Secure image. + */ + +&sram0_s { + reg = <0x20000000 DT_SIZE_K(88)>; +}; + +&sram0_modem { + reg = <0x20016000 DT_SIZE_K(40)>; +}; + +&sram0_ns { + reg = <0x20020000 DT_SIZE_K(128)>; +}; diff --git a/boards/arm/nrf9131ek_nrf9131/pre_dt_board.cmake b/boards/arm/nrf9131ek_nrf9131/pre_dt_board.cmake new file mode 100644 index 00000000000..c8267afd1b4 --- /dev/null +++ b/boards/arm/nrf9131ek_nrf9131/pre_dt_board.cmake @@ -0,0 +1,7 @@ +# Copyright (c) 2021 Linaro Limited +# SPDX-License-Identifier: Apache-2.0 + +# Suppress "unique_unit_address_if_enabled" to handle the following overlaps: +# - flash-controller@39000 & kmu@39000 +# - power@5000 & clock@5000 +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") diff --git a/tests/lib/devicetree/devices/testcase.yaml b/tests/lib/devicetree/devices/testcase.yaml index b57489b9a11..673e2319702 100644 --- a/tests/lib/devicetree/devices/testcase.yaml +++ b/tests/lib/devicetree/devices/testcase.yaml @@ -15,3 +15,5 @@ tests: - bl5340_dvk_cpuapp - bl5340_dvk_cpuapp_ns - mimxrt595_evk_cm33 + - nrf9131ek_nrf9131 + - nrf9131ek_nrf9131_ns From 6755c4785640afb19f4973563f9737eece9f57c4 Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Wed, 15 Nov 2023 12:55:40 +0100 Subject: [PATCH 0410/1623] [nrf noup] boards: arm: nrf9131ek: enable tfm This patch backports the nrf9131ek to a time before tfm was refactored. To be reverted when TF-M is updated. Signed-off-by: Maximilian Deubel --- boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig b/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig index 0ece4f9a2ac..378a58fb6e3 100644 --- a/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig +++ b/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig @@ -8,6 +8,22 @@ if BOARD_NRF9131EK_NRF9131 || BOARD_NRF9131EK_NRF9131_NS config BOARD default "nrf9131ek_nrf9131" + +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_NRF9131EK_NRF9131_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + # For the secure version of the board the firmware is linked at the beginning # of the flash, or into the code-partition defined in DT if it is intended to # be loaded by MCUboot. If the secure firmware is to be combined with a non- From b0177d6df95deb539e3ddc95048faa8d0c4b69bd Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Wed, 15 Nov 2023 12:41:16 +0100 Subject: [PATCH 0411/1623] [nrf fromlist] boards: arm: nrf9131ek: add docs This patch adds a readme file for the nRF9131-EK. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65224 Signed-off-by: Maximilian Deubel (cherry picked from commit f4297253a79867a94ddd97d9877cc5ed094a5040) --- .../doc/img/nrf9131ek_nrf9131.webp | Bin 0 -> 75800 bytes boards/arm/nrf9131ek_nrf9131/doc/index.rst | 228 ++++++++++++++++++ .../nrf9131ek_nrf9131_common.dtsi | 4 +- 3 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 boards/arm/nrf9131ek_nrf9131/doc/img/nrf9131ek_nrf9131.webp create mode 100644 boards/arm/nrf9131ek_nrf9131/doc/index.rst diff --git a/boards/arm/nrf9131ek_nrf9131/doc/img/nrf9131ek_nrf9131.webp b/boards/arm/nrf9131ek_nrf9131/doc/img/nrf9131ek_nrf9131.webp new file mode 100644 index 0000000000000000000000000000000000000000..056296ebbbcab5b514be7a6f30771f3b12167bc3 GIT binary patch literal 75800 zcmaI6V~{36w>A2-d)l_AZTGZo+t##g+qP}np0;iGv~53k-g9o;^ZoeF-4R*2YHeiZ zu8OLR9jPQKCWb@_0#FwfQczR)r2zu~0BHX;LNEXs2tZO;SRo(u-z@+%-`d#537ioC zu(5S^R1y~=($Lf*f;s`f0uTZ402%;}p|O*_pn`(Tf2{xS^1K27`HyCi?mw~q?>7G{ z3vXiTWDEd+5dE_dFt&Ge{)Y|zVRkoX`~Tqde;Cd9x1q^DT>THzI{usBKfLxI-sr#a z<$tjGf8qaH6q=)olJLK^q5b2D%>NH;^nYOE-;Or_Y*_!fYLv` z(Es9(^I!f7|GbR;d07CA|9OZ2>;N_Z!~gOJ{O1|`v-v0glUpY<7Uut=K;VP`0EitR z@PP~ffJy=YzT$zvj{+d@s}KMH+X4XkZU4vLE*}8+_4JRA{~wMt4*)<61^`7ya7)+4_8Gf2DovKjq#03pn-x{~h&p_MbzqJMU}qGwr$Va`%yc!8-=nc4W8w zZy@z=tLNFRz9T|S--@rK&#*VdEB?>EC7-FUx)1eN#I?MO-B-VrkG$L6SB5+NX2QL` zYrm5Zh)=uM(IzIwuqz7M~m_tf-YS&-MkUF=CBv`$h6mpE7U1}MMS@U;n1`^lhVO)O1 zMf{kS6i=~4K^vR|Q2F^?k2fS;2K$8DL&^Kks3BYARb*F1+ zUz@4ujr{Ffg>5-IG;XBt7KJzVbcHTfF(2VpwUCm~217(>?su zT}Y}m&@(}vkb&WHwNHv4kB$qgF8+?+27a!n0LarnE#Ss+23ZTfR^RFL;71ERyHT84 z{;R_|E#-_TkNWiUFv=NP!~(Z7`|i8O&1o;H2;_8&e>JOo%AtM51S$KyeE#&siXYxj zTSM2zkW-^t`ueib6YADfoyrnvZ~x4--``5ML&dCF{>NR00(O^39Vr<*464!DLedjP zGq%b|b{2q+o*jB0Yo1m>;iDs<%G!W=)2q%s2g##c`}~B4segW%@Xy-bW|ok4Tt{7s zU^}#f)2^t@(~B^bm9s&Tz+cNkp}A4UUx9qA6T9gol0V~9F6Oasj42*Iz}4+6Q|#)* zXR~P)tCwEN3SNT$iq$@(W=hT|#WwGHAB(ntKN=j;e&4T|K0MCyr3c{=Fl)cFL6@bMITf@!@UYD37d(14! zI3Ic>ra=`?asp#7Q>c#YI|d^KC5`!{yB#EamLoMNf^MYZ>$G`KcFKmrseA)|lf zgSQ=f{NGmylRDMX z(tprBS2OGi%x1*NC}Yz^l&wmj;FHl8G#3(E07t?(kiDxG_SaY%St`hxCoM;sDB8vx&UpT;1A8e`(8JkgT zLDl*lI~g{GQD+>B^_VaWRKu{3mrQ!@7q_&T-jYu0pWBbEMKt^;K51%1z{ig+G3oVO zmu*tdN9b8GfLk8@4~&?rg2U{4K^JxFpM#R^8-r%1qq&PigHU0h4;H|>`$U)p`_VRC zB$oa>`45IhhDH}dxUHh(k@3am6DHN@mmncqT#oUA8o%U^SFZ7a0R-jl0b1xBGo0+7 z8{gg-_1cXGB$ubbx!(PsU0%8VYjUTw5*qbwT~12wSjGu0Gn5fEWSw)FqKsZT?cjgV zjg@Bsg}U8(MC{c-tS67V7{fWBstH6L-ly0{1>rke_0VF*c?rWN4Vwg zEk_D(;Ca&^jh-pA#Z+liisC`WC?qLkB?tVcW$q_aHroTvtM*SnwI6Tp z6jizLq*WHYF4_Ddvab>olyOEdN#;6^cxh0#4l*)F!YqM*0#70lVO_l}GZ}vx z?R||78^<*hUX7D+Oy8us=FS==)>Oe0=G2`22PNr`t_p`Tm1?Vor}uRmYZA=yHx_4V zCfO^2Lle>h548c?B%xF^qC^{Wvu;FpoyJ)$H`E*@V;51~>ATx$Rg0_sh?YWCE%34} zIINp4HhlOXge%eXcdq``;tGIV=Srg9+Y=G+~+Lnk$vO<#qV zAaw_vh$GT`KZG=_$<&A|#ly}hm1lMrbgSmtp@G*R%Ee@ifXX=c2BiTL%_xs5P$b4q zGz6(}KOk9r1@u$&@;8-J3^z2%`e^!LSy^LE(VZ4yFQuuzibwFWzN=-K`S=xt6B>L= zYrD*VVvrH*=JY+zQ+c4>ozx93$BcCl zbWgLz@H0$apZ5OwZ8urEhkg&57E?u!I7*+80a_im7X1mQFHM7&w18s$2DdR0=#-Sr zv?A56v+yp<$nR{Yw{XJz=xo0{#uhxC&@}}&} z5O(9QirJ{qyM@M)HmWhUoj8kFHwt2S25BI48IH*P?6JTvr7(lD(KuIFoP}j=w~5lO+TJ<~B&S`bGkiFJ-~?Do09a(k%Nw z3s}j2hnRnQK6wvJ{|IaQ2!`6lEF0-~7H_(D{p#+>%qN&6KqhgXbq*vEL4K7GiY(|s z1A;;C^GXUrEdB-SMWtmHPPCv5nX#$tas9J5O{2p5tR{c=Hw8H&s`i7?bQzA67|4PFp2)PihNS8l{Kh;&NAT=LQid#lq;vW}Hg<6MgGy?Vg4 z-l(O;+%!bq>J&9%8^7GoNv;0KYU`Dn8Z#zgj5hiei0;BHo3GPg0-^xhAF3cJ{9PfDG5 zoACvimvP8ws=9e}x6ZKZrkP8l?O!rj{uCVHkpNf^p2HK;S&E-q;dgJ$*_+8M`pk4i z7IlScRdZ$4zBT4$MRcgXGhkFsvuMW6u8Aw?zEZw+FQ;TS8$Pie@7^v(c(U5dH%M&L z{FASFl3`sUgcy+)H8#oY)nN6z)NH}BnJpvFQ$nY&FHKc&jOtH<7iFSeXS2gV+YSuQ zPN*9=jD@NlRCE-74F&QBsDl9GM0UC5qIU@YV4Rn1HnNuDNe5P-F1>So4 za@4;-U6DVQr^x<5q`ij3`Iv~F1?7HcFRoa9aTL%&*>(K2-#rt3#5GHMu-wy0BGyLP z40;zf6Mx41aF9)bKDCtH+y=1*L?sA3nIeC=DdS!*E~b3s7f&HXH9|08cv8sK?wM#r z(j`oJpvtB^V)YmeU#r0$0pse}9LJv@3{c?@7F}1{g`K|YQ_z?n)9OjT8d)8}(8T`w zl${wuM%Ig7eCf0&_|e!ltp!O5SL@ofMuN=4h1GET~+H_ZtSwf<-&XrlFu->vuFeHjuB#77} zJp3AdbUXAEsVS3iKrgAJA6I@lMLIUB@9)q&LgTXXz;Zp!Pn$$7yM63D!li6u%Ar@M zE{UT>Lo(RI?L20u5=+VZ1F+K?lbXFhi2rq}{r8eNzJZDzR0}73#6HCpaIHoeb=~KW`Y>v>2?~rz+);qlN*gbCawbD+~pc zL*||;ZbT5*I=9Cq=e(&LnL_}VT>kfxM==+=;AQom^Y&jN!AL$V0uL03aHGRkA*qF0 znopL~f378(F8%nY7v?P?b=0vk3fEJORj+{JKK$nl6k!zC`IS{x8!;vFID0lfsOYwVO^GjDs)ev5NhzgrNsq(weimQ8Ksl zM5FL1H0{S4DsOBE4^?+I_(!UGn*Czby?z66YMtapJ}tX8#b5u`WWIsD|EVbb zx6qqSg?J6*XL+LD{Xsq@o;&Il_$j;mi}!Q0ympW(mu8=cLIDK|J~^BZ9_Np_;Y3PD z%7$sGIbqHuRS_3+Jn_RUC*8->_1lPsj_NO}u2)(lck6QCU|Z;hww~@h+SRM)c45Ie zP2a|QZwrrl(hKzx~?oJ2)7$vyj>L~yW#h5O~>YS zqIZrNGwGe;qu{}4+$IQkb_l{#+eNKmNQY%U70jk*;Wm$WgxjRPJpMDi>Lo0uDx{cj zfj`Mc6Lm8e-!Or(es!d_yE#iRzb^#&9ev9JTXjwA+NX@K-mSG*7P>;U)6nf3AHzN= zOMFQ|x!oMRd@D6Om=Ukjx6z^S*62HU%j*R96cDl_gL87M=Ui>yppAMHDC-Kt-$L%D zq1MRGAX>}kKXPtBH9W-J?p}A`JLJzrPk;RIV23&+7Tw;3pjAbrK@1Q_eo#^3N)MtJ zmP?(vM!3)S?Jc5BN3lQf$?>t5z!rZwFss_7$hrK&jMX2QymuRZj?uE^f+;r`%0lW> zZ)~JefoI}>NJ-Uba=nWA+nzI5m0}-`X(#31qL!uTL{&&Z@~JPq#9)Y+ylE?$%ul?KuM$OfnWL+Pth^j7wWwIc|E! z4HZzX1YTEL_;bSClhxpsEV{icKAGTfT=M5eX;zf;FR2o2;Klnu(h%~tL}*H#WCtXZ zWZ0fatJ~0_H&EbJJ^`QHlBh-5MjfuxD?6ne3^D)m>w@*4+IC51XR;b z%F}x4CF$>l77+6AhjC(cMxNGK>Soeum-DAyusVz~KW|-$VFCGMNQ%?F(q-5{F3}j} zN|g+(hJuTc{BCr4z($m|AMyTc>7#g&Z-pQW`DrSiUw27$81hTY`gXQ`REEhXU$$Zz zi09d>lhlg0>~Rr}Y>_F3KpSLTk*|!i=!>^<5#(#y*ISp|Od+$RUFdgbwV5Pa6p}4) zIhZN}@ue|Vv-BsIS-#V^O4m(Aov0}}>ZFCQ?6p?D1pnK>l^6IXl4cr?t*X}t*x$47 z$*uN}jYCp}kK?>)oZ)P3@E@&lJ#K5zulD08n~jfRo*ROs=eN7iK}hcUsNt_}IyhUr z+tr3aEejj|wlEm!KwMF$4J9dzeH`Dj4=YoHEGfsILeVZOu+pcy&`naE~rk#JF_q;dpSeZYXaf`>5jDqjALRrd$27%H_ri=U# z*xhmGLZof`JADH4y9-(O(b4ovk`F|vFTC}9!K_kSayBe|F9^0++JE*EQl8sVLeOp6 z)X(tK&N>>VqU_5MnjMXg&4EzuQ{z&1L?e)PQZnUAm;@gDa%PYL zR92oAoP6&YuJ@%0i4dQfiMEjOevkUvf>*=JW{`3P{)hTmt`ik(WBSItkcvo8j(X(Wy}d3|*kJQ4=R z>?BsOb&(iaShzO6CEt<neRr1tm#_daE{KpF zyf4&lYui#jndHgswr)Kplqc-f{`=kQW>?QW?$-EMeJ7^kM$>FvBPtUA>MGO7-uYo` z2I(v}sRKlLh1fMy=TAQY9V|)}Ib(7x_umJx({mBKK-=0L`?Rz{kA?$hCLnHZIbK!p0;?id)Ue9@iyqGR5gw96wB%RsNhjVY0XGM7i6{Z}2}SG9{{9%&pG&vK=y9Zu zdoZ2E(ru7^F_xvXgxoRJb?gf`gW}AG33p6P6YKy%8JDRb)8=BGPffNFVC3+d0kUgE z0cPVS!PR5x(JZ@Bk*um8IcW z2?r1b5k9VI!8$l+I)i@hgWr!I$8)`FDyf8p8V6p3ZxwgcV)G;&(Ag^q6+R4TeLO$h z?)O*_gdT{Gx}PCtK#>i3aog|(9tH-zNKYpdM`00bJ$*YcUJZ_@;2l^QzF3REC{9EmR$yZIc5b=idg$&ybj;ZSx_oCQ;3?)yL`)WbbO<{j$rtPKX4SFAt}e9A|(Y@0G>w=6&6ekt9~ z*-TALmCZBGY@>`=^@2xdnl=gE^C-1dd!Qu8AX3E{q31*54r0;*!QnT< zZ&kc)j5~hXNIT-i&ulgTdm{Ks%s?i6iFn$bYZ)qLj04le4$zxgZmGjh7o;^H6--ZS z1mAYr=8*!0Q_kcNOPMhHpp6$M!{W=PgovsYGgDW6oO0ClP(y= zO%6f7gT7z-)3$jR@nuG$n`una$5@Ro_jlbBg05%w9(EvM< zl1n<3pQWs2Bz+O258}nboT5rTo7EN#w{DU$xe&80L;Vvd9z-=9=IXWL<|TNs6V^A_ zh&?o~m_HQyhn2CKjW8g%$IfHKaCM|mYqD58 zR18F5L1cy^P(K3Tn#Cx)S5_1C(Q!RG35StcZpV5=-~8pCD;LPBF3P@wL@ZbZof1dI zbXB9bWVWjKSBIpsL`lEN1nu;z`%g*a%d-e)I+`*^wtpa!E#KQk@~@Zb-}Kd^JFL3O%pX1fbMg(Lgkn`!_9&rl+g9YuSds&#O#D7gwkFs^*84l}l0QW^DOAvl zltRv`&kl7m-CxuV)?pal)ASU`$sEHHY z{-)5{A};E3)!5CsIfw~iqv{bW}AEr&OM~5LsL(e zW-NNvLsST}zQ%@!-rJOuH(T=ufiC~o6!4{}x z*5FGwitRAe3a!sNxlzFs%AaZ-cIAa^*DjM81*8jXj>p`3G zU+p8e2cu*aTC{Ysq^q8KhJpYr*q%s{jz#f!C;m;tZPY9b_vv>gUm5enr{y*UpGPR+{(y2}>;Oho2h77~L3Ubv$M3AKpwzj=f6F`MifV6V!fU zvln7uM>;*`d^`JtCd`EX1vXuL1VN$<{sNF<9gG4 zSdMT8zoIvm7_AohOM-N;lS1iX&9zCrCLW8ysr+;Zn4SSBm{dmoHf{ZkYR`VClY;e9u8z{-- zX&D?W6?z<#FVpJX=Ia5KGkNJT3`4aSLB{7FQu;glKHQz}(Z?*Z>NHPghiYOIa*^tI zDnbKWFmMMmE`nyft1gsE)ySaaM)ji(PkTW5C`$XF)|aK@q-edq4{qehkayy}5)Fy; zbG!p%S@JHvcz@RKrTew}*i=oMmg4Fc7oxFEl)(&X|2t|q70%YuGg91O-c@jR7hFU5AhL)MGuIQRzFElik_|P!qw5AD?Xf#|k^JBMOZ7RzNMD zO+@K1lwo131*;4wQN~O^{`vkTACp)zRx}hZ=+8?Rx>FFg#2t>m15X4MB<2%SDAN{e zknan&3^jK0%?fWl@`0z-am&;r$-)&r@ASX6-@pb8Q&gH)vfXZ#&INxntd!IQRy*Im z1S&EohQp7)0(d}W6`^Z`MHXDS9 zA@=;PqP_>KzYY<7BA!}H-rUk;(P#ViDomQP7wZeUov(xiM-1!f)iw_D1`n5F1PTr= znHW%t4Jid-U4{2$t&irlX4lSp=t2F@4Io1ewVo_yj?|X!puIatb>`Gy;P99?xnyQA z#R^h=66URg_P-LRh zk%#w2|2)_tESg@5SgWL;;V3=!;&WZP`?5|E@iIRr1objfmg&&4~=#A4* zJMD)2DT>doDTF{KbYK&jq3#ekMFx8^(p`OwAjSe0g@z~XNSw0qvTJgr@-j!1YAckH%rJ8EDES-*P)(K6K2WCJbD@fFWb=rudOAL$TG zCeou2*{S3y{TFpo{lqH{-LO$U0a0cKD5b&9<>V@!{9WtuH;#uq(2$?`k59z)(Hxo3 z?DSE#=(m3PAkqRvv{nIuTmY9!m$ar`0j>2`bz~d|DP4egmU@BgVzaGB!wKm#4SrGY=GazBj1;IS*+AXafmUacjy{Yz6)b_2y>m-L__!hRx zH$8Wl2#gv_0ikcH1QQ^ZDfJxyUb-PuMx^edU^1r+D>*CpS_yr)eWnAsFo*AICXujc zcS`5grQAhneKDdni`*R3$SltAlL!D5|K0UH{L@0V%v8!}S_x&&UvK92az%I>q6X`! zHMNNr0$b9m!TD-wXHRwkmr!u`=^3?qj#-!U;a}NTdI(caS#dHIt~TA@?>CR%A>kNO z1!BXnk*o@yadT>Hlwg$iQK`VGLn`{oiZ#9S3(uk+h3Y0Ap?SmUkX-^K+ka0$Gnrw1l?lm=we%iV0T+@bs&zvGVI(PC*q)v;)3p7B%Hw4s4r zQ2JXJ&kTL$;zSwctVQ#&lO!Z&1lGTO7`8kwosanFA-V6U;xSW?W_itoq{(-vVU8$j zc*=ArL>WtH{LEsnqPdh9zpEEsP3yy1J=(mbQiNj5RODUmcbjHje zX+x zK(JUlz66E#bcz1@DIoyA*(reNmIlvWl0F~zyz_*pf&~!p>GtP<@_&9j z9Ox4B5F_|<>qVNh?x1I+pPtd+7N^yg{!B}FQT|p(fuqw!XZr!NnR#97g{@`W8&g>c z-(E1p1DckIvaAS-`umDGL&Kw_cl$`IqBOMj5-`S2LBHC4qE}*8Dg(v*N{oTBJvQlP z4U74SK+mp&W2@Vz%wo6(ty53tjuI{rjY$Mw78!8nqvhB=Xm(kx8k_E)_UJYNadx!{ z_j#WSr^>U^^9htmZ&|s$!zk2MF*UtGyx2TKjzMv5NDeOA?EVftz268`UJ@vHl2HNm zwc0UnOeh&B?4lT{o*z{pPSO-XWR++l4`|1X40(5*GHBSlE;zASNVbXP{f*Pd(#jk5 zoUWxYU3%r|UTv8WP&4>!Gc~b}Xy(kSU8^5YUKLa*1A=CSdb#)z9dnSOi{%OF+f5pd z?vOJkO7@nvMO+`eAp0*ZQ-bWPefSsb+rQ}l+%c-;UUq#qfUB;>_6>i4U`7XOdBzTq zW@e;P#=PqKqp9>$PrW!2Q(Yod)aN8)FJj5AUAQjU(xR%xe_BK%Y z6I&As1TcLzW?I!?a63`qB<1R=f@ek8@`WwCDY8wl!3DWT0Y&1P$$SmO^LVK1edk_a_46kDcCn&2%5#baEL5P(VD}PtDCeu9?_@-7$75e}V2+Q; zLCSNINh0i7k{(poz>h-DVwv&k>xYH!c@}cz!u0W&6%`QG6YB#F93bsLB>rf~=y4sX zkz*nKX@T7|WQ^Umo)Dp|me{wTiZA+bKQXPu9Y)tYrHJR)PYu|byXoI5aBpH%4a65z zLe0*~_RV3)9v;hUEv7seNNfC8>vmv+B=q>~qx<5IWoc7lwLQMY8p|u$z6q-uc({Cc zUJt3vGY56ut~E{a?N;}MKldmG(~I-|Q%87GJ5-* zkHS6Avr4tnTc&*+-qJ!}xrZ<=s+KGr)XqD&rMaLDFP4a}VNS^jW7?x+ZiOU%m^gSY zK~KsCL=J*))U<%YXbp95O;RZTgecs1C_C%yn*A9;)KpRWiC;l9=3ju!1fR@dtq|>s zEZt5GO=Z})s@Wy6Cyk(1u#iVOF5rKH~WTC zSiTk0de3Rkb1&mfT=6lYMAu=v?v=hDTqcmQV0Ug6=SK5d;zj+qQ z&)=O!!nBXLLUk=^c11f>ZYn&WnYuFOu^L=_;Xn3klc#RueX@jvGI7k0608*G{@ zqn}O94dXR(uS{FNkAuuu{bDv`vXs!ji%4=x@QHpa<>z7}BDYoc>ddbVbjhtF+&6(Y z&$pxL1L-UK2oMRPRj@91e`ruz8IJ9N_IJXY{-F^X#-)1hKIshY9tAgusK9Go2w(bb zw+yk+TXTNz;E5d;Pvu(D2}^m+RqpTy`RVMu}F-EI~ylet(42w3? zgE~P+O4u{Ir{W>eg47LzAx;GD3ZCN>1F=X}H-b$t4Lk+Nm7{_fK>3MiZ!CzcxMG0| zJ8{YJ&t+a`^2*jSs~>uN6N@_*#Cl9 z;Ea6C)oj;XxaJoeZs6s8q(P+}7_jrFzGTquaw3s-?dw`BKCeGg!_=yP?G}-3f6)lW zxk>DnnA0ixLFO2)Pq#w1eB?sDQrDc0ouJDLaVF2ZU8vY@2*jHs#h_h!a5aX_1fzgo zxGJK&lvfj6tYuzI2(429m`Gu7b?>;0Ohz`i?K`N2*?_=st#zk4#xSuowBY)N`>K?X z5fap_#|+nAzJE6);%T^5@F7l>RgBkL$yu9XwXxQt@bk|@qASo5I7Wq=a?iShZd(<- z0ajg_KRP|4lZRodlAchEe1J7`g@hJc9U~UvlGzhO6m@_K@q<%`SH<`1^FZX0{;6#1e zk^p=_^X443)zQnFI5`<@=1#)P4dgdD-8gVee066=)ka1+cc#e|U=TLpAosM0Mq6NO z^uAWF^5rUeA-0LxS=TVYb4~fRVikTwjGGn*UY@q$O2g+bv$m>&v>Tx5F|m%ZHU!7w zgYo2Vy~jp(3XMpWB0|49=8}awD}aLD=&-SEwL(@Kx*4+4jC>(-GyR&$C_KYVQ~3CN z9NfwvNQ3tyFjM!apUfcyrnJBbwG}#FWRzkTZYV+%CLGts%T&doU*S9UN|chNDDmLX z3zM++8Pzx@^)~N=bH1Y6W=j}Bk~}SA5FpEBPcqr>0&Bae{o!EP z_4N=v)~K&OeMBIWr2mI_r4dxSVbmcq4m`UNw$In!6shOc#{F%OmqCJg?57}n`QjO- z7?~%yE+%I8Vjbvc+OC2&H@)jcvIwjAsmO#iUb0Gvehlb2?!boNEpi0Y>^+kq(WdVo zzF(qwLi{lWeEPcjY^090kvkWyIM%s$x9ggnUWNk{>5U_ca?&*W;cB^7n2e02Zr&(< zNz-kRkAZXa9dVo19eBX^aZ6z&orEXJ#il14-^U8b#Ie2VK?t|nVX-s4y^ODVbnf3X z31sA-vZG9xi*__L4Lw(uY{WA&!>yc!DjuMCZsr&6zyQj-ALEJmGb6X{r_UXt?rOJR zgZ4xWmJm!-^OyXwSk-tu(rM@Alpas127~!*`xpz3c((E{WLuAtG4fI)E3X%bgg?P; zK&a>7FEEquz+{jhHqr<`tMou!3%0goZqMU(BLM?Pa!6~%(4?zbPoYXiV2C=L%UJRe z6r8Y*Wh*BOrjkRg#y?X?qJLTbE?s}^6E+1@KDw8<)Ov@~NXL-FlW%}(bX!T)T(S&3 zG~3IpPDZ&V-m&4eZ(u1>5-m~K@AXU-t|9H!keF=d*SYRyG+_ws>o z*90m+*uGz{Kk{R9B+(76B2oz(HA3Y(!+0?H$QM9p?2gA?2?>tTNnSlkHFffJXJ(rCY{EeBl=CBSv+O&mK3|5Wc{wx zw)pfmZ(Y49p*=;^6@%Sam{R}huE@i`612?ozd$(2HnB}VD|I5}B2)WaN|J4XB>O(E-J zl|bX*n^T{yhmLXV?D*u3!Kfix_8??Ixk<;Ftf6T3*qM2*yKt0dBhTH=BTzg9a~;o7 zp{k4M8g|U<0wxSZlvf8A>cSw8G50Y;=YSfZOMO}&sfg}U_xg8v2LW}nVq%&=r3c2TZzz2KxRtg$^*yG#+sH!;8~Sb zD)Fj^U4O{8w#DcX6vB>#YKksHrr4U1)Pgu`xFELqa~@jahx@`$V%5rE(N^O&Jd_0! zS`<#h9GrR;n2O>rs3+WzsoufAt>zm;Z6&>^k;*N&>sG?7C$%jowl;X!Pkf<9Dmo&E zcw1MEdm#c@*X2#Y+I4=Lm4iM|5>?f_k?TM`P^9;x_SedY5;a8w1wR+zUv#AgL|T_~ z4}1Pp>-Rm5dGxv`V~>(T4f8W77*osl7Oj9d%%VaKry>8gHL*O&$4+`#te=jbztn66 z8R&R+0)ewlkg`>gZAJZzDMI9GEp+aG$Gy9%!L%15>a{GrM!DHV2w6SL;76prsZPau zM&3<(rC~-G?14$HIs~$;&D|!1*Q7Fpw9i>N>}$455+e(k8tuY>OnQGb*fxLX+L>=7 zB#jJp%s?U#In0ogYwHTOCJE-Kk5-2Jr=(^XzUKNzYk$)B=`Jp}oM@W9w=dBU2&%++xs9OEMr|&;Fotnm=z#>fjs>J$Z+(bx z#pto~#Xn{)Uhp)`)e@XU#D$`GDAOGyZovM{8OL9FQz^P{FYr$LhismLF#2`LtxDgC z-C94|Lm9VXmm0*p4(fzI%D&&8cYc9N@ux`IW--6auDf#f;~M!Pkdv|w2imHAnej$a zz+^I(wP*$2RA*%}W@M0Ri*G&TdO{E}%kqT#Ex~`Fx2z0qcqByLztk80@qxYW|1mD3 zIKK8YFGrY@;7WCsX}kRfd&)76YTU$CnNDgKQX!NgvWGB)L%k13Tiqy1>0NsE@mNCG zzmYzR?i(qN&LgXoDO!d-C}C{{slx_%;D~T)KsjD`OV(!O$kRzGiz7~I;Im7k$A!r;24N4)yK5yD z1^8-JlOg;>bk76SOZ`F5_Gkkkt$r4L*RTs{m-Xt2A~G`OYb?pU`5_fh263)}ZRs7* z?%0TdIPhw6tf4+U&xizfa1wir15?~+2^v$Y52&l5|2d`9tIXyqq+sKiAQR|QWSUE% zkfk}Is!u)sE7kqb9#5=%DHdsJKqs46-&L1EM31Z^*9Sj0AnpTtx;pp{4hP9GVMe=8 zovn9wV*W`2p?~%J>22L8e<{-fj&GkM^t+!iY39hU(hi;lmF6#}FK`!F(rpvXN{8?6 z-XdMKO8TWf%FWrwo5?~$dG3t~{nwy%IJHc^@#mf7)zAG*j*e>nqgx{_(V5Z=srOzN z8rk=csFt;b5%h`5JejPXN1i`r^IECvIagjea(KOMtF@D%Jg`J*sCYay#0O%rWF{Fk z`Z9`nUAvPikvQ{GF`T16k1a{03_29`&hX&il4=zU%2NtyS1%M1P}Mb3tIS1k?M*r3 z3A})Pp#JG(FdTydSHLvP!^T3X#xTLR{UkKzGzhXEmR>A7+bTC9&lwCi8hM(GDr~*E zgbw+GQG(K35BB!TEr^r`K>NF08YNFZ##r#hO4ZZ+S|?Pj$Jtn=3e9v2^?6oNZXQXm7^l>q@0-50ASh8}(MHRpGjZJ4;D zR*r#>rqz_oZO!wGN-&rVHrHxPsoXdZ$rC%?6#LFLpx-xt?3?DS$64BAj`< z;=xD2Rb(eqV=cEo4B#&QTAhq?>-O|<*BOI@sKJXd=1^#LGJ?fQVg4w@)l6%8^tfgl zKYkzBn0xqa1oB|hk|KMeT#CIcvZJ*e>f}}0NYmzlzhx7?iXrvEzWA3FCHdF3J_#c} zeltG{$cCGb%h@J%PoYl@v94SJM7WD9y12KhaBb1aJ#E{IPnI@P1|`(hcMY*#8epY_ z3*@&bD8F^RagGxj#jyXkDQn1D&S96HN3*JO+uW1bib*Jj-i3wVO+&F$$iRDmQ^~>e zoz$DQ9s6%e??dZQ4IV~=J8jRui*A)#?jTJ54vz{4KGRSaX%uj&5E?wRxz1mEb_4WR z`SZ?XJ_t^W3V*X&su-gDIa8Jq-htX~H|2zNHo0Q5$&5iL?#G!PaqM8--a7$SMsvMR zHc&^}xdc=x8?(9df0t2Qg(-{B!l^!c6O0Fgdj?MLvC~Xz!k2=uz3P=als9@rDrl?x zApO2xEwYB1bsQ*y6ucz9vkf=D#bNQkp6hoApt^vd%6L!-v z>x$E-t@r{QTGQOooX1a`H^$w%rLH%*2DM_+O8R@=ah|}4c(yRQa?nKh<8Nwd45YZs z>zx@aD$0FxHaB?cCCPN)VVzwPp8heu)JrXU_}vWe&{h2|zxmwBQK*n^GY3n5P^NY% zt0Zk*ChcCBCv&sm<~)I*5-yLrnhvQB?5P(Cgo1STi`fn9y#YbKac$=u4gP-qK@R8TA-d$O_U0Z%Dl+Njp!={-*7 zD98xmLu)T$hP)ucK5dU-sQi$zcr_E|ARyxc2RZrKnUe2VJQ6ybE z2VJqZuC|CeIixFc|KRFHOWmu8wsMX!5YR+BGI>d#lwaG7xyuZ_z8_fm&6M;&0rC~Z zfaH17R{-D8sn}g)b>;@d4_YN5VLaGGdYd>EWKscaIWuU+&ujr_-w+N+<%(%KwRRW2 zq4F4PGWl9G0awc}2uKq!k9+V1#&*t_1p#&qt%JI3p-9}=;FgQN?5#O4{_018 za=T`Nn}N&9ZX%8#@4z05Sz#Jsq}G4g^~W&AwmkdTjho%?2T@sz zx|%5W*fF)Ht|j0-?EI=horsi~l_T!FG@#>nSb?Rc0S==+qu*Q|8r)}@6q>COYDLOP zQOywa3w~4nM-$xOZO1J{(29zQZEU`p34rv*8^LBy>Kg7CP?13KTNi>dV*Af%Nzb<@ zwch&y`L@*yjCko%ZF$ZVnGCE9BrWny*Zq0gpOK(_P+GoRI^IvJTdpBt8Au1_3WvuS z4%qK9CkGE)9f^Iu0aOHRZ@$|g4M?2D93AmBskh!;gY)KNU!{K$FKbc~?9-vtBe`pl z>)0A-A-guUCYH-0y7iG3Z$K70ugNk}?Kb)Y+yaeq%6PU5fsB&is2(1bY1P$<2CI3Z z;tqW-Ns5E0^CYp-k)#JxcqPAxa!lh<63Y9RI{H#Kcb1)2v z^%!Oi^ToTk<(oK;UykjA7r=ape17WYlRK(+$O$_I4(r25zLBEjD|jMZjj~sy1bkk| zs>aqK-nIY`b0E{X&^XSI_Q~3tf&o1lAz2P^>AuLAzccH+bPlSwzzH239tb<6Q(#J~ zNS}vkZ+meIGYv)Mllbr=eCq7KS8lQUKM8v4d~=5ZD;9C$z-?`C@ey&bufHj%d#@PR{z9U%R$h0}zpq;3S_9zikuaM+sdJ!o(j2p-!eAewbxr?U zlt8D@uo10?D}zVn2sXv36?8yElYq`L1c)#HtWUAb%L`uAZ)X#9lnP;Qd$hBbEII60 zbJ(!wnstHK4JTQ;dsgV>*KJ(bVocd^6_a4Hh)}(GID{6i^jee~AEht8n9N~rG^hBu zyJ-4Pe7|YnoIoi!&pZ#Uf8k0Qk#bGd{y^cbgIQyDVJi?@B3T#Ksv7)kMqdA~!nh~# zD5X$!k51iD`AA2AK#L#*qEQ3VZe$$+-L?;CeYO0puk2tNkIun-C0-Mftxtt4f9%Z- z?29G4xVspQY%h0j<9p1nqBXmtDXTT0#+VT}Me}Dp)BxFgIndFTb#nFa2i(9tx91uU}i}03IR$To~;EMbVI9e z+BpR6?wVur9(&@cUV!sUZ@DbYym(bg>!>O&p{~{Gh(9nUL9{)O}?@a4`)giu@m-U!F}oJWI@i2g70?{ zhs;MV%V%W?5#OY24<7Wcs+4!ejo~*Vgzs9Hk?XR_{FOMLZzGdALW?K%7Vi#JFWHnz z4<1~8C3etXlc^d=cT~`EQG_WhG#ctD?tw}(OVfG)_&5@?*a-l8Bx_~=>%|Q^ACZy~ zvt<+hQJ?(Jdi^O0H(V7%(%UD)77Yh0v8kbq?m6|v9IrG_aY10|GC0R}k*Y$D=GPP8 z0Y7Vrtn*NLRjF6DnWQ@$F@v z!a5X{{wb0V^tX`yZeQY`^xQBd<_I|_KAmkHm5B%7LA`V|vfUlh54ke$9F)OmGNaa(`#C_ER_`XLYc6%(ctZkhUYYh(EIP3k4k2 zZ*hwZBKc`qz1r|@IpSWv8*(b#5J|pG)p^_cx44ZRi^=Z4X;)v+j1(8$vTf zsg-)@*(jLo0+A6|i$HAz0F;93$fcDajab007`Nhx-|J5sYT?<2N$}4TQ$)TYfzzk8 zYEy?`{DoT~I?-AXLF9&pp>3mIx(JLu;`68OBA$=Q(mWbWyx!D{zNBax0vjWctXlzN zD@`PCgu>oGv_v}=%7SqwWmxQFg7Livd7F6t-Z>inigg1_zc>me`x3=%j5giD=Ccye zqGwmg7u|`pMOAB;l00$_eieR9|Eg z)Pz1O-ms?w2~P32&lEWC__pHL?@0lWDkVxz*d#z9UWU;D?V&g(4mUvtqg8+s1q0WF zD*&n4BV2|i@pH99%i7|*y)hK{i=5<+;0vb% zJz)36@!PTULVlHWw3}|ph$X!#3!o}=i$bA_f3fmRCA$^C1_|dXA?!2xKCHHIhW%6~li_AejY`mdJC#X-s!Mcb1 z0RQZ@niPlO(MnB@qWdJn;qZe`zlJ{Flfw;z?i4rKV@=B^n2*VK<@umiB>+tD{q;2+ zKer!wdwnxS+R6F9g^q*G&fzElc^{X~4!)V3X8N&|NNWd#sl_64tK=M91bnJ_dr4^g z5t&$Yc6HIWG*Kot`ZPK}1CFLoR|y-sAE?N7opsIDXo24tv?t?`MiyA0#clieDwI=R z1Bjj-4ztGj^4JESRc!%JXVaC?p}v0M!Pfq+wiVuy?jX_K4HVDYrNz)G{V_pJpGd=N3db+sWlx@V^e1+#1nM?8)uu?Qd$DZ>TB?JWlI zmqIaEK;?HrKGyKlfF0X;CtfVd}dNl(oQfWZUHz z+|Z;^`C9jrog!rK(ZHWolId7Ov{4*(D zp9kadlVKaSF7wXOwGuLaqDOj{tOF%#MU#2w;w^!hg zj)vz?FisG@H&R98&!w03*nciR1tA8praGRHB}+uWIF64a+RmMORiWNa7)S5&CSn-m zCCJ6Jxir}%)O#sZoYESc%k(Wha^j_XOmu6C;tXthb1Na)*81b&zo{msZ?L1@b>LQ- z{Gg~|oI?_pNe4FQB_b#y5X8W5-`=5ihM2~|?G*Bsobr1twB%9SyfYKs5N60HzHu?k zUv1oWy;|yCAXVxtEHc!fRGU#|nkJkB;-TSfJWGj6b*~)OkLBq|sh`5ug@+{vWy^~4 z#!#bD#-(yZ=-2C2u!gL9?gidw;|ka9TYXz} zN7gWib|F+Yz<|3SFfX1U`rv^dS>^_On#qM`Mp76pEN;xt)h5xsogHq!kI?%)reTUl z8oRL3*YwIsa4Td#w;=7VTsG2?xp9h;))JYyGUW%|RjjT_WD}5GFnjqdj z?dKVwqi+o^?1-g^)|GINqA)nRO-h{0lYf)1UdMbSigWc#Vhz)hlR2Kr$44d4xU;0W z+g=ucw6ffxGEwWDY-|jqV6Q}~JpsuRXGXmP%Iy8NpylIO&^D}F{~_0{OrD0qj6OTd z^luI(p(s;IEd3FarhoR7ind@uO?GdS}NEo&Fa2ezp;p_I7v44ku@j|xR~vr4%fHNoYmxFkr#HPNzN&PVc$sA+k1_MZp?;isN%cB}yFrFLxLKlr6wb-wAPeFV`32`Sf(*sj*5$*){9SrB$}^X#>FPZT%sKWMQ^az| zvpE^$EZ-+_Y#P2ACN*DrXDmCgf5M-XeUaBAdv&5k$Yv zL7p-x@;27_P9dnrihZ$el=uvLd0qA2MasPE$AcJ#y)i>jzF=UMMvUy z0^-tH>FIG^2gu^Refg}}0NOEgWl~Fa%IA%CHUweqHB70S7KylMJAyY>wQ6$6cDz&#JQ!W71z zrv?Fv>asEa*9Go+QK=3%ljNTVIi6>2C-|DgddIX3A|Q;C=>v{~Lp%Snl(6Rr}>-Q~b9X z-~vyhN;VgmuH&!B^`kRAnCQE^mU`Dq@-2~f{m}l?xgvK{U~vMpapEhA$)OLRdFH0) z4feRMbH5=;AYk|F0#1*oYw`nH*HmT622uJLJ44^N}* zONhzy3lCb!y2bqmN2n1GSiPVn5)KLPxxd`ZhdCoBw%a4MODr3I<$5d10Jv~hGvog8 z=TCeUP1YL=Qq_}m{J%fRWmpAKmZ1rlI#vMT>y8I!U+hsx19n0STTGik{c4`o4ZI9#K`asg6jv!b z2#z~IJ#y`F=%4!y_&U+eA#=w8VQ@LzFWm5!Ek$Y(h?vCI77IZMJ-GmxktiV_ zsIzAI3iYy3{Yv?xTo%@0#`;i2GU3ZX~ac~8IUWXFcg3N%$UdAK`)Q;alDl;Q|-nBGm}^zY0)3M!owOZz{ocog@Ibj6w0+LB|a=ACqGYOnX`W_2T50ps9Do zEFv8D!t?Iskr*xlv30MRiTzG+&3cQiY$!-Ph1nMZL${USIu!y~UhH2lyyBJ;Znk)t z)}L#{gxsMqdZ2ez%?KkvA;+A>phPq=doBeMG^v=d37vpeRutUx6L)Wp8#M3KPvw5hu@y=HPO^Nvz>qf zEo|$uRHxP9>Gspf|9baA5V&|Y>XKQ;gJohdUQ1;edOLp@2~OA^E4?&LRxwffM!z4D ziu~@7QAUT~0!Kz{fgH_?Mc{3`C9sEw%aeAz;e`8z**t1(|0p&+S8miarPJL%*vy{> zB(6N8+X%EPiSkq3t&I+?XB_F8R{BbA=FnDg^_DoCfpC#{Z}(OQrc9nS(}Gf%hMI>A z^ZGQNEgg1cxD8;F!s9cY7HW@QpILUmNB;M;!?tq+x^j}QJaI8O-e!eX|3%gOj0DMa zHiQ;t&QZ1Z*r0SdCGf(gfHXPjbOga}o{`}?_Ndl^b^PJS8O}SU^}J@4Bv#v9gDmPg zOLlU_*BYzG!!~b(xfKphb>GeaX1v^6aib;t*lDNWcXOa%hj0nML$-7)=@DAKJHtx4*K7HX=r1OkKLhYIe`$8f5!Ac@=q$508KmERca44*Mb zfq@RvmA161aUEGsE_dq%V*`BZBQUJ(!{WR{-k$tfM90Vw|@TltA zPi67s%{adB_=M@{R4_um`lMXQr1p7D7AtBLw`lw?Udn{x?6&zrLpL0jt3@iyyN+|_ ztS9{7hC+B6Sno_Q2!}GZY=UM9!Zp2kuszHBG*T@|o{U*RHZq}xVd;56JF6vk9pu9~ zeiwN6d2PyuJt440wgHPa@(PDpH!9rw^A&u&Rd2D)y+gHw0l#j4W70=aa@6~>#X>m+ zY@3{D-?l4j8Q9f+<`iJeGMvyvJerHXK+^+X;i)vuuH57VYn> zT~M9*4K!MAfC+Rs{Vg5D?dU||GpRi&nkSY!On;F>uk5TP%QRQjCj~;3p{9PsCuNe> zSv|)5BoA?wdg_$g=Ria$S<9DMY~oS*Yr>ixY9YH(?t(-#(35v#HKH(~04pta2CV}m z20*YcN9h2l+^F6c9{ldeca_hHMc#7LN!MHi?~J9W1qtsVMv^YTQR(1B^5E@CrU&_U zXE$PJsq+Sxp3r^jF^L|(r%@bI+*9|I&@6r%i&fKW5Bl!Ji!-A=eQNWSAf=)NlQF0k z9W>f+<%}Ge9LY(~ugc*JeTB5ZS%)r|{6K;_70Ov~*?r?*nF*Mp4t*){fQj`S%?$P| zO}Jj^N9zhw;@d@8ATq6&mpJ{X7XiC&4=Lo$K!f*Ae+SN_n(78Z0XW3Au-ed#!oLJV z;yXgKAe!rj$3r`}Q*75vLy!NzMh3z=5XuI>k+w9z_h8zLpF?XyJ)+tFSQG(#pus_Q z<9>`HgIIqZ2(BZ`YV!(H#vm;#13Y&$3J7{+DcAcdA4EFJ6xP6AWX5?QY-K8FEL{jK z^tG*YQl#SJn=F80m?{bJS3D>wFcG12B)qu5OfF^>%H3(hv5A5homNpyl76TH9nM3y z4roBZAWH6Ke+Z6`0#r$vJCa6QA@1*>9kXhPaeOKBUw6FgpP zxA3YS93Lz7cV2W&y{`Mr5HD)N(ELL~eve_k&3WljewV9p?6mdv?hCNG7o7gz1UMng zts(O;V+!>O!HB5c@+NoW2oCU%Nat-sKlMxo*^mylaAIOXqxUZJ?sVRnQ`*l*NKeOg zz3(s{$z+d@QF66La zDFBc2%<`9s&ka|EmaGn5w?kq~S3sKC(zt4>=}e{lnfLFy$QklKQp9Cj_0Z${_i!{z zcQp%*Xe@Li&Ig1R#VneTCyU&A^Hw1hu9+PSmG>{;$|Ng~>1;8-Wofpv44@SUqjKO! z;&u;YslGApQ=VFGG&&f?p1y4LFA*$z7K!htQu=ledGT-J9mU8$rny>JZixB|Xm)>} z{hKd0vv;(s51tz4K4Al|$Xj8o(wD?oTW?AmCwZH_9=dkq@Bd|`t)w5(d?V&b1s2;v zDYC*+gS(n`-<+O&09IeK&?WtP zdI2Nd&OYLe*4XLN-rtx+K0#X-a-cw1@uni)#Jrf}{ZfK94F%n5Q{RM=Do@q(O6+?$ zo;3S2F6>JG8WgIhBe(-twiaI|)X4>DxP`^i%G@8r5qMb&C}Glk&51ubtnKTj+?ykm z?U1R}VW%UvJkGx7U>Q1OXk-k^r`((J^2!=ymdU;=h*=O33~aC! zWnHDwH5S#m$8zo6|G5fNpyaVj1X1GvyeuMFD=MvIO&?0E3*MYgo5xIm`yqU6 zd?I(sG?r}y!ItHAvz><+tU4X7C;>pgSWulOyeu(H>8)pI;X5cN5-|Rdu_}K|U}M3L zT0I(@?zBq%1zkMsJ0HY*sp(7jDr~Mkg$h@Q2b0uW5c*26jjh)j?em(rY#A;aA=|^p zNe+a#8vt&y_<}oS7Q4)K(xGBShxtX^LMWbtG)ER?bwaa#Z-4~MmMuEpYcH@BR*X$ zjQ0A;?GQedIVW5(37hjfQ>39GH5Zus$@2~_2>IQp+?59OQrhg!nR5jrFZBRx<32g% zrR#tfNcGQ~z;&wKkD^7d@J?WreW2W424GZ?gm><;F?Pf=ShmI0SK;c6n+#R@?+GZM zX7xlgy4c3Q7bpSxaI)_6iJWo=8JIxQFdlz1y`aq}SWFm0HS0}JUHNLW@xa{y{*3H?(PQdzK)&tjVt{9@5s%?28u`Q8jnMmrtyWXmz*V?iC ztl=Wc{x67iA^Rxf;IpfXa_OIAW?0l*K`2U*8+?pZu~GVLWN#L0?5_BwX@yyX=AIB*W0#hB0PqEo)j$Viu=n9TqAy}u~jYp(T<}T&QbGyn= zw9tfExu*2e0yWGzR~4soHe1EDDKX>B{u^v5=!zD6oR z@TQa_WrJ9`d67DO(-D!RZZzh_#DDrvY^jXofo0O+Q?powF$e*r;dGXecqcmV<$?tF zR`9*GY0mzh)YJZ0oX^Yrro11ywH&O$kGIsiQQp{Eu%^XSAebPM2d?Q5_{*t%>i>O2 zhjP>;m?9XJ^#L{af_pxB8M~x`hYp1eP5&9DN6?gbOv4X7dw&Gi;wW;mxce{gu>vY$A>g0ylH?b%LY6In4e#)ts0#i@wECL#)1iyz^ce>FLgsg5EWXArD zyffD9k(o!q&pZ`dFA)#4Lar4unXF;s->Pi)CR-(xEJE8@otmH8>hC?UydM2$+f8da zMl&$W_^{e@b9$okYxh~L0n_5Gq%6v_#ga#|jiuu-&+cmh(EGwKi8J(xT+XWYks?$* z$Uz)aiuyulWQ=}9To75?zzLhMNpoep_C3zc?E$ZWm^IX*cm0vf;^tIv@>NxJy187y zozrRIT*H@ikF2p_OX|;xZN;wG_FM>}k-QP7`O{%Y{Gk0%o}nwvY;S_3a|r=g8jj{ z6%KqXKYDN9!75Gz)-su)4^@F7G!2}TFJZR$!q&La>ixi}i;gPoFezPF-0ReQ$7SFg zwlb-bu<++ECol&pylg;(2Y=^4stI_au{*x64|jtt2$bZx?1on{>;kqX{_1NJ8T=$j zw4Aq~2vxX?5NayPT$Fi@CM=y^qPF|nX^R26vCe&^8(&x&~)f8u{d5M;1@V zHnw`;hu7|;=%%=wLLt#VaCjwX@L7)eg@7*DwW56BHA0oBxmxoTJ@Q7iU?U#aCZyLJMJq=Uk+1In`oN@iCYW-x)*jN^60e37oWOkEW4Y?(8 z&N32}=@liI0t7r6!8 zVEHcD5^Vf$&Uoj-2$nlFUN#3C(9oiu7L?L+v?>`}wkvvR;%3OB%!K1iHjC>?W^;cx zEu)?Wh~h5Gi~I=bsdg2i;2NaGLsw1jE)r^VbK`k~^ zMPK-Bz8hbkZr;n&h~Sq`1xYvgsPN%!gS!*=>a3=QtE!GB8?woQ`3 z$N(piCwtwsTX20a;~`ICXXaQ-qPD;?+hYcoxMOS^JbrYnRjkNBVy{;m6<3VJJZ{{- z=|V|DYu2o7gGC<06k|%;A$1}g zeEMN$Kh6OL=I8}G=$)1wIRm`=NIRdxgESUs|3r#_$1G}u;_f!kyu_WRY;)@0#;{=3 zo9$QFDU;7e3e~xU(w-2L)}swNW)xmD+dtnE%b>KEMF)h-W-OIX)C!?g6!KI$n64Ix zCF*YO(-$5e1uXz;Uj|nLU%LPC1Rr9u)Va9i74gARp{AI1$fGq65V0q)d*snLQDe3J z%AFH`t--MS3F4t}uk?6p>^p8Lqe5Hzl{8QHa67Aklm^(DIi2`NXuKI($5@DC zMA~x)`|;z&*edOL;1-lWJD6qk-PF|}<~fNOs+#tM6r+!bmiYP0WP7Q^Tgx;zjXg7R z53e*OZt1PpB}9S3{5FZl$;aI)$vZK74gf&Sgy=5r6{v!+`Df2j>*!f{^63yg`Ch-xodGcsQc9Yyj9sRnb& z%(2_i-7g*Q+!*;}OJl}7V;kv)U-;|gCvf2`0a!Z?Qp6q(%LTxz2XdMvMr9fWHG`#nLIBO54|QQR?Af?{X|Me-Xl z{|Dca$eg`RtCvXHT@-|XLdC_30T#Ws_5dryZOFyUj8<MWx}j3o0`ubK!?L@p8w5EEZW=rR19cJbTLtB-pw zvw^8UF{}OjmWLFBY;1r^iE+i9YXh!I^|D2!*});y`h#)Cx0S;Q3Bs?YSNVbvMA|^{ zW{l}HtjV)%Z!UGTPbK zG-ofIB9>BS6AJhkce^k6K&I+TccIsQ0c50dav0(KN+x8g1Yap+A-JIyLd<6SM(ymC z4qwNRouOGMt|+!6cD0!3AY6)#3j;{Kp`|W(kJZt(T8q&8@v$pBE7~s`Wv|h8jitsh z=fmBgpEi@rLe1?9OQZlG(3~C*6_{z)vW7u3zUG%K z@0|-U{wOWDd>erwN=6cFF=FC7;gK+!L(ltqHS!@LKieWMYkC%u=sNn429WITbR6Vq z|A=KcZO|JX!t-^nsg$iNvIBdJeowT_d3yV!S@RREOw$t&MlOtDZicC?{ z*iE&Fh^Y~e@rxQ};6-gu87ws+bvoO@tJ~CLK2rH`;Qh=#fE^>%+=EUYXlM!*&O2P` z4KbZ{yJ+!nT5@hgbxyx$druw|D|+-1AXQBBUdq_hJrTJ+2fc3p(d&B#0^_m-L-+@(u-DL zR~w~&lz?_#CLstW36X?pU_~biRJ8G#R1bS(v6L)ZH-I@{IoTwTpHM-7i@EVtz_K zK~&4sR$RLbE-{(6b5*0R3@s$&@uXA(Ll#{_u@hC%iAVT*sv5;rg^Yu1ax&e_40y}o zi!PnB%0ZC8(MS5$E`0r(mxS3NZ;lWj-1oOK%^?JjHetM=phdzyPeV~;M5vB=Efslu z>VfnSEQovW_d7s2zB);;)^3)%mEN!%07+3jMRU8AGM9kpF0LYPbk}agee@@}?yI?C zY3RDAMSZlGtkck|gI;$4qgd(SS+9Y8B)vy5@)mBhd74kRbBj{QHhn2I{7D5K@XV8% z*;SNEq(;nYr~j^Y$~b$mjrI4^M(_3tge?gm(GMx>EO0Ub-`)X6cqVjOwzp4+EBGN< zW@aIVi$A0yEpe!~qGb#yLg6QoBS%9kG30yh5$yaHElNu5c3<=Nv4!0sx71l;6kvPx zLx4RY`1>cfc*z+`ML?#2zjE=fBd~G_20dqteKz>VY%8q&&(_=u1!QqZj-u`&y=+}+ zV^4q@8y&fccwcX+a#7d7=vgUJ5I%<1*v?lC{mKON(n4f0*_I(vaBY{Rv_%(v2lOyF z6zuFwW1P6*M#3!A@n0pXC^|(O3gbn=PFkJE$#@`qIBlH99XVdjt$ULy;#p?903NGQ zV^3IAZ?^ki+J28)!gm6ouk{Bv_^}0}6DcjrLLn?D>-8wrR!rJdUQcK;e-6 z#kA-pOA`BMLEn??-eL4&2(73&#rFMU!|Y7IC&;nX4RkGV^=?rVgIE&rG=40dTOdr{ ziLumMpl*Lrf`2Lf0VK=8k-&WmKtw+7U_oD^d}{<@q4<+PdpR`vUxZdhK@U#TJeO5R zv!Sw4a>t2VMqX5DBC}kY$o#YjDDZJNHd?JXgu#N7k3sgE9y55#AfGQO4VXKJFlnoq zRA@(P-r`lO8Ie}V>F=4zk-X-|I#L*Y24rKr7#A|s>iP)zDb;1Jo*nljc^wQZrgzUo znz%HyJoZFytOGQ=@7~G4#$Y^GWevG;ng^vxgmAU00}wsse5@+KW-mA=T_9>@GEwdb z8QDk&;IeJxH>6IzU6P5XCha1fii@sr8y>JP=MJPSyqYeufzeA>k5NeDDDGl7 z533(>@`dtlzgt-@wl>e{-As$$VHjr60gS8hXSoGXjrjIAwVZb@iR(PtpzaNR8k4Ib^?+_3|iM29!v7?sPCfJTxLVi0l+ZF2|uBJxGXYk~Z(Mpet^5NtJv zsJiIgeQ87Hzb#8$Piqn)omKSurIsWvvO8 zx{=-)I)Y+kutTVhDpt1>MqidhIDmfqcN% zaljF{0fHmSsLk_CWVgbdrtLQ92*bBd$jz4{XdQWs*pn}2tDwffQDjINjDu#)0|Ulu zB3CuSN5}sDD$^#j8n||-M-;ki^lNC8?)Y^RTd&3x=B)Z+h3k@385~VK;#5wY;Q3z(8C*xYT}CMaO9OgLxE;Efczf$Y z{LzH|a8&=-?<|i~UP&T<&B(Cq1M0ZRg>Grlr&x@wi|E? zdBF1IZjAl=cle8R#*K>{7dy!!d=5cTi_8vqYtFqg2dpDq9aE#CRO%;h1&22t=_toX(?Z!Wc~k82@5#szP+XI^PUp+Ji`* zevWA5$pAhId8deQ2_Kyri;SHR7iXZuO%<@W`G3_w-$^g)Kifjl62j&1?imQNU|@%* z(aGXZB$|z(_aI?XUXMY@FJ*GP?^kV%($}EKuhC1Rr8O5QV+_JmVi2ibn!-LW|d zp6rqLFyOVeXs)Yl0L1bW3ys-`q8YIuNtHlwTzT2%D+$pGq;BeRE%EllCdP7_6#a6P zrt6jRwS4fzLcmDijZ`1^c!GwFQX4|+mW#`Jx%ez6_u4SFXf!mI&&bJTp1uQ z92N#XaLw1@Uu_n-b1!>@%#qdWS2(eVpf<&}ib5thmge`-oi{2=X8P8*LEzU0W?3NP zuNM3ZyAysvc16{W9ljjPAlbAcs(XokBK57x5?|?fj>K?s;dalrGsA1$f}b$meCE_6 zqlWxZ=ij%bI_Sx4H#U?Blqds1+W7KWEIxIZ->-Ll;K$8MH)*QZ-A4 zPt#@n)l*U@@v47nsf|TM!a0yPadbYYCv?rwOor~ObE+Vy{Z-sO9A4x`-`c?=$O*>| z?ypB_yXw7Nv{+IJ3^wEx6DfQ8c7wwCu+HCuMg;#In=4r!KePMM%MU1$MQwDlwMC|Mo@H0p4 zv!2^IKx;fKEr|3vzQZ?7tbssJvR-0du7}*A`&O;|9s{#M@FhhLgvDT9w=75CGM(W| zT1Hhqj>N%ogciF}$N(1Yr9N4&l2wOhV2VnNcoio}e@bU{?n(GhfLgZXh&eU=S1K3x}M_%AkV~EBGn7Ni*4M2dsRz z&*^V>C8oOlc2;&^X_1ez%-r$5lat}A>8XT|lRnKbHum}4+(6y7>}5HLe4ni+;g3CA zE{Ghn%YAvYZ|)~zKy$u->zmO|%B_J9_bdvENP_x(oeJQmkZQbnsQ4QSf!6!J zH;6i^;l$mY`?)7J;ZF&CR(lLF%+4`V5 z7{kWnZw?xKAjHq_g#5Gb_0TCH(!U-Y5MszpxPd~ko6D& zrf}Kd5_o{7GemQ2`#6N-j6T(Zcfu22fP6+|W^(AJ*4&;GF32<{&jLbtGbsDdWXT{@ z%sqGeMQZ4hKT1nj60#tzRBF+qb>Q^|24M+I<27kNxWj`>j&V)kfiBN=o=n-{BN9j9 zctyB)*|`r$?7d25+rY?MAnANh&#-RbP+;Z0`TPwZGOD}h1!#zZ-wJgqGJ?@6+%Lu52`rMKjw34iF;{ks~*8Db9GYb};Ig-c2QYv8D!@A|q5%qY(q zqS3j`;n7T;lj(5juc)7}TP(7fhhu3(TEI$X%S3Z#D1D6!{0W4&DuT!na(LH7S%AU- z)gU`_G9cYRC%D!WCZ<8Tt7oa}Zb>s4!f8r~iyJ~f>6L@Jx6RMS z>^zz^!@jK1wzwft@tEq(Z~J^Q2bC^x9yrUk<7zcJVm4Rd_%Be?b4cD$Rf#AcCBfHY zh`71mY%oxF!YRi$aE(GI)jvVbLizmEc!ru`Tgj5mkp6zRa~PV)h&IkLdtELMiOk() z+|*!smlujn-^=|*k(+%SsCxxZYpyZNKMr*ZMMkVm64f2fN-L$0k^CK%_g}GQeq+`N zSgJS$Y!huDw^K-e_c(1S7kL$Uw|3y5%3~+2I7)0(uW*2IkyI%_<_-7fXi8IUM@ka; zlmNHFjOvGolAV!^TmV5pzQ1i`*E{Gf|9ubGRz4DDm6r=2UqFYbRskqz!~9glb%83y zR>#Ib&*P4DRY-4s_$CwR=HDss8KyFM7wNQyJWog2&k|2@Q9>Cf_H)8+Q{uW0(TT1Z zybHk(uGG0q{wq>TUZyMb-dTqx{CRjxPr;b%xxpkQ%R4wb=OcG0guOnP}Sf4d^E4=}PRmKtkfpGLV{ETyq z8L;Q1+&FRZiemRaqxwYU3A0@y9=X9)2QfWZfq7gMbZw9yS$9|#Y8M`+*oE0CE0(dJd z^4NGNcXMtq8f_FNvz$lS~iYix~DW5I7gE(bYEXa z-z!Q{#3*mm4(Wrpk+Ll(-|)fie>$m7igdl9A)Y3e>?}Z8$39~+Fnrg=GC}b)-pF>A ziwwzFf5>Ox=bVwDD0No^Nh3iTw@I|3&QK-8Ct=8P1?H%fs^|Ks7AVbf-i`CRXJ^@# z6t}3-M0JCoF@9uvKOCZvZU7oGDtM~Za3oFY{n-BVsj_B_Z*rhW*LFisNzqC`C{X#J zQsvx01BNo*_D_vt>pZ_se0g?>(4EZ0jMe9z-(to-zc60}rv;A4Vt{Uae+L#tVp}vO zyIx&uEFZS_)Zfh{izHRP1fWf?+&(SjbD;L?@=j02bv)K=oZTFpZLY=7FWFX)bUp#) zDk7FM(_Le6Ej(DXl_)vb_7J_bS)%j2ciX~4UQrftppQ(3&F9BbX?ZGnqpee}vQ!k! zAQa`>Skazrv)mPAZ7D-xJ@DcU2PHf&^Q?q4X}%lKL$u}>X+1tATy3}5 zdmpxe09N|G<)Q%of6JGX>f|K=U<|7v{)W=s6;amCK@ekd3)xNXqGxIl4W3IQd7uW?J zrP_L@Y)#+E@laBPR#5gtPW~kKZ{pS~qYV%C%g^&Za3Mae&IVMVZ7~o36S||7xQko_ zBIOmZwpR<^$jQfa7m2mxWc|X8giAp5SiVCQl$d^Tg=2ulD_a$u zxUQ2jkNTu2<+7ew`_F&*oD34^bNYdmiH@-S3C^G(9qC#=!Mx~SnM`BoN(JE@@8D0q zm$zg@T|N=%)Tcyo5FYZe=Un%J%^Jt+OJ(6n;=BkR8LpIUJ{-KYzSOPQ zRD3gg3GD=*UYMV^5veR2qgxl;P`F(|qJ%EZH~`gM;G4zHpB;w+JXC=35E5d0#865c za&ZVKy$7H?!4?b7TE17Bv3UH5qUY?RcQ(+I^D+4kT zf@0jxLzw81>ys3>fP!#`b9L|D;i4>F+|fl-RKv0%CUh}MblJYUP8nlCtPKm~b7eU- zAgtU81p&ATOmi32`RTQE`qC|8=$p6Xl*4Zd+>W?y(m1oQY0U;bSv8JSUqW>d?G10h zZC2u%H+~JLI^QBG>f^oKXg6tV1#Fk=!Hr0b#~9gmOtt&z2+En)6>=} zqEC6>xitLmf;d=sv663_jicJf;0Xb$F_3o2mW`Z9_{0p=0D2WxZ3&+?CdjO6k|ze( zaF!mr!rtAZo~yjJOx)uNRb}^G^f}k1fm|5IAjFW#P@Zhg8*P4Y_%Zt_v(93@|LMPO zn4YA`u3~DekKJ^uiU}WW*v-bKF@P0V-+PP0&sZ6-UV^-bm7v04#X)G+T)+1<%o1_h z4OSvOBN6Q+3jdaiePko`AGLVhcVaqS~Ur{c5F8VQY~hl1Lg;Li{%%ChOIZ% zN=wILKD~t{5+*DbuGB- z!pCxvS*{YNOPo6aOn8a{i3DOac{OulW?YPBQ@Asmz5Bpj^X)dUaoi;A*nv~amBdX6 z$_mz#9F2L7P|Ku6Zs>nh0fIn~!a8_|T-s>mS(pN_8qv^_gn3<_eMsauP|1hvnRS@6 zf3%j=)QGqNX_t$l)txyLT}*%&me4mvjmzi(ulY$OxW z`Rl)?F?6lu%7iDEnJWeyAr?Tk7X_YM7?f5aj)7W$A|m zs70Db#~Wkjs)`V6VZB0eq{}& z>%A9cmor2(0DQUt2ISxd1ag4w`X6qF=o=w-Qm&8OxykB^Pl);R$6c##KqdNnC~AsO zG{dx=!2DOhC6YLF1hRUk<^*6bymQD{tDC>NR+VGjF$TQWDKX-(O@AsK;%RI)t?TVJ ziVa(StUqY`>mUTzyAC~PSXR%x9gy}^u2C$!&c3)0u&I9P+56ka9AY-WA8P4dYO=WK zC{|r#`m?Q4bJxpx3U$Q-u6ApO(q+Y}2Nmxb^* zF0dC2Y7tqKLM7TYWN=P}6dPV?cnbEX-Uk?AgwtxgvzH~x4|6u(nFft94`a#{`jfC$ zrRHgnki3dApSIJCslelaOy%*TK_-TF6o_Q#^8;J@UdIp0CEvGo5n_jntHsc=49h;p-g4qLe45T>h zc^o2n@WWiJq1=?wiO;KO3Rh4BF7Vn(Jy|S#=9FMOOHr=hv4qm7Xhl*_rFn`2j*X~J z7Y#zdDH4E1F+p)T13#{Z&hxB}g@nJe=k@+`XX0hqoJDC%S<|&(KcD*b2=|B@mc^qO zmKdlcziW2HPMEz!=ZV|gKs2w={0%M|#r1B2Zl~Gkv3_>?n;DX6_-ec2zSRXgf0>wH z9}Q0IZ?ij|Xu7IUOeYLgg*e-)(ZZUwZ)*odQy3UUcp~tv7A~?%x6^$iGdQqrN%0PU z-MrKMbaO%G&cZRj<8)H5*Xu~P&t6co7EPz+BC!-WcW$?$kk|oX2)-8$X~E$b1;ghZ4hQU~USS9w zHq-%}!0}F>oimO(saG882j-^i&2rQ$fkCzh+jfY66#1tBf_(U;Xpr*5_Ez_M!*kZ(M5bVUNg7IfaPI@bfK)9GA!F&xqDiB2Oh zl*xfF=;Ys2vk(q}380K-bu|eq3k3Q=+(8Y5{ zh6WzAqER(rnfg4z_U(G%Zy`Nqn|Xk4n9qqF`d6X+tbowsfqTw7oF#Sy7YKo9I?X?r z?yZQYd8ZAxAo|CZ*cpc(V&~L5f}7g%?Kb?79VR856lDzQsn)noKk|F?Hj&KYeCB04 z6;IQE0e2YW+%{wr(f}-pPb7}Zby5!257*g%@urmLFJ<^)VE=Y#Ox>C!V0 zIU(w9krS57=rI;L9{?}Nno`YS-Dv<@w?Jf>05vX2=XFwx^ukuX>p4rCJ|YVd?H%92 z9@L4);zw+=)` zu!$zwDDbaM*+R)s;BF?v9~OTIdnxiYnM!2rax})P+K%(Gr#b~if7&N^1KqwX&YwA(0CkdX&*Fb=7=9qyrrBgGKt>_M=t6 zsVCYvBU!^upWTbHH^*wxq@71WmvimsdgbfT_s5FLO3)w;@K1{ZvNldg%B~_#+$v1u zrk5im@s&;35fVd**}u)eCz@?JwS&<*iO|-K@;{?>>t(EF7pCrz2HLFbaC(8#48Dk- zq!-T;@8PMK+8n-1?@dl)5UCTb^?+>VN9}+8#65CU-o`D|jutKT#2t=y>XQl}c(t1- zg+0f<1hj~;4MNF!|k4Df>%G zsphd4+!RL<@m=+;r7GO$%8^Xo$`0yuyp>?m7-g6X-~uOS-N(UT`zSGVSd#FNA=H)o z#*Ln)8JllI^i?|)Dvku4+H2t+*LP%rDM?@fXX>O6<%8T5@jx7av(cmQYSX` z+~qTvIf=X#BP2+zv$zp?-Xn3XUB>^1%6f5cUGT_KZeuJ8%Ren0xJ&Xm;aG6*OM;h3 zDJSc}c6ovNne@SSg@@hd52s?_oW5vxa7GqHWBg@VLEnigR+fJxN6Z`PeCAR_`jK@s z{Y3Zs;R@woY+3p$(azmSSvR)d4L=cKP_Qg|aG?_Pq7jK=D@wMOWUmk&N%jDGuu+QQ zoXXA<{ka98DIf?cg@8~dBv-V83{5g)@{1By27i<(MifYG@8SRDC9hG<9Vi;XQEdN3 z1}G_5j%V+lJCIICX0OKmX9arGAE5-DLoa@|I!>i;m84ituk6I>a)q3q$c)-D9Cc){ zR=H2ug8CZp(4&)?^8gO34K1Q+oxXSV0D<*%CwvBkX4}hWue%Ggpg0f}Yg81$1zFi2VfH{Ma)` zTaGYt0os@Gu1VyR4Jh>teM>SFv0KEL2!Ul*dAy0wSt#UbD^{W_-^Qm(vip+>_?DxJ z%|0#Jp8KQJU&y+h!*nfpS*ulZ3&e#`Imx75$Fb!Lit=P%r>+GZ$1$xUx@@+7`kj4z zKmllmmB&c~o4-0>H`%OUYGYMFn5?RBYLjy_RoseI$_t z9tipY?y(;_o?<)Rr4?+JQthN`9gKAnNsz(^kZ~QtL6M{k8)M{J;4*LXcCs|<(kQU*7kd+ ztpt^l_>kLfBpz9|D(%8T@$)I7$f>wgZa4sNbKW->A#@FbC(irQrq3>50CSnHW-RPR z#+&&r!iMW7b#EPc48h$MKhJQ!Um;=JHKtp1fW$<=eNNPcWUVrl;RThZMczVH36ajiMf; zp>%_pP6*9HwXshaqiPH?#Vd7SL?5+#LTvm?i6%E0$Zy_5sLx6ylplnJmx+7P(WQsQ zT=xDR=!)?J*GC_}%(|;@|ECv^J1C?JE3_>{)wKHG=hX>C0$qfF%!+9;b(QCrQ~2H1$Iq!wF#;1bHPJ$wia7o0bjiq0T;IhxPFY@ zaHHLLax@Q+n$okZTFWU9ENyfOBN-;w4qkMsI5W?X{?-9X!2=Y}(>=Li;9K@7cOw(C zX-Yu1s{funE8)A3c~eL5>HT;S}haz>PsQ)ljw{IZ-+Gmwit~JJR#jgwBPP%rC#!S zt9~(M)5Mk9xjF!?FEPi=4y;Iwx5!}mr16n!u(#LWB%)2^9Z)mot> z{=*J3MPKa~HG|ueYK2^PqG-_785a4a&}(i}C5z-{uZ|jt!0;5GD$*9VXK8E(A}Zg= zFDc=I6mF#qvNuhzz-QyK-gM7|H}QT3`s$z`LnSIYW5`Mt{5$Ug4O0S8T`gU9h6VBa z=mxvZ=IC`)+MdN&b@fL;l}C0zjrOBdFlh+SIYm4mUeEvELKZ*TuL1eSeI+w$Yksu> zkcV^E=k@d%lW0zL09padIVm&p4kO$DvbGQCf`ell?}IYc$PnV*QX8s0$oCPPuwM8% z2?R?onul|^UiePQVMnk~>?tp1J3FYsE5=CfO`piV54re) zV$EjcpRyf7{Y6l=<@IxRyOktC z+0CkCr0J&5Ip%*#Dm^u53K?5L)*i!D11HkH`R%k7q$A2!6y@j9`)6uER|~ zn;+~$5cy~$dz)rcMSui_Fc|mHty^vh7JXTvKJvA=dMdZrAE_PoMYC}bfm}RCcT7?s zsI0Pg?C=nLKg}>C1qvBCL;WUdVKIpANk?8w^$1NJu=wigYcww0`@&Oh#b9OIW`0x1 z#|~wI2Ca?QCGN_x#tJTh4_q&<_@#-oirWA?--x1(D3DwC(D%!u@x$X!0|RA}$q&_F z4wKX$E~tN&bxtAQzY>hItG~Xiiocw`1HiE2rIwReURrJr5K57M!x`UsJ4;UX-|29o zs{fImYkw^1ppBDYBo^nN;LHrF$Wqe~{=1P#JWNFku_snEwF7o^HkfJju*yChb#;=Y z7)(Zp%5!T%$kY+UAby-XcM1Bz2L|gmd88-xj`IX0PSb7_?De8d!5R=`t)_R;aEA*a zo?&s%YFO|R;VAg2pU~=SA0w8tv5!uq?RN}WDj^Sg`-_~HY?FZReJ!W3jF@75xm;fW z2V*F?V$Q=jQ<%kUc+*xpkp!#p=xgyFD*V!KHwW(@W~fsOa$jS|TOw=<3=qB(ti^qj2u!I5Hp}82O*Gla(30d4UP~swm zXXnll35xfQ3zof-jpq7&p#A;w2||ELwx`~MA~{U+jr12?hWec^`LgK= zTwnD53!?FKblF*0YYB=aj5w(B{4o{-oS`Mzt$~t?sfPzWK<28)rO%xJ&VV#*^$`Az z>CACjcAPh@T{B~^Lou%ZA^!XRUk39`OaAF8uCW-qI$=|{SOMZAfc0~z*-l!yM!v<* z(+q>eNj}LxtpeQoPPr!3D99P=Cqzu*QX}h1?3w<}%gLGqkTG!k-IxbA+-jxuf&f34 zs3`&|4GQEFRx#Bstkkc<6wbhN9mSuF!IZv!|65!l5I7i(bemSladQA-9i1;?rY+E( zCqCm8=RJ7qQNNi=J9{#_Q>?`kWs>krI}eAQ%Z)1wzP#p-FZ7;he{OvPMjc>q-=DJO z+FI?c-)(<#s}-8O_it6AW$(xB7J*buQwZ&g$EPvLv8|oKHv~`wp<+Cl9uVXMgiZW^ zk3P?;sR}PV_P3ay{)(cc=8Zk*c710bxB3s~vRffPXZ1D_3`q@fw2x~V&k!&kE(6h- z+$xd{MoVDTsOKO&_3DkvjJ#6;jJ?kD13G3$hT#+eLlP1l>zI7)k~d;tDLN>@bbmxr zn+5z5BWK|}>UGJ;p>-9o)Ac{~g4mT`cZri`yTtv*HneAwEjK@;B3Bl|_q8=bCum_- zcCE3geR;5?Ww*#hFhGmy%3kh5jz0WYwmT4}GyK~a#pCgO8qpLyAiKP~v-G}$^n({B zlJCe9W%`C|N?L`!TUy$i8pJ=&dJ?>D6^8jMU9nbP#b=xbI$cRN{%UTV%Tb{kDu|~E2p2B&2UH@({HQ33bR*9bscc$%0h=MZ3HgWpA z==0cWk`HU4`rENi$IMRDYT>9`s>4-S51#{g&@xrkb_|!I_J>F4YTUqE-sJZ?y_`kf z#f~*@KDz&joe0wk`u-`}TwiyT@G2Gi*|_nFPi?9F5il$9e*<}m5%9r90F+8*B+(sC zWDzV}Q$r3qh<6>T`=fV!Y%y zT^jy7gGgp+u{= zfmFceNh8;{$!o0W@C-eAnE0s`8E7T6cnQ8M-tWHrMd7jld;I%2(o%ju+?DpMP6 z7k2jwN4JHn)}%EEt)uoeBzXtFZ~6S&RvQGH1n6SnQJJ9l2cI$6!)ozS|D*Z1l(Bbs za9Fer{o}scz6~KJU)t?njAcP9x`F1AMr@5aF+g zxv}-*v&GU`JBJ0yaT#H1G>r~Viqu2o>hX?QBUON;M+CQVe87B9ezJ)dz!sZ0K~0_b zrN4pp?%1)Xj`dg`SmSTKlyQDIjT+$USAbuqC^a2F_z6Nxj$503m} zb5TLar=-?X2B6WY0rH&8ER=J7V=Y+=)lX2E6@|zd`qTcBJq0VVYaY3!H|jp#TG8G= z{N_gCN2AyX?4q7k!A0ld;$VjDVeu8x)zvVTs!Oe4g#KsWYuv}<`D?E)q;MFlCF>jd23AmcxBPZ@O58AaAE}FO zu8@Bmv`Vq~2smdyG^DVCyU6_nC)qZtD&#&S<~Y`f`?SqTX?j)=qzipja?K_nGmkRr z9!&G;h|`(WOvleca}BEbid>hcUR8qrPXZ$8_(`)Xr8(??en>=bXrB7-?PXQKvc{sP zA|hjV+k4O`{6qm!o3LJ5j53K|GRo=WvVLBS(D5l;EBbwvuq??LLK4sS(f#F85u62U zXWWVZrNV|+&!ZW4<42Z0&4P#mT!)Z`izcg;n0t4?{ELVi6;CTeD8*q_#=e6NM@+%kn&>yOg2{5D zbc!w(tiOcOgi#1(K?{K)0@0&`$0*3r*{OC)7&(G7R?0xQNVURP865g3o|6IwhjAH4 z+jT&J!#N!p~Pm4831)fsVgIgmyI|p0ij20gKy~e_#MBt&{5p?ubJElO&X~ac)|lELAulYc(_){rprC zXw4+J0V&uO&i*G+JA&bX^Tmro&CU6ce_LsK@A6fr7mz(v_8cbrhb;DNC3hl_mEjuYl6qumh9MFhJaC1KE(D)gA*k2EZLpE zc>3qTShhRUDlOhe+3#=JAYy>95#;d^&ZI!l77F?W82u7pT)v!k38Wz3Hw_l$@e(;) zKic2s9F~6w@|p!@&aA}t~7BP`+u`ObEUsFum z>LN$sC+ww8ASu3>)i4;r@Gn{GFg;Bo;?$k1n5Q@67@!Kn8~`Cu!;9zsn2fV%gqwC{ zJHB1~4CcuqD&eyz>EKEF+uu{uq3u}FQ3&W5ahYt>Lq-RvfVHxC1)^^0$SuN6=<(0f zN0W#m^reH&(6c9T&e^r9>w0u^`EK65vs#vxCk__uIOZ`gbi$I|*7i5&Ond`G?2S6B zi8R~D2A(gDags7)w|*0sb=n97WT=Z;T!2pjvNZ~djW80Kl}6VH*khO zqkkZq{}!7I#Gv91MmuBXY2_%a%x!Nj67>e5L3ul@t#JYlkYHMq@M52P?bGnIY=jbK za?C_rs>?VzwATDn4D+&~m_5vycTym}akZ~3 z7&fW@R)O$Sw&ph#(-yfHhLk|=-KmqHNzAksclOAOuuCjJg2$vfq~-30vON-?95YM|isk^;K)w#IH!5+=RB{JQlA=HA=k0w_V-;`sZLilRnQJQRQ6us&XgqlGCkdK? zs2yBYg~G4gVmPnWc?&*!HJrm57wM}_qH*?0rO;k~D>*aK`r+P{Pd`SK@KI6>4{-*ohga1a^1kQ?h)h)#&gp<{FmO2pp}X?I z!Q_>0NPxLemdY{+$gpsO5fU0A;o~j zH^uSJ5x@!&h!u8PfYGNZZ}1Zi%3-Vp`~I4NA$bjy{( zl{p76`QlO^S=JQ;c24_pi9uo)!3vE~?u8tgkipqx=N#*e_&YyGcpVA2_zmAy*mui2 zLqXRhccbM#vKWH@+Wn#Lj{=6>2N^QB$8jBp+8x#I+4@mtzY-D%f6>5`vx^H$#&WHC z)M?HEAM_q@)0aGtxTtlBrV9Mgd^`mQh_l95HDjtu3s%rD&9M~p$f8J-;Jv*0u~gZ8xUEUcX(f}H z1jfdHk|30GL8O zeFv6aYnYfq&%2H{u_n)7pN-1qIln39_*Hllk)Fds>$+V_ZdgZ^Gh;Ab^^x+-@%N9$ zf!Y`5Gey~=&kQ(^3{Q~`bXaDHfNq|Ttt3A$$I&q1gQVg(kZckq%y(S1>Ia_}5An38 zfvSi_9`k@ctup>ICYjI~HU@yn_l#wlQ)k4!EKP0%qS`jfM>N@g%nqlxHDM&v(J5kB z2*%o|yXwsgPve3T6-r1da;#h5_Uiwc_$$bx1>nF@=jOh7J^5sAOK5``bbvzabl4F! zp8ThIWS=nUTCy=ql4ODdZz;zcGJi&IF*mu^?5AbP{$Ac%Wd0g`We8Q35a8vz6o#WP zh;SWX##Hp$w&*#NAVVk4YAkKL@iMSKs%CRO5Zgu;C{xFiy8NB0qmwb3^I>#f z@>w+Cs$N~Wo@bARoU$*13f#0)q9iWcuiX>08#}9=m71QBI$^6EU^z1;u6TUaRqzmN zC}F}3uFRG_u<`6WoT#2h4S)`N+--sGe%MFcev3wxk}bT6OdS|#8YpE73`0w(goSqw1Y`fni!c0T=R{dV7&?KX3bx66!k!nwmY~a)>*LpP|6I9(7KWqL!-! zyeVh1GFHGCAEX~L9^<;d z<^3{TQ}d;r1tCPTwiRJIi`Do1gpHbozHeAh*H{%CWYy3;`3V}$BNFNk@&FHK)x(H{ zL=bww>#I#R&(6eNMRK@s_q2;5S~qj(M)#~fR2(0)-%vPfSW($}y_A$rEH(E&{HVgi z+TP-jw91?B$75kTRE(pS+c+p3YZGvWOuFrF;GR=+W4c~r=*bQ33Lq1U7P5pII$Eed z^3`~J)SI!5%N^8CoJ-I@sDBTSe~^0W5X7PW#-Mu_XsnzNu;X zE4K_ujD!~48V=I58iu(#OVK1n5q5+Q^%iv(LlT$PGuwy#9ao(B(-eWbFo927p^mWr zs@Ju9KsSp#ilg`CG8$WOW*qOh=0&>YQ3psj=i<)Pl1?QD;(AQ5N@G z2Gp{U`wDb4FR@S~53HPCYTLO6F?DHuxQRo5+lvQQYKgIQP)3V~ke9s_9x>ql;S6v6D3P_?@CLAJju%Xf8npC~>$S?l zAHiT+AJW)(!q~}v?F+7ITSe?OXTq@#eqD`_4tW2kCFqCS@j%ow@}h@T(=VguOSNGk zw@$I#eX@!moc1U4nskJSRrdnD+(C>}ge+Ax4g~f8+_C_}RlmT;hT>2>j1Y|T@UYlr znxL6UeGlrsYbmi-3~}SV&ycSrL>2VpmDCe^exQkxr-s0~c7KujZ;C*qi*zcesc-CE z);BrQRL*^jByD+XJ48v7v%_)9xFzau(#gfeBNW{Z(&Y7VL>4x*gUo+OVJHP#N#Pv5 z=l6*eI-w?+em*1P0MJpXKS7G}&KHim&Hu`P>BiI=d>o4_?lBGL3Vk|)pJvqb<5;2$ z33LH~SCTN#MIiw}G}(mOil4^pm$OX}paFmZflf~8Xe}l$mgI6~_Zz@xnvvda_Qpil z^^~H32h38=E)Tn6&vMM@h?ETbidkouZ>74y_0@1@@3Tfk&Gu`=qwrPbEf_4EOn^AN znE`0OY3q%iWMfJaF!zBS$Z(9Cwimc^#S-B+r@6Yq?m0XTjzbI|yvuvafg>jX!56t< z+I@jSWJTt*{M{Nwz-Up zJ~1e12cC{$)L)K!Z^J>Z({Bqdk?RjUQ|o97}u>wBqA%1O=MgNIwa?}9|kPAWm7CVG$ zsK{$sv|L+`#98Z^{SA4ZWnk3&vB*1}lzuIT<>(>%eg!Ri=~%-6YCJ_)9TFkP8hxo3 ze@(m})LGWDNqX<706}Bm-8!3+jVZ2FL31;@T9itQ$fg%JgFYbXQqDr@^ad8&`-WG3 zif9-n6YZ3(1vZn@VKM4V#wipEmB$Fg>Z+@88t?kWGj^+Pv9|rTdlcvUJMjbmDKD?X zZC>VR9g_g1l40s3=v{eoA&>d;?Hbz2g;GW`Qm)B?!AAa3)pxw?iRlObX~#@uQg<DT$$Z2#hEpP}Yl(?31^B5~L$mIE7YSELQQ(#1SnUQP{+suo1G0YtqHzhL z_NZJyXL-s5Lp2mTS3<$U{W`A2MtO*8&LY~e8S;=$$+m6{9=lE_@g}vYO_G-T$hpv- zdl@FD-EBCGIcO)TRq)QCw_ww9-W#$`!`4TZ7qM5pU|3~^{-mJiw_wbk@Q3}e^lenk zZgXt20>T2lTb$uy6ElQs;hNx}sR0n-I(Ik^^);x-_nGiFQKEM-A4KtBflUZ9!@ocE z1ewTKkp{JyheiHkqP;zUn>?I0ccuzQE{l7|q}P3|-Uyyq`Q4{nT6<75Gt|m6tb;JL2s_J`r)Kt-|VbKtz0V{T48*(;R60eQ0wzU<$;r zudpWvyx=3AdJFBHq{(hX*70w{p)C7C<`nX(-mb%H30BJ}s`?{+C_ zPSmmt4R$Vd;mzG4i?lnvRheFh*b6(KtZipsrRRc#Y>`51qU2O^uwP>1@yJV_HWsk;D%a(#ovmC||2{ zhkc7n@4tqRng?z%xL+ivhcg{s;Cy>Ca4>hU*nR2(aWVIi_;?><9zhjBXn1lY5qdQ= zA@a{7cVr{$@)m)rbhf$yu|mR{8;I5e=EqqP^pO5TpwuB@Bu>q!$wVmQNoN4E#0XTR zTAZ%`{TWz665f_7JF{U@uRmuO-|El3Yyg-dV{*IYHFv) zYb8in8r18ZyT16Tbuo(Ocwrfw1QLum1qn^(IBwS(4*O>~BL#O*h09z?k8$D;gu$kJ zkIyq9!Z%i4^9I;?I?4%5xDeCsNNlK9fC1~|v&Uk$dLM2Yfg($i35n3}s+!t8_*}E} z!EiC1A~Bx5RH1|aA%H1t5oo05)=lR9L(D=C->vn##D?@!8RLak1CWxOYbt2_KlX8` zfWoe6wOoipgk$QgtAIp%;0an|@uPtns|u>J4b&L3VRL8aj21Rgc-fd7H>*Yb3ey$Xo#WQ%MHbGqB>kYVFIAxO538eDhI!*hwnkAoUr zT@)$N2NPygkS$=ixbrPQ1R@idCqr`b;NP;t{MI3mPI!d@NjB@`V8wjjUhXcP_M;um8 zIeAq2q}O*Uc;~)wDqJ?X#qNF@eNG*nqV-4{~)SdZIhMCrk2hvE9vk{sRdS){{>zys;hSe@)^p{% zV+BLgYz+RY4t(V$R;qG)1gC2zyjwp6xU&vLs7S_`Ii=tohLKVAx_wWMY4;%@>Bq;s zDrlXRLccQu1pA_11rgIWOB4u6f4q&1aHW^GwP?oOE!gv^sN6)z$uA*~_q??NeIRh6 zYUw^U(F;*@|)Q3%nuOTDi1V+T>)_q2uebs}aPs%;`-u;HN16LCS$hJ%9n`x%(0 zV5()grMND9A4wA}nVZUYVCQqASaw=G%P9an>FOWw40chYN_4c}l+AQ1jc8I7E}TM< zb-u?P+r&fqu$Oel_wa=GScCs^Camh-3slzKx1 z8i5TYF>$J=D|P!awOp2&E!|urF!nlWqI3B;CO9Sqo)G{qoJoQ2t;??OPv6Rsu~}ua zCSz5Do>r7A<{hz{CZJnVUS^TrqH+NOIbBg0gIRbpLW+3II~WuyZT~jYQp`ee9Jm#{ zDvBC7wMeI?9>%+36go5gD&xs~k@BPB7xW^?w0}KV8;qW5S%hSK!GPbs{OIKAlhu3T zF=)k0bpAd}M4kQ3P8fwA;l>Vt$ot2pSQlXw{ID-5%>Q*>+&U)OOoWE4hKXe-dQWqj ze9yn6xBLXX;!_& z8v`OEYxoC1I0KPq6RlWYn7gl^LkVf;-1{qd)wCX564`EVu_VREg_akO{tzCVy)=KE zIfDUVEmpddS-S3)=HFeG!H^_+RM}NMPs%JTZu-9AGGD1LXMsAGw-k6lagQTA3C+$) zZ(}l(rE36@c~KQO#D1wknYf=S4Awa;X8b3oI~@IZF%U@PaB}YQn*PZ35mfZ@9)3S2 zcIv00@r6)RJ|u{{?xD@&Sd0iy*|rVYas-;v>r0fs=9X;|7u7l@T3t}uKPW2)S%UYJ zi3^Rr1;cd4U>E%&F+u|es&aLzfTOo=?PQjLeToddvVf?ceqaE1q=UFOLD(l1Xs-{Z z24xpzB2V6VfF`f!?SsP6v|H*wNm;U1)%O5xI-?1niJDfsTwmlL zdcnA6;IcgfAn>>Eipc4JGUq)p?KVkcYE8k|`bAjOZs$G!GIX8QM_%Lhq?&HFd0?Ky zfmC=>ft6G=&;)U9gbI-)R-{r@Tzh;#BFu}TGIAYWYt4n6y>pZ;L9;Ko+qP}nwolu( zZR@n%r)}G|ZJc(Wwr#tozjyDQ_tyM1Gr3pnjEc&vh+kz@?X@c-Blt`OX2=Moqq{Og zitML2w~=0A+-Fj>9~SR6Z2HYfZ=)^JU|YgI(G^-;#l&{vE95#coVXzk)UuU4^jgE$ zSC4#QSpTdQl?Ms-O1ttJLgh?%E=M;yk9barYSn#tB%3YXLZ6SCtxiJw>4!LH4ac^B$6 zmWGIiS45<9$cT5JeA6awg^8QwiDdNrsKZ5yfI~%{6srM{tdJ$R{=x&#W5(5 zWvtaMV2rE&Y6CawE3(9QW{Dp657Q%J4m|< z!ka&3+4jX7_sPnNJ|;X^QPBcrI7ZFVvY3g7{hPlU^eQMQipA zJX%GUoy&+ot4}+}c=84A&lP)0KrtEt_4a0PZ*KW-s=BD|oy62_ONZv@JP+*=Z4yb> zk9%5_7Lh=v?e`PF=U>#trJ3tn)ga!jf(z&aPjnO48?ba{#+_kqFqnu*kERVusEg^Q zg&(C@t;g#iZQnvLor*}DreBW@P0Y<>`AdZx@VInD>tSp|_Hu!*!|XiT)=2$8 zIz0Hp@v`!mv^$y1`T)3ZEzcHy&Qxr5B854dWul=O9V@v=I7epc+Cw7?kjqUix-vrl zDGzYF8OCgpdG&Q;vK8(J3mx*XJdI?ru@Upd--8b~ZZHps6`%4o_HDwCuO!}jsCk3G z$yHoef0U-m2AjMkiUkROd5%?0Z;17C)W7zl$yV&_g+hfBhv*h6_=P)OjCg1~X`nF?`D0bT5iMjT>d$#}n1v(P$`(vzrE z(y4%_Ik4@(&ZYvjCs6aEAZd-D)vPARiaY*HeRt;o&-;9_X0fb!oUDe66POb+oP|eg z8IQ5I;s0vXak{)*N?AA(X(~;=@ya{`A;d%WFen5G4FqLnY zue&b$&J=#0X$)qq5>?zi@1AA5sEf&c&5xTWQ*~YKBztgZE}csy(tss1C_>WUY(s80 zMh5e7FGN$a)F+%3U@>likiCi4tA~SxiKiLW@kSf8)EJl&OpAY&d&*9r6X(C8(-~*L znLI7^7jIU2HI~R@uy!7Zy5aZIPzNdO(f1J@vncVAy6Y|QzjNff(&hjnFdUI_TATe? zxP5zF>`5aW%Yk}d;`8XX+761nIz+oge*o_H<2tkfroR}Q6A6gYPOKHPpK*N6J=5gq zK1-#z%bD(U2v*m5So?zLe zAfK~OFvX?`lI!%jx^MZ{{Wo-mFT9C^8m%U zLN}!YeoBqTz@xy)td|E?-Y7>vl6GgU#hb#`9-Z_vt&v{`c~}i;$PeZ{Bh?LZd?XLr z?mrTTlGPy37&~rK!BAoeV-E!*1byv0KjSmQDIqHxBwif#JNRihSEKr_N78rdB2WkZ zDMKF-)+JrVylnD&7c23q2x0vGd$J>nhHmO^bEQAO8&GII1=rE^C}Jw4D?+F26n zz`Iy|4t};C&tv`97cRb%Sqf45-X7C}2XlqkMY=shziYPz*!g8Z_;BQpF#LcEK%`_AdFsWpYeA1~D2;6%6PkO9kh!dfhn`mMRU zkwip&f1x7)&bjN?!6RD=`Cg^9hTinl+hAiS>V$@VXHTuaJgiflB?VsccLFlV`IRHI z#oyg$hpcx?8zWonCU`Z=vM7>vzXN+Ha&n^JwXnF;f7OK759EBD>&2JPo|O>hnDW%g zM>nwOIiI*+S-_$d|NM0*eE{Q)$?n#=!WUZ1eA0^Soc}~<*@cMh{xSaUjtuG=G$Y%Xem5=2Ia6LI zUQB+`slfhoTz1zT>x>Z(6ol7l7K+`4pD*ls9)2mmL*;mK><*z%m~Muz^K0w^LofSP z>NDjEeK0!W5%dpn&cjmH$qJDCtcM#!F8W`l5|y8)5E9p|K}VYXwx{JMLX*(T*BpJ< zklXqlo`#!`-o2eMej4$giS@0Sc8BUDFs)SSBg4yI|8&)-fq$QFIjpI^ZbI{u16r~^ z1h^3A8l*FgM2;+DuU1YZfd|;k2SW;=VH{k=g4D*`tHS;&8lsRLED`}aIMKGxGFP|_ zq6^#jVXNQwD^I^c?S9PzJ#)^KTw?ia_>ofiGm_v07GHw9Yp~#QSN2d@ z(MAwaN9EuwyZXM!buO$fx~nU9xbvo%kqhHq@EO)WSFZSbX{Q4(;KSJ=jl|!PMio=J zpS_2inPkueEB-g@A>$1mZi)d;p4=y8fpKJ?wzDbNIqeK$8HSV=nmY}*=`Uw>t3ZYW z)Gw*gd19!^m&(gYJk<>LWV0(!UzpyMFpQCna*)H}u}Cu5^~_PCqUoa;kjP0YTy8#t z9daN%?C(#!=m-|U8VqCJS)1{BJNpF194(F;nyELba}?OzsD_s<`me@S)sL^qjpEd4&0(IWnutrBPS-;13tVMY=&D5dg)~@%!q$3bdeF%20le^uA z>NwV+?+_01ic0~%64zz_sXsL7v0=dMT}dSmc}MOLCN12iIw1wm`bgfnQ>t-duboHU z&DjuWgea-zW{a0>3xWz#l&t32MsjD>K>asJF% z^eZw9LK%(gX|7u|R^ymGk6wxV%`7q)u2W2Ypm$KbaECN4+~A1G-ZCDw%d#*uedhFy zKkqte`U4W7A^yO))>e&v3q?*>N`dcer$v&pMIF0V*Ouuu=baq?5^aCQ0- zE46HXo@(?5RAnU`NH_7hI%?$)W{p+#KrB!swJI2b+@l@U;)0hSZzhSLl6O*l8+)kL zb|>hq-l+|hYNtZB?3zHU85{^9j-AXp2H@o`-J*^<61j|JwM&_+m)zAg`9bg?(Z0W% z!GUf99C!^I=kETv>u|ewS{0tUdo=76)nFXB0VLx zv6A}O!yf89Rpb?sh7-;)-S}10N#g?Q$@O-9K~M#T)J;`Ti4o6niSa`i{v&#BM0JFC z@P2jw(JfW4B-vrcAKw?cN{}(|)A=xLSP7MyR=a#~;N5badn#|nAr9TJA!BWLPA_uo zq^62UejY8>js9m~8hZeXlu~)yBjoj4cFciFYx02h(Efq_#!7Fw;x?BQ-FDzxVWC`WPxyVf7#>Vwwsrx@T)p__+fkMx&`Qtnk=|f zxt@E|7w9V=>8V4}QCI22h(V@b6w0h_^anGrn(U*Qk6aX!73by$REg_A*-qG^-#r>ye&@B_1<3+l7aX8(nktByLA`+M#ElYJy@N*l+URbn|PLuweiK4IKcO#eCZd4aMUh%gUxo5&8*9}HY zeb6*)g`cpN9Lm~%H{UBvo+*Q=ez!^Ibz3gP>lOw@vbR6NwG_!uK=cnW1kjFXJs(IF zk%&$)od?r;+*-agPBI8i(Z<84un?*#)tMFhOk2T=dlLQxDEs0CQyyq#Rn6m{^yr1s6eNr5NT%%tHSk* zgsm(-%h$N7R*%XnTvBU}cn@&ksbHX(5^A~SHlm&fZf$|(Rtz}Mdr4*_SsmbDT9PoP z8x4@ZOvS1nM9YA+P<+?WPS$d1yYPj}h8!iggqe})zIT!H#i`}Up-3cQQ`bJ-)gx^h z9zF@6O5u6irTR*)ZTaG1w!i5Kzru9Q_XYK;_hZ#P>zrEn1$R)5hYz8j-GeP?bdaiE za8O!q`5PHkgqYzIsQPfB*;pgS|Oq&FRqQ^pBWLAw|z z?#1Gd26`190EJ`WKUMm)mTYjLP+87kQzTAifspKK)I8#2>k5rXb8PF6h|@Bh^fS`8|F)P1&W%32^0 zJ5K*@G-qD7WmM;;KjYSP--Y63s5m()04SyrjcA^0WOBP6o^F-nbV2Hkxv^&BIA|c$ z*cdf|1EyK0gj$yc2voP_&@6J+U249$(q~-U)-bzOHUU%fGjgxEV8DuK&SP&aDcD-To=ncWNQ|-U zCQ=q_5%{hoGbTOm98qMLJv`KS=hSz}e%zj%6A8)t1h@n7iG0Vnf_Ed#ld{zO5@mymimO}|+7*qeUMeNxrU9hF74(YT`mDzt5f>gMV57W$Z z6;xN9jPG$nIJL1c43V!h#9~eKOt|X4zd_Ks8|909*1~I4JJ1>VT1{PipYu@}6A{CJ zA@neG$`Y2}i#hD+IY(ytSQQ?qg#Ky5I>mRVsU;*t17`pO=G7k{VoavKT4Z;fNU~*~ z(ISn%E3<)sjQxi{(ndPzR5-p~jwn(R&T03pQ%^=IpE_mIf#clze-eTi?^ z+hM!cd#<&Ykzb$S1ez>R^bKk(B%WMK@c4J&ILp`zu3QC?87m*7mMl^}5&1E=N*5CcN#0X&6}m zMe22>PkMRZN!Ih$WpwthZnLX8t2ZHnfShLf9HNWp3HgTb=y6#`1uEkN=ewSpyy0-> zUlDkaD2V)AQ~;kK1vlCji~H3t+A71ItE6ywSb`8n;N#)ze4Dj1W>g2!zH}el*gLE~ z{3Iyt^04YWL4qo(#x;As@0}|yZ8jw(@gpjXs_oiSFsg+9f=R3U@2z7;xGF?o5biSEj`y{a#T!|}7WO3TIS z`SK0kJ2L=Ll0#OM^3?RL_$)7acs;HxHxC7Hw>#49J(83ap^Z!`r-}L@SYK)^>qum) z4s|pnw{zyRE6m8>sWd~;6ubPNh~WZD*^yukaFBKWF+{Sr>Ibz#?F|l7J6U)iGGCgH zLpou4WRqN_zfH}uf08U1hVt}^ilX7Z`Wkl-uyaFI*sB{?>obxn z1*Y-UTTqZv5GXx_kNQa6R8*|TPhMOg@y2y=Iv22o(PZs zX1L1k>1uCVSRH0c()k*cwUnG7mD*f7q7hm}sr4S?gS<#uGGyQ zrb`;PFBp0ESYQ|-s@yXxv}WvQNgUA%x-C~+wyu+$ac37vj201XaCLs0gs2c z<=@I{Iba1T0pXq1$Ra1^y5>Ywux*R%^b2!zdWI0~=a1b5(z^pkd2k$Gb=UcqdjHlA zIcSaEim3Cnc932J&O7XN^m&zO_k3FDlRN9jFa&568*-Hz*Ge}x7#{k;-?04)FSHK= zLeqAn8RIpeCwjX3`{G@K2`jWmoOl1SjV7ykB$!O2IgcwqN^A07Bz3=s^t_XOYD+Ft z{9gs_qDJ~Fb+aXDU`xu8Y?d5Wn*fW>9^K0fmG3@9!01SAe=@~9`y?4Qz-wSme*18M zq3@g|ah91y5h9Oh5syOeU>OWn-aJj$0A1HPwp_CTT5WFDB}E6Ig5Dxe@E=`6UEm3@I^p_(@r3_#!EaNUC`_Bk)6-Tn@=eRTdC z^l+ugN`Yot;W&vE3ARbK5T8End%L=rYzh|6# zSEOteMF`2VEQ-8NS5b^L3Kf{8)n5B8fK~AfB4lY0+*FuW8_0<+oS|)E^>^f-8pr6O z93AE@=8C6~CTPoh;vEQu?v-tXAW+>((4fJdm;)dyS5dRuAal53lwx0fvZZ!^if`AG zzuiRmCUy||56JHOK4UI){RYHw%D4q;GUY<5n*}OM=E63)BPwlht$wg~ip3&`aoG-o0EVyFSBtN>FYglSnS) zUM#}mCC}Z)ibLo7qMmU{+*v=@UH#t2~5As$H5 zp!^2-W}P#V-vSVyttyiXamOes2`%lTG&qJcSaX>aCNgQ75-!FTDU|FLuIE$duT7J+ zGEf-?iDlN5zhOAe zZ1iq#OXdzTF~57gxr~66dL1uZ&ciPaj?*Fc7nd0X1+$PJ1~qZS$V_#Q6wJ}gnESd= z$xTKl<3VdB*^%gY_^Fj?5uKJEhY2QhxNJO=?h=jVeIChYb3>2Jzn6_gJnhc1wRJh` zhCC4_;9s#&KTAUUrCva3MQ+Zrm*Mm{4=`z!UxJwQ@}<*vw4Mj`K7J!6eL1oxLYUMs zm%XFuN%53F8h}7SUVj{tvp5Aa>NU|Sr=m3%s#IYLI2(&IzCYZ*MFng=c$;2j?||A; znIi0#3KyF7$S`F<1-hwDs*jTXo3aa6AxspAeD`of?pz^ml6~K-88%9O{QRAnrh-A-UnLL3hd9^!gJ0<-W=u-8O3a zXF)Kb>W-ZOe8($mHW4A_u_#i})j`0RxEz9oVSzEPE5Y(HM#d;G@MUC$%sYESXuBCk z7hXoAmZDRVao~Kgh=@LA+*9E7i_^a#auf-L;QI4%S&MD`!sZ)_eK%&7xB!2X#XY%F z~r2b{)}I>CM^Bz)1-4CWsdCR2oHazeCVFem-)?#hGtF zyQLZflf?-5jg^dt4s_KOya*{lXCdzCQqNf)*E3=_}JZ0nJg_LoFV zV~GxpYziBaG6g@xL8emWRtb3o#-FXTC1$QdqFa4P5S_SVfSSY0kRGx;2v_TyAm~0r z%HsF6=AtuF#*GjEuZd&gxN&G&Xh9SLgJB*m6*|2KWRY(x%8`XD`DPDuGOw4Z%hIYNTF$Hq`)*b>g z=GkZ(2Ry5U>Q`dUR4zFIPk|LIF>MZ>SNO@$)p!wf(Z7AbY#A@8+5yYP0Nm1BXLzFC zuNoCC^#@NV7@)Cf7GUBPA3wEry} zVa%mj^{*X%TpPuzhj_2RfBn^f*$CVY$`ZswDu%;#JdBTmfC)WQcg(o#0SLsS7_~9r z`$pH)fvAgOJ9S7(t0nrkrvG`&*&Vo#tVDcAY!^87CxE;lxfZjAR>?S@n8&Qb@9#cJ zF|W^1UUd;k8n2Ip?QOc6l&epD>>|T?%q{fU&0`tg94I*gE!*GmdJos%L@W#kI@h!U z{j=9P;JSgAj1eb+E8J}lIu&5cphx55fQHHs=5_APBiuD2_tx3Dm}|@{WW4=sA^L*0 z;pq#pG=Gd*9Hsh0L2I0!2b0D@4j7Uj=b2^F9MgcAHrI<6ylbG^%S=BT;jNJie39`$ z5@m4MTn{%u2F=_oy4d#XpiyWTf|rb*>pGSEts=4@0l&IyOr(A&UumRl@0v_$7|UqZ zGCJia!Xn|ACuj9u9@_@?aiX+G-wmwE@~;qE%1lFUR(zU#NHCbx&{m^p8g~{~h3Bf? z<2e9sqr!F(CIPt7?hv{SdJkXAc3-MIqvm=XKf$)n+t8{souiiV+!zsUkd~fx(}1$| zL;dithzH<~)ikxU;JGWBMQ4(W^DtIi;eKAkH}oFYQ9ktC*p;fsXM&`tH8mP z6Fsxp@;oN=4Qh;DS}w>1{hrgl_;9zO*S8JJHsP0w7@>!%f^MsYIP>Tw3=8Ik^OHHS zi|?PqgJ+-0C_UOKuB6wWty?ka8RIsC>MAS?l8qR@o72=(KCJWDu#l{+>K+vs|+j(1MNdf9F{{Oow`H?sMf@eMcWm349_uQp+`-a}(9MMt3?n|XBYV+fW{(3ZaOLD8u&nxh5+X-q?< zfbjMCvK1$+E1h+@VwTqEcwEY*4bN^`*3=pnc9g_4UjL<*K@L9CWUvHc%$1b+N!H=` zDtz#qr9$YVQ8vINTl&;mV}JOX7?NFz6zK1Tl*sbsb7oKG`7={22{kX*>4iBT-T46| z8a(uJ_lo2WLS+;!7y6#;7zWJ`vOK0)8P>v0V+S zuLxu!8#rj!NuovhfG3#_<%E5U9Ii+erl^HN;7-&E2jr!YPHNVo7b3N<#L?(KC#CDZ z19WV&JM)K&`$fH7e3>cxasQksw)ux(i8lJOcX59rrzMg#SQI3d?_8x|O>NioV3e#! zdNrROYGg!pBiCAlTdEuq(Ld398^7&i161u++aq4NhbM0AMN`B zRLcL^ps$%_hwkL7ZNiZ@DGMPz(cLa;_NKrQj)x?W*GC zy8POVj#nh)`#G46O&VQGbZqdV5%%2e;+4VguyEi(lN?a88I%0W{CdECFHHIMH#jgD zg&+xHuF~x(M||mj&+@|e{NgZJ#$o^zdXtZMw4fPLa*{W{Lm~C;u^ch)LtzlSSzca0 z1tGH|v)vH2S>F(o~qboN=t?@$*N^hb#%&96|9&}!P0KI*SOb5D^dUF<4!U3 z6_Hr40Hf&RBDrYUtHdg~yGpzVD?{CM(t7RDJD!Qn8Fzg%x7l(9;&Yf(MmET6bA&_~ z(2<-PJNR%has!=-@1$aZYQ>%tv6A`B*d!0a-6%16~C3> zmHgEv(_KIha8$tTz}tE`frF++~w;UsCEJp|IDH?xONwY#8-HIMW9w zSQ4~%md9}amM(1?Qz?zvo)lf|tQ+W{%m)h5Eku5IHb@1$RuEAxz8wqYUDErYBC5q4 z1PR!yCj@Jlbmj$hC?W1JZkL$mvBX#xR97^Oo6p;lhv9md9H1W(ATrz`YuL#-hXOGi zysPn;hey4lXv?K{mv$|+rBJ(x>Hxpi7-|*00cjTS_V}AIh}T%3JH?yqI;=p}=twwZ zrV(@>Yq7KaaY+vyLZB*3gGe<5Q)nX4VAoXgXa&UsTcR_b{PZWB%ebc~ z^Icg=30S$!;d9`=hq%RMaYmoZ`w_0$hrGtWGm|00n2V%X@NT2cEiCD_$pMxL?%uJ% zf}8f%%cF(|jCV~`!}`PUPgM$fHX4Jn!2}cvZw5N={!N^A#ct8O05~ayMPm+D+7HQ; zd(;B;OAE&qWPQ^iv_H7+V_D5$>Z4q!x`+zwlfR{@e04?F=-O*n5P1-U(|ZpYRw2g| zx)t(3qG&=HV;*&P98X;Pli5bHAqC@8LvNRV623nfuWA+63aHt1l7g=tXtg>Vf+;Tq z)pzKQOr;NzeIUDJVC+;l?dkT?vG2rs7=yVNwC~Ahx1;%X&l9Pl*>>q`7D59x7>=va9LYg+lz$o-O*9Nj`T8Trs@;C&>- z)9IspYT>MU7RW!ahdX0S zB|OlQ>b{-qwaqASf4JQy#&e?`>OJLh+{stgS@!6#9Hvj)DZ!U~P2p-@#(-)!aJk(y zJy`E`vVwz%oyh4k;iU9UGAkD$EXT!aiK6pd4)V7_=MPtPW%t-=YybRjtoYKxK3b;L zZ1frdi#ghAu{N^Wh>L~=qtLDS{JGh5=fJ3Sr4<`Lw?V{6sseHt00ET*DRm_|^KX?>7)V-_d{Hc@QVKwM0oc6P9!W;=+ zhHb82YQjbbCZxk?$f7G%$YYkYGh^}&zy=GDyLHt8kOf~}rerNhF2He}BBat~wDO{h zLg+M&b=+m^HnC>3LQFCA;z3mf_d}4^NEEvi>&Ev!#1_h4Huw zMwui0)!97sDgEOVs?C&snd{W>A7iHQW>-03+7Xf$nGMzAwOj8nbrZ!_& zS__Q!GNvXspOA3XO$8kW3&hnF` zDma5c_p7YIas!G-e}Th%2Bg{zyay(C$PnpZ<~3-#t7V52TqhJ2nNlyO1+?)_gEvmZ zcstcwnUm`&vh#qwIJ$ZWI9TNQKMOUP(cKmQwdjlRnRR4w$+42LdEt>4Mp&h2xY!w2 zty{Vgv2u0o71`w|}C|!Vnm%qBdeRFB!fU+LTsrY{PSmv`I%tS}!&fpC! zim3fi$34p1+Mmd?0V6)@ncaC6>2|gm3jkrdi+>Vt0o7>>G*O=gUu5%IXSJo3%OOl) zBCS~3X!Dsw-7OAmS_4YLd!jl7fM~v_1&v(OU1rOdJW|j@yi{fH+v|$4iSUb@bqg0GSvP-HbXz^zRWftV{qdy0q z1vN2vWgZi^tMiIOYA`qJ* zppFCTx^2~=`#9atm=>0>n<#tXM)*)F=c0^*;J|sJg~dGHc@R*g0Qi4XK-jG+!jlZ5 z=(ortF9KA+1?$Mkf93r26w{Cr2c-l6q@<_;kU!hd000mu0O*G!1o>hAnDGr z`hoKPw?#i)0Z@Q1z<(Y4KQ{gkrvDiFKbZ7>#Q%dy_(u-%-}Zw4$ie>)9_|0Y0R;SC z$CUhO5B%SJC;5LA{EzM5tKT~S#9!i4;y;T1bAo=pzSjXF07!6f2yie+2nYx$C`f2n zR5(}|7+5T16a-W}Yyx~dY+PJIQhEwPVpH^niZA5(9vdfIyIdzJ~w=KX!rv{jc(0P=2<7 zK|sO4At0fkVSXAkBmU=1fdGSofPsO6{_OSr*$)6k0z)QZ5&}n2G=v~_L}d<$&xa%t zuJ1=vn!6!oF>(rof=0){#KI;cr=X;wW@TgN;N;>K5fu}ckd*qRtfH!>uA!-AY+`C= zZeeNV?BeR??&0Yb6dV#779J6qkeHO5lA4yDQBYV^TvA$AUeVCl)ZEhA_Os4>aA z1Qg;wxPXA&{{tKe6pV-o99c*a!q5?gm^lCvRX9Gsz8{K&Md=33$Y~B5os@N#?Djv< z{ui?UcfbPweYXDdfpr645K>`Q>p5JDdT&EdCLd=#JcACUFm1%bBpYVPb z**8l)VAaNdXx8e!{25YrUrAuGi%(&l5w$>o=HtvmDD2%eec|~EYWW5v`iBtQG<@KF z1BBN7$9o6bY5_hR3l#GSzT)##oBI-;`bRuzcB>U004hCC()!cLk=x#Z=^V1U)|(Hj z2rq4?PM>&Ntjz^N1A+xSN6m_e?k1clKC8iz4DhnE7LIR#1^qC_M8qmO2&p-q;|z`V zWxf9_&!6|3Z@{je_swUlJYga=8->noRVO175M6ZndrCxL^Quk2GnN$K} zaVR{1Yg8bhGCC=FdBC!I>}#Fiv3x(-e|4 zQy&O0VmM^*C9Pyc=d;-G2UeR=4ZY+q~h$PBNj}~HZ{I={4GZmYx@`BDTg&q zlUlnJBJ73P4CE{X7Q{`JZ_(nbrx(UVwRcWE!;n0*@H^QuaZJbVT>qDf)Gf+DJQ%Yz z5}{%8Ml3U5TP@W~X3gpTP=~1S5Q>?ar6ku@Isv&n-yeOg#67p}(k%;a(<(;r^szYU zc8xNSteqRV9S6=~6?5`^kLwqIJvXxAn$mKPA$_PSYZ7ZDP`hZw8-H8{e&QFIAye!j zJq=EV`rF(Zn&}VSJwER9-R#xRu9vXyJp$fUpH@usWL=6vwvCdvFWEWbG#BI9K)5JyQW7%PBMx> zt<-%04cz_g(m3aPRW2#^b~pW%#{<&jl+xJVVRIJw@8Qsl#XP$F8! ztA=8tcjNoNR1dtK!<$xnXtlP+P4Hn1>N^5)Xq`lYavZQ6bFZE%36R*Nt^c5(T!N?E z)0O-y76S?npXyY;SMI-Bq>^fCcNd&*Tzr)J84o#H&x|3dHWNDutWQe&A1$Klwnl_8 zbCLWAr+V7ABASg$HWyVkHrb^Rv-D}c6?vh!<`ASNZtGh7oJ-aAU0{}AEeW@>t__@d z0Q86exMvB%-$jn+Gu%qi2aCR&-+-DyOPVt;gb!MIXiq)+ry)H($6n+8`(c=$Yc4kW zv`TcW*E5g{XrNue$P% zKyZg#^^fnNy1Hjk#-;lxu6?tj^N8a(MK7B}Vv^lb@KSdC`I=p&VU-q4HTNA(8Pv#2 z79+&pH|%yjFl%eqo5{V9nCz@tvXF-;81dOb8g{N{EHwfhlY6~)6`}@b9A7veOSh`l z#!6tw_yCAjwkMT_A|&31AD`RyhzpwIT9i|x`@P96F@pt5C!L{r&fv6FTiv1CS*~e{ z0vkFvsh!>^f}1~|=Y3 z(NYk!)pZGm4>IoHVp7Cc#EO>dq}C~U{KCWI&)RB7Y_^dIwHTIhCmM5&|0 z%}9(k<;K4eFd_IKrAjVn@a^}68$BjvLT!&&mug>P(9*tcZ~=Wmvt>05!wIi`tUcMp z9{^P48I{k15Rrc6hk+LLxtu4y1O&pH!#S;V zvz6si8&QrIFJKl@s!@_1pu}4Wa*V0-hMztRceg!;+$nj~eELY!*=F~MLt(4ub<-6KtXV3L?EAQv_ zSF@6l)v&G;*Uk-iFqx5(xVhM!W0TMJ5a$&_`E|4klDs{};Aw$&+4N8=rnR%c6b7{j zD8*_lxF_yDaW{q#Kk_0kn~7MK@+*4EI8RC1J!%%nQP6t>yi-^7GjYme4~`aFaY{Wb zqs}n-tJ|s+N}S5R+aeYgAK>9_ZVH`~04^f6KZi6~Ykv|lavZr_IV-wFh}Rn_w(Ftz z1~J=YsU+k82CvXw<1d%t3MOw(SU~h!>xG~A7Vkz!S31Fcyzlo9HG&>t+NAzN`wHKHzSM63_Akp$;w&BaGk1KN zrN>T~b1a*~ZtFs`+iBL8IYx(<4e+J)MKANxDQBhgwc7CN2U{354h&=~nWO!wcjR3t z<&#bcxCID4Imlt&Yc0l}%ptELWVVsvXqnL;7c6?N8RjALJd%vj6_XX0Ym^O( z7O&+}m$?a&KNtw@GZ2^%wXDuG>vc|@&hFee)zbRyH>B#%$~sbx$9dr}WJ5;mIDTh4 zzFVcWGVT?VWoKHmA=g)InnSIWdYn5Z8vlZTrKw{IL%C)!bAs@!c?7wuufs!=t2}}f z7w)kPdoJ>61*vZm(UkYmzI-MdD6@s`%uk9@+sA~7P3#Jne*I52ViQ~rpS?OhRL-Iv-L zH|tLyO~x|bvlj(6EC?qiW^^>!CKv_C@UGE8(H04kLd-Jn(Xkm(h zuv4i5w9eRGF3Ul_yw>K1|5&qNo&;2Z4P z=lxpW?TGQ8X`|PEoFq4h_ko`H#^%N_xyaR_w3a`UQo8P}j>G}0Cb^je!dAs;xj}^2qKsqE7?7yXP_uX|2o@%XXwEwSmuKXYB z@B5F4ghYsDEDhc&>ln+73`s}x1VDN7QvXU|Tu@B5ymEMwo| zJ9;ml@Av!o{s-Up{B&RUbY-kSv)OIEQTqu-zki^aDppCD44XA$Etl*+A+SP`Qe1@~V*E zz$i3bFGdw%$8E3A=hYLk;l-;hJ1*C=x)OGOr93<-ph!P@iFEj**LnKlR8B4@fQsk> z7YT^o&;G1MF#FtokcZM@>I2&0~jdb46GcX$j)bL{?}KskD&O$gJv;C`=I`^8p@8pICkY3p7$~+iEP{yp6x8W3e=irVr8o+&Lho2`Ln>EEWYr#Eq~ei z==BHi_F8dDnpTDpa4gn1ZMzeFBZ!kvz={sZ?GsX@z`GkzSLPb%Y;xVC{LxX5WLcv* zRu({KpL*_gk(ofs>MCKQR95R|Mi9P2L#&7=Z<^sswqTrR6c{-Oa`^n(>}ysH+Ya!s zgqN>njL%f@f{9j`yyja{On)PjthT?=<5Z@dgL!J`YoDvOjpvWm#@_?yV*Xb!Fmon z7}s&Lng_T7oY>hdd%BDr)K}~yy*}2Z{wk=wWcpGpQbg52kfYjaFDi}@`)z(@hy5n* z`s<6kmIw9Bskcg8Wqj$m*gKyO`9bCic&U@-VcXv?zcnyeu-Qrc#-Ub)W&nLEb4xZ5 zew8}Q0f2BjHl>;Nc!GL%y@6T69Wu!$|f2{SX;XBy+|Px)Ti8HDVUs#6s>H$oigc~i8FfksxP~=XK~w`zZ5Mu zTqBy6yNd5VU1P=a3E<3Up3DsA=Y~&u5{}~5#%uR+M4IgPdD@+lQBC$8l-ZfcPBxS4 zG}{qRU#^IbS}_!2h7fQSr0g}UIL9pbl)9vvA&X>c#2GS!Gt104OV)IeL?Q zfGs)w;(~61W`5$VajTW}hX0wkYzq-c&#TfIc64|*{khtuk0}+Y%}hH_#}@3Nn`v*e zVi5kzY%5Y(45h;!FM;rMpGtxFJSY#OMcAMUtc{v#F)yO0F*W{?&-SR1QIb{SjlCLg z96|45sLw2&_(81CLh#i)*J_CMrJGs9n56D8CB^-p zrgYq=wWkfF6-y5D$C}MWOVaYj+|~Os zvs8l~XIop20pNl-Sc{8?agOEd=$`}CZ0K^bS9)B!kr5&_0efK#TJS4+KMF6v0NjrXWJlCt5Q0|mQWjNj9_1L?7`jt=&f#{NSEcq$X@{hq2pW5J6-IB)o)z=dBv|^b zh^%VgDX?lrec=-F8`N`oL1s|uUp<}tN+7`%sNv?&sQzWiZNI0;ciOq-up>||>$F#l zmeUtmUHo(h7m=E*(NvD7KMW*Da)w;YY zD56`NfKh#FbKCS?|&Kr$zZ3&l*h)BvTaNMB3i?89-3tNTrX>Z<{X=S7x zc;MEgh14zGi%n=B^Q>)+QAZHc_T4-yz7=s0ywJs31UA?FUx`4XZF$#r$+t(barIt+ zcD4B;>;yI$TEX;ID+h}NDKkKcK-PTsvp0Qre~?t3G$VC{DALPvVG zN+iLFf8Lg!~Wr1zSgQqH*8f zwD4M)&4)}YfOaEwyDP5aY{t1NKNpC!vCm#DcM$UcnKMTB4tyLN&(2O7ppx$aVQN*C z#Qi$mW4p`vKE9THK32vfOJ=UC;^|tI8Y;{(123<>Q@=U;M<=t=j>oyUV8XN!x1vGs zX13~xb7A7go{IbnBIb?&i5aG5(0osKiM(r$O=9<|vS!-S$YPL(xv&yn<*+B7vn%;J#W{p#-}y zSEKy1MWbZC3epiz4Hc=b&}F;rf^y(lHub2XAJL1QGvk$VqBo}%&zRt9={<+0p`4dg zYu7IFZ8dRq?BGJljghn&lVjo!$|^iOLOuAwDg~sdB!{FhrN5F`x_ADcn-QJ&j{J1$QJ^rZ3aSUiaYqmpis*6=Gz^2Tw=KCwd0WOCU zN2@u?d!I;j9fHMM{#2>fi(S?E;+#S$1ko!^5&*+6q z8m7ZkQ}jcIHP6GETD~3wN_NWD@41289liOwSWOt}92OH9$>Sz}$Tyt5+hh&h zC?v%1iyJCrW?mSEyYy_n2S0mCdrPxj7r&<@RLZx}#4deJUG{XjX0EW&mNzQwVU8Pg z;Sxu1wlxmxaeXN(s|nP<-kf3UaimAtt*JUbpY3(oST$v;l679sXi=)%r?^h&xzNLF z4gOhIVTjw@Ucx2W*n5i^Wo&Up=cA~E-sHv~-kyF=P!QCdW*~9BiJ0QzM-_g$L01J0 z*^kiL(%O_JzZy97>Np0N0QdUCO$?&*#!0c$?RnV(4uem7dQhp)?SD>vIzwkY(o_#Q&)N0~<>Bp{lBK)ZpB~c7+AYA6Uw==*!j(HCg2`=qAy6w& zb?Xf#8GPs3h}it;-W3tu;<54wB>*ZZFn!nX(YrOXpj*+m+Vk@CqkMH7+4q<&hyhEm zY!q8uv}o}bf?9<<@syC`irwePb?l#n=$|)dJr&S;jxvzv`Y=4q7Zkk_FzC`WkfuDz zg()HHinD$HZSyUmyv}ZE?8So1M ztJLk-Me@bEMDd{S$ADnVLdsmW3Czrw>VvowX^A4Yn#f{R=^nyS$Bb*s3R;-@z#I-y(o*%8l zED}kXEwHiX<|XgAYe_m~hKX`TAULqgNzUgSX@7m-OV^e$ADJ_RX+0kA9q#qkjUheQ-~nojRiuS@|k%CzxQ7H?WeuA}%H{c6K;FDP9PBy|hW1 zShJl-Q}T&HR73lz&VgKk?|HE!jrU)ZVa7g5P}Rt~lKqKSGVd~ta2H0u-Hs0~dXzUZ zxJ5Ici$JvbW;vUSHeYMU6Jya)X%^tpwqJ8Jj4W6hOF5Fky+Kj#uE#Ozn65p&hr*u&6=>54v zTBhpVIz%d$eh{bXfXbE+WIs1K6z#WLat!#8+F7Wnu(XZ-)YsPVg|clFQT+@ao*)=% zPE{^6B3(W;VnTbx85n-yLGOz<4`bBOEJx&10nHe0pwGQ8#2Bbft&1V3z%OITFig&` zfL7&{Jk zm4q_x5=F}n$m(@Tr+rPZJReUv##mN4xsH>IE?JmC`RUDyfti;F8uyF(z9*yN&aiV< zw}$z{Zw}3Fgy}v|PSKcFH`1=`HLupFxg`0M^Q^D%1%GG-v#lNj6MNq=K>wJszN%ed zG~E%rES^}WUZifSp%1O-PM@fN0eBpK?CQVACI*a>ynBBtxgo-2L-zQIpRW7Qqyv88 zYUJIx0_r>LEE7>|Ht7Z~bNfl;txfjjYDQ1QsoiUh>r2xfrFQQoHrnSbO#Rrbr~x|R zS8nzj*$T<5I&NpbZ{Z0O;|~VMBeX>ZIhaZfkwD0544fuu0kXmLYUlThrd&Tm5u(>~`6>UUHr?mo;iuo;kxcxt^9f1xzC<*{81 zSc~6!HjGkFD7Wn`!$w(+dzC4kJjnFZj!`e_4 zc*K`b8lKNhoL`y{{Xgw8DA<*M^Z8?tA%zp0F;6INgp}6J;5ak1TUF!G!Ln2=_ zbqJ4=tLaR}t-a4DXjZNze;S~6rPd;TpN*|)N~!6{aL--aT0NA_Ff&@>VehMtDRp-K z6rC>t;Fb&Xf-g~yoJn7($rPJR?W>49x29d)C9j@kI=-u+_lO{1_4t?HNGtI9GK_0Q z&Rxf;;QffFTKPcwT72&I)y7`hnw`tF;e$O}wP(9Ujh+-y&;i~LcrpF-y#+idu+_XKt zJ}kKoZxbo|Mt^=hcdv~{kj%2h%(_?{U*_|q$ctQ7O3Y|3zoB>9-BF!y-ySZFYrN>{ zJ`vEPnZFj13;Oxtl#kWt^HE>jXFAVA1}SS9gA1vdN>_5~9PN&*!e5rxtxY*;PjMUA zHRSm={d)Ze*Y>2sPZZZ)C2_B7>Uvfsutqa&jN%sVnWYGA@_YwPY}gDn-xK)q57QQv zb77YpR#reOJMy=`(A{7A9{qlplArnp-yIjP4XRCu0fu2q5)R4mbduDPoOqCQR_kke zo2VwwhHP?1^ABbbmnd3?=EcR4lFwb5J)w?X^(Uk=bgQOVk$L8gU)CDdG=^^Otd}%< zc5Es5?1o!q?I!LIZBkYQY(9s2FM8L2(Uip{mSo68DXc+nZ9Ic4Tsw@zZeLvX>JVcXf3YbA^f#9IeD5 za5!9CLQ-5(Qj{VgN_4YxLXt%7i2Q#e+`>skl&-|8nF1lqTxB*<-{XV2A`~M-)cI z1!L#L|F=3C^^dN-v!m_r0MICLj4cLF5hGHpLH;pyQt0@P^hv;0SiJpj4GOdWNI79G z|3l0F@aN>tZ}@?|(@C9p{N4g$%h{1eEiMKkBy-;1i>AXaWk0miyhrSV*DZ zmNIBjOBpCiR0;x@6-7d%k)krvma;H390`$uL;l85w<9_s?NFE#915}+mI5LpiAG7n zAy82$T#BM^0h1JkVI*WlEirH@2pWyDl$J*St*_;XrDPn^_P_gcf`g{uNJz@aNXVe1 zM5Uon2nELyB?^a0AVn=LBqSx^NNE`v85EcgjgnI(IO36%M~1~CtuW%Q7z=wa-wCyH zO838;D72^PxACn-qo-~ z%5As5GG7Pd@K?(g%lA9) -b 115200 + +Replace :code:`` with the port where the nRF9131 EK +can be found. For example, under Linux, :code:`/dev/ttyACM0`. + +Then build and flash the application in the usual way. + +.. zephyr-app-commands:: + :zephyr-app: samples/hello_world + :board: nrf9131ek_nrf9131 + :goals: build flash + +Debugging +========= + +Refer to the :ref:`nordic_segger` page to learn about debugging Nordic boards with a +Segger IC. + + +Testing the LEDs and buttons in the nRF9131 EK +********************************************** + +There are 2 samples that allow you to test that the button and LED on +the board are working properly with Zephyr: + +* :zephyr:code-sample:`blinky` +* :zephyr:code-sample:`button` + +You can build and flash the examples to make sure Zephyr is running correctly on +your board. The button and LED definitions can be found in +:zephyr_file:`boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi`. + +References +********** + +.. target-notes:: + +.. _IDAU: + https://developer.arm.com/docs/100690/latest/attribution-units-sau-and-idau +.. _Nordic Semiconductor Infocenter: https://infocenter.nordicsemi.com +.. _Trusted Firmware M: https://www.trustedfirmware.org/projects/tf-m/ diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi index 35314cd0784..2c3b8481d2a 100644 --- a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi +++ b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi @@ -20,7 +20,7 @@ compatible = "gpio-leds"; led0: led_0 { gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; - label = "Green LED 1"; + label = "Red LED 1"; }; led1: led_1 { gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; @@ -28,7 +28,7 @@ }; led2: led_2 { gpios = <&gpio0 31 GPIO_ACTIVE_HIGH>; - label = "Green LED 3"; + label = "Blue LED 3"; }; }; From 56f475ad3e6fe5583a7478db6dfa47fad3485d35 Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Thu, 16 Nov 2023 14:19:25 +0100 Subject: [PATCH 0412/1623] [nrf noup] boards: arm: nrf9131ek: fix docs build This patch backports the nrf9131ek docs. To be reverted when after the next Zephyr update. Signed-off-by: Maximilian Deubel --- boards/arm/nrf9131ek_nrf9131/doc/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boards/arm/nrf9131ek_nrf9131/doc/index.rst b/boards/arm/nrf9131ek_nrf9131/doc/index.rst index a72cd1526e3..ffb066d860d 100644 --- a/boards/arm/nrf9131ek_nrf9131/doc/index.rst +++ b/boards/arm/nrf9131ek_nrf9131/doc/index.rst @@ -210,8 +210,8 @@ Testing the LEDs and buttons in the nRF9131 EK There are 2 samples that allow you to test that the button and LED on the board are working properly with Zephyr: -* :zephyr:code-sample:`blinky` -* :zephyr:code-sample:`button` +* :ref:`blinky-sample` +* :ref:`button-sample` You can build and flash the examples to make sure Zephyr is running correctly on your board. The button and LED definitions can be found in From a69bb9315bcd02096bbf27f13038a5c0a1706632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Mon, 16 Oct 2023 12:46:29 +0200 Subject: [PATCH 0413/1623] [nrf fromtree] tfm: Enable TFM_EXCEPTION_INFO_DUMP by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exception info dump is a very basic feature so it should IMHO be enabled by default. For instance, a simple null-pointer exception in the non-secure app will not be logged unless this option is enabled. Signed-off-by: Sebastian Bøe (cherry picked from commit a4e9aed68de223968e43f4ea4fa1abdda5b49c26) Signed-off-by: Joakim Andersson --- modules/trusted-firmware-m/Kconfig.tfm | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index bafa5cf0bab..2a5edb64343 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -446,6 +446,7 @@ endchoice config TFM_EXCEPTION_INFO_DUMP bool "TF-M exception info dump" + default y help On fatal errors in the secure firmware, capture info about the exception. Print the info if the SPM log level is sufficient. From b96a183abe7f07a90ba844c7928740d2c1b3c96c Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Wed, 15 Nov 2023 18:04:28 +0100 Subject: [PATCH 0414/1623] [nrf fromlist] tfm: Fix include order between platform_ns and tfm_api_ns libraries Fix include order between platform_ns and tfm_api_ns libraries. platform_ns functions may depend on tfm_api_ns. This would typically be platform specific IOCTL services added to the platform_ns library requiring the tfm_platform_ioctl from the TF-M platform partition exposed in tfm_platform_api.c Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65253 Signed-off-by: Joakim Andersson --- modules/trusted-firmware-m/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index f00116cda2c..177a47e28d6 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -435,8 +435,8 @@ if (CONFIG_BUILD_WITH_TFM) else() zephyr_library_link_libraries( - ${TFM_API_NS_PATH} ${PLATFORM_NS_FILE} + ${TFM_API_NS_PATH} ) endif() From 1687aaaac27cce09921a015a3f63c79666ebdc37 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 16 Nov 2023 14:29:55 +0100 Subject: [PATCH 0415/1623] [nrf fromlist] tfm: Change SFN and FP_HARDABI dependency TF-M only suports floating point in IPC model, not the SFN model. Since floating point is a basic feature of the architecture and TF-M has the limitation it makes more sense for the dependency to exist in TF-M and and limit the TF-M model choice instead of limiting the option to enable floating point. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65304 Signed-off-by: Joakim Andersson --- arch/arm/core/aarch32/Kconfig | 1 - modules/trusted-firmware-m/Kconfig.tfm | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/core/aarch32/Kconfig b/arch/arm/core/aarch32/Kconfig index a14bcd0cb62..58d5253cb94 100644 --- a/arch/arm/core/aarch32/Kconfig +++ b/arch/arm/core/aarch32/Kconfig @@ -267,7 +267,6 @@ config FP_HARDABI # TF-M build system does not build the NS app and libraries correctly with Hard ABI. # This limitation should be removed in the next TF-M synchronization. depends on !TFM_BUILD_NS - depends on !(BUILD_WITH_TFM && !TFM_IPC) help This option selects the Floating point ABI in which hardware floating point instructions are generated and uses FPU-specific calling diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index 2a5edb64343..c09d922e9fd 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -323,6 +323,7 @@ config TFM_IPC config TFM_SFN bool "SFN model" + depends on !FP_HARDABI help Use the SFN Model as the SPM backend for the PSA API. The SFN model supports the SFN Partition model, and isolation level 1. From af993b28c1dcde6c52e55517801628b82429ad78 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 14 Nov 2023 14:31:37 +0100 Subject: [PATCH 0416/1623] [nrf fromlist] net: pkt: Add function for allocating buffers w/o preconditions Add new function to allocate additional buffers for net_pkt, w/o any additional preconditions/checks. Just allocate what was requested. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65251 Signed-off-by: Robert Lubos --- include/zephyr/net/net_pkt.h | 25 +++++++++++++++ subsys/net/ip/net_pkt.c | 61 ++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/include/zephyr/net/net_pkt.h b/include/zephyr/net/net_pkt.h index d4011d1f582..199f78d2361 100644 --- a/include/zephyr/net/net_pkt.h +++ b/include/zephyr/net/net_pkt.h @@ -1678,6 +1678,13 @@ int net_pkt_alloc_buffer_debug(struct net_pkt *pkt, net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \ __func__, __LINE__) +int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size, + k_timeout_t timeout, + const char *caller, int line); +#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \ + net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \ + __func__, __LINE__) + struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface, size_t size, sa_family_t family, @@ -1792,6 +1799,24 @@ int net_pkt_alloc_buffer(struct net_pkt *pkt, k_timeout_t timeout); #endif +/** + * @brief Allocate buffer for a net_pkt, of specified size, w/o any additional + * preconditions + * + * @details: The actual buffer size may be larger than requested one if fixed + * size buffers are in use. + * + * @param pkt The network packet requiring buffer to be allocated. + * @param size The size of buffer being requested. + * @param timeout Maximum time to wait for an allocation. + * + * @return 0 on success, negative errno code otherwise. + */ +#if !defined(NET_PKT_DEBUG_ENABLED) +int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size, + k_timeout_t timeout); +#endif + /** * @brief Allocate a network packet and buffer at once * diff --git a/subsys/net/ip/net_pkt.c b/subsys/net/ip/net_pkt.c index 57ba0f3bb0d..fb44490dd2b 100644 --- a/subsys/net/ip/net_pkt.c +++ b/subsys/net/ip/net_pkt.c @@ -1197,6 +1197,67 @@ int net_pkt_alloc_buffer(struct net_pkt *pkt, return 0; } + +#if NET_LOG_LEVEL >= LOG_LEVEL_DBG +int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size, + k_timeout_t timeout, const char *caller, + int line) +#else +int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size, + k_timeout_t timeout) +#endif +{ + struct net_buf_pool *pool = NULL; + struct net_buf *buf; + + if (size == 0) { + return 0; + } + + if (k_is_in_isr()) { + timeout = K_NO_WAIT; + } + + NET_DBG("Data allocation size %zu", size); + + if (pkt->context) { + pool = get_data_pool(pkt->context); + } + + if (!pool) { + pool = pkt->slab == &tx_pkts ? &tx_bufs : &rx_bufs; + } + +#if NET_LOG_LEVEL >= LOG_LEVEL_DBG + buf = pkt_alloc_buffer(pool, size, timeout, caller, line); +#else + buf = pkt_alloc_buffer(pool, size, timeout); +#endif + + if (!buf) { +#if NET_LOG_LEVEL >= LOG_LEVEL_DBG + NET_ERR("Data buffer (%zd) allocation failed (%s:%d)", + size, caller, line); +#else + NET_ERR("Data buffer (%zd) allocation failed.", size); +#endif + return -ENOMEM; + } + + net_pkt_append_buffer(pkt, buf); + +#if IS_ENABLED(CONFIG_NET_BUF_FIXED_DATA_SIZE) + /* net_buf allocators shrink the buffer size to the requested size. + * We don't want this behavior here, so restore the real size of the + * last fragment. + */ + buf = net_buf_frag_last(buf); + buf->size = CONFIG_NET_BUF_DATA_SIZE; +#endif + + return 0; +} + #if NET_LOG_LEVEL >= LOG_LEVEL_DBG static struct net_pkt *pkt_alloc(struct k_mem_slab *slab, k_timeout_t timeout, const char *caller, int line) From 2242e9c7569a3651e2a07c11e0e24e2212e3dbd9 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 14 Nov 2023 12:40:49 +0100 Subject: [PATCH 0417/1623] [nrf fromlist] net: tcp: Rework data queueing API Rework how data is queued for the TCP connections: * net_context no longer allocates net_pkt for TCP connections. This was not only inefficient (net_context has no knowledge of the TX window size), but also error-prone in certain configuration (for example when IP fragmentation was enabled, net_context may attempt to allocate enormous packet, instead of let the data be fragmented for the TCP stream. * Instead, implement already defined `net_tcp_queue()` API, which takes raw buffer and length. This allows to take TX window into account and also better manage the allocated net_buf's (like for example avoid allocation if there's still room in the buffer). In result, the TCP stack will not only no longer exceed the TX window, but also prevent empty gaps in allocated net_buf's, which should lead to less out-of-mem issues with the stack. * As net_pkt-based `net_tcp_queue_data()` is no longer in use, it was removed. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65251 Signed-off-by: Robert Lubos --- subsys/net/ip/net_context.c | 27 +++--- subsys/net/ip/tcp.c | 166 +++++++++++++++++++++-------------- subsys/net/ip/tcp.h | 15 +--- subsys/net/ip/tcp_internal.h | 20 +++-- 4 files changed, 132 insertions(+), 96 deletions(-) diff --git a/subsys/net/ip/net_context.c b/subsys/net/ip/net_context.c index 1372398185a..6af67103721 100644 --- a/subsys/net/ip/net_context.c +++ b/subsys/net/ip/net_context.c @@ -1480,7 +1480,7 @@ static int context_sendto(struct net_context *context, { const struct msghdr *msghdr = NULL; struct net_if *iface; - struct net_pkt *pkt; + struct net_pkt *pkt = NULL; size_t tmp_len; int ret; @@ -1689,6 +1689,15 @@ static int context_sendto(struct net_context *context, return -ENETDOWN; } + context->send_cb = cb; + context->user_data = user_data; + + if (IS_ENABLED(CONFIG_NET_TCP) && + net_context_get_proto(context) == IPPROTO_TCP && + !net_if_is_ip_offloaded(net_context_get_iface(context))) { + goto skip_alloc; + } + pkt = context_alloc_pkt(context, len, PKT_WAIT_TIME); if (!pkt) { NET_ERR("Failed to allocate net_pkt"); @@ -1707,9 +1716,6 @@ static int context_sendto(struct net_context *context, len = tmp_len; } - context->send_cb = cb; - context->user_data = user_data; - if (IS_ENABLED(CONFIG_NET_CONTEXT_PRIORITY)) { uint8_t priority; @@ -1731,6 +1737,7 @@ static int context_sendto(struct net_context *context, } } +skip_alloc: if (IS_ENABLED(CONFIG_NET_OFFLOAD) && net_if_is_ip_offloaded(net_context_get_iface(context))) { ret = context_write_data(pkt, buf, len, msghdr); @@ -1762,16 +1769,12 @@ static int context_sendto(struct net_context *context, } else if (IS_ENABLED(CONFIG_NET_TCP) && net_context_get_proto(context) == IPPROTO_TCP) { - ret = context_write_data(pkt, buf, len, msghdr); + ret = net_tcp_queue(context, buf, len, msghdr); if (ret < 0) { goto fail; } - net_pkt_cursor_init(pkt); - ret = net_tcp_queue_data(context, pkt); - if (ret < 0) { - goto fail; - } + len = ret; ret = net_tcp_send_data(context, cb, user_data); } else if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET) && @@ -1827,7 +1830,9 @@ static int context_sendto(struct net_context *context, return len; fail: - net_pkt_unref(pkt); + if (pkt != NULL) { + net_pkt_unref(pkt); + } return ret; } diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index ad9cd1e4c98..2e70824b8ed 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -1252,6 +1252,49 @@ static int tcp_pkt_peek(struct net_pkt *to, struct net_pkt *from, size_t pos, return net_pkt_copy(to, from, len); } +static int tcp_pkt_append(struct net_pkt *pkt, const uint8_t *data, size_t len) +{ + size_t alloc_len = len; + struct net_buf *buf = NULL; + int ret = 0; + + if (pkt->buffer) { + buf = net_buf_frag_last(pkt->buffer); + + if (len > net_buf_tailroom(buf)) { + alloc_len -= net_buf_tailroom(buf); + } else { + alloc_len = 0; + } + } + + if (alloc_len > 0) { + ret = net_pkt_alloc_buffer_raw(pkt, alloc_len, + TCP_PKT_ALLOC_TIMEOUT); + if (ret < 0) { + return -ENOBUFS; + } + } + + if (buf == NULL) { + buf = pkt->buffer; + } + + while (buf != NULL && len > 0) { + size_t write_len = MIN(len, net_buf_tailroom(buf)); + + net_buf_add_mem(buf, data, write_len); + + data += write_len; + len -= write_len; + buf = buf->frags; + } + + NET_ASSERT(len == 0, "Not all bytes written"); + + return ret; +} + static bool tcp_window_full(struct tcp *conn) { bool window_full = (conn->send_data_total >= conn->send_win); @@ -3055,13 +3098,12 @@ int net_tcp_update_recv_wnd(struct net_context *context, int32_t delta) return ret; } -/* net_context queues the outgoing data for the TCP connection */ -int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt) +int net_tcp_queue(struct net_context *context, const void *data, size_t len, + const struct msghdr *msg) { struct tcp *conn = context->tcp; - struct net_buf *orig_buf = NULL; + size_t queued_len = 0; int ret = 0; - size_t len; if (!conn || conn->state != TCP_ESTABLISHED) { return -ENOTCONN; @@ -3078,72 +3120,69 @@ int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt) goto out; } - len = net_pkt_get_len(pkt); + if (msg) { + len = 0; - if (conn->send_data->buffer) { - orig_buf = net_buf_frag_last(conn->send_data->buffer); + for (int i = 0; i < msg->msg_iovlen; i++) { + len += msg->msg_iov[i].iov_len; + } } - net_pkt_append_buffer(conn->send_data, pkt->buffer); - conn->send_data_total += len; - NET_DBG("conn: %p Queued %zu bytes (total %zu)", conn, len, - conn->send_data_total); - pkt->buffer = NULL; + /* Queue no more than TX window permits. It's guaranteed at this point + * that conn->send_data_total is less than conn->send_win, as it was + * verified in tcp_window_full() check above. As the connection mutex + * is held, their values shall not change since. + */ + len = MIN(conn->send_win - conn->send_data_total, len); + + if (msg) { + for (int i = 0; i < msg->msg_iovlen; i++) { + int iovlen = MIN(msg->msg_iov[i].iov_len, len); + + ret = tcp_pkt_append(conn->send_data, + msg->msg_iov[i].iov_base, + iovlen); + if (ret < 0) { + if (queued_len == 0) { + goto out; + } else { + break; + } + } + queued_len += iovlen; + len -= iovlen; + + if (len == 0) { + break; + } + } + } else { + ret = tcp_pkt_append(conn->send_data, data, len); + if (ret < 0) { + goto out; + } + + queued_len = len; + } + + conn->send_data_total += queued_len; + + /* Successfully queued data for transmission. Even if there's a transmit + * failure now (out-of-buf case), it can be ignored for now, retransmit + * timer will take care of queued data retransmission. + */ ret = tcp_send_queued_data(conn); if (ret < 0 && ret != -ENOBUFS) { tcp_conn_close(conn, ret); goto out; } - if ((ret == -ENOBUFS) && - (conn->send_data_total < (conn->unacked_len + len))) { - /* Some of the data has been sent, we cannot remove the - * whole chunk, the remainder portion is already - * in the send_data and will be transmitted upon a - * received ack or the next send call - * - * Set the return code back to 0 to pretend we just - * transmitted the chunk - */ - ret = 0; + if (tcp_window_full(conn)) { + (void)k_sem_take(&conn->tx_sem, K_NO_WAIT); } - if (ret == -ENOBUFS) { - /* Restore the original data so that we do not resend the pkt - * data multiple times. - */ - conn->send_data_total -= len; - - if (orig_buf) { - pkt->buffer = orig_buf->frags; - orig_buf->frags = NULL; - } else { - pkt->buffer = conn->send_data->buffer; - conn->send_data->buffer = NULL; - } - - /* If we have out-of-bufs case, and the send_data buffer has - * become empty, till the retransmit timer, as there is no - * data to retransmit. - * The socket layer will catch this and resend data if needed. - * Only perform this when it is just the newly added packet, - * otherwise it can disrupt any pending transmission - */ - if (conn->send_data_total == 0) { - NET_DBG("No bufs, cancelling retransmit timer"); - k_work_cancel_delayable(&conn->send_data_timer); - } - } else { - if (tcp_window_full(conn)) { - (void)k_sem_take(&conn->tx_sem, K_NO_WAIT); - } - - /* We should not free the pkt if there was an error. It will be - * freed in net_context.c:context_sendto() - */ - tcp_pkt_unref(pkt); - } + ret = queued_len; out: k_mutex_unlock(&conn->lock); @@ -3498,7 +3537,9 @@ static size_t tp_tcp_recv_cb(struct tcp *conn, struct net_pkt *pkt) net_pkt_pull(up, net_pkt_get_len(up) - len); - net_tcp_queue_data(conn->context, up); + for (struct net_buf *buf = pkt->buffer; buf != NULL; buf = buf->frags) { + net_tcp_queue(conn->context, buf->data, buf->len); + } return len; } @@ -3641,12 +3682,7 @@ enum net_verdict tp_input(struct net_conn *net_conn, responded = true; NET_DBG("tcp_send(\"%s\")", tp->data); { - struct net_pkt *data_pkt; - - data_pkt = tcp_pkt_alloc(conn, len); - net_pkt_write(data_pkt, buf, len); - net_pkt_cursor_init(data_pkt); - net_tcp_queue_data(conn->context, data_pkt); + net_tcp_queue(conn->context, buf, len); } } break; diff --git a/subsys/net/ip/tcp.h b/subsys/net/ip/tcp.h index f6f481d5443..162407710eb 100644 --- a/subsys/net/ip/tcp.h +++ b/subsys/net/ip/tcp.h @@ -31,6 +31,7 @@ extern "C" { #endif +#include #include /** @@ -72,18 +73,7 @@ int net_tcp_listen(struct net_context *context); */ int net_tcp_accept(struct net_context *context, net_tcp_accept_cb_t cb, void *user_data); -/** - * @brief Enqueue data for transmission - * - * @param context Network context - * @param buf Pointer to the data - * @param len Number of bytes - * @param msghdr Data for a vector array operation - * - * @return 0 if ok, < 0 if error - */ -int net_tcp_queue(struct net_context *context, const void *buf, size_t len, - const struct msghdr *msghdr); + /* TODO: split into 2 functions, conn -> context, queue -> send? */ /* The following functions are provided solely for the compatibility @@ -112,7 +102,6 @@ void net_tcp_init(void); #define net_tcp_init(...) #endif int net_tcp_update_recv_wnd(struct net_context *context, int32_t delta); -int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt); int net_tcp_finalize(struct net_pkt *pkt); #if defined(CONFIG_NET_TEST_PROTOCOL) diff --git a/subsys/net/ip/tcp_internal.h b/subsys/net/ip/tcp_internal.h index e76ba859e49..17d4581aa3d 100644 --- a/subsys/net/ip/tcp_internal.h +++ b/subsys/net/ip/tcp_internal.h @@ -282,21 +282,27 @@ struct net_tcp_hdr *net_tcp_input(struct net_pkt *pkt, #endif /** - * @brief Enqueue a single packet for transmission + * @brief Enqueue data for transmission * - * @param context TCP context - * @param pkt Packet + * @param context Network context + * @param data Pointer to the data + * @param len Number of bytes + * @param msg Data for a vector array operation * * @return 0 if ok, < 0 if error */ #if defined(CONFIG_NET_NATIVE_TCP) -int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt); +int net_tcp_queue(struct net_context *context, const void *data, size_t len, + const struct msghdr *msg); #else -static inline int net_tcp_queue_data(struct net_context *context, - struct net_pkt *pkt) +static inline int net_tcp_queue(struct net_context *context, const void *data, + size_t len, const struct msghdr *msg) { ARG_UNUSED(context); - ARG_UNUSED(pkt); + ARG_UNUSED(data); + ARG_UNUSED(len); + ARG_UNUSED(msg); + return -EPROTONOSUPPORT; } #endif From f165bb7517c01c00eb42db01404408d7a2731ce0 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 15 Nov 2023 16:32:22 +0100 Subject: [PATCH 0418/1623] [nrf fromlist] net: tcp: Feed TX semaphore on connection close Otherwise, if the application was for example blocked on poll() pending POLLOUT, it won't be notified. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65251 Signed-off-by: Robert Lubos --- subsys/net/ip/tcp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index 2e70824b8ed..680fdcecb85 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -621,6 +621,8 @@ static int tcp_conn_close(struct tcp *conn, int status) status, conn->recv_user_data); } + k_sem_give(&conn->tx_sem); + return tcp_conn_unref(conn); } From 67fddd31afce6d47ae8645fc40a4479e26d23965 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 15 Nov 2023 16:33:24 +0100 Subject: [PATCH 0419/1623] [nrf fromlist] net: sockets: tls: Set errno on TX waiting error In case underlying socket reported error while waiting for TX, the errno value was not set accordingly. This commit fixes this. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65251 Signed-off-by: Robert Lubos --- subsys/net/lib/sockets/sockets_tls.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/subsys/net/lib/sockets/sockets_tls.c b/subsys/net/lib/sockets/sockets_tls.c index 20fdc3617af..f77bf51d668 100644 --- a/subsys/net/lib/sockets/sockets_tls.c +++ b/subsys/net/lib/sockets/sockets_tls.c @@ -2230,10 +2230,9 @@ static ssize_t send_tls(struct tls_context *ctx, const void *buf, timeout_ms = timeout_to_ms(&timeout); ret = wait_for_reason(ctx->sock, timeout_ms, ret); if (ret != 0) { - /* Retry. */ + errno = -ret; break; } - } else { (void)tls_mbedtls_reset(ctx); errno = EIO; From e8c9775db7c7dbdb833e025038d6067983ae4cad Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 15 Nov 2023 17:49:00 +0100 Subject: [PATCH 0420/1623] [nrf fromlist] net: zperf: Fix TCP packet counting Make sure we send the entire packet buffer before bumping the packet counter, send() does not guarantee that all of the requested data will be sent at once with STREAM socket. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65251 Signed-off-by: Robert Lubos --- subsys/net/lib/zperf/zperf_tcp_uploader.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/zperf/zperf_tcp_uploader.c b/subsys/net/lib/zperf/zperf_tcp_uploader.c index 3e72f81e54b..5fcc0530c5c 100644 --- a/subsys/net/lib/zperf/zperf_tcp_uploader.c +++ b/subsys/net/lib/zperf/zperf_tcp_uploader.c @@ -20,6 +20,22 @@ static char sample_packet[PACKET_SIZE_MAX]; static struct zperf_async_upload_context tcp_async_upload_ctx; +static ssize_t sendall(int sock, const void *buf, size_t len) +{ + while (len) { + ssize_t out_len = zsock_send(sock, buf, len, 0); + + if (out_len < 0) { + return out_len; + } + + buf = (const char *)buf + out_len; + len -= out_len; + } + + return 0; +} + static int tcp_upload(int sock, unsigned int duration_in_ms, unsigned int packet_size, @@ -50,7 +66,7 @@ static int tcp_upload(int sock, do { /* Send the packet */ - ret = zsock_send(sock, sample_packet, packet_size, 0); + ret = sendall(sock, sample_packet, packet_size); if (ret < 0) { if (nb_errors == 0 && ret != -ENOMEM) { NET_ERR("Failed to send the packet (%d)", errno); From f51a3a880d04f082e92dfc478d6dfdbdea8304e3 Mon Sep 17 00:00:00 2001 From: Eduardo Montoya Date: Thu, 9 Nov 2023 11:33:31 +0100 Subject: [PATCH 0421/1623] [nrf fromtree] net: openthread: upmerge to `6edb06e` Regular OpenThread upmerge to `6edb06e`. Also add `OPENTHREAD_CSL_RECEIVER_LOCAL_TIME_SYNC` config. Signed-off-by: Eduardo Montoya (cherry picked from commit 3508cd609c9e13b21b10d592ee4ef5f3817f787e) Signed-off-by: Maciej Baczmanski --- modules/openthread/CMakeLists.txt | 6 ++++++ modules/openthread/Kconfig.features | 7 +++++++ west.yml | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index 826d9b31590..bad6d131771 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -148,6 +148,12 @@ else() set(OT_CSL_RECEIVER OFF CACHE BOOL "Enable CSL receiver feature for Thread 1.2" FORCE) endif() +if(CONFIG_OPENTHREAD_CSL_RECEIVER_LOCAL_TIME_SYNC) + set(OT_CSL_RECEIVER_LOCAL_TIME_SYNC ON CACHE BOOL "Use local time for CSL sync" FORCE) +else() + set(OT_CSL_RECEIVER_LOCAL_TIME_SYNC OFF CACHE BOOL "Use local time for CSL sync" FORCE) +endif() + if(CONFIG_OPENTHREAD_DATASET_UPDATER) set(OT_DATASET_UPDATER ON CACHE BOOL "Enable Dataset updater" FORCE) else() diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index 87c220944a4..a75c9e8fd48 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -92,6 +92,13 @@ config OPENTHREAD_CSL_RECEIVER help Enable CSL Receiver support for Thread 1.2 +config OPENTHREAD_CSL_RECEIVER_LOCAL_TIME_SYNC + bool "Use local time for CSL synchronization" + help + Use host time rather than radio platform time to track elapsed time + since last CSL synchronization. This reduces the usage of radio API + calls, and it is useful for platforms in which those are costly. + config OPENTHREAD_DEVICE_PROP_LEADER_WEIGHT bool "Device props for leader weight" default n if (OPENTHREAD_THREAD_VERSION_1_1 || \ diff --git a/west.yml b/west.yml index 1847e94b37c..93db410ea77 100644 --- a/west.yml +++ b/west.yml @@ -303,7 +303,7 @@ manifest: revision: 42b7c577714b8f22ce82a901e19c1814af4609a8 path: modules/lib/open-amp - name: openthread - revision: d62167ee34b091e7025c9ec2820aae71e17a3944 + revision: 6edb06e4e0472411200ce2a084a783eaf3faffe3 path: modules/lib/openthread - name: picolibc path: modules/lib/picolibc From 5ba9369a4ed737d05145d892516d44f2f439eba3 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 21 Nov 2023 17:40:23 +0100 Subject: [PATCH 0422/1623] [nrf fromlist] tfm: Remove SFN model FP limitation Despite what the TF-M documentation says about SFN model not supporting Floating Point, it does support it, according to TF-M developers. Remove SFN limitation not supported with FP Hard ABI. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65537 Signed-off-by: Joakim Andersson --- arch/arm/core/aarch32/Kconfig | 2 -- modules/trusted-firmware-m/Kconfig.tfm | 1 - 2 files changed, 3 deletions(-) diff --git a/arch/arm/core/aarch32/Kconfig b/arch/arm/core/aarch32/Kconfig index 58d5253cb94..529d143ef8c 100644 --- a/arch/arm/core/aarch32/Kconfig +++ b/arch/arm/core/aarch32/Kconfig @@ -272,8 +272,6 @@ config FP_HARDABI point instructions are generated and uses FPU-specific calling conventions. - Note: When building with TF-M enabled only the IPC mode is supported. - config FP_SOFTABI bool "Floating point Soft ABI" help diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index c09d922e9fd..2a5edb64343 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -323,7 +323,6 @@ config TFM_IPC config TFM_SFN bool "SFN model" - depends on !FP_HARDABI help Use the SFN Model as the SPM backend for the PSA API. The SFN model supports the SFN Partition model, and isolation level 1. From 90a72daae2c8715d760d974a7d294aa2eb6b38c4 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 21 Nov 2023 19:02:47 +0100 Subject: [PATCH 0423/1623] [nrf fromlist] tfm: Remove limitation of enabling FP when build TF-M NS application Remove limitation of enabling FP when building TF-M NS application. FP support have been fixed in the tf-m-tests repository for NS application. Board support for NS executable may still be lacking for some boards. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65537 Signed-off-by: Joakim Andersson --- arch/arm/core/aarch32/Kconfig | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/arm/core/aarch32/Kconfig b/arch/arm/core/aarch32/Kconfig index 529d143ef8c..c8a48cb7f11 100644 --- a/arch/arm/core/aarch32/Kconfig +++ b/arch/arm/core/aarch32/Kconfig @@ -264,9 +264,6 @@ choice config FP_HARDABI bool "Floating point Hard ABI" - # TF-M build system does not build the NS app and libraries correctly with Hard ABI. - # This limitation should be removed in the next TF-M synchronization. - depends on !TFM_BUILD_NS help This option selects the Floating point ABI in which hardware floating point instructions are generated and uses FPU-specific calling From 0c7fcf3c32a712f5003def83a3607404850dc9e2 Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Mon, 2 Oct 2023 09:12:43 +0200 Subject: [PATCH 0424/1623] [nrf fromlist] net: openthread: Remove waiting for DTR in openthread UART. Uart driver for openthread have been waiting for host to start communicating with coprocessor, during booting of the Zephyr and by that blocking start os OS. There is no longer a need for that since the stack will be soft rebooted after host connects to coprocessor, removing the need to wait on host communication. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/63355 Signed-off-by: Przemyslaw Bida (cherry picked from commit cc85223ed4d5907bd457cb8145672c2167821cbf) --- modules/openthread/platform/uart.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/modules/openthread/platform/uart.c b/modules/openthread/platform/uart.c index dd62d36ee11..ebf156ded15 100644 --- a/modules/openthread/platform/uart.c +++ b/modules/openthread/platform/uart.c @@ -170,7 +170,6 @@ otError otPlatUartEnable(void) if (DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_ot_uart), zephyr_cdc_acm_uart)) { int ret; - uint32_t dtr = 0U; ret = usb_enable(NULL); if (ret != 0 && ret != -EALREADY) { @@ -178,20 +177,6 @@ otError otPlatUartEnable(void) return OT_ERROR_FAILED; } - LOG_INF("Waiting for host to be ready to communicate"); - - /* Data Terminal Ready - check if host is ready to communicate */ - while (!dtr) { - ret = uart_line_ctrl_get(ot_uart.dev, - UART_LINE_CTRL_DTR, &dtr); - if (ret) { - LOG_ERR("Failed to get Data Terminal Ready line state: %d", - ret); - continue; - } - k_msleep(100); - } - /* Data Carrier Detect Modem - mark connection as established */ (void)uart_line_ctrl_set(ot_uart.dev, UART_LINE_CTRL_DCD, 1); /* Data Set Ready - the NCP SoC is ready to communicate */ From 6af59667d730b009cec654671b0a1f3eee0f06fd Mon Sep 17 00:00:00 2001 From: Kyra Lengfeld Date: Fri, 24 Nov 2023 15:44:38 +0100 Subject: [PATCH 0425/1623] [nrf fromtree] Bluetooth: Controller: Add Kconfig for LE Power Control Request Feature Add the controller Kconfig to use in Zephyr. Signed-off-by: Kyra Lengfeld (cherry picked from commit 56a59019559f6bb7237b50644e765306a8b3d527) Signed-off-by: Kyra Lengfeld --- subsys/bluetooth/controller/Kconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 467683705f3..9ba67a05768 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -101,6 +101,9 @@ config BT_CTLR_READ_ISO_LINK_QUALITY_SUPPORT BT_CTLR_PERIPHERAL_ISO_SUPPORT bool +config BT_CTLR_LE_POWER_CONTROL_SUPPORT + bool + config BT_CTLR bool "Bluetooth Controller" help @@ -501,6 +504,14 @@ config BT_CTLR_CONN_RSSI help Enable connection RSSI measurement. +config BT_CTLR_LE_POWER_CONTROL + bool "LE Power Control Request Feature" + depends on BT_CTLR_LE_POWER_CONTROL_SUPPORT + default y if BT_TRANSMIT_POWER_CONTROL + help + Enable support for LE Power Control Request feature that is defined in the + Bluetooth Core specification, Version 5.4 | Vol 6, Part B, Section 4.6.31. + endif # BT_CONN config BT_CTLR_FILTER_ACCEPT_LIST From 90bd9418d718975f0cba8d2a1c3c27fddb10cbcf Mon Sep 17 00:00:00 2001 From: Kyra Lengfeld Date: Thu, 16 Nov 2023 09:09:26 +0100 Subject: [PATCH 0426/1623] [nrf fromtree] Bluetooth: Host: Add LE Power Control Request Procedure APIs This commits adds the LE API's for the LE Power Control Request Feature in Zephyr. The support of feature is provided with the controller-based feature selection with BT_CTLR_LE_POWER_CONTROL_SUPPORT and is selectable via BT_TRANSMIT_POWER_CONTROL. With the new APIs, the applications will: get improved reading of local and remote tx power be aware of changes in remote or local tx power Defined HCI commands in Core Spec v5.4: 7.8.117 LE Enhanced Read Transmit Power Level command: improvement to existing local tx power reading. 7.8.118 LE Read Remote Transmit Power Level command: Remote tx power is read through an event (LE Transmit Power Reporting) 7.8.121 LE Set Transmit Power Reporting Enable command: Enables local or remote tx power reporting to monitor changes in tx power 7.7.65.33 LE Transmit Power Reporting event Note: to utilize the Feature fully Nordic-LL-only vendor-specific commands are needed. These will not be added in RTOS zephyr but instead implemented in a maintainable way in sdk. Signed-off-by: Kyra Lengfeld (cherry picked from commit 93e5cf6e6183ea87eefe3a028a0c39e683446677) Signed-off-by: Kyra Lengfeld --- include/zephyr/bluetooth/conn.h | 87 +++++++++++++++++++++ include/zephyr/bluetooth/hci_types.h | 49 ++++++++++++ subsys/bluetooth/Kconfig | 8 ++ subsys/bluetooth/host/conn.c | 108 +++++++++++++++++++++++++- subsys/bluetooth/host/conn_internal.h | 3 + subsys/bluetooth/host/hci_core.c | 34 ++++++++ 6 files changed, 285 insertions(+), 4 deletions(-) diff --git a/include/zephyr/bluetooth/conn.h b/include/zephyr/bluetooth/conn.h index 9fd78b6a89b..f8a15bea9b8 100644 --- a/include/zephyr/bluetooth/conn.h +++ b/include/zephyr/bluetooth/conn.h @@ -479,6 +479,42 @@ struct bt_conn_le_tx_power { int8_t max_level; }; + +/** LE Transmit Power Reporting Structure */ +struct bt_conn_le_tx_power_report { + + /** Reason for Transmit power reporting, + * as documented in Core Spec. Version 5.4 Vol. 4, Part E, 7.7.65.33. + */ + uint8_t reason; + + /** Phy of Transmit power reporting. */ + enum bt_conn_le_tx_power_phy phy; + + /** Transmit power level + * - 0xXX - Transmit power level + * + Range: -127 to 20 + * + Units: dBm + * + * - 0x7E - Remote device is not managing power levels on this PHY. + * - 0x7F - Transmit power level is not available + */ + int8_t tx_power_level; + + /** Bit 0: Transmit power level is at minimum level. + * Bit 1: Transmit power level is at maximum level. + */ + uint8_t tx_power_level_flag; + + /** Change in transmit power level + * - 0xXX - Change in transmit power level (positive indicates increased + * power, negative indicates decreased power, zero indicates unchanged) + * Units: dB + * - 0x7F - Change is not available or is out of range. + */ + int8_t delta; +}; + /** @brief Passkey Keypress Notification type * * The numeric values are the same as in the Core specification for Pairing @@ -530,6 +566,41 @@ int bt_conn_get_remote_info(struct bt_conn *conn, int bt_conn_le_get_tx_power_level(struct bt_conn *conn, struct bt_conn_le_tx_power *tx_power_level); +/** @brief Get local enhanced connection transmit power level. + * + * @param conn Connection object. + * @param tx_power Transmit power level descriptor. + * + * @return Zero on success or (negative) error code on failure. + * @retval -ENOBUFS HCI command buffer is not available. + */ +int bt_conn_le_enhanced_get_tx_power_level(struct bt_conn *conn, + struct bt_conn_le_tx_power *tx_power); + +/** @brief Get remote (peer) transmit power level. + * + * @param conn Connection object. + * @param phy PHY information. + * + * @return Zero on success or (negative) error code on failure. + * @retval -ENOBUFS HCI command buffer is not available. + */ +int bt_conn_le_get_remote_tx_power_level(struct bt_conn *conn, + enum bt_conn_le_tx_power_phy phy); + +/** @brief Enable transmit power reporting. + * + * @param conn Connection object. + * @param local_enable Enable/disable reporting for local. + * @param remote_enable Enable/disable reporting for remote. + * + * @return Zero on success or (negative) error code on failure. + * @retval -ENOBUFS HCI command buffer is not available. + */ +int bt_conn_le_set_tx_power_report_enable(struct bt_conn *conn, + bool local_enable, + bool remote_enable); + /** @brief Update the connection parameters. * * If the local device is in the peripheral role then updating the connection @@ -1049,6 +1120,22 @@ struct bt_conn_cb { const struct bt_df_conn_iq_samples_report *iq_report); #endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */ +#if defined(CONFIG_BT_TRANSMIT_POWER_CONTROL) + /** @brief LE Read Remote Transmit Power Level procedure has completed or LE + * Transmit Power Reporting event. + * + * This callback notifies the application that either the remote transmit power level + * has been read from the peer or transmit power level has changed for the local or + * remote controller when transmit power reporting is enabled for the respective side + * using @ref bt_conn_le_set_tx_power_report_enable. + * + * @param conn Connection object. + * @param report Transmit power report. + */ + void (*tx_power_report)(struct bt_conn *conn, + const struct bt_conn_le_tx_power_report *report); +#endif /* CONFIG_BT_TRANSMIT_POWER_CONTROL */ + struct bt_conn_cb *_next; }; diff --git a/include/zephyr/bluetooth/hci_types.h b/include/zephyr/bluetooth/hci_types.h index d9dff357d35..dc1566a0df4 100644 --- a/include/zephyr/bluetooth/hci_types.h +++ b/include/zephyr/bluetooth/hci_types.h @@ -571,6 +571,35 @@ struct bt_hci_rp_read_tx_power_level { int8_t tx_power_level; } __packed; +#define BT_HCI_LE_TX_POWER_PHY_1M 0x01 +#define BT_HCI_LE_TX_POWER_PHY_2M 0x02 +#define BT_HCI_LE_TX_POWER_PHY_CODED_S8 0x03 +#define BT_HCI_LE_TX_POWER_PHY_CODED_S2 0x04 +#define BT_HCI_OP_LE_ENH_READ_TX_POWER_LEVEL BT_OP(BT_OGF_LE, 0x0076) +struct bt_hci_cp_le_read_tx_power_level { + uint16_t handle; + uint8_t phy; +} __packed; + +struct bt_hci_rp_le_read_tx_power_level { + uint8_t status; + uint16_t handle; + uint8_t phy; + int8_t current_tx_power_level; + int8_t max_tx_power_level; +} __packed; + +#define BT_HCI_OP_LE_READ_REMOTE_TX_POWER_LEVEL BT_OP(BT_OGF_LE, 0x0077) + +#define BT_HCI_LE_TX_POWER_REPORT_DISABLE 0x00 +#define BT_HCI_LE_TX_POWER_REPORT_ENABLE 0x01 +#define BT_HCI_OP_LE_SET_TX_POWER_REPORT_ENABLE BT_OP(BT_OGF_LE, 0x007A) +struct bt_hci_cp_le_set_tx_power_report_enable { + uint16_t handle; + uint8_t local_enable; + uint8_t remote_enable; +} __packed; + #define BT_HCI_CTL_TO_HOST_FLOW_DISABLE 0x00 #define BT_HCI_CTL_TO_HOST_FLOW_ENABLE 0x01 #define BT_HCI_OP_SET_CTL_TO_HOST_FLOW BT_OP(BT_OGF_BASEBAND, 0x0031) @@ -2903,6 +2932,26 @@ struct bt_hci_evt_le_req_peer_sca_complete { uint8_t sca; } __packed; +/** Reason for Transmit power reporting. + */ +/* Local Transmit power changed. */ +#define BT_HCI_LE_TX_POWER_REPORT_REASON_LOCAL_CHANGED 0x00 +/* Remote Transmit power changed. */ +#define BT_HCI_LE_TX_POWER_REPORT_REASON_REMOTE_CHANGED 0x01 +/* HCI_LE_Read_Remote_Transmit_Power_Level command completed. */ +#define BT_HCI_LE_TX_POWER_REPORT_REASON_READ_REMOTE_COMPLETED 0x02 + +#define BT_HCI_EVT_LE_TRANSMIT_POWER_REPORT 0x21 +struct bt_hci_evt_le_transmit_power_report { + uint8_t status; + uint16_t handle; + uint8_t reason; + uint8_t phy; + int8_t tx_power_level; + uint8_t tx_power_level_flag; + int8_t delta; +} __packed; + #define BT_HCI_EVT_LE_BIGINFO_ADV_REPORT 0x22 struct bt_hci_evt_le_biginfo_adv_report { uint16_t sync_handle; diff --git a/subsys/bluetooth/Kconfig b/subsys/bluetooth/Kconfig index e02901cd906..912846e4cda 100644 --- a/subsys/bluetooth/Kconfig +++ b/subsys/bluetooth/Kconfig @@ -175,6 +175,14 @@ config BT_SCA_UPDATE depends on !BT_CTLR || BT_CTLR_SCA_UPDATE_SUPPORT help Enable support for Bluetooth 5.1 Sleep Clock Accuracy Update Procedure + +config BT_TRANSMIT_POWER_CONTROL + bool "LE Power Control" + depends on !BT_CTLR || BT_CTLR_LE_POWER_CONTROL_SUPPORT + help + Enable support for LE Power Control Request feature that is defined in the + Bluetooth Core specification, Version 5.4 | Vol 6, Part B, Section 4.6.31. + endif # BT_CONN rsource "Kconfig.iso" diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 155b1a041a0..0e355c36390 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -2614,16 +2614,116 @@ static int bt_conn_get_tx_power_level(struct bt_conn *conn, uint8_t type, return 0; } +#if defined(CONFIG_BT_TRANSMIT_POWER_CONTROL) +void notify_tx_power_report(struct bt_conn *conn, + struct bt_conn_le_tx_power_report report) +{ + for (struct bt_conn_cb *cb = callback_list; cb; cb = cb->_next) { + if (cb->tx_power_report) { + cb->tx_power_report(conn, &report); + } + } + + STRUCT_SECTION_FOREACH(bt_conn_cb, cb) + { + if (cb->tx_power_report) { + cb->tx_power_report(conn, &report); + } + } +} + +int bt_conn_le_enhanced_get_tx_power_level(struct bt_conn *conn, + struct bt_conn_le_tx_power *tx_power) +{ + int err; + struct bt_hci_rp_le_read_tx_power_level *rp; + struct net_buf *rsp; + struct bt_hci_cp_le_read_tx_power_level *cp; + struct net_buf *buf; + + if (!tx_power->phy) { + return -EINVAL; + } + + buf = bt_hci_cmd_create(BT_HCI_OP_LE_ENH_READ_TX_POWER_LEVEL, sizeof(*cp)); + if (!buf) { + return -ENOBUFS; + } + + cp = net_buf_add(buf, sizeof(*cp)); + cp->handle = sys_cpu_to_le16(conn->handle); + cp->phy = tx_power->phy; + + err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_ENH_READ_TX_POWER_LEVEL, buf, &rsp); + if (err) { + return err; + } + + rp = (void *) rsp->data; + tx_power->phy = rp->phy; + tx_power->current_level = rp->current_tx_power_level; + tx_power->max_level = rp->max_tx_power_level; + net_buf_unref(rsp); + + return 0; +} + +int bt_conn_le_get_remote_tx_power_level(struct bt_conn *conn, + enum bt_conn_le_tx_power_phy phy) +{ + struct bt_hci_cp_le_read_tx_power_level *cp; + struct net_buf *buf; + + if (!phy) { + return -EINVAL; + } + + buf = bt_hci_cmd_create(BT_HCI_OP_LE_READ_REMOTE_TX_POWER_LEVEL, sizeof(*cp)); + if (!buf) { + return -ENOBUFS; + } + + cp = net_buf_add(buf, sizeof(*cp)); + cp->handle = sys_cpu_to_le16(conn->handle); + cp->phy = phy; + + return bt_hci_cmd_send_sync(BT_HCI_OP_LE_READ_REMOTE_TX_POWER_LEVEL, buf, NULL); +} + +int bt_conn_le_set_tx_power_report_enable(struct bt_conn *conn, + bool local_enable, + bool remote_enable) +{ + struct bt_hci_cp_le_set_tx_power_report_enable *cp; + struct net_buf *buf; + + buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_TX_POWER_REPORT_ENABLE, sizeof(*cp)); + if (!buf) { + return -ENOBUFS; + } + + cp = net_buf_add(buf, sizeof(*cp)); + cp->handle = sys_cpu_to_le16(conn->handle); + cp->local_enable = local_enable ? BT_HCI_LE_TX_POWER_REPORT_ENABLE : + BT_HCI_LE_TX_POWER_REPORT_DISABLE; + cp->remote_enable = remote_enable ? BT_HCI_LE_TX_POWER_REPORT_ENABLE : + BT_HCI_LE_TX_POWER_REPORT_DISABLE; + + return bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_TX_POWER_REPORT_ENABLE, buf, NULL); +} +#endif /* CONFIG_BT_TRANSMIT_POWER_CONTROL */ + int bt_conn_le_get_tx_power_level(struct bt_conn *conn, struct bt_conn_le_tx_power *tx_power_level) { int err; if (tx_power_level->phy != 0) { - /* Extend the implementation when LE Enhanced Read Transmit - * Power Level HCI command is available for use. - */ - return -ENOTSUP; + if (IS_ENABLED(CONFIG_BT_TRANSMIT_POWER_CONTROL)) { + return bt_conn_le_enhanced_get_tx_power_level(conn, tx_power_level); + } else { + return -ENOTSUP; + } } err = bt_conn_get_tx_power_level(conn, BT_TX_POWER_LEVEL_CURRENT, diff --git a/subsys/bluetooth/host/conn_internal.h b/subsys/bluetooth/host/conn_internal.h index bddbf11ae7d..a2d8e28bd4d 100644 --- a/subsys/bluetooth/host/conn_internal.h +++ b/subsys/bluetooth/host/conn_internal.h @@ -353,6 +353,9 @@ void notify_le_phy_updated(struct bt_conn *conn); bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param); +void notify_tx_power_report(struct bt_conn *conn, + struct bt_conn_le_tx_power_report report); + #if defined(CONFIG_BT_SMP) /* If role specific LTK is present */ bool bt_conn_ltk_present(const struct bt_conn *conn); diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index eb1d7195d5c..7cf699aa8cc 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -2392,6 +2392,33 @@ int bt_hci_register_vnd_evt_cb(bt_hci_vnd_evt_cb_t cb) } #endif /* CONFIG_BT_HCI_VS_EVT_USER */ +#if defined(CONFIG_BT_TRANSMIT_POWER_CONTROL) +void bt_hci_le_transmit_power_report(struct net_buf *buf) +{ + struct bt_hci_evt_le_transmit_power_report *evt; + struct bt_conn_le_tx_power_report report; + struct bt_conn *conn; + + evt = net_buf_pull_mem(buf, sizeof(*evt)); + conn = bt_conn_lookup_handle(sys_le16_to_cpu(evt->handle), BT_CONN_TYPE_LE); + if (!conn) { + LOG_ERR("Unknown conn handle 0x%04X for transmit power report", + sys_le16_to_cpu(evt->handle)); + return; + } + + report.reason = evt->reason; + report.phy = evt->phy; + report.tx_power_level = evt->tx_power_level; + report.tx_power_level_flag = evt->tx_power_level_flag; + report.delta = evt->delta; + + notify_tx_power_report(conn, report); + + bt_conn_unref(conn); +} +#endif /* CONFIG_BT_TRANSMIT_POWER_CONTROL */ + static const struct event_handler vs_events[] = { #if defined(CONFIG_BT_DF_VS_CL_IQ_REPORT_16_BITS_IQ_SAMPLES) EVENT_HANDLER(BT_HCI_EVT_VS_LE_CONNECTIONLESS_IQ_REPORT, @@ -2537,6 +2564,10 @@ static const struct event_handler meta_events[] = { EVENT_HANDLER(BT_HCI_EVT_LE_CTE_REQUEST_FAILED, bt_hci_le_df_cte_req_failed, sizeof(struct bt_hci_evt_le_cte_req_failed)), #endif /* CONFIG_BT_DF_CONNECTION_CTE_REQ */ +#if defined(CONFIG_BT_TRANSMIT_POWER_CONTROL) + EVENT_HANDLER(BT_HCI_EVT_LE_TRANSMIT_POWER_REPORT, bt_hci_le_transmit_power_report, + sizeof(struct bt_hci_evt_le_transmit_power_report)), +#endif /* CONFIG_BT_TRANSMIT_POWER_CONTROL */ #if defined(CONFIG_BT_PER_ADV_SYNC_RSP) EVENT_HANDLER(BT_HCI_EVT_LE_PER_ADVERTISING_REPORT_V2, bt_hci_le_per_adv_report_v2, sizeof(struct bt_hci_evt_le_per_advertising_report_v2)), @@ -3078,6 +3109,9 @@ static int le_set_event_mask(void) BT_FEAT_LE_PHY_CODED(bt_dev.le.features))) { mask |= BT_EVT_MASK_LE_PHY_UPDATE_COMPLETE; } + if (IS_ENABLED(CONFIG_BT_TRANSMIT_POWER_CONTROL)) { + mask |= BT_EVT_MASK_LE_TRANSMIT_POWER_REPORTING; + } } if (IS_ENABLED(CONFIG_BT_SMP) && From 9d18c0aa9ac4139965935775aa58925f78c85a06 Mon Sep 17 00:00:00 2001 From: Kyra Lengfeld Date: Fri, 24 Nov 2023 15:39:01 +0100 Subject: [PATCH 0427/1623] [nrf fromtree] Bluetooth: Host: Add bt shell functions LE Power Control Request Feature To use LE commands of Le Power Control Request Feature one must utilize the BT_TRANSMIT_POWER_CONTROL config. Signed-off-by: Kyra Lengfeld (cherry picked from commit 2c9af855bc6ef00160712cf0b71c953c4d13f196) Signed-off-by: Kyra Lengfeld --- subsys/bluetooth/shell/bt.c | 178 ++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index d1d1238baf6..a7ad5fe27a7 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -121,6 +121,67 @@ static void print_le_addr(const char *desc, const bt_addr_le_t *addr) } #endif /* CONFIG_BT_CONN || (CONFIG_BT_BROADCASTER && CONFIG_BT_EXT_ADV) */ +#if defined(CONFIG_BT_TRANSMIT_POWER_CONTROL) +static const char *tx_power_flag2str(int8_t flag) +{ + switch (flag) { + case 0: + return "Neither Max nor Min Tx Power"; + case 1: + return "Tx Power Level is at minimum"; + case 2: + return "Tx Power Level is at maximum"; + /* Current Tx Power Level is the only available one*/ + case 3: + return "Tx Power Level is at minimum & maximum."; + default: + return "Unknown"; + } +} + +static const char *tx_power_report_reason2str(uint8_t reason) +{ + switch (reason) { + case BT_HCI_LE_TX_POWER_REPORT_REASON_LOCAL_CHANGED: + return "Local Tx Power changed"; + case BT_HCI_LE_TX_POWER_REPORT_REASON_REMOTE_CHANGED: + return "Remote Tx Power changed"; + case BT_HCI_LE_TX_POWER_REPORT_REASON_READ_REMOTE_COMPLETED: + return "Completed to read remote Tx Power"; + default: + return "Unknown"; + } +} + +static const char *tx_pwr_ctrl_phy2str(enum bt_conn_le_tx_power_phy phy) +{ + switch (phy) { + case BT_CONN_LE_TX_POWER_PHY_NONE: + return "None"; + case BT_CONN_LE_TX_POWER_PHY_1M: + return "LE 1M"; + case BT_CONN_LE_TX_POWER_PHY_2M: + return "LE 2M"; + case BT_CONN_LE_TX_POWER_PHY_CODED_S8: + return "LE Coded S8"; + case BT_CONN_LE_TX_POWER_PHY_CODED_S2: + return "LE Coded S2"; + default: + return "Unknown"; + } +} + +static const char *enabled2str(bool enabled) +{ + if (enabled) { + return "Enabled"; + } else { + return "Disabled"; + } +} + +#endif /* CONFIG_BT_TRANSMIT_POWER_CONTROL */ + #if defined(CONFIG_BT_CENTRAL) static int cmd_scan_off(const struct shell *sh); static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[]); @@ -807,6 +868,19 @@ void le_phy_updated(struct bt_conn *conn, } #endif +#if defined(CONFIG_BT_TRANSMIT_POWER_CONTROL) +void tx_power_report(struct bt_conn *conn, + const struct bt_conn_le_tx_power_report *report) +{ + shell_print(ctx_shell, "Tx Power Report: Reason: %s, PHY: %s, Tx Power Level: %d", + tx_power_report_reason2str(report->reason), tx_pwr_ctrl_phy2str(report->phy), + report->tx_power_level); + shell_print(ctx_shell, "Tx Power Level Flag Info: %s, Delta: %d", + tx_power_flag2str(report->tx_power_level_flag), report->delta); +} +#endif + + static struct bt_conn_cb conn_callbacks = { .connected = connected, .disconnected = disconnected, @@ -827,6 +901,9 @@ static struct bt_conn_cb conn_callbacks = { #if defined(CONFIG_BT_USER_PHY_UPDATE) .le_phy_updated = le_phy_updated, #endif +#if defined(CONFIG_BT_TRANSMIT_POWER_CONTROL) + .tx_power_report = tx_power_report, +#endif }; #endif /* CONFIG_BT_CONN */ @@ -2604,6 +2681,102 @@ static int cmd_per_adv_set_info_transfer(const struct shell *sh, size_t argc, } #endif /* CONFIG_BT_PER_ADV_SYNC_TRANSFER_SENDER && CONFIG_BT_PER_ADV */ +#if defined(CONFIG_BT_TRANSMIT_POWER_CONTROL) +static int cmd_read_remote_tx_power(const struct shell *sh, size_t argc, char *argv[]) +{ + if (argc < 3) { + int err = 0; + enum bt_conn_le_tx_power_phy phy = strtoul(argv[1], NULL, 16); + + err = bt_conn_le_get_remote_tx_power_level(default_conn, phy); + + if (!err) { + shell_print(sh, "Read Remote TX Power for PHY %s", + tx_pwr_ctrl_phy2str(phy)); + } else { + shell_print(sh, "error %d", err); + } + } else { + shell_help(sh); + return SHELL_CMD_HELP_PRINTED; + } + return 0; +} + +static int cmd_read_local_tx_power(const struct shell *sh, size_t argc, char *argv[]) +{ + int err = 0; + + if (argc < 3) { + struct bt_conn_le_tx_power tx_power_level; + + tx_power_level.phy = strtoul(argv[1], NULL, 16); + + int8_t unachievable_current_level = -100; + /* Arbitrary, these are output parameters.*/ + tx_power_level.current_level = unachievable_current_level; + tx_power_level.max_level = 6; + + if (default_conn == NULL) { + shell_error(sh, "Conn handle error, at least one connection is required."); + return -ENOEXEC; + } + err = bt_conn_le_get_tx_power_level(default_conn, &tx_power_level); + if (err) { + shell_print(sh, "Commad returned error error %d", err); + return err; + } + if (tx_power_level.current_level == unachievable_current_level) { + shell_print(sh, "We received no current tx power level."); + return -EIO; + } + shell_print(sh, "Read local TX Power: current level: %d, PHY: %s, Max Level: %d", + tx_power_level.current_level, + tx_pwr_ctrl_phy2str((enum bt_conn_le_tx_power_phy)tx_power_level.phy), + tx_power_level.max_level); + } else { + shell_help(sh); + return SHELL_CMD_HELP_PRINTED; + } + + return err; +} + +static int cmd_set_power_report_enable(const struct shell *sh, size_t argc, char *argv[]) +{ + if (argc < 4) { + int err = 0; + bool local_enable = 0; + bool remote_enable = 0; + + if (*argv[1] == '1') { + local_enable = 1; + } + if (*argv[2] == '1') { + remote_enable = 1; + } + if (default_conn == NULL) { + shell_error(sh, "Conn handle error, at least one connection is required."); + return -ENOEXEC; + } + err = bt_conn_le_set_tx_power_report_enable(default_conn, local_enable, + remote_enable); + if (!err) { + shell_print(sh, "Tx Power Report: local: %s, remote: %s", + enabled2str(local_enable), enabled2str(remote_enable)); + } else { + shell_print(sh, "error %d", err); + } + } else { + shell_help(sh); + return SHELL_CMD_HELP_PRINTED; + } + return 0; +} + +#endif + + #if defined(CONFIG_BT_CONN) #if defined(CONFIG_BT_CENTRAL) static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[]) @@ -4011,6 +4184,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds, cmd_default_handler), SHELL_CMD_ARG(scan-verbose-output, NULL, "", cmd_scan_verbose_output, 2, 0), #endif /* CONFIG_BT_OBSERVER */ +#if defined(CONFIG_BT_TRANSMIT_POWER_CONTROL) + SHELL_CMD_ARG(read-remote-tx-power, NULL, HELP_NONE, cmd_read_remote_tx_power, 2, 0), + SHELL_CMD_ARG(read-local-tx-power, NULL, HELP_NONE, cmd_read_local_tx_power, 2, 0), + SHELL_CMD_ARG(set-power-report-enable, NULL, HELP_NONE, cmd_set_power_report_enable, 3, 0), +#endif #if defined(CONFIG_BT_BROADCASTER) SHELL_CMD_ARG(advertise, NULL, " [mode: discov, non_discov] " From 74b0d020e749332b39d9a1140d49a2afa538c2ec Mon Sep 17 00:00:00 2001 From: Kyra Lengfeld Date: Mon, 27 Nov 2023 12:32:01 +0100 Subject: [PATCH 0428/1623] [nrf fromtree] Bluetooth: Host: Align return lines of bt shell helper function phy2str As other helper functions were introduced for the LE Power Control Request Feature (see CONFIG_BT_TRANSMIT_POWER_CONTROL), it was noticed that the return statements of switch cases should be on the next line generally. This will align phy2str with the rest in bt.c. Signed-off-by: Kyra Lengfeld (cherry picked from commit 77ab683dc6253e2b3bf5107ca7bb43d569150332) Signed-off-by: Kyra Lengfeld --- subsys/bluetooth/shell/bt.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index a7ad5fe27a7..890eafe2210 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -97,10 +97,14 @@ static const char *phy2str(uint8_t phy) { switch (phy) { case 0: return "No packets"; - case BT_GAP_LE_PHY_1M: return "LE 1M"; - case BT_GAP_LE_PHY_2M: return "LE 2M"; - case BT_GAP_LE_PHY_CODED: return "LE Coded"; - default: return "Unknown"; + case BT_GAP_LE_PHY_1M: + return "LE 1M"; + case BT_GAP_LE_PHY_2M: + return "LE 2M"; + case BT_GAP_LE_PHY_CODED: + return "LE Coded"; + default: + return "Unknown"; } } #endif From f8dc8ac55203667f5137e4d4e245de4277db4980 Mon Sep 17 00:00:00 2001 From: Kyra Lengfeld Date: Tue, 28 Nov 2023 17:29:44 +0100 Subject: [PATCH 0429/1623] [nrf fromtree] Bluetooth: Host: build shell power_control_request (Not to mistake it for the dynamic power control nor the zephyr LL vendor-specific commands controlling local tx power) this yaml addition will build the shell code for the LE Power Control Feature API's, acting as verification. Signed-off-by: Kyra Lengfeld (cherry picked from commit 07d04b0f40b1569eafbfe8cf15184686f2faccc2) Signed-off-by: Kyra Lengfeld --- tests/bluetooth/shell/testcase.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/bluetooth/shell/testcase.yaml b/tests/bluetooth/shell/testcase.yaml index 4b46c8d6781..ef4eed67eb3 100644 --- a/tests/bluetooth/shell/testcase.yaml +++ b/tests/bluetooth/shell/testcase.yaml @@ -13,6 +13,13 @@ tests: tags: bluetooth harness: keyboard min_flash: 145 + bluetooth.shell.power_control_request: + extra_configs: + - CONFIG_BT_TRANSMIT_POWER_CONTROL=y + - CONFIG_BT_CTLR=n + platform_allow: + - native_posix + build_only: true bluetooth.shell.cdc_acm: extra_args: - OVERLAY_CONFIG=cdc_acm.conf From 8721401fed0cd5df940610005b411821c6c16648 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 29 Nov 2023 21:18:46 +0530 Subject: [PATCH 0430/1623] [nrf fromlist] wifi: Check WPA-PSK passphrase length When WPA-PSK was introduced the passphrase length check was missed. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65933 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_mgmt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 65457427bda..0751f5d2b8c 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -275,6 +275,7 @@ static int wifi_connect(uint32_t mgmt_request, struct net_if *iface, (params->ssid_length > WIFI_SSID_MAX_LEN) || (params->ssid_length == 0U) || ((params->security == WIFI_SECURITY_TYPE_PSK || + params->security == WIFI_SECURITY_TYPE_WPA_PSK || params->security == WIFI_SECURITY_TYPE_PSK_SHA256) && ((params->psk_length < 8) || (params->psk_length > 64) || (params->psk_length == 0U) || !params->psk)) || From e3429fadeece82ab46940a23edf4dc0954d9a718 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 10:29:53 +0530 Subject: [PATCH 0431/1623] [nrf fromlist] wifi: shell: Fix unbalanced braces Fix the typo in braces for help. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index a9837bbaf6b..2592d1274d5 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1669,15 +1669,15 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" - "[-i : Interface index - optional argument\n" - "[-s : Station mode.\n" - "[-m : Monitor mode.\n" - "[-p : Promiscuous mode.\n" - "[-t : TX-Injection mode.\n" - "[-a : AP mode.\n" - "[-k : Softap mode.\n" - "[-h : Help.\n" - "[-g : Get current mode for a specific interface index.\n" + "[-i] : Interface index - optional argument\n" + "[-s] : Station mode.\n" + "[-m] : Monitor mode.\n" + "[-p] : Promiscuous mode.\n" + "[-t] : TX-Injection mode.\n" + "[-a] : AP mode.\n" + "[-k] : Softap mode.\n" + "[-h] : Help.\n" + "[-g] : Get current mode for a specific interface index.\n" "Usage: Get operation example for interface index 1\n" "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" @@ -1688,14 +1688,14 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" "parameters:" - "[-i : Interface index - optional argument.\n" - "[-a : Enable all packet filter modes\n" - "[-m : Enable management packets to allowed up the stack.\n" - "[-c : Enable control packets to be allowed up the stack.\n" - "[-d : Enable Data packets to be allowed up the stack.\n" - "[-g : Get current filter settings for a specific interface index.\n" - "<-b : Capture length buffer size for each packet to be captured - optional argument.\n" - "<-h : Help.\n" + "[-i] : Interface index - optional argument.\n" + "[-a] : Enable all packet filter modes\n" + "[-m] : Enable management packets to allowed up the stack.\n" + "[-c] : Enable control packets to be allowed up the stack.\n" + "[-d] : Enable Data packets to be allowed up the stack.\n" + "[-g] : Get current filter settings for a specific interface index.\n" + "<-b> : Capture length buffer size for each packet to be captured - optional argument.\n" + "<-h> : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" @@ -1706,10 +1706,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" "parameters:" - "[-i : Interface index - optional argument.\n" - "[-c : Set a specific channel number to the lower layer.\n" - "[-g : Get current set channel number from the lower layer.\n" - "[-h : Help.\n" + "[-i] : Interface index - optional argument.\n" + "[-c] : Set a specific channel number to the lower layer.\n" + "[-g] : Get current set channel number from the lower layer.\n" + "[-h] : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" From ad503caacd6004efb4f386ce526f8f1f8e1952a0 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 10:36:06 +0530 Subject: [PATCH 0432/1623] [nrf fromlist] wifi: shell: Fix brackets type for optional params General notation for Optional params is to use square brackets. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 2592d1274d5..f9f5720e3cd 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1627,11 +1627,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(connect, NULL, "Connect to a Wi-Fi AP\n" "\"\"\n" - "\n" - "\n" - "\n" + "[channel number: 0 means all]\n" + "[PSK: valid only for secure SSIDs]\n" + "[Security type: valid only for secure SSIDs]\n" "0:None, 1:PSK, 2:PSK-256, 3:SAE\n" - "\n" + "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_connect), SHELL_CMD(disconnect, NULL, "Disconnect from the Wi-Fi AP", @@ -1663,7 +1663,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" "Usage: wifi reg_domain [ISO/IEC 3166-1 alpha2] [-f]\n" - "-f: Force to use this regulatory hint over any other regulatory hints\n" + "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain), SHELL_CMD(mode, NULL, "mode operational setting\n" From 9c2c52a44a28f974fa1280b35f06875b067c69ea Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 10:37:21 +0530 Subject: [PATCH 0433/1623] [nrf fromlist] wifi: shell: Fix PS mode help There is only a single parameter called "mode" that takes two possible values. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index f9f5720e3cd..ad0916abbbe 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1640,8 +1640,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, cmd_wifi_ps), SHELL_CMD_ARG(ps_mode, NULL, - "\n" - "", + "\n", cmd_wifi_ps_mode, 2, 0), @@ -1729,8 +1728,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, 0), SHELL_CMD_ARG(ps_wakeup_mode, NULL, - " : Set PS wake up mode to DTIM interval\n" - " : Set PS wake up mode to listen interval", + "\n", cmd_wifi_ps_wakeup_mode, 2, 0), From 7c23186c1282125353cacca44899f030706b2b68 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 10:40:25 +0530 Subject: [PATCH 0434/1623] [nrf fromlist] wifi: shell: Add missing security options Newly added security types are missing from the help. Also, now that we have two variants of PSK, use the prefix to disambiguate. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index ad0916abbbe..0bfac983cf0 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1630,7 +1630,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[channel number: 0 means all]\n" "[PSK: valid only for secure SSIDs]\n" "[Security type: valid only for secure SSIDs]\n" - "0:None, 1:PSK, 2:PSK-256, 3:SAE\n" + "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_connect), From bebc385d82e4fd230ac7afd0d580a8045624e921 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 10:57:40 +0530 Subject: [PATCH 0435/1623] [nrf fromlist] wifi: shell: Enforce argument count checks Use the proper API to enforce argument count checks as per mandatory or optional params. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 74 ++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 0bfac983cf0..11fb02e4bed 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1594,37 +1594,43 @@ static int cmd_wifi_packet_filter(const struct shell *sh, size_t argc, char *arg } SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, - SHELL_CMD(disable, NULL, + SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode", - cmd_wifi_ap_disable), - SHELL_CMD(enable, NULL, " [channel] [PSK]", - cmd_wifi_ap_enable), + cmd_wifi_ap_disable, + 1, 0), + SHELL_CMD_ARG(enable, NULL, " [channel] [PSK]", + cmd_wifi_ap_enable, + 2, 1), SHELL_SUBCMD_SET_END ); SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops, - SHELL_CMD(quick_setup, NULL, " Start a TWT flow with defaults:\n" + SHELL_CMD_ARG(quick_setup, NULL, " Start a TWT flow with defaults:\n" " \n", - cmd_wifi_twt_setup_quick), - SHELL_CMD(setup, NULL, " Start a TWT flow:\n" + cmd_wifi_twt_setup_quick, + 3, 0), + SHELL_CMD_ARG(setup, NULL, " Start a TWT flow:\n" "\n" "\n" " " " \n", - cmd_wifi_twt_setup), - SHELL_CMD(teardown, NULL, " Teardown a TWT flow:\n" + cmd_wifi_twt_setup, + 11, 0), + SHELL_CMD_ARG(teardown, NULL, " Teardown a TWT flow:\n" "\n" "\n" " \n", - cmd_wifi_twt_teardown), - SHELL_CMD(teardown_all, NULL, " Teardown all TWT flows\n", - cmd_wifi_twt_teardown_all), + cmd_wifi_twt_teardown, + 5, 0), + SHELL_CMD_ARG(teardown_all, NULL, " Teardown all TWT flows\n", + cmd_wifi_twt_teardown_all, + 1, 0), SHELL_SUBCMD_SET_END ); SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(ap, &wifi_cmd_ap, "Access Point mode commands", NULL), - SHELL_CMD(connect, NULL, + SHELL_CMD_ARG(connect, NULL, "Connect to a Wi-Fi AP\n" "\"\"\n" "[channel number: 0 means all]\n" @@ -1633,18 +1639,21 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required", - cmd_wifi_connect), - SHELL_CMD(disconnect, NULL, "Disconnect from the Wi-Fi AP", - cmd_wifi_disconnect), - SHELL_CMD(ps, NULL, "Configure Wi-F PS on/off, no arguments will dump config", - cmd_wifi_ps), + cmd_wifi_connect, + 2, 5), + SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", + cmd_wifi_disconnect, + 1, 0), + SHELL_CMD_ARG(ps, NULL, "Configure Wi-F PS on/off, no arguments will dump config", + cmd_wifi_ps, + 1, 1), SHELL_CMD_ARG(ps_mode, NULL, "\n", cmd_wifi_ps_mode, 2, 0), - SHELL_CMD(scan, NULL, + SHELL_CMD_ARG(scan, NULL, "Scan for Wi-Fi APs\n" "OPTIONAL PARAMETERS:\n" "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active.\n" @@ -1655,17 +1664,19 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535.\n" "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6-11,14_5:36,149-165,44\n" "[-h, --help] : Print out the help for the scan command.", - cmd_wifi_scan), - SHELL_CMD(statistics, NULL, "Wi-Fi interface statistics", cmd_wifi_stats), - SHELL_CMD(status, NULL, "Status of the Wi-Fi interface", cmd_wifi_status), + cmd_wifi_scan, + 1, 8), + SHELL_CMD_ARG(statistics, NULL, "Wi-Fi interface statistics", cmd_wifi_stats, 1, 0), + SHELL_CMD_ARG(status, NULL, "Status of the Wi-Fi interface", cmd_wifi_status, 1, 0), SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows", NULL), - SHELL_CMD(reg_domain, NULL, + SHELL_CMD_ARG(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" "Usage: wifi reg_domain [ISO/IEC 3166-1 alpha2] [-f]\n" "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", - cmd_wifi_reg_domain), - SHELL_CMD(mode, NULL, "mode operational setting\n" + cmd_wifi_reg_domain, + 2, 1), + SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" "[-i] : Interface index - optional argument\n" @@ -1681,8 +1692,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" "wifi mode -i1 -sp\n", - cmd_wifi_mode), - SHELL_CMD(packet_filter, NULL, "mode filter setting\n" + cmd_wifi_mode, + 1, 9), + SHELL_CMD_ARG(packet_filter, NULL, "mode filter setting\n" "This command is used to set packet filter setting when\n" "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" @@ -1699,8 +1711,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" "wifi packet_filter -i1 -md\n", - cmd_wifi_packet_filter), - SHELL_CMD(channel, NULL, "wifi channel setting\n" + cmd_wifi_packet_filter, + 1, 8), + SHELL_CMD_ARG(channel, NULL, "wifi channel setting\n" "This command is used to set the channel when\n" "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" @@ -1713,7 +1726,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" "wifi -i1 -c5\n", - cmd_wifi_channel), + cmd_wifi_channel, + 1, 4), SHELL_CMD_ARG(ps_timeout, NULL, " - PS inactivity timer(in ms)", From f721e835805a6e6bae6e7c491f3d4369d64412e4 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 11:06:51 +0530 Subject: [PATCH 0436/1623] [nrf fromlist] wifi: shell: Add long arguments to help Long arguments are handy for new users. Also use hyphen's rather than underscore to follow the convention. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 11fb02e4bed..66ee0eeba00 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1271,10 +1271,10 @@ void parse_mode_args_to_params(const struct shell *sh, int argc, int opt; int option_index = 0; - static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, + static struct option long_options[] = {{"if-index", optional_argument, 0, 'i'}, {"sta", no_argument, 0, 's'}, {"monitor", no_argument, 0, 'm'}, - {"TX-injection", no_argument, 0, 't'}, + {"tx-injection", no_argument, 0, 't'}, {"promiscuous", no_argument, 0, 'p'}, {"ap", no_argument, 0, 'a'}, {"softap", no_argument, 0, 'k'}, @@ -1381,7 +1381,7 @@ void parse_channel_args_to_params(const struct shell *sh, int argc, int opt; int option_index = 0; - static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, + static struct option long_options[] = {{"if-index", optional_argument, 0, 'i'}, {"channel", required_argument, 0, 'c'}, {"get", no_argument, 0, 'g'}, {"help", no_argument, 0, 'h'}, @@ -1487,8 +1487,8 @@ void parse_filter_args_to_params(const struct shell *sh, int argc, int opt; int option_index = 0; - static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, - {"capture_len", optional_argument, 0, 'b'}, + static struct option long_options[] = {{"if-index", optional_argument, 0, 'i'}, + {"capture-len", optional_argument, 0, 'b'}, {"all", no_argument, 0, 'a'}, {"mgmt", no_argument, 0, 'm'}, {"ctrl", no_argument, 0, 'c'}, @@ -1679,15 +1679,15 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" - "[-i] : Interface index - optional argument\n" - "[-s] : Station mode.\n" - "[-m] : Monitor mode.\n" - "[-p] : Promiscuous mode.\n" - "[-t] : TX-Injection mode.\n" - "[-a] : AP mode.\n" - "[-k] : Softap mode.\n" - "[-h] : Help.\n" - "[-g] : Get current mode for a specific interface index.\n" + "[-i, --if-index ] : Interface index.\n" + "[-s, --sta] : Station mode.\n" + "[-m, --monitor] : Monitor mode.\n" + "[-p, --promiscuous] : Promiscuous mode.\n" + "[-t, --tx-injection] : TX-Injection mode.\n" + "[-a, --ap] : AP mode.\n" + "[-k, --softap] : Softap mode.\n" + "[-h, --help] : Help.\n" + "[-g, --get] : Get current mode for a specific interface index.\n" "Usage: Get operation example for interface index 1\n" "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" @@ -1699,14 +1699,14 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" "parameters:" - "[-i] : Interface index - optional argument.\n" - "[-a] : Enable all packet filter modes\n" - "[-m] : Enable management packets to allowed up the stack.\n" - "[-c] : Enable control packets to be allowed up the stack.\n" - "[-d] : Enable Data packets to be allowed up the stack.\n" - "[-g] : Get current filter settings for a specific interface index.\n" - "<-b> : Capture length buffer size for each packet to be captured - optional argument.\n" - "<-h> : Help.\n" + "[-i, --if-index ] : Interface index.\n" + "[-a, --all] : Enable all packet filter modes\n" + "[-m, --mgmt] : Enable management packets to allowed up the stack.\n" + "[-c, --ctrl] : Enable control packets to be allowed up the stack.\n" + "[-d, --data] : Enable Data packets to be allowed up the stack.\n" + "[-g, --get] : Get current filter settings for a specific interface index.\n" + "[-b, --capture-len ] : Capture length buffer size for each packet to be captured\n" + "[-h, --help] : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" @@ -1718,10 +1718,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" "parameters:" - "[-i] : Interface index - optional argument.\n" - "[-c] : Set a specific channel number to the lower layer.\n" - "[-g] : Get current set channel number from the lower layer.\n" - "[-h] : Help.\n" + "[-i, --if-index ] : Interface index.\n" + "[-c, --channel ] : Set a specific channel number to the lower layer.\n" + "[-g, --get] : Get current set channel number from the lower layer.\n" + "[-h, --help] : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" From 92a5b80480bd6b1be9dabb5684162cef3067a85d Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 30 Nov 2023 15:00:12 +0100 Subject: [PATCH 0437/1623] [nrf noup] modules: tfm: Make TF-M crypto module depend on PSA_WANT fixup! [nrf noup] modules: tf-m: use of PSA_HAS_XXXX_SUPPORT Make TF-M crypto module depend on PSA_WANT_GENERATE_RANDOM, same as all other crypto modules, which have PSA_HAS to group all PSA features that require the module. This makes TF-M by default exclude the RNG module when not needed. Signed-off-by: Joakim Andersson --- modules/trusted-firmware-m/Kconfig.tfm.crypto_modules | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules b/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules index 1f0ec52aed3..02d3580c22f 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules +++ b/modules/trusted-firmware-m/Kconfig.tfm.crypto_modules @@ -10,6 +10,7 @@ if TFM_PARTITION_CRYPTO config TFM_CRYPTO_RNG_MODULE_ENABLED bool "Random number generator crypto module" default y + depends on PSA_WANT_GENERATE_RANDOM && NRF_SECURITY help Enables the random number generator module within the crypto partition. Unset this option if 'psa_generate_random' is not used. From 2364b332d085341d78e9618125256ae3a5cc71b0 Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Fri, 1 Dec 2023 13:36:39 +0530 Subject: [PATCH 0438/1623] [nrf fromtree] net: l2: wifi: Fix Print of SSID in WIFI status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While printing SSID in wifi status command, If the length is maximum(32 character). It leads to buffer overflow. It required one character for null terminator ‘\0’. Changing the Format Specifiers to print proper SSID. Signed-off-by: Kapil Bhatt (cherry picked from commit cb7b650b923f160540943f0724b79b79fd8e51f4) --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 66ee0eeba00..90dbd1588f7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -643,7 +643,7 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[]) wifi_mode_txt(status.iface_mode)); shell_fprintf(sh, SHELL_NORMAL, "Link Mode: %s\n", wifi_link_mode_txt(status.link_mode)); - shell_fprintf(sh, SHELL_NORMAL, "SSID: %-32s\n", status.ssid); + shell_fprintf(sh, SHELL_NORMAL, "SSID: %.32s\n", status.ssid); shell_fprintf(sh, SHELL_NORMAL, "BSSID: %s\n", net_sprint_ll_addr_buf(status.bssid, WIFI_MAC_ADDR_LEN, mac_string_buf, From e97dfe6a6edf3ca0e6b4a1a07c585d2f9be9f6ff Mon Sep 17 00:00:00 2001 From: Florian Grandel Date: Tue, 5 Sep 2023 18:23:45 +0200 Subject: [PATCH 0439/1623] [nrf fromtree] net: l2: ieee802154: pkt: fix cpp build failure CPP needs an additional cast. Fixes: #62282 Signed-off-by: Florian Grandel (cherry picked from commit 718fe844c2f5c7bc3d6364913f08f9542a3ec44a) --- include/zephyr/net/ieee802154_pkt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/net/ieee802154_pkt.h b/include/zephyr/net/ieee802154_pkt.h index 23921467d96..a1dca472448 100644 --- a/include/zephyr/net/ieee802154_pkt.h +++ b/include/zephyr/net/ieee802154_pkt.h @@ -92,7 +92,7 @@ static inline void *net_pkt_cb(struct net_pkt *pkt); static inline struct net_pkt_cb_ieee802154 *net_pkt_cb_ieee802154(struct net_pkt *pkt) { - return net_pkt_cb(pkt); + return (struct net_pkt_cb_ieee802154 *)net_pkt_cb(pkt); }; static inline uint8_t net_pkt_ieee802154_lqi(struct net_pkt *pkt) From 9566a94fc5175eae833af9ec264f68bcf16bc3f6 Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Tue, 21 Nov 2023 11:01:17 +0100 Subject: [PATCH 0440/1623] [nrf fromtree] twister: pytest: Add --pytest-args to Twister command line Extend Twister command line with --pytest-args. This parameter is passed to pytest subprocess. It allows to select a specific testcase from a test suite. Signed-off-by: Grzegorz Chwierut (cherry picked from commit a1698b691d9bfd25dfd70fc1ed42e819cdec61a3) --- doc/develop/test/pytest.rst | 10 +++ .../pylib/twister/twisterlib/environment.py | 5 ++ scripts/pylib/twister/twisterlib/harness.py | 19 ++++-- .../pytest_integration/test_harness_pytest.py | 66 +++++++++++++++++++ 4 files changed, 96 insertions(+), 4 deletions(-) diff --git a/doc/develop/test/pytest.rst b/doc/develop/test/pytest.rst index 087c45bcce8..e8ad82654c1 100644 --- a/doc/develop/test/pytest.rst +++ b/doc/develop/test/pytest.rst @@ -56,6 +56,16 @@ Pytest scans the given locations looking for tests, following its default `discovery rules `_ One can also pass some extra arguments to the pytest from yaml file using ``pytest_args`` keyword under ``harness_config``, e.g.: ``pytest_args: [‘-k=test_method’, ‘--log-level=DEBUG’]``. +There is also an option to pass ``--pytest-args`` through Twister command line parameters. +This can be particularly useful when one wants to select a specific testcase from a test suite. +For instance, one can use a command: + +.. code-block:: console + + $ ./scripts/twister --platform native_sim -T samples/subsys/testsuite/pytest/shell \ + -s samples/subsys/testsuite/pytest/shell/sample.pytest.shell \ + --pytest-args='-k test_shell_print_version' + Helpers & fixtures ================== diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index b5018bc1f01..89377e8b961 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -211,6 +211,11 @@ def add_parse_arguments(parser = None): and 'fifo_loop' is a name of a function found in main.c without test prefix. """) + parser.add_argument("--pytest-args", + help="""Pass additional arguments to the pytest subprocess. This parameter + will override the pytest_args from the harness_config in YAML file. + """) + valgrind_asan_group.add_argument( "--enable-valgrind", action="store_true", help="""Run binary through valgrind and check for several memory access diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index bd86df1b4df..203adf4560c 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -245,8 +245,9 @@ def pytest_run(self, timeout): def generate_command(self): config = self.instance.testsuite.harness_config + handler: Handler = self.instance.handler pytest_root = config.get('pytest_root', ['pytest']) if config else ['pytest'] - pytest_args = config.get('pytest_args', []) if config else [] + pytest_args_yaml = config.get('pytest_args', []) if config else [] pytest_dut_scope = config.get('pytest_dut_scope', None) if config else None command = [ 'pytest', @@ -260,12 +261,19 @@ def generate_command(self): ] command.extend([os.path.normpath(os.path.join( self.source_dir, os.path.expanduser(os.path.expandvars(src)))) for src in pytest_root]) - command.extend(pytest_args) + + if handler.options.pytest_args: + command.append(handler.options.pytest_args) + if pytest_args_yaml: + logger.warning(f'The pytest_args ({handler.options.pytest_args}) specified ' + 'in the command line will override the pytest_args defined ' + f'in the YAML file {pytest_args_yaml}') + else: + command.extend(pytest_args_yaml) + if pytest_dut_scope: command.append(f'--dut-scope={pytest_dut_scope}') - handler: Handler = self.instance.handler - if handler.options.verbose > 1: command.extend([ '--log-cli-level=DEBUG', @@ -425,6 +433,9 @@ def _parse_report_file(self, report): tc.status = 'error' tc.reason = elem.get('message') tc.output = elem.text + else: + self.state = 'skipped' + self.instance.reason = 'No tests collected' class Gtest(Harness): diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index 150980059b3..fc60b99e0d1 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -25,6 +25,7 @@ def testinstance() -> TestInstance: testinstance.handler = mock.Mock() testinstance.handler.options = mock.Mock() testinstance.handler.options.verbose = 1 + testinstance.handler.options.pytest_args = None testinstance.handler.type_str = 'native' return testinstance @@ -67,6 +68,18 @@ def test_pytest_command_extra_args(testinstance: TestInstance): assert c in command +def test_pytest_command_extra_args_in_options(testinstance: TestInstance): + pytest_harness = Pytest() + pytest_args_from_yaml = '-k test_from_yaml' + pytest_args_from_cmd = '-k test_from_cmd' + testinstance.testsuite.harness_config['pytest_args'] = [pytest_args_from_yaml] + testinstance.handler.options.pytest_args = pytest_args_from_cmd + pytest_harness.configure(testinstance) + command = pytest_harness.generate_command() + assert pytest_args_from_cmd in command + assert pytest_args_from_yaml not in command + + @pytest.mark.parametrize( ('pytest_root', 'expected'), [ @@ -222,3 +235,56 @@ def test_skip_2(): assert len(testinstance.testcases) == 2 for tc in testinstance.testcases: assert tc.status == "skipped" + + +def test_if_report_with_filter(pytester, testinstance: TestInstance): + test_file_content = textwrap.dedent(""" + import pytest + def test_A(): + pass + def test_B(): + pass + """) + test_file = pytester.path / 'test_filter.py' + test_file.write_text(test_file_content) + report_file = pytester.path / 'report.xml' + result = pytester.runpytest( + str(test_file), + '-k', 'test_B', + f'--junit-xml={str(report_file)}' + ) + result.assert_outcomes(passed=1) + assert report_file.is_file() + + pytest_harness = Pytest() + pytest_harness.configure(testinstance) + pytest_harness.report_file = report_file + pytest_harness._update_test_status() + assert pytest_harness.state == "passed" + assert testinstance.status == "passed" + assert len(testinstance.testcases) == 1 + + +def test_if_report_with_no_collected(pytester, testinstance: TestInstance): + test_file_content = textwrap.dedent(""" + import pytest + def test_A(): + pass + """) + test_file = pytester.path / 'test_filter.py' + test_file.write_text(test_file_content) + report_file = pytester.path / 'report.xml' + result = pytester.runpytest( + str(test_file), + '-k', 'test_B', + f'--junit-xml={str(report_file)}' + ) + result.assert_outcomes(passed=0) + assert report_file.is_file() + + pytest_harness = Pytest() + pytest_harness.configure(testinstance) + pytest_harness.report_file = report_file + pytest_harness._update_test_status() + assert pytest_harness.state == "skipped" + assert testinstance.status == "skipped" From ad95bc81b8b9d44431c092a3cee4e7204dfceba4 Mon Sep 17 00:00:00 2001 From: Ederson de Souza Date: Mon, 27 Nov 2023 17:09:07 -0800 Subject: [PATCH 0441/1623] [nrf fromtree] scripts/pylib/twister/twisterlib: Support multiple `--pytest-args` One can not even replace sucessfully pytest basic sample `pytest-args` with command line "--pytest-args", as all it does is to append a single string to current list of commands, making it impossible to send several arguments. This patch fixes that by allowing several instances of `--pytest-args` to compose the whole list of arguments to be passed to pytest. Signed-off-by: Ederson de Souza (cherry picked from commit 10ec2b129c9102a867d1ce26eb8cb986f95b6d98) --- doc/develop/test/pytest.rst | 2 ++ .../pylib/twister/twisterlib/environment.py | 3 ++- scripts/pylib/twister/twisterlib/harness.py | 19 ++++++++++--------- .../pytest_integration/test_harness_pytest.py | 5 +++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/doc/develop/test/pytest.rst b/doc/develop/test/pytest.rst index e8ad82654c1..957ff8c773b 100644 --- a/doc/develop/test/pytest.rst +++ b/doc/develop/test/pytest.rst @@ -67,6 +67,8 @@ For instance, one can use a command: --pytest-args='-k test_shell_print_version' +Note that ``--pytest-args`` can be passed multiple times to pass several arguments to the pytest. + Helpers & fixtures ================== diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index 89377e8b961..d1ce56711c2 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -211,7 +211,8 @@ def add_parse_arguments(parser = None): and 'fifo_loop' is a name of a function found in main.c without test prefix. """) - parser.add_argument("--pytest-args", + parser.add_argument( + "--pytest-args", action="append", help="""Pass additional arguments to the pytest subprocess. This parameter will override the pytest_args from the harness_config in YAML file. """) diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index 203adf4560c..edb053232b9 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -262,15 +262,6 @@ def generate_command(self): command.extend([os.path.normpath(os.path.join( self.source_dir, os.path.expanduser(os.path.expandvars(src)))) for src in pytest_root]) - if handler.options.pytest_args: - command.append(handler.options.pytest_args) - if pytest_args_yaml: - logger.warning(f'The pytest_args ({handler.options.pytest_args}) specified ' - 'in the command line will override the pytest_args defined ' - f'in the YAML file {pytest_args_yaml}') - else: - command.extend(pytest_args_yaml) - if pytest_dut_scope: command.append(f'--dut-scope={pytest_dut_scope}') @@ -290,6 +281,16 @@ def generate_command(self): command.append('--device-type=custom') else: raise PytestHarnessException(f'Handling of handler {handler.type_str} not implemented yet') + + if handler.options.pytest_args: + command.extend(handler.options.pytest_args) + if pytest_args_yaml: + logger.warning(f'The pytest_args ({handler.options.pytest_args}) specified ' + 'in the command line will override the pytest_args defined ' + f'in the YAML file {pytest_args_yaml}') + else: + command.extend(pytest_args_yaml) + return command def _generate_parameters_for_hardware(self, handler: Handler): diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index fc60b99e0d1..befd384be37 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -71,12 +71,13 @@ def test_pytest_command_extra_args(testinstance: TestInstance): def test_pytest_command_extra_args_in_options(testinstance: TestInstance): pytest_harness = Pytest() pytest_args_from_yaml = '-k test_from_yaml' - pytest_args_from_cmd = '-k test_from_cmd' + pytest_args_from_cmd = ['-k', 'test_from_cmd'] testinstance.testsuite.harness_config['pytest_args'] = [pytest_args_from_yaml] testinstance.handler.options.pytest_args = pytest_args_from_cmd pytest_harness.configure(testinstance) command = pytest_harness.generate_command() - assert pytest_args_from_cmd in command + assert pytest_args_from_cmd[0] in command + assert pytest_args_from_cmd[1] in command assert pytest_args_from_yaml not in command From 3e94ff1efea007b75e8d9bf6b8e86076cb31525a Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 7 Dec 2023 20:50:55 +0530 Subject: [PATCH 0442/1623] [nrf fromlist] wifi: Add an enum for connect result status This can be used to interpret the "status" in the connect result event. To start with a few common reasons are enumerated but can be extended in the future. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66285 Signed-off-by: Chaitanya Tata --- include/zephyr/net/wifi_mgmt.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index ab3225e1408..ae0336d3a88 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -305,6 +305,22 @@ struct wifi_connect_req_params { int timeout; }; +/** Wi-Fi connect result codes. To be overlaid on top of \ref wifi_status + * in the connect result event for detailed status. + */ +enum wifi_conn_status { + /** Connection successful */ + WIFI_STATUS_CONN_SUCCESS = 0, + /** Connection failed - generic failure */ + WIFI_STATUS_CONN_FAIL, + /** Connection failed - wrong password */ + WIFI_STATUS_CONN_WRONG_PASSWORD, + /** Connection timed out */ + WIFI_STATUS_CONN_TIMEOUT, + /** Connection failed - AP not found */ + WIFI_STATUS_CONN_AP_NOT_FOUND, +}; + /** Generic Wi-Fi status for commands and events */ struct wifi_status { int status; From 4c6c7fa95617e53d2b9d5347d0a066a2fbe559a0 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 7 Dec 2023 20:57:14 +0530 Subject: [PATCH 0443/1623] [nrf fromlist] wifi: Add an enum for disconnect reasons This can be used to interpret the "status" in the disconnect result event. To start with a few common reasons are enumerated but can be extended in the future. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66285 Signed-off-by: Chaitanya Tata --- include/zephyr/net/wifi_mgmt.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index ae0336d3a88..9aa6ca248f1 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -321,6 +321,20 @@ enum wifi_conn_status { WIFI_STATUS_CONN_AP_NOT_FOUND, }; +/** Wi-Fi disconnect reason codes. To be overlaid on top of \ref wifi_status + * in the disconnect result event for detailed reason. + */ +enum wifi_disconn_reason { + /** Unspecified reason */ + WIFI_REASON_DISCONN_UNSPECIFIED = 0, + /** Disconnected due to user request */ + WIFI_REASON_DISCONN_USER_REQUEST, + /** Disconnected due to AP leaving */ + WIFI_REASON_DISCONN_AP_LEAVING, + /** Disconnected due to inactivity */ + WIFI_REASON_DISCONN_INACTIVITY, +}; + /** Generic Wi-Fi status for commands and events */ struct wifi_status { int status; From 1a6d964dd2e6aa19ae755b5e2404e63b015e060c Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 8 Dec 2023 12:15:05 +0530 Subject: [PATCH 0444/1623] [nrf fromlist] wifi: Add the enums to the status This helps to demonstrate that the enumerations have to be used to interpret the status. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66285 Signed-off-by: Chaitanya Tata --- include/zephyr/net/wifi_mgmt.h | 6 +++++- lib/libc/newlib/Kconfig | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 9aa6ca248f1..1be98b927cb 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -337,7 +337,11 @@ enum wifi_disconn_reason { /** Generic Wi-Fi status for commands and events */ struct wifi_status { - int status; + union { + int status; + enum wifi_conn_status conn_status; + enum wifi_disconn_reason disconn_reason; + }; }; /** Wi-Fi interface status */ diff --git a/lib/libc/newlib/Kconfig b/lib/libc/newlib/Kconfig index 1b4f90341b0..a7d3ac38364 100644 --- a/lib/libc/newlib/Kconfig +++ b/lib/libc/newlib/Kconfig @@ -5,7 +5,7 @@ if NEWLIB_LIBC config NEWLIB_LIBC_NANO bool "Build with newlib-nano C library" - depends on HAS_NEWLIB_LIBC_NANO + depends on HAS_NEWLIB_LIBC_NANO && !WPA_SUPP help Build with newlib-nano library, for small embedded apps. The newlib-nano library for ARM embedded processors is a part of the From e0dc936a4af5550f15d9e37ab9b44db5de452ee0 Mon Sep 17 00:00:00 2001 From: Adam Wojasinski Date: Fri, 1 Dec 2023 14:53:27 +0100 Subject: [PATCH 0445/1623] [nrf fromlist] manifest: hal_nordic: Update revision with fixed workaround in nrfx_qspi Pulls update in nrfx_qspi driver with fixed order of applying workaround for anomaly 215 on nRF52840 and anomaly 43 on nRF5340. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66034 Signed-off-by: Adam Wojasinski --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 93db410ea77..475e8a7cc25 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 2ff8ce6e6ca131d87699dba260f3c0cc4a6cc365 + revision: b9633ecea67bf52925d4c61455046223b46402b1 path: modules/hal/nordic groups: - hal From e4511cfcb7a672ca1bb0d6296dc257df6af0b12f Mon Sep 17 00:00:00 2001 From: Andrzej Kuros Date: Mon, 4 Dec 2023 13:23:41 +0100 Subject: [PATCH 0446/1623] [nrf fromtree] modules: hal_nordic: nRF 802.15.4 customizable asserts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Recent nRF 802.15.4 Radio Driver provides assert abstraction layer. The assert abstraction layer is implemented in Zephyr in following ways depending on the `NRF_802154_ASSERT_CHOICE` Kconfig choice. `NRF_802154_ASSERT_ZEPHYR_MINIMAL` (default) gives ability to still perform run-time checking of the nRF 802.15.4 Radio Driver operation with minimum memory overhead and configurable behavior on fault detection regardless of the `CONFIG_ASSERT` Kconfig option value. `NRF_802154_ASSERT_ZEPHYR` gives ability to use asserts provided and configurable by Zephyr including the ability to turn off the run-time checking of the nRF 802.15.4 Radio Driver operation. Signed-off-by: Andrzej Kuroś (cherry picked from commit f5337fc7a3c809e9cde6662dffd517e81a4e296b) --- modules/hal_nordic/Kconfig | 28 +++++++++++++++++- modules/hal_nordic/nrf_802154/CMakeLists.txt | 5 ++++ .../include/nrf_802154_assert_zephyr.h | 29 +++++++++++++++++++ .../nrf_802154/nrf_802154_assert_handler.c | 26 +++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 modules/hal_nordic/nrf_802154/include/nrf_802154_assert_zephyr.h create mode 100644 modules/hal_nordic/nrf_802154/nrf_802154_assert_handler.c diff --git a/modules/hal_nordic/Kconfig b/modules/hal_nordic/Kconfig index f842d2cb646..44c12e88685 100644 --- a/modules/hal_nordic/Kconfig +++ b/modules/hal_nordic/Kconfig @@ -205,13 +205,39 @@ endif endmenu # NRF_802154_SER_HOST || NRF_802154_SER_RADIO +if NRF_802154_RADIO_DRIVER || NRF_802154_SERIALIZATION + config NRF_802154_CARRIER_FUNCTIONS bool "nRF 802.15.4 carrier functions" - depends on NRF_802154_RADIO_DRIVER || NRF_802154_SERIALIZATION help This option enables functions such as modulated carrier and continuous carrier. If this option is modified on a multicore SoC, its remote counterpart must be set to the exact same value. +choice NRF_802154_ASSERT_CHOICE + prompt "nRF 802.15.4 assert implementation" + default NRF_802154_ASSERT_ZEPHYR_MINIMAL + +config NRF_802154_ASSERT_ZEPHYR_MINIMAL + bool "nRF 802.15.4 minimal assertions" + help + This option provides minimal run-time checking of the nRF 802.15.4 Radio Driver's operation, + even if kernel-wide CONFIG_ASSERT is disabled. In case of an abnormal condition the function + `nrf_802154_assert_handler()` is called. File and line debug information are not provided + to save memory of the image file. Default implementation of the `nrf_802154_assert_handler` + involves a call to `k_panic`/`k_oops` and allows further tweaking of the behavior. + You can also provide your own implementation of `nrf_802154_assert_handler`. + +config NRF_802154_ASSERT_ZEPHYR + bool "nRF 802.15.4 Radio Driver assertions as Zephyr's standard __ASERT_NO_MSG" + help + The run-time checking of the nRF 802.15.4 Radio Driver depends fully on the configuration + of the `__ASSERT_NO_MSG` macro, including the ability to completely turn off the run-time + checking. + +endchoice # NRF_802154_ASSERT_CHOICE + +endif # NRF_802154_RADIO_DRIVER || NRF_802154_SERIALIZATION + endmenu # HAS_NORDIC_DRIVERS rsource "nrfx/Kconfig" diff --git a/modules/hal_nordic/nrf_802154/CMakeLists.txt b/modules/hal_nordic/nrf_802154/CMakeLists.txt index c338981b651..cd5ace0b278 100644 --- a/modules/hal_nordic/nrf_802154/CMakeLists.txt +++ b/modules/hal_nordic/nrf_802154/CMakeLists.txt @@ -95,6 +95,11 @@ endif() if (CONFIG_NRF_802154_RADIO_DRIVER OR CONFIG_NRF_802154_SERIALIZATION) target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_ENERGY_DETECTED_VERSION=1) + if (CONFIG_NRF_802154_ASSERT_ZEPHYR OR CONFIG_NRF_802154_ASSERT_ZEPHYR_MINIMAL) + target_include_directories(zephyr-802154-interface INTERFACE include) + target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_PLATFORM_ASSERT_INCLUDE=\"nrf_802154_assert_zephyr.h\") + target_sources(nrf-802154-platform PRIVATE nrf_802154_assert_handler.c) + endif() endif() set(NRF52_SERIES ${CONFIG_SOC_SERIES_NRF52X}) diff --git a/modules/hal_nordic/nrf_802154/include/nrf_802154_assert_zephyr.h b/modules/hal_nordic/nrf_802154/include/nrf_802154_assert_zephyr.h new file mode 100644 index 00000000000..ecd09de609a --- /dev/null +++ b/modules/hal_nordic/nrf_802154/include/nrf_802154_assert_zephyr.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef NRF_802154_ASSERT_ZEPHYR_H__ +#define NRF_802154_ASSERT_ZEPHYR_H__ + +#if defined(CONFIG_NRF_802154_ASSERT_ZEPHYR) + +#include + +#define NRF_802154_ASSERT(condition) __ASSERT_NO_MSG(condition) + +#elif defined(CONFIG_NRF_802154_ASSERT_ZEPHYR_MINIMAL) + +extern void nrf_802154_assert_handler(void); + +#define NRF_802154_ASSERT(condition) \ + do { \ + if (!(condition)) { \ + nrf_802154_assert_handler(); \ + } \ + } while (0) + +#endif /* CONFIG_NRF_802154_ASSERT_ZEPHYR_MINIMAL */ + +#endif /* NRF_802154_ASSERT_ZEPHYR_H__*/ diff --git a/modules/hal_nordic/nrf_802154/nrf_802154_assert_handler.c b/modules/hal_nordic/nrf_802154/nrf_802154_assert_handler.c new file mode 100644 index 00000000000..14d964724c6 --- /dev/null +++ b/modules/hal_nordic/nrf_802154/nrf_802154_assert_handler.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "nrf_802154_assert_zephyr.h" + +#if defined(CONFIG_NRF_802154_ASSERT_ZEPHYR_MINIMAL) + +__weak void nrf_802154_assert_handler(void) +{ +#ifdef CONFIG_USERSPACE + /* User threads aren't allowed to induce kernel panics; generate + * an oops instead. + */ + if (k_is_user_context()) { + k_oops(); + } +#endif + + k_panic(); +} + +#endif /* CONFIG_NRF_802154_ASSERT_ZEPHYR_MINIMAL */ From 919457f5c1d9d491033b23efcf77197d687422a6 Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Tue, 5 Dec 2023 13:48:37 +0100 Subject: [PATCH 0447/1623] [nrf fromtree] net: openthread: Openthread upmerge to `4ed44bc` This commit bumps openthread commit to `4ed44bc` and implements `CONFIG_OPENTHREAD_MULTIPAN_RCP` option. Signed-off-by: Przemyslaw Bida (cherry picked from commit 8f2b7a121bbf7b64fdf46c5c19231a12f96c4166) --- modules/openthread/CMakeLists.txt | 6 ++++++ modules/openthread/Kconfig.features | 3 +++ west.yml | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index bad6d131771..be66469b167 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -334,6 +334,12 @@ else() set(OT_MLR OFF CACHE BOOL "Enable Multicast Listener Registration feature for Thread 1.2" FORCE) endif() +if(CONFIG_OPENTHREAD_MULTIPAN_RCP) + set(OT_MULTIPAN_RCP ON CACHE BOOL "Enable Multi-PAN RCP" FORCE) +else() + set(OT_MULTIPAN_RCP OFF CACHE BOOL "Enable Multi-PAN RCP" FORCE) +endif() + if(CONFIG_OPENTHREAD_MULTIPLE_INSTANCE) set(OT_MULTIPLE_INSTANCE ON CACHE BOOL "Enable multiple instances" FORCE) else() diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index a75c9e8fd48..33213d05bef 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -214,6 +214,9 @@ config OPENTHREAD_MLR help Enable Multicast Listener Registration support for Thread 1.2 +config OPENTHREAD_MULTIPAN_RCP + bool "OpenThread multipan rcp" + config OPENTHREAD_MULTIPLE_INSTANCE bool "OpenThread multiple instances" diff --git a/west.yml b/west.yml index 475e8a7cc25..988343a9d10 100644 --- a/west.yml +++ b/west.yml @@ -303,7 +303,7 @@ manifest: revision: 42b7c577714b8f22ce82a901e19c1814af4609a8 path: modules/lib/open-amp - name: openthread - revision: 6edb06e4e0472411200ce2a084a783eaf3faffe3 + revision: 4ed44bc7d58d9a98c6cca13a50d38129045ab3df path: modules/lib/openthread - name: picolibc path: modules/lib/picolibc From 145754e56829d73776aa285ea9de275d5e0d026d Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Tue, 5 Dec 2023 16:13:06 +0100 Subject: [PATCH 0448/1623] [nrf fromtree] net: openthread: Add openthread TCAT implementation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds bbtc implementation. New file in modules/openthread/platform/ble.c New corresponding kconfig option `OPENTHREAD_BLE_TCAT`. Co-authored-by: Piotr Jasiński Signed-off-by: Przemyslaw Bida Signed-off-by: Piotr Jasiński (cherry picked from commit 304b98391cc2c41f24b591f72da29c13a1786766) --- modules/openthread/CMakeLists.txt | 6 + modules/openthread/Kconfig.features | 4 + modules/openthread/Kconfig.thread | 12 + modules/openthread/platform/CMakeLists.txt | 1 + modules/openthread/platform/ble.c | 458 +++++++++++++++++++++ 5 files changed, 481 insertions(+) create mode 100644 modules/openthread/platform/ble.c diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index be66469b167..3796ec8f177 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -58,6 +58,12 @@ else() set(OT_BACKBONE_ROUTER_MULTICAST_ROUTING OFF CACHE BOOL "Enable BBR MR support" FORCE) endif() +if(CONFIG_OPENTHREAD_BLE_TCAT) + set(OT_BLE_TCAT ON CACHE BOOL "Enable BLE TCAT support" FORCE) +else() + set(OT_BLE_TCAT OFF CACHE BOOL "Enable BLE TCAT support" FORCE) +endif() + if(CONFIG_OPENTHREAD_BORDER_AGENT) set(OT_BORDER_AGENT ON CACHE BOOL "Enable Border Agent" FORCE) else() diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index 33213d05bef..2be5332cde3 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -39,6 +39,10 @@ config OPENTHREAD_BACKBONE_ROUTER_DUA_NDPROXYING config OPENTHREAD_BACKBONE_ROUTER_MULTICAST_ROUTING bool "BBR MR support" +config OPENTHREAD_BLE_TCAT + bool "BLE TCAT support" + select EXPERIMENTAL + config OPENTHREAD_BORDER_AGENT bool "Border Agent support" diff --git a/modules/openthread/Kconfig.thread b/modules/openthread/Kconfig.thread index 73c547919a7..57a8de5d324 100644 --- a/modules/openthread/Kconfig.thread +++ b/modules/openthread/Kconfig.thread @@ -182,3 +182,15 @@ config OPENTHREAD_DEFAULT_TX_POWER default 0 help Set the default TX output power [dBm] in radio driver for OpenThread purpose. + +config OPENTHREAD_BLE_TCAT_THREAD_STACK_SIZE + int "Openthread default TCAT stack size" + default 4200 + help + Openthread default TCAT stack size. + +config OPENTHREAD_BLE_TCAT_RING_BUF_SIZE + int "Openthread BLE ringbuffer size" + default 512 + help + Openthread BLE TCAT ringbuffer size. diff --git a/modules/openthread/platform/CMakeLists.txt b/modules/openthread/platform/CMakeLists.txt index d363bcda7df..542aa5186ea 100644 --- a/modules/openthread/platform/CMakeLists.txt +++ b/modules/openthread/platform/CMakeLists.txt @@ -10,6 +10,7 @@ zephyr_library_sources( spi.c ) +zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_BLE_TCAT ble.c) zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_DIAG diag.c) zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_COPROCESSOR uart.c) zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_CRYPTO_PSA crypto_psa.c) diff --git a/modules/openthread/platform/ble.c b/modules/openthread/platform/ble.c new file mode 100644 index 00000000000..7b41556b617 --- /dev/null +++ b/modules/openthread/platform/ble.c @@ -0,0 +1,458 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +/* Zephyr OpenThread integration Library */ +#include + +/* OpenThread BLE driver API */ +#include + +/* Zephyr Logging */ + +#define LOG_MODULE_NAME net_openthread_tcat +#define LOG_LEVEL CONFIG_OPENTHREAD_LOG_LEVEL + +LOG_MODULE_REGISTER(LOG_MODULE_NAME); + +#define DEVICE_NAME CONFIG_BT_DEVICE_NAME +#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) + +/* BLE connection constants as defined in thread specification. */ +#define TOBLE_SERVICE_UUID 0xfffb +#define RX_CHARACTERISTIC_UUID \ + BT_UUID_128_ENCODE(0x6bd10d8b, 0x85a7, 0x4e5a, 0xba2d, 0xc83558a5f220) +#define TX_CHARACTERISTIC_UUID \ + BT_UUID_128_ENCODE(0x7fddf61f, 0x280a, 0x4773, 0xb448, 0xba1b8fe0dd69) + +#define BT_UUID_TCAT_SERVICE BT_UUID_DECLARE_16(TOBLE_SERVICE_UUID) +#define BT_UUID_TCAT_SERVICE_RX BT_UUID_DECLARE_128(RX_CHARACTERISTIC_UUID) +#define BT_UUID_TCAT_SERVICE_TX BT_UUID_DECLARE_128(TX_CHARACTERISTIC_UUID) + +#define PLAT_BLE_THREAD_DEALY 500 +#define PLAT_BLE_MSG_DATA_MAX CONFIG_BT_L2CAP_TX_MTU /* must match the maximum MTU size used */ + +#define PLAT_BLE_MSG_CONNECT (PLAT_BLE_MSG_DATA_MAX + 1U) +#define PLAT_BLE_MSG_DISCONNECT (PLAT_BLE_MSG_CONNECT + 1U) + +/* Zephyr Kernel Objects */ + +static void ot_plat_ble_thread(void *, void *, void *); +static uint8_t ot_plat_ble_msg_buf[PLAT_BLE_MSG_DATA_MAX]; + +static K_SEM_DEFINE(ot_plat_ble_init_semaphore, 0, 1); +static K_SEM_DEFINE(ot_plat_ble_event_semaphore, 0, K_SEM_MAX_LIMIT); +RING_BUF_DECLARE(ot_plat_ble_ring_buf, CONFIG_OPENTHREAD_BLE_TCAT_RING_BUF_SIZE); +static K_THREAD_DEFINE(ot_plat_ble_tid, CONFIG_OPENTHREAD_BLE_TCAT_THREAD_STACK_SIZE, + ot_plat_ble_thread, NULL, NULL, NULL, 5, 0, PLAT_BLE_THREAD_DEALY); + +/* OpenThread Objects */ + +static otInstance *ble_openthread_instance; + +/* BLE service Objects */ + +/* forward declaration for callback functions */ +static ssize_t on_receive(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, + uint16_t len, uint16_t offset, uint8_t flags); +static void on_cccd_changed(const struct bt_gatt_attr *attr, uint16_t value); + +/* Service Declaration and Registration */ +BT_GATT_SERVICE_DEFINE(my_service, BT_GATT_PRIMARY_SERVICE(BT_UUID_TCAT_SERVICE), + BT_GATT_CHARACTERISTIC(BT_UUID_TCAT_SERVICE_RX, + BT_GATT_CHRC_WRITE | BT_GATT_CHRC_WRITE_WITHOUT_RESP, + BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, NULL, + on_receive, NULL), + BT_GATT_CHARACTERISTIC(BT_UUID_TCAT_SERVICE_TX, BT_GATT_CHRC_NOTIFY, + BT_GATT_PERM_READ, NULL, NULL, NULL), + BT_GATT_CCC(on_cccd_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),); + +/* Zephyr BLE Objects */ + +/* forward declaration for callback functions */ +static void connected(struct bt_conn *conn, uint8_t err); +static void disconnected(struct bt_conn *conn, uint8_t reason); +static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param); +static void le_param_updated(struct bt_conn *conn, uint16_t interval, uint16_t latency, + uint16_t timeout); + +static struct bt_conn *ot_plat_ble_connection; + +static struct bt_conn_cb conn_callbacks = {.connected = connected, + .disconnected = disconnected, + .le_param_req = le_param_req, + .le_param_updated = le_param_updated}; + +static const struct bt_data ad[] = { + BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), + BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN), +}; + +static const struct bt_data sd[] = { + BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(TOBLE_SERVICE_UUID)), +}; + +/* Zephyr BLE Message Queue and Thread */ + +static bool ot_plat_ble_queue_msg(const uint8_t *aData, uint16_t aLen, int8_t aRssi) +{ + otError error = OT_ERROR_NONE; + uint16_t len = 0; + + if (aLen <= PLAT_BLE_MSG_DATA_MAX && aData == NULL) { + return OT_ERROR_INVALID_ARGS; + } + + k_sched_lock(); + + len = sizeof(aLen) + sizeof(aRssi) + ((aLen <= PLAT_BLE_MSG_DATA_MAX) ? aLen : 0); + + if (ring_buf_space_get(&ot_plat_ble_ring_buf) >= len) { + ring_buf_put(&ot_plat_ble_ring_buf, (uint8_t *)&aLen, sizeof(aLen)); + ring_buf_put(&ot_plat_ble_ring_buf, &aRssi, sizeof(aRssi)); + if (aLen <= PLAT_BLE_MSG_DATA_MAX) { + ring_buf_put(&ot_plat_ble_ring_buf, aData, aLen); + } + k_sem_give(&ot_plat_ble_event_semaphore); + } else { + error = OT_ERROR_NO_BUFS; + } + + k_sched_unlock(); + + return error; +} + +static void ot_plat_ble_thread(void *unused1, void *unused2, void *unused3) +{ + ARG_UNUSED(unused1); + ARG_UNUSED(unused2); + ARG_UNUSED(unused3); + + uint16_t len; + int8_t rssi; + otBleRadioPacket my_packet; + + LOG_INF("%s started", __func__); + + while (1) { + k_sem_take(&ot_plat_ble_event_semaphore, K_FOREVER); + ring_buf_get(&ot_plat_ble_ring_buf, (uint8_t *)&len, sizeof(len)); + ring_buf_get(&ot_plat_ble_ring_buf, &rssi, sizeof(rssi)); + if (len <= PLAT_BLE_MSG_DATA_MAX) { + ring_buf_get(&ot_plat_ble_ring_buf, ot_plat_ble_msg_buf, len); + } + + openthread_api_mutex_lock(openthread_get_default_context()); + + if (len <= PLAT_BLE_MSG_DATA_MAX) { + /* The packet parameter in otPlatBleGattServerOnWriteRequest is not const. + * Re-write all members. + */ + my_packet.mValue = ot_plat_ble_msg_buf; + my_packet.mPower = rssi; + my_packet.mLength = len; + otPlatBleGattServerOnWriteRequest(ble_openthread_instance, 0, &my_packet); + } else if (len == PLAT_BLE_MSG_CONNECT) { + otPlatBleGapOnConnected(ble_openthread_instance, 0); + } else if (len == PLAT_BLE_MSG_DISCONNECT) { + otPlatBleGapOnDisconnected(ble_openthread_instance, 0); + } + openthread_api_mutex_unlock(openthread_get_default_context()); + } +} + +/* Zephyr BLE service callbacks */ + +/* This function is called whenever the RX Characteristic has been written to by a Client */ +static ssize_t on_receive(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, + uint16_t len, uint16_t offset, uint8_t flags) +{ + LOG_DBG("Received data, handle %" PRIu16 ", len %" PRIu16, attr->handle, len); + + otError error = ot_plat_ble_queue_msg(buf, len, 0); + + if (error != OT_ERROR_NONE) { + LOG_WRN("Error queuing message: %s", otThreadErrorToString(error)); + } + + return len; +} + +/* This function is called whenever a Notification has been sent by the TX Characteristic */ +static void on_sent(struct bt_conn *conn, void *user_data) +{ + ARG_UNUSED(conn); + ARG_UNUSED(user_data); + + LOG_DBG("Data sent"); +} + +/* This function is called whenever the CCCD register has been changed by the client */ +void on_cccd_changed(const struct bt_gatt_attr *attr, uint16_t value) +{ + uint16_t mtu; + otError error = OT_ERROR_NONE; + + ARG_UNUSED(attr); + + switch (value) { + case BT_GATT_CCC_NOTIFY: + + error = ot_plat_ble_queue_msg(NULL, PLAT_BLE_MSG_CONNECT, 0); + if (error != OT_ERROR_NONE) { + LOG_WRN("Error queuing message: %s", otThreadErrorToString(error)); + } + + error = otPlatBleGattMtuGet(ble_openthread_instance, &mtu); + if (error != OT_ERROR_NONE) { + LOG_WRN("Error retrieving mtu: %s", otThreadErrorToString(error)); + } + + LOG_INF("CCCD update (mtu=%" PRIu16 ")!", mtu); + + break; + + default: + break; + } +} + +otError otPlatBleGattServerIndicate(otInstance *aInstance, uint16_t aHandle, + const otBleRadioPacket *aPacket) +{ + ARG_UNUSED(aInstance); + + /* TO DO change to indications. */ + const struct bt_gatt_attr *attr = &my_service.attrs[3]; + + struct bt_gatt_notify_params params = {.uuid = BT_UUID_TCAT_SERVICE_TX, + .attr = attr, + .data = aPacket->mValue, + .len = aPacket->mLength, + .func = on_sent}; + + LOG_DBG("Send data, handle %d, len %d", attr->handle, aPacket->mLength); + + /* Only one connection supported */ + if (aHandle != 0) { + return OT_ERROR_INVALID_ARGS; + } + + if (ot_plat_ble_connection == NULL) { + return OT_ERROR_INVALID_STATE; + } + + /* Check whether notifications are enabled or not */ + if (bt_gatt_is_subscribed(ot_plat_ble_connection, attr, BT_GATT_CCC_NOTIFY)) { + if (bt_gatt_notify_cb(ot_plat_ble_connection, ¶ms)) { + LOG_WRN("Error, unable to send notification"); + return OT_ERROR_INVALID_ARGS; + } + } else { + LOG_WRN("Warning, notification not enabled on the selected attribute"); + return OT_ERROR_INVALID_STATE; + } + + return OT_ERROR_NONE; +} + +otError otPlatBleGattMtuGet(otInstance *aInstance, uint16_t *aMtu) +{ + ARG_UNUSED(aInstance); + + if (ot_plat_ble_connection == NULL) { + return OT_ERROR_FAILED; + } + + if (aMtu != NULL) { + *aMtu = bt_gatt_get_mtu(ot_plat_ble_connection); + } + + return OT_ERROR_NONE; +} + +otError otPlatBleGapDisconnect(otInstance *aInstance) +{ + ARG_UNUSED(aInstance); + + if (ot_plat_ble_connection == NULL) { + return OT_ERROR_INVALID_STATE; + } + + if (bt_conn_disconnect(ot_plat_ble_connection, BT_HCI_ERR_REMOTE_USER_TERM_CONN)) { + return OT_ERROR_INVALID_STATE; + } + + return OT_ERROR_NONE; +} + +/* Zephyr BLE callbacks */ + +static void connected(struct bt_conn *conn, uint8_t err) +{ + struct bt_conn_info info; + char addr[BT_ADDR_LE_STR_LEN]; + uint16_t mtu; + otError error = OT_ERROR_NONE; + + ot_plat_ble_connection = bt_conn_ref(conn); + + if (err) { + LOG_WRN("Connection failed (err %u)", err); + return; + } else if (bt_conn_get_info(conn, &info)) { + LOG_WRN("Could not parse connection info"); + } else { + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + error = otPlatBleGattMtuGet(ble_openthread_instance, &mtu); + if (error != OT_ERROR_NONE) { + LOG_WRN("Error retrieving mtu: %s", otThreadErrorToString(error)); + } + + LOG_INF("Connection established (mtu=%" PRIu16 ")!", mtu); + } +} + +static void disconnected(struct bt_conn *conn, uint8_t reason) +{ + otError error = OT_ERROR_NONE; + + LOG_INF("Disconnected (reason %" PRIu8 ")", reason); + + if (ot_plat_ble_connection) { + bt_conn_unref(ot_plat_ble_connection); + ot_plat_ble_connection = NULL; + + error = ot_plat_ble_queue_msg(NULL, PLAT_BLE_MSG_DISCONNECT, 0); + if (error != OT_ERROR_NONE) { + LOG_WRN("Error queuing message: %s", otThreadErrorToString(error)); + } + } +} + +static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param) +{ + return true; +} + +static void le_param_updated(struct bt_conn *conn, uint16_t interval, uint16_t latency, + uint16_t timeout) +{ + struct bt_conn_info info; + char addr[BT_ADDR_LE_STR_LEN]; + uint16_t mtu; + otError error = OT_ERROR_NONE; + + if (bt_conn_get_info(conn, &info)) { + LOG_INF("Could not parse connection info"); + } else { + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + error = otPlatBleGattMtuGet(ble_openthread_instance, &mtu); + + if (error != OT_ERROR_NONE) { + LOG_WRN("Error retrieving mtu: %s", otThreadErrorToString(error)); + } + + LOG_INF("Connection parameters updated (mtu=%" PRIu16 ")!", mtu); + } +} + +static void bt_ready(int err) +{ + if (err) { + LOG_WRN("BLE init failed with error code %d", err); + return; + } + + bt_conn_cb_register(&conn_callbacks); + k_sem_give(&ot_plat_ble_init_semaphore); /* BLE stack up an running */ +} + +otError otPlatBleGapAdvStart(otInstance *aInstance, uint16_t aInterval) +{ + ARG_UNUSED(aInstance); + ARG_UNUSED(aInterval); + + /* TO DO advertisement format change */ + int err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)); + + if (err != 0 && err != -EALREADY) { + LOG_WRN("Advertising failed to start (err %d)", err); + return OT_ERROR_INVALID_STATE; + } + + LOG_INF("Advertising successfully started"); + + return OT_ERROR_NONE; +} + +otError otPlatBleGapAdvStop(otInstance *aInstance) +{ + ARG_UNUSED(aInstance); + + int err = bt_le_adv_stop(); + + if (err != 0 && err != -EALREADY) { + LOG_WRN("Advertisement failed to stop (err %d)", err); + return OT_ERROR_FAILED; + } + return OT_ERROR_NONE; +} + +/* Zephyr BLE initialization */ + +otError otPlatBleEnable(otInstance *aInstance) +{ + int err; + + ble_openthread_instance = aInstance; + err = bt_enable(bt_ready); + + if (err != 0 && err != -EALREADY) { + LOG_WRN("BLE enable failed with error code %d", err); + return OT_ERROR_FAILED; + } else if (err == -EALREADY) { + err = k_sem_take(&ot_plat_ble_init_semaphore, K_MSEC(500)); + return OT_ERROR_NONE; + } + + err = k_sem_take(&ot_plat_ble_init_semaphore, K_MSEC(500)); + + if (!err) { + LOG_INF("Bluetooth initialized"); + } else { + LOG_INF("BLE initialization did not complete in time"); + return OT_ERROR_FAILED; + } + + return OT_ERROR_NONE; +} + +otError otPlatBleDisable(otInstance *aInstance) +{ + ARG_UNUSED(aInstance); + /* This function intentionally does nothing since disabling advertisement disables BLE + * stack. + */ + return OT_ERROR_NONE; +} From b3979ec709df026fc655286f1a58be30b0f688e0 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 11 Dec 2023 14:15:45 +0530 Subject: [PATCH 0449/1623] [nrf noup] newlib: Revert unintended change fixup![nrf fromlist] wifi: Add the enums to the status This was only for local testing and by mistake got merged. Signed-off-by: Chaitanya Tata --- lib/libc/newlib/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libc/newlib/Kconfig b/lib/libc/newlib/Kconfig index a7d3ac38364..1b4f90341b0 100644 --- a/lib/libc/newlib/Kconfig +++ b/lib/libc/newlib/Kconfig @@ -5,7 +5,7 @@ if NEWLIB_LIBC config NEWLIB_LIBC_NANO bool "Build with newlib-nano C library" - depends on HAS_NEWLIB_LIBC_NANO && !WPA_SUPP + depends on HAS_NEWLIB_LIBC_NANO help Build with newlib-nano library, for small embedded apps. The newlib-nano library for ARM embedded processors is a part of the From 462ad3659295cc639b3c159573136731141a06cc Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 7 Dec 2023 15:05:13 +0100 Subject: [PATCH 0450/1623] [nrf fromlist] soc: nordic_nrf: Enable the TF-M NS storage partition for nordic boards Enable the TF-M NS storage partition for nordic boards. This partition is otherwise not used, and configured as secure. Fixes: #59376 Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66279 Signed-off-by: Joakim Andersson --- soc/arm/nordic_nrf/CMakeLists.txt | 4 ++++ soc/arm/nordic_nrf/Kconfig | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/soc/arm/nordic_nrf/CMakeLists.txt b/soc/arm/nordic_nrf/CMakeLists.txt index 47364b35ffb..3b097d73569 100644 --- a/soc/arm/nordic_nrf/CMakeLists.txt +++ b/soc/arm/nordic_nrf/CMakeLists.txt @@ -25,4 +25,8 @@ if(CONFIG_BUILD_WITH_TFM) set_property(TARGET zephyr_property_target APPEND PROPERTY TFM_CMAKE_OPTIONS -DZEPHYR_BASE=${ZEPHYR_BASE} ) + + set_property(TARGET zephyr_property_target + APPEND PROPERTY TFM_CMAKE_OPTIONS -DNRF_NS_STORAGE=${CONFIG_TFM_NRF_NS_STORAGE} + ) endif() diff --git a/soc/arm/nordic_nrf/Kconfig b/soc/arm/nordic_nrf/Kconfig index 19e49c05454..0372492cd7d 100644 --- a/soc/arm/nordic_nrf/Kconfig +++ b/soc/arm/nordic_nrf/Kconfig @@ -45,6 +45,10 @@ config TFM_LOG_LEVEL_SILENCE Disable TF-M secure output if the uart1 node has not assigned GPIO pins using pinctrl. +config TFM_NRF_NS_STORAGE + bool "TF-M non-secure storage partition" + default y + endif # BUILD_WITH_TFM From 349b71d443761d191fa7f0af9df0ee77229b3597 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 7 Dec 2023 19:13:35 +0100 Subject: [PATCH 0451/1623] [nrf fromlist] samples: soc_flash_nrf: Stop erasing outside of test partition Stop erasing outside of the test partition. We shouldn't really on this being accesible memory. This region may be consider as secure when application is non-secure. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66279 Signed-off-by: Joakim Andersson --- samples/drivers/soc_flash_nrf/README.rst | 2 +- samples/drivers/soc_flash_nrf/src/main.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/drivers/soc_flash_nrf/README.rst b/samples/drivers/soc_flash_nrf/README.rst index df97e4b65cc..70935c5da74 100644 --- a/samples/drivers/soc_flash_nrf/README.rst +++ b/samples/drivers/soc_flash_nrf/README.rst @@ -61,7 +61,7 @@ Sample Output Data read: 1234 Data read matches data written. Good! - Test 3: Flash erase (4 pages at 0x80000) + Test 3: Flash erase (2 pages at 0x80000) Flash erase succeeded! Test 4: Flash write (word array 2) diff --git a/samples/drivers/soc_flash_nrf/src/main.c b/samples/drivers/soc_flash_nrf/src/main.c index a438a67cf2f..91a763c781d 100644 --- a/samples/drivers/soc_flash_nrf/src/main.c +++ b/samples/drivers/soc_flash_nrf/src/main.c @@ -84,9 +84,9 @@ int main(void) } } - offset = TEST_PARTITION_OFFSET - FLASH_PAGE_SIZE * 2; - printf("\nTest 3: Flash erase (4 pages at 0x%x)\n", offset); - if (flash_erase(flash_dev, offset, FLASH_PAGE_SIZE * 4) != 0) { + offset = TEST_PARTITION_OFFSET; + printf("\nTest 3: Flash erase (2 pages at 0x%x)\n", offset); + if (flash_erase(flash_dev, offset, FLASH_PAGE_SIZE * 2) != 0) { printf(" Flash erase failed!\n"); } else { printf(" Flash erase succeeded!\n"); From 4819e656ade0727dca44e2a8d5cde16c1ebd4dc1 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 7 Dec 2023 19:16:57 +0100 Subject: [PATCH 0452/1623] [nrf fromlist] samples: soc_flash_nrf: Print finished message Print a finished message, so that it is clear that this in the end of the sample. This makes it certain that we didn't crash without output on the last test. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66279 Signed-off-by: Joakim Andersson --- samples/drivers/soc_flash_nrf/README.rst | 2 ++ samples/drivers/soc_flash_nrf/sample.yaml | 1 + samples/drivers/soc_flash_nrf/src/main.c | 2 ++ 3 files changed, 5 insertions(+) diff --git a/samples/drivers/soc_flash_nrf/README.rst b/samples/drivers/soc_flash_nrf/README.rst index 70935c5da74..14c39851f66 100644 --- a/samples/drivers/soc_flash_nrf/README.rst +++ b/samples/drivers/soc_flash_nrf/README.rst @@ -130,3 +130,5 @@ Sample Output Test 8: Write block size API write-block-size = 1 + + Finished! diff --git a/samples/drivers/soc_flash_nrf/sample.yaml b/samples/drivers/soc_flash_nrf/sample.yaml index 6557988b6e3..c493c553e1f 100644 --- a/samples/drivers/soc_flash_nrf/sample.yaml +++ b/samples/drivers/soc_flash_nrf/sample.yaml @@ -30,3 +30,4 @@ tests: - "Data read matches data written. Good!" - "SoC flash consists of \\d+ pages." - "write-block-size = 1" + - "Finished!" diff --git a/samples/drivers/soc_flash_nrf/src/main.c b/samples/drivers/soc_flash_nrf/src/main.c index 91a763c781d..33ab9b28e1d 100644 --- a/samples/drivers/soc_flash_nrf/src/main.c +++ b/samples/drivers/soc_flash_nrf/src/main.c @@ -191,5 +191,7 @@ int main(void) printf("\nTest 8: Write block size API\n"); printf(" write-block-size = %u\n", flash_get_write_block_size(flash_dev)); + + printf("\nFinished!\n"); return 0; } From 4b2ae638e61279338ce40b65a6bbed0a1f73fae2 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 7 Dec 2023 19:21:06 +0100 Subject: [PATCH 0453/1623] [nrf fromlist] samples: soc_flash_nrf: Make sure that the flash partition is valid Make sure that the flash partition is valid. With TF-M enabled the storage_partition can be used as memory that is known to be configured as non-secure flash region. The slot1_ns_partition partition is only correct when TF-M is built with BL2 enabled. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66279 Signed-off-by: Joakim Andersson --- samples/drivers/soc_flash_nrf/prj.conf | 4 ++++ samples/drivers/soc_flash_nrf/src/main.c | 6 +----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/drivers/soc_flash_nrf/prj.conf b/samples/drivers/soc_flash_nrf/prj.conf index 9909ef3b29f..48e64121b6a 100644 --- a/samples/drivers/soc_flash_nrf/prj.conf +++ b/samples/drivers/soc_flash_nrf/prj.conf @@ -3,3 +3,7 @@ CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_MPU_ALLOW_FLASH_WRITE=y CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y +CONFIG_FCB=y +CONFIG_FLASH_MAP=y +CONFIG_SETTINGS=y +CONFIG_SETTINGS_FCB=y diff --git a/samples/drivers/soc_flash_nrf/src/main.c b/samples/drivers/soc_flash_nrf/src/main.c index 33ab9b28e1d..29606a9ca5d 100644 --- a/samples/drivers/soc_flash_nrf/src/main.c +++ b/samples/drivers/soc_flash_nrf/src/main.c @@ -13,11 +13,7 @@ #include -#ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE -#define TEST_PARTITION slot1_ns_partition -#else -#define TEST_PARTITION slot1_partition -#endif +#define TEST_PARTITION storage_partition #define TEST_PARTITION_OFFSET FIXED_PARTITION_OFFSET(TEST_PARTITION) #define TEST_PARTITION_DEVICE FIXED_PARTITION_DEVICE(TEST_PARTITION) From 1c92e08276186aaa7bff4935c5b4ec03b5294b05 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 7 Dec 2023 19:35:48 +0100 Subject: [PATCH 0454/1623] [nrf fromlist] tests: flash: Use a flash partition that is known to be nonsecure With TF-M enabled the storage_partition can be used as memory that is known to be configured as non-secure flash region. The slot1_ns_partition partition is only correct when TF-M is built with BL2 enabled. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66279 Signed-off-by: Joakim Andersson --- .../flash/common/boards/nrf5340dk_nrf5340_cpuapp_ns.conf | 4 ++++ tests/drivers/flash/common/boards/nrf9160dk_nrf9160_ns.conf | 4 ++++ tests/drivers/flash/common/boards/nrf9161dk_nrf9161_ns.conf | 4 ++++ tests/drivers/flash/common/src/main.c | 3 --- tests/drivers/flash/common/testcase.yaml | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 tests/drivers/flash/common/boards/nrf5340dk_nrf5340_cpuapp_ns.conf create mode 100644 tests/drivers/flash/common/boards/nrf9160dk_nrf9160_ns.conf create mode 100644 tests/drivers/flash/common/boards/nrf9161dk_nrf9161_ns.conf diff --git a/tests/drivers/flash/common/boards/nrf5340dk_nrf5340_cpuapp_ns.conf b/tests/drivers/flash/common/boards/nrf5340dk_nrf5340_cpuapp_ns.conf new file mode 100644 index 00000000000..821a5e77e5b --- /dev/null +++ b/tests/drivers/flash/common/boards/nrf5340dk_nrf5340_cpuapp_ns.conf @@ -0,0 +1,4 @@ +CONFIG_FCB=y +CONFIG_FLASH_MAP=y +CONFIG_SETTINGS=y +CONFIG_SETTINGS_FCB=y diff --git a/tests/drivers/flash/common/boards/nrf9160dk_nrf9160_ns.conf b/tests/drivers/flash/common/boards/nrf9160dk_nrf9160_ns.conf new file mode 100644 index 00000000000..821a5e77e5b --- /dev/null +++ b/tests/drivers/flash/common/boards/nrf9160dk_nrf9160_ns.conf @@ -0,0 +1,4 @@ +CONFIG_FCB=y +CONFIG_FLASH_MAP=y +CONFIG_SETTINGS=y +CONFIG_SETTINGS_FCB=y diff --git a/tests/drivers/flash/common/boards/nrf9161dk_nrf9161_ns.conf b/tests/drivers/flash/common/boards/nrf9161dk_nrf9161_ns.conf new file mode 100644 index 00000000000..821a5e77e5b --- /dev/null +++ b/tests/drivers/flash/common/boards/nrf9161dk_nrf9161_ns.conf @@ -0,0 +1,4 @@ +CONFIG_FCB=y +CONFIG_FLASH_MAP=y +CONFIG_SETTINGS=y +CONFIG_SETTINGS_FCB=y diff --git a/tests/drivers/flash/common/src/main.c b/tests/drivers/flash/common/src/main.c index 4e73617ba41..79d75ca9b13 100644 --- a/tests/drivers/flash/common/src/main.c +++ b/tests/drivers/flash/common/src/main.c @@ -14,9 +14,6 @@ #define TEST_AREA_DEV_NODE DT_INST(0, nordic_qspi_nor) #elif defined(CONFIG_SPI_NOR) #define TEST_AREA_DEV_NODE DT_INST(0, jedec_spi_nor) -#elif defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) -/* SoC embedded NVM */ -#define TEST_AREA slot1_ns_partition #else #define TEST_AREA storage_partition #endif diff --git a/tests/drivers/flash/common/testcase.yaml b/tests/drivers/flash/common/testcase.yaml index 8e3e3cfbc4c..d1a3174c901 100644 --- a/tests/drivers/flash/common/testcase.yaml +++ b/tests/drivers/flash/common/testcase.yaml @@ -44,7 +44,7 @@ tests: drivers.flash.common.tfm_ns: build_only: true filter: (CONFIG_FLASH_HAS_DRIVER_ENABLED and CONFIG_TRUSTED_EXECUTION_NONSECURE - and dt_label_with_parent_compat_enabled("slot1_ns_partition", "fixed-partitions")) + and dt_label_with_parent_compat_enabled("storage_partition", "fixed-partitions")) integration_platforms: - nrf9161dk_nrf9161_ns drivers.flash.common.stm32: From 92c50d89502df25b5ee0a7b5f0cdf7641d1b59d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Fri, 10 Nov 2023 16:15:56 +0100 Subject: [PATCH 0455/1623] [nrf fromtree] soc: arm: Remove CPU_HAS_NRF_IDAU's dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CPU_HAS_NRF_IDAU is depending on SOC_SERIES_NRF91X and SOC_NRF5340_CPUAPP. This makes it more difficult to have an out-of-tree nrf SOC. It is also an unnecessary dependency. There is no prompt for CPU_HAS_NRF_IDAU, so it will not show up in menuconfig and it won't be possible to enable it from a users Kconfig fragment. The only way to enable it is to select it, and those that select this option can themselves make sure that they only do so when appropriate. Also, move NRF_SPU options out to SOC Kconfig files to also make out-of-tree SoCs possible. With the added benefit of not polluting the common soc/arm/Kconfig. Signed-off-by: Sebastian Bøe (cherry picked from commit 6348a973c38eeed5e18e6821dcb38a1c2f78ac76) Signed-off-by: Markus Swarowsky --- soc/arm/Kconfig | 16 ---------------- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 12 ++++++++++++ soc/arm/nordic_nrf/nrf91/Kconfig.series | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/soc/arm/Kconfig b/soc/arm/Kconfig index 443a0031189..461f0b41f84 100644 --- a/soc/arm/Kconfig +++ b/soc/arm/Kconfig @@ -34,28 +34,12 @@ config CPU_HAS_ARM_SAU config CPU_HAS_NRF_IDAU bool - depends on SOC_SERIES_NRF91X || SOC_NRF5340_CPUAPP select CPU_HAS_TEE help MCU implements the nRF (vendor-specific) Security Attribution Unit. (IDAU: "Implementation-Defined Attribution Unit", in accordance with ARM terminology). -if CPU_HAS_NRF_IDAU -config NRF_SPU_FLASH_REGION_SIZE - hex - default 0x8000 if SOC_SERIES_NRF91X - default 0x4000 if SOC_NRF5340_CPUAPP - help - FLASH region size for the NRF_SPU peripheral - -config NRF_SPU_RAM_REGION_SIZE - hex - default 0x2000 if SOC_SERIES_NRF91X || SOC_NRF5340_CPUAPP - help - RAM region size for the NRF_SPU peripheral -endif - config HAS_SWO bool help diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 2cd934af324..09b15948da0 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -98,6 +98,18 @@ config SOC_DCDC_NRF53X_HV help Enable nRF53 series System on Chip High Voltage DC/DC converter. +config NRF_SPU_FLASH_REGION_SIZE + hex + default 0x4000 + help + FLASH region size for the NRF_SPU peripheral + +config NRF_SPU_RAM_REGION_SIZE + hex + default 0x2000 + help + RAM region size for the NRF_SPU peripheral + config SOC_NRF_GPIO_FORWARDER_FOR_NRF5340 bool depends on NRF_SOC_SECURE_SUPPORTED diff --git a/soc/arm/nordic_nrf/nrf91/Kconfig.series b/soc/arm/nordic_nrf/nrf91/Kconfig.series index fd8f5b04d7a..1f2f233edb9 100644 --- a/soc/arm/nordic_nrf/nrf91/Kconfig.series +++ b/soc/arm/nordic_nrf/nrf91/Kconfig.series @@ -19,3 +19,17 @@ config SOC_SERIES_NRF91X select HAS_POWEROFF help Enable support for NRF91 MCU series + +if SOC_SERIES_NRF91X +config NRF_SPU_FLASH_REGION_SIZE + hex + default 0x8000 + help + FLASH region size for the NRF_SPU peripheral + +config NRF_SPU_RAM_REGION_SIZE + hex + default 0x2000 + help + RAM region size for the NRF_SPU peripheral +endif From 1f49692993f6ad7f1ee1e19ff27d3ff56659b23e Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Mon, 4 Dec 2023 15:27:08 +0100 Subject: [PATCH 0456/1623] [nrf noup] soc: arm: nRF53: Add SPU Flash/RAM alignment TF-M will uses SPU alignment during build time to make sure all partitions can be locked down with the SPU. So adding them for nRF53 Signed-off-by: Markus Swarowsky --- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 09b15948da0..1c8527e1716 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -104,12 +104,26 @@ config NRF_SPU_FLASH_REGION_SIZE help FLASH region size for the NRF_SPU peripheral +config NRF_SPU_FLASH_REGION_ALIGNMENT + hex + default 0x4000 + help + FLASH regions must be aligned to this value due to SPU HW + limitations. + config NRF_SPU_RAM_REGION_SIZE hex default 0x2000 help RAM region size for the NRF_SPU peripheral +config NRF_SPU_RAM_REGION_ALIGNMENT + hex + default 0x2000 + help + RAM regions must be aligned to this value due to SPU HW + limitations. + config SOC_NRF_GPIO_FORWARDER_FOR_NRF5340 bool depends on NRF_SOC_SECURE_SUPPORTED From 89be4330a38498731fe612f1343624fc3d0a098e Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Mon, 4 Dec 2023 15:27:14 +0100 Subject: [PATCH 0457/1623] [nrf noup] soc: arm: nRF91: Add SPU Flash/RAM alignment TF-M will uses SPU alignment during build time to make sure all partitions can be locked down with the SPU. So adding them for nRF91 Signed-off-by: Markus Swarowsky --- soc/arm/nordic_nrf/nrf91/Kconfig.series | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/soc/arm/nordic_nrf/nrf91/Kconfig.series b/soc/arm/nordic_nrf/nrf91/Kconfig.series index 1f2f233edb9..9e0e477e851 100644 --- a/soc/arm/nordic_nrf/nrf91/Kconfig.series +++ b/soc/arm/nordic_nrf/nrf91/Kconfig.series @@ -27,9 +27,23 @@ config NRF_SPU_FLASH_REGION_SIZE help FLASH region size for the NRF_SPU peripheral +config NRF_SPU_FLASH_REGION_ALIGNMENT + hex + default 0x8000 + help + FLASH regions must be aligned to this value due to SPU HW + limitations. + config NRF_SPU_RAM_REGION_SIZE hex default 0x2000 help RAM region size for the NRF_SPU peripheral + +config NRF_SPU_RAM_REGION_ALIGNMENT + hex + default 0x2000 + help + RAM regions must be aligned to this value due to SPU HW + limitations. endif From ec48dcb2ee4973bee58fbe610750fe62635a0e3f Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 25 Aug 2023 13:44:29 +0200 Subject: [PATCH 0458/1623] [nrf fromtree] tfm: Harded build against TF-M built with unsecure keys Introduce Kconfig option in zephyr build system that reflects the TF-M cmake config variable with the same default value for dummy provisioning and have it satisfy the IAK present requirement. This configuration is not suitable for production, and by having this in zephyr configuration we can have this as part of the hardened configuration check. Signed-off-by: Joakim Andersson (cherry picked from commit 25787e2df66aef6979503d613c292043ac5f6291) Signed-off-by: Joakim Andersson --- boards/arm/b_u585i_iot02a/Kconfig.defconfig | 7 +++++++ modules/trusted-firmware-m/CMakeLists.txt | 17 ++++++++++++++++- modules/trusted-firmware-m/Kconfig.tfm | 11 +++++++++++ scripts/kconfig/hardened.csv | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/boards/arm/b_u585i_iot02a/Kconfig.defconfig b/boards/arm/b_u585i_iot02a/Kconfig.defconfig index 93748d0dcf2..78c0253fe41 100644 --- a/boards/arm/b_u585i_iot02a/Kconfig.defconfig +++ b/boards/arm/b_u585i_iot02a/Kconfig.defconfig @@ -20,4 +20,11 @@ config USE_DT_CODE_PARTITION config SYS_CLOCK_TICKS_PER_SEC default 4096 if STM32_LPTIM_TIMER +if BUILD_WITH_TFM + +config TFM_DUMMY_PROVISIONING + default n + +endif # BUILD_WITH_TFM + endif # BOARD_B_U585I_IOT02A diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index 177a47e28d6..ad1109d849b 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -95,6 +95,12 @@ if (CONFIG_BUILD_WITH_TFM) list(APPEND TFM_CMAKE_ARGS -DMCUBOOT_IMAGE_NUMBER=${CONFIG_TFM_MCUBOOT_IMAGE_NUMBER}) endif() + if (CONFIG_TFM_DUMMY_PROVISIONING) + list(APPEND TFM_CMAKE_ARGS -DTFM_DUMMY_PROVISIONING=ON) + else() + list(APPEND TFM_CMAKE_ARGS -DTFM_DUMMY_PROVISIONING=OFF) + endif() + if (CONFIG_TFM_EXCEPTION_INFO_DUMP) list(APPEND TFM_CMAKE_ARGS -DTFM_EXCEPTION_INFO_DUMP=ON) else() @@ -579,4 +585,13 @@ if (CONFIG_BUILD_WITH_TFM) ${MERGED_FILE} ) endif() -endif() + + if(CONFIG_TFM_DUMMY_PROVISIONING) + message(WARNING + "TFM_DUMMY_PROVISIONING is enabled: + The device will be provisioned using dummy keys and is NOT secure! + This is not suitable for production" + ) + endif() + +endif() # CONFIG_BUILD_WITH_TFM diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index 2a5edb64343..4fac243cf41 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -177,6 +177,17 @@ config TFM_PARTITION_PLATFORM_CUSTOM_REBOOT Instead the application will have to override the weak ARM implementation of sys_arch_reset(). +config TFM_DUMMY_PROVISIONING + bool "Provision with dummy values. NOT to be used in production" + default y + help + If this option is enabled (as it is by default), a set of dummy + keys / data will be provisioned. The dummy IAK matches the IAK tested + by the TF-M tests, and the dummy bl2 ROTPKs match the dummy bl2 keys + used by default. + This option MUST not be used in production hardware, as the keys are + insecure. + config TFM_BL2_NOT_SUPPORTED bool help diff --git a/scripts/kconfig/hardened.csv b/scripts/kconfig/hardened.csv index a09defdc756..6a2937df65c 100644 --- a/scripts/kconfig/hardened.csv +++ b/scripts/kconfig/hardened.csv @@ -39,6 +39,7 @@ TEST_RANDOM_GENERATOR,n TEST_SHELL,n TEST_USERSPACE,n TFM_CMAKE_BUILD_TYPE_DEBUG,n +TFM_DUMMY_PROVISIONING,n THREAD_MONITOR,n THREAD_NAME,n TIMER_RANDOM_GENERATOR,n From 2ac74ca47b0ae06ff19755985e01b07b150f53b5 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 25 Aug 2023 13:55:49 +0200 Subject: [PATCH 0459/1623] [nrf fromtree] tfm: Enforce initial attestation with required key provisioned Enforce that the initial attestation partition has the required initial attestation key provisioned. If the initial attestation key (IAK) is not present during boot of TF-M the system will panic during initialization. Signed-off-by: Joakim Andersson (cherry picked from commit 2687376effac881c550e2c568c3d4ad10a67385b) --- boards/arm/b_u585i_iot02a/Kconfig.defconfig | 4 ++++ modules/trusted-firmware-m/Kconfig.tfm | 8 ++++++++ modules/trusted-firmware-m/Kconfig.tfm.partitions | 1 + 3 files changed, 13 insertions(+) diff --git a/boards/arm/b_u585i_iot02a/Kconfig.defconfig b/boards/arm/b_u585i_iot02a/Kconfig.defconfig index 78c0253fe41..84e7bdb320a 100644 --- a/boards/arm/b_u585i_iot02a/Kconfig.defconfig +++ b/boards/arm/b_u585i_iot02a/Kconfig.defconfig @@ -22,6 +22,10 @@ config SYS_CLOCK_TICKS_PER_SEC if BUILD_WITH_TFM +# Initial Attestation key provisioned by the BL1 bootloader +config TFM_INITIAL_ATTESTATION_KEY + default y + config TFM_DUMMY_PROVISIONING default n diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index 4fac243cf41..dc2ab24b17d 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -179,6 +179,7 @@ config TFM_PARTITION_PLATFORM_CUSTOM_REBOOT config TFM_DUMMY_PROVISIONING bool "Provision with dummy values. NOT to be used in production" + select TFM_INITIAL_ATTESTATION_KEY default y help If this option is enabled (as it is by default), a set of dummy @@ -188,6 +189,13 @@ config TFM_DUMMY_PROVISIONING This option MUST not be used in production hardware, as the keys are insecure. +config TFM_INITIAL_ATTESTATION_KEY + bool + help + Hidden option to mark that the TF-M platform has an initial + attestation key, which is a requirement for the Initial Attestation + partition. + config TFM_BL2_NOT_SUPPORTED bool help diff --git a/modules/trusted-firmware-m/Kconfig.tfm.partitions b/modules/trusted-firmware-m/Kconfig.tfm.partitions index cd9aaadb1ec..67b46f5328b 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm.partitions +++ b/modules/trusted-firmware-m/Kconfig.tfm.partitions @@ -44,6 +44,7 @@ config TFM_PARTITION_CRYPTO config TFM_PARTITION_INITIAL_ATTESTATION bool "Secure partition 'Initial Attestation'" depends on TFM_PARTITION_CRYPTO + depends on TFM_INITIAL_ATTESTATION_KEY default n help Setting this option will cause '-DTFM_PARTITION_INITIAL_ATTESTATION' From ae5914c83154f90d3ab115e81c067e5275ff2917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Ciupis?= Date: Wed, 22 Nov 2023 09:56:03 +0100 Subject: [PATCH 0460/1623] [nrf fromtree] drivers: ieee802154: nrf5: support raw mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When CONFIG_IEEE802154_RAW_MODE is set there is no network interface that could provide pointer to the device the interface is running on top of. The current implementation of nRF5 ieee802154 driver implicitly assumes that such an interface is always present, which leads to crashes when raw mode is enabled. This commit adds support for IEEE802154_RAW_MODE in nRF5 ieee802154 driver by latching pointer to the ieee802154 device on initialization if needed so that it doesn't have to be retrieved using the network interface in run-time. Signed-off-by: Jędrzej Ciupis (cherry picked from commit 0bad09c7faec98ccfb01326896fc3032f466147c) --- drivers/ieee802154/ieee802154_nrf5.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index f636da67983..779a0b842fe 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -57,6 +57,9 @@ struct nrf5_802154_config { }; static struct nrf5_802154_data nrf5_data; +#if defined(CONFIG_IEEE802154_RAW_MODE) +static const struct device *nrf5_dev; +#endif #define ACK_REQUEST_BYTE 1 #define ACK_REQUEST_BIT (1 << 5) @@ -98,6 +101,15 @@ static struct nrf5_802154_data nrf5_data; #define IEEE802154_NRF5_VENDOR_OUI (uint32_t)0xF4CE36 #endif +static inline const struct device *nrf5_get_device(void) +{ +#if defined(CONFIG_IEEE802154_RAW_MODE) + return nrf5_dev; +#else + return net_if_get_device(nrf5_data.iface); +#endif +} + static void nrf5_get_eui64(uint8_t *mac) { uint64_t factoryAddress; @@ -736,6 +748,9 @@ static int nrf5_init(const struct device *dev) { const struct nrf5_802154_config *nrf5_radio_cfg = NRF5_802154_CFG(dev); struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev); +#if defined(CONFIG_IEEE802154_RAW_MODE) + nrf5_dev = dev; +#endif k_fifo_init(&nrf5_radio->rx_fifo); k_sem_init(&nrf5_radio->tx_wait, 0, 1); @@ -1016,7 +1031,7 @@ void nrf_802154_received_timestamp_raw(uint8_t *data, int8_t power, uint8_t lqi, void nrf_802154_receive_failed(nrf_802154_rx_error_t error, uint32_t id) { - const struct device *dev = net_if_get_device(nrf5_data.iface); + const struct device *dev = nrf5_get_device(); #if defined(CONFIG_IEEE802154_CSL_ENDPOINT) if (id == DRX_SLOT_RX) { @@ -1133,7 +1148,7 @@ void nrf_802154_energy_detected(const nrf_802154_energy_detected_t *result) energy_scan_done_cb_t callback = nrf5_data.energy_scan_done; nrf5_data.energy_scan_done = NULL; - callback(net_if_get_device(nrf5_data.iface), result->ed_dbm); + callback(nrf5_get_device(), result->ed_dbm); } } @@ -1143,7 +1158,7 @@ void nrf_802154_energy_detection_failed(nrf_802154_ed_error_t error) energy_scan_done_cb_t callback = nrf5_data.energy_scan_done; nrf5_data.energy_scan_done = NULL; - callback(net_if_get_device(nrf5_data.iface), SHRT_MAX); + callback(nrf5_get_device(), SHRT_MAX); } } From 6e296fb2733fb373b5059bf642e8eec2b8635277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Ciupis?= Date: Mon, 27 Nov 2023 09:21:29 +0100 Subject: [PATCH 0461/1623] [nrf fromtree] modules: hal_nordic: nrf_802154: lengthen serialization ring buffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit increases the length of ring buffer that holds serialized nRF 802.15.4 API calls so that it can simultaneously store all notifications the driver is capable of issuing. Currently that's not the case, which creates a possibility of the serialization buffers running out while the driver is issuing notifications. Signed-off-by: Jędrzej Ciupis (cherry picked from commit 29d027a47b8cb8bccfbed32f1f98e3d4d1ebe114) --- .../serialization/platform/nrf_802154_spinel_backend_ipc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/hal_nordic/nrf_802154/serialization/platform/nrf_802154_spinel_backend_ipc.c b/modules/hal_nordic/nrf_802154/serialization/platform/nrf_802154_spinel_backend_ipc.c index 06ad1f003e6..8a9cd8739b2 100644 --- a/modules/hal_nordic/nrf_802154/serialization/platform/nrf_802154_spinel_backend_ipc.c +++ b/modules/hal_nordic/nrf_802154/serialization/platform/nrf_802154_spinel_backend_ipc.c @@ -71,9 +71,11 @@ nrf_802154_ser_err_t nrf_802154_backend_init(void) } /* Send packet thread details */ -#define RING_BUFFER_LEN 16 #define SEND_THREAD_STACK_SIZE 1024 +/* Make the ring buffer long enough to hold all notifications that the driver can produce */ +#define RING_BUFFER_LEN (CONFIG_NRF_802154_RX_BUFFERS + 10) + static K_SEM_DEFINE(send_sem, 0, RING_BUFFER_LEN); K_THREAD_STACK_DEFINE(send_thread_stack, SEND_THREAD_STACK_SIZE); struct k_thread send_thread_data; From 14a3d4d979bee0ecae346e24b112bb61732f0915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Ciupis?= Date: Tue, 21 Nov 2023 14:49:42 +0100 Subject: [PATCH 0462/1623] [nrf fromtree] drivers: ieee802154: support Key Identifier Mode > 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IEEE 802.15.4-2020 defines four possible values for Key Identifier Mode field of the Auxiliary Security Header. The current ieee802154 driver API only supports two of them: b00 and b01. This commit adds support for the two remaining Key Identifier Mode values. It's done by replacing a field that can only hold Key Index into a field that can holds a pointer to the entire Key Identifier field. See IEEE 802.15.4-2020, sections 9.4.2.3 and 9.4.4 for further reference. Signed-off-by: Jędrzej Ciupis (cherry picked from commit 7afeb62e209258ddf6d0765bf387a757c3b087c8) --- drivers/ieee802154/ieee802154_nrf5.c | 26 +++++++------------------- include/zephyr/net/ieee802154_radio.h | 7 ++++++- modules/openthread/platform/radio.c | 27 ++++++++++++++++++--------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index 779a0b842fe..35dbcaf11c8 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -791,25 +791,17 @@ static void nrf5_iface_init(struct net_if *iface) #if defined(CONFIG_NRF_802154_ENCRYPTION) static void nrf5_config_mac_keys(struct ieee802154_key *mac_keys) { - static nrf_802154_key_id_t stored_key_ids[NRF_802154_SECURITY_KEY_STORAGE_SIZE]; - static uint8_t stored_ids[NRF_802154_SECURITY_KEY_STORAGE_SIZE]; - uint8_t i; + nrf_802154_security_key_remove_all(); - for (i = 0; i < NRF_802154_SECURITY_KEY_STORAGE_SIZE && stored_key_ids[i].p_key_id; i++) { - nrf_802154_security_key_remove(&stored_key_ids[i]); - stored_key_ids[i].p_key_id = NULL; - } - - i = 0; - for (struct ieee802154_key *keys = mac_keys; keys->key_value - && i < NRF_802154_SECURITY_KEY_STORAGE_SIZE; keys++, i++) { + for (uint8_t i = 0; mac_keys->key_value + && i < NRF_802154_SECURITY_KEY_STORAGE_SIZE; mac_keys++, i++) { nrf_802154_key_t key = { - .value.p_cleartext_key = keys->key_value, - .id.mode = keys->key_id_mode, - .id.p_key_id = &(keys->key_index), + .value.p_cleartext_key = mac_keys->key_value, + .id.mode = mac_keys->key_id_mode, + .id.p_key_id = mac_keys->key_id, .type = NRF_802154_KEY_CLEARTEXT, .frame_counter = 0, - .use_global_frame_counter = !(keys->frame_counter_per_key), + .use_global_frame_counter = !(mac_keys->frame_counter_per_key), }; __ASSERT_EVAL((void)nrf_802154_security_key_store(&key), @@ -817,10 +809,6 @@ static void nrf5_config_mac_keys(struct ieee802154_key *mac_keys) err == NRF_802154_SECURITY_ERROR_NONE || err == NRF_802154_SECURITY_ERROR_ALREADY_PRESENT, "Storing key failed, err: %d", err); - - stored_ids[i] = *key.id.p_key_id; - stored_key_ids[i].mode = key.id.mode; - stored_key_ids[i].p_key_id = &stored_ids[i]; }; } #endif /* CONFIG_NRF_802154_ENCRYPTION */ diff --git a/include/zephyr/net/ieee802154_radio.h b/include/zephyr/net/ieee802154_radio.h index ae175ac8e85..861523cbf6a 100644 --- a/include/zephyr/net/ieee802154_radio.h +++ b/include/zephyr/net/ieee802154_radio.h @@ -224,11 +224,16 @@ struct ieee802154_filter { }; struct ieee802154_key { + /** Key material */ uint8_t *key_value; + /** Initial value of frame counter associated with the key, see section 9.4.3 */ uint32_t key_frame_counter; + /** Indicates if per-key frame counter should be used, see section 9.4.3 */ bool frame_counter_per_key; + /** Key Identifier Mode, see section 9.4.2.3, Table 9-7 */ uint8_t key_id_mode; - uint8_t key_index; + /** Key Identifier, see section 9.4.4 */ + uint8_t *key_id; }; /** IEEE802.15.4 Transmission mode. */ diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index 9d50e445714..e64e47a5fa9 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -1181,20 +1181,14 @@ void otPlatRadioSetMacKey(otInstance *aInstance, uint8_t aKeyIdMode, uint8_t aKe struct ieee802154_key keys[] = { { .key_id_mode = key_id_mode, - .key_index = aKeyId == 1 ? 0x80 : aKeyId - 1, - .key_value = (uint8_t *)aPrevKey->mKeyMaterial.mKey.m8, .frame_counter_per_key = false, }, { .key_id_mode = key_id_mode, - .key_index = aKeyId, - .key_value = (uint8_t *)aCurrKey->mKeyMaterial.mKey.m8, .frame_counter_per_key = false, }, { .key_id_mode = key_id_mode, - .key_index = aKeyId == 0x80 ? 1 : aKeyId + 1, - .key_value = (uint8_t *)aNextKey->mKeyMaterial.mKey.m8, .frame_counter_per_key = false, }, { @@ -1208,9 +1202,24 @@ void otPlatRadioSetMacKey(otInstance *aInstance, uint8_t aKeyIdMode, uint8_t aKe }, }; - /* aKeyId in range: (1, 0x80) means valid keys - * aKeyId == 0 is used only to clear keys for stack reset in RCP - */ + if (key_id_mode == 1) { + /* aKeyId in range: (1, 0x80) means valid keys */ + uint8_t prev_key_id = aKeyId == 1 ? 0x80 : aKeyId - 1; + uint8_t next_key_id = aKeyId == 0x80 ? 1 : aKeyId + 1; + + keys[0].key_id = &prev_key_id; + keys[0].key_value = (uint8_t *)aPrevKey->mKeyMaterial.mKey.m8; + + keys[1].key_id = &aKeyId; + keys[1].key_value = (uint8_t *)aCurrKey->mKeyMaterial.mKey.m8; + + keys[2].key_id = &next_key_id; + keys[2].key_value = (uint8_t *)aNextKey->mKeyMaterial.mKey.m8; + } else { + /* aKeyId == 0 is used only to clear keys for stack reset in RCP */ + __ASSERT_NO_MSG((key_id_mode == 0) && (aKeyId == 0)); + } + struct ieee802154_config config = { .mac_keys = aKeyId == 0 ? clear_keys : keys, }; From cac385035be59178826590a46db63f5d3d800e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Ciupis?= Date: Mon, 4 Dec 2023 10:19:11 +0100 Subject: [PATCH 0463/1623] [nrf fromtree] modules: hal_nordic: nrf_802154: remove magic number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit replaces a magic number in the definition of serialization ring buffer length with a macro provided by the 802.15.4 driver. Signed-off-by: Jędrzej Ciupis (cherry picked from commit 00f7c0e445d43b3e460aea6b7894f833dd469e2e) --- .../serialization/platform/nrf_802154_spinel_backend_ipc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/hal_nordic/nrf_802154/serialization/platform/nrf_802154_spinel_backend_ipc.c b/modules/hal_nordic/nrf_802154/serialization/platform/nrf_802154_spinel_backend_ipc.c index 8a9cd8739b2..b2629eef67b 100644 --- a/modules/hal_nordic/nrf_802154/serialization/platform/nrf_802154_spinel_backend_ipc.c +++ b/modules/hal_nordic/nrf_802154/serialization/platform/nrf_802154_spinel_backend_ipc.c @@ -9,6 +9,7 @@ #include #include +#include "nrf_802154.h" #include "nrf_802154_spinel_backend_callouts.h" #include "nrf_802154_serialization_error.h" #include "../../spinel_base/spinel.h" @@ -74,7 +75,7 @@ nrf_802154_ser_err_t nrf_802154_backend_init(void) #define SEND_THREAD_STACK_SIZE 1024 /* Make the ring buffer long enough to hold all notifications that the driver can produce */ -#define RING_BUFFER_LEN (CONFIG_NRF_802154_RX_BUFFERS + 10) +#define RING_BUFFER_LEN (NRF_802154_MAX_PENDING_NOTIFICATIONS + 1) static K_SEM_DEFINE(send_sem, 0, RING_BUFFER_LEN); K_THREAD_STACK_DEFINE(send_thread_stack, SEND_THREAD_STACK_SIZE); From 7d3f7bbf99454d8903c01490670a5a83d4fbd114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Fri, 3 Nov 2023 10:57:08 +0100 Subject: [PATCH 0464/1623] [nrf fromtree] drivers: nrf_qspi_nor: Activate QSPI peripheral when enabling XIP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The way that the QSPI peripheral is activated has been changed in nrfx 3.2.0. Now the peripheral is not activated during the driver initialization. Instead, the driver activates the peripheral when the first operation is requested or when `nrfx_qspi_activate()` is called. In case of XIP, the latter needs to be used, as there may be no standard operation request. Signed-off-by: Andrzej Głąbek (cherry picked from commit 1081df9554d225990f5137627adf8ecbdc963c01) --- drivers/flash/nrf_qspi_nor.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index e2ce6e6a706..c373a2c8ab7 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -1457,6 +1457,9 @@ void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable) nrf_qspi_xip_set(NRF_QSPI, enable); #endif qspi_lock(dev); + if (enable) { + (void)nrfx_qspi_activate(false); + } dev_data->xip_enabled = enable; qspi_unlock(dev); From 93e398cd1fdd7abb0a6ec347ebaa09f1ff5172ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Fri, 3 Nov 2023 12:08:09 +0100 Subject: [PATCH 0465/1623] [nrf fromtree] drivers: nrf_qspi_nor: Prevent reading status before sending RDPD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After entering the Deep Power-down mode, some flash chips ignore all commands except from the one that releases the chip from the DP mode and it is not possible to successfully read their Status Register then. Since the QSPI peripheral tries to read this register when it is being activated, it consequently fails to send the actual command that would release the flash chip from the DP mode if that is to be done right after QSPI initialization. Prevent this problem by performing the QSPI activation with all pins disconnected. This causes that the Status Register value is read as all zeros and allows the activation to always finish successfully, and the RDPD command to be properly sent. Signed-off-by: Andrzej Głąbek (cherry picked from commit 1727bbcc7046eb5870df7409310d58e0c9483233) --- drivers/flash/nrf_qspi_nor.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index c373a2c8ab7..945daa03d84 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -1339,15 +1339,34 @@ static int enter_dpd(const struct device *const dev) static int exit_dpd(const struct device *const dev) { if (IS_ENABLED(DT_INST_PROP(0, has_dpd))) { + nrf_qspi_pins_t pins; + nrf_qspi_pins_t disconnected_pins = { + .sck_pin = NRF_QSPI_PIN_NOT_CONNECTED, + .csn_pin = NRF_QSPI_PIN_NOT_CONNECTED, + .io0_pin = NRF_QSPI_PIN_NOT_CONNECTED, + .io1_pin = NRF_QSPI_PIN_NOT_CONNECTED, + .io2_pin = NRF_QSPI_PIN_NOT_CONNECTED, + .io3_pin = NRF_QSPI_PIN_NOT_CONNECTED, + }; struct qspi_cmd cmd = { .op_code = SPI_NOR_CMD_RDPD, }; uint32_t t_exit_dpd = DT_INST_PROP_OR(0, t_exit_dpd, 0); - int ret; + nrfx_err_t res; + int rc; - ret = qspi_send_cmd(dev, &cmd, false); - if (ret < 0) { - return ret; + nrf_qspi_pins_get(NRF_QSPI, &pins); + nrf_qspi_pins_set(NRF_QSPI, &disconnected_pins); + res = nrfx_qspi_activate(true); + nrf_qspi_pins_set(NRF_QSPI, &pins); + + if (res != NRFX_SUCCESS) { + return -EIO; + } + + rc = qspi_send_cmd(dev, &cmd, false); + if (rc < 0) { + return rc; } if (t_exit_dpd) { From 72a0fceed9941275c0c5b666363360a99f293d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Mon, 6 Nov 2023 14:31:56 +0100 Subject: [PATCH 0466/1623] [nrf fromtree] drivers: nrf_qspi_nor: Clean up handling of return values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consistently use `res` for results of calls to nrfx functions and `rc` for Zephyr return codes, to avoid mixing up those two and for example calling `qspi_get_zephyr_ret_code()` for a value that is already a Zephyr return code. Correct also such call in `qspi_nor_write()`. Signed-off-by: Andrzej Głąbek (cherry picked from commit 4a4558128848b3cc01a153ab128fb6aa09316a99) --- drivers/flash/nrf_qspi_nor.c | 248 ++++++++++++++++++----------------- 1 file changed, 125 insertions(+), 123 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index 945daa03d84..653f8b38f4e 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -371,7 +371,7 @@ static int qspi_device_init(const struct device *dev) return pm_device_runtime_get(dev); #else nrfx_err_t res; - int ret = 0; + int rc = 0; qspi_lock(dev); @@ -389,13 +389,13 @@ static int qspi_device_init(const struct device *dev) res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); - ret = qspi_get_zephyr_ret_code(res); - qspi_initialized = (ret == 0); + rc = qspi_get_zephyr_ret_code(res); + qspi_initialized = (rc == 0); } qspi_unlock(dev); - return ret; + return rc; #endif } @@ -408,10 +408,10 @@ static void qspi_device_uninit(const struct device *dev) } #ifdef CONFIG_PM_DEVICE_RUNTIME - int ret = pm_device_runtime_put(dev); + int rc = pm_device_runtime_put(dev); - if (ret < 0) { - LOG_ERR("Failed to schedule device sleep: %d", ret); + if (rc < 0) { + LOG_ERR("Failed to schedule device sleep: %d", rc); } #else bool last = true; @@ -526,27 +526,27 @@ static int qspi_rdsr(const struct device *dev, uint8_t sr_num) .op_code = opcode, .rx_buf = &sr_buf, }; - int ret = qspi_send_cmd(dev, &cmd, false); + int rc = qspi_send_cmd(dev, &cmd, false); - return (ret < 0) ? ret : sr; + return (rc < 0) ? rc : sr; } /* Wait until RDSR confirms write is not in progress. */ static int qspi_wait_while_writing(const struct device *dev) { - int ret; + int rc; do { - ret = qspi_rdsr(dev, 1); - } while ((ret >= 0) - && ((ret & SPI_NOR_WIP_BIT) != 0U)); + rc = qspi_rdsr(dev, 1); + } while ((rc >= 0) + && ((rc & SPI_NOR_WIP_BIT) != 0U)); - return (ret < 0) ? ret : 0; + return (rc < 0) ? rc : 0; } static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) { - int ret = 0; + int rc = 0; uint8_t opcode = SPI_NOR_CMD_WRSR; uint8_t length = 1; uint8_t sr_array[2] = {0}; @@ -559,12 +559,12 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) sr_array[0] = sr_val; #if SR1_WRITE_CLEARS_SR2 /* Writing sr1 clears sr2. need to read/modify/write both. */ - ret = qspi_rdsr(dev, 2); - if (ret < 0) { - LOG_ERR("RDSR for WRSR failed: %d", ret); - return ret; + rc = qspi_rdsr(dev, 2); + if (rc < 0) { + LOG_ERR("RDSR for WRSR failed: %d", rc); + return rc; } - sr_array[1] = ret; + sr_array[1] = rc; length = 2; #endif } else { /* sr_num == 2 */ @@ -574,12 +574,12 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) * Uses standard WRSR opcode */ sr_array[1] = sr_val; - ret = qspi_rdsr(dev, 1); - if (ret < 0) { - LOG_ERR("RDSR for WRSR failed: %d", ret); - return ret; + rc = qspi_rdsr(dev, 1); + if (rc < 0) { + LOG_ERR("RDSR for WRSR failed: %d", rc); + return rc; } - sr_array[0] = ret; + sr_array[0] = rc; length = 2; #elif IS_EQUAL(INST_0_QER, JESD216_DW15_QER_VAL_S2B1v6) /* Writing sr2 uses a dedicated WRSR2 command */ @@ -600,17 +600,17 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) .tx_buf = &sr_buf, }; - ret = qspi_send_cmd(dev, &cmd, true); + rc = qspi_send_cmd(dev, &cmd, true); /* Writing SR can take some time, and further * commands sent while it's happening can be * corrupted. Wait. */ - if (ret == 0) { - ret = qspi_wait_while_writing(dev); + if (rc == 0) { + rc = qspi_wait_while_writing(dev); } - return ret; + return rc; } #endif /* !IS_EQUAL(INST_0_QER, JESD216_DW15_QER_VAL_NONE) */ @@ -627,16 +627,16 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) return -EINVAL; } - int rv = 0; const struct qspi_nor_config *params = dev->config; + int rc, rc2; - rv = qspi_device_init(dev); - if (rv != 0) { + rc = qspi_device_init(dev); + if (rc != 0) { goto out; } qspi_trans_lock(dev); - rv = qspi_nor_write_protection_set(dev, false); - if (rv != 0) { + rc = qspi_nor_write_protection_set(dev, false); + if (rc != 0) { goto out_trans_unlock; } qspi_lock(dev); @@ -670,16 +670,16 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) size -= adj; } else { LOG_ERR("erase error at 0x%lx size %zu", (long)addr, size); - rv = qspi_get_zephyr_ret_code(res); + rc = qspi_get_zephyr_ret_code(res); break; } } qspi_unlock(dev); - int rv2 = qspi_nor_write_protection_set(dev, true); + rc2 = qspi_nor_write_protection_set(dev, true); - if (!rv) { - rv = rv2; + if (!rc) { + rc = rc2; } out_trans_unlock: @@ -687,7 +687,7 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) out: qspi_device_uninit(dev); - return rv; + return rc; } /* Configures QSPI memory for the transfer */ @@ -695,6 +695,8 @@ static int qspi_nrfx_configure(const struct device *dev) { struct qspi_nor_data *dev_data = dev->data; const struct qspi_nor_config *dev_config = dev->config; + nrfx_err_t res; + int rc; #if defined(CONFIG_SOC_SERIES_NRF53X) /* When the QSPI peripheral is activated, during the nrfx_qspi driver @@ -705,18 +707,16 @@ static int qspi_nrfx_configure(const struct device *dev) nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); #endif - nrfx_err_t res = nrfx_qspi_init(&dev_config->nrfx_cfg, - qspi_handler, - dev_data); + res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); #if defined(CONFIG_SOC_SERIES_NRF53X) /* Restore the default /4 divider after the QSPI initialization. */ nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); #endif - int ret = qspi_get_zephyr_ret_code(res); - if (ret < 0) { - return ret; + rc = qspi_get_zephyr_ret_code(res); + if (rc < 0) { + return rc; } #if DT_INST_NODE_HAS_PROP(0, rx_delay) @@ -736,9 +736,9 @@ static int qspi_nrfx_configure(const struct device *dev) * bootloader) might have set DPD mode before reboot. As a result, * attempt to exit DPD mode regardless of whether CONFIG_PM_DEVICE is set. */ - ret = exit_dpd(dev); - if (ret < 0) { - return ret; + rc = exit_dpd(dev); + if (rc < 0) { + return rc; } /* Set QE to match transfer mode. If not using quad @@ -769,28 +769,28 @@ static int qspi_nrfx_configure(const struct device *dev) return -EINVAL; #endif - ret = qspi_rdsr(dev, sr_num); - if (ret < 0) { - LOG_ERR("RDSR failed: %d", ret); - return ret; + rc = qspi_rdsr(dev, sr_num); + if (rc < 0) { + LOG_ERR("RDSR failed: %d", rc); + return rc; } - uint8_t sr = (uint8_t)ret; + uint8_t sr = (uint8_t)rc; bool qe_state = ((sr & qe_mask) != 0U); LOG_DBG("RDSR %02x QE %d need %d: %s", sr, qe_state, qe_value, (qe_state != qe_value) ? "updating" : "no-change"); - ret = 0; + rc = 0; if (qe_state != qe_value) { sr ^= qe_mask; - ret = qspi_wrsr(dev, sr, sr_num); + rc = qspi_wrsr(dev, sr, sr_num); } - if (ret < 0) { + if (rc < 0) { LOG_ERR("QE %s failed: %d", qe_value ? "set" : "clear", - ret); - return ret; + rc); + return rc; } #endif @@ -802,16 +802,16 @@ static int qspi_nrfx_configure(const struct device *dev) /* Call will send write enable before instruction if that * requirement is encoded in INST_0_4BA. */ - ret = qspi_send_cmd(dev, &cmd, (INST_0_4BA & 0x02)); + rc = qspi_send_cmd(dev, &cmd, (INST_0_4BA & 0x02)); - if (ret < 0) { - LOG_ERR("E4BA cmd issue failed: %d.", ret); + if (rc < 0) { + LOG_ERR("E4BA cmd issue failed: %d.", rc); } else { LOG_DBG("E4BA cmd issued."); } } - return ret; + return rc; } static int qspi_read_jedec_id(const struct device *dev, @@ -826,14 +826,14 @@ static int qspi_read_jedec_id(const struct device *dev, .rx_buf = &rx_buf, }; - int ret = qspi_device_init(dev); + int rc = qspi_device_init(dev); - if (ret == 0) { - ret = qspi_send_cmd(dev, &cmd, false); + if (rc == 0) { + rc = qspi_send_cmd(dev, &cmd, false); } qspi_device_uninit(dev); - return ret; + return rc; } #if defined(CONFIG_FLASH_JESD216_API) @@ -856,13 +856,13 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, .io3_level = true, }; - int ret = qspi_device_init(dev); + int rc = qspi_device_init(dev); nrfx_err_t res = NRFX_SUCCESS; - if (ret != 0) { - LOG_DBG("qspi_device_init: %d", ret); + if (rc != 0) { + LOG_DBG("qspi_device_init: %d", rc); qspi_device_uninit(dev); - return ret; + return rc; } qspi_lock(dev); @@ -901,9 +901,9 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, static inline int qspi_nor_read_id(const struct device *dev) { uint8_t id[SPI_NOR_MAX_ID_LEN]; - int ret = qspi_read_jedec_id(dev, id); + int rc = qspi_read_jedec_id(dev, id); - if (ret != 0) { + if (rc != 0) { return -EIO; } @@ -1109,6 +1109,7 @@ static int qspi_nor_write(const struct device *dev, off_t addr, } const struct qspi_nor_config *params = dev->config; + int rc, rc2; /* affected region should be within device */ if (addr < 0 || @@ -1119,18 +1120,18 @@ static int qspi_nor_write(const struct device *dev, off_t addr, return -EINVAL; } - nrfx_err_t res = NRFX_SUCCESS; - - int rc = qspi_device_init(dev); + rc = qspi_device_init(dev); if (rc != 0) { goto out; } qspi_trans_lock(dev); - res = qspi_nor_write_protection_set(dev, false); + rc = qspi_nor_write_protection_set(dev, false); qspi_lock(dev); - if (!res) { + if (rc == 0) { + nrfx_err_t res; + if (size < 4U) { res = write_sub_word(dev, addr, src, size); } else if (!nrfx_is_in_ram(src) || @@ -1140,17 +1141,18 @@ static int qspi_nor_write(const struct device *dev, off_t addr, res = nrfx_qspi_write(src, size, addr); qspi_wait_for_completion(dev, res); } + + rc = qspi_get_zephyr_ret_code(res); } qspi_unlock(dev); - int res2 = qspi_nor_write_protection_set(dev, true); + rc2 = qspi_nor_write_protection_set(dev, true); qspi_trans_unlock(dev); - if (!res) { - res = res2; + if (rc == 0) { + rc = rc2; } - rc = qspi_get_zephyr_ret_code(res); out: qspi_device_uninit(dev); return rc; @@ -1169,24 +1171,24 @@ static int qspi_nor_erase(const struct device *dev, off_t addr, size_t size) return -EINVAL; } - int ret = qspi_erase(dev, addr, size); + int rc = qspi_erase(dev, addr, size); - return ret; + return rc; } static int qspi_nor_write_protection_set(const struct device *dev, bool write_protect) { - int ret = 0; + int rc = 0; struct qspi_cmd cmd = { .op_code = ((write_protect) ? SPI_NOR_CMD_WRDI : SPI_NOR_CMD_WREN), }; if (qspi_send_cmd(dev, &cmd, false) != 0) { - ret = -EIO; + rc = -EIO; } - return ret; + return rc; } /** @@ -1198,16 +1200,16 @@ static int qspi_nor_write_protection_set(const struct device *dev, */ static int qspi_nor_configure(const struct device *dev) { - int ret = qspi_nrfx_configure(dev); + int rc = qspi_nrfx_configure(dev); - if (ret != 0) { - return ret; + if (rc != 0) { + return rc; } #ifdef CONFIG_PM_DEVICE_RUNTIME - ret = pm_device_runtime_enable(dev); - if (ret < 0) { - LOG_ERR("Failed to enable runtime power management: %d", ret); + rc = pm_device_runtime_enable(dev); + if (rc < 0) { + LOG_ERR("Failed to enable runtime power management: %d", rc); } else { LOG_DBG("Runtime power management enabled"); } @@ -1231,12 +1233,12 @@ static int qspi_nor_configure(const struct device *dev) */ static int qspi_nor_init(const struct device *dev) { - int rc; const struct qspi_nor_config *dev_config = dev->config; - int ret = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); + int rc; - if (ret < 0) { - return ret; + rc = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); + if (rc < 0) { + return rc; } IRQ_CONNECT(DT_IRQN(QSPI_NODE), DT_IRQ(QSPI_NODE, priority), @@ -1317,11 +1319,11 @@ static int enter_dpd(const struct device *const dev) .op_code = SPI_NOR_CMD_DPD, }; uint32_t t_enter_dpd = DT_INST_PROP_OR(0, t_enter_dpd, 0); - int ret; + int rc; - ret = qspi_send_cmd(dev, &cmd, false); - if (ret < 0) { - return ret; + rc = qspi_send_cmd(dev, &cmd, false); + if (rc < 0) { + return rc; } if (t_enter_dpd) { @@ -1386,8 +1388,8 @@ static int qspi_nor_pm_action(const struct device *dev, { struct qspi_nor_data *dev_data = dev->data; const struct qspi_nor_config *dev_config = dev->config; - int ret; - nrfx_err_t err; + int rc; + nrfx_err_t res; if (pm_device_is_busy(dev)) { return -EBUSY; @@ -1397,9 +1399,9 @@ static int qspi_nor_pm_action(const struct device *dev, case PM_DEVICE_ACTION_SUSPEND: #ifndef CONFIG_PM_DEVICE_RUNTIME /* If PM_DEVICE_RUNTIME, we don't uninit after RESUME */ - ret = qspi_device_init(dev); - if (ret < 0) { - return ret; + rc = qspi_device_init(dev); + if (rc < 0) { + return rc; } #endif @@ -1411,35 +1413,35 @@ static int qspi_nor_pm_action(const struct device *dev, return -EBUSY; } - ret = enter_dpd(dev); - if (ret < 0) { - return ret; + rc = enter_dpd(dev); + if (rc < 0) { + return rc; } nrfx_qspi_uninit(); - ret = pinctrl_apply_state(dev_config->pcfg, + rc = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP); - if (ret < 0) { - return ret; + if (rc < 0) { + return rc; } break; case PM_DEVICE_ACTION_RESUME: - ret = pinctrl_apply_state(dev_config->pcfg, + rc = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); - if (ret < 0) { - return ret; + if (rc < 0) { + return rc; } - err = nrfx_qspi_init(&dev_config->nrfx_cfg, + res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); - if (err != NRFX_SUCCESS) { + if (res != NRFX_SUCCESS) { return -EIO; } - ret = exit_dpd(dev); - if (ret < 0) { - return ret; + rc = exit_dpd(dev); + if (rc < 0) { + return rc; } #ifndef CONFIG_PM_DEVICE_RUNTIME @@ -1459,16 +1461,16 @@ static int qspi_nor_pm_action(const struct device *dev, void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable) { struct qspi_nor_data *dev_data = dev->data; - int ret; + int rc; if (dev_data->xip_enabled == enable) { return; } - ret = qspi_device_init(dev); + rc = qspi_device_init(dev); - if (ret != 0) { - LOG_ERR("NRF QSPI NOR XIP %s failed with %d\n", enable ? "enable" : "disable", ret); + if (rc != 0) { + LOG_ERR("NRF QSPI NOR XIP %s failed with %d\n", enable ? "enable" : "disable", rc); return; } From 9a0aca0df38a10f19296c26fe6df9bc5b5b52c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Mon, 6 Nov 2023 14:10:19 +0100 Subject: [PATCH 0467/1623] [nrf fromtree] drivers: nrf_qspi_nor: Refactor deactivation and locking access to QSPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After integration of nrfx 3.2.0, it is no longer needed to deinitialize the nrfx_qspi driver to avoid increased power consumption when the QSPI peripheral is idle. Now it is enough to call `nrfx_qspi_dectivate()` when a given operation is done. The driver will automatically activate the QSPI peripheral again when a next operation is requested. This commit applies the following changes: - `qspi_device_init` and `qspi_device_uninit` functions are replaced by `qspi_acquire` and `qspi_release`, respectively; those handle exclusive access to the QSPI peripheral and deactivation of it or runtime device power management - locking is removed from `qspi_send_cmd` as it is the resposibility of the caller of that function - `trans_lock` and `trans_unlock` functions are removed together with the related semaphore as they are no longer needed - checking of input parameters is moved from `qspi_erase` to its caller, `qspi_nor_erase` - `qspi_nor_pm_action` is refactored to properly handle locking of the QSPI peripheral; checking of the `xip_enabled` flag is removed from that function as now the call to `pm_device_is_busy()` covers that (when XIP is enabled, the device is kept indicated as busy) Signed-off-by: Andrzej Głąbek (cherry picked from commit 8c3df0aa9e9a8e7fe864b07ece840610009b3069) --- drivers/flash/nrf_qspi_nor.c | 507 +++++++++++++---------------------- 1 file changed, 193 insertions(+), 314 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index 653f8b38f4e..ae990a5d68e 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -26,15 +26,15 @@ LOG_MODULE_REGISTER(qspi_nor, CONFIG_FLASH_LOG_LEVEL); #include struct qspi_nor_data { +#if !defined(CONFIG_PM_DEVICE_RUNTIME) && defined(CONFIG_MULTITHREADING) + /* A semaphore to control QSPI deactivation. */ + struct k_sem count; +#endif #ifdef CONFIG_MULTITHREADING - /* The semaphore to control exclusive access on write/erase. */ - struct k_sem trans; /* The semaphore to control exclusive access to the device. */ struct k_sem sem; /* The semaphore to indicate that transfer has completed. */ struct k_sem sync; - /* The semaphore to control driver init/uninit. */ - struct k_sem count; #else /* CONFIG_MULTITHREADING */ /* A flag that signals completed transfer when threads are * not enabled. @@ -173,12 +173,6 @@ BUILD_ASSERT(DT_INST_PROP(0, address_size_32), "After entering 4 byte addressing mode, 4 byte addressing is expected"); #endif -#ifndef CONFIG_PM_DEVICE_RUNTIME -static bool qspi_initialized; -#endif - -static int qspi_device_init(const struct device *dev); -static void qspi_device_uninit(const struct device *dev); void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable); void z_vrfy_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable); @@ -245,72 +239,99 @@ static inline int qspi_get_zephyr_ret_code(nrfx_err_t res) static inline void qspi_lock(const struct device *dev) { +#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; - pm_device_busy_set(dev); - -#ifdef CONFIG_MULTITHREADING k_sem_take(&dev_data->sem, K_FOREVER); -#else /* CONFIG_MULTITHREADING */ - ARG_UNUSED(dev_data); -#endif /* CONFIG_MULTITHREADING */ - - /* - * Change the base clock divider only for the time the driver is locked - * to perform a QSPI operation, otherwise the power consumption would be - * increased also when the QSPI peripheral is idle. - * When XIP is enabled, there is nothing to do here as the changed - * divider is kept all the time. - */ -#if defined(CONFIG_SOC_SERIES_NRF53X) - if (!dev_data->xip_enabled) { - nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); - } #endif } static inline void qspi_unlock(const struct device *dev) { +#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; -#if defined(CONFIG_SOC_SERIES_NRF53X) - /* Restore the default base clock divider to reduce power consumption. - * Unless XIP is enabled, then the changed divider needs to be kept. - */ - if (!dev_data->xip_enabled) { - nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); - } + k_sem_give(&dev_data->sem); #endif +} -#ifdef CONFIG_MULTITHREADING - k_sem_give(&dev_data->sem); -#else - ARG_UNUSED(dev_data); +static inline void qspi_clock_div_change(void) +{ +#ifdef CONFIG_SOC_SERIES_NRF53X + /* Make sure the base clock divider is changed accordingly + * before a QSPI transfer is performed. + */ + nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); #endif +} - pm_device_busy_clear(dev); +static inline void qspi_clock_div_restore(void) +{ +#ifdef CONFIG_SOC_SERIES_NRF53X + /* Restore the default base clock divider to reduce power + * consumption when the QSPI peripheral is idle. + */ + nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); +#endif } -static inline void qspi_trans_lock(const struct device *dev) +static void qspi_acquire(const struct device *dev) { -#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; - k_sem_take(&dev_data->trans, K_FOREVER); -#else /* CONFIG_MULTITHREADING */ - ARG_UNUSED(dev); -#endif /* CONFIG_MULTITHREADING */ +#if defined(CONFIG_PM_DEVICE_RUNTIME) + int rc = pm_device_runtime_get(dev); + + if (rc < 0) { + LOG_ERR("pm_device_runtime_get failed: %d", rc); + } +#elif defined(CONFIG_MULTITHREADING) + /* In multithreading, the driver can call qspi_acquire more than once + * before calling qspi_release. Keeping count, so QSPI is deactivated + * only at the last call (count == 0). + */ + k_sem_give(&dev_data->count); +#endif + + qspi_lock(dev); + + if (!dev_data->xip_enabled) { + qspi_clock_div_change(); + + pm_device_busy_set(dev); + } } -static inline void qspi_trans_unlock(const struct device *dev) +static void qspi_release(const struct device *dev) { -#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; + bool deactivate = true; - k_sem_give(&dev_data->trans); -#else /* CONFIG_MULTITHREADING */ - ARG_UNUSED(dev); -#endif /* CONFIG_MULTITHREADING */ +#if !defined(CONFIG_PM_DEVICE_RUNTIME) && defined(CONFIG_MULTITHREADING) + /* The last thread to finish using the driver deactivates the QSPI */ + (void) k_sem_take(&dev_data->count, K_NO_WAIT); + deactivate = (k_sem_count_get(&dev_data->count) == 0); +#endif + + if (!dev_data->xip_enabled) { + qspi_clock_div_restore(); + + if (deactivate && !IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + (void) nrfx_qspi_deactivate(); + } + + pm_device_busy_clear(dev); + } + + qspi_unlock(dev); + +#if defined(CONFIG_PM_DEVICE_RUNTIME) + int rc = pm_device_runtime_put(dev); + + if (rc < 0) { + LOG_ERR("pm_device_runtime_put failed: %d", rc); + } +#endif } static inline void qspi_wait_for_completion(const struct device *dev, @@ -359,89 +380,6 @@ static void qspi_handler(nrfx_qspi_evt_t event, void *p_context) } } -static int qspi_device_init(const struct device *dev) -{ - struct qspi_nor_data *dev_data = dev->data; - - if (dev_data->xip_enabled) { - return 0; - } - -#ifdef CONFIG_PM_DEVICE_RUNTIME - return pm_device_runtime_get(dev); -#else - nrfx_err_t res; - int rc = 0; - - qspi_lock(dev); - - /* In multithreading, driver can call qspi_device_init more than once - * before calling qspi_device_uninit. Keepping count, so QSPI is - * uninitialized only at the last call (count == 0). - */ -#ifdef CONFIG_MULTITHREADING - k_sem_give(&dev_data->count); -#endif - - if (!qspi_initialized) { - const struct qspi_nor_config *dev_config = dev->config; - - res = nrfx_qspi_init(&dev_config->nrfx_cfg, - qspi_handler, - dev_data); - rc = qspi_get_zephyr_ret_code(res); - qspi_initialized = (rc == 0); - } - - qspi_unlock(dev); - - return rc; -#endif -} - -static void qspi_device_uninit(const struct device *dev) -{ - struct qspi_nor_data *dev_data = dev->data; - - if (dev_data->xip_enabled) { - return; - } - -#ifdef CONFIG_PM_DEVICE_RUNTIME - int rc = pm_device_runtime_put(dev); - - if (rc < 0) { - LOG_ERR("Failed to schedule device sleep: %d", rc); - } -#else - bool last = true; - - qspi_lock(dev); - -#ifdef CONFIG_MULTITHREADING - /* The last thread to finish using the driver uninit the QSPI */ - (void) k_sem_take(&dev_data->count, K_NO_WAIT); - last = (k_sem_count_get(&dev_data->count) == 0); -#endif - - if (last) { - while (nrfx_qspi_mem_busy_check() != NRFX_SUCCESS) { - if (IS_ENABLED(CONFIG_MULTITHREADING)) { - k_msleep(50); - } else { - k_busy_wait(50000); - } - } - - nrfx_qspi_uninit(); - - qspi_initialized = false; - } - - qspi_unlock(dev); -#endif -} - /* QSPI send custom command. * * If this is used for both send and receive the buffer sizes must be @@ -497,11 +435,8 @@ static int qspi_send_cmd(const struct device *dev, const struct qspi_cmd *cmd, .wren = wren, }; - qspi_lock(dev); - int res = nrfx_qspi_cinstr_xfer(&cinstr_cfg, tx_buf, rx_buf); - qspi_unlock(dev); return qspi_get_zephyr_ret_code(res); } @@ -617,29 +552,13 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) /* QSPI erase */ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) { - /* address must be sector-aligned */ - if ((addr % QSPI_SECTOR_SIZE) != 0) { - return -EINVAL; - } - - /* size must be a non-zero multiple of sectors */ - if ((size == 0) || (size % QSPI_SECTOR_SIZE) != 0) { - return -EINVAL; - } - const struct qspi_nor_config *params = dev->config; int rc, rc2; - rc = qspi_device_init(dev); - if (rc != 0) { - goto out; - } - qspi_trans_lock(dev); rc = qspi_nor_write_protection_set(dev, false); if (rc != 0) { - goto out_trans_unlock; + return rc; } - qspi_lock(dev); while (size > 0) { nrfx_err_t res = !NRFX_SUCCESS; uint32_t adj = 0; @@ -674,20 +593,10 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) break; } } - qspi_unlock(dev); rc2 = qspi_nor_write_protection_set(dev, true); - if (!rc) { - rc = rc2; - } - -out_trans_unlock: - qspi_trans_unlock(dev); - -out: - qspi_device_uninit(dev); - return rc; + return rc != 0 ? rc : rc2; } /* Configures QSPI memory for the transfer */ @@ -698,22 +607,7 @@ static int qspi_nrfx_configure(const struct device *dev) nrfx_err_t res; int rc; -#if defined(CONFIG_SOC_SERIES_NRF53X) - /* When the QSPI peripheral is activated, during the nrfx_qspi driver - * initialization, it reads the status of the connected flash chip. - * Make sure this transaction is performed with a valid base clock - * divider. - */ - nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); -#endif - res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); - -#if defined(CONFIG_SOC_SERIES_NRF53X) - /* Restore the default /4 divider after the QSPI initialization. */ - nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); -#endif - rc = qspi_get_zephyr_ret_code(res); if (rc < 0) { return rc; @@ -814,8 +708,7 @@ static int qspi_nrfx_configure(const struct device *dev) return rc; } -static int qspi_read_jedec_id(const struct device *dev, - uint8_t *id) +static int qspi_rdid(const struct device *dev, uint8_t *id) { const struct qspi_buf rx_buf = { .buf = id, @@ -826,18 +719,24 @@ static int qspi_read_jedec_id(const struct device *dev, .rx_buf = &rx_buf, }; - int rc = qspi_device_init(dev); + return qspi_send_cmd(dev, &cmd, false); +} - if (rc == 0) { - rc = qspi_send_cmd(dev, &cmd, false); - } - qspi_device_uninit(dev); +#if defined(CONFIG_FLASH_JESD216_API) + +static int qspi_read_jedec_id(const struct device *dev, uint8_t *id) +{ + int rc; + + qspi_acquire(dev); + + rc = qspi_rdid(dev, id); + + qspi_release(dev); return rc; } -#if defined(CONFIG_FLASH_JESD216_API) - static int qspi_sfdp_read(const struct device *dev, off_t offset, void *data, size_t len) { @@ -855,17 +754,10 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, .io2_level = true, .io3_level = true, }; + nrfx_err_t res; - int rc = qspi_device_init(dev); - nrfx_err_t res = NRFX_SUCCESS; - - if (rc != 0) { - LOG_DBG("qspi_device_init: %d", rc); - qspi_device_uninit(dev); - return rc; - } + qspi_acquire(dev); - qspi_lock(dev); res = nrfx_qspi_lfm_start(&cinstr_cfg); if (res != NRFX_SUCCESS) { LOG_DBG("lfm_start: %x", res); @@ -885,8 +777,8 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, } out: - qspi_unlock(dev); - qspi_device_uninit(dev); + qspi_release(dev); + return qspi_get_zephyr_ret_code(res); } @@ -901,7 +793,7 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, static inline int qspi_nor_read_id(const struct device *dev) { uint8_t id[SPI_NOR_MAX_ID_LEN]; - int rc = qspi_read_jedec_id(dev, id); + int rc = qspi_rdid(dev, id); if (rc != 0) { return -EIO; @@ -993,6 +885,9 @@ static inline nrfx_err_t read_non_aligned(const struct device *dev, static int qspi_nor_read(const struct device *dev, off_t addr, void *dest, size_t size) { + const struct qspi_nor_config *params = dev->config; + nrfx_err_t res; + if (!dest) { return -EINVAL; } @@ -1002,8 +897,6 @@ static int qspi_nor_read(const struct device *dev, off_t addr, void *dest, return 0; } - const struct qspi_nor_config *params = dev->config; - /* affected region should be within device */ if (addr < 0 || (addr + size) > params->size) { @@ -1013,23 +906,13 @@ static int qspi_nor_read(const struct device *dev, off_t addr, void *dest, return -EINVAL; } - int rc = qspi_device_init(dev); - - if (rc != 0) { - goto out; - } - - qspi_lock(dev); - - nrfx_err_t res = read_non_aligned(dev, addr, dest, size); + qspi_acquire(dev); - qspi_unlock(dev); + res = read_non_aligned(dev, addr, dest, size); - rc = qspi_get_zephyr_ret_code(res); + qspi_release(dev); -out: - qspi_device_uninit(dev); - return rc; + return qspi_get_zephyr_ret_code(res); } /* addr aligned, sptr not null, slen less than 4 */ @@ -1094,6 +977,9 @@ static int qspi_nor_write(const struct device *dev, off_t addr, const void *src, size_t size) { + const struct qspi_nor_config *params = dev->config; + int rc, rc2; + if (!src) { return -EINVAL; } @@ -1108,9 +994,6 @@ static int qspi_nor_write(const struct device *dev, off_t addr, return -EINVAL; } - const struct qspi_nor_config *params = dev->config; - int rc, rc2; - /* affected region should be within device */ if (addr < 0 || (addr + size) > params->size) { @@ -1120,15 +1003,9 @@ static int qspi_nor_write(const struct device *dev, off_t addr, return -EINVAL; } + qspi_acquire(dev); - rc = qspi_device_init(dev); - if (rc != 0) { - goto out; - } - - qspi_trans_lock(dev); rc = qspi_nor_write_protection_set(dev, false); - qspi_lock(dev); if (rc == 0) { nrfx_err_t res; @@ -1144,23 +1021,28 @@ static int qspi_nor_write(const struct device *dev, off_t addr, rc = qspi_get_zephyr_ret_code(res); } - qspi_unlock(dev); rc2 = qspi_nor_write_protection_set(dev, true); - qspi_trans_unlock(dev); - if (rc == 0) { - rc = rc2; - } + qspi_release(dev); -out: - qspi_device_uninit(dev); - return rc; + return rc != 0 ? rc : rc2; } static int qspi_nor_erase(const struct device *dev, off_t addr, size_t size) { const struct qspi_nor_config *params = dev->config; + int rc; + + /* address must be sector-aligned */ + if ((addr % QSPI_SECTOR_SIZE) != 0) { + return -EINVAL; + } + + /* size must be a non-zero multiple of sectors */ + if ((size == 0) || (size % QSPI_SECTOR_SIZE) != 0) { + return -EINVAL; + } /* affected region should be within device */ if (addr < 0 || @@ -1171,7 +1053,11 @@ static int qspi_nor_erase(const struct device *dev, off_t addr, size_t size) return -EINVAL; } - int rc = qspi_erase(dev, addr, size); + qspi_acquire(dev); + + rc = qspi_erase(dev, addr, size); + + qspi_release(dev); return rc; } @@ -1206,17 +1092,6 @@ static int qspi_nor_configure(const struct device *dev) return rc; } -#ifdef CONFIG_PM_DEVICE_RUNTIME - rc = pm_device_runtime_enable(dev); - if (rc < 0) { - LOG_ERR("Failed to enable runtime power management: %d", rc); - } else { - LOG_DBG("Runtime power management enabled"); - } -#else - qspi_device_uninit(dev); -#endif - /* now the spi bus is configured, we can verify the flash id */ if (qspi_nor_read_id(dev) != 0) { return -ENODEV; @@ -1244,10 +1119,24 @@ static int qspi_nor_init(const struct device *dev) IRQ_CONNECT(DT_IRQN(QSPI_NODE), DT_IRQ(QSPI_NODE, priority), nrfx_isr, nrfx_qspi_irq_handler, 0); + qspi_clock_div_change(); + rc = qspi_nor_configure(dev); + qspi_clock_div_restore(); + +#ifdef CONFIG_PM_DEVICE_RUNTIME + int rc2 = pm_device_runtime_enable(dev); + + if (rc2 < 0) { + LOG_ERR("Failed to enable runtime power management: %d", rc2); + } else { + LOG_DBG("Runtime power management enabled"); + } +#endif + #ifdef CONFIG_NORDIC_QSPI_NOR_XIP - if (!rc) { + if (rc == 0) { /* Enable XIP mode for QSPI NOR flash, this will prevent the * flash from being powered down */ @@ -1383,108 +1272,97 @@ static int exit_dpd(const struct device *const dev) } #ifdef CONFIG_PM_DEVICE -static int qspi_nor_pm_action(const struct device *dev, - enum pm_device_action action) +static int qspi_suspend(const struct device *dev) { - struct qspi_nor_data *dev_data = dev->data; const struct qspi_nor_config *dev_config = dev->config; - int rc; nrfx_err_t res; + int rc; - if (pm_device_is_busy(dev)) { + res = nrfx_qspi_mem_busy_check(); + if (res != NRFX_SUCCESS) { return -EBUSY; } - switch (action) { - case PM_DEVICE_ACTION_SUSPEND: -#ifndef CONFIG_PM_DEVICE_RUNTIME - /* If PM_DEVICE_RUNTIME, we don't uninit after RESUME */ - rc = qspi_device_init(dev); - if (rc < 0) { - return rc; - } -#endif + rc = enter_dpd(dev); + if (rc < 0) { + return rc; + } - if (dev_data->xip_enabled) { - return -EBUSY; - } + nrfx_qspi_uninit(); - if (nrfx_qspi_mem_busy_check() != NRFX_SUCCESS) { - return -EBUSY; - } + return pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP); +} - rc = enter_dpd(dev); - if (rc < 0) { - return rc; - } +static int qspi_resume(const struct device *dev) +{ + const struct qspi_nor_config *dev_config = dev->config; + nrfx_err_t res; + int rc; - nrfx_qspi_uninit(); - rc = pinctrl_apply_state(dev_config->pcfg, - PINCTRL_STATE_SLEEP); - if (rc < 0) { - return rc; - } - break; + rc = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); + if (rc < 0) { + return rc; + } - case PM_DEVICE_ACTION_RESUME: - rc = pinctrl_apply_state(dev_config->pcfg, - PINCTRL_STATE_DEFAULT); - if (rc < 0) { - return rc; - } - res = nrfx_qspi_init(&dev_config->nrfx_cfg, - qspi_handler, - dev_data); - if (res != NRFX_SUCCESS) { - return -EIO; - } + res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev->data); + if (res != NRFX_SUCCESS) { + return -EIO; + } - rc = exit_dpd(dev); - if (rc < 0) { - return rc; - } + return exit_dpd(dev); +} -#ifndef CONFIG_PM_DEVICE_RUNTIME - /* If PM_DEVICE_RUNTIME, we're immediately going to use the device */ - qspi_device_uninit(dev); -#endif +static int qspi_nor_pm_action(const struct device *dev, + enum pm_device_action action) +{ + int rc; + + if (pm_device_is_busy(dev)) { + return -EBUSY; + } + + qspi_lock(dev); + qspi_clock_div_change(); + + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + rc = qspi_suspend(dev); + break; + + case PM_DEVICE_ACTION_RESUME: + rc = qspi_resume(dev); break; default: - return -ENOTSUP; + rc = -ENOTSUP; } - return 0; + qspi_clock_div_restore(); + qspi_unlock(dev); + + return rc; } #endif /* CONFIG_PM_DEVICE */ void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable) { struct qspi_nor_data *dev_data = dev->data; - int rc; if (dev_data->xip_enabled == enable) { return; } - rc = qspi_device_init(dev); - - if (rc != 0) { - LOG_ERR("NRF QSPI NOR XIP %s failed with %d\n", enable ? "enable" : "disable", rc); - return; - } + qspi_acquire(dev); #if NRF_QSPI_HAS_XIPEN nrf_qspi_xip_set(NRF_QSPI, enable); #endif - qspi_lock(dev); if (enable) { (void)nrfx_qspi_activate(false); } dev_data->xip_enabled = enable; - qspi_unlock(dev); - qspi_device_uninit(dev); + qspi_release(dev); } #ifdef CONFIG_USERSPACE @@ -1502,11 +1380,12 @@ void z_vrfy_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable) #endif /* CONFIG_USERSPACE */ static struct qspi_nor_data qspi_nor_dev_data = { +#if !defined(CONFIG_PM_DEVICE_RUNTIME) && defined(CONFIG_MULTITHREADING) + .count = Z_SEM_INITIALIZER(qspi_nor_dev_data.count, 0, K_SEM_MAX_LIMIT), +#endif #ifdef CONFIG_MULTITHREADING - .trans = Z_SEM_INITIALIZER(qspi_nor_dev_data.trans, 1, 1), .sem = Z_SEM_INITIALIZER(qspi_nor_dev_data.sem, 1, 1), .sync = Z_SEM_INITIALIZER(qspi_nor_dev_data.sync, 0, 1), - .count = Z_SEM_INITIALIZER(qspi_nor_dev_data.count, 0, K_SEM_MAX_LIMIT), #endif /* CONFIG_MULTITHREADING */ }; From 86146714949810fd451dace302bd42ea4ecb3927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Fri, 10 Nov 2023 16:52:12 +0100 Subject: [PATCH 0468/1623] [nrf fromtree] drivers: nrf_qspi_nor: Fix and refactor driver initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So far the driver first changed the configuration of the flash chip and after that checked the signature of that chip. This could lead to improper change of the chip configuration if the actually found one was different than that specified in devicetree. This commit reverses the order of these two initialization steps and also restructures a bit the initialization code. Signed-off-by: Andrzej Głąbek (cherry picked from commit ea1be7f242b9348863a27adb17215014f15b318a) --- drivers/flash/nrf_qspi_nor.c | 125 +++++++++++++---------------------- 1 file changed, 45 insertions(+), 80 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index ae990a5d68e..ac055229710 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -599,41 +599,10 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) return rc != 0 ? rc : rc2; } -/* Configures QSPI memory for the transfer */ -static int qspi_nrfx_configure(const struct device *dev) +static int configure_chip(const struct device *dev) { - struct qspi_nor_data *dev_data = dev->data; const struct qspi_nor_config *dev_config = dev->config; - nrfx_err_t res; - int rc; - - res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); - rc = qspi_get_zephyr_ret_code(res); - if (rc < 0) { - return rc; - } - -#if DT_INST_NODE_HAS_PROP(0, rx_delay) - if (!nrf53_errata_121()) { - nrf_qspi_iftiming_set(NRF_QSPI, DT_INST_PROP(0, rx_delay)); - } -#endif - - /* It may happen that after the flash chip was previously put into - * the DPD mode, the system was reset but the flash chip was not. - * Consequently, the flash chip can be in the DPD mode at this point. - * Some flash chips will just exit the DPD mode on the first CS pulse, - * but some need to receive the dedicated command to do it, so send it. - * This can be the case even if the current image does not have - * CONFIG_PM_DEVICE set to enter DPD mode, as a previously executing image - * (for example the main image if the currently executing image is the - * bootloader) might have set DPD mode before reboot. As a result, - * attempt to exit DPD mode regardless of whether CONFIG_PM_DEVICE is set. - */ - rc = exit_dpd(dev); - if (rc < 0) { - return rc; - } + int rc = 0; /* Set QE to match transfer mode. If not using quad * it's OK to leave QE set, but doing so prevents use @@ -784,33 +753,6 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, #endif /* CONFIG_FLASH_JESD216_API */ -/** - * @brief Retrieve the Flash JEDEC ID and compare it with the one expected - * - * @param dev The device structure - * @return 0 on success, negative errno code otherwise - */ -static inline int qspi_nor_read_id(const struct device *dev) -{ - uint8_t id[SPI_NOR_MAX_ID_LEN]; - int rc = qspi_rdid(dev, id); - - if (rc != 0) { - return -EIO; - } - - const struct qspi_nor_config *qnc = dev->config; - - if (memcmp(qnc->id, id, SPI_NOR_MAX_ID_LEN) != 0) { - LOG_ERR("JEDEC id [%02x %02x %02x] expect [%02x %02x %02x]", - id[0], id[1], id[2], - qnc->id[0], qnc->id[1], qnc->id[2]); - return -ENODEV; - } - - return 0; -} - static inline nrfx_err_t read_non_aligned(const struct device *dev, off_t addr, void *dest, size_t size) @@ -1077,35 +1019,58 @@ static int qspi_nor_write_protection_set(const struct device *dev, return rc; } -/** - * @brief Configure the flash - * - * @param dev The flash device structure - * @param info The flash info structure - * @return 0 on success, negative errno code otherwise - */ -static int qspi_nor_configure(const struct device *dev) +static int qspi_init(const struct device *dev) { - int rc = qspi_nrfx_configure(dev); + const struct qspi_nor_config *dev_config = dev->config; + uint8_t id[SPI_NOR_MAX_ID_LEN]; + nrfx_err_t res; + int rc; - if (rc != 0) { + res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev->data); + rc = qspi_get_zephyr_ret_code(res); + if (rc < 0) { + return rc; + } + +#if DT_INST_NODE_HAS_PROP(0, rx_delay) + if (!nrf53_errata_121()) { + nrf_qspi_iftiming_set(NRF_QSPI, DT_INST_PROP(0, rx_delay)); + } +#endif + + /* It may happen that after the flash chip was previously put into + * the DPD mode, the system was reset but the flash chip was not. + * Consequently, the flash chip can be in the DPD mode at this point. + * Some flash chips will just exit the DPD mode on the first CS pulse, + * but some need to receive the dedicated command to do it, so send it. + * This can be the case even if the current image does not have + * CONFIG_PM_DEVICE set to enter DPD mode, as a previously executing image + * (for example the main image if the currently executing image is the + * bootloader) might have set DPD mode before reboot. As a result, + * attempt to exit DPD mode regardless of whether CONFIG_PM_DEVICE is set. + */ + rc = exit_dpd(dev); + if (rc < 0) { + return rc; + } + + /* Retrieve the Flash JEDEC ID and compare it with the one expected. */ + rc = qspi_rdid(dev, id); + if (rc < 0) { return rc; } - /* now the spi bus is configured, we can verify the flash id */ - if (qspi_nor_read_id(dev) != 0) { + if (memcmp(dev_config->id, id, SPI_NOR_MAX_ID_LEN) != 0) { + LOG_ERR("JEDEC id [%02x %02x %02x] expect [%02x %02x %02x]", + id[0], id[1], id[2], dev_config->id[0], + dev_config->id[1], dev_config->id[2]); return -ENODEV; } - return 0; + /* The chip is correct, it can be configured now. */ + return configure_chip(dev); } -/** - * @brief Initialize and configure the flash - * - * @param name The flash name - * @return 0 on success, negative errno code otherwise - */ static int qspi_nor_init(const struct device *dev) { const struct qspi_nor_config *dev_config = dev->config; @@ -1121,7 +1086,7 @@ static int qspi_nor_init(const struct device *dev) qspi_clock_div_change(); - rc = qspi_nor_configure(dev); + rc = qspi_init(dev); qspi_clock_div_restore(); From 85a25485d25f7da05e0d6c707b326a487b3a9e6b Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 14 Dec 2023 21:13:44 +0530 Subject: [PATCH 0469/1623] [nrf fromtree] wifi: shell: Fix AP argument checks and help AP enable takes the same parameters as connect, so, update the help and also fix the optional parameter count when security is involved. Signed-off-by: Chaitanya Tata (cherry picked from commit 9736cc7f29668542a85b5c775b368a6a30c7f8c0) --- subsys/net/l2/wifi/wifi_shell.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 90dbd1588f7..658dadce6fd 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1598,9 +1598,16 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, "Disable Access Point mode", cmd_wifi_ap_disable, 1, 0), - SHELL_CMD_ARG(enable, NULL, " [channel] [PSK]", + SHELL_CMD_ARG(enable, NULL, + "\"\"\n" + "[channel number: 0 means all]\n" + "[PSK: valid only for secure SSIDs]\n" + "[Security type: valid only for secure SSIDs]\n" + "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" + "[MFP (optional: needs security type to be specified)]\n" + ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_ap_enable, - 2, 1), + 2, 4), SHELL_SUBCMD_SET_END ); From b65e77cdb79c3deb22395874d3079f850a6dffd0 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 14 Dec 2023 21:17:07 +0530 Subject: [PATCH 0470/1623] [nrf fromtree] wifi: shell: Display RSSI only for station mode RSSI makes sense only for modes that have a single peer, so, add a station mode check. Signed-off-by: Chaitanya Tata (cherry picked from commit eaba47445a4e9cd1bee7d6adb9b9c62f159f3088) --- subsys/net/l2/wifi/wifi_shell.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 658dadce6fd..e1f225bd4e8 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -656,7 +656,9 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[]) wifi_security_txt(status.security)); shell_fprintf(sh, SHELL_NORMAL, "MFP: %s\n", wifi_mfp_txt(status.mfp)); - shell_fprintf(sh, SHELL_NORMAL, "RSSI: %d\n", status.rssi); + if (status.iface_mode == WIFI_MODE_INFRA) { + shell_fprintf(sh, SHELL_NORMAL, "RSSI: %d\n", status.rssi); + } shell_fprintf(sh, SHELL_NORMAL, "Beacon Interval: %d\n", status.beacon_interval); shell_fprintf(sh, SHELL_NORMAL, "DTIM: %d\n", status.dtim_period); shell_fprintf(sh, SHELL_NORMAL, "TWT: %s\n", From 426213023e08965311421143ca3abe2ec25b39a4 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 18 Dec 2023 17:42:43 +0530 Subject: [PATCH 0471/1623] [nrf fromlist] wifi: shell: Fix arg count for regulatory domain Regulatory domain supports both get and set, so, fix the argument counts. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66616 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index e1f225bd4e8..6893e20353e 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1684,7 +1684,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain, - 2, 1), + 1, 1), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" From 52ce713e771e3c8c9a64c47d52b25825c5c627d8 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sat, 16 Sep 2023 15:41:39 +1000 Subject: [PATCH 0472/1623] [nrf fromtree] net: wifi_mgmt: change type of `wifi_scan_params->chan` All WiFi channel numbers fit within a 8 bit number, as the maximum allocated channel is 233. This halves the memory requirement. Signed-off-by: Jordan Yates (cherry picked from commit dd090f06b7ed45bdc88335082a10bbe0db2ce439) --- include/zephyr/net/wifi_mgmt.h | 2 +- include/zephyr/net/wifi_utils.h | 2 +- subsys/net/l2/wifi/wifi_utils.c | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 1be98b927cb..67a603aea95 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -252,7 +252,7 @@ struct wifi_scan_params { * not conforming to regulatory restrictions etc. The invoker of the API should * ensure that the channels specified follow regulatory rules. */ - uint16_t chan[WIFI_FREQ_BAND_MAX + 1][WIFI_CHANNEL_MAX]; + uint8_t chan[WIFI_FREQ_BAND_MAX + 1][WIFI_CHANNEL_MAX]; }; /** Wi-Fi scan result, each result is provided to the net_mgmt_event_callback diff --git a/include/zephyr/net/wifi_utils.h b/include/zephyr/net/wifi_utils.h index 86b39ff4660..b005d075847 100644 --- a/include/zephyr/net/wifi_utils.h +++ b/include/zephyr/net/wifi_utils.h @@ -100,7 +100,7 @@ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, * @retval -errno value in case of failure. */ int wifi_utils_parse_scan_chan(char *scan_chan_str, - uint16_t chan[][WIFI_CHANNEL_MAX]); + uint8_t chan[][WIFI_CHANNEL_MAX]); /** * @} diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index ea0e42def47..a77e225bfbf 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -103,13 +103,13 @@ static bool wifi_utils_validate_chan(uint8_t band, } -static int wifi_utils_get_all_chans_in_range(uint16_t chan_start, - uint16_t chan_end, - uint16_t chan[][WIFI_CHANNEL_MAX], +static int wifi_utils_get_all_chans_in_range(uint8_t chan_start, + uint8_t chan_end, + uint8_t chan[][WIFI_CHANNEL_MAX], uint8_t band_idx, uint8_t *chan_idx) { - uint16_t i; + uint8_t i; bool start = false; bool end = false; uint8_t idx; @@ -310,7 +310,7 @@ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, int wifi_utils_parse_scan_chan(char *scan_chan_str, - uint16_t chan[][WIFI_CHANNEL_MAX]) + uint8_t chan[][WIFI_CHANNEL_MAX]) { char band_str[WIFI_UTILS_MAX_BAND_STR_LEN] = {0}; char chan_str[WIFI_UTILS_MAX_CHAN_STR_LEN] = {0}; @@ -318,8 +318,8 @@ int wifi_utils_parse_scan_chan(char *scan_chan_str, uint16_t band_str_start_idx = 0; uint16_t chan_str_start_idx = 0; uint8_t chan_idx = 0; - uint16_t chan_start = 0; - uint16_t chan_val = 0; + uint8_t chan_start = 0; + uint8_t chan_val = 0; uint16_t i = 0; bool valid_band = false; bool valid_chan = false; From f76c35a823c2b4909f2306c074267a57f9fff864 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sun, 17 Sep 2023 21:16:00 +1000 Subject: [PATCH 0473/1623] [nrf fromtree] net: l2: wifi_mgmt: remove scan kconfig defaults Remove the wifi_mgmt interface overriding default values with values from kconfig. The defaults were only applied when a `params` struct was provided by the application. This is the case when the application is explicitly setting the options it wants, why is the mgmt API changing these. When `params` is NULL and thus modem defaults are requested, these defaults aren't applied. This is the opposite behaviour from what seems reasonable. In addition, these options are: * Undocumented * Using non-trivial string parsing functions (strtok) * Adding complexity to the API implementation by forcing support for ROM versions of command line arguments. Signed-off-by: Jordan Yates (cherry picked from commit 5452665beb98acba74dbf8ecf07e1deb97b2a7e0) --- subsys/net/l2/wifi/Kconfig | 67 ---------------------------------- subsys/net/l2/wifi/wifi_mgmt.c | 55 ---------------------------- 2 files changed, 122 deletions(-) diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 6623456d84b..ccf5ce31ca6 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -39,40 +39,6 @@ config WIFI_MGMT_TWT_CHECK_IP even when it is awake intervals. Rejecting TWT setup till Wi-Fi interface has a valid IP address might be desirable in most scenarios. -config WIFI_MGMT_FORCED_PASSIVE_SCAN - bool "Force Passive scan" - help - Force passive scan (typically used to reduce power consumption), - the scan type is always sent as passive. - This doesn't guarantee that passive scan will be used, it depends - on the underlying chip implementation to support and honour scan type. - -config WIFI_MGMT_SCAN_BANDS - string "Frequency bands to scan" - default "" - help - Specifies the frequency bands to scan, as follows: - 2 - 2.4 GHz - 5 - 5 GHz - 6 - 6 GHz - "" - All bands allowed by the regulatory domain. - Multiple bands can be specified as comma separated band values. - Only regulatory domain permitted values are allowed. - -config WIFI_MGMT_SCAN_DWELL_TIME_ACTIVE - int "Active scan dwell time" - default 50 - range 5 1000 - help - Active scan dwell time (in ms) per channel. - -config WIFI_MGMT_SCAN_DWELL_TIME_PASSIVE - int "Passive scan dwell time" - default 130 - range 10 1000 - help - Passive scan dwell time (in ms) per channel. - config WIFI_MGMT_SCAN_SSID_FILT_MAX int "Maximum number of SSIDs that can be specified for SSID filtering" default 1 @@ -81,39 +47,6 @@ config WIFI_MGMT_SCAN_SSID_FILT_MAX Maximum number of SSIDs that can be specified for SSID filtering. This can be set based on the underlying chipsets limitations. -config WIFI_MGMT_SCAN_SSID_FILT - string "Scan for specific SSIDs" - default "" - help - String of comma separated SSID values to scan for. The number of SSID’s - that can be specified depends on WIFI_MGMT_SCAN_MAX_SSIDS. - Use "" to disable SSID filtering. - -config WIFI_MGMT_SCAN_MAX_BSS_CNT - int "Maximum number of scan results to return." - default 0 - range 0 65535 - help - Maximum number of scan results to return. 0 represents unlimited number of BSSes. - -config WIFI_MGMT_SCAN_CHAN - string "Scan on specific channels" - default "" - help - Formatted string which specifies channels to be scanned. The channel string has to be formatted - using the colon (:), comma(,), hyphen (-) and space ( ) delimiters as follows: - - A colon identifies the value preceding it as a band. A band value - (2: 2.4 GHz, 5: 5 GHz 6: 6 GHz) has to precede the channels in that band (e.g. 2: etc) - - Hyphens are used to identify channel ranges (e.g. 2-7, 32-48 etc) - - Commas are used to separate channel values within a band. Channels can be specified - as individual values (2,6,48 etc) or channel ranges using hyphens (1-14, 32-48 etc) - - Spaces are used to specify multiple band-channel sets (e.g. 2:1,2 5:36,40 etc) - - No spaces should be used anywhere else, i.e. before/after commas, - before/after hyphens. - An example channel specification specifying channels in the 2.4 GHz and 5 GHz bands is - as below: - 2:1,5,7,9-11_5:36-48,100,163-167 - config WIFI_NM bool "Wi-Fi Network manager support" help diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 0751f5d2b8c..58e14ff02ff 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -13,7 +13,6 @@ LOG_MODULE_REGISTER(net_wifi_mgmt, CONFIG_NET_L2_WIFI_MGMT_LOG_LEVEL); #include #include #include -#include #ifdef CONFIG_WIFI_NM #include #endif /* CONFIG_WIFI_NM */ @@ -323,65 +322,11 @@ static int wifi_scan(uint32_t mgmt_request, struct net_if *iface, const struct device *dev = net_if_get_device(iface); struct wifi_scan_params *params = data; const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); - bool chan_specified = false; - uint8_t i = 0; if (wifi_mgmt_api == NULL || wifi_mgmt_api->scan == NULL) { return -ENOTSUP; } - if (data && (len == sizeof(*params))) { -#ifdef CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN - params->scan_type = WIFI_SCAN_TYPE_PASSIVE; -#endif /* CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN */ - - if (!params->bands) { - if (wifi_utils_parse_scan_bands(CONFIG_WIFI_MGMT_SCAN_BANDS, - ¶ms->bands)) { - NET_ERR("Incorrect value(s) in CONFIG_WIFI_MGMT_SCAN_BANDS: %s", - CONFIG_WIFI_MGMT_SCAN_BANDS); - return -EINVAL; - } - } - - if (!params->dwell_time_active) { - params->dwell_time_active = CONFIG_WIFI_MGMT_SCAN_DWELL_TIME_ACTIVE; - } - - if (!params->dwell_time_passive) { - params->dwell_time_passive = CONFIG_WIFI_MGMT_SCAN_DWELL_TIME_PASSIVE; - } - - if (!strlen(params->ssids[0])) { - if (wifi_utils_parse_scan_ssids(CONFIG_WIFI_MGMT_SCAN_SSID_FILT, - params->ssids)) { - NET_ERR("Incorrect value(s) in CONFIG_WIFI_MGMT_SCAN_SSID_FILT: %s", - CONFIG_WIFI_MGMT_SCAN_SSID_FILT); - return -EINVAL; - } - } - - if (!params->max_bss_cnt) { - params->max_bss_cnt = CONFIG_WIFI_MGMT_SCAN_MAX_BSS_CNT; - } - - for (i = 0; i <= WIFI_FREQ_BAND_MAX; i++) { - if (params->chan[i][0]) { - chan_specified = true; - break; - } - } - - if ((!chan_specified) && strlen(CONFIG_WIFI_MGMT_SCAN_CHAN)) { - if (wifi_utils_parse_scan_chan(CONFIG_WIFI_MGMT_SCAN_CHAN, - params->chan)) { - NET_ERR("Incorrect value(s) in CONFIG_WIFI_MGMT_SCAN_CHAN: %s", - CONFIG_WIFI_MGMT_SCAN_CHAN); - return -EINVAL; - } - } - } - return wifi_mgmt_api->scan(dev, params, scan_result_cb); } From 8efaa1633aa03d4444be79b7b029a28c13362a02 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sat, 16 Sep 2023 15:47:17 +1000 Subject: [PATCH 0474/1623] [nrf fromtree] net: wifi_mgmt: make number of scan channels configurable Make the maximum number of channels that can be manually scanned configurable by the application. The previous value of 233 was vastly overallocating memory as the largest band only contains 60 allocated channels. Signed-off-by: Jordan Yates (cherry picked from commit 6a428f19b66b9603205b29b300557c14f77a0bc0) --- include/zephyr/net/wifi_mgmt.h | 8 +++++++- subsys/net/l2/wifi/Kconfig | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 67a603aea95..81634a7fc62 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -41,6 +41,12 @@ extern "C" { #define WIFI_MGMT_SCAN_SSID_FILT_MAX 0 #endif /* CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX */ +#ifdef CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL +#define WIFI_MGMT_SCAN_CHAN_MAX_MANUAL CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL +#else +#define WIFI_MGMT_SCAN_CHAN_MAX_MANUAL 1 +#endif /* CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL */ + #define WIFI_MGMT_BAND_STR_SIZE_MAX 8 /** Wi-Fi management commands */ @@ -252,7 +258,7 @@ struct wifi_scan_params { * not conforming to regulatory restrictions etc. The invoker of the API should * ensure that the channels specified follow regulatory rules. */ - uint8_t chan[WIFI_FREQ_BAND_MAX + 1][WIFI_CHANNEL_MAX]; + uint8_t chan[WIFI_FREQ_BAND_MAX + 1][WIFI_MGMT_SCAN_CHAN_MAX_MANUAL]; }; /** Wi-Fi scan result, each result is provided to the net_mgmt_event_callback diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index ccf5ce31ca6..5644852c2a0 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -47,6 +47,14 @@ config WIFI_MGMT_SCAN_SSID_FILT_MAX Maximum number of SSIDs that can be specified for SSID filtering. This can be set based on the underlying chipsets limitations. +config WIFI_MGMT_SCAN_CHAN_MAX_MANUAL + int "Maximum number of channels that can be manually specified per-band" + range 1 70 + default 3 + help + There are currently 60 channels allocated in the largest band (6GHz). + The default of 3 allows the 3 most common channels (2.4GHz: 1, 6, 11) to be specified. + config WIFI_NM bool "Wi-Fi Network manager support" help From 5fa35c899d62e725fa77f74881e7465f3749fb61 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sat, 16 Sep 2023 15:54:28 +1000 Subject: [PATCH 0475/1623] [nrf fromtree] net: wifi_mgmt: linearise `scan_params->chan` arrays Turn the nested arrays of `scan_params->chan` into a single array. This adds the requirement to specify the band for each channel, but eliminates the large amount of dead memory for unused bands. Overall, this saves 50% of the RAM space for this variable. Signed-off-by: Jordan Yates (cherry picked from commit b54951b86e440e92dcdd41598d38f67987ce3cf2) --- include/zephyr/net/wifi_mgmt.h | 18 ++++++++++++++---- include/zephyr/net/wifi_utils.h | 4 +++- subsys/net/l2/wifi/Kconfig | 6 +++--- subsys/net/l2/wifi/wifi_shell.c | 4 +++- subsys/net/l2/wifi/wifi_utils.c | 32 ++++++++++++++++++++++++-------- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 81634a7fc62..ab37bd4d878 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -209,6 +209,16 @@ enum net_event_wifi_cmd { #define NET_EVENT_WIFI_DISCONNECT_COMPLETE \ (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE) +/** + * @brief Wi-Fi structure to uniquely identify a band-channel pair + */ +struct wifi_band_channel { + /** Frequency band */ + uint8_t band; + /** Channel */ + uint8_t channel; +}; + /** * @brief Wi-Fi scan parameters structure. * Used to specify parameters which can control how the Wi-Fi scan @@ -248,9 +258,9 @@ struct wifi_scan_params { * band. * E.g. to scan channel 6 and 11 on the 2.4 GHz band, channel 36 on the 5 GHz band: * @code{.c} - * chan[WIFI_FREQ_BAND_2_4_GHZ][0] = 6; - * chan[WIFI_FREQ_BAND_2_4_GHZ][1] = 11; - * chan[WIFI_FREQ_BAND_5_GHZ][0] = 36; + * chan[0] = {WIFI_FREQ_BAND_2_4_GHZ, 6}; + * chan[1] = {WIFI_FREQ_BAND_2_4_GHZ, 11}; + * chan[2] = {WIFI_FREQ_BAND_5_GHZ, 36}; * @endcode * * This list specifies the channels to be __considered for scan__. The underlying @@ -258,7 +268,7 @@ struct wifi_scan_params { * not conforming to regulatory restrictions etc. The invoker of the API should * ensure that the channels specified follow regulatory rules. */ - uint8_t chan[WIFI_FREQ_BAND_MAX + 1][WIFI_MGMT_SCAN_CHAN_MAX_MANUAL]; + struct wifi_band_channel band_chan[WIFI_MGMT_SCAN_CHAN_MAX_MANUAL]; }; /** Wi-Fi scan result, each result is provided to the net_mgmt_event_callback diff --git a/include/zephyr/net/wifi_utils.h b/include/zephyr/net/wifi_utils.h index b005d075847..4284138b6f3 100644 --- a/include/zephyr/net/wifi_utils.h +++ b/include/zephyr/net/wifi_utils.h @@ -95,12 +95,14 @@ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, * * @param scan_chan_str List of channels expressed in the format described above. * @param chan Pointer to an array where the parsed channels are to be stored. + * @param max_channels Maximum number of channels to store * * @retval 0 on success. * @retval -errno value in case of failure. */ int wifi_utils_parse_scan_chan(char *scan_chan_str, - uint8_t chan[][WIFI_CHANNEL_MAX]); + struct wifi_band_channel *chan, + uint8_t max_channels); /** * @} diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 5644852c2a0..8fbd6aff4d6 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -48,11 +48,11 @@ config WIFI_MGMT_SCAN_SSID_FILT_MAX This can be set based on the underlying chipsets limitations. config WIFI_MGMT_SCAN_CHAN_MAX_MANUAL - int "Maximum number of channels that can be manually specified per-band" - range 1 70 + int "Maximum number of channels that can be manually specified" + range 1 110 default 3 help - There are currently 60 channels allocated in the largest band (6GHz). + There are approximately 100 channels allocated across the three supported bands. The default of 3 allows the 3 most common channels (2.4GHz: 1, 6, 11) to be specified. config WIFI_NM diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 6893e20353e..65e99204aa7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -557,7 +557,9 @@ static int wifi_scan_args_to_params(const struct shell *sh, opt_num++; break; case 'c': - if (wifi_utils_parse_scan_chan(optarg, params->chan)) { + if (wifi_utils_parse_scan_chan(optarg, + params->band_chan, + ARRAY_SIZE(params->band_chan))) { shell_fprintf(sh, SHELL_ERROR, "Invalid band or channel value(s)\n"); diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index a77e225bfbf..4c50b817d26 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -105,7 +105,7 @@ static bool wifi_utils_validate_chan(uint8_t band, static int wifi_utils_get_all_chans_in_range(uint8_t chan_start, uint8_t chan_end, - uint8_t chan[][WIFI_CHANNEL_MAX], + struct wifi_band_channel *band_chan, uint8_t band_idx, uint8_t *chan_idx) { @@ -136,7 +136,9 @@ static int wifi_utils_get_all_chans_in_range(uint8_t chan_start, idx = *chan_idx; for (i = chan_start; i <= chan_end; i++) { - chan[band_idx][idx++] = i; + band_chan[idx].band = band_idx; + band_chan[idx].channel = i; + idx++; } *chan_idx = idx; @@ -155,7 +157,9 @@ static int wifi_utils_get_all_chans_in_range(uint8_t chan_start, } if (start) { - chan[band_idx][idx++] = valid_5g_chans_20mhz[i]; + band_chan[idx].band = band_idx; + band_chan[idx].channel = valid_5g_chans_20mhz[i]; + idx++; } if (end) { @@ -171,7 +175,9 @@ static int wifi_utils_get_all_chans_in_range(uint8_t chan_start, i = chan_start; while (i <= chan_end) { - chan[band_idx][idx++] = i; + band_chan[idx].band = band_idx; + band_chan[idx].channel = i; + idx++; if (i == 1) { i++; @@ -310,7 +316,8 @@ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, int wifi_utils_parse_scan_chan(char *scan_chan_str, - uint8_t chan[][WIFI_CHANNEL_MAX]) + struct wifi_band_channel *band_chan, + uint8_t max_channels) { char band_str[WIFI_UTILS_MAX_BAND_STR_LEN] = {0}; char chan_str[WIFI_UTILS_MAX_CHAN_STR_LEN] = {0}; @@ -349,7 +356,6 @@ int wifi_utils_parse_scan_chan(char *scan_chan_str, } i++; - chan_idx = 0; chan_str_start_idx = i; valid_band = true; @@ -383,9 +389,13 @@ int wifi_utils_parse_scan_chan(char *scan_chan_str, memset(chan_str, 0, sizeof(chan_str)); if (chan_start) { + if ((chan_idx + (chan_val - chan_start)) >= max_channels) { + NET_ERR("Too many channels specified (%d)", max_channels); + return -EINVAL; + } if (wifi_utils_get_all_chans_in_range(chan_start, chan_val, - chan, + band_chan, band, &chan_idx)) { NET_ERR("Channel range invalid"); @@ -399,8 +409,14 @@ int wifi_utils_parse_scan_chan(char *scan_chan_str, NET_ERR("Invalid channel %d", chan_val); return -EINVAL; } + if (chan_idx == max_channels) { + NET_ERR("Too many channels specified (%d)", max_channels); + return -EINVAL; + } - chan[band][chan_idx++] = chan_val; + band_chan[chan_idx].band = band; + band_chan[chan_idx].channel = chan_val; + chan_idx++; } valid_chan = true; From 88884a533d602ff2e756f5e91af60cef5fd30a14 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sat, 23 Sep 2023 17:47:30 +1000 Subject: [PATCH 0476/1623] [nrf fromtree] net: wifi: shell: update SSID argument format Instead of providing a comma seperated list of SSIDs, provide the SSIDs individually. This substantially simplifies the implementation. Signed-off-by: Jordan Yates (cherry picked from commit 3b7237e6cd9592abba074822690c49bb774634e8) --- include/zephyr/net/wifi_utils.h | 6 +++-- subsys/net/l2/wifi/wifi_shell.c | 8 ++++--- subsys/net/l2/wifi/wifi_utils.c | 41 ++++++++------------------------- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/include/zephyr/net/wifi_utils.h b/include/zephyr/net/wifi_utils.h index 4284138b6f3..c9ef9979f91 100644 --- a/include/zephyr/net/wifi_utils.h +++ b/include/zephyr/net/wifi_utils.h @@ -63,13 +63,15 @@ int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map); * as a comma separated string and convert it to an array. * * @param scan_ssids_str List of SSIDs expressed as a comma separated list. - * @param ssids Pointer to an array where the parsed SSIDs are to be stored. + * @param ssids Pointer to an array where the SSIDs pointers are to be stored. + * @param num_ssids Maximum number of SSIDs that can be stored. * * @retval 0 on success. * @retval -errno value in case of failure. */ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, - char ssids[][WIFI_SSID_MAX_LEN + 1]); + const char *ssids[], + uint8_t num_ssids); /** diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 65e99204aa7..3aa674e73b7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -481,7 +481,7 @@ static int wifi_scan_args_to_params(const struct shell *sh, {"bands", required_argument, 0, 'b'}, {"dwell_time_active", required_argument, 0, 'a'}, {"dwell_time_passive", required_argument, 0, 'p'}, - {"ssids", required_argument, 0, 's'}, + {"ssid", required_argument, 0, 's'}, {"max_bss", required_argument, 0, 'm'}, {"chans", required_argument, 0, 'c'}, {"help", no_argument, 0, 'h'}, @@ -538,7 +538,9 @@ static int wifi_scan_args_to_params(const struct shell *sh, opt_num++; break; case 's': - if (wifi_utils_parse_scan_ssids(optarg, params->ssids)) { + if (wifi_utils_parse_scan_ssids(optarg, + params->ssids, + ARRAY_SIZE(params->ssids))) { shell_fprintf(sh, SHELL_ERROR, "Invalid SSID(s)\n"); return -ENOEXEC; } @@ -1671,7 +1673,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz.\n" "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms.\n" "[-p, --dwell_time_passive ] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms.\n" - "[-s, --ssids ] : SSID list to scan for.\n" + "[-s, --ssid : SSID to scan for. Can be provided multiple times.\n" "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535.\n" "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6-11,14_5:36,149-165,44\n" "[-h, --help] : Print out the help for the scan command.", diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index 4c50b817d26..52d25d90566 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -263,12 +263,9 @@ int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map) } int wifi_utils_parse_scan_ssids(char *scan_ssids_str, - char ssids[][WIFI_SSID_MAX_LEN + 1]) + const char *ssids[], + uint8_t num_ssids) { - char parse_str[(WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1)) + 1]; - char *ssid = NULL; - char *ctx = NULL; - uint8_t i = 0; int len; if (!scan_ssids_str) { @@ -276,41 +273,23 @@ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, } len = strlen(scan_ssids_str); - - if (len > (WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1))) { + if (len > WIFI_SSID_MAX_LEN) { NET_ERR("SSID string (%s) size (%d) exceeds maximum allowed value (%d)", scan_ssids_str, len, - (WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1))); + WIFI_SSID_MAX_LEN); return -EINVAL; } - strncpy(parse_str, scan_ssids_str, len); - parse_str[len] = '\0'; - - ssid = strtok_r(parse_str, ",", &ctx); - - while (ssid) { - if (strlen(ssid) > WIFI_SSID_MAX_LEN) { - NET_ERR("SSID length (%zu) exceeds maximum value (%d) for SSID %s", - strlen(ssid), - WIFI_SSID_MAX_LEN, - ssid); - return -EINVAL; - } - - if (i >= WIFI_MGMT_SCAN_SSID_FILT_MAX) { - NET_WARN("Exceeded maximum allowed (%d) SSIDs. Ignoring SSIDs %s onwards", - WIFI_MGMT_SCAN_SSID_FILT_MAX, - ssid); - break; + for (int i = 0; i < num_ssids; i++) { + if (ssids[i] != NULL) { + continue; } - - strcpy(&ssids[i++][0], ssid); - - ssid = strtok_r(NULL, ",", &ctx); + ssids[i] = scan_ssids_str; + return 0; } + NET_WARN("Exceeded maximum allowed SSIDs (%d)", num_ssids); return 0; } From 339e7dcdcf0baa5169ffda4e805ff6d688220f19 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sat, 23 Sep 2023 17:59:34 +1000 Subject: [PATCH 0477/1623] [nrf fromtree] net: wifi: re-add `WIFI_MGMT_FORCED_PASSIVE_SCAN` Re-add the `WIFI_MGMT_FORCED_PASSIVE_SCAN` option removed in #62751. Now that `struct wifi_scan_params` is a reasonable size, we can enforce the passive scan request even when no parameter struct is supplied by the user. Signed-off-by: Jordan Yates (cherry picked from commit 2b92598df12ce66d6fc42327636c72c25fe6222b) --- subsys/net/l2/wifi/Kconfig | 9 +++++++++ subsys/net/l2/wifi/wifi_mgmt.c | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 8fbd6aff4d6..134448aa57f 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -39,6 +39,15 @@ config WIFI_MGMT_TWT_CHECK_IP even when it is awake intervals. Rejecting TWT setup till Wi-Fi interface has a valid IP address might be desirable in most scenarios. +config WIFI_MGMT_FORCED_PASSIVE_SCAN + bool "Force passive Wi-Fi scanning" + help + Always request a passive scan, regardless of the user supplied parameters. + This is typically used when the underlying hardware is not certified for + RF transmissions. This doesn't guarantee that passive scan will be used, + it depends on the underlying chip implementation to support and honour + scan type. + config WIFI_MGMT_SCAN_SSID_FILT_MAX int "Maximum number of SSIDs that can be specified for SSID filtering" default 1 diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 58e14ff02ff..cdad7646e02 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -327,6 +327,15 @@ static int wifi_scan(uint32_t mgmt_request, struct net_if *iface, return -ENOTSUP; } +#ifdef CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN + struct wifi_scan_params default_params = {0}; + + if (params == NULL) { + params = &default_params; + } + params->scan_type = WIFI_SCAN_TYPE_PASSIVE; +#endif /* CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN */ + return wifi_mgmt_api->scan(dev, params, scan_result_cb); } From feb411bac2fb151c8299e47eefa6622d2e66d504 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sat, 23 Sep 2023 17:41:46 +1000 Subject: [PATCH 0478/1623] [nrf fromtree] net: wifi_mgmt: update SSID storage type Update the storage type of the SSID strings to pointers to the strings, instead of needing to copy the strings into the struct. This substantially reduces the parameter struct size. Signed-off-by: Jordan Yates (cherry picked from commit a32e7aaa102d87aa06bb2105e3678844956d2b71) --- include/zephyr/net/wifi_mgmt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index ab37bd4d878..d1bf5d43bfd 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -245,7 +245,7 @@ struct wifi_scan_params { uint16_t dwell_time_passive; /** Array of SSID strings to scan. */ - char ssids[WIFI_MGMT_SCAN_SSID_FILT_MAX][WIFI_SSID_MAX_LEN + 1]; + const char *ssids[WIFI_MGMT_SCAN_SSID_FILT_MAX]; /** Specifies the maximum number of scan results to return. These results would be the * BSSIDS with the best RSSI values, in all the scanned channels. This should only be * used to limit the number of returned scan results, and cannot be counted upon to limit From bf821e930748f94977af135540235b76dad32ee9 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 13:55:12 +0530 Subject: [PATCH 0479/1623] [nrf fromlist] wifi: shell: Fix the arg count for reg domain Missed accounting for "-f" option. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 3aa674e73b7..c3100c9ad2c 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1688,7 +1688,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain, - 1, 1), + 1, 2), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" From 16d86216eb95cbc5e173db576ebee9c7d72d0569 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 13:57:20 +0530 Subject: [PATCH 0480/1623] [nrf fromlist] wifi: shell: Fix optional arg count for connect Fix an extra optional arg. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index c3100c9ad2c..dbec138fea0 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1653,7 +1653,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_connect, - 2, 5), + 2, 4), SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", cmd_wifi_disconnect, 1, 0), From 0fc24a59c702c89f6fa04feb552d5bb1eee5e6df Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 13:59:52 +0530 Subject: [PATCH 0481/1623] [nrf fromlist] wifi: shell: Fix help for PS command Clearly mark the args as optional. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index dbec138fea0..6ef745670ab 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1657,7 +1657,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", cmd_wifi_disconnect, 1, 0), - SHELL_CMD_ARG(ps, NULL, "Configure Wi-F PS on/off, no arguments will dump config", + SHELL_CMD_ARG(ps, NULL, "Configure or display Wi-Fi power save state\n" + "[on/off]\n", cmd_wifi_ps, 1, 1), SHELL_CMD_ARG(ps_mode, From e8a952b68db6cd8d097e169a56284bf0ff42c2a0 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 14:00:50 +0530 Subject: [PATCH 0482/1623] [nrf fromlist] wifi: shell: Remove the unnecessary text in scan We are using standard notation to differentiate optional and mandatory, so, no need for a heading. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 1 - 1 file changed, 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 6ef745670ab..d6d14c86bf1 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1669,7 +1669,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, 0), SHELL_CMD_ARG(scan, NULL, "Scan for Wi-Fi APs\n" - "OPTIONAL PARAMETERS:\n" "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active.\n" "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz.\n" "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms.\n" From 6be67b3199e68acff52e8d09d231d0f4d5afec4d Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 14:02:42 +0530 Subject: [PATCH 0483/1623] [nrf fromlist] wifi: shell: Fix the help for reg domain Separate the two optional parameters and add help. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index d6d14c86bf1..890bb8f121e 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1684,7 +1684,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows", NULL), SHELL_CMD_ARG(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" - "Usage: wifi reg_domain [ISO/IEC 3166-1 alpha2] [-f]\n" + "[ISO/IEC 3166-1 alpha2]: Regulatory domain\n" "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain, From f9f9f83293267465b05927bc3756e1d22accab05 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 14:07:36 +0530 Subject: [PATCH 0484/1623] [nrf fromlist] wifi: shell: Remove the unnecessary text The parameters heading is implied and doesn't have the newline, so, just remove it. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 890bb8f121e..a983e5c18f5 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1691,7 +1691,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, 1, 2), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" - "parameters:" "[-i, --if-index ] : Interface index.\n" "[-s, --sta] : Station mode.\n" "[-m, --monitor] : Monitor mode.\n" @@ -1711,7 +1710,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "This command is used to set packet filter setting when\n" "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" - "parameters:" "[-i, --if-index ] : Interface index.\n" "[-a, --all] : Enable all packet filter modes\n" "[-m, --mgmt] : Enable management packets to allowed up the stack.\n" @@ -1730,7 +1728,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "This command is used to set the channel when\n" "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" - "parameters:" "[-i, --if-index ] : Interface index.\n" "[-c, --channel ] : Set a specific channel number to the lower layer.\n" "[-g, --get] : Get current set channel number from the lower layer.\n" From 1353dd144af6aaaa71649c82db287525a72da343 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 14:15:11 +0530 Subject: [PATCH 0485/1623] [nrf fromlist] wifi: shell: Fix the inconsistency in commands separation For better readability, below rules will help: * Each command should be separated by a newline * Each command should end with a full stop (intermediate statements shouldn't have full stops) Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 98 ++++++++++++++++----------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index a983e5c18f5..9bf33e827ec 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1601,7 +1601,7 @@ static int cmd_wifi_packet_filter(const struct shell *sh, size_t argc, char *arg SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, SHELL_CMD_ARG(disable, NULL, - "Disable Access Point mode", + "Disable Access Point mode.\n", cmd_wifi_ap_disable, 1, 0), SHELL_CMD_ARG(enable, NULL, @@ -1611,7 +1611,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, "[Security type: valid only for secure SSIDs]\n" "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" - ": 0:Disable, 1:Optional, 2:Required", + ": 0:Disable, 1:Optional, 2:Required.\n", cmd_wifi_ap_enable, 2, 4), SHELL_SUBCMD_SET_END @@ -1619,30 +1619,30 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops, SHELL_CMD_ARG(quick_setup, NULL, " Start a TWT flow with defaults:\n" - " \n", + " .\n", cmd_wifi_twt_setup_quick, 3, 0), SHELL_CMD_ARG(setup, NULL, " Start a TWT flow:\n" "\n" "\n" " " - " \n", + " .\n", cmd_wifi_twt_setup, 11, 0), SHELL_CMD_ARG(teardown, NULL, " Teardown a TWT flow:\n" "\n" "\n" - " \n", + " .\n", cmd_wifi_twt_teardown, 5, 0), - SHELL_CMD_ARG(teardown_all, NULL, " Teardown all TWT flows\n", + SHELL_CMD_ARG(teardown_all, NULL, " Teardown all TWT flows.\n", cmd_wifi_twt_teardown_all, 1, 0), SHELL_SUBCMD_SET_END ); SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, - SHELL_CMD(ap, &wifi_cmd_ap, "Access Point mode commands", NULL), + SHELL_CMD(ap, &wifi_cmd_ap, "Access Point mode commands.\n", NULL), SHELL_CMD_ARG(connect, NULL, "Connect to a Wi-Fi AP\n" "\"\"\n" @@ -1651,108 +1651,108 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[Security type: valid only for secure SSIDs]\n" "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" - ": 0:Disable, 1:Optional, 2:Required", + ": 0:Disable, 1:Optional, 2:Required.\n", cmd_wifi_connect, 2, 4), - SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", + SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP.\n", cmd_wifi_disconnect, 1, 0), SHELL_CMD_ARG(ps, NULL, "Configure or display Wi-Fi power save state\n" - "[on/off]\n", + "[on/off].\n", cmd_wifi_ps, 1, 1), SHELL_CMD_ARG(ps_mode, NULL, - "\n", + ".\n", cmd_wifi_ps_mode, 2, 0), SHELL_CMD_ARG(scan, NULL, "Scan for Wi-Fi APs\n" - "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active.\n" - "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz.\n" - "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms.\n" - "[-p, --dwell_time_passive ] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms.\n" - "[-s, --ssid : SSID to scan for. Can be provided multiple times.\n" - "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535.\n" + "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active\n" + "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz\n" + "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms\n" + "[-p, --dwell_time_passive ] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms\n" + "[-s, --ssid : SSID to scan for. Can be provided multiple times\n" + "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535\n" "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6-11,14_5:36,149-165,44\n" - "[-h, --help] : Print out the help for the scan command.", + "[-h, --help] : Print out the help for the scan command.\n", cmd_wifi_scan, 1, 8), - SHELL_CMD_ARG(statistics, NULL, "Wi-Fi interface statistics", cmd_wifi_stats, 1, 0), - SHELL_CMD_ARG(status, NULL, "Status of the Wi-Fi interface", cmd_wifi_status, 1, 0), - SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows", NULL), + SHELL_CMD_ARG(statistics, NULL, "Wi-Fi interface statistics.\n", cmd_wifi_stats, 1, 0), + SHELL_CMD_ARG(status, NULL, "Status of the Wi-Fi interface.\n", cmd_wifi_status, 1, 0), + SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows.\n", NULL), SHELL_CMD_ARG(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" "[ISO/IEC 3166-1 alpha2]: Regulatory domain\n" "[-f]: Force to use this regulatory hint over any other regulatory hints\n" - "Note: This may cause regulatory compliance issues, use it at your own risk.", + "Note: This may cause regulatory compliance issues, use it at your own risk.\n", cmd_wifi_reg_domain, 1, 2), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" - "[-i, --if-index ] : Interface index.\n" - "[-s, --sta] : Station mode.\n" - "[-m, --monitor] : Monitor mode.\n" - "[-p, --promiscuous] : Promiscuous mode.\n" - "[-t, --tx-injection] : TX-Injection mode.\n" - "[-a, --ap] : AP mode.\n" - "[-k, --softap] : Softap mode.\n" - "[-h, --help] : Help.\n" - "[-g, --get] : Get current mode for a specific interface index.\n" + "[-i, --if-index ] : Interface index\n" + "[-s, --sta] : Station mode\n" + "[-m, --monitor] : Monitor mode\n" + "[-p, --promiscuous] : Promiscuous mode\n" + "[-t, --tx-injection] : TX-Injection mode\n" + "[-a, --ap] : AP mode\n" + "[-k, --softap] : Softap mode\n" + "[-h, --help] : Help\n" + "[-g, --get] : Get current mode for a specific interface index\n" "Usage: Get operation example for interface index 1\n" "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" - "wifi mode -i1 -sp\n", + "wifi mode -i1 -sp.\n", cmd_wifi_mode, 1, 9), SHELL_CMD_ARG(packet_filter, NULL, "mode filter setting\n" "This command is used to set packet filter setting when\n" - "monitor, TX-Injection and promiscuous mode is enabled.\n" + "monitor, TX-Injection and promiscuous mode is enabled\n" "The different packet filter modes are control, management, data and enable all filters\n" - "[-i, --if-index ] : Interface index.\n" + "[-i, --if-index ] : Interface index\n" "[-a, --all] : Enable all packet filter modes\n" - "[-m, --mgmt] : Enable management packets to allowed up the stack.\n" - "[-c, --ctrl] : Enable control packets to be allowed up the stack.\n" - "[-d, --data] : Enable Data packets to be allowed up the stack.\n" - "[-g, --get] : Get current filter settings for a specific interface index.\n" + "[-m, --mgmt] : Enable management packets to allowed up the stack\n" + "[-c, --ctrl] : Enable control packets to be allowed up the stack\n" + "[-d, --data] : Enable Data packets to be allowed up the stack\n" + "[-g, --get] : Get current filter settings for a specific interface index\n" "[-b, --capture-len ] : Capture length buffer size for each packet to be captured\n" - "[-h, --help] : Help.\n" + "[-h, --help] : Help\n" "Usage: Get operation example for interface index 1\n" "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" - "wifi packet_filter -i1 -md\n", + "wifi packet_filter -i1 -md.\n", cmd_wifi_packet_filter, 1, 8), SHELL_CMD_ARG(channel, NULL, "wifi channel setting\n" "This command is used to set the channel when\n" - "monitor or TX-Injection mode is enabled.\n" + "monitor or TX-Injection mode is enabled\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" - "[-i, --if-index ] : Interface index.\n" - "[-c, --channel ] : Set a specific channel number to the lower layer.\n" - "[-g, --get] : Get current set channel number from the lower layer.\n" - "[-h, --help] : Help.\n" + "[-i, --if-index ] : Interface index\n" + "[-c, --channel ] : Set a specific channel number to the lower layer\n" + "[-g, --get] : Get current set channel number from the lower layer\n" + "[-h, --help] : Help\n" "Usage: Get operation example for interface index 1\n" "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" - "wifi -i1 -c5\n", + "wifi -i1 -c5.\n", cmd_wifi_channel, 1, 4), SHELL_CMD_ARG(ps_timeout, NULL, - " - PS inactivity timer(in ms)", + " - PS inactivity timer(in ms).\n", cmd_wifi_ps_timeout, 2, 0), SHELL_CMD_ARG(ps_listen_interval, NULL, - " - Listen interval in the range of <0-65535>", + " - Listen interval in the range of <0-65535>.\n", cmd_wifi_listen_interval, 2, 0), SHELL_CMD_ARG(ps_wakeup_mode, NULL, - "\n", + ".\n", cmd_wifi_ps_wakeup_mode, 2, 0), From 72453d6a4d48e08ec07e86d2fb5cf38a3fe628df Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 14:20:22 +0530 Subject: [PATCH 0486/1623] [nrf fromlist] shell: Add a space after colon Just a cosmetic change, but IMHO the help looks much better now :). Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata --- subsys/shell/shell_help.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/shell/shell_help.c b/subsys/shell/shell_help.c index 53bf00953c1..235e2111032 100644 --- a/subsys/shell/shell_help.c +++ b/subsys/shell/shell_help.c @@ -139,7 +139,7 @@ static void help_item_print(const struct shell *sh, const char *item_name, z_cursor_next_line_move(sh); return; } else { - z_shell_fprintf(sh, SHELL_NORMAL, "%s:", tabulator); + z_shell_fprintf(sh, SHELL_NORMAL, "%s: ", tabulator); } /* print option help */ formatted_text_print(sh, item_help, offset, false); From 0646c56102d167a6ef533095d5603e7d411b1f54 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 26 Dec 2023 21:27:32 +0530 Subject: [PATCH 0487/1623] [nrf fromlist] wifi: Fix duplication Use a common set of events and then add specific ones as per the configuration. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67015 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 9bf33e827ec..236e5cd05b8 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -29,19 +29,17 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); #define WIFI_SHELL_MODULE "wifi" +#define WIFI_SHELL_MGMT_EVENTS_COMMON (NET_EVENT_WIFI_SCAN_DONE |\ + NET_EVENT_WIFI_CONNECT_RESULT |\ + NET_EVENT_WIFI_DISCONNECT_RESULT | \ + NET_EVENT_WIFI_TWT |\ + NET_EVENT_WIFI_RAW_SCAN_RESULT) + #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY -#define WIFI_SHELL_MGMT_EVENTS (NET_EVENT_WIFI_RAW_SCAN_RESULT | \ - NET_EVENT_WIFI_SCAN_DONE | \ - NET_EVENT_WIFI_CONNECT_RESULT | \ - NET_EVENT_WIFI_DISCONNECT_RESULT | \ - NET_EVENT_WIFI_TWT) +#define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON) #else -#define WIFI_SHELL_MGMT_EVENTS (NET_EVENT_WIFI_SCAN_RESULT | \ - NET_EVENT_WIFI_SCAN_DONE | \ - NET_EVENT_WIFI_CONNECT_RESULT | \ - NET_EVENT_WIFI_DISCONNECT_RESULT | \ - NET_EVENT_WIFI_TWT | \ - NET_EVENT_WIFI_RAW_SCAN_RESULT) +#define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON |\ + NET_EVENT_WIFI_SCAN_RESULT) #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY */ static struct { From af9dc97de19890aa30dc04c1dbd889ef43453747 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 25 Dec 2023 20:09:45 +0530 Subject: [PATCH 0488/1623] [nrf fromlist] wifi: ap: Add status events These events communicate the status of AP mode operations (enable or disable) with few pre-defined enumerations. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67015 Signed-off-by: Chaitanya Tata --- include/zephyr/net/wifi_mgmt.h | 47 +++++++++++++++++++++++++++++++++ subsys/net/l2/wifi/wifi_mgmt.c | 24 +++++++++++++++++ subsys/net/l2/wifi/wifi_shell.c | 41 +++++++++++++++++++++++++--- 3 files changed, 108 insertions(+), 4 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index d1bf5d43bfd..1423cb2817f 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -180,6 +180,10 @@ enum net_event_wifi_cmd { NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT, /** Disconnect complete */ NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE, + /** AP mode enable result */ + NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT, + /** AP mode disable result */ + NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT, }; #define NET_EVENT_WIFI_SCAN_RESULT \ @@ -209,6 +213,12 @@ enum net_event_wifi_cmd { #define NET_EVENT_WIFI_DISCONNECT_COMPLETE \ (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE) +#define NET_EVENT_WIFI_AP_ENABLE_RESULT \ + (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT) + +#define NET_EVENT_WIFI_AP_DISABLE_RESULT \ + (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT) + /** * @brief Wi-Fi structure to uniquely identify a band-channel pair */ @@ -351,12 +361,35 @@ enum wifi_disconn_reason { WIFI_REASON_DISCONN_INACTIVITY, }; +/** Wi-Fi AP mode result codes. To be overlaid on top of \ref wifi_status + * in the AP mode enable or disable result event for detailed status. + */ +enum wifi_ap_status { + /** AP mode enable or disable successful */ + WIFI_STATUS_AP_SUCCESS = 0, + /** AP mode enable or disable failed - generic failure */ + WIFI_STATUS_AP_FAIL, + /** AP mode enable failed - channel not supported */ + WIFI_STATUS_AP_CHANNEL_NOT_SUPPORTED, + /** AP mode enable failed - channel not allowed */ + WIFI_STATUS_AP_CHANNEL_NOT_ALLOWED, + /** AP mode enable failed - SSID not allowed */ + WIFI_STATUS_AP_SSID_NOT_ALLOWED, + /** AP mode enable failed - authentication type not supported */ + WIFI_STATUS_AP_AUTH_TYPE_NOT_SUPPORTED, + /** AP mode enable failed - operation not supported */ + WIFI_STATUS_AP_OP_NOT_SUPPORTED, + /** AP mode enable failed - operation not permitted */ + WIFI_STATUS_AP_OP_NOT_PERMITTED, +}; + /** Generic Wi-Fi status for commands and events */ struct wifi_status { union { int status; enum wifi_conn_status conn_status; enum wifi_disconn_reason disconn_reason; + enum wifi_ap_status ap_status; }; }; @@ -802,6 +835,20 @@ void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface, */ void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface, int status); +/** Wi-Fi management AP mode enable result event + * + * @param iface Network interface + * @param status AP mode enable result status + */ +void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, enum wifi_ap_status status); + +/** Wi-Fi management AP mode disable result event + * + * @param iface Network interface + * @param status AP mode disable result status + */ +void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, enum wifi_ap_status status); + /** * @} */ diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index cdad7646e02..14e361c73fb 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -707,3 +707,27 @@ void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface, iface, &cnx_status, sizeof(struct wifi_status)); } + +void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, + enum wifi_ap_status status) +{ + struct wifi_status cnx_status = { + .status = status, + }; + + net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_ENABLE_RESULT, + iface, &cnx_status, + sizeof(enum wifi_ap_status)); +} + +void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, + enum wifi_ap_status status) +{ + struct wifi_status cnx_status = { + .status = status, + }; + + net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_DISABLE_RESULT, + iface, &cnx_status, + sizeof(enum wifi_ap_status)); +} diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 236e5cd05b8..217e4c703c0 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -33,7 +33,9 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); NET_EVENT_WIFI_CONNECT_RESULT |\ NET_EVENT_WIFI_DISCONNECT_RESULT | \ NET_EVENT_WIFI_TWT |\ - NET_EVENT_WIFI_RAW_SCAN_RESULT) + NET_EVENT_WIFI_RAW_SCAN_RESULT |\ + NET_EVENT_WIFI_AP_ENABLE_RESULT |\ + NET_EVENT_WIFI_AP_DISABLE_RESULT) #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY #define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON) @@ -300,6 +302,32 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) } } +static void handle_wifi_ap_enable_result(struct net_mgmt_event_callback *cb) +{ + const struct wifi_status *status = + (const struct wifi_status *)cb->info; + + if (status->status) { + print(context.sh, SHELL_WARNING, + "AP enable request failed (%d)\n", status->status); + } else { + print(context.sh, SHELL_NORMAL, "AP enabled\n"); + } +} + +static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb) +{ + const struct wifi_status *status = + (const struct wifi_status *)cb->info; + + if (status->status) { + print(context.sh, SHELL_WARNING, + "AP disable request failed (%d)\n", status->status); + } else { + print(context.sh, SHELL_NORMAL, "AP disabled\n"); + } +} + static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, struct net_if *iface) { @@ -324,6 +352,12 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, handle_wifi_raw_scan_result(cb); break; #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ + case NET_EVENT_WIFI_AP_ENABLE_RESULT: + handle_wifi_ap_enable_result(cb); + break; + case NET_EVENT_WIFI_AP_DISABLE_RESULT: + handle_wifi_ap_disable_result(cb); + break; default: break; } @@ -1112,7 +1146,7 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc, return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "AP mode enabled\n"); + shell_fprintf(sh, SHELL_NORMAL, "AP mode enable requested\n"); return 0; } @@ -1129,8 +1163,7 @@ static int cmd_wifi_ap_disable(const struct shell *sh, size_t argc, return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "AP mode disabled\n"); - + shell_fprintf(sh, SHELL_NORMAL, "AP mode disable requested\n"); return 0; } From 81038eb0200a36600381bfd7120c9105111b9cb0 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 26 Dec 2023 21:17:51 +0530 Subject: [PATCH 0489/1623] [nrf fromlist] wifi: ap: Add client side events These are helpful to track clients being added and deleted. Applications can actions based on these events. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67015 Signed-off-by: Chaitanya Tata --- include/zephyr/net/wifi_mgmt.h | 38 +++++++++++++++++++++++++++++++++ subsys/net/l2/wifi/wifi_mgmt.c | 16 ++++++++++++++ subsys/net/l2/wifi/wifi_shell.c | 32 ++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 1423cb2817f..8f1b145e233 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -184,6 +184,10 @@ enum net_event_wifi_cmd { NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT, /** AP mode disable result */ NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT, + /** STA connected to AP */ + NET_EVENT_WIFI_CMD_AP_STA_CONNECTED, + /** STA disconnected from AP */ + NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED, }; #define NET_EVENT_WIFI_SCAN_RESULT \ @@ -219,6 +223,12 @@ enum net_event_wifi_cmd { #define NET_EVENT_WIFI_AP_DISABLE_RESULT \ (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT) +#define NET_EVENT_WIFI_AP_STA_CONNECTED \ + (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_CONNECTED) + +#define NET_EVENT_WIFI_AP_STA_DISCONNECTED \ + (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED) + /** * @brief Wi-Fi structure to uniquely identify a band-channel pair */ @@ -568,6 +578,18 @@ struct wifi_raw_scan_result { }; #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ +/** AP mode - connected STA details */ +struct wifi_ap_sta_info { + /** Link mode, see enum wifi_link_mode */ + enum wifi_link_mode link_mode; + /** MAC address */ + uint8_t mac[WIFI_MAC_ADDR_LEN]; + /** MAC address length */ + uint8_t mac_length; + /** is TWT capable ? */ + bool twt_capable; +}; + /* for use in max info size calculations */ union wifi_mgmt_events { struct wifi_scan_result scan_result; @@ -577,6 +599,7 @@ union wifi_mgmt_events { struct wifi_raw_scan_result raw_scan_result; #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ struct wifi_twt_params twt_params; + struct wifi_ap_sta_info ap_sta_info; }; /** Wi-Fi mode setup */ @@ -849,6 +872,21 @@ void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, enum wifi_ap_s */ void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, enum wifi_ap_status status); +/** Wi-Fi management AP mode STA connected event + * + * @param iface Network interface + * @param sta_info STA information + */ +void wifi_mgmt_raise_ap_sta_connected_event(struct net_if *iface, + struct wifi_ap_sta_info *sta_info); + +/** Wi-Fi management AP mode STA disconnected event + * @param iface Network interface + * @param sta_info STA information + */ +void wifi_mgmt_raise_ap_sta_disconnected_event(struct net_if *iface, + struct wifi_ap_sta_info *sta_info); + /** * @} */ diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 14e361c73fb..4a9c3d8a63a 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -731,3 +731,19 @@ void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, iface, &cnx_status, sizeof(enum wifi_ap_status)); } + +void wifi_mgmt_raise_ap_sta_connected_event(struct net_if *iface, + struct wifi_ap_sta_info *sta_info) +{ + net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_STA_CONNECTED, + iface, sta_info, + sizeof(struct wifi_ap_sta_info)); +} + +void wifi_mgmt_raise_ap_sta_disconnected_event(struct net_if *iface, + struct wifi_ap_sta_info *sta_info) +{ + net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_STA_DISCONNECTED, + iface, sta_info, + sizeof(struct wifi_ap_sta_info)); +} diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 217e4c703c0..045fbed197e 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -35,7 +35,9 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); NET_EVENT_WIFI_TWT |\ NET_EVENT_WIFI_RAW_SCAN_RESULT |\ NET_EVENT_WIFI_AP_ENABLE_RESULT |\ - NET_EVENT_WIFI_AP_DISABLE_RESULT) + NET_EVENT_WIFI_AP_DISABLE_RESULT |\ + NET_EVENT_WIFI_AP_STA_CONNECTED |\ + NET_EVENT_WIFI_AP_STA_DISCONNECTED) #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY #define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON) @@ -328,6 +330,28 @@ static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb) } } +static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) +{ + const struct wifi_ap_sta_info *sta_info = + (const struct wifi_ap_sta_info *)cb->info; + uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + + print(context.sh, SHELL_NORMAL, "Station connected: %s\n", + net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, + mac_string_buf, sizeof(mac_string_buf))); +} + +static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb) +{ + const struct wifi_ap_sta_info *sta_info = + (const struct wifi_ap_sta_info *)cb->info; + uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + + print(context.sh, SHELL_NORMAL, "Station disconnected: %s\n", + net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, + mac_string_buf, sizeof(mac_string_buf))); +} + static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, struct net_if *iface) { @@ -358,6 +382,12 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, case NET_EVENT_WIFI_AP_DISABLE_RESULT: handle_wifi_ap_disable_result(cb); break; + case NET_EVENT_WIFI_AP_STA_CONNECTED: + handle_wifi_ap_sta_connected(cb); + break; + case NET_EVENT_WIFI_AP_STA_DISCONNECTED: + handle_wifi_ap_sta_disconnected(cb); + break; default: break; } From 3dab922e5d0561d37823058b0fa5fad18376cb33 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 27 Dec 2023 00:06:45 +0530 Subject: [PATCH 0490/1623] [nrf fromlist] wifi: shell: Add a shell command to list stations In AP mode maintain the database of connected stations based on the Wi-Fi management events and dump the list. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67015 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/Kconfig | 8 +++ subsys/net/l2/wifi/wifi_shell.c | 90 +++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 134448aa57f..2816be56d74 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -64,6 +64,14 @@ config WIFI_MGMT_SCAN_CHAN_MAX_MANUAL There are approximately 100 channels allocated across the three supported bands. The default of 3 allows the 3 most common channels (2.4GHz: 1, 6, 11) to be specified. +config WIFI_SHELL_MAX_AP_STA + int "Maximum number of APs and STAs that can be managed in Wi-Fi shell" + range 1 5 + default 1 + help + This option defines the maximum number of APs and STAs that can be managed + in Wi-Fi shell. + config WIFI_NM bool "Wi-Fi Network manager support" help diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 045fbed197e..1ee94304781 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -24,6 +24,7 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); #include #include #include +#include #include "net_private.h" @@ -64,6 +65,13 @@ static uint32_t scan_result; static struct net_mgmt_event_callback wifi_shell_mgmt_cb; +static K_MUTEX_DEFINE(wifi_ap_sta_list_lock); +struct wifi_ap_sta_node { + bool valid; + struct wifi_ap_sta_info sta_info; +}; +static struct wifi_ap_sta_node sta_list[CONFIG_WIFI_SHELL_MAX_AP_STA]; + #define print(sh, level, fmt, ...) \ do { \ if (sh) { \ @@ -328,6 +336,10 @@ static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb) } else { print(context.sh, SHELL_NORMAL, "AP disabled\n"); } + + k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); + memset(&sta_list, 0, sizeof(sta_list)); + k_mutex_unlock(&wifi_ap_sta_list_lock); } static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) @@ -335,10 +347,25 @@ static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) const struct wifi_ap_sta_info *sta_info = (const struct wifi_ap_sta_info *)cb->info; uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + int i; print(context.sh, SHELL_NORMAL, "Station connected: %s\n", net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, mac_string_buf, sizeof(mac_string_buf))); + + k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); + for (i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { + if (!sta_list[i].valid) { + sta_list[i].sta_info = *sta_info; + sta_list[i].valid = true; + break; + } + } + if (i == CONFIG_WIFI_SHELL_MAX_AP_STA) { + print(context.sh, SHELL_WARNING, "No space to store station info: " + "Increase CONFIG_WIFI_SHELL_MAX_AP_STA\n"); + } + k_mutex_unlock(&wifi_ap_sta_list_lock); } static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb) @@ -350,6 +377,20 @@ static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb) print(context.sh, SHELL_NORMAL, "Station disconnected: %s\n", net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, mac_string_buf, sizeof(mac_string_buf))); + + k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); + for (int i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { + if (!sta_list[i].valid) { + continue; + } + + if (!memcmp(sta_list[i].sta_info.mac, sta_info->mac, + WIFI_MAC_ADDR_LEN)) { + sta_list[i].valid = false; + break; + } + } + k_mutex_unlock(&wifi_ap_sta_list_lock); } static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, @@ -1169,6 +1210,8 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc, context.sh = sh; + k_mutex_init(&wifi_ap_sta_list_lock); + ret = net_mgmt(NET_REQUEST_WIFI_AP_ENABLE, iface, &cnx_params, sizeof(struct wifi_connect_req_params)); if (ret) { @@ -1197,6 +1240,49 @@ static int cmd_wifi_ap_disable(const struct shell *sh, size_t argc, return 0; } +static int cmd_wifi_ap_stations(const struct shell *sh, size_t argc, + char *argv[]) +{ + size_t id = 1; + + ARG_UNUSED(argv); + ARG_UNUSED(argc); + + shell_fprintf(sh, SHELL_NORMAL, "AP stations:\n"); + shell_fprintf(sh, SHELL_NORMAL, "============\n"); + + k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); + for (int i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { + struct wifi_ap_sta_info *sta; + uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + + if (!sta_list[i].valid) { + continue; + } + + sta = &sta_list[i].sta_info; + + shell_fprintf(sh, SHELL_NORMAL, "Station %zu:\n", id++); + shell_fprintf(sh, SHELL_NORMAL, "==========\n"); + shell_fprintf(sh, SHELL_NORMAL, "MAC: %s\n", + net_sprint_ll_addr_buf(sta->mac, + WIFI_MAC_ADDR_LEN, + mac_string_buf, + sizeof(mac_string_buf))); + shell_fprintf(sh, SHELL_NORMAL, "Link mode: %s\n", + wifi_link_mode_txt(sta->link_mode)); + shell_fprintf(sh, SHELL_NORMAL, "TWT: %s\n", + sta->twt_capable ? "Supported" : "Not supported"); + } + + if (id == 1) { + shell_fprintf(sh, SHELL_NORMAL, "No stations connected\n"); + } + k_mutex_unlock(&wifi_ap_sta_list_lock); + + return 0; +} + static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc, char *argv[]) @@ -1675,6 +1761,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, ": 0:Disable, 1:Optional, 2:Required.\n", cmd_wifi_ap_enable, 2, 4), + SHELL_CMD_ARG(stations, NULL, + "List stations connected to the AP", + cmd_wifi_ap_stations, + 1, 0), SHELL_SUBCMD_SET_END ); From 6fe770053b0f7beac3cccddca856b90b58285d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Ciupis?= Date: Mon, 18 Dec 2023 12:15:56 +0100 Subject: [PATCH 0491/1623] [nrf fromtree] modules: hal_nordic: reorganize nrf_802154 Kconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are multiple Kconfig symbols that are only available when the radio hardware is present. As a result, the nRF 802.15.4 radio driver is more difficult to configure on multicore architectures. Also, such solution goes against the principle of hiding the details of the platform behind the driver's interface. This commit moves all the Kconfig options that correspond to settings present in common nRF 802.15.4 configuration header so that they're available no matter if the API is serialized. Signed-off-by: Jędrzej Ciupis (cherry picked from commit 054353a75daac5522a765251201e93b4a722882f) --- modules/hal_nordic/Kconfig | 119 +++++++++---------- modules/hal_nordic/nrf_802154/CMakeLists.txt | 46 ++++--- 2 files changed, 75 insertions(+), 90 deletions(-) diff --git a/modules/hal_nordic/Kconfig b/modules/hal_nordic/Kconfig index 44c12e88685..b461c094ef4 100644 --- a/modules/hal_nordic/Kconfig +++ b/modules/hal_nordic/Kconfig @@ -43,30 +43,6 @@ config NRF_802154_MULTIPROTOCOL_SUPPORT in the driver, this option must be enabled. Otherwise, the driver assumes that access to the radio peripheral is granted indefinitely. -config NRF_802154_ENCRYPTION - bool "nRF 802.15.4 AES-CCM* authentication & encryption" - depends on !CRYPTO_NRF_ECB - -choice NRF_802154_CCA_MODE - prompt "nRF IEEE 802.15.4 CCA mode" - default NRF_802154_CCA_MODE_ED - help - CCA mode - -config NRF_802154_CCA_MODE_ED - bool "Energy Above Threshold" - -config NRF_802154_CCA_MODE_CARRIER - bool "Carrier Seen" - -config NRF_802154_CCA_MODE_CARRIER_AND_ED - bool "Energy Above Threshold AND Carrier Seen" - -config NRF_802154_CCA_MODE_CARRIER_OR_ED - bool "Energy Above Threshold OR Carrier Seen" - -endchoice - choice NRF_802154_SL_TYPE prompt "nRF IEEE 802.15.4 Service Layer Type" @@ -77,43 +53,6 @@ config NRF_802154_SL_OPENSOURCE endchoice -config NRF_802154_CCA_ED_THRESHOLD - int "nRF IEEE 802.15.4 CCA Energy Detection threshold" - default 45 - help - If energy detected in a given channel is above the value then the - channel is deemed busy. The unit is defined as per 802.15.4-2006 spec. - -config NRF_802154_CCA_CORR_THRESHOLD - int "nRF IEEE 802.15.4 CCA Correlator threshold" - default 45 - -config NRF_802154_CCA_CORR_LIMIT - int "nRF IEEE 802.15.4 CCA Correlator limit" - default 2 - help - Limit for occurrences above correlator threshold. When not equal to - zero the correlator based signal detect is enabled. - -config NRF_802154_PENDING_SHORT_ADDRESSES - int "nRF 802.15.4 pending short addresses" - default 16 - help - Number of slots containing short addresses of nodes for which pending data is stored - -config NRF_802154_PENDING_EXTENDED_ADDRESSES - int "nRF 802.15.4 pending extended addresses" - default 16 - help - Number of slots containing extended addresses of nodes for which pending data is stored - -config NRF_802154_RX_BUFFERS - int "nRF 802.15.4 receive buffers" - default 16 - help - Number of buffers in nRF 802.15.4 driver receive queue. If this value is modified, - its serialization host counterpart must be set to the exact same value. - config NRF_802154_TEMPERATURE_UPDATE bool "nRF 802.15.4 temperature update" default y @@ -192,7 +131,47 @@ config NRF_802154_SER_DEFAULT_RESPONSE_TIMEOUT This option specifies default timeout of spinel status response in milliseconds. -if NRF_802154_SER_HOST +endmenu # NRF_802154_SER_HOST || NRF_802154_SER_RADIO + +if NRF_802154_RADIO_DRIVER || NRF_802154_SERIALIZATION + +choice NRF_802154_CCA_MODE + prompt "nRF IEEE 802.15.4 CCA mode" + default NRF_802154_CCA_MODE_ED + help + CCA mode + +config NRF_802154_CCA_MODE_ED + bool "Energy Above Threshold" + +config NRF_802154_CCA_MODE_CARRIER + bool "Carrier Seen" + +config NRF_802154_CCA_MODE_CARRIER_AND_ED + bool "Energy Above Threshold AND Carrier Seen" + +config NRF_802154_CCA_MODE_CARRIER_OR_ED + bool "Energy Above Threshold OR Carrier Seen" + +endchoice + +config NRF_802154_CCA_ED_THRESHOLD + int "nRF IEEE 802.15.4 CCA Energy Detection threshold" + default 45 + help + If energy detected in a given channel is above the value then the + channel is deemed busy. The unit is defined as per 802.15.4-2006 spec. + +config NRF_802154_CCA_CORR_THRESHOLD + int "nRF IEEE 802.15.4 CCA Correlator threshold" + default 45 + +config NRF_802154_CCA_CORR_LIMIT + int "nRF IEEE 802.15.4 CCA Correlator limit" + default 2 + help + Limit for occurrences above correlator threshold. When not equal to + zero the correlator based signal detect is enabled. config NRF_802154_RX_BUFFERS int "nRF 802.15.4 receive buffers" @@ -201,11 +180,21 @@ config NRF_802154_RX_BUFFERS Number of buffers in nRF 802.15.4 driver serialization host's receive queue. If this value is modified, its remote counterpart must be set to the exact same value. -endif +config NRF_802154_PENDING_SHORT_ADDRESSES + int "nRF 802.15.4 pending short addresses" + default 16 + help + Number of slots containing short addresses of nodes for which pending data is stored -endmenu # NRF_802154_SER_HOST || NRF_802154_SER_RADIO +config NRF_802154_PENDING_EXTENDED_ADDRESSES + int "nRF 802.15.4 pending extended addresses" + default 16 + help + Number of slots containing extended addresses of nodes for which pending data is stored -if NRF_802154_RADIO_DRIVER || NRF_802154_SERIALIZATION +config NRF_802154_ENCRYPTION + bool "nRF 802.15.4 AES-CCM* authentication & encryption" + depends on !CRYPTO_NRF_ECB config NRF_802154_CARRIER_FUNCTIONS bool "nRF 802.15.4 carrier functions" diff --git a/modules/hal_nordic/nrf_802154/CMakeLists.txt b/modules/hal_nordic/nrf_802154/CMakeLists.txt index cd5ace0b278..a274a019e25 100644 --- a/modules/hal_nordic/nrf_802154/CMakeLists.txt +++ b/modules/hal_nordic/nrf_802154/CMakeLists.txt @@ -12,24 +12,6 @@ if (CONFIG_NRF_802154_RADIO_DRIVER) sl_opensource/platform/nrf_802154_irq_zephyr.c sl_opensource/platform/nrf_802154_temperature_zephyr.c ) - - target_compile_definitions(zephyr-802154-interface - INTERFACE - # CCA mode options - NRF_802154_CCA_CORR_LIMIT_DEFAULT=${CONFIG_NRF_802154_CCA_CORR_LIMIT} - NRF_802154_CCA_CORR_THRESHOLD_DEFAULT=${CONFIG_NRF_802154_CCA_CORR_THRESHOLD} - NRF_802154_CCA_ED_THRESHOLD_DEFAULT=${CONFIG_NRF_802154_CCA_ED_THRESHOLD} - ) - - if (CONFIG_NRF_802154_CCA_MODE_ED) - target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_CCA_MODE_DEFAULT=NRF_RADIO_CCA_MODE_ED) - elseif (CONFIG_NRF_802154_CCA_MODE_CARRIER) - target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_CCA_MODE_DEFAULT=NRF_RADIO_CCA_MODE_CARRIER) - elseif (CONFIG_NRF_802154_CCA_MODE_CARRIER_AND_ED) - target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_CCA_MODE_DEFAULT=NRF_RADIO_CCA_MODE_CARRIER_AND_ED) - elseif (CONFIG_NRF_802154_CCA_MODE_CARRIER_OR_ED) - target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_CCA_MODE_DEFAULT=NRF_RADIO_CCA_MODE_CARRIER_OR_ED) - endif() endif () if (CONFIG_NRF_802154_SERIALIZATION) @@ -69,8 +51,23 @@ target_compile_definitions(zephyr-802154-interface # ACK timeout NRF_802154_ACK_TIMEOUT_ENABLED=1 + + # CCA mode options + NRF_802154_CCA_CORR_LIMIT_DEFAULT=${CONFIG_NRF_802154_CCA_CORR_LIMIT} + NRF_802154_CCA_CORR_THRESHOLD_DEFAULT=${CONFIG_NRF_802154_CCA_CORR_THRESHOLD} + NRF_802154_CCA_ED_THRESHOLD_DEFAULT=${CONFIG_NRF_802154_CCA_ED_THRESHOLD} ) +if (CONFIG_NRF_802154_CCA_MODE_ED) + target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_CCA_MODE_DEFAULT=NRF_RADIO_CCA_MODE_ED) +elseif (CONFIG_NRF_802154_CCA_MODE_CARRIER) + target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_CCA_MODE_DEFAULT=NRF_RADIO_CCA_MODE_CARRIER) +elseif (CONFIG_NRF_802154_CCA_MODE_CARRIER_AND_ED) + target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_CCA_MODE_DEFAULT=NRF_RADIO_CCA_MODE_CARRIER_AND_ED) +elseif (CONFIG_NRF_802154_CCA_MODE_CARRIER_OR_ED) + target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_CCA_MODE_DEFAULT=NRF_RADIO_CCA_MODE_CARRIER_OR_ED) +endif() + if (CONFIG_NRF_802154_ENCRYPTION) target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_ENCRYPTION_ENABLED=1) target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_SECURITY_WRITER_ENABLED=1) @@ -93,13 +90,12 @@ else() target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_CARRIER_FUNCTIONS_ENABLED=0) endif() -if (CONFIG_NRF_802154_RADIO_DRIVER OR CONFIG_NRF_802154_SERIALIZATION) - target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_ENERGY_DETECTED_VERSION=1) - if (CONFIG_NRF_802154_ASSERT_ZEPHYR OR CONFIG_NRF_802154_ASSERT_ZEPHYR_MINIMAL) - target_include_directories(zephyr-802154-interface INTERFACE include) - target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_PLATFORM_ASSERT_INCLUDE=\"nrf_802154_assert_zephyr.h\") - target_sources(nrf-802154-platform PRIVATE nrf_802154_assert_handler.c) - endif() +target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_ENERGY_DETECTED_VERSION=1) + +if (CONFIG_NRF_802154_ASSERT_ZEPHYR OR CONFIG_NRF_802154_ASSERT_ZEPHYR_MINIMAL) + target_include_directories(zephyr-802154-interface INTERFACE include) + target_compile_definitions(zephyr-802154-interface INTERFACE NRF_802154_PLATFORM_ASSERT_INCLUDE=\"nrf_802154_assert_zephyr.h\") + target_sources(nrf-802154-platform PRIVATE nrf_802154_assert_handler.c) endif() set(NRF52_SERIES ${CONFIG_SOC_SERIES_NRF52X}) From f59385bdd3af03f3d825e60089a6ec3fcf8c40a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Ciupis?= Date: Mon, 18 Dec 2023 12:20:26 +0100 Subject: [PATCH 0492/1623] [nrf fromtree] modules: hal_nordic: new nrf_802154 configuration option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new Kconfig for the nRF 802.15.4 radio driver that allows the user to specify the number of encryption keys the driver can simultaneously store. Signed-off-by: Jędrzej Ciupis (cherry picked from commit 57ee911891049e5e7845fad1506dca5ab56fb014) --- modules/hal_nordic/Kconfig | 6 ++++++ modules/hal_nordic/nrf_802154/CMakeLists.txt | 3 +++ 2 files changed, 9 insertions(+) diff --git a/modules/hal_nordic/Kconfig b/modules/hal_nordic/Kconfig index b461c094ef4..6f77bbea427 100644 --- a/modules/hal_nordic/Kconfig +++ b/modules/hal_nordic/Kconfig @@ -196,6 +196,12 @@ config NRF_802154_ENCRYPTION bool "nRF 802.15.4 AES-CCM* authentication & encryption" depends on !CRYPTO_NRF_ECB +config NRF_802154_SECURITY_KEY_STORAGE_SIZE + int "nRF 802.15.4 security key storage size" + default 3 + help + Number of encryption keys that the nRF 802.15.4 Radio Driver can store simultaneously. + config NRF_802154_CARRIER_FUNCTIONS bool "nRF 802.15.4 carrier functions" help diff --git a/modules/hal_nordic/nrf_802154/CMakeLists.txt b/modules/hal_nordic/nrf_802154/CMakeLists.txt index a274a019e25..763f9625be8 100644 --- a/modules/hal_nordic/nrf_802154/CMakeLists.txt +++ b/modules/hal_nordic/nrf_802154/CMakeLists.txt @@ -56,6 +56,9 @@ target_compile_definitions(zephyr-802154-interface NRF_802154_CCA_CORR_LIMIT_DEFAULT=${CONFIG_NRF_802154_CCA_CORR_LIMIT} NRF_802154_CCA_CORR_THRESHOLD_DEFAULT=${CONFIG_NRF_802154_CCA_CORR_THRESHOLD} NRF_802154_CCA_ED_THRESHOLD_DEFAULT=${CONFIG_NRF_802154_CCA_ED_THRESHOLD} + + # Key storage size + NRF_802154_SECURITY_KEY_STORAGE_SIZE=${CONFIG_NRF_802154_SECURITY_KEY_STORAGE_SIZE} ) if (CONFIG_NRF_802154_CCA_MODE_ED) From 2cdab8eaaa0c16157babb37661655103740af2a2 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:12 +0000 Subject: [PATCH 0493/1623] Revert "[nrf fromlist] wifi: shell: Add a shell command to list stations" This reverts commit 3dab922e5d0561d37823058b0fa5fad18376cb33. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/Kconfig | 8 --- subsys/net/l2/wifi/wifi_shell.c | 90 --------------------------------- 2 files changed, 98 deletions(-) diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 2816be56d74..134448aa57f 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -64,14 +64,6 @@ config WIFI_MGMT_SCAN_CHAN_MAX_MANUAL There are approximately 100 channels allocated across the three supported bands. The default of 3 allows the 3 most common channels (2.4GHz: 1, 6, 11) to be specified. -config WIFI_SHELL_MAX_AP_STA - int "Maximum number of APs and STAs that can be managed in Wi-Fi shell" - range 1 5 - default 1 - help - This option defines the maximum number of APs and STAs that can be managed - in Wi-Fi shell. - config WIFI_NM bool "Wi-Fi Network manager support" help diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 1ee94304781..045fbed197e 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -24,7 +24,6 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); #include #include #include -#include #include "net_private.h" @@ -65,13 +64,6 @@ static uint32_t scan_result; static struct net_mgmt_event_callback wifi_shell_mgmt_cb; -static K_MUTEX_DEFINE(wifi_ap_sta_list_lock); -struct wifi_ap_sta_node { - bool valid; - struct wifi_ap_sta_info sta_info; -}; -static struct wifi_ap_sta_node sta_list[CONFIG_WIFI_SHELL_MAX_AP_STA]; - #define print(sh, level, fmt, ...) \ do { \ if (sh) { \ @@ -336,10 +328,6 @@ static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb) } else { print(context.sh, SHELL_NORMAL, "AP disabled\n"); } - - k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); - memset(&sta_list, 0, sizeof(sta_list)); - k_mutex_unlock(&wifi_ap_sta_list_lock); } static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) @@ -347,25 +335,10 @@ static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) const struct wifi_ap_sta_info *sta_info = (const struct wifi_ap_sta_info *)cb->info; uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; - int i; print(context.sh, SHELL_NORMAL, "Station connected: %s\n", net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, mac_string_buf, sizeof(mac_string_buf))); - - k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); - for (i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { - if (!sta_list[i].valid) { - sta_list[i].sta_info = *sta_info; - sta_list[i].valid = true; - break; - } - } - if (i == CONFIG_WIFI_SHELL_MAX_AP_STA) { - print(context.sh, SHELL_WARNING, "No space to store station info: " - "Increase CONFIG_WIFI_SHELL_MAX_AP_STA\n"); - } - k_mutex_unlock(&wifi_ap_sta_list_lock); } static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb) @@ -377,20 +350,6 @@ static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb) print(context.sh, SHELL_NORMAL, "Station disconnected: %s\n", net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, mac_string_buf, sizeof(mac_string_buf))); - - k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); - for (int i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { - if (!sta_list[i].valid) { - continue; - } - - if (!memcmp(sta_list[i].sta_info.mac, sta_info->mac, - WIFI_MAC_ADDR_LEN)) { - sta_list[i].valid = false; - break; - } - } - k_mutex_unlock(&wifi_ap_sta_list_lock); } static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, @@ -1210,8 +1169,6 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc, context.sh = sh; - k_mutex_init(&wifi_ap_sta_list_lock); - ret = net_mgmt(NET_REQUEST_WIFI_AP_ENABLE, iface, &cnx_params, sizeof(struct wifi_connect_req_params)); if (ret) { @@ -1240,49 +1197,6 @@ static int cmd_wifi_ap_disable(const struct shell *sh, size_t argc, return 0; } -static int cmd_wifi_ap_stations(const struct shell *sh, size_t argc, - char *argv[]) -{ - size_t id = 1; - - ARG_UNUSED(argv); - ARG_UNUSED(argc); - - shell_fprintf(sh, SHELL_NORMAL, "AP stations:\n"); - shell_fprintf(sh, SHELL_NORMAL, "============\n"); - - k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); - for (int i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { - struct wifi_ap_sta_info *sta; - uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; - - if (!sta_list[i].valid) { - continue; - } - - sta = &sta_list[i].sta_info; - - shell_fprintf(sh, SHELL_NORMAL, "Station %zu:\n", id++); - shell_fprintf(sh, SHELL_NORMAL, "==========\n"); - shell_fprintf(sh, SHELL_NORMAL, "MAC: %s\n", - net_sprint_ll_addr_buf(sta->mac, - WIFI_MAC_ADDR_LEN, - mac_string_buf, - sizeof(mac_string_buf))); - shell_fprintf(sh, SHELL_NORMAL, "Link mode: %s\n", - wifi_link_mode_txt(sta->link_mode)); - shell_fprintf(sh, SHELL_NORMAL, "TWT: %s\n", - sta->twt_capable ? "Supported" : "Not supported"); - } - - if (id == 1) { - shell_fprintf(sh, SHELL_NORMAL, "No stations connected\n"); - } - k_mutex_unlock(&wifi_ap_sta_list_lock); - - return 0; -} - static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc, char *argv[]) @@ -1761,10 +1675,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, ": 0:Disable, 1:Optional, 2:Required.\n", cmd_wifi_ap_enable, 2, 4), - SHELL_CMD_ARG(stations, NULL, - "List stations connected to the AP", - cmd_wifi_ap_stations, - 1, 0), SHELL_SUBCMD_SET_END ); From e646f905a074b7c85ff5078f523ef7f81cd3cb8c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:12 +0000 Subject: [PATCH 0494/1623] Revert "[nrf fromlist] wifi: ap: Add client side events" This reverts commit 81038eb0200a36600381bfd7120c9105111b9cb0. Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi_mgmt.h | 38 --------------------------------- subsys/net/l2/wifi/wifi_mgmt.c | 16 -------------- subsys/net/l2/wifi/wifi_shell.c | 32 +-------------------------- 3 files changed, 1 insertion(+), 85 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 8f1b145e233..1423cb2817f 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -184,10 +184,6 @@ enum net_event_wifi_cmd { NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT, /** AP mode disable result */ NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT, - /** STA connected to AP */ - NET_EVENT_WIFI_CMD_AP_STA_CONNECTED, - /** STA disconnected from AP */ - NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED, }; #define NET_EVENT_WIFI_SCAN_RESULT \ @@ -223,12 +219,6 @@ enum net_event_wifi_cmd { #define NET_EVENT_WIFI_AP_DISABLE_RESULT \ (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT) -#define NET_EVENT_WIFI_AP_STA_CONNECTED \ - (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_CONNECTED) - -#define NET_EVENT_WIFI_AP_STA_DISCONNECTED \ - (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED) - /** * @brief Wi-Fi structure to uniquely identify a band-channel pair */ @@ -578,18 +568,6 @@ struct wifi_raw_scan_result { }; #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ -/** AP mode - connected STA details */ -struct wifi_ap_sta_info { - /** Link mode, see enum wifi_link_mode */ - enum wifi_link_mode link_mode; - /** MAC address */ - uint8_t mac[WIFI_MAC_ADDR_LEN]; - /** MAC address length */ - uint8_t mac_length; - /** is TWT capable ? */ - bool twt_capable; -}; - /* for use in max info size calculations */ union wifi_mgmt_events { struct wifi_scan_result scan_result; @@ -599,7 +577,6 @@ union wifi_mgmt_events { struct wifi_raw_scan_result raw_scan_result; #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ struct wifi_twt_params twt_params; - struct wifi_ap_sta_info ap_sta_info; }; /** Wi-Fi mode setup */ @@ -872,21 +849,6 @@ void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, enum wifi_ap_s */ void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, enum wifi_ap_status status); -/** Wi-Fi management AP mode STA connected event - * - * @param iface Network interface - * @param sta_info STA information - */ -void wifi_mgmt_raise_ap_sta_connected_event(struct net_if *iface, - struct wifi_ap_sta_info *sta_info); - -/** Wi-Fi management AP mode STA disconnected event - * @param iface Network interface - * @param sta_info STA information - */ -void wifi_mgmt_raise_ap_sta_disconnected_event(struct net_if *iface, - struct wifi_ap_sta_info *sta_info); - /** * @} */ diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 4a9c3d8a63a..14e361c73fb 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -731,19 +731,3 @@ void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, iface, &cnx_status, sizeof(enum wifi_ap_status)); } - -void wifi_mgmt_raise_ap_sta_connected_event(struct net_if *iface, - struct wifi_ap_sta_info *sta_info) -{ - net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_STA_CONNECTED, - iface, sta_info, - sizeof(struct wifi_ap_sta_info)); -} - -void wifi_mgmt_raise_ap_sta_disconnected_event(struct net_if *iface, - struct wifi_ap_sta_info *sta_info) -{ - net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_STA_DISCONNECTED, - iface, sta_info, - sizeof(struct wifi_ap_sta_info)); -} diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 045fbed197e..217e4c703c0 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -35,9 +35,7 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); NET_EVENT_WIFI_TWT |\ NET_EVENT_WIFI_RAW_SCAN_RESULT |\ NET_EVENT_WIFI_AP_ENABLE_RESULT |\ - NET_EVENT_WIFI_AP_DISABLE_RESULT |\ - NET_EVENT_WIFI_AP_STA_CONNECTED |\ - NET_EVENT_WIFI_AP_STA_DISCONNECTED) + NET_EVENT_WIFI_AP_DISABLE_RESULT) #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY #define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON) @@ -330,28 +328,6 @@ static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb) } } -static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) -{ - const struct wifi_ap_sta_info *sta_info = - (const struct wifi_ap_sta_info *)cb->info; - uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; - - print(context.sh, SHELL_NORMAL, "Station connected: %s\n", - net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, - mac_string_buf, sizeof(mac_string_buf))); -} - -static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb) -{ - const struct wifi_ap_sta_info *sta_info = - (const struct wifi_ap_sta_info *)cb->info; - uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; - - print(context.sh, SHELL_NORMAL, "Station disconnected: %s\n", - net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, - mac_string_buf, sizeof(mac_string_buf))); -} - static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, struct net_if *iface) { @@ -382,12 +358,6 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, case NET_EVENT_WIFI_AP_DISABLE_RESULT: handle_wifi_ap_disable_result(cb); break; - case NET_EVENT_WIFI_AP_STA_CONNECTED: - handle_wifi_ap_sta_connected(cb); - break; - case NET_EVENT_WIFI_AP_STA_DISCONNECTED: - handle_wifi_ap_sta_disconnected(cb); - break; default: break; } From 322d4adeb1f5c73ffb98738272a17f13113ce714 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:12 +0000 Subject: [PATCH 0495/1623] Revert "[nrf fromlist] wifi: ap: Add status events" This reverts commit af9dc97de19890aa30dc04c1dbd889ef43453747. Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi_mgmt.h | 47 --------------------------------- subsys/net/l2/wifi/wifi_mgmt.c | 24 ----------------- subsys/net/l2/wifi/wifi_shell.c | 41 +++------------------------- 3 files changed, 4 insertions(+), 108 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 1423cb2817f..d1bf5d43bfd 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -180,10 +180,6 @@ enum net_event_wifi_cmd { NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT, /** Disconnect complete */ NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE, - /** AP mode enable result */ - NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT, - /** AP mode disable result */ - NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT, }; #define NET_EVENT_WIFI_SCAN_RESULT \ @@ -213,12 +209,6 @@ enum net_event_wifi_cmd { #define NET_EVENT_WIFI_DISCONNECT_COMPLETE \ (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE) -#define NET_EVENT_WIFI_AP_ENABLE_RESULT \ - (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT) - -#define NET_EVENT_WIFI_AP_DISABLE_RESULT \ - (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT) - /** * @brief Wi-Fi structure to uniquely identify a band-channel pair */ @@ -361,35 +351,12 @@ enum wifi_disconn_reason { WIFI_REASON_DISCONN_INACTIVITY, }; -/** Wi-Fi AP mode result codes. To be overlaid on top of \ref wifi_status - * in the AP mode enable or disable result event for detailed status. - */ -enum wifi_ap_status { - /** AP mode enable or disable successful */ - WIFI_STATUS_AP_SUCCESS = 0, - /** AP mode enable or disable failed - generic failure */ - WIFI_STATUS_AP_FAIL, - /** AP mode enable failed - channel not supported */ - WIFI_STATUS_AP_CHANNEL_NOT_SUPPORTED, - /** AP mode enable failed - channel not allowed */ - WIFI_STATUS_AP_CHANNEL_NOT_ALLOWED, - /** AP mode enable failed - SSID not allowed */ - WIFI_STATUS_AP_SSID_NOT_ALLOWED, - /** AP mode enable failed - authentication type not supported */ - WIFI_STATUS_AP_AUTH_TYPE_NOT_SUPPORTED, - /** AP mode enable failed - operation not supported */ - WIFI_STATUS_AP_OP_NOT_SUPPORTED, - /** AP mode enable failed - operation not permitted */ - WIFI_STATUS_AP_OP_NOT_PERMITTED, -}; - /** Generic Wi-Fi status for commands and events */ struct wifi_status { union { int status; enum wifi_conn_status conn_status; enum wifi_disconn_reason disconn_reason; - enum wifi_ap_status ap_status; }; }; @@ -835,20 +802,6 @@ void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface, */ void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface, int status); -/** Wi-Fi management AP mode enable result event - * - * @param iface Network interface - * @param status AP mode enable result status - */ -void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, enum wifi_ap_status status); - -/** Wi-Fi management AP mode disable result event - * - * @param iface Network interface - * @param status AP mode disable result status - */ -void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, enum wifi_ap_status status); - /** * @} */ diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 14e361c73fb..cdad7646e02 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -707,27 +707,3 @@ void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface, iface, &cnx_status, sizeof(struct wifi_status)); } - -void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, - enum wifi_ap_status status) -{ - struct wifi_status cnx_status = { - .status = status, - }; - - net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_ENABLE_RESULT, - iface, &cnx_status, - sizeof(enum wifi_ap_status)); -} - -void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, - enum wifi_ap_status status) -{ - struct wifi_status cnx_status = { - .status = status, - }; - - net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_DISABLE_RESULT, - iface, &cnx_status, - sizeof(enum wifi_ap_status)); -} diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 217e4c703c0..236e5cd05b8 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -33,9 +33,7 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); NET_EVENT_WIFI_CONNECT_RESULT |\ NET_EVENT_WIFI_DISCONNECT_RESULT | \ NET_EVENT_WIFI_TWT |\ - NET_EVENT_WIFI_RAW_SCAN_RESULT |\ - NET_EVENT_WIFI_AP_ENABLE_RESULT |\ - NET_EVENT_WIFI_AP_DISABLE_RESULT) + NET_EVENT_WIFI_RAW_SCAN_RESULT) #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY #define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON) @@ -302,32 +300,6 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) } } -static void handle_wifi_ap_enable_result(struct net_mgmt_event_callback *cb) -{ - const struct wifi_status *status = - (const struct wifi_status *)cb->info; - - if (status->status) { - print(context.sh, SHELL_WARNING, - "AP enable request failed (%d)\n", status->status); - } else { - print(context.sh, SHELL_NORMAL, "AP enabled\n"); - } -} - -static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb) -{ - const struct wifi_status *status = - (const struct wifi_status *)cb->info; - - if (status->status) { - print(context.sh, SHELL_WARNING, - "AP disable request failed (%d)\n", status->status); - } else { - print(context.sh, SHELL_NORMAL, "AP disabled\n"); - } -} - static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, struct net_if *iface) { @@ -352,12 +324,6 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, handle_wifi_raw_scan_result(cb); break; #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ - case NET_EVENT_WIFI_AP_ENABLE_RESULT: - handle_wifi_ap_enable_result(cb); - break; - case NET_EVENT_WIFI_AP_DISABLE_RESULT: - handle_wifi_ap_disable_result(cb); - break; default: break; } @@ -1146,7 +1112,7 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc, return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "AP mode enable requested\n"); + shell_fprintf(sh, SHELL_NORMAL, "AP mode enabled\n"); return 0; } @@ -1163,7 +1129,8 @@ static int cmd_wifi_ap_disable(const struct shell *sh, size_t argc, return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "AP mode disable requested\n"); + shell_fprintf(sh, SHELL_NORMAL, "AP mode disabled\n"); + return 0; } From 5114f4f6a47898fd0b1879fde95d6d234dae5613 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:13 +0000 Subject: [PATCH 0496/1623] Revert "[nrf fromlist] wifi: Fix duplication" This reverts commit 0646c56102d167a6ef533095d5603e7d411b1f54. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 236e5cd05b8..9bf33e827ec 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -29,17 +29,19 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); #define WIFI_SHELL_MODULE "wifi" -#define WIFI_SHELL_MGMT_EVENTS_COMMON (NET_EVENT_WIFI_SCAN_DONE |\ - NET_EVENT_WIFI_CONNECT_RESULT |\ - NET_EVENT_WIFI_DISCONNECT_RESULT | \ - NET_EVENT_WIFI_TWT |\ - NET_EVENT_WIFI_RAW_SCAN_RESULT) - #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY -#define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON) +#define WIFI_SHELL_MGMT_EVENTS (NET_EVENT_WIFI_RAW_SCAN_RESULT | \ + NET_EVENT_WIFI_SCAN_DONE | \ + NET_EVENT_WIFI_CONNECT_RESULT | \ + NET_EVENT_WIFI_DISCONNECT_RESULT | \ + NET_EVENT_WIFI_TWT) #else -#define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON |\ - NET_EVENT_WIFI_SCAN_RESULT) +#define WIFI_SHELL_MGMT_EVENTS (NET_EVENT_WIFI_SCAN_RESULT | \ + NET_EVENT_WIFI_SCAN_DONE | \ + NET_EVENT_WIFI_CONNECT_RESULT | \ + NET_EVENT_WIFI_DISCONNECT_RESULT | \ + NET_EVENT_WIFI_TWT | \ + NET_EVENT_WIFI_RAW_SCAN_RESULT) #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY */ static struct { From 1743c14faf3778ce47155fefab343a9b219f2661 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:13 +0000 Subject: [PATCH 0497/1623] Revert "[nrf fromlist] shell: Add a space after colon" This reverts commit 72453d6a4d48e08ec07e86d2fb5cf38a3fe628df. Signed-off-by: Dominik Ermel --- subsys/shell/shell_help.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/shell/shell_help.c b/subsys/shell/shell_help.c index 235e2111032..53bf00953c1 100644 --- a/subsys/shell/shell_help.c +++ b/subsys/shell/shell_help.c @@ -139,7 +139,7 @@ static void help_item_print(const struct shell *sh, const char *item_name, z_cursor_next_line_move(sh); return; } else { - z_shell_fprintf(sh, SHELL_NORMAL, "%s: ", tabulator); + z_shell_fprintf(sh, SHELL_NORMAL, "%s:", tabulator); } /* print option help */ formatted_text_print(sh, item_help, offset, false); From 55e995228073230bd5cb962feae6d1bf113b1c29 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:13 +0000 Subject: [PATCH 0498/1623] Revert "[nrf fromlist] wifi: shell: Fix the inconsistency in commands separation" This reverts commit 1353dd144af6aaaa71649c82db287525a72da343. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 98 ++++++++++++++++----------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 9bf33e827ec..a983e5c18f5 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1601,7 +1601,7 @@ static int cmd_wifi_packet_filter(const struct shell *sh, size_t argc, char *arg SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, SHELL_CMD_ARG(disable, NULL, - "Disable Access Point mode.\n", + "Disable Access Point mode", cmd_wifi_ap_disable, 1, 0), SHELL_CMD_ARG(enable, NULL, @@ -1611,7 +1611,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, "[Security type: valid only for secure SSIDs]\n" "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" - ": 0:Disable, 1:Optional, 2:Required.\n", + ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_ap_enable, 2, 4), SHELL_SUBCMD_SET_END @@ -1619,30 +1619,30 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops, SHELL_CMD_ARG(quick_setup, NULL, " Start a TWT flow with defaults:\n" - " .\n", + " \n", cmd_wifi_twt_setup_quick, 3, 0), SHELL_CMD_ARG(setup, NULL, " Start a TWT flow:\n" "\n" "\n" " " - " .\n", + " \n", cmd_wifi_twt_setup, 11, 0), SHELL_CMD_ARG(teardown, NULL, " Teardown a TWT flow:\n" "\n" "\n" - " .\n", + " \n", cmd_wifi_twt_teardown, 5, 0), - SHELL_CMD_ARG(teardown_all, NULL, " Teardown all TWT flows.\n", + SHELL_CMD_ARG(teardown_all, NULL, " Teardown all TWT flows\n", cmd_wifi_twt_teardown_all, 1, 0), SHELL_SUBCMD_SET_END ); SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, - SHELL_CMD(ap, &wifi_cmd_ap, "Access Point mode commands.\n", NULL), + SHELL_CMD(ap, &wifi_cmd_ap, "Access Point mode commands", NULL), SHELL_CMD_ARG(connect, NULL, "Connect to a Wi-Fi AP\n" "\"\"\n" @@ -1651,108 +1651,108 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[Security type: valid only for secure SSIDs]\n" "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" - ": 0:Disable, 1:Optional, 2:Required.\n", + ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_connect, 2, 4), - SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP.\n", + SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", cmd_wifi_disconnect, 1, 0), SHELL_CMD_ARG(ps, NULL, "Configure or display Wi-Fi power save state\n" - "[on/off].\n", + "[on/off]\n", cmd_wifi_ps, 1, 1), SHELL_CMD_ARG(ps_mode, NULL, - ".\n", + "\n", cmd_wifi_ps_mode, 2, 0), SHELL_CMD_ARG(scan, NULL, "Scan for Wi-Fi APs\n" - "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active\n" - "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz\n" - "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms\n" - "[-p, --dwell_time_passive ] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms\n" - "[-s, --ssid : SSID to scan for. Can be provided multiple times\n" - "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535\n" + "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active.\n" + "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz.\n" + "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms.\n" + "[-p, --dwell_time_passive ] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms.\n" + "[-s, --ssid : SSID to scan for. Can be provided multiple times.\n" + "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535.\n" "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6-11,14_5:36,149-165,44\n" - "[-h, --help] : Print out the help for the scan command.\n", + "[-h, --help] : Print out the help for the scan command.", cmd_wifi_scan, 1, 8), - SHELL_CMD_ARG(statistics, NULL, "Wi-Fi interface statistics.\n", cmd_wifi_stats, 1, 0), - SHELL_CMD_ARG(status, NULL, "Status of the Wi-Fi interface.\n", cmd_wifi_status, 1, 0), - SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows.\n", NULL), + SHELL_CMD_ARG(statistics, NULL, "Wi-Fi interface statistics", cmd_wifi_stats, 1, 0), + SHELL_CMD_ARG(status, NULL, "Status of the Wi-Fi interface", cmd_wifi_status, 1, 0), + SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows", NULL), SHELL_CMD_ARG(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" "[ISO/IEC 3166-1 alpha2]: Regulatory domain\n" "[-f]: Force to use this regulatory hint over any other regulatory hints\n" - "Note: This may cause regulatory compliance issues, use it at your own risk.\n", + "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain, 1, 2), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" - "[-i, --if-index ] : Interface index\n" - "[-s, --sta] : Station mode\n" - "[-m, --monitor] : Monitor mode\n" - "[-p, --promiscuous] : Promiscuous mode\n" - "[-t, --tx-injection] : TX-Injection mode\n" - "[-a, --ap] : AP mode\n" - "[-k, --softap] : Softap mode\n" - "[-h, --help] : Help\n" - "[-g, --get] : Get current mode for a specific interface index\n" + "[-i, --if-index ] : Interface index.\n" + "[-s, --sta] : Station mode.\n" + "[-m, --monitor] : Monitor mode.\n" + "[-p, --promiscuous] : Promiscuous mode.\n" + "[-t, --tx-injection] : TX-Injection mode.\n" + "[-a, --ap] : AP mode.\n" + "[-k, --softap] : Softap mode.\n" + "[-h, --help] : Help.\n" + "[-g, --get] : Get current mode for a specific interface index.\n" "Usage: Get operation example for interface index 1\n" "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" - "wifi mode -i1 -sp.\n", + "wifi mode -i1 -sp\n", cmd_wifi_mode, 1, 9), SHELL_CMD_ARG(packet_filter, NULL, "mode filter setting\n" "This command is used to set packet filter setting when\n" - "monitor, TX-Injection and promiscuous mode is enabled\n" + "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" - "[-i, --if-index ] : Interface index\n" + "[-i, --if-index ] : Interface index.\n" "[-a, --all] : Enable all packet filter modes\n" - "[-m, --mgmt] : Enable management packets to allowed up the stack\n" - "[-c, --ctrl] : Enable control packets to be allowed up the stack\n" - "[-d, --data] : Enable Data packets to be allowed up the stack\n" - "[-g, --get] : Get current filter settings for a specific interface index\n" + "[-m, --mgmt] : Enable management packets to allowed up the stack.\n" + "[-c, --ctrl] : Enable control packets to be allowed up the stack.\n" + "[-d, --data] : Enable Data packets to be allowed up the stack.\n" + "[-g, --get] : Get current filter settings for a specific interface index.\n" "[-b, --capture-len ] : Capture length buffer size for each packet to be captured\n" - "[-h, --help] : Help\n" + "[-h, --help] : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" - "wifi packet_filter -i1 -md.\n", + "wifi packet_filter -i1 -md\n", cmd_wifi_packet_filter, 1, 8), SHELL_CMD_ARG(channel, NULL, "wifi channel setting\n" "This command is used to set the channel when\n" - "monitor or TX-Injection mode is enabled\n" + "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" - "[-i, --if-index ] : Interface index\n" - "[-c, --channel ] : Set a specific channel number to the lower layer\n" - "[-g, --get] : Get current set channel number from the lower layer\n" - "[-h, --help] : Help\n" + "[-i, --if-index ] : Interface index.\n" + "[-c, --channel ] : Set a specific channel number to the lower layer.\n" + "[-g, --get] : Get current set channel number from the lower layer.\n" + "[-h, --help] : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" - "wifi -i1 -c5.\n", + "wifi -i1 -c5\n", cmd_wifi_channel, 1, 4), SHELL_CMD_ARG(ps_timeout, NULL, - " - PS inactivity timer(in ms).\n", + " - PS inactivity timer(in ms)", cmd_wifi_ps_timeout, 2, 0), SHELL_CMD_ARG(ps_listen_interval, NULL, - " - Listen interval in the range of <0-65535>.\n", + " - Listen interval in the range of <0-65535>", cmd_wifi_listen_interval, 2, 0), SHELL_CMD_ARG(ps_wakeup_mode, NULL, - ".\n", + "\n", cmd_wifi_ps_wakeup_mode, 2, 0), From 362be6f3bb02224b96e49088faef6dcb6b920456 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:13 +0000 Subject: [PATCH 0499/1623] Revert "[nrf fromlist] wifi: shell: Remove the unnecessary text" This reverts commit f9f9f83293267465b05927bc3756e1d22accab05. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index a983e5c18f5..890bb8f121e 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1691,6 +1691,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, 1, 2), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" + "parameters:" "[-i, --if-index ] : Interface index.\n" "[-s, --sta] : Station mode.\n" "[-m, --monitor] : Monitor mode.\n" @@ -1710,6 +1711,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "This command is used to set packet filter setting when\n" "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" + "parameters:" "[-i, --if-index ] : Interface index.\n" "[-a, --all] : Enable all packet filter modes\n" "[-m, --mgmt] : Enable management packets to allowed up the stack.\n" @@ -1728,6 +1730,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "This command is used to set the channel when\n" "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" + "parameters:" "[-i, --if-index ] : Interface index.\n" "[-c, --channel ] : Set a specific channel number to the lower layer.\n" "[-g, --get] : Get current set channel number from the lower layer.\n" From c48512bfc9bd5976192ff1b89e00a4706fa0ed09 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:13 +0000 Subject: [PATCH 0500/1623] Revert "[nrf fromlist] wifi: shell: Fix the help for reg domain" This reverts commit 6be67b3199e68acff52e8d09d231d0f4d5afec4d. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 890bb8f121e..d6d14c86bf1 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1684,7 +1684,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows", NULL), SHELL_CMD_ARG(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" - "[ISO/IEC 3166-1 alpha2]: Regulatory domain\n" + "Usage: wifi reg_domain [ISO/IEC 3166-1 alpha2] [-f]\n" "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain, From 766efac095eab69cb23efaa7cdc18dae1c3a50d4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:14 +0000 Subject: [PATCH 0501/1623] Revert "[nrf fromlist] wifi: shell: Remove the unnecessary text in scan" This reverts commit e8a952b68db6cd8d097e169a56284bf0ff42c2a0. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index d6d14c86bf1..6ef745670ab 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1669,6 +1669,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, 0), SHELL_CMD_ARG(scan, NULL, "Scan for Wi-Fi APs\n" + "OPTIONAL PARAMETERS:\n" "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active.\n" "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz.\n" "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms.\n" From 54e353e0f592f2f738106425fa3ea1e647caede8 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:14 +0000 Subject: [PATCH 0502/1623] Revert "[nrf fromlist] wifi: shell: Fix help for PS command" This reverts commit 0fc24a59c702c89f6fa04feb552d5bb1eee5e6df. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 6ef745670ab..dbec138fea0 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1657,8 +1657,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", cmd_wifi_disconnect, 1, 0), - SHELL_CMD_ARG(ps, NULL, "Configure or display Wi-Fi power save state\n" - "[on/off]\n", + SHELL_CMD_ARG(ps, NULL, "Configure Wi-F PS on/off, no arguments will dump config", cmd_wifi_ps, 1, 1), SHELL_CMD_ARG(ps_mode, From c78f0fa13b3531def8d6dbad525e300eb0407261 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:14 +0000 Subject: [PATCH 0503/1623] Revert "[nrf fromlist] wifi: shell: Fix optional arg count for connect" This reverts commit 16d86216eb95cbc5e173db576ebee9c7d72d0569. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index dbec138fea0..c3100c9ad2c 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1653,7 +1653,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_connect, - 2, 4), + 2, 5), SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", cmd_wifi_disconnect, 1, 0), From 727fd5058f91f4523877e2b771728ed55398cdbc Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:14 +0000 Subject: [PATCH 0504/1623] Revert "[nrf fromlist] wifi: shell: Fix the arg count for reg domain" This reverts commit bf821e930748f94977af135540235b76dad32ee9. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index c3100c9ad2c..3aa674e73b7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1688,7 +1688,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain, - 1, 2), + 1, 1), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" From a81a856ae7d2b088bbd0ad477f05dd7dc1cf0da3 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:15 +0000 Subject: [PATCH 0505/1623] Revert "[nrf fromtree] net: wifi_mgmt: update SSID storage type" This reverts commit feb411bac2fb151c8299e47eefa6622d2e66d504. Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi_mgmt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index d1bf5d43bfd..ab37bd4d878 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -245,7 +245,7 @@ struct wifi_scan_params { uint16_t dwell_time_passive; /** Array of SSID strings to scan. */ - const char *ssids[WIFI_MGMT_SCAN_SSID_FILT_MAX]; + char ssids[WIFI_MGMT_SCAN_SSID_FILT_MAX][WIFI_SSID_MAX_LEN + 1]; /** Specifies the maximum number of scan results to return. These results would be the * BSSIDS with the best RSSI values, in all the scanned channels. This should only be * used to limit the number of returned scan results, and cannot be counted upon to limit From 01aaa7b1f75f69eef134e1b8902f7af8d0c740ab Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:15 +0000 Subject: [PATCH 0506/1623] Revert "[nrf fromtree] net: wifi: re-add `WIFI_MGMT_FORCED_PASSIVE_SCAN`" This reverts commit 339e7dcdcf0baa5169ffda4e805ff6d688220f19. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/Kconfig | 9 --------- subsys/net/l2/wifi/wifi_mgmt.c | 9 --------- 2 files changed, 18 deletions(-) diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 134448aa57f..8fbd6aff4d6 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -39,15 +39,6 @@ config WIFI_MGMT_TWT_CHECK_IP even when it is awake intervals. Rejecting TWT setup till Wi-Fi interface has a valid IP address might be desirable in most scenarios. -config WIFI_MGMT_FORCED_PASSIVE_SCAN - bool "Force passive Wi-Fi scanning" - help - Always request a passive scan, regardless of the user supplied parameters. - This is typically used when the underlying hardware is not certified for - RF transmissions. This doesn't guarantee that passive scan will be used, - it depends on the underlying chip implementation to support and honour - scan type. - config WIFI_MGMT_SCAN_SSID_FILT_MAX int "Maximum number of SSIDs that can be specified for SSID filtering" default 1 diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index cdad7646e02..58e14ff02ff 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -327,15 +327,6 @@ static int wifi_scan(uint32_t mgmt_request, struct net_if *iface, return -ENOTSUP; } -#ifdef CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN - struct wifi_scan_params default_params = {0}; - - if (params == NULL) { - params = &default_params; - } - params->scan_type = WIFI_SCAN_TYPE_PASSIVE; -#endif /* CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN */ - return wifi_mgmt_api->scan(dev, params, scan_result_cb); } From 1b8439206b10dce2a98534b5c4302d3d7ee40e87 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:15 +0000 Subject: [PATCH 0507/1623] Revert "[nrf fromtree] net: wifi: shell: update SSID argument format" This reverts commit 88884a533d602ff2e756f5e91af60cef5fd30a14. Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi_utils.h | 6 ++--- subsys/net/l2/wifi/wifi_shell.c | 8 +++---- subsys/net/l2/wifi/wifi_utils.c | 41 +++++++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/include/zephyr/net/wifi_utils.h b/include/zephyr/net/wifi_utils.h index c9ef9979f91..4284138b6f3 100644 --- a/include/zephyr/net/wifi_utils.h +++ b/include/zephyr/net/wifi_utils.h @@ -63,15 +63,13 @@ int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map); * as a comma separated string and convert it to an array. * * @param scan_ssids_str List of SSIDs expressed as a comma separated list. - * @param ssids Pointer to an array where the SSIDs pointers are to be stored. - * @param num_ssids Maximum number of SSIDs that can be stored. + * @param ssids Pointer to an array where the parsed SSIDs are to be stored. * * @retval 0 on success. * @retval -errno value in case of failure. */ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, - const char *ssids[], - uint8_t num_ssids); + char ssids[][WIFI_SSID_MAX_LEN + 1]); /** diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 3aa674e73b7..65e99204aa7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -481,7 +481,7 @@ static int wifi_scan_args_to_params(const struct shell *sh, {"bands", required_argument, 0, 'b'}, {"dwell_time_active", required_argument, 0, 'a'}, {"dwell_time_passive", required_argument, 0, 'p'}, - {"ssid", required_argument, 0, 's'}, + {"ssids", required_argument, 0, 's'}, {"max_bss", required_argument, 0, 'm'}, {"chans", required_argument, 0, 'c'}, {"help", no_argument, 0, 'h'}, @@ -538,9 +538,7 @@ static int wifi_scan_args_to_params(const struct shell *sh, opt_num++; break; case 's': - if (wifi_utils_parse_scan_ssids(optarg, - params->ssids, - ARRAY_SIZE(params->ssids))) { + if (wifi_utils_parse_scan_ssids(optarg, params->ssids)) { shell_fprintf(sh, SHELL_ERROR, "Invalid SSID(s)\n"); return -ENOEXEC; } @@ -1673,7 +1671,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz.\n" "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms.\n" "[-p, --dwell_time_passive ] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms.\n" - "[-s, --ssid : SSID to scan for. Can be provided multiple times.\n" + "[-s, --ssids ] : SSID list to scan for.\n" "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535.\n" "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6-11,14_5:36,149-165,44\n" "[-h, --help] : Print out the help for the scan command.", diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index 52d25d90566..4c50b817d26 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -263,9 +263,12 @@ int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map) } int wifi_utils_parse_scan_ssids(char *scan_ssids_str, - const char *ssids[], - uint8_t num_ssids) + char ssids[][WIFI_SSID_MAX_LEN + 1]) { + char parse_str[(WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1)) + 1]; + char *ssid = NULL; + char *ctx = NULL; + uint8_t i = 0; int len; if (!scan_ssids_str) { @@ -273,23 +276,41 @@ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, } len = strlen(scan_ssids_str); - if (len > WIFI_SSID_MAX_LEN) { + + if (len > (WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1))) { NET_ERR("SSID string (%s) size (%d) exceeds maximum allowed value (%d)", scan_ssids_str, len, - WIFI_SSID_MAX_LEN); + (WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1))); return -EINVAL; } - for (int i = 0; i < num_ssids; i++) { - if (ssids[i] != NULL) { - continue; + strncpy(parse_str, scan_ssids_str, len); + parse_str[len] = '\0'; + + ssid = strtok_r(parse_str, ",", &ctx); + + while (ssid) { + if (strlen(ssid) > WIFI_SSID_MAX_LEN) { + NET_ERR("SSID length (%zu) exceeds maximum value (%d) for SSID %s", + strlen(ssid), + WIFI_SSID_MAX_LEN, + ssid); + return -EINVAL; + } + + if (i >= WIFI_MGMT_SCAN_SSID_FILT_MAX) { + NET_WARN("Exceeded maximum allowed (%d) SSIDs. Ignoring SSIDs %s onwards", + WIFI_MGMT_SCAN_SSID_FILT_MAX, + ssid); + break; } - ssids[i] = scan_ssids_str; - return 0; + + strcpy(&ssids[i++][0], ssid); + + ssid = strtok_r(NULL, ",", &ctx); } - NET_WARN("Exceeded maximum allowed SSIDs (%d)", num_ssids); return 0; } From fd184f89991928333d7b17be246b033ea5ea481d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:15 +0000 Subject: [PATCH 0508/1623] Revert "[nrf fromtree] net: wifi_mgmt: linearise `scan_params->chan` arrays" This reverts commit 5fa35c899d62e725fa77f74881e7465f3749fb61. Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi_mgmt.h | 18 ++++-------------- include/zephyr/net/wifi_utils.h | 4 +--- subsys/net/l2/wifi/Kconfig | 6 +++--- subsys/net/l2/wifi/wifi_shell.c | 4 +--- subsys/net/l2/wifi/wifi_utils.c | 32 ++++++++------------------------ 5 files changed, 17 insertions(+), 47 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index ab37bd4d878..81634a7fc62 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -209,16 +209,6 @@ enum net_event_wifi_cmd { #define NET_EVENT_WIFI_DISCONNECT_COMPLETE \ (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE) -/** - * @brief Wi-Fi structure to uniquely identify a band-channel pair - */ -struct wifi_band_channel { - /** Frequency band */ - uint8_t band; - /** Channel */ - uint8_t channel; -}; - /** * @brief Wi-Fi scan parameters structure. * Used to specify parameters which can control how the Wi-Fi scan @@ -258,9 +248,9 @@ struct wifi_scan_params { * band. * E.g. to scan channel 6 and 11 on the 2.4 GHz band, channel 36 on the 5 GHz band: * @code{.c} - * chan[0] = {WIFI_FREQ_BAND_2_4_GHZ, 6}; - * chan[1] = {WIFI_FREQ_BAND_2_4_GHZ, 11}; - * chan[2] = {WIFI_FREQ_BAND_5_GHZ, 36}; + * chan[WIFI_FREQ_BAND_2_4_GHZ][0] = 6; + * chan[WIFI_FREQ_BAND_2_4_GHZ][1] = 11; + * chan[WIFI_FREQ_BAND_5_GHZ][0] = 36; * @endcode * * This list specifies the channels to be __considered for scan__. The underlying @@ -268,7 +258,7 @@ struct wifi_scan_params { * not conforming to regulatory restrictions etc. The invoker of the API should * ensure that the channels specified follow regulatory rules. */ - struct wifi_band_channel band_chan[WIFI_MGMT_SCAN_CHAN_MAX_MANUAL]; + uint8_t chan[WIFI_FREQ_BAND_MAX + 1][WIFI_MGMT_SCAN_CHAN_MAX_MANUAL]; }; /** Wi-Fi scan result, each result is provided to the net_mgmt_event_callback diff --git a/include/zephyr/net/wifi_utils.h b/include/zephyr/net/wifi_utils.h index 4284138b6f3..b005d075847 100644 --- a/include/zephyr/net/wifi_utils.h +++ b/include/zephyr/net/wifi_utils.h @@ -95,14 +95,12 @@ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, * * @param scan_chan_str List of channels expressed in the format described above. * @param chan Pointer to an array where the parsed channels are to be stored. - * @param max_channels Maximum number of channels to store * * @retval 0 on success. * @retval -errno value in case of failure. */ int wifi_utils_parse_scan_chan(char *scan_chan_str, - struct wifi_band_channel *chan, - uint8_t max_channels); + uint8_t chan[][WIFI_CHANNEL_MAX]); /** * @} diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 8fbd6aff4d6..5644852c2a0 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -48,11 +48,11 @@ config WIFI_MGMT_SCAN_SSID_FILT_MAX This can be set based on the underlying chipsets limitations. config WIFI_MGMT_SCAN_CHAN_MAX_MANUAL - int "Maximum number of channels that can be manually specified" - range 1 110 + int "Maximum number of channels that can be manually specified per-band" + range 1 70 default 3 help - There are approximately 100 channels allocated across the three supported bands. + There are currently 60 channels allocated in the largest band (6GHz). The default of 3 allows the 3 most common channels (2.4GHz: 1, 6, 11) to be specified. config WIFI_NM diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 65e99204aa7..6893e20353e 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -557,9 +557,7 @@ static int wifi_scan_args_to_params(const struct shell *sh, opt_num++; break; case 'c': - if (wifi_utils_parse_scan_chan(optarg, - params->band_chan, - ARRAY_SIZE(params->band_chan))) { + if (wifi_utils_parse_scan_chan(optarg, params->chan)) { shell_fprintf(sh, SHELL_ERROR, "Invalid band or channel value(s)\n"); diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index 4c50b817d26..a77e225bfbf 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -105,7 +105,7 @@ static bool wifi_utils_validate_chan(uint8_t band, static int wifi_utils_get_all_chans_in_range(uint8_t chan_start, uint8_t chan_end, - struct wifi_band_channel *band_chan, + uint8_t chan[][WIFI_CHANNEL_MAX], uint8_t band_idx, uint8_t *chan_idx) { @@ -136,9 +136,7 @@ static int wifi_utils_get_all_chans_in_range(uint8_t chan_start, idx = *chan_idx; for (i = chan_start; i <= chan_end; i++) { - band_chan[idx].band = band_idx; - band_chan[idx].channel = i; - idx++; + chan[band_idx][idx++] = i; } *chan_idx = idx; @@ -157,9 +155,7 @@ static int wifi_utils_get_all_chans_in_range(uint8_t chan_start, } if (start) { - band_chan[idx].band = band_idx; - band_chan[idx].channel = valid_5g_chans_20mhz[i]; - idx++; + chan[band_idx][idx++] = valid_5g_chans_20mhz[i]; } if (end) { @@ -175,9 +171,7 @@ static int wifi_utils_get_all_chans_in_range(uint8_t chan_start, i = chan_start; while (i <= chan_end) { - band_chan[idx].band = band_idx; - band_chan[idx].channel = i; - idx++; + chan[band_idx][idx++] = i; if (i == 1) { i++; @@ -316,8 +310,7 @@ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, int wifi_utils_parse_scan_chan(char *scan_chan_str, - struct wifi_band_channel *band_chan, - uint8_t max_channels) + uint8_t chan[][WIFI_CHANNEL_MAX]) { char band_str[WIFI_UTILS_MAX_BAND_STR_LEN] = {0}; char chan_str[WIFI_UTILS_MAX_CHAN_STR_LEN] = {0}; @@ -356,6 +349,7 @@ int wifi_utils_parse_scan_chan(char *scan_chan_str, } i++; + chan_idx = 0; chan_str_start_idx = i; valid_band = true; @@ -389,13 +383,9 @@ int wifi_utils_parse_scan_chan(char *scan_chan_str, memset(chan_str, 0, sizeof(chan_str)); if (chan_start) { - if ((chan_idx + (chan_val - chan_start)) >= max_channels) { - NET_ERR("Too many channels specified (%d)", max_channels); - return -EINVAL; - } if (wifi_utils_get_all_chans_in_range(chan_start, chan_val, - band_chan, + chan, band, &chan_idx)) { NET_ERR("Channel range invalid"); @@ -409,14 +399,8 @@ int wifi_utils_parse_scan_chan(char *scan_chan_str, NET_ERR("Invalid channel %d", chan_val); return -EINVAL; } - if (chan_idx == max_channels) { - NET_ERR("Too many channels specified (%d)", max_channels); - return -EINVAL; - } - band_chan[chan_idx].band = band; - band_chan[chan_idx].channel = chan_val; - chan_idx++; + chan[band][chan_idx++] = chan_val; } valid_chan = true; From 49dcc6d44359a50364b87e212a51ceab8adbc12b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:16 +0000 Subject: [PATCH 0509/1623] Revert "[nrf fromtree] net: wifi_mgmt: make number of scan channels configurable" This reverts commit 8efaa1633aa03d4444be79b7b029a28c13362a02. Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi_mgmt.h | 8 +------- subsys/net/l2/wifi/Kconfig | 8 -------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 81634a7fc62..67a603aea95 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -41,12 +41,6 @@ extern "C" { #define WIFI_MGMT_SCAN_SSID_FILT_MAX 0 #endif /* CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX */ -#ifdef CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL -#define WIFI_MGMT_SCAN_CHAN_MAX_MANUAL CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL -#else -#define WIFI_MGMT_SCAN_CHAN_MAX_MANUAL 1 -#endif /* CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL */ - #define WIFI_MGMT_BAND_STR_SIZE_MAX 8 /** Wi-Fi management commands */ @@ -258,7 +252,7 @@ struct wifi_scan_params { * not conforming to regulatory restrictions etc. The invoker of the API should * ensure that the channels specified follow regulatory rules. */ - uint8_t chan[WIFI_FREQ_BAND_MAX + 1][WIFI_MGMT_SCAN_CHAN_MAX_MANUAL]; + uint8_t chan[WIFI_FREQ_BAND_MAX + 1][WIFI_CHANNEL_MAX]; }; /** Wi-Fi scan result, each result is provided to the net_mgmt_event_callback diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 5644852c2a0..ccf5ce31ca6 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -47,14 +47,6 @@ config WIFI_MGMT_SCAN_SSID_FILT_MAX Maximum number of SSIDs that can be specified for SSID filtering. This can be set based on the underlying chipsets limitations. -config WIFI_MGMT_SCAN_CHAN_MAX_MANUAL - int "Maximum number of channels that can be manually specified per-band" - range 1 70 - default 3 - help - There are currently 60 channels allocated in the largest band (6GHz). - The default of 3 allows the 3 most common channels (2.4GHz: 1, 6, 11) to be specified. - config WIFI_NM bool "Wi-Fi Network manager support" help From d7b10883a96e64bfcd9035f89598328d71739ab8 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:16 +0000 Subject: [PATCH 0510/1623] Revert "[nrf fromtree] net: l2: wifi_mgmt: remove scan kconfig defaults" This reverts commit f76c35a823c2b4909f2306c074267a57f9fff864. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/Kconfig | 67 ++++++++++++++++++++++++++++++++++ subsys/net/l2/wifi/wifi_mgmt.c | 55 ++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index ccf5ce31ca6..6623456d84b 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -39,6 +39,40 @@ config WIFI_MGMT_TWT_CHECK_IP even when it is awake intervals. Rejecting TWT setup till Wi-Fi interface has a valid IP address might be desirable in most scenarios. +config WIFI_MGMT_FORCED_PASSIVE_SCAN + bool "Force Passive scan" + help + Force passive scan (typically used to reduce power consumption), + the scan type is always sent as passive. + This doesn't guarantee that passive scan will be used, it depends + on the underlying chip implementation to support and honour scan type. + +config WIFI_MGMT_SCAN_BANDS + string "Frequency bands to scan" + default "" + help + Specifies the frequency bands to scan, as follows: + 2 - 2.4 GHz + 5 - 5 GHz + 6 - 6 GHz + "" - All bands allowed by the regulatory domain. + Multiple bands can be specified as comma separated band values. + Only regulatory domain permitted values are allowed. + +config WIFI_MGMT_SCAN_DWELL_TIME_ACTIVE + int "Active scan dwell time" + default 50 + range 5 1000 + help + Active scan dwell time (in ms) per channel. + +config WIFI_MGMT_SCAN_DWELL_TIME_PASSIVE + int "Passive scan dwell time" + default 130 + range 10 1000 + help + Passive scan dwell time (in ms) per channel. + config WIFI_MGMT_SCAN_SSID_FILT_MAX int "Maximum number of SSIDs that can be specified for SSID filtering" default 1 @@ -47,6 +81,39 @@ config WIFI_MGMT_SCAN_SSID_FILT_MAX Maximum number of SSIDs that can be specified for SSID filtering. This can be set based on the underlying chipsets limitations. +config WIFI_MGMT_SCAN_SSID_FILT + string "Scan for specific SSIDs" + default "" + help + String of comma separated SSID values to scan for. The number of SSID’s + that can be specified depends on WIFI_MGMT_SCAN_MAX_SSIDS. + Use "" to disable SSID filtering. + +config WIFI_MGMT_SCAN_MAX_BSS_CNT + int "Maximum number of scan results to return." + default 0 + range 0 65535 + help + Maximum number of scan results to return. 0 represents unlimited number of BSSes. + +config WIFI_MGMT_SCAN_CHAN + string "Scan on specific channels" + default "" + help + Formatted string which specifies channels to be scanned. The channel string has to be formatted + using the colon (:), comma(,), hyphen (-) and space ( ) delimiters as follows: + - A colon identifies the value preceding it as a band. A band value + (2: 2.4 GHz, 5: 5 GHz 6: 6 GHz) has to precede the channels in that band (e.g. 2: etc) + - Hyphens are used to identify channel ranges (e.g. 2-7, 32-48 etc) + - Commas are used to separate channel values within a band. Channels can be specified + as individual values (2,6,48 etc) or channel ranges using hyphens (1-14, 32-48 etc) + - Spaces are used to specify multiple band-channel sets (e.g. 2:1,2 5:36,40 etc) + - No spaces should be used anywhere else, i.e. before/after commas, + before/after hyphens. + An example channel specification specifying channels in the 2.4 GHz and 5 GHz bands is + as below: + 2:1,5,7,9-11_5:36-48,100,163-167 + config WIFI_NM bool "Wi-Fi Network manager support" help diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 58e14ff02ff..0751f5d2b8c 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -13,6 +13,7 @@ LOG_MODULE_REGISTER(net_wifi_mgmt, CONFIG_NET_L2_WIFI_MGMT_LOG_LEVEL); #include #include #include +#include #ifdef CONFIG_WIFI_NM #include #endif /* CONFIG_WIFI_NM */ @@ -322,11 +323,65 @@ static int wifi_scan(uint32_t mgmt_request, struct net_if *iface, const struct device *dev = net_if_get_device(iface); struct wifi_scan_params *params = data; const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); + bool chan_specified = false; + uint8_t i = 0; if (wifi_mgmt_api == NULL || wifi_mgmt_api->scan == NULL) { return -ENOTSUP; } + if (data && (len == sizeof(*params))) { +#ifdef CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN + params->scan_type = WIFI_SCAN_TYPE_PASSIVE; +#endif /* CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN */ + + if (!params->bands) { + if (wifi_utils_parse_scan_bands(CONFIG_WIFI_MGMT_SCAN_BANDS, + ¶ms->bands)) { + NET_ERR("Incorrect value(s) in CONFIG_WIFI_MGMT_SCAN_BANDS: %s", + CONFIG_WIFI_MGMT_SCAN_BANDS); + return -EINVAL; + } + } + + if (!params->dwell_time_active) { + params->dwell_time_active = CONFIG_WIFI_MGMT_SCAN_DWELL_TIME_ACTIVE; + } + + if (!params->dwell_time_passive) { + params->dwell_time_passive = CONFIG_WIFI_MGMT_SCAN_DWELL_TIME_PASSIVE; + } + + if (!strlen(params->ssids[0])) { + if (wifi_utils_parse_scan_ssids(CONFIG_WIFI_MGMT_SCAN_SSID_FILT, + params->ssids)) { + NET_ERR("Incorrect value(s) in CONFIG_WIFI_MGMT_SCAN_SSID_FILT: %s", + CONFIG_WIFI_MGMT_SCAN_SSID_FILT); + return -EINVAL; + } + } + + if (!params->max_bss_cnt) { + params->max_bss_cnt = CONFIG_WIFI_MGMT_SCAN_MAX_BSS_CNT; + } + + for (i = 0; i <= WIFI_FREQ_BAND_MAX; i++) { + if (params->chan[i][0]) { + chan_specified = true; + break; + } + } + + if ((!chan_specified) && strlen(CONFIG_WIFI_MGMT_SCAN_CHAN)) { + if (wifi_utils_parse_scan_chan(CONFIG_WIFI_MGMT_SCAN_CHAN, + params->chan)) { + NET_ERR("Incorrect value(s) in CONFIG_WIFI_MGMT_SCAN_CHAN: %s", + CONFIG_WIFI_MGMT_SCAN_CHAN); + return -EINVAL; + } + } + } + return wifi_mgmt_api->scan(dev, params, scan_result_cb); } From 017a98a048f0c11375983d8fda55dc194b307595 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:16 +0000 Subject: [PATCH 0511/1623] Revert "[nrf fromtree] net: wifi_mgmt: change type of `wifi_scan_params->chan`" This reverts commit 52ce713e771e3c8c9a64c47d52b25825c5c627d8. Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi_mgmt.h | 2 +- include/zephyr/net/wifi_utils.h | 2 +- subsys/net/l2/wifi/wifi_utils.c | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 67a603aea95..1be98b927cb 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -252,7 +252,7 @@ struct wifi_scan_params { * not conforming to regulatory restrictions etc. The invoker of the API should * ensure that the channels specified follow regulatory rules. */ - uint8_t chan[WIFI_FREQ_BAND_MAX + 1][WIFI_CHANNEL_MAX]; + uint16_t chan[WIFI_FREQ_BAND_MAX + 1][WIFI_CHANNEL_MAX]; }; /** Wi-Fi scan result, each result is provided to the net_mgmt_event_callback diff --git a/include/zephyr/net/wifi_utils.h b/include/zephyr/net/wifi_utils.h index b005d075847..86b39ff4660 100644 --- a/include/zephyr/net/wifi_utils.h +++ b/include/zephyr/net/wifi_utils.h @@ -100,7 +100,7 @@ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, * @retval -errno value in case of failure. */ int wifi_utils_parse_scan_chan(char *scan_chan_str, - uint8_t chan[][WIFI_CHANNEL_MAX]); + uint16_t chan[][WIFI_CHANNEL_MAX]); /** * @} diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index a77e225bfbf..ea0e42def47 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -103,13 +103,13 @@ static bool wifi_utils_validate_chan(uint8_t band, } -static int wifi_utils_get_all_chans_in_range(uint8_t chan_start, - uint8_t chan_end, - uint8_t chan[][WIFI_CHANNEL_MAX], +static int wifi_utils_get_all_chans_in_range(uint16_t chan_start, + uint16_t chan_end, + uint16_t chan[][WIFI_CHANNEL_MAX], uint8_t band_idx, uint8_t *chan_idx) { - uint8_t i; + uint16_t i; bool start = false; bool end = false; uint8_t idx; @@ -310,7 +310,7 @@ int wifi_utils_parse_scan_ssids(char *scan_ssids_str, int wifi_utils_parse_scan_chan(char *scan_chan_str, - uint8_t chan[][WIFI_CHANNEL_MAX]) + uint16_t chan[][WIFI_CHANNEL_MAX]) { char band_str[WIFI_UTILS_MAX_BAND_STR_LEN] = {0}; char chan_str[WIFI_UTILS_MAX_CHAN_STR_LEN] = {0}; @@ -318,8 +318,8 @@ int wifi_utils_parse_scan_chan(char *scan_chan_str, uint16_t band_str_start_idx = 0; uint16_t chan_str_start_idx = 0; uint8_t chan_idx = 0; - uint8_t chan_start = 0; - uint8_t chan_val = 0; + uint16_t chan_start = 0; + uint16_t chan_val = 0; uint16_t i = 0; bool valid_band = false; bool valid_chan = false; From a7414fa918493c3fbe06c9715d0f1435198e6734 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:16 +0000 Subject: [PATCH 0512/1623] Revert "[nrf fromlist] wifi: shell: Fix arg count for regulatory domain" This reverts commit 426213023e08965311421143ca3abe2ec25b39a4. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 6893e20353e..e1f225bd4e8 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1684,7 +1684,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain, - 1, 1), + 2, 1), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" From a474929bf203cb00b7acb7d5e8a30b9d4fa9971d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:17 +0000 Subject: [PATCH 0513/1623] Revert "[nrf fromtree] wifi: shell: Display RSSI only for station mode" This reverts commit b65e77cdb79c3deb22395874d3079f850a6dffd0. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index e1f225bd4e8..658dadce6fd 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -656,9 +656,7 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[]) wifi_security_txt(status.security)); shell_fprintf(sh, SHELL_NORMAL, "MFP: %s\n", wifi_mfp_txt(status.mfp)); - if (status.iface_mode == WIFI_MODE_INFRA) { - shell_fprintf(sh, SHELL_NORMAL, "RSSI: %d\n", status.rssi); - } + shell_fprintf(sh, SHELL_NORMAL, "RSSI: %d\n", status.rssi); shell_fprintf(sh, SHELL_NORMAL, "Beacon Interval: %d\n", status.beacon_interval); shell_fprintf(sh, SHELL_NORMAL, "DTIM: %d\n", status.dtim_period); shell_fprintf(sh, SHELL_NORMAL, "TWT: %s\n", From 8ea2f1f6e2b07a5484fc557fb1dc25b02b329b73 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:17 +0000 Subject: [PATCH 0514/1623] Revert "[nrf fromtree] wifi: shell: Fix AP argument checks and help" This reverts commit 85a25485d25f7da05e0d6c707b326a487b3a9e6b. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 658dadce6fd..90dbd1588f7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1598,16 +1598,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, "Disable Access Point mode", cmd_wifi_ap_disable, 1, 0), - SHELL_CMD_ARG(enable, NULL, - "\"\"\n" - "[channel number: 0 means all]\n" - "[PSK: valid only for secure SSIDs]\n" - "[Security type: valid only for secure SSIDs]\n" - "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" - "[MFP (optional: needs security type to be specified)]\n" - ": 0:Disable, 1:Optional, 2:Required", + SHELL_CMD_ARG(enable, NULL, " [channel] [PSK]", cmd_wifi_ap_enable, - 2, 4), + 2, 1), SHELL_SUBCMD_SET_END ); From 35ac56899a427ba128c04075f774d9888975e69d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:17 +0000 Subject: [PATCH 0515/1623] Revert "[nrf fromtree] drivers: nrf_qspi_nor: Fix and refactor driver initialization" This reverts commit 86146714949810fd451dace302bd42ea4ecb3927. Signed-off-by: Dominik Ermel --- drivers/flash/nrf_qspi_nor.c | 125 ++++++++++++++++++++++------------- 1 file changed, 80 insertions(+), 45 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index ac055229710..ae990a5d68e 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -599,10 +599,41 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) return rc != 0 ? rc : rc2; } -static int configure_chip(const struct device *dev) +/* Configures QSPI memory for the transfer */ +static int qspi_nrfx_configure(const struct device *dev) { + struct qspi_nor_data *dev_data = dev->data; const struct qspi_nor_config *dev_config = dev->config; - int rc = 0; + nrfx_err_t res; + int rc; + + res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); + rc = qspi_get_zephyr_ret_code(res); + if (rc < 0) { + return rc; + } + +#if DT_INST_NODE_HAS_PROP(0, rx_delay) + if (!nrf53_errata_121()) { + nrf_qspi_iftiming_set(NRF_QSPI, DT_INST_PROP(0, rx_delay)); + } +#endif + + /* It may happen that after the flash chip was previously put into + * the DPD mode, the system was reset but the flash chip was not. + * Consequently, the flash chip can be in the DPD mode at this point. + * Some flash chips will just exit the DPD mode on the first CS pulse, + * but some need to receive the dedicated command to do it, so send it. + * This can be the case even if the current image does not have + * CONFIG_PM_DEVICE set to enter DPD mode, as a previously executing image + * (for example the main image if the currently executing image is the + * bootloader) might have set DPD mode before reboot. As a result, + * attempt to exit DPD mode regardless of whether CONFIG_PM_DEVICE is set. + */ + rc = exit_dpd(dev); + if (rc < 0) { + return rc; + } /* Set QE to match transfer mode. If not using quad * it's OK to leave QE set, but doing so prevents use @@ -753,6 +784,33 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, #endif /* CONFIG_FLASH_JESD216_API */ +/** + * @brief Retrieve the Flash JEDEC ID and compare it with the one expected + * + * @param dev The device structure + * @return 0 on success, negative errno code otherwise + */ +static inline int qspi_nor_read_id(const struct device *dev) +{ + uint8_t id[SPI_NOR_MAX_ID_LEN]; + int rc = qspi_rdid(dev, id); + + if (rc != 0) { + return -EIO; + } + + const struct qspi_nor_config *qnc = dev->config; + + if (memcmp(qnc->id, id, SPI_NOR_MAX_ID_LEN) != 0) { + LOG_ERR("JEDEC id [%02x %02x %02x] expect [%02x %02x %02x]", + id[0], id[1], id[2], + qnc->id[0], qnc->id[1], qnc->id[2]); + return -ENODEV; + } + + return 0; +} + static inline nrfx_err_t read_non_aligned(const struct device *dev, off_t addr, void *dest, size_t size) @@ -1019,58 +1077,35 @@ static int qspi_nor_write_protection_set(const struct device *dev, return rc; } -static int qspi_init(const struct device *dev) +/** + * @brief Configure the flash + * + * @param dev The flash device structure + * @param info The flash info structure + * @return 0 on success, negative errno code otherwise + */ +static int qspi_nor_configure(const struct device *dev) { - const struct qspi_nor_config *dev_config = dev->config; - uint8_t id[SPI_NOR_MAX_ID_LEN]; - nrfx_err_t res; - int rc; - - res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev->data); - rc = qspi_get_zephyr_ret_code(res); - if (rc < 0) { - return rc; - } - -#if DT_INST_NODE_HAS_PROP(0, rx_delay) - if (!nrf53_errata_121()) { - nrf_qspi_iftiming_set(NRF_QSPI, DT_INST_PROP(0, rx_delay)); - } -#endif - - /* It may happen that after the flash chip was previously put into - * the DPD mode, the system was reset but the flash chip was not. - * Consequently, the flash chip can be in the DPD mode at this point. - * Some flash chips will just exit the DPD mode on the first CS pulse, - * but some need to receive the dedicated command to do it, so send it. - * This can be the case even if the current image does not have - * CONFIG_PM_DEVICE set to enter DPD mode, as a previously executing image - * (for example the main image if the currently executing image is the - * bootloader) might have set DPD mode before reboot. As a result, - * attempt to exit DPD mode regardless of whether CONFIG_PM_DEVICE is set. - */ - rc = exit_dpd(dev); - if (rc < 0) { - return rc; - } + int rc = qspi_nrfx_configure(dev); - /* Retrieve the Flash JEDEC ID and compare it with the one expected. */ - rc = qspi_rdid(dev, id); - if (rc < 0) { + if (rc != 0) { return rc; } - if (memcmp(dev_config->id, id, SPI_NOR_MAX_ID_LEN) != 0) { - LOG_ERR("JEDEC id [%02x %02x %02x] expect [%02x %02x %02x]", - id[0], id[1], id[2], dev_config->id[0], - dev_config->id[1], dev_config->id[2]); + /* now the spi bus is configured, we can verify the flash id */ + if (qspi_nor_read_id(dev) != 0) { return -ENODEV; } - /* The chip is correct, it can be configured now. */ - return configure_chip(dev); + return 0; } +/** + * @brief Initialize and configure the flash + * + * @param name The flash name + * @return 0 on success, negative errno code otherwise + */ static int qspi_nor_init(const struct device *dev) { const struct qspi_nor_config *dev_config = dev->config; @@ -1086,7 +1121,7 @@ static int qspi_nor_init(const struct device *dev) qspi_clock_div_change(); - rc = qspi_init(dev); + rc = qspi_nor_configure(dev); qspi_clock_div_restore(); From 9b3db0eb21158328f4477b35fccd7b47bde0ecd0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:18 +0000 Subject: [PATCH 0516/1623] Revert "[nrf fromtree] drivers: nrf_qspi_nor: Refactor deactivation and locking access to QSPI" This reverts commit 9a0aca0df38a10f19296c26fe6df9bc5b5b52c29. Signed-off-by: Dominik Ermel --- drivers/flash/nrf_qspi_nor.c | 507 ++++++++++++++++++++++------------- 1 file changed, 314 insertions(+), 193 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index ae990a5d68e..653f8b38f4e 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -26,15 +26,15 @@ LOG_MODULE_REGISTER(qspi_nor, CONFIG_FLASH_LOG_LEVEL); #include struct qspi_nor_data { -#if !defined(CONFIG_PM_DEVICE_RUNTIME) && defined(CONFIG_MULTITHREADING) - /* A semaphore to control QSPI deactivation. */ - struct k_sem count; -#endif #ifdef CONFIG_MULTITHREADING + /* The semaphore to control exclusive access on write/erase. */ + struct k_sem trans; /* The semaphore to control exclusive access to the device. */ struct k_sem sem; /* The semaphore to indicate that transfer has completed. */ struct k_sem sync; + /* The semaphore to control driver init/uninit. */ + struct k_sem count; #else /* CONFIG_MULTITHREADING */ /* A flag that signals completed transfer when threads are * not enabled. @@ -173,6 +173,12 @@ BUILD_ASSERT(DT_INST_PROP(0, address_size_32), "After entering 4 byte addressing mode, 4 byte addressing is expected"); #endif +#ifndef CONFIG_PM_DEVICE_RUNTIME +static bool qspi_initialized; +#endif + +static int qspi_device_init(const struct device *dev); +static void qspi_device_uninit(const struct device *dev); void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable); void z_vrfy_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable); @@ -239,99 +245,72 @@ static inline int qspi_get_zephyr_ret_code(nrfx_err_t res) static inline void qspi_lock(const struct device *dev) { -#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; + pm_device_busy_set(dev); + +#ifdef CONFIG_MULTITHREADING k_sem_take(&dev_data->sem, K_FOREVER); +#else /* CONFIG_MULTITHREADING */ + ARG_UNUSED(dev_data); +#endif /* CONFIG_MULTITHREADING */ + + /* + * Change the base clock divider only for the time the driver is locked + * to perform a QSPI operation, otherwise the power consumption would be + * increased also when the QSPI peripheral is idle. + * When XIP is enabled, there is nothing to do here as the changed + * divider is kept all the time. + */ +#if defined(CONFIG_SOC_SERIES_NRF53X) + if (!dev_data->xip_enabled) { + nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); + } #endif } static inline void qspi_unlock(const struct device *dev) { -#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; - k_sem_give(&dev_data->sem); -#endif -} - -static inline void qspi_clock_div_change(void) -{ -#ifdef CONFIG_SOC_SERIES_NRF53X - /* Make sure the base clock divider is changed accordingly - * before a QSPI transfer is performed. +#if defined(CONFIG_SOC_SERIES_NRF53X) + /* Restore the default base clock divider to reduce power consumption. + * Unless XIP is enabled, then the changed divider needs to be kept. */ - nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); + if (!dev_data->xip_enabled) { + nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); + } #endif -} -static inline void qspi_clock_div_restore(void) -{ -#ifdef CONFIG_SOC_SERIES_NRF53X - /* Restore the default base clock divider to reduce power - * consumption when the QSPI peripheral is idle. - */ - nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); +#ifdef CONFIG_MULTITHREADING + k_sem_give(&dev_data->sem); +#else + ARG_UNUSED(dev_data); #endif + + pm_device_busy_clear(dev); } -static void qspi_acquire(const struct device *dev) +static inline void qspi_trans_lock(const struct device *dev) { +#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; -#if defined(CONFIG_PM_DEVICE_RUNTIME) - int rc = pm_device_runtime_get(dev); - - if (rc < 0) { - LOG_ERR("pm_device_runtime_get failed: %d", rc); - } -#elif defined(CONFIG_MULTITHREADING) - /* In multithreading, the driver can call qspi_acquire more than once - * before calling qspi_release. Keeping count, so QSPI is deactivated - * only at the last call (count == 0). - */ - k_sem_give(&dev_data->count); -#endif - - qspi_lock(dev); - - if (!dev_data->xip_enabled) { - qspi_clock_div_change(); - - pm_device_busy_set(dev); - } + k_sem_take(&dev_data->trans, K_FOREVER); +#else /* CONFIG_MULTITHREADING */ + ARG_UNUSED(dev); +#endif /* CONFIG_MULTITHREADING */ } -static void qspi_release(const struct device *dev) +static inline void qspi_trans_unlock(const struct device *dev) { +#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; - bool deactivate = true; -#if !defined(CONFIG_PM_DEVICE_RUNTIME) && defined(CONFIG_MULTITHREADING) - /* The last thread to finish using the driver deactivates the QSPI */ - (void) k_sem_take(&dev_data->count, K_NO_WAIT); - deactivate = (k_sem_count_get(&dev_data->count) == 0); -#endif - - if (!dev_data->xip_enabled) { - qspi_clock_div_restore(); - - if (deactivate && !IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { - (void) nrfx_qspi_deactivate(); - } - - pm_device_busy_clear(dev); - } - - qspi_unlock(dev); - -#if defined(CONFIG_PM_DEVICE_RUNTIME) - int rc = pm_device_runtime_put(dev); - - if (rc < 0) { - LOG_ERR("pm_device_runtime_put failed: %d", rc); - } -#endif + k_sem_give(&dev_data->trans); +#else /* CONFIG_MULTITHREADING */ + ARG_UNUSED(dev); +#endif /* CONFIG_MULTITHREADING */ } static inline void qspi_wait_for_completion(const struct device *dev, @@ -380,6 +359,89 @@ static void qspi_handler(nrfx_qspi_evt_t event, void *p_context) } } +static int qspi_device_init(const struct device *dev) +{ + struct qspi_nor_data *dev_data = dev->data; + + if (dev_data->xip_enabled) { + return 0; + } + +#ifdef CONFIG_PM_DEVICE_RUNTIME + return pm_device_runtime_get(dev); +#else + nrfx_err_t res; + int rc = 0; + + qspi_lock(dev); + + /* In multithreading, driver can call qspi_device_init more than once + * before calling qspi_device_uninit. Keepping count, so QSPI is + * uninitialized only at the last call (count == 0). + */ +#ifdef CONFIG_MULTITHREADING + k_sem_give(&dev_data->count); +#endif + + if (!qspi_initialized) { + const struct qspi_nor_config *dev_config = dev->config; + + res = nrfx_qspi_init(&dev_config->nrfx_cfg, + qspi_handler, + dev_data); + rc = qspi_get_zephyr_ret_code(res); + qspi_initialized = (rc == 0); + } + + qspi_unlock(dev); + + return rc; +#endif +} + +static void qspi_device_uninit(const struct device *dev) +{ + struct qspi_nor_data *dev_data = dev->data; + + if (dev_data->xip_enabled) { + return; + } + +#ifdef CONFIG_PM_DEVICE_RUNTIME + int rc = pm_device_runtime_put(dev); + + if (rc < 0) { + LOG_ERR("Failed to schedule device sleep: %d", rc); + } +#else + bool last = true; + + qspi_lock(dev); + +#ifdef CONFIG_MULTITHREADING + /* The last thread to finish using the driver uninit the QSPI */ + (void) k_sem_take(&dev_data->count, K_NO_WAIT); + last = (k_sem_count_get(&dev_data->count) == 0); +#endif + + if (last) { + while (nrfx_qspi_mem_busy_check() != NRFX_SUCCESS) { + if (IS_ENABLED(CONFIG_MULTITHREADING)) { + k_msleep(50); + } else { + k_busy_wait(50000); + } + } + + nrfx_qspi_uninit(); + + qspi_initialized = false; + } + + qspi_unlock(dev); +#endif +} + /* QSPI send custom command. * * If this is used for both send and receive the buffer sizes must be @@ -435,8 +497,11 @@ static int qspi_send_cmd(const struct device *dev, const struct qspi_cmd *cmd, .wren = wren, }; + qspi_lock(dev); + int res = nrfx_qspi_cinstr_xfer(&cinstr_cfg, tx_buf, rx_buf); + qspi_unlock(dev); return qspi_get_zephyr_ret_code(res); } @@ -552,13 +617,29 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) /* QSPI erase */ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) { + /* address must be sector-aligned */ + if ((addr % QSPI_SECTOR_SIZE) != 0) { + return -EINVAL; + } + + /* size must be a non-zero multiple of sectors */ + if ((size == 0) || (size % QSPI_SECTOR_SIZE) != 0) { + return -EINVAL; + } + const struct qspi_nor_config *params = dev->config; int rc, rc2; + rc = qspi_device_init(dev); + if (rc != 0) { + goto out; + } + qspi_trans_lock(dev); rc = qspi_nor_write_protection_set(dev, false); if (rc != 0) { - return rc; + goto out_trans_unlock; } + qspi_lock(dev); while (size > 0) { nrfx_err_t res = !NRFX_SUCCESS; uint32_t adj = 0; @@ -593,10 +674,20 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) break; } } + qspi_unlock(dev); rc2 = qspi_nor_write_protection_set(dev, true); - return rc != 0 ? rc : rc2; + if (!rc) { + rc = rc2; + } + +out_trans_unlock: + qspi_trans_unlock(dev); + +out: + qspi_device_uninit(dev); + return rc; } /* Configures QSPI memory for the transfer */ @@ -607,7 +698,22 @@ static int qspi_nrfx_configure(const struct device *dev) nrfx_err_t res; int rc; +#if defined(CONFIG_SOC_SERIES_NRF53X) + /* When the QSPI peripheral is activated, during the nrfx_qspi driver + * initialization, it reads the status of the connected flash chip. + * Make sure this transaction is performed with a valid base clock + * divider. + */ + nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); +#endif + res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); + +#if defined(CONFIG_SOC_SERIES_NRF53X) + /* Restore the default /4 divider after the QSPI initialization. */ + nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); +#endif + rc = qspi_get_zephyr_ret_code(res); if (rc < 0) { return rc; @@ -708,7 +814,8 @@ static int qspi_nrfx_configure(const struct device *dev) return rc; } -static int qspi_rdid(const struct device *dev, uint8_t *id) +static int qspi_read_jedec_id(const struct device *dev, + uint8_t *id) { const struct qspi_buf rx_buf = { .buf = id, @@ -719,24 +826,18 @@ static int qspi_rdid(const struct device *dev, uint8_t *id) .rx_buf = &rx_buf, }; - return qspi_send_cmd(dev, &cmd, false); -} - -#if defined(CONFIG_FLASH_JESD216_API) + int rc = qspi_device_init(dev); -static int qspi_read_jedec_id(const struct device *dev, uint8_t *id) -{ - int rc; - - qspi_acquire(dev); - - rc = qspi_rdid(dev, id); - - qspi_release(dev); + if (rc == 0) { + rc = qspi_send_cmd(dev, &cmd, false); + } + qspi_device_uninit(dev); return rc; } +#if defined(CONFIG_FLASH_JESD216_API) + static int qspi_sfdp_read(const struct device *dev, off_t offset, void *data, size_t len) { @@ -754,10 +855,17 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, .io2_level = true, .io3_level = true, }; - nrfx_err_t res; - qspi_acquire(dev); + int rc = qspi_device_init(dev); + nrfx_err_t res = NRFX_SUCCESS; + + if (rc != 0) { + LOG_DBG("qspi_device_init: %d", rc); + qspi_device_uninit(dev); + return rc; + } + qspi_lock(dev); res = nrfx_qspi_lfm_start(&cinstr_cfg); if (res != NRFX_SUCCESS) { LOG_DBG("lfm_start: %x", res); @@ -777,8 +885,8 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, } out: - qspi_release(dev); - + qspi_unlock(dev); + qspi_device_uninit(dev); return qspi_get_zephyr_ret_code(res); } @@ -793,7 +901,7 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, static inline int qspi_nor_read_id(const struct device *dev) { uint8_t id[SPI_NOR_MAX_ID_LEN]; - int rc = qspi_rdid(dev, id); + int rc = qspi_read_jedec_id(dev, id); if (rc != 0) { return -EIO; @@ -885,9 +993,6 @@ static inline nrfx_err_t read_non_aligned(const struct device *dev, static int qspi_nor_read(const struct device *dev, off_t addr, void *dest, size_t size) { - const struct qspi_nor_config *params = dev->config; - nrfx_err_t res; - if (!dest) { return -EINVAL; } @@ -897,6 +1002,8 @@ static int qspi_nor_read(const struct device *dev, off_t addr, void *dest, return 0; } + const struct qspi_nor_config *params = dev->config; + /* affected region should be within device */ if (addr < 0 || (addr + size) > params->size) { @@ -906,13 +1013,23 @@ static int qspi_nor_read(const struct device *dev, off_t addr, void *dest, return -EINVAL; } - qspi_acquire(dev); + int rc = qspi_device_init(dev); + + if (rc != 0) { + goto out; + } - res = read_non_aligned(dev, addr, dest, size); + qspi_lock(dev); - qspi_release(dev); + nrfx_err_t res = read_non_aligned(dev, addr, dest, size); - return qspi_get_zephyr_ret_code(res); + qspi_unlock(dev); + + rc = qspi_get_zephyr_ret_code(res); + +out: + qspi_device_uninit(dev); + return rc; } /* addr aligned, sptr not null, slen less than 4 */ @@ -977,9 +1094,6 @@ static int qspi_nor_write(const struct device *dev, off_t addr, const void *src, size_t size) { - const struct qspi_nor_config *params = dev->config; - int rc, rc2; - if (!src) { return -EINVAL; } @@ -994,6 +1108,9 @@ static int qspi_nor_write(const struct device *dev, off_t addr, return -EINVAL; } + const struct qspi_nor_config *params = dev->config; + int rc, rc2; + /* affected region should be within device */ if (addr < 0 || (addr + size) > params->size) { @@ -1003,9 +1120,15 @@ static int qspi_nor_write(const struct device *dev, off_t addr, return -EINVAL; } - qspi_acquire(dev); + rc = qspi_device_init(dev); + if (rc != 0) { + goto out; + } + + qspi_trans_lock(dev); rc = qspi_nor_write_protection_set(dev, false); + qspi_lock(dev); if (rc == 0) { nrfx_err_t res; @@ -1021,28 +1144,23 @@ static int qspi_nor_write(const struct device *dev, off_t addr, rc = qspi_get_zephyr_ret_code(res); } + qspi_unlock(dev); rc2 = qspi_nor_write_protection_set(dev, true); - qspi_release(dev); + qspi_trans_unlock(dev); + if (rc == 0) { + rc = rc2; + } - return rc != 0 ? rc : rc2; +out: + qspi_device_uninit(dev); + return rc; } static int qspi_nor_erase(const struct device *dev, off_t addr, size_t size) { const struct qspi_nor_config *params = dev->config; - int rc; - - /* address must be sector-aligned */ - if ((addr % QSPI_SECTOR_SIZE) != 0) { - return -EINVAL; - } - - /* size must be a non-zero multiple of sectors */ - if ((size == 0) || (size % QSPI_SECTOR_SIZE) != 0) { - return -EINVAL; - } /* affected region should be within device */ if (addr < 0 || @@ -1053,11 +1171,7 @@ static int qspi_nor_erase(const struct device *dev, off_t addr, size_t size) return -EINVAL; } - qspi_acquire(dev); - - rc = qspi_erase(dev, addr, size); - - qspi_release(dev); + int rc = qspi_erase(dev, addr, size); return rc; } @@ -1092,6 +1206,17 @@ static int qspi_nor_configure(const struct device *dev) return rc; } +#ifdef CONFIG_PM_DEVICE_RUNTIME + rc = pm_device_runtime_enable(dev); + if (rc < 0) { + LOG_ERR("Failed to enable runtime power management: %d", rc); + } else { + LOG_DBG("Runtime power management enabled"); + } +#else + qspi_device_uninit(dev); +#endif + /* now the spi bus is configured, we can verify the flash id */ if (qspi_nor_read_id(dev) != 0) { return -ENODEV; @@ -1119,24 +1244,10 @@ static int qspi_nor_init(const struct device *dev) IRQ_CONNECT(DT_IRQN(QSPI_NODE), DT_IRQ(QSPI_NODE, priority), nrfx_isr, nrfx_qspi_irq_handler, 0); - qspi_clock_div_change(); - rc = qspi_nor_configure(dev); - qspi_clock_div_restore(); - -#ifdef CONFIG_PM_DEVICE_RUNTIME - int rc2 = pm_device_runtime_enable(dev); - - if (rc2 < 0) { - LOG_ERR("Failed to enable runtime power management: %d", rc2); - } else { - LOG_DBG("Runtime power management enabled"); - } -#endif - #ifdef CONFIG_NORDIC_QSPI_NOR_XIP - if (rc == 0) { + if (!rc) { /* Enable XIP mode for QSPI NOR flash, this will prevent the * flash from being powered down */ @@ -1272,97 +1383,108 @@ static int exit_dpd(const struct device *const dev) } #ifdef CONFIG_PM_DEVICE -static int qspi_suspend(const struct device *dev) -{ - const struct qspi_nor_config *dev_config = dev->config; - nrfx_err_t res; - int rc; - - res = nrfx_qspi_mem_busy_check(); - if (res != NRFX_SUCCESS) { - return -EBUSY; - } - - rc = enter_dpd(dev); - if (rc < 0) { - return rc; - } - - nrfx_qspi_uninit(); - - return pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP); -} - -static int qspi_resume(const struct device *dev) -{ - const struct qspi_nor_config *dev_config = dev->config; - nrfx_err_t res; - int rc; - - rc = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); - if (rc < 0) { - return rc; - } - - res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev->data); - if (res != NRFX_SUCCESS) { - return -EIO; - } - - return exit_dpd(dev); -} - static int qspi_nor_pm_action(const struct device *dev, enum pm_device_action action) { + struct qspi_nor_data *dev_data = dev->data; + const struct qspi_nor_config *dev_config = dev->config; int rc; + nrfx_err_t res; if (pm_device_is_busy(dev)) { return -EBUSY; } - qspi_lock(dev); - qspi_clock_div_change(); - switch (action) { case PM_DEVICE_ACTION_SUSPEND: - rc = qspi_suspend(dev); +#ifndef CONFIG_PM_DEVICE_RUNTIME + /* If PM_DEVICE_RUNTIME, we don't uninit after RESUME */ + rc = qspi_device_init(dev); + if (rc < 0) { + return rc; + } +#endif + + if (dev_data->xip_enabled) { + return -EBUSY; + } + + if (nrfx_qspi_mem_busy_check() != NRFX_SUCCESS) { + return -EBUSY; + } + + rc = enter_dpd(dev); + if (rc < 0) { + return rc; + } + + nrfx_qspi_uninit(); + rc = pinctrl_apply_state(dev_config->pcfg, + PINCTRL_STATE_SLEEP); + if (rc < 0) { + return rc; + } break; case PM_DEVICE_ACTION_RESUME: - rc = qspi_resume(dev); + rc = pinctrl_apply_state(dev_config->pcfg, + PINCTRL_STATE_DEFAULT); + if (rc < 0) { + return rc; + } + res = nrfx_qspi_init(&dev_config->nrfx_cfg, + qspi_handler, + dev_data); + if (res != NRFX_SUCCESS) { + return -EIO; + } + + rc = exit_dpd(dev); + if (rc < 0) { + return rc; + } + +#ifndef CONFIG_PM_DEVICE_RUNTIME + /* If PM_DEVICE_RUNTIME, we're immediately going to use the device */ + qspi_device_uninit(dev); +#endif break; default: - rc = -ENOTSUP; + return -ENOTSUP; } - qspi_clock_div_restore(); - qspi_unlock(dev); - - return rc; + return 0; } #endif /* CONFIG_PM_DEVICE */ void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable) { struct qspi_nor_data *dev_data = dev->data; + int rc; if (dev_data->xip_enabled == enable) { return; } - qspi_acquire(dev); + rc = qspi_device_init(dev); + + if (rc != 0) { + LOG_ERR("NRF QSPI NOR XIP %s failed with %d\n", enable ? "enable" : "disable", rc); + return; + } #if NRF_QSPI_HAS_XIPEN nrf_qspi_xip_set(NRF_QSPI, enable); #endif + qspi_lock(dev); if (enable) { (void)nrfx_qspi_activate(false); } dev_data->xip_enabled = enable; + qspi_unlock(dev); - qspi_release(dev); + qspi_device_uninit(dev); } #ifdef CONFIG_USERSPACE @@ -1380,12 +1502,11 @@ void z_vrfy_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable) #endif /* CONFIG_USERSPACE */ static struct qspi_nor_data qspi_nor_dev_data = { -#if !defined(CONFIG_PM_DEVICE_RUNTIME) && defined(CONFIG_MULTITHREADING) - .count = Z_SEM_INITIALIZER(qspi_nor_dev_data.count, 0, K_SEM_MAX_LIMIT), -#endif #ifdef CONFIG_MULTITHREADING + .trans = Z_SEM_INITIALIZER(qspi_nor_dev_data.trans, 1, 1), .sem = Z_SEM_INITIALIZER(qspi_nor_dev_data.sem, 1, 1), .sync = Z_SEM_INITIALIZER(qspi_nor_dev_data.sync, 0, 1), + .count = Z_SEM_INITIALIZER(qspi_nor_dev_data.count, 0, K_SEM_MAX_LIMIT), #endif /* CONFIG_MULTITHREADING */ }; From feb81afcb302368cebe23d1902ef94cb65aed90a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:18 +0000 Subject: [PATCH 0517/1623] Revert "[nrf fromtree] drivers: nrf_qspi_nor: Clean up handling of return values" This reverts commit 72a0fceed9941275c0c5b666363360a99f293d1e. Signed-off-by: Dominik Ermel --- drivers/flash/nrf_qspi_nor.c | 248 +++++++++++++++++------------------ 1 file changed, 123 insertions(+), 125 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index 653f8b38f4e..945daa03d84 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -371,7 +371,7 @@ static int qspi_device_init(const struct device *dev) return pm_device_runtime_get(dev); #else nrfx_err_t res; - int rc = 0; + int ret = 0; qspi_lock(dev); @@ -389,13 +389,13 @@ static int qspi_device_init(const struct device *dev) res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); - rc = qspi_get_zephyr_ret_code(res); - qspi_initialized = (rc == 0); + ret = qspi_get_zephyr_ret_code(res); + qspi_initialized = (ret == 0); } qspi_unlock(dev); - return rc; + return ret; #endif } @@ -408,10 +408,10 @@ static void qspi_device_uninit(const struct device *dev) } #ifdef CONFIG_PM_DEVICE_RUNTIME - int rc = pm_device_runtime_put(dev); + int ret = pm_device_runtime_put(dev); - if (rc < 0) { - LOG_ERR("Failed to schedule device sleep: %d", rc); + if (ret < 0) { + LOG_ERR("Failed to schedule device sleep: %d", ret); } #else bool last = true; @@ -526,27 +526,27 @@ static int qspi_rdsr(const struct device *dev, uint8_t sr_num) .op_code = opcode, .rx_buf = &sr_buf, }; - int rc = qspi_send_cmd(dev, &cmd, false); + int ret = qspi_send_cmd(dev, &cmd, false); - return (rc < 0) ? rc : sr; + return (ret < 0) ? ret : sr; } /* Wait until RDSR confirms write is not in progress. */ static int qspi_wait_while_writing(const struct device *dev) { - int rc; + int ret; do { - rc = qspi_rdsr(dev, 1); - } while ((rc >= 0) - && ((rc & SPI_NOR_WIP_BIT) != 0U)); + ret = qspi_rdsr(dev, 1); + } while ((ret >= 0) + && ((ret & SPI_NOR_WIP_BIT) != 0U)); - return (rc < 0) ? rc : 0; + return (ret < 0) ? ret : 0; } static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) { - int rc = 0; + int ret = 0; uint8_t opcode = SPI_NOR_CMD_WRSR; uint8_t length = 1; uint8_t sr_array[2] = {0}; @@ -559,12 +559,12 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) sr_array[0] = sr_val; #if SR1_WRITE_CLEARS_SR2 /* Writing sr1 clears sr2. need to read/modify/write both. */ - rc = qspi_rdsr(dev, 2); - if (rc < 0) { - LOG_ERR("RDSR for WRSR failed: %d", rc); - return rc; + ret = qspi_rdsr(dev, 2); + if (ret < 0) { + LOG_ERR("RDSR for WRSR failed: %d", ret); + return ret; } - sr_array[1] = rc; + sr_array[1] = ret; length = 2; #endif } else { /* sr_num == 2 */ @@ -574,12 +574,12 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) * Uses standard WRSR opcode */ sr_array[1] = sr_val; - rc = qspi_rdsr(dev, 1); - if (rc < 0) { - LOG_ERR("RDSR for WRSR failed: %d", rc); - return rc; + ret = qspi_rdsr(dev, 1); + if (ret < 0) { + LOG_ERR("RDSR for WRSR failed: %d", ret); + return ret; } - sr_array[0] = rc; + sr_array[0] = ret; length = 2; #elif IS_EQUAL(INST_0_QER, JESD216_DW15_QER_VAL_S2B1v6) /* Writing sr2 uses a dedicated WRSR2 command */ @@ -600,17 +600,17 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) .tx_buf = &sr_buf, }; - rc = qspi_send_cmd(dev, &cmd, true); + ret = qspi_send_cmd(dev, &cmd, true); /* Writing SR can take some time, and further * commands sent while it's happening can be * corrupted. Wait. */ - if (rc == 0) { - rc = qspi_wait_while_writing(dev); + if (ret == 0) { + ret = qspi_wait_while_writing(dev); } - return rc; + return ret; } #endif /* !IS_EQUAL(INST_0_QER, JESD216_DW15_QER_VAL_NONE) */ @@ -627,16 +627,16 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) return -EINVAL; } + int rv = 0; const struct qspi_nor_config *params = dev->config; - int rc, rc2; - rc = qspi_device_init(dev); - if (rc != 0) { + rv = qspi_device_init(dev); + if (rv != 0) { goto out; } qspi_trans_lock(dev); - rc = qspi_nor_write_protection_set(dev, false); - if (rc != 0) { + rv = qspi_nor_write_protection_set(dev, false); + if (rv != 0) { goto out_trans_unlock; } qspi_lock(dev); @@ -670,16 +670,16 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) size -= adj; } else { LOG_ERR("erase error at 0x%lx size %zu", (long)addr, size); - rc = qspi_get_zephyr_ret_code(res); + rv = qspi_get_zephyr_ret_code(res); break; } } qspi_unlock(dev); - rc2 = qspi_nor_write_protection_set(dev, true); + int rv2 = qspi_nor_write_protection_set(dev, true); - if (!rc) { - rc = rc2; + if (!rv) { + rv = rv2; } out_trans_unlock: @@ -687,7 +687,7 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) out: qspi_device_uninit(dev); - return rc; + return rv; } /* Configures QSPI memory for the transfer */ @@ -695,8 +695,6 @@ static int qspi_nrfx_configure(const struct device *dev) { struct qspi_nor_data *dev_data = dev->data; const struct qspi_nor_config *dev_config = dev->config; - nrfx_err_t res; - int rc; #if defined(CONFIG_SOC_SERIES_NRF53X) /* When the QSPI peripheral is activated, during the nrfx_qspi driver @@ -707,16 +705,18 @@ static int qspi_nrfx_configure(const struct device *dev) nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); #endif - res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); + nrfx_err_t res = nrfx_qspi_init(&dev_config->nrfx_cfg, + qspi_handler, + dev_data); #if defined(CONFIG_SOC_SERIES_NRF53X) /* Restore the default /4 divider after the QSPI initialization. */ nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); #endif - rc = qspi_get_zephyr_ret_code(res); - if (rc < 0) { - return rc; + int ret = qspi_get_zephyr_ret_code(res); + if (ret < 0) { + return ret; } #if DT_INST_NODE_HAS_PROP(0, rx_delay) @@ -736,9 +736,9 @@ static int qspi_nrfx_configure(const struct device *dev) * bootloader) might have set DPD mode before reboot. As a result, * attempt to exit DPD mode regardless of whether CONFIG_PM_DEVICE is set. */ - rc = exit_dpd(dev); - if (rc < 0) { - return rc; + ret = exit_dpd(dev); + if (ret < 0) { + return ret; } /* Set QE to match transfer mode. If not using quad @@ -769,28 +769,28 @@ static int qspi_nrfx_configure(const struct device *dev) return -EINVAL; #endif - rc = qspi_rdsr(dev, sr_num); - if (rc < 0) { - LOG_ERR("RDSR failed: %d", rc); - return rc; + ret = qspi_rdsr(dev, sr_num); + if (ret < 0) { + LOG_ERR("RDSR failed: %d", ret); + return ret; } - uint8_t sr = (uint8_t)rc; + uint8_t sr = (uint8_t)ret; bool qe_state = ((sr & qe_mask) != 0U); LOG_DBG("RDSR %02x QE %d need %d: %s", sr, qe_state, qe_value, (qe_state != qe_value) ? "updating" : "no-change"); - rc = 0; + ret = 0; if (qe_state != qe_value) { sr ^= qe_mask; - rc = qspi_wrsr(dev, sr, sr_num); + ret = qspi_wrsr(dev, sr, sr_num); } - if (rc < 0) { + if (ret < 0) { LOG_ERR("QE %s failed: %d", qe_value ? "set" : "clear", - rc); - return rc; + ret); + return ret; } #endif @@ -802,16 +802,16 @@ static int qspi_nrfx_configure(const struct device *dev) /* Call will send write enable before instruction if that * requirement is encoded in INST_0_4BA. */ - rc = qspi_send_cmd(dev, &cmd, (INST_0_4BA & 0x02)); + ret = qspi_send_cmd(dev, &cmd, (INST_0_4BA & 0x02)); - if (rc < 0) { - LOG_ERR("E4BA cmd issue failed: %d.", rc); + if (ret < 0) { + LOG_ERR("E4BA cmd issue failed: %d.", ret); } else { LOG_DBG("E4BA cmd issued."); } } - return rc; + return ret; } static int qspi_read_jedec_id(const struct device *dev, @@ -826,14 +826,14 @@ static int qspi_read_jedec_id(const struct device *dev, .rx_buf = &rx_buf, }; - int rc = qspi_device_init(dev); + int ret = qspi_device_init(dev); - if (rc == 0) { - rc = qspi_send_cmd(dev, &cmd, false); + if (ret == 0) { + ret = qspi_send_cmd(dev, &cmd, false); } qspi_device_uninit(dev); - return rc; + return ret; } #if defined(CONFIG_FLASH_JESD216_API) @@ -856,13 +856,13 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, .io3_level = true, }; - int rc = qspi_device_init(dev); + int ret = qspi_device_init(dev); nrfx_err_t res = NRFX_SUCCESS; - if (rc != 0) { - LOG_DBG("qspi_device_init: %d", rc); + if (ret != 0) { + LOG_DBG("qspi_device_init: %d", ret); qspi_device_uninit(dev); - return rc; + return ret; } qspi_lock(dev); @@ -901,9 +901,9 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, static inline int qspi_nor_read_id(const struct device *dev) { uint8_t id[SPI_NOR_MAX_ID_LEN]; - int rc = qspi_read_jedec_id(dev, id); + int ret = qspi_read_jedec_id(dev, id); - if (rc != 0) { + if (ret != 0) { return -EIO; } @@ -1109,7 +1109,6 @@ static int qspi_nor_write(const struct device *dev, off_t addr, } const struct qspi_nor_config *params = dev->config; - int rc, rc2; /* affected region should be within device */ if (addr < 0 || @@ -1120,18 +1119,18 @@ static int qspi_nor_write(const struct device *dev, off_t addr, return -EINVAL; } + nrfx_err_t res = NRFX_SUCCESS; + + int rc = qspi_device_init(dev); - rc = qspi_device_init(dev); if (rc != 0) { goto out; } qspi_trans_lock(dev); - rc = qspi_nor_write_protection_set(dev, false); + res = qspi_nor_write_protection_set(dev, false); qspi_lock(dev); - if (rc == 0) { - nrfx_err_t res; - + if (!res) { if (size < 4U) { res = write_sub_word(dev, addr, src, size); } else if (!nrfx_is_in_ram(src) || @@ -1141,18 +1140,17 @@ static int qspi_nor_write(const struct device *dev, off_t addr, res = nrfx_qspi_write(src, size, addr); qspi_wait_for_completion(dev, res); } - - rc = qspi_get_zephyr_ret_code(res); } qspi_unlock(dev); - rc2 = qspi_nor_write_protection_set(dev, true); + int res2 = qspi_nor_write_protection_set(dev, true); qspi_trans_unlock(dev); - if (rc == 0) { - rc = rc2; + if (!res) { + res = res2; } + rc = qspi_get_zephyr_ret_code(res); out: qspi_device_uninit(dev); return rc; @@ -1171,24 +1169,24 @@ static int qspi_nor_erase(const struct device *dev, off_t addr, size_t size) return -EINVAL; } - int rc = qspi_erase(dev, addr, size); + int ret = qspi_erase(dev, addr, size); - return rc; + return ret; } static int qspi_nor_write_protection_set(const struct device *dev, bool write_protect) { - int rc = 0; + int ret = 0; struct qspi_cmd cmd = { .op_code = ((write_protect) ? SPI_NOR_CMD_WRDI : SPI_NOR_CMD_WREN), }; if (qspi_send_cmd(dev, &cmd, false) != 0) { - rc = -EIO; + ret = -EIO; } - return rc; + return ret; } /** @@ -1200,16 +1198,16 @@ static int qspi_nor_write_protection_set(const struct device *dev, */ static int qspi_nor_configure(const struct device *dev) { - int rc = qspi_nrfx_configure(dev); + int ret = qspi_nrfx_configure(dev); - if (rc != 0) { - return rc; + if (ret != 0) { + return ret; } #ifdef CONFIG_PM_DEVICE_RUNTIME - rc = pm_device_runtime_enable(dev); - if (rc < 0) { - LOG_ERR("Failed to enable runtime power management: %d", rc); + ret = pm_device_runtime_enable(dev); + if (ret < 0) { + LOG_ERR("Failed to enable runtime power management: %d", ret); } else { LOG_DBG("Runtime power management enabled"); } @@ -1233,12 +1231,12 @@ static int qspi_nor_configure(const struct device *dev) */ static int qspi_nor_init(const struct device *dev) { - const struct qspi_nor_config *dev_config = dev->config; int rc; + const struct qspi_nor_config *dev_config = dev->config; + int ret = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); - rc = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); - if (rc < 0) { - return rc; + if (ret < 0) { + return ret; } IRQ_CONNECT(DT_IRQN(QSPI_NODE), DT_IRQ(QSPI_NODE, priority), @@ -1319,11 +1317,11 @@ static int enter_dpd(const struct device *const dev) .op_code = SPI_NOR_CMD_DPD, }; uint32_t t_enter_dpd = DT_INST_PROP_OR(0, t_enter_dpd, 0); - int rc; + int ret; - rc = qspi_send_cmd(dev, &cmd, false); - if (rc < 0) { - return rc; + ret = qspi_send_cmd(dev, &cmd, false); + if (ret < 0) { + return ret; } if (t_enter_dpd) { @@ -1388,8 +1386,8 @@ static int qspi_nor_pm_action(const struct device *dev, { struct qspi_nor_data *dev_data = dev->data; const struct qspi_nor_config *dev_config = dev->config; - int rc; - nrfx_err_t res; + int ret; + nrfx_err_t err; if (pm_device_is_busy(dev)) { return -EBUSY; @@ -1399,9 +1397,9 @@ static int qspi_nor_pm_action(const struct device *dev, case PM_DEVICE_ACTION_SUSPEND: #ifndef CONFIG_PM_DEVICE_RUNTIME /* If PM_DEVICE_RUNTIME, we don't uninit after RESUME */ - rc = qspi_device_init(dev); - if (rc < 0) { - return rc; + ret = qspi_device_init(dev); + if (ret < 0) { + return ret; } #endif @@ -1413,35 +1411,35 @@ static int qspi_nor_pm_action(const struct device *dev, return -EBUSY; } - rc = enter_dpd(dev); - if (rc < 0) { - return rc; + ret = enter_dpd(dev); + if (ret < 0) { + return ret; } nrfx_qspi_uninit(); - rc = pinctrl_apply_state(dev_config->pcfg, + ret = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP); - if (rc < 0) { - return rc; + if (ret < 0) { + return ret; } break; case PM_DEVICE_ACTION_RESUME: - rc = pinctrl_apply_state(dev_config->pcfg, + ret = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); - if (rc < 0) { - return rc; + if (ret < 0) { + return ret; } - res = nrfx_qspi_init(&dev_config->nrfx_cfg, + err = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); - if (res != NRFX_SUCCESS) { + if (err != NRFX_SUCCESS) { return -EIO; } - rc = exit_dpd(dev); - if (rc < 0) { - return rc; + ret = exit_dpd(dev); + if (ret < 0) { + return ret; } #ifndef CONFIG_PM_DEVICE_RUNTIME @@ -1461,16 +1459,16 @@ static int qspi_nor_pm_action(const struct device *dev, void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable) { struct qspi_nor_data *dev_data = dev->data; - int rc; + int ret; if (dev_data->xip_enabled == enable) { return; } - rc = qspi_device_init(dev); + ret = qspi_device_init(dev); - if (rc != 0) { - LOG_ERR("NRF QSPI NOR XIP %s failed with %d\n", enable ? "enable" : "disable", rc); + if (ret != 0) { + LOG_ERR("NRF QSPI NOR XIP %s failed with %d\n", enable ? "enable" : "disable", ret); return; } From 0ac90e10db2cd2173f701ccbf13c03cbdba4cf75 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:18 +0000 Subject: [PATCH 0518/1623] Revert "[nrf fromtree] drivers: nrf_qspi_nor: Prevent reading status before sending RDPD" This reverts commit 93e398cd1fdd7abb0a6ec347ebaa09f1ff5172ab. Signed-off-by: Dominik Ermel --- drivers/flash/nrf_qspi_nor.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index 945daa03d84..c373a2c8ab7 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -1339,34 +1339,15 @@ static int enter_dpd(const struct device *const dev) static int exit_dpd(const struct device *const dev) { if (IS_ENABLED(DT_INST_PROP(0, has_dpd))) { - nrf_qspi_pins_t pins; - nrf_qspi_pins_t disconnected_pins = { - .sck_pin = NRF_QSPI_PIN_NOT_CONNECTED, - .csn_pin = NRF_QSPI_PIN_NOT_CONNECTED, - .io0_pin = NRF_QSPI_PIN_NOT_CONNECTED, - .io1_pin = NRF_QSPI_PIN_NOT_CONNECTED, - .io2_pin = NRF_QSPI_PIN_NOT_CONNECTED, - .io3_pin = NRF_QSPI_PIN_NOT_CONNECTED, - }; struct qspi_cmd cmd = { .op_code = SPI_NOR_CMD_RDPD, }; uint32_t t_exit_dpd = DT_INST_PROP_OR(0, t_exit_dpd, 0); - nrfx_err_t res; - int rc; - - nrf_qspi_pins_get(NRF_QSPI, &pins); - nrf_qspi_pins_set(NRF_QSPI, &disconnected_pins); - res = nrfx_qspi_activate(true); - nrf_qspi_pins_set(NRF_QSPI, &pins); - - if (res != NRFX_SUCCESS) { - return -EIO; - } + int ret; - rc = qspi_send_cmd(dev, &cmd, false); - if (rc < 0) { - return rc; + ret = qspi_send_cmd(dev, &cmd, false); + if (ret < 0) { + return ret; } if (t_exit_dpd) { From aaf9974ce4f577402abe4ff5531b6d653725c0a4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:19 +0000 Subject: [PATCH 0519/1623] Revert "[nrf fromtree] drivers: nrf_qspi_nor: Activate QSPI peripheral when enabling XIP" This reverts commit 7d3f7bbf99454d8903c01490670a5a83d4fbd114. Signed-off-by: Dominik Ermel --- drivers/flash/nrf_qspi_nor.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index c373a2c8ab7..e2ce6e6a706 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -1457,9 +1457,6 @@ void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable) nrf_qspi_xip_set(NRF_QSPI, enable); #endif qspi_lock(dev); - if (enable) { - (void)nrfx_qspi_activate(false); - } dev_data->xip_enabled = enable; qspi_unlock(dev); From b7cfd8893805e2cbc4e96b85f32e69c8a4b5d447 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:19 +0000 Subject: [PATCH 0520/1623] Revert "[nrf fromtree] tfm: Enforce initial attestation with required key provisioned" This reverts commit 2ac74ca47b0ae06ff19755985e01b07b150f53b5. Signed-off-by: Dominik Ermel --- boards/arm/b_u585i_iot02a/Kconfig.defconfig | 4 ---- modules/trusted-firmware-m/Kconfig.tfm | 8 -------- modules/trusted-firmware-m/Kconfig.tfm.partitions | 1 - 3 files changed, 13 deletions(-) diff --git a/boards/arm/b_u585i_iot02a/Kconfig.defconfig b/boards/arm/b_u585i_iot02a/Kconfig.defconfig index 84e7bdb320a..78c0253fe41 100644 --- a/boards/arm/b_u585i_iot02a/Kconfig.defconfig +++ b/boards/arm/b_u585i_iot02a/Kconfig.defconfig @@ -22,10 +22,6 @@ config SYS_CLOCK_TICKS_PER_SEC if BUILD_WITH_TFM -# Initial Attestation key provisioned by the BL1 bootloader -config TFM_INITIAL_ATTESTATION_KEY - default y - config TFM_DUMMY_PROVISIONING default n diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index dc2ab24b17d..4fac243cf41 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -179,7 +179,6 @@ config TFM_PARTITION_PLATFORM_CUSTOM_REBOOT config TFM_DUMMY_PROVISIONING bool "Provision with dummy values. NOT to be used in production" - select TFM_INITIAL_ATTESTATION_KEY default y help If this option is enabled (as it is by default), a set of dummy @@ -189,13 +188,6 @@ config TFM_DUMMY_PROVISIONING This option MUST not be used in production hardware, as the keys are insecure. -config TFM_INITIAL_ATTESTATION_KEY - bool - help - Hidden option to mark that the TF-M platform has an initial - attestation key, which is a requirement for the Initial Attestation - partition. - config TFM_BL2_NOT_SUPPORTED bool help diff --git a/modules/trusted-firmware-m/Kconfig.tfm.partitions b/modules/trusted-firmware-m/Kconfig.tfm.partitions index 67b46f5328b..cd9aaadb1ec 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm.partitions +++ b/modules/trusted-firmware-m/Kconfig.tfm.partitions @@ -44,7 +44,6 @@ config TFM_PARTITION_CRYPTO config TFM_PARTITION_INITIAL_ATTESTATION bool "Secure partition 'Initial Attestation'" depends on TFM_PARTITION_CRYPTO - depends on TFM_INITIAL_ATTESTATION_KEY default n help Setting this option will cause '-DTFM_PARTITION_INITIAL_ATTESTATION' From 9c2d1803ebd1d6a47c4d8dcfdd77f5b6480bcad6 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:19 +0000 Subject: [PATCH 0521/1623] Revert "[nrf fromtree] tfm: Harded build against TF-M built with unsecure keys" This reverts commit ec48dcb2ee4973bee58fbe610750fe62635a0e3f. Signed-off-by: Dominik Ermel --- boards/arm/b_u585i_iot02a/Kconfig.defconfig | 7 ------- modules/trusted-firmware-m/CMakeLists.txt | 17 +---------------- modules/trusted-firmware-m/Kconfig.tfm | 11 ----------- scripts/kconfig/hardened.csv | 1 - 4 files changed, 1 insertion(+), 35 deletions(-) diff --git a/boards/arm/b_u585i_iot02a/Kconfig.defconfig b/boards/arm/b_u585i_iot02a/Kconfig.defconfig index 78c0253fe41..93748d0dcf2 100644 --- a/boards/arm/b_u585i_iot02a/Kconfig.defconfig +++ b/boards/arm/b_u585i_iot02a/Kconfig.defconfig @@ -20,11 +20,4 @@ config USE_DT_CODE_PARTITION config SYS_CLOCK_TICKS_PER_SEC default 4096 if STM32_LPTIM_TIMER -if BUILD_WITH_TFM - -config TFM_DUMMY_PROVISIONING - default n - -endif # BUILD_WITH_TFM - endif # BOARD_B_U585I_IOT02A diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index ad1109d849b..177a47e28d6 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -95,12 +95,6 @@ if (CONFIG_BUILD_WITH_TFM) list(APPEND TFM_CMAKE_ARGS -DMCUBOOT_IMAGE_NUMBER=${CONFIG_TFM_MCUBOOT_IMAGE_NUMBER}) endif() - if (CONFIG_TFM_DUMMY_PROVISIONING) - list(APPEND TFM_CMAKE_ARGS -DTFM_DUMMY_PROVISIONING=ON) - else() - list(APPEND TFM_CMAKE_ARGS -DTFM_DUMMY_PROVISIONING=OFF) - endif() - if (CONFIG_TFM_EXCEPTION_INFO_DUMP) list(APPEND TFM_CMAKE_ARGS -DTFM_EXCEPTION_INFO_DUMP=ON) else() @@ -585,13 +579,4 @@ if (CONFIG_BUILD_WITH_TFM) ${MERGED_FILE} ) endif() - - if(CONFIG_TFM_DUMMY_PROVISIONING) - message(WARNING - "TFM_DUMMY_PROVISIONING is enabled: - The device will be provisioned using dummy keys and is NOT secure! - This is not suitable for production" - ) - endif() - -endif() # CONFIG_BUILD_WITH_TFM +endif() diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index 4fac243cf41..2a5edb64343 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -177,17 +177,6 @@ config TFM_PARTITION_PLATFORM_CUSTOM_REBOOT Instead the application will have to override the weak ARM implementation of sys_arch_reset(). -config TFM_DUMMY_PROVISIONING - bool "Provision with dummy values. NOT to be used in production" - default y - help - If this option is enabled (as it is by default), a set of dummy - keys / data will be provisioned. The dummy IAK matches the IAK tested - by the TF-M tests, and the dummy bl2 ROTPKs match the dummy bl2 keys - used by default. - This option MUST not be used in production hardware, as the keys are - insecure. - config TFM_BL2_NOT_SUPPORTED bool help diff --git a/scripts/kconfig/hardened.csv b/scripts/kconfig/hardened.csv index 6a2937df65c..a09defdc756 100644 --- a/scripts/kconfig/hardened.csv +++ b/scripts/kconfig/hardened.csv @@ -39,7 +39,6 @@ TEST_RANDOM_GENERATOR,n TEST_SHELL,n TEST_USERSPACE,n TFM_CMAKE_BUILD_TYPE_DEBUG,n -TFM_DUMMY_PROVISIONING,n THREAD_MONITOR,n THREAD_NAME,n TIMER_RANDOM_GENERATOR,n From 46b6c2666ace17a75ae75ebdbb75b1fa04759622 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:19 +0000 Subject: [PATCH 0522/1623] Revert "[nrf noup] soc: arm: nRF91: Add SPU Flash/RAM alignment" This reverts commit 89be4330a38498731fe612f1343624fc3d0a098e. Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/nrf91/Kconfig.series | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf91/Kconfig.series b/soc/arm/nordic_nrf/nrf91/Kconfig.series index 9e0e477e851..1f2f233edb9 100644 --- a/soc/arm/nordic_nrf/nrf91/Kconfig.series +++ b/soc/arm/nordic_nrf/nrf91/Kconfig.series @@ -27,23 +27,9 @@ config NRF_SPU_FLASH_REGION_SIZE help FLASH region size for the NRF_SPU peripheral -config NRF_SPU_FLASH_REGION_ALIGNMENT - hex - default 0x8000 - help - FLASH regions must be aligned to this value due to SPU HW - limitations. - config NRF_SPU_RAM_REGION_SIZE hex default 0x2000 help RAM region size for the NRF_SPU peripheral - -config NRF_SPU_RAM_REGION_ALIGNMENT - hex - default 0x2000 - help - RAM regions must be aligned to this value due to SPU HW - limitations. endif From 65db981f1cf1b071af160dffa3ca0c07a8e8180c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:20 +0000 Subject: [PATCH 0523/1623] Revert "[nrf noup] soc: arm: nRF53: Add SPU Flash/RAM alignment" This reverts commit 1f49692993f6ad7f1ee1e19ff27d3ff56659b23e. Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 1c8527e1716..09b15948da0 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -104,26 +104,12 @@ config NRF_SPU_FLASH_REGION_SIZE help FLASH region size for the NRF_SPU peripheral -config NRF_SPU_FLASH_REGION_ALIGNMENT - hex - default 0x4000 - help - FLASH regions must be aligned to this value due to SPU HW - limitations. - config NRF_SPU_RAM_REGION_SIZE hex default 0x2000 help RAM region size for the NRF_SPU peripheral -config NRF_SPU_RAM_REGION_ALIGNMENT - hex - default 0x2000 - help - RAM regions must be aligned to this value due to SPU HW - limitations. - config SOC_NRF_GPIO_FORWARDER_FOR_NRF5340 bool depends on NRF_SOC_SECURE_SUPPORTED From 9ea27a5acc420a7fac8cc68f437327ddc708724a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:20 +0000 Subject: [PATCH 0524/1623] Revert "[nrf fromtree] soc: arm: Remove CPU_HAS_NRF_IDAU's dependencies" This reverts commit 92c50d89502df25b5ee0a7b5f0cdf7641d1b59d8. Signed-off-by: Dominik Ermel --- soc/arm/Kconfig | 16 ++++++++++++++++ soc/arm/nordic_nrf/nrf53/Kconfig.soc | 12 ------------ soc/arm/nordic_nrf/nrf91/Kconfig.series | 14 -------------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/soc/arm/Kconfig b/soc/arm/Kconfig index 461f0b41f84..443a0031189 100644 --- a/soc/arm/Kconfig +++ b/soc/arm/Kconfig @@ -34,12 +34,28 @@ config CPU_HAS_ARM_SAU config CPU_HAS_NRF_IDAU bool + depends on SOC_SERIES_NRF91X || SOC_NRF5340_CPUAPP select CPU_HAS_TEE help MCU implements the nRF (vendor-specific) Security Attribution Unit. (IDAU: "Implementation-Defined Attribution Unit", in accordance with ARM terminology). +if CPU_HAS_NRF_IDAU +config NRF_SPU_FLASH_REGION_SIZE + hex + default 0x8000 if SOC_SERIES_NRF91X + default 0x4000 if SOC_NRF5340_CPUAPP + help + FLASH region size for the NRF_SPU peripheral + +config NRF_SPU_RAM_REGION_SIZE + hex + default 0x2000 if SOC_SERIES_NRF91X || SOC_NRF5340_CPUAPP + help + RAM region size for the NRF_SPU peripheral +endif + config HAS_SWO bool help diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 09b15948da0..2cd934af324 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -98,18 +98,6 @@ config SOC_DCDC_NRF53X_HV help Enable nRF53 series System on Chip High Voltage DC/DC converter. -config NRF_SPU_FLASH_REGION_SIZE - hex - default 0x4000 - help - FLASH region size for the NRF_SPU peripheral - -config NRF_SPU_RAM_REGION_SIZE - hex - default 0x2000 - help - RAM region size for the NRF_SPU peripheral - config SOC_NRF_GPIO_FORWARDER_FOR_NRF5340 bool depends on NRF_SOC_SECURE_SUPPORTED diff --git a/soc/arm/nordic_nrf/nrf91/Kconfig.series b/soc/arm/nordic_nrf/nrf91/Kconfig.series index 1f2f233edb9..fd8f5b04d7a 100644 --- a/soc/arm/nordic_nrf/nrf91/Kconfig.series +++ b/soc/arm/nordic_nrf/nrf91/Kconfig.series @@ -19,17 +19,3 @@ config SOC_SERIES_NRF91X select HAS_POWEROFF help Enable support for NRF91 MCU series - -if SOC_SERIES_NRF91X -config NRF_SPU_FLASH_REGION_SIZE - hex - default 0x8000 - help - FLASH region size for the NRF_SPU peripheral - -config NRF_SPU_RAM_REGION_SIZE - hex - default 0x2000 - help - RAM region size for the NRF_SPU peripheral -endif From 37873f0312c9589493cbe836c47f9afbde4abad2 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:20 +0000 Subject: [PATCH 0525/1623] Revert "[nrf fromlist] soc: nordic_nrf: Enable the TF-M NS storage partition for nordic boards" This reverts commit 462ad3659295cc639b3c159573136731141a06cc. Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/CMakeLists.txt | 4 ---- soc/arm/nordic_nrf/Kconfig | 4 ---- 2 files changed, 8 deletions(-) diff --git a/soc/arm/nordic_nrf/CMakeLists.txt b/soc/arm/nordic_nrf/CMakeLists.txt index 3b097d73569..47364b35ffb 100644 --- a/soc/arm/nordic_nrf/CMakeLists.txt +++ b/soc/arm/nordic_nrf/CMakeLists.txt @@ -25,8 +25,4 @@ if(CONFIG_BUILD_WITH_TFM) set_property(TARGET zephyr_property_target APPEND PROPERTY TFM_CMAKE_OPTIONS -DZEPHYR_BASE=${ZEPHYR_BASE} ) - - set_property(TARGET zephyr_property_target - APPEND PROPERTY TFM_CMAKE_OPTIONS -DNRF_NS_STORAGE=${CONFIG_TFM_NRF_NS_STORAGE} - ) endif() diff --git a/soc/arm/nordic_nrf/Kconfig b/soc/arm/nordic_nrf/Kconfig index 0372492cd7d..19e49c05454 100644 --- a/soc/arm/nordic_nrf/Kconfig +++ b/soc/arm/nordic_nrf/Kconfig @@ -45,10 +45,6 @@ config TFM_LOG_LEVEL_SILENCE Disable TF-M secure output if the uart1 node has not assigned GPIO pins using pinctrl. -config TFM_NRF_NS_STORAGE - bool "TF-M non-secure storage partition" - default y - endif # BUILD_WITH_TFM From 37484cc81d27b05a485d9b660b09ccc0fb59be64 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:20 +0000 Subject: [PATCH 0526/1623] Revert "[nrf fromtree] net: openthread: Openthread upmerge to `4ed44bc`" This reverts commit 919457f5c1d9d491033b23efcf77197d687422a6. Signed-off-by: Dominik Ermel --- modules/openthread/CMakeLists.txt | 6 ------ modules/openthread/Kconfig.features | 3 --- west.yml | 2 +- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index 3796ec8f177..31bff57d776 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -340,12 +340,6 @@ else() set(OT_MLR OFF CACHE BOOL "Enable Multicast Listener Registration feature for Thread 1.2" FORCE) endif() -if(CONFIG_OPENTHREAD_MULTIPAN_RCP) - set(OT_MULTIPAN_RCP ON CACHE BOOL "Enable Multi-PAN RCP" FORCE) -else() - set(OT_MULTIPAN_RCP OFF CACHE BOOL "Enable Multi-PAN RCP" FORCE) -endif() - if(CONFIG_OPENTHREAD_MULTIPLE_INSTANCE) set(OT_MULTIPLE_INSTANCE ON CACHE BOOL "Enable multiple instances" FORCE) else() diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index 2be5332cde3..bd8a05ed9b9 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -218,9 +218,6 @@ config OPENTHREAD_MLR help Enable Multicast Listener Registration support for Thread 1.2 -config OPENTHREAD_MULTIPAN_RCP - bool "OpenThread multipan rcp" - config OPENTHREAD_MULTIPLE_INSTANCE bool "OpenThread multiple instances" diff --git a/west.yml b/west.yml index 988343a9d10..475e8a7cc25 100644 --- a/west.yml +++ b/west.yml @@ -303,7 +303,7 @@ manifest: revision: 42b7c577714b8f22ce82a901e19c1814af4609a8 path: modules/lib/open-amp - name: openthread - revision: 4ed44bc7d58d9a98c6cca13a50d38129045ab3df + revision: 6edb06e4e0472411200ce2a084a783eaf3faffe3 path: modules/lib/openthread - name: picolibc path: modules/lib/picolibc From 578048f085017b64f49ce07e9eb1222301636168 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:21 +0000 Subject: [PATCH 0527/1623] Revert "[nrf fromlist] manifest: hal_nordic: Update revision with fixed workaround in nrfx_qspi" This reverts commit e0dc936a4af5550f15d9e37ab9b44db5de452ee0. Signed-off-by: Dominik Ermel --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 475e8a7cc25..93db410ea77 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: b9633ecea67bf52925d4c61455046223b46402b1 + revision: 2ff8ce6e6ca131d87699dba260f3c0cc4a6cc365 path: modules/hal/nordic groups: - hal From 4d28b7510da0a4267a93859d9e2f8d6907e72601 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:21 +0000 Subject: [PATCH 0528/1623] Revert "[nrf fromtree] scripts/pylib/twister/twisterlib: Support multiple `--pytest-args`" This reverts commit ad95bc81b8b9d44431c092a3cee4e7204dfceba4. Signed-off-by: Dominik Ermel --- doc/develop/test/pytest.rst | 2 -- .../pylib/twister/twisterlib/environment.py | 3 +-- scripts/pylib/twister/twisterlib/harness.py | 19 +++++++++---------- .../pytest_integration/test_harness_pytest.py | 5 ++--- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/doc/develop/test/pytest.rst b/doc/develop/test/pytest.rst index 957ff8c773b..e8ad82654c1 100644 --- a/doc/develop/test/pytest.rst +++ b/doc/develop/test/pytest.rst @@ -67,8 +67,6 @@ For instance, one can use a command: --pytest-args='-k test_shell_print_version' -Note that ``--pytest-args`` can be passed multiple times to pass several arguments to the pytest. - Helpers & fixtures ================== diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index d1ce56711c2..89377e8b961 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -211,8 +211,7 @@ def add_parse_arguments(parser = None): and 'fifo_loop' is a name of a function found in main.c without test prefix. """) - parser.add_argument( - "--pytest-args", action="append", + parser.add_argument("--pytest-args", help="""Pass additional arguments to the pytest subprocess. This parameter will override the pytest_args from the harness_config in YAML file. """) diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index edb053232b9..203adf4560c 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -262,6 +262,15 @@ def generate_command(self): command.extend([os.path.normpath(os.path.join( self.source_dir, os.path.expanduser(os.path.expandvars(src)))) for src in pytest_root]) + if handler.options.pytest_args: + command.append(handler.options.pytest_args) + if pytest_args_yaml: + logger.warning(f'The pytest_args ({handler.options.pytest_args}) specified ' + 'in the command line will override the pytest_args defined ' + f'in the YAML file {pytest_args_yaml}') + else: + command.extend(pytest_args_yaml) + if pytest_dut_scope: command.append(f'--dut-scope={pytest_dut_scope}') @@ -281,16 +290,6 @@ def generate_command(self): command.append('--device-type=custom') else: raise PytestHarnessException(f'Handling of handler {handler.type_str} not implemented yet') - - if handler.options.pytest_args: - command.extend(handler.options.pytest_args) - if pytest_args_yaml: - logger.warning(f'The pytest_args ({handler.options.pytest_args}) specified ' - 'in the command line will override the pytest_args defined ' - f'in the YAML file {pytest_args_yaml}') - else: - command.extend(pytest_args_yaml) - return command def _generate_parameters_for_hardware(self, handler: Handler): diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index befd384be37..fc60b99e0d1 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -71,13 +71,12 @@ def test_pytest_command_extra_args(testinstance: TestInstance): def test_pytest_command_extra_args_in_options(testinstance: TestInstance): pytest_harness = Pytest() pytest_args_from_yaml = '-k test_from_yaml' - pytest_args_from_cmd = ['-k', 'test_from_cmd'] + pytest_args_from_cmd = '-k test_from_cmd' testinstance.testsuite.harness_config['pytest_args'] = [pytest_args_from_yaml] testinstance.handler.options.pytest_args = pytest_args_from_cmd pytest_harness.configure(testinstance) command = pytest_harness.generate_command() - assert pytest_args_from_cmd[0] in command - assert pytest_args_from_cmd[1] in command + assert pytest_args_from_cmd in command assert pytest_args_from_yaml not in command From 36162fec46dc7fd19850c16c55501bfdb5240d50 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:21 +0000 Subject: [PATCH 0529/1623] Revert "[nrf fromtree] twister: pytest: Add --pytest-args to Twister command line" This reverts commit 9566a94fc5175eae833af9ec264f68bcf16bc3f6. Signed-off-by: Dominik Ermel --- doc/develop/test/pytest.rst | 10 --- .../pylib/twister/twisterlib/environment.py | 5 -- scripts/pylib/twister/twisterlib/harness.py | 19 ++---- .../pytest_integration/test_harness_pytest.py | 66 ------------------- 4 files changed, 4 insertions(+), 96 deletions(-) diff --git a/doc/develop/test/pytest.rst b/doc/develop/test/pytest.rst index e8ad82654c1..087c45bcce8 100644 --- a/doc/develop/test/pytest.rst +++ b/doc/develop/test/pytest.rst @@ -56,16 +56,6 @@ Pytest scans the given locations looking for tests, following its default `discovery rules `_ One can also pass some extra arguments to the pytest from yaml file using ``pytest_args`` keyword under ``harness_config``, e.g.: ``pytest_args: [‘-k=test_method’, ‘--log-level=DEBUG’]``. -There is also an option to pass ``--pytest-args`` through Twister command line parameters. -This can be particularly useful when one wants to select a specific testcase from a test suite. -For instance, one can use a command: - -.. code-block:: console - - $ ./scripts/twister --platform native_sim -T samples/subsys/testsuite/pytest/shell \ - -s samples/subsys/testsuite/pytest/shell/sample.pytest.shell \ - --pytest-args='-k test_shell_print_version' - Helpers & fixtures ================== diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index 89377e8b961..b5018bc1f01 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -211,11 +211,6 @@ def add_parse_arguments(parser = None): and 'fifo_loop' is a name of a function found in main.c without test prefix. """) - parser.add_argument("--pytest-args", - help="""Pass additional arguments to the pytest subprocess. This parameter - will override the pytest_args from the harness_config in YAML file. - """) - valgrind_asan_group.add_argument( "--enable-valgrind", action="store_true", help="""Run binary through valgrind and check for several memory access diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index 203adf4560c..bd86df1b4df 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -245,9 +245,8 @@ def pytest_run(self, timeout): def generate_command(self): config = self.instance.testsuite.harness_config - handler: Handler = self.instance.handler pytest_root = config.get('pytest_root', ['pytest']) if config else ['pytest'] - pytest_args_yaml = config.get('pytest_args', []) if config else [] + pytest_args = config.get('pytest_args', []) if config else [] pytest_dut_scope = config.get('pytest_dut_scope', None) if config else None command = [ 'pytest', @@ -261,19 +260,12 @@ def generate_command(self): ] command.extend([os.path.normpath(os.path.join( self.source_dir, os.path.expanduser(os.path.expandvars(src)))) for src in pytest_root]) - - if handler.options.pytest_args: - command.append(handler.options.pytest_args) - if pytest_args_yaml: - logger.warning(f'The pytest_args ({handler.options.pytest_args}) specified ' - 'in the command line will override the pytest_args defined ' - f'in the YAML file {pytest_args_yaml}') - else: - command.extend(pytest_args_yaml) - + command.extend(pytest_args) if pytest_dut_scope: command.append(f'--dut-scope={pytest_dut_scope}') + handler: Handler = self.instance.handler + if handler.options.verbose > 1: command.extend([ '--log-cli-level=DEBUG', @@ -433,9 +425,6 @@ def _parse_report_file(self, report): tc.status = 'error' tc.reason = elem.get('message') tc.output = elem.text - else: - self.state = 'skipped' - self.instance.reason = 'No tests collected' class Gtest(Harness): diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index fc60b99e0d1..150980059b3 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -25,7 +25,6 @@ def testinstance() -> TestInstance: testinstance.handler = mock.Mock() testinstance.handler.options = mock.Mock() testinstance.handler.options.verbose = 1 - testinstance.handler.options.pytest_args = None testinstance.handler.type_str = 'native' return testinstance @@ -68,18 +67,6 @@ def test_pytest_command_extra_args(testinstance: TestInstance): assert c in command -def test_pytest_command_extra_args_in_options(testinstance: TestInstance): - pytest_harness = Pytest() - pytest_args_from_yaml = '-k test_from_yaml' - pytest_args_from_cmd = '-k test_from_cmd' - testinstance.testsuite.harness_config['pytest_args'] = [pytest_args_from_yaml] - testinstance.handler.options.pytest_args = pytest_args_from_cmd - pytest_harness.configure(testinstance) - command = pytest_harness.generate_command() - assert pytest_args_from_cmd in command - assert pytest_args_from_yaml not in command - - @pytest.mark.parametrize( ('pytest_root', 'expected'), [ @@ -235,56 +222,3 @@ def test_skip_2(): assert len(testinstance.testcases) == 2 for tc in testinstance.testcases: assert tc.status == "skipped" - - -def test_if_report_with_filter(pytester, testinstance: TestInstance): - test_file_content = textwrap.dedent(""" - import pytest - def test_A(): - pass - def test_B(): - pass - """) - test_file = pytester.path / 'test_filter.py' - test_file.write_text(test_file_content) - report_file = pytester.path / 'report.xml' - result = pytester.runpytest( - str(test_file), - '-k', 'test_B', - f'--junit-xml={str(report_file)}' - ) - result.assert_outcomes(passed=1) - assert report_file.is_file() - - pytest_harness = Pytest() - pytest_harness.configure(testinstance) - pytest_harness.report_file = report_file - pytest_harness._update_test_status() - assert pytest_harness.state == "passed" - assert testinstance.status == "passed" - assert len(testinstance.testcases) == 1 - - -def test_if_report_with_no_collected(pytester, testinstance: TestInstance): - test_file_content = textwrap.dedent(""" - import pytest - def test_A(): - pass - """) - test_file = pytester.path / 'test_filter.py' - test_file.write_text(test_file_content) - report_file = pytester.path / 'report.xml' - result = pytester.runpytest( - str(test_file), - '-k', 'test_B', - f'--junit-xml={str(report_file)}' - ) - result.assert_outcomes(passed=0) - assert report_file.is_file() - - pytest_harness = Pytest() - pytest_harness.configure(testinstance) - pytest_harness.report_file = report_file - pytest_harness._update_test_status() - assert pytest_harness.state == "skipped" - assert testinstance.status == "skipped" From d001b9e71cc2d80e7c6711a17d2f3ddf465d4914 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:21 +0000 Subject: [PATCH 0530/1623] Revert "[nrf fromtree] net: l2: ieee802154: pkt: fix cpp build failure" This reverts commit e97dfe6a6edf3ca0e6b4a1a07c585d2f9be9f6ff. Signed-off-by: Dominik Ermel --- include/zephyr/net/ieee802154_pkt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/net/ieee802154_pkt.h b/include/zephyr/net/ieee802154_pkt.h index a1dca472448..23921467d96 100644 --- a/include/zephyr/net/ieee802154_pkt.h +++ b/include/zephyr/net/ieee802154_pkt.h @@ -92,7 +92,7 @@ static inline void *net_pkt_cb(struct net_pkt *pkt); static inline struct net_pkt_cb_ieee802154 *net_pkt_cb_ieee802154(struct net_pkt *pkt) { - return (struct net_pkt_cb_ieee802154 *)net_pkt_cb(pkt); + return net_pkt_cb(pkt); }; static inline uint8_t net_pkt_ieee802154_lqi(struct net_pkt *pkt) From 0bdf1a8bbab6da0c9acfdf06cfbfd47bea3e2594 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:22 +0000 Subject: [PATCH 0531/1623] Revert "[nrf fromlist] wifi: shell: Add long arguments to help" This reverts commit f721e835805a6e6bae6e7c491f3d4369d64412e4. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 90dbd1588f7..1d7499e11bd 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1271,10 +1271,10 @@ void parse_mode_args_to_params(const struct shell *sh, int argc, int opt; int option_index = 0; - static struct option long_options[] = {{"if-index", optional_argument, 0, 'i'}, + static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, {"sta", no_argument, 0, 's'}, {"monitor", no_argument, 0, 'm'}, - {"tx-injection", no_argument, 0, 't'}, + {"TX-injection", no_argument, 0, 't'}, {"promiscuous", no_argument, 0, 'p'}, {"ap", no_argument, 0, 'a'}, {"softap", no_argument, 0, 'k'}, @@ -1381,7 +1381,7 @@ void parse_channel_args_to_params(const struct shell *sh, int argc, int opt; int option_index = 0; - static struct option long_options[] = {{"if-index", optional_argument, 0, 'i'}, + static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, {"channel", required_argument, 0, 'c'}, {"get", no_argument, 0, 'g'}, {"help", no_argument, 0, 'h'}, @@ -1487,8 +1487,8 @@ void parse_filter_args_to_params(const struct shell *sh, int argc, int opt; int option_index = 0; - static struct option long_options[] = {{"if-index", optional_argument, 0, 'i'}, - {"capture-len", optional_argument, 0, 'b'}, + static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, + {"capture_len", optional_argument, 0, 'b'}, {"all", no_argument, 0, 'a'}, {"mgmt", no_argument, 0, 'm'}, {"ctrl", no_argument, 0, 'c'}, @@ -1679,15 +1679,15 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" - "[-i, --if-index ] : Interface index.\n" - "[-s, --sta] : Station mode.\n" - "[-m, --monitor] : Monitor mode.\n" - "[-p, --promiscuous] : Promiscuous mode.\n" - "[-t, --tx-injection] : TX-Injection mode.\n" - "[-a, --ap] : AP mode.\n" - "[-k, --softap] : Softap mode.\n" - "[-h, --help] : Help.\n" - "[-g, --get] : Get current mode for a specific interface index.\n" + "[-i] : Interface index - optional argument\n" + "[-s] : Station mode.\n" + "[-m] : Monitor mode.\n" + "[-p] : Promiscuous mode.\n" + "[-t] : TX-Injection mode.\n" + "[-a] : AP mode.\n" + "[-k] : Softap mode.\n" + "[-h] : Help.\n" + "[-g] : Get current mode for a specific interface index.\n" "Usage: Get operation example for interface index 1\n" "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" @@ -1699,14 +1699,14 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" "parameters:" - "[-i, --if-index ] : Interface index.\n" - "[-a, --all] : Enable all packet filter modes\n" - "[-m, --mgmt] : Enable management packets to allowed up the stack.\n" - "[-c, --ctrl] : Enable control packets to be allowed up the stack.\n" - "[-d, --data] : Enable Data packets to be allowed up the stack.\n" - "[-g, --get] : Get current filter settings for a specific interface index.\n" - "[-b, --capture-len ] : Capture length buffer size for each packet to be captured\n" - "[-h, --help] : Help.\n" + "[-i] : Interface index - optional argument.\n" + "[-a] : Enable all packet filter modes\n" + "[-m] : Enable management packets to allowed up the stack.\n" + "[-c] : Enable control packets to be allowed up the stack.\n" + "[-d] : Enable Data packets to be allowed up the stack.\n" + "[-g] : Get current filter settings for a specific interface index.\n" + "<-b> : Capture length buffer size for each packet to be captured - optional argument.\n" + "<-h> : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" @@ -1718,10 +1718,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" "parameters:" - "[-i, --if-index ] : Interface index.\n" - "[-c, --channel ] : Set a specific channel number to the lower layer.\n" - "[-g, --get] : Get current set channel number from the lower layer.\n" - "[-h, --help] : Help.\n" + "[-i] : Interface index - optional argument.\n" + "[-c] : Set a specific channel number to the lower layer.\n" + "[-g] : Get current set channel number from the lower layer.\n" + "[-h] : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" From 0b1d7f89c717dd25b8d3190168185b2f91239868 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:22 +0000 Subject: [PATCH 0532/1623] Revert "[nrf fromlist] wifi: shell: Enforce argument count checks" This reverts commit bebc385d82e4fd230ac7afd0d580a8045624e921. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 74 +++++++++++++-------------------- 1 file changed, 30 insertions(+), 44 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 1d7499e11bd..95c28e5d7e9 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1594,43 +1594,37 @@ static int cmd_wifi_packet_filter(const struct shell *sh, size_t argc, char *arg } SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, - SHELL_CMD_ARG(disable, NULL, + SHELL_CMD(disable, NULL, "Disable Access Point mode", - cmd_wifi_ap_disable, - 1, 0), - SHELL_CMD_ARG(enable, NULL, " [channel] [PSK]", - cmd_wifi_ap_enable, - 2, 1), + cmd_wifi_ap_disable), + SHELL_CMD(enable, NULL, " [channel] [PSK]", + cmd_wifi_ap_enable), SHELL_SUBCMD_SET_END ); SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops, - SHELL_CMD_ARG(quick_setup, NULL, " Start a TWT flow with defaults:\n" + SHELL_CMD(quick_setup, NULL, " Start a TWT flow with defaults:\n" " \n", - cmd_wifi_twt_setup_quick, - 3, 0), - SHELL_CMD_ARG(setup, NULL, " Start a TWT flow:\n" + cmd_wifi_twt_setup_quick), + SHELL_CMD(setup, NULL, " Start a TWT flow:\n" "\n" "\n" " " " \n", - cmd_wifi_twt_setup, - 11, 0), - SHELL_CMD_ARG(teardown, NULL, " Teardown a TWT flow:\n" + cmd_wifi_twt_setup), + SHELL_CMD(teardown, NULL, " Teardown a TWT flow:\n" "\n" "\n" " \n", - cmd_wifi_twt_teardown, - 5, 0), - SHELL_CMD_ARG(teardown_all, NULL, " Teardown all TWT flows\n", - cmd_wifi_twt_teardown_all, - 1, 0), + cmd_wifi_twt_teardown), + SHELL_CMD(teardown_all, NULL, " Teardown all TWT flows\n", + cmd_wifi_twt_teardown_all), SHELL_SUBCMD_SET_END ); SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(ap, &wifi_cmd_ap, "Access Point mode commands", NULL), - SHELL_CMD_ARG(connect, NULL, + SHELL_CMD(connect, NULL, "Connect to a Wi-Fi AP\n" "\"\"\n" "[channel number: 0 means all]\n" @@ -1639,21 +1633,18 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required", - cmd_wifi_connect, - 2, 5), - SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", - cmd_wifi_disconnect, - 1, 0), - SHELL_CMD_ARG(ps, NULL, "Configure Wi-F PS on/off, no arguments will dump config", - cmd_wifi_ps, - 1, 1), + cmd_wifi_connect), + SHELL_CMD(disconnect, NULL, "Disconnect from the Wi-Fi AP", + cmd_wifi_disconnect), + SHELL_CMD(ps, NULL, "Configure Wi-F PS on/off, no arguments will dump config", + cmd_wifi_ps), SHELL_CMD_ARG(ps_mode, NULL, "\n", cmd_wifi_ps_mode, 2, 0), - SHELL_CMD_ARG(scan, NULL, + SHELL_CMD(scan, NULL, "Scan for Wi-Fi APs\n" "OPTIONAL PARAMETERS:\n" "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active.\n" @@ -1664,19 +1655,17 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535.\n" "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6-11,14_5:36,149-165,44\n" "[-h, --help] : Print out the help for the scan command.", - cmd_wifi_scan, - 1, 8), - SHELL_CMD_ARG(statistics, NULL, "Wi-Fi interface statistics", cmd_wifi_stats, 1, 0), - SHELL_CMD_ARG(status, NULL, "Status of the Wi-Fi interface", cmd_wifi_status, 1, 0), + cmd_wifi_scan), + SHELL_CMD(statistics, NULL, "Wi-Fi interface statistics", cmd_wifi_stats), + SHELL_CMD(status, NULL, "Status of the Wi-Fi interface", cmd_wifi_status), SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows", NULL), - SHELL_CMD_ARG(reg_domain, NULL, + SHELL_CMD(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" "Usage: wifi reg_domain [ISO/IEC 3166-1 alpha2] [-f]\n" "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", - cmd_wifi_reg_domain, - 2, 1), - SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" + cmd_wifi_reg_domain), + SHELL_CMD(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" "[-i] : Interface index - optional argument\n" @@ -1692,9 +1681,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" "wifi mode -i1 -sp\n", - cmd_wifi_mode, - 1, 9), - SHELL_CMD_ARG(packet_filter, NULL, "mode filter setting\n" + cmd_wifi_mode), + SHELL_CMD(packet_filter, NULL, "mode filter setting\n" "This command is used to set packet filter setting when\n" "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" @@ -1711,9 +1699,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" "wifi packet_filter -i1 -md\n", - cmd_wifi_packet_filter, - 1, 8), - SHELL_CMD_ARG(channel, NULL, "wifi channel setting\n" + cmd_wifi_packet_filter), + SHELL_CMD(channel, NULL, "wifi channel setting\n" "This command is used to set the channel when\n" "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" @@ -1726,8 +1713,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" "wifi -i1 -c5\n", - cmd_wifi_channel, - 1, 4), + cmd_wifi_channel), SHELL_CMD_ARG(ps_timeout, NULL, " - PS inactivity timer(in ms)", From 8df851b46fd1f0b3a69904b09ab1b61b345b1583 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:22 +0000 Subject: [PATCH 0533/1623] Revert "[nrf fromlist] wifi: shell: Add missing security options" This reverts commit 7c23186c1282125353cacca44899f030706b2b68. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 95c28e5d7e9..26ea9f50775 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1630,7 +1630,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[channel number: 0 means all]\n" "[PSK: valid only for secure SSIDs]\n" "[Security type: valid only for secure SSIDs]\n" - "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" + "0:None, 1:PSK, 2:PSK-256, 3:SAE\n" "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_connect), From 0402834fd90dfb0a731fc2ddcf4e3dc11e3c26e0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:23 +0000 Subject: [PATCH 0534/1623] Revert "[nrf fromlist] wifi: shell: Fix PS mode help" This reverts commit 9c2c52a44a28f974fa1280b35f06875b067c69ea. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 26ea9f50775..973fbb63535 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1640,7 +1640,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, cmd_wifi_ps), SHELL_CMD_ARG(ps_mode, NULL, - "\n", + "\n" + "", cmd_wifi_ps_mode, 2, 0), @@ -1728,7 +1729,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, 0), SHELL_CMD_ARG(ps_wakeup_mode, NULL, - "\n", + " : Set PS wake up mode to DTIM interval\n" + " : Set PS wake up mode to listen interval", cmd_wifi_ps_wakeup_mode, 2, 0), From 764acfba75beca8f6fb6ba8d9f477125e38cd656 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:23 +0000 Subject: [PATCH 0535/1623] Revert "[nrf fromlist] wifi: shell: Fix brackets type for optional params" This reverts commit ad503caacd6004efb4f386ce526f8f1f8e1952a0. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 973fbb63535..c4d5c3ec657 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1627,11 +1627,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(connect, NULL, "Connect to a Wi-Fi AP\n" "\"\"\n" - "[channel number: 0 means all]\n" - "[PSK: valid only for secure SSIDs]\n" - "[Security type: valid only for secure SSIDs]\n" + "\n" + "\n" + "\n" "0:None, 1:PSK, 2:PSK-256, 3:SAE\n" - "[MFP (optional: needs security type to be specified)]\n" + "\n" ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_connect), SHELL_CMD(disconnect, NULL, "Disconnect from the Wi-Fi AP", @@ -1663,7 +1663,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" "Usage: wifi reg_domain [ISO/IEC 3166-1 alpha2] [-f]\n" - "[-f]: Force to use this regulatory hint over any other regulatory hints\n" + "-f: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain), SHELL_CMD(mode, NULL, "mode operational setting\n" From 16269a6ff9c9ff663fba087b01786baacfa329ed Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:23 +0000 Subject: [PATCH 0536/1623] Revert "[nrf fromlist] wifi: shell: Fix unbalanced braces" This reverts commit e3429fadeece82ab46940a23edf4dc0954d9a718. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index c4d5c3ec657..280ebd90390 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1669,15 +1669,15 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" - "[-i] : Interface index - optional argument\n" - "[-s] : Station mode.\n" - "[-m] : Monitor mode.\n" - "[-p] : Promiscuous mode.\n" - "[-t] : TX-Injection mode.\n" - "[-a] : AP mode.\n" - "[-k] : Softap mode.\n" - "[-h] : Help.\n" - "[-g] : Get current mode for a specific interface index.\n" + "[-i : Interface index - optional argument\n" + "[-s : Station mode.\n" + "[-m : Monitor mode.\n" + "[-p : Promiscuous mode.\n" + "[-t : TX-Injection mode.\n" + "[-a : AP mode.\n" + "[-k : Softap mode.\n" + "[-h : Help.\n" + "[-g : Get current mode for a specific interface index.\n" "Usage: Get operation example for interface index 1\n" "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" @@ -1688,14 +1688,14 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" "parameters:" - "[-i] : Interface index - optional argument.\n" - "[-a] : Enable all packet filter modes\n" - "[-m] : Enable management packets to allowed up the stack.\n" - "[-c] : Enable control packets to be allowed up the stack.\n" - "[-d] : Enable Data packets to be allowed up the stack.\n" - "[-g] : Get current filter settings for a specific interface index.\n" - "<-b> : Capture length buffer size for each packet to be captured - optional argument.\n" - "<-h> : Help.\n" + "[-i : Interface index - optional argument.\n" + "[-a : Enable all packet filter modes\n" + "[-m : Enable management packets to allowed up the stack.\n" + "[-c : Enable control packets to be allowed up the stack.\n" + "[-d : Enable Data packets to be allowed up the stack.\n" + "[-g : Get current filter settings for a specific interface index.\n" + "<-b : Capture length buffer size for each packet to be captured - optional argument.\n" + "<-h : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" @@ -1706,10 +1706,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" "parameters:" - "[-i] : Interface index - optional argument.\n" - "[-c] : Set a specific channel number to the lower layer.\n" - "[-g] : Get current set channel number from the lower layer.\n" - "[-h] : Help.\n" + "[-i : Interface index - optional argument.\n" + "[-c : Set a specific channel number to the lower layer.\n" + "[-g : Get current set channel number from the lower layer.\n" + "[-h : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" From ab12af686ebf3f3c7a3aa52be3e5029b53f90a70 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:23 +0000 Subject: [PATCH 0537/1623] Revert "[nrf fromlist] net: openthread: Remove waiting for DTR in openthread UART." This reverts commit 0c7fcf3c32a712f5003def83a3607404850dc9e2. Signed-off-by: Dominik Ermel --- modules/openthread/platform/uart.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/openthread/platform/uart.c b/modules/openthread/platform/uart.c index ebf156ded15..dd62d36ee11 100644 --- a/modules/openthread/platform/uart.c +++ b/modules/openthread/platform/uart.c @@ -170,6 +170,7 @@ otError otPlatUartEnable(void) if (DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_ot_uart), zephyr_cdc_acm_uart)) { int ret; + uint32_t dtr = 0U; ret = usb_enable(NULL); if (ret != 0 && ret != -EALREADY) { @@ -177,6 +178,20 @@ otError otPlatUartEnable(void) return OT_ERROR_FAILED; } + LOG_INF("Waiting for host to be ready to communicate"); + + /* Data Terminal Ready - check if host is ready to communicate */ + while (!dtr) { + ret = uart_line_ctrl_get(ot_uart.dev, + UART_LINE_CTRL_DTR, &dtr); + if (ret) { + LOG_ERR("Failed to get Data Terminal Ready line state: %d", + ret); + continue; + } + k_msleep(100); + } + /* Data Carrier Detect Modem - mark connection as established */ (void)uart_line_ctrl_set(ot_uart.dev, UART_LINE_CTRL_DCD, 1); /* Data Set Ready - the NCP SoC is ready to communicate */ From 88094c96dfe30dde23190f772e6706985cc74db3 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:24 +0000 Subject: [PATCH 0538/1623] Revert "[nrf fromlist] tfm: Remove limitation of enabling FP when build TF-M NS application" This reverts commit 90a72daae2c8715d760d974a7d294aa2eb6b38c4. Signed-off-by: Dominik Ermel --- arch/arm/core/aarch32/Kconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm/core/aarch32/Kconfig b/arch/arm/core/aarch32/Kconfig index c8a48cb7f11..529d143ef8c 100644 --- a/arch/arm/core/aarch32/Kconfig +++ b/arch/arm/core/aarch32/Kconfig @@ -264,6 +264,9 @@ choice config FP_HARDABI bool "Floating point Hard ABI" + # TF-M build system does not build the NS app and libraries correctly with Hard ABI. + # This limitation should be removed in the next TF-M synchronization. + depends on !TFM_BUILD_NS help This option selects the Floating point ABI in which hardware floating point instructions are generated and uses FPU-specific calling From a810007e6e8b3ef3c77fc283d5f60a8390f34d0c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:24 +0000 Subject: [PATCH 0539/1623] Revert "[nrf fromlist] tfm: Remove SFN model FP limitation" This reverts commit 5ba9369a4ed737d05145d892516d44f2f439eba3. Signed-off-by: Dominik Ermel --- arch/arm/core/aarch32/Kconfig | 2 ++ modules/trusted-firmware-m/Kconfig.tfm | 1 + 2 files changed, 3 insertions(+) diff --git a/arch/arm/core/aarch32/Kconfig b/arch/arm/core/aarch32/Kconfig index 529d143ef8c..58d5253cb94 100644 --- a/arch/arm/core/aarch32/Kconfig +++ b/arch/arm/core/aarch32/Kconfig @@ -272,6 +272,8 @@ config FP_HARDABI point instructions are generated and uses FPU-specific calling conventions. + Note: When building with TF-M enabled only the IPC mode is supported. + config FP_SOFTABI bool "Floating point Soft ABI" help diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index 2a5edb64343..c09d922e9fd 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -323,6 +323,7 @@ config TFM_IPC config TFM_SFN bool "SFN model" + depends on !FP_HARDABI help Use the SFN Model as the SPM backend for the PSA API. The SFN model supports the SFN Partition model, and isolation level 1. From 07514687dfc371d7e50f439fafcf2160c4f0ecb3 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:24 +0000 Subject: [PATCH 0540/1623] Revert "[nrf fromtree] net: openthread: upmerge to `6edb06e`" This reverts commit f51a3a880d04f082e92dfc478d6dfdbdea8304e3. Signed-off-by: Dominik Ermel --- modules/openthread/CMakeLists.txt | 6 ------ modules/openthread/Kconfig.features | 7 ------- west.yml | 2 +- 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index 31bff57d776..83995aba72f 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -154,12 +154,6 @@ else() set(OT_CSL_RECEIVER OFF CACHE BOOL "Enable CSL receiver feature for Thread 1.2" FORCE) endif() -if(CONFIG_OPENTHREAD_CSL_RECEIVER_LOCAL_TIME_SYNC) - set(OT_CSL_RECEIVER_LOCAL_TIME_SYNC ON CACHE BOOL "Use local time for CSL sync" FORCE) -else() - set(OT_CSL_RECEIVER_LOCAL_TIME_SYNC OFF CACHE BOOL "Use local time for CSL sync" FORCE) -endif() - if(CONFIG_OPENTHREAD_DATASET_UPDATER) set(OT_DATASET_UPDATER ON CACHE BOOL "Enable Dataset updater" FORCE) else() diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index bd8a05ed9b9..cd57844370e 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -96,13 +96,6 @@ config OPENTHREAD_CSL_RECEIVER help Enable CSL Receiver support for Thread 1.2 -config OPENTHREAD_CSL_RECEIVER_LOCAL_TIME_SYNC - bool "Use local time for CSL synchronization" - help - Use host time rather than radio platform time to track elapsed time - since last CSL synchronization. This reduces the usage of radio API - calls, and it is useful for platforms in which those are costly. - config OPENTHREAD_DEVICE_PROP_LEADER_WEIGHT bool "Device props for leader weight" default n if (OPENTHREAD_THREAD_VERSION_1_1 || \ diff --git a/west.yml b/west.yml index 93db410ea77..1847e94b37c 100644 --- a/west.yml +++ b/west.yml @@ -303,7 +303,7 @@ manifest: revision: 42b7c577714b8f22ce82a901e19c1814af4609a8 path: modules/lib/open-amp - name: openthread - revision: 6edb06e4e0472411200ce2a084a783eaf3faffe3 + revision: d62167ee34b091e7025c9ec2820aae71e17a3944 path: modules/lib/openthread - name: picolibc path: modules/lib/picolibc From ea6d9e9a143ef21f9616457bd9168c94590a2ca4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:25 +0000 Subject: [PATCH 0541/1623] Revert "[nrf fromlist] net: zperf: Fix TCP packet counting" This reverts commit e8c9775db7c7dbdb833e025038d6067983ae4cad. Signed-off-by: Dominik Ermel --- subsys/net/lib/zperf/zperf_tcp_uploader.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_tcp_uploader.c b/subsys/net/lib/zperf/zperf_tcp_uploader.c index 5fcc0530c5c..3e72f81e54b 100644 --- a/subsys/net/lib/zperf/zperf_tcp_uploader.c +++ b/subsys/net/lib/zperf/zperf_tcp_uploader.c @@ -20,22 +20,6 @@ static char sample_packet[PACKET_SIZE_MAX]; static struct zperf_async_upload_context tcp_async_upload_ctx; -static ssize_t sendall(int sock, const void *buf, size_t len) -{ - while (len) { - ssize_t out_len = zsock_send(sock, buf, len, 0); - - if (out_len < 0) { - return out_len; - } - - buf = (const char *)buf + out_len; - len -= out_len; - } - - return 0; -} - static int tcp_upload(int sock, unsigned int duration_in_ms, unsigned int packet_size, @@ -66,7 +50,7 @@ static int tcp_upload(int sock, do { /* Send the packet */ - ret = sendall(sock, sample_packet, packet_size); + ret = zsock_send(sock, sample_packet, packet_size, 0); if (ret < 0) { if (nb_errors == 0 && ret != -ENOMEM) { NET_ERR("Failed to send the packet (%d)", errno); From 46dfbbbd0131b6a0a8df255cc3be23e7491ec264 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:25 +0000 Subject: [PATCH 0542/1623] Revert "[nrf fromlist] net: sockets: tls: Set errno on TX waiting error" This reverts commit 67fddd31afce6d47ae8645fc40a4479e26d23965. Signed-off-by: Dominik Ermel --- subsys/net/lib/sockets/sockets_tls.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/sockets/sockets_tls.c b/subsys/net/lib/sockets/sockets_tls.c index f77bf51d668..20fdc3617af 100644 --- a/subsys/net/lib/sockets/sockets_tls.c +++ b/subsys/net/lib/sockets/sockets_tls.c @@ -2230,9 +2230,10 @@ static ssize_t send_tls(struct tls_context *ctx, const void *buf, timeout_ms = timeout_to_ms(&timeout); ret = wait_for_reason(ctx->sock, timeout_ms, ret); if (ret != 0) { - errno = -ret; + /* Retry. */ break; } + } else { (void)tls_mbedtls_reset(ctx); errno = EIO; From 673d3d10f684a52523ea782410c78421ac8e1f5d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:25 +0000 Subject: [PATCH 0543/1623] Revert "[nrf fromlist] net: tcp: Feed TX semaphore on connection close" This reverts commit f165bb7517c01c00eb42db01404408d7a2731ce0. Signed-off-by: Dominik Ermel --- subsys/net/ip/tcp.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index 680fdcecb85..2e70824b8ed 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -621,8 +621,6 @@ static int tcp_conn_close(struct tcp *conn, int status) status, conn->recv_user_data); } - k_sem_give(&conn->tx_sem); - return tcp_conn_unref(conn); } From fb4f07c75a1172d8671a8808936f829f12d52f69 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:25 +0000 Subject: [PATCH 0544/1623] Revert "[nrf fromlist] net: tcp: Rework data queueing API" This reverts commit 2242e9c7569a3651e2a07c11e0e24e2212e3dbd9. Signed-off-by: Dominik Ermel --- subsys/net/ip/net_context.c | 27 +++--- subsys/net/ip/tcp.c | 166 ++++++++++++++--------------------- subsys/net/ip/tcp.h | 15 +++- subsys/net/ip/tcp_internal.h | 20 ++--- 4 files changed, 96 insertions(+), 132 deletions(-) diff --git a/subsys/net/ip/net_context.c b/subsys/net/ip/net_context.c index 6af67103721..1372398185a 100644 --- a/subsys/net/ip/net_context.c +++ b/subsys/net/ip/net_context.c @@ -1480,7 +1480,7 @@ static int context_sendto(struct net_context *context, { const struct msghdr *msghdr = NULL; struct net_if *iface; - struct net_pkt *pkt = NULL; + struct net_pkt *pkt; size_t tmp_len; int ret; @@ -1689,15 +1689,6 @@ static int context_sendto(struct net_context *context, return -ENETDOWN; } - context->send_cb = cb; - context->user_data = user_data; - - if (IS_ENABLED(CONFIG_NET_TCP) && - net_context_get_proto(context) == IPPROTO_TCP && - !net_if_is_ip_offloaded(net_context_get_iface(context))) { - goto skip_alloc; - } - pkt = context_alloc_pkt(context, len, PKT_WAIT_TIME); if (!pkt) { NET_ERR("Failed to allocate net_pkt"); @@ -1716,6 +1707,9 @@ static int context_sendto(struct net_context *context, len = tmp_len; } + context->send_cb = cb; + context->user_data = user_data; + if (IS_ENABLED(CONFIG_NET_CONTEXT_PRIORITY)) { uint8_t priority; @@ -1737,7 +1731,6 @@ static int context_sendto(struct net_context *context, } } -skip_alloc: if (IS_ENABLED(CONFIG_NET_OFFLOAD) && net_if_is_ip_offloaded(net_context_get_iface(context))) { ret = context_write_data(pkt, buf, len, msghdr); @@ -1769,12 +1762,16 @@ static int context_sendto(struct net_context *context, } else if (IS_ENABLED(CONFIG_NET_TCP) && net_context_get_proto(context) == IPPROTO_TCP) { - ret = net_tcp_queue(context, buf, len, msghdr); + ret = context_write_data(pkt, buf, len, msghdr); if (ret < 0) { goto fail; } - len = ret; + net_pkt_cursor_init(pkt); + ret = net_tcp_queue_data(context, pkt); + if (ret < 0) { + goto fail; + } ret = net_tcp_send_data(context, cb, user_data); } else if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET) && @@ -1830,9 +1827,7 @@ static int context_sendto(struct net_context *context, return len; fail: - if (pkt != NULL) { - net_pkt_unref(pkt); - } + net_pkt_unref(pkt); return ret; } diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index 2e70824b8ed..ad9cd1e4c98 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -1252,49 +1252,6 @@ static int tcp_pkt_peek(struct net_pkt *to, struct net_pkt *from, size_t pos, return net_pkt_copy(to, from, len); } -static int tcp_pkt_append(struct net_pkt *pkt, const uint8_t *data, size_t len) -{ - size_t alloc_len = len; - struct net_buf *buf = NULL; - int ret = 0; - - if (pkt->buffer) { - buf = net_buf_frag_last(pkt->buffer); - - if (len > net_buf_tailroom(buf)) { - alloc_len -= net_buf_tailroom(buf); - } else { - alloc_len = 0; - } - } - - if (alloc_len > 0) { - ret = net_pkt_alloc_buffer_raw(pkt, alloc_len, - TCP_PKT_ALLOC_TIMEOUT); - if (ret < 0) { - return -ENOBUFS; - } - } - - if (buf == NULL) { - buf = pkt->buffer; - } - - while (buf != NULL && len > 0) { - size_t write_len = MIN(len, net_buf_tailroom(buf)); - - net_buf_add_mem(buf, data, write_len); - - data += write_len; - len -= write_len; - buf = buf->frags; - } - - NET_ASSERT(len == 0, "Not all bytes written"); - - return ret; -} - static bool tcp_window_full(struct tcp *conn) { bool window_full = (conn->send_data_total >= conn->send_win); @@ -3098,12 +3055,13 @@ int net_tcp_update_recv_wnd(struct net_context *context, int32_t delta) return ret; } -int net_tcp_queue(struct net_context *context, const void *data, size_t len, - const struct msghdr *msg) +/* net_context queues the outgoing data for the TCP connection */ +int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt) { struct tcp *conn = context->tcp; - size_t queued_len = 0; + struct net_buf *orig_buf = NULL; int ret = 0; + size_t len; if (!conn || conn->state != TCP_ESTABLISHED) { return -ENOTCONN; @@ -3120,69 +3078,72 @@ int net_tcp_queue(struct net_context *context, const void *data, size_t len, goto out; } - if (msg) { - len = 0; + len = net_pkt_get_len(pkt); - for (int i = 0; i < msg->msg_iovlen; i++) { - len += msg->msg_iov[i].iov_len; - } + if (conn->send_data->buffer) { + orig_buf = net_buf_frag_last(conn->send_data->buffer); } - /* Queue no more than TX window permits. It's guaranteed at this point - * that conn->send_data_total is less than conn->send_win, as it was - * verified in tcp_window_full() check above. As the connection mutex - * is held, their values shall not change since. - */ - len = MIN(conn->send_win - conn->send_data_total, len); - - if (msg) { - for (int i = 0; i < msg->msg_iovlen; i++) { - int iovlen = MIN(msg->msg_iov[i].iov_len, len); - - ret = tcp_pkt_append(conn->send_data, - msg->msg_iov[i].iov_base, - iovlen); - if (ret < 0) { - if (queued_len == 0) { - goto out; - } else { - break; - } - } + net_pkt_append_buffer(conn->send_data, pkt->buffer); + conn->send_data_total += len; + NET_DBG("conn: %p Queued %zu bytes (total %zu)", conn, len, + conn->send_data_total); + pkt->buffer = NULL; - queued_len += iovlen; - len -= iovlen; - - if (len == 0) { - break; - } - } - } else { - ret = tcp_pkt_append(conn->send_data, data, len); - if (ret < 0) { - goto out; - } - - queued_len = len; - } - - conn->send_data_total += queued_len; - - /* Successfully queued data for transmission. Even if there's a transmit - * failure now (out-of-buf case), it can be ignored for now, retransmit - * timer will take care of queued data retransmission. - */ ret = tcp_send_queued_data(conn); if (ret < 0 && ret != -ENOBUFS) { tcp_conn_close(conn, ret); goto out; } - if (tcp_window_full(conn)) { - (void)k_sem_take(&conn->tx_sem, K_NO_WAIT); + if ((ret == -ENOBUFS) && + (conn->send_data_total < (conn->unacked_len + len))) { + /* Some of the data has been sent, we cannot remove the + * whole chunk, the remainder portion is already + * in the send_data and will be transmitted upon a + * received ack or the next send call + * + * Set the return code back to 0 to pretend we just + * transmitted the chunk + */ + ret = 0; } - ret = queued_len; + if (ret == -ENOBUFS) { + /* Restore the original data so that we do not resend the pkt + * data multiple times. + */ + conn->send_data_total -= len; + + if (orig_buf) { + pkt->buffer = orig_buf->frags; + orig_buf->frags = NULL; + } else { + pkt->buffer = conn->send_data->buffer; + conn->send_data->buffer = NULL; + } + + /* If we have out-of-bufs case, and the send_data buffer has + * become empty, till the retransmit timer, as there is no + * data to retransmit. + * The socket layer will catch this and resend data if needed. + * Only perform this when it is just the newly added packet, + * otherwise it can disrupt any pending transmission + */ + if (conn->send_data_total == 0) { + NET_DBG("No bufs, cancelling retransmit timer"); + k_work_cancel_delayable(&conn->send_data_timer); + } + } else { + if (tcp_window_full(conn)) { + (void)k_sem_take(&conn->tx_sem, K_NO_WAIT); + } + + /* We should not free the pkt if there was an error. It will be + * freed in net_context.c:context_sendto() + */ + tcp_pkt_unref(pkt); + } out: k_mutex_unlock(&conn->lock); @@ -3537,9 +3498,7 @@ static size_t tp_tcp_recv_cb(struct tcp *conn, struct net_pkt *pkt) net_pkt_pull(up, net_pkt_get_len(up) - len); - for (struct net_buf *buf = pkt->buffer; buf != NULL; buf = buf->frags) { - net_tcp_queue(conn->context, buf->data, buf->len); - } + net_tcp_queue_data(conn->context, up); return len; } @@ -3682,7 +3641,12 @@ enum net_verdict tp_input(struct net_conn *net_conn, responded = true; NET_DBG("tcp_send(\"%s\")", tp->data); { - net_tcp_queue(conn->context, buf, len); + struct net_pkt *data_pkt; + + data_pkt = tcp_pkt_alloc(conn, len); + net_pkt_write(data_pkt, buf, len); + net_pkt_cursor_init(data_pkt); + net_tcp_queue_data(conn->context, data_pkt); } } break; diff --git a/subsys/net/ip/tcp.h b/subsys/net/ip/tcp.h index 162407710eb..f6f481d5443 100644 --- a/subsys/net/ip/tcp.h +++ b/subsys/net/ip/tcp.h @@ -31,7 +31,6 @@ extern "C" { #endif -#include #include /** @@ -73,7 +72,18 @@ int net_tcp_listen(struct net_context *context); */ int net_tcp_accept(struct net_context *context, net_tcp_accept_cb_t cb, void *user_data); - +/** + * @brief Enqueue data for transmission + * + * @param context Network context + * @param buf Pointer to the data + * @param len Number of bytes + * @param msghdr Data for a vector array operation + * + * @return 0 if ok, < 0 if error + */ +int net_tcp_queue(struct net_context *context, const void *buf, size_t len, + const struct msghdr *msghdr); /* TODO: split into 2 functions, conn -> context, queue -> send? */ /* The following functions are provided solely for the compatibility @@ -102,6 +112,7 @@ void net_tcp_init(void); #define net_tcp_init(...) #endif int net_tcp_update_recv_wnd(struct net_context *context, int32_t delta); +int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt); int net_tcp_finalize(struct net_pkt *pkt); #if defined(CONFIG_NET_TEST_PROTOCOL) diff --git a/subsys/net/ip/tcp_internal.h b/subsys/net/ip/tcp_internal.h index 17d4581aa3d..e76ba859e49 100644 --- a/subsys/net/ip/tcp_internal.h +++ b/subsys/net/ip/tcp_internal.h @@ -282,27 +282,21 @@ struct net_tcp_hdr *net_tcp_input(struct net_pkt *pkt, #endif /** - * @brief Enqueue data for transmission + * @brief Enqueue a single packet for transmission * - * @param context Network context - * @param data Pointer to the data - * @param len Number of bytes - * @param msg Data for a vector array operation + * @param context TCP context + * @param pkt Packet * * @return 0 if ok, < 0 if error */ #if defined(CONFIG_NET_NATIVE_TCP) -int net_tcp_queue(struct net_context *context, const void *data, size_t len, - const struct msghdr *msg); +int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt); #else -static inline int net_tcp_queue(struct net_context *context, const void *data, - size_t len, const struct msghdr *msg) +static inline int net_tcp_queue_data(struct net_context *context, + struct net_pkt *pkt) { ARG_UNUSED(context); - ARG_UNUSED(data); - ARG_UNUSED(len); - ARG_UNUSED(msg); - + ARG_UNUSED(pkt); return -EPROTONOSUPPORT; } #endif From 0a160a5a535cf1b02366cb3b0c4a5da958fd5146 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:25 +0000 Subject: [PATCH 0545/1623] Revert "[nrf fromlist] net: pkt: Add function for allocating buffers w/o preconditions" This reverts commit af993b28c1dcde6c52e55517801628b82429ad78. Signed-off-by: Dominik Ermel --- include/zephyr/net/net_pkt.h | 25 --------------- subsys/net/ip/net_pkt.c | 61 ------------------------------------ 2 files changed, 86 deletions(-) diff --git a/include/zephyr/net/net_pkt.h b/include/zephyr/net/net_pkt.h index 199f78d2361..d4011d1f582 100644 --- a/include/zephyr/net/net_pkt.h +++ b/include/zephyr/net/net_pkt.h @@ -1678,13 +1678,6 @@ int net_pkt_alloc_buffer_debug(struct net_pkt *pkt, net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \ __func__, __LINE__) -int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size, - k_timeout_t timeout, - const char *caller, int line); -#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \ - net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \ - __func__, __LINE__) - struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface, size_t size, sa_family_t family, @@ -1799,24 +1792,6 @@ int net_pkt_alloc_buffer(struct net_pkt *pkt, k_timeout_t timeout); #endif -/** - * @brief Allocate buffer for a net_pkt, of specified size, w/o any additional - * preconditions - * - * @details: The actual buffer size may be larger than requested one if fixed - * size buffers are in use. - * - * @param pkt The network packet requiring buffer to be allocated. - * @param size The size of buffer being requested. - * @param timeout Maximum time to wait for an allocation. - * - * @return 0 on success, negative errno code otherwise. - */ -#if !defined(NET_PKT_DEBUG_ENABLED) -int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size, - k_timeout_t timeout); -#endif - /** * @brief Allocate a network packet and buffer at once * diff --git a/subsys/net/ip/net_pkt.c b/subsys/net/ip/net_pkt.c index fb44490dd2b..57ba0f3bb0d 100644 --- a/subsys/net/ip/net_pkt.c +++ b/subsys/net/ip/net_pkt.c @@ -1197,67 +1197,6 @@ int net_pkt_alloc_buffer(struct net_pkt *pkt, return 0; } - -#if NET_LOG_LEVEL >= LOG_LEVEL_DBG -int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size, - k_timeout_t timeout, const char *caller, - int line) -#else -int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size, - k_timeout_t timeout) -#endif -{ - struct net_buf_pool *pool = NULL; - struct net_buf *buf; - - if (size == 0) { - return 0; - } - - if (k_is_in_isr()) { - timeout = K_NO_WAIT; - } - - NET_DBG("Data allocation size %zu", size); - - if (pkt->context) { - pool = get_data_pool(pkt->context); - } - - if (!pool) { - pool = pkt->slab == &tx_pkts ? &tx_bufs : &rx_bufs; - } - -#if NET_LOG_LEVEL >= LOG_LEVEL_DBG - buf = pkt_alloc_buffer(pool, size, timeout, caller, line); -#else - buf = pkt_alloc_buffer(pool, size, timeout); -#endif - - if (!buf) { -#if NET_LOG_LEVEL >= LOG_LEVEL_DBG - NET_ERR("Data buffer (%zd) allocation failed (%s:%d)", - size, caller, line); -#else - NET_ERR("Data buffer (%zd) allocation failed.", size); -#endif - return -ENOMEM; - } - - net_pkt_append_buffer(pkt, buf); - -#if IS_ENABLED(CONFIG_NET_BUF_FIXED_DATA_SIZE) - /* net_buf allocators shrink the buffer size to the requested size. - * We don't want this behavior here, so restore the real size of the - * last fragment. - */ - buf = net_buf_frag_last(buf); - buf->size = CONFIG_NET_BUF_DATA_SIZE; -#endif - - return 0; -} - #if NET_LOG_LEVEL >= LOG_LEVEL_DBG static struct net_pkt *pkt_alloc(struct k_mem_slab *slab, k_timeout_t timeout, const char *caller, int line) From a84b8bcc6b222ab92bc6f756d754453e37011e45 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:26 +0000 Subject: [PATCH 0546/1623] Revert "[nrf fromlist] tfm: Change SFN and FP_HARDABI dependency" This reverts commit 1687aaaac27cce09921a015a3f63c79666ebdc37. Signed-off-by: Dominik Ermel --- arch/arm/core/aarch32/Kconfig | 1 + modules/trusted-firmware-m/Kconfig.tfm | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/core/aarch32/Kconfig b/arch/arm/core/aarch32/Kconfig index 58d5253cb94..a14bcd0cb62 100644 --- a/arch/arm/core/aarch32/Kconfig +++ b/arch/arm/core/aarch32/Kconfig @@ -267,6 +267,7 @@ config FP_HARDABI # TF-M build system does not build the NS app and libraries correctly with Hard ABI. # This limitation should be removed in the next TF-M synchronization. depends on !TFM_BUILD_NS + depends on !(BUILD_WITH_TFM && !TFM_IPC) help This option selects the Floating point ABI in which hardware floating point instructions are generated and uses FPU-specific calling diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index c09d922e9fd..2a5edb64343 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -323,7 +323,6 @@ config TFM_IPC config TFM_SFN bool "SFN model" - depends on !FP_HARDABI help Use the SFN Model as the SPM backend for the PSA API. The SFN model supports the SFN Partition model, and isolation level 1. From 8c6d7f2d5c984cb7ced81a0fb876137cfd397ac6 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:26 +0000 Subject: [PATCH 0547/1623] Revert "[nrf fromlist] tfm: Fix include order between platform_ns and tfm_api_ns libraries" This reverts commit b96a183abe7f07a90ba844c7928740d2c1b3c96c. Signed-off-by: Dominik Ermel --- modules/trusted-firmware-m/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index 177a47e28d6..f00116cda2c 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -435,8 +435,8 @@ if (CONFIG_BUILD_WITH_TFM) else() zephyr_library_link_libraries( - ${PLATFORM_NS_FILE} ${TFM_API_NS_PATH} + ${PLATFORM_NS_FILE} ) endif() From 0b2fed079a4b7180306a04b849552c9ad809203b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:26 +0000 Subject: [PATCH 0548/1623] Revert "[nrf fromtree] tfm: Enable TFM_EXCEPTION_INFO_DUMP by default" This reverts commit a69bb9315bcd02096bbf27f13038a5c0a1706632. Signed-off-by: Dominik Ermel --- modules/trusted-firmware-m/Kconfig.tfm | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index 2a5edb64343..bafa5cf0bab 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -446,7 +446,6 @@ endchoice config TFM_EXCEPTION_INFO_DUMP bool "TF-M exception info dump" - default y help On fatal errors in the secure firmware, capture info about the exception. Print the info if the SPM log level is sufficient. From b4ca83cbbe13ac10a83c52d05e7a3c3e66446733 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:26 +0000 Subject: [PATCH 0549/1623] Revert "[nrf noup] boards: arm: nrf9131ek: fix docs build" This reverts commit 56f475ad3e6fe5583a7478db6dfa47fad3485d35. Signed-off-by: Dominik Ermel --- boards/arm/nrf9131ek_nrf9131/doc/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boards/arm/nrf9131ek_nrf9131/doc/index.rst b/boards/arm/nrf9131ek_nrf9131/doc/index.rst index ffb066d860d..a72cd1526e3 100644 --- a/boards/arm/nrf9131ek_nrf9131/doc/index.rst +++ b/boards/arm/nrf9131ek_nrf9131/doc/index.rst @@ -210,8 +210,8 @@ Testing the LEDs and buttons in the nRF9131 EK There are 2 samples that allow you to test that the button and LED on the board are working properly with Zephyr: -* :ref:`blinky-sample` -* :ref:`button-sample` +* :zephyr:code-sample:`blinky` +* :zephyr:code-sample:`button` You can build and flash the examples to make sure Zephyr is running correctly on your board. The button and LED definitions can be found in From 5d74d40ee6f21bb3549831919ff5b4ab440fb3ea Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:27 +0000 Subject: [PATCH 0550/1623] Revert "[nrf fromlist] boards: arm: nrf9131ek: add docs" This reverts commit b0177d6df95deb539e3ddc95048faa8d0c4b69bd. Signed-off-by: Dominik Ermel --- .../doc/img/nrf9131ek_nrf9131.webp | Bin 75800 -> 0 bytes boards/arm/nrf9131ek_nrf9131/doc/index.rst | 228 ------------------ .../nrf9131ek_nrf9131_common.dtsi | 4 +- 3 files changed, 2 insertions(+), 230 deletions(-) delete mode 100644 boards/arm/nrf9131ek_nrf9131/doc/img/nrf9131ek_nrf9131.webp delete mode 100644 boards/arm/nrf9131ek_nrf9131/doc/index.rst diff --git a/boards/arm/nrf9131ek_nrf9131/doc/img/nrf9131ek_nrf9131.webp b/boards/arm/nrf9131ek_nrf9131/doc/img/nrf9131ek_nrf9131.webp deleted file mode 100644 index 056296ebbbcab5b514be7a6f30771f3b12167bc3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 75800 zcmaI6V~{36w>A2-d)l_AZTGZo+t##g+qP}np0;iGv~53k-g9o;^ZoeF-4R*2YHeiZ zu8OLR9jPQKCWb@_0#FwfQczR)r2zu~0BHX;LNEXs2tZO;SRo(u-z@+%-`d#537ioC zu(5S^R1y~=($Lf*f;s`f0uTZ402%;}p|O*_pn`(Tf2{xS^1K27`HyCi?mw~q?>7G{ z3vXiTWDEd+5dE_dFt&Ge{)Y|zVRkoX`~Tqde;Cd9x1q^DT>THzI{usBKfLxI-sr#a z<$tjGf8qaH6q=)olJLK^q5b2D%>NH;^nYOE-;Or_Y*_!fYLv` z(Es9(^I!f7|GbR;d07CA|9OZ2>;N_Z!~gOJ{O1|`v-v0glUpY<7Uut=K;VP`0EitR z@PP~ffJy=YzT$zvj{+d@s}KMH+X4XkZU4vLE*}8+_4JRA{~wMt4*)<61^`7ya7)+4_8Gf2DovKjq#03pn-x{~h&p_MbzqJMU}qGwr$Va`%yc!8-=nc4W8w zZy@z=tLNFRz9T|S--@rK&#*VdEB?>EC7-FUx)1eN#I?MO-B-VrkG$L6SB5+NX2QL` zYrm5Zh)=uM(IzIwuqz7M~m_tf-YS&-MkUF=CBv`$h6mpE7U1}MMS@U;n1`^lhVO)O1 zMf{kS6i=~4K^vR|Q2F^?k2fS;2K$8DL&^Kks3BYARb*F1+ zUz@4ujr{Ffg>5-IG;XBt7KJzVbcHTfF(2VpwUCm~217(>?su zT}Y}m&@(}vkb&WHwNHv4kB$qgF8+?+27a!n0LarnE#Ss+23ZTfR^RFL;71ERyHT84 z{;R_|E#-_TkNWiUFv=NP!~(Z7`|i8O&1o;H2;_8&e>JOo%AtM51S$KyeE#&siXYxj zTSM2zkW-^t`ueib6YADfoyrnvZ~x4--``5ML&dCF{>NR00(O^39Vr<*464!DLedjP zGq%b|b{2q+o*jB0Yo1m>;iDs<%G!W=)2q%s2g##c`}~B4segW%@Xy-bW|ok4Tt{7s zU^}#f)2^t@(~B^bm9s&Tz+cNkp}A4UUx9qA6T9gol0V~9F6Oasj42*Iz}4+6Q|#)* zXR~P)tCwEN3SNT$iq$@(W=hT|#WwGHAB(ntKN=j;e&4T|K0MCyr3c{=Fl)cFL6@bMITf@!@UYD37d(14! zI3Ic>ra=`?asp#7Q>c#YI|d^KC5`!{yB#EamLoMNf^MYZ>$G`KcFKmrseA)|lf zgSQ=f{NGmylRDMX z(tprBS2OGi%x1*NC}Yz^l&wmj;FHl8G#3(E07t?(kiDxG_SaY%St`hxCoM;sDB8vx&UpT;1A8e`(8JkgT zLDl*lI~g{GQD+>B^_VaWRKu{3mrQ!@7q_&T-jYu0pWBbEMKt^;K51%1z{ig+G3oVO zmu*tdN9b8GfLk8@4~&?rg2U{4K^JxFpM#R^8-r%1qq&PigHU0h4;H|>`$U)p`_VRC zB$oa>`45IhhDH}dxUHh(k@3am6DHN@mmncqT#oUA8o%U^SFZ7a0R-jl0b1xBGo0+7 z8{gg-_1cXGB$ubbx!(PsU0%8VYjUTw5*qbwT~12wSjGu0Gn5fEWSw)FqKsZT?cjgV zjg@Bsg}U8(MC{c-tS67V7{fWBstH6L-ly0{1>rke_0VF*c?rWN4Vwg zEk_D(;Ca&^jh-pA#Z+liisC`WC?qLkB?tVcW$q_aHroTvtM*SnwI6Tp z6jizLq*WHYF4_Ddvab>olyOEdN#;6^cxh0#4l*)F!YqM*0#70lVO_l}GZ}vx z?R||78^<*hUX7D+Oy8us=FS==)>Oe0=G2`22PNr`t_p`Tm1?Vor}uRmYZA=yHx_4V zCfO^2Lle>h548c?B%xF^qC^{Wvu;FpoyJ)$H`E*@V;51~>ATx$Rg0_sh?YWCE%34} zIINp4HhlOXge%eXcdq``;tGIV=Srg9+Y=G+~+Lnk$vO<#qV zAaw_vh$GT`KZG=_$<&A|#ly}hm1lMrbgSmtp@G*R%Ee@ifXX=c2BiTL%_xs5P$b4q zGz6(}KOk9r1@u$&@;8-J3^z2%`e^!LSy^LE(VZ4yFQuuzibwFWzN=-K`S=xt6B>L= zYrD*VVvrH*=JY+zQ+c4>ozx93$BcCl zbWgLz@H0$apZ5OwZ8urEhkg&57E?u!I7*+80a_im7X1mQFHM7&w18s$2DdR0=#-Sr zv?A56v+yp<$nR{Yw{XJz=xo0{#uhxC&@}}&} z5O(9QirJ{qyM@M)HmWhUoj8kFHwt2S25BI48IH*P?6JTvr7(lD(KuIFoP}j=w~5lO+TJ<~B&S`bGkiFJ-~?Do09a(k%Nw z3s}j2hnRnQK6wvJ{|IaQ2!`6lEF0-~7H_(D{p#+>%qN&6KqhgXbq*vEL4K7GiY(|s z1A;;C^GXUrEdB-SMWtmHPPCv5nX#$tas9J5O{2p5tR{c=Hw8H&s`i7?bQzA67|4PFp2)PihNS8l{Kh;&NAT=LQid#lq;vW}Hg<6MgGy?Vg4 z-l(O;+%!bq>J&9%8^7GoNv;0KYU`Dn8Z#zgj5hiei0;BHo3GPg0-^xhAF3cJ{9PfDG5 zoACvimvP8ws=9e}x6ZKZrkP8l?O!rj{uCVHkpNf^p2HK;S&E-q;dgJ$*_+8M`pk4i z7IlScRdZ$4zBT4$MRcgXGhkFsvuMW6u8Aw?zEZw+FQ;TS8$Pie@7^v(c(U5dH%M&L z{FASFl3`sUgcy+)H8#oY)nN6z)NH}BnJpvFQ$nY&FHKc&jOtH<7iFSeXS2gV+YSuQ zPN*9=jD@NlRCE-74F&QBsDl9GM0UC5qIU@YV4Rn1HnNuDNe5P-F1>So4 za@4;-U6DVQr^x<5q`ij3`Iv~F1?7HcFRoa9aTL%&*>(K2-#rt3#5GHMu-wy0BGyLP z40;zf6Mx41aF9)bKDCtH+y=1*L?sA3nIeC=DdS!*E~b3s7f&HXH9|08cv8sK?wM#r z(j`oJpvtB^V)YmeU#r0$0pse}9LJv@3{c?@7F}1{g`K|YQ_z?n)9OjT8d)8}(8T`w zl${wuM%Ig7eCf0&_|e!ltp!O5SL@ofMuN=4h1GET~+H_ZtSwf<-&XrlFu->vuFeHjuB#77} zJp3AdbUXAEsVS3iKrgAJA6I@lMLIUB@9)q&LgTXXz;Zp!Pn$$7yM63D!li6u%Ar@M zE{UT>Lo(RI?L20u5=+VZ1F+K?lbXFhi2rq}{r8eNzJZDzR0}73#6HCpaIHoeb=~KW`Y>v>2?~rz+);qlN*gbCawbD+~pc zL*||;ZbT5*I=9Cq=e(&LnL_}VT>kfxM==+=;AQom^Y&jN!AL$V0uL03aHGRkA*qF0 znopL~f378(F8%nY7v?P?b=0vk3fEJORj+{JKK$nl6k!zC`IS{x8!;vFID0lfsOYwVO^GjDs)ev5NhzgrNsq(weimQ8Ksl zM5FL1H0{S4DsOBE4^?+I_(!UGn*Czby?z66YMtapJ}tX8#b5u`WWIsD|EVbb zx6qqSg?J6*XL+LD{Xsq@o;&Il_$j;mi}!Q0ympW(mu8=cLIDK|J~^BZ9_Np_;Y3PD z%7$sGIbqHuRS_3+Jn_RUC*8->_1lPsj_NO}u2)(lck6QCU|Z;hww~@h+SRM)c45Ie zP2a|QZwrrl(hKzx~?oJ2)7$vyj>L~yW#h5O~>YS zqIZrNGwGe;qu{}4+$IQkb_l{#+eNKmNQY%U70jk*;Wm$WgxjRPJpMDi>Lo0uDx{cj zfj`Mc6Lm8e-!Or(es!d_yE#iRzb^#&9ev9JTXjwA+NX@K-mSG*7P>;U)6nf3AHzN= zOMFQ|x!oMRd@D6Om=Ukjx6z^S*62HU%j*R96cDl_gL87M=Ui>yppAMHDC-Kt-$L%D zq1MRGAX>}kKXPtBH9W-J?p}A`JLJzrPk;RIV23&+7Tw;3pjAbrK@1Q_eo#^3N)MtJ zmP?(vM!3)S?Jc5BN3lQf$?>t5z!rZwFss_7$hrK&jMX2QymuRZj?uE^f+;r`%0lW> zZ)~JefoI}>NJ-Uba=nWA+nzI5m0}-`X(#31qL!uTL{&&Z@~JPq#9)Y+ylE?$%ul?KuM$OfnWL+Pth^j7wWwIc|E! z4HZzX1YTEL_;bSClhxpsEV{icKAGTfT=M5eX;zf;FR2o2;Klnu(h%~tL}*H#WCtXZ zWZ0fatJ~0_H&EbJJ^`QHlBh-5MjfuxD?6ne3^D)m>w@*4+IC51XR;b z%F}x4CF$>l77+6AhjC(cMxNGK>Soeum-DAyusVz~KW|-$VFCGMNQ%?F(q-5{F3}j} zN|g+(hJuTc{BCr4z($m|AMyTc>7#g&Z-pQW`DrSiUw27$81hTY`gXQ`REEhXU$$Zz zi09d>lhlg0>~Rr}Y>_F3KpSLTk*|!i=!>^<5#(#y*ISp|Od+$RUFdgbwV5Pa6p}4) zIhZN}@ue|Vv-BsIS-#V^O4m(Aov0}}>ZFCQ?6p?D1pnK>l^6IXl4cr?t*X}t*x$47 z$*uN}jYCp}kK?>)oZ)P3@E@&lJ#K5zulD08n~jfRo*ROs=eN7iK}hcUsNt_}IyhUr z+tr3aEejj|wlEm!KwMF$4J9dzeH`Dj4=YoHEGfsILeVZOu+pcy&`naE~rk#JF_q;dpSeZYXaf`>5jDqjALRrd$27%H_ri=U# z*xhmGLZof`JADH4y9-(O(b4ovk`F|vFTC}9!K_kSayBe|F9^0++JE*EQl8sVLeOp6 z)X(tK&N>>VqU_5MnjMXg&4EzuQ{z&1L?e)PQZnUAm;@gDa%PYL zR92oAoP6&YuJ@%0i4dQfiMEjOevkUvf>*=JW{`3P{)hTmt`ik(WBSItkcvo8j(X(Wy}d3|*kJQ4=R z>?BsOb&(iaShzO6CEt<neRr1tm#_daE{KpF zyf4&lYui#jndHgswr)Kplqc-f{`=kQW>?QW?$-EMeJ7^kM$>FvBPtUA>MGO7-uYo` z2I(v}sRKlLh1fMy=TAQY9V|)}Ib(7x_umJx({mBKK-=0L`?Rz{kA?$hCLnHZIbK!p0;?id)Ue9@iyqGR5gw96wB%RsNhjVY0XGM7i6{Z}2}SG9{{9%&pG&vK=y9Zu zdoZ2E(ru7^F_xvXgxoRJb?gf`gW}AG33p6P6YKy%8JDRb)8=BGPffNFVC3+d0kUgE z0cPVS!PR5x(JZ@Bk*um8IcW z2?r1b5k9VI!8$l+I)i@hgWr!I$8)`FDyf8p8V6p3ZxwgcV)G;&(Ag^q6+R4TeLO$h z?)O*_gdT{Gx}PCtK#>i3aog|(9tH-zNKYpdM`00bJ$*YcUJZ_@;2l^QzF3REC{9EmR$yZIc5b=idg$&ybj;ZSx_oCQ;3?)yL`)WbbO<{j$rtPKX4SFAt}e9A|(Y@0G>w=6&6ekt9~ z*-TALmCZBGY@>`=^@2xdnl=gE^C-1dd!Qu8AX3E{q31*54r0;*!QnT< zZ&kc)j5~hXNIT-i&ulgTdm{Ks%s?i6iFn$bYZ)qLj04le4$zxgZmGjh7o;^H6--ZS z1mAYr=8*!0Q_kcNOPMhHpp6$M!{W=PgovsYGgDW6oO0ClP(y= zO%6f7gT7z-)3$jR@nuG$n`una$5@Ro_jlbBg05%w9(EvM< zl1n<3pQWs2Bz+O258}nboT5rTo7EN#w{DU$xe&80L;Vvd9z-=9=IXWL<|TNs6V^A_ zh&?o~m_HQyhn2CKjW8g%$IfHKaCM|mYqD58 zR18F5L1cy^P(K3Tn#Cx)S5_1C(Q!RG35StcZpV5=-~8pCD;LPBF3P@wL@ZbZof1dI zbXB9bWVWjKSBIpsL`lEN1nu;z`%g*a%d-e)I+`*^wtpa!E#KQk@~@Zb-}Kd^JFL3O%pX1fbMg(Lgkn`!_9&rl+g9YuSds&#O#D7gwkFs^*84l}l0QW^DOAvl zltRv`&kl7m-CxuV)?pal)ASU`$sEHHY z{-)5{A};E3)!5CsIfw~iqv{bW}AEr&OM~5LsL(e zW-NNvLsST}zQ%@!-rJOuH(T=ufiC~o6!4{}x z*5FGwitRAe3a!sNxlzFs%AaZ-cIAa^*DjM81*8jXj>p`3G zU+p8e2cu*aTC{Ysq^q8KhJpYr*q%s{jz#f!C;m;tZPY9b_vv>gUm5enr{y*UpGPR+{(y2}>;Oho2h77~L3Ubv$M3AKpwzj=f6F`MifV6V!fU zvln7uM>;*`d^`JtCd`EX1vXuL1VN$<{sNF<9gG4 zSdMT8zoIvm7_AohOM-N;lS1iX&9zCrCLW8ysr+;Zn4SSBm{dmoHf{ZkYR`VClY;e9u8z{-- zX&D?W6?z<#FVpJX=Ia5KGkNJT3`4aSLB{7FQu;glKHQz}(Z?*Z>NHPghiYOIa*^tI zDnbKWFmMMmE`nyft1gsE)ySaaM)ji(PkTW5C`$XF)|aK@q-edq4{qehkayy}5)Fy; zbG!p%S@JHvcz@RKrTew}*i=oMmg4Fc7oxFEl)(&X|2t|q70%YuGg91O-c@jR7hFU5AhL)MGuIQRzFElik_|P!qw5AD?Xf#|k^JBMOZ7RzNMD zO+@K1lwo131*;4wQN~O^{`vkTACp)zRx}hZ=+8?Rx>FFg#2t>m15X4MB<2%SDAN{e zknan&3^jK0%?fWl@`0z-am&;r$-)&r@ASX6-@pb8Q&gH)vfXZ#&INxntd!IQRy*Im z1S&EohQp7)0(d}W6`^Z`MHXDS9 zA@=;PqP_>KzYY<7BA!}H-rUk;(P#ViDomQP7wZeUov(xiM-1!f)iw_D1`n5F1PTr= znHW%t4Jid-U4{2$t&irlX4lSp=t2F@4Io1ewVo_yj?|X!puIatb>`Gy;P99?xnyQA z#R^h=66URg_P-LRh zk%#w2|2)_tESg@5SgWL;;V3=!;&WZP`?5|E@iIRr1objfmg&&4~=#A4* zJMD)2DT>doDTF{KbYK&jq3#ekMFx8^(p`OwAjSe0g@z~XNSw0qvTJgr@-j!1YAckH%rJ8EDES-*P)(K6K2WCJbD@fFWb=rudOAL$TG zCeou2*{S3y{TFpo{lqH{-LO$U0a0cKD5b&9<>V@!{9WtuH;#uq(2$?`k59z)(Hxo3 z?DSE#=(m3PAkqRvv{nIuTmY9!m$ar`0j>2`bz~d|DP4egmU@BgVzaGB!wKm#4SrGY=GazBj1;IS*+AXafmUacjy{Yz6)b_2y>m-L__!hRx zH$8Wl2#gv_0ikcH1QQ^ZDfJxyUb-PuMx^edU^1r+D>*CpS_yr)eWnAsFo*AICXujc zcS`5grQAhneKDdni`*R3$SltAlL!D5|K0UH{L@0V%v8!}S_x&&UvK92az%I>q6X`! zHMNNr0$b9m!TD-wXHRwkmr!u`=^3?qj#-!U;a}NTdI(caS#dHIt~TA@?>CR%A>kNO z1!BXnk*o@yadT>Hlwg$iQK`VGLn`{oiZ#9S3(uk+h3Y0Ap?SmUkX-^K+ka0$Gnrw1l?lm=we%iV0T+@bs&zvGVI(PC*q)v;)3p7B%Hw4s4r zQ2JXJ&kTL$;zSwctVQ#&lO!Z&1lGTO7`8kwosanFA-V6U;xSW?W_itoq{(-vVU8$j zc*=ArL>WtH{LEsnqPdh9zpEEsP3yy1J=(mbQiNj5RODUmcbjHje zX+x zK(JUlz66E#bcz1@DIoyA*(reNmIlvWl0F~zyz_*pf&~!p>GtP<@_&9j z9Ox4B5F_|<>qVNh?x1I+pPtd+7N^yg{!B}FQT|p(fuqw!XZr!NnR#97g{@`W8&g>c z-(E1p1DckIvaAS-`umDGL&Kw_cl$`IqBOMj5-`S2LBHC4qE}*8Dg(v*N{oTBJvQlP z4U74SK+mp&W2@Vz%wo6(ty53tjuI{rjY$Mw78!8nqvhB=Xm(kx8k_E)_UJYNadx!{ z_j#WSr^>U^^9htmZ&|s$!zk2MF*UtGyx2TKjzMv5NDeOA?EVftz268`UJ@vHl2HNm zwc0UnOeh&B?4lT{o*z{pPSO-XWR++l4`|1X40(5*GHBSlE;zASNVbXP{f*Pd(#jk5 zoUWxYU3%r|UTv8WP&4>!Gc~b}Xy(kSU8^5YUKLa*1A=CSdb#)z9dnSOi{%OF+f5pd z?vOJkO7@nvMO+`eAp0*ZQ-bWPefSsb+rQ}l+%c-;UUq#qfUB;>_6>i4U`7XOdBzTq zW@e;P#=PqKqp9>$PrW!2Q(Yod)aN8)FJj5AUAQjU(xR%xe_BK%Y z6I&As1TcLzW?I!?a63`qB<1R=f@ek8@`WwCDY8wl!3DWT0Y&1P$$SmO^LVK1edk_a_46kDcCn&2%5#baEL5P(VD}PtDCeu9?_@-7$75e}V2+Q; zLCSNINh0i7k{(poz>h-DVwv&k>xYH!c@}cz!u0W&6%`QG6YB#F93bsLB>rf~=y4sX zkz*nKX@T7|WQ^Umo)Dp|me{wTiZA+bKQXPu9Y)tYrHJR)PYu|byXoI5aBpH%4a65z zLe0*~_RV3)9v;hUEv7seNNfC8>vmv+B=q>~qx<5IWoc7lwLQMY8p|u$z6q-uc({Cc zUJt3vGY56ut~E{a?N;}MKldmG(~I-|Q%87GJ5-* zkHS6Avr4tnTc&*+-qJ!}xrZ<=s+KGr)XqD&rMaLDFP4a}VNS^jW7?x+ZiOU%m^gSY zK~KsCL=J*))U<%YXbp95O;RZTgecs1C_C%yn*A9;)KpRWiC;l9=3ju!1fR@dtq|>s zEZt5GO=Z})s@Wy6Cyk(1u#iVOF5rKH~WTC zSiTk0de3Rkb1&mfT=6lYMAu=v?v=hDTqcmQV0Ug6=SK5d;zj+qQ z&)=O!!nBXLLUk=^c11f>ZYn&WnYuFOu^L=_;Xn3klc#RueX@jvGI7k0608*G{@ zqn}O94dXR(uS{FNkAuuu{bDv`vXs!ji%4=x@QHpa<>z7}BDYoc>ddbVbjhtF+&6(Y z&$pxL1L-UK2oMRPRj@91e`ruz8IJ9N_IJXY{-F^X#-)1hKIshY9tAgusK9Go2w(bb zw+yk+TXTNz;E5d;Pvu(D2}^m+RqpTy`RVMu}F-EI~ylet(42w3? zgE~P+O4u{Ir{W>eg47LzAx;GD3ZCN>1F=X}H-b$t4Lk+Nm7{_fK>3MiZ!CzcxMG0| zJ8{YJ&t+a`^2*jSs~>uN6N@_*#Cl9 z;Ea6C)oj;XxaJoeZs6s8q(P+}7_jrFzGTquaw3s-?dw`BKCeGg!_=yP?G}-3f6)lW zxk>DnnA0ixLFO2)Pq#w1eB?sDQrDc0ouJDLaVF2ZU8vY@2*jHs#h_h!a5aX_1fzgo zxGJK&lvfj6tYuzI2(429m`Gu7b?>;0Ohz`i?K`N2*?_=st#zk4#xSuowBY)N`>K?X z5fap_#|+nAzJE6);%T^5@F7l>RgBkL$yu9XwXxQt@bk|@qASo5I7Wq=a?iShZd(<- z0ajg_KRP|4lZRodlAchEe1J7`g@hJc9U~UvlGzhO6m@_K@q<%`SH<`1^FZX0{;6#1e zk^p=_^X443)zQnFI5`<@=1#)P4dgdD-8gVee066=)ka1+cc#e|U=TLpAosM0Mq6NO z^uAWF^5rUeA-0LxS=TVYb4~fRVikTwjGGn*UY@q$O2g+bv$m>&v>Tx5F|m%ZHU!7w zgYo2Vy~jp(3XMpWB0|49=8}awD}aLD=&-SEwL(@Kx*4+4jC>(-GyR&$C_KYVQ~3CN z9NfwvNQ3tyFjM!apUfcyrnJBbwG}#FWRzkTZYV+%CLGts%T&doU*S9UN|chNDDmLX z3zM++8Pzx@^)~N=bH1Y6W=j}Bk~}SA5FpEBPcqr>0&Bae{o!EP z_4N=v)~K&OeMBIWr2mI_r4dxSVbmcq4m`UNw$In!6shOc#{F%OmqCJg?57}n`QjO- z7?~%yE+%I8Vjbvc+OC2&H@)jcvIwjAsmO#iUb0Gvehlb2?!boNEpi0Y>^+kq(WdVo zzF(qwLi{lWeEPcjY^090kvkWyIM%s$x9ggnUWNk{>5U_ca?&*W;cB^7n2e02Zr&(< zNz-kRkAZXa9dVo19eBX^aZ6z&orEXJ#il14-^U8b#Ie2VK?t|nVX-s4y^ODVbnf3X z31sA-vZG9xi*__L4Lw(uY{WA&!>yc!DjuMCZsr&6zyQj-ALEJmGb6X{r_UXt?rOJR zgZ4xWmJm!-^OyXwSk-tu(rM@Alpas127~!*`xpz3c((E{WLuAtG4fI)E3X%bgg?P; zK&a>7FEEquz+{jhHqr<`tMou!3%0goZqMU(BLM?Pa!6~%(4?zbPoYXiV2C=L%UJRe z6r8Y*Wh*BOrjkRg#y?X?qJLTbE?s}^6E+1@KDw8<)Ov@~NXL-FlW%}(bX!T)T(S&3 zG~3IpPDZ&V-m&4eZ(u1>5-m~K@AXU-t|9H!keF=d*SYRyG+_ws>o z*90m+*uGz{Kk{R9B+(76B2oz(HA3Y(!+0?H$QM9p?2gA?2?>tTNnSlkHFffJXJ(rCY{EeBl=CBSv+O&mK3|5Wc{wx zw)pfmZ(Y49p*=;^6@%Sam{R}huE@i`612?ozd$(2HnB}VD|I5}B2)WaN|J4XB>O(E-J zl|bX*n^T{yhmLXV?D*u3!Kfix_8??Ixk<;Ftf6T3*qM2*yKt0dBhTH=BTzg9a~;o7 zp{k4M8g|U<0wxSZlvf8A>cSw8G50Y;=YSfZOMO}&sfg}U_xg8v2LW}nVq%&=r3c2TZzz2KxRtg$^*yG#+sH!;8~Sb zD)Fj^U4O{8w#DcX6vB>#YKksHrr4U1)Pgu`xFELqa~@jahx@`$V%5rE(N^O&Jd_0! zS`<#h9GrR;n2O>rs3+WzsoufAt>zm;Z6&>^k;*N&>sG?7C$%jowl;X!Pkf<9Dmo&E zcw1MEdm#c@*X2#Y+I4=Lm4iM|5>?f_k?TM`P^9;x_SedY5;a8w1wR+zUv#AgL|T_~ z4}1Pp>-Rm5dGxv`V~>(T4f8W77*osl7Oj9d%%VaKry>8gHL*O&$4+`#te=jbztn66 z8R&R+0)ewlkg`>gZAJZzDMI9GEp+aG$Gy9%!L%15>a{GrM!DHV2w6SL;76prsZPau zM&3<(rC~-G?14$HIs~$;&D|!1*Q7Fpw9i>N>}$455+e(k8tuY>OnQGb*fxLX+L>=7 zB#jJp%s?U#In0ogYwHTOCJE-Kk5-2Jr=(^XzUKNzYk$)B=`Jp}oM@W9w=dBU2&%++xs9OEMr|&;Fotnm=z#>fjs>J$Z+(bx z#pto~#Xn{)Uhp)`)e@XU#D$`GDAOGyZovM{8OL9FQz^P{FYr$LhismLF#2`LtxDgC z-C94|Lm9VXmm0*p4(fzI%D&&8cYc9N@ux`IW--6auDf#f;~M!Pkdv|w2imHAnej$a zz+^I(wP*$2RA*%}W@M0Ri*G&TdO{E}%kqT#Ex~`Fx2z0qcqByLztk80@qxYW|1mD3 zIKK8YFGrY@;7WCsX}kRfd&)76YTU$CnNDgKQX!NgvWGB)L%k13Tiqy1>0NsE@mNCG zzmYzR?i(qN&LgXoDO!d-C}C{{slx_%;D~T)KsjD`OV(!O$kRzGiz7~I;Im7k$A!r;24N4)yK5yD z1^8-JlOg;>bk76SOZ`F5_Gkkkt$r4L*RTs{m-Xt2A~G`OYb?pU`5_fh263)}ZRs7* z?%0TdIPhw6tf4+U&xizfa1wir15?~+2^v$Y52&l5|2d`9tIXyqq+sKiAQR|QWSUE% zkfk}Is!u)sE7kqb9#5=%DHdsJKqs46-&L1EM31Z^*9Sj0AnpTtx;pp{4hP9GVMe=8 zovn9wV*W`2p?~%J>22L8e<{-fj&GkM^t+!iY39hU(hi;lmF6#}FK`!F(rpvXN{8?6 z-XdMKO8TWf%FWrwo5?~$dG3t~{nwy%IJHc^@#mf7)zAG*j*e>nqgx{_(V5Z=srOzN z8rk=csFt;b5%h`5JejPXN1i`r^IECvIagjea(KOMtF@D%Jg`J*sCYay#0O%rWF{Fk z`Z9`nUAvPikvQ{GF`T16k1a{03_29`&hX&il4=zU%2NtyS1%M1P}Mb3tIS1k?M*r3 z3A})Pp#JG(FdTydSHLvP!^T3X#xTLR{UkKzGzhXEmR>A7+bTC9&lwCi8hM(GDr~*E zgbw+GQG(K35BB!TEr^r`K>NF08YNFZ##r#hO4ZZ+S|?Pj$Jtn=3e9v2^?6oNZXQXm7^l>q@0-50ASh8}(MHRpGjZJ4;D zR*r#>rqz_oZO!wGN-&rVHrHxPsoXdZ$rC%?6#LFLpx-xt?3?DS$64BAj`< z;=xD2Rb(eqV=cEo4B#&QTAhq?>-O|<*BOI@sKJXd=1^#LGJ?fQVg4w@)l6%8^tfgl zKYkzBn0xqa1oB|hk|KMeT#CIcvZJ*e>f}}0NYmzlzhx7?iXrvEzWA3FCHdF3J_#c} zeltG{$cCGb%h@J%PoYl@v94SJM7WD9y12KhaBb1aJ#E{IPnI@P1|`(hcMY*#8epY_ z3*@&bD8F^RagGxj#jyXkDQn1D&S96HN3*JO+uW1bib*Jj-i3wVO+&F$$iRDmQ^~>e zoz$DQ9s6%e??dZQ4IV~=J8jRui*A)#?jTJ54vz{4KGRSaX%uj&5E?wRxz1mEb_4WR z`SZ?XJ_t^W3V*X&su-gDIa8Jq-htX~H|2zNHo0Q5$&5iL?#G!PaqM8--a7$SMsvMR zHc&^}xdc=x8?(9df0t2Qg(-{B!l^!c6O0Fgdj?MLvC~Xz!k2=uz3P=als9@rDrl?x zApO2xEwYB1bsQ*y6ucz9vkf=D#bNQkp6hoApt^vd%6L!-v z>x$E-t@r{QTGQOooX1a`H^$w%rLH%*2DM_+O8R@=ah|}4c(yRQa?nKh<8Nwd45YZs z>zx@aD$0FxHaB?cCCPN)VVzwPp8heu)JrXU_}vWe&{h2|zxmwBQK*n^GY3n5P^NY% zt0Zk*ChcCBCv&sm<~)I*5-yLrnhvQB?5P(Cgo1STi`fn9y#YbKac$=u4gP-qK@R8TA-d$O_U0Z%Dl+Njp!={-*7 zD98xmLu)T$hP)ucK5dU-sQi$zcr_E|ARyxc2RZrKnUe2VJQ6ybE z2VJqZuC|CeIixFc|KRFHOWmu8wsMX!5YR+BGI>d#lwaG7xyuZ_z8_fm&6M;&0rC~Z zfaH17R{-D8sn}g)b>;@d4_YN5VLaGGdYd>EWKscaIWuU+&ujr_-w+N+<%(%KwRRW2 zq4F4PGWl9G0awc}2uKq!k9+V1#&*t_1p#&qt%JI3p-9}=;FgQN?5#O4{_018 za=T`Nn}N&9ZX%8#@4z05Sz#Jsq}G4g^~W&AwmkdTjho%?2T@sz zx|%5W*fF)Ht|j0-?EI=horsi~l_T!FG@#>nSb?Rc0S==+qu*Q|8r)}@6q>COYDLOP zQOywa3w~4nM-$xOZO1J{(29zQZEU`p34rv*8^LBy>Kg7CP?13KTNi>dV*Af%Nzb<@ zwch&y`L@*yjCko%ZF$ZVnGCE9BrWny*Zq0gpOK(_P+GoRI^IvJTdpBt8Au1_3WvuS z4%qK9CkGE)9f^Iu0aOHRZ@$|g4M?2D93AmBskh!;gY)KNU!{K$FKbc~?9-vtBe`pl z>)0A-A-guUCYH-0y7iG3Z$K70ugNk}?Kb)Y+yaeq%6PU5fsB&is2(1bY1P$<2CI3Z z;tqW-Ns5E0^CYp-k)#JxcqPAxa!lh<63Y9RI{H#Kcb1)2v z^%!Oi^ToTk<(oK;UykjA7r=ape17WYlRK(+$O$_I4(r25zLBEjD|jMZjj~sy1bkk| zs>aqK-nIY`b0E{X&^XSI_Q~3tf&o1lAz2P^>AuLAzccH+bPlSwzzH239tb<6Q(#J~ zNS}vkZ+meIGYv)Mllbr=eCq7KS8lQUKM8v4d~=5ZD;9C$z-?`C@ey&bufHj%d#@PR{z9U%R$h0}zpq;3S_9zikuaM+sdJ!o(j2p-!eAewbxr?U zlt8D@uo10?D}zVn2sXv36?8yElYq`L1c)#HtWUAb%L`uAZ)X#9lnP;Qd$hBbEII60 zbJ(!wnstHK4JTQ;dsgV>*KJ(bVocd^6_a4Hh)}(GID{6i^jee~AEht8n9N~rG^hBu zyJ-4Pe7|YnoIoi!&pZ#Uf8k0Qk#bGd{y^cbgIQyDVJi?@B3T#Ksv7)kMqdA~!nh~# zD5X$!k51iD`AA2AK#L#*qEQ3VZe$$+-L?;CeYO0puk2tNkIun-C0-Mftxtt4f9%Z- z?29G4xVspQY%h0j<9p1nqBXmtDXTT0#+VT}Me}Dp)BxFgIndFTb#nFa2i(9tx91uU}i}03IR$To~;EMbVI9e z+BpR6?wVur9(&@cUV!sUZ@DbYym(bg>!>O&p{~{Gh(9nUL9{)O}?@a4`)giu@m-U!F}oJWI@i2g70?{ zhs;MV%V%W?5#OY24<7Wcs+4!ejo~*Vgzs9Hk?XR_{FOMLZzGdALW?K%7Vi#JFWHnz z4<1~8C3etXlc^d=cT~`EQG_WhG#ctD?tw}(OVfG)_&5@?*a-l8Bx_~=>%|Q^ACZy~ zvt<+hQJ?(Jdi^O0H(V7%(%UD)77Yh0v8kbq?m6|v9IrG_aY10|GC0R}k*Y$D=GPP8 z0Y7Vrtn*NLRjF6DnWQ@$F@v z!a5X{{wb0V^tX`yZeQY`^xQBd<_I|_KAmkHm5B%7LA`V|vfUlh54ke$9F)OmGNaa(`#C_ER_`XLYc6%(ctZkhUYYh(EIP3k4k2 zZ*hwZBKc`qz1r|@IpSWv8*(b#5J|pG)p^_cx44ZRi^=Z4X;)v+j1(8$vTf zsg-)@*(jLo0+A6|i$HAz0F;93$fcDajab007`Nhx-|J5sYT?<2N$}4TQ$)TYfzzk8 zYEy?`{DoT~I?-AXLF9&pp>3mIx(JLu;`68OBA$=Q(mWbWyx!D{zNBax0vjWctXlzN zD@`PCgu>oGv_v}=%7SqwWmxQFg7Livd7F6t-Z>inigg1_zc>me`x3=%j5giD=Ccye zqGwmg7u|`pMOAB;l00$_eieR9|Eg z)Pz1O-ms?w2~P32&lEWC__pHL?@0lWDkVxz*d#z9UWU;D?V&g(4mUvtqg8+s1q0WF zD*&n4BV2|i@pH99%i7|*y)hK{i=5<+;0vb% zJz)36@!PTULVlHWw3}|ph$X!#3!o}=i$bA_f3fmRCA$^C1_|dXA?!2xKCHHIhW%6~li_AejY`mdJC#X-s!Mcb1 z0RQZ@niPlO(MnB@qWdJn;qZe`zlJ{Flfw;z?i4rKV@=B^n2*VK<@umiB>+tD{q;2+ zKer!wdwnxS+R6F9g^q*G&fzElc^{X~4!)V3X8N&|NNWd#sl_64tK=M91bnJ_dr4^g z5t&$Yc6HIWG*Kot`ZPK}1CFLoR|y-sAE?N7opsIDXo24tv?t?`MiyA0#clieDwI=R z1Bjj-4ztGj^4JESRc!%JXVaC?p}v0M!Pfq+wiVuy?jX_K4HVDYrNz)G{V_pJpGd=N3db+sWlx@V^e1+#1nM?8)uu?Qd$DZ>TB?JWlI zmqIaEK;?HrKGyKlfF0X;CtfVd}dNl(oQfWZUHz z+|Z;^`C9jrog!rK(ZHWolId7Ov{4*(D zp9kadlVKaSF7wXOwGuLaqDOj{tOF%#MU#2w;w^!hg zj)vz?FisG@H&R98&!w03*nciR1tA8praGRHB}+uWIF64a+RmMORiWNa7)S5&CSn-m zCCJ6Jxir}%)O#sZoYESc%k(Wha^j_XOmu6C;tXthb1Na)*81b&zo{msZ?L1@b>LQ- z{Gg~|oI?_pNe4FQB_b#y5X8W5-`=5ihM2~|?G*Bsobr1twB%9SyfYKs5N60HzHu?k zUv1oWy;|yCAXVxtEHc!fRGU#|nkJkB;-TSfJWGj6b*~)OkLBq|sh`5ug@+{vWy^~4 z#!#bD#-(yZ=-2C2u!gL9?gidw;|ka9TYXz} zN7gWib|F+Yz<|3SFfX1U`rv^dS>^_On#qM`Mp76pEN;xt)h5xsogHq!kI?%)reTUl z8oRL3*YwIsa4Td#w;=7VTsG2?xp9h;))JYyGUW%|RjjT_WD}5GFnjqdj z?dKVwqi+o^?1-g^)|GINqA)nRO-h{0lYf)1UdMbSigWc#Vhz)hlR2Kr$44d4xU;0W z+g=ucw6ffxGEwWDY-|jqV6Q}~JpsuRXGXmP%Iy8NpylIO&^D}F{~_0{OrD0qj6OTd z^luI(p(s;IEd3FarhoR7ind@uO?GdS}NEo&Fa2ezp;p_I7v44ku@j|xR~vr4%fHNoYmxFkr#HPNzN&PVc$sA+k1_MZp?;isN%cB}yFrFLxLKlr6wb-wAPeFV`32`Sf(*sj*5$*){9SrB$}^X#>FPZT%sKWMQ^az| zvpE^$EZ-+_Y#P2ACN*DrXDmCgf5M-XeUaBAdv&5k$Yv zL7p-x@;27_P9dnrihZ$el=uvLd0qA2MasPE$AcJ#y)i>jzF=UMMvUy z0^-tH>FIG^2gu^Refg}}0NOEgWl~Fa%IA%CHUweqHB70S7KylMJAyY>wQ6$6cDz&#JQ!W71z zrv?Fv>asEa*9Go+QK=3%ljNTVIi6>2C-|DgddIX3A|Q;C=>v{~Lp%Snl(6Rr}>-Q~b9X z-~vyhN;VgmuH&!B^`kRAnCQE^mU`Dq@-2~f{m}l?xgvK{U~vMpapEhA$)OLRdFH0) z4feRMbH5=;AYk|F0#1*oYw`nH*HmT622uJLJ44^N}* zONhzy3lCb!y2bqmN2n1GSiPVn5)KLPxxd`ZhdCoBw%a4MODr3I<$5d10Jv~hGvog8 z=TCeUP1YL=Qq_}m{J%fRWmpAKmZ1rlI#vMT>y8I!U+hsx19n0STTGik{c4`o4ZI9#K`asg6jv!b z2#z~IJ#y`F=%4!y_&U+eA#=w8VQ@LzFWm5!Ek$Y(h?vCI77IZMJ-GmxktiV_ zsIzAI3iYy3{Yv?xTo%@0#`;i2GU3ZX~ac~8IUWXFcg3N%$UdAK`)Q;alDl;Q|-nBGm}^zY0)3M!owOZz{ocog@Ibj6w0+LB|a=ACqGYOnX`W_2T50ps9Do zEFv8D!t?Iskr*xlv30MRiTzG+&3cQiY$!-Ph1nMZL${USIu!y~UhH2lyyBJ;Znk)t z)}L#{gxsMqdZ2ez%?KkvA;+A>phPq=doBeMG^v=d37vpeRutUx6L)Wp8#M3KPvw5hu@y=HPO^Nvz>qf zEo|$uRHxP9>Gspf|9baA5V&|Y>XKQ;gJohdUQ1;edOLp@2~OA^E4?&LRxwffM!z4D ziu~@7QAUT~0!Kz{fgH_?Mc{3`C9sEw%aeAz;e`8z**t1(|0p&+S8miarPJL%*vy{> zB(6N8+X%EPiSkq3t&I+?XB_F8R{BbA=FnDg^_DoCfpC#{Z}(OQrc9nS(}Gf%hMI>A z^ZGQNEgg1cxD8;F!s9cY7HW@QpILUmNB;M;!?tq+x^j}QJaI8O-e!eX|3%gOj0DMa zHiQ;t&QZ1Z*r0SdCGf(gfHXPjbOga}o{`}?_Ndl^b^PJS8O}SU^}J@4Bv#v9gDmPg zOLlU_*BYzG!!~b(xfKphb>GeaX1v^6aib;t*lDNWcXOa%hj0nML$-7)=@DAKJHtx4*K7HX=r1OkKLhYIe`$8f5!Ac@=q$508KmERca44*Mb zfq@RvmA161aUEGsE_dq%V*`BZBQUJ(!{WR{-k$tfM90Vw|@TltA zPi67s%{adB_=M@{R4_um`lMXQr1p7D7AtBLw`lw?Udn{x?6&zrLpL0jt3@iyyN+|_ ztS9{7hC+B6Sno_Q2!}GZY=UM9!Zp2kuszHBG*T@|o{U*RHZq}xVd;56JF6vk9pu9~ zeiwN6d2PyuJt440wgHPa@(PDpH!9rw^A&u&Rd2D)y+gHw0l#j4W70=aa@6~>#X>m+ zY@3{D-?l4j8Q9f+<`iJeGMvyvJerHXK+^+X;i)vuuH57VYn> zT~M9*4K!MAfC+Rs{Vg5D?dU||GpRi&nkSY!On;F>uk5TP%QRQjCj~;3p{9PsCuNe> zSv|)5BoA?wdg_$g=Ria$S<9DMY~oS*Yr>ixY9YH(?t(-#(35v#HKH(~04pta2CV}m z20*YcN9h2l+^F6c9{ldeca_hHMc#7LN!MHi?~J9W1qtsVMv^YTQR(1B^5E@CrU&_U zXE$PJsq+Sxp3r^jF^L|(r%@bI+*9|I&@6r%i&fKW5Bl!Ji!-A=eQNWSAf=)NlQF0k z9W>f+<%}Ge9LY(~ugc*JeTB5ZS%)r|{6K;_70Ov~*?r?*nF*Mp4t*){fQj`S%?$P| zO}Jj^N9zhw;@d@8ATq6&mpJ{X7XiC&4=Lo$K!f*Ae+SN_n(78Z0XW3Au-ed#!oLJV z;yXgKAe!rj$3r`}Q*75vLy!NzMh3z=5XuI>k+w9z_h8zLpF?XyJ)+tFSQG(#pus_Q z<9>`HgIIqZ2(BZ`YV!(H#vm;#13Y&$3J7{+DcAcdA4EFJ6xP6AWX5?QY-K8FEL{jK z^tG*YQl#SJn=F80m?{bJS3D>wFcG12B)qu5OfF^>%H3(hv5A5homNpyl76TH9nM3y z4roBZAWH6Ke+Z6`0#r$vJCa6QA@1*>9kXhPaeOKBUw6FgpP zxA3YS93Lz7cV2W&y{`Mr5HD)N(ELL~eve_k&3WljewV9p?6mdv?hCNG7o7gz1UMng zts(O;V+!>O!HB5c@+NoW2oCU%Nat-sKlMxo*^mylaAIOXqxUZJ?sVRnQ`*l*NKeOg zz3(s{$z+d@QF66La zDFBc2%<`9s&ka|EmaGn5w?kq~S3sKC(zt4>=}e{lnfLFy$QklKQp9Cj_0Z${_i!{z zcQp%*Xe@Li&Ig1R#VneTCyU&A^Hw1hu9+PSmG>{;$|Ng~>1;8-Wofpv44@SUqjKO! z;&u;YslGApQ=VFGG&&f?p1y4LFA*$z7K!htQu=ledGT-J9mU8$rny>JZixB|Xm)>} z{hKd0vv;(s51tz4K4Al|$Xj8o(wD?oTW?AmCwZH_9=dkq@Bd|`t)w5(d?V&b1s2;v zDYC*+gS(n`-<+O&09IeK&?WtP zdI2Nd&OYLe*4XLN-rtx+K0#X-a-cw1@uni)#Jrf}{ZfK94F%n5Q{RM=Do@q(O6+?$ zo;3S2F6>JG8WgIhBe(-twiaI|)X4>DxP`^i%G@8r5qMb&C}Glk&51ubtnKTj+?ykm z?U1R}VW%UvJkGx7U>Q1OXk-k^r`((J^2!=ymdU;=h*=O33~aC! zWnHDwH5S#m$8zo6|G5fNpyaVj1X1GvyeuMFD=MvIO&?0E3*MYgo5xIm`yqU6 zd?I(sG?r}y!ItHAvz><+tU4X7C;>pgSWulOyeu(H>8)pI;X5cN5-|Rdu_}K|U}M3L zT0I(@?zBq%1zkMsJ0HY*sp(7jDr~Mkg$h@Q2b0uW5c*26jjh)j?em(rY#A;aA=|^p zNe+a#8vt&y_<}oS7Q4)K(xGBShxtX^LMWbtG)ER?bwaa#Z-4~MmMuEpYcH@BR*X$ zjQ0A;?GQedIVW5(37hjfQ>39GH5Zus$@2~_2>IQp+?59OQrhg!nR5jrFZBRx<32g% zrR#tfNcGQ~z;&wKkD^7d@J?WreW2W424GZ?gm><;F?Pf=ShmI0SK;c6n+#R@?+GZM zX7xlgy4c3Q7bpSxaI)_6iJWo=8JIxQFdlz1y`aq}SWFm0HS0}JUHNLW@xa{y{*3H?(PQdzK)&tjVt{9@5s%?28u`Q8jnMmrtyWXmz*V?iC ztl=Wc{x67iA^Rxf;IpfXa_OIAW?0l*K`2U*8+?pZu~GVLWN#L0?5_BwX@yyX=AIB*W0#hB0PqEo)j$Viu=n9TqAy}u~jYp(T<}T&QbGyn= zw9tfExu*2e0yWGzR~4soHe1EDDKX>B{u^v5=!zD6oR z@TQa_WrJ9`d67DO(-D!RZZzh_#DDrvY^jXofo0O+Q?powF$e*r;dGXecqcmV<$?tF zR`9*GY0mzh)YJZ0oX^Yrro11ywH&O$kGIsiQQp{Eu%^XSAebPM2d?Q5_{*t%>i>O2 zhjP>;m?9XJ^#L{af_pxB8M~x`hYp1eP5&9DN6?gbOv4X7dw&Gi;wW;mxce{gu>vY$A>g0ylH?b%LY6In4e#)ts0#i@wECL#)1iyz^ce>FLgsg5EWXArD zyffD9k(o!q&pZ`dFA)#4Lar4unXF;s->Pi)CR-(xEJE8@otmH8>hC?UydM2$+f8da zMl&$W_^{e@b9$okYxh~L0n_5Gq%6v_#ga#|jiuu-&+cmh(EGwKi8J(xT+XWYks?$* z$Uz)aiuyulWQ=}9To75?zzLhMNpoep_C3zc?E$ZWm^IX*cm0vf;^tIv@>NxJy187y zozrRIT*H@ikF2p_OX|;xZN;wG_FM>}k-QP7`O{%Y{Gk0%o}nwvY;S_3a|r=g8jj{ z6%KqXKYDN9!75Gz)-su)4^@F7G!2}TFJZR$!q&La>ixi}i;gPoFezPF-0ReQ$7SFg zwlb-bu<++ECol&pylg;(2Y=^4stI_au{*x64|jtt2$bZx?1on{>;kqX{_1NJ8T=$j zw4Aq~2vxX?5NayPT$Fi@CM=y^qPF|nX^R26vCe&^8(&x&~)f8u{d5M;1@V zHnw`;hu7|;=%%=wLLt#VaCjwX@L7)eg@7*DwW56BHA0oBxmxoTJ@Q7iU?U#aCZyLJMJq=Uk+1In`oN@iCYW-x)*jN^60e37oWOkEW4Y?(8 z&N32}=@liI0t7r6!8 zVEHcD5^Vf$&Uoj-2$nlFUN#3C(9oiu7L?L+v?>`}wkvvR;%3OB%!K1iHjC>?W^;cx zEu)?Wh~h5Gi~I=bsdg2i;2NaGLsw1jE)r^VbK`k~^ zMPK-Bz8hbkZr;n&h~Sq`1xYvgsPN%!gS!*=>a3=QtE!GB8?woQ`3 z$N(piCwtwsTX20a;~`ICXXaQ-qPD;?+hYcoxMOS^JbrYnRjkNBVy{;m6<3VJJZ{{- z=|V|DYu2o7gGC<06k|%;A$1}g zeEMN$Kh6OL=I8}G=$)1wIRm`=NIRdxgESUs|3r#_$1G}u;_f!kyu_WRY;)@0#;{=3 zo9$QFDU;7e3e~xU(w-2L)}swNW)xmD+dtnE%b>KEMF)h-W-OIX)C!?g6!KI$n64Ix zCF*YO(-$5e1uXz;Uj|nLU%LPC1Rr9u)Va9i74gARp{AI1$fGq65V0q)d*snLQDe3J z%AFH`t--MS3F4t}uk?6p>^p8Lqe5Hzl{8QHa67Aklm^(DIi2`NXuKI($5@DC zMA~x)`|;z&*edOL;1-lWJD6qk-PF|}<~fNOs+#tM6r+!bmiYP0WP7Q^Tgx;zjXg7R z53e*OZt1PpB}9S3{5FZl$;aI)$vZK74gf&Sgy=5r6{v!+`Df2j>*!f{^63yg`Ch-xodGcsQc9Yyj9sRnb& z%(2_i-7g*Q+!*;}OJl}7V;kv)U-;|gCvf2`0a!Z?Qp6q(%LTxz2XdMvMr9fWHG`#nLIBO54|QQR?Af?{X|Me-Xl z{|Dca$eg`RtCvXHT@-|XLdC_30T#Ws_5dryZOFyUj8<MWx}j3o0`ubK!?L@p8w5EEZW=rR19cJbTLtB-pw zvw^8UF{}OjmWLFBY;1r^iE+i9YXh!I^|D2!*});y`h#)Cx0S;Q3Bs?YSNVbvMA|^{ zW{l}HtjV)%Z!UGTPbK zG-ofIB9>BS6AJhkce^k6K&I+TccIsQ0c50dav0(KN+x8g1Yap+A-JIyLd<6SM(ymC z4qwNRouOGMt|+!6cD0!3AY6)#3j;{Kp`|W(kJZt(T8q&8@v$pBE7~s`Wv|h8jitsh z=fmBgpEi@rLe1?9OQZlG(3~C*6_{z)vW7u3zUG%K z@0|-U{wOWDd>erwN=6cFF=FC7;gK+!L(ltqHS!@LKieWMYkC%u=sNn429WITbR6Vq z|A=KcZO|JX!t-^nsg$iNvIBdJeowT_d3yV!S@RREOw$t&MlOtDZicC?{ z*iE&Fh^Y~e@rxQ};6-gu87ws+bvoO@tJ~CLK2rH`;Qh=#fE^>%+=EUYXlM!*&O2P` z4KbZ{yJ+!nT5@hgbxyx$druw|D|+-1AXQBBUdq_hJrTJ+2fc3p(d&B#0^_m-L-+@(u-DL zR~w~&lz?_#CLstW36X?pU_~biRJ8G#R1bS(v6L)ZH-I@{IoTwTpHM-7i@EVtz_K zK~&4sR$RLbE-{(6b5*0R3@s$&@uXA(Ll#{_u@hC%iAVT*sv5;rg^Yu1ax&e_40y}o zi!PnB%0ZC8(MS5$E`0r(mxS3NZ;lWj-1oOK%^?JjHetM=phdzyPeV~;M5vB=Efslu z>VfnSEQovW_d7s2zB);;)^3)%mEN!%07+3jMRU8AGM9kpF0LYPbk}agee@@}?yI?C zY3RDAMSZlGtkck|gI;$4qgd(SS+9Y8B)vy5@)mBhd74kRbBj{QHhn2I{7D5K@XV8% z*;SNEq(;nYr~j^Y$~b$mjrI4^M(_3tge?gm(GMx>EO0Ub-`)X6cqVjOwzp4+EBGN< zW@aIVi$A0yEpe!~qGb#yLg6QoBS%9kG30yh5$yaHElNu5c3<=Nv4!0sx71l;6kvPx zLx4RY`1>cfc*z+`ML?#2zjE=fBd~G_20dqteKz>VY%8q&&(_=u1!QqZj-u`&y=+}+ zV^4q@8y&fccwcX+a#7d7=vgUJ5I%<1*v?lC{mKON(n4f0*_I(vaBY{Rv_%(v2lOyF z6zuFwW1P6*M#3!A@n0pXC^|(O3gbn=PFkJE$#@`qIBlH99XVdjt$ULy;#p?903NGQ zV^3IAZ?^ki+J28)!gm6ouk{Bv_^}0}6DcjrLLn?D>-8wrR!rJdUQcK;e-6 z#kA-pOA`BMLEn??-eL4&2(73&#rFMU!|Y7IC&;nX4RkGV^=?rVgIE&rG=40dTOdr{ ziLumMpl*Lrf`2Lf0VK=8k-&WmKtw+7U_oD^d}{<@q4<+PdpR`vUxZdhK@U#TJeO5R zv!Sw4a>t2VMqX5DBC}kY$o#YjDDZJNHd?JXgu#N7k3sgE9y55#AfGQO4VXKJFlnoq zRA@(P-r`lO8Ie}V>F=4zk-X-|I#L*Y24rKr7#A|s>iP)zDb;1Jo*nljc^wQZrgzUo znz%HyJoZFytOGQ=@7~G4#$Y^GWevG;ng^vxgmAU00}wsse5@+KW-mA=T_9>@GEwdb z8QDk&;IeJxH>6IzU6P5XCha1fii@sr8y>JP=MJPSyqYeufzeA>k5NeDDDGl7 z533(>@`dtlzgt-@wl>e{-As$$VHjr60gS8hXSoGXjrjIAwVZb@iR(PtpzaNR8k4Ib^?+_3|iM29!v7?sPCfJTxLVi0l+ZF2|uBJxGXYk~Z(Mpet^5NtJv zsJiIgeQ87Hzb#8$Piqn)omKSurIsWvvO8 zx{=-)I)Y+kutTVhDpt1>MqidhIDmfqcN% zaljF{0fHmSsLk_CWVgbdrtLQ92*bBd$jz4{XdQWs*pn}2tDwffQDjINjDu#)0|Ulu zB3CuSN5}sDD$^#j8n||-M-;ki^lNC8?)Y^RTd&3x=B)Z+h3k@385~VK;#5wY;Q3z(8C*xYT}CMaO9OgLxE;Efczf$Y z{LzH|a8&=-?<|i~UP&T<&B(Cq1M0ZRg>Grlr&x@wi|E? zdBF1IZjAl=cle8R#*K>{7dy!!d=5cTi_8vqYtFqg2dpDq9aE#CRO%;h1&22t=_toX(?Z!Wc~k82@5#szP+XI^PUp+Ji`* zevWA5$pAhId8deQ2_Kyri;SHR7iXZuO%<@W`G3_w-$^g)Kifjl62j&1?imQNU|@%* z(aGXZB$|z(_aI?XUXMY@FJ*GP?^kV%($}EKuhC1Rr8O5QV+_JmVi2ibn!-LW|d zp6rqLFyOVeXs)Yl0L1bW3ys-`q8YIuNtHlwTzT2%D+$pGq;BeRE%EllCdP7_6#a6P zrt6jRwS4fzLcmDijZ`1^c!GwFQX4|+mW#`Jx%ez6_u4SFXf!mI&&bJTp1uQ z92N#XaLw1@Uu_n-b1!>@%#qdWS2(eVpf<&}ib5thmge`-oi{2=X8P8*LEzU0W?3NP zuNM3ZyAysvc16{W9ljjPAlbAcs(XokBK57x5?|?fj>K?s;dalrGsA1$f}b$meCE_6 zqlWxZ=ij%bI_Sx4H#U?Blqds1+W7KWEIxIZ->-Ll;K$8MH)*QZ-A4 zPt#@n)l*U@@v47nsf|TM!a0yPadbYYCv?rwOor~ObE+Vy{Z-sO9A4x`-`c?=$O*>| z?ypB_yXw7Nv{+IJ3^wEx6DfQ8c7wwCu+HCuMg;#In=4r!KePMM%MU1$MQwDlwMC|Mo@H0p4 zv!2^IKx;fKEr|3vzQZ?7tbssJvR-0du7}*A`&O;|9s{#M@FhhLgvDT9w=75CGM(W| zT1Hhqj>N%ogciF}$N(1Yr9N4&l2wOhV2VnNcoio}e@bU{?n(GhfLgZXh&eU=S1K3x}M_%AkV~EBGn7Ni*4M2dsRz z&*^V>C8oOlc2;&^X_1ez%-r$5lat}A>8XT|lRnKbHum}4+(6y7>}5HLe4ni+;g3CA zE{Ghn%YAvYZ|)~zKy$u->zmO|%B_J9_bdvENP_x(oeJQmkZQbnsQ4QSf!6!J zH;6i^;l$mY`?)7J;ZF&CR(lLF%+4`V5 z7{kWnZw?xKAjHq_g#5Gb_0TCH(!U-Y5MszpxPd~ko6D& zrf}Kd5_o{7GemQ2`#6N-j6T(Zcfu22fP6+|W^(AJ*4&;GF32<{&jLbtGbsDdWXT{@ z%sqGeMQZ4hKT1nj60#tzRBF+qb>Q^|24M+I<27kNxWj`>j&V)kfiBN=o=n-{BN9j9 zctyB)*|`r$?7d25+rY?MAnANh&#-RbP+;Z0`TPwZGOD}h1!#zZ-wJgqGJ?@6+%Lu52`rMKjw34iF;{ks~*8Db9GYb};Ig-c2QYv8D!@A|q5%qY(q zqS3j`;n7T;lj(5juc)7}TP(7fhhu3(TEI$X%S3Z#D1D6!{0W4&DuT!na(LH7S%AU- z)gU`_G9cYRC%D!WCZ<8Tt7oa}Zb>s4!f8r~iyJ~f>6L@Jx6RMS z>^zz^!@jK1wzwft@tEq(Z~J^Q2bC^x9yrUk<7zcJVm4Rd_%Be?b4cD$Rf#AcCBfHY zh`71mY%oxF!YRi$aE(GI)jvVbLizmEc!ru`Tgj5mkp6zRa~PV)h&IkLdtELMiOk() z+|*!smlujn-^=|*k(+%SsCxxZYpyZNKMr*ZMMkVm64f2fN-L$0k^CK%_g}GQeq+`N zSgJS$Y!huDw^K-e_c(1S7kL$Uw|3y5%3~+2I7)0(uW*2IkyI%_<_-7fXi8IUM@ka; zlmNHFjOvGolAV!^TmV5pzQ1i`*E{Gf|9ubGRz4DDm6r=2UqFYbRskqz!~9glb%83y zR>#Ib&*P4DRY-4s_$CwR=HDss8KyFM7wNQyJWog2&k|2@Q9>Cf_H)8+Q{uW0(TT1Z zybHk(uGG0q{wq>TUZyMb-dTqx{CRjxPr;b%xxpkQ%R4wb=OcG0guOnP}Sf4d^E4=}PRmKtkfpGLV{ETyq z8L;Q1+&FRZiemRaqxwYU3A0@y9=X9)2QfWZfq7gMbZw9yS$9|#Y8M`+*oE0CE0(dJd z^4NGNcXMtq8f_FNvz$lS~iYix~DW5I7gE(bYEXa z-z!Q{#3*mm4(Wrpk+Ll(-|)fie>$m7igdl9A)Y3e>?}Z8$39~+Fnrg=GC}b)-pF>A ziwwzFf5>Ox=bVwDD0No^Nh3iTw@I|3&QK-8Ct=8P1?H%fs^|Ks7AVbf-i`CRXJ^@# z6t}3-M0JCoF@9uvKOCZvZU7oGDtM~Za3oFY{n-BVsj_B_Z*rhW*LFisNzqC`C{X#J zQsvx01BNo*_D_vt>pZ_se0g?>(4EZ0jMe9z-(to-zc60}rv;A4Vt{Uae+L#tVp}vO zyIx&uEFZS_)Zfh{izHRP1fWf?+&(SjbD;L?@=j02bv)K=oZTFpZLY=7FWFX)bUp#) zDk7FM(_Le6Ej(DXl_)vb_7J_bS)%j2ciX~4UQrftppQ(3&F9BbX?ZGnqpee}vQ!k! zAQa`>Skazrv)mPAZ7D-xJ@DcU2PHf&^Q?q4X}%lKL$u}>X+1tATy3}5 zdmpxe09N|G<)Q%of6JGX>f|K=U<|7v{)W=s6;amCK@ekd3)xNXqGxIl4W3IQd7uW?J zrP_L@Y)#+E@laBPR#5gtPW~kKZ{pS~qYV%C%g^&Za3Mae&IVMVZ7~o36S||7xQko_ zBIOmZwpR<^$jQfa7m2mxWc|X8giAp5SiVCQl$d^Tg=2ulD_a$u zxUQ2jkNTu2<+7ew`_F&*oD34^bNYdmiH@-S3C^G(9qC#=!Mx~SnM`BoN(JE@@8D0q zm$zg@T|N=%)Tcyo5FYZe=Un%J%^Jt+OJ(6n;=BkR8LpIUJ{-KYzSOPQ zRD3gg3GD=*UYMV^5veR2qgxl;P`F(|qJ%EZH~`gM;G4zHpB;w+JXC=35E5d0#865c za&ZVKy$7H?!4?b7TE17Bv3UH5qUY?RcQ(+I^D+4kT zf@0jxLzw81>ys3>fP!#`b9L|D;i4>F+|fl-RKv0%CUh}MblJYUP8nlCtPKm~b7eU- zAgtU81p&ATOmi32`RTQE`qC|8=$p6Xl*4Zd+>W?y(m1oQY0U;bSv8JSUqW>d?G10h zZC2u%H+~JLI^QBG>f^oKXg6tV1#Fk=!Hr0b#~9gmOtt&z2+En)6>=} zqEC6>xitLmf;d=sv663_jicJf;0Xb$F_3o2mW`Z9_{0p=0D2WxZ3&+?CdjO6k|ze( zaF!mr!rtAZo~yjJOx)uNRb}^G^f}k1fm|5IAjFW#P@Zhg8*P4Y_%Zt_v(93@|LMPO zn4YA`u3~DekKJ^uiU}WW*v-bKF@P0V-+PP0&sZ6-UV^-bm7v04#X)G+T)+1<%o1_h z4OSvOBN6Q+3jdaiePko`AGLVhcVaqS~Ur{c5F8VQY~hl1Lg;Li{%%ChOIZ% zN=wILKD~t{5+*DbuGB- z!pCxvS*{YNOPo6aOn8a{i3DOac{OulW?YPBQ@Asmz5Bpj^X)dUaoi;A*nv~amBdX6 z$_mz#9F2L7P|Ku6Zs>nh0fIn~!a8_|T-s>mS(pN_8qv^_gn3<_eMsauP|1hvnRS@6 zf3%j=)QGqNX_t$l)txyLT}*%&me4mvjmzi(ulY$OxW z`Rl)?F?6lu%7iDEnJWeyAr?Tk7X_YM7?f5aj)7W$A|m zs70Db#~Wkjs)`V6VZB0eq{}& z>%A9cmor2(0DQUt2ISxd1ag4w`X6qF=o=w-Qm&8OxykB^Pl);R$6c##KqdNnC~AsO zG{dx=!2DOhC6YLF1hRUk<^*6bymQD{tDC>NR+VGjF$TQWDKX-(O@AsK;%RI)t?TVJ ziVa(StUqY`>mUTzyAC~PSXR%x9gy}^u2C$!&c3)0u&I9P+56ka9AY-WA8P4dYO=WK zC{|r#`m?Q4bJxpx3U$Q-u6ApO(q+Y}2Nmxb^* zF0dC2Y7tqKLM7TYWN=P}6dPV?cnbEX-Uk?AgwtxgvzH~x4|6u(nFft94`a#{`jfC$ zrRHgnki3dApSIJCslelaOy%*TK_-TF6o_Q#^8;J@UdIp0CEvGo5n_jntHsc=49h;p-g4qLe45T>h zc^o2n@WWiJq1=?wiO;KO3Rh4BF7Vn(Jy|S#=9FMOOHr=hv4qm7Xhl*_rFn`2j*X~J z7Y#zdDH4E1F+p)T13#{Z&hxB}g@nJe=k@+`XX0hqoJDC%S<|&(KcD*b2=|B@mc^qO zmKdlcziW2HPMEz!=ZV|gKs2w={0%M|#r1B2Zl~Gkv3_>?n;DX6_-ec2zSRXgf0>wH z9}Q0IZ?ij|Xu7IUOeYLgg*e-)(ZZUwZ)*odQy3UUcp~tv7A~?%x6^$iGdQqrN%0PU z-MrKMbaO%G&cZRj<8)H5*Xu~P&t6co7EPz+BC!-WcW$?$kk|oX2)-8$X~E$b1;ghZ4hQU~USS9w zHq-%}!0}F>oimO(saG882j-^i&2rQ$fkCzh+jfY66#1tBf_(U;Xpr*5_Ez_M!*kZ(M5bVUNg7IfaPI@bfK)9GA!F&xqDiB2Oh zl*xfF=;Ys2vk(q}380K-bu|eq3k3Q=+(8Y5{ zh6WzAqER(rnfg4z_U(G%Zy`Nqn|Xk4n9qqF`d6X+tbowsfqTw7oF#Sy7YKo9I?X?r z?yZQYd8ZAxAo|CZ*cpc(V&~L5f}7g%?Kb?79VR856lDzQsn)noKk|F?Hj&KYeCB04 z6;IQE0e2YW+%{wr(f}-pPb7}Zby5!257*g%@urmLFJ<^)VE=Y#Ox>C!V0 zIU(w9krS57=rI;L9{?}Nno`YS-Dv<@w?Jf>05vX2=XFwx^ukuX>p4rCJ|YVd?H%92 z9@L4);zw+=)` zu!$zwDDbaM*+R)s;BF?v9~OTIdnxiYnM!2rax})P+K%(Gr#b~if7&N^1KqwX&YwA(0CkdX&*Fb=7=9qyrrBgGKt>_M=t6 zsVCYvBU!^upWTbHH^*wxq@71WmvimsdgbfT_s5FLO3)w;@K1{ZvNldg%B~_#+$v1u zrk5im@s&;35fVd**}u)eCz@?JwS&<*iO|-K@;{?>>t(EF7pCrz2HLFbaC(8#48Dk- zq!-T;@8PMK+8n-1?@dl)5UCTb^?+>VN9}+8#65CU-o`D|jutKT#2t=y>XQl}c(t1- zg+0f<1hj~;4MNF!|k4Df>%G zsphd4+!RL<@m=+;r7GO$%8^Xo$`0yuyp>?m7-g6X-~uOS-N(UT`zSGVSd#FNA=H)o z#*Ln)8JllI^i?|)Dvku4+H2t+*LP%rDM?@fXX>O6<%8T5@jx7av(cmQYSX` z+~qTvIf=X#BP2+zv$zp?-Xn3XUB>^1%6f5cUGT_KZeuJ8%Ren0xJ&Xm;aG6*OM;h3 zDJSc}c6ovNne@SSg@@hd52s?_oW5vxa7GqHWBg@VLEnigR+fJxN6Z`PeCAR_`jK@s z{Y3Zs;R@woY+3p$(azmSSvR)d4L=cKP_Qg|aG?_Pq7jK=D@wMOWUmk&N%jDGuu+QQ zoXXA<{ka98DIf?cg@8~dBv-V83{5g)@{1By27i<(MifYG@8SRDC9hG<9Vi;XQEdN3 z1}G_5j%V+lJCIICX0OKmX9arGAE5-DLoa@|I!>i;m84ituk6I>a)q3q$c)-D9Cc){ zR=H2ug8CZp(4&)?^8gO34K1Q+oxXSV0D<*%CwvBkX4}hWue%Ggpg0f}Yg81$1zFi2VfH{Ma)` zTaGYt0os@Gu1VyR4Jh>teM>SFv0KEL2!Ul*dAy0wSt#UbD^{W_-^Qm(vip+>_?DxJ z%|0#Jp8KQJU&y+h!*nfpS*ulZ3&e#`Imx75$Fb!Lit=P%r>+GZ$1$xUx@@+7`kj4z zKmllmmB&c~o4-0>H`%OUYGYMFn5?RBYLjy_RoseI$_t z9tipY?y(;_o?<)Rr4?+JQthN`9gKAnNsz(^kZ~QtL6M{k8)M{J;4*LXcCs|<(kQU*7kd+ ztpt^l_>kLfBpz9|D(%8T@$)I7$f>wgZa4sNbKW->A#@FbC(irQrq3>50CSnHW-RPR z#+&&r!iMW7b#EPc48h$MKhJQ!Um;=JHKtp1fW$<=eNNPcWUVrl;RThZMczVH36ajiMf; zp>%_pP6*9HwXshaqiPH?#Vd7SL?5+#LTvm?i6%E0$Zy_5sLx6ylplnJmx+7P(WQsQ zT=xDR=!)?J*GC_}%(|;@|ECv^J1C?JE3_>{)wKHG=hX>C0$qfF%!+9;b(QCrQ~2H1$Iq!wF#;1bHPJ$wia7o0bjiq0T;IhxPFY@ zaHHLLax@Q+n$okZTFWU9ENyfOBN-;w4qkMsI5W?X{?-9X!2=Y}(>=Li;9K@7cOw(C zX-Yu1s{funE8)A3c~eL5>HT;S}haz>PsQ)ljw{IZ-+Gmwit~JJR#jgwBPP%rC#!S zt9~(M)5Mk9xjF!?FEPi=4y;Iwx5!}mr16n!u(#LWB%)2^9Z)mot> z{=*J3MPKa~HG|ueYK2^PqG-_785a4a&}(i}C5z-{uZ|jt!0;5GD$*9VXK8E(A}Zg= zFDc=I6mF#qvNuhzz-QyK-gM7|H}QT3`s$z`LnSIYW5`Mt{5$Ug4O0S8T`gU9h6VBa z=mxvZ=IC`)+MdN&b@fL;l}C0zjrOBdFlh+SIYm4mUeEvELKZ*TuL1eSeI+w$Yksu> zkcV^E=k@d%lW0zL09padIVm&p4kO$DvbGQCf`ell?}IYc$PnV*QX8s0$oCPPuwM8% z2?R?onul|^UiePQVMnk~>?tp1J3FYsE5=CfO`piV54re) zV$EjcpRyf7{Y6l=<@IxRyOktC z+0CkCr0J&5Ip%*#Dm^u53K?5L)*i!D11HkH`R%k7q$A2!6y@j9`)6uER|~ zn;+~$5cy~$dz)rcMSui_Fc|mHty^vh7JXTvKJvA=dMdZrAE_PoMYC}bfm}RCcT7?s zsI0Pg?C=nLKg}>C1qvBCL;WUdVKIpANk?8w^$1NJu=wigYcww0`@&Oh#b9OIW`0x1 z#|~wI2Ca?QCGN_x#tJTh4_q&<_@#-oirWA?--x1(D3DwC(D%!u@x$X!0|RA}$q&_F z4wKX$E~tN&bxtAQzY>hItG~Xiiocw`1HiE2rIwReURrJr5K57M!x`UsJ4;UX-|29o zs{fImYkw^1ppBDYBo^nN;LHrF$Wqe~{=1P#JWNFku_snEwF7o^HkfJju*yChb#;=Y z7)(Zp%5!T%$kY+UAby-XcM1Bz2L|gmd88-xj`IX0PSb7_?De8d!5R=`t)_R;aEA*a zo?&s%YFO|R;VAg2pU~=SA0w8tv5!uq?RN}WDj^Sg`-_~HY?FZReJ!W3jF@75xm;fW z2V*F?V$Q=jQ<%kUc+*xpkp!#p=xgyFD*V!KHwW(@W~fsOa$jS|TOw=<3=qB(ti^qj2u!I5Hp}82O*Gla(30d4UP~swm zXXnll35xfQ3zof-jpq7&p#A;w2||ELwx`~MA~{U+jr12?hWec^`LgK= zTwnD53!?FKblF*0YYB=aj5w(B{4o{-oS`Mzt$~t?sfPzWK<28)rO%xJ&VV#*^$`Az z>CACjcAPh@T{B~^Lou%ZA^!XRUk39`OaAF8uCW-qI$=|{SOMZAfc0~z*-l!yM!v<* z(+q>eNj}LxtpeQoPPr!3D99P=Cqzu*QX}h1?3w<}%gLGqkTG!k-IxbA+-jxuf&f34 zs3`&|4GQEFRx#Bstkkc<6wbhN9mSuF!IZv!|65!l5I7i(bemSladQA-9i1;?rY+E( zCqCm8=RJ7qQNNi=J9{#_Q>?`kWs>krI}eAQ%Z)1wzP#p-FZ7;he{OvPMjc>q-=DJO z+FI?c-)(<#s}-8O_it6AW$(xB7J*buQwZ&g$EPvLv8|oKHv~`wp<+Cl9uVXMgiZW^ zk3P?;sR}PV_P3ay{)(cc=8Zk*c710bxB3s~vRffPXZ1D_3`q@fw2x~V&k!&kE(6h- z+$xd{MoVDTsOKO&_3DkvjJ#6;jJ?kD13G3$hT#+eLlP1l>zI7)k~d;tDLN>@bbmxr zn+5z5BWK|}>UGJ;p>-9o)Ac{~g4mT`cZri`yTtv*HneAwEjK@;B3Bl|_q8=bCum_- zcCE3geR;5?Ww*#hFhGmy%3kh5jz0WYwmT4}GyK~a#pCgO8qpLyAiKP~v-G}$^n({B zlJCe9W%`C|N?L`!TUy$i8pJ=&dJ?>D6^8jMU9nbP#b=xbI$cRN{%UTV%Tb{kDu|~E2p2B&2UH@({HQ33bR*9bscc$%0h=MZ3HgWpA z==0cWk`HU4`rENi$IMRDYT>9`s>4-S51#{g&@xrkb_|!I_J>F4YTUqE-sJZ?y_`kf z#f~*@KDz&joe0wk`u-`}TwiyT@G2Gi*|_nFPi?9F5il$9e*<}m5%9r90F+8*B+(sC zWDzV}Q$r3qh<6>T`=fV!Y%y zT^jy7gGgp+u{= zfmFceNh8;{$!o0W@C-eAnE0s`8E7T6cnQ8M-tWHrMd7jld;I%2(o%ju+?DpMP6 z7k2jwN4JHn)}%EEt)uoeBzXtFZ~6S&RvQGH1n6SnQJJ9l2cI$6!)ozS|D*Z1l(Bbs za9Fer{o}scz6~KJU)t?njAcP9x`F1AMr@5aF+g zxv}-*v&GU`JBJ0yaT#H1G>r~Viqu2o>hX?QBUON;M+CQVe87B9ezJ)dz!sZ0K~0_b zrN4pp?%1)Xj`dg`SmSTKlyQDIjT+$USAbuqC^a2F_z6Nxj$503m} zb5TLar=-?X2B6WY0rH&8ER=J7V=Y+=)lX2E6@|zd`qTcBJq0VVYaY3!H|jp#TG8G= z{N_gCN2AyX?4q7k!A0ld;$VjDVeu8x)zvVTs!Oe4g#KsWYuv}<`D?E)q;MFlCF>jd23AmcxBPZ@O58AaAE}FO zu8@Bmv`Vq~2smdyG^DVCyU6_nC)qZtD&#&S<~Y`f`?SqTX?j)=qzipja?K_nGmkRr z9!&G;h|`(WOvleca}BEbid>hcUR8qrPXZ$8_(`)Xr8(??en>=bXrB7-?PXQKvc{sP zA|hjV+k4O`{6qm!o3LJ5j53K|GRo=WvVLBS(D5l;EBbwvuq??LLK4sS(f#F85u62U zXWWVZrNV|+&!ZW4<42Z0&4P#mT!)Z`izcg;n0t4?{ELVi6;CTeD8*q_#=e6NM@+%kn&>yOg2{5D zbc!w(tiOcOgi#1(K?{K)0@0&`$0*3r*{OC)7&(G7R?0xQNVURP865g3o|6IwhjAH4 z+jT&J!#N!p~Pm4831)fsVgIgmyI|p0ij20gKy~e_#MBt&{5p?ubJElO&X~ac)|lELAulYc(_){rprC zXw4+J0V&uO&i*G+JA&bX^Tmro&CU6ce_LsK@A6fr7mz(v_8cbrhb;DNC3hl_mEjuYl6qumh9MFhJaC1KE(D)gA*k2EZLpE zc>3qTShhRUDlOhe+3#=JAYy>95#;d^&ZI!l77F?W82u7pT)v!k38Wz3Hw_l$@e(;) zKic2s9F~6w@|p!@&aA}t~7BP`+u`ObEUsFum z>LN$sC+ww8ASu3>)i4;r@Gn{GFg;Bo;?$k1n5Q@67@!Kn8~`Cu!;9zsn2fV%gqwC{ zJHB1~4CcuqD&eyz>EKEF+uu{uq3u}FQ3&W5ahYt>Lq-RvfVHxC1)^^0$SuN6=<(0f zN0W#m^reH&(6c9T&e^r9>w0u^`EK65vs#vxCk__uIOZ`gbi$I|*7i5&Ond`G?2S6B zi8R~D2A(gDags7)w|*0sb=n97WT=Z;T!2pjvNZ~djW80Kl}6VH*khO zqkkZq{}!7I#Gv91MmuBXY2_%a%x!Nj67>e5L3ul@t#JYlkYHMq@M52P?bGnIY=jbK za?C_rs>?VzwATDn4D+&~m_5vycTym}akZ~3 z7&fW@R)O$Sw&ph#(-yfHhLk|=-KmqHNzAksclOAOuuCjJg2$vfq~-30vON-?95YM|isk^;K)w#IH!5+=RB{JQlA=HA=k0w_V-;`sZLilRnQJQRQ6us&XgqlGCkdK? zs2yBYg~G4gVmPnWc?&*!HJrm57wM}_qH*?0rO;k~D>*aK`r+P{Pd`SK@KI6>4{-*ohga1a^1kQ?h)h)#&gp<{FmO2pp}X?I z!Q_>0NPxLemdY{+$gpsO5fU0A;o~j zH^uSJ5x@!&h!u8PfYGNZZ}1Zi%3-Vp`~I4NA$bjy{( zl{p76`QlO^S=JQ;c24_pi9uo)!3vE~?u8tgkipqx=N#*e_&YyGcpVA2_zmAy*mui2 zLqXRhccbM#vKWH@+Wn#Lj{=6>2N^QB$8jBp+8x#I+4@mtzY-D%f6>5`vx^H$#&WHC z)M?HEAM_q@)0aGtxTtlBrV9Mgd^`mQh_l95HDjtu3s%rD&9M~p$f8J-;Jv*0u~gZ8xUEUcX(f}H z1jfdHk|30GL8O zeFv6aYnYfq&%2H{u_n)7pN-1qIln39_*Hllk)Fds>$+V_ZdgZ^Gh;Ab^^x+-@%N9$ zf!Y`5Gey~=&kQ(^3{Q~`bXaDHfNq|Ttt3A$$I&q1gQVg(kZckq%y(S1>Ia_}5An38 zfvSi_9`k@ctup>ICYjI~HU@yn_l#wlQ)k4!EKP0%qS`jfM>N@g%nqlxHDM&v(J5kB z2*%o|yXwsgPve3T6-r1da;#h5_Uiwc_$$bx1>nF@=jOh7J^5sAOK5``bbvzabl4F! zp8ThIWS=nUTCy=ql4ODdZz;zcGJi&IF*mu^?5AbP{$Ac%Wd0g`We8Q35a8vz6o#WP zh;SWX##Hp$w&*#NAVVk4YAkKL@iMSKs%CRO5Zgu;C{xFiy8NB0qmwb3^I>#f z@>w+Cs$N~Wo@bARoU$*13f#0)q9iWcuiX>08#}9=m71QBI$^6EU^z1;u6TUaRqzmN zC}F}3uFRG_u<`6WoT#2h4S)`N+--sGe%MFcev3wxk}bT6OdS|#8YpE73`0w(goSqw1Y`fni!c0T=R{dV7&?KX3bx66!k!nwmY~a)>*LpP|6I9(7KWqL!-! zyeVh1GFHGCAEX~L9^<;d z<^3{TQ}d;r1tCPTwiRJIi`Do1gpHbozHeAh*H{%CWYy3;`3V}$BNFNk@&FHK)x(H{ zL=bww>#I#R&(6eNMRK@s_q2;5S~qj(M)#~fR2(0)-%vPfSW($}y_A$rEH(E&{HVgi z+TP-jw91?B$75kTRE(pS+c+p3YZGvWOuFrF;GR=+W4c~r=*bQ33Lq1U7P5pII$Eed z^3`~J)SI!5%N^8CoJ-I@sDBTSe~^0W5X7PW#-Mu_XsnzNu;X zE4K_ujD!~48V=I58iu(#OVK1n5q5+Q^%iv(LlT$PGuwy#9ao(B(-eWbFo927p^mWr zs@Ju9KsSp#ilg`CG8$WOW*qOh=0&>YQ3psj=i<)Pl1?QD;(AQ5N@G z2Gp{U`wDb4FR@S~53HPCYTLO6F?DHuxQRo5+lvQQYKgIQP)3V~ke9s_9x>ql;S6v6D3P_?@CLAJju%Xf8npC~>$S?l zAHiT+AJW)(!q~}v?F+7ITSe?OXTq@#eqD`_4tW2kCFqCS@j%ow@}h@T(=VguOSNGk zw@$I#eX@!moc1U4nskJSRrdnD+(C>}ge+Ax4g~f8+_C_}RlmT;hT>2>j1Y|T@UYlr znxL6UeGlrsYbmi-3~}SV&ycSrL>2VpmDCe^exQkxr-s0~c7KujZ;C*qi*zcesc-CE z);BrQRL*^jByD+XJ48v7v%_)9xFzau(#gfeBNW{Z(&Y7VL>4x*gUo+OVJHP#N#Pv5 z=l6*eI-w?+em*1P0MJpXKS7G}&KHim&Hu`P>BiI=d>o4_?lBGL3Vk|)pJvqb<5;2$ z33LH~SCTN#MIiw}G}(mOil4^pm$OX}paFmZflf~8Xe}l$mgI6~_Zz@xnvvda_Qpil z^^~H32h38=E)Tn6&vMM@h?ETbidkouZ>74y_0@1@@3Tfk&Gu`=qwrPbEf_4EOn^AN znE`0OY3q%iWMfJaF!zBS$Z(9Cwimc^#S-B+r@6Yq?m0XTjzbI|yvuvafg>jX!56t< z+I@jSWJTt*{M{Nwz-Up zJ~1e12cC{$)L)K!Z^J>Z({Bqdk?RjUQ|o97}u>wBqA%1O=MgNIwa?}9|kPAWm7CVG$ zsK{$sv|L+`#98Z^{SA4ZWnk3&vB*1}lzuIT<>(>%eg!Ri=~%-6YCJ_)9TFkP8hxo3 ze@(m})LGWDNqX<706}Bm-8!3+jVZ2FL31;@T9itQ$fg%JgFYbXQqDr@^ad8&`-WG3 zif9-n6YZ3(1vZn@VKM4V#wipEmB$Fg>Z+@88t?kWGj^+Pv9|rTdlcvUJMjbmDKD?X zZC>VR9g_g1l40s3=v{eoA&>d;?Hbz2g;GW`Qm)B?!AAa3)pxw?iRlObX~#@uQg<DT$$Z2#hEpP}Yl(?31^B5~L$mIE7YSELQQ(#1SnUQP{+suo1G0YtqHzhL z_NZJyXL-s5Lp2mTS3<$U{W`A2MtO*8&LY~e8S;=$$+m6{9=lE_@g}vYO_G-T$hpv- zdl@FD-EBCGIcO)TRq)QCw_ww9-W#$`!`4TZ7qM5pU|3~^{-mJiw_wbk@Q3}e^lenk zZgXt20>T2lTb$uy6ElQs;hNx}sR0n-I(Ik^^);x-_nGiFQKEM-A4KtBflUZ9!@ocE z1ewTKkp{JyheiHkqP;zUn>?I0ccuzQE{l7|q}P3|-Uyyq`Q4{nT6<75Gt|m6tb;JL2s_J`r)Kt-|VbKtz0V{T48*(;R60eQ0wzU<$;r zudpWvyx=3AdJFBHq{(hX*70w{p)C7C<`nX(-mb%H30BJ}s`?{+C_ zPSmmt4R$Vd;mzG4i?lnvRheFh*b6(KtZipsrRRc#Y>`51qU2O^uwP>1@yJV_HWsk;D%a(#ovmC||2{ zhkc7n@4tqRng?z%xL+ivhcg{s;Cy>Ca4>hU*nR2(aWVIi_;?><9zhjBXn1lY5qdQ= zA@a{7cVr{$@)m)rbhf$yu|mR{8;I5e=EqqP^pO5TpwuB@Bu>q!$wVmQNoN4E#0XTR zTAZ%`{TWz665f_7JF{U@uRmuO-|El3Yyg-dV{*IYHFv) zYb8in8r18ZyT16Tbuo(Ocwrfw1QLum1qn^(IBwS(4*O>~BL#O*h09z?k8$D;gu$kJ zkIyq9!Z%i4^9I;?I?4%5xDeCsNNlK9fC1~|v&Uk$dLM2Yfg($i35n3}s+!t8_*}E} z!EiC1A~Bx5RH1|aA%H1t5oo05)=lR9L(D=C->vn##D?@!8RLak1CWxOYbt2_KlX8` zfWoe6wOoipgk$QgtAIp%;0an|@uPtns|u>J4b&L3VRL8aj21Rgc-fd7H>*Yb3ey$Xo#WQ%MHbGqB>kYVFIAxO538eDhI!*hwnkAoUr zT@)$N2NPygkS$=ixbrPQ1R@idCqr`b;NP;t{MI3mPI!d@NjB@`V8wjjUhXcP_M;um8 zIeAq2q}O*Uc;~)wDqJ?X#qNF@eNG*nqV-4{~)SdZIhMCrk2hvE9vk{sRdS){{>zys;hSe@)^p{% zV+BLgYz+RY4t(V$R;qG)1gC2zyjwp6xU&vLs7S_`Ii=tohLKVAx_wWMY4;%@>Bq;s zDrlXRLccQu1pA_11rgIWOB4u6f4q&1aHW^GwP?oOE!gv^sN6)z$uA*~_q??NeIRh6 zYUw^U(F;*@|)Q3%nuOTDi1V+T>)_q2uebs}aPs%;`-u;HN16LCS$hJ%9n`x%(0 zV5()grMND9A4wA}nVZUYVCQqASaw=G%P9an>FOWw40chYN_4c}l+AQ1jc8I7E}TM< zb-u?P+r&fqu$Oel_wa=GScCs^Camh-3slzKx1 z8i5TYF>$J=D|P!awOp2&E!|urF!nlWqI3B;CO9Sqo)G{qoJoQ2t;??OPv6Rsu~}ua zCSz5Do>r7A<{hz{CZJnVUS^TrqH+NOIbBg0gIRbpLW+3II~WuyZT~jYQp`ee9Jm#{ zDvBC7wMeI?9>%+36go5gD&xs~k@BPB7xW^?w0}KV8;qW5S%hSK!GPbs{OIKAlhu3T zF=)k0bpAd}M4kQ3P8fwA;l>Vt$ot2pSQlXw{ID-5%>Q*>+&U)OOoWE4hKXe-dQWqj ze9yn6xBLXX;!_& z8v`OEYxoC1I0KPq6RlWYn7gl^LkVf;-1{qd)wCX564`EVu_VREg_akO{tzCVy)=KE zIfDUVEmpddS-S3)=HFeG!H^_+RM}NMPs%JTZu-9AGGD1LXMsAGw-k6lagQTA3C+$) zZ(}l(rE36@c~KQO#D1wknYf=S4Awa;X8b3oI~@IZF%U@PaB}YQn*PZ35mfZ@9)3S2 zcIv00@r6)RJ|u{{?xD@&Sd0iy*|rVYas-;v>r0fs=9X;|7u7l@T3t}uKPW2)S%UYJ zi3^Rr1;cd4U>E%&F+u|es&aLzfTOo=?PQjLeToddvVf?ceqaE1q=UFOLD(l1Xs-{Z z24xpzB2V6VfF`f!?SsP6v|H*wNm;U1)%O5xI-?1niJDfsTwmlL zdcnA6;IcgfAn>>Eipc4JGUq)p?KVkcYE8k|`bAjOZs$G!GIX8QM_%Lhq?&HFd0?Ky zfmC=>ft6G=&;)U9gbI-)R-{r@Tzh;#BFu}TGIAYWYt4n6y>pZ;L9;Ko+qP}nwolu( zZR@n%r)}G|ZJc(Wwr#tozjyDQ_tyM1Gr3pnjEc&vh+kz@?X@c-Blt`OX2=Moqq{Og zitML2w~=0A+-Fj>9~SR6Z2HYfZ=)^JU|YgI(G^-;#l&{vE95#coVXzk)UuU4^jgE$ zSC4#QSpTdQl?Ms-O1ttJLgh?%E=M;yk9barYSn#tB%3YXLZ6SCtxiJw>4!LH4ac^B$6 zmWGIiS45<9$cT5JeA6awg^8QwiDdNrsKZ5yfI~%{6srM{tdJ$R{=x&#W5(5 zWvtaMV2rE&Y6CawE3(9QW{Dp657Q%J4m|< z!ka&3+4jX7_sPnNJ|;X^QPBcrI7ZFVvY3g7{hPlU^eQMQipA zJX%GUoy&+ot4}+}c=84A&lP)0KrtEt_4a0PZ*KW-s=BD|oy62_ONZv@JP+*=Z4yb> zk9%5_7Lh=v?e`PF=U>#trJ3tn)ga!jf(z&aPjnO48?ba{#+_kqFqnu*kERVusEg^Q zg&(C@t;g#iZQnvLor*}DreBW@P0Y<>`AdZx@VInD>tSp|_Hu!*!|XiT)=2$8 zIz0Hp@v`!mv^$y1`T)3ZEzcHy&Qxr5B854dWul=O9V@v=I7epc+Cw7?kjqUix-vrl zDGzYF8OCgpdG&Q;vK8(J3mx*XJdI?ru@Upd--8b~ZZHps6`%4o_HDwCuO!}jsCk3G z$yHoef0U-m2AjMkiUkROd5%?0Z;17C)W7zl$yV&_g+hfBhv*h6_=P)OjCg1~X`nF?`D0bT5iMjT>d$#}n1v(P$`(vzrE z(y4%_Ik4@(&ZYvjCs6aEAZd-D)vPARiaY*HeRt;o&-;9_X0fb!oUDe66POb+oP|eg z8IQ5I;s0vXak{)*N?AA(X(~;=@ya{`A;d%WFen5G4FqLnY zue&b$&J=#0X$)qq5>?zi@1AA5sEf&c&5xTWQ*~YKBztgZE}csy(tss1C_>WUY(s80 zMh5e7FGN$a)F+%3U@>likiCi4tA~SxiKiLW@kSf8)EJl&OpAY&d&*9r6X(C8(-~*L znLI7^7jIU2HI~R@uy!7Zy5aZIPzNdO(f1J@vncVAy6Y|QzjNff(&hjnFdUI_TATe? zxP5zF>`5aW%Yk}d;`8XX+761nIz+oge*o_H<2tkfroR}Q6A6gYPOKHPpK*N6J=5gq zK1-#z%bD(U2v*m5So?zLe zAfK~OFvX?`lI!%jx^MZ{{Wo-mFT9C^8m%U zLN}!YeoBqTz@xy)td|E?-Y7>vl6GgU#hb#`9-Z_vt&v{`c~}i;$PeZ{Bh?LZd?XLr z?mrTTlGPy37&~rK!BAoeV-E!*1byv0KjSmQDIqHxBwif#JNRihSEKr_N78rdB2WkZ zDMKF-)+JrVylnD&7c23q2x0vGd$J>nhHmO^bEQAO8&GII1=rE^C}Jw4D?+F26n zz`Iy|4t};C&tv`97cRb%Sqf45-X7C}2XlqkMY=shziYPz*!g8Z_;BQpF#LcEK%`_AdFsWpYeA1~D2;6%6PkO9kh!dfhn`mMRU zkwip&f1x7)&bjN?!6RD=`Cg^9hTinl+hAiS>V$@VXHTuaJgiflB?VsccLFlV`IRHI z#oyg$hpcx?8zWonCU`Z=vM7>vzXN+Ha&n^JwXnF;f7OK759EBD>&2JPo|O>hnDW%g zM>nwOIiI*+S-_$d|NM0*eE{Q)$?n#=!WUZ1eA0^Soc}~<*@cMh{xSaUjtuG=G$Y%Xem5=2Ia6LI zUQB+`slfhoTz1zT>x>Z(6ol7l7K+`4pD*ls9)2mmL*;mK><*z%m~Muz^K0w^LofSP z>NDjEeK0!W5%dpn&cjmH$qJDCtcM#!F8W`l5|y8)5E9p|K}VYXwx{JMLX*(T*BpJ< zklXqlo`#!`-o2eMej4$giS@0Sc8BUDFs)SSBg4yI|8&)-fq$QFIjpI^ZbI{u16r~^ z1h^3A8l*FgM2;+DuU1YZfd|;k2SW;=VH{k=g4D*`tHS;&8lsRLED`}aIMKGxGFP|_ zq6^#jVXNQwD^I^c?S9PzJ#)^KTw?ia_>ofiGm_v07GHw9Yp~#QSN2d@ z(MAwaN9EuwyZXM!buO$fx~nU9xbvo%kqhHq@EO)WSFZSbX{Q4(;KSJ=jl|!PMio=J zpS_2inPkueEB-g@A>$1mZi)d;p4=y8fpKJ?wzDbNIqeK$8HSV=nmY}*=`Uw>t3ZYW z)Gw*gd19!^m&(gYJk<>LWV0(!UzpyMFpQCna*)H}u}Cu5^~_PCqUoa;kjP0YTy8#t z9daN%?C(#!=m-|U8VqCJS)1{BJNpF194(F;nyELba}?OzsD_s<`me@S)sL^qjpEd4&0(IWnutrBPS-;13tVMY=&D5dg)~@%!q$3bdeF%20le^uA z>NwV+?+_01ic0~%64zz_sXsL7v0=dMT}dSmc}MOLCN12iIw1wm`bgfnQ>t-duboHU z&DjuWgea-zW{a0>3xWz#l&t32MsjD>K>asJF% z^eZw9LK%(gX|7u|R^ymGk6wxV%`7q)u2W2Ypm$KbaECN4+~A1G-ZCDw%d#*uedhFy zKkqte`U4W7A^yO))>e&v3q?*>N`dcer$v&pMIF0V*Ouuu=baq?5^aCQ0- zE46HXo@(?5RAnU`NH_7hI%?$)W{p+#KrB!swJI2b+@l@U;)0hSZzhSLl6O*l8+)kL zb|>hq-l+|hYNtZB?3zHU85{^9j-AXp2H@o`-J*^<61j|JwM&_+m)zAg`9bg?(Z0W% z!GUf99C!^I=kETv>u|ewS{0tUdo=76)nFXB0VLx zv6A}O!yf89Rpb?sh7-;)-S}10N#g?Q$@O-9K~M#T)J;`Ti4o6niSa`i{v&#BM0JFC z@P2jw(JfW4B-vrcAKw?cN{}(|)A=xLSP7MyR=a#~;N5badn#|nAr9TJA!BWLPA_uo zq^62UejY8>js9m~8hZeXlu~)yBjoj4cFciFYx02h(Efq_#!7Fw;x?BQ-FDzxVWC`WPxyVf7#>Vwwsrx@T)p__+fkMx&`Qtnk=|f zxt@E|7w9V=>8V4}QCI22h(V@b6w0h_^anGrn(U*Qk6aX!73by$REg_A*-qG^-#r>ye&@B_1<3+l7aX8(nktByLA`+M#ElYJy@N*l+URbn|PLuweiK4IKcO#eCZd4aMUh%gUxo5&8*9}HY zeb6*)g`cpN9Lm~%H{UBvo+*Q=ez!^Ibz3gP>lOw@vbR6NwG_!uK=cnW1kjFXJs(IF zk%&$)od?r;+*-agPBI8i(Z<84un?*#)tMFhOk2T=dlLQxDEs0CQyyq#Rn6m{^yr1s6eNr5NT%%tHSk* zgsm(-%h$N7R*%XnTvBU}cn@&ksbHX(5^A~SHlm&fZf$|(Rtz}Mdr4*_SsmbDT9PoP z8x4@ZOvS1nM9YA+P<+?WPS$d1yYPj}h8!iggqe})zIT!H#i`}Up-3cQQ`bJ-)gx^h z9zF@6O5u6irTR*)ZTaG1w!i5Kzru9Q_XYK;_hZ#P>zrEn1$R)5hYz8j-GeP?bdaiE za8O!q`5PHkgqYzIsQPfB*;pgS|Oq&FRqQ^pBWLAw|z z?#1Gd26`190EJ`WKUMm)mTYjLP+87kQzTAifspKK)I8#2>k5rXb8PF6h|@Bh^fS`8|F)P1&W%32^0 zJ5K*@G-qD7WmM;;KjYSP--Y63s5m()04SyrjcA^0WOBP6o^F-nbV2Hkxv^&BIA|c$ z*cdf|1EyK0gj$yc2voP_&@6J+U249$(q~-U)-bzOHUU%fGjgxEV8DuK&SP&aDcD-To=ncWNQ|-U zCQ=q_5%{hoGbTOm98qMLJv`KS=hSz}e%zj%6A8)t1h@n7iG0Vnf_Ed#ld{zO5@mymimO}|+7*qeUMeNxrU9hF74(YT`mDzt5f>gMV57W$Z z6;xN9jPG$nIJL1c43V!h#9~eKOt|X4zd_Ks8|909*1~I4JJ1>VT1{PipYu@}6A{CJ zA@neG$`Y2}i#hD+IY(ytSQQ?qg#Ky5I>mRVsU;*t17`pO=G7k{VoavKT4Z;fNU~*~ z(ISn%E3<)sjQxi{(ndPzR5-p~jwn(R&T03pQ%^=IpE_mIf#clze-eTi?^ z+hM!cd#<&Ykzb$S1ez>R^bKk(B%WMK@c4J&ILp`zu3QC?87m*7mMl^}5&1E=N*5CcN#0X&6}m zMe22>PkMRZN!Ih$WpwthZnLX8t2ZHnfShLf9HNWp3HgTb=y6#`1uEkN=ewSpyy0-> zUlDkaD2V)AQ~;kK1vlCji~H3t+A71ItE6ywSb`8n;N#)ze4Dj1W>g2!zH}el*gLE~ z{3Iyt^04YWL4qo(#x;As@0}|yZ8jw(@gpjXs_oiSFsg+9f=R3U@2z7;xGF?o5biSEj`y{a#T!|}7WO3TIS z`SK0kJ2L=Ll0#OM^3?RL_$)7acs;HxHxC7Hw>#49J(83ap^Z!`r-}L@SYK)^>qum) z4s|pnw{zyRE6m8>sWd~;6ubPNh~WZD*^yukaFBKWF+{Sr>Ibz#?F|l7J6U)iGGCgH zLpou4WRqN_zfH}uf08U1hVt}^ilX7Z`Wkl-uyaFI*sB{?>obxn z1*Y-UTTqZv5GXx_kNQa6R8*|TPhMOg@y2y=Iv22o(PZs zX1L1k>1uCVSRH0c()k*cwUnG7mD*f7q7hm}sr4S?gS<#uGGyQ zrb`;PFBp0ESYQ|-s@yXxv}WvQNgUA%x-C~+wyu+$ac37vj201XaCLs0gs2c z<=@I{Iba1T0pXq1$Ra1^y5>Ywux*R%^b2!zdWI0~=a1b5(z^pkd2k$Gb=UcqdjHlA zIcSaEim3Cnc932J&O7XN^m&zO_k3FDlRN9jFa&568*-Hz*Ge}x7#{k;-?04)FSHK= zLeqAn8RIpeCwjX3`{G@K2`jWmoOl1SjV7ykB$!O2IgcwqN^A07Bz3=s^t_XOYD+Ft z{9gs_qDJ~Fb+aXDU`xu8Y?d5Wn*fW>9^K0fmG3@9!01SAe=@~9`y?4Qz-wSme*18M zq3@g|ah91y5h9Oh5syOeU>OWn-aJj$0A1HPwp_CTT5WFDB}E6Ig5Dxe@E=`6UEm3@I^p_(@r3_#!EaNUC`_Bk)6-Tn@=eRTdC z^l+ugN`Yot;W&vE3ARbK5T8End%L=rYzh|6# zSEOteMF`2VEQ-8NS5b^L3Kf{8)n5B8fK~AfB4lY0+*FuW8_0<+oS|)E^>^f-8pr6O z93AE@=8C6~CTPoh;vEQu?v-tXAW+>((4fJdm;)dyS5dRuAal53lwx0fvZZ!^if`AG zzuiRmCUy||56JHOK4UI){RYHw%D4q;GUY<5n*}OM=E63)BPwlht$wg~ip3&`aoG-o0EVyFSBtN>FYglSnS) zUM#}mCC}Z)ibLo7qMmU{+*v=@UH#t2~5As$H5 zp!^2-W}P#V-vSVyttyiXamOes2`%lTG&qJcSaX>aCNgQ75-!FTDU|FLuIE$duT7J+ zGEf-?iDlN5zhOAe zZ1iq#OXdzTF~57gxr~66dL1uZ&ciPaj?*Fc7nd0X1+$PJ1~qZS$V_#Q6wJ}gnESd= z$xTKl<3VdB*^%gY_^Fj?5uKJEhY2QhxNJO=?h=jVeIChYb3>2Jzn6_gJnhc1wRJh` zhCC4_;9s#&KTAUUrCva3MQ+Zrm*Mm{4=`z!UxJwQ@}<*vw4Mj`K7J!6eL1oxLYUMs zm%XFuN%53F8h}7SUVj{tvp5Aa>NU|Sr=m3%s#IYLI2(&IzCYZ*MFng=c$;2j?||A; znIi0#3KyF7$S`F<1-hwDs*jTXo3aa6AxspAeD`of?pz^ml6~K-88%9O{QRAnrh-A-UnLL3hd9^!gJ0<-W=u-8O3a zXF)Kb>W-ZOe8($mHW4A_u_#i})j`0RxEz9oVSzEPE5Y(HM#d;G@MUC$%sYESXuBCk z7hXoAmZDRVao~Kgh=@LA+*9E7i_^a#auf-L;QI4%S&MD`!sZ)_eK%&7xB!2X#XY%F z~r2b{)}I>CM^Bz)1-4CWsdCR2oHazeCVFem-)?#hGtF zyQLZflf?-5jg^dt4s_KOya*{lXCdzCQqNf)*E3=_}JZ0nJg_LoFV zV~GxpYziBaG6g@xL8emWRtb3o#-FXTC1$QdqFa4P5S_SVfSSY0kRGx;2v_TyAm~0r z%HsF6=AtuF#*GjEuZd&gxN&G&Xh9SLgJB*m6*|2KWRY(x%8`XD`DPDuGOw4Z%hIYNTF$Hq`)*b>g z=GkZ(2Ry5U>Q`dUR4zFIPk|LIF>MZ>SNO@$)p!wf(Z7AbY#A@8+5yYP0Nm1BXLzFC zuNoCC^#@NV7@)Cf7GUBPA3wEry} zVa%mj^{*X%TpPuzhj_2RfBn^f*$CVY$`ZswDu%;#JdBTmfC)WQcg(o#0SLsS7_~9r z`$pH)fvAgOJ9S7(t0nrkrvG`&*&Vo#tVDcAY!^87CxE;lxfZjAR>?S@n8&Qb@9#cJ zF|W^1UUd;k8n2Ip?QOc6l&epD>>|T?%q{fU&0`tg94I*gE!*GmdJos%L@W#kI@h!U z{j=9P;JSgAj1eb+E8J}lIu&5cphx55fQHHs=5_APBiuD2_tx3Dm}|@{WW4=sA^L*0 z;pq#pG=Gd*9Hsh0L2I0!2b0D@4j7Uj=b2^F9MgcAHrI<6ylbG^%S=BT;jNJie39`$ z5@m4MTn{%u2F=_oy4d#XpiyWTf|rb*>pGSEts=4@0l&IyOr(A&UumRl@0v_$7|UqZ zGCJia!Xn|ACuj9u9@_@?aiX+G-wmwE@~;qE%1lFUR(zU#NHCbx&{m^p8g~{~h3Bf? z<2e9sqr!F(CIPt7?hv{SdJkXAc3-MIqvm=XKf$)n+t8{souiiV+!zsUkd~fx(}1$| zL;dithzH<~)ikxU;JGWBMQ4(W^DtIi;eKAkH}oFYQ9ktC*p;fsXM&`tH8mP z6Fsxp@;oN=4Qh;DS}w>1{hrgl_;9zO*S8JJHsP0w7@>!%f^MsYIP>Tw3=8Ik^OHHS zi|?PqgJ+-0C_UOKuB6wWty?ka8RIsC>MAS?l8qR@o72=(KCJWDu#l{+>K+vs|+j(1MNdf9F{{Oow`H?sMf@eMcWm349_uQp+`-a}(9MMt3?n|XBYV+fW{(3ZaOLD8u&nxh5+X-q?< zfbjMCvK1$+E1h+@VwTqEcwEY*4bN^`*3=pnc9g_4UjL<*K@L9CWUvHc%$1b+N!H=` zDtz#qr9$YVQ8vINTl&;mV}JOX7?NFz6zK1Tl*sbsb7oKG`7={22{kX*>4iBT-T46| z8a(uJ_lo2WLS+;!7y6#;7zWJ`vOK0)8P>v0V+S zuLxu!8#rj!NuovhfG3#_<%E5U9Ii+erl^HN;7-&E2jr!YPHNVo7b3N<#L?(KC#CDZ z19WV&JM)K&`$fH7e3>cxasQksw)ux(i8lJOcX59rrzMg#SQI3d?_8x|O>NioV3e#! zdNrROYGg!pBiCAlTdEuq(Ld398^7&i161u++aq4NhbM0AMN`B zRLcL^ps$%_hwkL7ZNiZ@DGMPz(cLa;_NKrQj)x?W*GC zy8POVj#nh)`#G46O&VQGbZqdV5%%2e;+4VguyEi(lN?a88I%0W{CdECFHHIMH#jgD zg&+xHuF~x(M||mj&+@|e{NgZJ#$o^zdXtZMw4fPLa*{W{Lm~C;u^ch)LtzlSSzca0 z1tGH|v)vH2S>F(o~qboN=t?@$*N^hb#%&96|9&}!P0KI*SOb5D^dUF<4!U3 z6_Hr40Hf&RBDrYUtHdg~yGpzVD?{CM(t7RDJD!Qn8Fzg%x7l(9;&Yf(MmET6bA&_~ z(2<-PJNR%has!=-@1$aZYQ>%tv6A`B*d!0a-6%16~C3> zmHgEv(_KIha8$tTz}tE`frF++~w;UsCEJp|IDH?xONwY#8-HIMW9w zSQ4~%md9}amM(1?Qz?zvo)lf|tQ+W{%m)h5Eku5IHb@1$RuEAxz8wqYUDErYBC5q4 z1PR!yCj@Jlbmj$hC?W1JZkL$mvBX#xR97^Oo6p;lhv9md9H1W(ATrz`YuL#-hXOGi zysPn;hey4lXv?K{mv$|+rBJ(x>Hxpi7-|*00cjTS_V}AIh}T%3JH?yqI;=p}=twwZ zrV(@>Yq7KaaY+vyLZB*3gGe<5Q)nX4VAoXgXa&UsTcR_b{PZWB%ebc~ z^Icg=30S$!;d9`=hq%RMaYmoZ`w_0$hrGtWGm|00n2V%X@NT2cEiCD_$pMxL?%uJ% zf}8f%%cF(|jCV~`!}`PUPgM$fHX4Jn!2}cvZw5N={!N^A#ct8O05~ayMPm+D+7HQ; zd(;B;OAE&qWPQ^iv_H7+V_D5$>Z4q!x`+zwlfR{@e04?F=-O*n5P1-U(|ZpYRw2g| zx)t(3qG&=HV;*&P98X;Pli5bHAqC@8LvNRV623nfuWA+63aHt1l7g=tXtg>Vf+;Tq z)pzKQOr;NzeIUDJVC+;l?dkT?vG2rs7=yVNwC~Ahx1;%X&l9Pl*>>q`7D59x7>=va9LYg+lz$o-O*9Nj`T8Trs@;C&>- z)9IspYT>MU7RW!ahdX0S zB|OlQ>b{-qwaqASf4JQy#&e?`>OJLh+{stgS@!6#9Hvj)DZ!U~P2p-@#(-)!aJk(y zJy`E`vVwz%oyh4k;iU9UGAkD$EXT!aiK6pd4)V7_=MPtPW%t-=YybRjtoYKxK3b;L zZ1frdi#ghAu{N^Wh>L~=qtLDS{JGh5=fJ3Sr4<`Lw?V{6sseHt00ET*DRm_|^KX?>7)V-_d{Hc@QVKwM0oc6P9!W;=+ zhHb82YQjbbCZxk?$f7G%$YYkYGh^}&zy=GDyLHt8kOf~}rerNhF2He}BBat~wDO{h zLg+M&b=+m^HnC>3LQFCA;z3mf_d}4^NEEvi>&Ev!#1_h4Huw zMwui0)!97sDgEOVs?C&snd{W>A7iHQW>-03+7Xf$nGMzAwOj8nbrZ!_& zS__Q!GNvXspOA3XO$8kW3&hnF` zDma5c_p7YIas!G-e}Th%2Bg{zyay(C$PnpZ<~3-#t7V52TqhJ2nNlyO1+?)_gEvmZ zcstcwnUm`&vh#qwIJ$ZWI9TNQKMOUP(cKmQwdjlRnRR4w$+42LdEt>4Mp&h2xY!w2 zty{Vgv2u0o71`w|}C|!Vnm%qBdeRFB!fU+LTsrY{PSmv`I%tS}!&fpC! zim3fi$34p1+Mmd?0V6)@ncaC6>2|gm3jkrdi+>Vt0o7>>G*O=gUu5%IXSJo3%OOl) zBCS~3X!Dsw-7OAmS_4YLd!jl7fM~v_1&v(OU1rOdJW|j@yi{fH+v|$4iSUb@bqg0GSvP-HbXz^zRWftV{qdy0q z1vN2vWgZi^tMiIOYA`qJ* zppFCTx^2~=`#9atm=>0>n<#tXM)*)F=c0^*;J|sJg~dGHc@R*g0Qi4XK-jG+!jlZ5 z=(ortF9KA+1?$Mkf93r26w{Cr2c-l6q@<_;kU!hd000mu0O*G!1o>hAnDGr z`hoKPw?#i)0Z@Q1z<(Y4KQ{gkrvDiFKbZ7>#Q%dy_(u-%-}Zw4$ie>)9_|0Y0R;SC z$CUhO5B%SJC;5LA{EzM5tKT~S#9!i4;y;T1bAo=pzSjXF07!6f2yie+2nYx$C`f2n zR5(}|7+5T16a-W}Yyx~dY+PJIQhEwPVpH^niZA5(9vdfIyIdzJ~w=KX!rv{jc(0P=2<7 zK|sO4At0fkVSXAkBmU=1fdGSofPsO6{_OSr*$)6k0z)QZ5&}n2G=v~_L}d<$&xa%t zuJ1=vn!6!oF>(rof=0){#KI;cr=X;wW@TgN;N;>K5fu}ckd*qRtfH!>uA!-AY+`C= zZeeNV?BeR??&0Yb6dV#779J6qkeHO5lA4yDQBYV^TvA$AUeVCl)ZEhA_Os4>aA z1Qg;wxPXA&{{tKe6pV-o99c*a!q5?gm^lCvRX9Gsz8{K&Md=33$Y~B5os@N#?Djv< z{ui?UcfbPweYXDdfpr645K>`Q>p5JDdT&EdCLd=#JcACUFm1%bBpYVPb z**8l)VAaNdXx8e!{25YrUrAuGi%(&l5w$>o=HtvmDD2%eec|~EYWW5v`iBtQG<@KF z1BBN7$9o6bY5_hR3l#GSzT)##oBI-;`bRuzcB>U004hCC()!cLk=x#Z=^V1U)|(Hj z2rq4?PM>&Ntjz^N1A+xSN6m_e?k1clKC8iz4DhnE7LIR#1^qC_M8qmO2&p-q;|z`V zWxf9_&!6|3Z@{je_swUlJYga=8->noRVO175M6ZndrCxL^Quk2GnN$K} zaVR{1Yg8bhGCC=FdBC!I>}#Fiv3x(-e|4 zQy&O0VmM^*C9Pyc=d;-G2UeR=4ZY+q~h$PBNj}~HZ{I={4GZmYx@`BDTg&q zlUlnJBJ73P4CE{X7Q{`JZ_(nbrx(UVwRcWE!;n0*@H^QuaZJbVT>qDf)Gf+DJQ%Yz z5}{%8Ml3U5TP@W~X3gpTP=~1S5Q>?ar6ku@Isv&n-yeOg#67p}(k%;a(<(;r^szYU zc8xNSteqRV9S6=~6?5`^kLwqIJvXxAn$mKPA$_PSYZ7ZDP`hZw8-H8{e&QFIAye!j zJq=EV`rF(Zn&}VSJwER9-R#xRu9vXyJp$fUpH@usWL=6vwvCdvFWEWbG#BI9K)5JyQW7%PBMx> zt<-%04cz_g(m3aPRW2#^b~pW%#{<&jl+xJVVRIJw@8Qsl#XP$F8! ztA=8tcjNoNR1dtK!<$xnXtlP+P4Hn1>N^5)Xq`lYavZQ6bFZE%36R*Nt^c5(T!N?E z)0O-y76S?npXyY;SMI-Bq>^fCcNd&*Tzr)J84o#H&x|3dHWNDutWQe&A1$Klwnl_8 zbCLWAr+V7ABASg$HWyVkHrb^Rv-D}c6?vh!<`ASNZtGh7oJ-aAU0{}AEeW@>t__@d z0Q86exMvB%-$jn+Gu%qi2aCR&-+-DyOPVt;gb!MIXiq)+ry)H($6n+8`(c=$Yc4kW zv`TcW*E5g{XrNue$P% zKyZg#^^fnNy1Hjk#-;lxu6?tj^N8a(MK7B}Vv^lb@KSdC`I=p&VU-q4HTNA(8Pv#2 z79+&pH|%yjFl%eqo5{V9nCz@tvXF-;81dOb8g{N{EHwfhlY6~)6`}@b9A7veOSh`l z#!6tw_yCAjwkMT_A|&31AD`RyhzpwIT9i|x`@P96F@pt5C!L{r&fv6FTiv1CS*~e{ z0vkFvsh!>^f}1~|=Y3 z(NYk!)pZGm4>IoHVp7Cc#EO>dq}C~U{KCWI&)RB7Y_^dIwHTIhCmM5&|0 z%}9(k<;K4eFd_IKrAjVn@a^}68$BjvLT!&&mug>P(9*tcZ~=Wmvt>05!wIi`tUcMp z9{^P48I{k15Rrc6hk+LLxtu4y1O&pH!#S;V zvz6si8&QrIFJKl@s!@_1pu}4Wa*V0-hMztRceg!;+$nj~eELY!*=F~MLt(4ub<-6KtXV3L?EAQv_ zSF@6l)v&G;*Uk-iFqx5(xVhM!W0TMJ5a$&_`E|4klDs{};Aw$&+4N8=rnR%c6b7{j zD8*_lxF_yDaW{q#Kk_0kn~7MK@+*4EI8RC1J!%%nQP6t>yi-^7GjYme4~`aFaY{Wb zqs}n-tJ|s+N}S5R+aeYgAK>9_ZVH`~04^f6KZi6~Ykv|lavZr_IV-wFh}Rn_w(Ftz z1~J=YsU+k82CvXw<1d%t3MOw(SU~h!>xG~A7Vkz!S31Fcyzlo9HG&>t+NAzN`wHKHzSM63_Akp$;w&BaGk1KN zrN>T~b1a*~ZtFs`+iBL8IYx(<4e+J)MKANxDQBhgwc7CN2U{354h&=~nWO!wcjR3t z<&#bcxCID4Imlt&Yc0l}%ptELWVVsvXqnL;7c6?N8RjALJd%vj6_XX0Ym^O( z7O&+}m$?a&KNtw@GZ2^%wXDuG>vc|@&hFee)zbRyH>B#%$~sbx$9dr}WJ5;mIDTh4 zzFVcWGVT?VWoKHmA=g)InnSIWdYn5Z8vlZTrKw{IL%C)!bAs@!c?7wuufs!=t2}}f z7w)kPdoJ>61*vZm(UkYmzI-MdD6@s`%uk9@+sA~7P3#Jne*I52ViQ~rpS?OhRL-Iv-L zH|tLyO~x|bvlj(6EC?qiW^^>!CKv_C@UGE8(H04kLd-Jn(Xkm(h zuv4i5w9eRGF3Ul_yw>K1|5&qNo&;2Z4P z=lxpW?TGQ8X`|PEoFq4h_ko`H#^%N_xyaR_w3a`UQo8P}j>G}0Cb^je!dAs;xj}^2qKsqE7?7yXP_uX|2o@%XXwEwSmuKXYB z@B5F4ghYsDEDhc&>ln+73`s}x1VDN7QvXU|Tu@B5ymEMwo| zJ9;ml@Av!o{s-Up{B&RUbY-kSv)OIEQTqu-zki^aDppCD44XA$Etl*+A+SP`Qe1@~V*E zz$i3bFGdw%$8E3A=hYLk;l-;hJ1*C=x)OGOr93<-ph!P@iFEj**LnKlR8B4@fQsk> z7YT^o&;G1MF#FtokcZM@>I2&0~jdb46GcX$j)bL{?}KskD&O$gJv;C`=I`^8p@8pICkY3p7$~+iEP{yp6x8W3e=irVr8o+&Lho2`Ln>EEWYr#Eq~ei z==BHi_F8dDnpTDpa4gn1ZMzeFBZ!kvz={sZ?GsX@z`GkzSLPb%Y;xVC{LxX5WLcv* zRu({KpL*_gk(ofs>MCKQR95R|Mi9P2L#&7=Z<^sswqTrR6c{-Oa`^n(>}ysH+Ya!s zgqN>njL%f@f{9j`yyja{On)PjthT?=<5Z@dgL!J`YoDvOjpvWm#@_?yV*Xb!Fmon z7}s&Lng_T7oY>hdd%BDr)K}~yy*}2Z{wk=wWcpGpQbg52kfYjaFDi}@`)z(@hy5n* z`s<6kmIw9Bskcg8Wqj$m*gKyO`9bCic&U@-VcXv?zcnyeu-Qrc#-Ub)W&nLEb4xZ5 zew8}Q0f2BjHl>;Nc!GL%y@6T69Wu!$|f2{SX;XBy+|Px)Ti8HDVUs#6s>H$oigc~i8FfksxP~=XK~w`zZ5Mu zTqBy6yNd5VU1P=a3E<3Up3DsA=Y~&u5{}~5#%uR+M4IgPdD@+lQBC$8l-ZfcPBxS4 zG}{qRU#^IbS}_!2h7fQSr0g}UIL9pbl)9vvA&X>c#2GS!Gt104OV)IeL?Q zfGs)w;(~61W`5$VajTW}hX0wkYzq-c&#TfIc64|*{khtuk0}+Y%}hH_#}@3Nn`v*e zVi5kzY%5Y(45h;!FM;rMpGtxFJSY#OMcAMUtc{v#F)yO0F*W{?&-SR1QIb{SjlCLg z96|45sLw2&_(81CLh#i)*J_CMrJGs9n56D8CB^-p zrgYq=wWkfF6-y5D$C}MWOVaYj+|~Os zvs8l~XIop20pNl-Sc{8?agOEd=$`}CZ0K^bS9)B!kr5&_0efK#TJS4+KMF6v0NjrXWJlCt5Q0|mQWjNj9_1L?7`jt=&f#{NSEcq$X@{hq2pW5J6-IB)o)z=dBv|^b zh^%VgDX?lrec=-F8`N`oL1s|uUp<}tN+7`%sNv?&sQzWiZNI0;ciOq-up>||>$F#l zmeUtmUHo(h7m=E*(NvD7KMW*Da)w;YY zD56`NfKh#FbKCS?|&Kr$zZ3&l*h)BvTaNMB3i?89-3tNTrX>Z<{X=S7x zc;MEgh14zGi%n=B^Q>)+QAZHc_T4-yz7=s0ywJs31UA?FUx`4XZF$#r$+t(barIt+ zcD4B;>;yI$TEX;ID+h}NDKkKcK-PTsvp0Qre~?t3G$VC{DALPvVG zN+iLFf8Lg!~Wr1zSgQqH*8f zwD4M)&4)}YfOaEwyDP5aY{t1NKNpC!vCm#DcM$UcnKMTB4tyLN&(2O7ppx$aVQN*C z#Qi$mW4p`vKE9THK32vfOJ=UC;^|tI8Y;{(123<>Q@=U;M<=t=j>oyUV8XN!x1vGs zX13~xb7A7go{IbnBIb?&i5aG5(0osKiM(r$O=9<|vS!-S$YPL(xv&yn<*+B7vn%;J#W{p#-}y zSEKy1MWbZC3epiz4Hc=b&}F;rf^y(lHub2XAJL1QGvk$VqBo}%&zRt9={<+0p`4dg zYu7IFZ8dRq?BGJljghn&lVjo!$|^iOLOuAwDg~sdB!{FhrN5F`x_ADcn-QJ&j{J1$QJ^rZ3aSUiaYqmpis*6=Gz^2Tw=KCwd0WOCU zN2@u?d!I;j9fHMM{#2>fi(S?E;+#S$1ko!^5&*+6q z8m7ZkQ}jcIHP6GETD~3wN_NWD@41289liOwSWOt}92OH9$>Sz}$Tyt5+hh&h zC?v%1iyJCrW?mSEyYy_n2S0mCdrPxj7r&<@RLZx}#4deJUG{XjX0EW&mNzQwVU8Pg z;Sxu1wlxmxaeXN(s|nP<-kf3UaimAtt*JUbpY3(oST$v;l679sXi=)%r?^h&xzNLF z4gOhIVTjw@Ucx2W*n5i^Wo&Up=cA~E-sHv~-kyF=P!QCdW*~9BiJ0QzM-_g$L01J0 z*^kiL(%O_JzZy97>Np0N0QdUCO$?&*#!0c$?RnV(4uem7dQhp)?SD>vIzwkY(o_#Q&)N0~<>Bp{lBK)ZpB~c7+AYA6Uw==*!j(HCg2`=qAy6w& zb?Xf#8GPs3h}it;-W3tu;<54wB>*ZZFn!nX(YrOXpj*+m+Vk@CqkMH7+4q<&hyhEm zY!q8uv}o}bf?9<<@syC`irwePb?l#n=$|)dJr&S;jxvzv`Y=4q7Zkk_FzC`WkfuDz zg()HHinD$HZSyUmyv}ZE?8So1M ztJLk-Me@bEMDd{S$ADnVLdsmW3Czrw>VvowX^A4Yn#f{R=^nyS$Bb*s3R;-@z#I-y(o*%8l zED}kXEwHiX<|XgAYe_m~hKX`TAULqgNzUgSX@7m-OV^e$ADJ_RX+0kA9q#qkjUheQ-~nojRiuS@|k%CzxQ7H?WeuA}%H{c6K;FDP9PBy|hW1 zShJl-Q}T&HR73lz&VgKk?|HE!jrU)ZVa7g5P}Rt~lKqKSGVd~ta2H0u-Hs0~dXzUZ zxJ5Ici$JvbW;vUSHeYMU6Jya)X%^tpwqJ8Jj4W6hOF5Fky+Kj#uE#Ozn65p&hr*u&6=>54v zTBhpVIz%d$eh{bXfXbE+WIs1K6z#WLat!#8+F7Wnu(XZ-)YsPVg|clFQT+@ao*)=% zPE{^6B3(W;VnTbx85n-yLGOz<4`bBOEJx&10nHe0pwGQ8#2Bbft&1V3z%OITFig&` zfL7&{Jk zm4q_x5=F}n$m(@Tr+rPZJReUv##mN4xsH>IE?JmC`RUDyfti;F8uyF(z9*yN&aiV< zw}$z{Zw}3Fgy}v|PSKcFH`1=`HLupFxg`0M^Q^D%1%GG-v#lNj6MNq=K>wJszN%ed zG~E%rES^}WUZifSp%1O-PM@fN0eBpK?CQVACI*a>ynBBtxgo-2L-zQIpRW7Qqyv88 zYUJIx0_r>LEE7>|Ht7Z~bNfl;txfjjYDQ1QsoiUh>r2xfrFQQoHrnSbO#Rrbr~x|R zS8nzj*$T<5I&NpbZ{Z0O;|~VMBeX>ZIhaZfkwD0544fuu0kXmLYUlThrd&Tm5u(>~`6>UUHr?mo;iuo;kxcxt^9f1xzC<*{81 zSc~6!HjGkFD7Wn`!$w(+dzC4kJjnFZj!`e_4 zc*K`b8lKNhoL`y{{Xgw8DA<*M^Z8?tA%zp0F;6INgp}6J;5ak1TUF!G!Ln2=_ zbqJ4=tLaR}t-a4DXjZNze;S~6rPd;TpN*|)N~!6{aL--aT0NA_Ff&@>VehMtDRp-K z6rC>t;Fb&Xf-g~yoJn7($rPJR?W>49x29d)C9j@kI=-u+_lO{1_4t?HNGtI9GK_0Q z&Rxf;;QffFTKPcwT72&I)y7`hnw`tF;e$O}wP(9Ujh+-y&;i~LcrpF-y#+idu+_XKt zJ}kKoZxbo|Mt^=hcdv~{kj%2h%(_?{U*_|q$ctQ7O3Y|3zoB>9-BF!y-ySZFYrN>{ zJ`vEPnZFj13;Oxtl#kWt^HE>jXFAVA1}SS9gA1vdN>_5~9PN&*!e5rxtxY*;PjMUA zHRSm={d)Ze*Y>2sPZZZ)C2_B7>Uvfsutqa&jN%sVnWYGA@_YwPY}gDn-xK)q57QQv zb77YpR#reOJMy=`(A{7A9{qlplArnp-yIjP4XRCu0fu2q5)R4mbduDPoOqCQR_kke zo2VwwhHP?1^ABbbmnd3?=EcR4lFwb5J)w?X^(Uk=bgQOVk$L8gU)CDdG=^^Otd}%< zc5Es5?1o!q?I!LIZBkYQY(9s2FM8L2(Uip{mSo68DXc+nZ9Ic4Tsw@zZeLvX>JVcXf3YbA^f#9IeD5 za5!9CLQ-5(Qj{VgN_4YxLXt%7i2Q#e+`>skl&-|8nF1lqTxB*<-{XV2A`~M-)cI z1!L#L|F=3C^^dN-v!m_r0MICLj4cLF5hGHpLH;pyQt0@P^hv;0SiJpj4GOdWNI79G z|3l0F@aN>tZ}@?|(@C9p{N4g$%h{1eEiMKkBy-;1i>AXaWk0miyhrSV*DZ zmNIBjOBpCiR0;x@6-7d%k)krvma;H390`$uL;l85w<9_s?NFE#915}+mI5LpiAG7n zAy82$T#BM^0h1JkVI*WlEirH@2pWyDl$J*St*_;XrDPn^_P_gcf`g{uNJz@aNXVe1 zM5Uon2nELyB?^a0AVn=LBqSx^NNE`v85EcgjgnI(IO36%M~1~CtuW%Q7z=wa-wCyH zO838;D72^PxACn-qo-~ z%5As5GG7Pd@K?(g%lA9) -b 115200 - -Replace :code:`` with the port where the nRF9131 EK -can be found. For example, under Linux, :code:`/dev/ttyACM0`. - -Then build and flash the application in the usual way. - -.. zephyr-app-commands:: - :zephyr-app: samples/hello_world - :board: nrf9131ek_nrf9131 - :goals: build flash - -Debugging -========= - -Refer to the :ref:`nordic_segger` page to learn about debugging Nordic boards with a -Segger IC. - - -Testing the LEDs and buttons in the nRF9131 EK -********************************************** - -There are 2 samples that allow you to test that the button and LED on -the board are working properly with Zephyr: - -* :zephyr:code-sample:`blinky` -* :zephyr:code-sample:`button` - -You can build and flash the examples to make sure Zephyr is running correctly on -your board. The button and LED definitions can be found in -:zephyr_file:`boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi`. - -References -********** - -.. target-notes:: - -.. _IDAU: - https://developer.arm.com/docs/100690/latest/attribution-units-sau-and-idau -.. _Nordic Semiconductor Infocenter: https://infocenter.nordicsemi.com -.. _Trusted Firmware M: https://www.trustedfirmware.org/projects/tf-m/ diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi index 2c3b8481d2a..35314cd0784 100644 --- a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi +++ b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi @@ -20,7 +20,7 @@ compatible = "gpio-leds"; led0: led_0 { gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; - label = "Red LED 1"; + label = "Green LED 1"; }; led1: led_1 { gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; @@ -28,7 +28,7 @@ }; led2: led_2 { gpios = <&gpio0 31 GPIO_ACTIVE_HIGH>; - label = "Blue LED 3"; + label = "Green LED 3"; }; }; From 87123959f5f1fcb3fe6043a2bdbd02634b27287c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:27 +0000 Subject: [PATCH 0551/1623] Revert "[nrf noup] boards: arm: nrf9131ek: enable tfm" This reverts commit 6755c4785640afb19f4973563f9737eece9f57c4. Signed-off-by: Dominik Ermel --- boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig b/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig index 378a58fb6e3..0ece4f9a2ac 100644 --- a/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig +++ b/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig @@ -8,22 +8,6 @@ if BOARD_NRF9131EK_NRF9131 || BOARD_NRF9131EK_NRF9131_NS config BOARD default "nrf9131ek_nrf9131" - -# By default, if we build for a Non-Secure version of the board, -# enable building with TF-M as the Secure Execution Environment. -config BUILD_WITH_TFM - default y if BOARD_NRF9131EK_NRF9131_NS - -if BUILD_WITH_TFM - -# By default, if we build with TF-M, instruct build system to -# flash the combined TF-M (Secure) & Zephyr (Non Secure) image -config TFM_FLASH_MERGED_BINARY - bool - default y - -endif # BUILD_WITH_TFM - # For the secure version of the board the firmware is linked at the beginning # of the flash, or into the code-partition defined in DT if it is intended to # be loaded by MCUboot. If the secure firmware is to be combined with a non- From 7bc05f3332b557cf89421c203f4d45d110fa713f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:27 +0000 Subject: [PATCH 0552/1623] Revert "[nrf fromtree] boards: arm: add nrf9131ek_nrf9131" This reverts commit e40ab3aeae65a78c7371113cfcb3bcf2d68d1845. Signed-off-by: Dominik Ermel --- boards/arm/nrf9131ek_nrf9131/Kconfig.board | 14 -- .../arm/nrf9131ek_nrf9131/Kconfig.defconfig | 38 --- boards/arm/nrf9131ek_nrf9131/board.cmake | 14 -- .../nrf9131ek_nrf9131/nrf9131ek_nrf9131.dts | 19 -- .../nrf9131ek_nrf9131/nrf9131ek_nrf9131.yaml | 17 -- .../nrf9131ek_nrf9131_common-pinctrl.dtsi | 100 -------- .../nrf9131ek_nrf9131_common.dtsi | 227 ------------------ .../nrf9131ek_nrf9131_defconfig | 26 -- .../nrf9131ek_nrf9131_ns.dts | 22 -- .../nrf9131ek_nrf9131_ns.yaml | 15 -- .../nrf9131ek_nrf9131_ns_defconfig | 35 --- .../nrf9131ek_nrf9131_partition_conf.dtsi | 60 ----- .../arm/nrf9131ek_nrf9131/pre_dt_board.cmake | 7 - tests/lib/devicetree/devices/testcase.yaml | 2 - 14 files changed, 596 deletions(-) delete mode 100644 boards/arm/nrf9131ek_nrf9131/Kconfig.board delete mode 100644 boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig delete mode 100644 boards/arm/nrf9131ek_nrf9131/board.cmake delete mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.dts delete mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.yaml delete mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common-pinctrl.dtsi delete mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi delete mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_defconfig delete mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.dts delete mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.yaml delete mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns_defconfig delete mode 100644 boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_partition_conf.dtsi delete mode 100644 boards/arm/nrf9131ek_nrf9131/pre_dt_board.cmake diff --git a/boards/arm/nrf9131ek_nrf9131/Kconfig.board b/boards/arm/nrf9131ek_nrf9131/Kconfig.board deleted file mode 100644 index 4a237e3fb61..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/Kconfig.board +++ /dev/null @@ -1,14 +0,0 @@ -# nRF9131-EK board configuration - -# Copyright (c) 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -if SOC_NRF9131_LACA - -config BOARD_NRF9131EK_NRF9131 - bool "nRF9131 EK NRF9131" - -config BOARD_NRF9131EK_NRF9131_NS - bool "nRF9131 EK NRF9131 non-secure" - -endif # SOC_NRF9131_LACA diff --git a/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig b/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig deleted file mode 100644 index 0ece4f9a2ac..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig +++ /dev/null @@ -1,38 +0,0 @@ -# nRF9131 EK NRF9131 board configuration - -# Copyright (c) 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -if BOARD_NRF9131EK_NRF9131 || BOARD_NRF9131EK_NRF9131_NS - -config BOARD - default "nrf9131ek_nrf9131" - -# For the secure version of the board the firmware is linked at the beginning -# of the flash, or into the code-partition defined in DT if it is intended to -# be loaded by MCUboot. If the secure firmware is to be combined with a non- -# secure image (TRUSTED_EXECUTION_SECURE=y), the secure FW image shall always -# be restricted to the size of its code partition. -# For the non-secure version of the board, the firmware -# must be linked into the code-partition (non-secure) defined in DT, regardless. -# Apply this configuration below by setting the Kconfig symbols used by -# the linker according to the information extracted from DT partitions. - -# Workaround for not being able to have commas in macro arguments -DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition - -config FLASH_LOAD_SIZE - default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) - depends on BOARD_NRF9131EK_NRF9131 && TRUSTED_EXECUTION_SECURE - -if BOARD_NRF9131EK_NRF9131_NS - -config FLASH_LOAD_OFFSET - default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) - -config FLASH_LOAD_SIZE - default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) - -endif # BOARD_NRF9131EK_NRF9131_NS - -endif # BOARD_NRF9131EK_NRF9131 || BOARD_NRF9131EK_NRF9131_NS diff --git a/boards/arm/nrf9131ek_nrf9131/board.cmake b/boards/arm/nrf9131ek_nrf9131/board.cmake deleted file mode 100644 index 8293a428b40..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/board.cmake +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -if(CONFIG_BOARD_NRF9131EK_NRF9131_NS) - set(TFM_PUBLIC_KEY_FORMAT "full") -endif() - -if(CONFIG_TFM_FLASH_MERGED_BINARY) - set_property(TARGET runners_yaml_props_target PROPERTY hex_file tfm_merged.hex) -endif() - -# TODO: change to nRF9131_xxAA when such device is available in JLink -board_runner_args(jlink "--device=nRF9160_xxAA" "--speed=4000") -include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) -include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.dts b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.dts deleted file mode 100644 index 4b66e5348a0..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.dts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/dts-v1/; -#include -#include "nrf9131ek_nrf9131_common.dtsi" - -/ { - chosen { - zephyr,sram = &sram0_s; - zephyr,flash = &flash0; - zephyr,code-partition = &slot0_partition; - zephyr,sram-secure-partition = &sram0_s; - zephyr,sram-non-secure-partition = &sram0_ns; - }; -}; diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.yaml b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.yaml deleted file mode 100644 index d1b04054ce8..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131.yaml +++ /dev/null @@ -1,17 +0,0 @@ -identifier: nrf9131ek_nrf9131 -name: nRF9131-EK-NRF9131 -type: mcu -arch: arm -toolchain: - - gnuarmemb - - xtools - - zephyr -ram: 88 -flash: 1024 -supported: - - gpio - - i2c - - pwm - - spi - - watchdog - - counter diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common-pinctrl.dtsi b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common-pinctrl.dtsi deleted file mode 100644 index 419e7c8d70c..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common-pinctrl.dtsi +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor - * SPDX-License-Identifier: Apache-2.0 - */ - -&pinctrl { - uart0_default: uart0_default { - group1 { - psels = , - ; - }; - group2 { - psels = , - ; - bias-pull-up; - }; - }; - - uart0_sleep: uart0_sleep { - group1 { - psels = , - , - , - ; - low-power-enable; - }; - }; - - uart1_default: uart1_default { - group1 { - psels = , - ; - }; - group2 { - psels = , - ; - bias-pull-up; - }; - }; - - uart1_sleep: uart1_sleep { - group1 { - psels = , - , - , - ; - low-power-enable; - }; - }; - - i2c2_default: i2c2_default { - group1 { - psels = , - ; - }; - }; - - i2c2_sleep: i2c2_sleep { - group1 { - psels = , - ; - low-power-enable; - }; - }; - - pwm0_default: pwm0_default { - group1 { - psels = , - , - ; - }; - }; - - pwm0_sleep: pwm0_sleep { - group1 { - psels = , - , - ; - low-power-enable; - }; - }; - - spi3_default: spi3_default { - group1 { - psels = , - , - ; - nordic,drive-mode = ; - }; - }; - - spi3_sleep: spi3_sleep { - group1 { - psels = , - , - ; - low-power-enable; - }; - }; -}; diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi deleted file mode 100644 index 35314cd0784..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_common.dtsi +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "nrf9131ek_nrf9131_common-pinctrl.dtsi" -#include - -/ { - model = "Nordic nRF9131 EK NRF9131"; - compatible = "nordic,nrf9131-ek-nrf9131"; - - chosen { - zephyr,console = &uart0; - zephyr,shell-uart = &uart0; - zephyr,uart-mcumgr = &uart0; - }; - - leds { - compatible = "gpio-leds"; - led0: led_0 { - gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>; - label = "Green LED 1"; - }; - led1: led_1 { - gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>; - label = "Green LED 2"; - }; - led2: led_2 { - gpios = <&gpio0 31 GPIO_ACTIVE_HIGH>; - label = "Green LED 3"; - }; - }; - - pwmleds { - compatible = "pwm-leds"; - pwm_led0: pwm_led_0 { - pwms = <&pwm0 0 PWM_MSEC(8) PWM_POLARITY_NORMAL>; - }; - pwm_led1: pwm_led_1 { - pwms = <&pwm0 1 PWM_MSEC(8) PWM_POLARITY_NORMAL>; - }; - pwm_led2: pwm_led_2 { - pwms = <&pwm0 2 PWM_MSEC(8) PWM_POLARITY_NORMAL>; - }; - }; - - buttons { - compatible = "gpio-keys"; - button0: button_0 { - gpios = <&gpio0 28 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; - label = "Push button 1"; - zephyr,code = ; - }; - }; - - /* These aliases are provided for compatibility with samples */ - aliases { - led0 = &led0; - led1 = &led1; - led2 = &led2; - pwm-led0 = &pwm_led0; - pwm-led1 = &pwm_led1; - pwm-led2 = &pwm_led2; - sw0 = &button0; - bootloader-led0 = &led0; - mcuboot-button0 = &button0; - mcuboot-led0 = &led0; - watchdog0 = &wdt0; - spi-flash0 = &gd25wb256; - }; -}; - -&adc { - status = "okay"; -}; - -&gpiote { - status = "okay"; -}; - -&gpio0 { - status = "okay"; -}; - -&uart0 { - status = "okay"; - current-speed = <115200>; - pinctrl-0 = <&uart0_default>; - pinctrl-1 = <&uart0_sleep>; - pinctrl-names = "default", "sleep"; -}; - -&uart1 { - status = "okay"; - current-speed = <115200>; - pinctrl-0 = <&uart1_default>; - pinctrl-1 = <&uart1_sleep>; - pinctrl-names = "default", "sleep"; -}; - -&i2c2 { - compatible = "nordic,nrf-twim"; - status = "okay"; - pinctrl-0 = <&i2c2_default>; - pinctrl-1 = <&i2c2_sleep>; - pinctrl-names = "default", "sleep"; - clock-frequency = ; - - pmic_main: npm1300@6b { - compatible = "nordic,npm1300"; - reg = <0x6b>; - pmic_charger: charger { - compatible = "nordic,npm1300-charger"; - term-microvolt = <4150000>; - term-warm-microvolt = <4000000>; - current-microamp = <150000>; - dischg-limit-microamp = <1000000>; - vbus-limit-microamp = <500000>; - thermistor-ohms = <10000>; - thermistor-beta = <3380>; - charging-enable; - }; - regulators { - compatible = "nordic,npm1300-regulator"; - BUCK1 { - regulator-min-microvolt = <1800000>; - regulator-max-microvolt = <1800000>; - regulator-boot-on; - }; - BUCK2 { - regulator-min-microvolt = <1800000>; - regulator-max-microvolt = <1800000>; - regulator-boot-on; - }; - }; - }; -}; - -&pwm0 { - status = "okay"; - pinctrl-0 = <&pwm0_default>; - pinctrl-1 = <&pwm0_sleep>; - pinctrl-names = "default", "sleep"; -}; - -&spi3 { - compatible = "nordic,nrf-spim"; - status = "okay"; - cs-gpios = <&gpio0 26 GPIO_ACTIVE_LOW>; - pinctrl-0 = <&spi3_default>; - pinctrl-1 = <&spi3_sleep>; - pinctrl-names = "default", "sleep"; - - gd25wb256: gd25wb256e3ir@0 { - compatible = "jedec,spi-nor"; - status = "disabled"; - reg = <0>; - spi-max-frequency = <8000000>; - size = <268435456>; - has-dpd; - t-enter-dpd = <3000>; - t-exit-dpd = <40000>; - sfdp-bfp = [ - e5 20 f3 ff ff ff ff 0f 44 eb 08 6b 08 3b 42 bb - ee ff ff ff ff ff 00 ff ff ff 00 ff 0c 20 0f 52 - 10 d8 00 ff 44 7a c9 fe 83 67 26 62 ec 82 18 44 - 7a 75 7a 75 04 c4 d5 5c 00 06 74 00 08 50 00 01 - ]; - jedec-id = [c8 65 19]; - }; -}; - -&flash0 { - partitions { - compatible = "fixed-partitions"; - #address-cells = <1>; - #size-cells = <1>; - - boot_partition: partition@0 { - label = "mcuboot"; - reg = <0x00000000 0x10000>; - }; - slot0_partition: partition@10000 { - label = "image-0"; - }; - slot0_ns_partition: partition@50000 { - label = "image-0-nonsecure"; - }; - slot1_partition: partition@85000 { - label = "image-1"; - }; - slot1_ns_partition: partition@c5000 { - label = "image-1-nonsecure"; - }; - storage_partition: partition@fa000 { - label = "storage"; - reg = <0x000fa000 0x00006000>; - }; - }; -}; - - - -/ { - - reserved-memory { - #address-cells = <1>; - #size-cells = <1>; - ranges; - - sram0_s: image_s@20000000 { - /* Secure image memory */ - }; - - sram0_modem: image_modem@20016000 { - /* Modem (shared) memory */ - }; - - sram0_ns: image_ns@20020000 { - /* Non-Secure image memory */ - }; - }; -}; - -/* Include partition configuration file */ -#include "nrf9131ek_nrf9131_partition_conf.dtsi" diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_defconfig b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_defconfig deleted file mode 100644 index fc77ffe0d13..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_defconfig +++ /dev/null @@ -1,26 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_SOC_SERIES_NRF91X=y -CONFIG_SOC_NRF9131_LACA=y -CONFIG_BOARD_NRF9131EK_NRF9131=y - -# Enable MPU -CONFIG_ARM_MPU=y - -# Enable hardware stack protection -CONFIG_HW_STACK_PROTECTION=y - -# Enable TrustZone-M -CONFIG_ARM_TRUSTZONE_M=y - -# enable GPIO -CONFIG_GPIO=y - -# Enable uart driver -CONFIG_SERIAL=y - -# enable console -CONFIG_CONSOLE=y -CONFIG_UART_CONSOLE=y - -CONFIG_PINCTRL=y diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.dts b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.dts deleted file mode 100644 index 9a652cd0aed..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.dts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/dts-v1/; -#include -#include "nrf9131ek_nrf9131_common.dtsi" - -/ { - chosen { - zephyr,flash = &flash0; - zephyr,sram = &sram0_ns; - zephyr,code-partition = &slot0_ns_partition; - }; -}; - -/* Disable UART1, because it is used by default in TF-M */ -&uart1 { - status = "disabled"; -}; diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.yaml b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.yaml deleted file mode 100644 index cf33abd55da..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns.yaml +++ /dev/null @@ -1,15 +0,0 @@ -identifier: nrf9131ek_nrf9131_ns -name: nRF9131-EK-NRF9131-Non-Secure -type: mcu -arch: arm -toolchain: - - gnuarmemb - - xtools - - zephyr -ram: 128 -flash: 212 -supported: - - i2c - - pwm - - watchdog - - netif:modem diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns_defconfig b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns_defconfig deleted file mode 100644 index 83af1cf6b74..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_ns_defconfig +++ /dev/null @@ -1,35 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_SOC_SERIES_NRF91X=y -CONFIG_SOC_NRF9131_LACA=y -CONFIG_BOARD_NRF9131EK_NRF9131_NS=y - -# Enable MPU -CONFIG_ARM_MPU=y - -# Enable hardware stack protection -CONFIG_HW_STACK_PROTECTION=y - -# Enable TrustZone-M -CONFIG_ARM_TRUSTZONE_M=y - -# This Board implies building Non-Secure firmware -CONFIG_TRUSTED_EXECUTION_NONSECURE=y - -# enable GPIO -CONFIG_GPIO=y - -# Enable uart driver -CONFIG_SERIAL=y - -# enable console -CONFIG_CONSOLE=y -CONFIG_UART_CONSOLE=y - -CONFIG_PINCTRL=y - -# enable PMIC -CONFIG_I2C=y -CONFIG_REGULATOR=y -CONFIG_SENSOR=y -CONFIG_NPM1300_CHARGER=y diff --git a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_partition_conf.dtsi b/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_partition_conf.dtsi deleted file mode 100644 index d14d8d95f75..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/nrf9131ek_nrf9131_partition_conf.dtsi +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * Default Flash planning for nRF9131ek_nrf9131. - * - * Zephyr build for nRF9131 with ARM TrustZone-M support, - * implies building Secure and Non-Secure Zephyr images. - * - * Secure image will be placed, by default, in flash0 - * (or in slot0, if MCUboot is present). - * Secure image will use sram0 for system memory. - * - * Non-Secure image will be placed in slot0_ns, and use - * sram0_ns for system memory. - * - * Note that the Secure image only requires knowledge of - * the beginning of the Non-Secure image (not its size). - */ - -&slot0_partition { - reg = <0x00010000 0x40000>; -}; - -&slot0_ns_partition { - reg = <0x00050000 0x35000>; -}; - -&slot1_partition { - reg = <0x00085000 0x40000>; -}; - -&slot1_ns_partition { - reg = <0x000c5000 0x35000>; -}; - -/* Default SRAM planning when building for nRF9131 with - * ARM TrustZone-M support - * - Lowest 88 kB SRAM allocated to Secure image (sram0_s). - * - 40 kB SRAM reserved for and used by the modem library - * (sram0_modem). This memory is Non-Secure. - * - Upper 128 kB allocated to Non-Secure image (sram0_ns). - * When building with TF-M, both sram0_modem and sram0_ns - * are allocated to the Non-Secure image. - */ - -&sram0_s { - reg = <0x20000000 DT_SIZE_K(88)>; -}; - -&sram0_modem { - reg = <0x20016000 DT_SIZE_K(40)>; -}; - -&sram0_ns { - reg = <0x20020000 DT_SIZE_K(128)>; -}; diff --git a/boards/arm/nrf9131ek_nrf9131/pre_dt_board.cmake b/boards/arm/nrf9131ek_nrf9131/pre_dt_board.cmake deleted file mode 100644 index c8267afd1b4..00000000000 --- a/boards/arm/nrf9131ek_nrf9131/pre_dt_board.cmake +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2021 Linaro Limited -# SPDX-License-Identifier: Apache-2.0 - -# Suppress "unique_unit_address_if_enabled" to handle the following overlaps: -# - flash-controller@39000 & kmu@39000 -# - power@5000 & clock@5000 -list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") diff --git a/tests/lib/devicetree/devices/testcase.yaml b/tests/lib/devicetree/devices/testcase.yaml index 673e2319702..b57489b9a11 100644 --- a/tests/lib/devicetree/devices/testcase.yaml +++ b/tests/lib/devicetree/devices/testcase.yaml @@ -15,5 +15,3 @@ tests: - bl5340_dvk_cpuapp - bl5340_dvk_cpuapp_ns - mimxrt595_evk_cm33 - - nrf9131ek_nrf9131 - - nrf9131ek_nrf9131_ns From d962e213c7f14e9d347b49feb20229a5c4493e55 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:27 +0000 Subject: [PATCH 0553/1623] Revert "[nrf fromtree] drivers: uart: nrf: rx_timeout_slab incorrectly set" This reverts commit fda9e48e5d953cf436fa0d0d50f0df9ca0127632. Signed-off-by: Dominik Ermel --- drivers/serial/uart_nrfx_uarte.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index b70af538abf..017efa6a2e5 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -844,7 +844,15 @@ static int uarte_nrfx_rx_enable(const struct device *dev, uint8_t *buf, } data->async->rx_timeout = timeout; - data->async->rx_timeout_slab = timeout / RX_TIMEOUT_DIV; + /* Set minimum interval to 3 RTC ticks. 3 is used due to RTC limitation + * which cannot set timeout for next tick. Assuming delay in processing + * 3 instead of 2 is used. Note that lower value would work in a similar + * way but timeouts would always occur later than expected, most likely + * after ~3 ticks. + */ + data->async->rx_timeout_slab = + MAX(timeout / RX_TIMEOUT_DIV, + NRFX_CEIL_DIV(3 * 1000000, CONFIG_SYS_CLOCK_TICKS_PER_SEC)); data->async->rx_buf = buf; data->async->rx_buf_len = len; From bd13386470fa0f411292b28a1a9ad1d859860b26 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:28 +0000 Subject: [PATCH 0554/1623] Revert "[nrf fromlist] sysbuild: create sysbuild_cache function" This reverts commit c441a8dc1291faf8972964f2f944dfe2129a5ede. Signed-off-by: Dominik Ermel --- .../cmake/modules/sysbuild_extensions.cmake | 124 ++++++------------ 1 file changed, 42 insertions(+), 82 deletions(-) diff --git a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake index ac8bac25f8c..a3838415eee 100644 --- a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake +++ b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake @@ -107,87 +107,6 @@ function(sysbuild_get variable) endif() endfunction() -# Usage: -# sysbuild_cache(CREATE APPLICATION [CMAKE_RERUN]) -# -# This function works on the sysbuild cache for sysbuild managed applications. -# -# Arguments: -# CREATE : Create or update existing sysbuild cache file for the application. -# The sysbuild cache is only updated if it contain changes. -# APPLICATION : Name of the application. -# CMAKE_RERUN : Force a CMake rerun for the application during next build -# invocation if the sysbuild cache has changed. It is -# advised to always use this flag. Not using this flag can -# reduce build time, but only do so if application is -# guranteed to be up-to-date. -# -function(sysbuild_cache) - cmake_parse_arguments(SB_CACHE "CREATE;CMAKE_RERUN" "APPLICATION" "" ${ARGN}) - zephyr_check_arguments_required(sysbuild_cache SB_CACHE APPLICATION) - zephyr_check_flags_required(sysbuild_cache SB_CACHE CREATE) - - get_target_property(${SB_CACHE_APPLICATION}_MAIN_APP ${SB_CACHE_APPLICATION} MAIN_APP) - get_cmake_property(sysbuild_cache CACHE_VARIABLES) - - foreach(var_name ${sysbuild_cache}) - if(NOT "${var_name}" MATCHES "^(CMAKE_.*|BOARD)$") - # Perform a dummy read to prevent a false warning about unused variables - # being emitted due to a cmake bug: https://gitlab.kitware.com/cmake/cmake/-/issues/24555 - set(unused_tmp_var ${${var_name}}) - - # We don't want to pass internal CMake variables. - # Required CMake variable to be passed, like CMAKE_BUILD_TYPE must be - # passed using `-D` on command invocation. - get_property(var_type CACHE ${var_name} PROPERTY TYPE) - set(cache_entry "${var_name}:${var_type}=$CACHE{${var_name}}") - string(REPLACE ";" "\;" cache_entry "${cache_entry}") - list(APPEND sysbuild_cache_strings "${cache_entry}\n") - endif() - endforeach() - if(DEFINED BOARD_REVISION) - list(APPEND sysbuild_cache_strings "BOARD:STRING=${BOARD}@${BOARD_REVISION}\n") - else() - list(APPEND sysbuild_cache_strings "BOARD:STRING=${BOARD}\n") - endif() - list(APPEND sysbuild_cache_strings "SYSBUILD_NAME:STRING=${SB_CACHE_APPLICATION}\n") - - if(${SB_CACHE_APPLICATION}_MAIN_APP) - list(APPEND sysbuild_cache_strings "SYSBUILD_MAIN_APP:BOOL=True\n") - endif() - - if(${SB_CACHE_APPLICATION}_BOARD AND NOT DEFINED CACHE{${SB_CACHE_APPLICATION}_BOARD}) - # Only set image specific board if provided. - # The sysbuild BOARD is exported through sysbuild cache, and will be used - # unless _BOARD is defined. - list(APPEND sysbuild_cache_strings - "${SB_CACHE_APPLICATION}_BOARD:STRING=${${SB_CACHE_APPLICATION}_BOARD}\n" - ) - endif() - - get_target_property(${SB_CACHE_APPLICATION}_CACHE_FILE ${SB_CACHE_APPLICATION} CACHE_FILE) - file(WRITE ${${SB_CACHE_APPLICATION}_CACHE_FILE}.tmp ${sysbuild_cache_strings}) - if(SB_CACHE_CMAKE_RERUN) - execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files - ${${SB_CACHE_APPLICATION}_CACHE_FILE}.tmp - ${${SB_CACHE_APPLICATION}_CACHE_FILE} - RESULT_VARIABLE compare_res - ) - if(NOT compare_res EQUAL 0) - file(COPY_FILE ${${SB_CACHE_APPLICATION}_CACHE_FILE}.tmp - ${${SB_CACHE_APPLICATION}_CACHE_FILE} - ) - ExternalProject_Get_Property(${SB_CACHE_APPLICATION} BINARY_DIR) - file(TOUCH_NOCREATE ${BINARY_DIR}/CMakeCache.txt) - endif() - else() - zephyr_file_copy(${${SB_CACHE_APPLICATION}_CACHE_FILE}.tmp - ${${SB_CACHE_APPLICATION}_CACHE_FILE} ONLY_IF_DIFFERENT - ) - endif() - -endfunction() - # Usage: # ExternalZephyrProject_Add(APPLICATION # SOURCE_DIR @@ -453,7 +372,9 @@ function(ExternalZephyrProject_Cmake) ) ExternalProject_Get_Property(${ZCMAKE_APPLICATION} SOURCE_DIR BINARY_DIR CMAKE_ARGS) + get_target_property(${ZCMAKE_APPLICATION}_CACHE_FILE ${ZCMAKE_APPLICATION} CACHE_FILE) get_target_property(${ZCMAKE_APPLICATION}_BOARD ${ZCMAKE_APPLICATION} BOARD) + get_target_property(${ZCMAKE_APPLICATION}_MAIN_APP ${ZCMAKE_APPLICATION} MAIN_APP) get_property(${ZCMAKE_APPLICATION}_CONF_SCRIPT TARGET ${ZCMAKE_APPLICATION} PROPERTY IMAGE_CONF_SCRIPT @@ -469,7 +390,46 @@ function(ExternalZephyrProject_Cmake) endif() endforeach() - sysbuild_cache(CREATE APPLICATION ${ZCMAKE_APPLICATION}) + get_cmake_property(sysbuild_cache CACHE_VARIABLES) + foreach(var_name ${sysbuild_cache}) + if(NOT "${var_name}" MATCHES "^(CMAKE_.*|BOARD)$") + # Perform a dummy read to prevent a false warning about unused variables + # being emitted due to a cmake bug: https://gitlab.kitware.com/cmake/cmake/-/issues/24555 + set(unused_tmp_var ${${var_name}}) + + # We don't want to pass internal CMake variables. + # Required CMake variable to be passed, like CMAKE_BUILD_TYPE must be + # passed using `-D` on command invocation. + get_property(var_type CACHE ${var_name} PROPERTY TYPE) + set(cache_entry "${var_name}:${var_type}=$CACHE{${var_name}}") + string(REPLACE ";" "\;" cache_entry "${cache_entry}") + list(APPEND sysbuild_cache_strings "${cache_entry}\n") + endif() + endforeach() + if(DEFINED BOARD_REVISION) + list(APPEND sysbuild_cache_strings "BOARD:STRING=${BOARD}@${BOARD_REVISION}\n") + else() + list(APPEND sysbuild_cache_strings "BOARD:STRING=${BOARD}\n") + endif() + list(APPEND sysbuild_cache_strings "SYSBUILD_NAME:STRING=${ZCMAKE_APPLICATION}\n") + + if(${ZCMAKE_APPLICATION}_MAIN_APP) + list(APPEND sysbuild_cache_strings "SYSBUILD_MAIN_APP:BOOL=True\n") + endif() + + if(${ZCMAKE_APPLICATION}_BOARD AND NOT DEFINED CACHE{${ZCMAKE_APPLICATION}_BOARD}) + # Only set image specific board if provided. + # The sysbuild BOARD is exported through sysbuild cache, and will be used + # unless _BOARD is defined. + list(APPEND sysbuild_cache_strings + "${ZCMAKE_APPLICATION}_BOARD:STRING=${${ZCMAKE_APPLICATION}_BOARD}\n" + ) + endif() + + file(WRITE ${${ZCMAKE_APPLICATION}_CACHE_FILE}.tmp ${sysbuild_cache_strings}) + zephyr_file_copy(${${ZCMAKE_APPLICATION}_CACHE_FILE}.tmp + ${${ZCMAKE_APPLICATION}_CACHE_FILE} ONLY_IF_DIFFERENT + ) foreach(script ${${ZCMAKE_APPLICATION}_CONF_SCRIPT}) include(${script}) From e0deb72356e37b3151db12898ee69c1c401e8c06 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:28 +0000 Subject: [PATCH 0555/1623] Revert "[nrf noup] Bluetooth: Mesh: adapt SDC specific api usage" This reverts commit 533baa16b5a6750cf59a7ce7257bc09bcac09637. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/adv_ext.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index fe9fc4fd403..525e5ee5066 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -529,8 +529,8 @@ int bt_mesh_adv_enable(void) if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE) && IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - advs[i].tags == BT_MESH_ADV_TAG_BIT_FRIEND) { - err = set_adv_randomness(advs[i].instance->handle, 0); + adv->tag == BT_MESH_FRIEND_ADV) { + err = set_adv_randomness(adv->instance->handle, 0); if (err) { LOG_ERR("Failed to set zero randomness: %d", err); } From c469abe57050c3322acbe5fb65fb7be8bf1b8019 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:28 +0000 Subject: [PATCH 0556/1623] Revert "[nrf fromlist] Bluetooth: Mesh: no more tinycrypt in ble mesh tfm image" This reverts commit d466b521fbbdf602a32d92c8ff9f9371e624fa51. Signed-off-by: Dominik Ermel --- .../boards/nrf5340dk_nrf5340_cpuapp_ns.conf | 5 --- .../boards/nrf5340dk_nrf5340_cpuapp_ns.conf | 5 --- .../boards/nrf5340dk_nrf5340_cpuapp_ns.conf | 3 -- subsys/bluetooth/host/Kconfig | 7 ++-- subsys/bluetooth/mesh/crypto_psa.c | 10 ------ tests/bsim/bluetooth/mesh/overlay_psa.conf | 5 --- tests/bsim/bluetooth/mesh/src/test_dfu.c | 35 +++++++++---------- .../bluetooth/mesh/src/test_persistence.c | 2 +- .../bluetooth/mesh/src/test_replay_cache.c | 8 ----- 9 files changed, 21 insertions(+), 59 deletions(-) diff --git a/samples/bluetooth/mesh/boards/nrf5340dk_nrf5340_cpuapp_ns.conf b/samples/bluetooth/mesh/boards/nrf5340dk_nrf5340_cpuapp_ns.conf index 4693e4d1f78..c638a292c91 100644 --- a/samples/bluetooth/mesh/boards/nrf5340dk_nrf5340_cpuapp_ns.conf +++ b/samples/bluetooth/mesh/boards/nrf5340dk_nrf5340_cpuapp_ns.conf @@ -1,8 +1,3 @@ -# The option adds TinyCrypt based bt_rand. -CONFIG_BT_HOST_CRYPTO=n -# The option adds GATT caching feature that is based on TinyCrypt. -CONFIG_BT_GATT_CACHING=n - # Known issue: non secure platforms do not work with settings subsystem. CONFIG_SETTINGS=n CONFIG_BT_SETTINGS=n diff --git a/samples/bluetooth/mesh_demo/boards/nrf5340dk_nrf5340_cpuapp_ns.conf b/samples/bluetooth/mesh_demo/boards/nrf5340dk_nrf5340_cpuapp_ns.conf index 4693e4d1f78..c638a292c91 100644 --- a/samples/bluetooth/mesh_demo/boards/nrf5340dk_nrf5340_cpuapp_ns.conf +++ b/samples/bluetooth/mesh_demo/boards/nrf5340dk_nrf5340_cpuapp_ns.conf @@ -1,8 +1,3 @@ -# The option adds TinyCrypt based bt_rand. -CONFIG_BT_HOST_CRYPTO=n -# The option adds GATT caching feature that is based on TinyCrypt. -CONFIG_BT_GATT_CACHING=n - # Known issue: non secure platforms do not work with settings subsystem. CONFIG_SETTINGS=n CONFIG_BT_SETTINGS=n diff --git a/samples/bluetooth/mesh_provisioner/boards/nrf5340dk_nrf5340_cpuapp_ns.conf b/samples/bluetooth/mesh_provisioner/boards/nrf5340dk_nrf5340_cpuapp_ns.conf index c3d134592fc..c638a292c91 100644 --- a/samples/bluetooth/mesh_provisioner/boards/nrf5340dk_nrf5340_cpuapp_ns.conf +++ b/samples/bluetooth/mesh_provisioner/boards/nrf5340dk_nrf5340_cpuapp_ns.conf @@ -1,6 +1,3 @@ -# The option adds TinyCrypt based bt_rand. -CONFIG_BT_HOST_CRYPTO=n - # Known issue: non secure platforms do not work with settings subsystem. CONFIG_SETTINGS=n CONFIG_BT_SETTINGS=n diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 2e740686b69..a4cf2e0959b 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -163,13 +163,12 @@ rsource "../mesh/Kconfig" rsource "../audio/Kconfig" config BT_HOST_CRYPTO - bool "Use crypto functionality implemented in the Bluetooth host" + # Hidden option that compiles in AES encryption support using TinyCrypt + # library if this is not provided by the controller implementation. + bool default y if !BT_CTLR_CRYPTO select TINYCRYPT select TINYCRYPT_AES - help - The option adds the AES encryption support using TinyCrypt - library if this is not provided by the controller implementation. config BT_HOST_CRYPTO_PRNG bool "Use Tinycrypt library for random number generation" diff --git a/subsys/bluetooth/mesh/crypto_psa.c b/subsys/bluetooth/mesh/crypto_psa.c index 587c367a6bd..450cde679a8 100644 --- a/subsys/bluetooth/mesh/crypto_psa.c +++ b/subsys/bluetooth/mesh/crypto_psa.c @@ -7,7 +7,6 @@ #include #include -#include #define LOG_LEVEL CONFIG_BT_MESH_CRYPTO_LOG_LEVEL #include @@ -511,12 +510,3 @@ int bt_mesh_key_compare(const uint8_t raw_key[16], const struct bt_mesh_key *key return memcmp(out, raw_key, 16); } - -__weak int bt_rand(void *buf, size_t len) -{ - CHECKIF(buf == NULL || len == 0) { - return -EINVAL; - } - - return psa_generate_random(buf, len) == PSA_SUCCESS ? 0 : -EIO; -} diff --git a/tests/bsim/bluetooth/mesh/overlay_psa.conf b/tests/bsim/bluetooth/mesh/overlay_psa.conf index 1957085b7e4..ba81c1e0213 100644 --- a/tests/bsim/bluetooth/mesh/overlay_psa.conf +++ b/tests/bsim/bluetooth/mesh/overlay_psa.conf @@ -1,7 +1,2 @@ -# The option adds TinyCrypt based bt_rand. -CONFIG_BT_HOST_CRYPTO=n -# The option adds GATT caching feature that is based on TinyCrypt. -CONFIG_BT_GATT_CACHING=n - # Enable mbedTLS PSA as a crypto backend CONFIG_BT_MESH_USES_MBEDTLS_PSA=y diff --git a/tests/bsim/bluetooth/mesh/src/test_dfu.c b/tests/bsim/bluetooth/mesh/src/test_dfu.c index 46ad4cecb41..a235e86eeec 100644 --- a/tests/bsim/bluetooth/mesh/src/test_dfu.c +++ b/tests/bsim/bluetooth/mesh/src/test_dfu.c @@ -23,7 +23,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); #define TARGET_ADDR 0x0100 #define IMPOSTER_MODEL_ID 0xe000 #define TEST_BLOB_ID 0xaabbccdd -#define SEMAPHORE_TIMEOUT 250 /* seconds */ struct bind_params { uint16_t model_id; @@ -1017,7 +1016,7 @@ static void test_cli_fail_on_persistency(void) FAIL("DFU Client send failed (err: %d)", err); } - if (k_sem_take(&dfu_ended, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_ended, K_SECONDS(200))) { FAIL("Firmware transfer failed"); } @@ -1051,7 +1050,7 @@ static void test_cli_fail_on_persistency(void) FAIL("DFU Client apply failed (err: %d)", err); } - if (k_sem_take(&dfu_cli_applied_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_cli_applied_sem, K_SECONDS(200))) { FAIL("Failed to apply firmware"); } @@ -1064,7 +1063,7 @@ static void test_cli_fail_on_persistency(void) FAIL("DFU Client confirm failed (err: %d)", err); } - if (k_sem_take(&dfu_cli_confirmed_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_cli_confirmed_sem, K_SECONDS(200))) { FAIL("Failed to confirm firmware"); } @@ -1097,7 +1096,7 @@ static void test_cli_all_targets_lost_common(void) FAIL("DFU Client send failed (err: %d)", err); } - if (k_sem_take(&dfu_ended, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_ended, K_SECONDS(200))) { FAIL("Firmware transfer failed"); } } @@ -1188,7 +1187,7 @@ static void test_cli_all_targets_lost_on_apply(void) FAIL("DFU Client apply failed (err: %d)", err); } - if (!k_sem_take(&dfu_cli_applied_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (!k_sem_take(&dfu_cli_applied_sem, K_SECONDS(200))) { FAIL("Apply should not be successful on any target"); } @@ -1219,7 +1218,7 @@ static void test_cli_stop(void) FAIL("DFU Client send failed (err: %d)", err); } - if (k_sem_take(&dfu_started, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_started, K_SECONDS(200))) { FAIL("Firmware transfer failed"); } @@ -1235,7 +1234,7 @@ static void test_cli_stop(void) FAIL("DFU Client resume failed (err: %d)", err); } - if (k_sem_take(&dfu_verifying, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_verifying, K_SECONDS(200))) { FAIL("Firmware transfer failed"); } ASSERT_EQUAL(BT_MESH_DFU_ERR_INTERNAL, dfu_cli_xfer.targets[0].status); @@ -1254,7 +1253,7 @@ static void test_cli_stop(void) FAIL("DFU Client send failed (err: %d)", err); } - if (k_sem_take(&dfu_verify_failed, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_verify_failed, K_SECONDS(200))) { FAIL("Firmware transfer failed"); } @@ -1270,12 +1269,12 @@ static void test_cli_stop(void) if (err) { FAIL("DFU Client send failed (err: %d)", err); } - if (k_sem_take(&dfu_ended, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_ended, K_SECONDS(200))) { FAIL("Firmware transfer failed"); } bt_mesh_dfu_cli_apply(&dfu_cli); - if (k_sem_take(&dfu_cli_applied_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_cli_applied_sem, K_SECONDS(200))) { /* This will time out as target will reboot before applying */ } ASSERT_EQUAL(BT_MESH_DFU_ERR_INTERNAL, dfu_cli_xfer.targets[0].status); @@ -1465,7 +1464,7 @@ static void test_target_fail_on_metadata(void) common_fail_on_target_init(&target_comp); target_prov_and_conf_default(); - if (k_sem_take(&dfu_metadata_check_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_metadata_check_sem, K_SECONDS(200))) { FAIL("Metadata check CB wasn't called"); } @@ -1479,7 +1478,7 @@ static void test_target_fail_on_caps_get(void) common_fail_on_target_init(&srv_caps_broken_comp); target_prov_and_conf_with_imposer(); - if (k_sem_take(&caps_get_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&caps_get_sem, K_SECONDS(200))) { FAIL("BLOB Info Get msg handler wasn't called"); } @@ -1493,11 +1492,11 @@ static void test_target_fail_on_update_get(void) common_fail_on_target_init(&srv_update_get_broken_comp); target_prov_and_conf_with_imposer(); - if (k_sem_take(&dfu_verify_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_verify_sem, K_SECONDS(200))) { FAIL("Transfer end CB wasn't triggered"); } - if (k_sem_take(&update_get_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&update_get_sem, K_SECONDS(200))) { FAIL("Firmware Update Get msg handler wasn't called"); } @@ -1512,7 +1511,7 @@ static void test_target_fail_on_verify(void) common_fail_on_target_init(&target_comp); target_prov_and_conf_default(); - if (k_sem_take(&dfu_verify_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_verify_sem, K_SECONDS(200))) { FAIL("Transfer end CB wasn't triggered"); } @@ -1526,7 +1525,7 @@ static void test_target_fail_on_apply(void) common_fail_on_target_init(&srv_update_apply_broken_comp); target_prov_and_conf_with_imposer(); - if (k_sem_take(&update_apply_sem, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&update_apply_sem, K_SECONDS(200))) { FAIL("Firmware Update Apply msg handler wasn't called"); } @@ -1538,7 +1537,7 @@ static void test_target_fail_on_nothing(void) common_fail_on_target_init(&target_comp); target_prov_and_conf_default(); - if (k_sem_take(&dfu_ended, K_SECONDS(SEMAPHORE_TIMEOUT))) { + if (k_sem_take(&dfu_ended, K_SECONDS(200))) { FAIL("DFU failed"); } diff --git a/tests/bsim/bluetooth/mesh/src/test_persistence.c b/tests/bsim/bluetooth/mesh/src/test_persistence.c index aab9c6dd185..90bf41f73a6 100644 --- a/tests/bsim/bluetooth/mesh/src/test_persistence.c +++ b/tests/bsim/bluetooth/mesh/src/test_persistence.c @@ -525,7 +525,7 @@ static void node_configure(void) */ uint8_t net_transmit; - net_transmit = BT_MESH_TRANSMIT(3, 50); + net_transmit = BT_MESH_TRANSMIT(3, 20); err = bt_mesh_cfg_cli_net_transmit_set(test_netkey_idx, TEST_ADDR, net_transmit, &status); if (err || status != net_transmit) { FAIL("Net transmit set failed (err %d, transmit %x)", err, status); diff --git a/tests/bsim/bluetooth/mesh/src/test_replay_cache.c b/tests/bsim/bluetooth/mesh/src/test_replay_cache.c index d7c140ab3ed..dbab05661cb 100644 --- a/tests/bsim/bluetooth/mesh/src/test_replay_cache.c +++ b/tests/bsim/bluetooth/mesh/src/test_replay_cache.c @@ -149,8 +149,6 @@ static void test_tx_immediate_replay_attack(void) } ASSERT_TRUE(is_tx_succeeded); - /* Let complete advertising of the previous transaction to prevent collisions. */ - k_sleep(K_SECONDS(1)); } bt_mesh.seq = seq; @@ -167,8 +165,6 @@ static void test_tx_immediate_replay_attack(void) } ASSERT_TRUE(!is_tx_succeeded); - /* Let complete advertising of the previous transaction to prevent collisions. */ - k_sleep(K_SECONDS(1)); } PASS(); @@ -212,8 +208,6 @@ static void test_tx_power_replay_attack(void) } ASSERT_TRUE(!is_tx_succeeded); - /* Let complete advertising of the previous transaction to prevent collisions. */ - k_sleep(K_SECONDS(1)); } for (int i = 0; i < 3; i++) { @@ -228,8 +222,6 @@ static void test_tx_power_replay_attack(void) } ASSERT_TRUE(is_tx_succeeded); - /* Let complete advertising of the previous transaction to prevent collisions. */ - k_sleep(K_SECONDS(1)); } PASS(); From 97f9037e31145ffbb7ef357e34e79355fb4e7ba0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:28 +0000 Subject: [PATCH 0557/1623] Revert "[nrf fromlist] bsim: bluetooth: mesh: Increase Net Transmit Count value on the node" This reverts commit 6dde66941e658d5a73420e49ac96113c457ce072. Signed-off-by: Dominik Ermel --- tests/bsim/bluetooth/mesh/src/test_persistence.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/bsim/bluetooth/mesh/src/test_persistence.c b/tests/bsim/bluetooth/mesh/src/test_persistence.c index 90bf41f73a6..6c510922330 100644 --- a/tests/bsim/bluetooth/mesh/src/test_persistence.c +++ b/tests/bsim/bluetooth/mesh/src/test_persistence.c @@ -520,17 +520,6 @@ static void node_configure(void) uint16_t va; struct bt_mesh_cfg_cli_mod_pub pub_params; - /* Set Network Transmit Count state on the device greater than on provisioner to increase - * probability of reception responses. - */ - uint8_t net_transmit; - - net_transmit = BT_MESH_TRANSMIT(3, 20); - err = bt_mesh_cfg_cli_net_transmit_set(test_netkey_idx, TEST_ADDR, net_transmit, &status); - if (err || status != net_transmit) { - FAIL("Net transmit set failed (err %d, transmit %x)", err, status); - } - struct test_appkey_t test_appkeys[] = { { .idx = TEST_APPKEY_0_IDX, .key = TEST_APPKEY_0_KEY }, { .idx = TEST_APPKEY_1_IDX, .key = TEST_APPKEY_1_KEY }, From ddc4d2416e86cb54ff717e904a4d4980c3b4a6eb Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:29 +0000 Subject: [PATCH 0558/1623] Revert "[nrf fromlist] Bluetooth: Mesh: Move ext adv sector to vector" This reverts commit 9c6d0f8a0bdca74bee70bea3746db945ac9d314a. Signed-off-by: Dominik Ermel --- cmake/linker_script/common/common-ram.cmake | 3 + include/zephyr/linker/common-ram.ld | 4 + subsys/bluetooth/mesh/Kconfig | 38 ++--- subsys/bluetooth/mesh/adv.c | 41 +++-- subsys/bluetooth/mesh/adv.h | 18 +-- subsys/bluetooth/mesh/adv_ext.c | 151 +++++++++--------- subsys/bluetooth/mesh/adv_legacy.c | 5 +- subsys/bluetooth/mesh/provisioner.c | 2 + tests/bluetooth/mesh/basic/multi_ext_adv.conf | 2 +- .../bsim/bluetooth/mesh/src/test_advertiser.c | 2 +- 10 files changed, 137 insertions(+), 129 deletions(-) diff --git a/cmake/linker_script/common/common-ram.cmake b/cmake/linker_script/common/common-ram.cmake index 9c051477d10..e6ef59eaf29 100644 --- a/cmake/linker_script/common/common-ram.cmake +++ b/cmake/linker_script/common/common-ram.cmake @@ -111,6 +111,9 @@ if(CONFIG_UVB) zephyr_iterable_section(NAME uvb_node GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) endif() +if(CONFIG_BT_MESH_ADV_EXT) + zephyr_iterable_section(NAME bt_mesh_ext_adv GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +endif() if(CONFIG_LOG) zephyr_iterable_section(NAME log_mpsc_pbuf GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) diff --git a/include/zephyr/linker/common-ram.ld b/include/zephyr/linker/common-ram.ld index 8ae67c73257..bfaa26ed400 100644 --- a/include/zephyr/linker/common-ram.ld +++ b/include/zephyr/linker/common-ram.ld @@ -12,6 +12,10 @@ #endif #endif /* NETWORKING */ +#if defined(CONFIG_BT_MESH) + ITERABLE_SECTION_RAM(bt_mesh_ext_adv, 4) +#endif + #if defined(CONFIG_GEN_SW_ISR_TABLE) && defined(CONFIG_DYNAMIC_INTERRUPTS) SECTION_DATA_PROLOGUE(sw_isr_table,,) { diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 63749a69d56..cb04b4dedfb 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -103,22 +103,22 @@ menuconfig BT_MESH_ADV_EXT if BT_MESH_ADV_EXT -config BT_MESH_RELAY_ADV_SETS - int "Maximum of simultaneous relay message support" +config BT_MESH_SIMULT_ADV_SETS + int "Maximum number of parallel advertising sets that can be used by the Bluetooth Mesh stack" default 0 range 0 BT_EXT_ADV_MAX_ADV_SET - depends on BT_MESH_RELAY + depends on BT_MESH_RELAY || BT_MESH_PB_ADV help - Maximum of simultaneous relay message support. Requires controller support + Maximum of simultaneous message support. Requires controller support multiple advertising sets. config BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET bool "Use the main advertising set to relay messages" - depends on BT_MESH_RELAY_ADV_SETS > 0 + depends on BT_MESH_SIMULT_ADV_SETS > 0 help When this option is enabled, there is a message that needs to be relayed, all relay advertising sets defined by - CONFIG_BT_MESH_RELAY_ADV_SETS are busy with relaying messages + CONFIG_BT_MESH_SIMULT_ADV_SETS are busy with relaying messages and the main advertising set is not busy with sending local messages, the stack will use the main advertising set to relay the message. This maximizes the utilization efficiency of @@ -192,15 +192,16 @@ config BT_MESH_UNPROV_BEACON_INT if BT_MESH_PB_ADV -config BT_MESH_PB_ADV_USE_RELAY_SETS - bool "Use relay advertising sets to send provisioning PDUs" - depends on BT_MESH_RELAY_ADV_SETS > 0 +config BT_MESH_PB_ADV_RETRANS_TIMEOUT + int "Timeout value of retransmit provisioning PDUs" + default 500 + range 100 800 help - Use relay advertising sets to send provisioning PDUs + Timeout value of retransmit provisioning PDUs. config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT int "Link Open and Transaction PDU retransmit count" - default 7 if BT_MESH_PB_ADV_USE_RELAY_SETS + default 7 if BT_MESH_SIMULT_ADV_SETS > 0 default 0 range 0 7 help @@ -209,28 +210,21 @@ config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT config BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT int "Link Ack and Transaction Ack retransmit count" - default 2 + default 0 range 0 7 help - Controls the number of retransmissions of original Link Ack and Transaction Acknowledgment PDU, + Controls the number of retransmissions of original Link Open and Transaction Acknowledgment PDU, in addition to the first transmission. config BT_MESH_PB_ADV_LINK_CLOSE_RETRANSMIT_COUNT int "Link Close retransmit count" - default 7 if BT_MESH_PB_ADV_USE_RELAY_SETS + default 7 if BT_MESH_SIMULT_ADV_SETS > 0 default 2 range 0 7 help Controls the number of retransmissions of original Link Close, in addition to the first transmission. -config BT_MESH_PB_ADV_RETRANS_TIMEOUT - int "Timeout value of retransmit provisioning PDUs" - default 500 - range 100 800 - help - Timeout value of retransmit provisioning PDUs. - endif # BT_MESH_PB_ADV if BT_CONN @@ -407,7 +401,7 @@ config BT_MESH_RELAY_BUF_COUNT of packet drops. When considering the message latency, also consider the values of BT_MESH_RELAY_RETRANSMIT_COUNT and BT_MESH_RELAY_RETRANSMIT_INTERVAL. A higher number of - BT_MESH_RELAY_ADV_SETS allows the increase in the number of buffers + BT_MESH_SIMULT_ADV_SETS allows the increase in the number of buffers while maintaining the latency. endif # BT_MESH_RELAY diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index b24523aacf3..c7abcd53d70 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -44,7 +44,7 @@ const uint8_t bt_mesh_adv_type[BT_MESH_ADV_TYPES] = { static bool active_scanning; static K_FIFO_DEFINE(bt_mesh_adv_queue); -static K_FIFO_DEFINE(bt_mesh_relay_queue); +static K_FIFO_DEFINE(bt_mesh_simult_queue); static K_FIFO_DEFINE(bt_mesh_friend_queue); void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv *adv) @@ -157,7 +157,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, tag, xmit, timeout); } -#if CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE +#if CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE static struct net_buf *process_events(struct k_poll_event *ev, int count) { for (; count; ev++, count--) { @@ -189,7 +189,7 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, K_POLL_MODE_NOTIFY_ONLY, - &bt_mesh_relay_queue, + &bt_mesh_simult_queue, 0), #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ }; @@ -202,34 +202,34 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) return process_events(events, ARRAY_SIZE(events)); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) { if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - tags & BT_MESH_ADV_TAG_BIT_FRIEND) { + tags & BT_MESH_ADV_TAG_FRIEND_BIT) { return net_buf_get(&bt_mesh_friend_queue, timeout); } -#if CONFIG_BT_MESH_RELAY_ADV_SETS - if (!(tags & BT_MESH_ADV_TAG_BIT_LOCAL)) { - return net_buf_get(&bt_mesh_relay_queue, timeout); + if (tags & BT_MESH_ADV_TAG_LOCAL_BIT) { + return bt_mesh_adv_buf_get(timeout); } -#endif - return bt_mesh_adv_buf_get(timeout); +#if CONFIG_BT_MESH_SIMULT_ADV_SETS + return net_buf_get(&bt_mesh_simult_queue, timeout); +#endif } -#else /* !(CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) */ +#else /* !(CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) */ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) { return net_buf_get(&bt_mesh_adv_queue, timeout); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) { ARG_UNUSED(tags); return bt_mesh_adv_buf_get(timeout); } -#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ +#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ void bt_mesh_adv_buf_get_cancel(void) { @@ -237,9 +237,9 @@ void bt_mesh_adv_buf_get_cancel(void) k_fifo_cancel_wait(&bt_mesh_adv_queue); -#if CONFIG_BT_MESH_RELAY_ADV_SETS - k_fifo_cancel_wait(&bt_mesh_relay_queue); -#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ +#if CONFIG_BT_MESH_SIMULT_ADV_SETS + k_fifo_cancel_wait(&bt_mesh_simult_queue); +#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { k_fifo_cancel_wait(&bt_mesh_friend_queue); @@ -267,12 +267,11 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, return; } -#if CONFIG_BT_MESH_RELAY_ADV_SETS +#if CONFIG_BT_MESH_SIMULT_ADV_SETS if (BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_RELAY || - (IS_ENABLED(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS) && - BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV)) { - net_buf_put(&bt_mesh_relay_queue, net_buf_ref(buf)); - bt_mesh_adv_buf_relay_ready(); + BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV) { + net_buf_put(&bt_mesh_simult_queue, net_buf_ref(buf)); + bt_mesh_adv_buf_simult_ready(); return; } #endif diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index a80ff7e8d4b..50c5b47604c 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -33,12 +33,12 @@ enum bt_mesh_adv_tag { BT_MESH_ADV_TAG_PROV, }; -enum bt_mesh_adv_tag_bit { - BT_MESH_ADV_TAG_BIT_LOCAL = BIT(BT_MESH_ADV_TAG_LOCAL), - BT_MESH_ADV_TAG_BIT_RELAY = BIT(BT_MESH_ADV_TAG_RELAY), - BT_MESH_ADV_TAG_BIT_PROXY = BIT(BT_MESH_ADV_TAG_PROXY), - BT_MESH_ADV_TAG_BIT_FRIEND = BIT(BT_MESH_ADV_TAG_FRIEND), - BT_MESH_ADV_TAG_BIT_PROV = BIT(BT_MESH_ADV_TAG_PROV), +enum bt_mesh_adv_tags { + BT_MESH_ADV_TAG_LOCAL_BIT = BIT(BT_MESH_ADV_TAG_LOCAL), + BT_MESH_ADV_TAG_RELAY_BIT = BIT(BT_MESH_ADV_TAG_RELAY), + BT_MESH_ADV_TAG_PROXY_BIT = BIT(BT_MESH_ADV_TAG_PROXY), + BT_MESH_ADV_TAG_FRIEND_BIT = BIT(BT_MESH_ADV_TAG_FRIEND), + BT_MESH_ADV_TAG_PROV_BIT = BIT(BT_MESH_ADV_TAG_PROV), }; struct bt_mesh_adv { @@ -66,7 +66,7 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout); -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout); +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout); void bt_mesh_adv_gatt_update(void); @@ -82,9 +82,9 @@ int bt_mesh_adv_enable(void); void bt_mesh_adv_buf_local_ready(void); -void bt_mesh_adv_buf_relay_ready(void); +void bt_mesh_adv_buf_simult_ready(void); -void bt_mesh_adv_buf_terminate(const struct net_buf *buf); +void bt_mesh_adv_buf_terminate(struct net_buf *buf); void bt_mesh_adv_buf_friend_ready(void); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 525e5ee5066..2065de372a4 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -33,8 +33,8 @@ LOG_MODULE_REGISTER(bt_mesh_adv_ext); /* Convert from ms to 0.625ms units */ #define ADV_INT_FAST_MS 20 -#ifndef CONFIG_BT_MESH_RELAY_ADV_SETS -#define CONFIG_BT_MESH_RELAY_ADV_SETS 0 +#ifndef CONFIG_BT_MESH_SIMULT_ADV_SETS +#define CONFIG_BT_MESH_SIMULT_ADV_SETS 0 #endif enum { @@ -60,7 +60,7 @@ enum { }; struct bt_mesh_ext_adv { - const enum bt_mesh_adv_tag_bit tags; + enum bt_mesh_adv_tags tags; ATOMIC_DEFINE(flags, ADV_FLAGS_NUM); struct bt_le_ext_adv *instance; struct net_buf *buf; @@ -72,71 +72,80 @@ struct bt_mesh_ext_adv { static void send_pending_adv(struct k_work *work); static bool schedule_send(struct bt_mesh_ext_adv *adv); -static struct bt_mesh_ext_adv advs[] = { - [0] = { - .tags = ( +static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { + .tags = ( #if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - BT_MESH_ADV_TAG_BIT_FRIEND | + BT_MESH_ADV_TAG_FRIEND_BIT | #endif #if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - BT_MESH_ADV_TAG_BIT_PROXY | + BT_MESH_ADV_TAG_PROXY_BIT | #endif /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) - BT_MESH_ADV_TAG_BIT_RELAY | + BT_MESH_ADV_TAG_RELAY_BIT | #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ -#if defined(CONFIG_BT_MESH_PB_ADV) - BT_MESH_ADV_TAG_BIT_PROV | -#endif /* CONFIG_BT_MESH_PB_ADV */ - BT_MESH_ADV_TAG_BIT_LOCAL - ), - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), - }, -#if CONFIG_BT_MESH_RELAY_ADV_SETS - [1 ... CONFIG_BT_MESH_RELAY_ADV_SETS] = { + BT_MESH_ADV_TAG_LOCAL_BIT), + + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), +}; + +#if CONFIG_BT_MESH_SIMULT_ADV_SETS +static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_SIMULT_ADV_SETS) = { + [0 ... CONFIG_BT_MESH_SIMULT_ADV_SETS - 1] = { .tags = ( #if defined(CONFIG_BT_MESH_RELAY) - BT_MESH_ADV_TAG_BIT_RELAY | + BT_MESH_ADV_TAG_RELAY_BIT | #endif /* CONFIG_BT_MESH_RELAY */ -#if defined(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS) - BT_MESH_ADV_TAG_BIT_PROV | -#endif /* CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS */ +#if defined(CONFIG_BT_MESH_PB_ADV) + BT_MESH_ADV_TAG_PROV_BIT | +#endif /* CONFIG_BT_MESH_PB_ADV */ 0), + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), - }, -#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ + } +}; +#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ + #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - { - .tags = BT_MESH_ADV_TAG_BIT_FRIEND, - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), - }, +#define ADV_EXT_FRIEND 1 +static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { + .tags = BT_MESH_ADV_TAG_FRIEND_BIT, + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), +}; +#else /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ +#define ADV_EXT_FRIEND 0 #endif /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ + #if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - { - .tags = BT_MESH_ADV_TAG_BIT_PROXY, - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), - }, -#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ +#define ADV_EXT_GATT 1 +static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_gatt) = { + .tags = BT_MESH_ADV_TAG_PROXY_BIT, + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; +#else /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ +#define ADV_EXT_GATT 0 +#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ + +#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_SIMULT_ADV_SETS + ADV_EXT_FRIEND + ADV_EXT_GATT) -BUILD_ASSERT(ARRAY_SIZE(advs) <= CONFIG_BT_EXT_ADV_MAX_ADV_SET, +BUILD_ASSERT(CONFIG_BT_EXT_ADV_MAX_ADV_SET >= BT_MESH_ADV_COUNT, "Insufficient adv instances"); static inline struct bt_mesh_ext_adv *relay_adv_get(void) { - if (!!(CONFIG_BT_MESH_RELAY_ADV_SETS)) { - return &advs[1]; - } else { - return &advs[0]; - } +#if CONFIG_BT_MESH_SIMULT_ADV_SETS + return adv_relay; +#else /* !CONFIG_BT_MESH_SIMULT_ADV_SETS */ + return &adv_main; +#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ } static inline struct bt_mesh_ext_adv *gatt_adv_get(void) { - if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)) { - return &advs[ARRAY_SIZE(advs) - 1]; - } else { - return &advs[0]; - } +#if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) + return &adv_gatt; +#else /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ + return &adv_main; +#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ } static int set_adv_randomness(uint8_t handle, int rand_us) @@ -319,7 +328,7 @@ static void send_pending_adv(struct k_work *work) } if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || - !(adv->tags & BT_MESH_ADV_TAG_BIT_PROXY)) { + !(adv->tags & BT_MESH_ADV_TAG_PROXY_BIT)) { return; } @@ -363,8 +372,8 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - adv->tags & BT_MESH_ADV_TAG_BIT_FRIEND) || - (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_BIT_RELAY)) { + adv->tags & BT_MESH_ADV_TAG_FRIEND_BIT) || + (CONFIG_BT_MESH_SIMULT_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_RELAY_BIT)) { k_work_reschedule(&adv->work, K_NO_WAIT); } else { /* The controller will send the next advertisement immediately. @@ -385,14 +394,14 @@ void bt_mesh_adv_gatt_update(void) void bt_mesh_adv_buf_local_ready(void) { - (void)schedule_send(advs); + (void)schedule_send(&adv_main); } -void bt_mesh_adv_buf_relay_ready(void) +void bt_mesh_adv_buf_simult_ready(void) { struct bt_mesh_ext_adv *adv = relay_adv_get(); - for (int i = 0; i < CONFIG_BT_MESH_RELAY_ADV_SETS; i++) { + for (int i = 0; i < CONFIG_BT_MESH_SIMULT_ADV_SETS; i++) { if (schedule_send(&adv[i])) { return; } @@ -400,26 +409,22 @@ void bt_mesh_adv_buf_relay_ready(void) /* Attempt to use the main adv set for the sending of relay messages. */ if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET)) { - (void)schedule_send(advs); + (void)schedule_send(&adv_main); } } void bt_mesh_adv_buf_friend_ready(void) { - if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { - schedule_send(&advs[1 + CONFIG_BT_MESH_RELAY_ADV_SETS]); - } else { - schedule_send(&advs[0]); - } +#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) + (void)schedule_send(&adv_friend); +#endif } -void bt_mesh_adv_buf_terminate(const struct net_buf *buf) +void bt_mesh_adv_buf_terminate(struct net_buf *buf) { int err; - for (int i = 0; i < ARRAY_SIZE(advs); i++) { - struct bt_mesh_ext_adv *adv = &advs[i]; - + STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { if (adv->buf != buf) { continue; } @@ -441,7 +446,7 @@ void bt_mesh_adv_buf_terminate(const struct net_buf *buf) k_work_submit(&adv->work.work); - return; + break; } } @@ -454,18 +459,17 @@ void bt_mesh_adv_init(void) #if defined(CONFIG_BT_MESH_DEBUG_USE_ID_ADDR) .options = BT_LE_ADV_OPT_USE_IDENTITY, #endif - }; - - for (int i = 0; i < ARRAY_SIZE(advs); i++) { - (void)memcpy(&advs[i].adv_param, &adv_param, sizeof(adv_param)); +}; + STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { + (void)memcpy(&adv->adv_param, &adv_param, sizeof(adv_param)); } } static struct bt_mesh_ext_adv *adv_instance_find(struct bt_le_ext_adv *instance) { - for (int i = 0; i < ARRAY_SIZE(advs); i++) { - if (advs[i].instance == instance) { - return &advs[i]; + STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { + if (adv->instance == instance) { + return adv; } } @@ -515,14 +519,15 @@ int bt_mesh_adv_enable(void) #endif /* CONFIG_BT_MESH_GATT_SERVER */ }; - if (advs[0].instance) { + if (adv_main.instance) { /* Already initialized */ return 0; } - for (int i = 0; i < ARRAY_SIZE(advs); i++) { - err = bt_le_ext_adv_create(&advs[i].adv_param, &adv_cb, - &advs[i].instance); + + STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { + err = bt_le_ext_adv_create(&adv->adv_param, &adv_cb, + &adv->instance); if (err) { return err; } @@ -561,5 +566,5 @@ int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, int bt_mesh_adv_bt_data_send(uint8_t num_events, uint16_t adv_interval, const struct bt_data *ad, size_t ad_len) { - return bt_data_send(advs, num_events, adv_interval, ad, ad_len); + return bt_data_send(&adv_main, num_events, adv_interval, ad, ad_len); } diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index a7d7dd1a320..cb4028662f9 100644 --- a/subsys/bluetooth/mesh/adv_legacy.c +++ b/subsys/bluetooth/mesh/adv_legacy.c @@ -195,7 +195,7 @@ void bt_mesh_adv_buf_local_ready(void) /* Will be handled automatically */ } -void bt_mesh_adv_buf_relay_ready(void) +void bt_mesh_adv_buf_simult_ready(void) { /* Will be handled automatically */ } @@ -205,8 +205,9 @@ void bt_mesh_adv_gatt_update(void) bt_mesh_adv_buf_get_cancel(); } -void bt_mesh_adv_buf_terminate(const struct net_buf *buf) +void bt_mesh_adv_buf_terminate(struct net_buf *buf) { + /* todo */ ARG_UNUSED(buf); } diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index a65bd25ab53..6bf759272dd 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -20,6 +20,8 @@ #include "common/bt_str.h" +#include "host/long_wq.h" + #include "crypto.h" #include "adv.h" #include "mesh.h" diff --git a/tests/bluetooth/mesh/basic/multi_ext_adv.conf b/tests/bluetooth/mesh/basic/multi_ext_adv.conf index 610318f847b..0278bd557bd 100644 --- a/tests/bluetooth/mesh/basic/multi_ext_adv.conf +++ b/tests/bluetooth/mesh/basic/multi_ext_adv.conf @@ -51,5 +51,5 @@ CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y CONFIG_BT_EXT_ADV_MAX_ADV_SET=3 -CONFIG_BT_MESH_RELAY_ADV_SETS=1 +CONFIG_BT_MESH_SIMULT_ADV_SETS=1 CONFIG_BT_MESH_ADV_EXT=y diff --git a/tests/bsim/bluetooth/mesh/src/test_advertiser.c b/tests/bsim/bluetooth/mesh/src/test_advertiser.c index 6a171b499bf..911c5772f8b 100644 --- a/tests/bsim/bluetooth/mesh/src/test_advertiser.c +++ b/tests/bsim/bluetooth/mesh/src/test_advertiser.c @@ -638,7 +638,7 @@ static void test_tx_random_order(void) previous_checker = 0xff; buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); - ASSERT_FALSE_MSG(!buf[0], "Out of buffers\n"); + ASSERT_FALSE(!buf[0], "Out of buffers\n"); buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); ASSERT_FALSE(!buf[1], "Out of buffers"); From ca5c21c291658487861ed2fe17d0cc7c068eb31e Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:29 +0000 Subject: [PATCH 0559/1623] Revert "[nrf fromlist] Bluetooth: Mesh: Use system workqueue for dhkey gen" This reverts commit d5bb75fa25114593f868352f0b6cfcc5af996a86. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/Kconfig | 2 +- subsys/bluetooth/mesh/prov_device.c | 9 +-------- subsys/bluetooth/mesh/provisioner.c | 11 +---------- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index cb04b4dedfb..a05d3917c1d 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -210,7 +210,7 @@ config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT config BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT int "Link Ack and Transaction Ack retransmit count" - default 0 + default 2 range 0 7 help Controls the number of retransmissions of original Link Open and Transaction Acknowledgment PDU, diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/prov_device.c index 6e56519eefb..992bf656202 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/prov_device.c @@ -358,13 +358,6 @@ static void prov_dh_key_gen(void) } } -static void prov_dh_key_gen_handler(struct k_work *work) -{ - prov_dh_key_gen(); -} - -static K_WORK_DEFINE(dh_gen_work, prov_dh_key_gen_handler); - static void prov_pub_key(const uint8_t *data) { LOG_DBG("Remote Public Key: %s", bt_hex(data, PUB_KEY_SIZE)); @@ -392,7 +385,7 @@ static void prov_pub_key(const uint8_t *data) PDU_LEN_PUB_KEY); } - k_work_submit(&dh_gen_work); + prov_dh_key_gen(); } static void notify_input_complete(void) diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index 6bf759272dd..717cdbee610 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -20,8 +20,6 @@ #include "common/bt_str.h" -#include "host/long_wq.h" - #include "crypto.h" #include "adv.h" #include "mesh.h" @@ -452,13 +450,6 @@ static void prov_dh_key_gen(void) send_confirm(); } -static void prov_dh_key_gen_handler(struct k_work *work) -{ - prov_dh_key_gen(); -} - -static K_WORK_DEFINE(dh_gen_work, prov_dh_key_gen_handler); - static void prov_pub_key(const uint8_t *data) { LOG_DBG("Remote Public Key: %s", bt_hex(data, PUB_KEY_SIZE)); @@ -469,7 +460,7 @@ static void prov_pub_key(const uint8_t *data) memcpy(bt_mesh_prov_link.conf_inputs.pub_key_device, data, PUB_KEY_SIZE); bt_mesh_prov_link.bearer->clear_tx(); - k_work_submit(&dh_gen_work); + prov_dh_key_gen(); } static void notify_input_complete(void) From d50b5bd42ce9b7fc23ae9990dd5e9119bea3cc12 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:29 +0000 Subject: [PATCH 0560/1623] Revert "[nrf fromlist] Bluetooth: Mesh: Rename adv relay to adv simultaneous" This reverts commit 4d33c79aca6fab97c81dfc03228b997028989562. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/Kconfig | 40 ++----- subsys/bluetooth/mesh/adv.c | 44 ++++--- subsys/bluetooth/mesh/adv.h | 22 ++-- subsys/bluetooth/mesh/adv_ext.c | 109 ++++++------------ subsys/bluetooth/mesh/adv_legacy.c | 8 +- subsys/bluetooth/mesh/beacon.c | 6 +- subsys/bluetooth/mesh/friend.c | 2 +- subsys/bluetooth/mesh/net.c | 2 +- subsys/bluetooth/mesh/pb_adv.c | 19 +-- subsys/bluetooth/mesh/statistic.c | 12 +- subsys/bluetooth/mesh/transport.c | 4 +- subsys/bluetooth/mesh/transport_legacy.c | 4 +- tests/bluetooth/mesh/basic/multi_ext_adv.conf | 2 +- .../bsim/bluetooth/mesh/src/test_advertiser.c | 18 +-- 14 files changed, 107 insertions(+), 185 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index a05d3917c1d..605e4608be7 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -103,22 +103,22 @@ menuconfig BT_MESH_ADV_EXT if BT_MESH_ADV_EXT -config BT_MESH_SIMULT_ADV_SETS - int "Maximum number of parallel advertising sets that can be used by the Bluetooth Mesh stack" +config BT_MESH_RELAY_ADV_SETS + int "Maximum of simultaneous relay message support" default 0 range 0 BT_EXT_ADV_MAX_ADV_SET - depends on BT_MESH_RELAY || BT_MESH_PB_ADV + depends on BT_MESH_RELAY help - Maximum of simultaneous message support. Requires controller support + Maximum of simultaneous relay message support. Requires controller support multiple advertising sets. config BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET bool "Use the main advertising set to relay messages" - depends on BT_MESH_SIMULT_ADV_SETS > 0 + depends on BT_MESH_RELAY_ADV_SETS > 0 help When this option is enabled, there is a message that needs to be relayed, all relay advertising sets defined by - CONFIG_BT_MESH_SIMULT_ADV_SETS are busy with relaying messages + CONFIG_BT_MESH_RELAY_ADV_SETS are busy with relaying messages and the main advertising set is not busy with sending local messages, the stack will use the main advertising set to relay the message. This maximizes the utilization efficiency of @@ -199,32 +199,6 @@ config BT_MESH_PB_ADV_RETRANS_TIMEOUT help Timeout value of retransmit provisioning PDUs. -config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT - int "Link Open and Transaction PDU retransmit count" - default 7 if BT_MESH_SIMULT_ADV_SETS > 0 - default 0 - range 0 7 - help - Controls the number of retransmissions of original Link Open and Transaction PDU, - in addition to the first transmission. - -config BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT - int "Link Ack and Transaction Ack retransmit count" - default 2 - range 0 7 - help - Controls the number of retransmissions of original Link Open and Transaction Acknowledgment PDU, - in addition to the first transmission. - -config BT_MESH_PB_ADV_LINK_CLOSE_RETRANSMIT_COUNT - int "Link Close retransmit count" - default 7 if BT_MESH_SIMULT_ADV_SETS > 0 - default 2 - range 0 7 - help - Controls the number of retransmissions of original Link Close, - in addition to the first transmission. - endif # BT_MESH_PB_ADV if BT_CONN @@ -401,7 +375,7 @@ config BT_MESH_RELAY_BUF_COUNT of packet drops. When considering the message latency, also consider the values of BT_MESH_RELAY_RETRANSMIT_COUNT and BT_MESH_RELAY_RETRANSMIT_INTERVAL. A higher number of - BT_MESH_SIMULT_ADV_SETS allows the increase in the number of buffers + BT_MESH_RELAY_ADV_SETS allows the increase in the number of buffers while maintaining the latency. endif # BT_MESH_RELAY diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index c7abcd53d70..e67d96414e7 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -44,7 +44,7 @@ const uint8_t bt_mesh_adv_type[BT_MESH_ADV_TYPES] = { static bool active_scanning; static K_FIFO_DEFINE(bt_mesh_adv_queue); -static K_FIFO_DEFINE(bt_mesh_simult_queue); +static K_FIFO_DEFINE(bt_mesh_relay_queue); static K_FIFO_DEFINE(bt_mesh_friend_queue); void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv *adv) @@ -138,7 +138,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, uint8_t xmit, k_timeout_t timeout) { #if defined(CONFIG_BT_MESH_RELAY) - if (tag == BT_MESH_ADV_TAG_RELAY) { + if (tag == BT_MESH_RELAY_ADV) { return bt_mesh_adv_create_from_pool(&relay_buf_pool, adv_relay_pool, type, tag, xmit, timeout); @@ -146,7 +146,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, #endif #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - if (tag == BT_MESH_ADV_TAG_FRIEND) { + if (tag == BT_MESH_FRIEND_ADV) { return bt_mesh_adv_create_from_pool(&friend_buf_pool, adv_friend_pool, type, tag, xmit, timeout); @@ -157,7 +157,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, tag, xmit, timeout); } -#if CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE +#if CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE static struct net_buf *process_events(struct k_poll_event *ev, int count) { for (; count; ev++, count--) { @@ -189,7 +189,7 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, K_POLL_MODE_NOTIFY_ONLY, - &bt_mesh_simult_queue, + &bt_mesh_relay_queue, 0), #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ }; @@ -204,20 +204,19 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) { - if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - tags & BT_MESH_ADV_TAG_FRIEND_BIT) { + if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && tags & BT_MESH_FRIEND_ADV_BIT) { return net_buf_get(&bt_mesh_friend_queue, timeout); } - if (tags & BT_MESH_ADV_TAG_LOCAL_BIT) { - return bt_mesh_adv_buf_get(timeout); +#if CONFIG_BT_MESH_RELAY_ADV_SETS + if (tags & BT_MESH_RELAY_ADV_BIT) { + return net_buf_get(&bt_mesh_relay_queue, timeout); } - -#if CONFIG_BT_MESH_SIMULT_ADV_SETS - return net_buf_get(&bt_mesh_simult_queue, timeout); #endif + + return bt_mesh_adv_buf_get(timeout); } -#else /* !(CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) */ +#else /* !(CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) */ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) { return net_buf_get(&bt_mesh_adv_queue, timeout); @@ -229,7 +228,7 @@ struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout return bt_mesh_adv_buf_get(timeout); } -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ +#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ void bt_mesh_adv_buf_get_cancel(void) { @@ -237,9 +236,9 @@ void bt_mesh_adv_buf_get_cancel(void) k_fifo_cancel_wait(&bt_mesh_adv_queue); -#if CONFIG_BT_MESH_SIMULT_ADV_SETS - k_fifo_cancel_wait(&bt_mesh_simult_queue); -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ +#if CONFIG_BT_MESH_RELAY_ADV_SETS + k_fifo_cancel_wait(&bt_mesh_relay_queue); +#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { k_fifo_cancel_wait(&bt_mesh_friend_queue); @@ -261,17 +260,16 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, } if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_FRIEND) { + BT_MESH_ADV(buf)->tag == BT_MESH_FRIEND_ADV) { net_buf_put(&bt_mesh_friend_queue, net_buf_ref(buf)); bt_mesh_adv_buf_friend_ready(); return; } -#if CONFIG_BT_MESH_SIMULT_ADV_SETS - if (BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_RELAY || - BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV) { - net_buf_put(&bt_mesh_simult_queue, net_buf_ref(buf)); - bt_mesh_adv_buf_simult_ready(); +#if CONFIG_BT_MESH_RELAY_ADV_SETS + if (BT_MESH_ADV(buf)->tag == BT_MESH_RELAY_ADV) { + net_buf_put(&bt_mesh_relay_queue, net_buf_ref(buf)); + bt_mesh_adv_buf_relay_ready(); return; } #endif diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index 50c5b47604c..22a8e0645e1 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -26,19 +26,17 @@ enum bt_mesh_adv_type { }; enum bt_mesh_adv_tag { - BT_MESH_ADV_TAG_LOCAL, - BT_MESH_ADV_TAG_RELAY, - BT_MESH_ADV_TAG_PROXY, - BT_MESH_ADV_TAG_FRIEND, - BT_MESH_ADV_TAG_PROV, + BT_MESH_LOCAL_ADV, + BT_MESH_RELAY_ADV, + BT_MESH_PROXY_ADV, + BT_MESH_FRIEND_ADV, }; enum bt_mesh_adv_tags { - BT_MESH_ADV_TAG_LOCAL_BIT = BIT(BT_MESH_ADV_TAG_LOCAL), - BT_MESH_ADV_TAG_RELAY_BIT = BIT(BT_MESH_ADV_TAG_RELAY), - BT_MESH_ADV_TAG_PROXY_BIT = BIT(BT_MESH_ADV_TAG_PROXY), - BT_MESH_ADV_TAG_FRIEND_BIT = BIT(BT_MESH_ADV_TAG_FRIEND), - BT_MESH_ADV_TAG_PROV_BIT = BIT(BT_MESH_ADV_TAG_PROV), + BT_MESH_LOCAL_ADV_BIT = BIT(BT_MESH_LOCAL_ADV), + BT_MESH_RELAY_ADV_BIT = BIT(BT_MESH_RELAY_ADV), + BT_MESH_PROXY_ADV_BIT = BIT(BT_MESH_PROXY_ADV), + BT_MESH_FRIEND_ADV_BIT = BIT(BT_MESH_FRIEND_ADV), }; struct bt_mesh_adv { @@ -82,9 +80,7 @@ int bt_mesh_adv_enable(void); void bt_mesh_adv_buf_local_ready(void); -void bt_mesh_adv_buf_simult_ready(void); - -void bt_mesh_adv_buf_terminate(struct net_buf *buf); +void bt_mesh_adv_buf_relay_ready(void); void bt_mesh_adv_buf_friend_ready(void); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 2065de372a4..d347602ac09 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -33,8 +33,8 @@ LOG_MODULE_REGISTER(bt_mesh_adv_ext); /* Convert from ms to 0.625ms units */ #define ADV_INT_FAST_MS 20 -#ifndef CONFIG_BT_MESH_SIMULT_ADV_SETS -#define CONFIG_BT_MESH_SIMULT_ADV_SETS 0 +#ifndef CONFIG_BT_MESH_RELAY_ADV_SETS +#define CONFIG_BT_MESH_RELAY_ADV_SETS 0 #endif enum { @@ -75,40 +75,32 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv); static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { .tags = ( #if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - BT_MESH_ADV_TAG_FRIEND_BIT | + BT_MESH_FRIEND_ADV_BIT | #endif #if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - BT_MESH_ADV_TAG_PROXY_BIT | + BT_MESH_PROXY_ADV_BIT | #endif /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) - BT_MESH_ADV_TAG_RELAY_BIT | + BT_MESH_RELAY_ADV_BIT | #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ - BT_MESH_ADV_TAG_LOCAL_BIT), + BT_MESH_LOCAL_ADV_BIT), .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; -#if CONFIG_BT_MESH_SIMULT_ADV_SETS -static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_SIMULT_ADV_SETS) = { - [0 ... CONFIG_BT_MESH_SIMULT_ADV_SETS - 1] = { - .tags = ( -#if defined(CONFIG_BT_MESH_RELAY) - BT_MESH_ADV_TAG_RELAY_BIT | -#endif /* CONFIG_BT_MESH_RELAY */ -#if defined(CONFIG_BT_MESH_PB_ADV) - BT_MESH_ADV_TAG_PROV_BIT | -#endif /* CONFIG_BT_MESH_PB_ADV */ - 0), - +#if CONFIG_BT_MESH_RELAY_ADV_SETS +static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_RELAY_ADV_SETS) = { + [0 ... CONFIG_BT_MESH_RELAY_ADV_SETS - 1] = { + .tags = BT_MESH_RELAY_ADV_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), } }; -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ +#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) #define ADV_EXT_FRIEND 1 static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { - .tags = BT_MESH_ADV_TAG_FRIEND_BIT, + .tags = BT_MESH_FRIEND_ADV_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; #else /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ @@ -118,25 +110,25 @@ static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { #if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) #define ADV_EXT_GATT 1 static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_gatt) = { - .tags = BT_MESH_ADV_TAG_PROXY_BIT, + .tags = BT_MESH_PROXY_ADV_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; #else /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #define ADV_EXT_GATT 0 #endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ -#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_SIMULT_ADV_SETS + ADV_EXT_FRIEND + ADV_EXT_GATT) +#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_RELAY_ADV_SETS + ADV_EXT_FRIEND + ADV_EXT_GATT) BUILD_ASSERT(CONFIG_BT_EXT_ADV_MAX_ADV_SET >= BT_MESH_ADV_COUNT, "Insufficient adv instances"); static inline struct bt_mesh_ext_adv *relay_adv_get(void) { -#if CONFIG_BT_MESH_SIMULT_ADV_SETS +#if CONFIG_BT_MESH_RELAY_ADV_SETS return adv_relay; -#else /* !CONFIG_BT_MESH_SIMULT_ADV_SETS */ +#else /* !CONFIG_BT_MESH_RELAY_ADV_SETS */ return &adv_main; -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ +#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ } static inline struct bt_mesh_ext_adv *gatt_adv_get(void) @@ -267,13 +259,20 @@ static int buf_send(struct bt_mesh_ext_adv *adv, struct net_buf *buf) return err; } -static const char * const adv_tag_to_str[] = { - [BT_MESH_ADV_TAG_LOCAL] = "local adv", - [BT_MESH_ADV_TAG_RELAY] = "relay adv", - [BT_MESH_ADV_TAG_PROXY] = "proxy adv", - [BT_MESH_ADV_TAG_FRIEND] = "friend adv", - [BT_MESH_ADV_TAG_PROV] = "prov adv", -}; +static const char *adv_tag_to_str(enum bt_mesh_adv_tags tags) +{ + if (tags & BT_MESH_LOCAL_ADV_BIT) { + return "local adv"; + } else if (tags & BT_MESH_PROXY_ADV_BIT) { + return "proxy adv"; + } else if (tags & BT_MESH_RELAY_ADV_BIT) { + return "relay adv"; + } else if (tags & BT_MESH_FRIEND_ADV_BIT) { + return "friend adv"; + } else { + return "(unknown tags)"; + } +} static void send_pending_adv(struct k_work *work) { @@ -290,9 +289,8 @@ static void send_pending_adv(struct k_work *work) */ int64_t duration = k_uptime_delta(&adv->timestamp); - LOG_DBG("Advertising stopped after %u ms for %s", (uint32_t)duration, - adv->buf ? adv_tag_to_str[BT_MESH_ADV(adv->buf)->tag] : - adv_tag_to_str[BT_MESH_ADV_TAG_PROXY]); + LOG_DBG("Advertising stopped after %u ms for (%u) %s", (uint32_t)duration, adv->tags, + adv_tag_to_str(adv->tags)); atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(adv->flags, ADV_FLAG_PROXY); @@ -328,7 +326,7 @@ static void send_pending_adv(struct k_work *work) } if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || - !(adv->tags & BT_MESH_ADV_TAG_PROXY_BIT)) { + !(adv->tags & BT_MESH_RELAY_ADV_BIT)) { return; } @@ -371,9 +369,8 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); - if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - adv->tags & BT_MESH_ADV_TAG_FRIEND_BIT) || - (CONFIG_BT_MESH_SIMULT_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_RELAY_BIT)) { + if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && adv->tags & BT_MESH_FRIEND_ADV_BIT) || + (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_RELAY_ADV_BIT)) { k_work_reschedule(&adv->work, K_NO_WAIT); } else { /* The controller will send the next advertisement immediately. @@ -397,11 +394,11 @@ void bt_mesh_adv_buf_local_ready(void) (void)schedule_send(&adv_main); } -void bt_mesh_adv_buf_simult_ready(void) +void bt_mesh_adv_buf_relay_ready(void) { struct bt_mesh_ext_adv *adv = relay_adv_get(); - for (int i = 0; i < CONFIG_BT_MESH_SIMULT_ADV_SETS; i++) { + for (int i = 0; i < CONFIG_BT_MESH_RELAY_ADV_SETS; i++) { if (schedule_send(&adv[i])) { return; } @@ -420,36 +417,6 @@ void bt_mesh_adv_buf_friend_ready(void) #endif } -void bt_mesh_adv_buf_terminate(struct net_buf *buf) -{ - int err; - - STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { - if (adv->buf != buf) { - continue; - } - - if (!atomic_test_bit(adv->flags, ADV_FLAG_ACTIVE)) { - return; - } - - err = bt_le_ext_adv_stop(adv->instance); - if (err) { - LOG_ERR("Failed to stop adv %d", err); - return; - } - - /* Do not call `cb:end`, since this user action */ - BT_MESH_ADV(adv->buf)->cb = NULL; - - atomic_set_bit(adv->flags, ADV_FLAG_SENT); - - k_work_submit(&adv->work.work); - - break; - } -} - void bt_mesh_adv_init(void) { struct bt_le_adv_param adv_param = { diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index cb4028662f9..8136aef9f22 100644 --- a/subsys/bluetooth/mesh/adv_legacy.c +++ b/subsys/bluetooth/mesh/adv_legacy.c @@ -195,7 +195,7 @@ void bt_mesh_adv_buf_local_ready(void) /* Will be handled automatically */ } -void bt_mesh_adv_buf_simult_ready(void) +void bt_mesh_adv_buf_relay_ready(void) { /* Will be handled automatically */ } @@ -205,12 +205,6 @@ void bt_mesh_adv_gatt_update(void) bt_mesh_adv_buf_get_cancel(); } -void bt_mesh_adv_buf_terminate(struct net_buf *buf) -{ - /* todo */ - ARG_UNUSED(buf); -} - void bt_mesh_adv_init(void) { k_thread_create(&adv_thread_data, adv_thread_stack, diff --git a/subsys/bluetooth/mesh/beacon.c b/subsys/bluetooth/mesh/beacon.c index afdea5b4c6a..8c0ac3b54e9 100644 --- a/subsys/bluetooth/mesh/beacon.c +++ b/subsys/bluetooth/mesh/beacon.c @@ -271,7 +271,7 @@ static bool net_beacon_send(struct bt_mesh_subnet *sub, struct bt_mesh_beacon *b return false; } - buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, + buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_LOCAL_ADV, PROV_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate beacon buffer"); @@ -335,7 +335,7 @@ static int unprovisioned_beacon_send(void) LOG_DBG(""); - buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, + buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_LOCAL_ADV, UNPROV_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate beacon buffer"); @@ -362,7 +362,7 @@ static int unprovisioned_beacon_send(void) if (prov->uri) { size_t len; - buf = bt_mesh_adv_create(BT_MESH_ADV_URI, BT_MESH_ADV_TAG_LOCAL, + buf = bt_mesh_adv_create(BT_MESH_ADV_URI, BT_MESH_LOCAL_ADV, UNPROV_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate URI buffer"); diff --git a/subsys/bluetooth/mesh/friend.c b/subsys/bluetooth/mesh/friend.c index 73b75eadf4f..179755d9706 100644 --- a/subsys/bluetooth/mesh/friend.c +++ b/subsys/bluetooth/mesh/friend.c @@ -1281,7 +1281,7 @@ static void friend_timeout(struct k_work *work) frnd->queue_size--; send_last: - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_FRIEND, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_FRIEND_ADV, FRIEND_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate friend adv buffer"); diff --git a/subsys/bluetooth/mesh/net.c b/subsys/bluetooth/mesh/net.c index 61efaeb2c81..2cfc709c648 100644 --- a/subsys/bluetooth/mesh/net.c +++ b/subsys/bluetooth/mesh/net.c @@ -712,7 +712,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, transmit = bt_mesh_net_transmit_get(); } - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_RELAY, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_RELAY_ADV, transmit, K_NO_WAIT); if (!buf) { LOG_DBG("Out of relay buffers"); diff --git a/subsys/bluetooth/mesh/pb_adv.c b/subsys/bluetooth/mesh/pb_adv.c index cb5f53f32b7..27d55763298 100644 --- a/subsys/bluetooth/mesh/pb_adv.c +++ b/subsys/bluetooth/mesh/pb_adv.c @@ -55,11 +55,11 @@ LOG_MODULE_REGISTER(bt_mesh_pb_adv); /* Acked messages, will do retransmissions manually, taking acks into account: */ -#define RETRANSMITS_RELIABLE CONFIG_BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT +#define RETRANSMITS_RELIABLE 0 /* PDU acks: */ -#define RETRANSMITS_ACK CONFIG_BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT +#define RETRANSMITS_ACK 2 /* Link close retransmits: */ -#define RETRANSMITS_LINK_CLOSE CONFIG_BT_MESH_PB_ADV_LINK_CLOSE_RETRANSMIT_COUNT +#define RETRANSMITS_LINK_CLOSE 2 enum { ADV_LINK_ACTIVE, /* Link has been opened */ @@ -178,15 +178,8 @@ static void free_segments(void) } link.tx.buf[i] = NULL; - - /* Terminate active adv */ - if (BT_MESH_ADV(buf)->busy == 0U) { - bt_mesh_adv_buf_terminate(buf); - } else { - /* Mark as canceled */ - BT_MESH_ADV(buf)->busy = 0U; - } - + /* Mark as canceled */ + BT_MESH_ADV(buf)->busy = 0U; net_buf_unref(buf); } } @@ -258,7 +251,7 @@ static struct net_buf *adv_buf_create(uint8_t retransmits) { struct net_buf *buf; - buf = bt_mesh_adv_create(BT_MESH_ADV_PROV, BT_MESH_ADV_TAG_PROV, + buf = bt_mesh_adv_create(BT_MESH_ADV_PROV, BT_MESH_LOCAL_ADV, BT_MESH_TRANSMIT(retransmits, 20), BUF_TIMEOUT); if (!buf) { diff --git a/subsys/bluetooth/mesh/statistic.c b/subsys/bluetooth/mesh/statistic.c index 21c451bee73..046fa3c0eeb 100644 --- a/subsys/bluetooth/mesh/statistic.c +++ b/subsys/bluetooth/mesh/statistic.c @@ -24,22 +24,22 @@ void bt_mesh_stat_reset(void) void bt_mesh_stat_planned_count(struct bt_mesh_adv *adv) { - if (adv->tag == BT_MESH_ADV_TAG_LOCAL) { + if (adv->tag == BT_MESH_LOCAL_ADV) { stat.tx_local_planned++; - } else if (adv->tag == BT_MESH_ADV_TAG_RELAY) { + } else if (adv->tag == BT_MESH_RELAY_ADV) { stat.tx_adv_relay_planned++; - } else if (adv->tag == BT_MESH_ADV_TAG_FRIEND) { + } else if (adv->tag == BT_MESH_FRIEND_ADV) { stat.tx_friend_planned++; } } void bt_mesh_stat_succeeded_count(struct bt_mesh_adv *adv) { - if (adv->tag == BT_MESH_ADV_TAG_LOCAL) { + if (adv->tag == BT_MESH_LOCAL_ADV) { stat.tx_local_succeeded++; - } else if (adv->tag == BT_MESH_ADV_TAG_RELAY) { + } else if (adv->tag == BT_MESH_RELAY_ADV) { stat.tx_adv_relay_succeeded++; - } else if (adv->tag == BT_MESH_ADV_TAG_FRIEND) { + } else if (adv->tag == BT_MESH_FRIEND_ADV) { stat.tx_friend_succeeded++; } } diff --git a/subsys/bluetooth/mesh/transport.c b/subsys/bluetooth/mesh/transport.c index f4c49aa6856..0343993e348 100644 --- a/subsys/bluetooth/mesh/transport.c +++ b/subsys/bluetooth/mesh/transport.c @@ -124,7 +124,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, { struct net_buf *buf; - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, tx->xmit, BUF_TIMEOUT); if (!buf) { LOG_ERR("Out of network buffers"); @@ -414,7 +414,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx) continue; } - seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, tx->xmit, BUF_TIMEOUT); if (!seg) { LOG_DBG("Allocating segment failed"); diff --git a/subsys/bluetooth/mesh/transport_legacy.c b/subsys/bluetooth/mesh/transport_legacy.c index 23e103b4370..475a0429f75 100644 --- a/subsys/bluetooth/mesh/transport_legacy.c +++ b/subsys/bluetooth/mesh/transport_legacy.c @@ -131,7 +131,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, { struct net_buf *buf; - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, tx->xmit, BUF_TIMEOUT); if (!buf) { LOG_ERR("Out of network buffers"); @@ -401,7 +401,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx) continue; } - seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, tx->xmit, BUF_TIMEOUT); if (!seg) { LOG_DBG("Allocating segment failed"); diff --git a/tests/bluetooth/mesh/basic/multi_ext_adv.conf b/tests/bluetooth/mesh/basic/multi_ext_adv.conf index 0278bd557bd..610318f847b 100644 --- a/tests/bluetooth/mesh/basic/multi_ext_adv.conf +++ b/tests/bluetooth/mesh/basic/multi_ext_adv.conf @@ -51,5 +51,5 @@ CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y CONFIG_BT_EXT_ADV_MAX_ADV_SET=3 -CONFIG_BT_MESH_SIMULT_ADV_SETS=1 +CONFIG_BT_MESH_RELAY_ADV_SETS=1 CONFIG_BT_MESH_ADV_EXT=y diff --git a/tests/bsim/bluetooth/mesh/src/test_advertiser.c b/tests/bsim/bluetooth/mesh/src/test_advertiser.c index 911c5772f8b..590eed8eebc 100644 --- a/tests/bsim/bluetooth/mesh/src/test_advertiser.c +++ b/tests/bsim/bluetooth/mesh/src/test_advertiser.c @@ -81,7 +81,7 @@ static void adv_init(void) static void allocate_all_array(struct net_buf **buf, size_t num_buf, uint8_t xmit) { for (int i = 0; i < num_buf; i++) { - *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, xmit, K_NO_WAIT); ASSERT_FALSE(!*buf, "Out of buffers"); @@ -94,7 +94,7 @@ static void verify_adv_queue_overflow(void) struct net_buf *dummy_buf; /* Verity Queue overflow */ - dummy_buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + dummy_buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); ASSERT_TRUE(!dummy_buf, "Unexpected extra buffer"); } @@ -160,7 +160,7 @@ static void realloc_end_cb(int err, void *cb_data) struct net_buf *buf = (struct net_buf *)cb_data; ASSERT_EQUAL(0, err); - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); ASSERT_FALSE(!buf, "Out of buffers"); @@ -425,7 +425,7 @@ static void test_tx_cb_single(void) bt_init(); adv_init(); - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); ASSERT_FALSE(!buf, "Out of buffers"); @@ -530,7 +530,7 @@ static void test_tx_proxy_mixin(void) * Advertising the proxy service should be resumed after * finishing advertising the message. */ - struct net_buf *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + struct net_buf *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, BT_MESH_TRANSMIT(5, 20), K_NO_WAIT); net_buf_add_mem(buf, txt_msg, sizeof(txt_msg)); bt_mesh_adv_send(buf, NULL, NULL); @@ -636,16 +636,16 @@ static void test_tx_random_order(void) /* Verify random order calls */ num_adv_sent = ARRAY_SIZE(buf); previous_checker = 0xff; - buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, xmit, K_NO_WAIT); - ASSERT_FALSE(!buf[0], "Out of buffers\n"); - buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + ASSERT_FALSE(!buf[0], "Out of buffers"); + buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, xmit, K_NO_WAIT); ASSERT_FALSE(!buf[1], "Out of buffers"); send_adv_buf(buf[0], 0, 0xff); - buf[2] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + buf[2] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, xmit, K_NO_WAIT); ASSERT_FALSE(!buf[2], "Out of buffers"); From db98744932c00baf43e2bbbddd4faba52df2966d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:29 +0000 Subject: [PATCH 0561/1623] Revert "[nrf fromlist] Bluetooth: Mesh: Remove bits for adv tag" This reverts commit 2c3b9c4f763085faa0c4654bc4cce8baaf32b89c. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/adv.c | 14 +++++------ subsys/bluetooth/mesh/adv.h | 17 ++++--------- subsys/bluetooth/mesh/adv_ext.c | 42 +++++++++++++++---------------- subsys/bluetooth/mesh/statistic.c | 12 ++++----- 4 files changed, 39 insertions(+), 46 deletions(-) diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index e67d96414e7..2132c14e151 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -138,7 +138,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, uint8_t xmit, k_timeout_t timeout) { #if defined(CONFIG_BT_MESH_RELAY) - if (tag == BT_MESH_RELAY_ADV) { + if (tag & BT_MESH_RELAY_ADV) { return bt_mesh_adv_create_from_pool(&relay_buf_pool, adv_relay_pool, type, tag, xmit, timeout); @@ -146,7 +146,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, #endif #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - if (tag == BT_MESH_FRIEND_ADV) { + if (tag & BT_MESH_FRIEND_ADV) { return bt_mesh_adv_create_from_pool(&friend_buf_pool, adv_friend_pool, type, tag, xmit, timeout); @@ -202,14 +202,14 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) return process_events(events, ARRAY_SIZE(events)); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(uint8_t tag, k_timeout_t timeout) { - if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && tags & BT_MESH_FRIEND_ADV_BIT) { + if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && tag & BT_MESH_FRIEND_ADV) { return net_buf_get(&bt_mesh_friend_queue, timeout); } #if CONFIG_BT_MESH_RELAY_ADV_SETS - if (tags & BT_MESH_RELAY_ADV_BIT) { + if (tag & BT_MESH_RELAY_ADV) { return net_buf_get(&bt_mesh_relay_queue, timeout); } #endif @@ -222,9 +222,9 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) return net_buf_get(&bt_mesh_adv_queue, timeout); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(uint8_t tag, k_timeout_t timeout) { - ARG_UNUSED(tags); + ARG_UNUSED(tag); return bt_mesh_adv_buf_get(timeout); } diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index 22a8e0645e1..3d0acf8a7ac 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -26,17 +26,10 @@ enum bt_mesh_adv_type { }; enum bt_mesh_adv_tag { - BT_MESH_LOCAL_ADV, - BT_MESH_RELAY_ADV, - BT_MESH_PROXY_ADV, - BT_MESH_FRIEND_ADV, -}; - -enum bt_mesh_adv_tags { - BT_MESH_LOCAL_ADV_BIT = BIT(BT_MESH_LOCAL_ADV), - BT_MESH_RELAY_ADV_BIT = BIT(BT_MESH_RELAY_ADV), - BT_MESH_PROXY_ADV_BIT = BIT(BT_MESH_PROXY_ADV), - BT_MESH_FRIEND_ADV_BIT = BIT(BT_MESH_FRIEND_ADV), + BT_MESH_LOCAL_ADV = BIT(0), + BT_MESH_RELAY_ADV = BIT(1), + BT_MESH_PROXY_ADV = BIT(2), + BT_MESH_FRIEND_ADV = BIT(3), }; struct bt_mesh_adv { @@ -64,7 +57,7 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout); -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout); +struct net_buf *bt_mesh_adv_buf_get_by_tag(uint8_t tag, k_timeout_t timeout); void bt_mesh_adv_gatt_update(void); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index d347602ac09..5c1a2bc3c32 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -60,7 +60,7 @@ enum { }; struct bt_mesh_ext_adv { - enum bt_mesh_adv_tags tags; + uint8_t tag; ATOMIC_DEFINE(flags, ADV_FLAGS_NUM); struct bt_le_ext_adv *instance; struct net_buf *buf; @@ -73,17 +73,17 @@ static void send_pending_adv(struct k_work *work); static bool schedule_send(struct bt_mesh_ext_adv *adv); static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { - .tags = ( + .tag = ( #if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - BT_MESH_FRIEND_ADV_BIT | + BT_MESH_FRIEND_ADV | #endif #if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - BT_MESH_PROXY_ADV_BIT | + BT_MESH_PROXY_ADV | #endif /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) - BT_MESH_RELAY_ADV_BIT | + BT_MESH_RELAY_ADV | #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ - BT_MESH_LOCAL_ADV_BIT), + BT_MESH_LOCAL_ADV), .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; @@ -91,7 +91,7 @@ static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { #if CONFIG_BT_MESH_RELAY_ADV_SETS static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_RELAY_ADV_SETS) = { [0 ... CONFIG_BT_MESH_RELAY_ADV_SETS - 1] = { - .tags = BT_MESH_RELAY_ADV_BIT, + .tag = BT_MESH_RELAY_ADV, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), } }; @@ -100,7 +100,7 @@ static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_ #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) #define ADV_EXT_FRIEND 1 static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { - .tags = BT_MESH_FRIEND_ADV_BIT, + .tag = BT_MESH_FRIEND_ADV, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; #else /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ @@ -110,7 +110,7 @@ static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { #if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) #define ADV_EXT_GATT 1 static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_gatt) = { - .tags = BT_MESH_PROXY_ADV_BIT, + .tag = BT_MESH_PROXY_ADV, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; #else /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ @@ -259,18 +259,18 @@ static int buf_send(struct bt_mesh_ext_adv *adv, struct net_buf *buf) return err; } -static const char *adv_tag_to_str(enum bt_mesh_adv_tags tags) +static const char *adv_tag_to_str(enum bt_mesh_adv_tag tag) { - if (tags & BT_MESH_LOCAL_ADV_BIT) { + if (tag & BT_MESH_LOCAL_ADV) { return "local adv"; - } else if (tags & BT_MESH_PROXY_ADV_BIT) { + } else if (tag & BT_MESH_PROXY_ADV) { return "proxy adv"; - } else if (tags & BT_MESH_RELAY_ADV_BIT) { + } else if (tag & BT_MESH_RELAY_ADV) { return "relay adv"; - } else if (tags & BT_MESH_FRIEND_ADV_BIT) { + } else if (tag & BT_MESH_FRIEND_ADV) { return "friend adv"; } else { - return "(unknown tags)"; + return "(unknown tag)"; } } @@ -289,8 +289,8 @@ static void send_pending_adv(struct k_work *work) */ int64_t duration = k_uptime_delta(&adv->timestamp); - LOG_DBG("Advertising stopped after %u ms for (%u) %s", (uint32_t)duration, adv->tags, - adv_tag_to_str(adv->tags)); + LOG_DBG("Advertising stopped after %u ms for (%u) %s", (uint32_t)duration, adv->tag, + adv_tag_to_str(adv->tag)); atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(adv->flags, ADV_FLAG_PROXY); @@ -308,7 +308,7 @@ static void send_pending_adv(struct k_work *work) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULED); - while ((buf = bt_mesh_adv_buf_get_by_tag(adv->tags, K_NO_WAIT))) { + while ((buf = bt_mesh_adv_buf_get_by_tag(adv->tag, K_NO_WAIT))) { /* busy == 0 means this was canceled */ if (!BT_MESH_ADV(buf)->busy) { net_buf_unref(buf); @@ -326,7 +326,7 @@ static void send_pending_adv(struct k_work *work) } if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || - !(adv->tags & BT_MESH_RELAY_ADV_BIT)) { + !(adv->tag & BT_MESH_PROXY_ADV)) { return; } @@ -369,8 +369,8 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); - if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && adv->tags & BT_MESH_FRIEND_ADV_BIT) || - (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_RELAY_ADV_BIT)) { + if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && adv->tag & BT_MESH_FRIEND_ADV) || + (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tag == BT_MESH_RELAY_ADV)) { k_work_reschedule(&adv->work, K_NO_WAIT); } else { /* The controller will send the next advertisement immediately. diff --git a/subsys/bluetooth/mesh/statistic.c b/subsys/bluetooth/mesh/statistic.c index 046fa3c0eeb..5b1ffe7e0f5 100644 --- a/subsys/bluetooth/mesh/statistic.c +++ b/subsys/bluetooth/mesh/statistic.c @@ -24,22 +24,22 @@ void bt_mesh_stat_reset(void) void bt_mesh_stat_planned_count(struct bt_mesh_adv *adv) { - if (adv->tag == BT_MESH_LOCAL_ADV) { + if (adv->tag & BT_MESH_LOCAL_ADV) { stat.tx_local_planned++; - } else if (adv->tag == BT_MESH_RELAY_ADV) { + } else if (adv->tag & BT_MESH_RELAY_ADV) { stat.tx_adv_relay_planned++; - } else if (adv->tag == BT_MESH_FRIEND_ADV) { + } else if (adv->tag & BT_MESH_FRIEND_ADV) { stat.tx_friend_planned++; } } void bt_mesh_stat_succeeded_count(struct bt_mesh_adv *adv) { - if (adv->tag == BT_MESH_LOCAL_ADV) { + if (adv->tag & BT_MESH_LOCAL_ADV) { stat.tx_local_succeeded++; - } else if (adv->tag == BT_MESH_RELAY_ADV) { + } else if (adv->tag & BT_MESH_RELAY_ADV) { stat.tx_adv_relay_succeeded++; - } else if (adv->tag == BT_MESH_FRIEND_ADV) { + } else if (adv->tag & BT_MESH_FRIEND_ADV) { stat.tx_friend_succeeded++; } } From 2a3c5ddd0c259d34b8b984d43a137bee004a170b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:30 +0000 Subject: [PATCH 0562/1623] Revert "[nrf fromlist] net: iface: Introduce TX mutex locking" This reverts commit 9ed7de1afad3ebc08a3ce379bee0bbbbd9702414. Signed-off-by: Dominik Ermel --- include/zephyr/net/net_if.h | 29 ----------------------------- subsys/net/ip/net_if.c | 3 --- subsys/net/l2/ethernet/arp.c | 2 -- 3 files changed, 34 deletions(-) diff --git a/include/zephyr/net/net_if.h b/include/zephyr/net/net_if.h index 92a59ad3b73..b06bf74de03 100644 --- a/include/zephyr/net/net_if.h +++ b/include/zephyr/net/net_if.h @@ -212,9 +212,6 @@ enum net_if_flag { /** IPv6 Multicast Listener Discovery disabled. */ NET_IF_IPV6_NO_MLD, - /** Mutex locking on TX data path disabled on the interface. */ - NET_IF_NO_TX_LOCK, - /** @cond INTERNAL_HIDDEN */ /* Total number of flags - must be at the end of the enum */ NET_IF_NUM_FLAGS @@ -616,7 +613,6 @@ struct net_if { #endif struct k_mutex lock; - struct k_mutex tx_lock; }; static inline void net_if_lock(struct net_if *iface) @@ -633,31 +629,6 @@ static inline void net_if_unlock(struct net_if *iface) k_mutex_unlock(&iface->lock); } -static inline bool net_if_flag_is_set(struct net_if *iface, - enum net_if_flag value); - -static inline void net_if_tx_lock(struct net_if *iface) -{ - NET_ASSERT(iface); - - if (net_if_flag_is_set(iface, NET_IF_NO_TX_LOCK)) { - return; - } - - (void)k_mutex_lock(&iface->tx_lock, K_FOREVER); -} - -static inline void net_if_tx_unlock(struct net_if *iface) -{ - NET_ASSERT(iface); - - if (net_if_flag_is_set(iface, NET_IF_NO_TX_LOCK)) { - return; - } - - k_mutex_unlock(&iface->tx_lock); -} - /** * @brief Set a value in network interface flags * diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 026eaa88b48..035e18da74f 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -265,9 +265,7 @@ static bool net_if_tx(struct net_if *iface, struct net_pkt *pkt) } } - net_if_tx_lock(iface); status = net_if_l2(iface)->send(iface, pkt); - net_if_tx_unlock(iface); if (IS_ENABLED(CONFIG_NET_PKT_TXTIME_STATS)) { uint32_t end_tick = k_cycle_get_32(); @@ -439,7 +437,6 @@ static inline void init_iface(struct net_if *iface) #endif k_mutex_init(&iface->lock); - k_mutex_init(&iface->tx_lock); api->init(iface); } diff --git a/subsys/net/l2/ethernet/arp.c b/subsys/net/l2/ethernet/arp.c index 39a06ed64a0..35a2ec63a64 100644 --- a/subsys/net/l2/ethernet/arp.c +++ b/subsys/net/l2/ethernet/arp.c @@ -534,9 +534,7 @@ static void arp_update(struct net_if *iface, * the pkt are not counted twice and the packet filter * callbacks are only called once. */ - net_if_tx_lock(iface); ret = net_if_l2(iface)->send(iface, pkt); - net_if_tx_unlock(iface); if (ret < 0) { net_pkt_unref(pkt); } From 17a42452a6f7f4a437377636b4f90ae86f1f7a96 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:30 +0000 Subject: [PATCH 0563/1623] Revert "[nrf fromtree] net: arp: Directly send the queued pkt" This reverts commit a707fc77ef2d80ce5f4bed6e5c9bdd6bc0cc3912. Signed-off-by: Dominik Ermel --- subsys/net/l2/ethernet/arp.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/subsys/net/l2/ethernet/arp.c b/subsys/net/l2/ethernet/arp.c index 35a2ec63a64..f26c2f7ba96 100644 --- a/subsys/net/l2/ethernet/arp.c +++ b/subsys/net/l2/ethernet/arp.c @@ -514,8 +514,6 @@ static void arp_update(struct net_if *iface, sys_slist_prepend(&arp_table, &entry->node); while (!k_fifo_is_empty(&entry->pending_queue)) { - int ret; - pkt = k_fifo_get(&entry->pending_queue, K_FOREVER); /* Set the dst in the pending packet */ @@ -527,17 +525,7 @@ static void arp_update(struct net_if *iface, net_sprint_ipv4_addr(&entry->ip), pkt, pkt->frags); - /* We directly send the packet without first queueing it. - * The pkt has already been queued for sending, once by - * net_if and second time in the ARP queue. We must not - * queue it twice in net_if so that the statistics of - * the pkt are not counted twice and the packet filter - * callbacks are only called once. - */ - ret = net_if_l2(iface)->send(iface, pkt); - if (ret < 0) { - net_pkt_unref(pkt); - } + net_if_queue_tx(iface, pkt); } k_mutex_unlock(&arp_mutex); From 735fc1ef566dab86284cf9f71737ddc8ac747d21 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:30 +0000 Subject: [PATCH 0564/1623] Revert "[nrf fromtree] net: Remove unnecessary lock" This reverts commit 2a8c218f530fcc80ef3209ca49d36dc7a68d2b59. Signed-off-by: Dominik Ermel --- subsys/net/ip/net_if.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 035e18da74f..828e48ecf78 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -448,6 +448,8 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt) enum net_verdict verdict = NET_OK; int status = -EIO; + net_if_lock(iface); + if (!net_if_flag_is_set(iface, NET_IF_LOWER_UP) || net_if_flag_is_set(iface, NET_IF_SUSPENDED)) { /* Drop packet if interface is not up */ @@ -530,6 +532,8 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt) net_if_queue_tx(iface, pkt); } + net_if_unlock(iface); + return verdict; } From c755dc0f0ae81bee520f57398386f1a40c8172a9 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:31 +0000 Subject: [PATCH 0565/1623] Revert "[nrf fromtree] doc: gsg: macOS: Include instructions to add homebrew to the path" This reverts commit 196bab5029e3217952429c58f38a2be656dfee94. Signed-off-by: Dominik Ermel --- doc/develop/getting_started/index.rst | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/doc/develop/getting_started/index.rst b/doc/develop/getting_started/index.rst index f7a76a71585..4a1b345ee62 100644 --- a/doc/develop/getting_started/index.rst +++ b/doc/develop/getting_started/index.rst @@ -118,32 +118,12 @@ The current minimum required version for the main dependencies are: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - #. After the Homebrew installation script completes, follow the on-screen - instructions to add the Homebrew installation to the path. - - * On macOS running on Apple Silicon, this is achieved with: - - .. code-block:: bash - - (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile - source ~/.zprofile - - * On macOS running on Intel, use the command for Apple Silicon, but replace ``/opt/homebrew/`` with ``/usr/local/``. - #. Use ``brew`` to install the required dependencies: .. code-block:: bash brew install cmake ninja gperf python3 ccache qemu dtc wget libmagic - #. Add the Homebrew Python folder to the path, in order to be able to - execute ``python`` and ``pip`` as well ``python3`` and ``pip3``. - - .. code-block:: bash - - (echo; echo 'export PATH="'$(brew --prefix)'/opt/python/libexec/bin:$PATH"') >> ~/.zprofile - source ~/.zprofile - .. group-tab:: Windows .. note:: From dabcf79b4eec5cb5ace667bc7e936ec981783aca Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:31 +0000 Subject: [PATCH 0566/1623] Revert "[nrf fromtree] twister: pytest: Improve reporting failed pytest scenarios" This reverts commit ac5a9860b73bdbde2e8ba936fdc35a5e7654189c. Signed-off-by: Dominik Ermel --- .../device/hardware_adapter.py | 1 + scripts/pylib/twister/twisterlib/harness.py | 2 -- scripts/pylib/twister/twisterlib/reports.py | 5 +--- scripts/pylib/twister/twisterlib/runner.py | 26 ++++--------------- .../pytest_integration/test_harness_pytest.py | 2 -- 5 files changed, 7 insertions(+), 29 deletions(-) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py index 3b7bf5d8214..403978eed9a 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py @@ -116,6 +116,7 @@ def _flash_and_run(self) -> None: stdout_decoded = stdout.decode(errors='ignore') with open(self.device_log_path, 'a+') as log_file: log_file.write(stdout_decoded) + logger.debug(f'Flashing output:\n{stdout_decoded}') if self.device_config.post_flash_script: self._run_custom_script(self.device_config.post_flash_script, self.base_timeout) if process is not None and process.returncode == 0: diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index bd86df1b4df..951a8c40010 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -400,10 +400,8 @@ def _parse_report_file(self, report): if elem_ts := root.find('testsuite'): if elem_ts.get('failures') != '0': self.state = 'failed' - self.instance.reason = f"{elem_ts.get('failures')}/{elem_ts.get('tests')} pytest scenario(s) failed" elif elem_ts.get('errors') != '0': self.state = 'error' - self.instance.reason = 'Error during pytest execution' elif elem_ts.get('skipped') == elem_ts.get('tests'): self.state = 'skipped' else: diff --git a/scripts/pylib/twister/twisterlib/reports.py b/scripts/pylib/twister/twisterlib/reports.py index be1bbb4dbd7..c1f160caad9 100644 --- a/scripts/pylib/twister/twisterlib/reports.py +++ b/scripts/pylib/twister/twisterlib/reports.py @@ -246,7 +246,6 @@ def json_report(self, filename, version="NA"): for instance in self.instances.values(): suite = {} handler_log = os.path.join(instance.build_dir, "handler.log") - pytest_log = os.path.join(instance.build_dir, "twister_harness.log") build_log = os.path.join(instance.build_dir, "build.log") device_log = os.path.join(instance.build_dir, "device.log") @@ -285,9 +284,7 @@ def json_report(self, filename, version="NA"): suite['status'] = instance.status suite["reason"] = instance.reason # FIXME - if os.path.exists(pytest_log): - suite["log"] = self.process_log(pytest_log) - elif os.path.exists(handler_log): + if os.path.exists(handler_log): suite["log"] = self.process_log(handler_log) elif os.path.exists(device_log): suite["log"] = self.process_log(device_log) diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index 4dbdb21f882..ef41084cdd4 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -40,9 +40,6 @@ from twisterlib.log_helper import log_command from twisterlib.testinstance import TestInstance -from twisterlib.environment import TwisterEnv -from twisterlib.testsuite import TestSuite -from twisterlib.platform import Platform from twisterlib.testplan import change_skip_to_error_if_integration from twisterlib.harness import HarnessImporter, Pytest @@ -223,7 +220,7 @@ class CMake: config_re = re.compile('(CONFIG_[A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$') dt_re = re.compile('([A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$') - def __init__(self, testsuite: TestSuite, platform: Platform, source_dir, build_dir, jobserver): + def __init__(self, testsuite, platform, source_dir, build_dir, jobserver): self.cwd = None self.capture_output = True @@ -417,7 +414,7 @@ def run_cmake(self, args="", filter_stages=[]): class FilterBuilder(CMake): - def __init__(self, testsuite: TestSuite, platform: Platform, source_dir, build_dir, jobserver): + def __init__(self, testsuite, platform, source_dir, build_dir, jobserver): super().__init__(testsuite, platform, source_dir, build_dir, jobserver) self.log = "config-twister.log" @@ -520,7 +517,7 @@ def parse_generated(self, filter_stages=[]): class ProjectBuilder(FilterBuilder): - def __init__(self, instance: TestInstance, env: TwisterEnv, jobserver, **kwargs): + def __init__(self, instance, env, jobserver, **kwargs): super().__init__(instance.testsuite, instance.platform, instance.testsuite.source_dir, instance.build_dir, jobserver) self.log = "build.log" @@ -530,7 +527,8 @@ def __init__(self, instance: TestInstance, env: TwisterEnv, jobserver, **kwargs) self.env = env self.duts = None - def log_info(self, filename, inline_logs, log_testcases=False): + @staticmethod + def log_info(filename, inline_logs): filename = os.path.abspath(os.path.realpath(filename)) if inline_logs: logger.info("{:-^100}".format(filename)) @@ -544,17 +542,6 @@ def log_info(self, filename, inline_logs, log_testcases=False): logger.error(data) logger.info("{:-^100}".format(filename)) - - if log_testcases: - for tc in self.instance.testcases: - if not tc.reason: - continue - logger.info( - f"\n{str(tc.name).center(100, '_')}\n" - f"{tc.reason}\n" - f"{100*'_'}\n" - f"{tc.output}" - ) else: logger.error("see: " + Fore.YELLOW + filename + Fore.RESET) @@ -564,12 +551,9 @@ def log_info_file(self, inline_logs): b_log = "{}/build.log".format(build_dir) v_log = "{}/valgrind.log".format(build_dir) d_log = "{}/device.log".format(build_dir) - pytest_log = "{}/twister_harness.log".format(build_dir) if os.path.exists(v_log) and "Valgrind" in self.instance.reason: self.log_info("{}".format(v_log), inline_logs) - elif os.path.exists(pytest_log) and os.path.getsize(pytest_log) > 0: - self.log_info("{}".format(pytest_log), inline_logs, log_testcases=True) elif os.path.exists(h_log) and os.path.getsize(h_log) > 0: self.log_info("{}".format(h_log), inline_logs) elif os.path.exists(d_log) and os.path.getsize(d_log) > 0: diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index 150980059b3..ab4baf88656 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -188,8 +188,6 @@ def test_err(): assert tc.status == "failed" assert tc.output assert tc.reason - assert testinstance.reason - assert '2/2' in testinstance.reason def test_if_report_with_skip(pytester, testinstance: TestInstance): From ca92a3b99bd4ba58f3974efb9abcb2ddbb3ce937 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:31 +0000 Subject: [PATCH 0567/1623] Revert "[nrf fromtree] twister: pytest: Parametrize scope of the dut fixture" This reverts commit 8186e5cf7cf25d3586896060730eddd6145589c5. Signed-off-by: Dominik Ermel --- doc/develop/test/pytest.rst | 9 ++------- doc/develop/test/twister.rst | 5 ----- .../src/twister_harness/fixtures.py | 13 ++++--------- .../src/twister_harness/plugin.py | 5 ----- scripts/pylib/twister/twisterlib/harness.py | 5 +---- scripts/schemas/twister/testsuite-schema.yaml | 8 -------- .../pytest_integration/test_harness_pytest.py | 19 ------------------- 7 files changed, 7 insertions(+), 57 deletions(-) diff --git a/doc/develop/test/pytest.rst b/doc/develop/test/pytest.rst index 087c45bcce8..d0fad4d6be6 100644 --- a/doc/develop/test/pytest.rst +++ b/doc/develop/test/pytest.rst @@ -69,9 +69,6 @@ DUT (initialize logging, flash device, connect serial etc). This fixture yields a device prepared according to the requested type (native posix, qemu, hardware, etc.). All types of devices share the same API. This allows for writing tests which are device-type-agnostic. -Scope of this fixture is determined by the ``pytest_dut_scope`` -keyword placed under ``harness_config`` section. - .. code-block:: python @@ -84,10 +81,8 @@ shell ----- Provide an object with methods used to interact with shell application. -It calls ``wait_for_promt`` method, to not start scenario until DUT is ready. -Note that it uses ``dut`` fixture, so ``dut`` can be skipped when ``shell`` is used. -Scope of this fixture is determined by the ``pytest_dut_scope`` -keyword placed under ``harness_config`` section. +It calls `wait_for_promt` method, to not start scenario until DUT is ready. +Note that it uses `dut` fixture, so `dut` can be skipped when `shell` is used. .. code-block:: python diff --git a/doc/develop/test/twister.rst b/doc/develop/test/twister.rst index a61744eec6d..4456386b77c 100644 --- a/doc/develop/test/twister.rst +++ b/doc/develop/test/twister.rst @@ -501,11 +501,6 @@ harness_config: pytest_args: (default empty) Specify a list of additional arguments to pass to ``pytest``. - pytest_dut_scope: (default function) - The scope for which ``dut`` and ``shell`` pytest fixtures are shared. - If the scope is set to ``function``, DUT is launched for every test case - in python script. For ``session`` scope, DUT is launched only once. - robot_test_path: (default empty) Specify a path to a file containing a Robot Framework test suite to be run. diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py index f2b1b53706c..e2e82674ada 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py @@ -36,16 +36,11 @@ def device_object(twister_harness_config: TwisterHarnessConfig) -> Generator[Dev device_object.close() -def determine_scope(fixture_name, config): - if dut_scope := config.getoption("--dut-scope", None): - return dut_scope - return 'function' - - -@pytest.fixture(scope=determine_scope) +@pytest.fixture(scope='function') def dut(request: pytest.FixtureRequest, device_object: DeviceAdapter) -> Generator[DeviceAdapter, None, None]: """Return launched device - with run application.""" - device_object.initialize_log_files(request.node.name) + test_name = request.node.name + device_object.initialize_log_files(test_name) try: device_object.launch() yield device_object @@ -53,7 +48,7 @@ def dut(request: pytest.FixtureRequest, device_object: DeviceAdapter) -> Generat device_object.close() -@pytest.fixture(scope=determine_scope) +@pytest.fixture(scope='function') def shell(dut: DeviceAdapter) -> Shell: """Return ready to use shell interface""" shell = Shell(dut, timeout=20.0) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py index dbd3465aba1..076d36d4cc9 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py @@ -100,11 +100,6 @@ def pytest_addoption(parser: pytest.Parser): metavar='PATH', help='Script executed after closing serial connection.' ) - twister_harness_group.addoption( - '--dut-scope', - choices=('function', 'class', 'module', 'package', 'session'), - help='The scope for which `dut` and `shell` fixtures are shared.' - ) def pytest_configure(config: pytest.Config): diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index 951a8c40010..6ae2622c810 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -247,7 +247,6 @@ def generate_command(self): config = self.instance.testsuite.harness_config pytest_root = config.get('pytest_root', ['pytest']) if config else ['pytest'] pytest_args = config.get('pytest_args', []) if config else [] - pytest_dut_scope = config.get('pytest_dut_scope', None) if config else None command = [ 'pytest', '--twister-harness', @@ -261,8 +260,6 @@ def generate_command(self): command.extend([os.path.normpath(os.path.join( self.source_dir, os.path.expanduser(os.path.expandvars(src)))) for src in pytest_root]) command.extend(pytest_args) - if pytest_dut_scope: - command.append(f'--dut-scope={pytest_dut_scope}') handler: Handler = self.instance.handler @@ -409,7 +406,7 @@ def _parse_report_file(self, report): self.instance.execution_time = float(elem_ts.get('time')) for elem_tc in elem_ts.findall('testcase'): - tc = self.instance.add_testcase(f"{self.id}.{elem_tc.get('name')}") + tc = self.instance.get_case_or_create(f"{self.id}.{elem_tc.get('name')}") tc.duration = float(elem_tc.get('time')) elem = elem_tc.find('*') if elem is None: diff --git a/scripts/schemas/twister/testsuite-schema.yaml b/scripts/schemas/twister/testsuite-schema.yaml index 1e198173c72..96a121767a5 100644 --- a/scripts/schemas/twister/testsuite-schema.yaml +++ b/scripts/schemas/twister/testsuite-schema.yaml @@ -104,10 +104,6 @@ mapping: required: false sequence: - type: str - "pytest_dut_scope": - type: str - enum: ["function", "class", "module", "package", "session"] - required: false "regex": type: seq required: false @@ -308,10 +304,6 @@ mapping: required: false sequence: - type: str - "pytest_dut_scope": - type: str - enum: ["function", "class", "module", "package", "session"] - required: false "regex": type: seq required: false diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index ab4baf88656..e1b27a0cf02 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -48,25 +48,6 @@ def test_pytest_command(testinstance: TestInstance, device_type): assert c in command -def test_pytest_command_dut_scope(testinstance: TestInstance): - pytest_harness = Pytest() - dut_scope = 'session' - testinstance.testsuite.harness_config['pytest_dut_scope'] = dut_scope - pytest_harness.configure(testinstance) - command = pytest_harness.generate_command() - assert f'--dut-scope={dut_scope}' in command - - -def test_pytest_command_extra_args(testinstance: TestInstance): - pytest_harness = Pytest() - pytest_args = ['-k test1', '-m mark1'] - testinstance.testsuite.harness_config['pytest_args'] = pytest_args - pytest_harness.configure(testinstance) - command = pytest_harness.generate_command() - for c in pytest_args: - assert c in command - - @pytest.mark.parametrize( ('pytest_root', 'expected'), [ From 9f7a516ca14049980948cea8dec827d45462c98d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:31 +0000 Subject: [PATCH 0568/1623] Revert "[nrf fromtree] twister: pytest: Move fixtures to one file" This reverts commit 4a05f790ba8345cc348c2ca2f7fcf84dfa983e8d. Signed-off-by: Dominik Ermel --- .../pytest/shell/pytest/test_shell.py | 12 +++++++++- .../src/twister_harness/__init__.py | 2 +- .../src/twister_harness/fixtures/__init__.py | 8 +++++++ .../{fixtures.py => fixtures/dut.py} | 22 ------------------- .../{helpers => fixtures}/mcumgr.py | 16 ++++++++++++++ .../src/twister_harness/plugin.py | 3 ++- .../tests/fixtures/mcumgr_fixture_test.py | 4 ++-- 7 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/__init__.py rename scripts/pylib/pytest-twister-harness/src/twister_harness/{fixtures.py => fixtures/dut.py} (72%) rename scripts/pylib/pytest-twister-harness/src/twister_harness/{helpers => fixtures}/mcumgr.py (88%) diff --git a/samples/subsys/testsuite/pytest/shell/pytest/test_shell.py b/samples/subsys/testsuite/pytest/shell/pytest/test_shell.py index 84d16ec1e5a..37efa74795b 100755 --- a/samples/subsys/testsuite/pytest/shell/pytest/test_shell.py +++ b/samples/subsys/testsuite/pytest/shell/pytest/test_shell.py @@ -4,11 +4,21 @@ import logging -from twister_harness import Shell +import pytest +from twister_harness import DeviceAdapter, Shell logger = logging.getLogger(__name__) +@pytest.fixture(scope='function') +def shell(dut: DeviceAdapter) -> Shell: + """Return ready to use shell interface""" + shell = Shell(dut, timeout=20.0) + logger.info('wait for prompt') + assert shell.wait_for_prompt() + return shell + + def test_shell_print_help(shell: Shell): logger.info('send "help" command') lines = shell.exec_command('help') diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/__init__.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/__init__.py index 4897e2cf391..251c5deb672 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/__init__.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/__init__.py @@ -5,7 +5,7 @@ # flake8: noqa from twister_harness.device.device_adapter import DeviceAdapter -from twister_harness.helpers.mcumgr import MCUmgr +from twister_harness.fixtures.mcumgr import MCUmgr from twister_harness.helpers.shell import Shell __all__ = ['DeviceAdapter', 'MCUmgr', 'Shell'] diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/__init__.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/__init__.py new file mode 100644 index 00000000000..ed61bf17b1c --- /dev/null +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/__init__.py @@ -0,0 +1,8 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +import pytest + +pytest.register_assert_rewrite('twister_harness.fixtures.dut') +pytest.register_assert_rewrite('twister_harness.fixtures.mcumgr') diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/dut.py similarity index 72% rename from scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py rename to scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/dut.py index e2e82674ada..0f34c05b252 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/dut.py @@ -10,8 +10,6 @@ from twister_harness.device.device_adapter import DeviceAdapter from twister_harness.device.factory import DeviceFactory from twister_harness.twister_harness_config import DeviceConfig, TwisterHarnessConfig -from twister_harness.helpers.shell import Shell -from twister_harness.helpers.mcumgr import MCUmgr logger = logging.getLogger(__name__) @@ -46,23 +44,3 @@ def dut(request: pytest.FixtureRequest, device_object: DeviceAdapter) -> Generat yield device_object finally: # to make sure we close all running processes execution device_object.close() - - -@pytest.fixture(scope='function') -def shell(dut: DeviceAdapter) -> Shell: - """Return ready to use shell interface""" - shell = Shell(dut, timeout=20.0) - logger.info('Wait for prompt') - assert shell.wait_for_prompt() - return shell - - -@pytest.fixture(scope='session') -def is_mcumgr_available() -> None: - if not MCUmgr.is_available(): - pytest.skip('mcumgr not available') - - -@pytest.fixture() -def mcumgr(is_mcumgr_available: None, dut: DeviceAdapter) -> Generator[MCUmgr, None, None]: - yield MCUmgr.create_for_serial(dut.device_config.serial) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/mcumgr.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/mcumgr.py similarity index 88% rename from scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/mcumgr.py rename to scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/mcumgr.py index b6cab6475c1..e0d85893792 100755 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/mcumgr.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures/mcumgr.py @@ -3,14 +3,19 @@ # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations +import pytest import logging import re import shlex +from typing import Generator from subprocess import check_output, getstatusoutput from pathlib import Path from dataclasses import dataclass +from twister_harness.device.device_adapter import DeviceAdapter + + logger = logging.getLogger(__name__) @@ -103,3 +108,14 @@ def image_confirm(self, hash: str | None = None): image_list = self.get_image_list() hash = image_list[0].hash self.run_command(f'image confirm {hash}') + + +@pytest.fixture(scope='session') +def is_mcumgr_available() -> None: + if not MCUmgr.is_available(): + pytest.skip('mcumgr not available') + + +@pytest.fixture() +def mcumgr(is_mcumgr_available: None, dut: DeviceAdapter) -> Generator[MCUmgr, None, None]: + yield MCUmgr.create_for_serial(dut.device_config.serial) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py index 076d36d4cc9..59bec12955d 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/plugin.py @@ -14,7 +14,8 @@ logger = logging.getLogger(__name__) pytest_plugins = ( - 'twister_harness.fixtures' + 'twister_harness.fixtures.dut', + 'twister_harness.fixtures.mcumgr' ) diff --git a/scripts/pylib/pytest-twister-harness/tests/fixtures/mcumgr_fixture_test.py b/scripts/pylib/pytest-twister-harness/tests/fixtures/mcumgr_fixture_test.py index f336311143a..f294adba30a 100644 --- a/scripts/pylib/pytest-twister-harness/tests/fixtures/mcumgr_fixture_test.py +++ b/scripts/pylib/pytest-twister-harness/tests/fixtures/mcumgr_fixture_test.py @@ -6,7 +6,7 @@ import textwrap from unittest import mock -from twister_harness.helpers.mcumgr import MCUmgr, MCUmgrException +from twister_harness.fixtures.mcumgr import MCUmgr, MCUmgrException @pytest.fixture(name='mcumgr') @@ -14,7 +14,7 @@ def fixture_mcumgr() -> MCUmgr: return MCUmgr.create_for_serial('SERIAL_PORT') -@mock.patch('twister_harness.helpers.mcumgr.MCUmgr.run_command', return_value='') +@mock.patch('twister_harness.fixtures.mcumgr.MCUmgr.run_command', return_value='') def test_if_mcumgr_fixture_generate_proper_command( patched_run_command: mock.Mock, mcumgr: MCUmgr ) -> None: From 01081ad4a295ed1724e456fe0a30dcfc5fa336e4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:31 +0000 Subject: [PATCH 0569/1623] Revert "[nrf noup] ci: Add CI-run-zephyr-twister test spec" This reverts commit ede86123951b7f824f91f6ebd1ea15f307f9a208. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 789f1a4e235..007f4307aa9 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -1,19 +1,4 @@ # This is the Jenkins ci variant of the .github/labler.yaml - -"CI-run-zephyr-twister": - - any: - - "!.github/**/*" - - "!doc/**/*" - - "!CODEOWNERS" - - "!LICENSE" - - "!**/*.rst" - - "!VERSION" - - "!submanifests/**/*" - - "!MAINTAINERS.yml" - - "!version.h.in" - - "!Jenkinsfile" - - "!**/*.md" - "CI-iot-zephyr-lwm2m-test": - "drivers/console/**/*" - "drivers/flash/**/*" From 75374c44374a2f1d1fcb2432ab67c7686f79badd Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:32 +0000 Subject: [PATCH 0570/1623] Revert "[nrf fromtree] Bluetooth: HCI: Add bt_hci_get_ver_str()" This reverts commit 2b912a70f905022a1ef891161b5f6c977980c87a. Signed-off-by: Dominik Ermel --- include/zephyr/bluetooth/hci.h | 13 ------------- subsys/bluetooth/host/hci_core.c | 10 +++++----- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/include/zephyr/bluetooth/hci.h b/include/zephyr/bluetooth/hci.h index 258f86519b6..8dd7434e445 100644 --- a/include/zephyr/bluetooth/hci.h +++ b/include/zephyr/bluetooth/hci.h @@ -97,19 +97,6 @@ int bt_hci_get_conn_handle(const struct bt_conn *conn, uint16_t *conn_handle); */ int bt_hci_get_adv_handle(const struct bt_le_ext_adv *adv, uint8_t *adv_handle); -/** @brief Obtain the version string given a core version number. - * - * The core version of a controller can be obtained by issuing - * the HCI Read Local Version Information command. - * - * See also the defines prefixed with BT_HCI_VERSION_. - * - * @param core_version The core version. - * - * @return Version string corresponding to the core version number. - */ -const char *bt_hci_get_ver_str(uint8_t core_version); - /** @typedef bt_hci_vnd_evt_cb_t * @brief Callback type for vendor handling of HCI Vendor-Specific Events. * diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 7cf699aa8cc..40e1b44e960 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -3459,15 +3459,15 @@ static int set_event_mask(void) return bt_hci_cmd_send_sync(BT_HCI_OP_SET_EVENT_MASK, buf, NULL); } -const char *bt_hci_get_ver_str(uint8_t core_version) +static const char *ver_str(uint8_t ver) { const char * const str[] = { "1.0b", "1.1", "1.2", "2.0", "2.1", "3.0", "4.0", "4.1", "4.2", "5.0", "5.1", "5.2", "5.3", "5.4" }; - if (core_version < ARRAY_SIZE(str)) { - return str[core_version]; + if (ver < ARRAY_SIZE(str)) { + return str[ver]; } return "unknown"; @@ -3508,9 +3508,9 @@ static void bt_dev_show_info(void) } LOG_INF("HCI: version %s (0x%02x) revision 0x%04x, manufacturer 0x%04x", - bt_hci_get_ver_str(bt_dev.hci_version), bt_dev.hci_version, bt_dev.hci_revision, + ver_str(bt_dev.hci_version), bt_dev.hci_version, bt_dev.hci_revision, bt_dev.manufacturer); - LOG_INF("LMP: version %s (0x%02x) subver 0x%04x", bt_hci_get_ver_str(bt_dev.lmp_version), + LOG_INF("LMP: version %s (0x%02x) subver 0x%04x", ver_str(bt_dev.lmp_version), bt_dev.lmp_version, bt_dev.lmp_subversion); } From e20e3707f80bd497e6eb720f4639049614d08c17 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:32 +0000 Subject: [PATCH 0571/1623] Revert "[nrf fromtree] scripts: Add test_plan.py to twister_ignore.txt" This reverts commit ac573c04413a1f16faf2a3b63936b0e91720820a. Signed-off-by: Dominik Ermel --- scripts/ci/twister_ignore.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/ci/twister_ignore.txt b/scripts/ci/twister_ignore.txt index fb267ed81f7..4a0589f291c 100644 --- a/scripts/ci/twister_ignore.txt +++ b/scripts/ci/twister_ignore.txt @@ -24,7 +24,6 @@ doc/* *.md # if we change this file or associated script, it should not trigger a full # twister. -scripts/ci/test_plan.py scripts/ci/twister_ignore.txt scripts/ci/what_changed.py scripts/ci/version_mgr.py From ff9983818e48d88995e623eae647d118441bda9b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:32 +0000 Subject: [PATCH 0572/1623] Revert "[nrf fromtree] twister: bugfix: Fix infinite loop in test_plan.py script" This reverts commit d8af055fc8c45815beaae06947d1625011451c88. Signed-off-by: Dominik Ermel --- scripts/ci/test_plan.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 21cac8e4914..a308abe63ab 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -284,8 +284,6 @@ def find_tests(self): tests.add(os.path.dirname(yaml)) self.resolved_files.append(f) scope_found = True - else: - d = os.path.dirname(d) else: d = os.path.dirname(d) From 22c65ddabe5e0c033b27bb0b59977115b44e563c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:33 +0000 Subject: [PATCH 0573/1623] Revert "[nrf fromtree] scripts: Add workflow for "common" directories in find_tests()" This reverts commit 10ef01ba7924b88c6f3dc9d75409f679486eb4ba. Signed-off-by: Dominik Ermel --- scripts/ci/test_plan.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index a308abe63ab..234d1302731 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -12,7 +12,6 @@ import json import logging import sys -import glob from pathlib import Path from git import Repo from west.manifest import Manifest @@ -265,25 +264,13 @@ def find_tests(self): if f.endswith(".rst"): continue d = os.path.dirname(f) - scope_found = False - while not scope_found and d: - head, tail = os.path.split(d) + while d: if os.path.exists(os.path.join(d, "testcase.yaml")) or \ os.path.exists(os.path.join(d, "sample.yaml")): tests.add(d) # Modified file is treated as resolved, since a matching scope was found self.resolved_files.append(f) - scope_found = True - elif tail == "common": - # Look for yamls in directories collocated with common - - yamls_found = [yaml for yaml in glob.iglob(head + '/**/testcase.yaml', recursive=True)] - yamls_found.extend([yaml for yaml in glob.iglob(head + '/**/sample.yaml', recursive=True)]) - if yamls_found: - for yaml in yamls_found: - tests.add(os.path.dirname(yaml)) - self.resolved_files.append(f) - scope_found = True + break else: d = os.path.dirname(d) From 998a991a0cb55c67ea3487ebbb611cff89365071 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:33 +0000 Subject: [PATCH 0574/1623] Revert "[nrf fromtree] scripts: Make workflow of test_plan.py script more robust" This reverts commit 158f0db91c3ab5455fb79e8fa3f07cb482c43b56. Signed-off-by: Dominik Ermel --- scripts/ci/test_plan.py | 39 ++++++++++++++--------------------- scripts/ci/twister_ignore.txt | 19 +++++++++++++++++ 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 234d1302731..1388250716f 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -97,13 +97,13 @@ def __init__(self, modified_files, ignore_path, alt_tags, testsuite_root, pull_request=False, platforms=[], detailed_test_id=True): self.modified_files = modified_files self.testsuite_root = testsuite_root - self.resolved_files = [] self.twister_options = [] self.full_twister = False self.all_tests = [] self.tag_options = [] self.pull_request = pull_request self.platforms = platforms + self.default_run = False self.detailed_test_id = detailed_test_id self.ignore_path = ignore_path self.tag_cfg_file = alt_tags @@ -115,7 +115,11 @@ def process(self): if not self.platforms: self.find_archs() self.find_boards() - self.find_excludes() + + if self.default_run: + self.find_excludes(skip=["tests/*", "boards/*/*/*"]) + else: + self.find_excludes() def get_plan(self, options, integration=False, use_testsuite_root=True): fname = "_test_plan_partial.json" @@ -196,8 +200,6 @@ def find_archs(self): archs.add('riscv64') else: archs.add(p.group(1)) - # Modified file is treated as resolved, since a matching scope was found - self.resolved_files.append(f) _options = [] for arch in archs: @@ -216,7 +218,6 @@ def find_archs(self): def find_boards(self): boards = set() all_boards = set() - resolved = [] for f in self.modified_files: if f.endswith(".rst") or f.endswith(".png") or f.endswith(".jpg"): @@ -224,7 +225,6 @@ def find_boards(self): p = re.match(r"^boards\/[^/]+\/([^/]+)\/", f) if p and p.groups(): boards.add(p.group(1)) - resolved.append(f) roots = [zephyr_base] if repository_path != zephyr_base: @@ -239,16 +239,10 @@ def find_boards(self): if name_re.search(kb.name): all_boards.add(kb.name) - # If modified file is catched by "find_boards" workflow (change in "boards" dir AND board recognized) - # it means a proper testing scope for this file was found and this file can be removed - # from further consideration - for board in all_boards: - self.resolved_files.extend(list(filter(lambda f: board in f, resolved))) - _options = [] if len(all_boards) > 20: logging.warning(f"{len(boards)} boards changed, this looks like a global change, skipping test handling, revert to default.") - self.full_twister = True + self.default_run = True return for board in all_boards: @@ -268,8 +262,6 @@ def find_tests(self): if os.path.exists(os.path.join(d, "testcase.yaml")) or \ os.path.exists(os.path.join(d, "sample.yaml")): tests.add(d) - # Modified file is treated as resolved, since a matching scope was found - self.resolved_files.append(f) break else: d = os.path.dirname(d) @@ -280,7 +272,7 @@ def find_tests(self): if len(tests) > 20: logging.warning(f"{len(tests)} tests changed, this looks like a global change, skipping test handling, revert to default") - self.full_twister = True + self.default_run = True return if _options: @@ -336,22 +328,21 @@ def find_excludes(self, skip=[]): ignores = filter(lambda x: not x.startswith("#"), ignores) found = set() - files_not_resolved = list(filter(lambda x: x not in self.resolved_files, self.modified_files)) + files = list(filter(lambda x: x, self.modified_files)) for pattern in ignores: + if pattern in skip: + continue if pattern: - found.update(fnmatch.filter(files_not_resolved, pattern)) + found.update(fnmatch.filter(files, pattern)) logging.debug(found) - logging.debug(files_not_resolved) + logging.debug(files) - # Full twister run can be ordered by detecting great number of tests/boards changed - # or if not all modified files were resolved (corresponding scope found) - self.full_twister = self.full_twister or sorted(files_not_resolved) != sorted(found) - - if self.full_twister: + if sorted(files) != sorted(found): _options = [] logging.info(f'Need to run full or partial twister...') + self.full_twister = True if self.platforms: for platform in self.platforms: _options.extend(["-p", platform]) diff --git a/scripts/ci/twister_ignore.txt b/scripts/ci/twister_ignore.txt index 4a0589f291c..59f735495ca 100644 --- a/scripts/ci/twister_ignore.txt +++ b/scripts/ci/twister_ignore.txt @@ -17,6 +17,25 @@ CODEOWNERS MAINTAINERS.yml LICENSE Makefile +tests/* +samples/* +boards/*/*/* +arch/xtensa/* +arch/x86/* +arch/posix/* +arch/arc/* +arch/sparc/* +arch/arm/* +arch/nios2/* +arch/riscv/* +include/arch/xtensa/* +include/arch/x86/* +include/arch/posix/* +include/arch/arc/* +include/arch/sparc/* +include/arch/arm/* +include/arch/nios2/* +include/arch/riscv/* doc/* # GH action have no impact on code .github/* From dccdde1cc7d482e464ee36078fd7c5bb1f30ae95 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:33 +0000 Subject: [PATCH 0575/1623] Revert "[nrf fromtree] scripts: Add arg to test_plan.py for alternative test locations" This reverts commit dfbb9972f240c1e55d4e84dcdb941f91af552ea0. Signed-off-by: Dominik Ermel --- scripts/ci/test_plan.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 1388250716f..6ee76b74aae 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -93,10 +93,8 @@ def __repr__(self): return "".format(self.name) class Filters: - def __init__(self, modified_files, ignore_path, alt_tags, testsuite_root, - pull_request=False, platforms=[], detailed_test_id=True): + def __init__(self, modified_files, ignore_path, alt_tags, pull_request=False, platforms=[], detailed_test_id=True): self.modified_files = modified_files - self.testsuite_root = testsuite_root self.twister_options = [] self.full_twister = False self.all_tests = [] @@ -121,14 +119,11 @@ def process(self): else: self.find_excludes() - def get_plan(self, options, integration=False, use_testsuite_root=True): + def get_plan(self, options, integration=False): fname = "_test_plan_partial.json" cmd = [f"{zephyr_base}/scripts/twister", "-c"] + options + ["--save-tests", fname ] if not self.detailed_test_id: cmd += ["--no-detailed-test-id"] - if self.testsuite_root and use_testsuite_root: - for root in self.testsuite_root: - cmd+=["-T", root] if integration: cmd.append("--integration") @@ -282,7 +277,7 @@ def find_tests(self): _options.extend(["-p", platform]) else: _options.append("--all") - self.get_plan(_options, use_testsuite_root=False) + self.get_plan(_options) def find_tags(self): @@ -385,12 +380,6 @@ def parse_args(): parser.add_argument('--alt-tags', default=os.path.join(zephyr_base, 'scripts', 'ci', 'tags.yaml'), help="Path to a file describing relations between directories and tags") - parser.add_argument( - "-T", "--testsuite-root", action="append", default=[], - help="Base directory to recursively search for test cases. All " - "testcase.yaml files under here will be processed. May be " - "called multiple times. Defaults to the 'samples/' and " - "'tests/' directories at the base of the Zephyr tree.") # Include paths in names by default. parser.set_defaults(detailed_test_id=True) @@ -418,8 +407,7 @@ def parse_args(): print("\n".join(files)) print("=========") - f = Filters(files, args.ignore_path, args.alt_tags, args.testsuite_root, - args.pull_request, args.platform, args.detailed_test_id) + f = Filters(files, args.ignore_path, args.alt_tags, args.pull_request, args.platform, args.detailed_test_id) f.process() # remove dupes and filtered cases From 9b069d53cf2c32ff2b1223e933c1622c31b24e75 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:33 +0000 Subject: [PATCH 0576/1623] Revert "[nrf fromtree] scripts: Add arg to set_plan.py for alternative tag relation list" This reverts commit bff52954a69905e162abbbb49045b81cf8e7bee1. Signed-off-by: Dominik Ermel --- scripts/ci/test_plan.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 6ee76b74aae..6ebcfc744bc 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -93,7 +93,7 @@ def __repr__(self): return "".format(self.name) class Filters: - def __init__(self, modified_files, ignore_path, alt_tags, pull_request=False, platforms=[], detailed_test_id=True): + def __init__(self, modified_files, ignore_path, pull_request=False, platforms=[], detailed_test_id=True): self.modified_files = modified_files self.twister_options = [] self.full_twister = False @@ -104,7 +104,6 @@ def __init__(self, modified_files, ignore_path, alt_tags, pull_request=False, pl self.default_run = False self.detailed_test_id = detailed_test_id self.ignore_path = ignore_path - self.tag_cfg_file = alt_tags def process(self): self.find_modules() @@ -281,7 +280,8 @@ def find_tests(self): def find_tags(self): - with open(self.tag_cfg_file, 'r') as ymlfile: + tag_cfg_file = os.path.join(zephyr_base, 'scripts', 'ci', 'tags.yaml') + with open(tag_cfg_file, 'r') as ymlfile: tags_config = yaml.safe_load(ymlfile) tags = {} @@ -377,9 +377,6 @@ def parse_args(): parser.add_argument('--ignore-path', default=os.path.join(zephyr_base, 'scripts', 'ci', 'twister_ignore.txt'), help="Path to a text file with patterns of files to be matched against changed files") - parser.add_argument('--alt-tags', - default=os.path.join(zephyr_base, 'scripts', 'ci', 'tags.yaml'), - help="Path to a file describing relations between directories and tags") # Include paths in names by default. parser.set_defaults(detailed_test_id=True) @@ -407,7 +404,7 @@ def parse_args(): print("\n".join(files)) print("=========") - f = Filters(files, args.ignore_path, args.alt_tags, args.pull_request, args.platform, args.detailed_test_id) + f = Filters(files, args.ignore_path, args.pull_request, args.platform, args.detailed_test_id) f.process() # remove dupes and filtered cases From a0319c5447d520791127c6f7c377c07a88e311ce Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:33 +0000 Subject: [PATCH 0577/1623] Revert "[nrf fromtree] scripts: Allow using alternative ignore-patters in test_plan.py" This reverts commit bd2c89e4a589eb0ad43c9a617d3308417b4ddda6. Signed-off-by: Dominik Ermel --- scripts/ci/test_plan.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 6ebcfc744bc..9a6f50f57d0 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -93,7 +93,7 @@ def __repr__(self): return "".format(self.name) class Filters: - def __init__(self, modified_files, ignore_path, pull_request=False, platforms=[], detailed_test_id=True): + def __init__(self, modified_files, pull_request=False, platforms=[], detailed_test_id=True): self.modified_files = modified_files self.twister_options = [] self.full_twister = False @@ -103,7 +103,6 @@ def __init__(self, modified_files, ignore_path, pull_request=False, platforms=[] self.platforms = platforms self.default_run = False self.detailed_test_id = detailed_test_id - self.ignore_path = ignore_path def process(self): self.find_modules() @@ -318,7 +317,7 @@ def find_tags(self): logging.info(f'Potential tag based filters: {exclude_tags}') def find_excludes(self, skip=[]): - with open(self.ignore_path, "r") as twister_ignore: + with open("scripts/ci/twister_ignore.txt", "r") as twister_ignore: ignores = twister_ignore.read().splitlines() ignores = filter(lambda x: not x.startswith("#"), ignores) @@ -374,9 +373,6 @@ def parse_args(): help="Don't put paths into tests' names.") parser.add_argument('-r', '--repo-to-scan', default=None, help="Repo to scan") - parser.add_argument('--ignore-path', - default=os.path.join(zephyr_base, 'scripts', 'ci', 'twister_ignore.txt'), - help="Path to a text file with patterns of files to be matched against changed files") # Include paths in names by default. parser.set_defaults(detailed_test_id=True) @@ -404,7 +400,7 @@ def parse_args(): print("\n".join(files)) print("=========") - f = Filters(files, args.ignore_path, args.pull_request, args.platform, args.detailed_test_id) + f = Filters(files, args.pull_request, args.platform, args.detailed_test_id) f.process() # remove dupes and filtered cases From 8b5c28a140ca0adba74c344206cafe7eaf2285aa Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:34 +0000 Subject: [PATCH 0578/1623] Revert "[nrf fromtree] scripts: Allow test_plan.py to work with other than zephyr repos" This reverts commit 26dfd71e944b74eb2ec73e41689cd26c128f3566. Signed-off-by: Dominik Ermel --- scripts/ci/test_plan.py | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 9a6f50f57d0..6251104c32e 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -19,17 +19,10 @@ if "ZEPHYR_BASE" not in os.environ: exit("$ZEPHYR_BASE environment variable undefined.") -# These are globaly used variables. They are assigned in __main__ and are visible in further methods -# however, pylint complains that it doesn't recognized them when used (used-before-assignment). -zephyr_base = Path(os.environ['ZEPHYR_BASE']) -repository_path = zephyr_base -repo_to_scan = zephyr_base -args = None - - +repository_path = Path(os.environ['ZEPHYR_BASE']) logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) -sys.path.append(os.path.join(zephyr_base, 'scripts')) +sys.path.append(os.path.join(repository_path, 'scripts')) import list_boards def _get_match_fn(globs, regexes): @@ -119,7 +112,7 @@ def process(self): def get_plan(self, options, integration=False): fname = "_test_plan_partial.json" - cmd = [f"{zephyr_base}/scripts/twister", "-c"] + options + ["--save-tests", fname ] + cmd = ["scripts/twister", "-c"] + options + ["--save-tests", fname ] if not self.detailed_test_id: cmd += ["--no-detailed-test-id"] if integration: @@ -138,7 +131,7 @@ def find_modules(self): if 'west.yml' in self.modified_files: print(f"Manifest file 'west.yml' changed") print("=========") - old_manifest_content = repo_to_scan.git.show(f"{args.commits[:-2]}:west.yml") + old_manifest_content = repo.git.show(f"{args.commits[:-2]}:west.yml") with open("west_old.yml", "w") as manifest: manifest.write(old_manifest_content) old_manifest = Manifest.from_file("west_old.yml") @@ -219,12 +212,8 @@ def find_boards(self): if p and p.groups(): boards.add(p.group(1)) - roots = [zephyr_base] - if repository_path != zephyr_base: - roots.append(repository_path) - - # Look for boards in monitored repositories - lb_args = argparse.Namespace(**{ 'arch_roots': roots, 'board_roots': roots}) + # Limit search to $ZEPHYR_BASE since this is where the changed files are + lb_args = argparse.Namespace(**{ 'arch_roots': [repository_path], 'board_roots': [repository_path] }) known_boards = list_boards.find_boards(lb_args) for b in boards: name_re = re.compile(b) @@ -279,7 +268,7 @@ def find_tests(self): def find_tags(self): - tag_cfg_file = os.path.join(zephyr_base, 'scripts', 'ci', 'tags.yaml') + tag_cfg_file = os.path.join(repository_path, 'scripts', 'ci', 'tags.yaml') with open(tag_cfg_file, 'r') as ymlfile: tags_config = yaml.safe_load(ymlfile) @@ -371,8 +360,6 @@ def parse_args(): help="Include paths to tests' locations in tests' names.") parser.add_argument("--no-detailed-test-id", dest='detailed_test_id', action="store_false", help="Don't put paths into tests' names.") - parser.add_argument('-r', '--repo-to-scan', default=None, - help="Repo to scan") # Include paths in names by default. parser.set_defaults(detailed_test_id=True) @@ -385,11 +372,9 @@ def parse_args(): args = parse_args() files = [] errors = 0 - if args.repo_to_scan: - repository_path = Path(args.repo_to_scan) if args.commits: - repo_to_scan = Repo(repository_path) - commit = repo_to_scan.git.diff("--name-only", args.commits) + repo = Repo(repository_path) + commit = repo.git.diff("--name-only", args.commits) files = commit.split("\n") elif args.modified_files: with open(args.modified_files, "r") as fp: From b3fca6aa31b344f7734fbc4b04758f6b96d50d73 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:34 +0000 Subject: [PATCH 0579/1623] Revert "[nrf fromtree] scripts: Add --no-detailed-test-id arg to test_plan.py script" This reverts commit 55257c34d335471c33fc2469f1c562e412efb4ed. Signed-off-by: Dominik Ermel --- scripts/ci/test_plan.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index 6251104c32e..8f2f24b0825 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -86,7 +86,7 @@ def __repr__(self): return "".format(self.name) class Filters: - def __init__(self, modified_files, pull_request=False, platforms=[], detailed_test_id=True): + def __init__(self, modified_files, pull_request=False, platforms=[]): self.modified_files = modified_files self.twister_options = [] self.full_twister = False @@ -95,7 +95,6 @@ def __init__(self, modified_files, pull_request=False, platforms=[], detailed_te self.pull_request = pull_request self.platforms = platforms self.default_run = False - self.detailed_test_id = detailed_test_id def process(self): self.find_modules() @@ -113,8 +112,6 @@ def process(self): def get_plan(self, options, integration=False): fname = "_test_plan_partial.json" cmd = ["scripts/twister", "-c"] + options + ["--save-tests", fname ] - if not self.detailed_test_id: - cmd += ["--no-detailed-test-id"] if integration: cmd.append("--integration") @@ -356,13 +353,6 @@ def parse_args(): help="Number of tests per builder") parser.add_argument('-n', '--default-matrix', default=10, type=int, help="Number of tests per builder") - parser.add_argument('--detailed-test-id', action='store_true', - help="Include paths to tests' locations in tests' names.") - parser.add_argument("--no-detailed-test-id", dest='detailed_test_id', action="store_false", - help="Don't put paths into tests' names.") - - # Include paths in names by default. - parser.set_defaults(detailed_test_id=True) return parser.parse_args() @@ -385,7 +375,8 @@ def parse_args(): print("\n".join(files)) print("=========") - f = Filters(files, args.pull_request, args.platform, args.detailed_test_id) + + f = Filters(files, args.pull_request, args.platform) f.process() # remove dupes and filtered cases From b70cd9bc022b8cdfb9fa22d3fc4086bd1a89b056 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:34 +0000 Subject: [PATCH 0580/1623] Revert "[nrf fromtree] twister: Fix error for --device-testing with not runnable integration" This reverts commit e4052b3643de84d69f5d6fb5656295298d4aac62. Signed-off-by: Dominik Ermel --- scripts/pylib/twister/twisterlib/testplan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pylib/twister/twisterlib/testplan.py b/scripts/pylib/twister/twisterlib/testplan.py index ae122862d1e..209b76c65d2 100755 --- a/scripts/pylib/twister/twisterlib/testplan.py +++ b/scripts/pylib/twister/twisterlib/testplan.py @@ -740,7 +740,7 @@ def apply_filters(self, **kwargs): instance.add_filter("Not part of requested test plan", Filters.TESTSUITE) if runnable and not instance.run: - instance.add_filter("Not runnable on device", Filters.CMD_LINE) + instance.add_filter("Not runnable on device", Filters.PLATFORM) if self.options.integration and ts.integration_platforms and plat.name not in ts.integration_platforms: instance.add_filter("Not part of integration platforms", Filters.TESTSUITE) From aaa3ae2e31e0dd6d538d8827a739ad232402cba1 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:34 +0000 Subject: [PATCH 0581/1623] Revert "[nrf fromtree] twister: Add options deciding if paths be included in tests' names" This reverts commit b19ec69bf9ef2c7ac5d7fa37b6f4d934de6e567d. Signed-off-by: Dominik Ermel --- .../pylib/twister/twisterlib/environment.py | 15 ------- scripts/pylib/twister/twisterlib/reports.py | 10 ++--- .../pylib/twister/twisterlib/testinstance.py | 7 +--- scripts/pylib/twister/twisterlib/testplan.py | 2 +- scripts/pylib/twister/twisterlib/testsuite.py | 16 +++----- scripts/tests/twister/test_harness.py | 1 - scripts/tests/twister/test_testsuite.py | 40 ------------------- 7 files changed, 10 insertions(+), 81 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index b5018bc1f01..160233a66fe 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -437,21 +437,6 @@ def add_parse_arguments(parser = None): help="Re-use the outdir before building. Will result in " "faster compilation since builds will be incremental.") - parser.add_argument( - '--detailed-test-id', action='store_true', - help="Include paths to tests' locations in tests' names. Names will follow " - "PATH_TO_TEST/SCENARIO_NAME schema " - "e.g. samples/hello_world/sample.basic.helloworld") - - parser.add_argument( - "--no-detailed-test-id", dest='detailed_test_id', action="store_false", - help="Don't put paths into tests' names. " - "With this arg a test name will be a scenario name " - "e.g. sample.basic.helloworld.") - - # Include paths in names by default. - parser.set_defaults(detailed_test_id=True) - # To be removed in favor of --detailed-skipped-report parser.add_argument( "--no-skipped-report", action="store_true", diff --git a/scripts/pylib/twister/twisterlib/reports.py b/scripts/pylib/twister/twisterlib/reports.py index c1f160caad9..0b34a5d309b 100644 --- a/scripts/pylib/twister/twisterlib/reports.py +++ b/scripts/pylib/twister/twisterlib/reports.py @@ -420,7 +420,6 @@ def footprint_reports(self, report, show_footprint, all_deltas, def synopsis(self): cnt = 0 example_instance = None - detailed_test_id = self.env.options.detailed_test_id for instance in self.instances.values(): if instance.status not in ["passed", "filtered", "skipped"]: cnt = cnt + 1 @@ -436,14 +435,11 @@ def synopsis(self): if cnt and example_instance: logger.info("") logger.info("To rerun the tests, call twister using the following commandline:") - extra_parameters = '' if detailed_test_id else ' --no-detailed-test-id' - logger.info(f"west twister -p -s {extra_parameters}, for example:") + logger.info("west twister -p -s , for example:") logger.info("") - logger.info(f"west twister -p {example_instance.platform.name} -s {example_instance.testsuite.name}" - f"{extra_parameters}") + logger.info(f"west twister -p {example_instance.platform.name} -s {example_instance.testsuite.name}") logger.info(f"or with west:") - logger.info(f"west build -p -b {example_instance.platform.name} " - f"{example_instance.testsuite.source_dir_rel} -T {example_instance.testsuite.id}") + logger.info(f"west build -p -b {example_instance.platform.name} -T {example_instance.testsuite.name}") logger.info("-+" * 40) def summary(self, results, unrecognized_sections, duration): diff --git a/scripts/pylib/twister/twisterlib/testinstance.py b/scripts/pylib/twister/twisterlib/testinstance.py index b9e7d411cb5..ccfc3cd06d4 100644 --- a/scripts/pylib/twister/twisterlib/testinstance.py +++ b/scripts/pylib/twister/twisterlib/testinstance.py @@ -55,12 +55,7 @@ def __init__(self, testsuite, platform, outdir): self.name = os.path.join(platform.name, testsuite.name) self.run_id = self._get_run_id() self.dut = None - if testsuite.detailed_test_id: - self.build_dir = os.path.join(outdir, platform.name, testsuite.name) - else: - # if suite is not in zephyr, keep only the part after ".." in reconstructed dir structure - source_dir_rel = testsuite.source_dir_rel.rsplit(os.pardir+os.path.sep, 1)[-1] - self.build_dir = os.path.join(outdir, platform.name, source_dir_rel, testsuite.name) + self.build_dir = os.path.join(outdir, platform.name, testsuite.name) self.domains = None diff --git a/scripts/pylib/twister/twisterlib/testplan.py b/scripts/pylib/twister/twisterlib/testplan.py index 209b76c65d2..1d9c625b28a 100755 --- a/scripts/pylib/twister/twisterlib/testplan.py +++ b/scripts/pylib/twister/twisterlib/testplan.py @@ -524,7 +524,7 @@ def add_testsuites(self, testsuite_filter=[]): for name in parsed_data.scenarios.keys(): suite_dict = parsed_data.get_scenario(name) - suite = TestSuite(root, suite_path, name, data=suite_dict, detailed_test_id=self.options.detailed_test_id) + suite = TestSuite(root, suite_path, name, data=suite_dict) suite.add_subcases(suite_dict, subcases, ztest_suite_names) if testsuite_filter: if suite.name and suite.name in testsuite_filter: diff --git a/scripts/pylib/twister/twisterlib/testsuite.py b/scripts/pylib/twister/twisterlib/testsuite.py index 39c21098718..faacf669c1d 100644 --- a/scripts/pylib/twister/twisterlib/testsuite.py +++ b/scripts/pylib/twister/twisterlib/testsuite.py @@ -348,7 +348,7 @@ class TestSuite(DisablePyTestCollectionMixin): """Class representing a test application """ - def __init__(self, suite_root, suite_path, name, data=None, detailed_test_id=True): + def __init__(self, suite_root, suite_path, name, data=None): """TestSuite constructor. This gets called by TestPlan as it finds and reads test yaml files. @@ -369,14 +369,12 @@ def __init__(self, suite_root, suite_path, name, data=None, detailed_test_id=Tru """ workdir = os.path.relpath(suite_path, suite_root) - - assert self.check_suite_name(name, suite_root, workdir) - self.detailed_test_id = detailed_test_id - self.name = self.get_unique(suite_root, workdir, name) if self.detailed_test_id else name + self.name = self.get_unique(suite_root, workdir, name) self.id = name self.source_dir = suite_path - self.source_dir_rel = os.path.relpath(os.path.realpath(suite_path), start=canonical_zephyr_base) + self.source_dir_rel = os.path.relpath(os.path.realpath(suite_path), + start=canonical_zephyr_base) self.yamlfile = suite_path self.testcases = [] @@ -429,14 +427,10 @@ def get_unique(testsuite_root, workdir, name): # workdir can be "." unique = os.path.normpath(os.path.join(relative_ts_root, workdir, name)) - return unique - - @staticmethod - def check_suite_name(name, testsuite_root, workdir): check = name.split(".") if len(check) < 2: raise TwisterException(f"""bad test name '{name}' in {testsuite_root}/{workdir}. \ Tests should reference the category and subsystem with a dot as a separator. """ ) - return True + return unique diff --git a/scripts/tests/twister/test_harness.py b/scripts/tests/twister/test_harness.py index 1da2aed3f46..a33d6431ab4 100644 --- a/scripts/tests/twister/test_harness.py +++ b/scripts/tests/twister/test_harness.py @@ -40,7 +40,6 @@ def gtest(): mock_platform.name = "mock_platform" mock_testsuite = mock.Mock() mock_testsuite.name = "mock_testsuite" - mock_testsuite.detailed_test_id = True mock_testsuite.id = "id" mock_testsuite.testcases = [] instance = TestInstance(testsuite=mock_testsuite, platform=mock_platform, outdir="") diff --git a/scripts/tests/twister/test_testsuite.py b/scripts/tests/twister/test_testsuite.py index 23e4f8ed034..49f19d0d0f8 100644 --- a/scripts/tests/twister/test_testsuite.py +++ b/scripts/tests/twister/test_testsuite.py @@ -749,43 +749,3 @@ def test_testcase_dunders(): assert case_lesser < case_greater assert str(case_greater) == 'a greater name' assert repr(case_greater) == '' - - -TESTDATA_11 = [ - ( - ZEPHYR_BASE + '/scripts/tests/twister/test_data/testsuites', - ZEPHYR_BASE + '/scripts/tests/twister/test_data/testsuites/tests/test_a', - 'test_a.check_1', - 'test_a.check_1' - ), - ( - ZEPHYR_BASE, - ZEPHYR_BASE, - 'test_a.check_1', - 'test_a.check_1' - ), - ( - ZEPHYR_BASE, - ZEPHYR_BASE + '/scripts/tests/twister/test_data/testsuites/test_b', - 'test_b.check_1', - 'test_b.check_1' - ), - ( - os.path.join(ZEPHYR_BASE, 'scripts/tests'), - os.path.join(ZEPHYR_BASE, 'scripts/tests'), - 'test_b.check_1', - 'test_b.check_1' - ), - ( - ZEPHYR_BASE, - ZEPHYR_BASE, - 'test_a.check_1.check_2', - 'test_a.check_1.check_2' - ), -] -@pytest.mark.parametrize("testsuite_root, suite_path, name, expected", TESTDATA_11) -def test_get_no_detailed_test_id(testsuite_root, suite_path, name, expected): - '''Test to check if the name without path is given for each testsuite''' - suite = TestSuite(testsuite_root, suite_path, name, detailed_test_id=False) - print(suite.name) - assert suite.name == expected From d7ac4dbf733e24f90bd33e55b00b662e9ab8bf08 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:34 +0000 Subject: [PATCH 0582/1623] Revert "[nrf fromtree] twister: Add "path" entry to json test report" This reverts commit df801013e317c988eb4a1fad2e8a6e2a438c10d5. Signed-off-by: Dominik Ermel --- scripts/pylib/twister/twisterlib/reports.py | 1 - scripts/pylib/twister/twisterlib/testsuite.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/reports.py b/scripts/pylib/twister/twisterlib/reports.py index 0b34a5d309b..bd005d4319a 100644 --- a/scripts/pylib/twister/twisterlib/reports.py +++ b/scripts/pylib/twister/twisterlib/reports.py @@ -258,7 +258,6 @@ def json_report(self, filename, version="NA"): "name": instance.testsuite.name, "arch": instance.platform.arch, "platform": instance.platform.name, - "path": instance.testsuite.source_dir_rel } if instance.run_id: suite['run_id'] = instance.run_id diff --git a/scripts/pylib/twister/twisterlib/testsuite.py b/scripts/pylib/twister/twisterlib/testsuite.py index faacf669c1d..3f4a71e4a8c 100644 --- a/scripts/pylib/twister/twisterlib/testsuite.py +++ b/scripts/pylib/twister/twisterlib/testsuite.py @@ -373,8 +373,6 @@ def __init__(self, suite_root, suite_path, name, data=None): self.id = name self.source_dir = suite_path - self.source_dir_rel = os.path.relpath(os.path.realpath(suite_path), - start=canonical_zephyr_base) self.yamlfile = suite_path self.testcases = [] From 6af83b284849c3499c669f1055c5fa1e997c2660 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:35 +0000 Subject: [PATCH 0583/1623] Revert "[nrf fromtree] wifi: shell: Move defaults to beginning" This reverts commit d36ea76f95b7b50cc31b45f207b2716ea4302cb8. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 280ebd90390..fe6f1c9f54c 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -341,10 +341,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[], return -EINVAL; } - /* Defaults */ params->band = WIFI_FREQ_BAND_UNKNOWN; - params->channel = WIFI_CHANNEL_ANY; - params->security = WIFI_SECURITY_TYPE_NONE; /* SSID */ params->ssid = argv[0]; @@ -365,6 +362,8 @@ static int __wifi_args_to_params(size_t argc, char *argv[], } idx++; + } else { + params->channel = WIFI_CHANNEL_ANY; } /* PSK (optional) */ @@ -403,6 +402,8 @@ static int __wifi_args_to_params(size_t argc, char *argv[], params->psk_length > WIFI_SAE_PSWD_MAX_LEN)) { return -EINVAL; } + } else { + params->security = WIFI_SECURITY_TYPE_NONE; } From 1113813ab6bdc1341cc5ab3a55d8596e40788cf1 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:35 +0000 Subject: [PATCH 0584/1623] Revert "[nrf fromtree] wifi: shell: Fix default band value" This reverts commit 902f4a417ae968e3fb1ebd97f72b1795c433a497. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index fe6f1c9f54c..9e521fcf028 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -341,8 +341,6 @@ static int __wifi_args_to_params(size_t argc, char *argv[], return -EINVAL; } - params->band = WIFI_FREQ_BAND_UNKNOWN; - /* SSID */ params->ssid = argv[0]; params->ssid_length = strlen(params->ssid); From 87cfab36ae920eb95ade673914b4dd305d200bf9 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:35 +0000 Subject: [PATCH 0585/1623] Revert "[nrf noup] testspec: Add audio" This reverts commit 2b1d418a6c8b17e028204bbefe4500f0286d46d4. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 007f4307aa9..c01ae703adf 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -218,25 +218,3 @@ - "subsys/bluetooth/**/*" - "!subsys/bluetooth/mesh/**/*" - "!subsys/bluetooth/audio/**/*" - -"CI-audio-test": - - "boards/arm/nrf5340_audio_dk_nrf5340/**/*" - - "drivers/flash/**/*" - - "drivers/spi/**/*" - - "drivers/gpio/**/*" - - "drivers/i2c/**/*" - - "drivers/watchdog/**/*" - - "include/dfu/**/*" - - "include/mgmt/mcumgr/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" - - "soc/arm/nordic_nrf/**/*" - - "subsys/bluetooth/audio/**/*" - - "subsys/bluetooth/host/**/*" - - "subsys/dfu/**/*" - - "subsys/fs/**/*" - - "subsys/mgmt/mcumgr/**/*" - - "subsys/sd/**/*" - - "subsys/storage/**/*" - - "subsys/task_wdt/**/*" - - "subsys/usb/**/*" - - "subsys/zbus/**/*" From 4894aec7879d711064e46b9d7c1c54db242feb9e Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:36 +0000 Subject: [PATCH 0586/1623] Revert "[nrf fromtree] net: zperf: Fix the check for IPv6" This reverts commit f0b15a5617adc94c29466827aeac051f5f157e3f. Signed-off-by: Dominik Ermel --- subsys/net/lib/zperf/zperf_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index b61501d0e9e..b32654f44bc 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -1147,7 +1147,7 @@ void zperf_shell_init(void) { int ret; - if (IS_ENABLED(MY_IP6ADDR_SET) && MY_IP6ADDR) { + if (IS_ENABLED(MY_IP4ADDR_SET) && MY_IP6ADDR) { ret = net_addr_pton(AF_INET6, MY_IP6ADDR, &in6_addr_my.sin6_addr); if (ret < 0) { From 90070b9bff7141141498d9a9f3747447ba610c2e Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:36 +0000 Subject: [PATCH 0587/1623] Revert "[nrf fromtree] net: zperf: By default bind to any IP address" This reverts commit 7ed5a305f4b4e741e855e3dbb89f3af30f2de115. Signed-off-by: Dominik Ermel --- subsys/net/lib/zperf/zperf_common.c | 21 +++++++++++++++++ subsys/net/lib/zperf/zperf_internal.h | 3 +++ subsys/net/lib/zperf/zperf_tcp_receiver.c | 27 ++++++++++++++++------ subsys/net/lib/zperf/zperf_udp_receiver.c | 28 ++++++++++++++++------- 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_common.c b/subsys/net/lib/zperf/zperf_common.c index 29568eeef5b..efe36cf69cd 100644 --- a/subsys/net/lib/zperf/zperf_common.c +++ b/subsys/net/lib/zperf/zperf_common.c @@ -109,6 +109,27 @@ int zperf_get_ipv4_addr(char *host, struct in_addr *addr) return 0; } + +const struct in_addr *zperf_get_default_if_in4_addr(void) +{ +#if CONFIG_NET_IPV4 + return net_if_ipv4_select_src_addr(NULL, + net_ipv4_unspecified_address()); +#else + return NULL; +#endif +} + +const struct in6_addr *zperf_get_default_if_in6_addr(void) +{ +#if CONFIG_NET_IPV6 + return net_if_ipv6_select_src_addr(NULL, + net_ipv6_unspecified_address()); +#else + return NULL; +#endif +} + int zperf_prepare_upload_sock(const struct sockaddr *peer_addr, int tos, int priority, int proto) { diff --git a/subsys/net/lib/zperf/zperf_internal.h b/subsys/net/lib/zperf/zperf_internal.h index 592424a9446..96dd9ea9123 100644 --- a/subsys/net/lib/zperf/zperf_internal.h +++ b/subsys/net/lib/zperf/zperf_internal.h @@ -95,6 +95,9 @@ struct sockaddr_in *zperf_get_sin(void); extern void connect_ap(char *ssid); +const struct in_addr *zperf_get_default_if_in4_addr(void); +const struct in6_addr *zperf_get_default_if_in6_addr(void); + int zperf_prepare_upload_sock(const struct sockaddr *peer_addr, int tos, int priority, int proto); diff --git a/subsys/net/lib/zperf/zperf_tcp_receiver.c b/subsys/net/lib/zperf/zperf_tcp_receiver.c index 6cc3374d0ae..614e1af6d03 100644 --- a/subsys/net/lib/zperf/zperf_tcp_receiver.c +++ b/subsys/net/lib/zperf/zperf_tcp_receiver.c @@ -171,11 +171,18 @@ static void tcp_server_session(void) &in4_addr->sin_addr); if (ret < 0) { NET_WARN("Unable to set IPv4"); - goto use_any_ipv4; + goto use_existing_ipv4; } } else { -use_any_ipv4: - in4_addr->sin_addr.s_addr = INADDR_ANY; +use_existing_ipv4: + /* Use existing IP */ + addr = zperf_get_default_if_in4_addr(); + if (!addr) { + NET_ERR("Unable to get IPv4 by default"); + goto error; + } + memcpy(&in4_addr->sin_addr, addr, + sizeof(struct in_addr)); } in4_addr->sin_port = htons(tcp_server_port); @@ -217,12 +224,18 @@ static void tcp_server_session(void) &in6_addr->sin6_addr); if (ret < 0) { NET_WARN("Unable to set IPv6"); - goto use_any_ipv6; + goto use_existing_ipv6; } } else { -use_any_ipv6: - memcpy(&in6_addr->sin6_addr, net_ipv6_unspecified_address(), - sizeof(struct in6_addr)); +use_existing_ipv6: + /* Use existing IP */ + addr = zperf_get_default_if_in6_addr(); + if (!addr) { + NET_ERR("Unable to get IPv6 by default"); + goto error; + } + memcpy(&in6_addr->sin6_addr, addr, + sizeof(struct in6_addr)); } in6_addr->sin6_port = htons(tcp_server_port); diff --git a/subsys/net/lib/zperf/zperf_udp_receiver.c b/subsys/net/lib/zperf/zperf_udp_receiver.c index 2724da4b1a9..cf29760e1c6 100644 --- a/subsys/net/lib/zperf/zperf_udp_receiver.c +++ b/subsys/net/lib/zperf/zperf_udp_receiver.c @@ -263,11 +263,18 @@ static void udp_server_session(void) &in4_addr_my->sin_addr); if (ret < 0) { NET_WARN("Unable to set IPv4"); - goto use_any_ipv4; + goto use_existing_ipv4; } } else { -use_any_ipv4: - in4_addr_my->sin_addr.s_addr = INADDR_ANY; + use_existing_ipv4: + /* Use existing IP */ + in4_addr = zperf_get_default_if_in4_addr(); + if (!in4_addr) { + NET_ERR("Unable to get IPv4 by default"); + goto error; + } + memcpy(&in4_addr_my->sin_addr, in4_addr, + sizeof(struct in_addr)); } NET_INFO("Binding to %s", @@ -312,13 +319,18 @@ static void udp_server_session(void) &in6_addr_my->sin6_addr); if (ret < 0) { NET_WARN("Unable to set IPv6"); - goto use_any_ipv6; + goto use_existing_ipv6; } } else { -use_any_ipv6: - memcpy(&in6_addr_my->sin6_addr, - net_ipv6_unspecified_address(), - sizeof(struct in6_addr)); + use_existing_ipv6: + /* Use existing IP */ + in6_addr = zperf_get_default_if_in6_addr(); + if (!in6_addr) { + NET_ERR("Unable to get IPv4 by default"); + goto error; + } + memcpy(&in6_addr_my->sin6_addr, in6_addr, + sizeof(struct in6_addr)); } NET_INFO("Binding to %s", From 66d905cbb8facff48abbab5e2ee90761353bf3f6 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:36 +0000 Subject: [PATCH 0588/1623] Revert "[nrf fromtree] net: zperf: Add support for bind to host option for tcp/udp download" This reverts commit 5fac2b050b54701f9d73fefaba6ecd585aacbe43. Signed-off-by: Dominik Ermel --- include/zephyr/net/zperf.h | 1 - subsys/net/lib/zperf/zperf_shell.c | 63 +++++------------------ subsys/net/lib/zperf/zperf_tcp_receiver.c | 24 +++------ subsys/net/lib/zperf/zperf_udp_receiver.c | 16 +----- 4 files changed, 20 insertions(+), 84 deletions(-) diff --git a/include/zephyr/net/zperf.h b/include/zephyr/net/zperf.h index fc809ae9278..cd86541721e 100644 --- a/include/zephyr/net/zperf.h +++ b/include/zephyr/net/zperf.h @@ -43,7 +43,6 @@ struct zperf_upload_params { struct zperf_download_params { uint16_t port; - struct sockaddr addr; }; struct zperf_results { diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index b32654f44bc..bcf60dcf037 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -178,39 +178,6 @@ static int parse_ipv4_addr(const struct shell *sh, char *host, char *port, return 0; } -static int zperf_bind_host(const struct shell *sh, - size_t argc, char *argv[], - struct zperf_download_params *param) -{ - int ret; - - /* Parse options */ - if (argc >= 2) { - param->port = strtoul(argv[1], NULL, 10); - } else { - param->port = DEF_PORT; - } - - if (argc >= 3) { - char *addr_str = argv[2]; - struct sockaddr addr; - - memset(&addr, 0, sizeof(addr)); - - ret = net_ipaddr_parse(addr_str, strlen(addr_str), &addr); - if (ret < 0) { - shell_fprintf(sh, SHELL_WARNING, - "Cannot parse address \"%s\"\n", - addr_str); - return ret; - } - - memcpy(¶m->addr, &addr, sizeof(struct sockaddr)); - } - - return 0; -} - static int cmd_setip(const struct shell *sh, size_t argc, char *argv[]) { int start = 0; @@ -366,12 +333,10 @@ static int cmd_udp_download(const struct shell *sh, size_t argc, struct zperf_download_params param = { 0 }; int ret; - ret = zperf_bind_host(sh, argc, argv, ¶m); - if (ret < 0) { - shell_fprintf(sh, SHELL_WARNING, - "Unable to bind host.\n"); - shell_help(sh); - return -ENOEXEC; + if (argc >= 2) { + param.port = strtoul(argv[1], NULL, 10); + } else { + param.port = DEF_PORT; } ret = zperf_udp_download(¶m, udp_session_cb, (void *)sh); @@ -1107,12 +1072,10 @@ static int cmd_tcp_download(const struct shell *sh, size_t argc, struct zperf_download_params param = { 0 }; int ret; - ret = zperf_bind_host(sh, argc, argv, ¶m); - if (ret < 0) { - shell_fprintf(sh, SHELL_WARNING, - "Unable to bind host.\n"); - shell_help(sh); - return -ENOEXEC; + if (argc >= 2) { + param.port = strtoul(argv[1], NULL, 10); + } else { + param.port = DEF_PORT; } ret = zperf_tcp_download(¶m, tcp_session_cb, (void *)sh); @@ -1245,9 +1208,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_tcp, , cmd_tcp_upload2), SHELL_CMD(download, &zperf_cmd_tcp_download, - "[]: Server port to listen on/connect to\n" - "[]: Bind to , an interface address\n" - "Example: tcp download 5001 192.168.0.1\n", + "[]\n" + "Example: tcp download 5001\n", cmd_tcp_download), SHELL_SUBCMD_SET_END ); @@ -1304,9 +1266,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp, , cmd_udp_upload2), SHELL_CMD(download, &zperf_cmd_udp_download, - "[]: Server port to listen on/connect to\n" - "[]: Bind to , an interface address\n" - "Example: udp download 5001 192.168.0.1\n", + "[]\n" + "Example: udp download 5001\n", cmd_udp_download), SHELL_SUBCMD_SET_END ); diff --git a/subsys/net/lib/zperf/zperf_tcp_receiver.c b/subsys/net/lib/zperf/zperf_tcp_receiver.c index 614e1af6d03..25f9adc3494 100644 --- a/subsys/net/lib/zperf/zperf_tcp_receiver.c +++ b/subsys/net/lib/zperf/zperf_tcp_receiver.c @@ -46,7 +46,6 @@ static void *tcp_user_data; static bool tcp_server_running; static bool tcp_server_stop; static uint16_t tcp_server_port; -static struct sockaddr tcp_server_addr; static K_SEM_DEFINE(tcp_server_run, 0, 1); static void tcp_received(const struct sockaddr *addr, size_t datalen) @@ -151,7 +150,6 @@ static void tcp_server_session(void) if (IS_ENABLED(CONFIG_NET_IPV4)) { struct sockaddr_in *in4_addr = zperf_get_sin(); - const struct in_addr *addr = NULL; fds[SOCK_ID_IPV4_LISTEN].fd = zsock_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); @@ -160,12 +158,7 @@ static void tcp_server_session(void) goto error; } - addr = &net_sin(&tcp_server_addr)->sin_addr; - - if (!net_ipv4_is_addr_unspecified(addr)) { - memcpy(&in4_addr->sin_addr, addr, - sizeof(struct in_addr)); - } else if (MY_IP4ADDR && strlen(MY_IP4ADDR)) { + if (MY_IP4ADDR && strlen(MY_IP4ADDR)) { /* Use Setting IP */ ret = zperf_get_ipv4_addr(MY_IP4ADDR, &in4_addr->sin_addr); @@ -174,8 +167,9 @@ static void tcp_server_session(void) goto use_existing_ipv4; } } else { -use_existing_ipv4: /* Use existing IP */ + const struct in_addr *addr; +use_existing_ipv4: addr = zperf_get_default_if_in4_addr(); if (!addr) { NET_ERR("Unable to get IPv4 by default"); @@ -203,7 +197,6 @@ static void tcp_server_session(void) if (IS_ENABLED(CONFIG_NET_IPV6)) { struct sockaddr_in6 *in6_addr = zperf_get_sin6(); - const struct in6_addr *addr = NULL; fds[SOCK_ID_IPV6_LISTEN].fd = zsock_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); @@ -212,12 +205,7 @@ static void tcp_server_session(void) goto error; } - addr = &net_sin6(&tcp_server_addr)->sin6_addr; - - if (!net_ipv6_is_addr_unspecified(addr)) { - memcpy(&in6_addr->sin6_addr, addr, - sizeof(struct in6_addr)); - } else if (MY_IP6ADDR && strlen(MY_IP6ADDR)) { + if (MY_IP6ADDR && strlen(MY_IP6ADDR)) { /* Use Setting IP */ ret = zperf_get_ipv6_addr(MY_IP6ADDR, MY_PREFIX_LEN_STR, @@ -227,8 +215,9 @@ static void tcp_server_session(void) goto use_existing_ipv6; } } else { -use_existing_ipv6: /* Use existing IP */ + const struct in6_addr *addr; +use_existing_ipv6: addr = zperf_get_default_if_in6_addr(); if (!addr) { NET_ERR("Unable to get IPv6 by default"); @@ -398,7 +387,6 @@ int zperf_tcp_download(const struct zperf_download_params *param, tcp_server_port = param->port; tcp_server_running = true; tcp_server_stop = false; - memcpy(&tcp_server_addr, ¶m->addr, sizeof(struct sockaddr)); k_sem_give(&tcp_server_run); diff --git a/subsys/net/lib/zperf/zperf_udp_receiver.c b/subsys/net/lib/zperf/zperf_udp_receiver.c index cf29760e1c6..f96acde6f49 100644 --- a/subsys/net/lib/zperf/zperf_udp_receiver.c +++ b/subsys/net/lib/zperf/zperf_udp_receiver.c @@ -48,7 +48,6 @@ static void *udp_user_data; static bool udp_server_running; static bool udp_server_stop; static uint16_t udp_server_port; -static struct sockaddr udp_server_addr; static K_SEM_DEFINE(udp_server_run, 0, 1); static inline void build_reply(struct zperf_udp_datagram *hdr, @@ -252,12 +251,7 @@ static void udp_server_session(void) goto error; } - in4_addr = &net_sin(&udp_server_addr)->sin_addr; - - if (!net_ipv4_is_addr_unspecified(in4_addr)) { - memcpy(&in4_addr_my->sin_addr, in4_addr, - sizeof(struct in_addr)); - } else if (MY_IP4ADDR && strlen(MY_IP4ADDR)) { + if (MY_IP4ADDR && strlen(MY_IP4ADDR)) { /* Use setting IP */ ret = zperf_get_ipv4_addr(MY_IP4ADDR, &in4_addr_my->sin_addr); @@ -307,12 +301,7 @@ static void udp_server_session(void) goto error; } - in6_addr = &net_sin6(&udp_server_addr)->sin6_addr; - - if (!net_ipv6_is_addr_unspecified(in6_addr)) { - memcpy(&in6_addr_my->sin6_addr, in6_addr, - sizeof(struct in6_addr)); - } else if (MY_IP6ADDR && strlen(MY_IP6ADDR)) { + if (MY_IP6ADDR && strlen(MY_IP6ADDR)) { /* Use setting IP */ ret = zperf_get_ipv6_addr(MY_IP6ADDR, MY_PREFIX_LEN_STR, @@ -452,7 +441,6 @@ int zperf_udp_download(const struct zperf_download_params *param, udp_server_port = param->port; udp_server_running = true; udp_server_stop = false; - memcpy(&udp_server_addr, ¶m->addr, sizeof(struct sockaddr)); k_sem_give(&udp_server_run); From f65b47c1cecfedee27a5cd312f940159dc45d68f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:36 +0000 Subject: [PATCH 0589/1623] Revert "[nrf fromtree] net: zperf: Set default IP addresses only if configured" This reverts commit b9b5d4751b8e10a932aec3fb8e658c27ac20bda7. Signed-off-by: Dominik Ermel --- subsys/net/lib/zperf/zperf_shell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index bcf60dcf037..c1f0c6a4950 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -1110,7 +1110,7 @@ void zperf_shell_init(void) { int ret; - if (IS_ENABLED(MY_IP4ADDR_SET) && MY_IP6ADDR) { + if (IS_ENABLED(CONFIG_NET_IPV6) && MY_IP6ADDR) { ret = net_addr_pton(AF_INET6, MY_IP6ADDR, &in6_addr_my.sin6_addr); if (ret < 0) { @@ -1133,7 +1133,7 @@ void zperf_shell_init(void) } } - if (IS_ENABLED(MY_IP4ADDR_SET) && MY_IP4ADDR) { + if (IS_ENABLED(CONFIG_NET_IPV4) && MY_IP4ADDR) { ret = net_addr_pton(AF_INET, MY_IP4ADDR, &in4_addr_my.sin_addr); if (ret < 0) { From 7d06f8422ade289b17a5e366734f795d6bcdd701 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:37 +0000 Subject: [PATCH 0590/1623] Revert "[nrf fromtree] net: zperf: Distinguish between IPv4 and IPv6 address set failures" This reverts commit bbc2731680cc1a7088ea5410d9ff81de4f4fe34a. Signed-off-by: Dominik Ermel --- subsys/net/lib/zperf/zperf_shell.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index c1f0c6a4950..3a8a9c61c4b 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -191,7 +191,7 @@ static int cmd_setip(const struct shell *sh, size_t argc, char *argv[]) if (zperf_get_ipv6_addr(argv[start + 1], argv[start + 2], &shell_ipv6) < 0) { shell_fprintf(sh, SHELL_WARNING, - "Unable to set %s address (%s disabled)\n", "IPv6", "IPv4"); + "Unable to set IP\n"); return 0; } @@ -208,7 +208,7 @@ static int cmd_setip(const struct shell *sh, size_t argc, char *argv[]) if (zperf_get_ipv4_addr(argv[start + 1], &shell_ipv4) < 0) { shell_fprintf(sh, SHELL_WARNING, - "Unable to set %s address (%s disabled)\n", "IPv4", "IPv6"); + "Unable to set IP\n"); return -ENOEXEC; } @@ -227,7 +227,7 @@ static int cmd_setip(const struct shell *sh, size_t argc, char *argv[]) if (zperf_get_ipv4_addr(argv[start + 1], &shell_ipv4) < 0) { shell_fprintf(sh, SHELL_WARNING, - "Unable to set %s address\n", "IPv4"); + "Unable to set IP\n"); return -ENOEXEC; } @@ -243,7 +243,7 @@ static int cmd_setip(const struct shell *sh, size_t argc, char *argv[]) if (zperf_get_ipv6_addr(argv[start + 1], argv[start + 2], &shell_ipv6) < 0) { shell_fprintf(sh, SHELL_WARNING, - "Unable to set %s address\n", "IPv6"); + "Unable to set IP\n"); return -ENOEXEC; } @@ -1114,7 +1114,7 @@ void zperf_shell_init(void) ret = net_addr_pton(AF_INET6, MY_IP6ADDR, &in6_addr_my.sin6_addr); if (ret < 0) { - NET_WARN("Unable to set %s address\n", "IPv6"); + NET_WARN("Unable to set IP"); } else { NET_INFO("Setting IP address %s", net_sprint_ipv6_addr(&in6_addr_my.sin6_addr)); @@ -1123,10 +1123,9 @@ void zperf_shell_init(void) ret = net_addr_pton(AF_INET6, DST_IP6ADDR, &in6_addr_dst.sin6_addr); if (ret < 0) { - NET_WARN("Unable to set destination %s address %s", - "IPv6", + NET_WARN("Unable to set IP %s", DST_IP6ADDR ? DST_IP6ADDR - : "(not set)"); + : "(Default IPv6 destination address not set)"); } else { NET_INFO("Setting destination IP address %s", net_sprint_ipv6_addr(&in6_addr_dst.sin6_addr)); @@ -1137,7 +1136,7 @@ void zperf_shell_init(void) ret = net_addr_pton(AF_INET, MY_IP4ADDR, &in4_addr_my.sin_addr); if (ret < 0) { - NET_WARN("Unable to set %s address\n", "IPv4"); + NET_WARN("Unable to set IP"); } else { NET_INFO("Setting IP address %s", net_sprint_ipv4_addr(&in4_addr_my.sin_addr)); @@ -1146,10 +1145,9 @@ void zperf_shell_init(void) ret = net_addr_pton(AF_INET, DST_IP4ADDR, &in4_addr_dst.sin_addr); if (ret < 0) { - NET_WARN("Unable to set destination %s address %s", - "IPv4", + NET_WARN("Unable to set IP %s", DST_IP4ADDR ? DST_IP4ADDR - : "(not set)"); + : "(Default IPv4 destination address not set)"); } else { NET_INFO("Setting destination IP address %s", net_sprint_ipv4_addr(&in4_addr_dst.sin_addr)); From 536f6e401bda1dbaf58121a0238f2788544c3088 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:37 +0000 Subject: [PATCH 0591/1623] Revert "[nrf fromtree] Bluetooth: BAP: Broadcast sink: Clear pa_sync on PA terminated" This reverts commit 7a9d7daf0af044b352a50feef529a5f45c285b91. Signed-off-by: Dominik Ermel --- subsys/bluetooth/audio/bap_broadcast_sink.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/subsys/bluetooth/audio/bap_broadcast_sink.c b/subsys/bluetooth/audio/bap_broadcast_sink.c index 4fad67ce539..0d92617f329 100644 --- a/subsys/bluetooth/audio/bap_broadcast_sink.c +++ b/subsys/bluetooth/audio/bap_broadcast_sink.c @@ -566,16 +566,6 @@ static void pa_recv(struct bt_le_per_adv_sync *sync, bt_data_parse(buf, pa_decode_base, (void *)sink); } -static void pa_term_cb(struct bt_le_per_adv_sync *sync, - const struct bt_le_per_adv_sync_term_info *info) -{ - struct bt_bap_broadcast_sink *sink = broadcast_sink_get_by_pa(sync); - - if (sink != NULL) { - sink->pa_sync = NULL; - } -} - static void update_recv_state_encryption(const struct bt_bap_broadcast_sink *sink) { struct bt_bap_scan_delegator_mod_src_param mod_src_param = { 0 }; @@ -1118,7 +1108,6 @@ static int broadcast_sink_init(void) static struct bt_le_per_adv_sync_cb cb = { .recv = pa_recv, .biginfo = biginfo_recv, - .term = pa_term_cb, }; bt_le_per_adv_sync_cb_register(&cb); From 4fc5455df78502aee6afbbe65e28ef45656e150f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:37 +0000 Subject: [PATCH 0592/1623] Revert "[nrf fromtree] Bluetooth: BAP: Broadcast Sink should not terminate the PA Sync" This reverts commit b552226dbe60943cd46e6ac598fbb81fda366317. Signed-off-by: Dominik Ermel --- subsys/bluetooth/audio/bap_broadcast_sink.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/subsys/bluetooth/audio/bap_broadcast_sink.c b/subsys/bluetooth/audio/bap_broadcast_sink.c index 0d92617f329..9866dfd1c57 100644 --- a/subsys/bluetooth/audio/bap_broadcast_sink.c +++ b/subsys/bluetooth/audio/bap_broadcast_sink.c @@ -1076,6 +1076,8 @@ int bt_bap_broadcast_sink_stop(struct bt_bap_broadcast_sink *sink) int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink) { + int err; + CHECKIF(sink == NULL) { LOG_DBG("sink is NULL"); return -EINVAL; @@ -1097,6 +1099,17 @@ int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink) } } + if (sink->pa_sync == NULL) { + LOG_DBG("Broadcast sink is already deleted"); + return -EALREADY; + } + + err = bt_le_per_adv_sync_delete(sink->pa_sync); + if (err != 0) { + LOG_DBG("Failed to delete periodic advertising sync (err %d)", err); + return err; + } + /* Reset the broadcast sink */ broadcast_sink_cleanup(sink); From fa755baa411e0d508e5c5c15039ed1feb1908611 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:38 +0000 Subject: [PATCH 0593/1623] Revert "[nrf fromtree] zbus: Add Message subscriber" This reverts commit b715be6b467b45eaa6f3688f2117a39a1e19985a. Signed-off-by: Dominik Ermel --- include/zephyr/zbus/zbus.h | 68 +----------------- subsys/zbus/Kconfig | 30 -------- subsys/zbus/zbus.c | 144 ++++++------------------------------- 3 files changed, 23 insertions(+), 219 deletions(-) diff --git a/include/zephyr/zbus/zbus.h b/include/zephyr/zbus/zbus.h index 8a4188aa821..466a2ad9dcf 100644 --- a/include/zephyr/zbus/zbus.h +++ b/include/zephyr/zbus/zbus.h @@ -92,8 +92,7 @@ struct zbus_channel { */ enum __packed zbus_observer_type { ZBUS_OBSERVER_LISTENER_TYPE, - ZBUS_OBSERVER_SUBSCRIBER_TYPE, - ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE, + ZBUS_OBSERVER_SUBSCRIBER_TYPE }; /** @@ -128,13 +127,6 @@ struct zbus_observer { /** Observer callback function. It turns the observer into a listener. */ void (*const callback)(const struct zbus_channel *chan); - -#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) || defined(__DOXYGEN__) - /** Observer message FIFO. It turns the observer into a message subscriber. It only - * exists if the @kconfig{CONFIG_ZBUS_MSG_SUBSCRIBER} is enabled. - */ - struct k_fifo *const message_fifo; -#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ }; }; @@ -164,10 +156,8 @@ struct zbus_channel_observation { #if defined(CONFIG_ZBUS_CHANNEL_NAME) #define ZBUS_CHANNEL_NAME_INIT(_name) .name = #_name, -#define _ZBUS_CHAN_NAME(_chan) (_chan)->name #else #define ZBUS_CHANNEL_NAME_INIT(_name) -#define _ZBUS_CHAN_NAME(_chan) "" #endif #if defined(CONFIG_ZBUS_OBSERVER_NAME) @@ -389,37 +379,6 @@ k_timeout_t _zbus_timeout_remainder(uint64_t end_ticks); */ #define ZBUS_LISTENER_DEFINE(_name, _cb) ZBUS_LISTENER_DEFINE_WITH_ENABLE(_name, _cb, true) -/** - * @brief Define and initialize a message subscriber. - * - * This macro defines an observer of @ref ZBUS_OBSERVER_SUBSCRIBER_TYPE type. It defines a FIFO - * where the subscriber will receive the message asynchronously and initialize the @ref - * zbus_observer defining the subscriber. - * - * @param[in] _name The subscriber's name. - * @param[in] _enable The subscriber's initial state. - */ -#define ZBUS_MSG_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, _enable) \ - static K_FIFO_DEFINE(_zbus_observer_fifo_##_name); \ - STRUCT_SECTION_ITERABLE(zbus_observer, _name) = { \ - ZBUS_OBSERVER_NAME_INIT(_name) /* Name field */ \ - .type = ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE, \ - .enabled = _enable, \ - .message_fifo = &_zbus_observer_fifo_##_name, \ - } - -/** - * @brief Define and initialize an enabled message subscriber. - * - * This macro defines an observer of message subscriber type. It defines a FIFO where the - * subscriber will receive the message asynchronously and initialize the @ref - * zbus_observer defining the subscriber. The message subscribers are defined in the enabled state - * with this macro. - - * - * @param[in] _name The subscriber's name. - */ -#define ZBUS_MSG_SUBSCRIBER_DEFINE(_name) ZBUS_MSG_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, true) /** * * @brief Publish to a channel @@ -782,31 +741,6 @@ static inline const char *zbus_obs_name(const struct zbus_observer *obs) int zbus_sub_wait(const struct zbus_observer *sub, const struct zbus_channel **chan, k_timeout_t timeout); -#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) || defined(__DOXYGEN__) - -/** - * @brief Wait for a channel message. - * - * This routine makes the subscriber wait for the new message in case of channel publication. - * - * @param[in] sub The subscriber's reference. - * @param[out] chan The notification channel's reference. - * @param[out] msg A reference to a copy of the published message. - * @param[in] timeout Waiting period for a notification arrival, - * or one of the special values, K_NO_WAIT and K_FOREVER. - * - * @retval 0 Message received. - * @retval -EINVAL The observer is not a subscriber. - * @retval -ENOMSG Could not retrieve the net_buf from the subscriber FIFO. - * @retval -EILSEQ Received an invalid channel reference. - * @retval -EFAULT A parameter is incorrect, or the function context is invalid (inside an ISR). The - * function only returns this value when the @kconfig{CONFIG_ZBUS_ASSERT_MOCK} is enabled. - */ -int zbus_sub_wait_msg(const struct zbus_observer *sub, const struct zbus_channel **chan, void *msg, - k_timeout_t timeout); - -#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ - /** * * @brief Iterate over channels. diff --git a/subsys/zbus/Kconfig b/subsys/zbus/Kconfig index f250865b466..622f89641a2 100644 --- a/subsys/zbus/Kconfig +++ b/subsys/zbus/Kconfig @@ -18,36 +18,6 @@ config ZBUS_CHANNEL_NAME config ZBUS_OBSERVER_NAME bool "Observer name field" -config ZBUS_MSG_SUBSCRIBER - select NET_BUF - bool "Message subscribers will receive all messages in sequence." - -if ZBUS_MSG_SUBSCRIBER - -choice - prompt "ZBus msg_subscribers buffer allocation" - -config ZBUS_MSG_SUBSCRIBER_NET_BUF_DYNAMIC - bool "Use heap to allocate msg_subscriber buffers data" - -config ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC - bool "Use fixed data size for msg_subscriber buffers pool" - -endchoice - -config ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_SIZE - default 16 - int "The count of net_buf available to be used simutaneously." - -if ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC - -config ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC_DATA_SIZE - int "The size of the biggest message used with ZBus." - -endif # ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC - -endif # ZBUS_MSG_SUBSCRIBER - config ZBUS_RUNTIME_OBSERVERS bool "Runtime observers support." default n diff --git a/subsys/zbus/zbus.c b/subsys/zbus/zbus.c index 4ea2d986a3f..abaf92c8641 100644 --- a/subsys/zbus/zbus.c +++ b/subsys/zbus/zbus.c @@ -8,47 +8,11 @@ #include #include #include -#include #include LOG_MODULE_REGISTER(zbus, CONFIG_ZBUS_LOG_LEVEL); -#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) - -#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_DYNAMIC) - -NET_BUF_POOL_HEAP_DEFINE(_zbus_msg_subscribers_pool, CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_SIZE, - sizeof(struct zbus_channel *), NULL); -BUILD_ASSERT(CONFIG_HEAP_MEM_POOL_SIZE > 0, "MSG_SUBSCRIBER feature requires heap memory pool."); - -static inline struct net_buf *_zbus_create_net_buf(struct net_buf_pool *pool, size_t size, - k_timeout_t timeout) -{ - return net_buf_alloc_len(&_zbus_msg_subscribers_pool, size, timeout); -} - -#else - -NET_BUF_POOL_FIXED_DEFINE(_zbus_msg_subscribers_pool, - (CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC_DATA_SIZE), - (CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_SIZE), - sizeof(struct zbus_channel *), NULL); - -static inline struct net_buf *_zbus_create_net_buf(struct net_buf_pool *pool, size_t size, - k_timeout_t timeout) -{ - __ASSERT(size <= CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC_DATA_SIZE, - "CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_STATIC_DATA_SIZE must be greater or equal to " - "%d", - (int)size); - return net_buf_alloc(&_zbus_msg_subscribers_pool, timeout); -} -#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_DYNAMIC */ - -#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ - int _zbus_init(void) { - const struct zbus_channel *curr = NULL; const struct zbus_channel *prev = NULL; @@ -80,62 +44,32 @@ int _zbus_init(void) SYS_INIT(_zbus_init, APPLICATION, CONFIG_ZBUS_CHANNELS_SYS_INIT_PRIORITY); static inline int _zbus_notify_observer(const struct zbus_channel *chan, - const struct zbus_observer *obs, k_timepoint_t end_time, - struct net_buf *buf) + const struct zbus_observer *obs, k_timepoint_t end_time) { - switch (obs->type) { - case ZBUS_OBSERVER_LISTENER_TYPE: { - obs->callback(chan); - break; - } - case ZBUS_OBSERVER_SUBSCRIBER_TYPE: { - return k_msgq_put(obs->queue, &chan, sys_timepoint_timeout(end_time)); - } -#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) - case ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE: { - struct net_buf *cloned_buf = net_buf_clone(buf, sys_timepoint_timeout(end_time)); - - if (cloned_buf == NULL) { - return -ENOMEM; - } - memcpy(net_buf_user_data(cloned_buf), &chan, sizeof(struct zbus_channel *)); - - net_buf_put(obs->message_fifo, cloned_buf); + int err = 0; - break; - } -#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ + if (obs->type == ZBUS_OBSERVER_LISTENER_TYPE) { + obs->callback(chan); - default: - _ZBUS_ASSERT(false, "Unreachable"); + } else if (obs->type == ZBUS_OBSERVER_SUBSCRIBER_TYPE) { + err = k_msgq_put(obs->queue, &chan, sys_timepoint_timeout(end_time)); + } else { + CODE_UNREACHABLE; } - return 0; + return err; } static inline int _zbus_vded_exec(const struct zbus_channel *chan, k_timepoint_t end_time) { int err = 0; int last_error = 0; - struct net_buf *buf = NULL; + + _ZBUS_ASSERT(chan != NULL, "chan is required"); /* Static observer event dispatcher logic */ struct zbus_channel_observation *observation; struct zbus_channel_observation_mask *observation_mask; -#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) - buf = _zbus_create_net_buf(&_zbus_msg_subscribers_pool, zbus_chan_msg_size(chan), - sys_timepoint_timeout(end_time)); - - _ZBUS_ASSERT(buf != NULL, "net_buf zbus_msg_subscribers_pool is " - "unavailable or heap is full"); - - net_buf_add_mem(buf, zbus_chan_msg(chan), zbus_chan_msg_size(chan)); -#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ - - LOG_DBG("Notifing %s's observers. Starting VDED:", _ZBUS_CHAN_NAME(chan)); - - int __maybe_unused index = 0; - for (int16_t i = chan->data->observers_start_idx, limit = chan->data->observers_end_idx; i < limit; ++i) { STRUCT_SECTION_GET(zbus_channel_observation, i, &observation); @@ -149,21 +83,15 @@ static inline int _zbus_vded_exec(const struct zbus_channel *chan, k_timepoint_t continue; } - err = _zbus_notify_observer(chan, obs, end_time, buf); + err = _zbus_notify_observer(chan, obs, end_time); + + _ZBUS_ASSERT(err == 0, + "could not deliver notification to observer %s. Error code %d", + _ZBUS_OBS_NAME(obs), err); if (err) { last_error = err; - LOG_ERR("could not deliver notification to observer %s. Error code %d", - _ZBUS_OBS_NAME(obs), err); - if (err == -ENOMEM) { - if (IS_ENABLED(CONFIG_ZBUS_MSG_SUBSCRIBER)) { - net_buf_unref(buf); - } - return err; - } } - - LOG_DBG(" %d -> %s", index++, _ZBUS_OBS_NAME(obs)); } #if defined(CONFIG_ZBUS_RUNTIME_OBSERVERS) @@ -172,13 +100,15 @@ static inline int _zbus_vded_exec(const struct zbus_channel *chan, k_timepoint_t SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&chan->data->observers, obs_nd, tmp, node) { + _ZBUS_ASSERT(obs_nd != NULL, "observer node is NULL"); + const struct zbus_observer *obs = obs_nd->obs; if (!obs->enabled) { continue; } - err = _zbus_notify_observer(chan, obs, end_time, buf); + err = _zbus_notify_observer(chan, obs, end_time); if (err) { last_error = err; @@ -186,8 +116,6 @@ static inline int _zbus_vded_exec(const struct zbus_channel *chan, k_timepoint_t } #endif /* CONFIG_ZBUS_RUNTIME_OBSERVERS */ - IF_ENABLED(CONFIG_ZBUS_MSG_SUBSCRIBER, (net_buf_unref(buf);)) - return last_error; } @@ -287,43 +215,15 @@ int zbus_sub_wait(const struct zbus_observer *sub, const struct zbus_channel **c { _ZBUS_ASSERT(!k_is_in_isr(), "zbus cannot be used inside ISRs"); _ZBUS_ASSERT(sub != NULL, "sub is required"); - _ZBUS_ASSERT(sub->type == ZBUS_OBSERVER_SUBSCRIBER_TYPE, "sub must be a SUBSCRIBER"); - _ZBUS_ASSERT(sub->queue != NULL, "sub queue is required"); - _ZBUS_ASSERT(chan != NULL, "chan is required"); - - return k_msgq_get(sub->queue, chan, timeout); -} - -#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) - -int zbus_sub_wait_msg(const struct zbus_observer *sub, const struct zbus_channel **chan, void *msg, - k_timeout_t timeout) -{ - _ZBUS_ASSERT(!k_is_in_isr(), "zbus subscribers cannot be used inside ISRs"); - _ZBUS_ASSERT(sub != NULL, "sub is required"); - _ZBUS_ASSERT(sub->type == ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE, - "sub must be a MSG_SUBSCRIBER"); - _ZBUS_ASSERT(sub->message_fifo != NULL, "sub message_fifo is required"); _ZBUS_ASSERT(chan != NULL, "chan is required"); - _ZBUS_ASSERT(msg != NULL, "msg is required"); - - struct net_buf *buf = net_buf_get(sub->message_fifo, timeout); - if (buf == NULL) { - return -ENOMSG; + if (sub->queue == NULL) { + return -EINVAL; } - *chan = *((struct zbus_channel **)net_buf_user_data(buf)); - - memcpy(msg, net_buf_remove_mem(buf, zbus_chan_msg_size(*chan)), zbus_chan_msg_size(*chan)); - - net_buf_unref(buf); - - return 0; + return k_msgq_get(sub->queue, chan, timeout); } -#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */ - int zbus_obs_set_chan_notification_mask(const struct zbus_observer *obs, const struct zbus_channel *chan, bool masked) { From 80531ddfe0086d320f70df3e153b759a8e7a9431 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:38 +0000 Subject: [PATCH 0594/1623] Revert "[nrf fromtree] tfm: Add BL2 log level configuration and disable it with TFM silent conf" This reverts commit ad501cb7ca3ce9951ea4fb21b4c21291e0680664. Signed-off-by: Dominik Ermel --- modules/trusted-firmware-m/CMakeLists.txt | 19 ------------------- modules/trusted-firmware-m/Kconfig.tfm | 15 --------------- 2 files changed, 34 deletions(-) diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index f00116cda2c..0c01858f34d 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -101,25 +101,6 @@ if (CONFIG_BUILD_WITH_TFM) list(APPEND TFM_CMAKE_ARGS -DTFM_EXCEPTION_INFO_DUMP=OFF) endif() - if (CONFIG_TFM_BL2) - if (CONFIG_TFM_BL2_LOG_LEVEL_DEBUG) - set(TFM_BL2_LOG_LEVEL "DEBUG") - elseif (CONFIG_TFM_BL2_LOG_LEVEL_INFO) - set(TFM_BL2_LOG_LEVEL "INFO") - elseif (CONFIG_TFM_BL2_LOG_LEVEL_WARNING) - set(TFM_BL2_LOG_LEVEL "WARNING") - elseif (CONFIG_TFM_BL2_LOG_LEVEL_ERROR) - set(TFM_BL2_LOG_LEVEL "ERROR") - elseif (CONFIG_TFM_BL2_LOG_LEVEL_OFF OR CONFIG_TFM_LOG_LEVEL_SILENCE) - set(TFM_BL2_LOG_LEVEL "OFF") - endif() - - if (DEFINED TFM_BL2_LOG_LEVEL) - # BL2 uses MCUBOOT_LOG_LEVEL configuration - list(APPEND TFM_CMAKE_ARGS -DMCUBOOT_LOG_LEVEL=${TFM_BL2_LOG_LEVEL}) - endif() - endif() - if (CONFIG_TFM_PARTITION_LOG_LEVEL_DEBUG) set(TFM_PARTITION_LOG_LEVEL "TFM_PARTITION_LOG_LEVEL_DEBUG") elseif (CONFIG_TFM_PARTITION_LOG_LEVEL_INFO) diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index bafa5cf0bab..7fd1b348a74 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -397,21 +397,6 @@ config ROM_START_OFFSET needs to be updated if TF-M switches to use a different header size for BL2. -choice TFM_BL2_LOG_LEVEL - prompt "BL2 Log Level" if !TFM_LOG_LEVEL_SILENCE - default TFM_BL2_LOG_LEVEL_INFO - config TFM_BL2_LOG_LEVEL_DEBUG - bool "Debug" - config TFM_BL2_LOG_LEVEL_INFO - bool "Info" - config TFM_BL2_LOG_LEVEL_WARNING - bool "Warning" - config TFM_BL2_LOG_LEVEL_ERROR - bool "Error" - config TFM_BL2_LOG_LEVEL_OFF - bool "Off" -endchoice - endif # !TFM_BL2 # Option to instruct flashing a merged binary consisting of BL2 (optionally), From fc28989dfce2088c049f03817473b9d315561fab Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:38 +0000 Subject: [PATCH 0595/1623] Revert "[nrf fromtree] boards: Fix nrf9160 NS flash partition layout" This reverts commit f189c88320733cefc0dc25bff43bc854809fc81e. Signed-off-by: Dominik Ermel --- .../circuitdojo_feather_nrf9160_common.dtsi | 13 ++++++++----- .../circuitdojo_feather_nrf9160_ns.yaml | 2 +- ...itdojo_feather_nrf9160_partition_conf.dtsi | 8 ++++---- .../nrf9160_innblue21_common.dtsi | 18 +++++++++++------- .../nrf9160_innblue21_ns.yaml | 2 +- .../nrf9160_innblue21_partition_conf.dtsi | 8 ++++---- .../nrf9160_innblue22_common.dtsi | 19 +++++++++++-------- .../nrf9160_innblue22_ns.yaml | 2 +- .../nrf9160_innblue22_partition_conf.dtsi | 8 ++++---- .../sparkfun_thing_plus_nrf9160_common.dtsi | 13 ++++++++----- .../sparkfun_thing_plus_nrf9160_ns.yaml | 2 +- ...fun_thing_plus_nrf9160_partition_conf.dtsi | 8 ++++---- 12 files changed, 58 insertions(+), 45 deletions(-) diff --git a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dtsi b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dtsi index 00ce5dcf6c0..33fdba4d865 100644 --- a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dtsi +++ b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dtsi @@ -187,19 +187,22 @@ slot0_partition: partition@10000 { label = "image-0"; }; - slot0_ns_partition: partition@50000 { + slot0_ns_partition: partition@40000 { label = "image-0-nonsecure"; }; slot1_partition: partition@80000 { label = "image-1"; }; - slot1_ns_partition: partition@c0000 { + slot1_ns_partition: partition@b0000 { label = "image-1-nonsecure"; }; - /* 0xf0000 to 0xf7fff reserved for TF-M partitions */ - storage_partition: partition@f8000 { + scratch_partition: partition@f0000 { + label = "image-scratch"; + reg = <0x000f0000 0xa000>; + }; + storage_partition: partition@fa000 { label = "storage"; - reg = <0x000f8000 0x00008000>; + reg = <0x000fa000 0x00006000>; }; }; }; diff --git a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_ns.yaml b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_ns.yaml index 56905972e9f..c358a1d87fe 100644 --- a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_ns.yaml +++ b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_ns.yaml @@ -7,7 +7,7 @@ toolchain: - xtools - zephyr ram: 128 -flash: 192 +flash: 256 supported: - i2c - pwm diff --git a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_partition_conf.dtsi b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_partition_conf.dtsi index 007975132d6..e8cb6fc586e 100644 --- a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_partition_conf.dtsi +++ b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_partition_conf.dtsi @@ -23,19 +23,19 @@ */ &slot0_partition { - reg = <0x00010000 0x40000>; + reg = <0x00010000 0x30000>; }; &slot0_ns_partition { - reg = <0x00050000 0x30000>; + reg = <0x00040000 0x40000>; }; &slot1_partition { - reg = <0x00080000 0x40000>; + reg = <0x00080000 0x30000>; }; &slot1_ns_partition { - reg = <0x000c0000 0x30000>; + reg = <0x000b0000 0x40000>; }; /* Default SRAM planning when building for nRF9160 with diff --git a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dtsi b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dtsi index 0ec5de5dfb1..0abfd4d6b9c 100644 --- a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dtsi +++ b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dtsi @@ -168,23 +168,27 @@ boot_partition: partition@0 { label = "mcuboot"; - reg = <0x00000000 0x10000>; + reg = <0x00000000 0xc000>; }; - slot0_partition: partition@10000 { + slot0_partition: partition@c000 { label = "image-0"; }; - slot0_ns_partition: partition@50000 { + slot0_ns_partition: partition@3e000 { label = "image-0-nonsecure"; }; - slot1_partition: partition@80000 { + slot1_partition: partition@7e000 { label = "image-1"; }; - slot1_ns_partition: partition@c0000 { + slot1_ns_partition: partition@b0000 { label = "image-1-nonsecure"; }; - storage_partition: partition@f8000 { + scratch_partition: partition@f0000 { + label = "image-scratch"; + reg = <0x000f0000 0xa000>; + }; + storage_partition: partition@fa000 { label = "storage"; - reg = <0x000f8000 0x00008000>; + reg = <0x000fa000 0x00006000>; }; }; }; diff --git a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_ns.yaml b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_ns.yaml index 4584ad0e6a4..096821d8364 100644 --- a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_ns.yaml +++ b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_ns.yaml @@ -7,7 +7,7 @@ toolchain: - xtools - zephyr ram: 128 -flash: 192 +flash: 256 supported: - i2c - pwm diff --git a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_partition_conf.dtsi b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_partition_conf.dtsi index 2c64ba67a8a..d3a30abdc76 100644 --- a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_partition_conf.dtsi +++ b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_partition_conf.dtsi @@ -22,19 +22,19 @@ */ &slot0_partition { - reg = <0x00010000 0x40000>; + reg = <0x0000c000 0x30000>; }; &slot0_ns_partition { - reg = <0x00050000 0x30000>; + reg = <0x0003e000 0x40000>; }; &slot1_partition { - reg = <0x00080000 0x40000>; + reg = <0x0007e000 0x30000>; }; &slot1_ns_partition { - reg = <0x000c0000 0x30000>; + reg = <0x000b0000 0x40000>; }; /* Default SRAM planning when building for nRF9160 with diff --git a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dtsi b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dtsi index 4738dd84a63..4582f975f5d 100644 --- a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dtsi +++ b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dtsi @@ -171,24 +171,27 @@ boot_partition: partition@0 { label = "mcuboot"; - reg = <0x00000000 0x10000>; + reg = <0x00000000 0xc000>; }; - slot0_partition: partition@10000 { + slot0_partition: partition@c000 { label = "image-0"; }; - slot0_ns_partition: partition@50000 { + slot0_ns_partition: partition@3e000 { label = "image-0-nonsecure"; }; - slot1_partition: partition@80000 { + slot1_partition: partition@7e000 { label = "image-1"; }; - slot1_ns_partition: partition@c0000 { + slot1_ns_partition: partition@b0000 { label = "image-1-nonsecure"; }; - /* 0xf0000 to 0xf7fff reserved for TF-M partitions */ - storage_partition: partition@f8000 { + scratch_partition: partition@f0000 { + label = "image-scratch"; + reg = <0x000f0000 0xa000>; + }; + storage_partition: partition@fa000 { label = "storage"; - reg = <0x000f8000 0x00008000>; + reg = <0x000fa000 0x00006000>; }; }; }; diff --git a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_ns.yaml b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_ns.yaml index 0186c26a377..2ce0d6e3db2 100644 --- a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_ns.yaml +++ b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_ns.yaml @@ -7,7 +7,7 @@ toolchain: - xtools - zephyr ram: 128 -flash: 192 +flash: 256 supported: - i2c - pwm diff --git a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_partition_conf.dtsi b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_partition_conf.dtsi index b14640a02ec..3588a6a7ce1 100644 --- a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_partition_conf.dtsi +++ b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_partition_conf.dtsi @@ -22,19 +22,19 @@ */ &slot0_partition { - reg = <0x00010000 0x40000>; + reg = <0x0000c000 0x30000>; }; &slot0_ns_partition { - reg = <0x00050000 0x30000>; + reg = <0x0003e000 0x40000>; }; &slot1_partition { - reg = <0x00080000 0x40000>; + reg = <0x0007e000 0x30000>; }; &slot1_ns_partition { - reg = <0x000c0000 0x30000>; + reg = <0x000b0000 0x40000>; }; /* Default SRAM planning when building for nRF9160 with diff --git a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dtsi b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dtsi index 2658ee5eaa4..b85c00ea5b2 100644 --- a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dtsi +++ b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dtsi @@ -185,19 +185,22 @@ slot0_partition: partition@10000 { label = "image-0"; }; - slot0_ns_partition: partition@50000 { + slot0_ns_partition: partition@40000 { label = "image-0-nonsecure"; }; slot1_partition: partition@80000 { label = "image-1"; }; - slot1_ns_partition: partition@c0000 { + slot1_ns_partition: partition@b0000 { label = "image-1-nonsecure"; }; - /* 0xf0000 to 0xf7fff reserved for TF-M partitions */ - storage_partition: partition@f8000 { + scratch_partition: partition@f0000 { + label = "image-scratch"; + reg = <0x000f0000 0xa000>; + }; + storage_partition: partition@fa000 { label = "storage"; - reg = <0x000f8000 0x00008000>; + reg = <0x000fa000 0x00006000>; }; }; }; diff --git a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_ns.yaml b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_ns.yaml index adbef49e2b0..e667a231774 100644 --- a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_ns.yaml +++ b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_ns.yaml @@ -7,7 +7,7 @@ toolchain: - xtools - zephyr ram: 128 -flash: 192 +flash: 256 supported: - i2c - pwm diff --git a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_partition_conf.dtsi b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_partition_conf.dtsi index 64591fbf900..2422b2fdc52 100644 --- a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_partition_conf.dtsi +++ b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_partition_conf.dtsi @@ -23,19 +23,19 @@ */ &slot0_partition { - reg = <0x00010000 0x40000>; + reg = <0x00010000 0x30000>; }; &slot0_ns_partition { - reg = <0x00050000 0x30000>; + reg = <0x00040000 0x40000>; }; &slot1_partition { - reg = <0x00080000 0x40000>; + reg = <0x00080000 0x30000>; }; &slot1_ns_partition { - reg = <0x000c0000 0x30000>; + reg = <0x000b0000 0x40000>; }; /* Default SRAM planning when building for nRF9160 with From 8f4dc248b507ce3d5c512153809839a62cf516e0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:39 +0000 Subject: [PATCH 0596/1623] Revert "[nrf fromtree] doc: Remove note for missing tf-m/ns target support" This reverts commit 5d85f6db2d5ec50922e809238e3b088da5727dcf. Signed-off-by: Dominik Ermel --- boards/arm/nrf5340_audio_dk_nrf5340/doc/index.rst | 3 +++ boards/arm/nrf9160_innblue21/doc/index.rst | 3 +++ boards/arm/nrf9160_innblue22/doc/index.rst | 3 +++ boards/arm/sparkfun_thing_plus_nrf9160/doc/index.rst | 3 +++ boards/arm/thingy53_nrf5340/doc/index.rst | 3 +++ 5 files changed, 15 insertions(+) diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/doc/index.rst b/boards/arm/nrf5340_audio_dk_nrf5340/doc/index.rst index 3d8d2413e91..7718258eec2 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/doc/index.rst +++ b/boards/arm/nrf5340_audio_dk_nrf5340/doc/index.rst @@ -53,6 +53,9 @@ The nrf5340_audio_dk_nrf5340_cpuapp build target provides support for the applic core on the nRF5340 SoC. The nrf5340_audio_dk_nrf5340_cpunet build target provides support for the network core on the nRF5340 SoC. +.. note:: + Trusted Firmware-M (TF-M) and building the ``ns`` target is not supported for this board. + The `Nordic Semiconductor Infocenter`_ contains the processor's information and the datasheet. diff --git a/boards/arm/nrf9160_innblue21/doc/index.rst b/boards/arm/nrf9160_innblue21/doc/index.rst index 9ded085dc6f..628166c409c 100644 --- a/boards/arm/nrf9160_innblue21/doc/index.rst +++ b/boards/arm/nrf9160_innblue21/doc/index.rst @@ -104,6 +104,9 @@ have to set the IDAU (SPU) configuration to allow Non-Secure access to all CPU resources utilized by the Non-Secure application firmware. SPU configuration shall take place before jumping to the Non-Secure application. +.. note:: + Trusted Firmware-M (TF-M) and building the ``ns`` target is not supported for this board. + Building a Secure only application ================================== diff --git a/boards/arm/nrf9160_innblue22/doc/index.rst b/boards/arm/nrf9160_innblue22/doc/index.rst index 06f6b6326f8..ce3eb35d60f 100644 --- a/boards/arm/nrf9160_innblue22/doc/index.rst +++ b/boards/arm/nrf9160_innblue22/doc/index.rst @@ -104,6 +104,9 @@ have to set the IDAU (SPU) configuration to allow Non-Secure access to all CPU resources utilized by the Non-Secure application firmware. SPU configuration shall take place before jumping to the Non-Secure application. +.. note:: + Trusted Firmware-M (TF-M) and building the ``ns`` target is not supported for this board. + Building a Secure only application ================================== diff --git a/boards/arm/sparkfun_thing_plus_nrf9160/doc/index.rst b/boards/arm/sparkfun_thing_plus_nrf9160/doc/index.rst index aa1a0e6279d..44366c49a39 100644 --- a/boards/arm/sparkfun_thing_plus_nrf9160/doc/index.rst +++ b/boards/arm/sparkfun_thing_plus_nrf9160/doc/index.rst @@ -91,6 +91,9 @@ Building an application In most cases you'll want to use the ``ns`` target with any of the Zephyr or Nordic based examples. +.. note:: + Trusted Firmware-M (TF-M) and building the ``ns`` target is not supported for this board. + Some of the examples do not use secure mode, so they do not required the ``ns`` suffix. A great example of this is the `hello_world` below. diff --git a/boards/arm/thingy53_nrf5340/doc/index.rst b/boards/arm/thingy53_nrf5340/doc/index.rst index 4544ea7ed79..3a77deee968 100644 --- a/boards/arm/thingy53_nrf5340/doc/index.rst +++ b/boards/arm/thingy53_nrf5340/doc/index.rst @@ -22,6 +22,9 @@ The nrf5340dk_nrf5340_cpuapp build target provides support for the application core on the nRF5340 SoC. The nrf5340dk_nrf5340_cpunet build target provides support for the network core on the nRF5340 SoC. +.. note:: + Trusted Firmware-M (TF-M) and building the ``ns`` target is not supported for this board. + The `Nordic Semiconductor Infocenter`_ contains the processor's information and the datasheet. From bf18e1b3d0d4ea11860eb0e47abe10da0dd536aa Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:39 +0000 Subject: [PATCH 0597/1623] Revert "[nrf fromtree] boards: Enable TF-M by default for nordic SoC NS boards" This reverts commit 4a3c39feef9ad6dcbb8fbe787f4aef5cc57fdbb3. Signed-off-by: Dominik Ermel --- boards/arm/bl5340_dvk/Kconfig.defconfig | 15 +++++++++++++++ boards/arm/nrf5340dk_nrf5340/Kconfig.defconfig | 15 +++++++++++++++ boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig | 15 +++++++++++++++ boards/arm/nrf9161dk_nrf9161/Kconfig.defconfig | 15 +++++++++++++++ soc/arm/nordic_nrf/Kconfig | 18 +----------------- 5 files changed, 61 insertions(+), 17 deletions(-) diff --git a/boards/arm/bl5340_dvk/Kconfig.defconfig b/boards/arm/bl5340_dvk/Kconfig.defconfig index e033f718dba..38a06c8b91d 100644 --- a/boards/arm/bl5340_dvk/Kconfig.defconfig +++ b/boards/arm/bl5340_dvk/Kconfig.defconfig @@ -13,6 +13,21 @@ config BOARD config I2C default GPIO || DAC +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_BL5340_DVK_CPUAPP_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + # Code Partition: # # For the secure version of the board the firmware is linked at the beginning diff --git a/boards/arm/nrf5340dk_nrf5340/Kconfig.defconfig b/boards/arm/nrf5340dk_nrf5340/Kconfig.defconfig index 09ebfbf50ba..d337e2f1a1c 100644 --- a/boards/arm/nrf5340dk_nrf5340/Kconfig.defconfig +++ b/boards/arm/nrf5340dk_nrf5340/Kconfig.defconfig @@ -8,6 +8,21 @@ if BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_NRF5340DK_NRF5340_CPUAPP_NS config BOARD default "nrf5340dk_nrf5340_cpuapp" if BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_NRF5340DK_NRF5340_CPUAPP_NS +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_NRF5340DK_NRF5340_CPUAPP_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + # Code Partition: # # For the secure version of the board the firmware is linked at the beginning diff --git a/boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig b/boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig index 7d9046f63b5..cd052dc7a20 100644 --- a/boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig +++ b/boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig @@ -8,6 +8,21 @@ if BOARD_NRF9160DK_NRF9160 || BOARD_NRF9160DK_NRF9160_NS config BOARD default "nrf9160dk_nrf9160" +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_NRF9160DK_NRF9160_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + # For the secure version of the board the firmware is linked at the beginning # of the flash, or into the code-partition defined in DT if it is intended to # be loaded by MCUboot. If the secure firmware is to be combined with a non- diff --git a/boards/arm/nrf9161dk_nrf9161/Kconfig.defconfig b/boards/arm/nrf9161dk_nrf9161/Kconfig.defconfig index ea7150ede5f..2674e87cad4 100644 --- a/boards/arm/nrf9161dk_nrf9161/Kconfig.defconfig +++ b/boards/arm/nrf9161dk_nrf9161/Kconfig.defconfig @@ -8,6 +8,21 @@ if BOARD_NRF9161DK_NRF9161 || BOARD_NRF9161DK_NRF9161_NS config BOARD default "nrf9161dk_nrf9161" +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_NRF9161DK_NRF9161_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + # For the secure version of the board the firmware is linked at the beginning # of the flash, or into the code-partition defined in DT if it is intended to # be loaded by MCUboot. If the secure firmware is to be combined with a non- diff --git a/soc/arm/nordic_nrf/Kconfig b/soc/arm/nordic_nrf/Kconfig index 19e49c05454..0e3b3e4ee6d 100644 --- a/soc/arm/nordic_nrf/Kconfig +++ b/soc/arm/nordic_nrf/Kconfig @@ -25,29 +25,13 @@ config NRF_SOC_SECURE_SUPPORTED For non-secure the functions must redirect to secure services exposed by the secure firmware. -config BUILD_WITH_TFM - default y if TRUSTED_EXECUTION_NONSECURE - help - By default, if we build for a Non-Secure version of the board, - enable building with TF-M as the Secure Execution Environment. - -if BUILD_WITH_TFM - -config TFM_FLASH_MERGED_BINARY - default y - help - By default, if we build with TF-M, instruct build system to - flash the combined TF-M (Secure) & Zephyr (Non Secure) image - config TFM_LOG_LEVEL_SILENCE default y if !$(dt_nodelabel_has_prop,uart1,pinctrl-names) + depends on BUILD_WITH_TFM help Disable TF-M secure output if the uart1 node has not assigned GPIO pins using pinctrl. -endif # BUILD_WITH_TFM - - config NRF_MPU_FLASH_REGION_SIZE hex default 0x1000 From 18cf61dae8120d792b83d3d13aaa5296d5cdc366 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:39 +0000 Subject: [PATCH 0598/1623] Revert "[nrf fromtree] tfm: nordic_nrf: Add generic SoC support for nordic SoCs" This reverts commit 9184096bd977feb4c31608ab67a3a47468e748c5. Signed-off-by: Dominik Ermel --- modules/trusted-firmware-m/Kconfig.tfm | 6 +- .../nordic_nrf/CMakeLists.txt | 67 ------------------- .../nordic_nrf/include/RTE_Device.h | 52 -------------- .../nordic_nrf/include/device_cfg.h | 32 --------- .../nordic_nrf/include/tfm_ioctl_api.h | 32 --------- .../include/tfm_peripherals_config.h | 40 ----------- .../nordic_nrf/include/tfm_read_ranges.h | 60 ----------------- .../nordic_nrf/include/util/array.h | 20 ------ .../nordic_nrf/nrf5340_cpuapp/CMakeLists.txt | 12 ---- .../nordic_nrf/nrf5340_cpuapp/config.cmake | 8 --- .../nordic_nrf/nrf5340_cpuapp/preload.cmake | 7 -- .../nordic_nrf/nrf9120/CMakeLists.txt | 12 ---- .../nordic_nrf/nrf9120/config.cmake | 8 --- .../nordic_nrf/nrf9120/preload.cmake | 7 -- .../nordic_nrf/nrf9160/CMakeLists.txt | 12 ---- .../nordic_nrf/nrf9160/config.cmake | 8 --- .../nordic_nrf/nrf9160/preload.cmake | 7 -- .../nordic_nrf/src/tfm_hal_platform.c | 13 ---- .../nordic_nrf/src/tfm_platform_system.c | 38 ----------- soc/arm/nordic_nrf/CMakeLists.txt | 4 -- soc/arm/nordic_nrf/Kconfig | 7 -- 21 files changed, 3 insertions(+), 449 deletions(-) delete mode 100644 modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt delete mode 100644 modules/trusted-firmware-m/nordic_nrf/include/RTE_Device.h delete mode 100644 modules/trusted-firmware-m/nordic_nrf/include/device_cfg.h delete mode 100644 modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h delete mode 100644 modules/trusted-firmware-m/nordic_nrf/include/tfm_peripherals_config.h delete mode 100644 modules/trusted-firmware-m/nordic_nrf/include/tfm_read_ranges.h delete mode 100644 modules/trusted-firmware-m/nordic_nrf/include/util/array.h delete mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt delete mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake delete mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/preload.cmake delete mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt delete mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake delete mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9120/preload.cmake delete mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt delete mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake delete mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9160/preload.cmake delete mode 100644 modules/trusted-firmware-m/nordic_nrf/src/tfm_hal_platform.c delete mode 100644 modules/trusted-firmware-m/nordic_nrf/src/tfm_platform_system.c diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index 7fd1b348a74..a7276d79374 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -9,6 +9,9 @@ config ZEPHYR_TRUSTED_FIRMWARE_M_MODULE config TFM_BOARD string + default "nordic_nrf/nrf9160dk_nrf9160" if BOARD_NRF9160DK_NRF9160_NS + default "nordic_nrf/nrf9161dk_nrf9161" if BOARD_NRF9161DK_NRF9161_NS + default "nordic_nrf/nrf5340dk_nrf5340_cpuapp" if BOARD_NRF5340DK_NRF5340_CPUAPP_NS default "nxp/lpcxpresso55s69" if BOARD_LPCXPRESSO55S69_CPU0 default "arm/mps2/an521" if BOARD_MPS2_AN521_CPU0_NS default "arm/mps3/an547" if BOARD_MPS3_AN547 @@ -18,9 +21,6 @@ config TFM_BOARD default "arm/musca_b1" if BOARD_MUSCA_B1 default "arm/musca_s1" if BOARD_MUSCA_S1 default "lairdconnectivity/bl5340_dvk_cpuapp" if BOARD_BL5340_DVK_CPUAPP_NS - default "${ZEPHYR_BASE}/modules/trusted-firmware-m/nordic_nrf/nrf9160" if SOC_NRF9160 - default "${ZEPHYR_BASE}/modules/trusted-firmware-m/nordic_nrf/nrf9120" if SOC_NRF9120 - default "${ZEPHYR_BASE}/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp" if SOC_NRF5340_CPUAPP help The board name used for building TFM. Building with TFM requires that TFM has been ported to the given board/SoC. diff --git a/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt deleted file mode 100644 index 41dca2f15a9..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -# -# Copyright (c) 2023, Nordic Semiconductor ASA. -# -# SPDX-License-Identifier: Apache-2.0 -# - -cmake_policy(SET CMP0076 NEW) -set(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}) - -set(partition_includes - ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/${NRF_SOC_VARIANT}/partition - ${CMAKE_BINARY_DIR}/../zephyr/include/generated -) - -set(board_includes - ${CMAKE_BINARY_DIR}/../zephyr/misc/generated/syscalls_links/include - ${ZEPHYR_BASE}/include -) - -target_include_directories(platform_region_defs - INTERFACE - ${partition_includes} -) - - -target_sources(platform_s - PRIVATE - $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/tfm_platform_system.c> -) - -target_include_directories(platform_s - PUBLIC - services/include - include - ${partition_includes} - ${board_includes} -) - -target_include_directories(platform_ns - PUBLIC - include - include/util - ${partition_includes} - ${board_includes} -) - -if(BL2) - target_include_directories(platform_bl2 - PUBLIC - include - include/util - ${partition_includes} - ${board_includes} - ) -endif() - -if (TFM_PARTITION_PLATFORM) -install(FILES include/tfm_ioctl_api.h - DESTINATION ${TFM_INSTALL_PATH}/interface/include) -endif() - -#========================= tfm_spm ============================================# - -target_sources(tfm_spm - PRIVATE - src/tfm_hal_platform.c -) diff --git a/modules/trusted-firmware-m/nordic_nrf/include/RTE_Device.h b/modules/trusted-firmware-m/nordic_nrf/include/RTE_Device.h deleted file mode 100644 index ca886583fa9..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/include/RTE_Device.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __RTE_DEVICE_H -#define __RTE_DEVICE_H - -#include - -/* ARRAY_SIZE causes a conflict as it is defined both by TF-M and indirectly by devicetree.h */ -#undef ARRAY_SIZE -#include - -#define UART_PIN_INIT(node_id, prop, idx) \ - DT_PROP_BY_IDX(node_id, prop, idx), - -/* Configuration settings for Driver_USART0. */ -#if DOMAIN_NS == 1U - -#define RTE_USART0 1 - -#define RTE_USART0_PINS \ -{ \ - DT_FOREACH_CHILD_VARGS( \ - DT_PINCTRL_BY_NAME(DT_NODELABEL(uart0), default, 0), \ - DT_FOREACH_PROP_ELEM, psels, UART_PIN_INIT \ - ) \ -} - -#endif - -/* Configuration settings for Driver_USART1. */ -#if DT_PINCTRL_HAS_NAME(DT_NODELABEL(uart1), default) && DOMAIN_NS != 1U - -#define RTE_USART1 1 - -#define RTE_USART1_PINS \ -{ \ - DT_FOREACH_CHILD_VARGS( \ - DT_PINCTRL_BY_NAME(DT_NODELABEL(uart1), default, 0), \ - DT_FOREACH_PROP_ELEM, psels, UART_PIN_INIT \ - ) \ -} - -#endif - -/* Configuration settings for Driver_FLASH0. */ -#define RTE_FLASH0 1 - -#endif /* __RTE_DEVICE_H */ diff --git a/modules/trusted-firmware-m/nordic_nrf/include/device_cfg.h b/modules/trusted-firmware-m/nordic_nrf/include/device_cfg.h deleted file mode 100644 index 9b766a35eb9..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/include/device_cfg.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef DEVICE_CFG_H__ -#define DEVICE_CFG_H__ - -#include - -/* ARRAY_SIZE causes a conflict as it is defined both by TF-M and indirectly by devicetree.h */ -#undef ARRAY_SIZE -#include - -#if DOMAIN_NS == 1U -#define TFM_UART uart0 -#endif - -#if DOMAIN_NS != 1U -#define TFM_UART uart1 -#endif - -#define DEFAULT_UART_BAUDRATE DT_PROP_OR(DT_NODELABEL(TFM_UART), current_speed, 115200) - -#if DT_PROP(DT_NODELABEL(TFM_UART), hw_flow_control) -#define DEFAULT_UART_CONTROL ARM_USART_FLOW_CONTROL_RTS_CTS -#else -#define DEFAULT_UART_CONTROL 0 -#endif - -#endif /* DEVICE_CFG_H__ */ diff --git a/modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h b/modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h deleted file mode 100644 index c6c36ee927f..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef TFM_IOCTL_API_H__ -#define TFM_IOCTL_API_H__ - -#include -#include -#include -#include - -/* Include core IOCTL services */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Board specific IOCTL services can be added here */ - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ - -#endif /* TFM_IOCTL_API_H__ */ diff --git a/modules/trusted-firmware-m/nordic_nrf/include/tfm_peripherals_config.h b/modules/trusted-firmware-m/nordic_nrf/include/tfm_peripherals_config.h deleted file mode 100644 index 577b583ad03..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/include/tfm_peripherals_config.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef TFM_PERIPHERALS_CONFIG_H__ -#define TFM_PERIPHERALS_CONFIG_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef SECURE_UART1 -#define TFM_PERIPHERAL_UARTE1_SECURE 1 -#endif - -#if TEST_NS_SLIH_IRQ || TEST_NS_FLIH_IRQ -#define TFM_PERIPHERAL_TIMER0_SECURE 1 -#endif - -#ifdef PSA_API_TEST_IPC -#define TFM_PERIPHERAL_EGU5_SECURE 1 - -#define TFM_PERIPHERAL_WDT_SECURE 1 -#endif - -#if defined(NRF91_SERIES) - #include -#elif defined(NRF5340_XXAA_APPLICATION) - #include -#else - #error "Unknown device." -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* TFM_PERIPHERAL_CONFIG_H__ */ diff --git a/modules/trusted-firmware-m/nordic_nrf/include/tfm_read_ranges.h b/modules/trusted-firmware-m/nordic_nrf/include/tfm_read_ranges.h deleted file mode 100644 index 43468c7fa31..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/include/tfm_read_ranges.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef TFM_READ_RANGES_H__ -#define TFM_READ_RANGES_H__ - -#include - -#include - -#ifdef NRF_FICR_S_BASE - -#define FICR_BASE NRF_FICR_S_BASE - -#define FICR_INFO_ADDR (FICR_BASE + offsetof(NRF_FICR_Type, INFO)) -#define FICR_INFO_SIZE (sizeof(FICR_INFO_Type)) - -#if defined(FICR_NFC_TAGHEADER0_MFGID_Msk) -#define FICR_NFC_ADDR (FICR_BASE + offsetof(NRF_FICR_Type, NFC)) -#define FICR_NFC_SIZE (sizeof(FICR_NFC_Type)) -#endif - -#if defined(FICR_XOSC32MTRIM_SLOPE_Msk) -#define FICR_XOSC32MTRIM_ADDR (FICR_BASE + offsetof(NRF_FICR_Type, XOSC32MTRIM)) -#define FICR_XOSC32MTRIM_SIZE (sizeof(uint32_t)) -#endif - -/* Used by nrf_erratas.h */ -#define FICR_RESTRICTED_ADDR (FICR_BASE + 0x130) -#define FICR_RESTRICTED_SIZE 0x8 - -#if defined(FICR_SIPINFO_PARTNO_PARTNO_Pos) -#define FICR_SIPINFO_ADDR (FICR_BASE + offsetof(NRF_FICR_Type, SIPINFO)) -#define FICR_SIPINFO_SIZE (sizeof(FICR_SIPINFO_Type)) -#endif - -#endif /* NRF_FICR_S_BASE */ - -static const struct tfm_read_service_range ranges[] = { -#if defined(FICR_INFO_ADDR) - { .start = FICR_INFO_ADDR, .size = FICR_INFO_SIZE }, -#endif -#if defined(FICR_NFC_ADDR) - { .start = FICR_NFC_ADDR, .size = FICR_NFC_SIZE }, -#endif -#if defined(FICR_RESTRICTED_ADDR) - { .start = FICR_RESTRICTED_ADDR, .size = FICR_RESTRICTED_SIZE }, -#endif -#if defined(FICR_XOSC32MTRIM_ADDR) - { .start = FICR_XOSC32MTRIM_ADDR, .size = FICR_XOSC32MTRIM_SIZE }, -#endif -#if defined(FICR_SIPINFO_ADDR) - { .start = FICR_SIPINFO_ADDR, .size = FICR_SIPINFO_SIZE }, -#endif -}; - -#endif /* TFM_READ_RANGES_H__ */ diff --git a/modules/trusted-firmware-m/nordic_nrf/include/util/array.h b/modules/trusted-firmware-m/nordic_nrf/include/util/array.h deleted file mode 100644 index dc9a1f3dddf..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/include/util/array.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __ARRAY_H__ -#define __ARRAY_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __cplusplus -} -#endif - -#endif /* __ARRAY_H__ */ diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt deleted file mode 100644 index 279ea385996..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright (c) 2023, Nordic Semiconductor ASA. -# -# SPDX-License-Identifier: Apache-2.0 -# - -set(NRF_BOARD_SELECTED True) -set(NRF_SOC_VARIANT nrf5340) - -add_subdirectory(${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/nrf5340 nrf5340) - -add_subdirectory(.. common) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake deleted file mode 100644 index b3e5d74181c..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake +++ /dev/null @@ -1,8 +0,0 @@ -# -# Copyright (c) 2023, Nordic Semiconductor ASA. -# -# SPDX-License-Identifier: Apache-2.0 -# - -set(PLATFORM_PATH platform/ext/target/nordic_nrf/) -include(${PLATFORM_PATH}/common/nrf5340/config.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/preload.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/preload.cmake deleted file mode 100644 index d9bd226eb65..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/preload.cmake +++ /dev/null @@ -1,7 +0,0 @@ -# -# Copyright (c) 2023, Nordic Semiconductor ASA. -# -# SPDX-License-Identifier: Apache-2.0 -# - -include(platform/ext/target/nordic_nrf/common/nrf5340/preload.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt deleted file mode 100644 index a84c6fd9fd5..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright (c) 2023, Nordic Semiconductor ASA. -# -# SPDX-License-Identifier: Apache-2.0 -# - -set(NRF_BOARD_SELECTED True) -set(NRF_SOC_VARIANT nrf91) - -add_subdirectory(${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/nrf91 nrf91) - -add_subdirectory(.. common) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake deleted file mode 100644 index 3f58e7b89eb..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake +++ /dev/null @@ -1,8 +0,0 @@ -# -# Copyright (c) 2023, Nordic Semiconductor ASA. -# -# SPDX-License-Identifier: Apache-2.0 -# - -set(PLATFORM_PATH platform/ext/target/nordic_nrf/) -include(${PLATFORM_PATH}/common/nrf91/config.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/preload.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9120/preload.cmake deleted file mode 100644 index 4b3c6ee79ab..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9120/preload.cmake +++ /dev/null @@ -1,7 +0,0 @@ -# -# Copyright (c) 2023, Nordic Semiconductor ASA. -# -# SPDX-License-Identifier: Apache-2.0 -# - -include(platform/ext/target/nordic_nrf/common/nrf9120/preload.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt deleted file mode 100644 index a84c6fd9fd5..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright (c) 2023, Nordic Semiconductor ASA. -# -# SPDX-License-Identifier: Apache-2.0 -# - -set(NRF_BOARD_SELECTED True) -set(NRF_SOC_VARIANT nrf91) - -add_subdirectory(${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/nrf91 nrf91) - -add_subdirectory(.. common) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake deleted file mode 100644 index 3f58e7b89eb..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake +++ /dev/null @@ -1,8 +0,0 @@ -# -# Copyright (c) 2023, Nordic Semiconductor ASA. -# -# SPDX-License-Identifier: Apache-2.0 -# - -set(PLATFORM_PATH platform/ext/target/nordic_nrf/) -include(${PLATFORM_PATH}/common/nrf91/config.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/preload.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9160/preload.cmake deleted file mode 100644 index 364480a6f7f..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9160/preload.cmake +++ /dev/null @@ -1,7 +0,0 @@ -# -# Copyright (c) 2023, Nordic Semiconductor ASA. -# -# SPDX-License-Identifier: Apache-2.0 -# - -include(platform/ext/target/nordic_nrf/common/nrf9160/preload.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/src/tfm_hal_platform.c b/modules/trusted-firmware-m/nordic_nrf/src/tfm_hal_platform.c deleted file mode 100644 index 508c1945910..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/src/tfm_hal_platform.c +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "tfm_hal_defs.h" -#include "tfm_hal_platform_common.h" - -enum tfm_hal_status_t tfm_hal_platform_init(void) -{ - return tfm_hal_platform_common_init(); -} diff --git a/modules/trusted-firmware-m/nordic_nrf/src/tfm_platform_system.c b/modules/trusted-firmware-m/nordic_nrf/src/tfm_platform_system.c deleted file mode 100644 index b96e1fe1188..00000000000 --- a/modules/trusted-firmware-m/nordic_nrf/src/tfm_platform_system.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "platform/include/tfm_platform_system.h" -#include "cmsis.h" -#include "tfm_platform_hal_ioctl.h" -#include "tfm_ioctl_core_api.h" - -void tfm_platform_hal_system_reset(void) -{ - /* Reset the system */ - NVIC_SystemReset(); -} - -enum tfm_platform_err_t tfm_platform_hal_ioctl(tfm_platform_ioctl_req_t request, - psa_invec *in_vec, - psa_outvec *out_vec) -{ - /* Core IOCTL services */ - switch (request) { - case TFM_PLATFORM_IOCTL_READ_SERVICE: - return tfm_platform_hal_read_service(in_vec, out_vec); -#if defined(GPIO_PIN_CNF_MCUSEL_Msk) - case TFM_PLATFORM_IOCTL_GPIO_SERVICE: - return tfm_platform_hal_gpio_service(in_vec, out_vec); -#endif /* defined(GPIO_PIN_CNF_MCUSEL_Msk) */ - - - /* Board specific IOCTL services */ - - /* Not a supported IOCTL service.*/ - default: - return TFM_PLATFORM_ERR_NOT_SUPPORTED; - } -} diff --git a/soc/arm/nordic_nrf/CMakeLists.txt b/soc/arm/nordic_nrf/CMakeLists.txt index 47364b35ffb..4cfc162f7fd 100644 --- a/soc/arm/nordic_nrf/CMakeLists.txt +++ b/soc/arm/nordic_nrf/CMakeLists.txt @@ -21,8 +21,4 @@ if(CONFIG_BUILD_WITH_TFM) set_property(TARGET zephyr_property_target APPEND PROPERTY TFM_CMAKE_OPTIONS -DHAL_NORDIC_PATH=${ZEPHYR_HAL_NORDIC_MODULE_DIR} ) - - set_property(TARGET zephyr_property_target - APPEND PROPERTY TFM_CMAKE_OPTIONS -DZEPHYR_BASE=${ZEPHYR_BASE} - ) endif() diff --git a/soc/arm/nordic_nrf/Kconfig b/soc/arm/nordic_nrf/Kconfig index 0e3b3e4ee6d..c2129db64b3 100644 --- a/soc/arm/nordic_nrf/Kconfig +++ b/soc/arm/nordic_nrf/Kconfig @@ -25,13 +25,6 @@ config NRF_SOC_SECURE_SUPPORTED For non-secure the functions must redirect to secure services exposed by the secure firmware. -config TFM_LOG_LEVEL_SILENCE - default y if !$(dt_nodelabel_has_prop,uart1,pinctrl-names) - depends on BUILD_WITH_TFM - help - Disable TF-M secure output if the uart1 node has not assigned GPIO - pins using pinctrl. - config NRF_MPU_FLASH_REGION_SIZE hex default 0x1000 From 8c91a73bf83809029b94068bc1a6be3384b05bff Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:39 +0000 Subject: [PATCH 0599/1623] Revert "[nrf fromtree] boards: Add uart1 pinctrl assignment to nrf5340 Audio DK" This reverts commit cf504c0167559b0ed749e6fee8c07fb153658db9. Signed-off-by: Dominik Ermel --- ...udio_dk_nrf5340_cpuapp_common-pinctrl.dtsi | 22 ------------------- ...rf5340_audio_dk_nrf5340_cpuapp_common.dtsi | 8 ------- 2 files changed, 30 deletions(-) diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common-pinctrl.dtsi b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common-pinctrl.dtsi index 5247c04429b..46359082edd 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common-pinctrl.dtsi +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common-pinctrl.dtsi @@ -51,28 +51,6 @@ }; }; - uart1_default: uart1_default { - group1 { - psels = , - ; - }; - group2 { - psels = , - ; - bias-pull-up; - }; - }; - - uart1_sleep: uart1_sleep { - group1 { - psels = , - , - , - ; - low-power-enable; - }; - }; - i2c1_default: i2c1_default { group1 { psels = , diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi index df028fb75a2..f529f16fbe8 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi @@ -141,14 +141,6 @@ pinctrl-names = "default", "sleep"; }; -arduino_serial: &uart1 { - compatible = "nordic,nrf-uarte"; - current-speed = <115200>; - pinctrl-0 = <&uart1_default>; - pinctrl-1 = <&uart1_sleep>; - pinctrl-names = "default", "sleep"; -}; - &i2c1 { compatible = "nordic,nrf-twim"; status = "okay"; From 493a47f15958699cea3aa35863b883e6800ffd96 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:40 +0000 Subject: [PATCH 0600/1623] Revert "[nrf fromtree] boards: nrf5340dk_nrf5340: Add default HW flow control pins to uart1" This reverts commit e0fab0305912c36f631b3ad55f4e8ffbf53bb450. Signed-off-by: Dominik Ermel --- .../nrf5340_cpuapp_common-pinctrl.dtsi | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common-pinctrl.dtsi b/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common-pinctrl.dtsi index f93e3a69402..6db9767c0dc 100644 --- a/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common-pinctrl.dtsi +++ b/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common-pinctrl.dtsi @@ -84,12 +84,10 @@ uart1_default: uart1_default { group1 { - psels = , - ; + psels = ; }; group2 { - psels = , - ; + psels = ; bias-pull-up; }; }; @@ -97,9 +95,7 @@ uart1_sleep: uart1_sleep { group1 { psels = , - , - , - ; + ; low-power-enable; }; }; From c8a1b762ef06ab459fc8ed183f95dce92e338bbb Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:40 +0000 Subject: [PATCH 0601/1623] Revert "[nrf fromtree] drivers: serial: serial_test.c: Patch 64-bit incompat" This reverts commit f1ee732cab5ebaa83ddf94f0d4c6f734d2684ea7. Signed-off-by: Dominik Ermel --- drivers/serial/serial_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/serial/serial_test.c b/drivers/serial/serial_test.c index b1bb46228be..b1661cdfeef 100644 --- a/drivers/serial/serial_test.c +++ b/drivers/serial/serial_test.c @@ -404,7 +404,7 @@ static int serial_vnd_rx_enable(const struct device *dev, uint8_t *read_buf, siz { struct serial_vnd_data *data = dev->data; - LOG_WRN("read_size %zd", read_size); + LOG_WRN("read_size %d", read_size); if (data == NULL) { return -ENOTSUP; From 5fbfdf9813cced1aa231178e5ee4b346233fb776 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:40 +0000 Subject: [PATCH 0602/1623] Revert "[nrf fromtree] tests: drivers: modem: Specify targets for cellular" This reverts commit 2370c3921324b0f0a5b85979e4fdb13f5fb03f8a. Signed-off-by: Dominik Ermel --- tests/drivers/build_all/modem/testcase.yaml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/drivers/build_all/modem/testcase.yaml b/tests/drivers/build_all/modem/testcase.yaml index 8b42363b4ff..3614cb09655 100644 --- a/tests/drivers/build_all/modem/testcase.yaml +++ b/tests/drivers/build_all/modem/testcase.yaml @@ -74,9 +74,10 @@ tests: - CONFIG_MODEM_IFACE_UART_ASYNC=y drivers.modem.modem_cellular.build: extra_args: CONF_FILE=modem_cellular.conf - platform_allow: - - native_posix_64 - - native_posix - - qemu_x86 - - qemu_x86_64 + platform_exclude: + - serpente + - particle_boron + - rak5010_nrf52840 + - litex_vexriscv + - ip_k66f min_ram: 36 From 30056531a8c650ffbea101ce50c96d8a814d6726 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:40 +0000 Subject: [PATCH 0603/1623] Revert "[nrf fromtree] drivers: serial: serial_test: Move ring buf dep to Kconfig" This reverts commit 4748e5ed0abaa6e6d9c9e489e16608a9ae2216bf. Signed-off-by: Dominik Ermel --- drivers/serial/Kconfig.test | 1 - drivers/serial/serial_test.c | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/serial/Kconfig.test b/drivers/serial/Kconfig.test index e7f38edc591..5e7353ba65a 100644 --- a/drivers/serial/Kconfig.test +++ b/drivers/serial/Kconfig.test @@ -8,4 +8,3 @@ config SERIAL_TEST select SERIAL_HAS_DRIVER select SERIAL_SUPPORT_INTERRUPT select SERIAL_SUPPORT_ASYNC - select RING_BUFFER if (UART_INTERRUPT_DRIVEN || UART_ASYNC_API) diff --git a/drivers/serial/serial_test.c b/drivers/serial/serial_test.c index b1661cdfeef..f18421b00e5 100644 --- a/drivers/serial/serial_test.c +++ b/drivers/serial/serial_test.c @@ -21,6 +21,9 @@ LOG_MODULE_REGISTER(mock_serial, CONFIG_LOG_DEFAULT_LEVEL); +BUILD_ASSERT(!IS_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN) || IS_ENABLED(CONFIG_RING_BUFFER)); +BUILD_ASSERT(!IS_ENABLED(CONFIG_UART_ASYNC_API) || IS_ENABLED(CONFIG_RING_BUFFER)); + #define DT_DRV_COMPAT vnd_serial struct serial_vnd_data { #ifdef CONFIG_RING_BUFFER From 7d8fdbead525a43d8ef6ddbd645091caef8cc978 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:40 +0000 Subject: [PATCH 0604/1623] Revert "[nrf fromtree] drivers: serial: serial_test: Patch irq_isr set to undefined" This reverts commit 757f63ca7660671b008071e7e4eb504660b7c95d. Signed-off-by: Dominik Ermel --- drivers/serial/serial_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/serial/serial_test.c b/drivers/serial/serial_test.c index f18421b00e5..2ce4fb50f38 100644 --- a/drivers/serial/serial_test.c +++ b/drivers/serial/serial_test.c @@ -318,7 +318,7 @@ static int serial_vnd_callback_set(const struct device *dev, uart_callback_t cal } #if defined(CONFIG_UART_EXCLUSIVE_API_CALLBACKS) && defined(CONFIG_UART_INTERRUPT_DRIVEN) - data->irq_isr = NULL; + data->irq_isr = cb; #endif if (callback == NULL && data->read_buf) { From 622a562a00dfff161faaaf6785361caaeafad84f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:41 +0000 Subject: [PATCH 0605/1623] Revert "[nrf fromtree] tests: build_all: modem: Patch dependencies preventing build" This reverts commit 064421793433e85e7df854343f88d725673d3e14. Signed-off-by: Dominik Ermel --- tests/drivers/build_all/modem/modem_cellular.conf | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/drivers/build_all/modem/modem_cellular.conf b/tests/drivers/build_all/modem/modem_cellular.conf index 3366fcf32d4..e541af07e2d 100644 --- a/tests/drivers/build_all/modem/modem_cellular.conf +++ b/tests/drivers/build_all/modem/modem_cellular.conf @@ -1,10 +1,7 @@ CONFIG_TEST=y CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_SERIAL=y +CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_NETWORKING=y CONFIG_NET_L2_PPP=y CONFIG_MODEM=y -CONFIG_PM_DEVICE=y -CONFIG_MODEM_CELLULAR=y -CONFIG_UART_ASYNC_API=y -CONFIG_GPIO=y From 3d45163e2e8b09859070024ed4890c4d9d006569 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:41 +0000 Subject: [PATCH 0606/1623] Revert "[nrf fromtree] bluetooth: samples: Add hci_uart_async" This reverts commit 237e871f948cb64089ec9d792d9cc5dd3377b85d. Signed-off-by: Dominik Ermel --- .../bluetooth/hci_uart_async/CMakeLists.txt | 10 - samples/bluetooth/hci_uart_async/README.rst | 158 ------- samples/bluetooth/hci_uart_async/app.overlay | 31 -- .../bluetooth/hci_uart_async/debug.mixin.conf | 15 - samples/bluetooth/hci_uart_async/prj.conf | 25 -- samples/bluetooth/hci_uart_async/sample.yaml | 19 - .../hci_uart_async/src/hci_uart_async.c | 403 ------------------ samples/bluetooth/hci_uart_async/src/main.c | 11 - tests/bluetooth/hci_uart_async/CMakeLists.txt | 15 - tests/bluetooth/hci_uart_async/app.overlay | 11 - .../hci_uart_async/boards/native_posix.conf | 3 - tests/bluetooth/hci_uart_async/prj.conf | 10 - .../hci_uart_async/src/test_hci_uart_async.c | 238 ----------- tests/bluetooth/hci_uart_async/testcase.yaml | 6 - 14 files changed, 955 deletions(-) delete mode 100644 samples/bluetooth/hci_uart_async/CMakeLists.txt delete mode 100644 samples/bluetooth/hci_uart_async/README.rst delete mode 100644 samples/bluetooth/hci_uart_async/app.overlay delete mode 100644 samples/bluetooth/hci_uart_async/debug.mixin.conf delete mode 100644 samples/bluetooth/hci_uart_async/prj.conf delete mode 100644 samples/bluetooth/hci_uart_async/sample.yaml delete mode 100644 samples/bluetooth/hci_uart_async/src/hci_uart_async.c delete mode 100644 samples/bluetooth/hci_uart_async/src/main.c delete mode 100644 tests/bluetooth/hci_uart_async/CMakeLists.txt delete mode 100644 tests/bluetooth/hci_uart_async/app.overlay delete mode 100644 tests/bluetooth/hci_uart_async/boards/native_posix.conf delete mode 100644 tests/bluetooth/hci_uart_async/prj.conf delete mode 100644 tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c delete mode 100644 tests/bluetooth/hci_uart_async/testcase.yaml diff --git a/samples/bluetooth/hci_uart_async/CMakeLists.txt b/samples/bluetooth/hci_uart_async/CMakeLists.txt deleted file mode 100644 index fe45a9cc371..00000000000 --- a/samples/bluetooth/hci_uart_async/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(hci_uart_async) -target_sources(app PRIVATE - src/hci_uart_async.c - src/main.c -) diff --git a/samples/bluetooth/hci_uart_async/README.rst b/samples/bluetooth/hci_uart_async/README.rst deleted file mode 100644 index 75bf586868d..00000000000 --- a/samples/bluetooth/hci_uart_async/README.rst +++ /dev/null @@ -1,158 +0,0 @@ -.. _bluetooth-hci-uart-async-sample: - -Bluetooth: HCI UART based on ASYNC UART -####################################### - -Expose a Zephyr Bluetooth Controller over a standard Bluetooth HCI UART interface. - -This sample performs the same basic function as the HCI UART sample, but it uses the UART_ASYNC_API -instead of UART_INTERRUPT_DRIVEN API. Not all boards implement both UART APIs, so the board support -of the HCI UART sample may be different. - -Requirements -************ - -* A board with BLE support - -Default UART settings -********************* - -By default the controller builds use the following settings: - -* Baudrate: 1Mbit/s -* 8 bits, no parity, 1 stop bit -* Hardware Flow Control (RTS/CTS) enabled - -Building and Running -******************** - -This sample can be found under :zephyr_file:`samples/bluetooth/hci_uart_async` -in the Zephyr tree and is built as a standard Zephyr application. - -Using the controller with emulators and BlueZ -********************************************* - -The instructions below show how to use a Nordic nRF5x device as a Zephyr BLE -controller and expose it to Linux's BlueZ. - -First, make sure you have a recent BlueZ version installed by following the -instructions in the :ref:`bluetooth_bluez` section. - -Now build and flash the sample for the Nordic nRF5x board of your choice. -All of the Nordic Development Kits come with a Segger IC that provides a -debugger interface and a CDC ACM serial port bridge. More information can be -found in :ref:`nordic_segger`. - -For example, to build for the nRF52832 Development Kit: - -.. zephyr-app-commands:: - :zephyr-app: samples/bluetooth/hci_uart_async - :board: nrf52dk_nrf52832 - :goals: build flash - -.. _bluetooth-hci-uart-async-qemu-posix: - -Using the controller with QEMU and Native POSIX -=============================================== - -In order to use the HCI UART controller with QEMU or Native POSIX you will need -to attach it to the Linux Host first. To do so simply build the sample and -connect the UART to the Linux machine, and then attach it with this command: - -.. code-block:: console - - sudo btattach -B /dev/ttyACM0 -S 1000000 -R - -.. note:: - Depending on the serial port you are using you will need to modify the - ``/dev/ttyACM0`` string to point to the serial device your controller is - connected to. - -.. note:: - The ``-R`` flag passed to ``btattach`` instructs the kernel to avoid - interacting with the controller and instead just be aware of it in order - to proxy it to QEMU later. - -If you are running :file:`btmon` you should see a brief log showing how the -Linux kernel identifies the attached controller. - -Once the controller is attached follow the instructions in the -:ref:`bluetooth_qemu_posix` section to use QEMU with it. - -.. _bluetooth-hci-uart-async-bluez: - -Using the controller with BlueZ -=============================== - -In order to use the HCI UART controller with BlueZ you will need to attach it -to the Linux Host first. To do so simply build the sample and connect the -UART to the Linux machine, and then attach it with this command: - -.. code-block:: console - - sudo btattach -B /dev/ttyACM0 -S 1000000 - -.. note:: - Depending on the serial port you are using you will need to modify the - ``/dev/ttyACM0`` string to point to the serial device your controller is - connected to. - -If you are running :file:`btmon` you should see a comprehensive log showing how -BlueZ loads and initializes the attached controller. - -Once the controller is attached follow the instructions in the -:ref:`bluetooth_ctlr_bluez` section to use BlueZ with it. - -Debugging the controller -======================== - -The sample can be debugged using RTT since the UART is reserved used by this -application. To enable debug over RTT the debug configuration file can be used. - -.. code-block:: console - - west build samples/bluetooth/hci_uart_async -- -DEXTRA_CONFIG='debug.mixin.conf' - -Then attach RTT as described here: :ref:`Using Segger J-Link ` - -Using the controller with the Zephyr host -========================================= - -This describes how to hook up a board running this sample to a board running -an application that uses the Zephyr host. - -On the controller side, the `zephyr,bt-c2h-uart` DTS property (in the `chosen` -block) is used to select which uart device to use. For example if we want to -keep the console logs, we can keep console on uart0 and the HCI on uart1 like -so: - -.. code-block:: dts - - / { - chosen { - zephyr,console = &uart0; - zephyr,shell-uart = &uart0; - zephyr,bt-c2h-uart = &uart1; - }; - }; - -On the host application, some config options need to be used to select the H4 -driver instead of the built-in controller: - -.. code-block:: kconfig - - CONFIG_BT_HCI=y - CONFIG_BT_CTLR=n - CONFIG_BT_H4=y - -Similarly, the `zephyr,bt-uart` DTS property selects which uart to use: - -.. code-block:: dts - - / { - chosen { - zephyr,console = &uart0; - zephyr,shell-uart = &uart0; - zephyr,bt-uart = &uart1; - }; - }; diff --git a/samples/bluetooth/hci_uart_async/app.overlay b/samples/bluetooth/hci_uart_async/app.overlay deleted file mode 100644 index e9a282ad78c..00000000000 --- a/samples/bluetooth/hci_uart_async/app.overlay +++ /dev/null @@ -1,31 +0,0 @@ -/* This is the default app device tree overlay. This file is ignored if - * there is a board-specific overlay in `./boards`. - * - * Most boards define a convenient `&uart0`. It's used here to make the - * sample 'just work' automatically for those boards. - */ - -bt_c2h_uart: &uart0 { - status = "okay"; - current-speed = <1000000>; - hw-flow-control; -}; - -/ { - chosen { - zephyr,bt-c2h-uart = &bt_c2h_uart; - }; -}; - -/* Some boards are by default assigning the &uart0 to these other - * functions. Removing the assignments will ensure a compilation error - * instead of accidental interference. - */ -/ { - chosen { - /delete-property/ zephyr,console; - /delete-property/ zephyr,shell-uart; - /delete-property/ zephyr,uart-mcumgr; - /delete-property/ zephyr,bt-mon-uart; - }; -}; diff --git a/samples/bluetooth/hci_uart_async/debug.mixin.conf b/samples/bluetooth/hci_uart_async/debug.mixin.conf deleted file mode 100644 index 3255df74018..00000000000 --- a/samples/bluetooth/hci_uart_async/debug.mixin.conf +++ /dev/null @@ -1,15 +0,0 @@ -CONFIG_ASSERT_ON_ERRORS=y -CONFIG_ASSERT=y -CONFIG_DEBUG_INFO=y -CONFIG_DEBUG_OPTIMIZATIONS=y -CONFIG_DEBUG_THREAD_INFO=y - -# Enable RTT console -CONFIG_RTT_CONSOLE=y - -CONFIG_LOG=y -CONFIG_LOG_BUFFER_SIZE=10000 - -# This outputs all HCI traffic to a separate RTT channel. Use `btmon -# --jlink` to read it out. Add `--priority 7` for debug logs. -CONFIG_BT_DEBUG_MONITOR_RTT=y diff --git a/samples/bluetooth/hci_uart_async/prj.conf b/samples/bluetooth/hci_uart_async/prj.conf deleted file mode 100644 index 1de1a46535e..00000000000 --- a/samples/bluetooth/hci_uart_async/prj.conf +++ /dev/null @@ -1,25 +0,0 @@ -# hci_uart_async -CONFIG_SERIAL=y -CONFIG_UART_ASYNC_API=y - -# hci_raw (dependency of hci_uart) -CONFIG_BT=y -CONFIG_BT_HCI_RAW=y -CONFIG_BT_HCI_RAW_H4=y -CONFIG_BT_HCI_RAW_H4_ENABLE=y - -# Controller configuration. Modify these for your application's needs. -CONFIG_BT_MAX_CONN=16 -CONFIG_BT_BUF_ACL_RX_SIZE=255 -CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255 - -# Send an initial HCI_Command_Complete event on boot without waiting for -# HCI_Reset. Make sure to use the same value for this setting in your -# host application. -#CONFIG_BT_WAIT_NOP=y - -# See `overlay.app`. The 'zephyr,console' chosen node is deleted there -# in case it has a interfering default. Those same boards set this -# config and it must be undone or the build will fail. -CONFIG_UART_CONSOLE=n diff --git a/samples/bluetooth/hci_uart_async/sample.yaml b/samples/bluetooth/hci_uart_async/sample.yaml deleted file mode 100644 index d0db2b90385..00000000000 --- a/samples/bluetooth/hci_uart_async/sample.yaml +++ /dev/null @@ -1,19 +0,0 @@ -sample: - name: Bluetooth HCI UART Async - description: - This sample is a batteries-included example of a Bluetooth HCI UART - connectivity chip. - - It demonstrates a possible implementation of an HCI UART (H4) - interface on top of Zephyr's Bluetooth Raw API, and how to expose it - over a UART. - - This implementation is based on the Zephyr Asynchoronous UART API. -tests: - sample.bluetooth.hci_uart_async.nrf5: - harness: bluetooth - platform_allow: - - nrf52dk_nrf52832 - tags: - - uart - - bluetooth diff --git a/samples/bluetooth/hci_uart_async/src/hci_uart_async.c b/samples/bluetooth/hci_uart_async/src/hci_uart_async.c deleted file mode 100644 index 4d276e42378..00000000000 --- a/samples/bluetooth/hci_uart_async/src/hci_uart_async.c +++ /dev/null @@ -1,403 +0,0 @@ -/* Copyright (c) 2023 Nordic Semiconductor ASA - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -LOG_MODULE_REGISTER(hci_uart_async, LOG_LEVEL_DBG); - -static const struct device *const hci_uart_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_c2h_uart)); - -static K_THREAD_STACK_DEFINE(h2c_thread_stack, CONFIG_BT_HCI_TX_STACK_SIZE); -static struct k_thread h2c_thread; - -enum h4_type { - H4_CMD = 0x01, - H4_ACL = 0x02, - H4_SCO = 0x03, - H4_EVT = 0x04, - H4_ISO = 0x05, -}; - -struct k_poll_signal uart_h2c_rx_sig; -struct k_poll_signal uart_c2h_tx_sig; - -static K_FIFO_DEFINE(c2h_queue); - -/** Send raw data on c2h UART. - * - * Blocks until completion. Not thread-safe. - * - * @retval 0 on success - * @retval -EBUSY Another transmission is in progress. This a - * thread-safety violation. - * @retval -errno @ref uart_tx error. - */ -static int uart_c2h_tx(const uint8_t *data, size_t size) -{ - int err; - struct k_poll_signal *sig = &uart_c2h_tx_sig; - struct k_poll_event done[] = { - K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, sig), - }; - - k_poll_signal_reset(sig); - err = uart_tx(hci_uart_dev, data, size, SYS_FOREVER_US); - - if (err) { - LOG_ERR("uart c2h tx: err %d", err); - return err; - } - - err = k_poll(done, ARRAY_SIZE(done), K_FOREVER); - __ASSERT_NO_MSG(err == 0); - - return 0; -} - -/* Function expects that type is validated and only CMD, ISO or ACL will be used. */ -static uint32_t hci_payload_size(const uint8_t *hdr_buf, enum h4_type type) -{ - switch (type) { - case H4_CMD: - return ((const struct bt_hci_cmd_hdr *)hdr_buf)->param_len; - case H4_ACL: - return sys_le16_to_cpu(((const struct bt_hci_acl_hdr *)hdr_buf)->len); - case H4_ISO: - return bt_iso_hdr_len( - sys_le16_to_cpu(((const struct bt_hci_iso_hdr *)hdr_buf)->len)); - default: - LOG_ERR("Invalid type: %u", type); - return 0; - } -} - -static uint8_t hci_hdr_size(enum h4_type type) -{ - switch (type) { - case H4_CMD: - return sizeof(struct bt_hci_cmd_hdr); - case H4_ACL: - return sizeof(struct bt_hci_acl_hdr); - case H4_ISO: - return sizeof(struct bt_hci_iso_hdr); - default: - LOG_ERR("Unexpected h4 type: %u", type); - return 0; - } -} - -/** Send raw data on c2h UART. - * - * Blocks until either @p size has been received or special UART - * condition occurs on the UART RX line, like an UART break or parity - * error. - * - * Not thread-safe. - * - * @retval 0 on success - * @retval -EBUSY Another transmission is in progress. This a - * thread-safety violation. - * @retval -errno @ref uart_rx_enable error. - * @retval +stop_reason Special condition @ref uart_rx_stop_reason. - */ -static int uart_h2c_rx(uint8_t *dst, size_t size) -{ - int err; - struct k_poll_signal *sig = &uart_h2c_rx_sig; - struct k_poll_event done[] = { - K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, sig), - }; - - k_poll_signal_reset(sig); - err = uart_rx_enable(hci_uart_dev, dst, size, SYS_FOREVER_US); - - if (err) { - LOG_ERR("uart h2c rx: err %d", err); - return err; - } - - k_poll(done, ARRAY_SIZE(done), K_FOREVER); - return sig->result; -} - -/** Inject a HCI EVT Hardware error into the c2h packet stream. - * - * This uses `bt_recv`, just as if the controller is sending the error. - */ -static void send_hw_error(void) -{ - const uint8_t err_code = 0; - const uint8_t hci_evt_hw_err[] = {BT_HCI_EVT_HARDWARE_ERROR, - sizeof(struct bt_hci_evt_hardware_error), err_code}; - - struct net_buf *buf = bt_buf_get_rx(BT_BUF_EVT, K_FOREVER); - - net_buf_add_mem(buf, hci_evt_hw_err, sizeof(hci_evt_hw_err)); - - /* Inject the message into the c2h queue. */ - bt_recv(buf); - - /* The c2h thread will send the message at some point. The host - * will receive it and reset the controller. - */ -} - -static void recover_sync_by_reset_pattern(void) -{ - /* { H4_CMD, le_16(HCI_CMD_OP_RESET), len=0 } */ - const uint8_t h4_cmd_reset[] = {0x01, 0x03, 0x0C, 0x00}; - const uint32_t reset_pattern = sys_get_be32(h4_cmd_reset); - int err; - struct net_buf *h2c_cmd_reset; - uint32_t shift_register = 0; - - LOG_DBG("Looking for reset pattern"); - - while (shift_register != reset_pattern) { - uint8_t read_byte; - - uart_h2c_rx(&read_byte, sizeof(uint8_t)); - LOG_DBG("h2c: 0x%02x", read_byte); - shift_register = (shift_register * 0x100) + read_byte; - } - - LOG_DBG("Pattern found"); - h2c_cmd_reset = bt_buf_get_tx(BT_BUF_H4, K_FOREVER, h4_cmd_reset, sizeof(h4_cmd_reset)); - LOG_DBG("Fowarding reset"); - - err = bt_send(h2c_cmd_reset); - __ASSERT(!err, "Failed to send reset: %d", err); -} - -static void h2c_h4_transport(void) -{ - /* When entering this function, the h2c stream should be - * 'synchronized'. I.e. The stream should be at a H4 packet - * boundary. - * - * This function returns to signal a desynchronization. - * When this happens, the caller should resynchronize before - * entering this function again. It's up to the caller to decide - * how to resynchronize. - */ - - for (;;) { - int err; - struct net_buf *buf; - uint8_t h4_type; - uint8_t hdr_size; - uint8_t *hdr_buf; - uint16_t payload_size; - - LOG_DBG("h2c: listening"); - - /* Read H4 type. */ - err = uart_h2c_rx(&h4_type, sizeof(uint8_t)); - - if (err) { - return; - } - LOG_DBG("h2c: h4_type %d", h4_type); - - /* Allocate buf. */ - buf = bt_buf_get_tx(BT_BUF_H4, K_FOREVER, &h4_type, sizeof(h4_type)); - LOG_DBG("h2c: buf %p", buf); - - if (!buf) { - /* `h4_type` was invalid. */ - __ASSERT_NO_MSG(hci_hdr_size(h4_type) == 0); - - LOG_WRN("bt_buf_get_tx failed h4_type %d", h4_type); - return; - } - - /* Read HCI header. */ - hdr_size = hci_hdr_size(h4_type); - hdr_buf = net_buf_add(buf, hdr_size); - - err = uart_h2c_rx(hdr_buf, hdr_size); - if (err) { - net_buf_unref(buf); - return; - } - LOG_HEXDUMP_DBG(hdr_buf, hdr_size, "h2c: hci hdr"); - - /* Read HCI payload. */ - payload_size = hci_payload_size(hdr_buf, h4_type); - - LOG_DBG("h2c: payload_size %u", payload_size); - - if (payload_size <= net_buf_tailroom(buf)) { - uint8_t *payload_dst = net_buf_add(buf, payload_size); - - err = uart_h2c_rx(payload_dst, payload_size); - if (err) { - net_buf_unref(buf); - return; - } - LOG_HEXDUMP_DBG(payload_dst, payload_size, "h2c: hci payload"); - } else { - /* Discard oversize packet. */ - uint8_t *discard_dst; - uint16_t discard_size; - - LOG_WRN("h2c: Discarding oversize h4_type %d payload_size %d.", h4_type, - payload_size); - - /* Reset `buf` so all of it is available. */ - net_buf_reset(buf); - discard_dst = net_buf_tail(buf); - discard_size = net_buf_max_len(buf); - - while (payload_size) { - uint16_t read_size = MIN(payload_size, discard_size); - - err = uart_h2c_rx(discard_dst, read_size); - if (err) { - net_buf_unref(buf); - return; - } - - payload_size -= read_size; - } - - net_buf_unref(buf); - buf = NULL; - } - - LOG_DBG("h2c: packet done"); - - /* Route buf to Controller. */ - if (buf) { - err = bt_send(buf); - if (err) { - /* This is not a transport error. */ - LOG_ERR("bt_send err %d", err); - net_buf_unref(buf); - buf = NULL; - } - } - - k_yield(); - } -} - -static void h2c_thread_entry(void *p1, void *p2, void *p3) -{ - k_thread_name_set(k_current_get(), "HCI TX (h2c)"); - - for (;;) { - LOG_DBG("Synchronized"); - h2c_h4_transport(); - LOG_WRN("Desynchronized"); - send_hw_error(); - recover_sync_by_reset_pattern(); - } -} - -void callback(const struct device *dev, struct uart_event *evt, void *user_data) -{ - ARG_UNUSED(user_data); - - if (evt->type == UART_RX_DISABLED) { - (void)k_poll_signal_raise(&uart_h2c_rx_sig, 0); - } else if (evt->type == UART_RX_STOPPED) { - (void)k_poll_signal_raise(&uart_h2c_rx_sig, evt->data.rx_stop.reason); - } else if (evt->type == UART_TX_DONE) { - (void)k_poll_signal_raise(&uart_c2h_tx_sig, 0); - } -} - -static int hci_uart_init(void) -{ - int err; - - k_poll_signal_init(&uart_h2c_rx_sig); - k_poll_signal_init(&uart_c2h_tx_sig); - - LOG_DBG(""); - - if (!device_is_ready(hci_uart_dev)) { - LOG_ERR("HCI UART %s is not ready", hci_uart_dev->name); - return -EINVAL; - } - - BUILD_ASSERT(IS_ENABLED(CONFIG_UART_ASYNC_API)); - err = uart_callback_set(hci_uart_dev, callback, NULL); - - /* Note: Asserts if CONFIG_UART_ASYNC_API is not enabled for `hci_uart_dev`. */ - __ASSERT(!err, "err %d", err); - - return 0; -} - -SYS_INIT(hci_uart_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); - -const struct { - uint8_t h4; - struct bt_hci_evt_hdr hdr; - struct bt_hci_evt_cmd_complete cc; -} __packed cc_evt = { - .h4 = H4_EVT, - .hdr = {.evt = BT_HCI_EVT_CMD_COMPLETE, .len = sizeof(struct bt_hci_evt_cmd_complete)}, - .cc = {.ncmd = 1, .opcode = sys_cpu_to_le16(BT_OP_NOP)}, -}; - -static void c2h_thread_entry(void) -{ - k_thread_name_set(k_current_get(), "HCI RX (c2h)"); - - if (IS_ENABLED(CONFIG_BT_WAIT_NOP)) { - uart_c2h_tx((char *)&cc_evt, sizeof(cc_evt)); - } - - for (;;) { - struct net_buf *buf; - - buf = net_buf_get(&c2h_queue, K_FOREVER); - uart_c2h_tx(buf->data, buf->len); - net_buf_unref(buf); - } -} - -void hci_uart_main(void) -{ - int err; - - err = bt_enable_raw(&c2h_queue); - __ASSERT_NO_MSG(!err); - - /* TX thread. */ - k_thread_create(&h2c_thread, h2c_thread_stack, K_THREAD_STACK_SIZEOF(h2c_thread_stack), - h2c_thread_entry, NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); - - /* Reuse current thread as RX thread. */ - c2h_thread_entry(); -} diff --git a/samples/bluetooth/hci_uart_async/src/main.c b/samples/bluetooth/hci_uart_async/src/main.c deleted file mode 100644 index 2d38d83e45c..00000000000 --- a/samples/bluetooth/hci_uart_async/src/main.c +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright (c) 2023 Nordic Semiconductor ASA - * SPDX-License-Identifier: Apache-2.0 - */ - -extern int hci_uart_main(void); - -int main(void) -{ - hci_uart_main(); - return 0; -} diff --git a/tests/bluetooth/hci_uart_async/CMakeLists.txt b/tests/bluetooth/hci_uart_async/CMakeLists.txt deleted file mode 100644 index 2380f9f1152..00000000000 --- a/tests/bluetooth/hci_uart_async/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -set(EXTRA_CONF_FILE - ../../../samples/bluetooth/hci_uart_async/prj.conf -) - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) - -project(test_samples_bluetooth_hci_uart_async) -target_sources(app PRIVATE - ../../../samples/bluetooth/hci_uart_async/src/hci_uart_async.c - src/test_hci_uart_async.c -) diff --git a/tests/bluetooth/hci_uart_async/app.overlay b/tests/bluetooth/hci_uart_async/app.overlay deleted file mode 100644 index d9186722ba6..00000000000 --- a/tests/bluetooth/hci_uart_async/app.overlay +++ /dev/null @@ -1,11 +0,0 @@ -/ { - chosen { - zephyr,bt-c2h-uart = &test_uart; - }; - - test_uart: test_uart { - compatible = "vnd,serial"; - status = "okay"; - buffer-size = <100>; - }; -}; diff --git a/tests/bluetooth/hci_uart_async/boards/native_posix.conf b/tests/bluetooth/hci_uart_async/boards/native_posix.conf deleted file mode 100644 index e638cd6a0ef..00000000000 --- a/tests/bluetooth/hci_uart_async/boards/native_posix.conf +++ /dev/null @@ -1,3 +0,0 @@ -# Print logs and test results on stdout. For some reason, this not the -# default when SERIAL=y. -CONFIG_LOG_BACKEND_NATIVE_POSIX=y diff --git a/tests/bluetooth/hci_uart_async/prj.conf b/tests/bluetooth/hci_uart_async/prj.conf deleted file mode 100644 index b038c7c4312..00000000000 --- a/tests/bluetooth/hci_uart_async/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_BT_NO_DRIVER=y - -CONFIG_RING_BUFFER=y - -CONFIG_ASSERT=y -CONFIG_LOG=y -CONFIG_TEST=y - -CONFIG_ZTEST=y -CONFIG_ZTEST_NEW_API=y diff --git a/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c b/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c deleted file mode 100644 index 1996aba177a..00000000000 --- a/tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c +++ /dev/null @@ -1,238 +0,0 @@ -/* Copyright (c) 2023 Nordic Semiconductor ASA - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include -#include - -#include - -#include -#include -#include - -#include -#include - -LOG_MODULE_REGISTER(test, LOG_LEVEL_DBG); - -/* This is a mock UART. Using `serial_vnd_...` on this simulates - * traffic from the external Host. - */ -static const struct device *const zephyr_bt_c2h_uart = DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_c2h_uart)); - -/* The DUT is Sandwiched between the mock serial interface and a mock - * controller. {{{ - */ -static void serial_vnd_data_callback(const struct device *dev, void *user_data); -static int drv_send(struct net_buf *buf); -static int drv_open(void); -static const struct bt_hci_driver drv = { - .name = "Mock Controller", - .bus = BT_HCI_DRIVER_BUS_VIRTUAL, - .open = drv_open, - .send = drv_send, -}; -static int sys_init_hci_driver_register(void) -{ - serial_vnd_set_callback(zephyr_bt_c2h_uart, serial_vnd_data_callback, NULL); - bt_hci_driver_register(&drv); - return 0; -} -SYS_INIT(sys_init_hci_driver_register, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); -/* }}} */ - -/* Start the DUT "main thread". The settings for this thread are selected as - * true as possible to the real main thread. {{{ - */ -static struct k_thread hci_uart_thread; -static K_THREAD_PINNED_STACK_DEFINE(hci_uart_thread_stack, CONFIG_MAIN_STACK_SIZE); -static void hci_uart_thread_entry(void *p1, void *p2, void *p3) -{ - extern void hci_uart_main(void); - hci_uart_main(); -} -static int sys_init_spawn_hci_uart(void) -{ - k_thread_name_set(&hci_uart_thread, "hci_uart_main"); - k_thread_create(&hci_uart_thread, hci_uart_thread_stack, - K_THREAD_STACK_SIZEOF(hci_uart_thread_stack), hci_uart_thread_entry, NULL, - NULL, NULL, CONFIG_MAIN_THREAD_PRIORITY, 0, K_NO_WAIT); - return 0; -} -SYS_INIT(sys_init_spawn_hci_uart, POST_KERNEL, 64); -/* }}} */ - -/* Mock controller callbacks. {{{ */ - -static int drv_open(void) -{ - LOG_DBG("drv_open"); - return 0; -} - -/** This FIFO holds the references to all h2c packets the DUT has sent - * to the controller using #bt_send. - * - * Each test should mock a controller by calling #net_buf_get on this - * FIFO and simulate a controller's #bt_hci_driver::drv_send. The mocks - * should use #bt_recv to send c2h packets to the DUT. - */ -K_FIFO_DEFINE(drv_send_fifo); /* elem T: net_buf */ -static int drv_send(struct net_buf *buf) -{ - LOG_DBG("buf %p type %d len %u", buf, bt_buf_get_type(buf), buf->len); - LOG_HEXDUMP_DBG(buf->data, buf->len, "buf"); - - __ASSERT_NO_MSG(buf); - net_buf_put(&drv_send_fifo, buf); - return 0; -} - -/* }}} */ - -/* Mock UART c2h TX handler. {{{ */ - -static void serial_vnd_data_callback(const struct device *dev, void *user_data) -{ - uint32_t size = serial_vnd_out_data_size_get(dev); - uint8_t data[size]; - - serial_vnd_read_out_data(dev, data, size); - LOG_HEXDUMP_DBG(data, size, "uart tx"); - - /* If a test needs to look at the c2h UART traffic, it can be - * captured here. - */ -} - -/* }}} */ - -#define HCI_NORMAL_CMD_BUF_COUNT (CONFIG_BT_BUF_CMD_TX_COUNT - 1) -#define TEST_PARAM_HOST_COMPLETE_COUNT 10 -#define TIMEOUT_PRESUME_STUCK K_SECONDS(1) - -/** Corresponds to: - * - #bt_hci_cmd_hdr - */ -const uint8_t h4_msg_cmd_dummy1[] = { - 0x01, /* H4: opcode = CMD */ - 0x01, 0x00, /* H4: CMD: opcode = 1 */ - 0x00, /* H4: CMD: len = 0 */ -}; - -/** Corresponds to: - * - #bt_hci_cmd_hdr - * - #bt_hci_cp_host_num_completed_packets - */ -const uint8_t h4_msg_cmd_host_num_complete[] = { - 0x01, /* H4: opcode = CMD */ - 0x35, 0x0c, /* H4: CMD: opcode = BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS */ - 0x05, /* H4: CMD: len = 5 */ - 0x01, /* H4: CMD: num_handles = 1 */ - 0x00, 0x00, /* H4: CMD: connection_handle = 0 */ - 0x01, 0x00, /* H4: CMD: num_complete = 1 */ -}; - -/** Corresponds to: - * - #bt_hci_evt_hdr - * - #bt_hci_evt_cmd_complete - */ -const uint8_t hci_msg_rx_evt_cmd_complete[] = { - BT_HCI_EVT_CMD_COMPLETE, /* EVT: opcode */ - 0x03, /* EVT: len */ - 0x01, /* EVT: CMDC: ncmd = 1 */ - /* EVT: CMDC: opcode */ - 0x00, - 0x00, -}; - -ZTEST_SUITE(hci_uart, NULL, NULL, NULL, NULL, NULL); -ZTEST(hci_uart, test_h2c_cmd_flow_control) -{ - /* This test assumes the DUT does not care about the contents of - * the HCI messages, other than the HCI type/endpoint and the - * size. This allows the test to cheat and skip the HCI Reset, - * connection setup etc and use dummy command-packets. - */ - - /* Send commands, saturating the controller's command pipeline. */ - for (uint16_t i = 0; i < HCI_NORMAL_CMD_BUF_COUNT; i++) { - int write_size = serial_vnd_queue_in_data(zephyr_bt_c2h_uart, h4_msg_cmd_dummy1, - sizeof(h4_msg_cmd_dummy1)); - __ASSERT_NO_MSG(write_size == sizeof(h4_msg_cmd_dummy1)); - } - - /* At this point, the HCI flow control limit for the cmd - * endpoint has been reached. It will remain so until the - * controller mock has sent a 'HCI Command Complete' event. - * - * But the 'HCI Host Number of Completed Packets' command is - * exempt from HCI flow control. (It's like it has its own - * endpoint, that has no flow control.) - * - * We now send several 'HCI Host Number of Completed Packets' - * packets before handling any commands in the controller. This - * tests whether the DUT is able to engage the lower transport - * flow controller (i.e. UART flow-control) or somehow handle - * the special packets out-of-order in real-time. - */ - for (uint16_t i = 0; i < TEST_PARAM_HOST_COMPLETE_COUNT; i++) { - int write_size = - serial_vnd_queue_in_data(zephyr_bt_c2h_uart, h4_msg_cmd_host_num_complete, - sizeof(h4_msg_cmd_host_num_complete)); - __ASSERT_NO_MSG(write_size == sizeof(h4_msg_cmd_host_num_complete)); - } - - LOG_DBG("All h2c packets queued on UART"); - - /* Then, we check that all packets are delivered without loss. */ - - /* Expect all the normal commands first. */ - for (uint16_t i = 0; i < HCI_NORMAL_CMD_BUF_COUNT; i++) { - /* The mock controller processes a command. */ - { - struct net_buf *buf = net_buf_get(&drv_send_fifo, TIMEOUT_PRESUME_STUCK); - - zassert_not_null(buf); - zassert_equal(buf->len, sizeof(h4_msg_cmd_dummy1) - 1, "Wrong length"); - zassert_mem_equal(buf->data, &h4_msg_cmd_dummy1[1], - sizeof(h4_msg_cmd_dummy1) - 1); - net_buf_unref(buf); - } - - /* The controller sends a HCI Command Complete response. */ - { - int err; - struct net_buf *buf = bt_buf_get_rx(BT_BUF_EVT, K_NO_WAIT); - - zassert_not_null(buf); - net_buf_add_mem(buf, hci_msg_rx_evt_cmd_complete, - sizeof(hci_msg_rx_evt_cmd_complete)); - err = bt_recv(buf); - zassert_equal(err, 0, "bt_recv failed"); - } - } - - /* Expect all the 'HCI Host Number of Completed Packets'. */ - for (uint16_t i = 0; i < TEST_PARAM_HOST_COMPLETE_COUNT; i++) { - /* The mock controller processes a 'HCI Host Number of Completed Packets'. */ - { - struct net_buf *buf = net_buf_get(&drv_send_fifo, TIMEOUT_PRESUME_STUCK); - - zassert_not_null(buf); - zassert_equal(buf->len, sizeof(h4_msg_cmd_host_num_complete) - 1, - "Wrong length"); - zassert_mem_equal(buf->data, &h4_msg_cmd_host_num_complete[1], - sizeof(h4_msg_cmd_dummy1) - 2); - net_buf_unref(buf); - } - - /* There is no response to 'HCI Host Number of Completed Packets'. */ - } - - LOG_DBG("All h2c packets received by controller."); -} diff --git a/tests/bluetooth/hci_uart_async/testcase.yaml b/tests/bluetooth/hci_uart_async/testcase.yaml deleted file mode 100644 index f7f4a6255eb..00000000000 --- a/tests/bluetooth/hci_uart_async/testcase.yaml +++ /dev/null @@ -1,6 +0,0 @@ -tests: - samples.bluetooth.hci_uart_async: - tags: bluetooth uart - harness: ztest - platform_allow: - - native_posix From 89162d677482a55ee6b1e4df1a0bb5728a5afcfa Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:41 +0000 Subject: [PATCH 0607/1623] Revert "[nrf fromtree] drivers: serial_test: Implement interrupt and async APIs" This reverts commit 3c923c5a170c793f8d8582224e7d1c988237247b. Signed-off-by: Dominik Ermel --- drivers/serial/serial_test.c | 319 +--------------------- include/zephyr/drivers/uart/serial_test.h | 2 +- 2 files changed, 3 insertions(+), 318 deletions(-) diff --git a/drivers/serial/serial_test.c b/drivers/serial/serial_test.c index 2ce4fb50f38..95e036e5992 100644 --- a/drivers/serial/serial_test.c +++ b/drivers/serial/serial_test.c @@ -9,21 +9,12 @@ * devices for the "vnd,serial" devicetree compatible used in test code. */ -#include - -#include #include #include #include #include -#include #include -LOG_MODULE_REGISTER(mock_serial, CONFIG_LOG_DEFAULT_LEVEL); - -BUILD_ASSERT(!IS_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN) || IS_ENABLED(CONFIG_RING_BUFFER)); -BUILD_ASSERT(!IS_ENABLED(CONFIG_UART_ASYNC_API) || IS_ENABLED(CONFIG_RING_BUFFER)); - #define DT_DRV_COMPAT vnd_serial struct serial_vnd_data { #ifdef CONFIG_RING_BUFFER @@ -32,156 +23,8 @@ struct serial_vnd_data { #endif serial_vnd_write_cb_t callback; void *callback_data; -#ifdef CONFIG_UART_INTERRUPT_DRIVEN - uart_irq_callback_user_data_t irq_isr; - bool irq_rx_enabled; - bool irq_tx_enabled; -#endif -#ifdef CONFIG_UART_ASYNC_API - uart_callback_t async_cb; - void *async_cb_user_data; - uint8_t *read_buf; - size_t read_size; - size_t read_position; -#endif }; -#ifdef CONFIG_UART_INTERRUPT_DRIVEN -static bool is_irq_rx_pending(const struct device *dev) -{ - struct serial_vnd_data *data = dev->data; - - return !ring_buf_is_empty(data->read_queue); -} - -static bool is_irq_tx_pending(const struct device *dev) -{ - struct serial_vnd_data *data = dev->data; - - return ring_buf_space_get(data->written) != 0; -} - -static void irq_process(const struct device *dev) -{ - struct serial_vnd_data *data = dev->data; - - for (;;) { - bool rx_rdy = is_irq_rx_pending(dev); - bool tx_rdy = is_irq_tx_pending(dev); - bool rx_int = rx_rdy && data->irq_rx_enabled; - bool tx_int = tx_rdy && data->irq_tx_enabled; - - LOG_DBG("rx_rdy %d tx_rdy %d", rx_rdy, tx_rdy); - LOG_DBG("rx_int %d tx_int %d", rx_int, tx_int); - - if (!(rx_int || tx_int)) { - break; - } - - LOG_DBG("isr"); - if (!data->irq_isr) { - LOG_ERR("no isr registered"); - break; - } - data->irq_isr(dev, NULL); - }; -} - -static void irq_rx_enable(const struct device *dev) -{ - struct serial_vnd_data *data = dev->data; - - data->irq_rx_enabled = true; - LOG_DBG("rx enabled"); - irq_process(dev); -} - -static void irq_rx_disable(const struct device *dev) -{ - struct serial_vnd_data *data = dev->data; - - data->irq_rx_enabled = false; - LOG_DBG("rx disabled"); -} - -static int irq_rx_ready(const struct device *dev) -{ - struct serial_vnd_data *data = dev->data; - bool ready = !ring_buf_is_empty(data->read_queue); - - LOG_DBG("rx ready: %d", ready); - return ready; -} - -static void irq_tx_enable(const struct device *dev) -{ - struct serial_vnd_data *data = dev->data; - - LOG_DBG("tx enabled"); - data->irq_tx_enabled = true; - irq_process(dev); -} - -static void irq_tx_disable(const struct device *dev) -{ - struct serial_vnd_data *data = dev->data; - - data->irq_tx_enabled = false; - LOG_DBG("tx disabled"); -} - -static int irq_tx_ready(const struct device *dev) -{ - struct serial_vnd_data *data = dev->data; - bool ready = (ring_buf_space_get(data->written) != 0); - - LOG_DBG("tx ready: %d", ready); - return ready; -} - -static void irq_callback_set(const struct device *dev, uart_irq_callback_user_data_t cb, - void *user_data) -{ - struct serial_vnd_data *data = dev->data; - - /* Not implemented. Ok because `user_data` is always NULL in the current - * implementation of core UART API. - */ - __ASSERT_NO_MSG(user_data == NULL); - -#if defined(CONFIG_UART_EXCLUSIVE_API_CALLBACKS) && defined(CONFIG_UART_ASYNC_API) - if (data->read_buf) { - LOG_ERR("Setting callback to NULL while asynchronous API is in use."); - } - data->async_cb = NULL; - data->async_cb_user_data = NULL; -#endif - - data->irq_isr = cb; - LOG_DBG("callback set"); -} - -static int fifo_fill(const struct device *dev, const uint8_t *tx_data, int size) -{ - struct serial_vnd_data *data = dev->data; - uint32_t write_len = ring_buf_put(data->written, tx_data, size); - - if (data->callback) { - data->callback(dev, data->callback_data); - } - return write_len; -} - -static int fifo_read(const struct device *dev, uint8_t *rx_data, const int size) -{ - struct serial_vnd_data *data = dev->data; - int read_len = ring_buf_get(data->read_queue, rx_data, size); - - LOG_HEXDUMP_DBG(rx_data, read_len, ""); - return read_len; -} -#endif /* CONFIG_UART_INTERRUPT_DRIVEN */ - static int serial_vnd_poll_in(const struct device *dev, unsigned char *c) { #ifdef CONFIG_RING_BUFFER @@ -216,35 +59,15 @@ static void serial_vnd_poll_out(const struct device *dev, unsigned char c) } } -#ifdef CONFIG_UART_ASYNC_API -static void async_rx_run(const struct device *dev); -#endif - #ifdef CONFIG_RING_BUFFER -int serial_vnd_queue_in_data(const struct device *dev, const unsigned char *c, uint32_t size) +int serial_vnd_queue_in_data(const struct device *dev, unsigned char *c, uint32_t size) { struct serial_vnd_data *data = dev->data; - int write_size; if (data == NULL || data->read_queue == NULL) { return -ENOTSUP; } - write_size = ring_buf_put(data->read_queue, c, size); - - LOG_DBG("size %u write_size %u", size, write_size); - LOG_HEXDUMP_DBG(c, write_size, ""); - -#ifdef CONFIG_UART_INTERRUPT_DRIVEN - if (write_size > 0) { - irq_process(dev); - } -#endif - -#ifdef CONFIG_UART_ASYNC_API - async_rx_run(dev); -#endif - - return write_size; + return ring_buf_put(data->read_queue, c, size); } uint32_t serial_vnd_out_data_size_get(const struct device *dev) @@ -307,128 +130,6 @@ static int serial_vnd_config_get(const struct device *dev, struct uart_config *c } #endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */ -#ifdef CONFIG_UART_ASYNC_API -static int serial_vnd_callback_set(const struct device *dev, uart_callback_t callback, - void *user_data) -{ - struct serial_vnd_data *data = dev->data; - - if (data == NULL) { - return -ENOTSUP; - } - -#if defined(CONFIG_UART_EXCLUSIVE_API_CALLBACKS) && defined(CONFIG_UART_INTERRUPT_DRIVEN) - data->irq_isr = cb; -#endif - - if (callback == NULL && data->read_buf) { - LOG_ERR("Setting callback to NULL while asynchronous API is in use."); - } - - data->async_cb = callback; - data->async_cb_user_data = user_data; - - return 0; -} - -static int serial_vnd_api_tx(const struct device *dev, const uint8_t *tx_data, size_t len, - int32_t timeout) -{ - struct serial_vnd_data *data = dev->data; - struct uart_event evt; - uint32_t write_len; - - if (data == NULL) { - return -ENOTSUP; - } - - if (data->async_cb == NULL) { - return -EINVAL; - } - - write_len = ring_buf_put(data->written, tx_data, len); - if (data->callback) { - data->callback(dev, data->callback_data); - } - - __ASSERT(write_len == len, "Ring buffer full. Async wait not implemented."); - - evt = (struct uart_event){ - .type = UART_TX_DONE, - .data.tx.buf = tx_data, - .data.tx.len = len, - }; - data->async_cb(dev, &evt, data->async_cb_user_data); - - return 0; -} - -static void async_rx_run(const struct device *dev) -{ - struct serial_vnd_data *data = dev->data; - struct uart_event evt; - uint32_t read_len; - uint32_t read_remaining; - - if (!data->read_buf) { - return; - } - - __ASSERT_NO_MSG(data->async_cb); - - read_remaining = data->read_size - data->read_position; - - read_len = ring_buf_get(data->read_queue, &data->read_buf[data->read_position], - read_remaining); - - if (read_len != 0) { - evt = (struct uart_event){ - .type = UART_RX_RDY, - .data.rx.buf = data->read_buf, - .data.rx.len = read_len, - .data.rx.offset = data->read_position, - }; - data->async_cb(dev, &evt, data->async_cb_user_data); - } - - data->read_position += read_len; - - if (data->read_position == data->read_size) { - data->read_buf = NULL; - evt = (struct uart_event){ - .type = UART_RX_DISABLED, - }; - data->async_cb(dev, &evt, data->async_cb_user_data); - } -} - -static int serial_vnd_rx_enable(const struct device *dev, uint8_t *read_buf, size_t read_size, - int32_t timeout) -{ - struct serial_vnd_data *data = dev->data; - - LOG_WRN("read_size %d", read_size); - - if (data == NULL) { - return -ENOTSUP; - } - - if (data->async_cb == NULL) { - return -EINVAL; - } - - __ASSERT(timeout == SYS_FOREVER_MS, "Async timeout not implemented."); - - data->read_buf = read_buf; - data->read_size = read_size; - data->read_position = 0; - - async_rx_run(dev); - - return 0; -} -#endif /* CONFIG_UART_ASYNC_API */ - static const struct uart_driver_api serial_vnd_api = { .poll_in = serial_vnd_poll_in, .poll_out = serial_vnd_poll_out, @@ -437,22 +138,6 @@ static const struct uart_driver_api serial_vnd_api = { .configure = serial_vnd_configure, .config_get = serial_vnd_config_get, #endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */ -#ifdef CONFIG_UART_INTERRUPT_DRIVEN - .irq_callback_set = irq_callback_set, - .irq_rx_enable = irq_rx_enable, - .irq_rx_disable = irq_rx_disable, - .irq_rx_ready = irq_rx_ready, - .irq_tx_enable = irq_tx_enable, - .irq_tx_disable = irq_tx_disable, - .irq_tx_ready = irq_tx_ready, - .fifo_read = fifo_read, - .fifo_fill = fifo_fill, -#endif /* CONFIG_UART_INTERRUPT_DRIVEN */ -#ifdef CONFIG_UART_ASYNC_API - .callback_set = serial_vnd_callback_set, - .tx = serial_vnd_api_tx, - .rx_enable = serial_vnd_rx_enable, -#endif /* CONFIG_UART_ASYNC_API */ }; #define VND_SERIAL_DATA_BUFFER(n) \ diff --git a/include/zephyr/drivers/uart/serial_test.h b/include/zephyr/drivers/uart/serial_test.h index ff1a2ad6181..5e011d40321 100644 --- a/include/zephyr/drivers/uart/serial_test.h +++ b/include/zephyr/drivers/uart/serial_test.h @@ -29,7 +29,7 @@ extern "C" { * * @retval Number of bytes written. */ -int serial_vnd_queue_in_data(const struct device *dev, const unsigned char *data, uint32_t size); +int serial_vnd_queue_in_data(const struct device *dev, unsigned char *data, uint32_t size); /** * @brief Returns size of unread written data. From bb9c3b8af16aa2b69a37dbf8b7b1c4997770979d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:41 +0000 Subject: [PATCH 0608/1623] Revert "[nrf fromtree] dts: bindings: Remove `reg` from `vnd,serial`" This reverts commit 5754cb6632da0d65c448362834f194ceb8b8493e. Signed-off-by: Dominik Ermel --- dts/bindings/test/vnd,serial.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dts/bindings/test/vnd,serial.yaml b/dts/bindings/test/vnd,serial.yaml index c2d931b0ed7..dc2327b4827 100644 --- a/dts/bindings/test/vnd,serial.yaml +++ b/dts/bindings/test/vnd,serial.yaml @@ -5,6 +5,9 @@ compatible: "vnd,serial" include: uart-controller.yaml properties: + reg: + required: true + baud-rate: type: int From 00aa78f7f430e8d43e06281bec9ab31789027424 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:42 +0000 Subject: [PATCH 0609/1623] Revert "[nrf noup] testspec: remove HomeKit from NCS" This reverts commit fabddf3a622625f39a71b9bb0377569e2fe230be. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index c01ae703adf..62b92e74d0f 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -131,6 +131,17 @@ "CI-rs-test": - "**/*" +"CI-homekit-test": + - "modules/openthread/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/net/**/*" + - "subsys/settings/**/*" + - any: + - "subsys/bluetooth/**/*" + - "!subsys/bluetooth/mesh/**/*" + - "!subsys/bluetooth/audio/**/*" + "CI-thread-test": - "include/zephyr/net/**/*" - "modules/mbedtls/**/*" From 6c59381599a9af3a50c6d2920223da427484d819 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:42 +0000 Subject: [PATCH 0610/1623] Revert "[nrf fromtree] net: shell: Fix unexpected timeout on loopback ping" This reverts commit 908794942947d049b61603b728f8f15af17e4873. Signed-off-by: Dominik Ermel --- subsys/net/ip/net_shell.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index 87995ccabb3..e7af6e16632 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -4535,12 +4535,6 @@ static void ping_work(struct k_work *work) return; } - if (ctx->sequence < ctx->count) { - k_work_reschedule(&ctx->work, K_MSEC(ctx->interval)); - } else { - k_work_reschedule(&ctx->work, K_SECONDS(2)); - } - if (ctx->addr.family == AF_INET6) { ret = net_icmpv6_send_echo_request(ctx->iface, &ctx->addr.in6_addr, @@ -4566,6 +4560,12 @@ static void ping_work(struct k_work *work) ping_done(ctx); return; } + + if (ctx->sequence < ctx->count) { + k_work_reschedule(&ctx->work, K_MSEC(ctx->interval)); + } else { + k_work_reschedule(&ctx->work, K_SECONDS(2)); + } } #define ASCII_CTRL_C 0x03 From 9f8b19cfbc8b5bc57e8f5903cee897ef56c833bf Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:42 +0000 Subject: [PATCH 0611/1623] Revert "[nrf fromtree] net: core: Set LL address on loopback packet" This reverts commit e73ebd314f6f8a8df179f11fd5f500522acc94e4. Signed-off-by: Dominik Ermel --- subsys/net/ip/net_core.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/subsys/net/ip/net_core.c b/subsys/net/ip/net_core.c index 1f6dac720af..c94607b4485 100644 --- a/subsys/net/ip/net_core.c +++ b/subsys/net/ip/net_core.c @@ -211,15 +211,6 @@ static void init_rx_queues(void) /* Check if the IPv{4|6} addresses are proper. As this can be expensive, * make this optional. */ - -static inline void copy_ll_addr(struct net_pkt *pkt) -{ - memcpy(net_pkt_lladdr_src(pkt), net_pkt_lladdr_if(pkt), - sizeof(struct net_linkaddr)); - memcpy(net_pkt_lladdr_dst(pkt), net_pkt_lladdr_if(pkt), - sizeof(struct net_linkaddr)); -} - static inline int check_ip_addr(struct net_pkt *pkt) { uint8_t family = net_pkt_family(pkt); @@ -248,9 +239,6 @@ static inline int check_ip_addr(struct net_pkt *pkt) NET_IPV6_HDR(pkt)->dst); net_ipv6_addr_copy_raw(NET_IPV6_HDR(pkt)->dst, (uint8_t *)&addr); - net_pkt_set_ll_proto_type(pkt, ETH_P_IPV6); - copy_ll_addr(pkt); - return 1; } @@ -298,9 +286,6 @@ static inline int check_ip_addr(struct net_pkt *pkt) NET_IPV4_HDR(pkt)->dst); net_ipv4_addr_copy_raw(NET_IPV4_HDR(pkt)->dst, (uint8_t *)&addr); - net_pkt_set_ll_proto_type(pkt, ETH_P_IP); - copy_ll_addr(pkt); - return 1; } From a30a56e49ba2d443aaf7b8be4117a0ef26a60725 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:42 +0000 Subject: [PATCH 0612/1623] Revert "[nrf fromtree] soc: arm: nordic_nrf: align nrf_power calls to new scheme" This reverts commit 729573484b5c74e6f4f83ccba5c63f80f96abad0. Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/nrf51/soc.c | 2 +- soc/arm/nordic_nrf/nrf52/soc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf51/soc.c b/soc/arm/nordic_nrf/nrf51/soc.c index 2b22c95679f..078a422c06b 100644 --- a/soc/arm/nordic_nrf/nrf51/soc.c +++ b/soc/arm/nordic_nrf/nrf51/soc.c @@ -29,7 +29,7 @@ LOG_MODULE_REGISTER(soc); */ void sys_arch_reboot(int type) { - nrf_power_gpregret_set(NRF_POWER, 0, (uint8_t)type); + nrf_power_gpregret_set(NRF_POWER, (uint8_t)type); NVIC_SystemReset(); } #endif diff --git a/soc/arm/nordic_nrf/nrf52/soc.c b/soc/arm/nordic_nrf/nrf52/soc.c index 5f310e5f945..52b97164e72 100644 --- a/soc/arm/nordic_nrf/nrf52/soc.c +++ b/soc/arm/nordic_nrf/nrf52/soc.c @@ -31,7 +31,7 @@ LOG_MODULE_REGISTER(soc); */ void sys_arch_reboot(int type) { - nrf_power_gpregret_set(NRF_POWER, 0, (uint8_t)type); + nrf_power_gpregret_set(NRF_POWER, (uint8_t)type); NVIC_SystemReset(); } #endif From 132e760eacd0c22e93547c3e671b9bcb87dd8e01 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:42 +0000 Subject: [PATCH 0613/1623] Revert "[nrf fromtree] modules: hal_nordic: nrfx: enable GPIOTE1 for NS builds" This reverts commit bc160058effb4a887acbad987ff44cf6b7db3494. Signed-off-by: Dominik Ermel --- modules/hal_nordic/nrfx/nrfx_config.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 29051ccf754..4b7cabd7a98 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -117,12 +117,6 @@ #ifdef CONFIG_NRFX_GPIOTE #define NRFX_GPIOTE_ENABLED 1 -#if (defined(CONFIG_SOC_SERIES_NRF91X) || defined(CONFIG_SOC_SERIES_NRF53X)) \ - && defined(NRF_TRUSTZONE_NONSECURE) -#define NRFX_GPIOTE1_ENABLED 1 -#else -#define NRFX_GPIOTE0_ENABLED 1 -#endif #endif #ifdef CONFIG_NRFX_GPIOTE_LOG #define NRFX_GPIOTE_CONFIG_LOG_ENABLED 1 From 29c2a495cf043db8562aa89cd19c2c0c7156186a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:43 +0000 Subject: [PATCH 0614/1623] Revert "[nrf fromtree] samples: boards: nrf: nrfx_prs: align to new nrfx_uarte" This reverts commit 7b453aac8b078f938eefff92e5d0b4d9f481adfb. Signed-off-by: Dominik Ermel --- samples/boards/nrf/nrfx_prs/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/boards/nrf/nrfx_prs/src/main.c b/samples/boards/nrf/nrfx_prs/src/main.c index 934bbbe834d..618c0718143 100644 --- a/samples/boards/nrf/nrfx_prs/src/main.c +++ b/samples/boards/nrf/nrfx_prs/src/main.c @@ -191,7 +191,7 @@ static bool spim_transfer(const uint8_t *tx_data, size_t tx_data_len, static void uarte_handler(const nrfx_uarte_event_t *p_event, void *p_context) { if (p_event->type == NRFX_UARTE_EVT_RX_DONE) { - received = p_event->data.rx.length; + received = p_event->data.rx.bytes; k_sem_give(&transfer_finished); } else if (p_event->type == NRFX_UARTE_EVT_ERROR) { received = 0; From aa763285c1d8b436f3fe7eb2f2da5751cd54fd69 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:43 +0000 Subject: [PATCH 0615/1623] Revert "[nrf fromtree] soc: arm: nordic_nrf: nrf53: align nrf_regulators" This reverts commit 2831d726ec09ce354fca9ff83382f8bf94bfefb5. Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/nrf53/soc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index 3542ef3e914..39d64d72cc2 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -554,13 +554,13 @@ static int nordicsemi_nrf53_init(void) #endif #if defined(CONFIG_SOC_DCDC_NRF53X_APP) - nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_MAIN, true); + nrf_regulators_dcdcen_set(NRF_REGULATORS, true); #endif #if defined(CONFIG_SOC_DCDC_NRF53X_NET) - nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_RADIO, true); + nrf_regulators_dcdcen_radio_set(NRF_REGULATORS, true); #endif #if defined(CONFIG_SOC_DCDC_NRF53X_HV) - nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_HIGH, true); + nrf_regulators_dcdcen_vddh_set(NRF_REGULATORS, true); #endif #if defined(CONFIG_SOC_NRF_GPIO_FORWARDER_FOR_NRF5340) From b6f7dc467a18e034d9e7bd78962ca97658842d7c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:43 +0000 Subject: [PATCH 0616/1623] Revert "[nrf fromtree] drivers: sensor: qdec_nrfx: Revert samplerdy workaround" This reverts commit 82e15a98880869aa4a80c2104988480330d8d326. Signed-off-by: Dominik Ermel --- drivers/sensor/qdec_nrfx/qdec_nrfx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/sensor/qdec_nrfx/qdec_nrfx.c b/drivers/sensor/qdec_nrfx/qdec_nrfx.c index b11ce70fb9c..81c3614fc05 100644 --- a/drivers/sensor/qdec_nrfx/qdec_nrfx.c +++ b/drivers/sensor/qdec_nrfx/qdec_nrfx.c @@ -135,6 +135,13 @@ static void qdec_nrfx_event_handler(nrfx_qdec_event_t event, void *p_context) unsigned int key; switch (event.type) { + case NRF_QDEC_EVENT_SAMPLERDY: + /* The underlying HAL driver may improperly forward an samplerdy event even if it's + * disabled in the configuration. Ignore the event to prevent error logs until the + * issue is fixed in HAL. + */ + break; + case NRF_QDEC_EVENT_REPORTRDY: accumulate(dev_data, event.data.report.acc); From e8549b921d17130d44764c49ac84a84d42e1770d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:43 +0000 Subject: [PATCH 0617/1623] Revert "[nrf fromtree] manifest: tf-m: update to have atomics for nrfx port" This reverts commit 7931877e976a0a2a47a99a7701e7e1930b2bde0d. Signed-off-by: Dominik Ermel --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 1847e94b37c..44098dac030 100644 --- a/west.yml +++ b/west.yml @@ -331,7 +331,7 @@ manifest: groups: - debug - name: trusted-firmware-m - revision: 33c0f47bcb19721a5c33e6fe1eee9225d00bb5bc + revision: 8b6146261fe2c0ad61154e20c7e338601eae2208 path: modules/tee/tf-m/trusted-firmware-m groups: - tee From 7c5854973f9c68241d05421ffa927d87bd0ed541 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:43 +0000 Subject: [PATCH 0618/1623] Revert "[nrf fromtree] manifest: hal_nordic: Update hal_nordic revision" This reverts commit 2a12aea553568d2b1683c2b329f0ac648661110a. Signed-off-by: Dominik Ermel --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 44098dac030..909800d0aab 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 2ff8ce6e6ca131d87699dba260f3c0cc4a6cc365 + revision: 427ee1a519e8a0844d0f78f7cbc8cdfc134ef00d path: modules/hal/nordic groups: - hal From 977540f7a3d1765a9574fc053a9ff4ac72df48d8 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:44 +0000 Subject: [PATCH 0619/1623] Revert "[nrf fromtree] scripts: ci: check_compliance: Add sysbuild Kconfig exceptions" This reverts commit 335beb0032206badd6cef214bbd82cdc0c51d49f. Signed-off-by: Dominik Ermel --- scripts/ci/check_compliance.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 07d7431dd65..1499d92eaf9 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -633,8 +633,6 @@ def check_no_undef_outside_kconfig(self, kconf): # toolchain Kconfig which is sourced based on # Zephyr toolchain variant and therefore not # visible to compliance. - "BOOT_ENCRYPTION_KEY_FILE", # Used in sysbuild - "BOOT_ENCRYPT_IMAGE", # Used in sysbuild "BOOT_UPGRADE_ONLY", # Used in example adjusting MCUboot config, but # symbol is defined in MCUboot itself. "BOOT_SERIAL_BOOT_MODE", # Used in (sysbuild-based) test/ From 5855d0887b632ee85f126c438de439d1e22971ea Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:44 +0000 Subject: [PATCH 0620/1623] Revert "[nrf fromtree] sysbuild: Add support for MCUboot/app encryption keys" This reverts commit 4936f55987b49cedd92288f686410f374ed345d2. Signed-off-by: Dominik Ermel --- .../MAIN_image_default.cmake | 3 --- .../sysbuild/images/bootloader/CMakeLists.txt | 4 ---- share/sysbuild/images/bootloader/Kconfig | 20 ++----------------- 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/share/sysbuild/image_configurations/MAIN_image_default.cmake b/share/sysbuild/image_configurations/MAIN_image_default.cmake index a2ae840ef97..a6bd72d7d1a 100644 --- a/share/sysbuild/image_configurations/MAIN_image_default.cmake +++ b/share/sysbuild/image_configurations/MAIN_image_default.cmake @@ -9,9 +9,6 @@ set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOTLOADER_MCUBOOT "${SB_CONFIG_BOO set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_SIGNATURE_KEY_FILE "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}" ) -set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE - "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}" -) if(SB_CONFIG_BOOTLOADER_MCUBOOT) if("${SB_CONFIG_SIGNATURE_TYPE}" STREQUAL "NONE") diff --git a/share/sysbuild/images/bootloader/CMakeLists.txt b/share/sysbuild/images/bootloader/CMakeLists.txt index 2a0f12f958d..c00a8e97783 100644 --- a/share/sysbuild/images/bootloader/CMakeLists.txt +++ b/share/sysbuild/images/bootloader/CMakeLists.txt @@ -15,8 +15,4 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT) sysbuild_add_dependencies(FLASH ${DEFAULT_IMAGE} ${image}) set_config_string(${image} CONFIG_BOOT_SIGNATURE_KEY_FILE "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}") - set_config_bool(${image} CONFIG_BOOT_ENCRYPT_IMAGE "${SB_CONFIG_BOOT_ENCRYPTION}") - if(SB_CONFIG_BOOT_ENCRYPTION) - set_config_string(${image} CONFIG_BOOT_ENCRYPTION_KEY_FILE "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}") - endif() endif() diff --git a/share/sysbuild/images/bootloader/Kconfig b/share/sysbuild/images/bootloader/Kconfig index e8c788f72c5..19924a6ca18 100644 --- a/share/sysbuild/images/bootloader/Kconfig +++ b/share/sysbuild/images/bootloader/Kconfig @@ -56,28 +56,12 @@ config BOOT_SIGNATURE_TYPE_ED25519 endchoice config BOOT_SIGNATURE_KEY_FILE - string "Signing PEM key file" + string "PEM key file" default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-ec-p256.pem" if BOOT_SIGNATURE_TYPE_ECDSA_P256 default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-ed25519.pem" if BOOT_SIGNATURE_TYPE_ED25519 default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/root-rsa-2048.pem" if BOOT_SIGNATURE_TYPE_RSA default "" help - Absolute path to signing key file to use with MCUBoot. - -config BOOT_ENCRYPTION - bool "Encrypted image support" - depends on !BOOT_SIGNATURE_TYPE_NONE - help - Support encrypted images. - -config BOOT_ENCRYPTION_KEY_FILE - string "Encryption PEM key file" - depends on BOOT_ENCRYPTION - default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/enc-ec256-priv.pem" if BOOT_SIGNATURE_TYPE_ECDSA_P256 - default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/enc-x25519-priv.pem" if BOOT_SIGNATURE_TYPE_ED25519 - default "$(ZEPHYR_MCUBOOT_MODULE_DIR)/enc-rsa2048-priv.pem" if BOOT_SIGNATURE_TYPE_RSA - default "" - help - Absolute path to encryption key file to use with MCUBoot. + Absolute path to key file to use with MCUBoot. endif From 17330500b22a4d4251c44d1a8558a0f3297f8569 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:44 +0000 Subject: [PATCH 0621/1623] Revert "[nrf fromtree] scripts: ci: Fix for compliance with multi-user machine" This reverts commit 9058a859d67b19c9d307943d8f206d917a37752a. Signed-off-by: Dominik Ermel --- scripts/ci/check_compliance.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 1499d92eaf9..74ddf19b2fb 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -16,7 +16,6 @@ import tempfile import traceback import shlex -import shutil from yamllint import config, linter @@ -370,8 +369,6 @@ def parse_kconfig(self): if not os.path.exists(kconfig_path): self.error(kconfig_path + " not found") - kconfiglib_dir = tempfile.mkdtemp(prefix="kconfiglib_") - sys.path.insert(0, kconfig_path) # Import globally so that e.g. kconfiglib.Symbol can be referenced in # tests @@ -386,7 +383,7 @@ def parse_kconfig(self): os.environ["ARCH_DIR"] = "arch/" os.environ["BOARD_DIR"] = "boards/*/*" os.environ["ARCH"] = "*" - os.environ["KCONFIG_BINARY_DIR"] = kconfiglib_dir + os.environ["KCONFIG_BINARY_DIR"] = tempfile.gettempdir() os.environ['DEVICETREE_CONF'] = "dummy" os.environ['TOOLCHAIN_HAS_NEWLIB'] = "y" @@ -395,9 +392,10 @@ def parse_kconfig(self): os.environ["GENERATED_DTS_BOARD_CONF"] = "dummy" # For multi repo support - self.get_modules(os.path.join(kconfiglib_dir, "Kconfig.modules")) + self.get_modules(os.path.join(tempfile.gettempdir(), "Kconfig.modules")) + # For Kconfig.dts support - self.get_kconfig_dts(os.path.join(kconfiglib_dir, "Kconfig.dts")) + self.get_kconfig_dts(os.path.join(tempfile.gettempdir(), "Kconfig.dts")) # Tells Kconfiglib to generate warnings for all references to undefined # symbols within Kconfig files @@ -412,9 +410,6 @@ def parse_kconfig(self): except kconfiglib.KconfigError as e: self.failure(str(e)) raise EndTest - finally: - # Clean up the temporary directory - shutil.rmtree(kconfiglib_dir) def get_defined_syms(self, kconf): # Returns a set() with the names of all defined Kconfig symbols (with no From c6c487715597ea2ee18744b84722cd771f1dbacf Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:44 +0000 Subject: [PATCH 0622/1623] Revert "[nrf fromtree] tests: bluetooth: tester: Fix GATT read multiple" This reverts commit 2e2523efe52a7ac89f0567b8798fd857b1e71ae3. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp_gatt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index 6509ca7fe4b..4d046cc3aad 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -1651,11 +1651,11 @@ static uint8_t read_multiple(const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } - if (cp->handles_count == 0 || cp->handles_count > ARRAY_SIZE(handles)) { + if (cp->handles_count > ARRAY_SIZE(handles)) { return BTP_STATUS_FAILED; } - for (i = 0; i < cp->handles_count; i++) { + for (i = 0; i < ARRAY_SIZE(handles); i++) { handles[i] = sys_le16_to_cpu(cp->handles[i]); } @@ -1670,7 +1670,7 @@ static uint8_t read_multiple(const void *cmd, uint16_t cmd_len, } read_params.func = read_cb; - read_params.handle_count = cp->handles_count; + read_params.handle_count = i; read_params.multiple.handles = handles; /* not used in read func */ read_params.multiple.variable = false; read_params.chan_opt = BT_ATT_CHAN_OPT_NONE; From 9600620aecb433f1f1fccd8389f5aaedcc35c5ba Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:45 +0000 Subject: [PATCH 0623/1623] Revert "[nrf fromlist] Bluetooth: Mesh: FU Server should not update internal state on error" This reverts commit 7ac418187369487f6fa633dab6d6c0a99913f479. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/dfu_srv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/dfu_srv.c b/subsys/bluetooth/mesh/dfu_srv.c index 462a777b46c..282a40074c9 100644 --- a/subsys/bluetooth/mesh/dfu_srv.c +++ b/subsys/bluetooth/mesh/dfu_srv.c @@ -302,10 +302,10 @@ static int handle_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, status = BT_MESH_DFU_ERR_WRONG_PHASE; } else { status = BT_MESH_DFU_SUCCESS; - srv->update.ttl = ttl; - srv->blob.state.xfer.id = blob_id; } + srv->update.ttl = ttl; + srv->blob.state.xfer.id = blob_id; LOG_WRN("Busy. Phase: %u", srv->update.phase); goto rsp; } From 8f5f55e7318f562c42a37e1fe4e7f35092f74e6d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:45 +0000 Subject: [PATCH 0624/1623] Revert "[nrf fromlist] Bluetooth: mesh: update model extension" This reverts commit 32a51d982e0b7eba7e458678a8246440b25c3916. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/access.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 6ca7dbe580b..63c4f76c392 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -1678,7 +1678,7 @@ int bt_mesh_model_extend(struct bt_mesh_model *extending_mod, struct bt_mesh_mod /* Check if a's list contains b */ for (it = a; (it != NULL) && (it->next != a); it = it->next) { if (it == b) { - goto register_extension; + return 0; } } @@ -1695,7 +1695,7 @@ int bt_mesh_model_extend(struct bt_mesh_model *extending_mod, struct bt_mesh_mod a->next = b; } -register_extension: + if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { return mod_rel_register(base_mod, extending_mod, RELATION_TYPE_EXT); } From 75708dd6049a7cb697f73c141fe8ff4bcbc69616 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:45 +0000 Subject: [PATCH 0625/1623] Revert "[nrf fromlist] Bluetooth: Mesh: Fix issue where dfu_cli could get stuck" This reverts commit 979569b82b96246889e67a17a4a7987710c4802e. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/dfu_cli.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/subsys/bluetooth/mesh/dfu_cli.c b/subsys/bluetooth/mesh/dfu_cli.c index 4db7779116b..3805a04e450 100644 --- a/subsys/bluetooth/mesh/dfu_cli.c +++ b/subsys/bluetooth/mesh/dfu_cli.c @@ -305,23 +305,6 @@ static void tx_end(int err, void *cb_data) blob_cli_broadcast_tx_complete(&cli->blob); } -static int tx(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, - const struct bt_mesh_send_cb *cb, struct bt_mesh_dfu_cli *cli) -{ - int err; - - err = bt_mesh_model_send(mod, ctx, buf, cb, cli); - if (err) { - LOG_ERR("Send err: %d", err); - if (cb) { - cb->end(err, cli); - } - return err; - } - - return 0; -} - static int info_get(struct bt_mesh_dfu_cli *cli, struct bt_mesh_msg_ctx *ctx, uint8_t idx, uint8_t max_count, const struct bt_mesh_send_cb *cb) @@ -331,7 +314,7 @@ static int info_get(struct bt_mesh_dfu_cli *cli, struct bt_mesh_msg_ctx *ctx, net_buf_simple_add_u8(&buf, idx); net_buf_simple_add_u8(&buf, max_count); - return tx(cli->mod, ctx, &buf, cb, cli); + return bt_mesh_model_send(cli->mod, ctx, &buf, cb, cli); } static void send_info_get(struct bt_mesh_blob_cli *b, uint16_t dst) @@ -369,7 +352,7 @@ static void send_update_start(struct bt_mesh_blob_cli *b, uint16_t dst) net_buf_simple_add_mem(&buf, cli->xfer.slot->metadata, cli->xfer.slot->metadata_len); - (void)tx(cli->mod, &ctx, &buf, &send_cb, cli); + bt_mesh_model_send(cli->mod, &ctx, &buf, &send_cb, cli); } static void send_update_get(struct bt_mesh_blob_cli *b, uint16_t dst) @@ -380,7 +363,7 @@ static void send_update_get(struct bt_mesh_blob_cli *b, uint16_t dst) BT_MESH_MODEL_BUF_DEFINE(buf, BT_MESH_DFU_OP_UPDATE_GET, 0); bt_mesh_model_msg_init(&buf, BT_MESH_DFU_OP_UPDATE_GET); - (void)tx(cli->mod, &ctx, &buf, &send_cb, cli); + bt_mesh_model_send(cli->mod, &ctx, &buf, &send_cb, cli); } static void send_update_cancel(struct bt_mesh_blob_cli *b, uint16_t dst) @@ -391,7 +374,7 @@ static void send_update_cancel(struct bt_mesh_blob_cli *b, uint16_t dst) BT_MESH_MODEL_BUF_DEFINE(buf, BT_MESH_DFU_OP_UPDATE_CANCEL, 0); bt_mesh_model_msg_init(&buf, BT_MESH_DFU_OP_UPDATE_CANCEL); - (void)tx(cli->mod, &ctx, &buf, &send_cb, cli); + bt_mesh_model_send(cli->mod, &ctx, &buf, &send_cb, cli); } static void send_update_apply(struct bt_mesh_blob_cli *b, uint16_t dst) @@ -402,7 +385,7 @@ static void send_update_apply(struct bt_mesh_blob_cli *b, uint16_t dst) BT_MESH_MODEL_BUF_DEFINE(buf, BT_MESH_DFU_OP_UPDATE_APPLY, 0); bt_mesh_model_msg_init(&buf, BT_MESH_DFU_OP_UPDATE_APPLY); - (void)tx(cli->mod, &ctx, &buf, &send_cb, cli); + bt_mesh_model_send(cli->mod, &ctx, &buf, &send_cb, cli); } /******************************************************************************* From 7612012dfcec90ad1b580b40c51ddbe480a57c15 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:45 +0000 Subject: [PATCH 0626/1623] Revert "[nrf fromlist] tests: bluetooth: tester: Allow to compile mesh without LPN" This reverts commit 66324255acd8c12723aaf62b8a61c2e1fb17c8f5. Signed-off-by: Dominik Ermel --- subsys/bluetooth/host/testing.c | 2 -- tests/bluetooth/tester/src/btp_mesh.c | 8 -------- 2 files changed, 10 deletions(-) diff --git a/subsys/bluetooth/host/testing.c b/subsys/bluetooth/host/testing.c index 3c118c51e0f..c3121fd230d 100644 --- a/subsys/bluetooth/host/testing.c +++ b/subsys/bluetooth/host/testing.c @@ -102,7 +102,6 @@ void bt_test_mesh_trans_incomp_timer_exp(void) } } -#if defined(CONFIG_BT_MESH_LOW_POWER) int bt_test_mesh_lpn_group_add(uint16_t group) { bt_mesh_lpn_group_add(group); @@ -116,7 +115,6 @@ int bt_test_mesh_lpn_group_remove(uint16_t *groups, size_t groups_count) return 0; } -#endif /* CONFIG_BT_MESH_LOW_POWER */ int bt_test_mesh_rpl_clear(void) { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index bdc37c2f2e5..5eff344540e 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1553,7 +1553,6 @@ static uint8_t ivu_toggle_state(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -#if defined(CONFIG_BT_MESH_LOW_POWER) static uint8_t lpn(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -1585,7 +1584,6 @@ static uint8_t lpn_poll(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -#endif /* CONFIG_BT_MESH_LOW_POWER */ static uint8_t net_send(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -1767,7 +1765,6 @@ static uint8_t model_send(const void *cmd, uint16_t cmd_len, } #if defined(CONFIG_BT_TESTING) -#if defined(CONFIG_BT_MESH_LOW_POWER) static uint8_t lpn_subscribe(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -1803,7 +1800,6 @@ static uint8_t lpn_unsubscribe(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -#endif /* CONFIG_BT_MESH_LOW_POWER */ static uint8_t rpl_clear(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -4583,7 +4579,6 @@ static const struct btp_handler handlers[] = { .expect_len = 0, .func = ivu_toggle_state, }, -#if defined(CONFIG_BT_MESH_LOW_POWER) { .opcode = BTP_MESH_LPN, .expect_len = sizeof(struct btp_mesh_lpn_set_cmd), @@ -4594,7 +4589,6 @@ static const struct btp_handler handlers[] = { .expect_len = 0, .func = lpn_poll, }, -#endif /* CONFIG_BT_MESH_LOW_POWER */ { .opcode = BTP_MESH_NET_SEND, .expect_len = BTP_HANDLER_LENGTH_VARIABLE, @@ -4906,7 +4900,6 @@ static const struct btp_handler handlers[] = { .func = va_del, }, #if defined(CONFIG_BT_TESTING) -#if defined(CONFIG_BT_MESH_LOW_POWER) { .opcode = BTP_MESH_LPN_SUBSCRIBE, .expect_len = sizeof(struct btp_mesh_lpn_subscribe_cmd), @@ -4917,7 +4910,6 @@ static const struct btp_handler handlers[] = { .expect_len = sizeof(struct btp_mesh_lpn_unsubscribe_cmd), .func = lpn_unsubscribe, }, -#endif /* CONFIG_BT_MESH_LOW_POWER */ { .opcode = BTP_MESH_RPL_CLEAR, .expect_len = 0, From 307236605e9564aba7068798cb3a807d392e0c04 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:45 +0000 Subject: [PATCH 0627/1623] Revert "[nrf fromlist] Bluetooth: Mesh: Keep sending Partial Block Report message" This reverts commit 834948da4a87ff41241bd325d685e4e474f511f4. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/blob_srv.c | 70 +++++++------------------------- 1 file changed, 14 insertions(+), 56 deletions(-) diff --git a/subsys/bluetooth/mesh/blob_srv.c b/subsys/bluetooth/mesh/blob_srv.c index 1e6cb9bc91a..56a89472ea6 100644 --- a/subsys/bluetooth/mesh/blob_srv.c +++ b/subsys/bluetooth/mesh/blob_srv.c @@ -251,37 +251,6 @@ static void resume(struct bt_mesh_blob_srv *srv) reset_timer(srv); } -static void end(struct bt_mesh_blob_srv *srv) -{ - phase_set(srv, BT_MESH_BLOB_XFER_PHASE_COMPLETE); - k_work_cancel_delayable(&srv->rx_timeout); - k_work_cancel_delayable(&srv->pull.report); - io_close(srv); - erase_state(srv); - - if (srv->cb && srv->cb->end) { - srv->cb->end(srv, srv->state.xfer.id, true); - } -} - -static bool all_blocks_received(struct bt_mesh_blob_srv *srv) -{ - for (int i = 0; i < ARRAY_SIZE(srv->state.blocks); ++i) { - if (srv->state.blocks[i]) { - return false; - } - } - - return true; -} - -static bool pull_mode_xfer_complete(struct bt_mesh_blob_srv *srv) -{ - return srv->state.xfer.mode == BT_MESH_BLOB_XFER_MODE_PULL && - srv->phase == BT_MESH_BLOB_XFER_PHASE_WAITING_FOR_CHUNK && - all_blocks_received(srv); -} - static void timeout(struct k_work *work) { struct bt_mesh_blob_srv *srv = @@ -291,8 +260,6 @@ static void timeout(struct k_work *work) if (srv->phase == BT_MESH_BLOB_XFER_PHASE_WAITING_FOR_START) { cancel(srv); - } else if (pull_mode_xfer_complete(srv)) { - end(srv); } else { suspend(srv); } @@ -421,15 +388,6 @@ static int handle_xfer_get(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ct struct bt_mesh_blob_srv *srv = mod->user_data; LOG_DBG(""); - - if (pull_mode_xfer_complete(srv)) { - /* The client requested transfer. If we are in Pull mode and all blocks were - * received, we should change the Transfer state here to Complete so that the client - * receives the correct state. - */ - end(srv); - } - xfer_status_rsp(srv, ctx, BT_MESH_BLOB_SUCCESS); return 0; @@ -727,7 +685,7 @@ static int handle_chunk(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, struct bt_mesh_blob_chunk chunk; size_t expected_size = 0; uint16_t idx; - int err; + int i, err; idx = net_buf_simple_pull_le16(buf); chunk.size = buf->len; @@ -787,26 +745,26 @@ static int handle_chunk(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, atomic_clear_bit(srv->state.blocks, srv->block.number); - if (!all_blocks_received(srv)) { + for (i = 0; i < ARRAY_SIZE(srv->state.blocks); ++i) { + if (!srv->state.blocks[i]) { + continue; + } + phase_set(srv, BT_MESH_BLOB_XFER_PHASE_WAITING_FOR_BLOCK); store_state(srv); return 0; } - if (srv->state.xfer.mode == BT_MESH_BLOB_XFER_MODE_PULL) { - /* By spec (section 5.2.4), the BLOB Server stops sending BLOB Partial Block Report - * messages "If the current block is the last block, then the server determines that - * the client knows the transfer is complete. For example, a higher-layer model may - * indicate that the client considers the transfer complete." - * - * We don't have any way for higher-layer model to indicate that the transfer is - * complete. Therefore we need to keep sending Partial Block Report messages until - * the client sends BLOB Transfer Get message or the Block Timer expires. - */ - return 0; + phase_set(srv, BT_MESH_BLOB_XFER_PHASE_COMPLETE); + k_work_cancel_delayable(&srv->rx_timeout); + k_work_cancel_delayable(&srv->pull.report); + io_close(srv); + erase_state(srv); + + if (srv->cb && srv->cb->end) { + srv->cb->end(srv, srv->state.xfer.id, true); } - end(srv); return 0; } From 479282b516db4cf20a6f07590b0107785a18790b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:46 +0000 Subject: [PATCH 0628/1623] Revert "[nrf fromlist] tests: bluetooth: tester: Fix BLOB server model pointer" This reverts commit d78ae6b7ad3e60ef3a63ad7b6e1ea8a01eb3f963. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp_mesh.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 5eff344540e..c43f19f04ce 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -4468,10 +4468,10 @@ static uint8_t blob_srv_recv(const void *cmd, uint16_t cmd_len, struct model_data *model_bound; int err; -#if defined(CONFIG_BT_MESH_DFD_SRV) - struct bt_mesh_blob_srv *srv = &dfd_srv.upload.blob; -#elif defined(CONFIG_BT_MESH_DFU_SRV) +#if defined(CONFIG_BT_MESH_DFU_SRV) struct bt_mesh_blob_srv *srv = &dfu_srv.blob; +#elif defined(CONFIG_BT_MESH_DFD_SRV) + struct bt_mesh_blob_srv *srv = &dfd_srv.upload.blob; #endif model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_SRV); From 338c2b0fe0c67376f345e33cf963a43e7de23157 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:46 +0000 Subject: [PATCH 0629/1623] Revert "[nrf fromlist] manifest: update hal_nordic to fix nRF52820 nrfx_gpiote" This reverts commit 93c996c9b8653daee0e15d94ff81b8369d9efdeb. Signed-off-by: Dominik Ermel --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 909800d0aab..f5366678a0e 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 427ee1a519e8a0844d0f78f7cbc8cdfc134ef00d + revision: 568a5e90b858a2e5b640b3fe6ab9b59dd2ce9f7f path: modules/hal/nordic groups: - hal From 5dac69c0d14a486cd99cc35a962df9fddf1cdbb8 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:46 +0000 Subject: [PATCH 0630/1623] Revert "[nrf fromtree] dts: arm: nordic: Add support for ieee802154 in the nRF52820 radio" This reverts commit fc7f82d468f64955083d0e8ed307965020c70326. Signed-off-by: Dominik Ermel --- dts/arm/nordic/nrf52820.dtsi | 6 ------ 1 file changed, 6 deletions(-) diff --git a/dts/arm/nordic/nrf52820.dtsi b/dts/arm/nordic/nrf52820.dtsi index c3d05fc6ec1..6d2f5eb02fe 100644 --- a/dts/arm/nordic/nrf52820.dtsi +++ b/dts/arm/nordic/nrf52820.dtsi @@ -88,15 +88,9 @@ interrupts = <1 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; dfe-supported; - ieee802154-supported; ble-2mbps-supported; ble-coded-phy-supported; tx-high-power-supported; - - ieee802154: ieee802154 { - compatible = "nordic,nrf-ieee802154"; - status = "disabled"; - }; }; uart0: uart@40002000 { From 7f7ff88d584fbb8aa2667b0a754fbefba7de945b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:46 +0000 Subject: [PATCH 0631/1623] Revert "[nrf fromlist] modules: hal_nordic: cmake: Fix checking if uicr DT node is accessible" This reverts commit a0d7c03a96a5ed77ca937491207044d0e538ac38. Signed-off-by: Dominik Ermel --- modules/hal_nordic/nrfx/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index ca325c31770..e98db561906 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -116,7 +116,7 @@ endif() # doing the proper configuration sequence during system init dt_nodelabel(uicr_path NODELABEL "uicr") -if(DEFINED uicr_path) +if(${uicr_path}) dt_prop(nfct_pins_as_gpios PATH ${uicr_path} PROPERTY "nfct-pins-as-gpios") if(${nfct_pins_as_gpios}) zephyr_library_compile_definitions(CONFIG_NFCT_PINS_AS_GPIOS) From 8a4a5f65eff3964f4dbdf8769a603267e2abda05 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:47 +0000 Subject: [PATCH 0632/1623] Revert "[nrf fromlist] tests: bluetooth: tester: add page number to response" This reverts commit ea44fcffcc107ced832752c7f8f91ffc559b8b56. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp_mesh.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index c43f19f04ce..1d6f696f729 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -2033,9 +2033,8 @@ static uint8_t composition_data_get(const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } - rp->data[0] = page; - memcpy(rp->data + 1, comp->data, comp->len); - *rsp_len = comp->len + 1; + memcpy(rp->data, comp->data, comp->len); + *rsp_len = comp->len; return BTP_STATUS_SUCCESS; } From 292aca50f662d5b57544787da0fc21a37a7958e4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:47 +0000 Subject: [PATCH 0633/1623] Revert "[nrf fromtree] Bluetooth: Mesh: improve solicitation debug logging" This reverts commit 52be85e04f3633e508156f79c8e13e87362c5a38. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/solicitation.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/mesh/solicitation.c b/subsys/bluetooth/mesh/solicitation.c index e2100fa42db..f6543dcb320 100644 --- a/subsys/bluetooth/mesh/solicitation.c +++ b/subsys/bluetooth/mesh/solicitation.c @@ -190,14 +190,13 @@ void bt_mesh_sol_recv(struct net_buf_simple *buf, uint8_t uuid_list_len) if (bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED || bt_mesh_priv_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED || bt_mesh_od_priv_proxy_get() == 0) { - LOG_DBG("Not soliciting"); return; } /* Get rid of ad_type that was checked in bt_mesh_scan_cb */ type = net_buf_simple_pull_u8(buf); if (type != BT_DATA_UUID16_SOME && type != BT_DATA_UUID16_ALL) { - LOG_DBG("Invalid type 0x%x, expected 0x%x or 0x%x", + LOG_ERR("Invalid type 0x%x, expected 0x%x or 0x%x", type, BT_DATA_UUID16_SOME, BT_DATA_UUID16_ALL); return; } @@ -216,7 +215,6 @@ void bt_mesh_sol_recv(struct net_buf_simple *buf, uint8_t uuid_list_len) } if (!sol_uuid_found) { - LOG_DBG("No solicitation UUID found"); return; } @@ -232,7 +230,6 @@ void bt_mesh_sol_recv(struct net_buf_simple *buf, uint8_t uuid_list_len) } if (buf->len <= reported_len - 3) { - LOG_DBG("Invalid length (%u) Solicitation PDU", buf->len); return; } @@ -240,13 +237,12 @@ void bt_mesh_sol_recv(struct net_buf_simple *buf, uint8_t uuid_list_len) } if (!svc_data_found) { - LOG_DBG("No solicitation service data found"); return; } type = net_buf_simple_pull_u8(buf); if (type != 0) { - LOG_DBG("Invalid type %d, expected 0x00", type); + LOG_ERR("Invalid type %d, expected 0x00", type); return; } From 3cdf9378c84d382729ce1f10fa2e51da2d6708fc Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:47 +0000 Subject: [PATCH 0634/1623] Revert "[nrf fromtree] tests: bluetooth: tester: enable proxy solicitation" This reverts commit 7b5fbe1bc0b575d221003234f7772696fd9978cd. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/overlay-mesh-v1d1.conf | 1 - tests/bluetooth/tester/src/btp_mesh.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh-v1d1.conf b/tests/bluetooth/tester/overlay-mesh-v1d1.conf index 52045ce34df..978d1acd3df 100644 --- a/tests/bluetooth/tester/overlay-mesh-v1d1.conf +++ b/tests/bluetooth/tester/overlay-mesh-v1d1.conf @@ -23,7 +23,6 @@ CONFIG_BT_MESH_DFU_SLOT_CNT=2 CONFIG_BT_MESH_PRIV_BEACONS=y CONFIG_BT_MESH_PRIV_BEACON_SRV=y CONFIG_BT_MESH_PRIV_BEACON_CLI=y -CONFIG_BT_MESH_OD_PRIV_PROXY_SRV=y CONFIG_BT_MESH_MODEL_EXTENSIONS=y CONFIG_BT_MESH_COMP_PAGE_1=y CONFIG_BT_MESH_COMP_PAGE_2=y diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 1d6f696f729..81c41dca708 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -5081,7 +5081,7 @@ static const struct btp_handler handlers[] = { .func = srpl_clear }, #endif -#if defined(CONFIG_BT_MESH_PROXY_SOLICITATION) +#if defined(CONFIG_BT_MESH_SOLICITATION) { .opcode = BTP_MESH_PROXY_SOLICIT, .expect_len = sizeof(struct btp_proxy_solicit_cmd), From 13ef034a85b5c3f50efdeb1faab939bce1218d65 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:47 +0000 Subject: [PATCH 0635/1623] Revert "[nrf fromtree] Bluetooth: Mesh: fix proxy solicitation" This reverts commit 5fed002128563c138ff679fdb35ac1b4f9ecb064. Signed-off-by: Dominik Ermel --- include/zephyr/bluetooth/uuid.h | 2 +- subsys/bluetooth/mesh/crypto.c | 2 +- subsys/bluetooth/mesh/proxy_srv.c | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/zephyr/bluetooth/uuid.h b/include/zephyr/bluetooth/uuid.h index cab12eac74b..1fa8ece6466 100644 --- a/include/zephyr/bluetooth/uuid.h +++ b/include/zephyr/bluetooth/uuid.h @@ -587,7 +587,7 @@ struct bt_uuid_128 { /** * @brief Proxy Solicitation UUID value */ -#define BT_UUID_MESH_PROXY_SOLICITATION_VAL 0x1859 +#define BT_UUID_MESH_PROXY_SOLICITATION_VAL 0x7fcb /** * @brief Reconnection Configuration Service UUID value */ diff --git a/subsys/bluetooth/mesh/crypto.c b/subsys/bluetooth/mesh/crypto.c index b79458f7ea2..e42717475c0 100644 --- a/subsys/bluetooth/mesh/crypto.c +++ b/subsys/bluetooth/mesh/crypto.c @@ -419,7 +419,7 @@ int bt_mesh_net_decrypt(const struct bt_mesh_key *key, struct net_buf_simple *bu if (IS_ENABLED(CONFIG_BT_MESH_PROXY) && type == BT_MESH_NONCE_PROXY) { create_proxy_nonce(nonce, buf->data, iv_index); - } else if (IS_ENABLED(CONFIG_BT_MESH_SOLICITATION) && + } else if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && type == BT_MESH_NONCE_SOLICITATION) { create_proxy_sol_nonce(nonce, buf->data); } else { diff --git a/subsys/bluetooth/mesh/proxy_srv.c b/subsys/bluetooth/mesh/proxy_srv.c index 12775b93651..62c46582fa0 100644 --- a/subsys/bluetooth/mesh/proxy_srv.c +++ b/subsys/bluetooth/mesh/proxy_srv.c @@ -698,11 +698,9 @@ static void gatt_proxy_solicited(struct bt_mesh_subnet *sub) if (sub->priv_net_id_sent > 0) { timeout = sub->priv_net_id_sent + MSEC_PER_SEC * bt_mesh_od_priv_proxy_get(); - remaining = MIN(timeout - now, INT32_MAX); - } else { - remaining = MSEC_PER_SEC * bt_mesh_od_priv_proxy_get(); } + remaining = MIN(timeout - now, INT32_MAX); if ((timeout > 0 && now > timeout) || (remaining / MSEC_PER_SEC < 1)) { LOG_DBG("Advertising Private Network ID timed out " "after solicitation"); From ab472d62eee5ed9c52e4412a63b22b216603fdb5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:47 +0000 Subject: [PATCH 0636/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Fix failing DFU/SR/FD/BV-08-C test" This reverts commit a17674613fd86db048183888dc1f55f1b72875f2. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/dfd_srv.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 0a9ecba6cec..d225f67bb77 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -412,20 +412,12 @@ static inline int set_upload_fwid(struct bt_mesh_dfd_srv *srv, struct bt_mesh_ms case -EFBIG: /* Fwid too long */ case -EALREADY: /* Other server is in progress with this fwid */ bt_mesh_dfu_slot_release(srv->upload.slot); - srv->upload.slot = NULL; upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); break; case -EEXIST: /* Img with this fwid already is in list */ srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; bt_mesh_dfu_slot_release(srv->upload.slot); - - err = bt_mesh_dfu_slot_get(fwid, fwid_len, &srv->upload.slot); - if (!err) { - upload_status_rsp_with_progress(srv, ctx, BT_MESH_DFD_SUCCESS, 100); - } else { - srv->upload.slot = NULL; - upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); - } + upload_status_rsp_with_progress(srv, ctx, BT_MESH_DFD_SUCCESS, 100); break; case 0: srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE; From a42960ee2972fe1e7a445689a429d59e07c58c85 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:48 +0000 Subject: [PATCH 0637/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Fix Capabilities Status message with OOB upload enabled" This reverts commit 1fc4225e4d05cc510aef22d8b69b918f559533f4. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/dfd_srv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index d225f67bb77..2547c07a5b4 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -233,10 +233,11 @@ static int handle_capabilities_get(struct bt_mesh_model *mod, struct bt_mesh_msg net_buf_simple_add_mem(&rsp, srv->oob_schemes.schemes, srv->oob_schemes.count); } else -#endif +#else { net_buf_simple_add_u8(&rsp, 0); } +#endif bt_mesh_model_send(mod, ctx, &rsp, NULL, NULL); From 3719292ec85c0e93c15a9b05c7556bd2b9ba13dd Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:48 +0000 Subject: [PATCH 0638/1623] Revert "[nrf fromlist] manifest: update hal_nordic rev to fix nRF91 anomaly 7" This reverts commit 6c895c5d3ee5b98453112f1855a646624211c68c. Signed-off-by: Dominik Ermel --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index f5366678a0e..bed3b47cfe5 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 568a5e90b858a2e5b640b3fe6ab9b59dd2ce9f7f + revision: 092eb78ed1b1551d8f480019b9c05d7371784578 path: modules/hal/nordic groups: - hal From 1ab6c6feead2b3e66ace284d04e73eeeb86b0273 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:48 +0000 Subject: [PATCH 0639/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Print URI and FWID in Upload OOB Start msg" This reverts commit e5ab2f9978ecfdde887735f5e59d28912a5ddb4d. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/dfd_srv.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 2547c07a5b4..cfcc82eb8d1 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -572,10 +572,6 @@ static int handle_upload_start_oob(struct bt_mesh_model *mod, struct bt_mesh_msg fwid_len = buf->len; fwid = net_buf_simple_pull_mem(buf, fwid_len); - LOG_DBG("Upload OOB Start"); - LOG_HEXDUMP_DBG(uri, uri_len, "URI"); - LOG_HEXDUMP_DBG(fwid, fwid_len, "FWID"); - if (upload_is_busy(srv)) { #ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD if (srv->upload.is_oob && From 53fd91da8c930af458d52cab93e7ccee894d7fad Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:48 +0000 Subject: [PATCH 0640/1623] Revert "[nrf fromtree] tests: bluetooth: tester: Add Upload OOB support for mesh tester" This reverts commit 5640e9e33ab1bfaca4ed341b0d752518ed181de2. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp_mesh.c | 119 -------------------------- 1 file changed, 119 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 81c41dca708..662dca238c1 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -162,132 +162,13 @@ static int dfd_srv_send(struct bt_mesh_dfd_srv *srv, return 0; } -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD -static struct { - uint8_t uri[CONFIG_BT_MESH_DFU_URI_MAXLEN]; - uint8_t uri_len; - uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; - uint8_t fwid_len; - const struct bt_mesh_dfu_slot *slot; - uint8_t progress; - bool started; -} dfd_srv_oob_ctx; - -static void oob_check_handler(struct k_work *work); -static K_WORK_DEFINE(oob_check, oob_check_handler); -static void oob_store_handler(struct k_work *work); -static K_WORK_DEFINE(oob_store, oob_store_handler); - -static int dfd_srv_start_oob_upload(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot, - const char *uri, uint8_t uri_len, - const uint8_t *fwid, uint16_t fwid_len) -{ - LOG_DBG("Start OOB Upload"); - - memcpy(dfd_srv_oob_ctx.uri, uri, uri_len); - dfd_srv_oob_ctx.uri_len = uri_len; - memcpy(dfd_srv_oob_ctx.fwid, fwid, fwid_len); - dfd_srv_oob_ctx.fwid_len = fwid_len; - dfd_srv_oob_ctx.slot = slot; - dfd_srv_oob_ctx.progress = 0; - dfd_srv_oob_ctx.started = true; - - k_work_submit(&oob_check); - - return BT_MESH_DFD_SUCCESS; -} - -static void dfd_srv_cancel_oob_upload(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot) -{ - LOG_DBG("Cancel OOB Upload"); - - dfd_srv_oob_ctx.started = false; -} - -static uint8_t dfd_srv_oob_progress_get(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot) -{ - uint8_t progress; - - if (dfd_srv_oob_ctx.started) { - progress = dfd_srv_oob_ctx.progress; - - dfd_srv_oob_ctx.progress = MIN(dfd_srv_oob_ctx.progress + 25, 99); - - if (dfd_srv_oob_ctx.progress == 99) { - k_work_submit(&oob_store); - } - } else { - progress = 0; - } - - LOG_DBG("OOB Progress Get (%sstarted: %d %%)", dfd_srv_oob_ctx.started ? "" : "not ", - progress); - return progress; -} -#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ - static struct bt_mesh_dfd_srv_cb dfd_srv_cb = { .recv = dfd_srv_recv, .del = dfd_srv_del, .send = dfd_srv_send, -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - .start_oob_upload = dfd_srv_start_oob_upload, - .cancel_oob_upload = dfd_srv_cancel_oob_upload, - .oob_progress_get = dfd_srv_oob_progress_get, -#endif }; static struct bt_mesh_dfd_srv dfd_srv = BT_MESH_DFD_SRV_INIT(&dfd_srv_cb); - -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD -#define SUPPORTED_SCHEME "http" - -static void oob_check_handler(struct k_work *work) -{ - uint8_t scheme[10]; - int i; - int status; - int err; - - for (i = 0; i < MIN(dfd_srv_oob_ctx.uri_len, sizeof(scheme)); i++) { - if (IN_RANGE(dfd_srv_oob_ctx.uri[i], 48, 57) || /* DIGIT */ - IN_RANGE(dfd_srv_oob_ctx.uri[i], 65, 90) || /* ALPHA UPPER CASE */ - IN_RANGE(dfd_srv_oob_ctx.uri[i], 97, 122) || /* ALPHA LOWER CASE */ - dfd_srv_oob_ctx.uri[i] == '.' || - dfd_srv_oob_ctx.uri[i] == '+' || - dfd_srv_oob_ctx.uri[i] == '-') { - scheme[i] = dfd_srv_oob_ctx.uri[i]; - } else { - break; - } - } - - if (i == dfd_srv_oob_ctx.uri_len || dfd_srv_oob_ctx.uri[i] != ':') { - status = BT_MESH_DFD_ERR_URI_MALFORMED; - } else if (i != strlen(SUPPORTED_SCHEME) || - memcmp(scheme, SUPPORTED_SCHEME, strlen(SUPPORTED_SCHEME))) { - status = BT_MESH_DFD_ERR_URI_NOT_SUPPORTED; - } else { - status = BT_MESH_DFD_SUCCESS; - } - - err = bt_mesh_dfd_srv_oob_check_complete(&dfd_srv, dfd_srv_oob_ctx.slot, status, - dfd_srv_oob_ctx.fwid, dfd_srv_oob_ctx.fwid_len); - LOG_DBG("OOB check completed (err %d)", err); -} - -static void oob_store_handler(struct k_work *work) -{ - int err; - - err = bt_mesh_dfd_srv_oob_store_complete(&dfd_srv, dfd_srv_oob_ctx.slot, true, - 10000, "metadata", 8); - LOG_DBG("OOB store completed (err %d)", err); -} -#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ #endif #if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) From 6c3bea1bf35369fa39339ec575cded547761cfed Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:49 +0000 Subject: [PATCH 0641/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Release previously reserved slot before reserving again" This reverts commit c97f38205f50eceac6b66359799e19df5b6aeb28. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/dfd_srv.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index cfcc82eb8d1..f8dfaf0b97f 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -607,13 +607,6 @@ static int handle_upload_start_oob(struct bt_mesh_model *mod, struct bt_mesh_msg return 0; } - /* This will be a no-op if the slot state isn't RESERVED, which is - * what we want. - */ - if (srv->upload.slot) { - bt_mesh_dfu_slot_release(srv->upload.slot); - } - srv->upload.is_oob = true; srv->upload.slot = slot; memcpy(srv->upload.oob.uri, uri, uri_len); From bfa9e4f7f84f58af8c7eb53f2bb8cb804747c102 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:49 +0000 Subject: [PATCH 0642/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Ignore duplicate OOB upload request" This reverts commit a2744d2bdee2459cd9dd0ebec788a99d82b02f7b. Signed-off-by: Dominik Ermel --- include/zephyr/bluetooth/mesh/dfd_srv.h | 1 - subsys/bluetooth/mesh/dfd_srv.c | 12 +----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/dfd_srv.h b/include/zephyr/bluetooth/mesh/dfd_srv.h index 666e0d8ad3d..da339c57ec6 100644 --- a/include/zephyr/bluetooth/mesh/dfd_srv.h +++ b/include/zephyr/bluetooth/mesh/dfd_srv.h @@ -228,7 +228,6 @@ struct bt_mesh_dfd_srv { struct bt_mesh_blob_srv blob; #ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD bool is_oob; - bool is_pending_oob_check; struct { uint8_t uri_len; uint8_t uri[CONFIG_BT_MESH_DFU_URI_MAXLEN]; diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index f8dfaf0b97f..f060e263ace 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -586,11 +586,6 @@ static int handle_upload_start_oob(struct bt_mesh_model *mod, struct bt_mesh_msg #endif upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_BUSY_WITH_UPLOAD); return 0; -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - } else if (srv->upload.is_oob && srv->upload.is_pending_oob_check) { - /* Ignore the request if we didn't confirm the previous one. */ - return 0; -#endif } #ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD @@ -623,8 +618,6 @@ static int handle_upload_start_oob(struct bt_mesh_model *mod, struct bt_mesh_msg if (status != BT_MESH_DFD_SUCCESS) { upload_status_rsp(srv, ctx, status); bt_mesh_dfu_slot_release(srv->upload.slot); - } else { - srv->upload.is_pending_oob_check = true; } #else upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_URI_NOT_SUPPORTED); @@ -1218,16 +1211,13 @@ int bt_mesh_dfd_srv_oob_check_complete(struct bt_mesh_dfd_srv *srv, int err; if (slot != srv->upload.slot || !srv->upload.is_oob || - srv->upload.phase == BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE || - !srv->upload.is_pending_oob_check) { + srv->upload.phase == BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE) { /* This should not happen, unless the application calls the function with a * "wrong" pointer or at a wrong time. */ return -EINVAL; } - srv->upload.is_pending_oob_check = false; - if (status != BT_MESH_DFD_SUCCESS) { bt_mesh_dfu_slot_release(srv->upload.slot); upload_status_rsp(srv, &srv->upload.oob.ctx, status); From 8266925385206874d57d67a9e9bde2f842f32fde Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:49 +0000 Subject: [PATCH 0643/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Fix Fw Dist Upload OOB Start msg length check" This reverts commit 4491262ebf889bf6bcb1ff2aed0c504a9f3cb17a. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/dfd_srv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index f060e263ace..a67a3a778ca 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -761,7 +761,7 @@ const struct bt_mesh_model_op _bt_mesh_dfd_srv_op[] = { { BT_MESH_DFD_OP_APPLY, BT_MESH_LEN_EXACT(0), handle_apply }, { BT_MESH_DFD_OP_UPLOAD_GET, BT_MESH_LEN_EXACT(0), handle_upload_get }, { BT_MESH_DFD_OP_UPLOAD_START, BT_MESH_LEN_MIN(16), handle_upload_start }, - { BT_MESH_DFD_OP_UPLOAD_START_OOB, BT_MESH_LEN_MIN(2), handle_upload_start_oob }, + { BT_MESH_DFD_OP_UPLOAD_START_OOB, BT_MESH_LEN_EXACT(2), handle_upload_start_oob }, { BT_MESH_DFD_OP_UPLOAD_CANCEL, BT_MESH_LEN_EXACT(0), handle_upload_cancel }, { BT_MESH_DFD_OP_FW_GET, BT_MESH_LEN_MIN(0), handle_fw_get }, { BT_MESH_DFD_OP_FW_GET_BY_INDEX, BT_MESH_LEN_EXACT(2), handle_fw_get_by_index }, From 32374909565a7901bf6760e953e02b511315f9c4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:49 +0000 Subject: [PATCH 0644/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Fix Upload Progress for already received fw" This reverts commit 74bdabf7e57a988ad740da44398cf93f7d5e0c79. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/dfd_srv.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index a67a3a778ca..5d3ada4b4aa 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -342,10 +342,9 @@ static int handle_apply(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, return 0; } -static void upload_status_rsp_with_progress(struct bt_mesh_dfd_srv *srv, - struct bt_mesh_msg_ctx *ctx, - enum bt_mesh_dfd_status status, - uint8_t progress) +static void upload_status_rsp(struct bt_mesh_dfd_srv *srv, + struct bt_mesh_msg_ctx *ctx, + enum bt_mesh_dfd_status status) { BT_MESH_MODEL_BUF_DEFINE(rsp, BT_MESH_DFD_OP_UPLOAD_STATUS, DFD_UPLOAD_STATUS_MSG_MAXLEN); @@ -362,13 +361,14 @@ static void upload_status_rsp_with_progress(struct bt_mesh_dfd_srv *srv, #ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD if (srv->upload.is_oob) { - net_buf_simple_add_u8(&rsp, progress | BIT(7)); + net_buf_simple_add_u8(&rsp, + srv->cb->oob_progress_get(srv, srv->upload.slot) | BIT(7)); net_buf_simple_add_mem(&rsp, srv->upload.oob.current_fwid, srv->upload.oob.current_fwid_len); } else #endif { - net_buf_simple_add_u8(&rsp, progress); + net_buf_simple_add_u8(&rsp, bt_mesh_blob_srv_progress(&srv->upload.blob)); net_buf_simple_add_mem(&rsp, srv->upload.slot->fwid, srv->upload.slot->fwid_len); } @@ -376,24 +376,6 @@ static void upload_status_rsp_with_progress(struct bt_mesh_dfd_srv *srv, bt_mesh_model_send(srv->mod, ctx, &rsp, NULL, NULL); } -static void upload_status_rsp(struct bt_mesh_dfd_srv *srv, - struct bt_mesh_msg_ctx *ctx, - enum bt_mesh_dfd_status status) -{ - uint8_t progress; - -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - if (srv->upload.is_oob) { - progress = srv->cb->oob_progress_get(srv, srv->upload.slot); - } else -#endif - { - progress = bt_mesh_blob_srv_progress(&srv->upload.blob); - } - - upload_status_rsp_with_progress(srv, ctx, status, progress); -} - static int handle_upload_get(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { @@ -418,7 +400,7 @@ static inline int set_upload_fwid(struct bt_mesh_dfd_srv *srv, struct bt_mesh_ms case -EEXIST: /* Img with this fwid already is in list */ srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; bt_mesh_dfu_slot_release(srv->upload.slot); - upload_status_rsp_with_progress(srv, ctx, BT_MESH_DFD_SUCCESS, 100); + upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); break; case 0: srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE; From be050cfb258b3df56acd11dac414630101f1314a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:50 +0000 Subject: [PATCH 0645/1623] Revert "[nrf fromtree] bluetooth: common: Kconfig: Add missing dependency for BT_MONITOR" This reverts commit 7e3e8dea4ba07c5730b6d037ba50ddede860bc1b. Signed-off-by: Dominik Ermel --- subsys/bluetooth/common/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index bf4aee75e48..d72ce90afa6 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -282,7 +282,6 @@ endif # BT_ASSERT config BT_MONITOR bool - select LOG_OUTPUT choice BT_DEBUG_TYPE prompt "Bluetooth debug type" From ce5d78f17a4ff51f9c730d668256142d65b78734 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:50 +0000 Subject: [PATCH 0646/1623] Revert "[nrf fromtree] tests: kernel: timer: jitter_drift: Restore initial alignment to tick" This reverts commit a4670ff4eabc3517bda2bc34b25b97e2159c33dd. Signed-off-by: Dominik Ermel --- tests/kernel/timer/timer_behavior/src/jitter_drift.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/kernel/timer/timer_behavior/src/jitter_drift.c b/tests/kernel/timer/timer_behavior/src/jitter_drift.c index 6d3e78d514b..cd6afaea00d 100644 --- a/tests/kernel/timer/timer_behavior/src/jitter_drift.c +++ b/tests/kernel/timer/timer_behavior/src/jitter_drift.c @@ -121,17 +121,6 @@ static void do_test_using(void (*sample_collection_fn)(void)) periodic_idx = 0; k_sem_init(&periodic_sem, 0, 1); - - /* Align to tick boundary. Otherwise the first handler execution - * might turn out to be significantly late and cause the test to - * fail. This can happen if k_timer_start() is called right before - * the upcoming tick boundary and in consequence the tick passes - * between the moment when the kernel decides what tick to use for - * the next timeout and the moment when the system timer actually - * sets up that timeout. - */ - k_sleep(K_TICKS(1)); - sample_collection_fn(); k_sem_take(&periodic_sem, K_FOREVER); From 8149a838c2ad4d1c980938110217d9078d4024cf Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:50 +0000 Subject: [PATCH 0647/1623] Revert "[nrf fromtree] drivers: spi_nrfx_spis: Handle empty spi_buf_set structures properly" This reverts commit 495c47634d7c2105b7dd21734ef4a87eb25ea932. Signed-off-by: Dominik Ermel --- drivers/spi/spi_nrfx_spis.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi_nrfx_spis.c b/drivers/spi/spi_nrfx_spis.c index d2a61530f00..6ba36a139a0 100644 --- a/drivers/spi/spi_nrfx_spis.c +++ b/drivers/spi/spi_nrfx_spis.c @@ -170,8 +170,6 @@ static int transceive(const struct device *dev, { struct spi_nrfx_data *dev_data = dev->data; const struct spi_nrfx_config *dev_config = dev->config; - const struct spi_buf *tx_buf = tx_bufs ? tx_bufs->buffers : NULL; - const struct spi_buf *rx_buf = rx_bufs ? rx_bufs->buffers : NULL; int error; spi_context_lock(&dev_data->ctx, asynchronous, cb, userdata, spi_cfg); @@ -183,7 +181,8 @@ static int transceive(const struct device *dev, (rx_bufs && rx_bufs->count > 1)) { LOG_ERR("Scattered buffers are not supported"); error = -ENOTSUP; - } else if (tx_buf && tx_buf->len && !nrfx_is_in_ram(tx_buf->buf)) { + } else if (tx_bufs && tx_bufs->buffers[0].len && + !nrfx_is_in_ram(tx_bufs->buffers[0].buf)) { LOG_ERR("Only buffers located in RAM are supported"); error = -ENOTSUP; } else { @@ -194,10 +193,10 @@ static int transceive(const struct device *dev, } error = prepare_for_transfer(dev, - tx_buf ? tx_buf->buf : NULL, - tx_buf ? tx_buf->len : 0, - rx_buf ? rx_buf->buf : NULL, - rx_buf ? rx_buf->len : 0); + tx_bufs ? tx_bufs->buffers[0].buf : NULL, + tx_bufs ? tx_bufs->buffers[0].len : 0, + rx_bufs ? rx_bufs->buffers[0].buf : NULL, + rx_bufs ? rx_bufs->buffers[0].len : 0); if (error == 0) { if (dev_config->wake_gpio.port) { /* Set the WAKE line low (tie it to ground) From a4d563dbfa43b58217a4ead6f31b4df2bc90e382 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:50 +0000 Subject: [PATCH 0648/1623] Revert "[nrf fromlist] nrf5340: pretick decoupled from workaround anomaly 160" This reverts commit 009e4d56688790dce25ab360d5add0ef44e92bd5. Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 1 - soc/arm/nordic_nrf/nrf53/soc.c | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 2cd934af324..87d961d6fb3 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -53,7 +53,6 @@ config SOC_NRF53_ANOMALY_160_WORKAROUND config SOC_NRF53_RTC_PRETICK bool "Pre-tick workaround for nRF5340 anomaly 165" - depends on (SYS_CLOCK_EXISTS && SOC_NRF5340_CPUNET) || SOC_NRF5340_CPUAPP select NRFX_DPPI select ARM_ON_ENTER_CPU_IDLE_HOOK if SOC_NRF5340_CPUNET select ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK if SOC_NRF5340_CPUNET diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index 39d64d72cc2..396ce79f49e 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -133,7 +133,6 @@ static bool nrf53_anomaly_160_check(void) return true; } -#endif /* CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND */ #if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) @@ -338,8 +337,6 @@ void z_arm_on_enter_cpu_idle_prepare(void) } #endif /* CONFIG_SOC_NRF53_RTC_PRETICK && CONFIG_SOC_NRF5340_CPUNET */ -#if defined(CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND) || \ - (defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET)) bool z_arm_on_enter_cpu_idle(void) { bool ok_to_sleep = true; @@ -360,7 +357,6 @@ bool z_arm_on_enter_cpu_idle(void) } #endif -#if defined(CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND) if (ok_to_sleep) { ok_to_sleep = nrf53_anomaly_160_check(); @@ -375,7 +371,6 @@ bool z_arm_on_enter_cpu_idle(void) } #endif } -#endif /* CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND */ #if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) if (!ok_to_sleep) { @@ -387,9 +382,7 @@ bool z_arm_on_enter_cpu_idle(void) return ok_to_sleep; } -#endif /* CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND || - * (CONFIG_SOC_NRF53_RTC_PRETICK && CONFIG_SOC_NRF5340_CPUNET) - */ +#endif /* CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND */ #if CONFIG_SOC_NRF53_RTC_PRETICK #ifdef CONFIG_SOC_NRF5340_CPUAPP From 7b288e716ae07f1fb9d5c7d273c43d1b41880488 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:51 +0000 Subject: [PATCH 0649/1623] Revert "[nrf fromlist] nrf53: fix RTC pretick for RTC rescheduling by other interrupts" This reverts commit fd1e8cfb37ef151b5421694bfde6857a8db18255. Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 6 +----- soc/arm/nordic_nrf/nrf53/soc.c | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 87d961d6fb3..87d8a6d0c7a 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -58,11 +58,7 @@ config SOC_NRF53_RTC_PRETICK select ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK if SOC_NRF5340_CPUNET help Indicates that the pre-tick workaround for the anomaly 165 that affects - the nRF5340 SoC should be applied. The workaround applies to wake ups caused - by EVENTS_COMPARE and EVENTS_OVRFLW on RTC0 and RTC1 for which interrupts are - enabled through INTENSET register. The case when these events are generated - by EVTEN but without interrupts enabled through INTENSET is not handled. - The EVENTS_TICK event is not handled. + the nRF5340 SoC should be applied. if SOC_NRF53_RTC_PRETICK diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index 396ce79f49e..c18228ac4fa 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -224,15 +224,6 @@ static bool cpu_idle_prepare_monitor_end(void) return __STREXB(0U, &cpu_idle_prepare_monitor_dummy); } -static void rtc_pretick_finish_previous(void) -{ - NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] &= - ~IPC_PUBLISH_RECEIVE_EN_Msk; - - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); -} - - void z_arm_on_enter_cpu_idle_prepare(void) { bool ok_to_sleep = true; @@ -272,7 +263,6 @@ void z_arm_on_enter_cpu_idle_prepare(void) if (rtc_pretick_cc_val != nrf_rtc_cc_get(NRF_RTC1, RTC1_PRETICK_CC_CHAN)) { /* The CC for pretick needs to be updated. */ - rtc_pretick_finish_previous(); nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_CC_CHAN, rtc_pretick_cc_val); if (rtc_ticks_to_next_event >= NRF_RTC_COUNTER_MAX/2) { @@ -416,14 +406,22 @@ static int rtc_pretick_cpuapp_init(void) } #else /* CONFIG_SOC_NRF5340_CPUNET */ +static void rtc_pretick_rtc_isr_hook(void) +{ + NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] &= + ~IPC_PUBLISH_RECEIVE_EN_Msk; + + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); +} + void rtc_pretick_rtc0_isr_hook(void) { - rtc_pretick_finish_previous(); + rtc_pretick_rtc_isr_hook(); } void rtc_pretick_rtc1_isr_hook(void) { - rtc_pretick_finish_previous(); + rtc_pretick_rtc_isr_hook(); } static int rtc_pretick_cpunet_init(void) From 0a4cc7cd79755e77725b94b16eb1246f6c813167 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:51 +0000 Subject: [PATCH 0650/1623] Revert "[nrf fromtree] tests: bluetooth: controller: Included kconfigs for ISO-AL logging" This reverts commit d03d84372b9ee34a6d22066899041c0da203d168. Signed-off-by: Dominik Ermel --- tests/bluetooth/ctrl_isoal/Kconfig | 19 ------------------- tests/bluetooth/ctrl_isoal/prj.conf | 2 -- 2 files changed, 21 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/Kconfig b/tests/bluetooth/ctrl_isoal/Kconfig index 30049d53a5e..b7c10723b93 100644 --- a/tests/bluetooth/ctrl_isoal/Kconfig +++ b/tests/bluetooth/ctrl_isoal/Kconfig @@ -12,25 +12,6 @@ config BT_CTLR_CONN_ISO_GROUPS range 1 240 default 1 -config BT_CTLR_DEBUG_ISOAL - bool "[DEPRECATED] Bluetooth ISO-AL debug" - select DEPRECATED - depends on BT_CTLR_ISO - help - This option enables debug support for the Bluetooth ISO-AL. - -module = BT_CTLR_ISOAL -legacy-debug-sym = BT_CTLR_DEBUG_ISOAL -module-str = "Bluetooth Controller ISO-AL" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_CTLR_ISOAL_LOG_DBG_VERBOSE - bool "ISO-AL verbose debug logging" - depends on BT_CTLR_ISOAL_LOG_LEVEL = 4 - default n - help - Use this option to enable ISO-AL verbose debug logging. - config BT_CTLR_ISOAL_SINKS int "Number of Isochronous Adaptation Layer sinks (for unit tests)" diff --git a/tests/bluetooth/ctrl_isoal/prj.conf b/tests/bluetooth/ctrl_isoal/prj.conf index 2f429dd8c47..5009e2785f8 100644 --- a/tests/bluetooth/ctrl_isoal/prj.conf +++ b/tests/bluetooth/ctrl_isoal/prj.conf @@ -9,5 +9,3 @@ CONFIG_BT_CTLR_CONN_ISO=y CONFIG_BT_CTLR_ISOAL_SINKS=4 CONFIG_BT_CTLR_ISOAL_SOURCES=4 CONFIG_BT_CTLR_ISO_RX_SDU_BUFFERS=4 - -CONFIG_BT_CTLR_ISOAL_LOG_LEVEL_INF=y From 4e4eb70451877f1251490e4f364532e54ab238dc Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:51 +0000 Subject: [PATCH 0651/1623] Revert "[nrf fromtree] tests: bluetooth: controller: Updated ISO-AL tests for length of err PDU" This reverts commit d1b4bbfe99dd4cf897c9d72d830ea99a894bc48c. Signed-off-by: Dominik Ermel --- .../ctrl_isoal/src/sub_sets/isoal_test_rx.c | 115 ++++++++++-------- 1 file changed, 64 insertions(+), 51 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c index fdb86af1f5c..5a3c60e0854 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c @@ -60,19 +60,19 @@ static isoal_status_t custom_sink_sdu_alloc_test(const struct isoal_sink *sink_c #define ZASSERT_ISOAL_SDU_ALLOC_TEST(_typ, _sink, _pdu) \ zassert_equal_ptr(_sink, \ sink_sdu_alloc_test_fake.arg0_##_typ, \ - "\t\tExpected alloc sink at %p, got %p.", \ + "\t\t%p != %p", \ _sink, \ sink_sdu_alloc_test_fake.arg0_##_typ); \ zassert_equal_ptr(_pdu, \ sink_sdu_alloc_test_fake.arg1_##_typ, \ - "\t\tExpected alloc PDU buffer at %p, got %p.", \ + "\t\t%p != %p", \ _pdu, \ sink_sdu_alloc_test_fake.arg1_##_typ) #define ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(_expected) \ zassert_equal(_expected, \ sink_sdu_alloc_test_fake.call_count, \ - "Expected alloc called %u times, actual %u.", \ + "Expected %u got %u", \ _expected, \ sink_sdu_alloc_test_fake.call_count) @@ -125,59 +125,59 @@ static isoal_status_t custom_sink_sdu_emit_test(const struct isoal_sink *sink_ct _sdu_status) \ zassert_equal_ptr(_sink, \ sink_sdu_emit_test_fake.arg0_##_typ, \ - "\t\tExpected sink at %p, got %p.", \ + "\t\t%p != %p", \ _sink, \ sink_sdu_emit_test_fake.arg0_##_typ); \ zassert_equal(_state, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_state, \ - "\t\tExpected SDU state '%s', got '%s'.", \ - STATE_TO_STR(_state), \ - STATE_TO_STR(sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_state)); \ + "\t\t%d != %d", \ + _state, \ + sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_state); \ zassert_equal(_frag_sz, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_frag_size, \ - "\t\tExpected SDU frag of size %u, got %u.", \ + "\t\t%d != %d", \ _frag_sz, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu_frag_size); \ zassert_equal(_frag_status, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.status, \ - "\t\tExpected SDU with status '%s', got '%s'.", \ - DU_ERR_TO_STR(_frag_status), \ - DU_ERR_TO_STR(sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.status)); \ + "\t\t%d != %d", \ + _frag_status, \ + sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.status); \ zassert_equal(_timestamp, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.timestamp, \ - "\t\tExpected SDU with timestamp %u, got %u.", \ + "\t\t%d != %d", \ _timestamp, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.timestamp); \ zassert_equal(_sn, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.sn, \ - "\t\tExpected SDU with sequence number %u, got %u.", \ + "\t\t%d != %d", \ _sn, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.sn); \ - zassert_equal_ptr(_dbuf, \ - sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.dbuf, \ - "\t\tExpected SDU data buffer at %p, got %p.", \ - _dbuf, \ - sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.dbuf); \ + zassert_equal(_dbuf, \ + sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.dbuf, \ + "\t\t%p != %p", \ + _dbuf, \ + sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.dbuf); \ zassert_equal(_dbuf_sz, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.size, \ - "\t\tExpected SDU data buffer of size %u, got %u.", \ + "\t\t%d != %d", \ _dbuf_sz, \ sink_sdu_emit_test_handler_fake.arg1_##_typ.sdu.contents.size); \ zassert_equal(_total_sz, \ sink_sdu_emit_test_handler_fake.arg2_##_typ.total_sdu_size, \ - "\t\tExpected total size of SDU %u,got %u.", \ + "\t\t%d != %d", \ _total_sz, \ sink_sdu_emit_test_handler_fake.arg2_##_typ.total_sdu_size); \ zassert_equal(_sdu_status, \ sink_sdu_emit_test_handler_fake.arg2_##_typ.collated_status, \ - "\t\tExpected SDU with status '%s', got '%s'.", \ - DU_ERR_TO_STR(_sdu_status), \ - DU_ERR_TO_STR(sink_sdu_emit_test_handler_fake.arg2_##_typ.collated_status)) + "\t\t%d != %d", \ + _sdu_status, \ + sink_sdu_emit_test_handler_fake.arg2_##_typ.collated_status) #define ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(_expected) \ zassert_equal(_expected, \ sink_sdu_emit_test_fake.call_count, \ - "Expected emit called %u times, actual %u.", \ + "Expected %u got %u", \ _expected, \ sink_sdu_emit_test_fake.call_count) @@ -212,24 +212,24 @@ custom_sink_sdu_write_test(void *dbuf, const uint8_t *pdu_payload, const size_t #define ZASSERT_ISOAL_SDU_WRITE_TEST(_typ, _frag_buf, _payload_buf, _length) \ zassert_equal_ptr(_frag_buf, \ sink_sdu_write_test_fake.arg0_##_typ, \ - "\t\tExpected write buffer at %p, got %p.", \ + "\t\t%p != %p", \ _frag_buf, \ sink_sdu_write_test_fake.arg0_##_typ); \ zassert_equal_ptr(_payload_buf, \ sink_sdu_write_test_fake.arg1_##_typ, \ - "\t\tExpected write source at %p, got %p.", \ + "\t\t%p != %p", \ _payload_buf, \ sink_sdu_write_test_fake.arg1_##_typ); \ zassert_equal(_length, \ sink_sdu_write_test_fake.arg2_##_typ, \ - "\t\tExpected write length of %u, got %u.", \ + "\t\t%d != %d", \ _length, \ sink_sdu_write_test_fake.arg2_##_typ) #define ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(_expected) \ zassert_equal(_expected, \ sink_sdu_write_test_fake.call_count, \ - "Expected write called %u times, actual %u.", \ + "Expected %u got %u", \ _expected, \ sink_sdu_write_test_fake.call_count) @@ -2767,7 +2767,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err) seqn = 0; testdata_indx = 0; testdata_size = 13; - sdu_size = 0; + sdu_size = 13; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); @@ -2804,9 +2804,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err) &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ - /* SDU payload should not be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); - + /* SDU payload should be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST(val, + &rx_sdu_frag_buf, /* SDU buffer */ + &rx_pdu_meta_buf.pdu[3], /* PDU payload */ + (testdata_size - testdata_indx)); /* Size */ /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -2836,6 +2838,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err) sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency); testdata_indx = testdata_size; testdata_size += 10; + sdu_size = 10; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); @@ -2863,9 +2866,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_single_pdu_err) &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ - /* SDU payload should not be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); - + /* SDU payload should be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST(val, + &rx_sdu_frag_buf, /* SDU buffer */ + &rx_pdu_meta_buf.pdu[3], /* PDU payload */ + (testdata_size - testdata_indx)); /* Size */ /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -3234,6 +3239,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err1) payload_number++; testdata_indx = testdata_size; testdata_size += 10; + sdu_size += 10; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); @@ -3257,11 +3263,12 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err1) /* Test recombine (Black Box) */ /* A new SDU should not be allocated */ - ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); - - /* SDU payload should not be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1); + /* SDU payload should be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST(val, + &rx_sdu_frag_buf, /* SDU buffer */ + &rx_pdu_meta_buf.pdu[3], /* PDU payload */ + (testdata_size - testdata_indx)); /* Size */ /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -3528,7 +3535,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err2) payload_number++; testdata_indx = testdata_size; testdata_size += 10; - sdu_size = 0; + sdu_size = 10; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, 50); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); @@ -3558,9 +3565,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_seq_pdu_err2) &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ - /* SDU payload should not be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1); - + /* SDU payload should be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST(val, + &rx_sdu_frag_buf, /* SDU buffer */ + &rx_pdu_meta_buf.pdu[3], /* PDU payload */ + (testdata_size - testdata_indx)); /* Size */ /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -4560,7 +4569,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_error1) seqn = 0; testdata_indx = 0; testdata_size = 13; - sdu_size = 0; + sdu_size = 13; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); @@ -4598,9 +4607,11 @@ ZTEST(test_rx_unframed, test_rx_unframed_padding_error1) &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ - /* SDU payload should not be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); - + /* SDU payload should be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST(val, + &rx_sdu_frag_buf, /* SDU buffer */ + &rx_pdu_meta_buf.pdu[3], /* PDU payload */ + (testdata_size - testdata_indx)); /* Size */ /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ @@ -5924,6 +5935,7 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid2_pdu_err) payload_number++; testdata_indx = testdata_size; testdata_size += 10; + sdu_size += 10; total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_ERRORS, ISOAL_SDU_STATUS_ERRORS); @@ -5946,11 +5958,12 @@ ZTEST(test_rx_unframed, test_rx_unframed_dbl_pdu_invalid_llid2_pdu_err) /* Test recombine (Black Box) */ /* A new SDU should not be allocated */ - ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(1); - - /* SDU payload should not be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1); + /* SDU payload should be written */ + ZASSERT_ISOAL_SDU_WRITE_TEST(val, + &rx_sdu_frag_buf, /* SDU buffer */ + &rx_pdu_meta_buf.pdu[3], /* PDU payload */ + (testdata_size - testdata_indx)); /* Size */ /* SDU should be emitted */ ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ From ef1bb63de84032669397619216bb4538edc4e3e3 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:51 +0000 Subject: [PATCH 0652/1623] Revert "[nrf fromtree] tests: bluetooth: controller: ISO-AL selection of TX time stamps" This reverts commit cd59d4f291540089700dc1c04e7dd82f8de345a5. Signed-off-by: Dominik Ermel --- .../ctrl_isoal/src/isoal_test_debug.c | 1 - tests/bluetooth/ctrl_isoal/src/main.c | 2 +- .../ctrl_isoal/src/sub_sets/isoal_test_tx.c | 540 +----------------- 3 files changed, 3 insertions(+), 540 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c b/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c index 084677cf462..734af1ad7c0 100644 --- a/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c +++ b/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c @@ -233,7 +233,6 @@ void isoal_test_debug_print_tx_sdu(struct isoal_sdu_tx *tx_sdu) PRINT("%02x ", buf[i]); } PRINT("\n"); - PRINT("Cntr TS. <%10u>\n", tx_sdu->cntr_time_stamp); PRINT(" Ref. <%10u>\n", tx_sdu->grp_ref_point); PRINT(" Event <%10u>\n", (uint32_t)tx_sdu->target_event); PRINT("\n"); diff --git a/tests/bluetooth/ctrl_isoal/src/main.c b/tests/bluetooth/ctrl_isoal/src/main.c index 8cbd36c509a..08175eab153 100644 --- a/tests/bluetooth/ctrl_isoal/src/main.c +++ b/tests/bluetooth/ctrl_isoal/src/main.c @@ -37,7 +37,7 @@ DEFINE_FFF_GLOBALS; ZTEST_SUITE(test_rx_basics, NULL, NULL, isoal_test_rx_common_before, NULL, NULL); ZTEST_SUITE(test_rx_unframed, NULL, NULL, isoal_test_rx_common_before, NULL, NULL); -ZTEST_SUITE(test_rx_framed, NULL, NULL, isoal_test_rx_common_before, NULL, NULL); +ZTEST_SUITE(test_rx_framed, NULL, NULL, NULL, isoal_test_rx_common_before, NULL); ZTEST_SUITE(test_tx_basics, NULL, NULL, isoal_test_tx_common_before, NULL, NULL); ZTEST_SUITE(test_tx_unframed, NULL, NULL, isoal_test_tx_common_before, NULL, NULL); diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c index c9a6fe67637..3f57d8bccbc 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c @@ -195,14 +195,14 @@ static isoal_status_t custom_source_pdu_write_test(struct isoal_pdu_buffer *pdu_ _consume_len, \ source_pdu_write_test_fake.arg3_##_typ); \ check_next_custom_source_pdu_write_test_sdu_payload((const uint8_t *)_sdu_payload, \ - _consume_len, __LINE__) + _consume_len, __LINE__); #define ZASSERT_PDU_WRITE_TEST_CALL_COUNT(_expected) \ zassert_equal(_expected, \ source_pdu_write_test_fake.call_count, \ "Expected %u, got %u", \ _expected, \ - source_pdu_write_test_fake.call_count) + source_pdu_write_test_fake.call_count); /*------------------ PDU Emit Callback --------------------------------------*/ /** @@ -480,7 +480,6 @@ static void isoal_test_create_sdu_fagment(uint8_t sdu_state, uint16_t sdu_total_length, uint16_t packet_number, uint32_t timestamp, - uint32_t cntr_timestamp, uint32_t ref_point, uint64_t target_event, struct isoal_sdu_tx *sdu_tx) @@ -489,7 +488,6 @@ static void isoal_test_create_sdu_fagment(uint8_t sdu_state, sdu_tx->packet_sn = packet_number; sdu_tx->iso_sdu_length = sdu_total_length; sdu_tx->time_stamp = timestamp; - sdu_tx->cntr_time_stamp = cntr_timestamp; sdu_tx->grp_ref_point = ref_point; sdu_tx->target_event = target_event; memcpy(sdu_tx->dbuf, dataptr, length); @@ -794,7 +792,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_maxPDU) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -923,7 +920,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_bufSize) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1039,7 +1035,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_3_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1200,7 +1195,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1247,7 +1241,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1291,7 +1284,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1411,7 +1403,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1460,7 +1451,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1527,7 +1517,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1745,7 +1734,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_1_frag_2_pdu_ts_wrap1) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1799,7 +1787,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_1_frag_2_pdu_ts_wrap1) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1929,7 +1916,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -1982,7 +1968,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2045,7 +2030,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2101,7 +2085,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2145,7 +2128,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2208,7 +2190,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2333,7 +2314,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2390,7 +2370,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2453,7 +2432,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2549,7 +2527,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2592,7 +2569,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2655,7 +2631,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2817,7 +2792,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_zero_sdu_1_frag_1_pdu_maxPDU_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -2978,7 +2952,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_alloc_err) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3096,7 +3069,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_emit_err) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3227,7 +3199,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3298,7 +3269,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3365,7 +3335,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3435,7 +3404,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -3483,470 +3451,6 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) zassert_equal(tx_sync_offset, tx_sync_offset_expected, "%u != %u", tx_sync_seq, 0); } -/** - * Test Suite : TX framed SDU segmentation - * - * Tests framed event selection - */ -#define RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT() \ - out_sdus_skipped = isoal_tx_framed_find_correct_tx_event(source, \ - &tx_sdu_frag_buf.sdu_tx, \ - &out_payload_number, \ - &out_ref_point, \ - &out_time_offset); \ - \ - zassert_equal(out_payload_number, expect_payload_number, "%llu != %llu", \ - out_payload_number, expect_payload_number); \ - zassert_equal(out_ref_point, expect_ref_point, "%u != %u", \ - out_ref_point, expect_ref_point); \ - zassert_equal(out_time_offset, expect_time_offset, "%u != %u", \ - out_time_offset, expect_time_offset); \ - zassert_equal(out_sdus_skipped, expect_sdus_skipped, "%u .!= %u", \ - out_sdus_skipped, expect_sdus_skipped) - -ZTEST(test_tx_framed, test_tx_framed_find_correct_tx_event) -{ - const uint8_t number_of_pdus = 1; - const uint8_t testdata_size_max = MAX_FRAMED_PDU_PAYLOAD(number_of_pdus); - - struct tx_sdu_frag_buffer tx_sdu_frag_buf; - struct isoal_source_session *session; - uint8_t testdata[testdata_size_max]; - isoal_sdu_len_t in_sdu_total_size; - isoal_source_handle_t source_hdl; - struct isoal_pdu_production *pp; - uint64_t expect_payload_number; - struct isoal_source *source; - uint64_t out_payload_number; - uint32_t expect_time_offset; - uint8_t expect_sdus_skipped; - uint32_t expected_timestamp; - uint32_t stream_sync_delay; - uint32_t in_cntr_timestamp; - uint32_t group_sync_delay; - uint64_t in_sdu_packet_sn; - uint32_t in_sdu_timestamp; - uint32_t expect_ref_point; - uint64_t in_target_event; - uint32_t iso_interval_us; - uint8_t iso_interval_int; - uint32_t out_time_offset; - uint8_t out_sdus_skipped; - uint16_t testdata_indx; - uint16_t testdata_size; - uint32_t out_ref_point; - uint32_t sdu_interval; - uint32_t in_ref_point; - uint8_t max_octets; - uint8_t role; - uint8_t BN; - uint8_t FT; - - /* Settings */ - role = BT_CONN_ROLE_PERIPHERAL; - iso_interval_int = 1; - iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; - sdu_interval = iso_interval_us + 50; - max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; - BN = 2; - FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; - - init_test_data_buffer(testdata, testdata_size_max); - - /* Create source */ - source_hdl = basic_tx_test_setup(0xADAD, /* Handle */ - role, /* Role */ - true, /* Framed */ - BN, /* BN */ - FT, /* FT */ - max_octets, /* max_octets */ - sdu_interval, /* SDU Interval */ - iso_interval_int, /* ISO Interval */ - stream_sync_delay, /* Stream Sync Delay */ - group_sync_delay); /* Group Sync Delay */ - - source = &isoal_global.source_state[source_hdl]; - session = &source->session; - pp = &source->pdu_production; - - in_sdu_total_size = testdata_size_max; - testdata_indx = 0; - testdata_size = testdata_size_max; - - /* Test : Selection of event for first SDU where - * -- Last SDU packet number is uninitialized - * -- Last SDU time stamp is uninitialized - * -- Payload number is uninitialized - * -- Target event and reference point are one event ahead - * -- Time stamp is valid - * -- Time stamp indicates that target event is feasible - * Expected: - * -- Target event is used for transmission and calculations are based - * on that - * -- Time offset is based on the SDUs time stamp - */ - in_sdu_packet_sn = 2000; - in_target_event = 2000; - in_sdu_timestamp = 9249; - in_cntr_timestamp = in_sdu_timestamp + 200; - in_ref_point = in_sdu_timestamp + iso_interval_us - 50; - - pp->initialized = 0U; - session->tx_time_stamp = 0; - session->tx_time_offset = 0; - session->last_input_sn = 0; - session->last_input_time_stamp = 0; - pp->payload_number = 0; - - expect_sdus_skipped = 0; - expect_payload_number = in_target_event * BN; - expect_ref_point = in_ref_point; - expected_timestamp = in_sdu_timestamp; - expect_time_offset = expect_ref_point - expected_timestamp; - - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - in_sdu_total_size, - in_sdu_packet_sn, - in_sdu_timestamp, - in_cntr_timestamp, - in_ref_point, - in_target_event, - &tx_sdu_frag_buf.sdu_tx); - - RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); - - /* Test : Selection of event for first SDU where - * -- Last SDU packet number is uninitialized - * -- Last SDU time stamp is uninitialized - * -- Payload number ahead of target event - * -- Target event and reference point are one event behind - * current payload - * -- Time stamp is valid - * -- Time stamp indicates that target event is feasible - * Expected: - * -- Target event + 1 is selected based on the payload being ahead and - * calculations are based on that reference - * -- Time offset is based on the SDUs time stamp - */ - in_sdu_packet_sn = 2000; - in_target_event = 2000; - in_sdu_timestamp = 9249; - in_cntr_timestamp = in_sdu_timestamp + 200; - in_ref_point = in_sdu_timestamp + iso_interval_us - 50; - - pp->initialized = 0U; - session->tx_time_stamp = 0; - session->tx_time_offset = 0; - session->last_input_sn = 0; - session->last_input_time_stamp = 0; - pp->payload_number = (in_target_event + 1) * BN; - - expect_sdus_skipped = 0; - expect_payload_number = (in_target_event + 1) * BN; - expect_ref_point = in_ref_point + iso_interval_us; - expected_timestamp = in_sdu_timestamp; - expect_time_offset = expect_ref_point - expected_timestamp; - - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - in_sdu_total_size, - in_sdu_packet_sn, - in_sdu_timestamp, - in_cntr_timestamp, - in_ref_point, - in_target_event, - &tx_sdu_frag_buf.sdu_tx); - - RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); - - /* Test : Selection of event for first SDU where - * -- Last SDU packet number is uninitialized - * -- Last SDU time stamp is uninitialized - * -- Payload number ahead of target event - * -- Target event and reference point are one event behind - * current payload - * -- Time stamp is invalid - * -- Controller time stamp indicates that target event is - * feasible - * Expected: - * -- Target event + 1 is selected based on the payload being ahead and - * calculations are based on that reference - * -- Time offset is based on the controller's capture time - */ - in_sdu_packet_sn = 2000; - in_target_event = 2000; - in_sdu_timestamp = 0; - in_cntr_timestamp = 9249 + 200; - in_ref_point = in_cntr_timestamp + iso_interval_us - 50; - - pp->initialized = 0U; - session->tx_time_stamp = 0; - session->tx_time_offset = 0; - session->last_input_sn = 0; - session->last_input_time_stamp = 0; - pp->payload_number = (in_target_event + 1) * BN; - - expect_sdus_skipped = 0; - expect_payload_number = (in_target_event + 1) * BN; - expect_ref_point = in_ref_point + iso_interval_us; - expected_timestamp = in_cntr_timestamp; - expect_time_offset = expect_ref_point - expected_timestamp; - - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - in_sdu_total_size, - in_sdu_packet_sn, - in_sdu_timestamp, - in_cntr_timestamp, - in_ref_point, - in_target_event, - &tx_sdu_frag_buf.sdu_tx); - - RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); - - /* Test : Selection of event for a subsequent SDU where - * -- Last SDU packet number is in sequence - * -- Last SDU time stamp is in sequence - * -- Payload number is in sequence - * -- Target event and reference point are one event ahead of - * current payload - * -- Time stamp is valid - * -- Time stamp indicates that target event is feasible - * Expected: - * -- Target event is selected based on the time stamp and calculations - * are based on that reference - * -- Time offset is based on the SDUs time stamp - */ - in_sdu_packet_sn = 2000; - in_target_event = 2000; - in_sdu_timestamp = 9249; - in_cntr_timestamp = 9249 + 200; - in_ref_point = in_sdu_timestamp + iso_interval_us - 50; - - pp->initialized = 1U; - session->tx_time_stamp = 0; - session->tx_time_offset = 0; - session->last_input_sn = in_sdu_packet_sn - 1; - session->last_input_time_stamp = in_sdu_timestamp - sdu_interval; - pp->payload_number = (in_target_event - 1) * BN; - - expect_sdus_skipped = 0; - expect_payload_number = in_target_event * BN; - expect_ref_point = in_ref_point; - expected_timestamp = in_sdu_timestamp; - expect_time_offset = expect_ref_point - expected_timestamp; - - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - in_sdu_total_size, - in_sdu_packet_sn, - in_sdu_timestamp, - in_cntr_timestamp, - in_ref_point, - in_target_event, - &tx_sdu_frag_buf.sdu_tx); - - RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); - - /* Test : Selection of event for a subsequent SDU where - * -- Last SDU packet number is not in sequence - * -- Last SDU time stamp is not in sequence - * -- Payload number is not in sequence - * -- Target event and reference point are two events ahead - * -- Time stamp is valid but at the border of the range - * -- Time stamp indicates that target event - 1 is feasible - * Expected: - * -- Target event - 1 is selected based on the time stamp and - * calculations are based on that reference - * -- Time offset is based on the SDUs time stamp - */ - in_sdu_packet_sn = 2000; - in_target_event = 2001; - in_sdu_timestamp = 9249; - in_cntr_timestamp = 9249 + sdu_interval + iso_interval_us; - in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50; - - pp->initialized = 1U; - session->tx_time_stamp = 0; - session->tx_time_offset = 0; - session->last_input_sn = in_sdu_packet_sn - 3; - session->last_input_time_stamp = in_sdu_timestamp - (sdu_interval * 2); - pp->payload_number = (in_target_event - 2) * BN; - - expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1; - expect_payload_number = (in_target_event - 1) * BN; - expect_ref_point = in_ref_point - iso_interval_us; - expected_timestamp = in_sdu_timestamp; - expect_time_offset = expect_ref_point - expected_timestamp; - - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - in_sdu_total_size, - in_sdu_packet_sn, - in_sdu_timestamp, - in_cntr_timestamp, - in_ref_point, - in_target_event, - &tx_sdu_frag_buf.sdu_tx); - - RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); - - /* Test : Selection of event for a subsequent SDU where - * -- Last SDU packet number is not in sequence - * -- Last SDU time stamp is not in sequence - * -- Payload number is not in sequence - * -- Target event and reference point are two events ahead - * -- Time stamp is invalid - * Expected: - * -- Target event is selected based on the time stamp calculated - * from the difference between time stamps and calculations are based - * on that reference - * -- Time offset is based on the SDUs time stamp - */ - in_sdu_packet_sn = 2000; - in_target_event = 2001; - in_sdu_timestamp = 9249; - in_cntr_timestamp = 9249 + sdu_interval + iso_interval_us + 1; - in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50; - - pp->initialized = 1U; - session->tx_time_stamp = in_ref_point - iso_interval_us; - session->tx_time_offset = session->tx_time_stamp - - (in_sdu_timestamp - sdu_interval); - session->last_input_sn = in_sdu_packet_sn - 3; - session->last_input_time_stamp = in_sdu_timestamp - (sdu_interval * 2); - pp->payload_number = (in_target_event - 2) * BN; - - expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1; - expect_payload_number = in_target_event * BN; - expect_ref_point = in_ref_point; - expected_timestamp = session->tx_time_stamp - session->tx_time_offset + - (in_sdu_timestamp - session->last_input_time_stamp); - expect_time_offset = expect_ref_point - expected_timestamp; - - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - in_sdu_total_size, - in_sdu_packet_sn, - in_sdu_timestamp, - in_cntr_timestamp, - in_ref_point, - in_target_event, - &tx_sdu_frag_buf.sdu_tx); - - RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); - - /* Test : Selection of event for a subsequent SDU where - * -- Last SDU packet number is not in sequence - * -- Last SDU time stamp has been projected as part of a - * burst - * -- Payload number is not in sequence - * -- Target event and reference point are two events ahead - * -- Time stamp is invalid - * -- Time stamp delta is invalid - * Expected: - * -- Target event + 1 is selected based on the time stamp calculated - * from the difference in packet sn and calculations are based - * on that reference - * -- Time offset is based on the SDUs time stamp - */ - in_sdu_packet_sn = 2000; - in_target_event = 2001; - in_sdu_timestamp = 9249; - in_cntr_timestamp = 9249 + sdu_interval + iso_interval_us + 1; - in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50; - - pp->initialized = 1U; - session->tx_time_stamp = in_ref_point - iso_interval_us; - session->tx_time_offset = session->tx_time_stamp - - (in_sdu_timestamp + sdu_interval); - session->last_input_sn = in_sdu_packet_sn - 1; - session->last_input_time_stamp = in_sdu_timestamp + (sdu_interval * 2); - pp->payload_number = (in_target_event - 2) * BN; - - expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1; - expect_payload_number = (in_target_event + 1) * BN; - expect_ref_point = in_ref_point + iso_interval_us; - expected_timestamp = session->tx_time_stamp - session->tx_time_offset + sdu_interval; - expect_time_offset = expect_ref_point - expected_timestamp; - - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - in_sdu_total_size, - in_sdu_packet_sn, - in_sdu_timestamp, - in_cntr_timestamp, - in_ref_point, - in_target_event, - &tx_sdu_frag_buf.sdu_tx); - - RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); - - /* Test : Selection of event for a subsequent SDU where - * -- Last SDU packet number is in sequence - * -- Last SDU time stamp has been projected as part of a - * burst - * -- Payload number is ahead of selected event - * -- Target event and reference point are two events ahead - * -- Time stamp is valid - * -- Time stamp indicates that target event - 1 is feasible - * Expected: - * -- Target event -1 is selected based on the time stamp and - * calculations are based on that reference - * -- Payload number continues from last - * -- Time offset is based on the SDUs time stamp - */ - in_sdu_packet_sn = 2000; - in_target_event = 2001; - in_sdu_timestamp = 9249; - in_cntr_timestamp = 9249; - in_ref_point = in_sdu_timestamp + (iso_interval_us * 2) - 50; - - pp->initialized = 1U; - session->tx_time_stamp = 0; - session->tx_time_offset = 0; - session->last_input_sn = in_sdu_packet_sn - 1; - session->last_input_time_stamp = in_sdu_timestamp - sdu_interval; - pp->payload_number = ((in_target_event - 1) * BN) + 1; - - expect_sdus_skipped = in_sdu_packet_sn - session->last_input_sn - 1; - expect_payload_number = pp->payload_number; - expect_ref_point = in_ref_point - iso_interval_us; - expected_timestamp = in_sdu_timestamp; - expect_time_offset = expect_ref_point - expected_timestamp; - - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - in_sdu_total_size, - in_sdu_packet_sn, - in_sdu_timestamp, - in_cntr_timestamp, - in_ref_point, - in_target_event, - &tx_sdu_frag_buf.sdu_tx); - - RUN_TX_FRAMED_FIND_CORRECT_TX_EVENT(); -} - /** * Test Suite : TX framed SDU segmentation * @@ -4033,7 +3537,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_maxPDU) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4189,7 +3692,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_bufSize) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4334,7 +3836,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4572,7 +4073,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4644,7 +4144,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4699,7 +4198,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_1_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4837,7 +4335,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -4911,7 +4408,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5004,7 +4500,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_2_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5142,7 +4637,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5218,7 +4712,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5311,7 +4804,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5378,7 +4870,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5445,7 +4936,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5537,7 +5027,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5675,7 +5164,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5748,7 +5236,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5840,7 +5327,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5904,7 +5390,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -5966,7 +5451,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6057,7 +5541,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6228,7 +5711,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6309,7 +5791,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6459,7 +5940,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_refPoint3) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6616,7 +6096,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_ts_wrap1) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6697,7 +6176,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_ts_wrap1) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6838,7 +6316,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_maxPDU) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -6990,7 +6467,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7171,7 +6647,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_alloc_err) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7300,7 +6775,6 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_emit_err) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7447,7 +6921,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7524,7 +6997,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7599,7 +7071,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7763,7 +7234,6 @@ ZTEST(test_tx_framed, test_tx_framed_event_utilization_1) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7839,7 +7309,6 @@ ZTEST(test_tx_framed, test_tx_framed_event_utilization_1) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -7949,7 +7418,6 @@ ZTEST(test_tx_framed, test_tx_framed_event_utilization_1) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -8042,7 +7510,6 @@ ZTEST(test_tx_framed, test_tx_framed_event_utilization_1) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -8229,7 +7696,6 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -8301,7 +7767,6 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); @@ -8382,7 +7847,6 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) sdu_total_size, sdu_packet_number, sdu_timestamp, - sdu_timestamp, ref_point, event_number, &tx_sdu_frag_buf.sdu_tx); From ec869c65367bd72f0d386beb1c57f8d7bc59d6e4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:52 +0000 Subject: [PATCH 0653/1623] Revert "[nrf fromtree] test: bluetooth: controller: Updated ISO-AL tests to cover endianness" This reverts commit 78f271634db1df8383b6e32e46e750c428e264fc. Signed-off-by: Dominik Ermel --- .../ctrl_isoal/src/isoal_test_common.c | 12 +++-- .../ctrl_isoal/src/isoal_test_debug.c | 44 +------------------ tests/bluetooth/ctrl_isoal/src/main.c | 2 - .../ctrl_isoal/src/sub_sets/isoal_test_tx.c | 36 +++++++-------- 4 files changed, 24 insertions(+), 70 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/src/isoal_test_common.c b/tests/bluetooth/ctrl_isoal/src/isoal_test_common.c index 35947656336..a20ba5fd084 100644 --- a/tests/bluetooth/ctrl_isoal/src/isoal_test_common.c +++ b/tests/bluetooth/ctrl_isoal/src/isoal_test_common.c @@ -23,7 +23,6 @@ #include #include -#include #include "util/memq.h" @@ -110,7 +109,7 @@ void isoal_test_create_unframed_pdu(uint8_t llid, uint16_t isoal_test_insert_segment(bool sc, bool cmplt, uint32_t time_offset, uint8_t *dataptr, uint8_t length, struct isoal_pdu_rx *pdu_meta) { - uint8_t seg_hdr[PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE]; + struct pdu_iso_sdu_sh seg_hdr; uint16_t pdu_payload_size; uint8_t hdr_write_size; uint16_t pdu_data_loc; @@ -123,13 +122,12 @@ uint16_t isoal_test_insert_segment(bool sc, bool cmplt, uint32_t time_offset, ui zassert_true(pdu_payload_size <= TEST_RX_PDU_PAYLOAD_MAX, "pdu_payload_size (%d)", pdu_payload_size); - /* Write header independent of endian dependent structures */ - WRITE_BIT(seg_hdr[0], 0, sc); /* sc */ - WRITE_BIT(seg_hdr[0], 1, cmplt); /* cmplt */ - seg_hdr[1] = length + (sc ? 0 : PDU_ISO_SEG_TIMEOFFSET_SIZE); + seg_hdr.sc = sc; + seg_hdr.cmplt = cmplt; + seg_hdr.len = length + (sc ? 0 : PDU_ISO_SEG_TIMEOFFSET_SIZE); if (!sc) { - sys_put_le24(time_offset, &seg_hdr[PDU_ISO_SEG_HDR_SIZE]); + seg_hdr.timeoffset = time_offset; } memcpy(&pdu_meta->pdu->payload[pdu_meta->pdu->len], &seg_hdr, hdr_write_size); diff --git a/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c b/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c index 734af1ad7c0..464d2586598 100644 --- a/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c +++ b/tests/bluetooth/ctrl_isoal/src/isoal_test_debug.c @@ -52,12 +52,6 @@ void isoal_test_debug_print_rx_pdu(struct isoal_pdu_rx *pdu_meta) { zassert_not_null(pdu_meta, ""); - struct pdu_iso *pdu; - uint8_t seg_length; - - pdu = pdu_meta->pdu; - seg_length = 0; - PRINT("\n"); PRINT("PDU %04u (%10u) | %12s [%10s] %03u: ", (uint32_t) pdu_meta->meta->payload_number, @@ -66,42 +60,8 @@ void isoal_test_debug_print_rx_pdu(struct isoal_pdu_rx *pdu_meta) DU_ERR_TO_STR(pdu_meta->meta->status), pdu_meta->pdu->len); - for (uint8_t i = 0U; i < pdu->len; i++) { - if (seg_length == 0U && pdu->ll_id == PDU_BIS_LLID_FRAMED) { - seg_length = pdu->payload[i + 1U]; - PRINT("[%s %s %03u]", - pdu->payload[i] & BIT(0) ? "C" : "S", - pdu->payload[i] & BIT(1) ? "C" : "-", - pdu->payload[i + 1U]); - if ((pdu->payload[i] & BIT(0)) == 0U) { - PRINT("(%8uus)", - ((uint32_t)pdu->payload[i + 2U] + - ((uint32_t)pdu->payload[i + 3U] << 8) + - ((uint32_t)pdu->payload[i + 4U] << 16))); - } - - PRINT(" / "); - PRINT("[%02x %02x]", - pdu->payload[i], - pdu->payload[i + 1U]); - if ((pdu->payload[i] & BIT(0)) == 0U) { - PRINT("(%02x %02x %02x)", - (uint32_t)pdu->payload[i + 4U], - (uint32_t)pdu->payload[i + 3U], - (uint32_t)pdu->payload[i + 2U]); - } - - PRINT(" : "); - seg_length -= pdu->payload[i] & BIT(0) ? 0 : PDU_ISO_SEG_TIMEOFFSET_SIZE; - i += PDU_ISO_SEG_HDR_SIZE + - (pdu->payload[i] & BIT(0) ? 0 : PDU_ISO_SEG_TIMEOFFSET_SIZE); - } - - PRINT("%02x ", pdu->payload[i]); - seg_length--; - if (seg_length == 0 && pdu->ll_id == PDU_BIS_LLID_FRAMED) { - PRINT("\n%44s", ""); - } + for (int i = 0; i < pdu_meta->pdu->len; i++) { + PRINT("%02x ", pdu_meta->pdu->payload[i]); } PRINT("\n"); PRINT("\n"); diff --git a/tests/bluetooth/ctrl_isoal/src/main.c b/tests/bluetooth/ctrl_isoal/src/main.c index 08175eab153..92ca21ff199 100644 --- a/tests/bluetooth/ctrl_isoal/src/main.c +++ b/tests/bluetooth/ctrl_isoal/src/main.c @@ -18,8 +18,6 @@ #include #include -#include - #include DEFINE_FFF_GLOBALS; diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c index 3f57d8bccbc..dc21c9b5d61 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c @@ -3757,8 +3757,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_bufSize) * Test Suite : TX framed SDU segmentation * * Tests segmentation of a single SDU contained in a single fragment - * into three PDUs where Max PDU is less than the PDU buffer size. Also tests - * endianness of the segment header. + * into three PDUs where Max PDU is less than the PDU buffer size */ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) { @@ -3855,11 +3854,10 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) /* Test segmentation (Black Box) */ /* Valid PDUs */ /* PDU 1 */ - /* Test endianness */ - WRITE_BIT(((uint8_t *)&seg_hdr[0])[0], 0, 0); /* sc */ - WRITE_BIT(((uint8_t *)&seg_hdr[0])[0], 1, 0); /* cmplt */ - sys_put_le24(ref_point - sdu_timestamp, (uint8_t *)(&seg_hdr[0]) + PDU_ISO_SEG_HDR_SIZE); - ((uint8_t *)(&seg_hdr[0]))[1] = PDU_ISO_SEG_TIMEOFFSET_SIZE; /* len */ + seg_hdr[0].sc = 0; + seg_hdr[0].cmplt = 0; + seg_hdr[0].timeoffset = ref_point - sdu_timestamp; + seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE; pdu_hdr_loc = 0; pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE; sdu_read_loc = 0; @@ -3879,7 +3877,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) (pdu_write_size - pdu_write_loc)); seg_hdr[1] = seg_hdr[0]; - ((uint8_t *)(&seg_hdr[1]))[1] += (pdu_write_size - pdu_write_loc); + seg_hdr[1].len += (pdu_write_size - pdu_write_loc); ZASSERT_PDU_WRITE_TEST(history[2], pdu_buffer, @@ -3897,10 +3895,10 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) /* PDU 2 */ payload_number++; - WRITE_BIT(((uint8_t *)&seg_hdr[2])[0], 0, 1); /* sc */ - WRITE_BIT(((uint8_t *)&seg_hdr[2])[0], 1, 0); /* cmplt */ - sys_put_le24(0, (uint8_t *)(&seg_hdr[2]) + PDU_ISO_SEG_HDR_SIZE); - ((uint8_t *)(&seg_hdr[2]))[1] = 0; /* len */ + seg_hdr[2].sc = 1; + seg_hdr[2].cmplt = 0; + seg_hdr[2].timeoffset = 0; + seg_hdr[2].len = 0; pdu_hdr_loc = 0; sdu_read_loc += (pdu_write_size - pdu_write_loc); pdu_write_loc = PDU_ISO_SEG_HDR_SIZE; @@ -3920,7 +3918,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) (pdu_write_size - pdu_write_loc)); seg_hdr[3] = seg_hdr[2]; - ((uint8_t *)(&seg_hdr[3]))[1] += (pdu_write_size - pdu_write_loc); /* len */ + seg_hdr[3].len += (pdu_write_size - pdu_write_loc); ZASSERT_PDU_WRITE_TEST(history[5], pdu_buffer, @@ -3938,10 +3936,10 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) /* PDU 3 */ payload_number++; - WRITE_BIT(((uint8_t *)&seg_hdr[4])[0], 0, 1); /* sc */ - WRITE_BIT(((uint8_t *)&seg_hdr[4])[0], 1, 0); /* cmplt */ - sys_put_le24(0, (uint8_t *)(&seg_hdr[4]) + PDU_ISO_SEG_HDR_SIZE); - ((uint8_t *)(&seg_hdr[4]))[1] = 0; /* len */ + seg_hdr[4].sc = 1; + seg_hdr[4].cmplt = 0; + seg_hdr[4].timeoffset = 0; + seg_hdr[4].len = 0; pdu_hdr_loc = 0; sdu_read_loc += (pdu_write_size - pdu_write_loc); pdu_write_loc = PDU_ISO_SEG_HDR_SIZE; @@ -3964,8 +3962,8 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) (pdu_write_size - pdu_write_loc)); seg_hdr[5] = seg_hdr[4]; - WRITE_BIT(((uint8_t *)&seg_hdr[5])[0], 1, 1); /* cmplt */ - ((uint8_t *)(&seg_hdr[5]))[1] += (pdu_write_size - pdu_write_loc); /* len */ + seg_hdr[5].cmplt = 1; + seg_hdr[5].len += (pdu_write_size - pdu_write_loc); ZASSERT_PDU_WRITE_TEST(history[8], pdu_buffer, From d598726261ba1278e397565901804acac8082890 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:52 +0000 Subject: [PATCH 0654/1623] Revert "[nrf fromtree] tests: bluetooth: controller: Test for framed TX in consecutive events" This reverts commit 9530f3bfb97b911974d607a58bd00cdab7887fa3. Signed-off-by: Dominik Ermel --- .../ctrl_isoal/src/sub_sets/isoal_test_rx.c | 109 ++- .../ctrl_isoal/src/sub_sets/isoal_test_tx.c | 754 ++++-------------- 2 files changed, 181 insertions(+), 682 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c index 5a3c60e0854..2ce8862e1d4 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c @@ -8332,30 +8332,27 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1) */ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) { - const uint8_t test_data_size = 33; - const uint8_t max_sdu_burst = 2; - - struct rx_sdu_frag_buffer rx_sdu_frag_buf[max_sdu_burst]; - struct isoal_sdu_buffer sdu_buffer[max_sdu_burst]; - isoal_sdu_status_t collated_status[max_sdu_burst]; struct rx_pdu_meta_buffer rx_pdu_meta_buf; - isoal_sdu_len_t sdu_size[max_sdu_burst]; - uint16_t total_sdu_size[max_sdu_burst]; - uint32_t sdu_timestamp[max_sdu_burst]; - uint8_t testdata[test_data_size]; + struct rx_sdu_frag_buffer rx_sdu_frag_buf; + struct isoal_sdu_buffer sdu_buffer; + isoal_sdu_status_t collated_status; isoal_sink_handle_t sink_hdl; uint32_t stream_sync_delay; uint32_t group_sync_delay; + isoal_sdu_len_t sdu_size; uint8_t iso_interval_int; uint16_t pdu_data_loc[5]; uint32_t iso_interval_us; uint64_t payload_number; + uint16_t total_sdu_size; uint32_t sdu_timeoffset; uint32_t pdu_timestamp; + uint32_t sdu_timestamp; uint16_t testdata_indx; uint16_t testdata_size; uint32_t sdu_interval; isoal_sdu_cnt_t seqn; + uint8_t testdata[33]; isoal_status_t err; uint32_t latency; uint8_t role; @@ -8374,14 +8371,12 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) /* PDU 1 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); - isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[0]); - init_test_data_buffer(testdata, test_data_size); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); + init_test_data_buffer(testdata, 33); memset(pdu_data_loc, 0, sizeof(pdu_data_loc)); - sdu_buffer[0].dbuf = &rx_sdu_frag_buf[0]; - sdu_buffer[0].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; - sdu_buffer[1].dbuf = &rx_sdu_frag_buf[1]; - sdu_buffer[1].size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; + sdu_buffer.dbuf = &rx_sdu_frag_buf; + sdu_buffer.size = TEST_RX_SDU_FRAG_PAYLOAD_MAX; payload_number = 1000 * BN; pdu_timestamp = 9249; latency = calc_rx_latency_by_role(role, @@ -8393,13 +8388,13 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) group_sync_delay); sdu_timeoffset = group_sync_delay - 50; /* PDU will have errors. Time stamp is only an approximation */ - sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us); + sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - iso_interval_us); seqn = 0; testdata_indx = 0; testdata_size = 23; - sdu_size[0] = 0; - total_sdu_size[0] = COLLATED_RX_SDU_INFO(sdu_size[0], sdu_size[0]); - collated_status[0] = + sdu_size = 0; + total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); + collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_LOST_DATA, ISOAL_SDU_STATUS_LOST_DATA); sink_hdl = basic_rx_test_setup(0xADAD, /* Handle */ @@ -8423,7 +8418,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ - push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[0]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; @@ -8433,14 +8428,25 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); /* Test recombine (Black Box) */ - /* A new SDU should not be allocated */ - ZASSERT_ISOAL_SDU_ALLOC_TEST_CALL_COUNT(0); + /* A new SDU should be allocated */ + ZASSERT_ISOAL_SDU_ALLOC_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + &rx_pdu_meta_buf.pdu_meta); /* PDU */ /* SDU payload should not be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(0); - /* SDU should not be emitted */ - ZASSERT_ISOAL_SDU_EMIT_TEST_CALL_COUNT(0); + /* SDU should be emitted */ + ZASSERT_ISOAL_SDU_EMIT_TEST(val, + &isoal_global.sink_state[sink_hdl], /* Sink */ + BT_ISO_SINGLE, /* Frag state */ + sdu_size, /* Frag size */ + ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ + sdu_timestamp, /* Timestamp */ + seqn, /* Seq. number */ + sdu_buffer.dbuf, /* Buffer */ + sdu_buffer.size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, @@ -8451,17 +8457,18 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) /* PDU 2 -------------------------------------------------------------*/ isoal_test_init_rx_pdu_buffer(&rx_pdu_meta_buf); - isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf[1]); + isoal_test_init_rx_sdu_buffer(&rx_sdu_frag_buf); payload_number++; sdu_timeoffset = get_next_time_offset(sdu_timeoffset, iso_interval_us, sdu_interval, false); - sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); + sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); + seqn++; testdata_indx = testdata_size; testdata_size += 10; - sdu_size[1] = 10; - total_sdu_size[1] = COLLATED_RX_SDU_INFO(sdu_size[1], sdu_size[1]); - collated_status[1] = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); + sdu_size = 10; + total_sdu_size = COLLATED_RX_SDU_INFO(sdu_size, sdu_size); + collated_status = COLLATED_RX_SDU_INFO(ISOAL_SDU_STATUS_VALID, ISOAL_SDU_STATUS_VALID); isoal_test_create_framed_pdu_base(payload_number, pdu_timestamp, @@ -8473,7 +8480,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) &rx_pdu_meta_buf.pdu_meta); /* Set callback function return values */ - push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer[1]); + push_custom_sink_sdu_alloc_test_output_buffer(&sdu_buffer); sink_sdu_alloc_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_write_test_fake.return_val = ISOAL_STATUS_OK; sink_sdu_emit_test_fake.return_val = ISOAL_STATUS_OK; @@ -8483,38 +8490,14 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); /* Test recombine (Black Box) */ - /* SDU 0 -------------------------------------------------------------*/ - /* A new SDU should be allocated */ - ZASSERT_ISOAL_SDU_ALLOC_TEST(history[0], - &isoal_global.sink_state[sink_hdl], /* Sink */ - &rx_pdu_meta_buf.pdu_meta); /* PDU */ - - /* SDU payload should not be written */ - - /* SDU should be emitted */ - ZASSERT_ISOAL_SDU_EMIT_TEST(history[0], - &isoal_global.sink_state[sink_hdl], /* Sink */ - BT_ISO_SINGLE, /* Frag state */ - sdu_size[0], /* Frag size */ - ISOAL_SDU_STATUS_LOST_DATA, /* Frag status */ - sdu_timestamp[0], /* Timestamp */ - seqn, /* Seq. number */ - sdu_buffer[0].dbuf, /* Buffer */ - sdu_buffer[0].size, /* Buffer size */ - total_sdu_size[0], /* Total size */ - collated_status[0]); /* SDU status */ - - /* SDU 1 -------------------------------------------------------------*/ - seqn++; /* A new SDU should be allocated */ ZASSERT_ISOAL_SDU_ALLOC_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ &rx_pdu_meta_buf.pdu_meta); /* PDU */ /* SDU payload should be written */ - ZASSERT_ISOAL_SDU_WRITE_TEST_CALL_COUNT(1); ZASSERT_ISOAL_SDU_WRITE_TEST(val, - &rx_sdu_frag_buf[1], /* SDU buffer */ + &rx_sdu_frag_buf, /* SDU buffer */ &rx_pdu_meta_buf.pdu[3 + pdu_data_loc[1]], /* PDU payload */ (testdata_size - testdata_indx)); /* Size */ @@ -8523,14 +8506,14 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) ZASSERT_ISOAL_SDU_EMIT_TEST(val, &isoal_global.sink_state[sink_hdl], /* Sink */ BT_ISO_SINGLE, /* Frag state */ - sdu_size[1], /* Frag size */ + sdu_size, /* Frag size */ ISOAL_SDU_STATUS_VALID, /* Frag status */ - sdu_timestamp[1], /* Timestamp */ + sdu_timestamp, /* Timestamp */ seqn, /* Seq. number */ - sdu_buffer[1].dbuf, /* Buffer */ - sdu_buffer[1].size, /* Buffer size */ - total_sdu_size[1], /* Total size */ - collated_status[1]); /* SDU status */ + sdu_buffer.dbuf, /* Buffer */ + sdu_buffer.size, /* Buffer size */ + total_sdu_size, /* Total size */ + collated_status); /* SDU status */ /* Test recombine (White Box) */ zassert_equal(isoal_global.sink_state[sink_hdl].sdu_production.fsm, diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c index dc21c9b5d61..fe375b7accd 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c @@ -111,8 +111,7 @@ static void push_custom_source_pdu_write_test_sdu_payload(const uint8_t *data, c } static void check_next_custom_source_pdu_write_test_sdu_payload(const uint8_t *data, - const size_t length, - const uint32_t line) + const size_t length) { size_t pos = custom_source_pdu_write_test_sdu_payloads.pos; size_t buffer_size = custom_source_pdu_write_test_sdu_payloads.buffer_size; @@ -126,8 +125,7 @@ static void check_next_custom_source_pdu_write_test_sdu_payload(const uint8_t *d for (size_t i = 0; i < custom_source_pdu_write_test_sdu_payloads.out_size[pos]; i++) { zassert_equal(custom_source_pdu_write_test_sdu_payloads.out[pos][i], data[i], - "[Line %lu] deviation at index %u, expected %u, got %u", - line, + "deviation at index %u, expected %u, got %u", i, data[i], custom_source_pdu_write_test_sdu_payloads.out[pos][i]); @@ -195,7 +193,7 @@ static isoal_status_t custom_source_pdu_write_test(struct isoal_pdu_buffer *pdu_ _consume_len, \ source_pdu_write_test_fake.arg3_##_typ); \ check_next_custom_source_pdu_write_test_sdu_payload((const uint8_t *)_sdu_payload, \ - _consume_len, __LINE__); + _consume_len); #define ZASSERT_PDU_WRITE_TEST_CALL_COUNT(_expected) \ zassert_equal(_expected, \ @@ -424,7 +422,7 @@ static isoal_source_handle_t basic_tx_test_setup(uint16_t handle, burst_number, flush_timeout, max_octets, - (iso_interval_int * ISO_INT_UNIT_US), + (iso_interval_int * CONN_INT_UNIT_US), sdu_interval, stream_sync_delay, group_sync_delay); @@ -538,8 +536,8 @@ ZTEST(test_tx_basics, test_source_isoal_test_create_destroy) max_octets = 40; sdu_interval_int = 1; iso_interval_int = 1; - iso_interval = iso_interval_int * ISO_INT_UNIT_US; - sdu_interval = sdu_interval_int * ISO_INT_UNIT_US; + iso_interval = iso_interval_int * CONN_INT_UNIT_US; + sdu_interval = sdu_interval_int * CONN_INT_UNIT_US; stream_sync_delay = iso_interval - 200; group_sync_delay = iso_interval - 50; @@ -608,8 +606,8 @@ ZTEST(test_tx_basics, test_source_isoal_test_create_destroy) max_octets += max_octets / 2; sdu_interval_int++; iso_interval_int = iso_interval_int * sdu_interval_int; - sdu_interval = (sdu_interval_int * ISO_INT_UNIT_US) - (framed ? 100 : 0); - iso_interval = iso_interval_int * ISO_INT_UNIT_US; + sdu_interval = (sdu_interval_int * CONN_INT_UNIT_US) - (framed ? 100 : 0); + iso_interval = iso_interval_int * CONN_INT_UNIT_US; stream_sync_delay = iso_interval - (200 * i); group_sync_delay = iso_interval - 50; } @@ -656,9 +654,9 @@ ZTEST(test_tx_basics, test_source_isoal_test_create_err) flush_timeout = 1; framed = false; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US; - stream_sync_delay = ISO_INT_UNIT_US - 200; - group_sync_delay = ISO_INT_UNIT_US - 50; + sdu_interval = CONN_INT_UNIT_US; + stream_sync_delay = CONN_INT_UNIT_US - 200; + group_sync_delay = CONN_INT_UNIT_US - 50; res = isoal_init(); zassert_equal(res, ISOAL_STATUS_OK, "res = 0x%02x", res); @@ -749,12 +747,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_maxPDU) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US; + sdu_interval = CONN_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -766,7 +764,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_maxPDU) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5; testdata_indx = 0; testdata_size = TEST_TX_PDU_PAYLOAD_MAX - 5; @@ -877,12 +875,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_bufSize) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US; + sdu_interval = CONN_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -894,7 +892,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_1_pdu_bufSize) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX; testdata_indx = 0; testdata_size = TEST_TX_PDU_PAYLOAD_MAX; @@ -995,12 +993,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_3_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US; + sdu_interval = CONN_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -1012,7 +1010,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_3_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = 100; testdata_indx = 0; testdata_size = 100; @@ -1154,12 +1152,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_1_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US; + sdu_interval = CONN_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -1171,7 +1169,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_1_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX; testdata_indx = 0; testdata_size = TEST_TX_PDU_PAYLOAD_MAX / 3; @@ -1359,12 +1357,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_2_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US; + sdu_interval = CONN_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 2; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -1380,7 +1378,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_3_frag_2_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX * 2; testdata_indx = 0; testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3; @@ -1691,12 +1689,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_1_frag_2_pdu_ts_wrap1) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US; + sdu_interval = CONN_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -1823,7 +1821,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_1_frag_2_pdu_ts_wrap1) /* Check TX Sync info */ tx_sync_seq_expected = 2; - tx_sync_timestamp_expected = (iso_interval_int * ISO_INT_UNIT_US) - 1; + tx_sync_timestamp_expected = (iso_interval_int * CONN_INT_UNIT_US) - 1; tx_sync_offset_expected = 0; err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset); @@ -1872,12 +1870,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 2; - sdu_interval = ISO_INT_UNIT_US; + sdu_interval = CONN_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 4; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -1893,7 +1891,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX * 2; testdata_indx = 0; testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3; @@ -2266,12 +2264,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 2; - sdu_interval = ISO_INT_UNIT_US; + sdu_interval = CONN_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 8; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -2291,7 +2289,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_2_sdu_3_frag_4_pdu_padding) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX * 2; testdata_indx = 0; testdata_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) / 3; @@ -2741,12 +2739,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_zero_sdu_1_frag_1_pdu_maxPDU_padding) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US; + sdu_interval = CONN_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -2766,7 +2764,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_zero_sdu_1_frag_1_pdu_maxPDU_padding) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = 0; testdata_indx = 0; testdata_size = 0; @@ -2909,12 +2907,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_alloc_err) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US; + sdu_interval = CONN_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -2926,7 +2924,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_alloc_err) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5; testdata_indx = 0; testdata_size = TEST_TX_PDU_PAYLOAD_MAX - 5; @@ -3026,12 +3024,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_emit_err) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US; + sdu_interval = CONN_INT_UNIT_US; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -3043,7 +3041,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_1_sdu_1_frag_pdu_emit_err) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5; testdata_indx = 0; testdata_size = TEST_TX_PDU_PAYLOAD_MAX - 5; @@ -3155,12 +3153,12 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US / 2; + sdu_interval = CONN_INT_UNIT_US / 2; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 2; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ /* Sets initial fragmentation status */ @@ -3173,7 +3171,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) event_number = 2000; sdu_packet_number = (event_number * BN); sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = 23; testdata_indx = 0; testdata_size = 23; @@ -3255,9 +3253,9 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); sdu_packet_number += 29; - sdu_timestamp += ((iso_interval_int * ISO_INT_UNIT_US) * 15) - sdu_interval; + sdu_timestamp += ((iso_interval_int * CONN_INT_UNIT_US) * 15) - sdu_interval; event_number += 15; - ref_point += (iso_interval_int * ISO_INT_UNIT_US) * 15; + ref_point += (iso_interval_int * CONN_INT_UNIT_US) * 15; sdu_total_size = 10; testdata_indx = testdata_size; testdata_size += 10; @@ -3305,7 +3303,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) /* Check TX Sync info */ tx_sync_seq_expected += 29; - tx_sync_timestamp_expected = ref_point - (iso_interval_int * ISO_INT_UNIT_US); + tx_sync_timestamp_expected = ref_point - (iso_interval_int * CONN_INT_UNIT_US); tx_sync_offset_expected = 0; err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset); @@ -3321,9 +3319,9 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); /* Same SDU packet sequence number for testing */ /* Time stamp just before the exact multiple of the SDU interval */ - sdu_timestamp += ((iso_interval_int * ISO_INT_UNIT_US) * 15) - 1; + sdu_timestamp += ((iso_interval_int * CONN_INT_UNIT_US) * 15) - 1; event_number += 15; - ref_point += (iso_interval_int * ISO_INT_UNIT_US) * 15; + ref_point += (iso_interval_int * CONN_INT_UNIT_US) * 15; sdu_total_size = 10; testdata_indx = testdata_size; testdata_size += 10; @@ -3371,7 +3369,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) /* Check TX Sync info */ tx_sync_seq_expected += 30; - tx_sync_timestamp_expected = ref_point - (iso_interval_int * ISO_INT_UNIT_US); + tx_sync_timestamp_expected = ref_point - (iso_interval_int * CONN_INT_UNIT_US); tx_sync_offset_expected = 0; err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset); @@ -3390,9 +3388,9 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) * +1 (reset to exact multiple of SDU interval from the last SDU) * +1 (push the time stamp 1us beyond the multiple mark) */ - sdu_timestamp += ((iso_interval_int * ISO_INT_UNIT_US) * 15) + 1 + 1; + sdu_timestamp += ((iso_interval_int * CONN_INT_UNIT_US) * 15) + 1 + 1; event_number += 15; - ref_point += (iso_interval_int * ISO_INT_UNIT_US) * 15; + ref_point += (iso_interval_int * CONN_INT_UNIT_US) * 15; sdu_total_size = 10; testdata_indx = testdata_size; testdata_size += 10; @@ -3440,7 +3438,7 @@ ZTEST(test_tx_unframed, test_tx_unframed_4_sdu_1_frag_4_pdu_stream_loc) /* Check TX Sync info */ tx_sync_seq_expected += 30; - tx_sync_timestamp_expected = ref_point - (iso_interval_int * ISO_INT_UNIT_US); + tx_sync_timestamp_expected = ref_point - (iso_interval_int * CONN_INT_UNIT_US); tx_sync_offset_expected = 0; err = isoal_tx_get_sync_info(source_hdl, &tx_sync_seq, &tx_sync_timestamp, &tx_sync_offset); @@ -3492,12 +3490,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_maxPDU) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -3512,7 +3510,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_maxPDU) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -3647,12 +3645,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_bufSize) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -3667,7 +3665,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_bufSize) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -3793,12 +3791,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -3812,7 +3810,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_3_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = 100 - ((3 * PDU_ISO_SEG_HDR_SIZE) + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; testdata_size = 100 - ((3 * PDU_ISO_SEG_HDR_SIZE) + PDU_ISO_SEG_TIMEOFFSET_SIZE); @@ -4024,12 +4022,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_1_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -4044,7 +4042,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_1_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -4283,12 +4281,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_2_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 2; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -4307,7 +4305,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_3_frag_2_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) - ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -4585,12 +4583,12 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 2; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 4; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -4609,7 +4607,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = 9249 + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) - ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -4853,7 +4851,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) sdu_packet_number++; event_number = 2000; sdu_timestamp = 9249 + sdu_interval; - ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = 9249 + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = (TEST_TX_PDU_PAYLOAD_MAX * 2) - ((PDU_ISO_SEG_HDR_SIZE * 2) + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -5117,12 +5115,12 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 2; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 6; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -5139,7 +5137,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = 9249 + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = testdata_size_max; testdata_indx = 0; testdata_size = testdata_size_max / number_of_sdu_frags; @@ -5376,7 +5374,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) sdu_packet_number++; event_number = 2000; sdu_timestamp = 9249 + sdu_interval; - ref_point = 9249 + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = 9249 + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = testdata_size_max; testdata_indx = 0; testdata_size = testdata_size_max / number_of_sdu_frags; @@ -5663,12 +5661,12 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -5684,7 +5682,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -5802,7 +5800,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_refPoint2) /* PDU 2 */ /* Advance the target event and the reference point to what it should be */ event_number++; - ref_point += iso_interval_int * ISO_INT_UNIT_US; + ref_point += iso_interval_int * CONN_INT_UNIT_US; payload_number++; seg_hdr[0].sc = 0; seg_hdr[0].cmplt = 0; @@ -5892,12 +5890,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_refPoint3) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -5957,7 +5955,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_1_pdu_refPoint3) /* PDU 1 */ /* Advance the target event and the reference point to what it should be */ event_number++; - ref_point += iso_interval_int * ISO_INT_UNIT_US; + ref_point += iso_interval_int * CONN_INT_UNIT_US; payload_number = event_number * BN; seg_hdr[0].sc = 0; seg_hdr[0].cmplt = 0; @@ -6048,12 +6046,12 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_ts_wrap1) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -6187,7 +6185,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_2_pdu_ts_wrap1) /* PDU 2 */ /* Advance the target event and the reference point to what it should be */ event_number++; - ref_point += iso_interval_int * ISO_INT_UNIT_US; + ref_point += iso_interval_int * CONN_INT_UNIT_US; payload_number++; seg_hdr[0].sc = 0; seg_hdr[0].cmplt = 0; @@ -6272,12 +6270,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_maxPDU) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -6290,7 +6288,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_maxPDU) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -6415,12 +6413,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 3; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); @@ -6441,7 +6439,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -6600,12 +6598,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_alloc_err) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -6620,7 +6618,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_alloc_err) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -6728,12 +6726,12 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_emit_err) /* Settings */ role = ISOAL_ROLE_PERIPHERAL; iso_interval_int = 1; - sdu_interval = ISO_INT_UNIT_US + 50; + sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU Frag 1 --------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -6748,7 +6746,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_sdu_1_frag_pdu_emit_err) sdu_packet_number = 2000; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -6881,8 +6879,8 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -6895,7 +6893,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) sdu_packet_number = 0; event_number = 2000; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = TEST_TX_PDU_PAYLOAD_MAX - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); testdata_indx = 0; @@ -7058,7 +7056,7 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) event_number++; sdu_packet_number++; sdu_timestamp = sdu_timestamp + sdu_interval; - ref_point = ref_point + (iso_interval_int * ISO_INT_UNIT_US); + ref_point = ref_point + (iso_interval_int * CONN_INT_UNIT_US); sdu_total_size = 20; testdata_indx = testdata_size; testdata_size += 20; @@ -7131,488 +7129,6 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_1_frag_pdu_timeout) isoal_global.source_state[source_hdl].session.handle); } -/** - * Test Suite : TX framed SDU segmentation - * - * Tests that consecutive events are used irrespective of the target event info - * as long as they are feasible. - */ -ZTEST(test_tx_framed, test_tx_framed_event_utilization_1) -{ - const uint8_t number_of_pdus = 3; - const uint8_t sdu_fragment_data_size = 25; - const uint8_t testdata_size_max = sdu_fragment_data_size * 4; - /* Two SDUs and one that would overflow into a new PDU */ - const uint8_t number_of_seg_hdr_buf = 3; - - struct tx_pdu_meta_buffer tx_pdu_meta_buf[number_of_pdus]; - struct pdu_iso_sdu_sh seg_hdr[number_of_seg_hdr_buf]; - struct isoal_pdu_buffer pdu_buffer[number_of_pdus]; - struct tx_sdu_frag_buffer tx_sdu_frag_buf; - uint8_t testdata[testdata_size_max]; - isoal_source_handle_t source_hdl; - isoal_sdu_len_t sdu_total_size; - isoal_pdu_len_t pdu_write_end; - uint32_t stream_sync_delay; - uint64_t sdu_packet_number; - uint32_t group_sync_delay; - uint64_t pdu_event_number; - uint8_t iso_interval_int; - uint32_t iso_interval_us; - uint64_t payload_number; - uint32_t pdu_ref_point; - uint32_t sdu_timestamp; - uint16_t testdata_indx; - uint16_t testdata_size; - uint16_t pdu_write_loc; - uint16_t sdu_read_loc; - uint64_t event_number; - uint32_t sdu_interval; - uint8_t sdu_fragments; - uint16_t pdu_hdr_loc; - uint32_t ref_point; - isoal_status_t err; - uint8_t max_octets; - uint8_t role; - uint8_t BN; - uint8_t FT; - - /* Settings */ - role = BT_CONN_ROLE_PERIPHERAL; - iso_interval_int = 1; - iso_interval_us = iso_interval_int * ISO_INT_UNIT_US; - sdu_interval = ISO_INT_UNIT_US - 50; /* Less than an ISO interval */ - max_octets = TEST_TX_PDU_PAYLOAD_MAX; - BN = 2; - FT = 1; - stream_sync_delay = iso_interval_us - 200; - group_sync_delay = iso_interval_us - 50; - - /* SDU 0 -------------------------------------------------------------*/ - isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); - isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]); - isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]); - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - init_test_data_buffer(testdata, testdata_size_max); - (void)memset(&seg_hdr, 0, sizeof(seg_hdr)); - pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx; - pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu; - pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX; - pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx; - pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu; - pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX; - pdu_buffer[2].handle = (void *)&tx_pdu_meta_buf[2].node_tx; - pdu_buffer[2].pdu = (struct pdu_iso *)tx_pdu_meta_buf[2].node_tx.pdu; - pdu_buffer[2].size = TEST_TX_PDU_PAYLOAD_MAX; - sdu_packet_number = 0; - event_number = 5; - pdu_event_number = event_number; - sdu_timestamp = 9249; - ref_point = sdu_timestamp + iso_interval_us; - pdu_ref_point = ref_point; - sdu_total_size = sdu_fragment_data_size; - testdata_indx = 0; - testdata_size = sdu_fragment_data_size; - sdu_fragments = 0; - - source_hdl = basic_tx_test_setup(0xADAD, /* Handle */ - role, /* Role */ - true, /* Framed */ - BN, /* BN */ - FT, /* FT */ - max_octets, /* max_octets */ - sdu_interval, /* SDU Interval */ - iso_interval_int, /* ISO Interval */ - stream_sync_delay, /* Stream Sync Delay */ - group_sync_delay); /* Group Sync Delay */ - - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - sdu_total_size, - sdu_packet_number, - sdu_timestamp, - ref_point, - event_number, - &tx_sdu_frag_buf.sdu_tx); - - SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]); - SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]); - SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]); - SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]); - SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[2]); - SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]); - PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK); - PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK); - PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK); - PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK); - - err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); - - zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); - - /* Test segmentation (Black Box) */ - /* Valid PDUs */ - /* PDU 0 */ - payload_number = event_number * BN; - seg_hdr[0].sc = 0; - seg_hdr[0].cmplt = 0; - seg_hdr[0].timeoffset = pdu_ref_point - sdu_timestamp; - seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE; - pdu_hdr_loc = 0; - pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE; - sdu_read_loc = 0; - pdu_write_end = sdu_fragment_data_size + pdu_write_loc; - sdu_fragments++; - - ZASSERT_PDU_WRITE_TEST(history[0], - pdu_buffer[0], - pdu_hdr_loc, - &seg_hdr[0], - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)); - - ZASSERT_PDU_WRITE_TEST(history[1], - pdu_buffer[0], - pdu_write_loc, - &testdata[sdu_read_loc], - (pdu_write_end - pdu_write_loc)); - - seg_hdr[0].cmplt = 1; - seg_hdr[0].len += (pdu_write_end - pdu_write_loc); - - ZASSERT_PDU_WRITE_TEST(history[2], - pdu_buffer[0], - pdu_hdr_loc, - &seg_hdr[0], - PDU_ISO_SEG_HDR_SIZE); - - /* PDU should not be emitted */ - ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0); - - /* PDU release not expected (No Error) */ - ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); - - /* SDU 1 -------------------------------------------------------------*/ - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - sdu_packet_number++; - event_number += 2; - ref_point += iso_interval_us * 2; - sdu_timestamp += sdu_interval; - testdata_indx = testdata_size; - testdata_size += sdu_fragment_data_size; - - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - sdu_total_size, - sdu_packet_number, - sdu_timestamp, - ref_point, - event_number, - &tx_sdu_frag_buf.sdu_tx); - - err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); - - zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); - - /* Test segmentation (Black Box) */ - /* Valid PDUs */ - /* PDU 10 */ - pdu_hdr_loc = pdu_write_end; - seg_hdr[1].sc = 0; - seg_hdr[1].cmplt = 0; - seg_hdr[1].timeoffset = pdu_ref_point - sdu_timestamp; - seg_hdr[1].len = PDU_ISO_SEG_TIMEOFFSET_SIZE; - pdu_write_loc = pdu_write_end + (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); - pdu_write_end = TEST_TX_PDU_PAYLOAD_MAX; - sdu_read_loc = testdata_indx; - - ZASSERT_PDU_WRITE_TEST(history[3], - pdu_buffer[0], - pdu_hdr_loc, - &seg_hdr[1], - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)); - - ZASSERT_PDU_WRITE_TEST(history[4], - pdu_buffer[0], - pdu_write_loc, - &testdata[sdu_read_loc], - (pdu_write_end - pdu_write_loc)); - - /* PDU should not be allocated */ - - seg_hdr[1].len += (pdu_write_end - pdu_write_loc); - - ZASSERT_PDU_WRITE_TEST(history[5], - pdu_buffer[0], - pdu_hdr_loc, - &seg_hdr[1], - PDU_ISO_SEG_HDR_SIZE); - - ZASSERT_PDU_EMIT_TEST(history[0], - &tx_pdu_meta_buf[0].node_tx, - payload_number, - sdu_fragments, - PDU_BIS_LLID_FRAMED, - pdu_write_end, - isoal_global.source_state[source_hdl].session.handle); - - /* PDU release not expected (No Error) */ - ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); - - /* PDU 11 */ - payload_number++; - seg_hdr[2].sc = 1; - seg_hdr[2].cmplt = 0; - seg_hdr[2].timeoffset = 0; - seg_hdr[2].len = 0; - sdu_read_loc += (pdu_write_end - pdu_write_loc); - pdu_hdr_loc = 0; - pdu_write_end = testdata_size - testdata_indx - (pdu_write_end - pdu_write_loc) + - PDU_ISO_SEG_HDR_SIZE; - pdu_write_loc = PDU_ISO_SEG_HDR_SIZE; - sdu_fragments = 1; - - ZASSERT_PDU_WRITE_TEST(history[6], - pdu_buffer[1], - pdu_hdr_loc, - &seg_hdr[2], - PDU_ISO_SEG_HDR_SIZE); - - ZASSERT_PDU_WRITE_TEST(history[7], - pdu_buffer[1], - pdu_write_loc, - &testdata[sdu_read_loc], - (pdu_write_end - pdu_write_loc)); - - seg_hdr[2].cmplt = 1; - seg_hdr[2].len += (pdu_write_end - pdu_write_loc); - - ZASSERT_PDU_WRITE_TEST(history[8], - pdu_buffer[1], - pdu_hdr_loc, - &seg_hdr[2], - PDU_ISO_SEG_HDR_SIZE); - - /* PDU should not be emitted */ - ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1); - - /* PDU release not expected (No Error) */ - ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); - - /* SDU 2 -------------------------------------------------------------*/ - isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - sdu_packet_number++; - event_number += 2; - ref_point += iso_interval_us * 2; - sdu_timestamp += sdu_interval; - testdata_indx = testdata_size; - testdata_size += sdu_fragment_data_size; - - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - sdu_total_size, - sdu_packet_number, - sdu_timestamp, - ref_point, - event_number, - &tx_sdu_frag_buf.sdu_tx); - - err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); - - zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); - - /* Test segmentation (Black Box) */ - /* Valid PDUs */ - /* PDU 11 */ - - ZASSERT_PDU_EMIT_TEST(history[1], - &tx_pdu_meta_buf[1].node_tx, - payload_number, - sdu_fragments, - PDU_BIS_LLID_FRAMED, - pdu_write_end, - isoal_global.source_state[source_hdl].session.handle); - - /* PDU release not expected (No Error) */ - ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); - - /* PDU 12 */ - payload_number++; - pdu_event_number++; - pdu_ref_point += iso_interval_us; - seg_hdr[0].sc = 0; - seg_hdr[0].cmplt = 0; - seg_hdr[0].timeoffset = pdu_ref_point - sdu_timestamp; - seg_hdr[0].len = 3; - sdu_read_loc = testdata_indx; - pdu_hdr_loc = 0; - pdu_write_end = testdata_size - testdata_indx + PDU_ISO_SEG_HDR_SIZE + - PDU_ISO_SEG_TIMEOFFSET_SIZE; - pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE; - sdu_fragments = 1; - - ZASSERT_PDU_WRITE_TEST(history[9], - pdu_buffer[0], - pdu_hdr_loc, - &seg_hdr[0], - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)); - - ZASSERT_PDU_WRITE_TEST(history[10], - pdu_buffer[0], - pdu_write_loc, - &testdata[sdu_read_loc], - (pdu_write_end - pdu_write_loc)); - - seg_hdr[0].cmplt = 1; - seg_hdr[0].len += (pdu_write_end - pdu_write_loc); - - ZASSERT_PDU_WRITE_TEST(history[11], - pdu_buffer[0], - pdu_hdr_loc, - &seg_hdr[0], - PDU_ISO_SEG_HDR_SIZE); - - /* PDU should not be emitted */ - ZASSERT_PDU_EMIT_TEST_CALL_COUNT(2); - - /* PDU release not expected (No Error) */ - ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); - - /* Send Event Timeout ----------------------------------------------- */ - isoal_tx_event_prepare(source_hdl, pdu_event_number - 1); - - /* PDU should not be emitted */ - ZASSERT_PDU_EMIT_TEST_CALL_COUNT(2); - - /* PDU release not expected (No Error) */ - ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); - - /* SDU 3 -------------------------------------------------------------*/ - isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]); - isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]); - isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); - sdu_packet_number++; - event_number += 2; - ref_point += iso_interval_us * 2; - sdu_timestamp += sdu_interval; - sdu_total_size = sdu_fragment_data_size; - testdata_indx = testdata_size; - testdata_size += sdu_fragment_data_size; - - isoal_test_create_sdu_fagment(BT_ISO_SINGLE, - &testdata[testdata_indx], - (testdata_size - testdata_indx), - sdu_total_size, - sdu_packet_number, - sdu_timestamp, - ref_point, - event_number, - &tx_sdu_frag_buf.sdu_tx); - - err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); - - zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); - - /* Test segmentation (Black Box) */ - /* Valid PDUs */ - /* PDU 12 */ - ZASSERT_PDU_EMIT_TEST(history[2], - &tx_pdu_meta_buf[0].node_tx, - payload_number, - sdu_fragments, - PDU_BIS_LLID_FRAMED, - pdu_write_end, - isoal_global.source_state[source_hdl].session.handle); - - /* PDU 13 */ - payload_number++; - - /* Padding PDU */ - ZASSERT_PDU_EMIT_TEST_CALL_COUNT(4); - ZASSERT_PDU_EMIT_TEST(history[3], - &tx_pdu_meta_buf[1].node_tx, - payload_number, - 0, - PDU_BIS_LLID_FRAMED, - 0, - isoal_global.source_state[source_hdl].session.handle); - - /* PDU release not expected (No Error) */ - ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); - - /* PDU 14 */ - payload_number++; - pdu_event_number++; - pdu_ref_point += iso_interval_us; - seg_hdr[1].sc = 0; - seg_hdr[1].cmplt = 0; - seg_hdr[1].timeoffset = pdu_ref_point - sdu_timestamp; - seg_hdr[1].len = 3; - sdu_read_loc = testdata_indx; - pdu_hdr_loc = 0; - pdu_write_end = testdata_size - testdata_indx + PDU_ISO_SEG_HDR_SIZE + - PDU_ISO_SEG_TIMEOFFSET_SIZE; - pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE; - sdu_fragments = 1; - - ZASSERT_PDU_WRITE_TEST(history[12], - pdu_buffer[2], - pdu_hdr_loc, - &seg_hdr[1], - PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); - - ZASSERT_PDU_WRITE_TEST(history[13], - pdu_buffer[2], - pdu_write_loc, - &testdata[sdu_read_loc], - (pdu_write_end - pdu_write_loc)); - - seg_hdr[1].cmplt = 1; - seg_hdr[1].len += (pdu_write_end - pdu_write_loc); - - ZASSERT_PDU_WRITE_TEST(history[14], - pdu_buffer[2], - pdu_hdr_loc, - &seg_hdr[1], - PDU_ISO_SEG_HDR_SIZE); - - /* PDU should not be emitted */ - ZASSERT_PDU_EMIT_TEST_CALL_COUNT(4); - - /* PDU release not expected (No Error) */ - ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); - - /* Send Event Timeout ----------------------------------------------- */ - isoal_tx_event_prepare(source_hdl, pdu_event_number); - - - ZASSERT_PDU_EMIT_TEST(history[4], - &tx_pdu_meta_buf[2].node_tx, - payload_number, - sdu_fragments, - PDU_BIS_LLID_FRAMED, - pdu_write_end, - isoal_global.source_state[source_hdl].session.handle); - - /* PDU 5 */ - payload_number++; - - /* Padding PDU */ - ZASSERT_PDU_EMIT_TEST(history[5], - &tx_pdu_meta_buf[0].node_tx, - payload_number, - 0, - PDU_BIS_LLID_FRAMED, - 0, - isoal_global.source_state[source_hdl].session.handle); - - /* PDU release not expected (No Error) */ - ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); -} - /** * Test Suite : TX framed EBQ test IAL-CIS-FRA-PER-BV07C * @@ -7657,8 +7173,8 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; BN = 1; FT = 1; - stream_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 200; - group_sync_delay = (iso_interval_int * ISO_INT_UNIT_US) - 50; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; /* SDU 1 Frag 1 ------------------------------------------------------*/ isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf); @@ -7671,7 +7187,7 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) sdu_packet_number = 0; event_number = 0; sdu_timestamp = 9249; - ref_point = sdu_timestamp + (iso_interval_int * ISO_INT_UNIT_US) - 50; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; sdu_total_size = 10; testdata_indx = 0; testdata_size = 10; @@ -7834,7 +7350,7 @@ ZTEST(test_tx_framed_ebq, test_tx_framed_cis_fra_per_bv07c) event_number++; sdu_packet_number++; sdu_timestamp = sdu_timestamp + sdu_interval; - ref_point = ref_point + (iso_interval_int * ISO_INT_UNIT_US); + ref_point = ref_point + (iso_interval_int * CONN_INT_UNIT_US); sdu_total_size = 20; testdata_indx = testdata_size; testdata_size += 20; From a3204b3b44662a328ba4f90b6760e341ec09fb92 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:52 +0000 Subject: [PATCH 0655/1623] Revert "[nrf fromtree] soc nordic_nrf: Select new compatible kconfig options" This reverts commit ff4e15ae36af8fc8abe680e8a418f882d97e731d. Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/nrf53/Kconfig.series | 1 - soc/arm/nordic_nrf/nrf53/Kconfig.soc | 2 -- 2 files changed, 3 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.series b/soc/arm/nordic_nrf/nrf53/Kconfig.series index 8ab81ad310b..03e47bacf63 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.series +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.series @@ -6,7 +6,6 @@ config SOC_SERIES_NRF53X bool "Nordic Semiconductor nRF53 series MCU" select ARM - select SOC_COMPATIBLE_NRF53X select CPU_CORTEX_M33 select CPU_CORTEX_M_HAS_DWT select CPU_HAS_ARM_MPU diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 87d8a6d0c7a..2ad4a7add66 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -10,13 +10,11 @@ config SOC_NRF5340_CPUAPP select CPU_HAS_FPU select ARMV8_M_DSP select HAS_POWEROFF - select SOC_COMPATIBLE_NRF5340_CPUAPP imply SOC_NRF53_RTC_PRETICK config SOC_NRF5340_CPUNET bool select ARM_ON_EXIT_CPU_IDLE - select SOC_COMPATIBLE_NRF5340_CPUNET imply SOC_NRF53_ANOMALY_160_WORKAROUND_NEEDED imply SOC_NRF53_RTC_PRETICK if !WDT_NRFX From 7fbab865f66d50e41b14a738975193501bf35eac Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:52 +0000 Subject: [PATCH 0656/1623] Revert "[nrf fromtree] nrf5x_bsim: Add helper kconfig symbols for simulated nrf5340" This reverts commit 7b202de62b4f1ed8938747b4664972b02b565942. Signed-off-by: Dominik Ermel --- boards/posix/nrf52_bsim/Kconfig | 6 ------ soc/Kconfig | 12 ++---------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/boards/posix/nrf52_bsim/Kconfig b/boards/posix/nrf52_bsim/Kconfig index 566520fafa0..ea1b49bea0a 100644 --- a/boards/posix/nrf52_bsim/Kconfig +++ b/boards/posix/nrf52_bsim/Kconfig @@ -26,9 +26,3 @@ config SOC_SERIES_BSIM_NRF52X depends on SOC_SERIES_BSIM_NRFXX help Any NRF52 simulated SOC with BabbleSim, based on the POSIX arch - -config SOC_SERIES_BSIM_NRF53X - bool - depends on SOC_SERIES_BSIM_NRFXX - help - Any NRF53 simulated SOC with BabbleSim, based on the POSIX arch diff --git a/soc/Kconfig b/soc/Kconfig index 33c2d0c29a4..20734c0f51f 100644 --- a/soc/Kconfig +++ b/soc/Kconfig @@ -24,7 +24,8 @@ source "subsys/logging/Kconfig.template.log_config" endmenu # The helper symbols below are put here due to an unusual setup: The simulated -# nrf5x_bsim boards use the POSIX arch, but are compatible with Nordic ARM boards +# nrf52_bsim board uses the POSIX arch, but is compatible with Nordic ARM +# boards config SOC_COMPATIBLE_NRF bool @@ -32,18 +33,9 @@ config SOC_COMPATIBLE_NRF config SOC_COMPATIBLE_NRF52X bool -config SOC_COMPATIBLE_NRF53X - bool - config SOC_COMPATIBLE_NRF52833 bool -config SOC_COMPATIBLE_NRF5340_CPUNET - bool - -config SOC_COMPATIBLE_NRF5340_CPUAPP - bool - # # SOC_*_LD: SoC specific Linker script additions # From f83c39718f7d041d7584c03a6202d580fba70563 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:53 +0000 Subject: [PATCH 0657/1623] Revert "[nrf fromtree] Test: Bluetooth: controller: add CI testing for advertising chaining" This reverts commit 96efa92108ad91cec08e0c23b557433cfc0d6ddb. Signed-off-by: Dominik Ermel --- .../broadcaster_multiple/src/broadcaster_multiple.c | 10 +--------- tests/bsim/bluetooth/host/adv/chain/prj.conf | 6 +++--- tests/bsim/bluetooth/host/adv/chain/src/main.c | 10 +--------- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c index 30fe35d3dec..d1c6d792e95 100644 --- a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c +++ b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c @@ -47,18 +47,11 @@ BT_AD_DATA_FORMAT_LEN_SIZE - \ BT_AD_DATA_FORMAT_TYPE_SIZE - \ BT_DEVICE_NAME_AD_DATA_LEN))) -/* - * Datalength is an integer, so BT_MFG_DATA_LEN can not be larger than 255. - * To ensure that we need to chain PDUs we therefore add manufacturer data - * twice when chaining is enabled - */ + static uint8_t mfg_data[BT_MFG_DATA_LEN] = { 0xFF, 0xFF, }; static const struct bt_data ad[] = { BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, sizeof(mfg_data)), -#if defined(CONFIG_BT_CTLR_ADV_DATA_CHAIN) - BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, sizeof(mfg_data)), -#endif }; static struct bt_le_ext_adv *adv[CONFIG_BT_EXT_ADV_MAX_ADV_SET]; @@ -82,7 +75,6 @@ int broadcaster_multiple(void) printk("Bluetooth init failed (err %d)\n", err); return err; } - for (int index = 0; index < CONFIG_BT_EXT_ADV_MAX_ADV_SET; index++) { /* Use advertising set instance index as SID */ adv_param.sid = index; diff --git a/tests/bsim/bluetooth/host/adv/chain/prj.conf b/tests/bsim/bluetooth/host/adv/chain/prj.conf index 82eb16e5db0..85861dccd66 100644 --- a/tests/bsim/bluetooth/host/adv/chain/prj.conf +++ b/tests/bsim/bluetooth/host/adv/chain/prj.conf @@ -30,9 +30,9 @@ CONFIG_BT_EXT_SCAN_BUF_SIZE=1650 # Set maximum scan data length for Extended Scanning in Bluetooth LE Controller CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 -# The Zephyr Controller does not combine all the 1650 bytes before -# fragmenting into 8 HCI reports, if a PDU has 255 bytes, -# it will generate 2 HCI reports and so we need to reserve 16 buffers +# Zephyr Controller does not combine all the 1650 bytes before fragmenting them +# into 8 HCI reports, if a PDU has 255 bytes, it will generate 2 HCI reports +# and so we need to reserve 16 buffers CONFIG_BT_BUF_EVT_RX_COUNT=16 # Increase Zephyr Bluetooth LE Controller Rx buffer to receive complete chain diff --git a/tests/bsim/bluetooth/host/adv/chain/src/main.c b/tests/bsim/bluetooth/host/adv/chain/src/main.c index d58d2a3890f..4475a069535 100644 --- a/tests/bsim/bluetooth/host/adv/chain/src/main.c +++ b/tests/bsim/bluetooth/host/adv/chain/src/main.c @@ -34,12 +34,8 @@ #define NAME_LEN 30 #define BT_AD_DATA_NAME_SIZE (sizeof(CONFIG_BT_DEVICE_NAME) - 1U + 2U) #define BT_AD_DATA_MFG_DATA_SIZE (254U + 2U) -/* - * for testing chaining the manufacturing data is duplicated, hence DATA_LEN needs to - * add twice the size for this element - */ #define DATA_LEN MIN((BT_AD_DATA_NAME_SIZE + \ - BT_AD_DATA_MFG_DATA_SIZE + BT_AD_DATA_MFG_DATA_SIZE), \ + BT_AD_DATA_MFG_DATA_SIZE), \ CONFIG_BT_CTLR_ADV_DATA_LEN_MAX) static K_SEM_DEFINE(sem_recv, 0, 1); @@ -98,7 +94,6 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, data_len = buf->len; if (data_len != DATA_LEN) { - printk("Received datalength: %d\n", data_len); return; } @@ -106,13 +101,11 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, bt_data_parse(buf, data_cb, name); if (strcmp(name, CONFIG_BT_DEVICE_NAME)) { - printk("Wrong name %s\n", name); return; } for (uint8_t i = 0; i < sid_count; i++) { if (sid[i] == info->sid) { - printk("Received SID %d\n", info->sid); return; } } @@ -120,7 +113,6 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, sid[sid_count++] = info->sid; if (sid_count < CONFIG_BT_EXT_ADV_MAX_ADV_SET) { - printk("Received advertising sets: %d\n", sid_count); return; } From d8e69fe789f395c7901aae0d1d2a545be0002410 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:53 +0000 Subject: [PATCH 0658/1623] Revert "[nrf fromtree] Bluetooth: controller: change calc for data in PDU" This reverts commit 8eefe7f80331b72b2bcf00113684fb60fbad906f. Signed-off-by: Dominik Ermel --- .../bluetooth/controller/ll_sw/ull_adv_aux.c | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c index 2480c286e4b..0754a047207 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c @@ -411,9 +411,13 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, /* We could not fit all the data, append as much as possible * ad_len_overflow is how much overflows with the AUX ptr */ + uint8_t ad_len_overflow_first_try; const uint16_t chain_add_fields = ULL_ADV_PDU_HDR_FIELD_AD_DATA_APPEND | ULL_ADV_PDU_HDR_FIELD_AUX_PTR; + ad_len_overflow_first_try = hdr_data[ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + + ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; + val_ptr = hdr_data; *val_ptr++ = len; (void)memcpy(val_ptr, &data, sizeof(data)); @@ -423,18 +427,18 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, chain_err = ull_adv_aux_pdu_set_clear(adv, pdu_prev, pdu, chain_add_fields, 0U, hdr_data); - ad_len_chain = hdr_data[ULL_ADV_HDR_DATA_AUX_PTR_PTR_OFFSET + - ULL_ADV_HDR_DATA_AUX_PTR_PTR_SIZE + - ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + - ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; - - /* len is the total amount of datawe want to add - * ad_len_chain is the amount of data that does - * not fit in the current PDU - * the difference of the two is the amount that - * we can fit in the current PDU + ad_len_overflow = hdr_data[ULL_ADV_HDR_DATA_AUX_PTR_PTR_OFFSET + + ULL_ADV_HDR_DATA_AUX_PTR_PTR_SIZE + + ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + + ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; + + /* ad_len_overflow - ad_len_overflow_first_try is the size of + * the aux pointer + * ad_len_prev is how much data is already present, ad_len is how + * much data we can add to this PDU */ - ad_len = len - ad_len_chain; + ad_len = PDU_AC_PAYLOAD_SIZE_MAX - ad_len_prev - + (ad_len_overflow - ad_len_overflow_first_try) - 4; val_ptr = hdr_data; *val_ptr++ = ad_len; @@ -453,10 +457,9 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, /* * in the next PDU we still need to add ad_len_chain bytes of data * but we do not have overflow, since we already added - * the exact amount that would fit. We explicitly set overflow to 0. - * FIXME: ad_len_overflow already should be 0, to be verified. We wait - * fixing this until rewriting this whole function + * the exact amount that would fit */ + ad_len_chain = len - ad_len; ad_len_overflow = 0U; } else { ad_len_overflow = 0U; From 2b4f365210aaf1caa7a71b880b7bd9b0a7655f2d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:53 +0000 Subject: [PATCH 0659/1623] Revert "[nrf fromtree] Bluetooth: controller: fix failing EBQ advertising tests" This reverts commit 68a8baa59b3e58f0e88623996868009d4e5f3741. Signed-off-by: Dominik Ermel --- .../src/broadcaster_multiple.c | 1 + .../bluetooth/controller/ll_sw/ull_adv_aux.c | 154 ++++++------------ tests/bsim/bluetooth/host/adv/chain/prj.conf | 5 +- 3 files changed, 49 insertions(+), 111 deletions(-) diff --git a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c index d1c6d792e95..56cc210de78 100644 --- a/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c +++ b/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c @@ -75,6 +75,7 @@ int broadcaster_multiple(void) printk("Bluetooth init failed (err %d)\n", err); return err; } + for (int index = 0; index < CONFIG_BT_EXT_ADV_MAX_ADV_SET; index++) { /* Use advertising set instance index as SID */ adv_param.sid = index; diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c index 0754a047207..302dc6da785 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c @@ -117,7 +117,6 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, uint8_t ad_len_overflow; uint8_t ad_len_chain; struct pdu_adv *pdu; - uint8_t ad_len = 0U; #endif /* CONFIG_BT_CTLR_ADV_AUX_PDU_LINK */ /* Get the advertising set instance */ @@ -302,7 +301,7 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, struct pdu_adv *pdu_chain_prev; struct pdu_adv *pdu_chain; uint16_t ad_len_total; - uint8_t ad_len_prev = 0U; + uint8_t ad_len_prev; /* Traverse to next set clear hdr data parameter */ val_ptr += sizeof(data); @@ -318,23 +317,29 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, ad_len_total = 0U; pdu_chain_prev = pdu_prev; pdu_chain = pdu; - /* make a copy of the previous chain, until we reach the end */ do { - val_ptr = hdr_data; - *val_ptr++ = 0U; - (void)memset((void *)val_ptr, 0U, - ULL_ADV_HDR_DATA_DATA_PTR_SIZE); + /* Prepare for aux ptr field reference to be returned, hence + * second parameter will be for AD data field. + */ + *val_ptr = 0U; + (void)memset((void *)&val_ptr[ULL_ADV_HDR_DATA_DATA_PTR_OFFSET], + 0U, ULL_ADV_HDR_DATA_DATA_PTR_SIZE); pdu_prev = pdu_chain_prev; pdu = pdu_chain; + /* Add Aux Ptr field if not already present */ err = ull_adv_aux_pdu_set_clear(adv, pdu_prev, pdu, - ULL_ADV_PDU_HDR_FIELD_AD_DATA, - 0U, hdr_data); - ad_len_prev = hdr_data[ULL_ADV_HDR_DATA_LEN_OFFSET]; - + (ULL_ADV_PDU_HDR_FIELD_AD_DATA | + ULL_ADV_PDU_HDR_FIELD_AUX_PTR), + 0, hdr_data); LL_ASSERT(!err || (err == BT_HCI_ERR_PACKET_TOO_LONG)); + /* Get PDUs previous AD data length */ + ad_len_prev = + hdr_data[ULL_ADV_HDR_DATA_AUX_PTR_PTR_OFFSET + + ULL_ADV_HDR_DATA_AUX_PTR_PTR_SIZE]; + /* Check of max supported AD data len */ ad_len_total += ad_len_prev; if ((ad_len_total + len) > @@ -360,10 +365,31 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, (!pdu_chain_prev && !pdu_chain)); } while (pdu_chain_prev); - /* No AD data overflow */ - ad_len_overflow = 0U; - /* No AD data in chain PDU */ - ad_len_chain = 0U; + if (err == BT_HCI_ERR_PACKET_TOO_LONG) { + ad_len_overflow = + hdr_data[ULL_ADV_HDR_DATA_AUX_PTR_PTR_OFFSET + + ULL_ADV_HDR_DATA_AUX_PTR_PTR_SIZE + + ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + + ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; + + /* Prepare for aux ptr field reference to be returned, + * hence second parameter will be for AD data field. + * Fill it with reduced AD data length. + */ + *val_ptr = ad_len_prev - ad_len_overflow; + + /* AD data len in chain PDU */ + ad_len_chain = len; + + /* Proceed to add chain PDU */ + err = 0U; + } else { + /* No AD data overflow */ + ad_len_overflow = 0U; + + /* No AD data in chain PDU */ + ad_len_chain = 0U; + } } #else /* !CONFIG_BT_CTLR_ADV_AUX_PDU_LINK */ } else { @@ -385,88 +411,8 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, #if defined(CONFIG_BT_CTLR_ADV_AUX_PDU_LINK) if ((op == BT_HCI_LE_EXT_ADV_OP_INTERM_FRAG) || - (op == BT_HCI_LE_EXT_ADV_OP_LAST_FRAG)) { - /* in the previous step we duplicated the chain - * the next step is to append new data in the last existing pdu in the chain, - */ - - uint8_t chain_err = 0U; - - val_ptr = hdr_data; - *val_ptr++ = len; - (void)memcpy(val_ptr, &data, sizeof(data)); - - /* Append data to the last PDU */ - chain_err = ull_adv_aux_pdu_set_clear(adv, pdu_prev, pdu, - ULL_ADV_PDU_HDR_FIELD_AD_DATA_APPEND, - 0U, hdr_data); - - LL_ASSERT((!chain_err) || (chain_err == BT_HCI_ERR_PACKET_TOO_LONG)); - - /* FIXME: the code has become quite complex, an alternative and simpler - * implementation would be to first fill an array with all data that - * must be send, and create the chained PDUs from this array - */ - if (chain_err == BT_HCI_ERR_PACKET_TOO_LONG) { - /* We could not fit all the data, append as much as possible - * ad_len_overflow is how much overflows with the AUX ptr - */ - uint8_t ad_len_overflow_first_try; - const uint16_t chain_add_fields = ULL_ADV_PDU_HDR_FIELD_AD_DATA_APPEND | - ULL_ADV_PDU_HDR_FIELD_AUX_PTR; - - ad_len_overflow_first_try = hdr_data[ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + - ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; - - val_ptr = hdr_data; - *val_ptr++ = len; - (void)memcpy(val_ptr, &data, sizeof(data)); - val_ptr += sizeof(data); - *val_ptr++ = len; - (void)memcpy(val_ptr, &data, sizeof(data)); - chain_err = ull_adv_aux_pdu_set_clear(adv, pdu_prev, pdu, - chain_add_fields, - 0U, hdr_data); - ad_len_overflow = hdr_data[ULL_ADV_HDR_DATA_AUX_PTR_PTR_OFFSET + - ULL_ADV_HDR_DATA_AUX_PTR_PTR_SIZE + - ULL_ADV_HDR_DATA_DATA_PTR_OFFSET + - ULL_ADV_HDR_DATA_DATA_PTR_SIZE]; - - /* ad_len_overflow - ad_len_overflow_first_try is the size of - * the aux pointer - * ad_len_prev is how much data is already present, ad_len is how - * much data we can add to this PDU - */ - ad_len = PDU_AC_PAYLOAD_SIZE_MAX - ad_len_prev - - (ad_len_overflow - ad_len_overflow_first_try) - 4; - - val_ptr = hdr_data; - *val_ptr++ = ad_len; - (void)memcpy(val_ptr, &data, sizeof(data)); - val_ptr += sizeof(data); - *val_ptr++ = ad_len; - (void)memcpy(val_ptr, &data, sizeof(data)); - - /* we now know how much data we can add to the - * last PDU without getting an overflow - */ - chain_err = ull_adv_aux_pdu_set_clear(adv, pdu_prev, pdu, - chain_add_fields, - 0U, hdr_data); - LL_ASSERT(chain_err == 0U); - /* - * in the next PDU we still need to add ad_len_chain bytes of data - * but we do not have overflow, since we already added - * the exact amount that would fit - */ - ad_len_chain = len - ad_len; - ad_len_overflow = 0U; - } else { - ad_len_overflow = 0U; - } - } - - if (ad_len_chain || ad_len_overflow) { + (op == BT_HCI_LE_EXT_ADV_OP_LAST_FRAG) || + ad_len_overflow) { struct pdu_adv_com_ext_adv *com_hdr_chain; struct pdu_adv_com_ext_adv *com_hdr; struct pdu_adv_ext_hdr *hdr_chain; @@ -479,7 +425,6 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, uint16_t sec_len; uint8_t *dptr; - len = ad_len_chain; /* Get reference to flags in superior PDU */ com_hdr = &pdu->adv_ext_ind; if (com_hdr->ext_hdr_len) { @@ -505,7 +450,6 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, hdr_chain = (void *)&com_hdr_chain->ext_hdr_adv_data[0]; dptr_chain = (void *)hdr_chain; - LL_ASSERT(dptr_chain); /* Flags */ *dptr_chain = 0U; @@ -554,7 +498,6 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, if (ad_len_overflow) { uint8_t *ad_overflow; - val_ptr = hdr_data; /* Copy overflowed AD data from previous PDU into this * new chain PDU */ @@ -562,7 +505,6 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, &val_ptr[ULL_ADV_HDR_DATA_DATA_PTR_OFFSET], sizeof(ad_overflow)); ad_overflow += *val_ptr; - (void)memcpy(dptr_chain, ad_overflow, ad_len_overflow); dptr_chain += ad_len_overflow; @@ -587,6 +529,8 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, return err; } + /* AD data len in chain PDU besides the overflow */ + len = ad_len_chain; } /* Check AdvData overflow */ @@ -611,13 +555,7 @@ uint8_t ll_adv_aux_ad_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref, pdu_chain->len = sec_len + ad_len_overflow + len; /* Fill AD Data in chain PDU */ - if (ad_len_overflow != 0U) { - (void)memcpy(dptr_chain, data, ad_len_overflow); - } - - if (ad_len_chain != 0U) { - (void)memcpy(dptr_chain, &data[ad_len + ad_len_overflow], ad_len_chain); - } + (void)memcpy(dptr_chain, data, len); /* Get reference to aux ptr in superior PDU */ (void)memcpy(&aux_ptr, diff --git a/tests/bsim/bluetooth/host/adv/chain/prj.conf b/tests/bsim/bluetooth/host/adv/chain/prj.conf index 85861dccd66..3e7f11009c2 100644 --- a/tests/bsim/bluetooth/host/adv/chain/prj.conf +++ b/tests/bsim/bluetooth/host/adv/chain/prj.conf @@ -30,9 +30,8 @@ CONFIG_BT_EXT_SCAN_BUF_SIZE=1650 # Set maximum scan data length for Extended Scanning in Bluetooth LE Controller CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 -# Zephyr Controller does not combine all the 1650 bytes before fragmenting them -# into 8 HCI reports, if a PDU has 255 bytes, it will generate 2 HCI reports -# and so we need to reserve 16 buffers +# Zephyr Bluetooth LE Controller needs 16 event buffers to generate Extended +# Advertising Report for receiving the complete 1650 bytes of data CONFIG_BT_BUF_EVT_RX_COUNT=16 # Increase Zephyr Bluetooth LE Controller Rx buffer to receive complete chain From fe9faf985bf62abfd7d1451b6f6f93c7a08e2b6b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:53 +0000 Subject: [PATCH 0660/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix leak in scheduled ticker node" This reverts commit 730249a34382716d6593e50bbd03aa0c3c1561ac. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ticker/ticker.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index 83bd6437d59..9b5bb53a625 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -2337,7 +2337,6 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, while (rescheduling) { struct ticker_node *ticker_resched; uint32_t ticks_to_expire_offset; - uint8_t ticker_id_resched_prev; struct ticker_ext *ext_data; uint32_t ticks_start_offset; uint32_t window_start_ticks; @@ -2351,7 +2350,6 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, rescheduling = 0U; /* Find first pending re-schedule */ - ticker_id_resched_prev = TICKER_NULL; ticker_id_resched = instance->ticker_id_head; while (ticker_id_resched != TICKER_NULL) { ticker_resched = &nodes[ticker_id_resched]; @@ -2359,8 +2357,6 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, /* Pending reschedule found */ break; } - - ticker_id_resched_prev = ticker_id_resched; ticker_id_resched = ticker_resched->next; } if (ticker_id_resched == TICKER_NULL) { @@ -2540,15 +2536,13 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, /* If the node moved in the list, insert it */ if (ticker_id_prev != TICKER_NULL) { - /* Remove node from its current position in list */ - if (ticker_id_resched_prev != TICKER_NULL) { - /* Node was not at the head of the list */ - nodes[ticker_id_resched_prev].next = - ticker_resched->next; - } else { - /* Node was at the head, move head forward */ - instance->ticker_id_head = ticker_resched->next; - } + LL_ASSERT(instance->ticker_id_head == + ticker_id_resched); + + /* Node did not become the first - update head and + * insert node after 'previous' + */ + instance->ticker_id_head = ticker_resched->next; /* Link inserted node */ ticker_resched->next = nodes[ticker_id_prev].next; From a0783e31a298e059fec430318a29671b7b2f91bf Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:53 +0000 Subject: [PATCH 0661/1623] Revert "[nrf fromtree] Bluetooth: Controller: Rename ticker reschedule variables" This reverts commit 2b86f49ef42aec7d80c2842da5dc6414d0b0ecc1. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ticker/ticker.c | 123 +++++++++----------- 1 file changed, 54 insertions(+), 69 deletions(-) diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index 9b5bb53a625..e5c89dca905 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -2326,46 +2326,43 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, uint32_t ticks_elapsed) { struct ticker_node *nodes; - uint8_t rescheduling; - uint8_t rescheduled; + uint8_t rescheduling = 1U; + uint8_t rescheduled = 0U; nodes = &instance->nodes[0]; /* Do until all pending re-schedules handled */ - rescheduling = 1U; - rescheduled = 0U; while (rescheduling) { - struct ticker_node *ticker_resched; - uint32_t ticks_to_expire_offset; + uint32_t ticks_to_expire_offset = 0U; + uint32_t ticks_start_offset = 0U; + uint32_t window_start_ticks = 0U; + uint32_t ticks_slot_window = 0U; + uint32_t ticks_to_expire = 0U; struct ticker_ext *ext_data; - uint32_t ticks_start_offset; - uint32_t window_start_ticks; - uint32_t ticks_slot_window; - uint8_t ticker_id_resched; - uint32_t ticks_to_expire; + struct ticker_node *ticker; + uint8_t ticker_id_head; uint8_t ticker_id_prev; - uint8_t ticker_id_next; + uint8_t ticker_id_iter; uint32_t ticks_slot; rescheduling = 0U; /* Find first pending re-schedule */ - ticker_id_resched = instance->ticker_id_head; - while (ticker_id_resched != TICKER_NULL) { - ticker_resched = &nodes[ticker_id_resched]; - if (TICKER_RESCHEDULE_PENDING(ticker_resched)) { + ticker_id_head = instance->ticker_id_head; + while (ticker_id_head != TICKER_NULL) { + ticker = &nodes[ticker_id_head]; + if (TICKER_RESCHEDULE_PENDING(ticker)) { /* Pending reschedule found */ break; } - ticker_id_resched = ticker_resched->next; + ticker_id_head = ticker->next; } - if (ticker_id_resched == TICKER_NULL) { + if (ticker_id_head == TICKER_NULL) { /* Done */ break; } /* Check for intersection with already active node */ - window_start_ticks = 0U; if (instance->ticks_slot_previous > ticks_elapsed) { /* Active node intersects - window starts after end of * active slot @@ -2374,7 +2371,7 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, ticks_elapsed; } - ticker_id_next = ticker_resched->next; + ticker_id_iter = nodes[ticker_id_head].next; /* If drift was applied to this node, this must be * taken into consideration. Reduce the window with @@ -2385,50 +2382,43 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, * ticker would have the best possible window to re-schedule in * and not be restricted to ticks_slot_window - ticks_drift. */ - ext_data = ticker_resched->ext_data; + ext_data = ticker->ext_data; if (ext_data->ticks_drift < ext_data->ticks_slot_window) { ticks_slot_window = ext_data->ticks_slot_window - ext_data->ticks_drift; } else { /* Window has been exhausted - we can't reschedule */ - ticker_id_next = TICKER_NULL; - - /* Assignment will be unused when TICKER_NULL */ - ticks_slot_window = 0U; + ticker_id_iter = TICKER_NULL; } /* Use ticker's reserved time ticks_slot, else for unreserved * tickers use the reschedule margin as ticks_slot. */ - if (ticker_resched->ticks_slot) { - ticks_slot = ticker_resched->ticks_slot; + if (ticker->ticks_slot) { + ticks_slot = ticker->ticks_slot; } else { - LL_ASSERT(TICKER_HAS_SLOT_WINDOW(ticker_resched)); + LL_ASSERT(TICKER_HAS_SLOT_WINDOW(ticker)); ticks_slot = HAL_TICKER_RESCHEDULE_MARGIN; } /* Try to find available slot for re-scheduling */ - ticks_to_expire_offset = 0U; - ticks_start_offset = 0U; - ticks_to_expire = 0U; - while ((ticker_id_next != TICKER_NULL) && + while ((ticker_id_iter != TICKER_NULL) && ((ticks_start_offset + ticks_slot) <= ticks_slot_window)) { - struct ticker_node *ticker_next; - uint32_t window_end_ticks; + uint32_t window_end_ticks = 0U; + struct ticker_node *node; - ticker_next = &nodes[ticker_id_next]; - ticks_to_expire_offset += ticker_next->ticks_to_expire; + node = &nodes[ticker_id_iter]; + ticks_to_expire_offset += node->ticks_to_expire; /* Skip other pending re-schedule nodes and * tickers with no reservation or not periodic */ - if (TICKER_RESCHEDULE_PENDING(ticker_next) || - !ticker_next->ticks_slot || - !ticker_next->ticks_periodic) { - ticker_id_next = ticker_next->next; - + if (TICKER_RESCHEDULE_PENDING(node) || + !node->ticks_slot || + !node->ticks_periodic) { + ticker_id_iter = node->next; continue; } @@ -2454,7 +2444,7 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, */ if (window_end_ticks > (ticks_start_offset + ticks_slot)) { - if (!ticker_resched->ticks_slot) { + if (!ticker->ticks_slot) { /* Place at start of window */ ticks_to_expire = window_start_ticks; } else { @@ -2487,10 +2477,10 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, */ ticks_start_offset += ticks_to_expire_offset; window_start_ticks = ticks_start_offset + - ticker_next->ticks_slot; + node->ticks_slot; ticks_to_expire_offset = 0U; - if (!ticker_resched->ticks_slot) { + if (!ticker->ticks_slot) { /* Try at the end of the next node */ ticks_to_expire = window_start_ticks; } else { @@ -2503,61 +2493,56 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, ticks_slot; } - ticker_id_next = ticker_next->next; + ticker_id_iter = node->next; } ext_data->ticks_drift += ticks_to_expire - - ticker_resched->ticks_to_expire; - ticker_resched->ticks_to_expire = ticks_to_expire; + ticker->ticks_to_expire; + ticker->ticks_to_expire = ticks_to_expire; + ticker_id_iter = nodes[ticker_id_head].next; + ticker_id_prev = TICKER_NULL; /* Place the ticker node sorted by expiration time and adjust * delta times */ - ticker_id_next = ticker_resched->next; - ticker_id_prev = TICKER_NULL; - while (ticker_id_next != TICKER_NULL) { - struct ticker_node *ticker_next; + while (ticker_id_iter != TICKER_NULL) { + struct ticker_node *node; - ticker_next = &nodes[ticker_id_next]; - if (ticker_resched->ticks_to_expire > - ticker_next->ticks_to_expire) { + node = &nodes[ticker_id_iter]; + if (ticker->ticks_to_expire > node->ticks_to_expire) { /* Node is after this - adjust delta */ - ticker_resched->ticks_to_expire -= - ticker_next->ticks_to_expire; + ticker->ticks_to_expire -= + node->ticks_to_expire; } else { /* Node is before this one */ - ticker_next->ticks_to_expire -= - ticker_resched->ticks_to_expire; + node->ticks_to_expire -= + ticker->ticks_to_expire; break; } - ticker_id_prev = ticker_id_next; - ticker_id_next = ticker_next->next; + ticker_id_prev = ticker_id_iter; + ticker_id_iter = node->next; } - /* If the node moved in the list, insert it */ if (ticker_id_prev != TICKER_NULL) { - LL_ASSERT(instance->ticker_id_head == - ticker_id_resched); - /* Node did not become the first - update head and * insert node after 'previous' */ - instance->ticker_id_head = ticker_resched->next; + instance->ticker_id_head = nodes[ticker_id_head].next; /* Link inserted node */ - ticker_resched->next = nodes[ticker_id_prev].next; - nodes[ticker_id_prev].next = ticker_id_resched; + nodes[ticker_id_head].next = nodes[ticker_id_prev].next; + nodes[ticker_id_prev].next = ticker_id_head; } /* Remove latency added in ticker_worker */ - ticker_resched->lazy_current--; + ticker->lazy_current--; /* Prevent repeated re-scheduling */ ext_data->reschedule_state = TICKER_RESCHEDULE_STATE_DONE; #if defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO) - ticker_mark_expire_info_outdated(instance, ticker_id_resched); + ticker_mark_expire_info_outdated(instance, ticker_id_head); #endif /* CONFIG_BT_TICKER_EXT_EXPIRE_INFO */ /* Check for other pending re-schedules and set exit flag */ From bdd75c8f0e396799b29865b1caa47d61fd495ef7 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:54 +0000 Subject: [PATCH 0662/1623] Revert "[nrf fromtree] Bluetooth: Controller: Remove legacy BT_CTLR_FAST_ENC option" This reverts commit 009025d45d384fd1eacf3669c9a859627058b684. Signed-off-by: Dominik Ermel --- drivers/entropy/entropy_nrf5.c | 5 +++++ drivers/entropy/entropy_smartbond.c | 5 +++++ drivers/entropy/entropy_stm32.c | 9 ++++++++- subsys/bluetooth/controller/Kconfig.ll_sw_split | 12 ++++++++++++ tests/bluetooth/init/prj_ctlr_4_0.conf | 1 + tests/bluetooth/init/prj_ctlr_4_0_dbg.conf | 1 + tests/bluetooth/init/prj_ctlr_5_x_dbg.conf | 1 + tests/bluetooth/init/prj_ctlr_dbg.conf | 1 + tests/bluetooth/init/prj_ctlr_ticker.conf | 1 + tests/bluetooth/init/prj_ctlr_tiny.conf | 1 + 10 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/entropy/entropy_nrf5.c b/drivers/entropy/entropy_nrf5.c index 2f04bc06a37..8febcfacb15 100644 --- a/drivers/entropy/entropy_nrf5.c +++ b/drivers/entropy/entropy_nrf5.c @@ -116,6 +116,10 @@ static int random_byte_get(void) return retval; } +#pragma GCC push_options +#if defined(CONFIG_BT_CTLR_FAST_ENC) +#pragma GCC optimize ("Ofast") +#endif static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, uint16_t len) { uint32_t last = rngp->last; @@ -171,6 +175,7 @@ static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, uint16_t len) return len; } +#pragma GCC pop_options static int rng_pool_put(struct rng_pool *rngp, uint8_t byte) { diff --git a/drivers/entropy/entropy_smartbond.c b/drivers/entropy/entropy_smartbond.c index 28b6f08e100..0058baafce5 100644 --- a/drivers/entropy/entropy_smartbond.c +++ b/drivers/entropy/entropy_smartbond.c @@ -100,6 +100,10 @@ static int random_word_get(uint8_t buf[4]) return retval; } +#pragma GCC push_options +#if defined(CONFIG_BT_CTLR_FAST_ENC) +#pragma GCC optimize("Ofast") +#endif static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, uint16_t len) { uint32_t last = rngp->last; @@ -155,6 +159,7 @@ static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, uint16_t len) return len; } +#pragma GCC pop_options static int rng_pool_put(struct rng_pool *rngp, uint8_t byte) { diff --git a/drivers/entropy/entropy_stm32.c b/drivers/entropy/entropy_stm32.c index 7c342a09c23..9f2ad136203 100644 --- a/drivers/entropy/entropy_stm32.c +++ b/drivers/entropy/entropy_stm32.c @@ -377,7 +377,13 @@ static void pool_filling_work_handler(struct k_work *work) } } -static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, +#if defined(CONFIG_BT_CTLR_FAST_ENC) +#define __fast __attribute__((optimize("Ofast"))) +#else +#define __fast +#endif + +__fast static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, uint16_t len) { uint32_t last = rngp->last; @@ -442,6 +448,7 @@ static uint16_t rng_pool_get(struct rng_pool *rngp, uint8_t *buf, return len; } +#undef __fast static int rng_pool_put(struct rng_pool *rngp, uint8_t byte) { diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index e2975107f86..a7dade7a1db 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -760,6 +760,18 @@ config BT_CTLR_PARAM_CHECK if BT_CONN +config BT_CTLR_FAST_ENC + bool "Fast Encryption Setup" + depends on BT_CTLR_LE_ENC + default y if BT_HCI_RAW + help + Enable connection encryption setup in 4 connection events. + Peripheral will respond to Encryption Request with Encryption Response + in the next connection event, and will transmit Start Encryption + Request PDU in the same connection event, hence completing encryption + setup in 4 connection events. Encrypted data would be transmitted as + fast as in 4th connection event from Encryption Request. + config BT_CTLR_LLCP_CONN int "Number of connections with worst-case overlapping procedures" default BT_MAX_CONN diff --git a/tests/bluetooth/init/prj_ctlr_4_0.conf b/tests/bluetooth/init/prj_ctlr_4_0.conf index 4f9ec70d3bb..ff3917be54b 100644 --- a/tests/bluetooth/init/prj_ctlr_4_0.conf +++ b/tests/bluetooth/init/prj_ctlr_4_0.conf @@ -19,6 +19,7 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=y CONFIG_BT_CTLR_SCHED_ADVANCED=y CONFIG_BT_CTLR_RADIO_ENABLE_FAST=n CONFIG_BT_CTLR_TIFS_HW=y +CONFIG_BT_CTLR_FAST_ENC=n CONFIG_BT_CTLR_CONN_RSSI=n CONFIG_BT_CTLR_ADV_INDICATION=n CONFIG_BT_CTLR_SCAN_REQ_NOTIFY=n diff --git a/tests/bluetooth/init/prj_ctlr_4_0_dbg.conf b/tests/bluetooth/init/prj_ctlr_4_0_dbg.conf index 5fc61cf98c6..4c101cc6e16 100644 --- a/tests/bluetooth/init/prj_ctlr_4_0_dbg.conf +++ b/tests/bluetooth/init/prj_ctlr_4_0_dbg.conf @@ -21,6 +21,7 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=y CONFIG_BT_CTLR_SCHED_ADVANCED=y CONFIG_BT_CTLR_RADIO_ENABLE_FAST=n CONFIG_BT_CTLR_TIFS_HW=y +CONFIG_BT_CTLR_FAST_ENC=n CONFIG_BT_CTLR_CONN_RSSI=n CONFIG_BT_CTLR_ADV_INDICATION=n CONFIG_BT_CTLR_SCAN_REQ_NOTIFY=n diff --git a/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf b/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf index 50f72889476..df0d006a13e 100644 --- a/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf +++ b/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf @@ -29,6 +29,7 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=n CONFIG_BT_CTLR_SCHED_ADVANCED=y CONFIG_BT_CTLR_RADIO_ENABLE_FAST=y CONFIG_BT_CTLR_TIFS_HW=n +CONFIG_BT_CTLR_FAST_ENC=y CONFIG_BT_CTLR_TX_RETRY_DISABLE=y CONFIG_BT_CTLR_CONN_RSSI=y CONFIG_BT_CTLR_ADV_INDICATION=y diff --git a/tests/bluetooth/init/prj_ctlr_dbg.conf b/tests/bluetooth/init/prj_ctlr_dbg.conf index 2f8224cdfea..6aff0965ce9 100644 --- a/tests/bluetooth/init/prj_ctlr_dbg.conf +++ b/tests/bluetooth/init/prj_ctlr_dbg.conf @@ -23,6 +23,7 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=n CONFIG_BT_CTLR_SCHED_ADVANCED=n CONFIG_BT_CTLR_RADIO_ENABLE_FAST=y CONFIG_BT_CTLR_TIFS_HW=n +CONFIG_BT_CTLR_FAST_ENC=y CONFIG_BT_CTLR_TX_RETRY_DISABLE=y CONFIG_BT_CTLR_CONN_RSSI=y CONFIG_BT_CTLR_ADV_INDICATION=y diff --git a/tests/bluetooth/init/prj_ctlr_ticker.conf b/tests/bluetooth/init/prj_ctlr_ticker.conf index 4e5b962231e..d77f519406b 100644 --- a/tests/bluetooth/init/prj_ctlr_ticker.conf +++ b/tests/bluetooth/init/prj_ctlr_ticker.conf @@ -23,6 +23,7 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=n CONFIG_BT_CTLR_SCHED_ADVANCED=n CONFIG_BT_CTLR_RADIO_ENABLE_FAST=y CONFIG_BT_CTLR_TIFS_HW=n +CONFIG_BT_CTLR_FAST_ENC=y CONFIG_BT_CTLR_TX_RETRY_DISABLE=y CONFIG_BT_CTLR_CONN_RSSI=y CONFIG_BT_CTLR_ADV_INDICATION=y diff --git a/tests/bluetooth/init/prj_ctlr_tiny.conf b/tests/bluetooth/init/prj_ctlr_tiny.conf index ce75583da16..7679de9a661 100644 --- a/tests/bluetooth/init/prj_ctlr_tiny.conf +++ b/tests/bluetooth/init/prj_ctlr_tiny.conf @@ -22,6 +22,7 @@ CONFIG_BT_CTLR_XTAL_ADVANCED=n CONFIG_BT_CTLR_SCHED_ADVANCED=n CONFIG_BT_CTLR_RADIO_ENABLE_FAST=n CONFIG_BT_CTLR_TIFS_HW=y +CONFIG_BT_CTLR_FAST_ENC=n CONFIG_BT_CTLR_CONN_RSSI=n CONFIG_BT_CTLR_ADV_INDICATION=n CONFIG_BT_CTLR_SCAN_REQ_NOTIFY=n From fb0d500cd1fd5304ff35bdbdc58647d99a1a1bc5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:54 +0000 Subject: [PATCH 0663/1623] Revert "[nrf fromtree] Bluetooth: Controller: Add hdl checks in isoal.c" This reverts commit cc06a1088c2186089719036a62762adb9a2d9585. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/isoal.c | 78 ++++++----------------- 1 file changed, 21 insertions(+), 57 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index 48ad0835074..d43233f0289 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -226,17 +226,8 @@ static isoal_status_t isoal_sink_allocate(isoal_sink_handle_t *hdl) */ static void isoal_sink_deallocate(isoal_sink_handle_t hdl) { - if (hdl < ARRAY_SIZE(isoal_global.sink_allocated)) { - isoal_global.sink_allocated[hdl] = ISOAL_ALLOC_STATE_FREE; - } else { - LL_ASSERT(0); - } - - if (hdl < ARRAY_SIZE(isoal_global.sink_state)) { - (void)memset(&isoal_global.sink_state[hdl], 0, sizeof(struct isoal_sink)); - } else { - LL_ASSERT(0); - } + isoal_global.sink_allocated[hdl] = ISOAL_ALLOC_STATE_FREE; + (void)memset(&isoal_global.sink_state[hdl], 0, sizeof(struct isoal_sink)); } /** @@ -374,16 +365,12 @@ isoal_status_t isoal_sink_create( */ void isoal_sink_enable(isoal_sink_handle_t hdl) { - if (hdl < ARRAY_SIZE(isoal_global.sink_state)) { - /* Reset bookkeeping state */ - memset(&isoal_global.sink_state[hdl].sdu_production, 0, - sizeof(isoal_global.sink_state[hdl].sdu_production)); + /* Reset bookkeeping state */ + memset(&isoal_global.sink_state[hdl].sdu_production, 0, + sizeof(isoal_global.sink_state[hdl].sdu_production)); - /* Atomically enable */ - isoal_global.sink_state[hdl].sdu_production.mode = ISOAL_PRODUCTION_MODE_ENABLED; - } else { - LL_ASSERT(0); - } + /* Atomically enable */ + isoal_global.sink_state[hdl].sdu_production.mode = ISOAL_PRODUCTION_MODE_ENABLED; } /** @@ -392,12 +379,8 @@ void isoal_sink_enable(isoal_sink_handle_t hdl) */ void isoal_sink_disable(isoal_sink_handle_t hdl) { - if (hdl < ARRAY_SIZE(isoal_global.sink_state)) { - /* Atomically disable */ - isoal_global.sink_state[hdl].sdu_production.mode = ISOAL_PRODUCTION_MODE_DISABLED; - } else { - LL_ASSERT(0); - } + /* Atomically disable */ + isoal_global.sink_state[hdl].sdu_production.mode = ISOAL_PRODUCTION_MODE_DISABLED; } /** @@ -1459,13 +1442,7 @@ static void isoal_source_deallocate(isoal_source_handle_t hdl) struct isoal_pdu_production *pp; struct isoal_source *source; - if (hdl < ARRAY_SIZE(isoal_global.source_state)) { - source = &isoal_global.source_state[hdl]; - } else { - LL_ASSERT(0); - return; - } - + source = &isoal_global.source_state[hdl]; pp = &source->pdu_production; if (pp->pdu_available > 0) { @@ -1477,13 +1454,8 @@ static void isoal_source_deallocate(isoal_source_handle_t hdl) } } - if (hdl < ARRAY_SIZE(isoal_global.source_allocated)) { - isoal_global.source_allocated[hdl] = ISOAL_ALLOC_STATE_FREE; - } else { - LL_ASSERT(0); - } - - (void)memset(source, 0, sizeof(struct isoal_source)); + isoal_global.source_allocated[hdl] = ISOAL_ALLOC_STATE_FREE; + (void)memset(&isoal_global.source_state[hdl], 0, sizeof(struct isoal_source)); } /** @@ -1493,8 +1465,8 @@ static void isoal_source_deallocate(isoal_source_handle_t hdl) */ static isoal_status_t isoal_check_source_hdl_valid(isoal_source_handle_t hdl) { - if (hdl < ARRAY_SIZE(isoal_global.source_allocated) && - isoal_global.source_allocated[hdl] == ISOAL_ALLOC_STATE_TAKEN) { + if (hdl < CONFIG_BT_CTLR_ISOAL_SOURCES && + isoal_global.source_allocated[hdl] == ISOAL_ALLOC_STATE_TAKEN) { return ISOAL_STATUS_OK; } @@ -1588,16 +1560,12 @@ isoal_status_t isoal_source_create( */ void isoal_source_enable(isoal_source_handle_t hdl) { - if (hdl < ARRAY_SIZE(isoal_global.source_state)) { - /* Reset bookkeeping state */ - memset(&isoal_global.source_state[hdl].pdu_production, 0, - sizeof(isoal_global.source_state[hdl].pdu_production)); + /* Reset bookkeeping state */ + memset(&isoal_global.source_state[hdl].pdu_production, 0, + sizeof(isoal_global.source_state[hdl].pdu_production)); - /* Atomically enable */ - isoal_global.source_state[hdl].pdu_production.mode = ISOAL_PRODUCTION_MODE_ENABLED; - } else { - LL_ASSERT(0); - } + /* Atomically enable */ + isoal_global.source_state[hdl].pdu_production.mode = ISOAL_PRODUCTION_MODE_ENABLED; } /** @@ -1606,12 +1574,8 @@ void isoal_source_enable(isoal_source_handle_t hdl) */ void isoal_source_disable(isoal_source_handle_t hdl) { - if (hdl < ARRAY_SIZE(isoal_global.source_state)) { - /* Atomically disable */ - isoal_global.source_state[hdl].pdu_production.mode = ISOAL_PRODUCTION_MODE_DISABLED; - } else { - LL_ASSERT(0); - } + /* Atomically disable */ + isoal_global.source_state[hdl].pdu_production.mode = ISOAL_PRODUCTION_MODE_DISABLED; } /** From 371642eb781651216399a73e2f3c696d5d81c366 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:54 +0000 Subject: [PATCH 0664/1623] Revert "[nrf fromtree] Bluetooth: Controller: Make aa in radio_aa_set const" This reverts commit 9e70b2847662239880a1d0f6b69bde41298fbea7. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c | 2 +- subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h | 2 +- .../bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.c | 2 +- .../bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index c6becbe322f..a657ab95dfe 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -382,7 +382,7 @@ void radio_whiten_iv_set(uint32_t iv) RADIO_PCNF1_WHITEEN_Msk; } -void radio_aa_set(const uint8_t *aa) +void radio_aa_set(uint8_t *aa) { NRF_RADIO->TXADDRESS = (((0UL) << RADIO_TXADDRESS_TXADDRESS_Pos) & diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h index fc355af1edc..4bf833b233a 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h @@ -70,7 +70,7 @@ int8_t radio_tx_power_max_get(void); int8_t radio_tx_power_floor(int8_t power); void radio_freq_chan_set(uint32_t chan); void radio_whiten_iv_set(uint32_t iv); -void radio_aa_set(const uint8_t *aa); +void radio_aa_set(uint8_t *aa); void radio_pkt_configure(uint8_t bits_len, uint8_t max_len, uint8_t flags); void radio_pkt_rx_set(void *rx_packet); void radio_pkt_tx_set(void *tx_packet); diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.c b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.c index ecdf17bbe43..6107bfc9c68 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.c @@ -684,7 +684,7 @@ void radio_whiten_iv_set(uint32_t iv) GENFSK->WHITEN_SZ_THR |= GENFSK_WHITEN_SZ_THR_WHITEN_SZ_THR(0); } -void radio_aa_set(const uint8_t *aa) +void radio_aa_set(uint8_t *aa) { /* Configure Access Address detection using NETWORK ADDRESS 0 */ GENFSK->NTW_ADR_0 = *((uint32_t *)aa); diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.h b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.h index cc3fda99964..1168804bbd5 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.h +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/radio/radio.h @@ -20,7 +20,7 @@ void radio_tx_power_set(uint32_t power); void radio_tx_power_max_set(void); void radio_freq_chan_set(uint32_t chan); void radio_whiten_iv_set(uint32_t iv); -void radio_aa_set(const uint8_t *aa); +void radio_aa_set(uint8_t *aa); void radio_pkt_configure(uint8_t bits_len, uint8_t max_len, uint8_t flags); void radio_pkt_rx_set(void *rx_packet); void radio_pkt_tx_set(void *tx_packet); From 69ecd28a43c340bc577e30efbd60b1ea6a40f635 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:54 +0000 Subject: [PATCH 0665/1623] Revert "[nrf fromtree] Bluetooth: controller: fix comparision of unsigned int to 0" This reverts commit 4eefd65d6bebfcfbb64b0a2fa0b3aa6c882d2452. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_iso_types.h | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_iso_types.h b/subsys/bluetooth/controller/ll_sw/ull_iso_types.h index 457ad1d2458..18d9a0f7bfe 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_iso_types.h +++ b/subsys/bluetooth/controller/ll_sw/ull_iso_types.h @@ -9,18 +9,11 @@ #define LL_BIS_ADV_HANDLE_BASE BT_CTLR_ADV_ISO_STREAM_HANDLE_BASE #define LL_BIS_ADV_IDX_FROM_HANDLE(conn_handle) \ ((conn_handle) - (LL_BIS_ADV_HANDLE_BASE)) -/* Conditional compile to prevent coverity issue CWE570, comparison of unsigned int to 0 */ -#if (LL_BIS_ADV_HANDLE_BASE > 0) #define IS_ADV_ISO_HANDLE(conn_handle) \ (((conn_handle) >= (LL_BIS_ADV_HANDLE_BASE)) && \ ((conn_handle) <= ((LL_BIS_ADV_HANDLE_BASE) + \ (BT_CTLR_ADV_ISO_STREAM_MAX) - 1U))) #else -#define IS_ADV_ISO_HANDLE(conn_handle) \ - ((conn_handle) <= ((LL_BIS_ADV_HANDLE_BASE) + \ - (BT_CTLR_ADV_ISO_STREAM_MAX) - 1U)) -#endif /* LL_BIS_ADV_HANDLE_BASE */ -#else #define LL_BIS_ADV_IDX_FROM_HANDLE(conn_handle) 0U #define IS_ADV_ISO_HANDLE(conn_handle) 0U #endif /* CONFIG_BT_CTLR_ADV_ISO */ @@ -30,18 +23,11 @@ #define LL_BIS_SYNC_HANDLE_BASE BT_CTLR_SYNC_ISO_STREAM_HANDLE_BASE #define LL_BIS_SYNC_IDX_FROM_HANDLE(conn_handle) \ ((conn_handle) - (LL_BIS_SYNC_HANDLE_BASE)) -/* Conditional compile to prevent coverity issue CWE570, comparison of unsigned int to 0 */ -#if (LL_BIS_SYNC_HANDLE_BASE > 0) #define IS_SYNC_ISO_HANDLE(conn_handle) \ (((conn_handle) >= (LL_BIS_SYNC_HANDLE_BASE)) && \ ((conn_handle) <= ((LL_BIS_SYNC_HANDLE_BASE) + \ (BT_CTLR_SYNC_ISO_STREAM_MAX) - 1U))) #else -#define IS_SYNC_ISO_HANDLE(conn_handle) \ - ((conn_handle) <= ((LL_BIS_SYNC_HANDLE_BASE) + \ - (BT_CTLR_SYNC_ISO_STREAM_MAX) - 1U)) -#endif /* LL_BIS_SYNC_HANDLE_BASE */ -#else #define LL_BIS_SYNC_IDX_FROM_HANDLE(conn_handle) 0U #define IS_SYNC_ISO_HANDLE(conn_handle) 0U #endif /* CONFIG_BT_CTLR_SYNC_ISO */ From 45fac94fbd2ab945a79d6de5495c71c2d7e17725 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:55 +0000 Subject: [PATCH 0666/1623] Revert "[nrf fromtree] Bluetooth: Controll: Fix dead code in ll_setup_iso_path" This reverts commit 5e6ae9f1a206335f50da010532f106693e189ffa. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_iso.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_iso.c b/subsys/bluetooth/controller/ll_sw/ull_iso.c index b21a9d20721..70d018e7e0c 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_iso.c @@ -491,11 +491,11 @@ uint8_t ll_setup_iso_path(uint16_t handle, uint8_t path_dir, uint8_t path_id, pdu_release, &source_handle); if (!err) { - if (IS_ENABLED(CONFIG_BT_CTLR_CONN_ISO) && cis != NULL) { + if (cis) { cis->hdr.datapath_in = dp; } - if (IS_ENABLED(CONFIG_BT_CTLR_ADV_ISO) && adv_stream != NULL) { + if (adv_stream) { adv_stream->dp = dp; } From 53d8965698cd83fb790ed3748717c3bf7667cea0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:55 +0000 Subject: [PATCH 0667/1623] Revert "[nrf fromtree] Bluetooth: Controller: Remove unused terminate_ack" This reverts commit 49afbcceeb53e75ca2be62e895b2b18bd5742993. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_central.c | 2 ++ subsys/bluetooth/controller/ll_sw/ull_conn.c | 6 ++++++ subsys/bluetooth/controller/ll_sw/ull_conn_types.h | 1 + 3 files changed, 9 insertions(+) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central.c b/subsys/bluetooth/controller/ll_sw/ull_central.c index 7ea3c600ea6..b189c65fa21 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central.c @@ -291,6 +291,8 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, /* Setup the PRT reload */ ull_cp_prt_reload_set(conn, conn_interval_us); + conn->central.terminate_ack = 0U; + conn->llcp_terminate.reason_final = 0U; /* NOTE: use allocated link for generating dedicated * terminate ind rx node diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 1640c00e87e..9d78af7acc1 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -1044,6 +1044,12 @@ void ull_conn_done(struct node_rx_event_done *done) lll->latency_event = lll->latency; } #endif /* CONFIG_BT_PERIPHERAL */ + +#if defined(CONFIG_BT_CENTRAL) + } else if (reason_final) { + conn->central.terminate_ack = 1; +#endif /* CONFIG_BT_CENTRAL */ + } /* Reset connection failed to establish countdown */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_types.h b/subsys/bluetooth/controller/ll_sw/ull_conn_types.h index 8fabab03378..12e16488f38 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_types.h +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_types.h @@ -202,6 +202,7 @@ struct ll_conn { #if defined(CONFIG_BT_CTLR_CONN_META) uint8_t is_must_expire:1; #endif /* CONFIG_BT_CTLR_CONN_META */ + uint8_t terminate_ack:1; } central; #endif /* CONFIG_BT_CENTRAL */ }; From 85c1d711308d56d5a8086392ca76849b6253032c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:55 +0000 Subject: [PATCH 0668/1623] Revert "[nrf fromtree] Bluetooth: Controller: Review rework flush timeout support" This reverts commit a96ce9920c747042b8d5bd3a86c2a854c8e49706. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/hci/hci.c | 44 +--- .../bluetooth/controller/ll_sw/lll_conn_iso.h | 28 +-- .../ll_sw/nordic/lll/lll_central_iso.c | 19 +- .../ll_sw/nordic/lll/lll_peripheral_iso.c | 8 - tests/bsim/bluetooth/ll/cis/src/main.c | 206 +++++++++--------- ...onnected_iso_acl_first_ft_cen_skip_2_se.sh | 2 +- ...onnected_iso_acl_first_ft_per_skip_2_se.sh | 2 +- 7 files changed, 128 insertions(+), 181 deletions(-) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index c3dd070720b..b2c95271b2c 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -5762,18 +5762,6 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) /* Catch up local pkt_seq_num with internal pkt_seq_num */ event_count = cis->lll.event_count; pkt_seq_num = event_count + 1U; - /* If pb_flag is BT_ISO_START (0b00) or BT_ISO_SINGLE (0b10) - * then we simply check that the pb_flag is an even value, and - * then pkt_seq_num is a future sequence number value compare - * to last recorded number in cis->pkt_seq_num. - * - * When (pkt_seq_num - stream->pkt_seq_num) is negative then - * BIT64(39) will be set (2's compliment value). The diff value - * less than or equal to BIT64_MASK(38) means the diff value is - * positive and hence pkt_seq_num is greater than - * stream->pkt_seq_num. This calculation is valid for when value - * rollover too. - */ if (!(pb_flag & 0x01) && (((pkt_seq_num - cis->pkt_seq_num) & BIT64_MASK(39)) <= BIT64_MASK(38))) { @@ -5782,17 +5770,12 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) pkt_seq_num = cis->pkt_seq_num; } - /* Pre-increment, when pg_flag is BT_ISO_SINGLE (0b10) or - * BT_ISO_END (0b11) then we simple check if pb_flag has bit 1 - * is set, for next ISO data packet seq num comparison. - */ + /* Pre-increment, for next ISO data packet seq num comparison */ if (pb_flag & 0x10) { cis->pkt_seq_num++; } - /* Target next ISO event to avoid overlapping with, if any, - * current ISO event - */ + /* Target next event to avoid overlapping with current event */ pkt_seq_num++; sdu_frag_tx.target_event = pkt_seq_num; sdu_frag_tx.grp_ref_point = @@ -5834,7 +5817,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) #endif /* !CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ /* Get controller's input data path for CIS */ - hdr = &cis->hdr; + hdr = &(cis->hdr); dp_in = hdr->datapath_in; if (!dp_in || dp_in->path_id != BT_HCI_DATAPATH_ID_HCI) { LOG_ERR("Input data path not set for HCI"); @@ -5901,18 +5884,6 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) /* Catch up local pkt_seq_num with internal pkt_seq_num */ event_count = lll_iso->payload_count / lll_iso->bn; pkt_seq_num = event_count; - /* If pb_flag is BT_ISO_START (0b00) or BT_ISO_SINGLE (0b10) - * then we simply check that the pb_flag is an even value, and - * then pkt_seq_num is a future sequence number value compare - * to last recorded number in cis->pkt_seq_num. - * - * When (pkt_seq_num - stream->pkt_seq_num) is negative then - * BIT64(39) will be set (2's compliment value). The diff value - * less than or equal to BIT64_MASK(38) means the diff value is - * positive and hence pkt_seq_num is greater than - * stream->pkt_seq_num. This calculation is valid for when value - * rollover too. - */ if (!(pb_flag & 0x01) && (((pkt_seq_num - stream->pkt_seq_num) & BIT64_MASK(39)) <= BIT64_MASK(38))) { @@ -5921,17 +5892,12 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) pkt_seq_num = stream->pkt_seq_num; } - /* Pre-increment, when pg_flag is BT_ISO_SINGLE (0b10) or - * BT_ISO_END (0b11) then we simple check if pb_flag has bit 1 - * is set, for next ISO data packet seq num comparison. - */ + /* Pre-increment, for next ISO data packet seq num comparison */ if (pb_flag & 0x10) { stream->pkt_seq_num++; } - /* Target next ISO event to avoid overlapping with, if any, - * current ISO event - */ + /* Target next event to avoid overlapping with current event */ /* FIXME: Implement ISO Tx ack generation early in done compared * to currently only in prepare. I.e. to ensure upper * layer has the number of completed packet before the diff --git a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h index 8a85ca7c6c9..0321b96f638 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h +++ b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h @@ -15,10 +15,8 @@ struct lll_conn_iso_stream_rxtx { uint64_t ft:8; /* Flush timeout (FT) */ uint64_t bn:4; /* Burst number (BN) */ uint64_t phy:3; /* PHY */ - uint64_t rfu0:1; - - uint8_t bn_curr:4; /* Current burst number */ - uint8_t rfu1:4; + uint64_t rfu:1; + uint8_t bn_curr:4; /* Current burst number */ #if defined(CONFIG_BT_CTLR_LE_ENC) struct ccm ccm; @@ -75,26 +73,20 @@ struct lll_conn_iso_group { struct lll_hdr hdr; uint16_t handle; /* CIG handle (internal) */ + uint8_t num_cis:5; /* Number of CISes in this CIG */ + uint8_t role:1; /* 0: CENTRAL, 1: PERIPHERAL*/ + uint8_t paused:1; /* 1: CIG is paused */ - /* Resumption information */ - uint16_t resume_cis; /* CIS handle to schedule at resume */ - - /* ISO group information */ - uint32_t num_cis:5; /* Number of CISes in this CIG */ - uint32_t role:1; /* 0: CENTRAL, 1: PERIPHERAL*/ - uint32_t paused:1; /* 1: CIG is paused */ - uint32_t rfu0:1; - - /* ISO interval to calculate timestamp under FT > 1, - * maximum ISO interval of 4 seconds can be represented in 22-bits. - */ - uint32_t iso_interval_us:22; - uint32_t rfu1:2; + /* ISO interval to calculate timestamp under FT > 1 */ + uint32_t iso_interval_us; /* Accumulates LLL prepare callback latencies */ uint16_t latency_prepare; uint16_t latency_event; + /* Resumption information */ + uint16_t resume_cis; /* CIS handle to schedule at resume */ + #if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) /* Window widening. Relies on vendor specific conversion macros, e.g. * EVENT_US_FRAC_TO_TICKS(). diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 751c3915fc2..9c2184b9942 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -48,7 +48,7 @@ static void isr_prepare_subevent(void *param); static void isr_done(void *param); static void payload_count_flush(struct lll_conn_iso_stream *cis_lll); static void payload_count_flush_or_inc_on_close(struct lll_conn_iso_stream *cis_lll); -static void payload_count_lazy_update(struct lll_conn_iso_stream *cis_lll, uint16_t lazy); +static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy); static uint16_t next_cis_chan_remap_idx; static uint16_t next_cis_chan_prn_s; @@ -183,7 +183,7 @@ static int prepare_cb(struct lll_prepare_param *p) se_curr = 1U; /* Adjust the SN and NESN for skipped CIG events */ - payload_count_lazy_update(cis_lll, lazy); + payload_count_lazy(cis_lll, lazy); /* Start setting up of Radio h/w */ radio_reset(); @@ -370,7 +370,7 @@ static int prepare_cb(struct lll_prepare_param *p) cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); if (cis_lll && cis_lll->active) { /* Adjust sn and nesn for skipped CIG events */ - payload_count_lazy_update(cis_lll, lazy); + payload_count_lazy(cis_lll, lazy); /* Adjust sn and nesn for canceled events */ if (err) { @@ -676,20 +676,11 @@ static void isr_rx(void *param) /* No Rx */ if (!trx_done || #if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) - /* Used by test code, - * to skip a number of events in every 3 event count when current subevent is less than - * or equal to 2 or when current subevent has completed all its NSE number of subevents. - * OR - * to skip a (number + 1) of events in every 3 event count when current subevent is less - * than or equal to 1 or when current subevent has completed all its NSE number of - * subevents. - */ ((((cis_lll->event_count % 3U) < CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT) && ((se_curr > cis_lll->nse) || (se_curr <= 2U))) || - (((cis_lll->event_count % 3U) < (CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT + 1U)) && ((se_curr > cis_lll->nse) || (se_curr <= 1U)))) || -#endif /* CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS */ +#endif false) { payload_count_flush(cis_lll); @@ -1239,7 +1230,7 @@ static void payload_count_flush_or_inc_on_close(struct lll_conn_iso_stream *cis_ } } -static void payload_count_lazy_update(struct lll_conn_iso_stream *cis_lll, uint16_t lazy) +static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy) { if (cis_lll->tx.bn) { uint16_t tx_lazy; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 27ed4d1e42c..c33c82d4c70 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -474,14 +474,6 @@ static void isr_rx(void *param) /* No Rx */ if (!trx_done || #if defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) - /* Used by test code, - * to skip a number of events in every 3 event count when current subevent is less than - * or equal to 2 or when current subevent has completed all its NSE number of subevents. - * OR - * to skip a (number + 1) of events in every 3 event count when current subevent is less - * than or equal to 1 or when current subevent has completed all its NSE number of - * subevents. - */ ((((cis_lll->event_count % 3U) < CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT) && ((se_curr > cis_lll->nse) || (se_curr <= 2U))) || (((cis_lll->event_count % 3U) < (CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT + 1U)) && diff --git a/tests/bsim/bluetooth/ll/cis/src/main.c b/tests/bsim/bluetooth/ll/cis/src/main.c index b544546a404..15e102981d6 100644 --- a/tests/bsim/bluetooth/ll/cis/src/main.c +++ b/tests/bsim/bluetooth/ll/cis/src/main.c @@ -352,7 +352,7 @@ static void test_cis_central(void) struct bt_conn *conn_list[CONFIG_BT_MAX_CONN]; struct bt_iso_cig_param cig_param; struct bt_iso_cig *cig; - int conn_count; + uint8_t conn_count; int err; printk("Bluetooth initializing..."); @@ -370,12 +370,12 @@ static void test_cis_central(void) for (int i = 0; i < CONFIG_BT_ISO_MAX_CHAN; i++) { iso_tx[i].sdu = CONFIG_BT_ISO_TX_MTU; iso_tx[i].phy = BT_GAP_LE_PHY_2M; - iso_tx[i].path = NULL; if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { iso_tx[i].rtn = 2U; } else { iso_tx[i].rtn = 0U; } + iso_tx[i].path = NULL; if (!IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS) || IS_ENABLED(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS)) { @@ -386,12 +386,12 @@ static void test_cis_central(void) iso_rx[i].sdu = CONFIG_BT_ISO_RX_MTU; iso_rx[i].phy = BT_GAP_LE_PHY_2M; - iso_rx[i].path = NULL; if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { iso_rx[i].rtn = 2U; } else { iso_rx[i].rtn = 0U; } + iso_rx[i].path = NULL; if (IS_ENABLED(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS)) { iso_qos[i].rx = &iso_rx[i]; @@ -413,12 +413,12 @@ static void test_cis_central(void) cig_param.sca = BT_GAP_SCA_UNKNOWN; cig_param.packing = 0U; cig_param.framing = 0U; - cig_param.interval = ISO_INTERVAL_US; if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { cig_param.latency = ISO_LATENCY_FT_MS; } else { cig_param.latency = ISO_LATENCY_MS; } + cig_param.interval = ISO_INTERVAL_US; printk("Create CIG..."); err = bt_iso_cig_create(&cig_param, &cig); @@ -428,10 +428,10 @@ static void test_cis_central(void) } printk("success.\n"); - conn_count = 0; + conn_count = 0U; #if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) - for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { expected_seq_num[chan] = (CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT - 1U) * 2U; } #endif @@ -443,8 +443,8 @@ static void test_cis_central(void) #endif struct bt_conn *conn; - int conn_index; - int chan; + uint8_t conn_index; + uint8_t chan; printk("Start scanning (%d)...", i); err = bt_le_scan_start(BT_LE_SCAN_CUSTOM, NULL); @@ -494,12 +494,12 @@ static void test_cis_central(void) #if defined(CONFIG_TEST_CONNECT_ACL_FIRST) } - for (int chan = 0, conn_index = 0; + for (uint8_t chan = 0U, conn_index = 0U; (conn_index < conn_count) && (chan < CONFIG_BT_ISO_MAX_CHAN); conn_index++, chan++) { #elif defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) - for (int chan = 0, conn_index = 0; + for (uint8_t chan = 0U, conn_index = 0U; (chan < CONFIG_BT_ISO_MAX_CHAN); chan++) { #endif @@ -523,67 +523,70 @@ static void test_cis_central(void) printk("connected to peer %d ISO channel.\n", chan); } - if (!IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS) || - IS_ENABLED(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS)) { - for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { - - for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { - uint8_t iso_data[CONFIG_BT_ISO_TX_MTU] = { 0, }; - struct net_buf *buf; - int ret; - - buf = net_buf_alloc(&tx_pool, K_MSEC(BUF_ALLOC_TIMEOUT)); - if (!buf) { - FAIL("Data buffer allocate timeout on channel %d\n", chan); - return; - } - - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - sys_put_le16(seq_num, iso_data); - net_buf_add_mem(buf, iso_data, sizeof(iso_data)); - - ret = k_sem_take(&sem_iso_data, K_MSEC(BUF_ALLOC_TIMEOUT)); - if (ret) { - FAIL("k_sem_take for ISO data sent failed.\n"); - return; - } - - printk("ISO send: seq_num %u, chan %d\n", seq_num, chan); - ret = bt_iso_chan_send(&iso_chan[chan], buf, - seq_num, BT_ISO_TIMESTAMP_NONE); - if (ret < 0) { - FAIL("Unable to send data on channel %d : %d\n", chan, ret); - net_buf_unref(buf); - return; - } +#if !defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) || defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) + for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { + + for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + uint8_t iso_data[CONFIG_BT_ISO_TX_MTU] = { 0, }; + struct net_buf *buf; + int ret; + + buf = net_buf_alloc(&tx_pool, + K_MSEC(BUF_ALLOC_TIMEOUT)); + if (!buf) { + FAIL("Data buffer allocate timeout on channel" + " %u\n", chan); + return; + } + net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); + sys_put_le32(seq_num, iso_data); + net_buf_add_mem(buf, iso_data, sizeof(iso_data)); + + ret = k_sem_take(&sem_iso_data, + K_MSEC(BUF_ALLOC_TIMEOUT)); + if (ret) { + FAIL("k_sem_take for ISO data sent failed.\n"); + return; } - if ((seq_num % 100) == 0) { - printk("Sending value %u\n", seq_num); + printk("ISO send: seq_num %u, chan %u\n", seq_num, chan); + ret = bt_iso_chan_send(&iso_chan[chan], buf, + seq_num, BT_ISO_TIMESTAMP_NONE); + if (ret < 0) { + FAIL("Unable to send data on channel %u" + " : %d\n", chan, ret); + net_buf_unref(buf); + return; } } - k_sleep(K_MSEC(1000)); - } else { - k_sleep(K_SECONDS(11)); + if ((seq_num % 100) == 0) { + printk("Sending value %u\n", seq_num); + } } - for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { - printk("ISO disconnect channel %d...", chan); + k_sleep(K_MSEC(1000)); +#else + k_sleep(K_SECONDS(11)); +#endif + + for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + printk("ISO disconnect channel %u...", chan); err = bt_iso_chan_disconnect(&iso_chan[chan]); if (err) { - FAIL("Failed to disconnect channel %d (%d)\n", chan, err); + FAIL("Failed to disconnect channel %u (%d)\n", + chan, err); return; } printk("success\n"); - printk("Waiting for ISO channel disconnect %d...", chan); + printk("Waiting for ISO channel disconnect %u...", chan); err = k_sem_take(&sem_iso_disc, K_FOREVER); if (err) { FAIL("failed (err %d)\n", err); return; } - printk("disconnected to peer %d ISO channel.\n", chan); + printk("disconnected to peer %u ISO channel.\n", chan); } bt_conn_foreach(BT_CONN_TYPE_LE, disconnect, NULL); @@ -604,15 +607,15 @@ static void test_cis_central(void) } #endif - if (IS_ENABLED(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS)) { - for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { - if (expected_seq_num[chan] < SEQ_NUM_MAX) { - FAIL("ISO Data reception incomplete %u (%u).\n", - expected_seq_num[chan], SEQ_NUM_MAX); - return; - } +#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) + for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + if (expected_seq_num[chan] < SEQ_NUM_MAX) { + FAIL("ISO Data reception incomplete %u (%u).\n", + expected_seq_num[chan], SEQ_NUM_MAX); + return; } } +#endif PASS("Central ISO tests Passed\n"); } @@ -668,12 +671,12 @@ static void test_cis_peripheral(void) for (int i = 0; i < CONFIG_BT_ISO_MAX_CHAN; i++) { iso_tx_p[i].sdu = CONFIG_BT_ISO_TX_MTU; iso_tx_p[i].phy = BT_GAP_LE_PHY_2M; - iso_tx_p[i].path = NULL; if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { iso_tx_p[i].rtn = 2U; } else { iso_tx_p[i].rtn = 0U; } + iso_tx_p[i].path = NULL; iso_qos_p[i].tx = &iso_tx_p[i]; @@ -738,7 +741,7 @@ static void test_cis_peripheral(void) printk("connected to peer central.\n"); #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) - for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { #endif printk("Waiting for ISO channel connection..."); @@ -753,47 +756,50 @@ static void test_cis_peripheral(void) } #endif - if (IS_ENABLED(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS)) { - for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { - for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { - uint8_t iso_data[CONFIG_BT_ISO_TX_MTU] = { 0, }; - struct net_buf *buf; - int ret; - - buf = net_buf_alloc(&tx_pool, K_MSEC(BUF_ALLOC_TIMEOUT)); - if (!buf) { - FAIL("Data buffer allocate timeout on channel %d\n", chan); - return; - } - - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - sys_put_le16(seq_num, iso_data); - net_buf_add_mem(buf, iso_data, sizeof(iso_data)); - - ret = k_sem_take(&sem_iso_data, K_MSEC(BUF_ALLOC_TIMEOUT)); - if (ret) { - FAIL("k_sem_take for ISO data sent failed.\n"); - return; - } - - printk("ISO send: seq_num %u, chan %d\n", seq_num, chan); - ret = bt_iso_chan_send(&iso_chan_p[chan], buf, seq_num, - BT_ISO_TIMESTAMP_NONE); - if (ret < 0) { - FAIL("Unable to send data on channel %d : %d\n", chan, ret); - net_buf_unref(buf); - return; - } +#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) + for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { + for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + uint8_t iso_data[CONFIG_BT_ISO_TX_MTU] = { 0, }; + struct net_buf *buf; + int ret; + + buf = net_buf_alloc(&tx_pool, + K_MSEC(BUF_ALLOC_TIMEOUT)); + if (!buf) { + FAIL("Data buffer allocate timeout on channel" + " %u\n", chan); + return; + } + net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); + sys_put_le32(seq_num, iso_data); + net_buf_add_mem(buf, iso_data, sizeof(iso_data)); + + ret = k_sem_take(&sem_iso_data, + K_MSEC(BUF_ALLOC_TIMEOUT)); + if (ret) { + FAIL("k_sem_take for ISO data sent failed.\n"); + return; } - if ((seq_num % 100) == 0) { - printk("Sending value %u\n", seq_num); + printk("ISO send: seq_num %u, chan %u\n", seq_num, chan); + ret = bt_iso_chan_send(&iso_chan_p[chan], buf, + seq_num, BT_ISO_TIMESTAMP_NONE); + if (ret < 0) { + FAIL("Unable to send data on channel %u" + " : %d\n", chan, ret); + net_buf_unref(buf); + return; } } + + if ((seq_num % 100) == 0) { + printk("Sending value %u\n", seq_num); + } } +#endif #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) - for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { #endif printk("Waiting for ISO channel disconnect..."); @@ -818,13 +824,13 @@ static void test_cis_peripheral(void) #if !defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) || defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) - for (int chan = 0; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { + for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { #else - int chan = 0; + uint8_t chan = 0U; #endif if (expected_seq_num[chan] < SEQ_NUM_MAX) { - FAIL("ISO Data reception incomplete %u (%u).\n", expected_seq_num[chan], - SEQ_NUM_MAX); + FAIL("ISO Data reception incomplete %u (%u).\n", + expected_seq_num[chan], SEQ_NUM_MAX); return; } #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) diff --git a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh index bb08f582574..04ce474e812 100755 --- a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh +++ b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA +# Copyright 2020 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 source ${ZEPHYR_BASE}/tests/bsim/sh_common.source diff --git a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh index 84d3c5c4ed3..307d865a117 100755 --- a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh +++ b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA +# Copyright 2020 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 source ${ZEPHYR_BASE}/tests/bsim/sh_common.source From 9721ecaa0749b9b9868f331a571cb90d5a9fb95c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:55 +0000 Subject: [PATCH 0669/1623] Revert "[nrf fromtree] tests: bsim: Bluetooth: Test RTN=2, FT=2, Cen skip 2 SE in Controller" This reverts commit 5e04a9f2a3a99b319901d0eca3cdc361c75acc45. Signed-off-by: Dominik Ermel --- .../ll_sw/nordic/lll/lll_central_iso.c | 9 +- tests/bsim/bluetooth/ll/cis/Kconfig | 13 -- .../overlay-acl_first_ft_cen_skip_2_se.conf | 9 -- tests/bsim/bluetooth/ll/cis/src/main.c | 114 +----------------- ...onnected_iso_acl_first_ft_cen_skip_2_se.sh | 24 ---- tests/bsim/bluetooth/ll/compile.sh | 2 - 6 files changed, 7 insertions(+), 164 deletions(-) delete mode 100644 tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_cen_skip_2_se.conf delete mode 100755 tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 9c2184b9942..4bf44a42cd9 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -674,14 +674,7 @@ static void isr_rx(void *param) cis_lll = param; /* No Rx */ - if (!trx_done || -#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) - ((((cis_lll->event_count % 3U) < CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT) && - ((se_curr > cis_lll->nse) || (se_curr <= 2U))) || - (((cis_lll->event_count % 3U) < (CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT + 1U)) && - ((se_curr > cis_lll->nse) || (se_curr <= 1U)))) || -#endif - false) { + if (!trx_done) { payload_count_flush(cis_lll); goto isr_rx_next_subevent; diff --git a/tests/bsim/bluetooth/ll/cis/Kconfig b/tests/bsim/bluetooth/ll/cis/Kconfig index 6076f88ae3c..532a26f5d52 100644 --- a/tests/bsim/bluetooth/ll/cis/Kconfig +++ b/tests/bsim/bluetooth/ll/cis/Kconfig @@ -35,19 +35,6 @@ config TEST_FT_PER_SKIP_EVENTS_COUNT help Skip peripheral ISO events count where all subevents are skipped. -config TEST_FT_CEN_SKIP_SUBEVENTS - bool "Skip central role subevents to test Flush Timeout" - select TEST_FT_SKIP_SUBEVENTS - help - Skip central role subevent reception to test flush timeout - implementation. - -config TEST_FT_CEN_SKIP_EVENTS_COUNT - int "Skip central ISO events count, all subevents in them" - depends on TEST_FT_CEN_SKIP_SUBEVENTS - help - Skip central ISO events count where all subevents are skipped. - config BT_CTLR_SCAN_UNRESERVED default y if TEST_CONNECT_ACL_FIRST help diff --git a/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_cen_skip_2_se.conf b/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_cen_skip_2_se.conf deleted file mode 100644 index 194a23ffec6..00000000000 --- a/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_cen_skip_2_se.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_TEST_USE_LEGACY_ADVERTISING=n -CONFIG_TEST_CONNECT_ACL_FIRST=y -CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS=y -CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT=1 -CONFIG_BT_MAX_CONN=1 -CONFIG_BT_ISO_MAX_CHAN=1 -CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=9 -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_ISOAL_PSN_IGNORE=y diff --git a/tests/bsim/bluetooth/ll/cis/src/main.c b/tests/bsim/bluetooth/ll/cis/src/main.c index 15e102981d6..720adc16ef9 100644 --- a/tests/bsim/bluetooth/ll/cis/src/main.c +++ b/tests/bsim/bluetooth/ll/cis/src/main.c @@ -296,19 +296,15 @@ static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *in seq_num = sys_get_le32(buf->data); if (info->flags & BT_ISO_FLAGS_VALID) { if (seq_num != expected_seq_num[index]) { - if (expected_seq_num[index]) { - FAIL("ISO data miss match, expected %u actual %u\n", - expected_seq_num[index], seq_num); - } + FAIL("ISO data miss match, expected %u actual %u\n", + expected_seq_num[index], seq_num); expected_seq_num[index] = seq_num; } expected_seq_num[index] += 1U; -#if defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) +#if defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) expected_seq_num[index] += ((CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT - 1U) * 2U); -#elif defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) - expected_seq_num[index] += ((CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT - 1U) * 2U); #endif } else if (expected_seq_num[index] && expected_seq_num[index] < SEQ_NUM_MAX) { @@ -346,7 +342,6 @@ static struct bt_iso_chan_ops iso_ops = { static void test_cis_central(void) { struct bt_iso_chan_io_qos iso_tx[CONFIG_BT_ISO_MAX_CHAN]; - struct bt_iso_chan_io_qos iso_rx[CONFIG_BT_ISO_MAX_CHAN]; struct bt_iso_chan_qos iso_qos[CONFIG_BT_ISO_MAX_CHAN]; struct bt_iso_chan *channels[CONFIG_BT_ISO_MAX_CHAN]; struct bt_conn *conn_list[CONFIG_BT_MAX_CONN]; @@ -377,27 +372,8 @@ static void test_cis_central(void) } iso_tx[i].path = NULL; - if (!IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS) || - IS_ENABLED(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS)) { - iso_qos[i].tx = &iso_tx[i]; - } else { - iso_qos[i].tx = NULL; - } - - iso_rx[i].sdu = CONFIG_BT_ISO_RX_MTU; - iso_rx[i].phy = BT_GAP_LE_PHY_2M; - if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { - iso_rx[i].rtn = 2U; - } else { - iso_rx[i].rtn = 0U; - } - iso_rx[i].path = NULL; - - if (IS_ENABLED(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS)) { - iso_qos[i].rx = &iso_rx[i]; - } else { - iso_qos[i].rx = NULL; - } + iso_qos[i].tx = &iso_tx[i]; + iso_qos[i].rx = NULL; iso_chan[i].ops = &iso_ops; iso_chan[i].qos = &iso_qos[i]; @@ -430,12 +406,6 @@ static void test_cis_central(void) conn_count = 0U; -#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) - for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { - expected_seq_num[chan] = (CONFIG_TEST_FT_CEN_SKIP_EVENTS_COUNT - 1U) * 2U; - } -#endif - #if !defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) for (int i = 0; i < CONFIG_BT_MAX_CONN; i++) { #else @@ -523,7 +493,6 @@ static void test_cis_central(void) printk("connected to peer %d ISO channel.\n", chan); } -#if !defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) || defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { @@ -566,9 +535,6 @@ static void test_cis_central(void) } k_sleep(K_MSEC(1000)); -#else - k_sleep(K_SECONDS(11)); -#endif for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { printk("ISO disconnect channel %u...", chan); @@ -607,16 +573,6 @@ static void test_cis_central(void) } #endif -#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) - for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { - if (expected_seq_num[chan] < SEQ_NUM_MAX) { - FAIL("ISO Data reception incomplete %u (%u).\n", - expected_seq_num[chan], SEQ_NUM_MAX); - return; - } - } -#endif - PASS("Central ISO tests Passed\n"); } @@ -657,7 +613,6 @@ static struct bt_iso_server iso_server = { static void test_cis_peripheral(void) { - struct bt_iso_chan_io_qos iso_tx_p[CONFIG_BT_ISO_MAX_CHAN]; int err; printk("Bluetooth initializing..."); @@ -669,18 +624,7 @@ static void test_cis_peripheral(void) printk("success.\n"); for (int i = 0; i < CONFIG_BT_ISO_MAX_CHAN; i++) { - iso_tx_p[i].sdu = CONFIG_BT_ISO_TX_MTU; - iso_tx_p[i].phy = BT_GAP_LE_PHY_2M; - if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { - iso_tx_p[i].rtn = 2U; - } else { - iso_tx_p[i].rtn = 0U; - } - iso_tx_p[i].path = NULL; - - iso_qos_p[i].tx = &iso_tx_p[i]; - - iso_rx_p[i].sdu = CONFIG_BT_ISO_RX_MTU; + iso_rx_p[i].sdu = CONFIG_BT_ISO_TX_MTU; iso_qos_p[i].rx = &iso_rx_p[i]; @@ -754,51 +698,7 @@ static void test_cis_peripheral(void) #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) } -#endif - -#if defined(CONFIG_TEST_FT_CEN_SKIP_SUBEVENTS) - for (uint16_t seq_num = 0U; seq_num < SEQ_NUM_MAX; seq_num++) { - for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { - uint8_t iso_data[CONFIG_BT_ISO_TX_MTU] = { 0, }; - struct net_buf *buf; - int ret; - buf = net_buf_alloc(&tx_pool, - K_MSEC(BUF_ALLOC_TIMEOUT)); - if (!buf) { - FAIL("Data buffer allocate timeout on channel" - " %u\n", chan); - return; - } - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - sys_put_le32(seq_num, iso_data); - net_buf_add_mem(buf, iso_data, sizeof(iso_data)); - - ret = k_sem_take(&sem_iso_data, - K_MSEC(BUF_ALLOC_TIMEOUT)); - if (ret) { - FAIL("k_sem_take for ISO data sent failed.\n"); - return; - } - - printk("ISO send: seq_num %u, chan %u\n", seq_num, chan); - ret = bt_iso_chan_send(&iso_chan_p[chan], buf, - seq_num, BT_ISO_TIMESTAMP_NONE); - if (ret < 0) { - FAIL("Unable to send data on channel %u" - " : %d\n", chan, ret); - net_buf_unref(buf); - return; - } - } - - if ((seq_num % 100) == 0) { - printk("Sending value %u\n", seq_num); - } - } -#endif - -#if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { #endif @@ -822,7 +722,6 @@ static void test_cis_peripheral(void) } printk("disconnected from peer device.\n"); -#if !defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) || defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { #else @@ -835,7 +734,6 @@ static void test_cis_peripheral(void) } #if defined(CONFIG_TEST_MULTIPLE_PERIPERAL_CIS) } -#endif #endif PASS("Peripheral ISO tests Passed\n"); diff --git a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh deleted file mode 100755 index 04ce474e812..00000000000 --- a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_cen_skip_2_se.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2020 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -source ${ZEPHYR_BASE}/tests/bsim/sh_common.source - -# Basic Connected ISO test: a Central connects to 1 Peripheral and tests RTN=2, -# FT=2, skips 2 subevents in the central -simulation_id="connected_iso_acl_first_ft_cen_skip_2_se" -verbosity_level=2 -EXECUTE_TIMEOUT=60 - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_cis_prj_conf_overlay-acl_first_ft_cen_skip_2_se_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central - -Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_cis_prj_conf_overlay-acl_first_ft_cen_skip_2_se_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=30e6 $@ - -wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/compile.sh b/tests/bsim/bluetooth/ll/compile.sh index 6d530d05d72..28ca40b322c 100755 --- a/tests/bsim/bluetooth/ll/compile.sh +++ b/tests/bsim/bluetooth/ll/compile.sh @@ -40,8 +40,6 @@ app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_group.conf compile app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_group_acl_first.conf compile app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-peripheral_cis.conf compile app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_first_ft_per_skip_2_se.conf compile -app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_first_ft_per_skip_4_se.conf compile -app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_first_ft_cen_skip_2_se.conf compile app=tests/bsim/bluetooth/ll/edtt/hci_test_app \ conf_file=prj_dut_llcp.conf compile From 51767467a0952276f557f28559dd852b662dd78b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:56 +0000 Subject: [PATCH 0670/1623] Revert "[nrf fromtree] tests: bsim: Bluetooth: Test RTN=2, FT=2, Per skip 2 SE in Controller" This reverts commit 227cc39f8b9b67c4f3bce67a3e85df5d24a49073. Signed-off-by: Dominik Ermel --- .../ll_sw/nordic/lll/lll_peripheral_iso.c | 9 +----- tests/bsim/bluetooth/ll/cis/Kconfig | 19 ------------- .../overlay-acl_first_ft_per_skip_2_se.conf | 9 ------ tests/bsim/bluetooth/ll/cis/prj.conf | 1 - tests/bsim/bluetooth/ll/cis/src/main.c | 28 +++++-------------- ...onnected_iso_acl_first_ft_per_skip_2_se.sh | 24 ---------------- tests/bsim/bluetooth/ll/compile.sh | 1 - 7 files changed, 8 insertions(+), 83 deletions(-) delete mode 100644 tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_per_skip_2_se.conf delete mode 100755 tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index c33c82d4c70..25401f5564e 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -472,14 +472,7 @@ static void isr_rx(void *param) cis_lll = param; /* No Rx */ - if (!trx_done || -#if defined(CONFIG_TEST_FT_PER_SKIP_SUBEVENTS) - ((((cis_lll->event_count % 3U) < CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT) && - ((se_curr > cis_lll->nse) || (se_curr <= 2U))) || - (((cis_lll->event_count % 3U) < (CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT + 1U)) && - ((se_curr > cis_lll->nse) || (se_curr <= 1U)))) || -#endif - false) { + if (!trx_done) { payload_count_flush(cis_lll); /* Next subevent or next CIS */ diff --git a/tests/bsim/bluetooth/ll/cis/Kconfig b/tests/bsim/bluetooth/ll/cis/Kconfig index 532a26f5d52..b59a46be4fc 100644 --- a/tests/bsim/bluetooth/ll/cis/Kconfig +++ b/tests/bsim/bluetooth/ll/cis/Kconfig @@ -16,25 +16,6 @@ config TEST_MULTIPLE_PERIPERAL_CIS help Multiple Peripheral CIS establishment. -config TEST_FT_SKIP_SUBEVENTS - bool - help - Skip central and/or peripheral subevent reception to test flush - timeout implementation. - -config TEST_FT_PER_SKIP_SUBEVENTS - bool "Skip peripheral role subevents to test Flush Timeout" - select TEST_FT_SKIP_SUBEVENTS - help - Skip peripheral role subevent reception to test flush timeout - implementation. - -config TEST_FT_PER_SKIP_EVENTS_COUNT - int "Skip peripheral ISO events count, all subevents in them" - depends on TEST_FT_PER_SKIP_SUBEVENTS - help - Skip peripheral ISO events count where all subevents are skipped. - config BT_CTLR_SCAN_UNRESERVED default y if TEST_CONNECT_ACL_FIRST help diff --git a/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_per_skip_2_se.conf b/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_per_skip_2_se.conf deleted file mode 100644 index bfbe36115f5..00000000000 --- a/tests/bsim/bluetooth/ll/cis/overlay-acl_first_ft_per_skip_2_se.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_TEST_USE_LEGACY_ADVERTISING=n -CONFIG_TEST_CONNECT_ACL_FIRST=y -CONFIG_TEST_FT_PER_SKIP_SUBEVENTS=y -CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT=1 -CONFIG_BT_MAX_CONN=1 -CONFIG_BT_ISO_MAX_CHAN=1 -CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=9 -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_ISOAL_PSN_IGNORE=y diff --git a/tests/bsim/bluetooth/ll/cis/prj.conf b/tests/bsim/bluetooth/ll/cis/prj.conf index a4d3c3e8c5f..0b6b764393b 100644 --- a/tests/bsim/bluetooth/ll/cis/prj.conf +++ b/tests/bsim/bluetooth/ll/cis/prj.conf @@ -13,7 +13,6 @@ CONFIG_BT_MAX_CONN=9 CONFIG_BT_ISO_MAX_CHAN=9 CONFIG_BT_ISO_TX_BUF_COUNT=18 CONFIG_BT_ISO_TX_MTU=120 -CONFIG_BT_ISO_RX_MTU=120 CONFIG_BT_BUF_CMD_TX_SIZE=255 CONFIG_BT_BUF_EVT_RX_SIZE=255 diff --git a/tests/bsim/bluetooth/ll/cis/src/main.c b/tests/bsim/bluetooth/ll/cis/src/main.c index 720adc16ef9..a9538e3e9c6 100644 --- a/tests/bsim/bluetooth/ll/cis/src/main.c +++ b/tests/bsim/bluetooth/ll/cis/src/main.c @@ -53,7 +53,6 @@ static bt_addr_le_t peer_addr; #define ISO_INTERVAL_US 10000U #define ISO_LATENCY_MS DIV_ROUND_UP(ISO_INTERVAL_US, USEC_PER_MSEC) -#define ISO_LATENCY_FT_MS 20U #define BT_CONN_US_TO_INTERVAL(t) ((uint16_t)((t) * 4U / 5U / USEC_PER_MSEC)) @@ -104,7 +103,7 @@ static bt_addr_le_t peer_addr; #define NAME_LEN 30 -#define BUF_ALLOC_TIMEOUT (40) /* milliseconds */ +#define BUF_ALLOC_TIMEOUT (30) /* milliseconds */ NET_BUF_POOL_FIXED_DEFINE(tx_pool, CONFIG_BT_ISO_TX_BUF_COUNT, BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), 8, NULL); @@ -301,11 +300,8 @@ static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *in expected_seq_num[index] = seq_num; } - expected_seq_num[index] += 1U; + expected_seq_num[index]++; -#if defined(CONFIG_TEST_FT_SKIP_SUBEVENTS) - expected_seq_num[index] += ((CONFIG_TEST_FT_PER_SKIP_EVENTS_COUNT - 1U) * 2U); -#endif } else if (expected_seq_num[index] && expected_seq_num[index] < SEQ_NUM_MAX) { FAIL("%s: Invalid ISO data after valid ISO data reception.\n" @@ -365,11 +361,7 @@ static void test_cis_central(void) for (int i = 0; i < CONFIG_BT_ISO_MAX_CHAN; i++) { iso_tx[i].sdu = CONFIG_BT_ISO_TX_MTU; iso_tx[i].phy = BT_GAP_LE_PHY_2M; - if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { - iso_tx[i].rtn = 2U; - } else { - iso_tx[i].rtn = 0U; - } + iso_tx[i].rtn = 0U; iso_tx[i].path = NULL; iso_qos[i].tx = &iso_tx[i]; @@ -389,11 +381,7 @@ static void test_cis_central(void) cig_param.sca = BT_GAP_SCA_UNKNOWN; cig_param.packing = 0U; cig_param.framing = 0U; - if (IS_ENABLED(CONFIG_TEST_FT_SKIP_SUBEVENTS)) { - cig_param.latency = ISO_LATENCY_FT_MS; - } else { - cig_param.latency = ISO_LATENCY_MS; - } + cig_param.latency = ISO_LATENCY_MS; cig_param.interval = ISO_INTERVAL_US; printk("Create CIG..."); @@ -416,7 +404,7 @@ static void test_cis_central(void) uint8_t conn_index; uint8_t chan; - printk("Start scanning (%d)...", i); + printk("Start scanning..."); err = bt_le_scan_start(BT_LE_SCAN_CUSTOM, NULL); if (err) { FAIL("Could not start scan: %d\n", err); @@ -522,7 +510,7 @@ static void test_cis_central(void) ret = bt_iso_chan_send(&iso_chan[chan], buf, seq_num, BT_ISO_TIMESTAMP_NONE); if (ret < 0) { - FAIL("Unable to send data on channel %u" + FAIL("Unable to broadcast data on channel %u" " : %d\n", chan, ret); net_buf_unref(buf); return; @@ -534,7 +522,7 @@ static void test_cis_central(void) } } - k_sleep(K_MSEC(1000)); + k_sleep(K_MSEC(100)); for (uint8_t chan = 0U; chan < CONFIG_BT_ISO_MAX_CHAN; chan++) { printk("ISO disconnect channel %u...", chan); @@ -599,8 +587,6 @@ static int iso_accept(const struct bt_iso_accept_info *info, *chan = &iso_chan_p[chan_count]; chan_count++; - printk("Accepted on channel %p\n", *chan); - return 0; } diff --git a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh b/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh deleted file mode 100755 index 307d865a117..00000000000 --- a/tests/bsim/bluetooth/ll/cis/tests_scripts/connected_iso_acl_first_ft_per_skip_2_se.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2020 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -source ${ZEPHYR_BASE}/tests/bsim/sh_common.source - -# Basic Connected ISO test: a Central connects to 1 Peripheral and tests RTN=2, -# FT=2, skips 2 subevents in the peripheral -simulation_id="connected_iso_acl_first_ft_per_skip_2_se" -verbosity_level=2 -EXECUTE_TIMEOUT=60 - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_cis_prj_conf_overlay-acl_first_ft_per_skip_2_se_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central - -Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_cis_prj_conf_overlay-acl_first_ft_per_skip_2_se_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=30e6 $@ - -wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/compile.sh b/tests/bsim/bluetooth/ll/compile.sh index 28ca40b322c..2369192e0cc 100755 --- a/tests/bsim/bluetooth/ll/compile.sh +++ b/tests/bsim/bluetooth/ll/compile.sh @@ -39,7 +39,6 @@ app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-legacy_adv_acl_first.conf c app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_group.conf compile app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_group_acl_first.conf compile app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-peripheral_cis.conf compile -app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_first_ft_per_skip_2_se.conf compile app=tests/bsim/bluetooth/ll/edtt/hci_test_app \ conf_file=prj_dut_llcp.conf compile From 3390fc5c328885e520ebb87ca9426afc588226e0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:56 +0000 Subject: [PATCH 0671/1623] Revert "[nrf fromtree] Bluetooth: Controller: Option to ignore Tx ISO Data Packet Seq Num" This reverts commit 41b3a58b1641934eec748c66d57846f0e4ef56e0. Signed-off-by: Dominik Ermel --- .../bluetooth/controller/Kconfig.ll_sw_split | 9 +- subsys/bluetooth/controller/hci/hci.c | 108 +++--------------- .../controller/ll_sw/ull_central_iso.c | 3 - .../controller/ll_sw/ull_conn_iso_types.h | 4 - .../controller/ll_sw/ull_peripheral_iso.c | 3 - 5 files changed, 16 insertions(+), 111 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index a7dade7a1db..3f6f3c10382 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -499,8 +499,7 @@ config BT_CTLR_SCAN_ENABLE_STRICT config BT_CTLR_ISOAL_SN_STRICT bool "Enforce Strict Tx ISO Data Sequence Number use" - depends on !BT_CTLR_ISOAL_PSN_IGNORE && (BT_CTLR_ADV_ISO || \ - BT_CTLR_CONN_ISO) + depends on BT_CTLR_ADV_ISO || BT_CTLR_CONN_ISO default y help Enforce strict sequencing of released payloads based on the TX SDU's @@ -518,12 +517,6 @@ config BT_CTLR_ISOAL_SN_STRICT dropped. This will result in better delivery of data to the receiver but at the cost of creating skews in the received stream of SDUs. -config BT_CTLR_ISOAL_PSN_IGNORE - bool "Ignore Tx ISO Data Packet Sequence Number use" - depends on BT_CTLR_ADV_ISO || BT_CTLR_CONN_ISO - help - Ignore the use of Tx ISO Data Packet Sequence Number. - config BT_CTLR_ZLI bool "Use Zero Latency IRQs" depends on ZERO_LATENCY_IRQS diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index b2c95271b2c..0adbf5ff70c 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -5657,6 +5657,8 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) struct bt_hci_iso_data_hdr *iso_data_hdr; struct isoal_sdu_tx sdu_frag_tx; struct bt_hci_iso_hdr *iso_hdr; + struct ll_iso_datapath *dp_in; + struct ll_iso_stream_hdr *hdr; uint32_t *time_stamp; uint16_t handle; uint8_t pb_flag; @@ -5666,6 +5668,8 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) iso_data_hdr = NULL; *evt = NULL; + hdr = NULL; + dp_in = NULL; if (buf->len < sizeof(*iso_hdr)) { LOG_ERR("No HCI ISO header"); @@ -5743,50 +5747,17 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) * data path */ } else if (IS_CIS_HANDLE(handle)) { - struct ll_conn_iso_stream *cis; - struct ll_conn_iso_group *cig; - struct ll_iso_stream_hdr *hdr; - struct ll_iso_datapath *dp_in; - - cis = ll_iso_stream_connected_get(handle); + struct ll_conn_iso_stream *cis = + ll_iso_stream_connected_get(handle); if (!cis) { return -EINVAL; } - cig = cis->group; - -#if defined(CONFIG_BT_CTLR_ISOAL_PSN_IGNORE) - uint64_t event_count; - uint64_t pkt_seq_num; - - /* Catch up local pkt_seq_num with internal pkt_seq_num */ - event_count = cis->lll.event_count; - pkt_seq_num = event_count + 1U; - if (!(pb_flag & 0x01) && - (((pkt_seq_num - cis->pkt_seq_num) & - BIT64_MASK(39)) <= BIT64_MASK(38))) { - cis->pkt_seq_num = pkt_seq_num; - } else { - pkt_seq_num = cis->pkt_seq_num; - } - - /* Pre-increment, for next ISO data packet seq num comparison */ - if (pb_flag & 0x10) { - cis->pkt_seq_num++; - } - - /* Target next event to avoid overlapping with current event */ - pkt_seq_num++; - sdu_frag_tx.target_event = pkt_seq_num; - sdu_frag_tx.grp_ref_point = - isoal_get_wrapped_time_us(cig->cig_ref_point, - ((pkt_seq_num - event_count) * - cig->iso_interval * - ISO_INT_UNIT_US)); - -#else /* !CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ + struct ll_conn_iso_group *cig = cis->group; uint8_t event_offset; + hdr = &(cis->hdr); + /* We must ensure sufficient time for ISO-AL to fragment SDU and * deliver PDUs to the TX queue. By checking ull_ref_get, we * know if we are within the subevents of an ISO event. If so, @@ -5809,15 +5780,11 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) } sdu_frag_tx.target_event = cis->lll.event_count + event_offset; - sdu_frag_tx.grp_ref_point = - isoal_get_wrapped_time_us(cig->cig_ref_point, - (event_offset * - cig->iso_interval * - ISO_INT_UNIT_US)); -#endif /* !CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ + sdu_frag_tx.grp_ref_point = isoal_get_wrapped_time_us(cig->cig_ref_point, + (event_offset * cig->iso_interval * + ISO_INT_UNIT_US)); /* Get controller's input data path for CIS */ - hdr = &(cis->hdr); dp_in = hdr->datapath_in; if (!dp_in || dp_in->path_id != BT_HCI_DATAPATH_ID_HCI) { LOG_ERR("Input data path not set for HCI"); @@ -5850,6 +5817,8 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) struct ll_adv_iso_set *adv_iso; struct lll_adv_iso *lll_iso; uint16_t stream_handle; + uint8_t target_event; + uint8_t event_offset; uint16_t slen; /* FIXME: Code only expects header present */ @@ -5875,53 +5844,6 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) return -EINVAL; } - lll_iso = &adv_iso->lll; - -#if defined(CONFIG_BT_CTLR_ISOAL_PSN_IGNORE) - uint64_t event_count; - uint64_t pkt_seq_num; - - /* Catch up local pkt_seq_num with internal pkt_seq_num */ - event_count = lll_iso->payload_count / lll_iso->bn; - pkt_seq_num = event_count; - if (!(pb_flag & 0x01) && - (((pkt_seq_num - stream->pkt_seq_num) & - BIT64_MASK(39)) <= BIT64_MASK(38))) { - stream->pkt_seq_num = pkt_seq_num; - } else { - pkt_seq_num = stream->pkt_seq_num; - } - - /* Pre-increment, for next ISO data packet seq num comparison */ - if (pb_flag & 0x10) { - stream->pkt_seq_num++; - } - - /* Target next event to avoid overlapping with current event */ - /* FIXME: Implement ISO Tx ack generation early in done compared - * to currently only in prepare. I.e. to ensure upper - * layer has the number of completed packet before the - * next BIG event, so as to supply new ISO data packets. - * Without which upper layers need extra buffers to - * buffer next ISO data packet. - * - * Enable below increment once early Tx ack is - * implemented. - * - * pkt_seq_num++; - */ - sdu_frag_tx.target_event = pkt_seq_num; - sdu_frag_tx.grp_ref_point = - isoal_get_wrapped_time_us(adv_iso->big_ref_point, - (((pkt_seq_num + 1U) - - event_count) * - lll_iso->iso_interval * - ISO_INT_UNIT_US)); - -#else /* !CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ - uint8_t target_event; - uint8_t event_offset; - /* Determine the target event and the first event offset after * datapath setup. * event_offset mitigates the possibility of first SDU being @@ -5939,6 +5861,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) * BIG event by incrementing the previous elapsed big_ref_point * by one additional ISO interval. */ + lll_iso = &adv_iso->lll; target_event = lll_iso->payload_count / lll_iso->bn; event_offset = ull_ref_get(&adv_iso->ull) ? 0U : 1U; event_offset += lll_iso->latency_prepare; @@ -5949,7 +5872,6 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) ((event_offset + 1U) * lll_iso->iso_interval * ISO_INT_UNIT_US)); -#endif /* !CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ /* Start Fragmentation */ /* FIXME: need to ensure ISO-AL returns proper isoal_status. diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 474b8d0dbe9..62a684bbfa9 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -883,9 +883,6 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, #endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ cis->central.instant = instant; -#if defined(CONFIG_BT_CTLR_ISOAL_PSN_IGNORE) - cis->pkt_seq_num = 0U; -#endif /* CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ cis->lll.event_count = LLL_CONN_ISO_EVENT_COUNT_MAX; cis->lll.next_subevent = 0U; cis->lll.sn = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h b/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h index 39cee21d0b1..e8ca29da7af 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h @@ -48,10 +48,6 @@ struct ll_conn_iso_stream { */ uint8_t terminate_reason; uint8_t cis_id; - -#if defined(CONFIG_BT_CTLR_ISOAL_PSN_IGNORE) - uint64_t pkt_seq_num:39; -#endif /* CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ }; struct ll_conn_iso_group { diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index 843bf877935..a707341f41c 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -326,9 +326,6 @@ uint8_t ull_peripheral_iso_setup(struct pdu_data_llctrl_cis_ind *ind, cis->sync_delay = sys_get_le24(ind->cis_sync_delay); cis->offset = cis_offset; memcpy(cis->lll.access_addr, ind->aa, sizeof(ind->aa)); -#if defined(CONFIG_BT_CTLR_ISOAL_PSN_IGNORE) - cis->pkt_seq_num = 0U; -#endif /* CONFIG_BT_CTLR_ISOAL_PSN_IGNORE */ cis->lll.event_count = LLL_CONN_ISO_EVENT_COUNT_MAX; cis->lll.next_subevent = 0U; cis->lll.sn = 0U; From c32ef8aa7f674ac8dcceef1755d2505bac64b91e Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:56 +0000 Subject: [PATCH 0672/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix ISO Data timestamp when FT > 1" This reverts commit 2694658063e3e5667cd8871632c23b268f71b54a. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/lll_conn_iso.h | 3 --- .../controller/ll_sw/nordic/lll/lll_central_iso.c | 7 +------ .../controller/ll_sw/nordic/lll/lll_peripheral_iso.c | 5 ----- subsys/bluetooth/controller/ll_sw/ull_central_iso.c | 1 - subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c | 1 - 5 files changed, 1 insertion(+), 16 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h index 0321b96f638..9822066f513 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h +++ b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h @@ -77,9 +77,6 @@ struct lll_conn_iso_group { uint8_t role:1; /* 0: CENTRAL, 1: PERIPHERAL*/ uint8_t paused:1; /* 1: CIG is paused */ - /* ISO interval to calculate timestamp under FT > 1 */ - uint32_t iso_interval_us; - /* Accumulates LLL prepare callback latencies */ uint16_t latency_prepare; uint16_t latency_event; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 4bf44a42cd9..d4f4c8c3262 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -716,7 +716,6 @@ static void isr_rx(void *param) (cis_lll->rx.bn_curr <= cis_lll->rx.bn) && (pdu_rx->sn == cis_lll->nesn) && ull_iso_pdu_rx_alloc_peek(2U)) { - struct lll_conn_iso_group *cig_lll; struct node_rx_iso_meta *iso_meta; cis_lll->nesn++; @@ -754,10 +753,6 @@ static void isr_rx(void *param) iso_meta->timestamp = HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + radio_tmr_ready_restore(); - cig_lll = ull_conn_iso_lll_group_get_by_stream(cis_lll); - iso_meta->timestamp -= (cis_lll->event_count - - (cis_lll->rx.payload_count / cis_lll->rx.bn)) * - cig_lll->iso_interval_us; iso_meta->timestamp %= HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); iso_meta->status = 0U; @@ -793,8 +788,8 @@ static void isr_rx(void *param) isr_rx_next_subevent: if (cie || (se_curr == cis_lll->nse)) { - struct lll_conn_iso_stream *next_cis_lll; struct lll_conn_iso_stream *old_cis_lll; + struct lll_conn_iso_stream *next_cis_lll; struct lll_conn_iso_group *cig_lll; struct lll_conn *next_conn_lll; uint8_t phy; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 25401f5564e..75af765f9d0 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -545,7 +545,6 @@ static void isr_rx(void *param) (cis_lll->rx.bn_curr <= cis_lll->rx.bn) && (pdu_rx->sn == cis_lll->nesn) && ull_iso_pdu_rx_alloc_peek(2U)) { - struct lll_conn_iso_group *cig_lll; struct node_rx_iso_meta *iso_meta; cis_lll->nesn++; @@ -585,10 +584,6 @@ static void isr_rx(void *param) HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + radio_tmr_aa_restore() - cis_offset_first - addr_us_get(cis_lll->rx.phy); - cig_lll = ull_conn_iso_lll_group_get_by_stream(cis_lll); - iso_meta->timestamp -= (cis_lll->event_count - - (cis_lll->rx.payload_count / cis_lll->rx.bn)) * - cig_lll->iso_interval_us; iso_meta->timestamp %= HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); iso_meta->status = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 62a684bbfa9..8c516826e06 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -254,7 +254,6 @@ uint8_t ll_cig_parameters_commit(uint8_t cig_id, uint16_t *handles) } iso_interval_us = cig->iso_interval * ISO_INT_UNIT_US; - cig->lll.iso_interval_us = iso_interval_us; lll_hdr_init(&cig->lll, cig); max_se_length = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index a707341f41c..eeef778734b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -191,7 +191,6 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl, cig->iso_interval = sys_le16_to_cpu(req->iso_interval); iso_interval_us = cig->iso_interval * CONN_INT_UNIT_US; - cig->lll.iso_interval_us = iso_interval_us; cig->cig_id = req->cig_id; cig->lll.handle = LLL_HANDLE_INVALID; From 3c045dade6b419552c3875d67074e3281e3d7e5c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:57 +0000 Subject: [PATCH 0673/1623] Revert "[nrf fromtree] Bluetooth: Controller: Use of payload_count for Flush Timeout" This reverts commit 7c19e78ea41afa3f5b10c001af8bc84042620830. Signed-off-by: Dominik Ermel --- .../bluetooth/controller/ll_sw/lll_conn_iso.h | 3 +- .../ll_sw/nordic/lll/lll_central_iso.c | 379 ++++++---------- .../ll_sw/nordic/lll/lll_peripheral_iso.c | 405 +++++++----------- 3 files changed, 284 insertions(+), 503 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h index 9822066f513..7fdf6bf48d5 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h +++ b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h @@ -16,7 +16,8 @@ struct lll_conn_iso_stream_rxtx { uint64_t bn:4; /* Burst number (BN) */ uint64_t phy:3; /* PHY */ uint64_t rfu:1; - uint8_t bn_curr:4; /* Current burst number */ + uint8_t bn_curr:4; /* Current burst number */ + #if defined(CONFIG_BT_CTLR_LE_ENC) struct ccm ccm; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index d4f4c8c3262..936087369f1 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -40,15 +40,14 @@ #include "hal/debug.h" static int init_reset(void); +static inline void lll_flush_tx(struct lll_conn_iso_stream *cis_lll); +static inline void lll_flush_rx(struct lll_conn_iso_stream *cis_lll); static int prepare_cb(struct lll_prepare_param *p); static void abort_cb(struct lll_prepare_param *prepare_param, void *param); static void isr_tx(void *param); static void isr_rx(void *param); static void isr_prepare_subevent(void *param); static void isr_done(void *param); -static void payload_count_flush(struct lll_conn_iso_stream *cis_lll); -static void payload_count_flush_or_inc_on_close(struct lll_conn_iso_stream *cis_lll); -static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy); static uint16_t next_cis_chan_remap_idx; static uint16_t next_cis_chan_prn_s; @@ -119,6 +118,24 @@ static int init_reset(void) return 0; } +static inline void lll_flush_tx(struct lll_conn_iso_stream *cis_lll) +{ + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + uint8_t sn_update = cis_lll->tx.bn + 1U - cis_lll->tx.bn_curr; + + /* we'll re-use sn_update when implementing flush timeout */ + cis_lll->sn += sn_update; +} + +static inline void lll_flush_rx(struct lll_conn_iso_stream *cis_lll) +{ + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + uint8_t nesn_update = cis_lll->rx.bn + 1U - cis_lll->rx.bn_curr; + + /* we'll re-use sn_update when implementing flush timeout */ + cis_lll->nesn += nesn_update; +} + static int prepare_cb(struct lll_prepare_param *p) { struct lll_conn_iso_group *cig_lll = p->param; @@ -180,10 +197,24 @@ static int prepare_cb(struct lll_prepare_param *p) /* Reset accumulated latencies */ cig_lll->latency_prepare = 0U; - se_curr = 1U; - /* Adjust the SN and NESN for skipped CIG events */ - payload_count_lazy(cis_lll, lazy); + if (cis_lll->event_count) { + uint16_t cis_lazy; + + if (lazy > cis_lll->event_count) { + cis_lazy = lazy - cis_lll->event_count; + } else { + cis_lazy = lazy; + } + + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->sn += cis_lll->tx.bn * cis_lazy; + cis_lll->nesn += cis_lll->rx.bn * cis_lazy; + } + + se_curr = 1U; + cis_lll->tx.bn_curr = 1U; + cis_lll->rx.bn_curr = 1U; /* Start setting up of Radio h/w */ radio_reset(); @@ -217,8 +248,7 @@ static int prepare_cb(struct lll_prepare_param *p) struct node_tx_iso *node_tx; memq_link_t *link; - payload_count = cis_lll->tx.payload_count + - cis_lll->tx.bn_curr - 1U; + payload_count = cis_lll->event_count * cis_lll->tx.bn; do { link = memq_peek(cis_lll->memq_tx.head, @@ -369,12 +399,33 @@ static int prepare_cb(struct lll_prepare_param *p) do { cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); if (cis_lll && cis_lll->active) { - /* Adjust sn and nesn for skipped CIG events */ - payload_count_lazy(cis_lll, lazy); + if (cis_lll->event_count) { + uint16_t cis_lazy; + + if (lazy > cis_lll->event_count) { + cis_lazy = lazy - cis_lll->event_count; + } else { + cis_lazy = lazy; + } - /* Adjust sn and nesn for canceled events */ - if (err) { - payload_count_flush_or_inc_on_close(cis_lll); + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->sn += cis_lll->tx.bn * cis_lazy; + cis_lll->nesn += cis_lll->rx.bn * cis_lazy; + + /* Adjust sn and nesn for canceled events */ + if (err) { + /* Adjust sn when flushing Tx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { + lll_flush_tx(cis_lll); + } + + /* Adjust nesn when flushing Rx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { + lll_flush_rx(cis_lll); + } + } } } } while (cis_lll); @@ -399,21 +450,9 @@ static void abort_cb(struct lll_prepare_param *prepare_param, void *param) /* NOTE: This is not a prepare being cancelled */ if (!prepare_param) { - struct lll_conn_iso_stream *next_cis_lll; struct lll_conn_iso_stream *cis_lll; - struct lll_conn_iso_group *cig_lll; cis_lll = ull_conn_iso_lll_stream_get(cis_handle_curr); - cig_lll = param; - - /* Adjust the SN, NESN and payload_count on abort for CISes */ - do { - next_cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, - &cis_handle_curr); - if (next_cis_lll && next_cis_lll->active) { - payload_count_flush_or_inc_on_close(next_cis_lll); - } - } while (next_cis_lll); /* Perform event abort here. * After event has been cleanly aborted, clean up resources @@ -469,8 +508,8 @@ static void isr_tx(void *param) uint64_t payload_count; uint8_t pkt_flags; - payload_count = cis_lll->rx.payload_count + - cis_lll->rx.bn_curr - 1U; + payload_count = (cis_lll->event_count * cis_lll->rx.bn) + + (cis_lll->rx.bn_curr - 1U); cis_lll->rx.ccm.counter = payload_count; @@ -613,9 +652,7 @@ static void isr_tx(void *param) cis_lll = next_cis_lll; /* Tx Ack stale ISO Data */ - payload_count = cis_lll->tx.payload_count + - cis_lll->tx.bn_curr - 1U; - + payload_count = cis_lll->event_count * cis_lll->tx.bn; do { link = memq_peek(cis_lll->memq_tx.head, cis_lll->memq_tx.tail, @@ -650,6 +687,8 @@ static void isr_tx(void *param) static void isr_rx(void *param) { struct lll_conn_iso_stream *cis_lll; + struct node_rx_pdu *node_rx; + struct pdu_cis *pdu_rx; uint8_t ack_pending; uint8_t trx_done; uint8_t crc_ok; @@ -675,8 +714,6 @@ static void isr_rx(void *param) /* No Rx */ if (!trx_done) { - payload_count_flush(cis_lll); - goto isr_rx_next_subevent; } @@ -686,23 +723,23 @@ static void isr_rx(void *param) /* Set the bit corresponding to CIS index */ trx_performed_bitmask |= (1U << LL_CIS_IDX_FROM_HANDLE(cis_lll->handle)); - if (crc_ok) { - struct node_rx_pdu *node_rx; - struct pdu_cis *pdu_rx; + /* Get reference to received PDU */ + node_rx = ull_iso_pdu_rx_alloc_peek(1U); + LL_ASSERT(node_rx); - /* Get reference to received PDU */ - node_rx = ull_iso_pdu_rx_alloc_peek(1U); - LL_ASSERT(node_rx); - pdu_rx = (void *)node_rx->pdu; + pdu_rx = (void *)node_rx->pdu; + if (crc_ok) { /* Tx ACK */ - if ((pdu_rx->nesn != cis_lll->sn) && (cis_lll->tx.bn_curr <= cis_lll->tx.bn)) { + if (pdu_rx->nesn != cis_lll->sn) { + /* Increment sequence number */ cis_lll->sn++; - cis_lll->tx.bn_curr++; - if ((cis_lll->tx.bn_curr > cis_lll->tx.bn) && - ((cis_lll->tx.payload_count / cis_lll->tx.bn) < cis_lll->event_count)) { - cis_lll->tx.payload_count += cis_lll->tx.bn; - cis_lll->tx.bn_curr = 1U; + + /* Increment burst number */ + if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { + + cis_lll->tx.bn_curr++; + } /* TODO: Implement early Tx Ack. Currently Tx Ack @@ -718,6 +755,7 @@ static void isr_rx(void *param) ull_iso_pdu_rx_alloc_peek(2U)) { struct node_rx_iso_meta *iso_meta; + /* Increment next expected sequence number */ cis_lll->nesn++; #if defined(CONFIG_BT_CTLR_LE_ENC) @@ -748,8 +786,9 @@ static void isr_rx(void *param) node_rx->hdr.type = NODE_RX_TYPE_ISO_PDU; node_rx->hdr.handle = cis_lll->handle; iso_meta = &node_rx->hdr.rx_iso_meta; - iso_meta->payload_number = cis_lll->rx.payload_count + - cis_lll->rx.bn_curr - 1U; + iso_meta->payload_number = (cis_lll->event_count * + cis_lll->rx.bn) + + (cis_lll->rx.bn_curr - 1U); iso_meta->timestamp = HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + radio_tmr_ready_restore(); @@ -764,23 +803,36 @@ static void isr_rx(void *param) iso_rx_sched(); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ + /* Increment burst number */ cis_lll->rx.bn_curr++; - if ((cis_lll->rx.bn_curr > cis_lll->rx.bn) && - ((cis_lll->rx.payload_count / cis_lll->rx.bn) < cis_lll->event_count)) { - cis_lll->rx.payload_count += cis_lll->rx.bn; - cis_lll->rx.bn_curr = 1U; - } /* Need to be acked */ ack_pending = 1U; + + /* Handle NULL PDU indication received */ + } else if (pdu_rx->npi) { + /* Source could not send ISO data, increment NESN as if + * we received and expect to receive the next PDU in the + * burst. + */ + if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { + /* Increment next expected serial number */ + cis_lll->nesn++; + + /* Increment burst number */ + cis_lll->rx.bn_curr++; + } + + /* Not NPI, or more than the BN, or no free Rx ISO PDU buffers. + */ + } else { + /* Do nothing, ignore the Rx buffer */ } /* Close Isochronous Event */ cie = cie || pdu_rx->cie; } - payload_count_flush(cis_lll); - /* Close Isochronous Event */ cie = cie || ((cis_lll->rx.bn_curr > cis_lll->rx.bn) && (cis_lll->tx.bn_curr > cis_lll->tx.bn) && @@ -841,8 +893,7 @@ static void isr_rx(void *param) old_cis_lll = cis_lll; cis_lll = next_cis_lll; - payload_count = cis_lll->tx.payload_count + - cis_lll->tx.bn_curr - 1U; + payload_count = cis_lll->event_count * cis_lll->tx.bn; do { link = memq_peek(cis_lll->memq_tx.head, @@ -876,10 +927,22 @@ static void isr_rx(void *param) cis_lll = old_cis_lll; } - payload_count_flush_or_inc_on_close(cis_lll); + /* Adjust sn when flushing Tx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { + lll_flush_tx(cis_lll); + } + + /* Adjust nesn when flushing Rx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { + lll_flush_rx(cis_lll); + } /* Reset indices for the next CIS */ se_curr = 0U; /* isr_prepare_subevent() will increase se_curr */ + next_cis_lll->tx.bn_curr = 1U; + next_cis_lll->rx.bn_curr = 1U; #if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) radio_tx_power_set(next_conn_lll->tx_pwr_lvl); @@ -938,7 +1001,8 @@ static void isr_prepare_subevent(void *param) memq_link_t *link; payload_index = cis_lll->tx.bn_curr - 1U; - payload_count = cis_lll->tx.payload_count + payload_index; + payload_count = cis_lll->event_count * cis_lll->tx.bn + + payload_index; link = memq_peek_n(cis_lll->memq_tx.head, cis_lll->memq_tx.tail, payload_index, (void **)&node_tx); @@ -1077,7 +1141,17 @@ static void isr_done(void *param) /* Get reference to CIS LLL context */ cis_lll = param; - payload_count_flush_or_inc_on_close(cis_lll); + /* Adjust sn when flushing Tx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { + lll_flush_tx(cis_lll); + } + + /* Adjust nesn when flushing Rx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { + lll_flush_rx(cis_lll); + } e = ull_event_done_extra_get(); LL_ASSERT(e); @@ -1092,190 +1166,3 @@ static void isr_done(void *param) lll_isr_cleanup(param); } - -static void payload_count_flush(struct lll_conn_iso_stream *cis_lll) -{ - if (cis_lll->tx.bn) { - uint64_t payload_count; - uint8_t u; - - payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * - (cis_lll->tx.bn - 1U - - (payload_count % cis_lll->tx.bn))); - if ((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) == - (cis_lll->event_count + 1U)) && (u <= se_curr) && - (((cis_lll->tx.bn_curr < cis_lll->tx.bn) && - ((cis_lll->tx.payload_count / cis_lll->tx.bn) <= cis_lll->event_count)) || - ((cis_lll->tx.bn_curr == cis_lll->tx.bn) && - ((cis_lll->tx.payload_count / cis_lll->tx.bn) < cis_lll->event_count)))) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->sn++; - cis_lll->tx.bn_curr++; - if (cis_lll->tx.bn_curr > cis_lll->tx.bn) { - cis_lll->tx.payload_count += cis_lll->tx.bn; - cis_lll->tx.bn_curr = 1U; - } - } - } - - if (cis_lll->rx.bn) { - uint64_t payload_count; - uint8_t u; - - payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * - (cis_lll->rx.bn - 1U - - (payload_count % cis_lll->rx.bn))); - if ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) == - (cis_lll->event_count + 1U)) && (u <= se_curr) && - (((cis_lll->rx.bn_curr < cis_lll->rx.bn) && - ((cis_lll->rx.payload_count / cis_lll->rx.bn) <= cis_lll->event_count)) || - ((cis_lll->rx.bn_curr == cis_lll->rx.bn) && - ((cis_lll->rx.payload_count / cis_lll->rx.bn) < cis_lll->event_count)))) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->nesn++; - cis_lll->rx.bn_curr++; - if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { - cis_lll->rx.payload_count += cis_lll->rx.bn; - cis_lll->rx.bn_curr = 1U; - } - } - } -} - -static void payload_count_flush_or_inc_on_close(struct lll_conn_iso_stream *cis_lll) -{ - if (cis_lll->tx.bn) { - uint64_t payload_count; - uint8_t u; - - if (((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.bn_curr) > - (cis_lll->event_count + cis_lll->tx.bn)) { - cis_lll->tx.payload_count += cis_lll->tx.bn; - cis_lll->tx.bn_curr = 1U; - - goto payload_count_flush_or_inc_on_close_rx; - } - - payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * - (cis_lll->tx.bn - 1U - - (payload_count % cis_lll->tx.bn))); - while ((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) < - (cis_lll->event_count + 1U)) || - ((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) == - (cis_lll->event_count + 1U)) && (u <= (cis_lll->nse + 1U)))) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->sn++; - cis_lll->tx.bn_curr++; - if (cis_lll->tx.bn_curr > cis_lll->tx.bn) { - cis_lll->tx.payload_count += cis_lll->tx.bn; - cis_lll->tx.bn_curr = 1U; - } - - payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * - (cis_lll->tx.bn - 1U - - (payload_count % cis_lll->tx.bn))); - } - } - -payload_count_flush_or_inc_on_close_rx: - if (cis_lll->rx.bn) { - uint64_t payload_count; - uint8_t u; - - if (((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.bn_curr) > - (cis_lll->event_count + cis_lll->rx.bn)) { - cis_lll->rx.payload_count += cis_lll->rx.bn; - cis_lll->rx.bn_curr = 1U; - - return; - } - - payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * - (cis_lll->rx.bn - 1U - - (payload_count % cis_lll->rx.bn))); - while ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) < - (cis_lll->event_count + 1U)) || - ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) == - (cis_lll->event_count + 1U)) && (u <= (cis_lll->nse + 1U)))) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->nesn++; - cis_lll->rx.bn_curr++; - if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { - cis_lll->rx.payload_count += cis_lll->rx.bn; - cis_lll->rx.bn_curr = 1U; - } - - payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * - (cis_lll->rx.bn - 1U - - (payload_count % cis_lll->rx.bn))); - } - } -} - -static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy) -{ - if (cis_lll->tx.bn) { - uint16_t tx_lazy; - - tx_lazy = lazy; - while (tx_lazy--) { - uint64_t payload_count; - uint8_t u; - - payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * - (cis_lll->tx.bn - 1U - - (payload_count % cis_lll->tx.bn))); - while (((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) < - (cis_lll->event_count + 1U)) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->sn++; - cis_lll->tx.bn_curr++; - if (cis_lll->tx.bn_curr > cis_lll->tx.bn) { - cis_lll->tx.payload_count += cis_lll->tx.bn; - cis_lll->tx.bn_curr = 1U; - } - - payload_count = cis_lll->tx.payload_count + - cis_lll->tx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * - (cis_lll->tx.bn - 1U - - (payload_count % cis_lll->tx.bn))); - } - } - } - - if (cis_lll->rx.bn) { - while (lazy--) { - uint64_t payload_count; - uint8_t u; - - payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * - (cis_lll->rx.bn - 1U - - (payload_count % cis_lll->rx.bn))); - while (((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) < - (cis_lll->event_count + 1U)) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->nesn++; - cis_lll->rx.bn_curr++; - if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { - cis_lll->rx.payload_count += cis_lll->rx.bn; - cis_lll->rx.bn_curr = 1U; - } - - payload_count = cis_lll->rx.payload_count + - cis_lll->rx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * - (cis_lll->rx.bn - 1U - - (payload_count % cis_lll->rx.bn))); - } - } - } -} diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 75af765f9d0..3bbdb5fbf90 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -49,9 +49,8 @@ static void isr_prepare_subevent(void *param); static void isr_prepare_subevent_next_cis(void *param); static void isr_prepare_subevent_common(void *param); static void isr_done(void *param); -static void payload_count_flush(struct lll_conn_iso_stream *cis_lll); -static void payload_count_rx_flush_or_txrx_inc(struct lll_conn_iso_stream *cis_lll); -static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy); +static inline void lll_flush_tx(struct lll_conn_iso_stream *cis_lll); +static inline void lll_flush_rx(struct lll_conn_iso_stream *cis_lll); static uint8_t next_chan_use; static uint16_t data_chan_id; @@ -62,6 +61,7 @@ static uint32_t trx_performed_bitmask; static uint16_t cis_offset_first; static uint16_t cis_handle_curr; static uint8_t se_curr; +static uint8_t has_tx; #if defined(CONFIG_BT_CTLR_LE_ENC) static uint8_t mic_state; @@ -135,6 +135,24 @@ static int init_reset(void) return 0; } +static inline void lll_flush_tx(struct lll_conn_iso_stream *cis_lll) +{ + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + uint8_t sn_update = cis_lll->tx.bn + 1U - cis_lll->tx.bn_curr; + + /* TODO we'll re-use sn_update when implementing flush timeout */ + cis_lll->sn += sn_update; +} + +static inline void lll_flush_rx(struct lll_conn_iso_stream *cis_lll) +{ + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + uint8_t nesn_update = cis_lll->rx.bn + 1U - cis_lll->rx.bn_curr; + + /* TODO we'll re-use nesn_update when implementing flush timeout */ + cis_lll->nesn += nesn_update; +} + static int prepare_cb(struct lll_prepare_param *p) { struct lll_conn_iso_group *cig_lll = p->param; @@ -207,10 +225,14 @@ static int prepare_cb(struct lll_prepare_param *p) EVENT_US_TO_US_FRAC(cig_lll->window_widening_max_us); } - se_curr = 1U; - /* Adjust sn and nesn for skipped CIG events */ - payload_count_lazy(cis_lll, lazy); + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->sn += (cis_lll->tx.bn * lazy); + cis_lll->nesn += cis_lll->rx.bn * lazy; + + se_curr = 1U; + cis_lll->rx.bn_curr = 1U; + has_tx = 0U; /* Start setting up of Radio h/w */ radio_reset(); @@ -238,9 +260,8 @@ static int prepare_cb(struct lll_prepare_param *p) uint64_t payload_cnt; uint8_t pkt_flags; - payload_cnt = cis_lll->rx.payload_count + - cis_lll->rx.bn_curr - 1U; - + payload_cnt = (cis_lll->event_count * cis_lll->rx.bn) + + (cis_lll->rx.bn_curr - 1U); cis_lll->rx.ccm.counter = payload_cnt; pkt_flags = RADIO_PKT_CONF_FLAGS(RADIO_PKT_CONF_PDU_TYPE_CIS, @@ -351,10 +372,9 @@ static int prepare_cb(struct lll_prepare_param *p) /* Adjust the SN and NESN for skipped CIG events */ uint16_t cis_handle = cis_handle_curr; - do { - payload_count = cis_lll->tx.payload_count + - cis_lll->tx.bn_curr - 1U; - + while (true) { + /* FIXME: Update below implementation when supporting Flush Timeout */ + payload_count = cis_lll->event_count * cis_lll->tx.bn; do { link = memq_peek(cis_lll->memq_tx.head, cis_lll->memq_tx.tail, (void **)&tx); @@ -372,22 +392,26 @@ static int prepare_cb(struct lll_prepare_param *p) } } while (link); - do { - cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); - } while (cis_lll && !cis_lll->active); - + cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); if (!cis_lll) { break; } - /* Adjust sn and nesn for skipped CIG events */ - payload_count_lazy(cis_lll, lazy); - - /* Adjust sn and nesn for canceled events */ - if (err) { - payload_count_rx_flush_or_txrx_inc(cis_lll); + if (cis_lll->active) { + /* sn and nesn are 1-bit, only Least Significant bit is needed */ + cis_lll->sn += cis_lll->tx.bn * lazy; + cis_lll->nesn += cis_lll->rx.bn * lazy; + + /* Adjust sn and nesn for canceled events */ + if (err) { + /* Adjust nesn when flushing Rx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { + lll_flush_rx(cis_lll); + } + } } - } while (cis_lll); + }; /* Return if prepare callback cancelled */ if (err) { @@ -409,21 +433,24 @@ static void abort_cb(struct lll_prepare_param *prepare_param, void *param) /* NOTE: This is not a prepare being cancelled */ if (!prepare_param) { - struct lll_conn_iso_stream *next_cis_lll; + struct lll_conn_iso_group *cig_lll = param; struct lll_conn_iso_stream *cis_lll; - struct lll_conn_iso_group *cig_lll; - cis_lll = ull_conn_iso_lll_stream_get(cis_handle_curr); - cig_lll = param; + cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, NULL); - /* Adjust the SN, NESN and payload_count on abort for CISes */ - do { - next_cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, - &cis_handle_curr); - if (next_cis_lll && next_cis_lll->active) { - payload_count_rx_flush_or_txrx_inc(next_cis_lll); + /* FIXME: Consider Flush Timeout when resetting current burst number */ + if (!has_tx) { + has_tx = 1U; + + /* Adjust nesn when flushing Tx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { + lll_flush_tx(cis_lll); } - } while (next_cis_lll); + + /* Set to last burst number in previous event */ + cis_lll->tx.bn_curr = cis_lll->tx.bn; + } /* Perform event abort here. * After event has been cleanly aborted, clean up resources @@ -473,9 +500,20 @@ static void isr_rx(void *param) /* No Rx */ if (!trx_done) { - payload_count_flush(cis_lll); + /* FIXME: Consider Flush Timeout when resetting current burst number */ + if (!has_tx) { + has_tx = 1U; + + /* Adjust nesn when flushing Tx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { + lll_flush_tx(cis_lll); + } + + /* Start transmitting new burst */ + cis_lll->tx.bn_curr = cis_lll->tx.bn; + } - /* Next subevent or next CIS */ if (se_curr < cis_lll->nse) { radio_isr_set(isr_prepare_subevent, param); } else { @@ -524,20 +562,17 @@ static void isr_rx(void *param) pdu_rx = (void *)node_rx->pdu; /* Tx ACK */ - if ((pdu_rx->nesn != cis_lll->sn) && (cis_lll->tx.bn_curr <= cis_lll->tx.bn)) { + if (pdu_rx->nesn != cis_lll->sn) { + /* Increment sequence number */ cis_lll->sn++; - cis_lll->tx.bn_curr++; - if ((cis_lll->tx.bn_curr > cis_lll->tx.bn) && - ((cis_lll->tx.payload_count / cis_lll->tx.bn) < - cis_lll->event_count)) { - cis_lll->tx.payload_count += cis_lll->tx.bn; - cis_lll->tx.bn_curr = 1U; + + /* Increment burst number */ + if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { + cis_lll->tx.bn_curr++; } - /* TODO: Implement early Tx Ack. Currently Tx Ack - * generated as stale Tx Ack when payload count - * has elapsed. - */ + /* TODO: Tx Ack */ + } /* Handle valid ISO data Rx */ @@ -547,6 +582,7 @@ static void isr_rx(void *param) ull_iso_pdu_rx_alloc_peek(2U)) { struct node_rx_iso_meta *iso_meta; + /* Increment next expected sequence number */ cis_lll->nesn++; #if defined(CONFIG_BT_CTLR_LE_ENC) @@ -578,8 +614,9 @@ static void isr_rx(void *param) node_rx->hdr.type = NODE_RX_TYPE_ISO_PDU; node_rx->hdr.handle = cis_lll->handle; iso_meta = &node_rx->hdr.rx_iso_meta; - iso_meta->payload_number = cis_lll->rx.payload_count + - cis_lll->rx.bn_curr - 1U; + iso_meta->payload_number = (cis_lll->event_count * + cis_lll->rx.bn) + + (cis_lll->rx.bn_curr - 1U); iso_meta->timestamp = cis_lll->offset + HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + radio_tmr_aa_restore() - cis_offset_first - @@ -595,19 +632,46 @@ static void isr_rx(void *param) iso_rx_sched(); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ + /* Increment burst number */ cis_lll->rx.bn_curr++; - if ((cis_lll->rx.bn_curr > cis_lll->rx.bn) && - ((cis_lll->rx.payload_count / cis_lll->rx.bn) < cis_lll->event_count)) { - cis_lll->rx.payload_count += cis_lll->rx.bn; - cis_lll->rx.bn_curr = 1U; + + /* Handle NULL PDU indication received */ + } else if (pdu_rx->npi) { + /* Source could not send ISO data, increment NESN as if + * we received and expect to receive the next PDU in the + * burst. + */ + if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { + /* Increment next expected serial number */ + cis_lll->nesn++; + + /* Increment burst number */ + cis_lll->rx.bn_curr++; } + + /* Not NPI, or more than the BN, or no free Rx ISO PDU buffers. + */ + } else { + /* Do nothing, ignore the Rx buffer */ } /* Close Isochronous Event */ cie = cie || pdu_rx->cie; } - payload_count_flush(cis_lll); + /* FIXME: Consider Flush Timeout when resetting current burst number */ + if (!has_tx) { + has_tx = 1U; + + /* Adjust nesn when flushing Tx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { + lll_flush_tx(cis_lll); + } + + /* Start transmitting new burst */ + cis_lll->tx.bn_curr = 1U; + } /* Close Isochronous Event */ cie = cie || ((cis_lll->rx.bn_curr > cis_lll->rx.bn) && @@ -632,7 +696,8 @@ static void isr_rx(void *param) memq_link_t *link; payload_index = cis_lll->tx.bn_curr - 1U; - payload_count = cis_lll->tx.payload_count + payload_index; + payload_count = cis_lll->event_count * cis_lll->tx.bn + + payload_index; link = memq_peek_n(cis_lll->memq_tx.head, cis_lll->memq_tx.tail, payload_index, (void **)&tx); @@ -736,7 +801,6 @@ static void isr_rx(void *param) &data_chan_prn_s, &data_chan_remap_idx); } else { - struct lll_conn_iso_stream *next_cis_lll; struct lll_conn_iso_group *cig_lll; uint16_t event_counter; uint16_t cis_handle; @@ -745,34 +809,34 @@ static void isr_rx(void *param) cig_lll = ull_conn_iso_lll_group_get_by_stream(cis_lll); cis_handle = cis_handle_curr; do { - next_cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); - } while (next_cis_lll && !next_cis_lll->active); + cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); + } while (cis_lll && !cis_lll->active); - if (!next_cis_lll) { + if (!cis_lll) { /* ISO Event Done */ radio_isr_set(isr_done, param); return; } - payload_count_rx_flush_or_txrx_inc(cis_lll); - cis_handle_curr = cis_handle; /* Event counter value, 0-15 bit of cisEventCounter */ - event_counter = next_cis_lll->event_count; + event_counter = cis_lll->event_count; /* Calculate the radio channel to use for next CIS ISO event */ - data_chan_id = lll_chan_id(next_cis_lll->access_addr); + data_chan_id = lll_chan_id(cis_lll->access_addr); next_chan_use = lll_chan_iso_event(event_counter, data_chan_id, conn_lll->data_chan_map, conn_lll->data_chan_count, &data_chan_prn_s, &data_chan_remap_idx); - /* Next CIS, se_curr is incremented in isr_tx() */ - cis_lll = next_cis_lll; - se_curr = 0U; + /* Reset indices for the next CIS */ + se_curr = 0U; /* isr_tx() will increase se_curr */ + cis_lll->tx.bn_curr = 1U; /* FIXME: may be this should be previous event value? */ + cis_lll->rx.bn_curr = 1U; + has_tx = 0U; } /* Schedule next subevent reception */ @@ -830,9 +894,8 @@ static void isr_tx(void *param) uint64_t payload_count; uint8_t pkt_flags; - payload_count = cis_lll->rx.payload_count + - cis_lll->rx.bn_curr - 1U; - + payload_count = (cis_lll->event_count * cis_lll->rx.bn) + + (cis_lll->rx.bn_curr - 1U); cis_lll->rx.ccm.counter = payload_count; pkt_flags = RADIO_PKT_CONF_FLAGS(RADIO_PKT_CONF_PDU_TYPE_CIS, @@ -933,7 +996,6 @@ static void isr_tx(void *param) static void next_cis_prepare(void *param) { - struct lll_conn_iso_stream *next_cis_lll; struct lll_conn_iso_stream *cis_lll; struct lll_conn_iso_group *cig_lll; uint16_t cis_handle; @@ -943,13 +1005,12 @@ static void next_cis_prepare(void *param) /* Check for next active CIS */ cig_lll = ull_conn_iso_lll_group_get_by_stream(cis_lll); - next_cis_lll = cis_lll; cis_handle = cis_handle_curr; do { - next_cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); - } while (next_cis_lll && !next_cis_lll->active); + cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, &cis_handle); + } while (cis_lll && !cis_lll->active); - if (!next_cis_lll) { + if (!cis_lll) { /* ISO Event Done */ radio_isr_set(isr_done, param); @@ -958,7 +1019,7 @@ static void next_cis_prepare(void *param) cis_handle_curr = cis_handle; - radio_isr_set(isr_prepare_subevent_next_cis, next_cis_lll); + radio_isr_set(isr_prepare_subevent_next_cis, cis_lll); } static void isr_prepare_subevent(void *param) @@ -1010,8 +1071,11 @@ static void isr_prepare_subevent_next_cis(void *param) &data_chan_prn_s, &data_chan_remap_idx); - /* se_curr is incremented in isr_prepare_subevent_common() */ - se_curr = 0U; + /* Reset indices for the next CIS */ + se_curr = 0U; /* isr_prepare_subevent_common() will increase se_curr */ + cis_lll->tx.bn_curr = 1U; /* FIXME: may be this should be previous event value? */ + cis_lll->rx.bn_curr = 1U; + has_tx = 0U; isr_prepare_subevent_common(param); } @@ -1047,9 +1111,8 @@ static void isr_prepare_subevent_common(void *param) uint64_t payload_count; uint8_t pkt_flags; - payload_count = cis_lll->rx.payload_count + - cis_lll->rx.bn_curr - 1U; - + payload_count = (cis_lll->event_count * cis_lll->rx.bn) + + (cis_lll->rx.bn_curr - 1U); cis_lll->rx.ccm.counter = payload_count; pkt_flags = RADIO_PKT_CONF_FLAGS(RADIO_PKT_CONF_PDU_TYPE_CIS, @@ -1172,7 +1235,11 @@ static void isr_done(void *param) /* Get reference to CIS LLL context */ cis_lll = param; - payload_count_rx_flush_or_txrx_inc(cis_lll); + /* Adjust nesn when flushing Rx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { + lll_flush_rx(cis_lll); + } e = ull_event_done_extra_get(); LL_ASSERT(e); @@ -1208,177 +1275,3 @@ static void isr_done(void *param) lll_isr_cleanup(param); } - -static void payload_count_flush(struct lll_conn_iso_stream *cis_lll) -{ - if (cis_lll->tx.bn) { - uint64_t payload_count; - uint8_t u; - - payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * - (cis_lll->tx.bn - 1U - - (payload_count % cis_lll->tx.bn))); - while (((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) < - (cis_lll->event_count + 1U)) || - ((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) == - (cis_lll->event_count + 1U)) && (u < se_curr))) && - (((cis_lll->tx.bn_curr < cis_lll->tx.bn) && - ((cis_lll->tx.payload_count / cis_lll->tx.bn) <= cis_lll->event_count)) || - ((cis_lll->tx.bn_curr == cis_lll->tx.bn) && - ((cis_lll->tx.payload_count / cis_lll->tx.bn) < cis_lll->event_count)))) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->sn++; - cis_lll->tx.bn_curr++; - if (cis_lll->tx.bn_curr > cis_lll->tx.bn) { - cis_lll->tx.payload_count += cis_lll->tx.bn; - cis_lll->tx.bn_curr = 1U; - } - - payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * - (cis_lll->tx.bn - 1U - - (payload_count % cis_lll->tx.bn))); - } - } - - if (cis_lll->rx.bn) { - uint64_t payload_count; - uint8_t u; - - payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * - (cis_lll->rx.bn - 1U - - (payload_count % cis_lll->rx.bn))); - if ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) == - (cis_lll->event_count + 1U)) && (u <= se_curr) && - (((cis_lll->rx.bn_curr < cis_lll->rx.bn) && - ((cis_lll->rx.payload_count / cis_lll->rx.bn) <= cis_lll->event_count)) || - ((cis_lll->rx.bn_curr == cis_lll->rx.bn) && - ((cis_lll->rx.payload_count / cis_lll->rx.bn) < cis_lll->event_count)))) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->nesn++; - cis_lll->rx.bn_curr++; - if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { - cis_lll->rx.payload_count += cis_lll->rx.bn; - cis_lll->rx.bn_curr = 1U; - } - } - } -} - -static void payload_count_rx_flush_or_txrx_inc(struct lll_conn_iso_stream *cis_lll) -{ - if (cis_lll->tx.bn) { - if (((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.bn_curr) > - (cis_lll->event_count + cis_lll->tx.bn)) { - cis_lll->tx.payload_count += cis_lll->tx.bn; - cis_lll->tx.bn_curr = 1U; - } - } - - if (cis_lll->rx.bn) { - uint64_t payload_count; - uint8_t u; - - if (((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.bn_curr) > - (cis_lll->event_count + cis_lll->rx.bn)) { - cis_lll->rx.payload_count += cis_lll->rx.bn; - cis_lll->rx.bn_curr = 1U; - - return; - } - - payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * - (cis_lll->rx.bn - 1U - - (payload_count % cis_lll->rx.bn))); - while ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) < - (cis_lll->event_count + 1U)) || - ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) == - (cis_lll->event_count + 1U)) && (u <= (cis_lll->nse + 1U)))) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->nesn++; - cis_lll->rx.bn_curr++; - if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { - cis_lll->rx.payload_count += cis_lll->rx.bn; - cis_lll->rx.bn_curr = 1U; - } - - payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * - (cis_lll->rx.bn - 1U - - (payload_count % cis_lll->rx.bn))); - } - } -} - -static void payload_count_lazy(struct lll_conn_iso_stream *cis_lll, uint16_t lazy) -{ - if (cis_lll->tx.bn && lazy) { - uint16_t tx_lazy; - - tx_lazy = lazy; - while (tx_lazy--) { - uint64_t payload_count; - uint8_t u; - - payload_count = cis_lll->tx.payload_count + cis_lll->tx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * - (cis_lll->tx.bn - 1U - - (payload_count % cis_lll->tx.bn))); - while (((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) < - (cis_lll->event_count + 1U)) || - ((((cis_lll->tx.payload_count / cis_lll->tx.bn) + cis_lll->tx.ft) == - (cis_lll->event_count + 1U)) && (u < (cis_lll->nse + 1U)))) && - ((cis_lll->tx.payload_count / cis_lll->tx.bn) < - cis_lll->event_count)) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->sn++; - cis_lll->tx.bn_curr++; - if (cis_lll->tx.bn_curr > cis_lll->tx.bn) { - cis_lll->tx.payload_count += cis_lll->tx.bn; - cis_lll->tx.bn_curr = 1U; - } - - payload_count = cis_lll->tx.payload_count + - cis_lll->tx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->tx.bn) * - (cis_lll->tx.bn - 1U - - (payload_count % cis_lll->tx.bn))); - } - } - } - - if (cis_lll->rx.bn) { - while (lazy--) { - uint64_t payload_count; - uint8_t u; - - payload_count = cis_lll->rx.payload_count + cis_lll->rx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * - (cis_lll->rx.bn - 1U - - (payload_count % cis_lll->rx.bn))); - while (((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) < - (cis_lll->event_count + 1U)) || - ((((cis_lll->rx.payload_count / cis_lll->rx.bn) + cis_lll->rx.ft) == - (cis_lll->event_count + 1U)) && (u <= (cis_lll->nse + 1U)))) && - ((cis_lll->rx.payload_count / cis_lll->rx.bn) < - cis_lll->event_count)) { - /* sn and nesn are 1-bit, only Least Significant bit is needed */ - cis_lll->nesn++; - cis_lll->rx.bn_curr++; - if (cis_lll->rx.bn_curr > cis_lll->rx.bn) { - cis_lll->rx.payload_count += cis_lll->rx.bn; - cis_lll->rx.bn_curr = 1U; - } - - payload_count = cis_lll->rx.payload_count + - cis_lll->rx.bn_curr - 1U; - u = cis_lll->nse - ((cis_lll->nse / cis_lll->rx.bn) * - (cis_lll->rx.bn - 1U - - (payload_count % cis_lll->rx.bn))); - } - } - } -} From a102589e3b426b2fa2f2a0ec5661766877299265 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:57 +0000 Subject: [PATCH 0674/1623] Revert "[nrf fromtree] Bluetooth: Controller: Remove HCI ISO data with invalid status" This reverts commit 495dce2550cd4bba79af1b4429d8ab8f377244d4. Signed-off-by: Dominik Ermel --- .../ll_sw/nordic/lll/lll_central_iso.c | 97 +++++++++++++++++-- .../ll_sw/nordic/lll/lll_peripheral_iso.c | 43 ++++++++ 2 files changed, 132 insertions(+), 8 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 936087369f1..46360ef88d7 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -845,6 +845,7 @@ static void isr_rx(void *param) struct lll_conn_iso_group *cig_lll; struct lll_conn *next_conn_lll; uint8_t phy; + uint8_t bn; /* Fetch next CIS */ /* TODO: Use a new ull_conn_iso_lll_stream_get_active_by_group() @@ -860,6 +861,18 @@ static void isr_rx(void *param) goto isr_rx_done; } + /* Adjust sn when flushing Tx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { + lll_flush_tx(cis_lll); + } + + /* Adjust nesn when flushing Rx */ + /* FIXME: When Flush Timeout is implemented */ + if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { + lll_flush_rx(cis_lll); + } + /* Get reference to ACL context */ next_conn_lll = ull_conn_lll_get(next_cis_lll->acl_handle); @@ -927,17 +940,45 @@ static void isr_rx(void *param) cis_lll = old_cis_lll; } - /* Adjust sn when flushing Tx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) { - lll_flush_tx(cis_lll); + /* Generate ISO Data Invalid Status */ + bn = cis_lll->rx.bn_curr; + while (bn <= cis_lll->rx.bn) { + struct node_rx_iso_meta *iso_meta; + struct node_rx_pdu *status_node_rx; + + /* Ensure there is always one free for reception + * of ISO PDU by the radio h/w DMA, hence peek + * for two available ISO PDU when using one for + * generating invalid ISO data. + */ + status_node_rx = ull_iso_pdu_rx_alloc_peek(2U); + if (!status_node_rx) { + break; + } + + status_node_rx->hdr.type = NODE_RX_TYPE_ISO_PDU; + status_node_rx->hdr.handle = cis_lll->handle; + iso_meta = &status_node_rx->hdr.rx_iso_meta; + iso_meta->payload_number = (cis_lll->event_count * + cis_lll->rx.bn) + (bn - 1U); + iso_meta->timestamp = + HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + + radio_tmr_ready_restore(); + iso_meta->timestamp %= + HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); + iso_meta->status = 1U; + + ull_iso_pdu_rx_alloc(); + iso_rx_put(status_node_rx->hdr.link, status_node_rx); + + bn++; } - /* Adjust nesn when flushing Rx */ - /* FIXME: When Flush Timeout is implemented */ - if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) { - lll_flush_rx(cis_lll); +#if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) + if (bn != cis_lll->rx.bn_curr) { + iso_rx_sched(); } +#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ /* Reset indices for the next CIS */ se_curr = 0U; /* isr_prepare_subevent() will increase se_curr */ @@ -1135,6 +1176,7 @@ static void isr_done(void *param) { struct lll_conn_iso_stream *cis_lll; struct event_done_extra *e; + uint8_t bn; lll_isr_status_reset(); @@ -1153,6 +1195,45 @@ static void isr_done(void *param) lll_flush_rx(cis_lll); } + /* Generate ISO Data Invalid Status */ + bn = cis_lll->rx.bn_curr; + while (bn <= cis_lll->rx.bn) { + struct node_rx_iso_meta *iso_meta; + struct node_rx_pdu *node_rx; + + /* Ensure there is always one free for reception of ISO PDU by + * the radio h/w DMA, hence peek for two available ISO PDU when + * using one for generating invalid ISO data. + */ + node_rx = ull_iso_pdu_rx_alloc_peek(2U); + if (!node_rx) { + break; + } + + node_rx->hdr.type = NODE_RX_TYPE_ISO_PDU; + node_rx->hdr.handle = cis_lll->handle; + iso_meta = &node_rx->hdr.rx_iso_meta; + iso_meta->payload_number = (cis_lll->event_count * + cis_lll->rx.bn) + (bn - 1U); + iso_meta->timestamp = + HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + + radio_tmr_ready_restore(); + iso_meta->timestamp %= + HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); + iso_meta->status = 1U; + + ull_iso_pdu_rx_alloc(); + iso_rx_put(node_rx->hdr.link, node_rx); + + bn++; + } + +#if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) + if (bn != cis_lll->rx.bn_curr) { + iso_rx_sched(); + } +#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ + e = ull_event_done_extra_get(); LL_ASSERT(e); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 3bbdb5fbf90..13238c081cf 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -1229,6 +1229,7 @@ static void isr_done(void *param) { struct lll_conn_iso_stream *cis_lll; struct event_done_extra *e; + uint8_t bn; lll_isr_status_reset(); @@ -1241,6 +1242,48 @@ static void isr_done(void *param) lll_flush_rx(cis_lll); } + /* Generate ISO Data Invalid Status */ + bn = cis_lll->rx.bn_curr; + while (bn <= cis_lll->rx.bn) { + struct node_rx_iso_meta *iso_meta; + struct node_rx_pdu *node_rx; + + node_rx = ull_iso_pdu_rx_alloc_peek(2U); + if (!node_rx) { + break; + } + + node_rx->hdr.type = NODE_RX_TYPE_ISO_PDU; + node_rx->hdr.handle = cis_lll->handle; + iso_meta = &node_rx->hdr.rx_iso_meta; + iso_meta->payload_number = (cis_lll->event_count * + cis_lll->rx.bn) + (bn - 1U); + if (trx_performed_bitmask) { + iso_meta->timestamp = cis_lll->offset + + HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + + radio_tmr_aa_restore() - cis_offset_first - + addr_us_get(cis_lll->rx.phy); + } else { + iso_meta->timestamp = cis_lll->offset + + HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + + radio_tmr_ready_restore() - cis_offset_first; + } + iso_meta->timestamp %= + HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); + iso_meta->status = 1U; + + ull_iso_pdu_rx_alloc(); + iso_rx_put(node_rx->hdr.link, node_rx); + + bn++; + } + +#if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) + if (bn != cis_lll->rx.bn_curr) { + iso_rx_sched(); + } +#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ + e = ull_event_done_extra_get(); LL_ASSERT(e); From 38bf5250815f52d5851332d99dac39788144d699 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:57 +0000 Subject: [PATCH 0675/1623] Revert "[nrf fromtree] Bluetooth controller nrf: Provide radio hal header for simulated nrf5340" This reverts commit 10552082f75c89d7b69b7ad5b4ee815d84348761. Signed-off-by: Dominik Ermel --- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h | 2 - .../nordic/hal/nrf5/radio/radio_sim_nrf5340.h | 431 ------------------ 2 files changed, 433 deletions(-) delete mode 100644 subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf5340.h diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h index 842b4189184..9e29ab5f70b 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h @@ -17,8 +17,6 @@ /* SoC specific defines */ #if defined(CONFIG_BOARD_NRF52_BSIM) #include "radio_sim_nrf52.h" -#elif defined(CONFIG_BOARD_NRF5340BSIM_NRF5340_CPUNET) -#include "radio_sim_nrf5340.h" #elif defined(CONFIG_SOC_SERIES_NRF51X) #include "radio_nrf51.h" #elif defined(CONFIG_SOC_NRF52805) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf5340.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf5340.h deleted file mode 100644 index c0cd88b30b0..00000000000 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf5340.h +++ /dev/null @@ -1,431 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * Copyright (c) 2019 Ioannis Glaropoulos - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/* NRF Radio HW timing constants - * - provided in US and NS (for higher granularity) - * - based on the timings configured in the HW models, which are based - * on the product specification - * - Note that this timings are approx. the same as in the real HW, - * but tend to be rounded to the nearest microsecond - */ - -/* Override EVENT_TIMER_ID from 4 to 0, as nRF5340 does not have 4 timer - * instances. - */ -#if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) -#undef EVENT_TIMER_ID -#define EVENT_TIMER_ID 0 - -#undef EVENT_TIMER -#define EVENT_TIMER _CONCAT(NRF_TIMER, EVENT_TIMER_ID) - -#undef SW_SWITCH_TIMER -#define SW_SWITCH_TIMER EVENT_TIMER -#endif /* CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ - -/* TXEN->TXIDLE + TXIDLE->TX (with fast Radio ramp-up mode) - * in microseconds for LE 1M PHY. - */ -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_FAST_NS 41000 -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_FAST_US \ - HAL_RADIO_NS2US_ROUND(HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_FAST_NS) - -/* TXEN->TXIDLE + TXIDLE->TX (with default Radio ramp-up mode) - * in microseconds for LE 1M PHY. - */ -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NS 141000 -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_US \ - HAL_RADIO_NS2US_ROUND(HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NS) - -/* TXEN->TXIDLE + TXIDLE->TX (with default Radio ramp-up mode - * and no HW TIFS auto-switch) in microseconds for LE 1M PHY. - */ - /* 129.5 + 0.8 */ -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NO_HW_TIFS_NS 130000 -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NO_HW_TIFS_US \ - HAL_RADIO_NS2US_ROUND( \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NO_HW_TIFS_NS) - -/* TXEN->TXIDLE + TXIDLE->TX (with fast Radio ramp-up mode) - * in microseconds for LE 2M PHY. - */ -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_FAST_NS 40000 -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_FAST_US \ - HAL_RADIO_NS2US_ROUND(HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_FAST_NS) - -/* TXEN->TXIDLE + TXIDLE->TX (with default Radio ramp-up mode) - * in microseconds for LE 2M PHY. - */ -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NS 140000 -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_US \ - HAL_RADIO_NS2US_ROUND(HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NS) - -/* TXEN->TXIDLE + TXIDLE->TX (with default Radio ramp-up mode and - * no HW TIFS auto-switch) in microseconds for LE 2M PHY. - */ -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NO_HW_TIFS_NS 129000 -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NO_HW_TIFS_US \ - HAL_RADIO_NS2US_ROUND( \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NO_HW_TIFS_NS) - -/* RXEN->RXIDLE + RXIDLE->RX (with fast Radio ramp-up mode) - * in microseconds for LE 1M PHY. - */ -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_FAST_NS 40000 -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_FAST_US \ - HAL_RADIO_NS2US_CEIL(HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_FAST_NS) - -/* RXEN->RXIDLE + RXIDLE->RX (with default Radio ramp-up mode) - * in microseconds for LE 1M PHY. - */ -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NS 140000 -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_US \ - HAL_RADIO_NS2US_CEIL(HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NS) - -/* RXEN->RXIDLE + RXIDLE->RX (with default Radio ramp-up mode and - * no HW TIFS auto-switch) in microseconds for LE 1M PHY. - */ -/* 129.5 + 0.2 */ -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NO_HW_TIFS_NS 129000 -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NO_HW_TIFS_US \ - HAL_RADIO_NS2US_CEIL( \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NO_HW_TIFS_NS) - -/* RXEN->RXIDLE + RXIDLE->RX (with fast Radio ramp-up mode) - * in microseconds for LE 2M PHY. - */ -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_FAST_NS 40000 -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_FAST_US \ - HAL_RADIO_NS2US_CEIL(HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_FAST_NS) - -/* RXEN->RXIDLE + RXIDLE->RX (with default Radio ramp-up mode) - * in microseconds for LE 2M PHY. - */ -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NS 140000 -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_US \ - HAL_RADIO_NS2US_CEIL(HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NS) - -/* RXEN->RXIDLE + RXIDLE->RX (with default Radio ramp-up mode and - * no HW TIFS auto-switch) in microseconds for LE 2M PHY. - */ -/* 129.5 + 0.2 */ -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NO_HW_TIFS_NS 129000 -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NO_HW_TIFS_US \ - HAL_RADIO_NS2US_CEIL( \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NO_HW_TIFS_NS) - -#define HAL_RADIO_NRF5340_TX_CHAIN_DELAY_NS 1000 -#define HAL_RADIO_NRF5340_TX_CHAIN_DELAY_US \ - HAL_RADIO_NS2US_CEIL(HAL_RADIO_NRF5340_TX_CHAIN_DELAY_NS) - -#define HAL_RADIO_NRF5340_RX_CHAIN_DELAY_1M_US 9 -#define HAL_RADIO_NRF5340_RX_CHAIN_DELAY_1M_NS 9000 -#define HAL_RADIO_NRF5340_RX_CHAIN_DELAY_2M_US 5 -#define HAL_RADIO_NRF5340_RX_CHAIN_DELAY_2M_NS 5000 - -#if defined(CONFIG_BT_CTLR_RADIO_ENABLE_FAST) -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_US \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_FAST_US -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_NS \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_FAST_NS - -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_US \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_FAST_US -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_NS \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_FAST_NS - -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_US \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_FAST_US -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_NS \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_FAST_NS - -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_US \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_FAST_US -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_NS \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_FAST_NS - -#else /* !CONFIG_BT_CTLR_RADIO_ENABLE_FAST */ -#if defined(CONFIG_BT_CTLR_TIFS_HW) -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_US \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_US -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_NS \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NS - -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_US \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_US -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_NS \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NS - -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_US \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_US -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_NS \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NS - -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_US \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_US -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_NS \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NS - -#else /* !CONFIG_BT_CTLR_TIFS_HW */ -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_US \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NO_HW_TIFS_US -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_NS \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_DEFAULT_NO_HW_TIFS_NS - -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_US \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NO_HW_TIFS_US -#define HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_NS \ - HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_DEFAULT_NO_HW_TIFS_NS - -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_US \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NO_HW_TIFS_US -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_NS \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_DEFAULT_NO_HW_TIFS_NS - -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_US \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NO_HW_TIFS_US -#define HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_NS \ - HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_DEFAULT_NO_HW_TIFS_NS - -#endif /* !CONFIG_BT_CTLR_TIFS_HW */ -#endif /* !CONFIG_BT_CTLR_RADIO_ENABLE_FAST */ - -/* nRF5340 supports +3dBm Tx Power using high voltage request, define +3dBm - * value for Controller use. - */ -#ifndef RADIO_TXPOWER_TXPOWER_Pos3dBm -#define RADIO_TXPOWER_TXPOWER_Pos3dBm (0x03UL) -#endif - -/* SoC specific NRF_RADIO power-on reset value. Refer to Product Specification, - * RADIO Registers section for the documented reset values. - * - * NOTE: Only implementation used values defined here. - * In the future if MDK or nRFx header include these, use them instead. - */ -#define HAL_RADIO_RESET_VALUE_DFEMODE 0x00000000UL -#define HAL_RADIO_RESET_VALUE_CTEINLINECONF 0x00002800UL - -static inline void hal_radio_tx_power_high_voltage_clear(void); - -static inline void hal_radio_reset(void) -{ -} - -static inline void hal_radio_stop(void) -{ - /* If +3dBm Tx power was used, then turn off high voltage when radio not - * used. - */ - hal_radio_tx_power_high_voltage_clear(); -} - -static inline void hal_radio_ram_prio_setup(void) -{ -} - -static inline uint32_t hal_radio_phy_mode_get(uint8_t phy, uint8_t flags) -{ - uint32_t mode; - - switch (phy) { - case BIT(0): - default: - mode = RADIO_MODE_MODE_Ble_1Mbit; - break; - - case BIT(1): - mode = RADIO_MODE_MODE_Ble_2Mbit; - break; - -#if defined(CONFIG_BT_CTLR_PHY_CODED) - case BIT(2): - if (flags & 0x01) { - mode = RADIO_MODE_MODE_Ble_LR125Kbit; - } else { - mode = RADIO_MODE_MODE_Ble_LR500Kbit; - } - break; -#endif /* CONFIG_BT_CTLR_PHY_CODED */ - } - - return mode; -} - -static inline uint32_t hal_radio_tx_power_max_get(void) -{ - return RADIO_TXPOWER_TXPOWER_0dBm; -} - -static inline uint32_t hal_radio_tx_power_min_get(void) -{ - return RADIO_TXPOWER_TXPOWER_Neg40dBm; -} - -static inline uint32_t hal_radio_tx_power_floor(int8_t tx_power_lvl) -{ - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_0dBm) { - return RADIO_TXPOWER_TXPOWER_0dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg1dBm) { - return RADIO_TXPOWER_TXPOWER_Neg1dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg2dBm) { - return RADIO_TXPOWER_TXPOWER_Neg2dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg3dBm) { - return RADIO_TXPOWER_TXPOWER_Neg3dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg4dBm) { - return RADIO_TXPOWER_TXPOWER_Neg4dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg5dBm) { - return RADIO_TXPOWER_TXPOWER_Neg5dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg6dBm) { - return RADIO_TXPOWER_TXPOWER_Neg6dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg7dBm) { - return RADIO_TXPOWER_TXPOWER_Neg7dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg8dBm) { - return RADIO_TXPOWER_TXPOWER_Neg8dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg12dBm) { - return RADIO_TXPOWER_TXPOWER_Neg12dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg16dBm) { - return RADIO_TXPOWER_TXPOWER_Neg16dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg20dBm) { - return RADIO_TXPOWER_TXPOWER_Neg20dBm; - } - - /* Note: The -30 dBm power level is deprecated so ignore it! */ - return RADIO_TXPOWER_TXPOWER_Neg40dBm; -} - -static inline void hal_radio_tx_power_high_voltage_set(int8_t tx_power_lvl) -{ - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos3dBm) { - nrf_vreqctrl_radio_high_voltage_set(NRF_VREQCTRL, true); - } -} - -static inline void hal_radio_tx_power_high_voltage_clear(void) -{ - nrf_vreqctrl_radio_high_voltage_set(NRF_VREQCTRL, false); -} - -static inline uint32_t hal_radio_tx_ready_delay_us_get(uint8_t phy, uint8_t flags) -{ - ARG_UNUSED(flags); - - switch (phy) { - default: - case BIT(0): - return HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_US; - case BIT(1): - return HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_US; - } -} - -static inline uint32_t hal_radio_rx_ready_delay_us_get(uint8_t phy, uint8_t flags) -{ - ARG_UNUSED(flags); - - switch (phy) { - default: - case BIT(0): - return HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_US; - case BIT(1): - return HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_US; - } -} - -static inline uint32_t hal_radio_tx_chain_delay_us_get(uint8_t phy, uint8_t flags) -{ - ARG_UNUSED(phy); - ARG_UNUSED(flags); - - return HAL_RADIO_NRF5340_TX_CHAIN_DELAY_US; -} - -static inline uint32_t hal_radio_rx_chain_delay_us_get(uint8_t phy, uint8_t flags) -{ - ARG_UNUSED(flags); - - switch (phy) { - default: - case BIT(0): - return HAL_RADIO_NRF5340_RX_CHAIN_DELAY_1M_US; - case BIT(1): - return HAL_RADIO_NRF5340_RX_CHAIN_DELAY_2M_US; - } -} - -static inline uint32_t hal_radio_tx_ready_delay_ns_get(uint8_t phy, uint8_t flags) -{ - ARG_UNUSED(flags); - - switch (phy) { - default: - case BIT(0): - return HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_1M_NS; - case BIT(1): - return HAL_RADIO_NRF5340_TXEN_TXIDLE_TX_2M_NS; - } -} - -static inline uint32_t hal_radio_rx_ready_delay_ns_get(uint8_t phy, uint8_t flags) -{ - ARG_UNUSED(flags); - - switch (phy) { - default: - case BIT(0): - return HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_1M_NS; - case BIT(1): - return HAL_RADIO_NRF5340_RXEN_RXIDLE_RX_2M_NS; - } -} - -static inline uint32_t hal_radio_tx_chain_delay_ns_get(uint8_t phy, uint8_t flags) -{ - ARG_UNUSED(phy); - ARG_UNUSED(flags); - - return HAL_RADIO_NRF5340_TX_CHAIN_DELAY_NS; -} - -static inline uint32_t hal_radio_rx_chain_delay_ns_get(uint8_t phy, uint8_t flags) -{ - ARG_UNUSED(flags); - - switch (phy) { - default: - case BIT(0): - return HAL_RADIO_NRF5340_RX_CHAIN_DELAY_1M_NS; - case BIT(1): - return HAL_RADIO_NRF5340_RX_CHAIN_DELAY_2M_NS; - - } -} From 309de192c5ea78ae783f3557de57085b2ee6fdb2 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:57 +0000 Subject: [PATCH 0676/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix clang warning on ull" This reverts commit 4b5aac399c721b01dfd7924ce565d367e526fa59. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 3130978df4e..9811076b9ba 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -1232,8 +1232,10 @@ void ll_rx_dequeue(void) /* FIXME: use the correct adv and scan set to get * enabled status bitmask */ - bm = (IS_ENABLED(CONFIG_BT_OBSERVER)?(ull_scan_is_enabled(0) << 1):0) | - (IS_ENABLED(CONFIG_BT_BROADCASTER)?ull_adv_is_enabled(0):0); + bm = (IS_ENABLED(CONFIG_BT_OBSERVER) && + (ull_scan_is_enabled(0) << 1)) | + (IS_ENABLED(CONFIG_BT_BROADCASTER) && + ull_adv_is_enabled(0)); if (!bm) { ull_filter_adv_scan_state_cb(0); From 10afa7e7695f03b5ed60c74fc2e486c16aac0600 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:58 +0000 Subject: [PATCH 0677/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix regression in Adv PDU overflow calculation" This reverts commit a993ec04f01370731fd9fbdb1eaec298d865beff. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_adv_aux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c index 302dc6da785..5349b21dd9f 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c @@ -1804,7 +1804,7 @@ uint8_t ull_adv_aux_hdr_set_clear(struct ll_adv_set *adv, /* TODO: need aux_chain_ind support */ if ((sec_len + ad_len + ad_fragment_len) > PDU_AC_PAYLOAD_SIZE_MAX) { /* return excess length */ - *(uint8_t *)hdr_data = sec_len + ad_len + ad_fragment_len - + *(uint8_t *)hdr_data = sec_len + ad_len - PDU_AC_PAYLOAD_SIZE_MAX; if (pri_pdu == pri_pdu_prev) { @@ -2272,7 +2272,7 @@ uint8_t ull_adv_aux_pdu_set_clear(struct ll_adv_set *adv, /* Check AdvData overflow */ if ((len + ad_len + ad_fragment_len) > PDU_AC_PAYLOAD_SIZE_MAX) { /* return excess length */ - *(uint8_t *)hdr_data = len + ad_len + ad_fragment_len - + *(uint8_t *)hdr_data = len + ad_len - PDU_AC_PAYLOAD_SIZE_MAX; /* Will use packet too long error to determine fragmenting From 172ea10cdf91b8f60c201f7875bbb2dcdd0a677a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:58 +0000 Subject: [PATCH 0678/1623] Revert "[nrf fromtree] Bluetooth: controller: adding API for unmasking peer features" This reverts commit 340f46a013f08c35562f1aa1d75464e61246b77e. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c | 4 ++-- subsys/bluetooth/controller/ll_sw/ull_llcp_features.h | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c b/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c index 59c23e7a0f6..69dc80bda13 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c @@ -921,14 +921,14 @@ static void lp_cc_st_wait_rx_cis_rsp(struct ll_conn *conn, struct proc_ctx *ctx, break; case LP_CC_EVT_UNKNOWN: /* Unsupported in peer, so disable locally for this connection */ - feature_unmask_peer_features(conn, LL_FEAT_BIT_CIS_PERIPHERAL); + feature_unmask_features(conn, LL_FEAT_BIT_CIS_PERIPHERAL); ctx->data.cis_create.error = BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; lp_cc_complete(conn, ctx, evt, param); break; case LP_CC_EVT_REJECT: if (pdu->llctrl.reject_ext_ind.error_code == BT_HCI_ERR_UNSUPP_REMOTE_FEATURE) { /* Unsupported in peer, so disable locally for this connection */ - feature_unmask_peer_features(conn, LL_FEAT_BIT_CIS_PERIPHERAL); + feature_unmask_features(conn, LL_FEAT_BIT_CIS_PERIPHERAL); } ctx->data.cis_create.error = pdu->llctrl.reject_ext_ind.error_code; lp_cc_complete(conn, ctx, evt, param); diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_features.h b/subsys/bluetooth/controller/ll_sw/ull_llcp_features.h index 75d92d5524e..ac60206bc70 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_features.h +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_features.h @@ -9,11 +9,6 @@ static inline void feature_unmask_features(struct ll_conn *conn, uint64_t ll_fea conn->llcp.fex.features_used &= ~ll_feat_mask; } -static inline void feature_unmask_peer_features(struct ll_conn *conn, uint64_t ll_feat_mask) -{ - conn->llcp.fex.features_peer &= ~ll_feat_mask; -} - static inline bool feature_le_encryption(struct ll_conn *conn) { #if defined(CONFIG_BT_CTLR_LE_ENC) From a9a993c13027ae75f750ae4e7dbe843b7c08ae31 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:58 +0000 Subject: [PATCH 0679/1623] Revert "[nrf fromtree] Bluetooth: controller: add missing NTF alloc in central CIS Create" This reverts commit 48accabe1924f7c77291a9cad93c26e92df14447. Signed-off-by: Dominik Ermel --- .../bluetooth/controller/ll_sw/ull_llcp_cc.c | 26 +------------------ 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c b/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c index 69dc80bda13..387cc884dea 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c @@ -643,7 +643,6 @@ static void lp_cc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ /* LLCP Local Procedure FSM states */ enum { LP_CC_STATE_IDLE, - LP_CC_STATE_WAIT_NTF_AVAIL, LP_CC_STATE_WAIT_OFFSET_CALC, LP_CC_STATE_WAIT_OFFSET_CALC_TX_REQ, LP_CC_STATE_WAIT_TX_CIS_REQ, @@ -840,7 +839,7 @@ static void lp_cc_st_idle(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t ev } else { /* Peer doesn't support CIS Peripheral so report unsupported */ ctx->data.cis_create.error = BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; - ctx->state = LP_CC_STATE_WAIT_NTF_AVAIL; + lp_cc_complete(conn, ctx, evt, param); } break; default: @@ -855,26 +854,6 @@ static void lp_cc_st_idle(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t ev } } -static void lp_cc_state_wait_ntf_avail(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, - void *param) -{ - switch (evt) { - case LP_CC_EVT_RUN: - if (llcp_ntf_alloc_is_available()) { - ctx->node_ref.rx = llcp_ntf_alloc(); - /* Mark node as RETAIN to trigger put/sched */ - ctx->node_ref.rx->hdr.type = NODE_RX_TYPE_RETAIN; - - /* Now we're good to complete procedure*/ - lp_cc_complete(conn, ctx, evt, param); - } - break; - default: - /* Ignore other evts */ - break; - } -} - static void cc_prepare_cis_ind(struct ll_conn *conn, struct proc_ctx *ctx) { uint8_t err; @@ -1061,9 +1040,6 @@ static void lp_cc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ case LP_CC_STATE_IDLE: lp_cc_st_idle(conn, ctx, evt, param); break; - case LP_CC_STATE_WAIT_NTF_AVAIL: - lp_cc_state_wait_ntf_avail(conn, ctx, evt, param); - break; case LP_CC_STATE_WAIT_OFFSET_CALC_TX_REQ: lp_cc_st_wait_offset_calc_tx_req(conn, ctx, evt, param); break; From 221791d75f246df2cbac23af7d535eb889151a56 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:58 +0000 Subject: [PATCH 0680/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix connected ISO dynamic tx power" This reverts commit 287777875f227f7ba6b1691973f5ae708ff90d16. Signed-off-by: Dominik Ermel --- .../hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf | 3 --- samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf | 3 --- .../bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_peripheral_iso.c | 2 +- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf index e9e5ac63483..bb95b6ea74e 100644 --- a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf @@ -112,6 +112,3 @@ CONFIG_BT_CTLR_ISOAL_SOURCES=2 # ISO Receptions CONFIG_BT_CTLR_ISO_RX_BUFFERS=8 CONFIG_BT_CTLR_ISOAL_SINKS=2 - -# Tx Power Dynamic Control -CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y diff --git a/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf b/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf index 3774532c424..1f976f75f22 100644 --- a/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf @@ -104,6 +104,3 @@ CONFIG_BT_CTLR_ISOAL_SOURCES=2 # ISO Receptions CONFIG_BT_CTLR_ISO_RX_BUFFERS=8 CONFIG_BT_CTLR_ISOAL_SINKS=2 - -# Tx Power Dynamic Control -CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 46360ef88d7..d287bc794a6 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -220,7 +220,7 @@ static int prepare_cb(struct lll_prepare_param *p) radio_reset(); #if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - radio_tx_power_set(conn_lll->tx_pwr_lvl); + radio_tx_power_set(cis_lll->tx_pwr_lvl); #else /* !CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ radio_tx_power_set(RADIO_TXP_DEFAULT); #endif /* !CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ @@ -986,7 +986,7 @@ static void isr_rx(void *param) next_cis_lll->rx.bn_curr = 1U; #if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - radio_tx_power_set(next_conn_lll->tx_pwr_lvl); + radio_tx_power_set(next_cis_lll->tx_pwr_lvl); #else radio_tx_power_set(RADIO_TXP_DEFAULT); #endif diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 13238c081cf..f089a07bb0b 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -238,7 +238,7 @@ static int prepare_cb(struct lll_prepare_param *p) radio_reset(); #if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) - radio_tx_power_set(conn_lll->tx_pwr_lvl); + radio_tx_power_set(cis_lll->tx_pwr_lvl); #else /* !CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ radio_tx_power_set(RADIO_TXP_DEFAULT); #endif /* !CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ From c91e24b5847f10924f0952f5ec998c5b7faf3577 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:59 +0000 Subject: [PATCH 0681/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix ULL_HIGH ticker operations count" This reverts commit 6721814fdc868cdc5d4f9fb066c58915741ea9bf. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 9811076b9ba..e6a736f939d 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -278,21 +278,22 @@ #define TICKER_USER_ULL_LOW_OPS (1 + TICKER_USER_ULL_LOW_VENDOR_OPS + 1) -/* NOTE: Extended Advertising needs one extra ticker operation being enqueued - * for scheduling the auxiliary PDU reception while there can already - * be three other operations being enqueued. - * - * This value also covers the case were initiator with 1M and Coded PHY - * scan window is stopping the two scan tickers, stopping one scan stop - * ticker and starting one new ticker for establishing an ACL connection. +/* NOTE: When ULL_LOW priority is configured to lower than ULL_HIGH, then extra + * ULL_HIGH operations queue elements are required to buffer the + * requested ticker operations. */ -#if defined(CONFIG_BT_CTLR_ADV_EXT) +#if defined(CONFIG_BT_CENTRAL) && defined(CONFIG_BT_CTLR_ADV_EXT) && \ + defined(CONFIG_BT_CTLR_PHY_CODED) #define TICKER_USER_ULL_HIGH_OPS (4 + TICKER_USER_ULL_HIGH_VENDOR_OPS + \ TICKER_USER_ULL_HIGH_FLASH_OPS + 1) -#else /* !CONFIG_BT_CTLR_ADV_EXT */ +#else /* !CONFIG_BT_CENTRAL || !CONFIG_BT_CTLR_ADV_EXT || + * !CONFIG_BT_CTLR_PHY_CODED + */ #define TICKER_USER_ULL_HIGH_OPS (3 + TICKER_USER_ULL_HIGH_VENDOR_OPS + \ TICKER_USER_ULL_HIGH_FLASH_OPS + 1) -#endif /* !CONFIG_BT_CTLR_ADV_EXT */ +#endif /* !CONFIG_BT_CENTRAL || !CONFIG_BT_CTLR_ADV_EXT || + * !CONFIG_BT_CTLR_PHY_CODED + */ #define TICKER_USER_LLL_OPS (3 + TICKER_USER_LLL_VENDOR_OPS + 1) From fd338e810e116606b981f604ab778d69ed2e0ae0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:59 +0000 Subject: [PATCH 0682/1623] Revert "[nrf fromtree] Bluetooth: Controller: ISO: Fix compile issue with unicast" This reverts commit 6df62154bb91974ca7dfd26683ec98dca62fef2e. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_sched.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_sched.c b/subsys/bluetooth/controller/ll_sw/ull_sched.c index 4eb7687b97d..38589a2e644 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sched.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sched.c @@ -321,7 +321,7 @@ static int group_free_slot_get(uint8_t user_id, uint32_t ticks_slot_abs, if (false) { -#if defined(CONFIG_BT_BROADCASTER) && CONFIG_BT_CTLR_ADV_AUX_SET > 0 +#if defined(CONFIG_BT_BROADCASTER) } else if (IN_RANGE(ticker_id, TICKER_ID_ADV_AUX_BASE, TICKER_ID_ADV_AUX_LAST)) { const struct ll_adv_aux_set *aux; @@ -391,7 +391,7 @@ static int group_free_slot_get(uint8_t user_id, uint32_t ticks_slot_abs, #endif /* CONFIG_BT_CTLR_ADV_ISO */ #endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ -#endif /* CONFIG_BT_BROADCASTER && CONFIG_BT_CTLR_ADV_AUX_SET > 0 */ +#endif /* CONFIG_BT_BROADCASTER */ #if defined(CONFIG_BT_CONN) } else if (IN_RANGE(ticker_id, TICKER_ID_CONN_BASE, From 400a63cbc840e1f25711b6ab05207d4e77d00ab9 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:59 +0000 Subject: [PATCH 0683/1623] Revert "[nrf fromtree] Bluetooth: Controller: nRF53: Fix back-to-back PDU chaining" This reverts commit cd4014a2feb3e7f3ca2aeec959506dd6002ffca0. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c | 2 +- subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c index 6fa0204fb56..ca566a04db4 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c @@ -394,7 +394,7 @@ static void isr_tx_chain(void *param) lll->phy_s, lll->phy_flags); } else { radio_isr_set(isr_done, lll_aux); - radio_switch_complete_and_b2b_tx_disable(); + radio_switch_complete_and_disable(); } radio_pkt_tx_set(pdu); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c index 79a8c6b25cd..1e56f70493c 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c @@ -367,7 +367,7 @@ static void isr_tx(void *param) switch_radio_complete_and_b2b_tx(lll_sync, lll->phy_s); } else { radio_isr_set(isr_done, lll_sync); - radio_switch_complete_and_b2b_tx_disable(); + radio_switch_complete_and_disable(); } radio_pkt_tx_set(pdu); From dc4cbbe19a753bcc441a5a3e6b6392bce59fd9e1 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:29:59 +0000 Subject: [PATCH 0684/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix BIS payload sliding window overrun check" This reverts commit be0d9e0314e8bbf148d1eb054c04f003b4c04576. Signed-off-by: Dominik Ermel --- .../bluetooth/controller/ll_sw/lll_sync_iso.h | 1 + .../ll_sw/nordic/lll/lll_sync_iso.c | 52 ++++--------------- .../bluetooth/controller/ll_sw/ull_sync_iso.c | 3 +- 3 files changed, 14 insertions(+), 42 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_sync_iso.h b/subsys/bluetooth/controller/ll_sw/lll_sync_iso.h index c47aa433c63..2426f51105e 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_sync_iso.h +++ b/subsys/bluetooth/controller/ll_sw/lll_sync_iso.h @@ -74,6 +74,7 @@ struct lll_sync_iso { struct node_rx_pdu *payload[BT_CTLR_SYNC_ISO_STREAM_MAX] [PDU_BIG_PAYLOAD_COUNT_MAX]; uint8_t payload_count_max; + uint8_t payload_head; uint8_t payload_tail; uint32_t window_widening_periodic_us; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c index 12e9fd342b9..5089c6ccde7 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c @@ -489,6 +489,7 @@ static void isr_rx(void *param) uint8_t access_addr[4]; uint16_t data_chan_id; uint8_t data_chan_use; + uint8_t payload_index; uint8_t crc_init[3]; uint8_t rssi_ready; uint32_t start_us; @@ -555,8 +556,6 @@ static void isr_rx(void *param) if (crc_ok) { struct lll_sync_iso_stream *sync_stream; uint16_t stream_handle; - uint8_t payload_offset; - uint8_t payload_index; struct pdu_bis *pdu; /* Check if Control Subevent being received */ @@ -594,28 +593,21 @@ static void isr_rx(void *param) /* TODO: check same CSSN is used in every subevent */ } - /* Check payload buffer overflow */ - payload_offset = (lll->bn_curr - 1U) + - (lll->ptc_curr * lll->pto); - if (payload_offset > lll->payload_count_max) { - goto isr_rx_done; - } - - /* Calculate the payload index in the sliding window */ - payload_index = lll->payload_tail + payload_offset; + /* calculate the payload index in the sliding window */ + payload_index = lll->payload_tail + (lll->bn_curr - 1U) + + (lll->ptc_curr * lll->pto); if (payload_index >= lll->payload_count_max) { payload_index -= lll->payload_count_max; } - /* Get reference to stream context */ stream_handle = lll->stream_handle[lll->stream_curr]; sync_stream = ull_sync_iso_lll_stream_get(stream_handle); - /* Store the received PDU if selected stream and not already - * received (say in previous event as pre-transmitted PDU. - */ + /* store the received PDU */ if ((lll->bis_curr == sync_stream->bis_index) && pdu->len && - !lll->payload[bis_idx][payload_index]) { + !lll->payload[bis_idx][payload_index] && + ((payload_index >= lll->payload_tail) || + (payload_index < lll->payload_head))) { uint16_t handle; if (lll->enc) { @@ -652,23 +644,10 @@ static void isr_rx(void *param) /* Find the next (bn_curr)th subevent to receive PDU */ while (lll->bn_curr < lll->bn) { - uint8_t payload_offset; - uint8_t payload_index; - - /* Next burst number to check for reception required */ lll->bn_curr++; - /* Check payload buffer overflow */ - payload_offset = (lll->bn_curr - 1U); - if (payload_offset > lll->payload_count_max) { - /* (bn_curr)th Rx PDU skip subevent */ - skipped++; - - continue; - } - /* Find the index of the (bn_curr)th Rx PDU buffer */ - payload_index = lll->payload_tail + payload_offset; + payload_index = lll->payload_tail + (lll->bn_curr - 1U); if (payload_index >= lll->payload_count_max) { payload_index -= lll->payload_count_max; } @@ -688,11 +667,6 @@ static void isr_rx(void *param) /* Find the next repetition (irc_curr)th subevent to receive PDU */ if (lll->irc_curr < lll->irc) { if (!new_burst) { - uint8_t payload_index; - - /* Increment to next repetition count and be at first - * burst count for it. - */ lll->bn_curr = 1U; lll->irc_curr++; @@ -741,10 +715,6 @@ static void isr_rx(void *param) if (lll->ptc_curr < lll->ptc) { lll->ptc_curr++; - /* TODO: optimize to skip pre-transmission subevent in case - * of insufficient buffers in sliding window. - */ - /* Receive the (ptc_curr)th Rx PDU of bis_curr */ bis = lll->bis_curr; @@ -763,7 +733,6 @@ static void isr_rx(void *param) stream_handle = lll->stream_handle[lll->stream_curr]; sync_stream = ull_sync_iso_lll_stream_get(stream_handle); if (sync_stream->bis_index <= lll->num_bis) { - uint8_t payload_index; uint8_t bis_idx_new; lll->bis_curr = sync_stream->bis_index; @@ -1089,7 +1058,8 @@ static void isr_rx_done(void *param) bn = lll->bn; while (bn--) { if (lll->payload[bis_idx][payload_tail]) { - node_rx = lll->payload[bis_idx][payload_tail]; + node_rx = + lll->payload[bis_idx][payload_tail]; lll->payload[bis_idx][payload_tail] = NULL; iso_rx_put(node_rx->hdr.link, node_rx); diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c index 513ee3cdbed..ff3327ce393 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c @@ -454,9 +454,10 @@ void ull_sync_iso_setup(struct ll_sync_iso_set *sync_iso, /* Initialize payload pointers */ lll->payload_count_max = PDU_BIG_PAYLOAD_COUNT_MAX; + lll->payload_head = 0U; lll->payload_tail = 0U; for (int i = 0; i < CONFIG_BT_CTLR_SYNC_ISO_STREAM_MAX; i++) { - for (int j = 0; j < lll->payload_count_max; j++) { + for (int j = 0; j < PDU_BIG_PAYLOAD_COUNT_MAX; j++) { lll->payload[i][j] = NULL; } } From 2731264651bc86a8f7eaee77550dc5fa9df6e080 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:00 +0000 Subject: [PATCH 0685/1623] Revert "[nrf fromtree] Bluetooth: Controller: Add BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX Kconfig" This reverts commit 34f39e4fa35bfc3af1ba376d8bd04b791503e315. Signed-off-by: Dominik Ermel --- .../bluetooth/controller/Kconfig.ll_sw_split | 11 --- .../bluetooth/controller/ll_sw/ull_central.c | 12 +-- .../controller/ll_sw/ull_central_iso.c | 18 ++--- subsys/bluetooth/controller/ll_sw/ull_conn.c | 18 ++--- .../bluetooth/controller/ll_sw/ull_conn_iso.c | 4 +- .../controller/ll_sw/ull_peripheral.c | 23 ++---- .../controller/ll_sw/ull_peripheral_iso.c | 4 - tests/bluetooth/init/prj_ctlr_5_x_dbg.conf | 76 ------------------- tests/bluetooth/init/testcase.yaml | 10 --- 9 files changed, 24 insertions(+), 152 deletions(-) delete mode 100644 tests/bluetooth/init/prj_ctlr_5_x_dbg.conf diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 3f6f3c10382..4cd8e200b63 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -632,17 +632,6 @@ config BT_CTLR_CENTRAL_RESERVE_MAX Note, currently this value is only used to space multiple central connections and not for actual ticker time reservations. -config BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX - bool "Reserve maximum event overhead in time reservations" - default y - help - Use radio event scheduling CPU time overhead in calculations of event - time reservations. - - If this option is disabled, then Peripheral ACL and Peripheral ISO - role will not include CPU time overhead. Other role will continue to - use CPU overheads in their event time reservations. - config BT_CTLR_SLOT_RESERVATION_UPDATE bool "Update event length reservation after PHY or DLE update" depends on (BT_CTLR_DATA_LENGTH || BT_CTLR_PHY) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central.c b/subsys/bluetooth/controller/ll_sw/ull_central.c index b189c65fa21..de14395f840 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central.c @@ -97,7 +97,6 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, uint16_t max_tx_time; uint16_t max_rx_time; memq_link_t *link; - uint32_t slot_us; uint8_t hop; int err; @@ -361,13 +360,10 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, #endif /* CONFIG_BT_CTLR_ADV_EXT */ #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - /* Calculate event time reservation */ - slot_us = max_tx_time + max_rx_time; - slot_us += EVENT_IFS_US + (EVENT_CLOCK_JITTER_US << 1); - slot_us += ready_delay_us; - slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; - - conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); + conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( + EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + + ready_delay_us + max_tx_time + EVENT_IFS_US + max_rx_time + + (EVENT_CLOCK_JITTER_US << 1)); #if defined(CONFIG_BT_CTLR_PRIVACY) ull_filter_scan_update(filter_policy); diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 8c516826e06..19dec37c937 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -864,15 +864,9 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, } else if (CONFIG_BT_CTLR_CENTRAL_SPACING > 0) { uint32_t cis_offset; - cis_offset = HAL_TICKER_TICKS_TO_US(conn->ull.ticks_slot) + - (EVENT_TICKER_RES_MARGIN_US << 1U); - - cis_offset += cig->sync_delay - cis->sync_delay; - - if (cis_offset < *cis_offset_min) { - cis_offset = *cis_offset_min; - } - + cis_offset = MAX((HAL_TICKER_TICKS_TO_US(conn->ull.ticks_slot) + + (EVENT_TICKER_RES_MARGIN_US << 1U) + cig->sync_delay - + cis->sync_delay), *cis_offset_min); cis->offset = cis_offset; #endif /* CONFIG_BT_CTLR_CENTRAL_SPACING */ @@ -948,9 +942,8 @@ int ull_central_iso_cis_offset_get(uint16_t cis_handle, #endif /* CONFIG_BT_CTLR_CENTRAL_SPACING != 0 */ *cis_offset_min = HAL_TICKER_TICKS_TO_US(conn->ull.ticks_slot) + - (EVENT_TICKER_RES_MARGIN_US << 1U); - - *cis_offset_min += cig->sync_delay - cis->sync_delay; + (EVENT_TICKER_RES_MARGIN_US << 1U) + + cig->sync_delay - cis->sync_delay; return 0; } @@ -991,6 +984,7 @@ static void mfy_cig_offset_get(void *param) offset_min_us += cig->sync_delay - cis->sync_delay; conn = ll_conn_get(cis->lll.acl_handle); + conn_interval_us = (uint32_t)conn->lll.interval * CONN_INT_UNIT_US; while (offset_min_us >= (conn_interval_us + PDU_CIS_OFFSET_MIN_US)) { offset_min_us -= conn_interval_us; diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 9d78af7acc1..a8d3178e020 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -1233,7 +1233,7 @@ void ull_conn_done(struct node_rx_event_done *done) #if defined(CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE) #if defined(CONFIG_BT_CTLR_DATA_LENGTH) || defined(CONFIG_BT_CTLR_PHY) if (lll->evt_len_upd) { - uint32_t ready_delay, rx_time, tx_time, ticks_slot, slot_us; + uint32_t ready_delay, rx_time, tx_time, ticks_slot; lll->evt_len_upd = 0; #if defined(CONFIG_BT_CTLR_PHY) @@ -1257,18 +1257,10 @@ void ull_conn_done(struct node_rx_event_done *done) tx_time = PDU_DC_MAX_US(lll->dle.eff.max_tx_octets, 0); rx_time = PDU_DC_MAX_US(lll->dle.eff.max_rx_octets, 0); #endif /* CONFIG_BT_CTLR_PHY */ - - /* Calculate event time reservation */ - slot_us = tx_time + rx_time; - slot_us += EVENT_IFS_US + (EVENT_CLOCK_JITTER_US << 1); - slot_us += ready_delay; - - if (IS_ENABLED(CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX) || - !conn->lll.role) { - slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; - } - - ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); + ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( + EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + + ready_delay + EVENT_IFS_US + rx_time + tx_time + + (EVENT_CLOCK_JITTER_US << 1)); if (ticks_slot > conn->ull.ticks_slot) { ticks_slot_plus = ticks_slot - conn->ull.ticks_slot; } else { diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index 2ec6a73b4a4..46c00c305fe 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -972,9 +972,7 @@ void ull_conn_iso_start(struct ll_conn *conn, uint16_t cis_handle, /* Below is time reservation for sequential packing */ slot_us = cis->lll.sub_interval * cis->lll.nse; - if (IS_ENABLED(CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX)) { - slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; - } + slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; /* FIXME: How to use ready_delay_us in the time reservation? * i.e. when CISes use different PHYs? Is that even diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c index 5a34f787ec7..8b813fda9fd 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c @@ -89,7 +89,6 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, uint16_t max_rx_time; uint16_t win_offset; memq_link_t *link; - uint32_t slot_us; uint8_t chan_sel; void *node; @@ -361,19 +360,10 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, #endif /* !CONFIG_BT_CTLR_DATA_LENGTH */ #if defined(CONFIG_BT_CTLR_PHY) - ready_delay_us = lll_radio_rx_ready_delay_get(lll->phy_rx, PHY_FLAGS_S8); -#else /* CONFIG_BT_CTLR_PHY */ - ready_delay_us = lll_radio_rx_ready_delay_get(0U, 0U); -#endif /* CONFIG_BT_CTLR_PHY */ - - /* Calculate event time reservation */ - slot_us = max_rx_time + max_tx_time; - slot_us += EVENT_IFS_US + (EVENT_CLOCK_JITTER_US << 1); - slot_us += ready_delay_us; - - if (IS_ENABLED(CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX)) { - slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; - } + ready_delay_us = lll_radio_rx_ready_delay_get(lll->phy_rx, 1); +#else + ready_delay_us = lll_radio_rx_ready_delay_get(0, 0); +#endif /* TODO: active_to_start feature port */ conn->ull.ticks_active_to_start = 0U; @@ -381,7 +371,10 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); conn->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); + conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( + EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + + ready_delay_us + max_rx_time + EVENT_IFS_US + max_tx_time + + (EVENT_CLOCK_JITTER_US << 1)); ticks_slot_offset = MAX(conn->ull.ticks_active_to_start, conn->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index eeef778734b..d2627502ac2 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -110,10 +110,6 @@ uint8_t ll_cis_accept(uint16_t handle) } else { cis_offset_min = HAL_TICKER_TICKS_TO_US(conn->ull.ticks_slot) + (EVENT_TICKER_RES_MARGIN_US << 1U); - - if (!IS_ENABLED(CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX)) { - cis_offset_min += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; - } } /* Accept request */ diff --git a/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf b/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf deleted file mode 100644 index df0d006a13e..00000000000 --- a/tests/bluetooth/init/prj_ctlr_5_x_dbg.conf +++ /dev/null @@ -1,76 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CTLR=y -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_CTLR_DUP_FILTER_LEN=16 -CONFIG_BT_CTLR_CONN_PARAM_REQ=y -CONFIG_BT_CTLR_LE_PING=y -CONFIG_BT_CTLR_PRIVACY=n -CONFIG_BT_CTLR_EXT_SCAN_FP=n -CONFIG_BT_DATA_LEN_UPDATE=n -CONFIG_BT_PHY_UPDATE=y -CONFIG_BT_CTLR_CHAN_SEL_2=y -CONFIG_BT_CTLR_MIN_USED_CHAN=y -CONFIG_BT_CTLR_ADV_EXT=y -CONFIG_BT_CTLR_ADV_PERIODIC=y -CONFIG_BT_CTLR_ADV_ISO=y -CONFIG_BT_CTLR_SYNC_PERIODIC=y -CONFIG_BT_CTLR_SYNC_ISO=y -CONFIG_BT_CTLR_CENTRAL_ISO=y -CONFIG_BT_CTLR_PERIPHERAL_ISO=y -CONFIG_BT_CTLR_DTM_HCI=y -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_PHY_2M=y -CONFIG_BT_CTLR_PHY_2M_NRF=y -CONFIG_BT_CTLR_PHY_CODED=y -CONFIG_BT_CTLR_ADV_AUX_PDU_BACK2BACK=y -CONFIG_BT_CTLR_LLL_PRIO=0 -CONFIG_BT_CTLR_ULL_HIGH_PRIO=1 -CONFIG_BT_CTLR_XTAL_ADVANCED=n -CONFIG_BT_CTLR_SCHED_ADVANCED=y -CONFIG_BT_CTLR_RADIO_ENABLE_FAST=y -CONFIG_BT_CTLR_TIFS_HW=n -CONFIG_BT_CTLR_FAST_ENC=y -CONFIG_BT_CTLR_TX_RETRY_DISABLE=y -CONFIG_BT_CTLR_CONN_RSSI=y -CONFIG_BT_CTLR_ADV_INDICATION=y -CONFIG_BT_CTLR_SCAN_REQ_NOTIFY=y -CONFIG_BT_CTLR_SCAN_REQ_RSSI=y -CONFIG_BT_CTLR_SCAN_INDICATION=y -CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX=n -CONFIG_BT_CTLR_PROFILE_ISR=y -CONFIG_BT_CTLR_DEBUG_PINS=y -CONFIG_BT_CTLR_TEST=y -CONFIG_BT_HCI_VS_EXT=y -CONFIG_BT_HCI_MESH_EXT=n -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_EXT_ADV=y -CONFIG_BT_PER_ADV=y -CONFIG_BT_PER_ADV_SYNC=y -CONFIG_BT_ISO_BROADCASTER=y -CONFIG_BT_ISO_SYNC_RECEIVER=y -CONFIG_BT_ISO_CENTRAL=y -CONFIG_BT_ISO_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_SIGNING=y -CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_USE_DEBUG_KEYS=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_GATT_CLIENT=y -CONFIG_BT_DEBUG_MONITOR_UART=y -CONFIG_BT_HCI_CORE_LOG_LEVEL_DBG=y -CONFIG_BT_CONN_LOG_LEVEL_DBG=y -CONFIG_BT_KEYS_LOG_LEVEL_DBG=y -CONFIG_BT_L2CAP_LOG_LEVEL_DBG=y -CONFIG_BT_SMP_LOG_LEVEL_DBG=y -CONFIG_BT_HCI_DRIVER_LOG_LEVEL_DBG=y -CONFIG_BT_SMP_SELFTEST=y -CONFIG_BT_ATT_LOG_LEVEL_DBG=y -CONFIG_BT_GATT_LOG_LEVEL_DBG=y -CONFIG_BT_BREDR=n -CONFIG_DEBUG=y -CONFIG_FLASH=y -CONFIG_SOC_FLASH_NRF_RADIO_SYNC_TICKER=n -CONFIG_ZTEST=y -CONFIG_ZTEST_NEW_API=y diff --git a/tests/bluetooth/init/testcase.yaml b/tests/bluetooth/init/testcase.yaml index 17d57ec9d47..c38f5bed69e 100644 --- a/tests/bluetooth/init/testcase.yaml +++ b/tests/bluetooth/init/testcase.yaml @@ -122,16 +122,6 @@ tests: integration_platforms: - nrf52840dk_nrf52840 - nrf52dk_nrf52832 - bluetooth.init.test_ctlr_5_x_dbg: - extra_args: - - CONF_FILE=prj_ctlr_5_x_dbg.conf - - DTC_OVERLAY_FILE=pa_lna.overlay - platform_allow: - - nrf52840dk_nrf52840 - - nrf52dk_nrf52832 - integration_platforms: - - nrf52840dk_nrf52840 - - nrf52dk_nrf52832 bluetooth.init.test_ctlr_sw_switch_single_timer: extra_args: - CONF_FILE=prj_ctlr.conf From a997d1c8b2f77621f67cc9191aba7a617bc424b4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:00 +0000 Subject: [PATCH 0686/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix compile error when BT_CTLR_CENTRAL_SPACING=n" This reverts commit fd76eac8e690a1181d84cba6a89cdfc3808ef3e7. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_central_iso.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 19dec37c937..aac5d2057d2 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -857,19 +857,13 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, cis->offset = cis_offset; #else /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ - - if (false) { - -#if defined(CONFIG_BT_CTLR_CENTRAL_SPACING) - } else if (CONFIG_BT_CTLR_CENTRAL_SPACING > 0) { + if (IS_ENABLED(CONFIG_BT_CTLR_CENTRAL_SPACING) && (CONFIG_BT_CTLR_CENTRAL_SPACING > 0)) { uint32_t cis_offset; cis_offset = MAX((HAL_TICKER_TICKS_TO_US(conn->ull.ticks_slot) + (EVENT_TICKER_RES_MARGIN_US << 1U) + cig->sync_delay - cis->sync_delay), *cis_offset_min); cis->offset = cis_offset; -#endif /* CONFIG_BT_CTLR_CENTRAL_SPACING */ - } else { cis->offset = *cis_offset_min; } From 430e1defc4ce54ba25ff520580fb5721b3aa9490 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:00 +0000 Subject: [PATCH 0687/1623] Revert "[nrf fromtree] Bluetooth: Controller: nrf53: Fix back-to-back Tx Rx implementation" This reverts commit a91031e38b7c7e412c23636630ae62c0744c6cc9. Signed-off-by: Dominik Ermel --- .../ll_sw/nordic/hal/nrf5/radio/radio.c | 30 +----- .../ll_sw/nordic/hal/nrf5/radio/radio.h | 2 - .../nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 100 ++++++------------ .../nordic/hal/nrf5/radio/radio_nrf5_ppi.h | 66 +++++------- .../controller/ll_sw/nordic/lll/lll_adv_iso.c | 2 +- 5 files changed, 67 insertions(+), 133 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index a657ab95dfe..0b41a9bbfb6 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -718,7 +718,7 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla #endif /* CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE */ uint32_t delay; - hal_radio_sw_switch_setup(sw_tifs_toggle); + hal_radio_sw_switch_setup(cc, ppi, sw_tifs_toggle); /* NOTE: As constants are passed to dir_curr and dir_next, the * compiler should optimize out the redundant code path @@ -736,7 +736,7 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla hal_radio_tx_chain_delay_ns_get(phy_curr, flags_curr)); - hal_radio_b2b_txen_on_sw_switch(cc, ppi); + hal_radio_b2b_txen_on_sw_switch(ppi); } else { /* If RX PHY is LE Coded, calculate for S8 coding. * Assumption being, S8 has higher delay. @@ -746,7 +746,7 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla flags_next) + hal_radio_rx_chain_delay_ns_get(phy_curr, 1)); - hal_radio_txen_on_sw_switch(cc, ppi); + hal_radio_txen_on_sw_switch(ppi); } #if defined(CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE) @@ -839,7 +839,7 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla flags_curr)) + (EVENT_CLOCK_JITTER_US << 1); - hal_radio_rxen_on_sw_switch(cc, ppi); + hal_radio_rxen_on_sw_switch(ppi); } else { delay = HAL_RADIO_NS2US_CEIL( hal_radio_rx_ready_delay_ns_get(phy_next, @@ -848,7 +848,7 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla flags_curr)) + (EVENT_CLOCK_JITTER_US << 1); - hal_radio_b2b_rxen_on_sw_switch(cc, ppi); + hal_radio_b2b_rxen_on_sw_switch(ppi); } @@ -982,26 +982,6 @@ void radio_switch_complete_and_b2b_rx(uint8_t phy_curr, uint8_t flags_curr, #endif /* !CONFIG_BT_CTLR_TIFS_HW */ } -void radio_switch_complete_and_b2b_tx_disable(void) -{ -#if defined(CONFIG_BT_CTLR_TIFS_HW) - NRF_RADIO->SHORTS = (RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_DISABLE_Msk); -#else /* CONFIG_BT_CTLR_TIFS_HW */ - NRF_RADIO->SHORTS = (RADIO_SHORTS_READY_START_Msk | NRF_RADIO_SHORTS_PDU_END_DISABLE); - hal_radio_sw_switch_b2b_tx_disable(sw_tifs_toggle); -#endif /* !CONFIG_BT_CTLR_TIFS_HW */ -} - -void radio_switch_complete_and_b2b_rx_disable(void) -{ -#if defined(CONFIG_BT_CTLR_TIFS_HW) - NRF_RADIO->SHORTS = (RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_DISABLE_Msk); -#else /* CONFIG_BT_CTLR_TIFS_HW */ - NRF_RADIO->SHORTS = (RADIO_SHORTS_READY_START_Msk | NRF_RADIO_SHORTS_PDU_END_DISABLE); - hal_radio_sw_switch_b2b_rx_disable(sw_tifs_toggle); -#endif /* !CONFIG_BT_CTLR_TIFS_HW */ -} - void radio_switch_complete_and_disable(void) { #if defined(CONFIG_BT_CTLR_TIFS_HW) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h index 4bf833b233a..600d7e95481 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h @@ -106,8 +106,6 @@ void radio_switch_complete_and_b2b_tx(uint8_t phy_curr, uint8_t flags_curr, uint8_t phy_next, uint8_t flags_next); void radio_switch_complete_and_b2b_rx(uint8_t phy_curr, uint8_t flags_curr, uint8_t phy_next, uint8_t flags_next); -void radio_switch_complete_and_b2b_tx_disable(void); -void radio_switch_complete_and_b2b_rx_disable(void); void radio_switch_complete_and_disable(void); uint8_t radio_phy_flags_rx_get(void); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 1fdf7d90d30..787755866ab 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -455,7 +455,10 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) #endif /* CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE */ -static inline void hal_radio_sw_switch_setup(uint8_t ppi_group_index) +static inline void hal_radio_sw_switch_setup( + uint8_t compare_reg, + uint8_t radio_enable_ppi, + uint8_t ppi_group_index) { /* Set up software switch mechanism for next Radio switch. */ @@ -463,7 +466,7 @@ static inline void hal_radio_sw_switch_setup(uint8_t ppi_group_index) * over PPI[] */ HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_EVT = - HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_EVT; + HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_EVT; nrf_dppi_subscribe_set(NRF_DPPIC, HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(ppi_group_index)), HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI); @@ -473,70 +476,55 @@ static inline void hal_radio_sw_switch_setup(uint8_t ppi_group_index) nrf_dppi_subscribe_clear(NRF_DPPIC, HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(other_grp))); -} -static inline void hal_radio_txen_on_sw_switch(uint8_t compare_reg_index, uint8_t radio_enable_ppi) -{ /* Wire SW Switch timer event to the * PPI[] for enabling Radio. Do * not wire the task; it is done by the caller of * the function depending on the desired direction * (TX/RX). */ - HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT(compare_reg_index) = + HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT(compare_reg) = HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(radio_enable_ppi); - - nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_TXEN, radio_enable_ppi); } -static inline void hal_radio_b2b_txen_on_sw_switch(uint8_t compare_reg_index, - uint8_t radio_enable_ppi) +static inline void hal_radio_txen_on_sw_switch(uint8_t ppi) { - /* Wire SW Switch timer event to the - * PPI[] for enabling Radio. Do - * not wire the task; it is done by the caller of - * the function depending on the desired direction - * (TX/RX). - */ - HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT(compare_reg_index) = - HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(radio_enable_ppi); - - uint8_t prev_ppi_idx = (compare_reg_index + 0x01) & 0x01; - - radio_enable_ppi = HAL_SW_SWITCH_RADIO_ENABLE_PPI(prev_ppi_idx); - nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_TXEN, radio_enable_ppi); + nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_TXEN, ppi); } -static inline void hal_radio_rxen_on_sw_switch(uint8_t compare_reg_index, uint8_t radio_enable_ppi) +static inline void hal_radio_b2b_txen_on_sw_switch(uint8_t ppi) { - /* Wire SW Switch timer event to the - * PPI[] for enabling Radio. Do - * not wire the task; it is done by the caller of - * the function depending on the desired direction - * (TX/RX). + /* NOTE: Calling radio_tmr_start/radio_tmr_start_us/radio_tmr_start_now + * after the radio_switch_complete_and_b2b_tx() call would have + * changed the PPI channel to HAL_RADIO_ENABLE_ON_TICK_PPI as we + * cannot double buffer the subscribe buffer. Hence, lets have + * both DPPI channel enabled (other one was enabled by the DPPI + * group when the Radio End occurred) so that when both timer + * trigger one of the DPPI is correct in the radio tx + * subscription. */ - HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT(compare_reg_index) = - HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(radio_enable_ppi); + nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_TXEN, ppi); + nrf_dppi_channels_enable(NRF_DPPIC, BIT(ppi)); +} - nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_RXEN, radio_enable_ppi); +static inline void hal_radio_rxen_on_sw_switch(uint8_t ppi) +{ + nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_RXEN, ppi); } -static inline void hal_radio_b2b_rxen_on_sw_switch(uint8_t compare_reg_index, - uint8_t radio_enable_ppi) +static inline void hal_radio_b2b_rxen_on_sw_switch(uint8_t ppi) { - /* Wire SW Switch timer event to the - * PPI[] for enabling Radio. Do - * not wire the task; it is done by the caller of - * the function depending on the desired direction - * (TX/RX). + /* NOTE: Calling radio_tmr_start/radio_tmr_start_us/radio_tmr_start_now + * after the radio_switch_complete_and_b2b_rx() call would have + * changed the PPI channel to HAL_RADIO_ENABLE_ON_TICK_PPI as we + * cannot double buffer the subscribe buffer. Hence, lets have + * both DPPI channel enabled (other one was enabled by the DPPI + * group when the Radio End occurred) so that when both timer + * trigger one of the DPPI is correct in the radio rx + * subscription. */ - HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT(compare_reg_index) = - HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(radio_enable_ppi); - - uint8_t prev_ppi_idx = (compare_reg_index + 0x01) & 0x01; - - radio_enable_ppi = HAL_SW_SWITCH_RADIO_ENABLE_PPI(prev_ppi_idx); - nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_RXEN, radio_enable_ppi); + nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_RXEN, ppi); + nrf_dppi_channels_enable(NRF_DPPIC, BIT(ppi)); } static inline void hal_radio_sw_switch_disable(void) @@ -552,26 +540,6 @@ static inline void hal_radio_sw_switch_disable(void) HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(1))); } -static inline void hal_radio_sw_switch_b2b_tx_disable(uint8_t compare_reg_index) -{ - hal_radio_sw_switch_disable(); - - uint8_t prev_ppi_idx = (compare_reg_index + 0x01) & 0x01; - uint8_t radio_enable_ppi = HAL_SW_SWITCH_RADIO_ENABLE_PPI(prev_ppi_idx); - - nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_TXEN, radio_enable_ppi); -} - -static inline void hal_radio_sw_switch_b2b_rx_disable(uint8_t compare_reg_index) -{ - hal_radio_sw_switch_disable(); - - uint8_t prev_ppi_idx = (compare_reg_index + 0x01) & 0x01; - uint8_t radio_enable_ppi = HAL_SW_SWITCH_RADIO_ENABLE_PPI(prev_ppi_idx); - - nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_RXEN, radio_enable_ppi); -} - static inline void hal_radio_sw_switch_cleanup(void) { hal_radio_sw_switch_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h index 44cec4621a3..d964129bfa1 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h @@ -420,7 +420,10 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) #define HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_RX \ ((uint32_t)&(NRF_RADIO->TASKS_RXEN)) -static inline void hal_radio_sw_switch_setup(uint8_t ppi_group_index) +static inline void hal_radio_sw_switch_setup( + uint8_t compare_reg, + uint8_t radio_enable_ppi, + uint8_t ppi_group_index) { /* Set up software switch mechanism for next Radio switch. */ @@ -432,58 +435,53 @@ static inline void hal_radio_sw_switch_setup(uint8_t ppi_group_index) HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI, HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_EVT, HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_TASK(ppi_group_index)); -} -static inline void hal_radio_txen_on_sw_switch(uint8_t compare_reg_index, uint8_t radio_enable_ppi) -{ /* Wire SW Switch timer event to the * PPI[] for enabling Radio. Do * not wire the task; it is done by the caller of * the function depending on the desired direction * (TX/RX). */ - nrf_ppi_event_endpoint_setup(NRF_PPI, radio_enable_ppi, - HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(compare_reg_index)); + nrf_ppi_event_endpoint_setup( + NRF_PPI, + radio_enable_ppi, + HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(compare_reg)); +} - nrf_ppi_task_endpoint_setup(NRF_PPI, radio_enable_ppi, - HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_TX); +static inline void hal_radio_txen_on_sw_switch(uint8_t ppi) +{ + nrf_ppi_task_endpoint_setup( + NRF_PPI, + ppi, + HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_TX); } -static inline void hal_radio_b2b_txen_on_sw_switch(uint8_t compare_reg_index, - uint8_t radio_enable_ppi) +static inline void hal_radio_b2b_txen_on_sw_switch(uint8_t ppi) { /* NOTE: As independent PPI are used to trigger the Radio Tx task, * double buffers implementation works for sw_switch using PPIs, * simply reuse the hal_radio_txen_on_sw_switch() functon to set * the next PPIs task to be Radio Tx enable. */ - hal_radio_txen_on_sw_switch(compare_reg_index, radio_enable_ppi); + hal_radio_txen_on_sw_switch(ppi); } -static inline void hal_radio_rxen_on_sw_switch(uint8_t compare_reg_index, uint8_t radio_enable_ppi) +static inline void hal_radio_rxen_on_sw_switch(uint8_t ppi) { - /* Wire SW Switch timer event to the - * PPI[] for enabling Radio. Do - * not wire the task; it is done by the caller of - * the function depending on the desired direction - * (TX/RX). - */ - nrf_ppi_event_endpoint_setup(NRF_PPI, radio_enable_ppi, - HAL_SW_SWITCH_RADIO_ENABLE_PPI_EVT(compare_reg_index)); - - nrf_ppi_task_endpoint_setup(NRF_PPI, radio_enable_ppi, - HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_RX); + nrf_ppi_task_endpoint_setup( + NRF_PPI, + ppi, + HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_RX); } -static inline void hal_radio_b2b_rxen_on_sw_switch(uint8_t compare_reg_index, - uint8_t radio_enable_ppi) +static inline void hal_radio_b2b_rxen_on_sw_switch(uint8_t ppi) { - /* NOTE: As independent PPI are used to trigger the Radio Tx task, + /* NOTE: As independent PPI are used to trigger the Radio Rx task, * double buffers implementation works for sw_switch using PPIs, - * simply reuse the hal_radio_txen_on_sw_switch() functon to set - * the next PPIs task to be Radio Tx enable. + * simply reuse the hal_radio_rxen_on_sw_switch() functon to set + * the next PPIs task to be Radio Rx enable. */ - hal_radio_rxen_on_sw_switch(compare_reg_index, radio_enable_ppi); + hal_radio_rxen_on_sw_switch(ppi); } static inline void hal_radio_sw_switch_disable(void) @@ -498,16 +496,6 @@ static inline void hal_radio_sw_switch_disable(void) BIT(HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI)); } -static inline void hal_radio_sw_switch_b2b_tx_disable(uint8_t compare_reg_index) -{ - hal_radio_sw_switch_disable(); -} - -static inline void hal_radio_sw_switch_b2b_rx_disable(uint8_t compare_reg_index) -{ - hal_radio_sw_switch_disable(); -} - static inline void hal_radio_sw_switch_cleanup(void) { hal_radio_sw_switch_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c index 20e3fe528e1..87849d0e1fd 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c @@ -717,7 +717,7 @@ static void isr_tx_common(void *param, pkt_flags); } - radio_switch_complete_and_b2b_tx_disable(); + radio_switch_complete_and_disable(); radio_isr_set(isr_done_term, lll); } else { From cbcd42ebea2bb8fac3df743ab0a08d588c253824 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:01 +0000 Subject: [PATCH 0688/1623] Revert "[nrf fromtree] Bluetooth: Controller: nRF53: Cleanup dppi and dppi resources file" This reverts commit 85b2b7136d56092617648e8bee0e0d860cfbf524. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 4 ++-- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h | 2 +- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_resources.h | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 787755866ab..3792111292a 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -341,7 +341,7 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) /* Wire a SW SWITCH TIMER EVENTS_COMPARE[] event * to a PPI GROUP TASK DISABLE task (PPI group with index ). - * 2 adjacent PPIs (14 & 15) and 2 adjacent PPI groups are used for this wiring; + * 2 adjacent PPIs (8 & 9) and 2 adjacent PPI groups are used for this wiring; * must be 0 or 1. must be a valid TIMER CC register offset. */ #define HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(index) \ @@ -429,10 +429,10 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) (SW_SWITCH_TIMER_EVTS_COMP_PHYEND_DELAY_COMPENSATION_BASE + (index)) #define HAL_SW_SWITCH_RADIO_ENABLE_PHYEND_DELAY_COMPENSATION_PPI(index) \ HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(index) - /* Cancel the SW switch timer running considering PHYEND delay compensation timing: * wire the RADIO EVENTS_CTEPRESENT event to SW_SWITCH_TIMER TASKS_CAPTURE task. */ +#define HAL_SW_SWITCH_TIMER_PHYEND_DELAY_COMPENSATION_DISABLE_PPI 16 #define HAL_SW_SWITCH_TIMER_PHYEND_DELAY_COMPENSATION_DISABLE_PPI_REGISTER_EVT \ NRF_RADIO->PUBLISH_CTEPRESENT diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h index a8bbe8e63b4..e1b47d03fd7 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h @@ -98,7 +98,7 @@ /* Wire a SW SWITCH TIMER EVENTS_COMPARE[] event * to a PPI GROUP TASK DISABLE task (PPI group with index ). - * 2 adjacent PPIs (14 & 15) and 2 adjacent PPI groups are used for this wiring; + * 2 adjacent PPIs (8 & 9) and 2 adjacent PPI groups are used for this wiring; * must be 0 or 1. must be a valid TIMER CC register offset. */ #define HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_BASE 14 diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_resources.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_resources.h index ab196e17d58..5c5093f4b52 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_resources.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_resources.h @@ -143,6 +143,9 @@ #define HAL_SW_SWITCH_RADIO_ENABLE_PPI_BASE 12 #endif +#if defined(CONFIG_BT_CTLR_PHY_CODED) && \ + defined(CONFIG_HAS_HW_NRF_RADIO_BLE_CODED) + /* Wire the SW SWITCH TIMER EVENTS_COMPARE[] event * to RADIO TASKS_TXEN/RXEN task. */ @@ -153,6 +156,8 @@ */ #define HAL_SW_SWITCH_TIMER_S8_DISABLE_PPI 19 +#endif /* CONFIG_HAS_HW_NRF_RADIO_BLE_CODED */ + #if defined(CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE) /* Wire the SW SWITCH PHYEND delay compensation TIMER EVENTS_COMPARE[] event to software * switch TIMER0->CLEAR taks task. From fcacad706adbd62ead1ef62f4f0d3e9822609faa Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:01 +0000 Subject: [PATCH 0689/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix CIS assymmetric PHY usage" This reverts commit bce70f4a637c8efd602bd72c598182909f5697f0. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/lll/lll_central_iso.c | 12 +++--------- .../controller/ll_sw/nordic/lll/lll_peripheral_iso.c | 11 +---------- subsys/bluetooth/controller/ll_sw/ull_central_iso.c | 4 ---- .../bluetooth/controller/ll_sw/ull_peripheral_iso.c | 2 -- 4 files changed, 4 insertions(+), 25 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index d287bc794a6..6135cc9d863 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -488,17 +488,14 @@ static void isr_tx(void *param) /* Get reference to CIS LLL context */ cis_lll = param; - /* Acquire rx node for reception */ - node_rx = ull_iso_pdu_rx_alloc_peek(1U); - LL_ASSERT(node_rx); - #if defined(CONFIG_BT_CTLR_LE_ENC) /* Get reference to ACL context */ const struct lll_conn *conn_lll = ull_conn_lll_get(cis_lll->acl_handle); #endif /* CONFIG_BT_CTLR_LE_ENC */ - /* PHY */ - radio_phy_set(cis_lll->rx.phy, PHY_FLAGS_S8); + /* Acquire rx node for reception */ + node_rx = ull_iso_pdu_rx_alloc_peek(1U); + LL_ASSERT(node_rx); /* Encryption */ if (false) { @@ -1090,9 +1087,6 @@ static void isr_prepare_subevent(void *param) const struct lll_conn *conn_lll = ull_conn_lll_get(cis_lll->acl_handle); #endif /* CONFIG_BT_CTLR_LE_ENC */ - /* PHY */ - radio_phy_set(cis_lll->tx.phy, cis_lll->tx.phy_flags); - /* Encryption */ if (false) { diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index f089a07bb0b..4796696ce73 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -244,7 +244,7 @@ static int prepare_cb(struct lll_prepare_param *p) #endif /* !CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ phy = cis_lll->rx.phy; - radio_phy_set(phy, PHY_FLAGS_S8); + radio_phy_set(phy, cis_lll->rx.phy_flags); radio_aa_set(cis_lll->access_addr); radio_crc_configure(PDU_CRC_POLYNOMIAL, sys_get_le24(conn_lll->crc_init)); lll_chan_set(data_chan_use); @@ -738,9 +738,6 @@ static void isr_rx(void *param) pdu_tx->rfu0 = 0U; pdu_tx->rfu1 = 0U; - /* PHY */ - radio_phy_set(cis_lll->tx.phy, cis_lll->tx.phy_flags); - /* Encryption */ if (false) { @@ -883,9 +880,6 @@ static void isr_tx(void *param) const struct lll_conn *conn_lll = ull_conn_lll_get(cis_lll->acl_handle); #endif /* CONFIG_BT_CTLR_LE_ENC */ - /* PHY */ - radio_phy_set(cis_lll->rx.phy, PHY_FLAGS_S8); - /* Encryption */ if (false) { @@ -1100,9 +1094,6 @@ static void isr_prepare_subevent_common(void *param) const struct lll_conn *conn_lll = ull_conn_lll_get(cis_lll->acl_handle); #endif /* CONFIG_BT_CTLR_LE_ENC */ - /* PHY */ - radio_phy_set(cis_lll->rx.phy, PHY_FLAGS_S8); - /* Encryption */ if (false) { diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index aac5d2057d2..2a19e03bde5 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -136,9 +136,7 @@ uint8_t ll_cis_parameters_set(uint8_t cis_id, ll_iso_setup.stream[cis_idx].c_max_sdu = c_sdu; ll_iso_setup.stream[cis_idx].p_max_sdu = p_sdu; ll_iso_setup.stream[cis_idx].lll.tx.phy = c_phy; - ll_iso_setup.stream[cis_idx].lll.tx.phy_flags = PHY_FLAGS_S8; ll_iso_setup.stream[cis_idx].lll.rx.phy = p_phy; - ll_iso_setup.stream[cis_idx].lll.rx.phy_flags = PHY_FLAGS_S8; ll_iso_setup.stream[cis_idx].central.c_rtn = c_rtn; ll_iso_setup.stream[cis_idx].central.p_rtn = p_rtn; ll_iso_setup.cis_idx++; @@ -637,9 +635,7 @@ uint8_t ll_cis_parameters_test_set(uint8_t cis_id, uint8_t nse, ll_iso_setup.stream[cis_idx].lll.tx.max_pdu = c_bn ? c_pdu : 0U; ll_iso_setup.stream[cis_idx].lll.rx.max_pdu = p_bn ? p_pdu : 0U; ll_iso_setup.stream[cis_idx].lll.tx.phy = c_phy; - ll_iso_setup.stream[cis_idx].lll.tx.phy_flags = PHY_FLAGS_S8; ll_iso_setup.stream[cis_idx].lll.rx.phy = p_phy; - ll_iso_setup.stream[cis_idx].lll.rx.phy_flags = PHY_FLAGS_S8; ll_iso_setup.stream[cis_idx].lll.tx.bn = c_bn; ll_iso_setup.stream[cis_idx].lll.rx.bn = p_bn; ll_iso_setup.cis_idx++; diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index d2627502ac2..f68ca66656f 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -257,13 +257,11 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl, cis->lll.nse = req->nse; cis->lll.rx.phy = req->c_phy; - cis->lll.rx.phy_flags = PHY_FLAGS_S8; cis->lll.rx.bn = req->c_bn; cis->lll.rx.ft = req->c_ft; cis->lll.rx.max_pdu = sys_le16_to_cpu(req->c_max_pdu); cis->lll.tx.phy = req->p_phy; - cis->lll.tx.phy_flags = PHY_FLAGS_S8; cis->lll.tx.bn = req->p_bn; cis->lll.tx.ft = req->p_ft; cis->lll.tx.max_pdu = sys_le16_to_cpu(req->p_max_pdu); From 71df5dc94c08771984f6f48b3b6239e08b56cf46 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:01 +0000 Subject: [PATCH 0690/1623] Revert "[nrf fromtree] Bluetooth: Controller: nRF53: Fix missing NRF_CCM subscribe clear" This reverts commit 2528d7a49d30ff0334b4bf9af48618ddbf359373. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/hal/nrf5/radio/radio.c | 6 ------ .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 8 -------- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h | 10 ---------- 3 files changed, 24 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 0b41a9bbfb6..3fc76a27bdf 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -1084,8 +1084,6 @@ void radio_tmr_status_reset(void) { nrf_rtc_event_disable(NRF_RTC0, RTC_EVTENCLR_COMPARE2_Msk); - hal_trigger_crypt_ppi_disable(); - hal_radio_nrf_ppi_channels_disable( BIT(HAL_RADIO_ENABLE_TX_ON_TICK_PPI) | BIT(HAL_RADIO_ENABLE_RX_ON_TICK_PPI) | @@ -1118,8 +1116,6 @@ void radio_tmr_tx_status_reset(void) { nrf_rtc_event_disable(NRF_RTC0, RTC_EVTENCLR_COMPARE2_Msk); - hal_trigger_crypt_ppi_disable(); - hal_radio_nrf_ppi_channels_disable( #if (HAL_RADIO_ENABLE_TX_ON_TICK_PPI != HAL_RADIO_ENABLE_RX_ON_TICK_PPI) && \ !defined(DPPI_PRESENT) @@ -1156,8 +1152,6 @@ void radio_tmr_rx_status_reset(void) { nrf_rtc_event_disable(NRF_RTC0, RTC_EVTENCLR_COMPARE2_Msk); - hal_trigger_crypt_ppi_disable(); - hal_radio_nrf_ppi_channels_disable( #if (HAL_RADIO_ENABLE_TX_ON_TICK_PPI != HAL_RADIO_ENABLE_RX_ON_TICK_PPI) && \ !defined(DPPI_PRESENT) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 3792111292a..c28cc35a617 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -127,14 +127,6 @@ static inline void hal_trigger_crypt_ppi_config(void) nrf_ccm_subscribe_set(NRF_CCM, NRF_CCM_TASK_CRYPT, HAL_RADIO_RECV_TIMEOUT_CANCEL_PPI); } -/******************************************************************************* - * Disable trigger encryption task - */ -static inline void hal_trigger_crypt_ppi_disable(void) -{ - nrf_ccm_subscribe_clear(NRF_CCM, NRF_CCM_TASK_CRYPT); -} - #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX) /******************************************************************************* * Trigger encryption task on Bit counter match: diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h index d964129bfa1..866769c95eb 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi.h @@ -205,16 +205,6 @@ static inline void hal_trigger_crypt_ppi_config(void) /* No need to configure anything for the pre-programmed channel. */ } -/******************************************************************************* - * Disable trigger encryption task - */ -static inline void hal_trigger_crypt_ppi_disable(void) -{ - /* No need to disable anything as ppi channel will be disabled in a - * separate disable ppi call by the caller of this function. - */ -} - #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX) /******************************************************************************* * Trigger encryption task on Bit counter match: From 4e245fd50dc1b7d0057d2a76e941d42b849d68b4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:02 +0000 Subject: [PATCH 0691/1623] Revert "[nrf fromtree] Bluetooth: Controller: Use unique goto label in scan aux code" This reverts commit ac999bd51ac7d24cb11df0171b137ef6444279a4. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c index c8188d87cb6..50bcb0e6662 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c @@ -1510,7 +1510,7 @@ static void isr_rx_connect_rsp(void *param) rx = ftr->extra; rx->hdr.type = NODE_RX_TYPE_RELEASE; - goto isr_rx_connect_rsp_do_close; + goto isr_rx_do_close; } /* Update the max Tx and Rx time; and connection PHY based on the @@ -1548,7 +1548,7 @@ static void isr_rx_connect_rsp(void *param) } #endif /* CONFIG_BT_CTLR_PRIVACY */ -isr_rx_connect_rsp_do_close: +isr_rx_do_close: if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { lll_prof_cputime_capture(); } From 205314e10607deb9d41665a69e902354fd6d87c5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:02 +0000 Subject: [PATCH 0692/1623] Revert "[nrf fromtree] Bluetooth controller nrf: nrf52 bsim radio hal fix" This reverts commit 35d5889e89181556ca0b4c16f2cb87ad2bbb51ee. Signed-off-by: Dominik Ermel --- .../ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h index 1b8c1583547..3d53462326a 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h @@ -14,10 +14,7 @@ /* NRF Radio HW timing constants * - provided in US and NS (for higher granularity) - * - based on the timings configured in the HW models, which are based - * on the product specification - * - Note that this timings are approx. the same as in the real HW, - * but tend to be rounded to the nearest microsecond + * - based on empirical measurements and sniffer logs */ /* TXEN->TXIDLE + TXIDLE->TX (with fast Radio ramp-up mode) @@ -364,7 +361,7 @@ static inline uint32_t hal_radio_tx_chain_delay_ns_get(uint8_t phy, uint8_t flag ARG_UNUSED(phy); ARG_UNUSED(flags); - return HAL_RADIO_NRF52833_TX_CHAIN_DELAY_NS; + return HAL_RADIO_NRF52833_TX_CHAIN_DELAY_US; } static inline uint32_t hal_radio_rx_chain_delay_ns_get(uint8_t phy, uint8_t flags) From e1fbe67ba6f3e2fd6c6840f7b9561e4178934245 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:02 +0000 Subject: [PATCH 0693/1623] Revert "[nrf fromtree] Bluetooth controller nrf: nrf52 bsim radio hal header minor updates" This reverts commit 5b8de9becc22ff98ef6eeaa36284417a670942d3. Signed-off-by: Dominik Ermel --- .../nordic/hal/nrf5/radio/radio_sim_nrf52.h | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h index 3d53462326a..a767fe1ab30 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h @@ -185,10 +185,14 @@ static inline void hal_radio_reset(void) { + /* TODO: Add any required setup for each radio event + */ } static inline void hal_radio_stop(void) { + /* TODO: Add any required cleanup of actions taken in hal_radio_reset() + */ } static inline void hal_radio_ram_prio_setup(void) @@ -222,39 +226,25 @@ static inline uint32_t hal_radio_tx_power_min_get(void) static inline uint32_t hal_radio_tx_power_max_get(void) { - return RADIO_TXPOWER_TXPOWER_Pos8dBm; +#if defined(RADIO_TXPOWER_TXPOWER_Pos4dBm) + return RADIO_TXPOWER_TXPOWER_Pos4dBm; +#else + return RADIO_TXPOWER_TXPOWER_0dBm; +#endif } static inline uint32_t hal_radio_tx_power_floor(int8_t tx_power_lvl) { - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos8dBm) { - return RADIO_TXPOWER_TXPOWER_Pos8dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos7dBm) { - return RADIO_TXPOWER_TXPOWER_Pos7dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos6dBm) { - return RADIO_TXPOWER_TXPOWER_Pos6dBm; - } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos5dBm) { - return RADIO_TXPOWER_TXPOWER_Pos5dBm; - } - +#if defined(RADIO_TXPOWER_TXPOWER_Pos4dBm) if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos4dBm) { return RADIO_TXPOWER_TXPOWER_Pos4dBm; } - +#endif +#if defined(RADIO_TXPOWER_TXPOWER_Pos3dBm) if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos3dBm) { return RADIO_TXPOWER_TXPOWER_Pos3dBm; } - - if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos2dBm) { - return RADIO_TXPOWER_TXPOWER_Pos2dBm; - } - +#endif if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_0dBm) { return RADIO_TXPOWER_TXPOWER_0dBm; } @@ -279,7 +269,10 @@ static inline uint32_t hal_radio_tx_power_floor(int8_t tx_power_lvl) return RADIO_TXPOWER_TXPOWER_Neg20dBm; } - /* Note: The -30 dBm power level is deprecated so ignore it! */ + if (tx_power_lvl >= (int8_t)RADIO_TXPOWER_TXPOWER_Neg30dBm) { + return RADIO_TXPOWER_TXPOWER_Neg30dBm; + } + return RADIO_TXPOWER_TXPOWER_Neg40dBm; } From 5ce4d0c209dcf6b2ff6aa10e3f1a1f4bfcbb7b1b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:02 +0000 Subject: [PATCH 0694/1623] Revert "[nrf fromtree] Bluetooth: Controller: nrf: HAL for DPPI configuration cleanup" This reverts commit 65eaabbf2ff41853284222cf9f6f2776ef3a794c. Signed-off-by: Dominik Ermel --- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index c28cc35a617..69069288141 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -388,6 +388,21 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) & TIMER_PUBLISH_COMPARE_CHIDX_Msk) | \ ((TIMER_PUBLISH_COMPARE_EN_Enabled << TIMER_PUBLISH_COMPARE_EN_Pos) \ & TIMER_PUBLISH_COMPARE_EN_Msk)) +#define HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_TASK_TX \ + NRF_RADIO->SUBSCRIBE_TXEN +#define HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_TASK_RX \ + NRF_RADIO->SUBSCRIBE_RXEN +#define HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_TX_SET(chan) \ + (((chan << RADIO_SUBSCRIBE_TXEN_CHIDX_Pos) \ + & RADIO_SUBSCRIBE_TXEN_CHIDX_Msk) | \ + ((RADIO_SUBSCRIBE_TXEN_EN_Enabled << \ + RADIO_SUBSCRIBE_TXEN_EN_Pos) \ + & RADIO_SUBSCRIBE_TXEN_EN_Msk)) +#define HAL_SW_SWITCH_RADIO_ENABLE_PPI_TASK_RX_SET(chan) \ + (((chan << RADIO_SUBSCRIBE_RXEN_CHIDX_Pos) \ + & RADIO_SUBSCRIBE_RXEN_CHIDX_Msk) | \ + ((RADIO_SUBSCRIBE_RXEN_EN_Enabled << RADIO_SUBSCRIBE_RXEN_EN_Pos) \ + & RADIO_SUBSCRIBE_RXEN_EN_Msk)) /* Cancel the SW switch timer running considering S8 timing: * wire the RADIO EVENTS_RATEBOOST event to SW_SWITCH_TIMER TASKS_CAPTURE task. From 02a1ce0adc1e984b45ff5e2c03ef9fc7c7db500c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:03 +0000 Subject: [PATCH 0695/1623] Revert "[nrf fromtree] Bluetooth: Controller: nrf: Use HAL for DPPI configuration" This reverts commit 694b89fdbd9a78aedfd9e8521028622b9c54fd52. Signed-off-by: Dominik Ermel --- .../nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 102 ++++++++---------- 1 file changed, 44 insertions(+), 58 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 69069288141..9ed66dc3442 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -317,20 +317,6 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) #define SW_SWITCH_TIMER_S2_EVTS_COMP(index) \ (SW_SWITCH_TIMER_EVTS_COMP_S2_BASE + (index)) -/* - * Convert a dppi channel group number into the *enable* task enumerate value - * the nrfx hal accepts - */ -#define HAL_SW_DPPI_TASK_EN_FROM_IDX(index) \ - (NRF_DPPI_TASK_CHG0_EN + ((index) * (NRF_DPPI_TASK_CHG1_EN - NRF_DPPI_TASK_CHG0_EN))) - -/* - * Convert a dppi channel group number into the *disable* task enumerate value - * the nrfx hal accepts - */ -#define HAL_SW_DPPI_TASK_DIS_FROM_IDX(index) \ - (NRF_DPPI_TASK_CHG0_DIS + ((index) * (NRF_DPPI_TASK_CHG1_EN - NRF_DPPI_TASK_CHG0_EN))) - /* Wire a SW SWITCH TIMER EVENTS_COMPARE[] event * to a PPI GROUP TASK DISABLE task (PPI group with index ). * 2 adjacent PPIs (8 & 9) and 2 adjacent PPI groups are used for this wiring; @@ -346,10 +332,14 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) & TIMER_PUBLISH_COMPARE_CHIDX_Msk) | \ ((TIMER_PUBLISH_COMPARE_EN_Enabled << TIMER_PUBLISH_COMPARE_EN_Pos) \ & TIMER_PUBLISH_COMPARE_EN_Msk)) -#define HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(index, channel) \ - nrf_dppi_subscribe_set(NRF_DPPIC, \ - HAL_SW_DPPI_TASK_DIS_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(index)), \ - channel); +#define HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(index) \ + NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(index)].DIS +#define HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK(chan) \ + (((chan << DPPIC_SUBSCRIBE_CHG_DIS_CHIDX_Pos) \ + & DPPIC_SUBSCRIBE_CHG_DIS_CHIDX_Msk) | \ + ((DPPIC_SUBSCRIBE_CHG_DIS_EN_Enabled << \ + DPPIC_SUBSCRIBE_CHG_DIS_EN_Pos) \ + & DPPIC_SUBSCRIBE_CHG_DIS_EN_Msk)) /* Enable the SW Switch PPI Group on RADIO END Event. * @@ -363,6 +353,15 @@ static inline void hal_sw_switch_timer_clear_ppi_config(void) & RADIO_PUBLISH_END_CHIDX_Msk) | \ ((RADIO_PUBLISH_END_EN_Enabled << RADIO_PUBLISH_END_EN_Pos) \ & RADIO_PUBLISH_END_EN_Msk)) +#define HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK(index) \ + (NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(index)].EN) +#define HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_TASK \ + (((HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI << \ + DPPIC_SUBSCRIBE_CHG_EN_CHIDX_Pos) \ + & DPPIC_SUBSCRIBE_CHG_EN_CHIDX_Msk) | \ + ((DPPIC_SUBSCRIBE_CHG_EN_EN_Enabled << \ + DPPIC_SUBSCRIBE_CHG_EN_EN_Pos) \ + & DPPIC_SUBSCRIBE_CHG_EN_EN_Msk)) /* Enable Radio on SW Switch timer event. * Wire a SW SWITCH TIMER EVENTS_COMPARE[] event @@ -474,15 +473,12 @@ static inline void hal_radio_sw_switch_setup( */ HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_EVT = HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_EVT; - nrf_dppi_subscribe_set(NRF_DPPIC, - HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(ppi_group_index)), - HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI); + HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK(ppi_group_index) = + HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_TASK; /* We need to un-subscribe the other group from the PPI channel. */ - uint8_t other_grp = (ppi_group_index + 1) & 0x01; - - nrf_dppi_subscribe_clear(NRF_DPPIC, - HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(other_grp))); + HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK( + (ppi_group_index + 1) & 0x01) = 0; /* Wire SW Switch timer event to the * PPI[] for enabling Radio. Do @@ -541,10 +537,8 @@ static inline void hal_radio_sw_switch_disable(void) * So we simply cancel the task subscription. */ nrf_timer_subscribe_clear(SW_SWITCH_TIMER, NRF_TIMER_TASK_CLEAR); - nrf_dppi_subscribe_clear(NRF_DPPIC, - HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(0))); - nrf_dppi_subscribe_clear(NRF_DPPIC, - HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(1))); + HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK(0) = 0; + HAL_SW_SWITCH_GROUP_TASK_ENABLE_PPI_REGISTER_TASK(1) = 0; } static inline void hal_radio_sw_switch_cleanup(void) @@ -573,8 +567,8 @@ static inline void hal_radio_sw_switch_coded_tx_config_set(uint8_t ppi_en, HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_EVT(cc_s2) = HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_EVT(ppi_dis); - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(group_index, - ppi_dis); + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(group_index) = + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK(ppi_dis); /* Capture CC to cancel the timer that has assumed * S8 reception, if packet will be received in S2. @@ -615,7 +609,9 @@ static inline void hal_radio_sw_switch_disable_group_clear(uint8_t ppi_dis, uint HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_EVT( ppi_dis); HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK( - group_index, ppi_dis); + group_index) = + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK( + ppi_dis); } #endif /* defined(CONFIG_BT_CTLR_PHY_CODED) */ @@ -628,33 +624,21 @@ static inline void hal_radio_sw_switch_ppi_group_setup(void) * registers are written, therefore, we clear the task registers * here. */ - nrf_dppi_subscribe_clear(NRF_DPPIC, - HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(0))); - nrf_dppi_subscribe_clear(NRF_DPPIC, - HAL_SW_DPPI_TASK_DIS_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(0))); - nrf_dppi_subscribe_clear(NRF_DPPIC, - HAL_SW_DPPI_TASK_EN_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(1))); - nrf_dppi_subscribe_clear(NRF_DPPIC, - HAL_SW_DPPI_TASK_DIS_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(1))); - - nrf_dppi_task_trigger(NRF_DPPIC, - HAL_SW_DPPI_TASK_DIS_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(0))); - nrf_dppi_task_trigger(NRF_DPPIC, - HAL_SW_DPPI_TASK_DIS_FROM_IDX(SW_SWITCH_TIMER_TASK_GROUP(1))); + NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(0)].EN = 0; + NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(0)].DIS = 0; + NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(1)].EN = 0; + NRF_DPPIC->SUBSCRIBE_CHG[SW_SWITCH_TIMER_TASK_GROUP(1)].DIS = 0; + + NRF_DPPIC->TASKS_CHG[SW_SWITCH_TIMER_TASK_GROUP(0)].DIS = 1; + NRF_DPPIC->TASKS_CHG[SW_SWITCH_TIMER_TASK_GROUP(1)].DIS = 1; /* Include the appropriate PPI channels in the two PPI Groups. */ - nrf_dppi_group_clear(NRF_DPPIC, - SW_SWITCH_TIMER_TASK_GROUP(0)); - nrf_dppi_channels_include_in_group(NRF_DPPIC, + NRF_DPPIC->CHG[SW_SWITCH_TIMER_TASK_GROUP(0)] = BIT(HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(0)) | - BIT(HAL_SW_SWITCH_RADIO_ENABLE_PPI(0)), - SW_SWITCH_TIMER_TASK_GROUP(0)); - nrf_dppi_group_clear(NRF_DPPIC, - SW_SWITCH_TIMER_TASK_GROUP(1)); - nrf_dppi_channels_include_in_group(NRF_DPPIC, + BIT(HAL_SW_SWITCH_RADIO_ENABLE_PPI(0)); + NRF_DPPIC->CHG[SW_SWITCH_TIMER_TASK_GROUP(1)] = BIT(HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(1)) | - BIT(HAL_SW_SWITCH_RADIO_ENABLE_PPI(1)), - SW_SWITCH_TIMER_TASK_GROUP(1)); + BIT(HAL_SW_SWITCH_RADIO_ENABLE_PPI(1)); /* Sanity build-time check that RADIO Enable and Group Disable * tasks are going to be subscribed on the same PPIs. @@ -679,7 +663,8 @@ static inline void hal_radio_group_task_disable_ppi_setup(void) SW_SWITCH_TIMER_EVTS_COMP(0)) = HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_EVT( HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(0)); - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(0, + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(0) = + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK( HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(0)); /* Wire SW SWITCH TIMER event to @@ -689,8 +674,9 @@ static inline void hal_radio_group_task_disable_ppi_setup(void) SW_SWITCH_TIMER_EVTS_COMP(1)) = HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_EVT( HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(1)); - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(1, - HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(1)); + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_REGISTER_TASK(1) = + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK( + HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI(1)); } #if defined(CONFIG_BT_CTLR_DF_PHYEND_OFFSET_COMPENSATION_ENABLE) From 41e3ab145f46a6aea945ef2b2b8890f378fc6d4d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:03 +0000 Subject: [PATCH 0696/1623] Revert "[nrf fromtree] Bluetooth: Controller: nRF53: Fix sw switch single timer id regression" This reverts commit c3bc6faf52e3b301e91b62efc1a1763d28f29a46. Signed-off-by: Dominik Ermel --- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5340.h | 14 -------------- tests/bluetooth/init/testcase.yaml | 13 ------------- 2 files changed, 27 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5340.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5340.h index 68267490129..e0f43014508 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5340.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5340.h @@ -5,20 +5,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -/* Override EVENT_TIMER_ID from 4 to 0, as nRF5340 does not have 4 timer - * instances. - */ -#if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) -#undef EVENT_TIMER_ID -#define EVENT_TIMER_ID 0 - -#undef EVENT_TIMER -#define EVENT_TIMER _CONCAT(NRF_TIMER, EVENT_TIMER_ID) - -#undef SW_SWITCH_TIMER -#define SW_SWITCH_TIMER EVENT_TIMER -#endif /* CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ - /* NRF Radio HW timing constants * - provided in US and NS (for higher granularity) * - based on empirical measurements and sniffer logs diff --git a/tests/bluetooth/init/testcase.yaml b/tests/bluetooth/init/testcase.yaml index c38f5bed69e..fa30920dc1e 100644 --- a/tests/bluetooth/init/testcase.yaml +++ b/tests/bluetooth/init/testcase.yaml @@ -122,19 +122,6 @@ tests: integration_platforms: - nrf52840dk_nrf52840 - nrf52dk_nrf52832 - bluetooth.init.test_ctlr_sw_switch_single_timer: - extra_args: - - CONF_FILE=prj_ctlr.conf - - CONFIG_BT_CTLR_ADVANCED_FEATURES=y - - CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER=y - platform_allow: - - nrf5340dk_nrf5340_cpunet - - nrf52840dk_nrf52840 - - nrf52dk_nrf52832 - integration_platforms: - - nrf5340dk_nrf5340_cpunet - - nrf52840dk_nrf52840 - - nrf52dk_nrf52832 bluetooth.init.test_ctlr_ticker: extra_args: - CONF_FILE=prj_ctlr_ticker.conf From 40f8262ed7d69770d9ac5e45cbf7e0c88b5d391a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:03 +0000 Subject: [PATCH 0697/1623] Revert "[nrf fromtree] Bluetooth controller nrf: Rename bsim radio hal header" This reverts commit 5d1edf1e72deadd5680ed527feed12faeb2ee329. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h | 4 ++-- .../hal/nrf5/radio/{radio_sim_nrf52.h => radio_sim_nrfxx.h} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/{radio_sim_nrf52.h => radio_sim_nrfxx.h} (100%) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h index 9e29ab5f70b..a03e55f519d 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h @@ -15,8 +15,8 @@ #define HAL_RADIO_NS2US_ROUND(ns) ((ns + 500)/1000) /* SoC specific defines */ -#if defined(CONFIG_BOARD_NRF52_BSIM) -#include "radio_sim_nrf52.h" +#if defined(CONFIG_SOC_SERIES_BSIM_NRFXX) +#include "radio_sim_nrfxx.h" #elif defined(CONFIG_SOC_SERIES_NRF51X) #include "radio_nrf51.h" #elif defined(CONFIG_SOC_NRF52805) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h similarity index 100% rename from subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrf52.h rename to subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h From 4e8f1c2ceaa1ed33811317b28efdfac40c666c87 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:03 +0000 Subject: [PATCH 0698/1623] Revert "[nrf fromtree] Bluetooth controller nrf: ifdef some coded phy only code" This reverts commit 6a7a93c5ff3a44b58457be8b140fec29fb13ebe1. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 9ed66dc3442..71e5ffa0e6f 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -551,7 +551,6 @@ static inline void hal_radio_sw_switch_cleanup(void) nrf_dppi_group_disable(NRF_DPPIC, SW_SWITCH_TIMER_TASK_GROUP(1)); } -#if defined(CONFIG_BT_CTLR_PHY_CODED) static inline void hal_radio_sw_switch_coded_tx_config_set(uint8_t ppi_en, uint8_t ppi_dis, uint8_t cc_s2, uint8_t group_index) { @@ -613,7 +612,6 @@ static inline void hal_radio_sw_switch_disable_group_clear(uint8_t ppi_dis, uint HAL_SW_SWITCH_GROUP_TASK_DISABLE_PPI_TASK( ppi_dis); } -#endif /* defined(CONFIG_BT_CTLR_PHY_CODED) */ static inline void hal_radio_sw_switch_ppi_group_setup(void) { From 2cd7f15711379e9c1453360fe087e5ba7d285c3a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:04 +0000 Subject: [PATCH 0699/1623] Revert "[nrf fromtree] Bluetooth controller: nrf: Switch to use SOC_COMPATIBLE" This reverts commit cd06b1c9d643c1b3591a925d03bcc48cd9cbc36e. Signed-off-by: Dominik Ermel --- .../bluetooth/controller/Kconfig.ll_sw_split | 10 +-- .../controller/hci/nordic/hci_vendor.h | 2 +- .../ll_sw/nordic/hal/nrf5/radio/radio.c | 72 +++++++++---------- .../nrf5/radio/radio_nrf5_dppi_resources.h | 4 +- .../controller/ll_sw/nordic/hal/nrf5/swi.h | 8 +-- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 4cd8e200b63..1fa9031d47f 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -643,7 +643,7 @@ config BT_CTLR_SLOT_RESERVATION_UPDATE config BT_CTLR_LLL_PRIO int "Lower Link Layer (Radio) IRQ priority" if (BT_CTLR_ULL_LLL_PRIO_SUPPORT && !BT_CTLR_ZLI) range 0 3 if SOC_SERIES_NRF51X - range 0 6 if (SOC_COMPATIBLE_NRF52X || SOC_COMPATIBLE_NRF53X) + range 0 6 if (SOC_SERIES_NRF52X || SOC_SERIES_NRF53X) default 0 help The interrupt priority for event preparation and radio IRQ. @@ -651,7 +651,7 @@ config BT_CTLR_LLL_PRIO config BT_CTLR_ULL_HIGH_PRIO int "Upper Link Layer High IRQ priority" if BT_CTLR_ULL_LLL_PRIO_SUPPORT range BT_CTLR_LLL_PRIO 3 if SOC_SERIES_NRF51X - range BT_CTLR_LLL_PRIO 6 if (SOC_COMPATIBLE_NRF52X || SOC_COMPATIBLE_NRF53X) + range BT_CTLR_LLL_PRIO 6 if (SOC_SERIES_NRF52X || SOC_SERIES_NRF53X) default BT_CTLR_LLL_PRIO if (!BT_CTLR_ULL_LLL_PRIO_SUPPORT || BT_CTLR_ZLI || BT_CTLR_LOW_LAT) default 1 help @@ -661,7 +661,7 @@ config BT_CTLR_ULL_HIGH_PRIO config BT_CTLR_ULL_LOW_PRIO int "Upper Link Layer Low IRQ priority" if BT_CTLR_ULL_LLL_PRIO_SUPPORT range BT_CTLR_ULL_HIGH_PRIO 3 if SOC_SERIES_NRF51X - range BT_CTLR_ULL_HIGH_PRIO 6 if (SOC_COMPATIBLE_NRF52X || SOC_COMPATIBLE_NRF53X) + range BT_CTLR_ULL_HIGH_PRIO 6 if (SOC_SERIES_NRF52X || SOC_SERIES_NRF53X) default BT_CTLR_ULL_HIGH_PRIO help The interrupt priority for Ticker's Job IRQ and Upper Link Layer @@ -705,7 +705,7 @@ config BT_CTLR_RX_PDU_META config BT_CTLR_RADIO_ENABLE_FAST bool "Use tTXEN/RXEN,FAST ramp-up" - depends on SOC_COMPATIBLE_NRF52X || SOC_COMPATIBLE_NRF53X + depends on SOC_COMPATIBLE_NRF52X || SOC_SERIES_NRF53X default y help Enable use of fast radio ramp-up mode. @@ -719,7 +719,7 @@ config BT_CTLR_TIFS_HW config BT_CTLR_SW_SWITCH_SINGLE_TIMER bool "Single TIMER tIFS Trx SW switching" - depends on (!BT_CTLR_TIFS_HW) && (SOC_COMPATIBLE_NRF52X || SOC_COMPATIBLE_NRF53X) + depends on (!BT_CTLR_TIFS_HW) && (SOC_COMPATIBLE_NRF52X || SOC_SERIES_NRF53X) help Implement the tIFS Trx SW switch with the same TIMER instance, as the one used for BLE event timing. Requires diff --git a/subsys/bluetooth/controller/hci/nordic/hci_vendor.h b/subsys/bluetooth/controller/hci/nordic/hci_vendor.h index bea7004f9c9..4d3245728ed 100644 --- a/subsys/bluetooth/controller/hci/nordic/hci_vendor.h +++ b/subsys/bluetooth/controller/hci/nordic/hci_vendor.h @@ -10,7 +10,7 @@ #define BT_HCI_VS_HW_VAR BT_HCI_VS_HW_VAR_NORDIC_NRF51X #elif defined(CONFIG_SOC_COMPATIBLE_NRF52X) #define BT_HCI_VS_HW_VAR BT_HCI_VS_HW_VAR_NORDIC_NRF52X -#elif defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#elif defined(CONFIG_SOC_SERIES_NRF53X) #define BT_HCI_VS_HW_VAR BT_HCI_VS_HW_VAR_NORDIC_NRF53X #endif #else diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 3fc76a27bdf..1875dca7896 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -311,7 +311,7 @@ void radio_phy_set(uint8_t phy, uint8_t flags) void radio_tx_power_set(int8_t power) { -#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#if defined(CONFIG_SOC_SERIES_NRF53X) uint32_t value; /* NOTE: TXPOWER register only accepts upto 0dBm, hence use the HAL @@ -322,12 +322,12 @@ void radio_tx_power_set(int8_t power) NRF_RADIO->TXPOWER = value; hal_radio_tx_power_high_voltage_set(power); -#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#else /* !CONFIG_SOC_SERIES_NRF53X */ /* NOTE: valid value range is passed by Kconfig define. */ NRF_RADIO->TXPOWER = (uint32_t)power; -#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* !CONFIG_SOC_SERIES_NRF53X */ } void radio_tx_power_max_set(void) @@ -345,25 +345,25 @@ int8_t radio_tx_power_min_get(void) int8_t radio_tx_power_max_get(void) { -#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#if defined(CONFIG_SOC_SERIES_NRF53X) return RADIO_TXPOWER_TXPOWER_Pos3dBm; -#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#else /* !CONFIG_SOC_SERIES_NRF53X */ return (int8_t)hal_radio_tx_power_max_get(); -#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* !CONFIG_SOC_SERIES_NRF53X */ } int8_t radio_tx_power_floor(int8_t power) { -#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#if defined(CONFIG_SOC_SERIES_NRF53X) /* NOTE: TXPOWER register only accepts upto 0dBm, +3dBm permitted by * use of high voltage being set for radio when TXPOWER register is set. */ if (power >= (int8_t)RADIO_TXPOWER_TXPOWER_Pos3dBm) { return RADIO_TXPOWER_TXPOWER_Pos3dBm; } -#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* CONFIG_SOC_SERIES_NRF53X */ return (int8_t)hal_radio_tx_power_floor(power); } @@ -413,7 +413,7 @@ void radio_pkt_configure(uint8_t bits_len, uint8_t max_len, uint8_t flags) bits_s1 = RADIO_PKT_CONF_LENGTH_8BIT - bits_len; #elif defined(CONFIG_SOC_COMPATIBLE_NRF52X) || \ - defined(CONFIG_SOC_COMPATIBLE_NRF53X) + defined(CONFIG_SOC_SERIES_NRF53X) extra = 0U; phy = RADIO_PKT_CONF_PHY_GET(flags); @@ -510,7 +510,7 @@ uint32_t radio_rx_chain_delay_get(uint8_t phy, uint8_t flags) void radio_rx_enable(void) { #if !defined(CONFIG_BT_CTLR_TIFS_HW) -#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#if defined(CONFIG_SOC_SERIES_NRF53X) /* NOTE: Timer clear DPPI configuration is needed only for nRF53 * because of calls to radio_disable() and * radio_switch_complete_and_disable() inside a radio event call @@ -523,7 +523,7 @@ void radio_rx_enable(void) * radio event but when the radio event is done. */ hal_sw_switch_timer_clear_ppi_config(); -#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* CONFIG_SOC_SERIES_NRF53X */ #endif /* !CONFIG_BT_CTLR_TIFS_HW */ nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_RXEN); @@ -532,7 +532,7 @@ void radio_rx_enable(void) void radio_tx_enable(void) { #if !defined(CONFIG_BT_CTLR_TIFS_HW) -#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#if defined(CONFIG_SOC_SERIES_NRF53X) /* NOTE: Timer clear DPPI configuration is needed only for nRF53 * because of calls to radio_disable() and * radio_switch_complete_and_disable() inside a radio event call @@ -545,7 +545,7 @@ void radio_tx_enable(void) * radio event but when the radio event is done. */ hal_sw_switch_timer_clear_ppi_config(); -#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* CONFIG_SOC_SERIES_NRF53X */ #endif /* !CONFIG_BT_CTLR_TIFS_HW */ nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_TXEN); @@ -891,13 +891,13 @@ void sw_switch(uint8_t dir_curr, uint8_t dir_next, uint8_t phy_curr, uint8_t fla * time-stamp. */ hal_radio_end_time_capture_ppi_config(); -#if !defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#if !defined(CONFIG_SOC_SERIES_NRF53X) /* The function is not called for nRF5340 single timer configuration because * HAL_SW_SWITCH_TIMER_CLEAR_PPI is equal to HAL_RADIO_END_TIME_CAPTURE_PPI, * so channel is already enabled. */ hal_radio_nrf_ppi_channels_enable(BIT(HAL_RADIO_END_TIME_CAPTURE_PPI)); -#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* !CONFIG_SOC_SERIES_NRF53X */ #endif /* CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ sw_tifs_toggle += 1U; @@ -1186,38 +1186,38 @@ void radio_tmr_rx_status_reset(void) void radio_tmr_tx_enable(void) { -#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) -#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#if defined(CONFIG_SOC_SERIES_NRF53X) +#else /* !CONFIG_SOC_SERIES_NRF53X */ #if (HAL_RADIO_ENABLE_TX_ON_TICK_PPI == HAL_RADIO_ENABLE_RX_ON_TICK_PPI) hal_radio_enable_on_tick_ppi_config_and_enable(1U); #endif /* HAL_RADIO_ENABLE_TX_ON_TICK_PPI == HAL_RADIO_ENABLE_RX_ON_TICK_PPI */ -#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* !CONFIG_SOC_SERIES_NRF53X */ } void radio_tmr_rx_enable(void) { -#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) -#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#if defined(CONFIG_SOC_SERIES_NRF53X) +#else /* !CONFIG_SOC_SERIES_NRF53X */ #if (HAL_RADIO_ENABLE_TX_ON_TICK_PPI == HAL_RADIO_ENABLE_RX_ON_TICK_PPI) hal_radio_enable_on_tick_ppi_config_and_enable(0U); #endif /* HAL_RADIO_ENABLE_TX_ON_TICK_PPI == HAL_RADIO_ENABLE_RX_ON_TICK_PPI */ -#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* !CONFIG_SOC_SERIES_NRF53X */ } void radio_tmr_tx_disable(void) { -#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#if defined(CONFIG_SOC_SERIES_NRF53X) nrf_radio_subscribe_clear(NRF_RADIO, NRF_RADIO_TASK_TXEN); -#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ -#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#else /* !CONFIG_SOC_SERIES_NRF53X */ +#endif /* !CONFIG_SOC_SERIES_NRF53X */ } void radio_tmr_rx_disable(void) { -#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#if defined(CONFIG_SOC_SERIES_NRF53X) nrf_radio_subscribe_clear(NRF_RADIO, NRF_RADIO_TASK_RXEN); -#else /* !CONFIG_SOC_COMPATIBLE_NRF53X */ -#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X */ +#else /* !CONFIG_SOC_SERIES_NRF53X */ +#endif /* !CONFIG_SOC_SERIES_NRF53X */ } void radio_tmr_tifs_set(uint32_t tifs) @@ -1304,7 +1304,7 @@ uint32_t radio_tmr_start_tick(uint8_t trx, uint32_t tick) #if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) last_pdu_end_us = 0U; #endif /* CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ -#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#if defined(CONFIG_SOC_SERIES_NRF53X) /* NOTE: Timer clear DPPI configuration is needed only for nRF53 * because of calls to radio_disable() and * radio_switch_complete_and_disable() inside a radio event call @@ -1317,7 +1317,7 @@ uint32_t radio_tmr_start_tick(uint8_t trx, uint32_t tick) * radio event but when the radio event is done. */ hal_sw_switch_timer_clear_ppi_config(); -#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* CONFIG_SOC_SERIES_NRF53X */ #endif /* !CONFIG_BT_CTLR_TIFS_HW */ return remainder_us; @@ -1331,7 +1331,7 @@ uint32_t radio_tmr_start_us(uint8_t trx, uint32_t start_us) #if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) last_pdu_end_us = 0U; #endif /* CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ -#if defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#if defined(CONFIG_SOC_SERIES_NRF53X) /* NOTE: Timer clear DPPI configuration is needed only for nRF53 * because of calls to radio_disable() and * radio_switch_complete_and_disable() inside a radio event call @@ -1344,7 +1344,7 @@ uint32_t radio_tmr_start_us(uint8_t trx, uint32_t start_us) * radio event but when the radio event is done. */ hal_sw_switch_timer_clear_ppi_config(); -#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* CONFIG_SOC_SERIES_NRF53X */ #endif /* !CONFIG_BT_CTLR_TIFS_HW */ /* start_us could be the current count in the timer */ @@ -1464,12 +1464,12 @@ void radio_tmr_end_capture(void) * hal_sw_switch_timer_clear_ppi_config() and sw_switch(). There is no need to * configure the channel again in this function. */ -#if !defined(CONFIG_SOC_COMPATIBLE_NRF53X) || \ - (defined(CONFIG_SOC_COMPATIBLE_NRF53X) && !defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER)) +#if !defined(CONFIG_SOC_SERIES_NRF53X) || \ + (defined(CONFIG_SOC_SERIES_NRF53X) && !defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER)) hal_radio_end_time_capture_ppi_config(); hal_radio_nrf_ppi_channels_enable(BIT(HAL_RADIO_END_TIME_CAPTURE_PPI)); -#endif /* !CONFIG_SOC_COMPATIBLE_NRF53X || - * (CONFIG_SOC_COMPATIBLE_NRF53X && !CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) +#endif /* !CONFIG_SOC_SERIES_NRF53X || + * (CONFIG_SOC_SERIES_NRF53X && !CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) */ } @@ -1776,7 +1776,7 @@ static void *radio_ccm_ext_tx_pkt_set(struct ccm *cnf, uint8_t pdu_type, void *p NRF_CCM->ENABLE = CCM_ENABLE_ENABLE_Enabled; mode = (CCM_MODE_MODE_Encryption << CCM_MODE_MODE_Pos) & CCM_MODE_MODE_Msk; -#if defined(CONFIG_SOC_COMPATIBLE_NRF52X) || defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#if defined(CONFIG_SOC_COMPATIBLE_NRF52X) || defined(CONFIG_SOC_SERIES_NRF53X) /* Enable CCM support for 8-bit length field PDUs. */ mode |= (CCM_MODE_LENGTH_Extended << CCM_MODE_LENGTH_Pos) & CCM_MODE_LENGTH_Msk; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h index e1b47d03fd7..74fb56d9b5c 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_resources.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#if defined(CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET) || defined(DPPI_PRESENT) +#if defined(CONFIG_SOC_NRF5340_CPUNET) || defined(DPPI_PRESENT) /******************************************************************************* * Enable Radio on Event Timer tick: @@ -157,4 +157,4 @@ #define SW_SWITCH_TIMER_TASK_GROUP_BASE 0 #endif /* !CONFIG_BT_CTLR_TIFS_HW */ -#endif /* CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET || DPPI_PRESENT */ +#endif /* CONFIG_SOC_NRF5340_CPUNET || DPPI_PRESENT */ diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/swi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/swi.h index 6b364fd349a..eb9da5652ff 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/swi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/swi.h @@ -18,10 +18,10 @@ #endif /* nRF53 Series IRQ mapping */ -#elif defined(CONFIG_SOC_COMPATIBLE_NRF53X) +#elif defined(CONFIG_SOC_SERIES_NRF53X) /* nRF53 Series Engineering D and Revision 1 IRQ mapping */ -#if defined(CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET) +#if defined(CONFIG_SOC_NRF5340_CPUNET) #define HAL_SWI_RADIO_IRQ SWI2_IRQn #define HAL_SWI_WORKER_IRQ RTC0_IRQn @@ -33,9 +33,9 @@ #define HAL_SWI_JOB_IRQ SWI3_IRQn #endif -#endif /* CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET */ +#endif /* CONFIG_SOC_NRF5340_CPUNET */ -#endif /* CONFIG_SOC_COMPATIBLE_NRF53X */ +#endif /* CONFIG_SOC_SERIES_NRF53X */ static inline void hal_swi_init(void) { From 9e6178ed17e6ef2c8f022784c3beb6894f995ec2 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:04 +0000 Subject: [PATCH 0700/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix missing host feature reset" This reverts commit 0cbe44c1bf783f13cf6da1ede4e199771e97f3fd. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ll_feat.c | 5 ----- subsys/bluetooth/controller/ll_sw/ll_feat_internal.h | 7 ------- subsys/bluetooth/controller/ll_sw/ull.c | 7 +------ 3 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 subsys/bluetooth/controller/ll_sw/ll_feat_internal.h diff --git a/subsys/bluetooth/controller/ll_sw/ll_feat.c b/subsys/bluetooth/controller/ll_sw/ll_feat.c index d2ba2fefba0..a1aaa99ba6d 100644 --- a/subsys/bluetooth/controller/ll_sw/ll_feat.c +++ b/subsys/bluetooth/controller/ll_sw/ll_feat.c @@ -70,11 +70,6 @@ uint8_t ll_set_host_feature(uint8_t bit_number, uint8_t bit_value) return BT_HCI_ERR_SUCCESS; } -void ll_feat_reset(void) -{ - host_features = 0U; -} - uint64_t ll_feat_get(void) { return LL_FEAT | (host_features & LL_FEAT_HOST_BIT_MASK); diff --git a/subsys/bluetooth/controller/ll_sw/ll_feat_internal.h b/subsys/bluetooth/controller/ll_sw/ll_feat_internal.h deleted file mode 100644 index 7c23cb1a4e5..00000000000 --- a/subsys/bluetooth/controller/ll_sw/ll_feat_internal.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -void ll_feat_reset(void); diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index e6a736f939d..29cf43cd6d9 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -44,7 +44,6 @@ #include "lll_sync_iso.h" #include "lll_iso_tx.h" #include "lll_conn.h" -#include "lll_conn_iso.h" #include "lll_df.h" #include "ull_adv_types.h" @@ -61,7 +60,6 @@ #endif /* CONFIG_BT_CTLR_USER_EXT */ #include "isoal.h" -#include "ll_feat_internal.h" #include "ull_internal.h" #include "ull_iso_internal.h" #include "ull_adv_internal.h" @@ -71,6 +69,7 @@ #include "ull_central_internal.h" #include "ull_iso_types.h" #include "ull_conn_internal.h" +#include "lll_conn_iso.h" #include "ull_conn_iso_types.h" #include "ull_central_iso_internal.h" #include "ull_llcp.h" @@ -900,10 +899,6 @@ void ll_reset(void) LL_ASSERT(!err); #endif -#if defined(CONFIG_BT_CTLR_SET_HOST_FEATURE) - ll_feat_reset(); -#endif /* CONFIG_BT_CTLR_SET_HOST_FEATURE */ - /* clear static random address */ (void)ll_addr_set(1U, NULL); } From 187b9042929e7a9e592b3bf847627666ad176372 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:04 +0000 Subject: [PATCH 0701/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix assertion due to late PER CIS active set" This reverts commit ca85f44bdbc22337acd4b3ff64b7fab086443271. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index f68ca66656f..d45d89aa009 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -250,8 +250,7 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl, cis->p_max_sdu = (uint16_t)(req->p_max_sdu[1] & 0x0F) << 8 | req->p_max_sdu[0]; - cis->lll.active = 0U; - cis->lll.handle = LLL_HANDLE_INVALID; + cis->lll.handle = 0xFFFF; cis->lll.acl_handle = acl->lll.handle; cis->lll.sub_interval = sys_get_le24(req->sub_interval); cis->lll.nse = req->nse; @@ -326,6 +325,7 @@ uint8_t ull_peripheral_iso_setup(struct pdu_data_llctrl_cis_ind *ind, cis->lll.cie = 0U; cis->lll.npi = 0U; cis->lll.flush = LLL_CIS_FLUSH_NONE; + cis->lll.active = 0U; cis->lll.datapath_ready_rx = 0U; cis->lll.tx.payload_count = 0U; cis->lll.rx.payload_count = 0U; From 61e74af480a872ad239a571168d4f47fa84184d3 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:04 +0000 Subject: [PATCH 0702/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix PHY value in HCI LE CIS Established Event" This reverts commit 18f4f8597ba8339cb26fde13ac9917d027fca9ec. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/hci/hci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 0adbf5ff70c..30fb363fc9c 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -4245,8 +4245,8 @@ static void le_cis_established(struct pdu_data *pdu_data, sys_put_le24(cis->sync_delay, sep->cis_sync_delay); sys_put_le24(cig->c_latency, sep->c_latency); sys_put_le24(cig->p_latency, sep->p_latency); - sep->c_phy = find_lsb_set(lll_cis_c->phy); - sep->p_phy = find_lsb_set(lll_cis_p->phy); + sep->c_phy = lll_cis_c->phy; + sep->p_phy = lll_cis_p->phy; sep->nse = lll_cis->nse; sep->c_bn = lll_cis_c->bn; sep->p_bn = lll_cis_p->bn; From 2006e25cd388426d3a55c8bf4f0e06c0cfff6a8e Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:05 +0000 Subject: [PATCH 0703/1623] Revert "[nrf fromtree] Bluetooth: Controller: Use max time when scheduling Broadcast ISO" This reverts commit 5f4e7b0cc6f13cd4c8d659fc8833787d8997fa9e. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/ull_adv_internal.h | 3 - .../bluetooth/controller/ll_sw/ull_adv_iso.c | 63 ++++++------------- subsys/bluetooth/controller/ll_sw/ull_sched.c | 5 +- 3 files changed, 19 insertions(+), 52 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h index a2a0db7391f..f4d059e0cd3 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h @@ -322,9 +322,6 @@ struct lll_adv_iso_stream *ull_adv_iso_stream_get(uint16_t handle); /* helper function to release stream instances */ void ull_adv_iso_stream_release(struct ll_adv_iso_set *adv_iso); -/* helper function to return time reservation for Broadcast ISO event */ -uint32_t ull_adv_iso_max_time_get(const struct ll_adv_iso_set *adv_iso); - #if defined(CONFIG_BT_CTLR_DF_ADV_CTE_TX) /* helper function to release unused DF configuration memory */ void ull_df_adv_cfg_release(struct lll_df_adv_cfg *df_adv_cfg); diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index 6191f811311..de78352baa2 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -57,7 +57,6 @@ static struct stream *adv_iso_stream_acquire(void); static uint16_t adv_iso_stream_handle_get(struct lll_adv_iso_stream *stream); static uint8_t ptc_calc(const struct lll_adv_iso *lll, uint32_t event_spacing, uint32_t event_spacing_max); -static uint32_t adv_iso_time_get(const struct ll_adv_iso_set *adv_iso, bool max); static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, uint32_t iso_interval_us); static uint8_t adv_iso_chm_update(uint8_t big_handle); @@ -946,11 +945,6 @@ void ull_adv_iso_stream_release(struct ll_adv_iso_set *adv_iso) lll->adv = NULL; } -uint32_t ull_adv_iso_max_time_get(const struct ll_adv_iso_set *adv_iso) -{ - return adv_iso_time_get(adv_iso, true); -} - static int init_reset(void) { /* Add initializations common to power up initialization and HCI reset @@ -1004,12 +998,22 @@ static uint8_t ptc_calc(const struct lll_adv_iso *lll, uint32_t event_spacing, return 0U; } -static uint32_t adv_iso_time_get(const struct ll_adv_iso_set *adv_iso, bool max) +static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, + uint32_t iso_interval_us) { - const struct lll_adv_iso *lll_iso; + uint32_t ticks_slot_overhead; + struct lll_adv_iso *lll_iso; + uint32_t ticks_slot_offset; + uint32_t volatile ret_cb; + uint32_t ticks_anchor; uint32_t ctrl_spacing; uint32_t pdu_spacing; - uint32_t time_us; + uint32_t ticks_slot; + uint32_t slot_us; + uint32_t ret; + int err; + + ull_hdr_init(&adv_iso->ull); lll_iso = &adv_iso->lll; @@ -1019,46 +1023,15 @@ static uint32_t adv_iso_time_get(const struct ll_adv_iso_set *adv_iso, bool max) ctrl_spacing = PDU_BIS_US(sizeof(struct pdu_big_ctrl), lll_iso->enc, lll_iso->phy, lll_iso->phy_flags); - /* 1. Maximum PDU transmission time in 1M/2M/S8 PHY is 17040 us, or - * represented in 15-bits. - * 2. NSE in the range 1 to 31 is represented in 5-bits - * 3. num_bis in the range 1 to 31 is represented in 5-bits - * - * Hence, worst case event time can be represented in 25-bits plus - * one each bit for added ctrl_spacing and radio event overheads. I.e. - * 27-bits required and sufficiently covered by using 32-bit data type - * for time_us. - */ - - if (IS_ENABLED(CONFIG_BT_CTLR_ADV_ISO_RESERVE_MAX) || max) { - time_us = (pdu_spacing * lll_iso->nse * lll_iso->num_bis) + + if (IS_ENABLED(CONFIG_BT_CTLR_ADV_ISO_RESERVE_MAX)) { + slot_us = (pdu_spacing * lll_iso->nse * lll_iso->num_bis) + ctrl_spacing; } else { - time_us = pdu_spacing * ((lll_iso->nse * lll_iso->num_bis) - + slot_us = pdu_spacing * ((lll_iso->nse * lll_iso->num_bis) - lll_iso->ptc); } - /* Add implementation defined radio event overheads */ - time_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; - - return time_us; -} - -static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, - uint32_t iso_interval_us) -{ - uint32_t ticks_slot_overhead; - uint32_t ticks_slot_offset; - volatile uint32_t ret_cb; - uint32_t ticks_anchor; - uint32_t ticks_slot; - uint32_t slot_us; - uint32_t ret; - int err; - - ull_hdr_init(&adv_iso->ull); - - slot_us = adv_iso_time_get(adv_iso, false); + slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; adv_iso->ull.ticks_active_to_start = 0U; adv_iso->ull.ticks_prepare_to_start = @@ -1093,7 +1066,7 @@ static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, ret_cb = TICKER_STATUS_BUSY; ret = ticker_start(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, - (TICKER_ID_ADV_ISO_BASE + adv_iso->lll.handle), + (TICKER_ID_ADV_ISO_BASE + lll_iso->handle), ticks_anchor, 0U, HAL_TICKER_US_TO_TICKS(iso_interval_us), HAL_TICKER_REMAINDER(iso_interval_us), diff --git a/subsys/bluetooth/controller/ll_sw/ull_sched.c b/subsys/bluetooth/controller/ll_sw/ull_sched.c index 38589a2e644..e7ca8a0358b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sched.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sched.c @@ -701,10 +701,7 @@ static struct ull_hdr *ull_hdr_get_cb(uint8_t ticker_id, uint32_t *ticks_slot) adv_iso = ull_adv_iso_get(ticker_id - TICKER_ID_ADV_ISO_BASE); if (adv_iso) { - uint32_t time_us; - - time_us = ull_adv_iso_max_time_get(adv_iso); - *ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); + *ticks_slot = adv_iso->ull.ticks_slot; return &adv_iso->ull; } From 1a9b63edcf9937b9f9fbfb8f87d1dea14bc8ffc7 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:05 +0000 Subject: [PATCH 0704/1623] Revert "[nrf fromtree] Bluetooth: Controller: Maximize BIG event length and preempt PTO & CTRL" This reverts commit 15f89d667165914c90f6b5931e3d15b97f624f4a. Signed-off-by: Dominik Ermel --- .../bluetooth/controller/Kconfig.ll_sw_split | 12 ----- .../bluetooth/controller/ll_sw/ull_adv_iso.c | 51 ++++++------------- 2 files changed, 15 insertions(+), 48 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 1fa9031d47f..5fb2c54d085 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -386,18 +386,6 @@ config BT_CTLR_ADV_RESERVE_MAX corresponding to the Advertising Data present at the time of the start/enable of Advertising is used. -config BT_CTLR_ADV_ISO_RESERVE_MAX - bool "Use maximum Broadcast ISO event time reservation" - depends on BT_CTLR_ADV_ISO - default y - help - Use maximum Broadcast ISO event time reservation. If disabled, then - time reservation does not include the pre-transmissions of the last - BIS and any Control subevents. This will allow extended or periodic - advertising events to preempt the BIG events but allow higher radio - utilizations by allowing larger BIG events when not overlapping with - extended or periodic advertising. - config BT_CTLR_ADV_AUX_SYNC_OFFSET int "Pre-defined offset between AUX_ADV_IND and AUX_SYNC_IND" depends on BT_CTLR_ADV_PERIODIC diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index de78352baa2..4551fac228d 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -282,41 +282,27 @@ uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis, event_spacing = latency_packing + ctrl_spacing + EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; - /* Check if aux context allocated before we are creating ISO */ - if (adv->lll.aux) { - aux = HDR_LLL2ULL(adv->lll.aux); - } else { - aux = NULL; - } - /* Calculate overheads due to extended advertising. */ - if (aux && aux->is_started) { - ticks_slot_aux = aux->ull.ticks_slot; - if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { - ticks_slot_overhead = MAX(aux->ull.ticks_active_to_start, - aux->ull.ticks_prepare_to_start); - } else { - ticks_slot_overhead = 0U; - } - ticks_slot_aux += ticks_slot_overhead; + aux = HDR_LLL2ULL(adv->lll.aux); + ticks_slot_aux = aux->ull.ticks_slot; + if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { + ticks_slot_overhead = MAX(aux->ull.ticks_active_to_start, + aux->ull.ticks_prepare_to_start); } else { - ticks_slot_aux = 0U; + ticks_slot_overhead = 0U; } + ticks_slot_aux += ticks_slot_overhead; /* Calculate overheads due to periodic advertising. */ sync = HDR_LLL2ULL(lll_adv_sync); - if (sync->is_started) { - ticks_slot_sync = sync->ull.ticks_slot; - if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { - ticks_slot_overhead = MAX(sync->ull.ticks_active_to_start, - sync->ull.ticks_prepare_to_start); - } else { - ticks_slot_overhead = 0U; - } - ticks_slot_sync += ticks_slot_overhead; + ticks_slot_sync = sync->ull.ticks_slot; + if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { + ticks_slot_overhead = MAX(sync->ull.ticks_active_to_start, + sync->ull.ticks_prepare_to_start); } else { - ticks_slot_sync = 0U; + ticks_slot_overhead = 0U; } + ticks_slot_sync += ticks_slot_overhead; /* Calculate total overheads due to extended and periodic advertising */ if (CONFIG_BT_CTLR_ADV_AUX_SYNC_OFFSET > 0U) { @@ -1022,15 +1008,8 @@ static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, EVENT_MSS_US; ctrl_spacing = PDU_BIS_US(sizeof(struct pdu_big_ctrl), lll_iso->enc, lll_iso->phy, lll_iso->phy_flags); - - if (IS_ENABLED(CONFIG_BT_CTLR_ADV_ISO_RESERVE_MAX)) { - slot_us = (pdu_spacing * lll_iso->nse * lll_iso->num_bis) + - ctrl_spacing; - } else { - slot_us = pdu_spacing * ((lll_iso->nse * lll_iso->num_bis) - - lll_iso->ptc); - } - + slot_us = (pdu_spacing * lll_iso->nse * lll_iso->num_bis) + + ctrl_spacing; slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; adv_iso->ull.ticks_active_to_start = 0U; From d58bb9f33ece628ffa19496b1efcc5df1e09d5e9 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:05 +0000 Subject: [PATCH 0705/1623] Revert "[nrf fromtree] Bluetooth: Controller: Calculate Broadcast ISO event overheads" This reverts commit 5066d19a144b3096e6ee5c6ceb755b7589938a5e. Signed-off-by: Dominik Ermel --- .../bluetooth/controller/ll_sw/ull_adv_iso.c | 52 +++---------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index 4551fac228d..cb53f913b01 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -97,19 +97,13 @@ uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis, struct ll_adv_iso_set *adv_iso; struct pdu_adv *pdu_prev, *pdu; struct pdu_big_info *big_info; - uint32_t ticks_slot_overhead; - struct ll_adv_sync_set *sync; - struct ll_adv_aux_set *aux; uint32_t event_spacing_max; uint8_t pdu_big_info_size; uint32_t iso_interval_us; uint32_t latency_packing; - uint32_t ticks_slot_sync; - uint32_t ticks_slot_aux; memq_link_t *link_cmplt; memq_link_t *link_term; struct ll_adv_set *adv; - uint32_t slot_overhead; uint32_t event_spacing; uint16_t ctrl_spacing; uint8_t sdu_per_event; @@ -281,48 +275,14 @@ uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis, lll_adv_iso->num_bis; event_spacing = latency_packing + ctrl_spacing + EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; - - /* Calculate overheads due to extended advertising. */ - aux = HDR_LLL2ULL(adv->lll.aux); - ticks_slot_aux = aux->ull.ticks_slot; - if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { - ticks_slot_overhead = MAX(aux->ull.ticks_active_to_start, - aux->ull.ticks_prepare_to_start); - } else { - ticks_slot_overhead = 0U; - } - ticks_slot_aux += ticks_slot_overhead; - - /* Calculate overheads due to periodic advertising. */ - sync = HDR_LLL2ULL(lll_adv_sync); - ticks_slot_sync = sync->ull.ticks_slot; - if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { - ticks_slot_overhead = MAX(sync->ull.ticks_active_to_start, - sync->ull.ticks_prepare_to_start); - } else { - ticks_slot_overhead = 0U; - } - ticks_slot_sync += ticks_slot_overhead; - - /* Calculate total overheads due to extended and periodic advertising */ - if (CONFIG_BT_CTLR_ADV_AUX_SYNC_OFFSET > 0U) { - ticks_slot_overhead = MAX(ticks_slot_aux, ticks_slot_sync); - } else { - ticks_slot_overhead = ticks_slot_aux + ticks_slot_sync; - } - - /* Calculate max available ISO event spacing */ - slot_overhead = HAL_TICKER_TICKS_TO_US(ticks_slot_overhead); - if (slot_overhead < iso_interval_us) { - event_spacing_max = iso_interval_us - slot_overhead; - } else { - event_spacing_max = 0U; - } - - /* Check if ISO interval too small to fit the calculated BIG event - * timing required for the supplied BIG create parameters. + /* FIXME: calculate overheads due to extended and periodic advertising. */ + event_spacing_max = iso_interval_us - 2000U; if (event_spacing > event_spacing_max) { + /* ISO interval too small to fit the calculated BIG event + * timing required for the supplied BIG create parameters. + */ + /* Release allocated link buffers */ ll_rx_link_release(link_cmplt); ll_rx_link_release(link_term); From 11063f255a8b4f147475fa0966d25172a33c78e0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:05 +0000 Subject: [PATCH 0706/1623] Revert "[nrf fromtree] Bluetooth: Controller: Minor rename ull_adv_sync_iso_created()" This reverts commit 46a5b07bbc1d5dd0ed2c5bb7a12d4996d6703795. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_adv_internal.h | 2 +- subsys/bluetooth/controller/ll_sw/ull_adv_iso.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_adv_sync.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h index f4d059e0cd3..00bf3c126df 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h @@ -205,7 +205,7 @@ ull_adv_aux_hdr_len_fill(struct pdu_adv_com_ext_adv *com_hdr, uint8_t len) void ull_adv_sync_started_stopped(struct ll_adv_aux_set *aux); /* notify adv_sync_set that an iso instance has been created for it */ -void ull_adv_sync_iso_created(struct ll_adv_sync_set *sync); +void ull_adv_iso_created(struct ll_adv_sync_set *sync); #endif /* CONFIG_BT_CTLR_ADV_EXT */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index cb53f913b01..89e66ff99e5 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -487,7 +487,7 @@ uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis, #if defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO) /* Notify the sync instance */ - ull_adv_sync_iso_created(HDR_LLL2ULL(lll_adv_sync)); + ull_adv_iso_created(HDR_LLL2ULL(lll_adv_sync)); #endif /* CONFIG_BT_TICKER_EXT_EXPIRE_INFO */ /* Commit the BIGInfo in the ACAD field of Periodic Advertising */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c index f1f521ca235..bbb1b351848 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c @@ -222,7 +222,7 @@ uint8_t ll_adv_sync_param_set(uint8_t handle, uint16_t interval, uint16_t flags) } #if defined(CONFIG_BT_CTLR_ADV_ISO) && defined(CONFIG_BT_TICKER_EXT_EXPIRE_INFO) -void ull_adv_sync_iso_created(struct ll_adv_sync_set *sync) +void ull_adv_iso_created(struct ll_adv_sync_set *sync) { if (sync->lll.iso && sync->is_started) { uint8_t iso_handle = sync->lll.iso->handle; From f1ae885d8799eda41d34fdc50cfec38496e69887 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:06 +0000 Subject: [PATCH 0707/1623] Revert "[nrf fromtree] Bluetooth: Controller: Revert EVENT_OVERHEAD_START_US for Coded PHY" This reverts commit 064912923c684da6a02b32ebec9a895b4f2ae319. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h index db5f8e3f1d8..7df39f65c8a 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h @@ -21,22 +21,22 @@ /* Active connection in peripheral role with extended scanning on 1M and Coded * PHY, scheduling and receiving auxiliary PDUs. */ -#define EVENT_OVERHEAD_START_US 733 /* 24 RTC ticks */ +#define EVENT_OVERHEAD_START_US 458 #else /* !CONFIG_BT_CTLR_PHY_CODED */ /* Active connection in peripheral role with extended scanning on 1M only, * scheduling and receiving auxiliary PDUs. */ -#define EVENT_OVERHEAD_START_US 428 /* 14 RTC ticks */ +#define EVENT_OVERHEAD_START_US 428 #endif /* !CONFIG_BT_CTLR_PHY_CODED */ #else /* !CONFIG_BT_OBSERVER */ /* Active connection in peripheral role with legacy scanning on 1M. */ -#define EVENT_OVERHEAD_START_US 275 /* 9 RTC ticks */ +#define EVENT_OVERHEAD_START_US 275 #endif /* !CONFIG_BT_OBSERVER */ #else /* !CONFIG_BT_CTLR_ADV_EXT */ /* Active connection in peripheral role with additional advertising state. */ -#define EVENT_OVERHEAD_START_US 275 /* 9 RTC ticks */ +#define EVENT_OVERHEAD_START_US 275 #endif /* !CONFIG_BT_CTLR_ADV_EXT */ /* Worst-case time margin needed after event end-time in the air From b3372acfe2f0a9eb5dff5266f1061d261211436f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:06 +0000 Subject: [PATCH 0708/1623] Revert "[nrf fromtree] Bluetooth: Controller: Reduce successive ticker_job() on Extended Scan" This reverts commit c86add5e2012481673862ff86407a15979280e0b. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_scan_aux.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c b/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c index ecdfdd60d07..316cec7fec7 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c @@ -682,13 +682,6 @@ void ull_scan_aux_setup(memq_link_t *link, struct node_rx_hdr *rx) ticks_aux_offset = HAL_TICKER_US_TO_TICKS(aux_offset_us); -#if (CONFIG_BT_CTLR_ULL_HIGH_PRIO == CONFIG_BT_CTLR_ULL_LOW_PRIO) - /* disable ticker job, in order to chain yield and start to reduce - * CPU use by reducing successive calls to ticker_job(). - */ - mayfly_enable(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_ULL_LOW, 0); -#endif - /* Yield the primary scan window or auxiliary or periodic sync event * in ticker. */ @@ -721,13 +714,6 @@ void ull_scan_aux_setup(memq_link_t *link, struct node_rx_hdr *rx) ((ticker_status == TICKER_STATUS_FAILURE) && IS_ENABLED(CONFIG_BT_TICKER_LOW_LAT))); -#if (CONFIG_BT_CTLR_ULL_HIGH_PRIO == CONFIG_BT_CTLR_ULL_LOW_PRIO) - /* enable ticker job, queued ticker operation will be handled - * thereafter. - */ - mayfly_enable(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_ULL_LOW, 1); -#endif - return; ull_scan_aux_rx_flush: From f726a15c15ff0eddd9e98adbaf0ae99ab4c1684e Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:06 +0000 Subject: [PATCH 0709/1623] Revert "[nrf fromtree] Bluetooth: Controller: Refactor prepare dequeue iteration code" This reverts commit 290662fbfd0c9aecf7067a2440db51b9d6260027. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/lll/lll.c | 165 +++++++++--------- 1 file changed, 83 insertions(+), 82 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index db8f25a374c..9ccc36e49e5 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -65,9 +65,7 @@ static int init_reset(void); #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) static inline void done_inc(void); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ -static inline bool is_done_sync(void); -static inline struct lll_event *prepare_dequeue_iter_ready_get(uint8_t *idx); -static inline struct lll_event *resume_enqueue(lll_prepare_cb_t resume_cb); +static struct lll_event *resume_enqueue(lll_prepare_cb_t resume_cb); static void isr_race(void *param); #if !defined(CONFIG_BT_CTLR_LOW_LAT) @@ -645,27 +643,52 @@ void lll_isr_early_abort(void *param) lll_done(NULL); } +static int init_reset(void) +{ + return 0; +} + +#if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) +static inline void done_inc(void) +{ + event.done.lll_count++; + LL_ASSERT(event.done.lll_count != event.done.ull_count); +} +#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ + +static inline bool is_done_sync(void) +{ +#if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) + return event.done.lll_count == event.done.ull_count; +#else /* !CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ + return true; +#endif /* !CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ +} + int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, lll_prepare_cb_t prepare_cb, struct lll_prepare_param *prepare_param, uint8_t is_resume, uint8_t is_dequeue) { - struct lll_event *ready; - struct lll_event *next; + struct lll_event *p; uint8_t idx; int err; /* Find the ready prepare in the pipeline */ idx = UINT8_MAX; - ready = prepare_dequeue_iter_ready_get(&idx); + p = ull_prepare_dequeue_iter(&idx); + while (p && (p->is_aborted || p->is_resume)) { + p = ull_prepare_dequeue_iter(&idx); + } /* Current event active or another prepare is ready in the pipeline */ if ((!is_dequeue && !is_done_sync()) || event.curr.abort_cb || - (ready && is_resume)) { + (p && is_resume)) { #if defined(CONFIG_BT_CTLR_LOW_LAT) lll_prepare_cb_t resume_cb; #endif /* CONFIG_BT_CTLR_LOW_LAT */ + struct lll_event *next; if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT) && event.curr.param) { /* early abort */ @@ -683,28 +706,29 @@ int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, } /* Always start preempt timeout for first prepare in pipeline */ - struct lll_event *first = ready ? ready : next; + struct lll_event *first = p ? p : next; uint32_t ret; /* Start the preempt timeout */ - ret = preempt_ticker_start(first, ready, next); + ret = preempt_ticker_start(first, p, next); LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || (ret == TICKER_STATUS_BUSY)); #else /* CONFIG_BT_CTLR_LOW_LAT */ next = NULL; - while (ready) { - if (!ready->is_aborted) { - if (event.curr.param == ready->prepare_param.param) { - ready->is_aborted = 1; - ready->abort_cb(&ready->prepare_param, - ready->prepare_param.param); + while (p) { + if (!p->is_aborted) { + if (event.curr.param == + p->prepare_param.param) { + p->is_aborted = 1; + p->abort_cb(&p->prepare_param, + p->prepare_param.param); } else { - next = ready; + next = p; } } - ready = ull_prepare_dequeue_iter(&idx); + p = ull_prepare_dequeue_iter(&idx); } if (next) { @@ -725,7 +749,7 @@ int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, return -EINPROGRESS; } - LL_ASSERT(!ready || &ready->prepare_param == prepare_param); + LL_ASSERT(!p || &p->prepare_param == prepare_param); event.curr.param = prepare_param->param; event.curr.is_abort_cb = is_abort_cb; @@ -750,13 +774,15 @@ int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, */ /* Find next prepare needing preempt timeout to be setup */ - next = prepare_dequeue_iter_ready_get(&idx); - if (!next) { - return err; - } + do { + p = ull_prepare_dequeue_iter(&idx); + if (!p) { + return err; + } + } while (p->is_aborted || p->is_resume); /* Start the preempt timeout */ - ret = preempt_ticker_start(next, NULL, next); + ret = preempt_ticker_start(p, NULL, p); LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || (ret == TICKER_STATUS_BUSY)); #endif /* !CONFIG_BT_CTLR_LOW_LAT */ @@ -764,40 +790,7 @@ int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, return err; } -static int init_reset(void) -{ - return 0; -} - -#if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) -static inline void done_inc(void) -{ - event.done.lll_count++; - LL_ASSERT(event.done.lll_count != event.done.ull_count); -} -#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ - -static inline bool is_done_sync(void) -{ -#if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) - return event.done.lll_count == event.done.ull_count; -#else /* !CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ - return true; -#endif /* !CONFIG_BT_CTLR_LOW_LAT_ULL_DONE */ -} - -static inline struct lll_event *prepare_dequeue_iter_ready_get(uint8_t *idx) -{ - struct lll_event *ready; - - do { - ready = ull_prepare_dequeue_iter(idx); - } while (ready && (ready->is_aborted || ready->is_resume)); - - return ready; -} - -static inline struct lll_event *resume_enqueue(lll_prepare_cb_t resume_cb) +static struct lll_event *resume_enqueue(lll_prepare_cb_t resume_cb) { struct lll_prepare_param prepare_param = {0}; @@ -985,7 +978,7 @@ static void preempt_ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, static void preempt(void *param) { lll_prepare_cb_t resume_cb; - struct lll_event *ready; + struct lll_event *next; uint8_t idx; int err; @@ -996,32 +989,35 @@ static void preempt(void *param) /* Find a prepare that is ready and not a resume */ idx = UINT8_MAX; - ready = prepare_dequeue_iter_ready_get(&idx); - if (!ready) { - /* No ready prepare */ + do { + next = ull_prepare_dequeue_iter(&idx); + } while (next && (next->is_aborted || next->is_resume)); + + /* No ready prepare */ + if (!next) { return; } /* Preemptor not in pipeline */ - if (ready->prepare_param.param != param) { - struct lll_event *ready_next = NULL; - struct lll_event *preemptor; + if (next->prepare_param.param != param) { + struct lll_event *next_next = NULL; + struct lll_event *e; uint32_t ret; /* Find if a short prepare request in the pipeline */ do { - preemptor = ull_prepare_dequeue_iter(&idx); - if (!ready_next && preemptor && !preemptor->is_aborted && - !preemptor->is_resume) { - ready_next = preemptor; + e = ull_prepare_dequeue_iter(&idx); + if (!next_next && e && !e->is_aborted && + !e->is_resume) { + next_next = e; } - } while (preemptor && (preemptor->is_aborted || preemptor->is_resume || - (preemptor->prepare_param.param != param))); + } while (e && (e->is_aborted || e->is_resume || + (e->prepare_param.param != param))); /* No short prepare request in pipeline */ - if (!preemptor) { - /* Start the preempt timeout for ready event */ - ret = preempt_ticker_start(ready, NULL, ready); + if (!e) { + /* Start the preempt timeout for next event */ + ret = preempt_ticker_start(next, NULL, next); LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || (ret == TICKER_STATUS_BUSY)); @@ -1032,29 +1028,34 @@ static void preempt(void *param) * prepare event. For now, lets assert when many * enqueued prepares need aborting. */ - LL_ASSERT(preemptor == ready_next); + LL_ASSERT(next_next == e); /* Abort the prepare that is present before the short prepare */ - ready->is_aborted = 1; - ready->abort_cb(&ready->prepare_param, ready->prepare_param.param); + next->is_aborted = 1; + next->abort_cb(&next->prepare_param, next->prepare_param.param); /* As the prepare queue has been refreshed due to the call of * abort_cb which invokes the lll_done, find the latest prepare */ idx = UINT8_MAX; - ready = prepare_dequeue_iter_ready_get(&idx); - if (!ready) { - /* No ready prepare */ + do { + next = ull_prepare_dequeue_iter(&idx); + } while (next && (next->is_aborted || next->is_resume)); + + /* No ready prepare */ + if (!next) { return; } } /* Check if current event want to continue */ - err = event.curr.is_abort_cb(ready->prepare_param.param, event.curr.param, &resume_cb); + err = event.curr.is_abort_cb(next->prepare_param.param, + event.curr.param, + &resume_cb); if (!err) { /* Let preemptor LLL know about the cancelled prepare */ - ready->is_aborted = 1; - ready->abort_cb(&ready->prepare_param, ready->prepare_param.param); + next->is_aborted = 1; + next->abort_cb(&next->prepare_param, next->prepare_param.param); return; } From e963e7746ede7015ef4348bd0dd9f695d9f13297 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:06 +0000 Subject: [PATCH 0710/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix short prepare when many enqueued in pipeline" This reverts commit 3cefcc0b7485c4bdf5c494b9dda99921d5a36ae7. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/lll/lll.c | 69 +++++++------------ 1 file changed, 23 insertions(+), 46 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index 9ccc36e49e5..b127e60a9f4 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -899,6 +899,15 @@ static uint32_t preempt_ticker_start(struct lll_event *first, LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || (ret == TICKER_STATUS_BUSY)); + /* Set early as we get called again through the call to + * abort_cb(). + */ + ticks_at_preempt = ticks_at_preempt_new; + + /* Abort previous prepare that set the preempt timeout */ + prev->is_aborted = 1U; + prev->abort_cb(&prev->prepare_param, prev->prepare_param.param); + /* Schedule short preempt timeout */ first = next; } else { @@ -987,11 +996,17 @@ static void preempt(void *param) return; } - /* Find a prepare that is ready and not a resume */ + /* Check if any prepare in pipeline */ idx = UINT8_MAX; - do { + next = ull_prepare_dequeue_iter(&idx); + if (!next) { + return; + } + + /* Find a prepare that is ready and not a resume */ + while (next && (next->is_aborted || next->is_resume)) { next = ull_prepare_dequeue_iter(&idx); - } while (next && (next->is_aborted || next->is_resume)); + } /* No ready prepare */ if (!next) { @@ -1000,52 +1015,14 @@ static void preempt(void *param) /* Preemptor not in pipeline */ if (next->prepare_param.param != param) { - struct lll_event *next_next = NULL; - struct lll_event *e; uint32_t ret; - /* Find if a short prepare request in the pipeline */ - do { - e = ull_prepare_dequeue_iter(&idx); - if (!next_next && e && !e->is_aborted && - !e->is_resume) { - next_next = e; - } - } while (e && (e->is_aborted || e->is_resume || - (e->prepare_param.param != param))); - - /* No short prepare request in pipeline */ - if (!e) { - /* Start the preempt timeout for next event */ - ret = preempt_ticker_start(next, NULL, next); - LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || - (ret == TICKER_STATUS_BUSY)); - - return; - } - - /* FIXME: Abort all events in pipeline before the short - * prepare event. For now, lets assert when many - * enqueued prepares need aborting. - */ - LL_ASSERT(next_next == e); - - /* Abort the prepare that is present before the short prepare */ - next->is_aborted = 1; - next->abort_cb(&next->prepare_param, next->prepare_param.param); - - /* As the prepare queue has been refreshed due to the call of - * abort_cb which invokes the lll_done, find the latest prepare - */ - idx = UINT8_MAX; - do { - next = ull_prepare_dequeue_iter(&idx); - } while (next && (next->is_aborted || next->is_resume)); + /* Start the preempt timeout */ + ret = preempt_ticker_start(next, NULL, next); + LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || + (ret == TICKER_STATUS_BUSY)); - /* No ready prepare */ - if (!next) { - return; - } + return; } /* Check if current event want to continue */ From 0cba24aa81f99b18c40a2dcc7e3c3c57c1f545a0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:07 +0000 Subject: [PATCH 0711/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix ticks_slot_window use in Observer" This reverts commit 368963a73f394687b0fd9b648942d7674213d201. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_scan.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan.c b/subsys/bluetooth/controller/ll_sw/ull_scan.c index 21d6cc9c401..1ee99565a13 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_scan.c +++ b/subsys/bluetooth/controller/ll_sw/ull_scan.c @@ -500,10 +500,6 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan) * enabled. */ } - -#if defined(CONFIG_BT_TICKER_EXT) - ll_scan_ticker_ext[handle].ticks_slot_window = 0U; -#endif /* CONFIG_BT_TICKER_EXT */ } /* 1M scan window starts without any offset */ @@ -563,10 +559,6 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan) } else { ticks_offset = 0U; } - -#if defined(CONFIG_BT_TICKER_EXT) - ll_scan_ticker_ext[handle].ticks_slot_window = 0U; -#endif /* CONFIG_BT_TICKER_EXT */ } else { ticks_offset = 0U; } From 41d95b69595211816a1732f3333b2fc665a631e0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:07 +0000 Subject: [PATCH 0712/1623] Revert "[nrf fromtree] Bluetooth: Controller: Use ticker_ticks_diff_get to check short prepare" This reverts commit 146b77c3f11030a321efb7cf7eec51f76a13e0a8. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index b127e60a9f4..fe0a031d402 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -869,13 +869,6 @@ static uint32_t preempt_ticker_start(struct lll_event *first, (preempt_req != preempt_ack)) { uint32_t diff; - /* preempt timeout already started but no role/state in the head - * of prepare pipeline. - */ - if (!prev || prev->is_aborted) { - return TICKER_STATUS_SUCCESS; - } - /* Calc the preempt timeout */ p = &next->prepare_param; ull = HDR_LLL2ULL(p->param); @@ -888,9 +881,9 @@ static uint32_t preempt_ticker_start(struct lll_event *first, ticks_at_preempt_new &= HAL_TICKER_CNTR_MASK; /* Check for short preempt timeouts */ - diff = ticker_ticks_diff_get(ticks_at_preempt_new, - ticks_at_preempt); - if ((diff & BIT(HAL_TICKER_CNTR_MSBIT)) == 0U) { + diff = ticks_at_preempt_new - ticks_at_preempt; + if (!prev || prev->is_aborted || + ((diff & BIT(HAL_TICKER_CNTR_MSBIT)) == 0U)) { return TICKER_STATUS_SUCCESS; } From 484392a0aff818a2ec6b7240ddaefef2444234c0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:07 +0000 Subject: [PATCH 0713/1623] Revert "[nrf fromtree] Bluetooth: Controller: Use the state/role param in prepare pipeline" This reverts commit cb9acc327517604cbdf672db7e60e09623c0b053. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index fe0a031d402..cde3eaaa6ee 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -930,8 +930,8 @@ static uint32_t preempt_ticker_start(struct lll_event *first, TICKER_NULL_REMAINDER, TICKER_NULL_LAZY, TICKER_NULL_SLOT, - preempt_ticker_cb, first->prepare_param.param, - ticker_start_op_cb, NULL); + preempt_ticker_cb, first, + ticker_start_op_cb, first); return ret; } @@ -1007,7 +1007,7 @@ static void preempt(void *param) } /* Preemptor not in pipeline */ - if (next->prepare_param.param != param) { + if (next != param) { uint32_t ret; /* Start the preempt timeout */ From ae72c59f197634013b38e026191205517e36e2bf Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:08 +0000 Subject: [PATCH 0714/1623] Revert "[nrf fromtree] Revert "Bluetooth: Controller: Fix ull_prepare_dequeue for skipped events"" This reverts commit 1d6f3410fd50fe1b4920a95c3928f2e77e77c37d. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/lll/lll.c | 6 +-- subsys/bluetooth/controller/ll_sw/ull.c | 48 ++++++++++++------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index cde3eaaa6ee..fe0a031d402 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -930,8 +930,8 @@ static uint32_t preempt_ticker_start(struct lll_event *first, TICKER_NULL_REMAINDER, TICKER_NULL_LAZY, TICKER_NULL_SLOT, - preempt_ticker_cb, first, - ticker_start_op_cb, first); + preempt_ticker_cb, first->prepare_param.param, + ticker_start_op_cb, NULL); return ret; } @@ -1007,7 +1007,7 @@ static void preempt(void *param) } /* Preemptor not in pipeline */ - if (next != param) { + if (next->prepare_param.param != param) { uint32_t ret; /* Start the preempt timeout */ diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 29cf43cd6d9..6be8bc4759e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -2063,6 +2063,8 @@ void *ull_prepare_dequeue_iter(uint8_t *idx) void ull_prepare_dequeue(uint8_t caller_id) { + void *param_normal_head = NULL; + void *param_normal_next = NULL; void *param_resume_head = NULL; void *param_resume_next = NULL; struct lll_event *next; @@ -2103,31 +2105,41 @@ void ull_prepare_dequeue(uint8_t caller_id) /* The prepare element was not a resume event, it would * use the radio or was enqueued back into prepare * pipeline with a preempt timeout being set. + * + * Remember the first encountered and the next element + * in the prepare pipeline so that we do not infinitely + * loop through the resume events in prepare pipeline. */ if (!is_resume) { - break; - } - - /* Remember the first encountered resume and the next - * resume element in the prepare pipeline so that we do - * not infinitely loop through the resume events in - * prepare pipeline. - */ - if (!param_resume_head) { - param_resume_head = param; - } else if (!param_resume_next) { - param_resume_next = param; + if (!param_normal_head) { + param_normal_head = param; + } else if (!param_normal_next) { + param_normal_next = param; + } + } else { + if (!param_resume_head) { + param_resume_head = param; + } else if (!param_resume_next) { + param_resume_next = param; + } } /* Stop traversing the prepare pipeline when we reach - * back to the first or next resume event where we + * back to the first or next event where we * initially started processing the prepare pipeline. */ - if (next->is_resume && - ((next->prepare_param.param == - param_resume_head) || - (next->prepare_param.param == - param_resume_next))) { + if (!next->is_aborted && + ((!next->is_resume && + ((next->prepare_param.param == + param_normal_head) || + (next->prepare_param.param == + param_normal_next))) || + (next->is_resume && + !param_normal_next && + ((next->prepare_param.param == + param_resume_head) || + (next->prepare_param.param == + param_resume_next))))) { break; } } From 50c87cf5d05e2d80ce6b776e6f6aa120df5c8fb3 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:08 +0000 Subject: [PATCH 0715/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix LE Set Ext Adv Param Cmd invalid status" This reverts commit 4af51708076cf561df2c53eb8154f39426100718. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_adv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index b5595e5e9c2..d7d5b23f63e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -690,7 +690,7 @@ uint8_t ll_adv_params_set(uint16_t interval, uint8_t adv_type, lll_adv_data_reset(&adv->lll.scan_rsp); err = lll_adv_aux_data_init(&adv->lll.scan_rsp); if (err) { - return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; + return err; } pdu = lll_adv_scan_rsp_peek(&adv->lll); @@ -710,7 +710,7 @@ uint8_t ll_adv_params_set(uint16_t interval, uint8_t adv_type, lll_adv_data_reset(&adv->lll.scan_rsp); err = lll_adv_data_init(&adv->lll.scan_rsp); if (err) { - return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; + return err; } pdu = lll_adv_scan_rsp_peek(&adv->lll); @@ -926,7 +926,7 @@ uint8_t ll_adv_enable(uint8_t enable) err = lll_adv_data_init(&adv->lll.scan_rsp); if (err) { - return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; + return err; } pdu_scan = lll_adv_scan_rsp_peek(lll); @@ -1873,7 +1873,7 @@ uint8_t ull_scan_rsp_set(struct ll_adv_set *adv, uint8_t len, err = lll_adv_data_init(&adv->lll.scan_rsp); if (err) { - return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; + return err; } prev = lll_adv_scan_rsp_peek(&adv->lll); From 8ea8caaba3494afbfa68892eda98a55461ce0050 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:08 +0000 Subject: [PATCH 0716/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix order of preempt timeout requested flag" This reverts commit 8246e66a8ecaa438b87a025d7d02312ad239a0ce. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/lll/lll.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index fe0a031d402..1f8031a7c07 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -835,17 +835,11 @@ static void ticker_start_op_cb(uint32_t status, void *param) ARG_UNUSED(param); LL_ASSERT(status == TICKER_STATUS_SUCCESS); - /* Increase preempt requested count before acknowledging that the - * ticker start operation for the preempt timeout has been handled. - */ - LL_ASSERT(preempt_req == preempt_ack); - preempt_req++; - - /* Increase preempt start ack count, to acknowledge that the ticker - * start operation has been handled. - */ LL_ASSERT(preempt_start_req != preempt_start_ack); preempt_start_ack++; + + LL_ASSERT(preempt_req == preempt_ack); + preempt_req++; } static uint32_t preempt_ticker_start(struct lll_event *first, @@ -860,11 +854,7 @@ static uint32_t preempt_ticker_start(struct lll_event *first, uint32_t preempt_to; uint32_t ret; - /* Do not request to start preempt timeout if already requested. - * - * Check if there is pending preempt timeout start requested or if - * preempt timeout ticker has already been scheduled. - */ + /* Do not request to start preempt timeout if already requested */ if ((preempt_start_req != preempt_start_ack) || (preempt_req != preempt_ack)) { uint32_t diff; From 314de51c0c3c79b116400d10f021b7626e120029 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:08 +0000 Subject: [PATCH 0717/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix ticker to prefer ticker node started" This reverts commit 3d9d12428797dd3d53f0d772c611be6e54cb934f. Signed-off-by: Dominik Ermel --- .../bluetooth/controller/Kconfig.ll_sw_split | 17 ----- subsys/bluetooth/controller/ticker/ticker.c | 12 +--- tests/bluetooth/init/prj_ctlr_ticker.conf | 65 ------------------- tests/bluetooth/init/testcase.yaml | 9 --- 4 files changed, 1 insertion(+), 102 deletions(-) delete mode 100644 tests/bluetooth/init/prj_ctlr_ticker.conf diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 5fb2c54d085..910c3819f0c 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -55,8 +55,6 @@ config BT_LLL_VENDOR_NORDIC select BT_TICKER_REMAINDER_GET if BT_BROADCASTER && BT_CTLR_ADV_EXT select BT_TICKER_LAZY_GET if BT_CTLR_ADV_PERIODIC || BT_CTLR_CENTRAL_ISO - select BT_TICKER_PREFER_START_BEFORE_STOP if BT_TICKER_SLOT_AGNOSTIC - default y help Use Nordic Lower Link Layer implementation. @@ -1038,21 +1036,6 @@ config BT_TICKER_SLOT_AGNOSTIC reservations and collision handling, and operates as a simple multi-instance programmable timer. -config BT_TICKER_PREFER_START_BEFORE_STOP - bool "Ticker prefer start before stop request" - help - Under race conditions wherein for a given ticker node if a number of - start and stop operations are enqueued towards ticker_job by a said - user execution context, then start operations is preferred to be - processed before stop operations. - - Without this option, the default behavior is to defer all start - requests after all stop requests enqueued by all user context having - been processed. The rationale for default behavior being that under - race conditions, start followed by stop requests, or start before stop - requests, the said ticker node is always scheduled and at timeout the - execution context can take decision based on its execution state. - config BT_CTLR_JIT_SCHEDULING bool "Just-in-Time Scheduling" select BT_TICKER_SLOT_AGNOSTIC diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index e5c89dca905..ead148e85ba 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -55,11 +55,9 @@ struct ticker_node { uint8_t force:1; /* If non-zero, node timeout should * be forced at next expiration */ -#if defined(CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP) uint8_t start_pending:1; /* If non-zero, start is pending for * bottom half of ticker_job. */ -#endif /* CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP */ uint32_t ticks_periodic; /* If non-zero, interval * between expirations */ @@ -1909,15 +1907,12 @@ static inline uint8_t ticker_job_list_manage(struct ticker_instance *instance, /* if op is start, then skip update and stop ops */ if (user_op->op < TICKER_USER_OP_TYPE_UPDATE) { -#if defined(CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP) if (user_op->op == TICKER_USER_OP_TYPE_START) { /* Set start pending to validate a * successive, inline stop operation. */ ticker->start_pending = 1U; } -#endif /* CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP */ - continue; } @@ -1928,10 +1923,7 @@ static inline uint8_t ticker_job_list_manage(struct ticker_instance *instance, * set status and continue. */ if ((user_op->op > TICKER_USER_OP_TYPE_STOP_ABS) || - ((state == 0U) && -#if defined(CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP) - !ticker->start_pending && -#endif /* CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP */ + (((state == 0U) && !ticker->start_pending) && (user_op->op != TICKER_USER_OP_TYPE_YIELD_ABS)) || ((user_op->op == TICKER_USER_OP_TYPE_UPDATE) && (user_op->params.update.ticks_drift_plus == 0U) && @@ -2739,9 +2731,7 @@ static inline void ticker_job_list_insert(struct ticker_instance *instance, continue; } -#if defined(CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP) ticker->start_pending = 0U; -#endif /* CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP */ if (((ticker->req - ticker->ack) & 0xff) != 0U) { diff --git a/tests/bluetooth/init/prj_ctlr_ticker.conf b/tests/bluetooth/init/prj_ctlr_ticker.conf deleted file mode 100644 index d77f519406b..00000000000 --- a/tests/bluetooth/init/prj_ctlr_ticker.conf +++ /dev/null @@ -1,65 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CTLR=y -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_CTLR_DUP_FILTER_LEN=16 -CONFIG_BT_CTLR_CONN_PARAM_REQ=y -CONFIG_BT_CTLR_LE_PING=y -CONFIG_BT_CTLR_PRIVACY=n -CONFIG_BT_CTLR_EXT_SCAN_FP=n -CONFIG_BT_DATA_LEN_UPDATE=n -CONFIG_BT_PHY_UPDATE=y -CONFIG_BT_CTLR_CHAN_SEL_2=y -CONFIG_BT_CTLR_MIN_USED_CHAN=y -CONFIG_BT_CTLR_ADV_EXT=y -CONFIG_BT_CTLR_DTM_HCI=y -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_PHY_2M=y -CONFIG_BT_CTLR_PHY_2M_NRF=y -CONFIG_BT_CTLR_PHY_CODED=y -CONFIG_BT_CTLR_ADV_AUX_PDU_BACK2BACK=y -CONFIG_BT_CTLR_LLL_PRIO=0 -CONFIG_BT_CTLR_ULL_HIGH_PRIO=1 -CONFIG_BT_CTLR_XTAL_ADVANCED=n -CONFIG_BT_CTLR_SCHED_ADVANCED=n -CONFIG_BT_CTLR_RADIO_ENABLE_FAST=y -CONFIG_BT_CTLR_TIFS_HW=n -CONFIG_BT_CTLR_FAST_ENC=y -CONFIG_BT_CTLR_TX_RETRY_DISABLE=y -CONFIG_BT_CTLR_CONN_RSSI=y -CONFIG_BT_CTLR_ADV_INDICATION=y -CONFIG_BT_CTLR_SCAN_REQ_NOTIFY=y -CONFIG_BT_CTLR_SCAN_REQ_RSSI=y -CONFIG_BT_CTLR_SCAN_INDICATION=y -CONFIG_BT_CTLR_PROFILE_ISR=y -CONFIG_BT_CTLR_DEBUG_PINS=y -CONFIG_BT_CTLR_TEST=y -CONFIG_BT_TICKER_EXT=n -CONFIG_BT_TICKER_SLOT_AGNOSTIC=y -CONFIG_BT_TICKER_PREFER_START_BEFORE_STOP=y -CONFIG_BT_HCI_VS_EXT=y -CONFIG_BT_HCI_MESH_EXT=n -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_SMP=y -CONFIG_BT_SIGNING=y -CONFIG_BT_SMP_SC_ONLY=y -CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_USE_DEBUG_KEYS=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_GATT_CLIENT=y -CONFIG_BT_DEBUG_MONITOR_UART=y -CONFIG_BT_HCI_CORE_LOG_LEVEL_DBG=y -CONFIG_BT_CONN_LOG_LEVEL_DBG=y -CONFIG_BT_KEYS_LOG_LEVEL_DBG=y -CONFIG_BT_L2CAP_LOG_LEVEL_DBG=y -CONFIG_BT_SMP_LOG_LEVEL_DBG=y -CONFIG_BT_HCI_DRIVER_LOG_LEVEL_DBG=y -CONFIG_BT_SMP_SELFTEST=y -CONFIG_BT_ATT_LOG_LEVEL_DBG=y -CONFIG_BT_GATT_LOG_LEVEL_DBG=y -CONFIG_BT_BREDR=n -CONFIG_DEBUG=y -CONFIG_FLASH=y -CONFIG_SOC_FLASH_NRF_RADIO_SYNC_TICKER=n -CONFIG_ZTEST=y -CONFIG_ZTEST_NEW_API=y diff --git a/tests/bluetooth/init/testcase.yaml b/tests/bluetooth/init/testcase.yaml index fa30920dc1e..4c252115178 100644 --- a/tests/bluetooth/init/testcase.yaml +++ b/tests/bluetooth/init/testcase.yaml @@ -122,15 +122,6 @@ tests: integration_platforms: - nrf52840dk_nrf52840 - nrf52dk_nrf52832 - bluetooth.init.test_ctlr_ticker: - extra_args: - - CONF_FILE=prj_ctlr_ticker.conf - platform_allow: - - nrf52840dk_nrf52840 - - nrf52dk_nrf52832 - integration_platforms: - - nrf52840dk_nrf52840 - - nrf52dk_nrf52832 bluetooth.init.test_ctlr_broadcaster: extra_args: CONF_FILE=prj_ctlr_broadcaster.conf platform_allow: From 06798bf8b64e00b548b77c4839260910ba537b55 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:08 +0000 Subject: [PATCH 0718/1623] Revert "[nrf fromtree] Bluetooth: controller: Included kconfigs for ISO-AL logging" This reverts commit c88e67bb9ad3655d3a5bab013518bf11950eda92. Signed-off-by: Dominik Ermel --- subsys/bluetooth/Kconfig.logging | 17 ----------------- subsys/bluetooth/controller/Kconfig | 7 ------- subsys/bluetooth/controller/ll_sw/isoal.c | 6 +++--- 3 files changed, 3 insertions(+), 27 deletions(-) diff --git a/subsys/bluetooth/Kconfig.logging b/subsys/bluetooth/Kconfig.logging index addf8eb65fe..67a18afa919 100644 --- a/subsys/bluetooth/Kconfig.logging +++ b/subsys/bluetooth/Kconfig.logging @@ -398,16 +398,6 @@ config BT_DEBUG_SERVICE This option enables debug support for the Bluetooth Services. -# CONTROLLER (subsys/bluetooth/controller/Kconfig) - -config BT_CTLR_DEBUG_ISOAL - bool "[DEPRECATED] Bluetooth ISO-AL debug" - select DEPRECATED - depends on BT_CTLR_ISO - help - This option enables debug support for the Bluetooth ISO-AL. - - endmenu # [DEPRECATED] Others menu "[DEPRECATED] BR/EDR" @@ -910,13 +900,6 @@ legacy-debug-sym = BT_DEBUG_SERVICE module-str = "Bluetooth Services" source "subsys/bluetooth/common/Kconfig.template.log_config_bt" -# CONTROLLER (subsys/bluetooth/controller/Kconfig) - -module = BT_CTLR_ISOAL -legacy-debug-sym = BT_CTLR_DEBUG_ISOAL -module-str = "Bluetooth Controller ISO-AL" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endmenu # Others menu "BR/EDR" diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 9ba67a05768..599a241b84b 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -210,13 +210,6 @@ config BT_CTLR_ISO_TX_BUFFER_SIZE Size of the Isochronous Tx buffers and the value returned in HCI LE Read Buffer Size V2 command response. -config BT_CTLR_ISOAL_LOG_DBG_VERBOSE - bool "ISO-AL verbose debug logging" - depends on BT_CTLR_ISOAL_LOG_LEVEL = 4 - default n - help - Use this option to enable ISO-AL verbose debug logging. - config BT_CTLR_ISOAL_SOURCES int "Number of Isochronous Adaptation Layer sources" depends on BT_CTLR_ADV_ISO || BT_CTLR_CONN_ISO diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index d43233f0289..6c1dedd7b9d 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -36,15 +36,15 @@ #include -LOG_MODULE_REGISTER(bt_ctlr_isoal, CONFIG_BT_CTLR_ISOAL_LOG_LEVEL); +LOG_MODULE_REGISTER(bt_ctlr_isoal, LOG_LEVEL_INF); #define ISOAL_LOG_DBG(...) LOG_DBG(__VA_ARGS__) -#if defined(CONFIG_BT_CTLR_ISOAL_LOG_DBG_VERBOSE) +#if defined(ISOAL_DEBUG_VERBOSE) #define ISOAL_LOG_DBGV(...) LOG_DBG(__VA_ARGS__) #else #define ISOAL_LOG_DBGV(...) (void) 0 -#endif /* CONFIG_BT_CTLR_ISOAL_LOG_DBG_VERBOSE */ +#endif /* ISOAL_DEBUG_VERBOSE */ #include "hal/debug.h" From ee49660ceea128610c37503b88c7494091d48c05 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:09 +0000 Subject: [PATCH 0719/1623] Revert "[nrf fromtree] Bluetooth: controller: disregard length field on pdu error" This reverts commit 85f3925dbeea3ffb867ae802773eca323c096322. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/isoal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index 6c1dedd7b9d..d4cc61cea6c 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -738,7 +738,7 @@ static isoal_status_t isoal_rx_unframed_consume(struct isoal_sink *sink, /* If status is not ISOAL_PDU_STATUS_VALID, length and LLID cannot be trusted */ llid = pdu->ll_id; pdu_err = (pdu_meta->meta->status != ISOAL_PDU_STATUS_VALID); - length = pdu_err ? 0U : pdu->len; + length = pdu->len; /* A zero length PDU with LLID 0b01 (PDU_BIS_LLID_START_CONTINUE) would be a padding PDU. * However if there are errors in the PDU, it could be an incorrectly receive non-padding * PDU. Therefore only consider a PDU with errors as padding if received after the end From 46295496a0464a673950d2e3df5c7d3c82010d67 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:09 +0000 Subject: [PATCH 0720/1623] Revert "[nrf fromtree] Bluetooth: Controller: ISO-AL validation and selection of TX time stamps" This reverts commit 4ef38a538433f2ca8df60c605d4047f43f1a529b. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/hci/hci.c | 14 +- subsys/bluetooth/controller/ll_sw/isoal.c | 212 +++++--------------- subsys/bluetooth/controller/ll_sw/isoal.h | 2 - subsys/bluetooth/controller/ll_sw/ull_iso.c | 3 +- 4 files changed, 55 insertions(+), 176 deletions(-) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 30fb363fc9c..9ca905c44e0 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -5700,21 +5700,17 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt) * -- A captured time stamp of the SDU * -- A time stamp provided by the higher layer * -- A computed time stamp based on a sequence counter provided by the - * higher layer - * -- Any other method of determining Time_Offset - * (Uses a timestamp computed from the difference in provided - * timestamps, if the timestamp is deemed not based on the - * controller's clock) + * higher layer (Not implemented) + * -- Any other method of determining Time_Offset (Not implemented) */ - sdu_frag_tx.cntr_time_stamp = HAL_TICKER_TICKS_TO_US(ticker_ticks_now_get()); if (ts_flag) { - /* Use HCI provided time stamp */ + /* Overwrite time stamp with HCI provided time stamp */ time_stamp = net_buf_pull_mem(buf, sizeof(*time_stamp)); len -= sizeof(*time_stamp); sdu_frag_tx.time_stamp = sys_le32_to_cpu(*time_stamp); } else { - /* Use controller's capture time */ - sdu_frag_tx.time_stamp = sdu_frag_tx.cntr_time_stamp; + sdu_frag_tx.time_stamp = + HAL_TICKER_TICKS_TO_US(ticker_ticks_now_get()); } /* Extract ISO data header if included (PB_Flag 0b00 or 0b10) */ diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index d4cc61cea6c..00bc40504f7 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -1282,7 +1282,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, } /* Update next state */ - ISOAL_LOG_DBGV("[%p] FSM Next State %s", sink, FSM_TO_STR(next_state)); + ISOAL_LOG_DBGV("[%p] Decoding: Next State %s", sink, FSM_TO_STR(next_state)); sp->fsm = next_state; /* Find next segment header, set to null if past end of PDU */ @@ -1350,7 +1350,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, if (error_sdu_pending) { sp->sdu_status = next_sdu_status; - err |= isoal_rx_append_to_sdu(sink, pdu_meta, 0U, 0U, true, false); + err |= isoal_rx_append_to_sdu(sink, pdu_meta, 0, 0, true, false); } break; @@ -1373,8 +1373,8 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, } /* Update next state */ - ISOAL_LOG_DBGV("[%p] FSM Error Next State %s", sink, FSM_TO_STR(next_state)); - sp->fsm = next_state; + ISOAL_LOG_DBGV("[%p] Error: Next State %s", sink, FSM_TO_STR(next_state)); + sink->sdu_production.fsm = next_state; } sp->prev_pdu_id = meta->payload_number; @@ -1591,46 +1591,6 @@ void isoal_source_destroy(isoal_source_handle_t hdl) isoal_source_deallocate(hdl); } -static bool isoal_is_time_stamp_valid(const struct isoal_source *source_ctx, - const uint32_t cntr_time, - const uint32_t time_stamp) -{ - const struct isoal_source_session *session; - uint32_t time_diff; - - session = &source_ctx->session; - - /* This is an arbitrarily defined range. The purpose is to - * decide if the time stamp provided by the host is sensible - * within the controller's clock domain. An SDU interval plus ISO - * interval is expected to provide a good balance between situations - * where either could be significantly larger than the other. - * - * BT Core V5.4 : Vol 6 Low Energy Controller : Part G IS0-AL: - * 3.3 Time Stamp for SDU : - * When an HCI ISO Data packet sent by the Host does not contain - * a Time Stamp or the Time_Stamp value is not based on the - * Controller's clock, the Controller should determine the CIS - * or BIS event to be used to transmit the SDU contained in that - * packet based on the time of arrival of that packet. - */ - const uint32_t sdu_interval_us = session->sdu_interval; - const uint32_t iso_interval_us = session->iso_interval * ISO_INT_UNIT_US; - /* ISO Interval 0x0000_0004 ~ 0x0000_0C80 x 1250 + - * SDU Interval 0x0000_00FF ~ 0x000F_FFFF <= 004D_08FF - */ - const int32_t time_stamp_valid_half_range = sdu_interval_us + iso_interval_us; - const uint32_t time_stamp_valid_min = isoal_get_wrapped_time_us(cntr_time, - (-time_stamp_valid_half_range)); - const uint32_t time_stamp_valid_range = 2 * time_stamp_valid_half_range; - const bool time_stamp_is_valid = isoal_get_time_diff(time_stamp_valid_min, - time_stamp, - &time_diff) && - time_diff <= time_stamp_valid_range; - - return time_stamp_is_valid; -} - /** * Queue the PDU in production in the relevant LL transmit queue. If the * attmept to release the PDU fails, the buffer linked to the PDU will be released @@ -1676,8 +1636,8 @@ static isoal_status_t isoal_tx_pdu_emit(const struct isoal_source *source_ctx, status = source_ctx->session.pdu_emit(node_tx, handle); ISOAL_LOG_DBG("[%p] PDU %llu err=%X len=%u frags=%u released", - source_ctx, payload_number, status, - produced_pdu->contents.pdu->len, sdu_fragments); + source_ctx, payload_number, status, + produced_pdu->contents.pdu->len, sdu_fragments); if (status != ISOAL_STATUS_OK) { /* If it fails, the node will be released and no further attempt @@ -1881,8 +1841,8 @@ uint16_t isoal_tx_unframed_get_next_payload_number(isoal_source_handle_t source_ * @brief Fragment received SDU and produce unframed PDUs * @details Destination source may have an already partially built PDU * - * @param[in] source_hdl Destination source handle - * @param[in] tx_sdu SDU with packet boundary information + * @param source_hdl[in] Destination source handle + * @param tx_sdu[in] SDU with packet boundary information * * @return Status * @@ -2202,7 +2162,7 @@ static isoal_status_t isoal_insert_seg_header_timeoffset(struct isoal_source *so pp->pdu_available -= write_size; ISOAL_LOG_DBGV("[%p] Seg header write size=%u sc=%u cmplt=%u TO=%u len=%u", - source, write_size, sc, cmplt, time_offset, seg_hdr.len); + source, write_size, sc, cmplt, time_offset, seg_hdr.len); return err; } @@ -2243,48 +2203,46 @@ static isoal_status_t isoal_update_seg_header_cmplt_length(struct isoal_source * PDU_ISO_SEG_HDR_SIZE); ISOAL_LOG_DBGV("[%p] Seg header write size=%u sc=%u cmplt=%u len=%u", - source, PDU_ISO_SEG_HDR_SIZE, seg_hdr.sc, cmplt, seg_hdr.len); + source, PDU_ISO_SEG_HDR_SIZE, seg_hdr.sc, cmplt, seg_hdr.len); } /** * Find the earliest feasible event for transmission capacity is not wasted and * return information based on that event. - * - * @param[in] *source_ctx Destination source context + * @param[in] source_hdl Destination source handle * @param[in] tx_sdu SDU with meta data information * @param[out] payload_number Updated payload number for the selected event * @param[out] grp_ref_point Group reference point for the selected event * @param[out] time_offset Segmentation Time offset to selected event * @return The number SDUs skipped from the last */ -static uint16_t isoal_tx_framed_find_correct_tx_event(const struct isoal_source *source_ctx, +static uint16_t isoal_tx_framed_find_correct_tx_event(isoal_source_handle_t source_hdl, const struct isoal_sdu_tx *tx_sdu, uint64_t *payload_number, uint32_t *grp_ref_point, uint32_t *time_offset) { - const struct isoal_source_session *session; - const struct isoal_pdu_production *pp; + struct isoal_source_session *session; + struct isoal_pdu_production *pp; uint32_t actual_grp_ref_point; uint64_t next_payload_number; + struct isoal_source *source; uint16_t sdus_skipped; uint64_t actual_event; bool time_diff_valid; uint32_t time_diff; - uint32_t time_stamp_selected; - session = &source_ctx->session; - pp = &source_ctx->pdu_production; + source = &isoal_global.source_state[source_hdl]; + session = &source->session; + pp = &source->pdu_production; - sdus_skipped = 0U; - time_diff = 0U; + sdus_skipped = 0; /* Continue with the current payload unless there is need to change */ next_payload_number = pp->payload_number; actual_event = pp->payload_number / session->burst_number; - ISOAL_LOG_DBGV("[%p] Start PL=%llu Evt=%lu.", source_ctx, next_payload_number, - actual_event); + ISOAL_LOG_DBGV("[%p] Start PL=%llu Evt=%lu.", source, next_payload_number, actual_event); /* Get the drift updated group reference point for this event based on * the actual event being set. This might introduce some errors as the @@ -2301,35 +2259,29 @@ static uint16_t isoal_tx_framed_find_correct_tx_event(const struct isoal_source } ISOAL_LOG_DBGV("[%p] Current PL=%llu Evt=%llu Ref=%lu", - source_ctx, next_payload_number, actual_event, actual_grp_ref_point); + source, next_payload_number, actual_event, actual_grp_ref_point); if (tx_sdu->sdu_state == BT_ISO_START || tx_sdu->sdu_state == BT_ISO_SINGLE) { /* Start of a new SDU */ - const bool time_stamp_is_valid = isoal_is_time_stamp_valid(source_ctx, - tx_sdu->cntr_time_stamp, - tx_sdu->time_stamp); - /* Adjust payload number */ if (pp->initialized) { /* Not the first SDU in this session, so reference * information should be valid. . */ - time_diff_valid = isoal_get_time_diff(session->last_input_time_stamp, tx_sdu->time_stamp, &time_diff); /* Priority is given to the sequence number */ if (tx_sdu->packet_sn > session->last_input_sn + 1) { - ISOAL_LOG_DBGV("[%p] Using packet_sn for skipped SDUs", source_ctx); + ISOAL_LOG_DBGV("[%p] Using packet_sn for skipped SDUs", source); sdus_skipped = (tx_sdu->packet_sn - session->last_input_sn) - 1; } else if (tx_sdu->packet_sn == session->last_input_sn && - time_diff_valid && time_diff > session->sdu_interval) { - ISOAL_LOG_DBGV("[%p] Using time_stamp for skipped SDUs", - source_ctx); + time_diff_valid && time_diff > session->sdu_interval) { + ISOAL_LOG_DBGV("[%p] Using time_stamp for skipped SDUs", source); /* Round at mid-point */ sdus_skipped = ((time_diff + (session->sdu_interval / 2)) / session->sdu_interval) - 1; @@ -2337,58 +2289,12 @@ static uint16_t isoal_tx_framed_find_correct_tx_event(const struct isoal_source /* SDU is next in sequence */ } - if (time_stamp_is_valid) { - /* Use provided time stamp for time offset - * calcutation - */ - time_stamp_selected = tx_sdu->time_stamp; - ISOAL_LOG_DBGV("[%p] Selecting Time Stamp (%lu) from SDU", - source_ctx, time_stamp_selected); - } else if (time_diff_valid) { - /* Project a time stamp based on the last time - * stamp and the difference in input time stamps - */ - time_stamp_selected = isoal_get_wrapped_time_us( - session->tx_time_stamp, - time_diff - session->tx_time_offset); - ISOAL_LOG_DBGV("[%p] Projecting Time Stamp (%lu) from SDU delta", - source_ctx, time_stamp_selected); - } else { - /* Project a time stamp based on the last time - * stamp and the number of skipped SDUs - */ - time_stamp_selected = isoal_get_wrapped_time_us( - session->tx_time_stamp, - ((sdus_skipped + 1) * session->sdu_interval) - - session->tx_time_offset); - ISOAL_LOG_DBGV("[%p] Projecting Time Stamp (%lu) from skipped SDUs", - source_ctx, time_stamp_selected); - } - } else { /* First SDU, align with target event */ - if (actual_event < tx_sdu->target_event) { - actual_event = tx_sdu->target_event; - actual_grp_ref_point = tx_sdu->grp_ref_point; - } + actual_event = tx_sdu->target_event; + actual_grp_ref_point = tx_sdu->grp_ref_point; - ISOAL_LOG_DBGV("[%p] Use target_event", source_ctx); - - if (time_stamp_is_valid) { - /* Time stamp is within valid range - - * use provided time stamp - */ - time_stamp_selected = tx_sdu->time_stamp; - ISOAL_LOG_DBGV("[%p] Selecting Time Stamp (%lu) from SDU", - source_ctx, time_stamp_selected); - } else { - /* Time stamp is out of range - - * use controller's capture time - */ - time_stamp_selected = tx_sdu->cntr_time_stamp; - ISOAL_LOG_DBGV("[%p] Selecting Time Stamp (%lu) from controller", - source_ctx, time_stamp_selected); - } + ISOAL_LOG_DBGV("[%p] Use target_event", source); } /* Selecting the event for transmission is done solely based on @@ -2403,8 +2309,8 @@ static uint16_t isoal_tx_framed_find_correct_tx_event(const struct isoal_source * 3.1 Time_Offset in framed PDUs : * The Time_Offset shall be a positive value. */ - while (!isoal_get_time_diff(time_stamp_selected, actual_grp_ref_point, &time_diff) - || time_diff == 0) { + while (!isoal_get_time_diff(tx_sdu->time_stamp, actual_grp_ref_point, &time_diff) || + time_diff == 0) { /* Advance target to next event */ actual_event++; actual_grp_ref_point = isoal_get_wrapped_time_us(actual_grp_ref_point, @@ -2412,8 +2318,8 @@ static uint16_t isoal_tx_framed_find_correct_tx_event(const struct isoal_source } ISOAL_LOG_DBGV("[%p] Chosen PL=%llu Evt=%llu Ref=%lu", - source_ctx, (actual_event * session->burst_number), actual_event, - actual_grp_ref_point); + source, (actual_event * session->burst_number), actual_event, + actual_grp_ref_point); /* If the event selected is the last event segmented for, then * it is possible that that some payloads have already been @@ -2421,23 +2327,23 @@ static uint16_t isoal_tx_framed_find_correct_tx_event(const struct isoal_source * that payload. */ next_payload_number = MAX(pp->payload_number, - (actual_event * session->burst_number)); + (actual_event * session->burst_number)); + } - ISOAL_LOG_DBGV("[%p] Final Evt=%llu (PL=%llu) Ref.=%lu Next PL=%llu", - source, actual_event, (actual_event * session->burst_number), - actual_grp_ref_point, next_payload_number); + ISOAL_LOG_DBGV("[%p] Final Evt=%llu (PL=%llu) Ref.=%lu Next PL=%llu", + source, actual_event, (actual_event * session->burst_number), + actual_grp_ref_point, next_payload_number); - /* Calculate the time offset */ - time_diff_valid = isoal_get_time_diff(time_stamp_selected, - actual_grp_ref_point, &time_diff); + /* Calculate the time offset */ + time_diff_valid = isoal_get_time_diff(tx_sdu->time_stamp, + actual_grp_ref_point, &time_diff); - LL_ASSERT(time_diff_valid); - LL_ASSERT(time_diff > 0); - /* Time difference must be less than the maximum possible - * time-offset of 24-bits. - */ - LL_ASSERT(time_diff <= 0x00FFFFFF); - } + LL_ASSERT(time_diff_valid); + LL_ASSERT(time_diff > 0); + /* Time difference must be less than the maximum possible + * time-offset of 24-bits. + */ + LL_ASSERT(time_diff <= 0x00FFFFFF); *payload_number = next_payload_number; *grp_ref_point = actual_grp_ref_point; @@ -2483,24 +2389,19 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, tx_sdu->sdu_state == BT_ISO_SINGLE); ISOAL_LOG_DBGV("[%p] SDU %u len=%u TS=%lu Ref=%lu Evt=%llu Frag=%u", - source, tx_sdu->packet_sn, tx_sdu->iso_sdu_length, tx_sdu->time_stamp, - tx_sdu->grp_ref_point, tx_sdu->target_event, tx_sdu->sdu_state); + source, tx_sdu->packet_sn, tx_sdu->iso_sdu_length, tx_sdu->time_stamp, + tx_sdu->grp_ref_point, tx_sdu->target_event, tx_sdu->sdu_state); if (tx_sdu->sdu_state == BT_ISO_START || tx_sdu->sdu_state == BT_ISO_SINGLE) { uint32_t actual_grp_ref_point; uint64_t next_payload_number; uint16_t sdus_skipped; - bool time_diff_valid; - uint32_t time_diff; /* Start of a new SDU */ - time_diff_valid = isoal_get_time_diff(session->last_input_time_stamp, - tx_sdu->time_stamp, - &time_diff); /* Find the best transmission event */ - sdus_skipped = isoal_tx_framed_find_correct_tx_event(source, tx_sdu, + sdus_skipped = isoal_tx_framed_find_correct_tx_event(source_hdl, tx_sdu, &next_payload_number, &actual_grp_ref_point, &time_offset); @@ -2559,22 +2460,7 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, /* Update input packet number and time stamp */ session->last_input_sn = tx_sdu->packet_sn; - - if (pp->initialized && tx_sdu->time_stamp == tx_sdu->cntr_time_stamp && - (!time_diff_valid || time_diff < session->sdu_interval)) { - /* If the time-stamp is invalid or the difference is - * less than an SDU interval, then set the reference - * time stamp to what should have been received. This is - * done to avoid incorrectly detecting a gap in time - * stamp inputs should there be a burst of SDUs - * clustered together. - */ - session->last_input_time_stamp = isoal_get_wrapped_time_us( - session->last_input_time_stamp, - session->sdu_interval); - } else { - session->last_input_time_stamp = tx_sdu->time_stamp; - } + session->last_input_time_stamp = tx_sdu->time_stamp; } /* PDUs should be created until the SDU fragment has been fragmented or if diff --git a/subsys/bluetooth/controller/ll_sw/isoal.h b/subsys/bluetooth/controller/ll_sw/isoal.h index 61d3773c43d..cc69e4a5d53 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.h +++ b/subsys/bluetooth/controller/ll_sw/isoal.h @@ -189,8 +189,6 @@ struct isoal_sdu_tx { uint16_t iso_sdu_length; /** Time stamp from HCI or vendor specific path (us) */ uint32_t time_stamp; - /** Capture time stamp from controller (us) */ - uint32_t cntr_time_stamp; /** CIG Reference of target event (us, compensated for drift) */ uint32_t grp_ref_point; /** Target Event of SDU */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_iso.c b/subsys/bluetooth/controller/ll_sw/ull_iso.c index 70d018e7e0c..1520bd76963 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_iso.c @@ -1058,8 +1058,7 @@ void ll_iso_transmit_test_send_sdu(uint16_t handle, uint32_t ticks_at_expire) /* Send all SDU fragments */ do { - sdu.cntr_time_stamp = HAL_TICKER_TICKS_TO_US(ticks_at_expire); - sdu.time_stamp = sdu.cntr_time_stamp; + sdu.time_stamp = HAL_TICKER_TICKS_TO_US(ticks_at_expire); sdu.size = MIN(remaining_tx, ISO_TEST_TX_BUFFER_SIZE); memset(tx_buffer, 0, sdu.size); From 9cada2eaff87d36b99722956875be07bd1d9c455 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:09 +0000 Subject: [PATCH 0721/1623] Revert "[nrf fromtree] Bluetooth: controller: corrected time-offset for endianness" This reverts commit 1fd74b1654859ac2f7c936a6b855667ef34184b2. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/isoal.c | 12 +++++------- subsys/bluetooth/controller/ll_sw/pdu.h | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index 00bc40504f7..110a7aa901e 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -16,8 +16,6 @@ #include #include -#include - #include "util/memq.h" #include "hal/ccm.h" @@ -1160,7 +1158,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, case ISOAL_START: if (!sc) { /* Start segment, included time-offset */ - timeoffset = sys_le24_to_cpu(seg_hdr->timeoffset); + timeoffset = seg_hdr->timeoffset; anchorpoint = meta->timestamp; latency = session->sdu_sync_const; timestamp = isoal_get_wrapped_time_us(anchorpoint, @@ -1217,7 +1215,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, if (!sc) { /* Start segment, included time-offset */ - timeoffset = sys_le24_to_cpu(seg_hdr->timeoffset); + timeoffset = seg_hdr->timeoffset; anchorpoint = meta->timestamp; latency = session->sdu_sync_const; timestamp = isoal_get_wrapped_time_us(anchorpoint, @@ -1636,7 +1634,7 @@ static isoal_status_t isoal_tx_pdu_emit(const struct isoal_source *source_ctx, status = source_ctx->session.pdu_emit(node_tx, handle); ISOAL_LOG_DBG("[%p] PDU %llu err=%X len=%u frags=%u released", - source_ctx, payload_number, status, + source_ctx, node_tx->payload_count, status, produced_pdu->contents.pdu->len, sdu_fragments); if (status != ISOAL_STATUS_OK) { @@ -2481,7 +2479,7 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, */ err |= isoal_insert_seg_header_timeoffset(source, false, false, - sys_cpu_to_le24(time_offset)); + time_offset); pp->pdu_state = BT_ISO_CONT; } else if (!padding_pdu && pp->pdu_state == BT_ISO_CONT && pp->pdu_written == 0) { /* Continuing an SDU in a new PDU. Segmentation header @@ -2489,7 +2487,7 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, */ err |= isoal_insert_seg_header_timeoffset(source, true, false, - sys_cpu_to_le24(0)); + 0); } /* diff --git a/subsys/bluetooth/controller/ll_sw/pdu.h b/subsys/bluetooth/controller/ll_sw/pdu.h index 93e50e1ebcc..ceeb9ca12e7 100644 --- a/subsys/bluetooth/controller/ll_sw/pdu.h +++ b/subsys/bluetooth/controller/ll_sw/pdu.h @@ -1018,8 +1018,8 @@ struct pdu_iso_sdu_sh { uint8_t len; /* Note, timeoffset only available in first segment of sdu */ - uint32_t timeoffset:24; uint32_t payload:8; + uint32_t timeoffset:24; #endif /* CONFIG_LITTLE_ENDIAN */ } __packed; From af5da850bd2bfe5701cc7405a912361fbf977454 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:09 +0000 Subject: [PATCH 0722/1623] Revert "[nrf fromtree] Bluetooth: controller: Use consecutive event for framed TX and RX bugfix" This reverts commit 788c7ff8e63a7ddcd0e7c8850628c29f208e8937. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/isoal.c | 408 +++++++--------------- subsys/bluetooth/controller/ll_sw/isoal.h | 4 +- 2 files changed, 120 insertions(+), 292 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index 110a7aa901e..0a500cfd05e 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -50,11 +50,6 @@ LOG_MODULE_REGISTER(bt_ctlr_isoal, LOG_LEVEL_INF); (s == ISOAL_CONTINUE ? "CONTINUE" : \ (s == ISOAL_ERR_SPOOL ? "ERR SPOOL" : "???"))) -#define STATE_TO_STR(s) (s == BT_ISO_SINGLE ? "SINGLE" : \ - (s == BT_ISO_START ? "START" : \ - (s == BT_ISO_CONT ? "CONT" : \ - (s == BT_ISO_END ? "END" : "???")))) - #if defined(CONFIG_BT_CTLR_ADV_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO) /* Given the minimum payload, this defines the minimum number of bytes that * should be remaining in a TX PDU such that it would make inserting a new @@ -191,7 +186,7 @@ static bool isoal_get_time_diff(uint32_t time_before, uint32_t time_after, uint3 #define SET_RX_SDU_TIMESTAMP(_sink, _timestamp, _value) \ _timestamp = _value; \ - ISOAL_LOG_DBGV("[%p] %s updated (%lu)", _sink, #_timestamp, _value); + ISOAL_LOG_DBGV("[%p] %s updated (%ld)", _sink, #_timestamp, _value); static void isoal_rx_framed_update_sdu_release(struct isoal_sink *sink); @@ -420,7 +415,7 @@ static isoal_status_t isoal_rx_allocate_sdu(struct isoal_sink *sink, ); if (err == ISOAL_STATUS_OK) { - sp->sdu_allocated = 1U; + sp->sdu_allocated = true; } /* Nothing has been written into buffer yet */ @@ -604,7 +599,7 @@ static isoal_status_t isoal_rx_try_emit_sdu(struct isoal_sink *sink, bool end_of sdu->status = sp->sdu_status; err = isoal_rx_buffered_emit_sdu(sink, end_of_sdu); - sp->sdu_allocated = 0U; + sp->sdu_allocated = false; if (end_of_sdu) { isoal_rx_framed_update_sdu_release(sink); @@ -734,9 +729,9 @@ static isoal_status_t isoal_rx_unframed_consume(struct isoal_sink *sink, next_state = ISOAL_START; /* If status is not ISOAL_PDU_STATUS_VALID, length and LLID cannot be trusted */ - llid = pdu->ll_id; + llid = pdu_meta->pdu->ll_id; pdu_err = (pdu_meta->meta->status != ISOAL_PDU_STATUS_VALID); - length = pdu->len; + length = pdu_meta->pdu->len; /* A zero length PDU with LLID 0b01 (PDU_BIS_LLID_START_CONTINUE) would be a padding PDU. * However if there are errors in the PDU, it could be an incorrectly receive non-padding * PDU. Therefore only consider a PDU with errors as padding if received after the end @@ -942,7 +937,7 @@ static isoal_status_t isoal_rx_unframed_consume(struct isoal_sink *sink, sp->prev_pdu_is_end = !pdu_err && llid == PDU_BIS_LLID_COMPLETE_END; sp->prev_pdu_is_padding = !pdu_err && pdu_padding; - sp->initialized = 1U; + sp->initialized = true; return err; } @@ -1298,8 +1293,6 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, } if (pdu_err || seq_err || seg_err) { - bool error_sdu_pending = false; - /* When one or more ISO Data PDUs are not received, the receiving device may * discard all SDUs affected by the missing PDUs. Any partially received SDU * may also be discarded. @@ -1328,28 +1321,14 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, switch (sp->fsm) { case ISOAL_START: - /* If errors occur while waiting for the start of an SDU - * then an SDU should should only be released if there - * is confirmation that a reception occurred - * unsuccessfully. In the case of STATUS_LOST_DATA which - * could result from a flush, an SDU should not be - * released as the flush does not necessarily mean that - * part of an SDU has been lost. In this case Lost SDU - * release defaults to the lost SDU detection based on - * the SDU interval. If we have a SDU to release - * following any lost SDUs, lost SDU handling should be - * similar to when a valid timestamp for the next SDU - * exists. + /* First release lost SDUs and then release a new SDU + * with errors. Since we have an SDU to release + * following any lost SDUs, lost SDUs handling should be + * similar to when a valid timestamp exists. */ - error_sdu_pending = seg_err || - (pdu_err && meta->status == ISOAL_SDU_STATUS_ERRORS); - err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, - error_sdu_pending, timestamp); - - if (error_sdu_pending) { - sp->sdu_status = next_sdu_status; - err |= isoal_rx_append_to_sdu(sink, pdu_meta, 0, 0, true, false); - } + err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, true, timestamp); + sp->sdu_status = next_sdu_status; + err |= isoal_rx_append_to_sdu(sink, pdu_meta, 0, 0, true, false); break; case ISOAL_CONTINUE: @@ -1360,13 +1339,11 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, */ sp->sdu_status = next_sdu_status; err |= isoal_rx_append_to_sdu(sink, pdu_meta, 0, 0, true, false); - err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, - error_sdu_pending, timestamp); + err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, false, timestamp); break; case ISOAL_ERR_SPOOL: - err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, - error_sdu_pending, timestamp); + err |= isoal_rx_framed_release_lost_sdus(sink, pdu_meta, false, timestamp); break; } @@ -1376,7 +1353,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, } sp->prev_pdu_id = meta->payload_number; - sp->initialized = 1U; + sp->initialized = true; return err; } @@ -1633,10 +1610,6 @@ static isoal_status_t isoal_tx_pdu_emit(const struct isoal_source *source_ctx, /* Attempt to enqueue the node towards the LL */ status = source_ctx->session.pdu_emit(node_tx, handle); - ISOAL_LOG_DBG("[%p] PDU %llu err=%X len=%u frags=%u released", - source_ctx, node_tx->payload_count, status, - produced_pdu->contents.pdu->len, sdu_fragments); - if (status != ISOAL_STATUS_OK) { /* If it fails, the node will be released and no further attempt * will be possible @@ -1693,7 +1666,6 @@ static isoal_status_t isoal_tx_allocate_pdu(struct isoal_source *source, /* Nothing has been written into buffer yet */ pp->pdu_written = 0; pp->pdu_available = available_len; - pp->pdu_allocated = 1U; LL_ASSERT(available_len > 0); pp->pdu_cnt++; @@ -1736,7 +1708,6 @@ static isoal_status_t isoal_tx_try_emit_pdu(struct isoal_source *source, pp->pdu_written); pp->payload_number++; pp->sdu_fragments = 0; - pp->pdu_allocated = 0U; } return err; @@ -1780,7 +1751,7 @@ uint16_t isoal_tx_unframed_get_next_payload_number(isoal_source_handle_t source_ time_diff = 0; /* Adjust payload number */ - if (IS_ENABLED(CONFIG_BT_CTLR_ISOAL_SN_STRICT) && pp->initialized) { + if (IS_ENABLED(CONFIG_BT_CTLR_ISOAL_SN_STRICT) && session->sn) { /* Not the first SDU in this session, so reference * information should be valid. At this point, the * current payload number should be at the first PDU of @@ -1835,26 +1806,15 @@ uint16_t isoal_tx_unframed_get_next_payload_number(isoal_source_handle_t source_ return sdus_skipped; } -/** - * @brief Fragment received SDU and produce unframed PDUs - * @details Destination source may have an already partially built PDU +/* NOTE: Use of target_event and grp_ref_point as input from upper layer. * - * @param source_hdl[in] Destination source handle - * @param tx_sdu[in] SDU with packet boundary information - * - * @return Status - * - * @note - * PSN in SDUs for unframed TX: - * - * @par + * For unframed: * Before the modification to use the PSN to decide the position of an SDU in a * stream of SDU, the target event was what was used in deciding the event for * each SDU. This meant that there would possibly have been skews on the - * receiver for each SDU and there were problems with LL/CIS/PER/BV-39-C which + * receiver for each SDU and we had trouble with LL/CIS/PER/BV-39-C which * expects clustering within an event. * - * @par * After the change, the PSN is used to decide the position of an SDU in the * stream anchored at the first PSN received. However for the first SDU * (assume that PSN=0), it will be the target event that decides which event @@ -1863,7 +1823,6 @@ uint16_t isoal_tx_unframed_get_next_payload_number(isoal_source_handle_t source_ * impacts the event chosen for the first SDU and all subsequent SDUs will be * decided relative to the first. * - * @par * The target event and related group reference point is still used to provide * the ISO-AL with a notion of time, for example when storing information * required for the TX Sync command. For example if for PSN 4, target event is @@ -1873,17 +1832,26 @@ uint16_t isoal_tx_unframed_get_next_payload_number(isoal_source_handle_t source_ * for event 7. It is also expected that this value is the latest reference and * is drift compensated. * - * @par - * The PSN alone is not sufficient for this because host and controller have no - * common reference time for when CIG / BIG event 0 starts. Therefore it is - * expected that it is possible to receive PSN 0 in event 2 for example. If the - * target event provided is event 3, then PSN 0 will be fragmented into payloads - * for event 3 and that will serve as the anchor for the stream and subsequent - * SDUs. If for example target event provided was event 2 instead, then it could - * very well be that PSN 0 might not be transmitted as is was received midway - * through event 2 and the payloads expired. If this happens then subsequent - * SDUs might also all be late for their transmission slots as they are - * positioned relative to PSN 0. + * The PSN alone is not sufficient for this because as far as I am aware, host + * and controller have no common reference time for when CIG/BIG event 0 starts. + * Therefore I would expect it is possible to receive PSN 0 in event 2 for + * example. If the target event provided is event 3, then PSN 0 will be + * fragmented into payloads for event 3 and that will serve as the anchor for + * the stream and subsequent SDUs. If for example target event provided was + * event 2 instead, then it could very well be that PSN 0 might not be + * transmitted as is was received midway through event 2 and the payloads + * expired. If this happens then subsequent SDUs might also all be late for + * their transmission slots as they are positioned relative to PSN 0. + */ + +/** + * @brief Fragment received SDU and produce unframed PDUs + * @details Destination source may have an already partially built PDU + * + * @param source_hdl[in] Destination source handle + * @param tx_sdu[in] SDU with packet boundary information + * + * @return Status */ static isoal_status_t isoal_tx_unframed_produce(isoal_source_handle_t source_hdl, const struct isoal_sdu_tx *tx_sdu) @@ -1913,6 +1881,7 @@ static isoal_status_t isoal_tx_unframed_produce(isoal_source_handle_t source_hdl if (tx_sdu->sdu_state == BT_ISO_START || tx_sdu->sdu_state == BT_ISO_SINGLE) { + /* Initialize to info provided in SDU */ uint32_t actual_grp_ref_point; uint64_t next_payload_number; uint16_t sdus_skipped; @@ -2093,8 +2062,6 @@ static isoal_status_t isoal_tx_unframed_produce(isoal_source_handle_t source_hdl zero_length_sdu = false; } - pp->initialized = 1U; - return err; } @@ -2159,9 +2126,6 @@ static isoal_status_t isoal_insert_seg_header_timeoffset(struct isoal_source *so pp->pdu_written += write_size; pp->pdu_available -= write_size; - ISOAL_LOG_DBGV("[%p] Seg header write size=%u sc=%u cmplt=%u TO=%u len=%u", - source, write_size, sc, cmplt, time_offset, seg_hdr.len); - return err; } @@ -2199,155 +2163,6 @@ static isoal_status_t isoal_update_seg_header_cmplt_length(struct isoal_source * pp->last_seg_hdr_loc, (uint8_t *) &seg_hdr, PDU_ISO_SEG_HDR_SIZE); - - ISOAL_LOG_DBGV("[%p] Seg header write size=%u sc=%u cmplt=%u len=%u", - source, PDU_ISO_SEG_HDR_SIZE, seg_hdr.sc, cmplt, seg_hdr.len); -} - -/** - * Find the earliest feasible event for transmission capacity is not wasted and - * return information based on that event. - * @param[in] source_hdl Destination source handle - * @param[in] tx_sdu SDU with meta data information - * @param[out] payload_number Updated payload number for the selected event - * @param[out] grp_ref_point Group reference point for the selected event - * @param[out] time_offset Segmentation Time offset to selected event - * @return The number SDUs skipped from the last - */ -static uint16_t isoal_tx_framed_find_correct_tx_event(isoal_source_handle_t source_hdl, - const struct isoal_sdu_tx *tx_sdu, - uint64_t *payload_number, - uint32_t *grp_ref_point, - uint32_t *time_offset) -{ - struct isoal_source_session *session; - struct isoal_pdu_production *pp; - uint32_t actual_grp_ref_point; - uint64_t next_payload_number; - struct isoal_source *source; - uint16_t sdus_skipped; - uint64_t actual_event; - bool time_diff_valid; - uint32_t time_diff; - - source = &isoal_global.source_state[source_hdl]; - session = &source->session; - pp = &source->pdu_production; - - sdus_skipped = 0; - - /* Continue with the current payload unless there is need to change */ - next_payload_number = pp->payload_number; - actual_event = pp->payload_number / session->burst_number; - - ISOAL_LOG_DBGV("[%p] Start PL=%llu Evt=%lu.", source, next_payload_number, actual_event); - - /* Get the drift updated group reference point for this event based on - * the actual event being set. This might introduce some errors as the - * group refernce point for future events could drift. However as the - * time offset calculation requires an absolute value, this seems to be - * the best candidate. - */ - if (actual_event != tx_sdu->target_event) { - actual_grp_ref_point = isoal_get_wrapped_time_us(tx_sdu->grp_ref_point, - ((actual_event - tx_sdu->target_event) * session->iso_interval * - ISO_INT_UNIT_US)); - } else { - actual_grp_ref_point = tx_sdu->grp_ref_point; - } - - ISOAL_LOG_DBGV("[%p] Current PL=%llu Evt=%llu Ref=%lu", - source, next_payload_number, actual_event, actual_grp_ref_point); - - if (tx_sdu->sdu_state == BT_ISO_START || - tx_sdu->sdu_state == BT_ISO_SINGLE) { - /* Start of a new SDU */ - - /* Adjust payload number */ - if (pp->initialized) { - /* Not the first SDU in this session, so reference - * information should be valid. . - */ - time_diff_valid = isoal_get_time_diff(session->last_input_time_stamp, - tx_sdu->time_stamp, - &time_diff); - - /* Priority is given to the sequence number */ - if (tx_sdu->packet_sn > session->last_input_sn + 1) { - ISOAL_LOG_DBGV("[%p] Using packet_sn for skipped SDUs", source); - sdus_skipped = (tx_sdu->packet_sn - session->last_input_sn) - 1; - - } else if (tx_sdu->packet_sn == session->last_input_sn && - time_diff_valid && time_diff > session->sdu_interval) { - ISOAL_LOG_DBGV("[%p] Using time_stamp for skipped SDUs", source); - /* Round at mid-point */ - sdus_skipped = ((time_diff + (session->sdu_interval / 2)) / - session->sdu_interval) - 1; - } else { - /* SDU is next in sequence */ - } - - } else { - /* First SDU, align with target event */ - actual_event = tx_sdu->target_event; - actual_grp_ref_point = tx_sdu->grp_ref_point; - - ISOAL_LOG_DBGV("[%p] Use target_event", source); - } - - /* Selecting the event for transmission is done solely based on - * the time stamp and the ability to calculate a valid time - * offset. - */ - - /* Check if time stamp on packet is later than the group - * reference point and find next feasible event for transmission. - * - * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: - * 3.1 Time_Offset in framed PDUs : - * The Time_Offset shall be a positive value. - */ - while (!isoal_get_time_diff(tx_sdu->time_stamp, actual_grp_ref_point, &time_diff) || - time_diff == 0) { - /* Advance target to next event */ - actual_event++; - actual_grp_ref_point = isoal_get_wrapped_time_us(actual_grp_ref_point, - session->iso_interval * ISO_INT_UNIT_US); - } - - ISOAL_LOG_DBGV("[%p] Chosen PL=%llu Evt=%llu Ref=%lu", - source, (actual_event * session->burst_number), actual_event, - actual_grp_ref_point); - - /* If the event selected is the last event segmented for, then - * it is possible that that some payloads have already been - * released for this event. Segmentation should continue from - * that payload. - */ - next_payload_number = MAX(pp->payload_number, - (actual_event * session->burst_number)); - } - - ISOAL_LOG_DBGV("[%p] Final Evt=%llu (PL=%llu) Ref.=%lu Next PL=%llu", - source, actual_event, (actual_event * session->burst_number), - actual_grp_ref_point, next_payload_number); - - /* Calculate the time offset */ - time_diff_valid = isoal_get_time_diff(tx_sdu->time_stamp, - actual_grp_ref_point, &time_diff); - - LL_ASSERT(time_diff_valid); - LL_ASSERT(time_diff > 0); - /* Time difference must be less than the maximum possible - * time-offset of 24-bits. - */ - LL_ASSERT(time_diff <= 0x00FFFFFF); - - *payload_number = next_payload_number; - *grp_ref_point = actual_grp_ref_point; - *time_offset = time_diff; - - return sdus_skipped; } /** @@ -2371,6 +2186,7 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, bool zero_length_sdu; isoal_status_t err; bool padding_pdu; + uint8_t ll_id; source = &isoal_global.source_state[source_hdl]; session = &source->session; @@ -2386,53 +2202,15 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, zero_length_sdu = (packet_available == 0 && tx_sdu->sdu_state == BT_ISO_SINGLE); - ISOAL_LOG_DBGV("[%p] SDU %u len=%u TS=%lu Ref=%lu Evt=%llu Frag=%u", - source, tx_sdu->packet_sn, tx_sdu->iso_sdu_length, tx_sdu->time_stamp, - tx_sdu->grp_ref_point, tx_sdu->target_event, tx_sdu->sdu_state); - if (tx_sdu->sdu_state == BT_ISO_START || tx_sdu->sdu_state == BT_ISO_SINGLE) { - uint32_t actual_grp_ref_point; - uint64_t next_payload_number; - uint16_t sdus_skipped; - /* Start of a new SDU */ - /* Find the best transmission event */ - sdus_skipped = isoal_tx_framed_find_correct_tx_event(source_hdl, tx_sdu, - &next_payload_number, - &actual_grp_ref_point, - &time_offset); - - ISOAL_LOG_DBGV("[%p] %u SDUs skipped.", source, sdus_skipped); - ISOAL_LOG_DBGV("[%p] Starting SDU %u PL=(%llu->%llu) Grp Ref=%lu TO=%lu", - source, tx_sdu->packet_sn, pp->payload_number, next_payload_number, - actual_grp_ref_point, time_offset); - - - if (next_payload_number > pp->payload_number) { - /* Moving to a new payload */ - if (pp->pdu_allocated) { - /* Current PDU in production should be released before - * moving to new event. - */ - ISOAL_LOG_DBGV("[%p] Pending PDU released.\n"); - err |= isoal_tx_try_emit_pdu(source, true, PDU_BIS_LLID_FRAMED); - } - - while (err == ISOAL_STATUS_OK && next_payload_number > pp->payload_number && - (pp->payload_number % session->burst_number)) { - /* Release padding PDUs for this event */ - err |= isoal_tx_allocate_pdu(source, tx_sdu); - err |= isoal_tx_try_emit_pdu(source, true, PDU_BIS_LLID_FRAMED); - } - } - - /* Reset PDU production state */ - pp->pdu_state = BT_ISO_START; - - /* Update to new payload number */ - pp->payload_number = next_payload_number; + /* Initialize to info provided in SDU */ + uint32_t actual_grp_ref_point = tx_sdu->grp_ref_point; + uint64_t actual_event = tx_sdu->target_event; + bool time_diff_valid = false; + uint32_t time_diff = 0; /* Update sequence number for received SDU * @@ -2446,8 +2224,67 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, * with the sequence number in the ISOAL once the Datapath is * configured and the link is established. */ + session->sn++; - session->sn += sdus_skipped + 1; + /* Reset PDU production state */ + pp->pdu_state = BT_ISO_START; + + /* Update payload counter in case time has passed since the last + * SDU. This should mean that event count * burst number should + * be greater than the current payload number. In the event of + * an SDU interval smaller than the ISO interval, multiple SDUs + * will be sent in the same event. As such the current payload + * number should be retained. Payload numbers are indexed at 0 + * and valid until the PDU is emitted. + */ + pp->payload_number = MAX(pp->payload_number, + (tx_sdu->target_event * session->burst_number)); + + /* Get actual event for this payload number */ + actual_event = pp->payload_number / session->burst_number; + + /* Get group reference point for this PDU based on the actual + * event being set. This might introduce some errors as the + * group refernce point for future events could drift. However + * as the time offset calculation requires an absolute value, + * this seems to be the best candidate. + */ + if (actual_event > tx_sdu->target_event) { + actual_grp_ref_point = isoal_get_wrapped_time_us(tx_sdu->grp_ref_point, + ((actual_event - tx_sdu->target_event) * session->iso_interval * + ISO_INT_UNIT_US)); + } + + /* Check if time stamp on packet is later than the group + * reference point and adjust targets. This could happen if the + * SDU has been time-stampped at the controller when received + * via HCI. + * + * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: + * 3.1 Time_Offset in framed PDUs : + * The Time_Offset shall be a positive value. + */ + if (!isoal_get_time_diff(tx_sdu->time_stamp, actual_grp_ref_point, &time_diff) || + time_diff == 0) { + /* Advance target to next event */ + actual_event++; + actual_grp_ref_point = isoal_get_wrapped_time_us(actual_grp_ref_point, + session->iso_interval * ISO_INT_UNIT_US); + + /* Set payload number */ + pp->payload_number = actual_event * session->burst_number; + } + + /* Calculate the time offset */ + time_diff_valid = isoal_get_time_diff(tx_sdu->time_stamp, + actual_grp_ref_point, &time_diff); + LL_ASSERT(time_diff_valid); + LL_ASSERT(time_diff > 0); + /* Time difference must be less than the maximum possible + * time-offset of 24-bits. + */ + LL_ASSERT(time_diff <= 0x00FFFFFF); + time_offset = time_diff; /* Store timing info for TX Sync command */ session->tx_time_stamp = actual_grp_ref_point; @@ -2455,10 +2292,6 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, /* Reset PDU fragmentation count for this SDU */ pp->pdu_cnt = 0; - - /* Update input packet number and time stamp */ - session->last_input_sn = tx_sdu->packet_sn; - session->last_input_time_stamp = tx_sdu->time_stamp; } /* PDUs should be created until the SDU fragment has been fragmented or if @@ -2472,7 +2305,6 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, err |= err_alloc; - ISOAL_LOG_DBGV("[%p] State %s", source, STATE_TO_STR(pp->pdu_state)); if (pp->pdu_state == BT_ISO_START) { /* Start of a new SDU. Segmentation header and time-offset * should be inserted. @@ -2534,13 +2366,15 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, /* Update complete flag in last segmentation header */ err |= isoal_update_seg_header_cmplt_length(source, end_of_sdu, consume_len); + /* LLID is fixed for framed PDUs */ + ll_id = PDU_BIS_LLID_FRAMED; + /* If there isn't sufficient usable space then release the * PDU when the end of the SDU is reached, instead of waiting * for the next SDU. */ bool release_pdu = end_of_sdu && (pp->pdu_available <= ISOAL_TX_SEGMENT_MIN_SIZE); - const isoal_status_t err_emit = isoal_tx_try_emit_pdu(source, release_pdu, - PDU_BIS_LLID_FRAMED); + const isoal_status_t err_emit = isoal_tx_try_emit_pdu(source, release_pdu, ll_id); err |= err_emit; @@ -2558,8 +2392,6 @@ static isoal_status_t isoal_tx_framed_produce(isoal_source_handle_t source_hdl, zero_length_sdu = false; } - pp->initialized = 1U; - return err; } @@ -2592,9 +2424,9 @@ static isoal_status_t isoal_tx_framed_event_prepare_handle(isoal_source_handle_t first_event_payload = (session->burst_number * event_count); last_event_payload = (session->burst_number * (event_count + 1ULL)) - 1ULL; - if (pp->pdu_allocated && pp->payload_number <= last_event_payload) { + if (pp->pdu_available > 0 && + pp->payload_number <= last_event_payload) { /* Pending PDU that should be released for framed TX */ - ISOAL_LOG_DBGV("[%p] Prepare PDU released.", source); err = isoal_tx_try_emit_pdu(source, true, PDU_BIS_LLID_FRAMED); } @@ -2630,7 +2462,6 @@ static isoal_status_t isoal_tx_framed_event_prepare_handle(isoal_source_handle_t if (release_padding) { while (!err && !err_alloc && (pp->payload_number < last_event_payload + 1ULL)) { - ISOAL_LOG_DBGV("[%p] Prepare padding PDU release.", source); err_alloc = isoal_tx_allocate_pdu(source, NULL); err = isoal_tx_try_emit_pdu(source, true, PDU_BIS_LLID_FRAMED); @@ -2642,7 +2473,6 @@ static isoal_status_t isoal_tx_framed_event_prepare_handle(isoal_source_handle_t if (pp->payload_number < last_event_payload + 1ULL) { pp->payload_number = last_event_payload + 1ULL; - ISOAL_LOG_DBGV("[%p] Prepare PL updated to %lu.", source, pp->payload_number); } return err; @@ -2670,7 +2500,7 @@ isoal_status_t isoal_tx_sdu_fragment(isoal_source_handle_t source_hdl, /* Set source context active to mutually exclude ISO Event prepare * kick. */ - source->context_active = 1U; + source->context_active = true; if (source->pdu_production.mode != ISOAL_PRODUCTION_MODE_DISABLED) { /* BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: @@ -2690,12 +2520,11 @@ isoal_status_t isoal_tx_sdu_fragment(isoal_source_handle_t source_hdl, } } - source->context_active = 0U; + source->context_active = false; if (source->timeout_trigger) { - source->timeout_trigger = 0U; + source->timeout_trigger = false; if (session->framed) { - ISOAL_LOG_DBGV("[%p] Prepare cb flag trigger", source); isoal_tx_framed_event_prepare_handle(source_hdl, source->timeout_event_count); } @@ -2770,14 +2599,13 @@ void isoal_tx_event_prepare(isoal_source_handle_t source_hdl, * is active. */ source->timeout_event_count = event_count; - source->timeout_trigger = 1U; + source->timeout_trigger = true; if (source->context_active) { return; } - source->timeout_trigger = 0U; + source->timeout_trigger = false; if (session->framed) { - ISOAL_LOG_DBGV("[%p] Prepare call back", source); isoal_tx_framed_event_prepare_handle(source_hdl, event_count); } } diff --git a/subsys/bluetooth/controller/ll_sw/isoal.h b/subsys/bluetooth/controller/ll_sw/isoal.h index cc69e4a5d53..44f3504f1a6 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.h +++ b/subsys/bluetooth/controller/ll_sw/isoal.h @@ -376,6 +376,8 @@ struct isoal_source_session { uint8_t burst_number; uint8_t pdus_per_sdu; uint8_t max_pdu_size; + int32_t latency_unframed; + int32_t latency_framed; }; struct isoal_pdu_production { @@ -390,8 +392,6 @@ struct isoal_pdu_production { uint64_t seg_hdr_sc:1; uint64_t seg_hdr_length:8; uint64_t sdu_fragments:8; - uint64_t initialized:1; - uint64_t pdu_allocated:1; isoal_pdu_len_t pdu_written; isoal_pdu_len_t pdu_available; /* Location (byte index) of last segmentation header */ From b8d42f0f7be3a22acb6f511d9536c6fa2f5ee6d5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:10 +0000 Subject: [PATCH 0723/1623] Revert "[nrf fromtree] Bluetooth: Controller: Use DIV_ROUND_UP macro in HAL ticker" This reverts commit f5d51232a709225b77d6a2e9bfe25213e74637d5. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h | 5 +++-- .../bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h | 5 +++-- .../controller/mock_ctrl/include/hal/ticker_vendor_hal.h | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h index 10d780a559c..cbb8ae6a8ce 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h @@ -38,8 +38,9 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - DIV_ROUND_UP(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC), \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC) & \ + ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ HAL_TICKER_CNTR_MASK \ ) diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h index ab9b14207c1..78aa6362595 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h @@ -43,8 +43,9 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - DIV_ROUND_UP(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC), \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC) & \ + ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ HAL_TICKER_CNTR_MASK \ ) diff --git a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h index 8cb4e791a30..c2b20050caa 100644 --- a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h +++ b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h @@ -37,8 +37,9 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - DIV_ROUND_UP(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC), \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC) & \ + ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ HAL_TICKER_CNTR_MASK \ ) From a6d5c8f1afafdf359e9d5c8705e278aedc1edcd4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:10 +0000 Subject: [PATCH 0724/1623] Revert "[nrf fromtree] Bluetooth: Controller: Use defines for femto and pico seconds" This reverts commit fb5d216e14172be3d897607f7e0928459c3b0dd9. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/hal/nrf5/ticker.h | 41 +++++++++---------- .../ll_sw/openisa/hal/RV32M1/ticker.h | 29 ++++++------- .../mock_ctrl/include/hal/ticker_vendor_hal.h | 29 ++++++------- 3 files changed, 45 insertions(+), 54 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h index cbb8ae6a8ce..f179dbd0035 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h @@ -5,11 +5,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U -#define HAL_TICKER_CNTR_CLK_UNIT_FSEC 30517578125UL -#define HAL_TICKER_FSEC_PER_USEC 1000000000UL -#define HAL_TICKER_PSEC_PER_USEC 1000000UL -#define HAL_TICKER_FSEC_PER_PSEC 1000UL +#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U +#define HAL_TICKER_CNTR_CLK_UNIT_FS 30517578125UL /* Macro defining the minimum counter compare offset */ #define HAL_TICKER_CNTR_CMP_OFFSET_MIN 3 @@ -28,8 +25,8 @@ */ #define HAL_TICKER_US_TO_TICKS(x) \ ( \ - ((uint32_t)(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) / \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ + ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ HAL_TICKER_CNTR_MASK \ ) @@ -38,35 +35,35 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ + ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ + HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ HAL_TICKER_CNTR_MASK \ ) /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ ( \ - ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FSEC) / \ - HAL_TICKER_FSEC_PER_USEC)) \ + ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FS) / \ + 1000000000UL)) \ ) /* Macro returning remainder in picoseconds (to fit in 32-bits) */ #define HAL_TICKER_REMAINDER(x) \ ( \ ( \ - ((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) \ + ((uint64_t) (x) * 1000000000UL) \ - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC) \ + HAL_TICKER_CNTR_CLK_UNIT_FS) \ ) \ - / HAL_TICKER_FSEC_PER_PSEC \ + / 1000UL \ ) /* Macro defining the remainder resolution/range * ~ 1000000 * HAL_TICKER_TICKS_TO_US(1) */ #define HAL_TICKER_REMAINDER_RANGE \ - HAL_TICKER_TICKS_TO_US(HAL_TICKER_PSEC_PER_USEC) + HAL_TICKER_TICKS_TO_US(1000000) /* Macro defining the margin for positioning re-scheduled nodes */ #define HAL_TICKER_RESCHEDULE_MARGIN \ @@ -77,24 +74,24 @@ static inline void hal_ticker_remove_jitter(uint32_t *ticks, uint32_t *remainder) { /* Is remainder less than 1 us */ - if ((*remainder & BIT(31)) || !(*remainder / HAL_TICKER_PSEC_PER_USEC)) { + if ((*remainder & BIT(31)) || !(*remainder / 1000000UL)) { *ticks -= 1U; - *remainder += HAL_TICKER_CNTR_CLK_UNIT_FSEC / HAL_TICKER_FSEC_PER_PSEC; + *remainder += HAL_TICKER_CNTR_CLK_UNIT_FS / 1000UL; } /* pico seconds to micro seconds unit */ - *remainder /= HAL_TICKER_PSEC_PER_USEC; + *remainder /= 1000000UL; } /* Add ticks and return positive remainder value in microseconds */ static inline void hal_ticker_add_jitter(uint32_t *ticks, uint32_t *remainder) { /* Is remainder less than 1 us */ - if ((*remainder & BIT(31)) || !(*remainder / HAL_TICKER_PSEC_PER_USEC)) { + if ((*remainder & BIT(31)) || !(*remainder / 1000000UL)) { *ticks += 1U; - *remainder += HAL_TICKER_CNTR_CLK_UNIT_FSEC / HAL_TICKER_FSEC_PER_PSEC; + *remainder += HAL_TICKER_CNTR_CLK_UNIT_FS / 1000UL; } /* pico seconds to micro seconds unit */ - *remainder /= HAL_TICKER_PSEC_PER_USEC; + *remainder /= 1000000UL; } diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h index 78aa6362595..1f491739185 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h @@ -5,11 +5,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U -#define HAL_TICKER_CNTR_CLK_UNIT_FSEC 30517578125UL -#define HAL_TICKER_FSEC_PER_USEC 1000000000UL -#define HAL_TICKER_PSEC_PER_USEC 1000000UL -#define HAL_TICKER_FSEC_PER_PSEC 1000UL +#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U +#define HAL_TICKER_CNTR_CLK_UNIT_FS 30517578125UL /* Macro defining the minimum counter compare offset */ #define HAL_TICKER_CNTR_CMP_OFFSET_MIN 2 @@ -33,8 +30,8 @@ */ #define HAL_TICKER_US_TO_TICKS(x) \ ( \ - ((uint32_t)(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) / \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ + ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ HAL_TICKER_CNTR_MASK \ ) @@ -43,35 +40,35 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ + ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ + HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ HAL_TICKER_CNTR_MASK \ ) /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ ( \ - ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FSEC) / \ - HAL_TICKER_FSEC_PER_USEC)) \ + ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FS) / \ + 1000000000UL)) \ ) /* Macro returning remainder in picoseconds (to fit in 32-bits) */ #define HAL_TICKER_REMAINDER(x) \ ( \ ( \ - ((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) \ + ((uint64_t) (x) * 1000000000UL) \ - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC) \ + HAL_TICKER_CNTR_CLK_UNIT_FS) \ ) \ - / HAL_TICKER_FSEC_PER_PSEC \ + / 1000UL \ ) /* Macro defining the remainder resolution/range * ~ 1000000 * HAL_TICKER_TICKS_TO_US(1) */ #define HAL_TICKER_REMAINDER_RANGE \ - HAL_TICKER_TICKS_TO_US(HAL_TICKER_PSEC_PER_USEC) + HAL_TICKER_TICKS_TO_US(1000000) /* Macro defining the margin for positioning re-scheduled nodes */ #define HAL_TICKER_RESCHEDULE_MARGIN \ diff --git a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h index c2b20050caa..67a46515033 100644 --- a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h +++ b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h @@ -4,11 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U -#define HAL_TICKER_CNTR_CLK_UNIT_FSEC 30517578125UL -#define HAL_TICKER_FSEC_PER_USEC 1000000000UL -#define HAL_TICKER_PSEC_PER_USEC 1000000UL -#define HAL_TICKER_FSEC_PER_PSEC 1000UL +#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U +#define HAL_TICKER_CNTR_CLK_UNIT_FS 30517578125UL /* Macro defining the minimum counter compare offset */ #define HAL_TICKER_CNTR_CMP_OFFSET_MIN 3 @@ -27,8 +24,8 @@ */ #define HAL_TICKER_US_TO_TICKS(x) \ ( \ - ((uint32_t)(((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) / \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ + ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ HAL_TICKER_CNTR_MASK \ ) @@ -37,35 +34,35 @@ */ #define HAL_TICKER_US_TO_TICKS_CEIL(x) \ ( \ - ((uint32_t)(((((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) + \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC)) & \ + ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ + HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ HAL_TICKER_CNTR_MASK \ ) /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ ( \ - ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FSEC) / \ - HAL_TICKER_FSEC_PER_USEC)) \ + ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FS) / \ + 1000000000UL)) \ ) /* Macro returning remainder in picoseconds (to fit in 32-bits) */ #define HAL_TICKER_REMAINDER(x) \ ( \ ( \ - ((uint64_t) (x) * HAL_TICKER_FSEC_PER_USEC) \ + ((uint64_t) (x) * 1000000000UL) \ - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * \ - HAL_TICKER_CNTR_CLK_UNIT_FSEC) \ + HAL_TICKER_CNTR_CLK_UNIT_FS) \ ) \ - / HAL_TICKER_FSEC_PER_PSEC \ + / 1000UL \ ) /* Macro defining the remainder resolution/range * ~ 1000000 * HAL_TICKER_TICKS_TO_US(1) */ #define HAL_TICKER_REMAINDER_RANGE \ - HAL_TICKER_TICKS_TO_US(HAL_TICKER_PSEC_PER_USEC) + HAL_TICKER_TICKS_TO_US(1000000) /* Macro defining the margin for positioning re-scheduled nodes */ #define HAL_TICKER_RESCHEDULE_MARGIN \ From d3deb69671a100df9cfed8f42a7864c8407858bb Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:10 +0000 Subject: [PATCH 0725/1623] Revert "[nrf fromtree] Bluetooth: Controller: Use HAL_TICKER_US_TO_TICKS_CEIL for ticks_slot" This reverts commit 4604cde52079bb44a3d2fcfd08c7362969cf3a40. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/hal/nrf5/ticker.h | 11 ----------- .../controller/ll_sw/openisa/hal/RV32M1/ticker.h | 11 ----------- subsys/bluetooth/controller/ll_sw/ull_adv.c | 4 ++-- subsys/bluetooth/controller/ll_sw/ull_adv_aux.c | 6 +++--- subsys/bluetooth/controller/ll_sw/ull_adv_iso.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_adv_sync.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_central.c | 11 +++++++---- subsys/bluetooth/controller/ll_sw/ull_central_iso.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_conn.c | 10 ++++++---- subsys/bluetooth/controller/ll_sw/ull_conn_iso.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_peripheral.c | 11 +++++++---- subsys/bluetooth/controller/ll_sw/ull_scan_aux.c | 10 ++++++---- subsys/bluetooth/controller/ll_sw/ull_sched.c | 10 ++++------ subsys/bluetooth/controller/ll_sw/ull_sync.c | 10 ++++++---- subsys/bluetooth/controller/ll_sw/ull_sync_iso.c | 10 +++++----- .../mock_ctrl/include/hal/ticker_vendor_hal.h | 10 ---------- 16 files changed, 50 insertions(+), 72 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h index f179dbd0035..315601ce203 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h @@ -30,17 +30,6 @@ HAL_TICKER_CNTR_MASK \ ) -/* Macro to translate microseconds to tick units. - * NOTE: This returns the ceil value. - */ -#define HAL_TICKER_US_TO_TICKS_CEIL(x) \ - ( \ - ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ - HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ - HAL_TICKER_CNTR_MASK \ - ) - /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ ( \ diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h index 1f491739185..e4d162eb9d2 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h @@ -35,17 +35,6 @@ HAL_TICKER_CNTR_MASK \ ) -/* Macro to translate microseconds to tick units. - * NOTE: This returns the ceil value. - */ -#define HAL_TICKER_US_TO_TICKS_CEIL(x) \ - ( \ - ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ - HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ - HAL_TICKER_CNTR_MASK \ - ) - /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ ( \ diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index d7d5b23f63e..3797acdc541 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -1251,7 +1251,7 @@ uint8_t ll_adv_enable(uint8_t enable) HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); adv->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - adv->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); + adv->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); ticks_slot_offset = MAX(adv->ull.ticks_active_to_start, adv->ull.ticks_prepare_to_start); @@ -2145,7 +2145,7 @@ uint8_t ull_adv_time_update(struct ll_adv_set *adv, struct pdu_adv *pdu, chan_map = lll->chan_map; chan_cnt = util_ones_count_get(&chan_map, sizeof(chan_map)); time_us = adv_time_get(pdu, pdu_scan, chan_cnt, phy, phy_flags); - time_ticks = HAL_TICKER_US_TO_TICKS_CEIL(time_us); + time_ticks = HAL_TICKER_US_TO_TICKS(time_us); #if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) uint32_t volatile ret_cb; diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c index 5349b21dd9f..907a69b05c7 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c @@ -2454,7 +2454,7 @@ uint32_t ull_adv_aux_evt_init(struct ll_adv_aux_set *aux, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); aux->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - aux->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); + aux->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { ticks_slot_overhead = MAX(aux->ull.ticks_active_to_start, @@ -2471,7 +2471,7 @@ uint32_t ull_adv_aux_evt_init(struct ll_adv_aux_set *aux, #if defined(CONFIG_BT_CTLR_ADV_RESERVE_MAX) time_us = ull_adv_aux_time_get(aux, PDU_AC_PAYLOAD_SIZE_MAX, PDU_AC_PAYLOAD_SIZE_MAX); - ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); + ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); #else ticks_slot = aux->ull.ticks_slot; #endif @@ -2997,7 +2997,7 @@ static uint8_t aux_time_update(struct ll_adv_aux_set *aux, struct pdu_adv *pdu, uint32_t time_us; time_us = aux_time_min_get(aux); - time_ticks = HAL_TICKER_US_TO_TICKS_CEIL(time_us); + time_ticks = HAL_TICKER_US_TO_TICKS(time_us); #if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) uint32_t volatile ret_cb; diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index 89e66ff99e5..765e911b208 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -977,7 +977,7 @@ static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); adv_iso->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - adv_iso->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); + adv_iso->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(slot_us); ticks_slot_offset = MAX(adv_iso->ull.ticks_active_to_start, adv_iso->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c index bbb1b351848..178116a54ec 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c @@ -1136,7 +1136,7 @@ uint32_t ull_adv_sync_evt_init(struct ll_adv_set *adv, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); sync->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - sync->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); + sync->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); ticks_slot_offset = MAX(sync->ull.ticks_active_to_start, sync->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_central.c b/subsys/bluetooth/controller/ll_sw/ull_central.c index de14395f840..5effe2ae676 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central.c @@ -360,10 +360,13 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, #endif /* CONFIG_BT_CTLR_ADV_EXT */ #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( - EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + - ready_delay_us + max_tx_time + EVENT_IFS_US + max_rx_time + - (EVENT_CLOCK_JITTER_US << 1)); + conn->ull.ticks_slot = + HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + + EVENT_OVERHEAD_END_US + + ready_delay_us + + max_tx_time + + EVENT_IFS_US + + max_rx_time); #if defined(CONFIG_BT_CTLR_PRIVACY) ull_filter_scan_update(filter_policy); diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 2a19e03bde5..71b8d742a76 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -559,7 +559,7 @@ uint8_t ll_cig_parameters_commit(uint8_t cig_id, uint16_t *handles) HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); cig->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - cig->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); + cig->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(slot_us); #endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ /* Reset params cache */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index a8d3178e020..0b54a5dee79 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -1257,10 +1257,12 @@ void ull_conn_done(struct node_rx_event_done *done) tx_time = PDU_DC_MAX_US(lll->dle.eff.max_tx_octets, 0); rx_time = PDU_DC_MAX_US(lll->dle.eff.max_rx_octets, 0); #endif /* CONFIG_BT_CTLR_PHY */ - ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( - EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + - ready_delay + EVENT_IFS_US + rx_time + tx_time + - (EVENT_CLOCK_JITTER_US << 1)); + ticks_slot = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + + ready_delay + + EVENT_IFS_US + + rx_time + + tx_time + + 4); if (ticks_slot > conn->ull.ticks_slot) { ticks_slot_plus = ticks_slot - conn->ull.ticks_slot; } else { diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index 46c00c305fe..2ee5905b23b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -987,7 +987,7 @@ void ull_conn_iso_start(struct ll_conn *conn, uint16_t cis_handle, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); cig->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - cig->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(slot_us); + cig->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(slot_us); } ticks_slot_offset = MAX(cig->ull.ticks_active_to_start, diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c index 8b813fda9fd..f1716c06573 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c @@ -371,10 +371,13 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); conn->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( - EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US + - ready_delay_us + max_rx_time + EVENT_IFS_US + max_tx_time + - (EVENT_CLOCK_JITTER_US << 1)); + conn->ull.ticks_slot = + HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + + EVENT_OVERHEAD_END_US + + ready_delay_us + + max_rx_time + + EVENT_IFS_US + + max_tx_time); ticks_slot_offset = MAX(conn->ull.ticks_active_to_start, conn->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c b/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c index 316cec7fec7..26fc6d4806b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c @@ -666,10 +666,12 @@ void ull_scan_aux_setup(memq_link_t *link, struct node_rx_hdr *rx) HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); aux->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - aux->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( - EVENT_OVERHEAD_START_US + ready_delay_us + - PDU_AC_MAX_US(PDU_AC_EXT_PAYLOAD_RX_SIZE, lll_aux->phy) + - EVENT_OVERHEAD_END_US); + aux->ull.ticks_slot = + HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + + ready_delay_us + + PDU_AC_MAX_US(PDU_AC_EXT_PAYLOAD_RX_SIZE, + lll_aux->phy) + + EVENT_OVERHEAD_END_US); ticks_slot_offset = MAX(aux->ull.ticks_active_to_start, aux->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_sched.c b/subsys/bluetooth/controller/ll_sw/ull_sched.c index e7ca8a0358b..a445d986248 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sched.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sched.c @@ -656,7 +656,7 @@ static struct ull_hdr *ull_hdr_get_cb(uint8_t ticker_id, uint32_t *ticks_slot) time_us = ull_adv_aux_time_get(aux, PDU_AC_PAYLOAD_SIZE_MAX, PDU_AC_PAYLOAD_SIZE_MAX); - *ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); + *ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); } else { *ticks_slot = aux->ull.ticks_slot; @@ -686,7 +686,7 @@ static struct ull_hdr *ull_hdr_get_cb(uint8_t ticker_id, uint32_t *ticks_slot) uint32_t time_us; time_us = ull_adv_sync_time_get(sync, PDU_AC_PAYLOAD_SIZE_MAX); - *ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); + *ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); } else { *ticks_slot = sync->ull.ticks_slot; } @@ -745,11 +745,9 @@ static struct ull_hdr *ull_hdr_get_cb(uint8_t ticker_id, uint32_t *ticks_slot) #endif /* !CONFIG_BT_CTLR_PHY_CODED */ time_us = EVENT_OVERHEAD_START_US + - EVENT_OVERHEAD_END_US + ready_delay_us + max_rx_time + - EVENT_IFS_US + max_tx_time + - (EVENT_CLOCK_JITTER_US << 1); - *ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL(time_us); + EVENT_IFS_US + max_tx_time; + *ticks_slot = HAL_TICKER_US_TO_TICKS(time_us); } else { *ticks_slot = conn->ull.ticks_slot; } diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync.c b/subsys/bluetooth/controller/ll_sw/ull_sync.c index 265475196fd..6c674885810 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sync.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sync.c @@ -826,10 +826,12 @@ void ull_sync_setup(struct ll_scan_set *scan, struct ll_scan_aux_set *aux, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); sync->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - sync->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( - EVENT_OVERHEAD_START_US + ready_delay_us + - PDU_AC_MAX_US(PDU_AC_EXT_PAYLOAD_RX_SIZE, lll->phy) + - EVENT_OVERHEAD_END_US); + sync->ull.ticks_slot = + HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + + ready_delay_us + + PDU_AC_MAX_US(PDU_AC_EXT_PAYLOAD_RX_SIZE, + lll->phy) + + EVENT_OVERHEAD_END_US); ticks_slot_offset = MAX(sync->ull.ticks_active_to_start, sync->ull.ticks_prepare_to_start); diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c index ff3327ce393..fbacb56f8b4 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c @@ -509,11 +509,11 @@ void ull_sync_iso_setup(struct ll_sync_iso_set *sync_iso, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_XTAL_US); sync_iso->ull.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); - sync_iso->ull.ticks_slot = HAL_TICKER_US_TO_TICKS_CEIL( - EVENT_OVERHEAD_START_US + ready_delay_us + - PDU_BIS_MAX_US(PDU_AC_EXT_PAYLOAD_SIZE_MAX, lll->enc, - lll->phy) + - EVENT_OVERHEAD_END_US); + sync_iso->ull.ticks_slot = HAL_TICKER_US_TO_TICKS( + EVENT_OVERHEAD_START_US + ready_delay_us + + PDU_BIS_MAX_US(PDU_AC_EXT_PAYLOAD_SIZE_MAX, lll->enc, + lll->phy) + + EVENT_OVERHEAD_END_US); ticks_slot_offset = MAX(sync_iso->ull.ticks_active_to_start, sync_iso->ull.ticks_prepare_to_start); diff --git a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h index 67a46515033..7c3792d848c 100644 --- a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h +++ b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h @@ -29,16 +29,6 @@ HAL_TICKER_CNTR_MASK \ ) -/* Macro to translate microseconds to tick units. - * NOTE: This returns the ceil value. - */ -#define HAL_TICKER_US_TO_TICKS_CEIL(x) \ - ( \ - ((uint32_t)(((((uint64_t) (x) * 1000000000UL) + \ - HAL_TICKER_CNTR_CLK_UNIT_FS - 1U)) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ - HAL_TICKER_CNTR_MASK \ - ) /* Macro to translate tick units to microseconds. */ #define HAL_TICKER_TICKS_TO_US(x) \ From aedb3750e6f1a507b18b570caf67db8c000f0419 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:10 +0000 Subject: [PATCH 0726/1623] Revert "[nrf fromtree] Bluetooth: Controller: Make openisa and test hal ticker.h consistent" This reverts commit 1734da8febc892c0ad4231495b3425acd192668f. Signed-off-by: Dominik Ermel --- .../controller/ll_sw/nordic/hal/nrf5/ticker.h | 3 +- .../ll_sw/openisa/hal/RV32M1/ticker.h | 36 ++++---------- .../mock_ctrl/include/hal/ticker_vendor_hal.h | 49 ++++++------------- 3 files changed, 26 insertions(+), 62 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h index 315601ce203..5845d15145a 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h @@ -26,8 +26,7 @@ #define HAL_TICKER_US_TO_TICKS(x) \ ( \ ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ - HAL_TICKER_CNTR_MASK \ + HAL_TICKER_CNTR_CLK_UNIT_FS)) & HAL_TICKER_CNTR_MASK \ ) /* Macro to translate tick units to microseconds. */ diff --git a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h index e4d162eb9d2..642ca1e608f 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/ticker.h @@ -6,53 +6,37 @@ */ #define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U -#define HAL_TICKER_CNTR_CLK_UNIT_FS 30517578125UL -/* Macro defining the minimum counter compare offset */ #define HAL_TICKER_CNTR_CMP_OFFSET_MIN 2 -/* Macro defining the max. counter update latency in ticks */ #define HAL_TICKER_CNTR_SET_LATENCY 1 - -/* Macro defines the h/w supported most significant bit */ -#define HAL_TICKER_CNTR_MSBIT 31 - -/* Macro defining the HW supported counter bits */ -#define HAL_TICKER_CNTR_MASK 0xFFFFFFFF - /* * When the LPTMR is enabled, the first increment will take an additional * one or two prescaler clock cycles due to synchronization logic. */ -/* Macro to translate microseconds to tick units. - * NOTE: This returns the floor value. - */ #define HAL_TICKER_US_TO_TICKS(x) \ ( \ - ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ - HAL_TICKER_CNTR_MASK \ - ) - -/* Macro to translate tick units to microseconds. */ -#define HAL_TICKER_TICKS_TO_US(x) \ - ( \ - ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FS) / \ - 1000000000UL)) \ + ((uint32_t)(((uint64_t) (x) * 1000000000UL) / 30517578125UL)) \ + & HAL_TICKER_CNTR_MASK \ ) -/* Macro returning remainder in picoseconds (to fit in 32-bits) */ #define HAL_TICKER_REMAINDER(x) \ ( \ ( \ ((uint64_t) (x) * 1000000000UL) \ - - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * \ - HAL_TICKER_CNTR_CLK_UNIT_FS) \ + - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * 30517578125UL) \ ) \ / 1000UL \ ) +#define HAL_TICKER_TICKS_TO_US(x) \ + ((uint32_t)(((uint64_t)(x) * 30517578125UL) / 1000000000UL)) + +#define HAL_TICKER_CNTR_MSBIT 31 + +#define HAL_TICKER_CNTR_MASK 0xFFFFFFFF + /* Macro defining the remainder resolution/range * ~ 1000000 * HAL_TICKER_TICKS_TO_US(1) */ diff --git a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h index 7c3792d848c..bbd4b3e462c 100644 --- a/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h +++ b/tests/bluetooth/controller/mock_ctrl/include/hal/ticker_vendor_hal.h @@ -3,9 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ - #define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U -#define HAL_TICKER_CNTR_CLK_UNIT_FS 30517578125UL /* Macro defining the minimum counter compare offset */ #define HAL_TICKER_CNTR_CMP_OFFSET_MIN 3 @@ -13,47 +11,30 @@ /* Macro defining the max. counter update latency in ticks */ #define HAL_TICKER_CNTR_SET_LATENCY 0 -/* Macro defines the h/w supported most significant bit */ -#define HAL_TICKER_CNTR_MSBIT 23 - -/* Macro defining the HW supported counter bits */ -#define HAL_TICKER_CNTR_MASK 0x00FFFFFF - /* Macro to translate microseconds to tick units. * NOTE: This returns the floor value. */ -#define HAL_TICKER_US_TO_TICKS(x) \ - ( \ - ((uint32_t)(((uint64_t) (x) * 1000000000UL) / \ - HAL_TICKER_CNTR_CLK_UNIT_FS)) & \ - HAL_TICKER_CNTR_MASK \ - ) +#define HAL_TICKER_US_TO_TICKS(x) \ + (((uint32_t)(((uint64_t)(x) * 1000000000UL) / 30517578125UL)) & HAL_TICKER_CNTR_MASK) +/* Macro returning remainder in nanoseconds */ +#define HAL_TICKER_REMAINDER(x) \ + ((((uint64_t)(x) * 1000000000UL) - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * 30517578125UL)) /\ + 1000UL) /* Macro to translate tick units to microseconds. */ -#define HAL_TICKER_TICKS_TO_US(x) \ - ( \ - ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FS) / \ - 1000000000UL)) \ - ) - -/* Macro returning remainder in picoseconds (to fit in 32-bits) */ -#define HAL_TICKER_REMAINDER(x) \ - ( \ - ( \ - ((uint64_t) (x) * 1000000000UL) \ - - ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * \ - HAL_TICKER_CNTR_CLK_UNIT_FS) \ - ) \ - / 1000UL \ - ) +#define HAL_TICKER_TICKS_TO_US(x) ((uint32_t)(((uint64_t)(x) * 30517578125UL) / 1000000000UL)) + +/* Macro defines the h/w supported most significant bit */ +#define HAL_TICKER_CNTR_MSBIT 23 + +/* Macro defining the HW supported counter bits */ +#define HAL_TICKER_CNTR_MASK 0x00FFFFFF /* Macro defining the remainder resolution/range * ~ 1000000 * HAL_TICKER_TICKS_TO_US(1) */ -#define HAL_TICKER_REMAINDER_RANGE \ - HAL_TICKER_TICKS_TO_US(1000000) +#define HAL_TICKER_REMAINDER_RANGE HAL_TICKER_TICKS_TO_US(1000000) /* Macro defining the margin for positioning re-scheduled nodes */ -#define HAL_TICKER_RESCHEDULE_MARGIN \ - HAL_TICKER_US_TO_TICKS(150) +#define HAL_TICKER_RESCHEDULE_MARGIN HAL_TICKER_US_TO_TICKS(150) From c7a1b88d0216b8922c4575924ae5441d65766551 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:11 +0000 Subject: [PATCH 0727/1623] Revert "[nrf fromtree] Bluetooth: Controller: Revert EVENT_OVERHEAD_END_US to original value" This reverts commit 1845278ad53c15a557ca81895e9e5c89721d573b. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h index 7df39f65c8a..5ee063e4d53 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_vendor.h @@ -42,7 +42,7 @@ /* Worst-case time margin needed after event end-time in the air * (done/preempt race margin + power-down/chain delay) */ -#define EVENT_OVERHEAD_END_US 40 +#define EVENT_OVERHEAD_END_US 100 /* Sleep Clock Accuracy */ #define EVENT_JITTER_US 16 From d7707e31d290a914527b83c1d10389186f893a9b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:11 +0000 Subject: [PATCH 0728/1623] Revert "[nrf fromtree] bluetooth: controller: coex: convert to DT device" This reverts commit 4259135d4de0b463e3b9e10ab03982d92321e8ca. Signed-off-by: Dominik Ermel --- samples/bluetooth/beacon/prj-coex.conf | 1 + subsys/bluetooth/controller/coex/Kconfig | 4 ++-- subsys/bluetooth/controller/coex/coex_ticker.c | 18 ++++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/samples/bluetooth/beacon/prj-coex.conf b/samples/bluetooth/beacon/prj-coex.conf index eb9cd4bb16e..b16487f3999 100644 --- a/samples/bluetooth/beacon/prj-coex.conf +++ b/samples/bluetooth/beacon/prj-coex.conf @@ -3,4 +3,5 @@ CONFIG_LOG=y CONFIG_BT_DEVICE_NAME="Test beacon" CONFIG_BT_LL_SW_SPLIT=y +CONFIG_BT_CTLR_COEX_DRIVERS=y CONFIG_BT_CTLR_COEX_TICKER=y diff --git a/subsys/bluetooth/controller/coex/Kconfig b/subsys/bluetooth/controller/coex/Kconfig index b7bc7d30681..31754fbf52c 100644 --- a/subsys/bluetooth/controller/coex/Kconfig +++ b/subsys/bluetooth/controller/coex/Kconfig @@ -5,8 +5,8 @@ menuconfig BT_CTLR_COEX_DRIVERS bool "Bluetooth Co-existence Drivers" - default y - depends on BT_CTLR && DT_HAS_GPIO_RADIO_COEX_ENABLED + default n + depends on BT_CTLR if BT_CTLR_COEX_DRIVERS diff --git a/subsys/bluetooth/controller/coex/coex_ticker.c b/subsys/bluetooth/controller/coex/coex_ticker.c index be349622ecd..229e2f9e125 100644 --- a/subsys/bluetooth/controller/coex/coex_ticker.c +++ b/subsys/bluetooth/controller/coex/coex_ticker.c @@ -4,13 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define DT_DRV_COMPAT gpio_radio_coex - #include #include #include #include +#include #include #include #include @@ -196,11 +195,18 @@ static int coex_ticker_init(const struct device *dev) return 0; } +#define RADIO_NODE DT_NODELABEL(radio) +#define COEX_NODE DT_PROP(RADIO_NODE, coex) + +#if DT_NODE_EXISTS(COEX_NODE) static struct coex_ticker_config config = { - .grant_spec = GPIO_DT_SPEC_INST_GET(0, grant_gpios), - .grant_delay_us = DT_INST_PROP(0, grant_delay_us) + .grant_spec = GPIO_DT_SPEC_GET(COEX_NODE, grant_gpios), + .grant_delay_us = DT_PROP(COEX_NODE, grant_delay_us) }; static struct coex_ticker_data data; -DEVICE_DT_INST_DEFINE(0, &coex_ticker_init, NULL, &data, &config, - POST_KERNEL, 90, NULL); +DEVICE_DEFINE(coex_ticker, "COEX_TICKER", &coex_ticker_init, NULL, + &data, &config, + APPLICATION, 90, + NULL); +#endif From 17aa8566f2592e9c1bae98bb55a5acb892923737 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:11 +0000 Subject: [PATCH 0729/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix missing lazy calculation for Central ISO" This reverts commit 1cd5c0c6039be61db9eb5e5f0c95586854fdec52. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/Kconfig.ll_sw_split | 2 +- subsys/bluetooth/controller/ll_sw/ull_conn_iso.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 910c3819f0c..84db5fddb10 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -53,7 +53,7 @@ config BT_LLL_VENDOR_NORDIC (BT_OBSERVER && BT_CTLR_ADV_EXT) select BT_TICKER_REMAINDER if BT_CTLR_CENTRAL_ISO select BT_TICKER_REMAINDER_GET if BT_BROADCASTER && BT_CTLR_ADV_EXT - select BT_TICKER_LAZY_GET if BT_CTLR_ADV_PERIODIC || BT_CTLR_CENTRAL_ISO + select BT_TICKER_LAZY_GET if BT_CTLR_ADV_PERIODIC default y help diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index 2ee5905b23b..cc76c5219cb 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -1042,8 +1042,8 @@ static void mfy_cis_lazy_fill(void *param) uint32_t ticks_to_expire; uint32_t ticks_current; uint32_t remainder; - uint16_t lazy = 0U; uint8_t ticker_id; + uint16_t lazy; uint8_t retry; uint8_t id; From cdf2c9133769087c35ddaa627f1e57a7599de5c5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:11 +0000 Subject: [PATCH 0730/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix initialization of lazy_active" This reverts commit f6496260fc1dc3e873cb55cce34ab1814df1a004. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_conn_iso.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index cc76c5219cb..8b79100d942 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -851,10 +851,6 @@ void ull_conn_iso_start(struct ll_conn *conn, uint16_t cis_handle, */ if (cig->state == CIG_STATE_ACTIVE) { #if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) - /* Initialize CIS event lazy at CIS create */ - cis->lll.lazy_active = 0U; - - /* Deferred fill CIS event lazy value at CIS create */ cis_lazy_fill(cis); #else /* CONFIG_BT_CTLR_JIT_SCHEDULING */ /* Set CIS active in already active CIG */ @@ -1000,9 +996,6 @@ void ull_conn_iso_start(struct ll_conn *conn, uint16_t cis_handle, } ticks_slot = cig->ull.ticks_slot + ticks_slot_overhead; - - /* Initialize CIS event lazy at CIS create */ - cis->lll.lazy_active = 0U; #endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ /* Start CIS peripheral CIG ticker */ @@ -1021,6 +1014,11 @@ void ull_conn_iso_start(struct ll_conn *conn, uint16_t cis_handle, /* Set CIG and the first CIS state as active */ cig->state = CIG_STATE_ACTIVE; cis->lll.active = 1U; + +#if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) + /* CIS event lazy at CIS create */ + cis->lll.lazy_active = 0U; +#endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ } #if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) From e3e0591f0c762fa0c9cfdc3d7cd1cf8079a4e382 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:11 +0000 Subject: [PATCH 0731/1623] Revert "[nrf fromtree] Bluetooth: Controller: Minor clean up of redundant initialization" This reverts commit f3560c3ff5a62f3c8a90ad03cb623c2dea3c9d04. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull_central_iso.c | 10 +++++++++- subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 71b8d742a76..49ab4909e3e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -690,6 +690,15 @@ void ll_cis_create(uint16_t cis_handle, uint16_t acl_handle) /* Initialize stream states */ cis->established = 0; cis->teardown = 0; + cis->lll.event_count = LLL_CONN_ISO_EVENT_COUNT_MAX; + cis->lll.sn = 0; + cis->lll.nesn = 0; + cis->lll.cie = 0; + cis->lll.flush = LLL_CIS_FLUSH_NONE; + cis->lll.active = 0; + cis->lll.datapath_ready_rx = 0; + cis->lll.tx.bn_curr = 1U; + cis->lll.rx.bn_curr = 1U; (void)memset(&cis->hdr, 0U, sizeof(cis->hdr)); @@ -866,7 +875,6 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, #endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ cis->central.instant = instant; - cis->lll.event_count = LLL_CONN_ISO_EVENT_COUNT_MAX; cis->lll.next_subevent = 0U; cis->lll.sn = 0U; cis->lll.nesn = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index d45d89aa009..5bbac2528d0 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -259,11 +259,15 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl, cis->lll.rx.bn = req->c_bn; cis->lll.rx.ft = req->c_ft; cis->lll.rx.max_pdu = sys_le16_to_cpu(req->c_max_pdu); + cis->lll.rx.payload_count = 0; + cis->lll.rx.bn_curr = 1U; cis->lll.tx.phy = req->p_phy; cis->lll.tx.bn = req->p_bn; cis->lll.tx.ft = req->p_ft; cis->lll.tx.max_pdu = sys_le16_to_cpu(req->p_max_pdu); + cis->lll.tx.payload_count = 0; + cis->lll.tx.bn_curr = 1U; if (!cis->lll.link_tx_free) { cis->lll.link_tx_free = &cis->lll.link_tx; From 085a49d0479698b460d56dd9a16ad82094b044fd Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:12 +0000 Subject: [PATCH 0732/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix some compiler instruction re-ordering" This reverts commit f98dcccd9c67ed0c9c8e8d03e6b5fa795489ebce. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ticker/ticker.c | 1 - subsys/bluetooth/controller/util/mayfly.c | 7 ------- 2 files changed, 8 deletions(-) diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index ead148e85ba..679467d148c 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -3149,7 +3149,6 @@ void ticker_job(void *param) instance->job_guard = 0U; /* trigger worker if deferred */ - cpu_dmb(); if (instance->worker_trigger || compare_trigger) { instance->sched_cb(TICKER_CALL_ID_JOB, TICKER_CALL_ID_WORKER, 1, instance); diff --git a/subsys/bluetooth/controller/util/mayfly.c b/subsys/bluetooth/controller/util/mayfly.c index d45569c6a35..e8de3acfd80 100644 --- a/subsys/bluetooth/controller/util/mayfly.c +++ b/subsys/bluetooth/controller/util/mayfly.c @@ -6,13 +6,8 @@ */ #include - -#include #include #include - -#include "hal/cpu.h" - #include "memq.h" #include "mayfly.h" @@ -159,12 +154,10 @@ static void dequeue(uint8_t callee_id, uint8_t caller_id, memq_link_t *link, m->_link = link; /* reset mayfly state to idle */ - cpu_dmb(); ack = m->_ack; m->_ack = req; /* re-insert, if re-pended by interrupt */ - cpu_dmb(); if (((m->_req - ack) & 0x03) == 1U) { #if defined(MAYFLY_UT) printk("%s: RACE\n", __func__); From 6cc10e49b37dda5a89a83319cab82ad1804108c1 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:12 +0000 Subject: [PATCH 0733/1623] Revert "[nrf fromtree] Bluetooth: Controller: Nordic LLL: Use HAL to clear EVENTs" This reverts commit e0313b730459f788f15f9e8745f90404ccad1f28. Signed-off-by: Dominik Ermel --- .../ll_sw/nordic/hal/nrf5/radio/radio.c | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 1875dca7896..7b72b1a4b93 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -568,18 +568,18 @@ void radio_status_reset(void) * register value, PPI task will be triggered. Hence, other * EVENT_* registers are not reset to save code and CPU time. */ - nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_READY); - nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_END); + NRF_RADIO->EVENTS_READY = 0; + NRF_RADIO->EVENTS_END = 0; #if defined(CONFIG_BT_CTLR_DF_SUPPORT) && !defined(CONFIG_ZTEST) /* Clear it only for SoCs supporting DF extension */ - nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_PHYEND); - nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_CTEPRESENT); - nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_BCMATCH); + NRF_RADIO->EVENTS_PHYEND = 0; + NRF_RADIO->EVENTS_CTEPRESENT = 0; + NRF_RADIO->EVENTS_BCMATCH = 0; #endif /* CONFIG_BT_CTLR_DF_SUPPORT && !CONFIG_ZTEST */ - nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_DISABLED); + NRF_RADIO->EVENTS_DISABLED = 0; #if defined(CONFIG_BT_CTLR_PHY_CODED) #if defined(CONFIG_HAS_HW_NRF_RADIO_BLE_CODED) - nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_RATEBOOST); + NRF_RADIO->EVENTS_RATEBOOST = 0; #endif /* CONFIG_HAS_HW_NRF_RADIO_BLE_CODED */ #endif /* CONFIG_BT_CTLR_PHY_CODED */ } @@ -1019,7 +1019,7 @@ uint32_t radio_rssi_get(void) void radio_rssi_status_reset(void) { - nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_RSSIEND); + NRF_RADIO->EVENTS_RSSIEND = 0; } uint32_t radio_rssi_is_ready(void) @@ -1051,7 +1051,7 @@ void radio_filter_disable(void) void radio_filter_status_reset(void) { - nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_DEVMATCH); + NRF_RADIO->EVENTS_DEVMATCH = 0; } uint32_t radio_filter_has_match(void) @@ -1072,7 +1072,7 @@ void radio_bc_configure(uint32_t n) void radio_bc_status_reset(void) { - nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_BCMATCH); + NRF_RADIO->EVENTS_BCMATCH = 0; } uint32_t radio_bc_has_match(void) @@ -1356,7 +1356,7 @@ uint32_t radio_tmr_start_us(uint8_t trx, uint32_t start_us) start_us = (now_us << 1) - start_us; /* Setup compare event with min. 1 us offset */ - nrf_timer_event_clear(EVENT_TIMER, NRF_TIMER_EVENT_COMPARE0); + EVENT_TIMER->EVENTS_COMPARE[0] = 0U; nrf_timer_cc_set(EVENT_TIMER, 0, start_us + 1U); /* Capture the current time */ @@ -1749,9 +1749,9 @@ static void *radio_ccm_ext_rx_pkt_set(struct ccm *cnf, uint8_t phy, uint8_t pdu_ NRF_CCM->OUTPTR = (uint32_t)pkt; NRF_CCM->SCRATCHPTR = (uint32_t)_ccm_scratch; NRF_CCM->SHORTS = 0; - nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ENDKSGEN); - nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ENDCRYPT); - nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ERROR); + NRF_CCM->EVENTS_ENDKSGEN = 0; + NRF_CCM->EVENTS_ENDCRYPT = 0; + NRF_CCM->EVENTS_ERROR = 0; nrf_ccm_task_trigger(NRF_CCM, NRF_CCM_TASK_KSGEN); @@ -1820,9 +1820,9 @@ static void *radio_ccm_ext_tx_pkt_set(struct ccm *cnf, uint8_t pdu_type, void *p NRF_CCM->OUTPTR = (uint32_t)_pkt_scratch; NRF_CCM->SCRATCHPTR = (uint32_t)_ccm_scratch; NRF_CCM->SHORTS = CCM_SHORTS_ENDKSGEN_CRYPT_Msk; - nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ENDKSGEN); - nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ENDCRYPT); - nrf_ccm_event_clear(NRF_CCM, NRF_CCM_EVENT_ERROR); + NRF_CCM->EVENTS_ENDKSGEN = 0; + NRF_CCM->EVENTS_ENDCRYPT = 0; + NRF_CCM->EVENTS_ERROR = 0; nrf_ccm_task_trigger(NRF_CCM, NRF_CCM_TASK_KSGEN); @@ -1899,9 +1899,9 @@ void radio_ar_configure(uint32_t nirk, void *irk, uint8_t flags) NRF_AAR->ADDRPTR = addrptr; NRF_AAR->SCRATCHPTR = (uint32_t)&_aar_scratch[0]; - nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_END); - nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_RESOLVED); - nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_NOTRESOLVED); + NRF_AAR->EVENTS_END = 0; + NRF_AAR->EVENTS_RESOLVED = 0; + NRF_AAR->EVENTS_NOTRESOLVED = 0; radio_bc_configure(bcc); radio_bc_status_reset(); @@ -1957,9 +1957,9 @@ uint8_t radio_ar_resolve(const uint8_t *addr) NRF_AAR->ADDRPTR = (uint32_t)addr - 3; - nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_END); - nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_RESOLVED); - nrf_aar_event_clear(NRF_AAR, NRF_AAR_EVENT_NOTRESOLVED); + NRF_AAR->EVENTS_END = 0; + NRF_AAR->EVENTS_RESOLVED = 0; + NRF_AAR->EVENTS_NOTRESOLVED = 0; NVIC_ClearPendingIRQ(nrfx_get_irq_number(NRF_AAR)); From 333f27be4189911c038148bced6c3a54c2343589 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:12 +0000 Subject: [PATCH 0734/1623] Revert "[nrf fromtree] Bluetooth: Controller: Nordic LLL: Use HAL to clear RTC event" This reverts commit c5545cd918742435c48186f39e70fe806a037c0d. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index 1f8031a7c07..bc71bbcd5a6 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -8,8 +8,6 @@ #include #include -#include - #include #include @@ -108,7 +106,7 @@ static void rtc0_nrf5_isr(const void *arg) /* On compare0 run ticker worker instance0 */ if (NRF_RTC0->EVENTS_COMPARE[0]) { - nrf_rtc_event_clear(NRF_RTC0, NRF_RTC_EVENT_COMPARE_0); + NRF_RTC0->EVENTS_COMPARE[0] = 0; ticker_trigger(0); } From 2f267a736ebb5be0cba1b84b9dcc4f6a9fddb3b7 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:12 +0000 Subject: [PATCH 0735/1623] Revert "[nrf fromtree] Bluetooth: controller: Introduce config for avoiding SDU fragmentation" This reverts commit 78ec3b1294a711606b8302f3f95eef0a7095cb51. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/Kconfig | 11 ---- .../controller/ll_sw/ull_central_iso.c | 59 +++++-------------- 2 files changed, 14 insertions(+), 56 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 599a241b84b..0818ae03a3b 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -914,17 +914,6 @@ config BT_CTLR_CONN_ISO_STREAMS_MAX_FT help Maximum number of CIS flush timeout events. -config BT_CTLR_CONN_ISO_AVOID_SEGMENTATION - bool "Avoid SDU fragmentation for framed mode" - depends on BT_CTLR_CENTRAL_ISO - help - When creating a CIG, the Max_PDU size is calculated according to BT - Core 5.4 Vol 6, Part G, Section 2.2. However, HAP specifies a need for - avoiding segmentation by forcing the Max_PDU to the appropriate value. - Since there is no way to control the Max_PDU using the non-test - interface, the config provides a way to force the Max_PDU to Max_SDU + - 5 (header + offset). - config BT_CTLR_ISO bool default BT_CTLR_BROADCAST_ISO || BT_CTLR_CONN_ISO diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 49ab4909e3e..0c7a8e5ef35 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -234,15 +234,6 @@ uint8_t ll_cig_parameters_commit(uint8_t cig_id, uint16_t *handles) cig->iso_interval = BT_HCI_ISO_INTERVAL_MIN; } -#if defined(CONFIG_BT_CTLR_CONN_ISO_AVOID_SEGMENTATION) - /* Check if this is a HAP usecase which requires higher link bandwidth to ensure - * segmentation is not invoked in ISO-AL. - */ - if (cig->central.framing && cig->c_sdu_interval == 10000U) { - cig->iso_interval = 6; /* 7500 us */ - } -#endif - if (!cig->central.framing && (cig->c_sdu_interval % ISO_INT_UNIT_US)) { /* Framing not requested but requirement for unframed is not met. Force * CIG into framed mode. @@ -1140,51 +1131,29 @@ static void set_bn_max_pdu(bool framed, uint32_t iso_interval, uint8_t *max_pdu) { if (framed) { - uint32_t max_drift_us; + uint32_t ceil_f_x_max_sdu; + uint16_t max_pdu_bn1; + uint32_t max_drift; uint32_t ceil_f; - /* BT Core 5.4 Vol 6, Part G, Section 2.2: + /* Framed (From ES-18002): * Max_PDU >= ((ceil(F) x 5 + ceil(F x Max_SDU)) / BN) + 2 * F = (1 + MaxDrift) x ISO_Interval / SDU_Interval * SegmentationHeader + TimeOffset = 5 bytes * Continuation header = 2 bytes * MaxDrift (Max. allowed SDU delivery timing drift) = 100 ppm */ - max_drift_us = DIV_ROUND_UP(SDU_MAX_DRIFT_PPM * sdu_interval, USEC_PER_SEC); - ceil_f = DIV_ROUND_UP((USEC_PER_SEC + max_drift_us) * (uint64_t)iso_interval, - USEC_PER_SEC * (uint64_t)sdu_interval); - if (false) { -#if defined(CONFIG_BT_CTLR_CONN_ISO_AVOID_SEGMENTATION) - /* To avoid segmentation according to HAP, if the ISO_Interval is less than - * the SDU_Interval, we assume BN=1 and calculate the Max_PDU as: - * Max_PDU = celi(F / BN) x (5 / Max_SDU) - * - * This is in accordance with the "Core enhancement for ISOAL CR". - * - * This ensures that the drift can be contained in the difference between - * SDU_Interval and link bandwidth. For BN=1, ceil(F) == ceil(F/BN). - */ - } else if (iso_interval < sdu_interval) { - *bn = 1; - *max_pdu = ceil_f * (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE + - max_sdu); -#endif - } else { - uint32_t ceil_f_x_max_sdu; - uint16_t max_pdu_bn1; - - ceil_f_x_max_sdu = DIV_ROUND_UP(max_sdu * ((USEC_PER_SEC + max_drift_us) * - (uint64_t)iso_interval), - USEC_PER_SEC * (uint64_t)sdu_interval); + max_drift = DIV_ROUND_UP(SDU_MAX_DRIFT_PPM * sdu_interval, 1000000U); + ceil_f = DIV_ROUND_UP(iso_interval + max_drift, sdu_interval); + ceil_f_x_max_sdu = DIV_ROUND_UP(max_sdu * (iso_interval + max_drift), + sdu_interval); - /* Strategy: Keep lowest possible BN. - * TODO: Implement other strategies, possibly as policies. - */ - max_pdu_bn1 = ceil_f * (PDU_ISO_SEG_HDR_SIZE + - PDU_ISO_SEG_TIMEOFFSET_SIZE) + ceil_f_x_max_sdu; - *bn = DIV_ROUND_UP(max_pdu_bn1, LL_CIS_OCTETS_TX_MAX); - *max_pdu = DIV_ROUND_UP(max_pdu_bn1, *bn) + PDU_ISO_SEG_HDR_SIZE; - } + /* Strategy: Keep lowest possible BN. + * TODO: Implement other strategies, possibly as policies. + */ + max_pdu_bn1 = ceil_f * 5 + ceil_f_x_max_sdu; + *bn = DIV_ROUND_UP(max_pdu_bn1, LL_CIS_OCTETS_TX_MAX); + *max_pdu = DIV_ROUND_UP(max_pdu_bn1, *bn) + 2; } else { /* For unframed, ISO_Interval must be N x SDU_Interval */ LL_ASSERT(iso_interval % sdu_interval == 0); From f476efa5d5119a44cc44811a6ea2a7629d380410 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:13 +0000 Subject: [PATCH 0736/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Reset targets state before starting DFU on DFD srv" This reverts commit 7baae6c87ada53b681730c226d58a37a8ed6c382. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/dfd_srv.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 5d3ada4b4aa..59fe5b830d1 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -1015,13 +1015,6 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_start(struct bt_mesh_dfd_srv *srv, sys_slist_init(&srv->inputs.targets); for (i = 0; i < srv->target_cnt; i++) { - uint16_t addr = srv->targets[i].blob.addr; - - memset(&srv->targets[i].blob, 0, sizeof(struct bt_mesh_blob_target)); - memset(&srv->pull_ctxs[i], 0, sizeof(struct bt_mesh_blob_target_pull)); - srv->targets[i].blob.addr = addr; - srv->targets[i].blob.pull = &srv->pull_ctxs[i]; - sys_slist_append(&srv->inputs.targets, &srv->targets[i].blob.n); } From e46bbca13848e34559e848ff91bc650599578375 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:13 +0000 Subject: [PATCH 0737/1623] Revert "[nrf fromtree] Bluetooth: mesh: access: Fix model relation register" This reverts commit 0a1f19bfdc8b030f67b8b2ac0c499dc06d2d64d1. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/access.c | 92 +++++++++++++--------------------- 1 file changed, 36 insertions(+), 56 deletions(-) diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 63c4f76c392..2ea7ece90df 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -91,13 +91,17 @@ static struct mod_relation mod_rel_list[MOD_REL_LIST_SIZE]; mod_rel_list[(idx)].idx_ext == 0); \ (idx)++) -#define IS_MOD_BASE(mod, idx, offset) \ +#define IS_MOD_BASE(mod, idx) \ (mod_rel_list[(idx)].elem_base == (mod)->elem_idx && \ - mod_rel_list[(idx)].idx_base == (mod)->mod_idx + (offset)) + mod_rel_list[(idx)].idx_base == (mod)->mod_idx && \ + !(mod_rel_list[(idx)].elem_ext != (mod)->elem_idx && \ + mod_rel_list[(idx)].idx_ext != (mod)->mod_idx)) -#define IS_MOD_EXTENSION(mod, idx, offset) \ +#define IS_MOD_EXTENSION(mod, idx) \ (mod_rel_list[(idx)].elem_ext == (mod)->elem_idx && \ - mod_rel_list[(idx)].idx_ext == (mod)->mod_idx + (offset)) + mod_rel_list[(idx)].idx_ext == (mod)->mod_idx && \ + !(mod_rel_list[(idx)].elem_base != (mod)->elem_idx && \ + mod_rel_list[(idx)].idx_base != (mod)->mod_idx)) #define RELATION_TYPE_EXT 0xFF @@ -452,14 +456,14 @@ int bt_mesh_comp_data_get_page_0(struct net_buf_simple *buf, size_t offset) return 0; } -static uint8_t count_mod_ext(struct bt_mesh_model *mod, uint8_t *max_offset, uint8_t sig_offset) +static uint8_t count_mod_ext(struct bt_mesh_model *mod, uint8_t *max_offset) { int i; uint8_t extensions = 0; int8_t offset, offset_record = 0; MOD_REL_LIST_FOR_EACH(i) { - if (IS_MOD_EXTENSION(mod, i, sig_offset) && + if (IS_MOD_EXTENSION(mod, i) && mod_rel_list[i].type == RELATION_TYPE_EXT) { extensions++; offset = mod_rel_list[i].elem_ext - @@ -476,18 +480,17 @@ static uint8_t count_mod_ext(struct bt_mesh_model *mod, uint8_t *max_offset, uin return extensions; } -static bool is_cor_present(struct bt_mesh_model *mod, uint8_t *cor_id, uint8_t sig_offset) +static bool is_cor_present(struct bt_mesh_model *mod, uint8_t *cor_id) { int i; - MOD_REL_LIST_FOR_EACH(i) - { - if ((IS_MOD_BASE(mod, i, sig_offset) || - IS_MOD_EXTENSION(mod, i, sig_offset)) && + MOD_REL_LIST_FOR_EACH(i) { + if ((IS_MOD_BASE(mod, i) || IS_MOD_EXTENSION(mod, i)) && mod_rel_list[i].type < RELATION_TYPE_EXT) { if (cor_id) { memcpy(cor_id, &mod_rel_list[i].type, sizeof(uint8_t)); } + return true; } } @@ -495,15 +498,15 @@ static bool is_cor_present(struct bt_mesh_model *mod, uint8_t *cor_id, uint8_t s } static void prep_model_item_header(struct bt_mesh_model *mod, uint8_t *cor_id, uint8_t *mod_cnt, - struct net_buf_simple *buf, size_t *offset, uint8_t sig_offset) + struct net_buf_simple *buf, size_t *offset) { uint8_t ext_mod_cnt; bool cor_present; uint8_t mod_elem_info = 0; int8_t max_offset; - ext_mod_cnt = count_mod_ext(mod, &max_offset, sig_offset); - cor_present = is_cor_present(mod, cor_id, sig_offset); + ext_mod_cnt = count_mod_ext(mod, &max_offset); + cor_present = is_cor_present(mod, cor_id); mod_elem_info = ext_mod_cnt << 2; if (ext_mod_cnt > 31 || @@ -523,14 +526,13 @@ static void prep_model_item_header(struct bt_mesh_model *mod, uint8_t *cor_id, u } static void add_items_to_page(struct net_buf_simple *buf, struct bt_mesh_model *mod, - uint8_t ext_mod_cnt, size_t *offset, uint8_t sig_offset) + uint8_t ext_mod_cnt, size_t *offset) { int i, elem_offset; uint8_t mod_idx; MOD_REL_LIST_FOR_EACH(i) { - if (IS_MOD_EXTENSION(mod, i, sig_offset) && - mod_rel_list[i].type == RELATION_TYPE_EXT) { + if (IS_MOD_EXTENSION(mod, i)) { elem_offset = mod->elem_idx - mod_rel_list[i].elem_base; mod_idx = mod_rel_list[i].idx_base; if (ext_mod_cnt < 32 && @@ -555,18 +557,18 @@ static void add_items_to_page(struct net_buf_simple *buf, struct bt_mesh_model * } } -static size_t mod_items_size(struct bt_mesh_model *mod, uint8_t sig_offset) +static size_t mod_items_size(struct bt_mesh_model *mod) { int i, offset; size_t temp_size = 0; - int ext_mod_cnt = count_mod_ext(mod, NULL, sig_offset); + int ext_mod_cnt = count_mod_ext(mod, NULL); if (!ext_mod_cnt) { return 0; } MOD_REL_LIST_FOR_EACH(i) { - if (IS_MOD_EXTENSION(mod, i, sig_offset)) { + if (IS_MOD_EXTENSION(mod, i)) { offset = mod->elem_idx - mod_rel_list[i].elem_base; temp_size += (ext_mod_cnt < 32 && offset < 4 && offset > -5) ? 1 : 2; } @@ -580,13 +582,13 @@ static size_t page1_elem_size(struct bt_mesh_elem *elem) size_t temp_size = 2; for (int i = 0; i < elem->model_count; i++) { - temp_size += is_cor_present(&elem->models[i], NULL, 0) ? 2 : 1; - temp_size += mod_items_size(&elem->models[i], 0); + temp_size += is_cor_present(&elem->models[i], NULL) ? 2 : 1; + temp_size += mod_items_size(&elem->models[i]); } for (int i = 0; i < elem->vnd_model_count; i++) { - temp_size += is_cor_present(&elem->vnd_models[i], NULL, elem->model_count) ? 2 : 1; - temp_size += mod_items_size(&elem->vnd_models[i], elem->model_count); + temp_size += is_cor_present(&elem->vnd_models[i], NULL) ? 2 : 1; + temp_size += mod_items_size(&elem->vnd_models[i]); } return temp_size; @@ -628,22 +630,19 @@ static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf, size_t offse data_buf_add_u8_offset(buf, comp->elem[i].vnd_model_count, &offset); for (j = 0; j < comp->elem[i].model_count; j++) { prep_model_item_header(&comp->elem[i].models[j], &cor_id, &ext_mod_cnt, buf, - &offset, 0); + &offset); if (ext_mod_cnt != 0) { add_items_to_page(buf, &comp->elem[i].models[j], ext_mod_cnt, - &offset, - 0); + &offset); } } for (j = 0; j < comp->elem[i].vnd_model_count; j++) { prep_model_item_header(&comp->elem[i].vnd_models[j], &cor_id, &ext_mod_cnt, - buf, &offset, - comp->elem[i].model_count); + buf, &offset); if (ext_mod_cnt != 0) { add_items_to_page(buf, &comp->elem[i].vnd_models[j], ext_mod_cnt, - &offset, - comp->elem[i].model_count); + &offset); } } } @@ -1617,22 +1616,6 @@ void bt_mesh_model_extensions_walk(struct bt_mesh_model *model, } #ifdef CONFIG_BT_MESH_MODEL_EXTENSIONS -/* For vendor models, determine the offset within the model relation list - * by counting the number of standard SIG models in the associated element. - */ -static uint8_t get_sig_offset(struct bt_mesh_model *mod) -{ - const struct bt_mesh_elem *elem = bt_mesh_model_elem(mod); - uint8_t i; - - for (i = 0U; i < elem->vnd_model_count; i++) { - if (&elem->vnd_models[i] == mod) { - return elem->model_count; - } - } - return 0; -} - static int mod_rel_register(struct bt_mesh_model *base, struct bt_mesh_model *ext, uint8_t type) @@ -1640,9 +1623,9 @@ static int mod_rel_register(struct bt_mesh_model *base, LOG_DBG(""); struct mod_relation extension = { base->elem_idx, - base->mod_idx + get_sig_offset(base), + base->mod_idx, ext->elem_idx, - ext->mod_idx + get_sig_offset(ext), + ext->mod_idx, type, }; int i; @@ -1713,19 +1696,16 @@ int bt_mesh_model_correspond(struct bt_mesh_model *corresponding_mod, return -ENOTSUP; } - uint8_t base_offset = get_sig_offset(base_mod); - uint8_t corresponding_offset = get_sig_offset(corresponding_mod); - MOD_REL_LIST_FOR_EACH(i) { if (mod_rel_list[i].type < RELATION_TYPE_EXT && mod_rel_list[i].type > cor_id) { cor_id = mod_rel_list[i].type; } - if ((IS_MOD_BASE(base_mod, i, base_offset) || - IS_MOD_EXTENSION(base_mod, i, base_offset) || - IS_MOD_BASE(corresponding_mod, i, corresponding_offset) || - IS_MOD_EXTENSION(corresponding_mod, i, corresponding_offset)) && + if ((IS_MOD_BASE(base_mod, i) || + IS_MOD_EXTENSION(base_mod, i) || + IS_MOD_BASE(corresponding_mod, i) || + IS_MOD_EXTENSION(corresponding_mod, i)) && mod_rel_list[i].type < RELATION_TYPE_EXT) { return mod_rel_register(base_mod, corresponding_mod, mod_rel_list[i].type); } From 7c5279307360c2f5c3b7a432ff916ce65ebb487f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:13 +0000 Subject: [PATCH 0738/1623] Revert "[nrf fromtree] Bluetooth: mesh: Change cfg_cli buffer length check" This reverts commit 3aa391df864261dbb6c527265634dfdb02682ccd. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/cfg_cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/cfg_cli.c b/subsys/bluetooth/mesh/cfg_cli.c index c9f4f98f39d..68af4fae59d 100644 --- a/subsys/bluetooth/mesh/cfg_cli.c +++ b/subsys/bluetooth/mesh/cfg_cli.c @@ -2320,7 +2320,7 @@ struct bt_mesh_mod_id_vnd bt_mesh_comp_p0_elem_mod_vnd(struct bt_mesh_comp_p0_el struct bt_mesh_comp_p1_elem *bt_mesh_comp_p1_elem_pull(struct net_buf_simple *buf, struct bt_mesh_comp_p1_elem *elem) { - if (buf->len < 4) { + if (buf->len < 6) { LOG_DBG("No more elements to pull or missing data"); return NULL; } From f3304473f9cc245d6decfd5d2193c131fab19661 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:13 +0000 Subject: [PATCH 0739/1623] Revert "[nrf fromtree] tests: bluetooth: tester: Fix prov ctx init in PTS tests" This reverts commit 2da2829689578d541ec3cd43e4e35a6644d385b5. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp/btp_mesh.h | 2 -- tests/bluetooth/tester/src/btp_mesh.c | 13 ------------- 2 files changed, 15 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index b5ab169b263..c2636d1445d 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -1038,8 +1038,6 @@ struct btp_proxy_solicit_cmd { uint16_t net_idx; } __packed; -#define BTP_MESH_START 0x78 - /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 662dca238c1..c191ed54568 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1305,14 +1305,6 @@ static uint8_t init(const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } - return BTP_STATUS_SUCCESS; -} - -static uint8_t start(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - int err; - LOG_DBG(""); if (IS_ENABLED(CONFIG_BT_SETTINGS)) { @@ -4969,11 +4961,6 @@ static const struct btp_handler handlers[] = { .func = proxy_solicit }, #endif - { - .opcode = BTP_MESH_START, - .expect_len = 0, - .func = start - }, }; From 32925c686319dea78806e8fdb28675a6ba64492a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:14 +0000 Subject: [PATCH 0740/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Don't reset mod pointer" This reverts commit 598c6d18cfb77ca4aa47e8699e830a1dce1cea05. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/rpr_srv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/bluetooth/mesh/rpr_srv.c b/subsys/bluetooth/mesh/rpr_srv.c index 8fb28e56472..c8639d8b514 100644 --- a/subsys/bluetooth/mesh/rpr_srv.c +++ b/subsys/bluetooth/mesh/rpr_srv.c @@ -1337,6 +1337,7 @@ static void rpr_srv_reset(struct bt_mesh_model *mod) atomic_clear(srv.flags); srv.link.dev = NULL; srv.scan.dev = NULL; + srv.mod = NULL; } const struct bt_mesh_model_cb _bt_mesh_rpr_srv_cb = { From b5cdabfb1132b9c925eb76f8d92054155ce76f69 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:14 +0000 Subject: [PATCH 0741/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Common comp page parse func" This reverts commit 688605c9b2174c0086e86c235b0377d54ff0b09a. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/access.c | 27 --------------------- subsys/bluetooth/mesh/access.h | 1 - subsys/bluetooth/mesh/cfg_srv.c | 22 ++++++++++++++++- subsys/bluetooth/mesh/large_comp_data_srv.c | 22 ++++++++++++++++- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 2ea7ece90df..24259165e05 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -2562,30 +2562,3 @@ void bt_mesh_model_data_store_schedule(struct bt_mesh_model *mod) mod->flags |= BT_MESH_MOD_DATA_PENDING; bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_MOD_PENDING); } - -uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf) -{ - uint8_t page = net_buf_simple_pull_u8(buf); - - if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 130U; - } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 129U; - } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 128U; - } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { - page = 2U; - } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { - page = 1U; - } else if (page != 0U) { - LOG_DBG("Composition page %u not available", page); - page = 0U; - } - - return page; -} diff --git a/subsys/bluetooth/mesh/access.h b/subsys/bluetooth/mesh/access.h index f58c6f1d449..6027768ea94 100644 --- a/subsys/bluetooth/mesh/access.h +++ b/subsys/bluetooth/mesh/access.h @@ -64,7 +64,6 @@ int bt_mesh_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf); int bt_mesh_comp_register(const struct bt_mesh_comp *comp); int bt_mesh_comp_store(void); int bt_mesh_comp_read(struct net_buf_simple *buf, uint8_t page); -uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf); int bt_mesh_models_metadata_store(void); int bt_mesh_models_metadata_read(struct net_buf_simple *buf, size_t offset); diff --git a/subsys/bluetooth/mesh/cfg_srv.c b/subsys/bluetooth/mesh/cfg_srv.c index f65d2cba3c7..eb732a34910 100644 --- a/subsys/bluetooth/mesh/cfg_srv.c +++ b/subsys/bluetooth/mesh/cfg_srv.c @@ -59,7 +59,27 @@ static int dev_comp_data_get(struct bt_mesh_model *model, LOG_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, bt_hex(buf->data, buf->len)); - page = bt_mesh_comp_parse_page(buf); + page = net_buf_simple_pull_u8(buf); + + if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && + (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 130U; + } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && + (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 129U; + } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 128U; + } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { + page = 2U; + } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { + page = 1U; + } else if (page != 0U) { + LOG_DBG("Composition page %u not available", page); + page = 0U; + } LOG_DBG("Preparing Composition data page %d", page); bt_mesh_model_msg_init(&sdu, OP_DEV_COMP_DATA_STATUS); diff --git a/subsys/bluetooth/mesh/large_comp_data_srv.c b/subsys/bluetooth/mesh/large_comp_data_srv.c index 4ee591d9efd..12497d053a2 100644 --- a/subsys/bluetooth/mesh/large_comp_data_srv.c +++ b/subsys/bluetooth/mesh/large_comp_data_srv.c @@ -53,12 +53,32 @@ static int handle_large_comp_data_get(struct bt_mesh_model *model, struct bt_mes ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, bt_hex(buf->data, buf->len)); - page = bt_mesh_comp_parse_page(buf); + page = net_buf_simple_pull_u8(buf); offset = net_buf_simple_pull_le16(buf); LOG_DBG("page %u offset %u", page, offset); bt_mesh_model_msg_init(&rsp, OP_LARGE_COMP_DATA_STATUS); + if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && + (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 130U; + } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && + (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 129U; + } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 128U; + } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { + page = 2U; + } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { + page = 1U; + } else if (page != 0U) { + LOG_DBG("Composition page %u not available", page); + page = 0U; + } + net_buf_simple_add_u8(&rsp, page); net_buf_simple_add_le16(&rsp, offset); From 9b227abf5cd73b579884f05135f9edf5a04e142f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:14 +0000 Subject: [PATCH 0742/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Add missing comp pages to LCD mod" This reverts commit 14095d899da44030014ce550dcc2b7fb4b910d08. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/Kconfig | 10 - subsys/bluetooth/mesh/access.c | 228 ++++++++------------ subsys/bluetooth/mesh/access.h | 2 +- subsys/bluetooth/mesh/large_comp_data_srv.c | 53 +---- 4 files changed, 94 insertions(+), 199 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 605e4608be7..9f24ff81975 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1375,16 +1375,6 @@ config BT_MESH_PRIV_BEACON_CLI endif # BT_MESH_PRIV_BEACONS -config BT_MESH_COMP_PST_BUF_SIZE - int "Composition Data Page persistence buffer size" - default 100 - help - Stack allocated buffer used to temporarily hold Composition - Data Pages during flash operations. Should reflect the size - of the largest Composition Data Page present in the application. - Note that this buffer should still be large enough to restore previously stored - pages after a performed device firmware update. - config BT_MESH_COMP_PAGE_1 bool "Support for Composition Data Page 1" depends on BT_MESH_MODEL_EXTENSIONS diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 24259165e05..b6dab2d67a7 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -173,18 +173,6 @@ static void data_buf_add_le16_offset(struct net_buf_simple *buf, } } -static void data_buf_add_mem_offset(struct net_buf_simple *buf, uint8_t *data, size_t len, - size_t *offset) -{ - if (*offset >= len) { - *offset -= len; - return; - } - - net_buf_simple_add_mem(buf, data + *offset, len - *offset); - *offset = 0; -} - static void comp_add_model(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, bool vnd, void *user_data) { @@ -199,6 +187,20 @@ static void comp_add_model(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, } #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV) +static void data_buf_add_mem_offset(struct net_buf_simple *buf, + const void *mem, size_t len, + size_t *offset) +{ + if (*offset >= len) { + *offset -= len; + return; + } else if (*offset > 0) { + net_buf_simple_add_mem(buf, ((uint8_t *)mem), (len - *offset)); + + } else { + net_buf_simple_add_mem(buf, mem, len); + } +} static size_t metadata_model_size(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, bool vnd) @@ -364,6 +366,23 @@ int bt_mesh_metadata_get_page_0(struct net_buf_simple *buf, size_t offset) } #endif +size_t bt_mesh_comp_page_0_size(void) +{ + const struct bt_mesh_comp *comp; + const struct bt_mesh_elem *elem; + size_t size = 10; + int i; + + comp = bt_mesh_comp_get(); + + for (i = 0; i < comp->elem_count; i++) { + elem = &comp->elem[i]; + size += bt_mesh_comp_elem_size(elem); + } + + return size; +} + static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem, size_t *offset) { @@ -379,7 +398,7 @@ static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem, return 0; } - if (net_buf_simple_tailroom(buf) < ((elem_size - *offset) + BT_MESH_MIC_SHORT)) { + if (net_buf_simple_tailroom(buf) < (elem_size + BT_MESH_MIC_SHORT)) { if (IS_ENABLED(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)) { /* Mesh Profile 1.1 Section 4.4.1.2.2: * If the complete list of models does not fit in the Data field, @@ -497,8 +516,8 @@ static bool is_cor_present(struct bt_mesh_model *mod, uint8_t *cor_id) return false; } -static void prep_model_item_header(struct bt_mesh_model *mod, uint8_t *cor_id, uint8_t *mod_cnt, - struct net_buf_simple *buf, size_t *offset) +static void prep_model_item_header(struct bt_mesh_model *mod, uint8_t *cor_id, + uint8_t *mod_cnt, struct net_buf_simple *buf) { uint8_t ext_mod_cnt; bool cor_present; @@ -517,41 +536,41 @@ static void prep_model_item_header(struct bt_mesh_model *mod, uint8_t *cor_id, u if (cor_present) { mod_elem_info |= BIT(0); } - data_buf_add_u8_offset(buf, mod_elem_info, offset); + net_buf_simple_add_u8(buf, mod_elem_info); if (cor_present) { - data_buf_add_u8_offset(buf, *cor_id, offset); + net_buf_simple_add_u8(buf, *cor_id); } memset(mod_cnt, ext_mod_cnt, sizeof(uint8_t)); } static void add_items_to_page(struct net_buf_simple *buf, struct bt_mesh_model *mod, - uint8_t ext_mod_cnt, size_t *offset) + uint8_t ext_mod_cnt) { - int i, elem_offset; + int i, offset; uint8_t mod_idx; MOD_REL_LIST_FOR_EACH(i) { if (IS_MOD_EXTENSION(mod, i)) { - elem_offset = mod->elem_idx - mod_rel_list[i].elem_base; + offset = mod->elem_idx - mod_rel_list[i].elem_base; mod_idx = mod_rel_list[i].idx_base; if (ext_mod_cnt < 32 && - elem_offset < 4 && - elem_offset > -5) { + offset < 4 && + offset > -5) { /* short format */ - if (elem_offset < 0) { - elem_offset += 8; + if (offset < 0) { + offset += 8; } - elem_offset |= mod_idx << 3; - data_buf_add_u8_offset(buf, elem_offset, offset); + offset |= mod_idx << 3; + net_buf_simple_add_u8(buf, offset); } else { /* long format */ - if (elem_offset < 0) { - elem_offset += 256; + if (offset < 0) { + offset += 256; } - data_buf_add_u8_offset(buf, elem_offset, offset); - data_buf_add_u8_offset(buf, mod_idx, offset); + net_buf_simple_add_u8(buf, offset); + net_buf_simple_add_u8(buf, mod_idx); } } } @@ -594,7 +613,7 @@ static size_t page1_elem_size(struct bt_mesh_elem *elem) return temp_size; } -static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf, size_t offset) +static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf) { const struct bt_mesh_comp *comp; uint8_t cor_id = 0; @@ -604,14 +623,8 @@ static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf, size_t offse comp = bt_mesh_comp_get(); for (i = 0; i < comp->elem_count; i++) { - size_t elem_size = page1_elem_size(&comp->elem[i]); - - if (offset >= elem_size) { - offset -= elem_size; - continue; - } - - if (net_buf_simple_tailroom(buf) < ((elem_size - offset) + BT_MESH_MIC_SHORT)) { + if (net_buf_simple_tailroom(buf) < + (page1_elem_size(&comp->elem[i]) + BT_MESH_MIC_SHORT)) { if (IS_ENABLED(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)) { /* Mesh Profile 1.1 Section 4.4.1.2.2: * If the complete list of models does not fit in the Data field, @@ -626,53 +639,49 @@ static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf, size_t offse return -E2BIG; } - data_buf_add_u8_offset(buf, comp->elem[i].model_count, &offset); - data_buf_add_u8_offset(buf, comp->elem[i].vnd_model_count, &offset); + net_buf_simple_add_u8(buf, comp->elem[i].model_count); + net_buf_simple_add_u8(buf, comp->elem[i].vnd_model_count); for (j = 0; j < comp->elem[i].model_count; j++) { - prep_model_item_header(&comp->elem[i].models[j], &cor_id, &ext_mod_cnt, buf, - &offset); + prep_model_item_header(&comp->elem[i].models[j], + &cor_id, &ext_mod_cnt, buf); if (ext_mod_cnt != 0) { - add_items_to_page(buf, &comp->elem[i].models[j], ext_mod_cnt, - &offset); + add_items_to_page(buf, + &comp->elem[i].models[j], + ext_mod_cnt); } } for (j = 0; j < comp->elem[i].vnd_model_count; j++) { - prep_model_item_header(&comp->elem[i].vnd_models[j], &cor_id, &ext_mod_cnt, - buf, &offset); + prep_model_item_header(&comp->elem[i].vnd_models[j], + &cor_id, &ext_mod_cnt, buf); if (ext_mod_cnt != 0) { - add_items_to_page(buf, &comp->elem[i].vnd_models[j], ext_mod_cnt, - &offset); + add_items_to_page(buf, + &comp->elem[i].vnd_models[j], + ext_mod_cnt); } } } return 0; } -static int bt_mesh_comp_data_get_page_2(struct net_buf_simple *buf, size_t offset) +static int bt_mesh_comp_data_get_page_2(struct net_buf_simple *buf) { if (!dev_comp2) { LOG_ERR("Composition data P2 not registered"); return -ENODEV; } - size_t elem_size; - for (int i = 0; i < dev_comp2->record_cnt; i++) { - elem_size = - 8 + dev_comp2->record[i].elem_offset_cnt + dev_comp2->record[i].data_len; - if (offset >= elem_size) { - offset -= elem_size; - continue; - } - - if (net_buf_simple_tailroom(buf) < ((elem_size - offset) + BT_MESH_MIC_SHORT)) { + if (net_buf_simple_tailroom(buf) < + (8 + dev_comp2->record[i].elem_offset_cnt + dev_comp2->record[i].data_len + + BT_MESH_MIC_SHORT)) { if (IS_ENABLED(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)) { /* Mesh Profile 1.1 Section 4.4.1.2.2: * If the complete list of models does not fit in the Data field, * the element shall not be reported. */ - LOG_DBG("Record 0x%04x didn't fit in the Data field", i); + LOG_DBG("Record 0x%04x didn't fit in the Data field", + i); return 0; } @@ -680,20 +689,20 @@ static int bt_mesh_comp_data_get_page_2(struct net_buf_simple *buf, size_t offse return -E2BIG; } - data_buf_add_le16_offset(buf, dev_comp2->record[i].id, &offset); - data_buf_add_u8_offset(buf, dev_comp2->record[i].version.x, &offset); - data_buf_add_u8_offset(buf, dev_comp2->record[i].version.y, &offset); - data_buf_add_u8_offset(buf, dev_comp2->record[i].version.z, &offset); - data_buf_add_u8_offset(buf, dev_comp2->record[i].elem_offset_cnt, &offset); + net_buf_simple_add_le16(buf, dev_comp2->record[i].id); + net_buf_simple_add_u8(buf, dev_comp2->record[i].version.x); + net_buf_simple_add_u8(buf, dev_comp2->record[i].version.y); + net_buf_simple_add_u8(buf, dev_comp2->record[i].version.z); + net_buf_simple_add_u8(buf, dev_comp2->record[i].elem_offset_cnt); if (dev_comp2->record[i].elem_offset_cnt) { - data_buf_add_mem_offset(buf, (uint8_t *)dev_comp2->record[i].elem_offset, - dev_comp2->record[i].elem_offset_cnt, &offset); + net_buf_simple_add_mem(buf, dev_comp2->record[i].elem_offset, + dev_comp2->record[i].elem_offset_cnt); } - data_buf_add_le16_offset(buf, dev_comp2->record[i].data_len, &offset); + net_buf_simple_add_le16(buf, dev_comp2->record[i].data_len); if (dev_comp2->record[i].data_len) { - data_buf_add_mem_offset(buf, (uint8_t *)dev_comp2->record[i].data, - dev_comp2->record[i].data_len, &offset); + net_buf_simple_add_mem(buf, dev_comp2->record[i].data, + dev_comp2->record[i].data_len); } } @@ -2203,89 +2212,20 @@ int bt_mesh_comp_data_get_page(struct net_buf_simple *buf, size_t page, size_t o if (page == 0 || page == 128) { return bt_mesh_comp_data_get_page_0(buf, offset); } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && (page == 1 || page == 129)) { - return bt_mesh_comp_data_get_page_1(buf, offset); + return bt_mesh_comp_data_get_page_1(buf); } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && (page == 2 || page == 130)) { - return bt_mesh_comp_data_get_page_2(buf, offset); + return bt_mesh_comp_data_get_page_2(buf); } return -EINVAL; } -size_t comp_page_0_size(void) -{ - const struct bt_mesh_comp *comp; - const struct bt_mesh_elem *elem; - size_t size = 10; /* Non-variable length params of comp page 0. */ - - comp = bt_mesh_comp_get(); - - for (int i = 0; i < comp->elem_count; i++) { - elem = &comp->elem[i]; - size += bt_mesh_comp_elem_size(elem); - } - - return size; -} - -size_t comp_page_1_size(void) -{ - const struct bt_mesh_comp *comp; - size_t size = 0; - - comp = bt_mesh_comp_get(); - - for (int i = 0; i < comp->elem_count; i++) { - - size += page1_elem_size(&comp->elem[i]); - } - - return size; -} - -size_t comp_page_2_size(void) -{ - size_t size = 0; - - if (!dev_comp2) { - LOG_ERR("Composition data P2 not registered"); - return size; - } - - for (int i = 0; i < dev_comp2->record_cnt; i++) { - size += 8 + dev_comp2->record[i].elem_offset_cnt + dev_comp2->record[i].data_len; - } - return size; -} - -size_t bt_mesh_comp_page_size(uint8_t page) -{ - if (page == 0 || page == 128) { - return comp_page_0_size(); - } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && (page == 1 || page == 129)) { - return comp_page_1_size(); - } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && (page == 2 || page == 130)) { - return comp_page_2_size(); - } - - return 0; -} - int bt_mesh_comp_store(void) { -#if IS_ENABLED(CONFIG_BT_MESH_V1d1) - NET_BUF_SIMPLE_DEFINE(buf, CONFIG_BT_MESH_COMP_PST_BUF_SIZE); + NET_BUF_SIMPLE_DEFINE(buf, BT_MESH_TX_SDU_MAX); int err; for (int i = 0; i < ARRAY_SIZE(comp_data_pages); i++) { - size_t page_size = bt_mesh_comp_page_size(i); - - if (page_size > CONFIG_BT_MESH_COMP_PST_BUF_SIZE) { - LOG_WRN("CDP%d is larger than the CDP persistence buffer. " - "Please increase the CDP persistence buffer size " - "to the required size (%d bytes)", - i, page_size); - } - net_buf_simple_reset(&buf); err = bt_mesh_comp_data_get_page(&buf, comp_data_pages[i].page, 0); @@ -2302,7 +2242,7 @@ int bt_mesh_comp_store(void) LOG_DBG("Stored CDP%d", comp_data_pages[i].page); } -#endif + return 0; } diff --git a/subsys/bluetooth/mesh/access.h b/subsys/bluetooth/mesh/access.h index 6027768ea94..4740963dd21 100644 --- a/subsys/bluetooth/mesh/access.h +++ b/subsys/bluetooth/mesh/access.h @@ -23,7 +23,7 @@ enum { void bt_mesh_elem_register(struct bt_mesh_elem *elem, uint8_t count); uint8_t bt_mesh_elem_count(void); -size_t bt_mesh_comp_page_size(uint8_t page); +size_t bt_mesh_comp_page_0_size(void); int bt_mesh_comp_data_get_page_0(struct net_buf_simple *buf, size_t offset); size_t bt_mesh_metadata_page_0_size(void); int bt_mesh_metadata_get_page_0(struct net_buf_simple *buf, size_t offset); diff --git a/subsys/bluetooth/mesh/large_comp_data_srv.c b/subsys/bluetooth/mesh/large_comp_data_srv.c index 12497d053a2..9f097f4355a 100644 --- a/subsys/bluetooth/mesh/large_comp_data_srv.c +++ b/subsys/bluetooth/mesh/large_comp_data_srv.c @@ -59,59 +59,24 @@ static int handle_large_comp_data_get(struct bt_mesh_model *model, struct bt_mes LOG_DBG("page %u offset %u", page, offset); bt_mesh_model_msg_init(&rsp, OP_LARGE_COMP_DATA_STATUS); - if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 130U; - } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 129U; - } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 128U; - } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { - page = 2U; - } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { - page = 1U; - } else if (page != 0U) { + + if (page != 0U) { LOG_DBG("Composition page %u not available", page); page = 0U; } net_buf_simple_add_u8(&rsp, page); - net_buf_simple_add_le16(&rsp, offset); - if (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) && page < 128) { - size_t msg_space; + total_size = bt_mesh_comp_page_0_size(); + net_buf_simple_add_le16(&rsp, offset); + net_buf_simple_add_le16(&rsp, total_size); - NET_BUF_SIMPLE_DEFINE(temp_buf, CONFIG_BT_MESH_COMP_PST_BUF_SIZE); - err = bt_mesh_comp_read(&temp_buf, page); - if (err) { - LOG_ERR("Could not read comp data p%d, err: %d", page, err); + if (offset < total_size) { + err = bt_mesh_comp_data_get_page_0(&rsp, offset); + if (err && err != -E2BIG) { + LOG_ERR("comp_get_page_0 returned error"); return err; } - - net_buf_simple_add_le16(&rsp, temp_buf.len); - if (offset > temp_buf.len) { - return 0; - } - - msg_space = net_buf_simple_tailroom(&rsp) - BT_MESH_MIC_SHORT; - net_buf_simple_add_mem( - &rsp, temp_buf.data + offset, - (msg_space < (temp_buf.len - offset)) ? msg_space : temp_buf.len - offset); - } else { - total_size = bt_mesh_comp_page_size(page); - net_buf_simple_add_le16(&rsp, total_size); - - if (offset < total_size) { - err = bt_mesh_comp_data_get_page(&rsp, page, offset); - if (err && err != -E2BIG) { - LOG_ERR("Could not read comp data p%d, err: %d", page, err); - return err; - } - } } if (bt_mesh_model_send(model, ctx, &rsp, NULL, NULL)) { From 793ca0126e66430a5449d598f3675810e2865d68 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:14 +0000 Subject: [PATCH 0743/1623] Revert "[nrf fromtree] tests: bluetooth: tester: Fix self-update test DFU/SR/FD/BV-59-C" This reverts commit 60dc14e371af10a1f549fb3541b5be922217e524. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp_mesh.c | 33 +-------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index c191ed54568..2a74bb03828 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -17,7 +17,6 @@ #include #include #include -#include "mesh/access.h" #include #define LOG_MODULE_NAME bttester_mesh @@ -113,19 +112,6 @@ static const struct bt_mesh_blob_io dummy_blob_io = { #endif #if defined(CONFIG_BT_MESH_DFD_SRV) -static const struct bt_mesh_dfu_slot *dfu_self_update_slot; - -static bool is_self_update(struct bt_mesh_dfd_srv *srv) -{ - for (int i = 0; i < ARRAY_SIZE(srv->targets); i++) { - if (bt_mesh_has_addr(srv->targets[i].blob.addr)) { - return true; - } - } - - return false; -} - /* DFD Model data*/ static int dfd_srv_recv(struct bt_mesh_dfd_srv *srv, const struct bt_mesh_dfu_slot *slot, @@ -152,13 +138,6 @@ static int dfd_srv_send(struct bt_mesh_dfd_srv *srv, *io = &dummy_blob_io; - dfu_self_update_slot = NULL; - - if (is_self_update(srv)) { - LOG_DBG("DFD server starts self-update..."); - dfu_self_update_slot = slot; - } - return 0; } @@ -237,7 +216,7 @@ static struct bt_mesh_blob_cli blob_cli = { .cb = &blob_cli_handlers }; #if defined(CONFIG_BT_MESH_DFU_SRV) const char *metadata_data = "1100000000000011"; -static uint8_t dfu_fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { +static uint8_t dfu_fwid[] = { 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -305,16 +284,6 @@ static int dfu_apply(struct bt_mesh_dfu_srv *srv, LOG_DBG("Applying DFU transfer..."); -#if defined(CONFIG_BT_MESH_DFD_SRV) - if (is_self_update(&dfd_srv) && dfu_self_update_slot != NULL) { - LOG_DBG("Swapping fwid for self-update"); - /* Simulate self-update by swapping fwid. */ - memcpy(&dfu_fwid[0], dfu_self_update_slot->fwid, dfu_self_update_slot->fwid_len); - dfu_imgs[0].fwid_len = dfu_self_update_slot->fwid_len; - } - -#endif - return 0; } From c4e6f0e40677337eada080057d2e9f8055abde86 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:15 +0000 Subject: [PATCH 0744/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Fixed issue with RPR server and client." This reverts commit b043570e6e1a2721b9c4ac566a5f768366196f80. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/provisioner.c | 71 --- .../bsim/bluetooth/mesh/src/test_provision.c | 490 +++++------------- .../pb_remote_client_server_same_dev.sh | 32 -- 3 files changed, 123 insertions(+), 470 deletions(-) delete mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index 717cdbee610..361f373cb7b 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -857,72 +857,6 @@ int bt_mesh_pb_remote_open(struct bt_mesh_rpr_cli *cli, return link_open(uuid, &pb_remote_cli, net_idx, addr, 0, &ctx, 0); } -/* Remote Provision done where client and server is on same node, skip open link - * and sending of reprovision message, just execute reprovisioning on it self. - */ -static int reprovision_local_client_server(uint16_t addr) -{ - int err; - const uint8_t *pub_key; - const uint8_t *priv_key = NULL; - - if (atomic_test_and_set_bit(bt_mesh_prov_link.flags, LINK_ACTIVE)) { - return -EBUSY; - } - - LOG_DBG("net_idx %u iv_index 0x%08x, addr 0x%04x", - prov_device.node->net_idx, bt_mesh_cdb.iv_index, addr); - - atomic_set_bit(bt_mesh_prov_link.flags, REPROVISION); - atomic_set_bit(bt_mesh_prov_link.flags, PROVISIONER); - bt_mesh_prov_link.addr = addr; - bt_mesh_prov_link.bearer = &pb_remote_cli; - bt_mesh_prov_link.role = &role_provisioner; - prov_device.net_idx = prov_device.node->net_idx; - prov_device.attention_duration = 0; - - if (IS_ENABLED(CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY) && - bt_mesh_prov->public_key_be && bt_mesh_prov->private_key_be) { - LOG_DBG("Use OOB Public and Private key"); - pub_key = bt_mesh_prov->public_key_be; - priv_key = bt_mesh_prov->private_key_be; - } else { - pub_key = bt_mesh_pub_key_get(); - } - - if (!pub_key) { - LOG_ERR("No public key available"); - return -ENOEXEC; - } - - if (bt_mesh_dhkey_gen(pub_key, priv_key, bt_mesh_prov_link.dhkey)) { - LOG_ERR("Failed to generate DHKey"); - return -ENOEXEC; - } - LOG_DBG("DHkey: %s", bt_hex(bt_mesh_prov_link.dhkey, DH_KEY_SIZE)); - - err = bt_mesh_dev_key(bt_mesh_prov_link.dhkey, - bt_mesh_prov_link.prov_salt, prov_device.new_dev_key); - if (err) { - LOG_ERR("Unable to generate device key"); - return err; - } - - bt_mesh_dev_key_cand(prov_device.new_dev_key); - /* Mark the link that was never opened as closed. */ - atomic_set_bit(bt_mesh_prov_link.flags, COMPLETE); - bt_mesh_reprovision(addr); - bt_mesh_dev_key_cand_activate(); - - if (bt_mesh_prov->reprovisioned) { - LOG_DBG("Application reprovisioned callback 0x%04x", bt_mesh_primary_addr()); - bt_mesh_prov->reprovisioned(bt_mesh_primary_addr()); - } - - prov_link_closed(PROV_BEARER_LINK_STATUS_SUCCESS); - return 0; -} - int bt_mesh_pb_remote_open_node(struct bt_mesh_rpr_cli *cli, struct bt_mesh_rpr_node *srv, uint16_t addr, bool composition_change) @@ -943,11 +877,6 @@ int bt_mesh_pb_remote_open_node(struct bt_mesh_rpr_cli *cli, return -ENOENT; } - /* Check if server is on same device as client */ - if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) && bt_mesh_has_addr(srv->addr)) { - return reprovision_local_client_server(addr); - } - return link_open(NULL, &pb_remote_cli, prov_device.node->net_idx, addr, 0, &ctx, 0); } diff --git a/tests/bsim/bluetooth/mesh/src/test_provision.c b/tests/bsim/bluetooth/mesh/src/test_provision.c index c78fe8dc87d..171f8cccbbd 100644 --- a/tests/bsim/bluetooth/mesh/src/test_provision.c +++ b/tests/bsim/bluetooth/mesh/src/test_provision.c @@ -139,19 +139,6 @@ static const struct bt_mesh_comp rpr_srv_comp = { .elem_count = 1, }; -static const struct bt_mesh_comp rpr_cli_srv_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&(struct bt_mesh_cfg_cli){}), - BT_MESH_MODEL_RPR_CLI(&rpr_cli), - BT_MESH_MODEL_RPR_SRV), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - static int mock_pdu_send(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { @@ -1056,127 +1043,18 @@ static void test_provisioner_pb_remote_client_provision_timeout(void) PASS(); } -static void reprovision_remote_devkey_client(struct bt_mesh_rpr_node *srv, - struct bt_mesh_cdb_node *node) -{ - uint8_t status; - uint8_t prev_node_dev_key[16]; - - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), - "Can't export device key from cdb"); - - bt_mesh_reprovision_remote(&rpr_cli, srv, current_dev_addr, false); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); - - /* Check that CDB has updated Device Key for the node. */ - ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), - "Can't export device key from cdb"); - - /* Check device key by adding appkey. */ - ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, - &status)); - ASSERT_OK(status); - - /* Let RPR Server verify Device Key. */ - k_sleep(K_SECONDS(2)); -} - -static void reprovision_remote_comp_data_client(struct bt_mesh_rpr_node *srv, - struct bt_mesh_cdb_node *node, - struct net_buf_simple *dev_comp) -{ - NET_BUF_SIMPLE_DEFINE(new_dev_comp, BT_MESH_RX_SDU_MAX); - uint8_t prev_node_dev_key[16]; - uint8_t page; - - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), - "Can't export device key from cdb"); - - bt_mesh_reprovision_remote(&rpr_cli, srv, current_dev_addr, true); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); - - /* Check that CDB has updated Device Key for the node. */ - ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), - "Can't export device key from cdb"); - - /* Check that Composition Data Page 128 is now Page 0. */ - net_buf_simple_reset(&new_dev_comp); - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, current_dev_addr, 0, &page, - &new_dev_comp)); - - ASSERT_EQUAL(0, page); - ASSERT_EQUAL(dev_comp->len, new_dev_comp.len); - if (memcmp(dev_comp->data, new_dev_comp.data, dev_comp->len)) { - FAIL("Wrong composition data page 0"); - } - - /* Let RPR Server verify Device Key. */ - k_sleep(K_SECONDS(2)); -} - -static void reprovision_remote_address_client(struct bt_mesh_rpr_node *srv, - struct bt_mesh_cdb_node *node) -{ - uint8_t status; - uint8_t prev_node_dev_key[16]; - - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), - "Can't export device key from cdb"); - - bt_mesh_reprovision_remote(&rpr_cli, srv, current_dev_addr + 1, false); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); - - current_dev_addr++; - srv->addr++; - - /* Check that device doesn't respond to old address with old and new device key. */ - struct bt_mesh_cdb_node *prev_node; - uint8_t tmp[16]; - - prev_node = bt_mesh_cdb_node_alloc((uint8_t[16]) {}, current_dev_addr - 1, 1, 0); - ASSERT_TRUE(node); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_import(prev_node, prev_node_dev_key), - "Can't import device key into cdb"); - ASSERT_EQUAL(-ETIMEDOUT, bt_mesh_cfg_cli_app_key_add(0, current_dev_addr - 1, 0, 0, - test_app_key, &status)); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, tmp), - "Can't export device key from cdb"); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_import(prev_node, tmp), - "Can't import device key into cdb"); - ASSERT_EQUAL(-ETIMEDOUT, bt_mesh_cfg_cli_app_key_add(0, current_dev_addr - 1, 0, 0, - test_app_key, &status)); - bt_mesh_cdb_node_del(prev_node, false); - - /* Check that CDB has updated Device Key for the node. */ - ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); - ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), - "Can't export device key from cdb"); - - /* Check new device address by adding appkey. */ - ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, - &status)); - ASSERT_OK(status); - - /* Let RPR Server verify Device Key. */ - k_sleep(K_SECONDS(2)); - -} - /** @brief Verify robustness of NPPI procedures on a RPR Client by running Device Key Refresh, * Node Composition Refresh and Node Address Refresh procedures. */ static void test_provisioner_pb_remote_client_nppi_robustness(void) { NET_BUF_SIMPLE_DEFINE(dev_comp, BT_MESH_RX_SDU_MAX); + NET_BUF_SIMPLE_DEFINE(new_dev_comp, BT_MESH_RX_SDU_MAX); uint8_t page; uint16_t pb_remote_server_addr; uint8_t status; struct bt_mesh_cdb_node *node; + uint8_t prev_node_dev_key[16]; provisioner_pb_remote_client_setup(); @@ -1204,23 +1082,96 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void) node = bt_mesh_cdb_node_get(current_dev_addr); ASSERT_TRUE(node); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), + "Can't export device key from cdb"); LOG_INF("Testing DevKey refresh..."); for (int i = 0; i < PROV_REPROV_COUNT; i++) { LOG_INF("Refreshing device key #%d...\n", i); - reprovision_remote_devkey_client(&srv, node); + bt_mesh_reprovision_remote(&rpr_cli, &srv, current_dev_addr, false); + + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); + + /* Check that CDB has updated Device Key for the node. */ + ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), + "Can't export device key from cdb"); + + /* Check device key by adding appkey. */ + ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, + &status)); + ASSERT_OK(status); + + /* Let RPR Server verify Device Key. */ + k_sleep(K_SECONDS(2)); } LOG_INF("Testing Composition Data refresh..."); for (int i = 0; i < PROV_REPROV_COUNT; i++) { LOG_INF("Changing Composition Data #%d...\n", i); - reprovision_remote_comp_data_client(&srv, node, &dev_comp); + bt_mesh_reprovision_remote(&rpr_cli, &srv, current_dev_addr, true); + + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); + + /* Check that CDB has updated Device Key for the node. */ + ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), + "Can't export device key from cdb"); + + /* Check that Composition Data Page 128 is now Page 0. */ + net_buf_simple_reset(&new_dev_comp); + ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, current_dev_addr, 0, &page, + &new_dev_comp)); + ASSERT_EQUAL(0, page); + ASSERT_EQUAL(dev_comp.len, new_dev_comp.len); + if (memcmp(dev_comp.data, new_dev_comp.data, dev_comp.len)) { + FAIL("Wrong composition data page 0"); + } + + /* Let RPR Server verify Device Key. */ + k_sleep(K_SECONDS(2)); } LOG_INF("Testing address refresh..."); for (int i = 0; i < PROV_REPROV_COUNT; i++) { LOG_INF("Changing address #%d...\n", i); - reprovision_remote_address_client(&srv, node); + bt_mesh_reprovision_remote(&rpr_cli, &srv, current_dev_addr + 1, false); + + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); + + current_dev_addr++; + srv.addr++; + + /* Check that device doesn't respond to old address with old and new device key. */ + struct bt_mesh_cdb_node *prev_node; + uint8_t tmp[16]; + + prev_node = bt_mesh_cdb_node_alloc((uint8_t[16]) {}, current_dev_addr - 1, 1, 0); + ASSERT_TRUE(node); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_import(prev_node, prev_node_dev_key), + "Can't import device key into cdb"); + ASSERT_EQUAL(-ETIMEDOUT, bt_mesh_cfg_cli_app_key_add(0, current_dev_addr - 1, 0, 0, + test_app_key, &status)); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, tmp), + "Can't export device key from cdb"); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_import(prev_node, tmp), + "Can't import device key into cdb"); + ASSERT_EQUAL(-ETIMEDOUT, bt_mesh_cfg_cli_app_key_add(0, current_dev_addr - 1, 0, 0, + test_app_key, &status)); + bt_mesh_cdb_node_del(prev_node, false); + + /* Check that CDB has updated Device Key for the node. */ + ASSERT_TRUE(bt_mesh_key_compare(prev_node_dev_key, &node->dev_key)); + ASSERT_OK_MSG(bt_mesh_cdb_node_key_export(node, prev_node_dev_key), + "Can't export device key from cdb"); + + /* Check new device address by adding appkey. */ + ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, + &status)); + ASSERT_OK(status); + + /* Let RPR Server verify Device Key. */ + k_sleep(K_SECONDS(2)); } PASS(); @@ -1260,78 +1211,13 @@ static void test_device_pb_remote_server_proved(void) PASS(); } -static void reprovision_remote_devkey_server(const uint16_t initial_addr) -{ - uint8_t prev_dev_key[16]; - uint8_t dev_key[16]; - - ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); - ASSERT_EQUAL(initial_addr, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key and verify that it has - * been changed. - */ - k_sleep(K_SECONDS(2)); - ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); - ASSERT_TRUE(memcmp(&prev_dev_key, dev_key, sizeof(dev_key))); -} - -static void reprovision_remote_comp_data_server(const uint16_t initial_addr) -{ - u_int8_t prev_dev_key[16]; - u_int8_t dev_key[16]; - - /* The RPR Server won't let to run Node Composition Refresh procedure without first - * setting the BT_MESH_COMP_DIRTY flag. The flag is set on a boot if there is a - * "bt/mesh/cmp" entry in settings. The entry is added by the - * `bt_mesh_comp_change_prepare() call. The test suite is not compiled - * with CONFIG_BT_SETTINGS, so the flag will never be set. Since the purpose of the - * test is to check RPR Server behavior, but not the actual swap of the Composition - * Data, the flag is toggled directly from the test. - */ - atomic_set_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY); - ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); - - /* Drop the flag manually as CONFIG_BT_SETTINGS is not enabled. */ - atomic_clear_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY); - - ASSERT_EQUAL(initial_addr, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key and verify that it has - * been changed. - */ - k_sleep(K_SECONDS(2)); - ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); - ASSERT_TRUE(memcmp(prev_dev_key, dev_key, sizeof(dev_key))); -} - -static void reprovision_remote_address_server(const uint16_t initial_addr) -{ - uint8_t prev_dev_key[16]; - uint8_t dev_key[16]; - - ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); - ASSERT_EQUAL(initial_addr + 1, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key and verify that it has - * been changed. - */ - k_sleep(K_SECONDS(2)); - ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); - ASSERT_TRUE(memcmp(prev_dev_key, dev_key, sizeof(dev_key))); -} - /** @brief Verify robustness of NPPI procedures on a RPR Server by running Device Key Refresh, * Node Composition Refresh and Node Address Refresh procedures multiple times each. */ static void test_device_pb_remote_server_nppi_robustness(void) { + struct bt_mesh_key prev_dev_key; + k_sem_init(&prov_sem, 0, 1); k_sem_init(&reprov_sem, 0, 1); @@ -1344,25 +1230,65 @@ static void test_device_pb_remote_server_nppi_robustness(void) ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); const uint16_t initial_addr = bt_mesh_primary_addr(); + memcpy(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key)); + LOG_INF("Enabling PB-Remote server"); ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_REMOTE)); /* Test Device Key Refresh procedure robustness. */ for (int i = 0; i < PROV_REPROV_COUNT; i++) { LOG_INF("Devkey refresh loop #%d, waiting for being reprov ...\n", i); - reprovision_remote_devkey_server(initial_addr); + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); + ASSERT_EQUAL(initial_addr, bt_mesh_primary_addr()); + + /* Let Configuration Client activate the new Device Key and verify that it has + * been changed. + */ + k_sleep(K_SECONDS(2)); + ASSERT_TRUE(memcmp(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key))); + memcpy(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key)); } /* Test Node Composition Refresh procedure robustness. */ for (int i = 0; i < PROV_REPROV_COUNT; i++) { + /* The RPR Server won't let to run Node Composition Refresh procedure without first + * setting the BT_MESH_COMP_DIRTY flag. The flag is set on a boot if there is a + * "bt/mesh/cmp" entry in settings. The entry is added by the + * `bt_mesh_comp_change_prepare() call. The test suite is not compiled + * with CONFIG_BT_SETTINGS, so the flag will never be set. Since the purpose of the + * test is to check RPR Server behavior, but not the actual swap of the Composition + * Data, the flag is toggled directly from the test. + */ + atomic_set_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY); + LOG_INF("Composition data refresh loop #%d, waiting for being reprov ...\n", i); - reprovision_remote_comp_data_server(initial_addr); + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); + + /* Drop the flag manually as CONFIG_BT_SETTINGS is not enabled. */ + atomic_clear_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY); + + ASSERT_EQUAL(initial_addr, bt_mesh_primary_addr()); + + /* Let Configuration Client activate the new Device Key and verify that it has + * been changed. + */ + k_sleep(K_SECONDS(2)); + ASSERT_TRUE(memcmp(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key))); + memcpy(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key)); } /* Node Address Refresh robustness. */ for (int i = 0; i < PROV_REPROV_COUNT; i++) { LOG_INF("Address refresh loop #%d, waiting for being reprov ...\n", i); - reprovision_remote_address_server(initial_addr+i); + ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); + ASSERT_EQUAL(initial_addr + 1 + i, bt_mesh_primary_addr()); + + /* Let Configuration Client activate the new Device Key and verify that it has + * been changed. + */ + k_sleep(K_SECONDS(2)); + ASSERT_TRUE(memcmp(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key))); + memcpy(&prev_dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key)); } PASS(); @@ -1399,172 +1325,6 @@ static void test_provisioner_pb_remote_client_ncrp_provision(void) PASS(); } -/** @brief A device running a Remote Provisioning client and server that is used to reprovision - * another device and it self with the client. - */ -static void test_device_pb_remote_client_server_same_dev(void) -{ - NET_BUF_SIMPLE_DEFINE(dev_comp, BT_MESH_RX_SDU_MAX); - uint8_t status; - struct bt_mesh_cdb_node *node; - uint8_t page; - uint8_t prev_dev_key[16]; - uint16_t test_vector[] = { 0x0002, 0x0001 }; - - k_sem_init(&prov_sem, 0, 1); - k_sem_init(&reprov_sem, 0, 1); - - bt_mesh_device_setup(&prov, &rpr_cli_srv_comp); - - ASSERT_OK(bt_mesh_cdb_create(test_net_key)); - ASSERT_OK(bt_mesh_provision(test_net_key, 0, 0, 0, 0x0001, dev_key)); - - LOG_INF("Enabling PB-Remote server"); - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_REMOTE)); - - /* Provision a remote device with RPR Client and Server with local RPR Server. */ - current_dev_addr = 0x0001; - struct bt_mesh_rpr_node srv = { - .addr = current_dev_addr, - .net_idx = 0, - .ttl = 3, - }; - - LOG_INF("Provisioner prov, waiting for prov ...\n"); - ASSERT_OK(provision_remote(&srv, 1, &srv.addr)); - - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); - - /* Check device key by adding bt_mesh_reprovision_remote appkey. */ - ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, &status)); - ASSERT_OK(status); - - /* Swap callback to catch when device reprovisioned. */ - prov.node_added = prov_node_added_rpr; - - /* Reprovision a device with both RPR Client and Server. */ - for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { - current_dev_addr = test_vector[i]; - srv.addr = current_dev_addr; - bool self_reprov = (bool)(current_dev_addr == bt_mesh_primary_addr()); - - /* Store initial Composition Data Page 0. */ - net_buf_simple_reset(&dev_comp); - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, current_dev_addr, 0, &page, &dev_comp)); - - node = bt_mesh_cdb_node_get(current_dev_addr); - ASSERT_TRUE(node); - - LOG_INF("Refreshing 0x%04x device key ...\n", srv.addr); - ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); - reprovision_remote_devkey_client(&srv, node); - if (self_reprov) { - uint8_t dev_key[16]; - - ASSERT_EQUAL(current_dev_addr, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key - * and verify that it has been changed. - */ - ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); - ASSERT_TRUE(memcmp(prev_dev_key, dev_key, sizeof(dev_key))); - } - - LOG_INF("Changing 0x%04x Composition Data ...\n", srv.addr); - ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); - reprovision_remote_comp_data_client(&srv, node, &dev_comp); - if (self_reprov) { - uint8_t dev_key[16]; - - ASSERT_EQUAL(current_dev_addr, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key - * and verify that it has been changed. - */ - ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); - ASSERT_TRUE(memcmp(prev_dev_key, dev_key, sizeof(struct bt_mesh_key))); - } - - LOG_INF("Changing 0x%04x address ...\n", srv.addr); - ASSERT_OK(bt_mesh_key_export(prev_dev_key, &bt_mesh.dev_key)); - reprovision_remote_address_client(&srv, node); - if (self_reprov) { - uint8_t dev_key[16]; - - ASSERT_EQUAL(current_dev_addr, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key - * and verify that it has been changed. - */ - ASSERT_OK(bt_mesh_key_export(dev_key, &bt_mesh.dev_key)); - ASSERT_TRUE(memcmp(prev_dev_key, dev_key, sizeof(dev_key))); - } - } - - PASS(); -} - -/** @brief Verify that the Remote Provisioning client and server is able to be reprovision - * by another device with a Remote Provisioning client and server. - */ -static void test_device_pb_remote_server_same_dev(void) -{ - k_sem_init(&prov_sem, 0, 1); - k_sem_init(&reprov_sem, 0, 1); - - bt_mesh_device_setup(&prov, &rpr_cli_srv_comp); - - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_ADV)); - - LOG_INF("Waiting for being provisioned..."); - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); - - LOG_INF("Enabling PB-Remote server"); - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_REMOTE)); - - /* Swap callback to catch when device reprovisioned. */ - prov.node_added = prov_node_added_rpr; - - const uint16_t initial_addr = bt_mesh_primary_addr(); - - LOG_INF("Devkey refresh, waiting for being reprov ...\n"); - reprovision_remote_devkey_server(initial_addr); - - LOG_INF("Composition data refresh, waiting for being reprov ...\n"); - reprovision_remote_comp_data_server(initial_addr); - - LOG_INF("Address refresh, waiting for being reprov ...\n"); - reprovision_remote_address_server(initial_addr); - - PASS(); -} - -static void comp_data_get(uint16_t server_addr, uint8_t page, struct net_buf_simple *comp) -{ - uint8_t page_rsp; - - net_buf_simple_reset(comp); - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, server_addr, page, &page_rsp, comp)); - ASSERT_EQUAL(page, page_rsp); -} - -static void comp_data_compare(struct net_buf_simple *comp1, struct net_buf_simple *comp2, - bool expect_equal) -{ - if (expect_equal) { - ASSERT_EQUAL(comp1->len, comp2->len); - if (memcmp(comp1->data, comp2->data, comp1->len)) { - FAIL("Composition data is not equal"); - } - } else { - if (comp1->len == comp2->len) { - if (!memcmp(comp1->data, comp2->data, comp1->len)) { - FAIL("Composition data is equal"); - } - } - } -} - /** @brief Test Node Composition Refresh procedure on Remote Provisioning client: * - initiate Node Composition Refresh procedure on a 3rd device. */ @@ -1783,10 +1543,6 @@ static const struct bst_test_instance test_connect[] = { "Device: pb-remote reprovisioning, NPPI robustness"), TEST_CASE(device, pb_remote_server_unproved_unresponsive, "Device: used for remote provisioning, starts unprovisioned, stops responding"), - TEST_CASE(device, pb_remote_client_server_same_dev, - "Device: used for remote provisioning, with both client and server"), - TEST_CASE(device, pb_remote_server_same_dev, - "Device: used for remote reprovisioning, with both client and server"), #endif TEST_CASE(provisioner, pb_adv_no_oob, diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh deleted file mode 100755 index 33de74370e1..00000000000 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test a node re-provisioning through Remote Provisioning models. Procedure: -# 1. Device (prov_device_pb_remote_client_server_same_dev) provisions it self -# and start scanning for an upprovisioned device, and provisions the the -# second device (prov_device_pb_remote_server_same_dev) with local RPR server. -# 2. The first device (prov_device_pb_remote_client_server_same_dev) execute -# device key refresh procedure the second device (prov_device_pb_remote_server_same_dev). -# 3. The first device (prov_device_pb_remote_client_server_same_dev) execute -# composition refresh procedure the second device (prov_device_pb_remote_server_same_dev). -# 4. The first device (prov_device_pb_remote_client_server_same_dev) execute -# address refresh procedure the second device (prov_device_pb_remote_server_same_dev). -# 5. The first device (prov_device_pb_remote_client_server_same_dev) execute -# device key refresh procedure on it self with local RPR client and server. -# 6. The first device (prov_device_pb_remote_client_server_same_dev) execute -# composition refresh procedure on it self with local RPR client and server. -# 7. The first device (prov_device_pb_remote_client_server_same_dev) execute -# address refresh procedure on it self with local RPR client and server. -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_remote_client_server_same_dev \ - prov_device_pb_remote_client_server_same_dev \ - prov_device_pb_remote_server_same_dev - -conf=prj_mesh1d1_conf -overlay=overlay_psa_conf -RunTest mesh_prov_pb_remote_client_server_same_dev \ - prov_device_pb_remote_client_server_same_dev \ - prov_device_pb_remote_server_same_dev From 791b6358be55ab98312f3b3ed8cfc2a7fb4bf744 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:15 +0000 Subject: [PATCH 0745/1623] Revert "[nrf fromtree] tests: bluetooth: tester: Allow to pass int instead of bool in comp cmd" This reverts commit 0d5459354aa7383a99c7c7681fea795166061817. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp/btp_mesh.h | 2 +- tests/bluetooth/tester/src/btp_mesh.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index c2636d1445d..6b58d1515dc 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -78,7 +78,7 @@ struct btp_mesh_provision_node_cmd_v2 { #define BTP_MESH_INIT 0x04 struct btp_mesh_init_cmd { - uint8_t comp; + bool comp_alt; } __packed; #define BTP_MESH_RESET 0x05 diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 2a74bb03828..dd16e98367b 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1259,7 +1259,7 @@ static uint8_t init(const void *cmd, uint16_t cmd_len, const struct btp_mesh_init_cmd *cp = cmd; int err; - if (cp->comp == 0) { + if (!cp->comp_alt) { LOG_WRN("Loading default comp data"); err = bt_mesh_init(&prov, &comp); } else { From 34b55be7a43f0618a8f5652d0e5ca5baf46b1ab8 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:15 +0000 Subject: [PATCH 0746/1623] Revert "[nrf fromtree] tests: bluetooth: tester: Remove comp_alt_set command" This reverts commit 2814689b0005730341054fb7b7de91c0488f320a. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp/btp_mesh.h | 2 + tests/bluetooth/tester/src/btp_mesh.c | 48 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 6b58d1515dc..bb26524246e 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -849,6 +849,8 @@ struct btp_mesh_opcodes_aggregator_init_cmd { #define BTP_MESH_COMP_CHANGE_PREPARE 0x57 +#define BTP_MESH_SET_COMP_ALT 0x58 + #define BTP_MESH_RPR_SCAN_START 0x59 struct btp_rpr_scan_start_cmd { uint16_t dst; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index dd16e98367b..eea03b0936e 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -318,6 +318,8 @@ static struct { .dst = BT_MESH_ADDR_UNASSIGNED, }; +static bool default_comp = true; + static uint8_t supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -1903,6 +1905,47 @@ static uint8_t change_prepare(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } +#if IS_ENABLED(CONFIG_BT_SETTINGS) +static int comp_alt_set(const char *name, size_t len_rd, + settings_read_cb read_cb, void *store) +{ + ssize_t len; + bool alt_comp_value; + + if (len_rd == 0) { + LOG_DBG("Default composition"); + } + + len = read_cb(store, &alt_comp_value, sizeof(alt_comp_value)); + if (len < 0 || len != len_rd) { + LOG_ERR("Failed to read value (err %zd)", len); + return len; + } + + if (alt_comp_value) { + default_comp = false; + } + + return 0; +} + +SETTINGS_STATIC_HANDLER_DEFINE(tester_comp_alt, "tester/comp_alt", NULL, comp_alt_set, NULL, NULL); +#endif + +static uint8_t set_comp_alt(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ +#if !IS_ENABLED(CONFIG_BT_SETTINGS) + return BTP_STATUS_FAILED; +#else + bool comp_alt_val = true; + + settings_save_one("tester/comp_alt", &comp_alt_val, sizeof(comp_alt_val)); + + return BTP_STATUS_SUCCESS; +#endif +} + static uint8_t config_krp_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -4820,6 +4863,11 @@ static const struct btp_handler handlers[] = { .expect_len = 0, .func = change_prepare }, + { + .opcode = BTP_MESH_SET_COMP_ALT, + .expect_len = 0, + .func = set_comp_alt + }, #if defined(CONFIG_BT_MESH_RPR_CLI) { .opcode = BTP_MESH_RPR_SCAN_START, From 98f32eb5562e9ac0d38fb17155446df0222092e5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:15 +0000 Subject: [PATCH 0747/1623] Revert "[nrf fromtree] tests: bluetooth: tester: Move bt_mesh_init call to BTP_MESH_INIT cmd" This reverts commit b0b28e641a6591433abfdff68770fac327995e35. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp/btp_mesh.h | 4 --- tests/bluetooth/tester/src/btp_mesh.c | 32 +++++++++++------------ 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index bb26524246e..826f0fd0408 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -77,10 +77,6 @@ struct btp_mesh_provision_node_cmd_v2 { } __packed; #define BTP_MESH_INIT 0x04 -struct btp_mesh_init_cmd { - bool comp_alt; -} __packed; - #define BTP_MESH_RESET 0x05 #define BTP_MESH_INPUT_NUMBER 0x06 struct btp_mesh_input_number_cmd { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index eea03b0936e..e83f1a67ba1 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1258,24 +1258,8 @@ static uint8_t provision_adv(const void *cmd, uint16_t cmd_len, static uint8_t init(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { - const struct btp_mesh_init_cmd *cp = cmd; int err; - if (!cp->comp_alt) { - LOG_WRN("Loading default comp data"); - err = bt_mesh_init(&prov, &comp); - } else { - LOG_WRN("Loading alternative comp data"); -#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV - health_srv.metadata = health_srv_meta_alt; -#endif - err = bt_mesh_init(&prov, &comp_alt); - } - - if (err) { - return BTP_STATUS_FAILED; - } - LOG_DBG(""); if (IS_ENABLED(CONFIG_BT_SETTINGS)) { @@ -4435,7 +4419,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_MESH_INIT, - .expect_len = sizeof(struct btp_mesh_init_cmd), + .expect_len = 0, .func = init, }, { @@ -5240,6 +5224,8 @@ BT_MESH_LPN_CB_DEFINE(lpn_cb) = { uint8_t tester_init_mesh(void) { + int err; + if (IS_ENABLED(CONFIG_BT_TESTING)) { bt_test_cb_register(&bt_test_cb); } @@ -5250,6 +5236,18 @@ uint8_t tester_init_mesh(void) tester_register_command_handlers(BTP_SERVICE_ID_MESH, handlers, ARRAY_SIZE(handlers)); + if (default_comp) { + err = bt_mesh_init(&prov, &comp); + } else { +#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV + health_srv.metadata = health_srv_meta_alt; +#endif + err = bt_mesh_init(&prov, &comp_alt); + } + + if (err) { + return BTP_STATUS_FAILED; + } return BTP_STATUS_SUCCESS; } From d3bae7a0a1fd6597085477b7db1e14db96168747 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:15 +0000 Subject: [PATCH 0748/1623] Revert "[nrf fromtree] Bluetooth: Mesh: fix settings work queue size for rpr" This reverts commit 7bc30a2760c9c536cd24b1ebe040d1cdcbed6f08. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 9f24ff81975..2dfc125b8fd 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1718,7 +1718,6 @@ config BT_MESH_SETTINGS_WORKQ_PRIO config BT_MESH_SETTINGS_WORKQ_STACK_SIZE int "Stack size of the settings workq" - default 1200 if BT_MESH_RPR_SRV default 880 help Size of the settings workqueue stack. From d02a2dafdb4235c6df05f666df4e1174e73d847f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:16 +0000 Subject: [PATCH 0749/1623] =?UTF-8?q?Revert=20"[nrf=20fromtree]=C2=A0board?= =?UTF-8?q?s:=20arm:=20nrf9161dk=5Fnrf9161:=20Add=20ext=20flash=20support?= =?UTF-8?q?=20for=200.7.0=20version"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 10b0106a4e8771c99908d2b9c783fd9eee2e40bc. Signed-off-by: Dominik Ermel --- .../nrf9161dk_nrf9161_0_7_0.overlay | 7 ----- .../nrf9161dk_nrf9161_common_0_7_0.dtsi | 31 ------------------- .../nrf9161dk_nrf9161_ns_0_7_0.overlay | 7 ----- boards/arm/nrf9161dk_nrf9161/revision.cmake | 8 ----- 4 files changed, 53 deletions(-) delete mode 100644 boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_0_7_0.overlay delete mode 100644 boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common_0_7_0.dtsi delete mode 100644 boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_ns_0_7_0.overlay delete mode 100644 boards/arm/nrf9161dk_nrf9161/revision.cmake diff --git a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_0_7_0.overlay b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_0_7_0.overlay deleted file mode 100644 index 22e9f970dab..00000000000 --- a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_0_7_0.overlay +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "nrf9161dk_nrf9161_common_0_7_0.dtsi" diff --git a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common_0_7_0.dtsi b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common_0_7_0.dtsi deleted file mode 100644 index ae67df77b22..00000000000 --- a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common_0_7_0.dtsi +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -&spi3 { - gd25lb256: gd25lb256e3ir@1 { - compatible = "jedec,spi-nor"; - status = "okay"; - reg = <1>; - spi-max-frequency = <60000000>; - jedec-id = [c8 67 19]; - sfdp-bfp = [ - e5 20 ea ff ff ff ff 0f 44 eb 08 6b 00 3b 00 bb - fe ff ff ff ff ff 00 ff ff ff 44 eb 0c 20 0f 52 - 10 d8 00 ff d5 31 b1 fe 82 e4 14 4c ec 60 06 33 - 7a 75 7a 75 04 bd d5 5c 29 06 74 00 08 50 00 01 - ]; - size = <268435456>; - has-dpd; - t-enter-dpd = <3000>; - t-exit-dpd = <30000>; - }; -}; - -/ { - aliases { - spi-flash0 = &gd25lb256; - }; -}; diff --git a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_ns_0_7_0.overlay b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_ns_0_7_0.overlay deleted file mode 100644 index 22e9f970dab..00000000000 --- a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_ns_0_7_0.overlay +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "nrf9161dk_nrf9161_common_0_7_0.dtsi" diff --git a/boards/arm/nrf9161dk_nrf9161/revision.cmake b/boards/arm/nrf9161dk_nrf9161/revision.cmake deleted file mode 100644 index 2a899f61a83..00000000000 --- a/boards/arm/nrf9161dk_nrf9161/revision.cmake +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -board_check_revision( - FORMAT MAJOR.MINOR.PATCH - DEFAULT_REVISION 0.9.0 - VALID_REVISIONS 0.7.0 0.9.0 -) From dcadc3f9c9af6f338c64a92d385bd9dbd24992d2 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:16 +0000 Subject: [PATCH 0750/1623] Revert "[nrf fromtree] boards: arm: nrf9161dk: update SPI flash" This reverts commit 33a728fe359097894cd94598f2f09f7d883f6b8e. Signed-off-by: Dominik Ermel --- .../nrf9161dk_nrf9161_common.dtsi | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common.dtsi b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common.dtsi index a6aeccf34b9..1dee5b1b1a3 100644 --- a/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common.dtsi +++ b/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_common.dtsi @@ -128,7 +128,7 @@ mcuboot-button0 = &button0; mcuboot-led0 = &led0; watchdog0 = &wdt0; - spi-flash0 = &gd25wb256; + spi-flash0 = &gd25lb256; }; }; @@ -195,22 +195,22 @@ arduino_spi: &spi3 { pinctrl-1 = <&spi3_sleep>; pinctrl-names = "default", "sleep"; - gd25wb256: gd25wb256e3ir@1 { + gd25lb256: gd25lb256e3ir@1 { compatible = "jedec,spi-nor"; status = "disabled"; reg = <1>; - spi-max-frequency = <8000000>; + spi-max-frequency = <60000000>; + jedec-id = [c8 67 19]; + sfdp-bfp = [ + e5 20 ea ff ff ff ff 0f 44 eb 08 6b 00 3b 00 bb + fe ff ff ff ff ff 00 ff ff ff 44 eb 0c 20 0f 52 + 10 d8 00 ff d5 31 b1 fe 82 e4 14 4c ec 60 06 33 + 7a 75 7a 75 04 bd d5 5c 29 06 74 00 08 50 00 01 + ]; size = <268435456>; has-dpd; t-enter-dpd = <3000>; - t-exit-dpd = <40000>; - sfdp-bfp = [ - e5 20 f3 ff ff ff ff 0f 44 eb 08 6b 08 3b 42 bb - ee ff ff ff ff ff 00 ff ff ff 00 ff 0c 20 0f 52 - 10 d8 00 ff 44 7a c9 fe 83 67 26 62 ec 82 18 44 - 7a 75 7a 75 04 c4 d5 5c 00 06 74 00 08 50 00 01 - ]; - jedec-id = [c8 65 19]; + t-exit-dpd = <30000>; }; }; From 6d08b476d8b353c6668f931d8d70bf5735fad6ba Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:16 +0000 Subject: [PATCH 0751/1623] Revert "[nrf fromtree] Bluetooth: Test: Update `security/ccc_update`" This reverts commit c65b964187a631bd6bce52995599b29ba455b8dd. Signed-off-by: Dominik Ermel --- .../host/security/ccc_update/src/central.c | 9 ++++-- .../host/security/ccc_update/src/peripheral.c | 28 +++++++------------ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/tests/bsim/bluetooth/host/security/ccc_update/src/central.c b/tests/bsim/bluetooth/host/security/ccc_update/src/central.c index 8f2d2c17dd4..fbdf7ee0108 100644 --- a/tests/bsim/bluetooth/host/security/ccc_update/src/central.c +++ b/tests/bsim/bluetooth/host/security/ccc_update/src/central.c @@ -248,7 +248,7 @@ static void connect_unsubscribe(void) backchannel_sync_wait(SERVER_CLIENT_CHAN, SERVER_ID); } -static void connect_restore_sec(void) +static void connect_restore_sec_unsubscribe(void) { int err; @@ -270,7 +270,10 @@ static void connect_restore_sec(void) /* wait for server to check that the subscribtion has been restored */ backchannel_sync_wait(SERVER_CLIENT_CHAN, SERVER_ID); - /* wait for server to check that the subscription no longer exist */ + /* send unsubscribtion request */ + ccc_unsubscribe(); + + /* wait for server to check that the unsubscribtion has been well registered */ backchannel_sync_send(SERVER_CLIENT_CHAN, SERVER_ID); } @@ -344,7 +347,7 @@ void run_central(void) backchannel_sync_send(CLIENT_CLIENT_CHAN, BAD_CLIENT_ID); backchannel_sync_wait(CLIENT_CLIENT_CHAN, BAD_CLIENT_ID); - connect_restore_sec(); + connect_restore_sec_unsubscribe(); disconnect(); PASS("Central test passed\n"); diff --git a/tests/bsim/bluetooth/host/security/ccc_update/src/peripheral.c b/tests/bsim/bluetooth/host/security/ccc_update/src/peripheral.c index ac6307dae6a..b9070361577 100644 --- a/tests/bsim/bluetooth/host/security/ccc_update/src/peripheral.c +++ b/tests/bsim/bluetooth/host/security/ccc_update/src/peripheral.c @@ -194,9 +194,9 @@ static void connect_wait_unsubscribtion(struct bt_le_ext_adv *adv) stop_adv(adv); - /* check that subscribtion is restored for bad client */ - if (!is_peer_subscribed(default_conn)) { - FAIL("Subscribtion has not been restored for bad client\n"); + /* check that subscribtion is not restored for bad client */ + if (is_peer_subscribed(default_conn)) { + FAIL("Subscribtion has been restored for bad client\n"); } /* confirm to bad client that the subscribtion had not been restored */ @@ -204,12 +204,12 @@ static void connect_wait_unsubscribtion(struct bt_le_ext_adv *adv) /* wait for confirmation that bad client requested unsubscribtion */ backchannel_sync_wait(BAD_CLIENT_CHAN, BAD_CLIENT_ID); - /* check that unsubscribtion request didn't fail */ - if (!GET_FLAG(ccc_cfg_changed_flag)) { - FAIL("Bad client didn't manage to update CCC config\n"); + /* check that unsubscribtion request failed */ + if (GET_FLAG(ccc_cfg_changed_flag)) { + FAIL("Bad client updated CCC config\n"); } - /* confirm to bad client that unsubscribtion request has been well registered */ + /* confirm to bad client that unsubscribtion request has been ignored */ backchannel_sync_send(BAD_CLIENT_CHAN, BAD_CLIENT_ID); } @@ -225,9 +225,9 @@ static void connect_restore_sec_check_subscribtion(struct bt_le_ext_adv *adv) /* wait for good client end of security update */ backchannel_sync_wait(GOOD_CLIENT_CHAN, GOOD_CLIENT_ID); - /* check that subscribtion hasn't been restored */ - if (is_peer_subscribed(default_conn)) { - FAIL("Good client is subscribed\n"); + /* check that subscribtion has been restored */ + if (!is_peer_subscribed(default_conn)) { + FAIL("Good client is not subscribed\n"); } /* confirm to good client that the subscribtion has been well restored */ @@ -285,14 +285,6 @@ static void check_ccc_handle(void) void run_peripheral(void) { - /* - * test goal: demonstrate the expected behavior of the GATT server when - * a non-bonded peer try to unsubscribe from a previously subscription - * done in a bonded context - * - * test pass if the bad client manage to unsubscribe - */ - int err; struct bt_le_ext_adv *adv = NULL; From 0b778d104bfe903d2b5abd8bc564d93e1faeed96 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:16 +0000 Subject: [PATCH 0752/1623] Revert "[nrf fromtree] Revert "Bluetooth: Host: Fix GATT server handling of CCC"" This reverts commit c33d528a791c5aa4995e998b07ed8921ac2c04b2. Signed-off-by: Dominik Ermel --- include/zephyr/bluetooth/gatt.h | 5 ++++ subsys/bluetooth/host/gatt.c | 43 +++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/include/zephyr/bluetooth/gatt.h b/include/zephyr/bluetooth/gatt.h index f0ee8d5981a..e4aae4e4d41 100644 --- a/include/zephyr/bluetooth/gatt.h +++ b/include/zephyr/bluetooth/gatt.h @@ -736,6 +736,11 @@ struct bt_gatt_ccc_cfg { uint8_t id; /** Remote peer address. */ bt_addr_le_t peer; + /** + * Separate storage for encrypted and unencrypted context. This + * indicate that the link was encrypted when the CCC was written. + */ + bool link_encrypted; /** Configuration value. */ uint16_t value; }; diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index 93dfe555580..39f01bc45b4 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -1318,6 +1318,7 @@ static void clear_ccc_cfg(struct bt_gatt_ccc_cfg *cfg) bt_addr_le_copy(&cfg->peer, BT_ADDR_LE_ANY); cfg->id = 0U; cfg->value = 0U; + cfg->link_encrypted = false; } static void gatt_store_ccc_cf(uint8_t id, const bt_addr_le_t *peer_addr); @@ -2049,6 +2050,34 @@ struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr) return next; } +static bool bt_gatt_ccc_cfg_is_matching_conn(const struct bt_conn *conn, + const struct bt_gatt_ccc_cfg *cfg) +{ + bool conn_encrypted = bt_conn_get_security(conn) >= BT_SECURITY_L2; + + if (cfg->link_encrypted && !conn_encrypted) { + return false; + } + + return bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer); +} + +static struct bt_conn *bt_gatt_ccc_cfg_conn_lookup(const struct bt_gatt_ccc_cfg *cfg) +{ + struct bt_conn *conn; + + conn = bt_conn_lookup_addr_le(cfg->id, &cfg->peer); + if (conn) { + if (bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) { + return conn; + } + + bt_conn_unref(conn); + } + + return NULL; +} + static struct bt_gatt_ccc_cfg *find_ccc_cfg(const struct bt_conn *conn, struct _bt_gatt_ccc *ccc) { @@ -2056,8 +2085,7 @@ static struct bt_gatt_ccc_cfg *find_ccc_cfg(const struct bt_conn *conn, struct bt_gatt_ccc_cfg *cfg = &ccc->cfg[i]; if (conn) { - if (bt_conn_is_peer_addr_le(conn, cfg->id, - &cfg->peer)) { + if (bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) { return cfg; } } else if (bt_addr_le_eq(&cfg->peer, BT_ADDR_LE_ANY)) { @@ -2151,6 +2179,7 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn, bt_addr_le_copy(&cfg->peer, &conn->le.dst); cfg->id = conn->id; + cfg->link_encrypted = (bt_conn_get_security(conn) >= BT_SECURITY_L2); } /* Confirm write if cfg is managed by application */ @@ -3230,8 +3259,7 @@ static uint8_t update_ccc(const struct bt_gatt_attr *attr, uint16_t handle, struct bt_gatt_ccc_cfg *cfg = &ccc->cfg[i]; /* Ignore configuration for different peer or not active */ - if (!cfg->value || - !bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer)) { + if (!cfg->value || !bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) { continue; } @@ -3305,11 +3333,11 @@ static uint8_t disconnected_cb(const struct bt_gatt_attr *attr, uint16_t handle, continue; } - if (!bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer)) { + if (!bt_gatt_ccc_cfg_is_matching_conn(conn, cfg)) { struct bt_conn *tmp; /* Skip if there is another peer connected */ - tmp = bt_conn_lookup_addr_le(cfg->id, &cfg->peer); + tmp = bt_gatt_ccc_cfg_conn_lookup(cfg); if (tmp) { if (tmp->state == BT_CONN_CONNECTED) { value_used = true; @@ -3399,7 +3427,7 @@ bool bt_gatt_is_subscribed(struct bt_conn *conn, for (size_t i = 0; i < BT_GATT_CCC_MAX; i++) { const struct bt_gatt_ccc_cfg *cfg = &ccc->cfg[i]; - if (bt_conn_is_peer_addr_le(conn, cfg->id, &cfg->peer) && + if (bt_gatt_ccc_cfg_is_matching_conn(conn, cfg) && (ccc_type & ccc->cfg[i].value)) { return true; } @@ -5550,6 +5578,7 @@ static uint8_t ccc_load(const struct bt_gatt_attr *attr, uint16_t handle, } bt_addr_le_copy(&cfg->peer, load->addr_with_id.addr); cfg->id = load->addr_with_id.id; + cfg->link_encrypted = true; } cfg->value = load->entry->value; From e0c1a0292399fb30d5518e6823a8a4f0cacd3b16 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:17 +0000 Subject: [PATCH 0753/1623] Revert "[nrf fromtree] Bluetooth: Test: SC Indication" This reverts commit 860096c05abbb93e27d3ca0c3a14518cd3a69c5d. Signed-off-by: Dominik Ermel --- tests/bsim/bluetooth/host/compile.sh | 1 - .../host/gatt/sc_indicate/CMakeLists.txt | 25 --- .../bluetooth/host/gatt/sc_indicate/prj.conf | 20 -- .../host/gatt/sc_indicate/src/bs_bt_utils.c | 182 ---------------- .../host/gatt/sc_indicate/src/bs_bt_utils.h | 67 ------ .../host/gatt/sc_indicate/src/central.c | 195 ------------------ .../host/gatt/sc_indicate/src/main.c | 58 ------ .../host/gatt/sc_indicate/src/peripheral.c | 86 -------- .../gatt/sc_indicate/test_scripts/_compile.sh | 18 -- .../sc_indicate/test_scripts/sc_indicate.sh | 24 --- 10 files changed, 676 deletions(-) delete mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/CMakeLists.txt delete mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/prj.conf delete mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.c delete mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.h delete mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/src/central.c delete mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/src/main.c delete mode 100644 tests/bsim/bluetooth/host/gatt/sc_indicate/src/peripheral.c delete mode 100755 tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/_compile.sh delete mode 100755 tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/sc_indicate.sh diff --git a/tests/bsim/bluetooth/host/compile.sh b/tests/bsim/bluetooth/host/compile.sh index 98d6c79e3ef..a54dbd26507 100755 --- a/tests/bsim/bluetooth/host/compile.sh +++ b/tests/bsim/bluetooth/host/compile.sh @@ -44,7 +44,6 @@ app=tests/bsim/bluetooth/host/gatt/settings compile app=tests/bsim/bluetooth/host/gatt/settings conf_file=prj_2.conf compile app=tests/bsim/bluetooth/host/gatt/ccc_store compile app=tests/bsim/bluetooth/host/gatt/ccc_store conf_file=prj_2.conf compile -app=tests/bsim/bluetooth/host/gatt/sc_indicate compile app=tests/bsim/bluetooth/host/l2cap/general compile app=tests/bsim/bluetooth/host/l2cap/userdata compile diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/CMakeLists.txt b/tests/bsim/bluetooth/host/gatt/sc_indicate/CMakeLists.txt deleted file mode 100644 index d734b3c054e..00000000000 --- a/tests/bsim/bluetooth/host/gatt/sc_indicate/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set \ - the environment variable BSIM_COMPONENTS_PATH to point to its \ - components folder. More information can be found in \ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_auto_seq_req) - -target_sources(app PRIVATE - src/main.c - src/central.c - src/peripheral.c - src/bs_bt_utils.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ -) diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/prj.conf b/tests/bsim/bluetooth/host/gatt/sc_indicate/prj.conf deleted file mode 100644 index 7edaf36d10e..00000000000 --- a/tests/bsim/bluetooth/host/gatt/sc_indicate/prj.conf +++ /dev/null @@ -1,20 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_DEVICE_NAME="SC Indication Test" - -CONFIG_LOG=y -CONFIG_BT_EXT_ADV=y - -CONFIG_BT_SMP=y -CONFIG_BT_GATT_CLIENT=y - -CONFIG_SETTINGS=y -CONFIG_BT_SETTINGS=y -CONFIG_FLASH=y -CONFIG_FLASH_PAGE_LAYOUT=y -CONFIG_NVS=y -CONFIG_FLASH_MAP=y -CONFIG_SETTINGS_NVS=y - -CONFIG_BT_GATT_DYNAMIC_DB=y diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.c b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.c deleted file mode 100644 index 31952cbe330..00000000000 --- a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.c +++ /dev/null @@ -1,182 +0,0 @@ -/** - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include -#include -#include - -#include -LOG_MODULE_REGISTER(test_utils, LOG_LEVEL_DBG); - -#include "bs_bt_utils.h" - -struct bt_conn *g_conn; -DEFINE_FLAG(flag_is_connected); - -void wait_connected(void) -{ - LOG_DBG("Wait for connection..."); - WAIT_FOR_FLAG(flag_is_connected); -} - -void wait_disconnected(void) -{ - LOG_DBG("Wait for disconnection..."); - WAIT_FOR_FLAG_UNSET(flag_is_connected); -} - -static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err) -{ - LOG_DBG("security changed"); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - UNSET_FLAG(flag_is_connected); -} - -struct bt_conn *get_g_conn(void) -{ - return g_conn; -} - -void clear_g_conn(void) -{ - struct bt_conn *conn; - - conn = g_conn; - g_conn = NULL; - BSIM_ASSERT(conn, "Test error: no g_conn!\n"); - bt_conn_unref(conn); -} - -static void connected(struct bt_conn *conn, uint8_t err) -{ - BSIM_ASSERT((!g_conn || (conn == g_conn)), "Unexpected new connection."); - - if (!g_conn) { - g_conn = bt_conn_ref(conn); - } - - if (err != 0) { - clear_g_conn(); - return; - } - - SET_FLAG(flag_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, - .security_changed = security_changed, -}; - -static void stop_scan_and_connect(const bt_addr_le_t *addr, - int8_t rssi, - uint8_t type, - struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - if (g_conn != NULL) { - return; - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Got scan result, connecting.. dst %s, RSSI %d\n", addr_str, rssi); - - err = bt_le_scan_stop(); - BSIM_ASSERT(!err, "Err bt_le_scan_stop %d", err); - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, &g_conn); - BSIM_ASSERT(!err, "Err bt_conn_le_create %d", err); -} - -void scan_connect_to_first_result(void) -{ - int err; - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, stop_scan_and_connect); - BSIM_ASSERT(!err, "Err bt_le_scan_start %d", err); -} - -void disconnect(void) -{ - int err; - - err = bt_conn_disconnect(g_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - BSIM_ASSERT(!err, "bt_conn_disconnect failed (%d)\n", err); -} - -void set_security(bt_security_t sec) -{ - int err; - - err = bt_conn_set_security(g_conn, sec); - BSIM_ASSERT(!err, "Err bt_conn_set_security %d", err); -} - -void create_adv(struct bt_le_ext_adv **adv) -{ - int err; - struct bt_le_adv_param params = {}; - - params.options |= BT_LE_ADV_OPT_CONNECTABLE; - params.options |= BT_LE_ADV_OPT_EXT_ADV; - - params.id = BT_ID_DEFAULT; - params.sid = 0; - params.interval_min = BT_GAP_ADV_FAST_INT_MIN_2; - params.interval_max = BT_GAP_ADV_FAST_INT_MAX_2; - - err = bt_le_ext_adv_create(¶ms, NULL, adv); - BSIM_ASSERT(!err, "bt_le_ext_adv_create failed (%d)\n", err); -} - -void start_adv(struct bt_le_ext_adv *adv) -{ - int err; - - err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT); - BSIM_ASSERT(!err, "bt_le_ext_adv_start failed (%d)\n", err); -} - -void stop_adv(struct bt_le_ext_adv *adv) -{ - int err; - - err = bt_le_ext_adv_stop(adv); - BSIM_ASSERT(!err, "bt_le_ext_adv_stop failed (%d)\n", err); -} - -/* The following flags are raised by events and lowered by test code. */ -DEFINE_FLAG(flag_pairing_complete); -DEFINE_FLAG(flag_bonded); -DEFINE_FLAG(flag_not_bonded); - -void pairing_complete(struct bt_conn *conn, bool bonded) -{ - LOG_DBG("pairing complete"); - SET_FLAG(flag_pairing_complete); - - if (bonded) { - SET_FLAG(flag_bonded); - LOG_DBG("Bonded status: true"); - } else { - SET_FLAG(flag_not_bonded); - LOG_DBG("Bonded status: false"); - } -} - -void pairing_failed(struct bt_conn *conn, enum bt_security_err err) -{ - FAIL("Pairing failed\n"); -} diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.h b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.h deleted file mode 100644 index 5ec34005e9f..00000000000 --- a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/bs_bt_utils.h +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" -#include "bs_tracing.h" - -#include -#include - -extern enum bst_result_t bst_result; - -#define DECLARE_FLAG(flag) extern atomic_t flag -#define DEFINE_FLAG(flag) atomic_t flag = (atomic_t) false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define WAIT_FOR_FLAG_UNSET(flag) \ - while ((bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define TAKE_FLAG(flag) \ - while (!(bool)atomic_cas(&flag, true, false)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define GET_FLAG(flag) (bool)atomic_get(&flag) - -#define BSIM_ASSERT(expr, ...) \ - do { \ - if (!(expr)) { \ - FAIL(__VA_ARGS__); \ - } \ - } while (0) - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -DECLARE_FLAG(flag_pairing_complete); -DECLARE_FLAG(flag_bonded); -DECLARE_FLAG(flag_not_bonded); - -void scan_connect_to_first_result(void); -struct bt_conn *get_g_conn(void); -void clear_g_conn(void); -void disconnect(void); -void wait_connected(void); -void wait_disconnected(void); -void create_adv(struct bt_le_ext_adv **adv); -void start_adv(struct bt_le_ext_adv *adv); -void stop_adv(struct bt_le_ext_adv *adv); -void set_security(bt_security_t sec); -void pairing_complete(struct bt_conn *conn, bool bonded); -void pairing_failed(struct bt_conn *conn, enum bt_security_err err); diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/central.c b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/central.c deleted file mode 100644 index ca45874e9cb..00000000000 --- a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/central.c +++ /dev/null @@ -1,195 +0,0 @@ -/** - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include -LOG_MODULE_REGISTER(test_central, LOG_LEVEL_DBG); - -#include "bs_bt_utils.h" - -DEFINE_FLAG(flag_discovered); -DEFINE_FLAG(flag_subscribed); -DEFINE_FLAG(flag_indicated); - -enum GATT_HANDLES { - SC, - CCC, - NUM_HANDLES, -}; - -static uint16_t gatt_handles[NUM_HANDLES] = {0}; - -static struct bt_gatt_subscribe_params subscribe_params; - -static void sc_subscribed(struct bt_conn *conn, - uint8_t err, - struct bt_gatt_subscribe_params *params) -{ - LOG_DBG("subscribed"); - SET_FLAG(flag_subscribed); -} - -static uint8_t sc_indicated(struct bt_conn *conn, - struct bt_gatt_subscribe_params *params, - const void *data, - uint16_t length) -{ - LOG_DBG("indication received"); - - SET_FLAG(flag_indicated); - - return BT_GATT_ITER_CONTINUE; -} - -static void subscribe(void) -{ - int err; - - subscribe_params.ccc_handle = gatt_handles[CCC]; - subscribe_params.value_handle = gatt_handles[SC]; - subscribe_params.value = BT_GATT_CCC_INDICATE; - subscribe_params.subscribe = sc_subscribed; - subscribe_params.notify = sc_indicated; - - err = bt_gatt_subscribe(get_g_conn(), &subscribe_params); - BSIM_ASSERT(!err, "bt_gatt_subscribe failed (%d)\n", err); - - WAIT_FOR_FLAG(flag_subscribed); -} - -static uint8_t discover_func(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - struct bt_gatt_discover_params *params) -{ - if (attr == NULL) { - for (size_t i = 0U; i < ARRAY_SIZE(gatt_handles); i++) { - LOG_DBG("handle[%d] = 0x%x", i, gatt_handles[i]); - BSIM_ASSERT(gatt_handles[i] != 0, "did not find all handles\n"); - } - - (void)memset(params, 0, sizeof(*params)); - SET_FLAG(flag_discovered); - - return BT_GATT_ITER_STOP; - } - - if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { - const struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; - static const struct bt_uuid_16 ccc_uuid = BT_UUID_INIT_16(BT_UUID_GATT_CCC_VAL); - - if (bt_uuid_cmp(chrc->uuid, BT_UUID_GATT_SC) == 0) { - int err; - - LOG_DBG("found sc"); - gatt_handles[SC] = chrc->value_handle; - - params->uuid = &ccc_uuid.uuid; - params->start_handle = attr->handle + 2; - params->type = BT_GATT_DISCOVER_DESCRIPTOR; - - err = bt_gatt_discover(conn, params); - BSIM_ASSERT(!err, "bt_gatt_discover failed (%d)\n", err); - - return BT_GATT_ITER_STOP; - } - - } else if (params->type == BT_GATT_DISCOVER_DESCRIPTOR && - bt_uuid_cmp(params->uuid, BT_UUID_GATT_CCC) == 0) { - LOG_DBG("found ccc"); - gatt_handles[CCC] = attr->handle; - SET_FLAG(flag_discovered); - - return BT_GATT_ITER_STOP; - } - - return BT_GATT_ITER_CONTINUE; -} - -static void gatt_discover(void) -{ - int err; - static struct bt_gatt_discover_params discover_params; - - discover_params.uuid = NULL; - discover_params.func = discover_func; - discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; - discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; - - err = bt_gatt_discover(get_g_conn(), &discover_params); - BSIM_ASSERT(!err, "bt_gatt_discover failed (%d)\n", err); - - WAIT_FOR_FLAG(flag_discovered); - - LOG_DBG("sc handle: %d", gatt_handles[SC]); - LOG_DBG("ccc handle: %d", gatt_handles[CCC]); -} - -void central(void) -{ - /* - * test goal: check that service changed indication is sent on - * reconnection when the server's GATT database has been updated since - * last connection - * - * the central will connect, bond with the peripheral and then - * disconnect after doing that, the central will try to connect again, - * this time it will not elevate the security - * - * to pass the test, the central will wait to receive the service - * changed indication - */ - - int err; - struct bt_conn_auth_info_cb bt_conn_auth_info_cb = { - .pairing_failed = pairing_failed, - .pairing_complete = pairing_complete, - }; - - err = bt_enable(NULL); - BSIM_ASSERT(!err, "bt_enable failed (%d)\n", err); - - err = bt_conn_auth_info_cb_register(&bt_conn_auth_info_cb); - BSIM_ASSERT(!err, "bt_conn_auth_info_cb_register failed.\n"); - - err = settings_load(); - BSIM_ASSERT(!err, "settings_load failed (%d)\n", err); - - scan_connect_to_first_result(); - wait_connected(); - - set_security(BT_SECURITY_L2); - - TAKE_FLAG(flag_pairing_complete); - TAKE_FLAG(flag_bonded); - - /* subscribe to the service changed indication */ - gatt_discover(); - subscribe(); - - disconnect(); - wait_disconnected(); - clear_g_conn(); - - scan_connect_to_first_result(); - wait_connected(); - - /* wait for service change indication */ - WAIT_FOR_FLAG(flag_indicated); - - PASS("PASS\n"); -} diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/main.c b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/main.c deleted file mode 100644 index f5ffbbc4677..00000000000 --- a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/main.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" -#include "bs_bt_utils.h" - -#define BS_SECONDS_TO_US(dur_sec) ((bs_time_t)dur_sec * USEC_PER_SEC) -#define TEST_TIMEOUT_SIMULATED BS_SECONDS_TO_US(60) - -extern void central(void); -extern void peripheral(void); - -static void test_tick(bs_time_t HW_device_time) -{ - bs_trace_debug_time(0, "Simulation ends now.\n"); - if (bst_result != Passed) { - bst_result = Failed; - bs_trace_error("Test did not pass before simulation ended.\n"); - } -} - -static void test_init(void) -{ - bst_ticker_set_next_tick_absolute(TEST_TIMEOUT_SIMULATED); - bst_result = In_progress; -} - -static const struct bst_test_instance test_to_add[] = { - { - .test_id = "central", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = central, - }, - { - .test_id = "peripheral", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = peripheral, - }, - BSTEST_END_MARKER, -}; - -static struct bst_test_list *install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_to_add); -}; - -bst_test_install_t test_installers[] = {install, NULL}; - -int main(void) -{ - bst_main(); - return 0; -} diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/peripheral.c b/tests/bsim/bluetooth/host/gatt/sc_indicate/src/peripheral.c deleted file mode 100644 index e15c00b60d7..00000000000 --- a/tests/bsim/bluetooth/host/gatt/sc_indicate/src/peripheral.c +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -#include - -#include -#include -#include -#include -#include -#include - -#include -LOG_MODULE_REGISTER(test_peripheral, LOG_LEVEL_DBG); - -#include "bs_bt_utils.h" - -#define UUID_1 BT_UUID_DECLARE_128(0xdb, 0x1f, 0xe2, 0x52, 0xf3, 0xc6, 0x43, 0x66, \ - 0xb3, 0x92, 0x5d, 0xc6, 0xe7, 0xc9, 0x59, 0x9d) -#define UUID_2 BT_UUID_DECLARE_128(0x3f, 0xa4, 0x7f, 0x44, 0x2e, 0x2a, 0x43, 0x05, \ - 0xab, 0x38, 0x07, 0x8d, 0x16, 0xbf, 0x99, 0xf1) - -static void new_svc_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) -{ - ARG_UNUSED(attr); - - bool notif_enabled = (value == BT_GATT_CCC_NOTIFY); - - LOG_DBG("CCC Update: notification %s", notif_enabled ? "enabled" : "disabled"); -} - -static struct bt_gatt_attr attrs[] = { - BT_GATT_PRIMARY_SERVICE(UUID_1), - BT_GATT_CHARACTERISTIC(UUID_2, BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_NONE, NULL, NULL, NULL), - BT_GATT_CCC(new_svc_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), -}; - -static struct bt_gatt_service svc = { - .attrs = attrs, - .attr_count = ARRAY_SIZE(attrs), -}; - -void peripheral(void) -{ - /* - * test goal: check that service changed indication is sent on - * reconnection when the server's GATT database has been updated since - * last connection - * - * the peripheral will wait for connection/disconnection, when - * disconnected it will register a new service, when reconnecting, the - * central should receive an indication - */ - - int err; - struct bt_le_ext_adv *adv = NULL; - - err = bt_enable(NULL); - BSIM_ASSERT(!err, "bt_enable failed (%d)\n", err); - - err = settings_load(); - BSIM_ASSERT(!err, "settings_load failed (%d)\n", err); - - create_adv(&adv); - start_adv(adv); - wait_connected(); - - stop_adv(adv); - - wait_disconnected(); - clear_g_conn(); - - /* add a new service to trigger the service changed indication */ - err = bt_gatt_service_register(&svc); - BSIM_ASSERT(!err, "bt_gatt_service_register failed (%d)\n", err); - LOG_DBG("New service added"); - - start_adv(adv); - wait_connected(); - - PASS("Done\n"); -} diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/_compile.sh deleted file mode 100755 index b07577a9878..00000000000 --- a/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/_compile.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu - -# Terminate running simulations (if any) -${BSIM_COMPONENTS_PATH}/common/stop_bsim.sh - -test_name='sc_indicate' - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -bsim_bin="${BSIM_OUT_PATH}/bin" -BOARD="${BOARD:-nrf52_bsim}" -test_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_gatt_${test_name}_prj_conf" - -west build -b nrf52_bsim -d build && \ - cp -v build/zephyr/zephyr.exe "${test_exe}" diff --git a/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/sc_indicate.sh b/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/sc_indicate.sh deleted file mode 100755 index b46ae13929c..00000000000 --- a/tests/bsim/bluetooth/host/gatt/sc_indicate/test_scripts/sc_indicate.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -source ${ZEPHYR_BASE}/tests/bsim/sh_common.source - -test_name='sc_indicate' -test_exe="bs_${BOARD}_tests_bsim_bluetooth_host_gatt_${test_name}_prj_conf" -simulation_id="${test_name}" -verbosity_level=2 -EXECUTE_TIMEOUT=30 - -cd ${BSIM_OUT_PATH}/bin - -Execute "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central - -Execute "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 - -wait_for_background_jobs From e338ab04c804894e86a514411d74acd28aca582d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:17 +0000 Subject: [PATCH 0754/1623] Revert "[nrf fromtree] modules: openthread: fix unused variable during `otPlatCryptoInit`" This reverts commit f25764149e1e0ce62254cd1759909641077becb5. Signed-off-by: Dominik Ermel --- modules/openthread/platform/crypto_psa.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/openthread/platform/crypto_psa.c b/modules/openthread/platform/crypto_psa.c index e5b234ce030..e61177ef4c4 100644 --- a/modules/openthread/platform/crypto_psa.c +++ b/modules/openthread/platform/crypto_psa.c @@ -137,8 +137,9 @@ void otPlatCryptoInit(void) * PSA with emulated TFM, Settings have to be initialized at the end of otPlatCryptoInit(), * to be available before storing Network Key. */ - __ASSERT_EVAL((void) settings_subsys_init(), int err = settings_subsys_init(), - !err, "Failed to initialize settings"); + int err = settings_subsys_init(); + + __ASSERT(!err, "Failed to initialize settings"); #endif } From fe0980d798a12acce810f0ed4f1e7af76154b48f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:17 +0000 Subject: [PATCH 0755/1623] Revert "[nrf fromtree] doc: migration-guide: inform about GPIO_AS_PINRESET deprecation" This reverts commit 532564650101b3c9a9ccbde8ceb3afe4973fc096. Signed-off-by: Dominik Ermel --- doc/releases/migration-guide-3.5.rst | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/doc/releases/migration-guide-3.5.rst b/doc/releases/migration-guide-3.5.rst index 8c059b630c6..3f367ec5e35 100644 --- a/doc/releases/migration-guide-3.5.rst +++ b/doc/releases/migration-guide-3.5.rst @@ -53,14 +53,3 @@ Recommended Changes &uicr { nfct-pins-as-gpios; }; - -* Nordic nRF based boards using :kconfig:option:`CONFIG_GPIO_AS_PINRESET` - to configure reset GPIO as nRESET, should instead set the new UICR - ``gpio-as-nreset`` property in devicetree. It can be set like this in the - board devicetree files: - - .. code-block:: devicetree - - &uicr { - gpio-as-nreset; - }; From 2a60290acacd15d1af864946f3d475a558fb5a94 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:17 +0000 Subject: [PATCH 0756/1623] Revert "[nrf fromtree] boards: arm: nrf-based: remove redundant GPIO_AS_PINRESET=n" This reverts commit 12bfbfc7d6751e17c63cf190e8bce8eac056c29f. Signed-off-by: Dominik Ermel --- boards/arm/holyiot_yj16019/Kconfig.defconfig | 3 +++ boards/arm/ruuvi_ruuvitag/ruuvi_ruuvitag_defconfig | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/boards/arm/holyiot_yj16019/Kconfig.defconfig b/boards/arm/holyiot_yj16019/Kconfig.defconfig index de2d63ad7c8..99373ad286a 100644 --- a/boards/arm/holyiot_yj16019/Kconfig.defconfig +++ b/boards/arm/holyiot_yj16019/Kconfig.defconfig @@ -8,6 +8,9 @@ if BOARD_HOLYIOT_YJ16019 config BOARD default "holyiot_yj16019" +config GPIO_AS_PINRESET + default n + config BT_CTLR default BT diff --git a/boards/arm/ruuvi_ruuvitag/ruuvi_ruuvitag_defconfig b/boards/arm/ruuvi_ruuvitag/ruuvi_ruuvitag_defconfig index 7e28dde8423..bd247788458 100644 --- a/boards/arm/ruuvi_ruuvitag/ruuvi_ruuvitag_defconfig +++ b/boards/arm/ruuvi_ruuvitag/ruuvi_ruuvitag_defconfig @@ -14,4 +14,8 @@ CONFIG_USE_SEGGER_RTT=y # Enable GPIO CONFIG_GPIO=y +# additional board options +# set y to disable R button +CONFIG_GPIO_AS_PINRESET=n + CONFIG_PINCTRL=y From 4c50091fb262b1fbe7974c019416622f5a6e6875 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:18 +0000 Subject: [PATCH 0757/1623] Revert "[nrf fromtree] soc: arm: nordic_nrf: nrf52: deprecate GPIO_AS_PINRESET" This reverts commit 4c425de49697cf8629615c7f7b25feee45180cf6. Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/nrf52/Kconfig.soc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf52/Kconfig.soc b/soc/arm/nordic_nrf/nrf52/Kconfig.soc index b2a915f168e..13a2fef932b 100644 --- a/soc/arm/nordic_nrf/nrf52/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf52/Kconfig.soc @@ -94,15 +94,8 @@ config SOC_DCDC_NRF52X_HV Enable nRF52 series System on Chip High Voltage DC/DC converter. config GPIO_AS_PINRESET - bool "[DEPRECATED] GPIO as pin reset (reset button)" - select DEPRECATED - help - This option is deprecated, use devicetree instead. Example - configuration: - - &uicr { - gpio-as-nreset; - }; + bool "GPIO as pin reset (reset button)" + default y config NRF_ENABLE_ICACHE bool "The instruction cache (I-Cache)" From eaa563167f6a66a38d0dba1320782ef92d36c7ae Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:18 +0000 Subject: [PATCH 0758/1623] Revert "[nrf fromtree] boards: arm: nrf9160dk_nrf52840: use UICR gpio-as-nreset property" This reverts commit 11cbd4dd27bdabd5191901422a694a273a4afc53. Signed-off-by: Dominik Ermel --- boards/arm/nrf9160dk_nrf52840/board.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/arm/nrf9160dk_nrf52840/board.c b/boards/arm/nrf9160dk_nrf52840/board.c index cdf00f8f3dd..e01b8eb64e7 100644 --- a/boards/arm/nrf9160dk_nrf52840/board.c +++ b/boards/arm/nrf9160dk_nrf52840/board.c @@ -27,7 +27,7 @@ LOG_MODULE_REGISTER(board_control, CONFIG_BOARD_NRF9160DK_LOG_LEVEL); * exposes the nRESET function (P0.18 in nRF52840), there is no need to * provide any additional GPIO configuration for it. */ -#define RESET_INPUT_IS_PINRESET (DT_PROP(DT_NODELABEL(uicr), gpio_as_nreset) && \ +#define RESET_INPUT_IS_PINRESET (IS_ENABLED(CONFIG_GPIO_AS_PINRESET) && \ GET_PORT(reset_input, gpios, 0) == 0 && \ GET_PIN(reset_input, gpios, 0) == 18) #define USE_RESET_GPIO \ From 7256dd505911f6a4eda7b15e6133047b48496c2a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:18 +0000 Subject: [PATCH 0759/1623] Revert "[nrf fromtree] boards: arm: nrf-based: move all boards to gpio-as-nreset dt property" This reverts commit 8c4003eacd144e0d1e593dd333d5bfa6c7a4d473. Signed-off-by: Dominik Ermel --- boards/arm/96b_nitrogen/96b_nitrogen.dts | 4 ---- boards/arm/96b_nitrogen/96b_nitrogen_defconfig | 3 +++ boards/arm/acn52832/acn52832.dts | 4 ---- boards/arm/acn52832/acn52832_defconfig | 3 +++ .../adafruit_feather_nrf52840/adafruit_feather_nrf52840.dts | 4 ---- .../adafruit_feather_nrf52840_defconfig | 3 +++ .../adafruit_itsybitsy_nrf52840.dts | 4 ---- .../adafruit_itsybitsy_nrf52840_defconfig | 2 ++ .../arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi | 4 ---- boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_defconfig | 3 +++ .../arduino_nano_33_ble/arduino_nano_33_ble_sense_defconfig | 3 +++ boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me.dts | 4 ---- .../arduino_nicla_sense_me/arduino_nicla_sense_me_defconfig | 3 +++ boards/arm/bl652_dvk/bl652_dvk.dts | 4 ---- boards/arm/bl652_dvk/bl652_dvk_defconfig | 3 +++ boards/arm/bl653_dvk/bl653_dvk.dts | 4 ---- boards/arm/bl653_dvk/bl653_dvk_defconfig | 3 +++ boards/arm/bl654_dvk/bl654_dvk.dts | 4 ---- boards/arm/bl654_dvk/bl654_dvk_defconfig | 3 +++ boards/arm/bl654_sensor_board/bl654_sensor_board.dts | 4 ---- boards/arm/bl654_sensor_board/bl654_sensor_board_defconfig | 3 +++ boards/arm/bl654_usb/bl654_usb.dts | 4 ---- boards/arm/bl654_usb/bl654_usb_defconfig | 3 +++ .../blueclover_plt_demo_v2_nrf52832.dts | 4 ---- .../blueclover_plt_demo_v2_nrf52832_defconfig | 3 +++ boards/arm/bt510/bt510.dts | 4 ---- boards/arm/bt510/bt510_defconfig | 3 +++ boards/arm/bt610/bt610.dts | 1 - boards/arm/bt610/bt610_defconfig | 3 +++ .../contextualelectronics_abc/contextualelectronics_abc.dts | 4 ---- .../contextualelectronics_abc_defconfig | 3 +++ boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev.dts | 4 ---- .../arm/decawave_dwm1001_dev/decawave_dwm1001_dev_defconfig | 3 +++ boards/arm/degu_evk/degu_evk.dts | 4 ---- boards/arm/degu_evk/degu_evk_defconfig | 1 + boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832.dts | 4 ---- .../ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832_defconfig | 3 +++ boards/arm/mg100/mg100.dts | 4 ---- boards/arm/mg100/mg100_defconfig | 3 +++ boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840.dts | 4 ---- boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840_defconfig | 3 +++ boards/arm/nrf52832_mdk/nrf52832_mdk.dts | 4 ---- boards/arm/nrf52832_mdk/nrf52832_mdk_defconfig | 3 +++ boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820.dts | 4 ---- boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820_defconfig | 3 +++ boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833.dts | 4 ---- boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833_defconfig | 3 +++ boards/arm/nrf52840_blip/nrf52840_blip.dts | 4 ---- boards/arm/nrf52840_blip/nrf52840_blip_defconfig | 3 +++ boards/arm/nrf52840_mdk/nrf52840_mdk.dts | 4 ---- boards/arm/nrf52840_mdk/nrf52840_mdk_defconfig | 3 +++ .../arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts | 1 - .../nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig | 3 +++ boards/arm/nrf52840_papyr/nrf52840_papyr.dts | 4 ---- boards/arm/nrf52840_papyr/nrf52840_papyr_defconfig | 3 +++ boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811.dts | 4 ---- boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811_defconfig | 3 +++ boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts | 4 ---- boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig | 3 +++ .../arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts | 1 - .../nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig | 3 +++ boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather.dts | 4 ---- .../nrf52_adafruit_feather/nrf52_adafruit_feather_defconfig | 3 +++ boards/arm/nrf52_sparkfun/nrf52_sparkfun.dts | 4 ---- boards/arm/nrf52_sparkfun/nrf52_sparkfun_defconfig | 3 +++ boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts | 4 ---- boards/arm/nrf52_vbluno52/nrf52_vbluno52_defconfig | 3 +++ boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805.dts | 4 ---- boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805_defconfig | 3 +++ boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810.dts | 4 ---- boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810_defconfig | 3 +++ boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts | 4 ---- boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig | 3 +++ boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840.dts | 4 ---- boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840_defconfig | 3 +++ boards/arm/pan1770_evb/pan1770_evb.dts | 4 ---- boards/arm/pan1770_evb/pan1770_evb_defconfig | 3 +++ boards/arm/pan1780_evb/pan1780_evb.dts | 4 ---- boards/arm/pan1780_evb/pan1780_evb_defconfig | 3 +++ boards/arm/pan1781_evb/pan1781_evb.dts | 4 ---- boards/arm/pan1781_evb/pan1781_evb_defconfig | 3 +++ boards/arm/pan1782_evb/pan1782_evb.dts | 4 ---- boards/arm/pan1782_evb/pan1782_evb_defconfig | 3 +++ boards/arm/particle_argon/particle_argon.dts | 4 ---- boards/arm/particle_argon/particle_argon_defconfig | 3 +++ boards/arm/particle_boron/particle_boron.dts | 4 ---- boards/arm/particle_boron/particle_boron_defconfig | 3 +++ boards/arm/particle_xenon/particle_xenon.dts | 4 ---- boards/arm/particle_xenon/particle_xenon_defconfig | 3 +++ boards/arm/pinetime_devkit0/pinetime_devkit0.dts | 4 ---- boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig | 3 +++ boards/arm/pinnacle_100_dvk/pinnacle_100_dvk.dts | 4 ---- boards/arm/pinnacle_100_dvk/pinnacle_100_dvk_defconfig | 3 +++ boards/arm/rak4631_nrf52840/rak4631_nrf52840.dts | 4 ---- boards/arm/rak4631_nrf52840/rak4631_nrf52840_defconfig | 3 +++ .../raytac_mdbt50q_db_33_nrf52833.dts | 4 ---- .../raytac_mdbt50q_db_33_nrf52833_defconfig | 3 +++ .../raytac_mdbt50q_db_40_nrf52840.dts | 4 ---- .../raytac_mdbt50q_db_40_nrf52840_defconfig | 3 +++ boards/arm/reel_board/dts/reel_board.dtsi | 4 ---- boards/arm/reel_board/reel_board_defconfig | 3 +++ boards/arm/reel_board/reel_board_v2_defconfig | 3 +++ .../arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832.dts | 4 ---- .../ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832_defconfig | 3 +++ .../arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810.dts | 4 ---- .../ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810_defconfig | 3 +++ .../arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840.dts | 4 ---- .../ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840_defconfig | 3 +++ .../arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840.dts | 4 ---- .../ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840_defconfig | 3 +++ .../arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811.dts | 4 ---- .../ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811_defconfig | 3 +++ .../arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840.dts | 4 ---- .../ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840_defconfig | 3 +++ boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832.dts | 4 ---- .../ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832_defconfig | 3 +++ boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832.dts | 4 ---- .../ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832_defconfig | 3 +++ boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840.dts | 4 ---- .../ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840_defconfig | 3 +++ boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833.dts | 4 ---- .../ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833_defconfig | 3 +++ boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805.dts | 4 ---- .../we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805_defconfig | 3 +++ boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832.dts | 4 ---- .../we_proteus2ev_nrf52832/we_proteus2ev_nrf52832_defconfig | 3 +++ boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840.dts | 4 ---- .../we_proteus3ev_nrf52840/we_proteus3ev_nrf52840_defconfig | 3 +++ boards/arm/xiao_ble/xiao_ble_common.dtsi | 4 ---- boards/arm/xiao_ble/xiao_ble_defconfig | 3 +++ boards/arm/xiao_ble/xiao_ble_sense_defconfig | 3 +++ 131 files changed, 198 insertions(+), 247 deletions(-) diff --git a/boards/arm/96b_nitrogen/96b_nitrogen.dts b/boards/arm/96b_nitrogen/96b_nitrogen.dts index 69148a032d7..d5bac1cd6d3 100644 --- a/boards/arm/96b_nitrogen/96b_nitrogen.dts +++ b/boards/arm/96b_nitrogen/96b_nitrogen.dts @@ -58,10 +58,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/96b_nitrogen/96b_nitrogen_defconfig b/boards/arm/96b_nitrogen/96b_nitrogen_defconfig index e804b43da5c..500c469813b 100644 --- a/boards/arm/96b_nitrogen/96b_nitrogen_defconfig +++ b/boards/arm/96b_nitrogen/96b_nitrogen_defconfig @@ -16,4 +16,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/acn52832/acn52832.dts b/boards/arm/acn52832/acn52832.dts index ca9f5046fba..1e01221f652 100644 --- a/boards/arm/acn52832/acn52832.dts +++ b/boards/arm/acn52832/acn52832.dts @@ -45,10 +45,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/acn52832/acn52832_defconfig b/boards/arm/acn52832/acn52832_defconfig index 2bb13882f8c..6b1ae1a7ba7 100644 --- a/boards/arm/acn52832/acn52832_defconfig +++ b/boards/arm/acn52832/acn52832_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# Enable P0_21 as RST +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840.dts b/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840.dts index 284a4d24542..5024f43fd81 100644 --- a/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840.dts +++ b/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840.dts @@ -61,10 +61,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840_defconfig b/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840_defconfig index 1f42d1a0aa4..8d892db30f2 100644 --- a/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840_defconfig +++ b/boards/arm/adafruit_feather_nrf52840/adafruit_feather_nrf52840_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840.dts b/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840.dts index 103e18d8328..6e827388aef 100644 --- a/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840.dts +++ b/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840.dts @@ -55,10 +55,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840_defconfig b/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840_defconfig index e5a88c27fb3..bc27efcdd29 100644 --- a/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840_defconfig +++ b/boards/arm/adafruit_itsybitsy_nrf52840/adafruit_itsybitsy_nrf52840_defconfig @@ -17,6 +17,8 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y CONFIG_PINCTRL=y # Flashing diff --git a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi index 200db7f94c7..60c0d63920c 100644 --- a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi +++ b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi @@ -177,10 +177,6 @@ arduino_spi: &spi2 { pinctrl-names = "default", "sleep"; }; -&uicr { - gpio-as-nreset; -}; - &gpio0 { status = "okay"; }; diff --git a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_defconfig b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_defconfig index dcdc0c8a836..2d91725aaf9 100644 --- a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_defconfig +++ b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_defconfig @@ -20,4 +20,7 @@ CONFIG_UART_CONSOLE=y CONFIG_BOOTLOADER_BOSSA=y CONFIG_BOOTLOADER_BOSSA_LEGACY=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_sense_defconfig b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_sense_defconfig index 4604c6bf386..8ef8ece861c 100644 --- a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_sense_defconfig +++ b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_sense_defconfig @@ -20,4 +20,7 @@ CONFIG_UART_CONSOLE=y CONFIG_BOOTLOADER_BOSSA=y CONFIG_BOOTLOADER_BOSSA_LEGACY=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me.dts b/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me.dts index 2329853a1a3..ada4c76441c 100644 --- a/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me.dts +++ b/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me.dts @@ -45,10 +45,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me_defconfig b/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me_defconfig index c2f2b95cc72..396d37d36e0 100644 --- a/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me_defconfig +++ b/boards/arm/arduino_nicla_sense_me/arduino_nicla_sense_me_defconfig @@ -18,5 +18,8 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # enable pin controller CONFIG_PINCTRL=y diff --git a/boards/arm/bl652_dvk/bl652_dvk.dts b/boards/arm/bl652_dvk/bl652_dvk.dts index f2cffbd819b..5569f1323c0 100644 --- a/boards/arm/bl652_dvk/bl652_dvk.dts +++ b/boards/arm/bl652_dvk/bl652_dvk.dts @@ -68,10 +68,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/bl652_dvk/bl652_dvk_defconfig b/boards/arm/bl652_dvk/bl652_dvk_defconfig index 5302fa8d53f..1ca971e2546 100644 --- a/boards/arm/bl652_dvk/bl652_dvk_defconfig +++ b/boards/arm/bl652_dvk/bl652_dvk_defconfig @@ -21,6 +21,9 @@ CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y CONFIG_RTT_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # 32kHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y diff --git a/boards/arm/bl653_dvk/bl653_dvk.dts b/boards/arm/bl653_dvk/bl653_dvk.dts index ba8fa3658d2..ceb91aeb96f 100644 --- a/boards/arm/bl653_dvk/bl653_dvk.dts +++ b/boards/arm/bl653_dvk/bl653_dvk.dts @@ -91,10 +91,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/bl653_dvk/bl653_dvk_defconfig b/boards/arm/bl653_dvk/bl653_dvk_defconfig index 83b73ef4435..4933055c93c 100644 --- a/boards/arm/bl653_dvk/bl653_dvk_defconfig +++ b/boards/arm/bl653_dvk/bl653_dvk_defconfig @@ -20,6 +20,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # 32kHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y diff --git a/boards/arm/bl654_dvk/bl654_dvk.dts b/boards/arm/bl654_dvk/bl654_dvk.dts index 7ede69427de..b99435696d1 100644 --- a/boards/arm/bl654_dvk/bl654_dvk.dts +++ b/boards/arm/bl654_dvk/bl654_dvk.dts @@ -91,10 +91,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/bl654_dvk/bl654_dvk_defconfig b/boards/arm/bl654_dvk/bl654_dvk_defconfig index 976495f7e88..aa2238cda87 100644 --- a/boards/arm/bl654_dvk/bl654_dvk_defconfig +++ b/boards/arm/bl654_dvk/bl654_dvk_defconfig @@ -21,6 +21,9 @@ CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y CONFIG_RTT_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # 32kHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y diff --git a/boards/arm/bl654_sensor_board/bl654_sensor_board.dts b/boards/arm/bl654_sensor_board/bl654_sensor_board.dts index c43354f2705..1c2949ee2e8 100644 --- a/boards/arm/bl654_sensor_board/bl654_sensor_board.dts +++ b/boards/arm/bl654_sensor_board/bl654_sensor_board.dts @@ -56,10 +56,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/bl654_sensor_board/bl654_sensor_board_defconfig b/boards/arm/bl654_sensor_board/bl654_sensor_board_defconfig index e92c2c4005f..259fac9d309 100644 --- a/boards/arm/bl654_sensor_board/bl654_sensor_board_defconfig +++ b/boards/arm/bl654_sensor_board/bl654_sensor_board_defconfig @@ -17,6 +17,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# Additional board options +CONFIG_GPIO_AS_PINRESET=y + # 32KHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM=y diff --git a/boards/arm/bl654_usb/bl654_usb.dts b/boards/arm/bl654_usb/bl654_usb.dts index 80600290dbf..2cc6850a468 100644 --- a/boards/arm/bl654_usb/bl654_usb.dts +++ b/boards/arm/bl654_usb/bl654_usb.dts @@ -47,10 +47,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &gpio0 { status = "okay"; }; diff --git a/boards/arm/bl654_usb/bl654_usb_defconfig b/boards/arm/bl654_usb/bl654_usb_defconfig index 983150c35d9..59c26ddb4d7 100644 --- a/boards/arm/bl654_usb/bl654_usb_defconfig +++ b/boards/arm/bl654_usb/bl654_usb_defconfig @@ -19,6 +19,9 @@ CONFIG_GPIO=y # Enable USB CONFIG_USB_DEVICE_STACK=y +# Additional board options +CONFIG_GPIO_AS_PINRESET=y + # 32KHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM=y diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts index 4c49979bb0a..cf7dd7a52de 100644 --- a/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts @@ -48,10 +48,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status ="okay"; }; diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig index 301a23af362..52f089ba0d6 100644 --- a/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig @@ -24,4 +24,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/bt510/bt510.dts b/boards/arm/bt510/bt510.dts index 984b098e5d5..74818be0d7c 100644 --- a/boards/arm/bt510/bt510.dts +++ b/boards/arm/bt510/bt510.dts @@ -72,10 +72,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/bt510/bt510_defconfig b/boards/arm/bt510/bt510_defconfig index eb769cc9465..fd86ea3f0f2 100644 --- a/boards/arm/bt510/bt510_defconfig +++ b/boards/arm/bt510/bt510_defconfig @@ -17,6 +17,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# Additional board options +CONFIG_GPIO_AS_PINRESET=y + # 32KHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM=y diff --git a/boards/arm/bt610/bt610.dts b/boards/arm/bt610/bt610.dts index 489401a5fb3..6bbe8d57fe3 100644 --- a/boards/arm/bt610/bt610.dts +++ b/boards/arm/bt610/bt610.dts @@ -145,7 +145,6 @@ &uicr { nfct-pins-as-gpios; - gpio-as-nreset; }; &gpio0 { diff --git a/boards/arm/bt610/bt610_defconfig b/boards/arm/bt610/bt610_defconfig index d1d7226fade..1c77ed9e37b 100644 --- a/boards/arm/bt610/bt610_defconfig +++ b/boards/arm/bt610/bt610_defconfig @@ -17,6 +17,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# Additional board options +CONFIG_GPIO_AS_PINRESET=y + # Enable hardware stack protection CONFIG_HW_STACK_PROTECTION=y diff --git a/boards/arm/contextualelectronics_abc/contextualelectronics_abc.dts b/boards/arm/contextualelectronics_abc/contextualelectronics_abc.dts index 6f60b1ddfed..ebc866afeff 100644 --- a/boards/arm/contextualelectronics_abc/contextualelectronics_abc.dts +++ b/boards/arm/contextualelectronics_abc/contextualelectronics_abc.dts @@ -25,10 +25,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/contextualelectronics_abc/contextualelectronics_abc_defconfig b/boards/arm/contextualelectronics_abc/contextualelectronics_abc_defconfig index 7a3055b9c82..bb841469339 100644 --- a/boards/arm/contextualelectronics_abc/contextualelectronics_abc_defconfig +++ b/boards/arm/contextualelectronics_abc/contextualelectronics_abc_defconfig @@ -20,4 +20,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# Additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev.dts b/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev.dts index a1c415fc299..75510faf4a6 100644 --- a/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev.dts +++ b/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev.dts @@ -84,10 +84,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev_defconfig b/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev_defconfig index 4cb6022e7ae..89d31bfd45b 100644 --- a/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev_defconfig +++ b/boards/arm/decawave_dwm1001_dev/decawave_dwm1001_dev_defconfig @@ -21,4 +21,7 @@ CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y CONFIG_RTT_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/degu_evk/degu_evk.dts b/boards/arm/degu_evk/degu_evk.dts index eb3329726e9..caa134752e0 100644 --- a/boards/arm/degu_evk/degu_evk.dts +++ b/boards/arm/degu_evk/degu_evk.dts @@ -92,10 +92,6 @@ status ="okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status ="okay"; }; diff --git a/boards/arm/degu_evk/degu_evk_defconfig b/boards/arm/degu_evk/degu_evk_defconfig index e003438c3dc..7b9d7737481 100644 --- a/boards/arm/degu_evk/degu_evk_defconfig +++ b/boards/arm/degu_evk/degu_evk_defconfig @@ -17,6 +17,7 @@ CONFIG_USB_DEVICE_STACK=y # additional board options CONFIG_GPIO=y +CONFIG_GPIO_AS_PINRESET=y # required to enable 3V3 power rail and Vin1 monitor CONFIG_REGULATOR=y diff --git a/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832.dts b/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832.dts index 31eb0cc7524..9fa240cb5ae 100644 --- a/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832.dts +++ b/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832.dts @@ -75,10 +75,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832_defconfig b/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832_defconfig index 05acf2ca945..3e1778de525 100644 --- a/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832_defconfig +++ b/boards/arm/ebyte_e73_tbb_nrf52832/ebyte_e73_tbb_nrf52832_defconfig @@ -23,4 +23,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# Additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/mg100/mg100.dts b/boards/arm/mg100/mg100.dts index 0d33fd32151..512ca901010 100644 --- a/boards/arm/mg100/mg100.dts +++ b/boards/arm/mg100/mg100.dts @@ -65,10 +65,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/mg100/mg100_defconfig b/boards/arm/mg100/mg100_defconfig index bb7d09dabf2..93f55f3d0a4 100644 --- a/boards/arm/mg100/mg100_defconfig +++ b/boards/arm/mg100/mg100_defconfig @@ -18,6 +18,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# Additional board options +CONFIG_GPIO_AS_PINRESET=y + # 32KHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM=y diff --git a/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840.dts b/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840.dts index af0ea59794c..077eb4a1657 100644 --- a/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840.dts +++ b/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840.dts @@ -150,10 +150,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840_defconfig b/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840_defconfig index af230adb18a..56d8497b43a 100644 --- a/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840_defconfig +++ b/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840_defconfig @@ -23,4 +23,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52832_mdk/nrf52832_mdk.dts b/boards/arm/nrf52832_mdk/nrf52832_mdk.dts index c51002c6497..348a5b79745 100644 --- a/boards/arm/nrf52832_mdk/nrf52832_mdk.dts +++ b/boards/arm/nrf52832_mdk/nrf52832_mdk.dts @@ -86,10 +86,6 @@ }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52832_mdk/nrf52832_mdk_defconfig b/boards/arm/nrf52832_mdk/nrf52832_mdk_defconfig index 8993b59f938..2c283bda97e 100644 --- a/boards/arm/nrf52832_mdk/nrf52832_mdk_defconfig +++ b/boards/arm/nrf52832_mdk/nrf52832_mdk_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820.dts b/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820.dts index 4942dd6daa0..f70d6649aa8 100644 --- a/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820.dts +++ b/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820.dts @@ -99,10 +99,6 @@ clock-prescaler = <8>; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820_defconfig b/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820_defconfig index 9ef66860ab3..9bbc4da98cb 100644 --- a/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820_defconfig +++ b/boards/arm/nrf52833dk_nrf52820/nrf52833dk_nrf52820_defconfig @@ -23,4 +23,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833.dts b/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833.dts index b488b5d1ff3..0d1725d5bbb 100644 --- a/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833.dts +++ b/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833.dts @@ -127,10 +127,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833_defconfig b/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833_defconfig index 9cbee72b2e7..7fe9f4e480c 100644 --- a/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833_defconfig +++ b/boards/arm/nrf52833dk_nrf52833/nrf52833dk_nrf52833_defconfig @@ -23,4 +23,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840_blip/nrf52840_blip.dts b/boards/arm/nrf52840_blip/nrf52840_blip.dts index e641c60bd1f..112d22799bc 100644 --- a/boards/arm/nrf52840_blip/nrf52840_blip.dts +++ b/boards/arm/nrf52840_blip/nrf52840_blip.dts @@ -66,10 +66,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52840_blip/nrf52840_blip_defconfig b/boards/arm/nrf52840_blip/nrf52840_blip_defconfig index 811a88de939..82c0146ecf1 100644 --- a/boards/arm/nrf52840_blip/nrf52840_blip_defconfig +++ b/boards/arm/nrf52840_blip/nrf52840_blip_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840_mdk/nrf52840_mdk.dts b/boards/arm/nrf52840_mdk/nrf52840_mdk.dts index 2439b0c2aca..0ed4addb069 100644 --- a/boards/arm/nrf52840_mdk/nrf52840_mdk.dts +++ b/boards/arm/nrf52840_mdk/nrf52840_mdk.dts @@ -90,10 +90,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52840_mdk/nrf52840_mdk_defconfig b/boards/arm/nrf52840_mdk/nrf52840_mdk_defconfig index e4c79a2bf88..f0ed2a2fbad 100644 --- a/boards/arm/nrf52840_mdk/nrf52840_mdk_defconfig +++ b/boards/arm/nrf52840_mdk/nrf52840_mdk_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts index 4e13783d656..8e835597c78 100644 --- a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts +++ b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts @@ -89,7 +89,6 @@ &uicr { nfct-pins-as-gpios; - gpio-as-nreset; }; &gpio0 { diff --git a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig index 8701863e99a..90850c10e0a 100644 --- a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig +++ b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig @@ -13,4 +13,7 @@ CONFIG_HW_STACK_PROTECTION=y # enable GPIO CONFIG_GPIO=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840_papyr/nrf52840_papyr.dts b/boards/arm/nrf52840_papyr/nrf52840_papyr.dts index 0a9d8ff4724..acbb09d2df2 100644 --- a/boards/arm/nrf52840_papyr/nrf52840_papyr.dts +++ b/boards/arm/nrf52840_papyr/nrf52840_papyr.dts @@ -85,10 +85,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52840_papyr/nrf52840_papyr_defconfig b/boards/arm/nrf52840_papyr/nrf52840_papyr_defconfig index 4a5e737cd14..0ad48d7f940 100644 --- a/boards/arm/nrf52840_papyr/nrf52840_papyr_defconfig +++ b/boards/arm/nrf52840_papyr/nrf52840_papyr_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811.dts b/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811.dts index a53a174be15..eb99beca22f 100644 --- a/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811.dts +++ b/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811.dts @@ -97,10 +97,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811_defconfig b/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811_defconfig index 2c6b7f2fc82..36553a757eb 100644 --- a/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811_defconfig +++ b/boards/arm/nrf52840dk_nrf52811/nrf52840dk_nrf52811_defconfig @@ -22,6 +22,9 @@ CONFIG_UART_CONSOLE=y # enable GPIO CONFIG_GPIO=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # Bluetooth not enabled by default on nRF52811 due to RAM limitations when # running the default set of kernel tests. # Enable this on your prj.conf to include Bluetooth support diff --git a/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts b/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts index 96006ec4722..ba5d94738a6 100644 --- a/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts +++ b/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts @@ -139,10 +139,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig b/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig index 9f1232a8f0a..100d91ed320 100644 --- a/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig +++ b/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig @@ -23,4 +23,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts index dcf9fb690d1..93b59baa920 100644 --- a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts +++ b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts @@ -101,7 +101,6 @@ &uicr { nfct-pins-as-gpios; - gpio-as-nreset; }; &gpio0 { diff --git a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig index c367a90d5ef..32a9d03b44e 100644 --- a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig +++ b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig @@ -13,6 +13,9 @@ CONFIG_HW_STACK_PROTECTION=y # enable GPIO CONFIG_GPIO=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y # Board Kconfig.defconfig enables USB CDC ACM and should disable USB remote diff --git a/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather.dts b/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather.dts index c29ca8000dc..4412d3c492d 100644 --- a/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather.dts +++ b/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather.dts @@ -70,10 +70,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather_defconfig b/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather_defconfig index 19aaa3825d1..42948633b2f 100644 --- a/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather_defconfig +++ b/boards/arm/nrf52_adafruit_feather/nrf52_adafruit_feather_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52_sparkfun/nrf52_sparkfun.dts b/boards/arm/nrf52_sparkfun/nrf52_sparkfun.dts index 60de01f0bb0..618bd670ad1 100644 --- a/boards/arm/nrf52_sparkfun/nrf52_sparkfun.dts +++ b/boards/arm/nrf52_sparkfun/nrf52_sparkfun.dts @@ -50,10 +50,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52_sparkfun/nrf52_sparkfun_defconfig b/boards/arm/nrf52_sparkfun/nrf52_sparkfun_defconfig index 2a21dc07192..944fc20b9c8 100644 --- a/boards/arm/nrf52_sparkfun/nrf52_sparkfun_defconfig +++ b/boards/arm/nrf52_sparkfun/nrf52_sparkfun_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# Enable P0_21 as RST +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts b/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts index b622a1a23ea..8b276c5fed7 100644 --- a/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts +++ b/boards/arm/nrf52_vbluno52/nrf52_vbluno52.dts @@ -49,10 +49,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52_vbluno52/nrf52_vbluno52_defconfig b/boards/arm/nrf52_vbluno52/nrf52_vbluno52_defconfig index fac5419e6f6..97f4efbc236 100644 --- a/boards/arm/nrf52_vbluno52/nrf52_vbluno52_defconfig +++ b/boards/arm/nrf52_vbluno52/nrf52_vbluno52_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805.dts b/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805.dts index e0eaa911a06..29257e7a0b2 100644 --- a/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805.dts +++ b/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805.dts @@ -89,10 +89,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpio0 { status = "okay"; }; diff --git a/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805_defconfig b/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805_defconfig index 6e275e63f35..31571f10fb4 100644 --- a/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805_defconfig +++ b/boards/arm/nrf52dk_nrf52805/nrf52dk_nrf52805_defconfig @@ -20,6 +20,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# Additional board options +CONFIG_GPIO_AS_PINRESET=y + # Bluetooth not enabled by default on nRF52805 due to RAM limitations when # running the default set of kernel tests. diff --git a/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810.dts b/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810.dts index 4d4600f1222..823a3db7f7e 100644 --- a/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810.dts +++ b/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810.dts @@ -91,10 +91,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810_defconfig b/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810_defconfig index 93706e89d0a..5873f1d2e9a 100644 --- a/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810_defconfig +++ b/boards/arm/nrf52dk_nrf52810/nrf52dk_nrf52810_defconfig @@ -20,6 +20,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # Bluetooth not enabled by default on nRF52810 due to RAM limitations when # running the default set of kernel tests. # Enable this on your prj.conf to include Bluetooth support diff --git a/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts b/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts index 687bba9254a..3002a1841c9 100644 --- a/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts +++ b/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts @@ -138,10 +138,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig b/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig index 23e1f4c249a..547ff67c348 100644 --- a/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig +++ b/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832_defconfig @@ -23,4 +23,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840.dts b/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840.dts index 07dc648b853..c8cc706750c 100644 --- a/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840.dts +++ b/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840.dts @@ -141,10 +141,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840_defconfig b/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840_defconfig index 073409dbba1..c15e39669ea 100644 --- a/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840_defconfig +++ b/boards/arm/nrf9160dk_nrf52840/nrf9160dk_nrf52840_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/pan1770_evb/pan1770_evb.dts b/boards/arm/pan1770_evb/pan1770_evb.dts index 2b2a9d561a7..d8fbe8fe9df 100644 --- a/boards/arm/pan1770_evb/pan1770_evb.dts +++ b/boards/arm/pan1770_evb/pan1770_evb.dts @@ -137,10 +137,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/pan1770_evb/pan1770_evb_defconfig b/boards/arm/pan1770_evb/pan1770_evb_defconfig index 1d90cb82c25..1192aca064e 100644 --- a/boards/arm/pan1770_evb/pan1770_evb_defconfig +++ b/boards/arm/pan1770_evb/pan1770_evb_defconfig @@ -26,5 +26,8 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # using pinctrl CONFIG_PINCTRL=y diff --git a/boards/arm/pan1780_evb/pan1780_evb.dts b/boards/arm/pan1780_evb/pan1780_evb.dts index da9a7e7fdb8..4f4dbca98ac 100644 --- a/boards/arm/pan1780_evb/pan1780_evb.dts +++ b/boards/arm/pan1780_evb/pan1780_evb.dts @@ -137,10 +137,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/pan1780_evb/pan1780_evb_defconfig b/boards/arm/pan1780_evb/pan1780_evb_defconfig index ca1a58c3b74..0c459f39aac 100644 --- a/boards/arm/pan1780_evb/pan1780_evb_defconfig +++ b/boards/arm/pan1780_evb/pan1780_evb_defconfig @@ -26,5 +26,8 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # using pinctrl CONFIG_PINCTRL=y diff --git a/boards/arm/pan1781_evb/pan1781_evb.dts b/boards/arm/pan1781_evb/pan1781_evb.dts index 8ab6af51ea9..7d9b7028e35 100644 --- a/boards/arm/pan1781_evb/pan1781_evb.dts +++ b/boards/arm/pan1781_evb/pan1781_evb.dts @@ -98,10 +98,6 @@ clock-prescaler = <8>; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/pan1781_evb/pan1781_evb_defconfig b/boards/arm/pan1781_evb/pan1781_evb_defconfig index dacffd42175..76436dd2ccd 100644 --- a/boards/arm/pan1781_evb/pan1781_evb_defconfig +++ b/boards/arm/pan1781_evb/pan1781_evb_defconfig @@ -26,5 +26,8 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # using pinctrl CONFIG_PINCTRL=y diff --git a/boards/arm/pan1782_evb/pan1782_evb.dts b/boards/arm/pan1782_evb/pan1782_evb.dts index fdc86f792ec..cf169e41d87 100644 --- a/boards/arm/pan1782_evb/pan1782_evb.dts +++ b/boards/arm/pan1782_evb/pan1782_evb.dts @@ -98,10 +98,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/pan1782_evb/pan1782_evb_defconfig b/boards/arm/pan1782_evb/pan1782_evb_defconfig index e6a6cc1d4a5..0bdeb9d9127 100644 --- a/boards/arm/pan1782_evb/pan1782_evb_defconfig +++ b/boards/arm/pan1782_evb/pan1782_evb_defconfig @@ -26,6 +26,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # using pinctrl CONFIG_PINCTRL=y diff --git a/boards/arm/particle_argon/particle_argon.dts b/boards/arm/particle_argon/particle_argon.dts index a88199fe40b..fa2314b6fb2 100644 --- a/boards/arm/particle_argon/particle_argon.dts +++ b/boards/arm/particle_argon/particle_argon.dts @@ -32,10 +32,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &uart1 { /* ESP32 */ compatible = "nordic,nrf-uarte"; current-speed = <921600>; diff --git a/boards/arm/particle_argon/particle_argon_defconfig b/boards/arm/particle_argon/particle_argon_defconfig index c29f62babd4..784364e9edc 100644 --- a/boards/arm/particle_argon/particle_argon_defconfig +++ b/boards/arm/particle_argon/particle_argon_defconfig @@ -21,4 +21,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/particle_boron/particle_boron.dts b/boards/arm/particle_boron/particle_boron.dts index 06e75a5a52e..3e20eddb94f 100644 --- a/boards/arm/particle_boron/particle_boron.dts +++ b/boards/arm/particle_boron/particle_boron.dts @@ -36,10 +36,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &i2c1 { /* power monitoring */ compatible = "nordic,nrf-twi"; status = "okay"; diff --git a/boards/arm/particle_boron/particle_boron_defconfig b/boards/arm/particle_boron/particle_boron_defconfig index 622a3169073..6963e9d9393 100644 --- a/boards/arm/particle_boron/particle_boron_defconfig +++ b/boards/arm/particle_boron/particle_boron_defconfig @@ -20,6 +20,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y # Fix the priority to enable the modem line's serial buffer diff --git a/boards/arm/particle_xenon/particle_xenon.dts b/boards/arm/particle_xenon/particle_xenon.dts index 2d64ba119b2..22252c077f3 100644 --- a/boards/arm/particle_xenon/particle_xenon.dts +++ b/boards/arm/particle_xenon/particle_xenon.dts @@ -33,10 +33,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &uart1 { /* feather UART2 */ compatible = "nordic,nrf-uarte"; current-speed = <115200>; diff --git a/boards/arm/particle_xenon/particle_xenon_defconfig b/boards/arm/particle_xenon/particle_xenon_defconfig index 2495d886b41..5f90beabba0 100644 --- a/boards/arm/particle_xenon/particle_xenon_defconfig +++ b/boards/arm/particle_xenon/particle_xenon_defconfig @@ -20,4 +20,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/pinetime_devkit0/pinetime_devkit0.dts b/boards/arm/pinetime_devkit0/pinetime_devkit0.dts index 207c8934880..fb377fd89e1 100644 --- a/boards/arm/pinetime_devkit0/pinetime_devkit0.dts +++ b/boards/arm/pinetime_devkit0/pinetime_devkit0.dts @@ -83,10 +83,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig b/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig index fc8f45eceaa..ad7442afe0d 100644 --- a/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig +++ b/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig @@ -13,4 +13,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# use P0.21 as RST +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk.dts b/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk.dts index 19f9e6ff41e..62664e67b5e 100644 --- a/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk.dts +++ b/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk.dts @@ -88,10 +88,6 @@ status ="okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status ="okay"; }; diff --git a/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk_defconfig b/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk_defconfig index 010c72e8c07..7f11757ab5d 100644 --- a/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk_defconfig +++ b/boards/arm/pinnacle_100_dvk/pinnacle_100_dvk_defconfig @@ -22,6 +22,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# Additional board options +CONFIG_GPIO_AS_PINRESET=y + # 32KHz clock source CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM=y diff --git a/boards/arm/rak4631_nrf52840/rak4631_nrf52840.dts b/boards/arm/rak4631_nrf52840/rak4631_nrf52840.dts index 454c4bb84b1..43b2dd0de28 100644 --- a/boards/arm/rak4631_nrf52840/rak4631_nrf52840.dts +++ b/boards/arm/rak4631_nrf52840/rak4631_nrf52840.dts @@ -48,10 +48,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/rak4631_nrf52840/rak4631_nrf52840_defconfig b/boards/arm/rak4631_nrf52840/rak4631_nrf52840_defconfig index 4cc2863efab..80da4e05041 100644 --- a/boards/arm/rak4631_nrf52840/rak4631_nrf52840_defconfig +++ b/boards/arm/rak4631_nrf52840/rak4631_nrf52840_defconfig @@ -22,4 +22,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833.dts b/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833.dts index a3ada26e811..6a530e687f6 100644 --- a/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833.dts +++ b/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833.dts @@ -93,10 +93,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833_defconfig b/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833_defconfig index 1212ba8928f..7ed9a1ffe8b 100644 --- a/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833_defconfig +++ b/boards/arm/raytac_mdbt50q_db_33_nrf52833/raytac_mdbt50q_db_33_nrf52833_defconfig @@ -26,4 +26,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840.dts b/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840.dts index bd1a2f06855..2414b8ea517 100644 --- a/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840.dts +++ b/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840.dts @@ -93,10 +93,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840_defconfig b/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840_defconfig index 438343c6d9b..973b83c9d62 100644 --- a/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840_defconfig +++ b/boards/arm/raytac_mdbt50q_db_40_nrf52840/raytac_mdbt50q_db_40_nrf52840_defconfig @@ -26,4 +26,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/reel_board/dts/reel_board.dtsi b/boards/arm/reel_board/dts/reel_board.dtsi index 028a5d86a78..6289cf0ec6d 100644 --- a/boards/arm/reel_board/dts/reel_board.dtsi +++ b/boards/arm/reel_board/dts/reel_board.dtsi @@ -94,10 +94,6 @@ }; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/reel_board/reel_board_defconfig b/boards/arm/reel_board/reel_board_defconfig index 850506692ba..7ec7b36871b 100644 --- a/boards/arm/reel_board/reel_board_defconfig +++ b/boards/arm/reel_board/reel_board_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/reel_board/reel_board_v2_defconfig b/boards/arm/reel_board/reel_board_v2_defconfig index 2ac0610f78c..a7f80f970e8 100644 --- a/boards/arm/reel_board/reel_board_v2_defconfig +++ b/boards/arm/reel_board/reel_board_v2_defconfig @@ -17,4 +17,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832.dts b/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832.dts index 9594b760488..a248d8f650e 100644 --- a/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832.dts +++ b/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832.dts @@ -137,10 +137,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832_defconfig b/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832_defconfig index 801393790fe..769e28f5846 100644 --- a/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832_defconfig +++ b/boards/arm/ubx_bmd300eval_nrf52832/ubx_bmd300eval_nrf52832_defconfig @@ -23,4 +23,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810.dts b/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810.dts index c65221eb38c..5afd4960694 100644 --- a/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810.dts +++ b/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810.dts @@ -137,10 +137,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810_defconfig b/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810_defconfig index 4f8a5c5a8da..6fd69454784 100644 --- a/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810_defconfig +++ b/boards/arm/ubx_bmd330eval_nrf52810/ubx_bmd330eval_nrf52810_defconfig @@ -26,4 +26,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840.dts b/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840.dts index 070730c69d2..f7fbee05909 100644 --- a/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840.dts +++ b/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840.dts @@ -136,10 +136,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840_defconfig b/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840_defconfig index 37271c2ce81..4a1d3a6075c 100644 --- a/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840_defconfig +++ b/boards/arm/ubx_bmd340eval_nrf52840/ubx_bmd340eval_nrf52840_defconfig @@ -26,4 +26,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840.dts b/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840.dts index 68b3755123b..2db4e005b04 100644 --- a/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840.dts +++ b/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840.dts @@ -152,10 +152,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840_defconfig b/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840_defconfig index 4a35f6e612f..6a6d80f1b2b 100644 --- a/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840_defconfig +++ b/boards/arm/ubx_bmd345eval_nrf52840/ubx_bmd345eval_nrf52840_defconfig @@ -26,4 +26,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811.dts b/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811.dts index 5b8679cc065..842c882ac7f 100644 --- a/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811.dts +++ b/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811.dts @@ -137,10 +137,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811_defconfig b/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811_defconfig index 7a63bc69bf2..b2996dba82d 100644 --- a/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811_defconfig +++ b/boards/arm/ubx_bmd360eval_nrf52811/ubx_bmd360eval_nrf52811_defconfig @@ -26,4 +26,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840.dts b/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840.dts index d7a21c98b44..1c4623b52fe 100644 --- a/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840.dts +++ b/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840.dts @@ -97,10 +97,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840_defconfig b/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840_defconfig index c20dc6fe9f3..d0a583edbe8 100644 --- a/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840_defconfig +++ b/boards/arm/ubx_bmd380eval_nrf52840/ubx_bmd380eval_nrf52840_defconfig @@ -27,4 +27,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832.dts b/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832.dts index 2c0f051d25f..b183b17bc41 100644 --- a/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832.dts +++ b/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832.dts @@ -133,10 +133,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832_defconfig b/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832_defconfig index 93127beefef..4a289cc2597 100644 --- a/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832_defconfig +++ b/boards/arm/ubx_evkannab1_nrf52832/ubx_evkannab1_nrf52832_defconfig @@ -26,4 +26,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832.dts b/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832.dts index 849c96c5e6f..691705b3a91 100644 --- a/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832.dts +++ b/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832.dts @@ -133,10 +133,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832_defconfig b/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832_defconfig index b44e54e3d18..b7064633b25 100644 --- a/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832_defconfig +++ b/boards/arm/ubx_evkninab1_nrf52832/ubx_evkninab1_nrf52832_defconfig @@ -26,4 +26,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840.dts b/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840.dts index 5e15c5cc232..19b4e25a5af 100644 --- a/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840.dts +++ b/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840.dts @@ -129,10 +129,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840_defconfig b/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840_defconfig index f9cabe94b4a..ca03d00a8e7 100644 --- a/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840_defconfig +++ b/boards/arm/ubx_evkninab3_nrf52840/ubx_evkninab3_nrf52840_defconfig @@ -26,4 +26,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833.dts b/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833.dts index 521f9f6aa9e..783d69b4788 100644 --- a/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833.dts +++ b/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833.dts @@ -134,10 +134,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833_defconfig b/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833_defconfig index c06ad795868..96d99738526 100644 --- a/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833_defconfig +++ b/boards/arm/ubx_evkninab4_nrf52833/ubx_evkninab4_nrf52833_defconfig @@ -26,4 +26,7 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805.dts b/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805.dts index 4d7c3d8cc0b..b9b9bfcedb2 100644 --- a/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805.dts +++ b/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805.dts @@ -61,10 +61,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpio0 { status = "okay"; }; diff --git a/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805_defconfig b/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805_defconfig index 88c4ddb2023..d1a44910ced 100644 --- a/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805_defconfig +++ b/boards/arm/we_ophelia1ev_nrf52805/we_ophelia1ev_nrf52805_defconfig @@ -21,6 +21,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# Additional board options +CONFIG_GPIO_AS_PINRESET=y + # Use internal oscillator CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y diff --git a/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832.dts b/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832.dts index ef7eede1f75..4cd193c4162 100644 --- a/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832.dts +++ b/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832.dts @@ -56,10 +56,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832_defconfig b/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832_defconfig index 249c4a8e394..ab2356cf412 100644 --- a/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832_defconfig +++ b/boards/arm/we_proteus2ev_nrf52832/we_proteus2ev_nrf52832_defconfig @@ -24,6 +24,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # Use internal oscillator CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y diff --git a/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840.dts b/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840.dts index 62cecf7066e..4c64bcaa4d0 100644 --- a/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840.dts +++ b/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840.dts @@ -57,10 +57,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840_defconfig b/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840_defconfig index cca27094e6a..b232a355e40 100644 --- a/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840_defconfig +++ b/boards/arm/we_proteus3ev_nrf52840/we_proteus3ev_nrf52840_defconfig @@ -24,6 +24,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + # Use internal oscillator CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y diff --git a/boards/arm/xiao_ble/xiao_ble_common.dtsi b/boards/arm/xiao_ble/xiao_ble_common.dtsi index d031ce4b5b3..588f381868a 100644 --- a/boards/arm/xiao_ble/xiao_ble_common.dtsi +++ b/boards/arm/xiao_ble/xiao_ble_common.dtsi @@ -62,10 +62,6 @@ status = "okay"; }; -&uicr { - gpio-as-nreset; -}; - &gpiote { status = "okay"; }; diff --git a/boards/arm/xiao_ble/xiao_ble_defconfig b/boards/arm/xiao_ble/xiao_ble_defconfig index 6b6aa3168ec..faef5befa1f 100644 --- a/boards/arm/xiao_ble/xiao_ble_defconfig +++ b/boards/arm/xiao_ble/xiao_ble_defconfig @@ -29,4 +29,7 @@ CONFIG_USB_DEVICE_STACK=y CONFIG_BUILD_OUTPUT_UF2=y CONFIG_USE_DT_CODE_PARTITION=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y diff --git a/boards/arm/xiao_ble/xiao_ble_sense_defconfig b/boards/arm/xiao_ble/xiao_ble_sense_defconfig index 269f6f7915b..f549e4173dc 100644 --- a/boards/arm/xiao_ble/xiao_ble_sense_defconfig +++ b/boards/arm/xiao_ble/xiao_ble_sense_defconfig @@ -29,6 +29,9 @@ CONFIG_USB_DEVICE_STACK=y CONFIG_BUILD_OUTPUT_UF2=y CONFIG_USE_DT_CODE_PARTITION=y +# additional board options +CONFIG_GPIO_AS_PINRESET=y + CONFIG_PINCTRL=y # required to enable LSM6DS3TR-C power From 8827231ed597ad7e23778a0d780892b65f2fbe33 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:19 +0000 Subject: [PATCH 0760/1623] Revert "[nrf fromtree] modules: hal_nordic: nrfx: add support for 'gpio-as-nreset'" This reverts commit 23001717f6451eb5b14588a044525bc7dd7f07a5. Signed-off-by: Dominik Ermel --- modules/hal_nordic/nrfx/CMakeLists.txt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index e98db561906..98ba1961396 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -111,19 +111,14 @@ if(CONFIG_NRFX_TWI OR CONFIG_NRFX_TWIM) endif() # Inject HAL "CONFIG_NFCT_PINS_AS_GPIOS" definition if user requests to -# configure the NFCT pins as GPIOS. Do the same with "CONFIG_GPIO_AS_PINRESET" -# to configure the reset GPIO as nRESET. This way, the HAL will take care of -# doing the proper configuration sequence during system init +# configure the NFCT pins as GPIOS. This way, the HAL will take care of doing +# the proper configuration sequence during system init dt_nodelabel(uicr_path NODELABEL "uicr") if(${uicr_path}) dt_prop(nfct_pins_as_gpios PATH ${uicr_path} PROPERTY "nfct-pins-as-gpios") + if(${nfct_pins_as_gpios}) zephyr_library_compile_definitions(CONFIG_NFCT_PINS_AS_GPIOS) endif() - - dt_prop(gpio_as_nreset PATH ${uicr_path} PROPERTY "gpio-as-nreset") - if(${gpio_as_nreset}) - zephyr_library_compile_definitions(CONFIG_GPIO_AS_PINRESET) - endif() endif() From aec500720c39636f9acb7a67a7c4b4a9f15dfb7b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:19 +0000 Subject: [PATCH 0761/1623] Revert "[nrf fromtree] dts: bindings: arm: nordic,nrf-uicr: add gpio-as-nreset" This reverts commit 9fd2a0dff20d7b02531259295db889590566996e. Signed-off-by: Dominik Ermel --- dts/bindings/arm/nordic,nrf-uicr.yaml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/dts/bindings/arm/nordic,nrf-uicr.yaml b/dts/bindings/arm/nordic,nrf-uicr.yaml index b39a6ed6855..dbbb34e1265 100644 --- a/dts/bindings/arm/nordic,nrf-uicr.yaml +++ b/dts/bindings/arm/nordic,nrf-uicr.yaml @@ -19,14 +19,3 @@ properties: This setting, once applied, can only be unset by erasing the UICR registers. Refer to the reference manual for more details. - - gpio-as-nreset: - type: boolean - description: | - When enabled, this property will configure the reset GPIO as nRESET. - - nRESET pin in nRF52805/52810/52811/52832 series: P0.21 - nRESET pin in nRF52820/52833/52840 series: P0.18 - - This setting, once applied, can only be unset by erasing the UICR - registers. Refer to the reference manual for more details. From df95edc55556a525a690518cf91ab4d510c24844 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:19 +0000 Subject: [PATCH 0762/1623] Revert "[nrf fromtree] doc: migration-guide: add notes on CONFIG_NFCT_PINS_AS_GPIOS changes" This reverts commit d2aacb763ce42db6b11a46d7617e9a8f9fc5f745. Signed-off-by: Dominik Ermel --- doc/releases/migration-guide-3.5.rst | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/doc/releases/migration-guide-3.5.rst b/doc/releases/migration-guide-3.5.rst index 3f367ec5e35..7ffb16319d1 100644 --- a/doc/releases/migration-guide-3.5.rst +++ b/doc/releases/migration-guide-3.5.rst @@ -42,14 +42,3 @@ Recommended Changes :kconfig:option:`CONFIG_GIC_V3` directly in Kconfig has been deprecated. The GIC version should now be specified by adding the appropriate compatible, for example :dtcompatible:`arm,gic-v2`, to the GIC node in the device tree. - -* Nordic nRF based boards using :kconfig:option:`CONFIG_NFCT_PINS_AS_GPIOS` - to configure NFCT pins as GPIOs, should instead set the new UICR - ``nfct-pins-as-gpios`` property in devicetree. It can be set like this in the - board devicetree files: - - .. code-block:: devicetree - - &uicr { - nfct-pins-as-gpios; - }; From a3866892b89c6aee4bd52b20071f2b704aaea886 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:19 +0000 Subject: [PATCH 0763/1623] Revert "[nrf fromtree] soc: arm: nordic_nrf: deprecate CONFIG_NFCT_PINS_AS_GPIOS" This reverts commit f18175381579045b4cf9ef9a9cb3d09c33832c70. Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/Kconfig | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/soc/arm/nordic_nrf/Kconfig b/soc/arm/nordic_nrf/Kconfig index c2129db64b3..2c386f99a53 100644 --- a/soc/arm/nordic_nrf/Kconfig +++ b/soc/arm/nordic_nrf/Kconfig @@ -47,9 +47,8 @@ config NRF_ACL_FLASH_REGION_SIZE FLASH region size for the NRF_ACL peripheral. config NFCT_PINS_AS_GPIOS - bool "[DEPRECATED] NFCT pins as GPIOs" + bool "NFCT pins as GPIOs" depends on $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_NFCT)) - select DEPRECATED help Two pins are usually reserved for NFC in SoCs that implement the NFCT peripheral. This option switches them to normal GPIO mode. @@ -61,13 +60,6 @@ config NFCT_PINS_AS_GPIOS NFC pins in nRF52 series: P0.09 and P0.10 NFC pins in nRF5340: P0.02 and P0.03 - This option is deprecated, please use devicetree to configure NFCT - pins as GPIOS like this: - - &uicr { - nfct-pins-as-gpios; - }; - choice NRF_APPROTECT_HANDLING bool "APPROTECT handling" depends on SOC_SERIES_NRF52X || SOC_NRF5340_CPUNET || \ From c633c0868b3ff7e733dad6ca68c516a796559d94 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:19 +0000 Subject: [PATCH 0764/1623] Revert "[nrf fromtree] boards: arm: nrf: use UICR nfc-pins-as-gpios devicetree property" This reverts commit dda4a3bf0be6c10a1c48516f579b1ae5d6b9ff98. Signed-off-by: Dominik Ermel --- boards/arm/bt610/bt610.dts | 4 ---- boards/arm/bt610/bt610_defconfig | 1 + .../arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts | 4 ---- .../nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig | 1 + .../arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts | 4 ---- .../nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig | 1 + .../nrf5340_audio_dk_nrf5340_cpuapp.dts | 4 ---- .../nrf5340_audio_dk_nrf5340_cpuapp_defconfig | 1 + boards/arm/pinetime_devkit0/pinetime_devkit0.dts | 4 ---- boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig | 3 +++ 10 files changed, 7 insertions(+), 20 deletions(-) diff --git a/boards/arm/bt610/bt610.dts b/boards/arm/bt610/bt610.dts index 6bbe8d57fe3..3c047a50fcd 100644 --- a/boards/arm/bt610/bt610.dts +++ b/boards/arm/bt610/bt610.dts @@ -143,10 +143,6 @@ status = "okay"; }; -&uicr { - nfct-pins-as-gpios; -}; - &gpio0 { status = "okay"; }; diff --git a/boards/arm/bt610/bt610_defconfig b/boards/arm/bt610/bt610_defconfig index 1c77ed9e37b..64f0fcb85ed 100644 --- a/boards/arm/bt610/bt610_defconfig +++ b/boards/arm/bt610/bt610_defconfig @@ -9,6 +9,7 @@ CONFIG_ARM_MPU=y # Enable GPIO CONFIG_GPIO=y +CONFIG_NFCT_PINS_AS_GPIOS=y # Enable uart driver CONFIG_SERIAL=y diff --git a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts index 8e835597c78..616af71443c 100644 --- a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts +++ b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle.dts @@ -87,10 +87,6 @@ status = "okay"; }; -&uicr { - nfct-pins-as-gpios; -}; - &gpio0 { status = "okay"; }; diff --git a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig index 90850c10e0a..92ec1dc7885 100644 --- a/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig +++ b/boards/arm/nrf52840_mdk_usb_dongle/nrf52840_mdk_usb_dongle_defconfig @@ -15,5 +15,6 @@ CONFIG_GPIO=y # additional board options CONFIG_GPIO_AS_PINRESET=y +CONFIG_NFCT_PINS_AS_GPIOS=y CONFIG_PINCTRL=y diff --git a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts index 93b59baa920..f17ecb8e18a 100644 --- a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts +++ b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts @@ -99,10 +99,6 @@ status = "okay"; }; -&uicr { - nfct-pins-as-gpios; -}; - &gpio0 { status = "okay"; }; diff --git a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig index 32a9d03b44e..f38880961d5 100644 --- a/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig +++ b/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840_defconfig @@ -15,6 +15,7 @@ CONFIG_GPIO=y # additional board options CONFIG_GPIO_AS_PINRESET=y +CONFIG_NFCT_PINS_AS_GPIOS=y CONFIG_PINCTRL=y diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp.dts b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp.dts index be871800332..8fe46bdd7a3 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp.dts +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp.dts @@ -20,7 +20,3 @@ zephyr,sram-non-secure-partition = &sram0_ns; }; }; - -&uicr { - nfct-pins-as-gpios; -}; diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_defconfig b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_defconfig index d1b5f551c9b..0f5f1991b6d 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_defconfig +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_defconfig @@ -12,6 +12,7 @@ CONFIG_HW_STACK_PROTECTION=y CONFIG_ARM_TRUSTZONE_M=y CONFIG_GPIO=y +CONFIG_NFCT_PINS_AS_GPIOS=y CONFIG_SERIAL=y diff --git a/boards/arm/pinetime_devkit0/pinetime_devkit0.dts b/boards/arm/pinetime_devkit0/pinetime_devkit0.dts index fb377fd89e1..baad177740c 100644 --- a/boards/arm/pinetime_devkit0/pinetime_devkit0.dts +++ b/boards/arm/pinetime_devkit0/pinetime_devkit0.dts @@ -87,10 +87,6 @@ status = "okay"; }; -&uicr { - nfct-pins-as-gpios; -}; - &gpio0 { status = "okay"; diff --git a/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig b/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig index ad7442afe0d..4e48c259730 100644 --- a/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig +++ b/boards/arm/pinetime_devkit0/pinetime_devkit0_defconfig @@ -13,6 +13,9 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y +# use P0.09 and P0.10 as GPIOs +CONFIG_NFCT_PINS_AS_GPIOS=y + # use P0.21 as RST CONFIG_GPIO_AS_PINRESET=y From 641b006debb06b98b4a78081a89742a211ced57c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:20 +0000 Subject: [PATCH 0765/1623] Revert "[nrf fromtree] modules: hal_nordic: inject CONFIG_NFCT_PINS_AS_GPIOS" This reverts commit 6f482d8e6f99115d9bd09d94855f76f491afc03c. Signed-off-by: Dominik Ermel --- modules/hal_nordic/nrfx/CMakeLists.txt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index 98ba1961396..5842ae45ad5 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -109,16 +109,3 @@ zephyr_library_sources_ifdef(CONFIG_NRFX_WDT ${SRC_DIR}/nrfx_wdt.c) if(CONFIG_NRFX_TWI OR CONFIG_NRFX_TWIM) zephyr_library_sources(${SRC_DIR}/nrfx_twi_twim.c) endif() - -# Inject HAL "CONFIG_NFCT_PINS_AS_GPIOS" definition if user requests to -# configure the NFCT pins as GPIOS. This way, the HAL will take care of doing -# the proper configuration sequence during system init - -dt_nodelabel(uicr_path NODELABEL "uicr") -if(${uicr_path}) - dt_prop(nfct_pins_as_gpios PATH ${uicr_path} PROPERTY "nfct-pins-as-gpios") - - if(${nfct_pins_as_gpios}) - zephyr_library_compile_definitions(CONFIG_NFCT_PINS_AS_GPIOS) - endif() -endif() From 20f2d334f67fea2c1706b8f7d240eed1da258534 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:20 +0000 Subject: [PATCH 0766/1623] Revert "[nrf fromtree] dts: bindings: arm: nordic,nrf-uicr add nfct-pins-as-gpios" This reverts commit aa88cae57f098f7caf7ed4aac6ba2abafbf0afe0. Signed-off-by: Dominik Ermel --- dts/bindings/arm/nordic,nrf-uicr.yaml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/dts/bindings/arm/nordic,nrf-uicr.yaml b/dts/bindings/arm/nordic,nrf-uicr.yaml index dbbb34e1265..82ac8fc2089 100644 --- a/dts/bindings/arm/nordic,nrf-uicr.yaml +++ b/dts/bindings/arm/nordic,nrf-uicr.yaml @@ -7,15 +7,3 @@ include: base.yaml properties: reg: required: true - - nfct-pins-as-gpios: - type: boolean - description: | - When enabled this property will configure pins dedicated to NFCT - peripheral as regular GPIOs. - - NFC pins in nRF52 series: P0.09 and P0.10 - NFC pins in nRF5340: P0.02 and P0.03 - - This setting, once applied, can only be unset by erasing the UICR - registers. Refer to the reference manual for more details. From ebfeffd8a1b19732c89c9a667db5456df2f7388f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:20 +0000 Subject: [PATCH 0767/1623] Revert "[nrf fromlist] nrf53: fix RTC pretick power usage for events on RTC0" This reverts commit 7d27517258a04103755733c102e74f11841a1318. Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/nrf53/soc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index c18228ac4fa..aa93dfd4b54 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -410,8 +410,6 @@ static void rtc_pretick_rtc_isr_hook(void) { NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] &= ~IPC_PUBLISH_RECEIVE_EN_Msk; - - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); } void rtc_pretick_rtc0_isr_hook(void) @@ -422,6 +420,10 @@ void rtc_pretick_rtc0_isr_hook(void) void rtc_pretick_rtc1_isr_hook(void) { rtc_pretick_rtc_isr_hook(); + + if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); + } } static int rtc_pretick_cpunet_init(void) From 2fb860661ae316700e904f809c28bb1b1fbb092d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:20 +0000 Subject: [PATCH 0768/1623] Revert "[nrf fromtree] mgmt/MCUmgr/grp/os: Add booloader info support" This reverts commit 8bef82541c679398d9886f211db6a8eb34f34760. Signed-off-by: Dominik Ermel --- .../zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h | 4 -- subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt | 8 +-- subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig | 10 --- subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c | 70 +------------------ 4 files changed, 2 insertions(+), 90 deletions(-) diff --git a/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h b/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h index e1ac45e6389..9c541e11c29 100644 --- a/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h +++ b/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h @@ -24,7 +24,6 @@ extern "C" { #define OS_MGMT_ID_RESET 5 #define OS_MGMT_ID_MCUMGR_PARAMS 6 #define OS_MGMT_ID_INFO 7 -#define OS_MGMT_ID_BOOTLOADER_INFO 8 /** * Command result codes for OS management group. @@ -38,9 +37,6 @@ enum os_mgmt_err_code_t { /** The provided format value is not valid. */ OS_MGMT_ERR_INVALID_FORMAT, - - /** Query was not recognized. */ - OS_MGMT_ERR_QUERY_YIELDS_NO_ANSWER, }; /* Bitmask values used by the os info command handler. Note that the width of this variable is diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt b/subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt index 35123fa1159..e712acf6e94 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt +++ b/subsys/mgmt/mcumgr/grp/os_mgmt/CMakeLists.txt @@ -1,6 +1,6 @@ # # Copyright (c) 2018-2021 mcumgr authors -# Copyright (c) 2022-2023 Nordic Semiconductor ASA +# Copyright (c) 2022 Nordic Semiconductor ASA # # SPDX-License-Identifier: Apache-2.0 # @@ -12,12 +12,6 @@ zephyr_library_sources(src/os_mgmt.c) zephyr_library_include_directories(include) -if (CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO) - zephyr_include_directories( - ${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/bootutil/include - ) -endif() - if(DEFINED CONFIG_MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME) set(MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME_DIR ${PROJECT_BINARY_DIR}/os_mgmt_auto) file(MAKE_DIRECTORY ${MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME_DIR}) diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig b/subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig index fa743b53caf..897db735982 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig +++ b/subsys/mgmt/mcumgr/grp/os_mgmt/Kconfig @@ -173,16 +173,6 @@ config MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME endif -if BOOTLOADER_MCUBOOT - -config MCUMGR_GRP_OS_BOOTLOADER_INFO - bool "Bootloader information" - help - Allows to query MCUmgr about bootloader used by device and various bootloader - parameters. - -endif # BOOTLOADER_MCUBOOT - module = MCUMGR_GRP_OS module-str = mcumgr_grp_os source "subsys/logging/Kconfig.template.log_config" diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c b/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c index a42e2f4022f..55a6fa81564 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c @@ -33,15 +33,10 @@ #include #endif -#if defined(CONFIG_MCUMGR_GRP_OS_INFO) || defined(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO) +#ifdef CONFIG_MCUMGR_GRP_OS_INFO #include #include -#if defined(CONFIG_MCUMGR_GRP_OS_INFO) #include -#endif -#if defined(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO) -#include -#endif #include #if defined(CONFIG_NET_HOSTNAME_ENABLE) #include @@ -375,64 +370,6 @@ os_mgmt_mcumgr_params(struct smp_streamer *ctxt) } #endif -#if defined(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO) - -#if IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP) -#define BOOTLOADER_MODE MCUBOOT_MODE_SINGLE_SLOT -#elif IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_SCRATCH) -#define BOOTLOADER_MODE MCUBOOT_MODE_SWAP_USING_SCRATCH -#elif IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY) -#define BOOTLOADER_MODE MCUBOOT_MODE_UPGRADE_ONLY -#elif IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_WITHOUT_SCRATCH) -#define BOOTLOADER_MODE MCUBOOT_MODE_SWAP_USING_MOVE -#elif IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) -#define BOOTLOADER_MODE MCUBOOT_MODE_DIRECT_XIP -#elif IS_ENABLED(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) -#define BOOTLOADER_MODE MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT -#else -#define BOOTLOADER_MODE -1 -#endif - -static int -os_mgmt_bootloader_info(struct smp_streamer *ctxt) -{ - zcbor_state_t *zse = ctxt->writer->zs; - zcbor_state_t *zsd = ctxt->reader->zs; - struct zcbor_string query = { 0 }; - size_t decoded; - bool ok; - - struct zcbor_map_decode_key_val bootloader_info[] = { - ZCBOR_MAP_DECODE_KEY_DECODER("query", zcbor_tstr_decode, &query), - }; - - if (zcbor_map_decode_bulk(zsd, bootloader_info, ARRAY_SIZE(bootloader_info), &decoded)) { - return MGMT_ERR_EINVAL; - } - - /* If no parameter is recognized then just introduce the bootloader. */ - if (decoded == 0) { - ok = zcbor_tstr_put_lit(zse, "bootloader") && - zcbor_tstr_put_lit(zse, "MCUboot"); - } else if (zcbor_map_decode_bulk_key_found(bootloader_info, ARRAY_SIZE(bootloader_info), - "query") && - (sizeof("mode") - 1) == query.len && - memcmp("mode", query.value, query.len) == 0) { - - ok = zcbor_tstr_put_lit(zse, "mode") && - zcbor_int32_put(zse, BOOTLOADER_MODE); -#if IS_ENABLED(MCUBOOT_BOOTLOADER_NO_DOWNGRADE) - ok = zcbor_tstr_put_lit(zse, "no-downgrade") && - zcbor_bool_encode(zse, true); -#endif - } else { - return OS_MGMT_ERR_QUERY_YIELDS_NO_ANSWER; - } - - return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE; -} -#endif - #ifdef CONFIG_MCUMGR_GRP_OS_INFO /** * Command handler: os info @@ -796,11 +733,6 @@ static const struct mgmt_handler os_mgmt_group_handlers[] = { os_mgmt_info, NULL }, #endif -#ifdef CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO - [OS_MGMT_ID_BOOTLOADER_INFO] = { - os_mgmt_bootloader_info, NULL - }, -#endif }; #define OS_MGMT_GROUP_SZ ARRAY_SIZE(os_mgmt_group_handlers) From eb94ee634137ffbb214fbc36143e2c16e9d92deb Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:21 +0000 Subject: [PATCH 0769/1623] Revert "[nrf fromtree] doc/release-notes: MCUboot overwrite mode Kconfig info" This reverts commit b1ab980959dac1486bd6d781ec8b9c80bba21fac. Signed-off-by: Dominik Ermel --- doc/releases/release-notes-3.5.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/releases/release-notes-3.5.rst b/doc/releases/release-notes-3.5.rst index 82d2698849b..d22978d8a84 100644 --- a/doc/releases/release-notes-3.5.rst +++ b/doc/releases/release-notes-3.5.rst @@ -344,11 +344,6 @@ MCUboot with downgrade prevention enabled. This option is automatically selected for DirectXIP mode and is available for both swap modes. - * Added :kconfig:option:`CONFIG_MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY` - that allows to inform application that the on-board MCUboot will overwrite - the primary slot with secondary slot contents, without saving the original - image in primary slot. - Storage ******* From 23585b274395eff820b3b46319deffdd9351c50b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:21 +0000 Subject: [PATCH 0770/1623] Revert "[nrf fromtree] doc/services/device_mgmt: Bootloader info request definition" This reverts commit 3d0052713f45333aa094a8c6d8896bd3b9c051ce. Signed-off-by: Dominik Ermel --- .../device_mgmt/smp_groups/smp_group_0.rst | 211 +----------------- 1 file changed, 3 insertions(+), 208 deletions(-) diff --git a/doc/services/device_mgmt/smp_groups/smp_group_0.rst b/doc/services/device_mgmt/smp_groups/smp_group_0.rst index 53907f33bcc..839b0e06be3 100644 --- a/doc/services/device_mgmt/smp_groups/smp_group_0.rst +++ b/doc/services/device_mgmt/smp_groups/smp_group_0.rst @@ -28,8 +28,6 @@ OS management group defines following commands: +-------------------+-----------------------------------------------+ | ``7`` | OS/Application info | +-------------------+-----------------------------------------------+ - | ``8`` | Bootloader information | - +-------------------+-----------------------------------------------+ Echo command ************ @@ -662,215 +660,12 @@ CBOR data of response: where: -.. table:: - :align: center - - +------------------+-------------------------------------------------------------------------+ - | "output" | Text response including requested parameters. | - +------------------+-------------------------------------------------------------------------+ - | "err" -> "group" | :c:enum:`mcumgr_group_t` group of the group-based error code. Only | - | | appears if an error is returned when using SMP version 2. | - +------------------+-------------------------------------------------------------------------+ - | "err" -> "rc" | contains the index of the group-based error code. Only appears if | - | | non-zero (error condition) when using SMP version 2. | - +------------------+-------------------------------------------------------------------------+ - | "rc" | :c:enum:`mcumgr_err_t` only appears if non-zero (error condition) when | - | | using SMP version 1 or for SMP errors when using SMP version 2. | - +------------------+-------------------------------------------------------------------------+ - -Bootloader Information -********************** - -Allows retrieving information about the on-board bootloader and its parameters. - -Bootloader Information Request -============================== - -Bootloader information request header: - -.. table:: - :align: center - - +--------+--------------+----------------+ - | ``OP`` | ``Group ID`` | ``Command ID`` | - +========+==============+================+ - | ``0`` | ``0`` | ``8`` | - +--------+--------------+----------------+ - -CBOR data of request: - -.. code-block:: none - - { - (str,opt)"query" : (str) - } - -where: - .. table:: :align: center +--------------+-----------------------------------------------+ - | "query" | Is string representing query for parameters, | - | | with no restrictions how the query looks like | - | | as processing of query is left for bootloader | - | | backend. | - | | If there is no query, then response will | - | | return string identifying the bootloader. | + | "output" | Text response including requested parameters. | +--------------+-----------------------------------------------+ - -Bootloader Information Response -=============================== - -Bootloader information response header: - -.. table:: - :align: center - - +--------+--------------+----------------+ - | ``OP`` | ``Group ID`` | ``Command ID`` | - +========+==============+================+ - | ``1`` | ``0`` | ``8`` | - +--------+--------------+----------------+ - -In case when no "query" has been provided in request, -CBOR data of response: - -.. code-block:: none - - { - (str)"bootloader" : (str) - } - -where: - -.. table:: - :align: center - - +--------------+-----------------------------------------------+ - | "bootloader" | String representing bootloader name | + | "rc" | :c:enum:`mcumgr_err_t` | + | | only appears if non-zero (error condition). | +--------------+-----------------------------------------------+ - -In case when "query" is provided: - -.. code-block:: none - - { - (str,opt) : () - ... - } - -where: - -.. table:: - :align: center - - +------------------+-------------------------------------------------------------------------+ - | | Response to "query". This is optional and may be left out in case when | - | | query yields no response, SMP version 2 error code of | - | | `OS_MGMT_ERR_QUERY_YIELDS_NO_ANSWER` is expected. | - | | Response may have more than one parameter reported back or it may be | - | | a map, that is dependent on bootloader backednd and query. | - +------------------+-------------------------------------------------------------------------+ - | ... | Parameter characteristic information. | - +------------------+-------------------------------------------------------------------------+ - -Parameter may be accompanied by additional, parameter specific, information keywords with -assigned values. - -In case of error the CBOR data takes the form: - -.. tabs:: - - .. group-tab:: SMP version 2 - - .. code-block:: none - - { - (str)"err" : { - (str)"group" : (uint) - (str)"rc" : (uint) - } - } - - .. group-tab:: SMP version 1 (and non-group SMP version 2) - - .. code-block:: none - - { - (str)"rc" : (int) - } - -where: - -.. table:: - :align: center - - +------------------+-------------------------------------------------------------------------+ - | "err" -> "group" | :c:enum:`mcumgr_group_t` group of the group-based error code. Only | - | | appears if an error is returned when using SMP version 2. | - +------------------+-------------------------------------------------------------------------+ - | "err" -> "rc" | contains the index of the group-based error code. Only appears if | - | | non-zero (error condition) when using SMP version 2. | - +------------------+-------------------------------------------------------------------------+ - | "rc" | :c:enum:`mcumgr_err_t` only appears if non-zero (error condition) when | - | | using SMP version 1 or for SMP errors when using SMP version 2. | - +------------------+-------------------------------------------------------------------------+ - -Bootloader Information: MCUboot -=============================== - -In case when MCUboot is application bootloader empty request will -be responded with: - -.. code-block:: none - - { - (str)"bootloader" : (str)"MCUboot" - } - -Currently "MCUboot" supports querying for mode of operation: - -.. code-block:: none - - { - (str)"query" : (str)"mode" - } - -Response to "mode" is: - -.. code-block:: none - - { - (str)"mode" : (int) - (str,opt)"no-downgrade" : (bool) - } - -where "mode" is one of: - -.. table:: - :align: center - - +-----+-----------------------------------------------------+ - | -1 | Unknown mode of MCUboot. | - +-----+-----------------------------------------------------+ - | 0 | MCUboot is in single application mode. | - +-----+-----------------------------------------------------+ - | 1 | MCUboot is in swap using scratch partition mode. | - +-----+-----------------------------------------------------+ - | 2 | MCUboot is in overwrite (upgrade-only) mode. | - +-----+-----------------------------------------------------+ - | 3 | MCUboot is in swap without scratch mode. | - +-----+-----------------------------------------------------+ - | 4 | MCUboot is in DirectXIP without revert mode. | - +-----+-----------------------------------------------------+ - | 5 | MCUboot is in DirectXIP with revert mode. | - +-----+-----------------------------------------------------+ - | 6 | MCUboot is in RAM loader mode. | - +-----+-----------------------------------------------------+ - -The "no-downgrade" is a flag, which is always sent when true, indicating that -mode has downgrade prevention enabled; downgrade prevention means that -if uploaded image has lower version than running, it will notbe taken -for exectuion by MCUboot. -MCUmgr may reject image with lower version in that MCUboot configuration. From e00ae48a5346e9704e6b90d3626529f349ab0ce3 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:21 +0000 Subject: [PATCH 0771/1623] Revert "[nrf fromtree] modules/MCUboot: Add overwrite mode for MCUboot" This reverts commit d73788b2457d22003d435da88143ee67881bdc43. Signed-off-by: Dominik Ermel --- modules/Kconfig.mcuboot | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index 8df4bde8829..1679bfeb8a9 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -175,18 +175,6 @@ config MCUBOOT_BOOTLOADER_MODE_SWAP_SCRATCH MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected if MCUboot has been built with MCUBOOT_DOWNGRADE_PREVENTION. -config MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY - bool "MCUboot has been configured to just overwrite primary slot" - select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE - help - MCUboot will take contents of secondary slot of an image and will - overwrite primary slot with it. - In this mode it is not possible to revert back to previous version - as it is not stored in the secondary slot. - This mode supports MCUBOOT_BOOTLOADER_NO_DOWNGRADE which means - that the overwrite will not happen unless the version of secondary - slot is higher than the version in primary slot. - config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP bool "MCUboot has been configured for DirectXIP operation" select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE From b0f2eca67d88ff7208dcb47e06fdb885058d7863 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:21 +0000 Subject: [PATCH 0772/1623] Revert "[nrf fromtree] bluetooth: tests: Improve bondable_per_connection bsim test" This reverts commit 55f4b17ea515edd707dd2fc3a907911f270e088a. Signed-off-by: Dominik Ermel --- .../host/security/bond_per_connection/src/bs_bt_utils.c | 6 ------ .../host/security/bond_per_connection/src/peripheral.c | 6 ------ 2 files changed, 12 deletions(-) diff --git a/tests/bsim/bluetooth/host/security/bond_per_connection/src/bs_bt_utils.c b/tests/bsim/bluetooth/host/security/bond_per_connection/src/bs_bt_utils.c index 94b27a50b33..1523e10d8a5 100644 --- a/tests/bsim/bluetooth/host/security/bond_per_connection/src/bs_bt_utils.c +++ b/tests/bsim/bluetooth/host/security/bond_per_connection/src/bs_bt_utils.c @@ -88,11 +88,6 @@ DEFINE_FLAG(flag_pairing_complete); DEFINE_FLAG(flag_bonded); DEFINE_FLAG(flag_not_bonded); -static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason) -{ - FAIL("Pairing failed (unexpected): reason %u\n", reason); -} - static void pairing_complete(struct bt_conn *conn, bool bonded) { SET_FLAG(flag_pairing_complete); @@ -105,7 +100,6 @@ static void pairing_complete(struct bt_conn *conn, bool bonded) } static struct bt_conn_auth_info_cb bt_conn_auth_info_cb = { - .pairing_failed = pairing_failed, .pairing_complete = pairing_complete, }; diff --git a/tests/bsim/bluetooth/host/security/bond_per_connection/src/peripheral.c b/tests/bsim/bluetooth/host/security/bond_per_connection/src/peripheral.c index 01956d251df..5e11d6ac712 100644 --- a/tests/bsim/bluetooth/host/security/bond_per_connection/src/peripheral.c +++ b/tests/bsim/bluetooth/host/security/bond_per_connection/src/peripheral.c @@ -33,8 +33,6 @@ void peripheral(void) wait_connected(); /* Central should bond here and trigger a disconnect. */ wait_disconnected(); - TAKE_FLAG(flag_pairing_complete); - TAKE_FLAG(flag_bonded); unpair(id_a); clear_g_conn(); @@ -45,8 +43,6 @@ void peripheral(void) wait_connected(); /* Central should bond here and trigger a disconnect. */ wait_disconnected(); - TAKE_FLAG(flag_pairing_complete); - TAKE_FLAG(flag_bonded); clear_g_conn(); printk("== Bonding id b - bond per-connection false ==\n"); @@ -55,8 +51,6 @@ void peripheral(void) wait_connected(); /* Central should pair without bond here and trigger a disconnect. */ wait_disconnected(); - TAKE_FLAG(flag_pairing_complete); - TAKE_FLAG(flag_not_bonded); PASS("PASS\n"); } From 7b4e434ad953410d6cb4fc2aefc0fe8bb020fdfb Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:21 +0000 Subject: [PATCH 0773/1623] Revert "[nrf fromtree] bluetooth: host: smp: Add runtime check for central-specific path" This reverts commit 27f8c5cbafa199be5c1945ab95bc5cbcff9ab8cd. Signed-off-by: Dominik Ermel --- subsys/bluetooth/host/smp.c | 1 - 1 file changed, 1 deletion(-) diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 9643982c421..add06660bf6 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -4706,7 +4706,6 @@ static void bt_smp_encrypt_change(struct bt_l2cap_chan *chan, */ if (IS_ENABLED(CONFIG_BT_CENTRAL) && IS_ENABLED(CONFIG_BT_PRIVACY) && - conn->role == BT_HCI_ROLE_CENTRAL && !(smp->remote_dist & BT_SMP_DIST_ID_KEY)) { uint8_t smp_err; From 1bcc187c901e74a1f8ec5ba838dbe1a786149220 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:22 +0000 Subject: [PATCH 0774/1623] Revert "[nrf fromlist] bluetooth: tester: add support for variable static oob size" This reverts commit 6319f2cfbe21cd9cac956922ad70595b149220a0. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp/btp_mesh.h | 8 +++++--- tests/bluetooth/tester/src/btp_mesh.c | 13 ++----------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 826f0fd0408..6c4a5e90106 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -30,12 +30,15 @@ struct btp_mesh_read_supported_commands_rp { #define BTP_MESH_CONFIG_PROVISIONING 0x02 -#define BTP_MESH_PROV_AUTH_MAX_LEN 32 +#if IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM) +#define BTP_MESH_PROV_AUTH_MAX_LEN 32 +#else +#define BTP_MESH_PROV_AUTH_MAX_LEN 16 +#endif struct btp_mesh_config_provisioning_cmd { uint8_t uuid[16]; uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; - uint8_t static_auth_size; uint8_t out_size; uint16_t out_actions; uint8_t in_size; @@ -45,7 +48,6 @@ struct btp_mesh_config_provisioning_cmd { struct btp_mesh_config_provisioning_cmd_v2 { uint8_t uuid[16]; uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; - uint8_t static_auth_size; uint8_t out_size; uint16_t out_actions; uint8_t in_size; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index e83f1a67ba1..af41c1518d5 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -50,7 +50,6 @@ static uint8_t priv_key[32]; /* Configured provisioning data */ static uint8_t dev_uuid[16]; static uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; -static uint8_t static_auth_size; /* Vendor Model data */ #define VND_MODEL_ID_1 0x1234 @@ -1144,21 +1143,13 @@ static uint8_t config_prov(const void *cmd, uint16_t cmd_len, /* TODO consider fix BTP commands to avoid this */ if (cmd_len != sizeof(*cp) && cmd_len != (sizeof(*cp2))) { - LOG_DBG("wrong cmd size"); return BTP_STATUS_FAILED; } LOG_DBG(""); - static_auth_size = cp->static_auth_size; - - if (static_auth_size > BTP_MESH_PROV_AUTH_MAX_LEN || static_auth_size == 0) { - LOG_DBG("wrong static auth length"); - return BTP_STATUS_FAILED; - } - memcpy(dev_uuid, cp->uuid, sizeof(dev_uuid)); - memcpy(static_auth, cp->static_auth, cp->static_auth_size); + memcpy(static_auth, cp->static_auth, sizeof(static_auth)); prov.output_size = cp->out_size; prov.output_actions = sys_le16_to_cpu(cp->out_actions); @@ -1177,7 +1168,7 @@ static uint8_t config_prov(const void *cmd, uint16_t cmd_len, } else if (cp->auth_method == AUTH_METHOD_INPUT) { err = bt_mesh_auth_method_set_input(prov.input_actions, prov.input_size); } else if (cp->auth_method == AUTH_METHOD_STATIC) { - err = bt_mesh_auth_method_set_static(static_auth, static_auth_size); + err = bt_mesh_auth_method_set_static(static_auth, sizeof(static_auth)); } if (err) { From 534769cc77b56211c3d6597a22de8a8313423030 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:22 +0000 Subject: [PATCH 0775/1623] Revert "[nrf fromlist] bluetooth: tester: Enable composition data page 2" This reverts commit 5cb1ed20ab2c98d0e0856219a355a7e7dd51394c. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/overlay-mesh-v1d1.conf | 2 +- tests/bluetooth/tester/src/btp_mesh.c | 20 ------------------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh-v1d1.conf b/tests/bluetooth/tester/overlay-mesh-v1d1.conf index 978d1acd3df..7a3907cc78c 100644 --- a/tests/bluetooth/tester/overlay-mesh-v1d1.conf +++ b/tests/bluetooth/tester/overlay-mesh-v1d1.conf @@ -25,5 +25,5 @@ CONFIG_BT_MESH_PRIV_BEACON_SRV=y CONFIG_BT_MESH_PRIV_BEACON_CLI=y CONFIG_BT_MESH_MODEL_EXTENSIONS=y CONFIG_BT_MESH_COMP_PAGE_1=y -CONFIG_BT_MESH_COMP_PAGE_2=y + CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index af41c1518d5..1d94eb43cb5 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1103,22 +1103,6 @@ static const struct bt_mesh_comp comp_alt = { .vid = 2, }; -#if defined(CONFIG_BT_MESH_COMP_PAGE_2) -static const uint8_t cmp2_elem_offset[1] = {0}; - -static const struct bt_mesh_comp2_record comp_rec = { - .id = 0x1600, - .version.x = 1, - .version.y = 0, - .version.z = 0, - .elem_offset_cnt = 1, - .elem_offset = cmp2_elem_offset, - .data_len = 0 -}; - -static const struct bt_mesh_comp2 comp_p2 = {.record_cnt = 1, .record = &comp_rec}; -#endif - static struct bt_mesh_prov prov = { .uuid = dev_uuid, .static_val = static_auth, @@ -5221,10 +5205,6 @@ uint8_t tester_init_mesh(void) bt_test_cb_register(&bt_test_cb); } -#if defined(CONFIG_BT_MESH_COMP_PAGE_2) - bt_mesh_comp2_register(&comp_p2); -#endif - tester_register_command_handlers(BTP_SERVICE_ID_MESH, handlers, ARRAY_SIZE(handlers)); if (default_comp) { From 0826530bbdea8134c0bf43c03c2ee81b8713c187 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:22 +0000 Subject: [PATCH 0776/1623] Revert "[nrf fromtree] bluetooth: mesh: fix static oob auth padding" This reverts commit 058c19c5a8644dcb0817d720876bb5265776a7ad. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/prov_device.c | 18 ++++++++---------- subsys/bluetooth/mesh/provisioner.c | 13 +++++-------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/prov_device.c index 992bf656202..0184463568f 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/prov_device.c @@ -192,16 +192,14 @@ static void prov_start(const uint8_t *data) } if (atomic_test_bit(bt_mesh_prov_link.flags, OOB_STATIC_KEY)) { - /* Trim the Auth if it is longer than required length */ - memcpy(bt_mesh_prov_link.auth, bt_mesh_prov->static_val, - bt_mesh_prov->static_val_len > auth_size ? auth_size - : bt_mesh_prov->static_val_len); - - /* Padd with zeros if the Auth is shorter the required length*/ - if (bt_mesh_prov->static_val_len < auth_size) { - memset(bt_mesh_prov_link.auth + bt_mesh_prov->static_val_len, 0, - auth_size - bt_mesh_prov->static_val_len); - } + + uint8_t tail_size = bt_mesh_prov->static_val_len < auth_size + ? auth_size - bt_mesh_prov->static_val_len + : 0; + + memcpy(bt_mesh_prov_link.auth + tail_size, bt_mesh_prov->static_val, + tail_size ? bt_mesh_prov->static_val_len : auth_size); + memset(bt_mesh_prov_link.auth, 0, tail_size); } } diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index 361f373cb7b..673e14578d2 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -751,20 +751,17 @@ int bt_mesh_auth_method_set_output(bt_mesh_output_action_t action, uint8_t size) int bt_mesh_auth_method_set_static(const uint8_t *static_val, uint8_t size) { + uint8_t tail_size = size < PROV_AUTH_MAX_LEN ? PROV_AUTH_MAX_LEN - size : 0; + if (!size || !static_val) { return -EINVAL; } prov_set_method(AUTH_METHOD_STATIC, 0, 0); - /* Trim the Auth if it is longer than required length */ - memcpy(bt_mesh_prov_link.auth, static_val, - size > PROV_AUTH_MAX_LEN ? PROV_AUTH_MAX_LEN : size); - - /* Padd with zeros if the Auth is shorter the required length*/ - if (size < PROV_AUTH_MAX_LEN) { - memset(bt_mesh_prov_link.auth + size, 0, PROV_AUTH_MAX_LEN - size); - } + memcpy(bt_mesh_prov_link.auth + tail_size, static_val, + tail_size ? size : PROV_AUTH_MAX_LEN); + memset(bt_mesh_prov_link.auth, 0, tail_size); return 0; } From acf33ea999c3f83c3117a2554f3a1f96eccdb93d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:22 +0000 Subject: [PATCH 0777/1623] Revert "[nrf fromtree] tests: btp_mesh: Check correct error code" This reverts commit cbeb833f4470fa050c5c43429298ec72e7a656b2. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp_mesh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 1d94eb43cb5..f02d51c905a 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -3801,7 +3801,7 @@ static void dfu_slot_add(size_t size, uint8_t *fwid, size_t fwid_len, return; } - err = bt_mesh_dfu_slot_commit(slot); + bt_mesh_dfu_slot_commit(slot); if (err) { LOG_ERR("Failed to commit slot: %d", err); return; From ac3f491436be3fc81b7a0d5e2c880372f44cc4aa Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:23 +0000 Subject: [PATCH 0778/1623] Revert "[nrf fromtree] bluetooth: mesh: check upload slot before release" This reverts commit 1d3d0be5a5684572f422e1b5c9ee3afabe77c7a7. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/dfd_srv.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 59fe5b830d1..54de343c94a 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -477,9 +477,7 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx /* This will be a no-op if the slot state isn't RESERVED, which is * what we want. */ - if (srv->upload.slot) { - bt_mesh_dfu_slot_release(srv->upload.slot); - } + bt_mesh_dfu_slot_release(srv->upload.slot); #ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD srv->upload.is_oob = false; From a0da100891815d08010d9aee5aa1b7720f0afcfe Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:23 +0000 Subject: [PATCH 0779/1623] Revert "[nrf fromtree] tests: bluetooth: tester: fix improper large comp rsp struct init" This reverts commit 0f4ef37e9e32afb8c4a006df4876d3d27146a75e. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp_mesh.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index f02d51c905a..ffd4b69db84 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1761,12 +1761,7 @@ static uint8_t large_comp_data_get(const void *cmd, uint16_t cmd_len, struct btp_mesh_large_comp_data_get_rp *rp = rsp; int err; - NET_BUF_SIMPLE_DEFINE(data, 500); - net_buf_simple_init(&data, 0); - - struct bt_mesh_large_comp_data_rsp comp = { - .data = &data, - }; + struct bt_mesh_large_comp_data_rsp comp; err = bt_mesh_large_comp_data_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->addr), cp->page, @@ -1790,12 +1785,7 @@ static uint8_t models_metadata_get(const void *cmd, uint16_t cmd_len, struct btp_mesh_models_metadata_get_rp *rp = rsp; int err; - NET_BUF_SIMPLE_DEFINE(data, 500); - net_buf_simple_init(&data, 0); - - struct bt_mesh_large_comp_data_rsp metadata = { - .data = &data, - }; + struct bt_mesh_large_comp_data_rsp metadata; err = bt_mesh_models_metadata_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->addr), cp->page, From 33aa6585d36ae879b62c3afb8dd167bd1fac5ccc Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:23 +0000 Subject: [PATCH 0780/1623] Revert "[nrf fromtree] tests: bluetooth: tester: add transfer ttl to mbt inputs" This reverts commit 954d54fef79f1a2f7400098e2a58bf7b64ec9b18. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp/btp_mesh.h | 2 -- tests/bluetooth/tester/src/btp_mesh.c | 8 +------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 6c4a5e90106..ea5d89de07a 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -954,7 +954,6 @@ struct btp_mmdl_dfu_firmware_update_rp { struct btp_mmdl_blob_srv_recv_cmd { uint64_t id; uint16_t timeout; - uint8_t ttl; } __packed; #define BTP_MMDL_BLOB_TRANSFER_START 0x66 @@ -964,7 +963,6 @@ struct btp_mmdl_blob_transfer_start_cmd { uint8_t block_size; uint16_t chunk_size; uint16_t timeout; - uint8_t ttl; } __packed; #define BTP_MMDL_BLOB_TRANSFER_CANCEL 0x67 diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index ffd4b69db84..b9297474860 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -4228,10 +4228,6 @@ static uint8_t blob_transfer_start(const void *cmd, uint16_t cmd_len, blob_cli_xfer.inputs.timeout_base = cp->timeout; } - if (cp->ttl) { - blob_cli_xfer.inputs.ttl = cp->ttl; - } - err = bt_mesh_blob_cli_send(&blob_cli, &blob_cli_xfer.inputs, &blob_cli_xfer.xfer, &dummy_blob_io); @@ -4315,15 +4311,13 @@ static uint8_t blob_srv_recv(const void *cmd, uint16_t cmd_len, uint16_t timeout_base; uint64_t id; - uint8_t ttl; LOG_DBG(""); id = cp->id; timeout_base = cp->timeout; - ttl = cp->ttl; - err = bt_mesh_blob_srv_recv(srv, id, &dummy_blob_io, ttl, + err = bt_mesh_blob_srv_recv(srv, id, &dummy_blob_io, BT_MESH_TTL_MAX, timeout_base); if (err) { From ccef8673e0204940aafe92078f686c30fce6f75c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:23 +0000 Subject: [PATCH 0781/1623] Revert "[nrf fromtree] tests: bluetooth: tester: Move mesh-1.1 features to a separate conf" This reverts commit 991f7b9e250d62a4df1e3322b28127e7ff3cd69e. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/overlay-mesh-v1d1.conf | 29 ------------------- tests/bluetooth/tester/overlay-mesh.conf | 29 ++++++++++++++++++- tests/bluetooth/tester/testcase.yaml | 9 ------ 3 files changed, 28 insertions(+), 39 deletions(-) delete mode 100644 tests/bluetooth/tester/overlay-mesh-v1d1.conf diff --git a/tests/bluetooth/tester/overlay-mesh-v1d1.conf b/tests/bluetooth/tester/overlay-mesh-v1d1.conf deleted file mode 100644 index 7a3907cc78c..00000000000 --- a/tests/bluetooth/tester/overlay-mesh-v1d1.conf +++ /dev/null @@ -1,29 +0,0 @@ -CONFIG_ENTROPY_GENERATOR=y - -CONFIG_BT_MESH_V1d1=y -CONFIG_BT_MESH_OP_AGG_CLI=y -CONFIG_BT_MESH_OP_AGG_SRV=y -# PTS requires more key slots. -# First one is implicitly taken by Device Key. -CONFIG_BT_MESH_MODEL_KEY_COUNT=3 -CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y -CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y -CONFIG_BT_MESH_SAR_CFG_SRV=y -CONFIG_BT_MESH_SAR_CFG_CLI=y -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_RPR_SRV=y -CONFIG_BT_MESH_RPR_CLI=y -CONFIG_BT_MESH_RPR_AD_TYPES_MAX=2 -CONFIG_BT_MESH_BLOB_CLI=y -CONFIG_BT_MESH_DFU_CLI=y -CONFIG_BT_MESH_BLOB_SRV=y -CONFIG_BT_MESH_DFU_SRV=y -CONFIG_BT_MESH_DFD_SRV=y -CONFIG_BT_MESH_DFU_SLOT_CNT=2 -CONFIG_BT_MESH_PRIV_BEACONS=y -CONFIG_BT_MESH_PRIV_BEACON_SRV=y -CONFIG_BT_MESH_PRIV_BEACON_CLI=y -CONFIG_BT_MESH_MODEL_EXTENSIONS=y -CONFIG_BT_MESH_COMP_PAGE_1=y - -CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 840af06c1c0..fe4c9a62fef 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -1,4 +1,5 @@ CONFIG_BT_MESH=y +CONFIG_BT_MESH_V1d1=y CONFIG_BT_MESH_RELAY=y CONFIG_BT_MESH_PB_ADV=y CONFIG_BT_MESH_PB_GATT=y @@ -8,14 +9,23 @@ CONFIG_BT_MESH_GATT_PROXY=y CONFIG_BT_MESH_LABEL_COUNT=2 CONFIG_BT_MESH_SUBNET_COUNT=2 CONFIG_BT_MESH_MODEL_GROUP_COUNT=2 +CONFIG_BT_MESH_OP_AGG_CLI=y +CONFIG_BT_MESH_OP_AGG_SRV=y +# PTS requires more key slots. +# First one is implicitly taken by Device Key. +CONFIG_BT_MESH_MODEL_KEY_COUNT=3 CONFIG_BT_MESH_APP_KEY_COUNT=4 CONFIG_BT_MESH_IV_UPDATE_TEST=y CONFIG_BT_MESH_CFG_CLI=y CONFIG_BT_MESH_HEALTH_CLI=y +CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y +CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y +CONFIG_BT_MESH_SAR_CFG_SRV=y +CONFIG_BT_MESH_SAR_CFG_CLI=y CONFIG_BT_MESH_FRIEND=y CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=32 CONFIG_BT_MESH_RX_SEG_MAX=13 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=3 +CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 CONFIG_BT_MESH_LPN_POLL_TIMEOUT=100 CONFIG_BT_MESH_PROVISIONER=y CONFIG_BT_MESH_CDB=y @@ -23,3 +33,20 @@ CONFIG_BT_MESH_CDB_NODE_COUNT=3 CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y CONFIG_BT_MESH_MSG_CACHE_SIZE=10 CONFIG_BT_MESH_PROXY_CLIENT=y +CONFIG_BT_MESH_PROVISIONER=y +CONFIG_BT_MESH_RPR_SRV=y +CONFIG_BT_MESH_RPR_CLI=y +CONFIG_BT_MESH_RPR_AD_TYPES_MAX=2 +CONFIG_BT_MESH_BLOB_CLI=y +CONFIG_BT_MESH_DFU_CLI=y +CONFIG_BT_MESH_BLOB_SRV=y +CONFIG_BT_MESH_DFU_SRV=y +CONFIG_BT_MESH_DFD_SRV=y +CONFIG_BT_MESH_DFU_SLOT_CNT=2 +CONFIG_BT_MESH_PRIV_BEACONS=y +CONFIG_BT_MESH_PRIV_BEACON_SRV=y +CONFIG_BT_MESH_PRIV_BEACON_CLI=y +CONFIG_BT_MESH_MODEL_EXTENSIONS=y +CONFIG_BT_MESH_COMP_PAGE_1=y + +CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/testcase.yaml b/tests/bluetooth/tester/testcase.yaml index dba67716af1..65588568994 100644 --- a/tests/bluetooth/tester/testcase.yaml +++ b/tests/bluetooth/tester/testcase.yaml @@ -25,12 +25,3 @@ tests: extra_args: OVERLAY_CONFIG="overlay-mesh.conf" tags: bluetooth harness: bluetooth - bluetooth.general.tester_mesh_v1d1: - build_only: true - platform_allow: - - qemu_x86 - - native_posix - - nrf52840dk_nrf52840 - extra_args: OVERLAY_CONFIG="overlay-mesh.conf;overlay-mesh-v1d1.conf" - tags: bluetooth - harness: bluetooth From d14b38c7e117ab9e99569a501ee15a82cdd15a38 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:24 +0000 Subject: [PATCH 0782/1623] Revert "[nrf fromtree] tests: Bluetooth: tester: add support for Proxy Solicitation" This reverts commit fd0886b30723ba0a0309fd4d6c0e01442dc7dc4f. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp/btp_mesh.h | 27 ----- tests/bluetooth/tester/src/btp_mesh.c | 138 ---------------------- 2 files changed, 165 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index ea5d89de07a..e93c2ceeb3d 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -1009,33 +1009,6 @@ struct btp_priv_node_id_set_cmd { #define BTP_MESH_PROXY_PRIVATE_IDENTITY 0x72 -#define BTP_MESH_OD_PRIV_PROXY_GET 0x73 -struct btp_od_priv_proxy_get_cmd { - uint16_t dst; -} __packed; - -#define BTP_MESH_OD_PRIV_PROXY_SET 0x74 - -struct btp_od_priv_proxy_set_cmd { - uint16_t dst; - uint8_t val; -} __packed; - -#define BTP_MESH_SRPL_CLEAR 0x75 - -struct btp_srpl_clear_cmd { - uint16_t dst; - uint16_t range_start; - uint8_t range_len; - uint8_t acked; -} __packed; - -#define BTP_MESH_PROXY_SOLICIT 0x76 - -struct btp_proxy_solicit_cmd { - uint16_t net_idx; -} __packed; - /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index b9297474860..2c837bfb198 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -773,108 +773,6 @@ static uint8_t proxy_private_identity_enable(const void *cmd, uint16_t cmd_len, } #endif -#if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI) -static struct bt_mesh_sol_pdu_rpl_cli srpl_cli; -#endif - - -#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI) -static struct bt_mesh_od_priv_proxy_cli od_priv_proxy_cli; - -static uint8_t od_priv_proxy_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_od_priv_proxy_get_cmd *cp = cmd; - uint8_t val_rsp; - int err; - - LOG_DBG(""); - - err = bt_mesh_od_priv_proxy_cli_get(net.net_idx, cp->dst, &val_rsp); - if (err) { - LOG_ERR("Failed to get On-Demand Private Proxy state (err %d)", err); - return BTP_STATUS_FAILED; - } - - LOG_DBG("On-Demand Private Proxy state: %u", val_rsp); - - return BTP_STATUS_SUCCESS; -} - -static uint8_t od_priv_proxy_set(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_od_priv_proxy_set_cmd *cp = cmd; - uint8_t val_rsp; - int err; - - LOG_DBG(""); - - err = bt_mesh_od_priv_proxy_cli_set(net.net_idx, cp->dst, cp->val, &val_rsp); - if (err) { - LOG_ERR("Failed to set On-Demand Private Proxy state (err %d)", err); - return BTP_STATUS_FAILED; - } - - LOG_DBG("On-Demand Private Proxy set state: %u", val_rsp); - - return BTP_STATUS_SUCCESS; -} - -#endif - -#if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI) -static uint8_t srpl_clear(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_srpl_clear_cmd *cp = cmd; - uint16_t app_idx = BT_MESH_KEY_UNUSED; - uint16_t start_rsp; - uint8_t len_rsp; - int err; - - /* Lookup source address */ - for (int i = 0; i < ARRAY_SIZE(model_bound); i++) { - if (model_bound[i].model->id == BT_MESH_MODEL_ID_SOL_PDU_RPL_CLI) { - app_idx = model_bound[i].appkey_idx; - break; - } - } - - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, cp->dst); - - if (cp->acked) { - err = bt_mesh_sol_pdu_rpl_clear(&ctx, cp->range_start, cp->range_len, &start_rsp, - &len_rsp); - } else { - err = bt_mesh_sol_pdu_rpl_clear_unack(&ctx, cp->range_start, cp->range_len); - } - if (err) { - LOG_ERR("Failed to clear SRPL (err %d)", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} -#endif - -#if defined(CONFIG_BT_MESH_PROXY_SOLICITATION) -static uint8_t proxy_solicit(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_proxy_solicit_cmd *cp = cmd; - int err; - - err = bt_mesh_proxy_solicit(cp->net_idx); - if (err) { - LOG_ERR("Failed to advertise solicitation PDU (err %d)", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} -#endif /* CONFIG_BT_MESH_PROXY_SOLICITATION */ - static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), @@ -919,16 +817,6 @@ static struct bt_mesh_model root_models[] = { #if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI) BT_MESH_MODEL_PRIV_BEACON_CLI(&priv_beacon_cli), #endif -#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI) - BT_MESH_MODEL_OD_PRIV_PROXY_CLI(&od_priv_proxy_cli), -#endif -#if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI) - BT_MESH_MODEL_SOL_PDU_RPL_CLI(&srpl_cli), -#endif -#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) - BT_MESH_MODEL_OD_PRIV_PROXY_SRV, -#endif - }; struct model_data *lookup_model_bound(uint16_t id) { @@ -4895,32 +4783,6 @@ static const struct btp_handler handlers[] = { .func = proxy_private_identity_enable }, #endif -#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI) - { - .opcode = BTP_MESH_OD_PRIV_PROXY_GET, - .expect_len = sizeof(struct btp_od_priv_proxy_get_cmd), - .func = od_priv_proxy_get - }, - { - .opcode = BTP_MESH_OD_PRIV_PROXY_SET, - .expect_len = sizeof(struct btp_od_priv_proxy_set_cmd), - .func = od_priv_proxy_set - }, -#endif -#if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI) - { - .opcode = BTP_MESH_SRPL_CLEAR, - .expect_len = sizeof(struct btp_srpl_clear_cmd), - .func = srpl_clear - }, -#endif -#if defined(CONFIG_BT_MESH_SOLICITATION) - { - .opcode = BTP_MESH_PROXY_SOLICIT, - .expect_len = sizeof(struct btp_proxy_solicit_cmd), - .func = proxy_solicit - }, -#endif }; From b2c031ec985e0d66828654e18f563d6176c93bd1 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:24 +0000 Subject: [PATCH 0783/1623] Revert "[nrf fromtree] tests: Bluetooth: tester: Add Models Metadata Page 128" This reverts commit 5237cdd07078a0064c3808f31d263e07f1d9ee42. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp_mesh.c | 33 --------------------------- 1 file changed, 33 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 2c837bfb198..5a7b4bb5fd7 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -542,31 +542,8 @@ static uint8_t health_tests[] = { BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_NORDIC_SEMI, 3, 0x01, 0x02, 0x03), }; -static uint8_t zero_metadata[100]; - static struct bt_mesh_models_metadata_entry health_srv_meta[] = { BT_MESH_HEALTH_TEST_INFO_METADATA(health_tests), - { - .len = ARRAY_SIZE(zero_metadata), - .id = 0xABCD, - .data = zero_metadata, - }, - BT_MESH_MODELS_METADATA_END, -}; - -static uint8_t health_tests_alt[] = { - BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_LF, 6, 0x11, 0x22, 0x33, 0x44, 0x55, - 0x66), - BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_NORDIC_SEMI, 3, 0x11, 0x22, 0x33), -}; - -static struct bt_mesh_models_metadata_entry health_srv_meta_alt[] = { - BT_MESH_HEALTH_TEST_INFO_METADATA(health_tests_alt), - { - .len = ARRAY_SIZE(zero_metadata), - .id = 0xFEED, - .data = zero_metadata, - }, BT_MESH_MODELS_METADATA_END, }; #endif @@ -1732,13 +1709,6 @@ static uint8_t change_prepare(const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } -#if CONFIG_BT_MESH_LARGE_COMP_DATA_SRV - err = bt_mesh_models_metadata_change_prepare(); - if (err < 0) { - return BTP_STATUS_FAILED; - } -#endif - return BTP_STATUS_SUCCESS; } @@ -5056,9 +5026,6 @@ uint8_t tester_init_mesh(void) if (default_comp) { err = bt_mesh_init(&prov, &comp); } else { -#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV - health_srv.metadata = health_srv_meta_alt; -#endif err = bt_mesh_init(&prov, &comp_alt); } From 77cd168ff114808b2c3b61f686e220d07eba6e96 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:24 +0000 Subject: [PATCH 0784/1623] Revert "[nrf fromtree] tests: Bluetooth: tester: enable Composition Data Page 1" This reverts commit d629e26fb5e4ffc8e70de557700d6f98285a9db4. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/overlay-mesh.conf | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index fe4c9a62fef..95a61769a1a 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -46,7 +46,5 @@ CONFIG_BT_MESH_DFU_SLOT_CNT=2 CONFIG_BT_MESH_PRIV_BEACONS=y CONFIG_BT_MESH_PRIV_BEACON_SRV=y CONFIG_BT_MESH_PRIV_BEACON_CLI=y -CONFIG_BT_MESH_MODEL_EXTENSIONS=y -CONFIG_BT_MESH_COMP_PAGE_1=y CONFIG_SETTINGS=y From 125d9bcf338aa34a0a634b730de30050a7367886 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:24 +0000 Subject: [PATCH 0785/1623] Revert "[nrf fromtree] Tests: Bluetooth: Tester: Add BTP command to enable Private NID" This reverts commit c77879087eaaae5206ba1274c86636d903ae119c. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/overlay-mesh.conf | 3 - tests/bluetooth/tester/src/btp/btp_mesh.h | 38 ----- tests/bluetooth/tester/src/btp_mesh.c | 177 ---------------------- 3 files changed, 218 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 95a61769a1a..60f809f77e5 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -43,8 +43,5 @@ CONFIG_BT_MESH_BLOB_SRV=y CONFIG_BT_MESH_DFU_SRV=y CONFIG_BT_MESH_DFD_SRV=y CONFIG_BT_MESH_DFU_SLOT_CNT=2 -CONFIG_BT_MESH_PRIV_BEACONS=y -CONFIG_BT_MESH_PRIV_BEACON_SRV=y -CONFIG_BT_MESH_PRIV_BEACON_CLI=y CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index e93c2ceeb3d..63fb2adcf12 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -971,44 +971,6 @@ struct btp_mmdl_blob_transfer_start_cmd { #define BTP_MMDL_DFU_FIRMWARE_UPDATE_APPLY 0x6A #define BTP_MMDL_DFU_SRV_APPLY 0x6B -#define BTP_MESH_PRIV_BEACON_GET 0x6c -struct btp_priv_beacon_get_cmd { - uint16_t dst; -} __packed; - -#define BTP_MESH_PRIV_BEACON_SET 0x6d -struct btp_priv_beacon_set_cmd { - uint16_t dst; - uint8_t enabled; - uint8_t rand_interval; -} __packed; - -#define BTP_MESH_PRIV_GATT_PROXY_GET 0x6e -struct btp_priv_gatt_proxy_get_cmd { - uint16_t dst; -} __packed; - -#define BTP_MESH_PRIV_GATT_PROXY_SET 0x6f -struct btp_priv_gatt_proxy_set_cmd { - uint16_t dst; - uint8_t state; -} __packed; - -#define BTP_MESH_PRIV_NODE_ID_GET 0x70 -struct btp_priv_node_id_get_cmd { - uint16_t dst; - uint16_t key_net_idx; -} __packed; - -#define BTP_MESH_PRIV_NODE_ID_SET 0x71 -struct btp_priv_node_id_set_cmd { - uint16_t dst; - uint16_t net_idx; - uint8_t state; -} __packed; - -#define BTP_MESH_PROXY_PRIVATE_IDENTITY 0x72 - /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 5a7b4bb5fd7..4f3d181fd1d 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -617,139 +617,6 @@ static uint8_t dfu_srv_apply(const void *cmd, uint16_t cmd_len, } #endif -#ifdef CONFIG_BT_MESH_PRIV_BEACON_CLI -static struct bt_mesh_priv_beacon_cli priv_beacon_cli; - -static uint8_t priv_beacon_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_priv_beacon_get_cmd *cp = cmd; - - struct bt_mesh_priv_beacon val; - int err; - - err = bt_mesh_priv_beacon_cli_get(net.net_idx, cp->dst, &val); - if (err) { - LOG_ERR("Failed to send Private Beacon Get (err %d)", err); - return BTP_STATUS_FAILED; - } - - LOG_DBG("Private Beacon state: %u, %u", val.enabled, val.rand_interval); - return BTP_STATUS_SUCCESS; -} - -static uint8_t priv_beacon_set(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_priv_beacon_set_cmd *cp = cmd; - struct bt_mesh_priv_beacon val; - int err; - - val.enabled = cp->enabled; - val.rand_interval = cp->rand_interval; - - err = bt_mesh_priv_beacon_cli_set(net.net_idx, cp->dst, &val); - if (err) { - LOG_ERR("Failed to send Private Beacon Set (err %d)", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t priv_gatt_proxy_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_priv_gatt_proxy_get_cmd *cp = cmd; - - uint8_t state; - int err; - - err = bt_mesh_priv_beacon_cli_gatt_proxy_get(net.net_idx, cp->dst, &state); - if (err) { - LOG_ERR("Failed to send Private GATT Proxy Get (err %d)", err); - return BTP_STATUS_FAILED; - } - - LOG_DBG("Private GATT Proxy state: %u", state); - return BTP_STATUS_SUCCESS; -} - -static uint8_t priv_gatt_proxy_set(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_priv_gatt_proxy_set_cmd *cp = cmd; - - uint8_t state; - int err; - - state = cp->state; - - err = bt_mesh_priv_beacon_cli_gatt_proxy_set(net.net_idx, cp->dst, &state); - if (err) { - LOG_ERR("Failed to send Private GATT Proxy Set (err %d)", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t priv_node_id_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_priv_node_id_get_cmd *cp = cmd; - struct bt_mesh_priv_node_id val; - uint16_t key_net_idx; - int err; - - key_net_idx = cp->key_net_idx; - - err = bt_mesh_priv_beacon_cli_node_id_get(net.net_idx, cp->dst, key_net_idx, &val); - if (err) { - LOG_ERR("Failed to send Private Node Identity Get (err %d)", err); - return BTP_STATUS_FAILED; - } - - LOG_DBG("Private Node Identity state: %u %u %u", val.net_idx, val.state, val.status); - return BTP_STATUS_SUCCESS; -} - -static uint8_t priv_node_id_set(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_priv_node_id_set_cmd *cp = cmd; - struct bt_mesh_priv_node_id val; - int err; - - val.net_idx = cp->net_idx; - val.state = cp->state; - - err = bt_mesh_priv_beacon_cli_node_id_set(net.net_idx, cp->dst, &val); - if (err) { - LOG_ERR("Failed to send Private Node Identity Set (err %d)", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t proxy_private_identity_enable(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - int err; - - LOG_DBG(""); - - err = bt_mesh_proxy_private_identity_enable(); - if (err) { - LOG_ERR("Failed to enable proxy private identity (err %d)", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} -#endif - static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), @@ -788,12 +655,6 @@ static struct bt_mesh_model root_models[] = { #if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) BT_MESH_MODEL_BLOB_CLI(&blob_cli), #endif -#if defined(CONFIG_BT_MESH_PRIV_BEACON_SRV) - BT_MESH_MODEL_PRIV_BEACON_SRV, -#endif -#if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI) - BT_MESH_MODEL_PRIV_BEACON_CLI(&priv_beacon_cli), -#endif }; struct model_data *lookup_model_bound(uint16_t id) { @@ -4715,44 +4576,6 @@ static const struct btp_handler handlers[] = { .expect_len = sizeof(struct btp_rpr_reprov_remote_cmd), .func = rpr_reprov_remote }, -#endif -#if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI) - { - .opcode = BTP_MESH_PRIV_BEACON_GET, - .expect_len = sizeof(struct btp_priv_beacon_get_cmd), - .func = priv_beacon_get - }, - { - .opcode = BTP_MESH_PRIV_BEACON_SET, - .expect_len = sizeof(struct btp_priv_beacon_set_cmd), - .func = priv_beacon_set - }, - { - .opcode = BTP_MESH_PRIV_GATT_PROXY_GET, - .expect_len = sizeof(struct btp_priv_gatt_proxy_get_cmd), - .func = priv_gatt_proxy_get - }, - { - .opcode = BTP_MESH_PRIV_GATT_PROXY_SET, - .expect_len = sizeof(struct btp_priv_gatt_proxy_set_cmd), - .func = priv_gatt_proxy_set - }, - { - .opcode = BTP_MESH_PRIV_NODE_ID_GET, - .expect_len = sizeof(struct btp_priv_node_id_get_cmd), - .func = priv_node_id_get - }, - { - .opcode = BTP_MESH_PRIV_NODE_ID_SET, - .expect_len = sizeof(struct btp_priv_node_id_set_cmd), - .func = priv_node_id_set - }, - { - .opcode = BTP_MESH_PROXY_PRIVATE_IDENTITY, - .expect_len = 0, - .func = proxy_private_identity_enable - }, -#endif }; From 84a90fbf1539c5d600e08da50f96ce3e8ecfa6bc Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:24 +0000 Subject: [PATCH 0786/1623] Revert "[nrf fromtree] tests: bluetooth: tester: Add Opcodes Aggregator support" This reverts commit 14e69effb12eee44178feadc4d8e9d0cac0b9cbd. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/overlay-mesh.conf | 5 - tests/bluetooth/tester/src/btp/btp_mesh.h | 10 -- tests/bluetooth/tester/src/btp_mesh.c | 115 +++------------------- 3 files changed, 11 insertions(+), 119 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 60f809f77e5..3352e36f3a4 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -9,11 +9,6 @@ CONFIG_BT_MESH_GATT_PROXY=y CONFIG_BT_MESH_LABEL_COUNT=2 CONFIG_BT_MESH_SUBNET_COUNT=2 CONFIG_BT_MESH_MODEL_GROUP_COUNT=2 -CONFIG_BT_MESH_OP_AGG_CLI=y -CONFIG_BT_MESH_OP_AGG_SRV=y -# PTS requires more key slots. -# First one is implicitly taken by Device Key. -CONFIG_BT_MESH_MODEL_KEY_COUNT=3 CONFIG_BT_MESH_APP_KEY_COUNT=4 CONFIG_BT_MESH_IV_UPDATE_TEST=y CONFIG_BT_MESH_CFG_CLI=y diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 63fb2adcf12..66a86bbb128 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -835,16 +835,6 @@ struct btp_mesh_models_metadata_get_rp { uint8_t data[0]; } __packed; -#define BTP_MESH_OPCODES_AGGREGATOR_INIT 0x55 -struct btp_mesh_opcodes_aggregator_init_cmd { - uint16_t net_idx; - uint16_t app_idx; - uint16_t dst; - uint16_t elem_addr; -} __packed; - -#define BTP_MESH_OPCODES_AGGREGATOR_SEND 0x56 - #define BTP_MESH_COMP_CHANGE_PREPARE 0x57 #define BTP_MESH_SET_COMP_ALT 0x58 diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 4f3d181fd1d..8c637320a11 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -634,12 +634,6 @@ static struct bt_mesh_model root_models[] = { #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&lcd_cli), #endif -#if defined(CONFIG_BT_MESH_OP_AGG_SRV) - BT_MESH_MODEL_OP_AGG_SRV, -#endif -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - BT_MESH_MODEL_OP_AGG_CLI, -#endif #if defined(CONFIG_BT_MESH_RPR_CLI) BT_MESH_MODEL_RPR_CLI(&rpr_cli), #endif @@ -2497,8 +2491,6 @@ static uint8_t config_model_app_bind(const void *cmd, uint16_t cmd_len, LOG_DBG(""); - bt_mesh_cfg_cli_timeout_set(5000); - err = bt_mesh_cfg_cli_mod_app_bind(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -2942,7 +2934,7 @@ static uint8_t health_fault_clear(const void *cmd, uint16_t cmd_len, .addr = sys_le16_to_cpu(cp->address), .app_idx = sys_le16_to_cpu(cp->app_idx), }; - uint8_t test_id = 0; + uint8_t test_id; size_t fault_count = 16; uint8_t faults[fault_count]; int err; @@ -2952,20 +2944,7 @@ static uint8_t health_fault_clear(const void *cmd, uint16_t cmd_len, if (cp->ack) { err = bt_mesh_health_cli_fault_clear(&health_cli, &ctx, sys_le16_to_cpu(cp->cid), -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - bt_mesh_op_agg_cli_seq_is_started() ? - NULL : -#endif - &test_id, -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - bt_mesh_op_agg_cli_seq_is_started() ? - NULL : -#endif - faults, -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - bt_mesh_op_agg_cli_seq_is_started() ? - NULL : -#endif + &test_id, faults, &fault_count); } else { err = bt_mesh_health_cli_fault_clear_unack(&health_cli, &ctx, @@ -2998,37 +2977,20 @@ static uint8_t health_fault_test(const void *cmd, uint16_t cmd_len, }; size_t fault_count = 16; uint8_t faults[fault_count]; + uint8_t test_id; + uint16_t cid; int err; LOG_DBG(""); + test_id = cp->test_id; + cid = sys_le16_to_cpu(cp->cid); + if (cp->ack) { - err = bt_mesh_health_cli_fault_test(&health_cli, &ctx, - sys_le16_to_cpu(cp->cid), -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - bt_mesh_op_agg_cli_seq_is_started() ? - 0 : -#endif - cp->test_id, -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - bt_mesh_op_agg_cli_seq_is_started() ? - NULL : -#endif - faults, -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - bt_mesh_op_agg_cli_seq_is_started() ? - NULL : -#endif + err = bt_mesh_health_cli_fault_test(&health_cli, &ctx, cid, test_id, faults, &fault_count); -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - if (bt_mesh_op_agg_cli_seq_is_started()) { - fault_count = 0; - } -#endif } else { - err = bt_mesh_health_cli_fault_test_unack(&health_cli, &ctx, - sys_le16_to_cpu(cp->cid), - cp->test_id); + err = bt_mesh_health_cli_fault_test_unack(&health_cli, &ctx, cid, test_id); } if (err) { @@ -3039,8 +3001,8 @@ static uint8_t health_fault_test(const void *cmd, uint16_t cmd_len, if (cp->ack) { struct btp_mesh_health_fault_test_rp *rp = rsp; - rp->test_id = cp->test_id; - rp->cid = cp->cid; + rp->test_id = test_id; + rp->cid = sys_cpu_to_le16(cid); (void)memcpy(rp->faults, faults, fault_count); *rsp_len = sizeof(*rp) + fault_count; @@ -3089,10 +3051,6 @@ static uint8_t health_period_set(const void *cmd, uint16_t cmd_len, if (cp->ack) { err = bt_mesh_health_cli_period_set(&health_cli, &ctx, cp->divisor, -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - bt_mesh_op_agg_cli_seq_is_started() ? - NULL : -#endif &updated_divisor); } else { err = bt_mesh_health_cli_period_set_unack(&health_cli, &ctx, cp->divisor); @@ -3154,10 +3112,6 @@ static uint8_t health_attention_set(const void *cmd, uint16_t cmd_len, if (cp->ack) { err = bt_mesh_health_cli_attention_set(&health_cli, &ctx, cp->attention, -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - bt_mesh_op_agg_cli_seq_is_started() ? - NULL : -#endif &updated_attention); } else { err = bt_mesh_health_cli_attention_set_unack(&health_cli, &ctx, cp->attention); @@ -3179,41 +3133,6 @@ static uint8_t health_attention_set(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) -static uint8_t opcodes_aggregator_init(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mesh_opcodes_aggregator_init_cmd *cp = cmd; - int err; - - LOG_DBG(""); - - err = bt_mesh_op_agg_cli_seq_start(cp->net_idx, cp->app_idx, cp->dst, cp->elem_addr); - if (err) { - LOG_ERR("Failed to init Opcodes Aggregator Context (err %d)", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t opcodes_aggregator_send(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - int err; - - LOG_DBG(""); - - err = bt_mesh_op_agg_cli_seq_send(); - if (err) { - LOG_ERR("Failed to send Opcodes Aggregator message (err %d)", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} -#endif - #if defined(CONFIG_BT_MESH_RPR_CLI) static uint8_t rpr_scan_start(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -4507,18 +4426,6 @@ static const struct btp_handler handlers[] = { .expect_len = sizeof(struct btp_mesh_models_metadata_get_cmd), .func = models_metadata_get }, -#endif -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - { - .opcode = BTP_MESH_OPCODES_AGGREGATOR_INIT, - .expect_len = sizeof(struct btp_mesh_opcodes_aggregator_init_cmd), - .func = opcodes_aggregator_init - }, - { - .opcode = BTP_MESH_OPCODES_AGGREGATOR_SEND, - .expect_len = 0, - .func = opcodes_aggregator_send - }, #endif { .opcode = BTP_MESH_COMP_CHANGE_PREPARE, From 6dac39351e9f74e3cdf6e535203bc7c22c1564a0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:25 +0000 Subject: [PATCH 0787/1623] Revert "[nrf fromtree] Bluetooth: Tester: Add Blob, DFU and DFD tests support" This reverts commit 26290321c5f585ca469dd52076fe458045a55d01. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/overlay-mesh.conf | 8 +- tests/bluetooth/tester/src/btp/btp_mesh.h | 68 -- tests/bluetooth/tester/src/btp/bttester.h | 3 - tests/bluetooth/tester/src/btp_core.c | 6 - tests/bluetooth/tester/src/btp_mesh.c | 999 +--------------------- 5 files changed, 2 insertions(+), 1082 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 3352e36f3a4..b537ae0001e 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -20,7 +20,7 @@ CONFIG_BT_MESH_SAR_CFG_CLI=y CONFIG_BT_MESH_FRIEND=y CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=32 CONFIG_BT_MESH_RX_SEG_MAX=13 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 +CONFIG_BT_MESH_TX_SEG_MSG_COUNT=3 CONFIG_BT_MESH_LPN_POLL_TIMEOUT=100 CONFIG_BT_MESH_PROVISIONER=y CONFIG_BT_MESH_CDB=y @@ -32,11 +32,5 @@ CONFIG_BT_MESH_PROVISIONER=y CONFIG_BT_MESH_RPR_SRV=y CONFIG_BT_MESH_RPR_CLI=y CONFIG_BT_MESH_RPR_AD_TYPES_MAX=2 -CONFIG_BT_MESH_BLOB_CLI=y -CONFIG_BT_MESH_DFU_CLI=y -CONFIG_BT_MESH_BLOB_SRV=y -CONFIG_BT_MESH_DFU_SRV=y -CONFIG_BT_MESH_DFD_SRV=y -CONFIG_BT_MESH_DFU_SLOT_CNT=2 CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 66a86bbb128..29523d02d8c 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -895,72 +895,6 @@ struct btp_rpr_reprov_remote_cmd { bool comp_change; } __packed; -#define BTP_MMDL_DFU_INFO_GET 0x5f -struct btp_mmdl_dfu_info_get_cmd { - uint8_t limit; -} __packed; - -#define BTP_MMDL_BLOB_INFO_GET 0x60 -struct btp_mmdl_blob_info_get_cmd { - uint8_t addr_cnt; - uint8_t addr[]; -} __packed; - -#define BTP_MMDL_DFU_UPDATE_METADATA_CHECK 0x61 -struct btp_mmdl_dfu_metadata_check_cmd { - uint8_t index; - uint8_t slot_idx; - uint8_t slot_size; - uint8_t fwid_len; - uint8_t metadata_len; - uint8_t data[]; -} __packed; - -struct btp_mmdl_dfu_metadata_check_rp { - uint8_t idx; - uint8_t status; - uint8_t effect; -} __packed; - -#define BTP_MMDL_DFU_FIRMWARE_UPDATE_GET 0x62 -#define BTP_MMDL_DFU_FIRMWARE_UPDATE_CANCEL 0x63 -#define BTP_MMDL_DFU_FIRMWARE_UPDATE_START 0x64 -struct btp_mmdl_dfu_firmware_update_cmd { - uint8_t addr_cnt; - uint8_t slot_idx; - uint8_t slot_size; - uint8_t fwid_len; - uint8_t metadata_len; - uint8_t block_size; - uint16_t chunk_size; - uint8_t data[]; -} __packed; - -struct btp_mmdl_dfu_firmware_update_rp { - uint8_t status; -} __packed; - -#define BTP_MMDL_BLOB_SRV_RECV 0x65 -struct btp_mmdl_blob_srv_recv_cmd { - uint64_t id; - uint16_t timeout; -} __packed; - -#define BTP_MMDL_BLOB_TRANSFER_START 0x66 -struct btp_mmdl_blob_transfer_start_cmd { - uint64_t id; - uint16_t size; - uint8_t block_size; - uint16_t chunk_size; - uint16_t timeout; -} __packed; - -#define BTP_MMDL_BLOB_TRANSFER_CANCEL 0x67 -#define BTP_MMDL_BLOB_TRANSFER_GET 0x68 -#define BTP_MMDL_BLOB_SRV_CANCEL 0x69 -#define BTP_MMDL_DFU_FIRMWARE_UPDATE_APPLY 0x6A -#define BTP_MMDL_DFU_SRV_APPLY 0x6B - /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { @@ -1062,5 +996,3 @@ struct btp_mesh_model_recv_ev { uint8_t payload_len; uint8_t payload[]; } __packed; - -#define MESH_EV_BLOB_LOST_TARGET 0x90 diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index 84d4722a913..b30eee70d44 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -73,9 +73,6 @@ uint8_t tester_unregister_vocs(void); uint8_t tester_init_ias(void); uint8_t tester_unregister_ias(void); -uint8_t tester_init_mmdl(void); -uint8_t tester_unregister_mmdl(void); - uint8_t tester_init_gap(void); uint8_t tester_unregister_gap(void); diff --git a/tests/bluetooth/tester/src/btp_core.c b/tests/bluetooth/tester/src/btp_core.c index 7ece1224ed0..36f92619bfc 100644 --- a/tests/bluetooth/tester/src/btp_core.c +++ b/tests/bluetooth/tester/src/btp_core.c @@ -118,9 +118,6 @@ static uint8_t register_service(const void *cmd, uint16_t cmd_len, case BTP_SERVICE_ID_MESH: status = tester_init_mesh(); break; - case BTP_SERVICE_ID_MESH_MDL: - status = tester_init_mmdl(); - break; #endif /* CONFIG_BT_MESH */ #if defined(CONFIG_BT_VCP_VOL_REND) case BTP_SERVICE_ID_VCS: @@ -204,9 +201,6 @@ static uint8_t unregister_service(const void *cmd, uint16_t cmd_len, case BTP_SERVICE_ID_MESH: status = tester_unregister_mesh(); break; - case BTP_SERVICE_ID_MESH_MDL: - status = tester_unregister_mmdl(); - break; #endif /* CONFIG_BT_MESH */ #if defined(CONFIG_BT_VCP_VOL_REND) case BTP_SERVICE_ID_VCS: diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 8c637320a11..40ae3a6f038 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -12,18 +12,15 @@ #include #include #include -#include #include #include #include -#include #include #define LOG_MODULE_NAME bttester_mesh LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_BTTESTER_LOG_LEVEL); #include "btp/btp.h" -#include "dfu_slot.h" #define CID_LOCAL 0x05F1 #define COMPANY_ID_LF 0x05F1 @@ -57,245 +54,7 @@ static uint8_t vnd_app_key[16]; static uint16_t vnd_app_key_idx = 0x000f; /* Model send data */ -#define MODEL_BOUNDS_MAX 100 - -#if defined(CONFIG_BT_MESH_BLOB_SRV) || defined(CONFIG_BT_MESH_BLOB_CLI) -/* BLOB Model data*/ -static uint8_t blob_rx_sum; -static bool blob_valid; -static const char *blob_data = "11111111111111111111111111111111"; - -static int blob_io_open(const struct bt_mesh_blob_io *io, - const struct bt_mesh_blob_xfer *xfer, - enum bt_mesh_blob_io_mode mode) -{ - blob_rx_sum = 0; - blob_valid = true; - return 0; -} - -static int blob_chunk_wr(const struct bt_mesh_blob_io *io, - const struct bt_mesh_blob_xfer *xfer, - const struct bt_mesh_blob_block *block, - const struct bt_mesh_blob_chunk *chunk) -{ - for (int i = 0; i < chunk->size; ++i) { - blob_rx_sum += chunk->data[i]; - if (chunk->data[i] != - blob_data[(i + chunk->offset) % strlen(blob_data)]) { - blob_valid = false; - } - } - - return 0; -} - -static int blob_chunk_rd(const struct bt_mesh_blob_io *io, - const struct bt_mesh_blob_xfer *xfer, - const struct bt_mesh_blob_block *block, - const struct bt_mesh_blob_chunk *chunk) -{ - for (int i = 0; i < chunk->size; ++i) { - chunk->data[i] = - blob_data[(i + chunk->offset) % strlen(blob_data)]; - } - - return 0; -} - -static const struct bt_mesh_blob_io dummy_blob_io = { - .open = blob_io_open, - .rd = blob_chunk_rd, - .wr = blob_chunk_wr, -}; -#endif - -#if defined(CONFIG_BT_MESH_DFD_SRV) -/* DFD Model data*/ -static int dfd_srv_recv(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot, - const struct bt_mesh_blob_io **io) -{ - LOG_DBG("Uploading new firmware image to the distributor."); - - *io = &dummy_blob_io; - - return 0; -} - -static void dfd_srv_del(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot) -{ - LOG_DBG("Deleting the firmware image from the distributor."); -} - -static int dfd_srv_send(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot, - const struct bt_mesh_blob_io **io) -{ - LOG_DBG("Starting the firmware distribution."); - - *io = &dummy_blob_io; - - return 0; -} - -static struct bt_mesh_dfd_srv_cb dfd_srv_cb = { - .recv = dfd_srv_recv, - .del = dfd_srv_del, - .send = dfd_srv_send, -}; - -static struct bt_mesh_dfd_srv dfd_srv = BT_MESH_DFD_SRV_INIT(&dfd_srv_cb); -#endif - -#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) -static struct { - struct bt_mesh_blob_cli_inputs inputs; - struct bt_mesh_blob_target targets[32]; - struct bt_mesh_blob_target_pull pull[32]; - uint8_t target_count; - struct bt_mesh_blob_xfer xfer; -} blob_cli_xfer; - -static void blob_cli_lost_target(struct bt_mesh_blob_cli *cli, - struct bt_mesh_blob_target *target, - enum bt_mesh_blob_status reason) -{ - LOG_DBG("Mesh Blob: Lost target 0x%04x (reason: %u)", target->addr, - reason); - tester_event(BTP_SERVICE_ID_MESH, MESH_EV_BLOB_LOST_TARGET, NULL, 0); -} - -static void blob_cli_caps(struct bt_mesh_blob_cli *cli, - const struct bt_mesh_blob_cli_caps *caps) -{ - const char *const modes[] = { - "none", - "push", - "pull", - "all", - }; - - if (!caps) { - LOG_DBG("None of the targets can be used for BLOB transfer"); - return; - } - - LOG_DBG("Mesh BLOB: capabilities:"); - LOG_DBG("\tMax BLOB size: %u bytes", caps->max_size); - LOG_DBG("\tBlock size: %u-%u (%u-%u bytes)", caps->min_block_size_log, - caps->max_block_size_log, 1 << caps->min_block_size_log, - 1 << caps->max_block_size_log); - LOG_DBG("\tMax chunks: %u", caps->max_chunks); - LOG_DBG("\tChunk size: %u", caps->max_chunk_size); - LOG_DBG("\tMTU size: %u", caps->mtu_size); - LOG_DBG("\tModes: %s", modes[caps->modes]); -} - -static void blob_cli_end(struct bt_mesh_blob_cli *cli, - const struct bt_mesh_blob_xfer *xfer, bool success) -{ - if (success) { - LOG_DBG("Mesh BLOB transfer complete."); - } else { - LOG_DBG("Mesh BLOB transfer failed."); - } -} - -static const struct bt_mesh_blob_cli_cb blob_cli_handlers = { - .lost_target = blob_cli_lost_target, - .caps = blob_cli_caps, - .end = blob_cli_end, -}; - -static struct bt_mesh_blob_cli blob_cli = { .cb = &blob_cli_handlers }; -#endif - -#if defined(CONFIG_BT_MESH_DFU_SRV) -const char *metadata_data = "1100000000000011"; - -static uint8_t dfu_fwid[] = { - 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -static struct bt_mesh_dfu_img dfu_imgs[] = { { - .fwid = &dfu_fwid, - .fwid_len = sizeof(dfu_fwid), -} }; - -static int dfu_meta_check(struct bt_mesh_dfu_srv *srv, - const struct bt_mesh_dfu_img *img, - struct net_buf_simple *metadata, - enum bt_mesh_dfu_effect *effect) -{ - char string[2 * CONFIG_BT_MESH_DFU_METADATA_MAXLEN + 1]; - int i; - size_t len; - - len = bin2hex(metadata->data, metadata->len, string, sizeof(string)); - string[len] = '\0'; - - for (i = 0; i <= len; i++) { - if (string[i] != metadata_data[i]) { - LOG_ERR("Wrong Firmware Metadata"); - return -EINVAL; - } - } - - return 0; -} - -static int dfu_start(struct bt_mesh_dfu_srv *srv, - const struct bt_mesh_dfu_img *img, - struct net_buf_simple *metadata, - const struct bt_mesh_blob_io **io) -{ - LOG_DBG("DFU setup"); - - *io = &dummy_blob_io; - - return 0; -} - -static void dfu_end(struct bt_mesh_dfu_srv *srv, - const struct bt_mesh_dfu_img *img, bool success) -{ - if (!success) { - LOG_ERR("DFU failed"); - return; - } - - if (!blob_valid) { - bt_mesh_dfu_srv_rejected(srv); - return; - } - - bt_mesh_dfu_srv_verified(srv); -} - -static int dfu_apply(struct bt_mesh_dfu_srv *srv, - const struct bt_mesh_dfu_img *img) -{ - if (!blob_valid) { - return -EINVAL; - } - - LOG_DBG("Applying DFU transfer..."); - - return 0; -} - -static const struct bt_mesh_dfu_srv_cb dfu_handlers = { - .check = dfu_meta_check, - .start = dfu_start, - .end = dfu_end, - .apply = dfu_apply, -}; - -static struct bt_mesh_dfu_srv dfu_srv = - BT_MESH_DFU_SRV_INIT(&dfu_handlers, dfu_imgs, ARRAY_SIZE(dfu_imgs)); -#endif /* CONFIG_BT_MESH_DFU_SRV */ +#define MODEL_BOUNDS_MAX 2 /* Model Authentication Method */ #define AUTH_METHOD_STATIC 0x01 @@ -607,16 +366,6 @@ static struct bt_mesh_rpr_cli rpr_cli = { }; #endif -#if defined(CONFIG_BT_MESH_DFU_SRV) -static uint8_t dfu_srv_apply(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - LOG_DBG("Applying image on server"); - bt_mesh_dfu_srv_applied(&dfu_srv); - return BTP_STATUS_SUCCESS; -} -#endif - static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), @@ -640,28 +389,8 @@ static struct bt_mesh_model root_models[] = { #if defined(CONFIG_BT_MESH_RPR_SRV) BT_MESH_MODEL_RPR_SRV, #endif -#if defined(CONFIG_BT_MESH_DFD_SRV) - BT_MESH_MODEL_DFD_SRV(&dfd_srv), -#endif -#if defined(CONFIG_BT_MESH_DFU_SRV) - BT_MESH_MODEL_DFU_SRV(&dfu_srv), -#endif -#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) - BT_MESH_MODEL_BLOB_CLI(&blob_cli), -#endif }; -struct model_data *lookup_model_bound(uint16_t id) -{ - int i; - for (i = 0; i < ARRAY_SIZE(model_bound); i++) { - if (model_bound[i].model && model_bound[i].model->id == id) { - return &model_bound[i]; - } - } - - return NULL; -} static struct bt_mesh_model vnd_models[] = { BT_MESH_MODEL_VND(CID_LOCAL, VND_MODEL_ID_1, BT_MESH_MODEL_NO_OPS, NULL, NULL), @@ -3360,643 +3089,6 @@ static uint8_t rpr_reprov_remote(const void *cmd, uint16_t cmd_len, } #endif -#if defined(CONFIG_BT_MESH_DFD_SRV) -static struct { - struct bt_mesh_dfu_target targets[32]; - struct bt_mesh_blob_target_pull pull[32]; - size_t target_cnt; - struct bt_mesh_blob_cli_inputs inputs; -} dfu_tx; - -static void dfu_tx_prepare(void) -{ - sys_slist_init(&dfu_tx.inputs.targets); - - for (int i = 0; i < dfu_tx.target_cnt; i++) { - /* Reset target context. */ - uint16_t addr = dfu_tx.targets[i].blob.addr; - - memset(&dfu_tx.targets[i].blob, 0, - sizeof(struct bt_mesh_blob_target)); - memset(&dfu_tx.pull[i], 0, - sizeof(struct bt_mesh_blob_target_pull)); - dfu_tx.targets[i].blob.addr = addr; - dfu_tx.targets[i].blob.pull = &dfu_tx.pull[i]; - - sys_slist_append(&dfu_tx.inputs.targets, - &dfu_tx.targets[i].blob.n); - } -} - -static void dfu_target(uint8_t img_idx, uint16_t addr) -{ - if (dfu_tx.target_cnt == ARRAY_SIZE(dfu_tx.targets)) { - LOG_ERR("No room."); - return; - } - - for (int i = 0; i < dfu_tx.target_cnt; i++) { - if (dfu_tx.targets[i].blob.addr == addr) { - LOG_ERR("Target 0x%04x already exists", addr); - return; - } - } - - dfu_tx.targets[dfu_tx.target_cnt].blob.addr = addr; - dfu_tx.targets[dfu_tx.target_cnt].img_idx = img_idx; - sys_slist_append(&dfu_tx.inputs.targets, - &dfu_tx.targets[dfu_tx.target_cnt].blob.n); - dfu_tx.target_cnt++; - - LOG_DBG("Added target 0x%04x", addr); -} -static void dfu_slot_add(size_t size, uint8_t *fwid, size_t fwid_len, - uint8_t *metadata, size_t metadata_len) -{ - struct bt_mesh_dfu_slot *slot; - int err; - - slot = bt_mesh_dfu_slot_reserve(); - err = bt_mesh_dfu_slot_info_set(slot, size, metadata, metadata_len); - if (err) { - LOG_ERR("Failed to set slot info: %d", err); - return; - } - - err = bt_mesh_dfu_slot_fwid_set(slot, fwid, fwid_len); - if (err) { - LOG_ERR("Failed to set slot fwid: %d", err); - return; - } - - bt_mesh_dfu_slot_commit(slot); - if (err) { - LOG_ERR("Failed to commit slot: %d", err); - return; - } - - LOG_DBG("Slot added."); -} -static enum bt_mesh_dfu_iter dfu_img_cb(struct bt_mesh_dfu_cli *cli, - struct bt_mesh_msg_ctx *ctx, - uint8_t idx, uint8_t total, - const struct bt_mesh_dfu_img *img, - void *cb_data) -{ - char fwid[2 * CONFIG_BT_MESH_DFU_FWID_MAXLEN + 1]; - size_t len; - - idx = 0xff; - - if (img->fwid_len <= sizeof(fwid)) { - len = bin2hex(img->fwid, img->fwid_len, fwid, sizeof(fwid)); - } else { - LOG_ERR("FWID is too big"); - return BT_MESH_DFU_ITER_STOP; - } - - fwid[len] = '\0'; - - LOG_DBG("Image %u:", idx); - LOG_DBG("\tFWID: "); - if (img->uri) { - LOG_DBG("\tURI: "); - } - - return BT_MESH_DFU_ITER_CONTINUE; -} - -static uint8_t dfu_info_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mmdl_dfu_info_get_cmd *cp = cmd; - struct model_data *model_bound; - struct bt_mesh_msg_ctx ctx = { - .net_idx = net.net_idx, - .send_ttl = BT_MESH_TTL_DEFAULT, - }; - uint8_t max_count; - int err = 0; - - LOG_DBG(""); - - model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); - if (!model_bound) { - LOG_ERR("Model not found"); - return BTP_STATUS_FAILED; - } - ctx.addr = model_bound->addr; - ctx.app_idx = model_bound->appkey_idx; - - max_count = cp->limit; - - err = bt_mesh_dfu_cli_imgs_get(&dfd_srv.dfu, &ctx, dfu_img_cb, NULL, - max_count); - if (err) { - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t dfu_update_metadata_check(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mmdl_dfu_metadata_check_cmd *cp = cmd; - struct btp_mmdl_dfu_metadata_check_rp *rp = rsp; - const struct bt_mesh_dfu_slot *slot; - struct model_data *model_bound; - struct bt_mesh_msg_ctx ctx = { - .net_idx = net.net_idx, - .send_ttl = BT_MESH_TTL_DEFAULT, - }; - struct bt_mesh_dfu_metadata_status rsp_data; - uint8_t img_idx, slot_idx; - size_t size; - size_t fwid_len; - size_t metadata_len; - uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; - uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN]; - int err; - - LOG_DBG(""); - - model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); - if (!model_bound) { - LOG_ERR("Model not found"); - return BTP_STATUS_FAILED; - } - - ctx.addr = model_bound->addr; - ctx.app_idx = model_bound->appkey_idx; - img_idx = cp->index; - slot_idx = cp->slot_idx; - size = cp->slot_size; - fwid_len = cp->fwid_len; - metadata_len = cp->metadata_len; - - if ((metadata_len > 0) && - (metadata_len < CONFIG_BT_MESH_DFU_METADATA_MAXLEN)) { - memcpy(&metadata, cp->data, metadata_len); - } - - dfu_slot_add(size, fwid, fwid_len, metadata, metadata_len); - - slot = bt_mesh_dfu_slot_at(slot_idx); - if (!slot) { - LOG_ERR("No image in slot %u", slot_idx); - return BTP_STATUS_FAILED; - } - - err = bt_mesh_dfu_cli_metadata_check(&dfd_srv.dfu, &ctx, img_idx, slot, - &rsp_data); - - if (err) { - LOG_ERR("ERR %d", err); - return BTP_STATUS_FAILED; - } - - rp->idx = rsp_data.idx; - rp->status = rsp_data.status; - rp->effect = rsp_data.effect; - - *rsp_len = sizeof(struct btp_mmdl_dfu_metadata_check_rp); - - return BTP_STATUS_SUCCESS; -} - -static uint8_t dfu_firmware_update_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - struct model_data *model_bound; - struct bt_mesh_msg_ctx ctx = { - .net_idx = net.net_idx, - .send_ttl = BT_MESH_TTL_DEFAULT, - }; - struct bt_mesh_dfu_target_status rsp_data; - struct btp_mmdl_dfu_firmware_update_rp *rp = rsp; - int err; - - LOG_DBG(""); - - model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); - if (!model_bound) { - LOG_ERR("Model not found"); - return BTP_STATUS_FAILED; - } - - ctx.addr = model_bound->addr; - ctx.app_idx = model_bound->appkey_idx; - - err = bt_mesh_dfu_cli_status_get(&dfd_srv.dfu, &ctx, &rsp_data); - if (err) { - LOG_ERR("err %d", err); - return BTP_STATUS_FAILED; - } - - rp->status = rsp_data.status; - *rsp_len = sizeof(struct btp_mmdl_dfu_firmware_update_rp); - return BTP_STATUS_SUCCESS; -} - -static uint8_t dfu_firmware_update_cancel(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - struct model_data *model_bound; - struct bt_mesh_msg_ctx ctx = { - .net_idx = net.net_idx, - .send_ttl = BT_MESH_TTL_DEFAULT, - }; - int err; - - LOG_DBG(""); - - model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); - if (!model_bound) { - LOG_ERR("Model not found"); - return BTP_STATUS_FAILED; - } - - ctx.addr = model_bound->addr; - ctx.app_idx = model_bound->appkey_idx; - - err = bt_mesh_dfu_cli_cancel(&dfd_srv.dfu, &ctx); - if (err) { - LOG_ERR("err %d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t dfu_firmware_update_start(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mmdl_dfu_firmware_update_cmd *cp = cmd; - struct model_data *model_bound; - struct bt_mesh_dfu_cli_xfer xfer; - uint8_t addr_cnt; - uint16_t addr = BT_MESH_ADDR_UNASSIGNED; - uint8_t slot_idx; - size_t size; - size_t fwid_len; - size_t metadata_len; - uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; - uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN]; - int err = 0; - int i = 0; - - LOG_DBG(""); - - model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); - if (!model_bound) { - LOG_ERR("Model not found"); - return BTP_STATUS_FAILED; - } - - struct bt_mesh_dfu_cli_xfer_blob_params blob = { - .block_size_log = cp->block_size, - .chunk_size = cp->chunk_size, - }; - - addr_cnt = cp->addr_cnt; - slot_idx = cp->slot_idx; - size = cp->slot_size; - fwid_len = cp->fwid_len; - metadata_len = cp->metadata_len; - xfer.mode = BT_MESH_BLOB_XFER_MODE_PUSH; - xfer.blob_params = &blob; - - if ((metadata_len > 0) && - (metadata_len < CONFIG_BT_MESH_DFU_METADATA_MAXLEN)) { - memcpy(&metadata, cp->data, metadata_len); - } - - bt_mesh_dfu_slot_del_all(); - - dfu_slot_add(size, fwid, fwid_len, metadata, metadata_len); - - xfer.slot = bt_mesh_dfu_slot_at(slot_idx); - if (!xfer.slot) { - LOG_ERR("No image in slot %u", slot_idx); - return BTP_STATUS_FAILED; - } - - for (i = 0; i < addr_cnt; i++) { - addr = cp->data[metadata_len + 1 + i * sizeof(uint16_t)] | - (cp->data[metadata_len + i * sizeof(uint16_t)] << 8); - dfu_target(slot_idx, addr); - } - - dfu_tx_prepare(); - - if (!dfu_tx.target_cnt) { - LOG_ERR("No targets."); - return BTP_STATUS_FAILED; - } - - if (addr_cnt > 1) { - dfu_tx.inputs.group = BT_MESH_ADDR_UNASSIGNED; - } else { - dfu_tx.inputs.group = addr; - } - - dfu_tx.inputs.app_idx = model_bound->appkey_idx; - dfu_tx.inputs.ttl = BT_MESH_TTL_DEFAULT; - - err = bt_mesh_dfu_cli_send(&dfd_srv.dfu, &dfu_tx.inputs, &dummy_blob_io, &xfer); - - if (err) { - LOG_ERR("err %d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t dfu_firmware_update_apply(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - struct model_data *model_bound; - int err; - - LOG_DBG(""); - - model_bound = lookup_model_bound(BT_MESH_MODEL_ID_DFU_CLI); - if (!model_bound) { - LOG_ERR("Model not found"); - return BTP_STATUS_FAILED; - } - - err = bt_mesh_dfu_cli_apply(&dfd_srv.dfu); - if (err) { - LOG_ERR("err %d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} -#endif - -#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) -static void blob_cli_inputs_prepare(uint16_t group, uint16_t app_idx) -{ - int i; - - blob_cli_xfer.inputs.ttl = BT_MESH_TTL_DEFAULT; - blob_cli_xfer.inputs.group = group; - blob_cli_xfer.inputs.app_idx = app_idx; - sys_slist_init(&blob_cli_xfer.inputs.targets); - - for (i = 0; i < blob_cli_xfer.target_count; ++i) { - /* Reset target context. */ - uint16_t addr = blob_cli_xfer.targets[i].addr; - - memset(&blob_cli_xfer.targets[i], 0, - sizeof(struct bt_mesh_blob_target)); - memset(&blob_cli_xfer.pull[i], 0, - sizeof(struct bt_mesh_blob_target_pull)); - blob_cli_xfer.targets[i].addr = addr; - blob_cli_xfer.targets[i].pull = &blob_cli_xfer.pull[i]; - - sys_slist_append(&blob_cli_xfer.inputs.targets, - &blob_cli_xfer.targets[i].n); - } -} - -static int cmd_blob_target(uint16_t addr) -{ - struct bt_mesh_blob_target *t; - - if (blob_cli_xfer.target_count == ARRAY_SIZE(blob_cli_xfer.targets)) { - LOG_ERR("No more room"); - return 0; - } - - t = &blob_cli_xfer.targets[blob_cli_xfer.target_count]; - - t->addr = addr; - - LOG_DBG("Added target 0x%04x", t->addr); - - blob_cli_xfer.target_count++; - return 0; -} - -static uint8_t blob_info_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mmdl_blob_info_get_cmd *cp = cmd; - struct model_data *model_bound; - uint16_t addr = BT_MESH_ADDR_UNASSIGNED; - uint16_t group = BT_MESH_ADDR_UNASSIGNED; - int err; - - LOG_DBG(""); - - model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_CLI); - if (!model_bound) { - LOG_ERR("Model not found"); - return BTP_STATUS_FAILED; - } - - for (int i = 0; i < cp->addr_cnt; i++) { - addr = cp->addr[1 + i * sizeof(uint16_t)] | - (cp->addr[i * sizeof(uint16_t)] << 8); - err = cmd_blob_target(addr); - if (err) { - LOG_ERR("err target %d", err); - return BTP_STATUS_FAILED; - } - } - - if (cp->addr_cnt > 1) { - group = BT_MESH_ADDR_UNASSIGNED; - } else { - group = addr; - } - - if (!blob_cli_xfer.target_count) { - LOG_ERR("Failed: No targets"); - return BTP_STATUS_FAILED; - } - - blob_cli_inputs_prepare(group, model_bound->appkey_idx); - - err = bt_mesh_blob_cli_caps_get(&blob_cli, &blob_cli_xfer.inputs); - - if (err) { - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t blob_transfer_start(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mmdl_blob_transfer_start_cmd *cp = cmd; - struct model_data *model_bound; - int err = 0; - - LOG_DBG(""); - - model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_CLI); - if (!model_bound) { - LOG_ERR("Model not found"); - return BTP_STATUS_FAILED; - } - - if (!blob_cli_xfer.target_count) { - LOG_ERR("Failed: No targets"); - return BTP_STATUS_FAILED; - } - blob_cli_xfer.xfer.id = cp->id; - blob_cli_xfer.xfer.size = cp->size; - blob_cli_xfer.xfer.block_size_log = cp->block_size; - blob_cli_xfer.xfer.chunk_size = cp->chunk_size; - - if (blob_cli.caps.modes) { - blob_cli_xfer.xfer.mode = blob_cli.caps.modes; - } else { - blob_cli_xfer.xfer.mode = BT_MESH_BLOB_XFER_MODE_PUSH; - } - - if (cp->timeout) { - blob_cli_xfer.inputs.timeout_base = cp->timeout; - } - - err = bt_mesh_blob_cli_send(&blob_cli, &blob_cli_xfer.inputs, - &blob_cli_xfer.xfer, &dummy_blob_io); - - if (err) { - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t blob_transfer_cancel(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - LOG_DBG(""); - - bt_mesh_blob_cli_cancel(&blob_cli); - - return BTP_STATUS_SUCCESS; -} - -static uint8_t blob_transfer_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - struct model_data *model_bound; - uint16_t group; - int err; - - LOG_DBG(""); - - model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_CLI); - if (!model_bound) { - LOG_ERR("Model not found"); - return BTP_STATUS_FAILED; - } - - group = model_bound->addr; - - err = cmd_blob_target(group); - if (err) { - LOG_ERR("err target %d", err); - return BTP_STATUS_FAILED; - } - - if (!blob_cli_xfer.target_count) { - LOG_ERR("Failed: No targets"); - return BTP_STATUS_FAILED; - } - - blob_cli_inputs_prepare(group, model_bound->appkey_idx); - - err = bt_mesh_blob_cli_xfer_progress_get(&blob_cli, &blob_cli_xfer.inputs); - - if (err) { - LOG_ERR("ERR %d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} -#endif /* CONFIG_BT_MESH_BLOB_CLI */ - -#if defined(CONFIG_BT_MESH_BLOB_SRV) -static uint8_t blob_srv_recv(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mmdl_blob_srv_recv_cmd *cp = cmd; - struct model_data *model_bound; - int err; - -#if defined(CONFIG_BT_MESH_DFU_SRV) - struct bt_mesh_blob_srv *srv = &dfu_srv.blob; -#elif defined(CONFIG_BT_MESH_DFD_SRV) - struct bt_mesh_blob_srv *srv = &dfd_srv.upload.blob; -#endif - - model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_SRV); - if (!model_bound) { - LOG_ERR("Model not found"); - return BTP_STATUS_FAILED; - } - - uint16_t timeout_base; - uint64_t id; - - LOG_DBG(""); - - id = cp->id; - timeout_base = cp->timeout; - - err = bt_mesh_blob_srv_recv(srv, id, &dummy_blob_io, BT_MESH_TTL_MAX, - timeout_base); - - if (err) { - LOG_ERR("ERR %d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t blob_srv_cancel(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - struct model_data *model_bound; - int err; - -#if defined(CONFIG_BT_MESH_DFU_SRV) - struct bt_mesh_blob_srv *srv = &dfu_srv.blob; -#elif defined(CONFIG_BT_MESH_DFD_SRV) - struct bt_mesh_blob_srv *srv = &dfd_srv.upload.blob; -#endif - - model_bound = lookup_model_bound(BT_MESH_MODEL_ID_BLOB_SRV); - if (!model_bound) { - LOG_ERR("Model not found"); - return BTP_STATUS_FAILED; - } - - LOG_DBG(""); - - err = bt_mesh_blob_srv_cancel(srv); - - if (err) { - LOG_ERR("ERR %d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} -#endif - static const struct btp_handler handlers[] = { { .opcode = BTP_MESH_READ_SUPPORTED_COMMANDS, @@ -4485,83 +3577,6 @@ static const struct btp_handler handlers[] = { }, }; - -static const struct btp_handler mdl_handlers[] = { -#if defined(CONFIG_BT_MESH_DFD_SRV) - { - .opcode = BTP_MMDL_DFU_INFO_GET, - .expect_len = sizeof(struct btp_mmdl_dfu_info_get_cmd), - .func = dfu_info_get, - }, - { - .opcode = BTP_MMDL_DFU_UPDATE_METADATA_CHECK, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = dfu_update_metadata_check, - }, - { - .opcode = BTP_MMDL_DFU_FIRMWARE_UPDATE_GET, - .expect_len = 0, - .func = dfu_firmware_update_get, - }, - { - .opcode = BTP_MMDL_DFU_FIRMWARE_UPDATE_CANCEL, - .expect_len = 0, - .func = dfu_firmware_update_cancel, - }, - { - .opcode = BTP_MMDL_DFU_FIRMWARE_UPDATE_START, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = dfu_firmware_update_start, - }, - { - .opcode = BTP_MMDL_DFU_FIRMWARE_UPDATE_APPLY, - .expect_len = 0, - .func = dfu_firmware_update_apply, - }, -#endif -#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV) - { - .opcode = BTP_MMDL_BLOB_INFO_GET, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = blob_info_get, - }, - { - .opcode = BTP_MMDL_BLOB_TRANSFER_START, - .expect_len = sizeof(struct btp_mmdl_blob_transfer_start_cmd), - .func = blob_transfer_start, - }, - { - .opcode = BTP_MMDL_BLOB_TRANSFER_CANCEL, - .expect_len = 0, - .func = blob_transfer_cancel, - }, - { - .opcode = BTP_MMDL_BLOB_TRANSFER_GET, - .expect_len = 0, - .func = blob_transfer_get, - }, -#endif -#if defined(CONFIG_BT_MESH_BLOB_SRV) - { - .opcode = BTP_MMDL_BLOB_SRV_RECV, - .expect_len = sizeof(struct btp_mmdl_blob_srv_recv_cmd), - .func = blob_srv_recv - }, - { - .opcode = BTP_MMDL_BLOB_SRV_CANCEL, - .expect_len = 0, - .func = blob_srv_cancel - }, -#endif -#if defined(CONFIG_BT_MESH_DFU_SRV) - { - .opcode = BTP_MMDL_DFU_SRV_APPLY, - .expect_len = 0, - .func = dfu_srv_apply - }, -#endif -}; - void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload, size_t payload_len) { @@ -4770,15 +3785,3 @@ uint8_t tester_unregister_mesh(void) { return BTP_STATUS_SUCCESS; } - -uint8_t tester_init_mmdl(void) -{ - tester_register_command_handlers(BTP_SERVICE_ID_MESH_MDL, mdl_handlers, - ARRAY_SIZE(mdl_handlers)); - return BTP_STATUS_SUCCESS; -} - -uint8_t tester_unregister_mmdl(void) -{ - return BTP_STATUS_SUCCESS; -} From f5b4ffa8b067ccc60e2cd19700dd5fc120b00e1c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:25 +0000 Subject: [PATCH 0788/1623] Revert "[nrf fromtree] Tests: Bluetooth: tester: enable Remote Provisioning" This reverts commit 2560e34ef5baf2d9a4c0ddadc36e4037a39d5569. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/overlay-mesh.conf | 4 - tests/bluetooth/tester/src/btp/btp_mesh.h | 61 --- tests/bluetooth/tester/src/btp_mesh.c | 434 +--------------------- 3 files changed, 4 insertions(+), 495 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index b537ae0001e..43e666d0eb3 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -28,9 +28,5 @@ CONFIG_BT_MESH_CDB_NODE_COUNT=3 CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y CONFIG_BT_MESH_MSG_CACHE_SIZE=10 CONFIG_BT_MESH_PROXY_CLIENT=y -CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_RPR_SRV=y -CONFIG_BT_MESH_RPR_CLI=y -CONFIG_BT_MESH_RPR_AD_TYPES_MAX=2 CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 29523d02d8c..67ce612c2ac 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -835,66 +835,6 @@ struct btp_mesh_models_metadata_get_rp { uint8_t data[0]; } __packed; -#define BTP_MESH_COMP_CHANGE_PREPARE 0x57 - -#define BTP_MESH_SET_COMP_ALT 0x58 - -#define BTP_MESH_RPR_SCAN_START 0x59 -struct btp_rpr_scan_start_cmd { - uint16_t dst; - uint8_t timeout; - uint8_t uuid[16]; -} __packed; - -#define BTP_MESH_RPR_EXT_SCAN_START 0x5a -struct btp_rpr_ext_scan_start_cmd { - uint16_t dst; - uint8_t timeout; - uint8_t uuid[16]; - uint8_t ad_count; - uint8_t ad_types[]; -} __packed; - -#define BTP_MESH_RPR_SCAN_CAPS_GET 0x5b -struct btp_rpr_scan_caps_get_cmd { - uint16_t dst; -} __packed; - -#define BTP_MESH_RPR_SCAN_GET 0x5c -struct btp_rpr_scan_get_cmd { - uint16_t dst; -} __packed; - -#define BTP_MESH_RPR_SCAN_STOP 0x5d -struct btp_rpr_scan_stop_cmd { - uint16_t dst; -} __packed; - -#define BTP_MESH_RPR_LINK_GET 0x5e -struct btp_rpr_link_get_cmd { - uint16_t dst; -} __packed; - -#define BTP_MESH_RPR_LINK_CLOSE 0x5f -struct btp_rpr_link_close_cmd { - uint16_t dst; -} __packed; - -#define BTP_MESH_RPR_PROV_REMOTE 0x60 -struct btp_rpr_prov_remote_cmd { - uint16_t dst; - uint8_t uuid[16]; - uint16_t net_idx; - uint16_t addr; -} __packed; - -#define BTP_MESH_RPR_REPROV_REMOTE 0x61 -struct btp_rpr_reprov_remote_cmd { - uint16_t dst; - uint16_t addr; - bool comp_change; -} __packed; - /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { @@ -918,7 +858,6 @@ struct btp_mesh_in_action_ev { #define BTP_MESH_PROV_BEARER_PB_ADV 0x00 #define BTP_MESH_PROV_BEARER_PB_GATT 0x01 -#define BTP_MESH_PROV_BEARER_REMOTE 0x04 #define BTP_MESH_EV_PROV_LINK_OPEN 0x84 struct btp_mesh_prov_link_open_ev { uint8_t bearer; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 40ae3a6f038..232e3d7d8b4 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -76,7 +76,6 @@ static struct { .dst = BT_MESH_ADDR_UNASSIGNED, }; -static bool default_comp = true; static uint8_t supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -323,49 +322,6 @@ static struct bt_mesh_cfg_cli cfg_cli = { static struct bt_mesh_sar_cfg_cli sar_cfg_cli; #endif -#if defined(CONFIG_BT_MESH_RPR_CLI) -static void rpr_scan_report(struct bt_mesh_rpr_cli *cli, - const struct bt_mesh_rpr_node *srv, - struct bt_mesh_rpr_unprov *unprov, - struct net_buf_simple *adv_data) -{ - char uuid_hex_str[32 + 1]; - - bin2hex(unprov->uuid, 16, uuid_hex_str, sizeof(uuid_hex_str)); - - LOG_DBG("Server 0x%04x:\n" - "\tuuid: %s\n" - "\tOOB: 0x%04x", - srv->addr, uuid_hex_str, unprov->oob); - - while (adv_data && adv_data->len > 2) { - uint8_t len, type; - uint8_t data[31]; - - len = net_buf_simple_pull_u8(adv_data) - 1; - type = net_buf_simple_pull_u8(adv_data); - memcpy(data, net_buf_simple_pull_mem(adv_data, len), len); - data[len] = '\0'; - - if (type == BT_DATA_URI) { - LOG_DBG("\tURI: \"\\x%02x%s\"", - data[0], &data[1]); - } else if (type == BT_DATA_NAME_COMPLETE) { - LOG_DBG("\tName: \"%s\"", data); - } else { - char string[64 + 1]; - - bin2hex(data, len, string, sizeof(string)); - LOG_DBG("\t0x%02x: %s", type, string); - } - } -} - -static struct bt_mesh_rpr_cli rpr_cli = { - .scan_report = rpr_scan_report, -}; -#endif - static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), @@ -383,12 +339,6 @@ static struct bt_mesh_model root_models[] = { #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&lcd_cli), #endif -#if defined(CONFIG_BT_MESH_RPR_CLI) - BT_MESH_MODEL_RPR_CLI(&rpr_cli), -#endif -#if defined(CONFIG_BT_MESH_RPR_SRV) - BT_MESH_MODEL_RPR_SRV, -#endif }; static struct bt_mesh_model vnd_models[] = { @@ -413,9 +363,6 @@ static void link_open(bt_mesh_prov_bearer_t bearer) case BT_MESH_PROV_GATT: ev.bearer = BTP_MESH_PROV_BEARER_PB_GATT; break; - case BT_MESH_PROV_REMOTE: - ev.bearer = BTP_MESH_PROV_BEARER_REMOTE; - break; default: LOG_ERR("Invalid bearer"); @@ -438,9 +385,6 @@ static void link_close(bt_mesh_prov_bearer_t bearer) case BT_MESH_PROV_GATT: ev.bearer = BTP_MESH_PROV_BEARER_PB_GATT; break; - case BT_MESH_PROV_REMOTE: - ev.bearer = BTP_MESH_PROV_BEARER_REMOTE; - break; default: LOG_ERR("Invalid bearer"); @@ -532,24 +476,12 @@ static void prov_reset(void) LOG_DBG(""); bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT); - - if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV)) { - bt_mesh_prov_enable(BT_MESH_PROV_REMOTE); - } } static const struct bt_mesh_comp comp = { .cid = CID_LOCAL, .elem = elements, .elem_count = ARRAY_SIZE(elements), - .vid = 1, -}; - -static const struct bt_mesh_comp comp_alt = { - .cid = CID_LOCAL, - .elem = elements, - .elem_count = ARRAY_SIZE(elements), - .vid = 2, }; static struct bt_mesh_prov prov = { @@ -564,7 +496,6 @@ static struct bt_mesh_prov prov = { .complete = prov_complete, .node_added = prov_node_added, .reset = prov_reset, - .uri = "Tester", }; static uint8_t config_prov(const void *cmd, uint16_t cmd_len, @@ -686,26 +617,19 @@ static uint8_t init(const void *cmd, uint16_t cmd_len, LOG_DBG(""); - if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - printk("Loading stored settings\n"); - settings_load(); + err = bt_mesh_init(&prov, &comp); + if (err) { + return BTP_STATUS_FAILED; } if (addr) { err = bt_mesh_provision(net_key, net_key_idx, flags, iv_index, addr, dev_key); - if (err && err != -EALREADY) { + if (err) { return BTP_STATUS_FAILED; } } else { err = bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT); - if (err && err != -EALREADY) { - return BTP_STATUS_FAILED; - } - } - - if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV)) { - err = bt_mesh_prov_enable(BT_MESH_PROV_REMOTE); if (err) { return BTP_STATUS_FAILED; } @@ -1281,62 +1205,6 @@ static uint8_t composition_data_get(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t change_prepare(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - int err; - - LOG_DBG(""); - - err = bt_mesh_comp_change_prepare(); - if (err < 0) { - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -#if IS_ENABLED(CONFIG_BT_SETTINGS) -static int comp_alt_set(const char *name, size_t len_rd, - settings_read_cb read_cb, void *store) -{ - ssize_t len; - bool alt_comp_value; - - if (len_rd == 0) { - LOG_DBG("Default composition"); - } - - len = read_cb(store, &alt_comp_value, sizeof(alt_comp_value)); - if (len < 0 || len != len_rd) { - LOG_ERR("Failed to read value (err %zd)", len); - return len; - } - - if (alt_comp_value) { - default_comp = false; - } - - return 0; -} - -SETTINGS_STATIC_HANDLER_DEFINE(tester_comp_alt, "tester/comp_alt", NULL, comp_alt_set, NULL, NULL); -#endif - -static uint8_t set_comp_alt(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ -#if !IS_ENABLED(CONFIG_BT_SETTINGS) - return BTP_STATUS_FAILED; -#else - bool comp_alt_val = true; - - settings_save_one("tester/comp_alt", &comp_alt_val, sizeof(comp_alt_val)); - - return BTP_STATUS_SUCCESS; -#endif -} - static uint8_t config_krp_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -2862,233 +2730,6 @@ static uint8_t health_attention_set(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -#if defined(CONFIG_BT_MESH_RPR_CLI) -static uint8_t rpr_scan_start(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_rpr_scan_start_cmd *cp = cmd; - - struct bt_mesh_rpr_scan_status status; - const struct bt_mesh_rpr_node srv = { - .addr = cp->dst, - .net_idx = net.net_idx, - .ttl = BT_MESH_TTL_DEFAULT, - }; - uint8_t uuid[16] = {0}; - int err; - - err = bt_mesh_rpr_scan_start(&rpr_cli, &srv, - memcmp(uuid, cp->uuid, 16) ? cp->uuid : NULL, - cp->timeout, - BT_MESH_RPR_SCAN_MAX_DEVS_ANY, &status); - - if (err) { - LOG_ERR("Scan start failed: %d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t rpr_ext_scan_start(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_rpr_ext_scan_start_cmd *cp = cmd; - const struct bt_mesh_rpr_node srv = { - .addr = cp->dst, - .net_idx = net.net_idx, - .ttl = BT_MESH_TTL_DEFAULT, - }; - int err; - - err = bt_mesh_rpr_scan_start_ext(&rpr_cli, &srv, cp->uuid, - cp->timeout, cp->ad_types, - cp->ad_count); - if (err) { - LOG_ERR("Scan start failed: %d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t rpr_scan_caps_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_rpr_scan_caps_get_cmd *cp = cmd; - struct bt_mesh_rpr_caps caps; - const struct bt_mesh_rpr_node srv = { - .addr = cp->dst, - .net_idx = net.net_idx, - .ttl = BT_MESH_TTL_DEFAULT, - }; - int err; - - err = bt_mesh_rpr_scan_caps_get(&rpr_cli, &srv, &caps); - if (err) { - LOG_ERR("Scan capabilities get failed: %d", err); - return BTP_STATUS_FAILED; - } - - LOG_DBG("Remote Provisioning scan capabilities of 0x%04x:", - net.dst); - LOG_DBG("\tMax devices: %u", caps.max_devs); - LOG_DBG("\tActive scanning: %s", - caps.active_scan ? "true" : "false"); - - return BTP_STATUS_SUCCESS; -} - -static uint8_t rpr_scan_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_rpr_scan_get_cmd *cp = cmd; - struct bt_mesh_rpr_scan_status status; - const struct bt_mesh_rpr_node srv = { - .addr = cp->dst, - .net_idx = net.net_idx, - .ttl = BT_MESH_TTL_DEFAULT, - }; - int err; - - err = bt_mesh_rpr_scan_get(&rpr_cli, &srv, &status); - if (err) { - LOG_ERR("Scan get failed: %d", err); - return BTP_STATUS_FAILED; - } - - LOG_DBG("Remote Provisioning scan on 0x%04x:", cp->dst); - LOG_DBG("\tStatus: %u", status.status); - LOG_DBG("\tScan type: %u", status.scan); - LOG_DBG("\tMax devices: %u", status.max_devs); - LOG_DBG("\tRemaining time: %u", status.timeout); - - return BTP_STATUS_SUCCESS; -} - -static uint8_t rpr_scan_stop(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_rpr_scan_stop_cmd *cp = cmd; - struct bt_mesh_rpr_scan_status status; - const struct bt_mesh_rpr_node srv = { - .addr = cp->dst, - .net_idx = net.net_idx, - .ttl = BT_MESH_TTL_DEFAULT, - }; - int err; - - err = bt_mesh_rpr_scan_stop(&rpr_cli, &srv, &status); - if (err || status.status) { - LOG_DBG("Scan stop failed: %d %u", err, status.status); - return BTP_STATUS_FAILED; - } - - LOG_DBG("Remote Provisioning scan on 0x%04x stopped.", - net.dst); - - return BTP_STATUS_SUCCESS; -} - -static uint8_t rpr_link_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_rpr_link_get_cmd *cp = cmd; - struct bt_mesh_rpr_link link; - const struct bt_mesh_rpr_node srv = { - .addr = cp->dst, - .net_idx = net.net_idx, - .ttl = BT_MESH_TTL_DEFAULT, - }; - int err; - - err = bt_mesh_rpr_link_get(&rpr_cli, &srv, &link); - if (err) { - LOG_ERR("Link get failed: %d %u", err, link.status); - return BTP_STATUS_FAILED; - } - - LOG_DBG("Remote Provisioning Link on 0x%04x:", cp->dst); - LOG_DBG("\tStatus: %u", link.status); - LOG_DBG("\tState: %u", link.state); - - return BTP_STATUS_SUCCESS; -} - -static uint8_t rpr_link_close(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_rpr_link_close_cmd *cp = cmd; - struct bt_mesh_rpr_link link; - const struct bt_mesh_rpr_node srv = { - .addr = cp->dst, - .net_idx = net.net_idx, - .ttl = BT_MESH_TTL_DEFAULT, - }; - int err; - - err = bt_mesh_rpr_link_close(&rpr_cli, &srv, &link); - if (err) { - LOG_ERR("Link close failed: %d %u", err, link.status); - return BTP_STATUS_FAILED; - } - - LOG_DBG("Remote Provisioning Link on 0x%04x:", cp->dst); - LOG_DBG("\tStatus: %u", link.status); - LOG_DBG("\tState: %u", link.state); - - return BTP_STATUS_SUCCESS; -} - -static uint8_t rpr_prov_remote(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_rpr_prov_remote_cmd *cp = cmd; - struct bt_mesh_rpr_node srv = { - .addr = cp->dst, - .net_idx = net.net_idx, - .ttl = BT_MESH_TTL_DEFAULT, - }; - int err; - - err = bt_mesh_provision_remote(&rpr_cli, &srv, cp->uuid, - cp->net_idx, cp->addr); - if (err) { - LOG_ERR("Prov remote start failed: %d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t rpr_reprov_remote(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_rpr_reprov_remote_cmd *cp = cmd; - struct bt_mesh_rpr_node srv = { - .addr = cp->dst, - .net_idx = net.net_idx, - .ttl = BT_MESH_TTL_DEFAULT, - }; - int err; - - if (!BT_MESH_ADDR_IS_UNICAST(cp->addr)) { - LOG_ERR("Must be a valid unicast address"); - err = -EINVAL; - return BTP_STATUS_FAILED; - } - - err = bt_mesh_reprovision_remote(&rpr_cli, &srv, cp->addr, - cp->comp_change); - if (err) { - LOG_ERR("Reprovisioning failed: %d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} -#endif - static const struct btp_handler handlers[] = { { .opcode = BTP_MESH_READ_SUPPORTED_COMMANDS, @@ -3519,62 +3160,6 @@ static const struct btp_handler handlers[] = { .func = models_metadata_get }, #endif - { - .opcode = BTP_MESH_COMP_CHANGE_PREPARE, - .expect_len = 0, - .func = change_prepare - }, - { - .opcode = BTP_MESH_SET_COMP_ALT, - .expect_len = 0, - .func = set_comp_alt - }, -#if defined(CONFIG_BT_MESH_RPR_CLI) - { - .opcode = BTP_MESH_RPR_SCAN_START, - .expect_len = sizeof(struct btp_rpr_scan_start_cmd), - .func = rpr_scan_start - }, - { - .opcode = BTP_MESH_RPR_EXT_SCAN_START, - .expect_len = BTP_HANDLER_LENGTH_VARIABLE, - .func = rpr_ext_scan_start - }, - { - .opcode = BTP_MESH_RPR_SCAN_CAPS_GET, - .expect_len = sizeof(struct btp_rpr_scan_caps_get_cmd), - .func = rpr_scan_caps_get - }, - { - .opcode = BTP_MESH_RPR_SCAN_GET, - .expect_len = sizeof(struct btp_rpr_scan_get_cmd), - .func = rpr_scan_get - }, - { - .opcode = BTP_MESH_RPR_SCAN_STOP, - .expect_len = sizeof(struct btp_rpr_scan_stop_cmd), - .func = rpr_scan_stop - }, - { - .opcode = BTP_MESH_RPR_LINK_GET, - .expect_len = sizeof(struct btp_rpr_link_get_cmd), - .func = rpr_link_get - }, - { - .opcode = BTP_MESH_RPR_LINK_CLOSE, - .expect_len = sizeof(struct btp_rpr_link_close_cmd), - .func = rpr_link_close - }, - { - .opcode = BTP_MESH_RPR_PROV_REMOTE, - .expect_len = sizeof(struct btp_rpr_prov_remote_cmd), - .func = rpr_prov_remote - }, - { - .opcode = BTP_MESH_RPR_REPROV_REMOTE, - .expect_len = sizeof(struct btp_rpr_reprov_remote_cmd), - .func = rpr_reprov_remote - }, }; void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload, @@ -3760,23 +3345,12 @@ BT_MESH_LPN_CB_DEFINE(lpn_cb) = { uint8_t tester_init_mesh(void) { - int err; - if (IS_ENABLED(CONFIG_BT_TESTING)) { bt_test_cb_register(&bt_test_cb); } tester_register_command_handlers(BTP_SERVICE_ID_MESH, handlers, ARRAY_SIZE(handlers)); - if (default_comp) { - err = bt_mesh_init(&prov, &comp); - } else { - err = bt_mesh_init(&prov, &comp_alt); - } - - if (err) { - return BTP_STATUS_FAILED; - } return BTP_STATUS_SUCCESS; } From 3d8ca45c22281e165b988cffff2078eab5dbce85 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:25 +0000 Subject: [PATCH 0789/1623] Revert "[nrf fromtree] Bluetooth: tester: Add Transport SAR Configuration models" This reverts commit 9c7ac78741416f601ad8f453f76f5edab0b4d110. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/overlay-mesh.conf | 2 - tests/bluetooth/tester/src/btp/btp_mesh.h | 40 ------- tests/bluetooth/tester/src/btp_mesh.c | 133 +--------------------- 3 files changed, 1 insertion(+), 174 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 43e666d0eb3..937f4d1270e 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -15,8 +15,6 @@ CONFIG_BT_MESH_CFG_CLI=y CONFIG_BT_MESH_HEALTH_CLI=y CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y -CONFIG_BT_MESH_SAR_CFG_SRV=y -CONFIG_BT_MESH_SAR_CFG_CLI=y CONFIG_BT_MESH_FRIEND=y CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=32 CONFIG_BT_MESH_RX_SEG_MAX=13 diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 67ce612c2ac..63984f0b61f 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -773,46 +773,6 @@ struct btp_proxy_connect_cmd { uint16_t net_idx; } __packed; -struct sar_transmitter { - uint8_t seg_int_step; - uint8_t unicast_retrans_count; - uint8_t unicast_retrans_without_prog_count; - uint8_t unicast_retrans_int_step; - uint8_t unicast_retrans_int_inc; - uint8_t multicast_retrans_count; - uint8_t multicast_retrans_int; -} __packed; - -struct sar_receiver { - uint8_t seg_thresh; - uint8_t ack_delay_inc; - uint8_t ack_retrans_count; - uint8_t discard_timeout; - uint8_t rx_seg_int_step; -} __packed; - -#define BTP_MESH_SAR_TRANSMITTER_GET 0x4f -struct btp_mesh_sar_transmitter_get_cmd { - uint16_t dst; -} __packed; - -#define BTP_MESH_SAR_TRANSMITTER_SET 0x50 -struct btp_mesh_sar_transmitter_set_cmd { - uint16_t dst; - struct sar_transmitter tx; -} __packed; - -#define BTP_MESH_SAR_RECEIVER_GET 0x51 -struct btp_mesh_sar_receiver_get_cmd { - uint16_t dst; -} __packed; - -#define BTP_MESH_SAR_RECEIVER_SET 0x52 -struct btp_mesh_sar_receiver_set_cmd { - uint16_t dst; - struct sar_receiver rx; -} __packed; - #define BTP_MESH_LARGE_COMP_DATA_GET 0x53 struct btp_mesh_large_comp_data_get_cmd { uint16_t net_idx; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 232e3d7d8b4..a6ccd319b2d 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #define LOG_MODULE_NAME bttester_mesh @@ -318,21 +317,11 @@ BT_MESH_HEALTH_PUB_DEFINE(health_pub, CUR_FAULTS_MAX); static struct bt_mesh_cfg_cli cfg_cli = { }; -#if defined(CONFIG_BT_MESH_SAR_CFG_CLI) -static struct bt_mesh_sar_cfg_cli sar_cfg_cli; -#endif - static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub), BT_MESH_MODEL_HEALTH_CLI(&health_cli), -#if defined(CONFIG_BT_MESH_SAR_CFG_SRV) - BT_MESH_MODEL_SAR_CFG_SRV, -#endif -#if defined(CONFIG_BT_MESH_SAR_CFG_CLI) - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), -#endif #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV) BT_MESH_MODEL_LARGE_COMP_DATA_SRV, #endif @@ -1027,105 +1016,6 @@ static uint8_t proxy_connect(const void *cmd, uint16_t cmd_len, } #endif -#if defined(CONFIG_BT_MESH_SAR_CFG_CLI) -static uint8_t sar_transmitter_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mesh_sar_transmitter_get_cmd *cp = cmd; - struct bt_mesh_sar_tx tx_rsp; - int err; - - LOG_DBG(""); - - bt_mesh_sar_cfg_cli_timeout_set(5000); - - err = bt_mesh_sar_cfg_cli_transmitter_get( - net_key_idx, sys_le16_to_cpu(cp->dst), &tx_rsp); - if (err) { - LOG_ERR("err=%d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t sar_transmitter_set(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mesh_sar_transmitter_set_cmd *cp = cmd; - struct bt_mesh_sar_tx set, tx_rsp; - int err; - - LOG_DBG(""); - - bt_mesh_sar_cfg_cli_timeout_set(5000); - - set.seg_int_step = cp->tx.seg_int_step; - set.unicast_retrans_count = cp->tx.unicast_retrans_count; - set.unicast_retrans_int_inc = cp->tx.unicast_retrans_int_inc; - set.unicast_retrans_int_step = cp->tx.unicast_retrans_int_step; - set.unicast_retrans_without_prog_count = - cp->tx.unicast_retrans_without_prog_count; - set.multicast_retrans_count = cp->tx.multicast_retrans_count; - set.multicast_retrans_int = cp->tx.multicast_retrans_int; - - err = bt_mesh_sar_cfg_cli_transmitter_set(net_key_idx, - sys_le16_to_cpu(cp->dst), - &set, &tx_rsp); - if (err) { - LOG_ERR("err=%d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t sar_receiver_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mesh_sar_receiver_get_cmd *cp = cmd; - struct bt_mesh_sar_rx rx_rsp; - int err; - - LOG_DBG(""); - - err = bt_mesh_sar_cfg_cli_receiver_get(net_key_idx, - sys_le16_to_cpu(cp->dst), &rx_rsp); - if (err) { - LOG_ERR("err=%d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} - -static uint8_t sar_receiver_set(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mesh_sar_receiver_set_cmd *cp = cmd; - struct bt_mesh_sar_rx set, rx_rsp; - int err; - - LOG_DBG(""); - - set.ack_delay_inc = cp->rx.ack_delay_inc; - set.ack_retrans_count = cp->rx.ack_retrans_count; - set.discard_timeout = cp->rx.discard_timeout; - set.seg_thresh = cp->rx.seg_thresh; - set.rx_seg_int_step = cp->rx.rx_seg_int_step; - - err = bt_mesh_sar_cfg_cli_receiver_set(net_key_idx, - sys_le16_to_cpu(cp->dst), &set, - &rx_rsp); - if (err) { - LOG_ERR("err=%d", err); - return BTP_STATUS_FAILED; - } - - return BTP_STATUS_SUCCESS; -} -#endif - #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) static uint8_t large_comp_data_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -3126,28 +3016,6 @@ static const struct btp_handler handlers[] = { .func = proxy_connect }, #endif -#if defined(CONFIG_BT_MESH_SAR_CFG_CLI) - { - .opcode = BTP_MESH_SAR_TRANSMITTER_GET, - .expect_len = sizeof(struct btp_mesh_sar_transmitter_get_cmd), - .func = sar_transmitter_get - }, - { - .opcode = BTP_MESH_SAR_TRANSMITTER_SET, - .expect_len = sizeof(struct btp_mesh_sar_transmitter_set_cmd), - .func = sar_transmitter_set - }, - { - .opcode = BTP_MESH_SAR_RECEIVER_GET, - .expect_len = sizeof(struct btp_mesh_sar_receiver_get_cmd), - .func = sar_receiver_get - }, - { - .opcode = BTP_MESH_SAR_RECEIVER_SET, - .expect_len = sizeof(struct btp_mesh_sar_receiver_set_cmd), - .func = sar_receiver_set - }, -#endif #if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) { .opcode = BTP_MESH_LARGE_COMP_DATA_GET, @@ -3162,6 +3030,7 @@ static const struct btp_handler handlers[] = { #endif }; + void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload, size_t payload_len) { From b615cedf5f50356dcd9f49fff4518c6ae427ba5a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:25 +0000 Subject: [PATCH 0790/1623] Revert "[nrf fromtree] tester: Add Large Comp Data models" This reverts commit 4b5500c758e19a5338dc0bc778975ed94024f0d2. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/overlay-mesh.conf | 5 - tests/bluetooth/tester/src/btp/btp_mesh.h | 22 ----- tests/bluetooth/tester/src/btp_mesh.c | 111 ++-------------------- 3 files changed, 9 insertions(+), 129 deletions(-) diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 937f4d1270e..840af06c1c0 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -1,5 +1,4 @@ CONFIG_BT_MESH=y -CONFIG_BT_MESH_V1d1=y CONFIG_BT_MESH_RELAY=y CONFIG_BT_MESH_PB_ADV=y CONFIG_BT_MESH_PB_GATT=y @@ -13,8 +12,6 @@ CONFIG_BT_MESH_APP_KEY_COUNT=4 CONFIG_BT_MESH_IV_UPDATE_TEST=y CONFIG_BT_MESH_CFG_CLI=y CONFIG_BT_MESH_HEALTH_CLI=y -CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y -CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y CONFIG_BT_MESH_FRIEND=y CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=32 CONFIG_BT_MESH_RX_SEG_MAX=13 @@ -26,5 +23,3 @@ CONFIG_BT_MESH_CDB_NODE_COUNT=3 CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y CONFIG_BT_MESH_MSG_CACHE_SIZE=10 CONFIG_BT_MESH_PROXY_CLIENT=y - -CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 63984f0b61f..bd7af172744 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -773,28 +773,6 @@ struct btp_proxy_connect_cmd { uint16_t net_idx; } __packed; -#define BTP_MESH_LARGE_COMP_DATA_GET 0x53 -struct btp_mesh_large_comp_data_get_cmd { - uint16_t net_idx; - uint16_t addr; - uint8_t page; - uint16_t offset; -} __packed; -struct btp_mesh_large_comp_data_get_rp { - uint8_t data[0]; -} __packed; - -#define BTP_MESH_MODELS_METADATA_GET 0x54 -struct btp_mesh_models_metadata_get_cmd { - uint16_t net_idx; - uint16_t addr; - uint8_t page; - uint16_t offset; -} __packed; -struct btp_mesh_models_metadata_get_rp { - uint8_t data[0]; -} __packed; - /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 struct btp_mesh_out_number_action_ev { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index a6ccd319b2d..b6ac4d91e1c 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -22,8 +22,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_BTTESTER_LOG_LEVEL); #include "btp/btp.h" #define CID_LOCAL 0x05F1 -#define COMPANY_ID_LF 0x05F1 -#define COMPANY_ID_NORDIC_SEMI 0x05F9 /* Health server data */ #define CUR_FAULTS_MAX 4 @@ -256,6 +254,15 @@ static const struct bt_mesh_health_srv_cb health_srv_cb = { .fault_test = fault_test, }; +static struct bt_mesh_health_srv health_srv = { + .cb = &health_srv_cb, +}; + +BT_MESH_HEALTH_PUB_DEFINE(health_pub, CUR_FAULTS_MAX); + +static struct bt_mesh_cfg_cli cfg_cli = { +}; + static void show_faults(uint8_t test_id, uint16_t cid, uint8_t *faults, size_t fault_count) { size_t i; @@ -282,52 +289,15 @@ static void health_current_status(struct bt_mesh_health_cli *cli, uint16_t addr, show_faults(test_id, cid, faults, fault_count); } -#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) -static struct bt_mesh_large_comp_data_cli lcd_cli = { -}; -#endif - static struct bt_mesh_health_cli health_cli = { .current_status = health_current_status, }; - -#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV -static uint8_t health_tests[] = { - BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_LF, 6, 0x01, 0x02, 0x03, 0x04, 0x34, - 0x15), - BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_NORDIC_SEMI, 3, 0x01, 0x02, 0x03), -}; - -static struct bt_mesh_models_metadata_entry health_srv_meta[] = { - BT_MESH_HEALTH_TEST_INFO_METADATA(health_tests), - BT_MESH_MODELS_METADATA_END, -}; -#endif - -static struct bt_mesh_health_srv health_srv = { - .cb = &health_srv_cb, -#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV - .metadata = health_srv_meta, -#endif -}; - -BT_MESH_HEALTH_PUB_DEFINE(health_pub, CUR_FAULTS_MAX); - -static struct bt_mesh_cfg_cli cfg_cli = { -}; - static struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub), BT_MESH_MODEL_HEALTH_CLI(&health_cli), -#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV) - BT_MESH_MODEL_LARGE_COMP_DATA_SRV, -#endif -#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) - BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&lcd_cli), -#endif }; static struct bt_mesh_model vnd_models[] = { @@ -1016,56 +986,6 @@ static uint8_t proxy_connect(const void *cmd, uint16_t cmd_len, } #endif -#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) -static uint8_t large_comp_data_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mesh_large_comp_data_get_cmd *cp = cmd; - struct btp_mesh_large_comp_data_get_rp *rp = rsp; - int err; - - struct bt_mesh_large_comp_data_rsp comp; - - err = bt_mesh_large_comp_data_get(sys_le16_to_cpu(cp->net_idx), - sys_le16_to_cpu(cp->addr), cp->page, - sys_le16_to_cpu(cp->offset), &comp); - if (err) { - LOG_ERR("Large Composition Data Get failed (err %d)", err); - - return BTP_STATUS_FAILED; - } - - memcpy(rp->data, comp.data->data, comp.data->len); - *rsp_len = comp.data->len; - - return BTP_STATUS_SUCCESS; -} - -static uint8_t models_metadata_get(const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) -{ - const struct btp_mesh_models_metadata_get_cmd *cp = cmd; - struct btp_mesh_models_metadata_get_rp *rp = rsp; - int err; - - struct bt_mesh_large_comp_data_rsp metadata; - - err = bt_mesh_models_metadata_get(sys_le16_to_cpu(cp->net_idx), - sys_le16_to_cpu(cp->addr), cp->page, - sys_le16_to_cpu(cp->offset), &metadata); - - if (err) { - LOG_ERR("Models Metadata Get failed (err %d)", err); - return BTP_STATUS_FAILED; - } - - memcpy(rp->data, metadata.data->data, metadata.data->len); - *rsp_len = metadata.data->len; - - return BTP_STATUS_SUCCESS; -} -#endif - static uint8_t composition_data_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -3016,21 +2936,8 @@ static const struct btp_handler handlers[] = { .func = proxy_connect }, #endif -#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) - { - .opcode = BTP_MESH_LARGE_COMP_DATA_GET, - .expect_len = sizeof(struct btp_mesh_large_comp_data_get_cmd), - .func = large_comp_data_get - }, - { - .opcode = BTP_MESH_MODELS_METADATA_GET, - .expect_len = sizeof(struct btp_mesh_models_metadata_get_cmd), - .func = models_metadata_get - }, -#endif }; - void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload, size_t payload_len) { From d17ece15b4507397f190d6fc30a6be64564d54e2 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:26 +0000 Subject: [PATCH 0791/1623] Revert "[nrf fromtree] Bluetooth: tester: Add ttl param to Model Send CMD" This reverts commit 83280e62bcf2d4f9ab18ce82c79ad6103a46cd62. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp/btp_mesh.h | 1 - tests/bluetooth/tester/src/btp_mesh.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index bd7af172744..e17d8481500 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -127,7 +127,6 @@ struct btp_mesh_lpn_set_cmd { #define BTP_MESH_MODEL_SEND 0x0f struct btp_mesh_model_send_cmd { - uint8_t ttl; uint16_t src; uint16_t dst; uint8_t payload_len; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index b6ac4d91e1c..2796f6418e4 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -861,7 +861,7 @@ static uint8_t model_send(const void *cmd, uint16_t cmd_len, .net_idx = net.net_idx, .app_idx = BT_MESH_KEY_DEV, .addr = sys_le16_to_cpu(cp->dst), - .send_ttl = cp->ttl, + .send_ttl = BT_MESH_TTL_DEFAULT, }; if (BT_MESH_ADDR_IS_VIRTUAL(ctx.addr)) { From e771bcd6dae2d02463e548e21d724de5e082250f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:26 +0000 Subject: [PATCH 0792/1623] Revert "[nrf fromtree] Bluetooth: tester: Use Model Receive testing callback" This reverts commit ab1eb73243f14658b3d50ff2b541516a857ace70. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp/btp_mesh.h | 8 -------- tests/bluetooth/tester/src/btp_mesh.c | 23 ----------------------- 2 files changed, 31 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index e17d8481500..bf73d6839d2 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -864,11 +864,3 @@ struct btp_mesh_prov_node_added_ev { uint8_t uuid[16]; uint8_t num_elems; } __packed; - -#define BTP_MESH_EV_MODEL_RECV 0x8f -struct btp_mesh_model_recv_ev { - uint16_t src; - uint16_t dst; - uint8_t payload_len; - uint8_t payload[]; -} __packed; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 2796f6418e4..c56c0ff9c1c 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -2963,28 +2963,6 @@ void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const voi tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_NET_RECV, buf.data, buf.len); } -void model_recv_ev(uint16_t src, uint16_t dst, const void *payload, - size_t payload_len) -{ - NET_BUF_SIMPLE_DEFINE(buf, UINT8_MAX); - struct btp_mesh_model_recv_ev *ev; - - LOG_DBG("src 0x%04x dst 0x%04x payload_len %zu", src, dst, payload_len); - - if (payload_len > net_buf_simple_tailroom(&buf)) { - LOG_ERR("Payload size exceeds buffer size"); - return; - } - - ev = net_buf_simple_add(&buf, sizeof(*ev)); - ev->src = sys_cpu_to_le16(src); - ev->dst = sys_cpu_to_le16(dst); - ev->payload_len = payload_len; - net_buf_simple_add_mem(&buf, payload, payload_len); - - tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_MODEL_RECV, buf.data, buf.len); -} - static void model_bound_cb(uint16_t addr, struct bt_mesh_model *model, uint16_t key_idx) { @@ -3045,7 +3023,6 @@ static void incomp_timer_exp_cb(void) static struct bt_test_cb bt_test_cb = { .mesh_net_recv = net_recv_ev, - .mesh_model_recv = model_recv_ev, .mesh_model_bound = model_bound_cb, .mesh_model_unbound = model_unbound_cb, .mesh_prov_invalid_bearer = invalid_bearer_cb, From 51146f2ede01cc40248f5cce3ff0dc82f2c4e525 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:26 +0000 Subject: [PATCH 0793/1623] Revert "[nrf fromtree] tests: Bluetooth: tester: fix mesh1d1 EHP pts tests" This reverts commit b6a8f040d960f817bc4abbb5806aa23d50c4bd07. Signed-off-by: Dominik Ermel --- tests/bluetooth/tester/src/btp/btp_mesh.h | 10 ++-------- tests/bluetooth/tester/src/btp_mesh.c | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index bf73d6839d2..d7d2b2cdc7b 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -30,15 +30,9 @@ struct btp_mesh_read_supported_commands_rp { #define BTP_MESH_CONFIG_PROVISIONING 0x02 -#if IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM) -#define BTP_MESH_PROV_AUTH_MAX_LEN 32 -#else -#define BTP_MESH_PROV_AUTH_MAX_LEN 16 -#endif - struct btp_mesh_config_provisioning_cmd { uint8_t uuid[16]; - uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; + uint8_t static_auth[16]; uint8_t out_size; uint16_t out_actions; uint8_t in_size; @@ -47,7 +41,7 @@ struct btp_mesh_config_provisioning_cmd { } __packed; struct btp_mesh_config_provisioning_cmd_v2 { uint8_t uuid[16]; - uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; + uint8_t static_auth[16]; uint8_t out_size; uint16_t out_actions; uint8_t in_size; diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index c56c0ff9c1c..c922c812631 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -43,7 +43,7 @@ static uint8_t priv_key[32]; /* Configured provisioning data */ static uint8_t dev_uuid[16]; -static uint8_t static_auth[BTP_MESH_PROV_AUTH_MAX_LEN]; +static uint8_t static_auth[16]; /* Vendor Model data */ #define VND_MODEL_ID_1 0x1234 From 2c6287a4587c2cdf658d0b6af2c70c81cf1c98f6 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:26 +0000 Subject: [PATCH 0794/1623] Revert "[nrf fromtree] Bluetooth: Mesh: refactor mandatory oob for mesh1d1" This reverts commit 2ec2e076210bd6c281ead3e1daebbc5ffcb54fc2. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/prov.c | 6 ++++++ subsys/bluetooth/mesh/prov_device.c | 13 ++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/subsys/bluetooth/mesh/prov.c b/subsys/bluetooth/mesh/prov.c index fbbcde58185..f44fffde649 100644 --- a/subsys/bluetooth/mesh/prov.c +++ b/subsys/bluetooth/mesh/prov.c @@ -181,6 +181,12 @@ int bt_mesh_prov_auth(bool is_provisioner, uint8_t method, uint8_t action, uint8 uint8_t auth_size = bt_mesh_prov_auth_size_get(); int err; + if (IS_ENABLED(CONFIG_BT_MESH_OOB_AUTH_REQUIRED) && + (method == AUTH_METHOD_NO_OOB || + bt_mesh_prov_link.algorithm == BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM)) { + return -EINVAL; + } + switch (method) { case AUTH_METHOD_NO_OOB: if (action || size) { diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/prov_device.c index 0184463568f..a83ace178db 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/prov_device.c @@ -94,16 +94,15 @@ static void prov_invite(const uint8_t *data) bt_mesh_prov->input_size > 0 || bt_mesh_prov->static_val; if (IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM)) { - WRITE_BIT(algorithm_bm, BT_MESH_PROV_AUTH_HMAC_SHA256_AES_CCM, 1); + algorithm_bm |= BIT(BT_MESH_PROV_AUTH_HMAC_SHA256_AES_CCM); } if (IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_CMAC_AES128_AES_CCM)) { - WRITE_BIT(algorithm_bm, BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM, 1); + algorithm_bm |= BIT(BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM); } if (oob_availability && IS_ENABLED(CONFIG_BT_MESH_OOB_AUTH_REQUIRED)) { oob_type |= BT_MESH_OOB_AUTH_REQUIRED; - WRITE_BIT(algorithm_bm, BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM, 0); } /* Supported algorithms */ @@ -177,18 +176,10 @@ static void prov_start(const uint8_t *data) bt_mesh_prov_link.oob_action = data[3]; bt_mesh_prov_link.oob_size = data[4]; - if (IS_ENABLED(CONFIG_BT_MESH_OOB_AUTH_REQUIRED) && - (bt_mesh_prov_link.oob_method == AUTH_METHOD_NO_OOB || - bt_mesh_prov_link.algorithm == BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM)) { - prov_fail(PROV_ERR_NVAL_FMT); - return; - } - if (bt_mesh_prov_auth(false, data[2], data[3], data[4]) < 0) { LOG_ERR("Invalid authentication method: 0x%02x; " "action: 0x%02x; size: 0x%02x", data[2], data[3], data[4]); prov_fail(PROV_ERR_NVAL_FMT); - return; } if (atomic_test_bit(bt_mesh_prov_link.flags, OOB_STATIC_KEY)) { From 369e0834b26e932aa3e23689de94f09957a5c88c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:27 +0000 Subject: [PATCH 0795/1623] Revert "[nrf fromtree] Bluetooth: Mesh: shell supports 32 bytes static oob" This reverts commit 609c593b26ea626d88909f09b7b6df4d26f88363. Signed-off-by: Dominik Ermel --- doc/connectivity/bluetooth/api/mesh/shell.rst | 4 ++-- subsys/bluetooth/mesh/shell/shell.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/connectivity/bluetooth/api/mesh/shell.rst b/doc/connectivity/bluetooth/api/mesh/shell.rst index 6f102b5490f..e6609f40e5c 100644 --- a/doc/connectivity/bluetooth/api/mesh/shell.rst +++ b/doc/connectivity/bluetooth/api/mesh/shell.rst @@ -297,7 +297,7 @@ To allow a device to provision devices over GATT, the :kconfig:option:`CONFIG_BT * ``String``: Unquoted alphanumeric authentication string. -``mesh prov static-oob [Val(1-32 hex)]`` +``mesh prov static-oob [Val(1-16 hex)]`` ---------------------------------------- Set or clear the static OOB authentication value. The static OOB authentication value must be set before provisioning starts to have any effect. The static OOB value must be same on both participants in the provisioning. To enable this command, the :kconfig:option:`BT_MESH_SHELL_PROV_CTX_INSTANCE` option must be enabled. @@ -358,7 +358,7 @@ To allow a device to provision devices over GATT, the :kconfig:option:`CONFIG_BT ------------------------------------------------ From the provisioner device, instruct the unprovisioned device to use static OOB authentication, and use the given static authentication value when provisioning. - * ``Val`` - Static OOB value. Providing a hex-string shorter than 32 bytes will populate the N most significant bytes of the array and zero-pad the rest. + * ``Val`` - Static OOB value. Providing a hex-string shorter than 16 bytes will populate the N most significant bytes of the array and zero-pad the rest. ``mesh prov auth-method none`` ------------------------------ diff --git a/subsys/bluetooth/mesh/shell/shell.c b/subsys/bluetooth/mesh/shell/shell.c index c5592db02cf..243166441fe 100644 --- a/subsys/bluetooth/mesh/shell/shell.c +++ b/subsys/bluetooth/mesh/shell/shell.c @@ -611,7 +611,7 @@ static void link_close(bt_mesh_prov_bearer_t bearer) shell_print_ctx("Provisioning link closed on %s", bearer2str(bearer)); } -static uint8_t static_val[32]; +static uint8_t static_val[16]; struct bt_mesh_prov bt_mesh_shell_prov = { .uuid = dev_uuid, @@ -645,7 +645,7 @@ static int cmd_static_oob(const struct shell *sh, size_t argc, char *argv[]) bt_mesh_shell_prov.static_val_len = 0U; } else { bt_mesh_shell_prov.static_val_len = hex2bin(argv[1], strlen(argv[1]), - static_val, 32); + static_val, 16); if (bt_mesh_shell_prov.static_val_len) { bt_mesh_shell_prov.static_val = static_val; } else { @@ -886,7 +886,7 @@ static int cmd_auth_method_set_output(const struct shell *sh, size_t argc, char static int cmd_auth_method_set_static(const struct shell *sh, size_t argc, char *argv[]) { size_t len; - uint8_t static_oob_auth[32]; + uint8_t static_oob_auth[16]; int err = 0; len = hex2bin(argv[1], strlen(argv[1]), static_oob_auth, sizeof(static_oob_auth)); From 65cedbd218bd5b4897d793fb746effa2b7271d5b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:27 +0000 Subject: [PATCH 0796/1623] Revert "[nrf fromtree] Bluetooth: Mesh: fix static oob setting" This reverts commit efc4e52f347da84ba172e23935f3786d9612a781. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/prov_device.c | 11 +++-------- subsys/bluetooth/mesh/provisioner.c | 15 ++++++++------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/prov_device.c index a83ace178db..20735f49fa5 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/prov_device.c @@ -183,14 +183,9 @@ static void prov_start(const uint8_t *data) } if (atomic_test_bit(bt_mesh_prov_link.flags, OOB_STATIC_KEY)) { - - uint8_t tail_size = bt_mesh_prov->static_val_len < auth_size - ? auth_size - bt_mesh_prov->static_val_len - : 0; - - memcpy(bt_mesh_prov_link.auth + tail_size, bt_mesh_prov->static_val, - tail_size ? bt_mesh_prov->static_val_len : auth_size); - memset(bt_mesh_prov_link.auth, 0, tail_size); + memcpy(bt_mesh_prov_link.auth + auth_size - bt_mesh_prov->static_val_len, + bt_mesh_prov->static_val, bt_mesh_prov->static_val_len); + memset(bt_mesh_prov_link.auth, 0, auth_size - bt_mesh_prov->static_val_len); } } diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index 673e14578d2..25f0a299480 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -254,7 +254,8 @@ static void prov_capabilities(const uint8_t *data) return; } - if (caps.oob_type & BT_MESH_OOB_AUTH_REQUIRED) { + if (IS_ENABLED(CONFIG_BT_MESH_OOB_AUTH_REQUIRED) && + (caps.oob_type & BT_MESH_OOB_AUTH_REQUIRED)) { bool oob_availability = caps.output_size > 0 || caps.input_size > 0 || (caps.oob_type & BT_MESH_STATIC_OOB_AVAILABLE); @@ -751,18 +752,18 @@ int bt_mesh_auth_method_set_output(bt_mesh_output_action_t action, uint8_t size) int bt_mesh_auth_method_set_static(const uint8_t *static_val, uint8_t size) { - uint8_t tail_size = size < PROV_AUTH_MAX_LEN ? PROV_AUTH_MAX_LEN - size : 0; + uint8_t auth_size = bt_mesh_prov_auth_size_get(); - if (!size || !static_val) { + if (!size || !static_val || size > auth_size) { return -EINVAL; } prov_set_method(AUTH_METHOD_STATIC, 0, 0); - memcpy(bt_mesh_prov_link.auth + tail_size, static_val, - tail_size ? size : PROV_AUTH_MAX_LEN); - memset(bt_mesh_prov_link.auth, 0, tail_size); - + memcpy(bt_mesh_prov_link.auth + auth_size - size, static_val, size); + if (size < auth_size) { + (void)memset(bt_mesh_prov_link.auth, 0, auth_size - size); + } return 0; } From ed1eaa8645619e33c1673ce97790473472358c43 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:27 +0000 Subject: [PATCH 0797/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Use decimals instead of hex nums in DFD shell cmds" This reverts commit cd7dfd7466119b3764545e4af9ae825ee577397e. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/shell/dfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/shell/dfd.c b/subsys/bluetooth/mesh/shell/dfd.c index 0415929dfec..b7daf42af1c 100644 --- a/subsys/bluetooth/mesh/shell/dfd.c +++ b/subsys/bluetooth/mesh/shell/dfd.c @@ -29,7 +29,7 @@ static void print_dfd_status(const struct shell *sh, struct bt_mesh_dfd_srv *srv srv->phase); if (srv->phase != BT_MESH_DFD_PHASE_IDLE && srv->dfu.xfer.slot) { - shell_fprintf(sh, SHELL_NORMAL, ", \"group\": %d, \"app_idx\": %d, " + shell_fprintf(sh, SHELL_NORMAL, ", \"group\": 0x%04x, \"app_idx\": %d, " "\"ttl\": %d, \"timeout_base\": %d, \"xfer_mode\": %d, " "\"apply\": %d, \"slot_idx\": %d", srv->inputs.group, srv->inputs.app_idx, srv->inputs.ttl, srv->inputs.timeout_base, @@ -165,7 +165,7 @@ static int cmd_dfd_receivers_get(const struct shell *sh, size_t argc, char *argv for (int i = 0; i < cnt; i++) { const struct bt_mesh_dfu_target *t = &dfd_srv->targets[i + first]; - shell_print(sh, "\t\t\"%d\": { \"blob_addr\": %d, \"phase\": %d, " + shell_print(sh, "\t\t\"%d\": { \"blob_addr\": 0x%04x, \"phase\": %d, " "\"status\": %d, \"blob_status\": %d, \"progress\": %d, " "\"img_idx\": %d }%s", i + first, t->blob.addr, t->phase, t->status, t->blob.status, progress, t->img_idx, (i == cnt - 1) ? "" : ","); From 487a2355dcd32f6f1b33c2f7b01d583964eac99c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:27 +0000 Subject: [PATCH 0798/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Fix printing device UUID" This reverts commit 7e3caf9f788b375b0eacf2b3c501606d95038ab0. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/prov_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/prov_device.c index 20735f49fa5..48d852cb1a7 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/prov_device.c @@ -675,7 +675,7 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers) return -EALREADY; } -#if defined(CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL) +#if IS_ENABLED(CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL) if (CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL > 2) { struct bt_uuid_128 uuid = { .uuid = { BT_UUID_TYPE_128 } }; From 7fe7cb0dad2cb10e7af3ee6f91610b9f153e8ee7 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:27 +0000 Subject: [PATCH 0799/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Add support for Upload OOB Start" This reverts commit 34e20954d8d64805a6e1cd0c804361ce713da363. Signed-off-by: Dominik Ermel --- doc/connectivity/bluetooth/api/mesh/shell.rst | 5 +- include/zephyr/bluetooth/mesh/dfd_srv.h | 163 +--------- include/zephyr/bluetooth/mesh/dfu.h | 13 +- subsys/bluetooth/mesh/Kconfig | 8 - subsys/bluetooth/mesh/dfd_srv.c | 270 +++------------- subsys/bluetooth/mesh/dfu_slot.c | 294 ++++++++---------- subsys/bluetooth/mesh/dfu_slot.h | 87 ++---- subsys/bluetooth/mesh/shell/dfd.c | 9 +- subsys/bluetooth/mesh/shell/dfu.c | 53 ++-- tests/bsim/bluetooth/mesh/prj_mesh1d1.conf | 3 +- tests/bsim/bluetooth/mesh/src/test_dfu.c | 185 ++++------- .../tests_scripts/dfu/dfu_slot_idempotency.sh | 14 - .../tests_scripts/dfu/dfu_slot_reservation.sh | 14 - 13 files changed, 326 insertions(+), 792 deletions(-) delete mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh delete mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh diff --git a/doc/connectivity/bluetooth/api/mesh/shell.rst b/doc/connectivity/bluetooth/api/mesh/shell.rst index e6609f40e5c..f9acf24d277 100644 --- a/doc/connectivity/bluetooth/api/mesh/shell.rst +++ b/doc/connectivity/bluetooth/api/mesh/shell.rst @@ -1034,14 +1034,15 @@ Firmware Update Client model The Firmware Update Client model can be added to the mesh shell by enabling configuration options :kconfig:option:`CONFIG_BT_MESH_BLOB_CLI` and :kconfig:option:`CONFIG_BT_MESH_DFU_CLI`. The Firmware Update Client demonstrates the firmware update Distributor role by transferring a dummy firmware update to a set of Target nodes. -``mesh models dfu slot add []`` +``mesh models dfu slot add [ [ []]]`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add a virtual DFU image slot that can be transferred as a DFU image. The image slot will be assigned an image slot index, which is printed as a response, and can be used to reference the slot in other commands. To update the image slot, remove it using the ``mesh models dfu slot del`` shell command and then add it again. * ``Size``: DFU image slot size in bytes. - * ``FwID``: Firmware ID, formatted as a hexstring. + * ``FwID``: Optional firmware ID, formatted as a hexstring. * ``Metadata``: Optional firmware metadata, formatted as a hexstring. + * ``URI``: Optional URI for the firmware. ``mesh models dfu slot del `` diff --git a/include/zephyr/bluetooth/mesh/dfd_srv.h b/include/zephyr/bluetooth/mesh/dfd_srv.h index da339c57ec6..0e281b29186 100644 --- a/include/zephyr/bluetooth/mesh/dfd_srv.h +++ b/include/zephyr/bluetooth/mesh/dfd_srv.h @@ -29,47 +29,11 @@ extern "C" { #define CONFIG_BT_MESH_DFD_SRV_TARGETS_MAX 0 #endif -#ifndef CONFIG_BT_MESH_DFD_SRV_SLOT_MAX_SIZE -#define CONFIG_BT_MESH_DFD_SRV_SLOT_MAX_SIZE 0 -#endif - -#ifndef CONFIG_BT_MESH_DFD_SRV_SLOT_SPACE -#define CONFIG_BT_MESH_DFD_SRV_SLOT_SPACE 0 -#endif - struct bt_mesh_dfd_srv; -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD -/** - * - * @brief Initialization parameters for the @ref bt_mesh_dfd_srv with OOB - * upload support. - * - * @param[in] _cb Pointer to a @ref bt_mesh_dfd_srv_cb instance. - * @param[in] _oob_schemes Array of OOB schemes supported by the server, - * each scheme being a code point from the - * Bluetooth SIG Assigned Numbers document. - * @param[in] _oob_schemes_count Number of schemes in @c _oob_schemes. - */ -#define BT_MESH_DFD_SRV_OOB_INIT(_cb, _oob_schemes, _oob_schemes_count) \ - { \ - .cb = _cb, \ - .dfu = BT_MESH_DFU_CLI_INIT(&_bt_mesh_dfd_srv_dfu_cb), \ - .upload = { \ - .blob = { .cb = &_bt_mesh_dfd_srv_blob_cb }, \ - }, \ - .oob_schemes = { \ - .schemes = _oob_schemes, \ - .count = _oob_schemes_count, \ - }, \ - } -#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ - /** * * @brief Initialization parameters for the @ref bt_mesh_dfd_srv. - * - * @param[in] _cb Pointer to a @ref bt_mesh_dfd_srv_cb instance. */ #define BT_MESH_DFD_SRV_INIT(_cb) \ { \ @@ -111,64 +75,6 @@ struct bt_mesh_dfd_srv_cb { const struct bt_mesh_dfu_slot *slot, const struct bt_mesh_blob_io **io); -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - /** @brief Firmware upload OOB start callback. - * - * Called at the start of an OOB firmware upload. The application must - * start a firmware check using an OOB mechanism, and then call - * @ref bt_mesh_dfd_srv_oob_check_complete. Depending on the return - * value of this function, the application must then start storing the - * firmware image using an OOB mechanism, and call - * @ref bt_mesh_dfd_srv_oob_store_complete. This callback is mandatory - * to support OOB uploads. - * - * @param srv Firmware Distribution Server model instance. - * @param slot Slot to be used for the upload. - * @param uri Pointer to buffer containing the URI used to - * check for new firmware. - * @param uri_len Length of the URI buffer. - * @param fwid Pointer to buffer containing the current - * firmware ID to be used when checking for - * availability of new firmware. - * @param fwid_len Length of the current firmware ID. Must be set - * to the length of the new firmware ID if it is - * available, or to 0 if new firmware is not - * available. - * - * @return BT_MESH_DFD_SUCCESS on success, or error code otherwise. - */ - int (*start_oob_upload)(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot, - const char *uri, uint8_t uri_len, - const uint8_t *fwid, uint16_t fwid_len); - - /** @brief Cancel store OOB callback - * - * Called when an OOB store is cancelled. The application must stop - * any ongoing OOB image transfer. This callback is mandatory to - * support OOB uploads. - * - * @param srv Firmware Distribution Server model instance. - * @param slot DFU image slot to cancel - */ - void (*cancel_oob_upload)(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot); - - /** @brief Get the progress of an ongoing OOB store - * - * Called by the Firmware Distribution Server model when it needs to - * get the current progress of an ongoing OOB store from the - * application. This callback is mandatory to support OOB uploads. - * - * @param srv Firmware Distribution Server model instance. - * @param slot DFU image slot to get progress for. - * - * @return The current progress of the ongoing OOB store, in percent. - */ - uint8_t (*oob_progress_get)(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot); -#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ - /** @brief Slot delete callback. * * Called when the Firmware Distribution Server is about to delete a DFU image slot. @@ -223,79 +129,12 @@ struct bt_mesh_dfd_srv { struct { enum bt_mesh_dfd_upload_phase phase; - struct bt_mesh_dfu_slot *slot; + const struct bt_mesh_dfu_slot *slot; const struct flash_area *area; struct bt_mesh_blob_srv blob; -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - bool is_oob; - struct { - uint8_t uri_len; - uint8_t uri[CONFIG_BT_MESH_DFU_URI_MAXLEN]; - uint16_t current_fwid_len; - uint8_t current_fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; - struct bt_mesh_msg_ctx ctx; - } oob; -#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ } upload; - -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - struct { - const uint8_t *schemes; - const uint8_t count; - } oob_schemes; -#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ }; -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD -/** @brief Call when an OOB check has completed or failed - * - * This should be called by the application after an OOB check started by the @c start_oob_upload - * callback has completed or failed. The @p status param should be set to one of the following - * values: - * - * * @c BT_MESH_DFD_SUCCESS if the check was succesfull and a new firmware ID was found. - * * @c BT_MESH_DFD_ERR_URI_MALFORMED if the URI is not formatted correctly. - * * @c BT_MESH_DFD_ERR_URI_NOT_SUPPORTED if the URI scheme is not supported by the node. - * * @c BT_MESH_DFD_ERR_URI_UNREACHABLE if the URI can't be reached. - * * @c BT_MESH_DFD_ERR_NEW_FW_NOT_AVAILABLE if the check completes successfully but no new - * firmware is available. - * - * If this function returns 0, the application should then download the firmware to the - * slot. If an error code is returned, the application should abort the OOB upload. - * - * @param srv Firmware Distribution Server model instance. - * @param slot The slot used in the OOB upload. - * @param status The result of the firmware check. - * @param fwid If the check was successful and new firmware found, this should point to a - * buffer containing the new firmware ID to store. - * @param fwid_len The length of the firmware ID pointed to by @p fwid. - * - * @return 0 on success, (negative) error code otherwise. - */ -int bt_mesh_dfd_srv_oob_check_complete(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot, int status, - uint8_t *fwid, size_t fwid_len); - -/** @brief Call when an OOB store has completed or failed - * - * This should be called by the application after an OOB store started after a succesfull call to - * @c bt_mesh_dfd_srv_oob_check_complete has completed successfully or failed. - * - * @param srv Firmware Distribution Server model instance. - * @param slot The slot used when storing the firmware image. - * @param success @c true if the OOB store completed successfully, @c false otherwise. - * @param size The size of the stored firmware image, in bytes. - * @param metadata Pointer to the metadata received OOB, or @c NULL if no metadata was - * received. - * @param metadata_len Size of the metadata pointed to by @p metadata. - * - * @return 0 on success, (negative) error code otherwise. - */ -int bt_mesh_dfd_srv_oob_store_complete(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot, bool success, - size_t size, const uint8_t *metadata, size_t metadata_len); -#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ - /** @cond INTERNAL_HIDDEN */ extern const struct bt_mesh_model_op _bt_mesh_dfd_srv_op[]; extern const struct bt_mesh_model_cb _bt_mesh_dfd_srv_cb; diff --git a/include/zephyr/bluetooth/mesh/dfu.h b/include/zephyr/bluetooth/mesh/dfu.h index 4745355f039..91f36cdbaeb 100644 --- a/include/zephyr/bluetooth/mesh/dfu.h +++ b/include/zephyr/bluetooth/mesh/dfu.h @@ -34,10 +34,6 @@ extern "C" { #define CONFIG_BT_MESH_DFU_URI_MAXLEN 0 #endif -#ifndef CONFIG_BT_MESH_DFU_SLOT_CNT -#define CONFIG_BT_MESH_DFU_SLOT_CNT 0 -#endif - /** DFU transfer phase. */ enum bt_mesh_dfu_phase { /** Ready to start a Receive Firmware procedure. */ @@ -144,7 +140,10 @@ struct bt_mesh_dfu_img { /** Length of the firmware ID. */ size_t fwid_len; - /** Update URI, or NULL. */ + /** Update URI, or NULL. + * + * Must use one of the http: or https: schemes. + */ const char *uri; }; @@ -156,10 +155,14 @@ struct bt_mesh_dfu_slot { size_t fwid_len; /** Length of the metadata. */ size_t metadata_len; + /** Length of the image URI. */ + size_t uri_len; /** Firmware ID. */ uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; /** Metadata. */ uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN]; + /** Image URI. */ + char uri[CONFIG_BT_MESH_DFU_URI_MAXLEN]; }; /** @} */ diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 2dfc125b8fd..b8e26309a28 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1235,14 +1235,6 @@ config BT_MESH_DFD_SRV_TARGETS_MAX This value defines the maximum number of Target nodes the Firmware Distribution Server can target simultaneously. -config BT_MESH_DFD_SRV_OOB_UPLOAD - bool "Support for DFU image OOB upload" - help - This enables support for OOB upload of firmware images for - distribution. This makes several callbacks and use of the init - macro BT_MESH_DFD_SRV_INIT_OOB mandatory. See the API documentation - for bt_mesh_dfd_srv_cb for details about the mandatory callbacks. - endif config BT_MESH_RPR_SRV diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 54de343c94a..2898ca39a39 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -224,20 +224,7 @@ static int handle_capabilities_get(struct bt_mesh_model *mod, struct bt_mesh_msg size = MIN(size, CONFIG_BT_MESH_DFD_SRV_SLOT_SPACE); net_buf_simple_add_le32(&rsp, CONFIG_BT_MESH_DFD_SRV_SLOT_SPACE - size); - -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - struct bt_mesh_dfd_srv *srv = mod->user_data; - - if (srv->oob_schemes.count > 0) { - net_buf_simple_add_u8(&rsp, 1); - net_buf_simple_add_mem(&rsp, srv->oob_schemes.schemes, - srv->oob_schemes.count); - } else -#else - { - net_buf_simple_add_u8(&rsp, 0); - } -#endif + net_buf_simple_add_u8(&rsp, 0U); /* OOB retrieval not supported */ bt_mesh_model_send(mod, ctx, &rsp, NULL, NULL); @@ -359,19 +346,10 @@ static void upload_status_rsp(struct bt_mesh_dfd_srv *srv, return; } -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - if (srv->upload.is_oob) { - net_buf_simple_add_u8(&rsp, - srv->cb->oob_progress_get(srv, srv->upload.slot) | BIT(7)); - net_buf_simple_add_mem(&rsp, srv->upload.oob.current_fwid, - srv->upload.oob.current_fwid_len); - } else -#endif - { - net_buf_simple_add_u8(&rsp, bt_mesh_blob_srv_progress(&srv->upload.blob)); - net_buf_simple_add_mem(&rsp, srv->upload.slot->fwid, - srv->upload.slot->fwid_len); - } + net_buf_simple_add_u8(&rsp, + bt_mesh_blob_srv_progress(&srv->upload.blob)); + net_buf_simple_add_mem(&rsp, srv->upload.slot->fwid, + srv->upload.slot->fwid_len); bt_mesh_model_send(srv->mod, ctx, &rsp, NULL, NULL); } @@ -386,42 +364,16 @@ static int handle_upload_get(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx * return 0; } -static inline int set_upload_fwid(struct bt_mesh_dfd_srv *srv, struct bt_mesh_msg_ctx *ctx, - const uint8_t *fwid, size_t fwid_len) -{ - int err = bt_mesh_dfu_slot_fwid_set(srv->upload.slot, fwid, fwid_len); - - switch (err) { - case -EFBIG: /* Fwid too long */ - case -EALREADY: /* Other server is in progress with this fwid */ - bt_mesh_dfu_slot_release(srv->upload.slot); - upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); - break; - case -EEXIST: /* Img with this fwid already is in list */ - srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; - bt_mesh_dfu_slot_release(srv->upload.slot); - upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); - break; - case 0: - srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE; - break; - case -EINVAL: /* Slot in wrong state. */ - default: - break; - } - - return err; -} - static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { struct bt_mesh_dfd_srv *srv = mod->user_data; + const struct bt_mesh_dfu_slot *old_slot = srv->upload.slot; size_t meta_len, fwid_len, size; const uint8_t *meta, *fwid; uint16_t timeout_base; uint64_t blob_id; - int err; + int err, idx; uint8_t ttl; ttl = net_buf_simple_pull_u8(buf); @@ -440,7 +392,9 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx LOG_DBG("Upload Start: size: %d, fwid: %s, metadata: %s", size, bt_hex(fwid, fwid_len), bt_hex(meta, meta_len)); - if (size > CONFIG_BT_MESH_DFD_SRV_SLOT_MAX_SIZE) { + if (size > CONFIG_BT_MESH_DFD_SRV_SLOT_MAX_SIZE || + fwid_len > CONFIG_BT_MESH_DFU_FWID_MAXLEN || + meta_len > CONFIG_BT_MESH_DFU_METADATA_MAXLEN) { upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INSUFFICIENT_RESOURCES); return 0; @@ -459,11 +413,7 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx !memcmp(srv->upload.slot->metadata, meta, meta_len) && srv->upload.blob.state.xfer.id == blob_id && srv->upload.blob.state.ttl == ttl && - srv->upload.blob.state.timeout_base == timeout_base -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - && !srv->upload.is_oob -#endif - ) { + srv->upload.blob.state.timeout_base == timeout_base) { LOG_DBG("Duplicate upload start"); upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); return 0; @@ -474,16 +424,23 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx return 0; } - /* This will be a no-op if the slot state isn't RESERVED, which is - * what we want. - */ - bt_mesh_dfu_slot_release(srv->upload.slot); + idx = bt_mesh_dfu_slot_get(fwid, fwid_len, &srv->upload.slot); + if (idx >= 0 && bt_mesh_dfu_slot_is_valid(srv->upload.slot)) { + LOG_DBG("Already received image"); + srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; + upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); + return 0; + } -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - srv->upload.is_oob = false; -#endif - srv->upload.slot = bt_mesh_dfu_slot_reserve(); + if (old_slot && !bt_mesh_dfu_slot_is_valid(old_slot)) { + LOG_DBG("Deleting old invalid slot"); + slot_del(srv, old_slot); + } + /* TODO Store transfer state before slot is added. */ + + srv->upload.slot = bt_mesh_dfu_slot_add(size, fwid, fwid_len, meta, + meta_len, NULL, 0); if (!srv->upload.slot) { LOG_WRN("No space for slot"); upload_status_rsp(srv, ctx, @@ -491,27 +448,11 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx return 0; } - err = set_upload_fwid(srv, ctx, fwid, fwid_len); - if (err) { - return err; - } - - err = bt_mesh_dfu_slot_info_set(srv->upload.slot, size, meta, meta_len); - switch (err) { - case -EFBIG: - upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); - break; - case 0: - break; - default: - return err; - } - srv->io = NULL; err = srv->cb->recv(srv, srv->upload.slot, &srv->io); if (err || !srv->io) { LOG_ERR("App rejected upload. err: %d io: %p", err, srv->io); - bt_mesh_dfu_slot_release(srv->upload.slot); + slot_del(srv, srv->upload.slot); upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); return 0; } @@ -520,7 +461,7 @@ static int handle_upload_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx timeout_base); if (err) { LOG_ERR("BLOB Server rejected upload (err: %d)", err); - bt_mesh_dfu_slot_release(srv->upload.slot); + slot_del(srv, srv->upload.slot); upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); return 0; } @@ -537,71 +478,10 @@ static int handle_upload_start_oob(struct bt_mesh_model *mod, struct bt_mesh_msg struct net_buf_simple *buf) { struct bt_mesh_dfd_srv *srv = mod->user_data; - uint8_t uri_len; - uint8_t *uri; - uint16_t fwid_len; - uint8_t *fwid; - - uri_len = net_buf_simple_pull_u8(buf); - - if (uri_len > buf->len) { - return -EINVAL; - } - - uri = net_buf_simple_pull_mem(buf, uri_len); - fwid_len = buf->len; - fwid = net_buf_simple_pull_mem(buf, fwid_len); - if (upload_is_busy(srv)) { -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - if (srv->upload.is_oob && - uri_len == srv->upload.oob.uri_len && - fwid_len == srv->upload.oob.current_fwid_len && - !memcmp(uri, srv->upload.oob.uri, uri_len) && - !memcmp(fwid, srv->upload.oob.current_fwid, fwid_len)) { - /* Same image, return SUCCESS for idempotency */ - upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); - return 0; - } -#endif - upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_BUSY_WITH_UPLOAD); - return 0; - } - -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - if (uri_len > CONFIG_BT_MESH_DFU_URI_MAXLEN || - fwid_len > CONFIG_BT_MESH_DFU_FWID_MAXLEN) { - upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INTERNAL); - return 0; - } - - struct bt_mesh_dfu_slot *slot = bt_mesh_dfu_slot_reserve(); - - if (slot == NULL) { - upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_INSUFFICIENT_RESOURCES); - return 0; - } + LOG_DBG(""); - srv->upload.is_oob = true; - srv->upload.slot = slot; - memcpy(srv->upload.oob.uri, uri, uri_len); - srv->upload.oob.uri_len = uri_len; - memcpy(srv->upload.oob.current_fwid, fwid, fwid_len); - srv->upload.oob.current_fwid_len = fwid_len; - memcpy(&srv->upload.oob.ctx, ctx, sizeof(struct bt_mesh_msg_ctx)); - - int status = srv->cb->start_oob_upload(srv, srv->upload.slot, srv->upload.oob.uri, - srv->upload.oob.uri_len, - srv->upload.oob.current_fwid, - srv->upload.oob.current_fwid_len); - - if (status != BT_MESH_DFD_SUCCESS) { - upload_status_rsp(srv, ctx, status); - bt_mesh_dfu_slot_release(srv->upload.slot); - } -#else upload_status_rsp(srv, ctx, BT_MESH_DFD_ERR_URI_NOT_SUPPORTED); -#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ return 0; } @@ -612,14 +492,7 @@ static int handle_upload_cancel(struct bt_mesh_model *mod, struct bt_mesh_msg_ct struct bt_mesh_dfd_srv *srv = mod->user_data; srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_IDLE; -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD - if (srv->upload.is_oob) { - srv->cb->cancel_oob_upload(srv, srv->upload.slot); - } else -#endif - { - (void)bt_mesh_blob_srv_cancel(&srv->upload.blob); - } + (void)bt_mesh_blob_srv_cancel(&srv->upload.blob); upload_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); return 0; @@ -635,7 +508,7 @@ static void fw_status_rsp(struct bt_mesh_dfd_srv *srv, bt_mesh_model_msg_init(&rsp, BT_MESH_DFD_OP_FW_STATUS); net_buf_simple_add_u8(&rsp, status); - net_buf_simple_add_le16(&rsp, bt_mesh_dfu_slot_count()); + net_buf_simple_add_le16(&rsp, bt_mesh_dfu_slot_foreach(NULL, NULL)); net_buf_simple_add_le16(&rsp, idx); if (fwid) { @@ -649,7 +522,7 @@ static int handle_fw_get(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { struct bt_mesh_dfd_srv *srv = mod->user_data; - struct bt_mesh_dfu_slot *slot; + const struct bt_mesh_dfu_slot *slot; const uint8_t *fwid; size_t fwid_len; int idx; @@ -658,7 +531,7 @@ static int handle_fw_get(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, fwid = net_buf_simple_pull_mem(buf, fwid_len); idx = bt_mesh_dfu_slot_get(fwid, fwid_len, &slot); - if (idx >= 0) { + if (idx >= 0 && bt_mesh_dfu_slot_is_valid(slot)) { fw_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS, idx, fwid, fwid_len); } else { @@ -679,7 +552,7 @@ static int handle_fw_get_by_index(struct bt_mesh_model *mod, struct bt_mesh_msg_ idx = net_buf_simple_pull_le16(buf); slot = bt_mesh_dfu_slot_at(idx); - if (slot) { + if (slot && bt_mesh_dfu_slot_is_valid(slot)) { fw_status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS, idx, slot->fwid, slot->fwid_len); } else { @@ -856,7 +729,8 @@ static void upload_end(struct bt_mesh_blob_srv *b, uint64_t id, bool success) LOG_DBG("%u", success); - if (success && (bt_mesh_dfu_slot_commit(srv->upload.slot) == 0)) { + if (success) { + bt_mesh_dfu_slot_valid_set(srv->upload.slot, true); srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; return; } @@ -976,7 +850,7 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_start(struct bt_mesh_dfd_srv *srv, xfer.mode = params->xfer_mode; xfer.slot = bt_mesh_dfu_slot_at(params->slot_idx); - if (!xfer.slot) { + if (!xfer.slot || !bt_mesh_dfu_slot_is_valid(xfer.slot)) { return BT_MESH_DFD_ERR_FW_NOT_FOUND; } @@ -1139,7 +1013,7 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_apply(struct bt_mesh_dfd_srv *srv) enum bt_mesh_dfd_status bt_mesh_dfd_srv_fw_delete(struct bt_mesh_dfd_srv *srv, size_t *fwid_len, const uint8_t **fwid) { - struct bt_mesh_dfu_slot *slot; + const struct bt_mesh_dfu_slot *slot; int idx, err; if (srv->phase != BT_MESH_DFD_PHASE_IDLE) { @@ -1149,7 +1023,7 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_fw_delete(struct bt_mesh_dfd_srv *srv, s } idx = bt_mesh_dfu_slot_get(*fwid, *fwid_len, &slot); - if (idx < 0) { + if (idx < 0 || !bt_mesh_dfu_slot_is_valid(slot)) { return BT_MESH_DFD_SUCCESS; } @@ -1175,69 +1049,3 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_fw_delete_all(struct bt_mesh_dfd_srv *sr return BT_MESH_DFD_SUCCESS; } - -#ifdef CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD -int bt_mesh_dfd_srv_oob_check_complete(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot, int status, - uint8_t *fwid, size_t fwid_len) -{ - int err; - - if (slot != srv->upload.slot || !srv->upload.is_oob || - srv->upload.phase == BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE) { - /* This should not happen, unless the application calls the function with a - * "wrong" pointer or at a wrong time. - */ - return -EINVAL; - } - - if (status != BT_MESH_DFD_SUCCESS) { - bt_mesh_dfu_slot_release(srv->upload.slot); - upload_status_rsp(srv, &srv->upload.oob.ctx, status); - return -ECANCELED; - } - - err = set_upload_fwid(srv, &srv->upload.oob.ctx, fwid, fwid_len); - - if (err) { - return err; - } - - upload_status_rsp(srv, &srv->upload.oob.ctx, BT_MESH_DFD_SUCCESS); - return 0; -} - -int bt_mesh_dfd_srv_oob_store_complete(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot, bool success, - size_t size, const uint8_t *metadata, size_t metadata_len) -{ - int err = 0; - - if (srv->upload.phase != BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ACTIVE || - srv->upload.slot != slot || !srv->upload.is_oob) { - return -EINVAL; - } - - if (!success) { - goto error; - } - - err = bt_mesh_dfu_slot_info_set(srv->upload.slot, size, metadata, metadata_len); - if (err) { - goto error; - } - - err = bt_mesh_dfu_slot_commit(srv->upload.slot); - if (err) { - goto error; - } - - srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_SUCCESS; - return 0; - -error: - srv->upload.phase = BT_MESH_DFD_UPLOAD_PHASE_TRANSFER_ERROR; - bt_mesh_dfu_slot_release(srv->upload.slot); - return err; -} -#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */ diff --git a/subsys/bluetooth/mesh/dfu_slot.c b/subsys/bluetooth/mesh/dfu_slot.c index 097d5abcc82..16628793457 100644 --- a/subsys/bluetooth/mesh/dfu_slot.c +++ b/subsys/bluetooth/mesh/dfu_slot.c @@ -20,22 +20,23 @@ LOG_MODULE_REGISTER(bt_mesh_dfu_slot); #define DFU_SLOT_SETTINGS_PATH "bt/mesh-dfu/slot" -#define HEADER_SIZE offsetof(struct slot, slot.fwid) +#define HEADER_SIZE offsetof(struct bt_mesh_dfu_slot, fwid) #define PROP_HEADER "h" #define PROP_FWID "id" #define PROP_METADATA "m" +#define PROP_URI "u" +#define VALID_SLOTS_TAG "v" -static sys_slist_t list; +#define SLOT_IN_ARRAY(_slot) PART_OF_ARRAY(slots, CONTAINER_OF(_slot, struct slot, slot)) +static ATOMIC_DEFINE(valid_slots, CONFIG_BT_MESH_DFU_SLOT_CNT); +static sys_slist_t list; static struct slot { - uint32_t idx; - struct bt_mesh_dfu_slot slot; sys_snode_t n; + struct bt_mesh_dfu_slot slot; } slots[CONFIG_BT_MESH_DFU_SLOT_CNT]; -static uint32_t slot_index; - static char *slot_entry_encode(uint16_t idx, char buf[SLOT_ENTRY_BUFLEN], const char *property) { @@ -45,29 +46,32 @@ static char *slot_entry_encode(uint16_t idx, char buf[SLOT_ENTRY_BUFLEN], return buf; } -static bool slot_eq(const struct bt_mesh_dfu_slot *slot, - const uint8_t *fwid, size_t fwid_len) +static inline bool slot_in_use(const struct bt_mesh_dfu_slot *slot) { - return (slot->fwid_len == fwid_len) && - !memcmp(fwid, slot->fwid, fwid_len); + return slot->size > 0U; } -static bool is_slot_committed(struct slot *slot_to_check) +static inline uint16_t slot_idx(const struct bt_mesh_dfu_slot *slot) { - struct slot *s; + return CONTAINER_OF(slot, struct slot, slot) - &slots[0]; +} - SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { - if (s == slot_to_check) { - return true; - } - } +static inline void slot_invalidate(struct slot *slot_to_invalidate) +{ + slot_to_invalidate->slot.size = 0U; + atomic_clear_bit(valid_slots, slot_to_invalidate - &slots[0]); +} - return false; +static bool slot_eq(const struct bt_mesh_dfu_slot *slot, + const uint8_t *fwid, size_t fwid_len) +{ + return (slot->fwid_len == fwid_len) && + !memcmp(fwid, slot->fwid, fwid_len); } static int slot_store(const struct slot *slot_to_store) { - uint16_t idx = ARRAY_INDEX(slots, slot_to_store); + uint16_t idx = slot_to_store - &slots[0]; char buf[SLOT_ENTRY_BUFLEN]; int err; @@ -86,51 +90,55 @@ static int slot_store(const struct slot *slot_to_store) err = settings_save_one(slot_entry_encode(idx, buf, PROP_METADATA), slot_to_store->slot.metadata, slot_to_store->slot.metadata_len); + if (err) { + return err; + } - return err; + return settings_save_one(slot_entry_encode(idx, buf, PROP_URI), + slot_to_store->slot.uri, slot_to_store->slot.uri_len); } static void slot_erase(struct slot *slot_to_erase) { - uint16_t idx = ARRAY_INDEX(slots, slot_to_erase); + uint16_t idx = slot_to_erase - &slots[0]; char buf[SLOT_ENTRY_BUFLEN]; settings_delete(slot_entry_encode(idx, buf, PROP_HEADER)); settings_delete(slot_entry_encode(idx, buf, PROP_FWID)); settings_delete(slot_entry_encode(idx, buf, PROP_METADATA)); + settings_delete(slot_entry_encode(idx, buf, PROP_URI)); } -static void slot_index_defrag(void) +static int valid_slots_store(void) { - slot_index = 0; - struct slot *s; - - SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { - s->idx = ++slot_index; - slot_store(s); - } + return settings_save_one(DFU_SLOT_SETTINGS_PATH "/" VALID_SLOTS_TAG, + valid_slots, sizeof(valid_slots)); } -int bt_mesh_dfu_slot_count(void) +const struct bt_mesh_dfu_slot * +bt_mesh_dfu_slot_add(size_t size, const uint8_t *fwid, + size_t fwid_len, const uint8_t *metadata, + size_t metadata_len, const char *uri, size_t uri_len) { - int cnt = 0; - sys_snode_t *n; + struct slot *slot = NULL; + int err, i; - SYS_SLIST_FOR_EACH_NODE(&list, n) { - cnt++; + if (size == 0 || fwid_len > CONFIG_BT_MESH_DFU_FWID_MAXLEN || + metadata_len > CONFIG_BT_MESH_DFU_METADATA_MAXLEN || + uri_len > CONFIG_BT_MESH_DFU_URI_MAXLEN) { + LOG_WRN("Param too large: (size: %d, fwid: %d, metadata: %d, uri: %d)", + size, fwid_len, metadata_len, uri_len); + return NULL; } - return cnt; -} - -struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_reserve(void) -{ - struct slot *slot = NULL; - - for (int i = 0; i < ARRAY_SIZE(slots); ++i) { - if (slots[i].idx == 0) { + for (i = 0; i < ARRAY_SIZE(slots); ++i) { + if (!slot_in_use(&slots[i].slot)) { slot = &slots[i]; - break; + continue; + } + + if (slot_eq(&slots[i].slot, fwid, fwid_len)) { + return &slots[i].slot; } } @@ -139,136 +147,110 @@ struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_reserve(void) return NULL; } - if (slot_index == UINT32_MAX) { - slot_index_defrag(); - } + slot->slot.fwid_len = fwid_len; + slot->slot.metadata_len = metadata_len; + slot->slot.uri_len = uri_len; + memcpy(slot->slot.fwid, fwid, fwid_len); + memcpy(slot->slot.metadata, metadata, metadata_len); + memcpy(slot->slot.uri, uri, uri_len); + slot->slot.size = size; - slot->slot.fwid_len = 0; - slot->slot.metadata_len = 0; - slot->slot.size = 0; - slot->idx = ++slot_index; + err = slot_store(slot); + if (err) { + slot_invalidate(slot); + LOG_WRN("Store failed (err: %d)", err); + return NULL; + } - LOG_DBG("Reserved slot #%u", slot - &slots[0]); + sys_slist_append(&list, &slot->n); + LOG_DBG("Added slot #%u: %s", slot - &slots[0], + bt_hex(slot->slot.fwid, slot->slot.fwid_len)); return &slot->slot; } -int bt_mesh_dfu_slot_info_set(struct bt_mesh_dfu_slot *dfu_slot, size_t size, - const uint8_t *metadata, size_t metadata_len) +int bt_mesh_dfu_slot_valid_set(const struct bt_mesh_dfu_slot *slot, bool valid) { - struct slot *slot = CONTAINER_OF(dfu_slot, struct slot, slot); - - if (metadata_len > CONFIG_BT_MESH_DFU_METADATA_MAXLEN) { - return -EFBIG; - } + uint16_t idx; + bool prev; + int err; - if (slot->idx == 0 || is_slot_committed(slot)) { - return -EINVAL; + if (!SLOT_IN_ARRAY(slot) || !slot_in_use(slot)) { + return -ENOENT; } - slot->slot.size = size; - slot->slot.metadata_len = metadata_len; - memcpy(slot->slot.metadata, metadata, metadata_len); - return 0; -} - -int bt_mesh_dfu_slot_fwid_set(struct bt_mesh_dfu_slot *dfu_slot, - const uint8_t *fwid, size_t fwid_len) -{ - struct slot *slot = CONTAINER_OF(dfu_slot, struct slot, slot); + idx = slot_idx(slot); - if (fwid_len > CONFIG_BT_MESH_DFU_FWID_MAXLEN) { - return -EFBIG; - } + LOG_DBG("%u: %u", idx, valid); - if (slot->idx == 0 || is_slot_committed(slot)) { - return -EINVAL; - } - - for (int i = 0; i < ARRAY_SIZE(slots); i++) { - if (slots[i].idx != 0 && - slot_eq(&slots[i].slot, fwid, fwid_len)) { - return is_slot_committed(&slots[i]) ? - -EEXIST : -EALREADY; - } + if (valid) { + prev = atomic_test_and_set_bit(valid_slots, idx); + } else { + prev = atomic_test_and_clear_bit(valid_slots, idx); } - slot->slot.fwid_len = fwid_len; - memcpy(slot->slot.fwid, fwid, fwid_len); - return 0; -} - -int bt_mesh_dfu_slot_commit(struct bt_mesh_dfu_slot *dfu_slot) -{ - int err; - struct slot *slot = CONTAINER_OF(dfu_slot, struct slot, slot); - - if (slot->idx == 0 || - slot->slot.fwid_len == 0 || - slot->slot.size == 0 || - is_slot_committed(slot)) { - return -EINVAL; + if (valid == prev) { + return 0; } - err = slot_store(slot); + err = valid_slots_store(); if (err) { - LOG_WRN("Store failed (err: %d)", err); - return err; + LOG_WRN("Storage failed. err: %d", err); + atomic_set_bit_to(valid_slots, idx, prev); } - sys_slist_append(&list, &slot->n); - - LOG_DBG("Stored slot #%u: %s", ARRAY_INDEX(slots, slot), - bt_hex(slot->slot.fwid, slot->slot.fwid_len)); - return 0; + return err; } -void bt_mesh_dfu_slot_release(const struct bt_mesh_dfu_slot *dfu_slot) +bool bt_mesh_dfu_slot_is_valid(const struct bt_mesh_dfu_slot *slot) { - struct slot *slot = CONTAINER_OF(dfu_slot, struct slot, slot); + uint16_t idx; - if (is_slot_committed(slot)) { - return; + if (!SLOT_IN_ARRAY(slot) || !slot_in_use(slot)) { + return false; } - slot->idx = 0; + idx = slot_idx(slot); + return atomic_test_bit(valid_slots, idx); } -int bt_mesh_dfu_slot_del(const struct bt_mesh_dfu_slot *dfu_slot) +int bt_mesh_dfu_slot_del(const struct bt_mesh_dfu_slot *slot) { - struct slot *slot = CONTAINER_OF(dfu_slot, struct slot, slot); + struct slot *s = CONTAINER_OF(slot, struct slot, slot); - if (!sys_slist_find_and_remove(&list, &slot->n)) { - return -EINVAL; + if (!SLOT_IN_ARRAY(slot) || !slot_in_use(slot)) { + return -ENOENT; } - int idx = ARRAY_INDEX(slots, slot); + LOG_DBG("%u", s - &slots[0]); - LOG_DBG("%u", idx); - - slot_erase(slot); - slot->idx = 0; + slot_erase(s); + slot_invalidate(s); + sys_slist_find_and_remove(&list, &s->n); return 0; } -void bt_mesh_dfu_slot_del_all(void) +int bt_mesh_dfu_slot_del_all(void) { struct slot *s; + SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { slot_erase(s); - s->idx = 0; + slot_invalidate(s); } sys_slist_init(&list); + + return 0; } -const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t img_idx) +const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t idx) { struct slot *s; SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { - if (!img_idx--) { + if (!idx--) { return &s->slot; } } @@ -276,33 +258,34 @@ const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t img_idx) return NULL; } -int bt_mesh_dfu_slot_get(const uint8_t *fwid, size_t fwid_len, struct bt_mesh_dfu_slot **slot) +int bt_mesh_dfu_slot_get(const uint8_t *fwid, size_t fwid_len, + const struct bt_mesh_dfu_slot **slot) { struct slot *s; int idx = 0; SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { if (slot_eq(&s->slot, fwid, fwid_len)) { - if (slot) { - *slot = &s->slot; - } + *slot = &s->slot; return idx; } + idx++; } return -ENOENT; } -int bt_mesh_dfu_slot_img_idx_get(const struct bt_mesh_dfu_slot *dfu_slot) +int bt_mesh_dfu_slot_idx_get(const struct bt_mesh_dfu_slot *slot) { struct slot *s; int idx = 0; SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { - if (&s->slot == dfu_slot) { + if (&s->slot == slot) { return idx; } + idx++; } @@ -312,12 +295,11 @@ int bt_mesh_dfu_slot_img_idx_get(const struct bt_mesh_dfu_slot *dfu_slot) size_t bt_mesh_dfu_slot_foreach(bt_mesh_dfu_slot_cb_t cb, void *user_data) { enum bt_mesh_dfu_iter iter; - size_t cnt = 0; struct slot *s; + size_t cnt = 0; SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { cnt++; - if (!cb) { continue; } @@ -338,6 +320,15 @@ static int slot_data_load(const char *key, size_t len_rd, size_t len; uint16_t idx; + if (!strncmp(key, VALID_SLOTS_TAG, 1)) { + if (read_cb(cb_arg, valid_slots, + MIN(sizeof(valid_slots), len_rd)) < 0) { + return -EINVAL; + } + + return 0; + } + idx = strtol(key, NULL, 16); if (idx >= ARRAY_SIZE(slots)) { @@ -348,34 +339,16 @@ static int slot_data_load(const char *key, size_t len_rd, if (!strncmp(prop, PROP_HEADER, len)) { if (read_cb(cb_arg, &slots[idx], HEADER_SIZE) > 0) { - struct slot *s, *prev = NULL; - - SYS_SLIST_FOR_EACH_CONTAINER(&list, s, n) { - if (s->idx > slots[idx].idx) { - break; - } - - prev = s; - } - - if (prev == NULL) { - sys_slist_prepend(&list, &slots[idx].n); - } else { - sys_slist_insert(&list, &prev->n, &slots[idx].n); - } - - if (slots[idx].idx >= slot_index) { - slot_index = slots[idx].idx + 1; - } + sys_slist_append(&list, &slots[idx].n); } + return 0; } if (!strncmp(prop, PROP_FWID, len)) { if (read_cb(cb_arg, &slots[idx].slot.fwid, sizeof(slots[idx].slot.fwid)) < 0) { - slots[idx].idx = 0; - sys_slist_find_and_remove(&list, &slots[idx].n); + slot_invalidate(&slots[idx]); return 0; } @@ -386,8 +359,7 @@ static int slot_data_load(const char *key, size_t len_rd, if (!strncmp(prop, PROP_METADATA, len)) { if (read_cb(cb_arg, &slots[idx].slot.metadata, sizeof(slots[idx].slot.metadata)) < 0) { - slots[idx].idx = 0; - sys_slist_find_and_remove(&list, &slots[idx].n); + slot_invalidate(&slots[idx]); return 0; } @@ -395,6 +367,16 @@ static int slot_data_load(const char *key, size_t len_rd, return 0; } + if (!strncmp(prop, PROP_URI, len)) { + if (read_cb(cb_arg, &slots[idx].slot.uri, + sizeof(slots[idx].slot.uri)) < 0) { + slot_invalidate(&slots[idx]); + return 0; + } + + slots[idx].slot.uri_len = len_rd; + } + return 0; } diff --git a/subsys/bluetooth/mesh/dfu_slot.h b/subsys/bluetooth/mesh/dfu_slot.h index 969c6d3d25b..1bc58f64de9 100644 --- a/subsys/bluetooth/mesh/dfu_slot.h +++ b/subsys/bluetooth/mesh/dfu_slot.h @@ -16,69 +16,50 @@ typedef enum bt_mesh_dfu_iter (*bt_mesh_dfu_slot_cb_t)( const struct bt_mesh_dfu_slot *slot, void *user_data); -/** @brief Get the number of slots committed to the firmware list. - * - * @return Number of committed slots. - */ -int bt_mesh_dfu_slot_count(void); - -/** @brief Reserve a new DFU image slot for a distributable image. +/** @brief Register a new DFU image slot for a distributable image. * * A DFU image slot represents a single distributable DFU image with all its - * metadata. The slot data must be set using @ref bt_mesh_dfu_slot_info_set and - * @ref bt_mesh_dfu_slot_fwid_set, and the slot committed using - * @ref bt_mesh_dfu_slot_commit for the slot to be considered part of the slot - * list. + * metadata. * - * @return A pointer to the reserved slot, or NULL if allocation failed. - */ -struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_reserve(void); - -/** @brief Set the size and metadata for a reserved slot. + * @note The slot is allocated as invalid. Call + * @ref bt_mesh_dfu_slot_valid_set to make it valid. * - * @param dfu_slot Pointer to the reserved slot for which to set the - * metadata. - * @param size The size of the image. + * @param size Size of the image in bytes. + * @param fwid Firmware ID. + * @param fwid_len Length of the firmware ID, at most @c + * CONFIG_BT_MESH_DFU_FWID_MAXLEN. * @param metadata Metadata or NULL. * @param metadata_len Length of the metadata, at most @c * CONFIG_BT_MESH_DFU_METADATA_MAXLEN. + * @param uri Image URI or NULL. + * @param uri_len Length of the image URI, at most @c + * CONFIG_BT_MESH_DFU_URI_MAXLEN. * - * @return 0 on success, (negative) error code otherwise. + * @return A pointer to the allocated slot, or NULL if allocation failed. */ -int bt_mesh_dfu_slot_info_set(struct bt_mesh_dfu_slot *dfu_slot, size_t size, - const uint8_t *metadata, size_t metadata_len); +const struct bt_mesh_dfu_slot * +bt_mesh_dfu_slot_add(size_t size, const uint8_t *fwid, size_t fwid_len, + const uint8_t *metadata, size_t metadata_len, + const char *uri, size_t uri_len); -/** @brief Set the new fwid for the incoming image for a reserved slot. +/** @brief Set whether the given slot is valid. * - * @param dfu_slot Pointer to the reserved slot for which to set the fwid. - * @param fwid Fwid to set. - * @param fwid_len Length of the fwid, at most @c - * CONFIG_BT_MESH_DFU_FWID_MAXLEN. + * @param slot Allocated DFU image slot. + * @param valid New valid state of the slot. * - * @return 0 on success, (negative) error code otherwise. + * @return 0 on success, or (negative) error code on failure. */ -int bt_mesh_dfu_slot_fwid_set(struct bt_mesh_dfu_slot *dfu_slot, - const uint8_t *fwid, size_t fwid_len); +int bt_mesh_dfu_slot_valid_set(const struct bt_mesh_dfu_slot *slot, bool valid); -/** @brief Commit the reserved slot to the list of slots, and store it - * persistently. - * - * If the commit fails for any reason, the slot will still be in the reserved - * state after this call. - * - * @param dfu_slot Pointer to the reserved slot. +/** @brief Check whether a slot is valid. * - * @return 0 on success, (negative) error code otherwise. - */ -int bt_mesh_dfu_slot_commit(struct bt_mesh_dfu_slot *dfu_slot); - -/** @brief Release a reserved slot so that it can be reserved again. + * @param slot Slot to check. * - * @param dfu_slot Pointer to the reserved slot. + * @return true if the slot is valid, false otherwise. */ -void bt_mesh_dfu_slot_release(const struct bt_mesh_dfu_slot *dfu_slot); +bool bt_mesh_dfu_slot_is_valid(const struct bt_mesh_dfu_slot *slot); -/** @brief Delete a committed DFU image slot. +/** @brief Delete an allocated DFU image slot. * * @param slot Slot to delete. Must be a valid pointer acquired from this * module. @@ -91,19 +72,18 @@ int bt_mesh_dfu_slot_del(const struct bt_mesh_dfu_slot *slot); * * @return 0 on success, or (negative) error code on failure. */ -void bt_mesh_dfu_slot_del_all(void); +int bt_mesh_dfu_slot_del_all(void); -/** @brief Get the DFU image slot at the given firmware image list index. +/** @brief Get the DFU image slot at the given index. * * @param idx DFU image slot index. * * @return The DFU image slot at the given index, or NULL if no slot exists with the * given index. */ -const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t img_idx); +const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t idx); -/** @brief Get the committed DFU image slot for the image with the given - * firmware ID. +/** @brief Get the DFU image slot for the image with the given firmware ID. * * @param fwid Firmware ID. * @param fwid_len Firmware ID length. @@ -111,15 +91,16 @@ const struct bt_mesh_dfu_slot *bt_mesh_dfu_slot_at(uint16_t img_idx); * * @return Slot index on success, or negative error code on failure. */ -int bt_mesh_dfu_slot_get(const uint8_t *fwid, size_t fwid_len, struct bt_mesh_dfu_slot **slot); +int bt_mesh_dfu_slot_get(const uint8_t *fwid, size_t fwid_len, + const struct bt_mesh_dfu_slot **slot); -/** @brief Get the index in the firmware image list for the given slot. +/** @brief Get the DFU image slot index of the given slot. * * @param slot Slot to find. * * @return Slot index on success, or negative error code on failure. */ -int bt_mesh_dfu_slot_img_idx_get(const struct bt_mesh_dfu_slot *slot); +int bt_mesh_dfu_slot_idx_get(const struct bt_mesh_dfu_slot *slot); /** @brief Iterate through all DFU image slots. * diff --git a/subsys/bluetooth/mesh/shell/dfd.c b/subsys/bluetooth/mesh/shell/dfd.c index b7daf42af1c..94d656f3689 100644 --- a/subsys/bluetooth/mesh/shell/dfd.c +++ b/subsys/bluetooth/mesh/shell/dfd.c @@ -43,7 +43,7 @@ static void print_fw_status(const struct shell *sh, enum bt_mesh_dfd_status stat uint16_t idx, const uint8_t *fwid, size_t fwid_len) { shell_fprintf(sh, SHELL_NORMAL, "{ \"status\": %d, \"slot_cnt\": %d, \"idx\": %d", - status, bt_mesh_dfu_slot_count(), idx); + status, bt_mesh_dfu_slot_foreach(NULL, NULL), idx); if (fwid) { shell_fprintf(sh, SHELL_NORMAL, ", \"fwid\": \""); for (size_t i = 0; i < fwid_len; i++) { @@ -325,9 +325,10 @@ static int cmd_dfd_fw_get(const struct shell *sh, size_t argc, char *argv[]) return -EINVAL; } - int idx = bt_mesh_dfu_slot_get(fwid, fwid_len, NULL); + const struct bt_mesh_dfu_slot *slot; + int idx = bt_mesh_dfu_slot_get(fwid, fwid_len, &slot); - if (idx >= 0) { + if (idx >= 0 && bt_mesh_dfu_slot_is_valid(slot)) { print_fw_status(sh, BT_MESH_DFD_SUCCESS, idx, fwid, fwid_len); } else { print_fw_status(sh, BT_MESH_DFD_ERR_FW_NOT_FOUND, 0xffff, fwid, fwid_len); @@ -348,7 +349,7 @@ static int cmd_dfd_fw_get_by_idx(const struct shell *sh, size_t argc, char *argv return err; } - if (slot) { + if (slot && bt_mesh_dfu_slot_is_valid(slot)) { print_fw_status(sh, BT_MESH_DFD_SUCCESS, idx, slot->fwid, slot->fwid_len); } else { print_fw_status(sh, BT_MESH_DFD_ERR_FW_NOT_FOUND, idx, NULL, 0); diff --git a/subsys/bluetooth/mesh/shell/dfu.c b/subsys/bluetooth/mesh/shell/dfu.c index 8d7fc96e014..71d27b158e4 100644 --- a/subsys/bluetooth/mesh/shell/dfu.c +++ b/subsys/bluetooth/mesh/shell/dfu.c @@ -375,12 +375,13 @@ static int cmd_dfu_metadata_encode(const struct shell *sh, size_t argc, char *ar static int cmd_dfu_slot_add(const struct shell *sh, size_t argc, char *argv[]) { - struct bt_mesh_dfu_slot *slot; + const struct bt_mesh_dfu_slot *slot; size_t size; uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN]; size_t fwid_len = 0; uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN]; size_t metadata_len = 0; + const char *uri = ""; int err = 0; size = shell_strtoul(argv[1], 0, &err); @@ -389,33 +390,32 @@ static int cmd_dfu_slot_add(const struct shell *sh, size_t argc, char *argv[]) return err; } - shell_print(sh, "Adding slot (size: %u)", size); - slot = bt_mesh_dfu_slot_reserve(); - - if (!slot) { - shell_print(sh, "Failed to reserve slot."); - return 0; + if (argc > 2) { + fwid_len = hex2bin(argv[2], strlen(argv[2]), fwid, + sizeof(fwid)); } - fwid_len = hex2bin(argv[2], strlen(argv[2]), fwid, - sizeof(fwid)); - bt_mesh_dfu_slot_fwid_set(slot, fwid, fwid_len); - if (argc > 3) { metadata_len = hex2bin(argv[3], strlen(argv[3]), metadata, sizeof(metadata)); } - bt_mesh_dfu_slot_info_set(slot, size, metadata, metadata_len); + if (argc > 4) { + uri = argv[4]; + } - err = bt_mesh_dfu_slot_commit(slot); - if (err) { - shell_print(sh, "Failed to commit slot: %d", err); - bt_mesh_dfu_slot_release(slot); - return err; + shell_print(sh, "Adding slot (size: %u)", size); + + slot = bt_mesh_dfu_slot_add(size, fwid, fwid_len, metadata, + metadata_len, uri, strlen(uri)); + if (!slot) { + shell_print(sh, "Failed."); + return 0; } - shell_print(sh, "Slot added. Index: %u", bt_mesh_dfu_slot_img_idx_get(slot)); + bt_mesh_dfu_slot_valid_set(slot, true); + + shell_print(sh, "Slot added. ID: %u", bt_mesh_dfu_slot_idx_get(slot)); return 0; } @@ -451,7 +451,14 @@ static int cmd_dfu_slot_del(const struct shell *sh, size_t argc, char *argv[]) static int cmd_dfu_slot_del_all(const struct shell *sh, size_t argc, char *argv[]) { - bt_mesh_dfu_slot_del_all(); + int err; + + err = bt_mesh_dfu_slot_del_all(); + if (err) { + shell_print(sh, "Failed deleting all slots (err: %d)", err); + return 0; + } + shell_print(sh, "All slots deleted."); return 0; } @@ -461,6 +468,7 @@ static void slot_info_print(const struct shell *sh, const struct bt_mesh_dfu_slo { char fwid[2 * CONFIG_BT_MESH_DFU_FWID_MAXLEN + 1]; char metadata[2 * CONFIG_BT_MESH_DFU_METADATA_MAXLEN + 1]; + char uri[CONFIG_BT_MESH_DFU_URI_MAXLEN + 1]; size_t len; len = bin2hex(slot->fwid, slot->fwid_len, fwid, sizeof(fwid)); @@ -468,6 +476,8 @@ static void slot_info_print(const struct shell *sh, const struct bt_mesh_dfu_slo len = bin2hex(slot->metadata, slot->metadata_len, metadata, sizeof(metadata)); metadata[len] = '\0'; + memcpy(uri, slot->uri, slot->uri_len); + uri[slot->uri_len] = '\0'; if (idx != NULL) { shell_print(sh, "Slot %u:", *idx); @@ -477,6 +487,7 @@ static void slot_info_print(const struct shell *sh, const struct bt_mesh_dfu_slo shell_print(sh, "\tSize: %u bytes", slot->size); shell_print(sh, "\tFWID: %s", fwid); shell_print(sh, "\tMetadata: %s", metadata); + shell_print(sh, "\tURI: %s", uri); } static int cmd_dfu_slot_get(const struct shell *sh, size_t argc, char *argv[]) @@ -959,8 +970,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_STATIC_SUBCMD_SET_CREATE( dfu_slot_cmds, SHELL_CMD_ARG(add, NULL, - " []", - cmd_dfu_slot_add, 3, 1), + " [ [ []]]", + cmd_dfu_slot_add, 2, 3), SHELL_CMD_ARG(del, NULL, "", cmd_dfu_slot_del, 2, 0), SHELL_CMD_ARG(del-all, NULL, NULL, cmd_dfu_slot_del_all, 1, 0), SHELL_CMD_ARG(get, NULL, "", cmd_dfu_slot_get, 2, 0), diff --git a/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf b/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf index 2e08329b7ef..e870e190481 100644 --- a/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf +++ b/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf @@ -58,8 +58,7 @@ CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y CONFIG_BT_MESH_DFU_SRV=y CONFIG_BT_MESH_DFU_CLI=y CONFIG_BT_MESH_DFD_SRV=y -CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD=y -CONFIG_BT_MESH_DFU_SLOT_CNT=4 +CONFIG_BT_MESH_DFU_SLOT_CNT=3 CONFIG_BT_MESH_PRIV_BEACON_SRV=y CONFIG_BT_MESH_PRIV_BEACON_CLI=y CONFIG_BT_MESH_COMP_PAGE_1=y diff --git a/tests/bsim/bluetooth/mesh/src/test_dfu.c b/tests/bsim/bluetooth/mesh/src/test_dfu.c index a235e86eeec..f7c4ca6f4f0 100644 --- a/tests/bsim/bluetooth/mesh/src/test_dfu.c +++ b/tests/bsim/bluetooth/mesh/src/test_dfu.c @@ -434,50 +434,25 @@ static void target_prov_and_conf_default(void) target_prov_and_conf(addr, bind_params, ARRAY_SIZE(bind_params)); } -static struct bt_mesh_dfu_slot *slot_reserve_and_set(size_t size, uint8_t *fwid, size_t fwid_len, - uint8_t *metadata, size_t metadata_len) -{ - struct bt_mesh_dfu_slot *new_slot = bt_mesh_dfu_slot_reserve(); - - if (!new_slot) { - LOG_WRN("Reserving slot failed"); - return NULL; - } - - int err = bt_mesh_dfu_slot_fwid_set(new_slot, fwid, fwid_len); - - if (err) { - return NULL; - } - - err = bt_mesh_dfu_slot_info_set(new_slot, size, metadata, metadata_len); - - if (err) { - return NULL; - } - - return new_slot; -} - static bool slot_add(const struct bt_mesh_dfu_slot **slot) { - struct bt_mesh_dfu_slot *new_slot; + const struct bt_mesh_dfu_slot *new_slot; size_t size = 100; uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0xAA, 0xBB, 0xCC, 0xDD }; size_t fwid_len = 4; uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0xAA, 0xBB, 0xCC, 0xDD }; size_t metadata_len = 4; + const char *uri = ""; ASSERT_EQUAL(sizeof(target_fw_ver_new), fwid_len); - new_slot = slot_reserve_and_set(size, fwid, fwid_len, metadata, metadata_len); + new_slot = bt_mesh_dfu_slot_add(size, fwid, fwid_len, metadata, metadata_len, uri, + strlen(uri)); if (!new_slot) { return false; } - if (bt_mesh_dfu_slot_commit(new_slot) != 0) { - return false; - } + bt_mesh_dfu_slot_valid_set(new_slot, true); if (slot) { *slot = new_slot; @@ -593,12 +568,13 @@ static void test_dist_dfu_self_update(void) static void test_dist_dfu_slot_create(void) { - struct bt_mesh_dfu_slot *slot[CONFIG_BT_MESH_DFU_SLOT_CNT]; + const struct bt_mesh_dfu_slot *slot[3]; size_t size = 100; uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0 }; size_t fwid_len = 4; uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0 }; size_t metadata_len = 4; + const char *uri = "test"; int err, i; ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3, @@ -608,26 +584,36 @@ static void test_dist_dfu_slot_create(void) bt_mesh_device_setup(&prov, &dist_comp); dist_prov_and_conf(DIST_ADDR); - for (i = 0; i < CONFIG_BT_MESH_DFU_SLOT_CNT; i++) { + for (i = CONFIG_BT_MESH_DFU_SLOT_CNT - 1; i >= 0; i--) { fwid[0] = i; metadata[0] = i; - slot[i] = slot_reserve_and_set(size, fwid, fwid_len, metadata, metadata_len); + slot[i] = bt_mesh_dfu_slot_add(size, fwid, fwid_len, metadata, metadata_len, uri, + strlen(uri)); ASSERT_FALSE(slot[i] == NULL, "Failed to add slot"); + } - if (i > 0) { - /* All but first slot are committed */ - err = bt_mesh_dfu_slot_commit(slot[i]); - if (err) { - FAIL("Committing slot failed (err %d)", err); - } - } + /* First slot is set as valid */ + err = bt_mesh_dfu_slot_valid_set(slot[0], true); + if (err) { + FAIL("Setting slot to valid state failed (err %d)", err); + return; + } + ASSERT_TRUE(bt_mesh_dfu_slot_is_valid(slot[0])); + + /* Second slot is set as invalid */ + err = bt_mesh_dfu_slot_valid_set(slot[1], false); + if (err) { + FAIL("Setting slot to invalid state failed (err %d)", err); + return; } + ASSERT_TRUE(!bt_mesh_dfu_slot_is_valid(slot[1])); - /* Second slot is deleted */ - err = bt_mesh_dfu_slot_del(slot[1]); + /* Last slot is deleted */ + err = bt_mesh_dfu_slot_del(slot[CONFIG_BT_MESH_DFU_SLOT_CNT - 1]); if (err) { FAIL("Slot delete failed (err %d)", err); + return; } PASS(); @@ -640,17 +626,20 @@ enum bt_mesh_dfu_iter check_slot(const struct bt_mesh_dfu_slot *slot, void *data size_t fwid_len = 4; uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0 }; size_t metadata_len = 4; - int idx = bt_mesh_dfu_slot_img_idx_get(slot); - int *i = data; + const char *uri = "test"; + int idx = bt_mesh_dfu_slot_idx_get(slot); + + ASSERT_TRUE(idx >= 0, "Failed to retrieve slot index"); - ASSERT_EQUAL(idx, (*i)++); ASSERT_EQUAL(size, slot->size); + ASSERT_TRUE(strcmp(uri, slot->uri) == 0); + + fwid[0] = idx; - fwid[0] = idx + 2; ASSERT_EQUAL(fwid_len, slot->fwid_len); ASSERT_TRUE(memcmp(fwid, slot->fwid, fwid_len) == 0); - metadata[0] = idx + 2; + metadata[0] = idx; ASSERT_EQUAL(metadata_len, slot->metadata_len); ASSERT_TRUE(memcmp(metadata, slot->metadata, metadata_len) == 0); @@ -660,12 +649,13 @@ enum bt_mesh_dfu_iter check_slot(const struct bt_mesh_dfu_slot *slot, void *data static void test_dist_dfu_slot_create_recover(void) { size_t slot_count; - struct bt_mesh_dfu_slot *slot; + const struct bt_mesh_dfu_slot *slot; size_t size = 100; uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0 }; size_t fwid_len = 4; uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0 }; size_t metadata_len = 4; + const char *uri = "test"; int i, idx; ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3, @@ -674,17 +664,26 @@ static void test_dist_dfu_slot_create_recover(void) bt_mesh_test_cfg_set(NULL, WAIT_TIME); bt_mesh_device_setup(&prov, &dist_comp); - i = 0; - slot_count = bt_mesh_dfu_slot_foreach(check_slot, &i); - ASSERT_EQUAL(CONFIG_BT_MESH_DFU_SLOT_CNT - 2, slot_count); + slot_count = bt_mesh_dfu_slot_foreach(check_slot, NULL); + ASSERT_EQUAL(CONFIG_BT_MESH_DFU_SLOT_CNT - 1, slot_count); + + slot = bt_mesh_dfu_slot_at(0); + ASSERT_EQUAL(true, bt_mesh_dfu_slot_is_valid(slot)); - for (i = 2; i < CONFIG_BT_MESH_DFU_SLOT_CNT; i++) { + slot = bt_mesh_dfu_slot_at(1); + ASSERT_TRUE(slot != NULL); + ASSERT_EQUAL(false, bt_mesh_dfu_slot_is_valid(slot)); + + for (i = 0; i < (CONFIG_BT_MESH_DFU_SLOT_CNT - 1); i++) { fwid[0] = i; idx = bt_mesh_dfu_slot_get(fwid, fwid_len, &slot); - ASSERT_EQUAL(idx, i - 2); + ASSERT_TRUE(idx >= 0); + ASSERT_EQUAL(idx, bt_mesh_dfu_slot_idx_get(slot)); + ASSERT_EQUAL(size, slot->size); + ASSERT_TRUE(strcmp(uri, slot->uri) == 0); - metadata[0] = i; + metadata[0] = idx; ASSERT_EQUAL(metadata_len, slot->metadata_len); ASSERT_TRUE(memcmp(metadata, slot->metadata, metadata_len) == 0); } @@ -694,7 +693,7 @@ static void test_dist_dfu_slot_create_recover(void) static void check_delete_all(void) { - int i; + int i, idx, err; const struct bt_mesh_dfu_slot *slot; size_t slot_count; @@ -707,6 +706,14 @@ static void check_delete_all(void) for (i = 0; i < CONFIG_BT_MESH_DFU_SLOT_CNT - 1; i++) { slot = bt_mesh_dfu_slot_at(i); ASSERT_TRUE(slot == NULL); + + idx = bt_mesh_dfu_slot_idx_get(slot); + ASSERT_TRUE(idx < 0); + + err = bt_mesh_dfu_slot_valid_set(slot, true); + ASSERT_EQUAL(err, -ENOENT); + + ASSERT_TRUE(!bt_mesh_dfu_slot_is_valid(slot)); } } @@ -719,6 +726,7 @@ static void test_dist_dfu_slot_delete_all(void) bt_mesh_device_setup(&prov, &dist_comp); bt_mesh_dfu_slot_del_all(); + check_delete_all(); PASS(); @@ -734,63 +742,6 @@ static void test_dist_dfu_slot_check_delete_all(void) PASS(); } -static void test_dist_dfu_slot_reservation(void) -{ - int i; - struct bt_mesh_dfu_slot *slots[CONFIG_BT_MESH_DFU_SLOT_CNT]; - - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &dist_comp); - - for (i = 0; i < CONFIG_BT_MESH_DFU_SLOT_CNT; i++) { - slots[i] = bt_mesh_dfu_slot_reserve(); - ASSERT_TRUE(slots[i] != NULL); - } - - ASSERT_EQUAL(NULL, bt_mesh_dfu_slot_reserve()); - bt_mesh_dfu_slot_release(slots[0]); - /* Release twice to check idempotency with empty pool */ - bt_mesh_dfu_slot_release(slots[0]); - ASSERT_TRUE(bt_mesh_dfu_slot_reserve() != NULL); - ASSERT_EQUAL(NULL, bt_mesh_dfu_slot_reserve()); - - PASS(); -} - -static void test_dist_dfu_slot_idempotency(void) -{ - uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0 }; - size_t fwid_len = 4; - struct bt_mesh_dfu_slot *slot; - - ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 1, - "CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 1"); - - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &dist_comp); - dist_prov_and_conf(DIST_ADDR); - - slot = bt_mesh_dfu_slot_reserve(); - ASSERT_TRUE(slot != NULL); - - bt_mesh_dfu_slot_release(slot); - bt_mesh_dfu_slot_release(slot); - - slot = bt_mesh_dfu_slot_reserve(); - ASSERT_TRUE(slot != NULL); - - ASSERT_EQUAL(0, bt_mesh_dfu_slot_fwid_set(slot, fwid, fwid_len)); - ASSERT_EQUAL(0, bt_mesh_dfu_slot_info_set(slot, 100, NULL, 0)); - - ASSERT_EQUAL(0, bt_mesh_dfu_slot_commit(slot)); - ASSERT_EQUAL(-EINVAL, bt_mesh_dfu_slot_commit(slot)); - - ASSERT_EQUAL(0, bt_mesh_dfu_slot_del(slot)); - ASSERT_EQUAL(-EINVAL, bt_mesh_dfu_slot_del(slot)); - - PASS(); -} - static void target_test_effect(enum bt_mesh_dfu_effect effect) { dfu_target_effect = effect; @@ -970,14 +921,12 @@ static void cli_common_fail_on_init(void) static void cli_common_init_recover(void) { - struct bt_mesh_dfu_slot *slot; - uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0xAA, 0xBB, 0xCC, 0xDD }; - size_t fwid_len = 4; + const struct bt_mesh_dfu_slot *slot; bt_mesh_test_cfg_set(NULL, 300); bt_mesh_device_setup(&prov, &cli_comp); - ASSERT_TRUE(bt_mesh_dfu_slot_get(fwid, fwid_len, &slot) >= 0); + ASSERT_TRUE(slot_add(&slot)); dfu_cli_inputs_prepare(0); dfu_cli_xfer.xfer.mode = BT_MESH_BLOB_XFER_MODE_PUSH; @@ -1646,10 +1595,6 @@ static const struct bst_test_instance test_dfu[] = { TEST_CASE(dist, dfu_slot_delete_all, "Distributor deletes all image slots"), TEST_CASE(dist, dfu_slot_check_delete_all, "Distributor checks if all slots are removed from persistent storage"), - TEST_CASE(dist, dfu_slot_reservation, - "Distributor checks that the correct number of slots can be reserved"), - TEST_CASE(dist, dfu_slot_idempotency, - "Distributor checks that the the DFU slot APIs are idempotent"), TEST_CASE(cli, stop, "DFU Client stops at configured point of Firmware Distribution"), TEST_CASE(cli, fail_on_persistency, "DFU Client doesn't give up DFU Transfer"), TEST_CASE(cli, all_targets_lost_on_metadata, diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh deleted file mode 100755 index 3f18f1a2651..00000000000 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test DFU Slot API. This test tests that the APIs are idempotent. -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest dfu_slot_idempotency dfu_dist_dfu_slot_idempotency - -conf=prj_mesh1d1_conf -overlay="overlay_pst_conf_overlay_psa_conf" -RunTest dfu_slot_idempotency_psa dfu_dist_dfu_slot_idempotency diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh deleted file mode 100755 index ddd7d0123f5..00000000000 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test DFU Slot API. This test tests slot reservation APIs. -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest dfu_slot_reservation dfu_dist_dfu_slot_reservation - -conf=prj_mesh1d1_conf -overlay="overlay_pst_conf_overlay_psa_conf" -RunTest dfu_slot_reservation_psa dfu_dist_dfu_slot_reservation From a06eaede9acd272c40c09aac4d06378d3da7be25 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:28 +0000 Subject: [PATCH 0800/1623] Revert "[nrf fromtree] Bluetooth: Mesh: add optional OOB info to ext scan report" This reverts commit 96ac408fa71a6310e2a7565377854c1886cf5e42. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/rpr_srv.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/mesh/rpr_srv.c b/subsys/bluetooth/mesh/rpr_srv.c index c8639d8b514..b38bec4cd40 100644 --- a/subsys/bluetooth/mesh/rpr_srv.c +++ b/subsys/bluetooth/mesh/rpr_srv.c @@ -267,15 +267,13 @@ static void scan_ext_report_send(void) bt_mesh_model_msg_init(&buf, RPR_OP_EXTENDED_SCAN_REPORT); net_buf_simple_add_u8(&buf, BT_MESH_RPR_SUCCESS); net_buf_simple_add_mem(&buf, srv.scan.dev->uuid, 16); - - if (srv.scan.dev->flags & BT_MESH_RPR_UNPROV_FOUND) { - net_buf_simple_add_le16(&buf, srv.scan.dev->oob); - } else { + if (!(srv.scan.dev->flags & BT_MESH_RPR_UNPROV_FOUND)) { LOG_DBG("not found"); goto send; } if (srv.scan.dev->flags & BT_MESH_RPR_UNPROV_EXT_ADV_RXD) { + net_buf_simple_add_le16(&buf, srv.scan.dev->oob); net_buf_simple_add_mem(&buf, srv.scan.adv_data->data, srv.scan.adv_data->len); LOG_DBG("adv data: %s", From 0ca394e9e2e1fb5f02df02c14395f801501bfceb Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:28 +0000 Subject: [PATCH 0801/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Store priv proxy in sep entry" This reverts commit fbbfa43fae8509eef87eb3151281c3f10ed6265a. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/cfg.c | 15 ++++-- subsys/bluetooth/mesh/od_priv_proxy.h | 7 --- subsys/bluetooth/mesh/od_priv_proxy_srv.c | 65 ----------------------- 3 files changed, 12 insertions(+), 75 deletions(-) delete mode 100644 subsys/bluetooth/mesh/od_priv_proxy.h diff --git a/subsys/bluetooth/mesh/cfg.c b/subsys/bluetooth/mesh/cfg.c index c7bea0d29b0..4a59f76bbbd 100644 --- a/subsys/bluetooth/mesh/cfg.c +++ b/subsys/bluetooth/mesh/cfg.c @@ -16,7 +16,6 @@ #include "friend.h" #include "adv.h" #include "cfg.h" -#include "od_priv_proxy.h" #include "priv_beacon.h" #define LOG_LEVEL CONFIG_BT_MESH_CFG_LOG_LEVEL @@ -32,6 +31,9 @@ struct cfg_val { uint8_t gatt_proxy; uint8_t frnd; uint8_t default_ttl; +#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) + uint8_t on_demand_state; +#endif }; void bt_mesh_beacon_set(bool beacon) @@ -155,9 +157,9 @@ int bt_mesh_od_priv_proxy_set(uint8_t on_demand_proxy) bt_mesh.on_demand_state = on_demand_proxy; } - if (IS_ENABLED(CONFIG_BT_SETTINGS) && IS_ENABLED(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) && + if (IS_ENABLED(CONFIG_BT_SETTINGS) && atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) { - bt_mesh_od_priv_proxy_srv_store_schedule(); + bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_CFG_PENDING); } return 0; #endif @@ -447,6 +449,9 @@ static int cfg_set(const char *name, size_t len_rd, bt_mesh_gatt_proxy_set(cfg.gatt_proxy); bt_mesh_friend_set(cfg.frnd); bt_mesh_default_ttl_set(cfg.default_ttl); +#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) + bt_mesh_od_priv_proxy_set(cfg.on_demand_state); +#endif LOG_DBG("Restored configuration state"); @@ -479,6 +484,10 @@ static void store_pending_cfg(void) val.gatt_proxy = bt_mesh_gatt_proxy_get(); val.frnd = bt_mesh_friend_get(); val.default_ttl = bt_mesh_default_ttl_get(); +#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) + val.on_demand_state = bt_mesh_od_priv_proxy_get(); +#endif + err = settings_save_one("bt/mesh/Cfg", &val, sizeof(val)); if (err) { diff --git a/subsys/bluetooth/mesh/od_priv_proxy.h b/subsys/bluetooth/mesh/od_priv_proxy.h deleted file mode 100644 index 7baa7f067fc..00000000000 --- a/subsys/bluetooth/mesh/od_priv_proxy.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -void bt_mesh_od_priv_proxy_srv_store_schedule(void); diff --git a/subsys/bluetooth/mesh/od_priv_proxy_srv.c b/subsys/bluetooth/mesh/od_priv_proxy_srv.c index b18a8ec7530..32f5ea44179 100644 --- a/subsys/bluetooth/mesh/od_priv_proxy_srv.c +++ b/subsys/bluetooth/mesh/od_priv_proxy_srv.c @@ -9,28 +9,11 @@ #include "access.h" #include "cfg.h" #include "foundation.h" -#include "settings.h" #define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL #include LOG_MODULE_REGISTER(bt_mesh_od_priv_proxy_srv); - -static struct bt_mesh_model *od_priv_proxy_srv; -static uint8_t on_demand_state; - -static int od_priv_proxy_store(bool delete) -{ - if (!IS_ENABLED(CONFIG_BT_SETTINGS)) { - return 0; - } - - const void *data = delete ? NULL : &on_demand_state; - size_t len = delete ? 0 : sizeof(uint8_t); - - return bt_mesh_model_data_store(od_priv_proxy_srv, false, "pp", data, len); -} - static int proxy_status_rsp(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx) { @@ -81,8 +64,6 @@ const struct bt_mesh_model_op _bt_mesh_od_priv_proxy_srv_op[] = { static int od_priv_proxy_srv_init(struct bt_mesh_model *mod) { - od_priv_proxy_srv = mod; - struct bt_mesh_model *priv_beacon_srv = bt_mesh_model_find( bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_PRIV_BEACON_SRV); struct bt_mesh_model *sol_pdu_rpl_srv = bt_mesh_model_find( @@ -108,52 +89,6 @@ static int od_priv_proxy_srv_init(struct bt_mesh_model *mod) return 0; } -static void od_priv_proxy_srv_reset(struct bt_mesh_model *model) -{ - on_demand_state = 0; - od_priv_proxy_store(true); -} - -#ifdef CONFIG_BT_SETTINGS -static int od_priv_proxy_srv_settings_set(struct bt_mesh_model *model, const char *name, - size_t len_rd, settings_read_cb read_cb, void *cb_data) -{ - int err; - - if (len_rd == 0) { - LOG_DBG("Cleared configuration state"); - return 0; - } - - err = bt_mesh_settings_set(read_cb, cb_data, &on_demand_state, sizeof(uint8_t)); - if (err) { - LOG_ERR("Failed to set OD private proxy state"); - return err; - } - - bt_mesh_od_priv_proxy_set(on_demand_state); - return 0; -} - -static void od_priv_proxy_srv_pending_store(struct bt_mesh_model *model) -{ - on_demand_state = bt_mesh_od_priv_proxy_get(); - od_priv_proxy_store(false); -} -#endif - const struct bt_mesh_model_cb _bt_mesh_od_priv_proxy_srv_cb = { .init = od_priv_proxy_srv_init, - .reset = od_priv_proxy_srv_reset, -#ifdef CONFIG_BT_SETTINGS - .settings_set = od_priv_proxy_srv_settings_set, - .pending_store = od_priv_proxy_srv_pending_store, -#endif }; - -void bt_mesh_od_priv_proxy_srv_store_schedule(void) -{ - if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - bt_mesh_model_data_store_schedule(od_priv_proxy_srv); - } -} From e614cbab4386b870a20bc3b497212ed01a1eb94a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:28 +0000 Subject: [PATCH 0802/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Store priv beacon in sep entry" This reverts commit 6e082b4141d1dc295dbf9359cacb342fba06aa9f. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/cfg.c | 27 +++++++-- subsys/bluetooth/mesh/priv_beacon.h | 7 --- subsys/bluetooth/mesh/priv_beacon_srv.c | 74 ------------------------- 3 files changed, 21 insertions(+), 87 deletions(-) delete mode 100644 subsys/bluetooth/mesh/priv_beacon.h diff --git a/subsys/bluetooth/mesh/cfg.c b/subsys/bluetooth/mesh/cfg.c index 4a59f76bbbd..287023afa68 100644 --- a/subsys/bluetooth/mesh/cfg.c +++ b/subsys/bluetooth/mesh/cfg.c @@ -16,7 +16,6 @@ #include "friend.h" #include "adv.h" #include "cfg.h" -#include "priv_beacon.h" #define LOG_LEVEL CONFIG_BT_MESH_CFG_LOG_LEVEL #include @@ -31,6 +30,11 @@ struct cfg_val { uint8_t gatt_proxy; uint8_t frnd; uint8_t default_ttl; +#if defined(CONFIG_BT_MESH_PRIV_BEACONS) + uint8_t priv_beacon; + uint8_t priv_beacon_int; + uint8_t priv_gatt_proxy; +#endif #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) uint8_t on_demand_state; #endif @@ -105,9 +109,9 @@ int bt_mesh_priv_beacon_set(enum bt_mesh_feat_state priv_beacon) /* Beacon timer will stop automatically when all beacons are disabled. */ } - if (IS_ENABLED(CONFIG_BT_SETTINGS) && IS_ENABLED(CONFIG_BT_MESH_PRIV_BEACON_SRV) && + if (IS_ENABLED(CONFIG_BT_SETTINGS) && atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) { - bt_mesh_priv_beacon_srv_store_schedule(); + bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_CFG_PENDING); } return 0; @@ -240,9 +244,9 @@ int bt_mesh_priv_gatt_proxy_set(enum bt_mesh_feat_state priv_gatt_proxy) bt_mesh_adv_gatt_update(); } - if (IS_ENABLED(CONFIG_BT_SETTINGS) && IS_ENABLED(CONFIG_BT_MESH_PRIV_BEACON_SRV) && + if (IS_ENABLED(CONFIG_BT_SETTINGS) && atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) { - bt_mesh_priv_beacon_srv_store_schedule(); + bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_CFG_PENDING); } return 0; @@ -257,6 +261,7 @@ enum bt_mesh_feat_state bt_mesh_priv_gatt_proxy_get(void) return feature_get(BT_MESH_PRIV_GATT_PROXY); } + int bt_mesh_default_ttl_set(uint8_t default_ttl) { if (default_ttl == 1 || default_ttl > BT_MESH_TTL_MAX) { @@ -449,6 +454,11 @@ static int cfg_set(const char *name, size_t len_rd, bt_mesh_gatt_proxy_set(cfg.gatt_proxy); bt_mesh_friend_set(cfg.frnd); bt_mesh_default_ttl_set(cfg.default_ttl); +#if defined(CONFIG_BT_MESH_PRIV_BEACONS) + bt_mesh_priv_beacon_set(cfg.priv_beacon); + bt_mesh_priv_beacon_update_interval_set(cfg.priv_beacon_int); + bt_mesh_priv_gatt_proxy_set(cfg.priv_gatt_proxy); +#endif #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) bt_mesh_od_priv_proxy_set(cfg.on_demand_state); #endif @@ -466,7 +476,7 @@ static void clear_cfg(void) err = settings_delete("bt/mesh/Cfg"); if (err) { - LOG_ERR("Failed to clear configuration (err: %d)", err); + LOG_ERR("Failed to clear configuration"); } else { LOG_DBG("Cleared configuration"); } @@ -484,6 +494,11 @@ static void store_pending_cfg(void) val.gatt_proxy = bt_mesh_gatt_proxy_get(); val.frnd = bt_mesh_friend_get(); val.default_ttl = bt_mesh_default_ttl_get(); +#if defined(CONFIG_BT_MESH_PRIV_BEACONS) + val.priv_beacon = bt_mesh_priv_beacon_get(); + val.priv_beacon_int = bt_mesh_priv_beacon_update_interval_get(); + val.priv_gatt_proxy = bt_mesh_priv_gatt_proxy_get(); +#endif #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) val.on_demand_state = bt_mesh_od_priv_proxy_get(); #endif diff --git a/subsys/bluetooth/mesh/priv_beacon.h b/subsys/bluetooth/mesh/priv_beacon.h deleted file mode 100644 index 0cbbdafd0b1..00000000000 --- a/subsys/bluetooth/mesh/priv_beacon.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -void bt_mesh_priv_beacon_srv_store_schedule(void); diff --git a/subsys/bluetooth/mesh/priv_beacon_srv.c b/subsys/bluetooth/mesh/priv_beacon_srv.c index 377703e8352..a1478efff80 100644 --- a/subsys/bluetooth/mesh/priv_beacon_srv.c +++ b/subsys/bluetooth/mesh/priv_beacon_srv.c @@ -11,33 +11,11 @@ #include "foundation.h" #include "beacon.h" #include "cfg.h" -#include "settings.h" #define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL #include LOG_MODULE_REGISTER(bt_mesh_priv_beacon_srv); -static struct bt_mesh_model *priv_beacon_srv; - -/* Private Beacon configuration server model states */ -struct { - uint8_t state; - uint8_t interval; - uint8_t proxy_state; -} priv_beacon_state; - -static int priv_beacon_store(bool delete) -{ - if (!IS_ENABLED(CONFIG_BT_SETTINGS)) { - return 0; - } - - const void *data = delete ? NULL : &priv_beacon_state; - size_t len = delete ? 0 : sizeof(priv_beacon_state); - - return bt_mesh_model_data_store(priv_beacon_srv, false, "pb", data, len); -} - static int beacon_status_rsp(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx) { @@ -201,63 +179,11 @@ static int priv_beacon_srv_init(struct bt_mesh_model *mod) return -EINVAL; } - priv_beacon_srv = mod; mod->keys[0] = BT_MESH_KEY_DEV_LOCAL; return 0; } -static void priv_beacon_srv_reset(struct bt_mesh_model *model) -{ - (void)memset(&priv_beacon_state, 0, sizeof(priv_beacon_state)); - priv_beacon_store(true); -} - -#ifdef CONFIG_BT_SETTINGS -static int priv_beacon_srv_settings_set(struct bt_mesh_model *model, const char *name, - size_t len_rd, settings_read_cb read_cb, void *cb_data) -{ - int err; - - if (len_rd == 0) { - LOG_DBG("Cleared configuration state"); - return 0; - } - - err = bt_mesh_settings_set(read_cb, cb_data, &priv_beacon_state, sizeof(priv_beacon_state)); - if (err) { - LOG_ERR("Failed to set Private Beacon state"); - return err; - } - - bt_mesh_priv_beacon_set(priv_beacon_state.state); - bt_mesh_priv_beacon_update_interval_set(priv_beacon_state.interval); - bt_mesh_priv_gatt_proxy_set(priv_beacon_state.proxy_state); - return 0; -} - -static void priv_beacon_srv_pending_store(struct bt_mesh_model *model) -{ - priv_beacon_state.state = bt_mesh_priv_beacon_get(); - priv_beacon_state.interval = bt_mesh_priv_beacon_update_interval_get(); - priv_beacon_state.proxy_state = bt_mesh_priv_gatt_proxy_get(); - - priv_beacon_store(false); -} -#endif - const struct bt_mesh_model_cb bt_mesh_priv_beacon_srv_cb = { .init = priv_beacon_srv_init, - .reset = priv_beacon_srv_reset, -#ifdef CONFIG_BT_SETTINGS - .settings_set = priv_beacon_srv_settings_set, - .pending_store = priv_beacon_srv_pending_store, -#endif }; - -void bt_mesh_priv_beacon_srv_store_schedule(void) -{ - if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - bt_mesh_model_data_store_schedule(priv_beacon_srv); - } -} From f8a72033af25c5b402be60e19cc8567bdb3cb575 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:28 +0000 Subject: [PATCH 0803/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Fix Solicitation Mesh crypto API use" This reverts commit e99b89aedb7c7f2ece20244d5283d858b31ab29a. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/solicitation.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/solicitation.c b/subsys/bluetooth/mesh/solicitation.c index f6543dcb320..1bf9f9a465a 100644 --- a/subsys/bluetooth/mesh/solicitation.c +++ b/subsys/bluetooth/mesh/solicitation.c @@ -304,7 +304,7 @@ static int sol_pdu_create(struct bt_mesh_subnet *sub, struct net_buf_simple *pdu /* DST = 0x0000 */ net_buf_simple_add_le16(pdu, 0x0000); - err = bt_mesh_net_encrypt(&sub->keys[SUBNET_KEY_TX_IDX(sub)].msg.enc, + err = bt_mesh_net_encrypt(sub->keys[SUBNET_KEY_TX_IDX(sub)].msg.enc, pdu, 0, BT_MESH_NONCE_SOLICITATION); if (err) { @@ -313,7 +313,7 @@ static int sol_pdu_create(struct bt_mesh_subnet *sub, struct net_buf_simple *pdu } err = bt_mesh_net_obfuscate(pdu->data, 0, - &sub->keys[SUBNET_KEY_TX_IDX(sub)].msg.privacy); + sub->keys[SUBNET_KEY_TX_IDX(sub)].msg.privacy); if (err) { LOG_ERR("Obfuscation failed, err=%d", err); return err; From 9385973946cb212264ff48c7e9ed27daa02aa6e8 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:28 +0000 Subject: [PATCH 0804/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Shell support for comp data page2" This reverts commit c227d927cb85b7bf66c151063a15092a06a7850d. Signed-off-by: Dominik Ermel --- include/zephyr/bluetooth/mesh/cfg_cli.h | 34 -------------------- subsys/bluetooth/mesh/cfg_cli.c | 35 --------------------- subsys/bluetooth/mesh/shell/cfg.c | 42 ++----------------------- 3 files changed, 3 insertions(+), 108 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/cfg_cli.h b/include/zephyr/bluetooth/mesh/cfg_cli.h index d2221da38da..e6fd31d7c3a 100644 --- a/include/zephyr/bluetooth/mesh/cfg_cli.h +++ b/include/zephyr/bluetooth/mesh/cfg_cli.h @@ -1786,40 +1786,6 @@ struct bt_mesh_comp_p1_model_item *bt_mesh_comp_p1_item_pull( struct bt_mesh_comp_p1_ext_item *bt_mesh_comp_p1_pull_ext_item( struct bt_mesh_comp_p1_model_item *item, struct bt_mesh_comp_p1_ext_item *ext_item); -/** Composition data page 2 record parsing structure. */ -struct bt_mesh_comp_p2_record { - /** Mesh profile ID. */ - uint16_t id; - /** Mesh Profile Version. */ - struct { - /** Major version. */ - uint8_t x; - /** Minor version. */ - uint8_t y; - /** Z version. */ - uint8_t z; - } version; - /** Element offset buffer. */ - struct net_buf_simple *elem_buf; - /** Additional data buffer. */ - struct net_buf_simple *data_buf; -}; - -/** @brief Pull a Composition Data Page 2 Record from a composition data page 2 - * instance. - * - * Each call to this function will pull out a new element from the composition - * data page, until all elements have been pulled. - * - * @param buf Composition data page 2 buffer - * @param record Record to fill. - * - * @return A pointer to @c record on success, or NULL if no more elements could - * be pulled. - */ -struct bt_mesh_comp_p2_record *bt_mesh_comp_p2_record_pull(struct net_buf_simple *buf, - struct bt_mesh_comp_p2_record *record); - /** @brief Unpack a list of key index entries from a buffer. * * On success, @c dst_cnt is set to the amount of unpacked key index entries. diff --git a/subsys/bluetooth/mesh/cfg_cli.c b/subsys/bluetooth/mesh/cfg_cli.c index 68af4fae59d..a5ad80193f3 100644 --- a/subsys/bluetooth/mesh/cfg_cli.c +++ b/subsys/bluetooth/mesh/cfg_cli.c @@ -2443,38 +2443,3 @@ struct bt_mesh_comp_p1_ext_item *bt_mesh_comp_p1_pull_ext_item( } return ext_item; } - -struct bt_mesh_comp_p2_record *bt_mesh_comp_p2_record_pull(struct net_buf_simple *buf, - struct bt_mesh_comp_p2_record *record) -{ - if (buf->len < 8) { - LOG_DBG("No more elements to pull or missing data"); - return NULL; - } - - uint8_t elem_offset_cnt; - uint16_t data_len; - - record->id = net_buf_simple_pull_le16(buf); - record->version.x = net_buf_simple_pull_u8(buf); - record->version.y = net_buf_simple_pull_u8(buf); - record->version.z = net_buf_simple_pull_u8(buf); - elem_offset_cnt = net_buf_simple_pull_u8(buf); - if (buf->len < elem_offset_cnt + 2) { - LOG_WRN("Invalid composition data offset count"); - return NULL; - } - - net_buf_simple_init_with_data(record->elem_buf, - net_buf_simple_pull_mem(buf, elem_offset_cnt), - elem_offset_cnt); - data_len = net_buf_simple_pull_le16(buf); - if (buf->len < data_len) { - LOG_WRN("Invalid composition data additional data length"); - return NULL; - } - - net_buf_simple_init_with_data(record->data_buf, - net_buf_simple_pull_mem(buf, data_len), data_len); - return record; -} diff --git a/subsys/bluetooth/mesh/shell/cfg.c b/subsys/bluetooth/mesh/shell/cfg.c index c4a62a996e3..d47f04bcc00 100644 --- a/subsys/bluetooth/mesh/shell/cfg.c +++ b/subsys/bluetooth/mesh/shell/cfg.c @@ -98,10 +98,9 @@ static int cmd_get_comp(const struct shell *sh, size_t argc, char *argv[]) return 0; } - if (page != 0 && page != 128 && - ((page != 1 && page != 129) || !IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) && - ((page != 2 && page != 130) || !IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2))) { - shell_print(sh, "Got page %d. No parser available.", page); + if (page != 0 && page != 1 && page != 128 && page != 129) { + shell_print(sh, "Got page %d. No parser available.", + page); return 0; } @@ -255,41 +254,6 @@ static int cmd_get_comp(const struct shell *sh, size_t argc, char *argv[]) } } - if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && (page == 2 || page == 130)) { - /* size of 32 is chosen arbitrary, as sufficient for testing purposes */ - NET_BUF_SIMPLE_DEFINE(p2_elem_offset_buf, 32); - NET_BUF_SIMPLE_DEFINE(p2_data_buf, 32); - struct bt_mesh_comp_p2_record p2_elem = { - .elem_buf = &p2_elem_offset_buf, - .data_buf = &p2_data_buf - }; - - if (!buf.len) { - shell_error(sh, "Composition data empty"); - return 0; - } - shell_print(sh, "Got Composition Data for 0x%04x, page: %d:", - bt_mesh_shell_target_ctx.dst, page); - - while (bt_mesh_comp_p2_record_pull(&buf, &p2_elem)) { - - shell_print(sh, "\tMesh Profile id: %04x ", p2_elem.id); - shell_print(sh, "\t\tVersion: %d.%d.%d ", p2_elem.version.x, - p2_elem.version.y, p2_elem.version.z); - shell_print(sh, "\t\tElement offsets:"); - - while (p2_elem.elem_buf->len) { - shell_print(sh, "\t\t\t%d ", - net_buf_simple_pull_u8(p2_elem.elem_buf)); - } - - if (p2_elem.data_buf->len) { - shell_print(sh, "\t\t%d bytes of additional data is available", - p2_elem.data_buf->len); - } - } - } - if (buf.len) { shell_print(sh, "\t\t...truncated data!"); } From b3f7098d48a5d12db982a75b78777b1f72f88920 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:29 +0000 Subject: [PATCH 0805/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Support for comp data page 2" This reverts commit ced31ee9859ad299cf1a154124adef5bd9d25cda. Signed-off-by: Dominik Ermel --- include/zephyr/bluetooth/mesh/access.h | 45 ------------------ subsys/bluetooth/mesh/Kconfig | 5 -- subsys/bluetooth/mesh/access.c | 66 +------------------------- subsys/bluetooth/mesh/access.h | 1 + subsys/bluetooth/mesh/cfg_srv.c | 8 +--- 5 files changed, 4 insertions(+), 121 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/access.h b/include/zephyr/bluetooth/mesh/access.h index 5b1653c2487..f3b6c373128 100644 --- a/include/zephyr/bluetooth/mesh/access.h +++ b/include/zephyr/bluetooth/mesh/access.h @@ -1137,51 +1137,6 @@ struct bt_mesh_comp { struct bt_mesh_elem *elem; /**< List of elements. */ }; -/** Composition data page 2 record. */ -struct bt_mesh_comp2_record { - /** Mesh profile ID. */ - uint16_t id; - /** Mesh Profile Version. */ - struct { - /** Major version. */ - uint8_t x; - /** Minor version. */ - uint8_t y; - /** Z version. */ - uint8_t z; - } version; - /** Element offset count. */ - uint8_t elem_offset_cnt; - /** Element offset list. */ - const uint8_t *elem_offset; - /** Length of additional data. */ - uint16_t data_len; - /** Additional data. */ - const void *data; -}; - -/** Node Composition data page 2 */ -struct bt_mesh_comp2 { - /** The number of Mesh Profile records on a device. */ - size_t record_cnt; - /** List of records. */ - const struct bt_mesh_comp2_record *record; -}; - -/** @brief Register composition data page 2 of the device. - * - * Register Mesh Profiles information (Ref section 3.12 in - * Bluetooth SIG Assigned Numbers) for composition data - * page 2 of the device. - * - * @note There must be at least one record present in @c comp2 - * - * @param comp2 Pointer to composition data page 2. - * - * @return Zero on success or (negative) error code otherwise. - */ -int bt_mesh_comp2_register(const struct bt_mesh_comp2 *comp2); - #ifdef __cplusplus } #endif diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index b8e26309a28..9b0c4bd80f0 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1373,11 +1373,6 @@ config BT_MESH_COMP_PAGE_1 help Enable support for Composition Data Page 1. -config BT_MESH_COMP_PAGE_2 - bool "Support for Composition Data Page 2" - help - Enable support for Composition Data Page 2. - config BT_MESH_MODEL_EXTENSION_LIST_SIZE int "Model extensions list size" depends on BT_MESH_COMP_PAGE_1 diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index b6dab2d67a7..c022eedbadc 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -53,7 +53,6 @@ struct comp_foreach_model_arg { }; static const struct bt_mesh_comp *dev_comp; -static const struct bt_mesh_comp2 *dev_comp2; static uint16_t dev_primary_addr; static void (*msg_cb)(uint32_t opcode, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf); @@ -113,9 +112,6 @@ static const struct { #if IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) { "bt/mesh/cmp/1", 1, }, #endif -#if IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) - { "bt/mesh/cmp/2", 2, }, -#endif }; void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod, @@ -613,7 +609,7 @@ static size_t page1_elem_size(struct bt_mesh_elem *elem) return temp_size; } -static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf) +int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf) { const struct bt_mesh_comp *comp; uint8_t cor_id = 0; @@ -664,51 +660,6 @@ static int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf) return 0; } -static int bt_mesh_comp_data_get_page_2(struct net_buf_simple *buf) -{ - if (!dev_comp2) { - LOG_ERR("Composition data P2 not registered"); - return -ENODEV; - } - - for (int i = 0; i < dev_comp2->record_cnt; i++) { - if (net_buf_simple_tailroom(buf) < - (8 + dev_comp2->record[i].elem_offset_cnt + dev_comp2->record[i].data_len + - BT_MESH_MIC_SHORT)) { - if (IS_ENABLED(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)) { - /* Mesh Profile 1.1 Section 4.4.1.2.2: - * If the complete list of models does not fit in the Data field, - * the element shall not be reported. - */ - LOG_DBG("Record 0x%04x didn't fit in the Data field", - i); - return 0; - } - - LOG_ERR("Too large device composition"); - return -E2BIG; - } - - net_buf_simple_add_le16(buf, dev_comp2->record[i].id); - net_buf_simple_add_u8(buf, dev_comp2->record[i].version.x); - net_buf_simple_add_u8(buf, dev_comp2->record[i].version.y); - net_buf_simple_add_u8(buf, dev_comp2->record[i].version.z); - net_buf_simple_add_u8(buf, dev_comp2->record[i].elem_offset_cnt); - if (dev_comp2->record[i].elem_offset_cnt) { - net_buf_simple_add_mem(buf, dev_comp2->record[i].elem_offset, - dev_comp2->record[i].elem_offset_cnt); - } - - net_buf_simple_add_le16(buf, dev_comp2->record[i].data_len); - if (dev_comp2->record[i].data_len) { - net_buf_simple_add_mem(buf, dev_comp2->record[i].data, - dev_comp2->record[i].data_len); - } - } - - return 0; -} - int32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod) { int32_t period; @@ -1043,17 +994,6 @@ int bt_mesh_comp_register(const struct bt_mesh_comp *comp) return err; } -int bt_mesh_comp2_register(const struct bt_mesh_comp2 *comp2) -{ - if (!IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { - return -EINVAL; - } - - dev_comp2 = comp2; - - return 0; -} - void bt_mesh_comp_provision(uint16_t addr) { int i; @@ -2211,10 +2151,8 @@ int bt_mesh_comp_data_get_page(struct net_buf_simple *buf, size_t page, size_t o { if (page == 0 || page == 128) { return bt_mesh_comp_data_get_page_0(buf, offset); - } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && (page == 1 || page == 129)) { + } else if (page == 1 || page == 129) { return bt_mesh_comp_data_get_page_1(buf); - } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && (page == 2 || page == 130)) { - return bt_mesh_comp_data_get_page_2(buf); } return -EINVAL; diff --git a/subsys/bluetooth/mesh/access.h b/subsys/bluetooth/mesh/access.h index 4740963dd21..a7d3ffe5865 100644 --- a/subsys/bluetooth/mesh/access.h +++ b/subsys/bluetooth/mesh/access.h @@ -27,6 +27,7 @@ size_t bt_mesh_comp_page_0_size(void); int bt_mesh_comp_data_get_page_0(struct net_buf_simple *buf, size_t offset); size_t bt_mesh_metadata_page_0_size(void); int bt_mesh_metadata_get_page_0(struct net_buf_simple *buf, size_t offset); +int bt_mesh_comp_data_get_page_1(struct net_buf_simple *buf); /* Find local element based on unicast address */ struct bt_mesh_elem *bt_mesh_elem_find(uint16_t addr); diff --git a/subsys/bluetooth/mesh/cfg_srv.c b/subsys/bluetooth/mesh/cfg_srv.c index eb732a34910..2fba9360206 100644 --- a/subsys/bluetooth/mesh/cfg_srv.c +++ b/subsys/bluetooth/mesh/cfg_srv.c @@ -61,19 +61,13 @@ static int dev_comp_data_get(struct bt_mesh_model *model, page = net_buf_simple_pull_u8(buf); - if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 130U; - } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && + if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { page = 129U; } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { page = 128U; - } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { - page = 2U; } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { page = 1U; } else if (page != 0U) { From ac7ba6d459c268aafa5383187e45d85dc3bfcfde Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:29 +0000 Subject: [PATCH 0806/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Send od priv proxy with devkey" This reverts commit 915c64c22fc212ef2f5b25e62682179159ce97c5. Signed-off-by: Dominik Ermel --- include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h | 11 +++++------ subsys/bluetooth/mesh/od_priv_proxy_cli.c | 12 +++++------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h b/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h index f9734d78d3e..89e63c177a0 100644 --- a/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h +++ b/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h @@ -47,6 +47,7 @@ struct bt_mesh_od_priv_proxy_cli { _bt_mesh_od_priv_proxy_cli_op, NULL, cli_data, \ &_bt_mesh_od_priv_proxy_cli_cb) + /** @brief Get the target's On-Demand Private GATT Proxy state. * * This method can be used asynchronously by setting @p val_rsp as NULL. @@ -56,13 +57,12 @@ struct bt_mesh_od_priv_proxy_cli { * To process the response arguments of an async method, register * the @c od_status callback in @c bt_mesh_od_priv_proxy_cli struct. * - * @param net_idx Network index to encrypt with. - * @param addr Target node address. + * @param ctx Message context for the message. * @param val_rsp Response buffer for On-Demand Private GATT Proxy value. * * @return 0 on success, or (negative) error code otherwise. */ -int bt_mesh_od_priv_proxy_cli_get(uint16_t net_idx, uint16_t addr, uint8_t *val_rsp); +int bt_mesh_od_priv_proxy_cli_get(struct bt_mesh_msg_ctx *ctx, uint8_t *val_rsp); /** @brief Set the target's On-Demand Private GATT Proxy state. * @@ -73,14 +73,13 @@ int bt_mesh_od_priv_proxy_cli_get(uint16_t net_idx, uint16_t addr, uint8_t *val_ * To process the response arguments of an async method, register * the @c od_status callback in @c bt_mesh_od_priv_proxy_cli struct. * - * @param net_idx Network index to encrypt with. - * @param addr Target node address. + * @param ctx Message context for the message. * @param val On-Demand Private GATT Proxy state to be set * @param val_rsp Response buffer for On-Demand Private GATT Proxy value. * * @return 0 on success, or (negative) error code otherwise. */ -int bt_mesh_od_priv_proxy_cli_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *val_rsp); +int bt_mesh_od_priv_proxy_cli_set(struct bt_mesh_msg_ctx *ctx, uint8_t val, uint8_t *val_rsp); /** @brief Set the transmission timeout value. * diff --git a/subsys/bluetooth/mesh/od_priv_proxy_cli.c b/subsys/bluetooth/mesh/od_priv_proxy_cli.c index 67f5ac961ad..3dc8722ff72 100644 --- a/subsys/bluetooth/mesh/od_priv_proxy_cli.c +++ b/subsys/bluetooth/mesh/od_priv_proxy_cli.c @@ -54,25 +54,23 @@ const struct bt_mesh_model_op _bt_mesh_od_priv_proxy_cli_op[] = { BT_MESH_MODEL_OP_END }; -int bt_mesh_od_priv_proxy_cli_get(uint16_t net_idx, uint16_t addr, uint8_t *val_rsp) +int bt_mesh_od_priv_proxy_cli_get(struct bt_mesh_msg_ctx *ctx, uint8_t *val) { - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr); const struct bt_mesh_msg_rsp_ctx rsp = { .ack = &cli->ack_ctx, .op = OP_OD_PRIV_PROXY_STATUS, - .user_data = val_rsp, + .user_data = val, .timeout = msg_timeout, }; BT_MESH_MODEL_BUF_DEFINE(msg, OP_OD_PRIV_PROXY_GET, 0); bt_mesh_model_msg_init(&msg, OP_OD_PRIV_PROXY_GET); - return bt_mesh_msg_ackd_send(cli->model, &ctx, &msg, val_rsp ? &rsp : NULL); + return bt_mesh_msg_ackd_send(cli->model, ctx, &msg, val ? &rsp : NULL); } -int bt_mesh_od_priv_proxy_cli_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *val_rsp) +int bt_mesh_od_priv_proxy_cli_set(struct bt_mesh_msg_ctx *ctx, uint8_t val, uint8_t *val_rsp) { - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(net_idx, addr); const struct bt_mesh_msg_rsp_ctx rsp = { .ack = &cli->ack_ctx, .op = OP_OD_PRIV_PROXY_STATUS, @@ -85,7 +83,7 @@ int bt_mesh_od_priv_proxy_cli_set(uint16_t net_idx, uint16_t addr, uint8_t val, net_buf_simple_add_u8(&msg, val); - return bt_mesh_msg_ackd_send(cli->model, &ctx, &msg, val_rsp ? &rsp : NULL); + return bt_mesh_msg_ackd_send(cli->model, ctx, &msg, val_rsp ? &rsp : NULL); } void bt_mesh_od_priv_proxy_cli_timeout_set(int32_t timeout) From 831ae0e2a84194dee0e81f73a5d66209c81e0fdf Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:29 +0000 Subject: [PATCH 0807/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Fix Solicitation RPL PDU Server compilation" This reverts commit 4d987d3dcba621380f6714dd2cfa405dc78ad6fa. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/solicitation.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/solicitation.c b/subsys/bluetooth/mesh/solicitation.c index 1bf9f9a465a..3f639fbf0d6 100644 --- a/subsys/bluetooth/mesh/solicitation.c +++ b/subsys/bluetooth/mesh/solicitation.c @@ -153,12 +153,12 @@ static bool sol_pdu_decrypt(struct bt_mesh_subnet *sub, void *data) net_buf_simple_init(out, 0); net_buf_simple_add_mem(out, in->data, in->len); - err = bt_mesh_net_obfuscate(out->data, 0, &sub->keys[i].msg.privacy); + err = bt_mesh_net_obfuscate(out->data, 0, sub->keys[i].msg.privacy); if (err) { LOG_DBG("obfuscation err %d", err); continue; } - err = bt_mesh_net_decrypt(&sub->keys[i].msg.enc, out, + err = bt_mesh_net_decrypt(sub->keys[i].msg.enc, out, 0, BT_MESH_NONCE_SOLICITATION); if (!err) { LOG_DBG("Decrypted PDU %s", bt_hex(out->data, out->len)); From b11cd9257aa23884b6f83593e6b00b778e523373 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:30 +0000 Subject: [PATCH 0808/1623] Revert "[nrf fromtree] Bluetooth: Mesh: Fix Opcode Aggregator Server compilation" This reverts commit 079d1b105a61c46f7a8ffea881de673092a44b65. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/op_agg.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/subsys/bluetooth/mesh/op_agg.c b/subsys/bluetooth/mesh/op_agg.c index 1580c7f0847..4f6baacc898 100644 --- a/subsys/bluetooth/mesh/op_agg.c +++ b/subsys/bluetooth/mesh/op_agg.c @@ -17,7 +17,10 @@ LOG_MODULE_REGISTER(bt_mesh_op_agg); #define LENGTH_SHORT_MAX BIT_MASK(7) NET_BUF_SIMPLE_DEFINE_STATIC(sdu, BT_MESH_TX_SDU_MAX); + +#if IS_ENABLED(CONFIG_BT_MESH_OP_AGG_CLI) NET_BUF_SIMPLE_DEFINE_STATIC(srcs, BT_MESH_TX_SDU_MAX); +#endif static struct op_agg_ctx agg_ctx = { .sdu = &sdu, From c0e800a8ebde16448395f30cf521c3f8156bbf0e Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:31 +0000 Subject: [PATCH 0809/1623] Revert "[nrf fromtree] Bluetooth: att: don't re-use the ATT buffer for confirmations" This reverts commit 577db5cae9568f33fb5a1bb3fc6ab1a4725813f7. Signed-off-by: Dominik Ermel --- subsys/bluetooth/host/att.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index f5ae3768cec..d2c41eaa928 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -670,12 +670,10 @@ static struct net_buf *bt_att_chan_create_pdu(struct bt_att_chan *chan, uint8_t switch (att_op_get_type(op)) { case ATT_RESPONSE: - /* Use a timeout only when responding */ - timeout = BT_ATT_TIMEOUT; - re_use = true; - break; case ATT_CONFIRMATION: + /* Use a timeout only when responding/confirming */ timeout = BT_ATT_TIMEOUT; + re_use = true; break; default: timeout = K_FOREVER; @@ -703,7 +701,7 @@ static struct net_buf *bt_att_chan_create_pdu(struct bt_att_chan *chan, uint8_t * This is better than an assert as an assert would * allow a peer to DoS us. */ - LOG_ERR("already processing a REQ/RSP on chan %p", chan); + LOG_ERR("already processing a transaction on chan %p", chan); return NULL; } From ae3b2bf29783da3ac45691f113c7e515e2f42827 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:31 +0000 Subject: [PATCH 0810/1623] Revert "[nrf fromtree] net: dhcpv6: Fix params check" This reverts commit 3c8028b93d9392629b9b5a123850d1ddea6b66a3. Signed-off-by: Dominik Ermel --- subsys/net/ip/dhcpv6.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/ip/dhcpv6.c b/subsys/net/ip/dhcpv6.c index fdfef3c5147..6fae4f320bf 100644 --- a/subsys/net/ip/dhcpv6.c +++ b/subsys/net/ip/dhcpv6.c @@ -2100,7 +2100,7 @@ void net_dhcpv6_start(struct net_if *iface, struct net_dhcpv6_params *params) goto out; } - if (!params->request_addr && !params->request_prefix) { + if (!params->request_addr && !params->request_addr) { NET_ERR("Information Request not supported yet"); goto out; } From b56fe82ca25874726e384cc58eb71b8dc4d93e68 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:31 +0000 Subject: [PATCH 0811/1623] Revert "[nrf fromtree] net: shell: Add DHCPv6 support" This reverts commit 0258a9960c452a3e0f69004ed421a8838108ad9c. Signed-off-by: Dominik Ermel --- subsys/net/ip/net_shell.c | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index e7af6e16632..c5b07afd6aa 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -719,19 +719,6 @@ static void iface_cb(struct net_if *iface, void *user_data) iface->config.dhcpv4.attempts); #endif /* CONFIG_NET_DHCPV4 */ -#if defined(CONFIG_NET_DHCPV6) - PR("DHCPv6 address requested : %s\n", - iface->config.dhcpv6.params.request_addr ? - net_sprint_ipv6_addr(&iface->config.dhcpv6.addr) : "none"); - PR("DHCPv6 prefix requested : %s\n", - iface->config.dhcpv6.params.request_prefix ? - net_sprint_ipv6_addr(&iface->config.dhcpv6.prefix) : "none"); - PR("DHCPv6 state : %s\n", - net_dhcpv6_state_name(iface->config.dhcpv6.state)); - PR("DHCPv6 attempts : %d\n", - iface->config.dhcpv6.retransmissions + 1); -#endif /* CONFIG_NET_DHCPV6 */ - #else ARG_UNUSED(iface); ARG_UNUSED(user_data); @@ -2526,29 +2513,6 @@ static char *get_l3_desc(struct event_msg *msg, info = net_addr_ntop(AF_INET6, msg->data, extra_info, extra_info_len); break; - case NET_EVENT_IPV6_DHCP_START: - *desc = "DHCPv6"; - *desc2 = "start"; - break; - case NET_EVENT_IPV6_DHCP_BOUND: - *desc = "DHCPv6"; - *desc2 = "bound"; -#if defined(CONFIG_NET_DHCPV6) - struct net_if_dhcpv6 *data = (struct net_if_dhcpv6 *)msg->data; - - if (data->params.request_addr) { - info = net_addr_ntop(AF_INET6, &data->addr, extra_info, - extra_info_len); - } else if (data->params.request_prefix) { - info = net_addr_ntop(AF_INET6, &data->prefix, extra_info, - extra_info_len); - } -#endif - break; - case NET_EVENT_IPV6_DHCP_STOP: - *desc = "DHCPv6"; - *desc2 = "stop"; - break; case NET_EVENT_IPV4_ADDR_ADD: *desc = "IPv4 address"; *desc2 = "add"; From 3704f2bbbb4549dfd103cf1d2b35b7284ee448a6 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:32 +0000 Subject: [PATCH 0812/1623] Revert "[nrf fromtree] net: config: Add DHCPv6 support" This reverts commit 7b858ff1a5bb1cd919249412bdb1c8be3f7424d9. Signed-off-by: Dominik Ermel --- subsys/net/lib/config/Kconfig | 17 ------------- subsys/net/lib/config/init.c | 46 ++++------------------------------- 2 files changed, 5 insertions(+), 58 deletions(-) diff --git a/subsys/net/lib/config/Kconfig b/subsys/net/lib/config/Kconfig index 5ca788cebf1..0f1e3c50544 100644 --- a/subsys/net/lib/config/Kconfig +++ b/subsys/net/lib/config/Kconfig @@ -188,23 +188,6 @@ config NET_CONFIG_BT_NODE endif # NET_CONFIG_SETTINGS -if NET_DHCPV6 - -config NET_CONFIG_DHCPV6_REQUEST_ADDR - bool "Request IPv6 address when configuring DHCPv6 client" - default y - help - When DHCPv6 is enabled this will configure the DHCPv6 client to - request IPv6 address from the DHCPv6 server. - -config NET_CONFIG_DHCPV6_REQUEST_PREFIX - bool "Request IPv6 prefix when configuring DHCPv6 client" - help - When DHCPv6 is enabled this will configure the DHCPv6 client to - request IPv6 prefix from the DHCPv6 server. - -endif # NET_DHCPV6 - config NET_CONFIG_CLOCK_SNTP_INIT bool "Initialize system clock using SNTP on application startup" depends on SNTP && POSIX_CLOCK diff --git a/subsys/net/lib/config/init.c b/subsys/net/lib/config/init.c index 098003b79b3..cd2bf711a7d 100644 --- a/subsys/net/lib/config/init.c +++ b/subsys/net/lib/config/init.c @@ -21,7 +21,6 @@ LOG_MODULE_REGISTER(net_config, CONFIG_NET_CONFIG_LOG_LEVEL); #include #include #include -#include #include #include @@ -204,26 +203,8 @@ static void setup_ipv4(struct net_if *iface) #endif /* CONFIG_NET_IPV4 && !CONFIG_NET_DHCPV4 */ #if defined(CONFIG_NET_NATIVE_IPV6) - -#if defined(CONFIG_NET_DHCPV6) -static void setup_dhcpv6(struct net_if *iface) -{ - struct net_dhcpv6_params params = { - .request_addr = IS_ENABLED(CONFIG_NET_CONFIG_DHCPV6_REQUEST_ADDR), - .request_prefix = IS_ENABLED(CONFIG_NET_CONFIG_DHCPV6_REQUEST_PREFIX), - }; - - NET_INFO("Running dhcpv6 client..."); - - net_dhcpv6_start(iface, ¶ms); -} -#else /* CONFIG_NET_DHCPV6 */ -#define setup_dhcpv6(...) -#endif /* CONFIG_NET_DHCPV6 */ - -#if !defined(CONFIG_NET_CONFIG_DHCPV6_REQUEST_ADDR) && \ - !defined(CONFIG_NET_CONFIG_MY_IPV6_ADDR) -#error "You need to define an IPv6 address or enable DHCPv6!" +#if !defined(CONFIG_NET_CONFIG_MY_IPV6_ADDR) +#error "You need to define an IPv6 address!" #endif static struct net_mgmt_event_callback mgmt6_cb; @@ -268,21 +249,6 @@ static void ipv6_event_handler(struct net_mgmt_event_callback *cb, #if CONFIG_NET_CONFIG_LOG_LEVEL >= LOG_LEVEL_INF NET_INFO("IPv6 address: %s", net_addr_ntop(AF_INET6, &laddr, hr_addr, NET_IPV6_ADDR_LEN)); - - if (ifaddr->addr_type == NET_ADDR_DHCP) { - char remaining_str[] = "infinite"; - uint32_t remaining; - - remaining = net_timeout_remaining(&ifaddr->lifetime, - k_uptime_get_32()); - - if (!ifaddr->is_infinite) { - snprintk(remaining_str, sizeof(remaining_str), - "%u", remaining); - } - - NET_INFO("Lifetime: %s seconds", remaining_str); - } #endif services_notify_ready(NET_CONFIG_NEED_IPV6); @@ -298,9 +264,6 @@ static void setup_ipv6(struct net_if *iface, uint32_t flags) struct net_if_addr *ifaddr; uint32_t mask = NET_EVENT_IPV6_DAD_SUCCEED; - net_mgmt_init_event_callback(&mgmt6_cb, ipv6_event_handler, mask); - net_mgmt_add_event_callback(&mgmt6_cb); - if (sizeof(CONFIG_NET_CONFIG_MY_IPV6_ADDR) == 1) { /* Empty address, skip setting ANY address in this case */ goto exit; @@ -316,6 +279,9 @@ static void setup_ipv6(struct net_if *iface, uint32_t flags) mask |= NET_EVENT_IPV6_ROUTER_ADD; } + net_mgmt_init_event_callback(&mgmt6_cb, ipv6_event_handler, mask); + net_mgmt_add_event_callback(&mgmt6_cb); + /* * check for CMD_ADDR_ADD bit here, NET_EVENT_IPV6_ADDR_ADD is * a combination of _NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ADDR_ADD @@ -344,7 +310,6 @@ static void setup_ipv6(struct net_if *iface, uint32_t flags) #else #define setup_ipv6(...) -#define setup_dhcpv6(...) #endif /* CONFIG_NET_IPV6 */ #if defined(CONFIG_NET_NATIVE) @@ -435,7 +400,6 @@ int net_config_init_by_iface(struct net_if *iface, const char *app_info, setup_ipv4(iface); setup_dhcpv4(iface); setup_ipv6(iface, flags); - setup_dhcpv6(iface); /* Network interface did not come up. */ if (timeout > 0 && count < 0) { From 0d5839b825d036ed282f1edd1ddbbed0a068f5ff Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:32 +0000 Subject: [PATCH 0813/1623] Revert "[nrf fromtree] net: dhcpv6: Introduce net events for DHCPv6" This reverts commit 542166fc77cf4c9d8eb90bdfcb27984b17668017. Signed-off-by: Dominik Ermel --- include/zephyr/net/net_event.h | 12 ------------ subsys/net/ip/dhcpv6.c | 8 -------- subsys/net/ip/net_private.h | 3 --- 3 files changed, 23 deletions(-) diff --git a/include/zephyr/net/net_event.h b/include/zephyr/net/net_event.h index 34856aec6af..819a5ae6639 100644 --- a/include/zephyr/net/net_event.h +++ b/include/zephyr/net/net_event.h @@ -79,9 +79,6 @@ enum net_event_ipv6_cmd { NET_EVENT_IPV6_CMD_DAD_FAILED, NET_EVENT_IPV6_CMD_NBR_ADD, NET_EVENT_IPV6_CMD_NBR_DEL, - NET_EVENT_IPV6_CMD_DHCP_START, - NET_EVENT_IPV6_CMD_DHCP_BOUND, - NET_EVENT_IPV6_CMD_DHCP_STOP, }; #define NET_EVENT_IPV6_ADDR_ADD \ @@ -132,15 +129,6 @@ enum net_event_ipv6_cmd { #define NET_EVENT_IPV6_NBR_DEL \ (_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_NBR_DEL) -#define NET_EVENT_IPV6_DHCP_START \ - (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV6_CMD_DHCP_START) - -#define NET_EVENT_IPV6_DHCP_BOUND \ - (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV6_CMD_DHCP_BOUND) - -#define NET_EVENT_IPV6_DHCP_STOP \ - (_NET_EVENT_IPV4_BASE | NET_EVENT_IPV6_CMD_DHCP_STOP) - /* IPv4 Events*/ #define _NET_IPV4_LAYER NET_MGMT_LAYER_L3 #define _NET_IPV4_CORE_CODE 0x004 diff --git a/subsys/net/ip/dhcpv6.c b/subsys/net/ip/dhcpv6.c index 6fae4f320bf..040c9fa0e06 100644 --- a/subsys/net/ip/dhcpv6.c +++ b/subsys/net/ip/dhcpv6.c @@ -1374,10 +1374,6 @@ static void dhcpv6_enter_confirming(struct net_if *iface) static void dhcpv6_enter_bound(struct net_if *iface) { iface->config.dhcpv6.timeout = iface->config.dhcpv6.t1; - - net_mgmt_event_notify_with_info(NET_EVENT_IPV6_DHCP_BOUND, iface, - &iface->config.dhcpv6, - sizeof(iface->config.dhcpv6)); } static void dhcpv6_enter_state(struct net_if *iface, enum net_dhcpv6_state state) @@ -2105,8 +2101,6 @@ void net_dhcpv6_start(struct net_if *iface, struct net_dhcpv6_params *params) goto out; } - net_mgmt_event_notify(NET_EVENT_IPV6_DHCP_START, iface); - NET_DBG("Starting DHCPv6 on iface %p", iface); iface->config.dhcpv6.params = *params; @@ -2166,8 +2160,6 @@ void net_dhcpv6_stop(struct net_if *iface) break; } - net_mgmt_event_notify(NET_EVENT_IPV6_DHCP_STOP, iface); - k_mutex_unlock(&lock); } diff --git a/subsys/net/ip/net_private.h b/subsys/net/ip/net_private.h index c2b80aa4f05..be0466fc98b 100644 --- a/subsys/net/ip/net_private.h +++ b/subsys/net/ip/net_private.h @@ -30,9 +30,6 @@ union net_mgmt_events { #if defined(CONFIG_NET_DHCPV4) struct net_if_dhcpv4 dhcpv4; #endif /* CONFIG_NET_DHCPV4 */ -#if defined(CONFIG_NET_DHCPV6) - struct net_if_dhcpv6 dhcpv6; -#endif /* CONFIG_NET_DHCPV6 */ #if defined(CONFIG_NET_L2_WIFI_MGMT) union wifi_mgmt_events wifi; #endif /* CONFIG_NET_L2_WIFI_MGMT */ From 91a77c98c986b7a1af1511989a78c61004224d72 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:32 +0000 Subject: [PATCH 0814/1623] Revert "[nrf fromtree] net: dhcpv6: Add Zephyr DHCPv6 client" This reverts commit 04cd082a7d7b34ee66b07682e158ccbfafd93d8f. Signed-off-by: Dominik Ermel --- include/zephyr/net/dhcpv6.h | 116 -- include/zephyr/net/net_if.h | 70 - subsys/net/ip/CMakeLists.txt | 1 - subsys/net/ip/Kconfig.ipv6 | 14 - subsys/net/ip/dhcpv6.c | 2196 ------------------------------- subsys/net/ip/dhcpv6_internal.h | 196 --- subsys/net/ip/net_core.c | 6 - 7 files changed, 2599 deletions(-) delete mode 100644 include/zephyr/net/dhcpv6.h delete mode 100644 subsys/net/ip/dhcpv6.c delete mode 100644 subsys/net/ip/dhcpv6_internal.h diff --git a/include/zephyr/net/dhcpv6.h b/include/zephyr/net/dhcpv6.h deleted file mode 100644 index 95b59f530b5..00000000000 --- a/include/zephyr/net/dhcpv6.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** @file - * @brief DHCPv6 client - */ - -#ifndef ZEPHYR_INCLUDE_NET_DHCPV6_H_ -#define ZEPHYR_INCLUDE_NET_DHCPV6_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief DHCPv6 - * @defgroup dhcpv6 DHCPv6 - * @ingroup networking - * @{ - */ - -/** @cond INTERNAL_HIDDEN */ - -/** Current state of DHCPv6 client address/prefix negotiation. */ -enum net_dhcpv6_state { - NET_DHCPV6_DISABLED, - NET_DHCPV6_INIT, - NET_DHCPV6_SOLICITING, - NET_DHCPV6_REQUESTING, - NET_DHCPV6_CONFIRMING, - NET_DHCPV6_RENEWING, - NET_DHCPV6_REBINDING, - NET_DHCPV6_INFO_REQUESTING, - NET_DHCPV6_BOUND, -} __packed; - -#define DHCPV6_TID_SIZE 3 -#define DHCPV6_DUID_MAX_SIZE 20 - -struct net_dhcpv6_duid_raw { - uint16_t type; - uint8_t buf[DHCPV6_DUID_MAX_SIZE]; -} __packed; - -struct net_dhcpv6_duid_storage { - struct net_dhcpv6_duid_raw duid; - uint8_t length; -}; - -struct net_if; - -/** @endcond */ - -/** @brief DHCPv6 client configuration parameters. */ -struct net_dhcpv6_params { - bool request_addr : 1; /**< Request IPv6 address. */ - bool request_prefix : 1; /**< Request IPv6 prefix. */ -}; - -/** - * @brief Start DHCPv6 client on an iface - * - * @details Start DHCPv6 client on a given interface. DHCPv6 client will start - * negotiation for IPv6 address and/or prefix, depending on the configuration. - * Once the negotiation is complete, IPv6 address/prefix details will be added - * to the interface. - * - * @param iface A valid pointer to a network interface - * @param params DHCPv6 client configuration parameters. - */ -void net_dhcpv6_start(struct net_if *iface, struct net_dhcpv6_params *params); - -/** - * @brief Stop DHCPv6 client on an iface - * - * @details Stop DHCPv6 client on a given interface. DHCPv6 client - * will remove all configuration obtained from a DHCP server from the - * interface and stop any further negotiation with the server. - * - * @param iface A valid pointer to a network interface - */ -void net_dhcpv6_stop(struct net_if *iface); - -/** - * @brief Restart DHCPv6 client on an iface - * - * @details Restart DHCPv6 client on a given interface. DHCPv6 client - * will restart the state machine without any of the initial delays. - * - * @param iface A valid pointer to a network interface - */ -void net_dhcpv6_restart(struct net_if *iface); - -/** @cond INTERNAL_HIDDEN */ - -/** - * @brief DHCPv6 state name - * - * @internal - */ -const char *net_dhcpv6_state_name(enum net_dhcpv6_state state); - -/** @endcond */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* ZEPHYR_INCLUDE_NET_DHCPV6_H_ */ diff --git a/include/zephyr/net/net_if.h b/include/zephyr/net/net_if.h index b06bf74de03..cced3557b84 100644 --- a/include/zephyr/net/net_if.h +++ b/include/zephyr/net/net_if.h @@ -33,9 +33,6 @@ #if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4) #include #endif -#if defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6) -#include -#endif #if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4) #include #endif @@ -278,69 +275,6 @@ struct net_if_ipv6 { uint8_t hop_limit; }; -#if defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6) -struct net_if_dhcpv6 { - /** Used for timer list. */ - sys_snode_t node; - - /** Generated Client ID. */ - struct net_dhcpv6_duid_storage clientid; - - /** Server ID of the selected server. */ - struct net_dhcpv6_duid_storage serverid; - - /** DHCPv6 client state. */ - enum net_dhcpv6_state state; - - /** DHCPv6 client configuration parameters. */ - struct net_dhcpv6_params params; - - /** Timeout for the next event, absolute time, milliseconds. */ - uint64_t timeout; - - /** Time of the current exchange start, absolute time, milliseconds */ - uint64_t exchange_start; - - /** Renewal time, absolute time, milliseconds. */ - uint64_t t1; - - /** Rebinding time, absolute time, milliseconds. */ - uint64_t t2; - - /** The time when the last lease expires (terminates rebinding, - * DHCPv6 RFC8415, ch. 18.2.5). Absolute time, milliseconds. - */ - uint64_t expire; - - /** Generated IAID for IA_NA. */ - uint32_t addr_iaid; - - /** Generated IAID for IA_PD. */ - uint32_t prefix_iaid; - - /** Retransmit timeout for the current message, milliseconds. */ - uint32_t retransmit_timeout; - - /** Current best server preference received. */ - int16_t server_preference; - - /** Retransmission counter. */ - uint8_t retransmissions; - - /** Transaction ID for current exchange. */ - uint8_t tid[DHCPV6_TID_SIZE]; - - /** Prefix length. */ - uint8_t prefix_len; - - /** Assigned IPv6 prefix. */ - struct in6_addr prefix; - - /** Assigned IPv6 address. */ - struct in6_addr addr; -}; -#endif /* defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6) */ - /** @cond INTERNAL_HIDDEN */ #if defined(CONFIG_NET_NATIVE_IPV4) #define NET_IF_MAX_IPV4_ADDR CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT @@ -479,10 +413,6 @@ struct net_if_config { struct net_if_dhcpv4 dhcpv4; #endif /* CONFIG_NET_DHCPV4 */ -#if defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6) - struct net_if_dhcpv6 dhcpv6; -#endif /* CONFIG_NET_DHCPV6 */ - #if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4) struct net_if_ipv4_autoconf ipv4auto; #endif /* CONFIG_NET_IPV4_AUTO */ diff --git a/subsys/net/ip/CMakeLists.txt b/subsys/net/ip/CMakeLists.txt index 7dc54935c5c..70655e2f61c 100644 --- a/subsys/net/ip/CMakeLists.txt +++ b/subsys/net/ip/CMakeLists.txt @@ -31,7 +31,6 @@ zephyr_library_sources(net_tc.c) zephyr_library_sources_ifdef(CONFIG_NET_IP connection.c) zephyr_library_sources_ifdef(CONFIG_NET_6LO 6lo.c) zephyr_library_sources_ifdef(CONFIG_NET_DHCPV4 dhcpv4.c) -zephyr_library_sources_ifdef(CONFIG_NET_DHCPV6 dhcpv6.c) zephyr_library_sources_ifdef(CONFIG_NET_IPV4_AUTO ipv4_autoconf.c) zephyr_library_sources_ifdef(CONFIG_NET_IPV4 icmpv4.c ipv4.c) zephyr_library_sources_ifdef(CONFIG_NET_IPV4_IGMP igmp.c) diff --git a/subsys/net/ip/Kconfig.ipv6 b/subsys/net/ip/Kconfig.ipv6 index 18fb4b0ccc4..b776d3756eb 100644 --- a/subsys/net/ip/Kconfig.ipv6 +++ b/subsys/net/ip/Kconfig.ipv6 @@ -166,12 +166,6 @@ config NET_MAX_6LO_CONTEXTS 6lowpan context options table size. The value depends on your network and memory consumption. More 6CO options uses more memory. -config NET_DHCPV6 - bool "DHCPv6 client" - select NET_MGMT - select NET_MGMT_EVENT - depends on NET_UDP - if NET_6LO module = NET_6LO module-dep = NET_LOG @@ -198,13 +192,5 @@ module-str = Log level for IPv6 neighbor cache module-help = Enables IPv6 Neighbor Cache code to output debug messages. source "subsys/net/Kconfig.template.log_config.net" -if NET_DHCPV6 -module = NET_DHCPV6 -module-dep = NET_LOG -module-str = Log level for DHCPv6 client -module-help = Enables DHCPv6 client code to output debug messages. -source "subsys/net/Kconfig.template.log_config.net" -endif # NET_DHCPV6 - endif # NET_NATIVE_IPV6 endif # NET_IPV6 diff --git a/subsys/net/ip/dhcpv6.c b/subsys/net/ip/dhcpv6.c deleted file mode 100644 index 040c9fa0e06..00000000000 --- a/subsys/net/ip/dhcpv6.c +++ /dev/null @@ -1,2196 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** @file - * @brief DHCPv6 client implementation - */ - -#include -LOG_MODULE_REGISTER(net_dhcpv6, CONFIG_NET_DHCPV6_LOG_LEVEL); - -#include -#include -#include -#include - -#include "dhcpv6_internal.h" -#include "ipv6.h" -#include "net_private.h" -#include "udp_internal.h" - -/* Maximum number of options client can request. */ -#define DHCPV6_MAX_OPTION_REQUEST 2 - -struct dhcpv6_options_include { - bool clientid : 1; - bool serverid : 1; - bool elapsed_time : 1; - bool ia_na : 1; - bool iaaddr : 1; - bool ia_pd : 1; - bool iaprefix : 1; - uint16_t oro[DHCPV6_MAX_OPTION_REQUEST]; -}; - -static K_MUTEX_DEFINE(lock); - -/* All_DHCP_Relay_Agents_and_Servers (ff02::1:2) */ -static const struct in6_addr all_dhcpv6_ra_and_servers = { { { 0xff, 0x02, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0x01, 0, 0x02 } } }; - -static sys_slist_t dhcpv6_ifaces = SYS_SLIST_STATIC_INIT(&dhcpv6_ifaces); -static struct k_work_delayable dhcpv6_timeout_work; -static struct net_mgmt_event_callback dhcpv6_mgmt_cb; - -const char *net_dhcpv6_state_name(enum net_dhcpv6_state state) -{ - static const char * const name[] = { - "disabled", - "init", - "soliciting", - "requesting", - "confirming", - "renewing", - "rebinding", - "information requesting", - "bound", - }; - - __ASSERT_NO_MSG(state >= 0 && state < sizeof(name)); - return name[state]; -} - -static void dhcpv6_generate_tid(struct net_if *iface) -{ - sys_rand_get(iface->config.dhcpv6.tid, sizeof(iface->config.dhcpv6.tid)); -} - -static void dhcvp6_update_deadlines(struct net_if *iface, int64_t now, - uint32_t t1, uint32_t t2, - uint32_t preferred_lifetime, - uint32_t valid_lifetime) -{ - uint64_t t1_abs, t2_abs, expire_abs; - - /* In case server does not set T1/T2 values, the time choice is left to - * the client discretion. - * Here, we use recommendations for the servers, where it's advised to - * set T1/T2 as 0.5 and 0.8 of the preferred lifetime. - */ - if (t1 == 0 && t2 == 0) { - if (preferred_lifetime == DHCPV6_INFINITY) { - t1 = DHCPV6_INFINITY; - t2 = DHCPV6_INFINITY; - } else { - t1 = preferred_lifetime * 0.5; - t2 = preferred_lifetime * 0.8; - } - } else if (t1 == 0) { - if (t2 == DHCPV6_INFINITY) { - t1 = DHCPV6_INFINITY; - } else { - t1 = t2 * 0.625; /* 0.5 / 0.8 */ - } - } else if (t2 == 0) { - if (t1 == DHCPV6_INFINITY) { - t2 = DHCPV6_INFINITY; - } else { - t2 = t1 * 1.6; /* 0.8 / 0.5 */ - /* Overflow check. */ - if (t2 < t1) { - t2 = DHCPV6_INFINITY; - } - } - } else if (t1 >= t2) { - NET_ERR("Invalid T1(%u)/T2(%u) values.", t1, t2); - return; - } - - if (t1 == DHCPV6_INFINITY || - u64_add_overflow(now, 1000ULL * t1, &t1_abs)) { - t1_abs = UINT64_MAX; - } - - if (t2 == DHCPV6_INFINITY || - u64_add_overflow(now, 1000ULL * t2, &t2_abs)) { - t2_abs = UINT64_MAX; - } - - if (valid_lifetime == DHCPV6_INFINITY || - u64_add_overflow(now, 1000ULL * valid_lifetime, &expire_abs)) { - expire_abs = UINT64_MAX; - } - - if (iface->config.dhcpv6.t1 > t1_abs) { - iface->config.dhcpv6.t1 = t1_abs; - } - - if (iface->config.dhcpv6.t2 > t2_abs) { - iface->config.dhcpv6.t2 = t2_abs; - } - - if (iface->config.dhcpv6.expire < expire_abs) { - iface->config.dhcpv6.expire = expire_abs; - } -} - -static void dhcpv6_set_timeout(struct net_if *iface, uint64_t timeout) -{ - int64_t now = k_uptime_get(); - - NET_DBG("sched dhcpv6 timeout iface=%p timeout=%llums", iface, timeout); - - if (u64_add_overflow(now, timeout, &iface->config.dhcpv6.timeout)) { - iface->config.dhcpv6.timeout = UINT64_MAX; - } -} - -static void dhcpv6_reschedule(void) -{ - k_work_reschedule(&dhcpv6_timeout_work, K_NO_WAIT); -} - -static int randomize_timeout(int multiplier, int timeout) -{ - int factor; - - /* DHCPv6 RFC8415, ch. 15. the randomization factor should be a random - * number between -0.1 nand +0.1. As we operate on integers here, we - * scale it to -100 and +100, and divide the result by 1000. - */ - factor = (int)(sys_rand32_get() % 201) - 100; - - return (multiplier * timeout) + ((factor * timeout) / 1000); -} - -static int dhcpv6_initial_retransmit_time(int init_retransmit_time) -{ - /* DHCPv6 RFC8415, ch. 15. Retransmission time for the first msg. */ - return randomize_timeout(1, init_retransmit_time); -} - -static uint32_t dhcpv6_next_retransmit_time(int prev_retransmit_time, - int max_retransmit_time) -{ - int retransmit_time; - - /* DHCPv6 RFC8415, ch. 15. Retransmission time for the subsequent msg. */ - retransmit_time = randomize_timeout(2, prev_retransmit_time); - - if (max_retransmit_time == 0) { - return retransmit_time; - } - - if (retransmit_time > max_retransmit_time) { - retransmit_time = randomize_timeout(1, max_retransmit_time); - } - - return retransmit_time; -} - -/* DHCPv6 packet encoding functions */ - -static int dhcpv6_add_header(struct net_pkt *pkt, enum dhcpv6_msg_type type, - uint8_t *tid) -{ - int ret; - - ret = net_pkt_write_u8(pkt, type); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write(pkt, tid, DHCPV6_TID_SIZE); - - return ret; -} - -static int dhcpv6_add_option_header(struct net_pkt *pkt, - enum dhcpv6_option_code code, - uint16_t length) -{ - int ret; - - ret = net_pkt_write_be16(pkt, code); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_be16(pkt, length); - - return ret; -} - -static int dhcpv6_add_option_clientid(struct net_pkt *pkt, - struct net_dhcpv6_duid_storage *clientid) -{ - int ret; - - ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_CLIENTID, - clientid->length); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write(pkt, &clientid->duid, clientid->length); - - return ret; -} - -static int dhcpv6_add_option_serverid(struct net_pkt *pkt, - struct net_dhcpv6_duid_storage *serverid) -{ - int ret; - - ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_SERVERID, - serverid->length); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write(pkt, &serverid->duid, serverid->length); - - return ret; -} - - -static int dhcpv6_add_option_elapsed_time(struct net_pkt *pkt, uint64_t since) -{ - uint64_t elapsed; - int ret; - - ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_ELAPSED_TIME, - DHCPV6_OPTION_ELAPSED_TIME_SIZE); - if (ret < 0) { - return ret; - } - - /* Elapsed time should be expressed in hundredths of a second. */ - elapsed = (k_uptime_get() - since) / 10ULL; - if (elapsed > 0xFFFF) { - elapsed = 0xFFFF; - } - - ret = net_pkt_write_be16(pkt, (uint16_t)elapsed); - - return ret; -} - -static int dhcpv6_add_option_ia_na(struct net_pkt *pkt, struct dhcpv6_ia_na *ia_na, - bool include_addr) -{ - uint16_t optlen; - int ret; - - if (!include_addr) { - optlen = DHCPV6_OPTION_IA_NA_HEADER_SIZE; - } else { - optlen = DHCPV6_OPTION_IA_NA_HEADER_SIZE + - DHCPV6_OPTION_HEADER_SIZE + - DHCPV6_OPTION_IAADDR_HEADER_SIZE; - } - - ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_IA_NA, optlen); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_be32(pkt, ia_na->iaid); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_be32(pkt, ia_na->t1); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_be32(pkt, ia_na->t2); - if (ret < 0) { - return ret; - } - - if (!include_addr) { - return 0; - } - - ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_IAADDR, - DHCPV6_OPTION_IAADDR_HEADER_SIZE); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write(pkt, &ia_na->iaaddr.addr, sizeof(ia_na->iaaddr.addr)); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_be32(pkt, ia_na->iaaddr.preferred_lifetime); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_be32(pkt, ia_na->iaaddr.valid_lifetime); - - return ret; -} - -static int dhcpv6_add_option_ia_pd(struct net_pkt *pkt, struct dhcpv6_ia_pd *ia_pd, - bool include_prefix) -{ - uint16_t optlen; - int ret; - - if (!include_prefix) { - optlen = DHCPV6_OPTION_IA_PD_HEADER_SIZE; - } else { - optlen = DHCPV6_OPTION_IA_PD_HEADER_SIZE + - DHCPV6_OPTION_HEADER_SIZE + - DHCPV6_OPTION_IAPREFIX_HEADER_SIZE; - } - - ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_IA_PD, - optlen); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_be32(pkt, ia_pd->iaid); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_be32(pkt, ia_pd->t1); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_be32(pkt, ia_pd->t2); - if (ret < 0) { - return ret; - } - - if (!include_prefix) { - return 0; - } - - ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_IAPREFIX, - DHCPV6_OPTION_IAPREFIX_HEADER_SIZE); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_be32(pkt, ia_pd->iaprefix.preferred_lifetime); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_be32(pkt, ia_pd->iaprefix.valid_lifetime); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write_u8(pkt, ia_pd->iaprefix.prefix_len); - if (ret < 0) { - return ret; - } - - ret = net_pkt_write(pkt, &ia_pd->iaprefix.prefix, - sizeof(ia_pd->iaprefix.prefix)); - - return ret; -} - -static int dhcpv6_add_option_oro(struct net_pkt *pkt, uint16_t *codes, - int code_cnt) -{ - int ret; - - ret = dhcpv6_add_option_header(pkt, DHCPV6_OPTION_CODE_ORO, - sizeof(uint16_t) * code_cnt); - if (ret < 0) { - return ret; - } - - for (int i = 0; i < code_cnt; i++) { - ret = net_pkt_write_be16(pkt, codes[i]); - if (ret < 0) { - return ret; - } - } - - return ret; -} - -static size_t dhcpv6_calculate_message_size(struct dhcpv6_options_include *options) -{ - size_t msg_size = sizeof(struct dhcpv6_msg_hdr); - uint8_t oro_cnt = 0; - - if (options->clientid) { - msg_size += DHCPV6_OPTION_HEADER_SIZE; - msg_size += sizeof(struct net_dhcpv6_duid_storage); - } - - if (options->serverid) { - msg_size += DHCPV6_OPTION_HEADER_SIZE; - msg_size += sizeof(struct net_dhcpv6_duid_storage); - } - - if (options->elapsed_time) { - msg_size += DHCPV6_OPTION_HEADER_SIZE; - msg_size += DHCPV6_OPTION_ELAPSED_TIME_SIZE; - } - - if (options->ia_na) { - msg_size += DHCPV6_OPTION_HEADER_SIZE; - msg_size += DHCPV6_OPTION_IA_NA_HEADER_SIZE; - } - - if (options->iaaddr) { - msg_size += DHCPV6_OPTION_HEADER_SIZE; - msg_size += DHCPV6_OPTION_IAADDR_HEADER_SIZE; - } - - if (options->ia_pd) { - msg_size += DHCPV6_OPTION_HEADER_SIZE; - msg_size += DHCPV6_OPTION_IA_PD_HEADER_SIZE; - } - - if (options->iaprefix) { - msg_size += DHCPV6_OPTION_HEADER_SIZE; - msg_size += DHCPV6_OPTION_IAPREFIX_HEADER_SIZE; - } - - for (uint8_t i = 0; i < ARRAY_SIZE(options->oro); i++) { - if (options->oro[i] == 0) { - break; - } - - oro_cnt++; - } - - if (oro_cnt > 0) { - msg_size += DHCPV6_OPTION_HEADER_SIZE; - msg_size += oro_cnt * sizeof(uint16_t); - } - - return msg_size; -} - -static int dhcpv6_add_options(struct net_if *iface, struct net_pkt *pkt, - struct dhcpv6_options_include *options) -{ - uint8_t oro_cnt = 0; - int ret; - - if (options->clientid) { - ret = dhcpv6_add_option_clientid( - pkt, &iface->config.dhcpv6.clientid); - if (ret < 0) { - goto fail; - } - } - - if (options->serverid) { - ret = dhcpv6_add_option_serverid( - pkt, &iface->config.dhcpv6.serverid); - if (ret < 0) { - goto fail; - } - } - - if (options->elapsed_time) { - ret = dhcpv6_add_option_elapsed_time( - pkt, iface->config.dhcpv6.exchange_start); - if (ret < 0) { - goto fail; - } - } - - if (options->ia_na) { - struct dhcpv6_ia_na ia_na = { - .iaid = iface->config.dhcpv6.addr_iaid, - }; - - if (options->iaaddr) { - memcpy(&ia_na.iaaddr.addr, &iface->config.dhcpv6.addr, - sizeof(ia_na.iaaddr.addr)); - } - - ret = dhcpv6_add_option_ia_na(pkt, &ia_na, options->iaaddr); - if (ret < 0) { - goto fail; - } - } - - if (options->ia_pd) { - struct dhcpv6_ia_pd ia_pd = { - .iaid = iface->config.dhcpv6.prefix_iaid, - }; - - if (options->iaprefix) { - memcpy(&ia_pd.iaprefix.prefix, &iface->config.dhcpv6.prefix, - sizeof(ia_pd.iaprefix.prefix)); - ia_pd.iaprefix.prefix_len = iface->config.dhcpv6.prefix_len; - } - - ret = dhcpv6_add_option_ia_pd(pkt, &ia_pd, options->iaprefix); - if (ret < 0) { - goto fail; - } - } - - for (uint8_t i = 0; i < ARRAY_SIZE(options->oro); i++) { - if (options->oro[i] == 0) { - break; - } - - oro_cnt++; - } - - if (oro_cnt > 0) { - ret = dhcpv6_add_option_oro(pkt, options->oro, oro_cnt); - if (ret < 0) { - goto fail; - } - } - - return 0; - -fail: - return ret; -} - -static struct net_pkt *dhcpv6_create_message(struct net_if *iface, - enum dhcpv6_msg_type msg_type, - struct dhcpv6_options_include *options) -{ - struct in6_addr *local_addr; - struct net_pkt *pkt; - size_t msg_size; - - local_addr = net_if_ipv6_get_ll(iface, NET_ADDR_ANY_STATE); - if (local_addr == NULL) { - NET_ERR("No LL address"); - return NULL; - } - - msg_size = dhcpv6_calculate_message_size(options); - - pkt = net_pkt_alloc_with_buffer(iface, msg_size, AF_INET6, - IPPROTO_UDP, K_FOREVER); - if (pkt == NULL) { - return NULL; - } - - if (net_ipv6_create(pkt, local_addr, &all_dhcpv6_ra_and_servers) < 0 || - net_udp_create(pkt, htons(DHCPV6_CLIENT_PORT), - htons(DHCPV6_SERVER_PORT)) < 0) { - goto fail; - } - - dhcpv6_generate_tid(iface); - - if (dhcpv6_add_header(pkt, msg_type, iface->config.dhcpv6.tid) < 0) { - goto fail; - } - - if (dhcpv6_add_options(iface, pkt, options) < 0) { - goto fail; - } - - net_pkt_cursor_init(pkt); - net_ipv6_finalize(pkt, IPPROTO_UDP); - - return pkt; - -fail: - net_pkt_unref(pkt); - - return NULL; -} - -static int dhcpv6_send_solicit(struct net_if *iface) -{ - int ret; - struct net_pkt *pkt; - struct dhcpv6_options_include options = { - .clientid = true, - .elapsed_time = true, - .ia_na = iface->config.dhcpv6.params.request_addr, - .ia_pd = iface->config.dhcpv6.params.request_prefix, - .oro = { DHCPV6_OPTION_CODE_SOL_MAX_RT }, - }; - - pkt = dhcpv6_create_message(iface, DHCPV6_MSG_TYPE_SOLICIT, &options); - if (pkt == NULL) { - return -ENOMEM; - } - - ret = net_send_data(pkt); - if (ret < 0) { - net_pkt_unref(pkt); - } - - return ret; -} - -static int dhcpv6_send_request(struct net_if *iface) -{ - int ret; - struct net_pkt *pkt; - struct dhcpv6_options_include options = { - .clientid = true, - .serverid = true, - .elapsed_time = true, - .ia_na = iface->config.dhcpv6.params.request_addr, - .ia_pd = iface->config.dhcpv6.params.request_prefix, - .oro = { DHCPV6_OPTION_CODE_SOL_MAX_RT }, - }; - - pkt = dhcpv6_create_message(iface, DHCPV6_MSG_TYPE_REQUEST, &options); - if (pkt == NULL) { - return -ENOMEM; - } - - ret = net_send_data(pkt); - if (ret < 0) { - net_pkt_unref(pkt); - } - - return ret; -} - -static int dhcpv6_send_renew(struct net_if *iface) -{ - int ret; - struct net_pkt *pkt; - struct dhcpv6_options_include options = { - .clientid = true, - .serverid = true, - .elapsed_time = true, - .ia_na = iface->config.dhcpv6.params.request_addr, - .iaaddr = iface->config.dhcpv6.params.request_addr, - .ia_pd = iface->config.dhcpv6.params.request_prefix, - .iaprefix = iface->config.dhcpv6.params.request_prefix, - .oro = { DHCPV6_OPTION_CODE_SOL_MAX_RT }, - }; - - pkt = dhcpv6_create_message(iface, DHCPV6_MSG_TYPE_RENEW, &options); - if (pkt == NULL) { - return -ENOMEM; - } - - ret = net_send_data(pkt); - if (ret < 0) { - net_pkt_unref(pkt); - } - - return ret; -} - -static int dhcpv6_send_rebind(struct net_if *iface) -{ - int ret; - struct net_pkt *pkt; - struct dhcpv6_options_include options = { - .clientid = true, - .elapsed_time = true, - .ia_na = iface->config.dhcpv6.params.request_addr, - .iaaddr = iface->config.dhcpv6.params.request_addr, - .ia_pd = iface->config.dhcpv6.params.request_prefix, - .iaprefix = iface->config.dhcpv6.params.request_prefix, - .oro = { DHCPV6_OPTION_CODE_SOL_MAX_RT }, - }; - - pkt = dhcpv6_create_message(iface, DHCPV6_MSG_TYPE_REBIND, &options); - if (pkt == NULL) { - return -ENOMEM; - } - - ret = net_send_data(pkt); - if (ret < 0) { - net_pkt_unref(pkt); - } - - return ret; -} - -static int dhcpv6_send_confirm(struct net_if *iface) -{ - int ret; - struct net_pkt *pkt; - struct dhcpv6_options_include options = { - .clientid = true, - .elapsed_time = true, - .ia_na = true, - .iaaddr = true, - }; - - pkt = dhcpv6_create_message(iface, DHCPV6_MSG_TYPE_CONFIRM, &options); - if (pkt == NULL) { - return -ENOMEM; - } - - ret = net_send_data(pkt); - if (ret < 0) { - net_pkt_unref(pkt); - } - - return ret; -} - -/* DHCPv6 packet parsing functions */ - -static int dhcpv6_parse_option_clientid(struct net_pkt *pkt, uint16_t length, - struct net_dhcpv6_duid_storage *clientid) -{ - struct net_dhcpv6_duid_raw duid; - int ret; - - if (length > sizeof(struct net_dhcpv6_duid_raw)) { - NET_ERR("DUID too large to handle"); - return -EMSGSIZE; - } - - ret = net_pkt_read(pkt, &duid, length); - if (ret < 0) { - return ret; - } - - clientid->length = length; - memcpy(&clientid->duid, &duid, length); - - return 0; -} - -static int dhcpv6_parse_option_serverid(struct net_pkt *pkt, uint16_t length, - struct net_dhcpv6_duid_storage *serverid) -{ - struct net_dhcpv6_duid_raw duid; - int ret; - - if (length > sizeof(struct net_dhcpv6_duid_raw)) { - NET_ERR("DUID too large to handle"); - return -EMSGSIZE; - } - - ret = net_pkt_read(pkt, &duid, length); - if (ret < 0) { - return ret; - } - - serverid->length = length; - memcpy(&serverid->duid, &duid, length); - - return 0; -} - -static int dhcpv6_parse_option_preference(struct net_pkt *pkt, uint16_t length, - uint8_t *preference) -{ - if (length != DHCPV6_OPTION_PREFERENCE_SIZE) { - return -EBADMSG; - } - - if (net_pkt_read_u8(pkt, preference) < 0) { - return -EBADMSG; - } - - return 0; -} - -static int dhcpv6_parse_option_status_code(struct net_pkt *pkt, - uint16_t length, uint16_t *status) -{ - int ret; - - if (length < DHCPV6_OPTION_STATUS_CODE_HEADER_SIZE) { - NET_ERR("Invalid IAADDR option size"); - return -EMSGSIZE; - } - - ret = net_pkt_read_be16(pkt, status); - if (ret < 0) { - return ret; - } - - NET_DBG("status code %d", *status); - - length -= DHCPV6_OPTION_STATUS_CODE_HEADER_SIZE; - if (length > 0) { - /* Ignore status message */ - ret = net_pkt_skip(pkt, length); - } - - return ret; -} - -static int dhcpv6_parse_option_iaaddr(struct net_pkt *pkt, uint16_t length, - struct dhcpv6_iaaddr *iaaddr) -{ - int ret; - - if (length < DHCPV6_OPTION_IAADDR_HEADER_SIZE) { - NET_ERR("Invalid IAADDR option size"); - return -EMSGSIZE; - } - - ret = net_pkt_read(pkt, &iaaddr->addr, sizeof(iaaddr->addr)); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_be32(pkt, &iaaddr->preferred_lifetime); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_be32(pkt, &iaaddr->valid_lifetime); - if (ret < 0) { - return ret; - } - - /* DHCPv6 RFC8415, ch. 21.6 The client MUST discard any addresses for - * which the preferred lifetime is greater than the valid lifetime. - */ - if (iaaddr->preferred_lifetime > iaaddr->valid_lifetime) { - return -EBADMSG; - } - - NET_DBG("addr %s preferred_lifetime %d valid_lifetime %d", - net_sprint_ipv6_addr(&iaaddr->addr), iaaddr->preferred_lifetime, - iaaddr->valid_lifetime); - - iaaddr->status = DHCPV6_STATUS_SUCCESS; - - length -= DHCPV6_OPTION_IAADDR_HEADER_SIZE; - while (length > 0) { - uint16_t code, sublen; - - ret = net_pkt_read_be16(pkt, &code); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_be16(pkt, &sublen); - if (ret < 0) { - return ret; - } - - switch (code) { - case DHCPV6_OPTION_CODE_STATUS_CODE: - ret = dhcpv6_parse_option_status_code(pkt, sublen, - &iaaddr->status); - if (ret < 0) { - return ret; - } - - break; - default: - net_pkt_skip(pkt, sublen); - NET_DBG("Unexpected option %d length %d", code, sublen); - break; - } - - length -= (sublen + 4); - } - - return 0; -} - -static int dhcpv6_parse_option_ia_na(struct net_pkt *pkt, uint16_t length, - struct dhcpv6_ia_na *ia_na) -{ - int ret; - - if (length < DHCPV6_OPTION_IA_NA_HEADER_SIZE) { - NET_ERR("Invalid IA_NA option size"); - return -EMSGSIZE; - } - - ret = net_pkt_read_be32(pkt, &ia_na->iaid); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_be32(pkt, &ia_na->t1); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_be32(pkt, &ia_na->t2); - if (ret < 0) { - return ret; - } - - /* DHCPv6 RFC8415, ch. 21.4 If a client receives an IA_NA with T1 - * greater than T2 and both T1 and T2 are greater than 0, the client - * discards the IA_NA option and processes the remainder of the message - * as though the server had not included the invalid IA_NA option. - */ - if (ia_na->t1 != 0 && ia_na->t2 != 0 && ia_na->t1 > ia_na->t2) { - return -ENOENT; - } - - NET_DBG("iaid %d t1 %d t2 %d", ia_na->iaid, ia_na->t1, ia_na->t2); - - /* In case there's no IAADDR option, make this visible be setting - * error status. If the option is present, option parser will overwrite - * the value. - */ - ia_na->iaaddr.status = DHCPV6_STATUS_NO_ADDR_AVAIL; - ia_na->status = DHCPV6_STATUS_SUCCESS; - - length -= DHCPV6_OPTION_IA_NA_HEADER_SIZE; - while (length > 0) { - uint16_t code, sublen; - - ret = net_pkt_read_be16(pkt, &code); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_be16(pkt, &sublen); - if (ret < 0) { - return ret; - } - - switch (code) { - case DHCPV6_OPTION_CODE_IAADDR: - ret = dhcpv6_parse_option_iaaddr(pkt, sublen, - &ia_na->iaaddr); - if (ret < 0) { - return ret; - } - - break; - - case DHCPV6_OPTION_CODE_STATUS_CODE: - ret = dhcpv6_parse_option_status_code(pkt, sublen, - &ia_na->status); - if (ret < 0) { - return ret; - } - - break; - - default: - net_pkt_skip(pkt, sublen); - NET_DBG("Unexpected option %d length %d", code, sublen); - break; - } - - length -= (sublen + 4); - } - - return 0; -} - -static int dhcpv6_parse_option_iaprefix(struct net_pkt *pkt, uint16_t length, - struct dhcpv6_iaprefix *iaprefix) -{ - int ret; - - if (length < DHCPV6_OPTION_IAPREFIX_HEADER_SIZE) { - NET_ERR("Invalid IAPREFIX option size"); - return -EMSGSIZE; - } - - ret = net_pkt_read_be32(pkt, &iaprefix->preferred_lifetime); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_be32(pkt, &iaprefix->valid_lifetime); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_u8(pkt, &iaprefix->prefix_len); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read(pkt, &iaprefix->prefix, sizeof(iaprefix->prefix)); - if (ret < 0) { - return ret; - } - - /* DHCPv6 RFC8415, ch. 21.22 The client MUST discard any prefixes for - * which the preferred lifetime is greater than the valid lifetime. - */ - if (iaprefix->preferred_lifetime > iaprefix->valid_lifetime) { - return -EBADMSG; - } - - NET_DBG("prefix %s/%u preferred_lifetime %d valid_lifetime %d", - net_sprint_ipv6_addr(&iaprefix->prefix), iaprefix->prefix_len, - iaprefix->preferred_lifetime, iaprefix->valid_lifetime); - - iaprefix->status = DHCPV6_STATUS_SUCCESS; - - length -= DHCPV6_OPTION_IAPREFIX_HEADER_SIZE; - while (length > 0) { - uint16_t code, sublen; - - ret = net_pkt_read_be16(pkt, &code); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_be16(pkt, &sublen); - if (ret < 0) { - return ret; - } - - switch (code) { - case DHCPV6_OPTION_CODE_STATUS_CODE: - ret = dhcpv6_parse_option_status_code(pkt, sublen, - &iaprefix->status); - if (ret < 0) { - return ret; - } - - break; - default: - net_pkt_skip(pkt, sublen); - NET_DBG("Unexpected option %d length %d", code, sublen); - break; - } - - length -= (sublen + 4); - } - - return 0; -} - -static int dhcpv6_parse_option_ia_pd(struct net_pkt *pkt, uint16_t length, - struct dhcpv6_ia_pd *ia_pd) -{ - int ret; - - if (length < DHCPV6_OPTION_IA_PD_HEADER_SIZE) { - NET_ERR("Invalid IA_PD option size"); - return -EMSGSIZE; - } - - ret = net_pkt_read_be32(pkt, &ia_pd->iaid); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_be32(pkt, &ia_pd->t1); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_be32(pkt, &ia_pd->t2); - if (ret < 0) { - return ret; - } - - /* DHCPv6 RFC8415, ch. 21.21 If a client receives an IA_PD with T1 - * greater than T2 and both T1 and T2 are greater than 0, the client - * discards the IA_PD option and processes the remainder of the message - * as though the server had not included the IA_PD option. - */ - if (ia_pd->t1 != 0 && ia_pd->t2 != 0 && ia_pd->t1 > ia_pd->t2) { - return -ENOENT; - } - - NET_DBG("iaid %d t1 %d t2 %d", ia_pd->iaid, ia_pd->t1, ia_pd->t2); - - /* In case there's no IAPREFIX option, make this visible be setting - * error status. If the option is present, option parser will overwrite - * the value. - */ - ia_pd->iaprefix.status = DHCPV6_STATUS_NO_PREFIX_AVAIL; - ia_pd->status = DHCPV6_STATUS_SUCCESS; - - length -= DHCPV6_OPTION_IA_PD_HEADER_SIZE; - while (length > 0) { - uint16_t code, sublen; - - ret = net_pkt_read_be16(pkt, &code); - if (ret < 0) { - return ret; - } - - ret = net_pkt_read_be16(pkt, &sublen); - if (ret < 0) { - return ret; - } - - switch (code) { - case DHCPV6_OPTION_CODE_IAPREFIX: - ret = dhcpv6_parse_option_iaprefix(pkt, sublen, - &ia_pd->iaprefix); - if (ret < 0) { - return ret; - } - - break; - - case DHCPV6_OPTION_CODE_STATUS_CODE: - ret = dhcpv6_parse_option_status_code(pkt, sublen, - &ia_pd->status); - if (ret < 0) { - return ret; - } - - break; - default: - net_pkt_skip(pkt, sublen); - NET_DBG("Unexpected option %d length %d", code, sublen); - break; - } - - length -= (sublen + 4); - } - - return 0; -} - -static int dhcpv6_find_option(struct net_pkt *pkt, enum dhcpv6_option_code opt_code, - uint16_t *opt_len) -{ - uint16_t length; - uint16_t code; - - while (net_pkt_read_be16(pkt, &code) == 0) { - if (net_pkt_read_be16(pkt, &length) < 0) { - return -EBADMSG; - } - - if (code == opt_code) { - *opt_len = length; - return 0; - } - - net_pkt_skip(pkt, length); - } - - return -ENOENT; -} - -static int dhcpv6_find_clientid(struct net_pkt *pkt, - struct net_dhcpv6_duid_storage *clientid) -{ - struct net_pkt_cursor backup; - uint16_t length; - int ret; - - net_pkt_cursor_backup(pkt, &backup); - - ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_CLIENTID, &length); - if (ret == 0) { - ret = dhcpv6_parse_option_clientid(pkt, length, clientid); - } - - net_pkt_cursor_restore(pkt, &backup); - - return ret; -} - -static int dhcpv6_find_serverid(struct net_pkt *pkt, - struct net_dhcpv6_duid_storage *serverid) -{ - struct net_pkt_cursor backup; - uint16_t length; - int ret; - - net_pkt_cursor_backup(pkt, &backup); - - ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_SERVERID, &length); - if (ret == 0) { - ret = dhcpv6_parse_option_serverid(pkt, length, serverid); - } - - net_pkt_cursor_restore(pkt, &backup); - - return ret; -} - -static int dhcpv6_find_server_preference(struct net_pkt *pkt, - uint8_t *preference) -{ - struct net_pkt_cursor backup; - uint16_t length; - int ret; - - net_pkt_cursor_backup(pkt, &backup); - - ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_PREFERENCE, &length); - if (ret == 0) { - ret = dhcpv6_parse_option_preference(pkt, length, preference); - } else if (ret == -ENOENT) { - /* In case no preference option is present, default to 0. - * DHCPv6 RFC8415, ch. 18.2.1. - */ - *preference = 0; - ret = 0; - } - - net_pkt_cursor_restore(pkt, &backup); - - return ret; -} - -static int dhcpv6_find_ia_na(struct net_pkt *pkt, struct dhcpv6_ia_na *ia_na) -{ - struct net_pkt_cursor backup; - uint16_t length; - int ret; - - net_pkt_cursor_backup(pkt, &backup); - - ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_IA_NA, &length); - if (ret == 0) { - ret = dhcpv6_parse_option_ia_na(pkt, length, ia_na); - } - - net_pkt_cursor_restore(pkt, &backup); - - return ret; -} - -static int dhcpv6_find_ia_pd(struct net_pkt *pkt, struct dhcpv6_ia_pd *ia_pd) -{ - struct net_pkt_cursor backup; - uint16_t length; - int ret; - - net_pkt_cursor_backup(pkt, &backup); - - ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_IA_PD, &length); - if (ret == 0) { - ret = dhcpv6_parse_option_ia_pd(pkt, length, ia_pd); - } - - net_pkt_cursor_restore(pkt, &backup); - - return ret; -} - -static int dhcpv6_find_status_code(struct net_pkt *pkt, uint16_t *status) -{ - struct net_pkt_cursor backup; - uint16_t length; - int ret; - - net_pkt_cursor_backup(pkt, &backup); - - ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_STATUS_CODE, &length); - if (ret == 0) { - ret = dhcpv6_parse_option_status_code(pkt, length, status); - } else if (ret == -ENOENT) { - /* In case no status option is present, default to success. - * DHCPv6 RFC8415, ch. 21.13. - */ - *status = DHCPV6_STATUS_SUCCESS; - ret = 0; - } - - net_pkt_cursor_restore(pkt, &backup); - - return ret; -} - -/* DHCPv6 state changes */ - -static void dhcpv6_enter_init(struct net_if *iface) -{ - uint32_t timeout; - - /* RFC8415 requires to wait a random period up to 1 second before - * sending the initial solicit/information request/confirm. - */ - timeout = sys_rand32_get() % DHCPV6_SOL_MAX_DELAY; - - dhcpv6_set_timeout(iface, timeout); -} - -static void dhcpv6_enter_soliciting(struct net_if *iface) -{ - iface->config.dhcpv6.retransmit_timeout = - dhcpv6_initial_retransmit_time(DHCPV6_SOL_TIMEOUT); - iface->config.dhcpv6.retransmissions = 0; - iface->config.dhcpv6.server_preference = -1; - iface->config.dhcpv6.exchange_start = k_uptime_get(); - - (void)dhcpv6_send_solicit(iface); - dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); -} - -static void dhcpv6_enter_requesting(struct net_if *iface) -{ - iface->config.dhcpv6.retransmit_timeout = - dhcpv6_initial_retransmit_time(DHCPV6_REQ_TIMEOUT); - iface->config.dhcpv6.retransmissions = 0; - iface->config.dhcpv6.exchange_start = k_uptime_get(); - - (void)dhcpv6_send_request(iface); - dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); -} - -static void dhcpv6_enter_renewing(struct net_if *iface) -{ - iface->config.dhcpv6.retransmit_timeout = - dhcpv6_initial_retransmit_time(DHCPV6_REN_TIMEOUT); - iface->config.dhcpv6.retransmissions = 0; - iface->config.dhcpv6.exchange_start = k_uptime_get(); - - (void)dhcpv6_send_renew(iface); - dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); -} - -static void dhcpv6_enter_rebinding(struct net_if *iface) -{ - iface->config.dhcpv6.retransmit_timeout = - dhcpv6_initial_retransmit_time(DHCPV6_REB_TIMEOUT); - iface->config.dhcpv6.retransmissions = 0; - iface->config.dhcpv6.exchange_start = k_uptime_get(); - - (void)dhcpv6_send_rebind(iface); - dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); -} - -static void dhcpv6_enter_confirming(struct net_if *iface) -{ - iface->config.dhcpv6.retransmit_timeout = - dhcpv6_initial_retransmit_time(DHCPV6_CNF_TIMEOUT); - iface->config.dhcpv6.retransmissions = 0; - iface->config.dhcpv6.exchange_start = k_uptime_get(); - - (void)dhcpv6_send_confirm(iface); - dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); -} - -static void dhcpv6_enter_bound(struct net_if *iface) -{ - iface->config.dhcpv6.timeout = iface->config.dhcpv6.t1; -} - -static void dhcpv6_enter_state(struct net_if *iface, enum net_dhcpv6_state state) -{ - iface->config.dhcpv6.state = state; - - NET_DBG("enter state=%s", - net_dhcpv6_state_name(iface->config.dhcpv6.state)); - - switch (iface->config.dhcpv6.state) { - case NET_DHCPV6_DISABLED: - break; - case NET_DHCPV6_INIT: - return dhcpv6_enter_init(iface); - case NET_DHCPV6_SOLICITING: - return dhcpv6_enter_soliciting(iface); - case NET_DHCPV6_REQUESTING: - return dhcpv6_enter_requesting(iface); - case NET_DHCPV6_CONFIRMING: - return dhcpv6_enter_confirming(iface); - case NET_DHCPV6_RENEWING: - return dhcpv6_enter_renewing(iface); - case NET_DHCPV6_REBINDING: - return dhcpv6_enter_rebinding(iface); - case NET_DHCPV6_INFO_REQUESTING: - break; - case NET_DHCPV6_BOUND: - return dhcpv6_enter_bound(iface); - } -} - -/* DHCPv6 input processing */ - -static int dhcpv6_handle_advertise(struct net_if *iface, struct net_pkt *pkt, - uint8_t *tid) -{ - struct net_dhcpv6_duid_storage duid = { 0 }; - struct dhcpv6_ia_pd ia_pd = { 0 }; - struct dhcpv6_ia_na ia_na = { 0 }; - uint8_t server_preference = 0; - uint16_t status = 0; - int ret; - - if (iface->config.dhcpv6.state != NET_DHCPV6_SOLICITING) { - return -EINVAL; - } - - /* Verify client ID. */ - ret = dhcpv6_find_clientid(pkt, &duid); - if (ret < 0) { - NET_ERR("Client ID missing"); - return ret; - } - - if (iface->config.dhcpv6.clientid.length != duid.length || - memcmp(&iface->config.dhcpv6.clientid.duid, &duid.duid, - iface->config.dhcpv6.clientid.length) != 0) { - NET_ERR("Client ID mismatch"); - return -EBADMSG; - } - - /* Verify server ID is present. */ - memset(&duid, 0, sizeof(duid)); - ret = dhcpv6_find_serverid(pkt, &duid); - if (ret < 0) { - NET_ERR("Server ID missing"); - return ret; - } - - /* Verify TID. */ - if (memcmp(iface->config.dhcpv6.tid, tid, - sizeof(iface->config.dhcpv6.tid)) != 0) { - NET_INFO("TID mismatch"); - return -EBADMSG; - } - - /* Verify status code. */ - ret = dhcpv6_find_status_code(pkt, &status); - if (ret < 0) { - return ret; - } - - if (status != DHCPV6_STATUS_SUCCESS) { - /* Ignore. */ - return 0; - } - - /* TODO Process SOL_MAX_RT/INF_MAX_RT options. */ - - /* Verify server preference. */ - ret = dhcpv6_find_server_preference(pkt, &server_preference); - if (ret < 0) { - return ret; - } - - if ((int16_t)server_preference < iface->config.dhcpv6.server_preference) { - /* Ignore. */ - return 0; - } - - /* Find/verify address. */ - if (iface->config.dhcpv6.params.request_addr) { - ret = dhcpv6_find_ia_na(pkt, &ia_na); - if (ret < 0) { - NET_ERR("Address missing"); - return ret; - } - - if (ia_na.status != DHCPV6_STATUS_SUCCESS || - ia_na.iaaddr.status != DHCPV6_STATUS_SUCCESS) { - /* Ignore. */ - return 0; - } - } - - /* Find/verify prefix. */ - if (iface->config.dhcpv6.params.request_prefix) { - ret = dhcpv6_find_ia_pd(pkt, &ia_pd); - if (ret < 0) { - NET_ERR("Prefix missing"); - return ret; - } - - if (ia_pd.status != DHCPV6_STATUS_SUCCESS || - ia_pd.iaprefix.status != DHCPV6_STATUS_SUCCESS) { - /* Ignore. */ - return 0; - } - } - - /* Valid advertisement received, store received offer. */ - memcpy(&iface->config.dhcpv6.serverid, &duid, - sizeof(iface->config.dhcpv6.serverid)); - iface->config.dhcpv6.server_preference = server_preference; - - /* DHCPv6 RFC8415, ch. 18.2.1, if client received Advertise - * message with maximum preference, or after the first - * retransmission period, it should proceed with the exchange, - * w/o further wait. - */ - if (server_preference == DHCPV6_MAX_SERVER_PREFERENCE || - iface->config.dhcpv6.retransmissions > 0) { - /* Reschedule immediately */ - dhcpv6_enter_state(iface, NET_DHCPV6_REQUESTING); - dhcpv6_reschedule(); - } - - return 0; -} - -static int dhcpv6_handle_reply(struct net_if *iface, struct net_pkt *pkt, - uint8_t *tid) -{ - struct net_dhcpv6_duid_storage duid = { 0 }; - struct dhcpv6_ia_pd ia_pd = { 0 }; - struct dhcpv6_ia_na ia_na = { 0 }; - int64_t now = k_uptime_get(); - uint16_t status = 0; - bool rediscover = false; - int ret; - - if (iface->config.dhcpv6.state != NET_DHCPV6_REQUESTING && - iface->config.dhcpv6.state != NET_DHCPV6_CONFIRMING && - iface->config.dhcpv6.state != NET_DHCPV6_RENEWING && - iface->config.dhcpv6.state != NET_DHCPV6_REBINDING) { - return -EINVAL; - } - - /* Verify client ID. */ - ret = dhcpv6_find_clientid(pkt, &duid); - if (ret < 0) { - NET_ERR("Client ID missing"); - return ret; - } - - if (iface->config.dhcpv6.clientid.length != duid.length || - memcmp(&iface->config.dhcpv6.clientid.duid, &duid.duid, - iface->config.dhcpv6.clientid.length) != 0) { - NET_ERR("Client ID mismatch"); - return -EBADMSG; - } - - /* Verify server ID is present. */ - memset(&duid, 0, sizeof(duid)); - ret = dhcpv6_find_serverid(pkt, &duid); - if (ret < 0) { - NET_ERR("Server ID missing"); - return ret; - } - - /* Verify TID. */ - if (memcmp(iface->config.dhcpv6.tid, tid, - sizeof(iface->config.dhcpv6.tid)) != 0) { - NET_INFO("TID mismatch"); - return -EBADMSG; - } - - /* TODO Process SOL_MAX_RT/INF_MAX_RT options. */ - - /* Verify status code. */ - ret = dhcpv6_find_status_code(pkt, &status); - if (ret < 0) { - return ret; - } - - if (status == DHCPV6_STATUS_UNSPEC_FAIL) { - /* Ignore and try again later. */ - return 0; - } - - /* DHCPv6 RFC8415, ch. 18.2.10.1. If the client receives a NotOnLink - * status from the server in response to (...) Request, the client can - * either reissue the message without specifying any addresses or - * restart the DHCP server discovery process. - * - * Restart discovery for our case. - */ - if (iface->config.dhcpv6.state == NET_DHCPV6_REQUESTING && - status == DHCPV6_STATUS_NOT_ON_LINK) { - rediscover = true; - goto out; - } - - /* In case of Confirm Reply, status success indicates the client can - * still use the address. - */ - if (iface->config.dhcpv6.state == NET_DHCPV6_CONFIRMING) { - if (status != DHCPV6_STATUS_SUCCESS) { - rediscover = true; - } - - goto out; - } - - /* Find/verify address. */ - if (iface->config.dhcpv6.params.request_addr) { - ret = dhcpv6_find_ia_na(pkt, &ia_na); - if (ret < 0) { - NET_ERR("Address missing"); - return ret; - } - - if (iface->config.dhcpv6.addr_iaid != ia_na.iaid) { - return -EBADMSG; - } - } - - /* Find/verify prefix. */ - if (iface->config.dhcpv6.params.request_prefix) { - ret = dhcpv6_find_ia_pd(pkt, &ia_pd); - if (ret < 0) { - NET_ERR("Prefix missing"); - return ret; - } - - if (iface->config.dhcpv6.prefix_iaid != ia_pd.iaid) { - return -EBADMSG; - } - } - - /* Valid response received, store received data. */ - iface->config.dhcpv6.t1 = UINT64_MAX; - iface->config.dhcpv6.t2 = UINT64_MAX; - iface->config.dhcpv6.expire = now; - - if (iface->config.dhcpv6.params.request_addr) { - struct net_if_addr *ifaddr; - - if (ia_na.status == DHCPV6_STATUS_NO_ADDR_AVAIL || - ia_na.iaaddr.status == DHCPV6_STATUS_NO_ADDR_AVAIL || - ia_na.iaaddr.valid_lifetime == 0) { - /* Remove old lease. */ - net_if_ipv6_addr_rm(iface, &iface->config.dhcpv6.addr); - memset(&iface->config.dhcpv6.addr, 0, sizeof(struct in6_addr)); - rediscover = true; - goto prefix; - } - - /* TODO On nobiding (renew/rebind) go to requesting */ - - if (!net_ipv6_addr_cmp(&iface->config.dhcpv6.addr, - net_ipv6_unspecified_address()) && - !net_ipv6_addr_cmp(&iface->config.dhcpv6.addr, - &ia_na.iaaddr.addr)) { - /* Remove old lease. */ - net_if_ipv6_addr_rm(iface, &iface->config.dhcpv6.addr); - } - - memcpy(&iface->config.dhcpv6.addr, &ia_na.iaaddr.addr, - sizeof(iface->config.dhcpv6.addr)); - - dhcvp6_update_deadlines(iface, now, ia_na.t1, ia_na.t2, - ia_na.iaaddr.preferred_lifetime, - ia_na.iaaddr.valid_lifetime); - - ifaddr = net_if_ipv6_addr_lookup_by_iface(iface, &ia_na.iaaddr.addr); - if (ifaddr != NULL) { - net_if_ipv6_addr_update_lifetime( - ifaddr, ia_na.iaaddr.valid_lifetime); - } else if (net_if_ipv6_addr_add(iface, &ia_na.iaaddr.addr, NET_ADDR_DHCP, - ia_na.iaaddr.valid_lifetime) == NULL) { - NET_ERR("Failed to configure DHCPv6 address"); - net_dhcpv6_stop(iface); - return -EFAULT; - } - } - -prefix: - if (iface->config.dhcpv6.params.request_prefix) { - struct net_if_ipv6_prefix *ifprefix; - - if (ia_pd.status == DHCPV6_STATUS_NO_PREFIX_AVAIL || - ia_pd.iaprefix.status == DHCPV6_STATUS_NO_PREFIX_AVAIL || - ia_pd.iaprefix.valid_lifetime == 0) { - /* Remove old lease. */ - net_if_ipv6_prefix_rm(iface, &iface->config.dhcpv6.prefix, - iface->config.dhcpv6.prefix_len); - memset(&iface->config.dhcpv6.prefix, 0, sizeof(struct in6_addr)); - iface->config.dhcpv6.prefix_len = 0; - rediscover = true; - goto out; - } - - if (!net_ipv6_addr_cmp(&iface->config.dhcpv6.prefix, - net_ipv6_unspecified_address()) && - (!net_ipv6_addr_cmp(&iface->config.dhcpv6.prefix, - &ia_pd.iaprefix.prefix) || - iface->config.dhcpv6.prefix_len != ia_pd.iaprefix.prefix_len)) { - /* Remove old lease. */ - net_if_ipv6_prefix_rm(iface, &iface->config.dhcpv6.prefix, - iface->config.dhcpv6.prefix_len); - } - - iface->config.dhcpv6.prefix_len = ia_pd.iaprefix.prefix_len; - - memcpy(&iface->config.dhcpv6.prefix, &ia_pd.iaprefix.prefix, - sizeof(iface->config.dhcpv6.prefix)); - - dhcvp6_update_deadlines(iface, now, ia_pd.t1, ia_pd.t2, - ia_pd.iaprefix.preferred_lifetime, - ia_pd.iaprefix.valid_lifetime); - - ifprefix = net_if_ipv6_prefix_lookup(iface, &ia_pd.iaprefix.prefix, - ia_pd.iaprefix.prefix_len); - if (ifprefix != NULL) { - net_if_ipv6_prefix_set_timer(ifprefix, ia_pd.iaprefix.valid_lifetime); - } else if (net_if_ipv6_prefix_add(iface, &ia_pd.iaprefix.prefix, - ia_pd.iaprefix.prefix_len, - ia_pd.iaprefix.valid_lifetime) == NULL) { - NET_ERR("Failed to configure DHCPv6 prefix"); - net_dhcpv6_stop(iface); - return -EFAULT; - } - } - -out: - if (rediscover) { - dhcpv6_enter_state(iface, NET_DHCPV6_SOLICITING); - } else { - dhcpv6_enter_state(iface, NET_DHCPV6_BOUND); - } - - dhcpv6_reschedule(); - - return 0; -} - -static int dhcpv6_handle_reconfigure(struct net_if *iface, struct net_pkt *pkt) -{ - /* Reconfigure not supported yet. */ - return -ENOTSUP; -} - -static enum net_verdict dhcpv6_input(struct net_conn *conn, - struct net_pkt *pkt, - union net_ip_header *ip_hdr, - union net_proto_header *proto_hdr, - void *user_data) -{ - struct net_if *iface; - uint8_t msg_type; - uint8_t tid[DHCPV6_TID_SIZE]; - int ret; - - if (!conn) { - NET_ERR("Invalid connection"); - return NET_DROP; - } - - if (!pkt) { - NET_ERR("Invalid packet"); - return NET_DROP; - } - - iface = net_pkt_iface(pkt); - if (!iface) { - NET_ERR("No interface"); - return NET_DROP; - } - - net_pkt_cursor_init(pkt); - - if (net_pkt_skip(pkt, NET_IPV6UDPH_LEN)) { - NET_ERR("Missing IPv6/UDP header"); - return NET_DROP; - } - - if (net_pkt_read_u8(pkt, &msg_type) < 0) { - NET_ERR("Missing message type"); - return NET_DROP; - } - - if (net_pkt_read(pkt, tid, sizeof(tid)) < 0) { - NET_ERR("Missing transaction ID"); - return NET_DROP; - } - - NET_DBG("Received DHCPv6 packet [type=%d, tid=0x%02x%02x%02x]", - msg_type, tid[0], tid[1], tid[2]); - - switch (msg_type) { - case DHCPV6_MSG_TYPE_ADVERTISE: - ret = dhcpv6_handle_advertise(iface, pkt, tid); - break; - case DHCPV6_MSG_TYPE_REPLY: - ret = dhcpv6_handle_reply(iface, pkt, tid); - break; - case DHCPV6_MSG_TYPE_RECONFIGURE: - ret = dhcpv6_handle_reconfigure(iface, pkt); - break; - case DHCPV6_MSG_TYPE_SOLICIT: - case DHCPV6_MSG_TYPE_REQUEST: - case DHCPV6_MSG_TYPE_CONFIRM: - case DHCPV6_MSG_TYPE_RENEW: - case DHCPV6_MSG_TYPE_REBIND: - case DHCPV6_MSG_TYPE_RELEASE: - case DHCPV6_MSG_TYPE_DECLINE: - case DHCPV6_MSG_TYPE_INFORMATION_REQUEST: - case DHCPV6_MSG_TYPE_RELAY_FORW: - case DHCPV6_MSG_TYPE_RELAY_REPL: - default: - goto drop; - } - - if (ret < 0) { - goto drop; - } - - net_pkt_unref(pkt); - - return NET_OK; - -drop: - return NET_DROP; -} - -/* DHCPv6 timer management */ - -static uint64_t dhcpv6_timeleft(struct net_if *iface, int64_t now) -{ - uint64_t timeout = iface->config.dhcpv6.timeout; - - if (timeout > now) { - return timeout - now; - } - - return 0; -} - -static uint64_t dhcpv6_manage_timers(struct net_if *iface, int64_t now) -{ - uint64_t timeleft = dhcpv6_timeleft(iface, now); - - NET_DBG("iface %p state=%s timeleft=%llu", iface, - net_dhcpv6_state_name(iface->config.dhcpv6.state), timeleft); - - if (timeleft != 0U) { - return iface->config.dhcpv6.timeout; - } - - if (!net_if_is_up(iface)) { - /* An interface is down, the registered event handler will - * restart DHCP procedure when the interface is back up. - */ - return UINT64_MAX; - } - - switch (iface->config.dhcpv6.state) { - case NET_DHCPV6_DISABLED: - break; - case NET_DHCPV6_INIT: { - bool have_addr = false; - bool have_prefix = false; - - if (iface->config.dhcpv6.params.request_addr && - !net_ipv6_addr_cmp(&iface->config.dhcpv6.addr, - net_ipv6_unspecified_address())) { - have_addr = true; - } - - if (iface->config.dhcpv6.params.request_prefix && - !net_ipv6_addr_cmp(&iface->config.dhcpv6.prefix, - net_ipv6_unspecified_address())) { - have_prefix = true; - } - - if ((have_addr || have_prefix) && now < iface->config.dhcpv6.expire) { - /* Try to confirm the address/prefix. In case - * prefix is requested, Rebind is used with - * Confirm timings. - */ - iface->config.dhcpv6.expire = now + DHCPV6_CNF_MAX_RD; - - if (!iface->config.dhcpv6.params.request_prefix) { - dhcpv6_enter_state(iface, NET_DHCPV6_CONFIRMING); - } else { - dhcpv6_enter_state(iface, NET_DHCPV6_REBINDING); - } - } else { - dhcpv6_enter_state(iface, NET_DHCPV6_SOLICITING); - } - - return iface->config.dhcpv6.timeout; - } - case NET_DHCPV6_SOLICITING: - if (iface->config.dhcpv6.server_preference >= 0) { - dhcpv6_enter_state(iface, NET_DHCPV6_REQUESTING); - return iface->config.dhcpv6.timeout; - } - - iface->config.dhcpv6.retransmissions++; - iface->config.dhcpv6.retransmit_timeout = - dhcpv6_next_retransmit_time( - iface->config.dhcpv6.retransmit_timeout, - DHCPV6_SOL_MAX_RT); - - (void)dhcpv6_send_solicit(iface); - dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); - - return iface->config.dhcpv6.timeout; - case NET_DHCPV6_REQUESTING: - if (iface->config.dhcpv6.retransmissions >= DHCPV6_REQ_MAX_RC) { - /* Back to soliciting. */ - dhcpv6_enter_state(iface, NET_DHCPV6_SOLICITING); - return iface->config.dhcpv6.timeout; - } - - iface->config.dhcpv6.retransmissions++; - iface->config.dhcpv6.retransmit_timeout = - dhcpv6_next_retransmit_time( - iface->config.dhcpv6.retransmit_timeout, - DHCPV6_REQ_MAX_RT); - - (void)dhcpv6_send_request(iface); - dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); - - return iface->config.dhcpv6.timeout; - case NET_DHCPV6_CONFIRMING: - if (now >= iface->config.dhcpv6.expire) { - dhcpv6_enter_state(iface, NET_DHCPV6_SOLICITING); - return iface->config.dhcpv6.timeout; - } - - iface->config.dhcpv6.retransmissions++; - iface->config.dhcpv6.retransmit_timeout = - dhcpv6_next_retransmit_time( - iface->config.dhcpv6.retransmit_timeout, - DHCPV6_CNF_MAX_RT); - - (void)dhcpv6_send_confirm(iface); - dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); - - if (iface->config.dhcpv6.timeout > iface->config.dhcpv6.expire) { - iface->config.dhcpv6.timeout = iface->config.dhcpv6.expire; - } - - return iface->config.dhcpv6.timeout; - case NET_DHCPV6_RENEWING: - if (now >= iface->config.dhcpv6.t2) { - dhcpv6_enter_state(iface, NET_DHCPV6_REBINDING); - return iface->config.dhcpv6.timeout; - } - - iface->config.dhcpv6.retransmissions++; - iface->config.dhcpv6.retransmit_timeout = - dhcpv6_next_retransmit_time( - iface->config.dhcpv6.retransmit_timeout, - DHCPV6_REN_MAX_RT); - - (void)dhcpv6_send_renew(iface); - dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); - - if (iface->config.dhcpv6.timeout > iface->config.dhcpv6.t2) { - iface->config.dhcpv6.timeout = iface->config.dhcpv6.t2; - } - - return iface->config.dhcpv6.timeout; - case NET_DHCPV6_REBINDING: - if (now >= iface->config.dhcpv6.expire) { - dhcpv6_enter_state(iface, NET_DHCPV6_SOLICITING); - return iface->config.dhcpv6.timeout; - } - - iface->config.dhcpv6.retransmissions++; - iface->config.dhcpv6.retransmit_timeout = - dhcpv6_next_retransmit_time( - iface->config.dhcpv6.retransmit_timeout, - DHCPV6_REB_MAX_RT); - - (void)dhcpv6_send_rebind(iface); - dhcpv6_set_timeout(iface, iface->config.dhcpv6.retransmit_timeout); - - if (iface->config.dhcpv6.timeout > iface->config.dhcpv6.expire) { - iface->config.dhcpv6.timeout = iface->config.dhcpv6.expire; - } - - return iface->config.dhcpv6.timeout; - case NET_DHCPV6_INFO_REQUESTING: - break; - case NET_DHCPV6_BOUND: - dhcpv6_enter_state(iface, NET_DHCPV6_RENEWING); - return iface->config.dhcpv6.timeout; - } - - return UINT64_MAX; -} - -static void dhcpv6_timeout(struct k_work *work) -{ - uint64_t timeout_update = UINT64_MAX; - int64_t now = k_uptime_get(); - struct net_if_dhcpv6 *current, *next; - - ARG_UNUSED(work); - - k_mutex_lock(&lock, K_FOREVER); - - SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&dhcpv6_ifaces, current, next, node) { - struct net_if *iface = CONTAINER_OF( - CONTAINER_OF(current, struct net_if_config, dhcpv6), - struct net_if, config); - uint64_t next_timeout; - - next_timeout = dhcpv6_manage_timers(iface, now); - if (next_timeout < timeout_update) { - timeout_update = next_timeout; - } - } - - k_mutex_unlock(&lock); - - if (timeout_update != UINT64_MAX) { - if (now > timeout_update) { - timeout_update = 0ULL; - } else { - timeout_update -= now; - } - - NET_DBG("Waiting for %llums", timeout_update); - k_work_reschedule(&dhcpv6_timeout_work, K_MSEC(timeout_update)); - } -} - -static void dhcpv6_iface_event_handler(struct net_mgmt_event_callback *cb, - uint32_t mgmt_event, struct net_if *iface) -{ - sys_snode_t *node = NULL; - - k_mutex_lock(&lock, K_FOREVER); - - SYS_SLIST_FOR_EACH_NODE(&dhcpv6_ifaces, node) { - if (node == &iface->config.dhcpv6.node) { - break; - } - } - - if (node == NULL) { - goto out; - } - - if (mgmt_event == NET_EVENT_IF_DOWN) { - NET_DBG("Interface %p going down", iface); - dhcpv6_set_timeout(iface, UINT64_MAX); - } else if (mgmt_event == NET_EVENT_IF_UP) { - NET_DBG("Interface %p coming up", iface); - dhcpv6_enter_state(iface, NET_DHCPV6_INIT); - } - - dhcpv6_reschedule(); - -out: - k_mutex_unlock(&lock); -} - -static void dhcpv6_generate_client_duid(struct net_if *iface) -{ - struct net_linkaddr *lladdr = net_if_get_link_addr(iface); - struct net_dhcpv6_duid_storage *clientid = &iface->config.dhcpv6.clientid; - struct dhcpv6_duid_ll *duid_ll = - (struct dhcpv6_duid_ll *)&clientid->duid.buf; - - memset(clientid, 0, sizeof(*clientid)); - - UNALIGNED_PUT(htons(DHCPV6_DUID_TYPE_LL), &clientid->duid.type); - UNALIGNED_PUT(htons(DHCPV6_HARDWARE_ETHERNET_TYPE), &duid_ll->hw_type); - memcpy(duid_ll->ll_addr, lladdr->addr, lladdr->len); - - clientid->length = DHCPV6_DUID_LL_HEADER_SIZE + lladdr->len; -} - -/* DHCPv6 public API */ - -void net_dhcpv6_start(struct net_if *iface, struct net_dhcpv6_params *params) -{ - k_mutex_lock(&lock, K_FOREVER); - - if (iface->config.dhcpv6.state != NET_DHCPV6_DISABLED) { - NET_ERR("DHCPv6 already running on iface %p, state %s", iface, - net_dhcpv6_state_name(iface->config.dhcpv6.state)); - goto out; - } - - if (!params->request_addr && !params->request_addr) { - NET_ERR("Information Request not supported yet"); - goto out; - } - - NET_DBG("Starting DHCPv6 on iface %p", iface); - - iface->config.dhcpv6.params = *params; - - if (sys_slist_is_empty(&dhcpv6_ifaces)) { - net_mgmt_add_event_callback(&dhcpv6_mgmt_cb); - } - - sys_slist_append(&dhcpv6_ifaces, &iface->config.dhcpv6.node); - - if (params->request_addr) { - iface->config.dhcpv6.addr_iaid = net_if_get_by_iface(iface); - } - - if (params->request_prefix) { - iface->config.dhcpv6.prefix_iaid = net_if_get_by_iface(iface); - } - - dhcpv6_generate_client_duid(iface); - dhcpv6_enter_state(iface, NET_DHCPV6_INIT); - dhcpv6_reschedule(); - -out: - k_mutex_unlock(&lock); -} - -void net_dhcpv6_stop(struct net_if *iface) -{ - k_mutex_lock(&lock, K_FOREVER); - - switch (iface->config.dhcpv6.state) { - case NET_DHCPV6_DISABLED: - NET_INFO("DHCPv6 already disabled on iface %p", iface); - break; - - case NET_DHCPV6_INIT: - case NET_DHCPV6_SOLICITING: - case NET_DHCPV6_REQUESTING: - case NET_DHCPV6_CONFIRMING: - case NET_DHCPV6_RENEWING: - case NET_DHCPV6_REBINDING: - case NET_DHCPV6_INFO_REQUESTING: - case NET_DHCPV6_BOUND: - NET_DBG("Stopping DHCPv6 on iface %p, state %s", iface, - net_dhcpv6_state_name(iface->config.dhcpv6.state)); - - (void)dhcpv6_enter_state(iface, NET_DHCPV6_DISABLED); - - sys_slist_find_and_remove(&dhcpv6_ifaces, - &iface->config.dhcpv6.node); - - if (sys_slist_is_empty(&dhcpv6_ifaces)) { - (void)k_work_cancel_delayable(&dhcpv6_timeout_work); - net_mgmt_del_event_callback(&dhcpv6_mgmt_cb); - } - - break; - } - - k_mutex_unlock(&lock); -} - -void net_dhcpv6_restart(struct net_if *iface) -{ - struct net_dhcpv6_params params = iface->config.dhcpv6.params; - - net_dhcpv6_stop(iface); - net_dhcpv6_start(iface, ¶ms); -} - -int net_dhcpv6_init(void) -{ - struct sockaddr unspec_addr; - int ret; - - net_ipaddr_copy(&net_sin6(&unspec_addr)->sin6_addr, - net_ipv6_unspecified_address()); - unspec_addr.sa_family = AF_INET6; - - ret = net_udp_register(AF_INET6, NULL, &unspec_addr, - DHCPV6_SERVER_PORT, DHCPV6_CLIENT_PORT, - NULL, dhcpv6_input, NULL, NULL); - if (ret < 0) { - NET_DBG("UDP callback registration failed"); - return ret; - } - - k_work_init_delayable(&dhcpv6_timeout_work, dhcpv6_timeout); - net_mgmt_init_event_callback(&dhcpv6_mgmt_cb, dhcpv6_iface_event_handler, - NET_EVENT_IF_DOWN | NET_EVENT_IF_UP); - - return 0; -} diff --git a/subsys/net/ip/dhcpv6_internal.h b/subsys/net/ip/dhcpv6_internal.h deleted file mode 100644 index 5ec129e601f..00000000000 --- a/subsys/net/ip/dhcpv6_internal.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** @file - * @brief DHCPv6 internal header - * - * This header should not be included by the application. - */ - -#ifndef DHCPV6_INTERNAL_H_ -#define DHCPV6_INTERNAL_H_ - -#include - -#define DHCPV6_DUID_TYPE_SIZE 2 -#define DHVPV6_DUID_LL_HW_TYPE_SIZE 2 -#define DHCPV6_DUID_LL_HEADER_SIZE (DHCPV6_DUID_TYPE_SIZE + \ - DHVPV6_DUID_LL_HW_TYPE_SIZE) - -#define DHCPV6_MSG_TYPE_SIZE 1 -#define DHCPV6_HEADER_SIZE (DHCPV6_MSG_TYPE_SIZE + DHCPV6_TID_SIZE) - -#define DHCPV6_OPTION_CODE_SIZE 2 -#define DHCPV6_OPTION_LENGTH_SIZE 2 -#define DHCPV6_OPTION_HEADER_SIZE (DHCPV6_OPTION_CODE_SIZE + \ - DHCPV6_OPTION_LENGTH_SIZE) - -#define DHCPV6_OPTION_PREFERENCE_SIZE 1 -#define DHCPV6_OPTION_ELAPSED_TIME_SIZE 2 -#define DHCPV6_OPTION_ELAPSED_TIME_SIZE 2 -#define DHCPV6_OPTION_IA_NA_HEADER_SIZE 12 -#define DHCPV6_OPTION_IAADDR_HEADER_SIZE 24 -#define DHCPV6_OPTION_IA_PD_HEADER_SIZE 12 -#define DHCPV6_OPTION_IAPREFIX_HEADER_SIZE 25 -#define DHCPV6_OPTION_IAADDR_HEADER_SIZE 24 -#define DHCPV6_OPTION_IAPREFIX_HEADER_SIZE 25 -#define DHCPV6_OPTION_STATUS_CODE_HEADER_SIZE 2 - -#define DHCPV6_INFINITY UINT32_MAX -#define DHCPV6_MAX_SERVER_PREFERENCE 255 - -#define DHCPV6_HARDWARE_ETHERNET_TYPE 1 - -#define DHCPV6_CLIENT_PORT 546 -#define DHCPV6_SERVER_PORT 547 - -/* DHCPv6 Transmission/retransmission timeouts */ -#define DHCPV6_SOL_MAX_DELAY 1000 /* Max delay of first Solicit, milliseconds */ -#define DHCPV6_SOL_TIMEOUT 1000 /* Initial Solicit timeout, milliseconds */ -#define DHCPV6_SOL_MAX_RT 3600000 /* Max Solicit timeout value, milliseconds */ -#define DHCPV6_REQ_TIMEOUT 1000 /* Initial Request timeout, milliseconds */ -#define DHCPV6_REQ_MAX_RT 30000 /* Max Request timeout value, milliseconds */ -#define DHCPV6_REQ_MAX_RC 10 /* Max Request retry attempts */ -#define DHCPV6_CNF_MAX_DELAY 1000 /* Max delay of first Confirm, milliseconds */ -#define DHCPV6_CNF_TIMEOUT 1000 /* Initial Confirm timeout, milliseconds */ -#define DHCPV6_CNF_MAX_RT 4000 /* Max Confirm timeout, milliseconds */ -#define DHCPV6_CNF_MAX_RD 10000 /* Max Confirm duration, milliseconds */ -#define DHCPV6_REN_TIMEOUT 10000 /* Initial Renew timeout, milliseconds */ -#define DHCPV6_REN_MAX_RT 600000 /* Max Renew timeout value, milliseconds */ -#define DHCPV6_REB_TIMEOUT 10000 /* Initial Rebind timeout, milliseconds */ -#define DHCPV6_REB_MAX_RT 600000 /* Max Rebind timeout value, milliseconds */ - -/* DUID structures */ -struct dhcpv6_duid_llt { - uint16_t hw_type; - uint32_t time; - uint8_t ll_addr[]; -} __packed; - -struct dhcpv6_duid_en { - uint32_t enterprise_number; - uint8_t identifier[]; -} __packed; - -struct dhcpv6_duid_ll { - uint16_t hw_type; - uint8_t ll_addr[]; -} __packed; - -struct dhcpv6_duid_uuid { - uint8_t uuid[16]; -} __packed; - -struct dhcpv6_msg_hdr { - uint8_t type; /* Message type */ - uint8_t tid[3]; /* Transaction ID */ -} __packed; - -struct dhcpv6_iaaddr { - uint32_t preferred_lifetime; - uint32_t valid_lifetime; - struct in6_addr addr; - uint16_t status; -}; - -struct dhcpv6_ia_na { - uint32_t iaid; - uint32_t t1; - uint32_t t2; - uint16_t status; - struct dhcpv6_iaaddr iaaddr; -}; - -struct dhcpv6_iaprefix { - uint32_t preferred_lifetime; - uint32_t valid_lifetime; - struct in6_addr prefix; - uint8_t prefix_len; - uint16_t status; -}; - -struct dhcpv6_ia_pd { - uint32_t iaid; - uint32_t t1; - uint32_t t2; - uint16_t status; - struct dhcpv6_iaprefix iaprefix; -}; - -/* DHCPv6 message types, RFC8415, ch. 7.3. */ -enum dhcpv6_msg_type { - DHCPV6_MSG_TYPE_SOLICIT = 1, - DHCPV6_MSG_TYPE_ADVERTISE = 2, - DHCPV6_MSG_TYPE_REQUEST = 3, - DHCPV6_MSG_TYPE_CONFIRM = 4, - DHCPV6_MSG_TYPE_RENEW = 5, - DHCPV6_MSG_TYPE_REBIND = 6, - DHCPV6_MSG_TYPE_REPLY = 7, - DHCPV6_MSG_TYPE_RELEASE = 8, - DHCPV6_MSG_TYPE_DECLINE = 9, - DHCPV6_MSG_TYPE_RECONFIGURE = 10, - DHCPV6_MSG_TYPE_INFORMATION_REQUEST = 11, - DHCPV6_MSG_TYPE_RELAY_FORW = 12, - DHCPV6_MSG_TYPE_RELAY_REPL = 13, -}; - -/* DHCPv6 option codes, RFC8415, ch. 21. */ -enum dhcpv6_option_code { - DHCPV6_OPTION_CODE_CLIENTID = 1, - DHCPV6_OPTION_CODE_SERVERID = 2, - DHCPV6_OPTION_CODE_IA_NA = 3, - DHCPV6_OPTION_CODE_IA_TA = 4, - DHCPV6_OPTION_CODE_IAADDR = 5, - DHCPV6_OPTION_CODE_ORO = 6, - DHCPV6_OPTION_CODE_PREFERENCE = 7, - DHCPV6_OPTION_CODE_ELAPSED_TIME = 8, - DHCPV6_OPTION_CODE_RELAY_MSG = 9, - DHCPV6_OPTION_CODE_AUTH = 11, - DHCPV6_OPTION_CODE_UNICAST = 12, - DHCPV6_OPTION_CODE_STATUS_CODE = 13, - DHCPV6_OPTION_CODE_RAPID_COMMIT = 14, - DHCPV6_OPTION_CODE_USER_CLASS = 15, - DHCPV6_OPTION_CODE_VENDOR_CLASS = 16, - DHCPV6_OPTION_CODE_VENDOR_OPTS = 17, - DHCPV6_OPTION_CODE_INTERFACE_ID = 18, - DHCPV6_OPTION_CODE_RECONF_MSG = 19, - DHCPV6_OPTION_CODE_RECONF_ACCEPT = 20, - DHCPV6_OPTION_CODE_IA_PD = 25, - DHCPV6_OPTION_CODE_IAPREFIX = 26, - DHCPV6_OPTION_CODE_INFORMATION_REFRESH_TIME = 32, - DHCPV6_OPTION_CODE_SOL_MAX_RT = 82, - DHCPV6_OPTION_CODE_INF_MAX_RT = 83, -}; - -/* DHCPv6 option codes, RFC8415, ch. 21.13. */ -enum dhcpv6_status_code { - DHCPV6_STATUS_SUCCESS = 0, - DHCPV6_STATUS_UNSPEC_FAIL = 1, - DHCPV6_STATUS_NO_ADDR_AVAIL = 2, - DHCPV6_STATUS_NO_BINDING = 3, - DHCPV6_STATUS_NOT_ON_LINK = 4, - DHCPV6_STATUS_USE_MULTICAST = 5, - DHCPV6_STATUS_NO_PREFIX_AVAIL = 6, -}; - -/* DHCPv6 Unique Identifier types, RFC8415, ch. 11.1. */ -enum dhcpv6_duid_type { - DHCPV6_DUID_TYPE_LLT = 1, /* Based on Link-Layer Address Plus Time */ - DHCPV6_DUID_TYPE_EN = 2, /* Assigned by Vendor Based on Enterprise Number */ - DHCPV6_DUID_TYPE_LL = 3, /* Based on Link-Layer Address */ - DHCPV6_DUID_TYPE_UUID = 4, /* Based on Universally Unique Identifier */ -}; - -#if defined(CONFIG_NET_DHCPV6) -int net_dhcpv6_init(void); -#else -static inline int net_dhcpv6_init(void) -{ - return 0; -} -#endif /* CONFIG_NET_DHCPV6 */ - -#endif /* DHCPV6_INTERNAL_H_ */ diff --git a/subsys/net/ip/net_core.c b/subsys/net/ip/net_core.c index c94607b4485..00829dfcf90 100644 --- a/subsys/net/ip/net_core.c +++ b/subsys/net/ip/net_core.c @@ -45,7 +45,6 @@ LOG_MODULE_REGISTER(net_core, CONFIG_NET_CORE_LOG_LEVEL); #include "ipv4.h" #include "dhcpv4.h" -#include "dhcpv6_internal.h" #include "route.h" @@ -476,11 +475,6 @@ static inline int services_init(void) return status; } - status = net_dhcpv6_init(); - if (status != 0) { - return status; - } - dns_init_resolver(); websocket_init(); From 935c78e222eda7fb0dd612b1d201e6ae7efba7ba Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:32 +0000 Subject: [PATCH 0815/1623] Revert "[nrf noup] mgmt/MCUmgr/grp/img: Move out label to make compiler happy" This reverts commit 45ac1f809fef282566c124dc676c951428d707bc. Signed-off-by: Dominik Ermel --- subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c index 61515c14655..0968694c614 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c @@ -290,14 +290,13 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) return_slot = other_slot; } } -out: - #else if (rcs == 0 && rca == 0 && img_mgmt_vercmp(&aver, &over) < 0) { return_slot = other_slot; } #endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */ +out: if (type != NULL) { *type = lt; } From 965571eb172a2c9e2c273b88699227708ef537bd Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:33 +0000 Subject: [PATCH 0816/1623] Revert "[nrf fromtree] modules/MCUboot: Fix missing dependency" This reverts commit 8b829dcc8fdcd8d95fea171110fb3bec07a6f616. Signed-off-by: Dominik Ermel --- modules/Kconfig.mcuboot | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index 1679bfeb8a9..ab1dd44fbd5 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -192,7 +192,6 @@ config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT bool "MCUboot has been configured for DirectXIP with revert" select MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP - select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE select MCUBOOT_BOOTLOADER_NO_DOWNGRADE help MCUboot expects slot0_partition and slot1_partition to exist in DT. From 57324dc7a033224bbedc0fca1a4199f95b7fc0cb Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:33 +0000 Subject: [PATCH 0817/1623] Revert "[nrf fromtree] doc/release-notes: Add info on downgrade prevention Kconfig" This reverts commit c43324fe1614052517c8037351231e715c7f7d18. Signed-off-by: Dominik Ermel --- doc/releases/release-notes-3.5.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/releases/release-notes-3.5.rst b/doc/releases/release-notes-3.5.rst index d22978d8a84..4f9a8ab1793 100644 --- a/doc/releases/release-notes-3.5.rst +++ b/doc/releases/release-notes-3.5.rst @@ -339,11 +339,6 @@ HALs MCUboot ******* - * Added :kconfig:option:`CONFIG_MCUBOOT_BOOTLOADER_NO_DOWNGRADE` - that allows to inform application that the on-board MCUboot has been configured - with downgrade prevention enabled. This option is automatically selected for - DirectXIP mode and is available for both swap modes. - Storage ******* From ecac00de5e846efacfef81312cb7cdb7964dc8ec Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:34 +0000 Subject: [PATCH 0818/1623] Revert "[nrf fromtree] modules/MCUboot: Add new Kconfig indicating downgrade prevention" This reverts commit 8f6ede70c0db2e328b72e350ec5e6b79040d557c. Signed-off-by: Dominik Ermel --- modules/Kconfig.mcuboot | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index ab1dd44fbd5..5f83098a577 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -116,7 +116,7 @@ config MCUBOOT_EXTRA_IMGTOOL_ARGS help When signing (CONFIG_MCUBOOT_SIGNATURE_KEY_FILE is a non-empty string) you can use this option to pass extra options to - imgtool. For example, you could set this to "--version 1.2". + imgtool. For example, you could set this to "--version 1.2". config MCUBOOT_GENERATE_UNSIGNED_IMAGE bool "Generate unsigned binary image bootable with MCUboot" @@ -136,8 +136,6 @@ config MCUBOOT_GENERATE_CONFIRMED_IMAGE The existence of bin and hex files depends on CONFIG_BUILD_OUTPUT_BIN and CONFIG_BUILD_OUTPUT_HEX. -menu "On board MCUboot operation mode" - choice MCUBOOT_BOOTLOADER_MODE prompt "Application assumed MCUboot mode of operation" default MCUBOOT_BOOTLOADER_MODE_SWAP_WITHOUT_SCRATCH # MCUBOOT_BOOTLOADER_MODE @@ -156,43 +154,31 @@ config MCUBOOT_BOOTLOADER_MODE_SINGLE_APP config MCUBOOT_BOOTLOADER_MODE_SWAP_WITHOUT_SCRATCH bool "MCUboot has been configured for swap without scratch operation" - select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE help MCUboot expects slot0_partition and slot1_partition to be present in DT and application will boot from slot0_partition. - MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected - if MCUboot has been built with MCUBOOT_DOWNGRADE_PREVENTION. config MCUBOOT_BOOTLOADER_MODE_SWAP_SCRATCH bool "MCUboot has been configured for swap using scratch operation" - select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE help MCUboot expects slot0_partition, slot1_partition and scratch_partition to be present in DT, and application will boot from slot0_partition. In this mode scratch_partition is used as temporary storage when MCUboot swaps application from the secondary slot to the primary slot. - MCUBOOT_BOOTLOADER_NO_DOWNGRADE should also be selected - if MCUboot has been built with MCUBOOT_DOWNGRADE_PREVENTION. config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP bool "MCUboot has been configured for DirectXIP operation" - select MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE - select MCUBOOT_BOOTLOADER_NO_DOWNGRADE help MCUboot expects slot0_partition and slot1_partition to exist in DT. In this mode MCUboot can boot from either partition and will select one with higher application image version, which usually means major.minor.patch triple, unless BOOT_VERSION_CMP_USE_BUILD_NUMBER is also selected that enables comparison of build number. - This option automatically selectes - MCUBOOT_BOOTLOADER_NO_DOWNGRADE as it is not possible - to swap back to older version of application. config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT bool "MCUboot has been configured for DirectXIP with revert" select MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP - select MCUBOOT_BOOTLOADER_NO_DOWNGRADE help MCUboot expects slot0_partition and slot1_partition to exist in DT. In this mode MCUboot will boot the application with the higher version @@ -204,30 +190,9 @@ config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT This mode does not allow freely switching between application versions, as, once higher version application is approved, it is not possible to select lower version for boot. - This mode selects MCUBOOT_BOOTLOADER_NO_DOWNGRADE as it is not possible - to downgrade running application, but note that MCUboot may do that - if application with higher version will not get confirmed. endchoice # MCUBOOT_BOOTLOADER_MODE -config MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE - bool - help - Selected mode supports downgrade prevention, where you cannot switch to - an application with lower version than the currently running application. - -if MCUBOOT_BOOTLOADER_MODE_HAS_NO_DOWNGRADE -config MCUBOOT_BOOTLOADER_NO_DOWNGRADE - bool "MCUboot mode has downgrade prevention enabled" - help - Selected MCUboot mode has downgrade prevention enabled, where you are not - able to change back to image with lower version number. - This options should be selected when MCUboot has been built with - MCUBOOT_DOWNGRADE_PREVENTION option enabled. -endif - -endmenu # On board MCUboot operation mode - endif # BOOTLOADER_MCUBOOT menuconfig MCUBOOT_BOOTUTIL_LIB From 8c2b4befd3c7ee478fb83f8d9e2371812ac5d8d9 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:34 +0000 Subject: [PATCH 0819/1623] Revert "[nrf fromtree] samples/mcumgr/smp_svr: Build for DirectXIP with revert" This reverts commit 0e63631f6734ba12b8d5a8c02eeb706796d9f046. Signed-off-by: Dominik Ermel --- samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml b/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml index a13270e5845..ed7ffe8f33e 100644 --- a/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml +++ b/samples/subsys/mgmt/mcumgr/smp_svr/sample.yaml @@ -43,19 +43,6 @@ tests: - mg100 integration_platforms: - nrf52840dk_nrf52840 - # In mcuboot_flags test overlay-serial.conf is used for convenience as it is the simplest - # transport. Transport does not affect flags so it does not really matter which is selected, - # flags should affect any transport the same way. - sample.mcumgr.smp_svr.mcuboot_flags.direct_xip_withrevert: - extra_args: OVERLAY_CONFIG="overlay-serial.conf" - extra_configs: - - CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT=y - platform_allow: - - nrf52840dk_nrf52840 - - pinnacle_100_dvk - - mg100 - integration_platforms: - - nrf52840dk_nrf52840 sample.mcumgr.smp_svr.serial-console: extra_args: OVERLAY_CONFIG="overlay-serial-console.conf" platform_allow: From 8dbb168dd4d4bf2ce58a0163273eb399c2d82ad0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:34 +0000 Subject: [PATCH 0820/1623] Revert "[nrf fromtree] mgmt/MCUmgr/grp/img: Add support for DirectXIP with revert" This reverts commit 38f9d7e6f240c55d996e510e9a9d5deca27753cd. Signed-off-by: Dominik Ermel --- modules/Kconfig.mcuboot | 24 --- .../mcumgr/grp/img_mgmt/src/img_mgmt_state.c | 201 ++++-------------- 2 files changed, 40 insertions(+), 185 deletions(-) diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index 5f83098a577..0bb47d8854c 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -176,21 +176,6 @@ config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP means major.minor.patch triple, unless BOOT_VERSION_CMP_USE_BUILD_NUMBER is also selected that enables comparison of build number. -config MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT - bool "MCUboot has been configured for DirectXIP with revert" - select MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP - help - MCUboot expects slot0_partition and slot1_partition to exist in DT. - In this mode MCUboot will boot the application with the higher version - from either slot, as long as it has been marked to be boot - next time for test or permanently. In case when application is marked - for test it needs to confirm itself, on the first boot, or it will - be removed and MCUboot will revert to booting previously approved - application. - This mode does not allow freely switching between application - versions, as, once higher version application is approved, it is - not possible to select lower version for boot. - endchoice # MCUBOOT_BOOTLOADER_MODE endif # BOOTLOADER_MCUBOOT @@ -223,13 +208,4 @@ config BOOT_IMAGE_ACCESS_HOOKS It is up to the application project to add source file which implements hooks to the build. -if MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT - -config MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP - bool - help - Adds support for setting for test and confirming images - when bootloader is in DirectXIP-revert mode. -endif - endif # MCUBOOT_BOOTUTIL_LIB diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c index 0968694c614..a782acb92ee 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c @@ -55,14 +55,6 @@ LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL); #define REPORT_SLOT_PENDING BIT(1) #define REPORT_SLOT_CONFIRMED BIT(2) #define REPORT_SLOT_PERMANENT BIT(3) - -#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) -#define DIRECT_XIP_BOOT_UNSET 0 -#define DIRECT_XIP_BOOT_ONCE 1 -#define DIRECT_XIP_BOOT_REVERT 2 -#define DIRECT_XIP_BOOT_FOREVER 3 -#endif - /** * Collects information about the specified image slot. */ @@ -147,8 +139,7 @@ img_mgmt_state_flags(int query_slot) } #endif -#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) && \ - !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) +#ifndef CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) { const int active_slot = img_mgmt_active_slot(image); @@ -197,115 +188,27 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) return slot; } #else - -#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) - -static int read_directxip_state(int slot) -{ - struct boot_swap_state bss; - int fa_id = img_mgmt_flash_area_id(slot); - const struct flash_area *fa; - int rc = 0; - - __ASSERT(fa_id != -1, "Could not map slot to area ID"); - - rc = flash_area_open(fa_id, &fa); - if (rc < 0) { - return rc; - } - rc = boot_read_swap_state(fa, &bss); - flash_area_close(fa); - if (rc != 0) { - LOG_ERR("Failed to read state of slot %d with error %d", slot, rc); - return -1; - } - - if (bss.magic == BOOT_MAGIC_GOOD) { - if (bss.image_ok == BOOT_FLAG_SET) { - return DIRECT_XIP_BOOT_FOREVER; - } else if (bss.copy_done == BOOT_FLAG_SET) { - return DIRECT_XIP_BOOT_REVERT; - } - return DIRECT_XIP_BOOT_ONCE; - } - return DIRECT_XIP_BOOT_UNSET; -} -#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */ - int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) { struct image_version aver; struct image_version over; int active_slot = img_mgmt_active_slot(image); int other_slot = img_mgmt_get_opposite_slot(active_slot); -#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) - int active_slot_state; - int other_slot_state; -#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */ - enum img_mgmt_next_boot_type lt = NEXT_BOOT_TYPE_NORMAL; - int return_slot = active_slot; + if (type != NULL) { + *type = NEXT_BOOT_TYPE_NORMAL; + } int rcs = img_mgmt_read_info(other_slot, &over, NULL, NULL); int rca = img_mgmt_read_info(active_slot, &aver, NULL, NULL); -#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) - active_slot_state = read_directxip_state(active_slot); - other_slot_state = read_directxip_state(other_slot); - if (rca != 0 || - (rcs != 0 && rcs != IMG_MGMT_ERR_NO_IMAGE)) { - /* We do not really know what will happen, as we can not - * read states from bootloader. - */ - LOG_ERR("img_mgmt_read_info_failed rca = %d, rcs = %d", - rca, rcs); - goto out; - } - if (other_slot_state < 0 || active_slot_state < 0) { - LOG_ERR("Slot state read failed with status: active %d, other %d", - active_slot_state, other_slot_state); - /* We do not really know what will happen, as we can not - * read states from bootloader. - */ - goto out; - } - - /* There is not other image, the active one will boot next time */ - if (rcs == IMG_MGMT_ERR_NO_IMAGE) { - goto out; - } - - if (active_slot_state == DIRECT_XIP_BOOT_REVERT) { - lt = NEXT_BOOT_TYPE_REVERT; - return_slot = other_slot; - } else if (other_slot_state == DIRECT_XIP_BOOT_UNSET) { - if (active_slot_state == DIRECT_XIP_BOOT_ONCE) { - lt = NEXT_BOOT_TYPE_TEST; - } - } else if (img_mgmt_vercmp(&aver, &over) < 0) { - if (other_slot_state == DIRECT_XIP_BOOT_FOREVER) { - return_slot = other_slot; - } else if (other_slot_state == DIRECT_XIP_BOOT_ONCE) { - lt = NEXT_BOOT_TYPE_TEST; - return_slot = other_slot; - } - } -#else if (rcs == 0 && rca == 0 && img_mgmt_vercmp(&aver, &over) < 0) { - return_slot = other_slot; + return other_slot; } -#endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */ -out: - if (type != NULL) { - *type = lt; - } - - return return_slot; + return active_slot; } -#endif /* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) && \ - * !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) - */ +#endif /** @@ -519,53 +422,11 @@ img_mgmt_state_read(struct smp_streamer *ctxt) return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE; } -static int img_mgmt_set_next_boot_slot_common(int slot, int active_slot, bool confirm) +int img_mgmt_set_next_boot_slot(int slot, bool confirm) { const struct flash_area *fa; int area_id = img_mgmt_flash_area_id(slot); int rc = 0; - - if (flash_area_open(area_id, &fa) != 0) { - return IMG_MGMT_ERR_FLASH_OPEN_FAILED; - } - - rc = boot_set_next(fa, slot == active_slot, confirm); - if (rc != 0) { - /* Failed to set next slot for boot as desired */ - LOG_ERR("Faled boot_set_next with code %d, for slot %d," - " with active slot %d and confirm %d", - rc, slot, active_slot, confirm); - - /* Translate from boot util error code to IMG mgmt group error code */ - if (rc == BOOT_EFLASH) { - rc = IMG_MGMT_ERR_FLASH_WRITE_FAILED; - } else if (rc == BOOT_EBADVECT) { - rc = IMG_MGMT_ERR_INVALID_IMAGE_VECTOR_TABLE; - } else if (rc == BOOT_EBADIMAGE) { - rc = IMG_MGMT_ERR_INVALID_IMAGE_HEADER_MAGIC; - } else { - rc = IMG_MGMT_ERR_UNKNOWN; - } - } - flash_area_close(fa); - -#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS) - if (rc == 0 && slot == active_slot && confirm) { - int32_t err_rc; - uint16_t err_group; - - /* Confirm event is only sent for active slot */ - (void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_CONFIRMED, NULL, 0, &err_rc, - &err_group); - } -#endif - - return rc; -} - -#ifndef CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT -int img_mgmt_set_next_boot_slot(int slot, bool confirm) -{ /* image the requested slot is defined within */ int image = img_mgmt_slot_to_image(slot); /* active_slot is slot that is considered active/primary/executing @@ -637,26 +498,44 @@ int img_mgmt_set_next_boot_slot(int slot, bool confirm) /* Allow confirming slot == active_slot */ } - return img_mgmt_set_next_boot_slot_common(slot, active_slot, confirm); -} -#else -int img_mgmt_set_next_boot_slot(int slot, bool confirm) -{ - int active_image = img_mgmt_active_image(); - int active_slot = img_mgmt_active_slot(active_image); + if (flash_area_open(area_id, &fa) != 0) { + return IMG_MGMT_ERR_FLASH_OPEN_FAILED; + } - LOG_DBG("(%d, %s)", slot, confirm ? "confirm" : "test"); - LOG_DBG("aimg = %d, aslot = %d, slot = %d", - active_image, active_slot, slot); + rc = boot_set_next(fa, slot == active_slot, confirm); + if (rc != 0) { + /* Failed to set next slot for boot as desired */ + LOG_ERR("Faled boot_set_next with code %d, for slot %d," + " with active slot %d and confirm %d", + rc, slot, active_slot, confirm); - if (slot == active_slot && !confirm) { - return IMG_MGMT_ERR_IMAGE_SETTING_TEST_TO_ACTIVE_DENIED; + /* Translate from boot util error code to IMG mgmt group error code */ + if (rc == BOOT_EFLASH) { + rc = IMG_MGMT_ERR_FLASH_WRITE_FAILED; + } else if (rc == BOOT_EBADVECT) { + rc = IMG_MGMT_ERR_INVALID_IMAGE_VECTOR_TABLE; + } else if (rc == BOOT_EBADIMAGE) { + rc = IMG_MGMT_ERR_INVALID_IMAGE_HEADER_MAGIC; + } else { + rc = IMG_MGMT_ERR_UNKNOWN; + } } + flash_area_close(fa); - return img_mgmt_set_next_boot_slot_common(slot, active_slot, confirm); -} +#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS) + if (slot == active_slot && confirm) { + int32_t err_rc; + uint16_t err_group; + + /* Confirm event is only sent for active slot */ + (void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_CONFIRMED, NULL, 0, &err_rc, + &err_group); + } #endif + return rc; +} + /** * Command handler: image state write */ From 0780e653d8c7bd98ea40edf7a360b83f48c71a8a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:35 +0000 Subject: [PATCH 0821/1623] Revert "[nrf fromtree] drivers/flash/nrf: Workaround for nrf91 errata 7" This reverts commit 885245b9c1eb4ecd0a3eb6825a70e97422ea2db9. Signed-off-by: Dominik Ermel --- drivers/flash/soc_flash_nrf.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/drivers/flash/soc_flash_nrf.c b/drivers/flash/soc_flash_nrf.c index ea76ae1e3f8..f38492a41d1 100644 --- a/drivers/flash/soc_flash_nrf.c +++ b/drivers/flash/soc_flash_nrf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2023 Nordic Semiconductor ASA + * Copyright (c) 2017-2018 Nordic Semiconductor ASA * Copyright (c) 2016 Linaro Limited * Copyright (c) 2016 Intel Corporation * @@ -121,26 +121,6 @@ static inline bool is_uicr_addr_valid(off_t addr, size_t len) #endif /* CONFIG_SOC_FLASH_NRF_UICR */ } -#if CONFIG_SOC_FLASH_NRF_UICR && IS_ENABLED(NRF91_ERRATA_7_ENABLE_WORKAROUND) -static inline void nrf91_errata_7_enter(void) -{ - __disable_irq(); -} - -static inline void nrf91_errata_7_exit(void) -{ - __DSB(); - __enable_irq(); -} - -static void nrf_buffer_read_91_uicr(void *data, off_t addr, size_t len) -{ - nrf91_errata_7_enter(); - nrf_nvmc_buffer_read(data, (uint32_t)addr, len); - nrf91_errata_7_exit(); -} -#endif - static void nvmc_wait_ready(void) { while (!nrfx_nvmc_write_done_check()) { @@ -150,11 +130,9 @@ static void nvmc_wait_ready(void) static int flash_nrf_read(const struct device *dev, off_t addr, void *data, size_t len) { - const bool within_uicr = is_uicr_addr_valid(addr, len); - if (is_regular_addr_valid(addr, len)) { addr += DT_REG_ADDR(SOC_NV_FLASH_NODE); - } else if (!within_uicr) { + } else if (!is_uicr_addr_valid(addr, len)) { LOG_ERR("invalid address: 0x%08lx:%zu", (unsigned long)addr, len); return -EINVAL; @@ -169,12 +147,6 @@ static int flash_nrf_read(const struct device *dev, off_t addr, return soc_secure_mem_read(data, (void *)addr, len); } #endif -#if CONFIG_SOC_FLASH_NRF_UICR && IS_ENABLED(NRF91_ERRATA_7_ENABLE_WORKAROUND) - if (within_uicr) { - nrf_buffer_read_91_uicr(data, (uint32_t)addr, len); - return 0; - } -#endif nrf_nvmc_buffer_read(data, (uint32_t)addr, len); From 7700c8b43fa015e8643ba7d6dc5fd5495ce7f70e Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:35 +0000 Subject: [PATCH 0822/1623] Revert "[nrf fromtree] twister: pytest: Allow list of pytest testpaths" This reverts commit 29ccece157fa10782a41b8fa1eee15759174e24d. Signed-off-by: Dominik Ermel --- scripts/pylib/twister/twisterlib/harness.py | 5 +- scripts/schemas/twister/testsuite-schema.yaml | 8 +-- .../pytest_integration/test_harness_pytest.py | 61 ------------------- 3 files changed, 4 insertions(+), 70 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index 6ae2622c810..96b4a2e3461 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -245,20 +245,19 @@ def pytest_run(self, timeout): def generate_command(self): config = self.instance.testsuite.harness_config - pytest_root = config.get('pytest_root', ['pytest']) if config else ['pytest'] + pytest_root = config.get('pytest_root', 'pytest') if config else 'pytest' pytest_args = config.get('pytest_args', []) if config else [] command = [ 'pytest', '--twister-harness', '-s', '-v', + os.path.join(self.source_dir, pytest_root), f'--build-dir={self.running_dir}', f'--junit-xml={self.report_file}', '--log-file-level=DEBUG', '--log-file-format=%(asctime)s.%(msecs)d:%(levelname)s:%(name)s: %(message)s', f'--log-file={self.pytest_log_file_path}' ] - command.extend([os.path.normpath(os.path.join( - self.source_dir, os.path.expanduser(os.path.expandvars(src)))) for src in pytest_root]) command.extend(pytest_args) handler: Handler = self.instance.handler diff --git a/scripts/schemas/twister/testsuite-schema.yaml b/scripts/schemas/twister/testsuite-schema.yaml index 96a121767a5..116c1a43379 100644 --- a/scripts/schemas/twister/testsuite-schema.yaml +++ b/scripts/schemas/twister/testsuite-schema.yaml @@ -95,10 +95,8 @@ mapping: type: int required: false "pytest_root": - type: seq + type: str required: false - sequence: - - type: str "pytest_args": type: seq required: false @@ -295,10 +293,8 @@ mapping: type: int required: false "pytest_root": - type: seq + type: str required: false - sequence: - - type: str "pytest_args": type: seq required: false diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index e1b27a0cf02..db7bf389fbd 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -48,67 +48,6 @@ def test_pytest_command(testinstance: TestInstance, device_type): assert c in command -@pytest.mark.parametrize( - ('pytest_root', 'expected'), - [ - ( - ['pytest/test_shell_help.py'], - ['samples/hello/pytest/test_shell_help.py'] - ), - ( - ['pytest/test_shell_help.py', 'pytest/test_shell_version.py', 'test_dir'], - ['samples/hello/pytest/test_shell_help.py', - 'samples/hello/pytest/test_shell_version.py', - 'samples/hello/test_dir'] - ), - ( - ['../shell/pytest/test_shell.py'], - ['samples/shell/pytest/test_shell.py'] - ), - ( - ['/tmp/test_temp.py'], - ['/tmp/test_temp.py'] - ), - ( - ['~/tmp/test_temp.py'], - ['/home/joe/tmp/test_temp.py'] - ), - ( - ['$ZEPHYR_BASE/samples/subsys/testsuite/pytest/shell/pytest'], - ['/zephyr_base/samples/subsys/testsuite/pytest/shell/pytest'] - ), - ( - ['pytest/test_shell_help.py::test_A', 'pytest/test_shell_help.py::test_B'], - ['samples/hello/pytest/test_shell_help.py::test_A', - 'samples/hello/pytest/test_shell_help.py::test_B'] - ), - ( - ['pytest/test_shell_help.py::test_A[param_a]'], - ['samples/hello/pytest/test_shell_help.py::test_A[param_a]'] - ) - ], - ids=[ - 'one_file', - 'more_files', - 'relative_path', - 'absollute_path', - 'user_dir', - 'with_env_var', - 'subtests', - 'subtest_with_param' - ] -) -def test_pytest_handle_source_list(testinstance: TestInstance, monkeypatch, pytest_root, expected): - monkeypatch.setenv('ZEPHYR_BASE', '/zephyr_base') - monkeypatch.setenv('HOME', '/home/joe') - testinstance.testsuite.harness_config['pytest_root'] = pytest_root - pytest_harness = Pytest() - pytest_harness.configure(testinstance) - command = pytest_harness.generate_command() - for pytest_src in expected: - assert pytest_src in command - - def test_if_report_is_parsed(pytester, testinstance: TestInstance): test_file_content = textwrap.dedent(""" def test_1(): From 8eb0b81f23fd53225fd9914e64569d9541448cde Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:35 +0000 Subject: [PATCH 0823/1623] Revert "[nrf fromtree] twister: doc: Update pytest and twister docs" This reverts commit 801a64e6d1acfaac7bf1f5ebb2d647500464186e. Signed-off-by: Dominik Ermel --- doc/develop/test/pytest.rst | 55 +++++++++++++----------------------- doc/develop/test/twister.rst | 26 ++++++----------- 2 files changed, 28 insertions(+), 53 deletions(-) diff --git a/doc/develop/test/pytest.rst b/doc/develop/test/pytest.rst index d0fad4d6be6..97737ce0ae2 100644 --- a/doc/develop/test/pytest.rst +++ b/doc/develop/test/pytest.rst @@ -49,47 +49,28 @@ How to create a pytest test An example of a pytest test is given at :zephyr_file:`samples/subsys/testsuite/pytest/shell/pytest/test_shell.py`. Twister calls pytest for each configuration from the .yaml file which uses ``harness: pytest``. By default, it points to ``pytest`` directory, located next to a directory with binary sources. -A keyword ``pytest_root`` placed under ``harness_config`` section can be used to point to other -files, directories or subtests. +A keyword ``pytest_root`` placed under ``harness_config`` section can be used to point to another +location. -Pytest scans the given locations looking for tests, following its default +Pytest scans the given folder looking for tests, following its default `discovery rules `_ One can also pass some extra arguments to the pytest from yaml file using ``pytest_args`` keyword under ``harness_config``, e.g.: ``pytest_args: [‘-k=test_method’, ‘--log-level=DEBUG’]``. -Helpers & fixtures -================== - -dut ---- - -Give access to a DeviceAdapter type object, that represents Device Under Test. -This fixture is the core of pytest harness plugin. It is required to launch -DUT (initialize logging, flash device, connect serial etc). -This fixture yields a device prepared according to the requested type -(native posix, qemu, hardware, etc.). All types of devices share the same API. -This allows for writing tests which are device-type-agnostic. +Following import is required to include in .py sources: .. code-block:: python - from twister_harness import DeviceAdapter - - def test_sample(dut: DeviceAdapter): - dut.readlines_until('Hello world') - -shell ------ + from twister_harness import Device -Provide an object with methods used to interact with shell application. -It calls `wait_for_promt` method, to not start scenario until DUT is ready. -Note that it uses `dut` fixture, so `dut` can be skipped when `shell` is used. +It is important for type checking and enabling IDE hints for ``dut`` s (objects representing +Devices Under Test). The ``dut`` fixture is the core of pytest harness plugin. When used as an +argument of a test function it gives access to a DeviceAbstract type object. The fixture yields a +device prepared according to the requested type (native posix, qemu, hardware, etc.). All types of +devices share the same API. This allows for writing tests which are device-type-agnostic. -.. code-block:: python - - from twister_harness import Shell - - def test_shell(shell: Shell): - shell.exec_command('help') +Helpers & fixtures +================== mcumgr ------ @@ -101,15 +82,16 @@ More information about MCUmgr can be found here :ref:`mcu_mgr`. This fixture requires the ``mcumgr`` available in the system PATH Only selected functionality of MCUmgr is wrapped by this fixture. + For example, here is a test with a fixture ``mcumgr`` .. code-block:: python - from twister_harness import DeviceAdapter, Shell, McuMgr + from twister_harness import Device, McuMgr - def test_upgrade(dut: DeviceAdapter, shell: Shell, mcumgr: McuMgr): - # free the serial port for mcumgr - dut.disconnect() + def test_upgrade(dut: Device, mcumgr: McuMgr): + # wait for dut is up + time.sleep(2) # upload the signed image mcumgr.image_upload('path/to/zephyr.signed.bin') # obtain the hash of uploaded image from the device @@ -123,4 +105,7 @@ For example, here is a test with a fixture ``mcumgr`` Limitations *********** +* Device adapters in pytest plugin provide `iter_stdout` method to read from devices. In some + cases, it is not the most convenient way, and it will be considered how to improve this + (for example replace it with a simple read function with a given byte size and timeout arguments). * Not every platform type is supported in the plugin (yet). diff --git a/doc/develop/test/twister.rst b/doc/develop/test/twister.rst index 4456386b77c..a29890c7899 100644 --- a/doc/develop/test/twister.rst +++ b/doc/develop/test/twister.rst @@ -492,11 +492,10 @@ harness_config: Only one fixture can be defined per testcase and the fixture name has to be unique across all tests in the test suite. - pytest_root: (default pytest) - Specify a list of pytest directories, files or subtests that need to be executed - when test case begin to running, default pytest directory is pytest. - After pytest finished, twister will check if this case pass or fail according - to the pytest report. + pytest_root: (default pytest) + Specify a pytest directory which need to execute when test case begin to running, + default pytest directory name is pytest, after pytest finished, twister will + check if this case pass or fail according the pytest report. pytest_args: (default empty) Specify a list of additional arguments to pass to ``pytest``. @@ -527,24 +526,15 @@ harness_config: The following is an example yaml file with pytest harness_config options, default pytest_root name "pytest" will be used if pytest_root not specified. - please refer the examples in samples/subsys/testsuite/pytest/. + please refer the example in samples/subsys/testsuite/pytest/. :: - common: - harness: pytest tests: - pytest.example.directories: - harness_config: - pytest_root: - - pytest_dir1 - - $ENV_VAR/samples/test/pytest_dir2 - pytest.example.files_and_subtests: + pytest.example: + harness: pytest harness_config: - pytest_root: - - pytest/test_file_1.py - - test_file_2.py::test_A - - test_file_2.py::test_B[param_a] + pytest_root: [pytest directory name] The following is an example yaml file with robot harness_config options. From b368cf97e5780cc7bee67543c37875029a9c27de Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:35 +0000 Subject: [PATCH 0824/1623] Revert "[nrf fromtree] twister: pytest: Fix problems with no prompt in tests with shell" This reverts commit 90d276b0cd557bf7f3e35119e43106b09681194e. Signed-off-by: Dominik Ermel --- .../src/twister_harness/device/hardware_adapter.py | 1 - .../pytest-twister-harness/src/twister_harness/helpers/shell.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py index 403978eed9a..3a3f242fa85 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py @@ -250,7 +250,6 @@ def _clear_internal_resources(self) -> None: super()._clear_internal_resources() self._serial_connection = None self._serial_pty_proc = None - self._serial_buffer.clear() @staticmethod def _run_custom_script(script_path: str | Path, timeout: float) -> None: diff --git a/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/shell.py b/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/shell.py index 37f8ad432cf..fc8009d12fe 100644 --- a/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/shell.py +++ b/scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/shell.py @@ -57,7 +57,7 @@ def exec_command(self, command: str, timeout: float | None = None, print_output: timeout = timeout or self.base_timeout command_ext = f'{command}\n\n' regex_prompt = re.escape(self.prompt) - regex_command = f'.*{command}' + regex_command = f'{regex_prompt}.*{command}' self._device.clear_buffer() self._device.write(command_ext.encode()) lines: list[str] = [] From 7d756d53d9e6a05c31e749c4cf18364a9777b333 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:36 +0000 Subject: [PATCH 0825/1623] Revert "[nrf fromtree] scripts: domains: Convert Domain to a dataclass" This reverts commit 2cdbabc898855f447b8f17cd81548b16dfb6d045. Signed-off-by: Dominik Ermel --- scripts/pylib/build_helpers/domains.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/pylib/build_helpers/domains.py b/scripts/pylib/build_helpers/domains.py index 978569d9547..475844e9a61 100644 --- a/scripts/pylib/build_helpers/domains.py +++ b/scripts/pylib/build_helpers/domains.py @@ -8,8 +8,6 @@ Domain class. ''' -from dataclasses import dataclass - import yaml import pykwalify.core import logging @@ -121,8 +119,24 @@ def get_top_build_dir(self): return self._build_dir -@dataclass class Domain: - name: str - build_dir: str + def __init__(self, name, build_dir): + self.name = name + self.build_dir = build_dir + + @property + def name(self): + return self._name + + @name.setter + def name(self, value): + self._name = value + + @property + def build_dir(self): + return self._build_dir + + @build_dir.setter + def build_dir(self, value): + self._build_dir = value From 6fe9c05faad898fb5eabdcbe4159afa9a9a359a3 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:36 +0000 Subject: [PATCH 0826/1623] Revert "[nrf fromtree] scripts: domains: Support initialization only from YAML" This reverts commit f943f54c83a9ae04467dccdb01b33707bdcfffc0. Signed-off-by: Dominik Ermel --- scripts/pylib/build_helpers/domains.py | 32 ++++++++++++++------------ scripts/west_commands/build_helpers.py | 13 ++++------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/scripts/pylib/build_helpers/domains.py b/scripts/pylib/build_helpers/domains.py index 475844e9a61..f4c2f085fd2 100644 --- a/scripts/pylib/build_helpers/domains.py +++ b/scripts/pylib/build_helpers/domains.py @@ -56,15 +56,7 @@ class Domains: - def __init__(self, domains_yaml): - try: - data = yaml.safe_load(domains_yaml) - pykwalify.core.Core(source_data=data, - schema_data=schema).validate() - except (yaml.YAMLError, pykwalify.errors.SchemaError): - logger.critical(f'malformed domains.yaml') - exit(1) - + def __init__(self, data): self._build_dir = data['build_dir'] self._domains = { d['name']: Domain(d['name'], d['build_dir']) @@ -80,22 +72,32 @@ def __init__(self, domains_yaml): @staticmethod def from_file(domains_file): - '''Load domains from a domains.yaml file. + '''Load domains from domains.yaml. + + Exception raised: + - ``FileNotFoundError`` if the domains file is not found. ''' try: with open(domains_file, 'r') as f: - domains_yaml = f.read() + domains = yaml.safe_load(f.read()) except FileNotFoundError: logger.critical(f'domains.yaml file not found: {domains_file}') exit(1) - return Domains(domains_yaml) + try: + pykwalify.core.Core(source_data=domains, schema_data=schema)\ + .validate() + except pykwalify.errors.SchemaError: + logger.critical(f'ERROR: Malformed yaml in file: {domains_file}') + exit(1) + + return Domains(domains) @staticmethod - def from_yaml(domains_yaml): - '''Load domains from a string with YAML contents. + def from_data(domains_data): + '''Load domains from domains dictionary. ''' - return Domains(domains_yaml) + return Domains(domains_data) def get_domains(self, names=None, default_flash_order=False): if names is None: diff --git a/scripts/west_commands/build_helpers.py b/scripts/west_commands/build_helpers.py index ca6845f01da..88845e50f4b 100644 --- a/scripts/west_commands/build_helpers.py +++ b/scripts/west_commands/build_helpers.py @@ -151,14 +151,9 @@ def load_domains(path): domains_file = Path(path) / 'domains.yaml' if not domains_file.is_file(): - return Domains.from_yaml(f'''\ -default: app -build_dir: {path} -domains: - - name: app - build_dir: {path} -flash_order: - - app -''') + return Domains.from_data({'default': 'app', + 'build_dir': path, + 'domains': [{'name': 'app', 'build_dir': path}], + 'flash_order': ['app']}) return Domains.from_file(domains_file) From 6da59f61e5897b9205670be2e4555eb3e7ca95f5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:36 +0000 Subject: [PATCH 0827/1623] Revert "[nrf fromtree] scripts: domains: Tighten up initialization" This reverts commit 6df09b137cd799e5fdc1ef2371a70609f175e8c4. Signed-off-by: Dominik Ermel --- scripts/pylib/build_helpers/domains.py | 39 ++++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/scripts/pylib/build_helpers/domains.py b/scripts/pylib/build_helpers/domains.py index f4c2f085fd2..8cacac7b4e8 100644 --- a/scripts/pylib/build_helpers/domains.py +++ b/scripts/pylib/build_helpers/domains.py @@ -27,7 +27,7 @@ required: true type: str domains: - required: true + required: false type: seq sequence: - type: map @@ -57,18 +57,19 @@ class Domains: def __init__(self, data): - self._build_dir = data['build_dir'] + self._build_dir = data.get('build_dir') + domain_list = data.get('domains') or [] + if not domain_list: + logger.warning("no domains defined; this probably won't work") + self._domains = { d['name']: Domain(d['name'], d['build_dir']) - for d in data['domains'] + for d in domain_list } + self._default_domain = self._domains.get(data['default']) - # In the YAML data, the values for "default" and "flash_order" - # must not name any domains that aren't listed under "domains". - # Now that self._domains has been initialized, we can leverage - # the common checks in self.get_domain to verify this. - self._default_domain = self.get_domain(data['default']) - self._flash_order = self.get_domains(data['flash_order'] or []) + domains_flash_order = data.get('flash_order') or [] + self._flash_order = list(map(self._domains.get, domains_flash_order)) @staticmethod def from_file(domains_file): @@ -100,19 +101,21 @@ def from_data(domains_data): return Domains(domains_data) def get_domains(self, names=None, default_flash_order=False): - if names is None: + ret = [] + + if not names: if default_flash_order: return self._flash_order return list(self._domains.values()) - return list(map(self.get_domain, names)) - def get_domain(self, name): - found = self._domains.get(name) - if not found: - logger.critical(f'domain "{name}" not found, ' - f'valid domains are: {", ".join(self._domains)}') - exit(1) - return found + for n in names: + found = self._domains.get(n) + if not found: + logger.critical(f'domain {n} not found, ' + f'valid domains are: {", ".join(self._domains)}') + exit(1) + ret.append(found) + return ret def get_default_domain(self): return self._default_domain From 9fbef9dff521ac56b93f07da59e262653457421f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:36 +0000 Subject: [PATCH 0828/1623] Revert "[nrf fromtree] doc: sysbuild: Update documentation about BUILD_ONLY" This reverts commit 49df79f70077cc7a69125e7c9812c2764c24a501. Signed-off-by: Dominik Ermel --- doc/build/sysbuild/index.rst | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/doc/build/sysbuild/index.rst b/doc/build/sysbuild/index.rst index e09ee3e5617..2c53cb0e88a 100644 --- a/doc/build/sysbuild/index.rst +++ b/doc/build/sysbuild/index.rst @@ -569,19 +569,13 @@ You can mark ``my_sample`` as a build-only application in this manner: ) As a result, ``my_sample`` will be built as part of the sysbuild build invocation, -but it will be excluded from the default image sequence used by ``west flash``. +but neither ``west flash`` nor ``west debug`` will be aware of this application. Instead, you may use the outputs of this domain for other purposes - for example, to produce a secondary image for DFU, or to merge multiple images together. You can also replace ``TRUE`` with another boolean constant in CMake, such as a Kconfig option, which would make ``my_sample`` conditionally build-only. -.. note:: - - Applications marked as build-only can still be flashed manually, using - ``west flash --domain my_sample``. As such, the ``BUILD_ONLY`` option only - controls the default behavior of ``west flash``. - Zephyr application configuration ================================ From 3f299762f7e08675dd17ef898b0dddc63e211e2a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:37 +0000 Subject: [PATCH 0829/1623] Revert "[nrf fromtree] sysbuild: Do not exclude images from domains.yaml" This reverts commit 020dcdc2ab9118bf2960ef1feb396b79e6924b77. Signed-off-by: Dominik Ermel --- scripts/pylib/build_helpers/domains.py | 43 +++++++++++++------------- scripts/west_commands/build_helpers.py | 3 +- scripts/west_commands/flash.py | 3 +- share/sysbuild/cmake/domains.cmake | 11 +++---- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/scripts/pylib/build_helpers/domains.py b/scripts/pylib/build_helpers/domains.py index 8cacac7b4e8..c748a94a14f 100644 --- a/scripts/pylib/build_helpers/domains.py +++ b/scripts/pylib/build_helpers/domains.py @@ -38,11 +38,6 @@ build_dir: required: true type: str - flash_order: - required: false - type: seq - sequence: - - type: str ''' schema = yaml.safe_load(DOMAINS_SCHEMA) @@ -57,19 +52,21 @@ class Domains: def __init__(self, data): + self._domains = [] + self._domain_names = [] + self._domain_default = [] + self._build_dir = data.get('build_dir') - domain_list = data.get('domains') or [] + domain_list = data.get('domains') if not domain_list: logger.warning("no domains defined; this probably won't work") - self._domains = { - d['name']: Domain(d['name'], d['build_dir']) - for d in domain_list - } - self._default_domain = self._domains.get(data['default']) - - domains_flash_order = data.get('flash_order') or [] - self._flash_order = list(map(self._domains.get, domains_flash_order)) + for d in domain_list: + domain = Domain(d['name'], d['build_dir']) + self._domains.append(domain) + self._domain_names.append(domain.name) + if domain.name == data['default']: + self._default_domain = domain @staticmethod def from_file(domains_file): @@ -100,21 +97,25 @@ def from_data(domains_data): ''' return Domains(domains_data) - def get_domains(self, names=None, default_flash_order=False): + def get_domains(self, names=None): ret = [] if not names: - if default_flash_order: - return self._flash_order - return list(self._domains.values()) + return self._domains for n in names: - found = self._domains.get(n) + found = False + for d in self._domains: + if n == d.name: + ret.append(d) + found = True + break + # Getting here means the domain was not found. + # Todo: throw an error. if not found: logger.critical(f'domain {n} not found, ' - f'valid domains are: {", ".join(self._domains)}') + f'valid domains are:', *self._domain_names) exit(1) - ret.append(found) return ret def get_default_domain(self): diff --git a/scripts/west_commands/build_helpers.py b/scripts/west_commands/build_helpers.py index 88845e50f4b..e4352ff1f28 100644 --- a/scripts/west_commands/build_helpers.py +++ b/scripts/west_commands/build_helpers.py @@ -153,7 +153,6 @@ def load_domains(path): if not domains_file.is_file(): return Domains.from_data({'default': 'app', 'build_dir': path, - 'domains': [{'name': 'app', 'build_dir': path}], - 'flash_order': ['app']}) + 'domains': [{'name': 'app', 'build_dir': path}]}) return Domains.from_file(domains_file) diff --git a/scripts/west_commands/flash.py b/scripts/west_commands/flash.py index 4f173535be8..073a1ab2a28 100644 --- a/scripts/west_commands/flash.py +++ b/scripts/west_commands/flash.py @@ -28,6 +28,5 @@ def do_add_parser(self, parser_adder): def do_run(self, my_args, runner_args): build_dir = get_build_dir(my_args) - domains = load_domains(build_dir).get_domains(my_args.domain, - default_flash_order=True) + domains = load_domains(build_dir).get_domains(my_args.domain) do_run_common(self, my_args, runner_args, domains=domains) diff --git a/share/sysbuild/cmake/domains.cmake b/share/sysbuild/cmake/domains.cmake index 1d197059bf1..c46d261aff2 100644 --- a/share/sysbuild/cmake/domains.cmake +++ b/share/sysbuild/cmake/domains.cmake @@ -7,13 +7,12 @@ sysbuild_images_order(IMAGES_FLASHING_ORDER FLASH IMAGES ${IMAGES}) set(domains_yaml "default: ${DEFAULT_IMAGE}") set(domains_yaml "${domains_yaml}\nbuild_dir: ${CMAKE_BINARY_DIR}") set(domains_yaml "${domains_yaml}\ndomains:") -foreach(image ${IMAGES}) +foreach(image ${IMAGES_FLASHING_ORDER}) + get_target_property(image_is_build_only ${image} BUILD_ONLY) + if(image_is_build_only) + continue() + endif() set(domains_yaml "${domains_yaml}\n - name: ${image}") set(domains_yaml "${domains_yaml}\n build_dir: $") endforeach() -set(domains_yaml "${domains_yaml}\nflash_order:") -foreach(image ${IMAGES_FLASHING_ORDER}) - set(flash_cond "$>>") - set(domains_yaml "${domains_yaml}$<${flash_cond}:\n - ${image}>") -endforeach() file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/domains.yaml CONTENT "${domains_yaml}") From 19920767b1a2f83f0accd2d0a1ef5e78fa9fb589 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:37 +0000 Subject: [PATCH 0830/1623] Revert "[nrf fromtree] Bluetooth: documentation change of kconfig.iso configs" This reverts commit a977ac68d2b32f2c1c326c82467a6b3bf0d5882f. Signed-off-by: Dominik Ermel --- subsys/bluetooth/Kconfig.iso | 6 ------ 1 file changed, 6 deletions(-) diff --git a/subsys/bluetooth/Kconfig.iso b/subsys/bluetooth/Kconfig.iso index 304c408f42f..553ff3a7fb4 100644 --- a/subsys/bluetooth/Kconfig.iso +++ b/subsys/bluetooth/Kconfig.iso @@ -99,10 +99,6 @@ config BT_ISO_TX_MTU range 1 4095 help Maximum MTU for Isochronous channels TX buffers. - This is the actual data payload. It doesn't include the optional - HCI ISO Data packet fields (e.g. `struct bt_hci_iso_ts_data_hdr`). - Set this value to 247 to fit 247 bytes of data within a single - HCI ISO Data packet with a size of 255, without utilizing timestamps. config BT_ISO_RX_BUF_COUNT int "Number of Isochronous RX buffers" @@ -117,8 +113,6 @@ config BT_ISO_RX_MTU range 23 4095 help Maximum MTU for Isochronous channels RX buffers. - This is the actual data payload. It doesn't include the optional - HCI ISO Data packet fields (e.g. `struct bt_hci_iso_ts_data_hdr`) config BT_ISO_ADVANCED bool "Advanced ISO parameters" From 0c9b969be060d0b8975d5180d15665b31f7fb9fd Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:37 +0000 Subject: [PATCH 0831/1623] Revert "[nrf fromtree] Bluetooth: fix iso_has_ts field for SDU fragmented to multiple HCI packets" This reverts commit f70cd160196e6e346321bb88243743eeb1c807a1. Signed-off-by: Dominik Ermel --- subsys/bluetooth/host/conn.c | 1 - 1 file changed, 1 deletion(-) diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 0e355c36390..96bb2097854 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -711,7 +711,6 @@ static struct net_buf *create_frag(struct bt_conn *conn, struct net_buf *buf) /* Fragments never have a TX completion callback */ tx_data(frag)->tx = NULL; tx_data(frag)->is_cont = false; - tx_data(frag)->iso_has_ts = tx_data(buf)->iso_has_ts; return frag; } From 78d59e1fc7287882f4fdc697a9325cb1b106fa07 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:37 +0000 Subject: [PATCH 0832/1623] Revert "[nrf fromtree] Bluetooth: fix HCI ISO Data packets fragmentation" This reverts commit 865d0bb25b68360e203d68069c2f964041944a12. Signed-off-by: Dominik Ermel --- subsys/bluetooth/host/conn.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 96bb2097854..82c3aa91e17 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -655,6 +655,21 @@ static int do_send_frag(struct bt_conn *conn, struct net_buf *buf, uint8_t flags return err; } +static size_t iso_hdr_len(struct net_buf *buf, struct bt_conn *conn) +{ +#if defined(CONFIG_BT_ISO) + if (conn->type == BT_CONN_TYPE_ISO) { + if (tx_data(buf)->iso_has_ts) { + return BT_HCI_ISO_TS_DATA_HDR_SIZE; + } else { + return BT_HCI_ISO_DATA_HDR_SIZE; + } + } +#endif + + return 0; +} + static int send_frag(struct bt_conn *conn, struct net_buf *buf, struct net_buf *frag, uint8_t flags) @@ -667,7 +682,9 @@ static int send_frag(struct bt_conn *conn, /* Add the data to the buffer */ if (frag) { - uint16_t frag_len = MIN(conn_mtu(conn), net_buf_tailroom(frag)); + size_t iso_hdr = flags == FRAG_START ? iso_hdr_len(buf, conn) : 0; + uint16_t frag_len = MIN(conn_mtu(conn) + iso_hdr, + net_buf_tailroom(frag)); net_buf_add_mem(frag, buf->data, frag_len); net_buf_pull(buf, frag_len); @@ -715,6 +732,11 @@ static struct net_buf *create_frag(struct bt_conn *conn, struct net_buf *buf) return frag; } +static bool fits_single_ctlr_buf(struct net_buf *buf, struct bt_conn *conn) +{ + return buf->len - iso_hdr_len(buf, conn) <= conn_mtu(conn); +} + static int send_buf(struct bt_conn *conn, struct net_buf *buf) { struct net_buf *frag; @@ -724,7 +746,7 @@ static int send_buf(struct bt_conn *conn, struct net_buf *buf) LOG_DBG("conn %p buf %p len %u", conn, buf, buf->len); /* Send directly if the packet fits the ACL MTU */ - if (buf->len <= conn_mtu(conn) && !tx_data(buf)->is_cont) { + if (fits_single_ctlr_buf(buf, conn) && !tx_data(buf)->is_cont) { LOG_DBG("send single"); return send_frag(conn, buf, NULL, FRAG_SINGLE); } From 61e0cec37d90801fe7e4265c7015db4cea7782b9 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:38 +0000 Subject: [PATCH 0833/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix num cmplt for BIS HCI ISO Data fragments" This reverts commit 355032b839e85838fdd50baee5b645fb038c5068. Signed-off-by: Dominik Ermel --- subsys/bluetooth/controller/ll_sw/ull.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 6be8bc4759e..2f325f1a86b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -2582,10 +2582,18 @@ static uint8_t tx_cmplt_get(uint16_t *handle, uint8_t *first, uint8_t last) /* We must count each SDU HCI fragment */ tx_node = tx->node; if (IS_NODE_TX_PTR(tx_node)) { - /* We count each SDU fragment completed - * by this PDU. - */ - sdu_fragments = tx_node->sdu_fragments; + if (IS_ADV_ISO_HANDLE(tx->handle)) { + /* FIXME: ADV_ISO shall be updated to + * use ISOAL for TX. Until then, assume + * 1 node equals 1 fragment. + */ + sdu_fragments = 1U; + } else { + /* We count each SDU fragment completed + * by this PDU. + */ + sdu_fragments = tx_node->sdu_fragments; + } /* Replace node reference with fragments * count From e5701f9376b177770f41764f811b9af8bf8b5e9f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:38 +0000 Subject: [PATCH 0834/1623] Revert "[nrf fromtree] net: tcp: Fix goto condition in case of RST/packet error" This reverts commit 1907327297f59993d41f2f7f5af50968b0316289. Signed-off-by: Dominik Ermel --- subsys/net/ip/tcp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index ad9cd1e4c98..c90f7b92c20 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -2276,7 +2276,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) tcp_out(conn, RST); do_close = true; close_status = -ECONNRESET; - goto out; + goto next_state; } if (FL(&fl, &, RST)) { @@ -2292,7 +2292,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) net_stats_update_tcp_seg_rst(net_pkt_iface(pkt)); do_close = true; close_status = -ECONNRESET; - goto out; + goto next_state; } if (tcp_options_len && !tcp_options_check(&conn->recv_options, pkt, @@ -2301,7 +2301,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) tcp_out(conn, RST); do_close = true; close_status = -ECONNRESET; - goto out; + goto next_state; } if (th && (conn->state != TCP_LISTEN) && (conn->state != TCP_SYN_SENT) && @@ -2316,7 +2316,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) tcp_out(conn, RST); do_close = true; close_status = -ECONNRESET; - goto out; + goto next_state; } if (th) { @@ -2904,7 +2904,6 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) tcp_state_to_str(conn->state, true)); } -out: if (pkt) { if (verdict == NET_OK) { net_pkt_unref(pkt); From 6c8e91bcb77abbbd7ebff3ecce0caf3190d2dd8d Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:38 +0000 Subject: [PATCH 0835/1623] Revert "[nrf fromlist] net: lwm2m: Allow configuring update period" This reverts commit bd268c7f0e0b6c301a34df53c0d41075dd844d3d. Signed-off-by: Dominik Ermel --- .../api/images/lwm2m_lifetime_both.png | Bin 17612 -> 0 bytes .../images/lwm2m_lifetime_seconds_early.png | Bin 14563 -> 0 bytes doc/connectivity/networking/api/lwm2m.rst | 47 ------------------ samples/net/lwm2m_client/overlay-queue.conf | 6 +-- subsys/net/lib/lwm2m/Kconfig | 12 +---- subsys/net/lib/lwm2m/lwm2m_rd_client.c | 22 +++----- tests/net/lib/lwm2m/interop/prj.conf | 2 - .../lib/lwm2m/lwm2m_rd_client/CMakeLists.txt | 1 - 8 files changed, 8 insertions(+), 82 deletions(-) delete mode 100644 doc/connectivity/networking/api/images/lwm2m_lifetime_both.png delete mode 100644 doc/connectivity/networking/api/images/lwm2m_lifetime_seconds_early.png diff --git a/doc/connectivity/networking/api/images/lwm2m_lifetime_both.png b/doc/connectivity/networking/api/images/lwm2m_lifetime_both.png deleted file mode 100644 index 1cdf0bbb662965d525b6b24f6dade674d9b2f0fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17612 zcmd^n2Ut|wk}e`Bh)PZ>N=BmOAVG3&K!P*^LIX`~GBh~~LK9VjWDyZ0C&@X9f|7HP zBp_KpBniIN2|T5ATC1x53ae^=qSRF6E?u~C0Rsc$l7hUn zItB(N1YGCfoCDt;uCLd?pEHi?a*`PNo!1sIFi7m2WS~yguBH|UI0gfc)UPWBZccMs zM<)gzX$Ed?n4KMmi3QBe0cP#UVFPypL*Tx(t%-%H1>EG<9Bxi-9(GP4c5XpUP9X*! z30_|C#m&dT&%=5D*L;{6+~$NJ#Ma#cfq*e^%kpt>0#Y}jTwDx1lHf|&!p7MZ{B;%N zH{j=G23Hbxb_lpO+(^j+tSigMBf!DKkA6f+UK66sz%2!?5f)Z(@J9}AY-NjnM9SR3 z)*6h+a&ZZ8aH9W#K@FHG%)#O}5@;Tfa0f>VTbmOWxH$MZgnn%n?gTSCVO~?n#K^(S zK?UMyWzS{cqNIa>{+i?DW(WT@#{`bFFa`^9Gw{eTa7qBe=ns$7iO|3g8yMKou`tzu z9N4*jQLs1>9=o|SmjKMjQXOhyq-HOtaNo`OSjfLqJEdvuD(3*RGl$rkz!8A3iR;Pc z1vmwM5jAo9HNwR!c*2aC!|6gN>!JrVEZk3a#07SX7KWL#g$dm8L;Q7A+rq@j{MTGTzLV{t zXUoGa%*;<$=HfiLV+}iUd@p8 zOwgt$>0)l-1lO>GfzZGs?E<_u82hu;nA+Mn{T1(Mg78yh{Mxx4?B9?0(@4R?_h+o} zoM7!Yi{KJC8T;KNPUoFs@^|$A?*Q`OrD@*3Xj)56T0&FiFN$?Ax3xBM1_t^M#s8b1 z`(3pR+&m^QxS**qcr`f;Lgbw{_ko>=tS}-X35R_SM8iy?(fPu9s4g) z&IzD?GsC~A1%%||Y{?V>cRdLc=vZ(XF^mx~M@I{^_#)7{n z{`4&HTP)x{O@)4UH~*!v;N+n5&)kg}@Evw1fcUGwJ~_d_j7~G;6Ce8@7-j!Hqx-{( zf0yj3nf)%=Q&T*(_W#r^GOxrH*-Dl#%eO^3aaSi&;OXz{NIY((=*s#b3LyAD(`!ot^W(vk<%02-wIK` z+v@S%)6&v2=g@W)a zGcAS0hck4h7gJMHgDJ$_QYpkq&Zg25DO2yagyEj04L+l$Ol>N2G0t_K?Z|3qe>uOd zIUvQuY#zDeSxTk^bI;B}zAESx($ZLd?sK%)7A-A~^~a}}=ru!6`gK}NTI!QeC9XX0 zoM}4KA5)|o=o9*J|Mrs_>kKM`;PJO$oM7LRk34S{{vSVr#c?o+AT-pAgoFfVPCk## z)o=XqgTRjfi#|b8yqE4hLjxbY)N&vjiH#SdT8gLcd-18}Gt4P9GW2%TB*fDcl3(1! zx_94#;oxAso^`Iaoh1kQ@Z2TDq}NUNq7orJghHLN#gT9Hk-Ov4rSvktLyD5jJ`kM-K}nGr%d zS;3UgIrM1R&8di|WsQ4?KUs=2zx}o0?CP*_WS(pDt@es&BnYtC4q( z3L77uul_MwW^Fa;xfQ;>IyO}H$=%9oC||#GC;dXf`5T_yr9;uo8V=st$GQ;j1&U;- z4YYdg9h|Y%Dcq$asjl%{%nR}P-IMPF+6Fp@``cEp158_qAg{93vdtB}*5?y#ZO&6U zJ=XVFEqxIh&5|JLa~D4ZC|R76;ITQ&L)m;3izzV#D#=mvRq|ja^j0oVLB1>4T*X28 z-qwOJ%|M>6z|IcoJ?M+HUE{Z5MLGFZ?P3QjJY#MP$*Z5ERLf=~?|iB|+PBKlF8Jg? zi-Y$b?8F-Cy?YI>zx#!h^?;Uk>1e6d7*N{U<|o(L@Kx|Y8Q+jzA4lb9qN{hjYaA^$ zCXFM6-o~tMcHAo0Ht-s#yjC=-ha7<;8_t{;ygOX)^D~6|llyXB*=pGs$3jYTwrp+I zc~~ zWKiF$O~#@3CHKLIpz&d|=t7^|4KEXDg8!OO0He)E@S|T850vtf+`q3_@R)VJkqy66 ziM+j1*vztdp|6gwM|E2T4gYsRzS0_EZ@wYSF@qV&dd{3Zr|G${@Z6_Nr^Iwb$1EAn zu3PqIA;lwKlGAx*xaYFaX9A{xPi_lTOmS5%>uYT4^jO`@nMp=wDQ+2|DEBWff|4qz z2N{#iY1b!QCMWE42(`a`AF~w}AjK2G`~rqb2lI5RU8WSrocbWi7|=3AJnIeG<#%+E zZ&dFb_9Mrv1$J!4eeN9Xz6@=X4EQ=?;Bz<^Kq)x`SavbOE+P!Gs5<;UmZ$WLV-4T! z>x9I^b0gP1R$%yde%J+?(~{wC@Y+p@?_3Wc#k}PAG}3%#Z|9Rom;I2p`bJS+HY#)moTc8$g? zGLw@i(jPqc+(hM7uT`nMp0k|nrc(L^zDq=p&9fzT6}+9R#O;=pI4cYgMY)d&D6mYr zQbem~=*K<^Os@FH6=4)n8(WXSpXsl33a{rjJZcaZc?HlKO~9=b%f{6%*>s`hJ!b$V z^MGiOIql_l=bg4bgbRE!j}-k5eYKk-J1)!^N0!pK|?{50|$vL@#teV0oEbqd$akYYreofo>Lx8rgzDmYwN&M!xfSY)Zi~z}7zD7HPr)18uekviKe=x& z%^h8O5z>0eirD&Dj+a}(Q?&DM@dMz#cAxnXT$#Mj3HaUH9q$333*(4%e6igIRERQa zonWjl19H{l`-oYd*THwvNFzdEjkVlwd8ad)oCAC%)2VChm{#k59&toErQw$AsMQea z_P>NE&U(O?G=FR}{ zNV3yrhZZ(qOVf!95=HXOr-gDjFx9H}ox6&dV$-^6Q}F_lA~MoSx#tAbC$tR75V!kz zE$v|{d?t~M{l1BT_ui|L&2(Z&%beX(7gN5n>rz&xo-*l7xcI8Tq-S5*h-so)8py8NuRR|Iydm86Xm5dBpEqzi%=vY98p^d;Z#D7Co9oSM`Lva#_M$xx;l6LJoolm+BQ>fD$2OwXM*WU+1%pD%Sy)clcdEgtwGV5L`45CakEDS=VL$X`At#??9$tu$G+FR%#MtGHhf_2u%wMXe_shPlg|&Qo>XeX$3QS)Y+P4I* zpXD$F+`5v5hbl3cJ(jv&Qxn;@63TZT5YpGMx~gh?Wm3CoKx3TXnYb_$CNI-q&vMyM zJ~^8;!PO;yCpJxWiRw82(Z|Flh9qGc5l-P(Ycdetq(6g&)i|Y#D3XyWgGN-mBP7f? z&OBOaQ@8V=CbQ29q&0qw=CUb$VCJ*=Zo1i|&SU#YgsGEIrSWQI2T=qIJ4mWDL2@S3 zdNt<*LxRzO-kdJfzg#GxQ-Oc&nq_Y~DpY1>$$x4>X--L=kNgbbO)?-iqbK18bwrR2 zE1nqWapssB0P;6Q9O0RQr{*E9XR}<7Lx;DiP$a<)s*zNZQRK^vl0&)QHzd4R9UU;-Q%O$hglgSxiveBrW%uQsY4DlVI#=CY$i3t_dc5lNd z*W|RfD|cV}Xfmd5yx5c2GUgpRkIJBZ9T{h;W7mTfq)e_izvQ|va)A9}hE8mRB1R>$Y05D^sO^G3GL;p8de-V>2;?Gb}>kn1E{HcNHCvXCp=D&ZyI10^TybYb@Zl} z0imN4Wj_%R9p=ukPDi%)Mt?nbZ~NE6*>Yer?mwP>TlGg}&`aFa|65v~YQ84)g7h@u zCh(&te*B90eO^u#>NHCy2?M^mQH_P}G%rWbF;{e0&bIlbK=6%CN8O{z8Qm^_!jv@i zd%)P!@hWu4`b9{*5p0e0;wx^V)5YYu0ZQo0^OqRW0z-e)I04GArLw~Q*xyrS;B@~3 zx1(E%E3)~HZm`I>&2r)8MQQ3Am`g5u-MuBWYPZ4KuZ;5qTEoN_I+IuZ&R;L=xK%&C z|80@Dq&KI+o`KV-1?Qm4=g2sS3K<7U;APGqP^*-oegZfp8p+Mpq`}d1c+c=1q!q*C zm5zDN%Y(?~O9CXcx^py`l(^rP209*i@4?4lK~%X9YTfzGyQzDCEP@Gu6ma++g%GiW zM6b8O@9b)Nlu9x1U!yklhe)g8LfD%N*}W|(4Nn=A^ls!B)YmN=KRl0*bOu)B)t8Nl z3uGT%cuvdtf?Pu=W4)ce=SC|!LoI*3TD6=X=<&pX#R{{;^rM6SVhgcqE`dUpS3&NX ztW8=18o)83CY7y-NO=`XZC{=hZ4Ut!vnvKpX~sgjI%_n2nSEY~*JH~ta@X9GI;GR1*ohb{^w z9aR;KBOL`$#5*SQDg?t1fj89qN-0?w9?myt7y4jzw3JTGh?M3smiNJ`08^FE-W>Um z%Tj+MhqzFTVEL#tWm{@N4w!}B|n zsMYVQV`E>Zn|b_k`gYo%rCD-d@}Z$WKfL^rkcj{}eTC05dV76x5|?Rh@Gg;`6IR6* z9$p_fLac`IbiTX5jF=?009MqCUXIP-ub5p@gLU3o?G0%3gjw}0B$o&hL z+WO8h`i>v@_+d?0V`k629O}5A*FEFm5&Z>YY*NTYrwBMJN?aYM`+4)Hm@RN#xUJMQ zsB3EtPB;n|Fb7^HV5x|1YwA|my(p1JA2T&=5|pH1EQ?ZmAFvtN;~v~o$HXRwM2oG^ zYV;;7!D-cKG4-pFr81#pl`_Tlvu_#Pa~=@$VTO|5Lejd=h6|MG+Sc+}wraR-Qd4&r zTrVU#dM&NdbQL;~Ly7t0!30EL;&XsT&}Ayi3<7tnaKbn-uPVo(?<*sHhY?BYHQ?CS zT77sy#~qa+*{k`0mVlbmZPUceqGGLTIoD%n%}9e0>um&;m07ZLEb#|9Dre33{@Wu1 z(dLTCgLw^MREDSdq7LD^sD>K1tt7iqpPz@;0J?78x{+<+;`QE#D;sS$T>P`Na_-r) z*0m>s1Td=V5fk;Xhm&Fay0`GW+8}S?om(Qmb;u8XxPb=N{D=72{G>QxmwY~O7RU&B zu|tMV8wpe2@+zS+;`oz7sPKUYY<-!0K}%65;erhJ{XKbJnH*8eVqPK$pMt@<3h$X4 zeY_5z{GEr*EW>Uj}vcb#O%2>kLd@y zGn4H1-vr-X)$C88=JYx8WJ&_(WwYiW{4Qt!r&j@Edx1-ccqQ=bEIZdz_q8pi?^iix z>HfH9;N@%v%hsm@caY(`e5_-B> zW-Ey0^(%IT*GR}J^j#+S)&?~8=p+pXb9GdLpW8Lz&KDq_n1{&EzNVmkED6G{z9g0d zG~wLkYhTDp(JmG@06M&hdha9saSO+Of_lez z!65L9qu@aL2y5t`Rw$+)@aQ8TTp)y33Lg&SXsf0%UkFd*4i@)C$?I*}KO(ar@y$we^f74#9N>zdJ#e=Wvgr~#$aVhG z-I(IO#5`MxKG=Q#Ul~*wn!XfSe&as881vR}_1Z-Bs76LTBrZwI#wH!&X%D4EK zC{V7UDmqYwTumrT#`$L5|N05K{_!0c>sWS9{!+^9QMB^p1|^m2l;0!D)u3olovN;0 z#ogqP>^x{szN~NGN;+5!?+B@xYMb*oB8mLzdn1Ek-XHI}&*8Qst?UP{(Wp zu&Tdt=w#iNHor>up{kz`KOBIwa@{I8o*_X6M+mt` zpN|^0E}uaA%yJ+f+scBbN0mtn@_KhS0VQqsh&|g-_A0Mfq@+xs67_-X)&qobTSVz4{^5p8h=2%k$k9%cYXoWrR6Xq;MqQ3sD^JO< zUb{Wp1%jn%`M5(UmB&iany9ZN^{!Kw=*}>Zzyk$oUhC2R%VN8RO!A*V1PNx-_p5<8&J&$atYIl$0MLQt{qIh~)<-#M31fDbqEuUskaU|ISG zj#pKv&u_2VzR|j;(>lI95ZG>9V#)6NEBQ!6zd*d5e6CxKw8^{gH6LXMGv>!kIi;&2 zZjU(C14FY}g+-;<9GUt3{Mw8^ArdO+y3tC`I@ml_)#&~%hV-+a_zp8$rpu()&^8m+ z;XPgJn6jlej!PM0#4odRL*oaHe_rlNh5&;&To2JM8Ket?mQYIJz|;(>Dq~%JIAbduKI7*#!V@E?psMV%+`<~f^ z;$bCb#M8dJU!pIjD3iUsF6us9yYp!oc{7VSahq+ZLG^GP{|b`iC{6h12T-gw)U~O6 zWo3dS@lJz(o!eh6LBP{X8Xu$1vJxrTP&i?X`B}Dt^jmeiO_U4-JBum>Z}0KK ztc}VWY(f=iqs%ce&pyP%rHpQTk5_W-A!-7@t5B+W)E}FfPey|GF5`!}XiCDUF6qR) zvj-8bpoTTV)pjlF9xoS^FlI%$Zxze7ZqL-rNX0oXBT@OVyi?nECv+YN)E6F{I^!j0bHr z7h8J9&Cm?aWqXdbT*tzV*fPB|l=F=TU(W9H)36q{ScaBoff85;S6H6;X6(iKm+g!R zulZsh7u4;yLwLn{&e*%1q0}aw8h(|2KsczEhU+NcvY)P`EWS8ywwUsf-<(3TVq8UR z&xE{Vis}CC;KG zB*(+*GQ@7al<={)WycQJ5HcHU-JV5{sX*W0Osf3t=+i6ZA|6;9x8$Q?2{PAl?@FSp zin+HuZ$6Hv!PH~n=d~^ZbXwnQFzgW=tzHD0>kvhTXl)HcMJ(Q1kFzGX(3I#5OJzPPK&6* z=)$x6py?BP^s{Wl5Z zl=WKpHVmHor{R9W`sh~gk>Rc;=RaV7<1-Ot_HDT1nSEsvthdM3Ur15>#8A@gT1f?= zYq*R61uG$v?O;N1w(UH=+3cfI6qQq%uZ7PS>>YyH@lZxGVlpGWO+?vc!71Mwc1YH2 z682@9*0&+8*Ojh0QpR$znN&7ik2V*+t{1-PvVA$=z2D%11CKCe3+f+ z+Hec8$J=wRU%Fq|KstbcLkLAWUA}13*DwV$@Ye-jVN=PqekmJXoFeLRFI$D8Cpzn> z#lJ_pDMQb1s?nKi#XX6cAc=c=-ZVMG$8E@#qNl|LRX|r3R@dZ00Et(BFGI|PQ5a_; zEZXM3{E$FHwQDcLP{ovBw`+?O(kSBvj`7YTz0~L)-Bpnv0&xx~#@j5WeNMP{yoaNV z7FAStMYMIT`N)G;Rb_WkvA9C|cGoe_ku#z$huKb^Z=QYB(km54PDQ`nuc*d5{gm!Y zM5+R&0uO`#cDxfqLX!%sd%hk{AqCGuVPzBiQLqs3!mFSFfV}sm&^R7KYagEUj?Pd( zdxk2QW`>4`fz0Nu^X;C1YW!zc$j;747s_t!^!GW&kAIElmupEj;G70UkF>aG5Vkt86|R-ya7zL)QvYK0b&sAF*GB)~pkO2eTR>5?JE1+a zr)4xaF~XVmON5H{(9=*xB#AObLGAZZhq=b~W}9=ZL6e^zw)D%+DQJdBw9Z^}a+@Q9 zfU<=nqvg*BGl@82%Fl++5OGo{1Hfijku)JWedST`X?B8kZ@KSAjD1GWaLp;u_L9b(ZOLiDO{kAEDm`5Lysq<#xQm zWYWjLZxm)7KsYO6ZZYGQ&r2(bOwHF%wE%Gd=hxJMYS96i!hoHuuO z9DJF#?*|*|m{+G_T%b$f)_+OxNa<_5CuU=Fe%m6OXBd-z8LW9hB2od`BVD<;lUtC* zB&)Hk@6Z#V^awlQOhQ7OJSR^tpt)$}FrJKEHOXMDxTf>A*c?e>~J^pguRZ$ud7 z^_&{1RI_9>fV#74npEC+-qJX4s@}RE5GnYMcKh44v?%^&t!KBVpWNZlbmdks)ae*N zI;jPia=vAol*n3;p>D^rJD44%jU^D!w50VWAZ&8n3xmIC7OO5_yB3a~Y_%Dc{EzmE= z0Bs77W8eI~vyZ)HmM`b3*2ZaXW`k~_=YzP^J%Mxhjj>`3TD;RN47-=` zt_y3f%PNyX;<_t^Lpr_+qKHIFn|BJKJuso##;K2k$One@3XDa%pr9a)`G7wCDo+a~ zES!2bI^0Ao?Y)6egCD7X#Y5a>;-7ElBOw>@1h-gdl#HdhvTuOt6*jGyXs2?=^tTzqge-^6m zc8K($vX$X9*Zf!+pzj_|lh=9q+nWUvKt7Z}e+c$}#;3Y_PJ}?hZ@D8B2Yy}F(9Oz> zL`Fkw*}e?QeZz;Gq!>j2i8JF`H-a^gbSz%vEZg?y zC4g_~U?+SE{q~iChuWUlu+vl^P%8q}ofyKSZ=;}Vmx&XF(-lyAll`KwC>`cqx`rAq z(+?Eog@o=6Gwn6aX>F!~kaKwV#f;-`8%a=KK37g;e+}vrzigK`wS;p{)UiM15`JdD z2pg>mP7`A+A*_udvEqxTB2&U{SOsD3yL8Q-X!lBZhJ6I}O#iieSN!|;Zf%Jfo#T?t zWi4XZ%Rm_U))+RsHz#4A#e7x7IjtpLNb_~`5N2a!4$X<%dW|Qsl56#bJ(TZajS{ax z4@u2!XawjShEY1&d=R3vG+$8M4CEA{QcR+0j!fg38*m>$bq^UgC*aLpF{G8 zhM3?nrQ;@bdyF`wGbSL&q*^G6zmffsN0FY!ZEZsqyvv@iszYdSKY-$3e@F|-S0-Ir zbIuif+1S^^?&0VjO>{K+$(A2>?YDGiTCUkc=Mn^=k6AZ#17WwEI%Bl^#h#gm+z)*% z^2Z*Y(1U{1d(*ow{@7<4C`d6|vZrmH^n84Aq@RL19etuq;2&L|;47e1__{Q>o$j>j zL!bayd4eD#WwF2_^Zb?vNiG@wZq+xOAdr>#W+_YTxHCkCZabvKYrRjP_cg3qY!t|| z4h=_q|Dl@O_JW-u$+B4Dn+>`Q_L>%uXYubFlBT|R=2qNgo5^whk<mM7ozPF&U!f^W`cmo; znj>*SbPMZDb}^eRW+hfsfQH)+{=fq)Y3e$#xtTE}iyIbh0I4#O3L!#-^jIAZps}Y; zPUwe8_)eQsL68)urWoD3^CKbzl~zLYTE-EqY?e6sq^A?NG=;&q2^d$r=aJ3NC!Sh` zUi#b>NC64@2^K&p8d21~?G5|m|bxw&GNT?)kE1bPNC<<^?TIE1g6!4o7eR8rH>P!a{3DqhFLd>kqcK|i3! zp5BG7TBh=%i_^_IwkT%5*Erxt9Fm$;7YOh!7$+J?%2uYqm4=`NRqPz|42{aqpjXQ5 zW4bR(Nf4ZE_|%T&VP_@_c(+VC7U0SxQ5HLg8S^eV;G1uN=i39og#&0QXs(HhZx={Y za{vh{P-&y3p$Obicq%Omf4wmF>hM8~7}G;i?fdWVmru01 z@6-+-O=Lq}St{4;ovTKO-$?xNWvguUyY*_g_QI%r(8^lMp2x^!*~)tTgonHw)#OLy za$)4Q;6`_d&sO|^ZFhG@{SUu`<+kVSrOZ5J&`2rW`&*38p@ERS<2Uhi&>gJ~Q|(tY zk1b*Q(+BI4sEn&Y_(jZp^IGDbhMQQ`={~lJT&56s&1RBV^woy--ir*MuNFq?pa2AFis%wCxqXxxlYB0_&h)Ae~D~uJzPO8 zkegVG1C-jLQF`+-0K|-)Rz4xq<4y)`tsZHuM1cnrYi=vp2PQq|W2B?n>{PmD^K5F* z@lO?7P2BnD4SST__p(Iv>*s4@C97oLKZoL3AIgTazSffCeLq98(U~~|8q_Ul6d)2+ zunSoHl)03(2qEB2)u0KFg*^V5c8TvRtT#r(EFv>WA?1 zTr+Nm71P;$oG2J^cRqq!mycAaPx$O_oVO}orkTjKEzKP&N(hBdt>~Rui>o{vGza@R41?YWjNhlC z9IZo5*;k5~cZO5zGRHn>-zgioXV6?*UKPt|usdSQR($K(k>SGiTI-S05*9YJBMk)I z0ZsF?_FJ1++&T&9!najX&z0}pZ?q95>QrptSu zp*vdnlM?YVp9&#xxqkdgZh76oD5$-!%7%vUUm9RA?GbJZj{Vp08W{F7#mGPxTG2-Oewr&K;`4fWDDYQ}k|=^aa39`tJt zUm$SPiB%@Ow_^0Ydn&(=e`8u5GVn&)%P~1G!;`C1)&$|j^q`1Rv3@VFHsK(1v{buf zehgt|W?&azI$l;PD(W1f-}_V9!?e>QCjav8(ZNrhpuxn^(wFOn6Fax5Uz*Rf`;F%0 z)#)XQZZ}Ci{a zZ{dB#qAm|Sp9+z3Ai{d?_?44s5S;>N(=*#2i)#i(VQEkzWwmqwYKeezrR}-MBCQFW ztDpj>Oljt8J+SN?c%d!p+I=18Tr%K|!GwxyuYdHOH?4BC31U<;O zjrO|9z~1_G<>x{#`Xvy7wVy0vvVa%5#pBVP!>!AyOAB(T{piisfA8r7OVFw*17WnL z=hP4@q-vsXJeiP-LBI9D1-PIPNC|o12%=CDeH?Hx+oou~-$|q2j*-I3mQRJE#Ts%c ztpNQl${(sw<@b}s1G_cZAso2`Q`#AeN#j zVT7l$p@Eh94m=TZ5jye=-!J4kGNH8k{qOhW>!j9ijiUd;nF{;cEf$OJ?=9%%*YolW? zd;$IX4=&+NT0hNcfOP5McF?gE#|i;2xn#Zbjj6?Po$fDdmF4$1Vj7(7jvcH~(D(cG zu1_!}kXIaET*y^bOq|RtN3t<*>nlo}ttGfxmgpT8{yh5@Gw^6UKztnh_aqn!GAh#f Il7{~O3l2&u4FCWD diff --git a/doc/connectivity/networking/api/images/lwm2m_lifetime_seconds_early.png b/doc/connectivity/networking/api/images/lwm2m_lifetime_seconds_early.png deleted file mode 100644 index 119005ce5c7f0ea96030961a6f8c04cbf6ec4d11..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14563 zcmeHu2UwF^wT$?!Eua+&eSR%rnpNA<6#MxAxkrulM^-xUr$mfqlpJ z(a_Kwfa_|R($LT$!1p4CJ>YME-@RGzLF;9zqd`;Ba$VQFyQfu4Ax{XeTtvaf?P;Qd&k_QeIs8 zteK=dL`EGdL;VAlfXYFww&?AgQSRFe5m7P%;o*j|MA_@3!M@tEGG`=YzW}9Akv!PyBpdS1wM384z5`0 zEt)PkEC#G-OG%xPkfi^$ZrXY!rM7-tr|*V zpzcmG($e-wOC6M*yt=Nr{uT|M;DOqraYXr`9l(at5E&RmQXMd+{*%$%RvP%>ZU+R~ zRHiY|gSgZd2lTe`&Y~q{^-xf0O+ybuf;q+r^xi$SVxo_VC?9( zE&LhDGh0j@30o^t(6ifzamMXzw7oBN0g3kCmPiUnOI3!mH`)>9wSDu}5*~|n!=pX^ zy6Av)cSkvFn{u0@9S(=}{VSOh)@}QE+cX~FOVSS;Z8o7H~5yhDWX(?q#Z zwY{Uq?R|hZ{g2=Kr#5hZ#>0Px9kAS{C)>GsZ|iYu!3$5=Q7p>cQJrcZpb&dIFO-&@ z7tpPSBly^iUTWyM;4yCCGW9EU-PjI~N8zY(0i=}#p{(JB$6;MjJ9Yt%u7SgPyE|?& z0Im+M+u`v4#x9%d+928iFDf07<*&cC{ZLA7hso~?TSq}T{>^dzp}S3W{>KLVhZ%KH zATi)^1aK(df4JC=hq?UbT{~+yl$#wM?ekX`wcGY|=Reu~HS+)NL%*+3bF48I4U!?q zb3iTNkW$p^R5R|xuH5$Tot?a}-Z%%;_FYuMf9-nzVoTYbE&jbNfkB;7`2UG5Wk62W z25D+XIsdV7wy8G*>|as-Ee>V2wC3{<=Ql+;qk*pin}M`WEe%d6Jepbzs7m`SCh#af z5cj|P{g#JoV%@MfU=(+(JFvM1sETg?v}EUocBV##0|;LfAk_dx1dj%3Onv(T2JPrb z4LuEC7c?G)^sob^K}O3LWNona*QjyAy5s-u?^K4U9naX3+{5la@9{g8LPqwlz9zHn zYrjQ=)S2zI-$P=DZpSBo_x}GLhx|`j8u~X&n;UDXo5B8OSey$MWA6`;NaE zekc3i0p0 zjA9Sv3B+Vei`~5`E$~9t>Hg1FU*%SnR)Uf9hcV^#CtnBGuXHag_7^=~p|}Qi`&(zO zR0aj4i@Nrd*toJYsL{}|T&1Dsr3txDU&xDi$MWY&bSe!wK9$w-PYPPilw|rXVp;~Z zr+aCMO?w3-LZ~-`-!yc(Y+gIeXc@lqUWKk+ZG`+uPlL8U_zzY*^wEMm(NzNV^mv2w z38LovW-l2pvG+&Qh=w6A(mhq@px$=~5D99UFt|NX;Ru7TlM)5ivmL~#UI~Z z%=~fO{lPKW%k*p0;uRmBmsAbyTX}7CRLcIkd9hWO|H|yl*!-=YD~s(q-E{%JsWQ&D zYrnid^RY~M`NIp_pjA|#YiZrSLdCxKJr{%PCR*>P{v4N>YReAYn0w75=k>*4<)hbF zOS$_%P4E2Z+nHN3Ee{?#y#C_$w!=sjb4O*(Wr)(AtD~4vm_!FopVi68i^x;i710?C z?`YTI!4zcpUmjvCvM7FJX-jxHTeo7XI23l$ZEbNPL}jCq&8W;UU7=bvNUuINfz)F5 z@cT%d(e#gn)-xL$Es9^K3q(e11kF=Q>Xxn6r%D^#-bC}2)XQNgAACOsItQ*Vm)rOb zbWtiWsSEO?p{4J`cWUQS_la##fPov>}Qde%v@?30b zVJv-&-&FKamRGBCj|3n|Vw3frG!r`9Tn-mP6s}+0bx;y>UZixqZe`G`&&=u*M2+Xl zw~%tTUb3>LHCl1{K`7f*S=a8WW%wgQg$aT6p~%y2zcyBUTf3J(o^JRtH2+Y5Z*4j= z_@}46V2s~Xab?gNF&zPg|yKD16hc)A=J+@8BIZCm~ zOCWEgPsEC`UIB)~FBNh(q#-NEOxFdSnxp1%X=N`9J>#$3J}UD{S%+M7FR{_PVPkng zw%+sS`7A7m(JKtRh`FP0jhD2TelZHAU2@J0tcV=cJy_-^Hcu3nEFFJ;8g`O>!$jbX z*dad5fy|90x{8w46~hbp-6Q1C)3~V841H?y zXW31si)7apxrQ-F>VRJP?r~VYdNk3xUoN%zHBay~kssNv+&qIGs3})o>G$d`v8ip$ zi(ufwz2Q6Rl~RVtD?Z5>F8~|Ln<1XOqeSkCF-$4LB%Z=Hi%+)a-ei*-l_4D*J%z|n z>cuFEFbk(b!!;pPovL)i1{nkAl!_e%o#xY}+2g z_}IDCN8UX44CHddLW^R>`fTlbtYEr+UVm1nZrtrX#>dN|{8mSk4%?*s@UXxOyP!=~ z&X>#~5LS0S;R~98gM_oFrRX_kiPfau9n3(gM01*ox7<-)PIgV4zgQNPKOSWnZx%TB z@^G!VGNx!^i2yk&cKD5$zr)n$n>>bM2>)D!yhemH;idkY41ni6Z-Q*`LWdDdN-!y3IQChe+j1dBZe|UlRG@AA^6@MJkz> z+78rxDLqLiAij11+rZ^No-L87i}gXjHRzeb&yBokzkmMmh5DF7@devq3kiMztgBsu;AdMda<}VgisWCOeoxGGG^DRUR>swwns#VBPiJPphiN@ zj&rn+x{--8(V#>Kt&ElT*m^ljiA)lEK9pmGR%5;iXNnM}v|lp|>%hZb`41alJ>ezz z>8p*R-n9sMb%oQqr62X5;x(%IEh*B-n0LbV#4*>mhKz4XG5MwSYt3BntSh261t)11 z4Vseajg~}0ti4ZLmA%2x7S50^=JLZkEz%A(EnQ&@&q%mph@7{~x)-Sa1xj$phM2be!kj+9KX#Nx?ij3^iTG;Fhvv5Gs32#*mjC4|-LywhFC8MF&(4j%^8;CZu z3XRU!(`*f;_8Mxu`{<+dg>RX@EMr9%9%)h9BIVbkK}U=~<;d<0(T}UgX_Q`@3PwgA zWJo)M%~&U!tK4K>$UQ|Hr1E_wB$($#wF)l+_TWyK#nCE|De`wocp;QjT7%StuY8J| zp*jC$??UKm%<9!qjUW}=!14B_OsAw!wNGR%qDWeU2-=;ci8oeVAT-m6e`ED4o)|@Y zUQfo&4mnm?`XGsVfszQ=q1s_l<^C9Rne7WLj3+;Xm7U26YXi;ihj6HGldw1g_Gvmv^?xoL0g){kZ$`h_)PwV;QM*ZQo3%YV3zvYIo*J97 z?lk_Mf>)t03HXWQI}0JKYAJM@aM;eCjdyAO3x&{%eY!Z&Q4HGP7&pbJKYo`_>-N*} z_S_lOU#oY#r$4j{8m1koUhcTW@S6Z?M25x5uD7;~ewU#yA5Dk{ zYclBP*zzT8Y6Jw(pk38PR{as)t@adXA(?@y1JUrO-{*#lL60m^(^>5`rX>cv{um24 zQ^*N0;^Z>`y@lxUwlxF?rz#O1vE_qKKORj>He=lN{3PF}P#W^cu0u&wPh*I9$`kzK zbH%VlvDN5xl6KUwDYGc(Zdj^6FUu)lwsRSsR4ehG40#!OxVAsfXNJ;y&m>pc_9j#+ zoR`HAnELGN8y3LSQYR%*&FqKmKx`-5cs$#EKHw(wrQ5d&LpR`950C08fT`ws!qccT zgDxkvZ#`gS6Z~LzlPmG@U0tN1)&(Fg-&LsjJ|FIVU`E&%LYX)MY8Q=p z?LFB^8X+{&0_)v0*`Lp>i z`SZrZ+|+)(cdV$Fo4F>ue(?!ULH zi&Wz!?ExaG3DR9zIpMX7ZVt@ZFC9)yfU~gR=#cpao&>`ee;jzsBvHld>e_p7-|8ju zlUR`36QYI=Khh+j{sc6lD0j6K z+`{la2D3e2aFo8cU_d>llU&dbzbQ(25nDk^x}s1rFT#MC;d&fk)8d&8HUzy6HH7*~ z6o+rg7?hS5fzmAf9WR3eR)2Hg=z%|I=!di~y^P>6OuO7uGLvJd`Nw`wn-h|k)cR}m zf_Yicz^{on@4Nzq$&#4uF&&0M@w{`jD1X=g~4*(5NT5%3NASdiK^Xun|YDdx@)#VQk z%e~H-y@}TD6S414*MGNH{PuL$+Y7ZlwgJ6h#>RYovT%Fm!Ha_^m4(>Ov6gh#y(c`b zDlfc~@fpv)nOL0fYz+HVuZ2V_AHR)2s?p>y#En7CRhdYz7gf%C;Q6>6BC7f}$j z2a{&yQ5mNXtU4ziwiMehfV-1RkiFQ3jp>(%FP`#BuY#hORTT#dq_> z&^c$(BwK&d0Kf`RD&19`#nwG?eQq-AlSQR&xlwYW3)Qcc%MBmizt~W(IAw72mA|TG z?My}LOx5u1WzbtDRl@=Y0#^nGNI&$GB+7#~rY@pXdRk}d*Jr1KECvHtZ2IgY#Sdkk zMAZM08A&z&h>_Z_tFGB9YvZ|?%)n)-4F@Icpi-)GKt&u8U`pNQlkm7kL36*wYR>ma zBW2lk8u17#kFqx;_ohE4yBLRSW<&OJ>z+CRrY;iKm2c0M0W4GXI15;ndHv`5*O?d{ zZciLh?t*uhd3X&30R~-<72SwfeL*z&dFe~|D409FublyCKwrSux*6aIvf=T~@9xUj z1e7OxkGDM&e;WJv*LuS*uPXu$gV&NGmjOoLs`~54<648rRoR{k4nk=j*Vx!g(?HKl z1=9j1Nd?mYlEPm+pPS27_B0~0{+0F&M>hyM+7#;8njqZER@L#US}-lp_5{py_jUrz{Sc+1 znS$GJoR_C&cN|OGP~OK&Myeb5<1$VLcaOCwuUx2PxXjmueV747^DWVz>^R9G9(!Ux zw^G%u>G3rHfTaY5W`77A?)#pRRh$g)m%u&~+#+al&N_es zdja5dLF=8^U1C$D5~T9{7-C`&%uIvqFjEsp9Si~BRL!UAsc@6`1Ub(@ab8{GcEkzv zoIWR8SN3kd9vfe8Rw40gO);^cu(vN+n+ONqeUx(|NRL2-OW&8$l?dKgN&-O6yQozF zt|deROyfzYVck@h3j7|?n6+ete^p_&YB&w5Ymos|P-c?rmWEquVon-y?L5dhAy)ci zXx$c`xN&wFK)r2uKW=cW3YR65*L*qGIyM;~WI@RWR*gl5BiDahbC- z=ESBI4;&v*BJD5w#XI#CM`QE&2((YeG6MSLA~+|n5aCP({HLt6kh#)DmZd(dOyXIG ziV8A=D6muP@OGc`m)moScWXTVjDf&YD*D_NS8jpy^d56j*eW;n4s^o5i#qWo=Nu6o zTt$*1>nYjeY6XVr%~}yZ$Ss1q0BV{Sbwuhprkog;!>szF4Q7E)_r2#*GWO-rEqtHX z1QFgEqvm>rU3{Tpj0}$}F~1J8PQ7?#?ndM(0<1sr^u^g6<6}nQkBGA6*UzUwTLmg3 zwDp`gP^QE}lU(g^_mLq96Sm{0$%*mCaW%!2q*l@4%V1m*W!P?`X#k?w{2fgbwrL~ME!WZ z0qd!9gnfay;-~_FOzb}bQ!i7VYtv*-&`&8_5~BUS+=sQ{Da#W!F@x%|o`rFi8FN@Y zYPy=kOzHOjeB-dRineuV#JmXImx2+iCkruxu-j#R`q#YRas0Y7lyZHoLtPdy`tosC zYrPAyr=gkbQtcPu5kfFstb zkW_)&4JeQoKZP<2;^x@xVw3fiI0Cy8tA1KSlAseQIy`}$8yeYRML{ZE?x#&tOFrwy zeLVWqo7x)83uL`CmSMz!vhPN4x{OAwCJ5Fsj*W7n`~wW9pNw17 zRE~9WVoLS0ATJ{%6LnI|Ds$8_qDi*!9DZktEkYuQAE9@z=PexxwqUf-hK+&3Kb55? zmk2k!4|q%tU_uUmd_wT@t)`yt+w+%_!^&+h#+U09_j%3ChjU{$s_;@tMyIxz-Xz+_2CU;y0VXHf_41G;)gMw zA__4j!ld)oJpQ?}vHB7Z6=$nnU|KQY!4A5V2kH{7uaI~IE*X0gQKPPNOjt)d=0KCV z3Yob3oHZnt6|;ek>F`OrZL2F0%K~u}BiMvjuO_-lXWg(hVW@kVL=s*rkkdP{!4A)u z?COroVJGE*rgZl1Ax91@Q_I`Cv8Uj8_CVxfyI3_59@u6bHRzQfneKl|3ug`WX`&m^ zNs;Et{d7}*UUpUB+LW`}>0LxI3bzGagI*0oW>7|anYi3qzoNZH&w7HOO%b6~3LfYH zEl21g>t#ZwsA=LmZx&_`1~cL9g3-+5tmBqoZ1)Dr@-D;lb$5}5=}g(4m0yLreQ1NU zUS^%+JP+eD1WyyZDOng+@l#fx%9THhbH_?xS_!b&e4j~g56te>C{U(MHJ((Au`jh< zOZ<^a^eWYLS1nWQn7-#yy*NZ!Le1`)NusD`b|K6 zukPebvEwt7jF=o&Jr(m7BNg%pmwXoed5EXbVOZv(ua#RF1DZC;QRJ{TmLARYPHfE} ze5m=fp2{6TSu%0T+b^G!7naLjK7SIS$8C9had%_j+M?&)^LkdDdtjGhnIDU#l5S^r$H(A}=L%)Pj# zCqHT(V_+%s8}K22YNwx|s}@cIk1>+0Kg8=6zciO;vszrtzirFfb1iYoL*H8+UN@NP z9lP(eM1rR>6wO0gL7;f{c==!CmTaE@}qr#N}A7c@F%#uF1 zOc`0H+Gi0RV5iw%Mn8amo8P$RINByGogx5QV-GBMC@6db8lvw6Uv!6-V z;lq&j&S$xo8-!Ty=7cFsn^a$jJp_ZA|IkHNyb$N8Yp&o*R&uXCSZPKy7xJ4@fJH2N z#gvRY>$K~IH&l4aq&G?!Dm+pfCb^b(-S=!eEvC@TSMKtpZrAyxqkUehKRZ3CpcRlcpM26b}2yAxVm;GqI zcI+oTXcAGFk^|EykS$n0me4sP&m5T)5If^))~StQ)w?a=Pm;IMqp=)8L^jNal~tiX zcec~72BnAhlw1G~R2Dt?W*1|8MNb(-KwhM^=bm3{mql)cc)~CdBbc5}JRyW(6l|Ey zEQLahG{Y-iX|hVe_S7xh6*$wpi)`&TQBTowzDT;GAg5uX-9V0?(cwiNw5$oh)hP=R zl1{nmBVN<{6$}@2kHVtMx=yXOEHB9p&e1j>?zDJBY*HMTE+6c4*d3jJ_19dk!p>-@ zmr4`Kt?oy2(G+zbke-RjyTBnv-J{vwKn%i= zZ}vuiQO^SJEFfvWRRLuPi_-<&VDuC%Ca7ce!Bbl^1qXx?!1m}EM#KO)?SpC#IzE7+ z+`wOQ;RGt@rW@rDY!p#)(ADQ(nA%79X(b2c58GP%aZRcwK;yqNpPTVR|~ies@G%GZ6ADi*TYOpP^?m z*J5@&&`F-s+9Cj=&fQdd2!ymJtMk?X8;sxP62A$s8bMzo z3urJ^4aUSa#6G*KHpLr#n}*!@1bB;Hh8l{IZOCjM$xOovY!7pL>LLLSbSk8o6CCKn z98r#e9UwDi1~r`rsAf<*2PEIO1kLtj(WQdg`+-Zq4>6;Xz10Z*y{N^E0gs0HNNsnSpeI=5D-z2J!ClPnzI=z3Up@~{gF zFPS~cGbaJC4x!Hx1PTw?)iT2(44yHO7>r4WfH@C`+}j5ZQ$o;k1&G%si*syYHGu8I zj10VlJ_?Y+F;i!6p8P~3NLLOkb97bSuP(8+)HV&E|chZu>Q6B z{hpPEH{67Im}|ZB@qqOxm=DEsZ>3IzJtP$XJO76MI39&fU0Ewwo@Z*cnjZrLN&$l4ckRIO4?WzOb#E%Loo78inqYh@ZBk_` z!2tML`{UB3qe^jtgAPcZbQfj=g52DSm$NFmhk4rBsG&+gOs`SIO(tqN{t!@Zymo56 zMwS)>u`gDv6v}wM!~b|6vB35bDl_1RL@8e9gT+5~HVyVaLHJ-wOS8 z=JM`g46Mc7DDQimt*qi2BioBQ6L6U#aJ+5hO2E&k z*86L(Qme)|kD=#}HGG6y0v^+g{~W+fE8?oMtDzU*~uS=?gbJ(FdjX!SK{*YtH{ ziyr>lm*aaVaY&wr1!Jc@u_GME&>G1RXMFD+rRxPz{*D=7r-}6B@Q#&_#bwz&7cQTE zmyT*EU3)*umEK#PvHWF2;}(GUoX#IUz(qq2g%zIVGYB!$@*tA!x!DM# z+7gSf5TH)`RCNG6AeRey5CJ5aA;6}F5deH%`A$~cMD`zqvpsLb-%zUpnf)_2j}@3B z+3%{IYh<(&omWFD)6;gP&IWiVy?3;2#+y;k%aT^!jRC@{zb2Y@23(#WdI3VEcWn+xRrxD=n=-Y~Qpq7hz z79F&+UsLBz0i-Usj~9cr2!pJ1;Dn?%yL7-=_`zAiJV?hj&yw|$(Jo^7O4bs!2JG5= zsC9|TAVr;b4KNtL!>0_Y3t-R&)NeLIo8!-5#sU~zQ(HI!PEDb27NZLBI=x$y7d#DY zyh80 client.lifetime) { - early = client.lifetime; - } - - next = MIN(period, client.lifetime - early); - next = MAX(next, MINIMUM_PERIOD); - - return client.last_update + next * MSEC_PER_SEC; + /* + * check for lifetime seconds - SECONDS_TO_UPDATE_EARLY + * so that we can update early and avoid lifetime timeout + */ + return client.last_update + (client.lifetime - SECONDS_TO_UPDATE_EARLY) * MSEC_PER_SEC; } static int64_t next_rx_off(void) diff --git a/tests/net/lib/lwm2m/interop/prj.conf b/tests/net/lib/lwm2m/interop/prj.conf index 66d6334264f..5d255e0513e 100644 --- a/tests/net/lib/lwm2m/interop/prj.conf +++ b/tests/net/lib/lwm2m/interop/prj.conf @@ -61,8 +61,6 @@ CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=40 # Use QUEUE mode by default CONFIG_LWM2M_QUEUE_MODE_ENABLED=y CONFIG_LWM2M_QUEUE_MODE_UPTIME=20 -CONFIG_LWM2M_UPDATE_PERIOD=30 -CONFIG_LWM2M_SECONDS_TO_UPDATE_EARLY=10 # LwM2M configuration as OMA-ETS-LightweightM2M_INT-V1_1-20190912-D Configuration 3 CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=30 diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt b/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt index 2a8e8959c25..81e129c56c1 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt @@ -32,4 +32,3 @@ add_compile_definitions(CONFIG_LWM2M_QUEUE_MODE_ENABLED=1) add_compile_definitions(CONFIG_LWM2M_TLS_SESSION_CACHING=1) add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_LISTEN_AT_IDLE=1) add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP=1) -add_compile_definitions(CONFIG_LWM2M_UPDATE_PERIOD=0) From 6fb13649ad9a711b12c613b656900536836f062b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:39 +0000 Subject: [PATCH 0836/1623] Revert "[nrf fromlist] net: coap: release non-confirmable messages" This reverts commit db7577339d36b3f44997d478cb10207df51fc23a. Signed-off-by: Dominik Ermel --- subsys/net/lib/coap/coap_client.c | 79 +++++++++++++++++++--------- tests/net/lib/coap_client/src/main.c | 4 +- 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/subsys/net/lib/coap/coap_client.c b/subsys/net/lib/coap/coap_client.c index e78aafd6829..d096e39c62f 100644 --- a/subsys/net/lib/coap/coap_client.c +++ b/subsys/net/lib/coap/coap_client.c @@ -308,6 +308,12 @@ int coap_client_req(struct coap_client *client, int sock, const struct sockaddr reset_internal_request(internal_req); + if (retries == -1) { + internal_req->retry_count = DEFAULT_RETRY_AMOUNT; + } else { + internal_req->retry_count = retries; + } + if (k_mutex_lock(&client->send_mutex, K_NO_WAIT)) { return -EAGAIN; } @@ -326,26 +332,17 @@ int coap_client_req(struct coap_client *client, int sock, const struct sockaddr goto out; } - /* only TYPE_CON messages need pending tracking */ - if (coap_header_get_type(&internal_req->request) == COAP_TYPE_CON) { - if (retries == -1) { - internal_req->retry_count = DEFAULT_RETRY_AMOUNT; - } else { - internal_req->retry_count = retries; - } - - ret = coap_pending_init(&internal_req->pending, &internal_req->request, - &client->address, internal_req->retry_count); - - if (ret < 0) { - LOG_ERR("Failed to initialize pending struct"); - k_mutex_unlock(&client->send_mutex); - goto out; - } + ret = coap_pending_init(&internal_req->pending, &internal_req->request, &client->address, + internal_req->retry_count); - coap_pending_cycle(&internal_req->pending); + if (ret < 0) { + LOG_ERR("Failed to initialize pending struct"); + k_mutex_unlock(&client->send_mutex); + goto out; } + coap_pending_cycle(&internal_req->pending); + ret = send_request(sock, internal_req->request.data, internal_req->request.offset, 0, &client->address, client->socklen); @@ -371,10 +368,6 @@ static void report_callback_error(struct coap_client_internal_request *internal_ static bool timeout_expired(struct coap_client_internal_request *internal_req) { - if (internal_req->pending.timeout == 0) { - return false; - } - return (internal_req->request_ongoing && internal_req->pending.timeout <= (k_uptime_get() - internal_req->pending.t0)); } @@ -554,6 +547,35 @@ static int send_ack(struct coap_client *client, const struct coap_packet *req, return 0; } +static int send_reset(struct coap_client *client, const struct coap_packet *req, + uint8_t response_code) +{ + int ret; + uint16_t id; + uint8_t token[COAP_TOKEN_MAX_LEN]; + uint8_t tkl; + struct coap_packet reset; + + id = coap_header_get_id(req); + tkl = response_code ? coap_header_get_token(req, token) : 0; + ret = coap_packet_init(&reset, client->send_buf, MAX_COAP_MSG_LEN, COAP_VERSION, + COAP_TYPE_RESET, tkl, token, response_code, id); + + if (ret < 0) { + LOG_ERR("Error creating CoAP reset message"); + return ret; + } + + ret = send_request(client->fd, reset.data, reset.offset, 0, + &client->address, client->socklen); + if (ret < 0) { + LOG_ERR("Error sending CoAP reset message"); + return ret; + } + + return 0; +} + struct coap_client_internal_request *get_request_with_id(struct coap_client *client, uint16_t message_id) { @@ -609,7 +631,7 @@ static int handle_response(struct coap_client *client, const struct coap_packet */ response_type = coap_header_get_type(response); - internal_req = get_request_with_token(client, response); + internal_req = get_request_with_id(client, coap_header_get_id(response)); /* Reset and Ack need to match the message ID with request */ if ((response_type == COAP_TYPE_ACK || response_type == COAP_TYPE_RESET) && internal_req == NULL) { @@ -633,8 +655,17 @@ static int handle_response(struct coap_client *client, const struct coap_packet return 1; } + /* Check for tokens + * Separate response doesn't match with message ID, + * check if there is a separate request waiting with matching token + */ + if (internal_req == NULL) { + internal_req = get_request_with_token(client, response); + } + if (internal_req == NULL || !token_compare(internal_req, response)) { - LOG_WRN("Not matching tokens"); + LOG_ERR("Not matching tokens, respond with reset"); + ret = send_reset(client, response, COAP_RESPONSE_CODE_NOT_FOUND); return 1; } @@ -764,7 +795,7 @@ void coap_client_recv(void *coap_cl, void *a, void *b) ret = handle_response(clients[i], &response); if (ret < 0) { - LOG_ERR("Error handling response"); + LOG_ERR("Error handling respnse"); } clients[i]->response_ready = false; diff --git a/tests/net/lib/coap_client/src/main.c b/tests/net/lib/coap_client/src/main.c index bb9d9fc38c5..a3862852c21 100644 --- a/tests/net/lib/coap_client/src/main.c +++ b/tests/net/lib/coap_client/src/main.c @@ -392,5 +392,7 @@ ZTEST(coap_client, test_unmatching_tokens) k_sleep(K_MSEC(1)); k_sleep(K_MSEC(1)); clear_socket_events(); - k_sleep(K_MSEC(1000)); + zassert_equal(last_response_code, COAP_RESPONSE_CODE_NOT_FOUND, "Unexpected response %d", + last_response_code); + k_sleep(K_MSEC(1)); } From ad141108e7b09da8c03795dd6295983b0e3acbbc Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:39 +0000 Subject: [PATCH 0837/1623] Revert "[nrf fromtree] tests: mcumgr: Updated MCUmg & smp client tests" This reverts commit 63548546a8126ab0b0c7c780cf9add80d00c2c73. Signed-off-by: Dominik Ermel --- .../subsys/mgmt/mcumgr/mcumgr_client/CMakeLists.txt | 2 +- tests/subsys/mgmt/mcumgr/mcumgr_client/prj.conf | 7 ++----- .../mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c | 10 ++-------- tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c | 12 ++++++------ tests/subsys/mgmt/mcumgr/mcumgr_client/testcase.yaml | 11 ----------- tests/subsys/mgmt/mcumgr/smp_client/src/main.c | 6 +++--- tests/subsys/mgmt/mcumgr/smp_client/testcase.yaml | 11 ----------- 7 files changed, 14 insertions(+), 45 deletions(-) delete mode 100644 tests/subsys/mgmt/mcumgr/mcumgr_client/testcase.yaml delete mode 100644 tests/subsys/mgmt/mcumgr/smp_client/testcase.yaml diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/CMakeLists.txt b/tests/subsys/mgmt/mcumgr/mcumgr_client/CMakeLists.txt index 20a96480514..a0f76554629 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/CMakeLists.txt +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/CMakeLists.txt @@ -14,4 +14,4 @@ FILE(GLOB app_sources target_sources(app PRIVATE ${app_sources}) -zephyr_library_link_libraries(MCUBOOT_BOOTUTIL) +add_compile_definitions(CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER=1) diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/prj.conf b/tests/subsys/mgmt/mcumgr/mcumgr_client/prj.conf index 461a0ec9477..46835a49dc7 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/prj.conf +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/prj.conf @@ -12,17 +12,14 @@ CONFIG_NET_BUF=y CONFIG_BASE64=y CONFIG_ZCBOR=y CONFIG_CRC=y -# Enable MCUboot util library -CONFIG_MCUBOOT_BOOTUTIL_LIB=y -# Enable mcumgr client +# Enable mcumgr CONFIG_MCUMGR=y CONFIG_SMP_CLIENT=y +CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER=1 CONFIG_MCUMGR_GRP_OS_CLIENT=y CONFIG_MCUMGR_GRP_IMG_CLIENT=y CONFIG_MCUMGR_GRP_OS_CLIENT_ECHO=y CONFIG_MCUMGR_GRP_OS_CLIENT_RESET=y -# disable default image group build -CONFIG_IMG_MANAGER=n # Extend System Workqueue stack size CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304 diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c index aea03935fe6..5bd784a3954 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c @@ -24,12 +24,6 @@ static struct mcumgr_image_data image_dummy_info[2]; static size_t test_offset; static uint8_t *image_hash_ptr; -#ifdef CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER -#define IMG_UPDATABLE_IMAGE_COUNT CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER -#else -#define IMG_UPDATABLE_IMAGE_COUNT 1 -#endif - #define ZCBOR_ENCODE_FLAG(zse, label, value) \ (zcbor_tstr_put_lit(zse, label) && zcbor_bool_put(zse, value)) @@ -123,7 +117,7 @@ void img_read_response(int count) zcbor_tstr_put_term(zse, image_dummy_info[i].version) && zcbor_tstr_put_term(zse, "hash") && - zcbor_bstr_encode_ptr(zse, image_dummy_info[i].hash, IMG_MGMT_DATA_SHA_LEN) && + zcbor_bstr_encode_ptr(zse, image_dummy_info[i].hash, IMG_MGMT_HASH_LEN) && ZCBOR_ENCODE_FLAG(zse, "bootable", image_dummy_info[i].flags.bootable) && ZCBOR_ENCODE_FLAG(zse, "pending", image_dummy_info[i].flags.pending) && ZCBOR_ENCODE_FLAG(zse, "confirmed", image_dummy_info[i].flags.confirmed) && @@ -132,7 +126,7 @@ void img_read_response(int count) zcbor_map_end_encode(zse, 15); } - ok = ok && zcbor_list_end_encode(zse, 2 * IMG_UPDATABLE_IMAGE_COUNT); + ok = ok && zcbor_list_end_encode(zse, 2 * CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER); ok = ok && zcbor_map_end_encode(zse, 15); diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c index bf70f178fe7..a15e82f17a6 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c @@ -27,7 +27,7 @@ static struct smp_client_object smp_client; static struct img_mgmt_client img_client; static struct os_mgmt_client os_client; -ZTEST(mcumgr_client, test_img_upload) +ZTEST(mcumgr_client, img_upload) { int rc; struct mcumgr_image_upload response; @@ -108,7 +108,7 @@ ZTEST(mcumgr_client, test_img_upload) response.image_upload_offset); } -ZTEST(mcumgr_client, test_img_erase) +ZTEST(mcumgr_client, img_erase) { int rc; @@ -130,7 +130,7 @@ ZTEST(mcumgr_client, test_img_erase) zassert_equal(MGMT_ERR_EOK, rc, "Expected to receive %d response %d", MGMT_ERR_EOK, rc); } -ZTEST(mcumgr_client, test_image_state_read) +ZTEST(mcumgr_client, image_state_read) { int rc; struct mcumgr_image_state res_buf; @@ -153,7 +153,7 @@ ZTEST(mcumgr_client, test_image_state_read) res_buf.image_list_length); } -ZTEST(mcumgr_client, test_image_state_set) +ZTEST(mcumgr_client, image_state_set) { int rc; char hash[32]; @@ -199,7 +199,7 @@ ZTEST(mcumgr_client, test_image_state_set) true, image_info[0].flags.confirmed); } -ZTEST(mcumgr_client, test_os_reset) +ZTEST(mcumgr_client, os_reset) { int rc; @@ -217,7 +217,7 @@ ZTEST(mcumgr_client, test_os_reset) zassert_equal(MGMT_ERR_EOK, rc, "Expected to receive %d response %d", MGMT_ERR_EOK, rc); } -ZTEST(mcumgr_client, test_os_echo) +ZTEST(mcumgr_client, os_echo) { int rc; diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/testcase.yaml b/tests/subsys/mgmt/mcumgr/mcumgr_client/testcase.yaml deleted file mode 100644 index 99b9fac34ad..00000000000 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/testcase.yaml +++ /dev/null @@ -1,11 +0,0 @@ -# -# Copyright (c) 2023 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 -# -tests: - mgmt.mcumgr.mcumgr.client: - platform_allow: native_posix - tags: - - mcumgr - - mcumgr_client diff --git a/tests/subsys/mgmt/mcumgr/smp_client/src/main.c b/tests/subsys/mgmt/mcumgr/smp_client/src/main.c index 7b6ad8eafa8..be1a3968274 100644 --- a/tests/subsys/mgmt/mcumgr/smp_client/src/main.c +++ b/tests/subsys/mgmt/mcumgr/smp_client/src/main.c @@ -32,7 +32,7 @@ int smp_client_res_cb(struct net_buf *nb, void *user_data) return 0; } -ZTEST(smp_client, test_buf_alloc) +ZTEST(smp_client, buf_alloc) { struct smp_client_object smp_client; @@ -56,7 +56,7 @@ ZTEST(smp_client, test_buf_alloc) } } -ZTEST(smp_client, test_msg_send_timeout) +ZTEST(smp_client, msg_send_timeout) { struct net_buf *nb; @@ -72,7 +72,7 @@ ZTEST(smp_client, test_msg_send_timeout) zassert_equal_ptr(response_ptr, &testing_user_data, "User data not returned correctly"); } -ZTEST(smp_client, test_msg_response_handler) +ZTEST(smp_client, msg_response_handler) { struct smp_hdr dst_hdr; int rc; diff --git a/tests/subsys/mgmt/mcumgr/smp_client/testcase.yaml b/tests/subsys/mgmt/mcumgr/smp_client/testcase.yaml deleted file mode 100644 index 49971116251..00000000000 --- a/tests/subsys/mgmt/mcumgr/smp_client/testcase.yaml +++ /dev/null @@ -1,11 +0,0 @@ -# -# Copyright (c) 2023 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 -# -tests: - mgmt.mcumgr.smp.client: - platform_allow: native_posix - tags: - - mcumgr - - smp_client From 6ca557ee335956aeb85603d00700f1e910d7d786 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:40 +0000 Subject: [PATCH 0838/1623] Revert "[nrf fromtree] mgmt: mcumgr: Image management client fix" This reverts commit 7f84783145206883918b27572dcd32f25698e265. Signed-off-by: Dominik Ermel --- .../mgmt/mcumgr/grp/img_mgmt/img_mgmt_client.h | 4 ++-- .../mgmt/mcumgr/grp/img_mgmt_client/CMakeLists.txt | 1 - .../mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c | 12 ++++++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/zephyr/mgmt/mcumgr/grp/img_mgmt/img_mgmt_client.h b/include/zephyr/mgmt/mcumgr/grp/img_mgmt/img_mgmt_client.h index 8cede40d64e..6ee12fb5a61 100644 --- a/include/zephyr/mgmt/mcumgr/grp/img_mgmt/img_mgmt_client.h +++ b/include/zephyr/mgmt/mcumgr/grp/img_mgmt/img_mgmt_client.h @@ -40,7 +40,7 @@ struct mcumgr_image_data { /** Image number */ uint32_t img_num; /** Image SHA256 checksum */ - char hash[IMG_MGMT_DATA_SHA_LEN]; + char hash[IMG_MGMT_HASH_LEN]; /** Image Version */ char version[IMG_MGMT_VER_MAX_STR_LEN + 1]; /** Image Flags */ @@ -76,7 +76,7 @@ struct mcumgr_image_upload { */ struct img_gr_upload { /** Image 256-bit hash */ - char sha256[IMG_MGMT_DATA_SHA_LEN]; + char sha256[IMG_MGMT_HASH_LEN]; /** True when Hash is configured, false when not */ bool hash_initialized; /** Image size */ diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt_client/CMakeLists.txt b/subsys/mgmt/mcumgr/grp/img_mgmt_client/CMakeLists.txt index cae17e865ff..693891896d8 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt_client/CMakeLists.txt +++ b/subsys/mgmt/mcumgr/grp/img_mgmt_client/CMakeLists.txt @@ -13,4 +13,3 @@ zephyr_library_sources( ) zephyr_library_include_directories(include) -zephyr_library_link_libraries(MCUBOOT_BOOTUTIL) diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c b/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c index 9ab8ee02dcd..b0e38640e8c 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c @@ -126,7 +126,7 @@ static int image_state_res_fn(struct net_buf *nb, void *user_data) goto out; } /* Check that mandatory parameters have decoded */ - if (hash.len != IMG_MGMT_DATA_SHA_LEN || !version.len || + if (hash.len != IMG_MGMT_HASH_LEN || !version.len || !zcbor_map_decode_bulk_key_found(list_res_decode, ARRAY_SIZE(list_res_decode), "slot")) { LOG_ERR("Missing mandatory parametrs"); @@ -138,7 +138,7 @@ static int image_state_res_fn(struct net_buf *nb, void *user_data) image_info->image_list[image_info->image_list_length].img_num = img_num; image_info->image_list[image_info->image_list_length].slot_num = slot_num; memcpy(image_info->image_list[image_info->image_list_length].hash, - hash.value, IMG_MGMT_DATA_SHA_LEN); + hash.value, IMG_MGMT_HASH_LEN); if (version.len > IMG_MGMT_VER_MAX_STR_LEN) { LOG_WRN("Version truncated len %d -> %d", version.len, IMG_MGMT_VER_MAX_STR_LEN); @@ -277,7 +277,7 @@ static size_t upload_message_header_size(struct img_gr_upload *upload_state) /* Write hash when it defined and offset is 0 */ if (ok && upload_state->hash_initialized) { ok = zcbor_tstr_put_lit(zse, "sha") && - zcbor_bstr_encode_ptr(zse, upload_state->sha256, IMG_MGMT_DATA_SHA_LEN); + zcbor_bstr_encode_ptr(zse, upload_state->sha256, IMG_MGMT_HASH_LEN); } if (ok) { @@ -311,7 +311,7 @@ int img_mgmt_client_upload_init(struct img_mgmt_client *client, size_t image_siz client->upload.offset = 0; client->upload.image_num = image_num; if (image_hash) { - memcpy(client->upload.sha256, image_hash, IMG_MGMT_DATA_SHA_LEN); + memcpy(client->upload.sha256, image_hash, IMG_MGMT_HASH_LEN); client->upload.hash_initialized = true; } else { client->upload.hash_initialized = false; @@ -395,7 +395,7 @@ int img_mgmt_client_upload(struct img_mgmt_client *client, const uint8_t *data, if (ok && active_client->upload.hash_initialized) { ok = zcbor_tstr_put_lit(zse, "sha") && zcbor_bstr_encode_ptr(zse, active_client->upload.sha256, - IMG_MGMT_DATA_SHA_LEN); + IMG_MGMT_HASH_LEN); } } @@ -485,7 +485,7 @@ int img_mgmt_client_state_write(struct img_mgmt_client *client, char *hash, bool /* Write hash data */ if (ok && hash) { ok = zcbor_tstr_put_lit(zse, "hash") && - zcbor_bstr_encode_ptr(zse, hash, IMG_MGMT_DATA_SHA_LEN); + zcbor_bstr_encode_ptr(zse, hash, IMG_MGMT_HASH_LEN); } /* Close map */ if (ok) { From 86210cc1a121ef9115779a64cf14644badc09824 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:41 +0000 Subject: [PATCH 0839/1623] Revert "[nrf fromtree] net: coap: Improve CoAP Doxygen comments" This reverts commit 2158801356d3cfc3ed113afdc34b0e149446d9a3. Signed-off-by: Dominik Ermel --- include/zephyr/net/coap.h | 156 +++++++++++++++----------------------- 1 file changed, 61 insertions(+), 95 deletions(-) diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index 6fc21a6280b..5952cf77d83 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -42,25 +42,25 @@ extern "C" { * Refer to RFC 7252, section 12.2 for more information. */ enum coap_option_num { - COAP_OPTION_IF_MATCH = 1, /**< If-Match */ - COAP_OPTION_URI_HOST = 3, /**< Uri-Host */ - COAP_OPTION_ETAG = 4, /**< ETag */ - COAP_OPTION_IF_NONE_MATCH = 5, /**< If-None-Match */ - COAP_OPTION_OBSERVE = 6, /**< Observe (RFC 7641) */ - COAP_OPTION_URI_PORT = 7, /**< Uri-Port */ - COAP_OPTION_LOCATION_PATH = 8, /**< Location-Path */ - COAP_OPTION_URI_PATH = 11, /**< Uri-Path */ - COAP_OPTION_CONTENT_FORMAT = 12, /**< Content-Format */ - COAP_OPTION_MAX_AGE = 14, /**< Max-Age */ - COAP_OPTION_URI_QUERY = 15, /**< Uri-Query */ - COAP_OPTION_ACCEPT = 17, /**< Accept */ - COAP_OPTION_LOCATION_QUERY = 20, /**< Location-Query */ - COAP_OPTION_BLOCK2 = 23, /**< Block2 (RFC 7959) */ - COAP_OPTION_BLOCK1 = 27, /**< Block1 (RFC 7959) */ - COAP_OPTION_SIZE2 = 28, /**< Size2 (RFC 7959) */ - COAP_OPTION_PROXY_URI = 35, /**< Proxy-Uri */ - COAP_OPTION_PROXY_SCHEME = 39, /**< Proxy-Scheme */ - COAP_OPTION_SIZE1 = 60 /**< Size1 */ + COAP_OPTION_IF_MATCH = 1, + COAP_OPTION_URI_HOST = 3, + COAP_OPTION_ETAG = 4, + COAP_OPTION_IF_NONE_MATCH = 5, + COAP_OPTION_OBSERVE = 6, + COAP_OPTION_URI_PORT = 7, + COAP_OPTION_LOCATION_PATH = 8, + COAP_OPTION_URI_PATH = 11, + COAP_OPTION_CONTENT_FORMAT = 12, + COAP_OPTION_MAX_AGE = 14, + COAP_OPTION_URI_QUERY = 15, + COAP_OPTION_ACCEPT = 17, + COAP_OPTION_LOCATION_QUERY = 20, + COAP_OPTION_BLOCK2 = 23, + COAP_OPTION_BLOCK1 = 27, + COAP_OPTION_SIZE2 = 28, + COAP_OPTION_PROXY_URI = 35, + COAP_OPTION_PROXY_SCHEME = 39, + COAP_OPTION_SIZE1 = 60, }; /** @@ -69,13 +69,13 @@ enum coap_option_num { * To be used when creating a request or a response. */ enum coap_method { - COAP_METHOD_GET = 1, /**< GET */ - COAP_METHOD_POST = 2, /**< POST */ - COAP_METHOD_PUT = 3, /**< PUT */ - COAP_METHOD_DELETE = 4, /**< DELETE */ - COAP_METHOD_FETCH = 5, /**< FETCH */ - COAP_METHOD_PATCH = 6, /**< PATCH */ - COAP_METHOD_IPATCH = 7, /**< IPATCH */ + COAP_METHOD_GET = 1, + COAP_METHOD_POST = 2, + COAP_METHOD_PUT = 3, + COAP_METHOD_DELETE = 4, + COAP_METHOD_FETCH = 5, + COAP_METHOD_PATCH = 6, + COAP_METHOD_IPATCH = 7, }; #define COAP_REQUEST_MASK 0x07 @@ -120,7 +120,7 @@ enum coap_msgtype { * @param class Class of the response code (ex. 2, 4, 5, ...) * @param det Detail of the response code * @return Response code literal - */ +*/ #define COAP_MAKE_RESPONSE_CODE(class, det) ((class << 5) | (det)) /** @@ -129,60 +129,33 @@ enum coap_msgtype { * To be used when creating a response. */ enum coap_response_code { - /** 2.00 - OK */ COAP_RESPONSE_CODE_OK = COAP_MAKE_RESPONSE_CODE(2, 0), - /** 2.01 - Created */ COAP_RESPONSE_CODE_CREATED = COAP_MAKE_RESPONSE_CODE(2, 1), - /** 2.02 - Deleted */ COAP_RESPONSE_CODE_DELETED = COAP_MAKE_RESPONSE_CODE(2, 2), - /** 2.03 - Valid */ COAP_RESPONSE_CODE_VALID = COAP_MAKE_RESPONSE_CODE(2, 3), - /** 2.04 - Changed */ COAP_RESPONSE_CODE_CHANGED = COAP_MAKE_RESPONSE_CODE(2, 4), - /** 2.05 - Content */ COAP_RESPONSE_CODE_CONTENT = COAP_MAKE_RESPONSE_CODE(2, 5), - /** 2.31 - Continue */ COAP_RESPONSE_CODE_CONTINUE = COAP_MAKE_RESPONSE_CODE(2, 31), - /** 4.00 - Bad Request */ COAP_RESPONSE_CODE_BAD_REQUEST = COAP_MAKE_RESPONSE_CODE(4, 0), - /** 4.01 - Unauthorized */ COAP_RESPONSE_CODE_UNAUTHORIZED = COAP_MAKE_RESPONSE_CODE(4, 1), - /** 4.02 - Bad Option */ COAP_RESPONSE_CODE_BAD_OPTION = COAP_MAKE_RESPONSE_CODE(4, 2), - /** 4.03 - Forbidden */ COAP_RESPONSE_CODE_FORBIDDEN = COAP_MAKE_RESPONSE_CODE(4, 3), - /** 4.04 - Not Found */ COAP_RESPONSE_CODE_NOT_FOUND = COAP_MAKE_RESPONSE_CODE(4, 4), - /** 4.05 - Method Not Allowed */ COAP_RESPONSE_CODE_NOT_ALLOWED = COAP_MAKE_RESPONSE_CODE(4, 5), - /** 4.06 - Not Acceptable */ COAP_RESPONSE_CODE_NOT_ACCEPTABLE = COAP_MAKE_RESPONSE_CODE(4, 6), - /** 4.08 - Request Entity Incomplete */ COAP_RESPONSE_CODE_INCOMPLETE = COAP_MAKE_RESPONSE_CODE(4, 8), - /** 4.12 - Precondition Failed */ COAP_RESPONSE_CODE_CONFLICT = COAP_MAKE_RESPONSE_CODE(4, 9), - /** 4.12 - Precondition Failed */ COAP_RESPONSE_CODE_PRECONDITION_FAILED = COAP_MAKE_RESPONSE_CODE(4, 12), - /** 4.13 - Request Entity Too Large */ COAP_RESPONSE_CODE_REQUEST_TOO_LARGE = COAP_MAKE_RESPONSE_CODE(4, 13), - /** 4.15 - Unsupported Content-Format */ COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT = COAP_MAKE_RESPONSE_CODE(4, 15), - /** 4.22 - Unprocessable Entity */ COAP_RESPONSE_CODE_UNPROCESSABLE_ENTITY = COAP_MAKE_RESPONSE_CODE(4, 22), - /** 4.29 - Too Many Requests */ COAP_RESPONSE_CODE_TOO_MANY_REQUESTS = COAP_MAKE_RESPONSE_CODE(4, 29), - /** 5.00 - Internal Server Error */ COAP_RESPONSE_CODE_INTERNAL_ERROR = COAP_MAKE_RESPONSE_CODE(5, 0), - /** 5.01 - Not Implemented */ COAP_RESPONSE_CODE_NOT_IMPLEMENTED = COAP_MAKE_RESPONSE_CODE(5, 1), - /** 5.02 - Bad Gateway */ COAP_RESPONSE_CODE_BAD_GATEWAY = COAP_MAKE_RESPONSE_CODE(5, 2), - /** 5.03 - Service Unavailable */ COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE = COAP_MAKE_RESPONSE_CODE(5, 3), - /** 5.04 - Gateway Timeout */ COAP_RESPONSE_CODE_GATEWAY_TIMEOUT = COAP_MAKE_RESPONSE_CODE(5, 4), - /** 5.05 - Proxying Not Supported */ COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED = COAP_MAKE_RESPONSE_CODE(5, 5) }; @@ -197,15 +170,15 @@ enum coap_response_code { * To be used when encoding or decoding a Content-Format option. */ enum coap_content_format { - COAP_CONTENT_FORMAT_TEXT_PLAIN = 0, /**< text/plain;charset=utf-8 */ - COAP_CONTENT_FORMAT_APP_LINK_FORMAT = 40, /**< application/link-format */ - COAP_CONTENT_FORMAT_APP_XML = 41, /**< application/xml */ - COAP_CONTENT_FORMAT_APP_OCTET_STREAM = 42, /**< application/octet-stream */ - COAP_CONTENT_FORMAT_APP_EXI = 47, /**< application/exi */ - COAP_CONTENT_FORMAT_APP_JSON = 50, /**< application/json */ - COAP_CONTENT_FORMAT_APP_JSON_PATCH_JSON = 51, /**< application/json-patch+json */ - COAP_CONTENT_FORMAT_APP_MERGE_PATCH_JSON = 52, /**< application/merge-patch+json */ - COAP_CONTENT_FORMAT_APP_CBOR = 60 /**< application/cbor */ + COAP_CONTENT_FORMAT_TEXT_PLAIN = 0, /* charset=urf-8 */ + COAP_CONTENT_FORMAT_APP_LINK_FORMAT = 40, + COAP_CONTENT_FORMAT_APP_XML = 41, + COAP_CONTENT_FORMAT_APP_OCTET_STREAM = 42, + COAP_CONTENT_FORMAT_APP_EXI = 47, + COAP_CONTENT_FORMAT_APP_JSON = 50, + COAP_CONTENT_FORMAT_APP_JSON_PATCH_JSON = 51, + COAP_CONTENT_FORMAT_APP_MERGE_PATCH_JSON = 52, + COAP_CONTENT_FORMAT_APP_CBOR = 60, }; /* block option helper */ @@ -266,32 +239,25 @@ struct coap_observer { * @brief Representation of a CoAP Packet. */ struct coap_packet { - uint8_t *data; /**< User allocated buffer */ - uint16_t offset; /**< CoAP lib maintains offset while adding data */ - uint16_t max_len; /**< Max CoAP packet data length */ - uint8_t hdr_len; /**< CoAP header length */ - uint16_t opt_len; /**< Total options length (delta + len + value) */ - uint16_t delta; /**< Used for delta calculation in CoAP packet */ -#if defined(CONFIG_COAP_KEEP_USER_DATA) || defined(DOXGEN) - /** - * Application specific user data. - * Only available when @kconfig{CONFIG_COAP_KEEP_USER_DATA} is enabled. - */ - void *user_data; + uint8_t *data; /* User allocated buffer */ + uint16_t offset; /* CoAP lib maintains offset while adding data */ + uint16_t max_len; /* Max CoAP packet data length */ + uint8_t hdr_len; /* CoAP header length */ + uint16_t opt_len; /* Total options length (delta + len + value) */ + uint16_t delta; /* Used for delta calculation in CoAP packet */ +#if defined(CONFIG_COAP_KEEP_USER_DATA) + void *user_data; /* Application specific user data */ #endif }; -/** - * @brief Representation of a CoAP option. - */ struct coap_option { - uint16_t delta; /**< Option delta */ + uint16_t delta; #if defined(CONFIG_COAP_EXTENDED_OPTIONS_LEN) uint16_t len; uint8_t value[CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE]; #else - uint8_t len; /**< Option length */ - uint8_t value[12]; /**< Option value */ + uint8_t len; + uint8_t value[12]; #endif }; @@ -311,13 +277,13 @@ typedef int (*coap_reply_t)(const struct coap_packet *response, * @brief Represents a request awaiting for an acknowledgment (ACK). */ struct coap_pending { - struct sockaddr addr; /**< Remote address */ - int64_t t0; /**< Time when the request was sent */ - uint32_t timeout; /**< Timeout in ms */ - uint16_t id; /**< Message id */ - uint8_t *data; /**< User allocated buffer */ - uint16_t len; /**< Length of the CoAP packet */ - uint8_t retries; /**< Number of times the request has been sent */ + struct sockaddr addr; + int64_t t0; + uint32_t timeout; + uint16_t id; + uint8_t *data; + uint16_t len; + uint8_t retries; }; /** @@ -597,13 +563,13 @@ int coap_handle_request(struct coap_packet *cpkt, * https://tools.ietf.org/html/rfc7959 */ enum coap_block_size { - COAP_BLOCK_16, /**< 16-byte block size */ - COAP_BLOCK_32, /**< 32-byte block size */ - COAP_BLOCK_64, /**< 64-byte block size */ - COAP_BLOCK_128, /**< 128-byte block size */ - COAP_BLOCK_256, /**< 256-byte block size */ - COAP_BLOCK_512, /**< 512-byte block size */ - COAP_BLOCK_1024, /**< 1024-byte block size */ + COAP_BLOCK_16, + COAP_BLOCK_32, + COAP_BLOCK_64, + COAP_BLOCK_128, + COAP_BLOCK_256, + COAP_BLOCK_512, + COAP_BLOCK_1024, }; /** From bad438ac4646c2c6d49567a1247f01983f08096a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:41 +0000 Subject: [PATCH 0840/1623] Revert "[nrf fromtree] net: coap: Capitalize and document COAP_MAKE_RESPONSE_CODE macro" This reverts commit 4baf98b57ba7177839d831e35aa56696f50a598a. Signed-off-by: Dominik Ermel --- include/zephyr/net/coap.h | 62 ++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index 5952cf77d83..55776bfc6d8 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -115,13 +115,7 @@ enum coap_msgtype { COAP_TYPE_RESET = 3 }; -/** - * Utility macro to create a CoAP response code. - * @param class Class of the response code (ex. 2, 4, 5, ...) - * @param det Detail of the response code - * @return Response code literal -*/ -#define COAP_MAKE_RESPONSE_CODE(class, det) ((class << 5) | (det)) +#define coap_make_response_code(class, det) ((class << 5) | (det)) /** * @brief Set of response codes available for a response packet. @@ -129,35 +123,35 @@ enum coap_msgtype { * To be used when creating a response. */ enum coap_response_code { - COAP_RESPONSE_CODE_OK = COAP_MAKE_RESPONSE_CODE(2, 0), - COAP_RESPONSE_CODE_CREATED = COAP_MAKE_RESPONSE_CODE(2, 1), - COAP_RESPONSE_CODE_DELETED = COAP_MAKE_RESPONSE_CODE(2, 2), - COAP_RESPONSE_CODE_VALID = COAP_MAKE_RESPONSE_CODE(2, 3), - COAP_RESPONSE_CODE_CHANGED = COAP_MAKE_RESPONSE_CODE(2, 4), - COAP_RESPONSE_CODE_CONTENT = COAP_MAKE_RESPONSE_CODE(2, 5), - COAP_RESPONSE_CODE_CONTINUE = COAP_MAKE_RESPONSE_CODE(2, 31), - COAP_RESPONSE_CODE_BAD_REQUEST = COAP_MAKE_RESPONSE_CODE(4, 0), - COAP_RESPONSE_CODE_UNAUTHORIZED = COAP_MAKE_RESPONSE_CODE(4, 1), - COAP_RESPONSE_CODE_BAD_OPTION = COAP_MAKE_RESPONSE_CODE(4, 2), - COAP_RESPONSE_CODE_FORBIDDEN = COAP_MAKE_RESPONSE_CODE(4, 3), - COAP_RESPONSE_CODE_NOT_FOUND = COAP_MAKE_RESPONSE_CODE(4, 4), - COAP_RESPONSE_CODE_NOT_ALLOWED = COAP_MAKE_RESPONSE_CODE(4, 5), - COAP_RESPONSE_CODE_NOT_ACCEPTABLE = COAP_MAKE_RESPONSE_CODE(4, 6), - COAP_RESPONSE_CODE_INCOMPLETE = COAP_MAKE_RESPONSE_CODE(4, 8), - COAP_RESPONSE_CODE_CONFLICT = COAP_MAKE_RESPONSE_CODE(4, 9), - COAP_RESPONSE_CODE_PRECONDITION_FAILED = COAP_MAKE_RESPONSE_CODE(4, 12), - COAP_RESPONSE_CODE_REQUEST_TOO_LARGE = COAP_MAKE_RESPONSE_CODE(4, 13), + COAP_RESPONSE_CODE_OK = coap_make_response_code(2, 0), + COAP_RESPONSE_CODE_CREATED = coap_make_response_code(2, 1), + COAP_RESPONSE_CODE_DELETED = coap_make_response_code(2, 2), + COAP_RESPONSE_CODE_VALID = coap_make_response_code(2, 3), + COAP_RESPONSE_CODE_CHANGED = coap_make_response_code(2, 4), + COAP_RESPONSE_CODE_CONTENT = coap_make_response_code(2, 5), + COAP_RESPONSE_CODE_CONTINUE = coap_make_response_code(2, 31), + COAP_RESPONSE_CODE_BAD_REQUEST = coap_make_response_code(4, 0), + COAP_RESPONSE_CODE_UNAUTHORIZED = coap_make_response_code(4, 1), + COAP_RESPONSE_CODE_BAD_OPTION = coap_make_response_code(4, 2), + COAP_RESPONSE_CODE_FORBIDDEN = coap_make_response_code(4, 3), + COAP_RESPONSE_CODE_NOT_FOUND = coap_make_response_code(4, 4), + COAP_RESPONSE_CODE_NOT_ALLOWED = coap_make_response_code(4, 5), + COAP_RESPONSE_CODE_NOT_ACCEPTABLE = coap_make_response_code(4, 6), + COAP_RESPONSE_CODE_INCOMPLETE = coap_make_response_code(4, 8), + COAP_RESPONSE_CODE_CONFLICT = coap_make_response_code(4, 9), + COAP_RESPONSE_CODE_PRECONDITION_FAILED = coap_make_response_code(4, 12), + COAP_RESPONSE_CODE_REQUEST_TOO_LARGE = coap_make_response_code(4, 13), COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT = - COAP_MAKE_RESPONSE_CODE(4, 15), - COAP_RESPONSE_CODE_UNPROCESSABLE_ENTITY = COAP_MAKE_RESPONSE_CODE(4, 22), - COAP_RESPONSE_CODE_TOO_MANY_REQUESTS = COAP_MAKE_RESPONSE_CODE(4, 29), - COAP_RESPONSE_CODE_INTERNAL_ERROR = COAP_MAKE_RESPONSE_CODE(5, 0), - COAP_RESPONSE_CODE_NOT_IMPLEMENTED = COAP_MAKE_RESPONSE_CODE(5, 1), - COAP_RESPONSE_CODE_BAD_GATEWAY = COAP_MAKE_RESPONSE_CODE(5, 2), - COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE = COAP_MAKE_RESPONSE_CODE(5, 3), - COAP_RESPONSE_CODE_GATEWAY_TIMEOUT = COAP_MAKE_RESPONSE_CODE(5, 4), + coap_make_response_code(4, 15), + COAP_RESPONSE_CODE_UNPROCESSABLE_ENTITY = coap_make_response_code(4, 22), + COAP_RESPONSE_CODE_TOO_MANY_REQUESTS = coap_make_response_code(4, 29), + COAP_RESPONSE_CODE_INTERNAL_ERROR = coap_make_response_code(5, 0), + COAP_RESPONSE_CODE_NOT_IMPLEMENTED = coap_make_response_code(5, 1), + COAP_RESPONSE_CODE_BAD_GATEWAY = coap_make_response_code(5, 2), + COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE = coap_make_response_code(5, 3), + COAP_RESPONSE_CODE_GATEWAY_TIMEOUT = coap_make_response_code(5, 4), COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED = - COAP_MAKE_RESPONSE_CODE(5, 5) + coap_make_response_code(5, 5) }; #define COAP_CODE_EMPTY (0) From f7ff592debfc0bf15c98bd6bb8f46ba85e5b3257 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:42 +0000 Subject: [PATCH 0841/1623] Revert "[nrf fromtree] net: lwm2m: RD client Deregister event indicate" This reverts commit a63c627ac67cc7b2849f508113bebbf5db3370de. Signed-off-by: Dominik Ermel --- doc/connectivity/networking/api/lwm2m.rst | 8 -------- doc/releases/release-notes-3.5.rst | 1 - include/zephyr/net/lwm2m.h | 1 - samples/net/lwm2m_client/src/lwm2m-client.c | 3 --- subsys/net/lib/lwm2m/lwm2m_rd_client.c | 2 -- tests/net/lib/lwm2m/interop/src/lwm2m-client.c | 3 --- tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c | 6 ------ 7 files changed, 24 deletions(-) diff --git a/doc/connectivity/networking/api/lwm2m.rst b/doc/connectivity/networking/api/lwm2m.rst index 8d727d48bf5..c630ea7785a 100644 --- a/doc/connectivity/networking/api/lwm2m.rst +++ b/doc/connectivity/networking/api/lwm2m.rst @@ -318,14 +318,6 @@ events, setup a callback function: LOG_DBG("Disconnected"); break; - case LWM2M_RD_CLIENT_EVENT_REG_UPDATE: - LOG_DBG("Registration update"); - break; - - case LWM2M_RD_CLIENT_EVENT_DEREGISTER: - LOG_DBG("Deregistration client"); - break; - } } diff --git a/doc/releases/release-notes-3.5.rst b/doc/releases/release-notes-3.5.rst index 4f9a8ab1793..1c2a38edcf2 100644 --- a/doc/releases/release-notes-3.5.rst +++ b/doc/releases/release-notes-3.5.rst @@ -255,7 +255,6 @@ Networking * Added support for tickless mode. This removes the 500 ms timeout from the socket loop so the engine does not constantly wake up the CPU. This can be enabled by :kconfig:option:`CONFIG_LWM2M_TICKLESS`. - * Added new :c:macro:`LWM2M_RD_CLIENT_EVENT_DEREGISTER` event. * Wi-Fi * Added Passive scan support. diff --git a/include/zephyr/net/lwm2m.h b/include/zephyr/net/lwm2m.h index 6262f6d103d..e94297d3550 100644 --- a/include/zephyr/net/lwm2m.h +++ b/include/zephyr/net/lwm2m.h @@ -2073,7 +2073,6 @@ enum lwm2m_rd_client_event { LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED, LWM2M_RD_CLIENT_EVENT_NETWORK_ERROR, LWM2M_RD_CLIENT_EVENT_REG_UPDATE, - LWM2M_RD_CLIENT_EVENT_DEREGISTER, }; /** diff --git a/samples/net/lwm2m_client/src/lwm2m-client.c b/samples/net/lwm2m_client/src/lwm2m-client.c index 748f654d9ee..e20008c2f66 100644 --- a/samples/net/lwm2m_client/src/lwm2m-client.c +++ b/samples/net/lwm2m_client/src/lwm2m-client.c @@ -231,9 +231,6 @@ static void rd_client_event(struct lwm2m_ctx *client, case LWM2M_RD_CLIENT_EVENT_REG_UPDATE: LOG_DBG("Registration update"); break; - case LWM2M_RD_CLIENT_EVENT_DEREGISTER: - LOG_DBG("Client De-register"); - break; } } diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.c b/subsys/net/lib/lwm2m/lwm2m_rd_client.c index db8a84ce0b8..feebcaeea17 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.c +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.c @@ -215,8 +215,6 @@ static void set_sm_state_delayed(uint8_t sm_state, int64_t delay_ms) } } else if (sm_state == ENGINE_UPDATE_REGISTRATION) { event = LWM2M_RD_CLIENT_EVENT_REG_UPDATE; - } else if (sm_state == ENGINE_DEREGISTER) { - event = LWM2M_RD_CLIENT_EVENT_DEREGISTER; } if (sm_is_suspended()) { diff --git a/tests/net/lib/lwm2m/interop/src/lwm2m-client.c b/tests/net/lib/lwm2m/interop/src/lwm2m-client.c index 983fea79f3e..1278d807b71 100644 --- a/tests/net/lib/lwm2m/interop/src/lwm2m-client.c +++ b/tests/net/lib/lwm2m/interop/src/lwm2m-client.c @@ -117,9 +117,6 @@ static void rd_client_event(struct lwm2m_ctx *client, case LWM2M_RD_CLIENT_EVENT_REG_UPDATE: LOG_DBG("Registration update"); break; - case LWM2M_RD_CLIENT_EVENT_DEREGISTER: - LOG_DBG("Deregistration client"); - break; } } diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c b/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c index 03d0dce7f49..08c0820d5e9 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c @@ -106,9 +106,6 @@ static void lwm2m_event_cb(struct lwm2m_ctx *client, enum lwm2m_rd_client_event case LWM2M_RD_CLIENT_EVENT_REG_UPDATE: LOG_INF("*** LWM2M_RD_CLIENT_EVENT_REG_UPDATE"); break; - case LWM2M_RD_CLIENT_EVENT_DEREGISTER: - LOG_INF("*** LWM2M_RD_CLIENT_EVENT_DEREGISTER"); - break; } show_lwm2m_event(client_event); @@ -214,7 +211,6 @@ ZTEST(lwm2m_rd_client, test_start_registration_ok) coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_deleted; zassert_true(lwm2m_rd_client_stop(&ctx, lwm2m_event_cb, true) == 0, NULL); - zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DEREGISTER), NULL); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DISCONNECT), NULL); zassert_true(!lwm2m_rd_client_is_registred(&ctx), NULL); } @@ -429,7 +425,6 @@ ZTEST(lwm2m_rd_client, test_deregistration_timeout) test_prepare_pending_message_cb(&message_reply_timeout_cb_default); zassert_true(lwm2m_rd_client_stop(&ctx, lwm2m_event_cb, true) == 0, NULL); - zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DEREGISTER), NULL); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DEREGISTER_FAILURE)); } @@ -534,7 +529,6 @@ ZTEST(lwm2m_rd_client, test_suspend_stop_resume) zassert_equal(lwm2m_rd_client_stop(&ctx, lwm2m_event_cb, false), 0); zassert_true(lwm2m_rd_client_resume() == 0, NULL); - zassert_false(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DEREGISTER), NULL); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DISCONNECT), NULL); } From d8fb5f36e428d928e17b6aac158e223a31afb172 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:42 +0000 Subject: [PATCH 0842/1623] Revert "[nrf fromtree] net: coap: Fix coap client timeout" This reverts commit b65d00b7190dbccc6b7998f6ef868c19fc9f982f. Signed-off-by: Dominik Ermel --- subsys/net/lib/coap/coap_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/coap/coap_client.c b/subsys/net/lib/coap/coap_client.c index d096e39c62f..f8ba4283648 100644 --- a/subsys/net/lib/coap/coap_client.c +++ b/subsys/net/lib/coap/coap_client.c @@ -369,7 +369,7 @@ static void report_callback_error(struct coap_client_internal_request *internal_ static bool timeout_expired(struct coap_client_internal_request *internal_req) { return (internal_req->request_ongoing && - internal_req->pending.timeout <= (k_uptime_get() - internal_req->pending.t0)); + internal_req->pending.timeout <= k_uptime_get_32()); } static int resend_request(struct coap_client *client, @@ -649,7 +649,7 @@ static int handle_response(struct coap_client *client, const struct coap_packet /* Separate response coming */ if (payload_len == 0 && response_type == COAP_TYPE_ACK && response_code == COAP_CODE_EMPTY) { - internal_req->pending.t0 = k_uptime_get(); + internal_req->pending.t0 = k_uptime_get_32(); internal_req->pending.timeout = internal_req->pending.t0 + COAP_SEPARATE_TIMEOUT; internal_req->pending.retries = 0; return 1; From cad98d139b71138ce5a03a6e57db1a505f35d8a4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:42 +0000 Subject: [PATCH 0843/1623] Revert "[nrf fromtree] net: lwm2m: Generate new tokens for LwM2M SEND blocks" This reverts commit d96b34effcd3ec9010f7e80a564e5fbd93e4c995. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 678f358d1ee..7aaa42c20ab 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -307,13 +307,12 @@ STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_nu /* reuse message for next block. Copy token from the new query to allow * CoAP clients to use new token for every query of ongoing transaction */ + tkl = coap_header_get_token(msg->in.in_cpkt, token); lwm2m_reset_message(msg, false); if (msg->type == COAP_TYPE_ACK) { msg->mid = coap_header_get_id(msg->in.in_cpkt); - tkl = coap_header_get_token(msg->in.in_cpkt, token); } else { msg->mid = coap_next_id(); - tkl = LWM2M_MSG_TOKEN_GENERATE_NEW; } msg->token = token; msg->tkl = tkl; From a2d4cccf43905b74e1856c2c3a9189901a28e9a2 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:43 +0000 Subject: [PATCH 0844/1623] Revert "[nrf fromtree] net: lwm2m: Append CoAP Etag to protect integrity of blockwise" This reverts commit 821e53edec9e15d97e6248342daed14ebb97b5ee. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/Kconfig | 2 -- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 14 +------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/subsys/net/lib/lwm2m/Kconfig b/subsys/net/lib/lwm2m/Kconfig index d826e5cd599..41ac5bcf1ce 100644 --- a/subsys/net/lib/lwm2m/Kconfig +++ b/subsys/net/lib/lwm2m/Kconfig @@ -83,8 +83,6 @@ config LWM2M_COAP_BLOCK_TRANSFER help LwM2M messages with a big body that exceed the block size will be split into blocks for sending. - To append CoAP ETag option into outgoing block transfers, CONFIG_SYS_HASH_FUNC32 should - be enabled. config LWM2M_CANCEL_OBSERVE_BY_PATH bool "Use path matching as fallback for cancel-observe" diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 7aaa42c20ab..06cc1b5ecf8 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -33,7 +33,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #include #include -#include #if defined(CONFIG_LWM2M_DTLS_SUPPORT) #include @@ -379,7 +378,6 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg) { int ret; uint16_t len; - const uint8_t *payload; /* save the big buffer for later use (splitting blocks) */ msg->body_encode_buffer = msg->cpkt; @@ -389,7 +387,7 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg) msg->cpkt.offset = 0; msg->cpkt.max_len = MAX_PACKET_SIZE; - payload = coap_packet_get_payload(&msg->body_encode_buffer, &len); + coap_packet_get_payload(&msg->body_encode_buffer, &len); if (len <= CONFIG_LWM2M_COAP_MAX_MSG_SIZE) { /* copy the packet */ @@ -408,16 +406,6 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg) NET_ASSERT(msg->out.block_ctx == NULL, "Expecting to have no context to release"); } else { - /* Before splitting the content, append Etag option to protect the integrity of - * the payload. - */ - if (IS_ENABLED(CONFIG_SYS_HASH_FUNC32)) { - uint32_t hash = sys_hash32(payload, len); - - coap_packet_append_option(&msg->body_encode_buffer, COAP_OPTION_ETAG, - (const uint8_t *)&hash, sizeof(hash)); - } - ret = build_msg_block_for_send(msg, 0); if (ret != 0) { return ret; From def02a6d8f068b9c5cc3c4778f1e3fa5f208b26e Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:43 +0000 Subject: [PATCH 0845/1623] Revert "[nrf fromtree] net: lwm2m: Fix composite read on SenML-CBOR" This reverts commit 73a6d196160abe543c52944c07953dafdc338ea6. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 6 ++++++ subsys/net/lib/lwm2m/lwm2m_message_handling.h | 6 +----- subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c | 5 +---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 06cc1b5ecf8..df940cf4adb 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -417,6 +417,12 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg) #endif +bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg) +{ + return msg->block_send; +} + + void lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx) { struct lwm2m_message *msg; diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.h b/subsys/net/lib/lwm2m/lwm2m_message_handling.h index c41fbbac0ee..fd6c4470d84 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.h +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.h @@ -75,10 +75,6 @@ enum coap_block_size lwm2m_default_block_size(void); int lwm2m_parse_peerinfo(char *url, struct lwm2m_ctx *client_ctx, bool is_firmware_uri); void lwm2m_clear_block_contexts(void); - -static inline bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg) -{ - return msg->block_send; -} +bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg); #endif /* LWM2M_MESSAGE_HANDLING_H */ diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c index 15dc9a9451e..d62af88200b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c +++ b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c @@ -836,15 +836,12 @@ static uint8_t parse_composite_read_paths(struct lwm2m_message *msg, uint_fast8_t dret; int len; int ret; - char *payload; - uint16_t in_len; setup_in_fmt_data(msg); fd = engine_get_in_user_data(&msg->in); - payload = (char *)coap_packet_get_payload(msg->in.in_cpkt, &in_len); - dret = cbor_decode_lwm2m_senml(payload, in_len, &fd->dcd, &isize); + dret = cbor_decode_lwm2m_senml(ICTX_BUF_R_REGION(&msg->in), &fd->dcd, &isize); if (dret != ZCBOR_SUCCESS) { __ASSERT_NO_MSG(false); From ff64559f0d0be5073fd2eac5ac68c25a75a804e3 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:44 +0000 Subject: [PATCH 0846/1623] Revert "[nrf fromtree] net: lwm2m: Refactor blockwise SEND to support GET and FETCH" This reverts commit a65e10df9b91edd5198495d3bc13e928c314aa38. Signed-off-by: Dominik Ermel --- include/zephyr/net/coap.h | 14 --- subsys/net/lib/coap/coap.c | 13 --- subsys/net/lib/lwm2m/lwm2m_engine.c | 4 +- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 92 ++----------------- subsys/net/lib/lwm2m/lwm2m_message_handling.h | 1 - subsys/net/lib/lwm2m/lwm2m_object.h | 5 +- 6 files changed, 8 insertions(+), 121 deletions(-) diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index 55776bfc6d8..95bb0b45c65 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -713,20 +713,6 @@ int coap_get_option_int(const struct coap_packet *cpkt, uint16_t code); */ int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint8_t *block_number); -/** - * @brief Get values from CoAP block2 option. - * - * Decode block number and block size from option. Ignore the has_more flag - * as it should always be zero on queries. - * - * @param cpkt Packet to be inspected - * @param block_number Is set to the number of the block - * - * @return Integer value of the block size in case of success - * or negative in case of error. - */ -int coap_get_block2_option(const struct coap_packet *cpkt, uint8_t *block_number); - /** * @brief Retrieves BLOCK{1,2} and SIZE{1,2} from @a cpkt and updates * @a ctx accordingly. diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index e3427844bb5..a5c300bf0e2 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -1303,19 +1303,6 @@ int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint8 return ret; } -int coap_get_block2_option(const struct coap_packet *cpkt, uint8_t *block_number) -{ - int ret = coap_get_option_int(cpkt, COAP_OPTION_BLOCK2); - - if (ret < 0) { - return ret; - } - - *block_number = GET_NUM(ret); - ret = 1 << (GET_BLOCK_SIZE(ret) + 4); - return ret; -} - int insert_option(struct coap_packet *cpkt, uint16_t code, const uint8_t *value, uint16_t len) { uint16_t offset = cpkt->hdr_len; diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 651baa30ff6..d38c081ed34 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -675,9 +675,7 @@ static int socket_send_message(struct lwm2m_ctx *client_ctx) } if (msg->type != COAP_TYPE_CON) { - if (!lwm2m_outgoing_is_part_of_blockwise(msg)) { - lwm2m_reset_message(msg, true); - } + lwm2m_reset_message(msg, true); } return rc; diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index df940cf4adb..4eea849750b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -81,7 +81,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); /* Shared set of in-flight LwM2M messages */ static struct lwm2m_message messages[CONFIG_LWM2M_ENGINE_MAX_MESSAGES]; static struct lwm2m_block_context block1_contexts[NUM_BLOCK1_CONTEXT]; -static struct lwm2m_message *ongoing_block2_tx; #if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER) /* we need 1 more buffer as the payload is encoded in that buffer first even if @@ -100,7 +99,6 @@ sys_slist_t *lwm2m_engine_obj_inst_list(void); static int handle_request(struct coap_packet *request, struct lwm2m_message *msg); #if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER) -STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_num); struct coap_block_context *lwm2m_output_block_context(void); #endif @@ -303,16 +301,10 @@ STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_nu } msg->cpkt.hdr_len = msg->body_encode_buffer.hdr_len; } else { - /* reuse message for next block. Copy token from the new query to allow - * CoAP clients to use new token for every query of ongoing transaction - */ - tkl = coap_header_get_token(msg->in.in_cpkt, token); + /* reuse message for next block */ + tkl = coap_header_get_token(&msg->cpkt, token); lwm2m_reset_message(msg, false); - if (msg->type == COAP_TYPE_ACK) { - msg->mid = coap_header_get_id(msg->in.in_cpkt); - } else { - msg->mid = coap_next_id(); - } + msg->mid = coap_next_id(); msg->token = token; msg->tkl = tkl; ret = lwm2m_init_message(msg); @@ -341,14 +333,10 @@ STATIC int build_msg_block_for_send(struct lwm2m_message *msg, uint16_t block_nu return ret; } ret = coap_block_transfer_init(msg->out.block_ctx, lwm2m_default_block_size(), - complete_payload_len); + msg->body_encode_buffer.offset); if (ret < 0) { return ret; } - if (msg->type == COAP_TYPE_ACK) { - ongoing_block2_tx = msg; - } - msg->block_send = true; } else { /* update block context */ msg->out.block_ctx->current = block_num * block_size_bytes; @@ -414,15 +402,8 @@ STATIC int prepare_msg_for_send(struct lwm2m_message *msg) return 0; } - #endif -bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg) -{ - return msg->block_send; -} - - void lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx) { struct lwm2m_message *msg; @@ -2576,56 +2557,6 @@ static int lwm2m_response_promote_to_con(struct lwm2m_message *msg) return ret; } -static struct lwm2m_message *find_ongoing_block2_tx(void) -{ - /* TODO: I could try to check if there is Request-Tags attached, and then match queries - * for those, but currently popular LwM2M servers don't attach those tags, so in reality - * I have no way of properly matching query with BLOCK2 option to a previous query. - * Therefore we can only support one ongoing BLOCK2 transfer and assume all BLOCK2 requests - * are part of currently ongoing one. - */ - return ongoing_block2_tx; -} - -static void clear_ongoing_block2_tx(void) -{ - if (ongoing_block2_tx) { - LOG_DBG("clear"); - lwm2m_reset_message(ongoing_block2_tx, true); - ongoing_block2_tx = NULL; - } -} - -static void handle_ongoing_block2_tx(struct lwm2m_message *msg, struct coap_packet *cpkt) -{ -#if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER) - int r; - uint8_t block; - - r = coap_get_block2_option(cpkt, &block); - if (r < 0) { - LOG_ERR("Failed to parse BLOCK2"); - return; - } - - msg->in.in_cpkt = cpkt; - - r = build_msg_block_for_send(msg, block); - if (r < 0) { - clear_ongoing_block2_tx(); - LOG_ERR("Unable to build next block of lwm2m message! r=%d", r); - return; - } - - r = lwm2m_send_message_async(msg); - if (r < 0) { - clear_ongoing_block2_tx(); - LOG_ERR("Unable to send next block of lwm2m message!"); - return; - } -#endif -} - void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_len, struct sockaddr *from_addr) { @@ -2634,12 +2565,12 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ struct coap_reply *reply; struct coap_packet response; int r; + uint8_t token[8]; #if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER) bool more_blocks = false; uint8_t block_num; uint8_t last_block_num; #endif - bool has_block2; r = coap_packet_parse(&response, buf, buf_len, NULL, 0); if (r < 0) { @@ -2647,7 +2578,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ return; } - has_block2 = coap_get_option_int(&response, COAP_OPTION_BLOCK2) > 0 ? true : false; + (void)coap_header_get_token(&response, token); pending = coap_pending_received(&response, client_ctx->pendings, ARRAY_SIZE(client_ctx->pendings)); if (pending && coap_header_get_type(&response) == COAP_TYPE_ACK) { @@ -2755,17 +2686,6 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ } if (coap_header_get_type(&response) == COAP_TYPE_CON) { - if (has_block2 && IS_ENABLED(CONFIG_LWM2M_COAP_BLOCK_TRANSFER)) { - msg = find_ongoing_block2_tx(); - if (msg) { - return handle_ongoing_block2_tx(msg, &response); - } - return; - } - - /* Clear out existing Block2 transfers when new requests come */ - clear_ongoing_block2_tx(); - msg = lwm2m_get_message(client_ctx); if (!msg) { LOG_ERR("Unable to get a lwm2m message!"); diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.h b/subsys/net/lib/lwm2m/lwm2m_message_handling.h index fd6c4470d84..a98be3f8dc2 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.h +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.h @@ -75,6 +75,5 @@ enum coap_block_size lwm2m_default_block_size(void); int lwm2m_parse_peerinfo(char *url, struct lwm2m_ctx *client_ctx, bool is_firmware_uri); void lwm2m_clear_block_contexts(void); -bool lwm2m_outgoing_is_part_of_blockwise(struct lwm2m_message *msg); #endif /* LWM2M_MESSAGE_HANDLING_H */ diff --git a/subsys/net/lib/lwm2m/lwm2m_object.h b/subsys/net/lib/lwm2m/lwm2m_object.h index 170a99c023d..05bc818c99c 100644 --- a/subsys/net/lib/lwm2m/lwm2m_object.h +++ b/subsys/net/lib/lwm2m/lwm2m_object.h @@ -521,11 +521,8 @@ struct lwm2m_message { /** Incoming message action */ uint8_t operation; - /** Information whether the message was acknowledged. */ + /* Information whether the message was acknowledged. */ bool acknowledged : 1; - - /** Indicate that this is part of outgoing block transfer. */ - bool block_send : 1; }; /* LWM2M format writer for the various formats supported */ From a90d1d40fe24a115e32dedb0158e06f34e169345 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:44 +0000 Subject: [PATCH 0847/1623] Revert "[nrf fromtree] net: lwm2m: Remove unneeded function pointer parameter" This reverts commit 58210f1e7f681cd8faf5f4a1a0d273bb7d7ec43f. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/lwm2m_engine.c | 2 +- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 14 +++++++++----- subsys/net/lib/lwm2m/lwm2m_message_handling.h | 6 +++++- tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c | 4 ++-- tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index d38c081ed34..91d8c3bd605 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -642,7 +642,7 @@ static int socket_recv_message(struct lwm2m_ctx *client_ctx) } in_buf[len] = 0U; - lwm2m_udp_receive(client_ctx, in_buf, len, &from_addr); + lwm2m_udp_receive(client_ctx, in_buf, len, &from_addr, handle_request); return 0; } diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 4eea849750b..299b0330c0b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -97,7 +97,6 @@ sys_slist_t *lwm2m_engine_obj_list(void); sys_slist_t *lwm2m_engine_obj_inst_list(void); -static int handle_request(struct coap_packet *request, struct lwm2m_message *msg); #if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER) struct coap_block_context *lwm2m_output_block_context(void); #endif @@ -2194,7 +2193,7 @@ static int lwm2m_exec_handler(struct lwm2m_message *msg) return -ENOENT; } -static int handle_request(struct coap_packet *request, struct lwm2m_message *msg) +int handle_request(struct coap_packet *request, struct lwm2m_message *msg) { int r; uint8_t code; @@ -2558,7 +2557,7 @@ static int lwm2m_response_promote_to_con(struct lwm2m_message *msg) } void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_len, - struct sockaddr *from_addr) + struct sockaddr *from_addr, udp_request_handler_cb_t udp_request_handler) { struct lwm2m_message *msg = NULL; struct coap_pending *pending; @@ -2685,7 +2684,12 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ return; } - if (coap_header_get_type(&response) == COAP_TYPE_CON) { + /* + * If no normal response handler is found, then this is + * a new request coming from the server. Let's look + * at registered objects to find a handler. + */ + if (udp_request_handler && coap_header_get_type(&response) == COAP_TYPE_CON) { msg = lwm2m_get_message(client_ctx); if (!msg) { LOG_ERR("Unable to get a lwm2m message!"); @@ -2703,7 +2707,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ lwm2m_registry_lock(); /* process the response to this request */ - r = handle_request(&response, msg); + r = udp_request_handler(&response, msg); lwm2m_registry_unlock(); if (r < 0) { return; diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.h b/subsys/net/lib/lwm2m/lwm2m_message_handling.h index a98be3f8dc2..12ba9e762fd 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.h +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.h @@ -39,6 +39,8 @@ #define NUM_OUTPUT_BLOCK_CONTEXT CONFIG_LWM2M_NUM_OUTPUT_BLOCK_CONTEXT #endif +/* Establish a request handler callback type */ +typedef int (*udp_request_handler_cb_t)(struct coap_packet *request, struct lwm2m_message *msg); /* LwM2M message functions */ struct lwm2m_message *lwm2m_get_message(struct lwm2m_ctx *client_ctx); struct lwm2m_message *find_msg(struct coap_pending *pending, struct coap_reply *reply); @@ -47,8 +49,10 @@ void lm2m_message_clear_allocations(struct lwm2m_message *msg); int lwm2m_init_message(struct lwm2m_message *msg); int lwm2m_send_message_async(struct lwm2m_message *msg); +int handle_request(struct coap_packet *request, struct lwm2m_message *msg); + void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_len, - struct sockaddr *from_addr); + struct sockaddr *from_addr, udp_request_handler_cb_t udp_request_handler); int generate_notify_message(struct lwm2m_ctx *ctx, struct observe_node *obs, void *user_data); /* Notification and Send operation */ diff --git a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c index 5db155f1e29..93f5cce1012 100644 --- a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c +++ b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c @@ -24,8 +24,8 @@ DEFINE_FAKE_VALUE_FUNC(int, generate_notify_message, struct lwm2m_ctx *, struct DEFINE_FAKE_VALUE_FUNC(int64_t, engine_observe_shedule_next_event, struct observe_node *, uint16_t, const int64_t); DEFINE_FAKE_VALUE_FUNC(int, handle_request, struct coap_packet *, struct lwm2m_message *); -DEFINE_FAKE_VOID_FUNC(lwm2m_udp_receive, struct lwm2m_ctx *, uint8_t *, uint16_t, - struct sockaddr *); +DEFINE_FAKE_VOID_FUNC(lwm2m_udp_receive, struct lwm2m_ctx *, uint8_t *, uint16_t, struct sockaddr *, + udp_request_handler_cb_t); DEFINE_FAKE_VALUE_FUNC(bool, lwm2m_rd_client_is_registred, struct lwm2m_ctx *); DEFINE_FAKE_VOID_FUNC(lwm2m_engine_context_close, struct lwm2m_ctx *); DEFINE_FAKE_VALUE_FUNC(int, lwm2m_get_res_buf, const struct lwm2m_obj_path *, void **, uint16_t *, diff --git a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h index 7b8ca481f85..088d72d4623 100644 --- a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h +++ b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h @@ -39,7 +39,7 @@ DECLARE_FAKE_VALUE_FUNC(int64_t, engine_observe_shedule_next_event, struct obser const int64_t); DECLARE_FAKE_VALUE_FUNC(int, handle_request, struct coap_packet *, struct lwm2m_message *); DECLARE_FAKE_VOID_FUNC(lwm2m_udp_receive, struct lwm2m_ctx *, uint8_t *, uint16_t, - struct sockaddr *); + struct sockaddr *, udp_request_handler_cb_t); DECLARE_FAKE_VALUE_FUNC(bool, lwm2m_rd_client_is_registred, struct lwm2m_ctx *); DECLARE_FAKE_VOID_FUNC(lwm2m_engine_context_close, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_get_res_buf, const struct lwm2m_obj_path *, void **, uint16_t *, From 9c7ad158f5f35f47868bb2feaab61f4345f35cee Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:45 +0000 Subject: [PATCH 0848/1623] Revert "[nrf fromtree] net: lwm2m: Only parse block1 option for WRITE operation" This reverts commit 142c5e169eaff5e0ef611f95556e5bc8b3ee2d9b. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 398 ++++++++---------- 1 file changed, 185 insertions(+), 213 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 299b0330c0b..8b18f918752 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -1926,179 +1926,50 @@ static int do_discover_op(struct lwm2m_message *msg, uint16_t content_format) static int do_write_op(struct lwm2m_message *msg, uint16_t format) { - int r; - switch (format) { case LWM2M_FORMAT_APP_OCTET_STREAM: - r = do_write_op_opaque(msg); - break; + return do_write_op_opaque(msg); case LWM2M_FORMAT_PLAIN_TEXT: case LWM2M_FORMAT_OMA_PLAIN_TEXT: - r = do_write_op_plain_text(msg); - break; + return do_write_op_plain_text(msg); #ifdef CONFIG_LWM2M_RW_OMA_TLV_SUPPORT case LWM2M_FORMAT_OMA_TLV: case LWM2M_FORMAT_OMA_OLD_TLV: - r = do_write_op_tlv(msg); - break; + return do_write_op_tlv(msg); #endif #ifdef CONFIG_LWM2M_RW_JSON_SUPPORT case LWM2M_FORMAT_OMA_JSON: case LWM2M_FORMAT_OMA_OLD_JSON: - r = do_write_op_json(msg); - break; + return do_write_op_json(msg); #endif #if defined(CONFIG_LWM2M_RW_SENML_JSON_SUPPORT) case LWM2M_FORMAT_APP_SEML_JSON: - r = do_write_op_senml_json(msg); - break; + return do_write_op_senml_json(msg); #endif #ifdef CONFIG_LWM2M_RW_CBOR_SUPPORT case LWM2M_FORMAT_APP_CBOR: - r = do_write_op_cbor(msg); - break; + return do_write_op_cbor(msg); #endif #ifdef CONFIG_LWM2M_RW_SENML_CBOR_SUPPORT case LWM2M_FORMAT_APP_SENML_CBOR: - r = do_write_op_senml_cbor(msg); - break; + return do_write_op_senml_cbor(msg); #endif default: LOG_ERR("Unsupported format: %u", format); - r = -ENOMSG; - break; - } - - return r; -} - -static int parse_write_op(struct lwm2m_message *msg, uint16_t format) -{ - int block_opt, block_num; - struct lwm2m_block_context *block_ctx = NULL; - enum coap_block_size block_size; - bool last_block = false; - int r; - uint16_t payload_len = 0U; - const uint8_t *payload_start; - - /* setup incoming data */ - payload_start = coap_packet_get_payload(msg->in.in_cpkt, &payload_len); - if (payload_len > 0) { - msg->in.offset = payload_start - msg->in.in_cpkt->data; - } else { - msg->in.offset = msg->in.in_cpkt->offset; - } - - /* Check for block transfer */ - block_opt = coap_get_option_int(msg->in.in_cpkt, COAP_OPTION_BLOCK1); - if (block_opt > 0) { - last_block = !GET_MORE(block_opt); - - /* RFC7252: 4.6. Message Size */ - block_size = GET_BLOCK_SIZE(block_opt); - if (!last_block && coap_block_size_to_bytes(block_size) > payload_len) { - LOG_DBG("Trailing payload is discarded!"); - return -EFBIG; - } - - block_num = GET_BLOCK_NUM(block_opt); - - /* Try to retrieve existing block context. If one not exists, - * and we've received first block, allocate new context. - */ - r = get_block_ctx(&msg->path, &block_ctx); - if (r < 0 && block_num == 0) { - r = init_block_ctx(&msg->path, &block_ctx); - } - - if (r < 0) { - LOG_ERR("Cannot find block context"); - return r; - } - - msg->in.block_ctx = block_ctx; - - if (block_num < block_ctx->expected) { - LOG_WRN("Block already handled %d, expected %d", block_num, - block_ctx->expected); - return 0; - } - if (block_num > block_ctx->expected) { - LOG_WRN("Block out of order %d, expected %d", block_num, - block_ctx->expected); - r = -EFAULT; - return r; - } - r = coap_update_from_block(msg->in.in_cpkt, &block_ctx->ctx); - if (r < 0) { - LOG_ERR("Error from block update: %d", r); - return r; - } - - block_ctx->last_block = last_block; - - /* Initial block sent by the server might be larger than - * our block size therefore it is needed to take this - * into account when calculating next expected block - * number. - */ - block_ctx->expected += GET_BLOCK_SIZE(block_opt) - block_ctx->ctx.block_size + 1; - - /* Handle blockwise 1 (Part 1): Set response code */ - if (!last_block) { - msg->code = COAP_RESPONSE_CODE_CONTINUE; - } - } - - r = do_write_op(msg, format); - - /* Handle blockwise 1 (Part 2): Append BLOCK1 option / free context */ - if (block_ctx) { - if (r >= 0 && !last_block) { - /* More to come, ack with correspond block # */ - r = coap_append_block1_option(msg->out.out_cpkt, &block_ctx->ctx); - if (r < 0) { - /* report as internal server error */ - LOG_ERR("Fail adding block1 option: %d", r); - r = -EINVAL; - } - } - if (r < 0 || last_block) { - /* Free context when finished or when there is error */ - free_block_ctx(block_ctx); - - } + return -ENOMSG; } - - return r; } static int do_composite_write_op(struct lwm2m_message *msg, uint16_t format) { - uint16_t payload_len = 0U; - const uint8_t *payload_start; - - /* setup incoming data */ - payload_start = coap_packet_get_payload(msg->in.in_cpkt, &payload_len); - if (payload_len > 0) { - msg->in.offset = payload_start - msg->in.in_cpkt->data; - } else { - msg->in.offset = msg->in.in_cpkt->offset; - } - - if (coap_get_option_int(msg->in.in_cpkt, COAP_OPTION_BLOCK1) >= 0) { - return -ENOTSUP; - } - switch (format) { #if defined(CONFIG_LWM2M_RW_SENML_JSON_SUPPORT) case LWM2M_FORMAT_APP_SEML_JSON: @@ -2203,6 +2074,13 @@ int handle_request(struct coap_packet *request, struct lwm2m_message *msg) uint8_t tkl = 0U; uint16_t format = LWM2M_FORMAT_NONE, accept; int observe = -1; /* default to -1, 0 = ENABLE, 1 = DISABLE */ + int block_opt, block_num; + struct lwm2m_block_context *block_ctx = NULL; + enum coap_block_size block_size; + uint16_t payload_len = 0U; + bool last_block = false; + bool ignore = false; + const uint8_t *payload_start; /* set CoAP request / message */ msg->in.in_cpkt = request; @@ -2374,111 +2252,202 @@ int handle_request(struct coap_packet *request, struct lwm2m_message *msg) break; } + /* setup incoming data */ + payload_start = coap_packet_get_payload(msg->in.in_cpkt, &payload_len); + if (payload_len > 0) { + msg->in.offset = payload_start - msg->in.in_cpkt->data; + } else { + msg->in.offset = msg->in.in_cpkt->offset; + } + + /* Check for block transfer */ + + block_opt = coap_get_option_int(msg->in.in_cpkt, COAP_OPTION_BLOCK1); + if (block_opt > 0) { + last_block = !GET_MORE(block_opt); + + /* RFC7252: 4.6. Message Size */ + block_size = GET_BLOCK_SIZE(block_opt); + if (!last_block && coap_block_size_to_bytes(block_size) > payload_len) { + LOG_DBG("Trailing payload is discarded!"); + r = -EFBIG; + goto error; + } + + block_num = GET_BLOCK_NUM(block_opt); + + /* Try to retrieve existing block context. If one not exists, + * and we've received first block, allocate new context. + */ + r = get_block_ctx(&msg->path, &block_ctx); + if (r < 0 && block_num == 0) { + r = init_block_ctx(&msg->path, &block_ctx); + } + + if (r < 0) { + LOG_ERR("Cannot find block context"); + goto error; + } + + msg->in.block_ctx = block_ctx; + + if (block_num < block_ctx->expected) { + LOG_WRN("Block already handled %d, expected %d", block_num, + block_ctx->expected); + ignore = true; + } else if (block_num > block_ctx->expected) { + LOG_WRN("Block out of order %d, expected %d", block_num, + block_ctx->expected); + r = -EFAULT; + goto error; + } else { + r = coap_update_from_block(msg->in.in_cpkt, &block_ctx->ctx); + if (r < 0) { + LOG_ERR("Error from block update: %d", r); + goto error; + } + + block_ctx->last_block = last_block; + + /* Initial block sent by the server might be larger than + * our block size therefore it is needed to take this + * into account when calculating next expected block + * number. + */ + block_ctx->expected += + GET_BLOCK_SIZE(block_opt) - block_ctx->ctx.block_size + 1; + } + + /* Handle blockwise 1 (Part 1): Set response code */ + if (!last_block) { + msg->code = COAP_RESPONSE_CODE_CONTINUE; + } + } + /* render CoAP packet header */ r = lwm2m_init_message(msg); if (r < 0) { goto error; } + if (!ignore) { #if defined(CONFIG_LWM2M_ACCESS_CONTROL_ENABLE) - r = access_control_check_access(msg->path.obj_id, msg->path.obj_inst_id, - msg->ctx->srv_obj_inst, msg->operation, - msg->ctx->bootstrap_mode); - if (r < 0) { - LOG_ERR("Access denied - Server obj %u does not have proper access to " - "resource", - msg->ctx->srv_obj_inst); - goto error; - } + r = access_control_check_access(msg->path.obj_id, msg->path.obj_inst_id, + msg->ctx->srv_obj_inst, msg->operation, + msg->ctx->bootstrap_mode); + if (r < 0) { + LOG_ERR("Access denied - Server obj %u does not have proper access to " + "resource", + msg->ctx->srv_obj_inst); + goto error; + } #endif - if (msg->path.obj_id == LWM2M_OBJECT_SECURITY_ID && !msg->ctx->bootstrap_mode) { - r = -EACCES; - goto error; - } - - switch (msg->operation) { + if (msg->path.obj_id == LWM2M_OBJECT_SECURITY_ID && !msg->ctx->bootstrap_mode) { + r = -EACCES; + goto error; + } - case LWM2M_OP_READ: - if (observe >= 0) { - /* Validate That Token is valid for Observation */ - if (!msg->token) { - LOG_ERR("OBSERVE request missing token"); - r = -EINVAL; - goto error; - } + switch (msg->operation) { - if ((code & COAP_REQUEST_MASK) == COAP_METHOD_GET) { - /* Normal Observation Request or Cancel */ - r = lwm2m_engine_observation_handler(msg, observe, accept, - false); - if (r < 0) { + case LWM2M_OP_READ: + if (observe >= 0) { + /* Validate That Token is valid for Observation */ + if (!msg->token) { + LOG_ERR("OBSERVE request missing token"); + r = -EINVAL; goto error; } - r = do_read_op(msg, accept); - } else { - /* Composite Observation request & cancel handler */ - r = lwm2m_engine_observation_handler(msg, observe, accept, - true); - if (r < 0) { - goto error; + if ((code & COAP_REQUEST_MASK) == COAP_METHOD_GET) { + /* Normal Observation Request or Cancel */ + r = lwm2m_engine_observation_handler(msg, observe, accept, + false); + if (r < 0) { + goto error; + } + + r = do_read_op(msg, accept); + } else { + /* Composite Observation request & cancel handler */ + r = lwm2m_engine_observation_handler(msg, observe, accept, + true); + if (r < 0) { + goto error; + } } - } - } else { - if ((code & COAP_REQUEST_MASK) == COAP_METHOD_GET) { - r = do_read_op(msg, accept); } else { - r = do_composite_read_op(msg, accept); + if ((code & COAP_REQUEST_MASK) == COAP_METHOD_GET) { + r = do_read_op(msg, accept); + } else { + r = do_composite_read_op(msg, accept); + } } - } - break; + break; - case LWM2M_OP_DISCOVER: - r = do_discover_op(msg, accept); - break; + case LWM2M_OP_DISCOVER: + r = do_discover_op(msg, accept); + break; - case LWM2M_OP_WRITE: - case LWM2M_OP_CREATE: - if ((code & COAP_REQUEST_MASK) == COAP_METHOD_IPATCH) { - /* iPATCH is for Composite purpose */ - r = do_composite_write_op(msg, format); - } else { - /* Single resource write Operation */ - r = parse_write_op(msg, format); - } + case LWM2M_OP_WRITE: + case LWM2M_OP_CREATE: + if ((code & COAP_REQUEST_MASK) == COAP_METHOD_IPATCH) { + /* iPATCH is for Composite purpose */ + r = do_composite_write_op(msg, format); + } else { + /* Single resource write Operation */ + r = do_write_op(msg, format); + } #if defined(CONFIG_LWM2M_ACCESS_CONTROL_ENABLE) - if (msg->operation == LWM2M_OP_CREATE && r >= 0) { - access_control_add(msg->path.obj_id, msg->path.obj_inst_id, - msg->ctx->srv_obj_inst); - } + if (msg->operation == LWM2M_OP_CREATE && r >= 0) { + access_control_add(msg->path.obj_id, msg->path.obj_inst_id, + msg->ctx->srv_obj_inst); + } #endif - break; + break; - case LWM2M_OP_WRITE_ATTR: - r = lwm2m_write_attr_handler(obj, msg); - break; + case LWM2M_OP_WRITE_ATTR: + r = lwm2m_write_attr_handler(obj, msg); + break; - case LWM2M_OP_EXECUTE: - r = lwm2m_exec_handler(msg); - break; + case LWM2M_OP_EXECUTE: + r = lwm2m_exec_handler(msg); + break; - case LWM2M_OP_DELETE: + case LWM2M_OP_DELETE: #if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) - if (msg->ctx->bootstrap_mode) { - r = bootstrap_delete(msg); + if (msg->ctx->bootstrap_mode) { + r = bootstrap_delete(msg); + break; + } +#endif + r = lwm2m_delete_handler(msg); break; + + default: + LOG_ERR("Unknown operation: %u", msg->operation); + r = -EINVAL; } -#endif - r = lwm2m_delete_handler(msg); - break; - default: - LOG_ERR("Unknown operation: %u", msg->operation); - r = -EINVAL; + if (r < 0) { + goto error; + } } - if (r < 0) { - goto error; + /* Handle blockwise 1 (Part 2): Append BLOCK1 option / free context */ + if (block_ctx) { + if (!last_block) { + /* More to come, ack with correspond block # */ + r = coap_append_block1_option(msg->out.out_cpkt, &block_ctx->ctx); + if (r < 0) { + /* report as internal server error */ + LOG_ERR("Fail adding block1 option: %d", r); + r = -EINVAL; + goto error; + } + } else { + /* Free context when finished */ + free_block_ctx(block_ctx); + } } return 0; @@ -2513,6 +2482,9 @@ int handle_request(struct coap_packet *request, struct lwm2m_message *msg) LOG_ERR("Error recreating message: %d", r); } + /* Free block context when error happened */ + free_block_ctx(block_ctx); + return 0; } From f1ed3e0c1b1c3381998b228c0504cad0dc29c862 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:45 +0000 Subject: [PATCH 0849/1623] Revert "[nrf fromtree] net: lwm2m: Separate opaque content format into its own" This reverts commit 6f6fd46e43ba5b13d47f4940d82652bfe91a4fee. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/CMakeLists.txt | 1 - subsys/net/lib/lwm2m/lwm2m_message_handling.c | 12 -- subsys/net/lib/lwm2m/lwm2m_rw_opaque.c | 165 ------------------ subsys/net/lib/lwm2m/lwm2m_rw_opaque.h | 18 -- subsys/net/lib/lwm2m/lwm2m_rw_plain_text.c | 44 +++++ .../lib/lwm2m/content_plain_text/src/main.c | 31 ++++ 6 files changed, 75 insertions(+), 196 deletions(-) delete mode 100644 subsys/net/lib/lwm2m/lwm2m_rw_opaque.c delete mode 100644 subsys/net/lib/lwm2m/lwm2m_rw_opaque.h diff --git a/subsys/net/lib/lwm2m/CMakeLists.txt b/subsys/net/lib/lwm2m/CMakeLists.txt index 2e895ec381b..5cb0ab158d5 100644 --- a/subsys/net/lib/lwm2m/CMakeLists.txt +++ b/subsys/net/lib/lwm2m/CMakeLists.txt @@ -14,7 +14,6 @@ zephyr_library_sources( lwm2m_obj_device.c lwm2m_rw_link_format.c lwm2m_rw_plain_text.c - lwm2m_rw_opaque.c lwm2m_util.c lwm2m_rd_client.c ) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 8b18f918752..1a7d023ceb2 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -47,7 +47,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "lwm2m_rw_link_format.h" #include "lwm2m_rw_oma_tlv.h" #include "lwm2m_rw_plain_text.h" -#include "lwm2m_rw_opaque.h" #include "lwm2m_util.h" #include "lwm2m_rd_client.h" #if defined(CONFIG_LWM2M_RW_SENML_JSON_SUPPORT) @@ -808,10 +807,6 @@ static int select_writer(struct lwm2m_output_context *out, uint16_t accept) out->writer = &link_format_writer; break; - case LWM2M_FORMAT_APP_OCTET_STREAM: - out->writer = &opaque_writer; - break; - case LWM2M_FORMAT_PLAIN_TEXT: case LWM2M_FORMAT_OMA_PLAIN_TEXT: out->writer = &plain_text_writer; @@ -862,9 +857,6 @@ static int select_reader(struct lwm2m_input_context *in, uint16_t format) switch (format) { case LWM2M_FORMAT_APP_OCTET_STREAM: - in->reader = &opaque_reader; - break; - case LWM2M_FORMAT_PLAIN_TEXT: case LWM2M_FORMAT_OMA_PLAIN_TEXT: in->reader = &plain_text_reader; @@ -1545,8 +1537,6 @@ static int do_read_op(struct lwm2m_message *msg, uint16_t content_format) switch (content_format) { case LWM2M_FORMAT_APP_OCTET_STREAM: - return do_read_op_opaque(msg, content_format); - case LWM2M_FORMAT_PLAIN_TEXT: case LWM2M_FORMAT_OMA_PLAIN_TEXT: return do_read_op_plain_text(msg, content_format); @@ -1929,8 +1919,6 @@ static int do_write_op(struct lwm2m_message *msg, uint16_t format) switch (format) { case LWM2M_FORMAT_APP_OCTET_STREAM: - return do_write_op_opaque(msg); - case LWM2M_FORMAT_PLAIN_TEXT: case LWM2M_FORMAT_OMA_PLAIN_TEXT: return do_write_op_plain_text(msg); diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_opaque.c b/subsys/net/lib/lwm2m/lwm2m_rw_opaque.c deleted file mode 100644 index 90cb4619d9a..00000000000 --- a/subsys/net/lib/lwm2m/lwm2m_rw_opaque.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * Copyright (c) 2015, Yanzi Networks AB. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define LOG_MODULE_NAME net_lwm2m_opaque -#define LOG_LEVEL CONFIG_LWM2M_LOG_LEVEL - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME); - -#include -#include -#include -#include -#include - -#include "lwm2m_object.h" -#include "lwm2m_rw_opaque.h" -#include "lwm2m_engine.h" -#include "lwm2m_util.h" - -static int get_opaque(struct lwm2m_input_context *in, uint8_t *value, - size_t buflen, struct lwm2m_opaque_context *opaque, - bool *last_block) -{ - uint16_t in_len; - - if (opaque->remaining == 0) { - coap_packet_get_payload(in->in_cpkt, &in_len); - - if (in_len == 0) { - return -ENODATA; - } - - if (in->block_ctx != NULL) { - uint32_t block_num = - in->block_ctx->ctx.current / - coap_block_size_to_bytes( - in->block_ctx->ctx.block_size); - - if (block_num == 0) { - opaque->len = in->block_ctx->ctx.total_size; - } - - if (opaque->len == 0) { - /* No size1 option provided, use current - * payload size. This will reset on next packet - * received. - */ - opaque->remaining = in_len; - } else { - opaque->remaining = opaque->len; - } - - } else { - opaque->len = in_len; - opaque->remaining = in_len; - } - } - - return lwm2m_engine_get_opaque_more(in, value, buflen, - opaque, last_block); -} - -static int put_opaque(struct lwm2m_output_context *out, - struct lwm2m_obj_path *path, char *buf, - size_t buflen) -{ - int ret; - - ret = buf_append(CPKT_BUF_WRITE(out->out_cpkt), buf, buflen); - if (ret < 0) { - return ret; - } - - return buflen; -} - - -const struct lwm2m_writer opaque_writer = { - .put_opaque = put_opaque, -}; - -const struct lwm2m_reader opaque_reader = { - .get_opaque = get_opaque, -}; - -int do_read_op_opaque(struct lwm2m_message *msg, int content_format) -{ - /* Opaque can only return single resource (instance) */ - if (msg->path.level < LWM2M_PATH_LEVEL_RESOURCE) { - return -EPERM; - } else if (msg->path.level > LWM2M_PATH_LEVEL_RESOURCE) { - if (!IS_ENABLED(CONFIG_LWM2M_VERSION_1_1)) { - return -ENOENT; - } else if (msg->path.level > LWM2M_PATH_LEVEL_RESOURCE_INST) { - return -ENOENT; - } - } - - return lwm2m_perform_read_op(msg, content_format); -} - -int do_write_op_opaque(struct lwm2m_message *msg) -{ - struct lwm2m_engine_obj_inst *obj_inst = NULL; - struct lwm2m_engine_obj_field *obj_field; - struct lwm2m_engine_res *res = NULL; - struct lwm2m_engine_res_inst *res_inst = NULL; - int ret; - uint8_t created = 0U; - - ret = lwm2m_get_or_create_engine_obj(msg, &obj_inst, &created); - if (ret < 0) { - return ret; - } - - ret = lwm2m_engine_validate_write_access(msg, obj_inst, &obj_field); - if (ret < 0) { - return ret; - } - - ret = lwm2m_engine_get_create_res_inst(&msg->path, &res, &res_inst); - if (ret < 0) { - return -ENOENT; - } - - if (msg->path.level < LWM2M_PATH_LEVEL_RESOURCE) { - msg->path.level = LWM2M_PATH_LEVEL_RESOURCE; - } - - return lwm2m_write_handler(obj_inst, res, res_inst, obj_field, msg); -} diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_opaque.h b/subsys/net/lib/lwm2m/lwm2m_rw_opaque.h deleted file mode 100644 index 4118049efe8..00000000000 --- a/subsys/net/lib/lwm2m/lwm2m_rw_opaque.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef LWM2M_RW_OPAQUE_H_ -#define LWM2M_RW_OPAQUE_H_ - -#include "lwm2m_object.h" - -extern const struct lwm2m_writer opaque_writer; -extern const struct lwm2m_reader opaque_reader; - -int do_read_op_opaque(struct lwm2m_message *msg, int content_format); -int do_write_op_opaque(struct lwm2m_message *msg); - -#endif /* LWM2M_RW_OPAQUE_H_ */ diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_plain_text.c b/subsys/net/lib/lwm2m/lwm2m_rw_plain_text.c index 3ec69e8db82..9650b33fc29 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rw_plain_text.c +++ b/subsys/net/lib/lwm2m/lwm2m_rw_plain_text.c @@ -341,6 +341,49 @@ static int get_bool(struct lwm2m_input_context *in, bool *value) return sizeof(uint8_t); } +static int get_opaque(struct lwm2m_input_context *in, uint8_t *value, + size_t buflen, struct lwm2m_opaque_context *opaque, + bool *last_block) +{ + uint16_t in_len; + + if (opaque->remaining == 0) { + coap_packet_get_payload(in->in_cpkt, &in_len); + + if (in_len == 0) { + return -ENODATA; + } + + if (in->block_ctx != NULL) { + uint32_t block_num = + in->block_ctx->ctx.current / + coap_block_size_to_bytes( + in->block_ctx->ctx.block_size); + + if (block_num == 0) { + opaque->len = in->block_ctx->ctx.total_size; + } + + if (opaque->len == 0) { + /* No size1 option provided, use current + * payload size. This will reset on next packet + * received. + */ + opaque->remaining = in_len; + } else { + opaque->remaining = opaque->len; + } + + } else { + opaque->len = in_len; + opaque->remaining = in_len; + } + } + + return lwm2m_engine_get_opaque_more(in, value, buflen, + opaque, last_block); +} + static int get_objlnk(struct lwm2m_input_context *in, struct lwm2m_objlnk *value) { @@ -389,6 +432,7 @@ const struct lwm2m_reader plain_text_reader = { .get_time = get_time, .get_float = get_float, .get_bool = get_bool, + .get_opaque = get_opaque, .get_objlnk = get_objlnk, }; diff --git a/tests/net/lib/lwm2m/content_plain_text/src/main.c b/tests/net/lib/lwm2m/content_plain_text/src/main.c index 7bc77a82327..c7cc857224c 100644 --- a/tests/net/lib/lwm2m/content_plain_text/src/main.c +++ b/tests/net/lib/lwm2m/content_plain_text/src/main.c @@ -470,6 +470,37 @@ ZTEST(net_content_plain_text_nodata, test_get_bool_nodata) zassert_equal(ret, -ENODATA, "Invalid error code returned"); } +ZTEST(net_content_plain_text, test_get_opaque) +{ + int ret; + const char *payload = "test_payload"; + uint8_t buf[16]; + bool last_block; + struct lwm2m_opaque_context ctx = { 0 }; + + test_payload_set(payload); + + ret = plain_text_reader.get_opaque(&test_in, buf, sizeof(buf), + &ctx, &last_block); + zassert_equal(ret, strlen(payload), "Invalid length returned"); + zassert_mem_equal(buf, payload, strlen(payload), + "Invalid value parsed"); + zassert_equal(test_in.offset, strlen(payload) + 1, + "Invalid packet offset"); +} + +ZTEST(net_content_plain_text_nodata, test_get_opaque_nodata) +{ + int ret; + uint8_t value[4]; + bool last_block; + struct lwm2m_opaque_context ctx = { 0 }; + + ret = plain_text_reader.get_opaque(&test_in, value, sizeof(value), + &ctx, &last_block); + zassert_equal(ret, 0, "Invalid error code returned"); +} + ZTEST(net_content_plain_text, test_get_objlnk) { int ret; From ca4a35bb8ff8cfe02a55c070ce9e7c856a79ad70 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:45 +0000 Subject: [PATCH 0850/1623] Revert "[nrf fromtree] net: lwm2m: Allow content formats to support only some data types" This reverts commit 5f6827522ce81d9091dcd0bf43d48e2e45ee1150. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/lwm2m_object.h | 143 ++++++++++------------------ 1 file changed, 52 insertions(+), 91 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_object.h b/subsys/net/lib/lwm2m/lwm2m_object.h index 05bc818c99c..ca8fdf12fd0 100644 --- a/subsys/net/lib/lwm2m/lwm2m_object.h +++ b/subsys/net/lib/lwm2m/lwm2m_object.h @@ -705,95 +705,71 @@ static inline int engine_put_end_ri(struct lwm2m_output_context *out, return 0; } -static inline int engine_put_s8(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, - int8_t value) +static inline int engine_put_s8(struct lwm2m_output_context *out, + struct lwm2m_obj_path *path, int8_t value) { - if (out->writer->put_s8) { - return out->writer->put_s8(out, path, value); - } - return -ENOTSUP; + return out->writer->put_s8(out, path, value); } -static inline int engine_put_s16(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, - int16_t value) +static inline int engine_put_s16(struct lwm2m_output_context *out, + struct lwm2m_obj_path *path, int16_t value) { - if (out->writer->put_s16) { - return out->writer->put_s16(out, path, value); - } - return -ENOTSUP; + return out->writer->put_s16(out, path, value); } -static inline int engine_put_s32(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, - int32_t value) +static inline int engine_put_s32(struct lwm2m_output_context *out, + struct lwm2m_obj_path *path, int32_t value) { - if (out->writer->put_s32) { - return out->writer->put_s32(out, path, value); - } - return -ENOTSUP; + return out->writer->put_s32(out, path, value); } -static inline int engine_put_s64(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, - int64_t value) +static inline int engine_put_s64(struct lwm2m_output_context *out, + struct lwm2m_obj_path *path, int64_t value) { - if (out->writer->put_s64) { - return out->writer->put_s64(out, path, value); - } - return -ENOTSUP; + return out->writer->put_s64(out, path, value); } -static inline int engine_put_string(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, - char *buf, size_t buflen) +static inline int engine_put_string(struct lwm2m_output_context *out, + struct lwm2m_obj_path *path, char *buf, + size_t buflen) { - if (out->writer->put_string) { - return out->writer->put_string(out, path, buf, buflen); - } - return -ENOTSUP; + return out->writer->put_string(out, path, buf, buflen); } -static inline int engine_put_float(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, - double *value) +static inline int engine_put_float(struct lwm2m_output_context *out, + struct lwm2m_obj_path *path, double *value) { - if (out->writer->put_float) { - return out->writer->put_float(out, path, value); - } - return -ENOTSUP; + return out->writer->put_float(out, path, value); } -static inline int engine_put_time(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, - time_t value) +static inline int engine_put_time(struct lwm2m_output_context *out, + struct lwm2m_obj_path *path, time_t value) { - if (out->writer->put_time) { - return out->writer->put_time(out, path, value); - } - return -ENOTSUP; + return out->writer->put_time(out, path, value); } -static inline int engine_put_bool(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, - bool value) +static inline int engine_put_bool(struct lwm2m_output_context *out, + struct lwm2m_obj_path *path, bool value) { - if (out->writer->put_bool) { - return out->writer->put_bool(out, path, value); - } - return -ENOTSUP; + return out->writer->put_bool(out, path, value); } -static inline int engine_put_opaque(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, - char *buf, size_t buflen) +static inline int engine_put_opaque(struct lwm2m_output_context *out, + struct lwm2m_obj_path *path, char *buf, + size_t buflen) { if (out->writer->put_opaque) { return out->writer->put_opaque(out, path, buf, buflen); } - return -ENOTSUP; + return 0; } -static inline int engine_put_objlnk(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, +static inline int engine_put_objlnk(struct lwm2m_output_context *out, + struct lwm2m_obj_path *path, struct lwm2m_objlnk *value) { - if (out->writer->put_objlnk) { - return out->writer->put_objlnk(out, path, value); - } - return -ENOTSUP; + return out->writer->put_objlnk(out, path, value); } static inline int engine_put_corelink(struct lwm2m_output_context *out, @@ -817,68 +793,53 @@ static inline int engine_put_timestamp(struct lwm2m_output_context *out, time_t static inline int engine_get_s32(struct lwm2m_input_context *in, int32_t *value) { - if (in->reader->get_s32) { - return in->reader->get_s32(in, value); - } - return -ENOTSUP; + return in->reader->get_s32(in, value); } static inline int engine_get_s64(struct lwm2m_input_context *in, int64_t *value) { - if (in->reader->get_s64) { - return in->reader->get_s64(in, value); - } - return -ENOTSUP; + return in->reader->get_s64(in, value); } -static inline int engine_get_string(struct lwm2m_input_context *in, uint8_t *buf, size_t buflen) +static inline int engine_get_string(struct lwm2m_input_context *in, + uint8_t *buf, size_t buflen) { - if (in->reader->get_string) { - return in->reader->get_string(in, buf, buflen); - } - return -ENOTSUP; + return in->reader->get_string(in, buf, buflen); } static inline int engine_get_time(struct lwm2m_input_context *in, time_t *value) { - if (in->reader->get_time) { - return in->reader->get_time(in, value); - } - return -ENOTSUP; + return in->reader->get_time(in, value); } -static inline int engine_get_float(struct lwm2m_input_context *in, double *value) +static inline int engine_get_float(struct lwm2m_input_context *in, + double *value) { - if (in->reader->get_float) { - return in->reader->get_float(in, value); - } - return -ENOTSUP; + return in->reader->get_float(in, value); } static inline int engine_get_bool(struct lwm2m_input_context *in, bool *value) { - if (in->reader->get_bool) { - return in->reader->get_bool(in, value); - } - return -ENOTSUP; + return in->reader->get_bool(in, value); } -static inline int engine_get_opaque(struct lwm2m_input_context *in, uint8_t *buf, size_t buflen, - struct lwm2m_opaque_context *opaque, bool *last_block) +static inline int engine_get_opaque(struct lwm2m_input_context *in, + uint8_t *buf, size_t buflen, + struct lwm2m_opaque_context *opaque, + bool *last_block) { if (in->reader->get_opaque) { - return in->reader->get_opaque(in, buf, buflen, opaque, last_block); + return in->reader->get_opaque(in, buf, buflen, + opaque, last_block); } - return -ENOTSUP; + return 0; } -static inline int engine_get_objlnk(struct lwm2m_input_context *in, struct lwm2m_objlnk *value) +static inline int engine_get_objlnk(struct lwm2m_input_context *in, + struct lwm2m_objlnk *value) { - if (in->reader->get_objlnk) { - return in->reader->get_objlnk(in, value); - } - return -ENOTSUP; + return in->reader->get_objlnk(in, value); } #endif /* LWM2M_OBJECT_H_ */ From 075fc5fc14ae96d890cd654643bb97b8086368fa Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:45 +0000 Subject: [PATCH 0851/1623] Revert "[nrf fromtree] net: lwm2m: Clean up shell documentation" This reverts commit 79d70889263c4965c760e5835d1b2d1f7e69fbe9. Signed-off-by: Dominik Ermel --- doc/connectivity/networking/api/lwm2m.rst | 68 +++++++++-------------- subsys/net/lib/lwm2m/lwm2m_shell.c | 22 ++++---- 2 files changed, 37 insertions(+), 53 deletions(-) diff --git a/doc/connectivity/networking/api/lwm2m.rst b/doc/connectivity/networking/api/lwm2m.rst index c630ea7785a..6d26205511e 100644 --- a/doc/connectivity/networking/api/lwm2m.rst +++ b/doc/connectivity/networking/api/lwm2m.rst @@ -633,58 +633,40 @@ required actions from the server side. .. code-block:: console - uart:~$ lwm2m - lwm2m - LwM2M commands - Subcommands: - send :send PATHS - LwM2M SEND operation - - exec :exec PATH [PARAM] - Execute a resource - - read :read PATH [OPTIONS] - Read value from LwM2M resource - -x Read value as hex stream (default) - -s Read value as string + uart:~$ lwm2m + lwm2m - LwM2M commands + Subcommands: + exec :Execute a resource + exec PATH + + read :Read value from LwM2M resource + read PATH [OPTIONS] + -s Read value as string (default) -b Read value as bool (1/0) -uX Read value as uintX_t -sX Read value as intX_t -f Read value as float - -t Read value as time_t - - write :write PATH [OPTIONS] VALUE - Write into LwM2M resource - -s Write value as string (default) - -b Write value as bool - -uX Write value as uintX_t - -sX Write value as intX_t - -f Write value as float - -t Write value as time_t - - create :create PATH - Create object instance - - cache :cache PATH NUM - Enable data cache for resource - PATH is LwM2M path - NUM how many elements to cache - - start :start EP_NAME [BOOTSTRAP FLAG] - Start the LwM2M RD (Registration / Discovery) Client - -b Set the bootstrap flag (default 0) - stop :stop [OPTIONS] - Stop the LwM2M RD (De-register) Client - -f Force close the connection + write :Write into LwM2M resource + write PATH [OPTIONS] VALUE + -s Value as string (default) + -b Value as bool + -uX Value as uintX_t + -sX Value as intX_t + -f Value as float - update :Trigger Registration Update of the LwM2M RD Client + start :Start the LwM2M RD (Registration / Discovery) Client + start EP_NAME [BOOTSTRAP FLAG] + -b Set the bootstrap flag (default 0) - pause :LwM2M engine thread pause - resume :LwM2M engine thread resume - lock :Lock the LwM2M registry - unlock :Unlock the LwM2M registry + stop :Stop the LwM2M RD (De-register) Client + stop [OPTIONS] + -f Force close the connection + update :Trigger Registration Update of the LwM2M RD Client + pause :LwM2M engine thread pause + resume :LwM2M engine thread resume .. _lwm2m_api_reference: diff --git a/subsys/net/lib/lwm2m/lwm2m_shell.c b/subsys/net/lib/lwm2m/lwm2m_shell.c index 335004ec5d5..2a86aa88d69 100644 --- a/subsys/net/lib/lwm2m/lwm2m_shell.c +++ b/subsys/net/lib/lwm2m/lwm2m_shell.c @@ -22,9 +22,10 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #define LWM2M_HELP_CMD "LwM2M commands" -#define LWM2M_HELP_SEND "send PATHS\nLwM2M SEND operation\n" -#define LWM2M_HELP_EXEC "exec PATH [PARAM]\nExecute a resource\n" -#define LWM2M_HELP_READ "read PATH [OPTIONS]\nRead value from LwM2M resource\n" \ +#define LWM2M_HELP_SEND "LwM2M SEND operation\nsend [OPTION]... [PATH]...\n" \ + "Root-level operation is unsupported" +#define LWM2M_HELP_EXEC "Execute a resource\nexec PATH [PARAM]\n" +#define LWM2M_HELP_READ "Read value from LwM2M resource\nread PATH [OPTIONS]\n" \ "-x \tRead value as hex stream (default)\n" \ "-s \tRead value as string\n" \ "-b \tRead value as bool (1/0)\n" \ @@ -32,25 +33,26 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); "-sX\tRead value as intX_t\n" \ "-f \tRead value as float\n" \ "-t \tRead value as time_t\n" -#define LWM2M_HELP_WRITE "write PATH [OPTIONS] VALUE\nWrite into LwM2M resource\n" \ +#define LWM2M_HELP_WRITE "Write into LwM2M resource\nwrite PATH [OPTIONS] VALUE\n" \ "-s \tWrite value as string (default)\n" \ "-b \tWrite value as bool\n" \ "-uX\tWrite value as uintX_t\n" \ "-sX\tWrite value as intX_t\n" \ "-f \tWrite value as float\n" \ "-t \tWrite value as time_t\n" -#define LWM2M_HELP_CREATE "create PATH\nCreate object instance\n" -#define LWM2M_HELP_START "start EP_NAME [BOOTSTRAP FLAG]\n" \ - "Start the LwM2M RD (Registration / Discovery) Client\n" \ +#define LWM2M_HELP_CREATE "Create object instance\ncreate PATH\n" +#define LWM2M_HELP_START "Start the LwM2M RD (Registration / Discovery) Client\n" \ + "start EP_NAME [BOOTSTRAP FLAG]\n" \ "-b \tSet the bootstrap flag (default 0)\n" -#define LWM2M_HELP_STOP "stop [OPTIONS]\nStop the LwM2M RD (De-register) Client\n" \ +#define LWM2M_HELP_STOP "Stop the LwM2M RD (De-register) Client\nstop [OPTIONS]\n" \ "-f \tForce close the connection\n" #define LWM2M_HELP_UPDATE "Trigger Registration Update of the LwM2M RD Client\n" #define LWM2M_HELP_PAUSE "LwM2M engine thread pause" #define LWM2M_HELP_RESUME "LwM2M engine thread resume" #define LWM2M_HELP_LOCK "Lock the LwM2M registry" #define LWM2M_HELP_UNLOCK "Unlock the LwM2M registry" -#define LWM2M_HELP_CACHE "cache PATH NUM\nEnable data cache for resource\n" \ +#define LWM2M_HELP_CACHE "Enable data cache for resource\n" \ + "cache PATH NUM\n" \ "PATH is LwM2M path\n" \ "NUM how many elements to cache\n" \ @@ -595,7 +597,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD_ARG(read, NULL, LWM2M_HELP_READ, cmd_read, 2, 1), SHELL_CMD_ARG(write, NULL, LWM2M_HELP_WRITE, cmd_write, 3, 1), SHELL_CMD_ARG(create, NULL, LWM2M_HELP_CREATE, cmd_create, 2, 0), - SHELL_CMD_ARG(cache, NULL, LWM2M_HELP_CACHE, cmd_cache, 3, 0), SHELL_CMD_ARG(start, NULL, LWM2M_HELP_START, cmd_start, 2, 2), SHELL_CMD_ARG(stop, NULL, LWM2M_HELP_STOP, cmd_stop, 1, 1), SHELL_CMD_ARG(update, NULL, LWM2M_HELP_UPDATE, cmd_update, 1, 0), @@ -603,6 +604,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD_ARG(resume, NULL, LWM2M_HELP_RESUME, cmd_resume, 1, 0), SHELL_CMD_ARG(lock, NULL, LWM2M_HELP_LOCK, cmd_lock, 1, 0), SHELL_CMD_ARG(unlock, NULL, LWM2M_HELP_UNLOCK, cmd_unlock, 1, 0), + SHELL_CMD_ARG(cache, NULL, LWM2M_HELP_CACHE, cmd_cache, 3, 0), SHELL_SUBCMD_SET_END); SHELL_COND_CMD_ARG_REGISTER(CONFIG_LWM2M_SHELL, lwm2m, &sub_lwm2m, From 88b110357ca3be4353735a9f79ad5cdfa3858621 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:46 +0000 Subject: [PATCH 0852/1623] Revert "[nrf fromtree] net: lwm2m: Add functional tests for LwM2M against Leshan" This reverts commit 70a65804527ea66bf30a353d12ab4a348cf54cd8. Signed-off-by: Dominik Ermel --- tests/net/lib/lwm2m/interop/CMakeLists.txt | 10 - tests/net/lib/lwm2m/interop/README.md | 103 ---- .../lwm2m/interop/boards/native_posix.conf | 7 - .../lwm2m/interop/boards/qemu_cortex_m3.conf | 20 - tests/net/lib/lwm2m/interop/prj.conf | 90 ---- tests/net/lib/lwm2m/interop/pytest/leshan.py | 104 ---- .../lib/lwm2m/interop/pytest/test_lwm2m.py | 446 ------------------ tests/net/lib/lwm2m/interop/requirements.txt | 1 - .../net/lib/lwm2m/interop/src/lwm2m-client.c | 171 ------- tests/net/lib/lwm2m/interop/testcase.yaml | 14 - 10 files changed, 966 deletions(-) delete mode 100644 tests/net/lib/lwm2m/interop/CMakeLists.txt delete mode 100644 tests/net/lib/lwm2m/interop/README.md delete mode 100644 tests/net/lib/lwm2m/interop/boards/native_posix.conf delete mode 100644 tests/net/lib/lwm2m/interop/boards/qemu_cortex_m3.conf delete mode 100644 tests/net/lib/lwm2m/interop/prj.conf delete mode 100644 tests/net/lib/lwm2m/interop/pytest/leshan.py delete mode 100644 tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py delete mode 100644 tests/net/lib/lwm2m/interop/requirements.txt delete mode 100644 tests/net/lib/lwm2m/interop/src/lwm2m-client.c delete mode 100644 tests/net/lib/lwm2m/interop/testcase.yaml diff --git a/tests/net/lib/lwm2m/interop/CMakeLists.txt b/tests/net/lib/lwm2m/interop/CMakeLists.txt deleted file mode 100644 index 89c4d33e43e..00000000000 --- a/tests/net/lib/lwm2m/interop/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(lwm2m_interop_tests) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources}) - -include(${ZEPHYR_BASE}/samples/net/common/common.cmake) diff --git a/tests/net/lib/lwm2m/interop/README.md b/tests/net/lib/lwm2m/interop/README.md deleted file mode 100644 index 858f5007f64..00000000000 --- a/tests/net/lib/lwm2m/interop/README.md +++ /dev/null @@ -1,103 +0,0 @@ -# LwM2M Interoperability tests using Leshan demo server - -This directory contains list of testcases that use -the Twister's Pytest integration to run testcases against Leshan demo server. -These tests use emulated hardware (native_posix). - -These tests require setup that is not done in Twister run, so follow this documentation to set -up the test environment. - -## Network setup - -As with typical network samples, host machine uses IP address `192.0.2.2` and the emulated device -running Zephyr is using address `192.0.2.1`. - -Follow [Networking with the host system](https://docs.zephyrproject.org/latest/connectivity/networking/networking_with_host.html#networking-with-the-host-system) -from Zephyr's documentation how to set it up, or follow [Create NAT and routing for Zephyr native network on Linux](https://github.com/zephyrproject-rtos/net-tools/blob/master/README%20NAT.md). - -### Leshan server setup - -* Leshan server must be reachable from the device using IP address `192.0.2.2`. - Configure the port forwarding, if you use Docker to run Leshan. -* Leshan demo server REST API must be reachable from localhost. -* tcp/8080 Leshan web interface and REST API -* tcp/8081 Leshan bootstrap server REST API -* udp/5683 Leshan non-secure CoAP -* udp/5684 Leshan DTLS CoAP -* udp/5783 non-secure Bootstrap CoAP -* udp/5684 DTLS Bootstrap CoAP -* Download Leshan JAR file from https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-server-demo.jar -* Download Leshan Bootstrap server JAR file from https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-bsserver-demo.jar - -Both server can be started like this: -``` -java -jar ./leshan-server-demo.jar -wp 8080 -vv -java -jar ./leshan-bsserver-demo.jar -lp=5783 -slp=5784 -wp 8081 -``` - -Or create a helper script that does everything, including download: -``` -#!/bin/sh -eu - -# Download Leshan if needed -if [ ! -f leshan-server-demo.jar ]; then - wget https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-server-demo.jar -fi - -if [ ! -f leshan-bsserver-demo.jar ]; then - wget 'https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-bsserver-demo.jar' -fi - -mkdir -p log - -start-stop-daemon --make-pidfile --pidfile log/leshan.pid --chdir $(pwd) --background --start \ - --startas /bin/bash -- -c "exec java -jar ./leshan-server-demo.jar -wp 8080 -vv --models-folder objects >log/leshan.log 2>&1" - -start-stop-daemon --make-pidfile --pidfile log/leshan_bs.pid --chdir $(pwd) --background --start \ - --startas /bin/bash -- -c "exec java -jar ./leshan-bsserver-demo.jar -lp=5783 -slp=5784 -wp 8081 -vv >log/leshan_bs.log 2>&1" -``` - -Then stopping would require similar script: -``` -#!/bin/sh -eu - -start-stop-daemon --remove-pidfile --pidfile log/leshan.pid --stop -start-stop-daemon --remove-pidfile --pidfile log/leshan_bs.pid --stop -``` - -## Python package requirements - -These tests require extra package that is not installed when you follow the Zephyr's setup. -Install with `pip install CoAPthon3` - -## Running tests - -``` -twister -p native_posix -vv --enable-slow -T tests/net/lib/lwm2m/interop -`````` - -## Test specification - -Tests are written from test spec; -[OMA Enabler Test Specification (Interoperability) for Lightweight M2M](https://www.openmobilealliance.org/release/LightweightM2M/ETS/OMA-ETS-LightweightM2M-V1_1-20190912-D.pdf) - -Following tests are implemented: -* LightweightM2M-1.1-int-0 – Client Initiated Bootstrap -* LightweightM2M-1.1-int-1 – Client Initiated Bootstrap Full (PSK) -* LightweightM2M-1.1-int-101 – Initial Registration -* LightweightM2M-1.1-int-102 – Registration Update -* LightweightM2M-1.1-int-104 – Registration Update Trigge -* LightweightM2M-1.1-int-105 - Discarded Register Update -* LightweightM2M-1.1-int-107 – Extending the lifetime of a registration -* LightweightM2M-1.1-int-108 – Turn on Queue Mode -* LightweightM2M-1.1-int-109 – Behavior in Queue Mode -* LightweightM2M-1.1-int-201 – Querying basic information in Plain Text -* LightweightM2M-1.1-int-203 – Querying basic information in TLV format -* LightweightM2M-1.1-int-204 – Querying basic information in JSON format -* LightweightM2M-1.1-int-205 – Setting basic information in Plain Text -* LightweightM2M-1.1-int-211 – Querying basic information in CBOR format -* LightweightM2M-1.1-int-212 – Setting basic information in CBOR format -* LightweightM2M-1.1-int-215 – Setting basic information in TLV format -* LightweightM2M-1.1-int-220 – Setting basic information in JSON format -* LightweightM2M-1.1-int-221 – Attempt to perform operations on Security -* LightweightM2M-1.1-int-401 – UDP Channel Security – PSK Mode diff --git a/tests/net/lib/lwm2m/interop/boards/native_posix.conf b/tests/net/lib/lwm2m/interop/boards/native_posix.conf deleted file mode 100644 index 44346db12ed..00000000000 --- a/tests/net/lib/lwm2m/interop/boards/native_posix.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_DNS_RESOLVER=y -CONFIG_DNS_SERVER_IP_ADDRESSES=y -CONFIG_DNS_SERVER1="192.0.2.2" -CONFIG_LWM2M_DNS_SUPPORT=y -CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2" -CONFIG_NATIVE_POSIX_SLOWDOWN_TO_REAL_TIME=y -CONFIG_NATIVE_UART_0_ON_STDINOUT=y diff --git a/tests/net/lib/lwm2m/interop/boards/qemu_cortex_m3.conf b/tests/net/lib/lwm2m/interop/boards/qemu_cortex_m3.conf deleted file mode 100644 index 7a3fd344e50..00000000000 --- a/tests/net/lib/lwm2m/interop/boards/qemu_cortex_m3.conf +++ /dev/null @@ -1,20 +0,0 @@ -CONFIG_NET_L2_ETHERNET=y -CONFIG_ETH_DRIVER=y -CONFIG_ETH_STELLARIS=y -CONFIG_NET_QEMU_ETHERNET=y - -# RAM/ROM tuning -CONFIG_IDLE_STACK_SIZE=128 -CONFIG_MBEDTLS_HEAP_SIZE=7000 -CONFIG_ISR_STACK_SIZE=512 -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1024 -CONFIG_LWM2M_ENGINE_STACK_SIZE=2000 -CONFIG_LWM2M_LOG_LEVEL_INF=y -CONFIG_LWM2M_ENGINE_MAX_MESSAGES=3 -CONFIG_LWM2M_ENGINE_VALIDATION_BUFFER_SIZE=0 -CONFIG_LWM2M_ENGINE_MAX_OBSERVER=5 -CONFIG_LWM2M_SECURITY_DTLS_TLS_CIPHERSUITE_MAX=3 -CONFIG_LWM2M_DEVICE_PWRSRC_MAX=2 -CONFIG_LWM2M_DEVICE_ERROR_CODE_MAX=5 -CONFIG_LWM2M_DEVICE_EXT_DEV_INFO_MAX=2 -CONFIG_LWM2M_NUM_ATTR=10 diff --git a/tests/net/lib/lwm2m/interop/prj.conf b/tests/net/lib/lwm2m/interop/prj.conf deleted file mode 100644 index 5d255e0513e..00000000000 --- a/tests/net/lib/lwm2m/interop/prj.conf +++ /dev/null @@ -1,90 +0,0 @@ -CONFIG_NETWORKING=y -CONFIG_LOG=y -CONFIG_LWM2M_LOG_LEVEL_DBG=y -CONFIG_TEST_RANDOM_GENERATOR=y -CONFIG_NET_IPV6=y -CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 -CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2 -CONFIG_NET_IPV4=y -CONFIG_NET_DHCPV4=n -CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=3 -CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT=2 -CONFIG_PRINTK=y -CONFIG_NET_PKT_RX_COUNT=10 -CONFIG_NET_PKT_TX_COUNT=10 -CONFIG_NET_BUF_RX_COUNT=10 -CONFIG_NET_BUF_TX_COUNT=10 -CONFIG_NET_MAX_CONTEXTS=5 -CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" -CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2" -CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" -CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2" - -CONFIG_NET_LOG=y - -CONFIG_NET_CONFIG_NEED_IPV6=y -CONFIG_NET_CONFIG_NEED_IPV4=y -CONFIG_NET_CONFIG_SETTINGS=y - -CONFIG_LWM2M=y -CONFIG_LWM2M_COAP_BLOCK_SIZE=512 -CONFIG_LWM2M_IPSO_SUPPORT=y -CONFIG_LWM2M_SHELL=y -CONFIG_LWM2M_ACCESS_CONTROL_ENABLE=n - -#Enable Portfolio object -CONFIG_LWM2M_PORTFOLIO_OBJ_SUPPORT=y - -#LwM2M v1.1 configure -CONFIG_LWM2M_VERSION_1_1=y -CONFIG_LWM2M_DTLS_SUPPORT=y -CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP=y - -#Enable SenML JSON content format -CONFIG_JSON_LIBRARY=y -CONFIG_BASE64=y -CONFIG_LWM2M_RW_SENML_JSON_SUPPORT=y - -#Enable SenML CBOR content format -CONFIG_LWM2M_RW_SENML_CBOR_SUPPORT=y -CONFIG_LWM2M_RW_SENML_CBOR_RECORDS=60 -CONFIG_ZCBOR_CANONICAL=y - -#Enable legacy content formats -CONFIG_LWM2M_RW_JSON_SUPPORT=y -CONFIG_LWM2M_RW_OMA_TLV_SUPPORT=y - -# Longer endpoint name might be returned in a registration reply -CONFIG_COAP_EXTENDED_OPTIONS_LEN=y -CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=40 - -# Use QUEUE mode by default -CONFIG_LWM2M_QUEUE_MODE_ENABLED=y -CONFIG_LWM2M_QUEUE_MODE_UPTIME=20 - -# LwM2M configuration as OMA-ETS-LightweightM2M_INT-V1_1-20190912-D Configuration 3 -CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=30 -CONFIG_LWM2M_SERVER_DEFAULT_PMIN=1 -CONFIG_LWM2M_SERVER_DEFAULT_PMAX=10 - -CONFIG_MBEDTLS=y -CONFIG_MBEDTLS_TLS_VERSION_1_2=y - -# Special MbedTLS changes -CONFIG_MBEDTLS_ENABLE_HEAP=y -CONFIG_MBEDTLS_HEAP_SIZE=8192 -CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=1500 -CONFIG_MBEDTLS_CIPHER_CCM_ENABLED=y - -# Disable RSA, we don't parse certs: saves flash/memory -CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED=n -# Enable PSK instead -CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED=y - -CONFIG_NET_SOCKETS_SOCKOPT_TLS=y -CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=4 -CONFIG_NET_SOCKETS_ENABLE_DTLS=y - -# MbedTLS needs a larger stack -CONFIG_MAIN_STACK_SIZE=2048 -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 diff --git a/tests/net/lib/lwm2m/interop/pytest/leshan.py b/tests/net/lib/lwm2m/interop/pytest/leshan.py deleted file mode 100644 index 4d69a3a977f..00000000000 --- a/tests/net/lib/lwm2m/interop/pytest/leshan.py +++ /dev/null @@ -1,104 +0,0 @@ -# Copyright (c) 2023 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -from __future__ import annotations - -import json -import requests -import binascii - -class Leshan: - def __init__(self, url: str): - self.api_url = url - self.timeout = 10 - self.format = 'TLV' - # self.format = "SENML_CBOR" - try: - resp = self.get('/security/clients') - if not isinstance(resp, list): - raise RuntimeError('Did not receive list of endpoints') - except requests.exceptions.ConnectionError: - raise RuntimeError('Leshan not responding') - - @staticmethod - def handle_response(resp: requests.models.Response): - """Generic response handler for all queries""" - if resp.status_code >= 300 or resp.status_code < 200: - raise RuntimeError(f'Error {resp.status_code}: {resp.text}') - if len(resp.text): - obj = json.loads(resp.text) - return obj - else: - return None - - def get(self, path: str): - """Send HTTP GET query""" - resp = requests.get(f'{self.api_url}{path}?timeout={self.timeout}&format={self.format}') - return Leshan.handle_response(resp) - - def put_raw(self, path: str, data: str | dict | None = None, headers: dict | None = None): - resp = requests.put(f'{self.api_url}{path}', data=data, headers=headers) - return Leshan.handle_response(resp) - - def put(self, path: str, data: str | dict, uri_options: str = ''): - if isinstance(data, dict): - data = json.dumps(data) - return self.put_raw(f'{path}?timeout={self.timeout}&format={self.format}' + uri_options, data=data, headers={'content-type': 'application/json'}) - - def post(self, path: str, data: str | dict | None = None): - resp = requests.post(f'{self.api_url}{path}', data=data, headers={'content-type': 'application/json'}) - return Leshan.handle_response(resp) - - def delete(self, path: str): - resp = requests.delete(f'{self.api_url}{path}') - return Leshan.handle_response(resp) - - def execute(self, endpoint: str, path: str): - return self.post(f'/clients/{endpoint}/{path}') - - def write(self, endpoint: str, path: str, value: bool | int | str): - if isinstance(value, bool): - type = 'boolean' - value = "true" if value else "false" - elif isinstance(value, int): - type = 'integer' - value = str(value) - elif isinstance(value, str): - type = 'string' - value = '"' + value + '"' - id = path.split('/')[2] - return self.put(f'/clients/{endpoint}/{path}', f'{{"id":{id},"kind":"singleResource","value":{value},"type":"{type}"}}') - - def read(self, endpoint: str, path: str): - resp = self.get(f'/clients/{endpoint}/{path}') - if not resp['success']: - return resp - content = resp['content'] - if content['kind'] == 'instance': - return content['resources'] - elif content['kind'] == 'singleResource': - return content['value'] - elif content['kind'] == 'multiResource': - return content['values'] - raise RuntimeError(f'Unhandled type {content["kind"]}') - - def create_psk_device(self, endpoint: str, passwd: str): - psk = binascii.b2a_hex(passwd.encode()).decode() - self.put('/security/clients/', f'{{"endpoint":"{endpoint}","tls":{{"mode":"psk","details":{{"identity":"{endpoint}","key":"{psk}"}} }} }}') - - def delete_device(self, endpoint: str): - self.delete(f'/security/clients/{endpoint}') - - def create_bs_device(self, endpoint: str, server_uri: str, passwd: str): - psk = binascii.b2a_hex(passwd.encode()).decode() - data = f'{{"tls":{{"mode":"psk","details":{{"identity":"{endpoint}","key":"{psk}"}}}},"endpoint":"{endpoint}"}}' - self.put('/security/clients/', data) - id = str([ord(n) for n in endpoint]) - key = str([ord(n) for n in passwd]) - content = '{"servers":{"0":{"binding":"U","defaultMinPeriod":1,"lifetime":86400,"notifIfDisabled":false,"shortId":1}},"security":{"1":{"bootstrapServer":false,"clientOldOffTime":1,"publicKeyOrId":' + id + ',"secretKey":' + key + ',"securityMode":"PSK","serverId":1,"serverSmsNumber":"","smsBindingKeyParam":[],"smsBindingKeySecret":[],"smsSecurityMode":"NO_SEC","uri":"'+server_uri+'"}},"oscore":{},"toDelete":["/0","/1"]}' - self.post(f'/bootstrap/{endpoint}', content) - - def delete_bs_device(self, endpoint: str): - self.delete(f'/security/clients/{endpoint}') - self.delete(f'/bootstrap/{endpoint}') diff --git a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py deleted file mode 100644 index 21ed51ef1e6..00000000000 --- a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py +++ /dev/null @@ -1,446 +0,0 @@ -# Copyright (c) 2023 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -import time -import logging -import pytest -from leshan import Leshan -import os -import binascii -import random -import string - -from twister_harness import Shell - -LESHAN_IP: str = '192.0.2.2' -COAP_PORT: int = 5683 -COAPS_PORT: int = 5684 -BOOTSTRAP_COAPS_PORT: int = 5784 - -logger = logging.getLogger(__name__) - -@pytest.fixture(scope='module') -def helperclient() -> object: - try: - from coapthon.client.helperclient import HelperClient - except ModuleNotFoundError: - pytest.skip('CoAPthon3 package not installed') - return HelperClient(server=('127.0.0.1', COAP_PORT)) - -@pytest.fixture(scope='session') -def leshan() -> Leshan: - try: - return Leshan("http://localhost:8080/api") - except RuntimeError: - pytest.skip('Leshan server not available') - -@pytest.fixture(scope='session') -def leshan_bootstrap() -> Leshan: - try: - return Leshan("http://localhost:8081/api") - except RuntimeError: - pytest.skip('Leshan Bootstrap server not available') - -# -# Test specification: -# https://www.openmobilealliance.org/release/LightweightM2M/ETS/OMA-ETS-LightweightM2M-V1_1-20190912-D.pdf -# - -def verify_LightweightM2M_1_1_int_0(shell: Shell): - logger.info("LightweightM2M-1.1-int-0 - Client Initiated Bootstrap") - shell._device.readlines_until(regex='.*Bootstrap started with endpoint', timeout=5.0) - shell._device.readlines_until(regex='.*Bootstrap registration done', timeout=5.0) - shell._device.readlines_until(regex='.*Bootstrap data transfer done', timeout=5.0) - -def verify_LightweightM2M_1_1_int_1(shell: Shell, leshan: Leshan, endpoint: str): - logger.info("LightweightM2M-1.1-int-1 - Client Initiated Bootstrap Full (PSK)") - verify_LightweightM2M_1_1_int_0(shell) - verify_LightweightM2M_1_1_int_101(shell, leshan, endpoint) - verify_LightweightM2M_1_1_int_401(shell, leshan, endpoint) - -def verify_LightweightM2M_1_1_int_101(shell: Shell, leshan: Leshan, endpoint: str): - logger.info("LightweightM2M-1.1-int-101 - Initial Registration") - shell._device.readlines_until(regex='.*Registration Done', timeout=5.0) - assert leshan.get(f'/clients/{endpoint}') - -def verify_LightweightM2M_1_1_int_102(shell: Shell, leshan: Leshan, endpoint: str): - logger.info("LightweightM2M-1.1-int-102 - Registration Update") - lines = shell.get_filtered_output(shell.exec_command('lwm2m read 1/0/1 -u32')) - litetime = int(lines[0]) - lifetime = litetime + 10 - start_time = time.time() * 1000 - leshan.write(endpoint, '1/0/1', lifetime) - shell._device.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=5.0) - latest = leshan.get(f'/clients/{endpoint}') - assert latest["lastUpdate"] > start_time - assert latest["lastUpdate"] <= time.time()*1000 - assert latest["lifetime"] == lifetime - shell.exec_command('lwm2m write 1/0/1 -u32 86400') - -def verify_LightweightM2M_1_1_int_103(): - """LightweightM2M-1.1-int-103 - Deregistration""" - # Unsupported. We don't have "disabled" functionality in server object - -def verify_LightweightM2M_1_1_int_104(shell: Shell, leshan: Leshan, endpoint: str): - logger.info("LightweightM2M-1.1-int-104 - Registration Update Trigger") - shell.exec_command('lwm2m update') - shell._device.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=5.0) - leshan.execute(endpoint, '1/0/8') - shell._device.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=5.0) - -def verify_LightweightM2M_1_1_int_105(shell: Shell, leshan: Leshan, endpoint: str, helperclient: object): - logger.info("LightweightM2M-1.1-int-105 - Discarded Register Update") - status = leshan.get(f'/clients/{endpoint}') - if status["secure"]: - logger.debug("Skip, requires non-secure connection") - return - id = status["registrationId"] - assert id - # Fake unregister message - helperclient.delete(f'rd/{id}', timeout=0.1) - helperclient.stop() - time.sleep(1) - shell.exec_command('lwm2m update') - shell._device.readlines_until(regex=r'.*Failed with code 4\.4', timeout=5.0) - shell._device.readlines_until(regex='.*Registration Done', timeout=10.0) - -def verify_LightweightM2M_1_1_int_107(shell: Shell, leshan: Leshan, endpoint: str): - logger.info("LightweightM2M-1.1-int-107 - Extending the lifetime of a registration") - leshan.write(endpoint, '1/0/1', 120) - shell._device.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=5.0) - lines = shell.get_filtered_output(shell.exec_command('lwm2m read 1/0/1 -u32')) - lifetime = int(lines[0]) - assert lifetime == 120 - logger.debug(f'sleeping for {lifetime} s') - shell._device.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=lifetime) - assert leshan.get(f'/clients/{endpoint}') - -def verify_LightweightM2M_1_1_int_108(leshan, endpoint): - logger.info("LightweightM2M-1.1-int-108 - Turn on Queue Mode") - assert leshan.get(f'/clients/{endpoint}')["queuemode"] - -def verify_LightweightM2M_1_1_int_109(shell: Shell, leshan: Leshan, endpoint: str): - logger.info("LightweightM2M-1.1-int-109 - Behavior in Queue Mode") - verify_LightweightM2M_1_1_int_107(shell, leshan, endpoint) - shell._device.readlines_until(regex='.*Queue mode RX window closed', timeout=120) - # Restore previous value - shell.exec_command('lwm2m write 1/0/1 -u32 86400') - shell._device.readlines_until(regex='.*Registration update complete', timeout=10) - -def verify_LightweightM2M_1_1_int_201(shell: Shell, leshan: Leshan, endpoint: str): - - logger.info("LightweightM2M-1.1-int-201 - Querying basic information in Plain Text format") - fmt = leshan.format - leshan.format = 'TEXT' - assert leshan.get(f'/clients/{endpoint}/3/0/0')['content']['value'] == 'Zephyr' - assert leshan.get(f'/clients/{endpoint}/3/0/1')['content']['value'] == 'client-1' - assert leshan.get(f'/clients/{endpoint}/3/0/2')['content']['value'] == 'serial-1' - leshan.format = fmt - -def verify_device_object(resp): - ''' Verify that Device object match Configuration 3 ''' - assert resp['valid'] is True - found = 0 - for res in resp['content']['resources']: - if res['id'] == 0: - assert res['value'] == 'Zephyr' - found += 1 - elif res['id'] == 1: - assert res['value'] == 'client-1' - found += 1 - elif res['id'] == 2: - assert res['value'] == 'serial-1' - found += 1 - elif res['id'] == 3: - assert res['value'] == '1.2.3' - found += 1 - elif res['id'] == 11: - assert res['kind'] == 'multiResource' - assert res['values']['0'] == '0' - found += 1 - elif res['id'] == 16: - assert res['value'] == 'U' - found += 1 - assert found == 6 - -def verify_server_object(obj): - ''' Verify that server object match Configuration 3 ''' - found = 0 - for res in obj['resources']: - if res['id'] == 0: - assert res['value'] == '1' - found += 1 - elif res['id'] == 1: - assert res['value'] == '86400' - found += 1 - elif res['id'] == 2: - assert res['value'] == '1' - found += 1 - elif res['id'] == 3: - assert res['value'] == '10' - found += 1 - elif res['id'] == 5: - assert res['value'] == '86400' - found += 1 - elif res['id'] == 6: - assert res['value'] is False - found += 1 - elif res['id'] == 7: - assert res['value'] == 'U' - found += 1 - assert found == 7 - -def verify_LightweightM2M_1_1_int_203(shell: Shell, leshan: Leshan, endpoint: str): - shell.exec_command('lwm2m update') - logger.info('LightweightM2M-1.1-int-203 - Querying basic information in TLV format') - fmt = leshan.format - leshan.format = 'TLV' - resp = leshan.get(f'/clients/{endpoint}/3/0') - verify_device_object(resp) - leshan.format = fmt - -def verify_LightweightM2M_1_1_int_204(shell: Shell, leshan: Leshan, endpoint: str): - shell.exec_command('lwm2m update') - logger.info('LightweightM2M-1.1-int-204 - Querying basic information in JSON format') - fmt = leshan.format - leshan.format = 'JSON' - resp = leshan.get(f'/clients/{endpoint}/3/0') - verify_device_object(resp) - leshan.format = fmt - -def verify_LightweightM2M_1_1_int_205(shell: Shell, leshan: Leshan, endpoint: str): - logger.info('LightweightM2M-1.1-int-205 - Setting basic information in Plain Text format') - fmt = leshan.format - leshan.format = 'TEXT' - leshan.write(endpoint, '1/0/2', 101) - leshan.write(endpoint, '1/0/3', 1010) - leshan.write(endpoint, '1/0/5', 2000) - assert leshan.read(endpoint, '1/0/2') == '101' - assert leshan.read(endpoint, '1/0/3') == '1010' - assert leshan.read(endpoint, '1/0/5') == '2000' - leshan.write(endpoint, '1/0/2', 1) - leshan.write(endpoint, '1/0/3', 10) - leshan.write(endpoint, '1/0/5', 86400) - assert leshan.read(endpoint, '1/0/2') == '1' - assert leshan.read(endpoint, '1/0/3') == '10' - assert leshan.read(endpoint, '1/0/5') == '86400' - leshan.format = fmt - -def verify_LightweightM2M_1_1_int_211(shell: Shell, leshan: Leshan, endpoint: str): - logger.info('LightweightM2M-1.1-int-211 - Querying basic information in CBOR format') - fmt = leshan.format - leshan.format = 'CBOR' - lines = shell.get_filtered_output(shell.exec_command('lwm2m read 1/0/0 -u16')) - id = lines[0] - assert leshan.read(endpoint, '1/0/0') == id - assert leshan.read(endpoint, '1/0/6') is False - assert leshan.read(endpoint, '1/0/7') == 'U' - leshan.format = fmt - -def verify_LightweightM2M_1_1_int_212(shell: Shell, leshan: Leshan, endpoint: str): - logger.info('LightweightM2M-1.1-int-212 - Setting basic information in CBOR format') - fmt = leshan.format - leshan.format = 'CBOR' - leshan.write(endpoint, '1/0/2', 101) - leshan.write(endpoint, '1/0/3', 1010) - leshan.write(endpoint, '1/0/6', True) - assert leshan.read(endpoint, '1/0/2') == '101' - assert leshan.read(endpoint, '1/0/3') == '1010' - assert leshan.read(endpoint, '1/0/6') is True - leshan.write(endpoint, '1/0/2', 1) - leshan.write(endpoint, '1/0/3', 10) - leshan.write(endpoint, '1/0/6', False) - leshan.format = fmt - -def verify_setting_basic_in_format(shell, leshan, endpoint, format): - fmt = leshan.format - leshan.format = format - server_obj = leshan.get(f'/clients/{endpoint}/1/0')['content'] - verify_server_object(server_obj) - # Remove Read-Only resources, so we don't end up writing those - for res in server_obj['resources']: - if res['id'] in (0, 11, 12): - server_obj['resources'].remove(res) - data = '''{ - "kind": "instance", - "id": 0, - "resources": [ - { - "id": 2, - "kind": "singleResource", - "value": "101", - "type": "integer" - }, - { - "id": 3, - "kind": "singleResource", - "value": "1010", - "type": "integer" - }, - { - "id": 5, - "kind": "singleResource", - "value": "2000", - "type": "integer" - }, - { - "id": 6, - "kind": "singleResource", - "value": true, - "type": "boolean" - }, - { - "id": 7, - "kind": "singleResource", - "value": "U", - "type": "string" - } - ] - }''' - assert leshan.put(f'/clients/{endpoint}/1/0', data, uri_options = '&replace=false')['status'] == 'CHANGED(204)' - resp = leshan.get(f'/clients/{endpoint}/1/0') - assert resp['valid'] is True - found = 0 - for res in resp['content']['resources']: - if res['id'] == 2: - assert res['value'] == '101' - found += 1 - elif res['id'] == 3: - assert res['value'] == '1010' - found += 1 - elif res['id'] == 5: - assert res['value'] == '2000' - found += 1 - elif res['id'] == 6: - assert res['value'] is True - found += 1 - elif res['id'] == 7: - assert res['value'] == 'U' - found += 1 - assert found == 5 - assert leshan.put(f'/clients/{endpoint}/1/0', data = server_obj, uri_options = '&replace=true')['status'] == 'CHANGED(204)' - server_obj = leshan.get(f'/clients/{endpoint}/1/0')['content'] - verify_server_object(server_obj) - leshan.format = fmt - -def verify_LightweightM2M_1_1_int_215(shell: Shell, leshan: Leshan, endpoint: str): - logger.info('LightweightM2M-1.1-int-215 - Setting basic information in TLV format') - verify_setting_basic_in_format(shell, leshan, endpoint, 'TLV') - -def verify_LightweightM2M_1_1_int_220(shell: Shell, leshan: Leshan, endpoint: str): - logger.info('LightweightM2M-1.1-int-220 - Setting basic information in JSON format') - verify_setting_basic_in_format(shell, leshan, endpoint, 'JSON') - -def verify_LightweightM2M_1_1_int_221(shell: Shell, leshan: Leshan, endpoint: str): - logger.info('LightweightM2M-1.1-int-221 - Attempt to perform operations on Security') - assert leshan.read(endpoint, '0/0')['status'] == 'UNAUTHORIZED(401)' - assert leshan.write(endpoint, '0/0/0', 'coap://localhost')['status'] == 'UNAUTHORIZED(401)' - assert leshan.put_raw(f'/clients/{endpoint}/0/attributes?pmin=10')['status'] == 'UNAUTHORIZED(401)' - -def verify_LightweightM2M_1_1_int_401(shell: Shell, leshan: Leshan, endpoint: str): - logger.info("LightweightM2M-1.1-int-401 - UDP Channel Security - Pre-shared Key Mode") - lines = shell.get_filtered_output(shell.exec_command('lwm2m read 0/0/0 -s')) - host = lines[0] - assert 'coaps://' in host - lines = shell.get_filtered_output(shell.exec_command('lwm2m read 0/0/2 -u8')) - mode = int(lines[0]) - assert mode == 0 - resp = leshan.get(f'/clients/{endpoint}') - assert resp["secure"] - -def test_lwm2m_bootstrap_psk(shell: Shell, leshan, leshan_bootstrap): - try: - # Generate randon device id and password (PSK key) - endpoint = 'client_' + binascii.b2a_hex(os.urandom(1)).decode() - passwd = ''.join(random.choice(string.ascii_lowercase) for i in range(16)) - - - # Create device entries in Leshan and Bootstrap server - leshan_bootstrap.create_bs_device(endpoint, f'coaps://{LESHAN_IP}:{COAPS_PORT}', passwd) - leshan.create_psk_device(endpoint, passwd) - - # Allow engine to start & stop once. - time.sleep(2) - - # - # Verify PSK security using Bootstrap - # - - # Write bootsrap server information and PSK keys - shell.exec_command(f'lwm2m write 0/0/0 -s coaps://{LESHAN_IP}:{BOOTSTRAP_COAPS_PORT}') - shell.exec_command('lwm2m write 0/0/1 -b 1') - shell.exec_command('lwm2m write 0/0/2 -u8 0') - shell.exec_command(f'lwm2m write 0/0/3 -s {endpoint}') - shell.exec_command(f'lwm2m write 0/0/5 -s {passwd}') - shell.exec_command(f'lwm2m start {endpoint} -b 1') - - - # - # Bootstrap Interface test cases - # LightweightM2M-1.1-int-0 (included) - # LightweightM2M-1.1-int-401 (included) - verify_LightweightM2M_1_1_int_1(shell, leshan, endpoint) - - # - # Registration Interface test cases (using PSK security) - # - verify_LightweightM2M_1_1_int_102(shell, leshan, endpoint) - # skip, not implemented verify_LightweightM2M_1_1_int_103() - verify_LightweightM2M_1_1_int_104(shell, leshan, endpoint) - # skip, included in 109: verify_LightweightM2M_1_1_int_107(shell, leshan, endpoint) - verify_LightweightM2M_1_1_int_108(leshan, endpoint) - verify_LightweightM2M_1_1_int_109(shell, leshan, endpoint) - - # - # Device management & Service Enablement Interface test cases - # - verify_LightweightM2M_1_1_int_201(shell, leshan, endpoint) - verify_LightweightM2M_1_1_int_203(shell, leshan, endpoint) - verify_LightweightM2M_1_1_int_204(shell, leshan, endpoint) - verify_LightweightM2M_1_1_int_205(shell, leshan, endpoint) - verify_LightweightM2M_1_1_int_211(shell, leshan, endpoint) - verify_LightweightM2M_1_1_int_212(shell, leshan, endpoint) - verify_LightweightM2M_1_1_int_215(shell, leshan, endpoint) - - shell.exec_command('lwm2m stop') - shell._device.readlines_until(regex=r'.*Deregistration success', timeout=10.0) - - finally: - # Remove device and bootstrap information - # Leshan does not accept non-secure connection if device information is provided with PSK - leshan.delete_device(endpoint) - leshan_bootstrap.delete_bs_device(endpoint) - - -def test_lwm2m_nosecure(shell: Shell, leshan, helperclient): - - # Allow engine to start & stop once. - time.sleep(2) - - # Generate randon device id and password (PSK key) - endpoint = 'client_' + binascii.b2a_hex(os.urandom(1)).decode() - - # - # Registration Interface test cases (using Non-secure mode) - # - shell.exec_command(f'lwm2m write 0/0/0 -s coap://{LESHAN_IP}:{COAP_PORT}') - shell.exec_command('lwm2m write 0/0/1 -b 0') - shell.exec_command('lwm2m write 0/0/2 -u8 3') - shell.exec_command(f'lwm2m write 0/0/3 -s {endpoint}') - shell.exec_command('lwm2m create 1/0') - shell.exec_command('lwm2m write 0/0/10 -u16 1') - shell.exec_command('lwm2m write 1/0/0 -u16 1') - shell.exec_command('lwm2m write 1/0/1 -u32 86400') - shell.exec_command(f'lwm2m start {endpoint} -b 0') - shell._device.readlines_until(regex=f"RD Client started with endpoint '{endpoint}'", timeout=10.0) - - verify_LightweightM2M_1_1_int_101(shell, leshan, endpoint) - verify_LightweightM2M_1_1_int_105(shell, leshan, endpoint, helperclient) # needs no-security - verify_LightweightM2M_1_1_int_215(shell, leshan, endpoint) - verify_LightweightM2M_1_1_int_220(shell, leshan, endpoint) - verify_LightweightM2M_1_1_int_221(shell, leshan, endpoint) - - # All done - shell.exec_command('lwm2m stop') - shell._device.readlines_until(regex=r'.*Deregistration success', timeout=10.0) diff --git a/tests/net/lib/lwm2m/interop/requirements.txt b/tests/net/lib/lwm2m/interop/requirements.txt deleted file mode 100644 index 38c501218ee..00000000000 --- a/tests/net/lib/lwm2m/interop/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -CoAPthon3 diff --git a/tests/net/lib/lwm2m/interop/src/lwm2m-client.c b/tests/net/lib/lwm2m/interop/src/lwm2m-client.c deleted file mode 100644 index 1278d807b71..00000000000 --- a/tests/net/lib/lwm2m/interop/src/lwm2m-client.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2017 Linaro Limited - * Copyright (c) 2017-2019 Foundries.io - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#define LOG_MODULE_NAME net_lwm2m_client_app -#define LOG_LEVEL LOG_LEVEL_DBG - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME); -#include -#include -#include -#include -#include -#include - -#define APP_BANNER "Run LWM2M client" - -#define WAIT_TIME K_SECONDS(10) -#define CONNECT_TIME K_SECONDS(10) - -#define NAME "Zephyr" -#define MODEL "client-1" -#define SERIAL "serial-1" -#define VERSION "1.2.3" - -static struct lwm2m_ctx client; - -static int device_reboot_cb(uint16_t obj_inst_id, - uint8_t *args, uint16_t args_len) -{ - LOG_INF("DEVICE: REBOOT"); - return 0; -} - - -static int lwm2m_setup(void) -{ - /* setup DEVICE object */ - - lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 0), NAME, sizeof(NAME), - sizeof(NAME), LWM2M_RES_DATA_FLAG_RO); - lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 1), MODEL, sizeof(MODEL), - sizeof(MODEL), LWM2M_RES_DATA_FLAG_RO); - lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 2), SERIAL, sizeof(SERIAL), - sizeof(SERIAL), LWM2M_RES_DATA_FLAG_RO); - lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 3), VERSION, sizeof(VERSION), - sizeof(VERSION), LWM2M_RES_DATA_FLAG_RO); - lwm2m_register_exec_callback(&LWM2M_OBJ(3, 0, 4), device_reboot_cb); - lwm2m_set_res_buf(&LWM2M_OBJ(3, 0, 17), CONFIG_BOARD, sizeof(CONFIG_BOARD), - sizeof(CONFIG_BOARD), LWM2M_RES_DATA_FLAG_RO); - - return 0; -} - -static void rd_client_event(struct lwm2m_ctx *client, - enum lwm2m_rd_client_event client_event) -{ - switch (client_event) { - - case LWM2M_RD_CLIENT_EVENT_NONE: - /* do nothing */ - break; - - case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE: - LOG_DBG("Bootstrap registration failure!"); - break; - - case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_COMPLETE: - LOG_DBG("Bootstrap registration complete"); - break; - - case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_TRANSFER_COMPLETE: - LOG_DBG("Bootstrap transfer complete"); - break; - - case LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE: - LOG_DBG("Registration failure!"); - break; - - case LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE: - LOG_DBG("Registration complete"); - break; - - case LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT: - LOG_DBG("Registration timeout!"); - break; - - case LWM2M_RD_CLIENT_EVENT_REG_UPDATE_COMPLETE: - LOG_DBG("Registration update complete"); - break; - - case LWM2M_RD_CLIENT_EVENT_DEREGISTER_FAILURE: - LOG_DBG("Deregister failure!"); - break; - - case LWM2M_RD_CLIENT_EVENT_DISCONNECT: - LOG_DBG("Disconnected"); - break; - - case LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF: - LOG_DBG("Queue mode RX window closed"); - break; - - case LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED: - LOG_DBG("LwM2M engine suspended"); - break; - - case LWM2M_RD_CLIENT_EVENT_NETWORK_ERROR: - LOG_ERR("LwM2M engine reported a network error."); - lwm2m_rd_client_stop(client, rd_client_event, true); - break; - - case LWM2M_RD_CLIENT_EVENT_REG_UPDATE: - LOG_DBG("Registration update"); - break; - } -} - -static void observe_cb(enum lwm2m_observe_event event, - struct lwm2m_obj_path *path, void *user_data) -{ - char buf[LWM2M_MAX_PATH_STR_SIZE]; - - switch (event) { - - case LWM2M_OBSERVE_EVENT_OBSERVER_ADDED: - LOG_INF("Observer added for %s", lwm2m_path_log_buf(buf, path)); - break; - - case LWM2M_OBSERVE_EVENT_OBSERVER_REMOVED: - LOG_INF("Observer removed for %s", lwm2m_path_log_buf(buf, path)); - break; - - case LWM2M_OBSERVE_EVENT_NOTIFY_ACK: - LOG_INF("Notify acknowledged for %s", lwm2m_path_log_buf(buf, path)); - break; - - case LWM2M_OBSERVE_EVENT_NOTIFY_TIMEOUT: - LOG_INF("Notify timeout for %s, trying registration update", - lwm2m_path_log_buf(buf, path)); - - lwm2m_rd_client_update(); - break; - } -} - -int main(void) -{ - int ret; - -#if defined(CONFIG_BOARD_NATIVE_POSIX) - srandom(time(NULL)); -#endif - - ret = lwm2m_setup(); - if (ret < 0) { - LOG_ERR("Cannot setup LWM2M fields (%d)", ret); - return 0; - } - - client.tls_tag = 1; - - lwm2m_rd_client_start(&client, CONFIG_BOARD, 0, rd_client_event, observe_cb); - lwm2m_rd_client_stop(&client, rd_client_event, false); - - return 0; -} diff --git a/tests/net/lib/lwm2m/interop/testcase.yaml b/tests/net/lib/lwm2m/interop/testcase.yaml deleted file mode 100644 index aeba64748df..00000000000 --- a/tests/net/lib/lwm2m/interop/testcase.yaml +++ /dev/null @@ -1,14 +0,0 @@ -tests: - net.lwm2m.interop: - harness: pytest - timeout: 300 - slow: true - integration_platforms: - - native_posix - platform_allow: - - native_posix - - qemu_cortex_m3 - tags: - - testing - - pytest - - shell From 49ffa81ed3a257901b5c11733601e883be266f39 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:46 +0000 Subject: [PATCH 0853/1623] Revert "[nrf fromtree] net: lwm2m: Add shell command to create object instances" This reverts commit 52d120825d49c1d37430162fbf9c1d4a8edd1bb9. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/lwm2m_shell.c | 36 ------------------------------ 1 file changed, 36 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_shell.c b/subsys/net/lib/lwm2m/lwm2m_shell.c index 2a86aa88d69..f8374eb34f2 100644 --- a/subsys/net/lib/lwm2m/lwm2m_shell.c +++ b/subsys/net/lib/lwm2m/lwm2m_shell.c @@ -40,7 +40,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); "-sX\tWrite value as intX_t\n" \ "-f \tWrite value as float\n" \ "-t \tWrite value as time_t\n" -#define LWM2M_HELP_CREATE "Create object instance\ncreate PATH\n" #define LWM2M_HELP_START "Start the LwM2M RD (Registration / Discovery) Client\n" \ "start EP_NAME [BOOTSTRAP FLAG]\n" \ "-b \tSet the bootstrap flag (default 0)\n" @@ -373,40 +372,6 @@ static int cmd_write(const struct shell *sh, size_t argc, char **argv) return 0; } -static int cmd_create(const struct shell *sh, size_t argc, char **argv) -{ - struct lwm2m_obj_path path; - struct lwm2m_engine_obj_inst *obj_inst; - int ret; - - if (argc < 2) { - shell_error(sh, "No object ID given\n"); - shell_help(sh); - return -EINVAL; - } - - ret = lwm2m_string_to_path(argv[1], &path, '/'); - if (ret < 0) { - shell_error(sh, "failed to read path (%d)\n", ret); - return -ENOEXEC; - } - - if (path.level != LWM2M_PATH_LEVEL_OBJECT_INST) { - shell_error(sh, "path is not an object instance\n"); - shell_help(sh); - return -EINVAL; - } - - ret = lwm2m_create_obj_inst(path.obj_id, path.obj_inst_id, &obj_inst); - if (ret < 0) { - shell_error(sh, "Failed to create object instance %d/%d, ret=%d", path.obj_id, - path.obj_inst_id, ret); - return -ENOEXEC; - } - - return 0; -} - static int cmd_start(const struct shell *sh, size_t argc, char **argv) { struct lwm2m_ctx *ctx = lwm2m_rd_client_ctx(); @@ -596,7 +561,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD_ARG(exec, NULL, LWM2M_HELP_EXEC, cmd_exec, 2, 1), SHELL_CMD_ARG(read, NULL, LWM2M_HELP_READ, cmd_read, 2, 1), SHELL_CMD_ARG(write, NULL, LWM2M_HELP_WRITE, cmd_write, 3, 1), - SHELL_CMD_ARG(create, NULL, LWM2M_HELP_CREATE, cmd_create, 2, 0), SHELL_CMD_ARG(start, NULL, LWM2M_HELP_START, cmd_start, 2, 2), SHELL_CMD_ARG(stop, NULL, LWM2M_HELP_STOP, cmd_stop, 1, 1), SHELL_CMD_ARG(update, NULL, LWM2M_HELP_UPDATE, cmd_update, 1, 0), From 3a43bf79655ff04b4e399ed03ea6b8e7b49e2274 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:46 +0000 Subject: [PATCH 0854/1623] Revert "[nrf fromtree] net: lwm2m: Don't allow operations on security object" This reverts commit 98a073881f16b6f656f52c697e333a38a25c0d3d. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 1a7d023ceb2..952a3d9c130 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -2330,11 +2330,6 @@ int handle_request(struct coap_packet *request, struct lwm2m_message *msg) goto error; } #endif - if (msg->path.obj_id == LWM2M_OBJECT_SECURITY_ID && !msg->ctx->bootstrap_mode) { - r = -EACCES; - goto error; - } - switch (msg->operation) { case LWM2M_OP_READ: From 555769dd1944eac90607ea856a5c609b4f39b936 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:46 +0000 Subject: [PATCH 0855/1623] Revert "[nrf fromtree] net: lwm2m: Fix build warning on access-control object" This reverts commit 2ea372c8833205e30b5986a1567ab48e735f1726. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/lwm2m_obj_access_control.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_access_control.c b/subsys/net/lib/lwm2m/lwm2m_obj_access_control.c index 383dbe9b539..1a83ef5ad29 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_access_control.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_access_control.c @@ -432,10 +432,10 @@ static int ac_control_init(void) ac_obj.create_cb = ac_create; lwm2m_register_obj(&ac_obj); - if (!IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)) { - /* add the objects/object instances that were created before the ac control */ - add_existing_objects(); - } +#if !IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) + /* add the objects/object instances that were created before the ac control object */ + add_existing_objects(); +#endif /* CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP */ return 0; } From 277e2837d2f5518d50878d2685b325df3f677d66 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:46 +0000 Subject: [PATCH 0856/1623] Revert "[nrf fromtree] net: lwm2m: Allow Bootstrap server to close DTLS connection" This reverts commit 2a642c8d8dace1cfe3ea52f80dcfd41bd0832d92. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/lwm2m_rd_client.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.c b/subsys/net/lib/lwm2m/lwm2m_rd_client.c index feebcaeea17..fca3f7d560f 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.c +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.c @@ -89,10 +89,12 @@ static void set_sm_state(uint8_t sm_state); enum sm_engine_state { ENGINE_IDLE, ENGINE_INIT, +#if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) ENGINE_DO_BOOTSTRAP_REG, ENGINE_BOOTSTRAP_REG_SENT, ENGINE_BOOTSTRAP_REG_DONE, ENGINE_BOOTSTRAP_TRANS_DONE, +#endif ENGINE_DO_REGISTRATION, ENGINE_SEND_REGISTRATION, ENGINE_REGISTRATION_SENT, @@ -353,21 +355,15 @@ static void sm_handle_failure_state(enum sm_engine_state sm_state) static void socket_fault_cb(int error) { LOG_ERR("RD Client socket error: %d", error); - lwm2m_socket_close(client.ctx); - if (IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) && sm_is_bootstrap()) { + if (sm_is_bootstrap()) { client.ctx->sec_obj_inst = -1; /* force full registration */ client.last_update = 0; - - if (get_sm_state() == ENGINE_BOOTSTRAP_TRANS_DONE) { - /* Ignore the error, some servers close the connection immediately - * after receiving Ack to Bootstrap-Finish command. - */ - return; - } } + lwm2m_socket_close(client.ctx); + /* Network error state causes engine to re-register, * so only trigger that state if we are not stopping the * engine. From 8a80faa616f89a1345c3ec9c497af9c0397d8ad9 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:47 +0000 Subject: [PATCH 0857/1623] Revert "[nrf fromtree] net: lwm2m: Add timeouts to state machine" This reverts commit 8ff85348030453c3562bf8edcc4f9a583f168f22. Signed-off-by: Dominik Ermel --- subsys/net/lib/lwm2m/lwm2m_rd_client.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.c b/subsys/net/lib/lwm2m/lwm2m_rd_client.c index fca3f7d560f..0f4405bfc92 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.c +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.c @@ -70,7 +70,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #define CLIENT_QUEUE_LEN sizeof("Q") #define DELAY_BEFORE_CLOSING (1 * MSEC_PER_SEC) #define DELAY_FOR_ACK 100U -#define EXCHANGE_LIFETIME 247U static void sm_handle_registration_update_failure(void); static int sm_send_registration_msg(void); @@ -121,7 +120,6 @@ struct lwm2m_rd_client_info { int64_t last_update; int64_t last_tx; int64_t next_event; - int64_t last_state_change; char ep_name[CLIENT_EP_LEN]; char server_ep[CLIENT_EP_LEN]; @@ -174,7 +172,6 @@ void engine_update_tx_time(void) static void next_event_at(int64_t timestamp) { - client.next_event = timestamp; (void)lwm2m_engine_call_at(lwm2m_rd_client_service, timestamp); } @@ -239,7 +236,6 @@ static void set_sm_state_delayed(uint8_t sm_state, int64_t delay_ms) lwm2m_close_socket(client.ctx); } } - client.last_state_change = k_uptime_get(); next_event_at(k_uptime_get() + delay_ms); k_mutex_unlock(&client.mutex); } @@ -1292,11 +1288,8 @@ static void lwm2m_rd_client_service(struct k_work *work) { k_mutex_lock(&client.mutex, K_FOREVER); - int64_t timeout = 0; - if (client.ctx) { LOG_DBG("State: %d", get_sm_state()); - client.next_event = INT64_MAX; switch (get_sm_state()) { case ENGINE_IDLE: if (client.ctx->sock_fd > -1) { @@ -1319,12 +1312,10 @@ static void lwm2m_rd_client_service(struct k_work *work) case ENGINE_BOOTSTRAP_REG_SENT: /* wait for bootstrap registration done */ - timeout = EXCHANGE_LIFETIME; break; case ENGINE_BOOTSTRAP_REG_DONE: /* wait for transfer done */ - timeout = EXCHANGE_LIFETIME; break; case ENGINE_BOOTSTRAP_TRANS_DONE: @@ -1342,7 +1333,6 @@ static void lwm2m_rd_client_service(struct k_work *work) case ENGINE_REGISTRATION_SENT: /* wait registration to be done or timeout */ - timeout = EXCHANGE_LIFETIME; break; case ENGINE_REGISTRATION_DONE: @@ -1356,7 +1346,6 @@ static void lwm2m_rd_client_service(struct k_work *work) case ENGINE_UPDATE_SENT: /* wait update to be done or abort */ - timeout = EXCHANGE_LIFETIME; break; case ENGINE_DEREGISTER: @@ -1365,7 +1354,6 @@ static void lwm2m_rd_client_service(struct k_work *work) case ENGINE_DEREGISTER_SENT: /* wait for deregister to be done or reset */ - timeout = EXCHANGE_LIFETIME; break; case ENGINE_DEREGISTERED: @@ -1381,17 +1369,6 @@ static void lwm2m_rd_client_service(struct k_work *work) LOG_ERR("Unhandled state: %d", get_sm_state()); } - - if (timeout) { - int64_t end = client.last_state_change + timeout * MSEC_PER_SEC; - - if (end < k_uptime_get()) { - LOG_DBG("State machine have timed out"); - sm_handle_timeout_state(NULL, ENGINE_INIT); - } else if (client.next_event > end) { - next_event_at(end); - } - } } k_mutex_unlock(&client.mutex); From 5eba083e6471a6b8d5a45f0ffbd733b1c74b9794 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:47 +0000 Subject: [PATCH 0858/1623] Revert "[nrf fromtree] test: lwm2m: Fix minor timing issue" This reverts commit 09bcf9d88014ee367f0db56ff244754b306efe31. Signed-off-by: Dominik Ermel --- tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt | 2 +- tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt b/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt index 81e129c56c1..5f29bdad0dd 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/CMakeLists.txt @@ -23,7 +23,7 @@ add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_ENDPOINT_NAME_MAX_LENGTH=32) add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_MAX_RETRIES=2) add_compile_definitions(CONFIG_LWM2M_COAP_BLOCK_SIZE=256) add_compile_definitions(CONFIG_LWM2M_COAP_MAX_MSG_SIZE=512) -add_compile_definitions(CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=20) +add_compile_definitions(CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=60) add_compile_definitions(CONFIG_LWM2M_SECURITY_INSTANCE_COUNT=1) add_compile_definitions(CONFIG_LWM2M_SECONDS_TO_UPDATE_EARLY=10) add_compile_definitions(CONFIG_LWM2M_QUEUE_MODE_UPTIME=10) diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c index 41789e20340..58f64f4984d 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c @@ -117,12 +117,10 @@ uint16_t counter = RD_CLIENT_MAX_SERVICE_ITERATIONS; struct lwm2m_message *pending_message; void *(*pending_message_cb)(); static bool running; -K_SEM_DEFINE(srv_sem, 0, 1); static void service_work_fn(struct k_work *work) { while (running) { - k_sleep(K_MSEC(10)); if (pending_message != NULL && pending_message_cb != NULL) { pending_message_cb(pending_message); pending_message = NULL; @@ -131,9 +129,8 @@ static void service_work_fn(struct k_work *work) if (next && next < k_uptime_get()) { next = 0; service(NULL); - k_sem_give(&srv_sem); } - + k_sleep(K_MSEC(10)); counter--; /* avoid endless loop if rd client is stuck somewhere */ @@ -146,8 +143,10 @@ static void service_work_fn(struct k_work *work) void wait_for_service(uint16_t cycles) { - while (cycles--) { - k_sem_take(&srv_sem, K_MSEC(100)); + uint16_t end = counter - cycles; + + while (counter > end) { + k_sleep(K_MSEC(10)); } } @@ -158,7 +157,6 @@ void test_lwm2m_engine_start_service(void) running = true; counter = RD_CLIENT_MAX_SERVICE_ITERATIONS; k_work_submit(&service_work); - k_sem_reset(&srv_sem); } void test_lwm2m_engine_stop_service(void) From c5dfc5ee01425876076bb18be1161fb0abbe8bb5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:47 +0000 Subject: [PATCH 0859/1623] Revert "[nrf fromtree] nrf53: pretick with NRF_802154_RADIO_DRIVER" This reverts commit d4e8b1eeae72a627d38c3cf08736dfe436efdac5. Signed-off-by: Dominik Ermel --- drivers/timer/Kconfig.nrf_rtc | 1 - soc/arm/nordic_nrf/nrf53/Kconfig.soc | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/timer/Kconfig.nrf_rtc b/drivers/timer/Kconfig.nrf_rtc index acb6f123afe..cda05d4dabe 100644 --- a/drivers/timer/Kconfig.nrf_rtc +++ b/drivers/timer/Kconfig.nrf_rtc @@ -19,7 +19,6 @@ if NRF_RTC_TIMER config NRF_RTC_TIMER_USER_CHAN_COUNT int "Additional channels that can be used" - default 2 if NRF_802154_RADIO_DRIVER && SOC_NRF5340_CPUNET default 3 if NRF_802154_RADIO_DRIVER default 0 help diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 2ad4a7add66..9bb4caf2bb9 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -51,6 +51,7 @@ config SOC_NRF53_ANOMALY_160_WORKAROUND config SOC_NRF53_RTC_PRETICK bool "Pre-tick workaround for nRF5340 anomaly 165" + depends on !NRF_802154_RADIO_DRIVER select NRFX_DPPI select ARM_ON_ENTER_CPU_IDLE_HOOK if SOC_NRF5340_CPUNET select ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK if SOC_NRF5340_CPUNET @@ -201,7 +202,6 @@ config NRF53_SYNC_RTC_INIT_PRIORITY nRF53 Synchronized RTC initialization priority. config NRF_RTC_TIMER_USER_CHAN_COUNT - default 2 if NRF_802154_RADIO_DRIVER && SOC_NRF5340_CPUNET default 3 if NRF_802154_RADIO_DRIVER default 1 From bc5f3901f483e2a1982ef7b15fa41193d8157633 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:47 +0000 Subject: [PATCH 0860/1623] Revert "[nrf fromtree] nrf53: RTC pretick allows user channels and require just one CC" This reverts commit 0704fb1e49aef4c6d9f892b0d46c771f0081e360. Signed-off-by: Dominik Ermel --- drivers/timer/nrf_rtc_timer.c | 18 +- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 9 +- soc/arm/nordic_nrf/nrf53/soc.c | 274 +++++---------------------- 3 files changed, 62 insertions(+), 239 deletions(-) diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index 9241c5b7a10..e8ba5bd42a5 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -17,18 +17,20 @@ #include #include -#define RTC_PRETICK (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK) && \ - IS_ENABLED(CONFIG_SOC_NRF5340_CPUNET)) - #define EXT_CHAN_COUNT CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT #define CHAN_COUNT (EXT_CHAN_COUNT + 1) #define RTC NRF_RTC1 #define RTC_IRQn NRFX_IRQ_NUMBER_GET(RTC) #define RTC_LABEL rtc1 -#define CHAN_COUNT_MAX (RTC1_CC_NUM - (RTC_PRETICK ? 1 : 0)) +#define RTC_CH_COUNT RTC1_CC_NUM -BUILD_ASSERT(CHAN_COUNT <= CHAN_COUNT_MAX, "Not enough compare channels"); +#define RTC_PRETICK (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK) && \ + IS_ENABLED(CONFIG_SOC_NRF5340_CPUNET)) + +BUILD_ASSERT(!RTC_PRETICK || !(RTC_PRETICK && (CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT > 0)), + "Cannot use user channels when RTC pretick is used"); +BUILD_ASSERT(CHAN_COUNT <= RTC_CH_COUNT, "Not enough compare channels"); /* Ensure that counter driver for RTC1 is not enabled. */ BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(RTC_LABEL), disabled), "Counter for RTC1 must be disabled"); @@ -47,6 +49,7 @@ BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(RTC_LABEL), disabled), #define ANCHOR_RANGE_END (7 * COUNTER_SPAN / 8) #define TARGET_TIME_INVALID (UINT64_MAX) +extern void rtc_pretick_rtc1_cc0_set_hook(uint32_t val); extern void rtc_pretick_rtc1_isr_hook(void); static volatile uint32_t overflow_cnt; @@ -265,7 +268,7 @@ static int set_alarm(int32_t chan, uint32_t req_cc, bool exact) * This never happens when the written value is N+3. Use 3 cycles as * the nearest possible scheduling then. */ - enum { MIN_CYCLES_FROM_NOW = 3 }; + enum { MIN_CYCLES_FROM_NOW = RTC_PRETICK ? 4 : 3 }; uint32_t cc_val = req_cc; uint32_t cc_inc = MIN_CYCLES_FROM_NOW; @@ -282,6 +285,9 @@ static int set_alarm(int32_t chan, uint32_t req_cc, bool exact) for (;;) { uint32_t now; + if (RTC_PRETICK) { + rtc_pretick_rtc1_cc0_set_hook(cc_val); + } set_comparator(chan, cc_val); /* Enable event routing after the required CC value was set. * Even though the above operation may get repeated (see below), diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 9bb4caf2bb9..b84985d57eb 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -16,7 +16,7 @@ config SOC_NRF5340_CPUNET bool select ARM_ON_EXIT_CPU_IDLE imply SOC_NRF53_ANOMALY_160_WORKAROUND_NEEDED - imply SOC_NRF53_RTC_PRETICK if !WDT_NRFX + imply SOC_NRF53_RTC_PRETICK choice prompt "nRF53x MCU Selection" @@ -50,14 +50,9 @@ config SOC_NRF53_ANOMALY_160_WORKAROUND select ARM_ON_ENTER_CPU_IDLE_HOOK config SOC_NRF53_RTC_PRETICK - bool "Pre-tick workaround for nRF5340 anomaly 165" + bool depends on !NRF_802154_RADIO_DRIVER select NRFX_DPPI - select ARM_ON_ENTER_CPU_IDLE_HOOK if SOC_NRF5340_CPUNET - select ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK if SOC_NRF5340_CPUNET - help - Indicates that the pre-tick workaround for the anomaly 165 that affects - the nRF5340 SoC should be applied. if SOC_NRF53_RTC_PRETICK diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index aa93dfd4b54..50f00932be9 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -43,11 +42,8 @@ #define PIN_XL1 0 #define PIN_XL2 1 -#define RTC1_PRETICK_CC_CHAN (RTC1_CC_NUM - 1) - -/* Mask of CC channels capable of generating interrupts, see nrf_rtc_timer.c */ -#define RTC1_PRETICK_SELECTED_CC_MASK BIT_MASK(CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT + 1U) -#define RTC0_PRETICK_SELECTED_CC_MASK BIT_MASK(NRF_RTC_CC_COUNT_MAX) +#define RTC1_PRETICK_CC_CHAN 1 +#define RTC1_PRETICK_OVERFLOW_CHAN 2 #if defined(CONFIG_SOC_NRF_GPIO_FORWARDER_FOR_NRF5340) #define GPIOS_PSEL_BY_IDX(node_id, prop, idx) \ @@ -134,240 +130,39 @@ static bool nrf53_anomaly_160_check(void) return true; } -#if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) - -BUILD_ASSERT(!IS_ENABLED(CONFIG_WDT_NRFX), - "For CONFIG_SOC_NRF53_RTC_PRETICK watchdog is used internally for the pre-tick workaround on nRF5340 cpunet. Application cannot use the watchdog."); - -static inline uint32_t rtc_counter_sub(uint32_t a, uint32_t b) -{ - return (a - b) & NRF_RTC_COUNTER_MAX; -} - -static bool rtc_ticks_to_next_event_get(NRF_RTC_Type *rtc, uint32_t selected_cc_mask, uint32_t cntr, - uint32_t *ticks_to_next_event) -{ - bool result = false; - - /* Let's preload register to speed-up. */ - uint32_t reg_intenset = rtc->INTENSET; - - /* Note: TICK event not handled. */ - - if (reg_intenset & NRF_RTC_INT_OVERFLOW_MASK) { - /* Overflow can generate an interrupt. */ - *ticks_to_next_event = NRF_RTC_COUNTER_MAX + 1U - cntr; - result = true; - } - - for (uint32_t chan = 0; chan < NRF_RTC_CC_COUNT_MAX; chan++) { - if ((selected_cc_mask & (1U << chan)) && - (reg_intenset & NRF_RTC_CHANNEL_INT_MASK(chan))) { - /* The CC is in selected mask and is can generate an interrupt. */ - uint32_t cc = nrf_rtc_cc_get(rtc, chan); - uint32_t ticks_to_fire = rtc_counter_sub(cc, cntr); - - if (ticks_to_fire == 0U) { - /* When ticks_to_fire == 0, the event should have been just - * generated the interrupt can be already handled or be pending. - * However the next event is expected to be after counter wraps. - */ - ticks_to_fire = NRF_RTC_COUNTER_MAX + 1U; - } - - if (!result) { - *ticks_to_next_event = ticks_to_fire; - result = true; - } else if (ticks_to_fire < *ticks_to_next_event) { - *ticks_to_next_event = ticks_to_fire; - result = true; - } else { - /* CC that fires no earlier than already found. */ - } - } - } - - return result; -} - -static void rtc_counter_synchronized_get(NRF_RTC_Type *rtc_a, NRF_RTC_Type *rtc_b, - uint32_t *counter_a, uint32_t *counter_b) -{ - do { - *counter_a = nrf_rtc_counter_get(rtc_a); - barrier_dmem_fence_full(); - *counter_b = nrf_rtc_counter_get(rtc_b); - barrier_dmem_fence_full(); - } while (*counter_a != nrf_rtc_counter_get(rtc_a)); -} - -static uint8_t cpu_idle_prepare_monitor_dummy; -static bool cpu_idle_prepare_allows_sleep; - -static void cpu_idle_prepare_monitor_begin(void) -{ - __LDREXB(&cpu_idle_prepare_monitor_dummy); -} - -/* Returns 0 if no exception preempted since the last call to cpu_idle_prepare_monitor_begin. */ -static bool cpu_idle_prepare_monitor_end(void) -{ - /* The value stored is irrelevant. If any exception took place after - * cpu_idle_prepare_monitor_begin, the the local monitor is cleared and - * the store fails returning 1. - * See Arm v8-M Architecture Reference Manual: - * Chapter B9.2 The local monitors - * Chapter B9.4 Exclusive access instructions and the monitors - * See Arm Cortex-M33 Processor Technical Reference Manual - * Chapter 3.5 Exclusive monitor - */ - return __STREXB(0U, &cpu_idle_prepare_monitor_dummy); -} - -void z_arm_on_enter_cpu_idle_prepare(void) +bool z_arm_on_enter_cpu_idle(void) { - bool ok_to_sleep = true; - - cpu_idle_prepare_monitor_begin(); - - uint32_t rtc_counter = 0U; - uint32_t rtc_ticks_to_next_event = 0U; - uint32_t rtc0_counter = 0U; - uint32_t rtc0_ticks_to_next_event = 0U; - - rtc_counter_synchronized_get(NRF_RTC1, NRF_RTC0, &rtc_counter, &rtc0_counter); - - bool rtc_scheduled = rtc_ticks_to_next_event_get(NRF_RTC1, RTC1_PRETICK_SELECTED_CC_MASK, - rtc_counter, &rtc_ticks_to_next_event); - - if (rtc_ticks_to_next_event_get(NRF_RTC0, RTC0_PRETICK_SELECTED_CC_MASK, rtc0_counter, - &rtc0_ticks_to_next_event)) { - /* An event is scheduled on RTC0. */ - if (!rtc_scheduled) { - rtc_ticks_to_next_event = rtc0_ticks_to_next_event; - rtc_scheduled = true; - } else if (rtc0_ticks_to_next_event < rtc_ticks_to_next_event) { - rtc_ticks_to_next_event = rtc0_ticks_to_next_event; - } else { - /* Event on RTC0 will not happen earlier than already found. */ - } - } + bool ok_to_sleep = nrf53_anomaly_160_check(); - if (rtc_scheduled) { - static bool rtc_pretick_cc_set_on_time; - /* The pretick should happen 1 tick before the earliest scheduled event - * that can trigger an interrupt. - */ - uint32_t rtc_pretick_cc_val = (rtc_counter + rtc_ticks_to_next_event - 1U) - & NRF_RTC_COUNTER_MAX; - - if (rtc_pretick_cc_val != nrf_rtc_cc_get(NRF_RTC1, RTC1_PRETICK_CC_CHAN)) { - /* The CC for pretick needs to be updated. */ - nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_CC_CHAN, rtc_pretick_cc_val); - - if (rtc_ticks_to_next_event >= NRF_RTC_COUNTER_MAX/2) { - /* Pretick is scheduled so far in the future, assumed on time. */ - rtc_pretick_cc_set_on_time = true; - } else { - /* Let's check if we updated CC on time, so that the CC can - * take effect. - */ - barrier_dmem_fence_full(); - rtc_counter = nrf_rtc_counter_get(NRF_RTC1); - uint32_t pretick_cc_to_counter = - rtc_counter_sub(rtc_pretick_cc_val, rtc_counter); - - if ((pretick_cc_to_counter < 3) || - (pretick_cc_to_counter >= NRF_RTC_COUNTER_MAX/2)) { - /* The COUNTER value is close enough to the expected - * pretick CC or has just expired, so the pretick event - * generation is not guaranteed. - */ - rtc_pretick_cc_set_on_time = false; - } else { - /* The written rtc_pretick_cc is guaranteed to to trigger - * compare event. - */ - rtc_pretick_cc_set_on_time = true; - } - } - } else { - /* The CC for pretick doesn't need to be updated, however - * rtc_pretick_cc_set_on_time still holds if we managed to set it on time. - */ - } +#if (LOG_LEVEL >= LOG_LEVEL_DBG) + static bool suppress_message; - /* If the CC for pretick is set on time, so the pretick CC event can be reliably - * generated then allow to sleep. Otherwise (the CC for pretick cannot be reliably - * generated, because CC was set very short to it's fire time) sleep not at all. - */ - ok_to_sleep = rtc_pretick_cc_set_on_time; - } else { - /* No events on any RTC timers are scheduled. */ + if (ok_to_sleep) { + suppress_message = false; + } else if (!suppress_message) { + LOG_DBG("Anomaly 160 trigger conditions detected."); + suppress_message = true; } - +#endif +#if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) if (ok_to_sleep) { NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] |= IPC_PUBLISH_RECEIVE_EN_Msk; - if (!nrf_rtc_event_check(NRF_RTC1, - NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN))) { + if (!nrf_rtc_event_check(NRF_RTC0, NRF_RTC_CHANNEL_EVENT_ADDR(3)) && + !nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)) && + !nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN))) { NRF_WDT->TASKS_STOP = 1; /* Check if any event did not occur after we checked for * stopping condition. If yes, we might have stopped WDT * when it should be running. Restart it. */ - if (nrf_rtc_event_check(NRF_RTC1, - NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN))) { + if (nrf_rtc_event_check(NRF_RTC0, NRF_RTC_CHANNEL_EVENT_ADDR(3)) || + nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)) || + nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN))) { NRF_WDT->TASKS_START = 1; } } } - - cpu_idle_prepare_allows_sleep = ok_to_sleep; -} -#endif /* CONFIG_SOC_NRF53_RTC_PRETICK && CONFIG_SOC_NRF5340_CPUNET */ - -bool z_arm_on_enter_cpu_idle(void) -{ - bool ok_to_sleep = true; - -#if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) - if (cpu_idle_prepare_monitor_end() == 0) { - /* No exception happened since cpu_idle_prepare_monitor_begin. - * We can trust the outcome of. z_arm_on_enter_cpu_idle_prepare - */ - ok_to_sleep = cpu_idle_prepare_allows_sleep; - } else { - /* Exception happened since cpu_idle_prepare_monitor_begin. - * The values which z_arm_on_enter_cpu_idle_prepare could be changed - * by the exception, so we can not trust to it's outcome. - * Do not sleep at all, let's try in the next iteration of idle loop. - */ - ok_to_sleep = false; - } -#endif - - if (ok_to_sleep) { - ok_to_sleep = nrf53_anomaly_160_check(); - -#if (LOG_LEVEL >= LOG_LEVEL_DBG) - static bool suppress_message; - - if (ok_to_sleep) { - suppress_message = false; - } else if (!suppress_message) { - LOG_DBG("Anomaly 160 trigger conditions detected."); - suppress_message = true; - } -#endif - } - -#if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) - if (!ok_to_sleep) { - NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] &= - ~IPC_PUBLISH_RECEIVE_EN_Msk; - NRF_WDT->TASKS_STOP = 1; - } #endif return ok_to_sleep; @@ -417,12 +212,25 @@ void rtc_pretick_rtc0_isr_hook(void) rtc_pretick_rtc_isr_hook(); } +void rtc_pretick_rtc1_cc0_set_hook(uint32_t val) +{ + nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_CC_CHAN, val - 1); +} + void rtc_pretick_rtc1_isr_hook(void) { rtc_pretick_rtc_isr_hook(); - if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); + if (nrf_rtc_event_check(NRF_RTC1, NRF_RTC_EVENT_OVERFLOW)) { + if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { + nrf_rtc_event_clear(NRF_RTC1, + NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); + } + } + if (nrf_rtc_event_check(NRF_RTC1, NRF_RTC_EVENT_COMPARE_0)) { + if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); + } } } @@ -436,8 +244,11 @@ static int rtc_pretick_cpunet_init(void) uint32_t task_ipc = nrf_ipc_task_address_get(NRF_IPC, ipc_task); uint32_t evt_ipc = nrf_ipc_event_address_get(NRF_IPC, ipc_event); uint32_t task_wdt = nrf_wdt_task_address_get(NRF_WDT, NRF_WDT_TASK_START); + uint32_t evt_mpsl_cc = nrf_rtc_event_address_get(NRF_RTC0, NRF_RTC_EVENT_COMPARE_3); uint32_t evt_cc = nrf_rtc_event_address_get(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); + uint32_t evt_overflow = nrf_rtc_event_address_get(NRF_RTC1, + NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); /* Configure Watchdog to allow stopping. */ nrf_wdt_behaviour_set(NRF_WDT, WDT_CONFIG_STOPEN_Msk | BIT(4)); @@ -456,14 +267,24 @@ static int rtc_pretick_cpunet_init(void) return -ENOMEM; } + /* Setup a PPI connection between RTC "pretick" events and IPC task. */ + if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE)) { + nrfx_gppi_event_endpoint_setup(ppi_ch, evt_mpsl_cc); + } nrfx_gppi_event_endpoint_setup(ppi_ch, evt_cc); + nrfx_gppi_event_endpoint_setup(ppi_ch, evt_overflow); nrfx_gppi_task_endpoint_setup(ppi_ch, task_ipc); nrfx_gppi_event_endpoint_setup(ppi_ch, evt_ipc); nrfx_gppi_task_endpoint_setup(ppi_ch, task_wdt); nrfx_gppi_channels_enable(BIT(ppi_ch)); nrf_rtc_event_enable(NRF_RTC1, NRF_RTC_CHANNEL_INT_MASK(RTC1_PRETICK_CC_CHAN)); + nrf_rtc_event_enable(NRF_RTC1, NRF_RTC_CHANNEL_INT_MASK(RTC1_PRETICK_OVERFLOW_CHAN)); + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); + nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); + /* Set event 1 tick before overflow. */ + nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_OVERFLOW_CHAN, 0x00FFFFFF); return 0; } @@ -471,6 +292,7 @@ static int rtc_pretick_cpunet_init(void) static int rtc_pretick_init(void) { + ARG_UNUSED(unused); #ifdef CONFIG_SOC_NRF5340_CPUAPP return rtc_pretick_cpuapp_init(); #else From bc38ac400916728f358d2dced03f7e722c0a9111 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:48 +0000 Subject: [PATCH 0861/1623] Revert "[nrf fromtree] arch: arm: aarch32: Introduce z_arm_on_enter_cpu_idle_prepare() hook" This reverts commit b2a1ffbe848082f67c50e094dc065d6d17f5dcc6. Signed-off-by: Dominik Ermel --- arch/arm/Kconfig | 10 ---------- arch/arm/core/aarch32/cpu_idle.S | 25 +++++-------------------- include/zephyr/arch/arm/aarch32/misc.h | 9 --------- 3 files changed, 5 insertions(+), 39 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index ef9a20d0cc9..e17cf3f9b31 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -53,16 +53,6 @@ config ARM_ON_ENTER_CPU_IDLE_HOOK If needed, this hook can be used to prevent the CPU from actually entering sleep by skipping the WFE/WFI instruction. -config ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK - bool - help - Enables a hook (z_arm_on_enter_cpu_idle_prepare()) that is called when - the CPU is made idle (by k_cpu_idle() or k_cpu_atomic_idle()). - If needed, this hook can prepare data to upcoming call to - z_arm_on_enter_cpu_idle(). The z_arm_on_enter_cpu_idle_prepare differs - from z_arm_on_enter_cpu_idle because it is called before interrupts are - disabled. - config ARM_ON_EXIT_CPU_IDLE bool help diff --git a/arch/arm/core/aarch32/cpu_idle.S b/arch/arm/core/aarch32/cpu_idle.S index 95e37917180..8164959ab29 100644 --- a/arch/arm/core/aarch32/cpu_idle.S +++ b/arch/arm/core/aarch32/cpu_idle.S @@ -85,24 +85,16 @@ _skip_\@: .endm SECTION_FUNC(TEXT, arch_cpu_idle) -#if defined(CONFIG_TRACING) || \ - defined(CONFIG_ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK) - push {r0, lr} - #ifdef CONFIG_TRACING + push {r0, lr} bl sys_trace_idle -#endif -#ifdef CONFIG_ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK - bl z_arm_on_enter_cpu_idle_prepare -#endif - #if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE) pop {r0, r1} mov lr, r1 #else pop {r0, lr} #endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */ -#endif +#endif /* CONFIG_TRACING */ #if defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE) /* @@ -146,24 +138,17 @@ SECTION_FUNC(TEXT, arch_cpu_idle) bx lr SECTION_FUNC(TEXT, arch_cpu_atomic_idle) -#if defined(CONFIG_TRACING) || \ - defined(CONFIG_ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK) - push {r0, lr} - #ifdef CONFIG_TRACING + push {r0, lr} bl sys_trace_idle -#endif -#ifdef CONFIG_ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK - bl z_arm_on_enter_cpu_idle_prepare -#endif - #if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE) pop {r0, r1} mov lr, r1 #else pop {r0, lr} #endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */ -#endif +#endif /* CONFIG_TRACING */ + /* * Lock PRIMASK while sleeping: wfe will still get interrupted by * incoming interrupts but the CPU will not service them right away. diff --git a/include/zephyr/arch/arm/aarch32/misc.h b/include/zephyr/arch/arm/aarch32/misc.h index ab67a35e94c..24ed69f663c 100644 --- a/include/zephyr/arch/arm/aarch32/misc.h +++ b/include/zephyr/arch/arm/aarch32/misc.h @@ -51,15 +51,6 @@ extern bool z_arm_thread_is_in_user_mode(void); bool z_arm_on_enter_cpu_idle(void); #endif -#if defined(CONFIG_ARM_ON_ENTER_CPU_IDLE_PREPARE_HOOK) -/* Prototype of a hook that can be enabled to be called every time the CPU is - * made idle (the calls will be done from k_cpu_idle() and k_cpu_atomic_idle()). - * The function is called before interrupts are disabled and can prepare to - * upcoming call to z_arm_on_enter_cpu_idle. - */ -void z_arm_on_enter_cpu_idle_prepare(void); -#endif - #endif #ifdef __cplusplus From 52549a5be97225317179133636ac7341e8d96675 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:48 +0000 Subject: [PATCH 0862/1623] Revert "[nrf fromtree] nrf53: Add RTC pretick" This reverts commit 3d2da670428f177fdbe761db49783cdff83503ee. Signed-off-by: Dominik Ermel --- drivers/timer/nrf_rtc_timer.c | 17 +-- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 21 ---- soc/arm/nordic_nrf/nrf53/soc.c | 164 --------------------------- 3 files changed, 1 insertion(+), 201 deletions(-) diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index e8ba5bd42a5..4410529608b 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -25,11 +25,6 @@ #define RTC_LABEL rtc1 #define RTC_CH_COUNT RTC1_CC_NUM -#define RTC_PRETICK (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK) && \ - IS_ENABLED(CONFIG_SOC_NRF5340_CPUNET)) - -BUILD_ASSERT(!RTC_PRETICK || !(RTC_PRETICK && (CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT > 0)), - "Cannot use user channels when RTC pretick is used"); BUILD_ASSERT(CHAN_COUNT <= RTC_CH_COUNT, "Not enough compare channels"); /* Ensure that counter driver for RTC1 is not enabled. */ BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(RTC_LABEL), disabled), @@ -49,9 +44,6 @@ BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(RTC_LABEL), disabled), #define ANCHOR_RANGE_END (7 * COUNTER_SPAN / 8) #define TARGET_TIME_INVALID (UINT64_MAX) -extern void rtc_pretick_rtc1_cc0_set_hook(uint32_t val); -extern void rtc_pretick_rtc1_isr_hook(void); - static volatile uint32_t overflow_cnt; static volatile uint64_t anchor; static uint64_t last_count; @@ -268,7 +260,7 @@ static int set_alarm(int32_t chan, uint32_t req_cc, bool exact) * This never happens when the written value is N+3. Use 3 cycles as * the nearest possible scheduling then. */ - enum { MIN_CYCLES_FROM_NOW = RTC_PRETICK ? 4 : 3 }; + enum { MIN_CYCLES_FROM_NOW = 3 }; uint32_t cc_val = req_cc; uint32_t cc_inc = MIN_CYCLES_FROM_NOW; @@ -285,9 +277,6 @@ static int set_alarm(int32_t chan, uint32_t req_cc, bool exact) for (;;) { uint32_t now; - if (RTC_PRETICK) { - rtc_pretick_rtc1_cc0_set_hook(cc_val); - } set_comparator(chan, cc_val); /* Enable event routing after the required CC value was set. * Even though the above operation may get repeated (see below), @@ -570,10 +559,6 @@ void rtc_nrf_isr(const void *arg) { ARG_UNUSED(arg); - if (RTC_PRETICK) { - rtc_pretick_rtc1_isr_hook(); - } - if (nrf_rtc_int_enable_check(RTC, NRF_RTC_INT_OVERFLOW_MASK) && nrf_rtc_event_check(RTC, NRF_RTC_EVENT_OVERFLOW)) { nrf_rtc_event_clear(RTC, NRF_RTC_EVENT_OVERFLOW); diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index b84985d57eb..122c36988e5 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -10,13 +10,11 @@ config SOC_NRF5340_CPUAPP select CPU_HAS_FPU select ARMV8_M_DSP select HAS_POWEROFF - imply SOC_NRF53_RTC_PRETICK config SOC_NRF5340_CPUNET bool select ARM_ON_EXIT_CPU_IDLE imply SOC_NRF53_ANOMALY_160_WORKAROUND_NEEDED - imply SOC_NRF53_RTC_PRETICK choice prompt "nRF53x MCU Selection" @@ -49,25 +47,6 @@ config SOC_NRF53_ANOMALY_160_WORKAROUND depends on SYS_CLOCK_EXISTS select ARM_ON_ENTER_CPU_IDLE_HOOK -config SOC_NRF53_RTC_PRETICK - bool - depends on !NRF_802154_RADIO_DRIVER - select NRFX_DPPI - -if SOC_NRF53_RTC_PRETICK - -config SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET - int "IPC 0 channel for RTC pretick" - range 0 15 - default 10 - -config SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET - int "IPC 1 channel for RTC pretick" - range 0 15 - default 11 - -endif - if SOC_NRF5340_CPUAPP config SOC_DCDC_NRF53X_APP diff --git a/soc/arm/nordic_nrf/nrf53/soc.c b/soc/arm/nordic_nrf/nrf53/soc.c index 50f00932be9..6552f9d4bb1 100644 --- a/soc/arm/nordic_nrf/nrf53/soc.c +++ b/soc/arm/nordic_nrf/nrf53/soc.c @@ -18,8 +18,6 @@ #include #include #include -#include -#include #if defined(CONFIG_SOC_NRF5340_CPUAPP) #include #include @@ -33,8 +31,6 @@ #if defined(CONFIG_PM_S2RAM) #include #endif -#include -#include #include #include @@ -42,9 +38,6 @@ #define PIN_XL1 0 #define PIN_XL2 1 -#define RTC1_PRETICK_CC_CHAN 1 -#define RTC1_PRETICK_OVERFLOW_CHAN 2 - #if defined(CONFIG_SOC_NRF_GPIO_FORWARDER_FOR_NRF5340) #define GPIOS_PSEL_BY_IDX(node_id, prop, idx) \ NRF_DT_GPIOS_TO_PSEL_BY_IDX(node_id, prop, idx), @@ -144,164 +137,11 @@ bool z_arm_on_enter_cpu_idle(void) suppress_message = true; } #endif -#if defined(CONFIG_SOC_NRF53_RTC_PRETICK) && defined(CONFIG_SOC_NRF5340_CPUNET) - if (ok_to_sleep) { - NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] |= - IPC_PUBLISH_RECEIVE_EN_Msk; - if (!nrf_rtc_event_check(NRF_RTC0, NRF_RTC_CHANNEL_EVENT_ADDR(3)) && - !nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)) && - !nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN))) { - NRF_WDT->TASKS_STOP = 1; - /* Check if any event did not occur after we checked for - * stopping condition. If yes, we might have stopped WDT - * when it should be running. Restart it. - */ - if (nrf_rtc_event_check(NRF_RTC0, NRF_RTC_CHANNEL_EVENT_ADDR(3)) || - nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)) || - nrf_rtc_event_check(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN))) { - NRF_WDT->TASKS_START = 1; - } - } - } -#endif return ok_to_sleep; } #endif /* CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND */ -#if CONFIG_SOC_NRF53_RTC_PRETICK -#ifdef CONFIG_SOC_NRF5340_CPUAPP -/* RTC pretick - application core part. */ -static int rtc_pretick_cpuapp_init(void) -{ - uint8_t ch; - nrfx_err_t err; - nrf_ipc_event_t ipc_event = - nrf_ipc_receive_event_get(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET); - nrf_ipc_task_t ipc_task = - nrf_ipc_send_task_get(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET); - uint32_t task_ipc = nrf_ipc_task_address_get(NRF_IPC, ipc_task); - uint32_t evt_ipc = nrf_ipc_event_address_get(NRF_IPC, ipc_event); - - err = nrfx_gppi_channel_alloc(&ch); - if (err != NRFX_SUCCESS) { - return -ENOMEM; - } - - nrf_ipc_receive_config_set(NRF_IPC, CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET, - BIT(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET)); - nrf_ipc_send_config_set(NRF_IPC, CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET, - BIT(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET)); - - nrfx_gppi_task_endpoint_setup(ch, task_ipc); - nrfx_gppi_event_endpoint_setup(ch, evt_ipc); - nrfx_gppi_channels_enable(BIT(ch)); - - return 0; -} -#else /* CONFIG_SOC_NRF5340_CPUNET */ - -static void rtc_pretick_rtc_isr_hook(void) -{ - NRF_IPC->PUBLISH_RECEIVE[CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET] &= - ~IPC_PUBLISH_RECEIVE_EN_Msk; -} - -void rtc_pretick_rtc0_isr_hook(void) -{ - rtc_pretick_rtc_isr_hook(); -} - -void rtc_pretick_rtc1_cc0_set_hook(uint32_t val) -{ - nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_CC_CHAN, val - 1); -} - -void rtc_pretick_rtc1_isr_hook(void) -{ - rtc_pretick_rtc_isr_hook(); - - if (nrf_rtc_event_check(NRF_RTC1, NRF_RTC_EVENT_OVERFLOW)) { - if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { - nrf_rtc_event_clear(NRF_RTC1, - NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); - } - } - if (nrf_rtc_event_check(NRF_RTC1, NRF_RTC_EVENT_COMPARE_0)) { - if (IS_ENABLED(CONFIG_SOC_NRF53_RTC_PRETICK)) { - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); - } - } -} - -static int rtc_pretick_cpunet_init(void) -{ - uint8_t ppi_ch; - nrf_ipc_task_t ipc_task = - nrf_ipc_send_task_get(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET); - nrf_ipc_event_t ipc_event = - nrf_ipc_receive_event_get(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET); - uint32_t task_ipc = nrf_ipc_task_address_get(NRF_IPC, ipc_task); - uint32_t evt_ipc = nrf_ipc_event_address_get(NRF_IPC, ipc_event); - uint32_t task_wdt = nrf_wdt_task_address_get(NRF_WDT, NRF_WDT_TASK_START); - uint32_t evt_mpsl_cc = nrf_rtc_event_address_get(NRF_RTC0, NRF_RTC_EVENT_COMPARE_3); - uint32_t evt_cc = nrf_rtc_event_address_get(NRF_RTC1, - NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); - uint32_t evt_overflow = nrf_rtc_event_address_get(NRF_RTC1, - NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); - - /* Configure Watchdog to allow stopping. */ - nrf_wdt_behaviour_set(NRF_WDT, WDT_CONFIG_STOPEN_Msk | BIT(4)); - *((volatile uint32_t *)0x41203120) = 0x14; - - /* Configure IPC */ - nrf_ipc_receive_config_set(NRF_IPC, CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET, - BIT(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET)); - nrf_ipc_send_config_set(NRF_IPC, CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET, - BIT(CONFIG_SOC_NRF53_RTC_PRETICK_IPC_CH_FROM_NET)); - - /* Allocate PPI channel for RTC Compare event publishers that starts WDT. */ - nrfx_err_t err = nrfx_gppi_channel_alloc(&ppi_ch); - - if (err != NRFX_SUCCESS) { - return -ENOMEM; - } - - /* Setup a PPI connection between RTC "pretick" events and IPC task. */ - if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE)) { - nrfx_gppi_event_endpoint_setup(ppi_ch, evt_mpsl_cc); - } - nrfx_gppi_event_endpoint_setup(ppi_ch, evt_cc); - nrfx_gppi_event_endpoint_setup(ppi_ch, evt_overflow); - nrfx_gppi_task_endpoint_setup(ppi_ch, task_ipc); - nrfx_gppi_event_endpoint_setup(ppi_ch, evt_ipc); - nrfx_gppi_task_endpoint_setup(ppi_ch, task_wdt); - nrfx_gppi_channels_enable(BIT(ppi_ch)); - - nrf_rtc_event_enable(NRF_RTC1, NRF_RTC_CHANNEL_INT_MASK(RTC1_PRETICK_CC_CHAN)); - nrf_rtc_event_enable(NRF_RTC1, NRF_RTC_CHANNEL_INT_MASK(RTC1_PRETICK_OVERFLOW_CHAN)); - - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_CC_CHAN)); - nrf_rtc_event_clear(NRF_RTC1, NRF_RTC_CHANNEL_EVENT_ADDR(RTC1_PRETICK_OVERFLOW_CHAN)); - /* Set event 1 tick before overflow. */ - nrf_rtc_cc_set(NRF_RTC1, RTC1_PRETICK_OVERFLOW_CHAN, 0x00FFFFFF); - - return 0; -} -#endif /* CONFIG_SOC_NRF5340_CPUNET */ - -static int rtc_pretick_init(void) -{ - ARG_UNUSED(unused); -#ifdef CONFIG_SOC_NRF5340_CPUAPP - return rtc_pretick_cpuapp_init(); -#else - return rtc_pretick_cpunet_init(); -#endif -} -#endif /* CONFIG_SOC_NRF53_RTC_PRETICK */ - - static int nordicsemi_nrf53_init(void) { #if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(CONFIG_NRF_ENABLE_CACHE) @@ -402,7 +242,3 @@ void arch_busy_wait(uint32_t time_us) } SYS_INIT(nordicsemi_nrf53_init, PRE_KERNEL_1, 0); - -#ifdef CONFIG_SOC_NRF53_RTC_PRETICK -SYS_INIT(rtc_pretick_init, POST_KERNEL, 0); -#endif From ebd2ab7acc23aca2871fe6dfe71ac6f64ecf2778 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:48 +0000 Subject: [PATCH 0863/1623] Revert "[nrf fromtree] logging: Unused arg in log_msg_get_tid" This reverts commit 1b5ab89ed6d031cea80269cb38a512800e46fb59. Signed-off-by: Dominik Ermel --- include/zephyr/logging/log_msg.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/zephyr/logging/log_msg.h b/include/zephyr/logging/log_msg.h index 0279fb0d2cd..4eee566bdc5 100644 --- a/include/zephyr/logging/log_msg.h +++ b/include/zephyr/logging/log_msg.h @@ -669,7 +669,6 @@ static inline void *log_msg_get_tid(struct log_msg *msg) #if CONFIG_LOG_THREAD_ID_PREFIX return msg->hdr.tid; #else - ARG_UNUSED(msg); return NULL; #endif } From 8f55883711c4eab59b75f06f0ad555dea1090341 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:48 +0000 Subject: [PATCH 0864/1623] Revert "[nrf fromtree] net: l2: wifi: Fix Wi-Fi mode get command bug" This reverts commit 9df3b459e3b507bccc1cbedc43617fdd56b98c93. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 9e521fcf028..f1c512304bf 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1302,7 +1302,7 @@ void parse_mode_args_to_params(const struct shell *sh, int argc, mode->mode |= WIFI_SOFTAP_MODE; break; case 'g': - mode->oper = WIFI_MGMT_GET; + mode->oper = true; break; case 'i': mode->if_index = (uint8_t)atoi(optarg); From 4fa650403eae5df1af00e7903738c3d264227153 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:49 +0000 Subject: [PATCH 0865/1623] Revert "[nrf fromtree] modules: openthread: radio: OT now uses standard TX timestamp" This reverts commit 0b79df6d821b2f77d65f80c5fe411ec15b273768. Signed-off-by: Dominik Ermel --- modules/openthread/CMakeLists.txt | 12 ------------ modules/openthread/Kconfig.features | 13 ------------- modules/openthread/platform/radio.c | 4 +++- tests/subsys/openthread/radio_test.c | 10 ++++++---- west.yml | 2 +- 5 files changed, 10 insertions(+), 31 deletions(-) diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index 83995aba72f..e32354bcc73 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -160,12 +160,6 @@ else() set(OT_DATASET_UPDATER OFF CACHE BOOL "Enable Dataset updater" FORCE) endif() -if(CONFIG_OPENTHREAD_DEVICE_PROP_LEADER_WEIGHT) - set(OT_DEVICE_PROP_LEADER_WEIGHT ON CACHE BOOL "Enable device props for leader weight" FORCE) -else() - set(OT_DEVICE_PROP_LEADER_WEIGHT OFF CACHE BOOL "Enable device props for leader weight" FORCE) -endif() - if(CONFIG_OPENTHREAD_DHCP6_CLIENT) set(OT_DHCP6_CLIENT ON CACHE BOOL "Enable DHCPv6 Client" FORCE) else() @@ -286,12 +280,6 @@ else() set(OT_LINK_METRICS_INITIATOR OFF CACHE BOOL "Enable Link Metrics initiator for Thread 1.2" FORCE) endif() -if(CONFIG_OPENTHREAD_LINK_METRICS_MANAGER) - set(OT_LINK_METRICS_MANAGER ON CACHE BOOL "Enable Link Metrics manager for Thread 1.2" FORCE) -else() - set(OT_LINK_METRICS_MANAGER OFF CACHE BOOL "Enable Link Metrics manager for Thread 1.2" FORCE) -endif() - if(CONFIG_OPENTHREAD_LINK_METRICS_SUBJECT) set(OT_LINK_METRICS_SUBJECT ON CACHE BOOL "Enable Link Metrics subject for Thread 1.2" FORCE) else() diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index cd57844370e..55256098487 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -96,16 +96,6 @@ config OPENTHREAD_CSL_RECEIVER help Enable CSL Receiver support for Thread 1.2 -config OPENTHREAD_DEVICE_PROP_LEADER_WEIGHT - bool "Device props for leader weight" - default n if (OPENTHREAD_THREAD_VERSION_1_1 || \ - OPENTHREAD_THREAD_VERSION_1_2 || \ - OPENTHREAD_THREAD_VERSION_1_3) - default y - help - Enable the device properties which are then used to determine and set - the Leader Weight. - config OPENTHREAD_DATASET_UPDATER bool "Dataset updater" @@ -179,9 +169,6 @@ config OPENTHREAD_LEGACY config OPENTHREAD_LINK_METRICS_INITIATOR bool "Link Metrics initiator" -config OPENTHREAD_LINK_METRICS_MANAGER - bool "Link Metrics manager" - config OPENTHREAD_LINK_METRICS_SUBJECT bool "Link Metrics subject" diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index e64e47a5fa9..36e74c6a225 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -58,6 +58,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_OPENTHREAD_L2_LOG_LEVEL); #define CHANNEL_COUNT OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MAX - OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MIN + 1 +#define PHY_SHR_DURATION 160 /* duration of SHR in us */ + enum pending_events { PENDING_EVENT_FRAME_TO_SEND, /* There is a tx frame to send */ PENDING_EVENT_FRAME_RECEIVED, /* Radio has received new frame */ @@ -395,7 +397,7 @@ void transmit_message(struct k_work *tx_job) (sTransmitFrame.mInfo.mTxInfo.mTxDelay != 0)) { #if defined(CONFIG_NET_PKT_TXTIME) uint32_t tx_at = sTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime + - sTransmitFrame.mInfo.mTxInfo.mTxDelay; + sTransmitFrame.mInfo.mTxInfo.mTxDelay + PHY_SHR_DURATION; struct net_ptp_time timestamp = ns_to_net_ptp_time(convert_32bit_us_wrapped_to_64bit_ns(tx_at)); net_pkt_set_timestamp(tx_pkt, ×tamp); diff --git a/tests/subsys/openthread/radio_test.c b/tests/subsys/openthread/radio_test.c index 87a7013a0d5..fb6c8755039 100644 --- a/tests/subsys/openthread/radio_test.c +++ b/tests/subsys/openthread/radio_test.c @@ -30,6 +30,8 @@ DEFINE_FFF_GLOBALS; #define FRAME_TYPE_MASK 0x07 #define FRAME_TYPE_ACK 0x02 +#define PHY_SHR_DURATION 160 + K_SEM_DEFINE(ot_sem, 0, 1); /** @@ -293,10 +295,10 @@ ZTEST(openthread_radio, test_tx_test) get_time_mock_fake.return_val = (int64_t)UINT32_MAX * NSEC_PER_USEC + 1000; frm->mInfo.mTxInfo.mTxDelayBaseTime = 3U; frm->mInfo.mTxInfo.mTxDelay = 5U; - expected_target_time = - get_time_mock_fake.return_val + - (frm->mInfo.mTxInfo.mTxDelayBaseTime + frm->mInfo.mTxInfo.mTxDelay) * - NSEC_PER_USEC; + expected_target_time = get_time_mock_fake.return_val + + (frm->mInfo.mTxInfo.mTxDelayBaseTime + + frm->mInfo.mTxInfo.mTxDelay + PHY_SHR_DURATION) * + NSEC_PER_USEC; } /* ACKed frame */ diff --git a/west.yml b/west.yml index bed3b47cfe5..b4f874a87c5 100644 --- a/west.yml +++ b/west.yml @@ -303,7 +303,7 @@ manifest: revision: 42b7c577714b8f22ce82a901e19c1814af4609a8 path: modules/lib/open-amp - name: openthread - revision: d62167ee34b091e7025c9ec2820aae71e17a3944 + revision: f7690fe7e9d638341921808cba6a3e695ec0131e path: modules/lib/openthread - name: picolibc path: modules/lib/picolibc From 6ce6260ed1a6012957736dc2a45d98a304f0320f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:49 +0000 Subject: [PATCH 0866/1623] Revert "[nrf fromtree] Bluetooth: ASCS: Modify the ACL disconnect behavior" This reverts commit 71c7ace4d8da9c5e88b729e3f1dabde5f330f184. Signed-off-by: Dominik Ermel --- subsys/bluetooth/audio/ascs.c | 14 +------------- tests/bluetooth/audio/ascs/src/main.c | 4 ++++ tests/bluetooth/audio/mocks/src/kernel.c | 7 ------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index d85a90ec77a..9b45754fe90 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -119,8 +119,6 @@ static void ase_free(struct bt_ascs_ase *ase) bt_conn_unref(ase->conn); ase->conn = NULL; - - (void)k_work_cancel(&ase->state_transition_work); } static void ase_status_changed(struct bt_ascs_ase *ase, uint8_t state) @@ -1096,17 +1094,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) } if (ase->ep.status.state != BT_BAP_EP_STATE_IDLE) { - /* We must set the state to idle when the ACL is disconnected immediately, - * as when the ACL disconnect callbacks have been called, the application - * should expect there to be only a single reference to the bt_conn pointer - * from the stack. - * We trigger the work handler directly rather than e.g. calling - * ase_set_state_idle to trigger "regular" state change behavior (such) as - * calling stream->stopped when leaving the streaming state. - */ - ase->ep.reason = reason; - ase->state_pending = BT_BAP_EP_STATE_IDLE; - state_transition_work_handler(&ase->state_transition_work); + ase_release(ase, reason, BT_BAP_ASCS_RSP_NULL); /* At this point, `ase` object have been free'd */ } } diff --git a/tests/bluetooth/audio/ascs/src/main.c b/tests/bluetooth/audio/ascs/src/main.c index 126c82d63bb..b0bc7f88150 100644 --- a/tests/bluetooth/audio/ascs/src/main.c +++ b/tests/bluetooth/audio/ascs/src/main.c @@ -250,6 +250,7 @@ ZTEST_F(ascs_test_suite, test_release_ase_on_acl_disconnection_client_terminates mock_bt_iso_disconnected(chan, BT_HCI_ERR_REMOTE_USER_TERM_CONN); /* Expected to notify the upper layers */ + expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_released_called_once(stream); bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); @@ -287,6 +288,7 @@ ZTEST_F(ascs_test_suite, test_release_ase_on_acl_disconnection_server_terminates k_sleep(K_MSEC(CONFIG_BT_ASCS_ISO_DISCONNECT_DELAY)); /* Expected to notify the upper layers */ + expect_bt_bap_unicast_server_cb_release_called_once(stream); expect_bt_bap_stream_ops_released_called_once(stream); bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); @@ -349,6 +351,7 @@ ZTEST_F(ascs_test_suite, test_release_stream_pair_on_acl_disconnection_client_te const struct bt_bap_stream *streams[2] = { &snk_stream, &src_stream }; expect_bt_bap_stream_ops_released_called_twice(streams); + expect_bt_bap_unicast_server_cb_release_called_twice(streams); bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); } @@ -410,6 +413,7 @@ ZTEST_F(ascs_test_suite, test_release_stream_pair_on_acl_disconnection_server_te const struct bt_bap_stream *streams[2] = { &snk_stream, &src_stream }; expect_bt_bap_stream_ops_released_called_twice(streams); + expect_bt_bap_unicast_server_cb_release_called_twice(streams); bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); } diff --git a/tests/bluetooth/audio/mocks/src/kernel.c b/tests/bluetooth/audio/mocks/src/kernel.c index 03dc2cf582d..ce9dcab5d3a 100644 --- a/tests/bluetooth/audio/mocks/src/kernel.c +++ b/tests/bluetooth/audio/mocks/src/kernel.c @@ -56,13 +56,6 @@ int k_work_cancel_delayable(struct k_work_delayable *dwork) return 0; } -int k_work_cancel(struct k_work *work) -{ - (void)sys_slist_find_and_remove(&work_pending, &work->node); - - return 0; -} - void k_work_init(struct k_work *work, k_work_handler_t handler) { work->handler = handler; From efdcfd8b6b5417aeeaa87101217a6de5c14898af Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:49 +0000 Subject: [PATCH 0867/1623] Revert "[nrf fromtree] tests: bsim: Bluetooth: Add BAP unicast disconnect test" This reverts commit 44ae4b554d43483324be575a189a4640a98437b6. Signed-off-by: Dominik Ermel --- tests/bsim/bluetooth/audio/prj.conf | 5 +- .../audio/src/bap_unicast_client_test.c | 149 +------------ .../audio/src/bap_unicast_server_test.c | 201 +++++------------- .../bap_unicast_audio_acl_disconnect.sh | 27 --- 4 files changed, 54 insertions(+), 328 deletions(-) delete mode 100755 tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio_acl_disconnect.sh diff --git a/tests/bsim/bluetooth/audio/prj.conf b/tests/bsim/bluetooth/audio/prj.conf index 8f2d6a585a9..2077143452b 100644 --- a/tests/bsim/bluetooth/audio/prj.conf +++ b/tests/bsim/bluetooth/audio/prj.conf @@ -9,9 +9,8 @@ CONFIG_BT_DEVICE_NAME="bsim_test_audio" # TBS Client may require up to 12 buffers CONFIG_BT_L2CAP_TX_BUF_COUNT=12 CONFIG_BT_ATT_PREPARE_COUNT=5 -CONFIG_BT_MAX_CONN=3 -CONFIG_BT_MAX_PAIRED=3 -CONFIG_BT_EXT_ADV_MAX_ADV_SET=3 +CONFIG_BT_MAX_CONN=5 +CONFIG_BT_MAX_PAIRED=5 CONFIG_BT_GATT_DYNAMIC_DB=y CONFIG_BT_SMP=y CONFIG_BT_L2CAP_TX_MTU=100 diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c index 3fbd70458b9..72aa1cfcd96 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c @@ -306,92 +306,6 @@ static struct bt_gatt_cb gatt_callbacks = { .att_mtu_updated = att_mtu_updated, }; -static bool parse_ascs_ad_data(struct bt_data *data, void *user_data) -{ - const struct bt_le_scan_recv_info *info = user_data; - uint16_t available_source_context; - uint16_t available_sink_context; - struct net_buf_simple net_buf; - struct bt_uuid_16 adv_uuid; - uint8_t announcement_type; - void *uuid; - int err; - - const size_t min_data_len = BT_UUID_SIZE_16 + sizeof(announcement_type) + - sizeof(available_sink_context) + - sizeof(available_source_context); - - if (data->type != BT_DATA_SVC_DATA16) { - return true; - } - - if (data->data_len < min_data_len) { - - return true; - } - - net_buf_simple_init_with_data(&net_buf, (void *)data->data, data->data_len); - - uuid = net_buf_simple_pull_mem(&net_buf, BT_UUID_SIZE_16); - if (!bt_uuid_create(&adv_uuid.uuid, uuid, BT_UUID_SIZE_16)) { - return true; - } - - if (bt_uuid_cmp(&adv_uuid.uuid, BT_UUID_ASCS)) { - return true; - } - - announcement_type = net_buf_simple_pull_u8(&net_buf); - available_sink_context = net_buf_simple_pull_le16(&net_buf); - available_source_context = net_buf_simple_pull_le16(&net_buf); - - printk("Found ASCS with announcement type 0x%02X, sink ctx 0x%04X, source ctx 0x%04X\n", - announcement_type, available_sink_context, available_source_context); - - printk("Stopping scan\n"); - if (bt_le_scan_stop()) { - FAIL("Could not stop scan"); - return false; - } - - err = bt_conn_le_create(info->addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, - &default_conn); - if (err) { - FAIL("Could not connect to peer: %d", err); - return false; - } - - /* Stop parsing */ - return false; -} - -static void broadcast_scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - - if (default_conn) { - return; - } - - /* We're only interested in connectable events */ - if ((info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) == 0) { - return; - } - /* connect only to devices in close proximity */ - if (info->rssi < -70) { - return; - } - - bt_addr_le_to_str(info->addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, info->rssi); - - bt_data_parse(ad, parse_ascs_ad_data, (void *)info); -} - -static struct bt_le_scan_cb bap_scan_cb = { - .recv = broadcast_scan_recv, -}; - static void init(void) { int err; @@ -406,7 +320,7 @@ static void init(void) g_streams[i].ops = &stream_ops; } - bt_le_scan_cb_register(&bap_scan_cb); + bt_le_scan_cb_register(&common_scan_cb); bt_gatt_cb_register(&gatt_callbacks); err = bt_bap_unicast_client_register_cb(&unicast_client_cbs); @@ -853,71 +767,14 @@ static void test_main(void) PASS("Unicast client passed\n"); } -static void test_main_acl_disconnect(void) -{ - struct bt_bap_unicast_group *unicast_group; - size_t stream_cnt; - - init(); - - scan_and_connect(); - - exchange_mtu(); - - discover_sinks(); - - discover_sources(); - - /* Run the stream setup multiple time to ensure states are properly - * set and reset - */ - - printk("Creating unicast group\n"); - stream_cnt = create_unicast_group(&unicast_group); - - printk("Codec configuring streams\n"); - codec_configure_streams(stream_cnt); - - printk("QoS configuring streams\n"); - qos_configure_streams(unicast_group, stream_cnt); - - printk("Enabling streams\n"); - enable_streams(stream_cnt); - - printk("Metadata update streams\n"); - metadata_update_streams(stream_cnt); - - printk("Starting streams\n"); - start_streams(); - - disconnect_acl(); - - printk("Deleting unicast group\n"); - delete_unicast_group(unicast_group); - unicast_group = NULL; - - /* Reconnect */ - scan_and_connect(); - - disconnect_acl(); - - PASS("Unicast client ACL disconnect passed\n"); -} - static const struct bst_test_instance test_unicast_client[] = { { .test_id = "unicast_client", .test_post_init_f = test_init, .test_tick_f = test_tick, - .test_main_f = test_main, - }, - { - .test_id = "unicast_client_acl_disconnect", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_acl_disconnect, + .test_main_f = test_main }, - BSTEST_END_MARKER, + BSTEST_END_MARKER }; struct bst_test_list *test_unicast_client_install(struct bst_test_list *tests) diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c index 58acdc1726c..c302ec320ab 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c @@ -48,20 +48,11 @@ static struct bt_bap_stream streams[CONFIG_BT_ASCS_ASE_SNK_COUNT + CONFIG_BT_ASC static const struct bt_audio_codec_qos_pref qos_pref = BT_AUDIO_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, 0x02, 10, 40000, 40000, 40000, 40000); -static uint8_t unicast_server_addata[] = { - BT_UUID_16_ENCODE(BT_UUID_ASCS_VAL), /* ASCS UUID */ - BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED, /* Target Announcement */ - BT_BYTES_LIST_LE16(PREF_CONTEXT), - BT_BYTES_LIST_LE16(PREF_CONTEXT), - 0x00, /* Metadata length */ -}; - +/* TODO: Expand with BAP data */ static const struct bt_data unicast_server_ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_ASCS_VAL)), - BT_DATA(BT_DATA_SVC_DATA16, unicast_server_addata, ARRAY_SIZE(unicast_server_addata)), }; -static struct bt_le_ext_adv *ext_adv; CREATE_FLAG(flag_stream_configured); @@ -239,6 +230,47 @@ static struct bt_bap_stream_ops stream_ops = { .recv = stream_recv }; +static void init(void) +{ + static struct bt_pacs_cap cap = { + .codec_cap = &lc3_codec_cap, + }; + int err; + + err = bt_enable(NULL); + if (err != 0) { + FAIL("Bluetooth enable failed (err %d)\n", err); + return; + } + + printk("Bluetooth initialized\n"); + + bt_bap_unicast_server_register_cb(&unicast_server_cb); + + err = bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &cap); + if (err != 0) { + FAIL("Failed to register capabilities: %d", err); + return; + } + + err = bt_pacs_cap_register(BT_AUDIO_DIR_SOURCE, &cap); + if (err != 0) { + FAIL("Failed to register capabilities: %d", err); + return; + } + + for (size_t i = 0; i < ARRAY_SIZE(streams); i++) { + bt_bap_stream_cb_register(&streams[i], &stream_ops); + } + + err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, unicast_server_ad, ARRAY_SIZE(unicast_server_ad), + NULL, 0); + if (err != 0) { + FAIL("Advertising failed to start (err %d)\n", err); + return; + } +} + static void set_location(void) { int err; @@ -300,160 +332,25 @@ static void set_available_contexts(void) printk("Available contexts successfully set\n"); } -static void init(void) +static void test_main(void) { - static struct bt_pacs_cap cap = { - .codec_cap = &lc3_codec_cap, - }; - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth enable failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - bt_bap_unicast_server_register_cb(&unicast_server_cb); - - err = bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &cap); - if (err != 0) { - FAIL("Failed to register capabilities: %d", err); - return; - } - - err = bt_pacs_cap_register(BT_AUDIO_DIR_SOURCE, &cap); - if (err != 0) { - FAIL("Failed to register capabilities: %d", err); - return; - } + init(); set_location(); set_available_contexts(); - for (size_t i = 0; i < ARRAY_SIZE(streams); i++) { - bt_bap_stream_cb_register(&streams[i], &stream_ops); - } - - /* Create a non-connectable non-scannable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_NAME, NULL, &ext_adv); - if (err != 0) { - FAIL("Failed to create advertising set (err %d)\n", err); - return; - } - - err = bt_le_ext_adv_set_data(ext_adv, unicast_server_ad, ARRAY_SIZE(unicast_server_ad), - NULL, 0); - if (err != 0) { - FAIL("Failed to set advertising data (err %d)\n", err); - return; - } - - err = bt_le_ext_adv_start(ext_adv, BT_LE_EXT_ADV_START_DEFAULT); - if (err != 0) { - FAIL("Failed to start advertising set (err %d)\n", err); - return; - } - printk("Advertising started\n"); -} - -static void test_main(void) -{ - init(); - /* TODO: When babblesim supports ISO, wait for audio stream to pass */ WAIT_FOR_FLAG(flag_connected); WAIT_FOR_FLAG(flag_stream_configured); - - WAIT_FOR_UNSET_FLAG(flag_connected); - PASS("Unicast server passed\n"); } -static void restart_adv_cb(struct k_work *work) -{ - int err; - - printk("Restarting ext_adv after disconnect\n"); - - err = bt_le_ext_adv_start(ext_adv, BT_LE_EXT_ADV_START_DEFAULT); - if (err != 0) { - FAIL("Failed to start advertising set (err %d)\n", err); - return; - } -} - -static K_WORK_DEFINE(restart_adv_work, restart_adv_cb); - -static void acl_disconnected(struct bt_conn *conn, uint8_t reason) -{ - if (conn != default_conn) { - return; - } - - k_work_submit(&restart_adv_work); -} - -static void test_main_acl_disconnect(void) -{ - struct bt_le_ext_adv *dummy_ext_adv[CONFIG_BT_MAX_CONN - 1]; - static struct bt_conn_cb conn_callbacks = { - .disconnected = acl_disconnected, - }; - - init(); - - /* Create CONFIG_BT_MAX_CONN - 1 dummy advertising sets, to ensure that we only have 1 free - * connection when attempting to restart advertising, which should ensure that the - * bt_conn object is properly unref'ed by the stack - */ - for (size_t i = 0U; i < ARRAY_SIZE(dummy_ext_adv); i++) { - const struct bt_le_adv_param param = BT_LE_ADV_PARAM_INIT( - (BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CONNECTABLE), - BT_GAP_ADV_SLOW_INT_MAX, BT_GAP_ADV_SLOW_INT_MAX, NULL); - int err; - - err = bt_le_ext_adv_create(¶m, NULL, &dummy_ext_adv[i]); - if (err != 0) { - FAIL("Failed to create advertising set[%zu] (err %d)\n", i, err); - return; - } - - err = bt_le_ext_adv_start(dummy_ext_adv[i], BT_LE_EXT_ADV_START_DEFAULT); - if (err != 0) { - FAIL("Failed to start advertising set[%zu] (err %d)\n", i, err); - return; - } - } - - bt_conn_cb_register(&conn_callbacks); - - WAIT_FOR_FLAG(flag_connected); - WAIT_FOR_FLAG(flag_stream_configured); - - /* The client will reconnect */ - WAIT_FOR_UNSET_FLAG(flag_connected); - WAIT_FOR_FLAG(flag_connected); - PASS("Unicast server ACL disconnect passed\n"); -} - -static const struct bst_test_instance test_unicast_server[] = { - { - .test_id = "unicast_server", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main, - }, - { - .test_id = "unicast_server_acl_disconnect", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_acl_disconnect, - }, - BSTEST_END_MARKER, -}; +static const struct bst_test_instance test_unicast_server[] = {{.test_id = "unicast_server", + .test_post_init_f = test_init, + .test_tick_f = test_tick, + .test_main_f = test_main}, + BSTEST_END_MARKER}; struct bst_test_list *test_unicast_server_install(struct bst_test_list *tests) { diff --git a/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio_acl_disconnect.sh b/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio_acl_disconnect.sh deleted file mode 100755 index 875a2b752dc..00000000000 --- a/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio_acl_disconnect.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2023 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="unicast_audio_acl_disconnect" -VERBOSITY_LEVEL=2 -EXECUTE_TIMEOUT=20 - -source ${ZEPHYR_BASE}/tests/bsim/sh_common.source - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n======== Unicast Audio ACL Disconnect test =========\n\n" - -Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=unicast_client_acl_disconnect -rs=23 - -Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=unicast_server_acl_disconnect -rs=28 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -wait_for_background_jobs From 66a516ec4a5d3b49ff9f591846af5f6ef6756211 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:49 +0000 Subject: [PATCH 0868/1623] Revert "[nrf fromtree] tests: Bluetooth: Audio: Modify bsim tests to use bt_le_scan_cb_register" This reverts commit 83e1ffa903da471f7d065edfeb59c990b695ae25. Signed-off-by: Dominik Ermel --- .../audio/src/bap_broadcast_assistant_test.c | 3 +-- .../audio/src/bap_unicast_client_test.c | 17 +---------------- tests/bsim/bluetooth/audio/src/common.c | 19 ++++++++----------- tests/bsim/bluetooth/audio/src/common.h | 3 ++- .../bluetooth/audio/src/has_client_test.c | 4 +--- .../bluetooth/audio/src/ias_client_test.c | 4 +--- tests/bsim/bluetooth/audio/src/mcc_test.c | 4 +--- .../audio/src/media_controller_test.c | 4 +--- .../bluetooth/audio/src/micp_mic_ctlr_test.c | 4 +--- .../audio/src/pacs_notify_client_test.c | 6 ++---- tests/bsim/bluetooth/audio/src/tbs_test.c | 3 +-- .../bluetooth/audio/src/vcp_vol_ctlr_test.c | 3 +-- 12 files changed, 21 insertions(+), 53 deletions(-) diff --git a/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c b/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c index 9964bd29c0a..381810d68db 100644 --- a/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c @@ -490,10 +490,9 @@ static int common_init(void) bt_gatt_cb_register(&gatt_callbacks); bt_bap_broadcast_assistant_register_cb(&broadcast_assistant_cbs); bt_le_per_adv_sync_cb_register(&sync_callbacks); - bt_le_scan_cb_register(&common_scan_cb); printk("Starting scan\n"); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return err; diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c index 72aa1cfcd96..e31c092684a 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c @@ -320,7 +320,6 @@ static void init(void) g_streams[i].ops = &stream_ops; } - bt_le_scan_cb_register(&common_scan_cb); bt_gatt_cb_register(&gatt_callbacks); err = bt_bap_unicast_client_register_cb(&unicast_client_cbs); @@ -334,7 +333,7 @@ static void scan_and_connect(void) { int err; - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return; @@ -344,19 +343,6 @@ static void scan_and_connect(void) WAIT_FOR_FLAG(flag_connected); } -static void disconnect_acl(void) -{ - int err; - - err = bt_conn_disconnect(default_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - if (err != 0) { - FAIL("Failed to disconnect (err %d)\n", err); - return; - } - - WAIT_FOR_UNSET_FLAG(flag_connected); -} - static void exchange_mtu(void) { WAIT_FOR_FLAG(flag_mtu_exchanged); @@ -762,7 +748,6 @@ static void test_main(void) unicast_group = NULL; } - disconnect_acl(); PASS("Unicast client passed\n"); } diff --git a/tests/bsim/bluetooth/audio/src/common.c b/tests/bsim/bluetooth/audio/src/common.c index 90a8cb98efa..30758e01732 100644 --- a/tests/bsim/bluetooth/audio/src/common.c +++ b/tests/bsim/bluetooth/audio/src/common.c @@ -16,7 +16,8 @@ const struct bt_data ad[AD_SIZE] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)) }; -static void device_found(const struct bt_le_scan_recv_info *info, struct net_buf_simple *ad) +void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, + struct net_buf_simple *ad) { char addr_str[BT_ADDR_LE_STR_LEN]; int err; @@ -26,15 +27,15 @@ static void device_found(const struct bt_le_scan_recv_info *info, struct net_buf } /* We're only interested in connectable events */ - if ((info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) == 0) { + if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { return; } - bt_addr_le_to_str(info->addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, info->rssi); + bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); + printk("Device found: %s (RSSI %d)\n", addr_str, rssi); /* connect only to devices in close proximity */ - if (info->rssi < -70) { + if (rssi < -70) { FAIL("RSSI too low"); return; } @@ -45,17 +46,13 @@ static void device_found(const struct bt_le_scan_recv_info *info, struct net_buf return; } - err = bt_conn_le_create(info->addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, - &default_conn); + err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, + BT_LE_CONN_PARAM_DEFAULT, &default_conn); if (err) { FAIL("Could not connect to peer: %d", err); } } -struct bt_le_scan_cb common_scan_cb = { - .recv = device_found, -}; - static void connected(struct bt_conn *conn, uint8_t err) { char addr[BT_ADDR_LE_STR_LEN]; diff --git a/tests/bsim/bluetooth/audio/src/common.h b/tests/bsim/bluetooth/audio/src/common.h index 14d6dbbc092..917a024b724 100644 --- a/tests/bsim/bluetooth/audio/src/common.h +++ b/tests/bsim/bluetooth/audio/src/common.h @@ -65,12 +65,13 @@ #define SYNC_RETRY_COUNT 6 /* similar to retries for connections */ #define PA_SYNC_SKIP 5 -extern struct bt_le_scan_cb common_scan_cb; extern const struct bt_data ad[AD_SIZE]; extern struct bt_conn *default_conn; extern atomic_t flag_connected; extern atomic_t flag_conn_updated; +void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, + struct net_buf_simple *ad); void disconnected(struct bt_conn *conn, uint8_t reason); void test_tick(bs_time_t HW_device_time); void test_init(void); diff --git a/tests/bsim/bluetooth/audio/src/has_client_test.c b/tests/bsim/bluetooth/audio/src/has_client_test.c index 6690c6b032e..9d63463e0ce 100644 --- a/tests/bsim/bluetooth/audio/src/has_client_test.c +++ b/tests/bsim/bluetooth/audio/src/has_client_test.c @@ -157,9 +157,7 @@ static void test_main(void) return; } - bt_le_scan_cb_register(&common_scan_cb); - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err < 0) { FAIL("Scanning failed to start (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/ias_client_test.c b/tests/bsim/bluetooth/audio/src/ias_client_test.c index 7c24b1a172a..2c5dbd40bd0 100644 --- a/tests/bsim/bluetooth/audio/src/ias_client_test.c +++ b/tests/bsim/bluetooth/audio/src/ias_client_test.c @@ -83,9 +83,7 @@ static void test_main(void) return; } - bt_le_scan_cb_register(&common_scan_cb); - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err < 0) { FAIL("Scanning failed to start (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/mcc_test.c b/tests/bsim/bluetooth/audio/src/mcc_test.c index 9e8cd95806b..8a32e33bf16 100644 --- a/tests/bsim/bluetooth/audio/src/mcc_test.c +++ b/tests/bsim/bluetooth/audio/src/mcc_test.c @@ -2396,8 +2396,6 @@ void test_main(void) printk("Bluetooth initialized\n"); - bt_le_scan_cb_register(&common_scan_cb); - /* Initialize MCC ********************************************/ err = do_mcc_init(); if (err != 0) { @@ -2416,7 +2414,7 @@ void test_main(void) printk("\n########### Running iteration #%u\n\n", i); UNSET_FLAG(flag_connected); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err != 0) { FAIL("Failed to start scanning (err %d\n)", err); } else { diff --git a/tests/bsim/bluetooth/audio/src/media_controller_test.c b/tests/bsim/bluetooth/audio/src/media_controller_test.c index ad91cffb939..9c1df656fd1 100644 --- a/tests/bsim/bluetooth/audio/src/media_controller_test.c +++ b/tests/bsim/bluetooth/audio/src/media_controller_test.c @@ -1585,8 +1585,6 @@ void initialize_bluetooth(void) WAIT_FOR_FLAG(ble_is_initialized); printk("Bluetooth initialized\n"); - - bt_le_scan_cb_register(&common_scan_cb); } void scan_and_connect(void) @@ -1594,7 +1592,7 @@ void scan_and_connect(void) char addr[BT_ADDR_LE_STR_LEN]; int err; - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err) { FAIL("Failed to start scanning (err %d\n)", err); return; diff --git a/tests/bsim/bluetooth/audio/src/micp_mic_ctlr_test.c b/tests/bsim/bluetooth/audio/src/micp_mic_ctlr_test.c index 5cefd31d099..1074c8c2cef 100644 --- a/tests/bsim/bluetooth/audio/src/micp_mic_ctlr_test.c +++ b/tests/bsim/bluetooth/audio/src/micp_mic_ctlr_test.c @@ -357,13 +357,11 @@ static void test_main(void) return; } - bt_le_scan_cb_register(&common_scan_cb); - bt_micp_mic_ctlr_cb_register(&micp_mic_ctlr_cbs); WAIT_FOR_COND(g_bt_init); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/pacs_notify_client_test.c b/tests/bsim/bluetooth/audio/src/pacs_notify_client_test.c index 9910f6f2c8c..7cbe5feaa22 100644 --- a/tests/bsim/bluetooth/audio/src/pacs_notify_client_test.c +++ b/tests/bsim/bluetooth/audio/src/pacs_notify_client_test.c @@ -490,10 +490,8 @@ static void test_main(void) return; } - bt_le_scan_cb_register(&common_scan_cb); - printk("Starting scan\n"); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err != 0) { FAIL("Could not start scanning (err %d)\n", err); return; @@ -538,7 +536,7 @@ static void test_main(void) WAIT_FOR_UNSET_FLAG(flag_connected); printk("Starting scan\n"); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err != 0) { FAIL("Could not start scanning (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/tbs_test.c b/tests/bsim/bluetooth/audio/src/tbs_test.c index a1bf1e035c0..b20dca26608 100644 --- a/tests/bsim/bluetooth/audio/src/tbs_test.c +++ b/tests/bsim/bluetooth/audio/src/tbs_test.c @@ -331,10 +331,9 @@ static void test_main(void) printk("Audio Client: Bluetooth initialized\n"); bt_conn_cb_register(&conn_callbacks); - bt_le_scan_cb_register(&common_scan_cb); bt_tbs_register_cb(&tbs_cbs); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return; diff --git a/tests/bsim/bluetooth/audio/src/vcp_vol_ctlr_test.c b/tests/bsim/bluetooth/audio/src/vcp_vol_ctlr_test.c index 77feaa4bfb5..52ba2f072ab 100644 --- a/tests/bsim/bluetooth/audio/src/vcp_vol_ctlr_test.c +++ b/tests/bsim/bluetooth/audio/src/vcp_vol_ctlr_test.c @@ -1153,10 +1153,9 @@ static void test_main(void) return; } - bt_le_scan_cb_register(&common_scan_cb); test_cb_register(); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err != 0) { FAIL("Scanning failed to start (err %d)\n", err); return; From 5afd86d5626acd370af73d32fdc4e1b909ddb169 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:49 +0000 Subject: [PATCH 0869/1623] Revert "[nrf fromtree] drivers: serial: uart_nrfx_uarte: coexisting async and interrupt API" This reverts commit c606de126612153b2c036b730d66ec622c88aec9. Signed-off-by: Dominik Ermel --- drivers/serial/uart_nrfx_uarte.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index 017efa6a2e5..bdafe6c7d4c 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -937,6 +937,11 @@ static int uarte_nrfx_callback_set(const struct device *dev, data->async->user_callback = callback; data->async->user_data = user_data; +#if defined(CONFIG_UART_EXCLUSIVE_API_CALLBACKS) && defined(UARTE_INTERRUPT_DRIVEN) + data->int_driven->cb = NULL; + data->int_driven->cb_data = NULL; +#endif + return 0; } @@ -1675,6 +1680,11 @@ static void uarte_nrfx_irq_callback_set(const struct device *dev, data->int_driven->cb = cb; data->int_driven->cb_data = cb_data; + +#if defined(UARTE_ANY_ASYNC) && defined(CONFIG_UART_EXCLUSIVE_API_CALLBACKS) + data->async->user_callback = NULL; + data->async->user_data = NULL; +#endif } #endif /* UARTE_INTERRUPT_DRIVEN */ From df448f82e8f0d45f57262828669e597971f82695 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:50 +0000 Subject: [PATCH 0870/1623] Revert "[nrf fromtree] mgmt: mcumgr: Split mgmt defines to new file" This reverts commit b0cfad5a121d46969e682eb77ea91b1a2720960d. Signed-off-by: Dominik Ermel --- include/zephyr/mgmt/mcumgr/mgmt/mgmt.h | 119 +++++++++++++- .../zephyr/mgmt/mcumgr/mgmt/mgmt_defines.h | 150 ------------------ 2 files changed, 118 insertions(+), 151 deletions(-) delete mode 100644 include/zephyr/mgmt/mcumgr/mgmt/mgmt_defines.h diff --git a/include/zephyr/mgmt/mcumgr/mgmt/mgmt.h b/include/zephyr/mgmt/mcumgr/mgmt/mgmt.h index e681ea2b939..eb9ecfcf2a9 100644 --- a/include/zephyr/mgmt/mcumgr/mgmt/mgmt.h +++ b/include/zephyr/mgmt/mcumgr/mgmt/mgmt.h @@ -11,7 +11,6 @@ #include #include #include -#include #ifdef __cplusplus extern "C" { @@ -24,6 +23,124 @@ extern "C" { * @{ */ +/** + * Used at end of MCUmgr handlers to return an error if the message size limit was reached, + * or OK if it was not + */ +#define MGMT_RETURN_CHECK(ok) ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE + +/** Opcodes; encoded in first byte of header. */ +enum mcumgr_op_t { + /** Read op-code */ + MGMT_OP_READ = 0, + + /** Read response op-code */ + MGMT_OP_READ_RSP, + + /** Write op-code */ + MGMT_OP_WRITE, + + /** Write response op-code */ + MGMT_OP_WRITE_RSP, +}; + +/** + * MCUmgr groups. The first 64 groups are reserved for system level mcumgr + * commands. Per-user commands are then defined after group 64. + */ +enum mcumgr_group_t { + /** OS (operating system) group */ + MGMT_GROUP_ID_OS = 0, + + /** Image management group, used for uploading firmware images */ + MGMT_GROUP_ID_IMAGE, + + /** Statistic management group, used for retieving statistics */ + MGMT_GROUP_ID_STAT, + + /** Settings management (config) group, used for reading/writing settings */ + MGMT_GROUP_ID_SETTINGS, + + /** Log management group (unused) */ + MGMT_GROUP_ID_LOG, + + /** Crash group (unused) */ + MGMT_GROUP_ID_CRASH, + + /** Split image management group (unused) */ + MGMT_GROUP_ID_SPLIT, + + /** Run group (unused) */ + MGMT_GROUP_ID_RUN, + + /** FS (file system) group, used for performing file IO operations */ + MGMT_GROUP_ID_FS, + + /** Shell management group, used for executing shell commands */ + MGMT_GROUP_ID_SHELL, + + /** User groups defined from 64 onwards */ + MGMT_GROUP_ID_PERUSER = 64, + + /** Zephyr-specific groups decrease from PERUSER to avoid collision with upstream and + * user-defined groups. + * Zephyr-specific: Basic group + */ + ZEPHYR_MGMT_GRP_BASIC = (MGMT_GROUP_ID_PERUSER - 1), +}; + +/** + * MCUmgr error codes. + */ +enum mcumgr_err_t { + /** No error (success). */ + MGMT_ERR_EOK = 0, + + /** Unknown error. */ + MGMT_ERR_EUNKNOWN, + + /** Insufficient memory (likely not enough space for CBOR object). */ + MGMT_ERR_ENOMEM, + + /** Error in input value. */ + MGMT_ERR_EINVAL, + + /** Operation timed out. */ + MGMT_ERR_ETIMEOUT, + + /** No such file/entry. */ + MGMT_ERR_ENOENT, + + /** Current state disallows command. */ + MGMT_ERR_EBADSTATE, + + /** Response too large. */ + MGMT_ERR_EMSGSIZE, + + /** Command not supported. */ + MGMT_ERR_ENOTSUP, + + /** Corrupt */ + MGMT_ERR_ECORRUPT, + + /** Command blocked by processing of other command */ + MGMT_ERR_EBUSY, + + /** Access to specific function, command or resource denied */ + MGMT_ERR_EACCESSDENIED, + + /** Requested SMP MCUmgr protocol version is not supported (too old) */ + MGMT_ERR_UNSUPPORTED_TOO_OLD, + + /** Requested SMP MCUmgr protocol version is not supported (too new) */ + MGMT_ERR_UNSUPPORTED_TOO_NEW, + + /** User errors defined from 256 onwards */ + MGMT_ERR_EPERUSER = 256 +}; + +#define MGMT_HDR_SIZE 8 + /** @typedef mgmt_alloc_rsp_fn * @brief Allocates a buffer suitable for holding a response. * diff --git a/include/zephyr/mgmt/mcumgr/mgmt/mgmt_defines.h b/include/zephyr/mgmt/mcumgr/mgmt/mgmt_defines.h deleted file mode 100644 index 2f33b6d22a1..00000000000 --- a/include/zephyr/mgmt/mcumgr/mgmt/mgmt_defines.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2018-2021 mcumgr authors - * Copyright (c) 2022-2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef H_MGMT_MGMT_DEFINES_ -#define H_MGMT_MGMT_DEFINES_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief MCUmgr mgmt API - * @defgroup mcumgr_mgmt_api MCUmgr mgmt API - * @ingroup mcumgr - * @{ - */ - -/** - * Used at end of MCUmgr handlers to return an error if the message size limit was reached, - * or OK if it was not - */ -#define MGMT_RETURN_CHECK(ok) ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE - -/** Opcodes; encoded in first byte of header. */ -enum mcumgr_op_t { - /** Read op-code */ - MGMT_OP_READ = 0, - - /** Read response op-code */ - MGMT_OP_READ_RSP, - - /** Write op-code */ - MGMT_OP_WRITE, - - /** Write response op-code */ - MGMT_OP_WRITE_RSP, -}; - -/** - * MCUmgr groups. The first 64 groups are reserved for system level mcumgr - * commands. Per-user commands are then defined after group 64. - */ -enum mcumgr_group_t { - /** OS (operating system) group */ - MGMT_GROUP_ID_OS = 0, - - /** Image management group, used for uploading firmware images */ - MGMT_GROUP_ID_IMAGE, - - /** Statistic management group, used for retieving statistics */ - MGMT_GROUP_ID_STAT, - - /** Settings management (config) group, used for reading/writing settings */ - MGMT_GROUP_ID_SETTINGS, - - /** Log management group (unused) */ - MGMT_GROUP_ID_LOG, - - /** Crash group (unused) */ - MGMT_GROUP_ID_CRASH, - - /** Split image management group (unused) */ - MGMT_GROUP_ID_SPLIT, - - /** Run group (unused) */ - MGMT_GROUP_ID_RUN, - - /** FS (file system) group, used for performing file IO operations */ - MGMT_GROUP_ID_FS, - - /** Shell management group, used for executing shell commands */ - MGMT_GROUP_ID_SHELL, - - /** User groups defined from 64 onwards */ - MGMT_GROUP_ID_PERUSER = 64, - - /** Zephyr-specific groups decrease from PERUSER to avoid collision with upstream and - * user-defined groups. - * Zephyr-specific: Basic group - */ - ZEPHYR_MGMT_GRP_BASIC = (MGMT_GROUP_ID_PERUSER - 1), -}; - -/** - * MCUmgr error codes. - */ -enum mcumgr_err_t { - /** No error (success). */ - MGMT_ERR_EOK = 0, - - /** Unknown error. */ - MGMT_ERR_EUNKNOWN, - - /** Insufficient memory (likely not enough space for CBOR object). */ - MGMT_ERR_ENOMEM, - - /** Error in input value. */ - MGMT_ERR_EINVAL, - - /** Operation timed out. */ - MGMT_ERR_ETIMEOUT, - - /** No such file/entry. */ - MGMT_ERR_ENOENT, - - /** Current state disallows command. */ - MGMT_ERR_EBADSTATE, - - /** Response too large. */ - MGMT_ERR_EMSGSIZE, - - /** Command not supported. */ - MGMT_ERR_ENOTSUP, - - /** Corrupt */ - MGMT_ERR_ECORRUPT, - - /** Command blocked by processing of other command */ - MGMT_ERR_EBUSY, - - /** Access to specific function, command or resource denied */ - MGMT_ERR_EACCESSDENIED, - - /** Requested SMP MCUmgr protocol version is not supported (too old) */ - MGMT_ERR_UNSUPPORTED_TOO_OLD, - - /** Requested SMP MCUmgr protocol version is not supported (too new) */ - MGMT_ERR_UNSUPPORTED_TOO_NEW, - - /** User errors defined from 256 onwards */ - MGMT_ERR_EPERUSER = 256 -}; - -#define MGMT_HDR_SIZE 8 - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* MGMT_MGMT_DEFINES_H_ */ From caa1e7aa5f361685437dfb24388f29282e35353f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:50 +0000 Subject: [PATCH 0871/1623] Revert "[nrf fromtree] net: Fix usage of strncpy in net_if_get_name and net_if_set_name" This reverts commit 9aa9bb98607f6f7232adedb5e7e15f7663f58498. Signed-off-by: Dominik Ermel --- subsys/net/ip/net_if.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 828e48ecf78..e6e3512e4b2 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -4747,8 +4747,7 @@ int net_if_get_name(struct net_if *iface, char *buf, int len) return -ERANGE; } - /* Copy string and null terminator */ - memcpy(buf, net_if_get_config(iface)->name, name_len + 1); + strncpy(buf, net_if_get_config(iface)->name, name_len); return name_len; #else @@ -4770,8 +4769,7 @@ int net_if_set_name(struct net_if *iface, const char *buf) return -ENAMETOOLONG; } - /* Copy string and null terminator */ - memcpy(net_if_get_config(iface)->name, buf, name_len + 1); + strncpy(net_if_get_config(iface)->name, buf, name_len); return 0; #else From b50d63fb52c8a888fb3ed0481c61da4a72362df6 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:50 +0000 Subject: [PATCH 0872/1623] Revert "[nrf fromtree] drivers: gpio_nrfx: Allow to disable interrupt support" This reverts commit 1cba00a409f64a96f3a0c75bd3cb15c146829077. Signed-off-by: Dominik Ermel --- drivers/gpio/Kconfig.nrfx | 11 +--------- drivers/gpio/gpio_nrfx.c | 42 ++++++++++++++------------------------- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/drivers/gpio/Kconfig.nrfx b/drivers/gpio/Kconfig.nrfx index 356c43cb5fa..6757b6b12e9 100644 --- a/drivers/gpio/Kconfig.nrfx +++ b/drivers/gpio/Kconfig.nrfx @@ -1,19 +1,10 @@ # Copyright (c) 2018 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -menuconfig GPIO_NRFX +config GPIO_NRFX bool "nRF GPIO driver" default y depends on DT_HAS_NORDIC_NRF_GPIO_ENABLED select NRFX_GPIOTE help Enable GPIO driver for nRF line of MCUs. - -config GPIO_NRFX_INTERRUPT - bool "Interrupt support" - depends on GPIO_NRFX - default y - help - The option can be used to disable the GPIO interrupt support to - significantly reduce memory footprint in case of application that does - not need GPIO interrupts. diff --git a/drivers/gpio/gpio_nrfx.c b/drivers/gpio/gpio_nrfx.c index 0aa282dda37..1683b8b2cea 100644 --- a/drivers/gpio/gpio_nrfx.c +++ b/drivers/gpio/gpio_nrfx.c @@ -85,19 +85,17 @@ static nrf_gpio_pin_pull_t get_pull(gpio_flags_t flags) static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin, gpio_flags_t flags) { - nrfx_err_t err = NRFX_SUCCESS; + nrfx_err_t err; uint8_t ch; - bool free_ch = false; + bool free_ch; const struct gpio_nrfx_cfg *cfg = get_port_cfg(port); nrfx_gpiote_pin_t abs_pin = NRF_GPIO_PIN_MAP(cfg->port_num, pin); /* Get the GPIOTE channel associated with this pin, if any. It needs * to be freed when the pin is reconfigured or disconnected. */ - if (IS_ENABLED(CONFIG_GPIO_NRFX_INTERRUPT)) { - err = nrfx_gpiote_channel_get(abs_pin, &ch); - free_ch = (err == NRFX_SUCCESS); - } + err = nrfx_gpiote_channel_get(abs_pin, &ch); + free_ch = (err == NRFX_SUCCESS); if ((flags & (GPIO_INPUT | GPIO_OUTPUT)) == GPIO_DISCONNECTED) { /* Ignore the error code. The pin may not have been used. */ @@ -111,21 +109,19 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin, return 0; } - if (IS_ENABLED(CONFIG_GPIO_NRFX_INTERRUPT)) { - nrfx_gpiote_trigger_config_t trigger_config = { - .trigger = NRFX_GPIOTE_TRIGGER_NONE - }; + nrfx_gpiote_trigger_config_t trigger_config = { + .trigger = NRFX_GPIOTE_TRIGGER_NONE + }; - /* Remove previously configured trigger when pin is reconfigured. */ - err = nrfx_gpiote_input_configure(abs_pin, NULL, &trigger_config, NULL); - if (err != NRFX_SUCCESS) { - return -EINVAL; - } + /* Remove previously configured trigger when pin is reconfigured. */ + err = nrfx_gpiote_input_configure(abs_pin, NULL, &trigger_config, NULL); + if (err != NRFX_SUCCESS) { + return -EINVAL; + } - if (free_ch) { - err = nrfx_gpiote_channel_free(ch); - __ASSERT_NO_MSG(err == NRFX_SUCCESS); - } + if (free_ch) { + err = nrfx_gpiote_channel_free(ch); + __ASSERT_NO_MSG(err == NRFX_SUCCESS); } if (flags & GPIO_OUTPUT) { @@ -223,7 +219,6 @@ static int gpio_nrfx_port_toggle_bits(const struct device *port, return 0; } -#ifdef CONFIG_GPIO_NRFX_INTERRUPT static nrfx_gpiote_trigger_t get_trigger(enum gpio_int_mode mode, enum gpio_int_trig trig) { @@ -290,7 +285,6 @@ static int gpio_nrfx_manage_callback(const struct device *port, return gpio_manage_callback(&get_port_data(port)->callbacks, callback, set); } -#endif /* CONFIG_GPIO_NRFX_INTERRUPT */ #ifdef CONFIG_GPIO_GET_DIRECTION static int gpio_nrfx_port_get_direction(const struct device *port, @@ -328,7 +322,6 @@ static int gpio_nrfx_port_get_direction(const struct device *port, } #endif /* CONFIG_GPIO_GET_DIRECTION */ -#ifdef CONFIG_GPIO_NRFX_INTERRUPT /* Get port device from port id. */ static const struct device *get_dev(uint32_t port_id) { @@ -365,7 +358,6 @@ static void nrfx_gpio_handler(nrfx_gpiote_pin_t abs_pin, gpio_fire_callbacks(list, port, BIT(pin)); } -#endif /* CONFIG_GPIO_NRFX_INTERRUPT */ #define GPIOTE_NODE DT_INST(0, nordic_nrf_gpiote) @@ -382,12 +374,10 @@ static int gpio_nrfx_init(const struct device *port) return -EIO; } -#ifdef CONFIG_GPIO_NRFX_INTERRUPT nrfx_gpiote_global_callback_set(nrfx_gpio_handler, NULL); IRQ_CONNECT(DT_IRQN(GPIOTE_NODE), DT_IRQ(GPIOTE_NODE, priority), nrfx_isr, nrfx_gpiote_irq_handler, 0); -#endif /* CONFIG_GPIO_NRFX_INTERRUPT */ return 0; } @@ -399,10 +389,8 @@ static const struct gpio_driver_api gpio_nrfx_drv_api_funcs = { .port_set_bits_raw = gpio_nrfx_port_set_bits_raw, .port_clear_bits_raw = gpio_nrfx_port_clear_bits_raw, .port_toggle_bits = gpio_nrfx_port_toggle_bits, -#ifdef CONFIG_GPIO_NRFX_INTERRUPT .pin_interrupt_configure = gpio_nrfx_pin_interrupt_configure, .manage_callback = gpio_nrfx_manage_callback, -#endif #ifdef CONFIG_GPIO_GET_DIRECTION .port_get_direction = gpio_nrfx_port_get_direction, #endif From e04177f3998ed4cac4294f18d20e1b9233c65eac Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:51 +0000 Subject: [PATCH 0873/1623] Revert "[nrf fromtree] drivers: gpio: fix optional operations usage" This reverts commit cf88137e48d93f97b16354ce0a41e1323478bbb7. Signed-off-by: Dominik Ermel --- drivers/gpio/gpio_ads114s0x.c | 12 ++++++++++++ drivers/gpio/gpio_axp192.c | 12 ++++++++++++ drivers/gpio/gpio_bd8lb600fs.c | 7 +++++++ drivers/gpio/gpio_creg_gpio.c | 9 +++++++++ drivers/gpio/gpio_cy8c95xx.c | 9 +++++++++ drivers/gpio/gpio_fxl6408.c | 10 ++++++++++ drivers/gpio/gpio_lmp90xxx.c | 14 ++++++++++++++ drivers/gpio/gpio_mcp23s17.c | 9 +++++++++ drivers/gpio/gpio_mmio32.c | 13 +++++++++++++ drivers/gpio/gpio_neorv32.c | 14 ++++++++++++++ drivers/gpio/gpio_npm1300.c | 12 ++++++++++++ drivers/gpio/gpio_npm6001.c | 14 ++++++++++++++ drivers/gpio/gpio_nxp_s32.c | 29 ++++++++++++++++++++++++++--- drivers/gpio/gpio_pca95xx.c | 14 ++++++++++++-- drivers/gpio/gpio_sc18im704.c | 12 ++++++++++++ drivers/gpio/gpio_sn74hc595.c | 11 +++++++++++ drivers/gpio/gpio_stmpe1600.c | 9 +++++++++ drivers/gpio/gpio_sx1509b.c | 11 ++++++++--- drivers/gpio/gpio_test.c | 23 +++++++++++++++++++++++ drivers/gpio/gpio_xlnx_axi.c | 4 +--- drivers/gpio/gpio_xmc4xxx.c | 15 ++++++++++----- 21 files changed, 247 insertions(+), 16 deletions(-) diff --git a/drivers/gpio/gpio_ads114s0x.c b/drivers/gpio/gpio_ads114s0x.c index 13f4f7f1266..79383d38154 100644 --- a/drivers/gpio/gpio_ads114s0x.c +++ b/drivers/gpio/gpio_ads114s0x.c @@ -106,6 +106,17 @@ static int gpio_ads114s0x_port_toggle_bits(const struct device *dev, gpio_port_p return ads114s0x_gpio_port_toggle_bits(config->parent, pins); } +static int gpio_ads114s0x_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, + enum gpio_int_mode mode, enum gpio_int_trig trig) +{ + ARG_UNUSED(dev); + ARG_UNUSED(pin); + ARG_UNUSED(mode); + ARG_UNUSED(trig); + + return -ENOTSUP; +} + static int gpio_ads114s0x_init(const struct device *dev) { const struct gpio_ads114s0x_config *config = dev->config; @@ -124,6 +135,7 @@ static const struct gpio_driver_api gpio_ads114s0x_api = { .port_set_bits_raw = gpio_ads114s0x_port_set_bits_raw, .port_clear_bits_raw = gpio_ads114s0x_port_clear_bits_raw, .port_toggle_bits = gpio_ads114s0x_port_toggle_bits, + .pin_interrupt_configure = gpio_ads114s0x_pin_interrupt_configure, .port_get_raw = gpio_ads114s0x_port_get_raw, }; diff --git a/drivers/gpio/gpio_axp192.c b/drivers/gpio/gpio_axp192.c index 95625d99dfe..ee75fe9b276 100644 --- a/drivers/gpio/gpio_axp192.c +++ b/drivers/gpio/gpio_axp192.c @@ -159,6 +159,17 @@ static int gpio_axp192_port_toggle_bits(const struct device *dev, gpio_port_pins return ret; } +static int gpio_axp192_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, + enum gpio_int_mode mode, enum gpio_int_trig trig) +{ + ARG_UNUSED(dev); + ARG_UNUSED(pin); + ARG_UNUSED(mode); + ARG_UNUSED(trig); + + return -ENOTSUP; +} + #ifdef CONFIG_GPIO_GET_CONFIG static int gpio_axp192_get_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t *out_flags) { @@ -265,6 +276,7 @@ static const struct gpio_driver_api gpio_axp192_api = { .port_set_bits_raw = gpio_axp192_port_set_bits_raw, .port_clear_bits_raw = gpio_axp192_port_clear_bits_raw, .port_toggle_bits = gpio_axp192_port_toggle_bits, + .pin_interrupt_configure = gpio_axp192_pin_interrupt_configure, .manage_callback = gpio_axp192_manage_callback, #ifdef CONFIG_GPIO_GET_DIRECTION .port_get_direction = gpio_axp192_port_get_direction, diff --git a/drivers/gpio/gpio_bd8lb600fs.c b/drivers/gpio/gpio_bd8lb600fs.c index 30ae851d90b..555a63b91fd 100644 --- a/drivers/gpio/gpio_bd8lb600fs.c +++ b/drivers/gpio/gpio_bd8lb600fs.c @@ -193,6 +193,12 @@ static int bd8lb600fs_port_toggle_bits(const struct device *dev, uint32_t mask) return result; } +static int bd8lb600fs_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, + enum gpio_int_mode mode, enum gpio_int_trig trig) +{ + return -ENOTSUP; +} + static const struct gpio_driver_api api_table = { .pin_configure = bd8lb600fs_pin_configure, .port_get_raw = bd8lb600fs_port_get_raw, @@ -200,6 +206,7 @@ static const struct gpio_driver_api api_table = { .port_set_bits_raw = bd8lb600fs_port_set_bits_raw, .port_clear_bits_raw = bd8lb600fs_port_clear_bits_raw, .port_toggle_bits = bd8lb600fs_port_toggle_bits, + .pin_interrupt_configure = bd8lb600fs_pin_interrupt_configure, }; static int bd8lb600fs_init(const struct device *dev) diff --git a/drivers/gpio/gpio_creg_gpio.c b/drivers/gpio/gpio_creg_gpio.c index 1b9f4d63a50..05b09184df9 100644 --- a/drivers/gpio/gpio_creg_gpio.c +++ b/drivers/gpio/gpio_creg_gpio.c @@ -104,6 +104,14 @@ static int port_toggle_bits(const struct device *dev, return port_write(dev, 0, 0, pins); } +static int pin_interrupt_configure(const struct device *dev, + gpio_pin_t pin, + enum gpio_int_mode mode, + enum gpio_int_trig trig) +{ + return -ENOTSUP; +} + static int pin_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t flags) @@ -155,6 +163,7 @@ static const struct gpio_driver_api api_table = { .port_set_bits_raw = port_set_bits, .port_clear_bits_raw = port_clear_bits, .port_toggle_bits = port_toggle_bits, + .pin_interrupt_configure = pin_interrupt_configure, }; static const struct creg_gpio_config creg_gpio_cfg = { diff --git a/drivers/gpio/gpio_cy8c95xx.c b/drivers/gpio/gpio_cy8c95xx.c index 155bfb4988a..b540a7b96bf 100644 --- a/drivers/gpio/gpio_cy8c95xx.c +++ b/drivers/gpio/gpio_cy8c95xx.c @@ -214,6 +214,14 @@ static int port_toggle_bits(const struct device *dev, return port_write(dev, 0, 0, pins); } +static int pin_interrupt_configure(const struct device *dev, + gpio_pin_t pin, + enum gpio_int_mode mode, + enum gpio_int_trig trig) +{ + return -ENOTSUP; +} + /** * @brief Initialization function of CY8C95XX * @@ -269,6 +277,7 @@ static const struct gpio_driver_api api_table = { .port_set_bits_raw = port_set_bits, .port_clear_bits_raw = port_clear_bits, .port_toggle_bits = port_toggle_bits, + .pin_interrupt_configure = pin_interrupt_configure, }; static struct k_sem cy8c95xx_lock = Z_SEM_INITIALIZER(cy8c95xx_lock, 1, 1); diff --git a/drivers/gpio/gpio_fxl6408.c b/drivers/gpio/gpio_fxl6408.c index 7352390e371..164a4396c13 100644 --- a/drivers/gpio/gpio_fxl6408.c +++ b/drivers/gpio/gpio_fxl6408.c @@ -377,6 +377,15 @@ static int gpio_fxl6408_port_toggle_bits(const struct device *dev, return ret; } +static int gpio_fxl6408_pin_interrupt_configure(const struct device *port, + gpio_pin_t pin, + enum gpio_int_mode mode, + enum gpio_int_trig trig) +{ + LOG_DBG("Pin interrupts not supported."); + return -ENOTSUP; +} + int gpio_fxl6408_init(const struct device *dev) { struct gpio_fxl6408_drv_data *const drv_data = @@ -400,6 +409,7 @@ static const struct gpio_driver_api gpio_fxl_driver = { .port_set_bits_raw = gpio_fxl6408_port_set_bits_raw, .port_clear_bits_raw = gpio_fxl6408_port_clear_bits_raw, .port_toggle_bits = gpio_fxl6408_port_toggle_bits, + .pin_interrupt_configure = gpio_fxl6408_pin_interrupt_configure }; #define GPIO_FXL6408_DEVICE_INSTANCE(inst) \ diff --git a/drivers/gpio/gpio_lmp90xxx.c b/drivers/gpio/gpio_lmp90xxx.c index 2514ef35211..1bd99d88cf2 100644 --- a/drivers/gpio/gpio_lmp90xxx.c +++ b/drivers/gpio/gpio_lmp90xxx.c @@ -122,6 +122,19 @@ static int gpio_lmp90xxx_port_toggle_bits(const struct device *dev, return lmp90xxx_gpio_port_toggle_bits(config->parent, pins); } +static int gpio_lmp90xxx_pin_interrupt_configure(const struct device *dev, + gpio_pin_t pin, + enum gpio_int_mode mode, + enum gpio_int_trig trig) +{ + ARG_UNUSED(dev); + ARG_UNUSED(pin); + ARG_UNUSED(mode); + ARG_UNUSED(trig); + + return -ENOTSUP; +} + static int gpio_lmp90xxx_init(const struct device *dev) { const struct gpio_lmp90xxx_config *config = dev->config; @@ -141,6 +154,7 @@ static const struct gpio_driver_api gpio_lmp90xxx_api = { .port_set_bits_raw = gpio_lmp90xxx_port_set_bits_raw, .port_clear_bits_raw = gpio_lmp90xxx_port_clear_bits_raw, .port_toggle_bits = gpio_lmp90xxx_port_toggle_bits, + .pin_interrupt_configure = gpio_lmp90xxx_pin_interrupt_configure, .port_get_raw = gpio_lmp90xxx_port_get_raw, }; diff --git a/drivers/gpio/gpio_mcp23s17.c b/drivers/gpio/gpio_mcp23s17.c index 4849c3a02fe..96a266fdf6d 100644 --- a/drivers/gpio/gpio_mcp23s17.c +++ b/drivers/gpio/gpio_mcp23s17.c @@ -340,6 +340,14 @@ static int mcp23s17_port_toggle_bits(const struct device *dev, uint32_t mask) return ret; } +static int mcp23s17_pin_interrupt_configure(const struct device *dev, + gpio_pin_t pin, + enum gpio_int_mode mode, + enum gpio_int_trig trig) +{ + return -ENOTSUP; +} + static const struct gpio_driver_api api_table = { .pin_configure = mcp23s17_config, .port_get_raw = mcp23s17_port_get_raw, @@ -347,6 +355,7 @@ static const struct gpio_driver_api api_table = { .port_set_bits_raw = mcp23s17_port_set_bits_raw, .port_clear_bits_raw = mcp23s17_port_clear_bits_raw, .port_toggle_bits = mcp23s17_port_toggle_bits, + .pin_interrupt_configure = mcp23s17_pin_interrupt_configure, }; static int mcp23s17_init(const struct device *dev) diff --git a/drivers/gpio/gpio_mmio32.c b/drivers/gpio/gpio_mmio32.c index 0fe5e9fedd8..e9e58373b5b 100644 --- a/drivers/gpio/gpio_mmio32.c +++ b/drivers/gpio/gpio_mmio32.c @@ -147,6 +147,18 @@ static int gpio_mmio32_port_toggle_bits(const struct device *dev, return 0; } +static int gpio_mmio32_pin_interrupt_configure(const struct device *dev, + gpio_pin_t pin, + enum gpio_int_mode mode, + enum gpio_int_trig trig) +{ + if (mode != GPIO_INT_MODE_DISABLED) { + return -ENOTSUP; + } + + return 0; +} + const struct gpio_driver_api gpio_mmio32_api = { .pin_configure = gpio_mmio32_config, .port_get_raw = gpio_mmio32_port_get_raw, @@ -154,6 +166,7 @@ const struct gpio_driver_api gpio_mmio32_api = { .port_set_bits_raw = gpio_mmio32_port_set_bits_raw, .port_clear_bits_raw = gpio_mmio32_port_clear_bits_raw, .port_toggle_bits = gpio_mmio32_port_toggle_bits, + .pin_interrupt_configure = gpio_mmio32_pin_interrupt_configure, }; int gpio_mmio32_init(const struct device *dev) diff --git a/drivers/gpio/gpio_neorv32.c b/drivers/gpio/gpio_neorv32.c index b14c51c1471..b448962bde7 100644 --- a/drivers/gpio/gpio_neorv32.c +++ b/drivers/gpio/gpio_neorv32.c @@ -151,6 +151,19 @@ static int neorv32_gpio_port_toggle_bits(const struct device *dev, return 0; } +static int neorv32_gpio_pin_interrupt_configure(const struct device *dev, + gpio_pin_t pin, + enum gpio_int_mode mode, + enum gpio_int_trig trig) +{ + ARG_UNUSED(dev); + ARG_UNUSED(pin); + ARG_UNUSED(mode); + ARG_UNUSED(trig); + + return -ENOTSUP; +} + static int neorv32_gpio_manage_callback(const struct device *dev, struct gpio_callback *cb, bool set) @@ -202,6 +215,7 @@ static const struct gpio_driver_api neorv32_gpio_driver_api = { .port_set_bits_raw = neorv32_gpio_port_set_bits_raw, .port_clear_bits_raw = neorv32_gpio_port_clear_bits_raw, .port_toggle_bits = neorv32_gpio_port_toggle_bits, + .pin_interrupt_configure = neorv32_gpio_pin_interrupt_configure, .manage_callback = neorv32_gpio_manage_callback, .get_pending_int = neorv32_gpio_get_pending_int, }; diff --git a/drivers/gpio/gpio_npm1300.c b/drivers/gpio/gpio_npm1300.c index 65c3cdd6fda..37e7f99c936 100644 --- a/drivers/gpio/gpio_npm1300.c +++ b/drivers/gpio/gpio_npm1300.c @@ -185,6 +185,17 @@ static int gpio_npm1300_port_toggle_bits(const struct device *dev, gpio_port_pin return gpio_npm1300_port_set_masked_raw(dev, pins, ~value); } +static int gpio_npm1300_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, + enum gpio_int_mode mode, enum gpio_int_trig trig) +{ + ARG_UNUSED(dev); + ARG_UNUSED(pin); + ARG_UNUSED(mode); + ARG_UNUSED(trig); + + return -ENOTSUP; +} + static const struct gpio_driver_api gpio_npm1300_api = { .pin_configure = gpio_npm1300_configure, .port_get_raw = gpio_npm1300_port_get_raw, @@ -192,6 +203,7 @@ static const struct gpio_driver_api gpio_npm1300_api = { .port_set_bits_raw = gpio_npm1300_port_set_bits_raw, .port_clear_bits_raw = gpio_npm1300_port_clear_bits_raw, .port_toggle_bits = gpio_npm1300_port_toggle_bits, + .pin_interrupt_configure = gpio_npm1300_pin_interrupt_configure, }; static int gpio_npm1300_init(const struct device *dev) diff --git a/drivers/gpio/gpio_npm6001.c b/drivers/gpio/gpio_npm6001.c index f722c4275d6..98bd4db49e0 100644 --- a/drivers/gpio/gpio_npm6001.c +++ b/drivers/gpio/gpio_npm6001.c @@ -192,6 +192,19 @@ static int gpio_npm6001_port_toggle_bits(const struct device *dev, ~val & NPM6001_PIN_MSK); } +static int gpio_npm6001_pin_interrupt_configure(const struct device *dev, + gpio_pin_t pin, + enum gpio_int_mode mode, + enum gpio_int_trig trig) +{ + ARG_UNUSED(dev); + ARG_UNUSED(pin); + ARG_UNUSED(mode); + ARG_UNUSED(trig); + + return -ENOTSUP; +} + static const struct gpio_driver_api gpio_npm6001_api = { .pin_configure = gpio_npm6001_configure, .port_get_raw = gpio_npm6001_port_get_raw, @@ -199,6 +212,7 @@ static const struct gpio_driver_api gpio_npm6001_api = { .port_set_bits_raw = gpio_npm6001_port_set_bits_raw, .port_clear_bits_raw = gpio_npm6001_port_clear_bits_raw, .port_toggle_bits = gpio_npm6001_port_toggle_bits, + .pin_interrupt_configure = gpio_npm6001_pin_interrupt_configure, }; static int gpio_npm6001_init(const struct device *dev) diff --git a/drivers/gpio/gpio_nxp_s32.c b/drivers/gpio/gpio_nxp_s32.c index de5dbd39dd7..3bdf9f4599d 100644 --- a/drivers/gpio/gpio_nxp_s32.c +++ b/drivers/gpio/gpio_nxp_s32.c @@ -205,12 +205,14 @@ static void nxp_s32_gpio_isr(uint8_t pin, void *arg) gpio_fire_callbacks(&data->callbacks, dev, BIT(pin)); } +#endif /* CONFIG_NXP_S32_EIRQ */ static int nxp_s32_gpio_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, enum gpio_int_mode mode, enum gpio_int_trig trig) { +#ifdef CONFIG_NXP_S32_EIRQ const struct gpio_nxp_s32_config *config = dev->config; const struct eirq_nxp_s32_info *eirq_info = config->eirq_info; @@ -253,18 +255,35 @@ static int nxp_s32_gpio_pin_interrupt_configure(const struct device *dev, } return 0; +#else + ARG_UNUSED(dev); + ARG_UNUSED(pin); + ARG_UNUSED(mode); + ARG_UNUSED(trig); + + return -ENOTSUP; +#endif } static int nxp_s32_gpio_manage_callback(const struct device *dev, struct gpio_callback *cb, bool set) { +#ifdef CONFIG_NXP_S32_EIRQ struct gpio_nxp_s32_data *data = dev->data; return gpio_manage_callback(&data->callbacks, cb, set); +#else + ARG_UNUSED(dev); + ARG_UNUSED(cb); + ARG_UNUSED(set); + + return -ENOTSUP; +#endif } static uint32_t nxp_s32_gpio_get_pending_int(const struct device *dev) { +#ifdef CONFIG_NXP_S32_EIRQ const struct gpio_nxp_s32_config *config = dev->config; const struct eirq_nxp_s32_info *eirq_info = config->eirq_info; @@ -281,8 +300,14 @@ static uint32_t nxp_s32_gpio_get_pending_int(const struct device *dev) * that GPIO port belongs to */ return eirq_nxp_s32_get_pending(eirq_info->eirq_dev); + +#else + ARG_UNUSED(dev); + + return -ENOTSUP; +#endif } -#endif /* CONFIG_NXP_S32_EIRQ */ + #ifdef CONFIG_GPIO_GET_CONFIG static int nxp_s32_gpio_pin_get_config(const struct device *dev, @@ -375,11 +400,9 @@ static const struct gpio_driver_api gpio_nxp_s32_driver_api = { .port_set_bits_raw = nxp_s32_gpio_port_set_bits_raw, .port_clear_bits_raw = nxp_s32_gpio_port_clear_bits_raw, .port_toggle_bits = nxp_s32_gpio_port_toggle_bits, -#ifdef CONFIG_NXP_S32_EIRQ .pin_interrupt_configure = nxp_s32_gpio_pin_interrupt_configure, .manage_callback = nxp_s32_gpio_manage_callback, .get_pending_int = nxp_s32_gpio_get_pending_int, -#endif #ifdef CONFIG_GPIO_GET_CONFIG .pin_get_config = nxp_s32_gpio_pin_get_config, #endif diff --git a/drivers/gpio/gpio_pca95xx.c b/drivers/gpio/gpio_pca95xx.c index f8489128332..66b21fd5b88 100644 --- a/drivers/gpio/gpio_pca95xx.c +++ b/drivers/gpio/gpio_pca95xx.c @@ -644,6 +644,7 @@ static void gpio_pca95xx_interrupt_callback(const struct device *dev, /* Cannot read PCA95xx registers from ISR context, queue worker */ k_work_submit(&drv_data->interrupt_worker); } +#endif /* CONFIG_GPIO_PCA95XX_INTERRUPT */ static int gpio_pca95xx_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, @@ -651,6 +652,13 @@ static int gpio_pca95xx_pin_interrupt_configure(const struct device *dev, enum gpio_int_trig trig) { int ret = 0; + + if (!IS_ENABLED(CONFIG_GPIO_PCA95XX_INTERRUPT) + && (mode != GPIO_INT_MODE_DISABLED)) { + return -ENOTSUP; + } + +#ifdef CONFIG_GPIO_PCA95XX_INTERRUPT const struct gpio_pca95xx_config * const config = dev->config; struct gpio_pca95xx_drv_data * const drv_data = (struct gpio_pca95xx_drv_data * const)dev->data; @@ -734,9 +742,11 @@ static int gpio_pca95xx_pin_interrupt_configure(const struct device *dev, err: k_sem_give(&drv_data->lock); +#endif /* CONFIG_GPIO_PCA95XX_INTERRUPT */ return ret; } +#ifdef CONFIG_GPIO_PCA95XX_INTERRUPT static int gpio_pca95xx_manage_callback(const struct device *dev, struct gpio_callback *callback, bool set) @@ -756,7 +766,7 @@ static int gpio_pca95xx_manage_callback(const struct device *dev, k_sem_give(&drv_data->lock); return 0; } -#endif /* CONFIG_GPIO_PCA95XX_INTERRUPT */ +#endif static const struct gpio_driver_api gpio_pca95xx_drv_api_funcs = { .pin_configure = gpio_pca95xx_config, @@ -765,8 +775,8 @@ static const struct gpio_driver_api gpio_pca95xx_drv_api_funcs = { .port_set_bits_raw = gpio_pca95xx_port_set_bits_raw, .port_clear_bits_raw = gpio_pca95xx_port_clear_bits_raw, .port_toggle_bits = gpio_pca95xx_port_toggle_bits, -#ifdef CONFIG_GPIO_PCA95XX_INTERRUPT .pin_interrupt_configure = gpio_pca95xx_pin_interrupt_configure, +#ifdef CONFIG_GPIO_PCA95XX_INTERRUPT .manage_callback = gpio_pca95xx_manage_callback, #endif }; diff --git a/drivers/gpio/gpio_sc18im704.c b/drivers/gpio/gpio_sc18im704.c index c45e9d51a60..96fd56cadb6 100644 --- a/drivers/gpio/gpio_sc18im704.c +++ b/drivers/gpio/gpio_sc18im704.c @@ -239,6 +239,17 @@ static int gpio_sc18im_port_toggle_bits(const struct device *port, gpio_port_pin return gpio_sc18im_port_set_raw(port, 0, 0, (uint8_t)pins); } +static int gpio_sc18im_pin_interrupt_configure(const struct device *port, gpio_pin_t pin, + enum gpio_int_mode mode, enum gpio_int_trig trig) +{ + ARG_UNUSED(port); + ARG_UNUSED(pin); + ARG_UNUSED(mode); + ARG_UNUSED(trig); + + return -ENOTSUP; +} + static int gpio_sc18im_init(const struct device *dev) { const struct gpio_sc18im_config *cfg = dev->config; @@ -261,6 +272,7 @@ static const struct gpio_driver_api gpio_sc18im_driver_api = { .port_set_bits_raw = gpio_sc18im_port_set_bits_raw, .port_clear_bits_raw = gpio_sc18im_port_clear_bits_raw, .port_toggle_bits = gpio_sc18im_port_toggle_bits, + .pin_interrupt_configure = gpio_sc18im_pin_interrupt_configure, }; #define CHECK_COMPAT(node) \ diff --git a/drivers/gpio/gpio_sn74hc595.c b/drivers/gpio/gpio_sn74hc595.c index 16eb35bb690..38f5de94d38 100644 --- a/drivers/gpio/gpio_sn74hc595.c +++ b/drivers/gpio/gpio_sn74hc595.c @@ -134,6 +134,16 @@ static int gpio_sn74hc595_port_toggle_bits(const struct device *dev, uint32_t ma return ret; } +static int gpio_sn74hc595_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, + enum gpio_int_mode mode, enum gpio_int_trig trig) +{ + ARG_UNUSED(dev); + ARG_UNUSED(pin); + ARG_UNUSED(mode); + ARG_UNUSED(trig); + return -ENOTSUP; +} + static const struct gpio_driver_api gpio_sn74hc595_drv_api_funcs = { .pin_configure = gpio_sn74hc595_config, .port_get_raw = gpio_sn74hc595_port_get_raw, @@ -141,6 +151,7 @@ static const struct gpio_driver_api gpio_sn74hc595_drv_api_funcs = { .port_set_bits_raw = gpio_sn74hc595_port_set_bits_raw, .port_clear_bits_raw = gpio_sn74hc595_port_clear_bits_raw, .port_toggle_bits = gpio_sn74hc595_port_toggle_bits, + .pin_interrupt_configure = gpio_sn74hc595_pin_interrupt_configure, }; /** diff --git a/drivers/gpio/gpio_stmpe1600.c b/drivers/gpio/gpio_stmpe1600.c index 2331fdf9fed..518b41c7c57 100644 --- a/drivers/gpio/gpio_stmpe1600.c +++ b/drivers/gpio/gpio_stmpe1600.c @@ -249,6 +249,14 @@ static int stmpe1600_port_toggle_bits(const struct device *dev, uint32_t mask) return ret; } +static int stmpe1600_pin_interrupt_configure(const struct device *dev, + gpio_pin_t pin, + enum gpio_int_mode mode, + enum gpio_int_trig trig) +{ + return -ENOTSUP; +} + static int stmpe1600_init(const struct device *dev) { const struct stmpe1600_config *const config = dev->config; @@ -292,6 +300,7 @@ static const struct gpio_driver_api stmpe1600_drv_api = { .port_set_bits_raw = stmpe1600_port_set_bits_raw, .port_clear_bits_raw = stmpe1600_port_clear_bits_raw, .port_toggle_bits = stmpe1600_port_toggle_bits, + .pin_interrupt_configure = stmpe1600_pin_interrupt_configure, }; #define STMPE1600_INIT(inst) \ diff --git a/drivers/gpio/gpio_sx1509b.c b/drivers/gpio/gpio_sx1509b.c index b8ecdf4d772..c62f803e307 100644 --- a/drivers/gpio/gpio_sx1509b.c +++ b/drivers/gpio/gpio_sx1509b.c @@ -468,7 +468,6 @@ static int port_toggle_bits(const struct device *dev, return port_write(dev, 0, 0, pins); } -#ifdef CONFIG_GPIO_SX1509B_INTERRUPT static int pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, enum gpio_int_mode mode, @@ -476,6 +475,12 @@ static int pin_interrupt_configure(const struct device *dev, { int rc = 0; + if (!IS_ENABLED(CONFIG_GPIO_SX1509B_INTERRUPT) + && (mode != GPIO_INT_MODE_DISABLED)) { + return -ENOTSUP; + } + +#ifdef CONFIG_GPIO_SX1509B_INTERRUPT /* Device does not support level-triggered interrupts. */ if (mode == GPIO_INT_MODE_LEVEL) { return -ENOTSUP; @@ -526,10 +531,10 @@ static int pin_interrupt_configure(const struct device *dev, rc = i2c_write_dt(&cfg->bus, &irq_buf.reg, sizeof(irq_buf)); k_sem_give(&drv_data->lock); +#endif /* CONFIG_GPIO_SX1509B_INTERRUPT */ return rc; } -#endif /* CONFIG_GPIO_SX1509B_INTERRUPT */ /** * @brief Initialization function of SX1509B @@ -642,8 +647,8 @@ static const struct gpio_driver_api api_table = { .port_set_bits_raw = port_set_bits, .port_clear_bits_raw = port_clear_bits, .port_toggle_bits = port_toggle_bits, -#ifdef CONFIG_GPIO_SX1509B_INTERRUPT .pin_interrupt_configure = pin_interrupt_configure, +#ifdef CONFIG_GPIO_SX1509B_INTERRUPT .manage_callback = gpio_sx1509b_manage_callback, #endif }; diff --git a/drivers/gpio/gpio_test.c b/drivers/gpio/gpio_test.c index 3befab37fc2..192028acac0 100644 --- a/drivers/gpio/gpio_test.c +++ b/drivers/gpio/gpio_test.c @@ -63,6 +63,26 @@ static int vnd_gpio_port_toggle_bits(const struct device *port, return -ENOTSUP; } +static int vnd_gpio_pin_interrupt_configure(const struct device *port, + gpio_pin_t pin, + enum gpio_int_mode mode, + enum gpio_int_trig trig) +{ + return -ENOTSUP; +} + +static int vnd_gpio_manage_callback(const struct device *port, + struct gpio_callback *cb, + bool set) +{ + return -ENOTSUP; +} + +static uint32_t vnd_gpio_get_pending_int(const struct device *dev) +{ + return 0; +} + static const struct gpio_driver_api vnd_gpio_api = { .pin_configure = vnd_gpio_pin_configure, .port_get_raw = vnd_gpio_port_get_raw, @@ -70,6 +90,9 @@ static const struct gpio_driver_api vnd_gpio_api = { .port_set_bits_raw = vnd_gpio_port_set_bits_raw, .port_clear_bits_raw = vnd_gpio_port_clear_bits_raw, .port_toggle_bits = vnd_gpio_port_toggle_bits, + .pin_interrupt_configure = vnd_gpio_pin_interrupt_configure, + .manage_callback = vnd_gpio_manage_callback, + .get_pending_int = vnd_gpio_get_pending_int }; #define VND_GPIO_INIT(n) \ diff --git a/drivers/gpio/gpio_xlnx_axi.c b/drivers/gpio/gpio_xlnx_axi.c index f070e691e5d..99e9e350aa2 100644 --- a/drivers/gpio/gpio_xlnx_axi.c +++ b/drivers/gpio/gpio_xlnx_axi.c @@ -198,7 +198,6 @@ static int gpio_xlnx_axi_port_toggle_bits(const struct device *dev, gpio_port_pi return 0; } -#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(interrupts) /** * Enables interrupts for the given pins on the channel * The axi gpio can only enable interrupts for an entire port, so we need to track @@ -207,6 +206,7 @@ static int gpio_xlnx_axi_port_toggle_bits(const struct device *dev, gpio_port_pi static int gpio_xlnx_axi_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, enum gpio_int_mode mode, enum gpio_int_trig trig) { +#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(interrupts) const struct gpio_xlnx_axi_config *config = dev->config; struct gpio_xlnx_axi_data *data = dev->data; const uint32_t pin_mask = BIT(pin); @@ -390,11 +390,9 @@ static const struct gpio_driver_api gpio_xlnx_axi_driver_api = { .port_set_bits_raw = gpio_xlnx_axi_port_set_bits_raw, .port_clear_bits_raw = gpio_xlnx_axi_port_clear_bits_raw, .port_toggle_bits = gpio_xlnx_axi_port_toggle_bits, -#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(interrupts) .pin_interrupt_configure = gpio_xlnx_axi_pin_interrupt_configure, .manage_callback = gpio_xlnx_axi_manage_callback, .get_pending_int = gpio_xlnx_axi_get_pending_int, -#endif }; #define GPIO_XLNX_AXI_GPIO2_HAS_COMPAT_STATUS_OKAY(n) \ diff --git a/drivers/gpio/gpio_xmc4xxx.c b/drivers/gpio/gpio_xmc4xxx.c index d90f68d3b32..29462308481 100644 --- a/drivers/gpio/gpio_xmc4xxx.c +++ b/drivers/gpio/gpio_xmc4xxx.c @@ -117,10 +117,10 @@ static void gpio_xmc4xxx_isr(const struct device *dev, int pin) } #endif -#ifdef CONFIG_XMC4XXX_INTC static int gpio_xmc4xxx_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, enum gpio_int_mode mode, enum gpio_int_trig trig) { +#if defined(CONFIG_XMC4XXX_INTC) const struct gpio_xmc4xxx_config *config = dev->config; int port_id = PORT_TO_PORT_ID(config->port); @@ -132,8 +132,15 @@ static int gpio_xmc4xxx_pin_interrupt_configure(const struct device *dev, gpio_p } else { return -EINVAL; } -} +#else + ARG_UNUSED(dev); + ARG_UNUSED(pin); + ARG_UNUSED(mode); + ARG_UNUSED(trig); + + return -ENOTSUP; #endif +} static int gpio_xmc4xxx_get_raw(const struct device *dev, gpio_port_value_t *value) { @@ -208,10 +215,8 @@ static const struct gpio_driver_api gpio_xmc4xxx_driver_api = { .port_set_bits_raw = gpio_xmc4xxx_set_bits_raw, .port_clear_bits_raw = gpio_xmc4xxx_clear_bits_raw, .port_toggle_bits = gpio_xmc4xxx_toggle_bits, -#ifdef CONFIG_XMC4XXX_INTC .pin_interrupt_configure = gpio_xmc4xxx_pin_interrupt_configure, - .manage_callback = gpio_xmc4xxx_manage_callback, -#endif + .manage_callback = IS_ENABLED(CONFIG_XMC4XXX_INTC) ? gpio_xmc4xxx_manage_callback : NULL, }; #define GPIO_XMC4XXX_INIT(index) \ From 65bcdc974c463c587b49b3fbd6ee9020d88294be Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:52 +0000 Subject: [PATCH 0874/1623] Revert "[nrf fromtree] boards: arm: (mimx|vmu_)rt1170: fix documentation issues" This reverts commit 3f54ea307c5d2ff2b956ecb191a3bba57e457b63. Signed-off-by: Dominik Ermel --- boards/arm/mimxrt1170_evk/doc/index.rst | 8 ++++++-- boards/arm/vmu_rt1170/doc/index.rst | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/boards/arm/mimxrt1170_evk/doc/index.rst b/boards/arm/mimxrt1170_evk/doc/index.rst index 1582861ffc9..51d5053e360 100644 --- a/boards/arm/mimxrt1170_evk/doc/index.rst +++ b/boards/arm/mimxrt1170_evk/doc/index.rst @@ -317,8 +317,10 @@ reprogrammed with JLink firmware. - MIMXRT1170-EVKB: :ref:`mcu-link-cmsis-onboard-debug-probe` - MIMXRT1170-EVK: :ref:`opensda-daplink-onboard-debug-probe` +.. _Using J-Link RT1170: + Using J-Link ------------- +--------------------------------- JLink is the default runner for this board. Install the :ref:`jlink-debug-host-tools` and make sure they are in your search path. @@ -328,8 +330,10 @@ J-Link firmware, or :ref:`jlink-external-debug-probe` can be attached to the EVK. See `Using J-Link with MIMXRT1170-EVKB`_ or `Using J-Link with MIMXRT1160-EVK or MIMXRT1170-EVK`_ for more details. +.. _Using LinkServer RT1170: + Using LinkServer ----------------- +---------------------------------- Known limitations with LinkServer and these boards include: - ``west debug`` does not yet work correctly, and the application image is not diff --git a/boards/arm/vmu_rt1170/doc/index.rst b/boards/arm/vmu_rt1170/doc/index.rst index 28d57464b4f..3514bf15893 100644 --- a/boards/arm/vmu_rt1170/doc/index.rst +++ b/boards/arm/vmu_rt1170/doc/index.rst @@ -216,8 +216,10 @@ Configuring a Debug Probe A debug probe is used for both flashing and debugging the board. +.. _Using J-Link RT1170: + Using J-Link ------------- +--------------------------------- Install the :ref:`jlink-debug-host-tools` and make sure they are in your search path. From 56503409542224d86b0746f244d6fcafbf806c07 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:53 +0000 Subject: [PATCH 0875/1623] Revert "[nrf fromtree] linkserver: doc: updates for NXP's mimxrt1170" This reverts commit 2e321f2c6155adc5d32142a5235bd72ea55df2c3. Signed-off-by: Dominik Ermel --- boards/arm/mimxrt1170_evk/doc/index.rst | 102 ++++++++---------------- doc/develop/flash_debug/host-tools.rst | 25 ++---- doc/develop/flash_debug/probes.rst | 61 -------------- 3 files changed, 40 insertions(+), 148 deletions(-) diff --git a/boards/arm/mimxrt1170_evk/doc/index.rst b/boards/arm/mimxrt1170_evk/doc/index.rst index 51d5053e360..90f192c3870 100644 --- a/boards/arm/mimxrt1170_evk/doc/index.rst +++ b/boards/arm/mimxrt1170_evk/doc/index.rst @@ -1,4 +1,4 @@ -.. _mimxrt1170_evk: +.. _mimxrt1170_evk: NXP MIMXRT1170-EVK/EVKB ####################### @@ -9,7 +9,7 @@ Overview The dual core i.MX RT1170 runs on the Cortex-M7 core at 1 GHz and on the Cortex-M4 at 400 MHz. The i.MX RT1170 MCU offers support over a wide temperature range and is qualified for consumer, industrial and automotive markets. Zephyr -supports the initial revision of this EVK, as well as rev EVKB. +supports the initial revision of this EVK, as well as EVK rev B. .. image:: mimxrt1170_evk.jpg :align: center @@ -59,7 +59,7 @@ Hardware - Debug - JTAG 20-pin connector - - on-board debugger + - OpenSDA with DAPLink - Sensor @@ -90,17 +90,16 @@ This platform has the following external memories: | Device | Controller | Status | +====================+============+=====================================+ | W9825G6KH | SEMC | Enabled via device configuration | -| SDRAM | | data (DCD) block, which sets up | -| | | the SEMC at boot time | +| | | data block, which sets up SEMC at | +| | | boot time | +--------------------+------------+-------------------------------------+ -| IS25WP128 | FLEXSPI | Enabled via flash configuration | -| QSPI flash | | block (FCB), which sets up the | -| (RT1170 EVK) | | FLEXSPI at boot time. | +| IS25WP128 | FLEXSPI | Enabled via flash configurationn | +| (RT1170 EVK) | | block, which sets up FLEXSPI at | +| | | boot time. | +--------------------+------------+-------------------------------------+ -| W25Q512NWEIQ | FLEXSPI | Enabled via flash configuration | -| QSPI flash | | block (FCB), which sets up the | -| (RT1170 EVKB) | | FLEXSPI at boot time. Supported for | -| | | XIP only. | +| W25Q512NWEIQ | FLEXSPI | Enabled via flash configurationn | +| (RT1170 EVKB) | | block, which sets up FLEXSPI at | +| | | boot time. Supported for XIP only. | +--------------------+------------+-------------------------------------+ Supported Features @@ -124,8 +123,6 @@ RT1170 EVKB (`mimxrt1170_evkb_cm7/cm4`) +-----------+------------+-------------------------------------+-----------------+-----------------+ | COUNTER | on-chip | gpt | Supported | Supported | +-----------+------------+-------------------------------------+-----------------+-----------------+ -| TIMER | on-chip | gpt | Supported | Supported | -+-----------+------------+-------------------------------------+-----------------+-----------------+ | CAN | on-chip | flexcan | Supported (M7) | Supported (M7) | +-----------+------------+-------------------------------------+-----------------+-----------------+ | SPI | on-chip | spi | Supported (M7) | Supported | @@ -142,10 +139,11 @@ RT1170 EVKB (`mimxrt1170_evkb_cm7/cm4`) +-----------+------------+-------------------------------------+-----------------+-----------------+ | DMA | on-chip | dma | Supported | Supported | +-----------+------------+-------------------------------------+-----------------+-----------------+ +| GPT | on-chip | gpt | Supported | Supported | ++-----------+------------+-------------------------------------+-----------------+-----------------+ | WATCHDOG | on-chip | watchdog | Supported (M7) | Supported (M7) | +-----------+------------+-------------------------------------+-----------------+-----------------+ -| ENET | on-chip | ethernet - 10/100M (ENET_QOS or | Supported (M7) | No support | -| ENET1G | | GigE not supported yet) | | | +| ENET | on-chip | ethernet | Supported (M7) | No support | +-----------+------------+-------------------------------------+-----------------+-----------------+ | SAI | on-chip | i2s | Supported | No support | +-----------+------------+-------------------------------------+-----------------+-----------------+ @@ -167,9 +165,10 @@ RT1170 EVKB (`mimxrt1170_evkb_cm7/cm4`) | SDHC | on-chip | SD host controller | Supported (M7) | Supported (M7) | +-----------+------------+-------------------------------------+-----------------+-----------------+ -The default configuration can be found in the defconfig files: +The default configuration can be found in the defconfig file: ``boards/arm/mimxrt1170_evk/mimxrt1170_evk_cm7_defconfig`` -``boards/arm/mimxrt1170_evk/mimxrt1170_evkb_cm7_defconfig`` + +Other hardware features are not currently supported by the port. Connections and I/Os ==================== @@ -311,62 +310,33 @@ secondary core should be placed into a loop, then a debugger can be attached Configuring a Debug Probe ========================= -A debug probe is used for both flashing and debugging the board. The on-board -debugger listed below works with the LinkServer runner by default, or can be -reprogrammed with JLink firmware. -- MIMXRT1170-EVKB: :ref:`mcu-link-cmsis-onboard-debug-probe` -- MIMXRT1170-EVK: :ref:`opensda-daplink-onboard-debug-probe` +A debug probe is used for both flashing and debugging the board. This board is +configured by default to use the :ref:`opensda-daplink-onboard-debug-probe`, +however the :ref:`pyocd-debug-host-tools` do not yet support programming the +external flashes on this board so you must reconfigure the board for one of the +following debug probes instead. .. _Using J-Link RT1170: Using J-Link --------------------------------- -JLink is the default runner for this board. Install the -:ref:`jlink-debug-host-tools` and make sure they are in your search path. +Install the :ref:`jlink-debug-host-tools` and make sure they are in your search +path. There are two options: the onboard debug circuit can be updated with Segger J-Link firmware, or :ref:`jlink-external-debug-probe` can be attached to the -EVK. See `Using J-Link with MIMXRT1170-EVKB`_ or -`Using J-Link with MIMXRT1160-EVK or MIMXRT1170-EVK`_ for more details. - -.. _Using LinkServer RT1170: - -Using LinkServer ----------------------------------- - -Known limitations with LinkServer and these boards include: -- ``west debug`` does not yet work correctly, and the application image is not -properly written to the memory. `NXP MCUXpresso for Visual Studio Code`_ -can be used to debug Zephyr applications with LinkServer. -- ``west flash`` will not write images to non-flash locations. The flash -command only works when all data in the image is written to flash memory -regions. - -Install the :ref:`linkserver-debug-host-tools` and make sure they are in your -search path. LinkServer works with the default CMSIS-DAP firmware included in -the on-board debugger. - -Use the ``-r linkserver`` option with West to use the LinkServer runner. - -.. code-block:: console - - west flash -r linkserver - +EVK. See `Using J-Link with MIMXRT1160-EVK or MIMXRT1170-EVK`_ for more details. Configuring a Console ===================== -We will use the on-board debugger -microcontroller as a usb-to-serial adapter for the serial console. The following -jumper settings are default on these boards, and are required to connect the -UART signals to the USB bridge circuit: -- MIMXRT1170-EVKB: JP2 open (default) -- MIMXRT1170-EVK: J31 and J32 shorted (default) +Regardless of your choice in debug probe, we will use the OpenSDA +microcontroller as a usb-to-serial adapter for the serial console. Check that +jumpers J5 and J8 are **on** (they are on by default when boards ship from +the factory) to connect UART signals to the OpenSDA microcontroller. -Connect a USB cable from your PC to the on-board debugger USB port: -- MIMXRT1170-EVKB: J86 -- MIMXRT1170-EVK: J11 +Connect a USB cable from your PC to J11. Use the following settings with your serial terminal of choice (minicom, putty, etc.): @@ -381,7 +351,7 @@ Flashing Here is an example for the :ref:`hello_world` application. -Before powering the board, make sure SW1 is set to 0001b +Before power on the board, make sure SW1 is set to 0001b .. zephyr-app-commands:: :zephyr-app: samples/hello_world @@ -394,7 +364,7 @@ see the following message in the terminal: .. code-block:: console - ***** Booting Zephyr OS v3.4.0-xxxx-xxxxxxxxxxxxx ***** + ***** Booting Zephyr OS v2.4.0-xxxx-xxxxxxxxxxxxx ***** Hello World! mimxrt1170_evk_cm7 Debugging @@ -412,7 +382,7 @@ should see the following message in the terminal: .. code-block:: console - ***** Booting Zephyr OS v3.4.0-xxxx-xxxxxxxxxxxxx ***** + ***** Booting Zephyr OS v2.4.0-xxxx-xxxxxxxxxxxxx ***** Hello World! mimxrt1170_evk_cm7 .. _MIMXRT1170-EVK Website: @@ -433,11 +403,5 @@ should see the following message in the terminal: .. _Using J-Link with MIMXRT1160-EVK or MIMXRT1170-EVK: https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/Using-J-Link-with-MIMXRT1160-EVK-or-MIMXRT1170-EVK/ta-p/1529760 -.. _Using J-Link with MIMXRT1170-EVKB: - https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/Using-J-Link-with-MIMXRT1170-EVKB/ta-p/1715138 - .. _AN13264: https://www.nxp.com/docs/en/application-note/AN13264.pdf - -.. _NXP MCUXpresso for Visual Studio Code: - https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-for-visual-studio-code:MCUXPRESSO-VSC diff --git a/doc/develop/flash_debug/host-tools.rst b/doc/develop/flash_debug/host-tools.rst index 981c89ce686..e93ee618f55 100644 --- a/doc/develop/flash_debug/host-tools.rst +++ b/doc/develop/flash_debug/host-tools.rst @@ -206,20 +206,17 @@ LinkServer Debug Host Tools Linkserver is a utility for launching and managing GDB servers for NXP debug probes, which also provides a command-line target flash programming capabilities. -Linkserver can be used with the `NXP MCUXpresso for Visual Studio Code`_ implementation, +Linkserver can be used with NXP MCUXpresso for Visual Studio Code implementation, with custom debug configurations based on GNU tools or as part of a headless solution -for continuous integration and test. LinkServer can be used with MCU-Link, LPC-Link2, +for continuous integration and test. Linkserver can be used with MCU-Link, LPC-Link2, LPC11U35-based and OpenSDA based standalone or on-board debug probes from NXP. - -NXP recommends installing LinkServer by using NXP's `MCUXpresso Installer`_. -This method will also install the tools supporting the debug probes below, -including NXP's MCU-Link and LPCScrypt tools. +The Linkserver installer also includes the firmware update utilities for MCU-Link and +the LPCScrypt utility for use with LPC-Link2. Linkserver can also be installed using +the MCUXpresso Installer. LinkServer is compatible with the following debug probes: - :ref:`lpclink2-cmsis-onboard-debug-probe` -- :ref:`mcu-link-cmsis-onboard-debug-probe` -- :ref:`opensda-daplink-onboard-debug-probe` Supported west commands: @@ -237,14 +234,13 @@ Notes: LinkServer probes -2. With multiple debug probes attached to the host, use the -LinkServer west runner ``--probe`` option to pass the probe index. +2. Use the LinkServer west runner ``--probe`` option to pass the probe index. .. code-block:: console west flash --runner=linkserver --probe=3 -3. Device-specific settings can be overridden with the west runner for LinkServer with +3. device specific settings can be overridden with the west runner for LinkServer with the option '--override'. May be used multiple times. The format is dictated by LinkServer, e.g.: @@ -269,7 +265,6 @@ These debug host tools are compatible with the following debug probes: - :ref:`lpclink2-jlink-onboard-debug-probe` - :ref:`opensda-jlink-onboard-debug-probe` -- :ref:`mcu-link-jlink-onboard-debug-probe` - :ref:`jlink-external-debug-probe` - :ref:`stlink-v21-onboard-debug-probe` @@ -410,9 +405,3 @@ To enable Zephyr RTOS awareness follow the steps described in .. _BOSSA official releases: https://github.com/shumatech/BOSSA/releases - -.. _NXP MCUXpresso for Visual Studio Code: - https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-for-visual-studio-code:MCUXPRESSO-VSC - -.. _MCUXpresso Installer: - https://www.nxp.com/lgfiles/updates/mcuxpresso/MCUXpressoInstaller.exe diff --git a/doc/develop/flash_debug/probes.rst b/doc/develop/flash_debug/probes.rst index 83f355aadba..78a068d6ac4 100644 --- a/doc/develop/flash_debug/probes.rst +++ b/doc/develop/flash_debug/probes.rst @@ -58,64 +58,6 @@ onboard debug probe may have limitations, such as lack of support for advanced debuggers or high-speed tracing. You may need to adjust jumpers to prevent the onboard debug probe from interfering with the external debug probe. -.. _mcu-link-cmsis-onboard-debug-probe: - -MCU-Link CMSIS-DAP Onboard Debug Probe -*************************************** - -The CMSIS-DAP debug probes allow debugging from any compatible toolchain, -including IAR EWARM, Keil MDK, NXP’s MCUXpresso IDE and -MCUXpresso extension for VS Code. In addition to debug probe functionality, the -MCU-Link probes may also provide: - -1. SWO trace end point: this virtual device is used by MCUXpresso to retrieve - SWO trace data. See the MCUXpresso IDE documentation for more information. -#. Virtual COM (VCOM) port / UART bridge connected to the target processor -#. USB to UART, SPI and/or I2C interfaces (depending on MCU-Link - type/implementation) -#. Energy measurements of the target MCU - -This debug probe is compatible with the following debug host tools: - -- :ref:`linkserver-debug-host-tools` - -This probe is realized by programming the MCU-Link microcontroller with the -CMSIS-DAP MCU-Link firmware, which is already installed by default. NXP -recommends using NXP's `MCUXpresso Installer`_, which installs both the MCU-Link -host tools plus the :ref:`linkserver-debug-host-tools`. - -1. Put the MCU-Link microcontroller into DFU boot mode by attaching the DFU - jumper, then powering up the board. - -#. Run the ``program_CMSIS`` script, found in the installed MCU-Link ``scripts`` - folder. - -#. Remove the DFU jumper and power cycle the board. - -.. _mcu-link-jlink-onboard-debug-probe: - -MCU-Link JLink Onboard Debug Probe -************************************ - -The MCU-Link J-Link is an onboard debug probe and usb-to-serial adapter -supported on many NXP development boards. - -This debug probe is compatible with the following debug host tools: - -- :ref:`jlink-debug-host-tools` - -These probes do not have JLink firmware installed by default, and must be -updated. NXP recommends using NXP's `MCUXpresso Installer`_, which installs both -the :ref:`jlink-debug-host-tools` plus the MCU-Link host tools. - -1. Put the MCU-Link microcontroller into DFU boot mode by attaching the DFU - jumper, then powering up the board. - -#. Run the ``program_JLINK`` script, found in the installed MCU-Link ``scripts`` - folder. - -#. Remove the DFU jumper and power cycle the board. - .. _lpclink2-cmsis-onboard-debug-probe: LPC-LINK2 CMSIS DAP Onboard Debug Probe @@ -399,6 +341,3 @@ option. For more information about twister and available options, see .. _STM32CubeProgrammer Tool: https://www.st.com/en/development-tools/stm32cubeprog.html - -.. _MCUXpresso Installer: - https://www.nxp.com/lgfiles/updates/mcuxpresso/MCUXpressoInstaller.exe From 183f0083a23f1098913352d106b6d70759fe86d5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:54 +0000 Subject: [PATCH 0876/1623] Revert "[nrf fromtree] manifest: hal_nordic: update to prevent USBD bad DMA" This reverts commit 0985ab67282f633fe616fb499248c225a75cfe24. Signed-off-by: Dominik Ermel --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index b4f874a87c5..727d6d807ab 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 092eb78ed1b1551d8f480019b9c05d7371784578 + revision: 9ae7c765985ebdea3d9b98c0d3b154794f0b47cf path: modules/hal/nordic groups: - hal From aeb36c063d0429999f0b73a87e266ea51825228c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:54 +0000 Subject: [PATCH 0877/1623] Revert "[nrf fromlist] Bluetooth: Host: Use memcpy instad of strncpy in bt_set_name" This reverts commit 7ff9fc19e1337526ed731f643d716ddcc55c9e9a. Signed-off-by: Dominik Ermel --- subsys/bluetooth/host/hci_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 40e1b44e960..260865e6a36 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -4144,7 +4144,7 @@ int bt_set_name(const char *name) return 0; } - memcpy(bt_dev.name, name, len); + strncpy(bt_dev.name, name, len); bt_dev.name[len] = '\0'; if (IS_ENABLED(CONFIG_BT_SETTINGS)) { From 134849dc9483bbcca152f61429e7fc4605e94dc7 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:54 +0000 Subject: [PATCH 0878/1623] Revert "[nrf fromtree] tests: net: lib: lwm2m: fix the missing float support" This reverts commit 61e999db7b38eff9939f51860a0a2e2a7fe87138. Signed-off-by: Dominik Ermel --- tests/net/lib/lwm2m/content_json/prj.conf | 2 -- tests/net/lib/lwm2m/content_plain_text/prj.conf | 2 -- 2 files changed, 4 deletions(-) diff --git a/tests/net/lib/lwm2m/content_json/prj.conf b/tests/net/lib/lwm2m/content_json/prj.conf index 7ff07df9897..3f2cd3e60f2 100644 --- a/tests/net/lib/lwm2m/content_json/prj.conf +++ b/tests/net/lib/lwm2m/content_json/prj.conf @@ -9,5 +9,3 @@ CONFIG_LWM2M=y CONFIG_LWM2M_COAP_MAX_MSG_SIZE=512 CONFIG_LWM2M_RW_JSON_SUPPORT=y CONFIG_JSON_LIBRARY=y - -CONFIG_PICOLIBC_IO_FLOAT=y diff --git a/tests/net/lib/lwm2m/content_plain_text/prj.conf b/tests/net/lib/lwm2m/content_plain_text/prj.conf index 877c969958f..6041addad83 100644 --- a/tests/net/lib/lwm2m/content_plain_text/prj.conf +++ b/tests/net/lib/lwm2m/content_plain_text/prj.conf @@ -6,5 +6,3 @@ CONFIG_ZTEST_NEW_API=y CONFIG_ENTROPY_GENERATOR=y CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_LWM2M=y - -CONFIG_PICOLIBC_IO_FLOAT=y From 2d2595b7008b4f222e6843626b4f82d857973858 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:55 +0000 Subject: [PATCH 0879/1623] Revert "[nrf fromtree] Bluetooth: Controller: Fix missing PHY_CODED cond compile" This reverts commit 2069e2a621432e875a488200ef7a4d95285f5864. Signed-off-by: Dominik Ermel --- samples/bluetooth/hci_rpmsg/sample.yaml | 10 ---------- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 2 -- 2 files changed, 12 deletions(-) diff --git a/samples/bluetooth/hci_rpmsg/sample.yaml b/samples/bluetooth/hci_rpmsg/sample.yaml index 7cecb12be67..3330002a59d 100644 --- a/samples/bluetooth/hci_rpmsg/sample.yaml +++ b/samples/bluetooth/hci_rpmsg/sample.yaml @@ -82,16 +82,6 @@ tests: platform_allow: nrf5340dk_nrf5340_cpunet integration_platforms: - nrf5340dk_nrf5340_cpunet - sample.bluetooth.hci_rpmsg.df.no_phy_coded.bt_ll_sw_split: - harness: bluetooth - tags: bluetooth - extra_args: - - CONF_FILE="nrf5340_cpunet_df-bt_ll_sw_split.conf" - - DTC_OVERLAY_FILE="nrf5340_cpunet_df-bt_ll_sw_split.overlay" - - CONFIG_BT_CTLR_PHY_CODED=n - platform_allow: nrf5340dk_nrf5340_cpunet - integration_platforms: - - nrf5340dk_nrf5340_cpunet sample.bluetooth.hci_rpmsg.mesh.bt_ll_sw_split: harness: bluetooth tags: bluetooth diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index 71e5ffa0e6f..085b881d47e 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -582,7 +582,6 @@ static inline void hal_radio_sw_switch_coded_tx_config_set(uint8_t ppi_en, BIT(HAL_SW_SWITCH_TIMER_S8_DISABLE_PPI)); } -#if defined(CONFIG_BT_CTLR_PHY_CODED) && defined(CONFIG_HAS_HW_NRF_RADIO_BLE_CODED) static inline void hal_radio_sw_switch_coded_config_clear(uint8_t ppi_en, uint8_t ppi_dis, uint8_t cc_reg, uint8_t group_index) { @@ -595,7 +594,6 @@ static inline void hal_radio_sw_switch_coded_config_clear(uint8_t ppi_en, HAL_SW_SWITCH_RADIO_ENABLE_PPI_REGISTER_EVT( SW_SWITCH_TIMER_S2_EVTS_COMP(group_index)) = 0; } -#endif /* CONFIG_BT_CTLR_PHY_CODED && CONFIG_HAS_HW_NRF_RADIO_BLE_CODED */ static inline void hal_radio_sw_switch_disable_group_clear(uint8_t ppi_dis, uint8_t cc_reg, uint8_t group_index) From cb046402c3ba6bca0db04a27205524583b0aa9d4 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:55 +0000 Subject: [PATCH 0880/1623] Revert "[nrf fromtree] net: wifi: Move function from shell to mgmt" This reverts commit 4a36c92e39aae11a7736b872dd9f0c8d34235af5. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_mgmt.c | 218 -------------------------------- subsys/net/l2/wifi/wifi_shell.c | 218 ++++++++++++++++++++++++++++++++ 2 files changed, 218 insertions(+), 218 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 0751f5d2b8c..dba18f8154f 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -18,224 +18,6 @@ LOG_MODULE_REGISTER(net_wifi_mgmt, CONFIG_NET_L2_WIFI_MGMT_LOG_LEVEL); #include #endif /* CONFIG_WIFI_NM */ -const char * const wifi_security_txt(enum wifi_security_type security) -{ - switch (security) { - case WIFI_SECURITY_TYPE_NONE: - return "OPEN"; - case WIFI_SECURITY_TYPE_WEP: - return "WEP"; - case WIFI_SECURITY_TYPE_WPA_PSK: - return "WPA-PSK"; - case WIFI_SECURITY_TYPE_PSK: - return "WPA2-PSK"; - case WIFI_SECURITY_TYPE_PSK_SHA256: - return "WPA2-PSK-SHA256"; - case WIFI_SECURITY_TYPE_SAE: - return "WPA3-SAE"; - case WIFI_SECURITY_TYPE_WAPI: - return "WAPI"; - case WIFI_SECURITY_TYPE_EAP: - return "EAP"; - case WIFI_SECURITY_TYPE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_mfp_txt(enum wifi_mfp_options mfp) -{ - switch (mfp) { - case WIFI_MFP_DISABLE: - return "Disable"; - case WIFI_MFP_OPTIONAL: - return "Optional"; - case WIFI_MFP_REQUIRED: - return "Required"; - case WIFI_MFP_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_band_txt(enum wifi_frequency_bands band) -{ - switch (band) { - case WIFI_FREQ_BAND_2_4_GHZ: - return "2.4GHz"; - case WIFI_FREQ_BAND_5_GHZ: - return "5GHz"; - case WIFI_FREQ_BAND_6_GHZ: - return "6GHz"; - case WIFI_FREQ_BAND_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_state_txt(enum wifi_iface_state state) -{ - switch (state) { - case WIFI_STATE_DISCONNECTED: - return "DISCONNECTED"; - case WIFI_STATE_INACTIVE: - return "INACTIVE"; - case WIFI_STATE_INTERFACE_DISABLED: - return "INTERFACE_DISABLED"; - case WIFI_STATE_SCANNING: - return "SCANNING"; - case WIFI_STATE_AUTHENTICATING: - return "AUTHENTICATING"; - case WIFI_STATE_ASSOCIATING: - return "ASSOCIATING"; - case WIFI_STATE_ASSOCIATED: - return "ASSOCIATED"; - case WIFI_STATE_4WAY_HANDSHAKE: - return "4WAY_HANDSHAKE"; - case WIFI_STATE_GROUP_HANDSHAKE: - return "GROUP_HANDSHAKE"; - case WIFI_STATE_COMPLETED: - return "COMPLETED"; - case WIFI_STATE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_mode_txt(enum wifi_iface_mode mode) -{ - switch (mode) { - case WIFI_MODE_INFRA: - return "STATION"; - case WIFI_MODE_IBSS: - return "ADHOC"; - case WIFI_MODE_AP: - return "ACCESS POINT"; - case WIFI_MODE_P2P_GO: - return "P2P GROUP OWNER"; - case WIFI_MODE_P2P_GROUP_FORMATION: - return "P2P GROUP FORMATION"; - case WIFI_MODE_MESH: - return "MESH"; - case WIFI_MODE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_link_mode_txt(enum wifi_link_mode link_mode) -{ - switch (link_mode) { - case WIFI_0: - return "WIFI 0 (802.11)"; - case WIFI_1: - return "WIFI 1 (802.11b)"; - case WIFI_2: - return "WIFI 2 (802.11a)"; - case WIFI_3: - return "WIFI 3 (802.11g)"; - case WIFI_4: - return "WIFI 4 (802.11n/HT)"; - case WIFI_5: - return "WIFI 5 (802.11ac/VHT)"; - case WIFI_6: - return "WIFI 6 (802.11ax/HE)"; - case WIFI_6E: - return "WIFI 6E (802.11ax 6GHz/HE)"; - case WIFI_7: - return "WIFI 7 (802.11be/EHT)"; - case WIFI_LINK_MODE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_ps_txt(enum wifi_ps ps_name) -{ - switch (ps_name) { - case WIFI_PS_DISABLED: - return "Power save disabled"; - case WIFI_PS_ENABLED: - return "Power save enabled"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_ps_mode_txt(enum wifi_ps_mode ps_mode) -{ - switch (ps_mode) { - case WIFI_PS_MODE_LEGACY: - return "Legacy power save"; - case WIFI_PS_MODE_WMM: - return "WMM power save"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_twt_operation_txt(enum wifi_twt_operation twt_operation) -{ - switch (twt_operation) { - case WIFI_TWT_SETUP: - return "TWT setup"; - case WIFI_TWT_TEARDOWN: - return "TWT teardown"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_twt_negotiation_type_txt(enum wifi_twt_negotiation_type twt_negotiation) -{ - switch (twt_negotiation) { - case WIFI_TWT_INDIVIDUAL: - return "TWT individual negotiation"; - case WIFI_TWT_BROADCAST: - return "TWT broadcast negotiation"; - case WIFI_TWT_WAKE_TBTT: - return "TWT wake TBTT negotiation"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_twt_setup_cmd_txt(enum wifi_twt_setup_cmd twt_setup) -{ - switch (twt_setup) { - case WIFI_TWT_SETUP_CMD_REQUEST: - return "TWT request"; - case WIFI_TWT_SETUP_CMD_SUGGEST: - return "TWT suggest"; - case WIFI_TWT_SETUP_CMD_DEMAND: - return "TWT demand"; - case WIFI_TWT_SETUP_CMD_GROUPING: - return "TWT grouping"; - case WIFI_TWT_SETUP_CMD_ACCEPT: - return "TWT accept"; - case WIFI_TWT_SETUP_CMD_ALTERNATE: - return "TWT alternate"; - case WIFI_TWT_SETUP_CMD_DICTATE: - return "TWT dictate"; - case WIFI_TWT_SETUP_CMD_REJECT: - return "TWT reject"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode) -{ - switch (ps_wakeup_mode) { - case WIFI_PS_WAKEUP_MODE_DTIM: - return "PS wakeup mode DTIM"; - case WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL: - return "PS wakeup mode listen interval"; - default: - return "UNKNOWN"; - } -} - static const struct wifi_mgmt_ops *const get_wifi_api(struct net_if *iface) { const struct device *dev = net_if_get_device(iface); diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index f1c512304bf..1fd2a537952 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -97,6 +97,224 @@ static bool parse_number(const struct shell *sh, long *param, char *str, long mi return true; } +const char * const wifi_security_txt(enum wifi_security_type security) +{ + switch (security) { + case WIFI_SECURITY_TYPE_NONE: + return "OPEN"; + case WIFI_SECURITY_TYPE_WEP: + return "WEP"; + case WIFI_SECURITY_TYPE_WPA_PSK: + return "WPA-PSK"; + case WIFI_SECURITY_TYPE_PSK: + return "WPA2-PSK"; + case WIFI_SECURITY_TYPE_PSK_SHA256: + return "WPA2-PSK-SHA256"; + case WIFI_SECURITY_TYPE_SAE: + return "WPA3-SAE"; + case WIFI_SECURITY_TYPE_WAPI: + return "WAPI"; + case WIFI_SECURITY_TYPE_EAP: + return "EAP"; + case WIFI_SECURITY_TYPE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_mfp_txt(enum wifi_mfp_options mfp) +{ + switch (mfp) { + case WIFI_MFP_DISABLE: + return "Disable"; + case WIFI_MFP_OPTIONAL: + return "Optional"; + case WIFI_MFP_REQUIRED: + return "Required"; + case WIFI_MFP_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_band_txt(enum wifi_frequency_bands band) +{ + switch (band) { + case WIFI_FREQ_BAND_2_4_GHZ: + return "2.4GHz"; + case WIFI_FREQ_BAND_5_GHZ: + return "5GHz"; + case WIFI_FREQ_BAND_6_GHZ: + return "6GHz"; + case WIFI_FREQ_BAND_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_state_txt(enum wifi_iface_state state) +{ + switch (state) { + case WIFI_STATE_DISCONNECTED: + return "DISCONNECTED"; + case WIFI_STATE_INACTIVE: + return "INACTIVE"; + case WIFI_STATE_INTERFACE_DISABLED: + return "INTERFACE_DISABLED"; + case WIFI_STATE_SCANNING: + return "SCANNING"; + case WIFI_STATE_AUTHENTICATING: + return "AUTHENTICATING"; + case WIFI_STATE_ASSOCIATING: + return "ASSOCIATING"; + case WIFI_STATE_ASSOCIATED: + return "ASSOCIATED"; + case WIFI_STATE_4WAY_HANDSHAKE: + return "4WAY_HANDSHAKE"; + case WIFI_STATE_GROUP_HANDSHAKE: + return "GROUP_HANDSHAKE"; + case WIFI_STATE_COMPLETED: + return "COMPLETED"; + case WIFI_STATE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_mode_txt(enum wifi_iface_mode mode) +{ + switch (mode) { + case WIFI_MODE_INFRA: + return "STATION"; + case WIFI_MODE_IBSS: + return "ADHOC"; + case WIFI_MODE_AP: + return "ACCESS POINT"; + case WIFI_MODE_P2P_GO: + return "P2P GROUP OWNER"; + case WIFI_MODE_P2P_GROUP_FORMATION: + return "P2P GROUP FORMATION"; + case WIFI_MODE_MESH: + return "MESH"; + case WIFI_MODE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_link_mode_txt(enum wifi_link_mode link_mode) +{ + switch (link_mode) { + case WIFI_0: + return "WIFI 0 (802.11)"; + case WIFI_1: + return "WIFI 1 (802.11b)"; + case WIFI_2: + return "WIFI 2 (802.11a)"; + case WIFI_3: + return "WIFI 3 (802.11g)"; + case WIFI_4: + return "WIFI 4 (802.11n/HT)"; + case WIFI_5: + return "WIFI 5 (802.11ac/VHT)"; + case WIFI_6: + return "WIFI 6 (802.11ax/HE)"; + case WIFI_6E: + return "WIFI 6E (802.11ax 6GHz/HE)"; + case WIFI_7: + return "WIFI 7 (802.11be/EHT)"; + case WIFI_LINK_MODE_UNKNOWN: + default: + return "UNKNOWN"; + } +} + +const char * const wifi_ps_txt(enum wifi_ps ps_name) +{ + switch (ps_name) { + case WIFI_PS_DISABLED: + return "Power save disabled"; + case WIFI_PS_ENABLED: + return "Power save enabled"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_ps_mode_txt(enum wifi_ps_mode ps_mode) +{ + switch (ps_mode) { + case WIFI_PS_MODE_LEGACY: + return "Legacy power save"; + case WIFI_PS_MODE_WMM: + return "WMM power save"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_twt_operation_txt(enum wifi_twt_operation twt_operation) +{ + switch (twt_operation) { + case WIFI_TWT_SETUP: + return "TWT setup"; + case WIFI_TWT_TEARDOWN: + return "TWT teardown"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_twt_negotiation_type_txt(enum wifi_twt_negotiation_type twt_negotiation) +{ + switch (twt_negotiation) { + case WIFI_TWT_INDIVIDUAL: + return "TWT individual negotiation"; + case WIFI_TWT_BROADCAST: + return "TWT broadcast negotiation"; + case WIFI_TWT_WAKE_TBTT: + return "TWT wake TBTT negotiation"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_twt_setup_cmd_txt(enum wifi_twt_setup_cmd twt_setup) +{ + switch (twt_setup) { + case WIFI_TWT_SETUP_CMD_REQUEST: + return "TWT request"; + case WIFI_TWT_SETUP_CMD_SUGGEST: + return "TWT suggest"; + case WIFI_TWT_SETUP_CMD_DEMAND: + return "TWT demand"; + case WIFI_TWT_SETUP_CMD_GROUPING: + return "TWT grouping"; + case WIFI_TWT_SETUP_CMD_ACCEPT: + return "TWT accept"; + case WIFI_TWT_SETUP_CMD_ALTERNATE: + return "TWT alternate"; + case WIFI_TWT_SETUP_CMD_DICTATE: + return "TWT dictate"; + case WIFI_TWT_SETUP_CMD_REJECT: + return "TWT reject"; + default: + return "UNKNOWN"; + } +} + +const char * const wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode) +{ + switch (ps_wakeup_mode) { + case WIFI_PS_WAKEUP_MODE_DTIM: + return "PS wakeup mode DTIM"; + case WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL: + return "PS wakeup mode listen interval"; + default: + return "UNKNOWN"; + } +} + static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb) { const struct wifi_scan_result *entry = From 066149286b504a72ad4a4f6f282ed623ce390629 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:55 +0000 Subject: [PATCH 0881/1623] Revert "[nrf fromtree] net: l2: wifi: Change arrays to functions" This reverts commit ff771d084177ffb3595bf855fb0fb26cef6c225e. Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi.h | 187 ++++++++++++++++++++--- subsys/net/l2/wifi/wifi_shell.c | 258 +++----------------------------- 2 files changed, 189 insertions(+), 256 deletions(-) diff --git a/include/zephyr/net/wifi.h b/include/zephyr/net/wifi.h index 294fdc53c5d..55bd8d71a3a 100644 --- a/include/zephyr/net/wifi.h +++ b/include/zephyr/net/wifi.h @@ -52,7 +52,30 @@ enum wifi_security_type { }; /** Helper function to get user-friendly security type name. */ -const char * const wifi_security_txt(enum wifi_security_type security); +static inline const char *wifi_security_txt(enum wifi_security_type security) +{ + switch (security) { + case WIFI_SECURITY_TYPE_NONE: + return "OPEN"; + case WIFI_SECURITY_TYPE_WEP: + return "WEP"; + case WIFI_SECURITY_TYPE_WPA_PSK: + return "WPA-PSK"; + case WIFI_SECURITY_TYPE_PSK: + return "WPA2-PSK"; + case WIFI_SECURITY_TYPE_PSK_SHA256: + return "WPA2-PSK-SHA256"; + case WIFI_SECURITY_TYPE_SAE: + return "WPA3-SAE"; + case WIFI_SECURITY_TYPE_WAPI: + return "WAPI"; + case WIFI_SECURITY_TYPE_EAP: + return "EAP"; + case WIFI_SECURITY_TYPE_UNKNOWN: + default: + return "UNKNOWN"; + } +} /** IEEE 802.11w - Management frame protection. */ enum wifi_mfp_options { @@ -69,7 +92,20 @@ enum wifi_mfp_options { }; /** Helper function to get user-friendly MFP name.*/ -const char * const wifi_mfp_txt(enum wifi_mfp_options mfp); +static inline const char *wifi_mfp_txt(enum wifi_mfp_options mfp) +{ + switch (mfp) { + case WIFI_MFP_DISABLE: + return "Disable"; + case WIFI_MFP_OPTIONAL: + return "Optional"; + case WIFI_MFP_REQUIRED: + return "Required"; + case WIFI_MFP_UNKNOWN: + default: + return "UNKNOWN"; + } +} /** * @brief IEEE 802.11 operational frequency bands (not exhaustive). @@ -91,7 +127,20 @@ enum wifi_frequency_bands { }; /** Helper function to get user-friendly frequency band name. */ -const char * const wifi_band_txt(enum wifi_frequency_bands band); +static inline const char *wifi_band_txt(enum wifi_frequency_bands band) +{ + switch (band) { + case WIFI_FREQ_BAND_2_4_GHZ: + return "2.4GHz"; + case WIFI_FREQ_BAND_5_GHZ: + return "5GHz"; + case WIFI_FREQ_BAND_6_GHZ: + return "6GHz"; + case WIFI_FREQ_BAND_UNKNOWN: + default: + return "UNKNOWN"; + } +} #define WIFI_SSID_MAX_LEN 32 #define WIFI_PSK_MIN_LEN 8 @@ -135,7 +184,34 @@ enum wifi_iface_state { }; /** Helper function to get user-friendly interface state name. */ -const char * const wifi_state_txt(enum wifi_iface_state state); +static inline const char *wifi_state_txt(enum wifi_iface_state state) +{ + switch (state) { + case WIFI_STATE_DISCONNECTED: + return "DISCONNECTED"; + case WIFI_STATE_INACTIVE: + return "INACTIVE"; + case WIFI_STATE_INTERFACE_DISABLED: + return "INTERFACE_DISABLED"; + case WIFI_STATE_SCANNING: + return "SCANNING"; + case WIFI_STATE_AUTHENTICATING: + return "AUTHENTICATING"; + case WIFI_STATE_ASSOCIATING: + return "ASSOCIATING"; + case WIFI_STATE_ASSOCIATED: + return "ASSOCIATED"; + case WIFI_STATE_4WAY_HANDSHAKE: + return "4WAY_HANDSHAKE"; + case WIFI_STATE_GROUP_HANDSHAKE: + return "GROUP_HANDSHAKE"; + case WIFI_STATE_COMPLETED: + return "COMPLETED"; + case WIFI_STATE_UNKNOWN: + default: + return "UNKNOWN"; + } +} /** Wi-Fi interface modes. * @@ -161,7 +237,26 @@ enum wifi_iface_mode { }; /** Helper function to get user-friendly interface mode name. */ -const char * const wifi_mode_txt(enum wifi_iface_mode mode); +static inline const char *wifi_mode_txt(enum wifi_iface_mode mode) +{ + switch (mode) { + case WIFI_MODE_INFRA: + return "STATION"; + case WIFI_MODE_IBSS: + return "ADHOC"; + case WIFI_MODE_AP: + return "ACCESS POINT"; + case WIFI_MODE_P2P_GO: + return "P2P GROUP OWNER"; + case WIFI_MODE_P2P_GROUP_FORMATION: + return "P2P GROUP FORMATION"; + case WIFI_MODE_MESH: + return "MESH"; + case WIFI_MODE_UNKNOWN: + default: + return "UNKNOWN"; + } +} /** Wi-Fi link operating modes * @@ -193,7 +288,32 @@ enum wifi_link_mode { }; /** Helper function to get user-friendly link mode name. */ -const char * const wifi_link_mode_txt(enum wifi_link_mode link_mode); +static inline const char *wifi_link_mode_txt(enum wifi_link_mode link_mode) +{ + switch (link_mode) { + case WIFI_0: + return "WIFI 0 (802.11)"; + case WIFI_1: + return "WIFI 1 (802.11b)"; + case WIFI_2: + return "WIFI 2 (802.11a)"; + case WIFI_3: + return "WIFI 3 (802.11g)"; + case WIFI_4: + return "WIFI 4 (802.11n/HT)"; + case WIFI_5: + return "WIFI 5 (802.11ac/VHT)"; + case WIFI_6: + return "WIFI 6 (802.11ax/HE)"; + case WIFI_6E: + return "WIFI 6E (802.11ax 6GHz/HE)"; + case WIFI_7: + return "WIFI 7 (802.11be/EHT)"; + case WIFI_LINK_MODE_UNKNOWN: + default: + return "UNKNOWN"; + } +} /** Wi-Fi scanning types. */ enum wifi_scan_type { @@ -211,8 +331,12 @@ enum wifi_ps { WIFI_PS_ENABLED, }; -/** Helper function to get user-friendly ps name. */ -const char * const wifi_ps_txt(enum wifi_ps ps_name); +/** @cond INTERNAL_HIDDEN */ +static const char * const wifi_ps2str[] = { + [WIFI_PS_DISABLED] = "Power save disabled", + [WIFI_PS_ENABLED] = "Power save enabled", +}; +/** @endcond */ /** Wi-Fi power save modes. */ enum wifi_ps_mode { @@ -225,8 +349,12 @@ enum wifi_ps_mode { WIFI_PS_MODE_WMM, }; -/** Helper function to get user-friendly ps mode name. */ -const char * const wifi_ps_mode_txt(enum wifi_ps_mode ps_mode); +/** @cond INTERNAL_HIDDEN */ +static const char * const wifi_ps_mode2str[] = { + [WIFI_PS_MODE_LEGACY] = "Legacy power save", + [WIFI_PS_MODE_WMM] = "WMM power save", +}; +/** @endcond */ /* Interface index Min and Max values */ #define WIFI_INTERFACE_INDEX_MIN 1 @@ -268,8 +396,12 @@ enum wifi_twt_operation { WIFI_TWT_TEARDOWN, }; -/** Helper function to get user-friendly twt operation name. */ -const char * const wifi_twt_operation_txt(enum wifi_twt_operation twt_operation); +/** @cond INTERNAL_HIDDEN */ +static const char * const wifi_twt_operation2str[] = { + [WIFI_TWT_SETUP] = "TWT setup", + [WIFI_TWT_TEARDOWN] = "TWT teardown", +}; +/** @endcond */ /** Wi-Fi Target Wake Time (TWT) negotiation types. */ enum wifi_twt_negotiation_type { @@ -281,8 +413,13 @@ enum wifi_twt_negotiation_type { WIFI_TWT_WAKE_TBTT }; -/** Helper function to get user-friendly twt negotiation type name. */ -const char * const wifi_twt_negotiation_type_txt(enum wifi_twt_negotiation_type twt_negotiation); +/** @cond INTERNAL_HIDDEN */ +static const char * const wifi_twt_negotiation_type2str[] = { + [WIFI_TWT_INDIVIDUAL] = "TWT individual negotiation", + [WIFI_TWT_BROADCAST] = "TWT broadcast negotiation", + [WIFI_TWT_WAKE_TBTT] = "TWT wake TBTT negotiation", +}; +/** @endcond */ /** Wi-Fi Target Wake Time (TWT) setup commands. */ enum wifi_twt_setup_cmd { @@ -304,8 +441,18 @@ enum wifi_twt_setup_cmd { WIFI_TWT_SETUP_CMD_REJECT, }; -/** Helper function to get user-friendly twt setup cmd name. */ -const char * const wifi_twt_setup_cmd_txt(enum wifi_twt_setup_cmd twt_setup); +/** @cond INTERNAL_HIDDEN */ +static const char * const wifi_twt_setup_cmd2str[] = { + [WIFI_TWT_SETUP_CMD_REQUEST] = "TWT request", + [WIFI_TWT_SETUP_CMD_SUGGEST] = "TWT suggest", + [WIFI_TWT_SETUP_CMD_DEMAND] = "TWT demand", + [WIFI_TWT_SETUP_CMD_GROUPING] = "TWT grouping", + [WIFI_TWT_SETUP_CMD_ACCEPT] = "TWT accept", + [WIFI_TWT_SETUP_CMD_ALTERNATE] = "TWT alternate", + [WIFI_TWT_SETUP_CMD_DICTATE] = "TWT dictate", + [WIFI_TWT_SETUP_CMD_REJECT] = "TWT reject", +}; +/** @endcond */ /** Wi-Fi Target Wake Time (TWT) negotiation status. */ enum wifi_twt_setup_resp_status { @@ -396,8 +543,12 @@ enum wifi_ps_wakeup_mode { WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL, }; -/** Helper function to get user-friendly ps wakeup mode name. */ -const char * const wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode); +/** @cond INTERNAL_HIDDEN */ +static const char * const wifi_ps_wakeup_mode2str[] = { + [WIFI_PS_WAKEUP_MODE_DTIM] = "PS wakeup mode DTIM", + [WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL] = "PS wakeup mode listen interval", +}; +/** @endcond */ /** Wi-Fi power save error codes. */ enum wifi_config_ps_param_fail_reason { diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 1fd2a537952..236fb32ee83 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -97,224 +97,6 @@ static bool parse_number(const struct shell *sh, long *param, char *str, long mi return true; } -const char * const wifi_security_txt(enum wifi_security_type security) -{ - switch (security) { - case WIFI_SECURITY_TYPE_NONE: - return "OPEN"; - case WIFI_SECURITY_TYPE_WEP: - return "WEP"; - case WIFI_SECURITY_TYPE_WPA_PSK: - return "WPA-PSK"; - case WIFI_SECURITY_TYPE_PSK: - return "WPA2-PSK"; - case WIFI_SECURITY_TYPE_PSK_SHA256: - return "WPA2-PSK-SHA256"; - case WIFI_SECURITY_TYPE_SAE: - return "WPA3-SAE"; - case WIFI_SECURITY_TYPE_WAPI: - return "WAPI"; - case WIFI_SECURITY_TYPE_EAP: - return "EAP"; - case WIFI_SECURITY_TYPE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_mfp_txt(enum wifi_mfp_options mfp) -{ - switch (mfp) { - case WIFI_MFP_DISABLE: - return "Disable"; - case WIFI_MFP_OPTIONAL: - return "Optional"; - case WIFI_MFP_REQUIRED: - return "Required"; - case WIFI_MFP_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_band_txt(enum wifi_frequency_bands band) -{ - switch (band) { - case WIFI_FREQ_BAND_2_4_GHZ: - return "2.4GHz"; - case WIFI_FREQ_BAND_5_GHZ: - return "5GHz"; - case WIFI_FREQ_BAND_6_GHZ: - return "6GHz"; - case WIFI_FREQ_BAND_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_state_txt(enum wifi_iface_state state) -{ - switch (state) { - case WIFI_STATE_DISCONNECTED: - return "DISCONNECTED"; - case WIFI_STATE_INACTIVE: - return "INACTIVE"; - case WIFI_STATE_INTERFACE_DISABLED: - return "INTERFACE_DISABLED"; - case WIFI_STATE_SCANNING: - return "SCANNING"; - case WIFI_STATE_AUTHENTICATING: - return "AUTHENTICATING"; - case WIFI_STATE_ASSOCIATING: - return "ASSOCIATING"; - case WIFI_STATE_ASSOCIATED: - return "ASSOCIATED"; - case WIFI_STATE_4WAY_HANDSHAKE: - return "4WAY_HANDSHAKE"; - case WIFI_STATE_GROUP_HANDSHAKE: - return "GROUP_HANDSHAKE"; - case WIFI_STATE_COMPLETED: - return "COMPLETED"; - case WIFI_STATE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_mode_txt(enum wifi_iface_mode mode) -{ - switch (mode) { - case WIFI_MODE_INFRA: - return "STATION"; - case WIFI_MODE_IBSS: - return "ADHOC"; - case WIFI_MODE_AP: - return "ACCESS POINT"; - case WIFI_MODE_P2P_GO: - return "P2P GROUP OWNER"; - case WIFI_MODE_P2P_GROUP_FORMATION: - return "P2P GROUP FORMATION"; - case WIFI_MODE_MESH: - return "MESH"; - case WIFI_MODE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_link_mode_txt(enum wifi_link_mode link_mode) -{ - switch (link_mode) { - case WIFI_0: - return "WIFI 0 (802.11)"; - case WIFI_1: - return "WIFI 1 (802.11b)"; - case WIFI_2: - return "WIFI 2 (802.11a)"; - case WIFI_3: - return "WIFI 3 (802.11g)"; - case WIFI_4: - return "WIFI 4 (802.11n/HT)"; - case WIFI_5: - return "WIFI 5 (802.11ac/VHT)"; - case WIFI_6: - return "WIFI 6 (802.11ax/HE)"; - case WIFI_6E: - return "WIFI 6E (802.11ax 6GHz/HE)"; - case WIFI_7: - return "WIFI 7 (802.11be/EHT)"; - case WIFI_LINK_MODE_UNKNOWN: - default: - return "UNKNOWN"; - } -} - -const char * const wifi_ps_txt(enum wifi_ps ps_name) -{ - switch (ps_name) { - case WIFI_PS_DISABLED: - return "Power save disabled"; - case WIFI_PS_ENABLED: - return "Power save enabled"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_ps_mode_txt(enum wifi_ps_mode ps_mode) -{ - switch (ps_mode) { - case WIFI_PS_MODE_LEGACY: - return "Legacy power save"; - case WIFI_PS_MODE_WMM: - return "WMM power save"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_twt_operation_txt(enum wifi_twt_operation twt_operation) -{ - switch (twt_operation) { - case WIFI_TWT_SETUP: - return "TWT setup"; - case WIFI_TWT_TEARDOWN: - return "TWT teardown"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_twt_negotiation_type_txt(enum wifi_twt_negotiation_type twt_negotiation) -{ - switch (twt_negotiation) { - case WIFI_TWT_INDIVIDUAL: - return "TWT individual negotiation"; - case WIFI_TWT_BROADCAST: - return "TWT broadcast negotiation"; - case WIFI_TWT_WAKE_TBTT: - return "TWT wake TBTT negotiation"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_twt_setup_cmd_txt(enum wifi_twt_setup_cmd twt_setup) -{ - switch (twt_setup) { - case WIFI_TWT_SETUP_CMD_REQUEST: - return "TWT request"; - case WIFI_TWT_SETUP_CMD_SUGGEST: - return "TWT suggest"; - case WIFI_TWT_SETUP_CMD_DEMAND: - return "TWT demand"; - case WIFI_TWT_SETUP_CMD_GROUPING: - return "TWT grouping"; - case WIFI_TWT_SETUP_CMD_ACCEPT: - return "TWT accept"; - case WIFI_TWT_SETUP_CMD_ALTERNATE: - return "TWT alternate"; - case WIFI_TWT_SETUP_CMD_DICTATE: - return "TWT dictate"; - case WIFI_TWT_SETUP_CMD_REJECT: - return "TWT reject"; - default: - return "UNKNOWN"; - } -} - -const char * const wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode) -{ - switch (ps_wakeup_mode) { - case WIFI_PS_WAKEUP_MODE_DTIM: - return "PS wakeup mode DTIM"; - case WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL: - return "PS wakeup mode listen interval"; - default: - return "UNKNOWN"; - } -} - static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb) { const struct wifi_scan_result *entry = @@ -475,7 +257,7 @@ static void print_twt_params(uint8_t dialog_token, uint8_t flow_id, print(context.sh, SHELL_NORMAL, "TWT flow ID: %d\n", flow_id); print(context.sh, SHELL_NORMAL, "TWT negotiation type: %s\n", - wifi_twt_negotiation_type_txt(negotiation_type)); + wifi_twt_negotiation_type2str[negotiation_type]); print(context.sh, SHELL_NORMAL, "TWT responder: %s\n", responder ? "true" : "false"); print(context.sh, SHELL_NORMAL, "TWT implicit: %s\n", @@ -504,7 +286,7 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) if (resp->resp_status == WIFI_TWT_RESP_RECEIVED) { print(context.sh, SHELL_NORMAL, "TWT response: %s\n", - wifi_twt_setup_cmd_txt(resp->setup_cmd)); + wifi_twt_setup_cmd2str[resp->setup_cmd]); print(context.sh, SHELL_NORMAL, "== TWT negotiated parameters ==\n"); print_twt_params(resp->dialog_token, resp->flow_id, @@ -954,10 +736,10 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) } shell_fprintf(sh, SHELL_NORMAL, "PS status: %s\n", - wifi_ps_txt(config.ps_params.enabled)); + wifi_ps2str[config.ps_params.enabled]); if (config.ps_params.enabled) { shell_fprintf(sh, SHELL_NORMAL, "PS mode: %s\n", - wifi_ps_mode_txt(config.ps_params.mode)); + wifi_ps_mode2str[config.ps_params.mode]); } shell_fprintf(sh, SHELL_NORMAL, "PS listen_interval: %d\n", @@ -1012,7 +794,7 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "%s\n", wifi_ps_txt(params.enabled)); + shell_fprintf(sh, SHELL_NORMAL, "%s\n", wifi_ps2str[params.enabled]); return 0; } @@ -1037,12 +819,12 @@ static int cmd_wifi_ps_mode(const struct shell *sh, size_t argc, char *argv[]) if (net_mgmt(NET_REQUEST_WIFI_PS, iface, ¶ms, sizeof(params))) { shell_fprintf(sh, SHELL_WARNING, "%s failed Reason : %s\n", - wifi_ps_mode_txt(params.mode), + wifi_ps_mode2str[params.mode], wifi_ps_get_config_err_code_str(params.fail_reason)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "%s\n", wifi_ps_mode_txt(params.mode)); + shell_fprintf(sh, SHELL_NORMAL, "%s\n", wifi_ps_mode2str[params.mode]); return 0; } @@ -1121,15 +903,15 @@ static int cmd_wifi_twt_setup_quick(const struct shell *sh, size_t argc, if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n", - wifi_twt_operation_txt(params.operation), - wifi_twt_negotiation_type_txt(params.negotiation_type), + wifi_twt_operation2str[params.operation], + wifi_twt_negotiation_type2str[params.negotiation_type], wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s with dg: %d, flow_id: %d requested\n", - wifi_twt_operation_txt(params.operation), + wifi_twt_operation2str[params.operation], params.dialog_token, params.flow_id); return 0; @@ -1208,15 +990,15 @@ static int cmd_wifi_twt_setup(const struct shell *sh, size_t argc, if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { shell_fprintf(sh, SHELL_WARNING, "%s with %s failed. reason : %s\n", - wifi_twt_operation_txt(params.operation), - wifi_twt_negotiation_type_txt(params.negotiation_type), + wifi_twt_operation2str[params.operation], + wifi_twt_negotiation_type2str[params.negotiation_type], wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s with dg: %d, flow_id: %d requested\n", - wifi_twt_operation_txt(params.operation), + wifi_twt_operation2str[params.operation], params.dialog_token, params.flow_id); return 0; @@ -1264,15 +1046,15 @@ static int cmd_wifi_twt_teardown(const struct shell *sh, size_t argc, if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n", - wifi_twt_operation_txt(params.operation), - wifi_twt_negotiation_type_txt(params.negotiation_type), + wifi_twt_operation2str[params.operation], + wifi_twt_negotiation_type2str[params.negotiation_type], wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s with dg: %d, flow_id: %d success\n", - wifi_twt_operation_txt(params.operation), + wifi_twt_operation2str[params.operation], params.dialog_token, params.flow_id); return 0; @@ -1291,15 +1073,15 @@ static int cmd_wifi_twt_teardown_all(const struct shell *sh, size_t argc, if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n", - wifi_twt_operation_txt(params.operation), - wifi_twt_negotiation_type_txt(params.negotiation_type), + wifi_twt_operation2str[params.operation], + wifi_twt_negotiation_type2str[params.negotiation_type], wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s all flows success\n", - wifi_twt_operation_txt(params.operation)); + wifi_twt_operation2str[params.operation]); return 0; } @@ -1476,7 +1258,7 @@ static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *ar } shell_fprintf(sh, SHELL_NORMAL, "%s\n", - wifi_ps_wakeup_mode_txt(params.wakeup_mode)); + wifi_ps_wakeup_mode2str[params.wakeup_mode]); return 0; } From eaf6208a997b7a0e3c4baac0f2102986259c8633 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:56 +0000 Subject: [PATCH 0882/1623] Revert "[nrf fromtree] mgmt/MCUmgr/grp/img: Add support for three image configuration" This reverts commit 622ccbce57fab78fd9527f0099207f84a2582459. Signed-off-by: Dominik Ermel --- subsys/dfu/Kconfig | 2 +- subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig | 2 +- .../mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c | 65 ++++++++++--------- .../mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c | 36 ++-------- 4 files changed, 42 insertions(+), 63 deletions(-) diff --git a/subsys/dfu/Kconfig b/subsys/dfu/Kconfig index 121fa3964f6..f998b2ef9f2 100644 --- a/subsys/dfu/Kconfig +++ b/subsys/dfu/Kconfig @@ -89,7 +89,7 @@ if !MCUBOOT config UPDATEABLE_IMAGE_NUMBER int "Number of updateable images" default 1 - range 1 3 + range 1 2 help If value is set to 2 or greater then, this enables support needed when application is combined with MCUboot multi-image boot. diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig b/subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig index 81fc57d9238..641e16bd703 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig @@ -46,7 +46,7 @@ endif config MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER int "Number of supported images" default UPDATEABLE_IMAGE_NUMBER - range 1 3 + range 1 2 help Sets how many application images are supported (pairs of secondary and primary slots). Setting this to 2 requires MCUMGR_TRANSPORT_NETBUF_SIZE to be at least 512b. diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c index 305cad41c44..b2bb39aca86 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c @@ -59,38 +59,43 @@ BUILD_ASSERT(PM_MCUBOOT_PAD_SIZE == PM_MCUBOOT_SECONDARY_PAD_SIZE); (FIXED_PARTITION_OFFSET(label) == CONFIG_FLASH_LOAD_OFFSET) #endif /* USE_PARTITION_MANAGER */ -BUILD_ASSERT(sizeof(struct image_header) == IMAGE_HEADER_SIZE, - "struct image_header not required size"); - -#if CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER >= 2 -#if FIXED_PARTITION_EXISTS(slot0_ns_partition) && \ - FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_ns_partition) -#define ACTIVE_IMAGE_IS 0 -#elif FIXED_PARTITION_EXISTS(slot0_partition) && \ - FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_partition) -#define ACTIVE_IMAGE_IS 0 -#elif FIXED_PARTITION_EXISTS(slot1_partition) && \ - FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot1_partition) -#define ACTIVE_IMAGE_IS 0 -#elif FIXED_PARTITION_EXISTS(slot2_partition) && \ - FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot2_partition) -#define ACTIVE_IMAGE_IS 1 -#elif FIXED_PARTITION_EXISTS(slot3_partition) && \ - FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot3_partition) -#define ACTIVE_IMAGE_IS 1 -#elif FIXED_PARTITION_EXISTS(slot4_partition) && \ - FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot4_partition) -#define ACTIVE_IMAGE_IS 2 -#elif FIXED_PARTITION_EXISTS(slot5_partition) && \ - FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot5_partition) -#define ACTIVE_IMAGE_IS 2 -#else -#define ACTIVE_IMAGE_IS 0 +#if FIXED_PARTITION_EXISTS(slot0_partition) +#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_partition) +#define NUMBER_OF_ACTIVE_IMAGE 0 +#endif +#endif + +#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot0_ns_partition) +#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_ns_partition) +#define NUMBER_OF_ACTIVE_IMAGE 0 #endif -#else -#define ACTIVE_IMAGE_IS 0 #endif +#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot1_partition) +#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot1_partition) +#define NUMBER_OF_ACTIVE_IMAGE 0 +#endif +#endif + +#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot2_partition) +#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot2_partition) +#define NUMBER_OF_ACTIVE_IMAGE 1 +#endif +#endif + +#if !defined(NUMBER_OF_ACTIVE_IMAGE) && FIXED_PARTITION_EXISTS(slot3_partition) +#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot3_partition) +#define NUMBER_OF_ACTIVE_IMAGE 1 +#endif +#endif + +#ifndef NUMBER_OF_ACTIVE_IMAGE +#error "Unsupported code parition is set as active application partition" +#endif + +_Static_assert(sizeof(struct image_header) == IMAGE_HEADER_SIZE, + "struct image_header not required size"); + LOG_MODULE_REGISTER(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL); struct img_mgmt_state g_img_mgmt_state; @@ -172,7 +177,7 @@ int img_mgmt_active_slot(int image) int img_mgmt_active_image(void) { - return ACTIVE_IMAGE_IS; + return NUMBER_OF_ACTIVE_IMAGE; } /* diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c index addde1e9a2c..c3641986fd2 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c @@ -25,26 +25,12 @@ LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL); #define SLOT1_PARTITION slot1_partition #define SLOT2_PARTITION slot2_partition #define SLOT3_PARTITION slot3_partition -#define SLOT4_PARTITION slot4_partition -#define SLOT5_PARTITION slot5_partition - -/* SLOT0_PARTITION and SLOT1_PARTITION are not checked because - * there is not conditional code that depends on them. If they do - * not exist compilation will fail, but in case if some of other - * partitions do not exist, code will compile and will not work - * properly. - */ -#if CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER >= 2 -BUILD_ASSERT(FIXED_PARTITION_EXISTS(SLOT2_PARTITION) && - FIXED_PARTITION_EXISTS(SLOT3_PARTITION), - "Missing partitions?"); -#endif -#if CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 3 -BUILD_ASSERT(FIXED_PARTITION_EXISTS(SLOT4_PARTITION) && - FIXED_PARTITION_EXISTS(SLOT5_PARTITION), +BUILD_ASSERT(CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 1 || + (CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 2 && + FIXED_PARTITION_EXISTS(SLOT2_PARTITION) && + FIXED_PARTITION_EXISTS(SLOT3_PARTITION)), "Missing partitions?"); -#endif /** * Determines if the specified area of flash is completely unwritten. @@ -151,18 +137,6 @@ img_mgmt_flash_area_id(int slot) break; #endif -#if FIXED_PARTITION_EXISTS(SLOT4_PARTITION) - case 4: - fa_id = FIXED_PARTITION_ID(SLOT4_PARTITION); - break; -#endif - -#if FIXED_PARTITION_EXISTS(SLOT5_PARTITION) - case 5: - fa_id = FIXED_PARTITION_ID(SLOT5_PARTITION); - break; -#endif - default: fa_id = -1; break; @@ -220,7 +194,7 @@ static int img_mgmt_get_unused_slot_area_id(int slot) return slot != -1 ? img_mgmt_flash_area_id(slot) : -1; #endif } -#elif CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER >= 2 +#elif CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 2 static int img_mgmt_get_unused_slot_area_id(int image) { int area_id = -1; From 60cd04569f2473753126f099c6e023417831e1ef Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:56 +0000 Subject: [PATCH 0883/1623] Revert "[nrf fromtree] twister: handle quotes for configuration options" This reverts commit 45e05e2d8f3ffb0b46a0fa055cb5b3ded64e13f7. Signed-off-by: Dominik Ermel --- scripts/pylib/twister/twisterlib/runner.py | 10 ++-------- scripts/tests/twister/test_runner.py | 5 ++--- scripts/west_commands/build.py | 6 +----- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index ef41084cdd4..bbbdb18d05a 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -978,15 +978,9 @@ def report_out(self, results): sys.stdout.flush() @staticmethod - def cmake_assemble_args(extra_args, handler, extra_conf_files, extra_overlay_confs, + def cmake_assemble_args(args, handler, extra_conf_files, extra_overlay_confs, extra_dtc_overlay_files, cmake_extra_args, build_dir): - # Retain quotes around config options - config_options = [arg for arg in extra_args if arg.startswith("CONFIG_")] - args = [arg for arg in extra_args if not arg.startswith("CONFIG_")] - - args_expanded = ["-D{}".format(a.replace('"', '\"')) for a in config_options] - if handler.ready: args.extend(handler.args) @@ -1009,7 +1003,7 @@ def cmake_assemble_args(extra_args, handler, extra_conf_files, extra_overlay_con args.append("OVERLAY_CONFIG=\"%s\"" % (" ".join(overlays))) # Build the final argument list - args_expanded.extend(["-D{}".format(a.replace('"', '\"')) for a in cmake_extra_args]) + args_expanded = ["-D{}".format(a.replace('"', '\"')) for a in cmake_extra_args] args_expanded.extend(["-D{}".format(a.replace('"', '')) for a in args]) return args_expanded diff --git a/scripts/tests/twister/test_runner.py b/scripts/tests/twister/test_runner.py index 37c02b6d17b..7540da04394 100644 --- a/scripts/tests/twister/test_runner.py +++ b/scripts/tests/twister/test_runner.py @@ -90,7 +90,7 @@ class MockHandler: handler.ready = True assert(ProjectBuilder.cmake_assemble_args( - ["basearg1", "CONFIG_t=\"test\"", "SNIPPET_t=\"test\""], + ["basearg1"], handler, ["a.conf;b.conf", "c.conf"], ["extra_overlay.conf"], @@ -98,9 +98,8 @@ class MockHandler: ["cmake1=foo", "cmake2=bar"], "/builddir/", ) == [ - "-DCONFIG_t=\"test\"", "-Dcmake1=foo", "-Dcmake2=bar", - "-Dbasearg1", "-DSNIPPET_t=test", + "-Dbasearg1", "-Dhandler_arg1", "-Dhandler_arg2", "-DCONF_FILE=a.conf;b.conf;c.conf", "-DDTC_OVERLAY_FILE=x.overlay;y.overlay;z.overlay", diff --git a/scripts/west_commands/build.py b/scripts/west_commands/build.py index f7a605f4d7f..bcc5106f8ca 100644 --- a/scripts/west_commands/build.py +++ b/scripts/west_commands/build.py @@ -317,11 +317,7 @@ def _parse_test_item(self, test_item): if data == 'extra_configs': args = ["-D{}".format(arg.replace('"', '\"')) for arg in arg_list] elif data == 'extra_args': - # Retain quotes around config options - config_options = [arg for arg in arg_list if arg.startswith("CONFIG_")] - non_config_options = [arg for arg in arg_list if not arg.startswith("CONFIG_")] - args = ["-D{}".format(a.replace('"', '\"')) for a in config_options] - args.extend(["-D{}".format(arg.replace('"', '')) for arg in non_config_options]) + args = ["-D{}".format(arg.replace('"', '')) for arg in arg_list] elif data == 'extra_conf_files': extra_conf_files.extend(arg_list) continue From bee9b3bbd69b643e2e2c5e86b7a80da52a295365 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:56 +0000 Subject: [PATCH 0884/1623] Revert "[nrf fromtree] twister: Add support for required snippets" This reverts commit 5327c5408115ece4c62baaa0eb9fdd8086f78f1b. Signed-off-by: Dominik Ermel --- .../pylib/twister/twisterlib/config_parser.py | 1 - scripts/pylib/twister/twisterlib/runner.py | 4 -- scripts/pylib/twister/twisterlib/testplan.py | 42 ------------------- scripts/schemas/twister/testsuite-schema.yaml | 10 ----- scripts/snippets.py | 16 ------- scripts/twister | 3 -- scripts/west_commands/build.py | 11 +---- 7 files changed, 1 insertion(+), 86 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/config_parser.py b/scripts/pylib/twister/twisterlib/config_parser.py index f431e2d57c2..c822e9dfc77 100644 --- a/scripts/pylib/twister/twisterlib/config_parser.py +++ b/scripts/pylib/twister/twisterlib/config_parser.py @@ -48,7 +48,6 @@ class TwisterConfigParser: "extra_conf_files": {"type": "list", "default": []}, "extra_overlay_confs" : {"type": "list", "default": []}, "extra_dtc_overlay_files": {"type": "list", "default": []}, - "required_snippets": {"type": "list"}, "build_only": {"type": "bool", "default": False}, "build_on_all": {"type": "bool", "default": False}, "skip": {"type": "bool", "default": False}, diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index bbbdb18d05a..ad93145db38 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -359,10 +359,6 @@ def run_cmake(self, args="", filter_stages=[]): cmake_opts = ['-DBOARD={}'.format(self.platform.name)] cmake_args.extend(cmake_opts) - if self.instance.testsuite.required_snippets: - cmake_opts = ['-DSNIPPET={}'.format(';'.join(self.instance.testsuite.required_snippets))] - cmake_args.extend(cmake_opts) - cmake = shutil.which('cmake') cmd = [cmake] + cmake_args diff --git a/scripts/pylib/twister/twisterlib/testplan.py b/scripts/pylib/twister/twisterlib/testplan.py index 1d9c625b28a..85340885dbb 100755 --- a/scripts/pylib/twister/twisterlib/testplan.py +++ b/scripts/pylib/twister/twisterlib/testplan.py @@ -16,8 +16,6 @@ import copy import shutil import random -import snippets -from pathlib import Path logger = logging.getLogger('twister') logger.setLevel(logging.DEBUG) @@ -821,46 +819,6 @@ def apply_filters(self, **kwargs): if plat.only_tags and not set(plat.only_tags) & ts.tags: instance.add_filter("Excluded tags per platform (only_tags)", Filters.PLATFORM) - if ts.required_snippets: - missing_snippet = False - snippet_args = {"snippets": ts.required_snippets} - found_snippets = snippets.find_snippets_in_roots(snippet_args, [Path(ZEPHYR_BASE), Path(ts.source_dir)]) - - # Search and check that all required snippet files are found - for this_snippet in snippet_args['snippets']: - if this_snippet not in found_snippets: - logger.error(f"Can't find snippet '%s' for test '%s'", this_snippet, ts.name) - instance.status = "error" - instance.reason = f"Snippet {this_snippet} not found" - missing_snippet = True - break - - if not missing_snippet: - # Look for required snippets and check that they are applicable for these - # platforms/boards - for this_snippet in found_snippets: - matched_snippet_board = False - - # If the "appends" key is present with at least one entry then this - # snippet applies to all boards and further platform-specific checks - # are not required - if found_snippets[this_snippet].appends: - continue - - for this_board in found_snippets[this_snippet].board2appends: - if this_board.startswith('/'): - match = re.search(this_board[1:-1], plat.name) - if match is not None: - matched_snippet_board = True - break - elif this_board == plat.name: - matched_snippet_board = True - break - - if matched_snippet_board is False: - instance.add_filter("Snippet not supported", Filters.PLATFORM) - break - # platform_key is a list of unique platform attributes that form a unique key a test # will match against to determine if it should be scheduled to run. A key containing a # field name that the platform does not have will filter the platform. diff --git a/scripts/schemas/twister/testsuite-schema.yaml b/scripts/schemas/twister/testsuite-schema.yaml index 116c1a43379..4d67fe71706 100644 --- a/scripts/schemas/twister/testsuite-schema.yaml +++ b/scripts/schemas/twister/testsuite-schema.yaml @@ -145,11 +145,6 @@ mapping: matching: "all" sequence: - type: str - "required_snippets": - type: seq - required: false - sequence: - - type: str "tags": type: any required: false @@ -248,11 +243,6 @@ mapping: "extra_sections": type: any required: false - "required_snippets": - type: seq - required: false - sequence: - - type: str "filter": type: str required: false diff --git a/scripts/snippets.py b/scripts/snippets.py index 78ab896e85b..9662f3edcec 100644 --- a/scripts/snippets.py +++ b/scripts/snippets.py @@ -238,22 +238,6 @@ def process_snippets(args: argparse.Namespace) -> Snippets: return snippets -def find_snippets_in_roots(requested_snippets, snippet_roots) -> Snippets: - '''Process snippet.yml files under each *snippet_root* - by recursive search. Return a Snippets object describing - the results of the search. - ''' - # This will contain information about all the snippets - # we discover in each snippet_root element. - snippets = Snippets(requested=requested_snippets) - - # Process each path in snippet_root in order, adjusting - # snippets as needed for each one. - for root in snippet_roots: - process_snippets_in(root, snippets) - - return snippets - def process_snippets_in(root_dir: Path, snippets: Snippets) -> None: '''Process snippet.yml files in *root_dir*, updating *snippets* as needed.''' diff --git a/scripts/twister b/scripts/twister index f41349871ed..0f5e622011f 100755 --- a/scripts/twister +++ b/scripts/twister @@ -44,9 +44,6 @@ pairs: Extra configuration options to be merged with a master prj.conf when building or running the test case. - required_snippets: - Snippets that must be applied for the test case to run. - sysbuild: (default False) If true, build the sample using the sysbuild infrastructure. Filtering will only be enabled for the main project, and is not supported for diff --git a/scripts/west_commands/build.py b/scripts/west_commands/build.py index bcc5106f8ca..65dbe963cd4 100644 --- a/scripts/west_commands/build.py +++ b/scripts/west_commands/build.py @@ -293,7 +293,6 @@ def _parse_test_item(self, test_item): extra_dtc_overlay_files = [] extra_overlay_confs = [] extra_conf_files = [] - required_snippets = [] for section in [common, item]: if not section: continue @@ -303,8 +302,7 @@ def _parse_test_item(self, test_item): 'extra_configs', 'extra_conf_files', 'extra_overlay_confs', - 'extra_dtc_overlay_files', - 'required_snippets' + 'extra_dtc_overlay_files' ]: extra = section.get(data) if not extra: @@ -327,9 +325,6 @@ def _parse_test_item(self, test_item): elif data == 'extra_dtc_overlay_files': extra_dtc_overlay_files.extend(arg_list) continue - elif data == 'required_snippets': - required_snippets.extend(arg_list) - continue if self.args.cmake_opts: self.args.cmake_opts.extend(args) @@ -348,10 +343,6 @@ def _parse_test_item(self, test_item): if extra_overlay_confs: args.append(f"OVERLAY_CONFIG=\"{';'.join(extra_overlay_confs)}\"") - - if required_snippets: - args.append(f"SNIPPET=\"{';'.join(required_snippets)}\"") - # Build the final argument list args_expanded = ["-D{}".format(a.replace('"', '')) for a in args] From 14770de0a7dd8bfa7d89ea43de4ed562cc8f4033 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:57 +0000 Subject: [PATCH 0885/1623] Revert "[nrf fromtree] net: socketpair: Fix use after free" This reverts commit 4ea2d10cee590392888695101091446a4c4605d5. Signed-off-by: Dominik Ermel --- subsys/net/lib/sockets/socketpair.c | 8 ++++---- tests/net/socket/socketpair/testcase.yaml | 8 -------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/subsys/net/lib/sockets/socketpair.c b/subsys/net/lib/sockets/socketpair.c index 9207f4b659e..f3bbb46f6c8 100644 --- a/subsys/net/lib/sockets/socketpair.c +++ b/subsys/net/lib/sockets/socketpair.c @@ -191,10 +191,6 @@ static void spair_delete(struct spair *spair) res = k_poll_signal_raise(&spair->writeable, SPAIR_SIG_CANCEL); __ASSERT(res == 0, "k_poll_signal_raise() failed: %d", res); - if (remote != NULL && have_remote_sem) { - k_sem_give(&remote->sem); - } - /* ensure no private information is released to the memory pool */ memset(spair, 0, sizeof(*spair)); #ifdef CONFIG_NET_SOCKETPAIR_STATIC @@ -204,6 +200,10 @@ static void spair_delete(struct spair *spair) #else k_free(spair); #endif + + if (remote != NULL && have_remote_sem) { + k_sem_give(&remote->sem); + } } /** diff --git a/tests/net/socket/socketpair/testcase.yaml b/tests/net/socket/socketpair/testcase.yaml index d2b4462ce2d..e771e7c61d4 100644 --- a/tests/net/socket/socketpair/testcase.yaml +++ b/tests/net/socket/socketpair/testcase.yaml @@ -18,11 +18,3 @@ tests: extra_configs: - CONFIG_PICOLIBC=y platform_exclude: vmu_rt1170 mimxrt1160_evk_cm7 # See #61246 - net.socket.socketpair.high_mem: - min_ram: 64 - extra_configs: - # Low buffer sizes (e.g., 8192) will verify the crash fix, but tests will still - # fail due to insufficient memory. So, use high buffer sizes. - - CONFIG_NET_SOCKETPAIR_BUFFER_SIZE=4096 - - CONFIG_HEAP_MEM_POOL_SIZE=32768 - platform_exclude: vmu_rt1170 mimxrt1160_evk_cm7 # See #61246 From 4c5e075124f8cad7c399f8341b2afa6160452fa7 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:57 +0000 Subject: [PATCH 0886/1623] Revert "[nrf fromtree] net: l2: wifi: Add support for W-Fi mode setting and selection" This reverts commit 0feef90eb0216678f3cfe10bbeae034d79ad9840. Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi.h | 33 --- include/zephyr/net/wifi_mgmt.h | 76 ------- subsys/net/l2/wifi/wifi_mgmt.c | 60 ----- subsys/net/l2/wifi/wifi_shell.c | 388 +------------------------------- 4 files changed, 1 insertion(+), 556 deletions(-) diff --git a/include/zephyr/net/wifi.h b/include/zephyr/net/wifi.h index 55bd8d71a3a..aa3096fc5ac 100644 --- a/include/zephyr/net/wifi.h +++ b/include/zephyr/net/wifi.h @@ -148,7 +148,6 @@ static inline const char *wifi_band_txt(enum wifi_frequency_bands band) #define WIFI_SAE_PSWD_MAX_LEN 128 #define WIFI_MAC_ADDR_LEN 6 -#define WIFI_CHANNEL_MIN 1 #define WIFI_CHANNEL_MAX 233 #define WIFI_CHANNEL_ANY 255 @@ -356,38 +355,6 @@ static const char * const wifi_ps_mode2str[] = { }; /** @endcond */ -/* Interface index Min and Max values */ -#define WIFI_INTERFACE_INDEX_MIN 1 -#define WIFI_INTERFACE_INDEX_MAX 255 - -/** Wifi operational mode */ -enum wifi_operational_modes { - /** STA mode setting enable */ - WIFI_STA_MODE = BIT(0), - /** Monitor mode setting enable */ - WIFI_MONITOR_MODE = BIT(1), - /** TX injection mode setting enable */ - WIFI_TX_INJECTION_MODE = BIT(2), - /** Promiscuous mode setting enable */ - WIFI_PROMISCUOUS_MODE = BIT(3), - /** AP mode setting enable */ - WIFI_AP_MODE = BIT(4), - /** Softap mode setting enable */ - WIFI_SOFTAP_MODE = BIT(5), -}; - -/** Mode filter settings */ -enum wifi_filter { - /** Support management, data and control packet sniffing */ - WIFI_PACKET_FILTER_ALL = BIT(0), - /** Support only sniffing of management packets */ - WIFI_PACKET_FILTER_MGMT = BIT(1), - /** Support only sniffing of data packets */ - WIFI_PACKET_FILTER_DATA = BIT(2), - /** Support only sniffing of control packets */ - WIFI_PACKET_FILTER_CTRL = BIT(3), -}; - /** Wi-Fi Target Wake Time (TWT) operations. */ enum wifi_twt_operation { /** TWT setup operation */ diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 1be98b927cb..7a572eb673d 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -69,12 +69,6 @@ enum net_request_wifi_cmd { NET_REQUEST_WIFI_CMD_REG_DOMAIN, /** Set power save timeout */ NET_REQUEST_WIFI_CMD_PS_TIMEOUT, - /** Set or get Mode of operation */ - NET_REQUEST_WIFI_CMD_MODE, - /** Set or get packet filter setting for current mode */ - NET_REQUEST_WIFI_CMD_PACKET_FILTER, - /** Set or get Wi-Fi channel for Monitor or TX-Injection mode */ - NET_REQUEST_WIFI_CMD_CHANNEL, NET_REQUEST_WIFI_CMD_MAX }; @@ -137,21 +131,6 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_REG_DOMAIN); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PS_TIMEOUT); -#define NET_REQUEST_WIFI_MODE \ - (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_MODE) - -NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_MODE); - -#define NET_REQUEST_WIFI_PACKET_FILTER \ - (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PACKET_FILTER) - -NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PACKET_FILTER); - -#define NET_REQUEST_WIFI_CHANNEL \ - (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_CHANNEL) - -NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL); - /** Wi-Fi management events */ enum net_event_wifi_cmd { /** Scan results available */ @@ -530,37 +509,6 @@ union wifi_mgmt_events { struct wifi_twt_params twt_params; }; -/** Wi-Fi mode setup */ -struct wifi_mode_info { - /** Mode setting for a specific mode of operation */ - uint8_t mode; - /** Interface index */ - uint8_t if_index; - /** Get or set operation */ - enum wifi_mgmt_op oper; -}; - -/** Wi-Fi filter setting for monitor, prmoiscuous, TX-injection modes */ -struct wifi_filter_info { - /** Filter setting */ - uint8_t filter; - /** Interface index */ - uint8_t if_index; - /** Filter buffer size */ - uint16_t buffer_size; - /** Get or set operation */ - enum wifi_mgmt_op oper; -}; - -/** Wi-Fi channel setting for monitor and TX-injection modes */ -struct wifi_channel_info { - /** Channel value to set */ - uint16_t channel; - /** Interface index */ - uint8_t if_index; - /** Get or set operation */ - enum wifi_mgmt_op oper; -}; #include @@ -682,30 +630,6 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*reg_domain)(const struct device *dev, struct wifi_reg_domain *reg_domain); - /** Set or get packet filter settings for monitor and promiscuous modes - * - * @param dev Pointer to the device structure for the driver instance. - * @param packet filter settings - * - * @return 0 if ok, < 0 if error - */ - int (*filter)(const struct device *dev, struct wifi_filter_info *filter); - /** Set or get mode of operation - * - * @param dev Pointer to the device structure for the driver instance. - * @param mode settings - * - * @return 0 if ok, < 0 if error - */ - int (*mode)(const struct device *dev, struct wifi_mode_info *mode); - /** Set or get current channel of operation - * - * @param dev Pointer to the device structure for the driver instance. - * @param channel settings - * - * @return 0 if ok, < 0 if error - */ - int (*channel)(const struct device *dev, struct wifi_channel_info *channel); }; /** Wi-Fi management offload API */ diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index dba18f8154f..80f01b14e42 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -447,66 +447,6 @@ void wifi_mgmt_raise_twt_sleep_state(struct net_if *iface, sizeof(twt_sleep_state)); } -static int wifi_mode(uint32_t mgmt_request, struct net_if *iface, - void *data, size_t len) -{ - const struct device *dev = net_if_get_device(iface); - const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); - struct wifi_mode_info *mode_info = data; - - if (dev == NULL) { - return -ENODEV; - } - - if (wifi_mgmt_api == NULL || wifi_mgmt_api->mode == NULL) { - return -ENOTSUP; - } - - return wifi_mgmt_api->mode(dev, mode_info); -} - -NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_MODE, wifi_mode); - -static int wifi_packet_filter(uint32_t mgmt_request, struct net_if *iface, - void *data, size_t len) -{ - const struct device *dev = net_if_get_device(iface); - const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); - struct wifi_filter_info *filter_info = data; - - if (dev == NULL) { - return -ENODEV; - } - - if (wifi_mgmt_api == NULL || wifi_mgmt_api->filter == NULL) { - return -ENOTSUP; - } - - return wifi_mgmt_api->filter(dev, filter_info); -} - -NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PACKET_FILTER, wifi_packet_filter); - -static int wifi_channel(uint32_t mgmt_request, struct net_if *iface, - void *data, size_t len) -{ - const struct device *dev = net_if_get_device(iface); - const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); - struct wifi_channel_info *channel_info = data; - - if (dev == NULL) { - return -ENODEV; - } - - if (wifi_mgmt_api == NULL || wifi_mgmt_api->channel == NULL) { - return -ENOTSUP; - } - - return wifi_mgmt_api->channel(dev, channel_info); -} - -NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL, wifi_channel); - #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface, struct wifi_raw_scan_result *raw_scan_result) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 236fb32ee83..34dab2f9460 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -75,20 +75,12 @@ static bool parse_number(const struct shell *sh, long *param, char *str, long mi { char *endptr; char *str_tmp = str; - long num = 0; - - if ((str_tmp[0] == '0') && (str_tmp[1] == 'x')) { - /* Hexadecimal numbers take base 0 in strtol */ - num = strtol(str_tmp, &endptr, 0); - } else { - num = strtol(str_tmp, &endptr, 10); - } + long num = strtol(str_tmp, &endptr, 10); if (*endptr != '\0') { print(sh, SHELL_ERROR, "Invalid number: %s", str_tmp); return false; } - if ((num) < (min) || (num) > (max)) { print(sh, SHELL_WARNING, "Value out of range: %s, (%ld-%ld)", str_tmp, min, max); return false; @@ -1263,335 +1255,6 @@ static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *ar return 0; } -void parse_mode_args_to_params(const struct shell *sh, int argc, - char *argv[], struct wifi_mode_info *mode, - bool *do_mode_oper) -{ - int opt; - int option_index = 0; - - static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, - {"sta", no_argument, 0, 's'}, - {"monitor", no_argument, 0, 'm'}, - {"TX-injection", no_argument, 0, 't'}, - {"promiscuous", no_argument, 0, 'p'}, - {"ap", no_argument, 0, 'a'}, - {"softap", no_argument, 0, 'k'}, - {"get", no_argument, 0, 'g'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0}}; - - while ((opt = getopt_long(argc, argv, "i:smtpakgh", long_options, &option_index)) != -1) { - switch (opt) { - case 's': - mode->mode |= WIFI_STA_MODE; - break; - case 'm': - mode->mode |= WIFI_MONITOR_MODE; - break; - case 't': - mode->mode |= WIFI_TX_INJECTION_MODE; - break; - case 'p': - mode->mode |= WIFI_PROMISCUOUS_MODE; - break; - case 'a': - mode->mode |= WIFI_AP_MODE; - break; - case 'k': - mode->mode |= WIFI_SOFTAP_MODE; - break; - case 'g': - mode->oper = true; - break; - case 'i': - mode->if_index = (uint8_t)atoi(optarg); - break; - case 'h': - shell_help(sh); - *do_mode_oper = false; - break; - case '?': - default: - break; - } - } -} - -static int cmd_wifi_mode(const struct shell *sh, size_t argc, char *argv[]) -{ - struct net_if *iface; - struct wifi_mode_info mode_info = {0}; - int ret; - bool do_mode_oper = true; - - if (argc > 1) { - mode_info.oper = WIFI_MGMT_SET; - parse_mode_args_to_params(sh, argc, argv, &mode_info, &do_mode_oper); - } else { - shell_fprintf(sh, SHELL_ERROR, "Invalid number of arguments\n"); - return -EINVAL; - } - - if (do_mode_oper) { - /* Check interface index value. Mode validation must be performed by - * lower layer - */ - if (mode_info.if_index == 0) { - iface = net_if_get_first_wifi(); - if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find the default wifi interface\n"); - return -ENOEXEC; - } - mode_info.if_index = net_if_get_by_iface(iface); - } else { - iface = net_if_get_by_index(mode_info.if_index); - if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find interface for if_index %d\n", - mode_info.if_index); - return -ENOEXEC; - } - } - - ret = net_mgmt(NET_REQUEST_WIFI_MODE, iface, &mode_info, sizeof(mode_info)); - - if (ret) { - shell_fprintf(sh, SHELL_ERROR, "mode %s operation failed with reason %d\n", - mode_info.oper == WIFI_MGMT_GET ? "get" : "set", ret); - return -ENOEXEC; - } - - if (mode_info.oper == WIFI_MGMT_GET) { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi current mode is %x\n", - mode_info.mode); - } else { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi mode set to %x\n", mode_info.mode); - } - } - return 0; -} - -void parse_channel_args_to_params(const struct shell *sh, int argc, - char *argv[], struct wifi_channel_info *channel, - bool *do_channel_oper) -{ - int opt; - int option_index = 0; - - static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, - {"channel", required_argument, 0, 'c'}, - {"get", no_argument, 0, 'g'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0}}; - - while ((opt = getopt_long(argc, argv, "i:c:gh", long_options, &option_index)) != -1) { - switch (opt) { - case 'c': - channel->channel = (uint16_t)atoi(optarg); - break; - case 'i': - channel->if_index = (uint8_t)atoi(optarg); - break; - case 'g': - channel->oper = WIFI_MGMT_GET; - break; - case 'h': - shell_help(sh); - *do_channel_oper = false; - break; - case '?': - default: - break; - } - } -} - -static int cmd_wifi_channel(const struct shell *sh, size_t argc, char *argv[]) -{ - struct net_if *iface; - struct wifi_channel_info channel_info = {0}; - int ret; - bool do_channel_oper = true; - - if (argc > 1) { - channel_info.oper = WIFI_MGMT_SET; - parse_channel_args_to_params(sh, argc, argv, &channel_info, &do_channel_oper); - } else { - shell_fprintf(sh, SHELL_ERROR, "Invalid number of arguments\n"); - return -EINVAL; - } - - if (do_channel_oper) { - /* - * Validate parameters before sending to lower layer. - * Do it here instead of parse_channel_args_to_params - * as this is right before sending the parameters to - * the lower layer. - */ - - if (channel_info.if_index == 0) { - iface = net_if_get_first_wifi(); - if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find the default wifi interface\n"); - return -ENOEXEC; - } - channel_info.if_index = net_if_get_by_iface(iface); - } else { - iface = net_if_get_by_index(channel_info.if_index); - if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find interface for if_index %d\n", - channel_info.if_index); - return -ENOEXEC; - } - } - - if (channel_info.oper == WIFI_MGMT_SET) { - if ((channel_info.channel < WIFI_CHANNEL_MIN) || - (channel_info.channel > WIFI_CHANNEL_MAX)) { - shell_fprintf(sh, SHELL_ERROR, - "Invalid channel number. Range is (1-233)\n"); - return -ENOEXEC; - } - } - - ret = net_mgmt(NET_REQUEST_WIFI_CHANNEL, iface, - &channel_info, sizeof(channel_info)); - - if (ret) { - shell_fprintf(sh, SHELL_ERROR, - "channel %s operation failed with reason %d\n", - channel_info.oper == WIFI_MGMT_GET ? "get" : "set", ret); - return -ENOEXEC; - } - - if (channel_info.oper == WIFI_MGMT_GET) { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi current channel is: %d\n", - channel_info.channel); - } else { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi channel set to %d\n", - channel_info.channel); - } - } - return 0; -} - -void parse_filter_args_to_params(const struct shell *sh, int argc, - char *argv[], struct wifi_filter_info *filter, - bool *do_filter_oper) -{ - int opt; - int option_index = 0; - - static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, - {"capture_len", optional_argument, 0, 'b'}, - {"all", no_argument, 0, 'a'}, - {"mgmt", no_argument, 0, 'm'}, - {"ctrl", no_argument, 0, 'c'}, - {"data", no_argument, 0, 'd'}, - {"get", no_argument, 0, 'g'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0}}; - - while ((opt = getopt_long(argc, argv, "i:b:amcdgh", long_options, &option_index)) != -1) { - switch (opt) { - case 'a': - filter->filter |= WIFI_PACKET_FILTER_ALL; - break; - case 'm': - filter->filter |= WIFI_PACKET_FILTER_MGMT; - break; - case 'c': - filter->filter |= WIFI_PACKET_FILTER_DATA; - break; - case 'd': - filter->filter |= WIFI_PACKET_FILTER_CTRL; - break; - case 'i': - filter->if_index = (uint8_t)atoi(optarg); - break; - case 'b': - filter->buffer_size = (uint16_t)atoi(optarg); - break; - case 'h': - shell_help(sh); - *do_filter_oper = false; - break; - case 'g': - filter->oper = WIFI_MGMT_GET; - break; - case '?': - default: - break; - } - } -} - -static int cmd_wifi_packet_filter(const struct shell *sh, size_t argc, char *argv[]) -{ - struct net_if *iface; - struct wifi_filter_info packet_filter = {0}; - int ret; - bool do_filter_oper = true; - - if (argc > 1) { - packet_filter.oper = WIFI_MGMT_SET; - parse_filter_args_to_params(sh, argc, argv, &packet_filter, &do_filter_oper); - } else { - shell_fprintf(sh, SHELL_ERROR, "Invalid number of arguments\n"); - return -EINVAL; - } - - if (do_filter_oper) { - /* - * Validate parameters before sending to lower layer. - * Do it here instead of parse_filter_args_to_params - * as this is right before sending the parameters to - * the lower layer. filter and packet capture length - * value to be verified by the lower layer. - */ - if (packet_filter.if_index == 0) { - iface = net_if_get_first_wifi(); - if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find the default wifi interface\n"); - return -ENOEXEC; - } - packet_filter.if_index = net_if_get_by_iface(iface); - } else { - iface = net_if_get_by_index(packet_filter.if_index); - if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find interface for if_index %d\n", - packet_filter.if_index); - return -ENOEXEC; - } - } - - ret = net_mgmt(NET_REQUEST_WIFI_PACKET_FILTER, iface, - &packet_filter, sizeof(packet_filter)); - - if (ret) { - shell_fprintf(sh, SHELL_ERROR, - "Wi-Fi packet filter %s operation failed with reason %d\n", - packet_filter.oper == WIFI_MGMT_GET ? "get" : "set", ret); - return -ENOEXEC; - } - - if (packet_filter.oper == WIFI_MGMT_GET) { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi current mode packet filter is %d\n", - packet_filter.filter); - } else { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi mode packet filter set to %d\n", - packet_filter.filter); - } - } - return 0; -} - SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, SHELL_CMD(disable, NULL, "Disable Access Point mode", @@ -1665,55 +1328,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "-f: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain), - SHELL_CMD(mode, NULL, "mode operational setting\n" - "This command may be used to set the Wi-Fi device into a specific mode of operation\n" - "parameters:" - "[-i : Interface index - optional argument\n" - "[-s : Station mode.\n" - "[-m : Monitor mode.\n" - "[-p : Promiscuous mode.\n" - "[-t : TX-Injection mode.\n" - "[-a : AP mode.\n" - "[-k : Softap mode.\n" - "[-h : Help.\n" - "[-g : Get current mode for a specific interface index.\n" - "Usage: Get operation example for interface index 1\n" - "wifi mode -g -i1\n" - "Set operation example for interface index 1 - set station+promiscuous\n" - "wifi mode -i1 -sp\n", - cmd_wifi_mode), - SHELL_CMD(packet_filter, NULL, "mode filter setting\n" - "This command is used to set packet filter setting when\n" - "monitor, TX-Injection and promiscuous mode is enabled.\n" - "The different packet filter modes are control, management, data and enable all filters\n" - "parameters:" - "[-i : Interface index - optional argument.\n" - "[-a : Enable all packet filter modes\n" - "[-m : Enable management packets to allowed up the stack.\n" - "[-c : Enable control packets to be allowed up the stack.\n" - "[-d : Enable Data packets to be allowed up the stack.\n" - "[-g : Get current filter settings for a specific interface index.\n" - "<-b : Capture length buffer size for each packet to be captured - optional argument.\n" - "<-h : Help.\n" - "Usage: Get operation example for interface index 1\n" - "wifi packet_filter -g -i1\n" - "Set operation example for interface index 1 - set data+management frame filter\n" - "wifi packet_filter -i1 -md\n", - cmd_wifi_packet_filter), - SHELL_CMD(channel, NULL, "wifi channel setting\n" - "This command is used to set the channel when\n" - "monitor or TX-Injection mode is enabled.\n" - "Currently 20 MHz is only supported and no BW parameter is provided\n" - "parameters:" - "[-i : Interface index - optional argument.\n" - "[-c : Set a specific channel number to the lower layer.\n" - "[-g : Get current set channel number from the lower layer.\n" - "[-h : Help.\n" - "Usage: Get operation example for interface index 1\n" - "wifi channel -g -i1\n" - "Set operation example for interface index 1 (setting channel 5)\n" - "wifi -i1 -c5\n", - cmd_wifi_channel), SHELL_CMD_ARG(ps_timeout, NULL, " - PS inactivity timer(in ms)", From dc6cb1e3f7304c3dc0452d29ad79c4a2bb0e8ef0 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:57 +0000 Subject: [PATCH 0887/1623] Revert "[nrf fromtree] net: wifi: Fix crash in wifi_utils_parse_scan_ssids" This reverts commit e4ee01d63ffcf8405d868827ea7e1916b883c760. Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/Kconfig | 1 - subsys/net/l2/wifi/wifi_utils.c | 17 +---------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 6623456d84b..e034a745b5e 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -76,7 +76,6 @@ config WIFI_MGMT_SCAN_DWELL_TIME_PASSIVE config WIFI_MGMT_SCAN_SSID_FILT_MAX int "Maximum number of SSIDs that can be specified for SSID filtering" default 1 - range 1 4 help Maximum number of SSIDs that can be specified for SSID filtering. This can be set based on the underlying chipsets limitations. diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index ea0e42def47..6151f480d21 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -259,30 +259,15 @@ int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map) int wifi_utils_parse_scan_ssids(char *scan_ssids_str, char ssids[][WIFI_SSID_MAX_LEN + 1]) { - char parse_str[(WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1)) + 1]; char *ssid = NULL; char *ctx = NULL; uint8_t i = 0; - int len; if (!scan_ssids_str) { return -EINVAL; } - len = strlen(scan_ssids_str); - - if (len > (WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1))) { - NET_ERR("SSID string (%s) size (%d) exceeds maximum allowed value (%d)", - scan_ssids_str, - len, - (WIFI_MGMT_SCAN_SSID_FILT_MAX * (WIFI_SSID_MAX_LEN + 1))); - return -EINVAL; - } - - strncpy(parse_str, scan_ssids_str, len); - parse_str[len] = '\0'; - - ssid = strtok_r(parse_str, ",", &ctx); + ssid = strtok_r(scan_ssids_str, ",", &ctx); while (ssid) { if (strlen(ssid) > WIFI_SSID_MAX_LEN) { From 697c641b99f778e516ec35b5ef4a7621cdfbe723 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:57 +0000 Subject: [PATCH 0888/1623] Revert "[nrf fromtree] net: wifi: Fix crash in wifi_utils_parse_scan_bands" This reverts commit 09864f357bd2a56dc37c693b7bfe8e47df788e1f. Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi_mgmt.h | 2 -- subsys/net/l2/wifi/wifi_utils.c | 17 +---------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 7a572eb673d..57077a1c2f5 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -41,8 +41,6 @@ extern "C" { #define WIFI_MGMT_SCAN_SSID_FILT_MAX 0 #endif /* CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX */ -#define WIFI_MGMT_BAND_STR_SIZE_MAX 8 - /** Wi-Fi management commands */ enum net_request_wifi_cmd { /** Scan for Wi-Fi networks */ diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index 6151f480d21..f7e9d9af4dc 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -215,30 +215,15 @@ static int wifi_utils_validate_chan_str(char *chan_str) int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map) { - char parse_str[WIFI_MGMT_BAND_STR_SIZE_MAX + 1]; char *band_str = NULL; char *ctx = NULL; enum wifi_frequency_bands band = WIFI_FREQ_BAND_UNKNOWN; - int len; if (!scan_bands_str) { return -EINVAL; } - len = strlen(scan_bands_str); - - if (len > WIFI_MGMT_BAND_STR_SIZE_MAX) { - NET_ERR("Band string (%s) size (%d) exceeds maximum allowed value (%d)", - scan_bands_str, - len, - WIFI_MGMT_BAND_STR_SIZE_MAX); - return -EINVAL; - } - - strncpy(parse_str, scan_bands_str, len); - parse_str[len] = '\0'; - - band_str = strtok_r(parse_str, ",", &ctx); + band_str = strtok_r(scan_bands_str, ",", &ctx); while (band_str) { band = wifi_utils_map_band_str_to_idx(band_str); From ace40a3687ca2676ef5df149a5fef70267f4812f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:58 +0000 Subject: [PATCH 0889/1623] Revert "[nrf fromlist] cmake: Zephyr kernel version.h and app_version.h creation" This reverts commit be7e604c73b30a27bb9ff61353e2c833bb982f25. Signed-off-by: Dominik Ermel --- CMakeLists.txt | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e23650f262f..64e4fda5c2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -551,9 +551,31 @@ if(ZEPHYR_GIT_INDEX) set(git_dependency ${ZEPHYR_GIT_INDEX}) endif() +add_custom_command( + OUTPUT ${PROJECT_BINARY_DIR}/include/generated/version.h + COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} + -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/version.h + -DVERSION_TYPE=KERNEL + -DVERSION_FILE=${ZEPHYR_BASE}/VERSION + -DKERNEL_VERSION_CUSTOMIZATION="${KERNEL_VERSION_CUSTOMIZATION}" + ${build_version_argument} + -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake + DEPENDS ${ZEPHYR_BASE}/VERSION ${git_dependency} +) add_custom_target(version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/version.h) if(EXISTS ${APPLICATION_SOURCE_DIR}/VERSION) + add_custom_command( + OUTPUT ${PROJECT_BINARY_DIR}/include/generated/app_version.h + COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} + -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/app_version.h + -DVERSION_TYPE=APP + -DVERSION_FILE=${APPLICATION_SOURCE_DIR}/VERSION + -DAPP_VERSION_CUSTOMIZATION="${APP_VERSION_CUSTOMIZATION}" + ${build_version_argument} + -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake + DEPENDS ${APPLICATION_SOURCE_DIR}/VERSION ${git_dependency} + ) add_custom_target(app_version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/app_version.h) add_dependencies(zephyr_interface app_version_h) endif() @@ -604,32 +626,6 @@ endforeach() set(ZEPHYR_CURRENT_MODULE_DIR) set(ZEPHYR_CURRENT_CMAKE_DIR) -add_custom_command( - OUTPUT ${PROJECT_BINARY_DIR}/include/generated/version.h - COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} - -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/version.h - -DVERSION_TYPE=KERNEL - -DVERSION_FILE=${ZEPHYR_BASE}/VERSION - -DKERNEL_VERSION_CUSTOMIZATION="${KERNEL_VERSION_CUSTOMIZATION}" - ${build_version_argument} - -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake - DEPENDS ${ZEPHYR_BASE}/VERSION ${git_dependency} -) - -if(EXISTS ${APPLICATION_SOURCE_DIR}/VERSION) - add_custom_command( - OUTPUT ${PROJECT_BINARY_DIR}/include/generated/app_version.h - COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} - -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/app_version.h - -DVERSION_TYPE=APP - -DVERSION_FILE=${APPLICATION_SOURCE_DIR}/VERSION - -DAPP_VERSION_CUSTOMIZATION="${APP_VERSION_CUSTOMIZATION}" - ${build_version_argument} - -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake - DEPENDS ${APPLICATION_SOURCE_DIR}/VERSION ${git_dependency} - ) -endif() - get_property(LIBC_LINK_LIBRARIES TARGET zephyr_interface PROPERTY LIBC_LINK_LIBRARIES) zephyr_link_libraries(${LIBC_LINK_LIBRARIES}) From 13a0477d6b3f5319b6c0579567f93873618a5831 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:59 +0000 Subject: [PATCH 0890/1623] Revert "[nrf noup] ci: doc-build: use ubuntu-22.04 runner" This reverts commit 1479b0fc10df3b7542bb56c8b760287eb58ed3f2. Signed-off-by: Dominik Ermel --- .github/workflows/doc-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doc-build.yml b/.github/workflows/doc-build.yml index a18507e028d..40e170ddc8a 100644 --- a/.github/workflows/doc-build.yml +++ b/.github/workflows/doc-build.yml @@ -35,7 +35,7 @@ env: jobs: doc-build-html: name: "Documentation Build (HTML)" - runs-on: ubuntu-22.04 + runs-on: zephyr-runner-linux-x64-4xlarge timeout-minutes: 45 concurrency: group: doc-build-html-${{ github.ref }} From b0b14087bda15d17ba548f11572d1fdab18c93c2 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:30:59 +0000 Subject: [PATCH 0891/1623] Revert "[nrf noup] tree-wide: support NCS Partition Manager (PM) definitions" This reverts commit d1fa3da6c37763e1ae9306c43bfaf5cf965af594. Signed-off-by: Dominik Ermel --- cmake/modules/kernel.cmake | 4 -- drivers/flash/soc_flash_nrf.c | 11 ----- .../arm/aarch32/cortex_m/scripts/linker.ld | 46 ------------------- include/zephyr/storage/flash_map.h | 6 --- lib/libc/common/source/stdlib/malloc.c | 18 +------- lib/os/Kconfig.heap | 2 +- soc/arm/common/cortex_m/arm_mpu_regions.c | 13 ------ subsys/fs/littlefs_fs.c | 7 +-- subsys/ipc/rpmsg_service/rpmsg_backend.h | 27 ----------- 9 files changed, 4 insertions(+), 130 deletions(-) diff --git a/cmake/modules/kernel.cmake b/cmake/modules/kernel.cmake index 28ee922d40b..7e65c9cd186 100644 --- a/cmake/modules/kernel.cmake +++ b/cmake/modules/kernel.cmake @@ -242,7 +242,3 @@ if("${CMAKE_EXTRA_GENERATOR}" STREQUAL "Eclipse CDT4") include(${ZEPHYR_BASE}/cmake/ide/eclipse_cdt4_generator_amendment.cmake) eclipse_cdt4_generator_amendment(1) endif() - -if(ZEPHYR_NRF_MODULE_DIR) - include(${ZEPHYR_NRF_MODULE_DIR}/cmake/partition_manager.cmake) -endif() diff --git a/drivers/flash/soc_flash_nrf.c b/drivers/flash/soc_flash_nrf.c index f38492a41d1..fa433d1044b 100644 --- a/drivers/flash/soc_flash_nrf.c +++ b/drivers/flash/soc_flash_nrf.c @@ -37,11 +37,6 @@ LOG_MODULE_REGISTER(flash_nrf); #define SOC_NV_FLASH_NODE DT_INST(0, soc_nv_flash) -#if CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER -#include -#include -#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER */ - #ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE #define FLASH_SLOT_WRITE 7500 #if defined(CONFIG_SOC_FLASH_NRF_PARTIAL_ERASE) @@ -142,12 +137,6 @@ static int flash_nrf_read(const struct device *dev, off_t addr, return 0; } -#if CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER && PM_APP_ADDRESS - if (addr < PM_APP_ADDRESS) { - return soc_secure_mem_read(data, (void *)addr, len); - } -#endif - nrf_nvmc_buffer_read(data, (uint32_t)addr, len); return 0; diff --git a/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld b/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld index 85d55b2de29..92b6f02d029 100644 --- a/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld +++ b/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld @@ -26,35 +26,6 @@ #endif #define RAMABLE_REGION RAM -#if USE_PARTITION_MANAGER - -#include - -#if CONFIG_NCS_IS_VARIANT_IMAGE && defined(PM_S0_ID) -/* We are linking against S1, create symbol containing the flash ID of S0. - * This is used when writing code operating on the "other" slot. - */ -_image_1_primary_slot_id = PM_S0_ID; - -#else /* ! CONFIG_NCS_IS_VARIANT_IMAGE */ - -#ifdef PM_S1_ID -/* We are linking against S0, create symbol containing the flash ID of S1. - * This is used when writing code operating on the "other" slot. - */ -_image_1_primary_slot_id = PM_S1_ID; -#endif /* PM_S1_ID */ - -#endif /* CONFIG_NCS_IS_VARIANT_IMAGE */ - -#define ROM_ADDR PM_ADDRESS -#define ROM_SIZE PM_SIZE - -#define RAM_SIZE PM_SRAM_SIZE -#define RAM_ADDR PM_SRAM_ADDRESS - -#else /* ! USE_PARTITION_MANAGER */ - #if !defined(CONFIG_XIP) && (CONFIG_FLASH_SIZE == 0) #define ROM_ADDR RAM_ADDR #else @@ -81,23 +52,6 @@ _image_1_primary_slot_id = PM_S1_ID; #define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS #endif -#endif /* USE_PARTITION_MANAGER */ - -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay) -#define CCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ccm)) -#define CCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ccm)) -#endif - -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay) -#define ITCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_itcm)) -#define ITCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_itcm)) -#endif - -#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) -#define DTCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_dtcm)) -#define DTCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_dtcm)) -#endif - #if defined(CONFIG_CUSTOM_SECTION_ALIGN) _region_min_align = CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE; #else diff --git a/include/zephyr/storage/flash_map.h b/include/zephyr/storage/flash_map.h index cc4a246105d..380e58691e9 100644 --- a/include/zephyr/storage/flash_map.h +++ b/include/zephyr/storage/flash_map.h @@ -271,10 +271,6 @@ const char *flash_area_label(const struct flash_area *fa); */ uint8_t flash_area_erased_val(const struct flash_area *fa); -#if USE_PARTITION_MANAGER -#include -#else - #define FLASH_AREA_LABEL_EXISTS(label) __DEPRECATED_MACRO \ DT_HAS_FIXED_PARTITION_LABEL(label) @@ -347,8 +343,6 @@ uint8_t flash_area_erased_val(const struct flash_area *fa); #define FIXED_PARTITION_DEVICE(label) \ DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(label))) -#endif /* USE_PARTITION_MANAGER */ - #ifdef __cplusplus } #endif diff --git a/lib/libc/common/source/stdlib/malloc.c b/lib/libc/common/source/stdlib/malloc.c index 47583982838..50c688fa7f2 100644 --- a/lib/libc/common/source/stdlib/malloc.c +++ b/lib/libc/common/source/stdlib/malloc.c @@ -23,20 +23,6 @@ #include LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); -#if USE_PARTITION_MANAGER - -#include - -#define RAM_SIZE PM_SRAM_SIZE -#define RAM_ADDR PM_SRAM_ADDRESS - -#else /* ! USE_PARTITION_MANAGER */ - -#define RAM_SIZE (KB((size_t) CONFIG_SRAM_SIZE)) -#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS - -#endif /* USE_PARTITION_MANAGER */ - #ifdef CONFIG_COMMON_LIBC_MALLOC #if (CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE != 0) @@ -118,8 +104,8 @@ static POOL_SECTION unsigned char __aligned(HEAP_ALIGN) malloc_arena[HEAP_SIZE]; extern char _heap_sentry[]; # define HEAP_SIZE ROUND_DOWN((POINTER_TO_UINT(_heap_sentry) - HEAP_BASE), HEAP_ALIGN) # else -# define HEAP_SIZE ROUND_DOWN((RAM_SIZE - \ - ((size_t) HEAP_BASE - (size_t) RAM_ADDR)), HEAP_ALIGN) +# define HEAP_SIZE ROUND_DOWN((KB((size_t) CONFIG_SRAM_SIZE) - \ + ((size_t) HEAP_BASE - (size_t) CONFIG_SRAM_BASE_ADDRESS)), HEAP_ALIGN) # endif /* else CONFIG_XTENSA */ # endif /* else CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE > 0 */ diff --git a/lib/os/Kconfig.heap b/lib/os/Kconfig.heap index 1fa84ff41db..14fba87470b 100644 --- a/lib/os/Kconfig.heap +++ b/lib/os/Kconfig.heap @@ -51,7 +51,7 @@ config HEAP_LISTENER choice prompt "Supported heap sizes" depends on !64BIT - default SYS_HEAP_SMALL_ONLY if (SRAM_SIZE <= 256) && !PARTITION_MANAGER_ENABLED + default SYS_HEAP_SMALL_ONLY if (SRAM_SIZE <= 256) default SYS_HEAP_AUTO help Heaps using reduced-size chunk headers can accommodate so called diff --git a/soc/arm/common/cortex_m/arm_mpu_regions.c b/soc/arm/common/cortex_m/arm_mpu_regions.c index a7df11a19e1..557079ef5bc 100644 --- a/soc/arm/common/cortex_m/arm_mpu_regions.c +++ b/soc/arm/common/cortex_m/arm_mpu_regions.c @@ -9,9 +9,6 @@ #include #include -#if USE_PARTITION_MANAGER -#include -#endif static const struct arm_mpu_region mpu_regions[] = { /* Region 0 */ @@ -25,14 +22,6 @@ static const struct arm_mpu_region mpu_regions[] = { #endif /* Region 1 */ MPU_REGION_ENTRY("SRAM_0", -#if USE_PARTITION_MANAGER - PM_SRAM_ADDRESS, -#if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE) - REGION_RAM_ATTR(PM_SRAM_ADDRESS, PM_SRAM_SIZE)), -#else - REGION_RAM_ATTR(REGION_SRAM_SIZE)), -#endif -#else CONFIG_SRAM_BASE_ADDRESS, #if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE) REGION_RAM_ATTR(CONFIG_SRAM_BASE_ADDRESS, \ @@ -41,8 +30,6 @@ static const struct arm_mpu_region mpu_regions[] = { REGION_RAM_ATTR(REGION_SRAM_SIZE)), #endif -#endif /* USE_PARTITION_MANAGER */ - /* DT-defined regions */ DT_MEMORY_ATTR_APPLY(ARM_MPU_REGION_INIT) }; diff --git a/subsys/fs/littlefs_fs.c b/subsys/fs/littlefs_fs.c index c4c75bb48c4..3058f402d73 100644 --- a/subsys/fs/littlefs_fs.c +++ b/subsys/fs/littlefs_fs.c @@ -1054,12 +1054,7 @@ struct fs_mount_t FS_FSTAB_ENTRY(DT_DRV_INST(inst)) = { \ .type = FS_LITTLEFS, \ .mnt_point = DT_INST_PROP(inst, mount_point), \ .fs_data = &fs_data_##inst, \ - .storage_dev = (void *) \ - COND_CODE_1(USE_PARTITION_MANAGER, \ - (COND_CODE_1(FIXED_PARTITION_EXISTS(littlefs_storage), \ - (FIXED_PARTITION_ID(littlefs_storage)), \ - (FIXED_PARTITION_ID(storage)))), \ - (DT_FIXED_PARTITION_ID(FS_PARTITION(inst)))), \ + .storage_dev = (void *)DT_FIXED_PARTITION_ID(FS_PARTITION(inst)), \ .flags = FSTAB_ENTRY_DT_MOUNT_FLAGS(DT_DRV_INST(inst)), \ }; diff --git a/subsys/ipc/rpmsg_service/rpmsg_backend.h b/subsys/ipc/rpmsg_service/rpmsg_backend.h index 9996e1d74d9..a74e46b8520 100644 --- a/subsys/ipc/rpmsg_service/rpmsg_backend.h +++ b/subsys/ipc/rpmsg_service/rpmsg_backend.h @@ -13,35 +13,8 @@ extern "C" { #endif -#if CONFIG_PARTITION_MANAGER_ENABLED - -#include "pm_config.h" - -#if defined(PM_RPMSG_NRF53_SRAM_ADDRESS) || defined(PM__RPMSG_NRF53_SRAM_ADDRESS) - -#if defined(PM_RPMSG_NRF53_SRAM_ADDRESS) -#define VDEV_START_ADDR PM_RPMSG_NRF53_SRAM_ADDRESS -#define VDEV_SIZE PM_RPMSG_NRF53_SRAM_SIZE -#else -/* The current image is a child image in a different domain than the image - * which defined the required values. To reach the values of the parent domain - * we use the 'PM__' variant of the define. - */ -#define VDEV_START_ADDR PM__RPMSG_NRF53_SRAM_ADDRESS -#define VDEV_SIZE PM__RPMSG_NRF53_SRAM_SIZE -#endif /* defined(PM_RPMSG_NRF53_SRAM_ADDRESS) */ - -#else #define VDEV_START_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ipc_shm)) #define VDEV_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ipc_shm)) -#endif /* defined(PM_RPMSG_NRF53_SRAM_ADDRESS) || defined(PM__RPMSG_NRF53_SRAM_ADDRESS) */ - -#else - -#define VDEV_START_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ipc_shm)) -#define VDEV_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ipc_shm)) - -#endif /* CONFIG_PARTITION_MANAGER_ENABLED */ #define VDEV_STATUS_ADDR VDEV_START_ADDR #define VDEV_STATUS_SIZE 0x400 From af1a0352a1b35a23e4d9803abac5151410659e5c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:00 +0000 Subject: [PATCH 0892/1623] Revert "[nrf noup] mgmt/mcumgr: Bootutil hooks to handle image-1" This reverts commit 063b584e78395eb02a1e7cbd82a0ed3251b383f3. Signed-off-by: Dominik Ermel --- subsys/mgmt/mcumgr/CMakeLists.txt | 8 ------ subsys/mgmt/mcumgr/Kconfig | 1 - .../mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c | 27 ------------------- 3 files changed, 36 deletions(-) delete mode 100644 subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c diff --git a/subsys/mgmt/mcumgr/CMakeLists.txt b/subsys/mgmt/mcumgr/CMakeLists.txt index ad088eca067..39d4a4ca8ce 100644 --- a/subsys/mgmt/mcumgr/CMakeLists.txt +++ b/subsys/mgmt/mcumgr/CMakeLists.txt @@ -16,11 +16,3 @@ add_subdirectory(transport) add_subdirectory_ifdef(CONFIG_SMP_CLIENT smp_client) zephyr_library_link_libraries(mgmt_mcumgr) - -if (CONFIG_BOOT_IMAGE_ACCESS_HOOKS) - zephyr_include_directories( - ${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/bootutil/include - ${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/zephyr/include - ) - zephyr_library_sources(bootutil_hooks/nrf53_hooks.c) -endif() diff --git a/subsys/mgmt/mcumgr/Kconfig b/subsys/mgmt/mcumgr/Kconfig index a25ee0dc625..8af4ffe2738 100644 --- a/subsys/mgmt/mcumgr/Kconfig +++ b/subsys/mgmt/mcumgr/Kconfig @@ -7,7 +7,6 @@ menuconfig MCUMGR depends on NET_BUF depends on ZCBOR imply CRC - imply BOOT_IMAGE_ACCESS_HOOKS if (SOC_NRF5340_CPUAPP_QKAA && MCUMGR_GRP_IMG) help This option enables the mcumgr management library. diff --git a/subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c b/subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c deleted file mode 100644 index 9971a4e0843..00000000000 --- a/subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include "bootutil/bootutil_public.h" - -int boot_read_swap_state_primary_slot_hook(int image_index, - struct boot_swap_state *state) -{ - if (image_index == 1) { - /* Pretend that primary slot of image 1 unpopulated */ - state->magic = BOOT_MAGIC_UNSET; - state->swap_type = BOOT_SWAP_TYPE_NONE; - state->image_num = image_index; - state->copy_done = BOOT_FLAG_UNSET; - state->image_ok = BOOT_FLAG_UNSET; - - /* Prevent bootutil from trying to obtain true info */ - return 0; - } - - return BOOT_HOOK_REGULAR; -} From 100d91d7ff7a4499cffe58cc9b3973f112e0a52a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:00 +0000 Subject: [PATCH 0893/1623] Revert "[nrf fromtree] drivers: flash: nrf_qspi_nor: Add support for XIP at boot" This reverts commit f769ab6e3e3a96d83aa9ba22bf827840da97e5b9. Signed-off-by: Dominik Ermel --- drivers/flash/Kconfig.nordic_qspi_nor | 14 ++------------ drivers/flash/nrf_qspi_nor.c | 21 +-------------------- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/drivers/flash/Kconfig.nordic_qspi_nor b/drivers/flash/Kconfig.nordic_qspi_nor index 7b9fa05eb7f..16252e0812c 100644 --- a/drivers/flash/Kconfig.nordic_qspi_nor +++ b/drivers/flash/Kconfig.nordic_qspi_nor @@ -14,8 +14,8 @@ menuconfig NORDIC_QSPI_NOR if NORDIC_QSPI_NOR config NORDIC_QSPI_NOR_INIT_PRIORITY - int "Init priority" - default 41 + int + default 80 help Device driver initialization priority. @@ -39,14 +39,4 @@ config NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE if the data is larger than the configured size. Must be a multiple of 4. When set to 0, the feature is disabled. -config NORDIC_QSPI_NOR_XIP - bool "XIP (eXecute in place)" - depends on SOC_NRF5340_CPUAPP - help - Enable setting up the QSPI NOR driver to allow for execution of code - stored in QSPI XIP region. Note that for this functionality to work, - the QSPI NOR init priority must be set so that no XIP code in the - QSPI NOR flash chip is executed until the driver has been setup. - This will also disable power management for the QSPI NOR flash chip. - endif # NORDIC_QSPI_NOR diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index e2ce6e6a706..b2455ba3c6f 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -179,8 +179,6 @@ static bool qspi_initialized; static int qspi_device_init(const struct device *dev); static void qspi_device_uninit(const struct device *dev); -void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable); -void z_vrfy_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable); #define WORD_SIZE 4 @@ -1231,7 +1229,6 @@ static int qspi_nor_configure(const struct device *dev) */ static int qspi_nor_init(const struct device *dev) { - int rc; const struct qspi_nor_config *dev_config = dev->config; int ret = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); @@ -1241,19 +1238,7 @@ static int qspi_nor_init(const struct device *dev) IRQ_CONNECT(DT_IRQN(QSPI_NODE), DT_IRQ(QSPI_NODE, priority), nrfx_isr, nrfx_qspi_irq_handler, 0); - - rc = qspi_nor_configure(dev); - -#ifdef CONFIG_NORDIC_QSPI_NOR_XIP - if (!rc) { - /* Enable XIP mode for QSPI NOR flash, this will prevent the - * flash from being powered down - */ - z_impl_nrf_qspi_nor_xip_enable(dev, true); - } -#endif - - return rc; + return qspi_nor_configure(dev); } #if defined(CONFIG_FLASH_PAGE_LAYOUT) @@ -1384,10 +1369,6 @@ static int qspi_nor_pm_action(const struct device *dev, } #endif - if (dev_data->xip_enabled) { - return -EBUSY; - } - if (nrfx_qspi_mem_busy_check() != NRFX_SUCCESS) { return -EBUSY; } From f70576bb2f2f359d84934eb41488d4bd8ee6f2b5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:01 +0000 Subject: [PATCH 0894/1623] Revert "[nrf fromtree] bluetooth: Make long workqueue init priority configurable" This reverts commit 41b1428e720e72bdbea7b811840038b41be5e12b. Signed-off-by: Dominik Ermel --- subsys/bluetooth/host/Kconfig | 7 ------- subsys/bluetooth/host/long_wq.c | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index a4cf2e0959b..19754705200 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -23,13 +23,6 @@ config BT_LONG_WQ_PRIO int "Long workqueue priority. Should be pre-emptible." default 10 range 0 NUM_PREEMPT_PRIORITIES - -config BT_LONG_WQ_INIT_PRIO - int "Long workqueue init priority" - default 50 - help - Init priority level to setup the long workqueue. - endif # BT_LONG_WQ config BT_HCI_HOST diff --git a/subsys/bluetooth/host/long_wq.c b/subsys/bluetooth/host/long_wq.c index 2136739c243..61f86d0c909 100644 --- a/subsys/bluetooth/host/long_wq.c +++ b/subsys/bluetooth/host/long_wq.c @@ -40,4 +40,4 @@ static int long_wq_init(void) return 0; } -SYS_INIT(long_wq_init, POST_KERNEL, CONFIG_BT_LONG_WQ_INIT_PRIO); +SYS_INIT(long_wq_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); From 482704ae428703befde2897f2b8c13dde9c9319b Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:01 +0000 Subject: [PATCH 0895/1623] Revert "[nrf noup] ci: Update Thread test-spec entry" This reverts commit 488716469816d193dd5b7ffb53d9eb57dfa36c5a. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 62b92e74d0f..03e02441069 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -132,24 +132,25 @@ - "**/*" "CI-homekit-test": - - "modules/openthread/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" + - "include/dfu/**/*" + - "include/mgmt/mcumgr/**/*" - "soc/arm/nordic_nrf/**/*" - - "subsys/net/**/*" + - "subsys/dfu/**/*" - "subsys/settings/**/*" + - "subsys/net/lib/openthread/**/*" + - "subsys/mgmt/mcumgr/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" + - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" - any: - "subsys/bluetooth/**/*" - "!subsys/bluetooth/mesh/**/*" - - "!subsys/bluetooth/audio/**/*" "CI-thread-test": - - "include/zephyr/net/**/*" + - "subsys/net/**/*" - "modules/mbedtls/**/*" + - "include/zephyr/net/**/*" - "modules/openthread/**/*" - "samples/net/openthread/**/*" - - "soc/arm/nordic_nrf/**/*" - - "subsys/net/**/*" - - "subsys/settings/**/*" "CI-nfc-test": - "**/*" From a4039d0271878b29785dc797963720ac879c8a38 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:01 +0000 Subject: [PATCH 0896/1623] Revert "[nrf noup] ci: Update Thread test-spec entry" This reverts commit 6340daeb1824fa7f92d2e847d0eb68be53b21d51. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 03e02441069..f81ac31cf75 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -146,11 +146,7 @@ - "!subsys/bluetooth/mesh/**/*" "CI-thread-test": - - "subsys/net/**/*" - - "modules/mbedtls/**/*" - - "include/zephyr/net/**/*" - - "modules/openthread/**/*" - - "samples/net/openthread/**/*" + - "**/*" "CI-nfc-test": - "**/*" From 655e8d408601aac59a96f597046890f0778010cf Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:01 +0000 Subject: [PATCH 0897/1623] Revert "[nrf fromlist] zperf: Add support to configure context priority" This reverts commit 427badb22bfd80c63a691163b2d355bb1e3028a5. Signed-off-by: Dominik Ermel --- include/zephyr/net/zperf.h | 1 - subsys/net/lib/zperf/zperf_common.c | 20 +----------- subsys/net/lib/zperf/zperf_internal.h | 2 +- subsys/net/lib/zperf/zperf_shell.c | 39 ----------------------- subsys/net/lib/zperf/zperf_tcp_uploader.c | 2 +- subsys/net/lib/zperf/zperf_udp_uploader.c | 2 +- 6 files changed, 4 insertions(+), 62 deletions(-) diff --git a/include/zephyr/net/zperf.h b/include/zephyr/net/zperf.h index cd86541721e..447ffec670c 100644 --- a/include/zephyr/net/zperf.h +++ b/include/zephyr/net/zperf.h @@ -37,7 +37,6 @@ struct zperf_upload_params { struct { uint8_t tos; int tcp_nodelay; - int priority; } options; }; diff --git a/subsys/net/lib/zperf/zperf_common.c b/subsys/net/lib/zperf/zperf_common.c index efe36cf69cd..aa29bc99043 100644 --- a/subsys/net/lib/zperf/zperf_common.c +++ b/subsys/net/lib/zperf/zperf_common.c @@ -131,7 +131,7 @@ const struct in6_addr *zperf_get_default_if_in6_addr(void) } int zperf_prepare_upload_sock(const struct sockaddr *peer_addr, int tos, - int priority, int proto) + int proto) { socklen_t addrlen = peer_addr->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : @@ -192,24 +192,6 @@ int zperf_prepare_upload_sock(const struct sockaddr *peer_addr, int tos, return -EINVAL; } - if (IS_ENABLED(CONFIG_NET_CONTEXT_PRIORITY) && priority >= 0) { - uint8_t prio = priority; - - if (!IS_ENABLED(CONFIG_NET_ALLOW_ANY_PRIORITY) && - (prio > NET_MAX_PRIORITIES)) { - NET_ERR("Priority %d is too large, maximum is %d", - priority, NET_MAX_PRIORITIES); - return -EINVAL; - } - - if (zsock_setsockopt(sock, SOL_SOCKET, SO_PRIORITY, - &prio, - sizeof(prio)) != 0) { - NET_WARN("Failed to set SOL_SOCKET - SO_PRIORITY socket option."); - return -EINVAL; - } - } - ret = zsock_connect(sock, peer_addr, addrlen); if (ret < 0) { NET_ERR("Connect failed (%d)", errno); diff --git a/subsys/net/lib/zperf/zperf_internal.h b/subsys/net/lib/zperf/zperf_internal.h index 96dd9ea9123..5bef0331f6f 100644 --- a/subsys/net/lib/zperf/zperf_internal.h +++ b/subsys/net/lib/zperf/zperf_internal.h @@ -99,7 +99,7 @@ const struct in_addr *zperf_get_default_if_in4_addr(void); const struct in6_addr *zperf_get_default_if_in6_addr(void); int zperf_prepare_upload_sock(const struct sockaddr *peer_addr, int tos, - int priority, int proto); + int proto); uint32_t zperf_packet_duration(uint32_t packet_size, uint32_t rate_in_kbps); diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index 3a8a9c61c4b..d3bf11a7b33 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -642,7 +642,6 @@ static int shell_cmd_upload(const struct shell *sh, size_t argc, int start = 0; size_t opt_cnt = 0; - param.options.priority = -1; is_udp = proto == IPPROTO_UDP; /* Parse options */ @@ -681,19 +680,6 @@ static int shell_cmd_upload(const struct shell *sh, size_t argc, opt_cnt += 1; break; -#ifdef CONFIG_NET_CONTEXT_PRIORITY - case 'p': - param.options.priority = parse_arg(&i, argc, argv); - if (param.options.priority < 0 || - param.options.priority > UINT8_MAX) { - shell_fprintf(sh, SHELL_WARNING, - "Parse error: %s\n", argv[i]); - return -ENOEXEC; - } - opt_cnt += 2; - break; -#endif /* CONFIG_NET_CONTEXT_PRIORITY */ - default: shell_fprintf(sh, SHELL_WARNING, "Unrecognized argument: %s\n", argv[i]); @@ -867,19 +853,6 @@ static int shell_cmd_upload2(const struct shell *sh, size_t argc, opt_cnt += 1; break; -#ifdef CONFIG_NET_CONTEXT_PRIORITY - case 'p': - param.options.priority = parse_arg(&i, argc, argv); - if (param.options.priority == -1 || - param.options.priority > UINT8_MAX) { - shell_fprintf(sh, SHELL_WARNING, - "Parse error: %s\n", argv[i]); - return -ENOEXEC; - } - opt_cnt += 2; - break; -#endif /* CONFIG_NET_CONTEXT_PRIORITY */ - default: shell_fprintf(sh, SHELL_WARNING, "Unrecognized argument: %s\n", argv[i]); @@ -1173,9 +1146,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_tcp, "-S tos: Specify IPv4/6 type of service\n" "-a: Asynchronous call (shell will not block for the upload)\n" "-n: Disable Nagle's algorithm\n" -#ifdef CONFIG_NET_CONTEXT_PRIORITY - "-p: Specify custom packet priority\n" -#endif /* CONFIG_NET_CONTEXT_PRIORITY */ "Example: tcp upload 192.0.2.2 1111 1 1K\n" "Example: tcp upload 2001:db8::2\n", cmd_tcp_upload), @@ -1189,9 +1159,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_tcp, "Available options:\n" "-S tos: Specify IPv4/6 type of service\n" "-a: Asynchronous call (shell will not block for the upload)\n" -#ifdef CONFIG_NET_CONTEXT_PRIORITY - "-p: Specify custom packet priority\n" -#endif /* CONFIG_NET_CONTEXT_PRIORITY */ "Example: tcp upload2 v6 1 1K\n" "Example: tcp upload2 v4\n" "-n: Disable Nagle's algorithm\n" @@ -1231,9 +1198,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp, "Available options:\n" "-S tos: Specify IPv4/6 type of service\n" "-a: Asynchronous call (shell will not block for the upload)\n" -#ifdef CONFIG_NET_CONTEXT_PRIORITY - "-p: Specify custom packet priority\n" -#endif /* CONFIG_NET_CONTEXT_PRIORITY */ "Example: udp upload 192.0.2.2 1111 1 1K 1M\n" "Example: udp upload 2001:db8::2\n", cmd_udp_upload), @@ -1248,9 +1212,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp, "Available options:\n" "-S tos: Specify IPv4/6 type of service\n" "-a: Asynchronous call (shell will not block for the upload)\n" -#ifdef CONFIG_NET_CONTEXT_PRIORITY - "-p: Specify custom packet priority\n" -#endif /* CONFIG_NET_CONTEXT_PRIORITY */ "Example: udp upload2 v4 1 1K 1M\n" "Example: udp upload2 v6\n" #if defined(CONFIG_NET_IPV6) && defined(MY_IP6ADDR_SET) diff --git a/subsys/net/lib/zperf/zperf_tcp_uploader.c b/subsys/net/lib/zperf/zperf_tcp_uploader.c index 3e72f81e54b..97fd4f57f71 100644 --- a/subsys/net/lib/zperf/zperf_tcp_uploader.c +++ b/subsys/net/lib/zperf/zperf_tcp_uploader.c @@ -117,7 +117,7 @@ int zperf_tcp_upload(const struct zperf_upload_params *param, } sock = zperf_prepare_upload_sock(¶m->peer_addr, param->options.tos, - param->options.priority, IPPROTO_TCP); + IPPROTO_TCP); if (sock < 0) { return sock; } diff --git a/subsys/net/lib/zperf/zperf_udp_uploader.c b/subsys/net/lib/zperf/zperf_udp_uploader.c index e7e2efb9a08..1310063437b 100644 --- a/subsys/net/lib/zperf/zperf_udp_uploader.c +++ b/subsys/net/lib/zperf/zperf_udp_uploader.c @@ -284,7 +284,7 @@ int zperf_udp_upload(const struct zperf_upload_params *param, } sock = zperf_prepare_upload_sock(¶m->peer_addr, param->options.tos, - param->options.priority, IPPROTO_UDP); + IPPROTO_UDP); if (sock < 0) { return sock; } From 0f80969a75658e1ebdf0589472046fb823a770a3 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:02 +0000 Subject: [PATCH 0898/1623] Revert "[nrf fromlist] net: Add configuration option to allow any priority" This reverts commit 1675a8a5e9536587b9225953e08dcb286425d79d. Signed-off-by: Dominik Ermel --- subsys/net/ip/Kconfig | 6 ------ subsys/net/ip/icmpv4.c | 3 +-- subsys/net/ip/icmpv6.c | 2 -- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/subsys/net/ip/Kconfig b/subsys/net/ip/Kconfig index d2ca36b845c..d7edb988553 100644 --- a/subsys/net/ip/Kconfig +++ b/subsys/net/ip/Kconfig @@ -290,12 +290,6 @@ config NET_RX_DEFAULT_PRIORITY What is the default network RX packet priority if user has not set one. The value 0 means lowest priority and 7 is the highest. -config NET_ALLOW_ANY_PRIORITY - bool "Allow any network packet priority to be used" - help - If this is set, then any user given network packet priority can be used. Otherwise - the network packet priorities are limited to 0-7 range. - config NET_IP_ADDR_CHECK bool "Check IP address validity before sending IP packet" default y diff --git a/subsys/net/ip/icmpv4.c b/subsys/net/ip/icmpv4.c index ed69903bd8e..058233a7f97 100644 --- a/subsys/net/ip/icmpv4.c +++ b/subsys/net/ip/icmpv4.c @@ -538,13 +538,12 @@ int net_icmpv4_send_echo_request(struct net_if *iface, return -ENOMEM; } -#if !defined(CONFIG_NET_ALLOW_ANY_PRIORITY) if (priority > NET_MAX_PRIORITIES) { NET_ERR("Priority %d is too large, maximum is %d", priority, NET_MAX_PRIORITIES); return -EINVAL; } -#endif /* !CONFIG_NET_ALLOW_ANY_PRIORITY */ + if (priority < 0) { net_pkt_set_ip_dscp(pkt, net_ipv4_get_dscp(tos)); net_pkt_set_ip_ecn(pkt, net_ipv4_get_ecn(tos)); diff --git a/subsys/net/ip/icmpv6.c b/subsys/net/ip/icmpv6.c index 9abc034e1fb..f1286229536 100644 --- a/subsys/net/ip/icmpv6.c +++ b/subsys/net/ip/icmpv6.c @@ -363,13 +363,11 @@ int net_icmpv6_send_echo_request(struct net_if *iface, return -ENOMEM; } -#if !defined(CONFIG_NET_ALLOW_ANY_PRIORITY) if (priority > NET_MAX_PRIORITIES) { NET_ERR("Priority %d is too large, maximum is %d", priority, NET_MAX_PRIORITIES); return -EINVAL; } -#endif /* !CONFIG_NET_ALLOW_ANY_PRIORITY */ if (priority < 0) { net_pkt_set_ip_dscp(pkt, net_ipv6_get_dscp(tc)); From faa20cbf738c5283c5bf58ebeed39fa9b4114cb6 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:02 +0000 Subject: [PATCH 0899/1623] Revert "[nrf fromlist] net: Add priority to ping" This reverts commit 83d5224ee0287aa5a9fe75a3cf90263a5f6fa8f0. Signed-off-by: Dominik Ermel --- subsys/net/ip/icmpv4.c | 15 ++------------- subsys/net/ip/icmpv4.h | 3 --- subsys/net/ip/icmpv6.c | 15 ++------------- subsys/net/ip/icmpv6.h | 3 --- subsys/net/ip/net_shell.c | 15 +-------------- subsys/net/lib/zperf/zperf_shell.c | 2 +- 6 files changed, 6 insertions(+), 47 deletions(-) diff --git a/subsys/net/ip/icmpv4.c b/subsys/net/ip/icmpv4.c index 058233a7f97..5c3d844be8a 100644 --- a/subsys/net/ip/icmpv4.c +++ b/subsys/net/ip/icmpv4.c @@ -507,7 +507,6 @@ int net_icmpv4_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tos, - int priority, const void *data, size_t data_size) { @@ -538,18 +537,8 @@ int net_icmpv4_send_echo_request(struct net_if *iface, return -ENOMEM; } - if (priority > NET_MAX_PRIORITIES) { - NET_ERR("Priority %d is too large, maximum is %d", - priority, NET_MAX_PRIORITIES); - return -EINVAL; - } - - if (priority < 0) { - net_pkt_set_ip_dscp(pkt, net_ipv4_get_dscp(tos)); - net_pkt_set_ip_ecn(pkt, net_ipv4_get_ecn(tos)); - } else { - net_pkt_set_priority(pkt, priority); - } + net_pkt_set_ip_dscp(pkt, net_ipv4_get_dscp(tos)); + net_pkt_set_ip_ecn(pkt, net_ipv4_get_ecn(tos)); if (net_ipv4_create(pkt, src, dst) || icmpv4_create(pkt, NET_ICMPV4_ECHO_REQUEST, 0)) { diff --git a/subsys/net/ip/icmpv4.h b/subsys/net/ip/icmpv4.h index 492fc6e84a0..bfce2e8d9e6 100644 --- a/subsys/net/ip/icmpv4.h +++ b/subsys/net/ip/icmpv4.h @@ -82,7 +82,6 @@ int net_icmpv4_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tos, - int priority, const void *data, size_t data_size); #else @@ -91,7 +90,6 @@ static inline int net_icmpv4_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tos, - int priority, const void *data, size_t data_size) { @@ -100,7 +98,6 @@ static inline int net_icmpv4_send_echo_request(struct net_if *iface, ARG_UNUSED(identifier); ARG_UNUSED(sequence); ARG_UNUSED(tos); - ARG_UNUSED(priority); ARG_UNUSED(data); ARG_UNUSED(data_size); diff --git a/subsys/net/ip/icmpv6.c b/subsys/net/ip/icmpv6.c index f1286229536..95252a7c156 100644 --- a/subsys/net/ip/icmpv6.c +++ b/subsys/net/ip/icmpv6.c @@ -341,7 +341,6 @@ int net_icmpv6_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tc, - int priority, const void *data, size_t data_size) { @@ -363,18 +362,8 @@ int net_icmpv6_send_echo_request(struct net_if *iface, return -ENOMEM; } - if (priority > NET_MAX_PRIORITIES) { - NET_ERR("Priority %d is too large, maximum is %d", - priority, NET_MAX_PRIORITIES); - return -EINVAL; - } - - if (priority < 0) { - net_pkt_set_ip_dscp(pkt, net_ipv6_get_dscp(tc)); - net_pkt_set_ip_ecn(pkt, net_ipv6_get_ecn(tc)); - } else { - net_pkt_set_priority(pkt, priority); - } + net_pkt_set_ip_dscp(pkt, net_ipv6_get_dscp(tc)); + net_pkt_set_ip_ecn(pkt, net_ipv6_get_ecn(tc)); if (net_ipv6_create(pkt, src, dst) || net_icmpv6_create(pkt, NET_ICMPV6_ECHO_REQUEST, 0)) { diff --git a/subsys/net/ip/icmpv6.h b/subsys/net/ip/icmpv6.h index d71d9959c14..f0c586a7cf8 100644 --- a/subsys/net/ip/icmpv6.h +++ b/subsys/net/ip/icmpv6.h @@ -222,7 +222,6 @@ int net_icmpv6_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tc, - int priority, const void *data, size_t data_size); #else @@ -231,7 +230,6 @@ static inline int net_icmpv6_send_echo_request(struct net_if *iface, uint16_t identifier, uint16_t sequence, uint8_t tc, - int priority, const void *data, size_t data_size) { @@ -240,7 +238,6 @@ static inline int net_icmpv6_send_echo_request(struct net_if *iface, ARG_UNUSED(identifier); ARG_UNUSED(sequence); ARG_UNUSED(tc); - ARG_UNUSED(priority); ARG_UNUSED(data); ARG_UNUSED(data_size); diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index c5b07afd6aa..286d0eca8a9 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -4279,7 +4279,6 @@ static struct ping_context { uint32_t sequence; uint16_t payload_size; uint8_t tos; - int priority; } ping_ctx; static void ping_done(struct ping_context *ctx); @@ -4505,7 +4504,6 @@ static void ping_work(struct k_work *work) sys_rand32_get(), ctx->sequence, ctx->tos, - ctx->priority, NULL, ctx->payload_size); } else { @@ -4514,7 +4512,6 @@ static void ping_work(struct k_work *work) sys_rand32_get(), ctx->sequence, ctx->tos, - ctx->priority, NULL, ctx->payload_size); } @@ -4615,7 +4612,6 @@ static int cmd_net_ping(const struct shell *sh, size_t argc, char *argv[]) int iface_idx = -1; int tos = 0; int payload_size = 4; - int priority = -1; for (size_t i = 1; i < argc; ++i) { @@ -4651,14 +4647,6 @@ static int cmd_net_ping(const struct shell *sh, size_t argc, char *argv[]) } break; - case 'p': - priority = parse_arg(&i, argc, argv); - if (priority < 0 || priority > UINT8_MAX) { - PR_WARNING("Parse error: %s\n", argv[i]); - return -ENOEXEC; - } - break; - case 'Q': tos = parse_arg(&i, argc, argv); if (tos < 0 || tos > UINT8_MAX) { @@ -4695,7 +4683,6 @@ static int cmd_net_ping(const struct shell *sh, size_t argc, char *argv[]) ping_ctx.sh = sh; ping_ctx.count = count; ping_ctx.interval = interval; - ping_ctx.priority = priority; ping_ctx.tos = tos; ping_ctx.payload_size = payload_size; @@ -6597,7 +6584,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_vlan, SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_ping, SHELL_CMD(--help, NULL, "'net ping [-c count] [-i interval ms] [-I ] " - "[-Q tos] [-s payload size] [-p priority] ' " + "[-Q tos] [-s payload size] ' " "Send ICMPv4 or ICMPv6 Echo-Request to a network host.", cmd_net_ping), SHELL_SUBCMD_SET_END diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index d3bf11a7b33..a30caf08074 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -526,7 +526,7 @@ static int execute_upload(const struct shell *sh, * some time and start the test after that. */ net_icmpv6_send_echo_request(net_if_get_default(), - &ipv6->sin6_addr, 0, 0, 0, -1, NULL, 0); + &ipv6->sin6_addr, 0, 0, 0, NULL, 0); k_sleep(K_SECONDS(1)); } From 68deac814482858b9d9905f61d2e73209b12a7f7 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:02 +0000 Subject: [PATCH 0900/1623] Revert "[nrf noup] ci: Update ble and mesh test-spec entry" This reverts commit d6bb133392a74f9e71a39f8d8cd0ff99501edd8a. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index f81ac31cf75..7c4d93cd038 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -40,31 +40,11 @@ - "samples/tfm_integration/**/*" "CI-ble-test": - - any: - - "drivers/bluetooth/**/*" - - any: - - "dts/arm/nordic/nrf5*" - - any: - - "subsys/bluetooth/**/*" - - "!subsys/bluetooth/mesh/**/*" - - "!subsys/bluetooth/audio/**/*" - - any: - - "include/zephyr/bluetooth/**/*" - - "!include/zephyr/bluetooth/mesh/**/*" - - any: - - "samples/bluetooth/**/*" - - "!samples/bluetooth/mesh/**/*" - - "!samples/bluetooth/mesh_demo/**/*" - - "!samples/bluetooth/mesh_provisioner/**/*" - - any: - - "tests/bluetooth/**/*" - - "!tests/bluetooth/mesh/**/*" - - "!tests/bluetooth/mesh_shell/**/*" - - "!tests/bluetooth/audio/**/*" + - "**/*" "CI-mesh-test": - "subsys/bluetooth/mesh/**/*" - - "include/zephyr/bluetooth/mesh/**/*" + - "include/bluetooth/mesh/**/*" - "samples/bluetooth/mesh/**/*" - "samples/bluetooth/mesh_demo/**/*" - "samples/bluetooth/mesh_provisioner/**/*" From 9f95a3ca852af4d8ffa8a6227ebc7a62b99702d5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:02 +0000 Subject: [PATCH 0901/1623] Revert "[nrf noup] ci: Add Sidewalk to test-spec" This reverts commit 090fedd22fbc95498a3540ed63832934d0e66da6. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 7c4d93cd038..102642d4216 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -119,7 +119,7 @@ - "subsys/settings/**/*" - "subsys/net/lib/openthread/**/*" - "subsys/mgmt/mcumgr/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" + - "samples/hci_rpmsg/**/*" - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" - any: - "subsys/bluetooth/**/*" @@ -140,7 +140,7 @@ - "subsys/net/**/*" - "subsys/mgmt/mcumgr/**/*" - "drivers/net/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" + - "samples/hci_rpmsg/**/*" - any: - "subsys/bluetooth/**/*" - "!subsys/bluetooth/mesh/**/*" @@ -193,16 +193,3 @@ "CI-wifi": - "subsys/net/l2/wifi/**/*" - "subsys/net/l2/ethernet/**/*" - -"CI-sidewalk-test": - - "include/dfu/**/*" - - "include/mgmt/mcumgr/**/*" - - "soc/arm/nordic_nrf/**/*" - - "subsys/dfu/**/*" - - "subsys/settings/**/*" - - "subsys/mgmt/mcumgr/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" - - any: - - "subsys/bluetooth/**/*" - - "!subsys/bluetooth/mesh/**/*" - - "!subsys/bluetooth/audio/**/*" From 0abf7953e13cdd1dadfe24b5191dfe6f97c5382a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:03 +0000 Subject: [PATCH 0902/1623] Revert "[nrf noup] ci: Only run crypto and tf-m tests when needed" This reverts commit fe45e34a7acb0709bbe9d0acf15d35405fdb03e5. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 102642d4216..ce1d40b330e 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -31,13 +31,7 @@ - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" "CI-tfm-test": - - "boards/arm/nrf5340dk_nrf5340/**/*" - - "boards/arm/nrf9160dk_nrf9160/**/*" - - "drivers/entropy/*" - - "dts/arm/nordic/nrf5340*" - - "dts/arm/nordic/nrf9160*" - - "modules/trusted-firmware-m/**/*" - - "samples/tfm_integration/**/*" + - "**/*" "CI-ble-test": - "**/*" @@ -94,16 +88,7 @@ - "**/*" "CI-crypto-test": - - "boards/arm/nrf52840dk_nrf52840/**/*" - - "boards/arm/nrf5340dk_nrf5340/**/*" - - "boards/arm/nrf9160dk_nrf9160/**/*" - - "drivers/entropy/*" - - "drivers/serial/**/*" - - "dts/arm/nordic/nrf52840*" - - "dts/arm/nordic/nrf5340*" - - "dts/arm/nordic/nrf9160*" - - "include/drivers/serial/**/*" - - "modules/mbedtls/**/*" + - "**/*" "CI-fem-test": - "**/*" From d92ce58da907b8bf6b62da45b0521816c7588b84 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:03 +0000 Subject: [PATCH 0903/1623] Revert "[nrf noup] ci: Update Thingy91 test-spec entry" This reverts commit 00175bd6e6a27a9b52875cf417398f657889c535. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index ce1d40b330e..53b811f9ae0 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -52,37 +52,7 @@ - "include/dfu/**/*" "CI-thingy91-test": - - "boards/arm/nrf9160dk_nrf9160/**/*" - - "arch/x86/core/**/*" - - "arch/x86/include/**/*" - - "drivers/console/**/*" - - "drivers/ethernet/**/*" - - "drivers/flash/**/*" - - "drivers/hwinfo/**/*" - - "drivers/interrupt_controller/**/*" - - "drivers/net/**/*" - - "drivers/serial/**/*" - - "drivers/timer/**/*" - - "include/**/*" - - "kernel/**/*" - - "lib/libc/common/source/stdlib/**/*" - - "lib/libc/newlib/**/*" - - "lib/libc/picolibc/**/*" - - "lib/os/**/*" - - "lib/posix/**/*" - - "misc/**/*" - - "modules/mbedtls/**/*" - - "soc/x86/ia32/**/*" - - "subsys/fs/fcb/**/*" - - "subsys/logging/**/*" - - "subsys/net/**/*" - - "subsys/random/**/*" - - "subsys/settings/include/**/*" - - "subsys/settings/src/**/*" - - "subsys/stats/**/*" - - "subsys/storage/flash_map/**/*" - - "subsys/storage/stream/**/*" - - "subsys/tracing/**/*" + - "**/*" "CI-desktop-test": - "**/*" From 9bf76260819e3cb87240aabf1f7f682789cd587f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:03 +0000 Subject: [PATCH 0904/1623] Revert "[nrf noup] ci: Only run lwm2m tests when needed" This reverts commit d44fdf9127f611edd051a893c85992d0ace9be7f. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 53b811f9ae0..5dd281919bc 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -21,7 +21,7 @@ - "subsys/testsuite/ztest/**/*" "CI-lwm2m-test": -# Not necessary to run tests on changes to this repo. + - "**/*" "CI-boot-dfu-test": - "subsys/mgmt/mcumgr/**/*" From 42d2488d72bff7c40638c3db37a140be1169ba06 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:03 +0000 Subject: [PATCH 0905/1623] Revert "[nrf noup] ci: Update test-spec.yml with adding FEM to CI" This reverts commit f3aa7126214fdf6a77afd316a5c0f3e48257f62f. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 5dd281919bc..3fe9ba5fbec 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -60,9 +60,6 @@ "CI-crypto-test": - "**/*" -"CI-fem-test": - - "**/*" - "CI-rs-test": - "**/*" From d084eed0a7fa0f3b08089bc1b0a6cb6fcecdd858 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:03 +0000 Subject: [PATCH 0906/1623] Revert "[nrf noup] Bluetooth: Mesh: Fix adv randomness bug" This reverts commit 62a4cadefae85308a801698f8a164eaecaea2358. Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/adv_ext.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 5c1a2bc3c32..831149bf79e 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -499,9 +499,7 @@ int bt_mesh_adv_enable(void) return err; } - if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE) && - IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - adv->tag == BT_MESH_FRIEND_ADV) { + if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE) && adv->tag & BT_MESH_FRIEND_ADV) { err = set_adv_randomness(adv->instance->handle, 0); if (err) { LOG_ERR("Failed to set zero randomness: %d", err); From 6e2b4c1526bd94971353a5fe0308c9bf7a6b47b9 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:04 +0000 Subject: [PATCH 0907/1623] Revert "[nrf noup] samples&tests: Restore a few CONFIG_NEWLIB_LIBC_NANO=n" This reverts commit 9eb6436610f0a0cde6d1ffc6c1cfd70ec1377a15. Signed-off-by: Dominik Ermel --- samples/posix/eventfd/prj.conf | 1 - tests/lib/newlib/heap_listener/prj.conf | 1 - 2 files changed, 2 deletions(-) diff --git a/samples/posix/eventfd/prj.conf b/samples/posix/eventfd/prj.conf index a0bfcdf747b..7ff74543b2f 100644 --- a/samples/posix/eventfd/prj.conf +++ b/samples/posix/eventfd/prj.conf @@ -1,6 +1,5 @@ # General config CONFIG_NEWLIB_LIBC=y -CONFIG_NEWLIB_LIBC_NANO=n CONFIG_POSIX_API=y CONFIG_EVENTFD=y diff --git a/tests/lib/newlib/heap_listener/prj.conf b/tests/lib/newlib/heap_listener/prj.conf index 8d8ebf99baf..31bc1ca7e76 100644 --- a/tests/lib/newlib/heap_listener/prj.conf +++ b/tests/lib/newlib/heap_listener/prj.conf @@ -1,5 +1,4 @@ CONFIG_ZTEST=y CONFIG_NEWLIB_LIBC=y -CONFIG_NEWLIB_LIBC_NANO=n CONFIG_NEWLIB_LIBC_HEAP_LISTENER=y CONFIG_ZTEST_NEW_API=y From 7f4043fc1fcdddd0e609f997c648ebdd1ae49afc Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:04 +0000 Subject: [PATCH 0908/1623] Revert "[nrf noup] ipc: backends: rpmsg: initialize shared memory to zero" This reverts commit a3139d834c6bd8ee1228ec5f054661683f21612a. Signed-off-by: Dominik Ermel --- .../backends/ipc_rpmsg_static_vrings.c | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c b/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c index 5d04d029e8c..41f0a77ea22 100644 --- a/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c +++ b/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c @@ -774,8 +774,8 @@ static int backend_init(const struct device *instance) return 0; } -#define BACKEND_CONFIG_POPULATE(i) \ - { \ +#define DEFINE_BACKEND_DEVICE(i) \ + static struct backend_config_t backend_config_##i = { \ .role = DT_ENUM_IDX_OR(DT_DRV_INST(i), role, ROLE_HOST), \ .shm_size = DT_REG_SIZE(DT_INST_PHANDLE(i, memory_region)), \ .shm_addr = DT_REG_ADDR(DT_INST_PHANDLE(i, memory_region)), \ @@ -790,10 +790,8 @@ static int backend_init(const struct device *instance) .buffer_size = DT_INST_PROP_OR(i, zephyr_buffer_size, \ RPMSG_BUFFER_SIZE), \ .id = i, \ - } - -#define BACKEND_DEVICE_DEFINE(i) \ - static struct backend_config_t backend_config_##i = BACKEND_CONFIG_POPULATE(i); \ + }; \ + \ static struct backend_data_t backend_data_##i; \ \ DEVICE_DT_INST_DEFINE(i, \ @@ -805,23 +803,20 @@ static int backend_init(const struct device *instance) CONFIG_IPC_SERVICE_REG_BACKEND_PRIORITY, \ &backend_ops); -DT_INST_FOREACH_STATUS_OKAY(BACKEND_DEVICE_DEFINE) +DT_INST_FOREACH_STATUS_OKAY(DEFINE_BACKEND_DEVICE) -#define BACKEND_CONFIG_DEFINE(i) BACKEND_CONFIG_POPULATE(i), +#define BACKEND_CONFIG_INIT(n) &backend_config_##n, #if defined(CONFIG_IPC_SERVICE_BACKEND_RPMSG_SHMEM_RESET) static int shared_memory_prepare(void) { - const struct backend_config_t *backend_config; - const struct backend_config_t backend_configs[] = { - DT_INST_FOREACH_STATUS_OKAY(BACKEND_CONFIG_DEFINE) + static const struct backend_config_t *config[] = { + DT_INST_FOREACH_STATUS_OKAY(BACKEND_CONFIG_INIT) }; - for (backend_config = backend_configs; - backend_config < backend_configs + ARRAY_SIZE(backend_configs); - backend_config++) { - if (backend_config->role == ROLE_HOST) { - memset((void *) backend_config->shm_addr, 0, VDEV_STATUS_SIZE); + for (int i = 0; i < DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT); i++) { + if (config[i]->role == ROLE_HOST) { + memset((void *) config[i]->shm_addr, 0, VDEV_STATUS_SIZE); } } From 7023bb422a7e24367dccbab66a3d355002fdf706 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:04 +0000 Subject: [PATCH 0909/1623] Revert "[nrf noup] dts: choose cryptocell for entropy when available" This reverts commit 910bb5fe9e14e8afcf0c8b65c846e294821d693e. Signed-off-by: Dominik Ermel --- dts/arm/nordic/nrf52840.dtsi | 2 +- dts/arm/nordic/nrf5340_cpuapp.dtsi | 2 +- dts/arm/nordic/nrf91.dtsi | 1 - soc/arm/nordic_nrf/Kconfig.peripherals | 6 ++---- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index f4209c67d19..8c89968c108 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -5,7 +5,7 @@ / { chosen { - zephyr,entropy = &cryptocell; + zephyr,entropy = &rng; zephyr,flash-controller = &flash_controller; }; diff --git a/dts/arm/nordic/nrf5340_cpuapp.dtsi b/dts/arm/nordic/nrf5340_cpuapp.dtsi index 1294203f00a..7a32c5398db 100644 --- a/dts/arm/nordic/nrf5340_cpuapp.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp.dtsi @@ -33,7 +33,7 @@ }; chosen { - zephyr,entropy = &cryptocell; + zephyr,entropy = &rng_hci; zephyr,flash-controller = &flash_controller; }; diff --git a/dts/arm/nordic/nrf91.dtsi b/dts/arm/nordic/nrf91.dtsi index a2a490ab0b1..d872680fb20 100644 --- a/dts/arm/nordic/nrf91.dtsi +++ b/dts/arm/nordic/nrf91.dtsi @@ -28,7 +28,6 @@ }; chosen { - zephyr,entropy = &cryptocell; zephyr,flash-controller = &flash_controller; }; diff --git a/soc/arm/nordic_nrf/Kconfig.peripherals b/soc/arm/nordic_nrf/Kconfig.peripherals index 1645cf34ea0..c7bfb552409 100644 --- a/soc/arm/nordic_nrf/Kconfig.peripherals +++ b/soc/arm/nordic_nrf/Kconfig.peripherals @@ -13,12 +13,10 @@ config HAS_HW_NRF_BPROT def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_BPROT)) config HAS_HW_NRF_CC310 - def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_CC310)) || \ - ($(dt_nodelabel_enabled,psa_rng) && SOC_SERIES_NRF91X) + def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_CC310)) config HAS_HW_NRF_CC312 - def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_CC312)) || \ - ($(dt_nodelabel_enabled,psa_rng) && SOC_NRF5340_CPUAPP) + def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_CC312)) config HAS_HW_NRF_CCM def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_CCM)) From f0c0f30a75b77976c5edaaa0ccdfd1a8d82b1fe1 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:04 +0000 Subject: [PATCH 0910/1623] Revert "[nrf noup] ci: NCS-specific CI tweaks" This reverts commit 9b9ec58b0c575e15c57cb1e5de2d1c4ac5266a1f. Signed-off-by: Dominik Ermel --- .github/workflows/commit-tags.yml | 31 ------------------------------- .github/workflows/compliance.yml | 8 ++++---- .gitlint | 4 ++-- Jenkinsfile | 5 ----- 4 files changed, 6 insertions(+), 42 deletions(-) delete mode 100644 .github/workflows/commit-tags.yml delete mode 100644 Jenkinsfile diff --git a/.github/workflows/commit-tags.yml b/.github/workflows/commit-tags.yml deleted file mode 100644 index 9e0323f9498..00000000000 --- a/.github/workflows/commit-tags.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Commit tags - -on: pull_request - -jobs: - commit_tags: - runs-on: ubuntu-22.04 - name: Run commit tags checks on patch series (PR) - steps: - - name: Update PATH for west - run: | - echo "$HOME/.local/bin" >> $GITHUB_PATH - - - name: Checkout the code - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: 0 - - - name: Install python dependencies - run: | - pip3 install setuptools - pip3 install wheel - pip3 install gitlint - - - name: Run the commit tags - uses: nrfconnect/action-commit-tags@main - with: - target: '.' - baserev: origin/${{ github.base_ref }} - revrange: 'none' diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index f17780c38e3..f84faff3e4a 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -38,8 +38,8 @@ jobs: git config --global user.name "Your Name" git remote -v # Ensure there's no merge commits in the PR - #[[ "$(git rev-list --merges --count origin/${BASE_REF}..)" == "0" ]] || \ - #(echo "::error ::Merge commits not allowed, rebase instead";false) + [[ "$(git rev-list --merges --count origin/${BASE_REF}..)" == "0" ]] || \ + (echo "::error ::Merge commits not allowed, rebase instead";false) git rebase origin/${BASE_REF} # debug git log --pretty=oneline | head -n 10 @@ -56,8 +56,8 @@ jobs: # debug ls -la git log --pretty=oneline | head -n 10 - ./scripts/ci/check_compliance.py --annotate -e KconfigBasic -e Kconfig \ - -e KconfigBasicNoModules -c origin/${BASE_REF}.. + ./scripts/ci/check_compliance.py --annotate -e KconfigBasic \ + -c origin/${BASE_REF}.. - name: upload-results uses: actions/upload-artifact@v3 diff --git a/.gitlint b/.gitlint index 8a33f140b2a..b8d25ce49b9 100644 --- a/.gitlint +++ b/.gitlint @@ -16,7 +16,7 @@ debug = false extra-path=scripts/gitlint [title-max-length-no-revert] -line-length=120 +line-length=75 [body-min-line-count] min-line-count=1 @@ -42,7 +42,7 @@ words=wip [max-line-length-with-exceptions] # B1 = body-max-line-length -line-length=120 +line-length=75 [body-min-length] min-length=3 diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 3b9cf002239..00000000000 --- a/Jenkinsfile +++ /dev/null @@ -1,5 +0,0 @@ -@Library("CI_LIB") _ - -def pipeline = new ncs.sdk_zephyr.Main() - -pipeline.run(JOB_NAME) From 0c20bca62ee38081b108bc2921061117b5f12689 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 8 Jan 2024 12:31:05 +0000 Subject: [PATCH 0911/1623] Revert "[nrf noup] ci: add .github/test-spec.yml" This reverts commit ed6a2048c3ab68de67b3fc37275fff453bfe5dfa. Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 147 ------------------------------------------ CODEOWNERS | 1 - 2 files changed, 148 deletions(-) delete mode 100644 .github/test-spec.yml diff --git a/.github/test-spec.yml b/.github/test-spec.yml deleted file mode 100644 index 3fe9ba5fbec..00000000000 --- a/.github/test-spec.yml +++ /dev/null @@ -1,147 +0,0 @@ -# This is the Jenkins ci variant of the .github/labler.yaml -"CI-iot-zephyr-lwm2m-test": - - "drivers/console/**/*" - - "drivers/flash/**/*" - - "subsys/dfu/boot/**/*" - - "subsys/net/ip/**/*" - - "subsys/net/lib/http/**/*" - - "subsys/net/lib/lwm2m//**/*" - - "subsys/net/**/*" - -"CI-iot-samples-test": - - "boards/arm/nrf9160dk_nrf9160/**/*" - - "dts/arm/nordic/nrf9160*" - - "include/net/**/*" - - "subsys/net/lib/**/*" - -"CI-iot-libraries-test": - - "boards/arm/nrf9160dk_nrf9160/**/*" - - "dts/arm/nordic/nrf9160*" - - "include/net/socket_ncs.h" - - "subsys/testsuite/ztest/**/*" - -"CI-lwm2m-test": - - "**/*" - -"CI-boot-dfu-test": - - "subsys/mgmt/mcumgr/**/*" - - "subsys/dfu/**/*" - - "include/mgmt/mcumgr/**/*" - - "include/dfu/**/*" - - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" - -"CI-tfm-test": - - "**/*" - -"CI-ble-test": - - "**/*" - -"CI-mesh-test": - - "subsys/bluetooth/mesh/**/*" - - "include/bluetooth/mesh/**/*" - - "samples/bluetooth/mesh/**/*" - - "samples/bluetooth/mesh_demo/**/*" - - "samples/bluetooth/mesh_provisioner/**/*" - - "tests/bluetooth/mesh/**/*" - - "tests/bluetooth/mesh_shell/**/*" - -"CI-zigbee-test": - - "subsys/mgmt/mcumgr/**/*" - - "subsys/dfu/**/*" - - "include/mgmt/mcumgr/**/*" - - "include/dfu/**/*" - -"CI-thingy91-test": - - "**/*" - -"CI-desktop-test": - - "**/*" - -"CI-crypto-test": - - "**/*" - -"CI-rs-test": - - "**/*" - -"CI-homekit-test": - - "include/dfu/**/*" - - "include/mgmt/mcumgr/**/*" - - "soc/arm/nordic_nrf/**/*" - - "subsys/dfu/**/*" - - "subsys/settings/**/*" - - "subsys/net/lib/openthread/**/*" - - "subsys/mgmt/mcumgr/**/*" - - "samples/hci_rpmsg/**/*" - - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" - - any: - - "subsys/bluetooth/**/*" - - "!subsys/bluetooth/mesh/**/*" - -"CI-thread-test": - - "**/*" - -"CI-nfc-test": - - "**/*" - -"CI-matter-test": - - "include/dfu/**/*" - - "include/mgmt/mcumgr/**/*" - - "soc/arm/nordic_nrf/**/*" - - "subsys/dfu/**/*" - - "subsys/settings/**/*" - - "subsys/net/**/*" - - "subsys/mgmt/mcumgr/**/*" - - "drivers/net/**/*" - - "samples/hci_rpmsg/**/*" - - any: - - "subsys/bluetooth/**/*" - - "!subsys/bluetooth/mesh/**/*" - - "!subsys/bluetooth/audio/**/*" - -"CI-find-my-test": - - "**/*" - -"CI-gazell-test": - - "**/*" - -"CI-rpc-test": - - "**/*" - -"CI-modemshell-test": - - "include/net/**/*" - - "include/posix/**/*" - - "include/shell/**/*" - - "drivers/net/**/*" - - "drivers/serial/**/*" - - "drivers/wifi/**/*" - - "subsys/shell/**/*" - - "subsys/net/**/*" - - "subsys/settings/**/*" - -"CI-positioning-test": - - "include/net/**/*" - - "include/posix/**/*" - - "drivers/net/**/*" - - "drivers/wifi/**/*" - - "subsys/net/**/*" - - "subsys/settings/**/*" - -"CI-cloud-test": - - "include/zephyr/dfu/**/*" - - "include/zephyr/net/**/*" - - "include/zephyr/posix/**/*" - - "include/zephyr/settings/**/*" - - "drivers/led/**/*" - - "drivers/net/**/*" - - "drivers/sensor/**/*" - - "drivers/serial/**/*" - - "drivers/wifi/**/*" - - "lib/posix/**/*" - - "soc/arm/nordic_nrf/**/*" - - "subsys/dfu/**/*" - - "subsys/net/**/*" - - "subsys/settings/**/*" - -"CI-wifi": - - "subsys/net/l2/wifi/**/*" - - "subsys/net/l2/ethernet/**/*" diff --git a/CODEOWNERS b/CODEOWNERS index a670048c779..25cf3791114 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -14,7 +14,6 @@ # * @galak @nashif /.github/ @nashif @stephanosio -/.github/test-spec.yml @nrfconnect/ncs-test-leads /.github/workflows/ @galak @nashif /MAINTAINERS.yml @MaureenHelm /arch/arc/ @abrodkin @ruuddw @evgeniy-paltsev From 605f129e42d2a04086e819f3e446bdb4fd22b539 Mon Sep 17 00:00:00 2001 From: Sebastian Wezel Date: Tue, 15 Mar 2022 13:12:25 +0100 Subject: [PATCH 0912/1623] [nrf noup] ci: add .github/test-spec.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This file is used for NCS-specific testing configuration based on modifications to files in this repository. Signed-off-by: Alperen Sener Signed-off-by: Elisabeth Solheim Klakken Signed-off-by: Mariusz Poslinski Signed-off-by: Markus Swarowsky Signed-off-by: Robert Lubos Signed-off-by: Sebastian Wezel Signed-off-by: Tomasz Tyzenhauz Signed-off-by: Fredrik Ås Signed-off-by: Michał Szablowski Signed-off-by: Tony Le Signed-off-by: Krishna T (cherry picked from commit 2a59fbdf425895a357fc6bff919d3108b6e35469) (cherry picked from commit acb96b140c95e933546acc41cc6df22b609342db) (cherry picked from commit e102ad15b3804c9d71447dda2bf4e321ec4185fb) (cherry picked from commit f9eac37be8ef89db5b2cbb06e38aef09e13fc448) (cherry picked from commit ed6a2048c3ab68de67b3fc37275fff453bfe5dfa) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 147 ++++++++++++++++++++++++++++++++++++++++++ CODEOWNERS | 1 + 2 files changed, 148 insertions(+) create mode 100644 .github/test-spec.yml diff --git a/.github/test-spec.yml b/.github/test-spec.yml new file mode 100644 index 00000000000..3fe9ba5fbec --- /dev/null +++ b/.github/test-spec.yml @@ -0,0 +1,147 @@ +# This is the Jenkins ci variant of the .github/labler.yaml +"CI-iot-zephyr-lwm2m-test": + - "drivers/console/**/*" + - "drivers/flash/**/*" + - "subsys/dfu/boot/**/*" + - "subsys/net/ip/**/*" + - "subsys/net/lib/http/**/*" + - "subsys/net/lib/lwm2m//**/*" + - "subsys/net/**/*" + +"CI-iot-samples-test": + - "boards/arm/nrf9160dk_nrf9160/**/*" + - "dts/arm/nordic/nrf9160*" + - "include/net/**/*" + - "subsys/net/lib/**/*" + +"CI-iot-libraries-test": + - "boards/arm/nrf9160dk_nrf9160/**/*" + - "dts/arm/nordic/nrf9160*" + - "include/net/socket_ncs.h" + - "subsys/testsuite/ztest/**/*" + +"CI-lwm2m-test": + - "**/*" + +"CI-boot-dfu-test": + - "subsys/mgmt/mcumgr/**/*" + - "subsys/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "include/dfu/**/*" + - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" + +"CI-tfm-test": + - "**/*" + +"CI-ble-test": + - "**/*" + +"CI-mesh-test": + - "subsys/bluetooth/mesh/**/*" + - "include/bluetooth/mesh/**/*" + - "samples/bluetooth/mesh/**/*" + - "samples/bluetooth/mesh_demo/**/*" + - "samples/bluetooth/mesh_provisioner/**/*" + - "tests/bluetooth/mesh/**/*" + - "tests/bluetooth/mesh_shell/**/*" + +"CI-zigbee-test": + - "subsys/mgmt/mcumgr/**/*" + - "subsys/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "include/dfu/**/*" + +"CI-thingy91-test": + - "**/*" + +"CI-desktop-test": + - "**/*" + +"CI-crypto-test": + - "**/*" + +"CI-rs-test": + - "**/*" + +"CI-homekit-test": + - "include/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/dfu/**/*" + - "subsys/settings/**/*" + - "subsys/net/lib/openthread/**/*" + - "subsys/mgmt/mcumgr/**/*" + - "samples/hci_rpmsg/**/*" + - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" + - any: + - "subsys/bluetooth/**/*" + - "!subsys/bluetooth/mesh/**/*" + +"CI-thread-test": + - "**/*" + +"CI-nfc-test": + - "**/*" + +"CI-matter-test": + - "include/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/dfu/**/*" + - "subsys/settings/**/*" + - "subsys/net/**/*" + - "subsys/mgmt/mcumgr/**/*" + - "drivers/net/**/*" + - "samples/hci_rpmsg/**/*" + - any: + - "subsys/bluetooth/**/*" + - "!subsys/bluetooth/mesh/**/*" + - "!subsys/bluetooth/audio/**/*" + +"CI-find-my-test": + - "**/*" + +"CI-gazell-test": + - "**/*" + +"CI-rpc-test": + - "**/*" + +"CI-modemshell-test": + - "include/net/**/*" + - "include/posix/**/*" + - "include/shell/**/*" + - "drivers/net/**/*" + - "drivers/serial/**/*" + - "drivers/wifi/**/*" + - "subsys/shell/**/*" + - "subsys/net/**/*" + - "subsys/settings/**/*" + +"CI-positioning-test": + - "include/net/**/*" + - "include/posix/**/*" + - "drivers/net/**/*" + - "drivers/wifi/**/*" + - "subsys/net/**/*" + - "subsys/settings/**/*" + +"CI-cloud-test": + - "include/zephyr/dfu/**/*" + - "include/zephyr/net/**/*" + - "include/zephyr/posix/**/*" + - "include/zephyr/settings/**/*" + - "drivers/led/**/*" + - "drivers/net/**/*" + - "drivers/sensor/**/*" + - "drivers/serial/**/*" + - "drivers/wifi/**/*" + - "lib/posix/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/dfu/**/*" + - "subsys/net/**/*" + - "subsys/settings/**/*" + +"CI-wifi": + - "subsys/net/l2/wifi/**/*" + - "subsys/net/l2/ethernet/**/*" diff --git a/CODEOWNERS b/CODEOWNERS index 8872e7381c5..2c8b9db3961 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -18,6 +18,7 @@ # component or code. This file is going to be deprecated and currently only had # entries that are not covered by the MAINTAINERS file. +/.github/test-spec.yml @nrfconnect/ncs-test-leads /soc/arm/aspeed/ @aspeeddylan /soc/arm/atmel_sam/common/*_sam4l_*.c @nandojve /soc/arm/atmel_sam/sam3x/ @ioannisg From 6b014316c607f99f927c6e05917ee73167e08f03 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Fri, 30 Nov 2018 14:07:56 +0100 Subject: [PATCH 0913/1623] [nrf noup] ci: NCS-specific CI tweaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Necessary changes for NCS CI. - Add a Jenkinsfile - compliance.yml: Disable check for merge commits, since we have upmerges downstream. Add an additional check for sauce tags (details in scripts/gitlint) Also, since in the code we refer to Kconfig symbols that are defined in the sdk-nrf repository, the Kconfig checks (Kconfig and KconfigBasic) will not pass so exclude them. - Extend the max commit line lengths for Gitlint to account for sauce tags - Add a commit-tags workflow: This enables sauce tag checking in sdk-zephyr - scripts/gitlint: Add support for sauce tags checks. In order to not interfere with CI in other repos (namely sdk-nrf) this is run as an independent gitlint invocation and not as part of check_compliance.py. This invocation enables the ncs-sauce-tags rule and, since it runs before rebasing and thus will run on merge commits, disables the title-starts-with-subsystem rule by setting a catch-all regex. Signed-off-by: Carles Cufi Signed-off-by: Dominik Ermel Signed-off-by: Martí Bolívar Signed-off-by: Vinayak Kariappa Chettimada Signed-off-by: Krishna T (cherry picked from commit d34b035bcc569431b7008c72edc55db1b29bccf3) (cherry picked from commit 4a6d5fc57fe7589b2585ee5e44341f50821cc653) (cherry picked from commit a01c3a4caccb6964a29078172ba7f590bcdbe790) (cherry picked from commit 9b9ec58b0c575e15c57cb1e5de2d1c4ac5266a1f) Signed-off-by: Dominik Ermel --- .github/workflows/commit-tags.yml | 31 +++++++++++++++++++++++++++++++ .github/workflows/compliance.yml | 8 ++++---- Jenkinsfile | 5 +++++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/commit-tags.yml create mode 100644 Jenkinsfile diff --git a/.github/workflows/commit-tags.yml b/.github/workflows/commit-tags.yml new file mode 100644 index 00000000000..9e0323f9498 --- /dev/null +++ b/.github/workflows/commit-tags.yml @@ -0,0 +1,31 @@ +name: Commit tags + +on: pull_request + +jobs: + commit_tags: + runs-on: ubuntu-22.04 + name: Run commit tags checks on patch series (PR) + steps: + - name: Update PATH for west + run: | + echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: Checkout the code + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + + - name: Install python dependencies + run: | + pip3 install setuptools + pip3 install wheel + pip3 install gitlint + + - name: Run the commit tags + uses: nrfconnect/action-commit-tags@main + with: + target: '.' + baserev: origin/${{ github.base_ref }} + revrange: 'none' diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index de1decb2cc6..d70990ff2c1 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -38,8 +38,8 @@ jobs: git config --global user.name "Your Name" git remote -v # Ensure there's no merge commits in the PR - [[ "$(git rev-list --merges --count origin/${BASE_REF}..)" == "0" ]] || \ - (echo "::error ::Merge commits not allowed, rebase instead";false) + #[[ "$(git rev-list --merges --count origin/${BASE_REF}..)" == "0" ]] || \ + #(echo "::error ::Merge commits not allowed, rebase instead";false) git rebase origin/${BASE_REF} # debug git log --pretty=oneline | head -n 10 @@ -57,8 +57,8 @@ jobs: # debug ls -la git log --pretty=oneline | head -n 10 - ./scripts/ci/check_compliance.py --annotate -e KconfigBasic \ - -c origin/${BASE_REF}.. + ./scripts/ci/check_compliance.py --annotate -e KconfigBasic -e Kconfig \ + -e KconfigBasicNoModules -c origin/${BASE_REF}.. - name: upload-results uses: actions/upload-artifact@v3 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000000..3b9cf002239 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,5 @@ +@Library("CI_LIB") _ + +def pipeline = new ncs.sdk_zephyr.Main() + +pipeline.run(JOB_NAME) From 499041d072580ae79d4fe967f0df52e60e43966b Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Mon, 16 Jan 2023 14:15:22 +0100 Subject: [PATCH 0914/1623] [nrf noup] dts: choose cryptocell for entropy when available This is a long-term noup patch because driver support is NCS-only. Set HAS_HW_NRF_CC3XX to be defined in NS build when cryptocell is accessed through the PSA API. We need to know which CC3XX features are available. Signed-off-by: Georgios Vasilakis Signed-off-by: Joakim Andersson (cherry picked from commit c76cf8776d7bcbb7eef8023191a941f8e9410cb4) (cherry picked from commit 214533fa69601f52933977a39fff855d955c886f) (cherry picked from commit 3819c4ae701f0b4265bbd3409e37e5bba5c4abcb) (cherry picked from commit 910bb5fe9e14e8afcf0c8b65c846e294821d693e) Signed-off-by: Dominik Ermel --- dts/arm/nordic/nrf52840.dtsi | 4 ++-- dts/arm/nordic/nrf5340_cpuapp.dtsi | 4 ++-- dts/arm/nordic/nrf91.dtsi | 3 ++- soc/arm/nordic_nrf/Kconfig.peripherals | 6 ++++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index 24710e8e0ff..9e3b79b3abd 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -5,7 +5,7 @@ / { chosen { - zephyr,entropy = &rng; + zephyr,entropy = &cryptocell; zephyr,flash-controller = &flash_controller; }; @@ -543,7 +543,7 @@ reg = <0x5002a000 0x1000>, <0x5002b000 0x1000>; reg-names = "wrapper", "core"; interrupts = <42 NRF_DEFAULT_IRQ_PRIORITY>; - status = "disabled"; + status = "okay"; }; }; }; diff --git a/dts/arm/nordic/nrf5340_cpuapp.dtsi b/dts/arm/nordic/nrf5340_cpuapp.dtsi index 77762990e13..a6ae5d4a316 100644 --- a/dts/arm/nordic/nrf5340_cpuapp.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp.dtsi @@ -33,7 +33,7 @@ }; chosen { - zephyr,entropy = &rng_hci; + zephyr,entropy = &cryptocell; zephyr,flash-controller = &flash_controller; }; @@ -91,7 +91,7 @@ reg = <0x50844000 0x1000>, <0x50845000 0x1000>; reg-names = "wrapper", "core"; interrupts = <68 NRF_DEFAULT_IRQ_PRIORITY>; - status = "disabled"; + status = "okay"; }; }; diff --git a/dts/arm/nordic/nrf91.dtsi b/dts/arm/nordic/nrf91.dtsi index 46024011166..23d2c7cf20e 100644 --- a/dts/arm/nordic/nrf91.dtsi +++ b/dts/arm/nordic/nrf91.dtsi @@ -28,6 +28,7 @@ }; chosen { + zephyr,entropy = &cryptocell; zephyr,flash-controller = &flash_controller; }; @@ -51,7 +52,7 @@ reg = <0x50840000 0x1000>, <0x50841000 0x1000>; reg-names = "wrapper", "core"; interrupts = <64 NRF_DEFAULT_IRQ_PRIORITY>; - status = "disabled"; + status = "okay"; }; ctrlap: ctrlap@50006000 { diff --git a/soc/arm/nordic_nrf/Kconfig.peripherals b/soc/arm/nordic_nrf/Kconfig.peripherals index 3aacc35a08a..2b7791bf5e6 100644 --- a/soc/arm/nordic_nrf/Kconfig.peripherals +++ b/soc/arm/nordic_nrf/Kconfig.peripherals @@ -13,10 +13,12 @@ config HAS_HW_NRF_BPROT def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_BPROT)) config HAS_HW_NRF_CC310 - def_bool $(dt_compat_enabled,$(DT_COMPAT_ARM_CRYPTOCELL_310)) + def_bool $(dt_compat_enabled,$(DT_COMPAT_ARM_CRYPTOCELL_310)) || \ + ($(dt_nodelabel_enabled,psa_rng) && SOC_SERIES_NRF91X) config HAS_HW_NRF_CC312 - def_bool $(dt_compat_enabled,$(DT_COMPAT_ARM_CRYPTOCELL_312)) + def_bool $(dt_compat_enabled,$(DT_COMPAT_ARM_CRYPTOCELL_312)) || \ + ($(dt_nodelabel_enabled,psa_rng) && SOC_NRF5340_CPUAPP) config HAS_HW_NRF_CCM def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_CCM)) From 275c2a7e51b4e1038d3052d3411d22aa48949360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Thu, 1 Dec 2022 14:41:13 +0100 Subject: [PATCH 0915/1623] [nrf noup] samples&tests: Restore a few CONFIG_NEWLIB_LIBC_NANO=n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up to commit 9dd570f8a2207a02c886480b0065cd5a0e3a2e94. Since in NCS, unlike in vanilla Zephyr, the nano variant of newlib is the default one, restore entries that disable the nano variant in one sample and one test that require the full newlib variant. This patch is supposed to be removed when picolibc becomes the default. Signed-off-by: Andrzej Głąbek (cherry picked from commit 56204202e86fb7fa89f7ae74c916f73a00a22044) (cherry picked from commit 4edd3681905057c345eb622ffe144fac958593e0) (cherry picked from commit 9eb6436610f0a0cde6d1ffc6c1cfd70ec1377a15) Signed-off-by: Dominik Ermel --- tests/lib/newlib/heap_listener/prj.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/newlib/heap_listener/prj.conf b/tests/lib/newlib/heap_listener/prj.conf index e5a5dc6df4c..7282777ff1c 100644 --- a/tests/lib/newlib/heap_listener/prj.conf +++ b/tests/lib/newlib/heap_listener/prj.conf @@ -1,3 +1,4 @@ CONFIG_ZTEST=y CONFIG_NEWLIB_LIBC=y +CONFIG_NEWLIB_LIBC_NANO=n CONFIG_NEWLIB_LIBC_HEAP_LISTENER=y From 3afe29330d959ee78d57db509a7380f0e05b6bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Wed, 8 Mar 2023 12:17:09 +0100 Subject: [PATCH 0916/1623] [nrf noup] Bluetooth: Mesh: Fix adv randomness bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes issue where randomness can be removed for advertising sets that have to handle other adv types than the BT_MESH_FRIEND_ADV tag type. Signed-off-by: Anders Storrø (cherry picked from commit f8f113382356934cb6d1ef4cdad95a843f922085) (cherry picked from commit 996037de254a91a9b2da4a288f48c09e90427501) (cherry picked from commit 62a4cadefae85308a801698f8a164eaecaea2358) Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/adv_ext.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 0c11fc0053a..525e5ee5066 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -527,7 +527,9 @@ int bt_mesh_adv_enable(void) return err; } - if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE) && adv->tag & BT_MESH_FRIEND_ADV) { + if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE) && + IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && + adv->tag == BT_MESH_FRIEND_ADV) { err = set_adv_randomness(adv->instance->handle, 0); if (err) { LOG_ERR("Failed to set zero randomness: %d", err); From 817446221498fe6e6f585768fe4f9136a18fc0f2 Mon Sep 17 00:00:00 2001 From: Dawid Przybylo Date: Fri, 23 Jun 2023 08:15:25 +0200 Subject: [PATCH 0917/1623] [nrf noup] ci: Update test-spec.yml with adding FEM to CI Extend sdk-zephyr CI with FEM test label. Signed-off-by: Dawid Przybylo (cherry picked from commit d2bc2c3c6ce3d08628a93c3bd246fd688dc6a446) (cherry picked from commit f3aa7126214fdf6a77afd316a5c0f3e48257f62f) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 3fe9ba5fbec..5dd281919bc 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -60,6 +60,9 @@ "CI-crypto-test": - "**/*" +"CI-fem-test": + - "**/*" + "CI-rs-test": - "**/*" From d53a1c962551409a9db38d711f5e076804170d79 Mon Sep 17 00:00:00 2001 From: Rubin Gerritsen Date: Fri, 11 Aug 2023 15:37:25 +0200 Subject: [PATCH 0918/1623] [nrf noup] ci: Only run lwm2m tests when needed There is no need to run those for all PRs. For example: When there are only changes to Bluetooth, we don't want this CI to run. Adding these filters may speedup the time to merge for PRs to sdk-nrf Signed-off-by: Rubin Gerritsen (cherry picked from commit 78106c74f4ac7936ef78dcddb8c6e1e578fe41dd) (cherry picked from commit d44fdf9127f611edd051a893c85992d0ace9be7f) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 5dd281919bc..53b811f9ae0 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -21,7 +21,7 @@ - "subsys/testsuite/ztest/**/*" "CI-lwm2m-test": - - "**/*" +# Not necessary to run tests on changes to this repo. "CI-boot-dfu-test": - "subsys/mgmt/mcumgr/**/*" From 255ee9dbefa18142e395f4b8abfd4fd20a80ad53 Mon Sep 17 00:00:00 2001 From: Jorgen Kvalvaag Date: Thu, 24 Aug 2023 10:03:43 +0200 Subject: [PATCH 0919/1623] [nrf noup] ci: Update Thingy91 test-spec entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thingy91 CI tests dependencies added. Signed-off-by: Jørgen Kvalvaag (cherry picked from commit 6a0df6f20645130ef3bf90b8c2ec605510d9b125) (cherry picked from commit 00175bd6e6a27a9b52875cf417398f657889c535) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 53b811f9ae0..ce1d40b330e 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -52,7 +52,37 @@ - "include/dfu/**/*" "CI-thingy91-test": - - "**/*" + - "boards/arm/nrf9160dk_nrf9160/**/*" + - "arch/x86/core/**/*" + - "arch/x86/include/**/*" + - "drivers/console/**/*" + - "drivers/ethernet/**/*" + - "drivers/flash/**/*" + - "drivers/hwinfo/**/*" + - "drivers/interrupt_controller/**/*" + - "drivers/net/**/*" + - "drivers/serial/**/*" + - "drivers/timer/**/*" + - "include/**/*" + - "kernel/**/*" + - "lib/libc/common/source/stdlib/**/*" + - "lib/libc/newlib/**/*" + - "lib/libc/picolibc/**/*" + - "lib/os/**/*" + - "lib/posix/**/*" + - "misc/**/*" + - "modules/mbedtls/**/*" + - "soc/x86/ia32/**/*" + - "subsys/fs/fcb/**/*" + - "subsys/logging/**/*" + - "subsys/net/**/*" + - "subsys/random/**/*" + - "subsys/settings/include/**/*" + - "subsys/settings/src/**/*" + - "subsys/stats/**/*" + - "subsys/storage/flash_map/**/*" + - "subsys/storage/stream/**/*" + - "subsys/tracing/**/*" "CI-desktop-test": - "**/*" From 5e158827055b624583817e226972f2f8e2c1f030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magne=20V=C3=A6rnes?= Date: Wed, 23 Aug 2023 16:10:42 +0200 Subject: [PATCH 0920/1623] [nrf noup] ci: Only run crypto and tf-m tests when needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extended the github CI filter for crypto and TF-M tests to reduce the CI load and possibly speed up PRs. Signed-off-by: Magne Værnes (cherry picked from commit c0d21ea8df1bce0d1bc2774a8e7348f3fc90271f) (cherry picked from commit fe45e34a7acb0709bbe9d0acf15d35405fdb03e5) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index ce1d40b330e..102642d4216 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -31,7 +31,13 @@ - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" "CI-tfm-test": - - "**/*" + - "boards/arm/nrf5340dk_nrf5340/**/*" + - "boards/arm/nrf9160dk_nrf9160/**/*" + - "drivers/entropy/*" + - "dts/arm/nordic/nrf5340*" + - "dts/arm/nordic/nrf9160*" + - "modules/trusted-firmware-m/**/*" + - "samples/tfm_integration/**/*" "CI-ble-test": - "**/*" @@ -88,7 +94,16 @@ - "**/*" "CI-crypto-test": - - "**/*" + - "boards/arm/nrf52840dk_nrf52840/**/*" + - "boards/arm/nrf5340dk_nrf5340/**/*" + - "boards/arm/nrf9160dk_nrf9160/**/*" + - "drivers/entropy/*" + - "drivers/serial/**/*" + - "dts/arm/nordic/nrf52840*" + - "dts/arm/nordic/nrf5340*" + - "dts/arm/nordic/nrf9160*" + - "include/drivers/serial/**/*" + - "modules/mbedtls/**/*" "CI-fem-test": - "**/*" From 23b8a13a04d81fe92a185b15c60fdb10ac52578d Mon Sep 17 00:00:00 2001 From: Tomasz Tyzenhauz Date: Fri, 25 Aug 2023 13:27:53 +0200 Subject: [PATCH 0921/1623] [nrf noup] ci: Add Sidewalk to test-spec Add Sidewalk to be trigger on changes in this repo. Correct entry path for hci_rpmsg samples for Matter and Homekit. Signed-off-by: Tomasz Tyzenhauz (cherry picked from commit cd4e36f63fd444d1e850894ca743ee8e9654fc1a) (cherry picked from commit 090fedd22fbc95498a3540ed63832934d0e66da6) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 102642d4216..7c4d93cd038 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -119,7 +119,7 @@ - "subsys/settings/**/*" - "subsys/net/lib/openthread/**/*" - "subsys/mgmt/mcumgr/**/*" - - "samples/hci_rpmsg/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" - any: - "subsys/bluetooth/**/*" @@ -140,7 +140,7 @@ - "subsys/net/**/*" - "subsys/mgmt/mcumgr/**/*" - "drivers/net/**/*" - - "samples/hci_rpmsg/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" - any: - "subsys/bluetooth/**/*" - "!subsys/bluetooth/mesh/**/*" @@ -193,3 +193,16 @@ "CI-wifi": - "subsys/net/l2/wifi/**/*" - "subsys/net/l2/ethernet/**/*" + +"CI-sidewalk-test": + - "include/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/dfu/**/*" + - "subsys/settings/**/*" + - "subsys/mgmt/mcumgr/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" + - any: + - "subsys/bluetooth/**/*" + - "!subsys/bluetooth/mesh/**/*" + - "!subsys/bluetooth/audio/**/*" From 660313bbc996648d6a617a5c65c618b68b0c6686 Mon Sep 17 00:00:00 2001 From: Lang Xie Date: Fri, 8 Sep 2023 13:13:41 +0200 Subject: [PATCH 0922/1623] [nrf noup] ci: Update ble and mesh test-spec entry Add BLE CI test dependency and update the include path of mesh. Signed-off-by: Lang Xie (cherry picked from commit 02956222c991e2c036810a5e39fd60e72aa75866) (cherry picked from commit d6bb133392a74f9e71a39f8d8cd0ff99501edd8a) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 7c4d93cd038..f81ac31cf75 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -40,11 +40,31 @@ - "samples/tfm_integration/**/*" "CI-ble-test": - - "**/*" + - any: + - "drivers/bluetooth/**/*" + - any: + - "dts/arm/nordic/nrf5*" + - any: + - "subsys/bluetooth/**/*" + - "!subsys/bluetooth/mesh/**/*" + - "!subsys/bluetooth/audio/**/*" + - any: + - "include/zephyr/bluetooth/**/*" + - "!include/zephyr/bluetooth/mesh/**/*" + - any: + - "samples/bluetooth/**/*" + - "!samples/bluetooth/mesh/**/*" + - "!samples/bluetooth/mesh_demo/**/*" + - "!samples/bluetooth/mesh_provisioner/**/*" + - any: + - "tests/bluetooth/**/*" + - "!tests/bluetooth/mesh/**/*" + - "!tests/bluetooth/mesh_shell/**/*" + - "!tests/bluetooth/audio/**/*" "CI-mesh-test": - "subsys/bluetooth/mesh/**/*" - - "include/bluetooth/mesh/**/*" + - "include/zephyr/bluetooth/mesh/**/*" - "samples/bluetooth/mesh/**/*" - "samples/bluetooth/mesh_demo/**/*" - "samples/bluetooth/mesh_provisioner/**/*" From 14a865b41c6f51ba8786c7eae23a1a3ff70a3727 Mon Sep 17 00:00:00 2001 From: Mariusz Poslinski Date: Tue, 5 Sep 2023 09:43:10 +0200 Subject: [PATCH 0923/1623] [nrf noup] ci: Update Thread test-spec entry Update Thread test-spec entry. Signed-off-by: Mariusz Poslinski (cherry picked from commit 81c640bcccce83f83573234ca1725e6d5576e9c2) (cherry picked from commit 6340daeb1824fa7f92d2e847d0eb68be53b21d51) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index f81ac31cf75..03e02441069 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -146,7 +146,11 @@ - "!subsys/bluetooth/mesh/**/*" "CI-thread-test": - - "**/*" + - "subsys/net/**/*" + - "modules/mbedtls/**/*" + - "include/zephyr/net/**/*" + - "modules/openthread/**/*" + - "samples/net/openthread/**/*" "CI-nfc-test": - "**/*" From ddedbc9e833fa5f326a7d3d7d1fd0a27349d6208 Mon Sep 17 00:00:00 2001 From: Mariusz Poslinski Date: Mon, 18 Sep 2023 12:48:52 +0200 Subject: [PATCH 0924/1623] [nrf noup] ci: Update Thread test-spec entry Update Thread and HomeKit test-spec entries. Signed-off-by: Mariusz Poslinski (cherry picked from commit 4c741f1e2d2542ab23891fff46ed93add2893740) (cherry picked from commit 488716469816d193dd5b7ffb53d9eb57dfa36c5a) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 03e02441069..62b92e74d0f 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -132,25 +132,24 @@ - "**/*" "CI-homekit-test": - - "include/dfu/**/*" - - "include/mgmt/mcumgr/**/*" + - "modules/openthread/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" - "soc/arm/nordic_nrf/**/*" - - "subsys/dfu/**/*" + - "subsys/net/**/*" - "subsys/settings/**/*" - - "subsys/net/lib/openthread/**/*" - - "subsys/mgmt/mcumgr/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" - - "samples/subsys/mgmt/mcumgr/smp_svr/**/*" - any: - "subsys/bluetooth/**/*" - "!subsys/bluetooth/mesh/**/*" + - "!subsys/bluetooth/audio/**/*" "CI-thread-test": - - "subsys/net/**/*" - - "modules/mbedtls/**/*" - "include/zephyr/net/**/*" + - "modules/mbedtls/**/*" - "modules/openthread/**/*" - "samples/net/openthread/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/net/**/*" + - "subsys/settings/**/*" "CI-nfc-test": - "**/*" From 041e804add1e154ea95da502842df792e603cda5 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Thu, 23 Jun 2022 14:10:01 +0000 Subject: [PATCH 0925/1623] [nrf noup] mgmt/mcumgr: Bootutil hooks to handle image-1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The commit adds bootutil hook, for nrf5340, to allow it handling the non-accessible image-1/primary slot. Signed-off-by: Andrzej Głąbek Signed-off-by: Vinayak Kariappa Chettimada Signed-off-by: Johann Fischer (cherry picked from commit 840b8fa1dba3ddda02fa1652a9408b08b7c310de) (cherry picked from commit 9af7d7ad2f70cee26ccc98b4daadd2260662ff78) (cherry picked from commit 298d8037d2b60b4ca4dd8b2a7727196e33054dd8) (cherry picked from commit d3aa849948ce548ba46ddb7f6ec0b4422fa53db4) (cherry picked from commit 063b584e78395eb02a1e7cbd82a0ed3251b383f3) Signed-off-by: Dominik Ermel --- subsys/mgmt/mcumgr/CMakeLists.txt | 8 ++++++ subsys/mgmt/mcumgr/Kconfig | 1 + .../mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c | 27 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c diff --git a/subsys/mgmt/mcumgr/CMakeLists.txt b/subsys/mgmt/mcumgr/CMakeLists.txt index 39d4a4ca8ce..ad088eca067 100644 --- a/subsys/mgmt/mcumgr/CMakeLists.txt +++ b/subsys/mgmt/mcumgr/CMakeLists.txt @@ -16,3 +16,11 @@ add_subdirectory(transport) add_subdirectory_ifdef(CONFIG_SMP_CLIENT smp_client) zephyr_library_link_libraries(mgmt_mcumgr) + +if (CONFIG_BOOT_IMAGE_ACCESS_HOOKS) + zephyr_include_directories( + ${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/bootutil/include + ${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/zephyr/include + ) + zephyr_library_sources(bootutil_hooks/nrf53_hooks.c) +endif() diff --git a/subsys/mgmt/mcumgr/Kconfig b/subsys/mgmt/mcumgr/Kconfig index 49bd17f4669..1c6a3a2a516 100644 --- a/subsys/mgmt/mcumgr/Kconfig +++ b/subsys/mgmt/mcumgr/Kconfig @@ -6,6 +6,7 @@ menuconfig MCUMGR bool "mcumgr Support" depends on NET_BUF depends on ZCBOR + imply BOOT_IMAGE_ACCESS_HOOKS if (SOC_NRF5340_CPUAPP_QKAA && MCUMGR_GRP_IMG) help This option enables the mcumgr management library. diff --git a/subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c b/subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c new file mode 100644 index 00000000000..9971a4e0843 --- /dev/null +++ b/subsys/mgmt/mcumgr/bootutil_hooks/nrf53_hooks.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "bootutil/bootutil_public.h" + +int boot_read_swap_state_primary_slot_hook(int image_index, + struct boot_swap_state *state) +{ + if (image_index == 1) { + /* Pretend that primary slot of image 1 unpopulated */ + state->magic = BOOT_MAGIC_UNSET; + state->swap_type = BOOT_SWAP_TYPE_NONE; + state->image_num = image_index; + state->copy_done = BOOT_FLAG_UNSET; + state->image_ok = BOOT_FLAG_UNSET; + + /* Prevent bootutil from trying to obtain true info */ + return 0; + } + + return BOOT_HOOK_REGULAR; +} From a7fb26837763ee7c21fb666fe2faa8c7503a17f1 Mon Sep 17 00:00:00 2001 From: Sigvart Hovland Date: Fri, 3 May 2019 14:21:52 +0200 Subject: [PATCH 0926/1623] [nrf noup] tree-wide: support NCS Partition Manager (PM) definitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Partition Manager (PM) is a component of the nRF Connect SDK (NCS) which uses yaml files to resolve flash partition placement with a holistic view of the entire device, including each firmware image present on the flash device, and various subsystems, such as settings and NFFS. When this NCS extension is used, various source files which would use partition information from devicetree in "vanilla" zephyr instead use defines generated by PM instead. This commit removes support for HEX_FILES_TO_MERGE, as it conflicts with PM. The settings subsystem pm.yml defines a partition 'settings_storage'. The nffs subsystem pm.yml defines 'nffs_storage'. Leverage label translation to avoid patching partition names. Refer to the NCS documentation page for this feature for more details. This is a long-running out of tree patch which has been worked on by several people. The following sign-offs are in alphabetical order by first name. Signed-off-by: Andrzej Głąbek Signed-off-by: Andrzej Puzdrowski Signed-off-by: Håkon Øye Amundsen Signed-off-by: Ioannis Glaropoulos Signed-off-by: Joakim Andersson Signed-off-by: Johann Fischer Signed-off-by: Martí Bolívar Signed-off-by: Ole Sæther Signed-off-by: Robert Lubos Signed-off-by: Sebastian Bøe Signed-off-by: Sigvart Hovland Signed-off-by: Thomas Stenersen Signed-off-by: Torsten Rasmussen Signed-off-by: Øyvind Rønningstad Signed-off-by: Trond Einar Snekvik Signed-off-by: Gerard Marull-Paretas Signed-off-by: Tomasz Moń (cherry picked from commit ba54fe88dcfe3b25aca4c02f01e47f232b0f8bf7) (cherry picked from commit 68110ee5a75167e8e2c65746211571315618a3e1) (cherry picked from commit 12d1ebfb98a4f89dc018af4e7872382222b3b74a) (cherry picked from commit 5e8e748917649fc0a4a44a02c2c91c581007856d) (cherry picked from commit d1fa3da6c37763e1ae9306c43bfaf5cf965af594) Signed-off-by: Dominik Ermel --- arch/arm/core/mpu/arm_mpu_regions.c | 13 ++++++ cmake/modules/kernel.cmake | 4 ++ drivers/flash/soc_flash_nrf.c | 11 +++++ .../arch/arm/cortex_m/scripts/linker.ld | 46 +++++++++++++++++++ include/zephyr/storage/flash_map.h | 6 +++ lib/libc/common/source/stdlib/malloc.c | 18 +++++++- lib/os/Kconfig.heap | 2 +- subsys/fs/littlefs_fs.c | 7 ++- subsys/ipc/rpmsg_service/rpmsg_backend.h | 27 +++++++++++ 9 files changed, 130 insertions(+), 4 deletions(-) diff --git a/arch/arm/core/mpu/arm_mpu_regions.c b/arch/arm/core/mpu/arm_mpu_regions.c index 6af62f84078..cfe1230c907 100644 --- a/arch/arm/core/mpu/arm_mpu_regions.c +++ b/arch/arm/core/mpu/arm_mpu_regions.c @@ -8,6 +8,9 @@ #include #include +#if USE_PARTITION_MANAGER +#include +#endif static const struct arm_mpu_region mpu_regions[] = { /* Region 0 */ @@ -21,6 +24,14 @@ static const struct arm_mpu_region mpu_regions[] = { #endif /* Region 1 */ MPU_REGION_ENTRY("SRAM_0", +#if USE_PARTITION_MANAGER + PM_SRAM_ADDRESS, +#if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE) + REGION_RAM_ATTR(PM_SRAM_ADDRESS, PM_SRAM_SIZE)), +#else + REGION_RAM_ATTR(REGION_SRAM_SIZE)), +#endif +#else CONFIG_SRAM_BASE_ADDRESS, #if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE) REGION_RAM_ATTR(CONFIG_SRAM_BASE_ADDRESS, \ @@ -28,6 +39,8 @@ static const struct arm_mpu_region mpu_regions[] = { #else REGION_RAM_ATTR(REGION_SRAM_SIZE)), #endif + +#endif /* USE_PARTITION_MANAGER */ }; const struct arm_mpu_config mpu_config = { diff --git a/cmake/modules/kernel.cmake b/cmake/modules/kernel.cmake index a093d46691f..06e1642f362 100644 --- a/cmake/modules/kernel.cmake +++ b/cmake/modules/kernel.cmake @@ -243,3 +243,7 @@ if("${CMAKE_EXTRA_GENERATOR}" STREQUAL "Eclipse CDT4") include(${ZEPHYR_BASE}/cmake/ide/eclipse_cdt4_generator_amendment.cmake) eclipse_cdt4_generator_amendment(1) endif() + +if(ZEPHYR_NRF_MODULE_DIR) + include(${ZEPHYR_NRF_MODULE_DIR}/cmake/partition_manager.cmake) +endif() diff --git a/drivers/flash/soc_flash_nrf.c b/drivers/flash/soc_flash_nrf.c index cc840309264..b5a3fefa1e5 100644 --- a/drivers/flash/soc_flash_nrf.c +++ b/drivers/flash/soc_flash_nrf.c @@ -37,6 +37,11 @@ LOG_MODULE_REGISTER(flash_nrf); #define SOC_NV_FLASH_NODE DT_INST(0, soc_nv_flash) +#if CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER +#include +#include +#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER */ + #ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE #define FLASH_SLOT_WRITE 7500 #if defined(CONFIG_SOC_FLASH_NRF_PARTIAL_ERASE) @@ -166,6 +171,12 @@ static int flash_nrf_read(const struct device *dev, off_t addr, } #endif +#if CONFIG_TRUSTED_EXECUTION_NONSECURE && USE_PARTITION_MANAGER && PM_APP_ADDRESS + if (addr < PM_APP_ADDRESS) { + return soc_secure_mem_read(data, (void *)addr, len); + } +#endif + nrf_nvmc_buffer_read(data, (uint32_t)addr, len); return 0; diff --git a/include/zephyr/arch/arm/cortex_m/scripts/linker.ld b/include/zephyr/arch/arm/cortex_m/scripts/linker.ld index 13c2747f5a3..5050c778627 100644 --- a/include/zephyr/arch/arm/cortex_m/scripts/linker.ld +++ b/include/zephyr/arch/arm/cortex_m/scripts/linker.ld @@ -26,6 +26,35 @@ #endif #define RAMABLE_REGION RAM +#if USE_PARTITION_MANAGER + +#include + +#if CONFIG_NCS_IS_VARIANT_IMAGE && defined(PM_S0_ID) +/* We are linking against S1, create symbol containing the flash ID of S0. + * This is used when writing code operating on the "other" slot. + */ +_image_1_primary_slot_id = PM_S0_ID; + +#else /* ! CONFIG_NCS_IS_VARIANT_IMAGE */ + +#ifdef PM_S1_ID +/* We are linking against S0, create symbol containing the flash ID of S1. + * This is used when writing code operating on the "other" slot. + */ +_image_1_primary_slot_id = PM_S1_ID; +#endif /* PM_S1_ID */ + +#endif /* CONFIG_NCS_IS_VARIANT_IMAGE */ + +#define ROM_ADDR PM_ADDRESS +#define ROM_SIZE PM_SIZE + +#define RAM_SIZE PM_SRAM_SIZE +#define RAM_ADDR PM_SRAM_ADDRESS + +#else /* ! USE_PARTITION_MANAGER */ + #if !defined(CONFIG_XIP) && (CONFIG_FLASH_SIZE == 0) #define ROM_ADDR RAM_ADDR #else @@ -52,6 +81,23 @@ #define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS #endif +#endif /* USE_PARTITION_MANAGER */ + +#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay) +#define CCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ccm)) +#define CCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ccm)) +#endif + +#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay) +#define ITCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_itcm)) +#define ITCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_itcm)) +#endif + +#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay) +#define DTCM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_dtcm)) +#define DTCM_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_dtcm)) +#endif + #if defined(CONFIG_CUSTOM_SECTION_ALIGN) _region_min_align = CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE; #else diff --git a/include/zephyr/storage/flash_map.h b/include/zephyr/storage/flash_map.h index 380e58691e9..cc4a246105d 100644 --- a/include/zephyr/storage/flash_map.h +++ b/include/zephyr/storage/flash_map.h @@ -271,6 +271,10 @@ const char *flash_area_label(const struct flash_area *fa); */ uint8_t flash_area_erased_val(const struct flash_area *fa); +#if USE_PARTITION_MANAGER +#include +#else + #define FLASH_AREA_LABEL_EXISTS(label) __DEPRECATED_MACRO \ DT_HAS_FIXED_PARTITION_LABEL(label) @@ -343,6 +347,8 @@ uint8_t flash_area_erased_val(const struct flash_area *fa); #define FIXED_PARTITION_DEVICE(label) \ DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(label))) +#endif /* USE_PARTITION_MANAGER */ + #ifdef __cplusplus } #endif diff --git a/lib/libc/common/source/stdlib/malloc.c b/lib/libc/common/source/stdlib/malloc.c index e3a5db6f7d5..2f469d673e4 100644 --- a/lib/libc/common/source/stdlib/malloc.c +++ b/lib/libc/common/source/stdlib/malloc.c @@ -25,6 +25,20 @@ #include LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); +#if USE_PARTITION_MANAGER + +#include + +#define RAM_SIZE PM_SRAM_SIZE +#define RAM_ADDR PM_SRAM_ADDRESS + +#else /* ! USE_PARTITION_MANAGER */ + +#define RAM_SIZE (KB((size_t) CONFIG_SRAM_SIZE)) +#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS + +#endif /* USE_PARTITION_MANAGER */ + #ifdef CONFIG_COMMON_LIBC_MALLOC #if (CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE != 0) @@ -106,8 +120,8 @@ static POOL_SECTION unsigned char __aligned(HEAP_ALIGN) malloc_arena[HEAP_SIZE]; extern char _heap_sentry[]; # define HEAP_SIZE ROUND_DOWN((POINTER_TO_UINT(_heap_sentry) - HEAP_BASE), HEAP_ALIGN) # else -# define HEAP_SIZE ROUND_DOWN((KB((size_t) CONFIG_SRAM_SIZE) - \ - ((size_t) HEAP_BASE - (size_t) CONFIG_SRAM_BASE_ADDRESS)), HEAP_ALIGN) +# define HEAP_SIZE ROUND_DOWN((RAM_SIZE - \ + ((size_t) HEAP_BASE - (size_t) RAM_ADDR)), HEAP_ALIGN) # endif /* else CONFIG_XTENSA */ # endif /* else CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE > 0 */ diff --git a/lib/os/Kconfig.heap b/lib/os/Kconfig.heap index b913d6100dc..f6e8d93ae50 100644 --- a/lib/os/Kconfig.heap +++ b/lib/os/Kconfig.heap @@ -51,7 +51,7 @@ config HEAP_LISTENER choice prompt "Supported heap sizes" depends on !64BIT - default SYS_HEAP_SMALL_ONLY if (SRAM_SIZE <= 256) + default SYS_HEAP_SMALL_ONLY if (SRAM_SIZE <= 256) && !PARTITION_MANAGER_ENABLED default SYS_HEAP_AUTO help Heaps using reduced-size chunk headers can accommodate so called diff --git a/subsys/fs/littlefs_fs.c b/subsys/fs/littlefs_fs.c index 3058f402d73..c4c75bb48c4 100644 --- a/subsys/fs/littlefs_fs.c +++ b/subsys/fs/littlefs_fs.c @@ -1054,7 +1054,12 @@ struct fs_mount_t FS_FSTAB_ENTRY(DT_DRV_INST(inst)) = { \ .type = FS_LITTLEFS, \ .mnt_point = DT_INST_PROP(inst, mount_point), \ .fs_data = &fs_data_##inst, \ - .storage_dev = (void *)DT_FIXED_PARTITION_ID(FS_PARTITION(inst)), \ + .storage_dev = (void *) \ + COND_CODE_1(USE_PARTITION_MANAGER, \ + (COND_CODE_1(FIXED_PARTITION_EXISTS(littlefs_storage), \ + (FIXED_PARTITION_ID(littlefs_storage)), \ + (FIXED_PARTITION_ID(storage)))), \ + (DT_FIXED_PARTITION_ID(FS_PARTITION(inst)))), \ .flags = FSTAB_ENTRY_DT_MOUNT_FLAGS(DT_DRV_INST(inst)), \ }; diff --git a/subsys/ipc/rpmsg_service/rpmsg_backend.h b/subsys/ipc/rpmsg_service/rpmsg_backend.h index a74e46b8520..9996e1d74d9 100644 --- a/subsys/ipc/rpmsg_service/rpmsg_backend.h +++ b/subsys/ipc/rpmsg_service/rpmsg_backend.h @@ -13,8 +13,35 @@ extern "C" { #endif +#if CONFIG_PARTITION_MANAGER_ENABLED + +#include "pm_config.h" + +#if defined(PM_RPMSG_NRF53_SRAM_ADDRESS) || defined(PM__RPMSG_NRF53_SRAM_ADDRESS) + +#if defined(PM_RPMSG_NRF53_SRAM_ADDRESS) +#define VDEV_START_ADDR PM_RPMSG_NRF53_SRAM_ADDRESS +#define VDEV_SIZE PM_RPMSG_NRF53_SRAM_SIZE +#else +/* The current image is a child image in a different domain than the image + * which defined the required values. To reach the values of the parent domain + * we use the 'PM__' variant of the define. + */ +#define VDEV_START_ADDR PM__RPMSG_NRF53_SRAM_ADDRESS +#define VDEV_SIZE PM__RPMSG_NRF53_SRAM_SIZE +#endif /* defined(PM_RPMSG_NRF53_SRAM_ADDRESS) */ + +#else #define VDEV_START_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ipc_shm)) #define VDEV_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ipc_shm)) +#endif /* defined(PM_RPMSG_NRF53_SRAM_ADDRESS) || defined(PM__RPMSG_NRF53_SRAM_ADDRESS) */ + +#else + +#define VDEV_START_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_ipc_shm)) +#define VDEV_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_ipc_shm)) + +#endif /* CONFIG_PARTITION_MANAGER_ENABLED */ #define VDEV_STATUS_ADDR VDEV_START_ADDR #define VDEV_STATUS_SIZE 0x400 From 16d6edb4367f02f14e63706ed22ff6901796ab6f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Thu, 28 Sep 2023 11:10:55 +0000 Subject: [PATCH 0927/1623] [nrf noup] mgmt/MCUmgr/grp/img: Move out label to make compiler happy Move it inside ifdef. (cherry picked from commit 2fb8d761dbe3aeecc9285205cb9760701134463a) (cherry picked from commit 45ac1f809fef282566c124dc676c951428d707bc) Signed-off-by: Dominik Ermel --- subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c index 0968694c614..61515c14655 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c @@ -290,13 +290,14 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type) return_slot = other_slot; } } +out: + #else if (rcs == 0 && rca == 0 && img_mgmt_vercmp(&aver, &over) < 0) { return_slot = other_slot; } #endif /* defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) */ -out: if (type != NULL) { *type = lt; } From caae0dffc7de62bbe7188c85b92ba83ac05b44c8 Mon Sep 17 00:00:00 2001 From: Mariusz Poslinski Date: Thu, 26 Oct 2023 15:53:52 +0200 Subject: [PATCH 0928/1623] [nrf noup] testspec: remove HomeKit from NCS HomeKit Accessory Development Kit has been deprecated and removed from NCS. Signed-off-by: Mariusz Poslinski (cherry picked from commit fabddf3a622625f39a71b9bb0377569e2fe230be) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 62b92e74d0f..c01ae703adf 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -131,17 +131,6 @@ "CI-rs-test": - "**/*" -"CI-homekit-test": - - "modules/openthread/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" - - "soc/arm/nordic_nrf/**/*" - - "subsys/net/**/*" - - "subsys/settings/**/*" - - any: - - "subsys/bluetooth/**/*" - - "!subsys/bluetooth/mesh/**/*" - - "!subsys/bluetooth/audio/**/*" - "CI-thread-test": - "include/zephyr/net/**/*" - "modules/mbedtls/**/*" From fe461000fe30fd556bc9aca96314775e74c723e6 Mon Sep 17 00:00:00 2001 From: Alexander Svensen Date: Mon, 6 Nov 2023 10:39:08 +0100 Subject: [PATCH 0929/1623] [nrf noup] testspec: Add audio - Add filter for audio tests Signed-off-by: Alexander Svensen (cherry picked from commit 2b1d418a6c8b17e028204bbefe4500f0286d46d4) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index c01ae703adf..007f4307aa9 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -218,3 +218,25 @@ - "subsys/bluetooth/**/*" - "!subsys/bluetooth/mesh/**/*" - "!subsys/bluetooth/audio/**/*" + +"CI-audio-test": + - "boards/arm/nrf5340_audio_dk_nrf5340/**/*" + - "drivers/flash/**/*" + - "drivers/spi/**/*" + - "drivers/gpio/**/*" + - "drivers/i2c/**/*" + - "drivers/watchdog/**/*" + - "include/dfu/**/*" + - "include/mgmt/mcumgr/**/*" + - "samples/bluetooth/hci_rpmsg/**/*" + - "soc/arm/nordic_nrf/**/*" + - "subsys/bluetooth/audio/**/*" + - "subsys/bluetooth/host/**/*" + - "subsys/dfu/**/*" + - "subsys/fs/**/*" + - "subsys/mgmt/mcumgr/**/*" + - "subsys/sd/**/*" + - "subsys/storage/**/*" + - "subsys/task_wdt/**/*" + - "subsys/usb/**/*" + - "subsys/zbus/**/*" From 22735e0e29f6331a97202d2aa284377d0f6a998a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ga=C5=82da?= Date: Mon, 6 Nov 2023 18:44:48 +0100 Subject: [PATCH 0930/1623] [nrf noup] ci: Add CI-run-zephyr-twister test spec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI-run-zephyr-twister is used to determine if twister tests from sdk-zephyr should be run on PR to sdk-nrf repository. Signed-off-by: Jan Gałda (cherry picked from commit ede86123951b7f824f91f6ebd1ea15f307f9a208) Signed-off-by: Dominik Ermel --- .github/test-spec.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 007f4307aa9..789f1a4e235 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -1,4 +1,19 @@ # This is the Jenkins ci variant of the .github/labler.yaml + +"CI-run-zephyr-twister": + - any: + - "!.github/**/*" + - "!doc/**/*" + - "!CODEOWNERS" + - "!LICENSE" + - "!**/*.rst" + - "!VERSION" + - "!submanifests/**/*" + - "!MAINTAINERS.yml" + - "!version.h.in" + - "!Jenkinsfile" + - "!**/*.md" + "CI-iot-zephyr-lwm2m-test": - "drivers/console/**/*" - "drivers/flash/**/*" From 36710dee098619426dcadcecdb7f217c12d01910 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Thu, 9 Nov 2023 13:30:15 +0100 Subject: [PATCH 0931/1623] [nrf noup] Bluetooth: Mesh: adapt SDC specific api usage Usage of the Softdevice specific api has been adapted to upstream adv changes. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 533baa16b5a6750cf59a7ce7257bc09bcac09637) Signed-off-by: Dominik Ermel --- subsys/bluetooth/mesh/adv_ext.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 525e5ee5066..fe9fc4fd403 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -529,8 +529,8 @@ int bt_mesh_adv_enable(void) if (IS_ENABLED(CONFIG_BT_LL_SOFTDEVICE) && IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - adv->tag == BT_MESH_FRIEND_ADV) { - err = set_adv_randomness(adv->instance->handle, 0); + advs[i].tags == BT_MESH_ADV_TAG_BIT_FRIEND) { + err = set_adv_randomness(advs[i].instance->handle, 0); if (err) { LOG_ERR("Failed to set zero randomness: %d", err); } From d0b22f5deb110cbe508a847faf79d4b7add5b4bf Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Wed, 15 Nov 2023 12:55:40 +0100 Subject: [PATCH 0932/1623] [nrf noup] boards: arm: nrf9131ek: enable tfm This patch backports the nrf9131ek to a time before tfm was refactored. To be reverted when TF-M is updated. Signed-off-by: Maximilian Deubel (cherry picked from commit 6755c4785640afb19f4973563f9737eece9f57c4) Signed-off-by: Dominik Ermel --- boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig b/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig index 0ece4f9a2ac..378a58fb6e3 100644 --- a/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig +++ b/boards/arm/nrf9131ek_nrf9131/Kconfig.defconfig @@ -8,6 +8,22 @@ if BOARD_NRF9131EK_NRF9131 || BOARD_NRF9131EK_NRF9131_NS config BOARD default "nrf9131ek_nrf9131" + +# By default, if we build for a Non-Secure version of the board, +# enable building with TF-M as the Secure Execution Environment. +config BUILD_WITH_TFM + default y if BOARD_NRF9131EK_NRF9131_NS + +if BUILD_WITH_TFM + +# By default, if we build with TF-M, instruct build system to +# flash the combined TF-M (Secure) & Zephyr (Non Secure) image +config TFM_FLASH_MERGED_BINARY + bool + default y + +endif # BUILD_WITH_TFM + # For the secure version of the board the firmware is linked at the beginning # of the flash, or into the code-partition defined in DT if it is intended to # be loaded by MCUboot. If the secure firmware is to be combined with a non- From 26cebfca894cccafb2237dfdc0eaf7fde354f457 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 21 Nov 2023 19:02:47 +0100 Subject: [PATCH 0933/1623] [nrf fromlist] tfm: Remove limitation of enabling FP when build TF-M NS application Remove limitation of enabling FP when building TF-M NS application. FP support have been fixed in the tf-m-tests repository for NS application. Board support for NS executable may still be lacking for some boards. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65537 Signed-off-by: Joakim Andersson (cherry picked from commit 90a72daae2c8715d760d974a7d294aa2eb6b38c4) Signed-off-by: Dominik Ermel --- arch/arm/core/Kconfig | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/arm/core/Kconfig b/arch/arm/core/Kconfig index 75a64ea90eb..4afe6c06ab5 100644 --- a/arch/arm/core/Kconfig +++ b/arch/arm/core/Kconfig @@ -268,9 +268,6 @@ choice config FP_HARDABI bool "Floating point Hard ABI" - # TF-M build system does not build the NS app and libraries correctly with Hard ABI. - # This limitation should be removed in the next TF-M synchronization. - depends on !TFM_BUILD_NS help This option selects the Floating point ABI in which hardware floating point instructions are generated and uses FPU-specific calling From 03b90ac09da07502981123dc46a63a8cb283b7ab Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 10:29:53 +0530 Subject: [PATCH 0934/1623] [nrf fromlist] wifi: shell: Fix unbalanced braces Fix the typo in braces for help. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata (cherry picked from commit e3429fadeece82ab46940a23edf4dc0954d9a718) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 5f7eb5ba0ee..c50175e086f 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1673,15 +1673,15 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" - "[-i : Interface index - optional argument\n" - "[-s : Station mode.\n" - "[-m : Monitor mode.\n" - "[-p : Promiscuous mode.\n" - "[-t : TX-Injection mode.\n" - "[-a : AP mode.\n" - "[-k : Softap mode.\n" - "[-h : Help.\n" - "[-g : Get current mode for a specific interface index.\n" + "[-i] : Interface index - optional argument\n" + "[-s] : Station mode.\n" + "[-m] : Monitor mode.\n" + "[-p] : Promiscuous mode.\n" + "[-t] : TX-Injection mode.\n" + "[-a] : AP mode.\n" + "[-k] : Softap mode.\n" + "[-h] : Help.\n" + "[-g] : Get current mode for a specific interface index.\n" "Usage: Get operation example for interface index 1\n" "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" @@ -1692,14 +1692,14 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" "parameters:" - "[-i : Interface index - optional argument.\n" - "[-a : Enable all packet filter modes\n" - "[-m : Enable management packets to allowed up the stack.\n" - "[-c : Enable control packets to be allowed up the stack.\n" - "[-d : Enable Data packets to be allowed up the stack.\n" - "[-g : Get current filter settings for a specific interface index.\n" - "<-b : Capture length buffer size for each packet to be captured - optional argument.\n" - "<-h : Help.\n" + "[-i] : Interface index - optional argument.\n" + "[-a] : Enable all packet filter modes\n" + "[-m] : Enable management packets to allowed up the stack.\n" + "[-c] : Enable control packets to be allowed up the stack.\n" + "[-d] : Enable Data packets to be allowed up the stack.\n" + "[-g] : Get current filter settings for a specific interface index.\n" + "<-b> : Capture length buffer size for each packet to be captured - optional argument.\n" + "<-h> : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" @@ -1710,10 +1710,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" "parameters:" - "[-i : Interface index - optional argument.\n" - "[-c : Set a specific channel number to the lower layer.\n" - "[-g : Get current set channel number from the lower layer.\n" - "[-h : Help.\n" + "[-i] : Interface index - optional argument.\n" + "[-c] : Set a specific channel number to the lower layer.\n" + "[-g] : Get current set channel number from the lower layer.\n" + "[-h] : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" From ea492ab1190b2fd08cba1119b40ee525bd0455ed Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 10:36:06 +0530 Subject: [PATCH 0935/1623] [nrf fromlist] wifi: shell: Fix brackets type for optional params General notation for Optional params is to use square brackets. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata (cherry picked from commit ad503caacd6004efb4f386ce526f8f1f8e1952a0) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index c50175e086f..64f125dea01 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1631,11 +1631,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(connect, NULL, "Connect to a Wi-Fi AP\n" "\"\"\n" - "\n" - "\n" - "\n" + "[channel number: 0 means all]\n" + "[PSK: valid only for secure SSIDs]\n" + "[Security type: valid only for secure SSIDs]\n" "0:None, 1:PSK, 2:PSK-256, 3:SAE\n" - "\n" + "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_connect), SHELL_CMD(disconnect, NULL, "Disconnect from the Wi-Fi AP", @@ -1667,7 +1667,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" "Usage: wifi reg_domain [ISO/IEC 3166-1 alpha2] [-f]\n" - "-f: Force to use this regulatory hint over any other regulatory hints\n" + "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain), SHELL_CMD(mode, NULL, "mode operational setting\n" From b16198a61fb3225013e1b2a0791ed2289ff978c0 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 10:37:21 +0530 Subject: [PATCH 0936/1623] [nrf fromlist] wifi: shell: Fix PS mode help There is only a single parameter called "mode" that takes two possible values. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata (cherry picked from commit 9c2c52a44a28f974fa1280b35f06875b067c69ea) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 64f125dea01..cd3390828d1 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1644,8 +1644,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, cmd_wifi_ps), SHELL_CMD_ARG(ps_mode, NULL, - "\n" - "", + "\n", cmd_wifi_ps_mode, 2, 0), @@ -1733,8 +1732,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, 0), SHELL_CMD_ARG(ps_wakeup_mode, NULL, - " : Set PS wake up mode to DTIM interval\n" - " : Set PS wake up mode to listen interval", + "\n", cmd_wifi_ps_wakeup_mode, 2, 0), From d20bbab16aec2aaca8ce716723c3fc641b9cedf8 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 10:40:25 +0530 Subject: [PATCH 0937/1623] [nrf fromlist] wifi: shell: Add missing security options Newly added security types are missing from the help. Also, now that we have two variants of PSK, use the prefix to disambiguate. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata (cherry picked from commit 7c23186c1282125353cacca44899f030706b2b68) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index cd3390828d1..767ac3eaf05 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1634,7 +1634,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[channel number: 0 means all]\n" "[PSK: valid only for secure SSIDs]\n" "[Security type: valid only for secure SSIDs]\n" - "0:None, 1:PSK, 2:PSK-256, 3:SAE\n" + "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_connect), From 4ffdc9cb53bf752a13a6ee1ef6ad3f08b96159d1 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 10:57:40 +0530 Subject: [PATCH 0938/1623] [nrf fromlist] wifi: shell: Enforce argument count checks Use the proper API to enforce argument count checks as per mandatory or optional params. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata (cherry picked from commit bebc385d82e4fd230ac7afd0d580a8045624e921) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 74 ++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 767ac3eaf05..d0cd0551897 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1598,37 +1598,43 @@ static int cmd_wifi_packet_filter(const struct shell *sh, size_t argc, char *arg } SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, - SHELL_CMD(disable, NULL, + SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode", - cmd_wifi_ap_disable), - SHELL_CMD(enable, NULL, " [channel] [PSK]", - cmd_wifi_ap_enable), + cmd_wifi_ap_disable, + 1, 0), + SHELL_CMD_ARG(enable, NULL, " [channel] [PSK]", + cmd_wifi_ap_enable, + 2, 1), SHELL_SUBCMD_SET_END ); SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops, - SHELL_CMD(quick_setup, NULL, " Start a TWT flow with defaults:\n" + SHELL_CMD_ARG(quick_setup, NULL, " Start a TWT flow with defaults:\n" " \n", - cmd_wifi_twt_setup_quick), - SHELL_CMD(setup, NULL, " Start a TWT flow:\n" + cmd_wifi_twt_setup_quick, + 3, 0), + SHELL_CMD_ARG(setup, NULL, " Start a TWT flow:\n" "\n" "\n" " " " \n", - cmd_wifi_twt_setup), - SHELL_CMD(teardown, NULL, " Teardown a TWT flow:\n" + cmd_wifi_twt_setup, + 11, 0), + SHELL_CMD_ARG(teardown, NULL, " Teardown a TWT flow:\n" "\n" "\n" " \n", - cmd_wifi_twt_teardown), - SHELL_CMD(teardown_all, NULL, " Teardown all TWT flows\n", - cmd_wifi_twt_teardown_all), + cmd_wifi_twt_teardown, + 5, 0), + SHELL_CMD_ARG(teardown_all, NULL, " Teardown all TWT flows\n", + cmd_wifi_twt_teardown_all, + 1, 0), SHELL_SUBCMD_SET_END ); SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(ap, &wifi_cmd_ap, "Access Point mode commands", NULL), - SHELL_CMD(connect, NULL, + SHELL_CMD_ARG(connect, NULL, "Connect to a Wi-Fi AP\n" "\"\"\n" "[channel number: 0 means all]\n" @@ -1637,18 +1643,21 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required", - cmd_wifi_connect), - SHELL_CMD(disconnect, NULL, "Disconnect from the Wi-Fi AP", - cmd_wifi_disconnect), - SHELL_CMD(ps, NULL, "Configure Wi-F PS on/off, no arguments will dump config", - cmd_wifi_ps), + cmd_wifi_connect, + 2, 5), + SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", + cmd_wifi_disconnect, + 1, 0), + SHELL_CMD_ARG(ps, NULL, "Configure Wi-F PS on/off, no arguments will dump config", + cmd_wifi_ps, + 1, 1), SHELL_CMD_ARG(ps_mode, NULL, "\n", cmd_wifi_ps_mode, 2, 0), - SHELL_CMD(scan, NULL, + SHELL_CMD_ARG(scan, NULL, "Scan for Wi-Fi APs\n" "OPTIONAL PARAMETERS:\n" "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active.\n" @@ -1659,17 +1668,19 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535.\n" "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6-11,14_5:36,149-165,44\n" "[-h, --help] : Print out the help for the scan command.", - cmd_wifi_scan), - SHELL_CMD(statistics, NULL, "Wi-Fi interface statistics", cmd_wifi_stats), - SHELL_CMD(status, NULL, "Status of the Wi-Fi interface", cmd_wifi_status), + cmd_wifi_scan, + 1, 8), + SHELL_CMD_ARG(statistics, NULL, "Wi-Fi interface statistics", cmd_wifi_stats, 1, 0), + SHELL_CMD_ARG(status, NULL, "Status of the Wi-Fi interface", cmd_wifi_status, 1, 0), SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows", NULL), - SHELL_CMD(reg_domain, NULL, + SHELL_CMD_ARG(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" "Usage: wifi reg_domain [ISO/IEC 3166-1 alpha2] [-f]\n" "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", - cmd_wifi_reg_domain), - SHELL_CMD(mode, NULL, "mode operational setting\n" + cmd_wifi_reg_domain, + 2, 1), + SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" "[-i] : Interface index - optional argument\n" @@ -1685,8 +1696,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" "wifi mode -i1 -sp\n", - cmd_wifi_mode), - SHELL_CMD(packet_filter, NULL, "mode filter setting\n" + cmd_wifi_mode, + 1, 9), + SHELL_CMD_ARG(packet_filter, NULL, "mode filter setting\n" "This command is used to set packet filter setting when\n" "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" @@ -1703,8 +1715,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" "wifi packet_filter -i1 -md\n", - cmd_wifi_packet_filter), - SHELL_CMD(channel, NULL, "wifi channel setting\n" + cmd_wifi_packet_filter, + 1, 8), + SHELL_CMD_ARG(channel, NULL, "wifi channel setting\n" "This command is used to set the channel when\n" "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" @@ -1717,7 +1730,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" "wifi -i1 -c5\n", - cmd_wifi_channel), + cmd_wifi_channel, + 1, 4), SHELL_CMD_ARG(ps_timeout, NULL, " - PS inactivity timer(in ms)", From 893e58ca65abc6f5da237733ef7a4ebdecb0bc29 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 1 Dec 2023 11:06:51 +0530 Subject: [PATCH 0939/1623] [nrf fromlist] wifi: shell: Add long arguments to help Long arguments are handy for new users. Also use hyphen's rather than underscore to follow the convention. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66005 Signed-off-by: Chaitanya Tata (cherry picked from commit f721e835805a6e6bae6e7c491f3d4369d64412e4) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index d0cd0551897..c5b8f60d933 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1275,10 +1275,10 @@ void parse_mode_args_to_params(const struct shell *sh, int argc, int opt; int option_index = 0; - static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, + static struct option long_options[] = {{"if-index", optional_argument, 0, 'i'}, {"sta", no_argument, 0, 's'}, {"monitor", no_argument, 0, 'm'}, - {"TX-injection", no_argument, 0, 't'}, + {"tx-injection", no_argument, 0, 't'}, {"promiscuous", no_argument, 0, 'p'}, {"ap", no_argument, 0, 'a'}, {"softap", no_argument, 0, 'k'}, @@ -1385,7 +1385,7 @@ void parse_channel_args_to_params(const struct shell *sh, int argc, int opt; int option_index = 0; - static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, + static struct option long_options[] = {{"if-index", optional_argument, 0, 'i'}, {"channel", required_argument, 0, 'c'}, {"get", no_argument, 0, 'g'}, {"help", no_argument, 0, 'h'}, @@ -1491,8 +1491,8 @@ void parse_filter_args_to_params(const struct shell *sh, int argc, int opt; int option_index = 0; - static struct option long_options[] = {{"if_index", optional_argument, 0, 'i'}, - {"capture_len", optional_argument, 0, 'b'}, + static struct option long_options[] = {{"if-index", optional_argument, 0, 'i'}, + {"capture-len", optional_argument, 0, 'b'}, {"all", no_argument, 0, 'a'}, {"mgmt", no_argument, 0, 'm'}, {"ctrl", no_argument, 0, 'c'}, @@ -1683,15 +1683,15 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" - "[-i] : Interface index - optional argument\n" - "[-s] : Station mode.\n" - "[-m] : Monitor mode.\n" - "[-p] : Promiscuous mode.\n" - "[-t] : TX-Injection mode.\n" - "[-a] : AP mode.\n" - "[-k] : Softap mode.\n" - "[-h] : Help.\n" - "[-g] : Get current mode for a specific interface index.\n" + "[-i, --if-index ] : Interface index.\n" + "[-s, --sta] : Station mode.\n" + "[-m, --monitor] : Monitor mode.\n" + "[-p, --promiscuous] : Promiscuous mode.\n" + "[-t, --tx-injection] : TX-Injection mode.\n" + "[-a, --ap] : AP mode.\n" + "[-k, --softap] : Softap mode.\n" + "[-h, --help] : Help.\n" + "[-g, --get] : Get current mode for a specific interface index.\n" "Usage: Get operation example for interface index 1\n" "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" @@ -1703,14 +1703,14 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" "parameters:" - "[-i] : Interface index - optional argument.\n" - "[-a] : Enable all packet filter modes\n" - "[-m] : Enable management packets to allowed up the stack.\n" - "[-c] : Enable control packets to be allowed up the stack.\n" - "[-d] : Enable Data packets to be allowed up the stack.\n" - "[-g] : Get current filter settings for a specific interface index.\n" - "<-b> : Capture length buffer size for each packet to be captured - optional argument.\n" - "<-h> : Help.\n" + "[-i, --if-index ] : Interface index.\n" + "[-a, --all] : Enable all packet filter modes\n" + "[-m, --mgmt] : Enable management packets to allowed up the stack.\n" + "[-c, --ctrl] : Enable control packets to be allowed up the stack.\n" + "[-d, --data] : Enable Data packets to be allowed up the stack.\n" + "[-g, --get] : Get current filter settings for a specific interface index.\n" + "[-b, --capture-len ] : Capture length buffer size for each packet to be captured\n" + "[-h, --help] : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" @@ -1722,10 +1722,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" "parameters:" - "[-i] : Interface index - optional argument.\n" - "[-c] : Set a specific channel number to the lower layer.\n" - "[-g] : Get current set channel number from the lower layer.\n" - "[-h] : Help.\n" + "[-i, --if-index ] : Interface index.\n" + "[-c, --channel ] : Set a specific channel number to the lower layer.\n" + "[-g, --get] : Get current set channel number from the lower layer.\n" + "[-h, --help] : Help.\n" "Usage: Get operation example for interface index 1\n" "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" From 130824afa4d94bf56a6c3ea9e83384744eb7d9c4 Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Tue, 21 Nov 2023 11:01:17 +0100 Subject: [PATCH 0940/1623] [nrf fromtree] twister: pytest: Add --pytest-args to Twister command line Extend Twister command line with --pytest-args. This parameter is passed to pytest subprocess. It allows to select a specific testcase from a test suite. Signed-off-by: Grzegorz Chwierut (cherry picked from commit a1698b691d9bfd25dfd70fc1ed42e819cdec61a3) (cherry picked from commit 9566a94fc5175eae833af9ec264f68bcf16bc3f6) Signed-off-by: Dominik Ermel --- doc/develop/test/pytest.rst | 10 +++ .../pylib/twister/twisterlib/environment.py | 5 ++ scripts/pylib/twister/twisterlib/harness.py | 19 ++++-- .../pytest_integration/test_harness_pytest.py | 66 +++++++++++++++++++ 4 files changed, 96 insertions(+), 4 deletions(-) diff --git a/doc/develop/test/pytest.rst b/doc/develop/test/pytest.rst index e644882191e..f3db6fcee89 100644 --- a/doc/develop/test/pytest.rst +++ b/doc/develop/test/pytest.rst @@ -56,6 +56,16 @@ Pytest scans the given locations looking for tests, following its default `discovery rules `_ One can also pass some extra arguments to the pytest from yaml file using ``pytest_args`` keyword under ``harness_config``, e.g.: ``pytest_args: [‘-k=test_method’, ‘--log-level=DEBUG’]``. +There is also an option to pass ``--pytest-args`` through Twister command line parameters. +This can be particularly useful when one wants to select a specific testcase from a test suite. +For instance, one can use a command: + +.. code-block:: console + + $ ./scripts/twister --platform native_sim -T samples/subsys/testsuite/pytest/shell \ + -s samples/subsys/testsuite/pytest/shell/sample.pytest.shell \ + --pytest-args='-k test_shell_print_version' + Helpers & fixtures ================== diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index 86965f1f9cf..b7e11406cd4 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -216,6 +216,11 @@ def add_parse_arguments(parser = None): and 'fifo_loop' is a name of a function found in main.c without test prefix. """) + parser.add_argument("--pytest-args", + help="""Pass additional arguments to the pytest subprocess. This parameter + will override the pytest_args from the harness_config in YAML file. + """) + valgrind_asan_group.add_argument( "--enable-valgrind", action="store_true", help="""Run binary through valgrind and check for several memory access diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index 052def7162a..dece1673c7a 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -309,8 +309,9 @@ def pytest_run(self, timeout): def generate_command(self): config = self.instance.testsuite.harness_config + handler: Handler = self.instance.handler pytest_root = config.get('pytest_root', ['pytest']) if config else ['pytest'] - pytest_args = config.get('pytest_args', []) if config else [] + pytest_args_yaml = config.get('pytest_args', []) if config else [] pytest_dut_scope = config.get('pytest_dut_scope', None) if config else None command = [ 'pytest', @@ -324,12 +325,19 @@ def generate_command(self): ] command.extend([os.path.normpath(os.path.join( self.source_dir, os.path.expanduser(os.path.expandvars(src)))) for src in pytest_root]) - command.extend(pytest_args) + + if handler.options.pytest_args: + command.append(handler.options.pytest_args) + if pytest_args_yaml: + logger.warning(f'The pytest_args ({handler.options.pytest_args}) specified ' + 'in the command line will override the pytest_args defined ' + f'in the YAML file {pytest_args_yaml}') + else: + command.extend(pytest_args_yaml) + if pytest_dut_scope: command.append(f'--dut-scope={pytest_dut_scope}') - handler: Handler = self.instance.handler - if handler.options.verbose > 1: command.extend([ '--log-cli-level=DEBUG', @@ -489,6 +497,9 @@ def _parse_report_file(self, report): tc.status = 'error' tc.reason = elem.get('message') tc.output = elem.text + else: + self.state = 'skipped' + self.instance.reason = 'No tests collected' class Gtest(Harness): diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index 150980059b3..fc60b99e0d1 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -25,6 +25,7 @@ def testinstance() -> TestInstance: testinstance.handler = mock.Mock() testinstance.handler.options = mock.Mock() testinstance.handler.options.verbose = 1 + testinstance.handler.options.pytest_args = None testinstance.handler.type_str = 'native' return testinstance @@ -67,6 +68,18 @@ def test_pytest_command_extra_args(testinstance: TestInstance): assert c in command +def test_pytest_command_extra_args_in_options(testinstance: TestInstance): + pytest_harness = Pytest() + pytest_args_from_yaml = '-k test_from_yaml' + pytest_args_from_cmd = '-k test_from_cmd' + testinstance.testsuite.harness_config['pytest_args'] = [pytest_args_from_yaml] + testinstance.handler.options.pytest_args = pytest_args_from_cmd + pytest_harness.configure(testinstance) + command = pytest_harness.generate_command() + assert pytest_args_from_cmd in command + assert pytest_args_from_yaml not in command + + @pytest.mark.parametrize( ('pytest_root', 'expected'), [ @@ -222,3 +235,56 @@ def test_skip_2(): assert len(testinstance.testcases) == 2 for tc in testinstance.testcases: assert tc.status == "skipped" + + +def test_if_report_with_filter(pytester, testinstance: TestInstance): + test_file_content = textwrap.dedent(""" + import pytest + def test_A(): + pass + def test_B(): + pass + """) + test_file = pytester.path / 'test_filter.py' + test_file.write_text(test_file_content) + report_file = pytester.path / 'report.xml' + result = pytester.runpytest( + str(test_file), + '-k', 'test_B', + f'--junit-xml={str(report_file)}' + ) + result.assert_outcomes(passed=1) + assert report_file.is_file() + + pytest_harness = Pytest() + pytest_harness.configure(testinstance) + pytest_harness.report_file = report_file + pytest_harness._update_test_status() + assert pytest_harness.state == "passed" + assert testinstance.status == "passed" + assert len(testinstance.testcases) == 1 + + +def test_if_report_with_no_collected(pytester, testinstance: TestInstance): + test_file_content = textwrap.dedent(""" + import pytest + def test_A(): + pass + """) + test_file = pytester.path / 'test_filter.py' + test_file.write_text(test_file_content) + report_file = pytester.path / 'report.xml' + result = pytester.runpytest( + str(test_file), + '-k', 'test_B', + f'--junit-xml={str(report_file)}' + ) + result.assert_outcomes(passed=0) + assert report_file.is_file() + + pytest_harness = Pytest() + pytest_harness.configure(testinstance) + pytest_harness.report_file = report_file + pytest_harness._update_test_status() + assert pytest_harness.state == "skipped" + assert testinstance.status == "skipped" From 2837a3c6bd07e5920bfd0dcbab9392086f1769f3 Mon Sep 17 00:00:00 2001 From: Ederson de Souza Date: Mon, 27 Nov 2023 17:09:07 -0800 Subject: [PATCH 0941/1623] [nrf fromtree] scripts/pylib/twister/twisterlib: Support multiple `--pytest-args` One can not even replace sucessfully pytest basic sample `pytest-args` with command line "--pytest-args", as all it does is to append a single string to current list of commands, making it impossible to send several arguments. This patch fixes that by allowing several instances of `--pytest-args` to compose the whole list of arguments to be passed to pytest. Signed-off-by: Ederson de Souza (cherry picked from commit 10ec2b129c9102a867d1ce26eb8cb986f95b6d98) (cherry picked from commit ad95bc81b8b9d44431c092a3cee4e7204dfceba4) Signed-off-by: Dominik Ermel --- doc/develop/test/pytest.rst | 2 ++ .../pylib/twister/twisterlib/environment.py | 3 ++- scripts/pylib/twister/twisterlib/harness.py | 19 ++++++++++--------- .../pytest_integration/test_harness_pytest.py | 5 +++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/doc/develop/test/pytest.rst b/doc/develop/test/pytest.rst index f3db6fcee89..f6ba54fa52e 100644 --- a/doc/develop/test/pytest.rst +++ b/doc/develop/test/pytest.rst @@ -67,6 +67,8 @@ For instance, one can use a command: --pytest-args='-k test_shell_print_version' +Note that ``--pytest-args`` can be passed multiple times to pass several arguments to the pytest. + Helpers & fixtures ================== diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index b7e11406cd4..16e19c85fec 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -216,7 +216,8 @@ def add_parse_arguments(parser = None): and 'fifo_loop' is a name of a function found in main.c without test prefix. """) - parser.add_argument("--pytest-args", + parser.add_argument( + "--pytest-args", action="append", help="""Pass additional arguments to the pytest subprocess. This parameter will override the pytest_args from the harness_config in YAML file. """) diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index dece1673c7a..8b8ad92fc51 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -326,15 +326,6 @@ def generate_command(self): command.extend([os.path.normpath(os.path.join( self.source_dir, os.path.expanduser(os.path.expandvars(src)))) for src in pytest_root]) - if handler.options.pytest_args: - command.append(handler.options.pytest_args) - if pytest_args_yaml: - logger.warning(f'The pytest_args ({handler.options.pytest_args}) specified ' - 'in the command line will override the pytest_args defined ' - f'in the YAML file {pytest_args_yaml}') - else: - command.extend(pytest_args_yaml) - if pytest_dut_scope: command.append(f'--dut-scope={pytest_dut_scope}') @@ -354,6 +345,16 @@ def generate_command(self): command.append('--device-type=custom') else: raise PytestHarnessException(f'Handling of handler {handler.type_str} not implemented yet') + + if handler.options.pytest_args: + command.extend(handler.options.pytest_args) + if pytest_args_yaml: + logger.warning(f'The pytest_args ({handler.options.pytest_args}) specified ' + 'in the command line will override the pytest_args defined ' + f'in the YAML file {pytest_args_yaml}') + else: + command.extend(pytest_args_yaml) + return command def _generate_parameters_for_hardware(self, handler: Handler): diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index fc60b99e0d1..befd384be37 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -71,12 +71,13 @@ def test_pytest_command_extra_args(testinstance: TestInstance): def test_pytest_command_extra_args_in_options(testinstance: TestInstance): pytest_harness = Pytest() pytest_args_from_yaml = '-k test_from_yaml' - pytest_args_from_cmd = '-k test_from_cmd' + pytest_args_from_cmd = ['-k', 'test_from_cmd'] testinstance.testsuite.harness_config['pytest_args'] = [pytest_args_from_yaml] testinstance.handler.options.pytest_args = pytest_args_from_cmd pytest_harness.configure(testinstance) command = pytest_harness.generate_command() - assert pytest_args_from_cmd in command + assert pytest_args_from_cmd[0] in command + assert pytest_args_from_cmd[1] in command assert pytest_args_from_yaml not in command From 85997eb5ce6d0dcebdc02488e347b0dc59aa2303 Mon Sep 17 00:00:00 2001 From: Adam Wojasinski Date: Fri, 1 Dec 2023 14:53:27 +0100 Subject: [PATCH 0942/1623] [nrf fromlist] manifest: hal_nordic: Update revision with fixed workaround in nrfx_qspi Pulls update in nrfx_qspi driver with fixed order of applying workaround for anomaly 215 on nRF52840 and anomaly 43 on nRF5340. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66034 Signed-off-by: Adam Wojasinski (cherry picked from commit e0dc936a4af5550f15d9e37ab9b44db5de452ee0) Signed-off-by: Dominik Ermel --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 14847109194..ed84e713620 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 56e0b052dff311c2f8eb08c6804e60fc79feb56f + revision: b9633ecea67bf52925d4c61455046223b46402b1 path: modules/hal/nordic groups: - hal From 414a63955a3e0e60301b1970266b7c659553eff3 Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Tue, 5 Dec 2023 13:48:37 +0100 Subject: [PATCH 0943/1623] [nrf fromtree] net: openthread: Openthread upmerge to `4ed44bc` This commit bumps openthread commit to `4ed44bc` and implements `CONFIG_OPENTHREAD_MULTIPAN_RCP` option. Signed-off-by: Przemyslaw Bida (cherry picked from commit 8f2b7a121bbf7b64fdf46c5c19231a12f96c4166) (cherry picked from commit 919457f5c1d9d491033b23efcf77197d687422a6) Signed-off-by: Dominik Ermel --- modules/openthread/CMakeLists.txt | 6 ++++++ modules/openthread/Kconfig.features | 3 +++ west.yml | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index 8afa1aec440..646b086ef1e 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -340,6 +340,12 @@ else() set(OT_MLR OFF CACHE BOOL "Enable Multicast Listener Registration feature for Thread 1.2" FORCE) endif() +if(CONFIG_OPENTHREAD_MULTIPAN_RCP) + set(OT_MULTIPAN_RCP ON CACHE BOOL "Enable Multi-PAN RCP" FORCE) +else() + set(OT_MULTIPAN_RCP OFF CACHE BOOL "Enable Multi-PAN RCP" FORCE) +endif() + if(CONFIG_OPENTHREAD_MULTIPLE_INSTANCE) set(OT_MULTIPLE_INSTANCE ON CACHE BOOL "Enable multiple instances" FORCE) else() diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index bd8a05ed9b9..2be5332cde3 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -218,6 +218,9 @@ config OPENTHREAD_MLR help Enable Multicast Listener Registration support for Thread 1.2 +config OPENTHREAD_MULTIPAN_RCP + bool "OpenThread multipan rcp" + config OPENTHREAD_MULTIPLE_INSTANCE bool "OpenThread multiple instances" diff --git a/west.yml b/west.yml index ed84e713620..c99118074eb 100644 --- a/west.yml +++ b/west.yml @@ -301,7 +301,7 @@ manifest: revision: 214f9fc1539f8e5937c0474cb6ee29b6dcb2d4b8 path: modules/lib/open-amp - name: openthread - revision: 193e77e40ec2387d458eaebd1e03902d86f484a5 + revision: 4ed44bc7d58d9a98c6cca13a50d38129045ab3df path: modules/lib/openthread - name: percepio path: modules/debug/percepio From 8e3a9faff9e21e2f92bc3f7a01bd77311c58087c Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 7 Dec 2023 15:05:13 +0100 Subject: [PATCH 0944/1623] [nrf fromlist] soc: nordic_nrf: Enable the TF-M NS storage partition for nordic boards Enable the TF-M NS storage partition for nordic boards. This partition is otherwise not used, and configured as secure. Fixes: #59376 Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66279 Signed-off-by: Joakim Andersson (cherry picked from commit 462ad3659295cc639b3c159573136731141a06cc) Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/CMakeLists.txt | 4 ++++ soc/arm/nordic_nrf/Kconfig | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/soc/arm/nordic_nrf/CMakeLists.txt b/soc/arm/nordic_nrf/CMakeLists.txt index 47364b35ffb..3b097d73569 100644 --- a/soc/arm/nordic_nrf/CMakeLists.txt +++ b/soc/arm/nordic_nrf/CMakeLists.txt @@ -25,4 +25,8 @@ if(CONFIG_BUILD_WITH_TFM) set_property(TARGET zephyr_property_target APPEND PROPERTY TFM_CMAKE_OPTIONS -DZEPHYR_BASE=${ZEPHYR_BASE} ) + + set_property(TARGET zephyr_property_target + APPEND PROPERTY TFM_CMAKE_OPTIONS -DNRF_NS_STORAGE=${CONFIG_TFM_NRF_NS_STORAGE} + ) endif() diff --git a/soc/arm/nordic_nrf/Kconfig b/soc/arm/nordic_nrf/Kconfig index 19e49c05454..0372492cd7d 100644 --- a/soc/arm/nordic_nrf/Kconfig +++ b/soc/arm/nordic_nrf/Kconfig @@ -45,6 +45,10 @@ config TFM_LOG_LEVEL_SILENCE Disable TF-M secure output if the uart1 node has not assigned GPIO pins using pinctrl. +config TFM_NRF_NS_STORAGE + bool "TF-M non-secure storage partition" + default y + endif # BUILD_WITH_TFM From 90826581f1ee32b99f1cafdffc2e634a495d8ee3 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Mon, 4 Dec 2023 15:27:08 +0100 Subject: [PATCH 0945/1623] [nrf noup] soc: arm: nRF53: Add SPU Flash/RAM alignment TF-M will uses SPU alignment during build time to make sure all partitions can be locked down with the SPU. So adding them for nRF53 Signed-off-by: Markus Swarowsky (cherry picked from commit 1f49692993f6ad7f1ee1e19ff27d3ff56659b23e) Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 3afcd96f70d..f72ae5ab004 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -104,12 +104,26 @@ config NRF_SPU_FLASH_REGION_SIZE help FLASH region size for the NRF_SPU peripheral +config NRF_SPU_FLASH_REGION_ALIGNMENT + hex + default 0x4000 + help + FLASH regions must be aligned to this value due to SPU HW + limitations. + config NRF_SPU_RAM_REGION_SIZE hex default 0x2000 help RAM region size for the NRF_SPU peripheral +config NRF_SPU_RAM_REGION_ALIGNMENT + hex + default 0x2000 + help + RAM regions must be aligned to this value due to SPU HW + limitations. + config SOC_NRF_GPIO_FORWARDER_FOR_NRF5340 bool depends on NRF_SOC_SECURE_SUPPORTED From 83be41dde2e00776f02e583d8e6e55743b6c2ef7 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Mon, 4 Dec 2023 15:27:14 +0100 Subject: [PATCH 0946/1623] [nrf noup] soc: arm: nRF91: Add SPU Flash/RAM alignment TF-M will uses SPU alignment during build time to make sure all partitions can be locked down with the SPU. So adding them for nRF91 Signed-off-by: Markus Swarowsky (cherry picked from commit 89be4330a38498731fe612f1343624fc3d0a098e) Signed-off-by: Dominik Ermel --- soc/arm/nordic_nrf/nrf91/Kconfig.series | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/soc/arm/nordic_nrf/nrf91/Kconfig.series b/soc/arm/nordic_nrf/nrf91/Kconfig.series index 1be69c377e5..08d36e5b48c 100644 --- a/soc/arm/nordic_nrf/nrf91/Kconfig.series +++ b/soc/arm/nordic_nrf/nrf91/Kconfig.series @@ -27,9 +27,23 @@ config NRF_SPU_FLASH_REGION_SIZE help FLASH region size for the NRF_SPU peripheral +config NRF_SPU_FLASH_REGION_ALIGNMENT + hex + default 0x8000 + help + FLASH regions must be aligned to this value due to SPU HW + limitations. + config NRF_SPU_RAM_REGION_SIZE hex default 0x2000 help RAM region size for the NRF_SPU peripheral + +config NRF_SPU_RAM_REGION_ALIGNMENT + hex + default 0x2000 + help + RAM regions must be aligned to this value due to SPU HW + limitations. endif From 80251a66e6ddacbd9fc2855f2ae5fd25c0e1a143 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 25 Aug 2023 13:44:29 +0200 Subject: [PATCH 0947/1623] [nrf fromtree] tfm: Harded build against TF-M built with unsecure keys Introduce Kconfig option in zephyr build system that reflects the TF-M cmake config variable with the same default value for dummy provisioning and have it satisfy the IAK present requirement. This configuration is not suitable for production, and by having this in zephyr configuration we can have this as part of the hardened configuration check. Signed-off-by: Joakim Andersson (cherry picked from commit 25787e2df66aef6979503d613c292043ac5f6291) (cherry picked from commit ec48dcb2ee4973bee58fbe610750fe62635a0e3f) Signed-off-by: Dominik Ermel --- boards/arm/b_u585i_iot02a/Kconfig.defconfig | 7 +++++++ modules/trusted-firmware-m/CMakeLists.txt | 17 ++++++++++++++++- modules/trusted-firmware-m/Kconfig.tfm | 11 +++++++++++ scripts/kconfig/hardened.csv | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/boards/arm/b_u585i_iot02a/Kconfig.defconfig b/boards/arm/b_u585i_iot02a/Kconfig.defconfig index ae1e57aba8e..e8224106dae 100644 --- a/boards/arm/b_u585i_iot02a/Kconfig.defconfig +++ b/boards/arm/b_u585i_iot02a/Kconfig.defconfig @@ -16,4 +16,11 @@ config SPI_STM32_INTERRUPT config USE_DT_CODE_PARTITION default y if TRUSTED_EXECUTION_NONSECURE +if BUILD_WITH_TFM + +config TFM_DUMMY_PROVISIONING + default n + +endif # BUILD_WITH_TFM + endif # BOARD_B_U585I_IOT02A diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index 177a47e28d6..ad1109d849b 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -95,6 +95,12 @@ if (CONFIG_BUILD_WITH_TFM) list(APPEND TFM_CMAKE_ARGS -DMCUBOOT_IMAGE_NUMBER=${CONFIG_TFM_MCUBOOT_IMAGE_NUMBER}) endif() + if (CONFIG_TFM_DUMMY_PROVISIONING) + list(APPEND TFM_CMAKE_ARGS -DTFM_DUMMY_PROVISIONING=ON) + else() + list(APPEND TFM_CMAKE_ARGS -DTFM_DUMMY_PROVISIONING=OFF) + endif() + if (CONFIG_TFM_EXCEPTION_INFO_DUMP) list(APPEND TFM_CMAKE_ARGS -DTFM_EXCEPTION_INFO_DUMP=ON) else() @@ -579,4 +585,13 @@ if (CONFIG_BUILD_WITH_TFM) ${MERGED_FILE} ) endif() -endif() + + if(CONFIG_TFM_DUMMY_PROVISIONING) + message(WARNING + "TFM_DUMMY_PROVISIONING is enabled: + The device will be provisioned using dummy keys and is NOT secure! + This is not suitable for production" + ) + endif() + +endif() # CONFIG_BUILD_WITH_TFM diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index b635347b6e1..fed6ae4f485 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -177,6 +177,17 @@ config TFM_PARTITION_PLATFORM_CUSTOM_REBOOT Instead the application will have to override the weak ARM implementation of sys_arch_reset(). +config TFM_DUMMY_PROVISIONING + bool "Provision with dummy values. NOT to be used in production" + default y + help + If this option is enabled (as it is by default), a set of dummy + keys / data will be provisioned. The dummy IAK matches the IAK tested + by the TF-M tests, and the dummy bl2 ROTPKs match the dummy bl2 keys + used by default. + This option MUST not be used in production hardware, as the keys are + insecure. + config TFM_BL2_NOT_SUPPORTED bool help diff --git a/scripts/kconfig/hardened.csv b/scripts/kconfig/hardened.csv index ee95b54b3a7..6cc978f7e56 100644 --- a/scripts/kconfig/hardened.csv +++ b/scripts/kconfig/hardened.csv @@ -39,6 +39,7 @@ TEST_RANDOM_GENERATOR,n TEST_SHELL,n TEST_USERSPACE,n TFM_CMAKE_BUILD_TYPE_DEBUG,n +TFM_DUMMY_PROVISIONING,n THREAD_MONITOR,n THREAD_NAME,n TIMER_RANDOM_GENERATOR,n From cf3cec5e97911a6a1e4b4d1b93b48f2508a46d34 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 25 Aug 2023 13:55:49 +0200 Subject: [PATCH 0948/1623] [nrf fromtree] tfm: Enforce initial attestation with required key provisioned Enforce that the initial attestation partition has the required initial attestation key provisioned. If the initial attestation key (IAK) is not present during boot of TF-M the system will panic during initialization. Signed-off-by: Joakim Andersson (cherry picked from commit 2687376effac881c550e2c568c3d4ad10a67385b) (cherry picked from commit 2ac74ca47b0ae06ff19755985e01b07b150f53b5) Signed-off-by: Dominik Ermel --- boards/arm/b_u585i_iot02a/Kconfig.defconfig | 4 ++++ modules/trusted-firmware-m/Kconfig.tfm | 8 ++++++++ modules/trusted-firmware-m/Kconfig.tfm.partitions | 1 + 3 files changed, 13 insertions(+) diff --git a/boards/arm/b_u585i_iot02a/Kconfig.defconfig b/boards/arm/b_u585i_iot02a/Kconfig.defconfig index e8224106dae..6b3b72554ff 100644 --- a/boards/arm/b_u585i_iot02a/Kconfig.defconfig +++ b/boards/arm/b_u585i_iot02a/Kconfig.defconfig @@ -18,6 +18,10 @@ config USE_DT_CODE_PARTITION if BUILD_WITH_TFM +# Initial Attestation key provisioned by the BL1 bootloader +config TFM_INITIAL_ATTESTATION_KEY + default y + config TFM_DUMMY_PROVISIONING default n diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index fed6ae4f485..a0d71328540 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -179,6 +179,7 @@ config TFM_PARTITION_PLATFORM_CUSTOM_REBOOT config TFM_DUMMY_PROVISIONING bool "Provision with dummy values. NOT to be used in production" + select TFM_INITIAL_ATTESTATION_KEY default y help If this option is enabled (as it is by default), a set of dummy @@ -188,6 +189,13 @@ config TFM_DUMMY_PROVISIONING This option MUST not be used in production hardware, as the keys are insecure. +config TFM_INITIAL_ATTESTATION_KEY + bool + help + Hidden option to mark that the TF-M platform has an initial + attestation key, which is a requirement for the Initial Attestation + partition. + config TFM_BL2_NOT_SUPPORTED bool help diff --git a/modules/trusted-firmware-m/Kconfig.tfm.partitions b/modules/trusted-firmware-m/Kconfig.tfm.partitions index cd9aaadb1ec..67b46f5328b 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm.partitions +++ b/modules/trusted-firmware-m/Kconfig.tfm.partitions @@ -44,6 +44,7 @@ config TFM_PARTITION_CRYPTO config TFM_PARTITION_INITIAL_ATTESTATION bool "Secure partition 'Initial Attestation'" depends on TFM_PARTITION_CRYPTO + depends on TFM_INITIAL_ATTESTATION_KEY default n help Setting this option will cause '-DTFM_PARTITION_INITIAL_ATTESTATION' From de501648fc3071d44bb0b6169c09ad9ed3d71b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Fri, 3 Nov 2023 12:08:09 +0100 Subject: [PATCH 0949/1623] [nrf fromtree] drivers: nrf_qspi_nor: Prevent reading status before sending RDPD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After entering the Deep Power-down mode, some flash chips ignore all commands except from the one that releases the chip from the DP mode and it is not possible to successfully read their Status Register then. Since the QSPI peripheral tries to read this register when it is being activated, it consequently fails to send the actual command that would release the flash chip from the DP mode if that is to be done right after QSPI initialization. Prevent this problem by performing the QSPI activation with all pins disconnected. This causes that the Status Register value is read as all zeros and allows the activation to always finish successfully, and the RDPD command to be properly sent. Signed-off-by: Andrzej Głąbek (cherry picked from commit 1727bbcc7046eb5870df7409310d58e0c9483233) (cherry picked from commit 93e398cd1fdd7abb0a6ec347ebaa09f1ff5172ab) Signed-off-by: Dominik Ermel --- drivers/flash/nrf_qspi_nor.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index 28c705f6707..467d0643d48 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -1339,15 +1339,34 @@ static int enter_dpd(const struct device *const dev) static int exit_dpd(const struct device *const dev) { if (IS_ENABLED(DT_INST_PROP(0, has_dpd))) { + nrf_qspi_pins_t pins; + nrf_qspi_pins_t disconnected_pins = { + .sck_pin = NRF_QSPI_PIN_NOT_CONNECTED, + .csn_pin = NRF_QSPI_PIN_NOT_CONNECTED, + .io0_pin = NRF_QSPI_PIN_NOT_CONNECTED, + .io1_pin = NRF_QSPI_PIN_NOT_CONNECTED, + .io2_pin = NRF_QSPI_PIN_NOT_CONNECTED, + .io3_pin = NRF_QSPI_PIN_NOT_CONNECTED, + }; struct qspi_cmd cmd = { .op_code = SPI_NOR_CMD_RDPD, }; uint32_t t_exit_dpd = DT_INST_PROP_OR(0, t_exit_dpd, 0); - int ret; + nrfx_err_t res; + int rc; - ret = qspi_send_cmd(dev, &cmd, false); - if (ret < 0) { - return ret; + nrf_qspi_pins_get(NRF_QSPI, &pins); + nrf_qspi_pins_set(NRF_QSPI, &disconnected_pins); + res = nrfx_qspi_activate(true); + nrf_qspi_pins_set(NRF_QSPI, &pins); + + if (res != NRFX_SUCCESS) { + return -EIO; + } + + rc = qspi_send_cmd(dev, &cmd, false); + if (rc < 0) { + return rc; } if (t_exit_dpd) { From 3ae035a26abc2d5fe064e12c18c2496f4f51ff00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Mon, 6 Nov 2023 14:31:56 +0100 Subject: [PATCH 0950/1623] [nrf fromtree] drivers: nrf_qspi_nor: Clean up handling of return values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consistently use `res` for results of calls to nrfx functions and `rc` for Zephyr return codes, to avoid mixing up those two and for example calling `qspi_get_zephyr_ret_code()` for a value that is already a Zephyr return code. Correct also such call in `qspi_nor_write()`. Signed-off-by: Andrzej Głąbek (cherry picked from commit 4a4558128848b3cc01a153ab128fb6aa09316a99) (cherry picked from commit 72a0fceed9941275c0c5b666363360a99f293d1e) Signed-off-by: Dominik Ermel --- drivers/flash/nrf_qspi_nor.c | 248 ++++++++++++++++++----------------- 1 file changed, 125 insertions(+), 123 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index 467d0643d48..ca4673e8aa2 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -371,7 +371,7 @@ static int qspi_device_init(const struct device *dev) return pm_device_runtime_get(dev); #else nrfx_err_t res; - int ret = 0; + int rc = 0; qspi_lock(dev); @@ -389,13 +389,13 @@ static int qspi_device_init(const struct device *dev) res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); - ret = qspi_get_zephyr_ret_code(res); - qspi_initialized = (ret == 0); + rc = qspi_get_zephyr_ret_code(res); + qspi_initialized = (rc == 0); } qspi_unlock(dev); - return ret; + return rc; #endif } @@ -408,10 +408,10 @@ static void qspi_device_uninit(const struct device *dev) } #ifdef CONFIG_PM_DEVICE_RUNTIME - int ret = pm_device_runtime_put(dev); + int rc = pm_device_runtime_put(dev); - if (ret < 0) { - LOG_ERR("Failed to schedule device sleep: %d", ret); + if (rc < 0) { + LOG_ERR("Failed to schedule device sleep: %d", rc); } #else bool last = true; @@ -526,27 +526,27 @@ static int qspi_rdsr(const struct device *dev, uint8_t sr_num) .op_code = opcode, .rx_buf = &sr_buf, }; - int ret = qspi_send_cmd(dev, &cmd, false); + int rc = qspi_send_cmd(dev, &cmd, false); - return (ret < 0) ? ret : sr; + return (rc < 0) ? rc : sr; } /* Wait until RDSR confirms write is not in progress. */ static int qspi_wait_while_writing(const struct device *dev) { - int ret; + int rc; do { - ret = qspi_rdsr(dev, 1); - } while ((ret >= 0) - && ((ret & SPI_NOR_WIP_BIT) != 0U)); + rc = qspi_rdsr(dev, 1); + } while ((rc >= 0) + && ((rc & SPI_NOR_WIP_BIT) != 0U)); - return (ret < 0) ? ret : 0; + return (rc < 0) ? rc : 0; } static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) { - int ret = 0; + int rc = 0; uint8_t opcode = SPI_NOR_CMD_WRSR; uint8_t length = 1; uint8_t sr_array[2] = {0}; @@ -559,12 +559,12 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) sr_array[0] = sr_val; #if SR1_WRITE_CLEARS_SR2 /* Writing sr1 clears sr2. need to read/modify/write both. */ - ret = qspi_rdsr(dev, 2); - if (ret < 0) { - LOG_ERR("RDSR for WRSR failed: %d", ret); - return ret; + rc = qspi_rdsr(dev, 2); + if (rc < 0) { + LOG_ERR("RDSR for WRSR failed: %d", rc); + return rc; } - sr_array[1] = ret; + sr_array[1] = rc; length = 2; #endif } else { /* sr_num == 2 */ @@ -574,12 +574,12 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) * Uses standard WRSR opcode */ sr_array[1] = sr_val; - ret = qspi_rdsr(dev, 1); - if (ret < 0) { - LOG_ERR("RDSR for WRSR failed: %d", ret); - return ret; + rc = qspi_rdsr(dev, 1); + if (rc < 0) { + LOG_ERR("RDSR for WRSR failed: %d", rc); + return rc; } - sr_array[0] = ret; + sr_array[0] = rc; length = 2; #elif IS_EQUAL(INST_0_QER, JESD216_DW15_QER_VAL_S2B1v6) /* Writing sr2 uses a dedicated WRSR2 command */ @@ -600,17 +600,17 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) .tx_buf = &sr_buf, }; - ret = qspi_send_cmd(dev, &cmd, true); + rc = qspi_send_cmd(dev, &cmd, true); /* Writing SR can take some time, and further * commands sent while it's happening can be * corrupted. Wait. */ - if (ret == 0) { - ret = qspi_wait_while_writing(dev); + if (rc == 0) { + rc = qspi_wait_while_writing(dev); } - return ret; + return rc; } #endif /* !IS_EQUAL(INST_0_QER, JESD216_DW15_QER_VAL_NONE) */ @@ -627,16 +627,16 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) return -EINVAL; } - int rv = 0; const struct qspi_nor_config *params = dev->config; + int rc, rc2; - rv = qspi_device_init(dev); - if (rv != 0) { + rc = qspi_device_init(dev); + if (rc != 0) { goto out; } qspi_trans_lock(dev); - rv = qspi_nor_write_protection_set(dev, false); - if (rv != 0) { + rc = qspi_nor_write_protection_set(dev, false); + if (rc != 0) { goto out_trans_unlock; } qspi_lock(dev); @@ -670,16 +670,16 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) size -= adj; } else { LOG_ERR("erase error at 0x%lx size %zu", (long)addr, size); - rv = qspi_get_zephyr_ret_code(res); + rc = qspi_get_zephyr_ret_code(res); break; } } qspi_unlock(dev); - int rv2 = qspi_nor_write_protection_set(dev, true); + rc2 = qspi_nor_write_protection_set(dev, true); - if (!rv) { - rv = rv2; + if (!rc) { + rc = rc2; } out_trans_unlock: @@ -687,7 +687,7 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) out: qspi_device_uninit(dev); - return rv; + return rc; } /* Configures QSPI memory for the transfer */ @@ -695,6 +695,8 @@ static int qspi_nrfx_configure(const struct device *dev) { struct qspi_nor_data *dev_data = dev->data; const struct qspi_nor_config *dev_config = dev->config; + nrfx_err_t res; + int rc; #if defined(CONFIG_SOC_SERIES_NRF53X) /* When the QSPI peripheral is activated, during the nrfx_qspi driver @@ -705,18 +707,16 @@ static int qspi_nrfx_configure(const struct device *dev) nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); #endif - nrfx_err_t res = nrfx_qspi_init(&dev_config->nrfx_cfg, - qspi_handler, - dev_data); + res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); #if defined(CONFIG_SOC_SERIES_NRF53X) /* Restore the default /4 divider after the QSPI initialization. */ nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); #endif - int ret = qspi_get_zephyr_ret_code(res); - if (ret < 0) { - return ret; + rc = qspi_get_zephyr_ret_code(res); + if (rc < 0) { + return rc; } #if DT_INST_NODE_HAS_PROP(0, rx_delay) @@ -736,9 +736,9 @@ static int qspi_nrfx_configure(const struct device *dev) * bootloader) might have set DPD mode before reboot. As a result, * attempt to exit DPD mode regardless of whether CONFIG_PM_DEVICE is set. */ - ret = exit_dpd(dev); - if (ret < 0) { - return ret; + rc = exit_dpd(dev); + if (rc < 0) { + return rc; } /* Set QE to match transfer mode. If not using quad @@ -769,28 +769,28 @@ static int qspi_nrfx_configure(const struct device *dev) return -EINVAL; #endif - ret = qspi_rdsr(dev, sr_num); - if (ret < 0) { - LOG_ERR("RDSR failed: %d", ret); - return ret; + rc = qspi_rdsr(dev, sr_num); + if (rc < 0) { + LOG_ERR("RDSR failed: %d", rc); + return rc; } - uint8_t sr = (uint8_t)ret; + uint8_t sr = (uint8_t)rc; bool qe_state = ((sr & qe_mask) != 0U); LOG_DBG("RDSR %02x QE %d need %d: %s", sr, qe_state, qe_value, (qe_state != qe_value) ? "updating" : "no-change"); - ret = 0; + rc = 0; if (qe_state != qe_value) { sr ^= qe_mask; - ret = qspi_wrsr(dev, sr, sr_num); + rc = qspi_wrsr(dev, sr, sr_num); } - if (ret < 0) { + if (rc < 0) { LOG_ERR("QE %s failed: %d", qe_value ? "set" : "clear", - ret); - return ret; + rc); + return rc; } #endif @@ -802,16 +802,16 @@ static int qspi_nrfx_configure(const struct device *dev) /* Call will send write enable before instruction if that * requirement is encoded in INST_0_4BA. */ - ret = qspi_send_cmd(dev, &cmd, (INST_0_4BA & 0x02)); + rc = qspi_send_cmd(dev, &cmd, (INST_0_4BA & 0x02)); - if (ret < 0) { - LOG_ERR("E4BA cmd issue failed: %d.", ret); + if (rc < 0) { + LOG_ERR("E4BA cmd issue failed: %d.", rc); } else { LOG_DBG("E4BA cmd issued."); } } - return ret; + return rc; } static int qspi_read_jedec_id(const struct device *dev, @@ -826,14 +826,14 @@ static int qspi_read_jedec_id(const struct device *dev, .rx_buf = &rx_buf, }; - int ret = qspi_device_init(dev); + int rc = qspi_device_init(dev); - if (ret == 0) { - ret = qspi_send_cmd(dev, &cmd, false); + if (rc == 0) { + rc = qspi_send_cmd(dev, &cmd, false); } qspi_device_uninit(dev); - return ret; + return rc; } #if defined(CONFIG_FLASH_JESD216_API) @@ -856,13 +856,13 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, .io3_level = true, }; - int ret = qspi_device_init(dev); + int rc = qspi_device_init(dev); nrfx_err_t res = NRFX_SUCCESS; - if (ret != 0) { - LOG_DBG("qspi_device_init: %d", ret); + if (rc != 0) { + LOG_DBG("qspi_device_init: %d", rc); qspi_device_uninit(dev); - return ret; + return rc; } qspi_lock(dev); @@ -901,9 +901,9 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, static inline int qspi_nor_read_id(const struct device *dev) { uint8_t id[SPI_NOR_MAX_ID_LEN]; - int ret = qspi_read_jedec_id(dev, id); + int rc = qspi_read_jedec_id(dev, id); - if (ret != 0) { + if (rc != 0) { return -EIO; } @@ -1109,6 +1109,7 @@ static int qspi_nor_write(const struct device *dev, off_t addr, } const struct qspi_nor_config *params = dev->config; + int rc, rc2; /* affected region should be within device */ if (addr < 0 || @@ -1119,18 +1120,18 @@ static int qspi_nor_write(const struct device *dev, off_t addr, return -EINVAL; } - nrfx_err_t res = NRFX_SUCCESS; - - int rc = qspi_device_init(dev); + rc = qspi_device_init(dev); if (rc != 0) { goto out; } qspi_trans_lock(dev); - res = qspi_nor_write_protection_set(dev, false); + rc = qspi_nor_write_protection_set(dev, false); qspi_lock(dev); - if (!res) { + if (rc == 0) { + nrfx_err_t res; + if (size < 4U) { res = write_sub_word(dev, addr, src, size); } else if (!nrfx_is_in_ram(src) || @@ -1140,17 +1141,18 @@ static int qspi_nor_write(const struct device *dev, off_t addr, res = nrfx_qspi_write(src, size, addr); qspi_wait_for_completion(dev, res); } + + rc = qspi_get_zephyr_ret_code(res); } qspi_unlock(dev); - int res2 = qspi_nor_write_protection_set(dev, true); + rc2 = qspi_nor_write_protection_set(dev, true); qspi_trans_unlock(dev); - if (!res) { - res = res2; + if (rc == 0) { + rc = rc2; } - rc = qspi_get_zephyr_ret_code(res); out: qspi_device_uninit(dev); return rc; @@ -1169,24 +1171,24 @@ static int qspi_nor_erase(const struct device *dev, off_t addr, size_t size) return -EINVAL; } - int ret = qspi_erase(dev, addr, size); + int rc = qspi_erase(dev, addr, size); - return ret; + return rc; } static int qspi_nor_write_protection_set(const struct device *dev, bool write_protect) { - int ret = 0; + int rc = 0; struct qspi_cmd cmd = { .op_code = ((write_protect) ? SPI_NOR_CMD_WRDI : SPI_NOR_CMD_WREN), }; if (qspi_send_cmd(dev, &cmd, false) != 0) { - ret = -EIO; + rc = -EIO; } - return ret; + return rc; } /** @@ -1198,16 +1200,16 @@ static int qspi_nor_write_protection_set(const struct device *dev, */ static int qspi_nor_configure(const struct device *dev) { - int ret = qspi_nrfx_configure(dev); + int rc = qspi_nrfx_configure(dev); - if (ret != 0) { - return ret; + if (rc != 0) { + return rc; } #ifdef CONFIG_PM_DEVICE_RUNTIME - ret = pm_device_runtime_enable(dev); - if (ret < 0) { - LOG_ERR("Failed to enable runtime power management: %d", ret); + rc = pm_device_runtime_enable(dev); + if (rc < 0) { + LOG_ERR("Failed to enable runtime power management: %d", rc); } else { LOG_DBG("Runtime power management enabled"); } @@ -1231,12 +1233,12 @@ static int qspi_nor_configure(const struct device *dev) */ static int qspi_nor_init(const struct device *dev) { - int rc; const struct qspi_nor_config *dev_config = dev->config; - int ret = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); + int rc; - if (ret < 0) { - return ret; + rc = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); + if (rc < 0) { + return rc; } IRQ_CONNECT(DT_IRQN(QSPI_NODE), DT_IRQ(QSPI_NODE, priority), @@ -1317,11 +1319,11 @@ static int enter_dpd(const struct device *const dev) .op_code = SPI_NOR_CMD_DPD, }; uint32_t t_enter_dpd = DT_INST_PROP_OR(0, t_enter_dpd, 0); - int ret; + int rc; - ret = qspi_send_cmd(dev, &cmd, false); - if (ret < 0) { - return ret; + rc = qspi_send_cmd(dev, &cmd, false); + if (rc < 0) { + return rc; } if (t_enter_dpd) { @@ -1386,8 +1388,8 @@ static int qspi_nor_pm_action(const struct device *dev, { struct qspi_nor_data *dev_data = dev->data; const struct qspi_nor_config *dev_config = dev->config; - int ret; - nrfx_err_t err; + int rc; + nrfx_err_t res; if (pm_device_is_busy(dev)) { return -EBUSY; @@ -1397,9 +1399,9 @@ static int qspi_nor_pm_action(const struct device *dev, case PM_DEVICE_ACTION_SUSPEND: #ifndef CONFIG_PM_DEVICE_RUNTIME /* If PM_DEVICE_RUNTIME, we don't uninit after RESUME */ - ret = qspi_device_init(dev); - if (ret < 0) { - return ret; + rc = qspi_device_init(dev); + if (rc < 0) { + return rc; } #endif @@ -1411,35 +1413,35 @@ static int qspi_nor_pm_action(const struct device *dev, return -EBUSY; } - ret = enter_dpd(dev); - if (ret < 0) { - return ret; + rc = enter_dpd(dev); + if (rc < 0) { + return rc; } nrfx_qspi_uninit(); - ret = pinctrl_apply_state(dev_config->pcfg, + rc = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP); - if (ret < 0) { - return ret; + if (rc < 0) { + return rc; } break; case PM_DEVICE_ACTION_RESUME: - ret = pinctrl_apply_state(dev_config->pcfg, + rc = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); - if (ret < 0) { - return ret; + if (rc < 0) { + return rc; } - err = nrfx_qspi_init(&dev_config->nrfx_cfg, + res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); - if (err != NRFX_SUCCESS) { + if (res != NRFX_SUCCESS) { return -EIO; } - ret = exit_dpd(dev); - if (ret < 0) { - return ret; + rc = exit_dpd(dev); + if (rc < 0) { + return rc; } #ifndef CONFIG_PM_DEVICE_RUNTIME @@ -1459,16 +1461,16 @@ static int qspi_nor_pm_action(const struct device *dev, void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable) { struct qspi_nor_data *dev_data = dev->data; - int ret; + int rc; if (dev_data->xip_enabled == enable) { return; } - ret = qspi_device_init(dev); + rc = qspi_device_init(dev); - if (ret != 0) { - LOG_ERR("NRF QSPI NOR XIP %s failed with %d\n", enable ? "enable" : "disable", ret); + if (rc != 0) { + LOG_ERR("NRF QSPI NOR XIP %s failed with %d\n", enable ? "enable" : "disable", rc); return; } From 24e7218a2b0831b0f2d162d858d2556ff661d012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Mon, 6 Nov 2023 14:10:19 +0100 Subject: [PATCH 0951/1623] [nrf fromtree] drivers: nrf_qspi_nor: Refactor deactivation and locking access to QSPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After integration of nrfx 3.2.0, it is no longer needed to deinitialize the nrfx_qspi driver to avoid increased power consumption when the QSPI peripheral is idle. Now it is enough to call `nrfx_qspi_dectivate()` when a given operation is done. The driver will automatically activate the QSPI peripheral again when a next operation is requested. This commit applies the following changes: - `qspi_device_init` and `qspi_device_uninit` functions are replaced by `qspi_acquire` and `qspi_release`, respectively; those handle exclusive access to the QSPI peripheral and deactivation of it or runtime device power management - locking is removed from `qspi_send_cmd` as it is the resposibility of the caller of that function - `trans_lock` and `trans_unlock` functions are removed together with the related semaphore as they are no longer needed - checking of input parameters is moved from `qspi_erase` to its caller, `qspi_nor_erase` - `qspi_nor_pm_action` is refactored to properly handle locking of the QSPI peripheral; checking of the `xip_enabled` flag is removed from that function as now the call to `pm_device_is_busy()` covers that (when XIP is enabled, the device is kept indicated as busy) Signed-off-by: Andrzej Głąbek (cherry picked from commit 8c3df0aa9e9a8e7fe864b07ece840610009b3069) (cherry picked from commit 9a0aca0df38a10f19296c26fe6df9bc5b5b52c29) Signed-off-by: Dominik Ermel --- drivers/flash/nrf_qspi_nor.c | 507 +++++++++++++---------------------- 1 file changed, 193 insertions(+), 314 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index ca4673e8aa2..aa6449763be 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -26,15 +26,15 @@ LOG_MODULE_REGISTER(qspi_nor, CONFIG_FLASH_LOG_LEVEL); #include struct qspi_nor_data { +#if !defined(CONFIG_PM_DEVICE_RUNTIME) && defined(CONFIG_MULTITHREADING) + /* A semaphore to control QSPI deactivation. */ + struct k_sem count; +#endif #ifdef CONFIG_MULTITHREADING - /* The semaphore to control exclusive access on write/erase. */ - struct k_sem trans; /* The semaphore to control exclusive access to the device. */ struct k_sem sem; /* The semaphore to indicate that transfer has completed. */ struct k_sem sync; - /* The semaphore to control driver init/uninit. */ - struct k_sem count; #else /* CONFIG_MULTITHREADING */ /* A flag that signals completed transfer when threads are * not enabled. @@ -173,12 +173,6 @@ BUILD_ASSERT(DT_INST_PROP(0, address_size_32), "After entering 4 byte addressing mode, 4 byte addressing is expected"); #endif -#ifndef CONFIG_PM_DEVICE_RUNTIME -static bool qspi_initialized; -#endif - -static int qspi_device_init(const struct device *dev); -static void qspi_device_uninit(const struct device *dev); void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable); void z_vrfy_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable); @@ -245,72 +239,99 @@ static inline int qspi_get_zephyr_ret_code(nrfx_err_t res) static inline void qspi_lock(const struct device *dev) { +#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; - pm_device_busy_set(dev); - -#ifdef CONFIG_MULTITHREADING k_sem_take(&dev_data->sem, K_FOREVER); -#else /* CONFIG_MULTITHREADING */ - ARG_UNUSED(dev_data); -#endif /* CONFIG_MULTITHREADING */ - - /* - * Change the base clock divider only for the time the driver is locked - * to perform a QSPI operation, otherwise the power consumption would be - * increased also when the QSPI peripheral is idle. - * When XIP is enabled, there is nothing to do here as the changed - * divider is kept all the time. - */ -#if defined(CONFIG_SOC_SERIES_NRF53X) - if (!dev_data->xip_enabled) { - nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); - } #endif } static inline void qspi_unlock(const struct device *dev) { +#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; -#if defined(CONFIG_SOC_SERIES_NRF53X) - /* Restore the default base clock divider to reduce power consumption. - * Unless XIP is enabled, then the changed divider needs to be kept. - */ - if (!dev_data->xip_enabled) { - nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); - } + k_sem_give(&dev_data->sem); #endif +} -#ifdef CONFIG_MULTITHREADING - k_sem_give(&dev_data->sem); -#else - ARG_UNUSED(dev_data); +static inline void qspi_clock_div_change(void) +{ +#ifdef CONFIG_SOC_SERIES_NRF53X + /* Make sure the base clock divider is changed accordingly + * before a QSPI transfer is performed. + */ + nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); #endif +} - pm_device_busy_clear(dev); +static inline void qspi_clock_div_restore(void) +{ +#ifdef CONFIG_SOC_SERIES_NRF53X + /* Restore the default base clock divider to reduce power + * consumption when the QSPI peripheral is idle. + */ + nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); +#endif } -static inline void qspi_trans_lock(const struct device *dev) +static void qspi_acquire(const struct device *dev) { -#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; - k_sem_take(&dev_data->trans, K_FOREVER); -#else /* CONFIG_MULTITHREADING */ - ARG_UNUSED(dev); -#endif /* CONFIG_MULTITHREADING */ +#if defined(CONFIG_PM_DEVICE_RUNTIME) + int rc = pm_device_runtime_get(dev); + + if (rc < 0) { + LOG_ERR("pm_device_runtime_get failed: %d", rc); + } +#elif defined(CONFIG_MULTITHREADING) + /* In multithreading, the driver can call qspi_acquire more than once + * before calling qspi_release. Keeping count, so QSPI is deactivated + * only at the last call (count == 0). + */ + k_sem_give(&dev_data->count); +#endif + + qspi_lock(dev); + + if (!dev_data->xip_enabled) { + qspi_clock_div_change(); + + pm_device_busy_set(dev); + } } -static inline void qspi_trans_unlock(const struct device *dev) +static void qspi_release(const struct device *dev) { -#ifdef CONFIG_MULTITHREADING struct qspi_nor_data *dev_data = dev->data; + bool deactivate = true; - k_sem_give(&dev_data->trans); -#else /* CONFIG_MULTITHREADING */ - ARG_UNUSED(dev); -#endif /* CONFIG_MULTITHREADING */ +#if !defined(CONFIG_PM_DEVICE_RUNTIME) && defined(CONFIG_MULTITHREADING) + /* The last thread to finish using the driver deactivates the QSPI */ + (void) k_sem_take(&dev_data->count, K_NO_WAIT); + deactivate = (k_sem_count_get(&dev_data->count) == 0); +#endif + + if (!dev_data->xip_enabled) { + qspi_clock_div_restore(); + + if (deactivate && !IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + (void) nrfx_qspi_deactivate(); + } + + pm_device_busy_clear(dev); + } + + qspi_unlock(dev); + +#if defined(CONFIG_PM_DEVICE_RUNTIME) + int rc = pm_device_runtime_put(dev); + + if (rc < 0) { + LOG_ERR("pm_device_runtime_put failed: %d", rc); + } +#endif } static inline void qspi_wait_for_completion(const struct device *dev, @@ -359,89 +380,6 @@ static void qspi_handler(nrfx_qspi_evt_t event, void *p_context) } } -static int qspi_device_init(const struct device *dev) -{ - struct qspi_nor_data *dev_data = dev->data; - - if (dev_data->xip_enabled) { - return 0; - } - -#ifdef CONFIG_PM_DEVICE_RUNTIME - return pm_device_runtime_get(dev); -#else - nrfx_err_t res; - int rc = 0; - - qspi_lock(dev); - - /* In multithreading, driver can call qspi_device_init more than once - * before calling qspi_device_uninit. Keepping count, so QSPI is - * uninitialized only at the last call (count == 0). - */ -#ifdef CONFIG_MULTITHREADING - k_sem_give(&dev_data->count); -#endif - - if (!qspi_initialized) { - const struct qspi_nor_config *dev_config = dev->config; - - res = nrfx_qspi_init(&dev_config->nrfx_cfg, - qspi_handler, - dev_data); - rc = qspi_get_zephyr_ret_code(res); - qspi_initialized = (rc == 0); - } - - qspi_unlock(dev); - - return rc; -#endif -} - -static void qspi_device_uninit(const struct device *dev) -{ - struct qspi_nor_data *dev_data = dev->data; - - if (dev_data->xip_enabled) { - return; - } - -#ifdef CONFIG_PM_DEVICE_RUNTIME - int rc = pm_device_runtime_put(dev); - - if (rc < 0) { - LOG_ERR("Failed to schedule device sleep: %d", rc); - } -#else - bool last = true; - - qspi_lock(dev); - -#ifdef CONFIG_MULTITHREADING - /* The last thread to finish using the driver uninit the QSPI */ - (void) k_sem_take(&dev_data->count, K_NO_WAIT); - last = (k_sem_count_get(&dev_data->count) == 0); -#endif - - if (last) { - while (nrfx_qspi_mem_busy_check() != NRFX_SUCCESS) { - if (IS_ENABLED(CONFIG_MULTITHREADING)) { - k_msleep(50); - } else { - k_busy_wait(50000); - } - } - - nrfx_qspi_uninit(); - - qspi_initialized = false; - } - - qspi_unlock(dev); -#endif -} - /* QSPI send custom command. * * If this is used for both send and receive the buffer sizes must be @@ -497,11 +435,8 @@ static int qspi_send_cmd(const struct device *dev, const struct qspi_cmd *cmd, .wren = wren, }; - qspi_lock(dev); - int res = nrfx_qspi_cinstr_xfer(&cinstr_cfg, tx_buf, rx_buf); - qspi_unlock(dev); return qspi_get_zephyr_ret_code(res); } @@ -617,29 +552,13 @@ static int qspi_wrsr(const struct device *dev, uint8_t sr_val, uint8_t sr_num) /* QSPI erase */ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) { - /* address must be sector-aligned */ - if ((addr % QSPI_SECTOR_SIZE) != 0) { - return -EINVAL; - } - - /* size must be a non-zero multiple of sectors */ - if ((size == 0) || (size % QSPI_SECTOR_SIZE) != 0) { - return -EINVAL; - } - const struct qspi_nor_config *params = dev->config; int rc, rc2; - rc = qspi_device_init(dev); - if (rc != 0) { - goto out; - } - qspi_trans_lock(dev); rc = qspi_nor_write_protection_set(dev, false); if (rc != 0) { - goto out_trans_unlock; + return rc; } - qspi_lock(dev); while (size > 0) { nrfx_err_t res = !NRFX_SUCCESS; uint32_t adj = 0; @@ -674,20 +593,10 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) break; } } - qspi_unlock(dev); rc2 = qspi_nor_write_protection_set(dev, true); - if (!rc) { - rc = rc2; - } - -out_trans_unlock: - qspi_trans_unlock(dev); - -out: - qspi_device_uninit(dev); - return rc; + return rc != 0 ? rc : rc2; } /* Configures QSPI memory for the transfer */ @@ -698,22 +607,7 @@ static int qspi_nrfx_configure(const struct device *dev) nrfx_err_t res; int rc; -#if defined(CONFIG_SOC_SERIES_NRF53X) - /* When the QSPI peripheral is activated, during the nrfx_qspi driver - * initialization, it reads the status of the connected flash chip. - * Make sure this transaction is performed with a valid base clock - * divider. - */ - nrf_clock_hfclk192m_div_set(NRF_CLOCK, BASE_CLOCK_DIV); -#endif - res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); - -#if defined(CONFIG_SOC_SERIES_NRF53X) - /* Restore the default /4 divider after the QSPI initialization. */ - nrf_clock_hfclk192m_div_set(NRF_CLOCK, NRF_CLOCK_HFCLK_DIV_4); -#endif - rc = qspi_get_zephyr_ret_code(res); if (rc < 0) { return rc; @@ -814,8 +708,7 @@ static int qspi_nrfx_configure(const struct device *dev) return rc; } -static int qspi_read_jedec_id(const struct device *dev, - uint8_t *id) +static int qspi_rdid(const struct device *dev, uint8_t *id) { const struct qspi_buf rx_buf = { .buf = id, @@ -826,18 +719,24 @@ static int qspi_read_jedec_id(const struct device *dev, .rx_buf = &rx_buf, }; - int rc = qspi_device_init(dev); + return qspi_send_cmd(dev, &cmd, false); +} - if (rc == 0) { - rc = qspi_send_cmd(dev, &cmd, false); - } - qspi_device_uninit(dev); +#if defined(CONFIG_FLASH_JESD216_API) + +static int qspi_read_jedec_id(const struct device *dev, uint8_t *id) +{ + int rc; + + qspi_acquire(dev); + + rc = qspi_rdid(dev, id); + + qspi_release(dev); return rc; } -#if defined(CONFIG_FLASH_JESD216_API) - static int qspi_sfdp_read(const struct device *dev, off_t offset, void *data, size_t len) { @@ -855,17 +754,10 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, .io2_level = true, .io3_level = true, }; + nrfx_err_t res; - int rc = qspi_device_init(dev); - nrfx_err_t res = NRFX_SUCCESS; - - if (rc != 0) { - LOG_DBG("qspi_device_init: %d", rc); - qspi_device_uninit(dev); - return rc; - } + qspi_acquire(dev); - qspi_lock(dev); res = nrfx_qspi_lfm_start(&cinstr_cfg); if (res != NRFX_SUCCESS) { LOG_DBG("lfm_start: %x", res); @@ -885,8 +777,8 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, } out: - qspi_unlock(dev); - qspi_device_uninit(dev); + qspi_release(dev); + return qspi_get_zephyr_ret_code(res); } @@ -901,7 +793,7 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, static inline int qspi_nor_read_id(const struct device *dev) { uint8_t id[SPI_NOR_MAX_ID_LEN]; - int rc = qspi_read_jedec_id(dev, id); + int rc = qspi_rdid(dev, id); if (rc != 0) { return -EIO; @@ -993,6 +885,9 @@ static inline nrfx_err_t read_non_aligned(const struct device *dev, static int qspi_nor_read(const struct device *dev, off_t addr, void *dest, size_t size) { + const struct qspi_nor_config *params = dev->config; + nrfx_err_t res; + if (!dest) { return -EINVAL; } @@ -1002,8 +897,6 @@ static int qspi_nor_read(const struct device *dev, off_t addr, void *dest, return 0; } - const struct qspi_nor_config *params = dev->config; - /* affected region should be within device */ if (addr < 0 || (addr + size) > params->size) { @@ -1013,23 +906,13 @@ static int qspi_nor_read(const struct device *dev, off_t addr, void *dest, return -EINVAL; } - int rc = qspi_device_init(dev); - - if (rc != 0) { - goto out; - } - - qspi_lock(dev); - - nrfx_err_t res = read_non_aligned(dev, addr, dest, size); + qspi_acquire(dev); - qspi_unlock(dev); + res = read_non_aligned(dev, addr, dest, size); - rc = qspi_get_zephyr_ret_code(res); + qspi_release(dev); -out: - qspi_device_uninit(dev); - return rc; + return qspi_get_zephyr_ret_code(res); } /* addr aligned, sptr not null, slen less than 4 */ @@ -1094,6 +977,9 @@ static int qspi_nor_write(const struct device *dev, off_t addr, const void *src, size_t size) { + const struct qspi_nor_config *params = dev->config; + int rc, rc2; + if (!src) { return -EINVAL; } @@ -1108,9 +994,6 @@ static int qspi_nor_write(const struct device *dev, off_t addr, return -EINVAL; } - const struct qspi_nor_config *params = dev->config; - int rc, rc2; - /* affected region should be within device */ if (addr < 0 || (addr + size) > params->size) { @@ -1120,15 +1003,9 @@ static int qspi_nor_write(const struct device *dev, off_t addr, return -EINVAL; } + qspi_acquire(dev); - rc = qspi_device_init(dev); - if (rc != 0) { - goto out; - } - - qspi_trans_lock(dev); rc = qspi_nor_write_protection_set(dev, false); - qspi_lock(dev); if (rc == 0) { nrfx_err_t res; @@ -1144,23 +1021,28 @@ static int qspi_nor_write(const struct device *dev, off_t addr, rc = qspi_get_zephyr_ret_code(res); } - qspi_unlock(dev); rc2 = qspi_nor_write_protection_set(dev, true); - qspi_trans_unlock(dev); - if (rc == 0) { - rc = rc2; - } + qspi_release(dev); -out: - qspi_device_uninit(dev); - return rc; + return rc != 0 ? rc : rc2; } static int qspi_nor_erase(const struct device *dev, off_t addr, size_t size) { const struct qspi_nor_config *params = dev->config; + int rc; + + /* address must be sector-aligned */ + if ((addr % QSPI_SECTOR_SIZE) != 0) { + return -EINVAL; + } + + /* size must be a non-zero multiple of sectors */ + if ((size == 0) || (size % QSPI_SECTOR_SIZE) != 0) { + return -EINVAL; + } /* affected region should be within device */ if (addr < 0 || @@ -1171,7 +1053,11 @@ static int qspi_nor_erase(const struct device *dev, off_t addr, size_t size) return -EINVAL; } - int rc = qspi_erase(dev, addr, size); + qspi_acquire(dev); + + rc = qspi_erase(dev, addr, size); + + qspi_release(dev); return rc; } @@ -1206,17 +1092,6 @@ static int qspi_nor_configure(const struct device *dev) return rc; } -#ifdef CONFIG_PM_DEVICE_RUNTIME - rc = pm_device_runtime_enable(dev); - if (rc < 0) { - LOG_ERR("Failed to enable runtime power management: %d", rc); - } else { - LOG_DBG("Runtime power management enabled"); - } -#else - qspi_device_uninit(dev); -#endif - /* now the spi bus is configured, we can verify the flash id */ if (qspi_nor_read_id(dev) != 0) { return -ENODEV; @@ -1244,10 +1119,24 @@ static int qspi_nor_init(const struct device *dev) IRQ_CONNECT(DT_IRQN(QSPI_NODE), DT_IRQ(QSPI_NODE, priority), nrfx_isr, nrfx_qspi_irq_handler, 0); + qspi_clock_div_change(); + rc = qspi_nor_configure(dev); + qspi_clock_div_restore(); + +#ifdef CONFIG_PM_DEVICE_RUNTIME + int rc2 = pm_device_runtime_enable(dev); + + if (rc2 < 0) { + LOG_ERR("Failed to enable runtime power management: %d", rc2); + } else { + LOG_DBG("Runtime power management enabled"); + } +#endif + #ifdef CONFIG_NORDIC_QSPI_NOR_XIP - if (!rc) { + if (rc == 0) { /* Enable XIP mode for QSPI NOR flash, this will prevent the * flash from being powered down */ @@ -1383,108 +1272,97 @@ static int exit_dpd(const struct device *const dev) } #ifdef CONFIG_PM_DEVICE -static int qspi_nor_pm_action(const struct device *dev, - enum pm_device_action action) +static int qspi_suspend(const struct device *dev) { - struct qspi_nor_data *dev_data = dev->data; const struct qspi_nor_config *dev_config = dev->config; - int rc; nrfx_err_t res; + int rc; - if (pm_device_is_busy(dev)) { + res = nrfx_qspi_mem_busy_check(); + if (res != NRFX_SUCCESS) { return -EBUSY; } - switch (action) { - case PM_DEVICE_ACTION_SUSPEND: -#ifndef CONFIG_PM_DEVICE_RUNTIME - /* If PM_DEVICE_RUNTIME, we don't uninit after RESUME */ - rc = qspi_device_init(dev); - if (rc < 0) { - return rc; - } -#endif + rc = enter_dpd(dev); + if (rc < 0) { + return rc; + } - if (dev_data->xip_enabled) { - return -EBUSY; - } + nrfx_qspi_uninit(); - if (nrfx_qspi_mem_busy_check() != NRFX_SUCCESS) { - return -EBUSY; - } + return pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP); +} - rc = enter_dpd(dev); - if (rc < 0) { - return rc; - } +static int qspi_resume(const struct device *dev) +{ + const struct qspi_nor_config *dev_config = dev->config; + nrfx_err_t res; + int rc; - nrfx_qspi_uninit(); - rc = pinctrl_apply_state(dev_config->pcfg, - PINCTRL_STATE_SLEEP); - if (rc < 0) { - return rc; - } - break; + rc = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); + if (rc < 0) { + return rc; + } - case PM_DEVICE_ACTION_RESUME: - rc = pinctrl_apply_state(dev_config->pcfg, - PINCTRL_STATE_DEFAULT); - if (rc < 0) { - return rc; - } - res = nrfx_qspi_init(&dev_config->nrfx_cfg, - qspi_handler, - dev_data); - if (res != NRFX_SUCCESS) { - return -EIO; - } + res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev->data); + if (res != NRFX_SUCCESS) { + return -EIO; + } - rc = exit_dpd(dev); - if (rc < 0) { - return rc; - } + return exit_dpd(dev); +} -#ifndef CONFIG_PM_DEVICE_RUNTIME - /* If PM_DEVICE_RUNTIME, we're immediately going to use the device */ - qspi_device_uninit(dev); -#endif +static int qspi_nor_pm_action(const struct device *dev, + enum pm_device_action action) +{ + int rc; + + if (pm_device_is_busy(dev)) { + return -EBUSY; + } + + qspi_lock(dev); + qspi_clock_div_change(); + + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + rc = qspi_suspend(dev); + break; + + case PM_DEVICE_ACTION_RESUME: + rc = qspi_resume(dev); break; default: - return -ENOTSUP; + rc = -ENOTSUP; } - return 0; + qspi_clock_div_restore(); + qspi_unlock(dev); + + return rc; } #endif /* CONFIG_PM_DEVICE */ void z_impl_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable) { struct qspi_nor_data *dev_data = dev->data; - int rc; if (dev_data->xip_enabled == enable) { return; } - rc = qspi_device_init(dev); - - if (rc != 0) { - LOG_ERR("NRF QSPI NOR XIP %s failed with %d\n", enable ? "enable" : "disable", rc); - return; - } + qspi_acquire(dev); #if NRF_QSPI_HAS_XIPEN nrf_qspi_xip_set(NRF_QSPI, enable); #endif - qspi_lock(dev); if (enable) { (void)nrfx_qspi_activate(false); } dev_data->xip_enabled = enable; - qspi_unlock(dev); - qspi_device_uninit(dev); + qspi_release(dev); } #ifdef CONFIG_USERSPACE @@ -1502,11 +1380,12 @@ void z_vrfy_nrf_qspi_nor_xip_enable(const struct device *dev, bool enable) #endif /* CONFIG_USERSPACE */ static struct qspi_nor_data qspi_nor_dev_data = { +#if !defined(CONFIG_PM_DEVICE_RUNTIME) && defined(CONFIG_MULTITHREADING) + .count = Z_SEM_INITIALIZER(qspi_nor_dev_data.count, 0, K_SEM_MAX_LIMIT), +#endif #ifdef CONFIG_MULTITHREADING - .trans = Z_SEM_INITIALIZER(qspi_nor_dev_data.trans, 1, 1), .sem = Z_SEM_INITIALIZER(qspi_nor_dev_data.sem, 1, 1), .sync = Z_SEM_INITIALIZER(qspi_nor_dev_data.sync, 0, 1), - .count = Z_SEM_INITIALIZER(qspi_nor_dev_data.count, 0, K_SEM_MAX_LIMIT), #endif /* CONFIG_MULTITHREADING */ }; From 05688141d94c0cb28ab1cb48a653d733a4133001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Fri, 10 Nov 2023 16:52:12 +0100 Subject: [PATCH 0952/1623] [nrf fromtree] drivers: nrf_qspi_nor: Fix and refactor driver initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So far the driver first changed the configuration of the flash chip and after that checked the signature of that chip. This could lead to improper change of the chip configuration if the actually found one was different than that specified in devicetree. This commit reverses the order of these two initialization steps and also restructures a bit the initialization code. Signed-off-by: Andrzej Głąbek (cherry picked from commit ea1be7f242b9348863a27adb17215014f15b318a) (cherry picked from commit 86146714949810fd451dace302bd42ea4ecb3927) Signed-off-by: Dominik Ermel --- drivers/flash/nrf_qspi_nor.c | 125 +++++++++++++---------------------- 1 file changed, 45 insertions(+), 80 deletions(-) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index aa6449763be..d6695989857 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -599,41 +599,10 @@ static int qspi_erase(const struct device *dev, uint32_t addr, uint32_t size) return rc != 0 ? rc : rc2; } -/* Configures QSPI memory for the transfer */ -static int qspi_nrfx_configure(const struct device *dev) +static int configure_chip(const struct device *dev) { - struct qspi_nor_data *dev_data = dev->data; const struct qspi_nor_config *dev_config = dev->config; - nrfx_err_t res; - int rc; - - res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev_data); - rc = qspi_get_zephyr_ret_code(res); - if (rc < 0) { - return rc; - } - -#if DT_INST_NODE_HAS_PROP(0, rx_delay) - if (!nrf53_errata_121()) { - nrf_qspi_iftiming_set(NRF_QSPI, DT_INST_PROP(0, rx_delay)); - } -#endif - - /* It may happen that after the flash chip was previously put into - * the DPD mode, the system was reset but the flash chip was not. - * Consequently, the flash chip can be in the DPD mode at this point. - * Some flash chips will just exit the DPD mode on the first CS pulse, - * but some need to receive the dedicated command to do it, so send it. - * This can be the case even if the current image does not have - * CONFIG_PM_DEVICE set to enter DPD mode, as a previously executing image - * (for example the main image if the currently executing image is the - * bootloader) might have set DPD mode before reboot. As a result, - * attempt to exit DPD mode regardless of whether CONFIG_PM_DEVICE is set. - */ - rc = exit_dpd(dev); - if (rc < 0) { - return rc; - } + int rc = 0; /* Set QE to match transfer mode. If not using quad * it's OK to leave QE set, but doing so prevents use @@ -784,33 +753,6 @@ static int qspi_sfdp_read(const struct device *dev, off_t offset, #endif /* CONFIG_FLASH_JESD216_API */ -/** - * @brief Retrieve the Flash JEDEC ID and compare it with the one expected - * - * @param dev The device structure - * @return 0 on success, negative errno code otherwise - */ -static inline int qspi_nor_read_id(const struct device *dev) -{ - uint8_t id[SPI_NOR_MAX_ID_LEN]; - int rc = qspi_rdid(dev, id); - - if (rc != 0) { - return -EIO; - } - - const struct qspi_nor_config *qnc = dev->config; - - if (memcmp(qnc->id, id, SPI_NOR_MAX_ID_LEN) != 0) { - LOG_ERR("JEDEC id [%02x %02x %02x] expect [%02x %02x %02x]", - id[0], id[1], id[2], - qnc->id[0], qnc->id[1], qnc->id[2]); - return -ENODEV; - } - - return 0; -} - static inline nrfx_err_t read_non_aligned(const struct device *dev, off_t addr, void *dest, size_t size) @@ -1077,35 +1019,58 @@ static int qspi_nor_write_protection_set(const struct device *dev, return rc; } -/** - * @brief Configure the flash - * - * @param dev The flash device structure - * @param info The flash info structure - * @return 0 on success, negative errno code otherwise - */ -static int qspi_nor_configure(const struct device *dev) +static int qspi_init(const struct device *dev) { - int rc = qspi_nrfx_configure(dev); + const struct qspi_nor_config *dev_config = dev->config; + uint8_t id[SPI_NOR_MAX_ID_LEN]; + nrfx_err_t res; + int rc; - if (rc != 0) { + res = nrfx_qspi_init(&dev_config->nrfx_cfg, qspi_handler, dev->data); + rc = qspi_get_zephyr_ret_code(res); + if (rc < 0) { + return rc; + } + +#if DT_INST_NODE_HAS_PROP(0, rx_delay) + if (!nrf53_errata_121()) { + nrf_qspi_iftiming_set(NRF_QSPI, DT_INST_PROP(0, rx_delay)); + } +#endif + + /* It may happen that after the flash chip was previously put into + * the DPD mode, the system was reset but the flash chip was not. + * Consequently, the flash chip can be in the DPD mode at this point. + * Some flash chips will just exit the DPD mode on the first CS pulse, + * but some need to receive the dedicated command to do it, so send it. + * This can be the case even if the current image does not have + * CONFIG_PM_DEVICE set to enter DPD mode, as a previously executing image + * (for example the main image if the currently executing image is the + * bootloader) might have set DPD mode before reboot. As a result, + * attempt to exit DPD mode regardless of whether CONFIG_PM_DEVICE is set. + */ + rc = exit_dpd(dev); + if (rc < 0) { + return rc; + } + + /* Retrieve the Flash JEDEC ID and compare it with the one expected. */ + rc = qspi_rdid(dev, id); + if (rc < 0) { return rc; } - /* now the spi bus is configured, we can verify the flash id */ - if (qspi_nor_read_id(dev) != 0) { + if (memcmp(dev_config->id, id, SPI_NOR_MAX_ID_LEN) != 0) { + LOG_ERR("JEDEC id [%02x %02x %02x] expect [%02x %02x %02x]", + id[0], id[1], id[2], dev_config->id[0], + dev_config->id[1], dev_config->id[2]); return -ENODEV; } - return 0; + /* The chip is correct, it can be configured now. */ + return configure_chip(dev); } -/** - * @brief Initialize and configure the flash - * - * @param name The flash name - * @return 0 on success, negative errno code otherwise - */ static int qspi_nor_init(const struct device *dev) { const struct qspi_nor_config *dev_config = dev->config; @@ -1121,7 +1086,7 @@ static int qspi_nor_init(const struct device *dev) qspi_clock_div_change(); - rc = qspi_nor_configure(dev); + rc = qspi_init(dev); qspi_clock_div_restore(); From 915ea12b7c706f7c9667aa85b2fb90b406d36e19 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 14 Dec 2023 21:13:44 +0530 Subject: [PATCH 0953/1623] [nrf fromtree] wifi: shell: Fix AP argument checks and help AP enable takes the same parameters as connect, so, update the help and also fix the optional parameter count when security is involved. Signed-off-by: Chaitanya Tata (cherry picked from commit 9736cc7f29668542a85b5c775b368a6a30c7f8c0) (cherry picked from commit 85a25485d25f7da05e0d6c707b326a487b3a9e6b) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index c5b8f60d933..e243a9de4e4 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1602,9 +1602,16 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, "Disable Access Point mode", cmd_wifi_ap_disable, 1, 0), - SHELL_CMD_ARG(enable, NULL, " [channel] [PSK]", + SHELL_CMD_ARG(enable, NULL, + "\"\"\n" + "[channel number: 0 means all]\n" + "[PSK: valid only for secure SSIDs]\n" + "[Security type: valid only for secure SSIDs]\n" + "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" + "[MFP (optional: needs security type to be specified)]\n" + ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_ap_enable, - 2, 1), + 2, 4), SHELL_SUBCMD_SET_END ); From 620bad8edd3f13a77595747002554fec3ff60ed2 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 14 Dec 2023 21:17:07 +0530 Subject: [PATCH 0954/1623] [nrf fromtree] wifi: shell: Display RSSI only for station mode RSSI makes sense only for modes that have a single peer, so, add a station mode check. Signed-off-by: Chaitanya Tata (cherry picked from commit eaba47445a4e9cd1bee7d6adb9b9c62f159f3088) (cherry picked from commit b65e77cdb79c3deb22395874d3079f850a6dffd0) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index e243a9de4e4..f1a98105204 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -660,7 +660,9 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[]) wifi_security_txt(status.security)); shell_fprintf(sh, SHELL_NORMAL, "MFP: %s\n", wifi_mfp_txt(status.mfp)); - shell_fprintf(sh, SHELL_NORMAL, "RSSI: %d\n", status.rssi); + if (status.iface_mode == WIFI_MODE_INFRA) { + shell_fprintf(sh, SHELL_NORMAL, "RSSI: %d\n", status.rssi); + } shell_fprintf(sh, SHELL_NORMAL, "Beacon Interval: %d\n", status.beacon_interval); shell_fprintf(sh, SHELL_NORMAL, "DTIM: %d\n", status.dtim_period); shell_fprintf(sh, SHELL_NORMAL, "TWT: %s\n", From 9fb63a841e1dc54b7ed3a28bff90aa8ce41ceb8c Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 18 Dec 2023 17:42:43 +0530 Subject: [PATCH 0955/1623] [nrf fromlist] wifi: shell: Fix arg count for regulatory domain Regulatory domain supports both get and set, so, fix the argument counts. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66616 Signed-off-by: Chaitanya Tata (cherry picked from commit 426213023e08965311421143ca3abe2ec25b39a4) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index f1a98105204..3aa674e73b7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1688,7 +1688,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain, - 2, 1), + 1, 1), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" From 277b6e66bc52f5bdf22a140c8db748054e93a38c Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 13:55:12 +0530 Subject: [PATCH 0956/1623] [nrf fromlist] wifi: shell: Fix the arg count for reg domain Missed accounting for "-f" option. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata (cherry picked from commit bf821e930748f94977af135540235b76dad32ee9) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 3aa674e73b7..c3100c9ad2c 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1688,7 +1688,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain, - 1, 1), + 1, 2), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" "parameters:" From ee07a2d47bae600063b0e048355a9d8a44243a3a Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 13:57:20 +0530 Subject: [PATCH 0957/1623] [nrf fromlist] wifi: shell: Fix optional arg count for connect Fix an extra optional arg. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata (cherry picked from commit 16d86216eb95cbc5e173db576ebee9c7d72d0569) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index c3100c9ad2c..dbec138fea0 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1653,7 +1653,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required", cmd_wifi_connect, - 2, 5), + 2, 4), SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", cmd_wifi_disconnect, 1, 0), From f076140f55d70269c733b633a9ca2dc5612500c5 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 13:59:52 +0530 Subject: [PATCH 0958/1623] [nrf fromlist] wifi: shell: Fix help for PS command Clearly mark the args as optional. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata (cherry picked from commit 0fc24a59c702c89f6fa04feb552d5bb1eee5e6df) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index dbec138fea0..6ef745670ab 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1657,7 +1657,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", cmd_wifi_disconnect, 1, 0), - SHELL_CMD_ARG(ps, NULL, "Configure Wi-F PS on/off, no arguments will dump config", + SHELL_CMD_ARG(ps, NULL, "Configure or display Wi-Fi power save state\n" + "[on/off]\n", cmd_wifi_ps, 1, 1), SHELL_CMD_ARG(ps_mode, From 6f6774acf02d236c1a67dd4783ad2d7c5fed3919 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 14:00:50 +0530 Subject: [PATCH 0959/1623] [nrf fromlist] wifi: shell: Remove the unnecessary text in scan We are using standard notation to differentiate optional and mandatory, so, no need for a heading. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata (cherry picked from commit e8a952b68db6cd8d097e169a56284bf0ff42c2a0) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 1 - 1 file changed, 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 6ef745670ab..d6d14c86bf1 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1669,7 +1669,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, 0), SHELL_CMD_ARG(scan, NULL, "Scan for Wi-Fi APs\n" - "OPTIONAL PARAMETERS:\n" "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active.\n" "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz.\n" "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms.\n" From b86194298032cf0ffc53d990b8d71e0a08aa6012 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 14:02:42 +0530 Subject: [PATCH 0960/1623] [nrf fromlist] wifi: shell: Fix the help for reg domain Separate the two optional parameters and add help. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata (cherry picked from commit 6be67b3199e68acff52e8d09d231d0f4d5afec4d) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index d6d14c86bf1..890bb8f121e 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1684,7 +1684,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows", NULL), SHELL_CMD_ARG(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" - "Usage: wifi reg_domain [ISO/IEC 3166-1 alpha2] [-f]\n" + "[ISO/IEC 3166-1 alpha2]: Regulatory domain\n" "[-f]: Force to use this regulatory hint over any other regulatory hints\n" "Note: This may cause regulatory compliance issues, use it at your own risk.", cmd_wifi_reg_domain, From fd36c75dc0124f043c8875aef3163e8b40a99ec9 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 14:07:36 +0530 Subject: [PATCH 0961/1623] [nrf fromlist] wifi: shell: Remove the unnecessary text The parameters heading is implied and doesn't have the newline, so, just remove it. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata (cherry picked from commit f9f9f83293267465b05927bc3756e1d22accab05) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 890bb8f121e..a983e5c18f5 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1691,7 +1691,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, 1, 2), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" - "parameters:" "[-i, --if-index ] : Interface index.\n" "[-s, --sta] : Station mode.\n" "[-m, --monitor] : Monitor mode.\n" @@ -1711,7 +1710,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "This command is used to set packet filter setting when\n" "monitor, TX-Injection and promiscuous mode is enabled.\n" "The different packet filter modes are control, management, data and enable all filters\n" - "parameters:" "[-i, --if-index ] : Interface index.\n" "[-a, --all] : Enable all packet filter modes\n" "[-m, --mgmt] : Enable management packets to allowed up the stack.\n" @@ -1730,7 +1728,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "This command is used to set the channel when\n" "monitor or TX-Injection mode is enabled.\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" - "parameters:" "[-i, --if-index ] : Interface index.\n" "[-c, --channel ] : Set a specific channel number to the lower layer.\n" "[-g, --get] : Get current set channel number from the lower layer.\n" From 260afe3c20a494877fb38bc691c401c721870da2 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 14:15:11 +0530 Subject: [PATCH 0962/1623] [nrf fromlist] wifi: shell: Fix the inconsistency in commands separation For better readability, below rules will help: * Each command should be separated by a newline * Each command should end with a full stop (intermediate statements shouldn't have full stops) Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata (cherry picked from commit 1353dd144af6aaaa71649c82db287525a72da343) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 98 ++++++++++++++++----------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index a983e5c18f5..9bf33e827ec 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1601,7 +1601,7 @@ static int cmd_wifi_packet_filter(const struct shell *sh, size_t argc, char *arg SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, SHELL_CMD_ARG(disable, NULL, - "Disable Access Point mode", + "Disable Access Point mode.\n", cmd_wifi_ap_disable, 1, 0), SHELL_CMD_ARG(enable, NULL, @@ -1611,7 +1611,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, "[Security type: valid only for secure SSIDs]\n" "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" - ": 0:Disable, 1:Optional, 2:Required", + ": 0:Disable, 1:Optional, 2:Required.\n", cmd_wifi_ap_enable, 2, 4), SHELL_SUBCMD_SET_END @@ -1619,30 +1619,30 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops, SHELL_CMD_ARG(quick_setup, NULL, " Start a TWT flow with defaults:\n" - " \n", + " .\n", cmd_wifi_twt_setup_quick, 3, 0), SHELL_CMD_ARG(setup, NULL, " Start a TWT flow:\n" "\n" "\n" " " - " \n", + " .\n", cmd_wifi_twt_setup, 11, 0), SHELL_CMD_ARG(teardown, NULL, " Teardown a TWT flow:\n" "\n" "\n" - " \n", + " .\n", cmd_wifi_twt_teardown, 5, 0), - SHELL_CMD_ARG(teardown_all, NULL, " Teardown all TWT flows\n", + SHELL_CMD_ARG(teardown_all, NULL, " Teardown all TWT flows.\n", cmd_wifi_twt_teardown_all, 1, 0), SHELL_SUBCMD_SET_END ); SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, - SHELL_CMD(ap, &wifi_cmd_ap, "Access Point mode commands", NULL), + SHELL_CMD(ap, &wifi_cmd_ap, "Access Point mode commands.\n", NULL), SHELL_CMD_ARG(connect, NULL, "Connect to a Wi-Fi AP\n" "\"\"\n" @@ -1651,108 +1651,108 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[Security type: valid only for secure SSIDs]\n" "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" - ": 0:Disable, 1:Optional, 2:Required", + ": 0:Disable, 1:Optional, 2:Required.\n", cmd_wifi_connect, 2, 4), - SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP", + SHELL_CMD_ARG(disconnect, NULL, "Disconnect from the Wi-Fi AP.\n", cmd_wifi_disconnect, 1, 0), SHELL_CMD_ARG(ps, NULL, "Configure or display Wi-Fi power save state\n" - "[on/off]\n", + "[on/off].\n", cmd_wifi_ps, 1, 1), SHELL_CMD_ARG(ps_mode, NULL, - "\n", + ".\n", cmd_wifi_ps_mode, 2, 0), SHELL_CMD_ARG(scan, NULL, "Scan for Wi-Fi APs\n" - "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active.\n" - "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz.\n" - "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms.\n" - "[-p, --dwell_time_passive ] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms.\n" - "[-s, --ssid : SSID to scan for. Can be provided multiple times.\n" - "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535.\n" + "[-t, --type ] : Preferred mode of scan. The actual mode of scan can depend on factors such as the Wi-Fi chip implementation, regulatory domain restrictions. Default type is active\n" + "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz\n" + "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms\n" + "[-p, --dwell_time_passive ] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms\n" + "[-s, --ssid : SSID to scan for. Can be provided multiple times\n" + "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535\n" "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6-11,14_5:36,149-165,44\n" - "[-h, --help] : Print out the help for the scan command.", + "[-h, --help] : Print out the help for the scan command.\n", cmd_wifi_scan, 1, 8), - SHELL_CMD_ARG(statistics, NULL, "Wi-Fi interface statistics", cmd_wifi_stats, 1, 0), - SHELL_CMD_ARG(status, NULL, "Status of the Wi-Fi interface", cmd_wifi_status, 1, 0), - SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows", NULL), + SHELL_CMD_ARG(statistics, NULL, "Wi-Fi interface statistics.\n", cmd_wifi_stats, 1, 0), + SHELL_CMD_ARG(status, NULL, "Status of the Wi-Fi interface.\n", cmd_wifi_status, 1, 0), + SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows.\n", NULL), SHELL_CMD_ARG(reg_domain, NULL, "Set or Get Wi-Fi regulatory domain\n" "[ISO/IEC 3166-1 alpha2]: Regulatory domain\n" "[-f]: Force to use this regulatory hint over any other regulatory hints\n" - "Note: This may cause regulatory compliance issues, use it at your own risk.", + "Note: This may cause regulatory compliance issues, use it at your own risk.\n", cmd_wifi_reg_domain, 1, 2), SHELL_CMD_ARG(mode, NULL, "mode operational setting\n" "This command may be used to set the Wi-Fi device into a specific mode of operation\n" - "[-i, --if-index ] : Interface index.\n" - "[-s, --sta] : Station mode.\n" - "[-m, --monitor] : Monitor mode.\n" - "[-p, --promiscuous] : Promiscuous mode.\n" - "[-t, --tx-injection] : TX-Injection mode.\n" - "[-a, --ap] : AP mode.\n" - "[-k, --softap] : Softap mode.\n" - "[-h, --help] : Help.\n" - "[-g, --get] : Get current mode for a specific interface index.\n" + "[-i, --if-index ] : Interface index\n" + "[-s, --sta] : Station mode\n" + "[-m, --monitor] : Monitor mode\n" + "[-p, --promiscuous] : Promiscuous mode\n" + "[-t, --tx-injection] : TX-Injection mode\n" + "[-a, --ap] : AP mode\n" + "[-k, --softap] : Softap mode\n" + "[-h, --help] : Help\n" + "[-g, --get] : Get current mode for a specific interface index\n" "Usage: Get operation example for interface index 1\n" "wifi mode -g -i1\n" "Set operation example for interface index 1 - set station+promiscuous\n" - "wifi mode -i1 -sp\n", + "wifi mode -i1 -sp.\n", cmd_wifi_mode, 1, 9), SHELL_CMD_ARG(packet_filter, NULL, "mode filter setting\n" "This command is used to set packet filter setting when\n" - "monitor, TX-Injection and promiscuous mode is enabled.\n" + "monitor, TX-Injection and promiscuous mode is enabled\n" "The different packet filter modes are control, management, data and enable all filters\n" - "[-i, --if-index ] : Interface index.\n" + "[-i, --if-index ] : Interface index\n" "[-a, --all] : Enable all packet filter modes\n" - "[-m, --mgmt] : Enable management packets to allowed up the stack.\n" - "[-c, --ctrl] : Enable control packets to be allowed up the stack.\n" - "[-d, --data] : Enable Data packets to be allowed up the stack.\n" - "[-g, --get] : Get current filter settings for a specific interface index.\n" + "[-m, --mgmt] : Enable management packets to allowed up the stack\n" + "[-c, --ctrl] : Enable control packets to be allowed up the stack\n" + "[-d, --data] : Enable Data packets to be allowed up the stack\n" + "[-g, --get] : Get current filter settings for a specific interface index\n" "[-b, --capture-len ] : Capture length buffer size for each packet to be captured\n" - "[-h, --help] : Help.\n" + "[-h, --help] : Help\n" "Usage: Get operation example for interface index 1\n" "wifi packet_filter -g -i1\n" "Set operation example for interface index 1 - set data+management frame filter\n" - "wifi packet_filter -i1 -md\n", + "wifi packet_filter -i1 -md.\n", cmd_wifi_packet_filter, 1, 8), SHELL_CMD_ARG(channel, NULL, "wifi channel setting\n" "This command is used to set the channel when\n" - "monitor or TX-Injection mode is enabled.\n" + "monitor or TX-Injection mode is enabled\n" "Currently 20 MHz is only supported and no BW parameter is provided\n" - "[-i, --if-index ] : Interface index.\n" - "[-c, --channel ] : Set a specific channel number to the lower layer.\n" - "[-g, --get] : Get current set channel number from the lower layer.\n" - "[-h, --help] : Help.\n" + "[-i, --if-index ] : Interface index\n" + "[-c, --channel ] : Set a specific channel number to the lower layer\n" + "[-g, --get] : Get current set channel number from the lower layer\n" + "[-h, --help] : Help\n" "Usage: Get operation example for interface index 1\n" "wifi channel -g -i1\n" "Set operation example for interface index 1 (setting channel 5)\n" - "wifi -i1 -c5\n", + "wifi -i1 -c5.\n", cmd_wifi_channel, 1, 4), SHELL_CMD_ARG(ps_timeout, NULL, - " - PS inactivity timer(in ms)", + " - PS inactivity timer(in ms).\n", cmd_wifi_ps_timeout, 2, 0), SHELL_CMD_ARG(ps_listen_interval, NULL, - " - Listen interval in the range of <0-65535>", + " - Listen interval in the range of <0-65535>.\n", cmd_wifi_listen_interval, 2, 0), SHELL_CMD_ARG(ps_wakeup_mode, NULL, - "\n", + ".\n", cmd_wifi_ps_wakeup_mode, 2, 0), From 89aa0c510361acbbf4704d97b2db33f39671a491 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 22 Dec 2023 14:20:22 +0530 Subject: [PATCH 0963/1623] [nrf fromlist] shell: Add a space after colon Just a cosmetic change, but IMHO the help looks much better now :). Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66876 Signed-off-by: Chaitanya Tata (cherry picked from commit 72453d6a4d48e08ec07e86d2fb5cf38a3fe628df) Signed-off-by: Dominik Ermel --- subsys/shell/shell_help.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/shell/shell_help.c b/subsys/shell/shell_help.c index 53bf00953c1..235e2111032 100644 --- a/subsys/shell/shell_help.c +++ b/subsys/shell/shell_help.c @@ -139,7 +139,7 @@ static void help_item_print(const struct shell *sh, const char *item_name, z_cursor_next_line_move(sh); return; } else { - z_shell_fprintf(sh, SHELL_NORMAL, "%s:", tabulator); + z_shell_fprintf(sh, SHELL_NORMAL, "%s: ", tabulator); } /* print option help */ formatted_text_print(sh, item_help, offset, false); From c0ea30dbc132c23d11c863fda9592ad7bfde6843 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 26 Dec 2023 21:27:32 +0530 Subject: [PATCH 0964/1623] [nrf fromlist] wifi: Fix duplication Use a common set of events and then add specific ones as per the configuration. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67015 Signed-off-by: Chaitanya Tata (cherry picked from commit 0646c56102d167a6ef533095d5603e7d411b1f54) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/wifi_shell.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 9bf33e827ec..236e5cd05b8 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -29,19 +29,17 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); #define WIFI_SHELL_MODULE "wifi" +#define WIFI_SHELL_MGMT_EVENTS_COMMON (NET_EVENT_WIFI_SCAN_DONE |\ + NET_EVENT_WIFI_CONNECT_RESULT |\ + NET_EVENT_WIFI_DISCONNECT_RESULT | \ + NET_EVENT_WIFI_TWT |\ + NET_EVENT_WIFI_RAW_SCAN_RESULT) + #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY -#define WIFI_SHELL_MGMT_EVENTS (NET_EVENT_WIFI_RAW_SCAN_RESULT | \ - NET_EVENT_WIFI_SCAN_DONE | \ - NET_EVENT_WIFI_CONNECT_RESULT | \ - NET_EVENT_WIFI_DISCONNECT_RESULT | \ - NET_EVENT_WIFI_TWT) +#define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON) #else -#define WIFI_SHELL_MGMT_EVENTS (NET_EVENT_WIFI_SCAN_RESULT | \ - NET_EVENT_WIFI_SCAN_DONE | \ - NET_EVENT_WIFI_CONNECT_RESULT | \ - NET_EVENT_WIFI_DISCONNECT_RESULT | \ - NET_EVENT_WIFI_TWT | \ - NET_EVENT_WIFI_RAW_SCAN_RESULT) +#define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON |\ + NET_EVENT_WIFI_SCAN_RESULT) #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY */ static struct { From 15fe6c5d4ecfdf5d2e6ab9ebc5d6d41bcf74648a Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Mon, 25 Dec 2023 20:09:45 +0530 Subject: [PATCH 0965/1623] [nrf fromlist] wifi: ap: Add status events These events communicate the status of AP mode operations (enable or disable) with few pre-defined enumerations. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67015 Signed-off-by: Chaitanya Tata (cherry picked from commit af9dc97de19890aa30dc04c1dbd889ef43453747) Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi_mgmt.h | 47 +++++++++++++++++++++++++++++++++ subsys/net/l2/wifi/wifi_mgmt.c | 24 +++++++++++++++++ subsys/net/l2/wifi/wifi_shell.c | 41 +++++++++++++++++++++++++--- 3 files changed, 108 insertions(+), 4 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index babf67722c1..0897bdd5715 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -180,6 +180,10 @@ enum net_event_wifi_cmd { NET_EVENT_WIFI_CMD_RAW_SCAN_RESULT, /** Disconnect complete */ NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE, + /** AP mode enable result */ + NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT, + /** AP mode disable result */ + NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT, }; #define NET_EVENT_WIFI_SCAN_RESULT \ @@ -209,6 +213,12 @@ enum net_event_wifi_cmd { #define NET_EVENT_WIFI_DISCONNECT_COMPLETE \ (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE) +#define NET_EVENT_WIFI_AP_ENABLE_RESULT \ + (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT) + +#define NET_EVENT_WIFI_AP_DISABLE_RESULT \ + (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT) + /** * @brief Wi-Fi structure to uniquely identify a band-channel pair */ @@ -351,12 +361,35 @@ enum wifi_disconn_reason { WIFI_REASON_DISCONN_INACTIVITY, }; +/** Wi-Fi AP mode result codes. To be overlaid on top of \ref wifi_status + * in the AP mode enable or disable result event for detailed status. + */ +enum wifi_ap_status { + /** AP mode enable or disable successful */ + WIFI_STATUS_AP_SUCCESS = 0, + /** AP mode enable or disable failed - generic failure */ + WIFI_STATUS_AP_FAIL, + /** AP mode enable failed - channel not supported */ + WIFI_STATUS_AP_CHANNEL_NOT_SUPPORTED, + /** AP mode enable failed - channel not allowed */ + WIFI_STATUS_AP_CHANNEL_NOT_ALLOWED, + /** AP mode enable failed - SSID not allowed */ + WIFI_STATUS_AP_SSID_NOT_ALLOWED, + /** AP mode enable failed - authentication type not supported */ + WIFI_STATUS_AP_AUTH_TYPE_NOT_SUPPORTED, + /** AP mode enable failed - operation not supported */ + WIFI_STATUS_AP_OP_NOT_SUPPORTED, + /** AP mode enable failed - operation not permitted */ + WIFI_STATUS_AP_OP_NOT_PERMITTED, +}; + /** Generic Wi-Fi status for commands and events */ struct wifi_status { union { int status; enum wifi_conn_status conn_status; enum wifi_disconn_reason disconn_reason; + enum wifi_ap_status ap_status; }; }; @@ -802,6 +835,20 @@ void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface, */ void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface, int status); +/** Wi-Fi management AP mode enable result event + * + * @param iface Network interface + * @param status AP mode enable result status + */ +void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, enum wifi_ap_status status); + +/** Wi-Fi management AP mode disable result event + * + * @param iface Network interface + * @param status AP mode disable result status + */ +void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, enum wifi_ap_status status); + /** * @} */ diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 1a866d4c47c..21a426d794d 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -707,3 +707,27 @@ void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface, iface, &cnx_status, sizeof(struct wifi_status)); } + +void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, + enum wifi_ap_status status) +{ + struct wifi_status cnx_status = { + .status = status, + }; + + net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_ENABLE_RESULT, + iface, &cnx_status, + sizeof(enum wifi_ap_status)); +} + +void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, + enum wifi_ap_status status) +{ + struct wifi_status cnx_status = { + .status = status, + }; + + net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_DISABLE_RESULT, + iface, &cnx_status, + sizeof(enum wifi_ap_status)); +} diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 236e5cd05b8..217e4c703c0 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -33,7 +33,9 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); NET_EVENT_WIFI_CONNECT_RESULT |\ NET_EVENT_WIFI_DISCONNECT_RESULT | \ NET_EVENT_WIFI_TWT |\ - NET_EVENT_WIFI_RAW_SCAN_RESULT) + NET_EVENT_WIFI_RAW_SCAN_RESULT |\ + NET_EVENT_WIFI_AP_ENABLE_RESULT |\ + NET_EVENT_WIFI_AP_DISABLE_RESULT) #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY #define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON) @@ -300,6 +302,32 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) } } +static void handle_wifi_ap_enable_result(struct net_mgmt_event_callback *cb) +{ + const struct wifi_status *status = + (const struct wifi_status *)cb->info; + + if (status->status) { + print(context.sh, SHELL_WARNING, + "AP enable request failed (%d)\n", status->status); + } else { + print(context.sh, SHELL_NORMAL, "AP enabled\n"); + } +} + +static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb) +{ + const struct wifi_status *status = + (const struct wifi_status *)cb->info; + + if (status->status) { + print(context.sh, SHELL_WARNING, + "AP disable request failed (%d)\n", status->status); + } else { + print(context.sh, SHELL_NORMAL, "AP disabled\n"); + } +} + static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, struct net_if *iface) { @@ -324,6 +352,12 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, handle_wifi_raw_scan_result(cb); break; #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ + case NET_EVENT_WIFI_AP_ENABLE_RESULT: + handle_wifi_ap_enable_result(cb); + break; + case NET_EVENT_WIFI_AP_DISABLE_RESULT: + handle_wifi_ap_disable_result(cb); + break; default: break; } @@ -1112,7 +1146,7 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc, return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "AP mode enabled\n"); + shell_fprintf(sh, SHELL_NORMAL, "AP mode enable requested\n"); return 0; } @@ -1129,8 +1163,7 @@ static int cmd_wifi_ap_disable(const struct shell *sh, size_t argc, return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "AP mode disabled\n"); - + shell_fprintf(sh, SHELL_NORMAL, "AP mode disable requested\n"); return 0; } From 9a5a739cde1ed10fab5a0c989b991390d0412236 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 26 Dec 2023 21:17:51 +0530 Subject: [PATCH 0966/1623] [nrf fromlist] wifi: ap: Add client side events These are helpful to track clients being added and deleted. Applications can actions based on these events. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67015 Signed-off-by: Chaitanya Tata (cherry picked from commit 81038eb0200a36600381bfd7120c9105111b9cb0) Signed-off-by: Dominik Ermel --- include/zephyr/net/wifi_mgmt.h | 38 +++++++++++++++++++++++++++++++++ subsys/net/l2/wifi/wifi_mgmt.c | 16 ++++++++++++++ subsys/net/l2/wifi/wifi_shell.c | 32 ++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 0897bdd5715..78800f451e7 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -184,6 +184,10 @@ enum net_event_wifi_cmd { NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT, /** AP mode disable result */ NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT, + /** STA connected to AP */ + NET_EVENT_WIFI_CMD_AP_STA_CONNECTED, + /** STA disconnected from AP */ + NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED, }; #define NET_EVENT_WIFI_SCAN_RESULT \ @@ -219,6 +223,12 @@ enum net_event_wifi_cmd { #define NET_EVENT_WIFI_AP_DISABLE_RESULT \ (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT) +#define NET_EVENT_WIFI_AP_STA_CONNECTED \ + (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_CONNECTED) + +#define NET_EVENT_WIFI_AP_STA_DISCONNECTED \ + (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED) + /** * @brief Wi-Fi structure to uniquely identify a band-channel pair */ @@ -568,6 +578,18 @@ struct wifi_raw_scan_result { }; #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ +/** AP mode - connected STA details */ +struct wifi_ap_sta_info { + /** Link mode, see enum wifi_link_mode */ + enum wifi_link_mode link_mode; + /** MAC address */ + uint8_t mac[WIFI_MAC_ADDR_LEN]; + /** MAC address length */ + uint8_t mac_length; + /** is TWT capable ? */ + bool twt_capable; +}; + /* for use in max info size calculations */ union wifi_mgmt_events { struct wifi_scan_result scan_result; @@ -577,6 +599,7 @@ union wifi_mgmt_events { struct wifi_raw_scan_result raw_scan_result; #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ struct wifi_twt_params twt_params; + struct wifi_ap_sta_info ap_sta_info; }; /** Wi-Fi mode setup */ @@ -849,6 +872,21 @@ void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface, enum wifi_ap_s */ void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, enum wifi_ap_status status); +/** Wi-Fi management AP mode STA connected event + * + * @param iface Network interface + * @param sta_info STA information + */ +void wifi_mgmt_raise_ap_sta_connected_event(struct net_if *iface, + struct wifi_ap_sta_info *sta_info); + +/** Wi-Fi management AP mode STA disconnected event + * @param iface Network interface + * @param sta_info STA information + */ +void wifi_mgmt_raise_ap_sta_disconnected_event(struct net_if *iface, + struct wifi_ap_sta_info *sta_info); + /** * @} */ diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 21a426d794d..6e0cb761dbf 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -731,3 +731,19 @@ void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface, iface, &cnx_status, sizeof(enum wifi_ap_status)); } + +void wifi_mgmt_raise_ap_sta_connected_event(struct net_if *iface, + struct wifi_ap_sta_info *sta_info) +{ + net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_STA_CONNECTED, + iface, sta_info, + sizeof(struct wifi_ap_sta_info)); +} + +void wifi_mgmt_raise_ap_sta_disconnected_event(struct net_if *iface, + struct wifi_ap_sta_info *sta_info) +{ + net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_STA_DISCONNECTED, + iface, sta_info, + sizeof(struct wifi_ap_sta_info)); +} diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 217e4c703c0..045fbed197e 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -35,7 +35,9 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); NET_EVENT_WIFI_TWT |\ NET_EVENT_WIFI_RAW_SCAN_RESULT |\ NET_EVENT_WIFI_AP_ENABLE_RESULT |\ - NET_EVENT_WIFI_AP_DISABLE_RESULT) + NET_EVENT_WIFI_AP_DISABLE_RESULT |\ + NET_EVENT_WIFI_AP_STA_CONNECTED |\ + NET_EVENT_WIFI_AP_STA_DISCONNECTED) #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY #define WIFI_SHELL_MGMT_EVENTS (WIFI_SHELL_MGMT_EVENTS_COMMON) @@ -328,6 +330,28 @@ static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb) } } +static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) +{ + const struct wifi_ap_sta_info *sta_info = + (const struct wifi_ap_sta_info *)cb->info; + uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + + print(context.sh, SHELL_NORMAL, "Station connected: %s\n", + net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, + mac_string_buf, sizeof(mac_string_buf))); +} + +static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb) +{ + const struct wifi_ap_sta_info *sta_info = + (const struct wifi_ap_sta_info *)cb->info; + uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + + print(context.sh, SHELL_NORMAL, "Station disconnected: %s\n", + net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, + mac_string_buf, sizeof(mac_string_buf))); +} + static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, struct net_if *iface) { @@ -358,6 +382,12 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, case NET_EVENT_WIFI_AP_DISABLE_RESULT: handle_wifi_ap_disable_result(cb); break; + case NET_EVENT_WIFI_AP_STA_CONNECTED: + handle_wifi_ap_sta_connected(cb); + break; + case NET_EVENT_WIFI_AP_STA_DISCONNECTED: + handle_wifi_ap_sta_disconnected(cb); + break; default: break; } From b5c01369df121c4a9ee23f4c9c51ccdf4edb16d1 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 27 Dec 2023 00:06:45 +0530 Subject: [PATCH 0967/1623] [nrf fromlist] wifi: shell: Add a shell command to list stations In AP mode maintain the database of connected stations based on the Wi-Fi management events and dump the list. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67015 Signed-off-by: Chaitanya Tata (cherry picked from commit 3dab922e5d0561d37823058b0fa5fad18376cb33) Signed-off-by: Dominik Ermel --- subsys/net/l2/wifi/Kconfig | 8 +++ subsys/net/l2/wifi/wifi_shell.c | 90 +++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/subsys/net/l2/wifi/Kconfig b/subsys/net/l2/wifi/Kconfig index 134448aa57f..2816be56d74 100644 --- a/subsys/net/l2/wifi/Kconfig +++ b/subsys/net/l2/wifi/Kconfig @@ -64,6 +64,14 @@ config WIFI_MGMT_SCAN_CHAN_MAX_MANUAL There are approximately 100 channels allocated across the three supported bands. The default of 3 allows the 3 most common channels (2.4GHz: 1, 6, 11) to be specified. +config WIFI_SHELL_MAX_AP_STA + int "Maximum number of APs and STAs that can be managed in Wi-Fi shell" + range 1 5 + default 1 + help + This option defines the maximum number of APs and STAs that can be managed + in Wi-Fi shell. + config WIFI_NM bool "Wi-Fi Network manager support" help diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 045fbed197e..1ee94304781 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -24,6 +24,7 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); #include #include #include +#include #include "net_private.h" @@ -64,6 +65,13 @@ static uint32_t scan_result; static struct net_mgmt_event_callback wifi_shell_mgmt_cb; +static K_MUTEX_DEFINE(wifi_ap_sta_list_lock); +struct wifi_ap_sta_node { + bool valid; + struct wifi_ap_sta_info sta_info; +}; +static struct wifi_ap_sta_node sta_list[CONFIG_WIFI_SHELL_MAX_AP_STA]; + #define print(sh, level, fmt, ...) \ do { \ if (sh) { \ @@ -328,6 +336,10 @@ static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb) } else { print(context.sh, SHELL_NORMAL, "AP disabled\n"); } + + k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); + memset(&sta_list, 0, sizeof(sta_list)); + k_mutex_unlock(&wifi_ap_sta_list_lock); } static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) @@ -335,10 +347,25 @@ static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) const struct wifi_ap_sta_info *sta_info = (const struct wifi_ap_sta_info *)cb->info; uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + int i; print(context.sh, SHELL_NORMAL, "Station connected: %s\n", net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, mac_string_buf, sizeof(mac_string_buf))); + + k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); + for (i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { + if (!sta_list[i].valid) { + sta_list[i].sta_info = *sta_info; + sta_list[i].valid = true; + break; + } + } + if (i == CONFIG_WIFI_SHELL_MAX_AP_STA) { + print(context.sh, SHELL_WARNING, "No space to store station info: " + "Increase CONFIG_WIFI_SHELL_MAX_AP_STA\n"); + } + k_mutex_unlock(&wifi_ap_sta_list_lock); } static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb) @@ -350,6 +377,20 @@ static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb) print(context.sh, SHELL_NORMAL, "Station disconnected: %s\n", net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, mac_string_buf, sizeof(mac_string_buf))); + + k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); + for (int i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { + if (!sta_list[i].valid) { + continue; + } + + if (!memcmp(sta_list[i].sta_info.mac, sta_info->mac, + WIFI_MAC_ADDR_LEN)) { + sta_list[i].valid = false; + break; + } + } + k_mutex_unlock(&wifi_ap_sta_list_lock); } static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, @@ -1169,6 +1210,8 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc, context.sh = sh; + k_mutex_init(&wifi_ap_sta_list_lock); + ret = net_mgmt(NET_REQUEST_WIFI_AP_ENABLE, iface, &cnx_params, sizeof(struct wifi_connect_req_params)); if (ret) { @@ -1197,6 +1240,49 @@ static int cmd_wifi_ap_disable(const struct shell *sh, size_t argc, return 0; } +static int cmd_wifi_ap_stations(const struct shell *sh, size_t argc, + char *argv[]) +{ + size_t id = 1; + + ARG_UNUSED(argv); + ARG_UNUSED(argc); + + shell_fprintf(sh, SHELL_NORMAL, "AP stations:\n"); + shell_fprintf(sh, SHELL_NORMAL, "============\n"); + + k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); + for (int i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { + struct wifi_ap_sta_info *sta; + uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + + if (!sta_list[i].valid) { + continue; + } + + sta = &sta_list[i].sta_info; + + shell_fprintf(sh, SHELL_NORMAL, "Station %zu:\n", id++); + shell_fprintf(sh, SHELL_NORMAL, "==========\n"); + shell_fprintf(sh, SHELL_NORMAL, "MAC: %s\n", + net_sprint_ll_addr_buf(sta->mac, + WIFI_MAC_ADDR_LEN, + mac_string_buf, + sizeof(mac_string_buf))); + shell_fprintf(sh, SHELL_NORMAL, "Link mode: %s\n", + wifi_link_mode_txt(sta->link_mode)); + shell_fprintf(sh, SHELL_NORMAL, "TWT: %s\n", + sta->twt_capable ? "Supported" : "Not supported"); + } + + if (id == 1) { + shell_fprintf(sh, SHELL_NORMAL, "No stations connected\n"); + } + k_mutex_unlock(&wifi_ap_sta_list_lock); + + return 0; +} + static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc, char *argv[]) @@ -1675,6 +1761,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, ": 0:Disable, 1:Optional, 2:Required.\n", cmd_wifi_ap_enable, 2, 4), + SHELL_CMD_ARG(stations, NULL, + "List stations connected to the AP", + cmd_wifi_ap_stations, + 1, 0), SHELL_SUBCMD_SET_END ); From 7300a52ddc328f6ba9b8d081a2224143f74c869d Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 20 Nov 2023 15:00:59 +0000 Subject: [PATCH 0968/1623] [nrf fromlist] drivers: ieee802154: nrf5: Fix missed variable rename Fixes and issue with a variable that has been renamed but whose reference in the source file has not Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65480 Signed-off-by: Jamie McCrae Signed-off-by: Dominik Ermel --- drivers/ieee802154/ieee802154_nrf5.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index defbc90cd07..df01f530abf 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -933,9 +933,9 @@ static int nrf5_configure(const struct device *dev, #if defined(CONFIG_NRF_802154_SER_HOST) net_time_t period_ns = nrf5_data.csl_period * NSEC_PER_TEN_SYMBOLS; - bool changed = (config->csl_rx_time - nrf5_data.csl_rx_time) % period_ns; + bool changed = (config->expected_rx_time - nrf5_data.csl_rx_time) % period_ns; - nrf5_data.csl_rx_time = config->csl_rx_time; + nrf5_data.csl_rx_time = config->expected_rx_time; if (changed) #endif /* CONFIG_NRF_802154_SER_HOST */ From 7513bd8b9de3664eea8dc02121fa083dbae9e188 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Thu, 23 Nov 2023 12:54:12 +0100 Subject: [PATCH 0969/1623] [nrf fromtree] sysbuild: introduce Kconfig setting for controlling HCI IPC inclusion Follow-up: #64704 Introducing NET_CORE_IMAGE_HCI_IPC Kconfig setting to control inclusion of HCI IPC image when building through sysbuild. This allows users with custom netcore applications to avoid inclusion of the default HCI IPC image. Signed-off-by: Torsten Rasmussen (cherry picked from commit 13f3c6d0bda59855b8928fb510cb1cd3687c4dce) Signed-off-by: Dominik Ermel --- samples/bluetooth/broadcast_audio_sink/Kconfig.sysbuild | 5 +++++ samples/bluetooth/broadcast_audio_sink/sysbuild.cmake | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/samples/bluetooth/broadcast_audio_sink/Kconfig.sysbuild b/samples/bluetooth/broadcast_audio_sink/Kconfig.sysbuild index 37a6b66c7f4..f434010f81d 100644 --- a/samples/bluetooth/broadcast_audio_sink/Kconfig.sysbuild +++ b/samples/bluetooth/broadcast_audio_sink/Kconfig.sysbuild @@ -8,3 +8,8 @@ config NET_CORE_BOARD default "nrf5340dk_nrf5340_cpunet" if $(BOARD) = "nrf5340dk_nrf5340_cpuapp" default "nrf5340_audio_dk_nrf5340_cpunet" if $(BOARD) = "nrf5340_audio_dk_nrf5340_cpuapp" default "nrf5340bsim_nrf5340_cpunet" if $(BOARD) = "nrf5340bsim_nrf5340_cpuapp" + +config NET_CORE_IMAGE_HCI_IPC + bool "HCI IPC image on network core" + default y + depends on NET_CORE_BOARD != "" diff --git a/samples/bluetooth/broadcast_audio_sink/sysbuild.cmake b/samples/bluetooth/broadcast_audio_sink/sysbuild.cmake index c150913cc55..ed30d7f31f3 100644 --- a/samples/bluetooth/broadcast_audio_sink/sysbuild.cmake +++ b/samples/bluetooth/broadcast_audio_sink/sysbuild.cmake @@ -1,7 +1,7 @@ # Copyright (c) 2023 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -if(NOT("${SB_CONFIG_NET_CORE_BOARD}" STREQUAL "")) +if(SB_CONFIG_NET_CORE_IMAGE_HCI_IPC) # For builds in the nrf5340, we build the netcore image with the controller set(NET_APP hci_ipc) From 7086c624dbd5fd627891e1a7ee683a182370657f Mon Sep 17 00:00:00 2001 From: Marek Pieta Date: Mon, 27 Nov 2023 19:31:30 +0100 Subject: [PATCH 0970/1623] [nrf fromtree] soc: arm: nrf52: Configurable EGU instance for anomaly 109 workaround Change makes EGU instance used for anomaly 109 workaround configurable. The default EGU instance (5) may be used for other purpose. Signed-off-by: Marek Pieta (cherry picked from commit 00d8263a935dbfed3088f0fdc911aab7eb801587) Signed-off-by: Dominik Ermel --- modules/hal_nordic/nrfx/nrfx_config.h | 2 ++ soc/arm/nordic_nrf/nrf52/Kconfig.soc | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index aaf31751004..b5b09b96078 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -586,6 +586,8 @@ #define NRFX_SPIS_NRF52_ANOMALY_109_WORKAROUND_ENABLED 1 #define NRFX_TWIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 1 #define NRFX_PWM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 1 +#define NRFX_PWM_NRF52_ANOMALY_109_EGU_INSTANCE \ + CONFIG_NRF52_ANOMALY_109_WORKAROUND_EGU_INSTANCE #endif #if defined(CONFIG_SOC_SERIES_BSIM_NRFXX) diff --git a/soc/arm/nordic_nrf/nrf52/Kconfig.soc b/soc/arm/nordic_nrf/nrf52/Kconfig.soc index 517b4ce2baa..de6a16129d3 100644 --- a/soc/arm/nordic_nrf/nrf52/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf52/Kconfig.soc @@ -147,4 +147,12 @@ config NRF52_ANOMALY_109_WORKAROUND 64MHz clock at the same time as the peripheral that is using DMA is started. This anomaly applies to IC revisions up to "3", the most recent one. +config NRF52_ANOMALY_109_WORKAROUND_EGU_INSTANCE + int "Anomaly 109 workaround EGU instance" + depends on NRF52_ANOMALY_109_WORKAROUND + range 0 5 + default 5 + help + EGU instance used by the nRF52 Anomaly 109 workaround for PWM. + endif # SOC_SERIES_NRF52X From 23f410daa5232429398b95350a82c5368b4d32eb Mon Sep 17 00:00:00 2001 From: Marek Pieta Date: Tue, 28 Nov 2023 13:31:01 +0100 Subject: [PATCH 0971/1623] [nrf fromlist] drivers: usb: nrf_usbd_common: Remove unneeded assertion Code uses local RAM buffer to properly handle the case where provided USB transfer TX data is not in RAM. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/65865 Signed-off-by: Marek Pieta Signed-off-by: Dominik Ermel --- drivers/usb/common/nrf_usbd_common/nrf_usbd_common.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/usb/common/nrf_usbd_common/nrf_usbd_common.c b/drivers/usb/common/nrf_usbd_common/nrf_usbd_common.c index 9045e1ded70..3db193ee2f0 100644 --- a/drivers/usb/common/nrf_usbd_common/nrf_usbd_common.c +++ b/drivers/usb/common/nrf_usbd_common/nrf_usbd_common.c @@ -376,8 +376,6 @@ static bool nrf_usbd_common_feeder(nrf_usbd_common_ep_transfer_t *p_next, nrf_usbd_common_transfer_t *p_transfer, size_t ep_size) { - __ASSERT_NO_MSG(nrfx_is_in_ram(p_transfer->p_data.tx)); - size_t tx_size = p_transfer->size; if (tx_size > ep_size) { From 6f609a096e5ecc3ac2a993de4b2bbc33c4fe3a98 Mon Sep 17 00:00:00 2001 From: Marek Pieta Date: Tue, 5 Dec 2023 13:30:39 +0100 Subject: [PATCH 0972/1623] [nrf fromlist] logging: Fix using simplified message creation mode Change fixes marcos used to determine if argument types allow simplified message creation mode. Both arguments types must be proper. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66156 Signed-off-by: Marek Pieta Signed-off-by: Dominik Ermel --- include/zephyr/logging/log_msg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/logging/log_msg.h b/include/zephyr/logging/log_msg.h index fabc7a16b0c..39cbf1cedbc 100644 --- a/include/zephyr/logging/log_msg.h +++ b/include/zephyr/logging/log_msg.h @@ -241,7 +241,7 @@ enum z_log_msg_mode { #define LOG_MSG_SIMPLE_ARG_TYPE_CHECK_0(fmt) 1 #define LOG_MSG_SIMPLE_ARG_TYPE_CHECK_1(fmt, arg) Z_CBPRINTF_IS_WORD_NUM(arg) #define LOG_MSG_SIMPLE_ARG_TYPE_CHECK_2(fmt, arg0, arg1) \ - Z_CBPRINTF_IS_WORD_NUM(arg0) || Z_CBPRINTF_IS_WORD_NUM(arg1) + Z_CBPRINTF_IS_WORD_NUM(arg0) && Z_CBPRINTF_IS_WORD_NUM(arg1) /** brief Determine if string arguments types allow to use simplified message creation mode. * From 6da4c914b11a8a5c0441ee2c50e9450908ca9a51 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 24 Nov 2023 12:45:11 +0100 Subject: [PATCH 0973/1623] [nrf fromtree] samples/bluetooth: sysbuild: Add Kconfig setting for HCI IPC inclusion Introduce NET_CORE_IMAGE_HCI_IPC Kconfig setting to control inclusion of HCI IPC image when building through sysbuild. This allows users with custom netcore applications to avoid inclusion of the default HCI IPC image. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 8f78b7148ce5234aa877b2653ae99ddcab3a5c75) Signed-off-by: Dominik Ermel --- samples/bluetooth/broadcast_audio_source/Kconfig.sysbuild | 5 +++++ samples/bluetooth/broadcast_audio_source/sysbuild.cmake | 2 +- samples/bluetooth/unicast_audio_client/Kconfig.sysbuild | 5 +++++ samples/bluetooth/unicast_audio_client/sysbuild.cmake | 2 +- samples/bluetooth/unicast_audio_server/Kconfig.sysbuild | 5 +++++ samples/bluetooth/unicast_audio_server/sysbuild.cmake | 2 +- 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/samples/bluetooth/broadcast_audio_source/Kconfig.sysbuild b/samples/bluetooth/broadcast_audio_source/Kconfig.sysbuild index 37a6b66c7f4..f434010f81d 100644 --- a/samples/bluetooth/broadcast_audio_source/Kconfig.sysbuild +++ b/samples/bluetooth/broadcast_audio_source/Kconfig.sysbuild @@ -8,3 +8,8 @@ config NET_CORE_BOARD default "nrf5340dk_nrf5340_cpunet" if $(BOARD) = "nrf5340dk_nrf5340_cpuapp" default "nrf5340_audio_dk_nrf5340_cpunet" if $(BOARD) = "nrf5340_audio_dk_nrf5340_cpuapp" default "nrf5340bsim_nrf5340_cpunet" if $(BOARD) = "nrf5340bsim_nrf5340_cpuapp" + +config NET_CORE_IMAGE_HCI_IPC + bool "HCI IPC image on network core" + default y + depends on NET_CORE_BOARD != "" diff --git a/samples/bluetooth/broadcast_audio_source/sysbuild.cmake b/samples/bluetooth/broadcast_audio_source/sysbuild.cmake index c150913cc55..ed30d7f31f3 100644 --- a/samples/bluetooth/broadcast_audio_source/sysbuild.cmake +++ b/samples/bluetooth/broadcast_audio_source/sysbuild.cmake @@ -1,7 +1,7 @@ # Copyright (c) 2023 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -if(NOT("${SB_CONFIG_NET_CORE_BOARD}" STREQUAL "")) +if(SB_CONFIG_NET_CORE_IMAGE_HCI_IPC) # For builds in the nrf5340, we build the netcore image with the controller set(NET_APP hci_ipc) diff --git a/samples/bluetooth/unicast_audio_client/Kconfig.sysbuild b/samples/bluetooth/unicast_audio_client/Kconfig.sysbuild index 37a6b66c7f4..f434010f81d 100644 --- a/samples/bluetooth/unicast_audio_client/Kconfig.sysbuild +++ b/samples/bluetooth/unicast_audio_client/Kconfig.sysbuild @@ -8,3 +8,8 @@ config NET_CORE_BOARD default "nrf5340dk_nrf5340_cpunet" if $(BOARD) = "nrf5340dk_nrf5340_cpuapp" default "nrf5340_audio_dk_nrf5340_cpunet" if $(BOARD) = "nrf5340_audio_dk_nrf5340_cpuapp" default "nrf5340bsim_nrf5340_cpunet" if $(BOARD) = "nrf5340bsim_nrf5340_cpuapp" + +config NET_CORE_IMAGE_HCI_IPC + bool "HCI IPC image on network core" + default y + depends on NET_CORE_BOARD != "" diff --git a/samples/bluetooth/unicast_audio_client/sysbuild.cmake b/samples/bluetooth/unicast_audio_client/sysbuild.cmake index c150913cc55..ed30d7f31f3 100644 --- a/samples/bluetooth/unicast_audio_client/sysbuild.cmake +++ b/samples/bluetooth/unicast_audio_client/sysbuild.cmake @@ -1,7 +1,7 @@ # Copyright (c) 2023 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -if(NOT("${SB_CONFIG_NET_CORE_BOARD}" STREQUAL "")) +if(SB_CONFIG_NET_CORE_IMAGE_HCI_IPC) # For builds in the nrf5340, we build the netcore image with the controller set(NET_APP hci_ipc) diff --git a/samples/bluetooth/unicast_audio_server/Kconfig.sysbuild b/samples/bluetooth/unicast_audio_server/Kconfig.sysbuild index 37a6b66c7f4..f434010f81d 100644 --- a/samples/bluetooth/unicast_audio_server/Kconfig.sysbuild +++ b/samples/bluetooth/unicast_audio_server/Kconfig.sysbuild @@ -8,3 +8,8 @@ config NET_CORE_BOARD default "nrf5340dk_nrf5340_cpunet" if $(BOARD) = "nrf5340dk_nrf5340_cpuapp" default "nrf5340_audio_dk_nrf5340_cpunet" if $(BOARD) = "nrf5340_audio_dk_nrf5340_cpuapp" default "nrf5340bsim_nrf5340_cpunet" if $(BOARD) = "nrf5340bsim_nrf5340_cpuapp" + +config NET_CORE_IMAGE_HCI_IPC + bool "HCI IPC image on network core" + default y + depends on NET_CORE_BOARD != "" diff --git a/samples/bluetooth/unicast_audio_server/sysbuild.cmake b/samples/bluetooth/unicast_audio_server/sysbuild.cmake index c150913cc55..ed30d7f31f3 100644 --- a/samples/bluetooth/unicast_audio_server/sysbuild.cmake +++ b/samples/bluetooth/unicast_audio_server/sysbuild.cmake @@ -1,7 +1,7 @@ # Copyright (c) 2023 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -if(NOT("${SB_CONFIG_NET_CORE_BOARD}" STREQUAL "")) +if(SB_CONFIG_NET_CORE_IMAGE_HCI_IPC) # For builds in the nrf5340, we build the netcore image with the controller set(NET_APP hci_ipc) From cebd9529012a78d5d15738b91b2556bfddc1c0ed Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 24 Nov 2023 12:02:14 +0100 Subject: [PATCH 0974/1623] [nrf fromtree] tests: bsim: Bluetooth: Enable nrf5340bsim CIS ACL group test Enable testing CIS ACL group test on nrf5340bsim. Signed-off-by: Vinayak Kariappa Chettimada (cherry picked from commit 411731f778b771f0130b2d7d39e7dfd326305f61) Signed-off-by: Dominik Ermel --- .../compile.nrf5340bsim_nrf5340_cpuapp.sh | 1 + tests/bsim/bluetooth/ll/cis/Kconfig.sysbuild | 14 ++ tests/bsim/bluetooth/ll/cis/sysbuild.cmake | 47 +++++++ ...0_cpunet_iso_acl_group-bt_ll_sw_split.conf | 122 ++++++++++++++++++ 4 files changed, 184 insertions(+) create mode 100644 tests/bsim/bluetooth/ll/cis/Kconfig.sysbuild create mode 100644 tests/bsim/bluetooth/ll/cis/sysbuild.cmake create mode 100644 tests/bsim/bluetooth/ll/cis/sysbuild/hci_ipc/nrf5340_cpunet_iso_acl_group-bt_ll_sw_split.conf diff --git a/tests/bsim/bluetooth/compile.nrf5340bsim_nrf5340_cpuapp.sh b/tests/bsim/bluetooth/compile.nrf5340bsim_nrf5340_cpuapp.sh index 4f175540347..65769185867 100755 --- a/tests/bsim/bluetooth/compile.nrf5340bsim_nrf5340_cpuapp.sh +++ b/tests/bsim/bluetooth/compile.nrf5340bsim_nrf5340_cpuapp.sh @@ -21,6 +21,7 @@ source ${ZEPHYR_BASE}/tests/bsim/compile.source app=tests/bsim/bluetooth/ll/conn conf_file=prj_split_privacy.conf sysbuild=1 compile app=tests/bsim/bluetooth/ll/bis sysbuild=1 compile +app=tests/bsim/bluetooth/ll/cis conf_overlay=overlay-acl_group.conf sysbuild=1 compile run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/audio_samples/compile.sh diff --git a/tests/bsim/bluetooth/ll/cis/Kconfig.sysbuild b/tests/bsim/bluetooth/ll/cis/Kconfig.sysbuild new file mode 100644 index 00000000000..6c89fddc9f3 --- /dev/null +++ b/tests/bsim/bluetooth/ll/cis/Kconfig.sysbuild @@ -0,0 +1,14 @@ +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "share/sysbuild/Kconfig" + +config NET_CORE_BOARD + string + default "nrf5340bsim_nrf5340_cpunet" if $(BOARD) = "nrf5340bsim_nrf5340_cpuapp" + +config NATIVE_SIMULATOR_PRIMARY_MCU_INDEX + int + # Let's pass the test arguments to the application MCU test + # otherwise by default they would have gone to the net core. + default 0 if $(BOARD) = "nrf5340bsim_nrf5340_cpuapp" diff --git a/tests/bsim/bluetooth/ll/cis/sysbuild.cmake b/tests/bsim/bluetooth/ll/cis/sysbuild.cmake new file mode 100644 index 00000000000..495c3f4a20d --- /dev/null +++ b/tests/bsim/bluetooth/ll/cis/sysbuild.cmake @@ -0,0 +1,47 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if(NOT("${SB_CONFIG_NET_CORE_BOARD}" STREQUAL "")) + set(NET_APP hci_ipc) + set(NET_APP_SRC_DIR ${ZEPHYR_BASE}/samples/bluetooth/${NET_APP}) + + ExternalZephyrProject_Add( + APPLICATION ${NET_APP} + SOURCE_DIR ${NET_APP_SRC_DIR} + BOARD ${SB_CONFIG_NET_CORE_BOARD} + ) + + set(${NET_APP}_CONF_FILE + ${APP_DIR}/sysbuild/hci_ipc/nrf5340_cpunet_iso_acl_group-bt_ll_sw_split.conf + CACHE INTERNAL "" + ) + + # For the simulated board, the application core build will produce the final executable + # for that, we give it the path to the netcore image + set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${NET_APP}/zephyr/zephyr.elf) + set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG + "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" + ) + + if (NOT ("${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}" STREQUAL "")) + set_property(TARGET ${NET_APP} APPEND_STRING PROPERTY CONFIG + "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" + ) + set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG + "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" + ) + endif() + + # Let's build the net core library first + add_dependencies(${DEFAULT_IMAGE} ${NET_APP}) +endif() + +# Let's meet the expectation of finding the final executable in zephyr/zephyr.exe +add_custom_target(final_executable + ALL + COMMAND + ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe + ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe + DEPENDS ${DEFAULT_IMAGE} +) diff --git a/tests/bsim/bluetooth/ll/cis/sysbuild/hci_ipc/nrf5340_cpunet_iso_acl_group-bt_ll_sw_split.conf b/tests/bsim/bluetooth/ll/cis/sysbuild/hci_ipc/nrf5340_cpunet_iso_acl_group-bt_ll_sw_split.conf new file mode 100644 index 00000000000..a3c8f43c71f --- /dev/null +++ b/tests/bsim/bluetooth/ll/cis/sysbuild/hci_ipc/nrf5340_cpunet_iso_acl_group-bt_ll_sw_split.conf @@ -0,0 +1,122 @@ +CONFIG_IPC_SERVICE=y +CONFIG_MBOX=y + +CONFIG_ISR_STACK_SIZE=1024 +CONFIG_IDLE_STACK_SIZE=256 +CONFIG_MAIN_STACK_SIZE=512 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 +CONFIG_IPC_SERVICE_BACKEND_RPMSG_WQ_STACK_SIZE=512 +CONFIG_HEAP_MEM_POOL_SIZE=8192 +CONFIG_CBPRINTF_REDUCED_INTEGRAL=y + +CONFIG_BT=y +CONFIG_BT_HCI_RAW=y +CONFIG_BT_HCI_RAW_RESERVE=1 +CONFIG_BT_MAX_CONN=4 + +# Workaround: Unable to allocate command buffer when using K_NO_WAIT since +# Host number of completed commands does not follow normal flow control. +CONFIG_BT_BUF_CMD_TX_COUNT=10 + +CONFIG_BT_BUF_EVT_RX_COUNT=16 + +CONFIG_BT_BUF_EVT_RX_SIZE=255 +CONFIG_BT_BUF_ACL_RX_SIZE=255 +CONFIG_BT_BUF_ACL_TX_SIZE=251 +CONFIG_BT_BUF_CMD_TX_SIZE=255 + +# Tx/Rx Thread Stack Sizes +CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y +CONFIG_BT_HCI_TX_STACK_SIZE=1152 +CONFIG_BT_RX_STACK_SIZE=640 +CONFIG_BT_CTLR_RX_PRIO_STACK_SIZE=448 + +# Host features +CONFIG_BT_EXT_ADV=y +CONFIG_BT_PER_ADV=y +CONFIG_BT_PER_ADV_SYNC=y +CONFIG_BT_PER_ADV_SYNC_MAX=2 + +# Broadcast and Connected ISO +CONFIG_BT_ISO_BROADCASTER=y +CONFIG_BT_ISO_SYNC_RECEIVER=y +CONFIG_BT_ISO_CENTRAL=y +CONFIG_BT_ISO_PERIPHERAL=y + +# ISO Streams +CONFIG_BT_ISO_MAX_CHAN=4 + +# Controller +CONFIG_BT_LL_SW_SPLIT=y +CONFIG_BT_CTLR_ASSERT_HANDLER=y +CONFIG_BT_CTLR_DTM_HCI=y + +# Rx ACL and Adv Reports +CONFIG_BT_CTLR_RX_BUFFERS=9 +CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 + +# Coded PHY support +CONFIG_BT_CTLR_PHY_CODED=n + +# Advertising Sets and Extended Scanning +CONFIG_BT_CTLR_ADV_EXT=y +CONFIG_BT_CTLR_ADV_SET=3 +CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=191 +CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 + +CONFIG_BT_CTLR_ADVANCED_FEATURES=y +CONFIG_BT_CTLR_ADV_AUX_SET=3 +CONFIG_BT_CTLR_ADV_AUX_PDU_BACK2BACK=y +CONFIG_BT_CTLR_ADV_SYNC_SET=3 +CONFIG_BT_CTLR_ADV_SYNC_PDU_BACK2BACK=y +CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=6 + +# Increase the below to receive interleaved advertising chains +CONFIG_BT_CTLR_SCAN_AUX_SET=1 + +CONFIG_BT_CTLR_ADV_RESERVE_MAX=n +CONFIG_BT_CTLR_CENTRAL_RESERVE_MAX=n +# CONFIG_BT_CTLR_CENTRAL_SPACING=10000 +CONFIG_BT_CTLR_CENTRAL_SPACING=0 +CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE=n +CONFIG_BT_CTLR_SCAN_UNRESERVED=n +CONFIG_BT_TICKER_NEXT_SLOT_GET_MATCH=y +CONFIG_BT_TICKER_EXT=y +CONFIG_BT_TICKER_EXT_SLOT_WINDOW_YIELD=y + +# Control Procedure +CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=9 + +# ISO Broadcaster Controller +CONFIG_BT_CTLR_ADV_EXT=y +CONFIG_BT_CTLR_ADV_PERIODIC=y +CONFIG_BT_CTLR_ADV_ISO=y +CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX=251 +CONFIG_BT_CTLR_ADV_ISO_STREAM_MAX=2 + +# ISO Receive Controller +CONFIG_BT_CTLR_ADV_EXT=y +CONFIG_BT_CTLR_SYNC_PERIODIC=y +CONFIG_BT_CTLR_SYNC_ISO=y +CONFIG_BT_CTLR_SYNC_ISO_PDU_LEN_MAX=251 +CONFIG_BT_CTLR_SYNC_ISO_STREAM_MAX=2 + +# ISO Connection Oriented +CONFIG_BT_CTLR_CENTRAL_ISO=y +CONFIG_BT_CTLR_PERIPHERAL_ISO=y +CONFIG_BT_CTLR_CONN_ISO_SDU_LEN_MAX=251 +CONFIG_BT_CTLR_CONN_ISO_PDU_LEN_MAX=251 +CONFIG_BT_CTLR_CONN_ISO_STREAMS=4 +CONFIG_BT_CTLR_CONN_ISO_STREAMS_PER_GROUP=4 + +# ISO Transmissions +CONFIG_BT_CTLR_ISO_TX_BUFFERS=18 +CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=251 +CONFIG_BT_CTLR_ISOAL_SOURCES=4 + +# ISO Receptions +CONFIG_BT_CTLR_ISO_RX_BUFFERS=8 +CONFIG_BT_CTLR_ISOAL_SINKS=4 + +# Tx Power Dynamic Control +CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y From 2076afcd51b67a313fd5813bb74efe7ebe313c7e Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 29 Nov 2023 16:50:37 +0100 Subject: [PATCH 0975/1623] [nrf fromtree] sysbuild: Add extensions for native_simulator based targets Add 3 new functions to perform functions typically needed for native_simulator based targes and reduce the amount of boilerplate. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 94cdfa60dc17cd4fea77f73b9654e0c0f3263175) Signed-off-by: Dominik Ermel --- share/sysbuild/CMakeLists.txt | 7 ++- .../native_simulator_sb_extensions.cmake | 62 +++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 share/sysbuild/cmake/modules/native_simulator_sb_extensions.cmake diff --git a/share/sysbuild/CMakeLists.txt b/share/sysbuild/CMakeLists.txt index 7bbfe138760..8a15da9cef5 100644 --- a/share/sysbuild/CMakeLists.txt +++ b/share/sysbuild/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2023 Nordic Semiconductor +# Copyright (c) 2023 Nordic Semiconductor # # SPDX-License-Identifier: Apache-2.0 @@ -18,7 +18,10 @@ set(APP_DIR ${APP_DIR} CACHE PATH "Main Application Source Directory") list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/modules) # List of Zephyr and sysbuild CMake modules we need for sysbuild. # Note: sysbuild_kconfig will internally load kconfig CMake module. -set(zephyr_modules extensions sysbuild_extensions python west root zephyr_module boards shields sysbuild_kconfig) +set(zephyr_modules extensions + sysbuild_extensions python west root zephyr_module boards shields + sysbuild_kconfig native_simulator_sb_extensions + ) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS ${zephyr_modules}) diff --git a/share/sysbuild/cmake/modules/native_simulator_sb_extensions.cmake b/share/sysbuild/cmake/modules/native_simulator_sb_extensions.cmake new file mode 100644 index 00000000000..3d888d1775e --- /dev/null +++ b/share/sysbuild/cmake/modules/native_simulator_sb_extensions.cmake @@ -0,0 +1,62 @@ +# Copyright (c) 2023 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 + +# Usage: +# native_simulator_set_final_executable() +# +# When building for a native_simulator based target (including bsim targets), +# this function adds an extra build target which will copy the executable produced by +# `` to the top level, as zephyr/zephyr.exe +# +# This final image is expected to have been set to assemble other dependent images into +# itself if necessary, by calling native_simulator_set_child_images() +# This will allow other tools, like twister, or the bsim test scripts, as well as users to find +# this final executable in the same place as for non-sysbuild builds. +# +function(native_simulator_set_final_executable final_image) + if(("${BOARD}" MATCHES "native") OR ("${BOARD}" MATCHES "bsim")) + add_custom_target(final_executable + ALL + COMMAND + ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/${final_image}/zephyr/zephyr.exe + ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe + DEPENDS ${final_image} + ) + endif() +endfunction() + +# Usage: +# native_simulator_set_child_images( ) +# +# When building for a native_simulator based target (including bsim targets), +# this function sets a `` as dependencies of `` +# and configures the final image to assemble the child images into its final executable. +# +function(native_simulator_set_child_images final_image child_image) + if(("${BOARD}" MATCHES "native") OR ("${BOARD}" MATCHES "bsim")) + add_dependencies(${final_image} ${child_image}) + + set(CHILD_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${child_image}/zephyr/zephyr.elf) + set_property(TARGET ${final_image} APPEND_STRING PROPERTY CONFIG + "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${CHILD_LIBRARY_PATH}\"\n" + ) + endif() +endfunction() + +# Usage: +# native_simulator_set_primary_mcu_index( [ ...]) +# +# Propagate the SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX setting, +# if it is set, to each given image CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX +# +function(native_simulator_set_primary_mcu_index) + if (NOT ("${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}" STREQUAL "")) + foreach(arg IN LISTS ARGV) + set_property(TARGET ${arg} APPEND_STRING PROPERTY CONFIG + "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" + ) + endforeach() + endif() +endfunction() From c4fefa79ee03bf2c4b9c8d49012c50888ae43e09 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 29 Nov 2023 18:44:30 +0100 Subject: [PATCH 0976/1623] [nrf fromtree] samples/bluetooth: Reduce sysbuild boilerplate Reduce the sysbuild boilerplate required for the nrf5340bsim targets. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 8b70d98dcb1eb4f24ea5971cf81204f942c2804e) Signed-off-by: Dominik Ermel --- .../broadcast_audio_sink/sysbuild.cmake | 24 ++----------------- .../broadcast_audio_source/sysbuild.cmake | 24 ++----------------- .../unicast_audio_client/sysbuild.cmake | 24 ++----------------- .../unicast_audio_server/sysbuild.cmake | 24 ++----------------- 4 files changed, 8 insertions(+), 88 deletions(-) diff --git a/samples/bluetooth/broadcast_audio_sink/sysbuild.cmake b/samples/bluetooth/broadcast_audio_sink/sysbuild.cmake index ed30d7f31f3..2523aac8ea7 100644 --- a/samples/bluetooth/broadcast_audio_sink/sysbuild.cmake +++ b/samples/bluetooth/broadcast_audio_sink/sysbuild.cmake @@ -18,27 +18,7 @@ if(SB_CONFIG_NET_CORE_IMAGE_HCI_IPC) CACHE INTERNAL "" ) - # Let's build the net core library first - add_dependencies(${DEFAULT_IMAGE} ${NET_APP}) - - if("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp") - # For the simulated board, the application core build will produce the final executable - # for that, we give it the path to the netcore image - set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${NET_APP}/zephyr/zephyr.elf) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" - ) - endif() + native_simulator_set_child_images(${DEFAULT_IMAGE} ${NET_APP}) endif() -if(("${BOARD}" MATCHES "native") OR ("${BOARD}" MATCHES "bsim")) - # Let's meet the expectation of finding the final executable in zephyr/zephyr.exe - add_custom_target(final_executable - ALL - COMMAND - ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe - ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe - DEPENDS ${DEFAULT_IMAGE} - ) -endif() +native_simulator_set_final_executable(${DEFAULT_IMAGE}) diff --git a/samples/bluetooth/broadcast_audio_source/sysbuild.cmake b/samples/bluetooth/broadcast_audio_source/sysbuild.cmake index ed30d7f31f3..2523aac8ea7 100644 --- a/samples/bluetooth/broadcast_audio_source/sysbuild.cmake +++ b/samples/bluetooth/broadcast_audio_source/sysbuild.cmake @@ -18,27 +18,7 @@ if(SB_CONFIG_NET_CORE_IMAGE_HCI_IPC) CACHE INTERNAL "" ) - # Let's build the net core library first - add_dependencies(${DEFAULT_IMAGE} ${NET_APP}) - - if("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp") - # For the simulated board, the application core build will produce the final executable - # for that, we give it the path to the netcore image - set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${NET_APP}/zephyr/zephyr.elf) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" - ) - endif() + native_simulator_set_child_images(${DEFAULT_IMAGE} ${NET_APP}) endif() -if(("${BOARD}" MATCHES "native") OR ("${BOARD}" MATCHES "bsim")) - # Let's meet the expectation of finding the final executable in zephyr/zephyr.exe - add_custom_target(final_executable - ALL - COMMAND - ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe - ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe - DEPENDS ${DEFAULT_IMAGE} - ) -endif() +native_simulator_set_final_executable(${DEFAULT_IMAGE}) diff --git a/samples/bluetooth/unicast_audio_client/sysbuild.cmake b/samples/bluetooth/unicast_audio_client/sysbuild.cmake index ed30d7f31f3..2523aac8ea7 100644 --- a/samples/bluetooth/unicast_audio_client/sysbuild.cmake +++ b/samples/bluetooth/unicast_audio_client/sysbuild.cmake @@ -18,27 +18,7 @@ if(SB_CONFIG_NET_CORE_IMAGE_HCI_IPC) CACHE INTERNAL "" ) - # Let's build the net core library first - add_dependencies(${DEFAULT_IMAGE} ${NET_APP}) - - if("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp") - # For the simulated board, the application core build will produce the final executable - # for that, we give it the path to the netcore image - set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${NET_APP}/zephyr/zephyr.elf) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" - ) - endif() + native_simulator_set_child_images(${DEFAULT_IMAGE} ${NET_APP}) endif() -if(("${BOARD}" MATCHES "native") OR ("${BOARD}" MATCHES "bsim")) - # Let's meet the expectation of finding the final executable in zephyr/zephyr.exe - add_custom_target(final_executable - ALL - COMMAND - ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe - ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe - DEPENDS ${DEFAULT_IMAGE} - ) -endif() +native_simulator_set_final_executable(${DEFAULT_IMAGE}) diff --git a/samples/bluetooth/unicast_audio_server/sysbuild.cmake b/samples/bluetooth/unicast_audio_server/sysbuild.cmake index ed30d7f31f3..2523aac8ea7 100644 --- a/samples/bluetooth/unicast_audio_server/sysbuild.cmake +++ b/samples/bluetooth/unicast_audio_server/sysbuild.cmake @@ -18,27 +18,7 @@ if(SB_CONFIG_NET_CORE_IMAGE_HCI_IPC) CACHE INTERNAL "" ) - # Let's build the net core library first - add_dependencies(${DEFAULT_IMAGE} ${NET_APP}) - - if("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp") - # For the simulated board, the application core build will produce the final executable - # for that, we give it the path to the netcore image - set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${NET_APP}/zephyr/zephyr.elf) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" - ) - endif() + native_simulator_set_child_images(${DEFAULT_IMAGE} ${NET_APP}) endif() -if(("${BOARD}" MATCHES "native") OR ("${BOARD}" MATCHES "bsim")) - # Let's meet the expectation of finding the final executable in zephyr/zephyr.exe - add_custom_target(final_executable - ALL - COMMAND - ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe - ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe - DEPENDS ${DEFAULT_IMAGE} - ) -endif() +native_simulator_set_final_executable(${DEFAULT_IMAGE}) From 273508cf01151f3ab8d13e4df580f0b941fdcdeb Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 29 Nov 2023 18:46:21 +0100 Subject: [PATCH 0977/1623] [nrf fromtree] tests/bsim/bluetooth: Reduce sysbuild boilerplate Reduce the sysbuild boilerplate required for the nrf5340bsim targets. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 41f4826f272ae38dd1043bfda0c38cc8b6e7128f) Signed-off-by: Dominik Ermel --- .../broadcast_audio_sink/sysbuild.cmake | 9 +----- .../unicast_audio_client/sysbuild.cmake | 9 +----- tests/bsim/bluetooth/ll/bis/sysbuild.cmake | 29 ++----------------- tests/bsim/bluetooth/ll/cis/sysbuild.cmake | 29 ++----------------- tests/bsim/bluetooth/ll/conn/sysbuild.cmake | 29 ++----------------- 5 files changed, 11 insertions(+), 94 deletions(-) diff --git a/tests/bsim/bluetooth/audio_samples/broadcast_audio_sink/sysbuild.cmake b/tests/bsim/bluetooth/audio_samples/broadcast_audio_sink/sysbuild.cmake index a922830546d..2bf2920a476 100644 --- a/tests/bsim/bluetooth/audio_samples/broadcast_audio_sink/sysbuild.cmake +++ b/tests/bsim/bluetooth/audio_samples/broadcast_audio_sink/sysbuild.cmake @@ -3,11 +3,4 @@ include(${ZEPHYR_BASE}/samples/bluetooth/broadcast_audio_sink/sysbuild.cmake) -if (NOT ("${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}" STREQUAL "")) - set_property(TARGET ${NET_APP} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" - ) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" - ) -endif() +native_simulator_set_primary_mcu_index(${DEFAULT_IMAGE} ${NET_APP}) diff --git a/tests/bsim/bluetooth/audio_samples/unicast_audio_client/sysbuild.cmake b/tests/bsim/bluetooth/audio_samples/unicast_audio_client/sysbuild.cmake index 9686cde1bce..85b85b7cb63 100644 --- a/tests/bsim/bluetooth/audio_samples/unicast_audio_client/sysbuild.cmake +++ b/tests/bsim/bluetooth/audio_samples/unicast_audio_client/sysbuild.cmake @@ -3,11 +3,4 @@ include(${ZEPHYR_BASE}/samples/bluetooth/unicast_audio_client/sysbuild.cmake) -if (NOT ("${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}" STREQUAL "")) - set_property(TARGET ${NET_APP} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" - ) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" - ) -endif() +native_simulator_set_primary_mcu_index(${DEFAULT_IMAGE} ${NET_APP}) diff --git a/tests/bsim/bluetooth/ll/bis/sysbuild.cmake b/tests/bsim/bluetooth/ll/bis/sysbuild.cmake index eb75debccd3..69397264edf 100644 --- a/tests/bsim/bluetooth/ll/bis/sysbuild.cmake +++ b/tests/bsim/bluetooth/ll/bis/sysbuild.cmake @@ -16,32 +16,9 @@ if(NOT("${SB_CONFIG_NET_CORE_BOARD}" STREQUAL "")) CACHE INTERNAL "" ) - # For the simulated board, the application core build will produce the final executable - # for that, we give it the path to the netcore image - set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${NET_APP}/zephyr/zephyr.elf) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" - ) - - if (NOT ("${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}" STREQUAL "")) - set_property(TARGET ${NET_APP} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" - ) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" - ) - endif() + native_simulator_set_primary_mcu_index(${DEFAULT_IMAGE} ${NET_APP}) - # Let's build the net core library first - add_dependencies(${DEFAULT_IMAGE} ${NET_APP}) + native_simulator_set_child_images(${DEFAULT_IMAGE} ${NET_APP}) endif() -# Let's meet the expectation of finding the final executable in zephyr/zephyr.exe -add_custom_target(final_executable - ALL - COMMAND - ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe - ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe - DEPENDS ${DEFAULT_IMAGE} -) +native_simulator_set_final_executable(${DEFAULT_IMAGE}) diff --git a/tests/bsim/bluetooth/ll/cis/sysbuild.cmake b/tests/bsim/bluetooth/ll/cis/sysbuild.cmake index 495c3f4a20d..a1258ecf1f2 100644 --- a/tests/bsim/bluetooth/ll/cis/sysbuild.cmake +++ b/tests/bsim/bluetooth/ll/cis/sysbuild.cmake @@ -16,32 +16,9 @@ if(NOT("${SB_CONFIG_NET_CORE_BOARD}" STREQUAL "")) CACHE INTERNAL "" ) - # For the simulated board, the application core build will produce the final executable - # for that, we give it the path to the netcore image - set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${NET_APP}/zephyr/zephyr.elf) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" - ) - - if (NOT ("${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}" STREQUAL "")) - set_property(TARGET ${NET_APP} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" - ) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" - ) - endif() + native_simulator_set_primary_mcu_index(${DEFAULT_IMAGE} ${NET_APP}) - # Let's build the net core library first - add_dependencies(${DEFAULT_IMAGE} ${NET_APP}) + native_simulator_set_child_images(${DEFAULT_IMAGE} ${NET_APP}) endif() -# Let's meet the expectation of finding the final executable in zephyr/zephyr.exe -add_custom_target(final_executable - ALL - COMMAND - ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe - ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe - DEPENDS ${DEFAULT_IMAGE} -) +native_simulator_set_final_executable(${DEFAULT_IMAGE}) diff --git a/tests/bsim/bluetooth/ll/conn/sysbuild.cmake b/tests/bsim/bluetooth/ll/conn/sysbuild.cmake index 2294fd5bb5e..4dfa34ef519 100644 --- a/tests/bsim/bluetooth/ll/conn/sysbuild.cmake +++ b/tests/bsim/bluetooth/ll/conn/sysbuild.cmake @@ -11,32 +11,9 @@ if(NOT("${SB_CONFIG_NET_CORE_BOARD}" STREQUAL "")) BOARD ${SB_CONFIG_NET_CORE_BOARD} ) - # For the simulated board, the application core build will produce the final executable - # for that, we give it the path to the netcore image - set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${NET_APP}/zephyr/zephyr.elf) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" - ) - - if (NOT ("${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}" STREQUAL "")) - set_property(TARGET ${NET_APP} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" - ) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX=${SB_CONFIG_NATIVE_SIMULATOR_PRIMARY_MCU_INDEX}\n" - ) - endif() + native_simulator_set_primary_mcu_index(${DEFAULT_IMAGE} ${NET_APP}) - # Let's build the net core library first - add_dependencies(${DEFAULT_IMAGE} ${NET_APP}) + native_simulator_set_child_images(${DEFAULT_IMAGE} ${NET_APP}) endif() -# Let's meet the expectation of finding the final executable in zephyr/zephyr.exe -add_custom_target(final_executable - ALL - COMMAND - ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe - ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe - DEPENDS ${DEFAULT_IMAGE} -) +native_simulator_set_final_executable(${DEFAULT_IMAGE}) From bbbf671ef88cdf8c3b064fc79a38eec317a780c6 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 29 Nov 2023 18:46:52 +0100 Subject: [PATCH 0978/1623] [nrf fromtree] samples/subsys/logging/multidomain: Reduce sysbuild boilerplate Reduce the sysbuild boilerplate required for the nrf5340bsim targets Signed-off-by: Alberto Escolar Piedras (cherry picked from commit b02fc27464c46076a62e2401e51ce7ae0302de95) Signed-off-by: Dominik Ermel --- .../subsys/logging/multidomain/sysbuild.cmake | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/samples/subsys/logging/multidomain/sysbuild.cmake b/samples/subsys/logging/multidomain/sysbuild.cmake index e50f47b6db1..496a7a03f9d 100644 --- a/samples/subsys/logging/multidomain/sysbuild.cmake +++ b/samples/subsys/logging/multidomain/sysbuild.cmake @@ -15,24 +15,6 @@ ExternalZephyrProject_Add( BOARD ${SB_CONFIG_NET_CORE_BOARD} ) -if("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp") - # For the simulated board, the application core build will produce the final executable - # for that, we give it the path to the netcore image - set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${NET_APP}/zephyr/zephyr.elf) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" - ) +native_simulator_set_child_images(${DEFAULT_IMAGE} ${NET_APP}) - # Let's build the net core library first - add_dependencies(${DEFAULT_IMAGE} ${NET_APP}) - - # Let's meet users expectations of finding the final executable in zephyr/zephyr.exe - add_custom_target(final_executable - ALL - COMMAND - ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe - ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe - DEPENDS ${DEFAULT_IMAGE} - ) -endif() +native_simulator_set_final_executable(${DEFAULT_IMAGE}) From e4b78eddab9555b80726f00dfae9139f7f85cc35 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 29 Nov 2023 18:47:45 +0100 Subject: [PATCH 0979/1623] [nrf fromtree] samples/boards/nrf/nrf53_sync_rtc: Reduce sysbuild boilerplate Reduce the sysbuild boilerplate required for the nrf5340bsim targets Signed-off-by: Alberto Escolar Piedras (cherry picked from commit cbce3383d1e7cbdb23c6caac6d1bf9a5d8236091) Signed-off-by: Dominik Ermel --- .../boards/nrf/nrf53_sync_rtc/sysbuild.cmake | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/samples/boards/nrf/nrf53_sync_rtc/sysbuild.cmake b/samples/boards/nrf/nrf53_sync_rtc/sysbuild.cmake index a5d1eb9874f..0c97244fd7b 100644 --- a/samples/boards/nrf/nrf53_sync_rtc/sysbuild.cmake +++ b/samples/boards/nrf/nrf53_sync_rtc/sysbuild.cmake @@ -15,24 +15,6 @@ ExternalZephyrProject_Add( BOARD ${SB_CONFIG_NET_CORE_BOARD} ) -if("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp") - # For the simulated board, the application core build will produce the final executable - # for that, we give it the path to the netcore image - set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${REMOTE_APP}/zephyr/zephyr.elf) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" - ) +native_simulator_set_child_images(${DEFAULT_IMAGE} ${REMOTE_APP}) - # Let's build the net core library first - add_dependencies(${DEFAULT_IMAGE} ${REMOTE_APP}) - - # Let's meet users expectations of finding the final executable in zephyr/zephyr.exe - add_custom_target(final_executable - ALL - COMMAND - ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe - ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe - DEPENDS ${DEFAULT_IMAGE} - ) -endif() +native_simulator_set_final_executable(${DEFAULT_IMAGE}) From ab3ed158d57b033b08ed76952e3112b9802c7d67 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 29 Nov 2023 18:48:02 +0100 Subject: [PATCH 0980/1623] [nrf fromtree] samples/drivers/mbox: Reduce sysbuild boilerplate Reduce the sysbuild boilerplate required for the nrf5340bsim targets Signed-off-by: Alberto Escolar Piedras (cherry picked from commit d2151aa114cbf389fdec972119b218f7b39f3c9b) Signed-off-by: Dominik Ermel --- samples/drivers/mbox/sysbuild.cmake | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/samples/drivers/mbox/sysbuild.cmake b/samples/drivers/mbox/sysbuild.cmake index 1bd6a00ae9e..a8dfb8ebdf4 100644 --- a/samples/drivers/mbox/sysbuild.cmake +++ b/samples/drivers/mbox/sysbuild.cmake @@ -15,24 +15,6 @@ ExternalZephyrProject_Add( BOARD ${SB_CONFIG_REMOTE_BOARD} ) -if("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp") - # For the simulated board, the application core build will produce the final executable - # for that, we give it the path to the netcore image - set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${REMOTE_APP}/zephyr/zephyr.elf) - set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG - "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" - ) +native_simulator_set_child_images(${DEFAULT_IMAGE} ${REMOTE_APP}) - # Let's build the net core library first - add_dependencies(${DEFAULT_IMAGE} ${REMOTE_APP}) - - # Let's meet users expectations of finding the final executable in zephyr/zephyr.exe - add_custom_target(final_executable - ALL - COMMAND - ${CMAKE_COMMAND} -E copy - ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe - ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe - DEPENDS ${DEFAULT_IMAGE} - ) -endif() +native_simulator_set_final_executable(${DEFAULT_IMAGE}) From 53f7c555705ef394fbbf154770c6be493c23ded4 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 15 Dec 2023 07:57:14 +0000 Subject: [PATCH 0981/1623] [nrf noup] samples/tests: Disable PM for some sysbuild builds Disables partition manager when building some samples and tests which use sysbuild to prevent build issues Signed-off-by: Jamie McCrae --- samples/boards/nrf/nrf53_sync_rtc/sysbuild.conf | 1 + samples/drivers/mbox/sysbuild.conf | 1 + samples/subsys/ipc/ipc_service/icmsg/sysbuild.conf | 1 + samples/subsys/ipc/ipc_service/multi_endpoint/sysbuild.conf | 1 + samples/subsys/ipc/ipc_service/static_vrings/sysbuild.conf | 1 + samples/subsys/logging/multidomain/sysbuild.conf | 1 + tests/boot/mcuboot_recovery_retention/sysbuild.conf | 1 + tests/boot/test_mcuboot/sysbuild.conf | 1 + 8 files changed, 8 insertions(+) create mode 100644 samples/boards/nrf/nrf53_sync_rtc/sysbuild.conf create mode 100644 samples/drivers/mbox/sysbuild.conf create mode 100644 samples/subsys/ipc/ipc_service/icmsg/sysbuild.conf create mode 100644 samples/subsys/ipc/ipc_service/multi_endpoint/sysbuild.conf create mode 100644 samples/subsys/ipc/ipc_service/static_vrings/sysbuild.conf create mode 100644 samples/subsys/logging/multidomain/sysbuild.conf diff --git a/samples/boards/nrf/nrf53_sync_rtc/sysbuild.conf b/samples/boards/nrf/nrf53_sync_rtc/sysbuild.conf new file mode 100644 index 00000000000..6408669a847 --- /dev/null +++ b/samples/boards/nrf/nrf53_sync_rtc/sysbuild.conf @@ -0,0 +1 @@ +SB_CONFIG_PARTITION_MANAGER=n diff --git a/samples/drivers/mbox/sysbuild.conf b/samples/drivers/mbox/sysbuild.conf new file mode 100644 index 00000000000..6408669a847 --- /dev/null +++ b/samples/drivers/mbox/sysbuild.conf @@ -0,0 +1 @@ +SB_CONFIG_PARTITION_MANAGER=n diff --git a/samples/subsys/ipc/ipc_service/icmsg/sysbuild.conf b/samples/subsys/ipc/ipc_service/icmsg/sysbuild.conf new file mode 100644 index 00000000000..6408669a847 --- /dev/null +++ b/samples/subsys/ipc/ipc_service/icmsg/sysbuild.conf @@ -0,0 +1 @@ +SB_CONFIG_PARTITION_MANAGER=n diff --git a/samples/subsys/ipc/ipc_service/multi_endpoint/sysbuild.conf b/samples/subsys/ipc/ipc_service/multi_endpoint/sysbuild.conf new file mode 100644 index 00000000000..6408669a847 --- /dev/null +++ b/samples/subsys/ipc/ipc_service/multi_endpoint/sysbuild.conf @@ -0,0 +1 @@ +SB_CONFIG_PARTITION_MANAGER=n diff --git a/samples/subsys/ipc/ipc_service/static_vrings/sysbuild.conf b/samples/subsys/ipc/ipc_service/static_vrings/sysbuild.conf new file mode 100644 index 00000000000..6408669a847 --- /dev/null +++ b/samples/subsys/ipc/ipc_service/static_vrings/sysbuild.conf @@ -0,0 +1 @@ +SB_CONFIG_PARTITION_MANAGER=n diff --git a/samples/subsys/logging/multidomain/sysbuild.conf b/samples/subsys/logging/multidomain/sysbuild.conf new file mode 100644 index 00000000000..6408669a847 --- /dev/null +++ b/samples/subsys/logging/multidomain/sysbuild.conf @@ -0,0 +1 @@ +SB_CONFIG_PARTITION_MANAGER=n diff --git a/tests/boot/mcuboot_recovery_retention/sysbuild.conf b/tests/boot/mcuboot_recovery_retention/sysbuild.conf index 47f00ff3cff..3b5b3c96380 100644 --- a/tests/boot/mcuboot_recovery_retention/sysbuild.conf +++ b/tests/boot/mcuboot_recovery_retention/sysbuild.conf @@ -1 +1,2 @@ SB_CONFIG_BOOTLOADER_MCUBOOT=y +SB_CONFIG_PARTITION_MANAGER=n diff --git a/tests/boot/test_mcuboot/sysbuild.conf b/tests/boot/test_mcuboot/sysbuild.conf index 47f00ff3cff..3b5b3c96380 100644 --- a/tests/boot/test_mcuboot/sysbuild.conf +++ b/tests/boot/test_mcuboot/sysbuild.conf @@ -1 +1,2 @@ SB_CONFIG_BOOTLOADER_MCUBOOT=y +SB_CONFIG_PARTITION_MANAGER=n From 4a03d8a097843a324fe7746fb5383476b341671a Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 13 Dec 2023 15:46:45 +0200 Subject: [PATCH 0982/1623] [nrf fromtree] net: shell: Rename the common.h to be more unique As the common.h is only meant to be used by the network shell files, rename it to be more descriptive in order to avoid possible conflicts with any other common.h file. Signed-off-by: Jukka Rissanen (cherry picked from commit 477a4a5d34042f49830fc8aff94ffc16a98cce10) --- subsys/net/lib/shell/allocs.c | 2 +- subsys/net/lib/shell/arp.c | 2 +- subsys/net/lib/shell/capture.c | 2 +- subsys/net/lib/shell/conn.c | 2 +- subsys/net/lib/shell/dns.c | 2 +- subsys/net/lib/shell/events.c | 2 +- subsys/net/lib/shell/gptp.c | 2 +- subsys/net/lib/shell/iface.c | 2 +- subsys/net/lib/shell/ipv4.c | 2 +- subsys/net/lib/shell/ipv6.c | 2 +- subsys/net/lib/shell/mem.c | 2 +- subsys/net/lib/shell/nbr.c | 2 +- subsys/net/lib/shell/net_shell.c | 2 +- subsys/net/lib/shell/{common.h => net_shell_private.h} | 0 subsys/net/lib/shell/ping.c | 2 +- subsys/net/lib/shell/pkt.c | 2 +- subsys/net/lib/shell/ppp.c | 2 +- subsys/net/lib/shell/resume.c | 2 +- subsys/net/lib/shell/route.c | 2 +- subsys/net/lib/shell/sockets.c | 2 +- subsys/net/lib/shell/stats.c | 2 +- subsys/net/lib/shell/suspend.c | 2 +- subsys/net/lib/shell/tcp.c | 2 +- subsys/net/lib/shell/udp.c | 2 +- subsys/net/lib/shell/virtual.c | 2 +- subsys/net/lib/shell/vlan.c | 2 +- subsys/net/lib/shell/websocket.c | 2 +- 27 files changed, 26 insertions(+), 26 deletions(-) rename subsys/net/lib/shell/{common.h => net_shell_private.h} (100%) diff --git a/subsys/net/lib/shell/allocs.c b/subsys/net/lib/shell/allocs.c index 1c6e7288003..a2669590520 100644 --- a/subsys/net/lib/shell/allocs.c +++ b/subsys/net/lib/shell/allocs.c @@ -8,7 +8,7 @@ #include LOG_MODULE_DECLARE(net_shell); -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) static void allocs_cb(struct net_pkt *pkt, diff --git a/subsys/net/lib/shell/arp.c b/subsys/net/lib/shell/arp.c index fb1582411e9..58889f27d5c 100644 --- a/subsys/net/lib/shell/arp.c +++ b/subsys/net/lib/shell/arp.c @@ -8,7 +8,7 @@ #include LOG_MODULE_DECLARE(net_shell); -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_NET_ARP) #include "ethernet/arp.h" diff --git a/subsys/net/lib/shell/capture.c b/subsys/net/lib/shell/capture.c index f05531562ae..0c7347f8774 100644 --- a/subsys/net/lib/shell/capture.c +++ b/subsys/net/lib/shell/capture.c @@ -10,7 +10,7 @@ LOG_MODULE_DECLARE(net_shell); #include -#include "common.h" +#include "net_shell_private.h" #include diff --git a/subsys/net/lib/shell/conn.c b/subsys/net/lib/shell/conn.c index 36831809eb8..24b528537bd 100644 --- a/subsys/net/lib/shell/conn.c +++ b/subsys/net/lib/shell/conn.c @@ -8,7 +8,7 @@ #include LOG_MODULE_DECLARE(net_shell); -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_NET_TCP) #include "tcp_internal.h" diff --git a/subsys/net/lib/shell/dns.c b/subsys/net/lib/shell/dns.c index 24a52f5e8a2..54c768cecd1 100644 --- a/subsys/net/lib/shell/dns.c +++ b/subsys/net/lib/shell/dns.c @@ -10,7 +10,7 @@ LOG_MODULE_DECLARE(net_shell); #include -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_DNS_RESOLVER) static void dns_result_cb(enum dns_resolve_status status, diff --git a/subsys/net/lib/shell/events.c b/subsys/net/lib/shell/events.c index 047fd1e2186..5a5d0f38f7d 100644 --- a/subsys/net/lib/shell/events.c +++ b/subsys/net/lib/shell/events.c @@ -13,7 +13,7 @@ LOG_MODULE_DECLARE(net_shell); #include #include -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_NET_MGMT_EVENT_MONITOR) #define EVENT_MON_STACK_SIZE 1024 diff --git a/subsys/net/lib/shell/gptp.c b/subsys/net/lib/shell/gptp.c index a156637e3af..0de653e26cd 100644 --- a/subsys/net/lib/shell/gptp.c +++ b/subsys/net/lib/shell/gptp.c @@ -19,7 +19,7 @@ LOG_MODULE_DECLARE(net_shell); #include "ethernet/gptp/gptp_private.h" #endif -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_NET_GPTP) static const char *selected_role_str(int port); diff --git a/subsys/net/lib/shell/iface.c b/subsys/net/lib/shell/iface.c index 89983bd4839..53d4e99bd21 100644 --- a/subsys/net/lib/shell/iface.c +++ b/subsys/net/lib/shell/iface.c @@ -18,7 +18,7 @@ LOG_MODULE_DECLARE(net_shell); #include #endif -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_NET_L2_ETHERNET) && defined(CONFIG_NET_NATIVE) struct ethernet_capabilities { diff --git a/subsys/net/lib/shell/ipv4.c b/subsys/net/lib/shell/ipv4.c index 8fc88168c9a..e8584b205fb 100644 --- a/subsys/net/lib/shell/ipv4.c +++ b/subsys/net/lib/shell/ipv4.c @@ -10,7 +10,7 @@ LOG_MODULE_DECLARE(net_shell); #include -#include "common.h" +#include "net_shell_private.h" #include "../ip/ipv4.h" #if defined(CONFIG_NET_NATIVE_IPV4) diff --git a/subsys/net/lib/shell/ipv6.c b/subsys/net/lib/shell/ipv6.c index f81b8dcae23..04efda65d0f 100644 --- a/subsys/net/lib/shell/ipv6.c +++ b/subsys/net/lib/shell/ipv6.c @@ -8,7 +8,7 @@ #include LOG_MODULE_DECLARE(net_shell); -#include "common.h" +#include "net_shell_private.h" #include "../ip/ipv6.h" #if defined(CONFIG_NET_IPV6_FRAGMENT) diff --git a/subsys/net/lib/shell/mem.c b/subsys/net/lib/shell/mem.c index cf58cda6bd6..47058f92767 100644 --- a/subsys/net/lib/shell/mem.c +++ b/subsys/net/lib/shell/mem.c @@ -8,7 +8,7 @@ #include LOG_MODULE_DECLARE(net_shell); -#include "common.h" +#include "net_shell_private.h" struct ctx_info { int pos; diff --git a/subsys/net/lib/shell/nbr.c b/subsys/net/lib/shell/nbr.c index fd420b818ae..63b62406702 100644 --- a/subsys/net/lib/shell/nbr.c +++ b/subsys/net/lib/shell/nbr.c @@ -8,7 +8,7 @@ #include LOG_MODULE_DECLARE(net_shell); -#include "common.h" +#include "net_shell_private.h" static int cmd_net_nbr_rm(const struct shell *sh, size_t argc, char *argv[]) { diff --git a/subsys/net/lib/shell/net_shell.c b/subsys/net/lib/shell/net_shell.c index 19bab12e029..9f932cb1bc4 100644 --- a/subsys/net/lib/shell/net_shell.c +++ b/subsys/net/lib/shell/net_shell.c @@ -20,7 +20,7 @@ LOG_MODULE_REGISTER(net_shell, LOG_LEVEL_DBG); #include -#include "common.h" +#include "net_shell_private.h" #include "net_shell.h" int get_iface_idx(const struct shell *sh, char *index_str) diff --git a/subsys/net/lib/shell/common.h b/subsys/net/lib/shell/net_shell_private.h similarity index 100% rename from subsys/net/lib/shell/common.h rename to subsys/net/lib/shell/net_shell_private.h diff --git a/subsys/net/lib/shell/ping.c b/subsys/net/lib/shell/ping.c index 8b52df110be..833c6eb8d54 100644 --- a/subsys/net/lib/shell/ping.c +++ b/subsys/net/lib/shell/ping.c @@ -13,7 +13,7 @@ LOG_MODULE_DECLARE(net_shell); #include #include -#include "common.h" +#include "net_shell_private.h" #include "../ip/icmpv6.h" #include "../ip/icmpv4.h" diff --git a/subsys/net/lib/shell/pkt.c b/subsys/net/lib/shell/pkt.c index 09d7ae6738a..3306b05d1a7 100644 --- a/subsys/net/lib/shell/pkt.c +++ b/subsys/net/lib/shell/pkt.c @@ -8,7 +8,7 @@ #include LOG_MODULE_DECLARE(net_shell); -#include "common.h" +#include "net_shell_private.h" static bool is_pkt_part_of_slab(const struct k_mem_slab *slab, const char *ptr) { diff --git a/subsys/net/lib/shell/ppp.c b/subsys/net/lib/shell/ppp.c index 9b5f8355d47..f63c6ca3324 100644 --- a/subsys/net/lib/shell/ppp.c +++ b/subsys/net/lib/shell/ppp.c @@ -10,7 +10,7 @@ LOG_MODULE_DECLARE(net_shell); #include -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_NET_L2_PPP) #include diff --git a/subsys/net/lib/shell/resume.c b/subsys/net/lib/shell/resume.c index 585d421efab..dcd3fbf309d 100644 --- a/subsys/net/lib/shell/resume.c +++ b/subsys/net/lib/shell/resume.c @@ -9,7 +9,7 @@ #include LOG_MODULE_DECLARE(net_shell); -#include "common.h" +#include "net_shell_private.h" static int cmd_net_resume(const struct shell *sh, size_t argc, char *argv[]) { diff --git a/subsys/net/lib/shell/route.c b/subsys/net/lib/shell/route.c index d48c442ed41..035b56f6dfc 100644 --- a/subsys/net/lib/shell/route.c +++ b/subsys/net/lib/shell/route.c @@ -8,7 +8,7 @@ #include LOG_MODULE_DECLARE(net_shell); -#include "common.h" +#include "net_shell_private.h" #include "../ip/route.h" diff --git a/subsys/net/lib/shell/sockets.c b/subsys/net/lib/shell/sockets.c index 792e34efc21..8be67fc5faf 100644 --- a/subsys/net/lib/shell/sockets.c +++ b/subsys/net/lib/shell/sockets.c @@ -7,7 +7,7 @@ #include LOG_MODULE_DECLARE(net_shell); -#include "common.h" +#include "net_shell_private.h" #include #if defined(CONFIG_NET_SOCKETS_OBJ_CORE) diff --git a/subsys/net/lib/shell/stats.c b/subsys/net/lib/shell/stats.c index 455f5d7decd..666a98e35d7 100644 --- a/subsys/net/lib/shell/stats.c +++ b/subsys/net/lib/shell/stats.c @@ -10,7 +10,7 @@ LOG_MODULE_DECLARE(net_shell); #include -#include "common.h" +#include "net_shell_private.h" #include "../ip/net_stats.h" diff --git a/subsys/net/lib/shell/suspend.c b/subsys/net/lib/shell/suspend.c index 326eb602077..cfa01375cac 100644 --- a/subsys/net/lib/shell/suspend.c +++ b/subsys/net/lib/shell/suspend.c @@ -9,7 +9,7 @@ #include LOG_MODULE_DECLARE(net_shell); -#include "common.h" +#include "net_shell_private.h" static int cmd_net_suspend(const struct shell *sh, size_t argc, char *argv[]) { diff --git a/subsys/net/lib/shell/tcp.c b/subsys/net/lib/shell/tcp.c index f90e16b3b66..e2839af36ba 100644 --- a/subsys/net/lib/shell/tcp.c +++ b/subsys/net/lib/shell/tcp.c @@ -10,7 +10,7 @@ LOG_MODULE_DECLARE(net_shell); #include -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_NET_TCP) && defined(CONFIG_NET_NATIVE_TCP) static struct net_context *tcp_ctx; diff --git a/subsys/net/lib/shell/udp.c b/subsys/net/lib/shell/udp.c index 9eaf3254514..7bccbf93ba3 100644 --- a/subsys/net/lib/shell/udp.c +++ b/subsys/net/lib/shell/udp.c @@ -10,7 +10,7 @@ LOG_MODULE_DECLARE(net_shell); #include -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_NET_UDP) && defined(CONFIG_NET_NATIVE_UDP) static struct net_context *udp_ctx; diff --git a/subsys/net/lib/shell/virtual.c b/subsys/net/lib/shell/virtual.c index 19c9b1c1b0e..4eaabaa9916 100644 --- a/subsys/net/lib/shell/virtual.c +++ b/subsys/net/lib/shell/virtual.c @@ -12,7 +12,7 @@ LOG_MODULE_DECLARE(net_shell); #include #endif -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_NET_L2_VIRTUAL) static void virtual_iface_cb(struct net_if *iface, void *user_data) diff --git a/subsys/net/lib/shell/vlan.c b/subsys/net/lib/shell/vlan.c index 0a980caa11f..ea7103ef1c9 100644 --- a/subsys/net/lib/shell/vlan.c +++ b/subsys/net/lib/shell/vlan.c @@ -15,7 +15,7 @@ LOG_MODULE_DECLARE(net_shell); #include -#include "common.h" +#include "net_shell_private.h" #if defined(CONFIG_NET_VLAN) static void iface_vlan_del_cb(struct net_if *iface, void *user_data) diff --git a/subsys/net/lib/shell/websocket.c b/subsys/net/lib/shell/websocket.c index f3e77187627..56e705199e3 100644 --- a/subsys/net/lib/shell/websocket.c +++ b/subsys/net/lib/shell/websocket.c @@ -12,7 +12,7 @@ LOG_MODULE_DECLARE(net_shell); #include #endif -#include "common.h" +#include "net_shell_private.h" #include "websocket/websocket_internal.h" From 85a31e7c746db6023bced4cc9c997431f119d007 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 15 Dec 2023 09:35:22 +0000 Subject: [PATCH 0983/1623] [nrf noup] cmake: modules: kconfig: Add hide child/parent variable Adds a variable to Kconfig which, when set, will disable showing child/parent Kconfig values in builds (enabled when Sysbuild is used) Signed-off-by: Jamie McCrae --- cmake/modules/kconfig.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/modules/kconfig.cmake b/cmake/modules/kconfig.cmake index 632e9a72422..1a78b3ebd02 100644 --- a/cmake/modules/kconfig.cmake +++ b/cmake/modules/kconfig.cmake @@ -147,6 +147,7 @@ set(COMMON_KCONFIG_ENV_SETTINGS TOOLCHAIN_KCONFIG_DIR=${TOOLCHAIN_KCONFIG_DIR} TOOLCHAIN_HAS_NEWLIB=${_local_TOOLCHAIN_HAS_NEWLIB} TOOLCHAIN_HAS_PICOLIBC=${_local_TOOLCHAIN_HAS_PICOLIBC} + HIDE_CHILD_PARENT_CONFIG=${SYSBUILD} EDT_PICKLE=${EDT_PICKLE} # Export all Zephyr modules to Kconfig ${ZEPHYR_KCONFIG_MODULES_DIR} From e3c172a8be333da55dc7802cb83eff23e786c81c Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Thu, 7 Sep 2023 17:53:19 +0200 Subject: [PATCH 0984/1623] [nrf fromtree] llext: add support for shared objects Add support for linking PIC shared object, which only require linking, using their PLT and GOT lists and don't need any relocation otherwise. Signed-off-by: Guennadi Liakhovetski (cherry picked from commit d6a5a6e04c0a6f64b93d341af4b8f04bd698401c) --- subsys/llext/llext.c | 112 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 3 deletions(-) diff --git a/subsys/llext/llext.c b/subsys/llext/llext.c index 3d99c8af4fa..7b8099a9190 100644 --- a/subsys/llext/llext.c +++ b/subsys/llext/llext.c @@ -446,6 +446,105 @@ static int llext_copy_symbols(struct llext_loader *ldr, struct llext *ext) return 0; } +/* + * Find the section, containing the supplied offset and return file offset for + * that value + */ +static size_t llext_file_offset(struct llext_loader *ldr, size_t offset) +{ + unsigned int i; + + for (i = 0; i < LLEXT_SECT_COUNT; i++) + if (ldr->sects[i].sh_addr <= offset && + ldr->sects[i].sh_addr + ldr->sects[i].sh_size > offset) + return offset - ldr->sects[i].sh_addr + ldr->sects[i].sh_offset; + + return offset; +} + +static void llext_link_plt(struct llext_loader *ldr, struct llext *ext, elf_shdr_t *shdr) +{ + unsigned int sh_cnt = shdr->sh_size / shdr->sh_entsize; + /* + * CPU address where the .text section is stored, we use .text just as a + * reference point + */ + uint8_t *text = ext->mem[LLEXT_MEM_TEXT]; + + LOG_DBG("Found %p in PLT %u size %u cnt %u text %p", + (void *)llext_string(ldr, ext, LLEXT_MEM_SHSTRTAB, shdr->sh_name), + shdr->sh_type, shdr->sh_entsize, sh_cnt, (void *)text); + + const elf_shdr_t *sym_shdr = ldr->sects + LLEXT_SECT_SYMTAB; + unsigned int sym_cnt = sym_shdr->sh_size / sym_shdr->sh_entsize; + + for (unsigned int i = 0; i < sh_cnt; i++) { + elf_rela_t rela; + + int ret = llext_seek(ldr, shdr->sh_offset + i * shdr->sh_entsize); + + if (!ret) { + ret = llext_read(ldr, &rela, sizeof(rela)); + } + + if (ret < 0) { + LOG_ERR("PLT: failed to read RELA #%u, trying to continue", i); + continue; + } + + /* Index in the symbol table */ + unsigned int j = ELF32_R_SYM(rela.r_info); + + if (j >= sym_cnt) { + LOG_WRN("PLT: idx %u >= %u", j, sym_cnt); + continue; + } + + elf_sym_t sym_tbl; + + ret = llext_seek(ldr, sym_shdr->sh_offset + j * sizeof(elf_sym_t)); + if (!ret) { + ret = llext_read(ldr, &sym_tbl, sizeof(sym_tbl)); + } + + if (ret < 0) { + LOG_ERR("PLT: failed to read symbol table #%u RELA #%u, trying to continue", + j, i); + continue; + } + + uint32_t stt = ELF_ST_TYPE(sym_tbl.st_info); + const char *name = llext_string(ldr, ext, LLEXT_MEM_STRTAB, sym_tbl.st_name); + /* + * Both r_offset and sh_addr are addresses for which the extension + * has been built. + */ + size_t got_offset = llext_file_offset(ldr, rela.r_offset) - + ldr->sects[LLEXT_SECT_TEXT].sh_offset; + + if (stt == STT_NOTYPE && sym_tbl.st_shndx == SHN_UNDEF && name[0] != '\0') { + const void *link_addr = llext_find_sym(NULL, name); + + if (!link_addr) { + LOG_WRN("PLT: cannot find idx %u name %s", j, name); + continue; + } + + if (!rela.r_offset) { + LOG_WRN("PLT: zero offset idx %u name %s", j, name); + continue; + } + + LOG_DBG("symbol %s offset %#x r-offset %#x .text offset %#x", + name, got_offset, + rela.r_offset, ldr->sects[LLEXT_SECT_TEXT].sh_offset); + + /* Resolve the symbol */ + *(const void **)(text + got_offset) = link_addr; + } + } +} + __weak void arch_elf_relocate(elf_rela_t *rel, uintptr_t opaddr, uintptr_t opval) { } @@ -486,12 +585,19 @@ static int llext_link(struct llext_loader *ldr, struct llext *ext) if (strcmp(name, ".rel.text") == 0 || strcmp(name, ".rela.text") == 0) { loc = (uintptr_t)ext->mem[LLEXT_MEM_TEXT]; - } else if (strcmp(name, ".rel.bss") == 0) { + } else if (strcmp(name, ".rel.bss") == 0 || + strcmp(name, ".rela.bss") == 0) { loc = (uintptr_t)ext->mem[LLEXT_MEM_BSS]; - } else if (strcmp(name, ".rel.rodata") == 0) { + } else if (strcmp(name, ".rel.rodata") == 0 || + strcmp(name, ".rela.rodata") == 0) { loc = (uintptr_t)ext->mem[LLEXT_MEM_RODATA]; - } else if (strcmp(name, ".rel.data") == 0) { + } else if (strcmp(name, ".rel.data") == 0 || + strcmp(name, ".rela.data") == 0) { loc = (uintptr_t)ext->mem[LLEXT_MEM_DATA]; + } else if (strcmp(name, ".rela.plt") == 0 || + strcmp(name, ".rela.dyn") == 0) { + llext_link_plt(ldr, ext, &shdr); + continue; } LOG_DBG("relocation section %s (%d) linked to section %d has %d relocations", From 3ffae176371cc9aaf673e1ae05c3498e08f9fec9 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Wed, 6 Sep 2023 15:52:46 +0200 Subject: [PATCH 0985/1623] [nrf fromtree] llext: export some symbols Export some symbols for loadable modules. Also add an EXPORT_SYSCALL() helper macro for exporting system calls by their official names. Signed-off-by: Guennadi Liakhovetski (cherry picked from commit 69cdc3289279f476a495e6920a954fc194eec043) --- include/zephyr/llext/symbol.h | 10 ++++++++++ kernel/mutex.c | 3 +++ kernel/thread.c | 2 ++ lib/os/assert.c | 4 +++- subsys/llext/CMakeLists.txt | 3 +-- subsys/llext/llext_export.c | 17 +++++++++++++++++ subsys/logging/log_msg.c | 2 ++ 7 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 subsys/llext/llext_export.c diff --git a/include/zephyr/llext/symbol.h b/include/zephyr/llext/symbol.h index b1aef67413e..84e43d22b5b 100644 --- a/include/zephyr/llext/symbol.h +++ b/include/zephyr/llext/symbol.h @@ -78,6 +78,16 @@ struct llext_symtable { .name = STRINGIFY(x), .addr = &x, \ } +/** + * @brief Export a system call to a table of symbols + * + * Takes a system call name and uses @a EXPORT_SYMBOL() to export the respective + * function. + * + * @param x System call to export + */ +#define EXPORT_SYSCALL(x) EXPORT_SYMBOL(z_impl_ ## x) + /** * @} */ diff --git a/kernel/mutex.c b/kernel/mutex.c index 6d22ce83f22..622422aef7b 100644 --- a/kernel/mutex.c +++ b/kernel/mutex.c @@ -37,6 +37,7 @@ #include #include #include +#include LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); /* We use a global spinlock here because some of the synchronization @@ -195,6 +196,7 @@ int z_impl_k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout) return -EAGAIN; } +EXPORT_SYSCALL(k_mutex_lock); #ifdef CONFIG_USERSPACE static inline int z_vrfy_k_mutex_lock(struct k_mutex *mutex, @@ -280,6 +282,7 @@ int z_impl_k_mutex_unlock(struct k_mutex *mutex) return 0; } +EXPORT_SYSCALL(k_mutex_unlock); #ifdef CONFIG_USERSPACE static inline int z_vrfy_k_mutex_unlock(struct k_mutex *mutex) diff --git a/kernel/thread.c b/kernel/thread.c index 8f60054e798..fc31f4b36d8 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -29,6 +29,7 @@ #include #include #include +#include #include LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); @@ -141,6 +142,7 @@ bool k_is_in_isr(void) { return arch_is_in_isr(); } +EXPORT_SYMBOL(k_is_in_isr); /* * This function tags the current thread as essential to system operation. diff --git a/lib/os/assert.c b/lib/os/assert.c index b6a33ae7320..1fee487bff6 100644 --- a/lib/os/assert.c +++ b/lib/os/assert.c @@ -7,7 +7,7 @@ #include #include #include - +#include /** * @brief Assert Action Handler @@ -42,6 +42,7 @@ __weak void assert_post_action(const char *file, unsigned int line) k_panic(); } +EXPORT_SYMBOL(assert_post_action); void assert_print(const char *fmt, ...) { @@ -53,3 +54,4 @@ void assert_print(const char *fmt, ...) va_end(ap); } +EXPORT_SYMBOL(assert_print); diff --git a/subsys/llext/CMakeLists.txt b/subsys/llext/CMakeLists.txt index ac54f3172c3..b129dc7f943 100644 --- a/subsys/llext/CMakeLists.txt +++ b/subsys/llext/CMakeLists.txt @@ -1,6 +1,5 @@ if(CONFIG_LLEXT) zephyr_library() - zephyr_library_sources(llext.c) - zephyr_library_sources(buf_loader.c) + zephyr_library_sources(llext.c llext_export.c buf_loader.c) zephyr_library_sources_ifdef(CONFIG_LLEXT_SHELL shell.c) endif() diff --git a/subsys/llext/llext_export.c b/subsys/llext/llext_export.c new file mode 100644 index 00000000000..0ec7fe4ac0a --- /dev/null +++ b/subsys/llext/llext_export.c @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +EXPORT_SYMBOL(strcpy); +EXPORT_SYMBOL(strncpy); +EXPORT_SYMBOL(strlen); +EXPORT_SYMBOL(strcmp); +EXPORT_SYMBOL(strncmp); +EXPORT_SYMBOL(memcmp); +EXPORT_SYMBOL(memcpy); +EXPORT_SYMBOL(memset); diff --git a/subsys/logging/log_msg.c b/subsys/logging/log_msg.c index 8023cefbf8c..da9dffdc62e 100644 --- a/subsys/logging/log_msg.c +++ b/subsys/logging/log_msg.c @@ -10,6 +10,7 @@ #include #include #include +#include LOG_MODULE_DECLARE(log); BUILD_ASSERT(sizeof(struct log_msg_desc) == sizeof(uint32_t), @@ -270,6 +271,7 @@ void z_impl_z_log_msg_static_create(const void *source, z_log_msg_finalize(msg, source, out_desc, data); } +EXPORT_SYSCALL(z_log_msg_static_create); #ifdef CONFIG_USERSPACE static inline void z_vrfy_z_log_msg_static_create(const void *source, From 710df4fbe059934005a8c7399658b9e6ac6fd346 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Thu, 28 Sep 2023 16:45:34 +0200 Subject: [PATCH 0986/1623] [nrf fromtree] llext: make buffer access functions accessible externally llext_seek(), llext_read() and llext_peek() are needed outside of the extension code too, move them to a header. Signed-off-by: Guennadi Liakhovetski (cherry picked from commit a2a62b46a32bb6f4dcf8a21ee229e8eeea2c594d) --- include/zephyr/llext/loader.h | 19 +++++++++++++++++++ subsys/llext/llext.c | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/zephyr/llext/loader.h b/include/zephyr/llext/loader.h index 3cc53da7d88..3102f17cf1a 100644 --- a/include/zephyr/llext/loader.h +++ b/include/zephyr/llext/loader.h @@ -97,6 +97,25 @@ struct llext_loader { /** @endcond */ }; +static inline int llext_read(struct llext_loader *l, void *buf, size_t len) +{ + return l->read(l, buf, len); +} + +static inline int llext_seek(struct llext_loader *l, size_t pos) +{ + return l->seek(l, pos); +} + +static inline void *llext_peek(struct llext_loader *l, size_t pos) +{ + if (l->peek) { + return l->peek(l, pos); + } + + return NULL; +} + /** * @} */ diff --git a/subsys/llext/llext.c b/subsys/llext/llext.c index 7b8099a9190..6c47ddf29c6 100644 --- a/subsys/llext/llext.c +++ b/subsys/llext/llext.c @@ -21,25 +21,6 @@ K_HEAP_DEFINE(llext_heap, CONFIG_LLEXT_HEAP_SIZE * 1024); static const char ELF_MAGIC[] = {0x7f, 'E', 'L', 'F'}; -static inline int llext_read(struct llext_loader *l, void *buf, size_t len) -{ - return l->read(l, buf, len); -} - -static inline int llext_seek(struct llext_loader *l, size_t pos) -{ - return l->seek(l, pos); -} - -static inline void *llext_peek(struct llext_loader *l, size_t pos) -{ - if (l->peek) { - return l->peek(l, pos); - } - - return NULL; -} - static sys_slist_t _llext_list = SYS_SLIST_STATIC_INIT(&_llext_list); sys_slist_t *llext_list(void) From 94e99e2116f5370aee0d56bc4e52fcd5c0415bc9 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 29 Sep 2023 09:56:47 +0200 Subject: [PATCH 0987/1623] [nrf fromtree] llext: add Xtensa test support Add support for running a modular "Hello world" example on Xtensa. Signed-off-by: Guennadi Liakhovetski (cherry picked from commit e5c8d181d46f948e35851dd826637e32e48b77f6) --- tests/subsys/llext/hello_world/CMakeLists.txt | 23 +++++++++++++++---- tests/subsys/llext/src/test_llext_simple.c | 4 ++-- tests/subsys/llext/testcase.yaml | 5 ++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/tests/subsys/llext/hello_world/CMakeLists.txt b/tests/subsys/llext/hello_world/CMakeLists.txt index 1a16d4be26b..6519075e2f4 100644 --- a/tests/subsys/llext/hello_world/CMakeLists.txt +++ b/tests/subsys/llext/hello_world/CMakeLists.txt @@ -6,11 +6,26 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(hello_world) # TODO check which architecture is being used -set(CMAKE_C_FLAGS "-mlong-calls" "-mthumb") +if(CONFIG_ARM) + set(CMAKE_C_FLAGS "-mlong-calls" "-mthumb") -add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/hello_world.llext - COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -c -o ${PROJECT_BINARY_DIR}/hello_world.llext ${PROJECT_SOURCE_DIR}/hello_world.c -) + add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/hello_world.llext + COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -c + -o ${PROJECT_BINARY_DIR}/hello_world.llext + ${PROJECT_SOURCE_DIR}/hello_world.c + ) +elseif(CONFIG_XTENSA) + set(CMAKE_C_FLAGS "-shared" "-fPIC" "-nostdlib" "-nodefaultlibs") + + add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/hello_world.llext + COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} + -o ${PROJECT_BINARY_DIR}/hello_world.pre.llext + ${PROJECT_SOURCE_DIR}/hello_world.c + COMMAND ${CROSS_COMPILE}strip -R .xt.* + -o ${PROJECT_BINARY_DIR}/hello_world.llext + ${PROJECT_BINARY_DIR}/hello_world.pre.llext + ) +endif() set(HELLO_WORLD_LLEXT ${PROJECT_BINARY_DIR}/hello_world.llext PARENT_SCOPE) diff --git a/tests/subsys/llext/src/test_llext_simple.c b/tests/subsys/llext/src/test_llext_simple.c index ef0e62b93b5..d96191c1d72 100644 --- a/tests/subsys/llext/src/test_llext_simple.c +++ b/tests/subsys/llext/src/test_llext_simple.c @@ -9,7 +9,7 @@ #include #include -#ifdef CONFIG_ARM /* ARMV7 */ +#if defined(CONFIG_ARM) /* ARMV7 */ || defined(CONFIG_XTENSA) const static uint8_t hello_world_elf[] __aligned(4) = { #include "hello_world.inc" }; @@ -24,7 +24,7 @@ const static uint8_t hello_world_elf[] __aligned(4) = { */ ZTEST(llext, test_llext_simple) { - const char name[16] = {'h', 'e', 'l', 'l', 'o', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const char name[16] = "hello"; struct llext_buf_loader buf_loader = LLEXT_BUF_LOADER(hello_world_elf, ARRAY_SIZE(hello_world_elf)); struct llext_loader *loader = &buf_loader.loader; diff --git a/tests/subsys/llext/testcase.yaml b/tests/subsys/llext/testcase.yaml index 79d8f5a1fd9..0bbccd5e1ca 100644 --- a/tests/subsys/llext/testcase.yaml +++ b/tests/subsys/llext/testcase.yaml @@ -9,3 +9,8 @@ tests: # Broken platforms platform_exclude: - nuvoton_pfm_m487 # See #63167 + llext.simple.xtensa: + arch_allow: xtensa + # Broken platforms + platform_exclude: + - qemu_xtensa_mmu # ELF sections are read-only, and without peek() .text copy isn't executable From 7459728d37f039ded52d174b9597112676d7a5b5 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Wed, 15 Nov 2023 17:19:57 +0100 Subject: [PATCH 0988/1623] [nrf fromtree] llext: clarify section map allocation size Use an element size explicitly when calculating the array size and use the calculated size for memset(). Signed-off-by: Guennadi Liakhovetski (cherry picked from commit b5ce5012e29d5c1c2e2d5c1dac7fa15766db79e5) --- subsys/llext/llext.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/subsys/llext/llext.c b/subsys/llext/llext.c index 6c47ddf29c6..4f43dc17a1d 100644 --- a/subsys/llext/llext.c +++ b/subsys/llext/llext.c @@ -670,7 +670,7 @@ static int do_llext_load(struct llext_loader *ldr, struct llext *ext) memset(ldr->sects, 0, sizeof(ldr->sects)); ldr->sect_cnt = 0; - size_t sect_map_sz = ldr->hdr.e_shnum * sizeof(uint32_t); + size_t sect_map_sz = ldr->hdr.e_shnum * sizeof(ldr->sect_map[0]); ldr->sect_map = k_heap_alloc(&llext_heap, sect_map_sz, K_NO_WAIT); if (!ldr->sect_map) { @@ -678,7 +678,8 @@ static int do_llext_load(struct llext_loader *ldr, struct llext *ext) ret = -ENOMEM; goto out; } - memset(ldr->sect_map, 0, ldr->hdr.e_shnum*sizeof(uint32_t)); + memset(ldr->sect_map, 0, sect_map_sz); + ldr->sect_cnt = ldr->hdr.e_shnum; ext->mem_size += sect_map_sz; From 1f1048a9e98c1b11a9caa0628ab63c2af4200e93 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Mon, 20 Nov 2023 15:21:46 +0100 Subject: [PATCH 0989/1623] [nrf fromtree] llext: remove redundant initialisation a new llext object is completely initialised with zeros after allocation, no need to additionally set members of an embedded into it array to NULL. Signed-off-by: Guennadi Liakhovetski (cherry picked from commit b5506feed5a6fc3c1b9a44343deb62ce4445b240) --- subsys/llext/llext.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/subsys/llext/llext.c b/subsys/llext/llext.c index 4f43dc17a1d..a24d2b0833f 100644 --- a/subsys/llext/llext.c +++ b/subsys/llext/llext.c @@ -792,10 +792,6 @@ int llext_load(struct llext_loader *ldr, const char *name, struct llext **ext) } memset(*ext, 0, sizeof(struct llext)); - for (int i = 0; i < LLEXT_MEM_COUNT; i++) { - (*ext)->mem[i] = NULL; - } - ldr->hdr = ehdr; ret = do_llext_load(ldr, *ext); break; From fa777ddca7d6c7a37f512d324c7c8ce69221ddfb Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Thu, 23 Nov 2023 16:50:20 +0100 Subject: [PATCH 0990/1623] [nrf fromtree] llext: fix read-only extension image When using the LLEXT buffer loader we now avoid copying extensions from storage to allocated memory by pointing directly into the stored image. We then also perform linking and relocation in that memory, which modifies its contents. However, this is impossible if that storage is read-only. Add a Kconfig flag to distinguish between writable and read-only storage types. Also use that flag to decide, whether the extension image in test_llext_simple.c should be defined as const or not. Signed-off-by: Guennadi Liakhovetski (cherry picked from commit dbea13a1c7b10afdb6293b643e3cede34dfa3345) --- subsys/llext/Kconfig | 6 ++++++ subsys/llext/llext.c | 3 ++- tests/subsys/llext/src/test_llext_simple.c | 5 ++++- tests/subsys/llext/testcase.yaml | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/subsys/llext/Kconfig b/subsys/llext/Kconfig index 9fec16cb230..b1210b8f2e8 100644 --- a/subsys/llext/Kconfig +++ b/subsys/llext/Kconfig @@ -27,6 +27,12 @@ config LLEXT_SHELL_MAX_SIZE help When loading llext with shell it is stored in a temporary buffer of this size +config LLEXT_STORAGE_WRITABLE + bool "llext storage is writable" + help + Select if LLEXT storage is writable, i.e. if extensions are stored in + RAM and can be modified in place + module = LLEXT module-str = llext source "subsys/logging/Kconfig.template.log_config" diff --git a/subsys/llext/llext.c b/subsys/llext/llext.c index a24d2b0833f..8dd5801bc95 100644 --- a/subsys/llext/llext.c +++ b/subsys/llext/llext.c @@ -242,7 +242,8 @@ static int llext_copy_section(struct llext_loader *ldr, struct llext *ext, return 0; } - if (ldr->sects[sect_idx].sh_type != SHT_NOBITS) { + if (ldr->sects[sect_idx].sh_type != SHT_NOBITS && + IS_ENABLED(CONFIG_LLEXT_STORAGE_WRITABLE)) { ext->mem[mem_idx] = llext_peek(ldr, ldr->sects[sect_idx].sh_offset); if (ext->mem[mem_idx]) { ext->mem_on_heap[mem_idx] = false; diff --git a/tests/subsys/llext/src/test_llext_simple.c b/tests/subsys/llext/src/test_llext_simple.c index d96191c1d72..557697f576c 100644 --- a/tests/subsys/llext/src/test_llext_simple.c +++ b/tests/subsys/llext/src/test_llext_simple.c @@ -10,7 +10,10 @@ #include #if defined(CONFIG_ARM) /* ARMV7 */ || defined(CONFIG_XTENSA) -const static uint8_t hello_world_elf[] __aligned(4) = { +#ifndef CONFIG_LLEXT_STORAGE_WRITABLE +const +#endif +static uint8_t hello_world_elf[] __aligned(4) = { #include "hello_world.inc" }; #endif diff --git a/tests/subsys/llext/testcase.yaml b/tests/subsys/llext/testcase.yaml index 0bbccd5e1ca..2747edf8d0c 100644 --- a/tests/subsys/llext/testcase.yaml +++ b/tests/subsys/llext/testcase.yaml @@ -11,6 +11,8 @@ tests: - nuvoton_pfm_m487 # See #63167 llext.simple.xtensa: arch_allow: xtensa + extra_configs: + - CONFIG_LLEXT_STORAGE_WRITABLE=y # Broken platforms platform_exclude: - qemu_xtensa_mmu # ELF sections are read-only, and without peek() .text copy isn't executable From de1f9a6bec791ecf6c6d3002bd143a719b3ad069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 21 Nov 2023 08:27:07 +0100 Subject: [PATCH 0991/1623] [nrf fromtree] boards: nrf52840dk_nrf52840: Fix reserved GPIO lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up to commit 7a83724e0f18d7f2400517407150f9e9a1ecd6e6. There is no reason to mark that many GPIO lines as reserved on this board. And doing so causes several existing tests to fail as they are configured to use some of those now unavailable GPIO lines. Limit reservation to the lines that actually cannot be used as GPIOs without changes in the default configuration of the board or its physical modification (via solder bridges), i.e.: - XL1 and XL2 (connections for the 32.768 kHz crystal) - NFC1 and NFC2 (NFC antenna connections) - RESET - TXD and RXD (lines used by the console UART) - QSPI lines: CS, CLK, and DIO0-3 Provide names for all the GPIO lines that are described on the board. Even for the reserved ones, so that it is clear why they are reserved. Signed-off-by: Andrzej Głąbek (cherry picked from commit b172e5133b09ec0c32dbbe74dafa9ef8f2d9da33) --- .../nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts b/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts index dcee7b0db5f..60c3ecf55a1 100644 --- a/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts +++ b/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts @@ -149,18 +149,18 @@ &gpio0 { status = "okay"; - gpio-reserved-ranges = <0 11>, <17 7>, <26 6>; - gpio-line-names = "", "", "", "", "", "", "", "", - "", "", "", "BUTTON1", "BUTTON2", "LED1", "LED2", "LED3", - "LED4", "", "", "", "", "", "", "", - "BUTTON3", "BUTTON4", "", "", "", "", "", ""; + gpio-reserved-ranges = <0 2>, <6 1>, <8 3>, <17 7>; + gpio-line-names = "XL1", "XL2", "AREF", "A0", "A1", "RTS", "TXD", + "CTS", "RXD", "NFC1", "NFC2", "BUTTON1", "BUTTON2", "LED1", + "LED2", "LED3", "LED4", "QSPI CS", "RESET", "QSPI CLK", + "QSPI DIO0", "QSPI DIO1", "QSPI DIO2", "QSPI DIO3","BUTTON3", + "BUTTON4", "SDA", "SCL", "A2", "A3", "A4", "A5"; }; &gpio1 { status = "okay"; - gpio-reserved-ranges = <0 1>, <9 1>, <12 4>; gpio-line-names = "", "D0", "D1", "D2", "D3", "D4", "D5", "D6", - "D7", "", "D8", "D9", "", "", "", ""; + "D7", "", "D8", "D9", "D10", "D11", "D12", "D13"; }; &uart0 { From 1a7010954b184b1e29c9ad1a9a19600f213e4c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 21 Nov 2023 17:36:52 +0100 Subject: [PATCH 0992/1623] [nrf fromtree] tests: drivers: flash: Update nrf52840dk_mx25r_high_perf.overlay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up to commit 7a83724e0f18d7f2400517407150f9e9a1ecd6e6. This overlay uses an alternative connection (via spi2) for the external flash present on the nRF52840 DK and it needs to use one of the QSPI pins as GPIO, to get CS line control in the SPI communication. To make it possible, that GPIO must be removed from those marked as reserved. Signed-off-by: Andrzej Głąbek (cherry picked from commit 4a262c3947e745fff542a2d78dbedfe460cc2541) --- .../flash/common/boards/nrf52840dk_mx25r_high_perf.overlay | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/drivers/flash/common/boards/nrf52840dk_mx25r_high_perf.overlay b/tests/drivers/flash/common/boards/nrf52840dk_mx25r_high_perf.overlay index eabb26ebda6..a67f25e46c0 100644 --- a/tests/drivers/flash/common/boards/nrf52840dk_mx25r_high_perf.overlay +++ b/tests/drivers/flash/common/boards/nrf52840dk_mx25r_high_perf.overlay @@ -1,5 +1,9 @@ /delete-node/ &qspi; +&gpio0 { + gpio-reserved-ranges = <0 2>, <6 1>, <8 3>, <18 6>; +}; + &spi2 { compatible = "nordic,nrf-spim"; status = "okay"; From bea8d6bcc98289cf500718f87b303a3127bcca54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 21 Nov 2023 17:43:35 +0100 Subject: [PATCH 0993/1623] [nrf fromtree] tests: drivers: flash: Use fixtures for tests requiring external chips MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Several scenarios in this test require specific external flash chips to be connected to the nRF52840 DK. Specify proper fixture for them so that they are not performed on the board without those required external components connected. Signed-off-by: Andrzej Głąbek (cherry picked from commit c949018d36bd6a2b0453a52062adcc108060cce4) --- tests/drivers/flash/common/testcase.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/drivers/flash/common/testcase.yaml b/tests/drivers/flash/common/testcase.yaml index 9aa13bb40d5..88ce0a40e07 100644 --- a/tests/drivers/flash/common/testcase.yaml +++ b/tests/drivers/flash/common/testcase.yaml @@ -21,7 +21,7 @@ tests: - OVERLAY_CONFIG=boards/nrf52840_flash_qspi.conf - DTC_OVERLAY_FILE=boards/nrf52840dk_mx25l51245g.overlay harness_config: - fixture: external_flash + fixture: external_flash_mx25l51245g integration_platforms: - nrf52840dk_nrf52840 drivers.flash.common.soc_flash_nrf: @@ -78,11 +78,15 @@ tests: extra_args: - OVERLAY_CONFIG=boards/nrf52840dk_flash_spi.conf - DTC_OVERLAY_FILE=boards/nrf52840dk_spi_nor.overlay + harness_config: + fixture: external_flash_mx25v1635f drivers.flash.common.spi_nor_wp_hold: platform_allow: nrf52840dk_nrf52840 extra_args: - OVERLAY_CONFIG=boards/nrf52840dk_flash_spi.conf - DTC_OVERLAY_FILE=boards/nrf52840dk_spi_nor_wp_hold.overlay + harness_config: + fixture: external_flash_mx25v1635f drivers.flash.common.sam0: platform_allow: - atsamd20_xpro From a5fa2ffb399f2d98727848c2d37a4d3cfc9af53b Mon Sep 17 00:00:00 2001 From: Marcin Jelinski Date: Thu, 4 Jan 2024 14:23:54 +0100 Subject: [PATCH 0994/1623] [nrf fromtree] samples: ipc: multi_endpoint: Fix synchronisation of data receiving The incorrect semaphore was used for the ipc1 instance to synchronise the data receiving. This commit fixes it. Signed-off-by: Marcin Jelinski (cherry picked from commit 7815e52fd15d49c47b4201470b0fe52dab3e3c9c) Signed-off-by: Dominik Ermel --- samples/subsys/ipc/ipc_service/multi_endpoint/remote/src/main.c | 2 +- samples/subsys/ipc/ipc_service/multi_endpoint/src/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/subsys/ipc/ipc_service/multi_endpoint/remote/src/main.c b/samples/subsys/ipc/ipc_service/multi_endpoint/remote/src/main.c index 9b288f8a6a1..f285f4b6d23 100644 --- a/samples/subsys/ipc/ipc_service/multi_endpoint/remote/src/main.c +++ b/samples/subsys/ipc/ipc_service/multi_endpoint/remote/src/main.c @@ -193,7 +193,7 @@ static void ipc1_ept_recv(const void *data, size_t len, void *priv) { ipc1_received_data = *((uint8_t *) data); - k_sem_give(&ipc0B_data_sem); + k_sem_give(&ipc1_data_sem); } static struct ipc_ept_cfg ipc1_ept_cfg = { diff --git a/samples/subsys/ipc/ipc_service/multi_endpoint/src/main.c b/samples/subsys/ipc/ipc_service/multi_endpoint/src/main.c index 78d7af05288..4ad5659df38 100644 --- a/samples/subsys/ipc/ipc_service/multi_endpoint/src/main.c +++ b/samples/subsys/ipc/ipc_service/multi_endpoint/src/main.c @@ -190,7 +190,7 @@ static void ipc1_ept_recv(const void *data, size_t len, void *priv) { ipc1_received_data = *((uint8_t *) data); - k_sem_give(&ipc0B_data_sem); + k_sem_give(&ipc1_data_sem); } static struct ipc_ept_cfg ipc1_ept_cfg = { From 6946f4c6748eebe6c048074c2f1fa0cda9f25cb9 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Mon, 4 Dec 2023 14:26:17 -0800 Subject: [PATCH 0995/1623] [nrf fromtree] doc: ext/gh_utils: pass MAINTAINERS.yml to Maintainers This changes to pass full path of MAINTAINERS.yml to get_maintainer.Maintainers(). Without this, Maintainers would use git to find the top level of Zephyr tree. This restricts building of doc only when the build directory is under Zephyr root. Since we have ZEPHYR_BASE in gh_utils, we can pass full path of MAINTAINERS.yml to Maintainers() so that doc build directory no longer has to be under Zephyr root. Fixes #65037 Signed-off-by: Daniel Leung (cherry picked from commit ede9b0337c72ca5312d35961c2bdd4ad9334f42c) --- doc/_extensions/zephyr/gh_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/_extensions/zephyr/gh_utils.py b/doc/_extensions/zephyr/gh_utils.py index 6ba75ce5ab7..2c992436c87 100644 --- a/doc/_extensions/zephyr/gh_utils.py +++ b/doc/_extensions/zephyr/gh_utils.py @@ -53,7 +53,7 @@ from get_maintainer import Maintainers -MAINTAINERS : Final[Maintainers] = Maintainers() +MAINTAINERS : Final[Maintainers] = Maintainers(filename=f"{ZEPHYR_BASE}/MAINTAINERS.yml") __version__ = "0.1.0" From ed20dd66fdd81408bc26a693c299f829fb05214f Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Tue, 9 Jan 2024 15:23:54 +0100 Subject: [PATCH 0996/1623] [nrf fromlist] doc: extensions: zephyr-domain: fix object descriptions Zephyr's domain code-sample object description was incorrectly yielded, making Sphinx inventory (objects.inv) unusable on other projects that need to use the domain via Intersphinx. Ref. https://www.sphinx-doc.org/en/master/extdev/domainapi.html Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67384 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 139f7c8bb14f14a772ee0d9343bd06d727d9cca3) --- doc/_extensions/zephyr/domain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/_extensions/zephyr/domain.py b/doc/_extensions/zephyr/domain.py index 8c395142818..beb94eb4d2f 100644 --- a/doc/_extensions/zephyr/domain.py +++ b/doc/_extensions/zephyr/domain.py @@ -249,7 +249,7 @@ class ZephyrDomain(Domain): directives = {"code-sample": CodeSampleDirective} object_types: Dict[str, ObjType] = { - "code-sample": ObjType("code sample", "code-sample"), + "code-sample": ObjType("code-sample", "code-sample"), } initial_data: Dict[str, Any] = {"code-samples": {}} @@ -267,9 +267,9 @@ def merge_domaindata(self, docnames: List[str], otherdata: Dict) -> None: def get_objects(self): for _, code_sample in self.data["code-samples"].items(): yield ( + code_sample["id"], code_sample["name"], - code_sample["name"], - "code sample", + "code-sample", code_sample["docname"], code_sample["id"], 1, From 774a528ecbc8aae382cc969d8b944b59e4bb9dde Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Tue, 9 Jan 2024 15:34:14 +0100 Subject: [PATCH 0997/1623] [nrf fromlist] doc: extensions: zephyr-domain: make transforms optional So that external users of the domain only interested in e.g. referencing roles, can skip such unneeded transformations. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67384 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit bc7baa515ac10f07592777b76ca4dd8b3139dccc) --- doc/_extensions/zephyr/domain.py | 14 +++++++++++++- doc/conf.py | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/_extensions/zephyr/domain.py b/doc/_extensions/zephyr/domain.py index beb94eb4d2f..053965e26e3 100644 --- a/doc/_extensions/zephyr/domain.py +++ b/doc/_extensions/zephyr/domain.py @@ -80,6 +80,9 @@ class ConvertCodeSampleNode(SphinxTransform): default_priority = 100 def apply(self): + if not self.config.zephyr_domain_apply_transforms: + return + matcher = NodeMatcher(CodeSampleNode) for node in self.document.traverse(matcher): self.convert_node(node) @@ -140,6 +143,9 @@ class ProcessRelatedCodeSamplesNode(SphinxPostTransform): default_priority = 5 # before ReferencesResolver def run(self, **kwargs: Any) -> None: + if not self.config.zephyr_domain_apply_transforms: + return + matcher = NodeMatcher(RelatedCodeSamplesNode) for node in self.document.traverse(matcher): id = node["id"] # the ID of the node is the name of the doxygen group for which we @@ -308,10 +314,16 @@ class CustomDoxygenGroupDirective(DoxygenGroupDirective): def run(self) -> List[Node]: nodes = super().run() - return [RelatedCodeSamplesNode(id=self.arguments[0]), *nodes] + + if self.config.zephyr_domain_apply_transforms: + return [RelatedCodeSamplesNode(id=self.arguments[0]), *nodes] + else: + return nodes def setup(app): + app.add_config_value("zephyr_domain_apply_transforms", False, "env") + app.add_domain(ZephyrDomain) app.add_transform(ConvertCodeSampleNode) diff --git a/doc/conf.py b/doc/conf.py index 85488318a0a..4bab42dcc90 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -302,6 +302,10 @@ "build/dts/api/compatibles/**/*", ] +# -- Options for zephyr.domain -------------------------------------------- + +zephyr_domain_apply_transforms = True + # -- Options for sphinx.ext.graphviz -------------------------------------- graphviz_dot = os.environ.get("DOT_EXECUTABLE", "dot") From ead6b4d1db7209abda3c81a7bd8312eb42ef7a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Tue, 21 Nov 2023 15:59:33 +0100 Subject: [PATCH 0998/1623] [nrf fromtree] tests: logging: log_backend_uart: Disable backends other than UART MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test expects that there are no other backends enabled and some may be enabled by default. Signed-off-by: Krzysztof Chruściński (cherry picked from commit c143daf98dbdc88f2154f86c05c4256d01cb79f2) Signed-off-by: Dominik Ermel --- tests/subsys/logging/log_backend_uart/prj.conf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/subsys/logging/log_backend_uart/prj.conf b/tests/subsys/logging/log_backend_uart/prj.conf index ef6894f355e..c8615a65adb 100644 --- a/tests/subsys/logging/log_backend_uart/prj.conf +++ b/tests/subsys/logging/log_backend_uart/prj.conf @@ -9,3 +9,8 @@ CONFIG_LOG=y CONFIG_LOG_BACKEND_UART=y CONFIG_LOG_MODE_IMMEDIATE=y CONFIG_LOG_PRINTK=n +# +# Disable all potential other default backends +CONFIG_LOG_BACKEND_NATIVE_POSIX=n +CONFIG_LOG_BACKEND_RTT=n +CONFIG_LOG_BACKEND_XTENSA_SIM=n From 883c3709f9c8fd845a8dfa39d2583d5c665a915b Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 23 Nov 2023 12:18:17 +0100 Subject: [PATCH 0999/1623] [nrf fromtree] tests: modem: backend: uart: Add fixture to test suite Add fixture to test suite to allow for and signal that the test must be run on real hardware. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit bec7789862ea5449a63626de9c943678c95a13e8) Signed-off-by: Dominik Ermel --- .../uart/boards/b_u585i_iot02a.overlay | 35 +++------------- .../boards/nrf5340dk_nrf5340_cpuapp.overlay | 42 ++++++++----------- tests/subsys/modem/backends/uart/src/main.c | 2 +- .../subsys/modem/backends/uart/testcase.yaml | 18 ++++---- 4 files changed, 33 insertions(+), 64 deletions(-) diff --git a/tests/subsys/modem/backends/uart/boards/b_u585i_iot02a.overlay b/tests/subsys/modem/backends/uart/boards/b_u585i_iot02a.overlay index 394facef7bb..30402e6e9d2 100644 --- a/tests/subsys/modem/backends/uart/boards/b_u585i_iot02a.overlay +++ b/tests/subsys/modem/backends/uart/boards/b_u585i_iot02a.overlay @@ -1,34 +1,11 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + /* - * Pins 2 and 3 must be connected to each other on the STMOD+1 connector to - * loopback RX/TX. + * The Arduino D0 and D1 must be connected to each other to loopback RX/TX. */ -/ { - aliases { - test-uart = &usart2; - }; -}; - -&gpioh { - misc_fixed_usart2 { - gpio-hog; - gpios = <13 GPIO_ACTIVE_HIGH>; - output-high; - }; -}; - -&gpdma1 { - status = "okay"; -}; - -&usart2 { - pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3 &usart2_rts_pa1 &usart2_cts_pa0>; - pinctrl-names = "default"; - current-speed = <115200>; - - dmas = <&gpdma1 0 27 STM32_DMA_PERIPH_TX - &gpdma1 1 26 STM32_DMA_PERIPH_RX>; +dut: &usart3 { + dmas = <&gpdma1 0 29 STM32_DMA_PERIPH_TX + &gpdma1 1 28 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; - - status = "okay"; }; diff --git a/tests/subsys/modem/backends/uart/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/subsys/modem/backends/uart/boards/nrf5340dk_nrf5340_cpuapp.overlay index 2d47b0f0744..777aebd8d3b 100644 --- a/tests/subsys/modem/backends/uart/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/tests/subsys/modem/backends/uart/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -1,37 +1,31 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + /* - * Pins P1.10 and P1.11 must be connected to each other to loopback RX/TX. + * Pins P0.4 and P0.5 must be connected to each other to loopback RX/TX. */ -/ { - aliases { - test-uart = &uart1; - }; -}; - -&uart1 { - status = "okay"; - current-speed = <115200>; - pinctrl-0 = <&uart1_default>; - pinctrl-1 = <&uart1_sleep>; - hw-flow-control; - pinctrl-names = "default", "sleep"; -}; - &pinctrl { - uart1_default: uart1_default { + uart1_default_alt: uart1_default_alt { group1 { - psels = ; - }; - group2 { - psels = ; + psels = , + ; }; }; - uart1_sleep: uart1_sleep { + uart1_sleep_alt: uart1_sleep_alt { group1 { - psels = , - ; + psels = , + ; low-power-enable; }; }; }; + +dut: &uart1 { + compatible = "nordic,nrf-uarte"; + current-speed = <115200>; + status = "okay"; + pinctrl-0 = <&uart1_default_alt>; + pinctrl-1 = <&uart1_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; diff --git a/tests/subsys/modem/backends/uart/src/main.c b/tests/subsys/modem/backends/uart/src/main.c index 8a6c4c2813a..dffc203bb21 100644 --- a/tests/subsys/modem/backends/uart/src/main.c +++ b/tests/subsys/modem/backends/uart/src/main.c @@ -28,7 +28,7 @@ /*************************************************************************************************/ /* Mock pipe */ /*************************************************************************************************/ -static const struct device *uart = DEVICE_DT_GET(DT_ALIAS(test_uart)); +static const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(dut)); static struct modem_backend_uart uart_backend; static struct modem_pipe *pipe; K_SEM_DEFINE(receive_ready_sem, 0, 1); diff --git a/tests/subsys/modem/backends/uart/testcase.yaml b/tests/subsys/modem/backends/uart/testcase.yaml index 626ca639f75..54d8a6b9470 100644 --- a/tests/subsys/modem/backends/uart/testcase.yaml +++ b/tests/subsys/modem/backends/uart/testcase.yaml @@ -1,21 +1,19 @@ # Copyright (c) 2023 Trackunit Corporation # SPDX-License-Identifier: Apache-2.0 +common: + harness: ztest + harness_config: + fixture: gpio_loopback + platform_allow: + - b_u585i_iot02a + - nrf5340dk_nrf5340_cpuapp + tests: modem.backends.uart.async: - tags: modem_backend - harness: ztest - platform_allow: - - b_u585i_iot02a - - nrf5340dk_nrf5340_cpuapp extra_configs: - CONFIG_UART_ASYNC_API=y modem.backends.uart.isr: - tags: modem_backend - harness: ztest - platform_allow: - - b_u585i_iot02a - - nrf5340dk_nrf5340_cpuapp extra_configs: - CONFIG_UART_INTERRUPT_DRIVEN=y From d68a96e7be44ada31fe6e9a8d28e943298a6211f Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Thu, 11 Jan 2024 11:40:54 +0100 Subject: [PATCH 1000/1623] [nrf noup] ci: NCS-specific CI tweaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit squash! [nrf noup] ci: NCS-specific CI tweaks Necessary changes for NCS CI. - Add a Jenkinsfile - Add a commit-tags workflow: This enables sauce tag checking in sdk-zephyr - compliance.yml: Disable check for merge commits, since we have upmerges downstream. Also, since in the code we refer to Kconfig symbols that are defined in the sdk-nrf repository, the Kconfig checks (Kconfig, KconfigBasic and KconfigBasicNoModules) will not pass so exclude them. Also, disable any maintainers-related checks - scripts/gitlint: Extend the max commit line lengths for Gitlint to account for sauce tags Signed-off-by: Carles Cufi Signed-off-by: Dominik Ermel Signed-off-by: Martí Bolívar Signed-off-by: Vinayak Kariappa Chettimada Signed-off-by: Krishna T (cherry picked from commit d34b035bcc569431b7008c72edc55db1b29bccf3) (cherry picked from commit 4a6d5fc57fe7589b2585ee5e44341f50821cc653) (cherry picked from commit a01c3a4caccb6964a29078172ba7f590bcdbe790) (cherry picked from commit 9b9ec58b0c575e15c57cb1e5de2d1c4ac5266a1f) Signed-off-by: Dominik Ermel Signed-off-by: Carles Cufi --- .github/workflows/compliance.yml | 2 +- scripts/gitlint/zephyr_commit_rules.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index d70990ff2c1..036729418cb 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -58,7 +58,7 @@ jobs: ls -la git log --pretty=oneline | head -n 10 ./scripts/ci/check_compliance.py --annotate -e KconfigBasic -e Kconfig \ - -e KconfigBasicNoModules -c origin/${BASE_REF}.. + -e KconfigBasicNoModules -e ModulesMaintainers -c origin/${BASE_REF}.. - name: upload-results uses: actions/upload-artifact@v3 diff --git a/scripts/gitlint/zephyr_commit_rules.py b/scripts/gitlint/zephyr_commit_rules.py index ea31c6737f3..d39c7997e26 100644 --- a/scripts/gitlint/zephyr_commit_rules.py +++ b/scripts/gitlint/zephyr_commit_rules.py @@ -78,7 +78,7 @@ class TitleMaxLengthRevert(LineRule): name = "title-max-length-no-revert" id = "UC5" target = CommitMessageTitle - options_spec = [IntOption('line-length', 75, "Max line length")] + options_spec = [IntOption('line-length', 120, "Max line length")] violation_message = "Commit title exceeds max length ({0}>{1})" def validate(self, line, _commit): @@ -103,7 +103,7 @@ class MaxLineLengthExceptions(LineRule): name = "max-line-length-with-exceptions" id = "UC4" target = CommitMessageBody - options_spec = [IntOption('line-length', 75, "Max line length")] + options_spec = [IntOption('line-length', 120, "Max line length")] violation_message = "Commit message body line exceeds max length ({0}>{1})" def validate(self, line, _commit): From 1da00e0c84f7da2f4017f4efde99e479d40e5e6e Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Fri, 12 Jan 2024 10:38:58 +0100 Subject: [PATCH 1001/1623] [nrf noup] drivers: ieee802154: temporary fix for ACK header IE config Skip configuring ACK header IE if `EnableCsl()` has been called with arguments: - `aCslPeriod` == 0 - `aShortAddr` == IEEE802154_NO_SHORT_ADDRESS_ASSIGNED - `aExtAddr` == NULL This happens during RCP startup in `Radio::Init()` implementation. It will be fixed on OT and Zephyr level, but this commit is needed to prevent coprocessor samples from asserting on boot. Signed-off-by: Maciej Baczmanski --- drivers/ieee802154/ieee802154_nrf5.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index df01f530abf..e9c49e6089e 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -886,6 +886,19 @@ static int nrf5_configure(const struct device *dev, uint8_t short_addr_le[SHORT_ADDRESS_SIZE]; uint8_t element_id; + if (config->ack_ie.ext_addr == NULL && + config->ack_ie.header_ie == NULL && + config->ack_ie.short_addr == IEEE802154_NO_SHORT_ADDRESS_ASSIGNED) { + /* Hotfix for case when `EnableCsl()` has been called with arguments: + * - `aCslPeriod` == 0 + * - `aShortAddr` == IEEE802154_NO_SHORT_ADDRESS_ASSIGNED + * - `aExtAddr` == NULL + * In this case skip configuring ACK header IE until proper resetting of + * configuration is implemented. + */ + break; + } + if (config->ack_ie.short_addr == IEEE802154_BROADCAST_ADDRESS || config->ack_ie.ext_addr == NULL) { return -ENOTSUP; From accb038d8c6a7c7fc9afa522e781c5d87bd68b56 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Wed, 22 Nov 2023 16:24:48 +0100 Subject: [PATCH 1002/1623] [nrf fromtree] Bluetooth: Mesh: allocate mesh max required buffer number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since sending of public key was moved into system work (https://github.com/zephyrproject-rtos/zephyr/pull/62331) it uses the same context as a Host Tx buffer allocator for gatt sending. Host cannot wait for free buffer anymore. Mesh requires 4 buffers to send max size frame(public key) during provisioning. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 3d37549bac90f2008c5e7cfc41ec79c553dbe99a) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/common/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index bf4aee75e48..7b6bc839b89 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -33,6 +33,7 @@ config BT_BUF_ACL_TX_SIZE config BT_BUF_ACL_TX_COUNT int "Number of outgoing ACL data buffers" default 7 if BT_HCI_RAW + default 4 if BT_MESH_GATT default 3 range 1 255 help From 64e37c9348350f47639cfaa6e2ff7d63e58ba025 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1003/1623] [nrf fromtree] Bluetooth: Mesh: Use ATOMIC_DEFINE instead of atomic_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit atomic_*_bit functions work with atomic_t arg as with array, therefore the atomic variable should be declared using ATOMIC_DEFINE. Coverity-CID: 333358 Fixes #65588 Signed-off-by: Pavel Vasilyev (cherry picked from commit 362924a6939814fe527987c4a6d27a728bb2e1eb) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/rpl.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/subsys/bluetooth/mesh/rpl.c b/subsys/bluetooth/mesh/rpl.c index b3113530854..e19df33908f 100644 --- a/subsys/bluetooth/mesh/rpl.c +++ b/subsys/bluetooth/mesh/rpl.c @@ -41,8 +41,9 @@ static ATOMIC_DEFINE(store, CONFIG_BT_MESH_CRPL); enum { PENDING_CLEAR, PENDING_RESET, + RPL_FLAGS_COUNT, }; -static atomic_t rpl_flags; +static ATOMIC_DEFINE(rpl_flags, RPL_FLAGS_COUNT); static inline int rpl_idx(const struct bt_mesh_rpl *rpl) { @@ -133,7 +134,7 @@ bool bt_mesh_rpl_check(struct bt_mesh_net_rx *rx, /* Existing slot for given address */ if (rpl->src == rx->ctx.addr) { if (!rpl->old_iv && - atomic_test_bit(&rpl_flags, PENDING_RESET) && + atomic_test_bit(rpl_flags, PENDING_RESET) && !atomic_test_bit(store, i)) { /* Until rpl reset is finished, entry with old_iv == false and * without "store" bit set will be removed, therefore it can be @@ -178,7 +179,7 @@ void bt_mesh_rpl_clear(void) return; } - atomic_set_bit(&rpl_flags, PENDING_CLEAR); + atomic_set_bit(rpl_flags, PENDING_CLEAR); bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_RPL_PENDING); } @@ -233,7 +234,7 @@ void bt_mesh_rpl_reset(void) } if (i != 0) { - atomic_set_bit(&rpl_flags, PENDING_RESET); + atomic_set_bit(rpl_flags, PENDING_RESET); bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_RPL_PENDING); } } else { @@ -358,8 +359,8 @@ void bt_mesh_rpl_pending_store(uint16_t addr) bt_mesh_settings_store_cancel(BT_MESH_SETTINGS_RPL_PENDING); } - clr = atomic_test_and_clear_bit(&rpl_flags, PENDING_CLEAR); - rst = atomic_test_bit(&rpl_flags, PENDING_RESET); + clr = atomic_test_and_clear_bit(rpl_flags, PENDING_CLEAR); + rst = atomic_test_bit(rpl_flags, PENDING_RESET); for (int i = 0; i < ARRAY_SIZE(replay_list); i++) { struct bt_mesh_rpl *rpl = &replay_list[i]; @@ -398,7 +399,7 @@ void bt_mesh_rpl_pending_store(uint16_t addr) } } - atomic_clear_bit(&rpl_flags, PENDING_RESET); + atomic_clear_bit(rpl_flags, PENDING_RESET); if (addr == BT_MESH_ADDR_ALL_NODES) { (void)memset(&replay_list[last - shift + 1], 0, sizeof(struct bt_mesh_rpl) * shift); From 17fa0a84c7f6fbe2286a8b415b939160516bbae2 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1004/1623] [nrf fromtree] Bluetooth: Mesh: Return immediately if labels not supported MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoid unnecessary triggering of settings work. Signed-off-by: Pavel Vasilyev (cherry picked from commit 161aadd5909e610fa5e25a5912c882403718e21e) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/va.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subsys/bluetooth/mesh/va.c b/subsys/bluetooth/mesh/va.c index 6db9194da47..b69c22f40e9 100644 --- a/subsys/bluetooth/mesh/va.c +++ b/subsys/bluetooth/mesh/va.c @@ -306,6 +306,10 @@ void bt_mesh_va_clear(void) { int i; + if (CONFIG_BT_MESH_LABEL_COUNT == 0) { + return; + } + for (i = 0; i < ARRAY_SIZE(virtual_addrs); i++) { if (virtual_addrs[i].ref) { virtual_addrs[i].ref = 0U; From e9382bacb83cffda685d77a5d94702f577d41303 Mon Sep 17 00:00:00 2001 From: Mia Koen Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1005/1623] [nrf fromtree] bluetooth: mesh: Doc fix Bluetooth mesh to Mesh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SIG has changed Bluetooth mesh to Bluetooth Mesh Updating zephyr docs accordingly Leaving out old release notes Signed-off-by: Mia Koen (cherry picked from commit 0bcad093927267f5dc3b4f7d08409265baf82f23) Signed-off-by: Håvard Reierstad --- boards/arm/nrf52840_mdk/doc/index.rst | 2 +- boards/riscv/esp32c3_devkitm/doc/index.rst | 2 +- .../riscv/esp32c3_luatos_core/doc/index.rst | 2 +- doc/connectivity/bluetooth/api/mesh.rst | 4 +-- .../bluetooth/api/mesh/access.rst | 4 +-- doc/connectivity/bluetooth/api/mesh/blob.rst | 6 ++-- .../bluetooth/api/mesh/blob_cli.rst | 2 +- .../bluetooth/api/mesh/blob_srv.rst | 2 +- doc/connectivity/bluetooth/api/mesh/cfg.rst | 2 +- .../bluetooth/api/mesh/cfg_cli.rst | 2 +- .../bluetooth/api/mesh/cfg_srv.rst | 4 +-- doc/connectivity/bluetooth/api/mesh/core.rst | 4 +-- doc/connectivity/bluetooth/api/mesh/dfu.rst | 24 ++++++------- .../bluetooth/api/mesh/dfu_srv.rst | 8 ++--- .../bluetooth/api/mesh/health_srv.rst | 4 +-- .../bluetooth/api/mesh/heartbeat.rst | 2 +- .../bluetooth/api/mesh/lcd_cli.rst | 2 +- .../bluetooth/api/mesh/lcd_srv.rst | 2 +- .../bluetooth/api/mesh/models.rst | 4 +-- doc/connectivity/bluetooth/api/mesh/msg.rst | 2 +- .../bluetooth/api/mesh/od_cli.rst | 2 +- .../bluetooth/api/mesh/od_srv.rst | 2 +- .../bluetooth/api/mesh/op_agg_cli.rst | 2 +- .../bluetooth/api/mesh/priv_beacon_cli.rst | 2 +- .../bluetooth/api/mesh/priv_beacon_srv.rst | 2 +- .../bluetooth/api/mesh/provisioning.rst | 8 ++--- doc/connectivity/bluetooth/api/mesh/proxy.rst | 2 +- .../bluetooth/api/mesh/sar_cfg.rst | 4 +-- .../bluetooth/api/mesh/sar_cfg_cli.rst | 2 +- .../bluetooth/api/mesh/sar_cfg_srv.rst | 4 +-- doc/connectivity/bluetooth/api/mesh/shell.rst | 34 +++++++++---------- doc/connectivity/bluetooth/bluetooth-arch.rst | 2 +- doc/connectivity/bluetooth/overview.rst | 2 +- doc/introduction/index.rst | 2 +- doc/kernel/timeutil.rst | 2 +- doc/security/vulnerabilities.rst | 4 +-- include/zephyr/bluetooth/mesh.h | 2 +- include/zephyr/bluetooth/mesh/blob_srv.h | 2 +- include/zephyr/bluetooth/mesh/cfg.h | 2 +- include/zephyr/bluetooth/mesh/dfu_cli.h | 2 +- include/zephyr/bluetooth/mesh/dfu_metadata.h | 4 +-- include/zephyr/bluetooth/mesh/dfu_srv.h | 4 +-- include/zephyr/bluetooth/mesh/main.h | 6 ++-- samples/bluetooth/mesh/README.rst | 2 +- samples/bluetooth/mesh_demo/README.rst | 2 +- samples/bluetooth/mesh_provisioner/README.rst | 2 +- samples/boards/nrf/mesh/onoff-app/README.rst | 2 +- .../onoff_level_lighting_vnd_app/README.rst | 2 +- .../boards/reel_board/mesh_badge/README.rst | 4 +-- subsys/bluetooth/Kconfig.logging | 26 +++++++------- subsys/bluetooth/common/Kconfig | 2 +- subsys/bluetooth/mesh/Kconfig | 20 +++++------ subsys/bluetooth/mesh/access.h | 2 +- subsys/bluetooth/mesh/settings.c | 2 +- subsys/bluetooth/mesh/shell/Kconfig | 10 +++--- subsys/bluetooth/mesh/shell/shell.c | 2 +- tests/bsim/bluetooth/mesh/README.rst | 14 ++++---- tests/bsim/bluetooth/mesh/prj.conf | 2 +- tests/bsim/bluetooth/mesh/prj_mesh1d1.conf | 2 +- tests/bsim/bluetooth/mesh/src/mesh_test.h | 2 +- 60 files changed, 140 insertions(+), 140 deletions(-) diff --git a/boards/arm/nrf52840_mdk/doc/index.rst b/boards/arm/nrf52840_mdk/doc/index.rst index fce05bee593..6e0b24b65f2 100644 --- a/boards/arm/nrf52840_mdk/doc/index.rst +++ b/boards/arm/nrf52840_mdk/doc/index.rst @@ -7,7 +7,7 @@ Overview ******** The nRF52840-MDK is a versatile, easy-to-use IoT hardware platform for -Bluetooth 5, Bluetooth mesh, Thread, IEEE 802.15.4, ANT and 2.4GHz proprietary +Bluetooth 5, Bluetooth Mesh, Thread, IEEE 802.15.4, ANT and 2.4GHz proprietary applications using the nRF52840 SoC. The development kit comes with a fully integrated debugger (also known as diff --git a/boards/riscv/esp32c3_devkitm/doc/index.rst b/boards/riscv/esp32c3_devkitm/doc/index.rst index 6d21b2918c3..26f1521e087 100644 --- a/boards/riscv/esp32c3_devkitm/doc/index.rst +++ b/boards/riscv/esp32c3_devkitm/doc/index.rst @@ -18,7 +18,7 @@ The features include the following: - 32-bit core RISC-V microcontroller with a maximum clock speed of 160 MHz - 400 KB of internal RAM - 802.11b/g/n/e/i -- A Bluetooth LE subsystem that supports features of Bluetooth 5 and Bluetooth mesh +- A Bluetooth LE subsystem that supports features of Bluetooth 5 and Bluetooth Mesh - Various peripherals: - 12-bit ADC with up to 6 channels diff --git a/boards/riscv/esp32c3_luatos_core/doc/index.rst b/boards/riscv/esp32c3_luatos_core/doc/index.rst index c943931a9e6..fae8e2eb178 100644 --- a/boards/riscv/esp32c3_luatos_core/doc/index.rst +++ b/boards/riscv/esp32c3_luatos_core/doc/index.rst @@ -18,7 +18,7 @@ The features include the following: - 32-bit core RISC-V microcontroller with a maximum clock speed of 160 MHz - 400 KB of internal RAM - 802.11b/g/n/e/i -- A Bluetooth LE subsystem that supports features of Bluetooth 5 and Bluetooth mesh +- A Bluetooth LE subsystem that supports features of Bluetooth 5 and Bluetooth Mesh - Various peripherals: - 12-bit ADC with up to 6 channels diff --git a/doc/connectivity/bluetooth/api/mesh.rst b/doc/connectivity/bluetooth/api/mesh.rst index 457aa5b6895..f234ff7cedc 100644 --- a/doc/connectivity/bluetooth/api/mesh.rst +++ b/doc/connectivity/bluetooth/api/mesh.rst @@ -3,14 +3,14 @@ Bluetooth Mesh Profile ###################### -The Bluetooth mesh profile adds secure wireless multi-hop communication for +The Bluetooth Mesh profile adds secure wireless multi-hop communication for Bluetooth Low Energy. This module implements the `Bluetooth Mesh Profile Specification v1.0.1 `_. Implementation of the `Bluetooth Mesh Protocol Specification v1.1 `_ is in experimental state. -Read more about Bluetooth mesh on the +Read more about Bluetooth Mesh on the `Bluetooth SIG Website `_. .. toctree:: diff --git a/doc/connectivity/bluetooth/api/mesh/access.rst b/doc/connectivity/bluetooth/api/mesh/access.rst index 2af8e6a03b8..e4a94440556 100644 --- a/doc/connectivity/bluetooth/api/mesh/access.rst +++ b/doc/connectivity/bluetooth/api/mesh/access.rst @@ -3,7 +3,7 @@ Access layer ############ -The access layer is the application's interface to the Bluetooth mesh network. +The access layer is the application's interface to the Bluetooth Mesh network. The access layer provides mechanisms for compartmentalizing the node behavior into elements and models, which are implemented by the application. @@ -113,7 +113,7 @@ number within one publication interval. Extended models =============== -The Bluetooth mesh specification allows the mesh models to extend each other. +The Bluetooth Mesh specification allows the mesh models to extend each other. When a model extends another, it inherits that model's functionality, and extension can be used to construct complex models out of simple ones, leveraging the existing model functionality to avoid defining new opcodes. diff --git a/doc/connectivity/bluetooth/api/mesh/blob.rst b/doc/connectivity/bluetooth/api/mesh/blob.rst index 31f45289560..8395026afe4 100644 --- a/doc/connectivity/bluetooth/api/mesh/blob.rst +++ b/doc/connectivity/bluetooth/api/mesh/blob.rst @@ -5,7 +5,7 @@ BLOB Transfer models The Binary Large Object (BLOB) Transfer models implement the Bluetooth Mesh Binary Large Object Transfer Model specification version 1.0 and provide functionality for sending large binary objects -from a single source to many Target nodes over the Bluetooth mesh network. It is the underlying +from a single source to many Target nodes over the Bluetooth Mesh network. It is the underlying transport method for the :ref:`bluetooth_mesh_dfu`, but may be used for other object transfer purposes. The implementation is in experimental state. @@ -50,7 +50,7 @@ structure of the BLOB, and applications are free to define any encoding or compr on the data itself. The BLOB transfer protocol does not provide any built-in integrity checks, encryption or -authentication of the BLOB data. However, the underlying encryption of the Bluetooth mesh protocol +authentication of the BLOB data. However, the underlying encryption of the Bluetooth Mesh protocol provides data integrity checks and protects the contents of the BLOB from third parties using network and application level encryption. @@ -68,7 +68,7 @@ Chunks ------ Each block is divided into chunks. A chunk is the smallest data unit in the BLOB transfer, and must -fit inside a single Bluetooth mesh access message excluding the opcode (379 bytes or less). The +fit inside a single Bluetooth Mesh access message excluding the opcode (379 bytes or less). The mechanism for transferring chunks depends on the transfer mode. When operating in Push BLOB Transfer Mode, the chunks are sent as unacknowledged packets from the diff --git a/doc/connectivity/bluetooth/api/mesh/blob_cli.rst b/doc/connectivity/bluetooth/api/mesh/blob_cli.rst index 25b90c281c4..b4193d50334 100644 --- a/doc/connectivity/bluetooth/api/mesh/blob_cli.rst +++ b/doc/connectivity/bluetooth/api/mesh/blob_cli.rst @@ -67,7 +67,7 @@ Target nodes having the BLOB Transfer Server model subscribe to this group addre Using group addresses for transferring the BLOBs can generally increase the transfer speed, as the BLOB Transfer Client sends each message to all Target nodes at the same time. However, sending -large, segmented messages to group addresses in Bluetooth mesh is generally less reliable than +large, segmented messages to group addresses in Bluetooth Mesh is generally less reliable than sending them to unicast addresses, as there is no transport layer acknowledgment mechanism for groups. This can lead to longer recovery periods at the end of each block, and increases the risk of losing Target nodes. Using group addresses for BLOB transfers will generally only pay off if the diff --git a/doc/connectivity/bluetooth/api/mesh/blob_srv.rst b/doc/connectivity/bluetooth/api/mesh/blob_srv.rst index 918b9493ff9..0d13e92148e 100644 --- a/doc/connectivity/bluetooth/api/mesh/blob_srv.rst +++ b/doc/connectivity/bluetooth/api/mesh/blob_srv.rst @@ -77,7 +77,7 @@ Transfer recovery ***************** The state of the BLOB transfer is stored persistently. If a reboot occurs, the BLOB Transfer Server -will attempt to recover the transfer. When the Bluetooth mesh subsystem is started (for instance by +will attempt to recover the transfer. When the Bluetooth Mesh subsystem is started (for instance by calling :c:func:`bt_mesh_init`), the BLOB Transfer Server will check for aborted transfers, and call the :c:member:`recover ` callback if there is any. In the recover callback, the user must provide a BLOB stream to use for the rest of the transfer. If the recover diff --git a/doc/connectivity/bluetooth/api/mesh/cfg.rst b/doc/connectivity/bluetooth/api/mesh/cfg.rst index 01d3c9ca2e5..e178984210d 100644 --- a/doc/connectivity/bluetooth/api/mesh/cfg.rst +++ b/doc/connectivity/bluetooth/api/mesh/cfg.rst @@ -6,7 +6,7 @@ Runtime Configuration The runtime configuration API allows applications to change their runtime configuration directly, without going through the Configuration models. -Bluetooth mesh nodes should generally be configured by a central network +Bluetooth Mesh nodes should generally be configured by a central network configurator device with a :ref:`bluetooth_mesh_models_cfg_cli` model. Each mesh node instantiates a :ref:`bluetooth_mesh_models_cfg_srv` model that the Configuration Client can communicate with to change the node configuration. In some diff --git a/doc/connectivity/bluetooth/api/mesh/cfg_cli.rst b/doc/connectivity/bluetooth/api/mesh/cfg_cli.rst index bf84edc6b86..300c8ee3bc1 100644 --- a/doc/connectivity/bluetooth/api/mesh/cfg_cli.rst +++ b/doc/connectivity/bluetooth/api/mesh/cfg_cli.rst @@ -3,7 +3,7 @@ Configuration Client #################### -The Configuration Client model is a foundation model defined by the Bluetooth mesh +The Configuration Client model is a foundation model defined by the Bluetooth Mesh specification. It provides functionality for configuring most parameters of a mesh node, including encryption keys, model configuration and feature enabling. diff --git a/doc/connectivity/bluetooth/api/mesh/cfg_srv.rst b/doc/connectivity/bluetooth/api/mesh/cfg_srv.rst index 84f174df88b..8f595bf9b11 100644 --- a/doc/connectivity/bluetooth/api/mesh/cfg_srv.rst +++ b/doc/connectivity/bluetooth/api/mesh/cfg_srv.rst @@ -3,7 +3,7 @@ Configuration Server #################### -The Configuration Server model is a foundation model defined by the Bluetooth mesh +The Configuration Server model is a foundation model defined by the Bluetooth Mesh specification. The Configuration Server model controls most parameters of the mesh node. It does not have an API of its own, but relies on a :ref:`bluetooth_mesh_models_cfg_cli` to control it. @@ -14,7 +14,7 @@ mesh node. It does not have an API of its own, but relies on a should be set through Kconfig, and the Heartbeat feature should be controlled through the :ref:`bluetooth_mesh_heartbeat` API. -The Configuration Server model is mandatory on all Bluetooth mesh nodes, and +The Configuration Server model is mandatory on all Bluetooth Mesh nodes, and must only be instantiated on the primary element. API reference diff --git a/doc/connectivity/bluetooth/api/mesh/core.rst b/doc/connectivity/bluetooth/api/mesh/core.rst index b9fdd164257..94e2b8a6e5e 100644 --- a/doc/connectivity/bluetooth/api/mesh/core.rst +++ b/doc/connectivity/bluetooth/api/mesh/core.rst @@ -3,7 +3,7 @@ Core #### -The core provides functionality for managing the general Bluetooth mesh +The core provides functionality for managing the general Bluetooth Mesh state. .. _bluetooth_mesh_lpn: @@ -117,7 +117,7 @@ Advertisement identity All mesh stack bearers advertise data with the :c:macro:`BT_ID_DEFAULT` local identity. The value is preset in the mesh stack implementation. When Bluetooth® Low Energy (LE) -and Bluetooth mesh coexist on the same device, the application should allocate and +and Bluetooth Mesh coexist on the same device, the application should allocate and configure another local identity for Bluetooth LE purposes before starting the communication. API reference diff --git a/doc/connectivity/bluetooth/api/mesh/dfu.rst b/doc/connectivity/bluetooth/api/mesh/dfu.rst index 9cf55e244d6..6718b3ea0ce 100644 --- a/doc/connectivity/bluetooth/api/mesh/dfu.rst +++ b/doc/connectivity/bluetooth/api/mesh/dfu.rst @@ -3,16 +3,16 @@ Device Firmware Update (DFU) ############################ -Bluetooth mesh supports the distribution of firmware images across a mesh network. The Bluetooth +Bluetooth Mesh supports the distribution of firmware images across a mesh network. The Bluetooth mesh DFU subsystem implements the Bluetooth Mesh Device Firmware Update Model specification version 1.0. The implementation is in experimental state. -Bluetooth mesh DFU implements a distribution mechanism for firmware images, and does not put any +Bluetooth Mesh DFU implements a distribution mechanism for firmware images, and does not put any restrictions on the size, format or usage of the images. The primary design goal of the subsystem is -to provide the qualifiable parts of the Bluetooth mesh DFU specification, and leave the usage, +to provide the qualifiable parts of the Bluetooth Mesh DFU specification, and leave the usage, firmware validation and deployment to the application. -The DFU specification is implemented in the Zephyr Bluetooth mesh DFU subsystem as three separate +The DFU specification is implemented in the Zephyr Bluetooth Mesh DFU subsystem as three separate models: .. toctree:: @@ -28,7 +28,7 @@ Overview DFU roles ========= -The Bluetooth mesh DFU subsystem defines three different roles the mesh nodes have to assume in the +The Bluetooth Mesh DFU subsystem defines three different roles the mesh nodes have to assume in the distribution of firmware images: Target node @@ -47,20 +47,20 @@ Distributor image to the Target nodes. Initiator - The Initiator role is typically implemented by the same device that implements the Bluetooth mesh + The Initiator role is typically implemented by the same device that implements the Bluetooth Mesh :ref:`Provisioner ` and :ref:`Configurator ` roles. The Initiator needs a full overview of the potential Target nodes and their firmware, and will control (and initiate) all firmware updates. The - Initiator role is not implemented in the Zephyr Bluetooth mesh DFU subsystem. + Initiator role is not implemented in the Zephyr Bluetooth Mesh DFU subsystem. .. figure:: images/dfu_roles_mesh.svg :align: center :alt: Graphic overview of the DFU roles mesh nodes can have during the process of image distribution - DFU roles and the associated Bluetooth mesh models + DFU roles and the associated Bluetooth Mesh models -Bluetooth mesh applications may combine the DFU roles in any way they'd like, and even take on +Bluetooth Mesh applications may combine the DFU roles in any way they'd like, and even take on multiple instances of the same role by instantiating the models on separate elements. For instance, the Distributor and Initiator role can be combined by instantiating the :ref:`bluetooth_mesh_dfu_cli` on the Initiator node and calling its API directly. @@ -76,7 +76,7 @@ Firmware Update Client model directly, e.g. over a serial protocol. Stages ====== -The Bluetooth mesh DFU process is designed to act in three stages: +The Bluetooth Mesh DFU process is designed to act in three stages: Upload stage First, the image is uploaded to a Distributor in a mesh network by an external entity, such as a @@ -131,7 +131,7 @@ Firmware metadata Target node. The firmware metadata is optional, and its maximum length is determined by :kconfig:option:`CONFIG_BT_MESH_DFU_METADATA_MAXLEN`. - The Bluetooth mesh DFU subsystem in Zephyr provides its own metadata format + The Bluetooth Mesh DFU subsystem in Zephyr provides its own metadata format (:c:struct:`bt_mesh_dfu_metadata`) together with a set of related functions that can be used by an end product. The support for it is enabled using the :kconfig:option:`CONFIG_BT_MESH_DFU_METADATA` option. The format of the metadata is presented in @@ -299,7 +299,7 @@ following steps: node firmware image index and the firmware image metadata. Each Target node performs a metadata check and prepares their BLOB Transfer Server model for the transfer, before sending a status response to the Firmware Update Client, indicating if the firmware update will have any effect on - the Bluetooth mesh state of the node. + the Bluetooth Mesh state of the node. #. The Distributor's BLOB Transfer Client model transfers the firmware image to all Target nodes. #. Once the BLOB transfer has been received, the Target nodes' applications verify that the firmware is valid by performing checks such as signature verification or image checksums against the image diff --git a/doc/connectivity/bluetooth/api/mesh/dfu_srv.rst b/doc/connectivity/bluetooth/api/mesh/dfu_srv.rst index 2642dec8cc9..105bdecb86c 100644 --- a/doc/connectivity/bluetooth/api/mesh/dfu_srv.rst +++ b/doc/connectivity/bluetooth/api/mesh/dfu_srv.rst @@ -16,7 +16,7 @@ Firmware images The Firmware Update Server holds a list of all the updatable firmware images on the device. The full list shall be passed to the server through the ``_imgs`` parameter in -:c:macro:`BT_MESH_DFU_SRV_INIT`, and must be populated before the Bluetooth mesh subsystem is +:c:macro:`BT_MESH_DFU_SRV_INIT`, and must be populated before the Bluetooth Mesh subsystem is started. Each firmware image in the image list must be independently updatable, and should have its own firmware ID. @@ -33,9 +33,9 @@ application is described below: .. figure:: images/dfu_srv.svg :align: center - :alt: Bluetooth mesh Firmware Update Server transfer + :alt: Bluetooth Mesh Firmware Update Server transfer - Bluetooth mesh Firmware Update Server transfer + Bluetooth Mesh Firmware Update Server transfer Transfer check ============== @@ -118,7 +118,7 @@ updated image. When the transfer applies to the mesh application itself, the device might have to reboot as part of the swap. This restart can be performed from inside the apply callback, or done asynchronously. After booting up with the new firmware, the firmware image table should be updated before the -Bluetooth mesh subsystem is started. +Bluetooth Mesh subsystem is started. The Distributor will read out the firmware image table to confirm that the transfer was successfully applied. If the metadata check indicated that the device would become unprovisioned, the Target node diff --git a/doc/connectivity/bluetooth/api/mesh/health_srv.rst b/doc/connectivity/bluetooth/api/mesh/health_srv.rst index 84c543b4766..6f7b1fc3f33 100644 --- a/doc/connectivity/bluetooth/api/mesh/health_srv.rst +++ b/doc/connectivity/bluetooth/api/mesh/health_srv.rst @@ -21,7 +21,7 @@ necessarily damaging to the device. Errors indicate conditions that are outside of the node's design limits, and may have caused invalid behavior or permanent damage to the device. -Fault values ``0x01`` to ``0x7f`` are reserved for the Bluetooth mesh +Fault values ``0x01`` to ``0x7f`` are reserved for the Bluetooth Mesh specification, and the full list of specification defined faults are available in :ref:`bluetooth_mesh_health_faults`. Fault values ``0x80`` to ``0xff`` are vendor specific. The list of faults are always reported with a company ID to @@ -57,6 +57,6 @@ API reference Health faults ============= -Fault values defined by the Bluetooth mesh specification. +Fault values defined by the Bluetooth Mesh specification. .. doxygengroup:: bt_mesh_health_faults diff --git a/doc/connectivity/bluetooth/api/mesh/heartbeat.rst b/doc/connectivity/bluetooth/api/mesh/heartbeat.rst index 16c2bfa7840..706625849c1 100644 --- a/doc/connectivity/bluetooth/api/mesh/heartbeat.rst +++ b/doc/connectivity/bluetooth/api/mesh/heartbeat.rst @@ -3,7 +3,7 @@ Heartbeat ######### -The Heartbeat feature provides functionality for monitoring Bluetooth mesh nodes +The Heartbeat feature provides functionality for monitoring Bluetooth Mesh nodes and determining the distance between nodes. The Heartbeat feature is configured through the :ref:`bluetooth_mesh_models_cfg_srv` model. diff --git a/doc/connectivity/bluetooth/api/mesh/lcd_cli.rst b/doc/connectivity/bluetooth/api/mesh/lcd_cli.rst index 0eca28f1b2a..96189e21dd3 100644 --- a/doc/connectivity/bluetooth/api/mesh/lcd_cli.rst +++ b/doc/connectivity/bluetooth/api/mesh/lcd_cli.rst @@ -3,7 +3,7 @@ Large Composition Data Client ############################# -The Large Composition Data Client model is a foundation model defined by the Bluetooth mesh +The Large Composition Data Client model is a foundation model defined by the Bluetooth Mesh specification. The model is optional, and is enabled through the :kconfig:option:`CONFIG_BT_MESH_LARGE_COMP_DATA_CLI` option. diff --git a/doc/connectivity/bluetooth/api/mesh/lcd_srv.rst b/doc/connectivity/bluetooth/api/mesh/lcd_srv.rst index f96436138b7..f67b31c27f8 100644 --- a/doc/connectivity/bluetooth/api/mesh/lcd_srv.rst +++ b/doc/connectivity/bluetooth/api/mesh/lcd_srv.rst @@ -3,7 +3,7 @@ Large Composition Data Server ############################# -The Large Composition Data Server model is a foundation model defined by the Bluetooth mesh +The Large Composition Data Server model is a foundation model defined by the Bluetooth Mesh specification. The model is optional, and is enabled through the :kconfig:option:`CONFIG_BT_MESH_LARGE_COMP_DATA_SRV` option. diff --git a/doc/connectivity/bluetooth/api/mesh/models.rst b/doc/connectivity/bluetooth/api/mesh/models.rst index 3f5f94152ce..94c3914ca53 100644 --- a/doc/connectivity/bluetooth/api/mesh/models.rst +++ b/doc/connectivity/bluetooth/api/mesh/models.rst @@ -6,7 +6,7 @@ Mesh models Foundation models ***************** -The Bluetooth mesh specification defines foundation models that can be +The Bluetooth Mesh specification defines foundation models that can be used by network administrators to configure and diagnose mesh nodes. .. toctree:: @@ -34,7 +34,7 @@ used by network administrators to configure and diagnose mesh nodes. Model specification models ************************** -In addition to the foundation models defined in the Bluetooth mesh specification, the Bluetooth Mesh +In addition to the foundation models defined in the Bluetooth Mesh specification, the Bluetooth Mesh Model Specification defines several models, some of which are implemented in Zephyr: .. toctree:: diff --git a/doc/connectivity/bluetooth/api/mesh/msg.rst b/doc/connectivity/bluetooth/api/mesh/msg.rst index ae8b968198a..614d2604d90 100644 --- a/doc/connectivity/bluetooth/api/mesh/msg.rst +++ b/doc/connectivity/bluetooth/api/mesh/msg.rst @@ -3,7 +3,7 @@ Message ####### -The Bluetooth mesh message provides set of structures, macros and functions used +The Bluetooth Mesh message provides set of structures, macros and functions used for preparing message buffers, managing message and acknowledged message contexts. diff --git a/doc/connectivity/bluetooth/api/mesh/od_cli.rst b/doc/connectivity/bluetooth/api/mesh/od_cli.rst index 5fc841716ce..e419acb7572 100644 --- a/doc/connectivity/bluetooth/api/mesh/od_cli.rst +++ b/doc/connectivity/bluetooth/api/mesh/od_cli.rst @@ -3,7 +3,7 @@ On-Demand Private Proxy Client ############################## -The On-Demand Private Proxy Client model is a foundation model defined by the Bluetooth mesh +The On-Demand Private Proxy Client model is a foundation model defined by the Bluetooth Mesh specification. The model is optional, and is enabled with the :kconfig:option:`CONFIG_BT_MESH_OD_PRIV_PROXY_CLI` option. diff --git a/doc/connectivity/bluetooth/api/mesh/od_srv.rst b/doc/connectivity/bluetooth/api/mesh/od_srv.rst index 700517e4283..3c2f993bb30 100644 --- a/doc/connectivity/bluetooth/api/mesh/od_srv.rst +++ b/doc/connectivity/bluetooth/api/mesh/od_srv.rst @@ -3,7 +3,7 @@ On-Demand Private Proxy Server ############################## -The On-Demand Private Proxy Server model is a foundation model defined by the Bluetooth mesh +The On-Demand Private Proxy Server model is a foundation model defined by the Bluetooth Mesh specification. It is enabled with the :kconfig:option:`CONFIG_BT_MESH_OD_PRIV_PROXY_SRV` option. The On-Demand Private Proxy Server model was introduced in the Bluetooth Mesh Protocol Specification diff --git a/doc/connectivity/bluetooth/api/mesh/op_agg_cli.rst b/doc/connectivity/bluetooth/api/mesh/op_agg_cli.rst index 148557a4e81..4648b4495cd 100644 --- a/doc/connectivity/bluetooth/api/mesh/op_agg_cli.rst +++ b/doc/connectivity/bluetooth/api/mesh/op_agg_cli.rst @@ -3,7 +3,7 @@ Opcodes Aggregator Client ######################### -The Opcodes Aggregator Client model is a foundation model defined by the Bluetooth mesh +The Opcodes Aggregator Client model is a foundation model defined by the Bluetooth Mesh specification. It is an optional model, enabled with the :kconfig:option:`CONFIG_BT_MESH_OP_AGG_CLI` option. diff --git a/doc/connectivity/bluetooth/api/mesh/priv_beacon_cli.rst b/doc/connectivity/bluetooth/api/mesh/priv_beacon_cli.rst index cb531a4c3c8..c9bcc8e5eb1 100644 --- a/doc/connectivity/bluetooth/api/mesh/priv_beacon_cli.rst +++ b/doc/connectivity/bluetooth/api/mesh/priv_beacon_cli.rst @@ -11,7 +11,7 @@ The Private Beacon Client model is introduced in the Bluetooth Mesh Protocol Specification version 1.1, and provides functionality for configuring the :ref:`bluetooth_mesh_models_priv_beacon_srv` models. -The Private Beacons feature adds privacy to the different Bluetooth mesh +The Private Beacons feature adds privacy to the different Bluetooth Mesh beacons by periodically randomizing the beacon input data. This protects the mesh node from being tracked by devices outside the mesh network, and hides the network's IV index, IV update and the Key Refresh state. diff --git a/doc/connectivity/bluetooth/api/mesh/priv_beacon_srv.rst b/doc/connectivity/bluetooth/api/mesh/priv_beacon_srv.rst index 3c17cc44675..62450634a31 100644 --- a/doc/connectivity/bluetooth/api/mesh/priv_beacon_srv.rst +++ b/doc/connectivity/bluetooth/api/mesh/priv_beacon_srv.rst @@ -11,7 +11,7 @@ The Private Beacon Server model is introduced in the Bluetooth Mesh Protocol Specification version 1.1, and controls the mesh node's Private Beacon state, Private GATT Proxy state and Private Node Identity state. -The Private Beacons feature adds privacy to the different Bluetooth mesh +The Private Beacons feature adds privacy to the different Bluetooth Mesh beacons by periodically randomizing the beacon input data. This protects the mesh node from being tracked by devices outside the mesh network, and hides the network's IV index, IV update and the Key Refresh state. The Private Beacon Server diff --git a/doc/connectivity/bluetooth/api/mesh/provisioning.rst b/doc/connectivity/bluetooth/api/mesh/provisioning.rst index 36fa38927a3..685c9dda455 100644 --- a/doc/connectivity/bluetooth/api/mesh/provisioning.rst +++ b/doc/connectivity/bluetooth/api/mesh/provisioning.rst @@ -12,15 +12,15 @@ two devices operating in the following roles: Provisioning process. Before the provisioning process starts, the provisionee is an *unprovisioned device*. -The Provisioning module in the Zephyr Bluetooth mesh stack supports both the +The Provisioning module in the Zephyr Bluetooth Mesh stack supports both the Advertising and GATT Provisioning bearers for the provisionee role, as well as the Advertising Provisioning bearer for the provisioner role. The Provisioning process ************************ -All Bluetooth mesh nodes must be provisioned before they can participate in a -Bluetooth mesh network. The Provisioning API provides all the functionality +All Bluetooth Mesh nodes must be provisioned before they can participate in a +Bluetooth Mesh network. The Provisioning API provides all the functionality necessary for a device to become a provisioned mesh node. Provisioning is a five-step process, involving the following steps: @@ -176,7 +176,7 @@ Depending on the choice of public key exchange mechanism and authentication meth the provisioning process can be secure or insecure. On May 24th 2021, ANSSI `disclosed `_ -a set of vulnerabilities in the Bluetooth mesh provisioning protocol that showcased +a set of vulnerabilities in the Bluetooth Mesh provisioning protocol that showcased how the low entropy provided by the Blink, Vibrate, Push, Twist and Input/Output numeric OOB methods could be exploited in impersonation and MITM attacks. In response, the Bluetooth SIG has reclassified these OOB methods as diff --git a/doc/connectivity/bluetooth/api/mesh/proxy.rst b/doc/connectivity/bluetooth/api/mesh/proxy.rst index 823401c9571..5e905f2c9ef 100644 --- a/doc/connectivity/bluetooth/api/mesh/proxy.rst +++ b/doc/connectivity/bluetooth/api/mesh/proxy.rst @@ -3,7 +3,7 @@ Proxy ##### -The Proxy feature allows legacy devices like phones to access the Bluetooth mesh network through +The Proxy feature allows legacy devices like phones to access the Bluetooth Mesh network through GATT. The Proxy feature is only compiled in if the :kconfig:option:`CONFIG_BT_MESH_GATT_PROXY` option is set. The Proxy feature state is controlled by the :ref:`bluetooth_mesh_models_cfg_srv`, and the initial value can be set with :c:member:`bt_mesh_cfg_srv.gatt_proxy`. diff --git a/doc/connectivity/bluetooth/api/mesh/sar_cfg.rst b/doc/connectivity/bluetooth/api/mesh/sar_cfg.rst index a0aa2b46a3e..4f3354945c9 100644 --- a/doc/connectivity/bluetooth/api/mesh/sar_cfg.rst +++ b/doc/connectivity/bluetooth/api/mesh/sar_cfg.rst @@ -4,7 +4,7 @@ Segmentation and reassembly (SAR) ################################# Segmentation and reassembly (SAR) provides a way of handling larger upper transport layer messages -in a mesh network, with a purpose of enhancing the Bluetooth mesh throughput. The segmentation and +in a mesh network, with a purpose of enhancing the Bluetooth Mesh throughput. The segmentation and reassembly mechanism is used by the lower transport layer. The lower transport layer defines how the upper transport layer PDUs are segmented and reassembled @@ -23,7 +23,7 @@ required. Set the ``send rel`` flag (see :c:struct:`bt_mesh_msg_ctx`) to use the transmission and acknowledge single-segment segmented messages. The transport layer is able to transport up to 32 segments with its SAR mechanism, with a maximum -message (PDU) size of 384 octets. To configure message size for the Bluetooth mesh stack, use the +message (PDU) size of 384 octets. To configure message size for the Bluetooth Mesh stack, use the following Kconfig options: * :kconfig:option:`CONFIG_BT_MESH_RX_SEG_MAX` to set the maximum number of segments in an incoming message. diff --git a/doc/connectivity/bluetooth/api/mesh/sar_cfg_cli.rst b/doc/connectivity/bluetooth/api/mesh/sar_cfg_cli.rst index b017b53a01a..1e2ab6c47a1 100644 --- a/doc/connectivity/bluetooth/api/mesh/sar_cfg_cli.rst +++ b/doc/connectivity/bluetooth/api/mesh/sar_cfg_cli.rst @@ -3,7 +3,7 @@ SAR Configuration Client ######################## -The SAR Configuration Client model is a foundation model defined by the Bluetooth mesh +The SAR Configuration Client model is a foundation model defined by the Bluetooth Mesh specification. It is an optional model, enabled with the :kconfig:option:`CONFIG_BT_MESH_SAR_CFG_CLI` configuration option. diff --git a/doc/connectivity/bluetooth/api/mesh/sar_cfg_srv.rst b/doc/connectivity/bluetooth/api/mesh/sar_cfg_srv.rst index 2ea1446c9ea..4280fae1350 100644 --- a/doc/connectivity/bluetooth/api/mesh/sar_cfg_srv.rst +++ b/doc/connectivity/bluetooth/api/mesh/sar_cfg_srv.rst @@ -3,13 +3,13 @@ SAR Configuration Server ######################## -The SAR Configuration Server model is a foundation model defined by the Bluetooth mesh +The SAR Configuration Server model is a foundation model defined by the Bluetooth Mesh specification. It is an optional model, enabled with the :kconfig:option:`CONFIG_BT_MESH_SAR_CFG_SRV` configuration option. The SAR Configuration Server model is introduced in the Bluetooth Mesh Protocol Specification version 1.1, and it supports the configuration of the -:ref:`segmentation and reassembly (SAR) ` behavior of a Bluetooth mesh node. +:ref:`segmentation and reassembly (SAR) ` behavior of a Bluetooth Mesh node. The model defines a set of states and messages for the SAR configuration. The SAR Configuration Server model defines two states, SAR Transmitter state and SAR Receiver state. diff --git a/doc/connectivity/bluetooth/api/mesh/shell.rst b/doc/connectivity/bluetooth/api/mesh/shell.rst index 66bfcdf6168..9d5829fe380 100644 --- a/doc/connectivity/bluetooth/api/mesh/shell.rst +++ b/doc/connectivity/bluetooth/api/mesh/shell.rst @@ -3,32 +3,32 @@ Bluetooth Mesh Shell #################### -The Bluetooth mesh shell subsystem provides a set of Bluetooth mesh shell commands for the -:ref:`shell_api` module. It allows for testing and exploring the Bluetooth mesh API through an +The Bluetooth Mesh shell subsystem provides a set of Bluetooth Mesh shell commands for the +:ref:`shell_api` module. It allows for testing and exploring the Bluetooth Mesh API through an interactive interface, without having to write an application. -The Bluetooth mesh shell interface provides access to most Bluetooth mesh features, including +The Bluetooth Mesh shell interface provides access to most Bluetooth Mesh features, including provisioning, configuration, and message sending. Prerequisites ************* -The Bluetooth mesh shell subsystem depends on the application to create the composition data and do +The Bluetooth Mesh shell subsystem depends on the application to create the composition data and do the mesh initialization. Application *********** -The Bluetooth mesh shell subsystem is most easily used through the Bluetooth mesh shell application +The Bluetooth Mesh shell subsystem is most easily used through the Bluetooth Mesh shell application under ``tests/bluetooth/mesh_shell``. See :ref:`shell_api` for information on how to connect and -interact with the Bluetooth mesh shell application. +interact with the Bluetooth Mesh shell application. Basic usage *********** -The Bluetooth mesh shell subsystem adds a single ``mesh`` command, which holds a set of +The Bluetooth Mesh shell subsystem adds a single ``mesh`` command, which holds a set of sub-commands. Every time the device boots up, make sure to call ``mesh init`` before any of the -other Bluetooth mesh shell commands can be called:: +other Bluetooth Mesh shell commands can be called:: uart:~$ mesh init @@ -82,7 +82,7 @@ Message sending =============== With an application key added (see above), the mesh node's transition parameters are all valid, and -the Bluetooth mesh shell can send raw mesh messages through the network. +the Bluetooth Mesh shell can send raw mesh messages through the network. For example, to send a Generic OnOff Set message, call:: @@ -107,7 +107,7 @@ configured network and application keys will receive and process the messages we Sending raw mesh packets is a good way to test model message handler implementations during development, as it can be done without having to implement the sending model. By default, only the -reception of the model messages can be tested this way, as the Bluetooth mesh shell only includes +reception of the model messages can be tested this way, as the Bluetooth Mesh shell only includes the foundation models. To receive a packet in the mesh node, you have to add a model with a valid opcode handler list to the composition data in ``subsys/bluetooth/mesh/shell.c``, and print the incoming message to the shell in the handler callback. @@ -115,7 +115,7 @@ incoming message to the shell in the handler callback. Parameter formats ***************** -The Bluetooth mesh shell commands are parsed with a variety of formats: +The Bluetooth Mesh shell commands are parsed with a variety of formats: .. list-table:: Parameter formats :widths: 1 4 2 @@ -139,12 +139,12 @@ The Bluetooth mesh shell commands are parsed with a variety of formats: Commands ******** -The Bluetooth mesh shell implements a large set of commands. Some of the commands accept parameters, +The Bluetooth Mesh shell implements a large set of commands. Some of the commands accept parameters, which are mentioned in brackets after the command name. For example, ``mesh lpn set ``. Mandatory parameters are marked with angle brackets (e.g. ````), and optional parameters are marked with square brackets (e.g. ``[DstAddr]``). -The Bluetooth mesh shell commands are divided into the following groups: +The Bluetooth Mesh shell commands are divided into the following groups: .. contents:: :depth: 1 @@ -500,10 +500,10 @@ application. This shell module can be used for configuring itself and other node network. The Configuration Client uses general message parameters set by ``mesh target dst`` and ``mesh -target net`` to target specific nodes. When the Bluetooth mesh shell node is provisioned, given that +target net`` to target specific nodes. When the Bluetooth Mesh shell node is provisioned, given that the :kconfig:option:`CONFIG_BT_MESH_SHELL_PROV_CTX_INSTANCE` option is enabled with the shell provisioning context initialized, the Configuration Client model targets itself by default. -Similarly, when another node has been provisioned by the Bluetooth mesh shell, the Configuration +Similarly, when another node has been provisioned by the Bluetooth Mesh shell, the Configuration Client model targets the new node. In most common use-cases, the Configuration Client is depending on the provisioning features and the Configuration database to be fully functional. The Configuration Client always sends messages using the Device key bound to the destination address, so @@ -1645,7 +1645,7 @@ The Private Beacon Client model is an optional mesh subsystem that can be enable Opcodes Aggregator Client ------------------------- -The Opcodes Aggregator client is an optional Bluetooth mesh model that can be enabled through the +The Opcodes Aggregator client is an optional Bluetooth Mesh model that can be enabled through the :kconfig:option:`CONFIG_BT_MESH_OP_AGG_CLI` configuration option. The Opcodes Aggregator Client model is used to support the functionality of dispatching a sequence of access layer messages to nodes supporting the Opcodes Aggregator Server model. @@ -1675,7 +1675,7 @@ nodes supporting the Opcodes Aggregator Server model. Remote Provisioning Client -------------------------- -The Remote Provisioning Client is an optional Bluetooth mesh model enabled through the +The Remote Provisioning Client is an optional Bluetooth Mesh model enabled through the :kconfig:option:`CONFIG_BT_MESH_RPR_CLI` configuration option. The Remote Provisioning Client model provides support for remote provisioning of devices into a mesh network by using the Remote Provisioning Server model. diff --git a/doc/connectivity/bluetooth/bluetooth-arch.rst b/doc/connectivity/bluetooth/bluetooth-arch.rst index 9b455e680d0..ed0cf1ea9f6 100644 --- a/doc/connectivity/bluetooth/bluetooth-arch.rst +++ b/doc/connectivity/bluetooth/bluetooth-arch.rst @@ -248,7 +248,7 @@ Each role comes with its own build-time configuration option: connection-oriented roles central implicitly enables observer role, and peripheral implicitly enables broadcaster role. Usually the first step when creating an application is to decide which roles are needed and go -from there. Bluetooth mesh is a slightly special case, requiring at +from there. Bluetooth Mesh is a slightly special case, requiring at least the observer and broadcaster roles, and possibly also the Peripheral role. This will be described in more detail in a later section. diff --git a/doc/connectivity/bluetooth/overview.rst b/doc/connectivity/bluetooth/overview.rst index fece4ade496..1f727736b2d 100644 --- a/doc/connectivity/bluetooth/overview.rst +++ b/doc/connectivity/bluetooth/overview.rst @@ -76,7 +76,7 @@ Bluetooth stack. * Non-volatile storage support for permanent storage of Bluetooth-specific settings and data - * Bluetooth mesh support + * Bluetooth Mesh support * Relay, Friend Node, Low-Power Node (LPN) and GATT Proxy features * Both Provisioning roles and bearers supported (PB-ADV & PB-GATT) diff --git a/doc/introduction/index.rst b/doc/introduction/index.rst index 85968ca456a..13204e6bb7d 100644 --- a/doc/introduction/index.rst +++ b/doc/introduction/index.rst @@ -123,7 +123,7 @@ Zephyr offers a large and ever growing number of features including: **Bluetooth Low Energy 5.0 support** Bluetooth 5.0 compliant (ESR10) and Bluetooth Low Energy Controller support - (LE Link Layer). Includes Bluetooth mesh and a Bluetooth qualification-ready + (LE Link Layer). Includes Bluetooth Mesh and a Bluetooth qualification-ready Bluetooth controller. * Generic Access Profile (GAP) with all possible LE roles diff --git a/doc/kernel/timeutil.rst b/doc/kernel/timeutil.rst index d41c5b48b89..203d52ea9af 100644 --- a/doc/kernel/timeutil.rst +++ b/doc/kernel/timeutil.rst @@ -223,7 +223,7 @@ include: - GPS time: epoch of 1980-01-06T00:00:00Z, continuous following TAI with an offset of TAI-GPS=19 s. -- Bluetooth mesh time: epoch of 2000-01-01T00:00:00Z, continuous following TAI +- Bluetooth Mesh time: epoch of 2000-01-01T00:00:00Z, continuous following TAI with an offset of -32. - UNIX Leap Time: epoch of 1970-01-01T00:00:00Z, continuous following TAI with an offset of -8. diff --git a/doc/security/vulnerabilities.rst b/doc/security/vulnerabilities.rst index 61d0d25f618..fde156983d3 100644 --- a/doc/security/vulnerabilities.rst +++ b/doc/security/vulnerabilities.rst @@ -1176,7 +1176,7 @@ This has been fixed in main for v3.0.0 CVE-2022-1041 -------------- -Out-of-bound write vulnerability in the Bluetooth mesh core stack can be triggered during provisioning +Out-of-bound write vulnerability in the Bluetooth Mesh core stack can be triggered during provisioning This has been fixed in main for v3.1.0 @@ -1195,7 +1195,7 @@ This has been fixed in main for v3.1.0 CVE-2022-1042 -------------- -Out-of-bound write vulnerability in the Bluetooth mesh core stack can be triggered during provisioning +Out-of-bound write vulnerability in the Bluetooth Mesh core stack can be triggered during provisioning This has been fixed in main for v3.1.0 diff --git a/include/zephyr/bluetooth/mesh.h b/include/zephyr/bluetooth/mesh.h index a4ef70dc6de..fc84814fa44 100644 --- a/include/zephyr/bluetooth/mesh.h +++ b/include/zephyr/bluetooth/mesh.h @@ -1,5 +1,5 @@ /** @file - * @brief Bluetooth mesh Profile APIs. + * @brief Bluetooth Mesh Profile APIs. */ /* diff --git a/include/zephyr/bluetooth/mesh/blob_srv.h b/include/zephyr/bluetooth/mesh/blob_srv.h index bf807bad92f..92c809bd6b5 100644 --- a/include/zephyr/bluetooth/mesh/blob_srv.h +++ b/include/zephyr/bluetooth/mesh/blob_srv.h @@ -108,7 +108,7 @@ struct bt_mesh_blob_srv_cb { /** @brief Transfer recovery callback. * - * Called when the Bluetooth mesh subsystem is started if the device is rebooted + * Called when the Bluetooth Mesh subsystem is started if the device is rebooted * in the middle of a transfer. * * Transfers will not be resumed after a reboot if this callback is not diff --git a/include/zephyr/bluetooth/mesh/cfg.h b/include/zephyr/bluetooth/mesh/cfg.h index 7d1ca4e868f..9bfd067da9b 100644 --- a/include/zephyr/bluetooth/mesh/cfg.h +++ b/include/zephyr/bluetooth/mesh/cfg.h @@ -26,7 +26,7 @@ extern "C" { #endif -/** Bluetooth mesh feature states */ +/** Bluetooth Mesh feature states */ enum bt_mesh_feat_state { /** Feature is supported, but disabled. */ BT_MESH_FEATURE_DISABLED, diff --git a/include/zephyr/bluetooth/mesh/dfu_cli.h b/include/zephyr/bluetooth/mesh/dfu_cli.h index 3cbc220d825..ad8881ebc26 100644 --- a/include/zephyr/bluetooth/mesh/dfu_cli.h +++ b/include/zephyr/bluetooth/mesh/dfu_cli.h @@ -9,7 +9,7 @@ * @defgroup bt_mesh_dfu_cli Firmware Uppdate Client model * @ingroup bt_mesh_dfu * @{ - * @brief API for the Bluetooth mesh Firmware Update Client model + * @brief API for the Bluetooth Mesh Firmware Update Client model */ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_DFU_CLI_H__ diff --git a/include/zephyr/bluetooth/mesh/dfu_metadata.h b/include/zephyr/bluetooth/mesh/dfu_metadata.h index bec65897ac7..21d032236a7 100644 --- a/include/zephyr/bluetooth/mesh/dfu_metadata.h +++ b/include/zephyr/bluetooth/mesh/dfu_metadata.h @@ -6,10 +6,10 @@ /** * @file - * @defgroup bt_mesh_dfu_metadata Bluetooth mesh Device Firmware Update (DFU) metadata + * @defgroup bt_mesh_dfu_metadata Bluetooth Mesh Device Firmware Update (DFU) metadata * @ingroup bt_mesh_dfu * @{ - * @brief Common types and functions for the Bluetooth mesh DFU metadata. + * @brief Common types and functions for the Bluetooth Mesh DFU metadata. */ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_DFU_METADATA_H__ diff --git a/include/zephyr/bluetooth/mesh/dfu_srv.h b/include/zephyr/bluetooth/mesh/dfu_srv.h index e136701e664..2beaf2d9772 100644 --- a/include/zephyr/bluetooth/mesh/dfu_srv.h +++ b/include/zephyr/bluetooth/mesh/dfu_srv.h @@ -9,7 +9,7 @@ * @defgroup bt_mesh_dfu_srv Firmware Update Server model * @ingroup bt_mesh_dfu * @{ - * @brief API for the Bluetooth mesh Firmware Update Server model + * @brief API for the Bluetooth Mesh Firmware Update Server model */ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_DFU_SRV_H__ @@ -136,7 +136,7 @@ struct bt_mesh_dfu_srv_cb { /** @brief Transfer recovery callback. * * If the device reboots in the middle of a transfer, the Firmware Update Server - * calls this function when the Bluetooth mesh subsystem is started. + * calls this function when the Bluetooth Mesh subsystem is started. * * This callback is optional, but transfers will not be recovered after * a reboot without it. diff --git a/include/zephyr/bluetooth/mesh/main.h b/include/zephyr/bluetooth/mesh/main.h index a4e98b97f8c..8e7445fae6f 100644 --- a/include/zephyr/bluetooth/mesh/main.h +++ b/include/zephyr/bluetooth/mesh/main.h @@ -1,5 +1,5 @@ /** @file - * @brief Bluetooth mesh Protocol APIs. + * @brief Bluetooth Mesh Protocol APIs. */ /* @@ -550,8 +550,8 @@ bool bt_mesh_is_provisioned(void); */ /** - * @brief Bluetooth mesh - * @defgroup bt_mesh Bluetooth mesh + * @brief Bluetooth Mesh + * @defgroup bt_mesh Bluetooth Mesh * @ingroup bluetooth * @{ */ diff --git a/samples/bluetooth/mesh/README.rst b/samples/bluetooth/mesh/README.rst index e6ee78ba3a7..58532a0600b 100644 --- a/samples/bluetooth/mesh/README.rst +++ b/samples/bluetooth/mesh/README.rst @@ -6,7 +6,7 @@ Bluetooth: Mesh Overview ******** -This sample demonstrates Bluetooth mesh functionality. It has several +This sample demonstrates Bluetooth Mesh functionality. It has several standard mesh models, and supports provisioning over both the Advertising and the GATT Provisioning Bearers (i.e. PB-ADV and PB-GATT). The application also needs a functioning serial console, since that's diff --git a/samples/bluetooth/mesh_demo/README.rst b/samples/bluetooth/mesh_demo/README.rst index 7fe7f0908ce..2edb690ab19 100644 --- a/samples/bluetooth/mesh_demo/README.rst +++ b/samples/bluetooth/mesh_demo/README.rst @@ -6,7 +6,7 @@ Bluetooth: Mesh Demo Overview ******** -This sample is a Bluetooth mesh application intended for demonstration +This sample is a Bluetooth Mesh application intended for demonstration purposes only. The application provisions and configures itself (i.e. no external provisioner needed) with hard-coded network and application key values. The local unicast address can be set using a NODE_ADDR build diff --git a/samples/bluetooth/mesh_provisioner/README.rst b/samples/bluetooth/mesh_provisioner/README.rst index 6da113afc1b..1b37a04a4a8 100644 --- a/samples/bluetooth/mesh_provisioner/README.rst +++ b/samples/bluetooth/mesh_provisioner/README.rst @@ -6,7 +6,7 @@ Bluetooth: Mesh Provisioner Overview ******** -This sample demonstrates how to use the Bluetooth mesh APIs related to +This sample demonstrates how to use the Bluetooth Mesh APIs related to provisioning and using the Configuration Database (CDB). It is intended to be tested together with a device capable of being provisioned. For example, one could use the sample in diff --git a/samples/boards/nrf/mesh/onoff-app/README.rst b/samples/boards/nrf/mesh/onoff-app/README.rst index e8cadccd53c..35e37d6a599 100644 --- a/samples/boards/nrf/mesh/onoff-app/README.rst +++ b/samples/boards/nrf/mesh/onoff-app/README.rst @@ -6,7 +6,7 @@ Bluetooth: Mesh OnOff Model Overview ******** -This is a simple application demonstrating a Bluetooth mesh multi-element node. +This is a simple application demonstrating a Bluetooth Mesh multi-element node. Each element has a mesh onoff client and server model which controls one of the 4 sets of buttons and LEDs . diff --git a/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/README.rst b/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/README.rst index 05b8d896e77..f33bf1e7761 100644 --- a/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/README.rst +++ b/samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/README.rst @@ -4,7 +4,7 @@ Bluetooth: Mesh Generic OnOff, Generic Level, Lighting & Vendor Models ###################################################################### Overview ******** -This is a application demonstrating a Bluetooth mesh node in +This is a application demonstrating a Bluetooth Mesh node in which Root element has following models - Generic OnOff Server diff --git a/samples/boards/reel_board/mesh_badge/README.rst b/samples/boards/reel_board/mesh_badge/README.rst index d5973ab8e9c..ccfc7e771ae 100644 --- a/samples/boards/reel_board/mesh_badge/README.rst +++ b/samples/boards/reel_board/mesh_badge/README.rst @@ -6,7 +6,7 @@ Mesh Badge Overview ******** -This sample app for the reel board showcases Bluetooth mesh +This sample app for the reel board showcases Bluetooth Mesh The app starts off as a regular Bluetooth GATT peripheral application. Install the "nRF Connect" app on your phone (available both for @@ -34,7 +34,7 @@ Steps to set up you're not happy with it you can try writing something else. #. When you're happy with the text, disconnect from the board (exit the app or go back to the device scan page) -#. Once disconnected the board switches over to Bluetooth mesh mode, and you +#. Once disconnected the board switches over to Bluetooth Mesh mode, and you can't connect to it anymore over GATT. If you configure multiple boards like this they can communicate with diff --git a/subsys/bluetooth/Kconfig.logging b/subsys/bluetooth/Kconfig.logging index ec95ddad10e..6d8b999e03c 100644 --- a/subsys/bluetooth/Kconfig.logging +++ b/subsys/bluetooth/Kconfig.logging @@ -469,56 +469,56 @@ config BT_MESH_DEBUG_NET select DEPRECATED help Use this option to enable Network layer debug logs for the - Bluetooth mesh functionality. + Bluetooth Mesh functionality. config BT_MESH_DEBUG_RPL bool "[DEPRECATED] Replay protection list debug" select DEPRECATED help Use this option to enable Replay protection list debug logs - for the Bluetooth mesh functionality. + for the Bluetooth Mesh functionality. config BT_MESH_DEBUG_TRANS bool "[DEPRECATED] Transport layer debug" select DEPRECATED help Use this option to enable Transport layer debug logs for the - Bluetooth mesh functionality. + Bluetooth Mesh functionality. config BT_MESH_DEBUG_BEACON bool "[DEPRECATED] Beacon debug" select DEPRECATED help Use this option to enable Beacon-related debug logs for the - Bluetooth mesh functionality. + Bluetooth Mesh functionality. config BT_MESH_DEBUG_CRYPTO bool "[DEPRECATED] Crypto debug" select DEPRECATED help Use this option to enable cryptographic debug logs for the - Bluetooth mesh functionality. + Bluetooth Mesh functionality. config BT_MESH_DEBUG_KEYS bool "[DEPRECATED] Key management debug" select DEPRECATED help Use this option to enable key management debug logs for the - Bluetooth mesh functionality. + Bluetooth Mesh functionality. config BT_MESH_DEBUG_PROV bool "[DEPRECATED] Provisioning debug" select DEPRECATED help Use this option to enable Provisioning debug logs for the - Bluetooth mesh functionality. + Bluetooth Mesh functionality. config BT_MESH_DEBUG_PROVISIONER bool "[DEPRECATED] Provisioner debug" select DEPRECATED help Use this option to enable Provisioner debug logs for the - Bluetooth mesh functionality. + Bluetooth Mesh functionality. config BT_MESH_DEBUG_PROV_DEVICE bool "[DEPRECATED] Provisioning device debug" @@ -532,7 +532,7 @@ config BT_MESH_DEBUG_ACCESS select DEPRECATED help Use this option to enable Access layer and device composition - related debug logs for Bluetooth mesh. + related debug logs for Bluetooth Mesh. config BT_MESH_DEBUG_MODEL bool "[DEPRECATED] Foundation model debug" @@ -546,21 +546,21 @@ config BT_MESH_DEBUG_ADV select DEPRECATED help Use this option to enable advertising debug logs for - the Bluetooth mesh functionality. + the Bluetooth Mesh functionality. config BT_MESH_DEBUG_LOW_POWER bool "[DEPRECATED] Low Power debug" select DEPRECATED help Use this option to enable Low Power debug logs for the - Bluetooth mesh functionality. + Bluetooth Mesh functionality. config BT_MESH_DEBUG_FRIEND bool "[DEPRECATED] Friend debug" select DEPRECATED help Use this option to enable Friend debug logs for the - Bluetooth mesh functionality. + Bluetooth Mesh functionality. config BT_MESH_DEBUG_PROXY bool "[DEPRECATED] Proxy debug" @@ -588,7 +588,7 @@ config BT_MESH_DEBUG_CFG select DEPRECATED help Use this option to enable node configuration debug logs for the - Bluetooth mesh functionality. + Bluetooth Mesh functionality. endmenu # [DEPRECATED] Mesh diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index 7b6bc839b89..2fdc98694b1 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -243,7 +243,7 @@ config BT_HCI_MESH_EXT bool "Mesh HCI Command support" depends on BT_BROADCASTER && BT_OBSERVER && !BT_LL_SW_SPLIT help - Enable support for the Bluetooth mesh HCI Commands. + Enable support for the Bluetooth Mesh HCI Commands. config BT_WAIT_NOP bool "Wait for \"NOP\" Command Complete event during init" diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 04366828bbe..0c654e18064 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1,13 +1,13 @@ -# Bluetooth mesh configuration options +# Bluetooth Mesh configuration options # Copyright (c) 2017 Intel Corporation # SPDX-License-Identifier: Apache-2.0 menuconfig BT_MESH - bool "Bluetooth mesh support" + bool "Bluetooth Mesh support" depends on BT_OBSERVER && BT_BROADCASTER help - This option enables Bluetooth mesh support. The specific + This option enables Bluetooth Mesh support. The specific features that are available may depend on other features that have been enabled in the stack, such as GATT support. @@ -598,7 +598,7 @@ config BT_MESH_ACCESS_LAYER_MSG help This option allows the application to directly access Bluetooth access layer messages without the need to - instantiate Bluetooth mesh models. + instantiate Bluetooth Mesh models. config BT_MESH_MODEL_VND_MSG_CID_FORCE bool "Force vendor model to use the corresponding CID field message" @@ -1049,9 +1049,9 @@ config BT_MESH_FRIEND_ADV_LATENCY endif # BT_MESH_FRIEND menuconfig BT_MESH_V1d1 - bool "Bluetooth mesh v1.1 support" + bool "Bluetooth Mesh v1.1 support" help - This option enables Bluetooth mesh v1.1 support. Bluetooth mesh v1.1 + This option enables Bluetooth Mesh v1.1 support. Bluetooth Mesh v1.1 is backward compatible with v1.0.1. config BT_MESH_ECDH_P256_CMAC_AES128_AES_CCM @@ -1201,7 +1201,7 @@ config BT_MESH_DFU_METADATA bool "Support for the default metadata format" help This option adds a set of functions that can be used to encode and decode a firmware - metadata using the format defined in the Bluetooth mesh DFU subsystem. + metadata using the format defined in the Bluetooth Mesh DFU subsystem. config BT_MESH_DFU_URI_MAXLEN int "DFU URI max length" @@ -1734,16 +1734,16 @@ config BT_MESH_RPL_STORE_TIMEOUT endif # BT_MESH_RPL_STORAGE_MODE_SETTINGS && BT_SETTINGS config BT_MESH_SETTINGS_WORKQ - bool "Store the Bluetooth mesh settings in a separate work queue" + bool "Store the Bluetooth Mesh settings in a separate work queue" default y help This option enables a separate cooperative thread which is used to - store Bluetooth mesh configuration. When this option is disabled, + store Bluetooth Mesh configuration. When this option is disabled, the stack's configuration is stored in the system workqueue. This means that the system workqueue will be blocked for the time needed to store the pending data. This time may significantly increase if the flash driver does the erase operation. Enabling this option - allows Bluetooth mesh not to block the system workqueue, and thus + allows Bluetooth Mesh not to block the system workqueue, and thus process the incoming and outgoing messages while the flash driver waits for the controller to allocate the time needed to write the data and/or erase the required flash pages. diff --git a/subsys/bluetooth/mesh/access.h b/subsys/bluetooth/mesh/access.h index b7ce1abd0ea..48e0eadec10 100644 --- a/subsys/bluetooth/mesh/access.h +++ b/subsys/bluetooth/mesh/access.h @@ -94,7 +94,7 @@ void bt_mesh_msg_cb_set(void (*cb)(uint32_t opcode, struct bt_mesh_msg_ctx *ctx, * Send a mesh model layer message out into the mesh network without having instantiated * the relevant mesh models. * - * @param ctx The Bluetooth mesh message context. + * @param ctx The Bluetooth Mesh message context. * @param buf The message payload. * * @return 0 on success or negative error code on failure. diff --git a/subsys/bluetooth/mesh/settings.c b/subsys/bluetooth/mesh/settings.c index 771aad9b946..9cfcb3f5c2c 100644 --- a/subsys/bluetooth/mesh/settings.c +++ b/subsys/bluetooth/mesh/settings.c @@ -88,7 +88,7 @@ static int mesh_commit(void) } if (!atomic_test_bit(bt_dev.flags, BT_DEV_ENABLE)) { - /* The Bluetooth mesh settings loader calls bt_mesh_start() immediately + /* The Bluetooth Mesh settings loader calls bt_mesh_start() immediately * after loading the settings. This is not intended to work before * bt_enable(). The doc on @ref bt_enable requires the "bt/" settings * tree to be loaded after @ref bt_enable is completed, so this handler diff --git a/subsys/bluetooth/mesh/shell/Kconfig b/subsys/bluetooth/mesh/shell/Kconfig index 5e1e43f0057..46671c3bfaa 100644 --- a/subsys/bluetooth/mesh/shell/Kconfig +++ b/subsys/bluetooth/mesh/shell/Kconfig @@ -1,13 +1,13 @@ -# Bluetooth mesh shell configuration options +# Bluetooth Mesh shell configuration options # Copyright (c) 2022 Nordic Semiconductor # SPDX-License-Identifier: Apache-2.0 menuconfig BT_MESH_SHELL - bool "Bluetooth mesh shell" + bool "Bluetooth Mesh shell" select SHELL help - Activate shell module that provides Bluetooth mesh commands to + Activate shell module that provides Bluetooth Mesh commands to the console. if BT_MESH_SHELL @@ -24,7 +24,7 @@ config BT_MESH_SHELL_PROV_CTX_INSTANCE depends on BT_MESH_SHELL_PROV help This option enables the provisioning context instance in the - Bluetooth mesh shell module together with several provisioning + Bluetooth Mesh shell module together with several provisioning commands and target utility features. To use the provisioning context instance, use bt_mesh_shell_prov in the initialization of mesh. @@ -54,7 +54,7 @@ config BT_MESH_SHELL_HEALTH_SRV_INSTANCE depends on BT_MESH_SHELL_TEST help This option enables Health Server model instance in the - Bluetooth mesh shell module together with fault controlling + Bluetooth Mesh shell module together with fault controlling shell commands. To use the model instance, add bt_mesh_shell_health_srv to the device composition data. Use BT_MESH_SHELL_HEALTH_PUB_DEFINE to instantiate publication context. diff --git a/subsys/bluetooth/mesh/shell/shell.c b/subsys/bluetooth/mesh/shell/shell.c index a169bb16422..bb9892eb355 100644 --- a/subsys/bluetooth/mesh/shell/shell.c +++ b/subsys/bluetooth/mesh/shell/shell.c @@ -1814,5 +1814,5 @@ SHELL_STATIC_SUBCMD_SET_CREATE(mesh_cmds, SHELL_SUBCMD_SET_END ); -SHELL_CMD_ARG_REGISTER(mesh, &mesh_cmds, "Bluetooth mesh shell commands", +SHELL_CMD_ARG_REGISTER(mesh, &mesh_cmds, "Bluetooth Mesh shell commands", bt_mesh_shell_mdl_cmds_help, 1, 1); diff --git a/tests/bsim/bluetooth/mesh/README.rst b/tests/bsim/bluetooth/mesh/README.rst index 787b0084f0b..1ae78887b71 100644 --- a/tests/bsim/bluetooth/mesh/README.rst +++ b/tests/bsim/bluetooth/mesh/README.rst @@ -1,7 +1,7 @@ -Bluetooth mesh BabbleSim tests +Bluetooth Mesh BabbleSim tests ############################## -This directory contains a set of high level system tests for the Bluetooth mesh +This directory contains a set of high level system tests for the Bluetooth Mesh subsystem. The tests run on the BabbleSim simulator, using the BabbleSim test framework. @@ -10,7 +10,7 @@ subfolder of test_scripts contains tests for a specific module in the Bluetooth mesh subsystem, and each folder has a corresponding test_.c under the src/ directory containing the necessary test harnesses to execute the tests. -There's only a single test application for all the Bluetooth mesh BabbleSim +There's only a single test application for all the Bluetooth Mesh BabbleSim tests. The test application is built from this directory, and includes all test harnesses in every build. The overlying bsim test framework selects the harness to use at runtime, using the test identifiers passed in the test scripts. @@ -18,7 +18,7 @@ to use at runtime, using the test identifiers passed in the test scripts. Running the tests ***************** -The Bluetooth mesh tests have no extra requirements, and can be run using the +The Bluetooth Mesh tests have no extra requirements, and can be run using the procedure described in the parent folder. To only run the mesh tests, set ``SEARCH_PATH`` to point to this folder before @@ -57,13 +57,13 @@ Then separately, call Framework ********* -The Bluetooth mesh BabbleSim tests mainly operate on the test framework for the +The Bluetooth Mesh BabbleSim tests mainly operate on the test framework for the BabbleSim platform, but with some mesh specific additions: mesh_test.sh ============= -All test scripts in the Bluetooth mesh BabbleSim test suite follow a common +All test scripts in the Bluetooth Mesh BabbleSim test suite follow a common pattern for running a single test across N devices with different test harnesses. ``mesh_test.sh`` is sourced in each test script, and its ``RunTest`` function is called once in each script with the following parameters: @@ -113,6 +113,6 @@ has been called - otherwise, it will fail. The Bluetooth stack must be initialized in the ``test_main_f`` function of the harness, as the previous callbacks are all executed in hardware threads. -The Bluetooth mesh tests include the entire Bluetooth host and controller +The Bluetooth Mesh tests include the entire Bluetooth host and controller subsystems, so timing requirements should generally be kept fairly liberal to avoid regressions on changes in the underlying layers. diff --git a/tests/bsim/bluetooth/mesh/prj.conf b/tests/bsim/bluetooth/mesh/prj.conf index b0738c4fa05..a45bef89775 100644 --- a/tests/bsim/bluetooth/mesh/prj.conf +++ b/tests/bsim/bluetooth/mesh/prj.conf @@ -15,7 +15,7 @@ CONFIG_BT_BROADCASTER=y CONFIG_BT_CTLR_DUP_FILTER_LEN=0 CONFIG_BT_CTLR_PRIVACY=n -# Bluetooth mesh configuration +# Bluetooth Mesh configuration CONFIG_BT_MESH=y CONFIG_BT_MESH_LOG_LEVEL_DBG=y CONFIG_BT_MESH_RELAY=y diff --git a/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf b/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf index ab6066e01bf..11059c03da4 100644 --- a/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf +++ b/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf @@ -15,7 +15,7 @@ CONFIG_BT_BROADCASTER=y CONFIG_BT_CTLR_DUP_FILTER_LEN=0 CONFIG_BT_CTLR_PRIVACY=n -# Bluetooth mesh configuration +# Bluetooth Mesh configuration CONFIG_BT_MESH=y CONFIG_BT_MESH_V1d1=y CONFIG_BT_MESH_LOG_LEVEL_DBG=y diff --git a/tests/bsim/bluetooth/mesh/src/mesh_test.h b/tests/bsim/bluetooth/mesh/src/mesh_test.h index a5c8694947b..3dcaa5f784a 100644 --- a/tests/bsim/bluetooth/mesh/src/mesh_test.h +++ b/tests/bsim/bluetooth/mesh/src/mesh_test.h @@ -1,5 +1,5 @@ /** @file - * @brief Common functionality for Bluetooth mesh BabbleSim tests. + * @brief Common functionality for Bluetooth Mesh BabbleSim tests. */ /* From 8ce58a5c1e34394175903babacd17cb953bda4a2 Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1006/1623] [nrf fromtree] Bluetooth: Mesh: Align some code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Align tab 8. Signed-off-by: Lingao Meng (cherry picked from commit 3e6f751891150649d878d912f95b5cbc28a1d801) Signed-off-by: Håvard Reierstad --- include/zephyr/bluetooth/mesh/access.h | 4 ++-- include/zephyr/bluetooth/mesh/blob_cli.h | 8 ++++---- include/zephyr/bluetooth/mesh/cdb.h | 2 +- include/zephyr/bluetooth/mesh/cfg_cli.h | 20 ++++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/access.h b/include/zephyr/bluetooth/mesh/access.h index 817fba918ef..d57f30f8f05 100644 --- a/include/zephyr/bluetooth/mesh/access.h +++ b/include/zephyr/bluetooth/mesh/access.h @@ -1011,7 +1011,7 @@ const struct bt_mesh_elem *bt_mesh_model_elem(const struct bt_mesh_model *mod); * if no SIG model with the given ID exists in the given element. */ const struct bt_mesh_model *bt_mesh_model_find(const struct bt_mesh_elem *elem, - uint16_t id); + uint16_t id); /** @brief Find a vendor model. * @@ -1023,7 +1023,7 @@ const struct bt_mesh_model *bt_mesh_model_find(const struct bt_mesh_elem *elem, * if no vendor model with the given ID exists in the given element. */ const struct bt_mesh_model *bt_mesh_model_find_vnd(const struct bt_mesh_elem *elem, - uint16_t company, uint16_t id); + uint16_t company, uint16_t id); /** @brief Get whether the model is in the primary element of the device. * diff --git a/include/zephyr/bluetooth/mesh/blob_cli.h b/include/zephyr/bluetooth/mesh/blob_cli.h index 8e239b31457..9b591cfdd35 100644 --- a/include/zephyr/bluetooth/mesh/blob_cli.h +++ b/include/zephyr/bluetooth/mesh/blob_cli.h @@ -265,10 +265,10 @@ struct blob_cli_broadcast_ctx { void (*send)(struct bt_mesh_blob_cli *cli, uint16_t dst); /** Called after every @ref blob_cli_broadcast_ctx::send callback. */ void (*send_complete)(struct bt_mesh_blob_cli *cli, uint16_t dst); - /** If @ref blob_cli_broadcast_ctx::acked is true, called after all Target nodes - * have confirmed reception by @ref blob_cli_broadcast_rsp. Otherwise, called - * after transmission has been completed. - */ + /** If @ref blob_cli_broadcast_ctx::acked is true, called after all Target nodes + * have confirmed reception by @ref blob_cli_broadcast_rsp. Otherwise, called + * after transmission has been completed. + */ void (*next)(struct bt_mesh_blob_cli *cli); /** If true, every transmission needs to be confirmed by @ref blob_cli_broadcast_rsp before * @ref blob_cli_broadcast_ctx::next is called. diff --git a/include/zephyr/bluetooth/mesh/cdb.h b/include/zephyr/bluetooth/mesh/cdb.h index 800ae07edc4..8ea35ec2e55 100644 --- a/include/zephyr/bluetooth/mesh/cdb.h +++ b/include/zephyr/bluetooth/mesh/cdb.h @@ -231,7 +231,7 @@ enum { * or BT_MESH_CDB_ITER_STOP to stop. */ typedef uint8_t (*bt_mesh_cdb_node_func_t)(struct bt_mesh_cdb_node *node, - void *user_data); + void *user_data); /** @brief Node iterator. * diff --git a/include/zephyr/bluetooth/mesh/cfg_cli.h b/include/zephyr/bluetooth/mesh/cfg_cli.h index 0e8c26131ff..4aca0c17451 100644 --- a/include/zephyr/bluetooth/mesh/cfg_cli.h +++ b/include/zephyr/bluetooth/mesh/cfg_cli.h @@ -96,8 +96,8 @@ struct bt_mesh_cfg_cli_cb { * @param buf Message buffer containing subscription addresses. */ void (*mod_sub_list)(struct bt_mesh_cfg_cli *cli, uint16_t addr, uint8_t status, - uint16_t elem_addr, uint16_t mod_id, uint16_t cid, - struct net_buf_simple *buf); + uint16_t elem_addr, uint16_t mod_id, uint16_t cid, + struct net_buf_simple *buf); /** @brief Optional callback for Node Reset Status messages. * @@ -128,7 +128,7 @@ struct bt_mesh_cfg_cli_cb { * @param status Status Code for requesting message. */ void (*ttl_status)(struct bt_mesh_cfg_cli *cli, uint16_t addr, - uint8_t status); + uint8_t status); /** @brief Optional callback for Friend Status messages. * @@ -139,7 +139,7 @@ struct bt_mesh_cfg_cli_cb { * @param status Status Code for requesting message. */ void (*friend_status)(struct bt_mesh_cfg_cli *cli, uint16_t addr, - uint8_t status); + uint8_t status); /** @brief Optional callback for GATT Proxy Status messages. * @@ -150,7 +150,7 @@ struct bt_mesh_cfg_cli_cb { * @param status Status Code for requesting message. */ void (*gatt_proxy_status)(struct bt_mesh_cfg_cli *cli, uint16_t addr, - uint8_t status); + uint8_t status); /** @brief Optional callback for Network Transmit Status messages. * @@ -199,7 +199,7 @@ struct bt_mesh_cfg_cli_cb { * @param buf Message buffer containing key indexes. */ void (*net_key_list)(struct bt_mesh_cfg_cli *cli, uint16_t addr, - struct net_buf_simple *buf); + struct net_buf_simple *buf); /** @brief Optional callback for AppKey Status messages. * @@ -229,7 +229,7 @@ struct bt_mesh_cfg_cli_cb { * @param buf Message buffer containing key indexes. */ void (*app_key_list)(struct bt_mesh_cfg_cli *cli, uint16_t addr, uint8_t status, - uint16_t net_idx, struct net_buf_simple *buf); + uint16_t net_idx, struct net_buf_simple *buf); /** @brief Optional callback for Model App Status messages. * @@ -262,8 +262,8 @@ struct bt_mesh_cfg_cli_cb { * @param buf Message buffer containing key indexes. */ void (*mod_app_list)(struct bt_mesh_cfg_cli *cli, uint16_t addr, uint8_t status, - uint16_t elem_addr, uint16_t mod_id, uint16_t cid, - struct net_buf_simple *buf); + uint16_t elem_addr, uint16_t mod_id, uint16_t cid, + struct net_buf_simple *buf); /** @brief Optional callback for Node Identity Status messages. * @@ -326,7 +326,7 @@ struct bt_mesh_cfg_cli_cb { * @param sub HB subscription configuration parameters. */ void (*hb_sub_status)(struct bt_mesh_cfg_cli *cli, uint16_t addr, uint8_t status, - struct bt_mesh_cfg_cli_hb_sub *sub); + struct bt_mesh_cfg_cli_hb_sub *sub); }; /** Mesh Configuration Client Model Context */ From ac4f2cdb0c616b46fa0775bd001cc68951e62074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1007/1623] [nrf fromtree] Bluetooth: Mesh: advertiser: add disable function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a disable function for the extended advertising which stops and deletes the advertising instances, allowing them to be properly reinitialized when calling `bt_mesh_adv_enable()` after bluetooth has been disabled and re-enabled. For the legacy advertising, the function terminates the advertising thread. If legacy advertising is used, `bt_mesh_adv_init()` must be called before `bt_mesh_adv_enable()` to properly resume advertising after suspension. Signed-off-by: Håvard Reierstad (cherry picked from commit 3be26c4cb9f02ad0799ea6cc20df401d5c1fa7d2) Signed-off-by: Håvard Reierstad --- include/zephyr/bluetooth/mesh/main.h | 4 ++++ subsys/bluetooth/mesh/adv.h | 3 +++ subsys/bluetooth/mesh/adv_ext.c | 30 ++++++++++++++++++++++++++++ subsys/bluetooth/mesh/adv_legacy.c | 21 ++++++++++++++++--- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/main.h b/include/zephyr/bluetooth/mesh/main.h index 8e7445fae6f..a213e8ce22c 100644 --- a/include/zephyr/bluetooth/mesh/main.h +++ b/include/zephyr/bluetooth/mesh/main.h @@ -607,6 +607,10 @@ void bt_mesh_reset(void); * If at all possible, the Friendship feature should be used instead, to * make the node into a Low Power Node. * + * @note Should not be called from work queue due to undefined behavior. + * This is due to k_work_flush_delayable() being used in disabling of the + * extended advertising. + * * @return 0 on success, or (negative) error code on failure. */ int bt_mesh_suspend(void); diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index a80ff7e8d4b..42b07601ad5 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -80,6 +80,9 @@ int bt_mesh_scan_disable(void); int bt_mesh_adv_enable(void); +/* Should not be called from work queue due to undefined behavior */ +int bt_mesh_adv_disable(void); + void bt_mesh_adv_buf_local_ready(void); void bt_mesh_adv_buf_relay_ready(void); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index fe9fc4fd403..aaea8845ae5 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -540,6 +540,36 @@ int bt_mesh_adv_enable(void) return 0; } +int bt_mesh_adv_disable(void) +{ + int err; + struct k_work_sync sync; + + for (int i = 0; i < ARRAY_SIZE(advs); i++) { + k_work_flush_delayable(&advs[i].work, &sync); + + err = bt_le_ext_adv_stop(advs[i].instance); + if (err) { + LOG_ERR("Failed to stop adv %d", err); + return err; + } + + /* `adv_sent` is called to finish transmission of an adv buffer that was pushed to + * the host before the advertiser was stopped, but did not finish. + */ + adv_sent(advs[i].instance, NULL); + + err = bt_le_ext_adv_delete(advs[i].instance); + if (err) { + LOG_ERR("Failed to delete adv %d", err); + return err; + } + advs[i].instance = NULL; + } + + return 0; +} + int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, int32_t duration, const struct bt_data *ad, size_t ad_len, diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index a7d7dd1a320..aef13864131 100644 --- a/subsys/bluetooth/mesh/adv_legacy.c +++ b/subsys/bluetooth/mesh/adv_legacy.c @@ -39,6 +39,7 @@ LOG_MODULE_REGISTER(bt_mesh_adv_legacy); static struct k_thread adv_thread_data; static K_KERNEL_STACK_DEFINE(adv_thread_stack, CONFIG_BT_MESH_ADV_STACK_SIZE); static int32_t adv_timeout; +static bool enabled; static int bt_data_send(uint8_t num_events, uint16_t adv_int, const struct bt_data *ad, size_t ad_len, @@ -144,10 +145,9 @@ static inline void buf_send(struct net_buf *buf) static void adv_thread(void *p1, void *p2, void *p3) { LOG_DBG("started"); + struct net_buf *buf; - while (1) { - struct net_buf *buf; - + while (enabled) { if (IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER)) { buf = bt_mesh_adv_buf_get(K_NO_WAIT); if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && !buf) { @@ -188,6 +188,12 @@ static void adv_thread(void *p1, void *p2, void *p3) /* Give other threads a chance to run */ k_yield(); } + + /* Empty the advertising pool when advertising is disabled */ + while ((buf = bt_mesh_adv_buf_get(K_NO_WAIT))) { + bt_mesh_adv_send_start(0, -ENODEV, BT_MESH_ADV(buf)); + net_buf_unref(buf); + } } void bt_mesh_adv_buf_local_ready(void) @@ -221,10 +227,19 @@ void bt_mesh_adv_init(void) int bt_mesh_adv_enable(void) { + enabled = true; k_thread_start(&adv_thread_data); return 0; } +int bt_mesh_adv_disable(void) +{ + enabled = false; + k_thread_join(&adv_thread_data, K_FOREVER); + LOG_DBG("Advertising disabled"); + return 0; +} + int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, int32_t duration, const struct bt_data *ad, size_t ad_len, const struct bt_data *sd, size_t sd_len) From 00539bcdf7cd4f15f7e786d13d98c2eac828fd42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1008/1623] [nrf fromtree] Bluetooth: Mesh: suspend/resume advertising MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Disables Mesh advertising when suspending, and enables advertising when resuming Mesh. Signed-off-by: Håvard Reierstad (cherry picked from commit 897a1d0d1cec1ba8bc811a335fc414f8fe1960f0) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index 2c78ea227de..24bbd7c7e94 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -460,6 +460,13 @@ int bt_mesh_suspend(void) bt_mesh_model_foreach(model_suspend, NULL); + err = bt_mesh_adv_disable(); + if (err) { + atomic_clear_bit(bt_mesh.flags, BT_MESH_SUSPENDED); + LOG_WRN("Disabling advertisers failed (err %d)", err); + return err; + } + return 0; } @@ -488,6 +495,17 @@ int bt_mesh_resume(void) return -EALREADY; } + if (!IS_ENABLED(CONFIG_BT_EXT_ADV)) { + bt_mesh_adv_init(); + } + + err = bt_mesh_adv_enable(); + if (err) { + atomic_set_bit(bt_mesh.flags, BT_MESH_SUSPENDED); + LOG_WRN("Re-enabling advertisers failed (err %d)", err); + return err; + } + err = bt_mesh_scan_enable(); if (err) { LOG_WRN("Re-enabling scanning failed (err %d)", err); From 88122bae6f022d60b9a306908d31e2832372335c Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1009/1623] [nrf fromtree] Bluetooth: Mesh: Allow custom RPL use mesh settings work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change allows a custom RPL use pending mechanism and the mesh settings work to store pending RPL entries. `bt_mesh_rpl_pending_store` is a public API and should be implemented anyway. The custom RPL implementation has to trigger settings with the `BT_MESH_SETTINGS_RPL_PENDING` flag to ask the mesh settings work to call `bt_mesh_rpl_pending_store`. Signed-off-by: Pavel Vasilyev (cherry picked from commit bcd2aba4d755a73f06add63ea62df7b142f76ecc) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/settings.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/settings.c b/subsys/bluetooth/mesh/settings.c index 9cfcb3f5c2c..8ec9c66481a 100644 --- a/subsys/bluetooth/mesh/settings.c +++ b/subsys/bluetooth/mesh/settings.c @@ -186,8 +186,7 @@ static void store_pending(struct k_work *work) { LOG_DBG(""); - if (IS_ENABLED(CONFIG_BT_MESH_RPL_STORAGE_MODE_SETTINGS) && - atomic_test_and_clear_bit(pending_flags, BT_MESH_SETTINGS_RPL_PENDING)) { + if (atomic_test_and_clear_bit(pending_flags, BT_MESH_SETTINGS_RPL_PENDING)) { bt_mesh_rpl_pending_store(BT_MESH_ADDR_ALL_NODES); } From 353bc561d85af3e637b299aaee1b36fb75070321 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1010/1623] [nrf fromtree] Bluetooth: Mesh: Convert no opcode error to debug log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This error message may confuse when `CONFIG_BT_MESH_ACCESS_LAYER_MSG` is enabled and all messages are processed by the callback anyway. This error message also confuses when a node is subscribed to the same address as it publishes to, which makes it generating the error message every time it publishes a message. Signed-off-by: Pavel Vasilyev (cherry picked from commit ef1f2d133674255580395b6af6ed3446f4ba3412) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/access.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index dcf7f0f783b..81e2902afd1 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -1424,7 +1424,7 @@ static int element_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple op = find_op(elem, opcode, &model); if (!op) { - LOG_ERR("No OpCode 0x%08x for elem 0x%02x", opcode, elem->rt->addr); + LOG_DBG("No OpCode 0x%08x for elem 0x%02x", opcode, elem->rt->addr); return ACCESS_STATUS_WRONG_OPCODE; } From e12a81c47a25da93925863046dd79808643f1f8d Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1011/1623] [nrf fromtree] Bluetooth: Mesh: Use memslab replace with net_buf_pool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use memslab more efficiency than net_buf_pool and consume less ram with flash resource. Signed-off-by: Lingao Meng (cherry picked from commit 683098728ab548a8fdb34c575e30e6b9b7a3ed40) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/access.c | 1 - subsys/bluetooth/mesh/adv.c | 195 ++++++++++-------- subsys/bluetooth/mesh/adv.h | 51 +++-- subsys/bluetooth/mesh/adv_ext.c | 193 +++++++++-------- subsys/bluetooth/mesh/adv_legacy.c | 65 +++--- subsys/bluetooth/mesh/app_keys.c | 1 - subsys/bluetooth/mesh/beacon.c | 49 +++-- subsys/bluetooth/mesh/cfg.c | 1 - subsys/bluetooth/mesh/cfg_srv.c | 1 - subsys/bluetooth/mesh/friend.c | 15 +- subsys/bluetooth/mesh/gatt_cli.c | 1 - subsys/bluetooth/mesh/health_srv.c | 1 - subsys/bluetooth/mesh/lpn.c | 1 - subsys/bluetooth/mesh/main.c | 1 - subsys/bluetooth/mesh/net.c | 49 +++-- subsys/bluetooth/mesh/net.h | 3 +- subsys/bluetooth/mesh/pb_adv.c | 143 +++++++------ subsys/bluetooth/mesh/pb_gatt.c | 1 - subsys/bluetooth/mesh/pb_gatt_cli.c | 1 - subsys/bluetooth/mesh/pb_gatt_srv.c | 1 - subsys/bluetooth/mesh/priv_beacon_srv.c | 1 - subsys/bluetooth/mesh/prov_device.c | 1 - subsys/bluetooth/mesh/provisioner.c | 1 - subsys/bluetooth/mesh/proxy.h | 2 +- subsys/bluetooth/mesh/proxy_cli.c | 5 +- subsys/bluetooth/mesh/proxy_cli.h | 2 +- subsys/bluetooth/mesh/proxy_msg.c | 15 +- subsys/bluetooth/mesh/proxy_msg.h | 2 +- subsys/bluetooth/mesh/proxy_srv.c | 7 +- subsys/bluetooth/mesh/rpl.c | 1 - subsys/bluetooth/mesh/rpr_srv.c | 1 - subsys/bluetooth/mesh/solicitation.c | 1 - subsys/bluetooth/mesh/statistic.c | 17 +- subsys/bluetooth/mesh/statistic.h | 4 +- subsys/bluetooth/mesh/subnet.c | 1 - subsys/bluetooth/mesh/transport.c | 31 ++- subsys/bluetooth/mesh/transport_legacy.c | 31 ++- .../bsim/bluetooth/mesh/src/test_advertiser.c | 142 +++++++------ tests/bsim/bluetooth/mesh/src/test_beacon.c | 1 - tests/bsim/bluetooth/mesh/src/test_blob.c | 2 +- tests/bsim/bluetooth/mesh/src/test_dfu.c | 1 - .../bsim/bluetooth/mesh/src/test_provision.c | 1 - tests/bsim/bluetooth/mesh/src/test_scanner.c | 1 - 43 files changed, 521 insertions(+), 524 deletions(-) diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 81e2902afd1..f7de46fe167 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -19,7 +19,6 @@ #include "host/testing.h" #include "mesh.h" -#include "adv.h" #include "net.h" #include "lpn.h" #include "transport.h" diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index 548e7f3fe15..00e2a4aa7bb 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -17,7 +17,6 @@ #include "common/bt_str.h" -#include "adv.h" #include "net.h" #include "foundation.h" #include "beacon.h" @@ -47,124 +46,144 @@ static K_FIFO_DEFINE(bt_mesh_adv_queue); static K_FIFO_DEFINE(bt_mesh_relay_queue); static K_FIFO_DEFINE(bt_mesh_friend_queue); -void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv *adv) +K_MEM_SLAB_DEFINE_STATIC(local_adv_pool, sizeof(struct bt_mesh_adv), + CONFIG_BT_MESH_ADV_BUF_COUNT, __alignof__(struct bt_mesh_adv)); + +#if defined(CONFIG_BT_MESH_RELAY_BUF_COUNT) +K_MEM_SLAB_DEFINE_STATIC(relay_adv_pool, sizeof(struct bt_mesh_adv), + CONFIG_BT_MESH_RELAY_BUF_COUNT, __alignof__(struct bt_mesh_adv)); +#endif + +#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) +K_MEM_SLAB_DEFINE_STATIC(friend_adv_pool, sizeof(struct bt_mesh_adv), + CONFIG_BT_MESH_FRIEND_LPN_COUNT, __alignof__(struct bt_mesh_adv)); +#endif + +void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv_ctx *ctx) { - if (!adv->started) { - adv->started = 1; + if (!ctx->started) { + ctx->started = 1; - if (adv->cb && adv->cb->start) { - adv->cb->start(duration, err, adv->cb_data); + if (ctx->cb && ctx->cb->start) { + ctx->cb->start(duration, err, ctx->cb_data); } if (err) { - adv->cb = NULL; + ctx->cb = NULL; } else if (IS_ENABLED(CONFIG_BT_MESH_STATISTIC)) { - bt_mesh_stat_succeeded_count(adv); + bt_mesh_stat_succeeded_count(ctx); } } } -static void bt_mesh_adv_send_end(int err, struct bt_mesh_adv const *adv) +static void bt_mesh_adv_send_end(int err, struct bt_mesh_adv_ctx const *ctx) { - if (adv->started && adv->cb && adv->cb->end) { - adv->cb->end(err, adv->cb_data); + if (ctx->started && ctx->cb && ctx->cb->end) { + ctx->cb->end(err, ctx->cb_data); } } -static void adv_buf_destroy(struct net_buf *buf) +static struct bt_mesh_adv *adv_create_from_pool(struct k_mem_slab *buf_pool, + enum bt_mesh_adv_type type, + enum bt_mesh_adv_tag tag, + uint8_t xmit, k_timeout_t timeout) { - struct bt_mesh_adv adv = *BT_MESH_ADV(buf); + struct bt_mesh_adv_ctx *ctx; + struct bt_mesh_adv *adv; + int err; - net_buf_destroy(buf); + if (atomic_test_bit(bt_mesh.flags, BT_MESH_SUSPENDED)) { + LOG_WRN("Refusing to allocate buffer while suspended"); + return NULL; + } - bt_mesh_adv_send_end(0, &adv); -} + err = k_mem_slab_alloc(buf_pool, (void **)&adv, timeout); + if (err) { + return NULL; + } -NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BT_MESH_ADV_BUF_COUNT, - BT_MESH_ADV_DATA_SIZE, BT_MESH_ADV_USER_DATA_SIZE, - adv_buf_destroy); + adv->__ref = 1; -static struct bt_mesh_adv adv_local_pool[CONFIG_BT_MESH_ADV_BUF_COUNT]; + net_buf_simple_init_with_data(&adv->b, adv->__bufs, BT_MESH_ADV_DATA_SIZE); + net_buf_simple_reset(&adv->b); -#if defined(CONFIG_BT_MESH_RELAY) -NET_BUF_POOL_DEFINE(relay_buf_pool, CONFIG_BT_MESH_RELAY_BUF_COUNT, - BT_MESH_ADV_DATA_SIZE, BT_MESH_ADV_USER_DATA_SIZE, - adv_buf_destroy); + ctx = &adv->ctx; -static struct bt_mesh_adv adv_relay_pool[CONFIG_BT_MESH_RELAY_BUF_COUNT]; -#endif + (void)memset(ctx, 0, sizeof(*ctx)); -#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) -NET_BUF_POOL_DEFINE(friend_buf_pool, CONFIG_BT_MESH_FRIEND_LPN_COUNT, - BT_MESH_ADV_DATA_SIZE, BT_MESH_ADV_USER_DATA_SIZE, - adv_buf_destroy); + ctx->type = type; + ctx->tag = tag; + ctx->xmit = xmit; -static struct bt_mesh_adv adv_friend_pool[CONFIG_BT_MESH_FRIEND_LPN_COUNT]; -#endif + return adv; +} -static struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *buf_pool, - struct bt_mesh_adv *adv_pool, - enum bt_mesh_adv_type type, - enum bt_mesh_adv_tag tag, - uint8_t xmit, k_timeout_t timeout) +struct bt_mesh_adv *bt_mesh_adv_ref(struct bt_mesh_adv *adv) { - struct bt_mesh_adv *adv; - struct net_buf *buf; + __ASSERT_NO_MSG(adv->__ref < UINT8_MAX); - if (atomic_test_bit(bt_mesh.flags, BT_MESH_SUSPENDED)) { - LOG_WRN("Refusing to allocate buffer while suspended"); - return NULL; - } + adv->__ref++; - buf = net_buf_alloc(buf_pool, timeout); - if (!buf) { - return NULL; + return adv; +} + +void bt_mesh_adv_unref(struct bt_mesh_adv *adv) +{ + __ASSERT_NO_MSG(adv->__ref > 0); + + if (--adv->__ref > 0) { + return; } - adv = &adv_pool[net_buf_id(buf)]; - BT_MESH_ADV(buf) = adv; + struct k_mem_slab *slab = &local_adv_pool; + struct bt_mesh_adv_ctx ctx = adv->ctx; - (void)memset(adv, 0, sizeof(*adv)); +#if defined(CONFIG_BT_MESH_RELAY) + if (adv->ctx.tag == BT_MESH_ADV_TAG_RELAY) { + slab = &relay_adv_pool; + } +#endif - adv->type = type; - adv->tag = tag; - adv->xmit = xmit; +#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) + if (adv->ctx.tag == BT_MESH_ADV_TAG_FRIEND) { + slab = &friend_adv_pool; + } +#endif - return buf; + k_mem_slab_free(slab, (void *)adv); + bt_mesh_adv_send_end(0, &ctx); } -struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, - enum bt_mesh_adv_tag tag, - uint8_t xmit, k_timeout_t timeout) +struct bt_mesh_adv *bt_mesh_adv_create(enum bt_mesh_adv_type type, + enum bt_mesh_adv_tag tag, + uint8_t xmit, k_timeout_t timeout) { #if defined(CONFIG_BT_MESH_RELAY) if (tag == BT_MESH_ADV_TAG_RELAY) { - return bt_mesh_adv_create_from_pool(&relay_buf_pool, - adv_relay_pool, type, - tag, xmit, timeout); + return adv_create_from_pool(&relay_adv_pool, + type, tag, xmit, timeout); } #endif #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) if (tag == BT_MESH_ADV_TAG_FRIEND) { - return bt_mesh_adv_create_from_pool(&friend_buf_pool, - adv_friend_pool, type, - tag, xmit, timeout); + return adv_create_from_pool(&friend_adv_pool, + type, tag, xmit, timeout); } #endif - return bt_mesh_adv_create_from_pool(&adv_buf_pool, adv_local_pool, type, - tag, xmit, timeout); + return adv_create_from_pool(&local_adv_pool, type, + tag, xmit, timeout); } -static struct net_buf *process_events(struct k_poll_event *ev, int count) +static struct bt_mesh_adv *process_events(struct k_poll_event *ev, int count) { for (; count; ev++, count--) { LOG_DBG("ev->state %u", ev->state); switch (ev->state) { case K_POLL_STATE_FIFO_DATA_AVAILABLE: - return net_buf_get(ev->fifo, K_NO_WAIT); + return k_fifo_get(ev->fifo, K_NO_WAIT); case K_POLL_STATE_NOT_READY: case K_POLL_STATE_CANCELLED: break; @@ -177,7 +196,7 @@ static struct net_buf *process_events(struct k_poll_event *ev, int count) return NULL; } -struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) +struct bt_mesh_adv *bt_mesh_adv_get(k_timeout_t timeout) { int err; struct k_poll_event events[] = { @@ -204,22 +223,22 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) return process_events(events, ARRAY_SIZE(events)); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout) +struct bt_mesh_adv *bt_mesh_adv_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout) { if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && tags & BT_MESH_ADV_TAG_BIT_FRIEND) { - return net_buf_get(&bt_mesh_friend_queue, timeout); + return k_fifo_get(&bt_mesh_friend_queue, timeout); } if (IS_ENABLED(CONFIG_BT_MESH_RELAY) && !(tags & BT_MESH_ADV_TAG_BIT_LOCAL)) { - return net_buf_get(&bt_mesh_relay_queue, timeout); + return k_fifo_get(&bt_mesh_relay_queue, timeout); } - return bt_mesh_adv_buf_get(timeout); + return bt_mesh_adv_get(timeout); } -void bt_mesh_adv_buf_get_cancel(void) +void bt_mesh_adv_get_cancel(void) { LOG_DBG(""); @@ -234,38 +253,38 @@ void bt_mesh_adv_buf_get_cancel(void) } } -void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, +void bt_mesh_adv_send(struct bt_mesh_adv *adv, const struct bt_mesh_send_cb *cb, void *cb_data) { - LOG_DBG("type 0x%02x len %u: %s", BT_MESH_ADV(buf)->type, buf->len, - bt_hex(buf->data, buf->len)); + LOG_DBG("type 0x%02x len %u: %s", adv->ctx.type, adv->b.len, + bt_hex(adv->b.data, adv->b.len)); - BT_MESH_ADV(buf)->cb = cb; - BT_MESH_ADV(buf)->cb_data = cb_data; - BT_MESH_ADV(buf)->busy = 1U; + adv->ctx.cb = cb; + adv->ctx.cb_data = cb_data; + adv->ctx.busy = 1U; if (IS_ENABLED(CONFIG_BT_MESH_STATISTIC)) { - bt_mesh_stat_planned_count(BT_MESH_ADV(buf)); + bt_mesh_stat_planned_count(&adv->ctx); } if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_FRIEND) { - net_buf_put(&bt_mesh_friend_queue, net_buf_ref(buf)); - bt_mesh_adv_buf_friend_ready(); + adv->ctx.tag == BT_MESH_ADV_TAG_FRIEND) { + k_fifo_put(&bt_mesh_friend_queue, bt_mesh_adv_ref(adv)); + bt_mesh_adv_friend_ready(); return; } if ((IS_ENABLED(CONFIG_BT_MESH_RELAY) && - BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_RELAY) || + adv->ctx.tag == BT_MESH_ADV_TAG_RELAY) || (IS_ENABLED(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS) && - BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV)) { - net_buf_put(&bt_mesh_relay_queue, net_buf_ref(buf)); - bt_mesh_adv_buf_relay_ready(); + adv->ctx.tag == BT_MESH_ADV_TAG_PROV)) { + k_fifo_put(&bt_mesh_relay_queue, bt_mesh_adv_ref(adv)); + bt_mesh_adv_relay_ready(); return; } - net_buf_put(&bt_mesh_adv_queue, net_buf_ref(buf)); - bt_mesh_adv_buf_local_ready(); + k_fifo_put(&bt_mesh_adv_queue, bt_mesh_adv_ref(adv)); + bt_mesh_adv_local_ready(); } int bt_mesh_adv_gatt_send(void) diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index 42b07601ad5..0c936a1aa52 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -4,14 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifndef ZEPHYR_SUBSYS_BLUETOOTH_MESH_ADV_H_ +#define ZEPHYR_SUBSYS_BLUETOOTH_MESH_ADV_H_ + /* Maximum advertising data payload for a single data type */ #define BT_MESH_ADV_DATA_SIZE 29 -/* The user data is a pointer (4 bytes) to struct bt_mesh_adv */ -#define BT_MESH_ADV_USER_DATA_SIZE 4 - -#define BT_MESH_ADV(buf) (*(struct bt_mesh_adv **)net_buf_user_data(buf)) - #define BT_MESH_ADV_SCAN_UNIT(_ms) ((_ms) * 8 / 5) #define BT_MESH_SCAN_INTERVAL_MS 30 #define BT_MESH_SCAN_WINDOW_MS 30 @@ -41,7 +39,7 @@ enum bt_mesh_adv_tag_bit { BT_MESH_ADV_TAG_BIT_PROV = BIT(BT_MESH_ADV_TAG_PROV), }; -struct bt_mesh_adv { +struct bt_mesh_adv_ctx { const struct bt_mesh_send_cb *cb; void *cb_data; @@ -53,24 +51,39 @@ struct bt_mesh_adv { uint8_t xmit; }; +struct bt_mesh_adv { + sys_snode_t node; + + struct bt_mesh_adv_ctx ctx; + + struct net_buf_simple b; + + uint8_t __ref; + + uint8_t __bufs[BT_MESH_ADV_DATA_SIZE]; +}; + /* Lookup table for Advertising data types for bt_mesh_adv_type: */ extern const uint8_t bt_mesh_adv_type[BT_MESH_ADV_TYPES]; +struct bt_mesh_adv *bt_mesh_adv_ref(struct bt_mesh_adv *adv); +void bt_mesh_adv_unref(struct bt_mesh_adv *adv); + /* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */ -struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, - enum bt_mesh_adv_tag tag, - uint8_t xmit, k_timeout_t timeout); +struct bt_mesh_adv *bt_mesh_adv_create(enum bt_mesh_adv_type type, + enum bt_mesh_adv_tag tag, + uint8_t xmit, k_timeout_t timeout); -void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, +void bt_mesh_adv_send(struct bt_mesh_adv *adv, const struct bt_mesh_send_cb *cb, void *cb_data); -struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout); +struct bt_mesh_adv *bt_mesh_adv_get(k_timeout_t timeout); -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout); +struct bt_mesh_adv *bt_mesh_adv_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout); void bt_mesh_adv_gatt_update(void); -void bt_mesh_adv_buf_get_cancel(void); +void bt_mesh_adv_get_cancel(void); void bt_mesh_adv_init(void); @@ -83,13 +96,13 @@ int bt_mesh_adv_enable(void); /* Should not be called from work queue due to undefined behavior */ int bt_mesh_adv_disable(void); -void bt_mesh_adv_buf_local_ready(void); +void bt_mesh_adv_local_ready(void); -void bt_mesh_adv_buf_relay_ready(void); +void bt_mesh_adv_relay_ready(void); -void bt_mesh_adv_buf_terminate(const struct net_buf *buf); +void bt_mesh_adv_terminate(struct bt_mesh_adv *adv); -void bt_mesh_adv_buf_friend_ready(void); +void bt_mesh_adv_friend_ready(void); int bt_mesh_adv_gatt_send(void); @@ -97,9 +110,11 @@ int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, int32_t duration const struct bt_data *ad, size_t ad_len, const struct bt_data *sd, size_t sd_len); -void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv *adv); +void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv_ctx *ctx); int bt_mesh_scan_active_set(bool active); int bt_mesh_adv_bt_data_send(uint8_t num_events, uint16_t adv_interval, const struct bt_data *ad, size_t ad_len); + +#endif /* ZEPHYR_SUBSYS_BLUETOOTH_MESH_ADV_H_ */ diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index aaea8845ae5..a4f3f32ee5f 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -21,7 +21,6 @@ #include "host/hci_core.h" -#include "adv.h" #include "net.h" #include "proxy.h" #include "solicitation.h" @@ -63,14 +62,14 @@ struct bt_mesh_ext_adv { const enum bt_mesh_adv_tag_bit tags; ATOMIC_DEFINE(flags, ADV_FLAGS_NUM); struct bt_le_ext_adv *instance; - struct net_buf *buf; + struct bt_mesh_adv *adv; uint64_t timestamp; struct k_work_delayable work; struct bt_le_adv_param adv_param; }; static void send_pending_adv(struct k_work *work); -static bool schedule_send(struct bt_mesh_ext_adv *adv); +static bool schedule_send(struct bt_mesh_ext_adv *ext_adv); static struct bt_mesh_ext_adv advs[] = { [0] = { @@ -161,7 +160,7 @@ static int set_adv_randomness(uint8_t handle, int rand_us) #endif /* defined(CONFIG_BT_LL_SOFTDEVICE) */ } -static int adv_start(struct bt_mesh_ext_adv *adv, +static int adv_start(struct bt_mesh_ext_adv *ext_adv, const struct bt_le_adv_param *param, struct bt_le_ext_adv_start_param *start, const struct bt_data *ad, size_t ad_len, @@ -169,47 +168,47 @@ static int adv_start(struct bt_mesh_ext_adv *adv, { int err; - if (!adv->instance) { + if (!ext_adv->instance) { LOG_ERR("Mesh advertiser not enabled"); return -ENODEV; } - if (atomic_test_and_set_bit(adv->flags, ADV_FLAG_ACTIVE)) { + if (atomic_test_and_set_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) { LOG_ERR("Advertiser is busy"); return -EBUSY; } - if (atomic_test_bit(adv->flags, ADV_FLAG_UPDATE_PARAMS)) { - err = bt_le_ext_adv_update_param(adv->instance, param); + if (atomic_test_bit(ext_adv->flags, ADV_FLAG_UPDATE_PARAMS)) { + err = bt_le_ext_adv_update_param(ext_adv->instance, param); if (err) { LOG_ERR("Failed updating adv params: %d", err); - atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); + atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE); return err; } - atomic_set_bit_to(adv->flags, ADV_FLAG_UPDATE_PARAMS, - param != &adv->adv_param); + atomic_set_bit_to(ext_adv->flags, ADV_FLAG_UPDATE_PARAMS, + param != &ext_adv->adv_param); } - err = bt_le_ext_adv_set_data(adv->instance, ad, ad_len, sd, sd_len); + err = bt_le_ext_adv_set_data(ext_adv->instance, ad, ad_len, sd, sd_len); if (err) { LOG_ERR("Failed setting adv data: %d", err); - atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); + atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE); return err; } - adv->timestamp = k_uptime_get(); + ext_adv->timestamp = k_uptime_get(); - err = bt_le_ext_adv_start(adv->instance, start); + err = bt_le_ext_adv_start(ext_adv->instance, start); if (err) { LOG_ERR("Advertising failed: err %d", err); - atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); + atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE); } return err; } -static int bt_data_send(struct bt_mesh_ext_adv *adv, uint8_t num_events, uint16_t adv_interval, +static int bt_data_send(struct bt_mesh_ext_adv *ext_adv, uint8_t num_events, uint16_t adv_interval, const struct bt_data *ad, size_t ad_len) { struct bt_le_ext_adv_start_param start = { @@ -219,41 +218,41 @@ static int bt_data_send(struct bt_mesh_ext_adv *adv, uint8_t num_events, uint16_ adv_interval = MAX(ADV_INT_FAST_MS, adv_interval); /* Only update advertising parameters if they're different */ - if (adv->adv_param.interval_min != BT_MESH_ADV_SCAN_UNIT(adv_interval)) { - adv->adv_param.interval_min = BT_MESH_ADV_SCAN_UNIT(adv_interval); - adv->adv_param.interval_max = adv->adv_param.interval_min; - atomic_set_bit(adv->flags, ADV_FLAG_UPDATE_PARAMS); + if (ext_adv->adv_param.interval_min != BT_MESH_ADV_SCAN_UNIT(adv_interval)) { + ext_adv->adv_param.interval_min = BT_MESH_ADV_SCAN_UNIT(adv_interval); + ext_adv->adv_param.interval_max = ext_adv->adv_param.interval_min; + atomic_set_bit(ext_adv->flags, ADV_FLAG_UPDATE_PARAMS); } - return adv_start(adv, &adv->adv_param, &start, ad, ad_len, NULL, 0); + return adv_start(ext_adv, &ext_adv->adv_param, &start, ad, ad_len, NULL, 0); } -static int buf_send(struct bt_mesh_ext_adv *adv, struct net_buf *buf) +static int adv_send(struct bt_mesh_ext_adv *ext_adv, struct bt_mesh_adv *adv) { - uint8_t num_events = BT_MESH_TRANSMIT_COUNT(BT_MESH_ADV(buf)->xmit) + 1; + uint8_t num_events = BT_MESH_TRANSMIT_COUNT(adv->ctx.xmit) + 1; uint16_t duration, adv_int; struct bt_data ad; int err; - adv_int = BT_MESH_TRANSMIT_INT(BT_MESH_ADV(buf)->xmit); + adv_int = BT_MESH_TRANSMIT_INT(adv->ctx.xmit); /* Upper boundary estimate: */ duration = num_events * (adv_int + 10); - LOG_DBG("type %u len %u: %s", BT_MESH_ADV(buf)->type, - buf->len, bt_hex(buf->data, buf->len)); + LOG_DBG("type %u len %u: %s", adv->ctx.type, + adv->b.len, bt_hex(adv->b.data, adv->b.len)); LOG_DBG("count %u interval %ums duration %ums", num_events, adv_int, duration); - ad.type = bt_mesh_adv_type[BT_MESH_ADV(buf)->type]; - ad.data_len = buf->len; - ad.data = buf->data; + ad.type = bt_mesh_adv_type[adv->ctx.type]; + ad.data_len = adv->b.len; + ad.data = adv->b.data; - err = bt_data_send(adv, num_events, adv_int, &ad, 1); + err = bt_data_send(ext_adv, num_events, adv_int, &ad, 1); if (!err) { - adv->buf = net_buf_ref(buf); + ext_adv->adv = bt_mesh_adv_ref(adv); } - bt_mesh_adv_send_start(duration, err, BT_MESH_ADV(buf)); + bt_mesh_adv_send_start(duration, err, &adv->ctx); return err; } @@ -268,50 +267,50 @@ static const char * const adv_tag_to_str[] = { static void send_pending_adv(struct k_work *work) { - struct bt_mesh_ext_adv *adv; - struct net_buf *buf; + struct bt_mesh_ext_adv *ext_adv; + struct bt_mesh_adv *adv; int err; - adv = CONTAINER_OF(work, struct bt_mesh_ext_adv, work.work); + ext_adv = CONTAINER_OF(work, struct bt_mesh_ext_adv, work.work); - if (atomic_test_and_clear_bit(adv->flags, ADV_FLAG_SENT)) { + if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_SENT)) { /* Calling k_uptime_delta on a timestamp moves it to the current time. * This is essential here, as schedule_send() uses the end of the event * as a reference to avoid sending the next advertisement too soon. */ - int64_t duration = k_uptime_delta(&adv->timestamp); + int64_t duration = k_uptime_delta(&ext_adv->timestamp); LOG_DBG("Advertising stopped after %u ms for %s", (uint32_t)duration, - adv->buf ? adv_tag_to_str[BT_MESH_ADV(adv->buf)->tag] : + ext_adv->adv ? adv_tag_to_str[ext_adv->adv->ctx.tag] : adv_tag_to_str[BT_MESH_ADV_TAG_PROXY]); - atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); - atomic_clear_bit(adv->flags, ADV_FLAG_PROXY); - atomic_clear_bit(adv->flags, ADV_FLAG_PROXY_START); + atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE); + atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY); + atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START); - if (adv->buf) { - net_buf_unref(adv->buf); - adv->buf = NULL; + if (ext_adv->adv) { + bt_mesh_adv_unref(ext_adv->adv); + ext_adv->adv = NULL; } - (void)schedule_send(adv); + (void)schedule_send(ext_adv); return; } - atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULED); + atomic_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULED); - while ((buf = bt_mesh_adv_buf_get_by_tag(adv->tags, K_NO_WAIT))) { + while ((adv = bt_mesh_adv_get_by_tag(ext_adv->tags, K_NO_WAIT))) { /* busy == 0 means this was canceled */ - if (!BT_MESH_ADV(buf)->busy) { - net_buf_unref(buf); + if (!adv->ctx.busy) { + bt_mesh_adv_unref(adv); continue; } - BT_MESH_ADV(buf)->busy = 0U; - err = buf_send(adv, buf); + adv->ctx.busy = 0U; + err = adv_send(ext_adv, adv); - net_buf_unref(buf); + bt_mesh_adv_unref(adv); if (!err) { return; /* Wait for advertising to finish */ @@ -319,7 +318,7 @@ static void send_pending_adv(struct k_work *work) } if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || - !(adv->tags & BT_MESH_ADV_TAG_BIT_PROXY)) { + !(ext_adv->tags & BT_MESH_ADV_TAG_BIT_PROXY)) { return; } @@ -328,51 +327,51 @@ static void send_pending_adv(struct k_work *work) return; } - atomic_set_bit(adv->flags, ADV_FLAG_PROXY_START); + atomic_set_bit(ext_adv->flags, ADV_FLAG_PROXY_START); if (!bt_mesh_adv_gatt_send()) { - atomic_set_bit(adv->flags, ADV_FLAG_PROXY); + atomic_set_bit(ext_adv->flags, ADV_FLAG_PROXY); } - if (atomic_test_and_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING)) { - schedule_send(adv); + if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING)) { + schedule_send(ext_adv); } } -static bool schedule_send(struct bt_mesh_ext_adv *adv) +static bool schedule_send(struct bt_mesh_ext_adv *ext_adv) { uint64_t timestamp; int64_t delta; - timestamp = adv->timestamp; + timestamp = ext_adv->timestamp; - if (atomic_test_and_clear_bit(adv->flags, ADV_FLAG_PROXY)) { - atomic_clear_bit(adv->flags, ADV_FLAG_PROXY_START); - (void)bt_le_ext_adv_stop(adv->instance); + if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_PROXY)) { + atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START); + (void)bt_le_ext_adv_stop(ext_adv->instance); - atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); + atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE); } - if (atomic_test_bit(adv->flags, ADV_FLAG_ACTIVE)) { - atomic_set_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); + if (atomic_test_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) { + atomic_set_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING); return false; - } else if (atomic_test_and_set_bit(adv->flags, ADV_FLAG_SCHEDULED)) { + } else if (atomic_test_and_set_bit(ext_adv->flags, ADV_FLAG_SCHEDULED)) { return false; } - atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); + atomic_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING); if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - adv->tags & BT_MESH_ADV_TAG_BIT_FRIEND) || - (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_BIT_RELAY)) { - k_work_reschedule(&adv->work, K_NO_WAIT); + ext_adv->tags & BT_MESH_ADV_TAG_BIT_FRIEND) || + (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && ext_adv->tags & BT_MESH_ADV_TAG_BIT_RELAY)) { + k_work_reschedule(&ext_adv->work, K_NO_WAIT); } else { /* The controller will send the next advertisement immediately. * Introduce a delay here to avoid sending the next mesh packet closer * to the previous packet than what's permitted by the specification. */ delta = k_uptime_delta(×tamp); - k_work_reschedule(&adv->work, K_MSEC(ADV_INT_FAST_MS - delta)); + k_work_reschedule(&ext_adv->work, K_MSEC(ADV_INT_FAST_MS - delta)); } return true; @@ -383,17 +382,17 @@ void bt_mesh_adv_gatt_update(void) (void)schedule_send(gatt_adv_get()); } -void bt_mesh_adv_buf_local_ready(void) +void bt_mesh_adv_local_ready(void) { (void)schedule_send(advs); } -void bt_mesh_adv_buf_relay_ready(void) +void bt_mesh_adv_relay_ready(void) { - struct bt_mesh_ext_adv *adv = relay_adv_get(); + struct bt_mesh_ext_adv *ext_adv = relay_adv_get(); for (int i = 0; i < CONFIG_BT_MESH_RELAY_ADV_SETS; i++) { - if (schedule_send(&adv[i])) { + if (schedule_send(&ext_adv[i])) { return; } } @@ -404,7 +403,7 @@ void bt_mesh_adv_buf_relay_ready(void) } } -void bt_mesh_adv_buf_friend_ready(void) +void bt_mesh_adv_friend_ready(void) { if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { schedule_send(&advs[1 + CONFIG_BT_MESH_RELAY_ADV_SETS]); @@ -413,33 +412,33 @@ void bt_mesh_adv_buf_friend_ready(void) } } -void bt_mesh_adv_buf_terminate(const struct net_buf *buf) +void bt_mesh_adv_terminate(struct bt_mesh_adv *adv) { int err; for (int i = 0; i < ARRAY_SIZE(advs); i++) { - struct bt_mesh_ext_adv *adv = &advs[i]; + struct bt_mesh_ext_adv *ext_adv = &advs[i]; - if (adv->buf != buf) { + if (ext_adv->adv != adv) { continue; } - if (!atomic_test_bit(adv->flags, ADV_FLAG_ACTIVE)) { + if (!atomic_test_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) { return; } - err = bt_le_ext_adv_stop(adv->instance); + err = bt_le_ext_adv_stop(ext_adv->instance); if (err) { LOG_ERR("Failed to stop adv %d", err); return; } /* Do not call `cb:end`, since this user action */ - BT_MESH_ADV(adv->buf)->cb = NULL; + adv->ctx.cb = NULL; - atomic_set_bit(adv->flags, ADV_FLAG_SENT); + atomic_set_bit(ext_adv->flags, ADV_FLAG_SENT); - k_work_submit(&adv->work.work); + k_work_submit(&ext_adv->work.work); return; } @@ -475,31 +474,31 @@ static struct bt_mesh_ext_adv *adv_instance_find(struct bt_le_ext_adv *instance) static void adv_sent(struct bt_le_ext_adv *instance, struct bt_le_ext_adv_sent_info *info) { - struct bt_mesh_ext_adv *adv = adv_instance_find(instance); + struct bt_mesh_ext_adv *ext_adv = adv_instance_find(instance); - if (!adv) { + if (!ext_adv) { LOG_WRN("Unexpected adv instance"); return; } - if (!atomic_test_bit(adv->flags, ADV_FLAG_ACTIVE)) { + if (!atomic_test_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) { return; } - atomic_set_bit(adv->flags, ADV_FLAG_SENT); + atomic_set_bit(ext_adv->flags, ADV_FLAG_SENT); - k_work_submit(&adv->work.work); + k_work_submit(&ext_adv->work.work); } #if defined(CONFIG_BT_MESH_GATT_SERVER) static void connected(struct bt_le_ext_adv *instance, struct bt_le_ext_adv_connected_info *info) { - struct bt_mesh_ext_adv *adv = gatt_adv_get(); + struct bt_mesh_ext_adv *ext_adv = gatt_adv_get(); - if (atomic_test_and_clear_bit(adv->flags, ADV_FLAG_PROXY_START)) { - atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); - (void)schedule_send(adv); + if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START)) { + atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE); + (void)schedule_send(ext_adv); } } #endif /* CONFIG_BT_MESH_GATT_SERVER */ @@ -575,7 +574,7 @@ int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, const struct bt_data *ad, size_t ad_len, const struct bt_data *sd, size_t sd_len) { - struct bt_mesh_ext_adv *adv = gatt_adv_get(); + struct bt_mesh_ext_adv *ext_adv = gatt_adv_get(); struct bt_le_ext_adv_start_param start = { /* Timeout is set in 10 ms steps, with 0 indicating "forever" */ .timeout = (duration == SYS_FOREVER_MS) ? 0 : MAX(1, duration / 10), @@ -583,9 +582,9 @@ int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, LOG_DBG("Start advertising %d ms", duration); - atomic_set_bit(adv->flags, ADV_FLAG_UPDATE_PARAMS); + atomic_set_bit(ext_adv->flags, ADV_FLAG_UPDATE_PARAMS); - return adv_start(adv, param, &start, ad, ad_len, sd, sd_len); + return adv_start(ext_adv, param, &start, ad, ad_len, sd, sd_len); } int bt_mesh_adv_bt_data_send(uint8_t num_events, uint16_t adv_interval, diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index aef13864131..d4003e497bb 100644 --- a/subsys/bluetooth/mesh/adv_legacy.c +++ b/subsys/bluetooth/mesh/adv_legacy.c @@ -19,7 +19,6 @@ #include "host/hci_core.h" -#include "adv.h" #include "net.h" #include "foundation.h" #include "beacon.h" @@ -43,7 +42,7 @@ static bool enabled; static int bt_data_send(uint8_t num_events, uint16_t adv_int, const struct bt_data *ad, size_t ad_len, - struct bt_mesh_adv *adv) + struct bt_mesh_adv_ctx *ctx) { struct bt_le_adv_param param = {}; uint64_t uptime = k_uptime_get(); @@ -101,8 +100,8 @@ static int bt_data_send(uint8_t num_events, uint16_t adv_int, LOG_DBG("Advertising started. Sleeping %u ms", duration); - if (adv) { - bt_mesh_adv_send_start(duration, err, adv); + if (ctx) { + bt_mesh_adv_send_start(duration, err, ctx); } k_sleep(K_MSEC(duration)); @@ -124,37 +123,37 @@ int bt_mesh_adv_bt_data_send(uint8_t num_events, uint16_t adv_int, return bt_data_send(num_events, adv_int, ad, ad_len, NULL); } -static inline void buf_send(struct net_buf *buf) +static inline void adv_send(struct bt_mesh_adv *adv) { - uint16_t num_events = BT_MESH_TRANSMIT_COUNT(BT_MESH_ADV(buf)->xmit) + 1; + uint16_t num_events = BT_MESH_TRANSMIT_COUNT(adv->ctx.xmit) + 1; uint16_t adv_int; struct bt_data ad; - adv_int = BT_MESH_TRANSMIT_INT(BT_MESH_ADV(buf)->xmit); + adv_int = BT_MESH_TRANSMIT_INT(adv->ctx.xmit); - LOG_DBG("type %u len %u: %s", BT_MESH_ADV(buf)->type, - buf->len, bt_hex(buf->data, buf->len)); + LOG_DBG("type %u len %u: %s", adv->ctx.type, + adv->b.len, bt_hex(adv->b.data, adv->b.len)); - ad.type = bt_mesh_adv_type[BT_MESH_ADV(buf)->type]; - ad.data_len = buf->len; - ad.data = buf->data; + ad.type = bt_mesh_adv_type[adv->ctx.type]; + ad.data_len = adv->b.len; + ad.data = adv->b.data; - bt_data_send(num_events, adv_int, &ad, 1, BT_MESH_ADV(buf)); + bt_data_send(num_events, adv_int, &ad, 1, &adv->ctx); } static void adv_thread(void *p1, void *p2, void *p3) { LOG_DBG("started"); - struct net_buf *buf; + struct bt_mesh_adv *adv; while (enabled) { if (IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER)) { - buf = bt_mesh_adv_buf_get(K_NO_WAIT); - if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && !buf) { + adv = bt_mesh_adv_get(K_NO_WAIT); + if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && !adv) { (void)bt_mesh_sol_send(); } - while (!buf) { + while (!adv) { /* Adv timeout may be set by a call from proxy * to bt_mesh_adv_gatt_start: @@ -162,58 +161,58 @@ static void adv_thread(void *p1, void *p2, void *p3) adv_timeout = SYS_FOREVER_MS; (void)bt_mesh_adv_gatt_send(); - buf = bt_mesh_adv_buf_get(SYS_TIMEOUT_MS(adv_timeout)); + adv = bt_mesh_adv_get(SYS_TIMEOUT_MS(adv_timeout)); bt_le_adv_stop(); - if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && !buf) { + if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && !adv) { (void)bt_mesh_sol_send(); } } } else { - buf = bt_mesh_adv_buf_get(K_FOREVER); + adv = bt_mesh_adv_get(K_FOREVER); } - if (!buf) { + if (!adv) { continue; } /* busy == 0 means this was canceled */ - if (BT_MESH_ADV(buf)->busy) { - BT_MESH_ADV(buf)->busy = 0U; - buf_send(buf); + if (adv->ctx.busy) { + adv->ctx.busy = 0U; + adv_send(adv); } - net_buf_unref(buf); + bt_mesh_adv_unref(adv); /* Give other threads a chance to run */ k_yield(); } /* Empty the advertising pool when advertising is disabled */ - while ((buf = bt_mesh_adv_buf_get(K_NO_WAIT))) { - bt_mesh_adv_send_start(0, -ENODEV, BT_MESH_ADV(buf)); - net_buf_unref(buf); + while ((adv = bt_mesh_adv_get(K_NO_WAIT))) { + bt_mesh_adv_send_start(0, -ENODEV, &adv->ctx); + bt_mesh_adv_unref(adv); } } -void bt_mesh_adv_buf_local_ready(void) +void bt_mesh_adv_local_ready(void) { /* Will be handled automatically */ } -void bt_mesh_adv_buf_relay_ready(void) +void bt_mesh_adv_relay_ready(void) { /* Will be handled automatically */ } void bt_mesh_adv_gatt_update(void) { - bt_mesh_adv_buf_get_cancel(); + bt_mesh_adv_get_cancel(); } -void bt_mesh_adv_buf_terminate(const struct net_buf *buf) +void bt_mesh_adv_terminate(struct bt_mesh_adv *adv) { - ARG_UNUSED(buf); + ARG_UNUSED(adv); } void bt_mesh_adv_init(void) diff --git a/subsys/bluetooth/mesh/app_keys.c b/subsys/bluetooth/mesh/app_keys.c index a47d31447c5..5afd887a8e8 100644 --- a/subsys/bluetooth/mesh/app_keys.c +++ b/subsys/bluetooth/mesh/app_keys.c @@ -17,7 +17,6 @@ #include "rpl.h" #include "settings.h" #include "crypto.h" -#include "adv.h" #include "proxy.h" #include "friend.h" #include "foundation.h" diff --git a/subsys/bluetooth/mesh/beacon.c b/subsys/bluetooth/mesh/beacon.c index afdea5b4c6a..ef337f9f510 100644 --- a/subsys/bluetooth/mesh/beacon.c +++ b/subsys/bluetooth/mesh/beacon.c @@ -16,7 +16,6 @@ #include "common/bt_str.h" -#include "adv.h" #include "mesh.h" #include "net.h" #include "prov.h" @@ -256,7 +255,7 @@ static bool net_beacon_send(struct bt_mesh_subnet *sub, struct bt_mesh_beacon *b .end = beacon_complete, }; uint32_t now = k_uptime_get_32(); - struct net_buf *buf; + struct bt_mesh_adv *adv; uint32_t time_diff; uint32_t time_since_last_recv; int err; @@ -271,19 +270,19 @@ static bool net_beacon_send(struct bt_mesh_subnet *sub, struct bt_mesh_beacon *b return false; } - buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, + adv = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, PROV_XMIT, K_NO_WAIT); - if (!buf) { - LOG_ERR("Unable to allocate beacon buffer"); + if (!adv) { + LOG_ERR("Unable to allocate beacon adv"); return true; /* Bail out */ } - err = beacon_create(sub, &buf->b); + err = beacon_create(sub, &adv->b); if (!err) { - bt_mesh_adv_send(buf, &send_cb, beacon); + bt_mesh_adv_send(adv, &send_cb, beacon); } - net_buf_unref(buf); + bt_mesh_adv_unref(adv); return err != 0; } @@ -330,22 +329,22 @@ static int unprovisioned_beacon_send(void) { const struct bt_mesh_prov *prov; uint8_t uri_hash[16] = { 0 }; - struct net_buf *buf; + struct bt_mesh_adv *adv; uint16_t oob_info; LOG_DBG(""); - buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, + adv = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, UNPROV_XMIT, K_NO_WAIT); - if (!buf) { - LOG_ERR("Unable to allocate beacon buffer"); + if (!adv) { + LOG_ERR("Unable to allocate beacon adv"); return -ENOBUFS; } prov = bt_mesh_prov_get(); - net_buf_add_u8(buf, BEACON_TYPE_UNPROVISIONED); - net_buf_add_mem(buf, prov->uuid, 16); + net_buf_simple_add_u8(&adv->b, BEACON_TYPE_UNPROVISIONED); + net_buf_simple_add_mem(&adv->b, prov->uuid, 16); if (prov->uri && bt_mesh_s1_str(prov->uri, uri_hash) == 0) { oob_info = prov->oob_info | BT_MESH_PROV_OOB_URI; @@ -353,31 +352,31 @@ static int unprovisioned_beacon_send(void) oob_info = prov->oob_info; } - net_buf_add_be16(buf, oob_info); - net_buf_add_mem(buf, uri_hash, 4); + net_buf_simple_add_be16(&adv->b, oob_info); + net_buf_simple_add_mem(&adv->b, uri_hash, 4); - bt_mesh_adv_send(buf, NULL, NULL); - net_buf_unref(buf); + bt_mesh_adv_send(adv, NULL, NULL); + bt_mesh_adv_unref(adv); if (prov->uri) { size_t len; - buf = bt_mesh_adv_create(BT_MESH_ADV_URI, BT_MESH_ADV_TAG_LOCAL, + adv = bt_mesh_adv_create(BT_MESH_ADV_URI, BT_MESH_ADV_TAG_LOCAL, UNPROV_XMIT, K_NO_WAIT); - if (!buf) { - LOG_ERR("Unable to allocate URI buffer"); + if (!adv) { + LOG_ERR("Unable to allocate URI adv"); return -ENOBUFS; } len = strlen(prov->uri); - if (net_buf_tailroom(buf) < len) { + if (net_buf_simple_tailroom(&adv->b) < len) { LOG_WRN("Too long URI to fit advertising data"); } else { - net_buf_add_mem(buf, prov->uri, len); - bt_mesh_adv_send(buf, NULL, NULL); + net_buf_simple_add_mem(&adv->b, prov->uri, len); + bt_mesh_adv_send(adv, NULL, NULL); } - net_buf_unref(buf); + bt_mesh_adv_unref(adv); } return 0; diff --git a/subsys/bluetooth/mesh/cfg.c b/subsys/bluetooth/mesh/cfg.c index c7bea0d29b0..4fef60d5c8d 100644 --- a/subsys/bluetooth/mesh/cfg.c +++ b/subsys/bluetooth/mesh/cfg.c @@ -14,7 +14,6 @@ #include "settings.h" #include "heartbeat.h" #include "friend.h" -#include "adv.h" #include "cfg.h" #include "od_priv_proxy.h" #include "priv_beacon.h" diff --git a/subsys/bluetooth/mesh/cfg_srv.c b/subsys/bluetooth/mesh/cfg_srv.c index fa6bb48703a..268f883d8b8 100644 --- a/subsys/bluetooth/mesh/cfg_srv.c +++ b/subsys/bluetooth/mesh/cfg_srv.c @@ -21,7 +21,6 @@ #include "host/testing.h" #include "mesh.h" -#include "adv.h" #include "net.h" #include "rpl.h" #include "lpn.h" diff --git a/subsys/bluetooth/mesh/friend.c b/subsys/bluetooth/mesh/friend.c index 73b75eadf4f..6fbd9f81a68 100644 --- a/subsys/bluetooth/mesh/friend.c +++ b/subsys/bluetooth/mesh/friend.c @@ -13,7 +13,6 @@ #include #include "crypto.h" -#include "adv.h" #include "mesh.h" #include "net.h" #include "app_keys.h" @@ -1239,7 +1238,7 @@ static void friend_timeout(struct k_work *work) .start = buf_send_start, .end = buf_send_end, }; - struct net_buf *buf; + struct bt_mesh_adv *adv; uint8_t md; if (!friend_is_allocated(frnd)) { @@ -1281,19 +1280,19 @@ static void friend_timeout(struct k_work *work) frnd->queue_size--; send_last: - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_FRIEND, + adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_FRIEND, FRIEND_XMIT, K_NO_WAIT); - if (!buf) { - LOG_ERR("Unable to allocate friend adv buffer"); + if (!adv) { + LOG_ERR("Unable to allocate friend adv"); return; } - net_buf_add_mem(buf, frnd->last->data, frnd->last->len); + net_buf_simple_add_mem(&adv->b, frnd->last->data, frnd->last->len); frnd->pending_req = 0U; frnd->pending_buf = 1U; - bt_mesh_adv_send(buf, &buf_sent_cb, frnd); - net_buf_unref(buf); + bt_mesh_adv_send(adv, &buf_sent_cb, frnd); + bt_mesh_adv_unref(adv); } static void subnet_evt(struct bt_mesh_subnet *sub, enum bt_mesh_key_evt evt) diff --git a/subsys/bluetooth/mesh/gatt_cli.c b/subsys/bluetooth/mesh/gatt_cli.c index bff9b567011..7814f32f27f 100644 --- a/subsys/bluetooth/mesh/gatt_cli.c +++ b/subsys/bluetooth/mesh/gatt_cli.c @@ -18,7 +18,6 @@ #include "common/bt_str.h" #include "mesh.h" -#include "adv.h" #include "net.h" #include "rpl.h" #include "transport.h" diff --git a/subsys/bluetooth/mesh/health_srv.c b/subsys/bluetooth/mesh/health_srv.c index 8611e1004f6..3db3410aa34 100644 --- a/subsys/bluetooth/mesh/health_srv.c +++ b/subsys/bluetooth/mesh/health_srv.c @@ -16,7 +16,6 @@ #include #include "mesh.h" -#include "adv.h" #include "net.h" #include "transport.h" #include "access.h" diff --git a/subsys/bluetooth/mesh/lpn.c b/subsys/bluetooth/mesh/lpn.c index 2b655f729f3..f6f906b12fe 100644 --- a/subsys/bluetooth/mesh/lpn.c +++ b/subsys/bluetooth/mesh/lpn.c @@ -13,7 +13,6 @@ #include #include "crypto.h" -#include "adv.h" #include "mesh.h" #include "net.h" #include "transport.h" diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index 24bbd7c7e94..89115ebe3e8 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -18,7 +18,6 @@ #include #include "test.h" -#include "adv.h" #include "prov.h" #include "provisioner.h" #include "net.h" diff --git a/subsys/bluetooth/mesh/net.c b/subsys/bluetooth/mesh/net.c index 6a9f29b4064..943a5e83c23 100644 --- a/subsys/bluetooth/mesh/net.c +++ b/subsys/bluetooth/mesh/net.c @@ -20,7 +20,6 @@ #include "common/bt_str.h" #include "crypto.h" -#include "adv.h" #include "mesh.h" #include "net.h" #include "rpl.h" @@ -526,19 +525,19 @@ static int net_loopback(const struct bt_mesh_net_tx *tx, const uint8_t *data, return 0; } -int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, +int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct bt_mesh_adv *adv, const struct bt_mesh_send_cb *cb, void *cb_data) { const struct bt_mesh_net_cred *cred; int err; LOG_DBG("src 0x%04x dst 0x%04x len %u headroom %zu tailroom %zu", tx->src, tx->ctx->addr, - buf->len, net_buf_headroom(buf), net_buf_tailroom(buf)); - LOG_DBG("Payload len %u: %s", buf->len, bt_hex(buf->data, buf->len)); + adv->b.len, net_buf_simple_headroom(&adv->b), net_buf_simple_tailroom(&adv->b)); + LOG_DBG("Payload len %u: %s", adv->b.len, bt_hex(adv->b.data, adv->b.len)); LOG_DBG("Seq 0x%06x", bt_mesh.seq); cred = net_tx_cred_get(tx); - err = net_header_encode(tx, cred->nid, &buf->b); + err = net_header_encode(tx, cred->nid, &adv->b); if (err) { goto done; } @@ -546,7 +545,7 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, /* Deliver to local network interface if necessary */ if (bt_mesh_fixed_group_match(tx->ctx->addr) || bt_mesh_has_addr(tx->ctx->addr)) { - err = net_loopback(tx, buf->data, buf->len); + err = net_loopback(tx, adv->b.data, adv->b.len); /* Local unicast messages should not go out to network */ if (BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr) || @@ -569,28 +568,28 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, goto done; } - err = net_encrypt(&buf->b, cred, BT_MESH_NET_IVI_TX, BT_MESH_NONCE_NETWORK); + err = net_encrypt(&adv->b, cred, BT_MESH_NET_IVI_TX, BT_MESH_NONCE_NETWORK); if (err) { goto done; } - BT_MESH_ADV(buf)->cb = cb; - BT_MESH_ADV(buf)->cb_data = cb_data; + adv->ctx.cb = cb; + adv->ctx.cb_data = cb_data; /* Deliver to GATT Proxy Clients if necessary. */ if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { - (void)bt_mesh_proxy_relay(buf, tx->ctx->addr); + (void)bt_mesh_proxy_relay(adv, tx->ctx->addr); } /* Deliver to GATT Proxy Servers if necessary. */ if (IS_ENABLED(CONFIG_BT_MESH_PROXY_CLIENT)) { - (void)bt_mesh_proxy_cli_relay(buf); + (void)bt_mesh_proxy_cli_relay(adv); } - bt_mesh_adv_send(buf, cb, cb_data); + bt_mesh_adv_send(adv, cb, cb_data); done: - net_buf_unref(buf); + bt_mesh_adv_unref(adv); return err; } @@ -684,7 +683,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, struct bt_mesh_net_rx *rx) { const struct bt_mesh_net_cred *cred; - struct net_buf *buf; + struct bt_mesh_adv *adv; uint8_t transmit; if (rx->ctx.recv_ttl <= 1U) { @@ -711,10 +710,10 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, transmit = bt_mesh_net_transmit_get(); } - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_RELAY, + adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_RELAY, transmit, K_NO_WAIT); - if (!buf) { - LOG_DBG("Out of relay buffers"); + if (!adv) { + LOG_DBG("Out of relay advs"); return; } @@ -722,23 +721,23 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, sbuf->data[1] &= 0x80; sbuf->data[1] |= rx->ctx.recv_ttl - 1U; - net_buf_add_mem(buf, sbuf->data, sbuf->len); + net_buf_simple_add_mem(&adv->b, sbuf->data, sbuf->len); cred = &rx->sub->keys[SUBNET_KEY_TX_IDX(rx->sub)].msg; - LOG_DBG("Relaying packet. TTL is now %u", TTL(buf->data)); + LOG_DBG("Relaying packet. TTL is now %u", TTL(adv->b.data)); /* Update NID if RX or RX was with friend credentials */ if (rx->friend_cred) { - buf->data[0] &= 0x80; /* Clear everything except IVI */ - buf->data[0] |= cred->nid; + adv->b.data[0] &= 0x80; /* Clear everything except IVI */ + adv->b.data[0] |= cred->nid; } /* We re-encrypt and obfuscate using the received IVI rather than * the normal TX IVI (which may be different) since the transport * layer nonce includes the IVI. */ - if (net_encrypt(&buf->b, cred, BT_MESH_NET_IVI_RX(rx), BT_MESH_NONCE_NETWORK)) { + if (net_encrypt(&adv->b, cred, BT_MESH_NET_IVI_RX(rx), BT_MESH_NONCE_NETWORK)) { LOG_ERR("Re-encrypting failed"); goto done; } @@ -751,15 +750,15 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, (rx->friend_cred || bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED || bt_mesh_priv_gatt_proxy_get() == BT_MESH_PRIV_GATT_PROXY_ENABLED)) { - bt_mesh_proxy_relay(buf, rx->ctx.recv_dst); + bt_mesh_proxy_relay(adv, rx->ctx.recv_dst); } if (relay_to_adv(rx->net_if) || rx->friend_cred) { - bt_mesh_adv_send(buf, NULL, NULL); + bt_mesh_adv_send(adv, NULL, NULL); } done: - net_buf_unref(buf); + bt_mesh_adv_unref(adv); } void bt_mesh_net_header_parse(struct net_buf_simple *buf, diff --git a/subsys/bluetooth/mesh/net.h b/subsys/bluetooth/mesh/net.h index 04179a4dd49..28c21da3eaf 100644 --- a/subsys/bluetooth/mesh/net.h +++ b/subsys/bluetooth/mesh/net.h @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include "adv.h" #include "subnet.h" #include @@ -291,7 +292,7 @@ bool bt_mesh_net_iv_update(uint32_t iv_index, bool iv_update); int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf, enum bt_mesh_nonce_type type); -int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, +int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct bt_mesh_adv *adv, const struct bt_mesh_send_cb *cb, void *cb_data); int bt_mesh_net_decode(struct net_buf_simple *in, enum bt_mesh_net_if net_if, diff --git a/subsys/bluetooth/mesh/pb_adv.c b/subsys/bluetooth/mesh/pb_adv.c index e273739ed72..f723ff48c14 100644 --- a/subsys/bluetooth/mesh/pb_adv.c +++ b/subsys/bluetooth/mesh/pb_adv.c @@ -11,7 +11,6 @@ #include #include "host/testing.h" #include "net.h" -#include "adv.h" #include "crypto.h" #include "beacon.h" #include "prov.h" @@ -101,8 +100,8 @@ struct pb_adv { /* Transaction timeout in seconds */ uint8_t timeout; - /* Pending outgoing buffer(s) */ - struct net_buf *buf[3]; + /* Pending outgoing adv(s) */ + struct bt_mesh_adv *adv[3]; prov_bearer_send_complete_t cb; @@ -170,24 +169,24 @@ static void free_segments(void) { int i; - for (i = 0; i < ARRAY_SIZE(link.tx.buf); i++) { - struct net_buf *buf = link.tx.buf[i]; + for (i = 0; i < ARRAY_SIZE(link.tx.adv); i++) { + struct bt_mesh_adv *adv = link.tx.adv[i]; - if (!buf) { + if (!adv) { break; } - link.tx.buf[i] = NULL; + link.tx.adv[i] = NULL; /* Terminate active adv */ - if (BT_MESH_ADV(buf)->busy == 0U) { - bt_mesh_adv_buf_terminate(buf); + if (adv->ctx.busy == 0U) { + bt_mesh_adv_terminate(adv); } else { /* Mark as canceled */ - BT_MESH_ADV(buf)->busy = 0U; + adv->ctx.busy = 0U; } - net_buf_unref(buf); + bt_mesh_adv_unref(adv); } } @@ -200,7 +199,7 @@ static void prov_clear_tx(void) { LOG_DBG(""); - /* If this fails, the work handler will not find any buffers to send, + /* If this fails, the work handler will not find any advs to send, * and return without rescheduling. The work handler also checks the * LINK_ACTIVE flag, so if this call is part of reset_adv_link, it'll * exit early. @@ -254,19 +253,19 @@ static void close_link(enum prov_bearer_link_status reason) cb->link_closed(&bt_mesh_pb_adv, cb_data, reason); } -static struct net_buf *adv_buf_create(uint8_t retransmits) +static struct bt_mesh_adv *adv_create(uint8_t retransmits) { - struct net_buf *buf; + struct bt_mesh_adv *adv; - buf = bt_mesh_adv_create(BT_MESH_ADV_PROV, BT_MESH_ADV_TAG_PROV, + adv = bt_mesh_adv_create(BT_MESH_ADV_PROV, BT_MESH_ADV_TAG_PROV, BT_MESH_TRANSMIT(retransmits, 20), BUF_TIMEOUT); - if (!buf) { - LOG_ERR("Out of provisioning buffers"); + if (!adv) { + LOG_ERR("Out of provisioning advs"); return NULL; } - return buf; + return adv; } static void ack_complete(uint16_t duration, int err, void *user_data) @@ -328,7 +327,7 @@ static void gen_prov_ack_send(uint8_t xact_id) .start = ack_complete, }; const struct bt_mesh_send_cb *complete; - struct net_buf *buf; + struct bt_mesh_adv *adv; bool pending = atomic_test_and_set_bit(link.flags, ADV_ACK_PENDING); LOG_DBG("xact_id 0x%x", xact_id); @@ -338,8 +337,8 @@ static void gen_prov_ack_send(uint8_t xact_id) return; } - buf = adv_buf_create(RETRANSMITS_ACK); - if (!buf) { + adv = adv_create(RETRANSMITS_ACK); + if (!adv) { atomic_clear_bit(link.flags, ADV_ACK_PENDING); return; } @@ -351,12 +350,12 @@ static void gen_prov_ack_send(uint8_t xact_id) complete = &cb; } - net_buf_add_be32(buf, link.id); - net_buf_add_u8(buf, xact_id); - net_buf_add_u8(buf, GPC_ACK); + net_buf_simple_add_be32(&adv->b, link.id); + net_buf_simple_add_u8(&adv->b, xact_id); + net_buf_simple_add_u8(&adv->b, GPC_ACK); - bt_mesh_adv_send(buf, complete, NULL); - net_buf_unref(buf); + bt_mesh_adv_send(adv, complete, NULL); + bt_mesh_adv_unref(adv); } static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf) @@ -431,7 +430,7 @@ static void gen_prov_ack(struct prov_rx *rx, struct net_buf_simple *buf) { LOG_DBG("len %u", buf->len); - if (!link.tx.buf[0]) { + if (!link.tx.adv[0]) { return; } @@ -596,20 +595,20 @@ static void send_reliable(void) { int i; - for (i = 0; i < ARRAY_SIZE(link.tx.buf); i++) { - struct net_buf *buf = link.tx.buf[i]; + for (i = 0; i < ARRAY_SIZE(link.tx.adv); i++) { + struct bt_mesh_adv *adv = link.tx.adv[i]; - if (!buf) { + if (!adv) { break; } - if (BT_MESH_ADV(buf)->busy) { + if (adv->ctx.busy) { continue; } - LOG_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len)); + LOG_DBG("%u bytes: %s", adv->b.len, bt_hex(adv->b.data, adv->b.len)); - bt_mesh_adv_send(buf, NULL, NULL); + bt_mesh_adv_send(adv, NULL, NULL); } k_work_reschedule(&link.tx.retransmit, RETRANSMIT_TIMEOUT); @@ -633,30 +632,30 @@ static void prov_retransmit(struct k_work *work) send_reliable(); } -static struct net_buf *ctl_buf_create(uint8_t op, const void *data, uint8_t data_len, - uint8_t retransmits) +static struct bt_mesh_adv *ctl_adv_create(uint8_t op, const void *data, uint8_t data_len, + uint8_t retransmits) { - struct net_buf *buf; + struct bt_mesh_adv *adv; LOG_DBG("op 0x%02x data_len %u", op, data_len); - buf = adv_buf_create(retransmits); - if (!buf) { + adv = adv_create(retransmits); + if (!adv) { return NULL; } - net_buf_add_be32(buf, link.id); + net_buf_simple_add_be32(&adv->b, link.id); /* Transaction ID, always 0 for Bearer messages */ - net_buf_add_u8(buf, 0x00); - net_buf_add_u8(buf, GPC_CTL(op)); - net_buf_add_mem(buf, data, data_len); + net_buf_simple_add_u8(&adv->b, 0x00); + net_buf_simple_add_u8(&adv->b, GPC_CTL(op)); + net_buf_simple_add_mem(&adv->b, data, data_len); - return buf; + return adv; } -static int bearer_ctl_send(struct net_buf *buf) +static int bearer_ctl_send(struct bt_mesh_adv *adv) { - if (!buf) { + if (!adv) { return -ENOMEM; } @@ -664,23 +663,23 @@ static int bearer_ctl_send(struct net_buf *buf) k_work_reschedule(&link.prot_timer, bt_mesh_prov_protocol_timeout_get()); link.tx.start = k_uptime_get(); - link.tx.buf[0] = buf; + link.tx.adv[0] = adv; send_reliable(); return 0; } -static int bearer_ctl_send_unacked(struct net_buf *buf, void *user_data) +static int bearer_ctl_send_unacked(struct bt_mesh_adv *adv, void *user_data) { - if (!buf) { + if (!adv) { return -ENOMEM; } prov_clear_tx(); k_work_reschedule(&link.prot_timer, bt_mesh_prov_protocol_timeout_get()); - bt_mesh_adv_send(buf, &buf_sent_cb, user_data); - net_buf_unref(buf); + bt_mesh_adv_send(adv, &buf_sent_cb, user_data); + bt_mesh_adv_unref(adv); return 0; } @@ -688,26 +687,26 @@ static int bearer_ctl_send_unacked(struct net_buf *buf, void *user_data) static int prov_send_adv(struct net_buf_simple *msg, prov_bearer_send_complete_t cb, void *cb_data) { - struct net_buf *start, *buf; + struct bt_mesh_adv *start, *adv; uint8_t seg_len, seg_id; prov_clear_tx(); k_work_reschedule(&link.prot_timer, bt_mesh_prov_protocol_timeout_get()); - start = adv_buf_create(RETRANSMITS_RELIABLE); + start = adv_create(RETRANSMITS_RELIABLE); if (!start) { return -ENOBUFS; } link.tx.id = next_transaction_id(link.tx.id); - net_buf_add_be32(start, link.id); - net_buf_add_u8(start, link.tx.id); + net_buf_simple_add_be32(&start->b, link.id); + net_buf_simple_add_u8(&start->b, link.tx.id); - net_buf_add_u8(start, GPC_START(last_seg(msg->len))); - net_buf_add_be16(start, msg->len); - net_buf_add_u8(start, bt_mesh_fcs_calc(msg->data, msg->len)); + net_buf_simple_add_u8(&start->b, GPC_START(last_seg(msg->len))); + net_buf_simple_add_be16(&start->b, msg->len); + net_buf_simple_add_u8(&start->b, bt_mesh_fcs_calc(msg->data, msg->len)); - link.tx.buf[0] = start; + link.tx.adv[0] = start; link.tx.cb = cb; link.tx.cb_data = cb_data; link.tx.start = k_uptime_get(); @@ -716,33 +715,33 @@ static int prov_send_adv(struct net_buf_simple *msg, seg_len = MIN(msg->len, START_PAYLOAD_MAX); LOG_DBG("seg 0 len %u: %s", seg_len, bt_hex(msg->data, seg_len)); - net_buf_add_mem(start, msg->data, seg_len); + net_buf_simple_add_mem(&start->b, msg->data, seg_len); net_buf_simple_pull(msg, seg_len); - buf = start; + adv = start; for (seg_id = 1U; msg->len > 0; seg_id++) { - if (seg_id >= ARRAY_SIZE(link.tx.buf)) { + if (seg_id >= ARRAY_SIZE(link.tx.adv)) { LOG_ERR("Too big message"); free_segments(); return -E2BIG; } - buf = adv_buf_create(RETRANSMITS_RELIABLE); - if (!buf) { + adv = adv_create(RETRANSMITS_RELIABLE); + if (!adv) { free_segments(); return -ENOBUFS; } - link.tx.buf[seg_id] = buf; + link.tx.adv[seg_id] = adv; seg_len = MIN(msg->len, CONT_PAYLOAD_MAX); LOG_DBG("seg %u len %u: %s", seg_id, seg_len, bt_hex(msg->data, seg_len)); - net_buf_add_be32(buf, link.id); - net_buf_add_u8(buf, link.tx.id); - net_buf_add_u8(buf, GPC_CONT(seg_id)); - net_buf_add_mem(buf, msg->data, seg_len); + net_buf_simple_add_be32(&adv->b, link.id); + net_buf_simple_add_u8(&adv->b, link.tx.id); + net_buf_simple_add_u8(&adv->b, GPC_CONT(seg_id)); + net_buf_simple_add_mem(&adv->b, msg->data, seg_len); net_buf_simple_pull(msg, seg_len); } @@ -776,7 +775,7 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf) LOG_DBG("Resending link ack"); /* Ignore errors, message will be attempted again if we keep receiving link open: */ (void)bearer_ctl_send_unacked( - ctl_buf_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK), + ctl_adv_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK), (void *)PROV_BEARER_LINK_STATUS_SUCCESS); return; } @@ -791,7 +790,7 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf) net_buf_simple_reset(link.rx.buf); err = bearer_ctl_send_unacked( - ctl_buf_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK), + ctl_adv_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK), (void *)PROV_BEARER_LINK_STATUS_SUCCESS); if (err) { reset_adv_link(); @@ -891,7 +890,7 @@ static int prov_link_open(const uint8_t uuid[16], uint8_t timeout, net_buf_simple_reset(link.rx.buf); - return bearer_ctl_send(ctl_buf_create(LINK_OPEN, uuid, 16, RETRANSMITS_RELIABLE)); + return bearer_ctl_send(ctl_adv_create(LINK_OPEN, uuid, 16, RETRANSMITS_RELIABLE)); } static int prov_link_accept(const struct prov_bearer_cb *cb, void *cb_data) @@ -936,7 +935,7 @@ static void prov_link_close(enum prov_bearer_link_status status) link.tx.timeout = CLOSING_TIMEOUT; /* Ignore errors, the link will time out eventually if this doesn't get sent */ bearer_ctl_send_unacked( - ctl_buf_create(LINK_CLOSE, &status, 1, RETRANSMITS_LINK_CLOSE), + ctl_adv_create(LINK_CLOSE, &status, 1, RETRANSMITS_LINK_CLOSE), (void *)status); } diff --git a/subsys/bluetooth/mesh/pb_gatt.c b/subsys/bluetooth/mesh/pb_gatt.c index f8acc8f6c5a..849914f4b5f 100644 --- a/subsys/bluetooth/mesh/pb_gatt.c +++ b/subsys/bluetooth/mesh/pb_gatt.c @@ -8,7 +8,6 @@ #include #include "net.h" #include "proxy.h" -#include "adv.h" #include "prov.h" #include "pb_gatt.h" #include "proxy_msg.h" diff --git a/subsys/bluetooth/mesh/pb_gatt_cli.c b/subsys/bluetooth/mesh/pb_gatt_cli.c index 9231cc0f0b1..bf7dc14029a 100644 --- a/subsys/bluetooth/mesh/pb_gatt_cli.c +++ b/subsys/bluetooth/mesh/pb_gatt_cli.c @@ -16,7 +16,6 @@ #include #include "mesh.h" -#include "adv.h" #include "net.h" #include "rpl.h" #include "transport.h" diff --git a/subsys/bluetooth/mesh/pb_gatt_srv.c b/subsys/bluetooth/mesh/pb_gatt_srv.c index f6d9298fc78..f4fdac53570 100644 --- a/subsys/bluetooth/mesh/pb_gatt_srv.c +++ b/subsys/bluetooth/mesh/pb_gatt_srv.c @@ -17,7 +17,6 @@ #include "common/bt_str.h" #include "mesh.h" -#include "adv.h" #include "net.h" #include "rpl.h" #include "transport.h" diff --git a/subsys/bluetooth/mesh/priv_beacon_srv.c b/subsys/bluetooth/mesh/priv_beacon_srv.c index 5b5e62f1736..98be589fc22 100644 --- a/subsys/bluetooth/mesh/priv_beacon_srv.c +++ b/subsys/bluetooth/mesh/priv_beacon_srv.c @@ -5,7 +5,6 @@ */ #include #include "net.h" -#include "adv.h" #include #include "proxy.h" #include "foundation.h" diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/prov_device.c index af890396ac7..6ca65c2ec63 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/prov_device.c @@ -20,7 +20,6 @@ #include "common/bt_str.h" #include "crypto.h" -#include "adv.h" #include "mesh.h" #include "net.h" #include "rpl.h" diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index aba2449892f..ba02723e830 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -21,7 +21,6 @@ #include "common/bt_str.h" #include "crypto.h" -#include "adv.h" #include "mesh.h" #include "net.h" #include "rpl.h" diff --git a/subsys/bluetooth/mesh/proxy.h b/subsys/bluetooth/mesh/proxy.h index a2f6bb45ff6..34a119c3df6 100644 --- a/subsys/bluetooth/mesh/proxy.h +++ b/subsys/bluetooth/mesh/proxy.h @@ -34,6 +34,6 @@ int bt_mesh_proxy_adv_start(void); void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub, bool private); void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub); -bool bt_mesh_proxy_relay(struct net_buf *buf, uint16_t dst); +bool bt_mesh_proxy_relay(struct bt_mesh_adv *adv, uint16_t dst); void bt_mesh_proxy_addr_add(struct net_buf_simple *buf, uint16_t addr); uint8_t bt_mesh_proxy_srv_connected_cnt(void); diff --git a/subsys/bluetooth/mesh/proxy_cli.c b/subsys/bluetooth/mesh/proxy_cli.c index a0a25751b41..5dd6b02361f 100644 --- a/subsys/bluetooth/mesh/proxy_cli.c +++ b/subsys/bluetooth/mesh/proxy_cli.c @@ -16,7 +16,6 @@ #include #include "mesh.h" -#include "adv.h" #include "net.h" #include "rpl.h" #include "transport.h" @@ -79,7 +78,7 @@ static struct bt_mesh_proxy_server *find_proxy_srv_by_conn(struct bt_conn *conn) return NULL; } -bool bt_mesh_proxy_cli_relay(struct net_buf *buf) +bool bt_mesh_proxy_cli_relay(struct bt_mesh_adv *adv) { bool relayed = false; int i; @@ -91,7 +90,7 @@ bool bt_mesh_proxy_cli_relay(struct net_buf *buf) continue; } - if (bt_mesh_proxy_relay_send(server->role->conn, buf)) { + if (bt_mesh_proxy_relay_send(server->role->conn, adv)) { continue; } diff --git a/subsys/bluetooth/mesh/proxy_cli.h b/subsys/bluetooth/mesh/proxy_cli.h index 8c1fae10e84..c0b69f4aaf6 100644 --- a/subsys/bluetooth/mesh/proxy_cli.h +++ b/subsys/bluetooth/mesh/proxy_cli.h @@ -8,6 +8,6 @@ void bt_mesh_proxy_cli_adv_recv(const struct bt_le_scan_recv_info *info, struct net_buf_simple *buf); -bool bt_mesh_proxy_cli_relay(struct net_buf *buf); +bool bt_mesh_proxy_cli_relay(struct bt_mesh_adv *adv); bool bt_mesh_proxy_cli_is_connected(uint16_t net_idx); diff --git a/subsys/bluetooth/mesh/proxy_msg.c b/subsys/bluetooth/mesh/proxy_msg.c index 025909e0503..b2fa113d456 100644 --- a/subsys/bluetooth/mesh/proxy_msg.c +++ b/subsys/bluetooth/mesh/proxy_msg.c @@ -21,7 +21,6 @@ #include "common/bt_str.h" #include "mesh.h" -#include "adv.h" #include "net.h" #include "rpl.h" #include "transport.h" @@ -196,12 +195,12 @@ int bt_mesh_proxy_msg_send(struct bt_conn *conn, uint8_t type, static void buf_send_end(struct bt_conn *conn, void *user_data) { - struct net_buf *buf = user_data; + struct bt_mesh_adv *adv = user_data; - net_buf_unref(buf); + bt_mesh_adv_unref(adv); } -int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct net_buf *buf) +int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct bt_mesh_adv *adv) { int err; @@ -211,12 +210,12 @@ int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct net_buf *buf) * so we need to make a copy. */ net_buf_simple_reserve(&msg, 1); - net_buf_simple_add_mem(&msg, buf->data, buf->len); + net_buf_simple_add_mem(&msg, adv->b.data, adv->b.len); err = bt_mesh_proxy_msg_send(conn, BT_MESH_PROXY_NET_PDU, - &msg, buf_send_end, net_buf_ref(buf)); + &msg, buf_send_end, bt_mesh_adv_ref(adv)); - bt_mesh_adv_send_start(0, err, BT_MESH_ADV(buf)); + bt_mesh_adv_send_start(0, err, &adv->ctx); if (err) { LOG_ERR("Failed to send proxy message (err %d)", err); @@ -225,7 +224,7 @@ int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct net_buf *buf) * which is just opaque data to segment_and send) reference given * to segment_and_send() here. */ - net_buf_unref(buf); + bt_mesh_adv_unref(adv); } return err; diff --git a/subsys/bluetooth/mesh/proxy_msg.h b/subsys/bluetooth/mesh/proxy_msg.h index 7d4bd51ae4f..7ad4be7ae5d 100644 --- a/subsys/bluetooth/mesh/proxy_msg.h +++ b/subsys/bluetooth/mesh/proxy_msg.h @@ -51,7 +51,7 @@ ssize_t bt_mesh_proxy_msg_recv(struct bt_conn *conn, int bt_mesh_proxy_msg_send(struct bt_conn *conn, uint8_t type, struct net_buf_simple *msg, bt_gatt_complete_func_t end, void *user_data); -int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct net_buf *buf); +int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct bt_mesh_adv *adv); struct bt_mesh_proxy_role *bt_mesh_proxy_role_setup(struct bt_conn *conn, proxy_send_cb_t send, proxy_recv_cb_t recv); diff --git a/subsys/bluetooth/mesh/proxy_srv.c b/subsys/bluetooth/mesh/proxy_srv.c index 571144ceaed..45e29915325 100644 --- a/subsys/bluetooth/mesh/proxy_srv.c +++ b/subsys/bluetooth/mesh/proxy_srv.c @@ -20,7 +20,6 @@ #include "common/bt_str.h" #include "mesh.h" -#include "adv.h" #include "net.h" #include "rpl.h" #include "transport.h" @@ -1022,12 +1021,12 @@ static bool client_filter_match(struct bt_mesh_proxy_client *client, return false; } -bool bt_mesh_proxy_relay(struct net_buf *buf, uint16_t dst) +bool bt_mesh_proxy_relay(struct bt_mesh_adv *adv, uint16_t dst) { bool relayed = false; int i; - LOG_DBG("%u bytes to dst 0x%04x", buf->len, dst); + LOG_DBG("%u bytes to dst 0x%04x", adv->b.len, dst); for (i = 0; i < ARRAY_SIZE(clients); i++) { struct bt_mesh_proxy_client *client = &clients[i]; @@ -1040,7 +1039,7 @@ bool bt_mesh_proxy_relay(struct net_buf *buf, uint16_t dst) continue; } - if (bt_mesh_proxy_relay_send(client->cli->conn, buf)) { + if (bt_mesh_proxy_relay_send(client->cli->conn, adv)) { continue; } diff --git a/subsys/bluetooth/mesh/rpl.c b/subsys/bluetooth/mesh/rpl.c index e19df33908f..df67ddf9d2e 100644 --- a/subsys/bluetooth/mesh/rpl.c +++ b/subsys/bluetooth/mesh/rpl.c @@ -20,7 +20,6 @@ #include #include "mesh.h" -#include "adv.h" #include "net.h" #include "rpl.h" #include "settings.h" diff --git a/subsys/bluetooth/mesh/rpr_srv.c b/subsys/bluetooth/mesh/rpr_srv.c index 9813842a367..e97df35f28f 100644 --- a/subsys/bluetooth/mesh/rpr_srv.c +++ b/subsys/bluetooth/mesh/rpr_srv.c @@ -14,7 +14,6 @@ #include #include #include "access.h" -#include "adv.h" #include "prov.h" #include "crypto.h" #include "rpr.h" diff --git a/subsys/bluetooth/mesh/solicitation.c b/subsys/bluetooth/mesh/solicitation.c index e2100fa42db..642abfd87f1 100644 --- a/subsys/bluetooth/mesh/solicitation.c +++ b/subsys/bluetooth/mesh/solicitation.c @@ -12,7 +12,6 @@ #include #include #include "access.h" -#include "adv.h" #include "cfg.h" #include "crypto.h" #include "mesh.h" diff --git a/subsys/bluetooth/mesh/statistic.c b/subsys/bluetooth/mesh/statistic.c index 21c451bee73..b9f542a5923 100644 --- a/subsys/bluetooth/mesh/statistic.c +++ b/subsys/bluetooth/mesh/statistic.c @@ -6,7 +6,6 @@ #include -#include "adv.h" #include "net.h" #include "statistic.h" @@ -22,24 +21,24 @@ void bt_mesh_stat_reset(void) memset(&stat, 0, sizeof(struct bt_mesh_statistic)); } -void bt_mesh_stat_planned_count(struct bt_mesh_adv *adv) +void bt_mesh_stat_planned_count(struct bt_mesh_adv_ctx *ctx) { - if (adv->tag == BT_MESH_ADV_TAG_LOCAL) { + if (ctx->tag == BT_MESH_ADV_TAG_LOCAL) { stat.tx_local_planned++; - } else if (adv->tag == BT_MESH_ADV_TAG_RELAY) { + } else if (ctx->tag == BT_MESH_ADV_TAG_RELAY) { stat.tx_adv_relay_planned++; - } else if (adv->tag == BT_MESH_ADV_TAG_FRIEND) { + } else if (ctx->tag == BT_MESH_ADV_TAG_FRIEND) { stat.tx_friend_planned++; } } -void bt_mesh_stat_succeeded_count(struct bt_mesh_adv *adv) +void bt_mesh_stat_succeeded_count(struct bt_mesh_adv_ctx *ctx) { - if (adv->tag == BT_MESH_ADV_TAG_LOCAL) { + if (ctx->tag == BT_MESH_ADV_TAG_LOCAL) { stat.tx_local_succeeded++; - } else if (adv->tag == BT_MESH_ADV_TAG_RELAY) { + } else if (ctx->tag == BT_MESH_ADV_TAG_RELAY) { stat.tx_adv_relay_succeeded++; - } else if (adv->tag == BT_MESH_ADV_TAG_FRIEND) { + } else if (ctx->tag == BT_MESH_ADV_TAG_FRIEND) { stat.tx_friend_succeeded++; } } diff --git a/subsys/bluetooth/mesh/statistic.h b/subsys/bluetooth/mesh/statistic.h index fdb488f0d81..4cd9187f45a 100644 --- a/subsys/bluetooth/mesh/statistic.h +++ b/subsys/bluetooth/mesh/statistic.h @@ -7,8 +7,8 @@ #ifndef ZEPHYR_SUBSYS_BLUETOOTH_MESH_STATISTIC_H_ #define ZEPHYR_SUBSYS_BLUETOOTH_MESH_STATISTIC_H_ -void bt_mesh_stat_planned_count(struct bt_mesh_adv *adv); -void bt_mesh_stat_succeeded_count(struct bt_mesh_adv *adv); +void bt_mesh_stat_planned_count(struct bt_mesh_adv_ctx *ctx); +void bt_mesh_stat_succeeded_count(struct bt_mesh_adv_ctx *ctx); void bt_mesh_stat_rx(enum bt_mesh_net_if net_if); #endif /* ZEPHYR_SUBSYS_BLUETOOTH_MESH_STATISTIC_H_ */ diff --git a/subsys/bluetooth/mesh/subnet.c b/subsys/bluetooth/mesh/subnet.c index ef90ff8f725..695dd321b49 100644 --- a/subsys/bluetooth/mesh/subnet.c +++ b/subsys/bluetooth/mesh/subnet.c @@ -22,7 +22,6 @@ #include "common/bt_str.h" #include "crypto.h" -#include "adv.h" #include "mesh.h" #include "net.h" #include "lpn.h" diff --git a/subsys/bluetooth/mesh/transport.c b/subsys/bluetooth/mesh/transport.c index 94c1f698e91..47e8492a901 100644 --- a/subsys/bluetooth/mesh/transport.c +++ b/subsys/bluetooth/mesh/transport.c @@ -22,7 +22,6 @@ #include "host/testing.h" #include "crypto.h" -#include "adv.h" #include "mesh.h" #include "net.h" #include "app_keys.h" @@ -122,26 +121,26 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, const struct bt_mesh_send_cb *cb, void *cb_data, const uint8_t *ctl_op) { - struct net_buf *buf; + struct bt_mesh_adv *adv; - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, tx->xmit, BUF_TIMEOUT); - if (!buf) { - LOG_ERR("Out of network buffers"); + if (!adv) { + LOG_ERR("Out of network advs"); return -ENOBUFS; } - net_buf_reserve(buf, BT_MESH_NET_HDR_LEN); + net_buf_simple_reserve(&adv->b, BT_MESH_NET_HDR_LEN); if (ctl_op) { - net_buf_add_u8(buf, TRANS_CTL_HDR(*ctl_op, 0)); + net_buf_simple_add_u8(&adv->b, TRANS_CTL_HDR(*ctl_op, 0)); } else if (BT_MESH_IS_DEV_KEY(tx->ctx->app_idx)) { - net_buf_add_u8(buf, UNSEG_HDR(0, 0)); + net_buf_simple_add_u8(&adv->b, UNSEG_HDR(0, 0)); } else { - net_buf_add_u8(buf, UNSEG_HDR(1, tx->aid)); + net_buf_simple_add_u8(&adv->b, UNSEG_HDR(1, tx->aid)); } - net_buf_add_mem(buf, sdu->data, sdu->len); + net_buf_simple_add_mem(&adv->b, sdu->data, sdu->len); if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { if (!bt_mesh_friend_queue_has_space(tx->sub->net_idx, @@ -149,7 +148,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, NULL, 1)) { if (BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { LOG_ERR("Not enough space in Friend Queue"); - net_buf_unref(buf); + bt_mesh_adv_unref(adv); return -ENOBUFS; } else { LOG_WRN("No space in Friend Queue"); @@ -158,19 +157,19 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, } if (bt_mesh_friend_enqueue_tx(tx, BT_MESH_FRIEND_PDU_SINGLE, - NULL, 1, &buf->b) && + NULL, 1, &adv->b) && BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { /* PDUs for a specific Friend should only go * out through the Friend Queue. */ - net_buf_unref(buf); + bt_mesh_adv_unref(adv); send_cb_finalize(cb, cb_data); return 0; } } send: - return bt_mesh_net_send(tx, buf, cb, cb_data); + return bt_mesh_net_send(tx, adv, cb, cb_data); } static inline uint8_t seg_len(bool ctl) @@ -405,7 +404,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx) (uint16_t)(tx->seq_auth & TRANS_SEQ_ZERO_MASK), tx->attempts_left); while (tx->seg_o <= tx->seg_n) { - struct net_buf *seg; + struct bt_mesh_adv *seg; int err; if (!tx->seg[tx->seg_o]) { @@ -421,7 +420,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx) goto end; } - net_buf_reserve(seg, BT_MESH_NET_HDR_LEN); + net_buf_simple_reserve(&seg->b, BT_MESH_NET_HDR_LEN); seg_tx_buf_build(tx, tx->seg_o, &seg->b); LOG_DBG("Sending %u/%u", tx->seg_o, tx->seg_n); diff --git a/subsys/bluetooth/mesh/transport_legacy.c b/subsys/bluetooth/mesh/transport_legacy.c index da0c1830f73..1a826db4ac4 100644 --- a/subsys/bluetooth/mesh/transport_legacy.c +++ b/subsys/bluetooth/mesh/transport_legacy.c @@ -22,7 +22,6 @@ #include "host/testing.h" #include "crypto.h" -#include "adv.h" #include "mesh.h" #include "net.h" #include "app_keys.h" @@ -129,26 +128,26 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, const struct bt_mesh_send_cb *cb, void *cb_data, const uint8_t *ctl_op) { - struct net_buf *buf; + struct bt_mesh_adv *adv; - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, tx->xmit, BUF_TIMEOUT); - if (!buf) { - LOG_ERR("Out of network buffers"); + if (!adv) { + LOG_ERR("Out of network advs"); return -ENOBUFS; } - net_buf_reserve(buf, BT_MESH_NET_HDR_LEN); + net_buf_simple_reserve(&adv->b, BT_MESH_NET_HDR_LEN); if (ctl_op) { - net_buf_add_u8(buf, TRANS_CTL_HDR(*ctl_op, 0)); + net_buf_simple_add_u8(&adv->b, TRANS_CTL_HDR(*ctl_op, 0)); } else if (BT_MESH_IS_DEV_KEY(tx->ctx->app_idx)) { - net_buf_add_u8(buf, UNSEG_HDR(0, 0)); + net_buf_simple_add_u8(&adv->b, UNSEG_HDR(0, 0)); } else { - net_buf_add_u8(buf, UNSEG_HDR(1, tx->aid)); + net_buf_simple_add_u8(&adv->b, UNSEG_HDR(1, tx->aid)); } - net_buf_add_mem(buf, sdu->data, sdu->len); + net_buf_simple_add_mem(&adv->b, sdu->data, sdu->len); if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { if (!bt_mesh_friend_queue_has_space(tx->sub->net_idx, @@ -156,7 +155,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, NULL, 1)) { if (BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { LOG_ERR("Not enough space in Friend Queue"); - net_buf_unref(buf); + bt_mesh_adv_unref(adv); return -ENOBUFS; } @@ -165,19 +164,19 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, } if (bt_mesh_friend_enqueue_tx(tx, BT_MESH_FRIEND_PDU_SINGLE, - NULL, 1, &buf->b) && + NULL, 1, &adv->b) && BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { /* PDUs for a specific Friend should only go * out through the Friend Queue. */ - net_buf_unref(buf); + bt_mesh_adv_unref(adv); send_cb_finalize(cb, cb_data); return 0; } } send: - return bt_mesh_net_send(tx, buf, cb, cb_data); + return bt_mesh_net_send(tx, adv, cb, cb_data); } static inline uint8_t seg_len(bool ctl) @@ -392,7 +391,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx) tx->attempts); while (tx->seg_o <= tx->seg_n) { - struct net_buf *seg; + struct bt_mesh_adv *seg; int err; if (!tx->seg[tx->seg_o]) { @@ -408,7 +407,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx) goto end; } - net_buf_reserve(seg, BT_MESH_NET_HDR_LEN); + net_buf_simple_reserve(&seg->b, BT_MESH_NET_HDR_LEN); seg_tx_buf_build(tx, tx->seg_o, &seg->b); LOG_DBG("Sending %u/%u", tx->seg_o, tx->seg_n); diff --git a/tests/bsim/bluetooth/mesh/src/test_advertiser.c b/tests/bsim/bluetooth/mesh/src/test_advertiser.c index 073651ae843..47851fc72f4 100644 --- a/tests/bsim/bluetooth/mesh/src/test_advertiser.c +++ b/tests/bsim/bluetooth/mesh/src/test_advertiser.c @@ -7,7 +7,6 @@ #include #include #include "mesh_test.h" -#include "mesh/adv.h" #include "mesh/net.h" #include "mesh/mesh.h" #include "mesh/foundation.h" @@ -78,25 +77,25 @@ static void adv_init(void) ASSERT_OK_MSG(bt_mesh_adv_enable(), "Mesh adv init failed"); } -static void allocate_all_array(struct net_buf **buf, size_t num_buf, uint8_t xmit) +static void allocate_all_array(struct bt_mesh_adv **adv, size_t num_adv, uint8_t xmit) { - for (int i = 0; i < num_buf; i++) { - *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + for (int i = 0; i < num_adv; i++) { + *adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); - ASSERT_FALSE_MSG(!*buf, "Out of buffers\n"); - buf++; + ASSERT_FALSE_MSG(!*adv, "Out of advs\n"); + adv++; } } static void verify_adv_queue_overflow(void) { - struct net_buf *dummy_buf; + struct bt_mesh_adv *dummy_adv; /* Verity Queue overflow */ - dummy_buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + dummy_adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); - ASSERT_TRUE_MSG(!dummy_buf, "Unexpected extra buffer\n"); + ASSERT_TRUE_MSG(!dummy_adv, "Unexpected extra adv\n"); } static bool check_delta_time(uint8_t transmit, uint64_t interval) @@ -157,12 +156,12 @@ static void single_end_cb(int err, void *cb_data) static void realloc_end_cb(int err, void *cb_data) { - struct net_buf *buf = (struct net_buf *)cb_data; + struct bt_mesh_adv *adv = (struct bt_mesh_adv *)cb_data; ASSERT_EQUAL(0, err); - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); - ASSERT_FALSE_MSG(!buf, "Out of buffers\n"); + ASSERT_FALSE_MSG(!adv, "Out of advs\n"); k_sem_give(&observer_sem); } @@ -305,13 +304,13 @@ static void rx_xmit_adv(void) static void send_order_start_cb(uint16_t duration, int err, void *user_data) { - struct net_buf *buf = (struct net_buf *)user_data; + struct bt_mesh_adv *adv = (struct bt_mesh_adv *)user_data; ASSERT_OK_MSG(err, "Failed adv start cb err (%d)", err); - ASSERT_EQUAL(2, buf->len); + ASSERT_EQUAL(2, adv->b.len); - uint8_t current = buf->data[0]; - uint8_t previous = buf->data[1]; + uint8_t current = adv->b.data[0]; + uint8_t previous = adv->b.data[1]; LOG_INF("tx start: current(%d) previous(%d)", current, previous); @@ -321,10 +320,7 @@ static void send_order_start_cb(uint16_t duration, int err, void *user_data) static void send_order_end_cb(int err, void *user_data) { - struct net_buf *buf = (struct net_buf *)user_data; - ASSERT_OK_MSG(err, "Failed adv start cb err (%d)", err); - ASSERT_TRUE_MSG(!buf->data, "Data not cleared!\n"); seq_checker++; LOG_INF("tx end: seq(%d)", seq_checker); @@ -380,19 +376,19 @@ static void receive_order(int expect_adv) ASSERT_FALSE_MSG(err && err != -EALREADY, "Stopping scan failed (err %d)\n", err); } -static void send_adv_buf(struct net_buf *buf, uint8_t curr, uint8_t prev) +static void send_adv_buf(struct bt_mesh_adv *adv, uint8_t curr, uint8_t prev) { send_cb.start = send_order_start_cb; send_cb.end = send_order_end_cb; - (void)net_buf_add_u8(buf, curr); - (void)net_buf_add_u8(buf, prev); + (void)net_buf_simple_add_u8(&adv->b, curr); + (void)net_buf_simple_add_u8(&adv->b, prev); - bt_mesh_adv_send(buf, &send_cb, buf); - net_buf_unref(buf); + bt_mesh_adv_send(adv, &send_cb, adv); + bt_mesh_adv_unref(adv); } -static void send_adv_array(struct net_buf **buf, size_t num_buf, bool reverse) +static void send_adv_array(struct bt_mesh_adv **adv, size_t num_buf, bool reverse) { uint8_t previous; int i; @@ -405,13 +401,13 @@ static void send_adv_array(struct net_buf **buf, size_t num_buf, bool reverse) i = num_buf - 1; } while ((!reverse && i < num_buf) || (reverse && i >= 0)) { - send_adv_buf(*buf, (uint8_t)i, previous); + send_adv_buf(*adv, (uint8_t)i, previous); previous = (uint8_t)i; if (!reverse) { - buf++; + adv++; i++; } else { - buf--; + adv--; i--; } } @@ -419,24 +415,24 @@ static void send_adv_array(struct net_buf **buf, size_t num_buf, bool reverse) static void test_tx_cb_single(void) { - struct net_buf *buf; + struct bt_mesh_adv *adv; int err; bt_init(); adv_init(); - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); - ASSERT_FALSE_MSG(!buf, "Out of buffers\n"); + ASSERT_FALSE_MSG(!adv, "Out of advs\n"); send_cb.start = single_start_cb; send_cb.end = single_end_cb; - net_buf_add_mem(buf, txt_msg, sizeof(txt_msg)); + net_buf_simple_add_mem(&adv->b, txt_msg, sizeof(txt_msg)); seq_checker = 0; tx_timestamp = k_uptime_get(); - bt_mesh_adv_send(buf, &send_cb, (void *)cb_msg); - net_buf_unref(buf); + bt_mesh_adv_send(adv, &send_cb, (void *)cb_msg); + bt_mesh_adv_unref(adv); err = k_sem_take(&observer_sem, K_SECONDS(1)); ASSERT_OK_MSG(err, "Didn't call end tx cb."); @@ -457,37 +453,37 @@ static void test_rx_xmit(void) static void test_tx_cb_multi(void) { - struct net_buf *buf[CONFIG_BT_MESH_ADV_BUF_COUNT]; + struct bt_mesh_adv *adv[CONFIG_BT_MESH_ADV_BUF_COUNT]; int err; bt_init(); adv_init(); - /* Allocate all network buffers. */ - allocate_all_array(buf, ARRAY_SIZE(buf), BT_MESH_TRANSMIT(2, 20)); + /* Allocate all network advs. */ + allocate_all_array(adv, ARRAY_SIZE(adv), BT_MESH_TRANSMIT(2, 20)); - /* Start single adv to reallocate one network buffer in callback. - * Check that the buffer is freed before cb is triggered. + /* Start single adv to reallocate one network adv in callback. + * Check that the adv is freed before cb is triggered. */ send_cb.start = NULL; send_cb.end = realloc_end_cb; - net_buf_add_mem(buf[0], txt_msg, sizeof(txt_msg)); + net_buf_simple_add_mem(&(adv[0]->b), txt_msg, sizeof(txt_msg)); - bt_mesh_adv_send(buf[0], &send_cb, buf[0]); - net_buf_unref(buf[0]); + bt_mesh_adv_send(adv[0], &send_cb, adv[0]); + bt_mesh_adv_unref(adv[0]); err = k_sem_take(&observer_sem, K_SECONDS(1)); - ASSERT_OK_MSG(err, "Didn't call the end tx cb that reallocates buffer one more time."); + ASSERT_OK_MSG(err, "Didn't call the end tx cb that reallocates adv one more time."); - /* Start multi advs to check that all buffers are sent and cbs are triggered. */ + /* Start multi advs to check that all advs are sent and cbs are triggered. */ send_cb.start = seq_start_cb; send_cb.end = seq_end_cb; seq_checker = 0; for (int i = 0; i < CONFIG_BT_MESH_ADV_BUF_COUNT; i++) { - net_buf_add_le32(buf[i], i); - bt_mesh_adv_send(buf[i], &send_cb, (void *)(intptr_t)i); - net_buf_unref(buf[i]); + net_buf_simple_add_le32(&(adv[i]->b), i); + bt_mesh_adv_send(adv[i], &send_cb, (void *)(intptr_t)i); + bt_mesh_adv_unref(adv[i]); } err = k_sem_take(&observer_sem, K_SECONDS(10)); @@ -530,10 +526,10 @@ static void test_tx_proxy_mixin(void) * Advertising the proxy service should be resumed after * finishing advertising the message. */ - struct net_buf *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + struct bt_mesh_adv *adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(5, 20), K_NO_WAIT); - net_buf_add_mem(buf, txt_msg, sizeof(txt_msg)); - bt_mesh_adv_send(buf, NULL, NULL); + net_buf_simple_add_mem(&adv->b, txt_msg, sizeof(txt_msg)); + bt_mesh_adv_send(adv, NULL, NULL); k_sleep(K_MSEC(150)); /* Let the tester to measure an interval between advertisements again. */ @@ -577,46 +573,46 @@ static void test_rx_proxy_mixin(void) static void test_tx_send_order(void) { - struct net_buf *buf[CONFIG_BT_MESH_ADV_BUF_COUNT]; + struct bt_mesh_adv *adv[CONFIG_BT_MESH_ADV_BUF_COUNT]; uint8_t xmit = BT_MESH_TRANSMIT(2, 20); bt_init(); adv_init(); /* Verify sending order */ - allocate_all_array(buf, ARRAY_SIZE(buf), xmit); + allocate_all_array(adv, ARRAY_SIZE(adv), xmit); verify_adv_queue_overflow(); - send_adv_array(&buf[0], ARRAY_SIZE(buf), false); + send_adv_array(&adv[0], ARRAY_SIZE(adv), false); /* Wait for no message receive window to end. */ ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)), "Didn't call the last end tx cb."); - /* Verify buffer allocation/deallocation after sending */ - allocate_all_array(buf, ARRAY_SIZE(buf), xmit); + /* Verify adv allocation/deallocation after sending */ + allocate_all_array(adv, ARRAY_SIZE(adv), xmit); verify_adv_queue_overflow(); for (int i = 0; i < CONFIG_BT_MESH_ADV_BUF_COUNT; i++) { - net_buf_unref(buf[i]); - buf[i] = NULL; + bt_mesh_adv_unref(adv[i]); + adv[i] = NULL; } - /* Check that it possible to add just one net buf. */ - allocate_all_array(buf, 1, xmit); + /* Check that it possible to add just one net adv. */ + allocate_all_array(adv, 1, xmit); PASS(); } static void test_tx_reverse_order(void) { - struct net_buf *buf[CONFIG_BT_MESH_ADV_BUF_COUNT]; + struct bt_mesh_adv *adv[CONFIG_BT_MESH_ADV_BUF_COUNT]; uint8_t xmit = BT_MESH_TRANSMIT(2, 20); bt_init(); adv_init(); /* Verify reversed sending order */ - allocate_all_array(buf, ARRAY_SIZE(buf), xmit); + allocate_all_array(adv, ARRAY_SIZE(adv), xmit); - send_adv_array(&buf[CONFIG_BT_MESH_ADV_BUF_COUNT - 1], ARRAY_SIZE(buf), true); + send_adv_array(&adv[CONFIG_BT_MESH_ADV_BUF_COUNT - 1], ARRAY_SIZE(adv), true); /* Wait for no message receive window to end. */ ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)), @@ -627,31 +623,31 @@ static void test_tx_reverse_order(void) static void test_tx_random_order(void) { - struct net_buf *buf[3]; + struct bt_mesh_adv *adv[3]; uint8_t xmit = BT_MESH_TRANSMIT(0, 20); bt_init(); adv_init(); /* Verify random order calls */ - num_adv_sent = ARRAY_SIZE(buf); + num_adv_sent = ARRAY_SIZE(adv); previous_checker = 0xff; - buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + adv[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); - ASSERT_FALSE_MSG(!buf[0], "Out of buffers\n"); - buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + ASSERT_FALSE_MSG(!adv[0], "Out of advs\n"); + adv[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); - ASSERT_FALSE_MSG(!buf[1], "Out of buffers\n"); + ASSERT_FALSE_MSG(!adv[1], "Out of advs\n"); - send_adv_buf(buf[0], 0, 0xff); + send_adv_buf(adv[0], 0, 0xff); - buf[2] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, + adv[2] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); - ASSERT_FALSE_MSG(!buf[2], "Out of buffers\n"); + ASSERT_FALSE_MSG(!adv[2], "Out of advs\n"); - send_adv_buf(buf[2], 2, 0); + send_adv_buf(adv[2], 2, 0); - send_adv_buf(buf[1], 1, 2); + send_adv_buf(adv[1], 1, 2); /* Wait for no message receive window to end. */ ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)), diff --git a/tests/bsim/bluetooth/mesh/src/test_beacon.c b/tests/bsim/bluetooth/mesh/src/test_beacon.c index e93c2301e46..038c705f2cb 100644 --- a/tests/bsim/bluetooth/mesh/src/test_beacon.c +++ b/tests/bsim/bluetooth/mesh/src/test_beacon.c @@ -6,7 +6,6 @@ #include #include #include "mesh_test.h" -#include "mesh/adv.h" #include "mesh/net.h" #include "mesh/beacon.h" #include "mesh/mesh.h" diff --git a/tests/bsim/bluetooth/mesh/src/test_blob.c b/tests/bsim/bluetooth/mesh/src/test_blob.c index 4258ff77c62..0d3a69da2fc 100644 --- a/tests/bsim/bluetooth/mesh/src/test_blob.c +++ b/tests/bsim/bluetooth/mesh/src/test_blob.c @@ -6,9 +6,9 @@ #include "mesh_test.h" #include "dfu_blob_common.h" #include "friendship_common.h" +#include "mesh/adv.h" #include "mesh/blob.h" #include "argparse.h" -#include "mesh/adv.h" #define LOG_MODULE_NAME test_blob diff --git a/tests/bsim/bluetooth/mesh/src/test_dfu.c b/tests/bsim/bluetooth/mesh/src/test_dfu.c index 06f7248a6ad..1b54e873cc5 100644 --- a/tests/bsim/bluetooth/mesh/src/test_dfu.c +++ b/tests/bsim/bluetooth/mesh/src/test_dfu.c @@ -6,7 +6,6 @@ #include "mesh_test.h" #include "mesh/dfd_srv_internal.h" #include "mesh/dfu_slot.h" -#include "mesh/adv.h" #include "mesh/dfu.h" #include "mesh/blob.h" #include "argparse.h" diff --git a/tests/bsim/bluetooth/mesh/src/test_provision.c b/tests/bsim/bluetooth/mesh/src/test_provision.c index f2c98778a3b..3d0e8010c75 100644 --- a/tests/bsim/bluetooth/mesh/src/test_provision.c +++ b/tests/bsim/bluetooth/mesh/src/test_provision.c @@ -28,7 +28,6 @@ #define LOG_MODULE_NAME mesh_prov #include -#include "mesh/adv.h" #include "mesh/rpr.h" LOG_MODULE_REGISTER(LOG_MODULE_NAME); diff --git a/tests/bsim/bluetooth/mesh/src/test_scanner.c b/tests/bsim/bluetooth/mesh/src/test_scanner.c index 12557b7e1b2..a63284701df 100644 --- a/tests/bsim/bluetooth/mesh/src/test_scanner.c +++ b/tests/bsim/bluetooth/mesh/src/test_scanner.c @@ -6,7 +6,6 @@ #include #include "mesh_test.h" #include "mesh/net.h" -#include "mesh/adv.h" #include "mesh/mesh.h" #include "mesh/foundation.h" From 113bf618d85999f6c705ab4bb8b5304873b4e46c Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1012/1623] [nrf fromtree] Bluetooth: Mesh: access tx msg randomizer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit adds implementation of the specification recommendations regarding randomization of responses on the access layer. 3.7.3.1 Transmitting an Access messages Signed-off-by: Aleksandr Khromykh (cherry picked from commit d175ac0572c454eec99b11f9f6d0350efa5a5f8b) Signed-off-by: Håvard Reierstad --- .../bluetooth/api/mesh/access.rst | 33 ++ doc/releases/release-notes-3.6.rst | 5 + include/zephyr/bluetooth/mesh/msg.h | 3 + .../bluetooth/mesh/boards/bbc_microbit.conf | 1 + .../mesh_demo/boards/bbc_microbit.conf | 1 + subsys/bluetooth/mesh/CMakeLists.txt | 2 + subsys/bluetooth/mesh/Kconfig | 35 ++ subsys/bluetooth/mesh/access.c | 29 ++ subsys/bluetooth/mesh/access.h | 17 + subsys/bluetooth/mesh/delayable_msg.c | 314 ++++++++++++++++++ subsys/bluetooth/mesh/delayable_msg.h | 16 + subsys/bluetooth/mesh/main.c | 4 + 12 files changed, 460 insertions(+) create mode 100644 subsys/bluetooth/mesh/delayable_msg.c create mode 100644 subsys/bluetooth/mesh/delayable_msg.h diff --git a/doc/connectivity/bluetooth/api/mesh/access.rst b/doc/connectivity/bluetooth/api/mesh/access.rst index e4a94440556..7030a3c14b2 100644 --- a/doc/connectivity/bluetooth/api/mesh/access.rst +++ b/doc/connectivity/bluetooth/api/mesh/access.rst @@ -222,6 +222,39 @@ They are used to represent the new content of the mirrored pages when the Compos change after a firmware update. See :ref:`bluetooth_mesh_dfu_srv_comp_data_and_models_metadata` for details. +Delayable messages +================== + +The delayable message functionality is enabled with Kconfig option +:kconfig:option:`CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG`. +This is an optional functionality that implements specification recommendations for +messages that are transmitted by a model in a response to a received message, also called +response messages. + +Response messages should be sent with the following random delays: + +* Between 20 and 50 milliseconds if the received message was sent + to a unicast address +* Between 20 and 500 milliseconds if the received message was sent + to a group or virtual address + +The delayable message functionality is triggered if the :c:member:`bt_mesh_msg_ctx.rnd_delay` +flag is set. +The delayable message functionality stores messages in the local memory while they are +waiting for the random delay expiration. + +If the transport layer doesn't have sufficient memory to send a message at the moment +the random delay expires, the message is postponed for another 10 milliseconds. +If the transport layer cannot send a message for any other reason, the delayable message +functionality raises the :c:member:`bt_mesh_send_cb.start` callback with a transport layer +error code. + +If the delayable message functionality cannot find enough free memory to store an incoming +message, it will send messages with delay close to expiration to free memory. + +When the mesh stack is suspended or reset, messages not yet sent are removed and +the :c:member:`bt_mesh_send_cb.start` callback is raised with an error code. + API reference ************* diff --git a/doc/releases/release-notes-3.6.rst b/doc/releases/release-notes-3.6.rst index 676e16fa77c..8edd3280382 100644 --- a/doc/releases/release-notes-3.6.rst +++ b/doc/releases/release-notes-3.6.rst @@ -52,6 +52,11 @@ Bluetooth * Mesh + * Added the delayable messages functionality to apply random delays for + the transmitted responses on the Access layer. + The functionality is enabled by the :kconfig:option:`CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG` + Kconfig option. + * Controller Boards & SoC Support diff --git a/include/zephyr/bluetooth/mesh/msg.h b/include/zephyr/bluetooth/mesh/msg.h index e52ca85e3a4..8a7ce1a7128 100644 --- a/include/zephyr/bluetooth/mesh/msg.h +++ b/include/zephyr/bluetooth/mesh/msg.h @@ -98,6 +98,9 @@ struct bt_mesh_msg_ctx { /** Force sending reliably by using segment acknowledgment */ bool send_rel; + /** Send message with a random delay according to the Access layer transmitting rules. */ + bool rnd_delay; + /** TTL, or BT_MESH_TTL_DEFAULT for default TTL. */ uint8_t send_ttl; }; diff --git a/samples/bluetooth/mesh/boards/bbc_microbit.conf b/samples/bluetooth/mesh/boards/bbc_microbit.conf index 26fb05301c1..1655768864b 100644 --- a/samples/bluetooth/mesh/boards/bbc_microbit.conf +++ b/samples/bluetooth/mesh/boards/bbc_microbit.conf @@ -32,3 +32,4 @@ CONFIG_BT_MESH_SUBNET_COUNT=1 CONFIG_BT_MESH_APP_KEY_COUNT=1 CONFIG_BT_MESH_MODEL_GROUP_COUNT=1 CONFIG_BT_MESH_LABEL_COUNT=0 +CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG=n diff --git a/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf b/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf index 5eb087c4ced..64adc465794 100644 --- a/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf +++ b/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf @@ -22,3 +22,4 @@ CONFIG_BT_MESH_BEACON_ENABLED=n CONFIG_BT_MESH_LABEL_COUNT=1 CONFIG_BT_MESH_SETTINGS_WORKQ=n +CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG=n diff --git a/subsys/bluetooth/mesh/CMakeLists.txt b/subsys/bluetooth/mesh/CMakeLists.txt index 10b142e87f5..3fd2e7c3bfc 100644 --- a/subsys/bluetooth/mesh/CMakeLists.txt +++ b/subsys/bluetooth/mesh/CMakeLists.txt @@ -122,6 +122,8 @@ zephyr_library_sources_ifdef(CONFIG_BT_MESH_SOLICITATION solicitation.c) zephyr_library_sources_ifdef(CONFIG_BT_MESH_STATISTIC statistic.c) +zephyr_library_sources_ifdef(CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG delayable_msg.c) + if (CONFIG_BT_MESH_USES_TINYCRYPT) zephyr_library_sources(crypto_tc.c) else() diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 0c654e18064..3bc7dd2940f 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -628,6 +628,41 @@ config BT_MESH_LABEL_NO_RECOVER unprovisioned before upgrading to the version with this option). The option is marked as deprecated to remove the recovery code eventually. +menuconfig BT_MESH_ACCESS_DELAYABLE_MSG + bool "Access layer tx delayable message" + help + Enable following of the message transmitting recommendations, the Access layer + specification. The recommendations are optional. + However, they are strictly recommended if the device participates in the network with + intensive communication where the device receives a lot of requests that require responses. + +if BT_MESH_ACCESS_DELAYABLE_MSG + +config BT_MESH_ACCESS_DELAYABLE_MSG_COUNT + int "Number of simultaneously delayed messages" + default 4 + help + The maximum number of messages the Access layer can manage to delay + at the same time. The number of messages can be handled only if the Access layer + has a sufficient amount of memory to store the model payload for them. + +config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE + int "Maximum delayable message storage chunk" + default 20 + help + Size of memory that Access layer uses to split model message to. It allocates + a sufficient number of these chunks from the pool to store the full model payload. + +config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT + int "Maximum number of available chunks" + default 20 + help + The maximum number of available chunks the Access layer allocates to store model payload. + It is recommended to keep chunk size equal to the reasonable small value to prevent + unnecessary memory wasting. + +endif # BT_MESH_ACCESS_DELAYABLE_MSG + endmenu # Access layer menu "Models" diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index f7de46fe167..4cffe064329 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -27,6 +27,7 @@ #include "op_agg.h" #include "settings.h" #include "va.h" +#include "delayable_msg.h" #define LOG_LEVEL CONFIG_BT_MESH_ACCESS_LOG_LEVEL #include @@ -1518,6 +1519,13 @@ int bt_mesh_model_send(const struct bt_mesh_model *model, struct bt_mesh_msg_ctx return -EINVAL; } +#if defined CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG + if (ctx->rnd_delay) { + return bt_mesh_delayable_msg_manage(ctx, msg, bt_mesh_model_elem(model)->rt->addr, + cb, cb_data); + } +#endif + return bt_mesh_access_send(ctx, msg, bt_mesh_model_elem(model)->rt->addr, cb, cb_data); } @@ -2613,3 +2621,24 @@ uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf) return page; } + +void bt_mesh_access_init(void) +{ +#if defined CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG + bt_mesh_delayable_msg_init(); +#endif +} + +void bt_mesh_access_suspend(void) +{ +#if defined CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG + bt_mesh_delayable_msg_stop(); +#endif +} + +void bt_mesh_access_reset(void) +{ +#if defined CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG + bt_mesh_delayable_msg_stop(); +#endif +} diff --git a/subsys/bluetooth/mesh/access.h b/subsys/bluetooth/mesh/access.h index 48e0eadec10..210fceee319 100644 --- a/subsys/bluetooth/mesh/access.h +++ b/subsys/bluetooth/mesh/access.h @@ -96,8 +96,25 @@ void bt_mesh_msg_cb_set(void (*cb)(uint32_t opcode, struct bt_mesh_msg_ctx *ctx, * * @param ctx The Bluetooth Mesh message context. * @param buf The message payload. + * @param src_addr The source address of model + * @param cb Callback function. + * @param cb_data Callback data. * * @return 0 on success or negative error code on failure. */ int bt_mesh_access_send(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, uint16_t src_addr, const struct bt_mesh_send_cb *cb, void *cb_data); + +/** @brief Initialize the Access layer. + * + * Initialize the delayable message mechanism if it has been enabled. + */ +void bt_mesh_access_init(void); + +/** @brief Suspend the Access layer. + */ +void bt_mesh_access_suspend(void); + +/** @brief Reset the Access layer. + */ +void bt_mesh_access_reset(void); diff --git a/subsys/bluetooth/mesh/delayable_msg.c b/subsys/bluetooth/mesh/delayable_msg.c new file mode 100644 index 00000000000..5fa43205d63 --- /dev/null +++ b/subsys/bluetooth/mesh/delayable_msg.c @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include +#include + +#include "msg.h" +#include "access.h" +#include "net.h" + +#define LOG_LEVEL CONFIG_BT_MESH_ACCESS_LOG_LEVEL +#include +LOG_MODULE_REGISTER(bt_mesh_delayable_msg); + +static void delayable_msg_handler(struct k_work *w); +static bool push_msg_from_delayable_msgs(void); + +static struct delayable_msg_chunk { + sys_snode_t node; + uint8_t data[CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE]; +} delayable_msg_chunks[CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT]; + +static struct delayable_msg_ctx { + sys_snode_t node; + sys_slist_t chunks; + struct bt_mesh_msg_ctx ctx; + uint16_t src_addr; + const struct bt_mesh_send_cb *cb; + void *cb_data; + uint32_t fired_time; + uint16_t len; +} delayable_msgs_ctx[CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_COUNT]; + +static struct { + sys_slist_t busy_ctx; + sys_slist_t free_ctx; + sys_slist_t free_chunks; + struct k_work_delayable random_delay; +} access_delayable_msg = {.random_delay = Z_WORK_DELAYABLE_INITIALIZER(delayable_msg_handler)}; + +static void put_ctx_to_busy_list(struct delayable_msg_ctx *ctx) +{ + struct delayable_msg_ctx *curr_ctx; + sys_slist_t *list = &access_delayable_msg.busy_ctx; + sys_snode_t *head = sys_slist_peek_head(list); + sys_snode_t *curr = head; + sys_snode_t *prev = curr; + + if (!head) { + sys_slist_append(list, &ctx->node); + return; + } + + do { + curr_ctx = CONTAINER_OF(curr, struct delayable_msg_ctx, node); + if (ctx->fired_time < curr_ctx->fired_time) { + if (curr == head) { + sys_slist_prepend(list, &ctx->node); + } else { + sys_slist_insert(list, prev, &ctx->node); + } + return; + } + prev = curr; + } while ((curr = sys_slist_peek_next(curr))); + + sys_slist_append(list, &ctx->node); +} + +static struct delayable_msg_ctx *peek_pending_msg(void) +{ + struct delayable_msg_ctx *pending_msg = NULL; + sys_snode_t *node = sys_slist_peek_head(&access_delayable_msg.busy_ctx); + + if (node) { + pending_msg = CONTAINER_OF(node, struct delayable_msg_ctx, node); + } + + return pending_msg; +} + +static void reschedule_delayable_msg(struct delayable_msg_ctx *msg) +{ + uint32_t curr_time; + k_timeout_t delay = K_NO_WAIT; + struct delayable_msg_ctx *pending_msg; + + if (msg) { + put_ctx_to_busy_list(msg); + } + + pending_msg = peek_pending_msg(); + + if (!pending_msg) { + return; + } + + curr_time = k_uptime_get_32(); + if (curr_time < pending_msg->fired_time) { + delay = K_MSEC(pending_msg->fired_time - curr_time); + } + + k_work_reschedule(&access_delayable_msg.random_delay, delay); +} + +static int allocate_delayable_msg_chunks(struct delayable_msg_ctx *msg, int number) +{ + sys_snode_t *node; + + for (int i = 0; i < number; i++) { + node = sys_slist_get(&access_delayable_msg.free_chunks); + if (!node) { + LOG_WRN("Unable allocate %u chunks, allocated %u", number, i); + return i; + } + sys_slist_append(&msg->chunks, node); + } + + return number; +} + +static void release_delayable_msg_chunks(struct delayable_msg_ctx *msg) +{ + sys_snode_t *node; + + while ((node = sys_slist_get(&msg->chunks))) { + sys_slist_append(&access_delayable_msg.free_chunks, node); + } +} + +static struct delayable_msg_ctx *allocate_delayable_msg_ctx(void) +{ + struct delayable_msg_ctx *msg; + sys_snode_t *node; + + if (sys_slist_is_empty(&access_delayable_msg.free_ctx)) { + LOG_WRN("Purge pending delayable message."); + if (!push_msg_from_delayable_msgs()) { + return NULL; + } + } + + node = sys_slist_get(&access_delayable_msg.free_ctx); + msg = CONTAINER_OF(node, struct delayable_msg_ctx, node); + sys_slist_init(&msg->chunks); + + return msg; +} + +static void release_delayable_msg_ctx(struct delayable_msg_ctx *ctx) +{ + if (sys_slist_find_and_remove(&access_delayable_msg.busy_ctx, &ctx->node)) { + sys_slist_append(&access_delayable_msg.free_ctx, &ctx->node); + } +} + +static bool push_msg_from_delayable_msgs(void) +{ + sys_snode_t *node; + struct delayable_msg_chunk *chunk; + struct delayable_msg_ctx *msg = peek_pending_msg(); + uint16_t len = msg->len; + int err; + + if (!msg) { + return false; + } + + NET_BUF_SIMPLE_DEFINE(buf, BT_MESH_TX_SDU_MAX); + + SYS_SLIST_FOR_EACH_NODE(&msg->chunks, node) { + uint16_t tmp = MIN(CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE, len); + + chunk = CONTAINER_OF(node, struct delayable_msg_chunk, node); + memcpy(net_buf_simple_add(&buf, tmp), chunk->data, tmp); + len -= tmp; + } + + msg->ctx.rnd_delay = false; + err = bt_mesh_access_send(&msg->ctx, &buf, msg->src_addr, msg->cb, msg->cb_data); + msg->ctx.rnd_delay = true; + + if (err == -EBUSY || err == -ENOBUFS) { + return false; + } + + release_delayable_msg_chunks(msg); + release_delayable_msg_ctx(msg); + + if (err && msg->cb && msg->cb->start) { + msg->cb->start(0, err, msg->cb_data); + } + + return true; +} + +static void delayable_msg_handler(struct k_work *w) +{ + if (!push_msg_from_delayable_msgs()) { + sys_snode_t *node = sys_slist_get(&access_delayable_msg.busy_ctx); + struct delayable_msg_ctx *pending_msg = + CONTAINER_OF(node, struct delayable_msg_ctx, node); + + pending_msg->fired_time += 10; + reschedule_delayable_msg(pending_msg); + } else { + reschedule_delayable_msg(NULL); + } +} + +int bt_mesh_delayable_msg_manage(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, + uint16_t src_addr, const struct bt_mesh_send_cb *cb, void *cb_data) +{ + sys_snode_t *node; + struct delayable_msg_ctx *msg; + uint16_t random_delay; + int total_number = DIV_ROUND_UP(buf->size, CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE); + int allocated_number = 0; + uint16_t len = buf->len; + + if (atomic_test_bit(bt_mesh.flags, BT_MESH_SUSPENDED)) { + LOG_WRN("Refusing to allocate message context while suspended"); + return -ENODEV; + } + + if (total_number > CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT) { + return -EINVAL; + } + + msg = allocate_delayable_msg_ctx(); + if (!msg) { + LOG_WRN("No available free delayable message context."); + return -ENOMEM; + } + + do { + allocated_number += + allocate_delayable_msg_chunks(msg, total_number - allocated_number); + + if (total_number > allocated_number) { + LOG_DBG("Unable allocate %u chunks, allocated %u", total_number, + allocated_number); + if (!push_msg_from_delayable_msgs()) { + LOG_WRN("No available chunk memory."); + release_delayable_msg_chunks(msg); + release_delayable_msg_ctx(msg); + return -ENOMEM; + } + } + } while (total_number > allocated_number); + + SYS_SLIST_FOR_EACH_NODE(&msg->chunks, node) { + uint16_t tmp = MIN(CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE, buf->len); + + struct delayable_msg_chunk *chunk = + CONTAINER_OF(node, struct delayable_msg_chunk, node); + + memcpy(chunk->data, net_buf_simple_pull_mem(buf, tmp), tmp); + } + + bt_rand(&random_delay, sizeof(uint16_t)); + random_delay = 20 + random_delay % (BT_MESH_ADDR_IS_UNICAST(ctx->recv_dst) ? 30 : 480); + msg->fired_time = k_uptime_get_32() + random_delay; + msg->ctx = *ctx; + msg->src_addr = src_addr; + msg->cb = cb; + msg->cb_data = cb_data; + msg->len = len; + + reschedule_delayable_msg(msg); + + return 0; +} + +void bt_mesh_delayable_msg_init(void) +{ + sys_slist_init(&access_delayable_msg.busy_ctx); + sys_slist_init(&access_delayable_msg.free_ctx); + sys_slist_init(&access_delayable_msg.free_chunks); + + for (int i = 0; i < CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_COUNT; i++) { + sys_slist_append(&access_delayable_msg.free_ctx, &delayable_msgs_ctx[i].node); + } + + for (int i = 0; i < CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT; i++) { + sys_slist_append(&access_delayable_msg.free_chunks, &delayable_msg_chunks[i].node); + } +} + +void bt_mesh_delayable_msg_stop(void) +{ + sys_snode_t *node; + struct delayable_msg_ctx *ctx; + + k_work_cancel_delayable(&access_delayable_msg.random_delay); + + while ((node = sys_slist_peek_head(&access_delayable_msg.busy_ctx))) { + ctx = CONTAINER_OF(node, struct delayable_msg_ctx, node); + release_delayable_msg_chunks(ctx); + release_delayable_msg_ctx(ctx); + + if (ctx->cb && ctx->cb->start) { + ctx->cb->start(0, -ENODEV, ctx->cb_data); + } + } +} diff --git a/subsys/bluetooth/mesh/delayable_msg.h b/subsys/bluetooth/mesh/delayable_msg.h new file mode 100644 index 00000000000..1ab5dde2e76 --- /dev/null +++ b/subsys/bluetooth/mesh/delayable_msg.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_DELAYABLE_MSG_H__ +#define ZEPHYR_INCLUDE_BLUETOOTH_MESH_DELAYABLE_MSG_H__ + +int bt_mesh_delayable_msg_manage(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, + uint16_t src_addr, const struct bt_mesh_send_cb *cb, + void *cb_data); +void bt_mesh_delayable_msg_init(void); +void bt_mesh_delayable_msg_stop(void); + +#endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_DELAYABLE_MSG_H__ */ diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index 89115ebe3e8..2689a3355c1 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -359,6 +359,7 @@ void bt_mesh_reset(void) */ (void)k_work_cancel_delayable(&bt_mesh.ivu_timer); + bt_mesh_access_reset(); bt_mesh_model_reset(); bt_mesh_cfg_default_set(); bt_mesh_trans_reset(); @@ -459,6 +460,8 @@ int bt_mesh_suspend(void) bt_mesh_model_foreach(model_suspend, NULL); + bt_mesh_access_suspend(); + err = bt_mesh_adv_disable(); if (err) { atomic_clear_bit(bt_mesh.flags, BT_MESH_SUSPENDED); @@ -558,6 +561,7 @@ int bt_mesh_init(const struct bt_mesh_prov *prov, bt_mesh_cfg_default_set(); bt_mesh_net_init(); bt_mesh_trans_init(); + bt_mesh_access_init(); bt_mesh_hb_init(); bt_mesh_beacon_init(); bt_mesh_adv_init(); From 7184e98ff549316a48c49f19b24d8e07472bfd1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1013/1623] [nrf fromtree] Bluetooth: Mesh: Rename prov_dev->provisionee MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Renames "prov device" references and options to "provisionee" to align implementation with Mesh Protocol specification v1.1, section 5.4. Signed-off-by: Anders Storrø (cherry picked from commit 25d44a828d404422099dfa4d8875438dacf1f38c) Signed-off-by: Håvard Reierstad --- doc/connectivity/bluetooth/api/mesh/shell.rst | 4 +- doc/releases/migration-guide-3.6.rst | 25 +++++-- samples/bluetooth/mesh_provisioner/prj.conf | 2 +- subsys/bluetooth/Kconfig.logging | 2 +- subsys/bluetooth/mesh/CMakeLists.txt | 2 +- subsys/bluetooth/mesh/Kconfig | 15 +++- .../mesh/{prov_device.c => provisionee.c} | 8 +-- subsys/bluetooth/mesh/provisioner.c | 72 +++++++++---------- subsys/bluetooth/mesh/shell/shell.c | 8 +-- tests/bsim/bluetooth/mesh/prj.conf | 2 +- tests/bsim/bluetooth/mesh/prj_mesh1d1.conf | 2 +- 11 files changed, 81 insertions(+), 61 deletions(-) rename subsys/bluetooth/mesh/{prov_device.c => provisionee.c} (99%) diff --git a/doc/connectivity/bluetooth/api/mesh/shell.rst b/doc/connectivity/bluetooth/api/mesh/shell.rst index 9d5829fe380..3d925f29a3e 100644 --- a/doc/connectivity/bluetooth/api/mesh/shell.rst +++ b/doc/connectivity/bluetooth/api/mesh/shell.rst @@ -282,7 +282,7 @@ Provisioning ============ To allow a device to broadcast connectable unprovisioned beacons, the -:kconfig:option:`CONFIG_BT_MESH_PROV_DEVICE` configuration option must be enabled, along with the +:kconfig:option:`CONFIG_BT_MESH_PROVISIONEE` configuration option must be enabled, along with the :kconfig:option:`CONFIG_BT_MESH_PB_GATT` option. ``mesh prov pb-gatt `` @@ -295,7 +295,7 @@ To allow a device to broadcast connectable unprovisioned beacons, the * ``Val``: Enable or disable provisioning with GATT To allow a device to broadcast unprovisioned beacons, the -:kconfig:option:`CONFIG_BT_MESH_PROV_DEVICE` configuration option must be enabled, along with the +:kconfig:option:`CONFIG_BT_MESH_PROVISIONEE` configuration option must be enabled, along with the :kconfig:option:`CONFIG_BT_MESH_PB_ADV` option. ``mesh prov pb-adv `` diff --git a/doc/releases/migration-guide-3.6.rst b/doc/releases/migration-guide-3.6.rst index c4b93e5f150..c1739adf74d 100644 --- a/doc/releases/migration-guide-3.6.rst +++ b/doc/releases/migration-guide-3.6.rst @@ -113,13 +113,24 @@ Bluetooth cleared on :c:func:`bt_enable`. Callbacks can now be registered before the initial call to :c:func:`bt_enable`, and should no longer be re-registered after a :c:func:`bt_disable` :c:func:`bt_enable` cycle. (:github:`63693`) -* The Bluetooth Mesh ``model`` declaration has been changed to add prefix ``const``. - The ``model->user_data``, ``model->elem_idx`` and ``model->mod_idx`` field has been changed to - the new runtime structure, replaced by ``model->rt->user_data``, ``model->rt->elem_idx`` and - ``model->rt->mod_idx`` separately. (:github:`65152`) -* The Bluetooth Mesh ``element`` declaration has been changed to add prefix ``const``. - The ``elem->addr`` field has been changed to the new runtime structure, replaced by - ``elem->rt->addr``. (:github:`65388`) +* The Bluetooth UUID has been modified to rodata in ``BT_UUID_DECLARE_16``, ``BT_UUID_DECLARE_32` + and ``BT_UUID_DECLARE_128`` as the return value has been changed to `const`. + Any pointer to a UUID must be prefixed with `const`, otherwise there will be a compilation warning. + For example change ``struct bt_uuid *uuid = BT_UUID_DECLARE_16(xx)`` to + ``const struct bt_uuid *uuid = BT_UUID_DECLARE_16(xx)``. (:github:`66136`) + +* Mesh + + * The Bluetooth Mesh ``model`` declaration has been changed to add prefix ``const``. + The ``model->user_data``, ``model->elem_idx`` and ``model->mod_idx`` field has been changed to + the new runtime structure, replaced by ``model->rt->user_data``, ``model->rt->elem_idx`` and + ``model->rt->mod_idx`` separately. (:github:`65152`) + * The Bluetooth Mesh ``element`` declaration has been changed to add prefix ``const``. + The ``elem->addr`` field has been changed to the new runtime structure, replaced by + ``elem->rt->addr``. (:github:`65388`) + * Deprecated :kconfig:option:`CONFIG_BT_MESH_PROV_DEVICE`. This option is + replaced by new option :kconfig:option:`CONFIG_BT_MESH_PROVISIONEE` to + be aligned with Mesh Protocol Specification v1.1, section 5.4. (:github:`64252`) LoRaWAN ======= diff --git a/samples/bluetooth/mesh_provisioner/prj.conf b/samples/bluetooth/mesh_provisioner/prj.conf index bfc6d5a1241..341dd49ed2e 100644 --- a/samples/bluetooth/mesh_provisioner/prj.conf +++ b/samples/bluetooth/mesh_provisioner/prj.conf @@ -33,7 +33,7 @@ CONFIG_BT_MESH_RELAY=y CONFIG_BT_MESH_RELAY_RETRANSMIT_COUNT=3 CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_PROV_DEVICE=n +CONFIG_BT_MESH_PROVISIONEE=n CONFIG_BT_MESH_CDB=y CONFIG_BT_MESH_CDB_NODE_COUNT=16 CONFIG_BT_MESH_CDB_SUBNET_COUNT=3 diff --git a/subsys/bluetooth/Kconfig.logging b/subsys/bluetooth/Kconfig.logging index 6d8b999e03c..b6505f6e53a 100644 --- a/subsys/bluetooth/Kconfig.logging +++ b/subsys/bluetooth/Kconfig.logging @@ -1002,7 +1002,7 @@ legacy-debug-sym = BT_MESH_DEBUG_PROVISIONER module-str = "Provisioner" source "subsys/bluetooth/common/Kconfig.template.log_config_bt" -module = BT_MESH_PROV_DEVICE +module = BT_MESH_PROVISIONEE legacy-debug-sym = BT_MESH_DEBUG_PROV_DEVICE module-str = "Provisioning device" source "subsys/bluetooth/common/Kconfig.template.log_config_bt" diff --git a/subsys/bluetooth/mesh/CMakeLists.txt b/subsys/bluetooth/mesh/CMakeLists.txt index 3fd2e7c3bfc..fe4444b28ab 100644 --- a/subsys/bluetooth/mesh/CMakeLists.txt +++ b/subsys/bluetooth/mesh/CMakeLists.txt @@ -40,7 +40,7 @@ zephyr_library_sources_ifdef(CONFIG_BT_MESH_FRIEND friend.c) zephyr_library_sources_ifdef(CONFIG_BT_MESH_PROV prov.c) -zephyr_library_sources_ifdef(CONFIG_BT_MESH_PROV_DEVICE prov_device.c) +zephyr_library_sources_ifdef(CONFIG_BT_MESH_PROVISIONEE provisionee.c) zephyr_library_sources_ifdef(CONFIG_BT_MESH_PROVISIONER provisioner.c) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 3bc7dd2940f..bffbac3e8e7 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -240,7 +240,7 @@ config BT_MESH_PB_GATT select BT_MESH_GATT_SERVER select BT_MESH_PROV select BT_MESH_PB_GATT_COMMON - select BT_MESH_PROV_DEVICE + select BT_MESH_PROVISIONEE help Enable this option to allow the device to be provisioned over GATT. @@ -268,7 +268,16 @@ config BT_MESH_PB_GATT_CLIENT endif # BT_CONN config BT_MESH_PROV_DEVICE - bool "Provisioning device role support" + bool "[DEPRECATED] Provisioning device role support" + select DEPRECATED + select BT_MESH_PROVISIONEE + help + Enable this option to allow the device to be provisioned into a mesh network. + The option is marked as deprecated and will be replaced by BT_MESH_PROVISIONEE + option. + +config BT_MESH_PROVISIONEE + bool "Provisionee role support" depends on BT_MESH_PB_ADV || BT_MESH_PB_GATT default y help @@ -276,7 +285,7 @@ config BT_MESH_PROV_DEVICE config BT_MESH_PROV_OOB_PUBLIC_KEY bool "OOB Public key support" - depends on BT_MESH_PROV_DEVICE + depends on BT_MESH_PROVISIONEE help Enable this option if public key is to be exchanged via Out of Band (OOB) technology. diff --git a/subsys/bluetooth/mesh/prov_device.c b/subsys/bluetooth/mesh/provisionee.c similarity index 99% rename from subsys/bluetooth/mesh/prov_device.c rename to subsys/bluetooth/mesh/provisionee.c index 6ca65c2ec63..dcecb5838f0 100644 --- a/subsys/bluetooth/mesh/prov_device.c +++ b/subsys/bluetooth/mesh/provisionee.c @@ -32,9 +32,9 @@ #include "settings.h" #include "rpr.h" -#define LOG_LEVEL CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL +#define LOG_LEVEL CONFIG_BT_MESH_PROVISIONEE_LOG_LEVEL #include -LOG_MODULE_REGISTER(bt_mesh_prov_device); +LOG_MODULE_REGISTER(bt_mesh_provisionee); static void reprovision_fail(void); @@ -696,8 +696,8 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers) return -EALREADY; } -#if defined(CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL) - if (CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL > 2) { +#if defined(CONFIG_BT_MESH_PROVISIONEE_LOG_LEVEL) + if (CONFIG_BT_MESH_PROVISIONEE_LOG_LEVEL > 2) { struct bt_uuid_128 uuid = { .uuid = { BT_UUID_TYPE_128 } }; sys_memcpy_swap(uuid.val, bt_mesh_prov->uuid, 16); diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index ba02723e830..08b3f8bb8f1 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -46,7 +46,7 @@ static struct { uint8_t attention_duration; uint8_t uuid[16]; uint8_t new_dev_key[16]; -} prov_device; +} provisionee; static void send_pub_key(void); static void prov_dh_key_gen(void); @@ -54,8 +54,8 @@ static void prov_dh_key_gen(void); static int reset_state(void) { if (!atomic_test_bit(bt_mesh_prov_link.flags, REPROVISION) && - prov_device.node != NULL) { - bt_mesh_cdb_node_del(prov_device.node, false); + provisionee.node != NULL) { + bt_mesh_cdb_node_del(provisionee.node, false); } return bt_mesh_prov_reset_state(); @@ -86,9 +86,9 @@ static void send_invite(void) LOG_DBG(""); bt_mesh_prov_buf_init(&inv, PROV_INVITE); - net_buf_simple_add_u8(&inv, prov_device.attention_duration); + net_buf_simple_add_u8(&inv, provisionee.attention_duration); - memcpy(bt_mesh_prov_link.conf_inputs.invite, &prov_device.attention_duration, + memcpy(bt_mesh_prov_link.conf_inputs.invite, &provisionee.attention_duration, PDU_LEN_INVITE); if (bt_mesh_prov_send(&inv, NULL)) { @@ -246,8 +246,8 @@ static void prov_capabilities(const uint8_t *data) LOG_DBG("Input OOB Size: %u", caps.input_size); LOG_DBG("Input OOB Action: 0x%04x", caps.input_actions); - prov_device.elem_count = caps.elem_count; - if (prov_device.elem_count == 0) { + provisionee.elem_count = caps.elem_count; + if (provisionee.elem_count == 0) { LOG_ERR("Invalid number of elements"); prov_fail(PROV_ERR_NVAL_FMT); return; @@ -271,7 +271,7 @@ static void prov_capabilities(const uint8_t *data) if (atomic_test_bit(bt_mesh_prov_link.flags, REPROVISION)) { if (!bt_mesh_prov_link.addr) { bt_mesh_prov_link.addr = bt_mesh_cdb_free_addr_get( - prov_device.elem_count); + provisionee.elem_count); if (!bt_mesh_prov_link.addr) { LOG_ERR("Failed allocating address for node"); prov_fail(PROV_ERR_ADDR); @@ -279,19 +279,19 @@ static void prov_capabilities(const uint8_t *data) } } } else { - prov_device.node = - bt_mesh_cdb_node_alloc(prov_device.uuid, + provisionee.node = + bt_mesh_cdb_node_alloc(provisionee.uuid, bt_mesh_prov_link.addr, - prov_device.elem_count, - prov_device.net_idx); - if (prov_device.node == NULL) { + provisionee.elem_count, + provisionee.net_idx); + if (provisionee.node == NULL) { LOG_ERR("Failed allocating node 0x%04x", bt_mesh_prov_link.addr); prov_fail(PROV_ERR_RESOURCES); return; } /* Address might change in the alloc call */ - bt_mesh_prov_link.addr = prov_device.node->addr; + bt_mesh_prov_link.addr = provisionee.node->addr; } memcpy(bt_mesh_prov_link.conf_inputs.capabilities, data, PDU_LEN_CAPABILITIES); @@ -517,16 +517,16 @@ static void send_prov_data(void) LOG_DBG("Nonce: %s", bt_hex(nonce, 13)); err = bt_mesh_dev_key(bt_mesh_prov_link.dhkey, - bt_mesh_prov_link.prov_salt, prov_device.new_dev_key); + bt_mesh_prov_link.prov_salt, provisionee.new_dev_key); if (err) { LOG_ERR("Unable to generate device key"); prov_fail(PROV_ERR_UNEXP_ERR); goto session_key_destructor; } - sub = bt_mesh_cdb_subnet_get(prov_device.node->net_idx); + sub = bt_mesh_cdb_subnet_get(provisionee.node->net_idx); if (sub == NULL) { - LOG_ERR("No subnet with net_idx %u", prov_device.node->net_idx); + LOG_ERR("No subnet with net_idx %u", provisionee.node->net_idx); prov_fail(PROV_ERR_UNEXP_ERR); goto session_key_destructor; } @@ -540,14 +540,14 @@ static void send_prov_data(void) bt_mesh_prov_buf_init(&pdu, PROV_DATA); net_buf_simple_add_mem(&pdu, net_key, sizeof(net_key)); - net_buf_simple_add_be16(&pdu, prov_device.node->net_idx); + net_buf_simple_add_be16(&pdu, provisionee.node->net_idx); net_buf_simple_add_u8(&pdu, bt_mesh_cdb_subnet_flags(sub)); net_buf_simple_add_be32(&pdu, bt_mesh_cdb.iv_index); net_buf_simple_add_be16(&pdu, bt_mesh_prov_link.addr); net_buf_simple_add(&pdu, 8); /* For MIC */ LOG_DBG("net_idx %u, iv_index 0x%08x, addr 0x%04x", - prov_device.node->net_idx, bt_mesh.iv_index, + provisionee.node->net_idx, bt_mesh.iv_index, bt_mesh_prov_link.addr); err = bt_mesh_prov_encrypt(&session_key, nonce, &pdu.data[1], @@ -571,10 +571,10 @@ static void send_prov_data(void) static void prov_complete(const uint8_t *data) { - struct bt_mesh_cdb_node *node = prov_device.node; + struct bt_mesh_cdb_node *node = provisionee.node; LOG_DBG("key %s, net_idx %u, num_elem %u, addr 0x%04x", - bt_hex(&prov_device.new_dev_key, 16), node->net_idx, + bt_hex(&provisionee.new_dev_key, 16), node->net_idx, node->num_elem, node->addr); bt_mesh_prov_link.expect = PROV_NO_PDU; @@ -586,15 +586,15 @@ static void prov_complete(const uint8_t *data) static void prov_node_add(void) { LOG_DBG(""); - struct bt_mesh_cdb_node *node = prov_device.node; + struct bt_mesh_cdb_node *node = provisionee.node; int err; if (atomic_test_bit(bt_mesh_prov_link.flags, REPROVISION)) { bt_mesh_cdb_node_update(node, bt_mesh_prov_link.addr, - prov_device.elem_count); + provisionee.elem_count); } - err = bt_mesh_cdb_node_key_import(node, prov_device.new_dev_key); + err = bt_mesh_cdb_node_key_import(node, provisionee.new_dev_key); if (err) { LOG_ERR("Failed to import node device key"); return; @@ -604,7 +604,7 @@ static void prov_node_add(void) bt_mesh_cdb_node_store(node); } - prov_device.node = NULL; + provisionee.node = NULL; if (bt_mesh_prov->node_added) { bt_mesh_prov->node_added(node->net_idx, node->uuid, node->addr, @@ -807,7 +807,7 @@ static int link_open(const uint8_t *uuid, const struct prov_bearer *bearer, } if (uuid) { - memcpy(prov_device.uuid, uuid, 16); + memcpy(provisionee.uuid, uuid, 16); struct bt_uuid_128 uuid_repr = { .uuid = { BT_UUID_TYPE_128 } }; @@ -823,8 +823,8 @@ static int link_open(const uint8_t *uuid, const struct prov_bearer *bearer, bt_mesh_prov_link.addr = addr; bt_mesh_prov_link.bearer = bearer; bt_mesh_prov_link.role = &role_provisioner; - prov_device.net_idx = net_idx; - prov_device.attention_duration = attention_duration; + provisionee.net_idx = net_idx; + provisionee.attention_duration = attention_duration; err = bt_mesh_prov_link.bearer->link_open( uuid, timeout, bt_mesh_prov_bearer_cb_get(), bearer_cb_data); @@ -877,15 +877,15 @@ static int reprovision_local_client_server(uint16_t addr) } LOG_DBG("net_idx %u iv_index 0x%08x, addr 0x%04x", - prov_device.node->net_idx, bt_mesh_cdb.iv_index, addr); + provisionee.node->net_idx, bt_mesh_cdb.iv_index, addr); atomic_set_bit(bt_mesh_prov_link.flags, REPROVISION); atomic_set_bit(bt_mesh_prov_link.flags, PROVISIONER); bt_mesh_prov_link.addr = addr; bt_mesh_prov_link.bearer = &pb_remote_cli; bt_mesh_prov_link.role = &role_provisioner; - prov_device.net_idx = prov_device.node->net_idx; - prov_device.attention_duration = 0; + provisionee.net_idx = provisionee.node->net_idx; + provisionee.attention_duration = 0; if (IS_ENABLED(CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY) && bt_mesh_prov->public_key_be && bt_mesh_prov->private_key_be) { @@ -908,13 +908,13 @@ static int reprovision_local_client_server(uint16_t addr) LOG_DBG("DHkey: %s", bt_hex(bt_mesh_prov_link.dhkey, DH_KEY_SIZE)); err = bt_mesh_dev_key(bt_mesh_prov_link.dhkey, - bt_mesh_prov_link.prov_salt, prov_device.new_dev_key); + bt_mesh_prov_link.prov_salt, provisionee.new_dev_key); if (err) { LOG_ERR("Unable to generate device key"); return err; } - bt_mesh_dev_key_cand(prov_device.new_dev_key); + bt_mesh_dev_key_cand(provisionee.new_dev_key); /* Mark the link that was never opened as closed. */ atomic_set_bit(bt_mesh_prov_link.flags, COMPLETE); bt_mesh_reprovision(addr); @@ -943,8 +943,8 @@ int bt_mesh_pb_remote_open_node(struct bt_mesh_rpr_cli *cli, ctx.refresh = BT_MESH_RPR_NODE_REFRESH_DEVKEY; } - prov_device.node = bt_mesh_cdb_node_get(srv->addr); - if (!prov_device.node) { + provisionee.node = bt_mesh_cdb_node_get(srv->addr); + if (!provisionee.node) { LOG_ERR("No CDB node for 0x%04x", srv->addr); return -ENOENT; } @@ -954,7 +954,7 @@ int bt_mesh_pb_remote_open_node(struct bt_mesh_rpr_cli *cli, return reprovision_local_client_server(addr); } - return link_open(NULL, &pb_remote_cli, prov_device.node->net_idx, addr, + return link_open(NULL, &pb_remote_cli, provisionee.node->net_idx, addr, 0, &ctx, 0); } #endif diff --git a/subsys/bluetooth/mesh/shell/shell.c b/subsys/bluetooth/mesh/shell/shell.c index bb9892eb355..9a0e5ece5e3 100644 --- a/subsys/bluetooth/mesh/shell/shell.c +++ b/subsys/bluetooth/mesh/shell/shell.c @@ -771,7 +771,7 @@ static int cmd_provision_gatt(const struct shell *sh, size_t argc, } #endif /* CONFIG_BT_MESH_PB_GATT_CLIENT */ -#if defined(CONFIG_BT_MESH_PROV_DEVICE) +#if defined(CONFIG_BT_MESH_PROVISIONEE) static int cmd_pb(bt_mesh_prov_bearer_t bearer, const struct shell *sh, size_t argc, char *argv[]) { @@ -822,7 +822,7 @@ static int cmd_pb_gatt(const struct shell *sh, size_t argc, char *argv[]) return cmd_pb(BT_MESH_PROV_GATT, sh, argc, argv); } #endif /* CONFIG_BT_MESH_PB_GATT */ -#endif /* CONFIG_BT_MESH_PROV_DEVICE */ +#endif /* CONFIG_BT_MESH_PROVISIONEE */ #if defined(CONFIG_BT_MESH_PROVISIONER) static int cmd_remote_pub_key_set(const struct shell *sh, size_t argc, char *argv[]) @@ -1681,14 +1681,14 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD_ARG(comp-change, NULL, NULL, cmd_comp_change, 1, 0), /* Provisioning operations */ -#if defined(CONFIG_BT_MESH_PROV_DEVICE) +#if defined(CONFIG_BT_MESH_PROVISIONEE) #if defined(CONFIG_BT_MESH_PB_GATT) SHELL_CMD_ARG(pb-gatt, NULL, "", cmd_pb_gatt, 2, 0), #endif #if defined(CONFIG_BT_MESH_PB_ADV) SHELL_CMD_ARG(pb-adv, NULL, "", cmd_pb_adv, 2, 0), #endif -#endif /* CONFIG_BT_MESH_PROV_DEVICE */ +#endif /* CONFIG_BT_MESH_PROVISIONEE */ #if defined(CONFIG_BT_MESH_PROVISIONER) SHELL_CMD(auth-method, &auth_cmds, "Authentication methods", bt_mesh_shell_mdl_cmds_help), diff --git a/tests/bsim/bluetooth/mesh/prj.conf b/tests/bsim/bluetooth/mesh/prj.conf index a45bef89775..e9c719de6d7 100644 --- a/tests/bsim/bluetooth/mesh/prj.conf +++ b/tests/bsim/bluetooth/mesh/prj.conf @@ -37,7 +37,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3 CONFIG_BT_MESH_IV_UPDATE_TEST=y CONFIG_BT_MESH_PB_ADV=y CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_PROV_DEVICE=y +CONFIG_BT_MESH_PROVISIONEE=y CONFIG_BT_MESH_CDB=y CONFIG_BT_MESH_CDB_NODE_COUNT=4 CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y diff --git a/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf b/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf index 11059c03da4..fd0c953226b 100644 --- a/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf +++ b/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf @@ -39,7 +39,7 @@ CONFIG_BT_MESH_LABEL_COUNT=3 CONFIG_BT_MESH_IV_UPDATE_TEST=y CONFIG_BT_MESH_PB_ADV=y CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_PROV_DEVICE=y +CONFIG_BT_MESH_PROVISIONEE=y CONFIG_BT_MESH_CDB=y CONFIG_BT_MESH_CDB_NODE_COUNT=4 CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y From 9fe0ab63064c48af7e7a52080d7804c8811748fa Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1014/1623] [nrf fromtree] Bluetooth: Mesh: Added support for randomly delaying publications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The section 3.7.3.1 of the mesh specification recommends to delay a message publication in certain cases: - at power-up or upon state change for a time between 20 to 500 ms - for periodic publications for a time between 20 to 50 ms This change implements this recommendation by adding the `CONFIG_BT_MESH_DELAYABLE_PUBLICATION` Kconfig option which enables the randomization code and by adding the `bt_mesh_model_pub.delayable` bit field which allows each model decide whether the publications should be delayed for this model or not. Signed-off-by: Pavel Vasilyev (cherry picked from commit fe70e50d412cd470b301ccfda9ff07835f17219b) Signed-off-by: Håvard Reierstad --- .../bluetooth/api/mesh/access.rst | 15 ++ include/zephyr/bluetooth/mesh/access.h | 2 + subsys/bluetooth/mesh/Kconfig | 9 + subsys/bluetooth/mesh/access.c | 91 ++++++++- tests/bsim/bluetooth/mesh/src/test_access.c | 176 ++++++++++++++++-- .../access/access_period_delayable.sh | 17 ++ .../access/access_transmit_delayable.sh | 17 ++ 7 files changed, 311 insertions(+), 16 deletions(-) create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/access/access_period_delayable.sh create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh diff --git a/doc/connectivity/bluetooth/api/mesh/access.rst b/doc/connectivity/bluetooth/api/mesh/access.rst index 7030a3c14b2..cb02028b697 100644 --- a/doc/connectivity/bluetooth/api/mesh/access.rst +++ b/doc/connectivity/bluetooth/api/mesh/access.rst @@ -255,6 +255,21 @@ message, it will send messages with delay close to expiration to free memory. When the mesh stack is suspended or reset, messages not yet sent are removed and the :c:member:`bt_mesh_send_cb.start` callback is raised with an error code. +Delayable publications +====================== + +The delayable publication functionality implements the specification recommendations for message +publication delays in the following cases: + +* Between 20 to 500 milliseconds when the Bluetooth Mesh stack starts or when the publication is + triggered by the :c:func:`bt_mesh_model_publish` function +* Between 20 to 50 milliseconds for periodically published messages + +This feature is optional and enabled with the :kconfig:option:`CONFIG_BT_MESH_DELAYABLE_PUBLICATION` +Kconfig option. When enabled, each model can enable or disable the delayable publication by setting +the :c:member:`bt_mesh_model_pub.delayable` bit field to ``1`` or ``0`` correspondingly. This bit +field can be changed at any time. + API reference ************* diff --git a/include/zephyr/bluetooth/mesh/access.h b/include/zephyr/bluetooth/mesh/access.h index d57f30f8f05..a236ede525d 100644 --- a/include/zephyr/bluetooth/mesh/access.h +++ b/include/zephyr/bluetooth/mesh/access.h @@ -713,6 +713,8 @@ struct bt_mesh_model_pub { uint8_t period_div:4, /**< Divisor for the Period. */ count:4; /**< Transmissions left. */ + uint8_t delayable:1; /**< Use random delay for publishing. */ + uint32_t period_start; /**< Start of the current period. */ /** @brief Publication buffer, containing the publication message. diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index bffbac3e8e7..af6af8c44dc 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -672,6 +672,15 @@ config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT endif # BT_MESH_ACCESS_DELAYABLE_MSG +config BT_MESH_DELAYABLE_PUBLICATION + bool "Delayable publication" + default y + help + When enabled, the periodic publications are randomly delayed by 20 to 50ms. Publications + triggered at the start of the stack or by the bt_mesh_model_publish() call are delayed by + 20 to 500ms. This option reduces the probability of collisions when multiple nodes publish + at the same time. + endmenu # Access layer menu "Models" diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 4cffe064329..c3ef6a40554 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -33,6 +33,11 @@ #include LOG_MODULE_REGISTER(bt_mesh_access); +/* 20 - 50ms */ +#define RANDOM_DELAY_SHORT 30 +/* 20 - 500ms */ +#define RANDOM_DELAY_LONG 480 + /* Model publication information for persistent storage. */ struct mod_pub_val { struct { @@ -761,8 +766,16 @@ static int32_t next_period(const struct bt_mesh_model *mod) if (period && elapsed >= period) { LOG_WRN("Retransmission interval is too short"); - /* Return smallest positive number since 0 means disabled */ - return 1; + + if (!!pub->delayable) { + LOG_WRN("Publication period is too short for" + " retransmissions"); + } + + /* Keep retransmitting the message with the interval sacrificing the + * next publication period start. + */ + return BT_MESH_PUB_TRANSMIT_INT(mod->pub->retransmit); } } @@ -775,6 +788,11 @@ static int32_t next_period(const struct bt_mesh_model *mod) if (elapsed >= period) { LOG_WRN("Publication sending took longer than the period"); + + if (!!pub->delayable) { + LOG_WRN("Publication period is too short to be delayable"); + } + /* Return smallest positive number since 0 means disabled */ return 1; } @@ -855,6 +873,39 @@ static int pub_period_start(struct bt_mesh_model_pub *pub) return 0; } +static uint16_t pub_delay_get(int random_delay_window) +{ + if (!IS_ENABLED(CONFIG_BT_MESH_DELAYABLE_PUBLICATION)) { + return 0; + } + + uint16_t num = 0; + + (void)bt_rand(&num, sizeof(num)); + + return 20 + (num % random_delay_window); +} + +static int pub_delay_schedule(struct bt_mesh_model_pub *pub, int delay) +{ + uint16_t random; + int err; + + if (!IS_ENABLED(CONFIG_BT_MESH_DELAYABLE_PUBLICATION)) { + return -ENOTSUP; + } + + random = pub_delay_get(delay); + err = k_work_reschedule(&pub->timer, K_MSEC(random)); + if (err < 0) { + LOG_ERR("Unable to delay publication (err %d)", err); + return err; + } + + LOG_DBG("Publication delayed by %dms", random); + return 0; +} + static void mod_publish(struct k_work *work) { struct k_work_delayable *dwork = k_work_delayable_from_work(work); @@ -890,6 +941,13 @@ static void mod_publish(struct k_work *work) if (err) { return; } + + /* Delay the first publication in a period. */ + if (!!pub->delayable && !pub_delay_schedule(pub, RANDOM_DELAY_SHORT)) { + /* Increment count as it would do BT_MESH_PUB_MSG_TOTAL */ + pub->count++; + return; + } } err = publish_transmit(pub->mod); @@ -1564,6 +1622,18 @@ int bt_mesh_model_publish(const struct bt_mesh_model *model) LOG_DBG("Publish Retransmit Count %u Interval %ums", pub->count, BT_MESH_PUB_TRANSMIT_INT(pub->retransmit)); + /* Delay the publication for longer time when the publication is triggered manually (section + * 3.7.3.1): + * + * When the publication of a message is the result of a power-up, a state transition + * progress update, or completion of a state transition, multiple nodes may be reporting the + * state change at the same time. To reduce the probability of a message collision, these + * messages should be sent with a random delay between 20 and 500 milliseconds. + */ + if (!!pub->delayable && !pub_delay_schedule(pub, RANDOM_DELAY_LONG)) { + return 0; + } + k_work_reschedule(&pub->timer, K_NO_WAIT); return 0; @@ -2568,8 +2638,21 @@ static void commit_mod(const struct bt_mesh_model *mod, const struct bt_mesh_ele int32_t ms = bt_mesh_model_pub_period_get(mod); if (ms > 0) { - LOG_DBG("Starting publish timer (period %u ms)", ms); - k_work_schedule(&mod->pub->timer, K_MSEC(ms)); + /* Delay the first publication after power-up for longer time (section + * 3.7.3.1): + * + * When the publication of a message is the result of a power-up, a state + * transition progress update, or completion of a state transition, multiple + * nodes may be reporting the state change at the same time. To reduce the + * probability of a message collision, these messages should be sent with a + * random delay between 20 and 500 milliseconds. + */ + uint16_t random; + + random = !!mod->pub->delayable ? pub_delay_get(RANDOM_DELAY_LONG) : 0; + + LOG_DBG("Starting publish timer (period %u ms, delay %u ms)", ms, random); + k_work_schedule(&mod->pub->timer, K_MSEC(ms + random)); } } diff --git a/tests/bsim/bluetooth/mesh/src/test_access.c b/tests/bsim/bluetooth/mesh/src/test_access.c index b8b10fd7634..5cb7d2e28e1 100644 --- a/tests/bsim/bluetooth/mesh/src/test_access.c +++ b/tests/bsim/bluetooth/mesh/src/test_access.c @@ -60,6 +60,7 @@ static const struct { uint8_t div; int32_t period_ms; } test_period[] = { + { BT_MESH_PUB_PERIOD_100MS(1), 0, 100 }, { BT_MESH_PUB_PERIOD_100MS(5), 0, 500 }, { BT_MESH_PUB_PERIOD_SEC(2), 0, 2000 }, { BT_MESH_PUB_PERIOD_10SEC(1), 0, 10000 }, @@ -522,6 +523,91 @@ static void msgf_publish(void) bt_mesh_model_publish(model); } +static void pub_delayable_check(int32_t interval, uint8_t count) +{ + int64_t timestamp = k_uptime_get(); + int err; + + for (size_t j = 0; j < count; j++) { + /* Every new publication will release semaphore in the update handler and the time + * between two consecutive publications will be measured. + */ + err = k_sem_take(&publish_sem, K_SECONDS(20)); + if (err) { + FAIL("Send timed out"); + } + + int32_t time_delta = k_uptime_delta(×tamp); + int32_t pub_delta = time_delta - interval; + + LOG_DBG("Send time: %d delta: %d pub_delta: %d", (int32_t)timestamp, time_delta, + pub_delta); + + if (j == 0) { + /* The first delta will be between the messages published manually and next + * publication (or retransmission). So the time difference should not be + * longer than 500 - 20 + 10 (margin): + * + * |---|-------|--------|-------|----> + * M1 20ms tx(M1) 500ms + * update() + */ + ASSERT_IN_RANGE(pub_delta, 0, 510); + } else { + /* Time difference between the consequtive update callback calls should be + * within a small margin like without random delay as the callbacks should + * be called at the regular interval or immediately (if it passed the next + * period time). + */ + ASSERT_IN_RANGE(pub_delta, 0, 10); + } + } +} + +static void recv_delayable_check(int32_t interval, uint8_t count) +{ + int64_t timestamp; + int err; + + /* The measurement starts by the first received message. */ + err = k_sem_take(&publish_sem, K_SECONDS(20)); + if (err) { + FAIL("Recv timed out"); + } + + timestamp = k_uptime_get(); + + for (size_t j = 0; j < count; j++) { + /* Every new received message will release semaphore in the message handler and + * the time between two consecutive publications will be measured. + */ + err = k_sem_take(&publish_sem, K_SECONDS(20)); + if (err) { + FAIL("Recv timed out"); + } + + int32_t time_delta = k_uptime_delta(×tamp); + /* First message can be delayed up to 500ms, others for up to 50ms. */ + int32_t upper_delay = j == 0 ? 500 : 50; + + /* + * Lower boundary: tx2 - tx1 + interval + * |---|-------|---------------|-------|-----> + * M1 tx1(50ms/500ms) M2 tx2(20ms) + * + * Upper boundary: tx2 - tx1 + interval + * |---|-------|--------|-----------|-----> + * M1 tx1(20ms) M2 tx2(50ms/500ms) + */ + int32_t lower_boundary = 20 - upper_delay + interval; + int32_t upper_boundary = upper_delay - 20 + interval; + + LOG_DBG("Recv time: %d delta: %d boundaries: %d/%d", (int32_t)timestamp, time_delta, + lower_boundary, upper_boundary); + ASSERT_IN_RANGE(time_delta, lower_boundary, upper_boundary + RX_JITTER_MAX); + } +} + static void pub_jitter_check(int32_t interval, uint8_t count) { int64_t timestamp = k_uptime_get(); @@ -578,8 +664,8 @@ static void recv_jitter_check(int32_t interval, uint8_t count) jitter = MAX(pub_delta, jitter); - LOG_DBG("Recv time: %d delta: %d jitter: %d", (int32_t)timestamp, time_delta, - jitter); + LOG_DBG("Recv time: %d delta: %d jitter: %d, j: %d", (int32_t)timestamp, time_delta, + jitter, j); } LOG_INF("Recv jitter: %d", jitter); @@ -589,17 +675,19 @@ static void recv_jitter_check(int32_t interval, uint8_t count) /* Test publish period states by publishing a message and checking interval between update handler * calls. */ -static void test_tx_period(void) +static void tx_period(bool delayable) { const struct bt_mesh_model *model = &models[2]; - bt_mesh_test_cfg_set(NULL, 60); + bt_mesh_test_cfg_set(NULL, 70); bt_mesh_device_setup(&prov, &local_comp); provision(UNICAST_ADDR1); common_configure(UNICAST_ADDR1); k_sem_init(&publish_sem, 0, 1); + model->pub->delayable = delayable; + for (size_t i = 0; i < ARRAY_SIZE(test_period); i++) { pub_param_set(test_period[i].period, 0); @@ -611,7 +699,11 @@ static void test_tx_period(void) /* Start publishing messages and measure jitter. */ msgf_publish(); publish_allow = true; - pub_jitter_check(test_period[i].period_ms, PUB_PERIOD_COUNT); + if (delayable) { + pub_delayable_check(test_period[i].period_ms, PUB_PERIOD_COUNT); + } else { + pub_jitter_check(test_period[i].period_ms, PUB_PERIOD_COUNT); + } /* Disable periodic publication before the next test iteration. */ publish_allow = false; @@ -626,9 +718,9 @@ static void test_tx_period(void) /* Receive a periodically published message and check publication period by measuring interval * between message handler calls. */ -static void test_rx_period(void) +static void rx_period(bool delayable) { - bt_mesh_test_cfg_set(NULL, 60); + bt_mesh_test_cfg_set(NULL, 70); bt_mesh_device_setup(&prov, &local_comp); provision(UNICAST_ADDR2); common_configure(UNICAST_ADDR2); @@ -636,16 +728,40 @@ static void test_rx_period(void) k_sem_init(&publish_sem, 0, 1); for (size_t i = 0; i < ARRAY_SIZE(test_period); i++) { - recv_jitter_check(test_period[i].period_ms, PUB_PERIOD_COUNT); + if (delayable) { + recv_delayable_check(test_period[i].period_ms, PUB_PERIOD_COUNT); + } else { + recv_jitter_check(test_period[i].period_ms, PUB_PERIOD_COUNT); + } } PASS(); } +static void test_tx_period(void) +{ + tx_period(false); +} + +static void test_rx_period(void) +{ + rx_period(false); +} + +static void test_tx_period_delayable(void) +{ + tx_period(true); +} + +static void test_rx_period_delayable(void) +{ + rx_period(true); +} + /* Test publish retransmit interval and count states by publishing a message and checking interval * between update handler calls. */ -static void test_tx_transmit(void) +static void tx_transmit(bool delayable) { const struct bt_mesh_model *model = &models[2]; uint8_t status; @@ -672,6 +788,7 @@ static void test_tx_transmit(void) publish_allow = true; model->pub->retr_update = true; + model->pub->delayable = delayable; for (size_t i = 0; i < ARRAY_SIZE(test_transmit); i++) { pub_param_set(0, test_transmit[i]); @@ -683,7 +800,11 @@ static void test_tx_transmit(void) /* Start publishing messages and measure jitter. */ msgf_publish(); - pub_jitter_check(interval, count); + if (delayable) { + pub_delayable_check(interval, count); + } else { + pub_jitter_check(interval, count); + } /* Let the receiver hit the first semaphore. */ k_sleep(K_SECONDS(1)); @@ -695,7 +816,7 @@ static void test_tx_transmit(void) /* Receive a published message and check retransmission interval by measuring interval between * message handler calls. */ -static void test_rx_transmit(void) +static void rx_transmit(bool delayable) { bt_mesh_test_cfg_set(NULL, 60); bt_mesh_device_setup(&prov, &local_comp); @@ -708,12 +829,36 @@ static void test_rx_transmit(void) int32_t interval = BT_MESH_PUB_TRANSMIT_INT(test_transmit[i]); int count = BT_MESH_PUB_TRANSMIT_COUNT(test_transmit[i]); - recv_jitter_check(interval, count); + if (delayable) { + recv_delayable_check(interval, count); + } else { + recv_jitter_check(interval, count); + } } PASS(); } +static void test_tx_transmit(void) +{ + tx_transmit(false); +} + +static void test_rx_transmit(void) +{ + rx_transmit(false); +} + +static void test_tx_transmit_delayable(void) +{ + tx_transmit(true); +} + +static void test_rx_transmit_delayable(void) +{ + rx_transmit(true); +} + /* Cancel one of messages to be published and check that the next one is published when next period * starts. */ @@ -841,6 +986,13 @@ static const struct bst_test_instance test_access[] = { TEST_CASE(tx, cancel, "Access: Cancel a message during publication"), TEST_CASE(rx, cancel, "Access: Receive published messages except cancelled"), + TEST_CASE(tx, period_delayable, "Access: Test delayable periodic publication"), + TEST_CASE(rx, period_delayable, "Access: Receive delayable periodic publication"), + + TEST_CASE(tx, transmit_delayable, "Access: Test delayable publication with retransmission"), + TEST_CASE(rx, transmit_delayable, "Access: Receive delayable publication with" + " retransmissions"), + BSTEST_END_MARKER }; diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period_delayable.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period_delayable.sh new file mode 100755 index 00000000000..5ecd4a061de --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period_delayable.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +RunTest mesh_access_pub_period_delayable_retr \ + access_tx_period_delayable access_rx_period_delayable + +conf=prj_mesh1d1_conf +RunTest mesh_access_pub_period_delayable_retr_1d1 \ + access_tx_period_delayable access_rx_period_delayable + +conf=prj_mesh1d1_conf +overlay=overlay_psa_conf +RunTest mesh_access_pub_period_delayable_retr_psa \ + access_tx_period_delayable access_rx_period_delayable diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh new file mode 100755 index 00000000000..1622ac49f06 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +RunTest mesh_access_pub_transmit_delayable_retr \ + access_tx_transmit_delayable access_rx_transmit_delayable + +conf=prj_mesh1d1_conf +RunTest mesh_access_pub_transmit_delayable_retr_1d1 \ + access_tx_transmit_delayable access_rx_transmit_delayable + +conf=prj_mesh1d1_conf +overlay=overlay_psa_conf +RunTest mesh_access_pub_transmit_delayable_retr_psa \ + access_tx_period_delayable access_rx_period_delayable From 0408887166fe5c6d5636569437881bd21147250c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Thu, 11 Jan 2024 14:02:44 +0100 Subject: [PATCH 1015/1623] [nrf fromtree] Bluetooth: Mesh: Refactor proxy adv MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactors proxy advertising implementation to allow fair sharing of advertising resources between all subnets. In the new implementation, each subnet is agnostic to any other subnet that might have active proxy advertisement work. When proxy advertisement is triggered, the implementation will first check how many subnets that has active work. If there are more than one active subnet, a maximum timeslot will be calculated to ensure that all active subnets get access to the medium. The implementation will then poll the next eligible subnet for a proxy advertising request. If the duration of this request exceeds the maximum timeslot, the duration for the next advertisement will be set to the maximum value. If a proxy advertisement for a subnet is interrupted by other advertising activity, the implementation will now ensure that the interrupted proxy adv continues from the point where it was interrupted so that the subnet gets to utilize the entire allocated timeslot. This PR also alters the priv_proxy_net_id_multi Bsim test to align with the refactored proxy advertising scheme. Signed-off-by: Anders Storrø (cherry picked from commit 6c67ab3a637ea44bf815faffbe6fe083d5508aa3) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/proxy_srv.c | 332 +++++++++++--------- tests/bsim/bluetooth/mesh/src/test_beacon.c | 10 +- 2 files changed, 190 insertions(+), 152 deletions(-) diff --git a/subsys/bluetooth/mesh/proxy_srv.c b/subsys/bluetooth/mesh/proxy_srv.c index 45e29915325..9cad9e2fe04 100644 --- a/subsys/bluetooth/mesh/proxy_srv.c +++ b/subsys/bluetooth/mesh/proxy_srv.c @@ -625,7 +625,7 @@ static int net_id_adv(struct bt_mesh_subnet *sub, int32_t duration) return 0; } -static bool advertise_subnet(struct bt_mesh_subnet *sub) +static bool is_sub_proxy_active(struct bt_mesh_subnet *sub) { if (sub->net_idx == BT_MESH_KEY_UNUSED) { return false; @@ -633,44 +633,18 @@ static bool advertise_subnet(struct bt_mesh_subnet *sub) return (sub->node_id == BT_MESH_NODE_IDENTITY_RUNNING || #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) - sub->solicited || + (bt_mesh_od_priv_proxy_get() > 0 && sub->solicited) || #endif bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED || bt_mesh_priv_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED); } -static struct bt_mesh_subnet *next_sub(void) +static bool active_proxy_sub_cnt_cb(struct bt_mesh_subnet *sub, void *cb_data) { - struct bt_mesh_subnet *sub = NULL; + int *cnt = cb_data; - if (!beacon_sub) { - beacon_sub = bt_mesh_subnet_next(NULL); - if (!beacon_sub) { - /* No valid subnets */ - return NULL; - } - } - - sub = beacon_sub; - do { - if (advertise_subnet(sub)) { - beacon_sub = sub; - return sub; - } - - sub = bt_mesh_subnet_next(sub); - } while (sub != beacon_sub); - - /* No subnets to advertise on */ - return NULL; -} - -static bool sub_count_cb(struct bt_mesh_subnet *sub, void *cb_data) -{ - int *count = cb_data; - - if (advertise_subnet(sub)) { - (*count)++; + if (is_sub_proxy_active(sub)) { + (*cnt)++; } /* Don't stop until we've visited all subnets. @@ -679,155 +653,225 @@ static bool sub_count_cb(struct bt_mesh_subnet *sub, void *cb_data) return false; } -static int sub_count(void) +static int active_proxy_sub_cnt_get(void) { - int count = 0; + int cnt = 0; - (void)bt_mesh_subnet_find(sub_count_cb, &count); + (void)bt_mesh_subnet_find(active_proxy_sub_cnt_cb, &cnt); - return count; + return cnt; } -#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) -static void gatt_proxy_solicited(struct bt_mesh_subnet *sub) +static void proxy_adv_timeout_eval(struct bt_mesh_subnet *sub) { - int64_t now = k_uptime_get(); - int64_t timeout = 0; - int32_t remaining; - - if (sub->priv_net_id_sent > 0) { - timeout = sub->priv_net_id_sent + - MSEC_PER_SEC * (int64_t) bt_mesh_od_priv_proxy_get(); - remaining = MIN(timeout - now, INT32_MAX); - } else { - remaining = MSEC_PER_SEC * bt_mesh_od_priv_proxy_get(); + int32_t time_passed; + + if (sub->node_id == BT_MESH_NODE_IDENTITY_RUNNING) { + time_passed = k_uptime_get_32() - sub->node_id_start; + if (time_passed > (NODE_ID_TIMEOUT - MSEC_PER_SEC)) { + bt_mesh_proxy_identity_stop(sub); + LOG_DBG("Node ID stopped for subnet %d after %dms", sub->net_idx, + time_passed); + } } - if ((timeout > 0 && now > timeout) || (remaining / MSEC_PER_SEC < 1)) { - LOG_DBG("Advertising Private Network ID timed out " - "after solicitation"); - sub->priv_net_id_sent = 0; - sub->solicited = false; - } else { - LOG_DBG("Advertising Private Network ID for %ds" - "(%d remaining)", - bt_mesh_od_priv_proxy_get(), - remaining / MSEC_PER_SEC); - priv_net_id_adv(sub, remaining); - - if (!sub->priv_net_id_sent) { - sub->priv_net_id_sent = now; +#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) + if (bt_mesh_od_priv_proxy_get() > 0 && sub->solicited && sub->priv_net_id_sent) { + time_passed = k_uptime_get_32() - sub->priv_net_id_sent; + if (time_passed > ((MSEC_PER_SEC * bt_mesh_od_priv_proxy_get()) - MSEC_PER_SEC)) { + sub->priv_net_id_sent = 0; + sub->solicited = false; + LOG_DBG("Private Network ID stopped for subnet %d after %dms on " + "solicitation", + sub->net_idx, time_passed); } } +#endif } + +enum proxy_adv_evt { + NET_ID, + PRIV_NET_ID, + NODE_ID, + PRIV_NODE_ID, + OD_PRIV_NET_ID, +}; + +struct proxy_adv_request { + int32_t duration; + enum proxy_adv_evt evt; +}; + +static bool proxy_adv_request_get(struct bt_mesh_subnet *sub, struct proxy_adv_request *request) +{ + if (!sub) { + return false; + } + + if (sub->net_idx == BT_MESH_KEY_UNUSED) { + return false; + } + +#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) + if (bt_mesh_od_priv_proxy_get() > 0 && sub->solicited) { + int32_t timeout = MSEC_PER_SEC * (int32_t)bt_mesh_od_priv_proxy_get(); + + request->evt = OD_PRIV_NET_ID; + request->duration = !sub->priv_net_id_sent + ? timeout + : timeout - (k_uptime_get_32() - sub->priv_net_id_sent); + return true; + } #endif -static int gatt_proxy_advertise(struct bt_mesh_subnet *sub) + if (sub->node_id == BT_MESH_NODE_IDENTITY_RUNNING) { + request->duration = NODE_ID_TIMEOUT - (k_uptime_get_32() - sub->node_id_start); + request->evt = +#if defined(CONFIG_BT_MESH_PRIV_BEACONS) + sub->priv_beacon_ctx.node_id ? PRIV_NODE_ID : +#endif + NODE_ID; + + return true; + } + + if (bt_mesh_priv_gatt_proxy_get() == BT_MESH_FEATURE_ENABLED) { + request->evt = PRIV_NET_ID; + request->duration = PROXY_RANDOM_UPDATE_INTERVAL; + return true; + } + + if (bt_mesh_gatt_proxy_get() == BT_MESH_FEATURE_ENABLED) { + request->evt = NET_ID; + request->duration = SYS_FOREVER_MS; + return true; + } + + return false; +} + +static struct bt_mesh_subnet *adv_sub_get_next(struct bt_mesh_subnet *sub_start, + struct proxy_adv_request *request) { - int32_t remaining = SYS_FOREVER_MS; - int subnet_count; - int err = -EBUSY; - bool planned = false; + struct bt_mesh_subnet *sub_temp = sub_start; + + do { + if (proxy_adv_request_get(sub_temp, request)) { + return sub_temp; + } + + sub_temp = bt_mesh_subnet_next(sub_temp); + } while (sub_temp != sub_start); + + return NULL; +} + +static struct { + int32_t start; + struct bt_mesh_subnet *sub; + struct proxy_adv_request request; +} sub_adv; + +static int gatt_proxy_advertise(void) +{ + int err; + + int32_t max_adv_duration; + int cnt; + struct bt_mesh_subnet *sub; + struct proxy_adv_request request; LOG_DBG(""); + /* Close proxy activity that has timed out on all subnets */ + bt_mesh_subnet_foreach(proxy_adv_timeout_eval); + if (!bt_mesh_proxy_has_avail_conn()) { LOG_DBG("Connectable advertising deferred (max connections)"); return -ENOMEM; } - sub = beacon_sub ? beacon_sub : bt_mesh_subnet_next(beacon_sub); - if (!sub) { - LOG_WRN("No subnets to advertise on"); + cnt = active_proxy_sub_cnt_get(); + if (!cnt) { + LOG_DBG("No subnets to advertise proxy on"); return -ENOENT; - } - - subnet_count = sub_count(); - LOG_DBG("sub_count %u", subnet_count); - if (subnet_count > 1) { - int32_t max_timeout; + } else if (cnt > 1) { + /** There is more than one subnet that requires proxy adv, + * and the adv resources must be shared. + */ /* We use NODE_ID_TIMEOUT as a starting point since it may * be less than 60 seconds. Divide this period into at least - * 6 slices, but make sure that a slice is at least one + * 6 slices, but make sure that a slice is more than one * second long (to avoid excessive rotation). */ - max_timeout = NODE_ID_TIMEOUT / MAX(subnet_count, 6); - max_timeout = MAX(max_timeout, 1 * MSEC_PER_SEC); - - if (remaining > max_timeout || remaining == SYS_FOREVER_MS) { - remaining = max_timeout; + max_adv_duration = NODE_ID_TIMEOUT / MAX(cnt, 6); + max_adv_duration = MAX(max_adv_duration, MSEC_PER_SEC + 20); + + /* Check if the previous subnet finished its allocated timeslot */ + if ((sub_adv.request.duration != SYS_FOREVER_MS) && + proxy_adv_request_get(sub_adv.sub, &request) && + (sub_adv.request.evt == request.evt)) { + int32_t time_passed = k_uptime_get_32() - sub_adv.start; + + if (time_passed < sub_adv.request.duration && + ((sub_adv.request.duration - time_passed) >= MSEC_PER_SEC)) { + sub = sub_adv.sub; + request.duration = sub_adv.request.duration - time_passed; + goto end; + } } } - for (int i = 0; i < subnet_count; i++) { - - if (sub->node_id == BT_MESH_NODE_IDENTITY_RUNNING) { - uint32_t active = k_uptime_get_32() - sub->node_id_start; - bool priv_node_id = false; - - if (active < NODE_ID_TIMEOUT) { - remaining = MIN(remaining, NODE_ID_TIMEOUT - active); - LOG_DBG("Node ID active for %u ms, %d ms remaining", - active, remaining); -#if defined(CONFIG_BT_MESH_PRIV_BEACONS) - priv_node_id = sub->priv_beacon_ctx.node_id; -#endif - if (priv_node_id) { - err = priv_node_id_adv(sub, remaining); - } else { - err = node_id_adv(sub, remaining); - } - planned = true; - } else { - bt_mesh_proxy_identity_stop(sub); - LOG_DBG("Node ID stopped"); - } - } + sub = adv_sub_get_next(bt_mesh_subnet_next(sub_adv.sub), &request); + if (!sub) { + LOG_ERR("Could not find subnet to advertise"); + return -ENOENT; + } +end: + if (cnt > 1) { + request.duration = (request.duration == SYS_FOREVER_MS) + ? max_adv_duration + : MIN(request.duration, max_adv_duration); + } - /* MshPRTv1.1: section 7.2.2.2.1: - * "A node that does not support the Proxy feature or - * has the GATT Proxy state disabled shall not advertise with Network ID." - */ - if (sub->node_id == BT_MESH_NODE_IDENTITY_STOPPED) { - if (IS_ENABLED(CONFIG_BT_MESH_PRIV_BEACONS) && - (bt_mesh_priv_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED)) { - /* MshPRTv1.1: 7.2.2.2.4: The Random - * field should be updated every 10 minutes. Limit advertising to - * 10 minutes to ensure regeneration of a new random value at least - * that often. - */ - if (remaining == SYS_FOREVER_MS || - remaining > PROXY_RANDOM_UPDATE_INTERVAL) { - remaining = PROXY_RANDOM_UPDATE_INTERVAL; - } - - err = priv_net_id_adv(sub, remaining); - planned = true; - } else if (bt_mesh_gatt_proxy_get() == BT_MESH_FEATURE_ENABLED) { - err = net_id_adv(sub, remaining); - planned = true; - } + /* Save current state for next iteration */ + sub_adv.start = k_uptime_get_32(); + sub_adv.sub = sub; + sub_adv.request = request; + switch (request.evt) { + case NET_ID: + err = net_id_adv(sub, request.duration); + break; #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) - else if (bt_mesh_od_priv_proxy_get() > 0 && - sub->solicited) { - gatt_proxy_solicited(sub); - } -#endif - } - - beacon_sub = bt_mesh_subnet_next(sub); - - if (planned) { - LOG_DBG("Advertising %d ms for net_idx 0x%04x", remaining, sub->net_idx); - return err; + case OD_PRIV_NET_ID: + if (!sub->priv_net_id_sent) { + sub->priv_net_id_sent = k_uptime_get(); } + /* Fall through */ +#endif + case PRIV_NET_ID: + err = priv_net_id_adv(sub, request.duration); + break; + case NODE_ID: + err = node_id_adv(sub, request.duration); + break; + case PRIV_NODE_ID: + err = priv_node_id_adv(sub, request.duration); + break; + default: + LOG_ERR("Unexpected proxy adv evt: %d", request.evt); + return -ENODEV; + } - sub = beacon_sub; + if (err) { + LOG_ERR("Advertising proxy failed (err: %d)", err); + return err; } - return 0; + LOG_DBG("Advertising %d ms for net_idx 0x%04x", request.duration, sub->net_idx); + return err; } static void subnet_evt(struct bt_mesh_subnet *sub, enum bt_mesh_key_evt evt) @@ -1152,7 +1196,7 @@ int bt_mesh_proxy_adv_start(void) return -ENOTSUP; } - return gatt_proxy_advertise(next_sub()); + return gatt_proxy_advertise(); } BT_CONN_CB_DEFINE(conn_callbacks) = { diff --git a/tests/bsim/bluetooth/mesh/src/test_beacon.c b/tests/bsim/bluetooth/mesh/src/test_beacon.c index 038c705f2cb..f9230a397a9 100644 --- a/tests/bsim/bluetooth/mesh/src/test_beacon.c +++ b/tests/bsim/bluetooth/mesh/src/test_beacon.c @@ -1763,12 +1763,6 @@ static void test_tx_priv_multi_net_id(void) { tx_priv_common_init(PP_MULT_NET_ID_WAIT_TIME); - /* TODO: This should be removed as soon as - * SNB/proxy service advertising issue has - * been resolved. - */ - bt_mesh_beacon_set(false); - /* Add second network */ ASSERT_OK_MSG(bt_mesh_subnet_add(TEST_NET_IDX2, test_net_key_secondary), "Failed to add second subnet"); @@ -1819,8 +1813,8 @@ static void test_rx_priv_multi_net_id(void) /* Verify last Net ID adv result */ ASSERT_IN_RANGE(k_uptime_get() - net_ctx[old_idx].start, - MAX_TIMEOUT - 1000, MAX_TIMEOUT); - ASSERT_IN_RANGE(net_ctx[old_idx].recv_cnt, 9, 10); + MAX_TIMEOUT - 1000, MAX_TIMEOUT + 1000); + ASSERT_IN_RANGE(net_ctx[old_idx].recv_cnt, 9, 12); net_ctx[old_idx].recv_cnt = 0; old_idx = i; From f6350f1e94fa82e3f9b982014f32f046f2eb5379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Thu, 11 Jan 2024 14:02:45 +0100 Subject: [PATCH 1016/1623] [nrf fromtree] tests: Bluetooth: Mesh: Add proxy adv coex test. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds test that verifies correct Proxy advertisement behavior for a device where the Proxy adv requirements changes over time, both for single and multiple subnets. Signed-off-by: Anders Storrø (cherry picked from commit f70929a8f12214de7dc7e1fe52a8d696bfc7f55f) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/proxy_srv.c | 11 +- tests/bsim/bluetooth/mesh/overlay_gatt.conf | 1 + tests/bsim/bluetooth/mesh/src/test_beacon.c | 366 ++++++++++++++++-- .../proxy_adv_multi_subnet_coex.sh | 54 +++ 4 files changed, 397 insertions(+), 35 deletions(-) create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh diff --git a/subsys/bluetooth/mesh/proxy_srv.c b/subsys/bluetooth/mesh/proxy_srv.c index 9cad9e2fe04..25a44abfded 100644 --- a/subsys/bluetooth/mesh/proxy_srv.c +++ b/subsys/bluetooth/mesh/proxy_srv.c @@ -712,6 +712,13 @@ static bool proxy_adv_request_get(struct bt_mesh_subnet *sub, struct proxy_adv_r return false; } + /** The priority for proxy adv is first solicitation, then Node Identity, + * and lastly Network ID. Network ID is prioritized last since, in many + * cases, another device can fulfill the same demand. Solicitation is + * prioritized first since legacy devices are dependent on this to + * connect to the network. + */ + #if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) if (bt_mesh_od_priv_proxy_get() > 0 && sub->solicited) { int32_t timeout = MSEC_PER_SEC * (int32_t)bt_mesh_od_priv_proxy_get(); @@ -753,7 +760,7 @@ static bool proxy_adv_request_get(struct bt_mesh_subnet *sub, struct proxy_adv_r static struct bt_mesh_subnet *adv_sub_get_next(struct bt_mesh_subnet *sub_start, struct proxy_adv_request *request) { - struct bt_mesh_subnet *sub_temp = sub_start; + struct bt_mesh_subnet *sub_temp = bt_mesh_subnet_next(sub_start); do { if (proxy_adv_request_get(sub_temp, request)) { @@ -823,7 +830,7 @@ static int gatt_proxy_advertise(void) } } - sub = adv_sub_get_next(bt_mesh_subnet_next(sub_adv.sub), &request); + sub = adv_sub_get_next(sub_adv.sub, &request); if (!sub) { LOG_ERR("Could not find subnet to advertise"); return -ENOENT; diff --git a/tests/bsim/bluetooth/mesh/overlay_gatt.conf b/tests/bsim/bluetooth/mesh/overlay_gatt.conf index f94a26d623f..7660313b700 100644 --- a/tests/bsim/bluetooth/mesh/overlay_gatt.conf +++ b/tests/bsim/bluetooth/mesh/overlay_gatt.conf @@ -6,3 +6,4 @@ CONFIG_BT_MESH_LOW_POWER=n CONFIG_BT_MESH_FRIEND=n CONFIG_BT_CENTRAL=y CONFIG_BT_MESH_PROXY_CLIENT=y +CONFIG_BT_MESH_PROXY_SOLICITATION=y diff --git a/tests/bsim/bluetooth/mesh/src/test_beacon.c b/tests/bsim/bluetooth/mesh/src/test_beacon.c index f9230a397a9..e5f7d515da7 100644 --- a/tests/bsim/bluetooth/mesh/src/test_beacon.c +++ b/tests/bsim/bluetooth/mesh/src/test_beacon.c @@ -31,7 +31,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); #define BEACON_TYPE_PRIVATE 0x02 #endif -static uint8_t test_net_key_secondary[16] = { 0xca, 0x11, 0xab, 0x1e }; +static uint8_t test_net_key_2[16] = { 0xca, 0x11, 0xab, 0x1e }; static struct { uint8_t primary[16]; uint8_t secondary[16]; @@ -334,6 +334,7 @@ static struct { uint8_t random[13]; uint64_t pp_hash; uint64_t pp_random; + uint64_t net_id; bt_addr_le_t adv_addr; #endif bool (*process_cb)(const uint8_t *net_id, void *ctx); @@ -625,7 +626,7 @@ static void test_tx_kr_old_key(void) * the new Net Key. The node shall set Key Refresh phase to 2. The beacon interval shall * be increased. */ - beacon_create(&buf, test_net_key_secondary, 0x03, 0x0001); + beacon_create(&buf, test_net_key_2, 0x03, 0x0001); send_beacon(&buf); ASSERT_FALSE(wait_for_beacon(beacon_scan_cb, BEACON_INTERVAL + 1, NULL, NULL)); ASSERT_TRUE(wait_for_beacon(beacon_scan_cb, BEACON_INTERVAL + 1, NULL, NULL)); @@ -645,7 +646,7 @@ static void test_tx_kr_old_key(void) /* Try the same with the new Net Key. Now the node shall change Key Refresh phase to 0. The * beacon interval shall be increased. */ - beacon_create(&buf, test_net_key_secondary, 0x02, 0x0001); + beacon_create(&buf, test_net_key_2, 0x02, 0x0001); send_beacon(&buf); ASSERT_FALSE(wait_for_beacon(beacon_scan_cb, BEACON_INTERVAL + 1, NULL, NULL)); ASSERT_TRUE(wait_for_beacon(beacon_scan_cb, BEACON_INTERVAL + 1, NULL, NULL)); @@ -665,7 +666,7 @@ static void test_tx_kr_old_key(void) /* Do the same, but secure beacon with the new Net Key. Now the node shall change IV Update * flag to 0. The beacon interval shall be increased. */ - beacon_create(&buf, test_net_key_secondary, 0x00, 0x0001); + beacon_create(&buf, test_net_key_2, 0x00, 0x0001); send_beacon(&buf); ASSERT_FALSE(wait_for_beacon(beacon_scan_cb, BEACON_INTERVAL + 1, NULL, NULL)); ASSERT_TRUE(wait_for_beacon(beacon_scan_cb, BEACON_INTERVAL + 1, NULL, NULL)); @@ -686,7 +687,7 @@ static void test_rx_kr_old_key(void) bt_mesh_test_setup(); bt_mesh_iv_update_test(true); - err = bt_mesh_cfg_cli_net_key_update(0, cfg->addr, 0, test_net_key_secondary, &status); + err = bt_mesh_cfg_cli_net_key_update(0, cfg->addr, 0, test_net_key_2, &status); if (err || status) { FAIL("Net Key update failed (err %d, status %u)", err, status); } @@ -1541,60 +1542,73 @@ static void test_tx_priv_beacon_cache(void) #if IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) +static uint8_t test_net_key_3[16] = {0x12, 0x54, 0xab, 0x1e}; + +#define UNTIL_UPTIME(time) (k_uptime_get() > (time) ? K_NO_WAIT : K_MSEC((time) - k_uptime_get())) +#define BEACON_TYPE_NET_ID 0 +#define BEACON_TYPE_NODE_ID 1 #define BEACON_TYPE_PRIVATE_NET_ID 2 #define BEACON_TYPE_PRIVATE_NODE_ID 3 #define BEACON_TYPE_PRIVATE_LEN 28 #define TEST_NET_IDX1 0 #define TEST_NET_IDX2 1 +#define TEST_NET_IDX3 2 #define MAX_TIMEOUT ((CONFIG_BT_MESH_NODE_ID_TIMEOUT * 1000) / 6) #define PP_NET_ID_WAIT_TIME 610 /*seconds*/ #define PP_NODE_ID_WAIT_TIME 80 /*seconds*/ #define PP_MULT_NET_ID_WAIT_TIME 50 /*seconds*/ +#define PROXY_ADV_MULTI_SUBNET_COEX_WAIT_TIME 151 /*seconds*/ -struct pp_netkey_ctx { +struct netkey_ctx { uint8_t *net_key; uint8_t net_id[8]; + uint8_t net_idx; struct bt_mesh_key id_key; }; -static struct pp_netkey_ctx pp_net0 = {.net_key = (uint8_t *)test_net_key}; -static struct pp_netkey_ctx pp_net1 = {.net_key = (uint8_t *)test_net_key_secondary}; +static struct netkey_ctx pp_net0 = {.net_key = (uint8_t *)test_net_key, .net_idx = 0}; +static struct netkey_ctx pp_net1 = {.net_key = (uint8_t *)test_net_key_2, .net_idx = 1}; +static struct netkey_ctx pp_net2 = {.net_key = (uint8_t *)test_net_key_3, .net_idx = 2}; struct priv_test_ctx { uint8_t beacon_type; uint16_t *node_id_addr; }; -static void pp_netkey_ctx_init(struct pp_netkey_ctx *net) +static void pp_netkey_ctx_init(struct netkey_ctx *net) { ASSERT_OK_MSG(bt_mesh_identity_key(net->net_key, &net->id_key), "Failed to generate ID key"); ASSERT_OK_MSG(bt_mesh_k3(net->net_key, net->net_id), "Failed to generate Net ID"); } -static bool pp_type_check(uint16_t expected_beacon, uint8_t adv_type, struct net_buf_simple *buf) +static uint8_t proxy_adv_type_get(uint8_t adv_type, struct net_buf_simple *buf) { - if (adv_type != BT_GAP_ADV_TYPE_ADV_IND || buf->len != BEACON_TYPE_PRIVATE_LEN) { - return false; + uint8_t type; + uint8_t len = buf->len; + + if (adv_type != BT_GAP_ADV_TYPE_ADV_IND || len < 12) { + return 0xFF; } - /* Remove Header */ (void)net_buf_simple_pull_mem(buf, 11); - - uint8_t beacon_type = net_buf_simple_pull_u8(buf); - - if (beacon_type != expected_beacon) { - return false; + type = net_buf_simple_pull_u8(buf); + /* BEACON_TYPE_NET_ID is 20 bytes long, while the three other accepted types are 28 bytes*/ + if (len != ((type == BEACON_TYPE_NET_ID) ? 20 : 28)) { + return 0xFF; } - return true; + return type; } -static uint64_t pp_hash_calc(struct pp_netkey_ctx *net, uint64_t random, uint16_t *addr) +static uint64_t proxy_adv_hash_calc(struct netkey_ctx *net, uint64_t random, uint16_t *addr, + bool is_priv) { uint64_t hash; - uint8_t tmp[16] = {0, 0, 0, 0, 0, 3}; + uint8_t tmp[16] = {0}; + + tmp[5] = is_priv ? 3 : 0; if (addr) { memcpy(&tmp[6], &random, 8); @@ -1616,7 +1630,7 @@ static bool pp_beacon_check(const uint8_t *net_id, void *ctx) struct priv_test_ctx *test_ctx = (struct priv_test_ctx *)ctx; ASSERT_EQUAL(beacon.pp_hash, - pp_hash_calc(&pp_net0, beacon.pp_random, test_ctx->node_id_addr)); + proxy_adv_hash_calc(&pp_net0, beacon.pp_random, test_ctx->node_id_addr, true)); if (memcmp(beacon.adv_addr.a.val, last_beacon_adv_addr.a.val, BT_ADDR_SIZE) == 0) { return false; @@ -1632,15 +1646,58 @@ static void priv_scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type { struct priv_test_ctx *ctx = (struct priv_test_ctx *)beacon.user_ctx; - if (!pp_type_check(ctx->beacon_type, adv_type, buf)) { + if (proxy_adv_type_get(adv_type, buf) != ctx->beacon_type) { /* Wrong message type */ return; } bt_addr_le_copy(&beacon.adv_addr, addr); - beacon.pp_hash = net_buf_simple_pull_le64(buf); - beacon.pp_random = net_buf_simple_pull_le64(buf); + if (ctx->beacon_type == BEACON_TYPE_NET_ID) { + beacon.net_id = net_buf_simple_pull_le64(buf); + } else { + beacon.pp_hash = net_buf_simple_pull_le64(buf); + beacon.pp_random = net_buf_simple_pull_le64(buf); + } + + if (!beacon.process_cb || beacon.process_cb(NULL, beacon.user_ctx)) { + k_sem_give(&observer_sem); + } +} + +struct proxy_adv_beacon { + uint8_t evt_type; + uint8_t net_idx; + int64_t rx_timestamp; + union { + uint64_t net_id; + struct { + uint64_t hash; + uint64_t random; + } enc; + } ctx; +}; + +static void proxy_adv_scan_all_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type, + struct net_buf_simple *buf) +{ + struct proxy_adv_beacon *beac = (struct proxy_adv_beacon *)beacon.user_ctx; + + beac->evt_type = proxy_adv_type_get(adv_type, buf); + if (beac->evt_type == 0xFF) { + /* Not a related beacon type */ + return; + } + + bt_addr_le_copy(&beacon.adv_addr, addr); + beac->rx_timestamp = k_uptime_get(); + + if (beac->evt_type == BEACON_TYPE_NET_ID) { + beac->ctx.net_id = net_buf_simple_pull_le64(buf); + } else { + beac->ctx.enc.hash = net_buf_simple_pull_le64(buf); + beac->ctx.enc.random = net_buf_simple_pull_le64(buf); + } if (!beacon.process_cb || beacon.process_cb(NULL, beacon.user_ctx)) { k_sem_give(&observer_sem); @@ -1656,11 +1713,11 @@ static void rx_priv_common_init(uint16_t wait) ASSERT_OK_MSG(bt_enable(NULL), "Bluetooth init failed"); } -static void tx_priv_common_init(uint16_t wait) +static void tx_proxy_adv_common_init(uint16_t wait, const struct bt_mesh_test_cfg *cfg) { bt_mesh_test_cfg_set(NULL, wait); bt_mesh_device_setup(&prov, &prb_comp); - provision(&tx_cfg); + provision(cfg); /* Disable GATT proxy */ ASSERT_OK_MSG(bt_mesh_gatt_proxy_set(BT_MESH_GATT_PROXY_DISABLED), @@ -1669,7 +1726,7 @@ static void tx_priv_common_init(uint16_t wait) static void test_tx_priv_net_id(void) { - tx_priv_common_init(PP_NET_ID_WAIT_TIME); + tx_proxy_adv_common_init(PP_NET_ID_WAIT_TIME, &tx_cfg); /* Enable private GATT proxy */ ASSERT_OK_MSG(bt_mesh_priv_gatt_proxy_set(BT_MESH_GATT_PROXY_ENABLED), @@ -1708,7 +1765,7 @@ static void test_tx_priv_node_id(void) { enum bt_mesh_feat_state state; - tx_priv_common_init(PP_NODE_ID_WAIT_TIME); + tx_proxy_adv_common_init(PP_NODE_ID_WAIT_TIME, &tx_cfg); /* Start first node advertisement */ ASSERT_OK_MSG(bt_mesh_subnet_priv_node_id_set(TEST_NET_IDX1, BT_MESH_NODE_IDENTITY_RUNNING), @@ -1761,10 +1818,10 @@ static void test_rx_priv_node_id(void) static void test_tx_priv_multi_net_id(void) { - tx_priv_common_init(PP_MULT_NET_ID_WAIT_TIME); + tx_proxy_adv_common_init(PP_MULT_NET_ID_WAIT_TIME, &tx_cfg); /* Add second network */ - ASSERT_OK_MSG(bt_mesh_subnet_add(TEST_NET_IDX2, test_net_key_secondary), + ASSERT_OK_MSG(bt_mesh_subnet_add(TEST_NET_IDX2, test_net_key_2), "Failed to add second subnet"); /* Enable private GATT proxy */ @@ -1774,6 +1831,246 @@ static void test_tx_priv_multi_net_id(void) PASS(); } +static void proxy_adv_subnet_find(struct proxy_adv_beacon *beac, struct netkey_ctx **nets, + uint8_t net_cnt) +{ + for (size_t i = 0; i < net_cnt; i++) { + + switch (beac->evt_type) { + case BEACON_TYPE_NET_ID: + if (!memcmp(nets[i]->net_id, &beac->ctx.net_id, 8)) { + beac->net_idx = nets[i]->net_idx; + return; + } + break; + case BEACON_TYPE_NODE_ID: + if (beac->ctx.enc.hash == + proxy_adv_hash_calc(nets[i], beac->ctx.enc.random, + (uint16_t *)&tx_cfg.addr, false)) { + beac->net_idx = nets[i]->net_idx; + return; + } + break; + case BEACON_TYPE_PRIVATE_NET_ID: + if (beac->ctx.enc.hash == + proxy_adv_hash_calc(nets[i], beac->ctx.enc.random, + NULL, true)) { + beac->net_idx = nets[i]->net_idx; + return; + } + break; + case BEACON_TYPE_PRIVATE_NODE_ID: + if (beac->ctx.enc.hash == + proxy_adv_hash_calc(nets[i], beac->ctx.enc.random, + (uint16_t *)&tx_cfg.addr, true)) { + beac->net_idx = nets[i]->net_idx; + return; + } + break; + + default: + FAIL("Unexpected beacon type"); + break; + } + } + + FAIL("Could not find matching subnet for incoming proxy adv beacon"); +} + +static const char *const proxy_adv_str[] = {"Net_ID", "Node_ID", "Priv_Net_ID", "Priv_Node_ID"}; +struct expected_proxy_adv_evt { + uint8_t evt_type; + uint8_t net_idx; + uint16_t evt_cnt; + struct { + int64_t after; + int64_t before; + } time; +}; + +static void proxy_adv_register_evt(struct proxy_adv_beacon *beac, + struct expected_proxy_adv_evt *exp_evts, uint8_t cnt) +{ + for (int i = 0; i < cnt; i++) { + if ((exp_evts[i].evt_cnt) && (beac->evt_type == exp_evts[i].evt_type) && + (beac->net_idx == exp_evts[i].net_idx) && + (beac->rx_timestamp >= exp_evts[i].time.after) && + (beac->rx_timestamp <= exp_evts[i].time.before)) { + exp_evts[i].evt_cnt--; + } + } +} + +static void proxy_adv_confirm_evt(struct expected_proxy_adv_evt *exp_evts, uint8_t cnt) +{ + bool missing_evts = false; + + for (int i = 0; i < cnt; i++) { + if (exp_evts[i].evt_cnt) { + LOG_ERR("Missing %d expected %s events in period %llums-%llums", + exp_evts[i].evt_cnt, proxy_adv_str[exp_evts[i].evt_type], + exp_evts[i].time.after, exp_evts[i].time.before); + missing_evts = true; + } + } + + if (missing_evts) { + FAIL("Test failed due to missing events"); + } +} + +static void proxy_adv_scan_all(struct netkey_ctx **nets, uint16_t net_cnt, + struct expected_proxy_adv_evt *exp_evt, uint16_t exp_evt_cnt, + int64_t timeout) +{ + struct proxy_adv_beacon beac; + + while (k_uptime_get() < timeout) { + + ASSERT_TRUE(wait_for_beacon(proxy_adv_scan_all_cb, 2, NULL, &beac)); + proxy_adv_subnet_find(&beac, nets, net_cnt); + proxy_adv_register_evt(&beac, exp_evt, exp_evt_cnt); + + /** We want to monitor an even distribution of adv events. + * To ensure this, we wait a little less than the minimum + * proxy adv period (1 second) before scanning for the next + * evt. + */ + k_sleep(K_MSEC(990)); + } + + proxy_adv_confirm_evt(exp_evt, exp_evt_cnt); +} + +#define PROXY_ADV_MULTI_CHECKPOINT_1 20000 +#define PROXY_ADV_MULTI_CHECKPOINT_2 50000 +#define PROXY_ADV_MULTI_CHECKPOINT_3 110000 +#define PROXY_ADV_MULTI_CHECKPOINT_4 130000 +#define PROXY_ADV_MULTI_CHECKPOINT_END 150000 + +static void test_tx_proxy_adv_multi_subnet_coex(void) +{ + tx_proxy_adv_common_init(PROXY_ADV_MULTI_SUBNET_COEX_WAIT_TIME, &tx_cfg); + + /* Enable GATT proxy */ + ASSERT_OK_MSG(bt_mesh_gatt_proxy_set(BT_MESH_GATT_PROXY_ENABLED), + "Failed to Enable gatt proxy"); + + k_sleep(UNTIL_UPTIME(PROXY_ADV_MULTI_CHECKPOINT_1)); + /* Add second and third network */ + ASSERT_OK_MSG(bt_mesh_subnet_add(TEST_NET_IDX2, test_net_key_2), + "Failed to add second subnet"); + ASSERT_OK_MSG(bt_mesh_subnet_add(TEST_NET_IDX3, test_net_key_3), + "Failed to add third subnet"); + + k_sleep(UNTIL_UPTIME(PROXY_ADV_MULTI_CHECKPOINT_2)); + /* Start Node Identity on second network */ + bt_mesh_proxy_identity_start(bt_mesh_subnet_get(TEST_NET_IDX2), false); + + k_sleep(UNTIL_UPTIME(PROXY_ADV_MULTI_CHECKPOINT_3)); + /* Prepare for solicitation */ + ASSERT_OK_MSG(bt_mesh_gatt_proxy_set(BT_MESH_GATT_PROXY_DISABLED), + "Failed to Enable gatt proxy"); + ASSERT_OK_MSG(bt_mesh_od_priv_proxy_set(20), "Failed to set OD priv proxy state"); + + k_sleep(UNTIL_UPTIME(PROXY_ADV_MULTI_CHECKPOINT_4)); + /* Re-enable GATT proxy and remove second and third network */ + ASSERT_OK_MSG(bt_mesh_gatt_proxy_set(BT_MESH_GATT_PROXY_ENABLED), + "Failed to Enable gatt proxy"); + ASSERT_OK_MSG(bt_mesh_subnet_del(TEST_NET_IDX2), "Failed to delete subnet"); + ASSERT_OK_MSG(bt_mesh_subnet_del(TEST_NET_IDX3), "Failed to delete subnet"); + + PASS(); +} + +static const struct bt_mesh_test_cfg solicit_trigger_cfg = { + .addr = 0x0003, + .dev_key = { 0x03 }, +}; + +static void test_tx_proxy_adv_solicit_trigger(void) +{ + tx_proxy_adv_common_init(PROXY_ADV_MULTI_SUBNET_COEX_WAIT_TIME, &solicit_trigger_cfg); + ASSERT_OK_MSG(bt_mesh_subnet_add(TEST_NET_IDX2, test_net_key_2), + "Failed to add second subnet"); + + k_sleep(UNTIL_UPTIME(PROXY_ADV_MULTI_CHECKPOINT_3)); + + /* Solicit first and second network */ + ASSERT_OK_MSG(bt_mesh_proxy_solicit(TEST_NET_IDX1), + "Failed to start solicitation"); + ASSERT_OK_MSG(bt_mesh_proxy_solicit(TEST_NET_IDX2), + "Failed to start solicitation"); + + PASS(); +} + +static void test_rx_proxy_adv_multi_subnet_coex(void) +{ + rx_priv_common_init(PROXY_ADV_MULTI_SUBNET_COEX_WAIT_TIME); + pp_netkey_ctx_init(&pp_net1); + pp_netkey_ctx_init(&pp_net2); + + struct netkey_ctx *nets[] = {&pp_net0, &pp_net1, &pp_net2}; + struct expected_proxy_adv_evt exp_evt[] = { + /** A single subnet is active on the device with GATT Proxy + * enabled. Verify that the single subnet has exclusive + * access to the adv medium. + */ + {.evt_type = BEACON_TYPE_NET_ID, .net_idx = 0, .evt_cnt = 19, + .time = {.after = 0, .before = PROXY_ADV_MULTI_CHECKPOINT_1}}, + + /** Two additional subnets are added to the device. + * Check that the subnets are sharing the adv medium, + * advertising NET_ID beacons. + */ + {.evt_type = BEACON_TYPE_NET_ID, .net_idx = 0, .evt_cnt = 8, + .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_1, + .before = PROXY_ADV_MULTI_CHECKPOINT_2}}, + {.evt_type = BEACON_TYPE_NET_ID, .net_idx = 1, .evt_cnt = 8, + .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_1, + .before = PROXY_ADV_MULTI_CHECKPOINT_2}}, + {.evt_type = BEACON_TYPE_NET_ID, .net_idx = 2, .evt_cnt = 8, + .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_1, + .before = PROXY_ADV_MULTI_CHECKPOINT_2}}, + + /** The second subnet enables Node Identity. Check that NODE_ID + * is advertised by this subnet, and that the two others + * continues to advertise NET_ID. + */ + {.evt_type = BEACON_TYPE_NET_ID, .net_idx = 0, .evt_cnt = 17, + .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_2, + .before = PROXY_ADV_MULTI_CHECKPOINT_3}}, + {.evt_type = BEACON_TYPE_NODE_ID, .net_idx = 1, .evt_cnt = 17, + .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_2, + .before = PROXY_ADV_MULTI_CHECKPOINT_3}}, + {.evt_type = BEACON_TYPE_NET_ID, .net_idx = 2, .evt_cnt = 17, + .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_2, + .before = PROXY_ADV_MULTI_CHECKPOINT_3}}, + + /** The first and second subnet gets solicited. Check that + * PRIVATE_NET_ID is advertised by these subnet, + */ + {.evt_type = BEACON_TYPE_PRIVATE_NET_ID, .net_idx = 0, .evt_cnt = 9, + .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_3, + .before = PROXY_ADV_MULTI_CHECKPOINT_4}}, + {.evt_type = BEACON_TYPE_PRIVATE_NET_ID, .net_idx = 1, .evt_cnt = 9, + .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_3, + .before = PROXY_ADV_MULTI_CHECKPOINT_4}}, + + /** Second and third subnet are disabled. Verify that the single + * subnet has exclusive access to the adv medium. + */ + {.evt_type = BEACON_TYPE_NET_ID, .net_idx = 0, .evt_cnt = 19, + .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_4, + .before = PROXY_ADV_MULTI_CHECKPOINT_END}}, + }; + + proxy_adv_scan_all(nets, ARRAY_SIZE(nets), exp_evt, ARRAY_SIZE(exp_evt), + PROXY_ADV_MULTI_CHECKPOINT_END); + PASS(); +} + static void test_rx_priv_multi_net_id(void) { rx_priv_common_init(PP_MULT_NET_ID_WAIT_TIME); @@ -1787,7 +2084,7 @@ static void test_rx_priv_multi_net_id(void) uint16_t itr = 4; static uint8_t old_idx = 0xff; static struct { - struct pp_netkey_ctx *net; + struct netkey_ctx *net; uint16_t recv_cnt; int64_t start; } net_ctx[2] = { @@ -1802,7 +2099,7 @@ static void test_rx_priv_multi_net_id(void) for (size_t i = 0; i < ARRAY_SIZE(net_ctx); i++) { if (beacon.pp_hash == - pp_hash_calc(net_ctx[i].net, beacon.pp_random, NULL)) { + proxy_adv_hash_calc(net_ctx[i].net, beacon.pp_random, NULL, true)) { if (old_idx == 0xff) { /* Received first Net ID advertisment */ old_idx = i; @@ -1931,6 +2228,8 @@ static const struct bst_test_instance test_beacon[] = { TEST_CASE(tx, priv_node_id, "Private Proxy: advertise Node ID"), TEST_CASE(tx, priv_multi_net_id, "Private Proxy: advertise multiple Net ID"), TEST_CASE(tx, priv_gatt_proxy, "Private Proxy: Send Private Beacons over GATT"), + TEST_CASE(tx, proxy_adv_multi_subnet_coex, "Proxy Adv: Multi subnet coex proxy adv"), + TEST_CASE(tx, proxy_adv_solicit_trigger, "Proxy Adv: Trigger Solicitation"), #endif #endif @@ -1951,6 +2250,7 @@ static const struct bst_test_instance test_beacon[] = { TEST_CASE(rx, priv_node_id, "Private Proxy: scan for Node ID"), TEST_CASE(rx, priv_multi_net_id, "Private Proxy: scan for multiple Net ID"), TEST_CASE(rx, priv_gatt_proxy, "Private Proxy: Receive Private Beacons over GATT"), + TEST_CASE(rx, proxy_adv_multi_subnet_coex, "Proxy Adv: Multi subnet coex proxy adv"), #endif #endif BSTEST_END_MARKER diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh new file mode 100755 index 00000000000..aa96ee325d8 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test Proxy advertisement Coex + +# This test verifies correct Proxy advertisement behavior for a device +# where the Proxy adv requirements changes over time, both for single +# and multiple subnets. The TX device is the DUT in this instance, while +# the RX device scans and verifies that the correct proxy adv messages of +# the different subnets is sent within the expected time delta. + +# Note 1: The maximum allowed timeslot for a subnet to advertise proxy +# in this scenario is 10 seconds when there is more than one subnet that +# has active proxy adv work. This is reflected in the scanning criteria +# on the RX device. + +# Note 2: The expected message received count for each event is based on +# what would be a reasonable/acceptable to receive within a given time +# window. The Mesh Protocol specification does not specify exactly the +# timing for Proxy ADV messages. + +# Test procedure: +# 1. (0-20 seconds) A single subnet is active on the TX device with GATT +# Proxy enabled. RX device verifies that the single subnet has exclusive +# access to the adv medium. +# 2. (20-50 seconds) Two additional subnets are added to the TX device. RX +# device checks that the subnets are sharing the adv medium, advertising +# NET_ID beacons. +# 3. (50-110 seconds) The second subnet enables Node Identity. RX device +# checks that NODE_ID is advertised by this subnet, and that the two +# others continues to advertise NET_ID. +# 4. (110-130 seconds) The first and second subnet gets solicited. RX device +# checks that PRIVATE_NET_ID is advertised by these subnets. +# 5. (130-150 seconds) The second and third subnet are disabled on the TX +# device. RX device verifies that the single subnet has exclusive access +# to the adv medium again. + + +conf=prj_mesh1d1_conf +overlay=overlay_gatt_conf +RunTest proxy_adv_multi_subnet_coex \ + beacon_tx_proxy_adv_multi_subnet_coex \ + beacon_rx_proxy_adv_multi_subnet_coex \ + beacon_tx_proxy_adv_solicit_trigger + +conf=prj_mesh1d1_conf +overlay=overlay_gatt_conf_overlay_psa_conf +RunTest proxy_adv_multi_subnet_coex \ + beacon_tx_proxy_adv_multi_subnet_coex \ + beacon_rx_proxy_adv_multi_subnet_coex \ + beacon_tx_proxy_adv_solicit_trigger From f4b0993d4966c82f9a18c6ac7d55dc9960ef5be3 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Thu, 11 Jan 2024 14:02:45 +0100 Subject: [PATCH 1017/1623] [nrf fromtree] Bluetooth: Mesh: remove 20ms tx delay in adv bearer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The recommendation to have 20ms is fair for two consecutive messages over a single bearer. When mesh sends two messages it can be interpreted as two bearers working in parallel. No need to keep an artificial 20ms delay for that. Delay was removed and all related bsim tests were fixed. Signed-off-by: Aleksandr Khromykh (cherry picked from commit ac4cfe9880f45e871a98e2a62c3b1bd804b3860f) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/adv_ext.c | 54 ++++++------------- tests/bsim/bluetooth/mesh/overlay_pst.conf | 2 + .../bluetooth/mesh/src/test_persistence.c | 6 +++ .../bsim/bluetooth/mesh/src/test_provision.c | 10 ++++ 4 files changed, 34 insertions(+), 38 deletions(-) diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index a4f3f32ee5f..c30a3a2b9bc 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -63,8 +63,8 @@ struct bt_mesh_ext_adv { ATOMIC_DEFINE(flags, ADV_FLAGS_NUM); struct bt_le_ext_adv *instance; struct bt_mesh_adv *adv; - uint64_t timestamp; - struct k_work_delayable work; + uint32_t timestamp; + struct k_work work; struct bt_le_adv_param adv_param; }; @@ -88,7 +88,7 @@ static struct bt_mesh_ext_adv advs[] = { #endif /* CONFIG_BT_MESH_PB_ADV */ BT_MESH_ADV_TAG_BIT_LOCAL ), - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), + .work = Z_WORK_INITIALIZER(send_pending_adv), }, #if CONFIG_BT_MESH_RELAY_ADV_SETS [1 ... CONFIG_BT_MESH_RELAY_ADV_SETS] = { @@ -100,19 +100,19 @@ static struct bt_mesh_ext_adv advs[] = { BT_MESH_ADV_TAG_BIT_PROV | #endif /* CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS */ 0), - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), + .work = Z_WORK_INITIALIZER(send_pending_adv), }, #endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) { .tags = BT_MESH_ADV_TAG_BIT_FRIEND, - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), + .work = Z_WORK_INITIALIZER(send_pending_adv), }, #endif /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ #if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) { .tags = BT_MESH_ADV_TAG_BIT_PROXY, - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), + .work = Z_WORK_INITIALIZER(send_pending_adv), }, #endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ }; @@ -197,7 +197,7 @@ static int adv_start(struct bt_mesh_ext_adv *ext_adv, return err; } - ext_adv->timestamp = k_uptime_get(); + ext_adv->timestamp = k_uptime_get_32(); err = bt_le_ext_adv_start(ext_adv->instance, start); if (err) { @@ -271,18 +271,13 @@ static void send_pending_adv(struct k_work *work) struct bt_mesh_adv *adv; int err; - ext_adv = CONTAINER_OF(work, struct bt_mesh_ext_adv, work.work); + ext_adv = CONTAINER_OF(work, struct bt_mesh_ext_adv, work); if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_SENT)) { - /* Calling k_uptime_delta on a timestamp moves it to the current time. - * This is essential here, as schedule_send() uses the end of the event - * as a reference to avoid sending the next advertisement too soon. - */ - int64_t duration = k_uptime_delta(&ext_adv->timestamp); - - LOG_DBG("Advertising stopped after %u ms for %s", (uint32_t)duration, - ext_adv->adv ? adv_tag_to_str[ext_adv->adv->ctx.tag] : - adv_tag_to_str[BT_MESH_ADV_TAG_PROXY]); + LOG_DBG("Advertising stopped after %u ms for %s", + k_uptime_get_32() - ext_adv->timestamp, + ext_adv->adv ? adv_tag_to_str[ext_adv->adv->ctx.tag] + : adv_tag_to_str[BT_MESH_ADV_TAG_PROXY]); atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY); @@ -340,11 +335,6 @@ static void send_pending_adv(struct k_work *work) static bool schedule_send(struct bt_mesh_ext_adv *ext_adv) { - uint64_t timestamp; - int64_t delta; - - timestamp = ext_adv->timestamp; - if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_PROXY)) { atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START); (void)bt_le_ext_adv_stop(ext_adv->instance); @@ -360,19 +350,7 @@ static bool schedule_send(struct bt_mesh_ext_adv *ext_adv) } atomic_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING); - - if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - ext_adv->tags & BT_MESH_ADV_TAG_BIT_FRIEND) || - (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && ext_adv->tags & BT_MESH_ADV_TAG_BIT_RELAY)) { - k_work_reschedule(&ext_adv->work, K_NO_WAIT); - } else { - /* The controller will send the next advertisement immediately. - * Introduce a delay here to avoid sending the next mesh packet closer - * to the previous packet than what's permitted by the specification. - */ - delta = k_uptime_delta(×tamp); - k_work_reschedule(&ext_adv->work, K_MSEC(ADV_INT_FAST_MS - delta)); - } + k_work_submit(&ext_adv->work); return true; } @@ -438,7 +416,7 @@ void bt_mesh_adv_terminate(struct bt_mesh_adv *adv) atomic_set_bit(ext_adv->flags, ADV_FLAG_SENT); - k_work_submit(&ext_adv->work.work); + k_work_submit(&ext_adv->work); return; } @@ -487,7 +465,7 @@ static void adv_sent(struct bt_le_ext_adv *instance, atomic_set_bit(ext_adv->flags, ADV_FLAG_SENT); - k_work_submit(&ext_adv->work.work); + k_work_submit(&ext_adv->work); } #if defined(CONFIG_BT_MESH_GATT_SERVER) @@ -545,7 +523,7 @@ int bt_mesh_adv_disable(void) struct k_work_sync sync; for (int i = 0; i < ARRAY_SIZE(advs); i++) { - k_work_flush_delayable(&advs[i].work, &sync); + k_work_flush(&advs[i].work, &sync); err = bt_le_ext_adv_stop(advs[i].instance); if (err) { diff --git a/tests/bsim/bluetooth/mesh/overlay_pst.conf b/tests/bsim/bluetooth/mesh/overlay_pst.conf index 6a56ec8065b..6730b9ee233 100644 --- a/tests/bsim/bluetooth/mesh/overlay_pst.conf +++ b/tests/bsim/bluetooth/mesh/overlay_pst.conf @@ -19,4 +19,6 @@ CONFIG_BT_MESH_SEQ_STORE_RATE=1 CONFIG_BT_MESH_RPL_STORE_TIMEOUT=1 CONFIG_BT_MESH_STORE_TIMEOUT=1 CONFIG_BT_MESH_TX_SEG_RETRANS_COUNT=1 +CONFIG_BT_MESH_TX_SEG_RETRANS_TIMEOUT_UNICAST=200 +CONFIG_BT_MESH_SEG_ACK_BASE_TIMEOUT=400 CONFIG_BT_MESH_COMP_PST_BUF_SIZE=600 diff --git a/tests/bsim/bluetooth/mesh/src/test_persistence.c b/tests/bsim/bluetooth/mesh/src/test_persistence.c index 4bf1f9faa93..ec7d838d26a 100644 --- a/tests/bsim/bluetooth/mesh/src/test_persistence.c +++ b/tests/bsim/bluetooth/mesh/src/test_persistence.c @@ -455,6 +455,12 @@ static void provisioner_setup(void) FAIL("Failed to add test_netkey (err: %d, status: %d)", err, status); } + err = bt_mesh_cfg_cli_net_transmit_set(test_netkey_idx, TEST_PROV_ADDR, + BT_MESH_TRANSMIT(3, 50), &status); + if (err || status != BT_MESH_TRANSMIT(3, 50)) { + FAIL("Net transmit set failed (err %d, transmit %x)", err, status); + } + provisioner_ready = true; } diff --git a/tests/bsim/bluetooth/mesh/src/test_provision.c b/tests/bsim/bluetooth/mesh/src/test_provision.c index 3d0e8010c75..2bff871b187 100644 --- a/tests/bsim/bluetooth/mesh/src/test_provision.c +++ b/tests/bsim/bluetooth/mesh/src/test_provision.c @@ -1205,6 +1205,7 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void) uint16_t pb_remote_server_addr; uint8_t status; struct bt_mesh_cdb_node *node; + int err; provisioner_pb_remote_client_setup(); @@ -1218,6 +1219,15 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void) .ttl = 3, }; + /* Set Network Transmit Count state on the remote client greater than on the remote server + * to increase probability of reception responses. + */ + err = bt_mesh_cfg_cli_net_transmit_set(0, current_dev_addr, BT_MESH_TRANSMIT(3, 50), + &status); + if (err || status != BT_MESH_TRANSMIT(3, 50)) { + FAIL("Net transmit set failed (err %d, transmit %x)", err, status); + } + ASSERT_OK(provision_remote(&srv, 2, &srv.addr)); /* Check device key by adding appkey. */ From 609321cdd817d0e6201a0ed19b8a17011b567ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Thu, 11 Jan 2024 14:02:45 +0100 Subject: [PATCH 1018/1623] [nrf fromtree] Bluetooth: Mesh: fix proxy srv return value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, `bt_mesh_proxy_gatt_enable` returned the return value from `k_work_schedule`, which could be a positive (non-error) message. Now, it only returns negative error codes (else 0). Signed-off-by: Håvard Reierstad (cherry picked from commit 9285ea3238e468e1294e92bcad56a2b9b34d0d63) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/proxy_srv.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/proxy_srv.c b/subsys/bluetooth/mesh/proxy_srv.c index 25a44abfded..a903d94ffa9 100644 --- a/subsys/bluetooth/mesh/proxy_srv.c +++ b/subsys/bluetooth/mesh/proxy_srv.c @@ -975,6 +975,8 @@ static void svc_reg_work_handler(struct k_work *work) int bt_mesh_proxy_gatt_enable(void) { + int err; + LOG_DBG(""); if (!bt_mesh_is_provisioned()) { @@ -986,7 +988,13 @@ int bt_mesh_proxy_gatt_enable(void) } svc_reg_attempts = PROXY_SVC_REG_ATTEMPTS; - return k_work_schedule(&svc_reg_work, PROXY_SVC_INIT_TIMEOUT); + err = k_work_schedule(&svc_reg_work, PROXY_SVC_INIT_TIMEOUT); + if (err < 0) { + LOG_ERR("Enabling GATT proxy failed (err %d)", err); + return err; + } + + return 0; } void bt_mesh_proxy_gatt_disconnect(void) From 9aa5cc1391f01d02c72e2d44cc636e5edd7899d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Reierstad?= Date: Thu, 11 Jan 2024 14:02:45 +0100 Subject: [PATCH 1019/1623] [nrf fromtree] Bluetooth: Mesh: suspend/resume gatt advs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Disables pb gatt- and gatt proxy advs when suspending Mesh, and enables them again when resuming Mesh. Adds `bt_mesh_adv_gatt_send` to `bt_mesh_resume` to make sure that GATT advs start after resumption. Signed-off-by: Håvard Reierstad (cherry picked from commit 6c5fc658efc713b04b6c495be3170c46bf4ef832) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/main.c | 40 +++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index 2689a3355c1..1b80233cec1 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -462,6 +462,22 @@ int bt_mesh_suspend(void) bt_mesh_access_suspend(); + if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) { + err = bt_mesh_pb_gatt_srv_disable(); + if (err && err != -EALREADY) { + LOG_WRN("Disabling PB-GATT failed (err %d)", err); + return err; + } + } + + if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { + err = bt_mesh_proxy_gatt_disable(); + if (err && err != -EALREADY) { + LOG_WRN("Disabling GATT proxy failed (err %d)", err); + return err; + } + } + err = bt_mesh_adv_disable(); if (err) { atomic_clear_bit(bt_mesh.flags, BT_MESH_SUSPENDED); @@ -508,6 +524,22 @@ int bt_mesh_resume(void) return err; } + if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && bt_mesh_is_provisioned()) { + err = bt_mesh_proxy_gatt_enable(); + if (err) { + LOG_WRN("Re-enabling GATT proxy failed (err %d)", err); + return err; + } + } + + if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && !bt_mesh_is_provisioned()) { + err = bt_mesh_pb_gatt_srv_enable(); + if (err) { + LOG_WRN("Re-enabling PB-GATT failed (err %d)", err); + return err; + } + } + err = bt_mesh_scan_enable(); if (err) { LOG_WRN("Re-enabling scanning failed (err %d)", err); @@ -524,7 +556,13 @@ int bt_mesh_resume(void) bt_mesh_model_foreach(model_resume, NULL); - return err; + err = bt_mesh_adv_gatt_send(); + if (err && (err != -ENOTSUP)) { + LOG_WRN("GATT send failed (err %d)", err); + return err; + } + + return 0; } int bt_mesh_init(const struct bt_mesh_prov *prov, From f6e704ceefa7330d061eb9a5579e670d26524708 Mon Sep 17 00:00:00 2001 From: Andrzej Kuros Date: Mon, 15 Jan 2024 11:35:28 +0100 Subject: [PATCH 1020/1623] [nrf fromtree] dts: nrf5340: add missing `easydma-maxcnt-bits` for nrf5340_cpunet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The required property `easydma-maxcnt-bits` was missing for nrf5340_cpunet. Signed-off-by: Andrzej Kuroś (cherry picked from commit 728f0ec7bed5f8f210b88132bfa2fc0c4f28204c) --- dts/arm/nordic/nrf5340_cpunet.dtsi | 1 + 1 file changed, 1 insertion(+) diff --git a/dts/arm/nordic/nrf5340_cpunet.dtsi b/dts/arm/nordic/nrf5340_cpunet.dtsi index 63c7e920f81..c1e8371d410 100644 --- a/dts/arm/nordic/nrf5340_cpunet.dtsi +++ b/dts/arm/nordic/nrf5340_cpunet.dtsi @@ -192,6 +192,7 @@ reg = <0x41013000 0x1000>; clock-frequency = ; interrupts = <19 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <16>; status = "disabled"; }; From 65d32263c87639e9c199b31f6d770ab579796072 Mon Sep 17 00:00:00 2001 From: Ajay Parida Date: Mon, 8 Jan 2024 16:57:32 +0530 Subject: [PATCH 1021/1623] [nrf fromtree] net: mgmt: Provide Regulatory channel info Updated to provide regulatory channel information along with country code. Signed-off-by: Ajay Parida (cherry picked from commit 56de0a347e6965b0c5612cfd31725d75535532b4) --- include/zephyr/net/wifi_mgmt.h | 20 ++++++++++++++++++++ subsys/net/l2/wifi/wifi_shell.c | 19 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 78800f451e7..f6ae631a830 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -546,6 +546,22 @@ enum wifi_mgmt_op { WIFI_MGMT_SET = 1, }; +#define MAX_REG_CHAN_NUM 42 + +/** Per-channel regulatory attributes */ +struct wifi_reg_chan_info { + /** Center frequency in MHz */ + unsigned short center_frequency; + /** Maximum transmission power (in dBm) */ + unsigned short max_power:8; + /** Is channel supported or not */ + unsigned short supported:1; + /** Passive transmissions only */ + unsigned short passive_only:1; + /** Is a DFS channel */ + unsigned short dfs:1; +} __packed; + /** Regulatory domain information or configuration */ struct wifi_reg_domain { /* Regulatory domain operation */ @@ -554,6 +570,10 @@ struct wifi_reg_domain { bool force; /** Country code: ISO/IEC 3166-1 alpha-2 */ uint8_t country_code[WIFI_COUNTRY_CODE_LEN]; + /** Number of channels supported */ + unsigned int num_channels; + /** Channels information */ + struct wifi_reg_chan_info *chan_info; }; /** Wi-Fi TWT sleep states */ diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 1ee94304781..e1446cceca0 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -64,6 +64,7 @@ static struct { static uint32_t scan_result; static struct net_mgmt_event_callback wifi_shell_mgmt_cb; +static struct wifi_reg_chan_info chan_info[MAX_REG_CHAN_NUM]; static K_MUTEX_DEFINE(wifi_ap_sta_list_lock); struct wifi_ap_sta_node { @@ -134,7 +135,6 @@ static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb) wifi_mfp_txt(entry->mfp)); } -#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS static int wifi_freq_to_channel(int frequency) { int channel = 0; @@ -156,6 +156,7 @@ static int wifi_freq_to_channel(int frequency) return channel; } +#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS static enum wifi_frequency_bands wifi_freq_to_band(int frequency) { enum wifi_frequency_bands band = WIFI_FREQ_BAND_2_4_GHZ; @@ -1289,9 +1290,10 @@ static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc, { struct net_if *iface = net_if_get_first_wifi(); struct wifi_reg_domain regd = {0}; - int ret; + int ret, chan_idx = 0; if (argc == 1) { + (®d)->chan_info = &chan_info[0]; regd.oper = WIFI_MGMT_GET; } else if (argc >= 2 && argc <= 3) { regd.oper = WIFI_MGMT_SET; @@ -1336,6 +1338,19 @@ static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc, if (regd.oper == WIFI_MGMT_GET) { shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi Regulatory domain is: %c%c\n", regd.country_code[0], regd.country_code[1]); + shell_fprintf(sh, SHELL_NORMAL, + "\t
\t\t" + "\t\t\n"); + for (chan_idx = 0; chan_idx < regd.num_channels; chan_idx++) { + shell_fprintf(sh, SHELL_NORMAL, + " %d\t\t\t\%d\t\t\t\%s\t\t\t%d\t\t\t%s\t\t\t\t%s\n", + wifi_freq_to_channel(chan_info[chan_idx].center_frequency), + chan_info[chan_idx].center_frequency, + chan_info[chan_idx].supported ? "y" : "n", + chan_info[chan_idx].max_power, + chan_info[chan_idx].passive_only ? "y" : "n", + chan_info[chan_idx].dfs ? "y" : "n"); + } } else { shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi Regulatory domain set to: %c%c\n", regd.country_code[0], regd.country_code[1]); From 5ff2ec1ac15ad91cd16229a698b3b3ecbc2aa468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Ciupis?= Date: Wed, 3 Jan 2024 08:46:08 +0100 Subject: [PATCH 1022/1623] [nrf fromtree] manifest: update hal_nordic revision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates revision of hal_nordic to bring the latest changes in the nRF IEEE 802.15.4 driver. Signed-off-by: Jędrzej Ciupis (cherry picked from commit 1bbaaeffb0c24b4252ffd6f72e2c6781bb1ef853) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index c99118074eb..a141e94edd6 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: b9633ecea67bf52925d4c61455046223b46402b1 + revision: 3786c55424d4d64c62dd25219de31618cef26fdf path: modules/hal/nordic groups: - hal From c2f6fa7a7b1b6ec8d7b3901f8cf008328b773ae0 Mon Sep 17 00:00:00 2001 From: Eduardo Montoya Date: Tue, 31 Oct 2023 09:42:36 +0100 Subject: [PATCH 1023/1623] [nrf fromtree] drivers: ieee802154: nrf: make selective tx power the default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove `IEEE802154_SELECTIVE_TXPOWER` option. Cache the tx power value in nRF5 driver and make use of it on each operation. Signed-off-by: Eduardo Montoya Signed-off-by: Jędrzej Ciupis (cherry picked from commit 5767998d4f7f9ef89a6983e4c540215676051e7a) --- doc/releases/release-notes-3.6.rst | 2 ++ drivers/ieee802154/Kconfig | 5 ----- drivers/ieee802154/ieee802154_nrf5.c | 24 +++++++++++------------- drivers/ieee802154/ieee802154_nrf5.h | 3 +++ include/zephyr/net/ieee802154_pkt.h | 18 ------------------ modules/openthread/platform/radio.c | 7 +------ 6 files changed, 17 insertions(+), 42 deletions(-) diff --git a/doc/releases/release-notes-3.6.rst b/doc/releases/release-notes-3.6.rst index 8edd3280382..a253434a085 100644 --- a/doc/releases/release-notes-3.6.rst +++ b/doc/releases/release-notes-3.6.rst @@ -154,6 +154,8 @@ Drivers and Sensors * IEEE 802.15.4 + * Removed :kconfig:option:`CONFIG_IEEE802154_SELECTIVE_TXPOWER` Kconfig option. + * Interrupt Controller * Input diff --git a/drivers/ieee802154/Kconfig b/drivers/ieee802154/Kconfig index feccd4a6001..d692024b096 100644 --- a/drivers/ieee802154/Kconfig +++ b/drivers/ieee802154/Kconfig @@ -98,11 +98,6 @@ config IEEE802154_CSL_DEBUG help Enable support for CSL debugging by avoiding sleep state in favor of receive state. -config IEEE802154_SELECTIVE_TXPOWER - bool "Support selective TX power setting" - help - Enable support for selectively setting TX power for every transmission request. - module = IEEE802154_DRIVER module-str = IEEE 802.15.4 driver module-help = Sets log level for IEEE 802.15.4 Device Drivers. diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index e9c49e6089e..a43a1b44471 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -375,7 +375,7 @@ static int nrf5_set_txpower(const struct device *dev, int16_t dbm) LOG_DBG("%d", dbm); - nrf_802154_tx_power_set(dbm); + nrf5_data.txpwr = dbm; return 0; } @@ -454,10 +454,8 @@ static bool nrf5_tx_immediate(struct net_pkt *pkt, uint8_t *payload, bool cca) }, .cca = cca, .tx_power = { - .use_metadata_value = IS_ENABLED(CONFIG_IEEE802154_SELECTIVE_TXPOWER), -#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER) - .power = net_pkt_ieee802154_txpwr(pkt), -#endif + .use_metadata_value = true, + .power = nrf5_data.txpwr, }, }; @@ -473,10 +471,8 @@ static bool nrf5_tx_csma_ca(struct net_pkt *pkt, uint8_t *payload) .dynamic_data_is_set = net_pkt_ieee802154_mac_hdr_rdy(pkt), }, .tx_power = { - .use_metadata_value = IS_ENABLED(CONFIG_IEEE802154_SELECTIVE_TXPOWER), -#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER) - .power = net_pkt_ieee802154_txpwr(pkt), -#endif + .use_metadata_value = true, + .power = nrf5_data.txpwr, }, }; @@ -519,10 +515,8 @@ static bool nrf5_tx_at(struct nrf5_802154_data *nrf5_radio, struct net_pkt *pkt, .cca = cca, .channel = nrf_802154_channel_get(), .tx_power = { - .use_metadata_value = IS_ENABLED(CONFIG_IEEE802154_SELECTIVE_TXPOWER), -#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER) - .power = net_pkt_ieee802154_txpwr(pkt), -#endif + .use_metadata_value = true, + .power = nrf5_data.txpwr, }, #if defined(CONFIG_IEEE802154_NRF5_MULTIPLE_CCA) .extra_cca_attempts = max_extra_cca_attempts, @@ -660,6 +654,8 @@ static int nrf5_start(const struct device *dev) { ARG_UNUSED(dev); + nrf_802154_tx_power_set(nrf5_data.txpwr); + if (!nrf_802154_receive()) { LOG_ERR("Failed to enter receive state"); return -EIO; @@ -702,6 +698,8 @@ static int nrf5_continuous_carrier(const struct device *dev) { ARG_UNUSED(dev); + nrf_802154_tx_power_set(nrf5_data.txpwr); + if (!nrf_802154_continuous_carrier()) { LOG_ERR("Failed to enter continuous carrier state"); return -EIO; diff --git a/drivers/ieee802154/ieee802154_nrf5.h b/drivers/ieee802154/ieee802154_nrf5.h index 9115fe0bdae..79b47827d72 100644 --- a/drivers/ieee802154/ieee802154_nrf5.h +++ b/drivers/ieee802154/ieee802154_nrf5.h @@ -97,6 +97,9 @@ struct nrf5_802154_data { uint8_t max_extra_cca_attempts; #endif + /* The TX power in dBm. */ + int8_t txpwr; + #if defined(CONFIG_NRF_802154_SER_HOST) && defined(CONFIG_IEEE802154_CSL_ENDPOINT) /* The last configured value of CSL period in units of 10 symbols. */ uint32_t csl_period; diff --git a/include/zephyr/net/ieee802154_pkt.h b/include/zephyr/net/ieee802154_pkt.h index d5fdc712b49..3270f994248 100644 --- a/include/zephyr/net/ieee802154_pkt.h +++ b/include/zephyr/net/ieee802154_pkt.h @@ -59,12 +59,6 @@ struct net_pkt_cb_ieee802154 { */ uint8_t rssi; }; -#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER) - /* TX packets */ - struct { - int8_t txpwr; /* TX power in dBm. */ - }; -#endif /* CONFIG_IEEE802154_SELECTIVE_TXPOWER */ }; /* Flags */ @@ -185,18 +179,6 @@ static inline void net_pkt_set_ieee802154_rssi_dbm(struct net_pkt *pkt, int16_t CODE_UNREACHABLE; } -#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER) -static inline int8_t net_pkt_ieee802154_txpwr(struct net_pkt *pkt) -{ - return net_pkt_cb_ieee802154(pkt)->txpwr; -} - -static inline void net_pkt_set_ieee802154_txpwr(struct net_pkt *pkt, int8_t txpwr) -{ - net_pkt_cb_ieee802154(pkt)->txpwr = txpwr; -} -#endif /* CONFIG_IEEE802154_SELECTIVE_TXPOWER */ - static inline bool net_pkt_ieee802154_ack_fpb(struct net_pkt *pkt) { return net_pkt_cb_ieee802154(pkt)->ack_fpb; diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index a09b7dd3b67..cec73e3ef6f 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -380,13 +380,8 @@ void transmit_message(struct k_work *tx_job) channel = sTransmitFrame.mChannel; - radio_api->set_channel(radio_dev, sTransmitFrame.mChannel); - -#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER) - net_pkt_set_ieee802154_txpwr(tx_pkt, get_transmit_power_for_channel(channel)); -#else + radio_api->set_channel(radio_dev, channel); radio_api->set_txpower(radio_dev, get_transmit_power_for_channel(channel)); -#endif /* CONFIG_IEEE802154_SELECTIVE_TXPOWER */ net_pkt_set_ieee802154_frame_secured(tx_pkt, sTransmitFrame.mInfo.mTxInfo.mIsSecurityProcessed); From c46683f948d3b1f1c632b2424d3fb836b36706b8 Mon Sep 17 00:00:00 2001 From: Eduardo Montoya Date: Tue, 31 Oct 2023 10:24:18 +0100 Subject: [PATCH 1024/1623] [nrf fromtree] drivers: ieee802154: nrf: cache radio channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cache configured radio channel and apply them only when a relevant radio task is requested. This allows to configure the channel in the transmit metadata, thus avoiding unneeded `nrf_802154` API calls in some scenarios. Signed-off-by: Eduardo Montoya Signed-off-by: Jędrzej Ciupis (cherry picked from commit 780b12854c11f10f6b3e4b21ae02eaa1b2965736) --- drivers/ieee802154/ieee802154_nrf5.c | 18 ++++++++++++++++-- drivers/ieee802154/ieee802154_nrf5.h | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index a43a1b44471..891517a2a0f 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -254,6 +254,8 @@ static int nrf5_cca(const struct device *dev) { struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev); + nrf_802154_channel_set(nrf5_data.channel); + if (!nrf_802154_cca()) { LOG_DBG("CCA failed"); return -EBUSY; @@ -279,7 +281,7 @@ static int nrf5_set_channel(const struct device *dev, uint16_t channel) return channel < 11 ? -ENOTSUP : -EINVAL; } - nrf_802154_channel_set(channel); + nrf5_data.channel = channel; return 0; } @@ -292,6 +294,8 @@ static int nrf5_energy_scan_start(const struct device *dev, ARG_UNUSED(dev); + nrf_802154_channel_set(nrf5_data.channel); + if (nrf5_data.energy_scan_done == NULL) { nrf5_data.energy_scan_done = done_cb; @@ -457,6 +461,10 @@ static bool nrf5_tx_immediate(struct net_pkt *pkt, uint8_t *payload, bool cca) .use_metadata_value = true, .power = nrf5_data.txpwr, }, + .tx_channel = { + .use_metadata_value = true, + .channel = nrf5_data.channel, + }, }; return nrf_802154_transmit_raw(payload, &metadata); @@ -474,6 +482,10 @@ static bool nrf5_tx_csma_ca(struct net_pkt *pkt, uint8_t *payload) .use_metadata_value = true, .power = nrf5_data.txpwr, }, + .tx_channel = { + .use_metadata_value = true, + .channel = nrf5_data.channel, + }, }; return nrf_802154_transmit_csma_ca_raw(payload, &metadata); @@ -513,7 +525,7 @@ static bool nrf5_tx_at(struct nrf5_802154_data *nrf5_radio, struct net_pkt *pkt, .dynamic_data_is_set = net_pkt_ieee802154_mac_hdr_rdy(pkt), }, .cca = cca, - .channel = nrf_802154_channel_get(), + .channel = nrf5_data.channel, .tx_power = { .use_metadata_value = true, .power = nrf5_data.txpwr, @@ -655,6 +667,7 @@ static int nrf5_start(const struct device *dev) ARG_UNUSED(dev); nrf_802154_tx_power_set(nrf5_data.txpwr); + nrf_802154_channel_set(nrf5_data.channel); if (!nrf_802154_receive()) { LOG_ERR("Failed to enter receive state"); @@ -699,6 +712,7 @@ static int nrf5_continuous_carrier(const struct device *dev) ARG_UNUSED(dev); nrf_802154_tx_power_set(nrf5_data.txpwr); + nrf_802154_channel_set(nrf5_data.channel); if (!nrf_802154_continuous_carrier()) { LOG_ERR("Failed to enter continuous carrier state"); diff --git a/drivers/ieee802154/ieee802154_nrf5.h b/drivers/ieee802154/ieee802154_nrf5.h index 79b47827d72..b9f46dff307 100644 --- a/drivers/ieee802154/ieee802154_nrf5.h +++ b/drivers/ieee802154/ieee802154_nrf5.h @@ -100,6 +100,9 @@ struct nrf5_802154_data { /* The TX power in dBm. */ int8_t txpwr; + /* The radio channel. */ + uint8_t channel; + #if defined(CONFIG_NRF_802154_SER_HOST) && defined(CONFIG_IEEE802154_CSL_ENDPOINT) /* The last configured value of CSL period in units of 10 symbols. */ uint32_t csl_period; From 440b2b6a935365f1a0a4790d69ee1dc40b59306b Mon Sep 17 00:00:00 2001 From: Eduardo Montoya Date: Tue, 31 Oct 2023 10:23:51 +0100 Subject: [PATCH 1025/1623] [nrf fromtree] drivers: ieee802154: nrf5: add `IEEE802154_RX_ON_WHEN_IDLE` capability Add `IEEE802154_RX_ON_WHEN_IDLE` capability. Signed-off-by: Eduardo Montoya (cherry picked from commit 586eca8ad27951727440c61e7fcaf4e67eb4502c) --- drivers/ieee802154/ieee802154_nrf5.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index 891517a2a0f..6cbeb6ee2af 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -236,6 +236,7 @@ static void nrf5_get_capabilities_at_boot(void) ((caps & NRF_802154_CAPABILITY_DELAYED_TX) ? IEEE802154_HW_TXTIME : 0UL) | ((caps & NRF_802154_CAPABILITY_DELAYED_RX) ? IEEE802154_HW_RXTIME : 0UL) | IEEE802154_HW_SLEEP_TO_TX | + IEEE802154_RX_ON_WHEN_IDLE | ((caps & NRF_802154_CAPABILITY_SECURITY) ? IEEE802154_HW_TX_SEC : 0UL) #if defined(CONFIG_IEEE802154_NRF5_MULTIPLE_CCA) | IEEE802154_OPENTHREAD_HW_MULTIPLE_CCA @@ -1000,6 +1001,10 @@ static int nrf5_configure(const struct device *dev, break; #endif /* CONFIG_IEEE802154_NRF5_MULTIPLE_CCA */ + case IEEE802154_CONFIG_RX_ON_WHEN_IDLE: + nrf_802154_rx_on_when_idle_set(config->rx_on_when_idle); + break; + default: return -EINVAL; } @@ -1077,20 +1082,8 @@ void nrf_802154_receive_failed(nrf_802154_rx_error_t error, uint32_t id) const struct device *dev = nrf5_get_device(); #if defined(CONFIG_IEEE802154_CSL_ENDPOINT) - if (id == DRX_SLOT_RX) { - __ASSERT_NO_MSG(nrf5_data.event_handler); -#if !defined(CONFIG_IEEE802154_CSL_DEBUG) - /* When CSL debug option is used we intentionally avoid notifying the higher layer - * about the finalization of a DRX slot, so that the radio stays in receive state - * for receiving "out of slot" frames. - * As a side effect, regular failure notifications would be reported with the - * incorrect ID. - */ - nrf5_data.event_handler(dev, IEEE802154_EVENT_RX_OFF, NULL); -#endif - if (error == NRF_802154_RX_ERROR_DELAYED_TIMEOUT) { - return; - } + if (id == DRX_SLOT_RX && error == NRF_802154_RX_ERROR_DELAYED_TIMEOUT) { + return; } #else ARG_UNUSED(id); From c2784307ce7f6016105eddf47f786b913ec1cfb3 Mon Sep 17 00:00:00 2001 From: Mirko Covizzi Date: Fri, 12 Jan 2024 17:21:22 +0100 Subject: [PATCH 1026/1623] [nrf fromtree] net: sockets: prevent null pointer dereference According to the POSIX specification, null pointer is a valid value for the `address` argument of the `accept` function. This commit adds a check to prevent a null pointer dereference inside `z_impl_zsock_accept`. Signed-off-by: Mirko Covizzi (cherry picked from commit f3b2c04661370ac595faf32d2cafb43506704671) --- subsys/net/lib/sockets/sockets.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index d35317352c9..060c7fff8f7 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -681,7 +681,9 @@ int z_impl_zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen) new_sock = VTABLE_CALL(accept, sock, addr, addrlen); - (void)sock_obj_core_alloc_find(sock, new_sock, addr->sa_family, SOCK_STREAM); + if (addr) { + (void)sock_obj_core_alloc_find(sock, new_sock, addr->sa_family, SOCK_STREAM); + } return new_sock; } From 195291f95f6ba354b0d8e33cd370c27f3991dd19 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Mon, 13 Nov 2023 13:33:58 +0200 Subject: [PATCH 1027/1623] [nrf fromtree] test: lwm2m: Mark some tests as slow This allows quick filtering with pytest_args: ['-k not slow'] Signed-off-by: Seppo Takalo (cherry picked from commit eb127538b10e792179d60ca7124e9f41571e487c) --- tests/net/lib/lwm2m/interop/pytest/pytest.ini | 3 +++ tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py | 9 +++++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/net/lib/lwm2m/interop/pytest/pytest.ini diff --git a/tests/net/lib/lwm2m/interop/pytest/pytest.ini b/tests/net/lib/lwm2m/interop/pytest/pytest.ini new file mode 100644 index 00000000000..761785364d8 --- /dev/null +++ b/tests/net/lib/lwm2m/interop/pytest/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +markers = + slow: marks tests as slow (deselect with '-m "not slow"') diff --git a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py index 8f3acd69c7e..c37a3900aa6 100644 --- a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py +++ b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py @@ -51,6 +51,7 @@ def test_LightweightM2M_1_1_int_104(shell: Shell, dut: DeviceAdapter, leshan: Le leshan.execute(endpoint, '1/0/8') dut.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=5.0) +@pytest.mark.slow def test_LightweightM2M_1_1_int_107(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-107 - Extending the lifetime of a registration""" leshan.write(endpoint, '1/0/1', 120) @@ -66,6 +67,7 @@ def test_LightweightM2M_1_1_int_108(leshan, endpoint): """LightweightM2M-1.1-int-108 - Turn on Queue Mode""" assert leshan.get(f'/clients/{endpoint}')["queuemode"] +@pytest.mark.slow def test_LightweightM2M_1_1_int_109(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-109 - Behavior in Queue Mode""" logger.debug('Wait for Queue RX OFF') @@ -500,6 +502,7 @@ def test_LightweightM2M_1_1_int_281(shell: Shell, leshan: Leshan, endpoint: str) # Information Reporting Interface [300-399] # +@pytest.mark.slow def test_LightweightM2M_1_1_int_301(shell: Shell, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-301 - Observation and Notification of parameter values""" pwr_src = leshan.read(endpoint, '3/0/6') @@ -527,6 +530,7 @@ def test_LightweightM2M_1_1_int_301(shell: Shell, leshan: Leshan, endpoint: str) assert (start + 15) <= time.time() + 1 # Allow 1 second slack. (pMinx + pMax=15) leshan.cancel_observe(endpoint, '3/0/7') +@pytest.mark.slow def test_LightweightM2M_1_1_int_302(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-302 - Cancel Observations using Reset Operation""" leshan.observe(endpoint, '3/0/7') @@ -546,6 +550,7 @@ def test_LightweightM2M_1_1_int_302(shell: Shell, dut: DeviceAdapter, leshan: Le shell.exec_command('lwm2m write /3/0/8/0 -u32 50') dut.readlines_until(regex=r'.*Observer removed for 3/0/8') +@pytest.mark.slow def test_LightweightM2M_1_1_int_304(shell: Shell, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-304 - Observe-Composite Operation""" assert leshan.put_raw(f'/clients/{endpoint}/1/0/1/attributes?pmin=30')['status'] == 'CHANGED(204)' @@ -590,6 +595,8 @@ def test_LightweightM2M_1_1_int_307(shell: Shell, dut: DeviceAdapter, leshan: Le shell.exec_command('lwm2m send /3/0') dut.readlines_until(regex=r'.*SEND status: 0', timeout=5.0) + +@pytest.mark.slow def test_LightweightM2M_1_1_int_308(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-308 - Observe-Composite and Creating Object Instance""" shell.exec_command('lwm2m delete /16/0') @@ -631,6 +638,7 @@ def test_LightweightM2M_1_1_int_308(shell: Shell, dut: DeviceAdapter, leshan: Le shell.exec_command('lwm2m write 1/0/2 -u32 1') shell.exec_command('lwm2m write 1/0/3 -u32 10') +@pytest.mark.slow def test_LightweightM2M_1_1_int_309(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-309 - Observe-Composite and Deleting Object Instance""" shell.exec_command('lwm2m delete /16/0') @@ -673,6 +681,7 @@ def test_LightweightM2M_1_1_int_309(shell: Shell, dut: DeviceAdapter, leshan: Le shell.exec_command('lwm2m write 1/0/2 -u32 1') shell.exec_command('lwm2m write 1/0/3 -u32 10') +@pytest.mark.slow def test_LightweightM2M_1_1_int_310(shell: Shell, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-310 - Observe-Composite and modification of parameter values""" # Need to use Configuration C.1 From 1f4da8e3d3d31db845cf7df983e031b5211fa7aa Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Mon, 13 Nov 2023 16:02:07 +0200 Subject: [PATCH 1028/1623] [nrf fromtree] test: lwm2m: Implement write_attributes() Implement write and remove attributes command for Leshan. Remove all written attributes at the end of test, so it won't affect the next test case. Remove skip marks from testcase that is fixed on Leshan side. Signed-off-by: Seppo Takalo (cherry picked from commit 92ceaab491a0a579a585b55c85d66673bceb7ea6) --- tests/net/lib/lwm2m/interop/README.md | 2 +- tests/net/lib/lwm2m/interop/pytest/leshan.py | 19 ++++++- .../lib/lwm2m/interop/pytest/test_lwm2m.py | 56 ++++++++++--------- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/tests/net/lib/lwm2m/interop/README.md b/tests/net/lib/lwm2m/interop/README.md index bda38924d26..3654ca94b01 100644 --- a/tests/net/lib/lwm2m/interop/README.md +++ b/tests/net/lib/lwm2m/interop/README.md @@ -167,7 +167,7 @@ Tests are written from test spec; |LightweightM2M-1.1-int-256 - Write Operation Failure|:white_check_mark:| | |LightweightM2M-1.1-int-257 - Write-Composite Operation|:white_check_mark:| | |LightweightM2M-1.1-int-260 - Discover Command|:white_check_mark:| | -|LightweightM2M-1.1-int-261 - Write-Attribute Operation on a multiple resource|:large_orange_diamond:|Leshan don't allow writing attributes to resource instance| +|LightweightM2M-1.1-int-261 - Write-Attribute Operation on a multiple resource|:white_check_mark:| | |LightweightM2M-1.1-int-280 - Successful Read-Composite Operation|:white_check_mark:| | |LightweightM2M-1.1-int-281 - Partially Successful Read-Composite Operation|:white_check_mark:| | |LightweightM2M-1.1-int-301 - Observation and Notification of parameter values|:white_check_mark:| | diff --git a/tests/net/lib/lwm2m/interop/pytest/leshan.py b/tests/net/lib/lwm2m/interop/pytest/leshan.py index 7240aae2baf..4add988ea77 100644 --- a/tests/net/lib/lwm2m/interop/pytest/leshan.py +++ b/tests/net/lib/lwm2m/interop/pytest/leshan.py @@ -62,9 +62,9 @@ def get(self, path: str): resp = self._s.get(f'{self.api_url}{path}', params=params, timeout=self.timeout) return Leshan.handle_response(resp) - def put_raw(self, path: str, data: str | dict | None = None, headers: dict | None = None): + def put_raw(self, path: str, data: str | dict | None = None, headers: dict | None = None, params: dict | None = None): """Send HTTP PUT query without any default parameters""" - resp = self._s.put(f'{self.api_url}{path}', data=data, headers=headers, timeout=self.timeout) + resp = self._s.put(f'{self.api_url}{path}', data=data, headers=headers, params=params, timeout=self.timeout) return Leshan.handle_response(resp) def put(self, path: str, data: str | dict, uri_options: str = ''): @@ -108,6 +108,21 @@ def write(self, endpoint: str, path: str, value: bool | int | str): rid = path.split('/')[-1] return self.put(f'/clients/{endpoint}/{path}', self._define_resource(rid, value, kind)) + def write_attributes(self, endpoint: str, path: str, attributes: dict): + """Send LwM2M Write-Attributes to given path + example: + leshan.write_attributes(endpoint, '1/2/3, {'pmin': 10, 'pmax': 40}) + """ + return self.put_raw(f'/clients/{endpoint}/{path}/attributes', params=attributes) + + def remove_attributes(self, endpoint: str, path: str, attributes: list): + """Send LwM2M Write-Attributes to given path + example: + leshan.remove_attributes(endpoint, '1/2/3, ['pmin', 'pmax']) + """ + attrs = '&'.join(attributes) + return self.put_raw(f'/clients/{endpoint}/{path}/attributes?'+ attrs) + def update_obj_instance(self, endpoint: str, path: str, resources: dict): """Update object instance""" data = self._define_obj_inst(path, resources) diff --git a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py index c37a3900aa6..f596f74d30a 100644 --- a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py +++ b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py @@ -202,7 +202,7 @@ def test_LightweightM2M_1_1_int_221(shell: Shell, leshan: Leshan, endpoint: str) """LightweightM2M-1.1-int-221 - Attempt to perform operations on Security""" assert leshan.read(endpoint, '0/0')['status'] == 'UNAUTHORIZED(401)' assert leshan.write(endpoint, '0/0/0', 'coap://localhost')['status'] == 'UNAUTHORIZED(401)' - assert leshan.put_raw(f'/clients/{endpoint}/0/attributes?pmin=10')['status'] == 'UNAUTHORIZED(401)' + assert leshan.write_attributes(endpoint, '0', {'pmin':10})['status'] == 'UNAUTHORIZED(401)' def test_LightweightM2M_1_1_int_222(shell: Shell, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-222 - Read on Object""" @@ -429,15 +429,12 @@ def test_LightweightM2M_1_1_int_260(shell: Shell, leshan: Leshan, endpoint: str) expected_keys = ['/3', '/3/0', '/3/0/1', '/3/0/2', '/3/0/3', '/3/0/4', '/3/0/6', '/3/0/7', '/3/0/8', '/3/0/9', '/3/0/11', '/3/0/16'] missing_keys = [key for key in expected_keys if key not in resp.keys()] assert len(missing_keys) == 0 - assert leshan.put_raw(f'/clients/{endpoint}/3/attributes?pmin=10')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/3/attributes?pmax=200')['status'] == 'CHANGED(204)' + assert leshan.write_attributes(endpoint, '3', {'pmin': 10, 'pmax': 200})['status'] == 'CHANGED(204)' resp = leshan.discover(endpoint, '3/0') assert int(resp['/3/0/6']['dim']) == 2 assert int(resp['/3/0/7']['dim']) == 2 assert int(resp['/3/0/8']['dim']) == 2 - assert leshan.put_raw(f'/clients/{endpoint}/3/0/7/attributes?lt=1')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/3/0/7/attributes?gt=6')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/3/0/7/attributes?st=1')['status'] == 'CHANGED(204)' + assert leshan.write_attributes(endpoint, '3/0/7', {'lt': 1, 'gt': 6, 'st': 1})['status'] == 'CHANGED(204)' resp = leshan.discover(endpoint, '3/0') expected_keys = ['/3/0', '/3/0/1', '/3/0/2', '/3/0/3', '/3/0/4', '/3/0/6', '/3/0/7', '/3/0/8', '/3/0/9', '/3/0/11', '/3/0/16'] missing_keys = [key for key in expected_keys if key not in resp.keys()] @@ -451,8 +448,9 @@ def test_LightweightM2M_1_1_int_260(shell: Shell, leshan: Leshan, endpoint: str) missing_keys = [key for key in expected_keys if key not in resp.keys()] assert len(missing_keys) == 0 assert len(resp) == len(expected_keys) + # restore + leshan.remove_attributes(endpoint, '3', ['pmin', 'pmax']) -@pytest.mark.skip(reason="Leshan don't allow writing attributes to resource instance") def test_LightweightM2M_1_1_int_261(shell: Shell, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-261 - Write-Attribute Operation on a multiple resource""" resp = leshan.discover(endpoint, '3/0/11') @@ -462,19 +460,20 @@ def test_LightweightM2M_1_1_int_261(shell: Shell, leshan: Leshan, endpoint: str) assert len(missing_keys) == 0 assert len(resp) == len(expected_keys) assert int(resp['/3/0/11']['dim']) == 1 - assert leshan.put_raw(f'/clients/{endpoint}/3/attributes?pmin=10')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/3/attributes?pmax=200')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/3/0/attributes?pmax=320')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/3/0/11/0/attributes?pmax=100')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/3/0/11/0/attributes?epmin=1')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/3/0/11/0/attributes?epmax=20')['status'] == 'CHANGED(204)' + assert leshan.write_attributes(endpoint, '3', {'pmin':10, 'pmax':200})['status'] == 'CHANGED(204)' + assert leshan.write_attributes(endpoint, '3/0', {'pmax':320})['status'] == 'CHANGED(204)' + assert leshan.write_attributes(endpoint, '3/0/11/0', {'pmax':100, 'epmin':1, 'epmax':20})['status'] == 'CHANGED(204)' resp = leshan.discover(endpoint, '3/0/11') logger.debug(resp) assert int(resp['/3/0/11']['pmin']) == 10 assert int(resp['/3/0/11']['pmax']) == 320 assert int(resp['/3/0/11/0']['pmax']) == 100 - assert int(resp['/3/0/11/0']['epmin']) == 1 - assert int(resp['/3/0/11/0']['epmax']) == 20 + # Note: Zephyr does not support epmin&epmax. + # Restore + leshan.remove_attributes(endpoint, '3', ['pmin', 'pmax']) + leshan.remove_attributes(endpoint, '3/0', ['pmax']) + leshan.remove_attributes(endpoint, '3/0/11/0', ['pmax']) + def test_LightweightM2M_1_1_int_280(shell: Shell, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-280 - Successful Read-Composite Operation""" @@ -509,8 +508,7 @@ def test_LightweightM2M_1_1_int_301(shell: Shell, leshan: Leshan, endpoint: str) logger.debug(pwr_src) assert pwr_src[6][0] == 1 assert pwr_src[6][1] == 5 - assert leshan.put_raw(f'/clients/{endpoint}/3/0/7/attributes?pmin=5')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/3/0/7/attributes?pmax=10')['status'] == 'CHANGED(204)' + assert leshan.write_attributes(endpoint, '3/0/7', {'pmin': 5, 'pmax': 10})['status'] == 'CHANGED(204)' leshan.observe(endpoint, '3/0/7') with leshan.get_event_stream(endpoint, timeout=30) as events: shell.exec_command('lwm2m write /3/0/7/0 -u32 3000') @@ -529,6 +527,7 @@ def test_LightweightM2M_1_1_int_301(shell: Shell, leshan: Leshan, endpoint: str) assert data[3][0][7][0] == 3500 assert (start + 15) <= time.time() + 1 # Allow 1 second slack. (pMinx + pMax=15) leshan.cancel_observe(endpoint, '3/0/7') + leshan.remove_attributes(endpoint, '3/0/7', ['pmin', 'pmax']) @pytest.mark.slow def test_LightweightM2M_1_1_int_302(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): @@ -553,8 +552,10 @@ def test_LightweightM2M_1_1_int_302(shell: Shell, dut: DeviceAdapter, leshan: Le @pytest.mark.slow def test_LightweightM2M_1_1_int_304(shell: Shell, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-304 - Observe-Composite Operation""" - assert leshan.put_raw(f'/clients/{endpoint}/1/0/1/attributes?pmin=30')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/1/0/1/attributes?pmax=45')['status'] == 'CHANGED(204)' + # Need to use Configuration C.1 + shell.exec_command('lwm2m write 1/0/2 -u32 0') + shell.exec_command('lwm2m write 1/0/3 -u32 0') + assert leshan.write_attributes(endpoint, '1/0/1', {'pmin': 30, 'pmax': 45})['status'] == 'CHANGED(204)' data = leshan.composite_observe(endpoint, ['/1/0/1', '/3/0/11/0', '/3/0/16']) assert data[1][0][1] is not None assert data[3][0][11][0] is not None @@ -575,6 +576,10 @@ def test_LightweightM2M_1_1_int_304(shell: Shell, leshan: Leshan, endpoint: str) assert (start + 30) < time.time() assert (start + 45) > time.time() - 1 leshan.cancel_composite_observe(endpoint, ['/1/0/1', '/3/0/11/0', '/3/0/16']) + # Restore configuration C.3 + shell.exec_command('lwm2m write 1/0/2 -u32 1') + shell.exec_command('lwm2m write 1/0/3 -u32 10') + leshan.remove_attributes(endpoint, '1/0/1', ['pmin', 'pmax']) def test_LightweightM2M_1_1_int_306(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-306 - Send Operation""" @@ -620,8 +625,7 @@ def test_LightweightM2M_1_1_int_308(shell: Shell, dut: DeviceAdapter, leshan: Le content_both = {16: {0: resources_a, 1: resources_b}} assert leshan.create_obj_instance(endpoint, '16/0', resources_a)['status'] == 'CREATED(201)' dut.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=5.0) - assert leshan.put_raw(f'/clients/{endpoint}/16/0/attributes?pmin=30')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/16/0/attributes?pmax=45')['status'] == 'CHANGED(204)' + assert leshan.write_attributes(endpoint, '16/0', {'pmin': 30, 'pmax': 45})['status'] == 'CHANGED(204)' data = leshan.composite_observe(endpoint, ['/16/0', '/16/1']) assert data == content_one with leshan.get_event_stream(endpoint, timeout=50) as events: @@ -637,6 +641,7 @@ def test_LightweightM2M_1_1_int_308(shell: Shell, dut: DeviceAdapter, leshan: Le # Restore configuration C.3 shell.exec_command('lwm2m write 1/0/2 -u32 1') shell.exec_command('lwm2m write 1/0/3 -u32 10') + leshan.remove_attributes(endpoint, '16/0', ['pmin','pmax']) @pytest.mark.slow def test_LightweightM2M_1_1_int_309(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): @@ -663,8 +668,7 @@ def test_LightweightM2M_1_1_int_309(shell: Shell, dut: DeviceAdapter, leshan: Le assert leshan.create_obj_instance(endpoint, '16/0', resources_a)['status'] == 'CREATED(201)' assert leshan.create_obj_instance(endpoint, '16/1', resources_b)['status'] == 'CREATED(201)' dut.readlines_until(regex='.*net_lwm2m_rd_client: Update Done', timeout=5.0) - assert leshan.put_raw(f'/clients/{endpoint}/16/0/attributes?pmin=30')['status'] == 'CHANGED(204)' - assert leshan.put_raw(f'/clients/{endpoint}/16/0/attributes?pmax=45')['status'] == 'CHANGED(204)' + assert leshan.write_attributes(endpoint, '16/0', {'pmin': 30, 'pmax': 45})['status'] == 'CHANGED(204)' data = leshan.composite_observe(endpoint, ['/16/0', '/16/1']) assert data == content_both with leshan.get_event_stream(endpoint, timeout=50) as events: @@ -680,6 +684,7 @@ def test_LightweightM2M_1_1_int_309(shell: Shell, dut: DeviceAdapter, leshan: Le # Restore configuration C.3 shell.exec_command('lwm2m write 1/0/2 -u32 1') shell.exec_command('lwm2m write 1/0/3 -u32 10') + leshan.remove_attributes(endpoint, '16/0', ['pmin', 'pmax']) @pytest.mark.slow def test_LightweightM2M_1_1_int_310(shell: Shell, leshan: Leshan, endpoint: str): @@ -687,11 +692,9 @@ def test_LightweightM2M_1_1_int_310(shell: Shell, leshan: Leshan, endpoint: str) # Need to use Configuration C.1 shell.exec_command('lwm2m write 1/0/2 -u32 0') shell.exec_command('lwm2m write 1/0/3 -u32 0') - # Ensure that our previous attributes are not conflicting - assert leshan.put_raw(f'/clients/{endpoint}/3/attributes?pmin=0')['status'] == 'CHANGED(204)' leshan.composite_observe(endpoint, ['/1/0/1', '/3/0']) with leshan.get_event_stream(endpoint, timeout=50) as events: - assert leshan.put_raw(f'/clients/{endpoint}/3/attributes?pmax=5')['status'] == 'CHANGED(204)' + assert leshan.write_attributes(endpoint, '3', {'pmax': 5})['status'] == 'CHANGED(204)' start = time.time() data = events.next_event('NOTIFICATION') assert data[3][0][0] == 'Zephyr' @@ -704,6 +707,7 @@ def test_LightweightM2M_1_1_int_310(shell: Shell, leshan: Leshan, endpoint: str) # Restore configuration C.3 shell.exec_command('lwm2m write 1/0/2 -u32 1') shell.exec_command('lwm2m write 1/0/3 -u32 10') + leshan.remove_attributes(endpoint, '3', ['pmax']) def test_LightweightM2M_1_1_int_311(shell: Shell, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-311 - Send command""" From 913d9a36ff76cc8c01e7d68228ff13519ac27a12 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Mon, 13 Nov 2023 16:36:03 +0200 Subject: [PATCH 1029/1623] [nrf fromtree] test: lwm2m: Implement Read-Composite Operation on root path Test case: LightweightM2M-1.1-int-235 - Read-Composite Operation on root path is now working as Leshan added a support for reading the root path. Signed-off-by: Seppo Takalo (cherry picked from commit 2135e009e4d9dbc77a9083313705236708868dad) --- tests/net/lib/lwm2m/interop/README.md | 2 +- tests/net/lib/lwm2m/interop/pytest/leshan.py | 4 ++++ tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py | 7 +++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/net/lib/lwm2m/interop/README.md b/tests/net/lib/lwm2m/interop/README.md index 3654ca94b01..204aff636ac 100644 --- a/tests/net/lib/lwm2m/interop/README.md +++ b/tests/net/lib/lwm2m/interop/README.md @@ -160,7 +160,7 @@ Tests are written from test spec; |LightweightM2M-1.1-int-232 - Querying basic information in SenML CBOR format|:white_check_mark:| | |LightweightM2M-1.1-int-233 - Setting basic information in SenML CBOR format|:white_check_mark:| | |LightweightM2M-1.1-int-234 - Setting basic information in SenML JSON format|:white_check_mark:| | -|LightweightM2M-1.1-int-235 - Read-Composite Operation on root path|:large_orange_diamond:|Root Path is not yet supported by Leshan.| +|LightweightM2M-1.1-int-235 - Read-Composite Operation on root path|:white_check_mark:| | |LightweightM2M-1.1-int-236 - Read-Composite - Partial Presence|:white_check_mark:| | |LightweightM2M-1.1-int-237 - Read on Object without specifying Content-Type|:white_check_mark:| | |LightweightM2M-1.1-int-241 - Executable Resource: Rebooting the device|:white_check_mark:| | diff --git a/tests/net/lib/lwm2m/interop/pytest/leshan.py b/tests/net/lib/lwm2m/interop/pytest/leshan.py index 4add988ea77..65295e652bc 100644 --- a/tests/net/lib/lwm2m/interop/pytest/leshan.py +++ b/tests/net/lib/lwm2m/interop/pytest/leshan.py @@ -271,6 +271,10 @@ def parse_composite(cls, payload: dict): raise RuntimeError(f'No content received') payload = payload['content'] for path, content in payload.items(): + if path == "/": + for obj in content['objects']: + data.update(cls._decode_obj(obj)) + continue keys = [int(key) for key in path.lstrip("/").split('/')] if len(keys) == 1: data.update(cls._decode_obj(content)) diff --git a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py index f596f74d30a..eabc4bbc614 100644 --- a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py +++ b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py @@ -367,9 +367,12 @@ def test_LightweightM2M_1_1_int_234(shell: Shell, leshan: Leshan, endpoint: str) """LightweightM2M-1.1-int-234 - Setting basic information in SenML JSON format""" setting_basic_senml(shell, leshan, endpoint, 'SENML_JSON') -@pytest.mark.skip("Leshan does not allow reading root path") -def test_LightweightM2M_1_1_int_235(): +def test_LightweightM2M_1_1_int_235(leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-235 - Read-Composite Operation on root path""" + resp = leshan.composite_read(endpoint, ['/']) + expected_keys = [16, 1, 3, 5] + missing_keys = [key for key in expected_keys if key not in resp.keys()] + assert len(missing_keys) == 0 def test_LightweightM2M_1_1_int_236(shell: Shell, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-236 - Read-Composite - Partial Presence""" From b120890dddda2eb725ed66d78fa815126d972d65 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Mon, 20 Nov 2023 16:14:07 +0200 Subject: [PATCH 1030/1623] [nrf fromtree] test: lwm2m: Test cancellation using observe parameter Implement test cases: LightweightM2M-1.1-int-303 - Cancel observations using Observe with Cancel parameter LightweightM2M-1.1-int-305 - Cancel Observation-Composite Operation Modify existing Leshan API to passive_cancel(). Signed-off-by: Seppo Takalo (cherry picked from commit 31e9a5674267dbc3efc717f15bf601a2e064d1ec) --- tests/net/lib/lwm2m/interop/README.md | 4 +-- tests/net/lib/lwm2m/interop/pytest/leshan.py | 7 +++++ .../lib/lwm2m/interop/pytest/test_lwm2m.py | 30 +++++++++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/tests/net/lib/lwm2m/interop/README.md b/tests/net/lib/lwm2m/interop/README.md index 204aff636ac..3acbfcc71f8 100644 --- a/tests/net/lib/lwm2m/interop/README.md +++ b/tests/net/lib/lwm2m/interop/README.md @@ -172,9 +172,9 @@ Tests are written from test spec; |LightweightM2M-1.1-int-281 - Partially Successful Read-Composite Operation|:white_check_mark:| | |LightweightM2M-1.1-int-301 - Observation and Notification of parameter values|:white_check_mark:| | |LightweightM2M-1.1-int-302 - Cancel Observations using Reset Operation|:white_check_mark:| | -|LightweightM2M-1.1-int-303 - Cancel observations using Observe with Cancel parameter|:large_orange_diamond:|Leshan only supports passive cancelling| +|LightweightM2M-1.1-int-303 - Cancel observations using Observe with Cancel parameter|:white_check_mark:|| |LightweightM2M-1.1-int-304 - Observe-Composite Operation|:white_check_mark:| | -|LightweightM2M-1.1-int-305 - Cancel Observation-Composite Operation|:large_orange_diamond:|Leshan only supports passive cancelling| +|LightweightM2M-1.1-int-305 - Cancel Observation-Composite Operation|:white_check_mark:| | |LightweightM2M-1.1-int-306 – Send Operation|:white_check_mark:|[~~#64290~~](https://github.com/zephyrproject-rtos/zephyr/issues/64290)| |LightweightM2M-1.1-int-307 – Muting Send|:white_check_mark:| | |LightweightM2M-1.1-int-308 - Observe-Composite and Creating Object Instance|:white_check_mark:|[~~#64634~~](https://github.com/zephyrproject-rtos/zephyr/issues/64634)| diff --git a/tests/net/lib/lwm2m/interop/pytest/leshan.py b/tests/net/lib/lwm2m/interop/pytest/leshan.py index 65295e652bc..181f15ebf61 100644 --- a/tests/net/lib/lwm2m/interop/pytest/leshan.py +++ b/tests/net/lib/lwm2m/interop/pytest/leshan.py @@ -389,6 +389,9 @@ def observe(self, endpoint: str, path: str): return self.post(f'/clients/{endpoint}/{path}/observe', data="") def cancel_observe(self, endpoint: str, path: str): + return self.delete_raw(f'/clients/{endpoint}/{path}/observe?active') + + def passive_cancel_observe(self, endpoint: str, path: str): return self.delete_raw(f'/clients/{endpoint}/{path}/observe') def composite_observe(self, endpoint: str, paths: list[str]): @@ -398,6 +401,10 @@ def composite_observe(self, endpoint: str, paths: list[str]): return self.parse_composite(payload) def cancel_composite_observe(self, endpoint: str, paths: list[str]): + paths = [path if path.startswith('/') else '/' + path for path in paths] + return self.delete_raw(f'/clients/{endpoint}/composite/observe?paths=' + ','.join(paths) + '&active') + + def passive_cancel_composite_observe(self, endpoint: str, paths: list[str]): paths = [path if path.startswith('/') else '/' + path for path in paths] return self.delete_raw(f'/clients/{endpoint}/composite/observe?paths=' + ','.join(paths)) diff --git a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py index eabc4bbc614..131acb68e14 100644 --- a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py +++ b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py @@ -532,7 +532,6 @@ def test_LightweightM2M_1_1_int_301(shell: Shell, leshan: Leshan, endpoint: str) leshan.cancel_observe(endpoint, '3/0/7') leshan.remove_attributes(endpoint, '3/0/7', ['pmin', 'pmax']) -@pytest.mark.slow def test_LightweightM2M_1_1_int_302(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-302 - Cancel Observations using Reset Operation""" leshan.observe(endpoint, '3/0/7') @@ -541,17 +540,34 @@ def test_LightweightM2M_1_1_int_302(shell: Shell, dut: DeviceAdapter, leshan: Le shell.exec_command('lwm2m write /3/0/7/0 -u32 4000') data = events.next_event('NOTIFICATION') assert data[3][0][7][0] == 4000 - leshan.cancel_observe(endpoint, '3/0/7') + leshan.passive_cancel_observe(endpoint, '3/0/7') shell.exec_command('lwm2m write /3/0/7/0 -u32 3000') dut.readlines_until(regex=r'.*Observer removed for 3/0/7') with leshan.get_event_stream(endpoint) as events: shell.exec_command('lwm2m write /3/0/8/0 -u32 100') data = events.next_event('NOTIFICATION') assert data[3][0][8][0] == 100 - leshan.cancel_observe(endpoint, '3/0/8') + leshan.passive_cancel_observe(endpoint, '3/0/8') shell.exec_command('lwm2m write /3/0/8/0 -u32 50') dut.readlines_until(regex=r'.*Observer removed for 3/0/8') +def test_LightweightM2M_1_1_int_303(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): + """LightweightM2M-1.1-int-303 - Cancel observations using Observe with Cancel parameter""" + leshan.observe(endpoint, '3/0/7') + leshan.observe(endpoint, '3/0/8') + with leshan.get_event_stream(endpoint) as events: + shell.exec_command('lwm2m write /3/0/7/0 -u32 4000') + data = events.next_event('NOTIFICATION') + assert data[3][0][7][0] == 4000 + leshan.cancel_observe(endpoint, '3/0/7') + dut.readlines_until(regex=r'.*Observer removed for 3/0/7') + with leshan.get_event_stream(endpoint) as events: + shell.exec_command('lwm2m write /3/0/8/0 -u32 100') + data = events.next_event('NOTIFICATION') + assert data[3][0][8][0] == 100 + leshan.cancel_observe(endpoint, '3/0/8') + dut.readlines_until(regex=r'.*Observer removed for 3/0/8') + @pytest.mark.slow def test_LightweightM2M_1_1_int_304(shell: Shell, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-304 - Observe-Composite Operation""" @@ -584,6 +600,14 @@ def test_LightweightM2M_1_1_int_304(shell: Shell, leshan: Leshan, endpoint: str) shell.exec_command('lwm2m write 1/0/3 -u32 10') leshan.remove_attributes(endpoint, '1/0/1', ['pmin', 'pmax']) +def test_LightweightM2M_1_1_int_305(dut: DeviceAdapter, leshan: Leshan, endpoint: str): + """LightweightM2M-1.1-int-305 - Cancel Observation-Composite Operation""" + leshan.composite_observe(endpoint, ['/1/0/1', '/3/0/11/0', '/3/0/16']) + leshan.cancel_composite_observe(endpoint, ['/1/0/1', '/3/0/11/0', '/3/0/16']) + dut.readlines_until(regex=r'.*Observer removed for 1/0/1') + dut.readlines_until(regex=r'.*Observer removed for 3/0/11/0') + dut.readlines_until(regex=r'.*Observer removed for 3/0/16') + def test_LightweightM2M_1_1_int_306(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-306 - Send Operation""" with leshan.get_event_stream(endpoint) as events: From 03aacf0cfc5d2235d5812b0ccd4103c99bc23e5c Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Mon, 20 Nov 2023 13:40:55 +0200 Subject: [PATCH 1031/1623] [nrf fromtree] samples: lwm2m: Add support for Connection Manager Using Connection Manager, it's easy to run lwm2m sample on devices supporting different connectivity technologies (for example, Wi-Fi and LTE). Signed-off-by: Juha Ylinen (cherry picked from commit 637b4b62ee233cb4e3733b0bf65e4b415e41daa1) --- samples/net/lwm2m_client/src/lwm2m-client.c | 78 +++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/samples/net/lwm2m_client/src/lwm2m-client.c b/samples/net/lwm2m_client/src/lwm2m-client.c index 748f654d9ee..a120506639d 100644 --- a/samples/net/lwm2m_client/src/lwm2m-client.c +++ b/samples/net/lwm2m_client/src/lwm2m-client.c @@ -16,6 +16,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #include #include +#include +#include #include "modules.h" #define APP_BANNER "Run LWM2M client" @@ -29,6 +31,10 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #define CLIENT_FIRMWARE_VER "1.0" #define CLIENT_HW_VER "1.0.1" +/* Macros used to subscribe to specific Zephyr NET management events. */ +#define L4_EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED) +#define CONN_LAYER_EVENT_MASK (NET_EVENT_CONN_IF_FATAL_ERROR) + static uint8_t bat_idx = LWM2M_DEVICE_PWR_SRC_TYPE_BAT_INT; static int bat_mv = 3800; static int bat_ma = 125; @@ -52,6 +58,12 @@ BUILD_ASSERT(sizeof(endpoint) <= CONFIG_LWM2M_SECURITY_KEY_SIZE, static struct k_sem quit_lock; +/* Zephyr NET management event callback structures. */ +static struct net_mgmt_event_callback l4_cb; +static struct net_mgmt_event_callback conn_cb; + +static K_SEM_DEFINE(network_connected_sem, 0, 1); + static int device_reboot_cb(uint16_t obj_inst_id, uint8_t *args, uint16_t args_len) { @@ -265,6 +277,47 @@ static void observe_cb(enum lwm2m_observe_event event, } } +static void on_net_event_l4_disconnected(void) +{ + LOG_INF("Disconnected from network"); + lwm2m_engine_pause(); +} + +static void on_net_event_l4_connected(void) +{ + LOG_INF("Connected to network"); + k_sem_give(&network_connected_sem); + lwm2m_engine_resume(); +} + +static void l4_event_handler(struct net_mgmt_event_callback *cb, + uint32_t event, + struct net_if *iface) +{ + switch (event) { + case NET_EVENT_L4_CONNECTED: + LOG_INF("IP Up"); + on_net_event_l4_connected(); + break; + case NET_EVENT_L4_DISCONNECTED: + LOG_INF("IP down"); + on_net_event_l4_disconnected(); + break; + default: + break; + } +} + +static void connectivity_event_handler(struct net_mgmt_event_callback *cb, + uint32_t event, + struct net_if *iface) +{ + if (event == NET_EVENT_CONN_IF_FATAL_ERROR) { + LOG_ERR("Fatal error received from the connectivity layer"); + return; + } +} + int main(void) { uint32_t flags = IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) ? @@ -275,6 +328,31 @@ int main(void) k_sem_init(&quit_lock, 0, K_SEM_MAX_LIMIT); + if (IS_ENABLED(CONFIG_NET_CONNECTION_MANAGER)) { + /* Setup handler for Zephyr NET Connection Manager events. */ + net_mgmt_init_event_callback(&l4_cb, l4_event_handler, L4_EVENT_MASK); + net_mgmt_add_event_callback(&l4_cb); + + /* Setup handler for Zephyr NET Connection Manager Connectivity layer. */ + net_mgmt_init_event_callback(&conn_cb, connectivity_event_handler, + CONN_LAYER_EVENT_MASK); + net_mgmt_add_event_callback(&conn_cb); + + ret = net_if_up(net_if_get_default()); + + if (ret < 0 && ret != -EALREADY) { + LOG_ERR("net_if_up, error: %d", ret); + return ret; + } + + ret = conn_mgr_if_connect(net_if_get_default()); + /* Ignore errors from interfaces not requiring connectivity */ + if (ret == 0) { + LOG_INF("Connecting to network"); + k_sem_take(&network_connected_sem, K_FOREVER); + } + } + ret = lwm2m_setup(); if (ret < 0) { LOG_ERR("Cannot setup LWM2M fields (%d)", ret); From f5555ac8164d085e79bf37ec1e537e47f7c7ea17 Mon Sep 17 00:00:00 2001 From: Andreas Chmielewski Date: Thu, 26 Jan 2023 14:25:46 +0100 Subject: [PATCH 1032/1623] [nrf fromtree] tests: lwm2m_rd_client: Added more fff tests If the rdclient is suspended or deregistered any network errors caused by lwm2m_engine and forwarded by socket_fault handler should not change the rd client state. Signed-off-by: Andreas Chmielewski Signed-off-by: Seppo Takalo (cherry picked from commit 72f7a05a8b51524960a3ea5b7114249b10e715ba) --- .../net/lib/lwm2m/lwm2m_rd_client/src/main.c | 70 +++++++++++++++++++ .../net/lib/lwm2m/lwm2m_rd_client/src/stubs.c | 14 ++++ .../net/lib/lwm2m/lwm2m_rd_client/src/stubs.h | 3 + 3 files changed, 87 insertions(+) diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c b/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c index 931f6f15904..208298512d4 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c @@ -698,3 +698,73 @@ ZTEST(lwm2m_rd_client, test_bootstrap_no_srv_fallback_to_register) zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); } + +ZTEST(lwm2m_rd_client, test_start_stop_ignore_engine_fault) +{ + struct lwm2m_ctx ctx; + + (void)memset(&ctx, 0x0, sizeof(ctx)); + + test_prepare_pending_message_cb(&message_reply_cb_default); + + lwm2m_rd_client_init(); + test_lwm2m_engine_start_service(); + wait_for_service(1); + + lwm2m_engine_context_init_fake.custom_fake = lwm2m_engine_context_init_fake1; + lwm2m_get_bool_fake.custom_fake = lwm2m_get_bool_fake_default; + lwm2m_sprint_ip_addr_fake.custom_fake = lwm2m_sprint_ip_addr_fake_default; + lwm2m_init_message_fake.custom_fake = lwm2m_init_message_fake_default; + coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_created; + coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; + zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, + NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), + NULL); + + coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_deleted; + zassert_true(lwm2m_rd_client_stop(&ctx, lwm2m_event_cb, true) == 0, NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DISCONNECT), NULL); + + int c = show_lwm2m_event_fake.call_count; + + test_throw_network_error_from_engine(EIO); + wait_for_service(10); + zassert_equal(show_lwm2m_event_fake.call_count, c, + "Should not enter any other state and throw an event"); +} + +ZTEST(lwm2m_rd_client, test_start_suspend_ignore_engine_fault) +{ + struct lwm2m_ctx ctx; + + (void)memset(&ctx, 0x0, sizeof(ctx)); + + test_prepare_pending_message_cb(&message_reply_cb_default); + + lwm2m_rd_client_init(); + test_lwm2m_engine_start_service(); + wait_for_service(1); + + lwm2m_engine_context_init_fake.custom_fake = lwm2m_engine_context_init_fake1; + lwm2m_get_bool_fake.custom_fake = lwm2m_get_bool_fake_default; + lwm2m_sprint_ip_addr_fake.custom_fake = lwm2m_sprint_ip_addr_fake_default; + lwm2m_init_message_fake.custom_fake = lwm2m_init_message_fake_default; + coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_created; + coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; + zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, + NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), + NULL); + + coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_deleted; + zassert_true(lwm2m_rd_client_pause() == 0, NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED), NULL); + + int c = show_lwm2m_event_fake.call_count; + + test_throw_network_error_from_engine(EIO); + wait_for_service(10); + zassert_equal(show_lwm2m_event_fake.call_count, c, + "Should not enter any other state and throw an event"); +} diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c index 41789e20340..3cbde9060ce 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c @@ -86,6 +86,10 @@ int lwm2m_get_u32_val(const struct lwm2m_obj_path *path, uint32_t *val) /* subsys/net/lib/lwm2m/lwm2m_engine.h */ DEFINE_FAKE_VALUE_FUNC(int, lwm2m_socket_start, struct lwm2m_ctx *); +int lwm2m_socket_start_fake_fail(struct lwm2m_ctx *client_ctx) +{ + return -1; +} DEFINE_FAKE_VALUE_FUNC(int, lwm2m_socket_close, struct lwm2m_ctx *); DEFINE_FAKE_VALUE_FUNC(int, lwm2m_close_socket, struct lwm2m_ctx *); DEFINE_FAKE_VALUE_FUNC(int, lwm2m_socket_suspend, struct lwm2m_ctx *); @@ -93,6 +97,16 @@ DEFINE_FAKE_VALUE_FUNC(int, lwm2m_security_inst_id_to_index, uint16_t); DEFINE_FAKE_VALUE_FUNC(int, lwm2m_engine_connection_resume, struct lwm2m_ctx *); DEFINE_FAKE_VALUE_FUNC(int, lwm2m_push_queued_buffers, struct lwm2m_ctx *); DEFINE_FAKE_VOID_FUNC(lwm2m_engine_context_init, struct lwm2m_ctx *); +struct lwm2m_ctx *client_ctx_fake; +void lwm2m_engine_context_init_fake1(struct lwm2m_ctx *client_ctx) +{ + client_ctx_fake = client_ctx; +} +void test_throw_network_error_from_engine(int err) +{ + client_ctx_fake->fault_cb(err); +} + DEFINE_FAKE_VOID_FUNC(lwm2m_engine_context_close, struct lwm2m_ctx *); DEFINE_FAKE_VALUE_FUNC(char *, lwm2m_sprint_ip_addr, const struct sockaddr *); char *lwm2m_sprint_ip_addr_fake_default(const struct sockaddr *addr) diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.h b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.h index 620e4d8fc12..1276dd5c109 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.h +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.h @@ -54,6 +54,7 @@ int lwm2m_get_u32_val(const struct lwm2m_obj_path *path, uint32_t *val); /* subsys/net/lib/lwm2m/lwm2m_engine.h */ DECLARE_FAKE_VALUE_FUNC(int, lwm2m_socket_start, struct lwm2m_ctx *); +int lwm2m_socket_start_fake_fail(struct lwm2m_ctx *client_ctx); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_socket_close, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_close_socket, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_socket_suspend, struct lwm2m_ctx *); @@ -61,6 +62,8 @@ DECLARE_FAKE_VALUE_FUNC(int, lwm2m_security_inst_id_to_index, uint16_t); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_engine_connection_resume, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_push_queued_buffers, struct lwm2m_ctx *); DECLARE_FAKE_VOID_FUNC(lwm2m_engine_context_init, struct lwm2m_ctx *); +void lwm2m_engine_context_init_fake1(struct lwm2m_ctx *client_ctx); +void test_throw_network_error_from_engine(int err); DECLARE_FAKE_VOID_FUNC(lwm2m_engine_context_close, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(char *, lwm2m_sprint_ip_addr, const struct sockaddr *); char *lwm2m_sprint_ip_addr_fake_default(const struct sockaddr *addr); From 601069bfb239219ed109c06472dce9b45ec57c6c Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 29 Nov 2023 10:02:10 +0100 Subject: [PATCH 1033/1623] [nrf fromtree] net: lib: coap: Translate handler errors to CoAP response codes The CoAP request handler returns errno codes in the following cases: * ENOENT if no handler found; respond with 4.04 * ENOTSUP if an unknown request code received; respond with 4.00 * EPERM no handler found for the method; respond with 4.05 Signed-off-by: Pieter De Gendt (cherry picked from commit 8252ec7570b7b7182880d2982d70858860156e98) --- subsys/net/lib/coap/coap_server.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/subsys/net/lib/coap/coap_server.c b/subsys/net/lib/coap/coap_server.c index 4b4f1719f46..ac179f5545e 100644 --- a/subsys/net/lib/coap/coap_server.c +++ b/subsys/net/lib/coap/coap_server.c @@ -220,6 +220,19 @@ static int coap_server_process(int sock_fd) COAP_SERVICE_RESOURCE_COUNT(service), options, opt_num, &client_addr, client_addr_len); + /* Translate errors to response codes */ + switch (ret) { + case -ENOENT: + ret = COAP_RESPONSE_CODE_NOT_FOUND; + break; + case -ENOTSUP: + ret = COAP_RESPONSE_CODE_BAD_REQUEST; + break; + case -EPERM: + ret = COAP_RESPONSE_CODE_NOT_ALLOWED; + break; + } + /* Shortcut for replying a code without a body */ if (ret > 0 && type == COAP_TYPE_CON) { /* Minimal sized ack buffer */ From 56595ecd433cfacc8746bd47ac30735abdb68751 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 29 Nov 2023 15:33:19 +0100 Subject: [PATCH 1034/1623] [nrf fromtree] tests: net: lib: coap_server: Do not autostart service B with port 0 A race condition for the test occurs as the service might have started when booting. Do not autostart the service to verify the port stays 0. Signed-off-by: Pieter De Gendt (cherry picked from commit b500f7216e976a6237ff307246d00cf4a1879d20) --- tests/net/lib/coap_server/common/src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/net/lib/coap_server/common/src/main.c b/tests/net/lib/coap_server/common/src/main.c index 7af940c5360..20c4b7c0317 100644 --- a/tests/net/lib/coap_server/common/src/main.c +++ b/tests/net/lib/coap_server/common/src/main.c @@ -48,7 +48,7 @@ COAP_RESOURCE_DEFINE(resource_1, service_A, { }); static uint16_t service_B_port; -COAP_SERVICE_DEFINE(service_B, "b.service.com", &service_B_port, COAP_SERVICE_AUTOSTART); +COAP_SERVICE_DEFINE(service_B, "b.service.com", &service_B_port, 0); static const char * const resource_2_path[] = { "res2", "sub", NULL }; COAP_RESOURCE_DEFINE(resource_2, service_B, { @@ -132,7 +132,7 @@ ZTEST(coap_service, test_COAP_SERVICE_FOREACH) zassert_equal(svc->flags & COAP_SERVICE_AUTOSTART, COAP_SERVICE_AUTOSTART); } else if (svc == &service_B) { have_service_B = 1; - zassert_equal(svc->flags & COAP_SERVICE_AUTOSTART, COAP_SERVICE_AUTOSTART); + zassert_equal(svc->flags & COAP_SERVICE_AUTOSTART, 0); } else if (svc == &service_C) { have_service_C = 1; zassert_equal(svc->flags & COAP_SERVICE_AUTOSTART, 0); From 9dcf2ec3e25f0c7853541c039bd246a0f660e333 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 29 Nov 2023 14:45:53 +0100 Subject: [PATCH 1035/1623] [nrf fromtree] net: lib: coap: Init CoAP service socket fd to -1 Set the static initialiser socket file descriptor to -1 to make sure it is invalid before using coap_service_send. Signed-off-by: Pieter De Gendt (cherry picked from commit 4ff8080b65494eac5525de43dd67e3509de1a697) --- include/zephyr/net/coap_service.h | 4 +++- subsys/net/lib/coap/coap_server.c | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/zephyr/net/coap_service.h b/include/zephyr/net/coap_service.h index 3e3201308b9..377c89a7bef 100644 --- a/include/zephyr/net/coap_service.h +++ b/include/zephyr/net/coap_service.h @@ -57,7 +57,9 @@ struct coap_service { }; #define __z_coap_service_define(_name, _host, _port, _flags, _res_begin, _res_end) \ - static struct coap_service_data coap_service_data_##_name; \ + static struct coap_service_data coap_service_data_##_name = { \ + .sock_fd = -1, \ + }; \ const STRUCT_SECTION_ITERABLE(coap_service, _name) = { \ .name = STRINGIFY(_name), \ .host = _host, \ diff --git a/subsys/net/lib/coap/coap_server.c b/subsys/net/lib/coap/coap_server.c index ac179f5545e..009a0fe0274 100644 --- a/subsys/net/lib/coap/coap_server.c +++ b/subsys/net/lib/coap/coap_server.c @@ -707,9 +707,6 @@ static void coap_server_thread(void *p1, void *p2, void *p3) } COAP_SERVICE_FOREACH(svc) { - /* Init all file descriptors to -1 */ - svc->data->sock_fd = -1; - if (svc->flags & COAP_SERVICE_AUTOSTART) { ret = coap_service_start(svc); if (ret < 0) { From da039ffccc0d0fbb15a702391d0bf2f10a36c427 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 29 Nov 2023 14:57:06 +0100 Subject: [PATCH 1036/1623] [nrf fromtree] net: lib: coap: Fix return value documentation coap_service_start Corrected a return value in the doxygen description for coap_service_start. Signed-off-by: Pieter De Gendt (cherry picked from commit f2a256a4c9db9767cf50dc570e88fe5354047c81) --- include/zephyr/net/coap_service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/net/coap_service.h b/include/zephyr/net/coap_service.h index 377c89a7bef..92a276d0d48 100644 --- a/include/zephyr/net/coap_service.h +++ b/include/zephyr/net/coap_service.h @@ -199,7 +199,7 @@ struct coap_service { * @param service Pointer to CoAP service * @retval 0 in case of success. * @retval -EALREADY in case of an already running service. - * @retval -ENOMEM in case the server has no available context. + * @retval -ENOTSUP in case the server has no valid host and port configuration. */ int coap_service_start(const struct coap_service *service); From 717fb2bcdf37a5eb83dd4d6e1d9fa59ce0120e54 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 29 Nov 2023 14:58:12 +0100 Subject: [PATCH 1037/1623] [nrf fromtree] net: lib: coap: Add coap_service_is_running Add a CoAP service API function to query the running state of the provided service. Signed-off-by: Pieter De Gendt (cherry picked from commit 266181b0825c63adb48acafbb15e42191c4fc3ff) --- include/zephyr/net/coap_service.h | 12 ++++++++++++ subsys/net/lib/coap/coap_server.c | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/zephyr/net/coap_service.h b/include/zephyr/net/coap_service.h index 92a276d0d48..6f038ce61e1 100644 --- a/include/zephyr/net/coap_service.h +++ b/include/zephyr/net/coap_service.h @@ -214,6 +214,18 @@ int coap_service_start(const struct coap_service *service); */ int coap_service_stop(const struct coap_service *service); +/** + * @brief Query the provided @p service running state. + * + * @note This function is suitable for a @p service defined with @ref COAP_SERVICE_DEFINE. + * + * @param service Pointer to CoAP service + * @retval 1 if the service is running + * @retval 0 if the service is stopped + * @retval negative in case of an error. + */ +int coap_service_is_running(const struct coap_service *service); + /** * @brief Send a CoAP message from the provided @p service . * diff --git a/subsys/net/lib/coap/coap_server.c b/subsys/net/lib/coap/coap_server.c index 009a0fe0274..386bc2081bb 100644 --- a/subsys/net/lib/coap/coap_server.c +++ b/subsys/net/lib/coap/coap_server.c @@ -483,6 +483,24 @@ int coap_service_stop(const struct coap_service *service) return ret; } +int coap_service_is_running(const struct coap_service *service) +{ + int ret; + + if (!coap_service_in_section(service)) { + __ASSERT_NO_MSG(false); + return -EINVAL; + } + + k_mutex_lock(&lock, K_FOREVER); + + ret = (service->data->sock_fd < 0) ? 0 : 1; + + k_mutex_unlock(&lock); + + return ret; +} + int coap_service_send(const struct coap_service *service, const struct coap_packet *cpkt, const struct sockaddr *addr, socklen_t addr_len) { From 00b8ca550f27fcef408ec238fb576354e7ec1906 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Fri, 24 Nov 2023 13:40:19 +0200 Subject: [PATCH 1038/1623] [nrf fromtree] net: lwm2m: Allow finding security instance by short ID. Add API to find a security instance ID with given Short Server ID. Signed-off-by: Seppo Takalo (cherry picked from commit 304d920ef1a18fe514eb4ede22b5b0df569dbd0d) --- subsys/net/lib/lwm2m/lwm2m_engine.h | 8 ++++++++ subsys/net/lib/lwm2m/lwm2m_obj_security.c | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.h b/subsys/net/lib/lwm2m/lwm2m_engine.h index 2306fced197..2ea3e583242 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.h +++ b/subsys/net/lib/lwm2m/lwm2m_engine.h @@ -133,6 +133,14 @@ int lwm2m_engine_call_now(k_work_handler_t service); */ int lwm2m_security_inst_id_to_index(uint16_t obj_inst_id); +/** + * @brief Returns the object instance id of the security having ssid given by @p short_id. + * + * @param[in] short_id ssid of the security object + * @return Object instance id or negative in case not found + */ +int lwm2m_security_short_id_to_inst(uint16_t short_id); + /** * @brief Returns the object instance id of the security object instance at @p index * in the security object list. diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_security.c b/subsys/net/lib/lwm2m/lwm2m_obj_security.c index 874925c39d8..00796648634 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_security.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_security.c @@ -212,6 +212,16 @@ int lwm2m_security_index_to_inst_id(int index) return inst[index].obj_inst_id; } +int lwm2m_security_short_id_to_inst(uint16_t short_id) +{ + for (int i = 0; i < MAX_INSTANCE_COUNT; i++) { + if (short_server_id[i] == short_id) { + return inst[i].obj_inst_id; + } + } + return -ENOENT; +} + int lwm2m_security_mode(struct lwm2m_ctx *ctx) { int ret; From 7a29fd1a6439a6db0b4981b68a8c7850317079fc Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Fri, 24 Nov 2023 15:07:10 +0200 Subject: [PATCH 1039/1623] [nrf fromtree] net: lwm2m: Allow disabling server for a period of time React to disable executable, as well as add callback that allows disabling server for a period of time. Also add API that would find a next server candidate based on the priority and server being not-disabled. Move all server related functions into its own header. Signed-off-by: Seppo Takalo (cherry picked from commit ec962246e9eaf38746e2e895b1e7601896b67de5) --- subsys/net/lib/lwm2m/lwm2m_engine.h | 40 +--- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 1 + subsys/net/lib/lwm2m/lwm2m_obj_server.c | 224 ++++++++++++------ subsys/net/lib/lwm2m/lwm2m_obj_server.h | 144 +++++++++++ subsys/net/lib/lwm2m/lwm2m_observation.c | 1 + subsys/net/lib/lwm2m/lwm2m_rd_client.c | 1 + 6 files changed, 302 insertions(+), 109 deletions(-) create mode 100644 subsys/net/lib/lwm2m/lwm2m_obj_server.h diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.h b/subsys/net/lib/lwm2m/lwm2m_engine.h index 2ea3e583242..81b28395662 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.h +++ b/subsys/net/lib/lwm2m/lwm2m_engine.h @@ -30,6 +30,7 @@ /* length of time in milliseconds to wait for buffer allocations */ #define BUF_ALLOC_TIMEOUT K_SECONDS(1) + /** * @brief Validates that writing is a legal operation on the field given by the object in * @p obj_inst and the resource id in @p msg. Returns the field to obj_field (if it exists). @@ -150,45 +151,6 @@ int lwm2m_security_short_id_to_inst(uint16_t short_id); */ int lwm2m_security_index_to_inst_id(int index); -/** - * @brief Returns the default minimum period for an observation set for the server - * with object instance id given by @p obj_inst_id. - * - * @param[in] obj_inst_id Object instance id of the server object instance - * @return int32_t pmin value - */ -int32_t lwm2m_server_get_pmin(uint16_t obj_inst_id); - -/** - * @brief Returns the default maximum period for an observation set for the server - * with object instance id given by @p obj_inst_id. - * - * @param[in] obj_inst_id Object instance id of the server object instance - * @return int32_t pmax value - */ -int32_t lwm2m_server_get_pmax(uint16_t obj_inst_id); - -/** - * @brief Returns the Short Server ID of the server object instance with - * object instance id given by @p obj_inst_id. - * - * @param[in] obj_inst_id Object instance id of the server object - * @return SSID or negative in case not found - */ -int lwm2m_server_get_ssid(uint16_t obj_inst_id); - -/** - * @brief Returns the object instance id of the server having ssid given by @p short_id. - * - * @param[in] short_id ssid of the server object - * @return Object instance id or negative in case not found - */ -int lwm2m_server_short_id_to_inst(uint16_t short_id); - -#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) -bool lwm2m_server_get_mute_send(uint16_t obj_inst_id); -#endif - #if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT) /** * @brief Sets the update state (as specified in LWM2M SPEC E.6 regarding the firmware update) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 6d006b4603e..02c62cee67c 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -45,6 +45,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "lwm2m_engine.h" #include "lwm2m_object.h" #include "lwm2m_obj_access_control.h" +#include "lwm2m_obj_server.h" #include "lwm2m_rw_link_format.h" #include "lwm2m_rw_oma_tlv.h" #include "lwm2m_rw_plain_text.h" diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_server.c b/subsys/net/lib/lwm2m/lwm2m_obj_server.c index a1b2185ef1d..10c7a1a1ea0 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_server.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_server.c @@ -15,8 +15,9 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #include "lwm2m_object.h" -#include "lwm2m_engine.h" +#include "lwm2m_obj_server.h" #include "lwm2m_rd_client.h" +#include "lwm2m_registry.h" #define SERVER_VERSION_MAJOR 1 #if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) @@ -27,37 +28,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #define SERVER_MAX_ID 9 #endif /* defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) */ -/* Server resource IDs */ -#define SERVER_SHORT_SERVER_ID 0 -#define SERVER_LIFETIME_ID 1 -#define SERVER_DEFAULT_MIN_PERIOD_ID 2 -#define SERVER_DEFAULT_MAX_PERIOD_ID 3 -#define SERVER_DISABLE_ID 4 -#define SERVER_DISABLE_TIMEOUT_ID 5 -#define SERVER_STORE_NOTIFY_ID 6 -#define SERVER_TRANSPORT_BINDING_ID 7 -#define SERVER_REG_UPDATE_TRIGGER_ID 8 -#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) -#define SERVER_BOOTSTRAP_UPDATE_TRIGGER_ID 9 -#define SERVER_APN_LINK_ID 10 -#define SERVER_TLS_DTLS_ALERT_CODE_ID 11 -#define SERVER_LAST_BOOTSTRAPPED_ID 12 -#define SERVER_REGISTRATION_PRIORITY_ORDER_ID 13 -#define SERVER_INITIAL_REGISTRATION_DELAY_TIMER_ID 14 -#define SERVER_REGISTRATION_FAILURE_BLOCK_ID 15 -#define SERVER_BOOTSTRAP_ON_REGISTRATION_FAILURE_ID 16 -#define SERVER_COMMUNICATION_RETRY_COUNT_ID 17 -#define SERVER_COMMUNICATION_RETRY_TIMER_ID 18 -#define SERVER_COMMUNICATION_SEQUENCE_DELAY_TIMER_ID 19 -#define SERVER_COMMUNICATION_SEQUENCE_RETRY_TIMER_ID 20 -#define SERVER_SMS_TRIGGER_ID 21 -#define SERVER_PREFERRED_TRANSPORT_ID 22 -#define SERVER_MUTE_SEND_ID 23 -#endif /* defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) */ - - /* Server flags */ -#define SERVER_FLAG_DISABLED 1 #define SERVER_FLAG_STORE_NOTIFY 2 #define MAX_INSTANCE_COUNT CONFIG_LWM2M_SERVER_INSTANCE_COUNT @@ -76,13 +47,14 @@ static uint16_t server_id[MAX_INSTANCE_COUNT]; static uint32_t lifetime[MAX_INSTANCE_COUNT]; static uint32_t default_min_period[MAX_INSTANCE_COUNT]; static uint32_t default_max_period[MAX_INSTANCE_COUNT]; -static uint8_t server_flag_disabled[MAX_INSTANCE_COUNT]; +static k_timepoint_t disabled_until[MAX_INSTANCE_COUNT]; static uint32_t disabled_timeout[MAX_INSTANCE_COUNT]; static uint8_t server_flag_store_notify[MAX_INSTANCE_COUNT]; static char transport_binding[MAX_INSTANCE_COUNT][TRANSPORT_BINDING_LEN]; -#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) +/* Server object version 1.1 */ +static uint8_t priority[MAX_INSTANCE_COUNT]; static bool mute_send[MAX_INSTANCE_COUNT]; -#endif +static bool boostrap_on_fail[MAX_INSTANCE_COUNT]; static struct lwm2m_engine_obj server; static struct lwm2m_engine_obj_field fields[] = { @@ -101,10 +73,10 @@ static struct lwm2m_engine_obj_field fields[] = { OBJ_FIELD_DATA(SERVER_APN_LINK_ID, RW_OPT, OBJLNK), OBJ_FIELD_DATA(SERVER_TLS_DTLS_ALERT_CODE_ID, R_OPT, U8), OBJ_FIELD_DATA(SERVER_LAST_BOOTSTRAPPED_ID, R_OPT, TIME), - OBJ_FIELD_DATA(SERVER_REGISTRATION_PRIORITY_ORDER_ID, W_OPT, U16), + OBJ_FIELD_DATA(SERVER_REGISTRATION_PRIORITY_ORDER_ID, RW_OPT, U8), OBJ_FIELD_DATA(SERVER_INITIAL_REGISTRATION_DELAY_TIMER_ID, W_OPT, U16), OBJ_FIELD_DATA(SERVER_REGISTRATION_FAILURE_BLOCK_ID, W_OPT, BOOL), - OBJ_FIELD_DATA(SERVER_BOOTSTRAP_ON_REGISTRATION_FAILURE_ID, W_OPT, BOOL), + OBJ_FIELD_DATA(SERVER_BOOTSTRAP_ON_REGISTRATION_FAILURE_ID, RW_OPT, BOOL), OBJ_FIELD_DATA(SERVER_COMMUNICATION_RETRY_COUNT_ID, W_OPT, U16), OBJ_FIELD_DATA(SERVER_COMMUNICATION_RETRY_TIMER_ID, W_OPT, U16), OBJ_FIELD_DATA(SERVER_COMMUNICATION_SEQUENCE_DELAY_TIMER_ID, W_OPT, U16), @@ -128,7 +100,7 @@ static int disable_cb(uint16_t obj_inst_id, uint8_t *args, uint16_t args_len) LOG_DBG("DISABLE %d", obj_inst_id); for (i = 0; i < MAX_INSTANCE_COUNT; i++) { if (inst[i].obj && inst[i].obj_inst_id == obj_inst_id) { - server_flag_disabled[i] = 1U; + disabled_until[i] = sys_timepoint_calc(K_SECONDS(disabled_timeout[i])); return 0; } } @@ -143,7 +115,6 @@ static int update_trigger_cb(uint16_t obj_inst_id, return 0; } -#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) static int bootstrap_trigger_cb(uint16_t obj_inst_id, uint8_t *args, uint16_t args_len) { @@ -161,7 +132,6 @@ bool lwm2m_server_get_mute_send(uint16_t obj_inst_id) } return false; } -#endif /* defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) */ static int lifetime_write_cb(uint16_t obj_inst_id, uint16_t res_id, @@ -233,6 +203,116 @@ int lwm2m_server_short_id_to_inst(uint16_t short_id) return -ENOENT; } +static int lwm2m_server_inst_id_to_index(uint16_t obj_inst_id) +{ + for (int i = 0; i < ARRAY_SIZE(inst); i++) { + if (inst[i].obj && inst[i].obj_inst_id == obj_inst_id) { + return i; + } + } + return -1; +} + +bool lwm2m_server_is_enabled(uint16_t obj_inst_id) +{ + int idx = lwm2m_server_inst_id_to_index(obj_inst_id); + + if (idx < 0) { + return false; + } + return sys_timepoint_expired(disabled_until[idx]); +} + +int lwm2m_server_disable(uint16_t obj_inst_id, k_timeout_t timeout) +{ + int idx = lwm2m_server_inst_id_to_index(obj_inst_id); + + if (idx < 0) { + return -ENOENT; + } + disabled_until[idx] = sys_timepoint_calc(timeout); + return 0; +} + +k_timepoint_t lwm2m_server_get_disabled_time(uint16_t obj_inst_id) +{ + int idx = lwm2m_server_inst_id_to_index(obj_inst_id); + + if (idx < 0) { + return sys_timepoint_calc(K_FOREVER); + } + return disabled_until[idx]; +} + +void lwm2m_server_reset_timestamps(void) +{ + for (int i = 0; i < ARRAY_SIZE(inst); i++) { + disabled_until[i] = sys_timepoint_calc(K_NO_WAIT); + } +} + +bool lwm2m_server_select(uint16_t *obj_inst_id) +{ + uint8_t min = UINT8_MAX; + uint8_t max = 0; + + /* Find priority boundaries */ + if (IS_ENABLED(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1)) { + for (int i = 0; i < ARRAY_SIZE(inst); i++) { + if (min > priority[i]) { + min = priority[i]; + } + if (max < priority[i]) { + max = priority[i]; + } + } + } else { + min = max = 0; + } + + for (uint8_t prio = min; prio <= max; prio++) { + for (int i = 0; i < ARRAY_SIZE(inst); i++) { + /* Disabled for a period */ + if (!lwm2m_server_is_enabled(inst[i].obj_inst_id)) { + continue; + } + + /* Invalid short IDs */ + if (server_id[i] == 0 || server_id[i] == UINT16_MAX) { + continue; + } + + /* Check priority */ + if (IS_ENABLED(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1)) { + if (priority[i] > prio) { + continue; + } + } + if (obj_inst_id) { + *obj_inst_id = inst[i].obj_inst_id; + } + return true; + } + } + + LOG_ERR("No server candidate found"); + return false; +} + +uint8_t lwm2m_server_get_prio(uint16_t obj_inst_id) +{ + if (IS_ENABLED(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1)) { + int idx = lwm2m_server_inst_id_to_index(obj_inst_id); + + if (idx < 0) { + return UINT8_MAX; + } + return priority[idx]; + } + + return (uint8_t)obj_inst_id % UINT8_MAX; +} + static struct lwm2m_engine_obj_inst *server_create(uint16_t obj_inst_id) { int index, i = 0, j = 0; @@ -259,16 +339,14 @@ static struct lwm2m_engine_obj_inst *server_create(uint16_t obj_inst_id) } /* Set default values */ - server_flag_disabled[index] = 0U; + disabled_until[i] = sys_timepoint_calc(K_NO_WAIT); server_flag_store_notify[index] = 0U; server_id[index] = index + 1; lifetime[index] = CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME; default_min_period[index] = CONFIG_LWM2M_SERVER_DEFAULT_PMIN; default_max_period[index] = CONFIG_LWM2M_SERVER_DEFAULT_PMAX; disabled_timeout[index] = 86400U; -#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) - mute_send[index] = false; -#endif + boostrap_on_fail[index] = true; lwm2m_engine_get_binding(transport_binding[index]); @@ -305,33 +383,39 @@ static struct lwm2m_engine_obj_inst *server_create(uint16_t obj_inst_id) transport_binding[index], TRANSPORT_BINDING_LEN, strlen(transport_binding[index]) + 1); INIT_OBJ_RES_EXECUTE(SERVER_REG_UPDATE_TRIGGER_ID, res[index], i, update_trigger_cb); -#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) - INIT_OBJ_RES_EXECUTE(SERVER_BOOTSTRAP_UPDATE_TRIGGER_ID, res[index], i, - bootstrap_trigger_cb); - INIT_OBJ_RES_OPTDATA(SERVER_APN_LINK_ID, res[index], i, res_inst[index], j); - INIT_OBJ_RES_OPTDATA(SERVER_TLS_DTLS_ALERT_CODE_ID, res[index], i, res_inst[index], j); - INIT_OBJ_RES_OPTDATA(SERVER_LAST_BOOTSTRAPPED_ID, res[index], i, res_inst[index], j); - INIT_OBJ_RES_OPTDATA(SERVER_REGISTRATION_PRIORITY_ORDER_ID, res[index], i, res_inst[index], - j); - INIT_OBJ_RES_OPTDATA(SERVER_INITIAL_REGISTRATION_DELAY_TIMER_ID, res[index], i, - res_inst[index], j); - INIT_OBJ_RES_OPTDATA(SERVER_REGISTRATION_FAILURE_BLOCK_ID, res[index], i, res_inst[index], - j); - INIT_OBJ_RES_OPTDATA(SERVER_BOOTSTRAP_ON_REGISTRATION_FAILURE_ID, res[index], i, - res_inst[index], j); - INIT_OBJ_RES_OPTDATA(SERVER_COMMUNICATION_RETRY_COUNT_ID, res[index], i, res_inst[index], - j); - INIT_OBJ_RES_OPTDATA(SERVER_COMMUNICATION_RETRY_TIMER_ID, res[index], i, res_inst[index], - j); - INIT_OBJ_RES_OPTDATA(SERVER_COMMUNICATION_SEQUENCE_DELAY_TIMER_ID, res[index], i, - res_inst[index], j); - INIT_OBJ_RES_OPTDATA(SERVER_COMMUNICATION_SEQUENCE_RETRY_TIMER_ID, res[index], i, - res_inst[index], j); - INIT_OBJ_RES_OPTDATA(SERVER_SMS_TRIGGER_ID, res[index], i, res_inst[index], j); - INIT_OBJ_RES_OPTDATA(SERVER_PREFERRED_TRANSPORT_ID, res[index], i, res_inst[index], j); - INIT_OBJ_RES_DATA(SERVER_MUTE_SEND_ID, res[index], i, res_inst[index], j, &mute_send[index], - sizeof(bool)); -#endif /* defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) */ + + if (IS_ENABLED(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1)) { + mute_send[index] = false; + priority[index] = 0; + INIT_OBJ_RES_EXECUTE(SERVER_BOOTSTRAP_UPDATE_TRIGGER_ID, res[index], i, + bootstrap_trigger_cb); + INIT_OBJ_RES_OPTDATA(SERVER_APN_LINK_ID, res[index], i, res_inst[index], j); + INIT_OBJ_RES_OPTDATA(SERVER_TLS_DTLS_ALERT_CODE_ID, res[index], i, res_inst[index], + j); + INIT_OBJ_RES_OPTDATA(SERVER_LAST_BOOTSTRAPPED_ID, res[index], i, res_inst[index], + j); + INIT_OBJ_RES_DATA(SERVER_REGISTRATION_PRIORITY_ORDER_ID, res[index], i, + res_inst[index], j, &priority[index], sizeof(uint8_t)); + INIT_OBJ_RES_OPTDATA(SERVER_INITIAL_REGISTRATION_DELAY_TIMER_ID, res[index], i, + res_inst[index], j); + INIT_OBJ_RES_OPTDATA(SERVER_REGISTRATION_FAILURE_BLOCK_ID, res[index], i, + res_inst[index], j); + INIT_OBJ_RES_DATA(SERVER_BOOTSTRAP_ON_REGISTRATION_FAILURE_ID, res[index], i, + res_inst[index], j, &boostrap_on_fail[index], sizeof(bool)); + INIT_OBJ_RES_OPTDATA(SERVER_COMMUNICATION_RETRY_COUNT_ID, res[index], i, + res_inst[index], j); + INIT_OBJ_RES_OPTDATA(SERVER_COMMUNICATION_RETRY_TIMER_ID, res[index], i, + res_inst[index], j); + INIT_OBJ_RES_OPTDATA(SERVER_COMMUNICATION_SEQUENCE_DELAY_TIMER_ID, res[index], i, + res_inst[index], j); + INIT_OBJ_RES_OPTDATA(SERVER_COMMUNICATION_SEQUENCE_RETRY_TIMER_ID, res[index], i, + res_inst[index], j); + INIT_OBJ_RES_OPTDATA(SERVER_SMS_TRIGGER_ID, res[index], i, res_inst[index], j); + INIT_OBJ_RES_OPTDATA(SERVER_PREFERRED_TRANSPORT_ID, res[index], i, res_inst[index], + j); + INIT_OBJ_RES_DATA(SERVER_MUTE_SEND_ID, res[index], i, res_inst[index], j, + &mute_send[index], sizeof(bool)); + } inst[index].resources = res[index]; inst[index].resource_count = i; diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_server.h b/subsys/net/lib/lwm2m/lwm2m_obj_server.h new file mode 100644 index 00000000000..56d7a674071 --- /dev/null +++ b/subsys/net/lib/lwm2m/lwm2m_obj_server.h @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LWM2M_OBJ_SERVER_H_ +#define LWM2M_OBJ_SERVER_H_ + +#include +#include +#include + +/* Server resource IDs */ +#define SERVER_SHORT_SERVER_ID 0 +#define SERVER_LIFETIME_ID 1 +#define SERVER_DEFAULT_MIN_PERIOD_ID 2 +#define SERVER_DEFAULT_MAX_PERIOD_ID 3 +#define SERVER_DISABLE_ID 4 +#define SERVER_DISABLE_TIMEOUT_ID 5 +#define SERVER_STORE_NOTIFY_ID 6 +#define SERVER_TRANSPORT_BINDING_ID 7 +#define SERVER_REG_UPDATE_TRIGGER_ID 8 +/* Server object version 1.1 resource IDs */ +#define SERVER_BOOTSTRAP_UPDATE_TRIGGER_ID 9 +#define SERVER_APN_LINK_ID 10 +#define SERVER_TLS_DTLS_ALERT_CODE_ID 11 +#define SERVER_LAST_BOOTSTRAPPED_ID 12 +#define SERVER_REGISTRATION_PRIORITY_ORDER_ID 13 +#define SERVER_INITIAL_REGISTRATION_DELAY_TIMER_ID 14 +#define SERVER_REGISTRATION_FAILURE_BLOCK_ID 15 +#define SERVER_BOOTSTRAP_ON_REGISTRATION_FAILURE_ID 16 +#define SERVER_COMMUNICATION_RETRY_COUNT_ID 17 +#define SERVER_COMMUNICATION_RETRY_TIMER_ID 18 +#define SERVER_COMMUNICATION_SEQUENCE_DELAY_TIMER_ID 19 +#define SERVER_COMMUNICATION_SEQUENCE_RETRY_TIMER_ID 20 +#define SERVER_SMS_TRIGGER_ID 21 +#define SERVER_PREFERRED_TRANSPORT_ID 22 +#define SERVER_MUTE_SEND_ID 23 + +/** + * @brief Returns the default minimum period for an observation set for the server + * with object instance id given by @p obj_inst_id. + * + * @param[in] obj_inst_id Object instance id of the server object instance + * @return int32_t pmin value + */ +int32_t lwm2m_server_get_pmin(uint16_t obj_inst_id); + +/** + * @brief Returns the default maximum period for an observation set for the server + * with object instance id given by @p obj_inst_id. + * + * @param[in] obj_inst_id Object instance id of the server object instance + * @return int32_t pmax value + */ +int32_t lwm2m_server_get_pmax(uint16_t obj_inst_id); + +/** + * @brief Returns the Short Server ID of the server object instance with + * object instance id given by @p obj_inst_id. + * + * @param[in] obj_inst_id Object instance id of the server object + * @return SSID or negative in case not found + */ +int lwm2m_server_get_ssid(uint16_t obj_inst_id); + +/** + * @brief Returns the object instance id of the server having ssid given by @p short_id. + * + * @param[in] short_id ssid of the server object + * @return Object instance id or negative in case not found + */ +int lwm2m_server_short_id_to_inst(uint16_t short_id); + +/** + * @brief Check if given server instance is not disabled + * + * @param[in] obj_inst_id server instance + * @return true if not disabled, false otherwise. + */ +bool lwm2m_server_is_enabled(uint16_t obj_inst_id); + +/** + * @brief Select server instance. + * + * Find possible server instance considering values on server data. + * Server candidates cannot be in disabled state and if priority values are set, + * those are compared and lowest values are considered first. + * + * If @ref obj_inst_id is NULL, this can be used to check if there are any server available. + * + * @param[out] obj_inst_id where selected server instance ID is written. Can be NULL. + * @return true if server instance was found, false otherwise. + */ +bool lwm2m_server_select(uint16_t *obj_inst_id); + +/** + * @brief Disable server instance for a period of time. + * + * Timeout values can be calculated using kernel macros like K_SECONDS(). + * Values like K_FOREVER or K_NO_WAIT are also accepted. + * + * @param timeout Timeout value. + * @return zero on success, negative error code otherwise. + */ +int lwm2m_server_disable(uint16_t obj_inst_id, k_timeout_t timeout); + +/** + * @brief Get timepoint how long server instance is disabled. + * + * If server instance is not disabled, this still returns a valid timepoint + * that have already expired. + * If the instance id is not valid, the timepoint is set to K_FOREVER. + * + * @param obj_inst_id Server instance ID. + * @return timepoint + */ +k_timepoint_t lwm2m_server_get_disabled_time(uint16_t obj_inst_id); + +/** + * @brief Get priority of given server instance. + * + * Lower values mean higher priority. + * If LwM2M server object version 1.1 is not enabled, + * this returns obj_inst_id as priority. + * + * @param obj_inst_id instance ID + * @return priority or UINT8_MAX if instance not found + */ +uint8_t lwm2m_server_get_prio(uint16_t obj_inst_id); + +/** + * @brief Reset all disable-timers for all server instances. + * + */ +void lwm2m_server_reset_timestamps(void); + +#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1) +bool lwm2m_server_get_mute_send(uint16_t obj_inst_id); +#endif + + +#endif /* LWM2M_OBJ_SERVER_H_ */ diff --git a/subsys/net/lib/lwm2m/lwm2m_observation.c b/subsys/net/lib/lwm2m/lwm2m_observation.c index 9ee1fa6eda1..1c8034e6535 100644 --- a/subsys/net/lib/lwm2m/lwm2m_observation.c +++ b/subsys/net/lib/lwm2m/lwm2m_observation.c @@ -37,6 +37,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #include #include +#include "lwm2m_obj_server.h" #if defined(CONFIG_LWM2M_RW_SENML_JSON_SUPPORT) #include "lwm2m_rw_senml_json.h" diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.c b/subsys/net/lib/lwm2m/lwm2m_rd_client.c index d9f2e229edd..6eacba0ee0d 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.c +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.c @@ -62,6 +62,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "lwm2m_rd_client.h" #include "lwm2m_rw_link_format.h" #include "lwm2m_util.h" +#include "lwm2m_obj_server.h" #define LWM2M_RD_CLIENT_URI "rd" #define CLIENT_EP_LEN CONFIG_LWM2M_RD_CLIENT_ENDPOINT_NAME_MAX_LENGTH From c673375d64d8df0b2777168cba4ebfdabfbd7c87 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 30 Nov 2023 17:38:14 +0200 Subject: [PATCH 1040/1623] [nrf fromtree] net: lwm2m: Implement fallback mechanism and support for diable If server registration fails, allow fallback to secondary server, or fallback to bootstrap. Also allow fallback to different bootstrap server. Add API to tell RD client when server have been disabled by executable command. Changes to RD state machine: * All retry logic should be handled in NETWORK_ERROR state. * New state SERVER_DISABLED. * Internally disable servers that reject registration * Temporary disable server on network error. * Clean up all "disable timers" on start. * Select server first, then find security object for it. * State functions return void, error handling is done using states. * DISCONNECT event will only come when client is requested to stop. * NETWORK_ERROR will stop engine. This is generic error for all kinds of registration or network failures. * BOOTSTRAP_REG_FAILURE also stops engine. This is fatal, and we cannot recover. Refactoring: * Server selection logic is inside server object. * sm_handle_timeout_state() does not require msg parameter. Unused. * When bootstrap fail, we should NOT back off to registration. This is a fatal error, and it stops the engine and informs application. Signed-off-by: Seppo Takalo (cherry picked from commit dc8f6da53c856c56f9d31fec58b9bea208609c95) --- include/zephyr/net/lwm2m.h | 1 + samples/net/lwm2m_client/src/lwm2m-client.c | 4 + subsys/net/lib/lwm2m/lwm2m_obj_server.c | 18 +- subsys/net/lib/lwm2m/lwm2m_rd_client.c | 421 +++++++++++------- subsys/net/lib/lwm2m/lwm2m_rd_client.h | 10 + .../net/lib/lwm2m/interop/src/lwm2m-client.c | 4 + .../net/lib/lwm2m/lwm2m_rd_client/src/main.c | 201 +++++++-- .../net/lib/lwm2m/lwm2m_rd_client/src/stubs.c | 22 + .../net/lib/lwm2m/lwm2m_rd_client/src/stubs.h | 9 +- 9 files changed, 495 insertions(+), 195 deletions(-) diff --git a/include/zephyr/net/lwm2m.h b/include/zephyr/net/lwm2m.h index a57b5542f88..6ac0458af87 100644 --- a/include/zephyr/net/lwm2m.h +++ b/include/zephyr/net/lwm2m.h @@ -2075,6 +2075,7 @@ enum lwm2m_rd_client_event { LWM2M_RD_CLIENT_EVENT_NETWORK_ERROR, LWM2M_RD_CLIENT_EVENT_REG_UPDATE, LWM2M_RD_CLIENT_EVENT_DEREGISTER, + LWM2M_RD_CLIENT_EVENT_SERVER_DISABLED, }; /** diff --git a/samples/net/lwm2m_client/src/lwm2m-client.c b/samples/net/lwm2m_client/src/lwm2m-client.c index a120506639d..c610f1ad8dd 100644 --- a/samples/net/lwm2m_client/src/lwm2m-client.c +++ b/samples/net/lwm2m_client/src/lwm2m-client.c @@ -191,6 +191,10 @@ static void rd_client_event(struct lwm2m_ctx *client, /* do nothing */ break; + case LWM2M_RD_CLIENT_EVENT_SERVER_DISABLED: + LOG_DBG("LwM2M server disabled"); + break; + case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE: LOG_DBG("Bootstrap registration failure!"); break; diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_server.c b/subsys/net/lib/lwm2m/lwm2m_obj_server.c index 10c7a1a1ea0..a9432340038 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_server.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_server.c @@ -95,13 +95,21 @@ static struct lwm2m_engine_res_inst static int disable_cb(uint16_t obj_inst_id, uint8_t *args, uint16_t args_len) { - int i; + ARG_UNUSED(args); + ARG_UNUSED(args_len); + + int ret; - LOG_DBG("DISABLE %d", obj_inst_id); - for (i = 0; i < MAX_INSTANCE_COUNT; i++) { + for (int i = 0; i < MAX_INSTANCE_COUNT; i++) { if (inst[i].obj && inst[i].obj_inst_id == obj_inst_id) { - disabled_until[i] = sys_timepoint_calc(K_SECONDS(disabled_timeout[i])); - return 0; + LOG_DBG("DISABLE %d", obj_inst_id); + ret = lwm2m_rd_client_server_disabled(obj_inst_id); + if (ret == 0) { + disabled_until[i] = + sys_timepoint_calc(K_SECONDS(disabled_timeout[i])); + return 0; + } + return ret; } } diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.c b/subsys/net/lib/lwm2m/lwm2m_rd_client.c index 6eacba0ee0d..6b3fbcccc68 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.c +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.c @@ -72,6 +72,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #define DELAY_FOR_ACK 100U #define EXCHANGE_LIFETIME 247U #define MINIMUM_PERIOD 15 +#define DISABLE_TIMEOUT (K_SECONDS(CONFIG_LWM2M_RD_CLIENT_MAX_RETRIES * EXCHANGE_LIFETIME)) static void sm_handle_registration_update_failure(void); static int sm_send_registration_msg(void); @@ -80,6 +81,8 @@ static void lwm2m_rd_client_service(struct k_work *work); static int64_t calc_next_event(void); static void set_sm_state_delayed(uint8_t sm_state, int64_t delay_ms); static void set_sm_state(uint8_t sm_state); +/** Try to fallback to bootstrap. Return true if we did. */ +static bool fallback_to_bootstrap(void); /* The states for the RD client state machine */ /* @@ -101,6 +104,7 @@ enum sm_engine_state { ENGINE_REGISTRATION_DONE_RX_OFF, ENGINE_UPDATE_REGISTRATION, ENGINE_UPDATE_SENT, + ENGINE_SERVER_DISABLED, ENGINE_SUSPENDED, ENGINE_DEREGISTER, ENGINE_DEREGISTER_SENT, @@ -125,11 +129,11 @@ struct lwm2m_rd_client_info { char ep_name[CLIENT_EP_LEN]; char server_ep[CLIENT_EP_LEN]; - bool use_bootstrap : 1; - + bool use_bootstrap : 1; bool trigger_update : 1; bool update_objects : 1; - bool close_socket : 1; + bool close_socket : 1; + bool server_disabled: 1; } client; /* Allocate some data for queries and updates. Make sure it's large enough to @@ -201,23 +205,18 @@ static void set_sm_state_delayed(uint8_t sm_state, int64_t delay_ms) event = LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE; } else if (sm_state == ENGINE_REGISTRATION_DONE_RX_OFF) { event = LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF; - } else if ((sm_state == ENGINE_INIT || - sm_state == ENGINE_DEREGISTERED) && + } else if (sm_state == ENGINE_DEREGISTERED && (client.engine_state >= ENGINE_DO_REGISTRATION && - client.engine_state <= ENGINE_DEREGISTER_SENT)) { + client.engine_state <= ENGINE_DEREGISTER_SENT) && !client.server_disabled) { event = LWM2M_RD_CLIENT_EVENT_DISCONNECT; - } else if (sm_state == ENGINE_NETWORK_ERROR) { - lwm2m_socket_close(client.ctx); - client.retry_delay = 1 << client.retries; - client.retries++; - if (client.retries > CONFIG_LWM2M_RD_CLIENT_MAX_RETRIES) { - client.retries = 0; - event = LWM2M_RD_CLIENT_EVENT_NETWORK_ERROR; - } } else if (sm_state == ENGINE_UPDATE_REGISTRATION) { event = LWM2M_RD_CLIENT_EVENT_REG_UPDATE; } else if (sm_state == ENGINE_DEREGISTER) { - event = LWM2M_RD_CLIENT_EVENT_DEREGISTER; + if (client.server_disabled) { + event = LWM2M_RD_CLIENT_EVENT_SERVER_DISABLED; + } else { + event = LWM2M_RD_CLIENT_EVENT_DEREGISTER; + } } if (sm_is_suspended()) { @@ -292,27 +291,22 @@ static uint8_t get_sm_state(void) return state; } -static void sm_handle_timeout_state(struct lwm2m_message *msg, - enum sm_engine_state sm_state) +static void sm_handle_timeout_state(enum sm_engine_state sm_state) { k_mutex_lock(&client.mutex, K_FOREVER); enum lwm2m_rd_client_event event = LWM2M_RD_CLIENT_EVENT_NONE; -#if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) - if (client.engine_state == ENGINE_BOOTSTRAP_REG_SENT) { - event = LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE; - } else -#endif - { - if (client.engine_state == ENGINE_REGISTRATION_SENT) { - event = LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT; - } else if (client.engine_state == ENGINE_UPDATE_SENT) { - event = LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT; - } else if (client.engine_state == ENGINE_DEREGISTER_SENT) { - event = LWM2M_RD_CLIENT_EVENT_DEREGISTER_FAILURE; - } else { - /* TODO: unknown timeout state */ - } + /* Don't send BOOTSTRAP_REG_FAILURE event, that is only emitted from + * do_network_error() once we are out of retries. + */ + if (client.engine_state == ENGINE_REGISTRATION_SENT) { + event = LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT; + } else if (client.engine_state == ENGINE_UPDATE_SENT) { + event = LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT; + } else if (client.engine_state == ENGINE_DEREGISTER_SENT) { + event = LWM2M_RD_CLIENT_EVENT_DEREGISTER_FAILURE; + } else { + /* TODO: unknown timeout state */ } set_sm_state(sm_state); @@ -374,11 +368,14 @@ static void socket_fault_cb(int error) /* Network error state causes engine to re-register, * so only trigger that state if we are not stopping the * engine. + * Also when engine is going to be disabled, for a while, we might get spurious + * socket errors when closing, so ignore them. */ if (client.engine_state > ENGINE_IDLE && - client.engine_state < ENGINE_SUSPENDED) { - set_sm_state(ENGINE_NETWORK_ERROR); - } else if (client.engine_state != ENGINE_SUSPENDED) { + client.engine_state < ENGINE_SERVER_DISABLED) { + sm_handle_timeout_state(ENGINE_NETWORK_ERROR); + } else if (client.engine_state != ENGINE_SUSPENDED && + !client.server_disabled) { sm_handle_failure_state(ENGINE_IDLE); } } @@ -453,13 +450,7 @@ static int do_bootstrap_reply_cb(const struct coap_packet *response, static void do_bootstrap_reg_timeout_cb(struct lwm2m_message *msg) { LOG_WRN("Bootstrap Timeout"); - - /* TODO: - * Look for the "next" BOOTSTRAP server entry in our security info - */ - - /* Restart from scratch */ - sm_handle_timeout_state(msg, ENGINE_INIT); + sm_handle_timeout_state(ENGINE_NETWORK_ERROR); } #endif @@ -522,6 +513,8 @@ static int do_registration_reply_cb(const struct coap_packet *response, /* remember the last reg time */ client.last_update = k_uptime_get(); + client.server_disabled = false; + client.retries = 0; memcpy(client.server_ep, options[1].value, options[1].len); @@ -533,11 +526,12 @@ static int do_registration_reply_cb(const struct coap_packet *response, return 0; } - LOG_ERR("Failed with code %u.%u (%s). Not Retrying.", + LOG_ERR("Failed with code %u.%u (%s).", COAP_RESPONSE_CODE_CLASS(code), COAP_RESPONSE_CODE_DETAIL(code), code2str(code)); fail: - sm_handle_failure_state(ENGINE_IDLE); + lwm2m_server_disable(client.ctx->srv_obj_inst, DISABLE_TIMEOUT); + sm_handle_failure_state(ENGINE_NETWORK_ERROR); return ret; } @@ -546,8 +540,7 @@ static void do_registration_timeout_cb(struct lwm2m_message *msg) { LOG_WRN("Registration Timeout"); - /* Restart from scratch */ - sm_handle_timeout_state(msg, ENGINE_INIT); + sm_handle_timeout_state(ENGINE_NETWORK_ERROR); } static int do_update_reply_cb(const struct coap_packet *response, @@ -588,7 +581,7 @@ static void do_update_timeout_cb(struct lwm2m_message *msg) client.close_socket = true; } /* Re-do registration */ - sm_handle_timeout_state(msg, ENGINE_DO_REGISTRATION); + sm_handle_timeout_state(ENGINE_DO_REGISTRATION); } static int do_deregister_reply_cb(const struct coap_packet *response, @@ -612,7 +605,7 @@ static int do_deregister_reply_cb(const struct coap_packet *response, COAP_RESPONSE_CODE_CLASS(code), COAP_RESPONSE_CODE_DETAIL(code), code2str(code)); - sm_handle_failure_state(ENGINE_IDLE); + sm_handle_failure_state(ENGINE_DEREGISTERED); return 0; } @@ -621,10 +614,10 @@ static void do_deregister_timeout_cb(struct lwm2m_message *msg) { LOG_WRN("De-Registration Timeout"); - sm_handle_timeout_state(msg, ENGINE_IDLE); + sm_handle_timeout_state(ENGINE_DEREGISTERED); } -static bool sm_bootstrap_verify(bool bootstrap_server, int sec_obj_inst) +static bool is_bootsrap_server(int sec_obj_inst) { bool bootstrap; int ret; @@ -634,12 +627,7 @@ static bool sm_bootstrap_verify(bool bootstrap_server, int sec_obj_inst) LOG_WRN("Failed to check bootstrap, err %d", ret); return false; } - - if (bootstrap == bootstrap_server) { - return true; - } else { - return false; - } + return bootstrap; } static bool sm_update_lifetime(int srv_obj_inst, uint32_t *lifetime) @@ -665,58 +653,40 @@ static bool sm_update_lifetime(int srv_obj_inst, uint32_t *lifetime) return false; } -static int sm_select_server_inst(int sec_obj_inst, int *srv_obj_inst, - uint32_t *lifetime) -{ - uint16_t server_id; - int ret, obj_inst_id; - - ret = lwm2m_get_u16(&LWM2M_OBJ(0, sec_obj_inst, 10), &server_id); - if (ret < 0) { - LOG_WRN("Failed to obtain Short Server ID, err %d", ret); - return -EINVAL; - } - - obj_inst_id = lwm2m_server_short_id_to_inst(server_id); - if (obj_inst_id < 0) { - LOG_WRN("Failed to obtain Server Object instance, err %d", - obj_inst_id); - return -EINVAL; - } - - sm_update_lifetime(obj_inst_id, lifetime); - *srv_obj_inst = obj_inst_id; - - return 0; -} - -static int sm_select_security_inst(bool bootstrap_server, int *sec_obj_inst) +/** + * @brief Find the next security instance for bootstrapping. + * + * Search for the next security instance that has the bootstrap flag set and + * is not the same as current security instance. + * + * @param sec_obj_inst current security instance or -1. + * @return zero on success, negative on error. + */ +static int sm_next_bootstrap_inst(int *sec_obj_inst) { int i, obj_inst_id = -1; - /* lookup existing index */ - i = lwm2m_security_inst_id_to_index(*sec_obj_inst); - if (i >= 0 && sm_bootstrap_verify(bootstrap_server, *sec_obj_inst)) { - return 0; + if (*sec_obj_inst >= 0 && !is_bootsrap_server(*sec_obj_inst)) { + *sec_obj_inst = -1; } - *sec_obj_inst = -1; - /* Iterate over all instances to find the correct one. */ for (i = 0; i < CONFIG_LWM2M_SECURITY_INSTANCE_COUNT; i++) { obj_inst_id = lwm2m_security_index_to_inst_id(i); if (obj_inst_id < 0) { - LOG_WRN("Failed to get inst id for %d", i); + continue; + } + if (obj_inst_id == *sec_obj_inst) { continue; } - if (sm_bootstrap_verify(bootstrap_server, obj_inst_id)) { + if (is_bootsrap_server(obj_inst_id)) { *sec_obj_inst = obj_inst_id; return 0; } } - LOG_WRN("sec_obj_inst: No matching servers found."); + LOG_WRN("No Bootstrap servers found."); return -ENOENT; } @@ -726,24 +696,17 @@ static int sm_select_security_inst(bool bootstrap_server, int *sec_obj_inst) static int sm_do_init(void) { lwm2m_engine_stop(client.ctx); - client.ctx->sec_obj_inst = -1; - client.ctx->srv_obj_inst = -1; client.trigger_update = false; client.lifetime = 0U; - client.retries = 0U; client.last_update = 0U; client.close_socket = false; /* Do bootstrap or registration */ -#if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) - if (client.use_bootstrap) { + if (client.use_bootstrap && IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)) { set_sm_state(ENGINE_DO_BOOTSTRAP_REG); } else { set_sm_state(ENGINE_DO_REGISTRATION); } -#else - set_sm_state(ENGINE_DO_REGISTRATION); -#endif return 0; } @@ -814,7 +777,7 @@ static int sm_send_bootstrap_registration(void) return ret; } -static int sm_do_bootstrap_reg(void) +static void sm_do_bootstrap_reg(void) { int ret; @@ -824,23 +787,20 @@ static int sm_do_bootstrap_reg(void) } client.ctx->bootstrap_mode = true; - ret = sm_select_security_inst(client.ctx->bootstrap_mode, - &client.ctx->sec_obj_inst); + ret = sm_next_bootstrap_inst(&client.ctx->sec_obj_inst); if (ret < 0) { - /* no bootstrap server found, let's move to registration */ - LOG_WRN("Bootstrap server not found! Try normal registration."); - set_sm_state(ENGINE_DO_REGISTRATION); - return ret; + set_sm_state(ENGINE_NETWORK_ERROR); + return; } - LOG_INF("Bootstrap started with endpoint '%s' with client lifetime %d", - client.ep_name, client.lifetime); + LOG_INF("Bootstrap started with endpoint '%s' using security object %d", + client.ep_name, client.ctx->sec_obj_inst); ret = lwm2m_engine_start(client.ctx); if (ret < 0) { LOG_ERR("Cannot init LWM2M engine (%d)", ret); set_sm_state(ENGINE_NETWORK_ERROR); - return ret; + return; } ret = sm_send_bootstrap_registration(); @@ -851,7 +811,7 @@ static int sm_do_bootstrap_reg(void) set_sm_state(ENGINE_NETWORK_ERROR); } - return ret; + return; } void engine_bootstrap_finish(void) @@ -1047,8 +1007,9 @@ static int sm_send_registration_msg(void) return ret; } -static int sm_do_registration(void) +static void sm_do_registration(void) { + uint16_t ssid; int ret = 0; if (client.ctx->connection_suspended) { @@ -1056,10 +1017,16 @@ static int sm_do_registration(void) lwm2m_engine_context_close(client.ctx); /* perform full registration */ set_sm_state(ENGINE_DO_REGISTRATION); - return 0; + return; } } else { + bool select_srv = true; + uint16_t srv = (uint16_t) client.ctx->srv_obj_inst; + + client.last_update = 0; + client.ctx->bootstrap_mode = false; + /* clear out existing connection data */ if (client.ctx->sock_fd > -1) { if (client.close_socket) { @@ -1068,43 +1035,58 @@ static int sm_do_registration(void) lwm2m_engine_stop(client.ctx); } else { lwm2m_engine_context_close(client.ctx); + /* Keep current connection, retry registration with same server */ + select_srv = false; } } - client.last_update = 0; + if (select_srv) { + /* Select next one from the list, or fail */ + if (!lwm2m_server_select(&srv)) { + LOG_ERR("Unable to find a valid server instance."); + goto bootstrap_or_retry; + } - client.ctx->bootstrap_mode = false; - ret = sm_select_security_inst(client.ctx->bootstrap_mode, - &client.ctx->sec_obj_inst); - if (ret < 0) { - LOG_ERR("Unable to find a valid security instance."); - set_sm_state(ENGINE_INIT); - return -EINVAL; - } + client.ctx->srv_obj_inst = srv; + sm_update_lifetime(srv, &client.lifetime); - ret = sm_select_server_inst(client.ctx->sec_obj_inst, - &client.ctx->srv_obj_inst, - &client.lifetime); - if (ret < 0) { - LOG_ERR("Unable to find a valid server instance."); - set_sm_state(ENGINE_INIT); - return -EINVAL; + ret = lwm2m_get_u16(&LWM2M_OBJ(1, client.ctx->srv_obj_inst, 0), &ssid); + if (ret < 0) { + LOG_ERR("Failed to read SSID"); + lwm2m_server_disable(srv, K_FOREVER); + goto bootstrap_or_retry; + } + + ret = lwm2m_security_short_id_to_inst(ssid); + if (ret < 0) { + LOG_ERR("Unable to find a valid security instance."); + lwm2m_server_disable(srv, K_FOREVER); + goto bootstrap_or_retry; + } + client.ctx->sec_obj_inst = (uint16_t) ret; } - LOG_INF("RD Client started with endpoint '%s' with client lifetime %d", - client.ep_name, client.lifetime); + LOG_INF("RD Client started with endpoint '%s' with client lifetime %d using server " + "object %d", + client.ep_name, client.lifetime, client.ctx->srv_obj_inst); ret = lwm2m_engine_start(client.ctx); if (ret < 0) { LOG_ERR("Cannot init LWM2M engine (%d)", ret); - set_sm_state(ENGINE_NETWORK_ERROR); - return ret; + goto bootstrap_or_retry; } } - ret = sm_send_registration_msg(); + sm_send_registration_msg(); + return; - return ret; +bootstrap_or_retry: + lwm2m_engine_stop(client.ctx); + if (!client.server_disabled && fallback_to_bootstrap()) { + return; + } + + set_sm_state(ENGINE_NETWORK_ERROR); } static int64_t next_update(void) @@ -1269,32 +1251,116 @@ static int sm_do_deregister(void) return ret; } +static bool fallback_to_bootstrap(void) +{ + if (IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)) { + bool fallback = true; + + (void)lwm2m_get_bool(&LWM2M_OBJ(LWM2M_OBJECT_SERVER_ID, client.ctx->srv_obj_inst, + SERVER_BOOTSTRAP_ON_REGISTRATION_FAILURE_ID), + &fallback); + if (fallback) { + client.use_bootstrap = true; + set_sm_state(ENGINE_INIT); + return true; + } + } + return false; +} + static void sm_do_network_error(void) { int err; + LOG_ERR("sm_do_network_error, retries %d", client.retries); + + lwm2m_socket_close(client.ctx); + if (client.retry_delay) { - client.retry_delay = 0; next_event_at(k_uptime_get() + client.retry_delay * MSEC_PER_SEC); + client.retry_delay = 0; return; } + client.retry_delay = 1 << client.retries; + client.retries++; -#if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) - if (client.ctx->bootstrap_mode) { - lwm2m_engine_context_close(client.ctx); - set_sm_state(ENGINE_DO_BOOTSTRAP_REG); - return; + /* Stop retrying and try fallback */ + if (client.retries > CONFIG_LWM2M_RD_CLIENT_MAX_RETRIES) { + LOG_ERR("Network error, max retries reached (%d)", client.retries); + + /* Disable current server for a period so lwm2m_server_select() does not pick it */ + if (client.ctx->srv_obj_inst > -1) { + lwm2m_server_disable(client.ctx->srv_obj_inst, DISABLE_TIMEOUT); + } + + /* Are we in bootstrap? Try if we can fallback to some other BS server */ + if (client.ctx->bootstrap_mode && + IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)) { + LOG_DBG("In bootstrap, try fallback srv"); + /* Do we have any other bootstrap server to back off to? */ + if (sm_next_bootstrap_inst(&client.ctx->sec_obj_inst) < 0) { + /* No, we are out of options, stop engine */ + goto stop_engine; + } + set_sm_state(ENGINE_INIT); + return; + } + + /* Try if there are other server to fall back to, + * Only allow fallback to higher priority server (lower value, or lower id) + * if we have successfully registered before. + * This should block us from looping the same list again. + * Instead we should fallback to bootstrap. + */ + uint16_t srv; + + if (lwm2m_server_select(&srv)) { + uint8_t p1, p2; + + p1 = lwm2m_server_get_prio(client.ctx->srv_obj_inst); + p2 = lwm2m_server_get_prio(srv); + if (p1 < p2 || client.last_update != 0) { + set_sm_state(ENGINE_INIT); + return; + } + } + + /* If we have been disabled by some server, don't fall back to bootstrap */ + if (client.server_disabled) { + set_sm_state(ENGINE_SERVER_DISABLED); + return; + } + + if (fallback_to_bootstrap()) { + return; + } + goto stop_engine; + } + + /* Retry bootstrap */ + if (IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)) { + if (client.ctx->bootstrap_mode) { + lwm2m_engine_context_close(client.ctx); + /* If we don't have fallback BS server, retry with current one */ + if (sm_next_bootstrap_inst(&client.ctx->sec_obj_inst) < 0) { + client.ctx->sec_obj_inst = -1; + } + set_sm_state(ENGINE_DO_BOOTSTRAP_REG); + return; + } } -#endif if (!client.last_update || (k_uptime_get() - client.last_update) / MSEC_PER_SEC > client.lifetime) { /* do full registration as there is no active registration or lifetime exceeded */ - lwm2m_engine_context_close(client.ctx); + /* Keep the same server until out of retry */ set_sm_state(ENGINE_DO_REGISTRATION); return; } + /* Try if we can recover the DTLS session and try Update. + * This might fallback into full registration on sm_handle_registration_update_failure(). + */ err = lwm2m_socket_start(client.ctx); if (err) { LOG_ERR("Failed to start socket %d", err); @@ -1305,8 +1371,21 @@ static void sm_do_network_error(void) set_sm_state(ENGINE_NETWORK_ERROR); return; } - set_sm_state(ENGINE_UPDATE_REGISTRATION); + return; + +stop_engine: + + /* We are out of options, stop engine */ + if (client.ctx->event_cb) { + if (client.ctx->bootstrap_mode) { + client.ctx->event_cb(client.ctx, + LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE); + } else { + client.ctx->event_cb(client.ctx, LWM2M_RD_CLIENT_EVENT_NETWORK_ERROR); + } + } + set_sm_state(ENGINE_IDLE); } static void lwm2m_rd_client_service(struct k_work *work) @@ -1380,6 +1459,19 @@ static void lwm2m_rd_client_service(struct k_work *work) timeout = EXCHANGE_LIFETIME; break; + case ENGINE_SERVER_DISABLED: + if (lwm2m_server_select(NULL)) { + set_sm_state(ENGINE_INIT); + } else { + /* wait for server to be enabled. */ + /* + * TODO: Once engine is converted to use timepoint_t + * this should calculate the next event from the previous server. + */ + next_event_at(k_uptime_get() + SEC_PER_MIN * MSEC_PER_SEC); + } + break; + case ENGINE_DEREGISTER: sm_do_deregister(); break; @@ -1391,7 +1483,11 @@ static void lwm2m_rd_client_service(struct k_work *work) case ENGINE_DEREGISTERED: lwm2m_engine_stop(client.ctx); - set_sm_state(ENGINE_IDLE); + if (client.server_disabled) { + set_sm_state(ENGINE_SERVER_DISABLED); + } else { + set_sm_state(ENGINE_IDLE); + } break; case ENGINE_NETWORK_ERROR: @@ -1408,7 +1504,7 @@ static void lwm2m_rd_client_service(struct k_work *work) if (end < k_uptime_get()) { LOG_DBG("State machine have timed out"); - sm_handle_timeout_state(NULL, ENGINE_INIT); + sm_handle_timeout_state(ENGINE_INIT); } else if (client.next_event > end) { next_event_at(end); } @@ -1442,6 +1538,7 @@ int lwm2m_rd_client_start(struct lwm2m_ctx *client_ctx, const char *ep_name, } /* Init Context */ + lwm2m_server_reset_timestamps(); lwm2m_engine_context_init(client_ctx); client.ctx = client_ctx; @@ -1450,13 +1547,15 @@ int lwm2m_rd_client_start(struct lwm2m_ctx *client_ctx, const char *ep_name, client.ctx->observe_cb = observe_cb; client.ctx->event_cb = event_cb; client.use_bootstrap = flags & LWM2M_RD_CLIENT_FLAG_BOOTSTRAP; + client.ctx->srv_obj_inst = -1; + client.ctx->sec_obj_inst = -1; + client.retries = 0; - set_sm_state(ENGINE_INIT); strncpy(client.ep_name, ep_name, CLIENT_EP_LEN - 1); client.ep_name[CLIENT_EP_LEN - 1] = '\0'; LOG_INF("Start LWM2M Client: %s", client.ep_name); - next_event_at(0); + set_sm_state(ENGINE_INIT); k_mutex_unlock(&client.mutex); @@ -1477,9 +1576,10 @@ int lwm2m_rd_client_stop(struct lwm2m_ctx *client_ctx, client.ctx->event_cb = event_cb; rd_client_message_free(); - if (sm_is_registered() && deregister) { + if (sm_is_registered() && deregister && !client.server_disabled) { set_sm_state(ENGINE_DEREGISTER); } else { + client.server_disabled = false; set_sm_state(ENGINE_DEREGISTERED); } @@ -1557,7 +1657,7 @@ int lwm2m_rd_client_resume(void) #endif /* Or do we resume into registration state */ if (client.engine_state >= ENGINE_DO_REGISTRATION && - client.engine_state <= ENGINE_SUSPENDED) { + client.engine_state <= ENGINE_SERVER_DISABLED) { if (!client.last_update || (client.lifetime <= (k_uptime_get() - client.last_update) / MSEC_PER_SEC)) { /* No lifetime left, register again */ @@ -1575,6 +1675,29 @@ int lwm2m_rd_client_resume(void) return 0; } +int lwm2m_rd_client_server_disabled(uint16_t inst_id) +{ + if (client.ctx->srv_obj_inst != inst_id) { + return -EPERM; + } + + k_mutex_lock(&client.mutex, K_FOREVER); + + client.server_disabled = true; + + if (sm_is_registered()) { + LOG_INF("Server disabled, deregister"); + set_sm_state_delayed(ENGINE_DEREGISTER, DELAY_BEFORE_CLOSING); + } else { + LOG_INF("Server disabled"); + set_sm_state(ENGINE_DEREGISTERED); + } + + k_mutex_unlock(&client.mutex); + + return 0; +} + void lwm2m_rd_client_update(void) { engine_trigger_update(false); diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.h b/subsys/net/lib/lwm2m/lwm2m_rd_client.h index 66a3aac20f3..5d71ccb30f6 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.h +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.h @@ -56,4 +56,14 @@ int lwm2m_rd_client_connection_resume(struct lwm2m_ctx *client_ctx); void engine_update_tx_time(void); struct lwm2m_message *lwm2m_get_ongoing_rd_msg(void); +/** + * @brief Notify RD client that this server is disabled. + * + * This may return error -EPERM, if RD client is not registered on that server. + * + * @param inst_id server instance id + * @return int 0 on success, negative errno on failure. + */ +int lwm2m_rd_client_server_disabled(uint16_t inst_id); + #endif /* LWM2M_RD_CLIENT_H */ diff --git a/tests/net/lib/lwm2m/interop/src/lwm2m-client.c b/tests/net/lib/lwm2m/interop/src/lwm2m-client.c index 706091659a5..b6634069fbd 100644 --- a/tests/net/lib/lwm2m/interop/src/lwm2m-client.c +++ b/tests/net/lib/lwm2m/interop/src/lwm2m-client.c @@ -119,6 +119,10 @@ static void rd_client_event(struct lwm2m_ctx *client, /* do nothing */ break; + case LWM2M_RD_CLIENT_EVENT_SERVER_DISABLED: + LOG_DBG("LwM2M server disabled"); + break; + case LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE: LOG_DBG("Bootstrap registration failure!"); break; diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c b/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c index 208298512d4..1d6a4e584fa 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c @@ -21,7 +21,7 @@ DEFINE_FFF_GLOBALS; /* Maximum number of iterations within the state machine of RD Client * service that is waited for until a possible event occurs */ -static const uint8_t RD_CLIENT_MAX_LOOKUP_ITERATIONS = 100; +#define RD_CLIENT_MAX_LOOKUP_ITERATIONS 500 FAKE_VOID_FUNC(show_lwm2m_event, enum lwm2m_rd_client_event); FAKE_VOID_FUNC(show_lwm2m_observe, enum lwm2m_observe_event); @@ -97,6 +97,9 @@ static void lwm2m_event_cb(struct lwm2m_ctx *client, enum lwm2m_rd_client_event case LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF: LOG_INF("*** LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF"); break; + case LWM2M_RD_CLIENT_EVENT_SERVER_DISABLED: + LOG_INF("*** LWM2M_RD_CLIENT_EVENT_SERVER_DISABLED"); + break; case LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED: LOG_INF("*** LWM2M_RD_CLIENT_EVENT_ENGINE_SUSPENDED"); break; @@ -165,6 +168,7 @@ static void my_suite_before(void *data) lwm2m_init_message_fake.custom_fake = lwm2m_init_message_fake_default; coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_created; coap_packet_append_option_fake.custom_fake = NULL; + stub_lwm2m_server_disable(false); } static void my_suite_after(void *data) @@ -198,8 +202,6 @@ ZTEST(lwm2m_rd_client, test_start_registration_ok) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -207,6 +209,7 @@ ZTEST(lwm2m_rd_client, test_start_registration_ok) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert(lwm2m_rd_client_ctx() == &ctx, ""); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); @@ -228,8 +231,6 @@ ZTEST(lwm2m_rd_client, test_register_update_too_small_lifetime_to_default) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -237,6 +238,7 @@ ZTEST(lwm2m_rd_client, test_register_update_too_small_lifetime_to_default) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert(lwm2m_rd_client_ctx() == &ctx, ""); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); @@ -249,14 +251,13 @@ ZTEST(lwm2m_rd_client, test_timeout_resume_registration) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert(lwm2m_rd_client_ctx() == &ctx, ""); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); @@ -273,16 +274,17 @@ ZTEST(lwm2m_rd_client, test_start_registration_timeout) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_timeout_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); - zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DISCONNECT), NULL); + test_prepare_pending_message_cb(&message_reply_timeout_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT), NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT), NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT), NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_NETWORK_ERROR), NULL); } ZTEST(lwm2m_rd_client, test_start_registration_fail) @@ -291,8 +293,6 @@ ZTEST(lwm2m_rd_client, test_start_registration_fail) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -302,8 +302,15 @@ ZTEST(lwm2m_rd_client, test_start_registration_fail) lwm2m_init_message_fake.custom_fake = lwm2m_init_message_fake_default; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE), + NULL); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE), NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_FAILURE), + NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_NETWORK_ERROR), + NULL); } ZTEST(lwm2m_rd_client, test_start_registration_update) @@ -312,8 +319,6 @@ ZTEST(lwm2m_rd_client, test_start_registration_update) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -321,6 +326,7 @@ ZTEST(lwm2m_rd_client, test_start_registration_update) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); @@ -335,8 +341,6 @@ ZTEST(lwm2m_rd_client, test_rx_off) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -344,6 +348,7 @@ ZTEST(lwm2m_rd_client, test_rx_off) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); @@ -359,8 +364,6 @@ ZTEST(lwm2m_rd_client, test_start_registration_update_fail) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -368,6 +371,7 @@ ZTEST(lwm2m_rd_client, test_start_registration_update_fail) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); @@ -384,8 +388,6 @@ ZTEST(lwm2m_rd_client, test_registration_update_timeout) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -393,6 +395,7 @@ ZTEST(lwm2m_rd_client, test_registration_update_timeout) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); test_prepare_pending_message_cb(&message_reply_timeout_cb_default); @@ -415,8 +418,6 @@ ZTEST(lwm2m_rd_client, test_deregistration_timeout) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -424,6 +425,7 @@ ZTEST(lwm2m_rd_client, test_deregistration_timeout) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); @@ -439,8 +441,6 @@ ZTEST(lwm2m_rd_client, test_error_on_registration_update) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -449,6 +449,8 @@ ZTEST(lwm2m_rd_client, test_error_on_registration_update) coap_packet_append_option_fake.custom_fake = NULL; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); @@ -482,8 +484,6 @@ ZTEST(lwm2m_rd_client, test_suspend_resume_registration) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -491,6 +491,7 @@ ZTEST(lwm2m_rd_client, test_suspend_resume_registration) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); zassert_true(!lwm2m_rd_client_is_suspended(&ctx), NULL); @@ -517,8 +518,6 @@ ZTEST(lwm2m_rd_client, test_suspend_stop_resume) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -527,6 +526,7 @@ ZTEST(lwm2m_rd_client, test_suspend_stop_resume) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); zassert_true(lwm2m_rd_client_pause() == 0, NULL); @@ -544,8 +544,6 @@ ZTEST(lwm2m_rd_client, test_socket_error) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -554,6 +552,7 @@ ZTEST(lwm2m_rd_client, test_socket_error) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); @@ -569,8 +568,6 @@ ZTEST(lwm2m_rd_client, test_socket_error_on_stop) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -579,6 +576,7 @@ ZTEST(lwm2m_rd_client, test_socket_error_on_stop) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); @@ -608,8 +606,6 @@ ZTEST(lwm2m_rd_client, test_engine_trigger_bootstrap) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -617,6 +613,7 @@ ZTEST(lwm2m_rd_client, test_engine_trigger_bootstrap) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); lwm2m_get_bool_fake.custom_fake = lwm2m_get_bool_fake_true; @@ -638,8 +635,6 @@ ZTEST(lwm2m_rd_client, test_bootstrap_timeout) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_timeout_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -651,6 +646,7 @@ ZTEST(lwm2m_rd_client, test_bootstrap_timeout) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 1, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_timeout_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE), NULL); } @@ -661,8 +657,6 @@ ZTEST(lwm2m_rd_client, test_bootstrap_fail) (void)memset(&ctx, 0x0, sizeof(ctx)); - test_prepare_pending_message_cb(&message_reply_cb_default); - lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); @@ -674,27 +668,154 @@ ZTEST(lwm2m_rd_client, test_bootstrap_fail) coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; zassert_true(lwm2m_rd_client_start(&ctx, "Test", 1, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE), NULL); } -ZTEST(lwm2m_rd_client, test_bootstrap_no_srv_fallback_to_register) +ZTEST(lwm2m_rd_client, test_bootstrap_no_srv) { struct lwm2m_ctx ctx; (void)memset(&ctx, 0x0, sizeof(ctx)); + lwm2m_rd_client_init(); + test_lwm2m_engine_start_service(); + wait_for_service(1); + + coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; + zassert_true(lwm2m_rd_client_start(&ctx, "Test", 1, lwm2m_event_cb, lwm2m_observe_cb) == 0, + NULL); test_prepare_pending_message_cb(&message_reply_cb_default); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE), + NULL); +} + +ZTEST(lwm2m_rd_client, test_disable_server) +{ + struct lwm2m_ctx ctx; + + (void)memset(&ctx, 0x0, sizeof(ctx)); lwm2m_rd_client_init(); test_lwm2m_engine_start_service(); wait_for_service(1); coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; - zassert_true(lwm2m_rd_client_start(&ctx, "Test", 1, lwm2m_event_cb, lwm2m_observe_cb) == 0, + zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), + NULL); + coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_deleted; + stub_lwm2m_server_disable(true); + lwm2m_rd_client_server_disabled(0); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_SERVER_DISABLED), + NULL); +} + +ZTEST(lwm2m_rd_client, test_disable_server_stop) +{ + struct lwm2m_ctx ctx; + + (void)memset(&ctx, 0x0, sizeof(ctx)); + + lwm2m_rd_client_init(); + test_lwm2m_engine_start_service(); + wait_for_service(1); + + coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; + zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, + NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), + NULL); + coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_deleted; + stub_lwm2m_server_disable(true); + lwm2m_rd_client_server_disabled(0); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_SERVER_DISABLED), + NULL); + wait_for_service(1); + zassert_true(lwm2m_rd_client_stop(&ctx, lwm2m_event_cb, true) == 0, NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_DISCONNECT), NULL); +} + +ZTEST(lwm2m_rd_client, test_disable_server_connect) +{ + struct lwm2m_ctx ctx; + + (void)memset(&ctx, 0x0, sizeof(ctx)); + + lwm2m_rd_client_init(); + test_lwm2m_engine_start_service(); + wait_for_service(1); + + coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; + zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, + NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), + NULL); + coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_deleted; + stub_lwm2m_server_disable(true); + lwm2m_rd_client_server_disabled(0); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_SERVER_DISABLED), + NULL); + + wait_for_service(500); + + coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_created; + stub_lwm2m_server_disable(false); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), + NULL); +} + +ZTEST(lwm2m_rd_client, test_fallback_to_bootstrap) +{ + struct lwm2m_ctx ctx; + + (void)memset(&ctx, 0x0, sizeof(ctx)); + + lwm2m_rd_client_init(); + test_lwm2m_engine_start_service(); + wait_for_service(1); + + lwm2m_get_bool_fake.custom_fake = lwm2m_get_bool_fake_true; + zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, + NULL); + test_prepare_pending_message_cb(&message_reply_timeout_cb_default); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT), NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT), NULL); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REG_TIMEOUT), NULL); + + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_FAILURE), + NULL); +} + +ZTEST(lwm2m_rd_client, test_no_srv_fallback_to_bootstrap) +{ + struct lwm2m_ctx ctx; + + (void)memset(&ctx, 0x0, sizeof(ctx)); + + lwm2m_rd_client_init(); + test_lwm2m_engine_start_service(); + wait_for_service(1); + + coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_changed; + lwm2m_get_bool_fake.custom_fake = lwm2m_get_bool_fake_true; + stub_lwm2m_server_disable(true); + zassert_true(lwm2m_rd_client_start(&ctx, "Test", 0, lwm2m_event_cb, lwm2m_observe_cb) == 0, + NULL); + test_prepare_pending_message_cb(&message_reply_cb_default); + zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_BOOTSTRAP_REG_COMPLETE), + NULL); + coap_header_get_code_fake.custom_fake = coap_header_get_code_fake_created; + coap_find_options_fake.custom_fake = coap_find_options_do_registration_reply_cb_ok; + stub_lwm2m_server_disable(false); + engine_bootstrap_finish(); zassert_true(expect_lwm2m_rd_client_event(LWM2M_RD_CLIENT_EVENT_REGISTRATION_COMPLETE), NULL); } diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c index 3cbde9060ce..621057f8496 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c @@ -116,6 +116,24 @@ char *lwm2m_sprint_ip_addr_fake_default(const struct sockaddr *addr) DEFINE_FAKE_VALUE_FUNC(int, lwm2m_server_short_id_to_inst, uint16_t); DEFINE_FAKE_VALUE_FUNC(int, lwm2m_security_index_to_inst_id, int); +DEFINE_FAKE_VALUE_FUNC(int, lwm2m_security_short_id_to_inst, uint16_t); +DEFINE_FAKE_VALUE_FUNC(int, lwm2m_server_disable, uint16_t, k_timeout_t); +DEFINE_FAKE_VALUE_FUNC(uint8_t, lwm2m_server_get_prio, uint16_t); +DEFINE_FAKE_VOID_FUNC(lwm2m_server_reset_timestamps); + +static bool srv_disabled; +bool lwm2m_server_select(uint16_t *obj_inst_id) +{ + if (obj_inst_id) { + *obj_inst_id = 0; + } + return !srv_disabled; +} + +void stub_lwm2m_server_disable(bool disable) +{ + srv_disabled = disable; +} k_work_handler_t service; int64_t next; @@ -177,9 +195,13 @@ void test_lwm2m_engine_start_service(void) void test_lwm2m_engine_stop_service(void) { + struct k_work_sync sync; + pending_message_cb = NULL; + pending_message = NULL; running = false; k_work_cancel(&service_work); + k_work_flush(&service_work, &sync); } /* subsys/net/lib/lwm2m/lwm2m_message_handling.h */ diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.h b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.h index 1276dd5c109..0a3ce31d9e8 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.h +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.h @@ -59,6 +59,8 @@ DECLARE_FAKE_VALUE_FUNC(int, lwm2m_socket_close, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_close_socket, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_socket_suspend, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_security_inst_id_to_index, uint16_t); +DECLARE_FAKE_VALUE_FUNC(int, lwm2m_security_short_id_to_inst, uint16_t); +DECLARE_FAKE_VALUE_FUNC(int, lwm2m_security_index_to_inst_id, int); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_engine_connection_resume, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_push_queued_buffers, struct lwm2m_ctx *); DECLARE_FAKE_VOID_FUNC(lwm2m_engine_context_init, struct lwm2m_ctx *); @@ -68,10 +70,15 @@ DECLARE_FAKE_VOID_FUNC(lwm2m_engine_context_close, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(char *, lwm2m_sprint_ip_addr, const struct sockaddr *); char *lwm2m_sprint_ip_addr_fake_default(const struct sockaddr *addr); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_server_short_id_to_inst, uint16_t); -DECLARE_FAKE_VALUE_FUNC(int, lwm2m_security_index_to_inst_id, int); +DECLARE_FAKE_VALUE_FUNC(int, lwm2m_server_disable, uint16_t, k_timeout_t); +DECLARE_FAKE_VALUE_FUNC(uint8_t, lwm2m_server_get_prio, uint16_t); +DECLARE_FAKE_VOID_FUNC(lwm2m_server_reset_timestamps); + + void wait_for_service(uint16_t cycles); void test_lwm2m_engine_start_service(void); void test_lwm2m_engine_stop_service(void); +void stub_lwm2m_server_disable(bool disable); /* subsys/net/lib/lwm2m/lwm2m_message_handling.h */ DECLARE_FAKE_VALUE_FUNC(int, lwm2m_init_message, struct lwm2m_message *); From 1b26dba2528d3ba817bce40d0d5d95e312fdb977 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Fri, 1 Dec 2023 16:15:13 +0200 Subject: [PATCH 1041/1623] [nrf fromtree] test: lwm2m: Refactor tests to work with fallback changes In fallback refactoring to the LwM2M engine, some changes to the server object are visible in hard-coded test values. Also, add Endpoint wrapper class that ensures the registration state of the returned endpoint. Signed-off-by: Seppo Takalo (cherry picked from commit 30dcf1b30979c11f7fbd4b2edfa6d43ea8356667) --- .../net/lib/lwm2m/interop/pytest/conftest.py | 34 +++++++++++++++---- .../lib/lwm2m/interop/pytest/test_lwm2m.py | 9 ++--- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/tests/net/lib/lwm2m/interop/pytest/conftest.py b/tests/net/lib/lwm2m/interop/pytest/conftest.py index 9ca971b85c7..7d3ea4e7f80 100644 --- a/tests/net/lib/lwm2m/interop/pytest/conftest.py +++ b/tests/net/lib/lwm2m/interop/pytest/conftest.py @@ -27,6 +27,25 @@ logger = logging.getLogger(__name__) +class Endpoint: + def __init__(self, name: str, shell: Shell, registered: bool = False, bootstrap: bool = False): + self.name = name + self.registered = registered + self.bootstrap = bootstrap + self.shell = shell + self.last_update = 0.0 + + def check_update(self): + if not self.registered: + return + if self.last_update < time.time() - 5: + self.shell.exec_command('lwm2m update') + self.last_update = time.time() + + def __str__(self): + return self.name + + @pytest.fixture(scope='session') def leshan() -> Leshan: """ @@ -89,9 +108,8 @@ def endpoint_nosec(shell: Shell, dut: DeviceAdapter, leshan: Leshan) -> str: shell.exec_command('lwm2m write 1/0/0 -u16 1') shell.exec_command('lwm2m write 1/0/1 -u32 86400') shell.exec_command(f'lwm2m start {ep} -b 0') - dut.readlines_until(regex=f"RD Client started with endpoint '{ep}'", timeout=10.0) - yield ep + yield Endpoint(ep, shell) # All done shell.exec_command('lwm2m stop') @@ -125,7 +143,7 @@ def endpoint_bootstrap(shell: Shell, dut: DeviceAdapter, leshan: Leshan, leshan_ shell.exec_command(f'lwm2m write 0/0/5 -s {bs_passwd}') shell.exec_command(f'lwm2m start {ep} -b 1') - yield ep + yield Endpoint(ep, shell) shell.exec_command('lwm2m stop') dut.readlines_until(regex=r'.*Deregistration success', timeout=10.0) @@ -137,12 +155,16 @@ def endpoint_bootstrap(shell: Shell, dut: DeviceAdapter, leshan: Leshan, leshan_ leshan_bootstrap.delete_bs_device(ep) @pytest.fixture(scope='module') -def endpoint_registered(endpoint_bootstrap, shell: Shell, dut: DeviceAdapter) -> str: +def endpoint_registered(endpoint_bootstrap, dut: DeviceAdapter) -> str: """Fixture that returns an endpoint that is registered.""" - dut.readlines_until(regex='.*Registration Done', timeout=5.0) + if not endpoint_bootstrap.registered: + dut.readlines_until(regex='.*Registration Done', timeout=5.0) + endpoint_bootstrap.bootstrap = True + endpoint_bootstrap.registered = True return endpoint_bootstrap -@pytest.fixture(scope='module') +@pytest.fixture(scope='function') def endpoint(endpoint_registered) -> str: """Fixture that returns an endpoint that is registered.""" + endpoint_registered.check_update() return endpoint_registered diff --git a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py index 131acb68e14..ed7aaceac20 100644 --- a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py +++ b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py @@ -171,6 +171,7 @@ def verify_setting_basic_in_format(shell, leshan, endpoint, format): verify_server_object(server_obj) # Remove Read-Only resources, so we don't end up writing those del server_obj[0][0] + del server_obj[0][13] data = { 2: 101, 3: 1010, @@ -208,7 +209,7 @@ def test_LightweightM2M_1_1_int_222(shell: Shell, leshan: Leshan, endpoint: str) """LightweightM2M-1.1-int-222 - Read on Object""" resp = leshan.read(endpoint, '1') assert len(resp) == 1 - assert len(resp[1][0]) == 9 + assert len(resp[1][0]) == 11 resp = leshan.read(endpoint, '3') assert len(resp) == 1 assert len(resp[3]) == 1 @@ -218,7 +219,7 @@ def test_LightweightM2M_1_1_int_222(shell: Shell, leshan: Leshan, endpoint: str) def test_LightweightM2M_1_1_int_223(shell: Shell, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-223 - Read on Object Instance""" resp = leshan.read(endpoint, '1/0') - assert len(resp[0]) == 9 + assert len(resp[0]) == 11 resp = leshan.read(endpoint, '3/0') assert len(resp[0]) == 15 assert resp[0][0] == 'Zephyr' @@ -282,7 +283,7 @@ def test_LightweightM2M_1_1_int_229(shell: Shell, leshan: Leshan, endpoint: str) assert resp[3] is not None assert resp[1][0] is not None assert len(resp[3][0]) == 15 - assert len(resp[1][0]) == 9 + assert len(resp[1][0]) == 11 resp = leshan.composite_read(endpoint, ['1/0/1', '/3/0/11/0']) logger.debug(resp) @@ -370,7 +371,7 @@ def test_LightweightM2M_1_1_int_234(shell: Shell, leshan: Leshan, endpoint: str) def test_LightweightM2M_1_1_int_235(leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-235 - Read-Composite Operation on root path""" resp = leshan.composite_read(endpoint, ['/']) - expected_keys = [16, 1, 3, 5] + expected_keys = [1, 3, 5] missing_keys = [key for key in expected_keys if key not in resp.keys()] assert len(missing_keys) == 0 From 789fd359bd995a28bcfbeca023b98393b23655a5 Mon Sep 17 00:00:00 2001 From: Nick Ward Date: Tue, 5 Dec 2023 07:59:37 +1100 Subject: [PATCH 1042/1623] [nrf fromtree] net: lwm2m: device object: use LWM2M_DEVICE_ERROR_NONE Use LWM2M_DEVICE_ERROR_NONE macro. Signed-off-by: Nick Ward (cherry picked from commit b75a3f691d0130059e7943cb6aafebc21722b55a) --- subsys/net/lib/lwm2m/lwm2m_obj_device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_device.c b/subsys/net/lib/lwm2m/lwm2m_obj_device.c index c17815795c2..7df9df03a93 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_device.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_device.c @@ -89,7 +89,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); DEVICE_EXT_DEV_INFO_MAX) /* resource state variables */ -static uint8_t error_code_list[DEVICE_ERROR_CODE_MAX]; +static uint8_t error_code_list[DEVICE_ERROR_CODE_MAX] = { LWM2M_DEVICE_ERROR_NONE }; static time_t time_temp; static time_t time_offset; static uint8_t binding_mode[DEVICE_STRING_SHORT]; @@ -138,7 +138,7 @@ static int reset_error_list_cb(uint16_t obj_inst_id, /* "delete" error codes */ for (i = 0; i < DEVICE_ERROR_CODE_MAX; i++) { - error_code_list[i] = 0; + error_code_list[i] = LWM2M_DEVICE_ERROR_NONE; error_code_ri[i].res_inst_id = RES_INSTANCE_NOT_CREATED; } @@ -188,7 +188,7 @@ int lwm2m_device_add_err(uint8_t error_code) int i; for (i = 0; i < DEVICE_ERROR_CODE_MAX; i++) { - if (error_code_list[i] == 0) { + if (error_code_list[i] == LWM2M_DEVICE_ERROR_NONE) { break; } From ac786725181640eaabd87a07b8b81064a4410101 Mon Sep 17 00:00:00 2001 From: Nick Ward Date: Tue, 5 Dec 2023 08:11:36 +1100 Subject: [PATCH 1043/1623] [nrf fromtree] net: lwm2m: device object: optionally store error list in settings A device can be reset before the error code list is communicated to a LwM2M server so optionally store error list in settings so it can restored after reset. Signed-off-by: Nick Ward (cherry picked from commit b1d24e425c3a30cdf1aed3c54c25a2518061accc) --- subsys/net/lib/lwm2m/Kconfig | 7 ++ subsys/net/lib/lwm2m/lwm2m_obj_device.c | 106 ++++++++++++++++++++++-- 2 files changed, 105 insertions(+), 8 deletions(-) diff --git a/subsys/net/lib/lwm2m/Kconfig b/subsys/net/lib/lwm2m/Kconfig index dd3c0c45618..1e5a7ac8f6a 100644 --- a/subsys/net/lib/lwm2m/Kconfig +++ b/subsys/net/lib/lwm2m/Kconfig @@ -392,6 +392,13 @@ config LWM2M_COMPOSITE_PATH_LIST_SIZE help Define path list size for Composite Read and send operation. +config LWM2M_DEVICE_ERROR_CODE_SETTINGS + bool "Use settings to store error codes across device resets" + depends on SETTINGS + help + Store the device error code list in settings. Ensures error list can + be transferred to LwM2M server even if the device is reset. + config LWM2M_DEVICE_PWRSRC_MAX int "Maximum # of device power source records" default 5 diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_device.c b/subsys/net/lib/lwm2m/lwm2m_obj_device.c index 7df9df03a93..9416b3cf92c 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_device.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_device.c @@ -1,6 +1,7 @@ /* * Copyright (c) 2017 Linaro Limited * Copyright (c) 2018-2019 Foundries.io + * Copyright (c) 2023 FTP Technologies * * SPDX-License-Identifier: Apache-2.0 */ @@ -19,6 +20,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #include #include +#include #include "lwm2m_object.h" #include "lwm2m_engine.h" @@ -129,10 +131,12 @@ static struct lwm2m_engine_res_inst res_inst[RESOURCE_INSTANCE_COUNT]; /* save error code resource instance point so we can easily clear later */ static struct lwm2m_engine_res_inst *error_code_ri; +#define SETTINGS_SUBTREE_LWM2M_OBJ_DEVICE "lwm2m_obj_dev" +#define ERROR_LIST_KEY "err" + /* callbacks */ -static int reset_error_list_cb(uint16_t obj_inst_id, - uint8_t *args, uint16_t args_len) +static void reset_error_list(void) { int i; @@ -144,8 +148,29 @@ static int reset_error_list_cb(uint16_t obj_inst_id, /* Default error code indicating no error */ error_code_ri[0].res_inst_id = 0; +} + +static int reset_error_list_cb(uint16_t obj_inst_id, + uint8_t *args, uint16_t args_len) +{ + int ret = 0; + + ARG_UNUSED(obj_inst_id); + ARG_UNUSED(args); + ARG_UNUSED(args_len); + + reset_error_list(); - return 0; + lwm2m_notify_observer(LWM2M_OBJECT_DEVICE_ID, 0, DEVICE_ERROR_CODE_ID); + + if (IS_ENABLED(CONFIG_LWM2M_DEVICE_ERROR_CODE_SETTINGS)) { + ret = settings_delete(SETTINGS_SUBTREE_LWM2M_OBJ_DEVICE "/" ERROR_LIST_KEY); + if (ret != 0) { + LOG_ERR("Couldn't save error list: %d", ret); + } + } + + return ret; } static void *current_time_read_cb(uint16_t obj_inst_id, uint16_t res_id, @@ -182,9 +207,9 @@ static int current_time_post_write_cb(uint16_t obj_inst_id, uint16_t res_id, } /* error code function */ - int lwm2m_device_add_err(uint8_t error_code) { + int ret = 0; int i; for (i = 0; i < DEVICE_ERROR_CODE_MAX; i++) { @@ -206,7 +231,15 @@ int lwm2m_device_add_err(uint8_t error_code) error_code_ri[i].res_inst_id = i; lwm2m_notify_observer(LWM2M_OBJECT_DEVICE_ID, 0, DEVICE_ERROR_CODE_ID); - return 0; + if (IS_ENABLED(CONFIG_LWM2M_DEVICE_ERROR_CODE_SETTINGS)) { + ret = settings_save_one(SETTINGS_SUBTREE_LWM2M_OBJ_DEVICE "/" ERROR_LIST_KEY, + error_code_list, i + 1); + if (ret != 0) { + LOG_ERR("Couldn't save error list: %d", ret); + } + } + + return ret; } static void device_periodic_service(struct k_work *work) @@ -219,6 +252,49 @@ int lwm2m_update_device_service_period(uint32_t period_ms) return lwm2m_engine_update_service_period(device_periodic_service, period_ms); } +static int lwm2m_obj_device_settings_set(const char *name, size_t len, + settings_read_cb read_cb, void *cb_arg) +{ + const char *next; + int rc; + int i; + + if (settings_name_steq(name, ERROR_LIST_KEY, &next) && !next) { + if (len > sizeof(error_code_list)) { + LOG_ERR("Error code list too large: %u", len); + return -EINVAL; + } + + rc = read_cb(cb_arg, error_code_list, sizeof(error_code_list)); + if (rc == 0) { + reset_error_list(); + return 0; + } else if (rc > 0) { + for (i = 0; i < ARRAY_SIZE(error_code_list); i++) { + if (i < rc) { + error_code_ri[i].res_inst_id = i; + } else { + /* Reset remaining error code instances */ + error_code_list[i] = LWM2M_DEVICE_ERROR_NONE; + error_code_ri[i].res_inst_id = RES_INSTANCE_NOT_CREATED; + } + } + return 0; + } + + LOG_ERR("Error code list read failure: %d", rc); + + return rc; + } + + return -ENOENT; +} + +static struct settings_handler lwm2m_obj_device_settings_handler = { + .name = SETTINGS_SUBTREE_LWM2M_OBJ_DEVICE, + .h_set = lwm2m_obj_device_settings_set, +}; + static struct lwm2m_engine_obj_inst *device_create(uint16_t obj_inst_id) { int i = 0, j = 0; @@ -271,7 +347,7 @@ static struct lwm2m_engine_obj_inst *device_create(uint16_t obj_inst_id) static int lwm2m_device_init(void) { struct lwm2m_engine_obj_inst *obj_inst = NULL; - int ret = 0; + int ret; /* Set default values */ time_offset = 0U; @@ -294,12 +370,26 @@ static int lwm2m_device_init(void) LOG_DBG("Create LWM2M instance 0 error: %d", ret); } - /* Create the default error code resource instance */ - lwm2m_device_add_err(0); + /* Ensure error list is reset if not loaded from settings */ + reset_error_list(); + + /* Load error code resource instances */ + if (IS_ENABLED(CONFIG_LWM2M_DEVICE_ERROR_CODE_SETTINGS)) { + ret = settings_register(&lwm2m_obj_device_settings_handler); + if (ret == 0) { + ret = settings_load_subtree(SETTINGS_SUBTREE_LWM2M_OBJ_DEVICE); + if (ret != 0) { + LOG_ERR("Settings load failed: %d", ret); + } + } else { + LOG_ERR("Settings register failed: %d", ret); + } + } /* call device_periodic_service() every 10 seconds */ ret = lwm2m_engine_add_service(device_periodic_service, DEVICE_SERVICE_INTERVAL_MS); + return ret; } From 20f9d5c5a19f5129fd5308b4fe69edd5428938f6 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Fri, 1 Dec 2023 09:32:14 +0100 Subject: [PATCH 1044/1623] [nrf fromtree] samples: net: sockets: coap_server: Remove observer events In preparation of migrating to net_mgmt events, we need to remove the observer event callback handler. Signed-off-by: Pieter De Gendt (cherry picked from commit 527640b72675b1030c047c023645d06988d4268a) --- samples/net/sockets/coap_server/prj.conf | 1 - samples/net/sockets/coap_server/src/observer.c | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/samples/net/sockets/coap_server/prj.conf b/samples/net/sockets/coap_server/prj.conf index 1a26e614786..e9ff24577b7 100644 --- a/samples/net/sockets/coap_server/prj.conf +++ b/samples/net/sockets/coap_server/prj.conf @@ -13,7 +13,6 @@ CONFIG_COAP=y CONFIG_COAP_SERVER=y CONFIG_COAP_SERVER_WELL_KNOWN_CORE=y CONFIG_COAP_WELL_KNOWN_BLOCK_WISE=n -CONFIG_COAP_OBSERVER_EVENTS=y # Kernel options CONFIG_ENTROPY_GENERATOR=y diff --git a/samples/net/sockets/coap_server/src/observer.c b/samples/net/sockets/coap_server/src/observer.c index 29b7b4ed472..6d39536e232 100644 --- a/samples/net/sockets/coap_server/src/observer.c +++ b/samples/net/sockets/coap_server/src/observer.c @@ -17,16 +17,6 @@ static int obs_counter; static void update_counter(struct k_work *work); K_WORK_DELAYABLE_DEFINE(obs_work, update_counter); -#ifdef CONFIG_COAP_OBSERVER_EVENTS - -static void observer_event(struct coap_resource *resource, struct coap_observer *observer, - enum coap_observer_event event) -{ - LOG_INF("Observer %s", event == COAP_OBSERVER_ADDED ? "added" : "removed"); -} - -#endif - static int send_notification_packet(struct coap_resource *resource, const struct sockaddr *addr, socklen_t addr_len, @@ -138,9 +128,6 @@ COAP_RESOURCE_DEFINE(obs, coap_server, .get = obs_get, .path = obs_path, .notify = obs_notify, -#ifdef CONFIG_COAP_OBSERVER_EVENTS - .observer_event_handler = observer_event, -#endif }); static void update_counter(struct k_work *work) From 9af0dc0c004d20a23b174d0d5a3ba8996a22a403 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Fri, 1 Dec 2023 09:00:47 +0100 Subject: [PATCH 1045/1623] [nrf fromtree] Revert "net: lib: coap: Add support for observer event callbacks" This reverts commit 5227f248153f67e05b0ede9f859deb6f63ed4456. The coap observer events will be replaced with net_mgmt events. Signed-off-by: Pieter De Gendt (cherry picked from commit f712441840463e796fd4f3089ab2d128af1407da) --- include/zephyr/net/coap.h | 30 ------------------------------ subsys/net/lib/coap/Kconfig | 6 ------ subsys/net/lib/coap/coap.c | 17 +---------------- 3 files changed, 1 insertion(+), 52 deletions(-) diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index a907d1311e1..dceed869b43 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -238,29 +238,6 @@ typedef int (*coap_method_t)(struct coap_resource *resource, typedef void (*coap_notify_t)(struct coap_resource *resource, struct coap_observer *observer); -/** - * @brief Event types for observer event callbacks. - */ -enum coap_observer_event { - /** An observer was added. */ - COAP_OBSERVER_ADDED = 0, - /** An observer was removed. */ - COAP_OBSERVER_REMOVED, -}; - -/** - * @typedef coap_observer_event_handler_t - * @brief Type of the handler being called when a resource's observers has been modified. - * Either an observer was added or removed. - * - * @param resource A pointer to a CoAP resource for which the event occurred - * @param observer The observer being added/removed - * @param event The event type - */ -typedef void (*coap_observer_event_handler_t)(struct coap_resource *resource, - struct coap_observer *observer, - enum coap_observer_event event); - /** * @brief Description of CoAP resource. * @@ -275,13 +252,6 @@ struct coap_resource { void *user_data; sys_slist_t observers; int age; -#if defined(CONFIG_COAP_OBSERVER_EVENTS) || defined(DOXYGEN) - /** - * Optional observer event callback function - * Only available when @kconfig{CONFIG_COAP_OBSERVER_EVENTS} is enabled. - */ - coap_observer_event_handler_t observer_event_handler; -#endif }; /** diff --git a/subsys/net/lib/coap/Kconfig b/subsys/net/lib/coap/Kconfig index 8e62983ea72..cc6bee04f53 100644 --- a/subsys/net/lib/coap/Kconfig +++ b/subsys/net/lib/coap/Kconfig @@ -89,12 +89,6 @@ config COAP_URI_WILDCARD This option enables MQTT-style wildcards in path. Disable it if resource path may contain plus or hash symbol. -config COAP_OBSERVER_EVENTS - bool "CoAP resource observer events" - help - This option enables to register a callback function to CoAP resources - that will be called when adding/removing observers. - config COAP_KEEP_USER_DATA bool "Keeping user data in the CoAP packet" help diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index 9fe62730b47..e2ff715aec6 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -1856,28 +1856,13 @@ bool coap_register_observer(struct coap_resource *resource, resource->age = 2; } -#ifdef CONFIG_COAP_OBSERVER_EVENTS - if (resource->observer_event_handler) { - resource->observer_event_handler(resource, observer, COAP_OBSERVER_ADDED); - } -#endif - return first; } bool coap_remove_observer(struct coap_resource *resource, struct coap_observer *observer) { - if (!sys_slist_find_and_remove(&resource->observers, &observer->list)) { - return false; - } - -#ifdef CONFIG_COAP_OBSERVER_EVENTS - if (resource->observer_event_handler) { - resource->observer_event_handler(resource, observer, COAP_OBSERVER_REMOVED); - } -#endif - return true; + return sys_slist_find_and_remove(&resource->observers, &observer->list); } static bool sockaddr_equal(const struct sockaddr *a, From 7b7d001bb68ed4cd5450127fa93c1e99a1047762 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 29 Nov 2023 16:53:09 +0100 Subject: [PATCH 1046/1623] [nrf fromtree] net: lib: coap: Introduce net mgmt events for CoAP Allow users to register net mgmt events callbacks for CoAP events. Signed-off-by: Pieter De Gendt (cherry picked from commit 5182dd24c60ceeb15c7cadd119003b3328af23f7) --- include/zephyr/net/coap_mgmt.h | 102 ++++++++++++++++++++++++++++++ subsys/net/lib/coap/coap.c | 30 ++++++++- subsys/net/lib/coap/coap_server.c | 25 +++++++- 3 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 include/zephyr/net/coap_mgmt.h diff --git a/include/zephyr/net/coap_mgmt.h b/include/zephyr/net/coap_mgmt.h new file mode 100644 index 00000000000..f19eec6eb4b --- /dev/null +++ b/include/zephyr/net/coap_mgmt.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023 Basalte bv + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief CoAP Events code public header + */ + +#ifndef ZEPHYR_INCLUDE_NET_COAP_MGMT_H_ +#define ZEPHYR_INCLUDE_NET_COAP_MGMT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief CoAP Manager Events + * @defgroup coap_mgmt CoAP Manager Events + * @ingroup networking + * @{ + */ + +/** @cond INTERNAL_HIDDEN */ + +/* CoAP events */ +#define _NET_COAP_LAYER NET_MGMT_LAYER_L4 +#define _NET_COAP_CODE 0x1c0 +#define _NET_COAP_IF_BASE (NET_MGMT_EVENT_BIT | \ + NET_MGMT_LAYER(_NET_COAP_LAYER) | \ + NET_MGMT_LAYER_CODE(_NET_COAP_CODE)) + +struct coap_service; +struct coap_resource; +struct coap_observer; + +/** @endcond */ + +enum net_event_coap_cmd { + /* Service events */ + NET_EVENT_COAP_CMD_SERVICE_STARTED = 1, + NET_EVENT_COAP_CMD_SERVICE_STOPPED, + /* Observer events */ + NET_EVENT_COAP_CMD_OBSERVER_ADDED, + NET_EVENT_COAP_CMD_OBSERVER_REMOVED, +}; + +/** + * @brief coap_mgmt event raised when a service has started + */ +#define NET_EVENT_COAP_SERVICE_STARTED \ + (_NET_COAP_IF_BASE | NET_EVENT_COAP_CMD_SERVICE_STARTED) + +/** + * @brief coap_mgmt event raised when a service has stopped + */ +#define NET_EVENT_COAP_SERVICE_STOPPED \ + (_NET_COAP_IF_BASE | NET_EVENT_COAP_CMD_SERVICE_STOPPED) + +/** + * @brief coap_mgmt event raised when an observer has been added to a resource + */ +#define NET_EVENT_COAP_OBSERVER_ADDED \ + (_NET_COAP_IF_BASE | NET_EVENT_COAP_CMD_OBSERVER_ADDED) + +/** + * @brief coap_mgmt event raised when an observer has been removed from a resource + */ +#define NET_EVENT_COAP_OBSERVER_REMOVED \ + (_NET_COAP_IF_BASE | NET_EVENT_COAP_CMD_OBSERVER_REMOVED) + +/** + * @brief CoAP Service event structure. + */ +struct net_event_coap_service { + /* The CoAP service for which the event is emitted */ + const struct coap_service *service; +}; + +/** + * @brief CoAP Observer event structure. + */ +struct net_event_coap_observer { + /* The CoAP resource for which the event is emitted */ + struct coap_resource *resource; + /* The observer that is added/removed */ + struct coap_observer *observer; +}; + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif /* ZEPHYR_INCLUDE_NET_COAP_MGMT_H_ */ diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index e2ff715aec6..c49264e6776 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -23,6 +23,7 @@ LOG_MODULE_REGISTER(net_coap, CONFIG_COAP_LOG_LEVEL); #include #include #include +#include #define COAP_PATH_ELEM_DELIM '/' #define COAP_PATH_ELEM_QUERY '?' @@ -1844,6 +1845,25 @@ void coap_observer_init(struct coap_observer *observer, net_ipaddr_copy(&observer->addr, addr); } +static inline void coap_observer_raise_event(struct coap_resource *resource, + struct coap_observer *observer, + uint32_t mgmt_event) +{ +#ifdef CONFIG_NET_MGMT_EVENT_INFO + const struct net_event_coap_observer net_event = { + .resource = resource, + .observer = observer, + }; + + net_mgmt_event_notify_with_info(mgmt_event, NULL, (void *)&net_event, sizeof(net_event)); +#else + ARG_UNUSED(resource); + ARG_UNUSED(observer); + + net_mgmt_event_notify(mgmt_event, NULL); +#endif +} + bool coap_register_observer(struct coap_resource *resource, struct coap_observer *observer) { @@ -1856,13 +1876,21 @@ bool coap_register_observer(struct coap_resource *resource, resource->age = 2; } + coap_observer_raise_event(resource, observer, NET_EVENT_COAP_OBSERVER_ADDED); + return first; } bool coap_remove_observer(struct coap_resource *resource, struct coap_observer *observer) { - return sys_slist_find_and_remove(&resource->observers, &observer->list); + if (!sys_slist_find_and_remove(&resource->observers, &observer->list)) { + return false; + } + + coap_observer_raise_event(resource, observer, NET_EVENT_COAP_OBSERVER_REMOVED); + + return true; } static bool sockaddr_equal(const struct sockaddr *a, diff --git a/subsys/net/lib/coap/coap_server.c b/subsys/net/lib/coap/coap_server.c index 386bc2081bb..ce312968ea7 100644 --- a/subsys/net/lib/coap/coap_server.c +++ b/subsys/net/lib/coap/coap_server.c @@ -14,6 +14,7 @@ LOG_MODULE_DECLARE(net_coap, CONFIG_COAP_LOG_LEVEL); #include #include #include +#include #include #ifdef CONFIG_ARCH_POSIX #include @@ -345,6 +346,21 @@ static inline bool coap_service_in_section(const struct coap_service *service) STRUCT_SECTION_END(coap_service) > service; } +static inline void coap_service_raise_event(const struct coap_service *service, uint32_t mgmt_event) +{ +#if defined(CONFIG_NET_MGMT_EVENT_INFO) + const struct net_event_coap_service net_event = { + .service = service, + }; + + net_mgmt_event_notify_with_info(mgmt_event, NULL, (void *)&net_event, sizeof(net_event)); +#else + ARG_UNUSED(service); + + net_mgmt_event_notify(mgmt_event, NULL); +#endif +} + int coap_service_start(const struct coap_service *service) { int ret; @@ -446,6 +462,8 @@ int coap_service_start(const struct coap_service *service) coap_server_update_services(); + coap_service_raise_event(service, NET_EVENT_COAP_SERVICE_STARTED); + return ret; close: @@ -469,17 +487,18 @@ int coap_service_stop(const struct coap_service *service) k_mutex_lock(&lock, K_FOREVER); if (service->data->sock_fd < 0) { - ret = -EALREADY; - goto end; + k_mutex_unlock(&lock); + return -EALREADY; } /* Closing a socket will trigger a poll event */ ret = zsock_close(service->data->sock_fd); service->data->sock_fd = -1; -end: k_mutex_unlock(&lock); + coap_service_raise_event(service, NET_EVENT_COAP_SERVICE_STOPPED); + return ret; } From 8461ad27e602773abf402d044b167a84d8037081 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Fri, 1 Dec 2023 10:12:19 +0100 Subject: [PATCH 1047/1623] [nrf fromtree] samples: net: sockets: coap_server: Add CoAP events example Add an example handler for CoAP events triggered by net_mgmt. Signed-off-by: Pieter De Gendt (cherry picked from commit 8b22c769a76f4618648f5d1e0ff7d9656f17665a) --- samples/net/sockets/coap_server/prj.conf | 5 ++ samples/net/sockets/coap_server/src/events.c | 50 ++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 samples/net/sockets/coap_server/src/events.c diff --git a/samples/net/sockets/coap_server/prj.conf b/samples/net/sockets/coap_server/prj.conf index e9ff24577b7..59d444db456 100644 --- a/samples/net/sockets/coap_server/prj.conf +++ b/samples/net/sockets/coap_server/prj.conf @@ -29,6 +29,11 @@ CONFIG_COAP_SERVER_SHELL=y # Configuration CONFIG_NET_CONFIG_SETTINGS=y +# Events +CONFIG_NET_MGMT=y +CONFIG_NET_MGMT_EVENT=y +CONFIG_NET_MGMT_EVENT_INFO=y + # Enable only one protocol, if you enable both sources # won't compile. # IPv6 Support diff --git a/samples/net/sockets/coap_server/src/events.c b/samples/net/sockets/coap_server/src/events.c new file mode 100644 index 00000000000..3f843fba017 --- /dev/null +++ b/samples/net/sockets/coap_server/src/events.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 Basalte bv + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +LOG_MODULE_DECLARE(net_coap_service_sample); + +#include +#include + +#define COAP_EVENTS_SET (NET_EVENT_COAP_OBSERVER_ADDED | NET_EVENT_COAP_OBSERVER_REMOVED | \ + NET_EVENT_COAP_SERVICE_STARTED | NET_EVENT_COAP_SERVICE_STOPPED) + +void coap_event_handler(uint32_t mgmt_event, struct net_if *iface, + void *info, size_t info_length, void *user_data) +{ + ARG_UNUSED(iface); + ARG_UNUSED(user_data); + + switch (mgmt_event) { + case NET_EVENT_COAP_OBSERVER_ADDED: + LOG_INF("CoAP observer added"); + break; + case NET_EVENT_COAP_OBSERVER_REMOVED: + LOG_INF("CoAP observer removed"); + break; + case NET_EVENT_COAP_SERVICE_STARTED: + if (info != NULL && info_length == sizeof(struct net_event_coap_service)) { + struct net_event_coap_service *net_event = info; + + LOG_INF("CoAP service %s started", net_event->service->name); + } else { + LOG_INF("CoAP service started"); + } + break; + case NET_EVENT_COAP_SERVICE_STOPPED: + if (info != NULL && info_length == sizeof(struct net_event_coap_service)) { + struct net_event_coap_service *net_event = info; + + LOG_INF("CoAP service %s stopped", net_event->service->name); + } else { + LOG_INF("CoAP service stopped"); + } + break; + } +} + +NET_MGMT_REGISTER_EVENT_HANDLER(coap_events, COAP_EVENTS_SET, coap_event_handler, NULL); From 09a0826979591e4bd0ce562b24d0c81c3a120d45 Mon Sep 17 00:00:00 2001 From: Marc Lasch Date: Tue, 5 Dec 2023 16:06:11 +0100 Subject: [PATCH 1048/1623] [nrf fromtree] net: lwm2m: Reduce dependency on firmware update pull Kconfig There are functions whose headers are only visible when CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT is selected. However these functions are used outside the scope of the firmware update pull functionality. This change allows to disable CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT while still being able to use the firmware update object. Signed-off-by: Marc Lasch (cherry picked from commit 8358cdd6975799c45dcfb3706851d6644bbbbbf6) --- include/zephyr/net/lwm2m.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/zephyr/net/lwm2m.h b/include/zephyr/net/lwm2m.h index 6ac0458af87..51324f63153 100644 --- a/include/zephyr/net/lwm2m.h +++ b/include/zephyr/net/lwm2m.h @@ -551,7 +551,6 @@ void lwm2m_firmware_set_cancel_cb_inst(uint16_t obj_inst_id, lwm2m_engine_user_c */ lwm2m_engine_user_cb_t lwm2m_firmware_get_cancel_cb_inst(uint16_t obj_inst_id); -#if defined(CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT) || defined(__DOXYGEN__) /** * @brief Set data callback to handle firmware update execute events. * @@ -588,8 +587,6 @@ void lwm2m_firmware_set_update_cb_inst(uint16_t obj_inst_id, lwm2m_engine_execut */ lwm2m_engine_execute_cb_t lwm2m_firmware_get_update_cb_inst(uint16_t obj_inst_id); #endif -#endif - #if defined(CONFIG_LWM2M_SWMGMT_OBJ_SUPPORT) || defined(__DOXYGEN__) From 191896cdb8935ad3c71bf4b3452f2ea4d9db2f82 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 23 Nov 2023 16:57:41 +0200 Subject: [PATCH 1049/1623] [nrf fromtree] test: lwm2m: Implement bootstrap tests 4 - 7 * LightweightM2M-1.1-int-4 - Bootstrap Delete * LightweightM2M-1.1-int-5 - Server Initiated Bootstrap * LightweightM2M-1.1-int-6 - Bootstrap Sequence * LightweightM2M-1.1-int-7 - Fallback to bootstrap Signed-off-by: Seppo Takalo (cherry picked from commit 51869b3e459f3872ee137ed66d25ccd1fd6ac3aa) --- tests/net/lib/lwm2m/interop/README.md | 8 +++ tests/net/lib/lwm2m/interop/prj.conf | 5 ++ .../lwm2m/interop/pytest/test_bootstrap.py | 63 ++++++++++++++++--- .../net/lib/lwm2m/interop/src/lwm2m-client.c | 11 ++++ 4 files changed, 79 insertions(+), 8 deletions(-) diff --git a/tests/net/lib/lwm2m/interop/README.md b/tests/net/lib/lwm2m/interop/README.md index 3acbfcc71f8..28d8e12ccca 100644 --- a/tests/net/lib/lwm2m/interop/README.md +++ b/tests/net/lib/lwm2m/interop/README.md @@ -125,6 +125,14 @@ Tests are written from test spec; |---------|------|-----| |LightweightM2M-1.1-int-0 - Client Initiated Bootstrap |:white_check_mark:| | |LightweightM2M-1.1-int-1 - Client Initiated Bootstrap Full (PSK) |:white_check_mark:| | +|LightweightM2M-1.1-int-2 - Client Initiated Bootstrap Full (Cert) | |testcase not implemented | +|LightweightM2M-1.1-int-3 – Simple Bootstrap from Smartcard |:large_orange_diamond:|We don't have any smartcard support.| +|LightweightM2M-1.1-int-4 - Bootstrap Delete |:white_check_mark:| | +|LightweightM2M-1.1-int-5 - Server Initiated Bootstrap |:white_check_mark:| | +|LightweightM2M-1.1-int-6 - Bootstrap Sequence |:white_check_mark:| | +|LightweightM2M-1.1-int-7 - Fallback to bootstrap |:white_check_mark:| | +|LightweightM2M-1.1-int-8 - Bootstrap Read | |Test cannot be implemented from client side.| +|LightweightM2M-1.1-int-9 - Bootstrap and Configuration Consistency | |testcase not implemented | |LightweightM2M-1.1-int-101 - Initial Registration |:white_check_mark:| | |LightweightM2M-1.1-int-102 - Registration Update |:white_check_mark:| | |LightweightM2M-1.1-int-103 - Deregistration |:large_orange_diamond:|We don't have "disabled" functionality in server object| diff --git a/tests/net/lib/lwm2m/interop/prj.conf b/tests/net/lib/lwm2m/interop/prj.conf index 07bd9a0535d..43d4e73f081 100644 --- a/tests/net/lib/lwm2m/interop/prj.conf +++ b/tests/net/lib/lwm2m/interop/prj.conf @@ -44,6 +44,11 @@ CONFIG_LWM2M_RW_OMA_TLV_SUPPORT=y CONFIG_COAP_EXTENDED_OPTIONS_LEN=y CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=40 +# Speed up testing, we are running in non-lossy network +CONFIG_COAP_INIT_ACK_TIMEOUT_MS=1000 +CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT=n +CONFIG_LWM2M_RD_CLIENT_MAX_RETRIES=2 + # Use QUEUE mode by default CONFIG_LWM2M_QUEUE_MODE_ENABLED=y CONFIG_LWM2M_QUEUE_MODE_UPTIME=20 diff --git a/tests/net/lib/lwm2m/interop/pytest/test_bootstrap.py b/tests/net/lib/lwm2m/interop/pytest/test_bootstrap.py index 65561db0676..2a45669d912 100644 --- a/tests/net/lib/lwm2m/interop/pytest/test_bootstrap.py +++ b/tests/net/lib/lwm2m/interop/pytest/test_bootstrap.py @@ -15,9 +15,11 @@ """ import logging +import pytest from leshan import Leshan from twister_harness import Shell from twister_harness import DeviceAdapter +from conftest import Endpoint logger = logging.getLogger(__name__) @@ -29,24 +31,69 @@ # Bootstrap Interface: [0-99] # -def verify_LightweightM2M_1_1_int_0(shell: Shell, dut: DeviceAdapter): +def verify_LightweightM2M_1_1_int_0(dut: DeviceAdapter, endpoint_bootstrap: Endpoint): """LightweightM2M-1.1-int-0 - Client Initiated Bootstrap""" - dut.readlines_until(regex='.*Bootstrap started with endpoint', timeout=5.0) - dut.readlines_until(regex='.*Bootstrap registration done', timeout=5.0) - dut.readlines_until(regex='.*Bootstrap data transfer done', timeout=5.0) + dut.readlines_until(regex='.*Bootstrap transfer complete', timeout=5.0) + endpoint_bootstrap.bootstrap = True -def test_LightweightM2M_1_1_int_1(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint_bootstrap: str): +def test_LightweightM2M_1_1_int_1(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint_bootstrap: Endpoint): """LightweightM2M-1.1-int-1 - Client Initiated Bootstrap Full (PSK)""" - verify_LightweightM2M_1_1_int_0(shell, dut) + verify_LightweightM2M_1_1_int_0(dut, endpoint_bootstrap) verify_LightweightM2M_1_1_int_101(shell, dut, leshan, endpoint_bootstrap) verify_LightweightM2M_1_1_int_401(shell, leshan, endpoint_bootstrap) -def verify_LightweightM2M_1_1_int_101(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): +def test_LightweightM2M_1_1_int_4(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: Endpoint): + """LightweightM2M-1.1-int-4 - Bootstrap Delete""" + shell.exec_command('lwm2m create 1/2') + shell.exec_command('lwm2m read 1/2/0') + retval = int(shell.get_filtered_output(shell.exec_command('retval'))[0]) + assert retval == 0 + leshan.execute(endpoint, '1/0/9') + dut.readlines_until(regex='.*Registration Done', timeout=5.0) + shell.exec_command('lwm2m read 1/2/0') + retval = int(shell.get_filtered_output(shell.exec_command('retval'))[0]) + assert retval < 0 + logger.info('retval: %s', retval) + +def test_LightweightM2M_1_1_int_5(dut: DeviceAdapter, leshan: Leshan, endpoint: Endpoint): + """LightweightM2M-1.1-int-5 - Server Initiated Bootstrap""" + leshan.execute(endpoint, '1/0/9') + dut.readlines_until(regex='.*Server Initiated Bootstrap', timeout=1) + dut.readlines_until(regex='.*Bootstrap transfer complete', timeout=5.0) + dut.readlines_until(regex='.*Registration Done', timeout=5.0) + +def test_LightweightM2M_1_1_int_6(shell: Shell, dut: DeviceAdapter, endpoint: Endpoint): + """LightweightM2M-1.1-int-6 - Bootstrap Sequence""" + shell.exec_command('lwm2m stop') + dut.readlines_until(regex=r'.*Deregistration success', timeout=5) + shell.exec_command(f'lwm2m start {endpoint}') + lines = dut.readlines_until(regex='.*Registration Done', timeout=5.0) + assert not any("Bootstrap" in line for line in lines) + shell.exec_command('lwm2m stop') + dut.readlines_until(regex=r'.*Deregistration success', timeout=5) + shell.exec_command("lwm2m delete 1/0") + shell.exec_command("lwm2m delete 0/1") + shell.exec_command(f'lwm2m start {endpoint}') + lines = dut.readlines_until(regex='.*Registration Done', timeout=5.0) + assert any("Bootstrap" in line for line in lines) + +@pytest.mark.slow +def test_LightweightM2M_1_1_int_7(shell: Shell, dut: DeviceAdapter, endpoint: Endpoint): + """LightweightM2M-1.1-int-7 - Fallback to bootstrap""" + shell.exec_command('lwm2m stop') + dut.readlines_until(regex=r'.*Deregistration success', timeout=5) + shell.exec_command('lwm2m write 0/1/0 -s coaps://10.10.10.10:5684') + shell.exec_command(f'lwm2m start {endpoint}') + lines = dut.readlines_until(regex='.*Registration Done', timeout=600.0) + assert any("Bootstrap" in line for line in lines) + +def verify_LightweightM2M_1_1_int_101(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: Endpoint): """LightweightM2M-1.1-int-101 - Initial Registration""" dut.readlines_until(regex='.*Registration Done', timeout=5.0) assert leshan.get(f'/clients/{endpoint}') + endpoint.registered = True -def verify_LightweightM2M_1_1_int_401(shell: Shell, leshan: Leshan, endpoint: str): +def verify_LightweightM2M_1_1_int_401(shell: Shell, leshan: Leshan, endpoint: Endpoint): """LightweightM2M-1.1-int-401 - UDP Channel Security - Pre-shared Key Mode""" lines = shell.get_filtered_output(shell.exec_command('lwm2m read 0/0/0 -s')) host = lines[0] diff --git a/tests/net/lib/lwm2m/interop/src/lwm2m-client.c b/tests/net/lib/lwm2m/interop/src/lwm2m-client.c index b6634069fbd..a150f1b41cb 100644 --- a/tests/net/lib/lwm2m/interop/src/lwm2m-client.c +++ b/tests/net/lib/lwm2m/interop/src/lwm2m-client.c @@ -73,6 +73,17 @@ int set_socketoptions(struct lwm2m_ctx *ctx) ret = -errno; LOG_ERR("Failed to enable TLS_DTLS_CID: %d", ret); } + + /* Allow DTLS handshake to timeout much faster. + * these tests run on TUN/TAP network, so there should be no network latency. + */ + uint32_t min = 100; + uint32_t max = 500; + + zsock_setsockopt(ctx->sock_fd, SOL_TLS, TLS_DTLS_HANDSHAKE_TIMEOUT_MIN, &min, + sizeof(min)); + zsock_setsockopt(ctx->sock_fd, SOL_TLS, TLS_DTLS_HANDSHAKE_TIMEOUT_MAX, &max, + sizeof(max)); } return lwm2m_set_default_sockopt(ctx); } From 67e3744033592ac13037e4fb89ccafb569659133 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Mon, 4 Dec 2023 13:14:53 +0200 Subject: [PATCH 1050/1623] [nrf fromtree] test: lwm2m: Implement missing test case 103 Testcase 103 required "Disabled" functionality. Signed-off-by: Seppo Takalo (cherry picked from commit 725ceb72b70a836459b483a3f6634827493866f1) --- tests/net/lib/lwm2m/interop/README.md | 2 +- tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/net/lib/lwm2m/interop/README.md b/tests/net/lib/lwm2m/interop/README.md index 28d8e12ccca..7df931203aa 100644 --- a/tests/net/lib/lwm2m/interop/README.md +++ b/tests/net/lib/lwm2m/interop/README.md @@ -135,7 +135,7 @@ Tests are written from test spec; |LightweightM2M-1.1-int-9 - Bootstrap and Configuration Consistency | |testcase not implemented | |LightweightM2M-1.1-int-101 - Initial Registration |:white_check_mark:| | |LightweightM2M-1.1-int-102 - Registration Update |:white_check_mark:| | -|LightweightM2M-1.1-int-103 - Deregistration |:large_orange_diamond:|We don't have "disabled" functionality in server object| +|LightweightM2M-1.1-int-103 - Deregistration |:white_check_mark:| | |LightweightM2M-1.1-int-104 - Registration Update Trigge |:white_check_mark:| | |LightweightM2M-1.1-int-105 - Discarded Register Update |:white_check_mark:| | |LightweightM2M-1.1-int-107 - Extending the lifetime of a registration |:white_check_mark:| | diff --git a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py index ed7aaceac20..4e0ae207e8d 100644 --- a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py +++ b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py @@ -44,6 +44,17 @@ def test_LightweightM2M_1_1_int_102(shell: Shell, dut: DeviceAdapter, leshan: Le assert latest["lifetime"] == lifetime shell.exec_command('lwm2m write 1/0/1 -u32 86400') +def test_LightweightM2M_1_1_int_103(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): + """LightweightM2M-1.1-int-103 - Deregistration""" + leshan.execute(endpoint, '1/0/4') + dut.readlines_until(regex='LwM2M server disabled', timeout=5.0) + dut.readlines_until(regex='Deregistration success', timeout=5.0) + # Reset timers by restarting the client + shell.exec_command('lwm2m stop') + time.sleep(1) + shell.exec_command(f'lwm2m start {endpoint}') + dut.readlines_until(regex='.*Registration Done', timeout=5.0) + def test_LightweightM2M_1_1_int_104(shell: Shell, dut: DeviceAdapter, leshan: Leshan, endpoint: str): """LightweightM2M-1.1-int-104 - Registration Update Trigger""" shell.exec_command('lwm2m update') From c8e65c71cb7e43e07f41303d31b3ed45e1df03ac Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 7 Dec 2023 17:17:30 +0200 Subject: [PATCH 1051/1623] [nrf fromtree] net: lwm2m: Fix pmin handling on tickless If observed resource was written during the pMin period, it did not schedule any wake-up event into the future. Notify message would then only be generated as a result of any other (like Update) event. Refactor check_notifications() to follow same pattern as retransmit_req(). Return the next event timestamp, which could be now. Signed-off-by: Seppo Takalo (cherry picked from commit 005dc60d24bc378dffdc7c4ce12f4cd0cee1744a) --- subsys/net/lib/lwm2m/lwm2m_engine.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 45d3822bdbb..959d07419d3 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -581,14 +581,24 @@ void lwm2m_socket_del(struct lwm2m_ctx *ctx) lwm2m_engine_wake_up(); } -static void check_notifications(struct lwm2m_ctx *ctx, const int64_t timestamp) +/* Generate notify messages. Return timestamp of next Notify event */ +static int64_t check_notifications(struct lwm2m_ctx *ctx, const int64_t timestamp) { struct observe_node *obs; int rc; + int64_t next = INT64_MAX; lwm2m_registry_lock(); SYS_SLIST_FOR_EACH_CONTAINER(&ctx->observer, obs, node) { - if (!obs->event_timestamp || timestamp < obs->event_timestamp) { + if (!obs->event_timestamp) { + continue; + } + + if (obs->event_timestamp < next) { + next = obs->event_timestamp; + } + + if (timestamp < obs->event_timestamp) { continue; } /* Check That There is not pending process*/ @@ -604,6 +614,7 @@ static void check_notifications(struct lwm2m_ctx *ctx, const int64_t timestamp) obs->event_timestamp = engine_observe_shedule_next_event(obs, ctx->srv_obj_inst, timestamp); obs->last_timestamp = timestamp; + if (!rc) { /* create at most one notification */ goto cleanup; @@ -611,6 +622,7 @@ static void check_notifications(struct lwm2m_ctx *ctx, const int64_t timestamp) } cleanup: lwm2m_registry_unlock(); + return next; } static int socket_recv_message(struct lwm2m_ctx *client_ctx) @@ -704,7 +716,7 @@ static void socket_loop(void *p1, void *p2, void *p3) int i, rc; int64_t now, next; - int64_t timeout, next_retransmit; + int64_t timeout, next_tx; bool rd_client_paused; while (1) { @@ -741,12 +753,15 @@ static void socket_loop(void *p1, void *p2, void *p3) if (!sys_slist_is_empty(&sock_ctx[i]->pending_sends)) { continue; } - next_retransmit = retransmit_request(sock_ctx[i], now); - if (next_retransmit < next) { - next = next_retransmit; + next_tx = retransmit_request(sock_ctx[i], now); + if (next_tx < next) { + next = next_tx; } if (lwm2m_rd_client_is_registred(sock_ctx[i])) { - check_notifications(sock_ctx[i], now); + next_tx = check_notifications(sock_ctx[i], now); + if (next_tx < next) { + next = next_tx; + } } } From 162f4739d13bc2fb1d2cb84da2e2e820257cb6dc Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 7 Dec 2023 17:18:50 +0200 Subject: [PATCH 1052/1623] [nrf fromtree] test: lwm2m: Run interop tests in tickless mode Tickless mode is important to be tested against real server. Signed-off-by: Seppo Takalo (cherry picked from commit b4bdbfd76bca5f7b8dc321d0bea53e40d1a71d20) --- tests/net/lib/lwm2m/interop/prj.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/net/lib/lwm2m/interop/prj.conf b/tests/net/lib/lwm2m/interop/prj.conf index 43d4e73f081..6115e6f40e3 100644 --- a/tests/net/lib/lwm2m/interop/prj.conf +++ b/tests/net/lib/lwm2m/interop/prj.conf @@ -18,6 +18,9 @@ CONFIG_LWM2M=y CONFIG_LWM2M_IPSO_SUPPORT=y CONFIG_LWM2M_SHELL=y +CONFIG_LWM2M_TICKLESS=y +CONFIG_NET_SOCKETPAIR=y + #Enable Portfolio object CONFIG_LWM2M_PORTFOLIO_OBJ_SUPPORT=y From 613a359e5d0f6c2a96590b6fe2d211f6b6cef016 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Mon, 11 Dec 2023 08:44:26 +0100 Subject: [PATCH 1053/1623] [nrf fromtree] doc: connectivity: networking: api: Add doxygengroup for coap_mgmt Make sure the CoAP event doxygen is added to the documentation. Signed-off-by: Pieter De Gendt (cherry picked from commit 157b22e5ec92ed20ae654a3f2e5193fa79cb23f8) --- doc/connectivity/networking/api/coap_server.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/connectivity/networking/api/coap_server.rst b/doc/connectivity/networking/api/coap_server.rst index 9a91081f449..eb816665f41 100644 --- a/doc/connectivity/networking/api/coap_server.rst +++ b/doc/connectivity/networking/api/coap_server.rst @@ -245,3 +245,4 @@ API Reference ************* .. doxygengroup:: coap_service +.. doxygengroup:: coap_mgmt From 4bd6aac3a8765d2588baff084e543a800fc4487e Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Fri, 1 Dec 2023 10:22:23 +0200 Subject: [PATCH 1054/1623] [nrf fromtree] net: lib: coap: Add new API to configure retransmission settings Add new functions to the public CoAP API to configure CoAP packet retransmission settings. Application may need to re-configure the settings for example when cellular modem changes connection from LTE-M to NB-IoT or vice versa. Signed-off-by: Juha Ylinen (cherry picked from commit 69e28939dde528e10ccbd13b46520c2f3d32fd5b) --- include/zephyr/net/coap.h | 26 ++++++++++++++++++++++++ subsys/net/lib/coap/Kconfig | 7 +++++++ subsys/net/lib/coap/coap.c | 24 ++++++++++++++++++---- tests/net/lib/coap_client/CMakeLists.txt | 2 ++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index dceed869b43..e4374f41e34 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -1134,6 +1134,32 @@ int coap_resource_notify(struct coap_resource *resource); */ bool coap_request_is_observe(const struct coap_packet *request); +/** + * @brief CoAP transmission parameters. + */ +struct coap_transmission_parameters { + /** Initial AKC timeout. Value is used as a base value to retry pending CoAP packets. */ + uint32_t ack_timeout; + /** Set CoAP retry backoff factor. A value of 200 means a factor of 2.0. */ + uint16_t coap_backoff_percent; + /** Maximum number of retransmissions. */ + uint8_t max_retransmission; +}; + +/** + * @brief Get currently active CoAP transmission parameters. + * + * @return CoAP transmission parameters structure. + */ +struct coap_transmission_parameters coap_get_transmission_parameters(void); + +/** + * @brief Set CoAP transmission parameters. + * + * @param params Pointer to the transmission parameters structure. + */ +void coap_set_transmission_parameters(const struct coap_transmission_parameters *params); + #ifdef __cplusplus } #endif diff --git a/subsys/net/lib/coap/Kconfig b/subsys/net/lib/coap/Kconfig index cc6bee04f53..f4d002d0c5d 100644 --- a/subsys/net/lib/coap/Kconfig +++ b/subsys/net/lib/coap/Kconfig @@ -82,6 +82,13 @@ config COAP_MAX_RETRANSMIT default 4 range 1 10 +config COAP_BACKOFF_PERCENT + int "Retransmission backoff factor for ACK timeout described as percentage" + default 200 + help + Factor described as percentage to extend CoAP ACK timeout for retransmissions. + A value of 200 means a factor of 2.0. + config COAP_URI_WILDCARD bool "Wildcards in CoAP resource path" default y diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index c49264e6776..c21e14e5ded 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -54,6 +54,12 @@ LOG_MODULE_REGISTER(net_coap, CONFIG_COAP_LOG_LEVEL); /* The CoAP message ID that is incremented each time coap_next_id() is called. */ static uint16_t message_id; +static struct coap_transmission_parameters coap_transmission_params = { + .max_retransmission = CONFIG_COAP_MAX_RETRANSMIT, + .ack_timeout = CONFIG_COAP_INIT_ACK_TIMEOUT_MS, + .coap_backoff_percent = CONFIG_COAP_BACKOFF_PERCENT +}; + static int insert_option(struct coap_packet *cpkt, uint16_t code, const uint8_t *value, uint16_t len); @@ -1673,9 +1679,9 @@ struct coap_pending *coap_pending_next_to_expire( static uint32_t init_ack_timeout(void) { #if defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT) - const uint32_t max_ack = CONFIG_COAP_INIT_ACK_TIMEOUT_MS * + const uint32_t max_ack = coap_transmission_params.ack_timeout * CONFIG_COAP_ACK_RANDOM_PERCENT / 100; - const uint32_t min_ack = CONFIG_COAP_INIT_ACK_TIMEOUT_MS; + const uint32_t min_ack = coap_transmission_params.ack_timeout; /* Randomly generated initial ACK timeout * ACK_TIMEOUT < INIT_ACK_TIMEOUT < ACK_TIMEOUT * ACK_RANDOM_FACTOR @@ -1683,7 +1689,7 @@ static uint32_t init_ack_timeout(void) */ return min_ack + (sys_rand32_get() % (max_ack - min_ack)); #else - return CONFIG_COAP_INIT_ACK_TIMEOUT_MS; + return coap_transmission_params.ack_timeout; #endif /* defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT) */ } @@ -1701,7 +1707,7 @@ bool coap_pending_cycle(struct coap_pending *pending) } pending->t0 += pending->timeout; - pending->timeout = pending->timeout << 1; + pending->timeout = pending->timeout * coap_transmission_params.coap_backoff_percent / 100; pending->retries--; return true; @@ -2006,3 +2012,13 @@ uint16_t coap_next_id(void) { return message_id++; } + +struct coap_transmission_parameters coap_get_transmission_parameters(void) +{ + return coap_transmission_params; +} + +void coap_set_transmission_parameters(const struct coap_transmission_parameters *params) +{ + coap_transmission_params = *params; +} diff --git a/tests/net/lib/coap_client/CMakeLists.txt b/tests/net/lib/coap_client/CMakeLists.txt index 2e94112f0b0..cb86d78f611 100644 --- a/tests/net/lib/coap_client/CMakeLists.txt +++ b/tests/net/lib/coap_client/CMakeLists.txt @@ -27,3 +27,5 @@ add_compile_definitions(CONFIG_COAP_LOG_LEVEL=4) add_compile_definitions(CONFIG_COAP_INIT_ACK_TIMEOUT_MS=200) add_compile_definitions(CONFIG_COAP_CLIENT_MAX_REQUESTS=2) add_compile_definitions(CONFIG_COAP_CLIENT_MAX_INSTANCES=2) +add_compile_definitions(CONFIG_COAP_MAX_RETRANSMIT=4) +add_compile_definitions(CONFIG_COAP_BACKOFF_PERCENT=200) From 1a65a63f833d09179133249c2133139d918845f0 Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Tue, 12 Dec 2023 10:28:26 -0600 Subject: [PATCH 1055/1623] [nrf fromtree] net: lib: lwm2m: use correct format specifier for LOG_ERR Use correct format specifier for LOG_ERR in lwm2m_obj_device.c. The previously used format specifier of %u was correct for 32 bit systems but would produce a build warning for 64 bit systems. Fixes #66441 Signed-off-by: Daniel DeGrasse (cherry picked from commit 3091ddc4fee7ead733cffc2e1565f45e680b74ff) --- subsys/net/lib/lwm2m/lwm2m_obj_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_device.c b/subsys/net/lib/lwm2m/lwm2m_obj_device.c index 9416b3cf92c..f5399fefc1e 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_device.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_device.c @@ -261,7 +261,7 @@ static int lwm2m_obj_device_settings_set(const char *name, size_t len, if (settings_name_steq(name, ERROR_LIST_KEY, &next) && !next) { if (len > sizeof(error_code_list)) { - LOG_ERR("Error code list too large: %u", len); + LOG_ERR("Error code list too large: %zu", len); return -EINVAL; } From 737dfd9d5bb4abe5abdef0661d3a5443c1611373 Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Tue, 12 Dec 2023 15:27:29 +0200 Subject: [PATCH 1056/1623] [nrf fromtree] net: lib: coap: Change coap_pending_init() Replace function parameter 'retries' with pointer to structure holding coap transmission parameters. This allows setting the retransmission parameters individually for each pending request. Add coap transmission parameters to coap_pending structure. Update migration guide and release notes. Signed-off-by: Juha Ylinen (cherry picked from commit d09d3d82ef0a6861b7632dac7cb0519da17919a1) --- doc/releases/migration-guide-3.6.rst | 22 ++++++++++++ doc/releases/release-notes-3.6.rst | 5 +++ include/zephyr/net/coap.h | 30 ++++++++-------- include/zephyr/net/coap_client.h | 5 ++- subsys/net/lib/coap/coap.c | 23 +++++++----- subsys/net/lib/coap/coap_client.c | 19 ++++------ subsys/net/lib/coap/coap_server.c | 7 ++-- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 6 ++-- tests/net/lib/coap/src/main.c | 2 +- tests/net/lib/coap_client/src/main.c | 35 ++++++++++++------- 10 files changed, 97 insertions(+), 57 deletions(-) diff --git a/doc/releases/migration-guide-3.6.rst b/doc/releases/migration-guide-3.6.rst index c1739adf74d..27567c3c052 100644 --- a/doc/releases/migration-guide-3.6.rst +++ b/doc/releases/migration-guide-3.6.rst @@ -150,6 +150,28 @@ Networking ``request`` argument for :c:func:`coap_well_known_core_get` is made ``const``. (:github:`64265`) +* CoAP observer events have moved from a callback function in a CoAP resource to the Network Events + subsystem. The ``CONFIG_COAP_OBSERVER_EVENTS`` configuration option has been removed. + (:github:`65936`) + +* The CoAP public API function :c:func:`coap_pending_init` has changed. The parameter + ``retries`` is replaced with a pointer to :c:struct:`coap_transmission_parameters`. This allows to + specify retransmission parameters of the confirmable message. It is safe to pass a NULL pointer to + use default values. + (:github:`66482`) + +* The IGMP multicast library now supports IGMPv3. This results in a minor change to the existing + api. The :c:func:`net_ipv4_igmp_join` now takes an additional argument of the type + ``const struct igmp_param *param``. This allows IGMPv3 to exclude/include certain groups of + addresses. If this functionality is not used or available (when using IGMPv2), you can safely pass + a NULL pointer. IGMPv3 can be enabled using the Kconfig ``CONFIG_NET_IPV4_IGMPV3``. + (:github:`65293`) + +* The network stack now uses a separate IPv4 TTL (time-to-live) value for multicast packets. + Before, the same TTL value was used for unicast and multicast packets. + The IPv6 hop limit value is also changed so that unicast and multicast packets can have a + different one. (:github:`65886`) + Other Subsystems ================ diff --git a/doc/releases/release-notes-3.6.rst b/doc/releases/release-notes-3.6.rst index a253434a085..f4d813432b1 100644 --- a/doc/releases/release-notes-3.6.rst +++ b/doc/releases/release-notes-3.6.rst @@ -195,6 +195,11 @@ Networking * CoAP: + * Added new API functions: + + * :c:func:`coap_get_transmission_parameters` + * :c:func:`coap_set_transmission_parameters` + * Connection Manager: * DHCP: diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index e4374f41e34..e303d5c8ad3 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -309,6 +309,18 @@ typedef int (*coap_reply_t)(const struct coap_packet *response, struct coap_reply *reply, const struct sockaddr *from); +/** + * @brief CoAP transmission parameters. + */ +struct coap_transmission_parameters { + /** Initial ACK timeout. Value is used as a base value to retry pending CoAP packets. */ + uint32_t ack_timeout; + /** Set CoAP retry backoff factor. A value of 200 means a factor of 2.0. */ + uint16_t coap_backoff_percent; + /** Maximum number of retransmissions. */ + uint8_t max_retransmission; +}; + /** * @brief Represents a request awaiting for an acknowledgment (ACK). */ @@ -320,6 +332,7 @@ struct coap_pending { uint8_t *data; /**< User allocated buffer */ uint16_t len; /**< Length of the CoAP packet */ uint8_t retries; /**< Number of times the request has been sent */ + struct coap_transmission_parameters params; /**< Transmission parameters */ }; /** @@ -989,14 +1002,15 @@ void coap_reply_init(struct coap_reply *reply, * confirmation message, initialized with data from @a request * @param request Message waiting for confirmation * @param addr Address to send the retransmission - * @param retries Maximum number of retransmissions of the message. + * @param params Pointer to the CoAP transmission parameters struct, + * or NULL to use default values * * @return 0 in case of success or negative in case of error. */ int coap_pending_init(struct coap_pending *pending, const struct coap_packet *request, const struct sockaddr *addr, - uint8_t retries); + const struct coap_transmission_parameters *params); /** * @brief Returns the next available pending struct, that can be used @@ -1134,18 +1148,6 @@ int coap_resource_notify(struct coap_resource *resource); */ bool coap_request_is_observe(const struct coap_packet *request); -/** - * @brief CoAP transmission parameters. - */ -struct coap_transmission_parameters { - /** Initial AKC timeout. Value is used as a base value to retry pending CoAP packets. */ - uint32_t ack_timeout; - /** Set CoAP retry backoff factor. A value of 200 means a factor of 2.0. */ - uint16_t coap_backoff_percent; - /** Maximum number of retransmissions. */ - uint8_t max_retransmission; -}; - /** * @brief Get currently active CoAP transmission parameters. * diff --git a/include/zephyr/net/coap_client.h b/include/zephyr/net/coap_client.h index c3de1abee27..e48048d5c26 100644 --- a/include/zephyr/net/coap_client.h +++ b/include/zephyr/net/coap_client.h @@ -83,7 +83,6 @@ struct coap_client_internal_request { uint32_t offset; uint32_t last_id; uint8_t request_tkl; - uint8_t retry_count; bool request_ongoing; struct coap_block_context recv_blk_ctx; struct coap_block_context send_blk_ctx; @@ -131,12 +130,12 @@ int coap_client_init(struct coap_client *client, const char *info); * @param sock Open socket file descriptor. * @param addr the destination address of the request, NULL if socket is already connected. * @param req CoAP request structure - * @param retries How many times to retry or -1 to use default. + * @param params Pointer to transmission parameters structure or NULL to use default values. * @return zero when operation started successfully or negative error code otherwise. */ int coap_client_req(struct coap_client *client, int sock, const struct sockaddr *addr, - struct coap_client_request *req, int retries); + struct coap_client_request *req, struct coap_transmission_parameters *params); /** * @} diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index c21e14e5ded..bfb643a8e8c 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -1553,7 +1553,7 @@ size_t coap_next_block(const struct coap_packet *cpkt, int coap_pending_init(struct coap_pending *pending, const struct coap_packet *request, const struct sockaddr *addr, - uint8_t retries) + const struct coap_transmission_parameters *params) { memset(pending, 0, sizeof(*pending)); @@ -1561,10 +1561,16 @@ int coap_pending_init(struct coap_pending *pending, memcpy(&pending->addr, addr, sizeof(*addr)); + if (params) { + pending->params = *params; + } else { + pending->params = coap_transmission_params; + } + pending->data = request->data; pending->len = request->offset; pending->t0 = k_uptime_get(); - pending->retries = retries; + pending->retries = pending->params.max_retransmission; return 0; } @@ -1676,12 +1682,12 @@ struct coap_pending *coap_pending_next_to_expire( return found; } -static uint32_t init_ack_timeout(void) +static uint32_t init_ack_timeout(const struct coap_transmission_parameters *params) { #if defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT) - const uint32_t max_ack = coap_transmission_params.ack_timeout * + const uint32_t max_ack = params->ack_timeout * CONFIG_COAP_ACK_RANDOM_PERCENT / 100; - const uint32_t min_ack = coap_transmission_params.ack_timeout; + const uint32_t min_ack = params->ack_timeout; /* Randomly generated initial ACK timeout * ACK_TIMEOUT < INIT_ACK_TIMEOUT < ACK_TIMEOUT * ACK_RANDOM_FACTOR @@ -1689,7 +1695,7 @@ static uint32_t init_ack_timeout(void) */ return min_ack + (sys_rand32_get() % (max_ack - min_ack)); #else - return coap_transmission_params.ack_timeout; + return params->ack_timeout; #endif /* defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT) */ } @@ -1697,8 +1703,7 @@ bool coap_pending_cycle(struct coap_pending *pending) { if (pending->timeout == 0) { /* Initial transmission. */ - pending->timeout = init_ack_timeout(); - + pending->timeout = init_ack_timeout(&pending->params); return true; } @@ -1707,7 +1712,7 @@ bool coap_pending_cycle(struct coap_pending *pending) } pending->t0 += pending->timeout; - pending->timeout = pending->timeout * coap_transmission_params.coap_backoff_percent / 100; + pending->timeout = pending->timeout * pending->params.coap_backoff_percent / 100; pending->retries--; return true; diff --git a/subsys/net/lib/coap/coap_client.c b/subsys/net/lib/coap/coap_client.c index a947b15ae8e..4bdf387a242 100644 --- a/subsys/net/lib/coap/coap_client.c +++ b/subsys/net/lib/coap/coap_client.c @@ -16,7 +16,6 @@ LOG_MODULE_DECLARE(net_coap, CONFIG_COAP_LOG_LEVEL); #define COAP_VERSION 1 #define COAP_SEPARATE_TIMEOUT 6000 #define COAP_PERIODIC_TIMEOUT 500 -#define DEFAULT_RETRY_AMOUNT 5 #define BLOCK1_OPTION_SIZE 4 #define PAYLOAD_MARKER_SIZE 1 @@ -60,7 +59,6 @@ static void reset_internal_request(struct coap_client_internal_request *request) { request->offset = 0; request->last_id = 0; - request->retry_count = 0; reset_block_contexts(request); } @@ -277,7 +275,7 @@ static int coap_client_init_request(struct coap_client *client, } int coap_client_req(struct coap_client *client, int sock, const struct sockaddr *addr, - struct coap_client_request *req, int retries) + struct coap_client_request *req, struct coap_transmission_parameters *params) { int ret; @@ -352,14 +350,8 @@ int coap_client_req(struct coap_client *client, int sock, const struct sockaddr /* only TYPE_CON messages need pending tracking */ if (coap_header_get_type(&internal_req->request) == COAP_TYPE_CON) { - if (retries == -1) { - internal_req->retry_count = DEFAULT_RETRY_AMOUNT; - } else { - internal_req->retry_count = retries; - } - ret = coap_pending_init(&internal_req->pending, &internal_req->request, - &client->address, internal_req->retry_count); + &client->address, params); if (ret < 0) { LOG_ERR("Failed to initialize pending struct"); @@ -692,9 +684,11 @@ static int handle_response(struct coap_client *client, const struct coap_packet } if (coap_header_get_type(&internal_req->request) == COAP_TYPE_CON) { + struct coap_transmission_parameters params = + internal_req->pending.params; ret = coap_pending_init(&internal_req->pending, &internal_req->request, &client->address, - internal_req->retry_count); + ¶ms); if (ret < 0) { LOG_ERR("Error creating pending"); k_mutex_unlock(&client->send_mutex); @@ -793,8 +787,9 @@ static int handle_response(struct coap_client *client, const struct coap_packet goto fail; } + struct coap_transmission_parameters params = internal_req->pending.params; ret = coap_pending_init(&internal_req->pending, &internal_req->request, - &client->address, internal_req->retry_count); + &client->address, ¶ms); if (ret < 0) { LOG_ERR("Error creating pending"); k_mutex_unlock(&client->send_mutex); diff --git a/subsys/net/lib/coap/coap_server.c b/subsys/net/lib/coap/coap_server.c index ce312968ea7..66e5dcbc32c 100644 --- a/subsys/net/lib/coap/coap_server.c +++ b/subsys/net/lib/coap/coap_server.c @@ -542,6 +542,8 @@ int coap_service_send(const struct coap_service *service, const struct coap_pack * try to send. */ if (coap_header_get_type(cpkt) == COAP_TYPE_CON) { + struct coap_transmission_parameters params; + struct coap_pending *pending = coap_pending_next_unused(service->data->pending, MAX_PENDINGS); @@ -550,8 +552,9 @@ int coap_service_send(const struct coap_service *service, const struct coap_pack goto send; } - ret = coap_pending_init(pending, cpkt, addr, - CONFIG_COAP_SERVICE_PENDING_RETRANSMITS); + params = coap_get_transmission_parameters(); + params.max_retransmission = CONFIG_COAP_SERVICE_PENDING_RETRANSMITS; + ret = coap_pending_init(pending, cpkt, addr, ¶ms); if (ret < 0) { LOG_WRN("Failed to init pending message for %s (%d)", service->name, ret); goto send; diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 02c62cee67c..677879304f8 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -654,8 +654,7 @@ int lwm2m_init_message(struct lwm2m_message *msg) goto cleanup; } - r = coap_pending_init(msg->pending, &msg->cpkt, &msg->ctx->remote_addr, - CONFIG_COAP_MAX_RETRANSMIT); + r = coap_pending_init(msg->pending, &msg->cpkt, &msg->ctx->remote_addr, NULL); if (r < 0) { LOG_ERR("Unable to initialize a pending " "retransmission (err:%d).", @@ -2594,8 +2593,7 @@ static int lwm2m_response_promote_to_con(struct lwm2m_message *msg) return -ENOMEM; } - ret = coap_pending_init(msg->pending, &msg->cpkt, &msg->ctx->remote_addr, - CONFIG_COAP_MAX_RETRANSMIT); + ret = coap_pending_init(msg->pending, &msg->cpkt, &msg->ctx->remote_addr, NULL); if (ret < 0) { LOG_ERR("Unable to initialize a pending " "retransmission (err:%d).", diff --git a/tests/net/lib/coap/src/main.c b/tests/net/lib/coap/src/main.c index c9d0456d332..52b6cf0fd2a 100644 --- a/tests/net/lib/coap/src/main.c +++ b/tests/net/lib/coap/src/main.c @@ -779,7 +779,7 @@ ZTEST(coap, test_retransmit_second_round) zassert_not_null(pending, "No free pending"); r = coap_pending_init(pending, &cpkt, (struct sockaddr *) &dummy_addr, - CONFIG_COAP_MAX_RETRANSMIT); + NULL); zassert_equal(r, 0, "Could not initialize packet"); /* We "send" the packet the first time here */ diff --git a/tests/net/lib/coap_client/src/main.c b/tests/net/lib/coap_client/src/main.c index e1240c5e2ed..7d99c738950 100644 --- a/tests/net/lib/coap_client/src/main.c +++ b/tests/net/lib/coap_client/src/main.c @@ -378,7 +378,7 @@ ZTEST(coap_client, test_get_request) k_sleep(K_MSEC(1)); LOG_INF("Send request"); - ret = coap_client_req(&client, 0, &address, &client_request, -1); + ret = coap_client_req(&client, 0, &address, &client_request, NULL); zassert_true(ret >= 0, "Sending request failed, %d", ret); set_socket_events(ZSOCK_POLLIN); @@ -409,7 +409,7 @@ ZTEST(coap_client, test_resend_request) k_sleep(K_MSEC(1)); LOG_INF("Send request"); - ret = coap_client_req(&client, 0, &address, &client_request, -1); + ret = coap_client_req(&client, 0, &address, &client_request, NULL); zassert_true(ret >= 0, "Sending request failed, %d", ret); k_sleep(K_MSEC(300)); set_socket_events(ZSOCK_POLLIN); @@ -441,7 +441,7 @@ ZTEST(coap_client, test_echo_option) k_sleep(K_MSEC(1)); LOG_INF("Send request"); - ret = coap_client_req(&client, 0, &address, &client_request, -1); + ret = coap_client_req(&client, 0, &address, &client_request, NULL); zassert_true(ret >= 0, "Sending request failed, %d", ret); set_socket_events(ZSOCK_POLLIN); @@ -472,7 +472,7 @@ ZTEST(coap_client, test_echo_option_next_req) k_sleep(K_MSEC(1)); LOG_INF("Send request"); - ret = coap_client_req(&client, 0, &address, &client_request, -1); + ret = coap_client_req(&client, 0, &address, &client_request, NULL); zassert_true(ret >= 0, "Sending request failed, %d", ret); set_socket_events(ZSOCK_POLLIN); @@ -487,7 +487,7 @@ ZTEST(coap_client, test_echo_option_next_req) client_request.len = strlen(payload); LOG_INF("Send next request"); - ret = coap_client_req(&client, 0, &address, &client_request, -1); + ret = coap_client_req(&client, 0, &address, &client_request, NULL); zassert_true(ret >= 0, "Sending request failed, %d", ret); set_socket_events(ZSOCK_POLLIN); @@ -516,7 +516,7 @@ ZTEST(coap_client, test_get_no_path) k_sleep(K_MSEC(1)); LOG_INF("Send request"); - ret = coap_client_req(&client, 0, &address, &client_request, -1); + ret = coap_client_req(&client, 0, &address, &client_request, NULL); zassert_equal(ret, -EINVAL, "Get request without path"); } @@ -541,7 +541,7 @@ ZTEST(coap_client, test_send_large_data) k_sleep(K_MSEC(1)); LOG_INF("Send request"); - ret = coap_client_req(&client, 0, &address, &client_request, -1); + ret = coap_client_req(&client, 0, &address, &client_request, NULL); zassert_true(ret >= 0, "Sending request failed, %d", ret); set_socket_events(ZSOCK_POLLIN); @@ -563,6 +563,11 @@ ZTEST(coap_client, test_no_response) .payload = NULL, .len = 0 }; + struct coap_transmission_parameters params = { + .ack_timeout = 200, + .coap_backoff_percent = 200, + .max_retransmission = 0 + }; client_request.payload = short_payload; client_request.len = strlen(short_payload); @@ -571,7 +576,7 @@ ZTEST(coap_client, test_no_response) LOG_INF("Send request"); clear_socket_events(); - ret = coap_client_req(&client, 0, &address, &client_request, 0); + ret = coap_client_req(&client, 0, &address, &client_request, ¶ms); zassert_true(ret >= 0, "Sending request failed, %d", ret); k_sleep(K_MSEC(300)); @@ -601,7 +606,7 @@ ZTEST(coap_client, test_separate_response) k_sleep(K_MSEC(1)); LOG_INF("Send request"); - ret = coap_client_req(&client, 0, &address, &client_request, -1); + ret = coap_client_req(&client, 0, &address, &client_request, NULL); zassert_true(ret >= 0, "Sending request failed, %d", ret); set_socket_events(ZSOCK_POLLIN); @@ -632,10 +637,10 @@ ZTEST(coap_client, test_multiple_requests) set_socket_events(ZSOCK_POLLIN); LOG_INF("Send request"); - ret = coap_client_req(&client, 0, &address, &client_request, -1); + ret = coap_client_req(&client, 0, &address, &client_request, NULL); zassert_true(ret >= 0, "Sending request failed, %d", ret); - ret = coap_client_req(&client, 0, &address, &client_request, -1); + ret = coap_client_req(&client, 0, &address, &client_request, NULL); zassert_true(ret >= 0, "Sending request failed, %d", ret); k_sleep(K_MSEC(5)); @@ -660,6 +665,11 @@ ZTEST(coap_client, test_unmatching_tokens) .payload = NULL, .len = 0 }; + struct coap_transmission_parameters params = { + .ack_timeout = 200, + .coap_backoff_percent = 200, + .max_retransmission = 0 + }; client_request.payload = short_payload; client_request.len = strlen(short_payload); @@ -667,7 +677,7 @@ ZTEST(coap_client, test_unmatching_tokens) z_impl_zsock_recvfrom_fake.custom_fake = z_impl_zsock_recvfrom_custom_fake_unmatching; LOG_INF("Send request"); - ret = coap_client_req(&client, 0, &address, &client_request, 0); + ret = coap_client_req(&client, 0, &address, &client_request, ¶ms); zassert_true(ret >= 0, "Sending request failed, %d", ret); set_socket_events(ZSOCK_POLLIN); @@ -675,4 +685,5 @@ ZTEST(coap_client, test_unmatching_tokens) k_sleep(K_MSEC(1)); clear_socket_events(); k_sleep(K_MSEC(500)); + zassert_equal(last_response_code, -ETIMEDOUT, "Unexpected response"); } From b953247879b2a9ef5acb901e561996c984e5cd3e Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Wed, 13 Dec 2023 15:13:18 +0200 Subject: [PATCH 1057/1623] [nrf fromtree] tests: net: coap: Add test case for transmission parameters Add new test case. Signed-off-by: Juha Ylinen (cherry picked from commit f9fa2ae77ccf71c5443e756338d2234ea89ecbc2) --- tests/net/lib/coap/src/main.c | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/net/lib/coap/src/main.c b/tests/net/lib/coap/src/main.c index 52b6cf0fd2a..d1903dea10c 100644 --- a/tests/net/lib/coap/src/main.c +++ b/tests/net/lib/coap/src/main.c @@ -1718,4 +1718,57 @@ ZTEST(coap, test_coap_packet_set_path) COAP_OPTION_URI_PATH); } +ZTEST(coap, test_transmission_parameters) +{ + struct coap_packet cpkt; + struct coap_pending *pending; + struct coap_transmission_parameters params; + uint8_t *data = data_buf[0]; + int r; + uint16_t id; + + params = coap_get_transmission_parameters(); + zassert_equal(params.ack_timeout, CONFIG_COAP_INIT_ACK_TIMEOUT_MS, "Wrong ACK timeout"); + zassert_equal(params.coap_backoff_percent, CONFIG_COAP_BACKOFF_PERCENT, + "Wrong backoff percent"); + zassert_equal(params.max_retransmission, CONFIG_COAP_MAX_RETRANSMIT, + "Wrong max retransmission value"); + + params.ack_timeout = 1000; + params.coap_backoff_percent = 150; + params.max_retransmission = 2; + + coap_set_transmission_parameters(¶ms); + + id = coap_next_id(); + + r = coap_packet_init(&cpkt, data, COAP_BUF_SIZE, COAP_VERSION_1, + COAP_TYPE_CON, 0, coap_next_token(), + COAP_METHOD_GET, id); + zassert_equal(r, 0, "Could not initialize packet"); + + pending = coap_pending_next_unused(pendings, NUM_PENDINGS); + zassert_not_null(pending, "No free pending"); + + params.ack_timeout = 3000; + params.coap_backoff_percent = 250; + params.max_retransmission = 3; + + r = coap_pending_init(pending, &cpkt, (struct sockaddr *) &dummy_addr, + ¶ms); + zassert_equal(r, 0, "Could not initialize packet"); + + zassert_equal(pending->params.ack_timeout, 3000, "Wrong ACK timeout"); + zassert_equal(pending->params.coap_backoff_percent, 250, "Wrong backoff percent"); + zassert_equal(pending->params.max_retransmission, 3, "Wrong max retransmission value"); + + r = coap_pending_init(pending, &cpkt, (struct sockaddr *) &dummy_addr, + NULL); + zassert_equal(r, 0, "Could not initialize packet"); + + zassert_equal(pending->params.ack_timeout, 1000, "Wrong ACK timeout"); + zassert_equal(pending->params.coap_backoff_percent, 150, "Wrong backoff percent"); + zassert_equal(pending->params.max_retransmission, 2, "Wrong max retransmission value"); +} + ZTEST_SUITE(coap, NULL, NULL, NULL, NULL, NULL); From ab3e1338b6df45aae5bb77faff8aaeab2e26950b Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Thu, 14 Dec 2023 15:53:28 +0100 Subject: [PATCH 1058/1623] [nrf fromtree] net: lib: coap: Use coap_transmission_parameters in coap_server Update coap_service_send and coap_resource_send to take an optional pointer argument to the newly introduced coap_transmission_parameters. Signed-off-by: Pieter De Gendt (cherry picked from commit 4807ada01ee98d52ad7aa5b36166529b683fc09b) --- .../networking/api/coap_server.rst | 4 ++-- include/zephyr/net/coap_service.h | 8 ++++++-- samples/net/sockets/coap_server/src/core.c | 2 +- samples/net/sockets/coap_server/src/large.c | 6 +++--- .../sockets/coap_server/src/location_query.c | 2 +- samples/net/sockets/coap_server/src/observer.c | 2 +- samples/net/sockets/coap_server/src/query.c | 2 +- samples/net/sockets/coap_server/src/separate.c | 4 ++-- samples/net/sockets/coap_server/src/test.c | 8 ++++---- subsys/net/lib/coap/Kconfig | 6 ------ subsys/net/lib/coap/coap_server.c | 18 ++++++++---------- 11 files changed, 29 insertions(+), 33 deletions(-) diff --git a/doc/connectivity/networking/api/coap_server.rst b/doc/connectivity/networking/api/coap_server.rst index eb816665f41..bd53630ad6c 100644 --- a/doc/connectivity/networking/api/coap_server.rst +++ b/doc/connectivity/networking/api/coap_server.rst @@ -97,7 +97,7 @@ The following is an example of a CoAP resource registered with our service: coap_packet_append_payload(&response, (uint8_t *)msg, sizeof(msg)); /* Send to response back to the client */ - return coap_resource_send(resource, &response, addr, addr_len); + return coap_resource_send(resource, &response, addr, addr_len, NULL); } static int my_put(struct coap_resource *resource, struct coap_packet *request, @@ -189,7 +189,7 @@ and send state updates. An example using a temperature sensor can look like: coap_packet_append_payload_marker(&response); coap_packet_append_payload(&response, (uint8_t *)payload, strlen(payload)); - return coap_resource_send(resource, &response, addr, addr_len); + return coap_resource_send(resource, &response, addr, addr_len, NULL); } static int temp_get(struct coap_resource *resource, struct coap_packet *request, diff --git a/include/zephyr/net/coap_service.h b/include/zephyr/net/coap_service.h index 6f038ce61e1..b894fecf519 100644 --- a/include/zephyr/net/coap_service.h +++ b/include/zephyr/net/coap_service.h @@ -235,10 +235,12 @@ int coap_service_is_running(const struct coap_service *service); * @param cpkt CoAP Packet to send * @param addr Peer address * @param addr_len Peer address length + * @param params Pointer to transmission parameters structure or NULL to use default values. * @return 0 in case of success or negative in case of error. */ int coap_service_send(const struct coap_service *service, const struct coap_packet *cpkt, - const struct sockaddr *addr, socklen_t addr_len); + const struct sockaddr *addr, socklen_t addr_len, + const struct coap_transmission_parameters *params); /** * @brief Send a CoAP message from the provided @p resource . @@ -249,10 +251,12 @@ int coap_service_send(const struct coap_service *service, const struct coap_pack * @param cpkt CoAP Packet to send * @param addr Peer address * @param addr_len Peer address length + * @param params Pointer to transmission parameters structure or NULL to use default values. * @return 0 in case of success or negative in case of error. */ int coap_resource_send(const struct coap_resource *resource, const struct coap_packet *cpkt, - const struct sockaddr *addr, socklen_t addr_len); + const struct sockaddr *addr, socklen_t addr_len, + const struct coap_transmission_parameters *params); /** * @brief Parse a CoAP observe request for the provided @p resource . diff --git a/samples/net/sockets/coap_server/src/core.c b/samples/net/sockets/coap_server/src/core.c index 276ab0d5de1..00f4adb4d34 100644 --- a/samples/net/sockets/coap_server/src/core.c +++ b/samples/net/sockets/coap_server/src/core.c @@ -45,7 +45,7 @@ static int core_get(struct coap_resource *resource, return r; } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } diff --git a/samples/net/sockets/coap_server/src/large.c b/samples/net/sockets/coap_server/src/large.c index 28a3eebe099..8656a5b53b1 100644 --- a/samples/net/sockets/coap_server/src/large.c +++ b/samples/net/sockets/coap_server/src/large.c @@ -87,7 +87,7 @@ static int large_get(struct coap_resource *resource, memset(&ctx, 0, sizeof(ctx)); } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } @@ -167,7 +167,7 @@ static int large_update_put(struct coap_resource *resource, return r; } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } @@ -239,7 +239,7 @@ static int large_create_post(struct coap_resource *resource, return r; } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } diff --git a/samples/net/sockets/coap_server/src/location_query.c b/samples/net/sockets/coap_server/src/location_query.c index b13079bc456..bce4eb67b86 100644 --- a/samples/net/sockets/coap_server/src/location_query.c +++ b/samples/net/sockets/coap_server/src/location_query.c @@ -59,7 +59,7 @@ static int location_query_post(struct coap_resource *resource, } } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } diff --git a/samples/net/sockets/coap_server/src/observer.c b/samples/net/sockets/coap_server/src/observer.c index 6d39536e232..8a14d316c61 100644 --- a/samples/net/sockets/coap_server/src/observer.c +++ b/samples/net/sockets/coap_server/src/observer.c @@ -80,7 +80,7 @@ static int send_notification_packet(struct coap_resource *resource, k_work_reschedule(&obs_work, K_SECONDS(5)); - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } diff --git a/samples/net/sockets/coap_server/src/query.c b/samples/net/sockets/coap_server/src/query.c index 10479b1e6f1..95272189d9c 100644 --- a/samples/net/sockets/coap_server/src/query.c +++ b/samples/net/sockets/coap_server/src/query.c @@ -89,7 +89,7 @@ static int query_get(struct coap_resource *resource, return r; } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } diff --git a/samples/net/sockets/coap_server/src/separate.c b/samples/net/sockets/coap_server/src/separate.c index c3f6f6c256e..68bba0bb473 100644 --- a/samples/net/sockets/coap_server/src/separate.c +++ b/samples/net/sockets/coap_server/src/separate.c @@ -43,7 +43,7 @@ static int separate_get(struct coap_resource *resource, return r; } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); if (r < 0) { return r; } @@ -86,7 +86,7 @@ static int separate_get(struct coap_resource *resource, return r; } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } diff --git a/samples/net/sockets/coap_server/src/test.c b/samples/net/sockets/coap_server/src/test.c index aa496a125b1..52885b31a5d 100644 --- a/samples/net/sockets/coap_server/src/test.c +++ b/samples/net/sockets/coap_server/src/test.c @@ -73,7 +73,7 @@ static int piggyback_get(struct coap_resource *resource, return r; } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } @@ -113,7 +113,7 @@ static int test_del(struct coap_resource *resource, return r; } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } @@ -160,7 +160,7 @@ static int test_put(struct coap_resource *resource, return r; } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } @@ -221,7 +221,7 @@ static int test_post(struct coap_resource *resource, } } - r = coap_resource_send(resource, &response, addr, addr_len); + r = coap_resource_send(resource, &response, addr, addr_len, NULL); return r; } diff --git a/subsys/net/lib/coap/Kconfig b/subsys/net/lib/coap/Kconfig index f4d002d0c5d..63396bb0518 100644 --- a/subsys/net/lib/coap/Kconfig +++ b/subsys/net/lib/coap/Kconfig @@ -202,12 +202,6 @@ config COAP_SERVICE_PENDING_MESSAGES help Maximum number of pending CoAP messages to retransmit per active service. -config COAP_SERVICE_PENDING_RETRANSMITS - int "CoAP retransmit count" - default 2 - help - Maximum number of retries to send a pending message. - config COAP_SERVICE_OBSERVERS int "CoAP service observers" default 3 diff --git a/subsys/net/lib/coap/coap_server.c b/subsys/net/lib/coap/coap_server.c index 66e5dcbc32c..28d5b8de47f 100644 --- a/subsys/net/lib/coap/coap_server.c +++ b/subsys/net/lib/coap/coap_server.c @@ -215,7 +215,7 @@ static int coap_server_process(int sock_fd) goto unlock; } - ret = coap_service_send(service, &response, &client_addr, client_addr_len); + ret = coap_service_send(service, &response, &client_addr, client_addr_len, NULL); } else { ret = coap_handle_request_len(&request, service->res_begin, COAP_SERVICE_RESOURCE_COUNT(service), @@ -246,7 +246,7 @@ static int coap_server_process(int sock_fd) goto unlock; } - ret = coap_service_send(service, &ack, &client_addr, client_addr_len); + ret = coap_service_send(service, &ack, &client_addr, client_addr_len, NULL); } } @@ -521,7 +521,8 @@ int coap_service_is_running(const struct coap_service *service) } int coap_service_send(const struct coap_service *service, const struct coap_packet *cpkt, - const struct sockaddr *addr, socklen_t addr_len) + const struct sockaddr *addr, socklen_t addr_len, + const struct coap_transmission_parameters *params) { int ret; @@ -542,8 +543,6 @@ int coap_service_send(const struct coap_service *service, const struct coap_pack * try to send. */ if (coap_header_get_type(cpkt) == COAP_TYPE_CON) { - struct coap_transmission_parameters params; - struct coap_pending *pending = coap_pending_next_unused(service->data->pending, MAX_PENDINGS); @@ -552,9 +551,7 @@ int coap_service_send(const struct coap_service *service, const struct coap_pack goto send; } - params = coap_get_transmission_parameters(); - params.max_retransmission = CONFIG_COAP_SERVICE_PENDING_RETRANSMITS; - ret = coap_pending_init(pending, cpkt, addr, ¶ms); + ret = coap_pending_init(pending, cpkt, addr, params); if (ret < 0) { LOG_WRN("Failed to init pending message for %s (%d)", service->name, ret); goto send; @@ -589,12 +586,13 @@ int coap_service_send(const struct coap_service *service, const struct coap_pack } int coap_resource_send(const struct coap_resource *resource, const struct coap_packet *cpkt, - const struct sockaddr *addr, socklen_t addr_len) + const struct sockaddr *addr, socklen_t addr_len, + const struct coap_transmission_parameters *params) { /* Find owning service */ COAP_SERVICE_FOREACH(svc) { if (COAP_SERVICE_HAS_RESOURCE(svc, resource)) { - return coap_service_send(svc, cpkt, addr, addr_len); + return coap_service_send(svc, cpkt, addr, addr_len, params); } } From a3324c83c81941b2a8ddea05ffbb002ac5085583 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Thu, 14 Dec 2023 16:06:55 +0100 Subject: [PATCH 1059/1623] [nrf fromtree] doc: migration-guide: 3.6: Add CoAP service send functions update. Add an entry to indicate the changes to the coap_service_send and coap_resource_send API functions. Signed-off-by: Pieter De Gendt (cherry picked from commit dee2fe27f658e715427215d477f298558f6b1381) --- doc/releases/migration-guide-3.6.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/releases/migration-guide-3.6.rst b/doc/releases/migration-guide-3.6.rst index 27567c3c052..eeac0a89b75 100644 --- a/doc/releases/migration-guide-3.6.rst +++ b/doc/releases/migration-guide-3.6.rst @@ -160,6 +160,10 @@ Networking use default values. (:github:`66482`) +* The CoAP public API functions :c:func:`coap_service_send` and :c:func:`coap_resource_send` have + changed. An additional parameter pointer to :c:struct:`coap_transmission_parameters` has been + added. It is safe to pass a NULL pointer to use default values. (:github:`66540`) + * The IGMP multicast library now supports IGMPv3. This results in a minor change to the existing api. The :c:func:`net_ipv4_igmp_join` now takes an additional argument of the type ``const struct igmp_param *param``. This allows IGMPv3 to exclude/include certain groups of From b03f75da925a56c6b939328dcc1130ed7f9046f5 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Mon, 18 Dec 2023 13:37:33 +0200 Subject: [PATCH 1060/1623] [nrf fromtree] net: coap: Add API to count number of pending requests Add coap_pendings_count() that return number of waiting requests on the pendings array. Signed-off-by: Seppo Takalo (cherry picked from commit 01568b573a93bf55ecd7da62ce1cab08746c9392) --- include/zephyr/net/coap.h | 9 +++++++++ subsys/net/lib/coap/coap.c | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index e303d5c8ad3..cd57c560bee 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -1112,6 +1112,15 @@ void coap_pending_clear(struct coap_pending *pending); */ void coap_pendings_clear(struct coap_pending *pendings, size_t len); +/** + * @brief Count number of pending requests. + * + * @param len Number of elements in array. + * @param pendings Array of pending requests. + * @return count of elements where timeout is not zero. + */ +size_t coap_pendings_count(struct coap_pending *pendings, size_t len); + /** * @brief Cancels awaiting for this reply, so it becomes available * again. User responsibility to free the memory associated with data. diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index bfb643a8e8c..d22ee29bea7 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -1734,6 +1734,19 @@ void coap_pendings_clear(struct coap_pending *pendings, size_t len) } } +size_t coap_pendings_count(struct coap_pending *pendings, size_t len) +{ + struct coap_pending *p = pendings; + size_t c = 0; + + for (size_t i = 0; i < len && p; i++, p++) { + if (p->timeout) { + c++; + } + } + return c; +} + /* Reordering according to RFC7641 section 3.4 but without timestamp comparison */ static inline bool is_newer(int v1, int v2) { From c431117e0aeb2ae0e62bbe38af41480cc9730b3f Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Mon, 18 Dec 2023 13:43:03 +0200 Subject: [PATCH 1061/1623] [nrf fromtree] net: lwm2m: Update TX timestamp on zsock_send() In slow networks, like Nb-IOT, when using queue mode, there might be significant delay between the time we put the packet into a transmission queue and the time we actually start transmitting. This might cause QUEUE_RX_OFF state to be triggered earlier than expected. Remedy the issue by updating the timestamp on the moment where packet is accepted by zsock_send(). Signed-off-by: Seppo Takalo (cherry picked from commit 0d650ffd2626e522a64d08525f62fdac75298c2c) --- subsys/net/lib/lwm2m/lwm2m_engine.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 959d07419d3..85a428eeb5d 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -684,6 +684,8 @@ static int socket_send_message(struct lwm2m_ctx *client_ctx) if (rc < 0) { LOG_ERR("Failed to send packet, err %d", errno); rc = -errno; + } else { + engine_update_tx_time(); } if (msg->type != COAP_TYPE_CON) { From aced8e7eb6e18ad4c3c12ee810883a3ff298866d Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 9 Nov 2023 11:59:09 +0200 Subject: [PATCH 1062/1623] [nrf fromtree] net: lwm2m: Transmission state indications Allow engine to give hints about ongoing CoAP transmissions. This information can be used to control various power saving modes for network interfaces. For example cellular networks might support release assist indicator. Signed-off-by: Seppo Takalo (cherry picked from commit 6161fbdf21fe5f567b5828c54f84c5e3405fca71) --- include/zephyr/net/lwm2m.h | 24 +++++++ samples/net/lwm2m_client/overlay-queue.conf | 2 + samples/net/lwm2m_client/src/lwm2m-client.c | 20 ++++++ subsys/net/lib/lwm2m/lwm2m_engine.c | 35 +++++++++- tests/net/lib/lwm2m/lwm2m_engine/src/main.c | 72 +++++++++++++++++++- tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c | 2 + tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h | 4 ++ 7 files changed, 155 insertions(+), 4 deletions(-) diff --git a/include/zephyr/net/lwm2m.h b/include/zephyr/net/lwm2m.h index 51324f63153..3fca8bffae3 100644 --- a/include/zephyr/net/lwm2m.h +++ b/include/zephyr/net/lwm2m.h @@ -134,6 +134,22 @@ typedef void (*lwm2m_ctx_event_cb_t)(struct lwm2m_ctx *ctx, enum lwm2m_rd_client_event event); +/** + * @brief Different traffic states of the LwM2M socket. + * + * This information can be used to give hints for the network interface + * that can decide what kind of power management should be used. + * + * These hints are given from CoAP layer messages, so usage of DTLS might affect the + * actual number of expected datagrams. + */ +enum lwm2m_socket_states { + LWM2M_SOCKET_STATE_ONGOING, /**< Ongoing traffic is expected. */ + LWM2M_SOCKET_STATE_ONE_RESPONSE, /**< One response is expected for the next message. */ + LWM2M_SOCKET_STATE_LAST, /**< Next message is the last one. */ + LWM2M_SOCKET_STATE_NO_DATA, /**< No more data is expected. */ +}; + /** * @brief LwM2M context structure to maintain information for a single * LwM2M connection. @@ -249,6 +265,14 @@ struct lwm2m_ctx { * copied into the actual resource buffer. */ uint8_t validate_buf[CONFIG_LWM2M_ENGINE_VALIDATION_BUFFER_SIZE]; + + /** + * Callback to indicate transmission states. + * Client application may request LwM2M engine to indicate hints about + * transmission states and use that information to control various power + * saving modes. + */ + void (*set_socket_state)(int fd, enum lwm2m_socket_states state); }; /** diff --git a/samples/net/lwm2m_client/overlay-queue.conf b/samples/net/lwm2m_client/overlay-queue.conf index 1adc9eda5ec..946c0fbab67 100644 --- a/samples/net/lwm2m_client/overlay-queue.conf +++ b/samples/net/lwm2m_client/overlay-queue.conf @@ -1,5 +1,7 @@ CONFIG_LWM2M_QUEUE_MODE_ENABLED=y CONFIG_LWM2M_QUEUE_MODE_UPTIME=20 +CONFIG_LWM2M_RD_CLIENT_STOP_POLLING_AT_IDLE=y + # Default lifetime is 1 day CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=86400 # Send update once an hour diff --git a/samples/net/lwm2m_client/src/lwm2m-client.c b/samples/net/lwm2m_client/src/lwm2m-client.c index c610f1ad8dd..2e9792e51ea 100644 --- a/samples/net/lwm2m_client/src/lwm2m-client.c +++ b/samples/net/lwm2m_client/src/lwm2m-client.c @@ -253,6 +253,25 @@ static void rd_client_event(struct lwm2m_ctx *client, } } +static void socket_state(int fd, enum lwm2m_socket_states state) +{ + (void) fd; + switch (state) { + case LWM2M_SOCKET_STATE_ONGOING: + LOG_DBG("LWM2M_SOCKET_STATE_ONGOING"); + break; + case LWM2M_SOCKET_STATE_ONE_RESPONSE: + LOG_DBG("LWM2M_SOCKET_STATE_ONE_RESPONSE"); + break; + case LWM2M_SOCKET_STATE_LAST: + LOG_DBG("LWM2M_SOCKET_STATE_LAST"); + break; + case LWM2M_SOCKET_STATE_NO_DATA: + LOG_DBG("LWM2M_SOCKET_STATE_NO_DATA"); + break; + } +} + static void observe_cb(enum lwm2m_observe_event event, struct lwm2m_obj_path *path, void *user_data) { @@ -367,6 +386,7 @@ int main(void) #if defined(CONFIG_LWM2M_DTLS_SUPPORT) client_ctx.tls_tag = CONFIG_LWM2M_APP_TLS_TAG; #endif + client_ctx.set_socket_state = socket_state; /* client_ctx.sec_obj_inst is 0 as a starting point */ lwm2m_rd_client_start(&client_ctx, endpoint, flags, rd_client_event, observe_cb); diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 85a428eeb5d..d5a289a111f 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -197,6 +197,11 @@ int lwm2m_socket_suspend(struct lwm2m_ctx *client_ctx) lwm2m_close_socket(client_ctx); /* store back the socket handle */ client_ctx->sock_fd = socket_temp_id; + + if (client_ctx->set_socket_state) { + client_ctx->set_socket_state(client_ctx->sock_fd, + LWM2M_SOCKET_STATE_NO_DATA); + } } return ret; @@ -659,10 +664,10 @@ static int socket_recv_message(struct lwm2m_ctx *client_ctx) return 0; } -static int socket_send_message(struct lwm2m_ctx *client_ctx) +static int socket_send_message(struct lwm2m_ctx *ctx) { int rc; - sys_snode_t *msg_node = sys_slist_get(&client_ctx->pending_sends); + sys_snode_t *msg_node = sys_slist_get(&ctx->pending_sends); struct lwm2m_message *msg; if (!msg_node) { @@ -679,6 +684,32 @@ static int socket_send_message(struct lwm2m_ctx *client_ctx) coap_pending_cycle(msg->pending); } + if (ctx->set_socket_state) { +#if defined(CONFIG_LWM2M_QUEUE_MODE_ENABLED) + bool empty = sys_slist_is_empty(&ctx->pending_sends) && + sys_slist_is_empty(&ctx->queued_messages); +#else + bool empty = sys_slist_is_empty(&ctx->pending_sends); +#endif + if (coap_pendings_count(ctx->pendings, ARRAY_SIZE(ctx->pendings)) > 1) { + empty = false; + } + + if (!empty) { + ctx->set_socket_state(ctx->sock_fd, LWM2M_SOCKET_STATE_ONGOING); + } else { + switch (msg->type) { + case COAP_TYPE_CON: + ctx->set_socket_state(ctx->sock_fd, + LWM2M_SOCKET_STATE_ONE_RESPONSE); + break; + default: + ctx->set_socket_state(ctx->sock_fd, LWM2M_SOCKET_STATE_LAST); + break; + } + } + } + rc = zsock_send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0); if (rc < 0) { diff --git a/tests/net/lib/lwm2m/lwm2m_engine/src/main.c b/tests/net/lib/lwm2m/lwm2m_engine/src/main.c index ed26380eccd..5d80f5d1049 100644 --- a/tests/net/lib/lwm2m/lwm2m_engine/src/main.c +++ b/tests/net/lib/lwm2m/lwm2m_engine/src/main.c @@ -13,10 +13,11 @@ #include "lwm2m_rd_client.h" #include "stubs.h" -#if defined(CONFIG_NATIVE_POSIX_SLOWDOWN_TO_REAL_TIME) +#if defined(CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME) #include "timer_model.h" #endif +#define LOG_LEVEL LOG_LEVEL_DBG LOG_MODULE_REGISTER(lwm2m_engine_test); DEFINE_FFF_GLOBALS; @@ -67,7 +68,7 @@ static void test_service(struct k_work *work) static void setup(void *data) { -#if defined(CONFIG_NATIVE_POSIX_SLOWDOWN_TO_REAL_TIME) +#if defined(CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME) /* It is enough that some slow-down is happening on sleeps, it does not have to be * real time */ @@ -467,3 +468,70 @@ ZTEST(lwm2m_engine, test_security) zassert_equal(tls_credential_add_fake.arg1_history[2], TLS_CREDENTIAL_CA_CERTIFICATE); zassert_equal(lwm2m_engine_stop(&ctx), 0); } + +static enum lwm2m_socket_states last_state; + +static void socket_state(int fd, enum lwm2m_socket_states state) +{ + (void) fd; + last_state = state; +} + +ZTEST(lwm2m_engine, test_socket_state) +{ + int ret; + struct lwm2m_ctx ctx = { + .remote_addr.sa_family = AF_INET, + .sock_fd = -1, + .set_socket_state = socket_state, + }; + struct lwm2m_message msg1 = { + .ctx = &ctx, + .type = COAP_TYPE_CON, + }; + struct lwm2m_message msg2 = msg1; + struct lwm2m_message ack = { + .ctx = &ctx, + .type = COAP_TYPE_ACK, + }; + + sys_slist_init(&ctx.pending_sends); + ret = lwm2m_engine_start(&ctx); + zassert_equal(ret, 0); + + /* One confimable in queue, should cause ONE_RESPONSE status */ + coap_pendings_count_fake.return_val = 1; + sys_slist_append(&ctx.pending_sends, &msg1.node); + set_socket_events(ZSOCK_POLLOUT); + k_sleep(K_MSEC(100)); + zassert_equal(last_state, LWM2M_SOCKET_STATE_ONE_RESPONSE); + + /* More than one messages in queue, not empty, should cause ONGOING */ + coap_pendings_count_fake.return_val = 2; + sys_slist_append(&ctx.pending_sends, &msg1.node); + sys_slist_append(&ctx.pending_sends, &msg2.node); + set_socket_events(ZSOCK_POLLOUT); + k_sleep(K_MSEC(100)); + zassert_equal(last_state, LWM2M_SOCKET_STATE_ONGOING); + + /* Last out, while waiting for ACK to both, should still cause ONGOING */ + coap_pendings_count_fake.return_val = 2; + set_socket_events(ZSOCK_POLLOUT); + k_sleep(K_MSEC(100)); + zassert_equal(last_state, LWM2M_SOCKET_STATE_ONGOING); + + /* Only one Ack transmiting, nothing expected back -> LAST */ + coap_pendings_count_fake.return_val = 0; + sys_slist_append(&ctx.pending_sends, &ack.node); + set_socket_events(ZSOCK_POLLOUT); + k_sleep(K_MSEC(100)); + zassert_equal(last_state, LWM2M_SOCKET_STATE_LAST); + + /* Socket suspended (as in QUEUE_RX_OFF), should cause NO_DATA */ + ret = lwm2m_socket_suspend(&ctx); + zassert_equal(ret, 0); + zassert_equal(last_state, LWM2M_SOCKET_STATE_NO_DATA); + + ret = lwm2m_engine_stop(&ctx); + zassert_equal(ret, 0); +} diff --git a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c index 5db155f1e29..0958d75a54a 100644 --- a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c +++ b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c @@ -19,6 +19,7 @@ DEFINE_FAKE_VALUE_FUNC(int, lwm2m_send_message_async, struct lwm2m_message *); DEFINE_FAKE_VOID_FUNC(lwm2m_registry_lock); DEFINE_FAKE_VOID_FUNC(lwm2m_registry_unlock); DEFINE_FAKE_VALUE_FUNC(bool, coap_pending_cycle, struct coap_pending *); +DEFINE_FAKE_VALUE_FUNC(size_t, coap_pendings_count, struct coap_pending *, size_t); DEFINE_FAKE_VALUE_FUNC(int, generate_notify_message, struct lwm2m_ctx *, struct observe_node *, void *); DEFINE_FAKE_VALUE_FUNC(int64_t, engine_observe_shedule_next_event, struct observe_node *, uint16_t, @@ -41,6 +42,7 @@ DEFINE_FAKE_VALUE_FUNC(int, lwm2m_delete_obj_inst, uint16_t, uint16_t); DEFINE_FAKE_VOID_FUNC(lwm2m_clear_block_contexts); DEFINE_FAKE_VALUE_FUNC(int, lwm2m_security_mode, struct lwm2m_ctx *); DEFINE_FAKE_VALUE_FUNC(int, z_impl_zsock_setsockopt, int, int, int, const void *, socklen_t); +DEFINE_FAKE_VOID_FUNC(engine_update_tx_time); static sys_slist_t obs_obj_path_list = SYS_SLIST_STATIC_INIT(&obs_obj_path_list); sys_slist_t *lwm2m_obs_obj_path_list(void) diff --git a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h index 7b8ca481f85..67c4cde883d 100644 --- a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h +++ b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h @@ -28,6 +28,7 @@ DECLARE_FAKE_VALUE_FUNC(int, lwm2m_rd_client_resume); DECLARE_FAKE_VALUE_FUNC(struct lwm2m_message *, find_msg, struct coap_pending *, struct coap_reply *); DECLARE_FAKE_VOID_FUNC(coap_pending_clear, struct coap_pending *); +DECLARE_FAKE_VALUE_FUNC(size_t, coap_pendings_count, struct coap_pending *, size_t); DECLARE_FAKE_VOID_FUNC(lwm2m_reset_message, struct lwm2m_message *, bool); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_send_message_async, struct lwm2m_message *); DECLARE_FAKE_VOID_FUNC(lwm2m_registry_lock); @@ -56,6 +57,7 @@ DECLARE_FAKE_VOID_FUNC(lwm2m_clear_block_contexts); DECLARE_FAKE_VALUE_FUNC(int, z_impl_zsock_connect, int, const struct sockaddr *, socklen_t); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_security_mode, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(int, z_impl_zsock_setsockopt, int, int, int, const void *, socklen_t); +DECLARE_FAKE_VOID_FUNC(engine_update_tx_time); #define DO_FOREACH_FAKE(FUNC) \ do { \ @@ -63,6 +65,7 @@ DECLARE_FAKE_VALUE_FUNC(int, z_impl_zsock_setsockopt, int, int, int, const void FUNC(lwm2m_rd_client_resume) \ FUNC(find_msg) \ FUNC(coap_pending_clear) \ + FUNC(coap_pendings_count) \ FUNC(lwm2m_reset_message) \ FUNC(lwm2m_send_message_async) \ FUNC(lwm2m_registry_lock) \ @@ -85,6 +88,7 @@ DECLARE_FAKE_VALUE_FUNC(int, z_impl_zsock_setsockopt, int, int, int, const void FUNC(z_impl_zsock_connect) \ FUNC(lwm2m_security_mode) \ FUNC(z_impl_zsock_setsockopt) \ + FUNC(engine_update_tx_time) \ } while (0) #endif /* STUBS_H */ From 3fe5a7ae2f6ef9a4d7e1cdbb99fffe5c1ba66330 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Wed, 20 Dec 2023 14:48:41 +0200 Subject: [PATCH 1063/1623] [nrf fromtree] net: lwm2m: Deprecate lwm2m_get/set_u64 Deprecate lwm2m_set_u64() and lwm2m_get_u64 as only LWM2M_RES_TYPE_S64 exist. Unsigned variant is not defined. Technically these might have worked OK, but it is undefined what happens to large unsigned values when those are converted to various payload formats (like CBOR) that might decode numbers differently depending of their signedness. Signed-off-by: Seppo Takalo (cherry picked from commit 071cad2e762b04e7ea782a1742ab35b802bbcd78) --- include/zephyr/net/lwm2m.h | 10 ++++++++++ subsys/net/lib/lwm2m/lwm2m_registry.c | 4 ++-- subsys/net/lib/lwm2m/lwm2m_shell.c | 10 ---------- .../net/lib/lwm2m/lwm2m_registry/src/lwm2m_registry.c | 10 ---------- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/include/zephyr/net/lwm2m.h b/include/zephyr/net/lwm2m.h index 3fca8bffae3..c643c32f0bf 100644 --- a/include/zephyr/net/lwm2m.h +++ b/include/zephyr/net/lwm2m.h @@ -1009,11 +1009,16 @@ int lwm2m_engine_set_u64(const char *pathstr, uint64_t value); /** * @brief Set resource (instance) value (u64) * + * @deprecated Unsigned 64bit value type does not exits. + * This is internally handled as a int64_t. + * Use lwm2m_set_s64() instead. + * * @param[in] path LwM2M path as a struct * @param[in] value u64 value * * @return 0 for success or negative in case of error. */ +__deprecated int lwm2m_set_u64(const struct lwm2m_obj_path *path, uint64_t value); /** @@ -1335,11 +1340,16 @@ int lwm2m_engine_get_u64(const char *pathstr, uint64_t *value); /** * @brief Get resource (instance) value (u64) * + * @deprecated Unsigned 64bit value type does not exits. + * This is internally handled as a int64_t. + * Use lwm2m_get_s64() instead. + * @param[in] path LwM2M path as a struct * @param[out] value u64 buffer to copy data into * * @return 0 for success or negative in case of error. */ +__deprecated int lwm2m_get_u64(const struct lwm2m_obj_path *path, uint64_t *value); /** diff --git a/subsys/net/lib/lwm2m/lwm2m_registry.c b/subsys/net/lib/lwm2m/lwm2m_registry.c index 210c5525756..1701b7f7412 100644 --- a/subsys/net/lib/lwm2m/lwm2m_registry.c +++ b/subsys/net/lib/lwm2m/lwm2m_registry.c @@ -890,7 +890,7 @@ int lwm2m_engine_set_u64(const char *pathstr, uint64_t value) if (ret < 0) { return ret; } - return lwm2m_set_u64(&path, value); + return lwm2m_set_s64(&path, (int64_t) value); } int lwm2m_set_s8(const struct lwm2m_obj_path *path, int8_t value) @@ -1378,7 +1378,7 @@ int lwm2m_engine_get_u64(const char *pathstr, uint64_t *value) if (ret < 0) { return ret; } - return lwm2m_get_u64(&path, value); + return lwm2m_get_s64(&path, (int64_t *) value); } int lwm2m_get_s8(const struct lwm2m_obj_path *path, int8_t *value) diff --git a/subsys/net/lib/lwm2m/lwm2m_shell.c b/subsys/net/lib/lwm2m/lwm2m_shell.c index a4cedf8cd62..aad7dc5d166 100644 --- a/subsys/net/lib/lwm2m/lwm2m_shell.c +++ b/subsys/net/lib/lwm2m/lwm2m_shell.c @@ -246,14 +246,6 @@ static int cmd_read(const struct shell *sh, size_t argc, char **argv) goto out; } shell_print(sh, "%d\n", temp); - } else if (strcmp(dtype, "-u64") == 0) { - uint64_t temp = 0; - - ret = lwm2m_get_u64(&path, &temp); - if (ret != 0) { - goto out; - } - shell_print(sh, "%lld\n", temp); } else if (strcmp(dtype, "-f") == 0) { double temp = 0; @@ -349,8 +341,6 @@ static int cmd_write(const struct shell *sh, size_t argc, char **argv) ret = lwm2m_set_u16(&path, strtoul(value, &e, 10)); } else if (strcmp(dtype, "-u32") == 0) { ret = lwm2m_set_u32(&path, strtoul(value, &e, 10)); - } else if (strcmp(dtype, "-u64") == 0) { - ret = lwm2m_set_u64(&path, strtoull(value, &e, 10)); } else if (strcmp(dtype, "-b") == 0) { ret = lwm2m_set_bool(&path, strtoul(value, &e, 10)); } else if (strcmp(dtype, "-t") == 0) { diff --git a/tests/net/lib/lwm2m/lwm2m_registry/src/lwm2m_registry.c b/tests/net/lib/lwm2m/lwm2m_registry/src/lwm2m_registry.c index d4c0a7757a6..8e99f666b7f 100644 --- a/tests/net/lib/lwm2m/lwm2m_registry/src/lwm2m_registry.c +++ b/tests/net/lib/lwm2m/lwm2m_registry/src/lwm2m_registry.c @@ -203,16 +203,6 @@ ZTEST(lwm2m_registry, test_get_set) zassert_equal(strlen(buf), 0); } -ZTEST(lwm2m_registry, test_missing_u64) -{ - /* This data type is missing, so use S64 resource instead */ - uint64_t u64 = 123; - - zassert_equal(lwm2m_set_u64(&LWM2M_OBJ(32768, 0, LWM2M_RES_TYPE_S64), u64), 0); - zassert_equal(lwm2m_get_u64(&LWM2M_OBJ(32768, 0, LWM2M_RES_TYPE_S64), &u64), 0); - zassert_equal(u64, 123); -} - ZTEST(lwm2m_registry, test_temp_sensor) { int ret; From fa2e2446f70fb44dafafa409b03fde40031d3b79 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 21 Dec 2023 14:35:35 +0200 Subject: [PATCH 1064/1623] [nrf fromtree] net: lwm2m: Add transmission state indicator to RX as well Refactored the socket state indication into its own function that checks the state of TX queues as well as number of pending CoAP responses. Check the state after receiving a packet, as it might have been a last Ack packet we have been waiting. Signed-off-by: Seppo Takalo (cherry picked from commit dc6e7aa4b15b11094f2604c35180f7c72656896d) --- subsys/net/lib/lwm2m/lwm2m_engine.c | 72 +++++++++++++++++++---------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index d5a289a111f..639f65ea0fa 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -630,6 +630,50 @@ static int64_t check_notifications(struct lwm2m_ctx *ctx, const int64_t timestam return next; } +/** + * @brief Check TX queue states as well as number or pending CoAP transmissions. + * + * If all queues are empty and there is no packet we are currently transmitting and no + * CoAP responses (pendings) we are waiting, inform the application by a callback + * that socket is in state LWM2M_SOCKET_STATE_NO_DATA. + * Otherwise, before sending a packet, depending on the state of the queues, inform with + * one of the ONGOING, ONE_RESPONSE or LAST indicators. + * + * @param ctx Client context. + * @param ongoing_tx Current packet to be transmitted or NULL. + */ +static void hint_socket_state(struct lwm2m_ctx *ctx, struct lwm2m_message *ongoing_tx) +{ + if (!ctx->set_socket_state) { + return; + } + +#if defined(CONFIG_LWM2M_QUEUE_MODE_ENABLED) + bool empty = sys_slist_is_empty(&ctx->pending_sends) && + sys_slist_is_empty(&ctx->queued_messages); +#else + bool empty = sys_slist_is_empty(&ctx->pending_sends); +#endif + size_t pendings = coap_pendings_count(ctx->pendings, ARRAY_SIZE(ctx->pendings)); + + if (ongoing_tx) { + /* Check if more than current TX is in pendings list*/ + if (pendings > 1) { + empty = false; + } + + if (!empty) { + ctx->set_socket_state(ctx->sock_fd, LWM2M_SOCKET_STATE_ONGOING); + } else if (ongoing_tx->type == COAP_TYPE_CON) { + ctx->set_socket_state(ctx->sock_fd, LWM2M_SOCKET_STATE_ONE_RESPONSE); + } else { + ctx->set_socket_state(ctx->sock_fd, LWM2M_SOCKET_STATE_LAST); + } + } else if (empty && pendings == 0) { + ctx->set_socket_state(ctx->sock_fd, LWM2M_SOCKET_STATE_NO_DATA); + } +} + static int socket_recv_message(struct lwm2m_ctx *client_ctx) { static uint8_t in_buf[NET_IPV6_MTU]; @@ -684,31 +728,7 @@ static int socket_send_message(struct lwm2m_ctx *ctx) coap_pending_cycle(msg->pending); } - if (ctx->set_socket_state) { -#if defined(CONFIG_LWM2M_QUEUE_MODE_ENABLED) - bool empty = sys_slist_is_empty(&ctx->pending_sends) && - sys_slist_is_empty(&ctx->queued_messages); -#else - bool empty = sys_slist_is_empty(&ctx->pending_sends); -#endif - if (coap_pendings_count(ctx->pendings, ARRAY_SIZE(ctx->pendings)) > 1) { - empty = false; - } - - if (!empty) { - ctx->set_socket_state(ctx->sock_fd, LWM2M_SOCKET_STATE_ONGOING); - } else { - switch (msg->type) { - case COAP_TYPE_CON: - ctx->set_socket_state(ctx->sock_fd, - LWM2M_SOCKET_STATE_ONE_RESPONSE); - break; - default: - ctx->set_socket_state(ctx->sock_fd, LWM2M_SOCKET_STATE_LAST); - break; - } - } - } + hint_socket_state(ctx, msg); rc = zsock_send(msg->ctx->sock_fd, msg->cpkt.data, msg->cpkt.offset, 0); @@ -847,6 +867,8 @@ static void socket_loop(void *p1, void *p2, void *p3) break; } } + + hint_socket_state(sock_ctx[i], NULL); } if (sock_fds[i].revents & ZSOCK_POLLOUT) { From 9029ec9bf830893072ca2825a9704eb8b0169df4 Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Wed, 3 Jan 2024 13:08:57 +0200 Subject: [PATCH 1065/1623] [nrf fromtree] net: lwm2m: Delay triggering registration update Add short delay before triggering registration update. This allows postponing the update from application side if needed. Signed-off-by: Juha Ylinen (cherry picked from commit 85dfe3df1422fd104a38bb1241235d92bc079d31) --- subsys/net/lib/lwm2m/lwm2m_rd_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.c b/subsys/net/lib/lwm2m/lwm2m_rd_client.c index 6b3fbcccc68..95b576cb1c6 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.c +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.c @@ -1132,7 +1132,7 @@ static void sm_registration_done(void) if (sm_is_registered() && (client.trigger_update || now >= next_update())) { - set_sm_state(ENGINE_UPDATE_REGISTRATION); + set_sm_state_delayed(ENGINE_UPDATE_REGISTRATION, DELAY_FOR_ACK); } else if (IS_ENABLED(CONFIG_LWM2M_QUEUE_MODE_ENABLED) && (client.engine_state != ENGINE_REGISTRATION_DONE_RX_OFF) && (now >= next_rx_off())) { From 38abd5701f082d0f219ba8e8f27763810d5d5adc Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Wed, 3 Jan 2024 16:09:28 +0200 Subject: [PATCH 1066/1623] [nrf fromtree] net: lwm2m: Fix deadlock when calling lwm2m_engine_pause() lwm2m_engine_pause() caused deadlock if it was called within engine thread. Remove while loop from lwm2m_engine_resume(). Signed-off-by: Juha Ylinen (cherry picked from commit 7c53fa86ffa019a8497dd9a2b3943d5976769f07) --- subsys/net/lib/lwm2m/lwm2m_engine.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 639f65ea0fa..e08bb4ca17e 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -1259,6 +1259,12 @@ int lwm2m_engine_pause(void) suspend_engine_thread = true; lwm2m_engine_wake_up(); + /* Check if pause requested within a engine thread, a callback for example. */ + if (engine_thread_id == k_current_get()) { + LOG_DBG("Pause requested"); + return 0; + } + while (active_engine_thread) { k_msleep(10); } @@ -1275,10 +1281,7 @@ int lwm2m_engine_resume(void) k_thread_resume(engine_thread_id); lwm2m_engine_wake_up(); - while (!active_engine_thread) { - k_msleep(10); - } - LOG_INF("LWM2M engine thread resume"); + return 0; } From 30d13f412fd3adff9f781aa6ff6919fc1ba7c618 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Tue, 9 Jan 2024 16:58:18 -0800 Subject: [PATCH 1067/1623] [nrf fromtree] tests: net: lwm2m_engine: workaround stack overflow on qemu_x86 When running on qemu_x86, the test test_socket_state failed on stack overflow. Setting CONFIG_TEST_EXTRA_STACK_SIZE to 1024 seems to fix the issue. So add a board specific config for qemu_x86 so this test would pass. Signed-off-by: Daniel Leung (cherry picked from commit 78790a85aa86c7cd8ed7c9e8b1084306e68b85d7) --- tests/net/lib/lwm2m/lwm2m_engine/boards/qemu_x86.conf | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/net/lib/lwm2m/lwm2m_engine/boards/qemu_x86.conf diff --git a/tests/net/lib/lwm2m/lwm2m_engine/boards/qemu_x86.conf b/tests/net/lib/lwm2m/lwm2m_engine/boards/qemu_x86.conf new file mode 100644 index 00000000000..c735e1a8a2d --- /dev/null +++ b/tests/net/lib/lwm2m/lwm2m_engine/boards/qemu_x86.conf @@ -0,0 +1 @@ +CONFIG_TEST_EXTRA_STACK_SIZE=1024 From e1a716774ebac8c8fd9ef7baa0b7e3c04d1c9514 Mon Sep 17 00:00:00 2001 From: Simon Walz Date: Mon, 8 Jan 2024 13:42:28 +0100 Subject: [PATCH 1068/1623] [nrf fromtree] net: lwm2m: add gateway callback to handle prefixed messages Adding a callback for handling lwm2m messages with prefixed paths defined by the gateway object. If CONFIG_LWM2M_GATEWAY_OBJ_SUPPORT is set, each path is checked for the prefix stored in the object instances of the gateway object 25. If prefixes match the msg is passed to the gw_msg_cb. Signed-off-by: Simon Walz (cherry picked from commit 38aa4d5169e3fe60ef32b0de473831046516891d) --- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 12 ++++- subsys/net/lib/lwm2m/lwm2m_message_handling.h | 2 + subsys/net/lib/lwm2m/lwm2m_obj_gateway.c | 52 +++++++++++++++++++ subsys/net/lib/lwm2m/lwm2m_obj_gateway.h | 40 ++++++++++++++ 4 files changed, 105 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 677879304f8..480c64372e8 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -46,6 +46,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "lwm2m_object.h" #include "lwm2m_obj_access_control.h" #include "lwm2m_obj_server.h" +#include "lwm2m_obj_gateway.h" #include "lwm2m_rw_link_format.h" #include "lwm2m_rw_oma_tlv.h" #include "lwm2m_rw_plain_text.h" @@ -479,7 +480,7 @@ void lwm2m_engine_context_init(struct lwm2m_ctx *client_ctx) } /* utility functions */ -static int coap_options_to_path(struct coap_option *opt, int options_count, +int coap_options_to_path(struct coap_option *opt, int options_count, struct lwm2m_obj_path *path) { uint16_t len, @@ -2268,6 +2269,15 @@ static int handle_request(struct coap_packet *request, struct lwm2m_message *msg msg->token = token; } + if (IS_ENABLED(CONFIG_LWM2M_GATEWAY_OBJ_SUPPORT)) { + r = lwm2m_gw_handle_req(msg); + if (r == 0) { + return 0; + } else if (r != -ENOENT) { + goto error; + } + } + /* parse the URL path into components */ r = coap_find_options(msg->in.in_cpkt, COAP_OPTION_URI_PATH, options, ARRAY_SIZE(options)); if (r < 0) { diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.h b/subsys/net/lib/lwm2m/lwm2m_message_handling.h index c41fbbac0ee..3ac014b5db8 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.h +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.h @@ -39,6 +39,8 @@ #define NUM_OUTPUT_BLOCK_CONTEXT CONFIG_LWM2M_NUM_OUTPUT_BLOCK_CONTEXT #endif +int coap_options_to_path(struct coap_option *opt, int options_count, + struct lwm2m_obj_path *path); /* LwM2M message functions */ struct lwm2m_message *lwm2m_get_message(struct lwm2m_ctx *client_ctx); struct lwm2m_message *find_msg(struct coap_pending *pending, struct coap_reply *reply); diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_gateway.c b/subsys/net/lib/lwm2m/lwm2m_obj_gateway.c index 711fd5fe127..5bb12f80f47 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_gateway.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_gateway.c @@ -59,6 +59,7 @@ static struct lwm2m_engine_obj_field fields[] = { static struct lwm2m_engine_obj_inst inst[MAX_INSTANCE_COUNT]; static struct lwm2m_engine_res res[MAX_INSTANCE_COUNT][GATEWAY_MAX_ID]; static struct lwm2m_engine_res_inst res_inst[MAX_INSTANCE_COUNT][RESOURCE_INSTANCE_COUNT]; +lwm2m_engine_gateway_msg_cb gateway_msg_cb[MAX_INSTANCE_COUNT]; static int prefix_validation_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_inst_id, uint8_t *data, uint16_t data_len, bool last_block, @@ -146,6 +147,57 @@ static struct lwm2m_engine_obj_inst *lwm2m_gw_create(uint16_t obj_inst_id) return &inst[index]; } +int lwm2m_gw_handle_req(struct lwm2m_message *msg) +{ + struct coap_option options[4]; + int ret; + + ret = coap_find_options(msg->in.in_cpkt, COAP_OPTION_URI_PATH, options, + ARRAY_SIZE(options)); + if (ret < 0) { + return ret; + } + + for (int index = 0; index < MAX_INSTANCE_COUNT; index++) { + /* Skip uninitialized objects */ + if (!inst[index].obj) { + continue; + } + + char *prefix = device_table[index].prefix; + size_t prefix_len = strlen(prefix); + + if (prefix_len != options[0].len) { + continue; + } + if (strncmp(options[0].value, prefix, prefix_len) != 0) { + continue; + } + + if (gateway_msg_cb[index] == NULL) { + return -ENOENT; + } + /* Delete prefix from path*/ + ret = coap_options_to_path(&options[1], ret - 1, &msg->path); + if (ret < 0) { + return ret; + } + return gateway_msg_cb[index](msg); + } + return -ENOENT; +} + +int lwm2m_register_gw_callback(uint16_t obj_inst_id, lwm2m_engine_gateway_msg_cb cb) +{ + for (int index = 0; index < MAX_INSTANCE_COUNT; index++) { + if (inst[index].obj_inst_id == obj_inst_id) { + gateway_msg_cb[index] = cb; + return 0; + } + } + return -ENOENT; +} + static int lwm2m_gw_init(void) { int ret = 0; diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_gateway.h b/subsys/net/lib/lwm2m/lwm2m_obj_gateway.h index 597e3de19bc..0f7a82af249 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_gateway.h +++ b/subsys/net/lib/lwm2m/lwm2m_obj_gateway.h @@ -9,6 +9,8 @@ #ifndef __LWM2M_OBJ_GATEWAY__ #define __LWM2M_OBJ_GATEWAY__ +#include + /* LwM2M Gateway resource IDs */ /* clang-format off */ #define LWM2M_GATEWAY_DEVICE_RID 0 @@ -17,4 +19,42 @@ #define LWM2M_GATEWAY_IOT_DEVICE_OBJECTS_RID 3 /* clang-format on */ +/** + * @brief A callback which handles the prefixed messages from the server. + * + * The callback gets triggered each time the prefix in front of a received lwm2m + * msg path matches the prefix set in the LWM2M_GATEWAY_PREFIX_RID buffer. + * + * It must handle the content of the coap message completely. + * In case of success the LwM2M engine will then send the formatted coap message, + * otherwise a coap response code is sent. + * + * Example of returning CoAP response: + * @code{.c} + * lwm2m_init_message(msg); + * // Write CoAP packet to msg->out.out_cpkt + * return 0; + * @endcode + * + * + * @return 0 if msg contains a valid CoAP response. + * @return negative error code otherwise. + */ +typedef int (*lwm2m_engine_gateway_msg_cb)(struct lwm2m_message *msg); +/** + * @brief Register a callback which handles the prefixed messages from the server. + * + * @return 0 on success + * @return -ENOENT if no object instance with obj_inst_id was found + */ +int lwm2m_register_gw_callback(uint16_t obj_inst_id, lwm2m_engine_gateway_msg_cb cb); +/** + * @brief Check if given message is handled by Gateway callback. + * + * @return 0 if msg was handled by Gateawy and contains a valid response. Negative error code + * otherwise. + * @return -ENOENT if this msg was not handled by Gateway object. + */ +int lwm2m_gw_handle_req(struct lwm2m_message *msg); + #endif /* __LWM2M_OBJ_GATEWAY__ */ From 849719038d041e6b17149fce6e2e7625d6ba4598 Mon Sep 17 00:00:00 2001 From: Vladislav Litvinov Date: Thu, 14 Dec 2023 16:03:49 +0100 Subject: [PATCH 1069/1623] [nrf noup] ci: Add PMIC samples change scope Add change scope to run test suite for PMIC samples Signed-off-by: Vladislav Litvinov --- .github/test-spec.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 789f1a4e235..cad113b0883 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -255,3 +255,12 @@ - "subsys/task_wdt/**/*" - "subsys/usb/**/*" - "subsys/zbus/**/*" + +"CI-pmic-samples-test": + - "/samples/shields/npm1300_ek/**/*" + - "/boards/shields/npm1300_ek/**/*" + - "**/**npm1300**/**" + - "/drivers/regulator/regulator_common.c" + - "/drivers/regulator/regulator_shell.c" + - "/drivers/gpio/gpio_shell.c" + - "/drivers/sensor/sensor_shell.c" From fdb262308db6a867ad2ca650fd17c823fe1c58db Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 3 Jan 2024 13:13:13 +0530 Subject: [PATCH 1070/1623] [nrf fromtree] wifi: shell: Use case insensitive comparison The help text uses the capital case as its an acronym, but passing capital case fails. Also extend that to others as well. Signed-off-by: Chaitanya Tata (cherry picked from commit 9e6542b0cc0a69ba18b8f9bd7d53ac6b51740db3) --- subsys/net/l2/wifi/wifi_shell.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index e1446cceca0..4f378a5029b 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -15,6 +15,7 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); #include #include #include +#include #include #include #include @@ -886,9 +887,9 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) return 0; } - if (!strncmp(argv[1], "on", 2)) { + if (!strncasecmp(argv[1], "on", 2)) { params.enabled = WIFI_PS_ENABLED; - } else if (!strncmp(argv[1], "off", 3)) { + } else if (!strncasecmp(argv[1], "off", 3)) { params.enabled = WIFI_PS_DISABLED; } else { shell_fprintf(sh, SHELL_WARNING, "Invalid argument\n"); @@ -917,9 +918,9 @@ static int cmd_wifi_ps_mode(const struct shell *sh, size_t argc, char *argv[]) context.sh = sh; - if (!strncmp(argv[1], "legacy", 6)) { + if (!strncasecmp(argv[1], "legacy", 6)) { params.mode = WIFI_PS_MODE_LEGACY; - } else if (!strncmp(argv[1], "wmm", 3)) { + } else if (!strncasecmp(argv[1], "WMM", 4)) { params.mode = WIFI_PS_MODE_WMM; } else { shell_fprintf(sh, SHELL_WARNING, "Invalid PS mode\n"); @@ -1405,9 +1406,9 @@ static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *ar context.sh = sh; - if (!strncmp(argv[1], "dtim", 4)) { + if (!strncasecmp(argv[1], "dtim", 4)) { params.wakeup_mode = WIFI_PS_WAKEUP_MODE_DTIM; - } else if (!strncmp(argv[1], "listen_interval", 15)) { + } else if (!strncasecmp(argv[1], "listen_interval", 15)) { params.wakeup_mode = WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL; } else { shell_fprintf(sh, SHELL_WARNING, "Invalid argument\n"); From 8fe4834f8a7da79703d224f15547011e636c725e Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 10 Jan 2024 23:12:39 +0530 Subject: [PATCH 1071/1623] [nrf fromtree] wifi: shell: Fix missing case sensitivity This was missed in earlier that tried to fix all string comparisons to use case insensitive comparison. Signed-off-by: Chaitanya Tata (cherry picked from commit 2ce295b71e396f5305d39d819ada2fb179128748) --- subsys/net/l2/wifi/wifi_shell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 4f378a5029b..450b7b00eb5 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -601,9 +601,9 @@ static int wifi_scan_args_to_params(const struct shell *sh, state = getopt_state_get(); switch (opt) { case 't': - if (!strcmp(optarg, "passive")) { + if (!strncasecmp(optarg, "passive", 7)) { params->scan_type = WIFI_SCAN_TYPE_PASSIVE; - } else if (!strcmp(optarg, "active")) { + } else if (!strncasecmp(optarg, "active", 6)) { params->scan_type = WIFI_SCAN_TYPE_ACTIVE; } else { shell_fprintf(sh, SHELL_ERROR, "Invalid scan type %s\n", optarg); From cec939280dca0f61b214b0cd1141105b408651b8 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 16 Jan 2024 18:36:19 +0530 Subject: [PATCH 1072/1623] [nrf fromtree] wifi: shell: Fix typo in comparison The length should be 3 for WMM not 4. Signed-off-by: Chaitanya Tata (cherry picked from commit dc9d5d932120f22175857a80421c1c2df572af33) --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 450b7b00eb5..726ce69b435 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -920,7 +920,7 @@ static int cmd_wifi_ps_mode(const struct shell *sh, size_t argc, char *argv[]) if (!strncasecmp(argv[1], "legacy", 6)) { params.mode = WIFI_PS_MODE_LEGACY; - } else if (!strncasecmp(argv[1], "WMM", 4)) { + } else if (!strncasecmp(argv[1], "WMM", 3)) { params.mode = WIFI_PS_MODE_WMM; } else { shell_fprintf(sh, SHELL_WARNING, "Invalid PS mode\n"); From e09a8d4a07e55e1e5666348f0c7b69d9f2b5bab7 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 16 Jan 2024 23:25:21 +0530 Subject: [PATCH 1073/1623] [nrf fromlist] wifi: shell: Make channel mandatory for AP For starting an AP mode, channel is mandatory, so, fix the arguments and the help text. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67694 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 726ce69b435..96ce19e3e5c 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -458,7 +458,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[], return -EINVAL; } - /* Channel (optional) */ + /* Channel (optional: STA, mandatory: AP) */ if ((idx < argc) && (strlen(argv[idx]) <= 3)) { params->channel = strtol(argv[idx], &endptr, 10); if (*endptr != '\0') { @@ -1769,14 +1769,14 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, 1, 0), SHELL_CMD_ARG(enable, NULL, "\"\"\n" - "[channel number: 0 means all]\n" + "\n" "[PSK: valid only for secure SSIDs]\n" "[Security type: valid only for secure SSIDs]\n" "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" "[MFP (optional: needs security type to be specified)]\n" ": 0:Disable, 1:Optional, 2:Required.\n", cmd_wifi_ap_enable, - 2, 4), + 3, 3), SHELL_CMD_ARG(stations, NULL, "List stations connected to the AP", cmd_wifi_ap_stations, From 75b68d8e2ace1632f64e9bdff36d571211ed4a1b Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 16 Jan 2024 23:38:47 +0530 Subject: [PATCH 1074/1623] [nrf fromlist] wifi: shell: Add a sanity check for MFP For none and WPA-PSK MFP isn't applicable, it was only introduced in WPA2-PSK (RSN) and later. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67694 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 96ce19e3e5c..0ab9e884780 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -494,6 +494,11 @@ static int __wifi_args_to_params(size_t argc, char *argv[], if (idx < argc) { unsigned int mfp = strtol(argv[idx], &endptr, 10); + if (security == WIFI_SECURITY_TYPE_NONE || + security == WIFI_SECURITY_TYPE_WPA_PSK) { + return -EINVAL; + } + if (mfp <= WIFI_MFP_REQUIRED) { params->mfp = mfp; } From 02ac99c10a16f304298c6f39f5c5724fceda17bf Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 16 Jan 2024 23:30:13 +0530 Subject: [PATCH 1075/1623] [nrf fromlist] wifi: utils: Move channel helpers to public API These can be used for channel validation outside the utils. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67694 Signed-off-by: Chaitanya Tata --- include/zephyr/net/wifi_utils.h | 43 +++++++++++++++++++++++++++++++++ subsys/net/l2/wifi/wifi_utils.c | 8 +++--- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/include/zephyr/net/wifi_utils.h b/include/zephyr/net/wifi_utils.h index c16eef0e5b2..537db787648 100644 --- a/include/zephyr/net/wifi_utils.h +++ b/include/zephyr/net/wifi_utils.h @@ -103,6 +103,49 @@ int wifi_utils_parse_scan_chan(char *scan_chan_str, struct wifi_band_channel *chan, uint8_t max_channels); + +/** + * @brief Validate a channel against a band. + * + * @param band Band to validate the channel against. + * @param chan Channel to validate. + * + * @retval true if the channel is valid for the band. + * @retval false if the channel is not valid for the band. + */ +bool wifi_utils_validate_chan(uint8_t band, + uint16_t chan); + +/** + * @brief Validate a channel against the 2.4 GHz band. + * + * @param chan Channel to validate. + * + * @retval true if the channel is valid for the band. + * @retval false if the channel is not valid for the band. + */ +bool wifi_utils_validate_chan_2g(uint16_t chan); + +/** + * @brief Validate a channel against the 5 GHz band. + * + * @param chan Channel to validate. + * + * @retval true if the channel is valid for the band. + * @retval false if the channel is not valid for the band. + */ +bool wifi_utils_validate_chan_5g(uint16_t chan); + +/** + * @brief Validate a channel against the 6 GHz band. + * + * @param chan Channel to validate. + * + * @retval true if the channel is valid for the band. + * @retval false if the channel is not valid for the band. + */ +bool wifi_utils_validate_chan_6g(uint16_t chan); + /** * @} */ diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index 52d25d90566..76e93fc33e0 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -44,7 +44,7 @@ static enum wifi_frequency_bands wifi_utils_map_band_str_to_idx(char *band_str) } -static bool wifi_utils_validate_chan_2g(uint16_t chan) +bool wifi_utils_validate_chan_2g(uint16_t chan) { if ((chan >= 1) && (chan <= 14)) { return true; @@ -54,7 +54,7 @@ static bool wifi_utils_validate_chan_2g(uint16_t chan) } -static bool wifi_utils_validate_chan_5g(uint16_t chan) +bool wifi_utils_validate_chan_5g(uint16_t chan) { uint16_t i; @@ -68,7 +68,7 @@ static bool wifi_utils_validate_chan_5g(uint16_t chan) } -static bool wifi_utils_validate_chan_6g(uint16_t chan) +bool wifi_utils_validate_chan_6g(uint16_t chan) { if (((chan >= 1) && (chan <= 233) && (!((chan - 1)%4))) || (chan == 2)) { @@ -79,7 +79,7 @@ static bool wifi_utils_validate_chan_6g(uint16_t chan) } -static bool wifi_utils_validate_chan(uint8_t band, +bool wifi_utils_validate_chan(uint8_t band, uint16_t chan) { bool result = false; From bf61fbcf89eaebefdb91d9bab370446cbd7edccc Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 16 Jan 2024 23:44:23 +0530 Subject: [PATCH 1076/1623] [nrf fromlist] wifi: shell: Add channel validation Validate the channel for both STA and AP modes. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67694 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 0ab9e884780..01a76359702 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -437,7 +437,8 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, } static int __wifi_args_to_params(size_t argc, char *argv[], - struct wifi_connect_req_params *params) + struct wifi_connect_req_params *params, + enum wifi_iface_mode iface_mode) { char *endptr; int idx = 1; @@ -465,8 +466,26 @@ static int __wifi_args_to_params(size_t argc, char *argv[], return -EINVAL; } - if (params->channel == 0U) { + if (iface_mode == WIFI_MODE_INFRA && params->channel == 0) { params->channel = WIFI_CHANNEL_ANY; + } else { + const uint8_t bands[] = {WIFI_FREQ_BAND_2_4_GHZ, + WIFI_FREQ_BAND_5_GHZ, + WIFI_FREQ_BAND_6_GHZ}; + uint8_t band; + bool found = false; + + for (band = 0; band < ARRAY_SIZE(bands); band++) { + if (wifi_utils_validate_chan(bands[band], + params->channel)) { + found = true; + break; + } + } + + if (!found) { + return -EINVAL; + } } idx++; @@ -525,7 +544,7 @@ static int cmd_wifi_connect(const struct shell *sh, size_t argc, struct net_if *iface = net_if_get_first_wifi(); struct wifi_connect_req_params cnx_params = { 0 }; - if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params)) { + if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params, WIFI_MODE_INFRA)) { shell_help(sh); return -ENOEXEC; } @@ -1210,7 +1229,7 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc, static struct wifi_connect_req_params cnx_params; int ret; - if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params)) { + if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params, WIFI_MODE_AP)) { shell_help(sh); return -ENOEXEC; } From 595c41f2e62df604316f242afd8c65ab828ac299 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 16 Jan 2024 23:54:36 +0530 Subject: [PATCH 1077/1623] [nrf fromlist] wifi: shell: Fix the channel extraction The channel extraction from string directly uses the end variable with limited data type, this causes issue if an invalid channel that exceeds the data is given as an input e.g., 300, which would end up as a valid channel 44. Use an intermediate variable with type that can hold all possible combinations (valid and invalid) and only after validation assign that to the end type. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67694 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 01a76359702..49459774655 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -461,12 +461,13 @@ static int __wifi_args_to_params(size_t argc, char *argv[], /* Channel (optional: STA, mandatory: AP) */ if ((idx < argc) && (strlen(argv[idx]) <= 3)) { - params->channel = strtol(argv[idx], &endptr, 10); + long channel = strtol(argv[idx], &endptr, 10); + if (*endptr != '\0') { return -EINVAL; } - if (iface_mode == WIFI_MODE_INFRA && params->channel == 0) { + if (iface_mode == WIFI_MODE_INFRA && channel == 0) { params->channel = WIFI_CHANNEL_ANY; } else { const uint8_t bands[] = {WIFI_FREQ_BAND_2_4_GHZ, @@ -477,7 +478,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[], for (band = 0; band < ARRAY_SIZE(bands); band++) { if (wifi_utils_validate_chan(bands[band], - params->channel)) { + channel)) { found = true; break; } @@ -486,8 +487,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[], if (!found) { return -EINVAL; } - } + params->channel = channel; + } idx++; } From c3be80e41e8271190d4b0eaa4923e28dfe5d6802 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Wed, 17 Jan 2024 00:15:15 +0530 Subject: [PATCH 1078/1623] [nrf fromlist] wifi: shell: Log errors for validation Handy in giving feedback to the user rather than silent failure. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67694 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 43 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 49459774655..f470e700f8c 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -48,6 +48,8 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); NET_EVENT_WIFI_SCAN_RESULT) #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY */ +#define MAX_BANDS_STR_LEN 64 + static struct { const struct shell *sh; @@ -444,6 +446,8 @@ static int __wifi_args_to_params(size_t argc, char *argv[], int idx = 1; if (argc < 1) { + print(context.sh, SHELL_WARNING, + "SSID not specified\n"); return -EINVAL; } @@ -456,6 +460,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[], params->ssid = argv[0]; params->ssid_length = strlen(params->ssid); if (params->ssid_length > WIFI_SSID_MAX_LEN) { + print(context.sh, SHELL_WARNING, + "SSID too long (max %d characters)\n", + WIFI_SSID_MAX_LEN); return -EINVAL; } @@ -464,6 +471,11 @@ static int __wifi_args_to_params(size_t argc, char *argv[], long channel = strtol(argv[idx], &endptr, 10); if (*endptr != '\0') { + print(context.sh, SHELL_ERROR, + "Failed to parse channel: %s: endp: %s, err: %s\n", + argv[idx], + endptr, + strerror(errno)); return -EINVAL; } @@ -475,8 +487,23 @@ static int __wifi_args_to_params(size_t argc, char *argv[], WIFI_FREQ_BAND_6_GHZ}; uint8_t band; bool found = false; + char bands_str[MAX_BANDS_STR_LEN] = {0}; + size_t offset = 0; for (band = 0; band < ARRAY_SIZE(bands); band++) { + offset += snprintf(bands_str + offset, + sizeof(bands_str) - offset, + "%s%s", + band ? "," : "", + wifi_band_txt(bands[band])); + if (offset >= sizeof(bands_str)) { + print(context.sh, SHELL_ERROR, + "Failed to parse channel: %s: " + "band string too long\n", + argv[idx]); + return -EINVAL; + } + if (wifi_utils_validate_chan(bands[band], channel)) { found = true; @@ -485,6 +512,10 @@ static int __wifi_args_to_params(size_t argc, char *argv[], } if (!found) { + print(context.sh, SHELL_ERROR, + "Invalid channel: %ld, checked bands: %s\n", + channel, + bands_str); return -EINVAL; } @@ -517,6 +548,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[], if (security == WIFI_SECURITY_TYPE_NONE || security == WIFI_SECURITY_TYPE_WPA_PSK) { + print(context.sh, SHELL_ERROR, + "MFP not supported for security type %s\n", + wifi_security_txt(security)); return -EINVAL; } @@ -532,6 +566,10 @@ static int __wifi_args_to_params(size_t argc, char *argv[], params->psk_length > WIFI_PSK_MAX_LEN) || (params->security == WIFI_SECURITY_TYPE_SAE && params->psk_length > WIFI_SAE_PSWD_MAX_LEN)) { + print(context.sh, SHELL_ERROR, + "Invalid PSK length (%d) for security type %s\n", + params->psk_length, + wifi_security_txt(params->security)); return -EINVAL; } } @@ -546,13 +584,13 @@ static int cmd_wifi_connect(const struct shell *sh, size_t argc, struct net_if *iface = net_if_get_first_wifi(); struct wifi_connect_req_params cnx_params = { 0 }; + context.sh = sh; if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params, WIFI_MODE_INFRA)) { shell_help(sh); return -ENOEXEC; } context.connecting = true; - context.sh = sh; if (net_mgmt(NET_REQUEST_WIFI_CONNECT, iface, &cnx_params, sizeof(struct wifi_connect_req_params))) { @@ -1231,13 +1269,12 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc, static struct wifi_connect_req_params cnx_params; int ret; + context.sh = sh; if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params, WIFI_MODE_AP)) { shell_help(sh); return -ENOEXEC; } - context.sh = sh; - k_mutex_init(&wifi_ap_sta_list_lock); ret = net_mgmt(NET_REQUEST_WIFI_AP_ENABLE, iface, &cnx_params, From 4a043af1d0515aab82ec54ceeae543bb7f27a247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Thu, 18 Jan 2024 09:41:11 +0100 Subject: [PATCH 1079/1623] [nrf fromtree] drivers: nrf_qspi_nor: Deactivate QSPI peripheral after initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up to commit ea1be7f242b9348863a27adb17215014f15b318a. After the driver performs its initialization, it needs to deactivate the QSPI peripheral. Otherwise, the peripheral would unnecessarily consume power until some QSPI operation is performed (and only then it will get deactivated), what depending on the application may take a significant amount of time. Signed-off-by: Andrzej Głąbek (cherry picked from commit 3f6373eb364bcb3d91ae3733509c41f9673785c3) --- drivers/flash/nrf_qspi_nor.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index d6695989857..0e9d4181418 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -1090,6 +1090,10 @@ static int qspi_nor_init(const struct device *dev) qspi_clock_div_restore(); + if (!IS_ENABLED(CONFIG_NORDIC_QSPI_NOR_XIP) && nrfx_qspi_init_check()) { + (void)nrfx_qspi_deactivate(); + } + #ifdef CONFIG_PM_DEVICE_RUNTIME int rc2 = pm_device_runtime_enable(dev); From 6aa16dca7035766f29e87ea9f443d1f5d8fa9655 Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Fri, 24 Nov 2023 08:58:45 +0100 Subject: [PATCH 1080/1623] [nrf fromtree] net: openthread: upmerge to `75694d2` Regular OpenThread upmerge to commit `75694d2`. Move CONFIG_OPENTHREAD_PLATFORM_KEY_REFERENCES_ENABLE from header file to Kconfig. Signed-off-by: Maciej Baczmanski (cherry picked from commit c2f1ff7f5fbf053def69606a18df4fea83dc7b18) --- modules/openthread/CMakeLists.txt | 6 ++++++ modules/openthread/Kconfig.features | 6 ++++++ .../platform/openthread-core-zephyr-config.h | 10 ---------- subsys/net/l2/openthread/Kconfig | 10 ++-------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index 646b086ef1e..150039863d9 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -400,6 +400,12 @@ else() set(OT_PING_SENDER OFF CACHE BOOL "Enable ping sender support" FORCE) endif() +if(OPENTHREAD_PLATFORM_KEY_REF) + set(OT_PLATFORM_KEY_REF ON CACHE BOOL "Enable platform key reference support" FORCE) +else() + set(OT_PLATFORM_KEY_REF OFF CACHE BOOL "Enable platform key reference support" FORCE) +endif() + if(CONFIG_OPENTHREAD_PLATFORM_NETIF) set(OT_PLATFORM_NETIF ON CACHE BOOL "Enable platform netif support" FORCE) else() diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index 2be5332cde3..952a7853b43 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -249,6 +249,12 @@ config OPENTHREAD_OTNS config OPENTHREAD_PING_SENDER bool "Ping sender support" +config OPENTHREAD_PLATFORM_KEY_REF + bool "Platform cryptographic key reference support" + help + Enable usage of cryptographic key references instead of literal keys. + This requires a crypto backend library that supports key references. + config OPENTHREAD_PLATFORM_NETIF bool "Platform netif support" diff --git a/modules/openthread/platform/openthread-core-zephyr-config.h b/modules/openthread/platform/openthread-core-zephyr-config.h index 881585e5578..773cd170f2c 100644 --- a/modules/openthread/platform/openthread-core-zephyr-config.h +++ b/modules/openthread/platform/openthread-core-zephyr-config.h @@ -396,16 +396,6 @@ #define OPENTHREAD_CONFIG_CRYPTO_LIB OPENTHREAD_CONFIG_CRYPTO_LIB_PSA #endif -/** - * @def OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE - * - * Set to 1 if you want to enable key reference usage support. - * - */ -#ifdef CONFIG_OPENTHREAD_PLATFORM_KEY_REFERENCES_ENABLE -#define OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE 1 -#endif - /** * @def OPENTHREAD_CONFIG_PLATFORM_MAC_KEYS_EXPORTABLE_ENABLE * diff --git a/subsys/net/l2/openthread/Kconfig b/subsys/net/l2/openthread/Kconfig index 98113975797..aa7e03b8204 100644 --- a/subsys/net/l2/openthread/Kconfig +++ b/subsys/net/l2/openthread/Kconfig @@ -324,21 +324,15 @@ config OPENTHREAD_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE config OPENTHREAD_CRYPTO_PSA bool "ARM PSA crypto API" depends on MBEDTLS_PSA_CRYPTO_C || BUILD_WITH_TFM - select OPENTHREAD_PLATFORM_KEY_REFERENCES_ENABLE + select OPENTHREAD_PLATFORM_KEY_REF select OPENTHREAD_PLATFORM_KEYS_EXPORTABLE_ENABLE help Enable crypto backend library implementation based on ARM PSA crypto API instead of the default, using mbedTLS. -config OPENTHREAD_PLATFORM_KEY_REFERENCES_ENABLE - bool "Cryptographic key reference support" - help - Enable usage of cryptographic key references instead of literal keys - This requires a crypto backend library that supports key references. - config OPENTHREAD_PLATFORM_KEYS_EXPORTABLE_ENABLE bool "Make MAC keys exportable" - depends on OPENTHREAD_PLATFORM_KEY_REFERENCES_ENABLE + depends on OPENTHREAD_PLATFORM_KEY_REF help Enable the creation of exportable MAC keys in the OpenThread Key Manager. From a0272bc8bc2343fefe6abcd5e3949b505b055c9f Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Fri, 15 Dec 2023 21:30:27 +0100 Subject: [PATCH 1081/1623] [nrf fromtree] net: openthread: Add cmake makro to openthread cmake lists. This commit introduces `kconfig_to_ot_option` to simply fye the way of adding openthread related kconfigs. Signed-off-by: Przemyslaw Bida (cherry picked from commit b6d8d2715c31e971316cb1009460001e68df305f) --- modules/openthread/CMakeLists.txt | 571 +++++------------------------- 1 file changed, 90 insertions(+), 481 deletions(-) diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index 150039863d9..6691084eebd 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -3,6 +3,14 @@ if(CONFIG_OPENTHREAD_SOURCES) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +macro(kconfig_to_ot_option kconfig_option ot_config description) + if(${kconfig_option}) + set(${ot_config} ON CACHE BOOL "${description}" FORCE) + else() + set(${ot_config} OFF CACHE BOOL "${description}" FORCE) + endif() +endmacro() + # OpenThread options set(OT_BUILD_EXECUTABLES OFF CACHE BOOL "Disable OpenThread samples") set(OT_BUILTIN_MBEDTLS_MANAGEMENT OFF CACHE BOOL "Use Zephyr's mbedTLS heap") @@ -28,494 +36,95 @@ elseif(CONFIG_OPENTHREAD_MTD) set(OT_MTD ON CACHE BOOL "Enable MTD" FORCE) endif() -if(CONFIG_OPENTHREAD_ANYCAST_LOCATOR) - set(OT_ANYCAST_LOCATOR ON CACHE BOOL "Enable anycast locator" FORCE) -else() - set(OT_ANYCAST_LOCATOR OFF CACHE BOOL "Enable anycast locator" FORCE) -endif() - -if(CONFIG_ASSERT) - set(OT_ASSERT ON CACHE BOOL "Enable assert function OT_ASSERT()" FORCE) -else() - set(OT_ASSERT OFF CACHE BOOL "Enable assert function OT_ASSERT()" FORCE) -endif() - -if(CONFIG_OPENTHREAD_BACKBONE_ROUTER) - set(OT_BACKBONE_ROUTER ON CACHE BOOL "Enable backbone router functionality" FORCE) -else() - set(OT_BACKBONE_ROUTER OFF CACHE BOOL "Enable backbone router functionality" FORCE) -endif() - -if(CONFIG_OPENTHREAD_BACKBONE_ROUTER_DUA_NDPROXYING) - set(OT_BACKBONE_ROUTER_DUA_NDPROXYING ON CACHE BOOL "Enable BBR DUA ND Proxy support" FORCE) -else() - set(OT_BACKBONE_ROUTER_DUA_NDPROXYING OFF CACHE BOOL "Enable BBR DUA ND Proxy support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_BACKBONE_ROUTER_MULTICAST_ROUTING) - set(OT_BACKBONE_ROUTER_MULTICAST_ROUTING ON CACHE BOOL "Enable BBR MR support" FORCE) -else() - set(OT_BACKBONE_ROUTER_MULTICAST_ROUTING OFF CACHE BOOL "Enable BBR MR support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_BLE_TCAT) - set(OT_BLE_TCAT ON CACHE BOOL "Enable BLE TCAT support" FORCE) -else() - set(OT_BLE_TCAT OFF CACHE BOOL "Enable BLE TCAT support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_BORDER_AGENT) - set(OT_BORDER_AGENT ON CACHE BOOL "Enable Border Agent" FORCE) -else() - set(OT_BORDER_AGENT OFF CACHE BOOL "Enable Border Agent" FORCE) -endif() - -if(CONFIG_OPENTHREAD_BORDER_ROUTER) - set(OT_BORDER_ROUTER ON CACHE BOOL "Enable Border Router" FORCE) -else() - set(OT_BORDER_ROUTER OFF CACHE BOOL "Enable Border Router" FORCE) -endif() - -if(CONFIG_OPENTHREAD_BORDER_ROUTING) - set(OT_BORDER_ROUTING ON CACHE BOOL "Enable Border routing" FORCE) -else() - set(OT_BORDER_ROUTING OFF CACHE BOOL "Enable Border routing" FORCE) -endif() - -if(CONFIG_OPENTHREAD_BORDER_ROUTING_COUNTERS) - set(OT_BORDER_ROUTING_COUNTERS ON CACHE BOOL "Enable Border routing counters" FORCE) -else() - set(OT_BORDER_ROUTING_COUNTERS OFF CACHE BOOL "Enable Border routing counters" FORCE) -endif() - -if(CONFIG_OPENTHREAD_BORDER_ROUTING_DHCP6_PD) - set(OT_BORDER_ROUTING_DHCP6_PD ON CACHE BOOL "DHCPv6-PD support in border routing" FORCE) -else() - set(OT_BORDER_ROUTING_DHCP6_PD OFF CACHE BOOL "DHCPv6-PD support in border routing" FORCE) -endif() - -if(CONFIG_OPENTHREAD_CHANNEL_MANAGER) - set(OT_CHANNEL_MANAGER ON CACHE BOOL "Enable channel manager support" FORCE) -else() - set(OT_CHANNEL_MANAGER OFF CACHE BOOL "Enable channel manager support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_CHANNEL_MONITOR) - set(OT_CHANNEL_MONITOR ON CACHE BOOL "Enable channel monitor support" FORCE) -else() - set(OT_CHANNEL_MONITOR OFF CACHE BOOL "Enable channel monitor support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_COAP) - set(OT_COAP ON CACHE BOOL "Enable CoAP API" FORCE) -else() - set(OT_COAP OFF CACHE BOOL "Enable CoAP API" FORCE) -endif() - -if(CONFIG_OPENTHREAD_COAP_BLOCK) - set(OT_COAP_BLOCK ON CACHE BOOL "Enable CoAP Block-wise option support" FORCE) -else() - set(OT_COAP_BLOCK OFF CACHE BOOL "Enable CoAP Block-wise option support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_COAP_OBSERVE) - set(OT_COAP_OBSERVE ON CACHE BOOL "Enable CoAP Observe option support" FORCE) -else() - set(OT_COAP_OBSERVE OFF CACHE BOOL "Enable CoAP Observe option support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_COAPS) - set(OT_COAPS ON CACHE BOOL "Enable secure CoAP API support" FORCE) -else() - set(OT_COAPS OFF CACHE BOOL "Enable secure CoAP API support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_COMMISSIONER) - set(OT_COMMISSIONER ON CACHE BOOL "Enable Commissioner" FORCE) -else() - set(OT_COMMISSIONER OFF CACHE BOOL "Enable Commissioner" FORCE) -endif() - -if(CONFIG_OPENTHREAD_CSL_AUTO_SYNC) - set(OT_CSL_AUTO_SYNC ON CACHE BOOL "Enable csl autosync" FORCE) -else() - set(OT_CSL_AUTO_SYNC OFF CACHE BOOL "Enable csl autosync" FORCE) -endif() - -if(CONFIG_OPENTHREAD_CSL_DEBUG) - set(OT_CSL_DEBUG ON CACHE BOOL "Enable CSL debug" FORCE) -else() - set(OT_CSL_DEBUG OFF CACHE BOOL "Enable CSL debug" FORCE) -endif() - -if(CONFIG_OPENTHREAD_CSL_RECEIVER) - set(OT_CSL_RECEIVER ON CACHE BOOL "Enable CSL receiver feature for Thread 1.2" FORCE) -else() - set(OT_CSL_RECEIVER OFF CACHE BOOL "Enable CSL receiver feature for Thread 1.2" FORCE) -endif() +kconfig_to_ot_option(CONFIG_OPENTHREAD_ANYCAST_LOCATOR OT_ANYCAST_LOCATOR "Enable anycast locator") +kconfig_to_ot_option(CONFIG_ASSERT OT_ASSERT "Enable assert function OT_ASSERT()") +kconfig_to_ot_option(CONFIG_OPENTHREAD_BACKBONE_ROUTER OT_BACKBONE_ROUTER "Enable backbone router functionality") +kconfig_to_ot_option(CONFIG_OPENTHREAD_BACKBONE_ROUTER_DUA_NDPROXYING OT_BACKBONE_ROUTER_DUA_NDPROXYING "Enable BBR DUA ND Proxy support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_BACKBONE_ROUTER_MULTICAST_ROUTING OT_BACKBONE_ROUTER_MULTICAST_ROUTING "Enable BBR MR support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_BLE_TCAT OT_BLE_TCAT "Enable BLE TCAT support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_BORDER_AGENT OT_BORDER_AGENT "Enable Border Agent") +kconfig_to_ot_option(CONFIG_OPENTHREAD_BORDER_ROUTER OT_BORDER_ROUTER "Enable Border Router") +kconfig_to_ot_option(CONFIG_OPENTHREAD_BORDER_ROUTING OT_BORDER_ROUTING "Enable Border routing") +kconfig_to_ot_option(CONFIG_OPENTHREAD_BORDER_ROUTING_COUNTERS OT_BORDER_ROUTING_COUNTERS "Enable Border routing counters") +kconfig_to_ot_option(CONFIG_OPENTHREAD_BORDER_ROUTING_DHCP6_PD OT_BORDER_ROUTING_DHCP6_PD "DHCPv6-PD support in border routing") +kconfig_to_ot_option(CONFIG_OPENTHREAD_CHANNEL_MANAGER OT_CHANNEL_MANAGER "Enable channel manager support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_CHANNEL_MONITOR OT_CHANNEL_MONITOR "Enable channel monitor support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_COAP OT_COAP "Enable CoAP API") +kconfig_to_ot_option(CONFIG_OPENTHREAD_COAP_BLOCK OT_COAP_BLOCK "Enable CoAP Block-wise option support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_COAP_OBSERVE OT_COAP_OBSERVE "Enable CoAP Observe option support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_COAPS OT_COAPS "Enable secure CoAP API support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_COMMISSIONER OT_COMMISSIONER "Enable Commissioner") +kconfig_to_ot_option(CONFIG_OPENTHREAD_CSL_AUTO_SYNC OT_CSL_AUTO_SYNC "Enable csl autosync") +kconfig_to_ot_option(CONFIG_OPENTHREAD_CSL_DEBUG OT_CSL_DEBUG "Enable CSL debug") +kconfig_to_ot_option(CONFIG_OPENTHREAD_CSL_RECEIVER OT_CSL_RECEIVER "Enable CSL receiver feature for Thread 1.2") +kconfig_to_ot_option(CONFIG_OPENTHREAD_CSL_RECEIVER_LOCAL_TIME_SYNC OT_CSL_RECEIVER_LOCAL_TIME_SYNC "Use local time for CSL sync") +kconfig_to_ot_option(CONFIG_OPENTHREAD_DATASET_UPDATER OT_DATASET_UPDATER "Enable Dataset updater") +kconfig_to_ot_option(CONFIG_OPENTHREAD_DEVICE_PROP_LEADER_WEIGHT OT_DEVICE_PROP_LEADER_WEIGHT "Enable device props for leader weight") +kconfig_to_ot_option(CONFIG_OPENTHREAD_DHCP6_CLIENT OT_DHCP6_CLIENT "Enable DHCPv6 Client") +kconfig_to_ot_option(CONFIG_OPENTHREAD_DHCP6_SERVER OT_DHCP6_SERVER "Enable DHCPv6 Server") +kconfig_to_ot_option(CONFIG_OPENTHREAD_DIAG OT_DIAGNOSTIC "Enable Diagnostics support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_DNS_CLIENT OT_DNS_CLIENT "Enable DNS client support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_DNS_CLIENT_OVER_TCP OT_DNS_CLIENT_OVER_TCP "Enable dns query over tcp") +kconfig_to_ot_option(CONFIG_OPENTHREAD_DNS_DSO OT_DNS_DSO "Enable DNS Stateful Operations (DSO) support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_DNS_UPSTREAM_QUERY OT_DNS_UPSTREAM_QUERY "Enable forwarding DNS queries to upstream") +kconfig_to_ot_option(CONFIG_OPENTHREAD_DNSSD_SERVER OT_DNSSD_SERVER "Enable DNS-SD server support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_DUA OT_DUA "Enable Domain Unicast Address feature for Thread 1.2") +kconfig_to_ot_option(CONFIG_OPENTHREAD_ECDSA OT_ECDSA "Enable ECDSA support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_ENABLE_SERVICE OT_SERVICE "Enable Service entries in Thread Network Data") +kconfig_to_ot_option(CONFIG_OPENTHREAD_EXTERNAL_HEAP OT_EXTERNAL_HEAP "Enable external heap support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_FIREWALL OT_FIREWALL "Enable firewall") +kconfig_to_ot_option(CONFIG_OPENTHREAD_FULL_LOGS OT_FULL_LOGS "Enable full logs") +kconfig_to_ot_option(CONFIG_OPENTHREAD_HISTORY_TRACKER OT_HISTORY_TRACKER "Enable history tracker support.") +kconfig_to_ot_option(CONFIG_OPENTHREAD_IP6_FRAGM OT_IP6_FRAGM "Enable IPv6 fragmentation support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_JAM_DETECTION OT_JAM_DETECTION "Enable Jam Detection") +kconfig_to_ot_option(CONFIG_OPENTHREAD_JOINER OT_JOINER "Enable Joiner") +kconfig_to_ot_option(CONFIG_OPENTHREAD_LEGACY OT_LEGACY "Enable legacy network support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_LINK_METRICS_INITIATOR OT_LINK_METRICS_INITIATOR "Enable Link Metrics initiator for Thread 1.2") +kconfig_to_ot_option(CONFIG_OPENTHREAD_LINK_METRICS_MANAGER OT_LINK_METRICS_MANAGER "Enable Link Metrics manager for Thread 1.2") +kconfig_to_ot_option(CONFIG_OPENTHREAD_LINK_METRICS_SUBJECT OT_LINK_METRICS_SUBJECT "Enable Link Metrics subject for Thread 1.2") +kconfig_to_ot_option(CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC OT_LOG_LEVEL_DYNAMIC "Enable dynamic log level control") +kconfig_to_ot_option(CONFIG_OPENTHREAD_MAC_FILTER OT_MAC_FILTER "Enable MAC filter support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_MESH_DIAG OT_MESH_DIAG "Enable Mesh Diagnostics") +kconfig_to_ot_option(CONFIG_OPENTHREAD_MESSAGE_USE_HEAP OT_MESSAGE_USE_HEAP "Enable heap allocator for message buffers") +kconfig_to_ot_option(CONFIG_OPENTHREAD_MLE_LONG_ROUTES OT_MLE_LONG_ROUTES "Enable MLE long routes support (Experimental)") +kconfig_to_ot_option(CONFIG_OPENTHREAD_MLR OT_MLR "Enable Multicast Listener Registration feature for Thread 1.2") +kconfig_to_ot_option(CONFIG_OPENTHREAD_MULTIPAN_RCP OT_MULTIPAN_RCP "Enable Multi-PAN RCP") +kconfig_to_ot_option(CONFIG_OPENTHREAD_MULTIPLE_INSTANCE OT_MULTIPLE_INSTANCE "Enable multiple instances") +kconfig_to_ot_option(CONFIG_OPENTHREAD_NAT64_BORDER_ROUTING OT_NAT64_BORDER_ROUTING "Enable border routing NAT64 support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_NAT64_TRANSLATOR OT_NAT64_TRANSLATOR "Enable NAT64 translator") +kconfig_to_ot_option(CONFIG_OPENTHREAD_NEIGHBOR_DISCOVERY_AGENT OT_NEIGHBOR_DISCOVERY_AGENT "Enable neighbor discovery agent support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_NETDIAG_CLIENT OT_NETDIAG_CLIENT "Enable TMF network diagnostics on clients") +kconfig_to_ot_option(CONFIG_OPENTHREAD_NETDATA_PUBLISHER OT_NETDATA_PUBLISHER "Enable Thread Network Data publisher") +kconfig_to_ot_option(CONFIG_OPENTHREAD_OPERATIONAL_DATASET_AUTO_INIT OT_OPERATIONAL_DATASET_AUTO_INIT "Enable operational dataset auto init") +kconfig_to_ot_option(CONFIG_OPENTHREAD_OTNS OT_OTNS "Enable OTNS support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_PING_SENDER OT_PING_SENDER "Enable ping sender support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_PLATFORM_KEY_REF OT_PLATFORM_KEY_REF "Enable platform key reference support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_PLATFORM_NETIF OT_PLATFORM_NETIF "Enable platform netif support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_PLATFORM_UDP OT_PLATFORM_UDP "Enable platform UDP support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_RADIO_LINK_IEEE_802_15_4_ENABLE OT_15_4 "Enable 802.15.4 radio") +kconfig_to_ot_option(CONFIG_OPENTHREAD_RAW OT_LINK_RAW "Enable Link Raw") +kconfig_to_ot_option(CONFIG_OPENTHREAD_REFERENCE_DEVICE OT_REFERENCE_DEVICE "Enable Thread Certification Reference Device") +kconfig_to_ot_option(CONFIG_OPENTHREAD_SETTINGS_RAM OT_SETTINGS_RAM "Enable volatile-only storage of settings") +kconfig_to_ot_option(CONFIG_OPENTHREAD_SLAAC OT_SLAAC "Enable SLAAC") +kconfig_to_ot_option(CONFIG_OPENTHREAD_SNTP_CLIENT OT_SNTP_CLIENT "Enable SNTP Client support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_SRP_CLIENT OT_SRP_CLIENT "Enable SRP Client support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_SRP_SERVER OT_SRP_SERVER "Enable SRP Server support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_TCP_ENABLE OT_TCP "Enable TCP support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_TIME_SYNC OT_TIME_SYNC "Enable the time synchronization service feature") +kconfig_to_ot_option(CONFIG_OPENTHREAD_TREL OT_TREL "Enable TREL radio link for Thread over Infrastructure feature") +kconfig_to_ot_option(CONFIG_OPENTHREAD_TX_BEACON_PAYLOAD OT_TX_BEACON_PAYLOAD "Enable tx beacon payload support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_TX_QUEUE_STATISTICS OT_TX_QUEUE_STATS "Enable tx queue statistics") +kconfig_to_ot_option(CONFIG_OPENTHREAD_UDP_FORWARD OT_UDP_FORWARD "Enable UDP forward feature") +kconfig_to_ot_option(CONFIG_OPENTHREAD_UPTIME OT_UPTIME "Enable support for tracking OpenThread instance's uptime") -if(CONFIG_OPENTHREAD_CSL_RECEIVER_LOCAL_TIME_SYNC) - set(OT_CSL_RECEIVER_LOCAL_TIME_SYNC ON CACHE BOOL "Use local time for CSL sync" FORCE) -else() - set(OT_CSL_RECEIVER_LOCAL_TIME_SYNC OFF CACHE BOOL "Use local time for CSL sync" FORCE) -endif() - -if(CONFIG_OPENTHREAD_DATASET_UPDATER) - set(OT_DATASET_UPDATER ON CACHE BOOL "Enable Dataset updater" FORCE) -else() - set(OT_DATASET_UPDATER OFF CACHE BOOL "Enable Dataset updater" FORCE) -endif() - -if(CONFIG_OPENTHREAD_DEVICE_PROP_LEADER_WEIGHT) - set(OT_DEVICE_PROP_LEADER_WEIGHT ON CACHE BOOL "Enable device props for leader weight" FORCE) -else() - set(OT_DEVICE_PROP_LEADER_WEIGHT OFF CACHE BOOL "Enable device props for leader weight" FORCE) -endif() - -if(CONFIG_OPENTHREAD_DHCP6_CLIENT) - set(OT_DHCP6_CLIENT ON CACHE BOOL "Enable DHCPv6 Client" FORCE) -else() - set(OT_DHCP6_CLIENT OFF CACHE BOOL "Enable DHCPv6 Client" FORCE) -endif() - -if(CONFIG_OPENTHREAD_DHCP6_SERVER) - set(OT_DHCP6_SERVER ON CACHE BOOL "Enable DHCPv6 Server" FORCE) -else() - set(OT_DHCP6_SERVER OFF CACHE BOOL "Enable DHCPv6 Server" FORCE) -endif() - -if(CONFIG_OPENTHREAD_DIAG) - set(OT_DIAGNOSTIC ON CACHE BOOL "Enable Diagnostics support" FORCE) -else() - set(OT_DIAGNOSTIC OFF CACHE BOOL "Enable Diagnostics support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_DNS_CLIENT) - set(OT_DNS_CLIENT ON CACHE BOOL "Enable DNS client support" FORCE) -else() - set(OT_DNS_CLIENT OFF CACHE BOOL "Enable DNS client support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_DNS_CLIENT_OVER_TCP) - set(OT_DNS_CLIENT_OVER_TCP ON CACHE BOOL "Enable dns query over tcp" FORCE) -else() - set(OT_DNS_CLIENT_OVER_TCP OFF CACHE BOOL "Enable dns query over tcp" FORCE) -endif() - -if(CONFIG_OPENTHREAD_DNS_DSO) - set(OT_DNS_DSO ON CACHE BOOL "Enable DNS Stateful Operations (DSO) support" FORCE) -else() - set(OT_DNS_DSO OFF CACHE BOOL "Enable DNS Stateful Operations (DSO) support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_DNS_UPSTREAM_QUERY) - set(OT_DNS_UPSTREAM_QUERY ON CACHE BOOL "Enable forwarding DNS queries to upstream" FORCE) -else() - set(OT_DNS_UPSTREAM_QUERY OFF CACHE BOOL "Enable forwarding DNS queries to upstream" FORCE) -endif() - -if(CONFIG_OPENTHREAD_DNSSD_SERVER) - set(OT_DNSSD_SERVER ON CACHE BOOL "Enable DNS-SD server support" FORCE) -else() - set(OT_DNSSD_SERVER OFF CACHE BOOL "Enable DNS-SD server support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_DUA) - set(OT_DUA ON CACHE BOOL "Enable Domain Unicast Address feature for Thread 1.2" FORCE) -else() - set(OT_DUA OFF CACHE BOOL "Enable Domain Unicast Address feature for Thread 1.2" FORCE) -endif() - -if(CONFIG_OPENTHREAD_ECDSA) - set(OT_ECDSA ON CACHE BOOL "Enable ECDSA support" FORCE) -else() - set(OT_ECDSA OFF CACHE BOOL "Enable ECDSA support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_ENABLE_SERVICE) - set(OT_SERVICE ON CACHE BOOL "Enable Service entries in Thread Network Data" FORCE) -else() - set(OT_SERVICE OFF CACHE BOOL "Enable Service entries in Thread Network Data" FORCE) -endif() - -if(CONFIG_OPENTHREAD_EXTERNAL_HEAP) - set(OT_EXTERNAL_HEAP ON CACHE BOOL "Enable external heap support" FORCE) -else() - set(OT_EXTERNAL_HEAP OFF CACHE BOOL "Enable external heap support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_FIREWALL) - set(OT_FIREWALL ON CACHE BOOL "Enable firewall" FORCE) -else() - set(OT_FIREWALL OFF CACHE BOOL "Enable firewall" FORCE) -endif() - -if(CONFIG_OPENTHREAD_FULL_LOGS) - set(OT_FULL_LOGS ON CACHE BOOL "Enable full logs" FORCE) -else() - set(OT_FULL_LOGS OFF CACHE BOOL "Enable full logs" FORCE) -endif() - -if(CONFIG_OPENTHREAD_HISTORY_TRACKER) - set(OT_HISTORY_TRACKER ON CACHE BOOL "Enable history tracker support." FORCE) -else() - set(OT_HISTORY_TRACKER OFF CACHE BOOL "Enable history tracker support." FORCE) -endif() - -if(CONFIG_OPENTHREAD_IP6_FRAGM) - set(OT_IP6_FRAGM ON CACHE BOOL "Enable IPv6 fragmentation support" FORCE) -else() - set(OT_IP6_FRAGM OFF CACHE BOOL "Enable IPv6 fragmentation support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_JAM_DETECTION) - set(OT_JAM_DETECTION ON CACHE BOOL "Enable Jam Detection" FORCE) -else() - set(OT_JAM_DETECTION OFF CACHE BOOL "Enable Jam Detection" FORCE) -endif() - -if(CONFIG_OPENTHREAD_JOINER) - set(OT_JOINER ON CACHE BOOL "Enable Joiner" FORCE) -else() - set(OT_JOINER OFF CACHE BOOL "Enable Joiner" FORCE) -endif() - -if(CONFIG_OPENTHREAD_LEGACY) - set(OT_LEGACY ON CACHE BOOL "Enable legacy network support" FORCE) -else() - set(OT_LEGACY OFF CACHE BOOL "Enable legacy network support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_LINK_METRICS_INITIATOR) - set(OT_LINK_METRICS_INITIATOR ON CACHE BOOL "Enable Link Metrics initiator for Thread 1.2" FORCE) -else() - set(OT_LINK_METRICS_INITIATOR OFF CACHE BOOL "Enable Link Metrics initiator for Thread 1.2" FORCE) -endif() - -if(CONFIG_OPENTHREAD_LINK_METRICS_MANAGER) - set(OT_LINK_METRICS_MANAGER ON CACHE BOOL "Enable Link Metrics manager for Thread 1.2" FORCE) -else() - set(OT_LINK_METRICS_MANAGER OFF CACHE BOOL "Enable Link Metrics manager for Thread 1.2" FORCE) -endif() - -if(CONFIG_OPENTHREAD_LINK_METRICS_SUBJECT) - set(OT_LINK_METRICS_SUBJECT ON CACHE BOOL "Enable Link Metrics subject for Thread 1.2" FORCE) -else() - set(OT_LINK_METRICS_SUBJECT OFF CACHE BOOL "Enable Link Metrics subject for Thread 1.2" FORCE) -endif() - -if(CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC) - set(OT_LOG_LEVEL_DYNAMIC ON CACHE BOOL "Enable dynamic log level control" FORCE) -else() - set(OT_LOG_LEVEL_DYNAMIC OFF CACHE BOOL "Enable dynamic log level control" FORCE) -endif() - -if(CONFIG_OPENTHREAD_MAC_FILTER) - set(OT_MAC_FILTER ON CACHE BOOL "Enable MAC filter support" FORCE) -else() - set(OT_MAC_FILTER OFF CACHE BOOL "Enable MAC filter support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_MESH_DIAG) - set(OT_MESH_DIAG ON CACHE BOOL "Enable Mesh Diagnostics" FORCE) -else() - set(OT_MESH_DIAG OFF CACHE BOOL "Enable Mesh Diagnostics" FORCE) -endif() - -if(CONFIG_OPENTHREAD_MESSAGE_USE_HEAP) - set(OT_MESSAGE_USE_HEAP ON CACHE BOOL "Enable heap allocator for message buffers" FORCE) -else() - set(OT_MESSAGE_USE_HEAP OFF CACHE BOOL "Enable heap allocator for message buffers" FORCE) -endif() - -if(CONFIG_OPENTHREAD_MLE_LONG_ROUTES) - set(OT_MLE_LONG_ROUTES ON CACHE BOOL "Enable MLE long routes support (Experimental)" FORCE) -else() - set(OT_MLE_LONG_ROUTES OFF CACHE BOOL "Enable MLE long routes support (Experimental)" FORCE) -endif() - -if(CONFIG_OPENTHREAD_MLR) - set(OT_MLR ON CACHE BOOL "Enable Multicast Listener Registration feature for Thread 1.2" FORCE) -else() - set(OT_MLR OFF CACHE BOOL "Enable Multicast Listener Registration feature for Thread 1.2" FORCE) -endif() - -if(CONFIG_OPENTHREAD_MULTIPAN_RCP) - set(OT_MULTIPAN_RCP ON CACHE BOOL "Enable Multi-PAN RCP" FORCE) -else() - set(OT_MULTIPAN_RCP OFF CACHE BOOL "Enable Multi-PAN RCP" FORCE) -endif() - -if(CONFIG_OPENTHREAD_MULTIPLE_INSTANCE) - set(OT_MULTIPLE_INSTANCE ON CACHE BOOL "Enable multiple instances" FORCE) -else() - set(OT_MULTIPLE_INSTANCE OFF CACHE BOOL "Enable multiple instances" FORCE) -endif() - -if(CONFIG_OPENTHREAD_NAT64_BORDER_ROUTING) - set(OT_NAT64_BORDER_ROUTING ON CACHE BOOL "Enable border routing NAT64 support" FORCE) -else() - set(OT_NAT64_BORDER_ROUTING OFF CACHE BOOL "Enable border routing NAT64 support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_NAT64_TRANSLATOR) - set(OT_NAT64_TRANSLATOR ON CACHE BOOL "Enable NAT64 translator" FORCE) -else() - set(OT_NAT64_TRANSLATOR OFF CACHE BOOL "Enable NAT64 translator" FORCE) -endif() - -if(CONFIG_OPENTHREAD_NEIGHBOR_DISCOVERY_AGENT) - set(OT_NEIGHBOR_DISCOVERY_AGENT ON CACHE BOOL "Enable neighbor discovery agent support" FORCE) -else() - set(OT_NEIGHBOR_DISCOVERY_AGENT OFF CACHE BOOL "Enable neighbor discovery agent support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_NETDIAG_CLIENT) - set(OT_NETDIAG_CLIENT ON CACHE BOOL "Enable TMF network diagnostics on clients" FORCE) -else() - set(OT_NETDIAG_CLIENT OFF CACHE BOOL "Enable TMF network diagnostics on clients" FORCE) -endif() - -if(CONFIG_OPENTHREAD_NETDATA_PUBLISHER) - set(OT_NETDATA_PUBLISHER ON CACHE BOOL "Enable Thread Network Data publisher" FORCE) -else() - set(OT_NETDATA_PUBLISHER OFF CACHE BOOL "Enable Thread Network Data publisher" FORCE) -endif() - -if(CONFIG_OPENTHREAD_OPERATIONAL_DATASET_AUTO_INIT) - set(OT_OPERATIONAL_DATASET_AUTO_INIT ON CACHE BOOL "Enable operational dataset auto init" FORCE) -else() - set(OT_OPERATIONAL_DATASET_AUTO_INIT OFF CACHE BOOL "Enable operational dataset auto init" FORCE) -endif() - -if(CONFIG_OPENTHREAD_OTNS) - set(OT_OTNS ON CACHE BOOL "Enable OTNS support" FORCE) -else() - set(OT_OTNS OFF CACHE BOOL "Enable OTNS support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_PING_SENDER) - set(OT_PING_SENDER ON CACHE BOOL "Enable ping sender support" FORCE) -else() - set(OT_PING_SENDER OFF CACHE BOOL "Enable ping sender support" FORCE) -endif() - -if(OPENTHREAD_PLATFORM_KEY_REF) - set(OT_PLATFORM_KEY_REF ON CACHE BOOL "Enable platform key reference support" FORCE) -else() - set(OT_PLATFORM_KEY_REF OFF CACHE BOOL "Enable platform key reference support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_PLATFORM_NETIF) - set(OT_PLATFORM_NETIF ON CACHE BOOL "Enable platform netif support" FORCE) -else() - set(OT_PLATFORM_NETIF OFF CACHE BOOL "Enable platform netif support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_PLATFORM_UDP) - set(OT_PLATFORM_UDP ON CACHE BOOL "Enable platform UDP support" FORCE) -else() - set(OT_PLATFORM_UDP OFF CACHE BOOL "Enable platform UDP support" FORCE) +if(CONFIG_OPENTHREAD_COPROCESSOR_VENDOR_HOOK_SOURCE) + set(OT_NCP_VENDOR_HOOK_SOURCE ${CONFIG_OPENTHREAD_COPROCESSOR_VENDOR_HOOK_SOURCE} CACHE STRING "NCP vendor hook source file name" FORCE) endif() if(CONFIG_OPENTHREAD_POWER_SUPPLY) set(OT_POWER_SUPPLY ${CONFIG_OPENTHREAD_POWER_SUPPLY} CACHE STRING "Power supply configuration" FORCE) endif() -if(CONFIG_OPENTHREAD_RADIO_LINK_IEEE_802_15_4_ENABLE) - set(OT_15_4 ON CACHE BOOL "Enable 802.15.4 radio" FORCE) -else() - set(OT_15_4 OFF CACHE BOOL "Enable 802.15.4 radio" FORCE) -endif() - -if(CONFIG_OPENTHREAD_RAW) - set(OT_LINK_RAW ON CACHE BOOL "Enable Link Raw" FORCE) -else() - set(OT_LINK_RAW OFF CACHE BOOL "Enable Link Raw" FORCE) -endif() - -if(CONFIG_OPENTHREAD_REFERENCE_DEVICE) - set(OT_REFERENCE_DEVICE ON CACHE BOOL "Enable Thread Certification Reference Device" FORCE) -else() - set(OT_REFERENCE_DEVICE OFF CACHE BOOL "Enable Thread Certification Reference Device" FORCE) -endif() - -if(CONFIG_OPENTHREAD_SETTINGS_RAM) - set(OT_SETTINGS_RAM ON CACHE BOOL "Enable volatile-only storage of settings" FORCE) -else() - set(OT_SETTINGS_RAM OFF CACHE BOOL "Enable volatile-only storage of settings" FORCE) -endif() - -if(CONFIG_OPENTHREAD_SLAAC) - set(OT_SLAAC ON CACHE BOOL "Enable SLAAC" FORCE) -else() - set(OT_SLAAC OFF CACHE BOOL "Enable SLAAC" FORCE) -endif() - -if(CONFIG_OPENTHREAD_SNTP_CLIENT) - set(OT_SNTP_CLIENT ON CACHE BOOL "Enable SNTP Client support" FORCE) -else() - set(OT_SNTP_CLIENT OFF CACHE BOOL "Enable SNTP Client support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_SRP_CLIENT) - set(OT_SRP_CLIENT ON CACHE BOOL "Enable SRP Client support" FORCE) -else() - set(OT_SRP_CLIENT OFF CACHE BOOL "Enable SRP Client support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_SRP_SERVER) - set(OT_SRP_SERVER ON CACHE BOOL "Enable SRP Server support" FORCE) -else() - set(OT_SRP_SERVER OFF CACHE BOOL "Enable SRP Server support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_TCP_ENABLE) - set(OT_TCP ON CACHE BOOL "Enable TCP support" FORCE) -else() - set(OT_TCP OFF CACHE BOOL "Enable TCP support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_TIME_SYNC) - set(OT_TIME_SYNC ON CACHE BOOL "Enable the time synchronization service feature" FORCE) -else() - set(OT_TIME_SYNC OFF CACHE BOOL "Enable the time synchronization service feature" FORCE) -endif() - -if(CONFIG_OPENTHREAD_TREL) - set(OT_TREL ON CACHE BOOL "Enable TREL radio link for Thread over Infrastructure feature" FORCE) -else() - set(OT_TREL OFF CACHE BOOL "Enable TREL radio link for Thread over Infrastructure feature" FORCE) -endif() - -if(CONFIG_OPENTHREAD_TX_BEACON_PAYLOAD) - set(OT_TX_BEACON_PAYLOAD ON CACHE BOOL "Enable tx beacon payload support" FORCE) -else() - set(OT_TX_BEACON_PAYLOAD OFF CACHE BOOL "Enable tx beacon payload support" FORCE) -endif() - -if(CONFIG_OPENTHREAD_TX_QUEUE_STATISTICS) - set(OT_TX_QUEUE_STATS ON CACHE BOOL "Enable tx queue statistics" FORCE) -else() - set(OT_TX_QUEUE_STATS OFF CACHE BOOL "Enable tx queue statistics" FORCE) -endif() - -if(CONFIG_OPENTHREAD_UDP_FORWARD) - set(OT_UDP_FORWARD ON CACHE BOOL "Enable UDP forward feature" FORCE) -else() - set(OT_UDP_FORWARD OFF CACHE BOOL "Enable UDP forward feature" FORCE) -endif() - -if(CONFIG_OPENTHREAD_UPTIME) - set(OT_UPTIME ON CACHE BOOL "Enable support for tracking OpenThread instance's uptime" FORCE) -else() - set(OT_UPTIME OFF CACHE BOOL "Enable support for tracking OpenThread instance's uptime" FORCE) -endif() - -if(CONFIG_OPENTHREAD_COPROCESSOR_VENDOR_HOOK_SOURCE) - set(OT_NCP_VENDOR_HOOK_SOURCE ${CONFIG_OPENTHREAD_COPROCESSOR_VENDOR_HOOK_SOURCE} CACHE STRING "NCP vendor hook source file name" FORCE) -endif() - set(BUILD_TESTING OFF CACHE BOOL "Disable openthread cmake testing targets" FORCE) # Zephyr logging options From 2fea89562a6981c749378721e65cd3ed19d6c30a Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Wed, 3 Jan 2024 11:24:45 +0100 Subject: [PATCH 1082/1623] [nrf fromtree] net: openthread: increase TCAT stack size Running TCAT with PSA crypto API causes stack overflow. Increased stack size. Signed-off-by: Maciej Baczmanski (cherry picked from commit 11613e08e71d52db0438e4d25780f40489793ce4) --- modules/openthread/Kconfig.thread | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/openthread/Kconfig.thread b/modules/openthread/Kconfig.thread index 66e039b7300..542992e7fa1 100644 --- a/modules/openthread/Kconfig.thread +++ b/modules/openthread/Kconfig.thread @@ -184,6 +184,7 @@ config OPENTHREAD_DEFAULT_TX_POWER config OPENTHREAD_BLE_TCAT_THREAD_STACK_SIZE int "Openthread default TCAT stack size" + default 5120 if OPENTHREAD_CRYPTO_PSA default 4200 help Openthread default TCAT stack size. From 49502a0e47021b69efc7b2708ff68c8a2dc19423 Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Thu, 4 Jan 2024 10:27:34 +0100 Subject: [PATCH 1083/1623] [nrf fromtree] net: openthread: add missing cmake option Added `OT_PLATFORM_POWER_CALIBRATION` and set to always off as in Zephyr power calibration is handled by Radio Driver. Signed-off-by: Maciej Baczmanski (cherry picked from commit d0283f9b158ddb36e79ec490a1f7f0ddbe3fb04c) --- modules/openthread/CMakeLists.txt | 1 + .../platform/openthread-core-zephyr-config.h | 11 ----------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index 6691084eebd..c9ccf074649 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -15,6 +15,7 @@ endmacro() set(OT_BUILD_EXECUTABLES OFF CACHE BOOL "Disable OpenThread samples") set(OT_BUILTIN_MBEDTLS_MANAGEMENT OFF CACHE BOOL "Use Zephyr's mbedTLS heap") set(OT_PLATFORM "zephyr" CACHE STRING "Zephyr as a target platform") +set(OT_PLATFORM_POWER_CALIBRATION OFF CACHE BOOL "Use Zephyr's power calibration handled by Radio Driver") set(OT_THREAD_VERSION ${CONFIG_OPENTHREAD_THREAD_VERSION} CACHE STRING "User selected Thread stack version") set(OT_CLI_TRANSPORT "CONSOLE" CACHE STRING "Set CLI to use console interpreter") diff --git a/modules/openthread/platform/openthread-core-zephyr-config.h b/modules/openthread/platform/openthread-core-zephyr-config.h index 773cd170f2c..71a087ca0b5 100644 --- a/modules/openthread/platform/openthread-core-zephyr-config.h +++ b/modules/openthread/platform/openthread-core-zephyr-config.h @@ -438,17 +438,6 @@ #define OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE 0 #endif -/** - * @def OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE - * - * In Zephyr, power calibration is handled by Radio Driver, so it can't be handled on OT level. - * - */ -#ifndef OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE -#define OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE 0 -#endif - - /** * @def OPENTHREAD_CONFIG_RADIO_STATS * From aa1125153bc9e3ead72dc65ae5f969d3d4281965 Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Wed, 10 Jan 2024 13:03:21 +0100 Subject: [PATCH 1084/1623] [nrf fromtree] net: openthread: implement `otPlatResetToBootloader` This commit implements `otPlatResetToBootloader` in two ways: - trigger reset to bootloader using boot mode retention API - trigger reset to bootloader by triggering GPIO pin (applicable for nRF52840 Dongle) Signed-off-by: Maciej Baczmanski (cherry picked from commit f32e68651133960f257f7505ac7fac7f46986252) --- dts/bindings/options/openthread,config.yaml | 7 +++ modules/openthread/CMakeLists.txt | 1 + modules/openthread/Kconfig.features | 23 ++++++- modules/openthread/platform/misc.c | 66 +++++++++++++++++++++ 4 files changed, 95 insertions(+), 2 deletions(-) diff --git a/dts/bindings/options/openthread,config.yaml b/dts/bindings/options/openthread,config.yaml index 054107fab44..6366c289c80 100644 --- a/dts/bindings/options/openthread,config.yaml +++ b/dts/bindings/options/openthread,config.yaml @@ -10,6 +10,7 @@ description: | compatible = "openthread,config"; diag-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>, <&gpio1 0 GPIO_ACTIVE_LOW>; + bootloader-gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>; }; }; @@ -21,3 +22,9 @@ properties: description: | This enables access to diagnostic GPIO pins. Each field consists of GPIO pin's configuration: controller's phandle, pin number and configuration flags. + + bootloader-gpios: + type: phandle-array + description: | + This enables resetting to bootloader by triggering given GPIO pin. Property represents + chosen GPIO pin's configuration: controller's phandle, pin number and configuration flags. diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index c9ccf074649..5b64d3be2f5 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -99,6 +99,7 @@ kconfig_to_ot_option(CONFIG_OPENTHREAD_NETDATA_PUBLISHER OT_NETDATA_PUBLISHER "E kconfig_to_ot_option(CONFIG_OPENTHREAD_OPERATIONAL_DATASET_AUTO_INIT OT_OPERATIONAL_DATASET_AUTO_INIT "Enable operational dataset auto init") kconfig_to_ot_option(CONFIG_OPENTHREAD_OTNS OT_OTNS "Enable OTNS support") kconfig_to_ot_option(CONFIG_OPENTHREAD_PING_SENDER OT_PING_SENDER "Enable ping sender support") +kconfig_to_ot_option(CONFIG_OPENTHREAD_PLATFORM_BOOTLOADER_MODE OT_PLATFORM_BOOTLOADER_MODE "Enable platform bootloader mode support") kconfig_to_ot_option(CONFIG_OPENTHREAD_PLATFORM_KEY_REF OT_PLATFORM_KEY_REF "Enable platform key reference support") kconfig_to_ot_option(CONFIG_OPENTHREAD_PLATFORM_NETIF OT_PLATFORM_NETIF "Enable platform netif support") kconfig_to_ot_option(CONFIG_OPENTHREAD_PLATFORM_UDP OT_PLATFORM_UDP "Enable platform UDP support") diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index 952a7853b43..ba3990a348d 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -17,7 +17,7 @@ config OPENTHREAD_THREAD_VERSION_1_3 bool "Version 1.3" config OPENTHREAD_THREAD_VERSION_1_3_1 bool "Version 1.3.1" -endchoice +endchoice # OPENTHREAD_STACK_VERSION config OPENTHREAD_THREAD_VERSION string @@ -255,6 +255,25 @@ config OPENTHREAD_PLATFORM_KEY_REF Enable usage of cryptographic key references instead of literal keys. This requires a crypto backend library that supports key references. +choice OPENTHREAD_PLATFORM_BOOTLOADER_MODE_CHOICE + prompt "Platform bootloader mode configuration" + optional + +config OPENTHREAD_PLATFORM_BOOTLOADER_MODE_RETENTION + bool "Bootloader mode support with boot mode retention API" + depends on RETENTION_BOOT_MODE && REBOOT + select OPENTHREAD_PLATFORM_BOOTLOADER_MODE + +config OPENTHREAD_PLATFORM_BOOTLOADER_MODE_GPIO + bool "Bootloader mode support with GPIO pin trigger" + select OPENTHREAD_PLATFORM_BOOTLOADER_MODE +endchoice # OPENTHREAD_PLATFORM_BOOTLOADER_MODE + +config OPENTHREAD_PLATFORM_BOOTLOADER_MODE + bool + help + Platform bootloader mode support + config OPENTHREAD_PLATFORM_NETIF bool "Platform netif support" @@ -276,7 +295,7 @@ config OPENTHREAD_POWER_SUPPLY_EXTERNAL_STABLE config OPENTHREAD_POWER_SUPPLY_EXTERNAL_UNSTABLE bool "OT_POWER_SUPPLY_EXTERNAL_UNSTABLE" -endchoice +endchoice # OPENTHREAD_POWER_SUPPLY_CHOICE config OPENTHREAD_POWER_SUPPLY string diff --git a/modules/openthread/platform/misc.c b/modules/openthread/platform/misc.c index 7f57dddb9e3..11fdc42ec34 100644 --- a/modules/openthread/platform/misc.c +++ b/modules/openthread/platform/misc.c @@ -9,6 +9,24 @@ #include #include +#if defined(CONFIG_OPENTHREAD_PLATFORM_BOOTLOADER_MODE_RETENTION) + +#include + +#elif defined(CONFIG_OPENTHREAD_PLATFORM_BOOTLOADER_MODE_GPIO) + +BUILD_ASSERT(DT_HAS_COMPAT_STATUS_OKAY(openthread_config), + "`openthread,config` compatible node not found"); +BUILD_ASSERT(DT_NODE_HAS_PROP(DT_COMPAT_GET_ANY_STATUS_OKAY(openthread_config), bootloader_gpios), + "`bootloader-gpios` property missing from `openthread,config` compatible node"); + +#include + +static const struct gpio_dt_spec bootloader_gpio = + GPIO_DT_SPEC_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(openthread_config), + bootloader_gpios); +#endif + #include "platform-zephyr.h" void otPlatReset(otInstance *aInstance) @@ -19,6 +37,54 @@ void otPlatReset(otInstance *aInstance) sys_reboot(SYS_REBOOT_WARM); } +#if defined(CONFIG_OPENTHREAD_PLATFORM_BOOTLOADER_MODE) +otError otPlatResetToBootloader(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + +#if defined(CONFIG_OPENTHREAD_PLATFORM_BOOTLOADER_MODE_RETENTION) + if (bootmode_set(BOOT_MODE_TYPE_BOOTLOADER)) { + return OT_ERROR_NOT_CAPABLE; + } + sys_reboot(SYS_REBOOT_WARM); + +#elif defined(CONFIG_OPENTHREAD_PLATFORM_BOOTLOADER_MODE_GPIO) + /* + * To enable resetting to bootloader by triggering gpio pin, + * select `CONFIG_OPENTHREAD_PLATFORM_BOOTLOADER_MODE_GPIO=y`, + * and in Devicetree create `openthread` node in `/options/` path with + * `compatible = "openthread,config"` property and `bootloader-gpios` property, + * which should represent GPIO pin's configuration, + * containing controller phandle, pin number and pin flags. e.g: + * + * options { + * openthread { + * compatible = "openthread,config"; + * bootloader-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>; + * }; + * }; + * + * Note: in below implementation, chosen GPIO pin is configured as output + * and initialized to active state (logical value ‘1’). + * Configuring pin flags in `bootloader-gpios` allows to choose + * if pin should be active in high or in low state. + */ + + if (!gpio_is_ready_dt(&bootloader_gpio)) { + return OT_ERROR_NOT_CAPABLE; + } + gpio_pin_configure_dt(&bootloader_gpio, GPIO_OUTPUT_ACTIVE); + +#endif + + /* + * Return OT_ERROR_NOT_CAPABLE if resetting has been unsuccessful (invalid configuration or + * triggering reset had no effect) + */ + return OT_ERROR_NOT_CAPABLE; +} +#endif /* defined(CONFIG_OPENTHREAD_PLATFORM_BOOTLOADER_MODE) */ + otPlatResetReason otPlatGetResetReason(otInstance *aInstance) { ARG_UNUSED(aInstance); From 6ba80b70b43cce7e3a84fcfb9833ea51b2139450 Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Wed, 10 Jan 2024 15:34:16 +0100 Subject: [PATCH 1085/1623] [nrf fromtree] net: openthread: Add new key and algorithm in PSA. This commit adds new types of keys and algorithm to crypto_psa backend of openthread. Added options: - `OT_CRYPTO_KEY_TYPE_ECDSA` - `OT_CRYPTO_KEY_ALG_ECDSA` - `OT_CRYPTO_KEY_USAGE_VERIFY_HASH` Signed-off-by: Przemyslaw Bida (cherry picked from commit 0018204091d104bda853ef870aaff8a1bc0e201c) --- modules/openthread/platform/crypto_psa.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/openthread/platform/crypto_psa.c b/modules/openthread/platform/crypto_psa.c index e5b234ce030..0dcf3803fde 100644 --- a/modules/openthread/platform/crypto_psa.c +++ b/modules/openthread/platform/crypto_psa.c @@ -41,6 +41,8 @@ static psa_key_type_t toPsaKeyType(otCryptoKeyType aType) return PSA_KEY_TYPE_AES; case OT_CRYPTO_KEY_TYPE_HMAC: return PSA_KEY_TYPE_HMAC; + case OT_CRYPTO_KEY_TYPE_ECDSA: + return PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1); default: return PSA_KEY_TYPE_NONE; } @@ -53,6 +55,8 @@ static psa_algorithm_t toPsaAlgorithm(otCryptoKeyAlgorithm aAlgorithm) return PSA_ALG_ECB_NO_PADDING; case OT_CRYPTO_KEY_ALG_HMAC_SHA_256: return PSA_ALG_HMAC(PSA_ALG_SHA_256); + case OT_CRYPTO_KEY_ALG_ECDSA: + return PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256); default: /* * There is currently no constant like PSA_ALG_NONE, but 0 is used @@ -82,6 +86,10 @@ static psa_key_usage_t toPsaKeyUsage(int aUsage) usage |= PSA_KEY_USAGE_SIGN_HASH; } + if (aUsage & OT_CRYPTO_KEY_USAGE_VERIFY_HASH) { + usage |= PSA_KEY_USAGE_VERIFY_HASH; + } + return usage; } @@ -89,9 +97,10 @@ static bool checkKeyUsage(int aUsage) { /* Check if only supported flags have been passed */ int supported_flags = OT_CRYPTO_KEY_USAGE_EXPORT | - OT_CRYPTO_KEY_USAGE_ENCRYPT | - OT_CRYPTO_KEY_USAGE_DECRYPT | - OT_CRYPTO_KEY_USAGE_SIGN_HASH; + OT_CRYPTO_KEY_USAGE_ENCRYPT | + OT_CRYPTO_KEY_USAGE_DECRYPT | + OT_CRYPTO_KEY_USAGE_SIGN_HASH | + OT_CRYPTO_KEY_USAGE_VERIFY_HASH; return (aUsage & ~supported_flags) == 0; } From f6a644d15377ea7b9c8b953eb60398a017c6402a Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Thu, 11 Jan 2024 16:59:23 +0100 Subject: [PATCH 1086/1623] [nrf fromtree] net: openthread: Remove PSA crypto backend workarounds Remove two workarounds in OpenThread's PSA crypto backend that were required when Zephyr used pre-1.5 TF-M version: 1. psa_open_key() is no longer needed to reference a persistent key 2. psa_cipher_encrypt() can be used to simplify AES encryption Signed-off-by: Damian Krolik (cherry picked from commit 36b7a3e701fb36135f97b60d893640a99cd0b7d6) --- modules/openthread/platform/crypto_psa.c | 68 +++--------------------- 1 file changed, 7 insertions(+), 61 deletions(-) diff --git a/modules/openthread/platform/crypto_psa.c b/modules/openthread/platform/crypto_psa.c index 0dcf3803fde..55018254154 100644 --- a/modules/openthread/platform/crypto_psa.c +++ b/modules/openthread/platform/crypto_psa.c @@ -111,31 +111,6 @@ static bool checkContext(otCryptoContext *aContext, size_t aMinSize) return aContext != NULL && aContext->mContext != NULL && aContext->mContextSize >= aMinSize; } -static void ensureKeyIsLoaded(otCryptoKeyRef aKeyRef) -{ - /* - * The workaround below will no longer be need after updating TF-M version used in Zephyr - * to 1.5.0 (see upstream commit 42e77b561fcfe19819ff1e63cb7c0b672ee8ba41). - * In the recent versions of TF-M the concept of key handles and psa_open_key()/ - * psa_close_key() APIs have been being deprecated, but the version currently used in Zephyr - * is in the middle of that transition. Consequently, psa_destroy_key() and lots of other - * functions will fail when a key ID that they take as a parameter is not loaded from the - * persistent storage. That may occur when a given persistent key is created via - * psa_generate_key() or psa_import_key(), and then the device reboots. - * - * Use psa_open_key() when the key has not been loaded yet to work around the issue. - */ - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_status_t status = psa_get_key_attributes(aKeyRef, &attributes); - psa_key_id_t key_handle; - - if (status == PSA_ERROR_INVALID_HANDLE) { - psa_open_key(aKeyRef, &key_handle); - } - - psa_reset_key_attributes(&attributes); -} - void otPlatCryptoInit(void) { psa_crypto_init(); @@ -195,15 +170,11 @@ otError otPlatCryptoExportKey(otCryptoKeyRef aKeyRef, return OT_ERROR_INVALID_ARGS; } - ensureKeyIsLoaded(aKeyRef); - return psaToOtError(psa_export_key(aKeyRef, aBuffer, aBufferLen, aKeyLen)); } otError otPlatCryptoDestroyKey(otCryptoKeyRef aKeyRef) { - ensureKeyIsLoaded(aKeyRef); - return psaToOtError(psa_destroy_key(aKeyRef)); } @@ -212,7 +183,6 @@ bool otPlatCryptoHasKey(otCryptoKeyRef aKeyRef) psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_status_t status; - ensureKeyIsLoaded(aKeyRef); status = psa_get_key_attributes(aKeyRef, &attributes); psa_reset_key_attributes(&attributes); @@ -255,7 +225,6 @@ otError otPlatCryptoHmacSha256Start(otCryptoContext *aContext, const otCryptoKey return OT_ERROR_INVALID_ARGS; } - ensureKeyIsLoaded(aKey->mKeyRef); operation = aContext->mContext; status = psa_mac_sign_setup(operation, aKey->mKeyRef, PSA_ALG_HMAC(PSA_ALG_SHA_256)); @@ -323,7 +292,6 @@ otError otPlatCryptoAesEncrypt(otCryptoContext *aContext, const uint8_t *aInput, { const size_t block_size = PSA_BLOCK_CIPHER_BLOCK_LENGTH(PSA_KEY_TYPE_AES); psa_status_t status = PSA_SUCCESS; - psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; psa_key_id_t *key_ref; size_t cipher_length; @@ -331,37 +299,15 @@ otError otPlatCryptoAesEncrypt(otCryptoContext *aContext, const uint8_t *aInput, return OT_ERROR_INVALID_ARGS; } - /* - * The code below can be simplified after updating TF-M version used in Zephyr to 1.5.0 - * (see upstream commit: 045ec4abfc73152a0116684ba9127d0a97cc8d34), using - * psa_cipher_encrypt() function which will replace the setup-update-finish sequence below. - */ key_ref = aContext->mContext; - ensureKeyIsLoaded(*key_ref); - status = psa_cipher_encrypt_setup(&operation, *key_ref, PSA_ALG_ECB_NO_PADDING); - - if (status != PSA_SUCCESS) { - goto out; - } - - status = psa_cipher_update(&operation, - aInput, - block_size, - aOutput, - block_size, - &cipher_length); + status = psa_cipher_encrypt(*key_ref, + PSA_ALG_ECB_NO_PADDING, + aInput, + block_size, + aOutput, + block_size, + &cipher_length); - if (status != PSA_SUCCESS) { - goto out; - } - - status = psa_cipher_finish(&operation, - aOutput + cipher_length, - block_size - cipher_length, - &cipher_length); - -out: - psa_cipher_abort(&operation); return psaToOtError(status); } From 5d7a30bb2fa0bc6130e0e054821a0daa7043a736 Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Fri, 12 Jan 2024 09:58:52 +0100 Subject: [PATCH 1087/1623] [nrf fromtree] net: openthread: Print the actual assert location When OpenThread application is built with CONFIG_ASSERT and CONFIG_ASSERT_NO_MSG_INFO, OT_ASSERT() prints a location that points to the otPlatAssertFail() function instead of the code that actually failed an assertion. This is confusing and CONFIG_ASSERT_NO_MSG_INFO sometimes cannot be disabled because of flash size limitations. Make otPlatAssertFail() always print the actual assert location. Signed-off-by: Damian Krolik (cherry picked from commit 7b42e36c68f3ecc476bb35b3066d5c5d8a639953) --- modules/openthread/platform/misc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/openthread/platform/misc.c b/modules/openthread/platform/misc.c index 11fdc42ec34..5f9043dfa27 100644 --- a/modules/openthread/platform/misc.c +++ b/modules/openthread/platform/misc.c @@ -99,5 +99,10 @@ void otPlatWakeHost(void) void otPlatAssertFail(const char *aFilename, int aLineNumber) { - __ASSERT(false, "OpenThread ASSERT @ %s:%d", aFilename, aLineNumber); + /* + * The code below is used instead of __ASSERT(false) to print the actual assert + * location instead of __FILE__:__LINE__, which would point to this function. + */ + __ASSERT_PRINT("OpenThread ASSERT @ %s:%d\n", aFilename, aLineNumber); + __ASSERT_POST_ACTION(); } From 908763768e6de644d8d08a34dc3834c32563ab15 Mon Sep 17 00:00:00 2001 From: Andy Sinclair Date: Wed, 22 Nov 2023 16:34:02 +0000 Subject: [PATCH 1088/1623] [nrf fromtree] drivers: regulator: Fixed reference counting during enable Reference counting was broken when adding the enable delay. Now reverted to previous pattern. Signed-off-by: Andy Sinclair (cherry picked from commit c3a54ae1c34e939db83431bea354c0f4d0add0b3) --- drivers/regulator/regulator_common.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/regulator_common.c b/drivers/regulator/regulator_common.c index 7f33040d2d9..14866a3738f 100644 --- a/drivers/regulator/regulator_common.c +++ b/drivers/regulator/regulator_common.c @@ -107,10 +107,13 @@ int regulator_enable(const struct device *dev) (void)k_mutex_lock(&data->lock, K_FOREVER); #endif - if (data->refcnt == 0) { + data->refcnt++; + + if (data->refcnt == 1) { ret = api->enable(dev); - if (ret == 0) { - data->refcnt++; + if (ret < 0) { + data->refcnt--; + } else { regulator_delay(config->off_on_delay_us); } } From 8ba9711786a4cd6eea313b900130633f8b36145b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Ciupis?= Date: Thu, 18 Jan 2024 11:34:34 +0100 Subject: [PATCH 1089/1623] [nrf fromlist] drivers: ieee802154: fix nRF5 Rx error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current implementation implicitly assumes that if the device is configured to have the capability of acting as a CSL endpoint then in case a delayed reception with matching ID finishes with a timeout no action is needed. This assumption is correct when RxOnWhenIdle mode is disabled because the transition to sleep is done automatically by the driver below. However, it's wrong when RxOnWhenIdle is enabled. This commit fixes that case by adding a call to event handler that notifies the higher layer about the event and allows it to transition to RxOff if needed. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/67774 Signed-off-by: Jędrzej Ciupis --- drivers/ieee802154/ieee802154_nrf5.c | 10 +++++++++- drivers/ieee802154/ieee802154_nrf5.h | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index 6cbeb6ee2af..b542c5007f8 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -763,6 +763,7 @@ static int nrf5_init(const struct device *dev) nrf5_get_capabilities_at_boot(); + nrf5_radio->rx_on_when_idle = true; nrf5_radio_cfg->irq_config_func(dev); k_thread_create(&nrf5_radio->rx_thread, nrf5_radio->rx_stack, @@ -1003,6 +1004,7 @@ static int nrf5_configure(const struct device *dev, case IEEE802154_CONFIG_RX_ON_WHEN_IDLE: nrf_802154_rx_on_when_idle_set(config->rx_on_when_idle); + nrf5_data.rx_on_when_idle = config->rx_on_when_idle; break; default: @@ -1083,7 +1085,13 @@ void nrf_802154_receive_failed(nrf_802154_rx_error_t error, uint32_t id) #if defined(CONFIG_IEEE802154_CSL_ENDPOINT) if (id == DRX_SLOT_RX && error == NRF_802154_RX_ERROR_DELAYED_TIMEOUT) { - return; + if (!nrf5_data.rx_on_when_idle) { + /* Transition to RxOff done automatically by the driver */ + return; + } else if (nrf5_data.event_handler) { + /* Notify the higher layer to allow it to transition if needed */ + nrf5_data.event_handler(dev, IEEE802154_EVENT_RX_OFF, NULL); + } } #else ARG_UNUSED(id); diff --git a/drivers/ieee802154/ieee802154_nrf5.h b/drivers/ieee802154/ieee802154_nrf5.h index b9f46dff307..0d4d9c9accf 100644 --- a/drivers/ieee802154/ieee802154_nrf5.h +++ b/drivers/ieee802154/ieee802154_nrf5.h @@ -110,6 +110,9 @@ struct nrf5_802154_data { /* The last configured value of CSL phase time in nanoseconds. */ net_time_t csl_rx_time; #endif /* CONFIG_NRF_802154_SER_HOST && CONFIG_IEEE802154_CSL_ENDPOINT */ + + /* Indicates if RxOnWhenIdle mode is enabled. */ + bool rx_on_when_idle; }; #endif /* ZEPHYR_DRIVERS_IEEE802154_IEEE802154_NRF5_H_ */ From 51d4b69e9a0e82ba04b226c338aea438315d9913 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Sat, 25 Nov 2023 16:07:24 +0200 Subject: [PATCH 1090/1623] [nrf fromtree] drivers: sensor: adxl367: Add missing breaks Fix missing breaks errors. Signed-off-by: Andrei Emeltchenko (cherry picked from commit db1c21bfd75f9915d2d829f3c38f70ff65ae07f8) --- drivers/sensor/adxl367/adxl367.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/sensor/adxl367/adxl367.c b/drivers/sensor/adxl367/adxl367.c index f63b8f73a32..1d5c31ad021 100644 --- a/drivers/sensor/adxl367/adxl367.c +++ b/drivers/sensor/adxl367/adxl367.c @@ -287,16 +287,22 @@ int adxl367_self_test(const struct device *dev) switch (cfg->odr) { case ADXL367_ODR_12P5HZ: st_delay_ms = 320; + break; case ADXL367_ODR_25HZ: st_delay_ms = 160; + break; case ADXL367_ODR_50HZ: st_delay_ms = 80; + break; case ADXL367_ODR_100HZ: st_delay_ms = 40; + break; case ADXL367_ODR_200HZ: st_delay_ms = 20; + break; case ADXL367_ODR_400HZ: st_delay_ms = 10; + break; default: return -EINVAL; } From bc1d19177ed3633941254563852a9c3d2cf82ff3 Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Mon, 4 Dec 2023 16:47:01 +0100 Subject: [PATCH 1091/1623] [nrf fromtree] soc: arm: nordic_nrf: nrf91: add nRF9151 LACA This patch adds definitions for the nRF9151, which is software-compatible with nRF9161. Signed-off-by: Maximilian Deubel (cherry picked from commit efa030b32c874ea6840d509b1a80002497239bc7) --- dts/arm/nordic/nrf9151_laca.dtsi | 23 +++++++++++++++++++ dts/arm/nordic/nrf9151ns_laca.dtsi | 23 +++++++++++++++++++ .../nrf91/Kconfig.defconfig.nrf9151_LACA | 14 +++++++++++ soc/arm/nordic_nrf/nrf91/Kconfig.soc | 4 ++++ 4 files changed, 64 insertions(+) create mode 100644 dts/arm/nordic/nrf9151_laca.dtsi create mode 100644 dts/arm/nordic/nrf9151ns_laca.dtsi create mode 100644 soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.nrf9151_LACA diff --git a/dts/arm/nordic/nrf9151_laca.dtsi b/dts/arm/nordic/nrf9151_laca.dtsi new file mode 100644 index 00000000000..9ed20274017 --- /dev/null +++ b/dts/arm/nordic/nrf9151_laca.dtsi @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +&flash0 { + reg = <0x00000000 DT_SIZE_K(1024)>; +}; + +&sram0 { + reg = <0x20000000 DT_SIZE_K(256)>; +}; + +/ { + soc { + compatible = "nordic,nrf9151-laca", "nordic,nrf9120", + "nordic,nrf91", "simple-bus"; + }; +}; diff --git a/dts/arm/nordic/nrf9151ns_laca.dtsi b/dts/arm/nordic/nrf9151ns_laca.dtsi new file mode 100644 index 00000000000..ac31c6e19c6 --- /dev/null +++ b/dts/arm/nordic/nrf9151ns_laca.dtsi @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +&flash0 { + reg = <0x00000000 DT_SIZE_K(1024)>; +}; + +&sram0 { + reg = <0x20000000 DT_SIZE_K(256)>; +}; + +/ { + soc { + compatible = "nordic,nrf9151-laca", "nordic,nrf9120", + "nordic,nrf91", "simple-bus"; + }; +}; diff --git a/soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.nrf9151_LACA b/soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.nrf9151_LACA new file mode 100644 index 00000000000..1b3ea88e359 --- /dev/null +++ b/soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.nrf9151_LACA @@ -0,0 +1,14 @@ +# Nordic Semiconductor nRF9151 MCU + +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_NRF9151_LACA + +config SOC + default "nRF9151_LACA" + +config NUM_IRQS + default 65 + +endif # SOC_NRF9151_LACA diff --git a/soc/arm/nordic_nrf/nrf91/Kconfig.soc b/soc/arm/nordic_nrf/nrf91/Kconfig.soc index c9b8c54438b..0267ada4850 100644 --- a/soc/arm/nordic_nrf/nrf91/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf91/Kconfig.soc @@ -34,6 +34,10 @@ config SOC_NRF9131_LACA bool "NRF9131_LACA" select SOC_NRF9120 +config SOC_NRF9151_LACA + bool "NRF9151_LACA" + select SOC_NRF9120 + endchoice config NRF_ENABLE_ICACHE From 79858b97c0996a8c67fdc70ffcc745b19111f9de Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Mon, 4 Dec 2023 16:57:34 +0100 Subject: [PATCH 1092/1623] [nrf fromtree] boards: arm: add nrf9151dk_nrf9151 This patch adds the nRF9151-DK board. Signed-off-by: Maximilian Deubel (cherry picked from commit ecf6287b8ce9508f04a7591367869719b99d23ca) --- boards/arm/nrf9151dk_nrf9151/Kconfig.board | 14 + .../arm/nrf9151dk_nrf9151/Kconfig.defconfig | 47 +++ boards/arm/nrf9151dk_nrf9151/board.cmake | 14 + boards/arm/nrf9151dk_nrf9151/doc/index.rst | 203 +++++++++++++ .../nordic,nrf9151dk-nrf5340-reset.yaml | 18 ++ .../dts/nrf9151dk_buttons_on_io_expander.dtsi | 25 ++ .../dts/nrf9151dk_leds_on_io_expander.dtsi | 25 ++ .../nrf9151dk_nrf9151/nrf9151dk_nrf9151.dts | 19 ++ .../nrf9151dk_nrf9151/nrf9151dk_nrf9151.yaml | 22 ++ .../nrf9151dk_nrf9151_common-pinctrl.dtsi | 96 +++++++ .../nrf9151dk_nrf9151_common.dtsi | 268 ++++++++++++++++++ .../nrf9151dk_nrf9151_defconfig | 24 ++ .../nrf9151dk_nrf9151_ns.dts | 22 ++ .../nrf9151dk_nrf9151_ns.yaml | 20 ++ .../nrf9151dk_nrf9151_ns_defconfig | 27 ++ .../nrf9151dk_nrf9151_partition_conf.dtsi | 60 ++++ .../arm/nrf9151dk_nrf9151/pre_dt_board.cmake | 7 + 17 files changed, 911 insertions(+) create mode 100644 boards/arm/nrf9151dk_nrf9151/Kconfig.board create mode 100644 boards/arm/nrf9151dk_nrf9151/Kconfig.defconfig create mode 100644 boards/arm/nrf9151dk_nrf9151/board.cmake create mode 100644 boards/arm/nrf9151dk_nrf9151/doc/index.rst create mode 100644 boards/arm/nrf9151dk_nrf9151/dts/bindings/nordic,nrf9151dk-nrf5340-reset.yaml create mode 100644 boards/arm/nrf9151dk_nrf9151/dts/nrf9151dk_buttons_on_io_expander.dtsi create mode 100644 boards/arm/nrf9151dk_nrf9151/dts/nrf9151dk_leds_on_io_expander.dtsi create mode 100644 boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151.dts create mode 100644 boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151.yaml create mode 100644 boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_common-pinctrl.dtsi create mode 100644 boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_common.dtsi create mode 100644 boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_defconfig create mode 100644 boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns.dts create mode 100644 boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns.yaml create mode 100644 boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns_defconfig create mode 100644 boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_partition_conf.dtsi create mode 100644 boards/arm/nrf9151dk_nrf9151/pre_dt_board.cmake diff --git a/boards/arm/nrf9151dk_nrf9151/Kconfig.board b/boards/arm/nrf9151dk_nrf9151/Kconfig.board new file mode 100644 index 00000000000..92352ddc16f --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/Kconfig.board @@ -0,0 +1,14 @@ +# nRF9151 DK NRF9151 board configuration + +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_NRF9151_LACA + +config BOARD_NRF9151DK_NRF9151 + bool "nRF9151 DK NRF9151" + +config BOARD_NRF9151DK_NRF9151_NS + bool "nRF9151 DK NRF9151 non-secure" + +endif # SOC_NRF9151_LACA diff --git a/boards/arm/nrf9151dk_nrf9151/Kconfig.defconfig b/boards/arm/nrf9151dk_nrf9151/Kconfig.defconfig new file mode 100644 index 00000000000..3cbff101d63 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/Kconfig.defconfig @@ -0,0 +1,47 @@ +# nRF9151 DK NRF9151 board configuration + +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_NRF9151DK_NRF9151 || BOARD_NRF9151DK_NRF9151_NS + +config BOARD + default "nrf9151dk_nrf9151" + +# For the secure version of the board the firmware is linked at the beginning +# of the flash, or into the code-partition defined in DT if it is intended to +# be loaded by MCUboot. If the secure firmware is to be combined with a non- +# secure image (TRUSTED_EXECUTION_SECURE=y), the secure FW image shall always +# be restricted to the size of its code partition. +# For the non-secure version of the board, the firmware +# must be linked into the code-partition (non-secure) defined in DT, regardless. +# Apply this configuration below by setting the Kconfig symbols used by +# the linker according to the information extracted from DT partitions. + +# Workaround for not being able to have commas in macro arguments +DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition + +config FLASH_LOAD_SIZE + default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) + depends on BOARD_NRF9151DK_NRF9151 && TRUSTED_EXECUTION_SECURE + +if BOARD_NRF9151DK_NRF9151_NS + +config FLASH_LOAD_OFFSET + default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) + +config FLASH_LOAD_SIZE + default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) + +endif # BOARD_NRF9151DK_NRF9151_NS + +config BT_HCI_VS + default y if BT + +config BT_WAIT_NOP + default BT && $(dt_nodelabel_enabled,nrf5340_reset) + +config I2C + default $(dt_compat_on_bus,$(DT_COMPAT_NXP_PCAL6408A),i2c) + +endif # BOARD_NRF9151DK_NRF9151 || BOARD_NRF9151DK_NRF9151_NS diff --git a/boards/arm/nrf9151dk_nrf9151/board.cmake b/boards/arm/nrf9151dk_nrf9151/board.cmake new file mode 100644 index 00000000000..a3126c941d9 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/board.cmake @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: Apache-2.0 + +if(CONFIG_BOARD_NRF9151DK_NRF9151_NS) + set(TFM_PUBLIC_KEY_FORMAT "full") +endif() + +if(CONFIG_TFM_FLASH_MERGED_BINARY) + set_property(TARGET runners_yaml_props_target PROPERTY hex_file tfm_merged.hex) +endif() + +# TODO: change to nRF9151_xxAA when such device is available in JLink +board_runner_args(jlink "--device=nRF9160_xxAA" "--speed=4000") +include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) +include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) diff --git a/boards/arm/nrf9151dk_nrf9151/doc/index.rst b/boards/arm/nrf9151dk_nrf9151/doc/index.rst new file mode 100644 index 00000000000..4c02e7ed372 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/doc/index.rst @@ -0,0 +1,203 @@ +.. _nrf9151dk_nrf9151: + +nRF9151 DK +########## + +Overview +******** + +The nRF9151 DK (PCA10171) is a single-board development kit for evaluation and +development on the nRF9151 SiP for DECT NR+ and LTE-M/NB-IoT with GNSS. The nrf9151dk_nrf9151 +board configuration provides support for the Nordic Semiconductor nRF9151 ARM +Cortex-M33F CPU with ARMv8-M Security Extension and the following devices: + +* :abbr:`ADC (Analog to Digital Converter)` +* CLOCK +* FLASH +* :abbr:`GPIO (General Purpose Input Output)` +* :abbr:`I2C (Inter-Integrated Circuit)` +* :abbr:`MPU (Memory Protection Unit)` +* :abbr:`NVIC (Nested Vectored Interrupt Controller)` +* :abbr:`PWM (Pulse Width Modulation)` +* :abbr:`RTC (nRF RTC System Clock)` +* Segger RTT (RTT Console) +* :abbr:`SPI (Serial Peripheral Interface)` +* :abbr:`UARTE (Universal asynchronous receiver-transmitter with EasyDMA)` +* :abbr:`WDT (Watchdog Timer)` +* :abbr:`IDAU (Implementation Defined Attribution Unit)` + +More information about the board can be found at the +`nRF9151 DK website`_. The `Nordic Semiconductor Infocenter`_ +contains the processor's information and the datasheet. + + +Hardware +******** + +nRF9151 DK has two external oscillators. The frequency of +the slow clock is 32.768 kHz. The frequency of the main clock +is 32 MHz. + +Supported Features +================== + +The nrf9151dk_nrf9151 board configuration supports the following +hardware features: + ++-----------+------------+----------------------+ +| Interface | Controller | Driver/Component | ++===========+============+======================+ +| ADC | on-chip | adc | ++-----------+------------+----------------------+ +| CLOCK | on-chip | clock_control | ++-----------+------------+----------------------+ +| FLASH | on-chip | flash | ++-----------+------------+----------------------+ +| FLASH | external | spi | ++-----------+------------+----------------------+ +| GPIO | on-chip | gpio | ++-----------+------------+----------------------+ +| GPIO | external | i2c | ++-----------+------------+----------------------+ +| I2C(M) | on-chip | i2c | ++-----------+------------+----------------------+ +| MPU | on-chip | arch/arm | ++-----------+------------+----------------------+ +| NVIC | on-chip | arch/arm | ++-----------+------------+----------------------+ +| PWM | on-chip | pwm | ++-----------+------------+----------------------+ +| RTC | on-chip | system clock | ++-----------+------------+----------------------+ +| RTT | nRF53 | console | ++-----------+------------+----------------------+ +| SPI(M/S) | on-chip | spi | ++-----------+------------+----------------------+ +| SPU | on-chip | system protection | ++-----------+------------+----------------------+ +| UARTE | on-chip | serial | ++-----------+------------+----------------------+ +| WDT | on-chip | watchdog | ++-----------+------------+----------------------+ + + +.. _nrf9151dk_additional_hardware: + +Other hardware features have not been enabled yet for this board. +See `nRF9151 DK website`_ and `Nordic Semiconductor Infocenter`_ +for a complete list of nRF9151 DK board hardware features. + +Connections and IOs +=================== + +LED +--- + +* LED1 (green) = P0.0 +* LED2 (green) = P0.1 +* LED3 (green) = P0.4 +* LED4 (green) = P0.5 + +Push buttons and Switches +------------------------- + +* BUTTON1 = P0.8 +* BUTTON2 = P0.9 +* SWITCH1 = P0.18 +* SWITCH2 = P0.19 +* BOOT = SW5 = boot/reset + +Security components +=================== + +- Implementation Defined Attribution Unit (`IDAU`_). The IDAU is implemented + with the System Protection Unit and is used to define secure and non-secure + memory maps. By default, all of the memory space (Flash, SRAM, and + peripheral address space) is defined to be secure accessible only. +- Secure boot. + + +Programming and Debugging +************************* + +nrf9151dk_nrf9151 supports the Armv8m Security Extension, and by default boots +in the Secure state. + +Building Secure/Non-Secure Zephyr applications with Arm |reg| TrustZone |reg| +============================================================================= + +The process requires the following steps: + +1. Build the Secure Zephyr application using ``-DBOARD=nrf9151dk_nrf9151`` and + ``CONFIG_TRUSTED_EXECUTION_SECURE=y`` in the application project configuration file. +2. Build the Non-Secure Zephyr application using ``-DBOARD=nrf9151dk_nrf9151_ns``. +3. Merge the two binaries together. + +When building a Secure/Non-Secure application, the Secure application will +have to set the IDAU (SPU) configuration to allow Non-Secure access to all +CPU resources utilized by the Non-Secure application firmware. SPU +configuration shall take place before jumping to the Non-Secure application. + +Building a Secure only application +================================== + +Build the Zephyr app in the usual way (see :ref:`build_an_application` +and :ref:`application_run`), using ``-DBOARD=nrf9151dk_nrf9151``. + +Flashing +======== + +Follow the instructions in the :ref:`nordic_segger` page to install +and configure all the necessary software. Further information can be +found in :ref:`nordic_segger_flashing`. Then build and flash +applications as usual (see :ref:`build_an_application` and +:ref:`application_run` for more details). + +Here is an example for the :ref:`hello_world` application. + +First, run your favorite terminal program to listen for output. + +.. code-block:: console + + $ minicom -D -b 115200 + +Replace :code:`` with the port where the nRF9151 DK +can be found. For example, under Linux, :code:`/dev/ttyACM0`. + +Then build and flash the application in the usual way. + +.. zephyr-app-commands:: + :zephyr-app: samples/hello_world + :board: nrf9151dk_nrf9151 + :goals: build flash + +Debugging +========= + +Refer to the :ref:`nordic_segger` page to learn about debugging Nordic boards with a +Segger IC. + + +Testing the LEDs and buttons in the nRF9151 DK +********************************************** + +There are 2 samples that allow you to test that the buttons (switches) and LEDs on +the board are working properly with Zephyr: + +* :zephyr:code-sample:`blinky` +* :zephyr:code-sample:`button` + +You can build and flash the examples to make sure Zephyr is running correctly on +your board. The button and LED definitions can be found in +:zephyr_file:`boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_common.dtsi`. + +References +********** + +.. target-notes:: + +.. _IDAU: + https://developer.arm.com/docs/100690/latest/attribution-units-sau-and-idau +.. _nRF9151 DK website: https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF9151-DK +.. _Nordic Semiconductor Infocenter: https://infocenter.nordicsemi.com +.. _Trusted Firmware M: https://www.trustedfirmware.org/projects/tf-m/ diff --git a/boards/arm/nrf9151dk_nrf9151/dts/bindings/nordic,nrf9151dk-nrf5340-reset.yaml b/boards/arm/nrf9151dk_nrf9151/dts/bindings/nordic,nrf9151dk-nrf5340-reset.yaml new file mode 100644 index 00000000000..2b51125312c --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/dts/bindings/nordic,nrf9151dk-nrf5340-reset.yaml @@ -0,0 +1,18 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: GPIO used to reset nRF5340 on nRF9151 DK + +compatible: "nordic,nrf9151dk-nrf5340-reset" + +include: base.yaml + +properties: + status: + required: true + + gpios: + type: phandle-array + required: true + description: | + GPIO to use as nRF5340 reset line: output in nRF9151, input in nRF5340. diff --git a/boards/arm/nrf9151dk_nrf9151/dts/nrf9151dk_buttons_on_io_expander.dtsi b/boards/arm/nrf9151dk_nrf9151/dts/nrf9151dk_buttons_on_io_expander.dtsi new file mode 100644 index 00000000000..20f7d2406a5 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/dts/nrf9151dk_buttons_on_io_expander.dtsi @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&pcal6408a { + status = "okay"; +}; + +&button0 { + gpios = <&pcal6408a 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; +}; + +&button1 { + gpios = <&pcal6408a 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; +}; + +&button2 { + gpios = <&pcal6408a 2 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; +}; + +&button3 { + gpios = <&pcal6408a 3 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; +}; diff --git a/boards/arm/nrf9151dk_nrf9151/dts/nrf9151dk_leds_on_io_expander.dtsi b/boards/arm/nrf9151dk_nrf9151/dts/nrf9151dk_leds_on_io_expander.dtsi new file mode 100644 index 00000000000..d80c509d215 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/dts/nrf9151dk_leds_on_io_expander.dtsi @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&pcal6408a { + status = "okay"; +}; + +&led0 { + gpios = <&pcal6408a 4 GPIO_ACTIVE_HIGH>; +}; + +&led1 { + gpios = <&pcal6408a 5 GPIO_ACTIVE_HIGH>; +}; + +&led2 { + gpios = <&pcal6408a 6 GPIO_ACTIVE_HIGH>; +}; + +&led3 { + gpios = <&pcal6408a 7 GPIO_ACTIVE_HIGH>; +}; diff --git a/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151.dts b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151.dts new file mode 100644 index 00000000000..8c3b4921434 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151.dts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include "nrf9151dk_nrf9151_common.dtsi" + +/ { + chosen { + zephyr,sram = &sram0_s; + zephyr,flash = &flash0; + zephyr,code-partition = &slot0_partition; + zephyr,sram-secure-partition = &sram0_s; + zephyr,sram-non-secure-partition = &sram0_ns; + }; +}; diff --git a/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151.yaml b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151.yaml new file mode 100644 index 00000000000..3ad90fea76d --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151.yaml @@ -0,0 +1,22 @@ +identifier: nrf9151dk_nrf9151 +name: nRF9151-DK-NRF9151 +type: mcu +arch: arm +toolchain: + - gnuarmemb + - xtools + - zephyr +ram: 88 +flash: 1024 +supported: + - arduino_gpio + - arduino_i2c + - arduino_serial + - arduino_spi + - gpio + - i2c + - pwm + - spi + - watchdog + - counter +vendor: nordic diff --git a/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_common-pinctrl.dtsi b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_common-pinctrl.dtsi new file mode 100644 index 00000000000..a1680e830f4 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_common-pinctrl.dtsi @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor + * SPDX-License-Identifier: Apache-2.0 + */ + +&pinctrl { + uart0_default: uart0_default { + group1 { + psels = , + ; + }; + group2 { + psels = , + ; + bias-pull-up; + }; + }; + + uart0_sleep: uart0_sleep { + group1 { + psels = , + , + , + ; + low-power-enable; + }; + }; + + uart1_default: uart1_default { + group1 { + psels = , + ; + }; + group2 { + psels = , + ; + bias-pull-up; + }; + }; + + uart1_sleep: uart1_sleep { + group1 { + psels = , + , + , + ; + low-power-enable; + }; + }; + + i2c2_default: i2c2_default { + group1 { + psels = , + ; + }; + }; + + i2c2_sleep: i2c2_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; + + pwm0_default: pwm0_default { + group1 { + psels = ; + }; + }; + + pwm0_sleep: pwm0_sleep { + group1 { + psels = ; + low-power-enable; + }; + }; + + spi3_default: spi3_default { + group1 { + psels = , + , + ; + nordic,drive-mode = ; + }; + }; + + spi3_sleep: spi3_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; +}; diff --git a/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_common.dtsi b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_common.dtsi new file mode 100644 index 00000000000..958e864c63c --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_common.dtsi @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "nrf9151dk_nrf9151_common-pinctrl.dtsi" +#include + +/ { + model = "Nordic nRF9151 DK NRF9151"; + compatible = "nordic,nrf9151-dk-nrf9151"; + + chosen { + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + zephyr,uart-mcumgr = &uart0; + }; + + leds { + compatible = "gpio-leds"; + led0: led_0 { + gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>; + label = "Green LED 1"; + }; + led1: led_1 { + gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>; + label = "Green LED 2"; + }; + led2: led_2 { + gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>; + label = "Green LED 3"; + }; + led3: led_3 { + gpios = <&gpio0 5 GPIO_ACTIVE_HIGH>; + label = "Green LED 4"; + }; + }; + + pwmleds { + compatible = "pwm-leds"; + pwm_led0: pwm_led_0 { + pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_NORMAL>; + }; + }; + + buttons { + compatible = "gpio-keys"; + button0: button_0 { + gpios = <&gpio0 8 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 1"; + zephyr,code = ; + }; + button1: button_1 { + gpios = <&gpio0 9 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 2"; + zephyr,code = ; + }; + button2: button_2 { + gpios = <&gpio0 18 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 3"; + zephyr,code = ; + }; + button3: button_3 { + gpios = <&gpio0 19 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 4"; + zephyr,code = ; + }; + }; + + nrf5340_reset: gpio-reset { + compatible = "nordic,nrf9151dk-nrf5340-reset"; + status = "disabled"; + gpios = <&gpio0 21 GPIO_ACTIVE_LOW>; + }; + + arduino_header: connector { + compatible = "arduino-header-r3"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &gpio0 14 0>, /* A0 */ + <1 0 &gpio0 15 0>, /* A1 */ + <2 0 &gpio0 16 0>, /* A2 */ + <3 0 &gpio0 17 0>, /* A3 */ + <4 0 &gpio0 18 0>, /* A4 */ + <5 0 &gpio0 19 0>, /* A5 */ + <6 0 &gpio0 0 0>, /* D0 */ + <7 0 &gpio0 1 0>, /* D1 */ + <8 0 &gpio0 2 0>, /* D2 */ + <9 0 &gpio0 3 0>, /* D3 */ + <10 0 &gpio0 4 0>, /* D4 */ + <11 0 &gpio0 5 0>, /* D5 */ + <12 0 &gpio0 6 0>, /* D6 */ + <13 0 &gpio0 7 0>, /* D7 */ + <14 0 &gpio0 8 0>, /* D8 */ + <15 0 &gpio0 9 0>, /* D9 */ + <16 0 &gpio0 10 0>, /* D10 */ + <17 0 &gpio0 11 0>, /* D11 */ + <18 0 &gpio0 12 0>, /* D12 */ + <19 0 &gpio0 13 0>, /* D13 */ + <20 0 &gpio0 30 0>, /* D14 */ + <21 0 &gpio0 31 0>; /* D15 */ + }; + + arduino_adc: analog-connector { + compatible = "arduino,uno-adc"; + #io-channel-cells = <1>; + io-channel-map = <0 &adc 1>, /* A0 = P0.14 = AIN1 */ + <1 &adc 2>, /* A1 = P0.15 = AIN2 */ + <2 &adc 3>, /* A2 = P0.16 = AIN3 */ + <3 &adc 4>, /* A3 = P0.17 = AIN4 */ + <4 &adc 5>, /* A4 = P0.18 = AIN5 */ + <5 &adc 6>; /* A5 = P0.19 = AIN6 */ + }; + + /* These aliases are provided for compatibility with samples */ + aliases { + led0 = &led0; + led1 = &led1; + led2 = &led2; + led3 = &led3; + pwm-led0 = &pwm_led0; + sw0 = &button0; + sw1 = &button1; + sw2 = &button2; + sw3 = &button3; + bootloader-led0 = &led0; + mcuboot-button0 = &button0; + mcuboot-led0 = &led0; + watchdog0 = &wdt0; + spi-flash0 = &gd25wb256; + }; +}; + +&adc { + status = "okay"; +}; + +&gpiote { + status = "okay"; +}; + +&gpio0 { + status = "okay"; +}; + +&uart0 { + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&uart0_default>; + pinctrl-1 = <&uart0_sleep>; + pinctrl-names = "default", "sleep"; +}; + +arduino_serial: &uart1 { + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&uart1_default>; + pinctrl-1 = <&uart1_sleep>; + pinctrl-names = "default", "sleep"; +}; + +arduino_i2c: &i2c2 { + compatible = "nordic,nrf-twim"; + status = "okay"; + pinctrl-0 = <&i2c2_default>; + pinctrl-1 = <&i2c2_sleep>; + pinctrl-names = "default", "sleep"; + clock-frequency = ; + + pcal6408a: pcal6408a@21 { + compatible = "nxp,pcal6408a"; + status = "disabled"; + reg = <0x21>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <8>; + int-gpios = <&gpio0 19 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + }; +}; + +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_default>; + pinctrl-1 = <&pwm0_sleep>; + pinctrl-names = "default", "sleep"; +}; + +arduino_spi: &spi3 { + compatible = "nordic,nrf-spim"; + status = "okay"; + cs-gpios = <&arduino_header 16 GPIO_ACTIVE_LOW>, /* D10 */ + <&gpio0 20 GPIO_ACTIVE_LOW>; + pinctrl-0 = <&spi3_default>; + pinctrl-1 = <&spi3_sleep>; + pinctrl-names = "default", "sleep"; + + gd25wb256: gd25wb256e3ir@1 { + compatible = "jedec,spi-nor"; + status = "disabled"; + reg = <1>; + spi-max-frequency = <8000000>; + size = <268435456>; + has-dpd; + t-enter-dpd = <3000>; + t-exit-dpd = <40000>; + sfdp-bfp = [ + e5 20 f3 ff ff ff ff 0f 44 eb 08 6b 08 3b 42 bb + ee ff ff ff ff ff 00 ff ff ff 00 ff 0c 20 0f 52 + 10 d8 00 ff 44 7a c9 fe 83 67 26 62 ec 82 18 44 + 7a 75 7a 75 04 c4 d5 5c 00 06 74 00 08 50 00 01 + ]; + jedec-id = [c8 65 19]; + }; +}; + +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x10000>; + }; + slot0_partition: partition@10000 { + label = "image-0"; + }; + slot0_ns_partition: partition@50000 { + label = "image-0-nonsecure"; + }; + slot1_partition: partition@85000 { + label = "image-1"; + }; + slot1_ns_partition: partition@c5000 { + label = "image-1-nonsecure"; + }; + storage_partition: partition@fa000 { + label = "storage"; + reg = <0x000fa000 0x00006000>; + }; + }; +}; + +/ { + + reserved-memory { + #address-cells = <1>; + #size-cells = <1>; + ranges; + + sram0_s: image_s@20000000 { + /* Secure image memory */ + }; + + sram0_modem: image_modem@20016000 { + /* Modem (shared) memory */ + }; + + sram0_ns: image_ns@20020000 { + /* Non-Secure image memory */ + }; + }; +}; + +/* Include partition configuration file */ +#include "nrf9151dk_nrf9151_partition_conf.dtsi" diff --git a/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_defconfig b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_defconfig new file mode 100644 index 00000000000..7afe5ac7aa9 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_defconfig @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_NRF91X=y +CONFIG_SOC_NRF9151_LACA=y +CONFIG_BOARD_NRF9151DK_NRF9151=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# Enable hardware stack protection +CONFIG_HW_STACK_PROTECTION=y + +# Enable TrustZone-M +CONFIG_ARM_TRUSTZONE_M=y + +# enable GPIO +CONFIG_GPIO=y + +# Enable uart driver +CONFIG_SERIAL=y + +# enable console +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y diff --git a/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns.dts b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns.dts new file mode 100644 index 00000000000..a41c4aad388 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns.dts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include "nrf9151dk_nrf9151_common.dtsi" + +/ { + chosen { + zephyr,flash = &flash0; + zephyr,sram = &sram0_ns; + zephyr,code-partition = &slot0_ns_partition; + }; +}; + +/* Disable UART1, because it is used by default in TF-M */ +&uart1 { + status = "disabled"; +}; diff --git a/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns.yaml b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns.yaml new file mode 100644 index 00000000000..c5d4fe92541 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns.yaml @@ -0,0 +1,20 @@ +identifier: nrf9151dk_nrf9151_ns +name: nRF9151-DK-NRF9151-Non-Secure +type: mcu +arch: arm +toolchain: + - gnuarmemb + - xtools + - zephyr +ram: 128 +flash: 192 +supported: + - arduino_gpio + - arduino_i2c + - arduino_serial + - arduino_spi + - i2c + - pwm + - watchdog + - netif:modem +vendor: nordic diff --git a/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns_defconfig b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns_defconfig new file mode 100644 index 00000000000..949ef39f856 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_ns_defconfig @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_NRF91X=y +CONFIG_SOC_NRF9151_LACA=y +CONFIG_BOARD_NRF9151DK_NRF9151_NS=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# Enable hardware stack protection +CONFIG_HW_STACK_PROTECTION=y + +# Enable TrustZone-M +CONFIG_ARM_TRUSTZONE_M=y + +# This Board implies building Non-Secure firmware +CONFIG_TRUSTED_EXECUTION_NONSECURE=y + +# enable GPIO +CONFIG_GPIO=y + +# Enable uart driver +CONFIG_SERIAL=y + +# enable console +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y diff --git a/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_partition_conf.dtsi b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_partition_conf.dtsi new file mode 100644 index 00000000000..b209608a725 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/nrf9151dk_nrf9151_partition_conf.dtsi @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * Default Flash planning for nRF9151dk_nrf9151. + * + * Zephyr build for nRF9151 with ARM TrustZone-M support, + * implies building Secure and Non-Secure Zephyr images. + * + * Secure image will be placed, by default, in flash0 + * (or in slot0, if MCUboot is present). + * Secure image will use sram0 for system memory. + * + * Non-Secure image will be placed in slot0_ns, and use + * sram0_ns for system memory. + * + * Note that the Secure image only requires knowledge of + * the beginning of the Non-Secure image (not its size). + */ + +&slot0_partition { + reg = <0x00010000 0x40000>; +}; + +&slot0_ns_partition { + reg = <0x00050000 0x35000>; +}; + +&slot1_partition { + reg = <0x00085000 0x40000>; +}; + +&slot1_ns_partition { + reg = <0x000c5000 0x35000>; +}; + +/* Default SRAM planning when building for nRF9151 with + * ARM TrustZone-M support + * - Lowest 88 kB SRAM allocated to Secure image (sram0_s). + * - 40 kB SRAM reserved for and used by the modem library + * (sram0_modem). This memory is Non-Secure. + * - Upper 128 kB allocated to Non-Secure image (sram0_ns). + * When building with TF-M, both sram0_modem and sram0_ns + * are allocated to the Non-Secure image. + */ + +&sram0_s { + reg = <0x20000000 DT_SIZE_K(88)>; +}; + +&sram0_modem { + reg = <0x20016000 DT_SIZE_K(40)>; +}; + +&sram0_ns { + reg = <0x20020000 DT_SIZE_K(128)>; +}; diff --git a/boards/arm/nrf9151dk_nrf9151/pre_dt_board.cmake b/boards/arm/nrf9151dk_nrf9151/pre_dt_board.cmake new file mode 100644 index 00000000000..c8267afd1b4 --- /dev/null +++ b/boards/arm/nrf9151dk_nrf9151/pre_dt_board.cmake @@ -0,0 +1,7 @@ +# Copyright (c) 2021 Linaro Limited +# SPDX-License-Identifier: Apache-2.0 + +# Suppress "unique_unit_address_if_enabled" to handle the following overlaps: +# - flash-controller@39000 & kmu@39000 +# - power@5000 & clock@5000 +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") From 0b0b17ec9b28d37fa303ae49564a68420b902414 Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Tue, 9 Jan 2024 12:13:38 +0530 Subject: [PATCH 1093/1623] [nrf fromtree] net: wifi_utils: Fix max channels allow for scan Fix the maximum channels allow for scan command input. Signed-off-by: Kapil Bhatt (cherry picked from commit 3e8dbaf75fd0c239e00e33eb5970843341dad0f0) --- subsys/net/l2/wifi/wifi_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index 76e93fc33e0..bd47205e4f9 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -368,7 +368,7 @@ int wifi_utils_parse_scan_chan(char *scan_chan_str, memset(chan_str, 0, sizeof(chan_str)); if (chan_start) { - if ((chan_idx + (chan_val - chan_start)) >= max_channels) { + if ((chan_idx + (chan_val - chan_start)) > max_channels) { NET_ERR("Too many channels specified (%d)", max_channels); return -EINVAL; } From 8505a727386cf57765845ca3110ef21bcdc6d91d Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Tue, 9 Jan 2024 12:34:26 +0530 Subject: [PATCH 1094/1623] [nrf fromtree] net: wifi_shell: Update scan argument shell Update the example of scan -c argument. Default value for max channels is set to 3, So, update the example according to that. Add closing bracket in -s. Signed-off-by: Kapil Bhatt (cherry picked from commit 773ebe9c41903ce458eb2609c3c5668ef3976466) --- subsys/net/l2/wifi/wifi_shell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index f470e700f8c..d3f573a28d6 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1903,9 +1903,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-b, --bands ] : Bands to be scanned where 2: 2.4 GHz, 5: 5 GHz, 6: 6 GHz\n" "[-a, --dwell_time_active ] : Active scan dwell time (in ms) on a channel. Range 5 ms to 1000 ms\n" "[-p, --dwell_time_passive ] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms\n" - "[-s, --ssid : SSID to scan for. Can be provided multiple times\n" + "[-s, --ssid] : SSID to scan for. Can be provided multiple times\n" "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535\n" - "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6-11,14_5:36,149-165,44\n" + "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6_5:36\n" "[-h, --help] : Print out the help for the scan command.\n", cmd_wifi_scan, 1, 8), From 11305e472b97ad23381700865c424926498301e5 Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Thu, 11 Jan 2024 15:29:23 +0530 Subject: [PATCH 1095/1623] [nrf fromtree] net: wifi_shell: Add example of scan option Add an example of the scan's -c parameter to help with understanding. Signed-off-by: Kapil Bhatt (cherry picked from commit d8c362253dab3304e54704be029a7518f8f19adc) --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index d3f573a28d6..1e1ab4a3724 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1905,7 +1905,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-p, --dwell_time_passive ] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms\n" "[-s, --ssid] : SSID to scan for. Can be provided multiple times\n" "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535\n" - "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6_5:36\n" + "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6_5:36 or 2:1,6-11,14_5:36,163-177,52\n" "[-h, --help] : Print out the help for the scan command.\n", cmd_wifi_scan, 1, 8), From 9c754a80d072e415d54fc6dd45235359b016433b Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Thu, 18 Jan 2024 15:41:09 +0530 Subject: [PATCH 1096/1623] [nrf fromtree] net: wifi_shell: Add help for maximum channels in scan Add a line for scan's -c parameter which specify to take care of maximum channels. Signed-off-by: Kapil Bhatt (cherry picked from commit c22ce801e7fd6badde988e52e65a4b5c10bcef88) --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 1e1ab4a3724..1f13ae864ae 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1905,7 +1905,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-p, --dwell_time_passive ] : Passive scan dwell time (in ms) on a channel. Range 10 ms to 1000 ms\n" "[-s, --ssid] : SSID to scan for. Can be provided multiple times\n" "[-m, --max_bss ] : Maximum BSSes to scan for. Range 1 - 65535\n" - "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6_5:36 or 2:1,6-11,14_5:36,163-177,52\n" + "[-c, --chans ] : Channels to be scanned. The channels must be specified in the form band1:chan1,chan2_band2:chan3,..etc. band1, band2 must be valid band values and chan1, chan2, chan3 must be specified as a list of comma separated values where each value is either a single channel or a channel range specified as chan_start-chan_end. Each band channel set has to be separated by a _. For example, a valid channel specification can be 2:1,6_5:36 or 2:1,6-11,14_5:36,163-177,52. Care should be taken to ensure that configured channels don't exceed CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL\n" "[-h, --help] : Print out the help for the scan command.\n", cmd_wifi_scan, 1, 8), From ba7cedd0bc880c07fef2c689a19561fd5b96631e Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 29 Nov 2023 13:36:27 +0100 Subject: [PATCH 1097/1623] [nrf fromtree] boards nrf5340bsim_cpuapp: Define chosen entropy source Override the chosen entropy source irrespectively of what the SOC may chose. This is to avoid problems as the SOC may select the cryptocell, but we do not support it in the simulated target. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 25599df05e4b060d83d6ccf03ded7b2b411bb7a4) --- boards/posix/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts | 1 + 1 file changed, 1 insertion(+) diff --git a/boards/posix/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts b/boards/posix/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts index 36cbf9691b3..a7c3d39ace5 100644 --- a/boards/posix/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts +++ b/boards/posix/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts @@ -45,6 +45,7 @@ }; chosen { + zephyr,entropy = &rng_hci; zephyr,flash = &flash0; zephyr,bt-hci-ipc = &ipc0; nordic,802154-spinel-ipc = &ipc0; From 09da644ab209a2a329b5ebd59c012822d0796e39 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 1 Dec 2023 17:02:47 +0100 Subject: [PATCH 1098/1623] [nrf fromtree] manifest: Update nrf hw models to latest * Update the HW models module to 9b985ea6bc237b6ae06f48eb228f2ac7f6e3b96b Including the following: * 9b985ea nrf_ccm: Add RATEOVERRIDE subscribe support * 8592230 nrf_hack: Add comments * 5775f4c docs: Very minor typo and grammar fixes Signed-off-by: Alberto Escolar Piedras (cherry picked from commit c4e1807cdf4d4a868995bcbe51716ac7fef78d3d) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index a141e94edd6..b9a84545850 100644 --- a/west.yml +++ b/west.yml @@ -295,7 +295,7 @@ manifest: groups: - tools - name: nrf_hw_models - revision: a715dcc179f1a71f51c574165958b72fe932ae3f + revision: 9b985ea6bc237b6ae06f48eb228f2ac7f6e3b96b path: modules/bsim_hw_models/nrf_hw_models - name: open-amp revision: 214f9fc1539f8e5937c0474cb6ee29b6dcb2d4b8 From a8136cb27e83a594085a0f95d533c20ccd23354c Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 1 Dec 2023 16:52:19 +0100 Subject: [PATCH 1099/1623] [nrf fromtree] boards nrf5340bsim_cpuapp: Select approprite 802154 radio in DT Set the chosen 802154 radio in DT for the nrf5340bsim_nrf5340_cpuapp so we can build with the radio driver built into the net core. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 47b7eaece9419214fb2065cba4b9c520dc807ca6) --- boards/posix/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts | 1 + 1 file changed, 1 insertion(+) diff --git a/boards/posix/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts b/boards/posix/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts index a7c3d39ace5..c5ec3c95af5 100644 --- a/boards/posix/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts +++ b/boards/posix/nrf_bsim/nrf5340bsim_nrf5340_cpuapp.dts @@ -49,6 +49,7 @@ zephyr,flash = &flash0; zephyr,bt-hci-ipc = &ipc0; nordic,802154-spinel-ipc = &ipc0; + zephyr,ieee802154 = &ieee802154; }; soc { From d142e4b062d5e5c9f107d2702ee7db7f065292e0 Mon Sep 17 00:00:00 2001 From: Rubin Gerritsen Date: Thu, 18 Jan 2024 15:32:47 +0100 Subject: [PATCH 1100/1623] [nrf fromtree] Bluetooth: ISO: Fix CIS peripheral disconnection during setup When the central aborts the CIS setup during the CIS Creation procedure after it has accepted the CIS request, the peripheral will receive the HCI LE CIS Established event with an error code. It does not receive a disconnection event. See the message sequence chart in Core_v5.4, Vol 6, Part D, Section 6.23. This commit ensures that the perirpheral disconnected callback gets called for this particular scenario. Signed-off-by: Rubin Gerritsen (cherry picked from commit db588104921ac8bfd3f4c2b1b41c84cf5e710ec2) --- subsys/bluetooth/host/iso.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/iso.c b/subsys/bluetooth/host/iso.c index 42e9c877a9a..4d6366ead67 100644 --- a/subsys/bluetooth/host/iso.c +++ b/subsys/bluetooth/host/iso.c @@ -1117,7 +1117,8 @@ void hci_le_cis_established(struct net_buf *buf) bt_conn_set_state(iso, BT_CONN_CONNECTED); bt_conn_unref(iso); return; - } else if (evt->status != BT_HCI_ERR_OP_CANCELLED_BY_HOST) { + } else if (iso->role == BT_HCI_ROLE_PERIPHERAL || + evt->status != BT_HCI_ERR_OP_CANCELLED_BY_HOST) { iso->err = evt->status; bt_iso_disconnected(iso); } /* else we wait for disconnect event */ From 81474ef240546a7d4ef381cd7fb28627b5f43dc5 Mon Sep 17 00:00:00 2001 From: Vladislav Litvinov Date: Tue, 23 Jan 2024 10:37:39 +0100 Subject: [PATCH 1101/1623] [nrf noup] ci: Fix PMIC samples change scope Remove leading slashes Signed-off-by: Vladislav Litvinov --- .github/test-spec.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index cad113b0883..1d3e04fe75b 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -257,10 +257,10 @@ - "subsys/zbus/**/*" "CI-pmic-samples-test": - - "/samples/shields/npm1300_ek/**/*" - - "/boards/shields/npm1300_ek/**/*" + - "samples/shields/npm1300_ek/**/*" + - "boards/shields/npm1300_ek/**/*" - "**/**npm1300**/**" - - "/drivers/regulator/regulator_common.c" - - "/drivers/regulator/regulator_shell.c" - - "/drivers/gpio/gpio_shell.c" - - "/drivers/sensor/sensor_shell.c" + - "drivers/regulator/regulator_common.c" + - "drivers/regulator/regulator_shell.c" + - "drivers/gpio/gpio_shell.c" + - "drivers/sensor/sensor_shell.c" From 2e5e0b159563eba914f44bdbcdbb06eef31f8f98 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Sat, 9 Dec 2023 09:02:22 +0200 Subject: [PATCH 1102/1623] [nrf fromtree] net: Move trickle files to lib The trickle algorithm files are clearly a library so move them under lib/ directory. Signed-off-by: Jukka Rissanen (cherry picked from commit b6d9ed095d7bc395be602072db2679d201735113) --- subsys/net/ip/CMakeLists.txt | 1 - subsys/net/ip/Kconfig | 14 -------------- subsys/net/lib/CMakeLists.txt | 1 + subsys/net/lib/Kconfig | 2 ++ subsys/net/lib/trickle/CMakeLists.txt | 7 +++++++ subsys/net/lib/trickle/Kconfig | 18 ++++++++++++++++++ subsys/net/{ip => lib/trickle}/trickle.c | 0 7 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 subsys/net/lib/trickle/CMakeLists.txt create mode 100644 subsys/net/lib/trickle/Kconfig rename subsys/net/{ip => lib/trickle}/trickle.c (100%) diff --git a/subsys/net/ip/CMakeLists.txt b/subsys/net/ip/CMakeLists.txt index b9493b894a7..3a93e5020d4 100644 --- a/subsys/net/ip/CMakeLists.txt +++ b/subsys/net/ip/CMakeLists.txt @@ -45,7 +45,6 @@ zephyr_library_sources_ifdef(CONFIG_NET_ROUTE route.c) zephyr_library_sources_ifdef(CONFIG_NET_STATISTICS net_stats.c) zephyr_library_sources_ifdef(CONFIG_NET_TCP tcp.c) zephyr_library_sources_ifdef(CONFIG_NET_TEST_PROTOCOL tp.c) -zephyr_library_sources_ifdef(CONFIG_NET_TRICKLE trickle.c) zephyr_library_sources_ifdef(CONFIG_NET_UDP udp.c) zephyr_library_sources_ifdef(CONFIG_NET_PROMISCUOUS_MODE promiscuous.c) diff --git a/subsys/net/ip/Kconfig b/subsys/net/ip/Kconfig index fffa028b628..a5a6b7ba01e 100644 --- a/subsys/net/ip/Kconfig +++ b/subsys/net/ip/Kconfig @@ -758,20 +758,6 @@ config NET_SLIP_TAP communicate via the SLIP driver. See net-tools project at https://github.com/zephyrproject-rtos/net-tools for more details. -config NET_TRICKLE - bool "Trickle library" - help - Normally this is enabled automatically if needed, - so say 'n' if unsure. - -if NET_TRICKLE -module = NET_TRICKLE -module-dep = NET_LOG -module-str = Log level for Trickle algorithm -module-help = Enables Trickle library output debug messages -source "subsys/net/Kconfig.template.log_config.net" -endif # NET_TRICKLE - endif # NET_RAW_MODE config NET_PKT_RX_COUNT diff --git a/subsys/net/lib/CMakeLists.txt b/subsys/net/lib/CMakeLists.txt index 756adb41341..5e4eae7e028 100644 --- a/subsys/net/lib/CMakeLists.txt +++ b/subsys/net/lib/CMakeLists.txt @@ -14,6 +14,7 @@ add_subdirectory_ifdef(CONFIG_TLS_CREDENTIALS tls_credentials) add_subdirectory_ifdef(CONFIG_NET_CAPTURE capture) add_subdirectory_ifdef(CONFIG_NET_ZPERF zperf) add_subdirectory_ifdef(CONFIG_NET_SHELL shell) +add_subdirectory_ifdef(CONFIG_NET_TRICKLE trickle) if (CONFIG_DNS_RESOLVER OR CONFIG_MDNS_RESPONDER diff --git a/subsys/net/lib/Kconfig b/subsys/net/lib/Kconfig index 5df4a445885..b70105d5f9b 100644 --- a/subsys/net/lib/Kconfig +++ b/subsys/net/lib/Kconfig @@ -39,6 +39,8 @@ menu "Network additional services" source "subsys/net/lib/capture/Kconfig" +source "subsys/net/lib/trickle/Kconfig" + source "subsys/net/lib/zperf/Kconfig" endmenu diff --git a/subsys/net/lib/trickle/CMakeLists.txt b/subsys/net/lib/trickle/CMakeLists.txt new file mode 100644 index 00000000000..b9cf222aab5 --- /dev/null +++ b/subsys/net/lib/trickle/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() + +zephyr_library_sources( + trickle.c + ) diff --git a/subsys/net/lib/trickle/Kconfig b/subsys/net/lib/trickle/Kconfig new file mode 100644 index 00000000000..edc4f8fcf56 --- /dev/null +++ b/subsys/net/lib/trickle/Kconfig @@ -0,0 +1,18 @@ +# Trickle Library for Zephyr + +# Copyright (c) 2016 Intel Corporation. +# SPDX-License-Identifier: Apache-2.0 + +config NET_TRICKLE + bool "Trickle library" + help + Normally this is enabled automatically if needed, + so say 'n' if unsure. + +if NET_TRICKLE +module = NET_TRICKLE +module-dep = NET_LOG +module-str = Log level for Trickle algorithm +module-help = Enables Trickle library output debug messages +source "subsys/net/Kconfig.template.log_config.net" +endif # NET_TRICKLE diff --git a/subsys/net/ip/trickle.c b/subsys/net/lib/trickle/trickle.c similarity index 100% rename from subsys/net/ip/trickle.c rename to subsys/net/lib/trickle/trickle.c From 87cbab4403bc4627e1454521631beba6d925355a Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Thu, 16 Nov 2023 17:06:12 +0200 Subject: [PATCH 1103/1623] [nrf fromtree] net: sockets: Create a socket service API The socket service provides a similar functionality as what initd provides in Linux. It listens user registered sockets for any activity and then launches a k_work for it. This way each application does not need to create a thread to listen a blocking socket. Signed-off-by: Jukka Rissanen (cherry picked from commit eff5d028728ccc8291f9d83a724517288e940435) --- .../linker/common-rom/common-rom-net.ld | 4 + include/zephyr/net/socket_service.h | 246 +++++++++++++++ subsys/net/lib/sockets/CMakeLists.txt | 1 + subsys/net/lib/sockets/Kconfig | 25 ++ subsys/net/lib/sockets/sockets_service.c | 291 ++++++++++++++++++ 5 files changed, 567 insertions(+) create mode 100644 include/zephyr/net/socket_service.h create mode 100644 subsys/net/lib/sockets/sockets_service.c diff --git a/include/zephyr/linker/common-rom/common-rom-net.ld b/include/zephyr/linker/common-rom/common-rom-net.ld index 71c1c1e089f..18360212edc 100644 --- a/include/zephyr/linker/common-rom/common-rom-net.ld +++ b/include/zephyr/linker/common-rom/common-rom-net.ld @@ -21,3 +21,7 @@ #if defined(CONFIG_COAP_SERVER) ITERABLE_SECTION_ROM(coap_service, 4) #endif + +#if defined(CONFIG_NET_SOCKETS_SERVICE) + ITERABLE_SECTION_RAM(net_socket_service_desc, 4) +#endif diff --git a/include/zephyr/net/socket_service.h b/include/zephyr/net/socket_service.h new file mode 100644 index 00000000000..16da94d238b --- /dev/null +++ b/include/zephyr/net/socket_service.h @@ -0,0 +1,246 @@ +/** + * @file + * @brief BSD Socket service API + * + * API can be used to install a k_work that is called + * if there is data received to a socket. + */ + +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_NET_SOCKET_SERVICE_H_ +#define ZEPHYR_INCLUDE_NET_SOCKET_SERVICE_H_ + +/** + * @brief BSD socket service API + * @defgroup bsd_socket_service BSD socket service API + * @ingroup networking + * @{ + */ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * This struct contains information which socket triggered + * calls to the callback function. + */ +struct net_socket_service_event { + /** k_work that is done when there is desired activity in file descriptor. */ + struct k_work work; + /** Callback to be called for desired socket activity */ + k_work_handler_t callback; + /** Socket information that triggered this event. */ + struct zsock_pollfd event; + /** User data */ + void *user_data; + /** Service back pointer */ + struct net_socket_service_desc *svc; +}; + +/** + * Main structure holding socket service configuration information. + * The k_work item is created so that when there is data coming + * to those fds, the k_work callback is then called. + * The workqueue can be set NULL in which case system workqueue is used. + * The service descriptor should be created at built time, and then used + * as a parameter to register the sockets to be monitored. + * User should create needed sockets and then setup the poll struct and + * then register the sockets to be monitored at runtime. + */ +struct net_socket_service_desc { +#if CONFIG_NET_SOCKETS_LOG_LEVEL >= LOG_LEVEL_DBG + /** + * Owner name. This can be used in debugging to see who has + * registered this service. + */ + const char *owner; +#endif + /** Workqueue where the work is submitted. */ + struct k_work_q *work_q; + /** Pointer to the list of services that we are listening */ + struct net_socket_service_event *pev; + /** Length of the pollable socket array for this service. */ + int pev_len; + /** Where are my pollfd entries in the global list */ + int *idx; +}; + +#define __z_net_socket_svc_get_name(_svc_id) __z_net_socket_service_##_svc_id +#define __z_net_socket_svc_get_idx(_svc_id) __z_net_socket_service_idx##_svc_id +#define __z_net_socket_svc_get_owner __FILE__ ":" STRINGIFY(__LINE__) + +extern void net_socket_service_callback(struct k_work *work); + +#if CONFIG_NET_SOCKETS_LOG_LEVEL >= LOG_LEVEL_DBG +#define NET_SOCKET_SERVICE_OWNER .owner = __z_net_socket_svc_get_owner, +#else +#define NET_SOCKET_SERVICE_OWNER +#endif + +#define NET_SOCKET_SERVICE_CALLBACK_MODE(_flag) \ + IF_ENABLED(_flag, \ + (.work = Z_WORK_INITIALIZER(net_socket_service_callback),)) + +#define __z_net_socket_service_define(_name, _work_q, _cb, _count, _async, ...) \ + static int __z_net_socket_svc_get_idx(_name); \ + static struct net_socket_service_event \ + __z_net_socket_svc_get_name(_name)[_count] = { \ + [0 ... ((_count) - 1)] = { \ + .event.fd = -1, /* Invalid socket */ \ + NET_SOCKET_SERVICE_CALLBACK_MODE(_async) \ + .callback = _cb, \ + } \ + }; \ + COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), (), __VA_ARGS__) \ + const STRUCT_SECTION_ITERABLE(net_socket_service_desc, _name) = { \ + NET_SOCKET_SERVICE_OWNER \ + .work_q = (_work_q), \ + .pev = __z_net_socket_svc_get_name(_name), \ + .pev_len = (_count), \ + .idx = &__z_net_socket_svc_get_idx(_name), \ + } + +/** + * @brief Statically define a network socket service. + * The user callback is called asynchronously for this service meaning that + * the service API will not wait until the user callback returns before continuing + * with next socket service. + * + * The socket service can be accessed outside the module where it is defined using: + * + * @code extern struct net_socket_service_desc ; @endcode + * + * @note This macro cannot be used together with a static keyword. + * If such a use-case is desired, use NET_SOCKET_SERVICE_ASYNC_DEFINE_STATIC + * instead. + * + * @param name Name of the service. + * @param work_q Pointer to workqueue where the work is done. Can be null in which case + * system workqueue is used. + * @param cb Callback function that is called for socket activity. + * @param count How many pollable sockets is needed for this service. + */ +#define NET_SOCKET_SERVICE_ASYNC_DEFINE(name, work_q, cb, count) \ + __z_net_socket_service_define(name, work_q, cb, count, 1) + +/** + * @brief Statically define a network socket service in a private (static) scope. + * The user callback is called asynchronously for this service meaning that + * the service API will not wait until the user callback returns before continuing + * with next socket service. + * + * @param name Name of the service. + * @param work_q Pointer to workqueue where the work is done. Can be null in which case + * system workqueue is used. + * @param cb Callback function that is called for socket activity. + * @param count How many pollable sockets is needed for this service. + */ +#define NET_SOCKET_SERVICE_ASYNC_DEFINE_STATIC(name, work_q, cb, count) \ + __z_net_socket_service_define(name, work_q, cb, count, 1, static) + +/** + * @brief Statically define a network socket service. + * The user callback is called synchronously for this service meaning that + * the service API will wait until the user callback returns before continuing + * with next socket service. + * + * The socket service can be accessed outside the module where it is defined using: + * + * @code extern struct net_socket_service_desc ; @endcode + * + * @note This macro cannot be used together with a static keyword. + * If such a use-case is desired, use NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC + * instead. + * + * @param name Name of the service. + * @param work_q Pointer to workqueue where the work is done. Can be null in which case + * system workqueue is used. + * @param cb Callback function that is called for socket activity. + * @param count How many pollable sockets is needed for this service. + */ +#define NET_SOCKET_SERVICE_SYNC_DEFINE(name, work_q, cb, count) \ + __z_net_socket_service_define(name, work_q, cb, count, 0) + +/** + * @brief Statically define a network socket service in a private (static) scope. + * The user callback is called synchronously for this service meaning that + * the service API will wait until the user callback returns before continuing + * with next socket service. + * + * @param name Name of the service. + * @param work_q Pointer to workqueue where the work is done. Can be null in which case + * system workqueue is used. + * @param cb Callback function that is called for socket activity. + * @param count How many pollable sockets is needed for this service. + */ +#define NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(name, work_q, cb, count) \ + __z_net_socket_service_define(name, work_q, cb, count, 0, static) + +/** + * @brief Register pollable sockets. + * + * @param service Pointer to a service description. + * @param fds Socket array to poll. + * @param len Length of the socket array. + * @param user_data User specific data. + * + * @retval 0 No error + * @retval -ENOENT Service is not found. + * @retval -ENINVAL Invalid parameter. + */ +__syscall int net_socket_service_register(const struct net_socket_service_desc *service, + struct zsock_pollfd *fds, int len, void *user_data); + +/** + * @brief Unregister pollable sockets. + * + * @param service Pointer to a service description. + * + * @retval 0 No error + * @retval -ENOENT Service is not found. + * @retval -ENINVAL Invalid parameter. + */ +static inline int net_socket_service_unregister(const struct net_socket_service_desc *service) +{ + return net_socket_service_register(service, NULL, 0, NULL); +} + +/** + * @typedef net_socket_service_cb_t + * @brief Callback used while iterating over socket services. + * + * @param svc Pointer to current socket service. + * @param user_data A valid pointer to user data or NULL + */ +typedef void (*net_socket_service_cb_t)(const struct net_socket_service_desc *svc, + void *user_data); + +/** + * @brief Go through all the socket services and call callback for each service. + * + * @param cb User-supplied callback function to call + * @param user_data User specified data + */ +void net_socket_service_foreach(net_socket_service_cb_t cb, void *user_data); + +#ifdef __cplusplus +} +#endif + +#include + +/** + * @} + */ + +#endif /* ZEPHYR_INCLUDE_NET_SOCKET_SERVICE_H_ */ diff --git a/subsys/net/lib/sockets/CMakeLists.txt b/subsys/net/lib/sockets/CMakeLists.txt index 7ffd6dc476b..253cb4a182f 100644 --- a/subsys/net/lib/sockets/CMakeLists.txt +++ b/subsys/net/lib/sockets/CMakeLists.txt @@ -26,6 +26,7 @@ zephyr_library_sources_ifdef(CONFIG_NET_SOCKETS_SOCKOPT_TLS sockets_tls.c zephyr_library_sources_ifdef(CONFIG_NET_SOCKETS_OFFLOAD socket_offload.c) zephyr_library_sources_ifdef(CONFIG_NET_SOCKETS_OFFLOAD_DISPATCHER socket_dispatcher.c) zephyr_library_sources_ifdef(CONFIG_NET_SOCKETS_OBJ_CORE socket_obj_core.c) +zephyr_library_sources_ifdef(CONFIG_NET_SOCKETS_SERVICE sockets_service.c) if(CONFIG_NET_SOCKETS_NET_MGMT) zephyr_library_sources(sockets_net_mgmt.c) diff --git a/subsys/net/lib/sockets/Kconfig b/subsys/net/lib/sockets/Kconfig index b2da30c1e48..40d86b9498f 100644 --- a/subsys/net/lib/sockets/Kconfig +++ b/subsys/net/lib/sockets/Kconfig @@ -73,6 +73,31 @@ config NET_SOCKET_MAX_SEND_WAIT The maximum time a socket is waiting for a blocked connection before returning an ENOBUFS error. +config NET_SOCKETS_SERVICE + bool "Socket service support [EXPERIMENTAL]" + select EXPERIMENTAL + select EVENTFD + help + The socket service can monitor multiple sockets and save memory + by only having one thread listening socket data. If data is received + in the monitored socket, a user supplied work is called. + Note that you need to set CONFIG_NET_SOCKETS_POLL_MAX high enough + so that enough sockets entries can be serviced. This depends on + system needs as multiple services can be activated at the same time + depending on network configuration. + +config NET_SOCKETS_SERVICE_STACK_SIZE + int "Stack size for the thread handling socket services" + default 1200 + depends on NET_SOCKETS_SERVICE + help + Set the internal stack size for the thread that polls sockets. + +config NET_SOCKETS_SERVICE_INIT_PRIO + int "Startup priority for the network socket service" + default 95 + depends on NET_SOCKETS_SERVICE + config NET_SOCKETS_SOCKOPT_TLS bool "TCP TLS socket option support [EXPERIMENTAL]" imply TLS_CREDENTIALS diff --git a/subsys/net/lib/sockets/sockets_service.c b/subsys/net/lib/sockets/sockets_service.c new file mode 100644 index 00000000000..d253ece629c --- /dev/null +++ b/subsys/net/lib/sockets/sockets_service.c @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +LOG_MODULE_REGISTER(net_sock_svc, CONFIG_NET_SOCKETS_LOG_LEVEL); + +#include +#include +#include + +static int init_socket_service(void); +static bool init_done; + +static K_MUTEX_DEFINE(lock); +static K_CONDVAR_DEFINE(wait_start); + +STRUCT_SECTION_START_EXTERN(net_socket_service_desc); +STRUCT_SECTION_END_EXTERN(net_socket_service_desc); + +static struct service { + /* The +1 is for triggering events from register function */ + struct zsock_pollfd events[1 + CONFIG_NET_SOCKETS_POLL_MAX]; + int count; +} ctx; + +#define get_idx(svc) (*(svc->idx)) + +void net_socket_service_foreach(net_socket_service_cb_t cb, void *user_data) +{ + STRUCT_SECTION_FOREACH(net_socket_service_desc, svc) { + cb(svc, user_data); + } +} + +static void cleanup_svc_events(const struct net_socket_service_desc *svc) +{ + for (int i = 0; i < svc->pev_len; i++) { + ctx.events[get_idx(svc) + i].fd = -1; + svc->pev[i].event.fd = -1; + svc->pev[i].event.events = 0; + } +} + +int z_impl_net_socket_service_register(const struct net_socket_service_desc *svc, + struct zsock_pollfd *fds, int len, + void *user_data) +{ + int i, ret = -ENOENT; + + k_mutex_lock(&lock, K_FOREVER); + + if (!init_done) { + (void)k_condvar_wait(&wait_start, &lock, K_FOREVER); + } + + if (STRUCT_SECTION_START(net_socket_service_desc) > svc || + STRUCT_SECTION_END(net_socket_service_desc) <= svc) { + goto out; + } + + if (fds == NULL) { + cleanup_svc_events(svc); + } else { + if (len > svc->pev_len) { + NET_DBG("Too many file descriptors, " + "max is %d for service %p", + svc->pev_len, svc); + ret = -ENOMEM; + goto out; + } + + for (i = 0; i < len; i++) { + svc->pev[i].event = fds[i]; + svc->pev[i].user_data = user_data; + } + + for (i = 0; i < svc->pev_len; i++) { + ctx.events[get_idx(svc) + i] = svc->pev[i].event; + } + } + + /* Tell the thread to re-read the variables */ + eventfd_write(ctx.events[0].fd, 1); + ret = 0; + +out: + k_mutex_unlock(&lock); + + return ret; +} + +static struct net_socket_service_desc *find_svc_and_event( + struct zsock_pollfd *pev, + struct net_socket_service_event **event) +{ + STRUCT_SECTION_FOREACH(net_socket_service_desc, svc) { + for (int i = 0; i < svc->pev_len; i++) { + if (svc->pev[i].event.fd == pev->fd) { + *event = &svc->pev[i]; + return svc; + } + } + } + + return NULL; +} + +/* We do not set the user callback to our work struct because we need to + * hook into the flow and restore the global poll array so that the next poll + * round will not notice it and call the callback again while we are + * servicing the callback. + */ +void net_socket_service_callback(struct k_work *work) +{ + struct net_socket_service_event *pev = + CONTAINER_OF(work, struct net_socket_service_event, work); + struct net_socket_service_desc *svc = pev->svc; + struct net_socket_service_event ev = *pev; + + ev.callback(&ev.work); + + /* Copy back the socket fd to the global array because we marked + * it as -1 when triggering the work. + */ + for (int i = 0; i < svc->pev_len; i++) { + ctx.events[get_idx(svc) + i] = svc->pev[i].event; + } +} + +static int call_work(struct zsock_pollfd *pev, struct k_work_q *work_q, + struct k_work *work) +{ + int ret = 0; + + /* Mark the global fd non pollable so that we do not + * call the callback second time. + */ + pev->fd = -1; + + if (work->handler == NULL) { + /* Synchronous call */ + net_socket_service_callback(work); + } else { + if (work_q != NULL) { + ret = k_work_submit_to_queue(work_q, work); + } else { + ret = k_work_submit(work); + } + + k_yield(); + } + + return ret; + +} + +static int trigger_work(struct zsock_pollfd *pev) +{ + struct net_socket_service_event *event; + struct net_socket_service_desc *svc; + + svc = find_svc_and_event(pev, &event); + if (svc == NULL) { + return -ENOENT; + } + + event->svc = svc; + + /* Copy the triggered event to our event so that we know what + * was actually causing the event. + */ + event->event = *pev; + + return call_work(pev, svc->work_q, &event->work); +} + +static void socket_service_thread(void) +{ + int ret, i, fd, count = 0; + eventfd_t value; + + STRUCT_SECTION_COUNT(net_socket_service_desc, &ret); + if (ret == 0) { + NET_INFO("No socket services found, service disabled."); + goto fail; + } + + /* Create contiguous poll event array to enable socket polling */ + STRUCT_SECTION_FOREACH(net_socket_service_desc, svc) { + get_idx(svc) = count + 1; + count += svc->pev_len; + } + + if ((count + 1) > ARRAY_SIZE(ctx.events)) { + NET_WARN("You have %d services to monitor but " + "%d poll entries configured.", + count + 1, ARRAY_SIZE(ctx.events)); + NET_WARN("Consider increasing value of %s to %d", + "CONFIG_NET_SOCKETS_POLL_MAX", count + 1); + } + + NET_DBG("Monitoring %d socket entries", count); + + ctx.count = count + 1; + + /* Create an eventfd that can be used to trigger events during polling */ + fd = eventfd(0, 0); + if (fd < 0) { + fd = -errno; + NET_ERR("eventfd failed (%d)", fd); + goto out; + } + + init_done = true; + k_condvar_broadcast(&wait_start); + + ctx.events[0].fd = fd; + ctx.events[0].events = ZSOCK_POLLIN; + +restart: + i = 1; + + k_mutex_lock(&lock, K_FOREVER); + + /* Copy individual events to the big array */ + STRUCT_SECTION_FOREACH(net_socket_service_desc, svc) { + for (int j = 0; j < svc->pev_len; j++) { + ctx.events[get_idx(svc) + j] = svc->pev[j].event; + } + } + + k_mutex_unlock(&lock); + + while (true) { + ret = zsock_poll(ctx.events, count + 1, -1); + if (ret < 0) { + ret = -errno; + NET_ERR("poll failed (%d)", ret); + goto out; + } + + if (ret == 0) { + /* should not happen because timeout is -1 */ + break; + } + + if (ret > 0 && ctx.events[0].revents) { + eventfd_read(ctx.events[0].fd, &value); + NET_DBG("Received restart event."); + goto restart; + } + + for (i = 1; i < (count + 1); i++) { + if (ctx.events[i].fd < 0) { + continue; + } + + if (ctx.events[i].revents > 0) { + ret = trigger_work(&ctx.events[i]); + if (ret < 0) { + NET_DBG("Triggering work failed (%d)", ret); + } + } + } + } + +out: + NET_DBG("Socket service thread stopped"); + init_done = false; + + return; + +fail: + k_condvar_broadcast(&wait_start); +} + +K_THREAD_DEFINE(socket_service_monitor, CONFIG_NET_SOCKETS_SERVICE_STACK_SIZE, + socket_service_thread, NULL, NULL, NULL, + K_LOWEST_APPLICATION_THREAD_PRIO, 0, 0); + +static int init_socket_service(void) +{ + k_thread_name_set(socket_service_monitor, "net_socket_service"); + + return 0; +} + +SYS_INIT(init_socket_service, APPLICATION, CONFIG_NET_SOCKETS_SERVICE_INIT_PRIO); From 227b98f4aeeabb05f6660944f043a51bf6ef9f15 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Thu, 18 Jan 2024 12:55:25 +0100 Subject: [PATCH 1104/1623] [nrf fromtree] net: socket_service: Add underscore in the idx variable name Nothing critical, but it just looks better if the service name is separated from the prefix, i.e: _z_net_socket_service_idx_udp_service_async vs current: _z_net_socket_service_idxudp_service_async Signed-off-by: Robert Lubos (cherry picked from commit 3111b801d90ff9d109e678421097da01f45685e0) --- include/zephyr/net/socket_service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/net/socket_service.h b/include/zephyr/net/socket_service.h index 16da94d238b..a4e21f00a33 100644 --- a/include/zephyr/net/socket_service.h +++ b/include/zephyr/net/socket_service.h @@ -76,7 +76,7 @@ struct net_socket_service_desc { }; #define __z_net_socket_svc_get_name(_svc_id) __z_net_socket_service_##_svc_id -#define __z_net_socket_svc_get_idx(_svc_id) __z_net_socket_service_idx##_svc_id +#define __z_net_socket_svc_get_idx(_svc_id) __z_net_socket_service_idx_##_svc_id #define __z_net_socket_svc_get_owner __FILE__ ":" STRINGIFY(__LINE__) extern void net_socket_service_callback(struct k_work *work); From 93ac51d09be899f0f5e5fea4e03dea49e60ce882 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Thu, 18 Jan 2024 12:57:49 +0100 Subject: [PATCH 1105/1623] [nrf fromtree] net: socket_service: Fix iterable section location The iterable section should be located in ROM and not RAM, this caused crashes on multiple platforms running socket services. Fixes #67762 Signed-off-by: Robert Lubos (cherry picked from commit 8ad0e5763f844e1cff81b21ebc54c1cc6101ff41) --- include/zephyr/linker/common-rom/common-rom-net.ld | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/linker/common-rom/common-rom-net.ld b/include/zephyr/linker/common-rom/common-rom-net.ld index 18360212edc..2aa46dfecf5 100644 --- a/include/zephyr/linker/common-rom/common-rom-net.ld +++ b/include/zephyr/linker/common-rom/common-rom-net.ld @@ -23,5 +23,5 @@ #endif #if defined(CONFIG_NET_SOCKETS_SERVICE) - ITERABLE_SECTION_RAM(net_socket_service_desc, 4) + ITERABLE_SECTION_ROM(net_socket_service_desc, 4) #endif From 70abf9f2c7ff978d3218e6a1246fb75dcfa0cd19 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 16 Jan 2024 17:37:59 +0100 Subject: [PATCH 1106/1623] [nrf fromtree] net: arp: Make arp_update() function externally visible So that it's possible to register ARP entries manually. Needed for DHCP server implementation, which in unicast mode needs to reply to an IP address that is not registered on the peer interface yet (hence no ARP reply will be sent). It's needed to add an ARP entry manually in that case, as hardware address is already known at that point. Signed-off-by: Robert Lubos (cherry picked from commit 1d14f13d75eb31104eb84d5d00e835cf82fb8377) --- subsys/net/l2/ethernet/arp.c | 34 +++++++++++++++++----------------- subsys/net/l2/ethernet/arp.h | 4 ++++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/subsys/net/l2/ethernet/arp.c b/subsys/net/l2/ethernet/arp.c index 39a06ed64a0..6be7255b19b 100644 --- a/subsys/net/l2/ethernet/arp.c +++ b/subsys/net/l2/ethernet/arp.c @@ -457,11 +457,11 @@ static void arp_gratuitous(struct net_if *iface, } } -static void arp_update(struct net_if *iface, - struct in_addr *src, - struct net_eth_addr *hwaddr, - bool gratuitous, - bool force) +void net_arp_update(struct net_if *iface, + struct in_addr *src, + struct net_eth_addr *hwaddr, + bool gratuitous, + bool force) { struct arp_entry *entry; struct net_pkt *pkt; @@ -647,10 +647,10 @@ enum net_verdict net_arp_input(struct net_pkt *pkt, /* If the IP address is in our cache, * then update it here. */ - arp_update(net_pkt_iface(pkt), - (struct in_addr *)arp_hdr->src_ipaddr, - &arp_hdr->src_hwaddr, - true, false); + net_arp_update(net_pkt_iface(pkt), + (struct in_addr *)arp_hdr->src_ipaddr, + &arp_hdr->src_hwaddr, + true, false); break; } } @@ -689,10 +689,10 @@ enum net_verdict net_arp_input(struct net_pkt *pkt, net_sprint_ll_addr((uint8_t *)&arp_hdr->src_hwaddr, arp_hdr->hwlen)); - arp_update(net_pkt_iface(pkt), - (struct in_addr *)arp_hdr->src_ipaddr, - &arp_hdr->src_hwaddr, - false, true); + net_arp_update(net_pkt_iface(pkt), + (struct in_addr *)arp_hdr->src_ipaddr, + &arp_hdr->src_hwaddr, + false, true); dst_hw_addr = &arp_hdr->src_hwaddr; } else { @@ -711,10 +711,10 @@ enum net_verdict net_arp_input(struct net_pkt *pkt, case NET_ARP_REPLY: if (net_ipv4_is_my_addr((struct in_addr *)arp_hdr->dst_ipaddr)) { - arp_update(net_pkt_iface(pkt), - (struct in_addr *)arp_hdr->src_ipaddr, - &arp_hdr->src_hwaddr, - false, false); + net_arp_update(net_pkt_iface(pkt), + (struct in_addr *)arp_hdr->src_ipaddr, + &arp_hdr->src_hwaddr, + false, false); } break; diff --git a/subsys/net/l2/ethernet/arp.h b/subsys/net/l2/ethernet/arp.h index 28cafe5f20a..46589cbc1f7 100644 --- a/subsys/net/l2/ethernet/arp.h +++ b/subsys/net/l2/ethernet/arp.h @@ -67,6 +67,9 @@ int net_arp_foreach(net_arp_cb_t cb, void *user_data); void net_arp_clear_cache(struct net_if *iface); void net_arp_init(void); +void net_arp_update(struct net_if *iface, struct in_addr *src, + struct net_eth_addr *hwaddr, bool gratuitous, + bool force); /** * @} @@ -83,6 +86,7 @@ void net_arp_init(void); #define net_arp_foreach(...) 0 #define net_arp_init(...) #define net_arp_clear_pending(...) 0 +#define net_arp_update(...) #endif /* CONFIG_NET_ARP */ From f3d115bad99c167900b83d59dd1a88bb75acf27a Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 16 Jan 2024 17:38:16 +0100 Subject: [PATCH 1107/1623] [nrf fromtree] net: if: Add function to obtain IPv4 netmask Add a helper function to obtain IPv4 netmask configured on an interface. Signed-off-by: Robert Lubos (cherry picked from commit db80ed3e8df1d662f5e750b5629e5e6e7c1bddd5) --- include/zephyr/net/net_if.h | 9 +++++++++ subsys/net/ip/net_if.c | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/zephyr/net/net_if.h b/include/zephyr/net/net_if.h index 788c3316391..f1e5be67cf7 100644 --- a/include/zephyr/net/net_if.h +++ b/include/zephyr/net/net_if.h @@ -2217,6 +2217,15 @@ struct in_addr *net_if_ipv4_get_ll(struct net_if *iface, struct in_addr *net_if_ipv4_get_global_addr(struct net_if *iface, enum net_addr_state addr_state); +/** + * @brief Get IPv4 netmask of an interface. + * + * @param iface Interface to use. + * + * @return The netmask set on the interface, unspecified address if not found. + */ +struct in_addr net_if_ipv4_get_netmask(struct net_if *iface); + /** * @brief Set IPv4 netmask for an interface. * diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 00c9c74495d..1a8199ad62c 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -3532,6 +3532,27 @@ static inline int z_vrfy_net_if_ipv4_addr_lookup_by_index( #include #endif +struct in_addr net_if_ipv4_get_netmask(struct net_if *iface) +{ + struct in_addr netmask = { 0 }; + + net_if_lock(iface); + + if (net_if_config_ipv4_get(iface, NULL) < 0) { + goto out; + } + + if (!iface->config.ip.ipv4) { + goto out; + } + + netmask = iface->config.ip.ipv4->netmask; +out: + net_if_unlock(iface); + + return netmask; +} + void net_if_ipv4_set_netmask(struct net_if *iface, const struct in_addr *netmask) { From fb9ace0f2e6ac68e2f7a3438cafdf6f6f5799f33 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 16 Jan 2024 17:38:56 +0100 Subject: [PATCH 1108/1623] [nrf fromtree] net: dhcpv4: Implement DHCPv4 server Add basic socket-based implementation of DHCPv4 sever. Signed-off-by: Robert Lubos (cherry picked from commit 1e08bbd5434f82e7a7849677e7dd10416d71488b) --- include/zephyr/net/dhcpv4_server.h | 118 ++ subsys/net/ip/dhcpv4.h | 11 + subsys/net/ip/net_core.c | 2 + subsys/net/lib/CMakeLists.txt | 1 + subsys/net/lib/Kconfig | 2 + subsys/net/lib/dhcpv4/CMakeLists.txt | 11 + subsys/net/lib/dhcpv4/Kconfig | 46 + subsys/net/lib/dhcpv4/dhcpv4_server.c | 1439 +++++++++++++++++++++++++ 8 files changed, 1630 insertions(+) create mode 100644 include/zephyr/net/dhcpv4_server.h create mode 100644 subsys/net/lib/dhcpv4/CMakeLists.txt create mode 100644 subsys/net/lib/dhcpv4/Kconfig create mode 100644 subsys/net/lib/dhcpv4/dhcpv4_server.c diff --git a/include/zephyr/net/dhcpv4_server.h b/include/zephyr/net/dhcpv4_server.h new file mode 100644 index 00000000000..18c4af114cd --- /dev/null +++ b/include/zephyr/net/dhcpv4_server.h @@ -0,0 +1,118 @@ +/** @file + * @brief DHCPv4 Server API + */ + +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_NET_DHCPV4_SERVER_H_ +#define ZEPHYR_INCLUDE_NET_DHCPV4_SERVER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief DHCPv4 server + * @defgroup dhcpv4_server DHCPv4 server + * @ingroup networking + * @{ + */ + +/** @cond INTERNAL_HIDDEN */ + +struct net_if; + +#define DHCPV4_CLIENT_ID_MAX_SIZE 20 + +enum dhcpv4_server_addr_state { + DHCPV4_SERVER_ADDR_FREE, + DHCPV4_SERVER_ADDR_RESERVED, + DHCPV4_SERVER_ADDR_ALLOCATED, + DHCPV4_SERVER_ADDR_DECLINED, +}; + +struct dhcpv4_client_id { + uint8_t buf[DHCPV4_CLIENT_ID_MAX_SIZE]; + uint8_t len; +}; + +struct dhcpv4_addr_slot { + enum dhcpv4_server_addr_state state; + struct dhcpv4_client_id client_id; + struct in_addr addr; + uint32_t lease_time; + k_timepoint_t expiry; +}; + +/** @endcond */ + +/** + * @brief Start DHCPv4 server instance on an iface + * + * @details Start DHCPv4 server on a given interface. The server will start + * listening for DHCPv4 Discover/Request messages on the interface and assign + * IPv4 addresses from the configured address pool accordingly. + * + * @param iface A valid pointer on an interface + * @param base_addr First IPv4 address from the DHCPv4 address pool. The number + * of addresses in the pool is configured statically with Kconfig + * (CONFIG_NET_DHCPV4_SERVER_ADDR_COUNT). + * + * @return 0 on success, a negative error code otherwise. + */ +int net_dhcpv4_server_start(struct net_if *iface, struct in_addr *base_addr); + +/** + * @brief Stop DHCPv4 server instance on an iface + * + * @details Stop DHCPv4 server on a given interface. DHCPv4 requests will no + * longer be handled on the interface, and all of the allocations are cleared. + * + * @param iface A valid pointer on an interface + * + * @return 0 on success, a negative error code otherwise. + */ +int net_dhcpv4_server_stop(struct net_if *iface); + +/** + * @typedef net_dhcpv4_lease_cb_t + * @brief Callback used while iterating over active DHCPv4 address leases + * + * @param iface Pointer to the network interface + * @param lease Pointer to the DHPCv4 address lease slot + * @param user_data A valid pointer to user data or NULL + */ +typedef void (*net_dhcpv4_lease_cb_t)(struct net_if *iface, + struct dhcpv4_addr_slot *lease, + void *user_data); + +/** + * @brief Iterate over all DHCPv4 address leases on a given network interface + * and call callback for each lease. In case no network interface is provided + * (NULL interface pointer), will iterate over all interfaces running DHCPv4 + * server instance. + * + * @param iface Pointer to the network interface, can be NULL + * @param cb User-supplied callback function to call + * @param user_data User specified data + */ +int net_dhcpv4_server_foreach_lease(struct net_if *iface, + net_dhcpv4_lease_cb_t cb, + void *user_data); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_NET_DHCPV4_SERVER_H_ */ diff --git a/subsys/net/ip/dhcpv4.h b/subsys/net/ip/dhcpv4.h index a274e3a6aea..712d361ac80 100644 --- a/subsys/net/ip/dhcpv4.h +++ b/subsys/net/ip/dhcpv4.h @@ -62,6 +62,7 @@ struct dhcp_msg { #define DHCPV4_OPTIONS_REQ_LIST 55 #define DHCPV4_OPTIONS_RENEWAL 58 #define DHCPV4_OPTIONS_REBINDING 59 +#define DHCPV4_OPTIONS_CLIENT_ID 61 #define DHCPV4_OPTIONS_END 255 /* Useful size macros */ @@ -142,4 +143,14 @@ static inline bool net_dhcpv4_accept_unicast(struct net_pkt *pkt) #endif /* CONFIG_NET_DHCPV4 && CONFIG_NET_DHCPV4_ACCEPT_UNICAST */ +#if defined(CONFIG_NET_DHCPV4_SERVER) + +void net_dhcpv4_server_init(void); + +#else + +#define net_dhcpv4_server_init() + +#endif /* CONFIG_NET_DHCPV4_SERVER */ + #endif /* __INTERNAL_DHCPV4_H */ diff --git a/subsys/net/ip/net_core.c b/subsys/net/ip/net_core.c index baa8cd695c5..3187b40a66b 100644 --- a/subsys/net/ip/net_core.c +++ b/subsys/net/ip/net_core.c @@ -495,6 +495,8 @@ static inline int services_init(void) return status; } + net_dhcpv4_server_init(); + dns_init_resolver(); websocket_init(); diff --git a/subsys/net/lib/CMakeLists.txt b/subsys/net/lib/CMakeLists.txt index 5e4eae7e028..e3319f6cd8d 100644 --- a/subsys/net/lib/CMakeLists.txt +++ b/subsys/net/lib/CMakeLists.txt @@ -15,6 +15,7 @@ add_subdirectory_ifdef(CONFIG_NET_CAPTURE capture) add_subdirectory_ifdef(CONFIG_NET_ZPERF zperf) add_subdirectory_ifdef(CONFIG_NET_SHELL shell) add_subdirectory_ifdef(CONFIG_NET_TRICKLE trickle) +add_subdirectory_ifdef(CONFIG_NET_DHCPV4_SERVER dhcpv4) if (CONFIG_DNS_RESOLVER OR CONFIG_MDNS_RESPONDER diff --git a/subsys/net/lib/Kconfig b/subsys/net/lib/Kconfig index b70105d5f9b..6cfa0445241 100644 --- a/subsys/net/lib/Kconfig +++ b/subsys/net/lib/Kconfig @@ -39,6 +39,8 @@ menu "Network additional services" source "subsys/net/lib/capture/Kconfig" +source "subsys/net/lib/dhcpv4/Kconfig" + source "subsys/net/lib/trickle/Kconfig" source "subsys/net/lib/zperf/Kconfig" diff --git a/subsys/net/lib/dhcpv4/CMakeLists.txt b/subsys/net/lib/dhcpv4/CMakeLists.txt new file mode 100644 index 00000000000..348b6c99bb7 --- /dev/null +++ b/subsys/net/lib/dhcpv4/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() + +zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/net/ip) + +zephyr_library_sources( + dhcpv4_server.c + ) diff --git a/subsys/net/lib/dhcpv4/Kconfig b/subsys/net/lib/dhcpv4/Kconfig new file mode 100644 index 00000000000..801d536a5a1 --- /dev/null +++ b/subsys/net/lib/dhcpv4/Kconfig @@ -0,0 +1,46 @@ +# DHCPv4 server implementation for Zephyr + +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +config NET_DHCPV4_SERVER + bool "DHCPv4 server" + depends on NET_IPV4 && NET_UDP + select NET_SOCKETS + select NET_SOCKETS_SERVICE + +if NET_DHCPV4_SERVER + +module = NET_DHCPV4_SERVER +module-dep = NET_LOG +module-str = Log level for DHCPv4 server +module-help = Enables DHCPv4 server output debug messages +source "subsys/net/Kconfig.template.log_config.net" + +config NET_DHCPV4_SERVER_INSTANCES + int "Maximum number of DHCPv4 server instances" + default 1 + help + Maximum number of DHCPv4 server instances supported by the system. + Each network interface that wants to act as a DHCPv4 server requires + a separate instance. + +config NET_DHCPV4_SERVER_ADDR_COUNT + int "Number of IPv4 addresses that can be assigned by the server" + default 4 + help + Maximum number of IPv4 addresses that can be assigned by the DHCPv4 + server instance. The base IPv4 address in the address pool is provided + at runtime, during server initialization. Consecutive addresses in the + pool have the lowest address octet incremented. + +config NET_DHCPV4_SERVER_ADDR_LEASE_TIME + int "Lease time for IPv4 addresses assigned by the server (seconds)" + default 86400 + help + Lease time in seconds for IPv4 addresses assigned by the server. + The lease time determines when the IPv4 address lease expires if the + client does not renew it. + +endif # NET_DHCPV4_SERVER diff --git a/subsys/net/lib/dhcpv4/dhcpv4_server.c b/subsys/net/lib/dhcpv4/dhcpv4_server.c new file mode 100644 index 00000000000..714d036ddde --- /dev/null +++ b/subsys/net/lib/dhcpv4/dhcpv4_server.c @@ -0,0 +1,1439 @@ +/** @file + * @brief DHCPv4 server implementation + */ + +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(net_dhcpv4_server, CONFIG_NET_DHCPV4_SERVER_LOG_LEVEL); + +#include "dhcpv4.h" +#include "net_private.h" +#include "../../l2/ethernet/arp.h" + +#define DHCPV4_OPTIONS_MSG_TYPE_SIZE 3 +#define DHCPV4_OPTIONS_IP_LEASE_TIME_SIZE 6 +#define DHCPV4_OPTIONS_SERVER_ID_SIZE 6 +#define DHCPV4_OPTIONS_SUBNET_MASK_SIZE 6 +#define DHCPV4_OPTIONS_CLIENT_ID_MIN_SIZE 2 + +#define ADDRESS_RESERVED_TIMEOUT K_SECONDS(5) + +/* RFC 1497 [17] */ +static const uint8_t magic_cookie[4] = { 0x63, 0x82, 0x53, 0x63 }; + +struct dhcpv4_server_ctx { + struct net_if *iface; + int sock; + struct k_work_delayable timeout_work; + struct dhcpv4_addr_slot addr_pool[CONFIG_NET_DHCPV4_SERVER_ADDR_COUNT]; + struct in_addr server_addr; + struct in_addr netmask; +}; + +static struct dhcpv4_server_ctx server_ctx[CONFIG_NET_DHCPV4_SERVER_INSTANCES]; +static struct zsock_pollfd fds[CONFIG_NET_DHCPV4_SERVER_INSTANCES]; +static K_MUTEX_DEFINE(server_lock); + +#define DHCPV4_MAX_PARAMETERS_REQUEST_LEN 16 + +struct dhcpv4_parameter_request_list { + uint8_t list[DHCPV4_MAX_PARAMETERS_REQUEST_LEN]; + uint8_t count; +}; + +static void dhcpv4_server_timeout_recalc(struct dhcpv4_server_ctx *ctx) +{ + k_timepoint_t next = sys_timepoint_calc(K_FOREVER); + k_timeout_t timeout; + + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; + + if (slot->state == DHCPV4_SERVER_ADDR_RESERVED || + slot->state == DHCPV4_SERVER_ADDR_ALLOCATED) { + if (sys_timepoint_cmp(slot->expiry, next) < 0) { + next = slot->expiry; + } + } + } + + timeout = sys_timepoint_timeout(next); + + if (K_TIMEOUT_EQ(timeout, K_FOREVER)) { + LOG_DBG("No more addresses, canceling timer"); + k_work_cancel_delayable(&ctx->timeout_work); + } else { + k_work_reschedule(&ctx->timeout_work, timeout); + } +} + +/* Option parsing. */ + +static uint8_t *dhcpv4_find_option(uint8_t *data, size_t datalen, + uint8_t *optlen, uint8_t opt_code) +{ + uint8_t *opt = NULL; + + while (datalen > 0) { + uint8_t code; + uint8_t len; + + code = *data; + + /* Two special cases (fixed sized options) */ + if (code == 0) { + data++; + datalen--; + continue; + } + + if (code == DHCPV4_OPTIONS_END) { + break; + } + + /* Length field should now follow. */ + if (datalen < 2) { + break; + } + + len = *(data + 1); + + if (datalen < len + 2) { + break; + } + + if (code == opt_code) { + /* Found the option. */ + opt = data + 2; + *optlen = len; + break; + } + + data += len + 2; + datalen -= len + 2; + } + + return opt; +} + +static int dhcpv4_find_message_type_option(uint8_t *data, size_t datalen, + uint8_t *msgtype) +{ + uint8_t *opt; + uint8_t optlen; + + opt = dhcpv4_find_option(data, datalen, &optlen, + DHCPV4_OPTIONS_MSG_TYPE); + if (opt == NULL) { + return -ENOENT; + } + + if (optlen != 1) { + return -EINVAL; + } + + *msgtype = *opt; + + return 0; +} + +static int dhcpv4_find_server_id_option(uint8_t *data, size_t datalen, + struct in_addr *server_id) +{ + uint8_t *opt; + uint8_t optlen; + + opt = dhcpv4_find_option(data, datalen, &optlen, + DHCPV4_OPTIONS_SERVER_ID); + if (opt == NULL) { + return -ENOENT; + } + + if (optlen != sizeof(struct in_addr)) { + return -EINVAL; + } + + memcpy(server_id, opt, sizeof(struct in_addr)); + + return 0; +} + +static int dhcpv4_find_client_id_option(uint8_t *data, size_t datalen, + uint8_t *client_id, uint8_t *len) +{ + uint8_t *opt; + uint8_t optlen; + + opt = dhcpv4_find_option(data, datalen, &optlen, + DHCPV4_OPTIONS_CLIENT_ID); + if (opt == NULL) { + return -ENOENT; + } + + if (optlen < DHCPV4_OPTIONS_CLIENT_ID_MIN_SIZE) { + return -EINVAL; + } + + if (optlen > *len) { + LOG_ERR("Not enough memory for DHCPv4 client identifier."); + return -ENOMEM; + } + + memcpy(client_id, opt, optlen); + *len = optlen; + + return 0; +} + +static int dhcpv4_find_requested_ip_option(uint8_t *data, size_t datalen, + struct in_addr *requested_ip) +{ + uint8_t *opt; + uint8_t optlen; + + opt = dhcpv4_find_option(data, datalen, &optlen, + DHCPV4_OPTIONS_REQ_IPADDR); + if (opt == NULL) { + return -ENOENT; + } + + if (optlen != sizeof(struct in_addr)) { + return -EINVAL; + } + + memcpy(requested_ip, opt, sizeof(struct in_addr)); + + return 0; +} + +static int dhcpv4_find_ip_lease_time_option(uint8_t *data, size_t datalen, + uint32_t *lease_time) +{ + uint8_t *opt; + uint8_t optlen; + + opt = dhcpv4_find_option(data, datalen, &optlen, + DHCPV4_OPTIONS_LEASE_TIME); + if (opt == NULL) { + return -ENOENT; + } + + if (optlen != sizeof(uint32_t)) { + return -EINVAL; + } + + *lease_time = sys_get_be32(opt); + + return 0; +} + +static int dhcpv4_find_parameter_request_list_option( + uint8_t *data, size_t datalen, + struct dhcpv4_parameter_request_list *params) +{ + uint8_t *opt; + uint8_t optlen; + + opt = dhcpv4_find_option(data, datalen, &optlen, + DHCPV4_OPTIONS_REQ_LIST); + if (opt == NULL) { + return -ENOENT; + } + + if (optlen > sizeof(params->list)) { + /* Best effort here, copy as much as we can. */ + optlen = sizeof(params->list); + } + + memcpy(params->list, opt, optlen); + params->count = optlen; + + return 0; +} + +/* Option encoding. */ + +static uint8_t *dhcpv4_encode_magic_cookie(uint8_t *buf, size_t *buflen) +{ + if (buf == NULL || *buflen < SIZE_OF_MAGIC_COOKIE) { + return NULL; + } + + memcpy(buf, magic_cookie, SIZE_OF_MAGIC_COOKIE); + + *buflen -= SIZE_OF_MAGIC_COOKIE; + + return buf + SIZE_OF_MAGIC_COOKIE; +} + +static uint8_t *dhcpv4_encode_ip_lease_time_option(uint8_t *buf, size_t *buflen, + uint32_t lease_time) +{ + if (buf == NULL || *buflen < DHCPV4_OPTIONS_IP_LEASE_TIME_SIZE) { + return NULL; + } + + buf[0] = DHCPV4_OPTIONS_LEASE_TIME; + buf[1] = sizeof(lease_time); + sys_put_be32(lease_time, &buf[2]); + + *buflen -= DHCPV4_OPTIONS_IP_LEASE_TIME_SIZE; + + return buf + DHCPV4_OPTIONS_IP_LEASE_TIME_SIZE; +} + +static uint8_t *dhcpv4_encode_message_type_option(uint8_t *buf, size_t *buflen, + uint8_t msgtype) +{ + if (buf == NULL || *buflen < DHCPV4_OPTIONS_MSG_TYPE_SIZE) { + return NULL; + } + + buf[0] = DHCPV4_OPTIONS_MSG_TYPE; + buf[1] = 1; + buf[2] = msgtype; + + *buflen -= DHCPV4_OPTIONS_MSG_TYPE_SIZE; + + return buf + DHCPV4_OPTIONS_MSG_TYPE_SIZE; +} + +static uint8_t *dhcpv4_encode_server_id_option(uint8_t *buf, size_t *buflen, + struct in_addr *server_id) +{ + if (buf == NULL || *buflen < DHCPV4_OPTIONS_SERVER_ID_SIZE) { + return NULL; + } + + buf[0] = DHCPV4_OPTIONS_SERVER_ID; + buf[1] = sizeof(struct in_addr); + memcpy(&buf[2], server_id->s4_addr, sizeof(struct in_addr)); + + *buflen -= DHCPV4_OPTIONS_SERVER_ID_SIZE; + + return buf + DHCPV4_OPTIONS_SERVER_ID_SIZE; +} + +static uint8_t *dhcpv4_encode_subnet_mask_option(uint8_t *buf, size_t *buflen, + struct in_addr *mask) +{ + if (buf == NULL || *buflen < DHCPV4_OPTIONS_SUBNET_MASK_SIZE) { + return NULL; + } + + buf[0] = DHCPV4_OPTIONS_SUBNET_MASK; + buf[1] = sizeof(struct in_addr); + memcpy(&buf[2], mask->s4_addr, sizeof(struct in_addr)); + + *buflen -= DHCPV4_OPTIONS_SUBNET_MASK_SIZE; + + return buf + DHCPV4_OPTIONS_SUBNET_MASK_SIZE; +} + +static uint8_t *dhcpv4_encode_end_option(uint8_t *buf, size_t *buflen) +{ + if (buf == NULL || *buflen < 1) { + return NULL; + } + + buf[0] = DHCPV4_OPTIONS_END; + + *buflen -= 1; + + return buf + 1; +} + +/* Response handlers. */ + +static uint8_t *dhcpv4_encode_header(uint8_t *buf, size_t *buflen, + struct dhcp_msg *msg, + struct in_addr *yiaddr) +{ + struct dhcp_msg *reply_msg = (struct dhcp_msg *)buf; + + if (buf == NULL || *buflen < sizeof(struct dhcp_msg)) { + return NULL; + } + + reply_msg->op = DHCPV4_MSG_BOOT_REPLY; + reply_msg->htype = msg->htype; + reply_msg->hlen = msg->hlen; + reply_msg->hops = 0; + reply_msg->xid = msg->xid; + reply_msg->secs = 0; + reply_msg->flags = msg->flags; + memcpy(reply_msg->ciaddr, msg->ciaddr, sizeof(reply_msg->ciaddr)); + if (yiaddr != NULL) { + memcpy(reply_msg->yiaddr, yiaddr, sizeof(struct in_addr)); + } else { + memset(reply_msg->yiaddr, 0, sizeof(reply_msg->ciaddr)); + } + memset(reply_msg->siaddr, 0, sizeof(reply_msg->siaddr)); + memcpy(reply_msg->giaddr, msg->giaddr, sizeof(reply_msg->giaddr)); + memcpy(reply_msg->chaddr, msg->chaddr, sizeof(reply_msg->chaddr)); + + *buflen -= sizeof(struct dhcp_msg); + + return buf + sizeof(struct dhcp_msg); +} + +static uint8_t *dhcpv4_encode_string(uint8_t *buf, size_t *buflen, char *str, + size_t max_len) +{ + if (buf == NULL || *buflen < max_len) { + return NULL; + } + + memset(buf, 0, max_len); + + if (str == NULL) { + goto out; + } + + strncpy(buf, str, max_len - 1); + + out: + *buflen -= max_len; + + return buf + max_len; +} + +static uint8_t *dhcpv4_encode_sname(uint8_t *buf, size_t *buflen, char *sname) +{ + return dhcpv4_encode_string(buf, buflen, sname, SIZE_OF_SNAME); +} + +static uint8_t *dhcpv4_encode_file(uint8_t *buf, size_t *buflen, char *file) +{ + return dhcpv4_encode_string(buf, buflen, file, SIZE_OF_FILE); +} + +static uint8_t *dhcpv4_encode_requested_params( + uint8_t *buf, size_t *buflen, + struct dhcpv4_server_ctx *ctx, + struct dhcpv4_parameter_request_list *params) +{ + for (uint8_t i = 0; i < params->count; i++) { + switch (params->list[i]) { + case DHCPV4_OPTIONS_SUBNET_MASK: + buf = dhcpv4_encode_subnet_mask_option( + buf, buflen, &ctx->netmask); + if (buf == NULL) { + goto out; + } + break; + + /* Others - just ignore. */ + default: + break; + } + } + +out: + return buf; +} + +static int dhcpv4_send(struct dhcpv4_server_ctx *ctx, enum net_dhcpv4_msg_type type, + uint8_t *reply, size_t len, struct dhcp_msg *msg, + struct in_addr *yiaddr) +{ + struct sockaddr_in dst_addr = { + .sin_family = AF_INET, + .sin_port = htons(DHCPV4_CLIENT_PORT), + }; + struct in_addr giaddr; /* Relay agent address */ + struct in_addr ciaddr; /* Client address */ + int ret; + + memcpy(&giaddr, msg->giaddr, sizeof(giaddr)); + memcpy(&ciaddr, msg->ciaddr, sizeof(ciaddr)); + + /* Select destination address as described in ch. 4.1. */ + if (!net_ipv4_is_addr_unspecified(&giaddr)) { + /* If the 'giaddr' field in a DHCP message from a client is + * non-zero, the server sends any return messages to the + * 'DHCP server' port on the BOOTP relay agent whose address + * appears in 'giaddr'. + */ + dst_addr.sin_addr = giaddr; + dst_addr.sin_port = htons(DHCPV4_SERVER_PORT); + } else if (type == NET_DHCPV4_MSG_TYPE_NAK) { + /* In all cases, when 'giaddr' is zero, the server broadcasts + * any DHCPNAK messages to 0xffffffff. + */ + dst_addr.sin_addr = *net_ipv4_broadcast_address(); + } else if (!net_ipv4_is_addr_unspecified(&ciaddr)) { + /* If the 'giaddr' field is zero and the 'ciaddr' field is + * nonzero, then the server unicasts DHCPOFFER and DHCPACK + * messages to the address in 'ciaddr'. + */ + dst_addr.sin_addr = ciaddr; + } else if (ntohs(msg->flags) & DHCPV4_MSG_BROADCAST) { + /* If 'giaddr' is zero and 'ciaddr' is zero, and the broadcast + * bit is set, then the server broadcasts DHCPOFFER and DHCPACK + * messages to 0xffffffff. + */ + dst_addr.sin_addr = *net_ipv4_broadcast_address(); + } else if (yiaddr != NULL) { + /* If the broadcast bit is not set and 'giaddr' is zero and + * 'ciaddr' is zero, then the server unicasts DHCPOFFER and + * DHCPACK messages to the client's hardware address and 'yiaddr' + * address. + */ + struct net_eth_addr hwaddr; + + memcpy(&hwaddr, msg->chaddr, sizeof(hwaddr)); + net_arp_update(ctx->iface, yiaddr, &hwaddr, false, true); + dst_addr.sin_addr = *yiaddr; + } else { + NET_ERR("Unspecified destination address."); + return -EDESTADDRREQ; + } + + ret = zsock_sendto(ctx->sock, reply, len, 0, (struct sockaddr *)&dst_addr, + sizeof(dst_addr)); + if (ret < 0) { + return -errno; + } + + return 0; +} + +static int dhcpv4_send_offer(struct dhcpv4_server_ctx *ctx, struct dhcp_msg *msg, + struct in_addr *addr, uint32_t lease_time, + struct dhcpv4_parameter_request_list *params) +{ + uint8_t reply[NET_IPV4_MTU]; + uint8_t *buf = reply; + size_t buflen = sizeof(reply); + size_t reply_len = 0; + int ret; + + buf = dhcpv4_encode_header(buf, &buflen, msg, addr); + buf = dhcpv4_encode_sname(buf, &buflen, NULL); + buf = dhcpv4_encode_file(buf, &buflen, NULL); + buf = dhcpv4_encode_magic_cookie(buf, &buflen); + buf = dhcpv4_encode_ip_lease_time_option(buf, &buflen, lease_time); + buf = dhcpv4_encode_message_type_option(buf, &buflen, + NET_DHCPV4_MSG_TYPE_OFFER); + buf = dhcpv4_encode_server_id_option(buf, &buflen, &ctx->server_addr); + buf = dhcpv4_encode_requested_params(buf, &buflen, ctx, params); + buf = dhcpv4_encode_end_option(buf, &buflen); + + if (buf == NULL) { + LOG_ERR("Failed to encode %s message", "Offer"); + return -ENOMEM; + } + + reply_len = sizeof(reply) - buflen; + + ret = dhcpv4_send(ctx, NET_DHCPV4_MSG_TYPE_OFFER, reply, reply_len, + msg, addr); + if (ret < 0) { + LOG_ERR("Failed to send %s message, %d", "Offer", ret); + return ret; + } + + return 0; +} + +static int dhcpv4_send_ack(struct dhcpv4_server_ctx *ctx, struct dhcp_msg *msg, + struct in_addr *addr, uint32_t lease_time, + struct dhcpv4_parameter_request_list *params, + bool inform) +{ + uint8_t reply[NET_IPV4_MTU]; + uint8_t *buf = reply; + size_t buflen = sizeof(reply); + size_t reply_len = 0; + int ret; + + buf = dhcpv4_encode_header(buf, &buflen, msg, inform ? NULL : addr); + buf = dhcpv4_encode_sname(buf, &buflen, NULL); + buf = dhcpv4_encode_file(buf, &buflen, NULL); + buf = dhcpv4_encode_magic_cookie(buf, &buflen); + if (!inform) { + buf = dhcpv4_encode_ip_lease_time_option(buf, &buflen, lease_time); + } + buf = dhcpv4_encode_message_type_option(buf, &buflen, + NET_DHCPV4_MSG_TYPE_ACK); + buf = dhcpv4_encode_server_id_option(buf, &buflen, &ctx->server_addr); + buf = dhcpv4_encode_requested_params(buf, &buflen, ctx, params); + buf = dhcpv4_encode_end_option(buf, &buflen); + + if (buf == NULL) { + LOG_ERR("Failed to encode %s message", "ACK"); + return -ENOMEM; + } + + reply_len = sizeof(reply) - buflen; + + ret = dhcpv4_send(ctx, NET_DHCPV4_MSG_TYPE_ACK, reply, reply_len, msg, + addr); + if (ret < 0) { + LOG_ERR("Failed to send %s message, %d", "ACK", ret); + return ret; + } + + return 0; +} + +static int dhcpv4_send_nak(struct dhcpv4_server_ctx *ctx, struct dhcp_msg *msg) +{ + uint8_t reply[NET_IPV4_MTU]; + uint8_t *buf = reply; + size_t buflen = sizeof(reply); + size_t reply_len = 0; + int ret; + + buf = dhcpv4_encode_header(buf, &buflen, msg, NULL); + buf = dhcpv4_encode_sname(buf, &buflen, NULL); + buf = dhcpv4_encode_file(buf, &buflen, NULL); + buf = dhcpv4_encode_magic_cookie(buf, &buflen); + buf = dhcpv4_encode_message_type_option(buf, &buflen, + NET_DHCPV4_MSG_TYPE_NAK); + buf = dhcpv4_encode_server_id_option(buf, &buflen, &ctx->server_addr); + buf = dhcpv4_encode_end_option(buf, &buflen); + + if (buf == NULL) { + LOG_ERR("Failed to encode %s message", "NAK"); + return -ENOMEM; + } + + reply_len = sizeof(reply) - buflen; + + ret = dhcpv4_send(ctx, NET_DHCPV4_MSG_TYPE_NAK, reply, reply_len, msg, + NULL); + if (ret < 0) { + LOG_ERR("Failed to send %s message, %d", "NAK", ret); + return ret; + } + + return 0; +} + +/* Message handlers. */ + +static int dhcpv4_get_client_id(struct dhcp_msg *msg, uint8_t *options, + uint8_t optlen, struct dhcpv4_client_id *client_id) +{ + int ret; + + client_id->len = sizeof(client_id->buf); + + ret = dhcpv4_find_client_id_option(options, optlen, client_id->buf, + &client_id->len); + if (ret == 0) { + return 0; + } + + /* No Client Id option or too long to use, fallback to hardware address. */ + if (msg->hlen > sizeof(msg->chaddr)) { + LOG_ERR("Malformed chaddr length."); + return -EINVAL; + } + + client_id->buf[0] = msg->htype; + client_id->buf[1] = msg->hlen; + memcpy(client_id->buf + 2, msg->chaddr, msg->hlen); + client_id->len = msg->hlen + 2; + + return 0; +} + +static uint32_t dhcpv4_get_lease_time(uint8_t *options, uint8_t optlen) +{ + uint32_t lease_time; + + if (dhcpv4_find_ip_lease_time_option(options, optlen, + &lease_time) == 0) { + return lease_time; + } + + return CONFIG_NET_DHCPV4_SERVER_ADDR_LEASE_TIME; +} + +static void dhcpv4_handle_discover(struct dhcpv4_server_ctx *ctx, + struct dhcp_msg *msg, uint8_t *options, + uint8_t optlen) +{ + struct dhcpv4_parameter_request_list params = { 0 }; + struct dhcpv4_addr_slot *selected = NULL; + struct dhcpv4_client_id client_id; + int ret; + + ret = dhcpv4_get_client_id(msg, options, optlen, &client_id); + if (ret < 0) { + return; + } + + (void)dhcpv4_find_parameter_request_list_option(options, optlen, ¶ms); + + /* Address pool and address selection algorithm as + * described in 4.3.1 + */ + + /* 1. Check for current bindings */ + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; + + if ((slot->state == DHCPV4_SERVER_ADDR_RESERVED || + slot->state == DHCPV4_SERVER_ADDR_ALLOCATED) && + slot->client_id.len == client_id.len && + memcmp(slot->client_id.buf, client_id.buf, + client_id.len) == 0) { + /* Got match in current bindings. */ + selected = slot; + break; + } + } + + /* 2. Skipped, for now expired/released entries are forgotten. */ + + /* 3. Check Requested IP Address option. */ + if (selected == NULL) { + struct in_addr requested_ip; + + ret = dhcpv4_find_requested_ip_option(options, optlen, + &requested_ip); + if (ret == 0) { + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = + &ctx->addr_pool[i]; + + if (net_ipv4_addr_cmp(&slot->addr, + &requested_ip) && + slot->state == DHCPV4_SERVER_ADDR_FREE) { + /* Requested address is free. */ + selected = slot; + break; + } + } + } + } + + /* 4. Allocate new address from pool, if available. */ + if (selected == NULL) { + struct in_addr giaddr; + + memcpy(&giaddr, msg->giaddr, sizeof(giaddr)); + if (!net_ipv4_is_addr_unspecified(&giaddr)) { + /* Only addresses in local subnet supproted for now. */ + return; + } + + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; + + if (slot->state == DHCPV4_SERVER_ADDR_FREE) { + /* Requested address is free. */ + selected = slot; + break; + } + } + } + + if (selected == NULL) { + LOG_ERR("No free address found in address pool"); + } else { + uint32_t lease_time = dhcpv4_get_lease_time(options, optlen); + + if (dhcpv4_send_offer(ctx, msg, &selected->addr, lease_time, + ¶ms) < 0) { + return; + } + + LOG_DBG("DHCPv4 processing Discover - reserved %s", + net_sprint_ipv4_addr(&selected->addr)); + + selected->state = DHCPV4_SERVER_ADDR_RESERVED; + selected->client_id.len = client_id.len; + memcpy(selected->client_id.buf, client_id.buf, client_id.len); + selected->lease_time = lease_time; + selected->expiry = sys_timepoint_calc(ADDRESS_RESERVED_TIMEOUT); + dhcpv4_server_timeout_recalc(ctx); + } +} + +static void dhcpv4_handle_request(struct dhcpv4_server_ctx *ctx, + struct dhcp_msg *msg, uint8_t *options, + uint8_t optlen) +{ + struct dhcpv4_parameter_request_list params = { 0 }; + struct dhcpv4_addr_slot *selected = NULL; + struct dhcpv4_client_id client_id; + struct in_addr requested_ip, server_id, ciaddr, giaddr; + int ret; + + memcpy(&ciaddr, msg->ciaddr, sizeof(ciaddr)); + memcpy(&giaddr, msg->giaddr, sizeof(giaddr)); + + if (!net_ipv4_is_addr_unspecified(&giaddr)) { + /* Only addresses in local subnet supported for now. */ + return; + } + + ret = dhcpv4_get_client_id(msg, options, optlen, &client_id); + if (ret < 0) { + /* Failed to obtain Client ID, ignore. */ + return; + } + + (void)dhcpv4_find_parameter_request_list_option(options, optlen, ¶ms); + + ret = dhcpv4_find_server_id_option(options, optlen, &server_id); + if (ret == 0) { + /* Server ID present, Request generated during SELECTING. */ + if (!net_ipv4_addr_cmp(&ctx->server_addr, &server_id)) { + /* Not for us, ignore. */ + return; + } + + ret = dhcpv4_find_requested_ip_option(options, optlen, + &requested_ip); + if (ret < 0) { + /* Requested IP missing, ignore. */ + return; + } + + if (!net_ipv4_is_addr_unspecified(&ciaddr)) { + /* ciaddr MUST be zero */ + return; + } + + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; + + if (net_ipv4_addr_cmp(&slot->addr, &requested_ip) && + slot->client_id.len == client_id.len && + memcmp(slot->client_id.buf, client_id.buf, + client_id.len) == 0 && + slot->state == DHCPV4_SERVER_ADDR_RESERVED) { + selected = slot; + break; + } + } + + if (selected == NULL) { + LOG_ERR("No valid slot found for DHCPv4 Request"); + } else { + uint32_t lease_time = dhcpv4_get_lease_time(options, optlen); + + if (dhcpv4_send_ack(ctx, msg, &selected->addr, lease_time, + ¶ms, false) < 0) { + return; + } + + LOG_DBG("DHCPv4 processing Request - allocated %s", + net_sprint_ipv4_addr(&selected->addr)); + + selected->lease_time = lease_time; + selected->expiry = sys_timepoint_calc( + K_SECONDS(lease_time)); + selected->state = DHCPV4_SERVER_ADDR_ALLOCATED; + dhcpv4_server_timeout_recalc(ctx); + } + + return; + } + + /* No server ID option - check requested address. */ + ret = dhcpv4_find_requested_ip_option(options, optlen, &requested_ip); + if (ret == 0) { + /* Requested IP present, Request generated during INIT-REBOOT. */ + if (!net_ipv4_is_addr_unspecified(&ciaddr)) { + /* ciaddr MUST be zero */ + return; + } + + if (!net_if_ipv4_addr_mask_cmp(ctx->iface, &requested_ip)) { + /* Wrong subnet. */ + dhcpv4_send_nak(ctx, msg); + } + + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; + + if (slot->client_id.len == client_id.len && + memcmp(slot->client_id.buf, client_id.buf, + client_id.len) == 0 && + (slot->state == DHCPV4_SERVER_ADDR_RESERVED || + slot->state == DHCPV4_SERVER_ADDR_ALLOCATED)) { + selected = slot; + break; + } + } + + if (selected != NULL) { + if (net_ipv4_addr_cmp(&selected->addr, &requested_ip)) { + uint32_t lease_time = dhcpv4_get_lease_time( + options, optlen); + + if (dhcpv4_send_ack(ctx, msg, &selected->addr, + lease_time, ¶ms, + false) < 0) { + return; + } + + selected->lease_time = lease_time; + selected->expiry = sys_timepoint_calc( + K_SECONDS(lease_time)); + dhcpv4_server_timeout_recalc(ctx); + } else { + dhcpv4_send_nak(ctx, msg); + } + } + + /* No notion of the client, remain silent. */ + return; + } + + /* Neither server ID or requested IP set, Request generated during + * RENEWING or REBINDING. + */ + + if (!net_if_ipv4_addr_mask_cmp(ctx->iface, &ciaddr)) { + /* Wrong subnet. */ + dhcpv4_send_nak(ctx, msg); + } + + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; + + if (net_ipv4_addr_cmp(&slot->addr, &ciaddr)) { + selected = slot; + break; + } + } + + if (selected != NULL) { + if (selected->state == DHCPV4_SERVER_ADDR_ALLOCATED && + selected->client_id.len == client_id.len && + memcmp(selected->client_id.buf, client_id.buf, + client_id.len) == 0) { + uint32_t lease_time = dhcpv4_get_lease_time( + options, optlen); + + if (dhcpv4_send_ack(ctx, msg, &ciaddr, lease_time, + ¶ms, false) < 0) { + return; + } + + selected->lease_time = lease_time; + selected->expiry = sys_timepoint_calc( + K_SECONDS(lease_time)); + dhcpv4_server_timeout_recalc(ctx); + } else { + dhcpv4_send_nak(ctx, msg); + } + } +} + +static void dhcpv4_handle_decline(struct dhcpv4_server_ctx *ctx, + struct dhcp_msg *msg, uint8_t *options, + uint8_t optlen) +{ + struct dhcpv4_client_id client_id; + struct in_addr requested_ip, server_id; + int ret; + + ret = dhcpv4_find_server_id_option(options, optlen, &server_id); + if (ret < 0) { + /* No server ID, ignore. */ + return; + } + + if (!net_ipv4_addr_cmp(&ctx->server_addr, &server_id)) { + /* Not for us, ignore. */ + return; + } + + ret = dhcpv4_get_client_id(msg, options, optlen, &client_id); + if (ret < 0) { + /* Failed to obtain Client ID, ignore. */ + return; + } + + ret = dhcpv4_find_requested_ip_option(options, optlen, + &requested_ip); + if (ret < 0) { + /* Requested IP missing, ignore. */ + return; + } + + LOG_ERR("Received DHCPv4 Decline for %s (address already in use)", + net_sprint_ipv4_addr(&requested_ip)); + + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; + + if (net_ipv4_addr_cmp(&slot->addr, &requested_ip) && + slot->client_id.len == client_id.len && + memcmp(slot->client_id.buf, client_id.buf, + client_id.len) == 0 && + (slot->state == DHCPV4_SERVER_ADDR_RESERVED || + slot->state == DHCPV4_SERVER_ADDR_ALLOCATED)) { + slot->state = DHCPV4_SERVER_ADDR_DECLINED; + slot->expiry = sys_timepoint_calc(K_FOREVER); + dhcpv4_server_timeout_recalc(ctx); + break; + } + } +} + +static void dhcpv4_handle_release(struct dhcpv4_server_ctx *ctx, + struct dhcp_msg *msg, uint8_t *options, + uint8_t optlen) +{ + struct dhcpv4_client_id client_id; + struct in_addr ciaddr, server_id; + int ret; + + ret = dhcpv4_find_server_id_option(options, optlen, &server_id); + if (ret < 0) { + /* No server ID, ignore. */ + return; + } + + if (!net_ipv4_addr_cmp(&ctx->server_addr, &server_id)) { + /* Not for us, ignore. */ + return; + } + + ret = dhcpv4_get_client_id(msg, options, optlen, &client_id); + if (ret < 0) { + /* Failed to obtain Client ID, ignore. */ + return; + } + + memcpy(&ciaddr, msg->ciaddr, sizeof(ciaddr)); + + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; + + if (net_ipv4_addr_cmp(&slot->addr, &ciaddr) && + slot->client_id.len == client_id.len && + memcmp(slot->client_id.buf, client_id.buf, + client_id.len) == 0 && + (slot->state == DHCPV4_SERVER_ADDR_RESERVED || + slot->state == DHCPV4_SERVER_ADDR_ALLOCATED)) { + LOG_DBG("DHCPv4 processing Release - %s", + net_sprint_ipv4_addr(&slot->addr)); + + slot->state = DHCPV4_SERVER_ADDR_FREE; + slot->expiry = sys_timepoint_calc(K_FOREVER); + dhcpv4_server_timeout_recalc(ctx); + break; + } + } +} + +static void dhcpv4_handle_inform(struct dhcpv4_server_ctx *ctx, + struct dhcp_msg *msg, uint8_t *options, + uint8_t optlen) +{ + struct dhcpv4_parameter_request_list params = { 0 }; + + (void)dhcpv4_find_parameter_request_list_option(options, optlen, ¶ms); + (void)dhcpv4_send_ack(ctx, msg, (struct in_addr *)msg->ciaddr, 0, + ¶ms, true); +} + +/* Server core. */ + +static void dhcpv4_server_timeout(struct k_work *work) +{ + struct k_work_delayable *dwork = k_work_delayable_from_work(work); + struct dhcpv4_server_ctx *ctx = + CONTAINER_OF(dwork, struct dhcpv4_server_ctx, timeout_work); + + + k_mutex_lock(&server_lock, K_FOREVER); + + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; + + if (slot->state == DHCPV4_SERVER_ADDR_RESERVED || + slot->state == DHCPV4_SERVER_ADDR_ALLOCATED) { + if (sys_timepoint_expired(slot->expiry)) { + LOG_DBG("Address %s expired", + net_sprint_ipv4_addr(&slot->addr)); + slot->state = DHCPV4_SERVER_ADDR_FREE; + } + } + } + + dhcpv4_server_timeout_recalc(ctx); + + k_mutex_unlock(&server_lock); +} + +static void dhcpv4_process_data(struct dhcpv4_server_ctx *ctx, uint8_t *data, + size_t datalen) +{ + struct dhcp_msg *msg; + uint8_t msgtype; + int ret; + + if (datalen < sizeof(struct dhcp_msg)) { + LOG_DBG("DHCPv4 server malformed message"); + return; + } + + msg = (struct dhcp_msg *)data; + + if (msg->op != DHCPV4_MSG_BOOT_REQUEST) { + /* Silently drop messages other than BOOTREQUEST */ + return; + } + + data += sizeof(struct dhcp_msg); + datalen -= sizeof(struct dhcp_msg); + + /* Skip server hostname/filename/option cookie */ + if (datalen < (SIZE_OF_SNAME + SIZE_OF_FILE + SIZE_OF_MAGIC_COOKIE)) { + return; + } + + data += SIZE_OF_SNAME + SIZE_OF_FILE + SIZE_OF_MAGIC_COOKIE; + datalen -= SIZE_OF_SNAME + SIZE_OF_FILE + SIZE_OF_MAGIC_COOKIE; + + /* Search options for DHCP message type. */ + ret = dhcpv4_find_message_type_option(data, datalen, &msgtype); + if (ret < 0) { + LOG_ERR("No message type option"); + return; + } + + k_mutex_lock(&server_lock, K_FOREVER); + + switch (msgtype) { + case NET_DHCPV4_MSG_TYPE_DISCOVER: + dhcpv4_handle_discover(ctx, msg, data, datalen); + break; + case NET_DHCPV4_MSG_TYPE_REQUEST: + dhcpv4_handle_request(ctx, msg, data, datalen); + break; + case NET_DHCPV4_MSG_TYPE_DECLINE: + dhcpv4_handle_decline(ctx, msg, data, datalen); + break; + case NET_DHCPV4_MSG_TYPE_RELEASE: + dhcpv4_handle_release(ctx, msg, data, datalen); + break; + case NET_DHCPV4_MSG_TYPE_INFORM: + dhcpv4_handle_inform(ctx, msg, data, datalen); + break; + + case NET_DHCPV4_MSG_TYPE_OFFER: + case NET_DHCPV4_MSG_TYPE_ACK: + case NET_DHCPV4_MSG_TYPE_NAK: + default: + /* Ignore server initiated and unknown message types. */ + break; + } + + k_mutex_unlock(&server_lock); +} + +static void dhcpv4_server_cb(struct k_work *work) +{ + struct net_socket_service_event *evt = + CONTAINER_OF(work, struct net_socket_service_event, work); + struct dhcpv4_server_ctx *ctx = NULL; + uint8_t recv_buf[NET_IPV4_MTU]; + int ret; + + for (int i = 0; i < ARRAY_SIZE(server_ctx); i++) { + if (server_ctx[i].sock == evt->event.fd) { + ctx = &server_ctx[i]; + break; + } + } + + if (ctx == NULL) { + LOG_ERR("No DHCPv4 server context found for given FD."); + return; + } + + if (evt->event.revents & ZSOCK_POLLERR) { + LOG_ERR("DHCPv4 server poll revents error"); + net_dhcpv4_server_stop(ctx->iface); + return; + } + + if (!(evt->event.revents & ZSOCK_POLLIN)) { + return; + } + + ret = zsock_recvfrom(evt->event.fd, recv_buf, sizeof(recv_buf), + ZSOCK_MSG_DONTWAIT, NULL, 0); + if (ret < 0) { + if (errno == EAGAIN) { + return; + } + + LOG_ERR("DHCPv4 server recv error, %d", errno); + net_dhcpv4_server_stop(ctx->iface); + return; + } + + dhcpv4_process_data(ctx, recv_buf, ret); +} + +NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(dhcpv4_server, NULL, dhcpv4_server_cb, + CONFIG_NET_DHCPV4_SERVER_INSTANCES); + +int net_dhcpv4_server_start(struct net_if *iface, struct in_addr *base_addr) +{ + struct sockaddr_in addr = { + .sin_family = AF_INET, + .sin_addr = INADDR_ANY_INIT, + .sin_port = htons(DHCPV4_SERVER_PORT), + }; + struct ifreq ifreq = { 0 }; + int ret, sock = -1, slot = -1; + const struct in_addr *server_addr; + struct in_addr netmask; + + if (iface == NULL || base_addr == NULL) { + return -EINVAL; + } + + if (!net_if_ipv4_addr_mask_cmp(iface, base_addr)) { + LOG_ERR("Address pool does not belong to the interface subnet."); + return -EINVAL; + } + + server_addr = net_if_ipv4_select_src_addr(iface, base_addr); + if (server_addr == NULL) { + LOG_ERR("Failed to obtain a valid server address."); + return -EINVAL; + } + + netmask = net_if_ipv4_get_netmask(iface); + if (net_ipv4_is_addr_unspecified(&netmask)) { + LOG_ERR("Failed to obtain subnet mask."); + return -EINVAL; + } + + k_mutex_lock(&server_lock, K_FOREVER); + + for (int i = 0; i < ARRAY_SIZE(server_ctx); i++) { + if (server_ctx[i].iface != NULL) { + if (server_ctx[i].iface == iface) { + LOG_ERR("DHCPv4 server instance already running."); + ret = -EALREADY; + goto error; + } + } else { + if (slot < 0) { + slot = i; + } + } + } + + if (slot < 0) { + LOG_ERR("No free DHCPv4 server intance."); + ret = -ENOMEM; + goto error; + } + + ret = net_if_get_name(iface, ifreq.ifr_name, sizeof(ifreq.ifr_name)); + if (ret < 0) { + LOG_ERR("Failed to obtain interface name."); + goto error; + } + + sock = zsock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (sock < 0) { + ret = errno; + LOG_ERR("Failed to create DHCPv4 server socket, %d", ret); + goto error; + } + + ret = zsock_setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, &ifreq, + sizeof(ifreq)); + if (ret < 0) { + ret = errno; + LOG_ERR("Failed to bind DHCPv4 server socket with interface, %d", + ret); + goto error; + } + + ret = zsock_bind(sock, (struct sockaddr *)&addr, sizeof(addr)); + if (ret < 0) { + ret = errno; + LOG_ERR("Failed to bind DHCPv4 server socket, %d", ret); + goto error; + } + + fds[slot].fd = sock; + fds[slot].events = ZSOCK_POLLIN; + + server_ctx[slot].iface = iface; + server_ctx[slot].sock = sock; + server_ctx[slot].server_addr = *server_addr; + server_ctx[slot].netmask = netmask; + + k_work_init_delayable(&server_ctx[slot].timeout_work, + dhcpv4_server_timeout); + + LOG_DBG("Started DHCPv4 server, address pool:"); + for (int i = 0; i < ARRAY_SIZE(server_ctx[slot].addr_pool); i++) { + server_ctx[slot].addr_pool[i].state = DHCPV4_SERVER_ADDR_FREE; + server_ctx[slot].addr_pool[i].addr.s_addr = + htonl(ntohl(base_addr->s_addr) + i); + + LOG_DBG("\t%2d: %s", i, + net_sprint_ipv4_addr( + &server_ctx[slot].addr_pool[i].addr)); + } + + ret = net_socket_service_register(&dhcpv4_server, fds, ARRAY_SIZE(fds), + NULL); + if (ret < 0) { + LOG_ERR("Failed to register socket service, %d", ret); + memset(&server_ctx[slot], 0, sizeof(server_ctx[slot])); + fds[slot].fd = -1; + goto error; + } + + k_mutex_unlock(&server_lock); + + return 0; + +error: + if (sock >= 0) { + (void)zsock_close(sock); + } + + k_mutex_unlock(&server_lock); + + return ret; +} + +int net_dhcpv4_server_stop(struct net_if *iface) +{ + struct k_work_sync sync; + int slot = -1; + int ret = 0; + bool service_stop = true; + + if (iface == NULL) { + return -EINVAL; + } + + k_mutex_lock(&server_lock, K_FOREVER); + + for (int i = 0; i < ARRAY_SIZE(server_ctx); i++) { + if (server_ctx[i].iface == iface) { + slot = i; + break; + } + } + + if (slot < 0) { + ret = -ENOENT; + goto out; + } + + fds[slot].fd = -1; + (void)zsock_close(server_ctx[slot].sock); + + k_work_cancel_delayable_sync(&server_ctx[slot].timeout_work, &sync); + + memset(&server_ctx[slot], 0, sizeof(server_ctx[slot])); + + for (int i = 0; i < ARRAY_SIZE(fds); i++) { + if (fds[i].fd >= 0) { + service_stop = false; + break; + } + } + + if (service_stop) { + ret = net_socket_service_unregister(&dhcpv4_server); + } else { + ret = net_socket_service_register(&dhcpv4_server, fds, + ARRAY_SIZE(fds), NULL); + } + +out: + k_mutex_unlock(&server_lock); + + return ret; +} + +static void dhcpv4_server_foreach_lease_on_ctx(struct dhcpv4_server_ctx *ctx, + net_dhcpv4_lease_cb_t cb, + void *user_data) +{ + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *addr = &ctx->addr_pool[i]; + + if (addr->state != DHCPV4_SERVER_ADDR_FREE) { + cb(ctx->iface, addr, user_data); + } + } +} + +int net_dhcpv4_server_foreach_lease(struct net_if *iface, + net_dhcpv4_lease_cb_t cb, + void *user_data) +{ + int slot = -1; + int ret = 0; + + k_mutex_lock(&server_lock, K_FOREVER); + + if (iface == NULL) { + for (int i = 0; i < ARRAY_SIZE(server_ctx); i++) { + if (server_ctx[i].iface != NULL) { + dhcpv4_server_foreach_lease_on_ctx( + &server_ctx[i], cb, user_data); + } + } + + return 0; + } + + for (int i = 0; i < ARRAY_SIZE(server_ctx); i++) { + if (server_ctx[i].iface == iface) { + slot = i; + break; + } + } + + if (slot < 0) { + ret = -ENOENT; + goto out; + } + + dhcpv4_server_foreach_lease_on_ctx(&server_ctx[slot], cb, user_data); + +out: + k_mutex_unlock(&server_lock); + + return ret; +} + +void net_dhcpv4_server_init(void) +{ + for (int i = 0; i < ARRAY_SIZE(fds); i++) { + fds[i].fd = -1; + } +} From 7a0cbb67886c736bdf31f87246a5a626765087b3 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 16 Jan 2024 17:38:40 +0100 Subject: [PATCH 1109/1623] [nrf fromtree] net: socket_services: Increase default stack size for DHCPv4 server Increase socket services thread default stack size when DHCPv4 server is enabled, as it uses synchronous processing. Signed-off-by: Robert Lubos (cherry picked from commit 3bc50871bccb7a4ff9c03c845ac9a4a2208a0d12) --- subsys/net/lib/sockets/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/net/lib/sockets/Kconfig b/subsys/net/lib/sockets/Kconfig index 40d86b9498f..35750dd3583 100644 --- a/subsys/net/lib/sockets/Kconfig +++ b/subsys/net/lib/sockets/Kconfig @@ -88,6 +88,7 @@ config NET_SOCKETS_SERVICE config NET_SOCKETS_SERVICE_STACK_SIZE int "Stack size for the thread handling socket services" + default 2400 if NET_DHCPV4_SERVER default 1200 depends on NET_SOCKETS_SERVICE help From d97e4bc99ec6a3bbd96ebfa4a16b2a3a7efcf94f Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 16 Jan 2024 17:38:23 +0100 Subject: [PATCH 1110/1623] [nrf fromtree] net: shell: Implement DHCPv4 server shell commands Implement DHCPv4 shell module, which allows to start/stop DHCPv4 server operation, and print server status (address leases). Signed-off-by: Robert Lubos (cherry picked from commit 2c70c5d74adb250420506d8a7f2aa40631a24916) --- subsys/net/lib/shell/CMakeLists.txt | 1 + subsys/net/lib/shell/dhcpv4.c | 215 ++++++++++++++++++++++++++++ 2 files changed, 216 insertions(+) create mode 100644 subsys/net/lib/shell/dhcpv4.c diff --git a/subsys/net/lib/shell/CMakeLists.txt b/subsys/net/lib/shell/CMakeLists.txt index 2c5c0757505..5cfb5c269b4 100644 --- a/subsys/net/lib/shell/CMakeLists.txt +++ b/subsys/net/lib/shell/CMakeLists.txt @@ -10,6 +10,7 @@ zephyr_library_sources(allocs.c) zephyr_library_sources(arp.c) zephyr_library_sources(capture.c) zephyr_library_sources(conn.c) +zephyr_library_sources(dhcpv4.c) zephyr_library_sources(dns.c) zephyr_library_sources(events.c) zephyr_library_sources(gptp.c) diff --git a/subsys/net/lib/shell/dhcpv4.c b/subsys/net/lib/shell/dhcpv4.c new file mode 100644 index 00000000000..a59b9c45edb --- /dev/null +++ b/subsys/net/lib/shell/dhcpv4.c @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +LOG_MODULE_DECLARE(net_shell); + +#include +#include +#include + +#include "net_shell_private.h" + +static int cmd_net_dhcpv4_server_start(const struct shell *sh, size_t argc, char *argv[]) +{ +#if defined(CONFIG_NET_DHCPV4_SERVER) + struct net_if *iface = NULL; + struct in_addr base_addr; + int idx, ret; + + idx = get_iface_idx(sh, argv[1]); + if (idx < 0) { + return -ENOEXEC; + } + + iface = net_if_get_by_index(idx); + if (!iface) { + PR_WARNING("No such interface in index %d\n", idx); + return -ENOEXEC; + } + + if (net_addr_pton(AF_INET, argv[2], &base_addr)) { + PR_ERROR("Invalid address: %s\n", argv[2]); + return -EINVAL; + } + + ret = net_dhcpv4_server_start(iface, &base_addr); + if (ret == -EALREADY) { + PR_WARNING("DHCPv4 server already running on interface %d\n", idx); + } else if (ret < 0) { + PR_ERROR("DHCPv4 server failed to start on interface %d, error %d\n", + idx, -ret); + } else { + PR("DHCPv4 server started on interface %d\n", idx); + } +#else /* CONFIG_NET_DHCPV4_SERVER */ + PR_INFO("Set %s to enable %s support.\n", + "CONFIG_NET_DHCPV4_SERVER", "DHCPv4 server"); +#endif /* CONFIG_NET_DHCPV4_SERVER */ + return 0; +} + +static int cmd_net_dhcpv4_server_stop(const struct shell *sh, size_t argc, char *argv[]) +{ +#if defined(CONFIG_NET_DHCPV4_SERVER) + struct net_if *iface = NULL; + int idx, ret; + + idx = get_iface_idx(sh, argv[1]); + if (idx < 0) { + return -ENOEXEC; + } + + iface = net_if_get_by_index(idx); + if (!iface) { + PR_WARNING("No such interface in index %d\n", idx); + return -ENOEXEC; + } + + ret = net_dhcpv4_server_stop(iface); + if (ret == -ENOENT) { + PR_WARNING("DHCPv4 server is not running on interface %d\n", idx); + } else if (ret < 0) { + PR_ERROR("DHCPv4 server failed to stop on interface %d, error %d\n", + idx, -ret); + } else { + PR("DHCPv4 server stopped on interface %d\n", idx); + } +#else /* CONFIG_NET_DHCPV4_SERVER */ + PR_INFO("Set %s to enable %s support.\n", + "CONFIG_NET_DHCPV4_SERVER", "DHCPv4 server"); +#endif /* CONFIG_NET_DHCPV4_SERVER */ + return 0; +} + +#if defined(CONFIG_NET_DHCPV4_SERVER) +static const char *dhcpv4_addr_state_to_str(enum dhcpv4_server_addr_state state) +{ + switch (state) { + case DHCPV4_SERVER_ADDR_FREE: + return "FREE"; + case DHCPV4_SERVER_ADDR_RESERVED: + return "RESERVED"; + case DHCPV4_SERVER_ADDR_ALLOCATED: + return "ALLOCATED"; + case DHCPV4_SERVER_ADDR_DECLINED: + return "DECLINED"; + } + + return ""; +} + +static uint32_t timepoint_to_s(k_timepoint_t timepoint) +{ + k_timeout_t timeout = sys_timepoint_timeout(timepoint); + + if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) { + return 0; + } + + if (K_TIMEOUT_EQ(timeout, K_FOREVER)) { + return UINT32_MAX; + } + + return k_ticks_to_ms_floor64(timeout.ticks) / 1000; +} + +static void dhcpv4_lease_cb(struct net_if *iface, + struct dhcpv4_addr_slot *lease, + void *user_data) +{ + struct net_shell_user_data *data = user_data; + const struct shell *sh = data->sh; + int *count = data->user_data; + char expiry_str[] = "4294967295"; /* Lease time is uint32_t, so take + * theoretical max. + */ + char iface_name[IFNAMSIZ] = ""; + + if (*count == 0) { + PR(" Iface Address\t State\tExpiry (sec)\n"); + } + + (*count)++; + + (void)net_if_get_name(iface, iface_name, sizeof(iface_name)); + + if (lease->state == DHCPV4_SERVER_ADDR_DECLINED) { + snprintk(expiry_str, sizeof(expiry_str) - 1, "infinite"); + } else { + snprintk(expiry_str, sizeof(expiry_str) - 1, "%u", + timepoint_to_s(lease->expiry)); + } + + PR("%2d. %6s %15s\t%9s\t%12s\n", + *count, iface_name, net_sprint_ipv4_addr(&lease->addr), + dhcpv4_addr_state_to_str(lease->state), expiry_str); +} +#endif /* CONFIG_NET_DHCPV4_SERVER */ + +static int cmd_net_dhcpv4_server_status(const struct shell *sh, size_t argc, char *argv[]) +{ +#if defined(CONFIG_NET_DHCPV4_SERVER) + struct net_shell_user_data user_data; + struct net_if *iface = NULL; + int idx = 0, ret; + int count = 0; + + if (argc > 1) { + idx = get_iface_idx(sh, argv[1]); + if (idx < 0) { + return -ENOEXEC; + } + + iface = net_if_get_by_index(idx); + if (!iface) { + PR_WARNING("No such interface in index %d\n", idx); + return -ENOEXEC; + } + } + + user_data.sh = sh; + user_data.user_data = &count; + + ret = net_dhcpv4_server_foreach_lease(iface, dhcpv4_lease_cb, &user_data); + if (ret == -ENOENT) { + PR_WARNING("DHCPv4 server is not running on interface %d\n", idx); + } else if (count == 0) { + PR("DHCPv4 server - no addresses assigned\n"); + } +#else /* CONFIG_NET_DHCPV4_SERVER */ + PR_INFO("Set %s to enable %s support.\n", + "CONFIG_NET_DHCPV4_SERVER", "DHCPv4 server"); +#endif /* CONFIG_NET_DHCPV4_SERVER */ + return 0; +} + +SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_dhcpv4_server, + SHELL_CMD_ARG(start, NULL, "Start the DHCPv4 server operation on the interface.\n" + "'net dhcpv4 server start '\n" + " is the network interface index.\n" + " is the first address for the address pool.", + cmd_net_dhcpv4_server_start, 3, 0), + SHELL_CMD_ARG(stop, NULL, "Stop the DHCPv4 server operation on the interface.\n" + "'net dhcpv4 server stop '\n" + " is the network interface index.", + cmd_net_dhcpv4_server_stop, 2, 0), + SHELL_CMD_ARG(status, NULL, "Print the DHCPv4 server status on the interface.\n" + "'net dhcpv4 server status '\n" + " is the network interface index. Optional.", + cmd_net_dhcpv4_server_status, 1, 1), + SHELL_SUBCMD_SET_END +); + +SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_dhcpv4, + SHELL_CMD(server, &net_cmd_dhcpv4_server, + "DHCPv4 server service management.", + NULL), + SHELL_SUBCMD_SET_END +); + +SHELL_SUBCMD_ADD((net), dhcpv4, &net_cmd_dhcpv4, "Manage DHPCv4 services.", + NULL, 1, 0); From e537e00b1bc1325945dc9d29df13100d6ba2280a Mon Sep 17 00:00:00 2001 From: Kamil Piszczek Date: Fri, 12 Jan 2024 11:30:21 +0100 Subject: [PATCH 1111/1623] [nrf fromtree] bluetooth: gatt: add authorization callback API for gatt operations Added the GATT authorization callback API that allows the user to define application-specific authorization logic for GATT operations. Signed-off-by: Kamil Piszczek (cherry picked from commit 6852abf521ba3a56c2aa9fa21040d9341adb84bd) --- include/zephyr/bluetooth/gatt.h | 51 ++++++++++++++++++ subsys/bluetooth/host/Kconfig.gatt | 9 ++++ subsys/bluetooth/host/att.c | 83 ++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) diff --git a/include/zephyr/bluetooth/gatt.h b/include/zephyr/bluetooth/gatt.h index c53422648f0..eb38f765afb 100644 --- a/include/zephyr/bluetooth/gatt.h +++ b/include/zephyr/bluetooth/gatt.h @@ -235,6 +235,37 @@ struct bt_gatt_cb { sys_snode_t node; }; +/** @brief GATT authorization callback structure. */ +struct bt_gatt_authorization_cb { + /** @brief Authorize the GATT read operation. + * + * This callback allows the application to authorize the GATT + * read operation for the attribute that is being read. + * + * @param conn Connection object. + * @param attr The attribute that is being read. + * + * @retval true Authorize the operation and allow it to execute. + * @retval false Reject the operation and prevent it from executing. + */ + bool (*read_operation_authorize)(struct bt_conn *conn, + const struct bt_gatt_attr *attr); + + /** @brief Authorize the GATT write operation. + * + * This callback allows the application to authorize the GATT + * write operation for the attribute that is being written. + * + * @param conn Connection object. + * @param attr The attribute that is being written. + * + * @retval true Authorize the operation and allow it to execute. + * @retval false Reject the operation and prevent it from executing. + */ + bool (*write_operation_authorize)(struct bt_conn *conn, + const struct bt_gatt_attr *attr); +}; + /** Characteristic Properties Bit field values */ /** @@ -377,6 +408,26 @@ struct bt_gatt_cpf { */ void bt_gatt_cb_register(struct bt_gatt_cb *cb); +/** @brief Register GATT authorization callbacks. + * + * Register callbacks to perform application-specific authorization of GATT + * operations on all registered GATT attributes. The callback structure must + * remain valid throughout the entire duration of the Bluetooth subsys + * activity. + * + * The @kconfig{CONFIG_BT_GATT_AUTHORIZATION_CUSTOM} Kconfig must be enabled + * to make this API functional. + * + * This API allows the user to register only one callback structure + * concurrently. Passing NULL unregisters the previous set of callbacks + * and makes it possible to register a new one. + * + * @param cb Callback struct. + * + * @return Zero on success or negative error code otherwise + */ +int bt_gatt_authorization_cb_register(const struct bt_gatt_authorization_cb *cb); + /** @brief Register GATT service. * * Register GATT service. Applications can make use of diff --git a/subsys/bluetooth/host/Kconfig.gatt b/subsys/bluetooth/host/Kconfig.gatt index 9209368f943..a2364bbe557 100644 --- a/subsys/bluetooth/host/Kconfig.gatt +++ b/subsys/bluetooth/host/Kconfig.gatt @@ -276,4 +276,13 @@ config DEVICE_NAME_GATT_WRITABLE_AUTHEN endif #BT_DEVICE_NAME_GATT_WRITABLE +config BT_GATT_AUTHORIZATION_CUSTOM + bool "Custom authorization of GATT operations [EXPERIMENTAL]" + select EXPERIMENTAL + help + This option allows the user to define application-specific + authorization logic for GATT operations that can be registered + with the bt_gatt_authorization_cb_register API. See the API + documentation for more details. + endmenu diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index 130b4ab0853..44862f5bf25 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -115,6 +115,11 @@ static uint16_t bt_att_mtu(struct bt_att_chan *chan) return MIN(chan->chan.rx.mtu, chan->chan.tx.mtu); } +/* Descriptor of application-specific authorization callbacks that are used + * with the CONFIG_BT_GATT_AUTHORIZATION_CUSTOM Kconfig enabled. + */ +const static struct bt_gatt_authorization_cb *authorization_cb; + /* ATT connection specific data */ struct bt_att { struct bt_conn *conn; @@ -1289,6 +1294,20 @@ struct read_type_data { typedef bool (*attr_read_cb)(struct net_buf *buf, ssize_t read, void *user_data); +static bool attr_read_authorize(struct bt_conn *conn, + const struct bt_gatt_attr *attr) +{ + if (!IS_ENABLED(CONFIG_BT_GATT_AUTHORIZATION_CUSTOM)) { + return true; + } + + if (!authorization_cb || !authorization_cb->read_operation_authorize) { + return true; + } + + return authorization_cb->read_operation_authorize(conn, attr); +} + static bool attr_read_type_cb(struct net_buf *frag, ssize_t read, void *user_data) { @@ -1398,6 +1417,12 @@ static uint8_t read_type_cb(const struct bt_gatt_attr *attr, uint16_t handle, return BT_GATT_ITER_STOP; } + /* Check the attribute authorization logic */ + if (!attr_read_authorize(conn, attr)) { + data->err = BT_ATT_ERR_AUTHORIZATION; + return BT_GATT_ITER_STOP; + } + /* * If any attribute is founded in handle range it means that error * should be changed from pre-set: attr not found error to no error. @@ -1526,6 +1551,12 @@ static uint8_t read_cb(const struct bt_gatt_attr *attr, uint16_t handle, return BT_GATT_ITER_STOP; } + /* Check the attribute authorization logic */ + if (!attr_read_authorize(conn, attr)) { + data->err = BT_ATT_ERR_AUTHORIZATION; + return BT_GATT_ITER_STOP; + } + /* Read attribute value and store in the buffer */ ret = att_chan_read(chan, attr, data->buf, data->offset, NULL, NULL); if (ret < 0) { @@ -1693,6 +1724,12 @@ static uint8_t read_vl_cb(const struct bt_gatt_attr *attr, uint16_t handle, return BT_GATT_ITER_STOP; } + /* Check the attribute authorization logic */ + if (!attr_read_authorize(conn, attr)) { + data->err = BT_ATT_ERR_AUTHORIZATION; + return BT_GATT_ITER_STOP; + } + /* The Length Value Tuple List may be truncated within the first two * octets of a tuple due to the size limits of the current ATT_MTU. */ @@ -1940,6 +1977,20 @@ struct write_data { uint8_t err; }; +static bool attr_write_authorize(struct bt_conn *conn, + const struct bt_gatt_attr *attr) +{ + if (!IS_ENABLED(CONFIG_BT_GATT_AUTHORIZATION_CUSTOM)) { + return true; + } + + if (!authorization_cb || !authorization_cb->write_operation_authorize) { + return true; + } + + return authorization_cb->write_operation_authorize(conn, attr); +} + static uint8_t write_cb(const struct bt_gatt_attr *attr, uint16_t handle, void *user_data) { @@ -1956,6 +2007,12 @@ static uint8_t write_cb(const struct bt_gatt_attr *attr, uint16_t handle, return BT_GATT_ITER_STOP; } + /* Check the attribute authorization logic */ + if (!attr_write_authorize(data->conn, attr)) { + data->err = BT_ATT_ERR_AUTHORIZATION; + return BT_GATT_ITER_STOP; + } + /* Set command flag if not a request */ if (!data->req) { flags |= BT_GATT_WRITE_FLAG_CMD; @@ -2069,6 +2126,12 @@ static uint8_t prep_write_cb(const struct bt_gatt_attr *attr, uint16_t handle, return BT_GATT_ITER_STOP; } + /* Check the attribute authorization logic */ + if (!attr_write_authorize(data->conn, attr)) { + data->err = BT_ATT_ERR_AUTHORIZATION; + return BT_GATT_ITER_STOP; + } + /* Check if attribute requires handler to accept the data */ if (!(attr->perm & BT_GATT_PERM_PREPARE_WRITE)) { goto append; @@ -3997,3 +4060,23 @@ bool bt_att_chan_opt_valid(struct bt_conn *conn, enum bt_att_chan_opt chan_opt) return true; } + +int bt_gatt_authorization_cb_register(const struct bt_gatt_authorization_cb *cb) +{ + if (!IS_ENABLED(CONFIG_BT_GATT_AUTHORIZATION_CUSTOM)) { + return -ENOSYS; + } + + if (!cb) { + authorization_cb = NULL; + return 0; + } + + if (authorization_cb) { + return -EALREADY; + } + + authorization_cb = cb; + + return 0; +} From e4e6dc87bafd8f3e9c2562fc55dbfa4f8185b14b Mon Sep 17 00:00:00 2001 From: Kamil Piszczek Date: Tue, 16 Jan 2024 13:11:57 +0100 Subject: [PATCH 1112/1623] [nrf fromtree] tests: bsim: bluetooth: host: gatt: add authorization callback API test Added a new BabbleSim test that validates the authorization callback API from the Bluetooth GATT header. Signed-off-by: Kamil Piszczek (cherry picked from commit a369eb7b367f485bece73cd4973e531bf54cd27b) --- tests/bsim/bluetooth/host/compile.sh | 1 + .../host/gatt/authorization/CMakeLists.txt | 14 + .../host/gatt/authorization/prj.conf | 7 + .../host/gatt/authorization/src/common.c | 20 + .../host/gatt/authorization/src/common.h | 73 ++++ .../gatt/authorization/src/gatt_client_test.c | 341 ++++++++++++++++ .../gatt/authorization/src/gatt_server_test.c | 370 ++++++++++++++++++ .../host/gatt/authorization/src/main.c | 22 ++ .../gatt/authorization/test_scripts/gatt.sh | 22 ++ 9 files changed, 870 insertions(+) create mode 100644 tests/bsim/bluetooth/host/gatt/authorization/CMakeLists.txt create mode 100644 tests/bsim/bluetooth/host/gatt/authorization/prj.conf create mode 100644 tests/bsim/bluetooth/host/gatt/authorization/src/common.c create mode 100644 tests/bsim/bluetooth/host/gatt/authorization/src/common.h create mode 100644 tests/bsim/bluetooth/host/gatt/authorization/src/gatt_client_test.c create mode 100644 tests/bsim/bluetooth/host/gatt/authorization/src/gatt_server_test.c create mode 100644 tests/bsim/bluetooth/host/gatt/authorization/src/main.c create mode 100755 tests/bsim/bluetooth/host/gatt/authorization/test_scripts/gatt.sh diff --git a/tests/bsim/bluetooth/host/compile.sh b/tests/bsim/bluetooth/host/compile.sh index ff42fd27adf..098c983d75f 100755 --- a/tests/bsim/bluetooth/host/compile.sh +++ b/tests/bsim/bluetooth/host/compile.sh @@ -41,6 +41,7 @@ app=tests/bsim/bluetooth/host/att/sequential/dut compile app=tests/bsim/bluetooth/host/att/sequential/tester compile app=tests/bsim/bluetooth/host/att/long_read compile +app=tests/bsim/bluetooth/host/gatt/authorization compile app=tests/bsim/bluetooth/host/gatt/caching compile app=tests/bsim/bluetooth/host/gatt/general compile app=tests/bsim/bluetooth/host/gatt/notify compile diff --git a/tests/bsim/bluetooth/host/gatt/authorization/CMakeLists.txt b/tests/bsim/bluetooth/host/gatt/authorization/CMakeLists.txt new file mode 100644 index 00000000000..acb0dd45947 --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/authorization/CMakeLists.txt @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(bsim_test_gatt_authorization) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources} ) + +zephyr_include_directories( + ${BSIM_COMPONENTS_PATH}/libUtilv1/src/ + ${BSIM_COMPONENTS_PATH}/libPhyComv1/src/ + ) diff --git a/tests/bsim/bluetooth/host/gatt/authorization/prj.conf b/tests/bsim/bluetooth/host/gatt/authorization/prj.conf new file mode 100644 index 00000000000..9cba554afef --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/authorization/prj.conf @@ -0,0 +1,7 @@ +CONFIG_BT=y +CONFIG_BT_DEVICE_NAME="GATT tester" +CONFIG_BT_PERIPHERAL=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_GATT_CLIENT=y +CONFIG_BT_GATT_AUTHORIZATION_CUSTOM=y +CONFIG_BT_ATT_PREPARE_COUNT=3 diff --git a/tests/bsim/bluetooth/host/gatt/authorization/src/common.c b/tests/bsim/bluetooth/host/gatt/authorization/src/common.c new file mode 100644 index 00000000000..adff2dd05ef --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/authorization/src/common.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "common.h" + +void test_tick(bs_time_t HW_device_time) +{ + if (bst_result != Passed) { + FAIL("test failed (not passed after %i seconds)\n", WAIT_TIME); + } +} + +void test_init(void) +{ + bst_ticker_set_next_tick_absolute(WAIT_TIME); + bst_result = In_progress; +} diff --git a/tests/bsim/bluetooth/host/gatt/authorization/src/common.h b/tests/bsim/bluetooth/host/gatt/authorization/src/common.h new file mode 100644 index 00000000000..339919dfe88 --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/authorization/src/common.h @@ -0,0 +1,73 @@ +/** + * Common functions and helpers for BSIM GATT tests + * + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "bs_types.h" +#include "bs_tracing.h" +#include "time_machine.h" +#include "bstests.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +extern enum bst_result_t bst_result; + +#define WAIT_TIME (30 * 1e6) /*seconds*/ + +#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false +#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) +#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) +#define WAIT_FOR_FLAG(flag) \ + while (!(bool)atomic_get(&flag)) { \ + (void)k_sleep(K_MSEC(1)); \ + } + +#define FAIL(...) \ + do { \ + bst_result = Failed; \ + bs_trace_error_time_line(__VA_ARGS__); \ + } while (0) + +#define PASS(...) \ + do { \ + bst_result = Passed; \ + bs_trace_info_time(1, __VA_ARGS__); \ + } while (0) + +#define CHRC_SIZE 10 + +#define TEST_SERVICE_UUID \ + BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00) + +#define TEST_UNHANDLED_CHRC_UUID \ + BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFD, 0x00) + +#define TEST_UNAUTHORIZED_CHRC_UUID \ + BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFE, 0x00) + +#define TEST_AUTHORIZED_CHRC_UUID \ + BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0x00) + +#define TEST_CP_CHRC_UUID \ + BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xF0, 0x00) + +void test_tick(bs_time_t HW_device_time); +void test_init(void); diff --git a/tests/bsim/bluetooth/host/gatt/authorization/src/gatt_client_test.c b/tests/bsim/bluetooth/host/gatt/authorization/src/gatt_client_test.c new file mode 100644 index 00000000000..9c60c5b57b2 --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/authorization/src/gatt_client_test.c @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include "common.h" + +CREATE_FLAG(flag_is_connected); +CREATE_FLAG(flag_discover_complete); +CREATE_FLAG(flag_write_complete); +CREATE_FLAG(flag_read_complete); + +static struct bt_conn *g_conn; +static uint16_t unhandled_chrc_handle; +static uint16_t unauthorized_chrc_handle; +static uint16_t authorized_chrc_handle; +static uint16_t cp_chrc_handle; +static const struct bt_uuid *test_svc_uuid = TEST_SERVICE_UUID; + +#define ARRAY_ITEM(i, _) i +static uint8_t chrc_data[] = { LISTIFY(CHRC_SIZE, ARRAY_ITEM, (,)) }; /* 1, 2, 3 ... */ + +static void connected(struct bt_conn *conn, uint8_t err) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + if (err != 0) { + FAIL("Failed to connect to %s (%u)\n", addr, err); + return; + } + + printk("Connected to %s\n", addr); + + __ASSERT_NO_MSG(g_conn == conn); + + SET_FLAG(flag_is_connected); +} + +static void disconnected(struct bt_conn *conn, uint8_t reason) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + if (conn != g_conn) { + return; + } + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); + + bt_conn_unref(g_conn); + + g_conn = NULL; + UNSET_FLAG(flag_is_connected); +} + +BT_CONN_CB_DEFINE(conn_callbacks) = { + .connected = connected, + .disconnected = disconnected, +}; + +void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, + struct net_buf_simple *ad) +{ + char addr_str[BT_ADDR_LE_STR_LEN]; + int err; + + if (g_conn != NULL) { + return; + } + + /* We're only interested in connectable events */ + if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { + return; + } + + bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); + printk("Device found: %s (RSSI %d)\n", addr_str, rssi); + + printk("Stopping scan\n"); + err = bt_le_scan_stop(); + if (err != 0) { + FAIL("Could not stop scan: %d"); + return; + } + + err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, + BT_LE_CONN_PARAM_DEFAULT, &g_conn); + if (err != 0) { + FAIL("Could not connect to peer: %d", err); + } +} + +static uint8_t discover_func(struct bt_conn *conn, + const struct bt_gatt_attr *attr, + struct bt_gatt_discover_params *params) +{ + int err; + + if (attr == NULL) { + if (unhandled_chrc_handle == 0 || + unauthorized_chrc_handle == 0 || + authorized_chrc_handle == 0) { + FAIL("Did not discover required characterstics"); + } + + (void)memset(params, 0, sizeof(*params)); + + SET_FLAG(flag_discover_complete); + + return BT_GATT_ITER_STOP; + } + + printk("[ATTRIBUTE] handle %u\n", attr->handle); + + if (params->type == BT_GATT_DISCOVER_PRIMARY && + bt_uuid_cmp(params->uuid, TEST_SERVICE_UUID) == 0) { + printk("Found test service\n"); + params->uuid = NULL; + params->start_handle = attr->handle + 1; + params->type = BT_GATT_DISCOVER_CHARACTERISTIC; + + err = bt_gatt_discover(conn, params); + if (err != 0) { + FAIL("Discover failed (err %d)\n", err); + } + + return BT_GATT_ITER_STOP; + } else if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { + struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; + + if (bt_uuid_cmp(chrc->uuid, TEST_UNHANDLED_CHRC_UUID) == 0) { + printk("Found unhandled chrc\n"); + unhandled_chrc_handle = chrc->value_handle; + } else if (bt_uuid_cmp(chrc->uuid, TEST_UNAUTHORIZED_CHRC_UUID) == 0) { + printk("Found unauthorized\n"); + unauthorized_chrc_handle = chrc->value_handle; + } else if (bt_uuid_cmp(chrc->uuid, TEST_AUTHORIZED_CHRC_UUID) == 0) { + printk("Found authorized chrc\n"); + authorized_chrc_handle = chrc->value_handle; + } else if (bt_uuid_cmp(chrc->uuid, TEST_CP_CHRC_UUID) == 0) { + printk("Found CP chrc\n"); + cp_chrc_handle = chrc->value_handle; + } + } + + return BT_GATT_ITER_CONTINUE; +} + +static void gatt_discover(void) +{ + static struct bt_gatt_discover_params discover_params; + int err; + + printk("Discovering services and characteristics\n"); + + discover_params.uuid = test_svc_uuid; + discover_params.func = discover_func; + discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; + discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; + discover_params.type = BT_GATT_DISCOVER_PRIMARY; + + err = bt_gatt_discover(g_conn, &discover_params); + if (err != 0) { + FAIL("Discover failed(err %d)\n", err); + } + + WAIT_FOR_FLAG(flag_discover_complete); + printk("Discover complete\n"); +} + +static void gatt_write_cb(struct bt_conn *conn, uint8_t err, + struct bt_gatt_write_params *params) +{ + if ((err != BT_ATT_ERR_SUCCESS) && (params->handle != unauthorized_chrc_handle)) { + FAIL("Write failed on authorized characteristics: 0x%02X\n", err); + } + + if ((err != BT_ATT_ERR_AUTHORIZATION) && (params->handle == unauthorized_chrc_handle)) { + FAIL("Write failed on unauthorized characteristics: 0x%02X\n", err); + } + + (void)memset(params, 0, sizeof(*params)); + + SET_FLAG(flag_write_complete); +} + +static void gatt_write(uint16_t handle) +{ + static struct bt_gatt_write_params write_params; + int err; + + printk("Writing to chrc\n"); + + write_params.data = chrc_data; + write_params.length = sizeof(chrc_data); + write_params.func = gatt_write_cb; + write_params.handle = handle; + + UNSET_FLAG(flag_write_complete); + + err = bt_gatt_write(g_conn, &write_params); + if (err != 0) { + FAIL("bt_gatt_write failed: %d\n", err); + } + + WAIT_FOR_FLAG(flag_write_complete); + printk("success\n"); +} + +static void gatt_cp_write(void) +{ + static struct bt_gatt_write_params write_params; + int err; + uint8_t cp_write_data[] = {0x00}; + + printk("Writing to CP chrc\n"); + + write_params.data = cp_write_data; + write_params.length = sizeof(cp_write_data); + write_params.func = gatt_write_cb; + write_params.handle = cp_chrc_handle; + + UNSET_FLAG(flag_write_complete); + + err = bt_gatt_write(g_conn, &write_params); + if (err != 0) { + FAIL("bt_gatt_write failed: %d\n", err); + } + + WAIT_FOR_FLAG(flag_write_complete); + printk("success\n"); +} + +static uint8_t gatt_read_cb(struct bt_conn *conn, uint8_t err, + struct bt_gatt_read_params *params, + const void *data, uint16_t length) +{ + if ((err != BT_ATT_ERR_SUCCESS) && + (params->single.handle != unauthorized_chrc_handle)) { + FAIL("Read failed on authorized characteristics: 0x%02X\n", err); + + if ((length != CHRC_SIZE) || (memcmp(data, chrc_data, length) != 0)) { + FAIL("chrc data different than expected", err); + } + } + + if ((err != BT_ATT_ERR_AUTHORIZATION) && + (params->single.handle == unauthorized_chrc_handle)) { + FAIL("Read failed on unauthorized characteristics: 0x%02X\n", err); + } + + (void)memset(params, 0, sizeof(*params)); + + SET_FLAG(flag_read_complete); + + return 0; +} + +static void gatt_read(uint16_t handle) +{ + static struct bt_gatt_read_params read_params; + int err; + + printk("Reading chrc\n"); + + read_params.func = gatt_read_cb; + read_params.handle_count = 1; + read_params.single.handle = handle; + read_params.single.offset = 0; + + UNSET_FLAG(flag_read_complete); + + err = bt_gatt_read(g_conn, &read_params); + if (err != 0) { + FAIL("bt_gatt_read failed: %d\n", err); + } + + WAIT_FOR_FLAG(flag_read_complete); + printk("success\n"); +} + +static void gatt_interact(uint16_t handle) +{ + gatt_write(handle); + gatt_read(handle); + gatt_cp_write(); +} + +static void test_main(void) +{ + int err; + + err = bt_enable(NULL); + if (err != 0) { + FAIL("Bluetooth discover failed (err %d)\n", err); + } + + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + if (err != 0) { + FAIL("Scanning failed to start (err %d)\n", err); + } + + printk("Scanning successfully started\n"); + + WAIT_FOR_FLAG(flag_is_connected); + + gatt_discover(); + + printk("Interacting with the unhandled characteristic\n"); + gatt_interact(unhandled_chrc_handle); + + printk("Interacting with the unauthorized characteristic\n"); + gatt_interact(unauthorized_chrc_handle); + + printk("Interacting with the authorized characteristic\n"); + gatt_interact(authorized_chrc_handle); + + PASS("GATT client Passed\n"); +} + +static const struct bst_test_instance test_vcs[] = { + { + .test_id = "gatt_client", + .test_post_init_f = test_init, + .test_tick_f = test_tick, + .test_main_f = test_main + }, + BSTEST_END_MARKER +}; + +struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests) +{ + return bst_add_tests(tests, test_vcs); +} diff --git a/tests/bsim/bluetooth/host/gatt/authorization/src/gatt_server_test.c b/tests/bsim/bluetooth/host/gatt/authorization/src/gatt_server_test.c new file mode 100644 index 00000000000..d5dd5e0e0a7 --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/authorization/src/gatt_server_test.c @@ -0,0 +1,370 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "common.h" + +extern enum bst_result_t bst_result; + +CREATE_FLAG(flag_is_chrc_ctx_validated); + +static struct bt_conn *g_conn; + +static void connected(struct bt_conn *conn, uint8_t err) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + if (err != 0) { + FAIL("Failed to connect to %s (%u)\n", addr, err); + return; + } + + printk("Connected to %s\n", addr); + + g_conn = bt_conn_ref(conn); +} + +static void disconnected(struct bt_conn *conn, uint8_t reason) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + if (conn != g_conn) { + return; + } + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); + + bt_conn_unref(g_conn); + + g_conn = NULL; +} + +BT_CONN_CB_DEFINE(conn_callbacks) = { + .connected = connected, + .disconnected = disconnected, +}; + +struct test_chrc_ctx { + uint16_t auth_read_cnt; + uint16_t read_cnt; + uint16_t auth_write_cnt; + uint16_t write_cnt; + uint8_t data[CHRC_SIZE]; +}; + +static ssize_t read_test_chrc(struct test_chrc_ctx *chrc_ctx, + struct bt_conn *conn, + const struct bt_gatt_attr *attr, + void *buf, uint16_t len, uint16_t offset) +{ + chrc_ctx->read_cnt++; + + return bt_gatt_attr_read(conn, attr, buf, len, offset, + (void *)chrc_ctx->data, + sizeof(chrc_ctx->data)); +} + +static ssize_t write_test_chrc(struct test_chrc_ctx *chrc_ctx, + const void *buf, uint16_t len, + uint16_t offset, uint8_t flags) +{ + chrc_ctx->write_cnt++; + + if (len != sizeof(chrc_ctx->data)) { + printk("Invalid chrc length\n"); + return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); + } + + if (offset != 0) { + printk("Invalid chrc offset and length\n"); + return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); + } + + if (flags != 0) { + FAIL("Invalid flags %u\n", flags); + return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); + } + + (void)memcpy(chrc_ctx->data, buf, len); + + return len; +} + +static struct test_chrc_ctx unhandled_chrc_ctx; + +static ssize_t read_test_unhandled_chrc(struct bt_conn *conn, + const struct bt_gatt_attr *attr, + void *buf, uint16_t len, uint16_t offset) +{ + return read_test_chrc(&unhandled_chrc_ctx, conn, attr, buf, len, offset); +} + +static ssize_t write_test_unhandled_chrc(struct bt_conn *conn, + const struct bt_gatt_attr *attr, + const void *buf, uint16_t len, + uint16_t offset, uint8_t flags) +{ + printk("unhandled chrc len %u offset %u\n", len, offset); + + return write_test_chrc(&unhandled_chrc_ctx, buf, len, offset, flags); +} + +static struct test_chrc_ctx unauthorized_chrc_ctx; + +static ssize_t read_test_unauthorized_chrc(struct bt_conn *conn, + const struct bt_gatt_attr *attr, + void *buf, uint16_t len, uint16_t offset) +{ + return read_test_chrc(&unauthorized_chrc_ctx, conn, attr, buf, len, offset); +} + +static ssize_t write_test_unauthorized_chrc(struct bt_conn *conn, + const struct bt_gatt_attr *attr, + const void *buf, uint16_t len, + uint16_t offset, uint8_t flags) +{ + printk("unauthorized chrc len %u offset %u\n", len, offset); + + return write_test_chrc(&unauthorized_chrc_ctx, buf, len, offset, flags); +} + +static struct test_chrc_ctx authorized_chrc_ctx; + +static ssize_t read_test_authorized_chrc(struct bt_conn *conn, + const struct bt_gatt_attr *attr, + void *buf, uint16_t len, uint16_t offset) +{ + return read_test_chrc(&authorized_chrc_ctx, conn, attr, buf, len, offset); +} + +static ssize_t write_test_authorized_chrc(struct bt_conn *conn, + const struct bt_gatt_attr *attr, + const void *buf, uint16_t len, + uint16_t offset, uint8_t flags) +{ + printk("authorized chrc len %u offset %u\n", len, offset); + + return write_test_chrc(&authorized_chrc_ctx, buf, len, offset, flags); +} + +static const struct test_chrc_ctx zeroed_chrc_ctx; + +static bool unhandled_chrc_operation_validate(void) +{ + if (memcmp(&unauthorized_chrc_ctx, &zeroed_chrc_ctx, sizeof(zeroed_chrc_ctx)) != 0) { + return false; + } + + if (memcmp(&authorized_chrc_ctx, &zeroed_chrc_ctx, sizeof(zeroed_chrc_ctx)) != 0) { + return false; + } + + if ((unhandled_chrc_ctx.read_cnt != 1) && (unhandled_chrc_ctx.write_cnt != 1)) { + return false; + } + + if ((unhandled_chrc_ctx.auth_read_cnt != 0) && + (unhandled_chrc_ctx.auth_write_cnt != 0)) { + return false; + } + + return true; +} + +static bool unauthorized_chrc_operation_validate(void) +{ + if (memcmp(&unhandled_chrc_ctx, &zeroed_chrc_ctx, sizeof(zeroed_chrc_ctx)) != 0) { + return false; + } + + if (memcmp(&authorized_chrc_ctx, &zeroed_chrc_ctx, sizeof(zeroed_chrc_ctx)) != 0) { + return false; + } + + if ((unauthorized_chrc_ctx.read_cnt != 0) && (unauthorized_chrc_ctx.write_cnt != 0)) { + return false; + } + + if ((unauthorized_chrc_ctx.auth_read_cnt != 1) && + (unauthorized_chrc_ctx.auth_write_cnt != 1)) { + return false; + } + + return true; +} + +static bool authorized_chrc_operation_validate(void) +{ + if (memcmp(&unhandled_chrc_ctx, &zeroed_chrc_ctx, sizeof(zeroed_chrc_ctx)) != 0) { + return false; + } + + if (memcmp(&unauthorized_chrc_ctx, &zeroed_chrc_ctx, sizeof(zeroed_chrc_ctx)) != 0) { + return false; + } + + if ((authorized_chrc_ctx.read_cnt != 1) && (authorized_chrc_ctx.write_cnt != 1)) { + return false; + } + + if ((authorized_chrc_ctx.auth_read_cnt != 1) && + (authorized_chrc_ctx.auth_write_cnt != 1)) { + return false; + } + + return true; +} + +static ssize_t write_cp_chrc(struct bt_conn *conn, + const struct bt_gatt_attr *attr, + const void *buf, uint16_t len, + uint16_t offset, uint8_t flags) +{ + static uint16_t cp_write_cnt; + bool pass; + char *log_str; + + if (cp_write_cnt == 0) { + pass = unhandled_chrc_operation_validate(); + log_str = "unhandled"; + } else if (cp_write_cnt == 1) { + pass = unauthorized_chrc_operation_validate(); + log_str = "unauthorized"; + } else if (cp_write_cnt == 2) { + pass = authorized_chrc_operation_validate(); + log_str = "authorized"; + } else { + FAIL("Invalid value of CP write counter %u\n", cp_write_cnt); + return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); + } + + if (pass) { + printk("Correct context for %s chrc\n", log_str); + } else { + FAIL("Invalid context for %s chrc\n", log_str); + return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); + } + + memset(&unhandled_chrc_ctx, 0, sizeof(unhandled_chrc_ctx)); + memset(&unauthorized_chrc_ctx, 0, sizeof(unauthorized_chrc_ctx)); + memset(&authorized_chrc_ctx, 0, sizeof(authorized_chrc_ctx)); + + cp_write_cnt++; + + if (cp_write_cnt == 3) { + SET_FLAG(flag_is_chrc_ctx_validated); + } + + return len; +} + +BT_GATT_SERVICE_DEFINE(test_svc, + BT_GATT_PRIMARY_SERVICE(TEST_SERVICE_UUID), + BT_GATT_CHARACTERISTIC(TEST_UNHANDLED_CHRC_UUID, + BT_GATT_CHRC_WRITE | BT_GATT_CHRC_READ, + BT_GATT_PERM_WRITE | BT_GATT_PERM_READ, + read_test_unhandled_chrc, + write_test_unhandled_chrc, NULL), + BT_GATT_CHARACTERISTIC(TEST_UNAUTHORIZED_CHRC_UUID, + BT_GATT_CHRC_WRITE | BT_GATT_CHRC_READ, + BT_GATT_PERM_WRITE | BT_GATT_PERM_READ, + read_test_unauthorized_chrc, + write_test_unauthorized_chrc, NULL), + BT_GATT_CHARACTERISTIC(TEST_AUTHORIZED_CHRC_UUID, + BT_GATT_CHRC_WRITE | BT_GATT_CHRC_READ, + BT_GATT_PERM_WRITE | BT_GATT_PERM_READ, + read_test_authorized_chrc, + write_test_authorized_chrc, NULL), + BT_GATT_CHARACTERISTIC(TEST_CP_CHRC_UUID, + BT_GATT_CHRC_WRITE, + BT_GATT_PERM_WRITE, + NULL, write_cp_chrc, NULL), +); + +static bool gatt_read_operation_authorize(struct bt_conn *conn, + const struct bt_gatt_attr *attr) +{ + if (bt_uuid_cmp(attr->uuid, TEST_UNAUTHORIZED_CHRC_UUID) == 0) { + unauthorized_chrc_ctx.auth_read_cnt++; + return false; + } else if (bt_uuid_cmp(attr->uuid, TEST_AUTHORIZED_CHRC_UUID) == 0) { + authorized_chrc_ctx.auth_read_cnt++; + return true; + } else { + return true; + } +} + +static bool gatt_write_operation_authorize(struct bt_conn *conn, + const struct bt_gatt_attr *attr) +{ + if (bt_uuid_cmp(attr->uuid, TEST_UNAUTHORIZED_CHRC_UUID) == 0) { + unauthorized_chrc_ctx.auth_write_cnt++; + return false; + } else if (bt_uuid_cmp(attr->uuid, TEST_AUTHORIZED_CHRC_UUID) == 0) { + authorized_chrc_ctx.auth_write_cnt++; + return true; + } else { + return true; + } +} + +static const struct bt_gatt_authorization_cb gatt_authorization_callbacks = { + .read_operation_authorize = gatt_read_operation_authorize, + .write_operation_authorize = gatt_write_operation_authorize, +}; + +static void test_main(void) +{ + int err; + const struct bt_data ad[] = { + BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)) + }; + + err = bt_gatt_authorization_cb_register(&gatt_authorization_callbacks); + if (err) { + FAIL("Registering GATT authorization callbacks failed (err %d)\n", err); + return; + } + + err = bt_enable(NULL); + if (err != 0) { + FAIL("Bluetooth init failed (err %d)\n", err); + return; + } + + printk("Bluetooth initialized\n"); + + err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); + if (err != 0) { + FAIL("Advertising failed to start (err %d)\n", err); + return; + } + + printk("Advertising successfully started\n"); + + WAIT_FOR_FLAG(flag_is_chrc_ctx_validated); + + PASS("GATT server passed\n"); +} + +static const struct bst_test_instance test_gatt_server[] = { + { + .test_id = "gatt_server", + .test_post_init_f = test_init, + .test_tick_f = test_tick, + .test_main_f = test_main + }, + BSTEST_END_MARKER +}; + +struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests) +{ + return bst_add_tests(tests, test_gatt_server); +} diff --git a/tests/bsim/bluetooth/host/gatt/authorization/src/main.c b/tests/bsim/bluetooth/host/gatt/authorization/src/main.c new file mode 100644 index 00000000000..a95f0285e75 --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/authorization/src/main.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "bstests.h" + +extern struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests); +extern struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests); + +bst_test_install_t test_installers[] = { + test_gatt_server_install, + test_gatt_client_install, + NULL +}; + +int main(void) +{ + bst_main(); + return 0; +} diff --git a/tests/bsim/bluetooth/host/gatt/authorization/test_scripts/gatt.sh b/tests/bsim/bluetooth/host/gatt/authorization/test_scripts/gatt.sh new file mode 100755 index 00000000000..edad0eb86c9 --- /dev/null +++ b/tests/bsim/bluetooth/host/gatt/authorization/test_scripts/gatt.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# Copyright 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + +simulation_id="gatt_authorization" +verbosity_level=2 +EXECUTE_TIMEOUT=120 + +cd ${BSIM_OUT_PATH}/bin + +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_authorization_prj_conf \ + -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=gatt_client + +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_authorization_prj_conf \ + -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=gatt_server + +Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ + -D=2 -sim_length=60e6 $@ + +wait_for_background_jobs From 0f41950fd18eaa6125d2041ed2525a5aa27397ea Mon Sep 17 00:00:00 2001 From: Ajay Parida Date: Thu, 11 Jan 2024 12:36:15 +0530 Subject: [PATCH 1113/1623] [nrf fromtree] net: mgmt: Update app of TWT teardown status Update user/app status of TWT teardown sessions. Signed-off-by: Ajay Parida (cherry picked from commit 3053484dcb646066fe738050d9d5e4c314f1235f) --- include/zephyr/net/wifi.h | 8 ++++++++ include/zephyr/net/wifi_mgmt.h | 2 ++ subsys/net/l2/wifi/wifi_shell.c | 9 +++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/zephyr/net/wifi.h b/include/zephyr/net/wifi.h index 5c7d5b493fa..c49d6ad0f66 100644 --- a/include/zephyr/net/wifi.h +++ b/include/zephyr/net/wifi.h @@ -345,6 +345,14 @@ enum wifi_twt_fail_reason { WIFI_TWT_FAIL_FLOW_ALREADY_EXISTS, }; +/** Wi-Fi Target Wake Time (TWT) teradown status. */ +enum wifi_twt_teardown_status { + /** TWT teardown success */ + WIFI_TWT_TEARDOWN_SUCCESS = 0, + /** TWT teardown failure */ + WIFI_TWT_TEARDOWN_FAILED, +}; + /** @cond INTERNAL_HIDDEN */ static const char * const wifi_twt_err_code_tbl[] = { [WIFI_TWT_FAIL_UNSPECIFIED] = "Unspecified", diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index f6ae631a830..0c64cab3c01 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -470,6 +470,8 @@ struct wifi_twt_params { enum wifi_twt_setup_cmd setup_cmd; /** TWT setup response status, see enum wifi_twt_setup_resp_status */ enum wifi_twt_setup_resp_status resp_status; + /** TWT teardown cmd status, see enum wifi_twt_teardown_status */ + enum wifi_twt_teardown_status teardown_status; /** Dialog token, used to map requests to responses */ uint8_t dialog_token; /** Flow ID, used to map setup with teardown */ diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 1f13ae864ae..44f507f6e02 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -293,8 +293,13 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) (const struct wifi_twt_params *)cb->info; if (resp->operation == WIFI_TWT_TEARDOWN) { - print(context.sh, SHELL_NORMAL, "TWT teardown received for flow ID %d\n", - resp->flow_id); + if (resp->teardown_status == WIFI_TWT_TEARDOWN_SUCCESS) { + print(context.sh, SHELL_NORMAL, "TWT teardown received for flow ID %d\n", + resp->flow_id); + } else { + print(context.sh, SHELL_NORMAL, "TWT teardown failed for flow ID %d\n", + resp->flow_id); + } return; } From 8f02d6eeec4b4b0a8aebfceca05f1a029b8b08a0 Mon Sep 17 00:00:00 2001 From: Ajay Parida Date: Wed, 17 Jan 2024 14:49:00 +0530 Subject: [PATCH 1114/1623] [nrf fromtree] net: mgmt: Print correct TWT teardown status message Print success message for TWT teardown successful case. Signed-off-by: Ajay Parida (cherry picked from commit 4d854a193e4958659669afadad621f86636b0bff) --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 44f507f6e02..70b4f96d861 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -294,7 +294,7 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) if (resp->operation == WIFI_TWT_TEARDOWN) { if (resp->teardown_status == WIFI_TWT_TEARDOWN_SUCCESS) { - print(context.sh, SHELL_NORMAL, "TWT teardown received for flow ID %d\n", + print(context.sh, SHELL_NORMAL, "TWT teardown succeeded for flow ID %d\n", resp->flow_id); } else { print(context.sh, SHELL_NORMAL, "TWT teardown failed for flow ID %d\n", From bca3722d75202fdbe6c7d8dcc546ad90f1c03895 Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Mon, 22 Jan 2024 08:39:32 +0100 Subject: [PATCH 1115/1623] [nrf fromtree] net: openthread: Regular openthread upmerge to `00076af` Regular upmerge. Signed-off-by: Przemyslaw Bida (cherry picked from commit f661aa7641ef4e9561ec9d7f654afbe7d7669f2e) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index b9a84545850..2892d3db451 100644 --- a/west.yml +++ b/west.yml @@ -301,7 +301,7 @@ manifest: revision: 214f9fc1539f8e5937c0474cb6ee29b6dcb2d4b8 path: modules/lib/open-amp - name: openthread - revision: 4ed44bc7d58d9a98c6cca13a50d38129045ab3df + revision: 00076aff3ae571db7c90509ec9dc293457098c35 path: modules/lib/openthread - name: percepio path: modules/debug/percepio From 0c16a9a6fa8163a6166955124f7ab6a32217377e Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Thu, 11 Jan 2024 12:25:18 +0100 Subject: [PATCH 1116/1623] [nrf fromtree] net: openthread: Fix key import in case of ECDSA. According to PSA specification in case of `PSA_KEY_TYPE_ECC_KEY_PAIR` function `psa_import_key` takes private key from key pair as argument. This commit adds extraction of Private key from ECDSA key pair. Also removes not needed `otPlatCryptoEcdsaGetPublicKey`. Signed-off-by: Przemyslaw Bida (cherry picked from commit a6184b9be3d14166c21827b3540cec6514fafe12) --- modules/openthread/platform/crypto_psa.c | 114 +++++++++++------------ 1 file changed, 52 insertions(+), 62 deletions(-) diff --git a/modules/openthread/platform/crypto_psa.c b/modules/openthread/platform/crypto_psa.c index 55018254154..c818c5695a3 100644 --- a/modules/openthread/platform/crypto_psa.c +++ b/modules/openthread/platform/crypto_psa.c @@ -16,6 +16,7 @@ #if defined(CONFIG_OPENTHREAD_ECDSA) #include +#include #endif static otError psaToOtError(psa_status_t aStatus) @@ -62,7 +63,7 @@ static psa_algorithm_t toPsaAlgorithm(otCryptoKeyAlgorithm aAlgorithm) * There is currently no constant like PSA_ALG_NONE, but 0 is used * to indicate an unknown algorithm. */ - return (psa_algorithm_t) 0; + return (psa_algorithm_t)0; } } @@ -96,11 +97,9 @@ static psa_key_usage_t toPsaKeyUsage(int aUsage) static bool checkKeyUsage(int aUsage) { /* Check if only supported flags have been passed */ - int supported_flags = OT_CRYPTO_KEY_USAGE_EXPORT | - OT_CRYPTO_KEY_USAGE_ENCRYPT | - OT_CRYPTO_KEY_USAGE_DECRYPT | - OT_CRYPTO_KEY_USAGE_SIGN_HASH | - OT_CRYPTO_KEY_USAGE_VERIFY_HASH; + int supported_flags = OT_CRYPTO_KEY_USAGE_EXPORT | OT_CRYPTO_KEY_USAGE_ENCRYPT | + OT_CRYPTO_KEY_USAGE_DECRYPT | OT_CRYPTO_KEY_USAGE_SIGN_HASH | + OT_CRYPTO_KEY_USAGE_VERIFY_HASH; return (aUsage & ~supported_flags) == 0; } @@ -121,26 +120,57 @@ void otPlatCryptoInit(void) * PSA with emulated TFM, Settings have to be initialized at the end of otPlatCryptoInit(), * to be available before storing Network Key. */ - __ASSERT_EVAL((void) settings_subsys_init(), int err = settings_subsys_init(), - !err, "Failed to initialize settings"); + __ASSERT_EVAL((void)settings_subsys_init(), int err = settings_subsys_init(), !err, + "Failed to initialize settings"); #endif } -otError otPlatCryptoImportKey(otCryptoKeyRef *aKeyRef, - otCryptoKeyType aKeyType, - otCryptoKeyAlgorithm aKeyAlgorithm, - int aKeyUsage, - otCryptoKeyStorage aKeyPersistence, - const uint8_t *aKey, +otError otPlatCryptoImportKey(otCryptoKeyRef *aKeyRef, otCryptoKeyType aKeyType, + otCryptoKeyAlgorithm aKeyAlgorithm, int aKeyUsage, + otCryptoKeyStorage aKeyPersistence, const uint8_t *aKey, size_t aKeyLen) { +#if defined(CONFIG_OPENTHREAD_ECDSA) + int version; + size_t len; + unsigned char *p = (unsigned char *)aKey; + unsigned char *end; +#endif + psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_status_t status; + psa_status_t status = 0; if (aKeyRef == NULL || aKey == NULL || !checkKeyUsage(aKeyUsage)) { return OT_ERROR_INVALID_ARGS; } +#if defined(CONFIG_OPENTHREAD_ECDSA) + /* Check if key is ECDSA pair and extract private key from it since PSA expects it. */ + if (aKeyType == OT_CRYPTO_KEY_TYPE_ECDSA) { + + end = p + aKeyLen; + status = mbedtls_asn1_get_tag(&p, end, &len, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE); + if (status != 0) { + return OT_ERROR_FAILED; + } + + end = p + len; + status = mbedtls_asn1_get_int(&p, end, &version); + if (status != 0) { + return OT_ERROR_FAILED; + } + + status = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING); + if (status != 0 || len != 32) { + return OT_ERROR_FAILED; + } + + aKey = p; + aKeyLen = len; + } +#endif + psa_set_key_type(&attributes, toPsaKeyType(aKeyType)); psa_set_key_algorithm(&attributes, toPsaAlgorithm(aKeyAlgorithm)); psa_set_key_usage_flags(&attributes, toPsaKeyUsage(aKeyUsage)); @@ -161,9 +191,7 @@ otError otPlatCryptoImportKey(otCryptoKeyRef *aKeyRef, return psaToOtError(status); } -otError otPlatCryptoExportKey(otCryptoKeyRef aKeyRef, - uint8_t *aBuffer, - size_t aBufferLen, +otError otPlatCryptoExportKey(otCryptoKeyRef aKeyRef, uint8_t *aBuffer, size_t aBufferLen, size_t *aKeyLen) { if (aBuffer == NULL) { @@ -231,8 +259,7 @@ otError otPlatCryptoHmacSha256Start(otCryptoContext *aContext, const otCryptoKey return psaToOtError(status); } -otError otPlatCryptoHmacSha256Update(otCryptoContext *aContext, - const void *aBuf, +otError otPlatCryptoHmacSha256Update(otCryptoContext *aContext, const void *aBuf, uint16_t aBufLength) { psa_mac_operation_t *operation; @@ -243,7 +270,7 @@ otError otPlatCryptoHmacSha256Update(otCryptoContext *aContext, operation = aContext->mContext; - return psaToOtError(psa_mac_update(operation, (const uint8_t *) aBuf, aBufLength)); + return psaToOtError(psa_mac_update(operation, (const uint8_t *)aBuf, aBufLength)); } otError otPlatCryptoHmacSha256Finish(otCryptoContext *aContext, uint8_t *aBuf, size_t aBufLength) @@ -269,7 +296,7 @@ otError otPlatCryptoAesInit(otCryptoContext *aContext) } key_ref = aContext->mContext; - *key_ref = (psa_key_id_t) 0; /* In TF-M 1.5.0 this can be replaced with PSA_KEY_ID_NULL */ + *key_ref = (psa_key_id_t)0; /* In TF-M 1.5.0 this can be replaced with PSA_KEY_ID_NULL */ return OT_ERROR_NONE; } @@ -300,13 +327,8 @@ otError otPlatCryptoAesEncrypt(otCryptoContext *aContext, const uint8_t *aInput, } key_ref = aContext->mContext; - status = psa_cipher_encrypt(*key_ref, - PSA_ALG_ECB_NO_PADDING, - aInput, - block_size, - aOutput, - block_size, - &cipher_length); + status = psa_cipher_encrypt(*key_ref, PSA_ALG_ECB_NO_PADDING, aInput, block_size, aOutput, + block_size, &cipher_length); return psaToOtError(status); } @@ -366,7 +388,7 @@ otError otPlatCryptoSha256Update(otCryptoContext *aContext, const void *aBuf, ui operation = aContext->mContext; - return psaToOtError(psa_hash_update(operation, (const uint8_t *) aBuf, aBufLength)); + return psaToOtError(psa_hash_update(operation, (const uint8_t *)aBuf, aBufLength)); } otError otPlatCryptoSha256Finish(otCryptoContext *aContext, uint8_t *aHash, uint16_t aHashSize) @@ -430,38 +452,6 @@ otError otPlatCryptoEcdsaGenerateKey(otPlatCryptoEcdsaKeyPair *aKeyPair) return psaToOtError(status); } -otError otPlatCryptoEcdsaGetPublicKey(const otPlatCryptoEcdsaKeyPair *aKeyPair, - otPlatCryptoEcdsaPublicKey *aPublicKey) -{ - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_key_id_t key_id = 0; - psa_status_t status; - size_t exported_length; - uint8_t buffer[1 + OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE]; - - psa_set_key_algorithm(&attributes, PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256)); - psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1)); - psa_set_key_bits(&attributes, 256); - - status = psa_import_key(&attributes, aKeyPair->mDerBytes, aKeyPair->mDerLength, &key_id); - if (status != PSA_SUCCESS) { - goto out; - } - - status = psa_export_public_key(key_id, buffer, sizeof(buffer), &exported_length); - if (status != PSA_SUCCESS) { - goto out; - } - __ASSERT_NO_MSG(exported_length == sizeof(buffer)); - memcpy(aPublicKey->m8, buffer + 1, OT_CRYPTO_ECDSA_PUBLIC_KEY_SIZE); - -out: - psa_reset_key_attributes(&attributes); - psa_destroy_key(key_id); - - return psaToOtError(status); -} - otError otPlatCryptoEcdsaSign(const otPlatCryptoEcdsaKeyPair *aKeyPair, const otPlatCryptoSha256Hash *aHash, otPlatCryptoEcdsaSignature *aSignature) From e79378647820cd929411c0da58df5ede8075f1ec Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 8 Jan 2024 12:03:29 +0100 Subject: [PATCH 1117/1623] [nrf fromtree] Bluetooth: BAP: Add support for transparent coding format Add support for controlling whether the local controller should transcode, or whether it will be done by another module (e.g. the host). By default when using the macros, controller transcoding will be disabled. Signed-off-by: Emil Gydesen (cherry picked from commit 1faa5a2aa2a2c134f21e4a7dc62a374eaa5d7664) Signed-off-by: Jui-Chou Chung --- include/zephyr/bluetooth/audio/audio.h | 14 ++++++++++++++ subsys/bluetooth/audio/bap_stream.c | 22 ++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/zephyr/bluetooth/audio/audio.h b/include/zephyr/bluetooth/audio/audio.h index 17bac991f18..03f451a3c8b 100644 --- a/include/zephyr/bluetooth/audio/audio.h +++ b/include/zephyr/bluetooth/audio/audio.h @@ -209,6 +209,7 @@ enum bt_audio_metadata_type { ((struct bt_audio_codec_cfg){ \ /* Use HCI data path as default, can be overwritten by application */ \ .path_id = BT_ISO_DATA_PATH_HCI, \ + .ctlr_transcode = false, \ .id = _id, \ .cid = _cid, \ .vid = _vid, \ @@ -231,6 +232,7 @@ enum bt_audio_metadata_type { ((struct bt_audio_codec_cap){ \ /* Use HCI data path as default, can be overwritten by application */ \ .path_id = BT_ISO_DATA_PATH_HCI, \ + .ctlr_transcode = false, \ .id = (_id), \ .cid = (_cid), \ .vid = (_vid), \ @@ -316,6 +318,12 @@ struct bt_audio_codec_cap { * vendor specific ID. */ uint8_t path_id; + /** Whether or not the local controller should transcode + * + * This effectively sets the coding format for the ISO data path to @ref + * BT_HCI_CODING_FORMAT_TRANSPARENT if false, else uses the @ref bt_audio_codec_cfg.id. + */ + bool ctlr_transcode; /** Codec ID */ uint8_t id; /** Codec Company ID */ @@ -344,6 +352,12 @@ struct bt_audio_codec_cfg { * vendor specific ID. */ uint8_t path_id; + /** Whether or not the local controller should transcode + * + * This effectively sets the coding format for the ISO data path to @ref + * BT_HCI_CODING_FORMAT_TRANSPARENT if false, else uses the @ref bt_audio_codec_cfg.id. + */ + bool ctlr_transcode; /** Codec ID */ uint8_t id; /** Codec Company ID */ diff --git a/subsys/bluetooth/audio/bap_stream.c b/subsys/bluetooth/audio/bap_stream.c index 23e5bb8564b..6dae679ddef 100644 --- a/subsys/bluetooth/audio/bap_stream.c +++ b/subsys/bluetooth/audio/bap_stream.c @@ -35,12 +35,22 @@ void bt_audio_codec_cfg_to_iso_path(struct bt_iso_chan_path *path, struct bt_audio_codec_cfg *codec_cfg) { path->pid = codec_cfg->path_id; - path->format = codec_cfg->id; - path->cid = codec_cfg->cid; - path->vid = codec_cfg->vid; - path->delay = 0; /* TODO: Add to bt_audio_codec_cfg? Use presentation delay? */ - path->cc_len = codec_cfg->data_len; - path->cc = codec_cfg->data; + + if (codec_cfg->ctlr_transcode) { + path->format = codec_cfg->id; + path->cid = codec_cfg->cid; + path->vid = codec_cfg->vid; + path->delay = 0; + path->cc_len = codec_cfg->data_len; + path->cc = codec_cfg->data; + } else { + path->format = BT_HCI_CODING_FORMAT_TRANSPARENT; + path->cid = 0; + path->vid = 0; + path->delay = 0; + path->cc_len = 0; + path->cc = NULL; + } } #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) || defined(CONFIG_BT_BAP_BROADCAST_SOURCE) || \ From efade47773f7a119b9576a168e1e5c59ceb2c3d3 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 19 Jan 2024 13:13:08 +0100 Subject: [PATCH 1118/1623] [nrf fromtree] Bluetooth: BAP: Fix issue with setting invalid iso data path BAP would always set up the ISO data path in both directions, even for unidirectional CIS. This meant that in the unconfigured direction, the data path configuration data would all be 0, which causes issues on some controllers. The new refactored approach implemented by this commit will always ensure that the data path is setup correctly, and that we only set the data path in one direction for unidirectional CIS. The unset path will use the default ISO path of HCI and transparant format, which should always be allowed by a controller. This is building on the requirement in BAP that all streams in a unicast group shall be QoS configured at the same time. This ensures that before any streams in the CIG has been connected, they have all been configured. Signed-off-by: Emil Gydesen (cherry picked from commit aef39f69239bf2c4f2e07c11171d1d3ad896ad4f) Signed-off-by: Jui-Chou Chung --- subsys/bluetooth/audio/ascs.c | 6 +-- subsys/bluetooth/audio/bap_broadcast_sink.c | 2 +- subsys/bluetooth/audio/bap_broadcast_source.c | 4 +- subsys/bluetooth/audio/bap_iso.c | 48 +++++++++++++++---- subsys/bluetooth/audio/bap_iso.h | 1 + subsys/bluetooth/audio/bap_stream.c | 22 --------- subsys/bluetooth/audio/bap_stream.h | 2 - subsys/bluetooth/audio/bap_unicast_client.c | 13 +---- 8 files changed, 46 insertions(+), 52 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 116071d4c0f..6df91e5f43e 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -1820,11 +1820,7 @@ static int ase_stream_qos(struct bt_bap_stream *stream, struct bt_audio_codec_qo * we have the ISO <-> EP coupling completed (due to setting * the CIS ID in the QoS procedure). */ - if (ep->dir == BT_AUDIO_DIR_SINK) { - bt_audio_codec_cfg_to_iso_path(&ep->iso->rx.path, stream->codec_cfg); - } else { - bt_audio_codec_cfg_to_iso_path(&ep->iso->tx.path, stream->codec_cfg); - } + bt_bap_iso_configure_data_path(ep, stream->codec_cfg); ep->cig_id = cig_id; ep->cis_id = cis_id; diff --git a/subsys/bluetooth/audio/bap_broadcast_sink.c b/subsys/bluetooth/audio/bap_broadcast_sink.c index 4d2134455b8..aa4bc08f761 100644 --- a/subsys/bluetooth/audio/bap_broadcast_sink.c +++ b/subsys/bluetooth/audio/bap_broadcast_sink.c @@ -764,7 +764,7 @@ static int bt_bap_broadcast_sink_setup_stream(struct bt_bap_broadcast_sink *sink bt_bap_iso_bind_ep(iso, ep); bt_audio_codec_qos_to_iso_qos(iso->chan.qos->rx, &sink->codec_qos); - bt_audio_codec_cfg_to_iso_path(iso->chan.qos->rx->path, codec_cfg); + bt_bap_iso_configure_data_path(ep, codec_cfg); bt_bap_iso_unref(iso); diff --git a/subsys/bluetooth/audio/bap_broadcast_source.c b/subsys/bluetooth/audio/bap_broadcast_source.c index 8978e2816cb..33fd1f0e17d 100644 --- a/subsys/bluetooth/audio/bap_broadcast_source.c +++ b/subsys/bluetooth/audio/bap_broadcast_source.c @@ -288,7 +288,7 @@ static int broadcast_source_setup_stream(uint8_t index, struct bt_bap_stream *st bt_bap_iso_bind_ep(iso, ep); bt_audio_codec_qos_to_iso_qos(iso->chan.qos->tx, qos); - bt_audio_codec_cfg_to_iso_path(iso->chan.qos->tx->path, codec_cfg); + bt_bap_iso_configure_data_path(ep, codec_cfg); #if defined(CONFIG_BT_ISO_TEST_PARAMS) iso->chan.qos->num_subevents = qos->num_subevents; #endif /* CONFIG_BT_ISO_TEST_PARAMS */ @@ -878,7 +878,7 @@ int bt_bap_broadcast_source_reconfig(struct bt_bap_broadcast_source *source, iso_qos = stream->ep->iso->chan.qos->tx; bt_bap_stream_attach(NULL, stream, stream->ep, codec_cfg); - bt_audio_codec_cfg_to_iso_path(iso_qos->path, codec_cfg); + bt_bap_iso_configure_data_path(stream->ep, codec_cfg); } } diff --git a/subsys/bluetooth/audio/bap_iso.c b/subsys/bluetooth/audio/bap_iso.c index cb68a8032f5..3fa2059ea94 100644 --- a/subsys/bluetooth/audio/bap_iso.c +++ b/subsys/bluetooth/audio/bap_iso.c @@ -129,19 +129,12 @@ void bt_bap_iso_init(struct bt_bap_iso *iso, struct bt_iso_chan_ops *ops) iso->chan.ops = ops; iso->chan.qos = &iso->qos; - /* Setup points for both Tx and Rx + /* Setup the QoS for both Tx and Rx * This is due to the limitation in the ISO API where pointers like - * the `qos->tx` shall be initialized before the CIS is connected if - * ever want to use it for TX, and ditto for RX. They cannot be - * initialized after the CIS has been connected + * the `qos->tx` shall be initialized before the CIS is created */ iso->chan.qos->rx = &iso->rx.qos; - iso->chan.qos->rx->path = &iso->rx.path; - iso->chan.qos->rx->path->cc = iso->rx.cc; - iso->chan.qos->tx = &iso->tx.qos; - iso->chan.qos->tx->path = &iso->tx.path; - iso->chan.qos->tx->path->cc = iso->tx.cc; } static struct bt_bap_iso_dir *bap_iso_get_iso_dir(bool unicast_client, struct bt_bap_iso *iso, @@ -164,6 +157,43 @@ static struct bt_bap_iso_dir *bap_iso_get_iso_dir(bool unicast_client, struct bt } } +void bt_bap_iso_configure_data_path(struct bt_bap_ep *ep, struct bt_audio_codec_cfg *codec_cfg) +{ + struct bt_bap_iso *bap_iso = ep->iso; + struct bt_iso_chan_qos *qos = bap_iso->chan.qos; + const bool is_unicast_client = + IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) && bt_bap_ep_is_unicast_client(ep); + struct bt_bap_iso_dir *iso_dir = bap_iso_get_iso_dir(is_unicast_client, bap_iso, ep->dir); + struct bt_iso_chan_path *path = &iso_dir->path; + + /* Setup the data path objects */ + if (iso_dir == &bap_iso->rx) { + qos->rx->path = path; + } else { + qos->tx->path = path; + } + + /* Configure the data path to either use the controller for transcoding, or set the path to + * be transparant to indicate that the transcoding happens somewhere else + */ + path->pid = codec_cfg->path_id; + + if (codec_cfg->ctlr_transcode) { + path->format = codec_cfg->id; + path->cid = codec_cfg->cid; + path->vid = codec_cfg->vid; + path->delay = 0; + path->cc_len = codec_cfg->data_len; + path->cc = codec_cfg->data; + } else { + path->format = BT_HCI_CODING_FORMAT_TRANSPARENT; + path->cid = 0; + path->vid = 0; + path->delay = 0; + path->cc_len = 0; + path->cc = NULL; + } +} static bool is_unicast_client_ep(struct bt_bap_ep *ep) { return IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) && bt_bap_ep_is_unicast_client(ep); diff --git a/subsys/bluetooth/audio/bap_iso.h b/subsys/bluetooth/audio/bap_iso.h index d3b27f3823a..4384182d697 100644 --- a/subsys/bluetooth/audio/bap_iso.h +++ b/subsys/bluetooth/audio/bap_iso.h @@ -41,6 +41,7 @@ void bt_bap_iso_foreach(bt_bap_iso_func_t func, void *user_data); struct bt_bap_iso *bt_bap_iso_find(bt_bap_iso_func_t func, void *user_data); void bt_bap_iso_init(struct bt_bap_iso *iso, struct bt_iso_chan_ops *ops); void bt_bap_iso_bind_ep(struct bt_bap_iso *iso, struct bt_bap_ep *ep); +void bt_bap_iso_configure_data_path(struct bt_bap_ep *ep, struct bt_audio_codec_cfg *codec_cfg); void bt_bap_iso_unbind_ep(struct bt_bap_iso *iso, struct bt_bap_ep *ep); struct bt_bap_ep *bt_bap_iso_get_ep(bool unicast_client, struct bt_bap_iso *iso, enum bt_audio_dir dir); diff --git a/subsys/bluetooth/audio/bap_stream.c b/subsys/bluetooth/audio/bap_stream.c index 6dae679ddef..d6df9524e14 100644 --- a/subsys/bluetooth/audio/bap_stream.c +++ b/subsys/bluetooth/audio/bap_stream.c @@ -31,28 +31,6 @@ LOG_MODULE_REGISTER(bt_bap_stream, CONFIG_BT_BAP_STREAM_LOG_LEVEL); -void bt_audio_codec_cfg_to_iso_path(struct bt_iso_chan_path *path, - struct bt_audio_codec_cfg *codec_cfg) -{ - path->pid = codec_cfg->path_id; - - if (codec_cfg->ctlr_transcode) { - path->format = codec_cfg->id; - path->cid = codec_cfg->cid; - path->vid = codec_cfg->vid; - path->delay = 0; - path->cc_len = codec_cfg->data_len; - path->cc = codec_cfg->data; - } else { - path->format = BT_HCI_CODING_FORMAT_TRANSPARENT; - path->cid = 0; - path->vid = 0; - path->delay = 0; - path->cc_len = 0; - path->cc = NULL; - } -} - #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) || defined(CONFIG_BT_BAP_BROADCAST_SOURCE) || \ defined(CONFIG_BT_BAP_BROADCAST_SINK) void bt_audio_codec_qos_to_iso_qos(struct bt_iso_chan_io_qos *io, diff --git a/subsys/bluetooth/audio/bap_stream.h b/subsys/bluetooth/audio/bap_stream.h index 67e8c0470df..d16cf2cfcc9 100644 --- a/subsys/bluetooth/audio/bap_stream.h +++ b/subsys/bluetooth/audio/bap_stream.h @@ -17,8 +17,6 @@ void bt_bap_stream_reset(struct bt_bap_stream *stream); void bt_bap_stream_attach(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_bap_ep *ep, struct bt_audio_codec_cfg *codec_cfg); -void bt_audio_codec_cfg_to_iso_path(struct bt_iso_chan_path *path, - struct bt_audio_codec_cfg *codec_cfg); void bt_audio_codec_qos_to_iso_qos(struct bt_iso_chan_io_qos *io, const struct bt_audio_codec_qos *codec_qos); diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index 933db93ec72..b6de9b61a66 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -774,17 +774,8 @@ static void unicast_client_ep_qos_state(struct bt_bap_ep *ep, struct net_buf_sim * we have the ISO <-> EP coupling completed (due to setting * the CIS ID in the QoS procedure). */ - if (ep->dir == BT_AUDIO_DIR_SOURCE) { - /* If the endpoint is a source, then we need to - * configure our RX parameters - */ - bt_audio_codec_cfg_to_iso_path(&ep->iso->rx.path, stream->codec_cfg); - } else { - /* If the endpoint is a sink, then we need to - * configure our TX parameters - */ - bt_audio_codec_cfg_to_iso_path(&ep->iso->tx.path, stream->codec_cfg); - } + + bt_bap_iso_configure_data_path(ep, stream->codec_cfg); } /* Notify upper layer */ From beb27ee66e9cac0d6cb09733a3c891bd85040a68 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 23 Jan 2024 19:55:32 +0530 Subject: [PATCH 1119/1623] [nrf fromlist] wifi: ap: Add support to disconnect a STA In AP mode, this can be used to disconnect a connected station. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68007 Signed-off-by: Chaitanya Tata --- include/zephyr/net/wifi_mgmt.h | 15 +++++++++++++++ subsys/net/l2/wifi/wifi_mgmt.c | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 0c64cab3c01..bd8cba81d28 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -81,6 +81,8 @@ enum net_request_wifi_cmd { NET_REQUEST_WIFI_CMD_PACKET_FILTER, /** Set or get Wi-Fi channel for Monitor or TX-Injection mode */ NET_REQUEST_WIFI_CMD_CHANNEL, + /** Disconnect a STA from AP */ + NET_REQUEST_WIFI_CMD_AP_STA_DISCONNECT, NET_REQUEST_WIFI_CMD_MAX }; @@ -158,6 +160,11 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PACKET_FILTER); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL); +#define NET_REQUEST_WIFI_AP_STA_DISCONNECT \ + (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_AP_STA_DISCONNECT) + +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_STA_DISCONNECT); + /** Wi-Fi management events */ enum net_event_wifi_cmd { /** Scan results available */ @@ -726,6 +733,14 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*ap_disable)(const struct device *dev); + /** Disconnect a STA from AP + * + * @param dev Pointer to the device structure for the driver instance. + * @param mac MAC address of the STA to disconnect + * + * @return 0 if ok, < 0 if error + */ + int (*ap_sta_disconnect)(const struct device *dev, const uint8_t *mac); /** Get interface status * * @param dev Pointer to the device structure for the driver instance. diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 6e0cb761dbf..2cfe8e25d89 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -410,6 +410,30 @@ static int wifi_ap_disable(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_DISABLE, wifi_ap_disable); +static int wifi_ap_sta_disconnect(uint32_t mgmt_request, struct net_if *iface, + void *data, size_t len) +{ + const struct device *dev = net_if_get_device(iface); + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); + uint8_t *mac = data; + + if (dev == NULL) { + return -ENODEV; + } + + if (wifi_mgmt_api == NULL || wifi_mgmt_api->ap_sta_disconnect == NULL) { + return -ENOTSUP; + } + + if (!data || len != sizeof(uint8_t) * WIFI_MAC_ADDR_LEN) { + return -EINVAL; + } + + return wifi_mgmt_api->ap_sta_disconnect(dev, mac); +} + +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_STA_DISCONNECT, wifi_ap_sta_disconnect); + static int wifi_iface_status(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) { From 7265d089ed41eeaf0663cab55a3dab2215491d94 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 23 Jan 2024 20:03:59 +0530 Subject: [PATCH 1120/1623] [nrf fromlist] wifi: shell: ap: Add a command to disconnect a station The shell commands can be used to disconnect a connected station in AP mode. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68007 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 70b4f96d861..5a3d7e632a7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1353,6 +1353,34 @@ static int cmd_wifi_ap_stations(const struct shell *sh, size_t argc, return 0; } +static int cmd_wifi_ap_sta_disconnect(const struct shell *sh, size_t argc, + char *argv[]) +{ + struct net_if *iface = net_if_get_first_wifi(); + uint8_t mac[6]; + int ret; + + if (argc != 2) { + shell_fprintf(sh, SHELL_WARNING, "Invalid number of arguments\n"); + shell_help(sh); + return -ENOEXEC; + } + + if (net_bytes_from_str(mac, sizeof(mac), argv[1]) < 0) { + shell_fprintf(sh, SHELL_WARNING, "Invalid MAC address\n"); + return -ENOEXEC; + } + + ret = net_mgmt(NET_REQUEST_WIFI_AP_STA_DISCONNECT, iface, mac, sizeof(mac)); + if (ret) { + shell_fprintf(sh, SHELL_WARNING, "AP station disconnect failed: %s\n", + strerror(-ret)); + return -ENOEXEC; + } + + shell_fprintf(sh, SHELL_NORMAL, "AP station disconnect requested\n"); + return 0; +} static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc, char *argv[]) @@ -1849,6 +1877,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, "List stations connected to the AP", cmd_wifi_ap_stations, 1, 0), + SHELL_CMD_ARG(disconnect, NULL, + "Disconnect a station from the AP\n" + "\n", + cmd_wifi_ap_sta_disconnect, + 2, 0), SHELL_SUBCMD_SET_END ); From c6c44468cd4f3ddc9256cce990232ec2dbba4d64 Mon Sep 17 00:00:00 2001 From: Lukasz Majewski Date: Tue, 14 Nov 2023 16:28:11 +0100 Subject: [PATCH 1121/1623] [nrf fromtree] net: ethernet: Add support for setting T1S PLCA parameters The Zephyr's core ethernet code had to be adjusted to support setting T1S PLCA parameters from user Zephyr programs. Such approach allows more flexibility, as T1S network configuration; especially PLCA node numbers, can be assigned not only via device tree at compile time. For example user can read them from EEPROM and then configure the network accordingly. For now - the union in struct ethernet_t1s_param only consists of plca structure. This can change in the future, when other T1S OA parameters - like Receive/Transmit Cut-Through Enable (bits RXCTE/TXCTE in OA_CONFIG0 register) are made adjustable from user program. Signed-off-by: Lukasz Majewski (cherry picked from commit 25addd09842a05675b68e72d73acf3d616d4548b) --- include/zephyr/net/ethernet.h | 48 ++++++++++++++++++++++++++ include/zephyr/net/ethernet_mgmt.h | 7 ++++ subsys/net/l2/ethernet/ethernet_mgmt.c | 11 ++++++ 3 files changed, 66 insertions(+) diff --git a/include/zephyr/net/ethernet.h b/include/zephyr/net/ethernet.h index a47ec767a60..181503140a7 100644 --- a/include/zephyr/net/ethernet.h +++ b/include/zephyr/net/ethernet.h @@ -196,6 +196,7 @@ enum ethernet_config_type { ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM, ETHERNET_CONFIG_TYPE_FILTER, ETHERNET_CONFIG_TYPE_PORTS_NUM, + ETHERNET_CONFIG_TYPE_T1S_PARAM, }; enum ethernet_qav_param_type { @@ -206,7 +207,53 @@ enum ethernet_qav_param_type { ETHERNET_QAV_PARAM_TYPE_STATUS, }; +enum ethernet_t1s_param_type { + ETHERNET_T1S_PARAM_TYPE_PLCA_CONFIG, +}; + /** @endcond */ +struct ethernet_t1s_param { + /** Type of T1S parameter */ + enum ethernet_t1s_param_type type; + union { + /* PLCA is the Physical Layer (PHY) Collision + * Avoidance technique employed with multidrop + * 10Base-T1S standard. + * + * The PLCA parameters are described in standard [1] + * as registers in memory map 4 (MMS = 4) (point 9.6). + * + * IDVER (PLCA ID Version) + * CTRL0 (PLCA Control 0) + * CTRL1 (PLCA Control 1) + * STATUS (PLCA Status) + * TOTMR (PLCA TO Control) + * BURST (PLCA Burst Control) + * + * Those registers are implemented by each OA TC6 + * compliant vendor (like for e.g. LAN865x - e.g. [2]). + * + * Documents: + * [1] - "OPEN Alliance 10BASE-T1x MAC-PHY Serial + * Interface" (ver. 1.1) + * [2] - "DS60001734C" - LAN865x data sheet + */ + struct { + /** T1S PLCA enabled */ + bool enable; + /** T1S PLCA node id range: 0 to 254 */ + uint8_t node_id; + /** T1S PLCA node count range: 1 to 255 */ + uint8_t node_count; + /** T1S PLCA burst count range: 0x0 to 0xFF */ + uint8_t burst_count; + /** T1S PLCA burst timer */ + uint8_t burst_timer; + /** T1S PLCA TO value */ + uint8_t to_timer; + } plca; + }; +}; struct ethernet_qav_param { /** ID of the priority queue to use */ @@ -404,6 +451,7 @@ struct ethernet_config { struct net_eth_addr mac_address; + struct ethernet_t1s_param t1s_param; struct ethernet_qav_param qav_param; struct ethernet_qbv_param qbv_param; struct ethernet_qbu_param qbu_param; diff --git a/include/zephyr/net/ethernet_mgmt.h b/include/zephyr/net/ethernet_mgmt.h index 9d95fa7a42e..32a38f2df88 100644 --- a/include/zephyr/net/ethernet_mgmt.h +++ b/include/zephyr/net/ethernet_mgmt.h @@ -51,6 +51,7 @@ enum net_request_ethernet_cmd { NET_REQUEST_ETHERNET_CMD_GET_QBV_PARAM, NET_REQUEST_ETHERNET_CMD_GET_QBU_PARAM, NET_REQUEST_ETHERNET_CMD_GET_TXTIME_PARAM, + NET_REQUEST_ETHERNET_CMD_SET_T1S_PARAM, }; #define NET_REQUEST_ETHERNET_SET_AUTO_NEGOTIATION \ @@ -128,6 +129,11 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QBU_PARAM); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXTIME_PARAM); +#define NET_REQUEST_ETHERNET_SET_T1S_PARAM \ + (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_T1S_PARAM) + +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_T1S_PARAM); + struct net_eth_addr; struct ethernet_qav_param; struct ethernet_qbv_param; @@ -152,6 +158,7 @@ struct ethernet_req_params { struct ethernet_qbv_param qbv_param; struct ethernet_qbu_param qbu_param; struct ethernet_txtime_param txtime_param; + struct ethernet_t1s_param t1s_param; int priority_queues_num; int ports_num; diff --git a/subsys/net/l2/ethernet/ethernet_mgmt.c b/subsys/net/l2/ethernet/ethernet_mgmt.c index e7fcae8ac99..3e957e52c1e 100644 --- a/subsys/net/l2/ethernet/ethernet_mgmt.c +++ b/subsys/net/l2/ethernet/ethernet_mgmt.c @@ -192,6 +192,14 @@ static int ethernet_set_config(uint32_t mgmt_request, config.promisc_mode = params->promisc_mode; type = ETHERNET_CONFIG_TYPE_PROMISC_MODE; + } else if (mgmt_request == NET_REQUEST_ETHERNET_SET_T1S_PARAM) { + if (net_if_is_up(iface)) { + return -EACCES; + } + + memcpy(&config.t1s_param, ¶ms->t1s_param, + sizeof(struct ethernet_t1s_param)); + type = ETHERNET_CONFIG_TYPE_T1S_PARAM; } else { return -EINVAL; } @@ -226,6 +234,9 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_TXTIME_PARAM, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_PROMISC_MODE, ethernet_set_config); +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_T1S_PARAM, + ethernet_set_config); + static int ethernet_get_config(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) From f1f5d375838a07cf2c0d0669cec91a7133508d62 Mon Sep 17 00:00:00 2001 From: Vivekananda Uppunda Date: Mon, 22 Jan 2024 10:08:03 +0530 Subject: [PATCH 1122/1623] [nrf fromtree] net: l2: ethernet: bring in TX-Injection mode to l2 ethernet This set of changes brings in raw packet tx injection mode feature to ethernet and removes it from being a Wi-Fi only feature. It was earlier envisaged as Wi-Fi net management feature only. Signed-off-by: Vivekananda Uppunda (cherry picked from commit db4bf8d409ce7d0b8b96363e868258d99ba2d28f) --- include/zephyr/net/ethernet.h | 16 ++++++++++++++++ include/zephyr/net/ethernet_mgmt.h | 13 +++++++++++++ subsys/net/l2/ethernet/ethernet.c | 14 ++++++++++++++ subsys/net/l2/ethernet/ethernet_mgmt.c | 26 ++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/include/zephyr/net/ethernet.h b/include/zephyr/net/ethernet.h index 181503140a7..faa6cf7fc0b 100644 --- a/include/zephyr/net/ethernet.h +++ b/include/zephyr/net/ethernet.h @@ -179,6 +179,9 @@ enum ethernet_hw_caps { /** TXTIME supported */ ETHERNET_TXTIME = BIT(19), + + /** TX-Injection supported */ + ETHERNET_TXINJECTION_MODE = BIT(20), }; /** @cond INTERNAL_HIDDEN */ @@ -197,6 +200,7 @@ enum ethernet_config_type { ETHERNET_CONFIG_TYPE_FILTER, ETHERNET_CONFIG_TYPE_PORTS_NUM, ETHERNET_CONFIG_TYPE_T1S_PARAM, + ETHERNET_CONFIG_TYPE_TXINJECTION_MODE, }; enum ethernet_qav_param_type { @@ -442,6 +446,7 @@ struct ethernet_config { bool auto_negotiation; bool full_duplex; bool promisc_mode; + bool txinjection_mode; struct { bool link_10bt; @@ -1029,6 +1034,17 @@ void net_eth_carrier_off(struct net_if *iface); */ int net_eth_promisc_mode(struct net_if *iface, bool enable); +/** + * @brief Set TX-Injection mode either ON or OFF. + * + * @param iface Network interface + * + * @param enable on (true) or off (false) + * + * @return 0 if mode set or unset was successful, <0 otherwise. + */ +int net_eth_txinjection_mode(struct net_if *iface, bool enable); + /** * @brief Return PTP clock that is tied to this ethernet network interface. * diff --git a/include/zephyr/net/ethernet_mgmt.h b/include/zephyr/net/ethernet_mgmt.h index 32a38f2df88..18039e9f3aa 100644 --- a/include/zephyr/net/ethernet_mgmt.h +++ b/include/zephyr/net/ethernet_mgmt.h @@ -52,6 +52,8 @@ enum net_request_ethernet_cmd { NET_REQUEST_ETHERNET_CMD_GET_QBU_PARAM, NET_REQUEST_ETHERNET_CMD_GET_TXTIME_PARAM, NET_REQUEST_ETHERNET_CMD_SET_T1S_PARAM, + NET_REQUEST_ETHERNET_CMD_SET_TXINJECTION_MODE, + NET_REQUEST_ETHERNET_CMD_GET_TXINJECTION_MODE, }; #define NET_REQUEST_ETHERNET_SET_AUTO_NEGOTIATION \ @@ -134,6 +136,16 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXTIME_PARAM); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_T1S_PARAM); +#define NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE \ + (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_TXINJECTION_MODE) + +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE); + +#define NET_REQUEST_ETHERNET_GET_TXINJECTION_MODE \ + (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_TXINJECTION_MODE) + +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXINJECTION_MODE); + struct net_eth_addr; struct ethernet_qav_param; struct ethernet_qbv_param; @@ -145,6 +157,7 @@ struct ethernet_req_params { bool auto_negotiation; bool full_duplex; bool promisc_mode; + bool txinjection_mode; struct { bool link_10bt; diff --git a/subsys/net/l2/ethernet/ethernet.c b/subsys/net/l2/ethernet/ethernet.c index 2be3c5f2820..8e73e8bcd43 100644 --- a/subsys/net/l2/ethernet/ethernet.c +++ b/subsys/net/l2/ethernet/ethernet.c @@ -1197,6 +1197,20 @@ int net_eth_promisc_mode(struct net_if *iface, bool enable) } #endif/* CONFIG_NET_PROMISCUOUS_MODE */ +int net_eth_txinjection_mode(struct net_if *iface, bool enable) +{ + struct ethernet_req_params params; + + if (!(net_eth_get_hw_capabilities(iface) & ETHERNET_TXINJECTION_MODE)) { + return -ENOTSUP; + } + + params.txinjection_mode = enable; + + return net_mgmt(NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE, iface, + ¶ms, sizeof(struct ethernet_req_params)); +} + void ethernet_init(struct net_if *iface) { struct ethernet_context *ctx = net_if_l2_data(iface); diff --git a/subsys/net/l2/ethernet/ethernet_mgmt.c b/subsys/net/l2/ethernet/ethernet_mgmt.c index 3e957e52c1e..899aa7a9516 100644 --- a/subsys/net/l2/ethernet/ethernet_mgmt.c +++ b/subsys/net/l2/ethernet/ethernet_mgmt.c @@ -200,6 +200,13 @@ static int ethernet_set_config(uint32_t mgmt_request, memcpy(&config.t1s_param, ¶ms->t1s_param, sizeof(struct ethernet_t1s_param)); type = ETHERNET_CONFIG_TYPE_T1S_PARAM; + } else if (mgmt_request == NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE) { + if (!is_hw_caps_supported(dev, ETHERNET_TXINJECTION_MODE)) { + return -ENOTSUP; + } + + config.txinjection_mode = params->txinjection_mode; + type = ETHERNET_CONFIG_TYPE_TXINJECTION_MODE; } else { return -EINVAL; } @@ -237,6 +244,9 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_PROMISC_MODE, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_T1S_PARAM, ethernet_set_config); +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE, + ethernet_set_config); + static int ethernet_get_config(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len) @@ -430,6 +440,19 @@ static int ethernet_get_config(uint32_t mgmt_request, config.txtime_param.enable_txtime; break; } + } else if (mgmt_request == NET_REQUEST_ETHERNET_GET_TXINJECTION_MODE) { + if (!is_hw_caps_supported(dev, ETHERNET_TXINJECTION_MODE)) { + return -ENOTSUP; + } + + type = ETHERNET_CONFIG_TYPE_TXINJECTION_MODE; + + ret = api->get_config(dev, type, &config); + if (ret) { + return ret; + } + + params->txinjection_mode = config.txinjection_mode; } else { return -EINVAL; } @@ -455,6 +478,9 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QBU_PARAM, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXTIME_PARAM, ethernet_get_config); +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXINJECTION_MODE, + ethernet_get_config); + void ethernet_mgmt_raise_carrier_on_event(struct net_if *iface) { net_mgmt_event_notify(NET_EVENT_ETHERNET_CARRIER_ON, iface); From f923004850f7ae85f2b02bf339edc69a4e9b0172 Mon Sep 17 00:00:00 2001 From: Vivekananda Uppunda Date: Mon, 22 Jan 2024 12:30:53 +0530 Subject: [PATCH 1123/1623] [nrf fromtree] net: wifi_shell: Remove TX-Injection and Promisc mode Remove TX-Injection and Promiscuous mode setting from Wi-Fi mode shell command. These commands are being moved to ethernet l2 layer Signed-off-by: Vivekananda Uppunda (cherry picked from commit 7eb0aa04689b3086bf513f30531747393d86007b) --- subsys/net/l2/wifi/wifi_shell.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 5a3d7e632a7..d70e48024b7 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1539,8 +1539,6 @@ void parse_mode_args_to_params(const struct shell *sh, int argc, static struct option long_options[] = {{"if-index", optional_argument, 0, 'i'}, {"sta", no_argument, 0, 's'}, {"monitor", no_argument, 0, 'm'}, - {"tx-injection", no_argument, 0, 't'}, - {"promiscuous", no_argument, 0, 'p'}, {"ap", no_argument, 0, 'a'}, {"softap", no_argument, 0, 'k'}, {"get", no_argument, 0, 'g'}, @@ -1555,12 +1553,6 @@ void parse_mode_args_to_params(const struct shell *sh, int argc, case 'm': mode->mode |= WIFI_MONITOR_MODE; break; - case 't': - mode->mode |= WIFI_TX_INJECTION_MODE; - break; - case 'p': - mode->mode |= WIFI_PROMISCUOUS_MODE; - break; case 'a': mode->mode |= WIFI_AP_MODE; break; @@ -1962,8 +1954,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "[-i, --if-index ] : Interface index\n" "[-s, --sta] : Station mode\n" "[-m, --monitor] : Monitor mode\n" - "[-p, --promiscuous] : Promiscuous mode\n" - "[-t, --tx-injection] : TX-Injection mode\n" "[-a, --ap] : AP mode\n" "[-k, --softap] : Softap mode\n" "[-h, --help] : Help\n" From 593e6c8e4b831082ac8e225fd2db4fd8f14a15af Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Fri, 26 Jan 2024 10:55:05 +0100 Subject: [PATCH 1124/1623] Revert "[nrf noup] drivers: ieee802154: temporary fix for ACK header IE config" This reverts commit https://github.com/nrfconnect/sdk-zephyr/commit/1da00e0c84f7da2f4017f4efde99e479d40e5e6e Signed-off-by: Maciej Baczmanski --- drivers/ieee802154/ieee802154_nrf5.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index b542c5007f8..4f7c3f863a3 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -900,19 +900,6 @@ static int nrf5_configure(const struct device *dev, uint8_t short_addr_le[SHORT_ADDRESS_SIZE]; uint8_t element_id; - if (config->ack_ie.ext_addr == NULL && - config->ack_ie.header_ie == NULL && - config->ack_ie.short_addr == IEEE802154_NO_SHORT_ADDRESS_ASSIGNED) { - /* Hotfix for case when `EnableCsl()` has been called with arguments: - * - `aCslPeriod` == 0 - * - `aShortAddr` == IEEE802154_NO_SHORT_ADDRESS_ASSIGNED - * - `aExtAddr` == NULL - * In this case skip configuring ACK header IE until proper resetting of - * configuration is implemented. - */ - break; - } - if (config->ack_ie.short_addr == IEEE802154_BROADCAST_ADDRESS || config->ack_ie.ext_addr == NULL) { return -ENOTSUP; From 02e7e0f34df3ded888a736debf84573094d8af6c Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Tue, 23 Jan 2024 14:36:55 +0100 Subject: [PATCH 1125/1623] [nrf fromtree] drivers: ieee802154: fix ACK header IE implementation - In `set_vendor_ie_header_lm`, case when `link_metrics_data_len == 0` has been ignored. This commit fixes that by setting `header_ie->length = 0` before returning. - current implementation of enh ACK header IE returns `-ENOTSUP` when `ack_ie.header_ie == NULL` or `ack_ie.header_ie->length == 0`. This commit fixes that by refactoring checks in `nrf5_configure`. Co-authored-by: Przemyslaw Bida Signed-off-by: Maciej Baczmanski (cherry picked from commit d76bcd346ce7b9ede5144114fc357859e6a5d610) --- drivers/ieee802154/ieee802154_nrf5.c | 38 ++++++++++++++-------------- modules/openthread/platform/radio.c | 13 ++++------ 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index 4f7c3f863a3..16eb2cb0022 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -899,35 +899,38 @@ static int nrf5_configure(const struct device *dev, uint8_t ext_addr_le[EXTENDED_ADDRESS_SIZE]; uint8_t short_addr_le[SHORT_ADDRESS_SIZE]; uint8_t element_id; + bool valid_vendor_specific_ie = false; if (config->ack_ie.short_addr == IEEE802154_BROADCAST_ADDRESS || config->ack_ie.ext_addr == NULL) { return -ENOTSUP; } - element_id = ieee802154_header_ie_get_element_id(config->ack_ie.header_ie); + sys_put_le16(config->ack_ie.short_addr, short_addr_le); + sys_memcpy_swap(ext_addr_le, config->ack_ie.ext_addr, EXTENDED_ADDRESS_SIZE); - if (element_id != IEEE802154_HEADER_IE_ELEMENT_ID_CSL_IE && - (!IS_ENABLED(CONFIG_NET_L2_OPENTHREAD) || - element_id != IEEE802154_HEADER_IE_ELEMENT_ID_VENDOR_SPECIFIC_IE)) { - return -ENOTSUP; - } + if (config->ack_ie.header_ie == NULL || config->ack_ie.header_ie->length == 0) { + nrf_802154_ack_data_clear(short_addr_le, false, NRF_802154_ACK_DATA_IE); + nrf_802154_ack_data_clear(ext_addr_le, true, NRF_802154_ACK_DATA_IE); + } else { + element_id = ieee802154_header_ie_get_element_id(config->ack_ie.header_ie); #if defined(CONFIG_NET_L2_OPENTHREAD) - uint8_t vendor_oui_le[IEEE802154_OPENTHREAD_VENDOR_OUI_LEN] = - IEEE802154_OPENTHREAD_THREAD_IE_VENDOR_OUI; + uint8_t vendor_oui_le[IEEE802154_OPENTHREAD_VENDOR_OUI_LEN] = + IEEE802154_OPENTHREAD_THREAD_IE_VENDOR_OUI; - if (element_id == IEEE802154_HEADER_IE_ELEMENT_ID_VENDOR_SPECIFIC_IE && - memcmp(config->ack_ie.header_ie->content.vendor_specific.vendor_oui, - vendor_oui_le, sizeof(vendor_oui_le))) { - return -ENOTSUP; - } + if (element_id == IEEE802154_HEADER_IE_ELEMENT_ID_VENDOR_SPECIFIC_IE && + memcmp(config->ack_ie.header_ie->content.vendor_specific.vendor_oui, + vendor_oui_le, sizeof(vendor_oui_le)) == 0) { + valid_vendor_specific_ie = true; + } #endif - sys_put_le16(config->ack_ie.short_addr, short_addr_le); - sys_memcpy_swap(ext_addr_le, config->ack_ie.ext_addr, EXTENDED_ADDRESS_SIZE); + if (element_id != IEEE802154_HEADER_IE_ELEMENT_ID_CSL_IE && + !valid_vendor_specific_ie) { + return -ENOTSUP; + } - if (config->ack_ie.header_ie && config->ack_ie.header_ie->length > 0) { nrf_802154_ack_data_set(short_addr_le, false, config->ack_ie.header_ie, config->ack_ie.header_ie->length + IEEE802154_HEADER_IE_HEADER_LENGTH, @@ -936,9 +939,6 @@ static int nrf5_configure(const struct device *dev, config->ack_ie.header_ie->length + IEEE802154_HEADER_IE_HEADER_LENGTH, NRF_802154_ACK_DATA_IE); - } else { - nrf_802154_ack_data_clear(short_addr_le, false, NRF_802154_ACK_DATA_IE); - nrf_802154_ack_data_clear(ext_addr_le, true, NRF_802154_ACK_DATA_IE); } } break; diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index cec73e3ef6f..a26c66d875d 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -1348,7 +1348,7 @@ uint8_t otPlatRadioGetCslUncertainty(otInstance *aInstance) * | IE_VENDOR_THREAD_ACK_PROBING_ID | LINK_METRIC_TOKEN | LINK_METRIC_TOKEN| * |---------------------------------|-------------------|------------------| */ -static uint8_t set_vendor_ie_header_lm(bool lqi, bool link_margin, bool rssi, uint8_t *ie_header) +static void set_vendor_ie_header_lm(bool lqi, bool link_margin, bool rssi, uint8_t *ie_header) { /* Vendor-specific IE identifier */ const uint8_t ie_vendor_id = 0x00; @@ -1362,7 +1362,6 @@ static uint8_t set_vendor_ie_header_lm(bool lqi, bool link_margin, bool rssi, ui const uint8_t ie_vendor_thread_margin_token = 0x02; /* Thread Vendor-specific ACK Probing IE LQI value placeholder */ const uint8_t ie_vendor_thread_lqi_token = 0x03; - const uint8_t ie_header_size = 2; const uint8_t oui_size = 3; const uint8_t sub_type = 1; const uint8_t id_offset = 7; @@ -1380,7 +1379,8 @@ static uint8_t set_vendor_ie_header_lm(bool lqi, bool link_margin, bool rssi, ui __ASSERT(ie_header, "Invalid argument"); if (link_metrics_data_len == 0) { - return 0; + ie_header[0] = 0; + return; } /* Set Element ID */ @@ -1415,8 +1415,6 @@ static uint8_t set_vendor_ie_header_lm(bool lqi, bool link_margin, bool rssi, ui if (rssi) { ie_header[link_metrics_idx++] = ie_vendor_thread_rssi_token; } - - return ie_header_size + content_len; } otError otPlatRadioConfigureEnhAckProbing(otInstance *aInstance, otLinkMetrics aLinkMetrics, @@ -1428,13 +1426,12 @@ otError otPlatRadioConfigureEnhAckProbing(otInstance *aInstance, otLinkMetrics a .ack_ie.ext_addr = aExtAddress->m8, }; uint8_t header_ie_buf[OT_ACK_IE_MAX_SIZE]; - uint16_t header_ie_len; int result; ARG_UNUSED(aInstance); - header_ie_len = set_vendor_ie_header_lm(aLinkMetrics.mLqi, aLinkMetrics.mLinkMargin, - aLinkMetrics.mRssi, header_ie_buf); + set_vendor_ie_header_lm(aLinkMetrics.mLqi, aLinkMetrics.mLinkMargin, + aLinkMetrics.mRssi, header_ie_buf); config.ack_ie.header_ie = (struct ieee802154_header_ie *)header_ie_buf; result = radio_api->configure(radio_dev, IEEE802154_CONFIG_ENH_ACK_HEADER_IE, &config); From 93c590c3a81e738e59a95db384c58a8fbe73b762 Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Tue, 23 Jan 2024 14:55:09 +0100 Subject: [PATCH 1126/1623] [nrf fromtree] drivers: ieee802154: fix handling of `struct ieee802154_config` `struct ieee802154_config config` is a struct containing an union. Members of `config` were accessed incorrectly in `otPlatRadioEnableCsl`. Fix by initializing `config` with `0` and accessing one member at a time. Signed-off-by: Maciej Baczmanski (cherry picked from commit 36b7f44c1d37e842048773f3ad11af59f7b465bb) --- modules/openthread/platform/radio.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index a26c66d875d..c0df98367af 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -1255,10 +1255,7 @@ void otPlatRadioSetMacFrameCounterIfLarger(otInstance *aInstance, uint32_t aMacF otError otPlatRadioEnableCsl(otInstance *aInstance, uint32_t aCslPeriod, otShortAddress aShortAddr, const otExtAddress *aExtAddr) { - struct ieee802154_config config = { - .ack_ie.short_addr = aShortAddr, - .ack_ie.ext_addr = aExtAddr->m8, - }; + struct ieee802154_config config = { 0 }; int result; ARG_UNUSED(aInstance); @@ -1271,6 +1268,8 @@ otError otPlatRadioEnableCsl(otInstance *aInstance, uint32_t aCslPeriod, otShort if (result) { return OT_ERROR_FAILED; } + config.ack_ie.short_addr = aShortAddr; + config.ack_ie.ext_addr = aExtAddr != NULL ? aExtAddr->m8 : NULL; /* Configure the CSL IE. */ if (aCslPeriod > 0) { From b3c97b010983e5523d90f9140b8e657b06a2ea3f Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Tue, 23 Jan 2024 14:56:03 +0100 Subject: [PATCH 1127/1623] [nrf fromtree] net: openthread: upmerge to `7761b81` additionaly, implement `otPlatRadioResetCsl` functionality Signed-off-by: Maciej Baczmanski (cherry picked from commit 0f1747e4e73fa1db67f65dfb251d202e8d552db6) --- drivers/ieee802154/ieee802154_nrf5.c | 6 ++++++ include/zephyr/net/ieee802154_radio.h | 9 +++++++++ modules/openthread/platform/radio.c | 16 ++++++++++++++++ west.yml | 2 +- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index 16eb2cb0022..553d71188e9 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -901,6 +901,12 @@ static int nrf5_configure(const struct device *dev, uint8_t element_id; bool valid_vendor_specific_ie = false; + if (config->ack_ie.purge_ie) { + nrf_802154_ack_data_remove_all(false, NRF_802154_ACK_DATA_IE); + nrf_802154_ack_data_remove_all(true, NRF_802154_ACK_DATA_IE); + break; + } + if (config->ack_ie.short_addr == IEEE802154_BROADCAST_ADDRESS || config->ack_ie.ext_addr == NULL) { return -ENOTSUP; diff --git a/include/zephyr/net/ieee802154_radio.h b/include/zephyr/net/ieee802154_radio.h index de0cf89da4c..259d67b4321 100644 --- a/include/zephyr/net/ieee802154_radio.h +++ b/include/zephyr/net/ieee802154_radio.h @@ -1241,6 +1241,15 @@ struct ieee802154_config { * in CPU byte order */ uint16_t short_addr; + + /** + * Flag for purging enh ACK header IEs. + * When flag is set to true, driver should remove all existing + * header IEs, and all other entries in config should be ignored. + * This means that purging current header IEs and + * configuring a new one in the same call is not allowed. + */ + bool purge_ie; } ack_ie; }; }; diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index c0df98367af..d405539bcc0 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -1294,6 +1294,22 @@ otError otPlatRadioEnableCsl(otInstance *aInstance, uint32_t aCslPeriod, otShort return result ? OT_ERROR_FAILED : OT_ERROR_NONE; } +otError otPlatRadioResetCsl(otInstance *aInstance) +{ + struct ieee802154_config config = { 0 }; + int result; + + result = radio_api->configure(radio_dev, IEEE802154_CONFIG_CSL_PERIOD, &config); + if (result) { + return OT_ERROR_FAILED; + } + + config.ack_ie.purge_ie = true; + result = radio_api->configure(radio_dev, IEEE802154_CONFIG_ENH_ACK_HEADER_IE, &config); + + return result ? OT_ERROR_FAILED : OT_ERROR_NONE; +} + void otPlatRadioUpdateCslSampleTime(otInstance *aInstance, uint32_t aCslSampleTime) { ARG_UNUSED(aInstance); diff --git a/west.yml b/west.yml index 2892d3db451..ea8352aa7cf 100644 --- a/west.yml +++ b/west.yml @@ -301,7 +301,7 @@ manifest: revision: 214f9fc1539f8e5937c0474cb6ee29b6dcb2d4b8 path: modules/lib/open-amp - name: openthread - revision: 00076aff3ae571db7c90509ec9dc293457098c35 + revision: 7761b81d23b10b3d5ee21b8504c67535cde10896 path: modules/lib/openthread - name: percepio path: modules/debug/percepio From c790da9970699f7271c096b66328fb531f4dc2ff Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Fri, 12 Jan 2024 11:30:23 +0100 Subject: [PATCH 1128/1623] [nrf fromtree] Bluetooth: Mesh: Fix dereferencing before null pointer check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't dereference pointer until it is checked on NULL. Fixes: #66805 Coverity-CID: 338098 Signed-off-by: Pavel Vasilyev (cherry picked from commit 27b1f4eb7f9d887d8fda81cbdc52f651223e75e9) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/delayable_msg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/delayable_msg.c b/subsys/bluetooth/mesh/delayable_msg.c index 5fa43205d63..a1a247bb9c9 100644 --- a/subsys/bluetooth/mesh/delayable_msg.c +++ b/subsys/bluetooth/mesh/delayable_msg.c @@ -167,13 +167,15 @@ static bool push_msg_from_delayable_msgs(void) sys_snode_t *node; struct delayable_msg_chunk *chunk; struct delayable_msg_ctx *msg = peek_pending_msg(); - uint16_t len = msg->len; + uint16_t len; int err; if (!msg) { return false; } + len = msg->len; + NET_BUF_SIMPLE_DEFINE(buf, BT_MESH_TX_SDU_MAX); SYS_SLIST_FOR_EACH_NODE(&msg->chunks, node) { From 7c3e830729b70943c82a7dd04ba33ed669894115 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Tue, 9 Jan 2024 15:22:29 +0100 Subject: [PATCH 1129/1623] [nrf fromtree] Bluetooth: Mesh: enable access responses randomization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable by default the access layer responses random delays. Commit also adapts all mesh models, samples and babblesim tests to use random delay functionality correctly. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 4e7d64b1b45247de1e1d71a4402f5637b0fd0afe) Signed-off-by: Håvard Reierstad --- subsys/bluetooth/mesh/Kconfig | 15 +++++++++++++-- subsys/bluetooth/mesh/access.c | 10 ++++++++-- tests/bsim/bluetooth/mesh/src/test_access.c | 11 ++++++++--- tests/bsim/bluetooth/mesh/src/test_persistence.c | 6 ------ tests/bsim/bluetooth/mesh/src/test_provision.c | 10 ---------- .../access/access_transmit_delayable.sh | 2 +- .../priv_beacon/proxy_adv_multi_subnet_coex.sh | 4 ++++ 7 files changed, 34 insertions(+), 24 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index af6af8c44dc..555aac45bc0 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -639,6 +639,7 @@ config BT_MESH_LABEL_NO_RECOVER menuconfig BT_MESH_ACCESS_DELAYABLE_MSG bool "Access layer tx delayable message" + default y help Enable following of the message transmitting recommendations, the Access layer specification. The recommendations are optional. @@ -647,6 +648,16 @@ menuconfig BT_MESH_ACCESS_DELAYABLE_MSG if BT_MESH_ACCESS_DELAYABLE_MSG +config BT_MESH_ACCESS_DELAYABLE_MSG_CTX_ENABLED + bool "The delayable message in the notification message context" + default y + help + Controls whether the delayable message feature is enabled by default in + the message context of the opcode notifications. This allows the server part of any + model to not bother about additional context configuration to enable the delayable message. + Note that if this is disabled then all foundation models stop using the delayable message + functionality. + config BT_MESH_ACCESS_DELAYABLE_MSG_COUNT int "Number of simultaneously delayed messages" default 4 @@ -657,14 +668,14 @@ config BT_MESH_ACCESS_DELAYABLE_MSG_COUNT config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE int "Maximum delayable message storage chunk" - default 20 + default 10 help Size of memory that Access layer uses to split model message to. It allocates a sufficient number of these chunks from the pool to store the full model payload. config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT int "Maximum number of available chunks" - default 20 + default 40 help The maximum number of available chunks the Access layer allocates to store model payload. It is recommended to keep chunk size equal to the reasonable small value to prevent diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index c3ef6a40554..23fbb8e82c2 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -922,7 +922,7 @@ static void mod_publish(struct k_work *work) return; } - LOG_DBG("%u", k_uptime_get_32()); + LOG_DBG("timestamp: %u", k_uptime_get_32()); if (pub->count) { pub->count--; @@ -1504,6 +1504,10 @@ static int element_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple return ACCESS_STATUS_MESSAGE_NOT_UNDERSTOOD; } + if (IS_ENABLED(CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CTX_ENABLED)) { + ctx->rnd_delay = true; + } + net_buf_simple_save(buf, &state); err = op->func(model, ctx, buf); net_buf_simple_restore(buf, &state); @@ -1578,7 +1582,9 @@ int bt_mesh_model_send(const struct bt_mesh_model *model, struct bt_mesh_msg_ctx } #if defined CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG - if (ctx->rnd_delay) { + /* No sense to use delayable message for unicast loopback. */ + if (ctx->rnd_delay && + !(bt_mesh_has_addr(ctx->addr) && BT_MESH_ADDR_IS_UNICAST(ctx->addr))) { return bt_mesh_delayable_msg_manage(ctx, msg, bt_mesh_model_elem(model)->rt->addr, cb, cb_data); } diff --git a/tests/bsim/bluetooth/mesh/src/test_access.c b/tests/bsim/bluetooth/mesh/src/test_access.c index 5cb7d2e28e1..6967aa6d71c 100644 --- a/tests/bsim/bluetooth/mesh/src/test_access.c +++ b/tests/bsim/bluetooth/mesh/src/test_access.c @@ -102,11 +102,15 @@ static bool publish_allow; static int model1_update(const struct bt_mesh_model *model) { - model->pub->msg->data[1]++; + if (!publish_allow) { + return -1; + } + model->pub->msg->data[1]++; LOG_DBG("New pub: n: %d t: %d", model->pub->msg->data[1], k_uptime_get_32()); + k_sem_give(&publish_sem); - return publish_allow ? k_sem_give(&publish_sem), 0 : -1; + return 0; } static int test_msgf_handler(const struct bt_mesh_model *model, @@ -604,7 +608,8 @@ static void recv_delayable_check(int32_t interval, uint8_t count) LOG_DBG("Recv time: %d delta: %d boundaries: %d/%d", (int32_t)timestamp, time_delta, lower_boundary, upper_boundary); - ASSERT_IN_RANGE(time_delta, lower_boundary, upper_boundary + RX_JITTER_MAX); + ASSERT_IN_RANGE(time_delta, lower_boundary - RX_JITTER_MAX, + upper_boundary + RX_JITTER_MAX); } } diff --git a/tests/bsim/bluetooth/mesh/src/test_persistence.c b/tests/bsim/bluetooth/mesh/src/test_persistence.c index ec7d838d26a..4bf1f9faa93 100644 --- a/tests/bsim/bluetooth/mesh/src/test_persistence.c +++ b/tests/bsim/bluetooth/mesh/src/test_persistence.c @@ -455,12 +455,6 @@ static void provisioner_setup(void) FAIL("Failed to add test_netkey (err: %d, status: %d)", err, status); } - err = bt_mesh_cfg_cli_net_transmit_set(test_netkey_idx, TEST_PROV_ADDR, - BT_MESH_TRANSMIT(3, 50), &status); - if (err || status != BT_MESH_TRANSMIT(3, 50)) { - FAIL("Net transmit set failed (err %d, transmit %x)", err, status); - } - provisioner_ready = true; } diff --git a/tests/bsim/bluetooth/mesh/src/test_provision.c b/tests/bsim/bluetooth/mesh/src/test_provision.c index 2bff871b187..3d0e8010c75 100644 --- a/tests/bsim/bluetooth/mesh/src/test_provision.c +++ b/tests/bsim/bluetooth/mesh/src/test_provision.c @@ -1205,7 +1205,6 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void) uint16_t pb_remote_server_addr; uint8_t status; struct bt_mesh_cdb_node *node; - int err; provisioner_pb_remote_client_setup(); @@ -1219,15 +1218,6 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void) .ttl = 3, }; - /* Set Network Transmit Count state on the remote client greater than on the remote server - * to increase probability of reception responses. - */ - err = bt_mesh_cfg_cli_net_transmit_set(0, current_dev_addr, BT_MESH_TRANSMIT(3, 50), - &status); - if (err || status != BT_MESH_TRANSMIT(3, 50)) { - FAIL("Net transmit set failed (err %d, transmit %x)", err, status); - } - ASSERT_OK(provision_remote(&srv, 2, &srv.addr)); /* Check device key by adding appkey. */ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh index 1622ac49f06..0e966288db0 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh @@ -14,4 +14,4 @@ RunTest mesh_access_pub_transmit_delayable_retr_1d1 \ conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_access_pub_transmit_delayable_retr_psa \ - access_tx_period_delayable access_rx_period_delayable + access_tx_transmit_delayable access_rx_transmit_delayable diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh index aa96ee325d8..42863a13458 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh @@ -22,6 +22,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # window. The Mesh Protocol specification does not specify exactly the # timing for Proxy ADV messages. +# Note 3: The proxy transmitting device mandates emitting of the secure +# network beacons. This allows to check that proxy goes back to normal +# behavior after the device advertises the secure network beacons. + # Test procedure: # 1. (0-20 seconds) A single subnet is active on the TX device with GATT # Proxy enabled. RX device verifies that the single subnet has exclusive From 6994d092e1103ec8eaa65214d1d87164856334ac Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 26 Jan 2024 21:42:44 +0530 Subject: [PATCH 1130/1623] [nrf fromlist] wifi: shell: Add band support for STA For a Wi-Fi station the connect API supports both band and channel configuration, but for a shell command either channel or band makes sense, so, overload the channel field to support band. Rejig the band and channel validation to support all modes. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68174 Signed-off-by: Chaitanya Tata --- subsys/net/l2/wifi/wifi_shell.c | 53 ++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index d70e48024b7..7428a2a79e5 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -473,7 +473,14 @@ static int __wifi_args_to_params(size_t argc, char *argv[], /* Channel (optional: STA, mandatory: AP) */ if ((idx < argc) && (strlen(argv[idx]) <= 3)) { + uint8_t band; long channel = strtol(argv[idx], &endptr, 10); + const uint8_t all_bands[] = {WIFI_FREQ_BAND_2_4_GHZ, + WIFI_FREQ_BAND_5_GHZ, + WIFI_FREQ_BAND_6_GHZ}; + bool found = false; + char bands_str[MAX_BANDS_STR_LEN] = {0}; + size_t offset = 0; if (*endptr != '\0') { print(context.sh, SHELL_ERROR, @@ -484,23 +491,40 @@ static int __wifi_args_to_params(size_t argc, char *argv[], return -EINVAL; } - if (iface_mode == WIFI_MODE_INFRA && channel == 0) { - params->channel = WIFI_CHANNEL_ANY; + if (iface_mode == WIFI_MODE_INFRA) { + if (channel < 0) { + /* Negative channel means band */ + switch (-channel) { + case 2: + params->band = WIFI_FREQ_BAND_2_4_GHZ; + break; + case 5: + params->band = WIFI_FREQ_BAND_5_GHZ; + break; + case 6: + params->band = WIFI_FREQ_BAND_6_GHZ; + break; + default: + print(context.sh, SHELL_ERROR, + "Invalid band: %ld\n", channel); + return -EINVAL; + } + } } else { - const uint8_t bands[] = {WIFI_FREQ_BAND_2_4_GHZ, - WIFI_FREQ_BAND_5_GHZ, - WIFI_FREQ_BAND_6_GHZ}; - uint8_t band; - bool found = false; - char bands_str[MAX_BANDS_STR_LEN] = {0}; - size_t offset = 0; - - for (band = 0; band < ARRAY_SIZE(bands); band++) { + if (channel < 0) { + print(context.sh, SHELL_ERROR, + "Invalid channel: %ld\n", channel); + return -EINVAL; + } + } + + if (channel > 0) { + for (band = 0; band < ARRAY_SIZE(all_bands); band++) { offset += snprintf(bands_str + offset, sizeof(bands_str) - offset, "%s%s", band ? "," : "", - wifi_band_txt(bands[band])); + wifi_band_txt(all_bands[band])); if (offset >= sizeof(bands_str)) { print(context.sh, SHELL_ERROR, "Failed to parse channel: %s: " @@ -509,7 +533,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[], return -EINVAL; } - if (wifi_utils_validate_chan(bands[band], + if (wifi_utils_validate_chan(all_bands[band], channel)) { found = true; break; @@ -1906,7 +1930,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, SHELL_CMD_ARG(connect, NULL, "Connect to a Wi-Fi AP\n" "\"\"\n" - "[channel number: 0 means all]\n" + "[channel number/band: > 0:Channel, 0:any channel,\n" + "< 0:band (-2:2.4GHz, -5:5GHz, -6:6GHz]\n" "[PSK: valid only for secure SSIDs]\n" "[Security type: valid only for secure SSIDs]\n" "0:None, 1:WPA2-PSK, 2:WPA2-PSK-256, 3:SAE, 4:WAPI, 5:EAP, 6:WEP, 7: WPA-PSK\n" From 96325d267d652738e48d0be694f4b703d6912623 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 31 Jan 2024 11:05:28 +0100 Subject: [PATCH 1131/1623] [nrf fromtree] Bluetooth: BAP: Update log for unicast iso recv without endpoint Since we always set up the ISO data path for endpoints in both directions (due to limitations in the ISO API), we can actually receive valid (empty) SDUs on a CIS in a direction that has not been configured. This is not the ideal solution, but prevents unncessary LOG_ERR. The ideal solution is to modify the ISO API to provide the flexibility that BAP needs w.r.t. ISO data paths, but that is a larger change for later. Signed-off-by: Emil Gydesen (cherry picked from commit 13a357b0198defde8f5c34920bec25b9ea2a0855) Signed-off-by: Alexander Svensen --- subsys/bluetooth/audio/ascs.c | 3 ++- subsys/bluetooth/audio/bap_unicast_client.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 6df91e5f43e..1709bc452d8 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -766,7 +766,8 @@ static void ascs_iso_recv(struct bt_iso_chan *chan, * host as HCI ISO data packets, which we should just ignore */ if ((info->flags & BT_ISO_FLAGS_VALID) != 0) { - LOG_ERR("iso %p not bound with ep", chan); + LOG_DBG("Valid ISO packet of len %zu received for iso %p not bound with ep", + net_buf_frags_len(buf), chan); } return; diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index b6de9b61a66..36938129773 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -231,7 +231,8 @@ static void unicast_client_ep_iso_recv(struct bt_iso_chan *chan, * host as HCI ISO data packets, which we should just ignore */ if ((info->flags & BT_ISO_FLAGS_VALID) != 0) { - LOG_ERR("iso %p not bound with ep", chan); + LOG_DBG("Valid ISO packet of len %zu received for iso %p not bound with ep", + net_buf_frags_len(buf), chan); } return; From 93ad09a7305328387936b68059b63f64efd44f60 Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Fri, 2 Feb 2024 12:49:30 +0100 Subject: [PATCH 1132/1623] [nrf noup] modules: mbedtls: change `EXPERIMENTAL` flags on PSA features that are used by Matter and Thread Thread and Matter use PSA JPAKE and SPAKE2+ APIs underneath. Don't select `EXPERIMENTAL` flags in these cases. Signed-off-by: Maciej Baczmanski --- modules/mbedtls/Kconfig.psa | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 42d2a48825b..9bfb1c9ee07 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -668,12 +668,12 @@ endmenu # PSA Asymmetric support config PSA_WANT_ALG_JPAKE bool prompt "PSA EC J-PAKE support" if !PSA_PROMPTLESS - select EXPERIMENTAL + select EXPERIMENTAL if !NET_L2_OPENTHREAD config PSA_WANT_ALG_SPAKE2P bool prompt "PSA SPAKE2+ support" if !PSA_PROMPTLESS - select EXPERIMENTAL + select EXPERIMENTAL if !CHIP config PSA_WANT_ALG_SRP_6 bool From df133beb17266a409cb25b3ef64cca1ed33a8e9f Mon Sep 17 00:00:00 2001 From: Ajay Parida Date: Thu, 27 Apr 2023 15:40:36 +0530 Subject: [PATCH 1133/1623] [nrf fromtree] net: shell: Early wake up for TWT power save Provision of configurable parameter for generating unblock event ahead of TWT slot. Host application depending upon latencies can configure this to wakeup rpu ahead of the TWT slot. Signed-off-by: Ajay Parida (cherry picked from commit fc959fce475005b0e82ae1cfa91567190c4ff776) --- include/zephyr/net/wifi_mgmt.h | 9 +++++++++ subsys/net/l2/wifi/wifi_shell.c | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index bd8cba81d28..982184a103b 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -498,6 +498,12 @@ struct wifi_twt_params { bool announce; /** Wake up time */ uint32_t twt_wake_interval; + /* Wake ahead notification is sent earlier than + * TWT Service period (SP) start based on this duration. + * This should give applications ample time to + * prepare the data before TWT SP starts. + */ + uint32_t twt_wake_ahead_duration; } setup; /** Teardown specific parameters */ struct { @@ -514,6 +520,7 @@ struct wifi_twt_params { #define WIFI_MAX_TWT_INTERVAL_US (LONG_MAX - 1) /* 256 (u8) * 1TU */ #define WIFI_MAX_TWT_WAKE_INTERVAL_US 262144 +#define WIFI_MAX_TWT_WAKE_AHEAD_DURATION_US (LONG_MAX - 1) /** Wi-Fi TWT flow information */ struct wifi_twt_flow_info { @@ -535,6 +542,8 @@ struct wifi_twt_flow_info { bool announce; /** Wake up time */ uint32_t twt_wake_interval; + /* wake ahead duration */ + uint32_t twt_wake_ahead_duration; }; /** Wi-Fi power save configuration */ diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 7428a2a79e5..2b131d4e0fb 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -975,6 +975,9 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) config.twt_flows[i].trigger, config.twt_flows[i].twt_wake_interval, config.twt_flows[i].twt_interval); + shell_fprintf(context.sh, SHELL_NORMAL, + "TWT Wake ahead duration : %d us\n", + config.twt_flows[i].twt_wake_ahead_duration); } } return 0; @@ -1133,7 +1136,7 @@ static int cmd_wifi_twt_setup(const struct shell *sh, size_t argc, context.sh = sh; - if (argc != 11) { + if (argc != 12) { shell_fprintf(sh, SHELL_WARNING, "Invalid number of arguments\n"); shell_help(sh); return -ENOEXEC; @@ -1193,6 +1196,11 @@ static int cmd_wifi_twt_setup(const struct shell *sh, size_t argc, } params.setup.twt_interval = (uint64_t)value; + if (!parse_number(sh, &value, argv[idx++], 0, WIFI_MAX_TWT_WAKE_AHEAD_DURATION_US)) { + return -EINVAL; + } + params.setup.twt_wake_ahead_duration = (uint32_t)value; + if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { shell_fprintf(sh, SHELL_WARNING, "%s with %s failed. reason : %s\n", wifi_twt_operation_txt(params.operation), @@ -1910,9 +1918,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops, "\n" "\n" " " - " .\n", + " .\n" + ": 0us-2^31us>\n", cmd_wifi_twt_setup, - 11, 0), + 12, 0), SHELL_CMD_ARG(teardown, NULL, " Teardown a TWT flow:\n" "\n" "\n" From 41e34920abf4f6407178d8ce8bd78a882840caec Mon Sep 17 00:00:00 2001 From: Kelly Helmut Lord Date: Thu, 21 Dec 2023 14:00:12 -0500 Subject: [PATCH 1134/1623] [nrf fromtree] drivers: qspi: added operation timeout Added Kconfig assignment of qspi timeout. Per nrfx v3.2 addition of qspi timeout in config struct. Signed-off-by: Kelly Helmut Lord (cherry picked from commit abafe9bbe24c5bb2c377702db1ba3d1d2cd8379a) --- drivers/flash/Kconfig.nordic_qspi_nor | 9 +++++++++ drivers/flash/nrf_qspi_nor.c | 1 + 2 files changed, 10 insertions(+) diff --git a/drivers/flash/Kconfig.nordic_qspi_nor b/drivers/flash/Kconfig.nordic_qspi_nor index aac9830835a..ff652f60822 100644 --- a/drivers/flash/Kconfig.nordic_qspi_nor +++ b/drivers/flash/Kconfig.nordic_qspi_nor @@ -50,4 +50,13 @@ config NORDIC_QSPI_NOR_XIP QSPI NOR flash chip is executed until the driver has been setup. This will also disable power management for the QSPI NOR flash chip. +config NORDIC_QSPI_NOR_TIMEOUT_MS + int "Timeout for QSPI operations (ms)" + default 500 + help + The QSPI peripheral operation timeout in milliseconds. + Primarily intended for long running operations such as + a flash sector erase. The 500 ms default allows for + most typical NOR flash chips to erase a sector. + endif # NORDIC_QSPI_NOR diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index 0e9d4181418..c0e8c397d8e 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -1386,6 +1386,7 @@ static const struct qspi_nor_config qspi_nor_dev_config = { .sck_delay = DT_INST_PROP(0, sck_delay), .spi_mode = INST_0_SPI_MODE, }, + .nrfx_cfg.timeout = CONFIG_NORDIC_QSPI_NOR_TIMEOUT_MS, .size = INST_0_BYTES, .id = DT_INST_PROP(0, jedec_id), From 2d6f48b6db0148155c9b7bd7809d4c73c77a4ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Mon, 30 Oct 2023 15:56:34 +0100 Subject: [PATCH 1135/1623] [nrf fromtree] drivers: pinctrl_nrf: Fix pin drive configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the introduction of nrfx 3.0.0, values of `nrf_gpio_pin_drive_t` constants may be defined differently, depending on the SoC family. Since the nrf-pinctrl.h file is included also from dts files, it is not possible to use there different definitions of `NRF_GPIO_PIN_*` values based on Kconfig symbols that indicate given SoC family (as Kconfig is processed after devicetree) so that those values could still match `nrf_gpio_pin_drive_t` constants. To solve this problem, the pinctrl_nrf driver now uses a lookup table for mapping `NRF_GPIO_PIN_*` indexes to drive configuration values required by the GPIO HAL. Signed-off-by: Andrzej Głąbek (cherry picked from commit 7a9ff701d434801b6e7c4b0c4c118b69ea2adf92) --- drivers/pinctrl/pinctrl_nrf.c | 48 ++++++++++++------- .../zephyr/dt-bindings/pinctrl/nrf-pinctrl.h | 3 +- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/drivers/pinctrl/pinctrl_nrf.c b/drivers/pinctrl/pinctrl_nrf.c index c2ac538c93b..12ee1d52294 100644 --- a/drivers/pinctrl/pinctrl_nrf.c +++ b/drivers/pinctrl/pinctrl_nrf.c @@ -13,19 +13,24 @@ BUILD_ASSERT(((NRF_PULL_NONE == NRF_GPIO_PIN_NOPULL) && (NRF_PULL_UP == NRF_GPIO_PIN_PULLUP)), "nRF pinctrl pull settings do not match HAL values"); -BUILD_ASSERT(((NRF_DRIVE_S0S1 == NRF_GPIO_PIN_S0S1) && - (NRF_DRIVE_H0S1 == NRF_GPIO_PIN_H0S1) && - (NRF_DRIVE_S0H1 == NRF_GPIO_PIN_S0H1) && - (NRF_DRIVE_H0H1 == NRF_GPIO_PIN_H0H1) && - (NRF_DRIVE_D0S1 == NRF_GPIO_PIN_D0S1) && - (NRF_DRIVE_D0H1 == NRF_GPIO_PIN_D0H1) && - (NRF_DRIVE_S0D1 == NRF_GPIO_PIN_S0D1) && - (NRF_DRIVE_H0D1 == NRF_GPIO_PIN_H0D1) && -#if defined(GPIO_PIN_CNF_DRIVE_E0E1) - (NRF_DRIVE_E0E1 == NRF_GPIO_PIN_E0E1) && -#endif /* defined(GPIO_PIN_CNF_DRIVE_E0E1) */ - (1U)), - "nRF pinctrl drive settings do not match HAL values"); +#if defined(GPIO_PIN_CNF_DRIVE_E0E1) || defined(GPIO_PIN_CNF_DRIVE0_E0) +#define NRF_DRIVE_COUNT (NRF_DRIVE_E0E1 + 1) +#else +#define NRF_DRIVE_COUNT (NRF_DRIVE_H0D1 + 1) +#endif +static const nrf_gpio_pin_drive_t drive_modes[NRF_DRIVE_COUNT] = { + [NRF_DRIVE_S0S1] = NRF_GPIO_PIN_S0S1, + [NRF_DRIVE_H0S1] = NRF_GPIO_PIN_H0S1, + [NRF_DRIVE_S0H1] = NRF_GPIO_PIN_S0H1, + [NRF_DRIVE_H0H1] = NRF_GPIO_PIN_H0H1, + [NRF_DRIVE_D0S1] = NRF_GPIO_PIN_D0S1, + [NRF_DRIVE_D0H1] = NRF_GPIO_PIN_D0H1, + [NRF_DRIVE_S0D1] = NRF_GPIO_PIN_S0D1, + [NRF_DRIVE_H0D1] = NRF_GPIO_PIN_H0D1, +#if defined(GPIO_PIN_CNF_DRIVE_E0E1) || defined(GPIO_PIN_CNF_DRIVE0_E0) + [NRF_DRIVE_E0E1] = NRF_GPIO_PIN_E0E1, +#endif +}; /* value to indicate pin level doesn't need initialization */ #define NO_WRITE UINT32_MAX @@ -86,12 +91,19 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg) { for (uint8_t i = 0U; i < pin_cnt; i++) { - nrf_gpio_pin_drive_t drive = NRF_GET_DRIVE(pins[i]); + nrf_gpio_pin_drive_t drive; + uint8_t drive_idx = NRF_GET_DRIVE(pins[i]); uint32_t psel = NRF_GET_PIN(pins[i]); uint32_t write = NO_WRITE; nrf_gpio_pin_dir_t dir; nrf_gpio_pin_input_t input; + if (drive_idx < ARRAY_SIZE(drive_modes)) { + drive = drive_modes[drive_idx]; + } else { + return -EINVAL; + } + if (psel == NRF_PIN_DISCONNECTED) { psel = PSEL_DISCONNECTED; } @@ -165,22 +177,22 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, #if defined(NRF_PSEL_TWIM) case NRF_FUN_TWIM_SCL: NRF_PSEL_TWIM(reg, SCL) = psel; - if (drive == NRF_DRIVE_S0S1) { + if (drive == NRF_GPIO_PIN_S0S1) { /* Override the default drive setting with one * suitable for TWI/TWIM peripherals (S0D1). * This drive cannot be used always so that * users are able to select e.g. H0D1 or E0E1 * in devicetree. */ - drive = NRF_DRIVE_S0D1; + drive = NRF_GPIO_PIN_S0D1; } dir = NRF_GPIO_PIN_DIR_INPUT; input = NRF_GPIO_PIN_INPUT_CONNECT; break; case NRF_FUN_TWIM_SDA: NRF_PSEL_TWIM(reg, SDA) = psel; - if (drive == NRF_DRIVE_S0S1) { - drive = NRF_DRIVE_S0D1; + if (drive == NRF_GPIO_PIN_S0S1) { + drive = NRF_GPIO_PIN_S0D1; } dir = NRF_GPIO_PIN_DIR_INPUT; input = NRF_GPIO_PIN_INPUT_CONNECT; diff --git a/include/zephyr/dt-bindings/pinctrl/nrf-pinctrl.h b/include/zephyr/dt-bindings/pinctrl/nrf-pinctrl.h index b2dcd7ae6c9..9d7f8c2312f 100644 --- a/include/zephyr/dt-bindings/pinctrl/nrf-pinctrl.h +++ b/include/zephyr/dt-bindings/pinctrl/nrf-pinctrl.h @@ -131,7 +131,6 @@ /** * @name nRF pinctrl output drive. - * @note Values match nrf_gpio_pin_drive_t constants. * @{ */ @@ -152,7 +151,7 @@ /** High drive '0', disconnect '1'. */ #define NRF_DRIVE_H0D1 7U /** Extra high drive '0', extra high drive '1'. */ -#define NRF_DRIVE_E0E1 11U +#define NRF_DRIVE_E0E1 8U /** @} */ From 29fcc2e7e45ecac0c926f1dce46b5466e454af59 Mon Sep 17 00:00:00 2001 From: Adam Wojasinski Date: Wed, 15 Nov 2023 14:01:59 +0100 Subject: [PATCH 1136/1623] [nrf fromtree] modules: hal_nordic: watchdog: Add Kconfig symbols for new WDT instances This commit is a part of introduction of new WTD instances. It adds new Kconfig symbols that can be used in WDT shim and nrfx driver. Signed-off-by: Adam Wojasinski (cherry picked from commit 38739368dd449064325ab5ea773390d0becc09f7) --- modules/hal_nordic/nrfx/Kconfig | 15 +++++++++++++++ modules/hal_nordic/nrfx/nrfx_config.h | 9 +++++++++ soc/arm/nordic_nrf/Kconfig.peripherals | 9 +++++++++ 3 files changed, 33 insertions(+) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 5dcda73c9be..c4bfcc2d60e 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -561,6 +561,21 @@ config NRFX_WDT1 depends on $(dt_nodelabel_has_compat,wdt1,$(DT_COMPAT_NORDIC_NRF_WDT)) select NRFX_WDT +config NRFX_WDT30 + bool "WDT30 driver instance" + depends on $(dt_nodelabel_has_compat,wdt30,$(DT_COMPAT_NORDIC_NRF_WDT)) + select NRFX_WDT + +config NRFX_WDT31 + bool "WDT31 driver instance" + depends on $(dt_nodelabel_has_compat,wdt31,$(DT_COMPAT_NORDIC_NRF_WDT)) + select NRFX_WDT + +config NRFX_WDT130 + bool "WDT130 driver instance" + depends on $(dt_nodelabel_has_compat,wdt130,$(DT_COMPAT_NORDIC_NRF_WDT)) + select NRFX_WDT + menu "Peripheral Resource Sharing module" config NRFX_PRS diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index b5b09b96078..a285d1c86db 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -580,6 +580,15 @@ #ifdef CONFIG_NRFX_WDT1 #define NRFX_WDT1_ENABLED 1 #endif +#ifdef CONFIG_NRFX_WDT30 +#define NRFX_WDT30_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_WDT31 +#define NRFX_WDT31_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_WDT130 +#define NRFX_WDT130_ENABLED 1 +#endif #ifdef CONFIG_NRF52_ANOMALY_109_WORKAROUND #define NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 1 diff --git a/soc/arm/nordic_nrf/Kconfig.peripherals b/soc/arm/nordic_nrf/Kconfig.peripherals index 2b7791bf5e6..35b803a2457 100644 --- a/soc/arm/nordic_nrf/Kconfig.peripherals +++ b/soc/arm/nordic_nrf/Kconfig.peripherals @@ -403,3 +403,12 @@ config HAS_HW_NRF_WDT0 config HAS_HW_NRF_WDT1 def_bool $(dt_nodelabel_enabled_with_compat,wdt1,$(DT_COMPAT_NORDIC_NRF_WDT)) + +config HAS_HW_NRF_WDT30 + def_bool $(dt_nodelabel_enabled_with_compat,wdt30,$(DT_COMPAT_NORDIC_NRF_WDT)) + +config HAS_HW_NRF_WDT31 + def_bool $(dt_nodelabel_enabled_with_compat,wdt31,$(DT_COMPAT_NORDIC_NRF_WDT)) + +config HAS_HW_NRF_WDT130 + def_bool $(dt_nodelabel_enabled_with_compat,wdt130,$(DT_COMPAT_NORDIC_NRF_WDT)) From 6b4e21ce24af4bb6ebcdd2065219286593a1da00 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Thu, 4 Jan 2024 16:06:15 +0100 Subject: [PATCH 1137/1623] [nrf fromtree] dts: arm: add new gpiote instances definition Added GPIOTE0, GPIOTE1 instances for legacy devices, GPIOTE20, GPIOTE30 for Moonlight and GPIOTE130, GPIOTE131 instances for Haltium. Signed-off-by: Jakub Zymelka (cherry picked from commit dfbcc8911a94f01de22a90282de5a00b8a30ec12) --- dts/arm/nordic/nrf51822.dtsi | 4 +- dts/arm/nordic/nrf52805.dtsi | 4 +- dts/arm/nordic/nrf52810.dtsi | 4 +- dts/arm/nordic/nrf52811.dtsi | 4 +- dts/arm/nordic/nrf52820.dtsi | 4 +- dts/arm/nordic/nrf52832.dtsi | 4 +- dts/arm/nordic/nrf52833.dtsi | 5 +- dts/arm/nordic/nrf52840.dtsi | 5 +- dts/arm/nordic/nrf5340_cpuapp.dtsi | 17 ++++--- .../nordic/nrf5340_cpuapp_peripherals.dtsi | 2 + .../nordic/nrf5340_cpuapp_peripherals_ns.dtsi | 20 -------- dts/arm/nordic/nrf5340_cpuappns.dtsi | 22 +++++---- dts/arm/nordic/nrf5340_cpunet.dtsi | 5 +- dts/arm/nordic/nrf91.dtsi | 17 ++++++- dts/arm/nordic/nrf91_peripherals.dtsi | 1 + dts/arm/nordic/nrf91ns.dtsi | 9 +++- dts/bindings/gpio/nordic,nrf-gpio.yaml | 5 ++ dts/bindings/gpio/nordic,nrf-gpiote.yaml | 12 +++++ modules/hal_nordic/nrfx/Kconfig | 33 ++++++++++++- modules/hal_nordic/nrfx/nrfx_config.h | 21 ++++++--- .../nrfx/nrfx_config_nrf5340_application.h | 11 ++--- modules/hal_nordic/nrfx/nrfx_config_nrf91.h | 10 ++-- soc/arm/nordic_nrf/Kconfig.peripherals | 19 +++++++- soc/arm/nordic_nrf/common/soc_nrf_common.h | 46 +++++++++++++++++++ soc/arm/nordic_nrf/validate_base_addresses.c | 10 ++++ 25 files changed, 221 insertions(+), 73 deletions(-) delete mode 100644 dts/arm/nordic/nrf5340_cpuapp_peripherals_ns.dtsi diff --git a/dts/arm/nordic/nrf51822.dtsi b/dts/arm/nordic/nrf51822.dtsi index 222ccd4854c..020711a7e7f 100644 --- a/dts/arm/nordic/nrf51822.dtsi +++ b/dts/arm/nordic/nrf51822.dtsi @@ -131,11 +131,12 @@ status = "disabled"; }; - gpiote: gpiote@40006000 { + gpiote: gpiote0: gpiote@40006000 { compatible = "nordic,nrf-gpiote"; reg = <0x40006000 0x1000>; interrupts = <6 NRF_DEFAULT_IRQ_PRIORITY>; status = "disabled"; + instance = <0>; }; adc: adc@40007000 { @@ -316,6 +317,7 @@ #gpio-cells = <2>; status = "disabled"; port = <0>; + gpiote-instance = <&gpiote>; }; }; }; diff --git a/dts/arm/nordic/nrf52805.dtsi b/dts/arm/nordic/nrf52805.dtsi index dd7845588e7..a54e8eca9c6 100644 --- a/dts/arm/nordic/nrf52805.dtsi +++ b/dts/arm/nordic/nrf52805.dtsi @@ -132,11 +132,12 @@ status = "disabled"; }; - gpiote: gpiote@40006000 { + gpiote: gpiote0: gpiote@40006000 { compatible = "nordic,nrf-gpiote"; reg = <0x40006000 0x1000>; interrupts = <6 5>; status = "disabled"; + instance = <0>; }; adc: adc@40007000 { @@ -311,6 +312,7 @@ #gpio-cells = <2>; status = "disabled"; port = <0>; + gpiote-instance = <&gpiote>; }; }; }; diff --git a/dts/arm/nordic/nrf52810.dtsi b/dts/arm/nordic/nrf52810.dtsi index 82f5afb99f6..ce5a2bce779 100644 --- a/dts/arm/nordic/nrf52810.dtsi +++ b/dts/arm/nordic/nrf52810.dtsi @@ -136,11 +136,12 @@ status = "disabled"; }; - gpiote: gpiote@40006000 { + gpiote: gpiote0: gpiote@40006000 { compatible = "nordic,nrf-gpiote"; reg = <0x40006000 0x1000>; interrupts = <6 5>; status = "disabled"; + instance = <0>; }; adc: adc@40007000 { @@ -337,6 +338,7 @@ #gpio-cells = <2>; status = "disabled"; port = <0>; + gpiote-instance = <&gpiote>; }; }; }; diff --git a/dts/arm/nordic/nrf52811.dtsi b/dts/arm/nordic/nrf52811.dtsi index 9e03d5edb32..9c9a3fa6b77 100644 --- a/dts/arm/nordic/nrf52811.dtsi +++ b/dts/arm/nordic/nrf52811.dtsi @@ -167,11 +167,12 @@ status = "disabled"; }; - gpiote: gpiote@40006000 { + gpiote: gpiote0: gpiote@40006000 { compatible = "nordic,nrf-gpiote"; reg = <0x40006000 0x1000>; interrupts = <6 5>; status = "disabled"; + instance = <0>; }; adc: adc@40007000 { @@ -372,6 +373,7 @@ #gpio-cells = <2>; status = "disabled"; port = <0>; + gpiote-instance = <&gpiote>; }; }; }; diff --git a/dts/arm/nordic/nrf52820.dtsi b/dts/arm/nordic/nrf52820.dtsi index 71ff85afbeb..c210a7c23aa 100644 --- a/dts/arm/nordic/nrf52820.dtsi +++ b/dts/arm/nordic/nrf52820.dtsi @@ -180,11 +180,12 @@ status = "disabled"; }; - gpiote: gpiote@40006000 { + gpiote: gpiote0: gpiote@40006000 { compatible = "nordic,nrf-gpiote"; reg = <0x40006000 0x1000>; interrupts = <6 5>; status = "disabled"; + instance = <0>; }; timer0: timer@40008000 { @@ -389,6 +390,7 @@ #gpio-cells = <2>; status = "disabled"; port = <0>; + gpiote-instance = <&gpiote>; }; }; }; diff --git a/dts/arm/nordic/nrf52832.dtsi b/dts/arm/nordic/nrf52832.dtsi index 69de3aa591a..2e1fd68946b 100644 --- a/dts/arm/nordic/nrf52832.dtsi +++ b/dts/arm/nordic/nrf52832.dtsi @@ -179,11 +179,12 @@ status = "okay"; }; - gpiote: gpiote@40006000 { + gpiote: gpiote0: gpiote@40006000 { compatible = "nordic,nrf-gpiote"; reg = <0x40006000 0x1000>; interrupts = <6 5>; status = "disabled"; + instance = <0>; }; adc: adc@40007000 { @@ -465,6 +466,7 @@ #gpio-cells = <2>; status = "disabled"; port = <0>; + gpiote-instance = <&gpiote>; }; }; }; diff --git a/dts/arm/nordic/nrf52833.dtsi b/dts/arm/nordic/nrf52833.dtsi index 8003649385c..d55f0f6df9e 100644 --- a/dts/arm/nordic/nrf52833.dtsi +++ b/dts/arm/nordic/nrf52833.dtsi @@ -186,11 +186,12 @@ status = "okay"; }; - gpiote: gpiote@40006000 { + gpiote: gpiote0: gpiote@40006000 { compatible = "nordic,nrf-gpiote"; reg = <0x40006000 0x1000>; interrupts = <6 5>; status = "disabled"; + instance = <0>; }; adc: adc@40007000 { @@ -521,6 +522,7 @@ #gpio-cells = <2>; status = "disabled"; port = <0>; + gpiote-instance = <&gpiote>; }; gpio1: gpio@50000300 { @@ -532,6 +534,7 @@ ngpios = <10>; status = "disabled"; port = <1>; + gpiote-instance = <&gpiote>; }; }; }; diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index 9e3b79b3abd..2082f16c32a 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -181,11 +181,12 @@ status = "okay"; }; - gpiote: gpiote@40006000 { + gpiote: gpiote0: gpiote@40006000 { compatible = "nordic,nrf-gpiote"; reg = <0x40006000 0x1000>; interrupts = <6 5>; status = "disabled"; + instance = <0>; }; adc: adc@40007000 { @@ -525,6 +526,7 @@ #gpio-cells = <2>; status = "disabled"; port = <0>; + gpiote-instance = <&gpiote>; }; gpio1: gpio@50000300 { @@ -536,6 +538,7 @@ ngpios = <16>; status = "disabled"; port = <1>; + gpiote-instance = <&gpiote>; }; cryptocell: crypto@5002a000 { diff --git a/dts/arm/nordic/nrf5340_cpuapp.dtsi b/dts/arm/nordic/nrf5340_cpuapp.dtsi index a6ae5d4a316..9f122b36f85 100644 --- a/dts/arm/nordic/nrf5340_cpuapp.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp.dtsi @@ -84,6 +84,16 @@ reg = <0x5000d000 0x1000>; interrupts = <13 5>; status = "disabled"; + instance = <0>; + }; + + /* Additional Non-Secure GPIOTE instance */ + gpiote1: gpiote@4002f000 { + compatible = "nordic,nrf-gpiote"; + reg = <0x4002f000 0x1000>; + interrupts = <47 5>; + status = "disabled"; + instance = <1>; }; cryptocell: crypto@50844000 { @@ -104,10 +114,3 @@ &nvic { arm,num-irq-priority-bits = <3>; }; - -/* - * Include the non-secure peripherals file here since - * it expects to be at the root level. This provides - * a node for GPIOTE1. - */ -#include "nrf5340_cpuapp_peripherals_ns.dtsi" diff --git a/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi b/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi index e7aa0309f70..afb839fcef4 100644 --- a/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi @@ -526,6 +526,7 @@ gpio0: gpio@842500 { #gpio-cells = <2>; status = "disabled"; port = <0>; + gpiote-instance = <&gpiote>; }; gpio1: gpio@842800 { @@ -536,6 +537,7 @@ gpio1: gpio@842800 { ngpios = <16>; status = "disabled"; port = <1>; + gpiote-instance = <&gpiote>; }; ieee802154: ieee802154 { diff --git a/dts/arm/nordic/nrf5340_cpuapp_peripherals_ns.dtsi b/dts/arm/nordic/nrf5340_cpuapp_peripherals_ns.dtsi deleted file mode 100644 index 5cfe561e613..00000000000 --- a/dts/arm/nordic/nrf5340_cpuapp_peripherals_ns.dtsi +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * GPIOTE1 is always accessible as a non-secure peripheral. - */ - -/ { - soc { - gpiote1: gpiote@4002f000 { - compatible = "nordic,nrf-gpiote"; - reg = <0x4002f000 0x1000>; - interrupts = <47 5>; - status = "disabled"; - }; - }; -}; diff --git a/dts/arm/nordic/nrf5340_cpuappns.dtsi b/dts/arm/nordic/nrf5340_cpuappns.dtsi index b5278745e5d..aa97c337067 100644 --- a/dts/arm/nordic/nrf5340_cpuappns.dtsi +++ b/dts/arm/nordic/nrf5340_cpuappns.dtsi @@ -48,6 +48,19 @@ */ #include "nrf5340_cpuapp_peripherals.dtsi" }; + + /* + * GPIOTE1 is always accessible as a non-secure peripheral, + * so we give it the 'gpiote' label for use when building + * code for this target. + */ + gpiote: gpiote1: gpiote@4002f000 { + compatible = "nordic,nrf-gpiote"; + reg = <0x4002f000 0x1000>; + interrupts = <47 5>; + status = "disabled"; + instance = <1>; + }; }; /* Default IPC description */ @@ -64,12 +77,3 @@ &nvic { arm,num-irq-priority-bits = <3>; }; - -/* - * Include the non-secure peripherals file here since - * it expects to be at the root level, adding a 'gpiote' label - * for the GPIOTE1 peripheral defined in that file which is - * always accessible as a non-secure peripheral. - */ -#include "nrf5340_cpuapp_peripherals_ns.dtsi" -gpiote: &gpiote1 {}; diff --git a/dts/arm/nordic/nrf5340_cpunet.dtsi b/dts/arm/nordic/nrf5340_cpunet.dtsi index c1e8371d410..d930cf603c0 100644 --- a/dts/arm/nordic/nrf5340_cpunet.dtsi +++ b/dts/arm/nordic/nrf5340_cpunet.dtsi @@ -108,11 +108,12 @@ status = "okay"; }; - gpiote: gpiote@4100a000 { + gpiote: gpiote0: gpiote@4100a000 { compatible = "nordic,nrf-gpiote"; reg = <0x4100a000 0x1000>; interrupts = <10 5>; status = "disabled"; + instance = <0>; }; wdt: wdt0: watchdog@4100b000 { @@ -318,6 +319,7 @@ #gpio-cells = <2>; status = "disabled"; port = <0>; + gpiote-instance = <&gpiote>; }; gpio1: gpio@418c0800 { @@ -328,6 +330,7 @@ ngpios = <16>; status = "disabled"; port = <1>; + gpiote-instance = <&gpiote>; }; }; diff --git a/dts/arm/nordic/nrf91.dtsi b/dts/arm/nordic/nrf91.dtsi index 23d2c7cf20e..2b2fb57850d 100644 --- a/dts/arm/nordic/nrf91.dtsi +++ b/dts/arm/nordic/nrf91.dtsi @@ -61,11 +61,26 @@ status = "okay"; }; - gpiote: gpiote@5000d000 { + /* + * GPIOTE0 is always accessible as a secure peripheral, + * so we give it the 'gpiote' label for use when building + * code for this target. + */ + gpiote: gpiote0: gpiote@5000d000 { compatible = "nordic,nrf-gpiote"; reg = <0x5000d000 0x1000>; interrupts = <13 5>; status = "disabled"; + instance = <0>; + }; + + /* Additional Non-Secure GPIOTE instance */ + gpiote1: gpiote@40031000 { + compatible = "nordic,nrf-gpiote"; + reg = <0x40031000 0x1000>; + interrupts = <49 5>; + status = "disabled"; + instance = <1>; }; spu: spu@50003000 { diff --git a/dts/arm/nordic/nrf91_peripherals.dtsi b/dts/arm/nordic/nrf91_peripherals.dtsi index 2e437eb082d..12e61743bfe 100644 --- a/dts/arm/nordic/nrf91_peripherals.dtsi +++ b/dts/arm/nordic/nrf91_peripherals.dtsi @@ -313,6 +313,7 @@ gpio0: gpio@842500 { #gpio-cells = <2>; status = "disabled"; port = <0>; + gpiote-instance = <&gpiote>; }; rtc0: rtc@14000 { diff --git a/dts/arm/nordic/nrf91ns.dtsi b/dts/arm/nordic/nrf91ns.dtsi index 910f45ec706..23af6ebe37f 100644 --- a/dts/arm/nordic/nrf91ns.dtsi +++ b/dts/arm/nordic/nrf91ns.dtsi @@ -46,12 +46,17 @@ #include "nrf91_peripherals.dtsi" }; - /* Additional Non-Secure peripherals */ - gpiote: gpiote@40031000 { + /* + * GPIOTE1 is always accessible as a non-secure peripheral, + * so we give it the 'gpiote' label for use when building + * code for this target. + */ + gpiote: gpiote1: gpiote@40031000 { compatible = "nordic,nrf-gpiote"; reg = <0x40031000 0x1000>; interrupts = <49 5>; status = "disabled"; + instance = <1>; }; }; diff --git a/dts/bindings/gpio/nordic,nrf-gpio.yaml b/dts/bindings/gpio/nordic,nrf-gpio.yaml index 550acd1a865..097a99d8fa9 100644 --- a/dts/bindings/gpio/nordic,nrf-gpio.yaml +++ b/dts/bindings/gpio/nordic,nrf-gpio.yaml @@ -11,6 +11,11 @@ properties: reg: required: true + gpiote-instance: + type: phandle + description: | + GPIOTE instance that can be used with this GPIO port. + "#gpio-cells": const: 2 diff --git a/dts/bindings/gpio/nordic,nrf-gpiote.yaml b/dts/bindings/gpio/nordic,nrf-gpiote.yaml index 49ddba3595b..cefc3385afe 100644 --- a/dts/bindings/gpio/nordic,nrf-gpiote.yaml +++ b/dts/bindings/gpio/nordic,nrf-gpiote.yaml @@ -13,3 +13,15 @@ properties: interrupts: required: true + + instance: + type: int + required: true + description: | + The GPIOTE instance number. GPIOTE instance GPIOTE0 has: + + instance = <0>; + + And GPIOTE1 has: + + instance = <1>; diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index c4bfcc2d60e..a92aa93d9a2 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -63,8 +63,37 @@ config NRFX_EGU5 select NRFX_EGU config NRFX_GPIOTE - bool "GPIOTE driver" - depends on $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + bool + +config NRFX_GPIOTE0 + bool "GPIOTE0 driver instance" + depends on $(dt_nodelabel_has_compat,gpiote0,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + select NRFX_GPIOTE + +config NRFX_GPIOTE1 + bool "GPIOTE1 driver instance" + depends on $(dt_nodelabel_has_compat,gpiote1,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + select NRFX_GPIOTE + +config NRFX_GPIOTE20 + bool "NRFX_GPIOTE20 driver instance" + depends on $(dt_nodelabel_has_compat,gpiote20,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + select NRFX_GPIOTE + +config NRFX_GPIOTE30 + bool "NRFX_GPIOTE30 driver instance" + depends on $(dt_nodelabel_has_compat,gpiote30,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + select NRFX_GPIOTE + +config NRFX_GPIOTE130 + bool "NRFX_GPIOTE130 driver instance" + depends on $(dt_nodelabel_has_compat,gpiote130,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + select NRFX_GPIOTE + +config NRFX_GPIOTE131 + bool "NRFX_GPIOTE131 driver instance" + depends on $(dt_nodelabel_has_compat,gpiote131,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + select NRFX_GPIOTE config NRFX_GPIOTE_NUM_OF_EVT_HANDLERS int "Number of event handlers" diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index a285d1c86db..72617325684 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -117,15 +117,24 @@ #ifdef CONFIG_NRFX_GPIOTE #define NRFX_GPIOTE_ENABLED 1 -#if (defined(CONFIG_SOC_SERIES_NRF91X) || defined(CONFIG_SOC_SERIES_NRF53X)) \ - && defined(NRF_TRUSTZONE_NONSECURE) -#define NRFX_GPIOTE1_ENABLED 1 -#else +#endif +#ifdef CONFIG_NRFX_GPIOTE0 #define NRFX_GPIOTE0_ENABLED 1 #endif +#ifdef CONFIG_NRFX_GPIOTE1 +#define NRFX_GPIOTE1_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_GPIOTE20 +#define NRFX_GPIOTE20_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_GPIOTE30 +#define NRFX_GPIOTE30_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_GPIOTE130 +#define NRFX_GPIOTE130_ENABLED 1 #endif -#ifdef CONFIG_NRFX_GPIOTE_LOG -#define NRFX_GPIOTE_CONFIG_LOG_ENABLED 1 +#ifdef CONFIG_NRFX_GPIOTE131 +#define NRFX_GPIOTE131_ENABLED 1 #endif #ifdef CONFIG_NRFX_GPIOTE_NUM_OF_EVT_HANDLERS diff --git a/modules/hal_nordic/nrfx/nrfx_config_nrf5340_application.h b/modules/hal_nordic/nrfx/nrfx_config_nrf5340_application.h index 4a42f92ca98..18bcc40b2ac 100644 --- a/modules/hal_nordic/nrfx/nrfx_config_nrf5340_application.h +++ b/modules/hal_nordic/nrfx/nrfx_config_nrf5340_application.h @@ -83,6 +83,7 @@ * between secure and non-secure mapping. */ #if defined(NRF_TRUSTZONE_NONSECURE) +#define NRF_GPIOTE NRF_GPIOTE1 #define NRF_GPIOTE1 NRF_GPIOTE1_NS #else #define NRF_CACHE NRF_CACHE_S @@ -91,20 +92,14 @@ #define NRF_CRYPTOCELL NRF_CRYPTOCELL_S #define NRF_CTI NRF_CTI_S #define NRF_FICR NRF_FICR_S +#define NRF_GPIOTE NRF_GPIOTE0 #define NRF_GPIOTE0 NRF_GPIOTE0_S +#define NRF_GPIOTE1 NRF_GPIOTE1_NS #define NRF_SPU NRF_SPU_S #define NRF_TAD NRF_TAD_S #define NRF_UICR NRF_UICR_S #endif -/* Fixups for the GPIOTE driver. */ -#if defined(NRF_TRUSTZONE_NONSECURE) -#define NRF_GPIOTE NRF_GPIOTE1 -#else -#define NRF_GPIOTE NRF_GPIOTE0 -#endif - - /** * @brief NRFX_DEFAULT_IRQ_PRIORITY * diff --git a/modules/hal_nordic/nrfx/nrfx_config_nrf91.h b/modules/hal_nordic/nrfx/nrfx_config_nrf91.h index 873be583a35..c6029a18628 100644 --- a/modules/hal_nordic/nrfx/nrfx_config_nrf91.h +++ b/modules/hal_nordic/nrfx/nrfx_config_nrf91.h @@ -67,25 +67,21 @@ * between secure and non-secure mapping. */ #if defined(NRF_TRUSTZONE_NONSECURE) +#define NRF_GPIOTE NRF_GPIOTE1 #define NRF_GPIOTE1 NRF_GPIOTE1_NS #else #define NRF_CC_HOST_RGF NRF_CC_HOST_RGF_S #define NRF_CRYPTOCELL NRF_CRYPTOCELL_S #define NRF_CTRL_AP_PERI NRF_CTRL_AP_PERI_S #define NRF_FICR NRF_FICR_S +#define NRF_GPIOTE NRF_GPIOTE0 #define NRF_GPIOTE0 NRF_GPIOTE0_S +#define NRF_GPIOTE1 NRF_GPIOTE1_NS #define NRF_SPU NRF_SPU_S #define NRF_TAD NRF_TAD_S #define NRF_UICR NRF_UICR_S #endif -/* Fixups for the GPIOTE driver. */ -#if defined(NRF_TRUSTZONE_NONSECURE) -#define NRF_GPIOTE NRF_GPIOTE1 -#else -#define NRF_GPIOTE NRF_GPIOTE0 -#endif - /** * @brief NRFX_DEFAULT_IRQ_PRIORITY * diff --git a/soc/arm/nordic_nrf/Kconfig.peripherals b/soc/arm/nordic_nrf/Kconfig.peripherals index 35b803a2457..c9af5604510 100644 --- a/soc/arm/nordic_nrf/Kconfig.peripherals +++ b/soc/arm/nordic_nrf/Kconfig.peripherals @@ -71,8 +71,23 @@ config HAS_HW_NRF_GPIO0 config HAS_HW_NRF_GPIO1 def_bool $(dt_nodelabel_enabled_with_compat,gpio1,$(DT_COMPAT_NORDIC_NRF_GPIO)) -config HAS_HW_NRF_GPIOTE - def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) +config HAS_HW_NRF_GPIOTE0 + def_bool $(dt_nodelabel_enabled_with_compat,gpiote0,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + +config HAS_HW_NRF_GPIOTE1 + def_bool $(dt_nodelabel_enabled_with_compat,gpiote1,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + +config HAS_HW_NRF_GPIOTE20 + def_bool $(dt_nodelabel_enabled_with_compat,gpiote20,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + +config HAS_HW_NRF_GPIOTE30 + def_bool $(dt_nodelabel_enabled_with_compat,gpiote30,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + +config HAS_HW_NRF_GPIOTE130 + def_bool $(dt_nodelabel_enabled_with_compat,gpiote130,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) + +config HAS_HW_NRF_GPIOTE131 + def_bool $(dt_nodelabel_enabled_with_compat,gpiote131,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) config HAS_HW_NRF_I2S0 def_bool $(dt_nodelabel_enabled_with_compat,i2s0,$(DT_COMPAT_NORDIC_NRF_I2S)) diff --git a/soc/arm/nordic_nrf/common/soc_nrf_common.h b/soc/arm/nordic_nrf/common/soc_nrf_common.h index 4c00d7c0237..1e5e603967b 100644 --- a/soc/arm/nordic_nrf/common/soc_nrf_common.h +++ b/soc/arm/nordic_nrf/common/soc_nrf_common.h @@ -149,6 +149,52 @@ (NRF_DT_GPIOS_TO_PSEL(node_id, prop)), \ (default_value)) +/** + * @brief Convert a devicetree GPIO phandle+specifier to GPIOTE instance number. + * + * Some of nRF SoCs may have more instances of GPIOTE. + * To handle this, we use the "gpiote-instance" property of the GPIO node. + * + * This macro converts a devicetree GPIO phandle array value + * "<&gpioX pin ...>" to a GPIOTE instance number. + * + * Examples: + * + * &gpiote0 { + * instance = <0>; + * }; + * + * &gpiote20 { + * instance = <20>; + * }; + * + * &gpio0 { + * gpiote-instance = <&gpiote0>; + * } + * + * &gpio1 { + * gpiote-instance = <&gpiote20>; + * } + * + * foo: my-node { + * tx-gpios = <&gpio0 4 ...>; + * rx-gpios = <&gpio0 5 ...>, <&gpio1 5 ...>; + * }; + * + * NRF_DT_GPIOTE_INST_BY_IDX(DT_NODELABEL(foo), tx_gpios, 0) // = 0 + * NRF_DT_GPIOTE_INST_BY_IDX(DT_NODELABEL(foo), rx_gpios, 1) // = 20 + */ +#define NRF_DT_GPIOTE_INST_BY_IDX(node_id, prop, idx) \ + DT_PROP(DT_PHANDLE(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx), \ + gpiote_instance), \ + instance) + +/** + * @brief Equivalent to NRF_DT_GPIOTE_INST_BY_IDX(node_id, prop, 0) + */ +#define NRF_DT_GPIOTE_INST(node_id, prop) \ + NRF_DT_GPIOTE_INST_BY_IDX(node_id, prop, 0) + /** * Error out the build if 'prop' is set on node 'node_id' and * DT_GPIO_CTLR(node_id, prop) is not an SoC GPIO controller, diff --git a/soc/arm/nordic_nrf/validate_base_addresses.c b/soc/arm/nordic_nrf/validate_base_addresses.c index 58aaa5a7513..ee440c3252c 100644 --- a/soc/arm/nordic_nrf/validate_base_addresses.c +++ b/soc/arm/nordic_nrf/validate_base_addresses.c @@ -16,6 +16,10 @@ #define NRF_CTRLAP NRF_CTRL_AP_PERI #endif +#if !defined(NRF_GPIOTE0) && defined(NRF_GPIOTE) +#define NRF_GPIOTE0 NRF_GPIOTE +#endif + #if !defined(NRF_I2S0) && defined(NRF_I2S) #define NRF_I2S0 NRF_I2S #endif @@ -141,6 +145,12 @@ CHECK_DT_REG(flash_controller, NRF_NVMC); CHECK_DT_REG(gpio0, NRF_P0); CHECK_DT_REG(gpio1, NRF_P1); CHECK_DT_REG(gpiote, NRF_GPIOTE); +CHECK_DT_REG(gpiote0, NRF_GPIOTE0); +CHECK_DT_REG(gpiote1, NRF_GPIOTE1); +CHECK_DT_REG(gpiote20, NRF_GPIOTE20); +CHECK_DT_REG(gpiote30, NRF_GPIOTE30); +CHECK_DT_REG(gpiote130, NRF_GPIOTE130); +CHECK_DT_REG(gpiote131, NRF_GPIOTE131); CHECK_I2C_REG(i2c0, 0); CHECK_I2C_REG(i2c1, 1); CHECK_DT_REG(i2c2, NRF_TWIM2); From 2549254c509dadd16442eb761938959397b95388 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Mon, 6 Nov 2023 13:58:00 +0000 Subject: [PATCH 1138/1623] [nrf fromtree] modules: cmsis: Move cortex_m default configuration to its own file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kconfig parameters, header’s default & silicon vendor’s SDK configuration for CMSIS Core, must be consistent. Depending on the inclusion order of the headers, this is currently not always the case. This change introduces consistency checks & enusers defaults match their Kconfig settings. Signed-off-by: Wilfried Chauveau (cherry picked from commit 8d91ba200fa3460c51c4c4da6e0b2fc2a7676f3c) --- modules/cmsis/cmsis_core_m.h | 88 +--------------- modules/cmsis/cmsis_core_m_defaults.h | 142 ++++++++++++++++++++++++++ soc/arm/arm/mps2/soc.h | 10 +- soc/arm/arm/mps3/soc.h | 15 +-- 4 files changed, 145 insertions(+), 110 deletions(-) create mode 100644 modules/cmsis/cmsis_core_m_defaults.h diff --git a/modules/cmsis/cmsis_core_m.h b/modules/cmsis/cmsis_core_m.h index 880ff614b5b..dc468ada364 100644 --- a/modules/cmsis/cmsis_core_m.h +++ b/modules/cmsis/cmsis_core_m.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2017 Nordic Semiconductor ASA + * Copyright (c) 2023 Arm Limited * * SPDX-License-Identifier: Apache-2.0 */ @@ -18,91 +19,4 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - -/* Fill in CMSIS required values for non-CMSIS compliant SoCs. - * Use __NVIC_PRIO_BITS as it is required and simple to check, but - * ultimately all SoCs will define their own CMSIS types and constants. - */ -#ifndef __NVIC_PRIO_BITS -typedef enum { - Reset_IRQn = -15, - NonMaskableInt_IRQn = -14, - HardFault_IRQn = -13, -#if defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE) - MemoryManagement_IRQn = -12, - BusFault_IRQn = -11, - UsageFault_IRQn = -10, -#if defined(CONFIG_ARM_SECURE_FIRMWARE) - SecureFault_IRQn = -9, -#endif /* CONFIG_ARM_SECURE_FIRMWARE */ -#endif /* CONFIG_ARMV7_M_ARMV8_M_MAINLINE */ - SVCall_IRQn = -5, - DebugMonitor_IRQn = -4, - PendSV_IRQn = -2, - SysTick_IRQn = -1, - Max_IRQn = CONFIG_NUM_IRQS, -} IRQn_Type; - -#if defined(CONFIG_CPU_CORTEX_M0) -#define __CM0_REV 0 -#elif defined(CONFIG_CPU_CORTEX_M0PLUS) -#define __CM0PLUS_REV 0 -#elif defined(CONFIG_CPU_CORTEX_M1) -#define __CM1_REV 0 -#elif defined(CONFIG_CPU_CORTEX_M3) -#define __CM3_REV 0 -#elif defined(CONFIG_CPU_CORTEX_M4) -#define __CM4_REV 0 -#elif defined(CONFIG_CPU_CORTEX_M7) -#define __CM7_REV 0 -#elif defined(CONFIG_CPU_CORTEX_M23) -#define __CM23_REV 0 -#elif defined(CONFIG_CPU_CORTEX_M33) -#define __CM33_REV 0 -#elif defined(CONFIG_CPU_CORTEX_M55) -#define __CM55_REV 0 -#else -#error "Unknown Cortex-M device" -#endif - -#ifndef __MPU_PRESENT -#define __MPU_PRESENT 0U -#endif -#define __NVIC_PRIO_BITS NUM_IRQ_PRIO_BITS -#define __Vendor_SysTickConfig 0 /* Default to standard SysTick */ -#endif /* __NVIC_PRIO_BITS */ - -#if __NVIC_PRIO_BITS != NUM_IRQ_PRIO_BITS -#error "NUM_IRQ_PRIO_BITS and __NVIC_PRIO_BITS are not set to the same value" -#endif - -#ifdef __cplusplus -} -#endif - -#if defined(CONFIG_CPU_CORTEX_M0) -#include -#elif defined(CONFIG_CPU_CORTEX_M0PLUS) -#include -#elif defined(CONFIG_CPU_CORTEX_M1) -#include -#elif defined(CONFIG_CPU_CORTEX_M3) -#include -#elif defined(CONFIG_CPU_CORTEX_M4) -#include -#elif defined(CONFIG_CPU_CORTEX_M7) -#include -#elif defined(CONFIG_CPU_CORTEX_M23) -#include -#elif defined(CONFIG_CPU_CORTEX_M33) -#include -#elif defined(CONFIG_CPU_CORTEX_M55) -#include -#else -#error "Unknown Cortex-M device" -#endif - #endif /* ZEPHYR_MODULES_CMSIS_CMSIS_M_H_ */ diff --git a/modules/cmsis/cmsis_core_m_defaults.h b/modules/cmsis/cmsis_core_m_defaults.h new file mode 100644 index 00000000000..bef62665493 --- /dev/null +++ b/modules/cmsis/cmsis_core_m_defaults.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2017 Nordic Semiconductor ASA + * Copyright (c) 2023 Arm Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief CMSIS interface file + * + * This header populates the default values required to configure the + * ARM CMSIS Core headers. + */ + +#ifndef ZEPHYR_MODULES_CMSIS_CMSIS_M_DEFAULTS_H_ +#define ZEPHYR_MODULES_CMSIS_CMSIS_M_DEFAULTS_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Fill in CMSIS required values for non-CMSIS compliant SoCs. + * Use __NVIC_PRIO_BITS as it is required and simple to check, but + * ultimately all SoCs will define their own CMSIS types and constants. + */ +#ifndef __NVIC_PRIO_BITS +typedef enum { + Reset_IRQn = -15, + NonMaskableInt_IRQn = -14, + HardFault_IRQn = -13, +#if defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE) + MemoryManagement_IRQn = -12, + BusFault_IRQn = -11, + UsageFault_IRQn = -10, +#if defined(CONFIG_ARM_SECURE_FIRMWARE) + SecureFault_IRQn = -9, +#endif /* CONFIG_ARM_SECURE_FIRMWARE */ +#endif /* CONFIG_ARMV7_M_ARMV8_M_MAINLINE */ + SVCall_IRQn = -5, + DebugMonitor_IRQn = -4, + PendSV_IRQn = -2, + SysTick_IRQn = -1, + Max_IRQn = CONFIG_NUM_IRQS, +} IRQn_Type; + +#if defined(CONFIG_CPU_CORTEX_M0) +#define __CM0_REV 0 +#elif defined(CONFIG_CPU_CORTEX_M0PLUS) +#define __CM0PLUS_REV 0 +#elif defined(CONFIG_CPU_CORTEX_M1) +#define __CM1_REV 0 +#elif defined(CONFIG_CPU_CORTEX_M3) +#define __CM3_REV 0 +#elif defined(CONFIG_CPU_CORTEX_M4) +#define __CM4_REV 0 +#elif defined(CONFIG_CPU_CORTEX_M7) +#define __CM7_REV 0 +#elif defined(CONFIG_CPU_CORTEX_M23) +#define __CM23_REV 0 +#elif defined(CONFIG_CPU_CORTEX_M33) +#define __CM33_REV 0 +#elif defined(CONFIG_CPU_CORTEX_M55) +#define __CM55_REV 0 +#else +#error "Unknown Cortex-M device" +#endif + +#define __NVIC_PRIO_BITS NUM_IRQ_PRIO_BITS +#define __Vendor_SysTickConfig 0 /* Default to standard SysTick */ +#endif /* __NVIC_PRIO_BITS */ + +#ifndef __MPU_PRESENT +#define __MPU_PRESENT CONFIG_CPU_HAS_ARM_MPU +#endif + +#ifndef __FPU_PRESENT +#define __FPU_PRESENT CONFIG_CPU_HAS_FPU +#endif + +#ifndef __FPU_DP +#define __FPU_DP CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION +#endif + +#ifndef __VTOR_PRESENT +#define __VTOR_PRESENT CONFIG_CPU_CORTEX_M_HAS_VTOR +#endif + +#ifndef __DSP_PRESENT +#define __DSP_PRESENT CONFIG_ARMV8_M_DSP +#endif + +#ifndef __ICACHE_PRESENT +#define __ICACHE_PRESENT CONFIG_CPU_HAS_ICACHE +#endif + +#ifndef __DCACHE_PRESENT +#define __DCACHE_PRESENT CONFIG_CPU_HAS_DCACHE +#endif + +#ifndef __MVE_PRESENT +#define __MVE_PRESENT CONFIG_ARMV8_1_M_MVEI +#endif + +#ifndef __SAUREGION_PRESENT +#define __SAUREGION_PRESENT CONFIG_CPU_HAS_ARM_SAU +#endif + +#ifndef __PMU_PRESENT +#define __PMU_PRESENT CONFIG_ARMV8_1_M_PMU +#define __PMU_NUM_EVENTCNT CONFIG_ARMV8_1_M_PMU_EVENTCNT +#endif + +#ifdef __cplusplus +} +#endif + +#if defined(CONFIG_CPU_CORTEX_M0) +#include +#elif defined(CONFIG_CPU_CORTEX_M0PLUS) +#include +#elif defined(CONFIG_CPU_CORTEX_M1) +#include +#elif defined(CONFIG_CPU_CORTEX_M3) +#include +#elif defined(CONFIG_CPU_CORTEX_M4) +#include +#elif defined(CONFIG_CPU_CORTEX_M7) +#include +#elif defined(CONFIG_CPU_CORTEX_M23) +#include +#elif defined(CONFIG_CPU_CORTEX_M33) +#include +#elif defined(CONFIG_CPU_CORTEX_M55) +#include +#else +#error "Unknown Cortex-M device" +#endif + +#endif /* ZEPHYR_MODULES_CMSIS_CMSIS_M_DEFAULTS_H_ */ diff --git a/soc/arm/arm/mps2/soc.h b/soc/arm/arm/mps2/soc.h index 594d3d084c1..822c7ee01bd 100644 --- a/soc/arm/arm/mps2/soc.h +++ b/soc/arm/arm/mps2/soc.h @@ -7,15 +7,7 @@ #ifndef _SOC_H_ #define _SOC_H_ -#define __MPU_PRESENT 1 - -#if defined(CONFIG_SOC_MPS2_AN521) -#define __SAUREGION_PRESENT CONFIG_CPU_HAS_ARM_SAU -#define __FPU_PRESENT CONFIG_CPU_HAS_FPU -#define __DSP_PRESENT CONFIG_ARMV8_M_DSP - -#endif - +#include #include extern void wakeup_cpu1(void); diff --git a/soc/arm/arm/mps3/soc.h b/soc/arm/arm/mps3/soc.h index 6a325074cf2..c3a59da1c0d 100644 --- a/soc/arm/arm/mps3/soc.h +++ b/soc/arm/arm/mps3/soc.h @@ -7,19 +7,6 @@ #ifndef _SOC_H_ #define _SOC_H_ -#define __MPU_PRESENT 1 - -#if defined(CONFIG_SOC_MPS3_AN547) -#define __SAUREGION_PRESENT 1U /* SAU regions present */ -#define __FPU_PRESENT CONFIG_CPU_HAS_FPU -#define __DSP_PRESENT 1U /* DSP extension present */ -#define __MVE_PRESENT 1U /* MVE extensions present */ -#define __MVE_FP 1U /* MVE floating point present */ -#define __ICACHE_PRESENT 1U /* ICACHE present */ -#define __DCACHE_PRESENT 1U /* DCACHE present */ -#define __PMU_PRESENT 1U /* PMU present */ -#define __PMU_NUM_EVENTCNT 8U /* PMU Event Counters */ -#endif - +#include #endif /* _SOC_H_ */ From f9aa18ad5eca7bad208c00b9d15e45372fb4ce9b Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Tue, 31 Oct 2023 23:15:26 +0000 Subject: [PATCH 1139/1623] [nrf fromtree] arch: arm: cortex_m: add config for PMU This adds kconfig entries for Performance Monitoring Unit (PMU). Signed-off-by: Wilfried Chauveau (cherry picked from commit a00aa3bcfaeae0bfa69d6154920200ea7a7ab5eb) --- arch/arm/core/cortex_m/Kconfig | 15 ++++++++++++++- soc/arm/arm/mps3/Kconfig.soc | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/arm/core/cortex_m/Kconfig b/arch/arm/core/cortex_m/Kconfig index 95e05604783..61dd3dbba3c 100644 --- a/arch/arm/core/cortex_m/Kconfig +++ b/arch/arm/core/cortex_m/Kconfig @@ -283,7 +283,20 @@ config ARMV8_1_M_MVEF supporting the M-Profile Vector Extension (MVE) floating-point instruction set. -menu "ARM Cortex-M0/M0+/M1/M3/M4/M7/M23/M33 options" +config ARMV8_1_M_PMU + bool + help + This option is enabled when the CPU implements ARMv8-M Performance + Monitoring Unit (PMU). + +config ARMV8_M_PMU_EVENTCNT + int "Number of event counters in the Performance Monitoring Unit" + depends on ARMV8_1_M_PMU + range 2 8 + help + The number of event counters implemented. + +menu "ARM Cortex-M0/M0+/M1/M3/M4/M7/M23/M33/M55 options" depends on ARMV6_M_ARMV8_M_BASELINE || ARMV7_M_ARMV8_M_MAINLINE config GEN_ISR_TABLES diff --git a/soc/arm/arm/mps3/Kconfig.soc b/soc/arm/arm/mps3/Kconfig.soc index 86970e288cc..ae577fa549b 100644 --- a/soc/arm/arm/mps3/Kconfig.soc +++ b/soc/arm/arm/mps3/Kconfig.soc @@ -14,5 +14,10 @@ config SOC_MPS3_AN547 select ARMV8_M_DSP select ARMV8_1_M_MVEI select ARMV8_1_M_MVEF + select ARMV8_1_M_PMU endchoice + +config ARMV8_1_M_PMU_EVENTCNT + int + default 8 if SOC_MPS3_AN547 From 76945792a6387a9029c71954da9c922822a2af7f Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Mon, 6 Nov 2023 14:23:19 +0000 Subject: [PATCH 1140/1623] [nrf fromtree] modules: cmsis: Add consistency checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adds checks to validate consistency between Zephyr’s Kconfig settings and cmsis configuration defined in SiP’s sdk provided headers. This change also introduces a config to enable cmsis’ own checks which emits warnings if a parameter relies on auto-populated default values. Signed-off-by: Wilfried Chauveau (cherry picked from commit 3599fb47e12dd1f16fc620f5915eb408c1ada427) --- modules/cmsis/Kconfig | 7 ++++++ modules/cmsis/cmsis_core_m.h | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/modules/cmsis/Kconfig b/modules/cmsis/Kconfig index 4b5a8ee2855..eff0be6f40c 100644 --- a/modules/cmsis/Kconfig +++ b/modules/cmsis/Kconfig @@ -21,4 +21,11 @@ config HAS_CMSIS_CORE_R config HAS_CMSIS_CORE_M bool +config CMSIS_M_CHECK_DEVICE_DEFINES + bool "Check device defines" + default n + depends on HAS_CMSIS_CORE_M + help + This options enables the validation of CMSIS configuration flags. + endif diff --git a/modules/cmsis/cmsis_core_m.h b/modules/cmsis/cmsis_core_m.h index dc468ada364..e7382633945 100644 --- a/modules/cmsis/cmsis_core_m.h +++ b/modules/cmsis/cmsis_core_m.h @@ -15,8 +15,57 @@ #ifndef ZEPHYR_MODULES_CMSIS_CMSIS_M_H_ #define ZEPHYR_MODULES_CMSIS_CMSIS_M_H_ +#if defined(CONFIG_CMSIS_M_CHECK_DEVICE_DEFINES) && CONFIG_CMSIS_M_CHECK_DEVICE_DEFINES == 1U +#define __CHECK_DEVICE_DEFINES 1U +#endif + #include #include +#if __NVIC_PRIO_BITS != NUM_IRQ_PRIO_BITS +#error "NUM_IRQ_PRIO_BITS and __NVIC_PRIO_BITS are not set to the same value" +#endif + +#if __MPU_PRESENT != CONFIG_CPU_HAS_ARM_MPU +#error "__MPU_PRESENT and CONFIG_CPU_HAS_ARM_MPU are not set to the same value" +#endif + +#if __FPU_PRESENT != CONFIG_CPU_HAS_FPU +#error "__FPU_PRESENT and CONFIG_CPU_HAS_FPU are not set to the same value" +#endif + + +/* VTOR is only optional on armv6-m and armv8-m baseline. __VTOR_PRESENT is often + * left undefined on platform where it is not optional. + */ +#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE) && \ + (__VTOR_PRESENT != CONFIG_CPU_CORTEX_M_HAS_VTOR) +#error "__VTOR_PRESENT and CONFIG_CPU_CORTEX_M_HAS_VTOR are not set to the same value." +#endif + +/* Some platform’s sdk incorrectly define __DSP_PRESENT for Cortex-M4 & Cortex-M7 + * DSP extension. __ARM_FEATURE_DSP is set by the compiler for these. So ignore + * __DSP_PRESENT discrepancy when __ARM_FEATURE_DSP is defined. + */ +#if !defined(__ARM_FEATURE_DSP) && (__DSP_PRESENT != CONFIG_ARMV8_M_DSP) +#error "__DSP_PRESENT and CONFIG_ARMV8_M_DSP are not set to the same value" +#endif + +#if __ICACHE_PRESENT != CONFIG_CPU_HAS_ICACHE +#error "__ICACHE_PRESENT and CONFIG_CPU_HAS_ICACHE are not set to the same value" +#endif + +#if __DCACHE_PRESENT != CONFIG_CPU_HAS_DCACHE +#error "__DCACHE_PRESENT and CONFIG_CPU_HAS_DCACHE are not set to the same value" +#endif + +#if __MVE_PRESENT != CONFIG_ARMV8_1_M_MVEI +#error "__MVE_PRESENT and CONFIG_ARMV8_1_M_MVEI are not set to the same value" +#endif + +#if __SAUREGION_PRESENT != CONFIG_CPU_HAS_ARM_SAU +#error "__SAUREGION_PRESENT and CONFIG_CPU_HAS_ARM_SAU are not set to the same value" +#endif + #endif /* ZEPHYR_MODULES_CMSIS_CMSIS_M_H_ */ From b9bcccf9f65b3f821ce73cfbf04621b9af1088b0 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Tue, 7 Nov 2023 12:57:29 +0000 Subject: [PATCH 1141/1623] [nrf fromtree] soc: arm: fix missing configs & defines Some SoC have missing feature selections in their Kconfig. Some others are missing includes of CMSIS-Core headers. Signed-off-by: Wilfried Chauveau (cherry picked from commit af3a19106afe494f9ca7616e923e2b069e880c71) --- soc/arm/ambiq/apollo4x/Kconfig.series | 1 + soc/arm/arm/designstart/soc.h | 3 +-- soc/arm/arm/musca_s1/Kconfig.soc | 2 ++ soc/arm/aspeed/ast10x0/soc.h | 2 ++ soc/arm/atmel_sam0/samc21/Kconfig.series | 1 + soc/arm/bcm_vk/valkyrie/soc.h | 2 ++ soc/arm/bcm_vk/viper/soc.h | 4 +++- soc/arm/cypress/Kconfig | 3 +++ soc/arm/gigadevice/gd32a50x/Kconfig.series | 1 + soc/arm/gigadevice/gd32e50x/Kconfig.series | 1 + soc/arm/gigadevice/gd32l23x/Kconfig.series | 1 + soc/arm/microchip_mec/mec1501/Kconfig.series | 1 + soc/arm/microchip_mec/mec172x/soc.h | 2 ++ soc/arm/nuvoton_npcx/npcx4/soc.h | 4 +--- soc/arm/nuvoton_npcx/npcx7/soc.h | 4 +--- soc/arm/nuvoton_npcx/npcx9/soc.h | 4 +--- soc/arm/nxp_imx/mcimx6x_m4/Kconfig.series | 1 + soc/arm/nxp_imx/mcimx7_m4/Kconfig.series | 1 + soc/arm/nxp_imx/mimx8mm6_m4/Kconfig.series | 1 + soc/arm/nxp_imx/mimx8mq6_m4/Kconfig.series | 1 + soc/arm/nxp_imx/rt/Kconfig.soc | 4 ++++ soc/arm/nxp_kinetis/kl2x/Kconfig.series | 1 + soc/arm/nxp_kinetis/kwx/Kconfig.series | 1 + soc/arm/nxp_lpc/lpc11u6x/soc.h | 1 + soc/arm/nxp_lpc/lpc51u68/Kconfig.series | 1 + soc/arm/nxp_lpc/lpc51u68/soc.h | 2 ++ soc/arm/nxp_lpc/lpc54xxx/Kconfig.soc | 1 + soc/arm/nxp_lpc/lpc55xxx/Kconfig.soc | 1 + soc/arm/nxp_s32/s32k3/soc.h | 1 + soc/arm/quicklogic_eos_s3/Kconfig.soc | 1 + soc/arm/renesas_ra/common/ra_common_soc.h | 2 ++ soc/arm/renesas_smartbond/da1469x/Kconfig.series | 1 + soc/arm/rpi_pico/rp2/soc.h | 4 +--- soc/arm/silabs_exx32/efm32hg/Kconfig.series | 1 + soc/arm/silabs_exx32/efr32mg21/Kconfig.series | 1 + soc/arm/st_stm32/stm32mp1/Kconfig.series | 1 + soc/arm/ti_k3/am62x_m4/soc.h | 2 ++ soc/arm/ti_lm3s6965/soc.h | 1 + soc/arm/ti_simplelink/cc13x2_cc26x2/soc.h | 4 ++++ soc/arm/ti_simplelink/cc32xx/soc.h | 4 ++++ soc/arm/ti_simplelink/msp432p4xx/Kconfig.series | 1 + 41 files changed, 61 insertions(+), 15 deletions(-) diff --git a/soc/arm/ambiq/apollo4x/Kconfig.series b/soc/arm/ambiq/apollo4x/Kconfig.series index b7982d3609e..a9e72567206 100644 --- a/soc/arm/ambiq/apollo4x/Kconfig.series +++ b/soc/arm/ambiq/apollo4x/Kconfig.series @@ -10,6 +10,7 @@ config SOC_SERIES_APOLLO4X select CPU_CORTEX_M4 select CPU_CORTEX_M_HAS_DWT select CPU_HAS_FPU + select CPU_HAS_ARM_MPU select SOC_FAMILY_AMBIQ select HAS_SWO select AMBIQ_HAL diff --git a/soc/arm/arm/designstart/soc.h b/soc/arm/arm/designstart/soc.h index ec58467f923..a9bcdb4e9cd 100644 --- a/soc/arm/arm/designstart/soc.h +++ b/soc/arm/arm/designstart/soc.h @@ -7,7 +7,6 @@ #ifndef _SOC_H_ #define _SOC_H_ - -#define __MPU_PRESENT CONFIG_CPU_HAS_ARM_MPU +#include #endif /* _SOC_H_ */ diff --git a/soc/arm/arm/musca_s1/Kconfig.soc b/soc/arm/arm/musca_s1/Kconfig.soc index 9bf02614308..0c0763fae2a 100644 --- a/soc/arm/arm/musca_s1/Kconfig.soc +++ b/soc/arm/arm/musca_s1/Kconfig.soc @@ -11,5 +11,7 @@ config SOC_V2M_MUSCA_S1 select CPU_HAS_ARM_SAU select CPU_HAS_ARM_MPU select CPU_CORTEX_M_HAS_DWT + select CPU_HAS_FPU + select ARMV8_M_DSP endchoice diff --git a/soc/arm/aspeed/ast10x0/soc.h b/soc/arm/aspeed/ast10x0/soc.h index f45df84c128..be1cced5da2 100644 --- a/soc/arm/aspeed/ast10x0/soc.h +++ b/soc/arm/aspeed/ast10x0/soc.h @@ -25,4 +25,6 @@ void aspeed_print_sysrst_info(void); +#include + #endif /* ZEPHYR_SOC_ARM_ASPEED_AST10X0_SOC_H_*/ diff --git a/soc/arm/atmel_sam0/samc21/Kconfig.series b/soc/arm/atmel_sam0/samc21/Kconfig.series index 044a7aea229..acb83679e18 100644 --- a/soc/arm/atmel_sam0/samc21/Kconfig.series +++ b/soc/arm/atmel_sam0/samc21/Kconfig.series @@ -10,6 +10,7 @@ config SOC_SERIES_SAMC21 select CPU_CORTEX_M0PLUS select CPU_CORTEX_M_HAS_SYSTICK select CPU_CORTEX_M_HAS_VTOR + select CPU_HAS_ARM_MPU select SOC_FAMILY_SAM0 select PLATFORM_SPECIFIC_INIT select ASF diff --git a/soc/arm/bcm_vk/valkyrie/soc.h b/soc/arm/bcm_vk/valkyrie/soc.h index 26863fbfea0..c3e21a89581 100644 --- a/soc/arm/bcm_vk/valkyrie/soc.h +++ b/soc/arm/bcm_vk/valkyrie/soc.h @@ -292,4 +292,6 @@ typedef enum IRQn { #define PCIE0_PERST_FE_INTR BIT(1) #define PCIE0_PERST_INB_FE_INTR BIT(3) +#include + #endif diff --git a/soc/arm/bcm_vk/viper/soc.h b/soc/arm/bcm_vk/viper/soc.h index 6695e92ef5c..06bf59fb24d 100644 --- a/soc/arm/bcm_vk/viper/soc.h +++ b/soc/arm/bcm_vk/viper/soc.h @@ -9,10 +9,10 @@ #include #include +#include #ifndef _ASMLANGUAGE - /* Interrupt Number Definition */ typedef enum IRQn { /* CORTEX-M7 Processor Exceptions Numbers */ @@ -301,4 +301,6 @@ typedef enum IRQn { #define LS_ICFG_PMON_LITE_SW_RESETN 0x482f0120 #define PCIE_PMON_LITE_SW_RESETN BIT(0) +#include + #endif diff --git a/soc/arm/cypress/Kconfig b/soc/arm/cypress/Kconfig index 352c66b4e76..cb76ccb1090 100644 --- a/soc/arm/cypress/Kconfig +++ b/soc/arm/cypress/Kconfig @@ -12,12 +12,15 @@ config SOC_PSOC6_M0 select CPU_CORTEX_M0PLUS select CPU_CORTEX_M_HAS_SYSTICK select CPU_CORTEX_M_HAS_VTOR + select CPU_HAS_ARM_MPU config SOC_PSOC6_M4 bool "SOC_PSOC6_M4" select CPU_CORTEX_M4 select CPU_CORTEX_M_HAS_DWT select CPU_CORTEX_M_HAS_SYSTICK + select CPU_HAS_ARM_MPU + select CPU_HAS_FPU endchoice diff --git a/soc/arm/gigadevice/gd32a50x/Kconfig.series b/soc/arm/gigadevice/gd32a50x/Kconfig.series index 96fc8c1d0af..2488c643727 100644 --- a/soc/arm/gigadevice/gd32a50x/Kconfig.series +++ b/soc/arm/gigadevice/gd32a50x/Kconfig.series @@ -6,6 +6,7 @@ config SOC_SERIES_GD32A50X select ARM select CPU_HAS_ARM_MPU select CPU_HAS_FPU + select ARMV8_M_DSP select CPU_CORTEX_M33 select SOC_FAMILY_GD32_ARM select GD32_HAS_AF_PINMUX diff --git a/soc/arm/gigadevice/gd32e50x/Kconfig.series b/soc/arm/gigadevice/gd32e50x/Kconfig.series index 8bc3f71118e..546ca456793 100644 --- a/soc/arm/gigadevice/gd32e50x/Kconfig.series +++ b/soc/arm/gigadevice/gd32e50x/Kconfig.series @@ -7,6 +7,7 @@ config SOC_SERIES_GD32E50X select CPU_HAS_ARM_MPU select CPU_HAS_FPU select CPU_CORTEX_M33 + select ARMV8_M_DSP select SOC_FAMILY_GD32_ARM select GD32_HAS_AFIO_PINMUX select GD32_HAS_IRC_40K diff --git a/soc/arm/gigadevice/gd32l23x/Kconfig.series b/soc/arm/gigadevice/gd32l23x/Kconfig.series index 5bdb0dba7d3..d6125ca4152 100644 --- a/soc/arm/gigadevice/gd32l23x/Kconfig.series +++ b/soc/arm/gigadevice/gd32l23x/Kconfig.series @@ -6,6 +6,7 @@ config SOC_SERIES_GD32L23X select ARM select CPU_CORTEX_M23 select CPU_CORTEX_M_HAS_SYSTICK + select CPU_CORTEX_M_HAS_VTOR select SOC_FAMILY_GD32_ARM select GD32_HAS_AF_PINMUX select GD32_HAS_IRC_32K diff --git a/soc/arm/microchip_mec/mec1501/Kconfig.series b/soc/arm/microchip_mec/mec1501/Kconfig.series index d3b679bb557..92dc6f3f8f9 100644 --- a/soc/arm/microchip_mec/mec1501/Kconfig.series +++ b/soc/arm/microchip_mec/mec1501/Kconfig.series @@ -8,6 +8,7 @@ config SOC_SERIES_MEC1501X select ARM select CPU_CORTEX_M4 select CPU_CORTEX_M_HAS_DWT + select CPU_HAS_ARM_MPU select SOC_FAMILY_MEC select HAS_PM help diff --git a/soc/arm/microchip_mec/mec172x/soc.h b/soc/arm/microchip_mec/mec172x/soc.h index 3bf4f533fdb..19afc4e920a 100644 --- a/soc/arm/microchip_mec/mec172x/soc.h +++ b/soc/arm/microchip_mec/mec172x/soc.h @@ -242,6 +242,8 @@ typedef enum { MAX_IRQn } IRQn_Type; +#include + #include /* chip specific register defines */ diff --git a/soc/arm/nuvoton_npcx/npcx4/soc.h b/soc/arm/nuvoton_npcx/npcx4/soc.h index a9d4e88424b..9c780ca034a 100644 --- a/soc/arm/nuvoton_npcx/npcx4/soc.h +++ b/soc/arm/nuvoton_npcx/npcx4/soc.h @@ -7,9 +7,7 @@ #ifndef _NUVOTON_NPCX_SOC_H_ #define _NUVOTON_NPCX_SOC_H_ -/* CMSIS required definitions */ -#define __FPU_PRESENT CONFIG_CPU_HAS_FPU -#define __MPU_PRESENT CONFIG_CPU_HAS_ARM_MPU +#include /* NPCX4 SCFG multi-registers */ #define NPCX_DEVALT_OFFSET(n) (0x010 + n) diff --git a/soc/arm/nuvoton_npcx/npcx7/soc.h b/soc/arm/nuvoton_npcx/npcx7/soc.h index 7099552cec3..9b523ce1b8f 100644 --- a/soc/arm/nuvoton_npcx/npcx7/soc.h +++ b/soc/arm/nuvoton_npcx/npcx7/soc.h @@ -7,9 +7,7 @@ #ifndef _NUVOTON_NPCX_SOC_H_ #define _NUVOTON_NPCX_SOC_H_ -/* CMSIS required definitions */ -#define __FPU_PRESENT CONFIG_CPU_HAS_FPU -#define __MPU_PRESENT CONFIG_CPU_HAS_ARM_MPU +#include /* NPCX7 SCFG multi-registers offset */ #define NPCX_DEVALT_OFFSET(n) (0x010 + n) diff --git a/soc/arm/nuvoton_npcx/npcx9/soc.h b/soc/arm/nuvoton_npcx/npcx9/soc.h index 6b6c3f30a44..2ce745650fb 100644 --- a/soc/arm/nuvoton_npcx/npcx9/soc.h +++ b/soc/arm/nuvoton_npcx/npcx9/soc.h @@ -7,9 +7,7 @@ #ifndef _NUVOTON_NPCX_SOC_H_ #define _NUVOTON_NPCX_SOC_H_ -/* CMSIS required definitions */ -#define __FPU_PRESENT CONFIG_CPU_HAS_FPU -#define __MPU_PRESENT CONFIG_CPU_HAS_ARM_MPU +#include /* NPCX9 SCFG multi-registers */ #define NPCX_DEVALT_OFFSET(n) (0x010 + n) diff --git a/soc/arm/nxp_imx/mcimx6x_m4/Kconfig.series b/soc/arm/nxp_imx/mcimx6x_m4/Kconfig.series index ac0428eff53..7279ac8596e 100644 --- a/soc/arm/nxp_imx/mcimx6x_m4/Kconfig.series +++ b/soc/arm/nxp_imx/mcimx6x_m4/Kconfig.series @@ -11,6 +11,7 @@ config SOC_SERIES_IMX_6X_M4 select HAS_IMX_HAL select SOC_FAMILY_IMX select CPU_HAS_FPU + select CPU_HAS_ARM_MPU select CLOCK_CONTROL help Enable support for M4 core of i.MX 6SoloX MCU series diff --git a/soc/arm/nxp_imx/mcimx7_m4/Kconfig.series b/soc/arm/nxp_imx/mcimx7_m4/Kconfig.series index be0065cb373..e7ae54bcbda 100644 --- a/soc/arm/nxp_imx/mcimx7_m4/Kconfig.series +++ b/soc/arm/nxp_imx/mcimx7_m4/Kconfig.series @@ -11,5 +11,6 @@ config SOC_SERIES_IMX7_M4 select SOC_FAMILY_IMX select CLOCK_CONTROL select CPU_HAS_FPU + select CPU_HAS_ARM_MPU help Enable support for i.MX7 M4 MCU series diff --git a/soc/arm/nxp_imx/mimx8mm6_m4/Kconfig.series b/soc/arm/nxp_imx/mimx8mm6_m4/Kconfig.series index dddb12d1b70..f860a7fbd26 100644 --- a/soc/arm/nxp_imx/mimx8mm6_m4/Kconfig.series +++ b/soc/arm/nxp_imx/mimx8mm6_m4/Kconfig.series @@ -9,5 +9,6 @@ config SOC_SERIES_IMX8MM_M4 select CPU_CORTEX_M4 select SOC_FAMILY_IMX select CPU_HAS_FPU + select CPU_HAS_ARM_MPU help Enable support for i.MX8MM M4 MCU series diff --git a/soc/arm/nxp_imx/mimx8mq6_m4/Kconfig.series b/soc/arm/nxp_imx/mimx8mq6_m4/Kconfig.series index c4b16d3fb5c..3933037c3a0 100644 --- a/soc/arm/nxp_imx/mimx8mq6_m4/Kconfig.series +++ b/soc/arm/nxp_imx/mimx8mq6_m4/Kconfig.series @@ -9,5 +9,6 @@ config SOC_SERIES_IMX8MQ_M4 select CPU_CORTEX_M4 select SOC_FAMILY_IMX select CPU_HAS_FPU + select CPU_HAS_ARM_MPU help Enable support for i.MX8MQ M4 MCU series diff --git a/soc/arm/nxp_imx/rt/Kconfig.soc b/soc/arm/nxp_imx/rt/Kconfig.soc index 0058993e825..96dcd14dc86 100644 --- a/soc/arm/nxp_imx/rt/Kconfig.soc +++ b/soc/arm/nxp_imx/rt/Kconfig.soc @@ -21,6 +21,7 @@ config SOC_MIMXRT1011 select HAS_MCUX_LPUART select HAS_MCUX_GPT select HAS_MCUX_TRNG + select CPU_HAS_FPU select CPU_HAS_ARM_MPU select INIT_ENET_PLL select HAS_MCUX_USB_EHCI @@ -45,6 +46,7 @@ config SOC_MIMXRT1015 select HAS_MCUX_LPUART select HAS_MCUX_GPT select HAS_MCUX_TRNG + select CPU_HAS_FPU select CPU_HAS_FPU_DOUBLE_PRECISION select CPU_HAS_ARM_MPU select INIT_ENET_PLL @@ -368,6 +370,7 @@ config SOC_MIMXRT1176_CM4 select HAS_MCUX_FLEXSPI select HAS_MCUX_LPUART select HAS_MCUX_GPT + select CPU_HAS_FPU select CPU_HAS_ARM_MPU select INIT_ARM_PLL select INIT_ENET_PLL if NET_L2_ETHERNET && ETH_DRIVER @@ -435,6 +438,7 @@ config SOC_MIMXRT1166_CM4 select HAS_MCUX_FLEXSPI select HAS_MCUX_GPT select CPU_HAS_ARM_MPU + select CPU_HAS_FPU select INIT_ARM_PLL select INIT_ENET_PLL if NET_L2_ETHERNET && ETH_DRIVER select INIT_VIDEO_PLL diff --git a/soc/arm/nxp_kinetis/kl2x/Kconfig.series b/soc/arm/nxp_kinetis/kl2x/Kconfig.series index 53558c81648..3c606c7db27 100644 --- a/soc/arm/nxp_kinetis/kl2x/Kconfig.series +++ b/soc/arm/nxp_kinetis/kl2x/Kconfig.series @@ -9,6 +9,7 @@ config SOC_SERIES_KINETIS_KL2X select CPU_CORTEX_M0PLUS select SOC_FAMILY_KINETIS select CPU_CORTEX_M_HAS_SYSTICK + select CPU_CORTEX_M_HAS_VTOR select CLOCK_CONTROL select PLATFORM_SPECIFIC_INIT help diff --git a/soc/arm/nxp_kinetis/kwx/Kconfig.series b/soc/arm/nxp_kinetis/kwx/Kconfig.series index 4b00dd997a9..36ba7b54c21 100644 --- a/soc/arm/nxp_kinetis/kwx/Kconfig.series +++ b/soc/arm/nxp_kinetis/kwx/Kconfig.series @@ -8,6 +8,7 @@ config SOC_SERIES_KINETIS_KWX select ARM select SOC_FAMILY_KINETIS select CPU_CORTEX_M_HAS_SYSTICK + select CPU_CORTEX_M_HAS_VTOR select CLOCK_CONTROL select PLATFORM_SPECIFIC_INIT help diff --git a/soc/arm/nxp_lpc/lpc11u6x/soc.h b/soc/arm/nxp_lpc/lpc11u6x/soc.h index fd7ffbd5400..ec0abb4faf1 100644 --- a/soc/arm/nxp_lpc/lpc11u6x/soc.h +++ b/soc/arm/nxp_lpc/lpc11u6x/soc.h @@ -19,6 +19,7 @@ #ifndef _ASMLANGUAGE #include +#include #endif /* !_ASMLANGUAGE */ diff --git a/soc/arm/nxp_lpc/lpc51u68/Kconfig.series b/soc/arm/nxp_lpc/lpc51u68/Kconfig.series index 6995de0917a..8b1a9dd18b1 100644 --- a/soc/arm/nxp_lpc/lpc51u68/Kconfig.series +++ b/soc/arm/nxp_lpc/lpc51u68/Kconfig.series @@ -13,6 +13,7 @@ config SOC_SERIES_LPC51U68 select HAS_MCUX_SCTIMER select SOC_FAMILY_LPC select CPU_CORTEX_M_HAS_SYSTICK + select CPU_CORTEX_M_HAS_VTOR select PLATFORM_SPECIFIC_INIT help Enable support for LPC LPC51U68 MCU Series diff --git a/soc/arm/nxp_lpc/lpc51u68/soc.h b/soc/arm/nxp_lpc/lpc51u68/soc.h index 45355fb148e..9135c3fed71 100644 --- a/soc/arm/nxp_lpc/lpc51u68/soc.h +++ b/soc/arm/nxp_lpc/lpc51u68/soc.h @@ -10,6 +10,8 @@ #ifndef _ASMLANGUAGE #include +#include + #endif /* !_ASMLANGUAGE*/ #define IOCON_PIO_DIGITAL_EN 0x80u diff --git a/soc/arm/nxp_lpc/lpc54xxx/Kconfig.soc b/soc/arm/nxp_lpc/lpc54xxx/Kconfig.soc index 099dc832d5b..e71bc8f451e 100644 --- a/soc/arm/nxp_lpc/lpc54xxx/Kconfig.soc +++ b/soc/arm/nxp_lpc/lpc54xxx/Kconfig.soc @@ -12,6 +12,7 @@ config SOC_LPC54114_M4 select CPU_CORTEX_M4 select CPU_CORTEX_M_HAS_DWT select CPU_HAS_ARM_MPU + select CPU_HAS_FPU select PLATFORM_SPECIFIC_INIT select CLOCK_CONTROL select HAS_MCUX_IAP_LEGACY diff --git a/soc/arm/nxp_lpc/lpc55xxx/Kconfig.soc b/soc/arm/nxp_lpc/lpc55xxx/Kconfig.soc index c0341a8e9c5..a80374f2d81 100644 --- a/soc/arm/nxp_lpc/lpc55xxx/Kconfig.soc +++ b/soc/arm/nxp_lpc/lpc55xxx/Kconfig.soc @@ -35,6 +35,7 @@ config SOC_LPC55S16 config SOC_LPC55S28 bool "SOC_LPC55S28 M33" select CPU_CORTEX_M33 + select CPU_HAS_ARM_SAU select CPU_HAS_ARM_MPU select CPU_HAS_FPU select ARMV8_M_DSP diff --git a/soc/arm/nxp_s32/s32k3/soc.h b/soc/arm/nxp_s32/s32k3/soc.h index bbc53e18023..9e273ac6816 100644 --- a/soc/arm/nxp_s32/s32k3/soc.h +++ b/soc/arm/nxp_s32/s32k3/soc.h @@ -8,6 +8,7 @@ #define _NXP_S32_S32K_SOC_H_ #include +#include #if defined(CONFIG_CMSIS_RTOS_V2) /* diff --git a/soc/arm/quicklogic_eos_s3/Kconfig.soc b/soc/arm/quicklogic_eos_s3/Kconfig.soc index cb5fd170870..e555933430b 100644 --- a/soc/arm/quicklogic_eos_s3/Kconfig.soc +++ b/soc/arm/quicklogic_eos_s3/Kconfig.soc @@ -7,4 +7,5 @@ config SOC_EOS_S3 select CPU_CORTEX_M4 select CPU_CORTEX_M_HAS_SYSTICK select CPU_HAS_ARM_MPU + select CPU_HAS_FPU select EOS_S3_HAL diff --git a/soc/arm/renesas_ra/common/ra_common_soc.h b/soc/arm/renesas_ra/common/ra_common_soc.h index 60559793743..f76c4c26fc0 100644 --- a/soc/arm/renesas_ra/common/ra_common_soc.h +++ b/soc/arm/renesas_ra/common/ra_common_soc.h @@ -11,6 +11,8 @@ extern "C" { #endif +#include + #ifdef __cplusplus } #endif diff --git a/soc/arm/renesas_smartbond/da1469x/Kconfig.series b/soc/arm/renesas_smartbond/da1469x/Kconfig.series index a3a9e569460..c3672a9ecaf 100644 --- a/soc/arm/renesas_smartbond/da1469x/Kconfig.series +++ b/soc/arm/renesas_smartbond/da1469x/Kconfig.series @@ -8,6 +8,7 @@ config SOC_SERIES_DA1469X select CPU_HAS_FPU select CPU_HAS_ARM_MPU select CPU_CORTEX_M_HAS_SYSTICK + select ARMV8_M_DSP select SOC_FAMILY_SMARTBOND select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE select CLOCK_CONTROL diff --git a/soc/arm/rpi_pico/rp2/soc.h b/soc/arm/rpi_pico/rp2/soc.h index b38d2edf461..0eef4cf92a2 100644 --- a/soc/arm/rpi_pico/rp2/soc.h +++ b/soc/arm/rpi_pico/rp2/soc.h @@ -12,8 +12,6 @@ #ifndef _RPI_PICO_RP2040_SOC_H_ #define _RPI_PICO_RP2040_SOC_H_ - -#define __VTOR_PRESENT CONFIG_CPU_CORTEX_M_HAS_VTOR -#define __MPU_PRESENT CONFIG_CPU_HAS_ARM_MPU +#include #endif /* _RPI_PICO_RP2040_SOC_H_ */ diff --git a/soc/arm/silabs_exx32/efm32hg/Kconfig.series b/soc/arm/silabs_exx32/efm32hg/Kconfig.series index 33793b5386d..d17c24fbcdb 100644 --- a/soc/arm/silabs_exx32/efm32hg/Kconfig.series +++ b/soc/arm/silabs_exx32/efm32hg/Kconfig.series @@ -9,6 +9,7 @@ config SOC_SERIES_EFM32HG select CPU_CORTEX_M0PLUS select SOC_FAMILY_EXX32 select CPU_CORTEX_M_HAS_SYSTICK + select CPU_CORTEX_M_HAS_VTOR select HAS_SILABS_GECKO select SOC_GECKO_CMU select SOC_GECKO_GPIO diff --git a/soc/arm/silabs_exx32/efr32mg21/Kconfig.series b/soc/arm/silabs_exx32/efr32mg21/Kconfig.series index 146493469e8..731658d29e3 100644 --- a/soc/arm/silabs_exx32/efr32mg21/Kconfig.series +++ b/soc/arm/silabs_exx32/efr32mg21/Kconfig.series @@ -11,6 +11,7 @@ config SOC_SERIES_EFR32MG21 select ARMV8_M_DSP select CPU_HAS_FPU select CPU_HAS_ARM_MPU + select CPU_HAS_ARM_SAU select SOC_FAMILY_EXX32 select SOC_GECKO_HAS_RADIO select SOC_GECKO_SERIES2 diff --git a/soc/arm/st_stm32/stm32mp1/Kconfig.series b/soc/arm/st_stm32/stm32mp1/Kconfig.series index 0c6580e84cc..c1576a7ee17 100644 --- a/soc/arm/st_stm32/stm32mp1/Kconfig.series +++ b/soc/arm/st_stm32/stm32mp1/Kconfig.series @@ -11,6 +11,7 @@ config SOC_SERIES_STM32MP1X select SOC_FAMILY_STM32 select HAS_STM32CUBE select CPU_HAS_ARM_MPU + select CPU_HAS_FPU select OPENAMP_RSC_TABLE if RAM_CONSOLE help Enable support for STM32MP1 MPU series diff --git a/soc/arm/ti_k3/am62x_m4/soc.h b/soc/arm/ti_k3/am62x_m4/soc.h index 01ff4b07080..2fd6537b984 100644 --- a/soc/arm/ti_k3/am62x_m4/soc.h +++ b/soc/arm/ti_k3/am62x_m4/soc.h @@ -7,6 +7,8 @@ #ifndef __SOC_H_ #define __SOC_H_ +#include + #include #endif /* __SOC_H */ diff --git a/soc/arm/ti_lm3s6965/soc.h b/soc/arm/ti_lm3s6965/soc.h index bef939013ba..3c353b1a79b 100644 --- a/soc/arm/ti_lm3s6965/soc.h +++ b/soc/arm/ti_lm3s6965/soc.h @@ -15,6 +15,7 @@ #ifndef _BOARD__H_ #define _BOARD__H_ +#include #include /* default system clock */ diff --git a/soc/arm/ti_simplelink/cc13x2_cc26x2/soc.h b/soc/arm/ti_simplelink/cc13x2_cc26x2/soc.h index a1d3504b986..fdc9214732c 100644 --- a/soc/arm/ti_simplelink/cc13x2_cc26x2/soc.h +++ b/soc/arm/ti_simplelink/cc13x2_cc26x2/soc.h @@ -7,6 +7,8 @@ #ifndef TI_SIMPLELINK_CC13X2_CC26X2_SOC_H_ #define TI_SIMPLELINK_CC13X2_CC26X2_SOC_H_ +#include + /* CMSIS required values */ typedef enum { Reset_IRQn = -15, @@ -27,4 +29,6 @@ typedef enum { #define __Vendor_SysTickConfig 0 #define __FPU_PRESENT 1 +#include + #endif /* TI_SIMPLELINK_CC13X2_CC26X2_SOC_H_ */ diff --git a/soc/arm/ti_simplelink/cc32xx/soc.h b/soc/arm/ti_simplelink/cc32xx/soc.h index 9c841e0e4b0..e18dfce626a 100644 --- a/soc/arm/ti_simplelink/cc32xx/soc.h +++ b/soc/arm/ti_simplelink/cc32xx/soc.h @@ -7,6 +7,8 @@ #ifndef TI_SIMPLELINK_CC32XX_SOC_H_ #define TI_SIMPLELINK_CC32XX_SOC_H_ +#include + #include #include @@ -38,4 +40,6 @@ typedef enum { #define __NVIC_PRIO_BITS NUM_IRQ_PRIO_BITS #define __Vendor_SysTickConfig 0 /* Default to standard SysTick */ +#include + #endif /* TI_SIMPLELINK_CC32XX_SOC_H_ */ diff --git a/soc/arm/ti_simplelink/msp432p4xx/Kconfig.series b/soc/arm/ti_simplelink/msp432p4xx/Kconfig.series index 6bb0043ff90..8af48672ed2 100644 --- a/soc/arm/ti_simplelink/msp432p4xx/Kconfig.series +++ b/soc/arm/ti_simplelink/msp432p4xx/Kconfig.series @@ -11,5 +11,6 @@ config SOC_SERIES_MSP432P4XX select DYNAMIC_INTERRUPTS select SOC_FAMILY_TISIMPLELINK select CPU_HAS_FPU + select CPU_HAS_ARM_MPU help Enable support for TI SimpleLink MSP432P4XX. From 717015975e8282ed7b98166814f29e0db2b6bdc1 Mon Sep 17 00:00:00 2001 From: Adam Wojasinski Date: Wed, 19 Jul 2023 15:36:00 +0200 Subject: [PATCH 1142/1623] [nrf fromtree] drivers: watchdog: wdt_nrfx: Add support for new instances Add support for WDT30, WDT31, and WDT130 Signed-off-by: Adam Wojasinski (cherry picked from commit e654cb65b8943cdf5c66c4ad285ca26481a7da69) Signed-off-by: Robert Lubos --- drivers/watchdog/Kconfig.nrfx | 4 ++++ drivers/watchdog/wdt_nrfx.c | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/watchdog/Kconfig.nrfx b/drivers/watchdog/Kconfig.nrfx index 52cf45dc068..2967fe86489 100644 --- a/drivers/watchdog/Kconfig.nrfx +++ b/drivers/watchdog/Kconfig.nrfx @@ -9,5 +9,9 @@ config WDT_NRFX depends on DT_HAS_NORDIC_NRF_WDT_ENABLED select NRFX_WDT0 if HAS_HW_NRF_WDT0 select NRFX_WDT1 if HAS_HW_NRF_WDT1 + select NRFX_WDT30 if HAS_HW_NRF_WDT30 + select NRFX_WDT31 if HAS_HW_NRF_WDT31 + select NRFX_WDT130 if HAS_HW_NRF_WDT130 + help Enable support for nrfx WDT driver for nRF MCU series. diff --git a/drivers/watchdog/wdt_nrfx.c b/drivers/watchdog/wdt_nrfx.c index 98fcb713b81..363a1174e91 100644 --- a/drivers/watchdog/wdt_nrfx.c +++ b/drivers/watchdog/wdt_nrfx.c @@ -202,3 +202,15 @@ WDT_NRFX_WDT_DEVICE(0); #ifdef CONFIG_HAS_HW_NRF_WDT1 WDT_NRFX_WDT_DEVICE(1); #endif + +#ifdef CONFIG_HAS_HW_NRF_WDT30 +WDT_NRFX_WDT_DEVICE(30); +#endif + +#ifdef CONFIG_HAS_HW_NRF_WDT31 +WDT_NRFX_WDT_DEVICE(31); +#endif + +#ifdef CONFIG_HAS_HW_NRF_WDT130 +WDT_NRFX_WDT_DEVICE(130); +#endif From 434667a68cec60ece2becade21b7941547b363c5 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Thu, 4 Jan 2024 15:14:17 +0100 Subject: [PATCH 1143/1623] [nrf fromtree] boards: arm: nrf5340_audio_dk_cpunet_reset: switch to HAL Change the GPIOTE driver to HAL to prevent instantiation issues with a multi-instance GPIOTE driver. Signed-off-by: Jakub Zymelka (cherry picked from commit 7441ff0e7e4f2c8867f0f7b91818eddfe563aab7) Signed-off-by: Robert Lubos --- .../nrf5340_audio_dk_cpunet_reset.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_cpunet_reset.c b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_cpunet_reset.c index 4368ca303fc..f9082e6ca40 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_cpunet_reset.c +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_cpunet_reset.c @@ -10,8 +10,7 @@ #include #include - -#include +#include LOG_MODULE_REGISTER(nrf5340_audio_dk_nrf5340_cpuapp, CONFIG_LOG_DEFAULT_LEVEL); @@ -25,11 +24,11 @@ static int core_config(void) { nrf_gpiote_latency_t latency; - latency = nrfx_gpiote_latency_get(); + latency = nrf_gpiote_latency_get(NRF_GPIOTE); if (latency != NRF_GPIOTE_LATENCY_LOWPOWER) { LOG_DBG("Setting gpiote latency to low power"); - nrfx_gpiote_latency_set(NRF_GPIOTE_LATENCY_LOWPOWER); + nrf_gpiote_latency_set(NRF_GPIOTE, NRF_GPIOTE_LATENCY_LOWPOWER); } return 0; From 7e399018289cb9ff0fb3fe88dfab3086ca31de7e Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Thu, 4 Jan 2024 16:18:40 +0100 Subject: [PATCH 1144/1623] [nrf fromtree] boards: arm: set gpiote status to okay as default After adding new GPIOTE instances, there is a need to enable the instance for individual boards. Signed-off-by: Jakub Zymelka (cherry picked from commit c546c8b96be8f7bf4289ce6bb546bfdf78d5e3fb) Signed-off-by: Robert Lubos --- .../arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi | 4 ++++ boards/arm/bl654_usb/bl654_usb.dts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi index 200db7f94c7..3d31ede313f 100644 --- a/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi +++ b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble-common.dtsi @@ -189,6 +189,10 @@ arduino_spi: &spi2 { status = "okay"; }; +&gpiote { + status = "okay"; +}; + &pwm0 { status = "okay"; pinctrl-0 = <&pwm0_default>; diff --git a/boards/arm/bl654_usb/bl654_usb.dts b/boards/arm/bl654_usb/bl654_usb.dts index 80600290dbf..fa814f4b80e 100644 --- a/boards/arm/bl654_usb/bl654_usb.dts +++ b/boards/arm/bl654_usb/bl654_usb.dts @@ -59,6 +59,10 @@ status = "okay"; }; +&gpiote { + status = "okay"; +}; + &pwm0 { status = "okay"; pinctrl-0 = <&pwm0_default>; From 65d99d10bd76b17647eb83569d6c0eab886122d0 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Mon, 8 Jan 2024 09:45:46 +0100 Subject: [PATCH 1145/1623] [nrf fromtree] modules: hal_nordic: nrfx: update API version to 3.2.0 Updated API version enables multi-instance GPIOTE driver. Additionally obsolete symbol that was used to specify API version in the past was removed. Affected drivers have been adjusted and appropriate changes in affected files have been made. Signed-off-by: Jakub Zymelka (cherry picked from commit ade49f081df6fab0db6288bad25be4f5eff7ef3a) Signed-off-by: Robert Lubos --- drivers/adc/adc_nrfx_saadc.c | 4 +- drivers/display/display_nrf_led_matrix.c | 22 +- drivers/gpio/Kconfig.nrfx | 7 +- drivers/gpio/gpio_nrfx.c | 229 +++++++++++-------- drivers/pwm/pwm_nrf_sw.c | 20 +- drivers/spi/spi_nrfx_common.c | 31 ++- drivers/spi/spi_nrfx_common.h | 11 +- drivers/spi/spi_nrfx_spi.c | 7 +- drivers/spi/spi_nrfx_spim.c | 20 +- drivers/watchdog/wdt_nrfx.c | 16 +- modules/hal_nordic/nrfx/nrfx_config.h | 6 - modules/hal_nordic/nrfx/nrfx_config_common.h | 2 +- samples/boards/nrf/nrfx/Kconfig | 10 + samples/boards/nrf/nrfx/prj.conf | 1 - samples/boards/nrf/nrfx/src/main.c | 51 +++-- 15 files changed, 270 insertions(+), 167 deletions(-) diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index 72a20f47fc9..6d1973ca0aa 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -170,7 +170,7 @@ static void adc_context_update_buffer_pointer(struct adc_context *ctx, if (!repeat) { nrf_saadc_buffer_pointer_set( NRF_SAADC, - nrf_saadc_buffer_pointer_get(NRF_SAADC) + + (uint16_t *)nrf_saadc_buffer_pointer_get(NRF_SAADC) + nrf_saadc_amount_get(NRF_SAADC)); } } @@ -256,7 +256,7 @@ static int check_buffer_size(const struct adc_sequence *sequence, { size_t needed_buffer_size; - needed_buffer_size = active_channels * sizeof(nrf_saadc_value_t); + needed_buffer_size = active_channels * sizeof(uint16_t); if (sequence->options) { needed_buffer_size *= (1 + sequence->options->extra_samplings); } diff --git a/drivers/display/display_nrf_led_matrix.c b/drivers/display/display_nrf_led_matrix.c index dd36126a7ce..e27fb76a92a 100644 --- a/drivers/display/display_nrf_led_matrix.c +++ b/drivers/display/display_nrf_led_matrix.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #ifdef PWM_PRESENT #include @@ -89,6 +90,8 @@ struct display_drv_config { NRF_TIMER_Type *timer; #if USE_PWM NRF_PWM_Type *pwm; +#else + nrfx_gpiote_t gpiote; #endif uint8_t rows[ROW_COUNT]; uint8_t cols[COL_COUNT]; @@ -340,7 +343,7 @@ static void prepare_pixel_pulse(const struct device *dev, /* First timer channel is used for timing the period of pulses. */ nrf_timer_cc_set(dev_config->timer, 1 + channel_idx, pulse); - NRF_GPIOTE->CONFIG[dev_data->gpiote_ch[channel_idx]] = gpiote_cfg; + dev_config->gpiote.p_reg->CONFIG[dev_data->gpiote_ch[channel_idx]] = gpiote_cfg; #endif /* USE_PWM */ } @@ -370,7 +373,7 @@ static void timer_irq_handler(void *arg) } #else for (int i = 0; i < GROUP_SIZE; ++i) { - NRF_GPIOTE->CONFIG[dev_data->gpiote_ch[i]] = 0; + dev_config->gpiote.p_reg->CONFIG[dev_data->gpiote_ch[i]] = 0; } #endif @@ -466,7 +469,7 @@ static int instance_init(const struct device *dev) return -ENOMEM; } - err = nrfx_gpiote_channel_alloc(gpiote_ch); + err = nrfx_gpiote_channel_alloc(&dev_config->gpiote, gpiote_ch); if (err != NRFX_SUCCESS) { LOG_ERR("Failed to allocate GPIOTE channel."); /* Do not bother with freeing resources allocated @@ -479,7 +482,7 @@ static int instance_init(const struct device *dev) nrf_ppi_channel_endpoint_setup(NRF_PPI, ppi_ch, nrf_timer_event_address_get(dev_config->timer, nrf_timer_compare_event_get(1 + i)), - nrf_gpiote_event_address_get(NRF_GPIOTE, + nrf_gpiote_event_address_get(dev_config->gpiote.p_reg, nrf_gpiote_out_task_get(*gpiote_ch))); nrf_ppi_channel_enable(NRF_PPI, ppi_ch); } @@ -530,6 +533,14 @@ static struct display_drv_data instance_data = { .blanking = true, }; +#if !USE_PWM +#define CHECK_GPIOTE_INST(node_id, prop, idx) \ + BUILD_ASSERT(NRF_DT_GPIOTE_INST_BY_IDX(node_id, prop, idx) == \ + NRF_DT_GPIOTE_INST_BY_IDX(node_id, prop, 0), \ + "All column GPIOs must use the same GPIOTE instance"); +DT_FOREACH_PROP_ELEM(MATRIX_NODE, col_gpios, CHECK_GPIOTE_INST) +#endif + #define GET_PIN_INFO(node_id, pha, idx) \ (DT_GPIO_PIN_BY_IDX(node_id, pha, idx) | \ (DT_PROP_BY_PHANDLE_IDX(node_id, pha, idx, port) << 5) | \ @@ -546,6 +557,9 @@ static const struct display_drv_config instance_config = { .timer = (NRF_TIMER_Type *)DT_REG_ADDR(TIMER_NODE), #if USE_PWM .pwm = (NRF_PWM_Type *)DT_REG_ADDR(PWM_NODE), +#else + .gpiote = NRFX_GPIOTE_INSTANCE( + NRF_DT_GPIOTE_INST_BY_IDX(MATRIX_NODE, col_gpios, 0)), #endif .rows = { DT_FOREACH_PROP_ELEM(MATRIX_NODE, row_gpios, GET_PIN_INFO) }, .cols = { DT_FOREACH_PROP_ELEM(MATRIX_NODE, col_gpios, GET_PIN_INFO) }, diff --git a/drivers/gpio/Kconfig.nrfx b/drivers/gpio/Kconfig.nrfx index 356c43cb5fa..760a45204fd 100644 --- a/drivers/gpio/Kconfig.nrfx +++ b/drivers/gpio/Kconfig.nrfx @@ -5,7 +5,12 @@ menuconfig GPIO_NRFX bool "nRF GPIO driver" default y depends on DT_HAS_NORDIC_NRF_GPIO_ENABLED - select NRFX_GPIOTE + select NRFX_GPIOTE0 if HAS_HW_NRF_GPIOTE0 + select NRFX_GPIOTE1 if HAS_HW_NRF_GPIOTE1 + select NRFX_GPIOTE20 if HAS_HW_NRF_GPIOTE20 + select NRFX_GPIOTE30 if HAS_HW_NRF_GPIOTE30 + select NRFX_GPIOTE130 if HAS_HW_NRF_GPIOTE130 + select NRFX_GPIOTE131 if HAS_HW_NRF_GPIOTE131 help Enable GPIO driver for nRF line of MCUs. diff --git a/drivers/gpio/gpio_nrfx.c b/drivers/gpio/gpio_nrfx.c index 0aa282dda37..d89c964cc90 100644 --- a/drivers/gpio/gpio_nrfx.c +++ b/drivers/gpio/gpio_nrfx.c @@ -3,6 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ + #define DT_DRV_COMPAT nordic_nrf_gpio #include @@ -25,6 +26,7 @@ struct gpio_nrfx_cfg { NRF_GPIO_Type *port; uint32_t edge_sense; uint8_t port_num; + nrfx_gpiote_t gpiote; }; static inline struct gpio_nrfx_data *get_port_data(const struct device *port) @@ -37,131 +39,139 @@ static inline const struct gpio_nrfx_cfg *get_port_cfg(const struct device *port return port->config; } -static int get_drive(gpio_flags_t flags, nrf_gpio_pin_drive_t *drive) +static bool has_gpiote(const struct gpio_nrfx_cfg *cfg) +{ + return cfg->gpiote.p_reg != NULL; +} + +static nrf_gpio_pin_pull_t get_pull(gpio_flags_t flags) +{ + if (flags & GPIO_PULL_UP) { + return NRF_GPIO_PIN_PULLUP; + } else if (flags & GPIO_PULL_DOWN) { + return NRF_GPIO_PIN_PULLDOWN; + } + + return NRF_GPIO_PIN_NOPULL; +} + +static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin, + gpio_flags_t flags) { + nrfx_err_t err = NRFX_SUCCESS; + uint8_t ch; + bool free_ch = false; + const struct gpio_nrfx_cfg *cfg = get_port_cfg(port); + nrfx_gpiote_pin_t abs_pin = NRF_GPIO_PIN_MAP(cfg->port_num, pin); + nrf_gpio_pin_pull_t pull = get_pull(flags); + nrf_gpio_pin_drive_t drive; + switch (flags & (NRF_GPIO_DRIVE_MSK | GPIO_OPEN_DRAIN)) { case NRF_GPIO_DRIVE_S0S1: - *drive = NRF_GPIO_PIN_S0S1; + drive = NRF_GPIO_PIN_S0S1; break; case NRF_GPIO_DRIVE_S0H1: - *drive = NRF_GPIO_PIN_S0H1; + drive = NRF_GPIO_PIN_S0H1; break; case NRF_GPIO_DRIVE_H0S1: - *drive = NRF_GPIO_PIN_H0S1; + drive = NRF_GPIO_PIN_H0S1; break; case NRF_GPIO_DRIVE_H0H1: - *drive = NRF_GPIO_PIN_H0H1; + drive = NRF_GPIO_PIN_H0H1; break; case NRF_GPIO_DRIVE_S0 | GPIO_OPEN_DRAIN: - *drive = NRF_GPIO_PIN_S0D1; + drive = NRF_GPIO_PIN_S0D1; break; case NRF_GPIO_DRIVE_H0 | GPIO_OPEN_DRAIN: - *drive = NRF_GPIO_PIN_H0D1; + drive = NRF_GPIO_PIN_H0D1; break; case NRF_GPIO_DRIVE_S1 | GPIO_OPEN_SOURCE: - *drive = NRF_GPIO_PIN_D0S1; + drive = NRF_GPIO_PIN_D0S1; break; case NRF_GPIO_DRIVE_H1 | GPIO_OPEN_SOURCE: - *drive = NRF_GPIO_PIN_D0H1; + drive = NRF_GPIO_PIN_D0H1; break; default: return -EINVAL; } - return 0; -} - -static nrf_gpio_pin_pull_t get_pull(gpio_flags_t flags) -{ - if (flags & GPIO_PULL_UP) { - return NRF_GPIO_PIN_PULLUP; - } else if (flags & GPIO_PULL_DOWN) { - return NRF_GPIO_PIN_PULLDOWN; + if (flags & GPIO_OUTPUT_INIT_HIGH) { + nrf_gpio_port_out_set(cfg->port, BIT(pin)); + } else if (flags & GPIO_OUTPUT_INIT_LOW) { + nrf_gpio_port_out_clear(cfg->port, BIT(pin)); } - return NRF_GPIO_PIN_NOPULL; -} + if (!has_gpiote(cfg)) { + nrf_gpio_pin_dir_t dir = (flags & GPIO_OUTPUT) + ? NRF_GPIO_PIN_DIR_OUTPUT + : NRF_GPIO_PIN_DIR_INPUT; + nrf_gpio_pin_input_t input = (flags & GPIO_INPUT) + ? NRF_GPIO_PIN_INPUT_CONNECT + : NRF_GPIO_PIN_INPUT_DISCONNECT; -static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin, - gpio_flags_t flags) -{ - nrfx_err_t err = NRFX_SUCCESS; - uint8_t ch; - bool free_ch = false; - const struct gpio_nrfx_cfg *cfg = get_port_cfg(port); - nrfx_gpiote_pin_t abs_pin = NRF_GPIO_PIN_MAP(cfg->port_num, pin); + nrf_gpio_reconfigure(abs_pin, &dir, &input, &pull, &drive, NULL); + return 0; + } /* Get the GPIOTE channel associated with this pin, if any. It needs * to be freed when the pin is reconfigured or disconnected. */ if (IS_ENABLED(CONFIG_GPIO_NRFX_INTERRUPT)) { - err = nrfx_gpiote_channel_get(abs_pin, &ch); + err = nrfx_gpiote_channel_get(&cfg->gpiote, abs_pin, &ch); free_ch = (err == NRFX_SUCCESS); } if ((flags & (GPIO_INPUT | GPIO_OUTPUT)) == GPIO_DISCONNECTED) { /* Ignore the error code. The pin may not have been used. */ - (void)nrfx_gpiote_pin_uninit(abs_pin); - - if (free_ch) { - err = nrfx_gpiote_channel_free(ch); - __ASSERT_NO_MSG(err == NRFX_SUCCESS); + (void)nrfx_gpiote_pin_uninit(&cfg->gpiote, abs_pin); + } else { + /* Remove previously configured trigger when pin is reconfigured. */ + if (IS_ENABLED(CONFIG_GPIO_NRFX_INTERRUPT)) { + nrfx_gpiote_trigger_config_t trigger_config = { + .trigger = NRFX_GPIOTE_TRIGGER_NONE, + }; + nrfx_gpiote_input_pin_config_t input_pin_config = { + .p_trigger_config = &trigger_config, + }; + + err = nrfx_gpiote_input_configure(&cfg->gpiote, + abs_pin, &input_pin_config); + if (err != NRFX_SUCCESS) { + return -EINVAL; + } } - return 0; - } - - if (IS_ENABLED(CONFIG_GPIO_NRFX_INTERRUPT)) { - nrfx_gpiote_trigger_config_t trigger_config = { - .trigger = NRFX_GPIOTE_TRIGGER_NONE - }; + if (flags & GPIO_OUTPUT) { + nrfx_gpiote_output_config_t output_config = { + .drive = drive, + .input_connect = (flags & GPIO_INPUT) + ? NRF_GPIO_PIN_INPUT_CONNECT + : NRF_GPIO_PIN_INPUT_DISCONNECT, + .pull = pull, + }; + + err = nrfx_gpiote_output_configure(&cfg->gpiote, + abs_pin, &output_config, NULL); + } else { + nrfx_gpiote_input_pin_config_t input_pin_config = { + .p_pull_config = &pull, + }; + + err = nrfx_gpiote_input_configure(&cfg->gpiote, + abs_pin, &input_pin_config); + } - /* Remove previously configured trigger when pin is reconfigured. */ - err = nrfx_gpiote_input_configure(abs_pin, NULL, &trigger_config, NULL); if (err != NRFX_SUCCESS) { return -EINVAL; } - - if (free_ch) { - err = nrfx_gpiote_channel_free(ch); - __ASSERT_NO_MSG(err == NRFX_SUCCESS); - } } - if (flags & GPIO_OUTPUT) { - nrf_gpio_pin_drive_t drive; - int rv = get_drive(flags, &drive); - - if (rv != 0) { - return rv; - } - - nrfx_gpiote_output_config_t output_config = { - .drive = drive, - .input_connect = (flags & GPIO_INPUT) ? - NRF_GPIO_PIN_INPUT_CONNECT : - NRF_GPIO_PIN_INPUT_DISCONNECT, - .pull = get_pull(flags) - }; - - - if (flags & GPIO_OUTPUT_INIT_HIGH) { - nrf_gpio_port_out_set(cfg->port, BIT(pin)); - } else if (flags & GPIO_OUTPUT_INIT_LOW) { - nrf_gpio_port_out_clear(cfg->port, BIT(pin)); - } - - err = nrfx_gpiote_output_configure(abs_pin, &output_config, NULL); - return (err != NRFX_SUCCESS) ? -EINVAL : 0; + if (IS_ENABLED(CONFIG_GPIO_NRFX_INTERRUPT) && free_ch) { + err = nrfx_gpiote_channel_free(&cfg->gpiote, ch); + __ASSERT_NO_MSG(err == NRFX_SUCCESS); } - nrfx_gpiote_input_config_t input_config = { - .pull = get_pull(flags) - }; - - err = nrfx_gpiote_input_configure(abs_pin, &input_config, NULL, NULL); - - return (err != NRFX_SUCCESS) ? -EINVAL : 0; + return 0; } static int gpio_nrfx_port_get_raw(const struct device *port, @@ -242,12 +252,17 @@ static int gpio_nrfx_pin_interrupt_configure(const struct device *port, enum gpio_int_mode mode, enum gpio_int_trig trig) { - uint32_t abs_pin = NRF_GPIO_PIN_MAP(get_port_cfg(port)->port_num, pin); + const struct gpio_nrfx_cfg *cfg = get_port_cfg(port); + uint32_t abs_pin = NRF_GPIO_PIN_MAP(cfg->port_num, pin); nrfx_err_t err; uint8_t ch; + if (!has_gpiote(cfg)) { + return -ENOTSUP; + } + if (mode == GPIO_INT_MODE_DISABLED) { - nrfx_gpiote_trigger_disable(abs_pin); + nrfx_gpiote_trigger_disable(&cfg->gpiote, abs_pin); return 0; } @@ -255,16 +270,19 @@ static int gpio_nrfx_pin_interrupt_configure(const struct device *port, nrfx_gpiote_trigger_config_t trigger_config = { .trigger = get_trigger(mode, trig), }; + nrfx_gpiote_input_pin_config_t input_pin_config = { + .p_trigger_config = &trigger_config, + }; /* If edge mode is to be used and pin is not configured to use sense for * edge use IN event. */ - if (!(BIT(pin) & get_port_cfg(port)->edge_sense) && + if (!(BIT(pin) & cfg->edge_sense) && (mode == GPIO_INT_MODE_EDGE) && (nrf_gpio_pin_dir_get(abs_pin) == NRF_GPIO_PIN_DIR_INPUT)) { - err = nrfx_gpiote_channel_get(abs_pin, &ch); + err = nrfx_gpiote_channel_get(&cfg->gpiote, abs_pin, &ch); if (err == NRFX_ERROR_INVALID_PARAM) { - err = nrfx_gpiote_channel_alloc(&ch); + err = nrfx_gpiote_channel_alloc(&cfg->gpiote, &ch); if (err != NRFX_SUCCESS) { return -ENOMEM; } @@ -273,12 +291,12 @@ static int gpio_nrfx_pin_interrupt_configure(const struct device *port, trigger_config.p_in_channel = &ch; } - err = nrfx_gpiote_input_configure(abs_pin, NULL, &trigger_config, NULL); + err = nrfx_gpiote_input_configure(&cfg->gpiote, abs_pin, &input_pin_config); if (err != NRFX_SUCCESS) { return -EINVAL; } - nrfx_gpiote_trigger_enable(abs_pin, true); + nrfx_gpiote_trigger_enable(&cfg->gpiote, abs_pin, true); return 0; } @@ -367,26 +385,31 @@ static void nrfx_gpio_handler(nrfx_gpiote_pin_t abs_pin, } #endif /* CONFIG_GPIO_NRFX_INTERRUPT */ -#define GPIOTE_NODE DT_INST(0, nordic_nrf_gpiote) +#define GPIOTE_IRQ_HANDLER_CONNECT(node_id) \ + IRQ_CONNECT(DT_IRQN(node_id), DT_IRQ(node_id, priority), nrfx_isr, \ + NRFX_CONCAT(nrfx_gpiote_, DT_PROP(node_id, instance), _irq_handler), 0); static int gpio_nrfx_init(const struct device *port) { + const struct gpio_nrfx_cfg *cfg = get_port_cfg(port); nrfx_err_t err; - if (nrfx_gpiote_is_init()) { + if (!has_gpiote(cfg)) { + return 0; + } + + if (nrfx_gpiote_init_check(&cfg->gpiote)) { return 0; } - err = nrfx_gpiote_init(0/*not used*/); + err = nrfx_gpiote_init(&cfg->gpiote, 0 /*not used*/); if (err != NRFX_SUCCESS) { return -EIO; } #ifdef CONFIG_GPIO_NRFX_INTERRUPT - nrfx_gpiote_global_callback_set(nrfx_gpio_handler, NULL); - - IRQ_CONNECT(DT_IRQN(GPIOTE_NODE), DT_IRQ(GPIOTE_NODE, priority), - nrfx_isr, nrfx_gpiote_irq_handler, 0); + nrfx_gpiote_global_callback_set(&cfg->gpiote, nrfx_gpio_handler, NULL); + DT_FOREACH_STATUS_OKAY(nordic_nrf_gpiote, GPIOTE_IRQ_HANDLER_CONNECT); #endif /* CONFIG_GPIO_NRFX_INTERRUPT */ return 0; @@ -408,12 +431,27 @@ static const struct gpio_driver_api gpio_nrfx_drv_api_funcs = { #endif }; +#define GPIOTE_PHANDLE(id) DT_INST_PHANDLE(id, gpiote_instance) +#define GPIOTE_INST(id) DT_PROP(GPIOTE_PHANDLE(id), instance) + +#define GPIOTE_INSTANCE(id) \ + COND_CODE_1(DT_INST_NODE_HAS_PROP(id, gpiote_instance), \ + (NRFX_GPIOTE_INSTANCE(GPIOTE_INST(id))), \ + ({ .p_reg = NULL })) + /* Device instantiation is done with node labels because 'port_num' is * the peripheral number by SoC numbering. We therefore cannot use * DT_INST APIs here without wider changes. */ +#define GPIOTE_CHECK(id) \ + COND_CODE_1(DT_INST_NODE_HAS_PROP(id, gpiote_instance), \ + (BUILD_ASSERT(DT_NODE_HAS_STATUS(GPIOTE_PHANDLE(id), okay), \ + "Please enable GPIOTE instance for used GPIO port!")), \ + ()) + #define GPIO_NRF_DEVICE(id) \ + GPIOTE_CHECK(id); \ static const struct gpio_nrfx_cfg gpio_nrfx_p##id##_cfg = { \ .common = { \ .port_pin_mask = \ @@ -421,7 +459,8 @@ static const struct gpio_driver_api gpio_nrfx_drv_api_funcs = { }, \ .port = _CONCAT(NRF_P, DT_INST_PROP(id, port)), \ .port_num = DT_INST_PROP(id, port), \ - .edge_sense = DT_INST_PROP_OR(id, sense_edge_mask, 0) \ + .edge_sense = DT_INST_PROP_OR(id, sense_edge_mask, 0), \ + .gpiote = GPIOTE_INSTANCE(id), \ }; \ \ static struct gpio_nrfx_data gpio_nrfx_p##id##_data; \ diff --git a/drivers/pwm/pwm_nrf_sw.c b/drivers/pwm/pwm_nrf_sw.c index f367bb59899..2b9a22a38f0 100644 --- a/drivers/pwm/pwm_nrf_sw.c +++ b/drivers/pwm/pwm_nrf_sw.c @@ -62,6 +62,7 @@ struct pwm_config { NRF_RTC_Type *rtc; NRF_TIMER_Type *timer; }; + nrfx_gpiote_t gpiote[PWM_0_MAP_SIZE]; uint8_t psel_ch[PWM_0_MAP_SIZE]; uint8_t initially_inverted; uint8_t map_size; @@ -123,6 +124,7 @@ static int pwm_nrf_sw_set_cycles(const struct device *dev, uint32_t channel, const struct pwm_config *config = dev->config; NRF_TIMER_Type *timer = pwm_config_timer(config); NRF_RTC_Type *rtc = pwm_config_rtc(config); + NRF_GPIOTE_Type *gpiote; struct pwm_data *data = dev->data; uint32_t ppi_mask; uint8_t active_level; @@ -161,6 +163,7 @@ static int pwm_nrf_sw_set_cycles(const struct device *dev, uint32_t channel, } } + gpiote = config->gpiote[channel].p_reg; psel_ch = config->psel_ch[channel]; gpiote_ch = data->gpiote_ch[channel]; ppi_chs = data->ppi_ch[channel]; @@ -186,7 +189,7 @@ static int pwm_nrf_sw_set_cycles(const struct device *dev, uint32_t channel, : active_level); /* clear GPIOTE config */ - nrf_gpiote_te_default(NRF_GPIOTE, gpiote_ch); + nrf_gpiote_te_default(gpiote, gpiote_ch); /* No PWM generation for this channel. */ data->pulse_cycles[channel] = 0U; @@ -235,7 +238,7 @@ static int pwm_nrf_sw_set_cycles(const struct device *dev, uint32_t channel, } /* Configure GPIOTE - toggle task with proper initial output value. */ - NRF_GPIOTE->CONFIG[gpiote_ch] = + gpiote->CONFIG[gpiote_ch] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | ((uint32_t)psel_ch << 8) | (GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos) | @@ -256,9 +259,9 @@ static int pwm_nrf_sw_set_cycles(const struct device *dev, uint32_t channel, pulse_end_task = period_end_task = nrf_gpiote_out_task_get(gpiote_ch); #endif uint32_t pulse_end_task_address = - nrf_gpiote_task_address_get(NRF_GPIOTE, pulse_end_task); + nrf_gpiote_task_address_get(gpiote, pulse_end_task); uint32_t period_end_task_address = - nrf_gpiote_task_address_get(NRF_GPIOTE, period_end_task); + nrf_gpiote_task_address_get(gpiote, period_end_task); if (USE_RTC) { uint32_t clear_task_address = @@ -359,7 +362,8 @@ static int pwm_nrf_sw_init(const struct device *dev) } } - err = nrfx_gpiote_channel_alloc(&data->gpiote_ch[i]); + err = nrfx_gpiote_channel_alloc(&config->gpiote[i], + &data->gpiote_ch[i]); if (err != NRFX_SUCCESS) { /* Do not free allocated resource. It is a fatal condition, * system requires reconfiguration. @@ -402,8 +406,14 @@ static int pwm_nrf_sw_init(const struct device *dev) ((DT_GPIO_FLAGS_BY_IDX(_node_id, _prop, _idx) & GPIO_ACTIVE_LOW) \ ? BIT(_idx) : 0) | +#define GPIOTE_AND_COMMA(_node_id, _prop, _idx) \ + NRFX_GPIOTE_INSTANCE(NRF_DT_GPIOTE_INST_BY_IDX(_node_id, _prop, _idx)), + static const struct pwm_config pwm_nrf_sw_0_config = { COND_CODE_1(USE_RTC, (.rtc), (.timer)) = GENERATOR_ADDR, + .gpiote = { + DT_INST_FOREACH_PROP_ELEM(0, channel_gpios, GPIOTE_AND_COMMA) + }, .psel_ch = { DT_INST_FOREACH_PROP_ELEM(0, channel_gpios, PSEL_AND_COMMA) }, diff --git a/drivers/spi/spi_nrfx_common.c b/drivers/spi/spi_nrfx_common.c index 1ef233cfab3..04a11c2367a 100644 --- a/drivers/spi/spi_nrfx_common.c +++ b/drivers/spi/spi_nrfx_common.c @@ -6,40 +6,39 @@ #include "spi_nrfx_common.h" #include -#include -int spi_nrfx_wake_init(uint32_t wake_pin) +int spi_nrfx_wake_init(const nrfx_gpiote_t *gpiote, uint32_t wake_pin) { - nrfx_gpiote_input_config_t input_config = { - .pull = NRF_GPIO_PIN_PULLDOWN, - }; + nrf_gpio_pin_pull_t pull_config = NRF_GPIO_PIN_PULLDOWN; uint8_t ch; nrfx_gpiote_trigger_config_t trigger_config = { .trigger = NRFX_GPIOTE_TRIGGER_HITOLO, .p_in_channel = &ch, }; + nrfx_gpiote_input_pin_config_t input_config = { + .p_pull_config = &pull_config, + .p_trigger_config = &trigger_config, + .p_handler_config = NULL, + }; nrfx_err_t res; - res = nrfx_gpiote_channel_alloc(&ch); + res = nrfx_gpiote_channel_alloc(gpiote, &ch); if (res != NRFX_SUCCESS) { return -ENODEV; } - res = nrfx_gpiote_input_configure(wake_pin, - &input_config, - &trigger_config, - NULL); + res = nrfx_gpiote_input_configure(gpiote, wake_pin, &input_config); if (res != NRFX_SUCCESS) { - nrfx_gpiote_channel_free(ch); + nrfx_gpiote_channel_free(gpiote, ch); return -EIO; } return 0; } -int spi_nrfx_wake_request(uint32_t wake_pin) +int spi_nrfx_wake_request(const nrfx_gpiote_t *gpiote, uint32_t wake_pin) { - nrf_gpiote_event_t trigger_event = nrfx_gpiote_in_event_get(wake_pin); + nrf_gpiote_event_t trigger_event = nrfx_gpiote_in_event_get(gpiote, wake_pin); uint32_t start_cycles; uint32_t max_wait_cycles = DIV_ROUND_UP(CONFIG_SPI_NRFX_WAKE_TIMEOUT_US * @@ -51,7 +50,7 @@ int spi_nrfx_wake_request(uint32_t wake_pin) * The expected time to wait is quite short so it is not worth paying * the overhead of context switching to handle the interrupt. */ - nrfx_gpiote_trigger_enable(wake_pin, false); + nrfx_gpiote_trigger_enable(gpiote, wake_pin, false); /* Enable pull-up on the WAKE line. After the slave device sees the * WAKE line going high, it will force the line to go low. This will * be caught by the enabled trigger and the loop below waits for that. @@ -59,7 +58,7 @@ int spi_nrfx_wake_request(uint32_t wake_pin) nrf_gpio_cfg_input(wake_pin, NRF_GPIO_PIN_PULLUP); start_cycles = k_cycle_get_32(); - while (!nrf_gpiote_event_check(NRF_GPIOTE, trigger_event)) { + while (!nrf_gpiote_event_check(gpiote->p_reg, trigger_event)) { uint32_t elapsed_cycles = k_cycle_get_32() - start_cycles; if (elapsed_cycles >= max_wait_cycles) { @@ -68,7 +67,7 @@ int spi_nrfx_wake_request(uint32_t wake_pin) } } - nrfx_gpiote_trigger_disable(wake_pin); + nrfx_gpiote_trigger_disable(gpiote, wake_pin); nrf_gpio_cfg_input(wake_pin, NRF_GPIO_PIN_PULLDOWN); return err; diff --git a/drivers/spi/spi_nrfx_common.h b/drivers/spi/spi_nrfx_common.h index 515ed5c6f1f..0cf17e2a035 100644 --- a/drivers/spi/spi_nrfx_common.h +++ b/drivers/spi/spi_nrfx_common.h @@ -8,10 +8,17 @@ #define ZEPHYR_DRIVERS_SPI_NRFX_COMMON_H_ #include +#include #define WAKE_PIN_NOT_USED UINT32_MAX -int spi_nrfx_wake_init(uint32_t wake_pin); -int spi_nrfx_wake_request(uint32_t wake_pin); +#define WAKE_GPIOTE_INSTANCE(node_id) \ + COND_CODE_1(DT_NODE_HAS_PROP(node_id, wake_gpios), \ + (NRFX_GPIOTE_INSTANCE( \ + NRF_DT_GPIOTE_INST(node_id, wake_gpios))), \ + ({0})) + +int spi_nrfx_wake_init(const nrfx_gpiote_t *gpiote, uint32_t wake_pin); +int spi_nrfx_wake_request(const nrfx_gpiote_t *gpiote, uint32_t wake_pin); #endif /* ZEPHYR_DRIVERS_SPI_NRFX_COMMON_H_ */ diff --git a/drivers/spi/spi_nrfx_spi.c b/drivers/spi/spi_nrfx_spi.c index fd1dc5d933c..04d7853d11d 100644 --- a/drivers/spi/spi_nrfx_spi.c +++ b/drivers/spi/spi_nrfx_spi.c @@ -31,6 +31,7 @@ struct spi_nrfx_config { void (*irq_connect)(void); const struct pinctrl_dev_config *pcfg; uint32_t wake_pin; + nrfx_gpiote_t wake_gpiote; }; static void event_handler(const nrfx_spi_evt_t *p_event, void *p_context); @@ -237,7 +238,8 @@ static int transceive(const struct device *dev, dev_data->busy = true; if (dev_config->wake_pin != WAKE_PIN_NOT_USED) { - error = spi_nrfx_wake_request(dev_config->wake_pin); + error = spi_nrfx_wake_request(&dev_config->wake_gpiote, + dev_config->wake_pin); if (error == -ETIMEDOUT) { LOG_WRN("Waiting for WAKE acknowledgment timed out"); /* If timeout occurs, try to perform the transfer @@ -381,7 +383,7 @@ static int spi_nrfx_init(const struct device *dev) } if (dev_config->wake_pin != WAKE_PIN_NOT_USED) { - err = spi_nrfx_wake_init(dev_config->wake_pin); + err = spi_nrfx_wake_init(&dev_config->wake_gpiote, dev_config->wake_pin); if (err == -ENODEV) { LOG_ERR("Failed to allocate GPIOTE channel for WAKE"); return err; @@ -444,6 +446,7 @@ static int spi_nrfx_init(const struct device *dev) .pcfg = PINCTRL_DT_DEV_CONFIG_GET(SPI(idx)), \ .wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(SPI(idx), wake_gpios, \ WAKE_PIN_NOT_USED), \ + .wake_gpiote = WAKE_GPIOTE_INSTANCE(SPI(idx)), \ }; \ BUILD_ASSERT(!DT_NODE_HAS_PROP(SPI(idx), wake_gpios) || \ !(DT_GPIO_FLAGS(SPI(idx), wake_gpios) & GPIO_ACTIVE_LOW), \ diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index 8b187f54c52..fb89f096cca 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -9,7 +9,6 @@ #include #include #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 -#include #include #endif #include @@ -61,6 +60,7 @@ struct spi_nrfx_config { bool anomaly_58_workaround; #endif uint32_t wake_pin; + nrfx_gpiote_t wake_gpiote; }; static void event_handler(const nrfx_spim_evt_t *p_event, void *p_context); @@ -204,6 +204,8 @@ static int configure(const struct device *dev, } #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 +static const nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE(0); + /* * Brief Workaround for transmitting 1 byte with SPIM. * @@ -223,15 +225,15 @@ static void anomaly_58_workaround_setup(const struct device *dev) NRF_SPIM_Type *spim = dev_config->spim.p_reg; uint32_t ppi_ch = dev_data->ppi_ch; uint32_t gpiote_ch = dev_data->gpiote_ch; - uint32_t eep = (uint32_t)&NRF_GPIOTE->EVENTS_IN[gpiote_ch]; + uint32_t eep = (uint32_t)&gpiote.p_reg->EVENTS_IN[gpiote_ch]; uint32_t tep = (uint32_t)&spim->TASKS_STOP; dev_data->anomaly_58_workaround_active = true; /* Create an event when SCK toggles */ - nrf_gpiote_event_configure(NRF_GPIOTE, gpiote_ch, spim->PSEL.SCK, + nrf_gpiote_event_configure(gpiote.p_reg, gpiote_ch, spim->PSEL.SCK, GPIOTE_CONFIG_POLARITY_Toggle); - nrf_gpiote_event_enable(NRF_GPIOTE, gpiote_ch); + nrf_gpiote_event_enable(gpiote.p_reg, gpiote_ch); /* Stop the spim instance when SCK toggles */ nrf_ppi_channel_endpoint_setup(NRF_PPI, ppi_ch, eep, tep); @@ -250,7 +252,7 @@ static void anomaly_58_workaround_clear(struct spi_nrfx_data *dev_data) if (dev_data->anomaly_58_workaround_active) { nrf_ppi_channel_disable(NRF_PPI, ppi_ch); - nrf_gpiote_task_disable(NRF_GPIOTE, gpiote_ch); + nrf_gpiote_task_disable(gpiote.p_reg, gpiote_ch); dev_data->anomaly_58_workaround_active = false; } @@ -271,7 +273,7 @@ static int anomaly_58_workaround_init(const struct device *dev) return -ENODEV; } - err_code = nrfx_gpiote_channel_alloc(&dev_data->gpiote_ch); + err_code = nrfx_gpiote_channel_alloc(&gpiote, &dev_data->gpiote_ch); if (err_code != NRFX_SUCCESS) { LOG_ERR("Failed to allocate GPIOTE channel"); return -ENODEV; @@ -399,7 +401,8 @@ static int transceive(const struct device *dev, dev_data->busy = true; if (dev_config->wake_pin != WAKE_PIN_NOT_USED) { - error = spi_nrfx_wake_request(dev_config->wake_pin); + error = spi_nrfx_wake_request(&dev_config->wake_gpiote, + dev_config->wake_pin); if (error == -ETIMEDOUT) { LOG_WRN("Waiting for WAKE acknowledgment timed out"); /* If timeout occurs, try to perform the transfer @@ -547,7 +550,7 @@ static int spi_nrfx_init(const struct device *dev) } if (dev_config->wake_pin != WAKE_PIN_NOT_USED) { - err = spi_nrfx_wake_init(dev_config->wake_pin); + err = spi_nrfx_wake_init(&dev_config->wake_gpiote, dev_config->wake_pin); if (err == -ENODEV) { LOG_ERR("Failed to allocate GPIOTE channel for WAKE"); return err; @@ -634,6 +637,7 @@ static int spi_nrfx_init(const struct device *dev) ()) \ .wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(SPIM(idx), wake_gpios, \ WAKE_PIN_NOT_USED), \ + .wake_gpiote = WAKE_GPIOTE_INSTANCE(SPIM(idx)), \ }; \ BUILD_ASSERT(!DT_NODE_HAS_PROP(SPIM(idx), wake_gpios) || \ !(DT_GPIO_FLAGS(SPIM(idx), wake_gpios) & GPIO_ACTIVE_LOW),\ diff --git a/drivers/watchdog/wdt_nrfx.c b/drivers/watchdog/wdt_nrfx.c index 363a1174e91..8967d1e162b 100644 --- a/drivers/watchdog/wdt_nrfx.c +++ b/drivers/watchdog/wdt_nrfx.c @@ -145,8 +145,12 @@ static const struct wdt_driver_api wdt_nrfx_driver_api = { .feed = wdt_nrf_feed, }; -static void wdt_event_handler(const struct device *dev, uint32_t requests) +static void wdt_event_handler(const struct device *dev, nrf_wdt_event_t event_type, + uint32_t requests, void *p_context) { + (void)event_type; + (void)p_context; + struct wdt_nrfx_data *data = dev->data; while (requests) { @@ -162,9 +166,12 @@ static void wdt_event_handler(const struct device *dev, uint32_t requests) #define WDT(idx) DT_NODELABEL(wdt##idx) #define WDT_NRFX_WDT_DEVICE(idx) \ - static void wdt_##idx##_event_handler(uint32_t requests) \ + static void wdt_##idx##_event_handler(nrf_wdt_event_t event_type, \ + uint32_t requests, \ + void *p_context) \ { \ - wdt_event_handler(DEVICE_DT_GET(WDT(idx)), requests); \ + wdt_event_handler(DEVICE_DT_GET(WDT(idx)), event_type, \ + requests, p_context); \ } \ static int wdt_##idx##_init(const struct device *dev) \ { \ @@ -174,7 +181,8 @@ static void wdt_event_handler(const struct device *dev, uint32_t requests) nrfx_isr, nrfx_wdt_##idx##_irq_handler, 0); \ err_code = nrfx_wdt_init(&config->wdt, \ NULL, \ - wdt_##idx##_event_handler); \ + wdt_##idx##_event_handler, \ + NULL); \ if (err_code != NRFX_SUCCESS) { \ return -EBUSY; \ } \ diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 72617325684..57417644c32 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -9,12 +9,6 @@ #include -/* - * NRFX API version 2.10 flag. - * When the flag is set NRFX API is compatible with the newest NRFX release. - */ -#define NRFX_CONFIG_API_VER_2_10 1 - /* * These are mappings of Kconfig options enabling nrfx drivers and particular * peripheral instances to the corresponding symbols used inside of nrfx. diff --git a/modules/hal_nordic/nrfx/nrfx_config_common.h b/modules/hal_nordic/nrfx/nrfx_config_common.h index 8c0a58713a0..28a3a15b0de 100644 --- a/modules/hal_nordic/nrfx/nrfx_config_common.h +++ b/modules/hal_nordic/nrfx/nrfx_config_common.h @@ -18,7 +18,7 @@ /** @brief Symbol specifying minor version of the nrfx API to be used. */ #ifndef NRFX_CONFIG_API_VER_MINOR -#define NRFX_CONFIG_API_VER_MINOR 0 +#define NRFX_CONFIG_API_VER_MINOR 2 #endif /** @brief Symbol specifying micro version of the nrfx API to be used. */ diff --git a/samples/boards/nrf/nrfx/Kconfig b/samples/boards/nrf/nrfx/Kconfig index 0d54067202a..09076c9da49 100644 --- a/samples/boards/nrf/nrfx/Kconfig +++ b/samples/boards/nrf/nrfx/Kconfig @@ -7,4 +7,14 @@ config NRFX_DPPI config NRFX_PPI default HAS_HW_NRF_PPI +config NRFX_GPIOTE0 + default y if SOC_SERIES_NRF51X || \ + SOC_SERIES_NRF52X || \ + (SOC_SERIES_NRF53X && !TRUSTED_EXECUTION_NONSECURE) || \ + (SOC_SERIES_NRF91X && !TRUSTED_EXECUTION_NONSECURE) + +config NRFX_GPIOTE1 + default y if (SOC_SERIES_NRF53X && TRUSTED_EXECUTION_NONSECURE) || \ + (SOC_SERIES_NRF91X && TRUSTED_EXECUTION_NONSECURE) + source "Kconfig.zephyr" diff --git a/samples/boards/nrf/nrfx/prj.conf b/samples/boards/nrf/nrfx/prj.conf index 32cbfc3279c..d4f0c29699f 100644 --- a/samples/boards/nrf/nrfx/prj.conf +++ b/samples/boards/nrf/nrfx/prj.conf @@ -1,4 +1,3 @@ CONFIG_GPIO=n -CONFIG_NRFX_GPIOTE=y CONFIG_LOG=y CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100 diff --git a/samples/boards/nrf/nrfx/src/main.c b/samples/boards/nrf/nrfx/src/main.c index 615b800545e..0643b1c0911 100644 --- a/samples/boards/nrf/nrfx/src/main.c +++ b/samples/boards/nrf/nrfx/src/main.c @@ -21,6 +21,15 @@ LOG_MODULE_REGISTER(nrfx_sample, LOG_LEVEL_INF); #define INPUT_PIN DT_GPIO_PIN(DT_ALIAS(sw0), gpios) #define OUTPUT_PIN DT_GPIO_PIN(DT_ALIAS(led0), gpios) +#define GPIOTE_INST NRF_DT_GPIOTE_INST(DT_ALIAS(sw0), gpios) +#define GPIOTE_NODE DT_NODELABEL(_CONCAT(gpiote, GPIOTE_INST)) + +BUILD_ASSERT(NRF_DT_GPIOTE_INST(DT_ALIAS(led0), gpios) == GPIOTE_INST, + "Both sw0 and led0 GPIOs must use the same GPIOTE instance"); +BUILD_ASSERT(IS_ENABLED(_CONCAT(CONFIG_, _CONCAT(NRFX_GPIOTE, GPIOTE_INST))), + "NRFX_GPIOTE" STRINGIFY(GPIOTE_INST) " must be enabled in Kconfig"); + + static void button_handler(nrfx_gpiote_pin_t pin, nrfx_gpiote_trigger_t trigger, void *context) @@ -35,28 +44,28 @@ int main(void) nrfx_err_t err; uint8_t in_channel, out_channel; uint8_t ppi_channel; + const nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE(GPIOTE_INST); - /* Connect GPIOTE_0 IRQ to nrfx_gpiote_irq_handler */ - IRQ_CONNECT(DT_IRQN(DT_NODELABEL(gpiote)), - DT_IRQ(DT_NODELABEL(gpiote), priority), - nrfx_isr, nrfx_gpiote_irq_handler, 0); + /* Connect GPIOTE instance IRQ to irq handler */ + IRQ_CONNECT(DT_IRQN(GPIOTE_NODE), DT_IRQ(GPIOTE_NODE, priority), nrfx_isr, + NRFX_CONCAT(nrfx_gpiote_, GPIOTE_INST, _irq_handler), 0); /* Initialize GPIOTE (the interrupt priority passed as the parameter * here is ignored, see nrfx_glue.h). */ - err = nrfx_gpiote_init(0); + err = nrfx_gpiote_init(&gpiote, 0); if (err != NRFX_SUCCESS) { LOG_ERR("nrfx_gpiote_init error: 0x%08X", err); return 0; } - err = nrfx_gpiote_channel_alloc(&in_channel); + err = nrfx_gpiote_channel_alloc(&gpiote, &in_channel); if (err != NRFX_SUCCESS) { LOG_ERR("Failed to allocate in_channel, error: 0x%08X", err); return 0; } - err = nrfx_gpiote_channel_alloc(&out_channel); + err = nrfx_gpiote_channel_alloc(&gpiote, &out_channel); if (err != NRFX_SUCCESS) { LOG_ERR("Failed to allocate out_channel, error: 0x%08X", err); return 0; @@ -65,20 +74,22 @@ int main(void) /* Initialize input pin to generate event on high to low transition * (falling edge) and call button_handler() */ - static const nrfx_gpiote_input_config_t input_config = { - .pull = NRF_GPIO_PIN_PULLUP, - }; - const nrfx_gpiote_trigger_config_t trigger_config = { + static const nrf_gpio_pin_pull_t pull_config = NRF_GPIO_PIN_PULLUP; + nrfx_gpiote_trigger_config_t trigger_config = { .trigger = NRFX_GPIOTE_TRIGGER_HITOLO, .p_in_channel = &in_channel, }; static const nrfx_gpiote_handler_config_t handler_config = { .handler = button_handler, }; - err = nrfx_gpiote_input_configure(INPUT_PIN, - &input_config, - &trigger_config, - &handler_config); + nrfx_gpiote_input_pin_config_t input_config = { + .p_pull_config = &pull_config, + .p_trigger_config = &trigger_config, + .p_handler_config = &handler_config + }; + + err = nrfx_gpiote_input_configure(&gpiote, INPUT_PIN, &input_config); + if (err != NRFX_SUCCESS) { LOG_ERR("nrfx_gpiote_input_configure error: 0x%08X", err); return 0; @@ -97,7 +108,7 @@ int main(void) .polarity = NRF_GPIOTE_POLARITY_TOGGLE, .init_val = 1, }; - err = nrfx_gpiote_output_configure(OUTPUT_PIN, + err = nrfx_gpiote_output_configure(&gpiote, OUTPUT_PIN, &output_config, &task_config); if (err != NRFX_SUCCESS) { @@ -105,8 +116,8 @@ int main(void) return 0; } - nrfx_gpiote_trigger_enable(INPUT_PIN, true); - nrfx_gpiote_out_task_enable(OUTPUT_PIN); + nrfx_gpiote_trigger_enable(&gpiote, INPUT_PIN, true); + nrfx_gpiote_out_task_enable(&gpiote, OUTPUT_PIN); LOG_INF("nrfx_gpiote initialized"); @@ -122,8 +133,8 @@ int main(void) * the button is pressed, the LED pin will be toggled. */ nrfx_gppi_channel_endpoints_setup(ppi_channel, - nrfx_gpiote_in_event_address_get(INPUT_PIN), - nrfx_gpiote_out_task_address_get(OUTPUT_PIN)); + nrfx_gpiote_in_event_address_get(&gpiote, INPUT_PIN), + nrfx_gpiote_out_task_address_get(&gpiote, OUTPUT_PIN)); /* Enable the channel. */ nrfx_gppi_channels_enable(BIT(ppi_channel)); From 500afdbfdb655b3c8bcd54eef3ca405f075aac9f Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Thu, 21 Dec 2023 21:07:00 +0100 Subject: [PATCH 1146/1623] [nrf fromtree] manifest: hal_nordic: update revision to have nrfx 3.3.0 release New hal_nordic revision contains nrfx 3.3.0 which adds support for nRF54H20 EngA and nRF54L15 EngA devices. Signed-off-by: Nikodem Kastelik (cherry picked from commit c8d22cf13ae05e03695330bd34669af3c1336ea7) Signed-off-by: Robert Lubos --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index ea8352aa7cf..2697b445524 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 3786c55424d4d64c62dd25219de31618cef26fdf + revision: b55cfbbf0221d709560c2e438beef66842ada272 path: modules/hal/nordic groups: - hal From 6c7e834afa72ef9b2e35d78d05c6f4bf3827347d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Wed, 8 Nov 2023 13:33:57 +0100 Subject: [PATCH 1147/1623] [nrf fromtree] drivers: serial: Add async to interrupt driven adaptation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add adaptation layer which allows to provide interrupt driven API for drivers which exposes only asynchronous API. Signed-off-by: Krzysztof Chruściński (cherry picked from commit 2854fc18fdbd626e9486a9808b598702198856a0) Signed-off-by: Robert Lubos --- drivers/serial/CMakeLists.txt | 1 + drivers/serial/Kconfig | 15 + drivers/serial/uart_async_to_irq.c | 377 ++++++++++++++++++ .../zephyr/drivers/serial/uart_async_to_irq.h | 285 +++++++++++++ 4 files changed, 678 insertions(+) create mode 100644 drivers/serial/uart_async_to_irq.c create mode 100644 include/zephyr/drivers/serial/uart_async_to_irq.h diff --git a/drivers/serial/CMakeLists.txt b/drivers/serial/CMakeLists.txt index bfc38603864..2cd79e12f64 100644 --- a/drivers/serial/CMakeLists.txt +++ b/drivers/serial/CMakeLists.txt @@ -93,3 +93,4 @@ endif() zephyr_library_sources_ifdef(CONFIG_SERIAL_TEST serial_test.c) zephyr_library_sources_ifdef(CONFIG_UART_ASYNC_RX_HELPER uart_async_rx.c) +zephyr_library_sources_ifdef(CONFIG_UART_ASYNC_TO_INT_DRIVEN_API uart_async_to_irq.c) diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 5eb183c9a3e..2d097932cf4 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -133,6 +133,21 @@ config UART_ASYNC_RX_HELPER is delayed. Module implements zero-copy approach with multiple reception buffers. +config UART_ASYNC_TO_INT_DRIVEN_API + bool + select UART_ASYNC_RX_HELPER + help + Asynchronous to Interrupt driven adaptation layer. When enabled device + which implements only asynchronous API can be used with interrupt driven + API implemented by the generic adaptation layer. + +config UART_ASYNC_TO_INT_DRIVEN_RX_TIMEOUT + int "Receiver timeout (in bauds)" + depends on UART_ASYNC_TO_INT_DRIVEN_API + default 100 + help + Receiver inactivity timeout. It is used to calculate timeout in microseconds. + comment "Serial Drivers" source "drivers/serial/Kconfig.b91" diff --git a/drivers/serial/uart_async_to_irq.c b/drivers/serial/uart_async_to_irq.c new file mode 100644 index 00000000000..209e8d4f205 --- /dev/null +++ b/drivers/serial/uart_async_to_irq.c @@ -0,0 +1,377 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +LOG_MODULE_REGISTER(UART_ASYNC_TO_IRQ_LOG_NAME, CONFIG_UART_LOG_LEVEL); + +/* Internal state flags. */ + +/* RX interrupt enabled. */ +#define A2I_RX_IRQ_ENABLED BIT(0) + +/* TX interrupt enabled. */ +#define A2I_TX_IRQ_ENABLED BIT(1) + +/* Error interrupt enabled. */ +#define A2I_ERR_IRQ_ENABLED BIT(2) + +/* Receiver to be kept enabled. */ +#define A2I_RX_ENABLE BIT(3) + +/* TX busy. */ +#define A2I_TX_BUSY BIT(4) + +static struct uart_async_to_irq_data *get_data(const struct device *dev) +{ + struct uart_async_to_irq_data **data = dev->data; + + return *data; +} + +static const struct uart_async_to_irq_config *get_config(const struct device *dev) +{ + const struct uart_async_to_irq_config * const *config = dev->config; + + return *config; +} + +/* Function calculates RX timeout based on baudrate. */ +static uint32_t get_rx_timeout(const struct device *dev) +{ + struct uart_config cfg; + int err; + uint32_t baudrate; + + err = uart_config_get(dev, &cfg); + if (err == 0) { + baudrate = cfg.baudrate; + } else { + baudrate = get_config(dev)->baudrate; + } + + uint32_t us = (CONFIG_UART_ASYNC_TO_INT_DRIVEN_RX_TIMEOUT * 1000000) / baudrate; + + return us; +} + +static int rx_enable(const struct device *dev, + struct uart_async_to_irq_data *data, + uint8_t *buf, + size_t len) +{ + int err; + const struct uart_async_to_irq_config *config = get_config(dev); + + err = config->api->rx_enable(dev, buf, len, get_rx_timeout(dev)); + + return err; +} + +static int try_rx_enable(const struct device *dev, struct uart_async_to_irq_data *data) +{ + uint8_t *buf = uart_async_rx_buf_req(&data->rx.async_rx); + size_t len = uart_async_rx_get_buf_len(&data->rx.async_rx); + + if (buf == NULL) { + return -EBUSY; + } + + return rx_enable(dev, data, buf, len); +} + +static void on_rx_buf_req(const struct device *dev, + const struct uart_async_to_irq_config *config, + struct uart_async_to_irq_data *data) +{ + struct uart_async_rx *async_rx = &data->rx.async_rx; + uint8_t *buf = uart_async_rx_buf_req(async_rx); + size_t len = uart_async_rx_get_buf_len(async_rx); + + if (buf) { + int err = config->api->rx_buf_rsp(dev, buf, len); + + if (err < 0) { + uart_async_rx_on_buf_rel(async_rx, buf); + } + } else { + atomic_inc(&data->rx.pending_buf_req); + } +} + +static void on_rx_dis(const struct device *dev, struct uart_async_to_irq_data *data) +{ + if (data->flags & A2I_RX_ENABLE) { + data->rx.pending_buf_req = 0; + + int err = try_rx_enable(dev, data); + + LOG_INST_DBG(get_config(dev)->log, "Reenabling RX from RX_DISABLED (err:%d)", err); + __ASSERT_NO_MSG(err >= 0); + return; + } + + k_sem_give(&data->rx.sem); +} + +static void uart_async_to_irq_callback(const struct device *dev, + struct uart_event *evt, + void *user_data) +{ + struct uart_async_to_irq_data *data = (struct uart_async_to_irq_data *)user_data; + const struct uart_async_to_irq_config *config = get_config(dev); + bool call_handler = false; + + switch (evt->type) { + case UART_TX_DONE: + atomic_and(&data->flags, ~A2I_TX_BUSY); + call_handler = data->flags & A2I_TX_IRQ_ENABLED; + break; + case UART_RX_RDY: + uart_async_rx_on_rdy(&data->rx.async_rx, evt->data.rx.buf, evt->data.rx.len); + call_handler = data->flags & A2I_RX_IRQ_ENABLED; + break; + case UART_RX_BUF_REQUEST: + on_rx_buf_req(dev, config, data); + break; + case UART_RX_BUF_RELEASED: + uart_async_rx_on_buf_rel(&data->rx.async_rx, evt->data.rx_buf.buf); + break; + case UART_RX_STOPPED: + call_handler = data->flags & A2I_ERR_IRQ_ENABLED; + break; + case UART_RX_DISABLED: + on_rx_dis(dev, data); + break; + default: + break; + } + + if (data->callback && call_handler) { + atomic_inc(&data->irq_req); + config->trampoline(dev); + } +} + +int z_uart_async_to_irq_fifo_fill(const struct device *dev, const uint8_t *buf, int len) +{ + struct uart_async_to_irq_data *data = get_data(dev); + const struct uart_async_to_irq_config *config = get_config(dev); + int err; + + len = MIN(len, data->tx.len); + if (atomic_or(&data->flags, A2I_TX_BUSY) & A2I_TX_BUSY) { + return 0; + } + + memcpy(data->tx.buf, buf, len); + + err = config->api->tx(dev, data->tx.buf, len, SYS_FOREVER_US); + if (err < 0) { + atomic_and(&data->flags, ~A2I_TX_BUSY); + return 0; + } + + return len; +} + +/** Interrupt driven FIFO read function */ +int z_uart_async_to_irq_fifo_read(const struct device *dev, + uint8_t *buf, + const int len) +{ + struct uart_async_to_irq_data *data = get_data(dev); + const struct uart_async_to_irq_config *config = get_config(dev); + struct uart_async_rx *async_rx = &data->rx.async_rx; + size_t claim_len; + uint8_t *claim_buf; + + claim_len = uart_async_rx_data_claim(async_rx, &claim_buf, len); + if (claim_len == 0) { + return 0; + } + + memcpy(buf, claim_buf, claim_len); + uart_async_rx_data_consume(async_rx, claim_len); + + if (data->rx.pending_buf_req) { + buf = uart_async_rx_buf_req(async_rx); + if (buf) { + int err; + size_t rx_len = uart_async_rx_get_buf_len(async_rx); + + atomic_dec(&data->rx.pending_buf_req); + err = config->api->rx_buf_rsp(dev, buf, rx_len); + if (err < 0) { + if (err == -EACCES) { + data->rx.pending_buf_req = 0; + err = rx_enable(dev, data, buf, rx_len); + } + if (err < 0) { + return err; + } + } + } + } + + return (int)claim_len; +} + +static void dir_disable(const struct device *dev, uint32_t flag) +{ + struct uart_async_to_irq_data *data = get_data(dev); + + atomic_and(&data->flags, ~flag); +} + +static void dir_enable(const struct device *dev, uint32_t flag) +{ + struct uart_async_to_irq_data *data = get_data(dev); + + atomic_or(&data->flags, flag); + + atomic_inc(&data->irq_req); + get_config(dev)->trampoline(dev); +} + +/** Interrupt driven transfer enabling function */ +void z_uart_async_to_irq_irq_tx_enable(const struct device *dev) +{ + dir_enable(dev, A2I_TX_IRQ_ENABLED); +} + +/** Interrupt driven transfer disabling function */ +void z_uart_async_to_irq_irq_tx_disable(const struct device *dev) +{ + dir_disable(dev, A2I_TX_IRQ_ENABLED); +} + +/** Interrupt driven transfer ready function */ +int z_uart_async_to_irq_irq_tx_ready(const struct device *dev) +{ + struct uart_async_to_irq_data *data = get_data(dev); + + return (data->flags & A2I_TX_IRQ_ENABLED) && !(data->flags & A2I_TX_BUSY); +} + +/** Interrupt driven receiver enabling function */ +void z_uart_async_to_irq_irq_rx_enable(const struct device *dev) +{ + dir_enable(dev, A2I_RX_IRQ_ENABLED); +} + +/** Interrupt driven receiver disabling function */ +void z_uart_async_to_irq_irq_rx_disable(const struct device *dev) +{ + dir_disable(dev, A2I_RX_IRQ_ENABLED); +} + +/** Interrupt driven transfer complete function */ +int z_uart_async_to_irq_irq_tx_complete(const struct device *dev) +{ + return z_uart_async_to_irq_irq_tx_ready(dev); +} + +/** Interrupt driven receiver ready function */ +int z_uart_async_to_irq_irq_rx_ready(const struct device *dev) +{ + struct uart_async_to_irq_data *data = get_data(dev); + + return (data->flags & A2I_RX_IRQ_ENABLED) && (data->rx.async_rx.pending_bytes > 0); +} + +/** Interrupt driven error enabling function */ +void z_uart_async_to_irq_irq_err_enable(const struct device *dev) +{ + dir_enable(dev, A2I_ERR_IRQ_ENABLED); +} + +/** Interrupt driven error disabling function */ +void z_uart_async_to_irq_irq_err_disable(const struct device *dev) +{ + dir_disable(dev, A2I_ERR_IRQ_ENABLED); +} + +/** Interrupt driven pending status function */ +int z_uart_async_to_irq_irq_is_pending(const struct device *dev) +{ + return z_uart_async_to_irq_irq_tx_ready(dev) || z_uart_async_to_irq_irq_rx_ready(dev); +} + +/** Interrupt driven interrupt update function */ +int z_uart_async_to_irq_irq_update(const struct device *dev) +{ + return 1; +} + +/** Set the irq callback function */ +void z_uart_async_to_irq_irq_callback_set(const struct device *dev, + uart_irq_callback_user_data_t cb, + void *user_data) +{ + struct uart_async_to_irq_data *data = get_data(dev); + + data->callback = cb; + data->user_data = user_data; +} + +int uart_async_to_irq_rx_enable(const struct device *dev) +{ + struct uart_async_to_irq_data *data = get_data(dev); + const struct uart_async_to_irq_config *config = get_config(dev); + int err; + + err = config->api->callback_set(dev, uart_async_to_irq_callback, data); + if (err < 0) { + return err; + } + + uart_async_rx_reset(&data->rx.async_rx); + + err = try_rx_enable(dev, data); + if (err == 0) { + atomic_or(&data->flags, A2I_RX_ENABLE); + } + + return err; +} + +int uart_async_to_irq_rx_disable(const struct device *dev) +{ + struct uart_async_to_irq_data *data = get_data(dev); + const struct uart_async_to_irq_config *config = get_config(dev); + int err; + + if (atomic_and(&data->flags, ~A2I_RX_ENABLE) & A2I_RX_ENABLE) { + err = config->api->rx_disable(dev); + if (err < 0) { + return err; + } + k_sem_take(&data->rx.sem, K_FOREVER); + } + + return 0; +} + +void uart_async_to_irq_trampoline_cb(const struct device *dev) +{ + struct uart_async_to_irq_data *data = get_data(dev); + + do { + data->callback(dev, data->user_data); + } while (atomic_dec(&data->irq_req) > 1); +} + +int uart_async_to_irq_init(struct uart_async_to_irq_data *data, + const struct uart_async_to_irq_config *config) +{ + data->tx.buf = config->tx_buf; + data->tx.len = config->tx_len; + + k_sem_init(&data->rx.sem, 0, 1); + + return uart_async_rx_init(&data->rx.async_rx, &config->async_rx); +} diff --git a/include/zephyr/drivers/serial/uart_async_to_irq.h b/include/zephyr/drivers/serial/uart_async_to_irq.h new file mode 100644 index 00000000000..d5116dee2c0 --- /dev/null +++ b/include/zephyr/drivers/serial/uart_async_to_irq.h @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_DRIVERS_SERIAL_UART_ASYNC_TO_IRQ_H_ +#define ZEPHYR_DRIVERS_SERIAL_UART_ASYNC_TO_IRQ_H_ + +#include +#include +#include +#include +#include + +/** + * @brief UART Asynchronous to Interrupt driven API adaptation layer + * @ingroup uart_interface + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Forward declarations. */ + +/** @brief Data structure used by the adaptation layer. + * + * Pointer to that data must be the first element of the UART device data structure. + */ +struct uart_async_to_irq_data; + +/** @brief Configuration structure used by the adaptation layer. + * + * Pointer to this data must be the first element of the UART device configuration structure. + */ +struct uart_async_to_irq_config; + +/* @brief Function that triggers trampoline to the interrupt context. + * + * This context is used to call user UART interrupt handler. It is to used to + * fulfill the requirement that UART interrupt driven API shall be called from + * the UART interrupt. Trampoline context shall have the same priority as UART. + * + * One option may be to use k_timer configured to expire immediately. + */ +typedef void (*uart_async_to_irq_trampoline)(const struct device *dev); + +/** @brief Callback to be called from trampoline context. + * + * @param dev UART device. + */ +void uart_async_to_irq_trampoline_cb(const struct device *dev); + +/** @brief Interrupt driven API initializer. + * + * It should be used in the initialization of the UART API structure in the + * driver to provide interrupt driven API functions. + */ +#define UART_ASYNC_TO_IRQ_API_INIT() \ + .fifo_fill = z_uart_async_to_irq_fifo_fill, \ + .fifo_read = z_uart_async_to_irq_fifo_read, \ + .irq_tx_enable = z_uart_async_to_irq_irq_tx_enable, \ + .irq_tx_disable = z_uart_async_to_irq_irq_tx_disable, \ + .irq_tx_ready = z_uart_async_to_irq_irq_tx_ready, \ + .irq_rx_enable = z_uart_async_to_irq_irq_rx_enable, \ + .irq_rx_disable = z_uart_async_to_irq_irq_rx_disable, \ + .irq_tx_complete = z_uart_async_to_irq_irq_tx_complete,\ + .irq_rx_ready = z_uart_async_to_irq_irq_rx_ready, \ + .irq_err_enable = z_uart_async_to_irq_irq_err_enable, \ + .irq_err_disable = z_uart_async_to_irq_irq_err_disable,\ + .irq_is_pending = z_uart_async_to_irq_irq_is_pending, \ + .irq_update = z_uart_async_to_irq_irq_update, \ + .irq_callback_set = z_uart_async_to_irq_irq_callback_set + +/** @brief Configuration structure initializer. + * + * @param _api Structure with UART asynchronous API. + * @param _trampoline Function that trampolines to the interrupt context. + * @param _baudrate UART baudrate. + * @param _tx_buf TX buffer. + * @param _tx_len TX buffer length. + * @param _rx_buf RX buffer. + * @param _rx_len RX buffer length. + * @param _rx_cnt Number of chunks into which RX buffer is divided. + * @param _log Logging instance, if not provided (empty) then default is used. + */ +#define UART_ASYNC_TO_IRQ_API_CONFIG_INITIALIZER(_api, _trampoline, _baudrate, _tx_buf, \ + _tx_len, _rx_buf, _rx_len, _rx_cnt, _log) \ + { \ + .tx_buf = _tx_buf, \ + .tx_len = _tx_len, \ + .async_rx = { \ + .buffer = _rx_buf, \ + .length = _rx_len, \ + .buf_cnt = _rx_cnt \ + }, \ + .api = _api, \ + .trampoline = _trampoline, \ + .baudrate = _baudrate, \ + LOG_OBJECT_PTR_INIT(log, \ + COND_CODE_1(IS_EMPTY(_log), \ + (LOG_OBJECT_PTR(UART_ASYNC_TO_IRQ_LOG_NAME)), \ + (_log) \ + ) \ + ) \ + } + +/** @brief Initialize the adaptation layer. + * + * @param data Data associated with the given adaptation layer instance. + * @param config Configuration structure. Must be persistent. + * + * @retval 0 On successful initialization. + */ +int uart_async_to_irq_init(struct uart_async_to_irq_data *data, + const struct uart_async_to_irq_config *config); + +/* @brief Enable RX for interrupt driven API. + * + * @param dev UART device. Device must support asynchronous API. + * + * @retval 0 on successful operation. + * @retval -EINVAL if adaption layer has wrong configuration. + * @retval negative value Error reported by the UART API. + */ +int uart_async_to_irq_rx_enable(const struct device *dev); + +/* @brief Disable RX for interrupt driven API. + * + * @param dev UART device. Device must support asynchronous API. + * + * @retval 0 on successful operation. + * @retval -EINVAL if adaption layer has wrong configuration. + * @retval negative value Error reported by the UART API. + */ +int uart_async_to_irq_rx_disable(const struct device *dev); + +/* Starting from here API is internal only. */ + +/** @cond INTERNAL_HIDDEN + * @brief Structure used by the adaptation layer. + */ +struct uart_async_to_irq_config { + /** Pointer to the TX buffer. */ + uint8_t *tx_buf; + + /** TX buffer length. */ + size_t tx_len; + + /** UART Asynchronous RX helper configuration. */ + struct uart_async_rx_config async_rx; + + /** Async API used by the a2i layer. */ + const struct uart_async_to_irq_async_api *api; + + /** Trampoline callback. */ + uart_async_to_irq_trampoline trampoline; + + /** Initial baudrate. */ + uint32_t baudrate; + + /** Instance logging handler. */ + LOG_INSTANCE_PTR_DECLARE(log); +}; + +/** @brief Asynchronous API used by the adaptation layer. */ +struct uart_async_to_irq_async_api { + int (*callback_set)(const struct device *dev, + uart_callback_t callback, + void *user_data); + + int (*tx)(const struct device *dev, const uint8_t *buf, size_t len, + int32_t timeout); + int (*tx_abort)(const struct device *dev); + + int (*rx_enable)(const struct device *dev, uint8_t *buf, size_t len, + int32_t timeout); + int (*rx_buf_rsp)(const struct device *dev, uint8_t *buf, size_t len); + int (*rx_disable)(const struct device *dev); +}; + +/** @brief Structure holding receiver data. */ +struct uart_async_to_irq_rx_data { + /** Asynchronous RX helper data. */ + struct uart_async_rx async_rx; + + /** Semaphore for pending on RX disable. */ + struct k_sem sem; + + /** Number of pending buffer requests which weren't handled because lack of free buffers. */ + atomic_t pending_buf_req; +}; + +/** @brief Structure holding transmitter data. */ +struct uart_async_to_irq_tx_data { + /** TX buffer. */ + uint8_t *buf; + + /** Length of the buffer. */ + size_t len; +}; + +/** @briref Data associated with the asynchronous to the interrupt driven API adaptation layer. */ +struct uart_async_to_irq_data { + /** User callback for interrupt driven API. */ + uart_irq_callback_user_data_t callback; + + /** User data. */ + void *user_data; + + /** Interrupt request counter. */ + atomic_t irq_req; + + /** RX specific data. */ + struct uart_async_to_irq_rx_data rx; + + /** TX specific data. */ + struct uart_async_to_irq_tx_data tx; + + /** Spinlock. */ + struct k_spinlock lock; + + /** Internally used flags for holding the state of the a2i layer. */ + atomic_t flags; +}; + +/** Interrupt driven FIFO fill function. */ +int z_uart_async_to_irq_fifo_fill(const struct device *dev, + const uint8_t *buf, + int len); + +/** Interrupt driven FIFO read function. */ +int z_uart_async_to_irq_fifo_read(const struct device *dev, + uint8_t *buf, + const int len); + +/** Interrupt driven transfer enabling function. */ +void z_uart_async_to_irq_irq_tx_enable(const struct device *dev); + +/** Interrupt driven transfer disabling function */ +void z_uart_async_to_irq_irq_tx_disable(const struct device *dev); + +/** Interrupt driven transfer ready function */ +int z_uart_async_to_irq_irq_tx_ready(const struct device *dev); + +/** Interrupt driven receiver enabling function */ +void z_uart_async_to_irq_irq_rx_enable(const struct device *dev); + +/** Interrupt driven receiver disabling function */ +void z_uart_async_to_irq_irq_rx_disable(const struct device *dev); + +/** Interrupt driven transfer complete function */ +int z_uart_async_to_irq_irq_tx_complete(const struct device *dev); + +/** Interrupt driven receiver ready function */ +int z_uart_async_to_irq_irq_rx_ready(const struct device *dev); + +/** Interrupt driven error enabling function */ +void z_uart_async_to_irq_irq_err_enable(const struct device *dev); + +/** Interrupt driven error disabling function */ +void z_uart_async_to_irq_irq_err_disable(const struct device *dev); + +/** Interrupt driven pending status function */ +int z_uart_async_to_irq_irq_is_pending(const struct device *dev); + +/** Interrupt driven interrupt update function */ +int z_uart_async_to_irq_irq_update(const struct device *dev); + +/** Set the irq callback function */ +void z_uart_async_to_irq_irq_callback_set(const struct device *dev, + uart_irq_callback_user_data_t cb, + void *user_data); + +/** @endcond */ + +#ifdef __cplusplus +} +#endif + +/** @} */ + +#endif /* ZEPHYR_DRIVERS_SERIAL_UART_ASYNC_TO_IRQ_H_ */ From 8cf98c2026f65fea785dfef84ab2b831de5d55db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 13 Nov 2023 11:14:37 +0100 Subject: [PATCH 1148/1623] [nrf fromtree] soc: arm: nordic_nrf: Disable UART runtime configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since it takes 400 bytes of code and it is rarely used disable by default this feature. Signed-off-by: Krzysztof Chruściński (cherry picked from commit a0382bd0f39e94461820fc31a7394d2be35cabf6) Signed-off-by: Robert Lubos --- doc/releases/migration-guide-3.6.rst | 4 ++++ soc/arm/nordic_nrf/Kconfig.defconfig | 3 +++ 2 files changed, 7 insertions(+) diff --git a/doc/releases/migration-guide-3.6.rst b/doc/releases/migration-guide-3.6.rst index eeac0a89b75..c4cb37eaf94 100644 --- a/doc/releases/migration-guide-3.6.rst +++ b/doc/releases/migration-guide-3.6.rst @@ -55,6 +55,10 @@ Device Drivers and Device Tree (:github:`62994`) +* Runtime configuration is now disabled by default for Nordic UART drivers. The motivation for the + change is that this feature is rarely used and disabling it significantly reduces the memory + footprint. + Power Management ================ diff --git a/soc/arm/nordic_nrf/Kconfig.defconfig b/soc/arm/nordic_nrf/Kconfig.defconfig index 3eedcf350c6..858c60d1d88 100644 --- a/soc/arm/nordic_nrf/Kconfig.defconfig +++ b/soc/arm/nordic_nrf/Kconfig.defconfig @@ -40,4 +40,7 @@ config GPIO default y depends on SPI +config UART_USE_RUNTIME_CONFIGURE + default n + endif # SOC_FAMILY_NRF From 2ecabec97c571bd5a739dd2193d8918df62f0228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Wed, 17 Jan 2024 11:53:35 +0100 Subject: [PATCH 1149/1623] [nrf fromtree] modules: hal_nordic: nrfx: Add new UARTE options to Kconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Kconfig options to new configuration flags for nrfx_uarte. Signed-off-by: Krzysztof Chruściński (cherry picked from commit 4fcf8e0630b64c3f40c5c6acb5feb6ad1cab714f) Signed-off-by: Robert Lubos --- modules/hal_nordic/nrfx/Kconfig | 21 +++++++++++++++++++++ modules/hal_nordic/nrfx/nrfx_config.h | 12 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index a92aa93d9a2..b4c00040ee1 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -573,6 +573,27 @@ config NRFX_UARTE3 depends on $(dt_nodelabel_has_compat,uart3,$(DT_COMPAT_NORDIC_NRF_UARTE)) select NRFX_UARTE +config NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG + bool "UARTE GPIO configuration support" + depends on NRFX_UARTE + +config NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG + bool "UARTE PSEL configuration support" + depends on NRFX_UARTE + +config NRFX_UARTE_CONFIG_TX_LINK + bool "UARTE TX transfer linking support" + depends on NRFX_UARTE + +config NRFX_UARTE_CONFIG_RX_CACHE_ENABLED + bool "UARTE RX caching support" + default y if $(dt_nodelabel_has_compat,ram3x,$(DT_COMPAT_MMIO_SRAM)) + depends on NRFX_UARTE + help + Feature might be enabled on platforms which has limitations regarding addresses + to which receiver can write data. If enabled then internal driver buffers + (cache buffers) are used for DMA transfers and data is copied to the user buffer. + config NRFX_USBREG bool "USBREG driver" depends on $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_USBREG)) diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 57417644c32..ac930b13639 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -563,6 +563,18 @@ #ifdef CONFIG_NRFX_UARTE3 #define NRFX_UARTE3_ENABLED 1 #endif +#ifdef CONFIG_NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG +#define NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG 1 +#endif +#ifdef CONFIG_NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG +#define NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG 1 +#endif +#ifdef CONFIG_NRFX_UARTE_CONFIG_TX_LINK +#define NRFX_UARTE_CONFIG_TX_LINK 1 +#endif +#ifdef CONFIG_NRFX_UARTE_CONFIG_RX_CACHE_ENABLED +#define NRFX_UARTE_CONFIG_RX_CACHE_ENABLED 1 +#endif #ifdef CONFIG_NRFX_USBREG #define NRFX_USBREG_ENABLED 1 From f3b1f268ec4b356353154acc695f79fc2e6bb3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Wed, 17 Jan 2024 11:54:10 +0100 Subject: [PATCH 1150/1623] [nrf fromtree] drivers: serial: nrfx: Add new shim based on nrfx_uarte MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new shim which is based on nrfx driver. Legacy shim is kept for transition period. It can be used after setting CONFIG_UART_NRFX_UARTE_LEGACY_SHIM. Signed-off-by: Krzysztof Chruściński (cherry picked from commit 4cc213bc8d17220a2569ff8bb7548d6ed03f7d2f) Signed-off-by: Robert Lubos --- drivers/serial/CMakeLists.txt | 8 +- drivers/serial/Kconfig.nrfx | 11 +- drivers/serial/Kconfig.nrfx_uart_instance | 45 +- drivers/serial/uart_nrfx_uarte2.c | 1030 +++++++++++++++++++++ 4 files changed, 1091 insertions(+), 3 deletions(-) create mode 100644 drivers/serial/uart_nrfx_uarte2.c diff --git a/drivers/serial/CMakeLists.txt b/drivers/serial/CMakeLists.txt index 2cd79e12f64..67e02e0c261 100644 --- a/drivers/serial/CMakeLists.txt +++ b/drivers/serial/CMakeLists.txt @@ -26,7 +26,13 @@ zephyr_library_sources_ifdef(CONFIG_UART_MIV uart_miv.c) zephyr_library_sources_ifdef(CONFIG_UART_MSP432P4XX uart_msp432p4xx.c) zephyr_library_sources_ifdef(CONFIG_UART_NS16550 uart_ns16550.c) zephyr_library_sources_ifdef(CONFIG_UART_NRFX_UART uart_nrfx_uart.c) -zephyr_library_sources_ifdef(CONFIG_UART_NRFX_UARTE uart_nrfx_uarte.c) +if (CONFIG_UART_NRFX_UARTE) + if (CONFIG_UART_NRFX_UARTE_LEGACY_SHIM) + zephyr_library_sources(uart_nrfx_uarte.c) + else() + zephyr_library_sources(uart_nrfx_uarte2.c) + endif() +endif() zephyr_library_sources_ifdef(CONFIG_UART_NUMICRO uart_numicro.c) zephyr_library_sources_ifdef(CONFIG_UART_SAM uart_sam.c) zephyr_library_sources_ifdef(CONFIG_USART_SAM usart_sam.c) diff --git a/drivers/serial/Kconfig.nrfx b/drivers/serial/Kconfig.nrfx index 53553e3d06e..5709ca2d23a 100644 --- a/drivers/serial/Kconfig.nrfx +++ b/drivers/serial/Kconfig.nrfx @@ -25,11 +25,20 @@ config UART_NRFX_UART config UART_NRFX_UARTE def_bool y depends on DT_HAS_NORDIC_NRF_UARTE_ENABLED + imply NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG if !UART_NRFX_UARTE_LEGACY_SHIM + imply NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG if !UART_NRFX_UARTE_LEGACY_SHIM + +config UART_NRFX_UARTE_LEGACY_SHIM + bool "Legacy UARTE shim" + depends on UART_NRFX_UARTE + # New shim takes more ROM. Until it is fixed use legacy shim in memory + # constraint case. + default y if MCUBOOT config UART_ASYNC_TX_CACHE_SIZE int "TX cache buffer size" depends on UART_ASYNC_API - depends on UART_NRFX_UARTE + depends on UART_NRFX_UARTE_LEGACY_SHIM default 8 help For UARTE, TX cache buffer is used when provided TX buffer is not located diff --git a/drivers/serial/Kconfig.nrfx_uart_instance b/drivers/serial/Kconfig.nrfx_uart_instance index 39e774e2544..76f74caa038 100644 --- a/drivers/serial/Kconfig.nrfx_uart_instance +++ b/drivers/serial/Kconfig.nrfx_uart_instance @@ -6,6 +6,7 @@ config UART_$(nrfx_uart_num)_INTERRUPT_DRIVEN bool "Interrupt support on port $(nrfx_uart_num)" depends on UART_INTERRUPT_DRIVEN + select UART_ASYNC_TO_INT_DRIVEN_API if !UART_NRFX_UARTE_LEGACY_SHIM default y help This option enables UART interrupt support on port $(nrfx_uart_num). @@ -27,6 +28,9 @@ config UART_$(nrfx_uart_num)_ENHANCED_POLL_OUT When enabled, polling out does not trigger interrupt which stops TX. Feature uses a PPI channel. +config NRFX_UARTE$(nrfx_uart_num) + def_bool y if HAS_HW_NRF_UARTE$(nrfx_uart_num) && !UART_NRFX_UARTE_LEGACY_SHIM + config UART_$(nrfx_uart_num)_NRF_PARITY_BIT bool "Parity bit" help @@ -34,7 +38,8 @@ config UART_$(nrfx_uart_num)_NRF_PARITY_BIT config UART_$(nrfx_uart_num)_NRF_TX_BUFFER_SIZE int "Size of RAM buffer" - depends on UART_INTERRUPT_DRIVEN + depends on HAS_HW_NRF_UARTE$(nrfx_uart_num) + depends on UART_NRFX_UARTE_LEGACY_SHIM range 1 65535 default 32 help @@ -46,6 +51,7 @@ config UART_$(nrfx_uart_num)_NRF_HW_ASYNC bool "Use hardware RX byte counting" depends on HAS_HW_NRF_UARTE$(nrfx_uart_num) depends on UART_ASYNC_API + depends on UART_NRFX_UARTE_LEGACY_SHIM select NRFX_PPI if HAS_HW_NRF_PPI select NRFX_DPPI if HAS_HW_NRF_DPPIC help @@ -58,6 +64,7 @@ config UART_$(nrfx_uart_num)_NRF_ASYNC_LOW_POWER bool "Low power mode" depends on HAS_HW_NRF_UARTE$(nrfx_uart_num) depends on UART_ASYNC_API + depends on UART_NRFX_UARTE_LEGACY_SHIM help When enabled, UARTE is enabled before each TX or RX usage and disabled when not used. Disabling UARTE while in idle allows to achieve lowest @@ -67,6 +74,42 @@ config UART_$(nrfx_uart_num)_NRF_HW_ASYNC_TIMER int "Timer instance" depends on UART_$(nrfx_uart_num)_NRF_HW_ASYNC +config UART_$(nrfx_uart_num)_TX_CACHE_SIZE + int "TX cache buffer size" + depends on !UART_NRFX_UARTE_LEGACY_SHIM + default 8 + help + For UARTE, TX cache buffer is used when provided TX buffer is not located + in memory which can be used by the EasyDMA. + +config UART_$(nrfx_uart_num)_RX_CACHE_SIZE + int "RX cache buffer size" + depends on !UART_NRFX_UARTE_LEGACY_SHIM + default 32 if $(dt_nodelabel_has_compat,ram3x,$(DT_COMPAT_MMIO_SRAM)) + default 5 + range 5 255 + help + For UARTE, RX cache buffer is used when provided RX buffer is not located + in memory which can be used by the EasyDMA. It is also used to store + flushed data. + +config UART_$(nrfx_uart_num)_A2I_RX_SIZE + depends on !UART_NRFX_UARTE_LEGACY_SHIM + int "Asynchronous to interrupt driven adaptation layer RX buffer size" + default 64 if UART_$(nrfx_uart_num)_INTERRUPT_DRIVEN + default 0 + help + Amount of space dedicated for RX. It is divided into chunks with some + amount of that space used for control data. + +config UART_$(nrfx_uart_num)_A2I_RX_BUF_COUNT + depends on !UART_NRFX_UARTE_LEGACY_SHIM + int "Asynchronous to interrupt driven adaptation layer RX buffer count" + default 8 if UART_$(nrfx_uart_num)_INTERRUPT_DRIVEN + default 0 + help + Number of chunks into RX space is divided. + config UART_$(nrfx_uart_num)_GPIO_MANAGEMENT bool "GPIO management on port $(nrfx_uart_num)" depends on PM_DEVICE diff --git a/drivers/serial/uart_nrfx_uarte2.c b/drivers/serial/uart_nrfx_uarte2.c new file mode 100644 index 00000000000..c27f33c7284 --- /dev/null +++ b/drivers/serial/uart_nrfx_uarte2.c @@ -0,0 +1,1030 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @brief Driver for Nordic Semiconductor nRF UARTE + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define LOG_MODULE_NAME uarte +LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_UART_LOG_LEVEL); + +#define INSTANCE_INT_DRIVEN(periph, prefix, i, _) \ + IS_ENABLED(CONFIG_UART_##prefix##i##_INTERRUPT_DRIVEN) + +#define INSTANCE_ASYNC(periph, prefix, i, _) \ + IS_ENABLED(CONFIG_UART_##prefix##i##_ASYNC) + +#define INSTANCE_POLLING(periph, prefix, id, _) \ + UTIL_AND(CONFIG_HAS_HW_NRF_UARTE##prefix##id, \ + UTIL_AND(COND_CODE_1(CONFIG_UART_##prefix##id##_INTERRUPT_DRIVEN, (0), (1)), \ + COND_CODE_1(CONFIG_UART_##prefix##id##_ASYNC, (0), (1)))) + +#define INSTANCE_ENHANCED_POLL_OUT(periph, prefix, i, _) \ + IS_ENABLED(CONFIG_UART_##prefix##i##_ENHANCED_POLL_OUT) + +/* Macro determining if any instance is using interrupt driven API. */ +#if (NRFX_FOREACH_ENABLED(UARTE, INSTANCE_INT_DRIVEN, (+), (0), _)) +#define UARTE_ANY_INTERRUPT_DRIVEN 1 +#else +#define UARTE_ANY_INTERRUPT_DRIVEN 0 +#endif + +/* Macro determining if any instance is enabled and using ASYNC API. */ +#if (NRFX_FOREACH_ENABLED(UARTE, INSTANCE_ASYNC, (+), (0), _)) +#define UARTE_ANY_ASYNC 1 +#else +#define UARTE_ANY_ASYNC 0 +#endif + +/* Macro determining if any instance is using only polling API. */ +#if (NRFX_FOREACH_ENABLED(UARTE, INSTANCE_POLLING, (+), (0), _)) +#define UARTE_ANY_POLLING 1 +#else +#define UARTE_ANY_POLLING 0 +#endif + +/* Macro determining if any instance is using interrupt driven API. */ +#if (NRFX_FOREACH_ENABLED(UARTE, INSTANCE_ENHANCED_POLL_OUT, (+), (0), _)) +#define UARTE_ENHANCED_POLL_OUT 1 +#else +#define UARTE_ENHANCED_POLL_OUT 0 +#endif + +#if UARTE_ANY_INTERRUPT_DRIVEN || UARTE_ANY_ASYNC +#define UARTE_INT_ASYNC 1 +#else +#define UARTE_INT_ASYNC 0 +#endif + +#if defined(UARTE_CONFIG_PARITYTYPE_Msk) +#define UARTE_ODD_PARITY_ALLOWED 1 +#else +#define UARTE_ODD_PARITY_ALLOWED 0 +#endif + +/* + * RX timeout is divided into time slabs, this define tells how many divisions + * should be made. More divisions - higher timeout accuracy and processor usage. + */ +#define RX_TIMEOUT_DIV 5 + +/* Macro for converting numerical baudrate to register value. It is convenient + * to use this approach because for constant input it can calculate nrf setting + * at compile time. + */ +#define NRF_BAUDRATE(baudrate) ((baudrate) == 300 ? 0x00014000 :\ + (baudrate) == 600 ? 0x00027000 : \ + (baudrate) == 1200 ? NRF_UARTE_BAUDRATE_1200 : \ + (baudrate) == 2400 ? NRF_UARTE_BAUDRATE_2400 : \ + (baudrate) == 4800 ? NRF_UARTE_BAUDRATE_4800 : \ + (baudrate) == 9600 ? NRF_UARTE_BAUDRATE_9600 : \ + (baudrate) == 14400 ? NRF_UARTE_BAUDRATE_14400 : \ + (baudrate) == 19200 ? NRF_UARTE_BAUDRATE_19200 : \ + (baudrate) == 28800 ? NRF_UARTE_BAUDRATE_28800 : \ + (baudrate) == 31250 ? NRF_UARTE_BAUDRATE_31250 : \ + (baudrate) == 38400 ? NRF_UARTE_BAUDRATE_38400 : \ + (baudrate) == 56000 ? NRF_UARTE_BAUDRATE_56000 : \ + (baudrate) == 57600 ? NRF_UARTE_BAUDRATE_57600 : \ + (baudrate) == 76800 ? NRF_UARTE_BAUDRATE_76800 : \ + (baudrate) == 115200 ? NRF_UARTE_BAUDRATE_115200 : \ + (baudrate) == 230400 ? NRF_UARTE_BAUDRATE_230400 : \ + (baudrate) == 250000 ? NRF_UARTE_BAUDRATE_250000 : \ + (baudrate) == 460800 ? NRF_UARTE_BAUDRATE_460800 : \ + (baudrate) == 921600 ? NRF_UARTE_BAUDRATE_921600 : \ + (baudrate) == 1000000 ? NRF_UARTE_BAUDRATE_1000000 : 0) + +#define UARTE_DATA_FLAG_TRAMPOLINE BIT(0) +#define UARTE_DATA_FLAG_RX_ENABLED BIT(1) + +struct uarte_async_data { + uart_callback_t user_callback; + void *user_data; + + struct k_timer tx_timer; + struct k_timer rx_timer; + + k_timeout_t rx_timeout; + + /* Keeps the most recent error mask. */ + uint32_t err; + + uint8_t idle_cnt; +}; + +/* Device data structure */ +struct uarte_nrfx_data { + struct uart_async_to_irq_data *a2i_data; +#if CONFIG_UART_USE_RUNTIME_CONFIGURE + struct uart_config uart_config; +#endif + struct uarte_async_data *async; + atomic_t flags; + uint8_t rx_byte; +}; +BUILD_ASSERT(offsetof(struct uarte_nrfx_data, a2i_data) == 0); + +/* If set then pins are managed when going to low power mode. */ +#define UARTE_CFG_FLAG_GPIO_MGMT BIT(0) + +/* If set then receiver is not used. */ +#define UARTE_CFG_FLAG_NO_RX BIT(1) + +/* If set then instance is using interrupt driven API. */ +#define UARTE_CFG_FLAG_INTERRUPT_DRIVEN_API BIT(2) + +/** + * @brief Structure for UARTE configuration. + */ +struct uarte_nrfx_config { + const struct uart_async_to_irq_config *a2i_config; + nrfx_uarte_t nrfx_dev; + nrfx_uarte_config_t nrfx_config; + const struct pinctrl_dev_config *pcfg; + uint32_t flags; + + LOG_INSTANCE_PTR_DECLARE(log); +}; +BUILD_ASSERT(offsetof(struct uarte_nrfx_config, a2i_config) == 0); + +#define UARTE_ERROR_FROM_MASK(mask) \ + ((mask) & NRF_UARTE_ERROR_OVERRUN_MASK ? UART_ERROR_OVERRUN \ + : (mask) & NRF_UARTE_ERROR_PARITY_MASK ? UART_ERROR_PARITY \ + : (mask) & NRF_UARTE_ERROR_FRAMING_MASK ? UART_ERROR_FRAMING \ + : (mask) & NRF_UARTE_ERROR_BREAK_MASK ? UART_BREAK \ + : 0) + +/* Determine if the device has interrupt driven API enabled. */ +#define IS_INT_DRIVEN_API(dev) \ + (UARTE_ANY_INTERRUPT_DRIVEN && \ + (((const struct uarte_nrfx_config *)dev->config)->flags & \ + UARTE_CFG_FLAG_INTERRUPT_DRIVEN_API)) + +/* Determine if the device supports only polling API. */ +#define IS_POLLING_API(dev) \ + (!UARTE_INT_ASYNC || (((struct uarte_nrfx_data *)dev->data)->async == NULL)) + +/* Determine if the device supports asynchronous API. */ +#define IS_ASYNC_API(dev) (!IS_INT_DRIVEN_API(dev) && !IS_POLLING_API(dev)) + +static inline const nrfx_uarte_t *get_nrfx_dev(const struct device *dev) +{ + const struct uarte_nrfx_config *config = dev->config; + + return &config->nrfx_dev; +} + +static int callback_set(const struct device *dev, uart_callback_t callback, void *user_data) +{ + struct uarte_nrfx_data *data = dev->data; + + data->async->user_callback = callback; + data->async->user_data = user_data; + + return 0; +} + +#if UARTE_ANY_ASYNC +static int api_callback_set(const struct device *dev, uart_callback_t callback, void *user_data) +{ + if (!IS_ASYNC_API(dev)) { + return -ENOTSUP; + } + + return callback_set(dev, callback, user_data); +} +#endif + +static void on_tx_done(const struct device *dev, const nrfx_uarte_event_t *event) +{ + struct uarte_nrfx_data *data = dev->data; + struct uart_event evt = { + .type = (event->data.tx.flags & NRFX_UARTE_TX_DONE_ABORTED) ? + UART_TX_ABORTED : UART_TX_DONE, + .data.tx.buf = event->data.tx.p_buffer, + .data.tx.len = event->data.tx.length + }; + bool hwfc; + +#if CONFIG_UART_USE_RUNTIME_CONFIGURE + hwfc = data->uart_config.flow_ctrl == UART_CFG_FLOW_CTRL_RTS_CTS; +#else + const struct uarte_nrfx_config *config = dev->config; + + hwfc = config->nrfx_config.config.hwfc == NRF_UARTE_HWFC_ENABLED; +#endif + + if (hwfc) { + k_timer_stop(&data->async->tx_timer); + } + data->async->user_callback(dev, &evt, data->async->user_data); +} + +static void on_rx_done(const struct device *dev, const nrfx_uarte_event_t *event) +{ + struct uarte_nrfx_data *data = dev->data; + struct uart_event evt; + + if (event->data.rx.length) { + if (data->async->err) { + evt.type = UART_RX_STOPPED; + evt.data.rx_stop.reason = UARTE_ERROR_FROM_MASK(data->async->err); + evt.data.rx_stop.data.buf = event->data.rx.p_buffer; + evt.data.rx_stop.data.len = event->data.rx.length; + /* Keep error code for uart_err_check(). */ + if (!IS_INT_DRIVEN_API(dev)) { + data->async->err = 0; + } + } else { + evt.type = UART_RX_RDY, + evt.data.rx.buf = event->data.rx.p_buffer, + evt.data.rx.len = event->data.rx.length, + evt.data.rx.offset = 0; + } + data->async->user_callback(dev, &evt, data->async->user_data); + } + + evt.type = UART_RX_BUF_RELEASED; + evt.data.rx_buf.buf = event->data.rx.p_buffer; + + data->async->user_callback(dev, &evt, data->async->user_data); +} + +static void start_rx_timer(struct uarte_nrfx_data *data) +{ + struct uarte_async_data *adata = data->async; + + k_timer_start(&adata->rx_timer, adata->rx_timeout, K_NO_WAIT); +} + +static void on_rx_byte(const struct device *dev) +{ + struct uarte_nrfx_data *data = dev->data; + struct uarte_async_data *adata = data->async; + const nrfx_uarte_t *nrfx_dev = get_nrfx_dev(dev); + + nrfx_uarte_rxdrdy_disable(nrfx_dev); + adata->idle_cnt = RX_TIMEOUT_DIV; + start_rx_timer(data); +} + +static void on_rx_buf_req(const struct device *dev) +{ + struct uarte_nrfx_data *data = dev->data; + struct uarte_async_data *adata = data->async; + const nrfx_uarte_t *nrfx_dev = get_nrfx_dev(dev); + + struct uart_event evt = { + .type = UART_RX_BUF_REQUEST + }; + + /* If counter reached zero that indicates that timeout was reached and + * reception of one buffer was terminated to restart another transfer. + */ + if (!K_TIMEOUT_EQ(adata->rx_timeout, K_NO_WAIT)) { + /* Read and clear any pending new data information. */ + nrfx_uarte_rx_new_data_check(nrfx_dev); + nrfx_uarte_rxdrdy_enable(nrfx_dev); + } + data->async->user_callback(dev, &evt, data->async->user_data); +} + +static void on_rx_disabled(const struct device *dev, struct uarte_nrfx_data *data) +{ + struct uart_event evt = { + .type = UART_RX_DISABLED + }; + + atomic_and(&data->flags, ~UARTE_DATA_FLAG_RX_ENABLED); + k_timer_stop(&data->async->rx_timer); + + data->async->user_callback(dev, &evt, data->async->user_data); +} + +static void trigger_handler(const struct device *dev) +{ + struct uarte_nrfx_data *data = dev->data; + + if (UARTE_ANY_INTERRUPT_DRIVEN && + atomic_and(&data->flags, ~UARTE_DATA_FLAG_TRAMPOLINE) & + UARTE_DATA_FLAG_TRAMPOLINE) { + uart_async_to_irq_trampoline_cb(dev); + } +} + +static void evt_handler(nrfx_uarte_event_t const *event, void *context) +{ + const struct device *dev = context; + struct uarte_nrfx_data *data = dev->data; + + switch (event->type) { + case NRFX_UARTE_EVT_TX_DONE: + on_tx_done(dev, event); + break; + case NRFX_UARTE_EVT_RX_DONE: + on_rx_done(dev, event); + break; + case NRFX_UARTE_EVT_RX_BYTE: + on_rx_byte(dev); + break; + case NRFX_UARTE_EVT_ERROR: + data->async->err = event->data.error.error_mask; + break; + case NRFX_UARTE_EVT_RX_BUF_REQUEST: + on_rx_buf_req(dev); + break; + case NRFX_UARTE_EVT_RX_DISABLED: + on_rx_disabled(dev, data); + break; + case NRFX_UARTE_EVT_RX_BUF_TOO_LATE: + /* No support */ + break; + case NRFX_UARTE_EVT_TRIGGER: + trigger_handler(dev); + break; + default: + __ASSERT_NO_MSG(0); + } +} + +static int api_tx(const struct device *dev, const uint8_t *buf, size_t len, int32_t timeout) +{ + struct uarte_nrfx_data *data = dev->data; + const nrfx_uarte_t *nrfx_dev = get_nrfx_dev(dev); + nrfx_err_t err; + bool hwfc; + +#if CONFIG_UART_USE_RUNTIME_CONFIGURE + hwfc = data->uart_config.flow_ctrl == UART_CFG_FLOW_CTRL_RTS_CTS; +#else + const struct uarte_nrfx_config *config = dev->config; + + hwfc = config->nrfx_config.config.hwfc == NRF_UARTE_HWFC_ENABLED; +#endif + + err = nrfx_uarte_tx(nrfx_dev, buf, len, 0); + if (err != NRFX_SUCCESS) { + return (err == NRFX_ERROR_BUSY) ? -EBUSY : -EIO; + } + + if (hwfc && timeout != SYS_FOREVER_US) { + k_timer_start(&data->async->tx_timer, K_USEC(timeout), K_NO_WAIT); + } + + return 0; +} + +static int api_tx_abort(const struct device *dev) +{ + const nrfx_uarte_t *nrfx_dev = get_nrfx_dev(dev); + nrfx_err_t err; + + err = nrfx_uarte_tx_abort(nrfx_dev, false); + return (err == NRFX_SUCCESS) ? 0 : -EFAULT; +} + +static void tx_timeout_handler(struct k_timer *timer) +{ + const struct device *dev = k_timer_user_data_get(timer); + + (void)api_tx_abort(dev); +} + +static void rx_timeout_handler(struct k_timer *timer) +{ + const struct device *dev = (const struct device *)k_timer_user_data_get(timer); + struct uarte_nrfx_data *data = dev->data; + struct uarte_async_data *adata = data->async; + const nrfx_uarte_t *nrfx_dev = get_nrfx_dev(dev); + + if (nrfx_uarte_rx_new_data_check(nrfx_dev)) { + adata->idle_cnt = RX_TIMEOUT_DIV - 1; + } else { + adata->idle_cnt--; + if (adata->idle_cnt == 0) { + (void)nrfx_uarte_rx_abort(nrfx_dev, false, false); + return; + } + } + + start_rx_timer(data); +} + +/* Determine if RX FIFO content shall be kept when device is being disabled. + * When flow-control is used then we expect to keep RX FIFO content since HWFC + * enforces lossless communication. However, when HWFC is not used (by any instance + * then RX FIFO handling feature is disabled in the nrfx_uarte to save space. + * It is based on assumption that without HWFC it is expected that some data may + * be lost and there are means to prevent that (keeping receiver always opened by + * provided reception buffers on time). + */ +static inline uint32_t get_keep_fifo_content_flag(const struct device *dev) +{ +#if CONFIG_UART_USE_RUNTIME_CONFIGURE + struct uarte_nrfx_data *data = dev->data; + + if (data->uart_config.flow_ctrl == UART_CFG_FLOW_CTRL_RTS_CTS) { + return NRFX_UARTE_RX_ENABLE_KEEP_FIFO_CONTENT; + } +#else + const struct uarte_nrfx_config *config = dev->config; + + if (config->nrfx_config.config.hwfc == NRF_UARTE_HWFC_ENABLED) { + return NRFX_UARTE_RX_ENABLE_KEEP_FIFO_CONTENT; + } +#endif + + return 0; +} + +static int api_rx_enable(const struct device *dev, uint8_t *buf, size_t len, int32_t timeout) +{ + nrfx_err_t err; + const nrfx_uarte_t *nrfx_dev = get_nrfx_dev(dev); + const struct uarte_nrfx_config *cfg = dev->config; + struct uarte_nrfx_data *data = dev->data; + struct uarte_async_data *adata = data->async; + uint32_t flags = NRFX_UARTE_RX_ENABLE_CONT | + get_keep_fifo_content_flag(dev) | + (IS_ASYNC_API(dev) ? NRFX_UARTE_RX_ENABLE_STOP_ON_END : 0); + + if (cfg->flags & UARTE_CFG_FLAG_NO_RX) { + return -ENOTSUP; + } + + if (timeout != SYS_FOREVER_US) { + adata->idle_cnt = RX_TIMEOUT_DIV + 1; + adata->rx_timeout = K_USEC(timeout / RX_TIMEOUT_DIV); + } else { + adata->rx_timeout = K_NO_WAIT; + } + + err = nrfx_uarte_rx_buffer_set(nrfx_dev, buf, len); + if (err != NRFX_SUCCESS) { + return -EIO; + } + + err = nrfx_uarte_rx_enable(nrfx_dev, flags); + if (err != NRFX_SUCCESS) { + return (err == NRFX_ERROR_BUSY) ? -EBUSY : -EIO; + } + + atomic_or(&data->flags, UARTE_DATA_FLAG_RX_ENABLED); + + return 0; +} + +static int api_rx_buf_rsp(const struct device *dev, uint8_t *buf, size_t len) +{ + const nrfx_uarte_t *nrfx_dev = get_nrfx_dev(dev); + struct uarte_nrfx_data *data = dev->data; + nrfx_err_t err; + + if (!(data->flags & UARTE_DATA_FLAG_RX_ENABLED)) { + return -EACCES; + } + + err = nrfx_uarte_rx_buffer_set(nrfx_dev, buf, len); + switch (err) { + case NRFX_SUCCESS: + return 0; + case NRFX_ERROR_BUSY: + return -EBUSY; + default: + return -EIO; + } +} + +static int api_rx_disable(const struct device *dev) +{ + struct uarte_nrfx_data *data = dev->data; + + k_timer_stop(&data->async->rx_timer); + + return (nrfx_uarte_rx_abort(get_nrfx_dev(dev), true, false) == NRFX_SUCCESS) ? 0 : -EFAULT; +} + +static int api_poll_in(const struct device *dev, unsigned char *c) +{ + const struct uarte_nrfx_config *cfg = dev->config; + const nrfx_uarte_t *instance = &cfg->nrfx_dev; + nrfx_err_t err; + + if (IS_INT_DRIVEN_API(dev)) { + return uart_fifo_read(dev, c, 1) == 0 ? -1 : 0; + } + + if (IS_ASYNC_API(dev)) { + return -EBUSY; + } + + err = nrfx_uarte_rx_ready(instance, NULL); + if (err == NRFX_SUCCESS) { + uint8_t *rx_byte = cfg->nrfx_config.rx_cache.p_buffer; + + *c = *rx_byte; + err = nrfx_uarte_rx_buffer_set(instance, rx_byte, 1); + __ASSERT_NO_MSG(err == NRFX_SUCCESS); + + return 0; + } + + return -1; +} + +static void api_poll_out(const struct device *dev, unsigned char out_char) +{ + const nrfx_uarte_t *nrfx_dev = get_nrfx_dev(dev); + nrfx_err_t err; + + do { + /* When runtime PM is used we cannot use early return because then + * we have no information when UART is actually done with the + * transmission. It reduces UART performance however, polling in + * general is not power efficient and should be avoided in low + * power applications. + */ + err = nrfx_uarte_tx(nrfx_dev, &out_char, 1, NRFX_UARTE_TX_EARLY_RETURN); + __ASSERT(err != NRFX_ERROR_INVALID_ADDR, "Invalid address of the buffer"); + + if (err == NRFX_ERROR_BUSY && + IS_ENABLED(CONFIG_MULTITHREADING) && k_is_preempt_thread()) { + k_msleep(1); + } + Z_SPIN_DELAY(3); + } while (err == NRFX_ERROR_BUSY); +} + +#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE +/** + * @brief Set the baud rate + * + * This routine set the given baud rate for the UARTE. + * + * @param dev UARTE device struct + * @param baudrate Baud rate + * + * @return 0 on success or error code + */ +static int baudrate_set(NRF_UARTE_Type *uarte, uint32_t baudrate) +{ + nrf_uarte_baudrate_t nrf_baudrate = NRF_BAUDRATE(baudrate); + + if (baudrate == 0) { + return -EINVAL; + } + + nrfy_uarte_baudrate_set(uarte, nrf_baudrate); + + return 0; +} + +static int uarte_nrfx_configure(const struct device *dev, + const struct uart_config *cfg) +{ + const nrfx_uarte_t *nrfx_dev = get_nrfx_dev(dev); + struct uarte_nrfx_data *data = dev->data; + nrf_uarte_config_t uarte_cfg; + +#if defined(UARTE_CONFIG_STOP_Msk) + switch (cfg->stop_bits) { + case UART_CFG_STOP_BITS_1: + uarte_cfg.stop = NRF_UARTE_STOP_ONE; + break; + case UART_CFG_STOP_BITS_2: + uarte_cfg.stop = NRF_UARTE_STOP_TWO; + break; + default: + return -ENOTSUP; + } +#else + if (cfg->stop_bits != UART_CFG_STOP_BITS_1) { + return -ENOTSUP; + } +#endif + + if (cfg->data_bits != UART_CFG_DATA_BITS_8) { + return -ENOTSUP; + } + + switch (cfg->flow_ctrl) { + case UART_CFG_FLOW_CTRL_NONE: + uarte_cfg.hwfc = NRF_UARTE_HWFC_DISABLED; + break; + case UART_CFG_FLOW_CTRL_RTS_CTS: + uarte_cfg.hwfc = NRF_UARTE_HWFC_ENABLED; + break; + default: + return -ENOTSUP; + } + +#if defined(UARTE_CONFIG_PARITYTYPE_Msk) + uarte_cfg.paritytype = NRF_UARTE_PARITYTYPE_EVEN; +#endif + switch (cfg->parity) { + case UART_CFG_PARITY_NONE: + uarte_cfg.parity = NRF_UARTE_PARITY_EXCLUDED; + break; + case UART_CFG_PARITY_EVEN: + uarte_cfg.parity = NRF_UARTE_PARITY_INCLUDED; + break; +#if defined(UARTE_CONFIG_PARITYTYPE_Msk) + case UART_CFG_PARITY_ODD: + uarte_cfg.parity = NRF_UARTE_PARITY_INCLUDED; + uarte_cfg.paritytype = NRF_UARTE_PARITYTYPE_ODD; + break; +#endif + default: + return -ENOTSUP; + } + + if (baudrate_set(nrfx_dev->p_reg, cfg->baudrate) != 0) { + return -ENOTSUP; + } + + nrfy_uarte_configure(nrfx_dev->p_reg, &uarte_cfg); + + data->uart_config = *cfg; + + return 0; +} + +static int uarte_nrfx_config_get(const struct device *dev, + struct uart_config *cfg) +{ + struct uarte_nrfx_data *data = dev->data; + + *cfg = data->uart_config; + return 0; +} +#endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */ + +#if UARTE_ANY_POLLING || UARTE_ANY_INTERRUPT_DRIVEN +static int api_err_check(const struct device *dev) +{ + if (IS_POLLING_API(dev)) { + const struct uarte_nrfx_config *cfg = dev->config; + const nrfx_uarte_t *instance = &cfg->nrfx_dev; + uint32_t mask = nrfx_uarte_errorsrc_get(instance); + + return mask; + } + + struct uarte_nrfx_data *data = dev->data; + uint32_t rv = data->async->err; + + data->async->err = 0; + + return rv; +} +#endif + +static const struct uart_async_to_irq_async_api a2i_api = { + .callback_set = callback_set, + .tx = api_tx, + .tx_abort = api_tx_abort, + .rx_enable = api_rx_enable, + .rx_buf_rsp = api_rx_buf_rsp, + .rx_disable = api_rx_disable, +}; + +static const struct uart_driver_api uart_nrfx_uarte_driver_api = { + .poll_in = api_poll_in, + .poll_out = api_poll_out, +#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE + .configure = uarte_nrfx_configure, + .config_get = uarte_nrfx_config_get, +#endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */ +#if UARTE_ANY_POLLING || UARTE_ANY_INTERRUPT_DRIVEN + .err_check = api_err_check, +#endif +#if UARTE_ANY_ASYNC + .callback_set = api_callback_set, + .tx = api_tx, + .tx_abort = api_tx_abort, + .rx_enable = api_rx_enable, + .rx_buf_rsp = api_rx_buf_rsp, + .rx_disable = api_rx_disable, +#endif /* UARTE_ANY_ASYNC */ +#if UARTE_ANY_INTERRUPT_DRIVEN + UART_ASYNC_TO_IRQ_API_INIT(), +#endif /* UARTE_ANY_INTERRUPT_DRIVEN */ +}; + +static int endtx_stoptx_ppi_init(NRF_UARTE_Type *uarte) +{ + nrfx_err_t ret; + uint8_t ch; + + ret = nrfx_gppi_channel_alloc(&ch); + if (ret != NRFX_SUCCESS) { + LOG_ERR("Failed to allocate PPI Channel"); + return -EIO; + } + + nrfx_gppi_channel_endpoints_setup(ch, + nrfy_uarte_event_address_get(uarte, NRF_UARTE_EVENT_ENDTX), + nrfy_uarte_task_address_get(uarte, NRF_UARTE_TASK_STOPTX)); + nrfx_gppi_channels_enable(BIT(ch)); + + return 0; +} + +static int start_rx(const struct device *dev) +{ + const struct uarte_nrfx_config *cfg = dev->config; + + if (IS_INT_DRIVEN_API(dev)) { + return uart_async_to_irq_rx_enable(dev); + } + + __ASSERT_NO_MSG(IS_POLLING_API(dev)); + + nrfx_err_t err; + const nrfx_uarte_t *instance = &cfg->nrfx_dev; + uint8_t *rx_byte = cfg->nrfx_config.rx_cache.p_buffer; + + err = nrfx_uarte_rx_buffer_set(instance, rx_byte, 1); + __ASSERT_NO_MSG(err == NRFX_SUCCESS); + + err = nrfx_uarte_rx_enable(instance, 0); + __ASSERT_NO_MSG(err == NRFX_SUCCESS || err == NRFX_ERROR_BUSY); + + (void)err; + + return 0; +} + +static void async_to_irq_trampoline(const struct device *dev) +{ + const struct uarte_nrfx_config *cfg = dev->config; + struct uarte_nrfx_data *data = dev->data; + uint32_t prev = atomic_or(&data->flags, UARTE_DATA_FLAG_TRAMPOLINE); + + if (!(prev & UARTE_DATA_FLAG_TRAMPOLINE)) { + nrfx_uarte_int_trigger(&cfg->nrfx_dev); + } +} + +static int uarte_nrfx_init(const struct device *dev) +{ + int err; + nrfx_err_t nerr; + const nrfx_uarte_t *nrfx_dev = get_nrfx_dev(dev); + const struct uarte_nrfx_config *cfg = dev->config; + struct uarte_nrfx_data *data = dev->data; + + err = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); + if (err < 0) { + return err; + } + + if (UARTE_ENHANCED_POLL_OUT && cfg->nrfx_config.tx_stop_on_end) { + err = endtx_stoptx_ppi_init(nrfx_dev->p_reg); + if (err < 0) { + return err; + } + } + + if (UARTE_ANY_INTERRUPT_DRIVEN) { + if (cfg->a2i_config) { + err = uart_async_to_irq_init(data->a2i_data, cfg->a2i_config); + if (err < 0) { + return err; + } + } + } + + if (IS_ENABLED(UARTE_INT_ASYNC) && data->async) { + k_timer_init(&data->async->rx_timer, rx_timeout_handler, NULL); + k_timer_user_data_set(&data->async->rx_timer, (void *)dev); + k_timer_init(&data->async->tx_timer, tx_timeout_handler, NULL); + k_timer_user_data_set(&data->async->tx_timer, (void *)dev); + } + + nerr = nrfx_uarte_init(nrfx_dev, &cfg->nrfx_config, + IS_ENABLED(UARTE_INT_ASYNC) ? + (IS_POLLING_API(dev) ? NULL : evt_handler) : NULL); + if (nerr == NRFX_SUCCESS && !IS_ASYNC_API(dev) && !(cfg->flags & UARTE_CFG_FLAG_NO_RX)) { + err = start_rx(dev); + } + + switch (nerr) { + case NRFX_ERROR_INVALID_STATE: + return -EBUSY; + case NRFX_ERROR_BUSY: + return -EACCES; + case NRFX_ERROR_INVALID_PARAM: + return -EINVAL; + default: + return 0; + } +} + +#ifdef CONFIG_PM_DEVICE +static int stop_rx(const struct device *dev) +{ + const struct uarte_nrfx_config *cfg = dev->config; + + if (IS_INT_DRIVEN_API(dev)) { + return uart_async_to_irq_rx_disable(dev); + } + + __ASSERT_NO_MSG(IS_POLLING_API(dev)); + nrfx_err_t err; + const nrfx_uarte_t *instance = &cfg->nrfx_dev; + + err = nrfx_uarte_rx_abort(instance, true, true); + __ASSERT_NO_MSG(err == NRFX_SUCCESS); + + return 0; +} + +static int uarte_nrfx_pm_action(const struct device *dev, + enum pm_device_action action) +{ + const struct uarte_nrfx_config *cfg = dev->config; + int ret; + + switch (action) { + case PM_DEVICE_ACTION_RESUME: + if (cfg->flags & UARTE_CFG_FLAG_GPIO_MGMT) { + ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); + if (ret < 0) { + return ret; + } + } + if (!IS_ASYNC_API(dev) && !(cfg->flags & UARTE_CFG_FLAG_NO_RX)) { + return start_rx(dev); + } + + break; + case PM_DEVICE_ACTION_SUSPEND: + if (!IS_ASYNC_API(dev) && !(cfg->flags & UARTE_CFG_FLAG_NO_RX)) { + stop_rx(dev); + } + + if (cfg->flags & UARTE_CFG_FLAG_GPIO_MGMT) { + ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_SLEEP); + if (ret < 0) { + return ret; + } + } + + break; + default: + return -ENOTSUP; + } + + return 0; +} +#endif + +#if defined(UARTE_CONFIG_STOP_Msk) +#define UARTE_HAS_STOP_CONFIG 1 +#endif + +#define UARTE(idx) DT_NODELABEL(uart##idx) +#define UARTE_HAS_PROP(idx, prop) DT_NODE_HAS_PROP(UARTE(idx), prop) +#define UARTE_PROP(idx, prop) DT_PROP(UARTE(idx), prop) + +/* Macro returning initial log level. Logs are off for UART used for console. */ +#define GET_INIT_LOG_LEVEL(idx) \ + COND_CODE_1(DT_HAS_CHOSEN(zephyr_console), \ + (DT_SAME_NODE(UARTE(idx), \ + DT_CHOSEN(zephyr_console)) ? \ + LOG_LEVEL_NONE : CONFIG_UART_LOG_LEVEL), \ + (CONFIG_UART_LOG_LEVEL)) + +/* Macro puts buffers in dedicated section if device tree property is set. */ +#define UARTE_MEMORY_SECTION(idx) \ + COND_CODE_1(UARTE_HAS_PROP(idx, memory_regions), \ + (__attribute__((__section__(LINKER_DT_NODE_REGION_NAME( \ + DT_PHANDLE(UARTE(idx), memory_regions)))))), \ + ()) + +#define UART_NRF_UARTE_DEVICE(idx) \ + LOG_INSTANCE_REGISTER(LOG_MODULE_NAME, idx, GET_INIT_LOG_LEVEL(idx)); \ + static uint8_t uarte##idx##_tx_cache[CONFIG_UART_##idx##_TX_CACHE_SIZE] \ + UARTE_MEMORY_SECTION(idx) __aligned(4); \ + static uint8_t uarte##idx##_rx_cache[CONFIG_UART_##idx##_RX_CACHE_SIZE] \ + UARTE_MEMORY_SECTION(idx) __aligned(4); \ + static nrfx_uarte_rx_cache_t uarte##idx##_rx_cache_scratch; \ + IF_ENABLED(CONFIG_UART_##idx##_INTERRUPT_DRIVEN, \ + (static uint8_t a2i_rx_buf##idx[CONFIG_UART_##idx##_A2I_RX_SIZE];)) \ + PINCTRL_DT_DEFINE(UARTE(idx)); \ + static const struct uart_async_to_irq_config uarte_a2i_config_##idx = \ + UART_ASYNC_TO_IRQ_API_CONFIG_INITIALIZER(&a2i_api, \ + async_to_irq_trampoline, \ + UARTE_PROP(idx, current_speed), \ + uarte##idx##_tx_cache, \ + /* nrfx_uarte driver is using the last byte in the */ \ + /* cache buffer for keeping a byte that is currently*/\ + /* polled out so it cannot be used as a cache buffer*/\ + /* by the adaptation layer. */ \ + sizeof(uarte##idx##_tx_cache) - 1, \ + COND_CODE_1(CONFIG_UART_##idx##_INTERRUPT_DRIVEN, \ + (a2i_rx_buf##idx), (NULL)), \ + COND_CODE_1(CONFIG_UART_##idx##_INTERRUPT_DRIVEN, \ + (sizeof(a2i_rx_buf##idx)), (0)), \ + CONFIG_UART_##idx##_A2I_RX_BUF_COUNT, \ + LOG_INSTANCE_PTR(LOG_MODULE_NAME, idx)); \ + static const struct uarte_nrfx_config uarte_config_##idx = { \ + .a2i_config = IS_ENABLED(CONFIG_UART_##idx## _INTERRUPT_DRIVEN) ? \ + &uarte_a2i_config_##idx : NULL, \ + .nrfx_dev = NRFX_UARTE_INSTANCE(idx), \ + .nrfx_config = { \ + .p_context = (void *)DEVICE_DT_GET(UARTE(idx)), \ + .tx_cache = { \ + .p_buffer = uarte##idx##_tx_cache, \ + .length = CONFIG_UART_##idx##_TX_CACHE_SIZE \ + }, \ + .rx_cache = { \ + .p_buffer = uarte##idx##_rx_cache, \ + .length = CONFIG_UART_##idx##_RX_CACHE_SIZE \ + }, \ + .p_rx_cache_scratch = &uarte##idx##_rx_cache_scratch, \ + .baudrate = NRF_BAUDRATE(UARTE_PROP(idx, current_speed)), \ + .interrupt_priority = DT_IRQ(UARTE(idx), priority), \ + .config = { \ + .hwfc = (UARTE_PROP(idx, hw_flow_control) == \ + UART_CFG_FLOW_CTRL_RTS_CTS) ? \ + NRF_UARTE_HWFC_ENABLED : NRF_UARTE_HWFC_DISABLED, \ + .parity = IS_ENABLED(CONFIG_UART_##idx##_NRF_PARITY_BIT) ? \ + NRF_UARTE_PARITY_INCLUDED : NRF_UARTE_PARITY_EXCLUDED, \ + IF_ENABLED(UARTE_HAS_STOP_CONFIG, (.stop = NRF_UARTE_STOP_ONE,))\ + IF_ENABLED(UARTE_ODD_PARITY_ALLOWED, \ + (.paritytype = NRF_UARTE_PARITYTYPE_EVEN,)) \ + }, \ + .tx_stop_on_end = IS_ENABLED(CONFIG_UART_##idx##_ENHANCED_POLL_OUT), \ + .skip_psel_cfg = true, \ + .skip_gpio_cfg = true, \ + }, \ + .pcfg = PINCTRL_DT_DEV_CONFIG_GET(UARTE(idx)), \ + .flags = (UARTE_PROP(idx, disable_rx) ? UARTE_CFG_FLAG_NO_RX : 0) | \ + (IS_ENABLED(CONFIG_UART_##idx##_GPIO_MANAGEMENT) ? \ + UARTE_CFG_FLAG_GPIO_MGMT : 0) | \ + (IS_ENABLED(CONFIG_UART_##idx##_INTERRUPT_DRIVEN) ? \ + UARTE_CFG_FLAG_INTERRUPT_DRIVEN_API : 0), \ + LOG_INSTANCE_PTR_INIT(log, LOG_MODULE_NAME, idx) \ + }; \ + static struct uart_async_to_irq_data uarte_a2i_data_##idx; \ + static struct uarte_async_data uarte_async_##idx; \ + static struct uarte_nrfx_data uarte_data_##idx = { \ + .a2i_data = IS_ENABLED(CONFIG_UART_##idx##_INTERRUPT_DRIVEN) ? \ + &uarte_a2i_data_##idx : NULL, \ + IF_ENABLED(CONFIG_UART_USE_RUNTIME_CONFIGURE, \ + (.uart_config = { \ + .baudrate = UARTE_PROP(idx, current_speed), \ + .parity = IS_ENABLED(CONFIG_UART_##idx##_NRF_PARITY_BIT) ? \ + UART_CFG_PARITY_EVEN : UART_CFG_PARITY_NONE, \ + .stop_bits = UART_CFG_STOP_BITS_1, \ + .data_bits = UART_CFG_DATA_BITS_8, \ + .flow_ctrl = UARTE_PROP(idx, hw_flow_control) ? \ + UART_CFG_FLOW_CTRL_RTS_CTS : UART_CFG_FLOW_CTRL_NONE, \ + },)) \ + .async = (IS_ENABLED(CONFIG_UART_##idx##_INTERRUPT_DRIVEN) || \ + IS_ENABLED(CONFIG_UART_##idx##_ASYNC)) ? &uarte_async_##idx : NULL \ + }; \ + static int uarte_init_##idx(const struct device *dev) \ + { \ + COND_CODE_1(INSTANCE_POLLING(_, /*empty*/, idx, _), (), \ + ( \ + IRQ_CONNECT(DT_IRQN(UARTE(idx)), DT_IRQ(UARTE(idx), priority), \ + nrfx_isr, nrfx_uarte_##idx##_irq_handler, 0); \ + irq_enable(DT_IRQN(UARTE(idx))); \ + ) \ + ) \ + return uarte_nrfx_init(dev); \ + } \ + PM_DEVICE_DT_DEFINE(UARTE(idx), uarte_nrfx_pm_action); \ + DEVICE_DT_DEFINE(UARTE(idx), \ + uarte_init_##idx, \ + PM_DEVICE_DT_GET(UARTE(idx)), \ + &uarte_data_##idx, \ + &uarte_config_##idx, \ + PRE_KERNEL_1, \ + CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ + &uart_nrfx_uarte_driver_api) + +/* Macro creates device instance if it is enabled in devicetree. */ +#define UARTE_DEVICE(periph, prefix, id, _) \ + IF_ENABLED(CONFIG_HAS_HW_NRF_UARTE##prefix##id, (UART_NRF_UARTE_DEVICE(prefix##id);)) + +/* Macro iterates over nrfx_uarte instances enabled in the nrfx_config.h. */ +NRFX_FOREACH_ENABLED(UARTE, UARTE_DEVICE, (), (), _) From 0c56697d7268f707c77d45c85761efd11e2effc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 13 Nov 2023 09:47:24 +0100 Subject: [PATCH 1151/1623] [nrf fromtree] tests: drivers: uart: uart_mix_fifo_poll: Align the the new nrfx driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Align test configurations to the new uart driver based on nrfx_uarte. Signed-off-by: Krzysztof Chruściński (cherry picked from commit b8c9aad728768dfc28551b5479865eff646436af) Signed-off-by: Robert Lubos --- .../uart/uart_mix_fifo_poll/testcase.yaml | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/tests/drivers/uart/uart_mix_fifo_poll/testcase.yaml b/tests/drivers/uart/uart_mix_fifo_poll/testcase.yaml index 65848e6603e..c2196c1058d 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/testcase.yaml +++ b/tests/drivers/uart/uart_mix_fifo_poll/testcase.yaml @@ -18,22 +18,22 @@ tests: - CONFIG_UART_INTERRUPT_DRIVEN=n - CONFIG_UART_ASYNC_API=n - CONFIG_UART_0_ENHANCED_POLL_OUT=n + tags: bsim_skip_CI drivers.uart.uart_mix_poll_fifo: extra_configs: - CONFIG_UART_INTERRUPT_DRIVEN=y - CONFIG_UART_0_INTERRUPT_DRIVEN=y - CONFIG_UART_0_ENHANCED_POLL_OUT=n + tags: bsim_skip_CI drivers.uart.uart_mix_poll_async_api: extra_configs: - CONFIG_UART_ASYNC_API=y - CONFIG_UART_0_INTERRUPT_DRIVEN=n - CONFIG_UART_0_ASYNC=y - - CONFIG_UART_0_NRF_HW_ASYNC=y - - CONFIG_UART_0_NRF_HW_ASYNC_TIMER=2 - - CONFIG_NRFX_TIMER2=y - CONFIG_UART_0_ENHANCED_POLL_OUT=n + tags: bsim_skip_CI drivers.uart.uart_mix_poll_async_api_const: extra_args: TEST_CONST_BUFFER=1 @@ -41,22 +41,9 @@ tests: - CONFIG_UART_ASYNC_API=y - CONFIG_UART_0_INTERRUPT_DRIVEN=n - CONFIG_UART_0_ASYNC=y - - CONFIG_UART_0_NRF_HW_ASYNC=y - - CONFIG_UART_0_NRF_HW_ASYNC_TIMER=2 - - CONFIG_NRFX_TIMER2=y - - CONFIG_UART_0_ENHANCED_POLL_OUT=n - - CONFIG_UART_ASYNC_TX_CACHE_SIZE=2 - - drivers.uart.uart_mix_poll_async_api_low_power: - extra_configs: - - CONFIG_UART_ASYNC_API=y - - CONFIG_UART_0_INTERRUPT_DRIVEN=n - - CONFIG_UART_0_ASYNC=y - - CONFIG_UART_0_NRF_HW_ASYNC=y - - CONFIG_UART_0_NRF_ASYNC_LOW_POWER=y - - CONFIG_UART_0_NRF_HW_ASYNC_TIMER=2 - - CONFIG_NRFX_TIMER2=y - CONFIG_UART_0_ENHANCED_POLL_OUT=n + - CONFIG_UART_0_TX_CACHE_SIZE=2 + tags: bsim_skip_CI # We skip a few tests to save CI time, as they give little extra coverage drivers.uart.uart_mix_poll_with_ppi: extra_configs: @@ -75,18 +62,29 @@ tests: - CONFIG_UART_ASYNC_API=y - CONFIG_UART_0_INTERRUPT_DRIVEN=n - CONFIG_UART_0_ASYNC=y - - CONFIG_UART_0_NRF_HW_ASYNC=y - - CONFIG_UART_0_NRF_HW_ASYNC_TIMER=2 - - CONFIG_NRFX_TIMER2=y - CONFIG_UART_0_ENHANCED_POLL_OUT=y - drivers.uart.uart_mix_poll_async_api_with_ppi_low_power: + drivers.uart.legacy.uart_mix_poll: + extra_configs: + - CONFIG_UART_INTERRUPT_DRIVEN=n + - CONFIG_UART_ASYNC_API=n + - CONFIG_UART_0_ENHANCED_POLL_OUT=n + - CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=y + + drivers.uart.legacy.uart_mix_poll_fifo: + extra_configs: + - CONFIG_UART_INTERRUPT_DRIVEN=y + - CONFIG_UART_0_INTERRUPT_DRIVEN=y + - CONFIG_UART_0_ENHANCED_POLL_OUT=n + - CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=y + + drivers.uart.legacy.uart_mix_poll_async_api: extra_configs: - CONFIG_UART_ASYNC_API=y - CONFIG_UART_0_INTERRUPT_DRIVEN=n - CONFIG_UART_0_ASYNC=y + - CONFIG_UART_0_ENHANCED_POLL_OUT=n - CONFIG_UART_0_NRF_HW_ASYNC=y - - CONFIG_UART_0_NRF_ASYNC_LOW_POWER=y - CONFIG_UART_0_NRF_HW_ASYNC_TIMER=2 - CONFIG_NRFX_TIMER2=y - - CONFIG_UART_0_ENHANCED_POLL_OUT=y + - CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=y From 3ba0914d271c4a989fc52bf796fca20dad92f1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Wed, 17 Jan 2024 12:24:05 +0100 Subject: [PATCH 1152/1623] [nrf fromtree] tests: drivers: uart: async_api: Add configuration for legacy nrf driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add configuration which tests legacy nrf uart driver. Prevent tests on nrf52_bsim of the new driver (it is requiring adjustments for the simulation). It will be fixed by another patch. Signed-off-by: Krzysztof Chruściński (cherry picked from commit e47bdb2555c8c63443a2baf375571439ed9255a9) Signed-off-by: Robert Lubos --- tests/drivers/uart/uart_async_api/testcase.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/drivers/uart/uart_async_api/testcase.yaml b/tests/drivers/uart/uart_async_api/testcase.yaml index e9914d48d99..3c5f2d5583e 100644 --- a/tests/drivers/uart/uart_async_api/testcase.yaml +++ b/tests/drivers/uart/uart_async_api/testcase.yaml @@ -13,6 +13,7 @@ tests: harness_config: fixture: gpio_loopback depends_on: gpio + tags: bsim_skip_CI drivers.uart.wide: filter: CONFIG_UART_CONSOLE and CONFIG_SERIAL_SUPPORT_ASYNC and not CONFIG_UART_MCUX_LPUART harness: ztest @@ -25,6 +26,15 @@ tests: platform_allow: nucleo_h743zi integration_platforms: - nucleo_h743zi + drivers.uart.async_api.nrf_uarte_legacy: + platform_allow: nrf52840dk_nrf52840 nrf52_bsim + filter: CONFIG_SERIAL_SUPPORT_ASYNC + harness: ztest + harness_config: + fixture: gpio_loopback + depends_on: gpio + extra_configs: + - CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=y drivers.uart.async_api.nrf_uart: filter: CONFIG_UART_CONSOLE and CONFIG_SERIAL_SUPPORT_ASYNC harness: ztest From a7c7dcca6ec221b134a1306428920c431bffc77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Wed, 17 Jan 2024 12:25:02 +0100 Subject: [PATCH 1153/1623] [nrf fromtree] tests: drivers: uart: uart_pm: Use legacy nrf driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New nrf uart shim requires addiotional work around PM. Use legacy version for those tests until it is fixed. Signed-off-by: Krzysztof Chruściński (cherry picked from commit 2ebf83176c2bd7012a49f1d9b5b6247f36a20efe) Signed-off-by: Robert Lubos --- tests/drivers/uart/uart_pm/testcase.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/drivers/uart/uart_pm/testcase.yaml b/tests/drivers/uart/uart_pm/testcase.yaml index efb76ecf2c1..4d71ed881cd 100644 --- a/tests/drivers/uart/uart_pm/testcase.yaml +++ b/tests/drivers/uart/uart_pm/testcase.yaml @@ -13,12 +13,14 @@ tests: - CONFIG_UART_INTERRUPT_DRIVEN=n - CONFIG_UART_ASYNC_API=n - CONFIG_UART_0_ENHANCED_POLL_OUT=n + - CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=y drivers.uart.pm.no_rxpin: extra_configs: - CONFIG_UART_INTERRUPT_DRIVEN=n - CONFIG_UART_ASYNC_API=n - CONFIG_UART_0_ENHANCED_POLL_OUT=n + - CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=y extra_args: DTC_OVERLAY_FILE="boards/nrf52840dk_nrf52840.overlay;nrf_rx_disable.overlay" drivers.uart.pm.enhanced_poll: @@ -26,6 +28,7 @@ tests: - CONFIG_UART_INTERRUPT_DRIVEN=n - CONFIG_UART_ASYNC_API=n - CONFIG_UART_0_ENHANCED_POLL_OUT=y + - CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=y drivers.uart.pm.int_driven: extra_configs: @@ -33,6 +36,7 @@ tests: - CONFIG_UART_0_INTERRUPT_DRIVEN=y - CONFIG_UART_ASYNC_API=n - CONFIG_UART_0_ENHANCED_POLL_OUT=n + - CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=y drivers.uart.pm.int_driven.enhanced_poll: extra_configs: @@ -40,6 +44,7 @@ tests: - CONFIG_UART_0_INTERRUPT_DRIVEN=y - CONFIG_UART_ASYNC_API=n - CONFIG_UART_0_ENHANCED_POLL_OUT=y + - CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=y drivers.uart.pm.async: extra_configs: @@ -50,6 +55,7 @@ tests: - CONFIG_UART_0_NRF_HW_ASYNC_TIMER=2 - CONFIG_NRFX_TIMER2=y - CONFIG_UART_0_ENHANCED_POLL_OUT=n + - CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=y drivers.uart.pm.async.enhanced_poll: extra_configs: @@ -60,3 +66,4 @@ tests: - CONFIG_UART_0_NRF_HW_ASYNC_TIMER=2 - CONFIG_NRFX_TIMER2=y - CONFIG_UART_0_ENHANCED_POLL_OUT=y + - CONFIG_UART_NRFX_UARTE_LEGACY_SHIM=y From e1b8a38b2bf50d98d1ec4689d1f649083bc93b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Wed, 17 Jan 2024 12:56:28 +0100 Subject: [PATCH 1154/1623] [nrf fromtree] boards: posix: nrf_bsim: Use legacy UART shim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New UART shim must be adapted to work in the simulated environment. Use legacy version until it is fixed. Signed-off-by: Krzysztof Chruściński (cherry picked from commit e2dccab4d5103fa6ac9745c610697666e244c708) Signed-off-by: Robert Lubos --- boards/posix/nrf_bsim/Kconfig.defconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/boards/posix/nrf_bsim/Kconfig.defconfig b/boards/posix/nrf_bsim/Kconfig.defconfig index 6993048248c..0ee4c6ee2c1 100644 --- a/boards/posix/nrf_bsim/Kconfig.defconfig +++ b/boards/posix/nrf_bsim/Kconfig.defconfig @@ -93,4 +93,7 @@ config UART_CONSOLE endif # CONSOLE +config UART_NRFX_UARTE_LEGACY_SHIM + default y + endif # SOC_SERIES_BSIM_NRFXX From 4e00677dfdd416b25178f9d38e40dda39306c0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Fri, 19 Jan 2024 10:59:10 +0100 Subject: [PATCH 1155/1623] [nrf fromtree] drivers: serial: nrfx_uarte: Use legacy shim by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New shim takes more flash and is causing some tests to overflow the ROM memory. Switching to the legacy shim as default until it is fixed. Signed-off-by: Krzysztof Chruściński (cherry picked from commit fb185fb5bd84efb9128ebceb671d051c711c2d71) --- drivers/serial/Kconfig.nrfx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/serial/Kconfig.nrfx b/drivers/serial/Kconfig.nrfx index 5709ca2d23a..21a657fbaf4 100644 --- a/drivers/serial/Kconfig.nrfx +++ b/drivers/serial/Kconfig.nrfx @@ -31,9 +31,8 @@ config UART_NRFX_UARTE config UART_NRFX_UARTE_LEGACY_SHIM bool "Legacy UARTE shim" depends on UART_NRFX_UARTE - # New shim takes more ROM. Until it is fixed use legacy shim in memory - # constraint case. - default y if MCUBOOT + # New shim takes more ROM. Until it is fixed use legacy shim. + default y config UART_ASYNC_TX_CACHE_SIZE int "TX cache buffer size" From b4b61f3c7e80c13326d12d83b4769bb041579017 Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Thu, 18 Jan 2024 15:17:38 +0100 Subject: [PATCH 1156/1623] [nrf fromtree] drivers: serial: align to nRF54L15 Align UARTE driver config to nRF54L15. Signed-off-by: Magdalena Pastula (cherry picked from commit 9b3b34f16e9645524007050e52b96437f96334bb) --- drivers/serial/Kconfig.nrfx | 27 +++++++++++++++++++++++ drivers/serial/Kconfig.nrfx_uart_instance | 1 + 2 files changed, 28 insertions(+) diff --git a/drivers/serial/Kconfig.nrfx b/drivers/serial/Kconfig.nrfx index 21a657fbaf4..8995b6b9fbf 100644 --- a/drivers/serial/Kconfig.nrfx +++ b/drivers/serial/Kconfig.nrfx @@ -31,6 +31,8 @@ config UART_NRFX_UARTE config UART_NRFX_UARTE_LEGACY_SHIM bool "Legacy UARTE shim" depends on UART_NRFX_UARTE + # NRF54L15 need new UARTE driver + depends on !SOC_SERIES_NRF54LX # New shim takes more ROM. Until it is fixed use legacy shim. default y @@ -64,6 +66,31 @@ nrfx_uart_num = 3 rsource "Kconfig.nrfx_uart_instance" endif +if HAS_HW_NRF_UARTE00 +nrfx_uart_num = 00 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE20 +nrfx_uart_num = 20 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE21 +nrfx_uart_num = 21 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE22 +nrfx_uart_num = 22 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE30 +nrfx_uart_num = 30 +rsource "Kconfig.nrfx_uart_instance" +endif + config NRFX_TIMER0 default y depends on UART_0_NRF_HW_ASYNC_TIMER = 0 \ diff --git a/drivers/serial/Kconfig.nrfx_uart_instance b/drivers/serial/Kconfig.nrfx_uart_instance index 76f74caa038..718631a4d09 100644 --- a/drivers/serial/Kconfig.nrfx_uart_instance +++ b/drivers/serial/Kconfig.nrfx_uart_instance @@ -20,6 +20,7 @@ config UART_$(nrfx_uart_num)_ASYNC config UART_$(nrfx_uart_num)_ENHANCED_POLL_OUT bool "Efficient poll out on port $(nrfx_uart_num)" + depends on !SOC_SERIES_NRF54LX default y depends on HAS_HW_NRF_UARTE$(nrfx_uart_num) select NRFX_PPI if HAS_HW_NRF_PPI From 263b754845e73c8dcc74f3d45c69e9766b94cf6d Mon Sep 17 00:00:00 2001 From: Witold Lukasik Date: Mon, 11 Dec 2023 15:10:04 +0100 Subject: [PATCH 1157/1623] [nrf fromtree] drivers: timer: move SYSTEM_CLOCK_WAIT to Kconfig.nrf_xrtc SYSTEM_CLOCK_WAIT will be a common part for a next version of Nordic timer. Signed-off-by: Witold Lukasik (cherry picked from commit ae78cf017d9a2da978c89278a0e6de5f2269462e) --- drivers/timer/Kconfig | 1 + drivers/timer/Kconfig.nrf_rtc | 32 ---------------------------- drivers/timer/Kconfig.nrf_xrtc | 38 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 drivers/timer/Kconfig.nrf_xrtc diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index 8a88e731986..b7e01eb5811 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -84,6 +84,7 @@ source "drivers/timer/Kconfig.mips_cp0" source "drivers/timer/Kconfig.native_posix" source "drivers/timer/Kconfig.npcx_itim" source "drivers/timer/Kconfig.nrf_rtc" +source "drivers/timer/Kconfig.nrf_xrtc" source "drivers/timer/Kconfig.rcar_cmt" source "drivers/timer/Kconfig.riscv_machine" source "drivers/timer/Kconfig.rv32m1_lptmr" diff --git a/drivers/timer/Kconfig.nrf_rtc b/drivers/timer/Kconfig.nrf_rtc index baa917282bc..729dc8d362a 100644 --- a/drivers/timer/Kconfig.nrf_rtc +++ b/drivers/timer/Kconfig.nrf_rtc @@ -42,36 +42,4 @@ config NRF_RTC_TIMER_TRIGGER_OVERFLOW When enabled, a function can be used to trigger RTC overflow and effectively shift time into the future. -choice - prompt "Clock startup policy" - default SYSTEM_CLOCK_WAIT_FOR_STABILITY - -config SYSTEM_CLOCK_NO_WAIT - bool "No wait" - help - System clock source is initiated but does not wait for clock readiness. - When this option is picked, system clock may not be ready when code relying - on kernel API is executed. Requested timeouts will be prolonged by the - remaining startup time. - -config SYSTEM_CLOCK_WAIT_FOR_AVAILABILITY - bool "Wait for availability" - help - System clock source initialization waits until clock is available. In some - systems, clock initially runs from less accurate source which has faster - startup time and then seamlessly switches to the target clock source when - it is ready. When this option is picked, system clock is available after - system clock driver initialization but it may be less accurate. Option is - equivalent to waiting for stability if clock source does not have - intermediate state. - -config SYSTEM_CLOCK_WAIT_FOR_STABILITY - bool "Wait for stability" - help - System clock source initialization waits until clock is stable. When this - option is picked, system clock is available and stable after system clock - driver initialization. - -endchoice - endif # NRF_RTC_TIMER diff --git a/drivers/timer/Kconfig.nrf_xrtc b/drivers/timer/Kconfig.nrf_xrtc new file mode 100644 index 00000000000..56efbc3a298 --- /dev/null +++ b/drivers/timer/Kconfig.nrf_xrtc @@ -0,0 +1,38 @@ +# Common RTC configuration + +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if NRF_RTC_TIMER +choice + prompt "Clock startup policy" + default SYSTEM_CLOCK_WAIT_FOR_STABILITY + +config SYSTEM_CLOCK_NO_WAIT + bool "No wait" + help + System clock source is initiated but does not wait for clock readiness. + When this option is picked, system clock may not be ready when code relying + on kernel API is executed. Requested timeouts will be prolonged by the + remaining startup time. + +config SYSTEM_CLOCK_WAIT_FOR_AVAILABILITY + bool "Wait for availability" + help + System clock source initialization waits until clock is available. In some + systems, clock initially runs from less accurate source which has faster + startup time and then seamlessly switches to the target clock source when + it is ready. When this option is picked, system clock is available after + system clock driver initialization but it may be less accurate. Option is + equivalent to waiting for stability if clock source does not have + intermediate state. + +config SYSTEM_CLOCK_WAIT_FOR_STABILITY + bool "Wait for stability" + help + System clock source initialization waits until clock is stable. When this + option is picked, system clock is available and stable after system clock + driver initialization. + +endchoice +endif # NRF_RTC_TIMER From c30a6ee741141d0cce1f3608bb07872c1c612c5e Mon Sep 17 00:00:00 2001 From: Witold Lukasik Date: Mon, 11 Dec 2023 15:13:40 +0100 Subject: [PATCH 1158/1623] [nrf fromtree] soc: arm: nordic_nrf: move NRF_RTC_TIMER not to be selected as default NRF_RTC_TIMER will not be a default timer in the next version of Nordic timer. It should be soc selection specific. Signed-off-by: Witold Lukasik (cherry picked from commit daa888c37ba71da40b3e78a60ab77afb5463d2a4) --- soc/arm/nordic_nrf/Kconfig.defconfig | 5 +---- soc/arm/nordic_nrf/nrf51/Kconfig.defconfig.series | 4 ++++ soc/arm/nordic_nrf/nrf52/Kconfig.defconfig.series | 4 ++++ soc/arm/nordic_nrf/nrf53/Kconfig.defconfig.series | 4 ++++ soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.series | 4 ++++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/soc/arm/nordic_nrf/Kconfig.defconfig b/soc/arm/nordic_nrf/Kconfig.defconfig index 858c60d1d88..c20df806186 100644 --- a/soc/arm/nordic_nrf/Kconfig.defconfig +++ b/soc/arm/nordic_nrf/Kconfig.defconfig @@ -7,15 +7,12 @@ if SOC_FAMILY_NRF source "soc/arm/nordic_nrf/*/Kconfig.defconfig.series" -# If the kernel has timer support, enable both clock control and timer +# If the kernel has timer support, enable clock control if SYS_CLOCK_EXISTS config CLOCK_CONTROL default y -config NRF_RTC_TIMER - default y - endif # SYS_CLOCK_EXISTS config SYS_CLOCK_HW_CYCLES_PER_SEC diff --git a/soc/arm/nordic_nrf/nrf51/Kconfig.defconfig.series b/soc/arm/nordic_nrf/nrf51/Kconfig.defconfig.series index 8c0bc74c02f..a4053bf7fed 100644 --- a/soc/arm/nordic_nrf/nrf51/Kconfig.defconfig.series +++ b/soc/arm/nordic_nrf/nrf51/Kconfig.defconfig.series @@ -14,4 +14,8 @@ config SOC_SERIES config NUM_IRQS default 26 +# If the kernel has timer support, enable the timer +config NRF_RTC_TIMER + default y if SYS_CLOCK_EXISTS + endif # SOC_SERIES_NRF51X diff --git a/soc/arm/nordic_nrf/nrf52/Kconfig.defconfig.series b/soc/arm/nordic_nrf/nrf52/Kconfig.defconfig.series index 4a7edf2aa95..2e89a5130a6 100644 --- a/soc/arm/nordic_nrf/nrf52/Kconfig.defconfig.series +++ b/soc/arm/nordic_nrf/nrf52/Kconfig.defconfig.series @@ -10,4 +10,8 @@ source "soc/arm/nordic_nrf/nrf52/Kconfig.defconfig.nrf52*" config SOC_SERIES default "nrf52" +# If the kernel has timer support, enable the timer +config NRF_RTC_TIMER + default y if SYS_CLOCK_EXISTS + endif # SOC_SERIES_NRF52X diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.defconfig.series b/soc/arm/nordic_nrf/nrf53/Kconfig.defconfig.series index 2857d5dd25d..7e5660cf514 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.defconfig.series +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.defconfig.series @@ -10,4 +10,8 @@ source "soc/arm/nordic_nrf/nrf53/Kconfig.defconfig.nrf53*" config SOC_SERIES default "nrf53" +# If the kernel has timer support, enable the timer +config NRF_RTC_TIMER + default y if SYS_CLOCK_EXISTS + endif # SOC_SERIES_NRF53X diff --git a/soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.series b/soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.series index 9612555a4c8..6d6cccab999 100644 --- a/soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.series +++ b/soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.series @@ -10,4 +10,8 @@ source "soc/arm/nordic_nrf/nrf91/Kconfig.defconfig.nrf91*" config SOC_SERIES default "nrf91" +# If the kernel has timer support, enable the timer +config NRF_RTC_TIMER + default y if SYS_CLOCK_EXISTS + endif # SOC_SERIES_NRF91X From 0cf636a2e69718692534fa3b6b8e5827f4250bff Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Tue, 9 Jan 2024 15:47:17 +0100 Subject: [PATCH 1159/1623] [nrf fromtree] dts: binding: add binding for GRTC Add dts bindings for Global Real-Time Counter. Signed-off-by: Magdalena Pastula (cherry picked from commit 1d91a09bfee6f66c5063034784afa44e02463a60) --- dts/bindings/misc/nordic,split-channels.yaml | 44 ++++++++++++++++++++ dts/bindings/timer/nordic,nrf-grtc.yaml | 25 +++++++++++ 2 files changed, 69 insertions(+) create mode 100644 dts/bindings/misc/nordic,split-channels.yaml create mode 100644 dts/bindings/timer/nordic,nrf-grtc.yaml diff --git a/dts/bindings/misc/nordic,split-channels.yaml b/dts/bindings/misc/nordic,split-channels.yaml new file mode 100644 index 00000000000..a875dc12d7f --- /dev/null +++ b/dts/bindings/misc/nordic,split-channels.yaml @@ -0,0 +1,44 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +description: | + Nordic Split Channels + + Some of Nordic's peripherals support split ownership feature that allows to + be used by independent owners. As an example the configuration of the + Global Real Time Counter (GRTC) is shown below: + owned-channels = <0 1 2 3 4 5 6 7 8 9 10 11>; + child-owned-channels = <7 8 9 10 11>; + + Which means that channels 0-11 will be assigned to the particular CPU. + Other CPUs cannot use those and another set must be defined for them. + In addition, `child-owned-channels` property allows to use channels + 7-11 only by child subprocessor. If the CPU you're configuring has no + subprocessor(s) assigned, the `child-owned-channels` property + should not be defined. + +properties: + owned-channels: + type: array + description: | + List of channels in a split-ownership peripheral that are to be owned + for use by the compiled CPU. + + nonsecure-channels: + type: array + description: | + List of channels in a split-ownership, split-security peripheral that + are to be configured as nonsecure. In Trustzone systems, this property + is only evaluated for secure peripherals, as nonsecure channels are + implicitly specified through the owned-channels property. This property + is ignored in non-Trustzone systems. + + child-owned-channels: + type: array + description: | + List of channels in a split-ownership peripheral that are officially + owned by the compiled CPU but intended to be used by its child + subprocessor(s). diff --git a/dts/bindings/timer/nordic,nrf-grtc.yaml b/dts/bindings/timer/nordic,nrf-grtc.yaml new file mode 100644 index 00000000000..e78e57df97e --- /dev/null +++ b/dts/bindings/timer/nordic,nrf-grtc.yaml @@ -0,0 +1,25 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +description: Nordic GRTC (Global RTC) + +compatible: "nordic,nrf-grtc" + +include: + - "base.yaml" + - "nordic,split-channels.yaml" + +properties: + reg: + required: true + + interrupts: + required: true + + cc-num: + description: Number of capture/compare channels + type: int + required: true From 6009ece2edb63e0b524efc01a6dbf52662b685bc Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Tue, 9 Jan 2024 15:48:04 +0100 Subject: [PATCH 1160/1623] [nrf fromtree] modules: hal_nordic: nrfx: add nRF54L15 GRTC instance Add GRTC instance in Nordic HAL configs. Signed-off-by: Magdalena Pastula (cherry picked from commit d3fa931dfdc01ac30c8fff4f443c2016317b5600) --- modules/hal_nordic/nrfx/CMakeLists.txt | 7 +++++++ modules/hal_nordic/nrfx/Kconfig | 4 ++++ modules/hal_nordic/nrfx/Kconfig.logging | 4 ++++ modules/hal_nordic/nrfx/nrfx_config.h | 7 +++++++ 4 files changed, 22 insertions(+) diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index 69afbcc9c51..2e809c52b79 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -31,6 +31,8 @@ zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF5340_CPUAPP NRF5340_XXAA_APP zephyr_compile_definitions_ifdef(CONFIG_SOC_COMPATIBLE_NRF5340_CPUAPP NRF5340_XXAA_APPLICATION) zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF5340_CPUNET NRF5340_XXAA_NETWORK) zephyr_compile_definitions_ifdef(CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET NRF5340_XXAA_NETWORK) +zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L15_ENGA NRF54L15_ENGA_XXAA) +zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L15_ENGA_CPUAPP NRF_APPLICATION) zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9120 NRF9120_XXAA) zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9160 NRF9160_XXAA) @@ -79,6 +81,7 @@ zephyr_library_sources_ifdef(CONFIG_NRFX_COMP ${SRC_DIR}/nrfx_comp.c) zephyr_library_sources_ifdef(CONFIG_NRFX_DPPI ${SRC_DIR}/nrfx_dppi.c) zephyr_library_sources_ifdef(CONFIG_NRFX_EGU ${SRC_DIR}/nrfx_egu.c) zephyr_library_sources_ifdef(CONFIG_NRFX_GPIOTE ${SRC_DIR}/nrfx_gpiote.c) +zephyr_library_sources_ifdef(CONFIG_NRFX_GRTC ${SRC_DIR}/nrfx_grtc.c) zephyr_library_sources_ifdef(CONFIG_NRFX_I2S ${SRC_DIR}/nrfx_i2s.c) zephyr_library_sources_ifdef(CONFIG_NRFX_IPC ${SRC_DIR}/nrfx_ipc.c) zephyr_library_sources_ifdef(CONFIG_NRFX_LPCOMP ${SRC_DIR}/nrfx_lpcomp.c) @@ -111,6 +114,10 @@ if(CONFIG_NRFX_TWI OR CONFIG_NRFX_TWIM) zephyr_library_sources(${SRC_DIR}/nrfx_twi_twim.c) endif() +if (CONFIG_NRF_GRTC_TIMER AND CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) + zephyr_library_compile_definitions(NRF_GRTC_HAS_EXTENDED=1) +endif() + # Inject HAL "CONFIG_NFCT_PINS_AS_GPIOS" definition if user requests to # configure the NFCT pins as GPIOS. Do the same with "CONFIG_GPIO_AS_PINRESET" # to configure the reset GPIO as nRESET. This way, the HAL will take care of diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index b4c00040ee1..bdca4016ee3 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -103,6 +103,10 @@ config NRFX_GPIOTE_NUM_OF_EVT_HANDLERS Specifies number of handlers that can be registered to nrfx_gpiote driver by the user. +config NRFX_GRTC + bool "GRTC driver" + depends on $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_GRTC)) + config NRFX_I2S bool diff --git a/modules/hal_nordic/nrfx/Kconfig.logging b/modules/hal_nordic/nrfx/Kconfig.logging index 7f7b785e70c..b24d683d3de 100644 --- a/modules/hal_nordic/nrfx/Kconfig.logging +++ b/modules/hal_nordic/nrfx/Kconfig.logging @@ -28,6 +28,10 @@ config NRFX_GPIOTE_LOG bool "GPIOTE driver logging" depends on NRFX_GPIOTE +config NRFX_GRTC_LOG + bool "GRTC driver logging" + depends on NRFX_GRTC + config NRFX_I2S_LOG bool "I2S driver logging" depends on NRFX_I2S diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index ac930b13639..451101c8f4b 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -109,6 +109,13 @@ #define NRFX_EGU5_ENABLED 1 #endif +#ifdef CONFIG_NRFX_GRTC +#define NRFX_GRTC_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_GRTC_LOG +#define NRFX_GRTC_CONFIG_LOG_ENABLED 1 +#endif + #ifdef CONFIG_NRFX_GPIOTE #define NRFX_GPIOTE_ENABLED 1 #endif From 506370123592c171541e50b721031ea7cf63dfe3 Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Tue, 9 Jan 2024 15:49:11 +0100 Subject: [PATCH 1161/1623] [nrf fromtree] soc: arm: nordic_nrf: add support for nRF54L15 GRTC instance Add GRTC as possible clock source. Signed-off-by: Magdalena Pastula (cherry picked from commit 70b21845b219cbd7a4bffd4f997fe604b8edd87d) --- soc/arm/nordic_nrf/Kconfig.defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/soc/arm/nordic_nrf/Kconfig.defconfig b/soc/arm/nordic_nrf/Kconfig.defconfig index c20df806186..879217a92fe 100644 --- a/soc/arm/nordic_nrf/Kconfig.defconfig +++ b/soc/arm/nordic_nrf/Kconfig.defconfig @@ -16,10 +16,12 @@ config CLOCK_CONTROL endif # SYS_CLOCK_EXISTS config SYS_CLOCK_HW_CYCLES_PER_SEC + default 1000000 if NRF_GRTC_TIMER default 32768 config SYS_CLOCK_TICKS_PER_SEC default 128 if !TICKLESS_KERNEL + default 10000 if NRF_GRTC_TIMER default 32768 config ARCH_HAS_CUSTOM_BUSY_WAIT From bc68b120ee5d59ffa948f07df3f108e718709f5a Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Tue, 9 Jan 2024 15:49:46 +0100 Subject: [PATCH 1162/1623] [nrf fromtree] drivers: timer: add GRTC driver Add Nordic driver for GRTC. Signed-off-by: Magdalena Pastula (cherry picked from commit b605c4219bf34663d249ffbcdf0fb735f3daaead) --- drivers/timer/CMakeLists.txt | 1 + drivers/timer/Kconfig | 1 + drivers/timer/Kconfig.nrf_grtc | 48 ++ drivers/timer/Kconfig.nrf_xrtc | 4 +- drivers/timer/nrf_grtc_timer.c | 566 ++++++++++++++++++ include/zephyr/drivers/timer/nrf_grtc_timer.h | 202 +++++++ 6 files changed, 820 insertions(+), 2 deletions(-) create mode 100644 drivers/timer/Kconfig.nrf_grtc create mode 100644 drivers/timer/nrf_grtc_timer.c create mode 100644 include/zephyr/drivers/timer/nrf_grtc_timer.h diff --git a/drivers/timer/CMakeLists.txt b/drivers/timer/CMakeLists.txt index 47a10b358c1..36534e4716f 100644 --- a/drivers/timer/CMakeLists.txt +++ b/drivers/timer/CMakeLists.txt @@ -24,6 +24,7 @@ zephyr_library_sources_ifdef(CONFIG_MCUX_GPT_TIMER mcux_gpt_timer.c) zephyr_library_sources_ifdef(CONFIG_MIPS_CP0_TIMER mips_cp0_timer.c) zephyr_library_sources_ifdef(CONFIG_NATIVE_POSIX_TIMER native_posix_timer.c) zephyr_library_sources_ifdef(CONFIG_NPCX_ITIM_TIMER npcx_itim_timer.c) +zephyr_library_sources_ifdef(CONFIG_NRF_GRTC_TIMER nrf_grtc_timer.c) zephyr_library_sources_ifdef(CONFIG_NRF_RTC_TIMER nrf_rtc_timer.c) zephyr_library_sources_ifdef(CONFIG_RCAR_CMT_TIMER rcar_cmt_timer.c) zephyr_library_sources_ifdef(CONFIG_RISCV_MACHINE_TIMER riscv_machine_timer.c) diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index b7e01eb5811..f20442dd2c5 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -84,6 +84,7 @@ source "drivers/timer/Kconfig.mips_cp0" source "drivers/timer/Kconfig.native_posix" source "drivers/timer/Kconfig.npcx_itim" source "drivers/timer/Kconfig.nrf_rtc" +source "drivers/timer/Kconfig.nrf_grtc" source "drivers/timer/Kconfig.nrf_xrtc" source "drivers/timer/Kconfig.rcar_cmt" source "drivers/timer/Kconfig.riscv_machine" diff --git a/drivers/timer/Kconfig.nrf_grtc b/drivers/timer/Kconfig.nrf_grtc new file mode 100644 index 00000000000..442c524fd19 --- /dev/null +++ b/drivers/timer/Kconfig.nrf_grtc @@ -0,0 +1,48 @@ +# Timer driver configuration options +# Copyright (c) 2024 Nordic Semiconductor ASA + +menuconfig NRF_GRTC_TIMER + bool "nRF GRTC Timer" + default y if DT_HAS_NORDIC_NRF_GRTC_ENABLED + select TICKLESS_CAPABLE + select TIMER_HAS_64BIT_CYCLE_COUNTER + select NRFX_GRTC + help + This module implements a kernel device driver for the nRF Global Real + Time Counter NRF_GRTC and provides the standard "system clock driver" + interfaces. + +if NRF_GRTC_TIMER + +config NRF_GRTC_SLEEP_ALLOWED + def_bool y + depends on POWEROFF + help + This feature allows GRTC SYSCOUNTER to go to sleep state. + +config NRF_GRTC_TIMER_APP_DEFINED_INIT + bool "Application defines GRTC initialization" + help + Application defines the initialization procedure and time of the GRTC + drivers, rather than leaving it up to SYS_INIT. + +config NRF_GRTC_START_SYSCOUNTER + bool "Start SYSCOUNTER on driver init" + select NRF_GRTC_TIMER_CLOCK_MANAGEMENT + help + Start the SYSCOUNTER when initializing the GRTC. This should only be + handled by one processor in the system. + +config NRF_GRTC_TIMER_CLOCK_MANAGEMENT + bool + help + Compile additional driver code for enabling management functionality of + the GRTC. Usually this is only needed by the processor that is starting + the SYSCOUNTER, but can be shared by multiple processors in the system. + +config NRF_GRTC_SLEEP_MINIMUM_LATENCY + int + default 1000 + depends on NRF_GRTC_SLEEP_ALLOWED + +endif # NRF_GRTC_TIMER diff --git a/drivers/timer/Kconfig.nrf_xrtc b/drivers/timer/Kconfig.nrf_xrtc index 56efbc3a298..f9fa25a1c30 100644 --- a/drivers/timer/Kconfig.nrf_xrtc +++ b/drivers/timer/Kconfig.nrf_xrtc @@ -3,7 +3,7 @@ # Copyright (c) 2023 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -if NRF_RTC_TIMER +if NRF_RTC_TIMER || NRF_GRTC_TIMER choice prompt "Clock startup policy" default SYSTEM_CLOCK_WAIT_FOR_STABILITY @@ -35,4 +35,4 @@ config SYSTEM_CLOCK_WAIT_FOR_STABILITY driver initialization. endchoice -endif # NRF_RTC_TIMER +endif # NRF_RTC_TIMER || NRF_GRTC_TIMER diff --git a/drivers/timer/nrf_grtc_timer.c b/drivers/timer/nrf_grtc_timer.c new file mode 100644 index 00000000000..dc6ac410905 --- /dev/null +++ b/drivers/timer/nrf_grtc_timer.c @@ -0,0 +1,566 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define CHAN_COUNT NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS +#define EXT_CHAN_COUNT (CHAN_COUNT - 1) +/* The reset value of waketime is 1, which doesn't seem to work. + * It's being looked into, but for the time being use 4. + * Timeout must always be higher than waketime, so setting that to 5. + */ +#define WAKETIME (4) +#define TIMEOUT (WAKETIME + 1) + +#define GRTC_NODE DT_NODELABEL(grtc) + +#ifndef GRTC_SYSCOUNTERL_VALUE_Msk +#define GRTC_SYSCOUNTERL_VALUE_Msk GRTC_SYSCOUNTER_SYSCOUNTERL_VALUE_Msk +#endif + +#ifndef GRTC_SYSCOUNTERH_VALUE_Msk +#define GRTC_SYSCOUNTERH_VALUE_Msk GRTC_SYSCOUNTER_SYSCOUNTERH_VALUE_Msk +#endif + +#define MAX_CC_LATCH_WAIT_TIME_US 77 + +#define CYC_PER_TICK \ + ((uint64_t)sys_clock_hw_cycles_per_sec() / (uint64_t)CONFIG_SYS_CLOCK_TICKS_PER_SEC) + +#define COUNTER_SPAN (GRTC_SYSCOUNTERL_VALUE_Msk | ((uint64_t)GRTC_SYSCOUNTERH_VALUE_Msk << 32)) +#define MAX_TICKS \ + (((COUNTER_SPAN / CYC_PER_TICK) > INT_MAX) ? INT_MAX : (COUNTER_SPAN / CYC_PER_TICK)) + +#define MAX_CYCLES (MAX_TICKS * CYC_PER_TICK) + +/* The maximum SYSCOUNTERVALID settling time equals 1x32k cycles + 20x1MHz cycles. */ +#define GRTC_SYSCOUNTERVALID_SETTLE_MAX_TIME_US 51 + +#if defined(CONFIG_TEST) +const int32_t z_sys_timer_irq_for_test = DT_IRQN(GRTC_NODE); +#endif + +static void sys_clock_timeout_handler(int32_t id, uint64_t cc_val, void *p_context); + +static struct k_spinlock lock; +static uint64_t last_count; +static atomic_t int_mask; +static uint8_t ext_channels_allocated; +static nrfx_grtc_channel_t system_clock_channel_data = { + .handler = sys_clock_timeout_handler, + .p_context = NULL, + .channel = (uint8_t)-1, +}; + +#define IS_CHANNEL_ALLOWED_ASSERT(chan) \ + __ASSERT_NO_MSG((NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK & (1UL << (chan))) && \ + ((chan) != system_clock_channel_data.channel)) + +static inline void grtc_active_set(void) +{ +#if defined(NRF_GRTC_HAS_SYSCOUNTER_ARRAY) && (NRF_GRTC_HAS_SYSCOUNTER_ARRAY == 1) + nrfy_grtc_sys_counter_active_set(NRF_GRTC, true); + while (!nrfy_grtc_sys_conter_ready_check(NRF_GRTC)) { + } +#else + nrfy_grtc_sys_counter_active_state_request_set(NRF_GRTC, true); + k_busy_wait(GRTC_SYSCOUNTERVALID_SETTLE_MAX_TIME_US); +#endif +} + +static inline void grtc_wakeup(void) +{ + if (IS_ENABLED(CONFIG_NRF_GRTC_SLEEP_ALLOWED)) { + grtc_active_set(); + } +} + +static inline void grtc_sleep(void) +{ + if (IS_ENABLED(CONFIG_NRF_GRTC_SLEEP_ALLOWED)) { +#if defined(NRF_GRTC_HAS_SYSCOUNTER_ARRAY) && (NRF_GRTC_HAS_SYSCOUNTER_ARRAY == 1) + nrfy_grtc_sys_counter_active_set(NRF_GRTC, false); +#else + nrfy_grtc_sys_counter_active_state_request_set(NRF_GRTC, false); +#endif + } +} + +static inline uint64_t counter_sub(uint64_t a, uint64_t b) +{ + return (a - b); +} + +static inline uint64_t counter(void) +{ + uint64_t now; + + grtc_wakeup(); + nrfx_grtc_syscounter_get(&now); + grtc_sleep(); + return now; +} + +static inline uint64_t get_comparator(uint32_t chan) +{ + uint64_t cc; + nrfx_err_t result; + + result = nrfx_grtc_syscounter_cc_value_read(chan, &cc); + if (result != NRFX_SUCCESS) { + if (result != NRFX_ERROR_INVALID_PARAM) { + return -EAGAIN; + } + return -EPERM; + } + return cc; +} + +static void system_timeout_set(uint64_t value) +{ + if (value <= NRF_GRTC_SYSCOUNTER_CCADD_MASK) { + grtc_wakeup(); + nrfx_grtc_syscounter_cc_relative_set(&system_clock_channel_data, value, true, + NRFX_GRTC_CC_RELATIVE_SYSCOUNTER); + grtc_sleep(); + } else { + nrfx_grtc_syscounter_cc_absolute_set(&system_clock_channel_data, value + counter(), + true); + } +} + +static bool compare_int_lock(int32_t chan) +{ + atomic_val_t prev = atomic_and(&int_mask, ~BIT(chan)); + + nrfx_grtc_syscounter_cc_int_disable(chan); + + return prev & BIT(chan); +} + +static void compare_int_unlock(int32_t chan, bool key) +{ + if (key) { + atomic_or(&int_mask, BIT(chan)); + nrfx_grtc_syscounter_cc_int_enable(chan); + } +} + +static void sys_clock_timeout_handler(int32_t id, uint64_t cc_val, void *p_context) +{ + ARG_UNUSED(id); + ARG_UNUSED(p_context); + uint64_t dticks; + uint64_t now = counter(); + + if (unlikely(now < cc_val)) { + return; + } + if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) { + /* protection is not needed because we are in the GRTC interrupt + * so it won't get preempted by the interrupt. + */ + system_timeout_set(CYC_PER_TICK); + } + + dticks = counter_sub(now, last_count) / CYC_PER_TICK; + + last_count += dticks * CYC_PER_TICK; + sys_clock_announce(IS_ENABLED(CONFIG_TICKLESS_KERNEL) ? (int32_t)dticks : (dticks > 0)); +} + +int32_t z_nrf_grtc_timer_chan_alloc(void) +{ + uint8_t chan; + nrfx_err_t err_code; + + /* Prevent allocating all available channels - one must be left for system purposes. */ + if (ext_channels_allocated >= EXT_CHAN_COUNT) { + return -ENOMEM; + } + err_code = nrfx_grtc_channel_alloc(&chan); + if (err_code != NRFX_SUCCESS) { + return -ENOMEM; + } + ext_channels_allocated++; + return (int32_t)chan; +} + +void z_nrf_grtc_timer_chan_free(int32_t chan) +{ + IS_CHANNEL_ALLOWED_ASSERT(chan); + nrfx_err_t err_code = nrfx_grtc_channel_free(chan); + + if (err_code == NRFX_SUCCESS) { + ext_channels_allocated--; + } +} + +bool z_nrf_grtc_timer_compare_evt_check(int32_t chan) +{ + IS_CHANNEL_ALLOWED_ASSERT(chan); + + uint32_t event_address = nrfx_grtc_event_compare_address_get(chan); + + return *(volatile uint32_t *)event_address != 0; +} + +uint32_t z_nrf_grtc_timer_compare_evt_address_get(int32_t chan) +{ + IS_CHANNEL_ALLOWED_ASSERT(chan); + + return nrfx_grtc_event_compare_address_get(chan); +} + +uint32_t z_nrf_grtc_timer_capture_task_address_get(int32_t chan) +{ + IS_CHANNEL_ALLOWED_ASSERT(chan); + + return nrfx_grtc_capture_task_address_get(chan); +} + +uint64_t z_nrf_grtc_timer_read(void) +{ + return counter(); +} + +bool z_nrf_grtc_timer_compare_int_lock(int32_t chan) +{ + IS_CHANNEL_ALLOWED_ASSERT(chan); + + return compare_int_lock(chan); +} + +void z_nrf_grtc_timer_compare_int_unlock(int32_t chan, bool key) +{ + IS_CHANNEL_ALLOWED_ASSERT(chan); + + compare_int_unlock(chan, key); +} + +uint64_t z_nrf_grtc_timer_compare_read(int32_t chan) +{ + IS_CHANNEL_ALLOWED_ASSERT(chan); + + return get_comparator(chan); +} + +static int compare_set_nolocks(int32_t chan, uint64_t target_time, + z_nrf_grtc_timer_compare_handler_t handler, void *user_data) +{ + nrfx_err_t result; + + __ASSERT_NO_MSG(target_time < COUNTER_SPAN); + nrfx_grtc_channel_t user_channel_data = { + .handler = handler, + .p_context = user_data, + .channel = chan, + }; + result = nrfx_grtc_syscounter_cc_absolute_set(&user_channel_data, target_time, true); + if (result != NRFX_SUCCESS) { + return -EPERM; + } + return 0; +} + +static int compare_set(int32_t chan, uint64_t target_time, + z_nrf_grtc_timer_compare_handler_t handler, void *user_data) +{ + bool key = compare_int_lock(chan); + int ret = compare_set_nolocks(chan, target_time, handler, user_data); + + compare_int_unlock(chan, key); + + return ret; +} + +int z_nrf_grtc_timer_set(int32_t chan, uint64_t target_time, + z_nrf_grtc_timer_compare_handler_t handler, void *user_data) +{ + IS_CHANNEL_ALLOWED_ASSERT(chan); + + return compare_set(chan, target_time, (nrfx_grtc_cc_handler_t)handler, user_data); +} + +void z_nrf_grtc_timer_abort(int32_t chan) +{ + IS_CHANNEL_ALLOWED_ASSERT(chan); + + bool key = compare_int_lock(chan); + (void)nrfx_grtc_syscounter_cc_disable(chan); + compare_int_unlock(chan, key); +} + +uint64_t z_nrf_grtc_timer_get_ticks(k_timeout_t t) +{ + uint64_t curr_time; + int64_t curr_tick; + int64_t result; + int64_t abs_ticks; + + curr_time = counter(); + curr_tick = sys_clock_tick_get(); + + abs_ticks = Z_TICK_ABS(t.ticks); + if (abs_ticks < 0) { + /* relative timeout */ + return (t.ticks > (int64_t)COUNTER_SPAN) ? -EINVAL : (curr_time + t.ticks); + } + + /* absolute timeout */ + result = abs_ticks - curr_tick; + + if (result > (int64_t)COUNTER_SPAN) { + return -EINVAL; + } + + return curr_time + result; +} + +int z_nrf_grtc_timer_capture_prepare(int32_t chan) +{ + nrfx_grtc_channel_t user_channel_data = { + .handler = NULL, + .p_context = NULL, + .channel = chan, + }; + nrfx_err_t result; + + IS_CHANNEL_ALLOWED_ASSERT(chan); + + /* Set the CC value to mark channel as not triggered and also to enable it + * (makes CCEN=1). COUNTER_SPAN is used so as not to fire an event unnecessarily + * - it can be assumed that such a large value will never be reached. + */ + result = nrfx_grtc_syscounter_cc_absolute_set(&user_channel_data, COUNTER_SPAN, false); + + if (result != NRFX_SUCCESS) { + return -EPERM; + } + + return 0; +} + +int z_nrf_grtc_timer_capture_read(int32_t chan, uint64_t *captured_time) +{ + /* TODO: The implementation should probably go to nrfx_grtc and this + * should be just a wrapper for some nrfx_grtc_syscounter_capture_read. + */ + + uint64_t capt_time; + + IS_CHANNEL_ALLOWED_ASSERT(chan); + + /* TODO: Use `nrfy_grtc_sys_counter_enable_check` when available (NRFX-2480) */ + if (NRF_GRTC->CC[chan].CCEN == GRTC_CC_CCEN_ACTIVE_Enable) { + /* If the channel is enabled (.CCEN), it means that there was no capture + * triggering event. + */ + return -EBUSY; + } + + capt_time = nrfy_grtc_sys_counter_cc_get(NRF_GRTC, chan); + + __ASSERT_NO_MSG(capt_time < COUNTER_SPAN); + + *captured_time = capt_time; + + return 0; +} + +#if defined(CONFIG_NRF_GRTC_SLEEP_ALLOWED) +int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us) +{ + nrfx_err_t err_code; + static uint8_t systemoff_channel; + uint64_t now = counter(); + /* Minimum time that ensures valid execution of system-off procedure. */ + uint32_t minimum_latency_us = nrfy_grtc_waketime_get(NRF_GRTC) + + nrfy_grtc_timeout_get(NRF_GRTC) + + CONFIG_NRF_GRTC_SLEEP_MINIMUM_LATENCY; + uint32_t chan; + int ret; + + if (minimum_latency_us > wake_time_us) { + return -EINVAL; + } + k_spinlock_key_t key = k_spin_lock(&lock); + + err_code = nrfx_grtc_channel_alloc(&systemoff_channel); + if (err_code != NRFX_SUCCESS) { + k_spin_unlock(&lock, key); + return -ENOMEM; + } + (void)nrfx_grtc_syscounter_cc_int_disable(systemoff_channel); + ret = compare_set(systemoff_channel, now + wake_time_us, NULL, NULL); + if (ret < 0) { + k_spin_unlock(&lock, key); + return ret; + } + + for (uint32_t grtc_chan_mask = NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK; + grtc_chan_mask > 0; grtc_chan_mask &= ~BIT(chan)) { + /* Clear all GRTC channels except the systemoff_channel. */ + chan = u32_count_trailing_zeros(grtc_chan_mask); + if (chan != systemoff_channel) { + nrfx_grtc_syscounter_cc_disable(chan); + } + } + + /* Make sure that wake_time_us was not triggered yet. */ + if (nrfy_grtc_sys_counter_compare_event_check(NRF_GRTC, systemoff_channel)) { + k_spin_unlock(&lock, key); + return -EINVAL; + } + + /* This mechanism ensures that stored CC value is latched. */ + uint32_t wait_time = + nrfy_grtc_timeout_get(NRF_GRTC) * CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / 32768 + + MAX_CC_LATCH_WAIT_TIME_US; + k_busy_wait(wait_time); +#if NRF_GRTC_HAS_CLKSEL + nrfy_grtc_clksel_set(NRF_GRTC, NRF_GRTC_CLKSEL_LFXO); +#endif + k_spin_unlock(&lock, key); + return 0; +} +#endif /* CONFIG_NRF_GRTC_SLEEP_ALLOWED */ + +uint32_t sys_clock_cycle_get_32(void) +{ + k_spinlock_key_t key = k_spin_lock(&lock); + uint32_t ret = (uint32_t)counter(); + + k_spin_unlock(&lock, key); + return ret; +} + +uint64_t sys_clock_cycle_get_64(void) +{ + k_spinlock_key_t key = k_spin_lock(&lock); + uint64_t ret = counter(); + + k_spin_unlock(&lock, key); + return ret; +} + +uint32_t sys_clock_elapsed(void) +{ + if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) { + return 0; + } + + return (uint32_t)(counter_sub(counter(), last_count) / CYC_PER_TICK); +} + +static int sys_clock_driver_init(void) +{ + nrfx_err_t err_code; + +#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && \ + (defined(NRF_GRTC_HAS_CLKSEL) && (NRF_GRTC_HAS_CLKSEL == 1)) + /* Use System LFCLK as the low-frequency clock source. */ + nrfy_grtc_clksel_set(NRF_GRTC, NRF_GRTC_CLKSEL_LFCLK); +#endif + +#if defined(CONFIG_NRF_GRTC_START_SYSCOUNTER) + /* SYSCOUNTER needs to be turned off before initialization. */ + nrfy_grtc_sys_counter_set(NRF_GRTC, false); + nrfy_grtc_timeout_set(NRF_GRTC, TIMEOUT); + nrfy_grtc_waketime_set(NRF_GRTC, WAKETIME); +#endif /* CONFIG_NRF_GRTC_START_SYSCOUNTER */ + + IRQ_CONNECT(DT_IRQN(GRTC_NODE), DT_IRQ(GRTC_NODE, priority), nrfx_grtc_irq_handler, 0, 0); + + err_code = nrfx_grtc_init(0); + if (err_code != NRFX_SUCCESS) { + return -EPERM; + } + +#if defined(CONFIG_NRF_GRTC_START_SYSCOUNTER) + err_code = nrfx_grtc_syscounter_start(true, &system_clock_channel_data.channel); + if (err_code != NRFX_SUCCESS) { + return err_code == NRFX_ERROR_NO_MEM ? -ENOMEM : -EPERM; + } + if (IS_ENABLED(CONFIG_NRF_GRTC_SLEEP_ALLOWED)) { + nrfy_grtc_sys_counter_auto_mode_set(NRF_GRTC, false); + } +#else + err_code = nrfx_grtc_channel_alloc(&system_clock_channel_data.channel); + if (err_code != NRFX_SUCCESS) { + return -ENOMEM; + } +#endif /* CONFIG_NRF_GRTC_START_SYSCOUNTER */ + + if (!IS_ENABLED(CONFIG_NRF_GRTC_SLEEP_ALLOWED)) { + grtc_active_set(); + } + + int_mask = NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK; + if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) { + system_timeout_set(CYC_PER_TICK); + } + + static const enum nrf_lfclk_start_mode mode = + IS_ENABLED(CONFIG_SYSTEM_CLOCK_NO_WAIT) + ? CLOCK_CONTROL_NRF_LF_START_NOWAIT + : (IS_ENABLED(CONFIG_SYSTEM_CLOCK_WAIT_FOR_AVAILABILITY) + ? CLOCK_CONTROL_NRF_LF_START_AVAILABLE + : CLOCK_CONTROL_NRF_LF_START_STABLE); + + z_nrf_clock_control_lf_on(mode); + + return 0; +} + +void sys_clock_set_timeout(int32_t ticks, bool idle) +{ + ARG_UNUSED(idle); + uint64_t cyc, off, now; + + if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) { + return; + } + + ticks = (ticks == K_TICKS_FOREVER) ? MAX_TICKS : MIN(MAX_TICKS, MAX(ticks - 1, 0)); + + now = counter(); + + /* Round up to the next tick boundary */ + off = (now - last_count) + (CYC_PER_TICK - 1); + off = (off / CYC_PER_TICK) * CYC_PER_TICK; + + /* Get the offset with respect to now */ + off -= (now - last_count); + + /* Add the offset to get to the next tick boundary */ + cyc = (uint64_t)ticks * CYC_PER_TICK + off; + + /* Due to elapsed time the calculation above might produce a + * duration that laps the counter. Don't let it. + */ + if (cyc > MAX_CYCLES) { + cyc = MAX_CYCLES; + } + + system_timeout_set(cyc == 0 ? 1 : cyc); +} + +#if defined(CONFIG_NRF_GRTC_TIMER_APP_DEFINED_INIT) +int nrf_grtc_timer_clock_driver_init(void) +{ + return sys_clock_driver_init(); +} +#else +SYS_INIT(sys_clock_driver_init, PRE_KERNEL_2, CONFIG_SYSTEM_CLOCK_INIT_PRIORITY); +#endif diff --git a/include/zephyr/drivers/timer/nrf_grtc_timer.h b/include/zephyr/drivers/timer/nrf_grtc_timer.h new file mode 100644 index 00000000000..172a904fdef --- /dev/null +++ b/include/zephyr/drivers/timer/nrf_grtc_timer.h @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_TIMER_NRF_GRTC_TIMER_H +#define ZEPHYR_INCLUDE_DRIVERS_TIMER_NRF_GRTC_TIMER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** @brief GRTC timer compare event handler. + * + * Called from GRTC ISR context when processing a compare event. + * + * @param id Compare channel ID. + * + * @param expire_time An actual absolute expiration time set for a compare + * channel. It can differ from the requested target time + * and the difference can be used to determine whether the + * time set was delayed. + * + * @param user_data Pointer to a user context data. + */ +typedef void (*z_nrf_grtc_timer_compare_handler_t)(int32_t id, uint64_t expire_time, + void *user_data); + +/** @brief Allocate GRTC capture/compare channel. + * + * @retval >=0 Non-negative indicates allocated channel ID. + * @retval -ENOMEM if channel cannot be allocated. + */ +int32_t z_nrf_grtc_timer_chan_alloc(void); + +/** @brief Free GRTC capture/compare channel. + * + * @param chan Previously allocated channel ID. + */ +void z_nrf_grtc_timer_chan_free(int32_t chan); + +/** @brief Read current absolute time. + * + * @return Current absolute time. + */ +uint64_t z_nrf_grtc_timer_read(void); + +/** @brief Check COMPARE event state. + * + * @param chan Channel ID. + * + * @retval true The event has been generated. + * @retval false The event has not been generated. + */ +bool z_nrf_grtc_timer_compare_evt_check(int32_t chan); + +/** @brief Get COMPARE event register address. + * + * Address can be used for DPPIC. + * + * @param chan Channel ID. + * + * @return Register address. + */ +uint32_t z_nrf_grtc_timer_compare_evt_address_get(int32_t chan); + +/** @brief Get CAPTURE task register address. + * + * Address can be used for DPPIC. + * + * @param chan Channel ID. + * + * @return Register address. + */ +uint32_t z_nrf_grtc_timer_capture_task_address_get(int32_t chan); + +/** @brief Safely disable compare event interrupt. + * + * Function returns key indicating whether interrupt was already disabled. + * + * @param chan Channel ID. + * + * @return key passed to z_nrf_grtc_timer_compare_int_unlock(). + */ +bool z_nrf_grtc_timer_compare_int_lock(int32_t chan); + +/** @brief Safely enable compare event interrupt. + * + * Event interrupt is conditionally enabled based on @p key. + * + * @param chan Channel ID. + * + * @param key Key returned by z_nrf_grtc_timer_compare_int_lock(). + */ +void z_nrf_grtc_timer_compare_int_unlock(int32_t chan, bool key); + +/** @brief Read compare register value. + * + * @param chan Channel ID. + * + * @retval >=0 Positive is a Value set in the compare register + * @retval -EAGAIN if compare for given channel is not set. + * @retval -EPERM if either channel is unavailable or SYSCOUNTER is not running. + */ +uint64_t z_nrf_grtc_timer_compare_read(int32_t chan); + +/** @brief Set compare channel to given value. + * + * @param chan Channel ID. + * + * @param target_time Absolute target time in ticks. + * + * @param handler User function called in the context of the GRTC interrupt. + * + * @param user_data Data passed to the handler. + * + * @retval 0 if the compare channel was set successfully. + * @retval -EPERM if either channel is unavailable or SYSCOUNTER is not running. + */ +int z_nrf_grtc_timer_set(int32_t chan, uint64_t target_time, + z_nrf_grtc_timer_compare_handler_t handler, void *user_data); + +/** @brief Abort a timer requested with z_nrf_grtc_timer_set(). + * + * If an abort operation is performed too late it is still possible for an event + * to fire. The user can detect a spurious event by comparing absolute time + * provided in callback and a result of z_nrf_grtc_timer_read(). During this + * operation interrupt from that compare channel is disabled. Other interrupts + * are not locked during this operation. + * + * @param chan Channel ID between 1 and CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT. + */ +void z_nrf_grtc_timer_abort(int32_t chan); + +/** @brief Convert system clock time to GRTC ticks. + * + * @p t can be absolute or relative. + * + * @retval >=0 Positive value represents @p t in GRTC tick value. + * @retval -EINVAL if @p t is out of range. + */ +uint64_t z_nrf_grtc_timer_get_ticks(k_timeout_t t); + +/** @brief Prepare channel for timestamp capture. + * + * Use z_nrf_grtc_timer_capture_task_address_get() to determine the register + * address that is used to trigger capture. + * + * @note Capture and compare are mutually exclusive features - they cannot be + * used simultaneously on the same GRTC channel. + * + * @param chan Channel ID. + * + * @retval 0 if the channel was successfully prepared. + * @retval -EPERM if either channel is unavailable or SYSCOUNTER is not running. + */ +int z_nrf_grtc_timer_capture_prepare(int32_t chan); + +/** @brief Read timestamp value captured on the channel. + * + * The @p chan must be prepared using z_nrf_grtc_timer_capture_prepare(). + * + * @param chan Channel ID. + * + * @param captured_time Pointer to store the value. + * + * @retval 0 if the timestamp was successfully caught and read. + * @retval -EBUSY if capturing has not been triggered. + */ +int z_nrf_grtc_timer_capture_read(int32_t chan, uint64_t *captured_time); + +/** @brief Prepare GRTC as a source of wake up event and set the wake up time. + * + * @note Calling this function should be immediately followed by low-power mode enter + * (if it executed successfully). + * + * @param wake_time_us Relative wake up time in microseconds. + * + * @retval 0 if wake up time was successfully set. + * @retval -EPERM if the SYSCOUNTER is not running. + * @retval -ENOMEM if no available GRTC channels were found. + * @retval -EINVAL if @p wake_time_us is too low. + */ +int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us); + +/** + * @brief Initialize the GRTC clock timer driver from an application- + * defined function. + * + * @retval 0 on success. + * @retval -errno Negative error code on failure. + */ +int nrf_grtc_timer_clock_driver_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_DRIVERS_TIMER_NRF_GRTC_TIMER_H */ From 8b607138a7bf004e2ce76e4bdf178bf42e34248e Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Tue, 23 Jan 2024 14:55:47 +0100 Subject: [PATCH 1163/1623] [nrf fromtree] modules: hal_nordic: nrfx: add nRF54L15 peripherals instances Add new TIMER and UARTE instances for nRF54L15. Signed-off-by: Magdalena Pastula (cherry picked from commit 7322abe588bfaef767ade47edd9132d8545249ca) --- modules/hal_nordic/nrfx/Kconfig | 60 +++++++++++++++++++++++++++ modules/hal_nordic/nrfx/nrfx_config.h | 36 ++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index bdca4016ee3..d4efbb7cac8 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -422,6 +422,41 @@ config NRFX_TIMER4 depends on $(dt_nodelabel_has_compat,timer4,$(DT_COMPAT_NORDIC_NRF_TIMER)) select NRFX_TIMER +config NRFX_TIMER00 + bool "TIMER00 driver instance" + depends on $(dt_nodelabel_has_compat,timer00,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER10 + bool "TIMER10 driver instance" + depends on $(dt_nodelabel_has_compat,timer10,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER20 + bool "TIMER20 driver instance" + depends on $(dt_nodelabel_has_compat,timer20,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER21 + bool "TIMER21 driver instance" + depends on $(dt_nodelabel_has_compat,timer21,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER22 + bool "TIMER22 driver instance" + depends on $(dt_nodelabel_has_compat,timer22,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER23 + bool "TIMER23 driver instance" + depends on $(dt_nodelabel_has_compat,timer23,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER24 + bool "TIMER24 driver instance" + depends on $(dt_nodelabel_has_compat,timer24,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + config NRFX_TWI bool @@ -577,6 +612,31 @@ config NRFX_UARTE3 depends on $(dt_nodelabel_has_compat,uart3,$(DT_COMPAT_NORDIC_NRF_UARTE)) select NRFX_UARTE +config NRFX_UARTE00 + bool "UARTE00 driver instance" + depends on $(dt_nodelabel_has_compat,uart00,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE20 + bool "UARTE20 driver instance" + depends on $(dt_nodelabel_has_compat,uart20,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE21 + bool "UARTE21 driver instance" + depends on $(dt_nodelabel_has_compat,uart21,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE22 + bool "UARTE22 driver instance" + depends on $(dt_nodelabel_has_compat,uart22,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE30 + bool "UARTE30 driver instance" + depends on $(dt_nodelabel_has_compat,uart30,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + config NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG bool "UARTE GPIO configuration support" depends on NRFX_UARTE diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 451101c8f4b..5d5746e2c88 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -451,6 +451,27 @@ #ifdef CONFIG_NRFX_TIMER4 #define NRFX_TIMER4_ENABLED 1 #endif +#ifdef CONFIG_NRFX_TIMER00 +#define NRFX_TIMER00_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER10 +#define NRFX_TIMER10_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER20 +#define NRFX_TIMER20_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER21 +#define NRFX_TIMER21_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER22 +#define NRFX_TIMER22_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER23 +#define NRFX_TIMER23_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER24 +#define NRFX_TIMER24_ENABLED 1 +#endif #ifdef CONFIG_NRFX_TWI #define NRFX_TWI_ENABLED 1 @@ -570,6 +591,21 @@ #ifdef CONFIG_NRFX_UARTE3 #define NRFX_UARTE3_ENABLED 1 #endif +#ifdef CONFIG_NRFX_UARTE00 +#define NRFX_UARTE00_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE20 +#define NRFX_UARTE20_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE21 +#define NRFX_UARTE21_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE22 +#define NRFX_UARTE22_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE30 +#define NRFX_UARTE30_ENABLED 1 +#endif #ifdef CONFIG_NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG #define NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG 1 #endif From 947da7646f829893ed807cfe1059402e46115dba Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Tue, 23 Jan 2024 14:57:47 +0100 Subject: [PATCH 1164/1623] [nrf fromtree] soc: arm: nordic_nrf: add nRF54L15 peripherals instances Add support for nRF54L15 instances of UARTE, TIMER and WTD. Signed-off-by: Magdalena Pastula (cherry picked from commit a6bd4dbc33ea2362d1fed1bc16c99e877ab48813) --- soc/arm/nordic_nrf/Kconfig.peripherals | 36 ++++++++++++++++++++ soc/arm/nordic_nrf/validate_base_addresses.c | 14 ++++++++ 2 files changed, 50 insertions(+) diff --git a/soc/arm/nordic_nrf/Kconfig.peripherals b/soc/arm/nordic_nrf/Kconfig.peripherals index c9af5604510..0dc47fe516c 100644 --- a/soc/arm/nordic_nrf/Kconfig.peripherals +++ b/soc/arm/nordic_nrf/Kconfig.peripherals @@ -320,6 +320,27 @@ config HAS_HW_NRF_TIMER3 config HAS_HW_NRF_TIMER4 def_bool $(dt_nodelabel_enabled_with_compat,timer4,$(DT_COMPAT_NORDIC_NRF_TIMER)) +config HAS_HW_NRF_TIMER00 + def_bool $(dt_nodelabel_enabled_with_compat,timer00,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER10 + def_bool $(dt_nodelabel_enabled_with_compat,timer10,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER20 + def_bool $(dt_nodelabel_enabled_with_compat,timer20,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER21 + def_bool $(dt_nodelabel_enabled_with_compat,timer21,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER22 + def_bool $(dt_nodelabel_enabled_with_compat,timer22,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER23 + def_bool $(dt_nodelabel_enabled_with_compat,timer23,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER24 + def_bool $(dt_nodelabel_enabled_with_compat,timer24,$(DT_COMPAT_NORDIC_NRF_TIMER)) + config HAS_HW_NRF_TWI0 def_bool $(dt_nodelabel_enabled_with_compat,i2c0,$(DT_COMPAT_NORDIC_NRF_TWI)) @@ -404,6 +425,21 @@ config HAS_HW_NRF_UARTE2 config HAS_HW_NRF_UARTE3 def_bool $(dt_nodelabel_enabled_with_compat,uart3,$(DT_COMPAT_NORDIC_NRF_UARTE)) +config HAS_HW_NRF_UARTE00 + def_bool $(dt_nodelabel_enabled_with_compat,uart00,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE20 + def_bool $(dt_nodelabel_enabled_with_compat,uart20,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE21 + def_bool $(dt_nodelabel_enabled_with_compat,uart21,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE22 + def_bool $(dt_nodelabel_enabled_with_compat,uart22,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE30 + def_bool $(dt_nodelabel_enabled_with_compat,uart30,$(DT_COMPAT_NORDIC_NRF_UARTE)) + config HAS_HW_NRF_USBD def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_USBD)) diff --git a/soc/arm/nordic_nrf/validate_base_addresses.c b/soc/arm/nordic_nrf/validate_base_addresses.c index ee440c3252c..9daa820efa9 100644 --- a/soc/arm/nordic_nrf/validate_base_addresses.c +++ b/soc/arm/nordic_nrf/validate_base_addresses.c @@ -198,10 +198,22 @@ CHECK_DT_REG(timer1, NRF_TIMER1); CHECK_DT_REG(timer2, NRF_TIMER2); CHECK_DT_REG(timer3, NRF_TIMER3); CHECK_DT_REG(timer4, NRF_TIMER4); +CHECK_DT_REG(timer00, NRF_TIMER00); +CHECK_DT_REG(timer10, NRF_TIMER10); +CHECK_DT_REG(timer20, NRF_TIMER20); +CHECK_DT_REG(timer21, NRF_TIMER21); +CHECK_DT_REG(timer22, NRF_TIMER22); +CHECK_DT_REG(timer23, NRF_TIMER23); +CHECK_DT_REG(timer24, NRF_TIMER24); CHECK_UART_REG(uart0, 0); CHECK_DT_REG(uart1, NRF_UARTE1); CHECK_DT_REG(uart2, NRF_UARTE2); CHECK_DT_REG(uart3, NRF_UARTE3); +CHECK_DT_REG(uart00, NRF_UARTE00); +CHECK_DT_REG(uart20, NRF_UARTE20); +CHECK_DT_REG(uart21, NRF_UARTE21); +CHECK_DT_REG(uart22, NRF_UARTE22); +CHECK_DT_REG(uart30, NRF_UARTE30); CHECK_DT_REG(uicr, NRF_UICR); CHECK_DT_REG(usbd, NRF_USBD); CHECK_DT_REG(usbreg, NRF_USBREGULATOR); @@ -209,6 +221,8 @@ CHECK_DT_REG(vmc, NRF_VMC); CHECK_DT_REG(wdt, NRF_WDT0); /* this should be the same node as wdt0 */ CHECK_DT_REG(wdt0, NRF_WDT0); CHECK_DT_REG(wdt1, NRF_WDT1); +CHECK_DT_REG(wdt30, NRF_WDT30); +CHECK_DT_REG(wdt31, NRF_WDT31); /* nRF51/nRF52-specific addresses */ #if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) From 7b60671260e30d930e5d62db1dc72318efbbe7d1 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Fri, 19 Jan 2024 13:21:53 +0100 Subject: [PATCH 1165/1623] [nrf fromtree] dts: bindings: clock: add nordic,nrf-lfxo To describe the low frequency crystal oscillator present in some nRF series. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit e65d4141e618ebe651b7e6bfa5f58473bde21e9d) --- dts/bindings/clock/nordic,nrf-lfxo.yaml | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 dts/bindings/clock/nordic,nrf-lfxo.yaml diff --git a/dts/bindings/clock/nordic,nrf-lfxo.yaml b/dts/bindings/clock/nordic,nrf-lfxo.yaml new file mode 100644 index 00000000000..f0090ff4a81 --- /dev/null +++ b/dts/bindings/clock/nordic,nrf-lfxo.yaml @@ -0,0 +1,58 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: Nordic nRF low-frequency crystal oscillator + +compatible: "nordic,nrf-lfxo" + +include: [fixed-clock.yaml] + +properties: + clock-frequency: + const: 32768 + + load-capacitors: + type: string + enum: + - "internal" + - "external" + description: | + Type of load capacitors connected to the crystal. If not specified, + adjustments may still happen when the device trimming happens during + system initialization. + + load-capacitance-femtofarad: + type: int + enum: + - 4000 + - 4500 + - 5000 + - 5500 + - 6000 + - 6500 + - 7000 + - 7500 + - 8000 + - 8500 + - 9000 + - 9500 + - 10000 + - 10500 + - 11000 + - 11500 + - 12000 + - 12500 + - 13000 + - 13500 + - 14000 + - 14500 + - 15000 + - 15500 + - 16000 + - 16500 + - 17000 + - 17500 + - 18000 + description: | + Load capacitance in femtofarads. This property is only used when + load-capacitors is set to "internal". From c21106567025850d8f5ade4bb9fb2bf724b9821e Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Fri, 19 Jan 2024 13:39:19 +0100 Subject: [PATCH 1166/1623] [nrf fromtree] dts: bindings: clock: add nordic,nrf-hfxo: Add bindings for the nRF HFXO present in some nRF SoCs. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 32c7cd551a2e8c95143818ab12a3d593482b7300) --- dts/bindings/clock/nordic,nrf-hfxo.yaml | 82 +++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 dts/bindings/clock/nordic,nrf-hfxo.yaml diff --git a/dts/bindings/clock/nordic,nrf-hfxo.yaml b/dts/bindings/clock/nordic,nrf-hfxo.yaml new file mode 100644 index 00000000000..dc99c67e5cc --- /dev/null +++ b/dts/bindings/clock/nordic,nrf-hfxo.yaml @@ -0,0 +1,82 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: Nordic nRF high-frequency crystal oscillator + +compatible: "nordic,nrf-hfxo" + +include: [fixed-clock.yaml] + +properties: + clock-frequency: + const: 32000000 + + load-capacitors: + type: string + enum: + - "internal" + - "external" + description: | + Type of load capacitors connected to the crystal. If not specified, + adjustments may still happen when the device trimming happens during + system initialization. + + load-capacitance-femtofarad: + type: int + enum: + - 4000 + - 4250 + - 4500 + - 4750 + - 5000 + - 5250 + - 5500 + - 5750 + - 6000 + - 6250 + - 6500 + - 6750 + - 7000 + - 7250 + - 7500 + - 7750 + - 8000 + - 8250 + - 8500 + - 8750 + - 9000 + - 9250 + - 9500 + - 9750 + - 10000 + - 10250 + - 10500 + - 10750 + - 11000 + - 11250 + - 11500 + - 11750 + - 12000 + - 12250 + - 12500 + - 12750 + - 13000 + - 13250 + - 13500 + - 13750 + - 14000 + - 14250 + - 14500 + - 14750 + - 15000 + - 15250 + - 15500 + - 15750 + - 16000 + - 16250 + - 16500 + - 16750 + - 17000 + description: | + Load capacitance in femtofarads. This property is only used when + load-capacitors is set to "internal". From dec064215a5174fe38f912d7feab862c4af144e2 Mon Sep 17 00:00:00 2001 From: Witold Lukasik Date: Mon, 11 Dec 2023 17:26:19 +0100 Subject: [PATCH 1167/1623] [nrf fromtree] dts: arm: nordic: add support for Nordic nRF54L15 Add dts files for nRF54L15 chip. Signed-off-by: Witold Lukasik (cherry picked from commit 0b2ed9888afc6329f015d4a6e6ddc6521297d509) --- dts/arm/nordic/nrf54l15_cpuapp.dtsi | 90 ++++ .../nordic/nrf54l15_cpuapp_peripherals.dtsi | 412 ++++++++++++++++++ dts/arm/nordic/nrf54l_common.dtsi | 33 ++ 3 files changed, 535 insertions(+) create mode 100644 dts/arm/nordic/nrf54l15_cpuapp.dtsi create mode 100644 dts/arm/nordic/nrf54l15_cpuapp_peripherals.dtsi create mode 100644 dts/arm/nordic/nrf54l_common.dtsi diff --git a/dts/arm/nordic/nrf54l15_cpuapp.dtsi b/dts/arm/nordic/nrf54l15_cpuapp.dtsi new file mode 100644 index 00000000000..7e90c8b1213 --- /dev/null +++ b/dts/arm/nordic/nrf54l15_cpuapp.dtsi @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +/ { + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu: cpu@0 { + clock-frequency = ; + device_type = "cpu"; + compatible = "arm,cortex-m33f"; + reg = <0>; + #address-cells = <1>; + #size-cells = <1>; + itm: itm@e0000000 { + compatible = "arm,armv8m-itm"; + reg = <0xe0000000 0x1000>; + swo-ref-frequency = ; + }; + }; + }; + + clocks { + lfxo: lfxo { + compatible = "nordic,nrf-lfxo"; + #clock-cells = <0>; + clock-frequency = <32768>; + }; + + hfxo: hfxo { + compatible = "nordic,nrf-hfxo"; + #clock-cells = <0>; + clock-frequency = ; + }; + }; + + soc { + uicr: uicr@ffd000 { + compatible = "nordic,nrf-uicr"; + reg = <0xffd000 0x1000>; + }; + + ficr: ficr@ffc000 { + compatible = "nordic,nrf-ficr"; + reg = <0xffc000 0x1000>; + }; + + sram0: memory@20000000 { + compatible = "mmio-sram"; + reg = <0x20000000 DT_SIZE_K(256)>; + }; + + peripheral@50000000 { + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x50000000 0x10000000>; + + /* Common nRF54L15 peripheral description */ + #include "nrf54l15_cpuapp_peripherals.dtsi" + }; + }; +}; + +&nvic { + arm,num-irq-priority-bits = <3>; +}; + +&rram_controller { + rram0: rram@0 { + /* + * "1524 KB non-volatile memory (RRAM) and 256 KB RAM" + * -- Product Specification + * NB: 1524 = 1.5 * 1024 - 12 + */ + reg = <0x0 DT_SIZE_K(1524)>; + }; +}; + +/* Disable by default to use GRTC */ +&systick { + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf54l15_cpuapp_peripherals.dtsi b/dts/arm/nordic/nrf54l15_cpuapp_peripherals.dtsi new file mode 100644 index 00000000000..786c21ab215 --- /dev/null +++ b/dts/arm/nordic/nrf54l15_cpuapp_peripherals.dtsi @@ -0,0 +1,412 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +dppic00: dppic@42000 { + compatible = "nordic,nrf-dppic"; + reg = <0x42000 0x808>; + status = "disabled"; +}; + +spi00: spi@4a000 { + /* + * This spi node can be either SPIM or SPIS, + * for the user to pick: + * compatible = "nordic,nrf-spim" or + * "nordic,nrf-spis". + */ + compatible = "nordic,nrf-spim"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x4a000 0x1000>; + interrupts = <74 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + easydma-maxcnt-bits = <16>; + status = "disabled"; +}; + +uart00: uart@4a000 { + compatible = "nordic,nrf-uarte"; + reg = <0x4a000 0x1000>; + interrupts = <74 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +gpio2: gpio@50400 { + compatible = "nordic,nrf-gpio"; + gpio-controller; + reg = <0x50400 0x300>; + #gpio-cells = <2>; + ngpios = <11>; + status = "disabled"; + port = <2>; +}; + +timer00: timer@55000 { + compatible = "nordic,nrf-timer"; + status = "disabled"; + reg = <0x55000 0x1000>; + cc-num = <6>; + max-bit-width = <32>; + interrupts = <85 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <0>; +}; + +dppic10: dppic@82000 { + compatible = "nordic,nrf-dppic"; + reg = <0x82000 0x808>; + status = "disabled"; +}; + +timer10: timer@85000 { + compatible = "nordic,nrf-timer"; + status = "disabled"; + reg = <0x85000 0x1000>; + cc-num = <8>; + max-bit-width = <32>; + interrupts = <133 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <0>; +}; + +egu10: egu@87000 { + compatible = "nordic,nrf-egu"; + reg = <0x87000 0x1000>; + interrupts = <135 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +radio: radio@8a000 { + compatible = "nordic,nrf-radio"; + reg = <0x8a000 0x1000>; + interrupts = <138 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; + dfe-supported; + ieee802154-supported; + ble-2mbps-supported; + ble-coded-phy-supported; + + ieee802154: ieee802154 { + compatible = "nordic,nrf-ieee802154"; + status = "disabled"; + }; +}; + +dppic20: dppic@c2000 { + compatible = "nordic,nrf-dppic"; + reg = <0xc2000 0x808>; + status = "disabled"; +}; + +i2c20: i2c@c6000 { + compatible = "nordic,nrf-twim"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0xc6000 0x1000>; + clock-frequency = ; + interrupts = <198 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +spi20: spi@c6000 { + /* + * This spi node can be either SPIM or SPIS, + * for the user to pick: + * compatible = "nordic,nrf-spim" or + * "nordic,nrf-spis". + */ + compatible = "nordic,nrf-spim"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0xc6000 0x1000>; + interrupts = <198 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + easydma-maxcnt-bits = <16>; + status = "disabled"; +}; + +uart20: uart@c6000 { + compatible = "nordic,nrf-uarte"; + reg = <0xc6000 0x1000>; + interrupts = <198 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +i2c21: i2c@c7000 { + compatible = "nordic,nrf-twim"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0xc7000 0x1000>; + clock-frequency = ; + interrupts = <199 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +spi21: spi@c7000 { + /* + * This spi node can be either SPIM or SPIS, + * for the user to pick: + * compatible = "nordic,nrf-spim" or + * "nordic,nrf-spis". + */ + compatible = "nordic,nrf-spim"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0xc7000 0x1000>; + interrupts = <199 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + easydma-maxcnt-bits = <16>; + status = "disabled"; +}; + +uart21: uart@c7000 { + compatible = "nordic,nrf-uarte"; + reg = <0xc7000 0x1000>; + interrupts = <199 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +i2c22: i2c@c8000 { + compatible = "nordic,nrf-twim"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0xc8000 0x1000>; + clock-frequency = ; + interrupts = <200 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +spi22: spi@c8000 { + /* + * This spi node can be either SPIM or SPIS, + * for the user to pick: + * compatible = "nordic,nrf-spim" or + * "nordic,nrf-spis". + */ + compatible = "nordic,nrf-spim"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0xc8000 0x1000>; + interrupts = <200 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + easydma-maxcnt-bits = <16>; + status = "disabled"; +}; + +uart22: uart@c8000 { + compatible = "nordic,nrf-uarte"; + reg = <0xc8000 0x1000>; + interrupts = <200 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +egu20: egu@c9000 { + compatible = "nordic,nrf-egu"; + reg = <0xc9000 0x1000>; + interrupts = <201 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +timer20: timer@ca000 { + compatible = "nordic,nrf-timer"; + status = "disabled"; + reg = <0xca000 0x1000>; + cc-num = <6>; + max-bit-width = <32>; + interrupts = <202 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <0>; +}; + +timer21: timer@cb000 { + compatible = "nordic,nrf-timer"; + status = "disabled"; + reg = <0xcb000 0x1000>; + cc-num = <6>; + max-bit-width = <32>; + interrupts = <203 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <0>; +}; + +timer22: timer@cc000 { + compatible = "nordic,nrf-timer"; + status = "disabled"; + reg = <0xcc000 0x1000>; + cc-num = <6>; + max-bit-width = <32>; + interrupts = <204 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <0>; +}; + +timer23: timer@cd000 { + compatible = "nordic,nrf-timer"; + status = "disabled"; + reg = <0xcd000 0x1000>; + cc-num = <6>; + max-bit-width = <32>; + interrupts = <205 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <0>; +}; + +timer24: timer@ce000 { + compatible = "nordic,nrf-timer"; + status = "disabled"; + reg = <0xce000 0x1000>; + cc-num = <6>; + max-bit-width = <32>; + interrupts = <206 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <0>; +}; + +adc: adc@d5000 { + compatible = "nordic,nrf-saadc"; + reg = <0xd5000 0x1000>; + interrupts = <213 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; + #io-channel-cells = <1>; +}; + +nfct: nfct@d6000 { + compatible = "nordic,nrf-nfct"; + reg = <0xd6000 0x1000>; + interrupts = <214 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +temp: temp@d7000 { + compatible = "nordic,nrf-temp"; + reg = <0xd7000 0x1000>; + interrupts = <215 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +gpio1: gpio@d8200 { + compatible = "nordic,nrf-gpio"; + gpio-controller; + reg = <0xd8200 0x300>; + #gpio-cells = <2>; + ngpios = <16>; + status = "disabled"; + port = <1>; + gpiote-instance = <&gpiote20>; +}; + +gpiote20: gpiote@da000 { + compatible = "nordic,nrf-gpiote"; + reg = <0xda000 0x1000>; + interrupts = <219 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; + instance = <20>; +}; + +i2s20: i2s@dd000 { + compatible = "nordic,nrf-i2s"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0xdd000 0x1000>; + interrupts = <221 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +qdec20: qdec@e0000 { + compatible = "nordic,nrf-qdec"; + reg = <0xe0000 0x1000>; + interrupts = <224 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +qdec21: qdec@e1000 { + compatible = "nordic,nrf-qdec"; + reg = <0xe1000 0x1000>; + interrupts = <225 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +grtc: grtc@e2000 { + compatible = "nordic,nrf-grtc"; + reg = <0xe2000 0x1000>; + cc-num = <12>; + owned-channels = <0 1 2 3 4 5 6 7 8 9 10 11>; + interrupts = <228 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +dppic30: dppic@102000 { + compatible = "nordic,nrf-dppic"; + reg = <0x102000 0x808>; + status = "disabled"; +}; + +i2c30: i2c@104000 { + compatible = "nordic,nrf-twim"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x104000 0x1000>; + clock-frequency = ; + interrupts = <260 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +spi30: spi@104000 { + /* + * This spi node can be either SPIM or SPIS, + * for the user to pick: + * compatible = "nordic,nrf-spim" or + * "nordic,nrf-spis". + */ + compatible = "nordic,nrf-spim"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x104000 0x1000>; + interrupts = <260 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + easydma-maxcnt-bits = <16>; + status = "disabled"; +}; + +uart30: uart@104000 { + compatible = "nordic,nrf-uarte"; + reg = <0x104000 0x1000>; + interrupts = <260 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +wdt30: watchdog@108000 { + compatible = "nordic,nrf-wdt"; + reg = <0x108000 0x620>; + interrupts = <264 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +wdt31: watchdog@109000 { + compatible = "nordic,nrf-wdt"; + reg = <0x109000 0x620>; + interrupts = <265 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; + +gpio0: gpio@10a000 { + compatible = "nordic,nrf-gpio"; + gpio-controller; + reg = <0x10a000 0x300>; + #gpio-cells = <2>; + ngpios = <5>; + status = "disabled"; + port = <0>; + gpiote-instance = <&gpiote30>; +}; + +gpiote30: gpiote@10c000 { + compatible = "nordic,nrf-gpiote"; + reg = <0x10c000 0x1000>; + interrupts = <269 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; + instance = <30>; +}; + +clock: clock@10e000 { + compatible = "nordic,nrf-clock"; + reg = <0x10e000 0x1000>; + interrupts = <270 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf54l_common.dtsi b/dts/arm/nordic/nrf54l_common.dtsi new file mode 100644 index 00000000000..4fb7768bd3f --- /dev/null +++ b/dts/arm/nordic/nrf54l_common.dtsi @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "nrf_common.dtsi" + +/ { + soc { + rram_controller: rram-controller@5004b000 { + compatible = "nordic,rram-controller"; + reg = <0x5004b000 0x1000>; + #address-cells = <1>; + #size-cells = <1>; + interrupts = <75 NRF_DEFAULT_IRQ_PRIORITY>; + rram0: rram@0 { + compatible = "soc-nv-flash"; + erase-block-size = <4096>; + write-block-size = <1>; + }; + }; + }; + + chosen { + zephyr,flash-controller = &rram_controller; + }; + + sw_pwm: sw-pwm { + generator = <&timer21>; + }; +}; From 2b728821cc36a847b285b3c65b78fd042d375e01 Mon Sep 17 00:00:00 2001 From: Witold Lukasik Date: Mon, 11 Dec 2023 17:30:04 +0100 Subject: [PATCH 1168/1623] [nrf fromtree] soc: arm: nordic_nrf: add source code for validating rram partitions RRAM is a part of nRF54L15 SOC. Signed-off-by: Witold Lukasik (cherry picked from commit a5eeb6d6db3af44935efb2c4b5f3c9240c19d3d9) --- soc/arm/nordic_nrf/validate_rram_partitions.c | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 soc/arm/nordic_nrf/validate_rram_partitions.c diff --git a/soc/arm/nordic_nrf/validate_rram_partitions.c b/soc/arm/nordic_nrf/validate_rram_partitions.c new file mode 100644 index 00000000000..f35d9cf73f3 --- /dev/null +++ b/soc/arm/nordic_nrf/validate_rram_partitions.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#define PAIR__(f, sep, arg_first, ...) FOR_EACH_FIXED_ARG(f, sep, arg_first, __VA_ARGS__) +#define PAIR_(f, sep, args_to_expand) PAIR__(f, sep, args_to_expand) +#define PAIR(n, f, sep, ...) PAIR_(f, sep, GET_ARGS_LESS_N(n, __VA_ARGS__)) + +/** + * @brief Call a macro on every unique pair of the given variadic arguments. + * + * For example, FOR_EACH_PAIR(f, (,), 1, 2, 3, 4) should expand to: + * + * f(2, 1) , f(3, 1) , f(4, 1) , f(3, 2) , f(4, 2) , f(4, 3) + * + * @param f Macro to call. Must accept two arguments. + * @param sep Separator between macro calls. Must be in parentheses. + * + * @see FOR_EACH + */ +#define FOR_EACH_PAIR(f, sep, ...) \ + LISTIFY(NUM_VA_ARGS_LESS_1(__VA_ARGS__), PAIR, sep, f, sep, __VA_ARGS__) + +/** + * @brief Get a node's non-secure register block start address. + * + * @param node_id Node identifier. + */ +#define REG_ADDR_NS(node_id) (DT_REG_ADDR(node_id) & 0xEFFFFFFFUL) + +/** + * @brief Get a node's non-secure register block end address. + * + * @param node_id Node identifier. + */ +#define REG_END_NS(node_id) (REG_ADDR_NS(node_id) + DT_REG_SIZE(node_id)) + +/* clang-format off */ + +#define RRAM_BASE REG_ADDR_NS(DT_NODELABEL(rram0)) +#define RRAM_CONTROLLER DT_NODELABEL(rram_controller) + +#if !DT_NODE_EXISTS(RRAM_CONTROLLER) +#error "Missing \"rram-controller\" node" +#endif + +#define CHECK_RRAM_NODE_COMPATIBLE(node_id) \ + BUILD_ASSERT(DT_NODE_HAS_COMPAT(node_id, soc_nv_flash), \ + "Missing compatible \"soc-nv-flash\" from " DT_NODE_FULL_NAME(node_id) \ + " (required for all children of " DT_NODE_PATH(RRAM_CONTROLLER) ")") + +#define CHECK_RRAM_PARTITION_WITHIN_PARENT(node_id) \ + BUILD_ASSERT(RRAM_BASE + REG_ADDR_NS(node_id) >= REG_ADDR_NS(DT_GPARENT(node_id)) && \ + RRAM_BASE + REG_END_NS(node_id) <= REG_END_NS(DT_GPARENT(node_id)), \ + DT_NODE_FULL_NAME(node_id) " is not fully contained within its parent " \ + DT_NODE_PATH(DT_GPARENT(node_id))) + +#define CHECK_NODES_NON_OVERLAPPING(node_id_1, node_id_2) \ + BUILD_ASSERT(REG_ADDR_NS(node_id_1) >= REG_END_NS(node_id_2) || \ + REG_ADDR_NS(node_id_2) >= REG_END_NS(node_id_1), \ + DT_NODE_PATH(node_id_1) " and " DT_NODE_PATH(node_id_2) " are overlapping") + +/* Retrieve all RRAM nodes that are children of "rram-controller". */ +#define COMMA(x) x, +#define RRAM_NODES_LIST LIST_DROP_EMPTY(DT_FOREACH_CHILD(RRAM_CONTROLLER, COMMA)) + +#if !IS_EMPTY(RRAM_NODES_LIST) + +/* Check that every RRAM node matches the "soc-nv-flash" compatible. */ +FOR_EACH(CHECK_RRAM_NODE_COMPATIBLE, (;), RRAM_NODES_LIST); + +/* Check that no two RRAM nodes are overlapping. */ +FOR_EACH_PAIR(CHECK_NODES_NON_OVERLAPPING, (;), RRAM_NODES_LIST); + +#endif + +/* Retrieve all RRAM partitions by looking for "fixed-partitions" compatibles in each RRAM node. */ +#define PARTITION_(x) \ + COND_CODE_1(DT_NODE_HAS_COMPAT(x, fixed_partitions), (DT_FOREACH_CHILD(x, COMMA)), ()) +#define PARTITION(x, ...) DT_FOREACH_CHILD_STATUS_OKAY(x, PARTITION_) +#define RRAM_PARTITION_LIST LIST_DROP_EMPTY(DT_FOREACH_CHILD_VARGS(RRAM_CONTROLLER, PARTITION)) + +#if !IS_EMPTY(RRAM_PARTITION_LIST) + +/* Check that every RRAM partition is within the bounds of its parent RRAM node. */ +FOR_EACH(CHECK_RRAM_PARTITION_WITHIN_PARENT, (;), RRAM_PARTITION_LIST); + +/* Check that no two RRAM partitions are overlapping. */ +FOR_EACH_PAIR(CHECK_NODES_NON_OVERLAPPING, (;), RRAM_PARTITION_LIST); + +#endif From 7e57cadfe6fbdabedd2d20a699f0386740fc5925 Mon Sep 17 00:00:00 2001 From: Witold Lukasik Date: Mon, 11 Dec 2023 17:28:06 +0100 Subject: [PATCH 1169/1623] [nrf fromtree] soc: arm: nordic_nrf: add support for Nordic nrf54l family Add soc files for new Nordic family. Signed-off-by: Witold Lukasik (cherry picked from commit 1d9f70226098da5eb849dbaf4f4f9eddd710a86f) --- soc/arm/nordic_nrf/nrf54l/CMakeLists.txt | 12 ++ .../Kconfig.defconfig.nrf54l15_enga_cpuapp | 18 +++ .../nrf54l/Kconfig.defconfig.series | 19 +++ soc/arm/nordic_nrf/nrf54l/Kconfig.series | 13 ++ soc/arm/nordic_nrf/nrf54l/Kconfig.soc | 70 +++++++++ soc/arm/nordic_nrf/nrf54l/soc.c | 136 ++++++++++++++++++ soc/arm/nordic_nrf/nrf54l/soc.h | 21 +++ 7 files changed, 289 insertions(+) create mode 100644 soc/arm/nordic_nrf/nrf54l/CMakeLists.txt create mode 100644 soc/arm/nordic_nrf/nrf54l/Kconfig.defconfig.nrf54l15_enga_cpuapp create mode 100644 soc/arm/nordic_nrf/nrf54l/Kconfig.defconfig.series create mode 100644 soc/arm/nordic_nrf/nrf54l/Kconfig.series create mode 100644 soc/arm/nordic_nrf/nrf54l/Kconfig.soc create mode 100644 soc/arm/nordic_nrf/nrf54l/soc.c create mode 100644 soc/arm/nordic_nrf/nrf54l/soc.h diff --git a/soc/arm/nordic_nrf/nrf54l/CMakeLists.txt b/soc/arm/nordic_nrf/nrf54l/CMakeLists.txt new file mode 100644 index 00000000000..914aad289ef --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54l/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +zephyr_sources( + soc.c + ../validate_rram_partitions.c) + +set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") + +if (CONFIG_ELV_GRTC_LFXO_ALLOWED) + message(WARNING "WARNING! ELV mode feature is EXPERIMENTAL and may brick your device!") +endif() diff --git a/soc/arm/nordic_nrf/nrf54l/Kconfig.defconfig.nrf54l15_enga_cpuapp b/soc/arm/nordic_nrf/nrf54l/Kconfig.defconfig.nrf54l15_enga_cpuapp new file mode 100644 index 00000000000..d19df604c02 --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54l/Kconfig.defconfig.nrf54l15_enga_cpuapp @@ -0,0 +1,18 @@ +# Nordic Semiconductor nRF54L15 MCU + +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_NRF54L15_ENGA_CPUAPP + +config SOC + string + default "nrf54l15_cpuapp" + +config NUM_IRQS + default 271 + +config IEEE802154_NRF5 + default IEEE802154 + +endif # SOC_NRF54L15_ENGA_CPUAPP diff --git a/soc/arm/nordic_nrf/nrf54l/Kconfig.defconfig.series b/soc/arm/nordic_nrf/nrf54l/Kconfig.defconfig.series new file mode 100644 index 00000000000..6c0a5bc606d --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54l/Kconfig.defconfig.series @@ -0,0 +1,19 @@ +# Nordic Semiconductor nRF54L MCU line + +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_NRF54LX + +rsource "Kconfig.defconfig.nrf54l*" + +config SOC_SERIES + default "nrf54l" + +config CORTEX_M_SYSTICK + default !NRF_GRTC_TIMER + +config CACHE_NRF_CACHE + default y if EXTERNAL_CACHE + +endif # SOC_SERIES_NRF54LX diff --git a/soc/arm/nordic_nrf/nrf54l/Kconfig.series b/soc/arm/nordic_nrf/nrf54l/Kconfig.series new file mode 100644 index 00000000000..a9367a0bf36 --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54l/Kconfig.series @@ -0,0 +1,13 @@ +# Nordic Semiconductor nRF54L MCU line + +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_NRF54LX + bool "Nordic Semiconductor nRF54L series MCU" + select HAS_NRFX + select HAS_NORDIC_DRIVERS + select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE + select SOC_FAMILY_NRF + help + Enable support for nRF54L MCU series diff --git a/soc/arm/nordic_nrf/nrf54l/Kconfig.soc b/soc/arm/nordic_nrf/nrf54l/Kconfig.soc new file mode 100644 index 00000000000..c42c8cfc9b3 --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54l/Kconfig.soc @@ -0,0 +1,70 @@ +# Nordic Semiconductor nRF54 MCU line + +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_NRF54LX + +config SOC_NRF54L15 + bool "NRF54L15" + +config SOC_NRF54L15_ENGA + bool "NRF54L15 ENGA" + select SOC_NRF54L15 + +config SOC_NRF54L15_ENGA_CPUAPP + bool "NRF54L15 ENGA CPUAPP" + select ARM + select ARMV8_M_DSP + select CPU_CORTEX_M33 + select CPU_HAS_ARM_MPU + select CPU_HAS_ICACHE + select CPU_HAS_ARM_SAU + select CPU_HAS_FPU + select HAS_HW_NRF_RADIO_IEEE802154 + select HAS_POWEROFF + select SOC_NRF54L15_ENGA + +config SOC_NRF54LX_SKIP_CLOCK_CONFIG + bool "Skip clock frequency configuration in system initialization" + help + With this option, the CPU clock frequency is not set during system initialization. + The CPU runs with the default, hardware-selected frequency. + +config SOC_NRF_FORCE_CONSTLAT + bool "Force constant-latency mode" + help + In constant latency mode the CPU wakeup latency and the PPI task response + will be constant and kept at a minimum. This is secured by forcing a set + of base resources on while in sleep. The advantage of having a constant + and predictable latency will be at the cost of having increased power consumption. + +config SOC_NRF54L_VREG_MAIN_DCDC + bool "NRF54L DC/DC converter." + help + To enable, an inductor must be connected to the DC/DC converter pin. + +config SOC_NRF54L_NORMAL_VOLTAGE_MODE + bool "NRF54L Normal Voltage Mode." + +config SOC_NRF54L_GLITCHDET_WORKAROUND + bool "Workaround that disables glitch detector" + default y + help + Temporary workaround - disabling glitch detector to limit power consumption. + +if NRF_GRTC_TIMER + +config ELV_GRTC_LFXO_ALLOWED + bool + depends on NRF_GRTC_SLEEP_ALLOWED + select EXPERIMENTAL + help + This feature allows using ELV mode when GRTC operates with the LFXO as + a low-frequency clock source. The LFXO is automatically activated when + preparing to system-off. + WARNING! This feature is EXPERIMENTAL and may brick your device! + +endif # NRF_GRTC_TIMER + +endif # SOC_SERIES_NRF54LX diff --git a/soc/arm/nordic_nrf/nrf54l/soc.c b/soc/arm/nordic_nrf/nrf54l/soc.c new file mode 100644 index 00000000000..a7b286fa048 --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54l/soc.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief System/hardware module for Nordic Semiconductor nRF54L family processor + * + * This module provides routines to initialize and support board-level hardware + * for the Nordic Semiconductor nRF54L family processor. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL); + +#define LFXO_NODE DT_NODELABEL(lfxo) +#define HFXO_NODE DT_NODELABEL(hfxo) + +static int nordicsemi_nrf54l_init(void) +{ + /* Update the SystemCoreClock global variable with current core clock + * retrieved from hardware state. + */ + SystemCoreClockUpdate(); + + /* Enable ICACHE */ + sys_cache_instr_enable(); + + if (IS_ENABLED(CONFIG_SOC_NRF54L_GLITCHDET_WORKAROUND)) { + nrf_glitchdet_enable_set(NRF_GLITCHDET, false); + } + +#if DT_ENUM_HAS_VALUE(LFXO_NODE, load_capacitors, internal) + uint32_t xosc32ktrim = NRF_FICR->XOSC32KTRIM; + + uint32_t offset_k = + (xosc32ktrim & FICR_XOSC32KTRIM_OFFSET_Msk) >> FICR_XOSC32KTRIM_OFFSET_Pos; + + uint32_t slope_field_k = + (xosc32ktrim & FICR_XOSC32KTRIM_SLOPE_Msk) >> FICR_XOSC32KTRIM_SLOPE_Pos; + uint32_t slope_mask_k = FICR_XOSC32KTRIM_SLOPE_Msk >> FICR_XOSC32KTRIM_SLOPE_Pos; + uint32_t slope_sign_k = (slope_mask_k - (slope_mask_k >> 1)); + int32_t slope_k = (int32_t)(slope_field_k ^ slope_sign_k) - (int32_t)slope_sign_k; + + /* As specified in the nRF54L15 PS: + * CAPVALUE = round( (CAPACITANCE - 4) * (FICR->XOSC32KTRIM.SLOPE + 0.765625 * 2^9)/(2^9) + * + FICR->XOSC32KTRIM.OFFSET/(2^6) ); + * where CAPACITANCE is the desired capacitor value in pF, holding any + * value between 4 pF and 18 pF in 0.5 pF steps. + */ + uint32_t mid_val = + (((DT_PROP(LFXO_NODE, load_capacitance_femtofarad) * 2UL) / 1000UL - 8UL) * + (uint32_t)(slope_k + 392)) + (offset_k << 4UL); + uint32_t capvalue_k = mid_val >> 10UL; + + /* Round. */ + if ((mid_val % 1024UL) >= 512UL) { + capvalue_k++; + } + nrf_oscillators_lfxo_cap_set(NRF_OSCILLATORS, (nrf_oscillators_lfxo_cap_t)capvalue_k); +#elif DT_ENUM_HAS_VALUE(LFXO_NODE, load_capacitors, external) + nrf_oscillators_lfxo_cap_set(NRF_OSCILLATORS, (nrf_oscillators_lfxo_cap_t)0); +#endif + +#if DT_ENUM_HAS_VALUE(HFXO_NODE, load_capacitors, internal) + uint32_t xosc32mtrim = NRF_FICR->XOSC32MTRIM; + /* The SLOPE field is in the two's complement form, hence this special + * handling. Ideally, it would result in just one SBFX instruction for + * extracting the slope value, at least gcc is capable of producing such + * output, but since the compiler apparently tries first to optimize + * additions and subtractions, it generates slightly less than optimal + * code. + */ + uint32_t slope_field = + (xosc32mtrim & FICR_XOSC32MTRIM_SLOPE_Msk) >> FICR_XOSC32MTRIM_SLOPE_Pos; + uint32_t slope_mask = FICR_XOSC32MTRIM_SLOPE_Msk >> FICR_XOSC32MTRIM_SLOPE_Pos; + uint32_t slope_sign = (slope_mask - (slope_mask >> 1)); + int32_t slope_m = (int32_t)(slope_field ^ slope_sign) - (int32_t)slope_sign; + uint32_t offset_m = + (xosc32mtrim & FICR_XOSC32MTRIM_OFFSET_Msk) >> FICR_XOSC32MTRIM_OFFSET_Pos; + /* As specified in the nRF54L15 PS: + * CAPVALUE = (((CAPACITANCE-5.5)*(FICR->XOSC32MTRIM.SLOPE+791)) + + * FICR->XOSC32MTRIM.OFFSET<<2)>>8; + * where CAPACITANCE is the desired total load capacitance value in pF, + * holding any value between 4.0 pF and 17.0 pF in 0.25 pF steps. + */ + uint32_t capvalue = + (((((DT_PROP(HFXO_NODE, load_capacitance_femtofarad) * 4UL) / 1000UL) - 22UL) * + (uint32_t)(slope_m + 791) / 4UL) + (offset_m << 2UL)) >> 8UL; + + nrf_oscillators_hfxo_cap_set(NRF_OSCILLATORS, true, capvalue); +#elif DT_ENUM_HAS_VALUE(HFXO_NODE, load_capacitors, external) + nrf_oscillators_hfxo_cap_set(NRF_OSCILLATORS, false, 0); +#endif + + if (IS_ENABLED(CONFIG_SOC_NRF_FORCE_CONSTLAT)) { + nrf_power_task_trigger(NRF_POWER, NRF_POWER_TASK_CONSTLAT); + } + + if (IS_ENABLED(CONFIG_SOC_NRF54L_VREG_MAIN_DCDC)) { + nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_MAIN, true); + } + + if (IS_ENABLED(CONFIG_SOC_NRF54L_NORMAL_VOLTAGE_MODE)) { + nrf_regulators_vreg_enable_set(NRF_REGULATORS, NRF_REGULATORS_VREG_MEDIUM, false); + } + +#if defined(CONFIG_ELV_GRTC_LFXO_ALLOWED) + nrf_regulators_elv_mode_allow_set(NRF_REGULATORS, NRF_REGULATORS_ELV_ELVGRTCLFXO_MASK); +#endif /* CONFIG_ELV_GRTC_LFXO_ALLOWED */ + + return 0; +} + +void arch_busy_wait(uint32_t time_us) +{ + nrfx_coredep_delay_us(time_us); +} + +SYS_INIT(nordicsemi_nrf54l_init, PRE_KERNEL_1, 0); diff --git a/soc/arm/nordic_nrf/nrf54l/soc.h b/soc/arm/nordic_nrf/nrf54l/soc.h new file mode 100644 index 00000000000..721e9336989 --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54l/soc.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file SoC configuration macros for the Nordic Semiconductor NRF54L family processors. + */ + +#ifndef _NORDICSEMI_NRF54L_SOC_H_ +#define _NORDICSEMI_NRF54L_SOC_H_ + +#define __ICACHE_PRESENT 1 + +#include + +#define FLASH_PAGE_ERASE_MAX_TIME_US 8000UL +#define FLASH_PAGE_MAX_CNT 381UL + +#endif /* _NORDICSEMI_NRF54L_SOC_H_ */ From 171aa8a3e2e595521771f26b15be11d53efc34c2 Mon Sep 17 00:00:00 2001 From: Witold Lukasik Date: Mon, 11 Dec 2023 17:37:22 +0100 Subject: [PATCH 1170/1623] [nrf fromtree] modules: hal_nordic: nrfx: add support for nRF54L15 SOC Add config files for nRF54L15. Signed-off-by: Witold Lukasik (cherry picked from commit 04e4e6e5e97ff1d72959e46a0f26d727aaeaecd5) --- modules/hal_nordic/nrfx/CMakeLists.txt | 13 + modules/hal_nordic/nrfx/nrfx_config.h | 2 + .../nrfx_config_nrf54l15_enga_application.h | 1538 +++++++++++++++++ 3 files changed, 1553 insertions(+) create mode 100644 modules/hal_nordic/nrfx/nrfx_config_nrf54l15_enga_application.h diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index 2e809c52b79..20740683a44 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -66,6 +66,7 @@ zephyr_library_sources_ifdef(CONFIG_SOC_NRF52833 ${MDK_DIR}/system_nrf5283 zephyr_library_sources_ifdef(CONFIG_SOC_NRF52840 ${MDK_DIR}/system_nrf52840.c) zephyr_library_sources_ifdef(CONFIG_SOC_NRF5340_CPUAPP ${MDK_DIR}/system_nrf5340_application.c) zephyr_library_sources_ifdef(CONFIG_SOC_NRF5340_CPUNET ${MDK_DIR}/system_nrf5340_network.c) +zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF54LX ${MDK_DIR}/system_nrf54l.c) zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF91X ${MDK_DIR}/system_nrf91.c) zephyr_library_sources(nrfx_glue.c) @@ -135,3 +136,15 @@ if(DEFINED uicr_path) zephyr_library_compile_definitions(CONFIG_GPIO_AS_PINRESET) endif() endif() + +if(CONFIG_SOC_NRF54L15) + dt_prop(clock_frequency PATH "/cpus/cpu@0" PROPERTY "clock-frequency") + math(EXPR clock_frequency_mhz "${clock_frequency} / 1000000") + zephyr_compile_definitions("NRF_CONFIG_CPU_FREQ_MHZ=${clock_frequency_mhz}") +endif() + +zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54LX_SKIP_CLOCK_CONFIG NRF_SKIP_CLOCK_CONFIGURATION) + +if(CONFIG_SOC_SERIES_NRF54LX AND CONFIG_NRFX_DPPI) + zephyr_library_sources(${HELPERS_DIR}/nrfx_gppi_dppi_ppib_lumos.c) +endif() diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 5d5746e2c88..543329b4a30 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -698,6 +698,8 @@ #include #elif defined(NRF9120_XXAA) || defined(NRF9160_XXAA) #include +#elif defined(NRF54L15_ENGA_XXAA) && defined(NRF_APPLICATION) + #include #else #error "Unknown device." #endif diff --git a/modules/hal_nordic/nrfx/nrfx_config_nrf54l15_enga_application.h b/modules/hal_nordic/nrfx/nrfx_config_nrf54l15_enga_application.h new file mode 100644 index 00000000000..46b0aa0eff7 --- /dev/null +++ b/modules/hal_nordic/nrfx/nrfx_config_nrf54l15_enga_application.h @@ -0,0 +1,1538 @@ +/* + * Copyright (c) 2024, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef NRFX_CONFIG_NRF54L15_APPLICATION_H__ +#define NRFX_CONFIG_NRF54L15_APPLICATION_H__ + +#ifndef NRFX_CONFIG_H__ +#error "This file should not be included directly. Include nrfx_config.h instead." +#endif + +/** + * @brief NRFX_CLOCK_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_CLOCK_ENABLED +#define NRFX_CLOCK_ENABLED 0 +#endif + +/** + * @brief NRFX_CLOCK_CONFIG_LF_SRC + * + * Integer value. + * Supported values: + * - RC = 0 + * - XTAL = 1 + * - Synth = 2 + */ +#ifndef NRFX_CLOCK_CONFIG_LF_SRC +#define NRFX_CLOCK_CONFIG_LF_SRC 0 +#endif + +/** + * @brief NRFX_CLOCK_CONFIG_LF_CAL_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_CLOCK_CONFIG_LF_CAL_ENABLED +#define NRFX_CLOCK_CONFIG_LF_CAL_ENABLED 0 +#endif + +/** + * @brief NRFX_CLOCK_CONFIG_LFXO_TWO_STAGE_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_CLOCK_CONFIG_LFXO_TWO_STAGE_ENABLED +#define NRFX_CLOCK_CONFIG_LFXO_TWO_STAGE_ENABLED 0 +#endif + +/** + * @brief NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_CLOCK_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_CLOCK_CONFIG_LOG_ENABLED +#define NRFX_CLOCK_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_CLOCK_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_CLOCK_CONFIG_LOG_LEVEL +#define NRFX_CLOCK_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_COMP_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_COMP_ENABLED +#define NRFX_COMP_ENABLED 0 +#endif + +/** + * @brief NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_COMP_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_COMP_CONFIG_LOG_ENABLED +#define NRFX_COMP_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_COMP_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_COMP_CONFIG_LOG_LEVEL +#define NRFX_COMP_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_DPPI_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_DPPI_ENABLED +#define NRFX_DPPI_ENABLED 0 +#endif + +/** + * @brief NRFX_DPPI_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_DPPI_CONFIG_LOG_ENABLED +#define NRFX_DPPI_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_DPPI_CONFIG_LOG_LEVEL + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_DPPI_CONFIG_LOG_LEVEL +#define NRFX_DPPI_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_EGU_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_EGU_ENABLED +#define NRFX_EGU_ENABLED 0 +#endif + +/** + * @brief NRFX_EGU10_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_EGU10_ENABLED +#define NRFX_EGU10_ENABLED 0 +#endif + +/** + * @brief NRFX_EGU20_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_EGU20_ENABLED +#define NRFX_EGU20_ENABLED 0 +#endif + +/** + * @brief NRFX_EGU_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_EGU_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_EGU_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_GPIOTE_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_GPIOTE_ENABLED +#define NRFX_GPIOTE_ENABLED 0 +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS + * + * Integer value. Minimum: 0 Maximum: 15 + */ +#ifndef NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS +#define NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS 0 +#endif + +/** + * @brief NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_GPIOTE_CONFIG_LOG_ENABLED +#define NRFX_GPIOTE_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_GPIOTE_CONFIG_LOG_LEVEL +#define NRFX_GPIOTE_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_GRTC_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_GRTC_ENABLED +#define NRFX_GRTC_ENABLED 0 +#endif + +/** + * @brief GRTC CC channels ownership mask. + */ +#ifndef NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK +#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_grtc) +#if DT_NODE_HAS_PROP(DT_INST(0, nordic_nrf_grtc), owned_channels) +#define NRFX_CONFIG_BIT_DT(node_id, prop, idx) \ + BIT(DT_PROP_BY_IDX(node_id, prop, idx)) +#define NRFX_CONFIG_GRTC_MASK_DT(prop) \ + (COND_CODE_1(DT_NODE_HAS_PROP(DT_INST(0, nordic_nrf_grtc), prop), \ + (DT_FOREACH_PROP_ELEM_SEP(DT_INST(0, nordic_nrf_grtc), prop, \ + NRFX_CONFIG_BIT_DT, (|))), \ + (0))) + +#define NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK \ + (NRFX_CONFIG_GRTC_MASK_DT(owned_channels) & \ + ~NRFX_CONFIG_GRTC_MASK_DT(child_owned_channels)) +#define NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS \ + (DT_PROP_LEN_OR(DT_INST(0, nordic_nrf_grtc), owned_channels, 0) - \ + DT_PROP_LEN_OR(DT_INST(0, nordic_nrf_grtc), child_owned_channels, 0)) + +#if ((NRFX_CONFIG_GRTC_MASK_DT(owned_channels) | \ + NRFX_CONFIG_GRTC_MASK_DT(child_owned_channels)) != NRFX_CONFIG_GRTC_MASK_DT(owned_channels)) +#error "`child-owned-channels` property must be a subset of `owned-channels` property" +#endif +#else +#error "property `owned-channels` does not exist" +#endif /* DT_NODE_HAS_PROP(DT_INST(0, nordic_nrf_grtc), owned_channels) */ +#endif /* DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_grtc) */ + +#endif /* NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK */ + +/** + * @brief NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_I2S_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_I2S_ENABLED +#define NRFX_I2S_ENABLED 0 +#endif + +/** + * @brief NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_I2S_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_I2S_CONFIG_LOG_ENABLED +#define NRFX_I2S_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_I2S_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_I2S_CONFIG_LOG_LEVEL +#define NRFX_I2S_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_LPCOMP_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_LPCOMP_ENABLED +#define NRFX_LPCOMP_ENABLED 0 +#endif + +/** + * @brief NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_LPCOMP_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_LPCOMP_CONFIG_LOG_ENABLED +#define NRFX_LPCOMP_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_LPCOMP_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_LPCOMP_CONFIG_LOG_LEVEL +#define NRFX_LPCOMP_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_NFCT_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_NFCT_ENABLED +#define NRFX_NFCT_ENABLED 0 +#endif + +/** + * @brief NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID +#define NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID 0 +#endif + +/** + * @brief NRFX_NFCT_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_NFCT_CONFIG_LOG_ENABLED +#define NRFX_NFCT_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_NFCT_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_NFCT_CONFIG_LOG_LEVEL +#define NRFX_NFCT_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_PDM_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PDM_ENABLED +#define NRFX_PDM_ENABLED 0 +#endif + +/** + * @brief NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_PDM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PDM_CONFIG_LOG_ENABLED +#define NRFX_PDM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PDM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PDM_CONFIG_LOG_LEVEL +#define NRFX_PDM_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_POWER_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_POWER_ENABLED +#define NRFX_POWER_ENABLED 0 +#endif + +/** + * @brief NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_PRS_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PRS_ENABLED +#define NRFX_PRS_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_0_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PRS_BOX_0_ENABLED +#define NRFX_PRS_BOX_0_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_1_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PRS_BOX_1_ENABLED +#define NRFX_PRS_BOX_1_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_2_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PRS_BOX_2_ENABLED +#define NRFX_PRS_BOX_2_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_3_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PRS_BOX_3_ENABLED +#define NRFX_PRS_BOX_3_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_4_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PRS_BOX_4_ENABLED +#define NRFX_PRS_BOX_4_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_5_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PRS_BOX_5_ENABLED +#define NRFX_PRS_BOX_5_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PRS_CONFIG_LOG_ENABLED +#define NRFX_PRS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PRS_CONFIG_LOG_LEVEL +#define NRFX_PRS_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_PWM_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PWM_ENABLED +#define NRFX_PWM_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM20_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PWM20_ENABLED +#define NRFX_PWM20_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM21_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PWM21_ENABLED +#define NRFX_PWM21_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM22_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PWM22_ENABLED +#define NRFX_PWM22_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_PWM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_PWM_CONFIG_LOG_ENABLED +#define NRFX_PWM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PWM_CONFIG_LOG_LEVEL +#define NRFX_PWM_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_QDEC_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_QDEC_ENABLED +#define NRFX_QDEC_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC20_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_QDEC20_ENABLED +#define NRFX_QDEC20_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC21_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_QDEC21_ENABLED +#define NRFX_QDEC21_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_QDEC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_QDEC_CONFIG_LOG_ENABLED +#define NRFX_QDEC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_QDEC_CONFIG_LOG_LEVEL +#define NRFX_QDEC_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_RTC_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_RTC_ENABLED +#define NRFX_RTC_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC10_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_RTC10_ENABLED +#define NRFX_RTC10_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC30_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_RTC30_ENABLED +#define NRFX_RTC30_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_RTC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_RTC_CONFIG_LOG_ENABLED +#define NRFX_RTC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_RTC_CONFIG_LOG_LEVEL +#define NRFX_RTC_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_SAADC_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SAADC_ENABLED +#define NRFX_SAADC_ENABLED 0 +#endif + +/** + * @brief NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_SAADC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SAADC_CONFIG_LOG_ENABLED +#define NRFX_SAADC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SAADC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SAADC_CONFIG_LOG_LEVEL +#define NRFX_SAADC_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_SPI_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPI_ENABLED +#define NRFX_SPI_ENABLED 0 +#endif + +/** + * @brief NRFX_SPI00_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPI00_ENABLED +#define NRFX_SPI00_ENABLED 0 +#endif + +/** + * @brief NRFX_SPI20_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPI20_ENABLED +#define NRFX_SPI20_ENABLED 0 +#endif + +/** + * @brief NRFX_SPI21_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPI21_ENABLED +#define NRFX_SPI21_ENABLED 0 +#endif + +/** + * @brief NRFX_SPI22_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPI22_ENABLED +#define NRFX_SPI22_ENABLED 0 +#endif + +/** + * @brief NRFX_SPI30_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPI30_ENABLED +#define NRFX_SPI30_ENABLED 0 +#endif + +/** + * @brief NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_SPI_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPI_CONFIG_LOG_ENABLED +#define NRFX_SPI_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SPI_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SPI_CONFIG_LOG_LEVEL +#define NRFX_SPI_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_SPIM_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIM_ENABLED +#define NRFX_SPIM_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM00_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIM00_ENABLED +#define NRFX_SPIM00_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM20_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIM20_ENABLED +#define NRFX_SPIM20_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM21_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIM21_ENABLED +#define NRFX_SPIM21_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM22_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIM22_ENABLED +#define NRFX_SPIM22_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM30_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIM30_ENABLED +#define NRFX_SPIM30_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM_EXTENDED_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIM_EXTENDED_ENABLED +#define NRFX_SPIM_EXTENDED_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_SPIM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIM_CONFIG_LOG_ENABLED +#define NRFX_SPIM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SPIM_CONFIG_LOG_LEVEL +#define NRFX_SPIM_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_SPIS_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIS_ENABLED +#define NRFX_SPIS_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS00_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIS00_ENABLED +#define NRFX_SPIS00_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS20_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIS20_ENABLED +#define NRFX_SPIS20_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS21_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIS21_ENABLED +#define NRFX_SPIS21_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS22_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIS22_ENABLED +#define NRFX_SPIS22_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS30_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIS30_ENABLED +#define NRFX_SPIS30_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_SPIS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SPIS_CONFIG_LOG_ENABLED +#define NRFX_SPIS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SPIS_CONFIG_LOG_LEVEL +#define NRFX_SPIS_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_SYSTICK_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_SYSTICK_ENABLED +#define NRFX_SYSTICK_ENABLED 0 +#endif + +/** + * @brief NRFX_TEMP_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TEMP_ENABLED +#define NRFX_TEMP_ENABLED 0 +#endif + +/** + * @brief NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_TIMER_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TIMER_ENABLED +#define NRFX_TIMER_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER10_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TIMER10_ENABLED +#define NRFX_TIMER10_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER20_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TIMER20_ENABLED +#define NRFX_TIMER20_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER21_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TIMER21_ENABLED +#define NRFX_TIMER21_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER22_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TIMER22_ENABLED +#define NRFX_TIMER22_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER23_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TIMER23_ENABLED +#define NRFX_TIMER23_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER24_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TIMER24_ENABLED +#define NRFX_TIMER24_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_TIMER_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TIMER_CONFIG_LOG_ENABLED +#define NRFX_TIMER_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TIMER_CONFIG_LOG_LEVEL +#define NRFX_TIMER_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_TWIM_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIM_ENABLED +#define NRFX_TWIM_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM20_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIM20_ENABLED +#define NRFX_TWIM20_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM21_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIM21_ENABLED +#define NRFX_TWIM21_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM22_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIM22_ENABLED +#define NRFX_TWIM22_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM30_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIM30_ENABLED +#define NRFX_TWIM30_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_TWIM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIM_CONFIG_LOG_ENABLED +#define NRFX_TWIM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TWIM_CONFIG_LOG_LEVEL +#define NRFX_TWIM_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_TWIS_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIS_ENABLED +#define NRFX_TWIS_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS00_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIS00_ENABLED +#define NRFX_TWIS00_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS20_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIS20_ENABLED +#define NRFX_TWIS20_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS21_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIS21_ENABLED +#define NRFX_TWIS21_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS22_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIS22_ENABLED +#define NRFX_TWIS22_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS30_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIS30_ENABLED +#define NRFX_TWIS30_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY +#define NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY 0 +#endif + +/** + * @brief NRFX_TWIS_NO_SYNC_MODE + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIS_NO_SYNC_MODE +#define NRFX_TWIS_NO_SYNC_MODE 0 +#endif + +/** + * @brief NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_TWIS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_TWIS_CONFIG_LOG_ENABLED +#define NRFX_TWIS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TWIS_CONFIG_LOG_LEVEL +#define NRFX_TWIS_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_UARTE_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_UARTE_ENABLED +#define NRFX_UARTE_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE00_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_UARTE00_ENABLED +#define NRFX_UARTE00_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE20_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_UARTE20_ENABLED +#define NRFX_UARTE20_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE21_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_UARTE21_ENABLED +#define NRFX_UARTE21_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE22_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_UARTE22_ENABLED +#define NRFX_UARTE22_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE30_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_UARTE30_ENABLED +#define NRFX_UARTE30_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_LOG_ENABLED +#define NRFX_UARTE_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_UARTE_CONFIG_LOG_LEVEL +#define NRFX_UARTE_CONFIG_LOG_LEVEL 0 +#endif + +/** + * @brief NRFX_WDT_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_WDT_ENABLED +#define NRFX_WDT_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT30_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_WDT30_ENABLED +#define NRFX_WDT30_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT31_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_WDT31_ENABLED +#define NRFX_WDT31_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT_CONFIG_NO_IRQ + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_WDT_CONFIG_NO_IRQ +#define NRFX_WDT_CONFIG_NO_IRQ 0 +#endif + +/** + * @brief NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0 Maximum: 7 + */ +#ifndef NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY 0 +#endif + +/** + * @brief NRFX_WDT_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values 0 and 1. + */ +#ifndef NRFX_WDT_CONFIG_LOG_ENABLED +#define NRFX_WDT_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_WDT_CONFIG_LOG_LEVEL +#define NRFX_WDT_CONFIG_LOG_LEVEL 0 +#endif + +#endif /* NRFX_CONFIG_NRF54L15_APPLICATION_H__ */ From 64bccc5b90cfadb3981aaaba02ec0f5a9cd1877e Mon Sep 17 00:00:00 2001 From: Witold Lukasik Date: Mon, 11 Dec 2023 17:43:27 +0100 Subject: [PATCH 1171/1623] [nrf fromtree] boards: arm: add Nordic nrf54l15dk_nrf54l15 Add board files for nRF54L15 DK. Signed-off-by: Witold Lukasik (cherry picked from commit 4a095bfb356c8d67c7ce828b8d7176ce63e747ad) --- boards/arm/nrf54l15pdk_nrf54l15/Kconfig.board | 6 + .../nrf54l15pdk_nrf54l15/Kconfig.defconfig | 12 ++ boards/arm/nrf54l15pdk_nrf54l15/board.cmake | 4 + .../doc/img/nrf54l15pdk_nrf54l15.webp | Bin 0 -> 35746 bytes boards/arm/nrf54l15pdk_nrf54l15/doc/index.rst | 134 ++++++++++++++++ .../nrf54l15pdk_nrf54l15_cpuapp-pinctrl.dtsi | 36 +++++ .../nrf54l15pdk_nrf54l15_cpuapp.dts | 149 ++++++++++++++++++ .../nrf54l15pdk_nrf54l15_cpuapp.yaml | 19 +++ .../nrf54l15pdk_nrf54l15_cpuapp_defconfig | 32 ++++ .../arm/nrf54l15pdk_nrf54l15/revision.cmake | 9 ++ 10 files changed, 401 insertions(+) create mode 100644 boards/arm/nrf54l15pdk_nrf54l15/Kconfig.board create mode 100644 boards/arm/nrf54l15pdk_nrf54l15/Kconfig.defconfig create mode 100644 boards/arm/nrf54l15pdk_nrf54l15/board.cmake create mode 100644 boards/arm/nrf54l15pdk_nrf54l15/doc/img/nrf54l15pdk_nrf54l15.webp create mode 100644 boards/arm/nrf54l15pdk_nrf54l15/doc/index.rst create mode 100644 boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp-pinctrl.dtsi create mode 100644 boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp.dts create mode 100644 boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp.yaml create mode 100644 boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp_defconfig create mode 100644 boards/arm/nrf54l15pdk_nrf54l15/revision.cmake diff --git a/boards/arm/nrf54l15pdk_nrf54l15/Kconfig.board b/boards/arm/nrf54l15pdk_nrf54l15/Kconfig.board new file mode 100644 index 00000000000..d95fe51009f --- /dev/null +++ b/boards/arm/nrf54l15pdk_nrf54l15/Kconfig.board @@ -0,0 +1,6 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_NRF54L15PDK_NRF54L15_CPUAPP + bool "nRF54L15 PDK nRF54L15 Application MCU" + depends on SOC_NRF54L15_ENGA_CPUAPP diff --git a/boards/arm/nrf54l15pdk_nrf54l15/Kconfig.defconfig b/boards/arm/nrf54l15pdk_nrf54l15/Kconfig.defconfig new file mode 100644 index 00000000000..532ea07c859 --- /dev/null +++ b/boards/arm/nrf54l15pdk_nrf54l15/Kconfig.defconfig @@ -0,0 +1,12 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_NRF54L15PDK_NRF54L15_CPUAPP + +config BOARD + default "nrf54l15pdk_nrf54l15_cpuapp" + +config BT_CTLR + default BT + +endif # BOARD_NRF54L15PDK_NRF54L15_CPUAPP diff --git a/boards/arm/nrf54l15pdk_nrf54l15/board.cmake b/boards/arm/nrf54l15pdk_nrf54l15/board.cmake new file mode 100644 index 00000000000..378b7bcdb57 --- /dev/null +++ b/boards/arm/nrf54l15pdk_nrf54l15/board.cmake @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) diff --git a/boards/arm/nrf54l15pdk_nrf54l15/doc/img/nrf54l15pdk_nrf54l15.webp b/boards/arm/nrf54l15pdk_nrf54l15/doc/img/nrf54l15pdk_nrf54l15.webp new file mode 100644 index 0000000000000000000000000000000000000000..80fb2060a0772776c3ba1a4e092ba7c28f13bbd7 GIT binary patch literal 35746 zcmZshLz6Cy4ur?HZQJ%4+qP}nwr!oUZQC}_*yek`A8@nks%%n~MdwMivXr=Zb_@`Z zhM0(=x*``*{C~P(1vn3wW(cGPSm3X0feZy1MHyAA&cOmYwA?nnnpP_aZXpd2bOX*) zJBGr$#hc*#XQ;D6OfKq`@OM3!kKpvzTtM%n}~`iv^bgjsbv|%b%-v3ji!2V-52+ z001yV1pIFOko^P$z<=)6DZ>G=0PHW9U)tq>iQkBC!FPpS#=E@(Y>R736~>&O!aa@B=8E z^8Nze=au`V0nh-MZ_WY4C&rtCH^AT*_wVtm&a}xb;f>%cAnzUY*W+gy!1y^oTVGyq z+y5QV0C2m+y#)OBU-f|olm&!5-v9uB;e)q3MgZWq0CB&EaKM*jUF765 zL064Pv9%g$y=%KSx7jwKM=P=_QM%)JG+KM@sSLkDvMo^V~ncloY;(XC8 zr~6_NZGEUC*c5R{K42-8ITK}Ads{)-+qLMRO--V#bK(iYZ~}8&i_Cnb%E$NgHD3`^ z;C@s4V&?5zAs-k$-#>TdT7+ph;Df^Y&L#B3#tZAP*|Vr{q72b(FO_5tWMCZ?bTtg zchU6ZG*`kA2F2_=STI+8Mae8}!dQHSK~qEwe&l_=^H!wdwjVP;J(@qInn9zrclk!x zhW(=RTrpi}v1F`7M_n&i;7Ft+GE=sGkEX4X@bwjwdHfzpw1f0|*+>3BkGyML2Yn@o zsp1o4*-&4Ob3>MC2bQ4fYg%`4-OQS9F7lbwhfg+HpO0MVVhL<%fS9k0tMAdH>wpm3 z15m>oT#vgJ8tTAut;?P@BMrCpZD%){`H<7V$C-?-6%hQW!8N+3Qs01W>|Mi?3}`cr zN=dpeLIkGjvu9*J|7jv}f35<<>f`qHu2+>B=MBgDEwJ*-c+zZ>S)CRHjV6_fZrf1^ z1j#A+dB)fr;zYh$fDm$^eu~TSGOuu2jwjHM}}3dVmX#ozr6w36w9}lM4~I zKv)cVyvr#+@Dk!gi8#+pgyWzP1;ZWyp{44#T8&|ArP9lV5LHfuTQRh8yBc^SX!VG% zzw2K?&g**uK0+qpEv)+z*|=w!Y4nXg*Xy?E)RubQYGx{z>2>PZrswnN_L_Rky+ZFx ze#hME-z$Gw(iaGv^Iiz~DG@%{Ee>yk$D$XDqDHX;+$u8eLmb(dW38R$E-Ps&94RsF#-Ir!%2{=%%T^H5wv z)l7XbZm=kwL>T-?l*>N6cNw{4#_YS*xEcekh!|tL!uf7NEZm1J+5ISFTOz|{L!ZVV zaC}VrIdx}X#wSno6>J)c&$sX!&*4oP*CjLeUQlQw=$-qe=HEjejZxuqyEBW@M%6))@IEfC zV2OGvT861RTLeWR7vCX35kePuaU8H=yD?9l*K9eh0AkaV{XLKs+Z4J8QeO_lryTG%Zi86s^;|b`04L6Au*S4Z8C?6MEppm=?=X- zX3~1kAnkEyrxm0 zA3q~0t^+=*!pIdj2q%n9!u<HH4E+#aK!7m(jK9SI%QkTVknqzZ3jxWuN%|9q zXV5m9iNl-89>s6rc9W2sy>wo(LJ)_)?`&G^E3bY9}%; z1*N;-2wh?Sm$-gcRkc}NkDa@nAU~o?nEY(iv*YatVpLAD5xQu&w#~8ZH~V}>ndaeI z5p`rxHVg`|L6z!Z!%D*zeS=lxTqQKFFTR07vAorc+1BsO|C=~UK#*3Vt5H%1Y*=b! zg)G<|mpyF%a%dxK;&|e7|w8Hw=cP3 zli;6#Z{s88SCeejfW6c)FZ@WgN5fu8ChJ)X-W)~{`ZHr$c=n*d_imW9yxXD%GI+<0 zTgKo|7|5xrGvU$)?IIa{ zO?cdQ>6)N;+J-bbeh_G(l_RirXpeO=xLUEj|n5;m`%)h6~V z^{ej8`aOC1NH4MEaPm|lcjPo75_RAybTGa1kI$hMD3S<+rD!xx@gixClRb z!2>h-fGSN>EhGJVFn+n|p@u1rMFS??VuGsD`R8{ty13hcHEACDJ!2FdVDEd=f*(1j zGY(X|l5MewDdpoF%OnP8@z`dHVMq%&xIjlq=o5=dc8O7zTm);V=C+6?%;OBvqEZ>{2 zxwf@b**hqT%3An8>_s}oHv<%!7X{=7EdAH;4j3V#SohjVQtDjfCK6If65HPPdgF%$ z>_PH91hmCbXVVMSUl?X=`FqLtcD##iemBe*52aXn67HndsE-$4#zO9>0v=THG{%Bsw8OAv&k5S5IeggwCM@(I{ij%AZ;JW9h> zKFtz@lDT|Ukf?H>^CY;y13TSKTjq5bOJ zOgsou&*?DS;z(nif2u$lS+cujP^w5!jN{qK?w22<=YH|PFj@C=i|uw{trsVbEpeaM znzc@nYJy@B#P7iR$0@9P*)Ku+n7Pol`pYO10sh4{>`FrlO08PsK%A5sO5L`G$Lr;& z$V6sHdtor_-*+XoOcL+x8kvGlQ_Xe5z027l%{ER0FF{xy0@8u3f)1kMi*xFdW&|^G z+-n$&)B+v>A&VhxgH1%+YPkW&XlN22cRcOQTG;~|#)Ld2q{UydKaWI^5TI)r=HW^nCTkWp^IF!I5-^r8SmWFR345eWfP7h{{8Nt4hu@;^xVaBv6iGPu3Y zDytWSpZ|#Uzj^XbV6_b6k~KQrnt9`j3@oAwm0+yB#l>tzM&%=`8MKOVzrr3)xnFJs zGQbv?&ld_Q6-JfT3pg)2V%5Lv8TDnKWTy1=hD1{t{M)_jlej15=KoSqM)V*5$2{;Pq>xZf1X?)PCMXGT9UY*IR((hr zoYwRl@kV1ar8~vU*4R!-ujoaE|pfjEn_c zPhpHFP}SVpImT~@{o`C=0^vx#ZtV}S*m~!xnvHbk4h$2E`b)w9`hGS)!A7J%&czw!d{kj3jwl*YyuUZn7KGPXb`Eu^Q-jQ$ls>=xCL_F?Lm-Q^$SKm zzKh#Sn9#i`-%Me<&y+EJitA(d!n=nT`o@J>-b{ z6 zB@I2(IgIi)i4GlyJToZ=A=Ks3mTkDwQr<)V7H6e5yr;G;h<`lW|9INrE7s1oRKYC! z+O*Y_DcvVJZ^RKM5TTzx?OW%uHWLWQLvyr^YIGafVr~u=pP>Flb%h=F zWDd1Nj~3Cg6n3lqNa@DpZ3RQ+_MQ7~7Hrb?|Dt)1-A+753!CTBLX%0QDIZOk5^z2P zmQM&p!abKKDFHHU=HU7?X8TdmHGJ?>V8^t_{UA_s=LoFsjKjJv5i|Xzhv*d#QZ-tXT$PX%VS3q)xOUJkp>7NcmL=7hn0dpMD_h|@_7oFCY z2&%E8b)uQcYYPa%4mrYqD?ibHa6*vpeIs&Py2StBtA9Fl=Bil2%SNK%Y|FO&Z0dy6 zICCgk=3!ArR@1RygI3;~PfCH%+2~;`{VBhzaqaB06uQe{CYai2(4vtSLQ63eJaplr z4x#JyRL%^j8($z>rUa$JfHk^Q zANj;w_ld~Gr@(4bX!82j z{1L}@Z1`VI$ycsZwc@7T_7Z zk9>BR#caz_WNi2E8YUEHz5vK~w!(6{!$cugtPC$(h{#*2+&+&~9~EL`pmvvosF&2c z{#_Qxf;P5;ShTGV$7WswgwX&YeLX-rSJ}Y>q}d%-++p;(kfe6unGvUqc)jO>>b1jn zFsE>pC9$9Iyr}kXl~1#20v^mfQJ-&c0)08?tU!Xs8NyF<`|c`z!3KN6rJ_X=!}HZ% z!^z<3C65;=l1to1E9y29db8|ZEI9%Yi9`O!t4G5DtKA=?p!n$AFp&}*0n0v{@qcDt zFpI=B$Hv)c?^{tm*~r)fwv$}kOv_fBI9fF9N{fqTz}gbc6|3jNVhxDkVo%az6<=$9I&K28SA-zb%#B&3;uUpJQ@bXY zN5HQ1?M$6dn}zUEM-$d@YOojL<#vCzD_}+G_2%U7k=Bvi{YzbYLt9HtI+p~g`q=gWPFSUNb#yJAXTu4l{l)Hku*? zCJ+>$W)g;jd-4uYV7rnfjNMqtX^!?s{Et%fwoXwz7?(20tp@anX#pWm9 z;t8-%^1b5C@~xwMlVXQ1a$7we-4M;qR6 z&_4VDdh^v0Y~mK@HY5tJv|$aAP2p@~#&z9Gx*Wz{i{18E)5q{#_EWL6iobx$D z?SQ?skyzpKw}F=JH~NvC`NcpnjQgQ~daY$;YMj8Lw%M?~@Kj?8z2wQJpG%5LZeN&h z>H7O5T|;>1w!U<=yv7eqo0|ZyUtYCH-^5ixvfw!%QtyX_y$WeZo=lwj{E?qSu{Q}X z;~D;+=b-~8%C>&DI;DFAz3Po%5i#H?^2{SDzHTslMyICKGj-Sy2>;VoV2XKabf&Z) zUjq+Atc5(twr%ZzWqSzJYKRyeV`sg-Tfu7o@;(g2v-s|KZkAG#=(5IsFI9~_tC(A8 z4daiJ%n6qMatwq_73G;faLEiR1kq}MHl$DsfT{s#)6nOj^NF5Pd?HKi#py{`U$MUv8qQc)6Ebc}X zs9;ik6HapWC!qT*hlZGe=*)G9+U@P;ccSgqlHMLbz$F77VDavG6(M zI#lMNr;H$z?z^ve#BghfXm}GNn0zz53mH6|lcH zhxyT>D#LR}MPn+0!Kr_tTTGE5RP7(aI`SYtB;;#j8JU8GZ9mS-K}TllHO4W#@SuDK z1@j8z%zdHy->lA_RzWSTPOdjGb)ze0o0)&KAUL!=Lh+Tt>b{Kn#CZe1c}T0@EcCXHH% zjHh=!|L<`J^-&uxd51di!^~hUn#+o2@U4xYw&F#fh-(}Xy=5ynK&a$VZ&c5=&+&u- z{(OC8x?6PCfk8?VZ~Z1Q4;7)B;fQ*XU=n+s!C?EG9dpA(a=rP$%Dx_)&0{N2zp>zeKTF~IgQHCC zFtEWHt%|xa?ei!h%RuJJCU0g^e1}JZxIh?e(#;1V$gzi2=E(NeO|Xb&5LKaMu?;UW z_!T*N&AtzIA^d$jQ+<=pND}`eZ5UvaiZIH`F4k=Z&c=hRU2863OJUaP|jYmwx&lQc_$s6x1Ch9~k zXiA+^FNUDFT`#?Zd+t6JpxwePr|W$_I;}b*t`4272Z{q9E|mp#MppPF)N6djXv96$ z%d_x^rWA*i4d;3NL&_u+!i4+|9J$c|Hh6R6G05Su#~TSPBJf7yJl42E8iGZW{u%!% zACF>Rhl4y8NasM{RMCjt&C!=4bHmFwnbjbNYX%SR>QGyC05FXL56@SgbtHsMr5XTkNZp;(3*wgS>)a=&g z>ac3?R>e_qwNbPiq(%G;?h%i!K8h9@lxmx~xm|VmNof?j&yu%TWx_9ZQtX|-VIw2t zHPT!jdS3LKX5+GM<2Aue11w|0hlgFuP$5xrMy!$8M3W#|FLs>3sot$# zZq>5Tg9+fZH0SE`GHI+ydhJ*y|o47}b{dG^k_J%BeZ^9xljU{A(pi*UVqCh5F>Oz#N(Y!*%M z#D(!QwSf&E5G-7}Qe%x$N>0`i0WGMKjf$%nRdeQ~fz0Jg7y6Mu2E|{Ch0W%#w$$FB z6yk?&(kvbvv^a=thvVSV5Mo@gG$T%ZafUHkfh?lB<%EmLt-D%G~@c8;3&?BRds=~0ad+b z^hjUl<*na9iH>kc-{snPO(uB>>yhjb1I%FsM}>qXj)kMer)a|;DZaIk0_p3ay`y;(|C+6lp96Gs_R z=mbm$qJ@TNTe`2?E-Z^be+dC#-_oY?7@n&C&~{Y7X%N#g-GhM*RJceV;2iKe9<~*tP4%PX9yJq>*+|j`fIhV9tM9BO z-RS0diuqqTk=`o}aVsP8dKhI{S?B~UVyoFhp^mh2!H0n%#$j$Nd6^?u@V=6v^vMy|gVRAGBKv3)wOTT zf)lAvh^?79=cgCF86;d#K40AQ!?Nqu#*#%}wewLejHUikR@bxP$V zr&#ft22Yz+%{vLkr3DfVJdgu8NyT3P1o)xj7F^b9HOO`ooi#iMs{TIuO<`T#l^(*eRvZgAi-7_k+7d2?Ov`;dz+1j#o7 z60f$;U>ObOlO&GdK~C4p7;y%^7+N5rNa}_d*Q-GEh?bXrC(q|lq2&Cfl_)q*=Ohd| z=(Zi_O(qnU+s1F4Lwga(S=yg;)6`k$dt0Jl6w3amD4uv7k2s!e~2yr9VbtYq@aMBBV};Xn$#?SQm*D8kH4Vcz==hy@q3l zi>zcTw}7Hd7)^~^K`pM0p_?Abh+c@vN(c7ky;A;d+Ub;>S(iy#hSv+bzdOfj_SYv* zBHhA5Vs{tX%^z=Rhj7cXq0vNbx{j`4Vp<_W#~zSsczTAwG3xtLVGnhwS1)5s4PGsF z<<}1`qKc0pi705+E=Z;-IQE_zJ>E7Iy4_a@S5U zyeWA~M1@Zy>N=)ayHG83Ji}ZAjdt+%)+THIF#7rXzH=LQewRMZhtyot4`|jEr75F3=o>`r*E2apWZrvCZ3ogd%a>tsgnEU@O;TZbA2=Lb^cQF~}d}k}8 z8dv$C)q>JHt}A^wq-rX88jHfS1cpXR>@M6QN+MrRl}(g$Gf?4jjS;v>jYwV5DCxs{FKrG(OGfMjn-TjwxL^M)lV}^3RQJ2^% zX8422b-^g-QLVXJ06x9~U>{_PQx-?{V<1OM0BO8d^73q3HwZPXVCUjU)rSVMVhXtbw7YiE+YcAw6xH370#7OU*l1MdG+mLTrG*v z@P3klVWEpi5v^GdL=eM%VM2U0{WKoxC=o2Rq#=VU?B6=6m!u9h0u?kRTA=wwT?;C_ zrnihr1P0TzBm$9G!*;Fa0ION{N z%@roMFWg&gzs;x%=S2^7jK05Qa}6`dr*9@RR6gS{kC2-1$hRfm7?mq1fWO9N@Rmf@ z4Hq3Gb@J8fHyI5nR$EtcQ4j^-%ChN<2jKPQ7SmC5rE#uxnr3j4xt|KL-xv1mHQ3DW zW)y`qi^brZ#1?8KK3S>pIZjMON2^*Yu_G^s4!pJeU;BLAAImCrxeqC)pp0t#@4*O} zlES_H2a2ZBX35GWw!NO5i<40F{XqoGS%K8%B#;$0pTNhpOAOtj79N)>2O|adhued3 zKTb296HGl!{dE%S>bx73wE6WV?76@J6GgAQs_vx>2r}*pdwE_Jwwb5$p=r`w87sZ` zp2F{XB6&KJ5jL_yPu!x`t71&p307d-*dcyWDg%w1)c(~Qp6vA=0nAzuIJ?fFZgaSwpc4C)2}lps1mS%O8**XQpahUAGbB1L&yG1RP8#nX z1~g~{2HN=+s}%sLL-=xCaY(*hz5GnL7Yn}^c zIdkRNCCem-&bE|o!f86zo9yU5Uew>>Boxd-tIY2!+ryM=O7+=)2wK9DEdaZWz}p}} z8?00fHx94^bJrEjg<^pQbI)3F-jn~b0z8w}s|_1)rl;vZ@mD+I9dR%@RLitFe&6Rs zsu;~%B0$^S`$6EOxV;9YFErjyAPXzW(fuQ0%GSU%UE5?+w}siX zBxk4Oa3@2wbf^AB2|jJy8f<&u-DSmv!0{X8x=oZ>f@D zd9`3>w`ur*;ks|A?3Levy#wM8%9MOm@~X*ea)sm>N=-k^Pyp?0|5{FnX- zF?u99dyhgv%-sn*ev`nZnEGR{_=sAD}mCBZh5 z(W}x>!;q^F9Ug^OlooQepdt;nO(l=v?01$#kEIesYcG$@v+8X3x3#=`3$>`%LlT%C(3XCbYO4?l5xd=81)d&dCaFh?C=hAXySMCQNLpYkSaQ^u{{B{N6%##v(El)cV3hwY=SaL@d-)b!+>O zb_YGk`%Ro+AYJ+lBL`@Kvw)L)5{$2GKs#s6fy2mAlJAoW^ke!qj19Jr2qwk2a`>jt zb2{!OSaU&;7&uew65Ks49a8a~juzb5QrKY|GrG0Z_ZOO5N#*_75kqRE?N!963DE&NqSN1Y4LiPP4)6#$xl|Y3+rGVK9;o z8eN=oU)lCIzeTtR;62gC6n~2w|5wltRUsCbS?Z9XeoMk+!lH||7lIly=ptR@` zDo`Y+#tJ@9jJJNJj;f%RXN` z+DT#C#OxRH6@c~Y64i*@97q-lsqts={lRf$jDf1m7bJZ)WPqkfR=_?+F~|*vWF<32~=>e0j7)e#PPF=fUYLY?t5W za3tb>Nxuk35+n^>V>c%vxxAqrVr=&l#O;GWGLM#s<<(xfB*EwV&nx5s;33cpR} zoYWr(gWiazF7Ru%DI=_E$5)U2qv)jZ2)eF20R1aMZWOP_BSJGTR#JFocQjcVGkfR3MAXawp3x5t{S)Rst?PPWT772A3Mr-@M!bPEwiC zU#e_lNO@w7EkKO`JqdgMi!oEPj^8f9wit9ew`bxvCB#bCe1ku;F%|;7=Po7-m4gn& zOB>I=-qjO37WLq)aGXqBijpP2*1N(KNREElmDHh1k{TX>6xY=2O-B^|l``Z%7D4jm zjQv&99p~`5Yd}iRz9~<{?rKiCDfxO$1 zoV4@^*^iL9o5ItpNHOV|Tt6&ff+SJlGA(Q1v!%6M`ZzmLR;aEv+t%@_mJs%fKXqes zRrhPDR~L_DecqNc4er)@&XXjv)`MDbk-x&{Eb8N~i^Zf<=5_#j>s05V?Fp*4cZUA~ z(Y&k`<)^7ibubpoXdoaj#5MKO(A3e`h3f1^soE@RXT&fSmo$yh#_6Cm5sqsDUNwvI zP6*)N-J8G~tj%V%%ny(E*sS^6U5r`o$|xnD6#skX?tHK>kA8O@Kc=XgjAJg)3?&|* z^Cufm+)}MIZ>)MCJJRmadw0qJmSR5hR3`89&2?XX3@o$Z-?hk6@O+&~Ek6pSv0wX) zKFq#=AY&fCaS~tLXC?tnQXPEG{V3tjLDpVWua;52yi2Z{tnmbPc^amc1-6DqUWXs= zM!1!`i1^|xnfNMWoiaUj(3U&SXUKGsBmrgjStW8md$Tc)RfNU1w_n*O&r%){e78|CT`fka;cniEx^6Q-SEq)2lrKx-b$bfQ7w z@`RRjgkJw_!Vd`mY{}phFi`ckMVz#I51a-3ENr+X?30u7Wi|)P6HsIDmOrT2@f!jE zy;N;*AKpxzO)CTb3(?e7XX&1jTla;NczY`SHxd;3aw!_a=M=$`Hc|x3lMD<$wxCcI zHh>B7*|e{!LLy50ZR1@FHa)A_XtUt3?|saI9tmzM_6)RQ7Ba_yQ;Wkhy5oLoGW=R7 z{7G;`-Q%7VRKgJf4N@ilLxzIVXC4wXX@0wnT$SCtu6oGG$}#Mn6`Ztj?y!)jK<)lC zn_%NntTl((0;kkTD?|?AU}e9c%E%9<6{{#m_6FC#k*x-h&MRvRCaA!B@J81oSeYk3 z_pjG}TqM2Pdzj2W9TS9qVl=`5zlsEk@Y>0Wci#SuOvVP%GJkon1}f7KH>{4CD%XF( zvR_$C)-qR_s89ZPGB~v*-aF&l_*sQO6z&2k2uB9PC6sg^wxU#Vo@aMNg(hy-yGd0) z>3b=AZq#%lo3cslE9qzFYws&1)->Bh(L z_fHjo1-W|5EGbOpsMBB)N)B!S#9Lr?mk?F_v;Oek6iERr>zVRyl1rJCJXV>~FqPM< z_7iF|4NIzoW0oMnMz}K%OABbK0dq2rltl8ei^G1@(9Z|&vo2c^sD9;~V{~>N>3Dnh z*oyft_eiW zG4ePsh!D*^gk3LT`oeNJxI-bn#46JxI7V{S(f#+8f2cDe*L>xF6EqA2iApy904mW( zWD$nzk!|8TV|8o#jJGD)OoYkU8I2U2WDFZKfjUIqphRg&{uONgi{V{>^A_#K(4_uU zC>u!bi#CI#M`e-#3obx7$GPNTT}_Y{FcTagyl!`rth{j1v;y^4)ik)lsI^E=&9_VFd>%kA)) zxiMi0ft567X%_soo(4PP2P{4URfk=iL|1n|2E#v|wRTpht8s(eryG2j#qdHfRqQm2 zu#1~N1OQX6X{NB`FfNf3b+Lpp{s`4tjS@<^Jnft>YsX*8QhqaJTv)zC zdd~NtxI^TTUY8@ZBc{w6l>~U>q4M zaKO)l9|Jjqaj_u9Up)`)^C`G1JdrGP!EWUg`!F{h(w>di5OI67?a9AJkS~M|XQ&W6 z$(+h<`Ccei(UKn=7(t=`#gLj`!m=AVAOR{HLytf2?ng~^5T(bK!5o~xu0yT&hNYzJ-8nZ%RfnH@hs-NSIdj{Ii;09qZ=?v^*`Yp~Rv zkL8^^e$b$HDeeKCgi9c+lH3VCa!6H)f`SqUT@Y`z23+GI>J;-I$8w_knBc6F3*xNX zJ={iDd!ZLA=hG|4?Do9iolEEfA{}WdbYWq#`V$?$g)0DSWy1+U7HC{gb{jV24LtvZ z@|+M8@)oahC5g^4@(D&I6){d-@`lMH)r}&+_r{yMk<(1|`+^MLDNklw2h2lGg1k5D z+;o?UCZ+m(bQ6a*#p3O^{Fm1bn5jEO2ddL1a`P=z#~+Mhg{dzx_k63i6cvSxW1Kyf z>@cc`@h3Aat4fO|3{F*;(xjcl=iSG$kLF}ACf~c-lvEC@_lc+0YI6o=#Xf_V&z~A?Ak=~u zN;e}_bh;EL_m=Q(O%YT`V=h$<{+Nnrl!%&17PQsH&l}!Q+>4>$@Ad5zn;2!MwI{-x z^^`HyjDMvwQ5CS4^MM7{9lyYnp>ZCHPYJ7Bs$6UB3`FvP0#V=%npxQ~&^Kgn)sTB4psoTX0uj0xO-XK=tfr9w zgiWJG@~nrpnREnOAewK`LPACOG8n+ajEraS7Z4E&w$+oH87UX@Aqu zO0EkE8u`Y-Vu)FdkNy*dl$Ct_*ebTb@=mydl0Y3o(wc$mDtx?=6-axB`E2on<-H?Y zf!z5uO;(QFHobnNkEwWWet`4d-9iP*S%D*jG`Q$NA`eA@UZ@X#n=GVnbbry2uy-#~ z@>m2OiACNwSa&adQa!U7%07#>1B8l|6Gp4nXw-N;$M~N2`lkfA5f@lQ9XJuXMXI6&TP2W(lTwD7RJC2EXn{*1?<5N>@&qWC9BXt z+`k%9YjBjpbPXp-J*Ivr;n-ea1S;?>lk;VcYh!~0w{BZH*x6ikhhJd9+DV^?HkV<5 z`p4C=p zE2+lYorDQKxl)z`+{&xU(_dT}2SwF#+#;-BLFVR(h0?N1Hd78h?P0+rAHvP`UW-+;oa>a`rMFK;fa3h@Wz-NOG_ivj@5z14B7c0kaPCq*t zeydUjBow8A&WagVab4ai;}wD^{sulQ70|#3{$etWBZV(vq_^R@s!u55OOWp+C(Vx| zue&zT2@~wIa@Yc4!E*T5r2cFV99eTJ-s&7+WI*LmLe;yHf47hEBG0;fi2f~B84*Z5e?b+Ullpm? z+!&k)q3CNp^7M~IGj$lYFHN{qs9QgRf)ZF!Ym!`etS(!>Z~2@ujF$cq8>KksU_9PTaY-^?$s@hF zgaQ9e=Q)LRj#LSG+*mX&{6_!qJT&nFPycz@+q5xgWxLsX@qyWnil#B&^W^$G>LsvL0N zACI`5Qn}JfrrzdJ@=0+;6&_4?G;w>{1$61l@X=^L=Q(&$8Y)xn_4Hq*f*u=N!Y7~p zAOX83O5&5c8^)|_vL1ZwI^`jvf0WvsBk7>^X31?TvZI-l(FIdAaD?&oeM81QY^<3$ znNIK^L52e}unL@5>NLPRx7^x#gXp1-(jkcl&22yf)H9v3*wryO4d#ef?9fl6DHy_e zHb(;Cmwtu6=J}cj)Whl>uYsR6G-;9Yotc+4NGw4aILb#Ns})(C&KPVb$_G)|XXy!- zt6mlxBag98GKExeJVQe4=j5Z?sdaK^Bq1Eua+pa%eL%W%6~zK7T94*zg)|oh!v0hra28=}@1F-TN&z1%+JDeIc0c$y=~?N{X>qp`~*Oefc>MBcrX zN@7?8Y`nmcCjD~fh*rrr3r~pEYxj@G)L_0fh`OIZ7V$qGna3o0&F-t2epIl7XS`~yin3}m#s zSELe{*zHf^Wfat~(w@3$%2{OHi<tuxxxK2^w z6kXKi66Sv2+smDGIJ(ioz#jpIt(U0U6+0D$?eMIvn1K(qi3R?ExzWl?ghOoN(4+{w zl@gCO4wem{8;8!;<5O*fPo+bL`Y@)D9NkCf3&nW9v<`wH!@VN*1ZN0P7~*?UvQz|> zCk-X1#gPzC2J?q)!q3sGCf2?IPtg7kBS750a|?`vNLTr`Fy~ zV6DnGGTdyVqGBL23w8P7e?$?GrA7nXSZ!Yi*1|;LozC(;(Fw=5LFpV+(QsU2gTe+Z z?b9&Bt+Lp0RN(;y7v5w3k0u7NoBmf)7QmXpMlu9<7g4}~7;p9j<2C0gxQvIhU`;Rt zP&D*QMMNsC;)%DPZ7u7G%!#3YSFB(w zC*v%z%!tT%gK)H!Wz(P(D~DG_#n_|Zc6SEYs`P&1GGowRrp^0EmnGc;zJ3V@FvK?( z+#sJ!S$`pAVF3NcV2RJ3hHt<-Ilb<__2(MZ@yu%& zC0{eA{x}?J;yiavfX3r%d4?*uN;Lu0WkT<|AH{B~66RBTp&zZ^50LS-ais)aBAa=z zymOsgd@Bn!LAB$hG4VXmK@Wn&KJLGLb~vtrMBnb1f3p17s}ecRlY){L5&?sp(_>iq zjKgYj^Fh9x2}5ZvUi(TvFk$Jp)0FP3ofhwj&O6KS^=Od(=K0JFZNgiiagc*8iPV#f zsFr7(SnN0`I28=7kzG#xfEpL7Yv!PmQ6}qSbtS&i*}5BRSLuJx+9H$Rh8`(E-NyPX zsmK6#m76J|jX73|;tsu$ zE-%~n+Ymx?Wguz;Tq{!|9fX9%7fK2Av)Ln`JMlakTW#0&? zAYG4R_SS{k0YLIj|83GSb8jL2%HJ>Hk#QR&@J2ArJ6CM9B4t0zf~)aFJW zF~e|;f>p_CdwV|k(qQ+i)?0Tt$%aZ323bB&xh=JCiCZD0V3?1xAcAn3_&9y+(q9ZW zNGyGX@kuhDD^@sLD6*^7mO!=r{2=AxKatIj}2db97Cw%LMW$4t= zUtDpdB7p^39`hQY_oUPXovf40J5bQBIashcM${#CW35B-s9)Yh5XuAWTq5BBL4r%m zK@6uVRXh3J7ALF{xU@>>>Zcaw2A@%G^Ip0+_?S~z;h*6|O0F^q%EJ)ahL}FWlHfxp zPkOoPX>2Oj^Vco=YY~+Ub{UJQxN(}qH!-%bIgh2S?EnRAefc0p2c={aZfSMs^Pcnl z=$`)Go0M?JMj^Q|te*Wp3s}O6XNlw0CUzz45sa@`O4sL_Z+v}u*IMc;&a=xZh(!V! z0CVfDaqizU$sk~;|KBW`R19s!A`-OPBhp)x5uo_Ns4}M8py0LTx%tgPU0~wIOF6_1 ze?9Upiq&YKAHt<2n*Z-hyi44ikE`;Bj`}$HVQRZmx3i(?gg$?`C>Q6)Hx%i; zl>5{t{eW*wc?o1~QmY9|0$tfl^`1jb9%+CBnVh0qWEPzzUUL#9^Y{yg8#&3s`>drf zZJPB?xu#)Nt3zb*)6re6yjm)6KdZ3LwaMk0*XHnHNldz0ExR(OT|^s>b+n%ymo`rP zs;NUi?D2&n{JA!Y?_$TUu#pYRoe_hP8snip1o$r5`%VwfnJWY(cWdK9_G(Q6$PF;x zUVh_Kyzd&rIM!eb^Xn*DXeYtB=+=H|Os_r-D#>+&vxEU!cjbOnapZ(lvp(1UGu;c8 ze5w??^f`4J;J;}SZ4AC=i6hPya^Vvr?rdkg7{uVkrWf zz=Gc)_fNo|pJ#;XZn$3K5=bN7Z~(MQpQV|IwDnNCG;*=m04muF|K0Ru`yfVsYhCBm zL$CBC#%tBLu5hPOWJ#?IEX@<>Om(~gl(t|`NKTOB9}RTw{%9qB|HylcA;&HI4J~qD zyLK0oP;MT@MGv8rPyteQ(~-xD{G$FR-j#KXC&AH?6!>3}7xdPN0DI6nS?Wu6X0cfr z5H*Rbw8hd}Mpd;DL;?(ns28@#@cZZEi>#2lrQ&}^lmxRjgy5&DVr;l+#LFgY|ayy|4R6?rGHHkZxj;XQuZVnQ<0_0|o@kgDQFjd1{?(6 zImVj!lejd8)**b4?r~P{CqT?;#YX2o6fd1?{5Bg5n3gBZdsw1 z`JR1?HxWB3pf4UslY0*&H7aT5+Jx^p~?H|yp>3rw4 ziTdYw{wRK&u6rw^8j&6a74gK}zKm<{%CUI1%STvrttM^i&*L_vX6S`>Nls-C>sW-L zkgR2P@L^mR0CU6Ho*FNs3v5hl+R1!I0nn3U^OpZx4wLG~R63q^;oLjt zMch-g;EU70OAa!tL#|MVa~}C)De3ucN$28zrJEikx_eBWD=}iS>;tsYmy5z2JD9gF zL{1I-Ua(qCtUy#=h=oIj=>Qn()~zBMB-Eimj;=QXQL-PE`F2F@7y-HKU zVGTmKy_Kwd=;91t>10WaU|)O!RN$jg{{k5-u#7km*J=rqL%~UZVs!vADz;k2WUf1h z-sNf`A96N}b*$&`GaK|E32enJyc+R3S9W?$#Xol9VO!e%gmbM&f;_ykeBz$UA!ydT zq-c3pBf1uPXlEzI=-Es~{yjTAQ+ zW@Xxd$-tiNsmcp5h3^Hs zAnc>6YMExyb&h-flah5I(z#!Lt~(xpoX<1v(P06C0oVGoWb21OkJ*?kY%fMQ)?`E8 zuCxuBnpdw2NKnDo_&lvL)i753?}cE8-m zsYUE#$sFVugOyM`hW=Q%Gg(ICR~ulOQkICBc^;6#j=z7tOvHT`ZZ^Qt8S!V5lTw(D z110|0vy2f~^o5YR!X0vjr18ke4ppMF;gQz9{RS|4=(gt+EBKU%4IZMSDpxM!4Z4`M zsXhX7B_ku+h%2lOh+QdErt(#xk)rH-NgRFcf}{KS`ch@%pFmfHnba zeJkp)cbw;|u>k8#F_&%97d%&V;nyC1uEj_sS}G%$t&Q8eRj!wIS44lM=DIGTDBJQi zS-HCc1P!<{+Z%jz^&H8YoJ5{eLs13%nI^DCJK8J35*`(?qXbvvll$y&p_3K!22w|n zy_(IQq%*NaJKLabsN~JL9b`xX_N!=ZIV;k7<9!+wS1kVj=w0ByuPVLBF4}T+DplNc z@c@8r)>BcRxjy>nkuP+&M+8xkrHA@Li~wq=C;I2LyXgF6OxYpqe^)qyTB}tq)mo>jp51bx}R*u6KiKhKA<2=2C+K_-aRKFZ^R)EP&r0PdZ z(HvB2>yDL6%{biZKS5UIuK26l!&9j`UsHQI+%K$or;b}i)88_o8CB&ZPSBG)B^hpBZ?un*c+7ko4} z>d&S;DHnefh{mRCrz4p`nYS&nNIQxKdY--q$M6OyQdE>1&5p?l!NXexeR5T=68t!e z%_MGjk_;COisEq%A62myn||Ze`ni0_JkOUS%C`=Nypb5c(M=3$F;|by{7>Qz`Mjj| zXD~4)Nh}dE*dP-uj4D z`gn|K1)31*}GjWg8x2t$Svh1Haj=_M{V!@)sko z;ip69V;%_0uo{QWw690BQKz(U@^+ zQOPO)AJ!c63v2K?;oK*OD?Y}XD^^qdc3+=+H7d4ONX9c^d;un&{T$GJeOsFGGzYDB zQfE^TDk3M&Up0_(jYNAtqsiW(BbZ|bHgmhq2tnpS_ z+}LggatC@TF5TJpku@m$Oi>mRXy8^59V8^yyB3EtARDK+qgqI9^gAN!ro(&uRHAnJ zSVKv+pWV)lt%k#10Ex{hg>m@;3eRC=t1+Min>-4AL$Z?hGFDQYU6KW~DTw7(oK}h%ODD0Ab^ds-9k3D+q%TeDZ zoewN9@R_#SkgS$Ib!V<5wGY#Cx*9oi-vj`!y_?Lb#!<%84 zk~^ClC-HtQud}B48)CF8CWO!aAUFw_KxGJ79hK|)N?V%9GUAsPC*uo0a5C2%7maN# zYZKZ_x8cBn{E4Jy#O-*4HgL!QM!-~xbY&J&@_UpPeZ}7S(S$kSsr9WLVZ8!wyT!ot zm=6r~rqgUz2_$z`0pYvQhy`Tw{jy}WNW<=phXNALBvRw|EUY8pXa zc2GC|BR`dGeS279=lGbpY9*!YST$96lMhWr^Rein&381pU>vsY@m&KsMv|bfX-|nf z4IE5{{-*n8*LuzySJlt%M&2ZrPXE?KZTA6;v|eDGV#5@vRgGH|d|L2vzq!$$G|evd zAANLC!W}%`UQsgxq9PpLY~7H3UZm;k^eaEv`#LF1=MdFspW}#luaauS?CS#KbR=wI z$lgO#s=<`Yn~X|dtEQ!uTU8>eh!At!05#FQ~Q2x%?}1d3j# zmw(V5P^8TQF_@g|u?>(W3Q-Z2fRVFmmZ2i#` zCLGH&lEMzbs-M`tLPwt(`UIDolmIsYkY|=KD2GRn=kU@g`%!>@3QhVv>QEfz^Yu?0 z6<&iS7+Yw_aQXo{Na;t*&@M}Uu>Tu?TkTBy*F8lvPLs=r2@CfZ`rdD%nMMsrjkti{ z)XBd!q7$t;ig!$WDZj;2q5zTOCO?_aJa;Ap*I+04yq7lO%okJnGBN-m2#|$4&iOZW z2?(l?;&c~5utXT~z1CPavc+0Z8%(!FdMNa~v8+b| zhfUnKcIj3v8`z=}Gl3Wh%}ZP>)$J@(O19?pJ0r&IZUM3#RRz}BW?w&^nX*nI2Z7f) z)Tn6}b(v_Hc01}qm+H#mGMp7waABErTzz zJ_o(fyaJWscX}O1_Qxw)PN`bdY>aH*)%R1OonluEw3$nRlJ=n3;h)>z*IL@IVc-Bz zY4clL04q$H(}~%Kz}mF}X_=d4gRf3xMa_)soj%Tke-*#cvKE7POR5?&jk%*x;+f}^ z?~_%0ASAwiB*~Le(=uK6nc@$9=ZzOfi_(h@rcmv?z04@z+zk>C&EB!Ap`x^X)BsuB zNsa+SjREOzmj%yRQJ($;?Sx2UApQE0H*M^BkCcBblNe-#26PpbZOKaFJ zo8dNPRr|ObE;pF8$Go@nEgze`{m-Mo{OjM81~7^XnZq3*?Q@xt(`($Myr7MmCiJT^ zFYaZYg8_8WFN|m&Lq#OfLL%Ov{NSd-9i#?MX~Rdj7_MH<19B|)b&yf~MDGQEU#(&0 zaW_SVHxGUMAynQG(&onHlXtZusJ(P>wa*1;HF2Ekoz!M9ITkIaV9%e-S+;dsfWrB8 z6kOXLMubFNuLs<|^Pc&}0XpMd4-Yu7>vS&s>UTq9O)~A8LEvq?SW0BVD+o+k(=}=w zJpf=%6?#;ToVS-r56;&nWFZMeCW3K(+YU$Y`H})RV})_+5+xyx_beoqg-CNw+buJ( zoxE3OM`5`Ho06Qv8Dkc(Pm-4xC8b}obroBF0uTm;#YAI5G{`x}1#!J;$!K)SSr5@o z8BU>yJ?d4y;hKJAvuG7rHfcfRCrZZp{aht98CO%RFOAEkd>V_}{UWwH65v`cnU>y! z#+IzNq~{8a#aF?HENp+R5-wI9x%>sGxsCl@7qPu7p%U|bTfI+1x`wm|d{ChLF+YvZ zNlXL^)iU}{bgRLsk4tpgZIEAf4?$X-zBK5MgM_}K+R`Kl^eHpRucICSu5Xw z>Ae=X4@h9qWl!59-VHVxZ0CD|@+s;n+XU!(p1v?V9Uk5V0*1Owz`hg30|rmmm z4*G$Q(17%b%^9MH5QfAMC!!UZ@5GVF=c1thV`9oq<2*iO^s}x#nn#r)Wv&L=u^7c1 znROXgVBMPM+wjz5>*W_21Tp7s1L47eVA%JKx@XfSAWv|nx)=gdNi&L>d%MY{Vb#xZ0B|)%j zOY8$FzEyCU>=7Khgz8y2d};)X+0tr@XQAAfv8DUlYieEuBwjsWo;wZfWiKqq<5t*` zH~Q=Jz>z3i0 z_+xL1>z(Pbso`n_&DeB2(K{Pny5sPsyQ8l3=sf4C+u}sWK)0cTQII=;5yq}_RW`*V zFj}Q;YY;Rg>=QNmjfP5jZSB@XfZ>D5_6W4u`mMSWbJ%8CmYa{v{B6*D=DVTKFFJnK zA@nVEim>f~V_}2k?T=Ts$g%6#@a-{_$`4q7-8%iNYKSQ`O9#427(O+`QHH*sCD3~^ zUy;L~6s`a=#MK-AC)j6_j*6lFaE!!G$?H5Ajxr$^Peoy=Q3&x?;;6W9HMfO>N0s=+ z5E!o}RdJkL)wCkX#Q*8@tmG|^Gr?y|D!9ZTOh_(~91{Y1Nnc{cG;TCNlUPH{6suodkzFNrbD#guM!dWqExmhCHOYLQ zg+iO3_l!q|{B_l4c(5j75{!A5Tv3g#J zhAs3I<$cQ9)!QTQSc}K8W2!fsl_7Li5$xw({uS{j!;TR4Cds0yPWFG3f9o{uHX_ZO z{A_P|8B^^jpY?&Gd%1cet<7hozj}ABak_pOpa*u{PiesqC;jYkpYQnRh=2HNhRV{u zmD&8Vq7qT})5i7UEfwM~55pk&c&|Qb?2W-36u7BfEKj?H5!@%=M+i@3%{q3v)8am2 zCKF!JL&|V{=u?=i$4o>o`}B%}#{Y@skFbny)8cRP21lS3P=eAm3znL?d0b$w9mDJM zGFRyBzmAQ;@$EcwG*5+fzl>$!H}Bp#4gvs!fo!?2BVBFZQD30fD^{+s@KVxq8P_qn$S}K*9pK3g(H${?Azsbq>+o^@v*UK1bv_%tj#v868k;HEyC0i~sZ|zy@;-+$Fa$!2G=GtB zmrCdJ|Dc(sbbMD^ZdGg9xBhJB$f~`CCeMU$i~!nrmpFTg+>m~O7fIe2PiD;`io)h2 z8Ck4ia#O8oM14B6o~v1Id3sG99&F^bN(XO z|CDZk^IVyx6rlKjAw&#(993>+Vff%(@~(r-+Y?xCLJF_wrNe3bGz2Z}rgSc=ylwO% zLwn*LLMm9FurkHkr|@#wPLrvSOmfhtugqq1XorBL9bS2xpzUQ4N5V1_cFKkeb<9d6 zICy73>FO1L*Zs`bl`Ykc)o=I>Sv^y^8#i1-zLpq!Q}n*i8z&=98m#VPobW*JL0m*a zch{dlbalNk#-UYt3eOCs;z0MNN3EuP)t8@oYUW#!-e4SadZ|YjPNhB0CnQNDJn8!@ z@RXz1{)O7T=cpRHSxBZ3{#nHyn_(lDX$;hQt}aNVz7p&vKqWq z)oJt~Sue4qfmv5Dc@|>-YCmBG=M)e1qO}oFsGuZZzw9@Ytt;UQG6Tyt2We8Vh7`SlBeyxyH%W zn0YaqS}Fd9Cj3l0k{`Ra-*%`MOs+ko)_zuFoc-jr*9~qu_JuumU@*ZoOT@_$)ent8 zxe9oMM^{Z%B)i_?-C;7~d=^&P!Vw`yf1gqH>)Q=$RA>#ToSLp{Te7YXBc2i+= zR;s>wZnnW*nnsHTI+hpl8kudTUy(o2%)umX;JcwnUq@2i*(@*m*Cses48-_k<2 zI7MlM%xK4-`mk-42aeX*w);edE!EZO&gV;mSK<7_z=;ir`D zs%ChvuvMGy0Kn9miz}NIl^dfFN4F0%LCCqp8qAr`*CjNTph|+MPeEKHFJK*&_aVH* z_Oo&Q6vc@{R_Y@`j zkS)&DH{)dYehQ0Sf7}YkgVjm&=+>Zzv;Q!LO=get@8Et-zT*n!RLz2WSsaBX8$*)UGXeB1`&a}*hwKN{J5wBZJY1oqf!3gtrUP-Orl1xaY9JZT!uG?kwl}B6pt}U^uva}G z35qYx@b=)KF|!h6F3sylmXP^5EoD#_T4uTdS}b2PnY4QHx`+stpzQteY+FF^Fr$7n z&Ap6H5a`G;829Cr1H>c_qVv!XRh0dPJMQAZx~8cGR?VBxHmUaxzibQzv_K?kho7 z5TF$#2Tit}vd5oZf-|T>wy$}Kodo18u9m0#@U~E%IB}4BPp7dhJo-qR@{=Y@^ocIa zfY?@GRJ;BmxHYYy;`gf6(^GFjX?EQkj}Wxs2vzxm4e5R-qoWuFoCiFX#~9&V)v$k#xs{GRiY34$q6!K~j~c^hl2oQ(V-wB; z!XuzNyav0hjeV7vo+t{aWeJcKmzRVnZs&7(%VH0H^bFWs$PhfaPk7RNd|u4aFOK_R z(UC5x*A^P?z?Jn-zPMWo)iVC)=0_%qX|u2VW=$ixVmq_I7!FW<-}jhw`SG{~=9b`B zJBjNKX`V8Sbh0K5$}%uGOmLdojn+KfiJ^LN-kA$F5UcDvD`v|GSU{9<4jiM*sY6v; zzOxrypxjbfh0on*Mp;~mR%bsP^)~mwGZSMu_u6FX4~2HGd+YFttnt05IZ;5A|HM_I zh!0s3qkTL1@+$*gNM$C)n|}<|rPW(N*;u|uS=9DeHM_Im&{d1xtZmha%zt-5j@$=! zZ2~z5!{lAL>t8Uq z+@FjkiObqBI2tGc#>XnIf4^p|!cFHX&P@Gp_&GYllNqeN|9n9C>$OTHSTl&2dNG=+ z!YV}Tx0LX>7ANGn&?aRV%+n2Df^Q*GY_e16g7H0jyRXPxuU{+HOy3r~|`=%&7a*0)!#U*%)%@-;z zKH(|=R||!^m3?d&UH~FlnYxofdGj>C8h3%;Puv}n=ot9`Te4q02xQ&`FEa`oq z2>N~B7~AW)7QT}*uD9?pZC4MR&xr~lg~QKqcTdWYc&OA5-JQ#cVz+5o>F-Mqe;H~E zh*0J9^_|b^97UXzrrh<>j(4@|cuR&s2Y}@bT!9}o>E@`)E597x^Bf>g+Kd5RjNXJ}@i>zvYiDC^68zwhKv!aw|y0?7N6!5BZDnIzAMt zJE~r=*8lqFpsTpn%l`|1>8`bWy552KgH2;yddj=LmLRPq#dUax+Z=0>$w59SP1lF_ zG>^0GY!I|&J8*vU#%49Ust(5CoO3f)T_=pn$aCouBSb8tgGi$uLHh2Ye)N>?dIRAJ z{0YVjUNfcu-lOBZ${(Z95%%W__J$K>`0Sx>40@$(-4Sq+W-QTLdW+zo)>na^?CVe< zd3)UQR1{|EmM&63tP9dH0>0r#{I}Q$^{1N*R2G|iS^X-*iDdmPji~b6a(yg<@~W~z zinDJ=^5wpcdevSN$w{<7)p&L2O4aFFdfywAy!enYka+LZM)mtyzAr#D?^Y~7U2`K8 zFr8RN84X+Y>Fps&K1hHQh-953b!cssubC*5sbYf^e3#?f{^z|##L#HI}hPnDtX4N-iw#L6exaSMUs_)T&JMIp_b)^drMthTO6p=)DwF_G?ffbW?Se z9L0L|nPB*J&kGWNuvS#18W*q)7(rf*JdGILA6@*-&> z%Vg&e%OjGTX9zC2Y4(2x+#{IZ^3f?+f>cT21Cvt}Dd!0e2ry?gr5hcu!*QH$q<)Kv zM)rHzA0*n>pJ9h*!}%qjtt9>57mla|!on3VOE3h7#FjmN%o~~bL0LQ#%rv}m!YdqOGrIgP%&O!ahB0{&FPll*a)FQf5B*soq zZ7XQv-@o%2Hb!QAQ)@%d;lk|_oMm`)GOu_epu?A#b8Wbaj z&x^ve=1|5O!}z|tX3@-?p_Gikws%dqUo`R#uVv(sGS&lFHYZ@cP|57MpjsjQd}pX-eI z|1Sd`jGXBSnQuuRr++0SU#g%p-ZM1uRUkAP`UMNhEhwL_1P@|94BqwBSP=R$0DhN8 zh)KY5b2?JY2g84QhiKHNNe0zJB}#^skv?N2u3$Vcte~vMmF){0jbcL!KXf3UsFNE) zWR<5a_w_hqkZ5vN)@DJ@IP;+lz$FH#gfaGJfZp`MaUbvb`R9u>$6QS!{DSX$k^wR{ zC64p{ZsE8@j^X1ovF*WtI7}hXz7^ouOq%*4gAL1v4^mWNGLubF#*tvy_0gXGnk?m> zNUibw*P#)w#85cjdn>}Y<8&!V>;$LiU!#++N~{}n+{&MhrpmF((nKnof$lIrtQ|Ww z^?^R@%A^};q*W?OWN9K+w?Yn2nK@1w^D2teaZlQPa4f@4h{8eWs~X~__4F&`RWX^9 zGFlcP0bIToxrNo+Vm_w|g&}V^8mM$UV!M@pOs^lJ$ZN@ko-`U)Z>C>M;I%NqI;CVk zlUj)mU}TWT?8Xi!cM#7HHT;?@=S$~in7q^a1|pTz3}Z1^=X2Gjp)FmKCU&F%EMNmg zcjB3orHNz+Sn*(ydkqUG{4Gh$;y5YLa<@n#Q#GBHLbZ1M51s$QV5(_Mzk=NKyUJ9R z`d6QejNl_`0x1zKfAv>dG3E&SCuMf?(FFI21YRVNZkE^~{h*;hTPa}T9b)m(V-vb}{D&UpiWu#Y0X| z578>Q()z`|bK6qMRBKlr%-2ip45m(S3Dcqw8UQp?ihLn39k1I_kj-l7yrv72Iz=gk zhS6&{p`+tO`+OfFdy!ELs4W+7UmR58#`CLjSq9VIKd@`GEEcYBY4bzrO34fuI=Tf{ z#?|}3F~g4@dVK+$WTA4<_`YKb|8>uY_ z$Nl9q+(01|w3U~8eaJmYKn4z(5JKI}ab2s5fTMey*mqfW|nzQaj{_+Rs1D=2in9+ts1>88a?Zbf)8X7JAIju!b~GI7KU^&> z(T8TTw;sAGTDL$d@p>cPr(7nuEJnOQ-J{fe3ASt8Q!Mt1S6;8T_hH~#sA9Sl#h_Tl zD+UpjoH1=I*v@03*~P|K@rbvY-qv?{G@?el>`yg9jGYpkcmVfVECwLtK(5v<_RBEi z3#|}zk$?md2`^y2cAtFdS_ve-Djh#1~%&(-AC`P z(|O}&LlDr0Q?35KR&E6D;RYT~**7d|n~hw(Fh_JpFW=MN-KnGC0`s0dg`K2#%a5O; z*(zyeamV2$CvCUINrtWfOgW#^5Ccd4qrQNafT#Zw-JFX+fM$QzrXZ5_P((9AIIdq> zAcbF0Xd(q;?osWR1LQ1V^(=gsiUG|zOihnO9B0QeZ@vD3fCn*S2&o-(ULS+G$8^5T zY=kNO+fG8P4X2agJIN{0z`=}k%SB*oKU5>j-Lflrhb>^{u&HhY9wa(U5`-Edjj=ru zUGHVgHvpxG*TT#T5fAp&4D~A5(;=;2rj^SY?(1+TGox09aLq&tx!NH7A|PUBQsg86 z-?o{$68%r~jE|Nozs8a$p~M1dV<#el=NLN{*wYqEHbZ-=Nea|M;n~$4Ma6u;6?iJI$4Dmk$gVN?n z$J|~cV|;~K*wArSfQT7jbNZTc1y5JW=S4p-3&{c*XXQMwp6rl?Swi3TlMYggfEz7{ zJ%6kt@&@G-EKAd8ws}LJv&>^+20uqEV~FB%&8xcM3$We=K6V-kx{P@UT`?N4ZzLOs zh@+!{pBW}<{yb4$R9?->U^?Ag;s2H-0OAqy<^{QB$SA^5za2I0jTX3~SF-@u^e*js z)S7Lvv}@1trZbrfcSs_%*&7P7N(-ftUwki#^DmX%l?r{!L62d5?&S{#Xy1J~!tA<> z7OvK(Qjc!z&EWDwPsbu%H1mW|sF9fq$mu`1#E%fr!nRllJ$S#s2KZy{GUjt>rD||? z23AYwym5_Pv<0M-?d9ZqFY(YEREv|&>ywm?_mcCxUTlzf{><)_oJ@bb>ZmzMe#HNq zPP;=7za9A%oMp^?bC+BfHTsdt8$(HRAg0ft7m$UaQ{wB26g1Ia)wxXNIJWF|4cCI9 z6wCD+ke87muIVugb2!g9*&j!CxAN*3Pp6?>+q`igan?sf8HV|V{~I3{1YvN|ntFW7 zMAn{>;(y$*oitG9ChgrpR^ri#_6JqMFhOOM!pG%s2qU@8y>|WWFx}{jP^@*Uzx00J~YhUmpAQFVJK5%%L3#21votrlq&h zTH}S8q^sJffGY^B5gZmk)h0&Q=D_~iP%R5uJO1o4tSYH7G#gNi7sZ4IO(DBU_yN0^FWQTd878XD0+s8 z`ratf6!$1$PL0UYyq)bEG0xQ6Wy*c?*9g0!V90=J^qw&!TWGURRLMn%4YO?QVVr1t z?Hl40vqgQx0wZxz@ZaU|cAYiRH?&aU`bs4rc%AJE$c3W!7W{ZUYGK;t2UW-qLt!h3 zeb1Jd^#b=9a}%*;=!VioVMc38$6~^sw?cbHZ;)d=6P&A_suYfNvCBtKOXA_n7 z-^ihcQ2i<>>b#Eg0o7HMWC1apR*+sNk2Nq&jwbP4ILDt z;aG&%)fRk*wvRRNP!z#%SD&G{`QORQj_r?AKIw1Va&>u&@9vVO501%$0Zo%&I?0jW zSD+GROnLvS*!84`bw8ND;alF}IytsGjix ze%lsoVLZZDkU@=kYlK8r9U9!%YZ`XRMOtV!cOotk>ROL!#r$v9jKh8=!qPrOm5t~d?2+(BS=Od}Td4dG#A4B%gx03SRmsZfVDtjtsWgM} zi=2aK0t#)}NGL`M?US^iYMKw_&>+@CiBzzFZ?`dh>e+hHPC}q*35xySZDHb^LeIV`{XrAr7KG%)fE=_|z zs3>1i|AhcUQ5}yovwgP)Y&{pWN4NC@SXb=O**+OCRx(o*zY?GObx$K_5kDFibalUY`^N zNyz6LBQn%mJ@%3uTjcdL@N*nGV^lW;M!y&Y>nV&3V_&WDWmE{(d{SU_#3J6a-uU7~ zz)(pq&0Nyf`B;{mOwJA)C#`rIo+)_DuC`;50*>#nY7tr5kMni+) zLAoN0-1lA7FNdr*w9}F=6cL3OQ%WehZsR>Rs3r zL<|JsOrT18t)250Z44hP^gbtX<6R-XA=!U+`S#ya@Bf&-wtY_3LT7dXoMaO`WMLv) zD*2irK_pD~q5YNd{)f!n=!UC_iv)xTvv3`SK4L~92?4$)$R@4?AC9ix18*#w)AVp* zL>3v|W9V#&g6{&>&Y@}Oed%NDNeAJ)6w0zQHJzqOS8|a~1!oiYZRZ%>-8qNGbtw^( zOii3Od)>;tXh+V*eVA5~UmBPPs9~n5F(^FVF(vr&Q5_?AMoE6Wa>Lm0Y0(sPk9lJ3 zdNs9QcNNdrt*qijq@eQ4>f%s11@@?;YZrU|76=f}Ia5N}w`~swA}+OfJV&5O$QsG) z0*Mnkv(uMMpPUnQ;XzM44PVJI+79eLnCw=GLSU5E0Vt2^B?Qe7f{MVIC1e3od{lsv z$YWju3{a?;mzoKip6H_zDe@Qip>xq$P6&(7hBB3>Tq|R9zp=P2VQ1r8buBSg0lM2t zP@S5J9^>0heI63Y!o93p;d)cjydksGZsqGV+T{px*9{FLwKDT-+fy8!h`hwW>0)9w zw+~pSMLHnQw~M{Rs^@%ps|SZ$_#~UF&Nck#7R-$k7sjq8;?|U2eOm4i8gU8ZnXVg4; zb_or~vuU<#m9U?i+#^B{xN(~iPF1P(_a;gSXi(8dD_TDo_#5sZ^bT<&jFf+bO6DUn ze+pqvb+279=VzVIPMCJP$f?@a;g@LZD-XW44ERt(9rL(MGy3!fx|DQP$whRq-^s&b zl&qAL0;5k-$21}+-q077AaE)jJQFpnrQJy>m5HE@d!;t|$`Kpg_N99bx590U?0g<` z5z{-g-yRT&4{%KkdG@>na=7}eeE960PnC%%B^$3Bw)Xw; z$QO&k^DP*A`!=17Oa}-xP;3cnXyne`AUA0B-E_P__s?+5D<@+F`~pxQ5cCRFtyK>X z9dg%zzfocjp1XX$&=>ZJ{=tJMO(ziQKO@x-j~+x~y;Ey2SY%XRf8>T_CY;0_&3xB4HMjyl9>tV=w~F1fG;=YK%H!q5k8H&z;j|HjfS#fBxYOouo-fIVT)p7X}W^Iv2Z{#`O3>uJCf~b?zx1L zLq>VK>?U~#{9S8(C*+U;F$>Q0*cf@UAOJ52to|ybTj0Ab`{%OCv^+{$p~5%@Zrf>P z9z0VE_=fM2K}6PS>^NX6loxjFL@9fVYew`bm#+GIh=EE10Ld^*=1I-xO<&Ng?Y2Y< zo`y#eX&O1c!roqp_$cSf!1{4XWnPNu&i^T@QG3&Ti>{bG0yfysGZfTe^>LL=Y1sCY zD|xMgKFN387irPu0QttZI}6l^B?!?u5wt`_zs!S`xu#!Hc&r4W)@qy&B^YC8(#vq? z*B1!7m#M*`1rmTJL@Z&Vs=GX;z}_pnv#0>-#7^+{J1(SZ9!Tg1EYG;9J;%W)JUc78 zEr!iRe9wNO%8!B#XVy{#ARP!lm(QWO^8sj5-GT`8O8;}MS;h0>rz%3gXw0(br0MgJGBkl;**j;-;LkU zt6Nz!hob;gb>zZX-3Sa%8{-Iu46X{~;Cxz}O>*L%|KZL8i zz>jTL`Z=LXU(zRXSy`bl6@8%C9kUl^mkjHW$9QY;vzzfh=k!a?;!+YIO4s&R0oNJ> zbADBi*ktG)OxnDMtYw1C@`)km6R+kNHxavm*rnj8QdjfNV#f9HkT)Z@7F;ywkrwW% zN<^K5n?)C^gn{igBc72Grh#r26~`1rDrK7UXfNR+y!b=mG0iqWtBtjoSD7Dh-59Vw z+vCR$C+=lrHz{=(JTY9mDIK;yKen-8D=FXQ54t9vZD=Rj$)r?o`67AohrLR2R>ui% zG|*Fla^A1DtYwQ!YS$KeCPl%ZmGXVJ;`87zmHhXB0!Nf!!Z4*%FanvflAx&5nCORx z$UYHAa~#6Vx7^z72{Q#bZ6ti^4QU;IJp0-&riL~v&L|_RUj{b^_(-UnZfSa>c_Yp3BM^U@p--Q05B;q0I>@hWpS0wN?7le;m>LnY}HOWyIrDJd(1dz7yFrZxBKfwQ+2(UT{0Dc6{OVr$Z?P~63;!pct|m}L z@%|;@YpY2V-LX|QRZxGF^V!Qwlr^wF=}3*^fXsD>EA5~=lVLEMla?nqToBdAKVqKJ z4+9o8_%7~Yw;slL82F2t%>K^JBgiJ=mx87RtV|6MBL~y#rnh_lrEH{?vf-0*vP}_5 za&w-^hq*2ZAU*j40%jWjX1#^0qs^l30}^ju{7&ld6eoU8Y|y*-1X%9q8XM)B7t7X( zxY)R=3)B+Y!0!zhMHfZaf;K9AU33NAOK}w_V~2CaOeD|MUg^v3%QTnCfofJWuzNo@ zLm+zEu2H@m$RidKGlq)WDv->|d%pn(gvv>HjeTrK|F?Z!G^#k_^yG~b&#fNC8Kd`7 zn-5R0wKJ@8QumgYQMTdxh|aR`3(%4EYE%4@b4|M0bJI&(7jZ89QM zowJ07SfAxY;3cRXUlcub zLP6DIY%#xDEiMs|PaOOEGK}&C@H%b&>udM=()JU@{W0i~Ezvt4=fBAEIdG%fNrL2# zg+4Q-aLk<0Wy@UU_x-rWlI9-M>Ux5A(DeS1-qgn6(!O#|t zTYafoTw%VMXQUUUiEiL7Si0=&yXa9kc6d9^jSjad3`%-Yf8zg@?Q} z>dsjM@BaLG<%k!HD>u_p(by+2~pnsdP%xbc!BARz6dIcTYx`kEpco_r7&6T$1 z{kyv^*JcPD5AmA`T@>d&Cbsq~@-{6`00GyTchvb_6kk?I;<()2R6Pm{x{w-RmIb>+ zXy^?6w{UF|n3nrQSN_Ije@~e0htJTM>cs?7l$s z&FW5U;WQf(W9A_vgax`qAk=eH9uU}T+Y<3WpC1ZgCq70ep<3M7Vbtbi?jW`=4nklI z$vHMhA{bT|V=pv-;>-xyynSLiMsiGOl`f;+N}2kH3P)};lIz_isVwHenI zh|H;@#b0!g0r9Q2i;XzBh6V>*cW0?#dbjy>Y$&>*F@+5$^26vN0{r?cQ*z<3`z!uEd9| z5oOS9aI8IMJkiq-nA0A6B68Hx1z~egUYPhYT#VXk3^pL3;vd_2_#=3g5D~3@!geGp zVp4-_SYmd?zY{It1=BWK1Z*M9o@-x;Xtf>Y!YSOS;k{7o>*+>$3V?-XKa=DNx#QS~ zz1LcfeP7ZD@zYP4NGQtM=-U@ZA7X+O+|)V#v`@qrjpHS6(05y8c2>ns6!NM7MlC2@ zh{}psQhZNd6!Mj{R%NDFqLg`Y?ho`(+0pCCp?lhdhJ_2=6&q!G7xNZZLb^Z{1d z$S4F~B8-49n}iz+t6Buj1To3+oB2Ml9HK)xr`7aqV!vv3YJGE~zj0A;?*J8_Gr$wa zd&|${Iw&AuVCE&vHT&&V+R%VtjRM%~&*XVb=G=VvVuDP{hUaLu;42<;f0ZhsU7vhn zz5oZ|SPiH-`$4BRX_AHP;MEw~lytqy#)K4U4+Fh*Q!FKfs-|r;+W$%tM}n*`M<66t zv&NM%u@v3TNb#aAelSu6N}vD$00000 c0000000000000000000000000000000Kr;4x&QzG literal 0 HcmV?d00001 diff --git a/boards/arm/nrf54l15pdk_nrf54l15/doc/index.rst b/boards/arm/nrf54l15pdk_nrf54l15/doc/index.rst new file mode 100644 index 00000000000..fa896f98398 --- /dev/null +++ b/boards/arm/nrf54l15pdk_nrf54l15/doc/index.rst @@ -0,0 +1,134 @@ +.. _nrf54l15pdk_nrf54l15: + +nRF54L15 PDK +############ + +Overview +******** + +The nRF54L15 Preview Development Kit hardware provides +support for the Nordic Semiconductor nRF54L15 Arm Cortex-M33 CPU and +the following devices: + +* :abbr:`SAADC (Successive Approximation Analog to Digital Converter)` +* CLOCK +* RRAM +* :abbr:`GPIO (General Purpose Input Output)` +* :abbr:`TWIM (I2C-compatible two-wire interface master with EasyDMA)` +* :abbr:`MPU (Memory Protection Unit)` +* :abbr:`NVIC (Nested Vectored Interrupt Controller)` +* :abbr:`PWM (Pulse Width Modulation)` +* :abbr:`GRTC (Global real-time counter)` +* Segger RTT (RTT Console) +* :abbr:`SPI (Serial Peripheral Interface)` +* :abbr:`UARTE (Universal asynchronous receiver-transmitter)` +* :abbr:`WDT (Watchdog Timer)` + +.. figure:: img/nrf54l15pdk_nrf54l15.webp + :align: center + :alt: nRF54L15 PDK + + nRF54L15 PDK (Credit: Nordic Semiconductor) + +Hardware +******** + +nRF54L15 PDK has two crystal oscillators: + +* High-frequency 32 MHz crystal oscillator (HFXO) +* Low-frequency 32.768 kHz crystal oscillator (LFXO) + +The crystal oscillators can be configured to use either +internal or external capacitors. + +Supported Features +================== + +The nrf54l15pdk_nrf54l15 board configuration supports the following +hardware features: + ++-----------+------------+----------------------+ +| Interface | Controller | Driver/Component | ++===========+============+======================+ +| SAADC | on-chip | adc | ++-----------+------------+----------------------+ +| CLOCK | on-chip | clock_control | ++-----------+------------+----------------------+ +| RRAM | on-chip | flash | ++-----------+------------+----------------------+ +| GPIO | on-chip | gpio | ++-----------+------------+----------------------+ +| TWIM | on-chip | i2c | ++-----------+------------+----------------------+ +| MPU | on-chip | arch/arm | ++-----------+------------+----------------------+ +| NVIC | on-chip | arch/arm | ++-----------+------------+----------------------+ +| PWM | on-chip | pwm | ++-----------+------------+----------------------+ +| GRTC | on-chip | counter | ++-----------+------------+----------------------+ +| RTT | Segger | console | ++-----------+------------+----------------------+ +| SPI(M/S) | on-chip | spi | ++-----------+------------+----------------------+ +| SPU | on-chip | system protection | ++-----------+------------+----------------------+ +| UARTE | on-chip | serial | ++-----------+------------+----------------------+ +| WDT | on-chip | watchdog | ++-----------+------------+----------------------+ + +Other hardware features have not been enabled yet for this board. + +Programming and Debugging +************************* + +Applications for the ``nrf54l15pdk_nrf54l15_cpuapp`` board can be +built, flashed, and debugged in the usual way. See +:ref:`build_an_application` and :ref:`application_run` for more details on +building and running. + +Flashing +======== + +As an example, this section shows how to build and flash the :ref:`hello_world` +application. + +.. warning:: + + When programming the device, you might get an error similar to the following message:: + + ERROR: The operation attempted is unavailable due to readback protection in + ERROR: your device. Please use --recover to unlock the device. + + This error occurs when readback protection is enabled. + To disable the readback protection, you must *recover* your device. + + Enter the following command to recover the core:: + + west flash --recover + + The ``--recover`` command erases the flash memory and then writes a small binary into + the recovered flash memory. + This binary prevents the readback protection from enabling itself again after a pin + reset or power cycle. + +Follow the instructions in the :ref:`nordic_segger` page to install +and configure all the necessary software. Further information can be +found in :ref:`nordic_segger_flashing`. + +To build and program the sample to the nRF54L15 PDK, complete the following steps: + +First, connect the nRF54L15 PDK to you computer using the IMCU USB port on the PDK. +Next, build the sample by running the following command: + +.. zephyr-app-commands:: + :zephyr-app: samples/hello_world + :board: nrf54l15pdk_nrf54l15_cpuapp + :goals: build flash + +Testing the LEDs and buttons in the nRF54L15 PDK +************************************************ + +Test the nRF54L15 PDK with a :zephyr:code-sample:`blinky` sample. diff --git a/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp-pinctrl.dtsi b/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp-pinctrl.dtsi new file mode 100644 index 00000000000..02b02bc8171 --- /dev/null +++ b/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp-pinctrl.dtsi @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * SPDX-License-Identifier: Apache-2.0 + */ + +&pinctrl { + uart20_default: uart20_default { + group1 { + psels = , + ; + }; + }; + + uart20_sleep: uart20_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; + + uart30_default: uart30_default { + group1 { + psels = , + ; + }; + }; + + uart30_sleep: uart30_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; +}; diff --git a/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp.dts b/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp.dts new file mode 100644 index 00000000000..1e0245f6cc3 --- /dev/null +++ b/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp.dts @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include "nrf54l15pdk_nrf54l15_cpuapp-pinctrl.dtsi" +#include + +/ { + model = "Nordic nRF54L15 PDK nRF54L15 Application MCU"; + compatible = "nordic,nrf54l15pdk_nrf54l15-cpuapp"; + + chosen { + zephyr,console = &uart20; + zephyr,shell-uart = &uart20; + zephyr,sram = &sram0; + zephyr,flash = &rram0; + zephyr,code-partition = &slot0_partition; + zephyr,ieee802154 = &ieee802154; + }; + + leds { + compatible = "gpio-leds"; + led0: led_0 { + gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>; + label = "Green LED 0"; + }; + led1: led_1 { + gpios = <&gpio1 8 GPIO_ACTIVE_HIGH>; + label = "Green LED 1"; + }; + led2: led_2 { + gpios = <&gpio1 13 GPIO_ACTIVE_HIGH>; + label = "Green LED 2"; + }; + led3: led_3 { + gpios = <&gpio1 14 GPIO_ACTIVE_HIGH>; + label = "Green LED 3"; + }; + }; + + buttons { + compatible = "gpio-keys"; + button0: button_0 { + gpios = <&gpio1 9 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 0"; + zephyr,code = ; + }; + button1: button_1 { + gpios = <&gpio1 10 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 1"; + zephyr,code = ; + }; + button2: button_2 { + gpios = <&gpio2 9 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 2"; + zephyr,code = ; + }; + button3: button_3 { + gpios = <&gpio2 10 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 3"; + zephyr,code = ; + }; + }; + + aliases { + led0 = &led0; + led1 = &led1; + led2 = &led2; + led3 = &led3; + watchdog0 = &wdt30; + sw0 = &button0; + sw1 = &button1; + sw2 = &button2; + sw3 = &button3; + }; +}; + +&lfxo { + load-capacitors = "internal"; + load-capacitance-femtofarad = <15500>; +}; + +&hfxo { + load-capacitors = "internal"; + load-capacitance-femtofarad = <15000>; +}; + +&uart20 { + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&uart20_default>; + pinctrl-1 = <&uart20_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&uart30 { + current-speed = <115200>; + pinctrl-0 = <&uart30_default>; + pinctrl-1 = <&uart30_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&grtc { + status = "okay"; +}; + +&gpio0 { + status = "okay"; +}; + +&gpio1 { + status = "okay"; +}; + +&gpio2 { + status = "okay"; +}; + +&gpiote20 { + status = "okay"; +}; + +&gpiote30 { + status = "okay"; +}; + +&rram0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + slot0_partition: partition@0 { + label = "image-0"; + reg = <0x0 DT_SIZE_K(64)>; + }; + storage_partition: partition@f2000 { + label = "storage"; + reg = <0xf2000 DT_SIZE_K(24)>; + }; + }; +}; + +&clock { + status = "okay"; +}; diff --git a/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp.yaml b/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp.yaml new file mode 100644 index 00000000000..de5ce29d162 --- /dev/null +++ b/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp.yaml @@ -0,0 +1,19 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +identifier: nrf54l15pdk_nrf54l15_cpuapp +name: nRF54l15-PDK-nRF54l15-Application +type: mcu +arch: arm +toolchain: + - gnuarmemb + - xtools + - zephyr +ram: 256 +flash: 1536 +supported: + - gpio + - i2c + - spi + - watchdog + - i2s diff --git a/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp_defconfig b/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp_defconfig new file mode 100644 index 00000000000..bc74c3eeb33 --- /dev/null +++ b/boards/arm/nrf54l15pdk_nrf54l15/nrf54l15pdk_nrf54l15_cpuapp_defconfig @@ -0,0 +1,32 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_NRF54LX=y +CONFIG_SOC_NRF54L15_ENGA_CPUAPP=y +CONFIG_BOARD_NRF54L15PDK_NRF54L15_CPUAPP=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# Enable hardware stack protection +CONFIG_HW_STACK_PROTECTION=y + +# MPU-based null-pointer dereferencing detection cannot +# be applied as the (0x0 - 0x400) is unmapped for this target. +CONFIG_NULL_POINTER_EXCEPTION_DETECTION_NONE=y + +# Enable Cache +CONFIG_CACHE_MANAGEMENT=y +CONFIG_EXTERNAL_CACHE=y + +CONFIG_UART_CONSOLE=y +CONFIG_CONSOLE=y +CONFIG_SERIAL=y + +# Enable GPIO +CONFIG_GPIO=y + +CONFIG_SOC_NRF_FORCE_CONSTLAT=y + +# Start SYSCOUNTER on driver init +CONFIG_NRF_GRTC_START_SYSCOUNTER=y diff --git a/boards/arm/nrf54l15pdk_nrf54l15/revision.cmake b/boards/arm/nrf54l15pdk_nrf54l15/revision.cmake new file mode 100644 index 00000000000..4fe5b260db3 --- /dev/null +++ b/boards/arm/nrf54l15pdk_nrf54l15/revision.cmake @@ -0,0 +1,9 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +board_check_revision(FORMAT MAJOR.MINOR.PATCH + VALID_REVISIONS 0.2.0 + DEFAULT_REVISION 0.2.0) From 4ae085e8116590eb7f3b00ee8e7602bac071fdd8 Mon Sep 17 00:00:00 2001 From: Witold Lukasik Date: Mon, 11 Dec 2023 15:01:50 +0100 Subject: [PATCH 1172/1623] [nrf fromtree] drivers: cache: add Nordic cache driver Add Nordic driver for cache. Signed-off-by: Witold Lukasik (cherry picked from commit 6d3009ff2bf80a8e76f1ab928a65b14621f05bb3) --- drivers/cache/CMakeLists.txt | 1 + drivers/cache/Kconfig | 1 + drivers/cache/Kconfig.nrf | 9 + drivers/cache/cache_nrf.c | 390 +++++++++++++++++++++++++++++++++++ 4 files changed, 401 insertions(+) create mode 100644 drivers/cache/Kconfig.nrf create mode 100644 drivers/cache/cache_nrf.c diff --git a/drivers/cache/CMakeLists.txt b/drivers/cache/CMakeLists.txt index 47c790f0a89..23cb11afb6a 100644 --- a/drivers/cache/CMakeLists.txt +++ b/drivers/cache/CMakeLists.txt @@ -7,3 +7,4 @@ zephyr_library_property(ALLOW_EMPTY TRUE) zephyr_library_sources_ifdef(CONFIG_CACHE_ASPEED cache_aspeed.c) zephyr_library_sources_ifdef(CONFIG_USERSPACE cache_handlers.c) +zephyr_library_sources_ifdef(CONFIG_CACHE_NRF_CACHE cache_nrf.c) diff --git a/drivers/cache/Kconfig b/drivers/cache/Kconfig index 834cc49e181..4dcb64f488a 100644 --- a/drivers/cache/Kconfig +++ b/drivers/cache/Kconfig @@ -19,5 +19,6 @@ source "subsys/logging/Kconfig.template.log_config" comment "Device Drivers" source "drivers/cache/Kconfig.aspeed" +source "drivers/cache/Kconfig.nrf" endif # CACHE diff --git a/drivers/cache/Kconfig.nrf b/drivers/cache/Kconfig.nrf new file mode 100644 index 00000000000..820445db432 --- /dev/null +++ b/drivers/cache/Kconfig.nrf @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Carlo Caione +# SPDX-License-Identifier: Apache-2.0 + +config CACHE_NRF_CACHE + bool "nRF cache driver" + select CACHE_HAS_DRIVER + depends on HAS_NRFX && CACHE_MANAGEMENT + help + Enable support for the nRF cache driver. diff --git a/drivers/cache/cache_nrf.c b/drivers/cache/cache_nrf.c new file mode 100644 index 00000000000..63d76a47d6e --- /dev/null +++ b/drivers/cache/cache_nrf.c @@ -0,0 +1,390 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +#include + +LOG_MODULE_REGISTER(cache_nrfx, CONFIG_CACHE_LOG_LEVEL); + +#if !defined(NRF_ICACHE) && defined(NRF_CACHE) +#define NRF_ICACHE NRF_CACHE +#endif + +#define CACHE_LINE_SIZE 32 +#define CACHE_BUSY_RETRY_INTERVAL_US 10 + +static struct k_spinlock lock; + +enum k_nrf_cache_op { + /* + * Sequentially loop through all dirty lines and write those data units to + * memory. + * + * This is FLUSH in Zephyr nomenclature. + */ + K_NRF_CACHE_CLEAN, + + /* + * Mark all lines as invalid, ignoring any dirty data. + * + * This is INVALIDATE in Zephyr nomenclature. + */ + K_NRF_CACHE_INVD, + + /* + * Clean followed by invalidate + * + * This is FLUSH_AND_INVALIDATE in Zephyr nomenclature. + */ + K_NRF_CACHE_FLUSH, +}; + +static inline bool is_cache_busy(NRF_CACHE_Type *cache) +{ +#if NRF_CACHE_HAS_STATUS + return nrf_cache_busy_check(cache); +#else + return false; +#endif +} + +static inline void wait_for_cache(NRF_CACHE_Type *cache) +{ + while (is_cache_busy(cache)) { + k_busy_wait(CACHE_BUSY_RETRY_INTERVAL_US); + } +} + +static inline int _cache_all(NRF_CACHE_Type *cache, enum k_nrf_cache_op op) +{ + /* + * We really do not want to invalidate the whole cache. + */ + if (op == K_NRF_CACHE_INVD) { + return -ENOTSUP; + } + + k_spinlock_key_t key = k_spin_lock(&lock); + + /* + * Invalidating the whole cache is dangerous. For good measure + * disable the cache. + */ + nrf_cache_disable(cache); + + wait_for_cache(cache); + + switch (op) { + +#if NRF_CACHE_HAS_TASK_CLEAN + case K_NRF_CACHE_CLEAN: + nrf_cache_task_trigger(cache, NRF_CACHE_TASK_CLEANCACHE); + break; +#endif + + case K_NRF_CACHE_INVD: + nrf_cache_task_trigger(cache, NRF_CACHE_TASK_INVALIDATECACHE); + break; + +#if NRF_CACHE_HAS_TASK_FLUSH + case K_NRF_CACHE_FLUSH: + nrf_cache_task_trigger(cache, NRF_CACHE_TASK_FLUSHCACHE); + break; +#endif + + default: + break; + } + + wait_for_cache(cache); + + nrf_cache_enable(cache); + + k_spin_unlock(&lock, key); + + return 0; +} + +static inline void _cache_line(NRF_CACHE_Type *cache, enum k_nrf_cache_op op, uintptr_t line_addr) +{ + wait_for_cache(cache); + + nrf_cache_lineaddr_set(cache, line_addr); + + switch (op) { + +#if NRF_CACHE_HAS_TASK_CLEAN + case K_NRF_CACHE_CLEAN: + nrf_cache_task_trigger(cache, NRF_CACHE_TASK_CLEANLINE); + break; +#endif + + case K_NRF_CACHE_INVD: + nrf_cache_task_trigger(cache, NRF_CACHE_TASK_INVALIDATELINE); + break; + +#if NRF_CACHE_HAS_TASK_FLUSH + case K_NRF_CACHE_FLUSH: + nrf_cache_task_trigger(cache, NRF_CACHE_TASK_FLUSHLINE); + break; +#endif + + default: + break; + } + + wait_for_cache(cache); +} + +static inline int _cache_range(NRF_CACHE_Type *cache, enum k_nrf_cache_op op, void *addr, + size_t size) +{ + uintptr_t line_addr = (uintptr_t)addr; + uintptr_t end_addr = line_addr + size; + + /* + * Align address to line size + */ + line_addr &= ~(CACHE_LINE_SIZE - 1); + + do { + k_spinlock_key_t key = k_spin_lock(&lock); + + _cache_line(cache, op, line_addr); + + k_spin_unlock(&lock, key); + + line_addr += CACHE_LINE_SIZE; + + } while (line_addr < end_addr); + + return 0; +} + +static inline int _cache_checks(NRF_CACHE_Type *cache, enum k_nrf_cache_op op, void *addr, + size_t size, bool is_range) +{ + /* Check if the cache is enabled */ + if (!(cache->ENABLE & CACHE_ENABLE_ENABLE_Enabled)) { + return -EAGAIN; + } + + if (!is_range) { + return _cache_all(cache, op); + } + + /* Check for invalid address or size */ + if ((!addr) || (!size)) { + return -EINVAL; + } + + return _cache_range(cache, op, addr, size); +} + +#if defined(NRF_DCACHE) && NRF_CACHE_HAS_TASKS + +void cache_data_enable(void) +{ + nrf_cache_enable(NRF_DCACHE); +} + +void cache_data_disable(void) +{ + nrf_cache_disable(NRF_DCACHE); +} + +int cache_data_flush_all(void) +{ +#if NRF_CACHE_HAS_TASK_CLEAN + return _cache_checks(NRF_DCACHE, K_NRF_CACHE_CLEAN, NULL, 0, false); +#else + return -ENOTSUP; +#endif +} + +int cache_data_invd_all(void) +{ + return _cache_checks(NRF_DCACHE, K_NRF_CACHE_INVD, NULL, 0, false); +} + +int cache_data_flush_and_invd_all(void) +{ +#if NRF_CACHE_HAS_TASK_FLUSH + return _cache_checks(NRF_DCACHE, K_NRF_CACHE_FLUSH, NULL, 0, false); +#else + return -ENOTSUP; +#endif +} + +int cache_data_flush_range(void *addr, size_t size) +{ +#if NRF_CACHE_HAS_TASK_CLEAN + return _cache_checks(NRF_DCACHE, K_NRF_CACHE_CLEAN, addr, size, true); +#else + return -ENOTSUP; +#endif +} + +int cache_data_invd_range(void *addr, size_t size) +{ + return _cache_checks(NRF_DCACHE, K_NRF_CACHE_INVD, addr, size, true); +} + +int cache_data_flush_and_invd_range(void *addr, size_t size) +{ +#if NRF_CACHE_HAS_TASK_FLUSH + return _cache_checks(NRF_DCACHE, K_NRF_CACHE_FLUSH, addr, size, true); +#else + return -ENOTSUP; +#endif +} + +#else + +void cache_data_enable(void) +{ + /* Nothing */ +} + +void cache_data_disable(void) +{ + /* Nothing */ +} + +int cache_data_flush_all(void) +{ + return -ENOTSUP; +} + +int cache_data_invd_all(void) +{ + return -ENOTSUP; +} + +int cache_data_flush_and_invd_all(void) +{ + return -ENOTSUP; +} + +int cache_data_flush_range(void *addr, size_t size) +{ + return -ENOTSUP; +} + +int cache_data_invd_range(void *addr, size_t size) +{ + return -ENOTSUP; +} + +int cache_data_flush_and_invd_range(void *addr, size_t size) +{ + return -ENOTSUP; +} + +#endif /* NRF_DCACHE */ + +#if defined(NRF_ICACHE) && NRF_CACHE_HAS_TASKS + +void cache_instr_enable(void) +{ + nrf_cache_enable(NRF_ICACHE); +} + +void cache_instr_disable(void) +{ + nrf_cache_disable(NRF_ICACHE); +} + +int cache_instr_flush_all(void) +{ +#if NRF_CACHE_HAS_TASK_CLEAN + return _cache_checks(NRF_ICACHE, K_NRF_CACHE_CLEAN, NULL, 0, false); +#else + return -ENOTSUP; +#endif +} + +int cache_instr_invd_all(void) +{ + return _cache_checks(NRF_ICACHE, K_NRF_CACHE_INVD, NULL, 0, false); +} + +int cache_instr_flush_and_invd_all(void) +{ +#if NRF_CACHE_HAS_TASK_FLUSH + return _cache_checks(NRF_ICACHE, K_NRF_CACHE_FLUSH, NULL, 0, false); +#else + return -ENOTSUP; +#endif +} + +int cache_instr_flush_range(void *addr, size_t size) +{ +#if NRF_CACHE_HAS_TASK_CLEAN + return _cache_checks(NRF_ICACHE, K_NRF_CACHE_CLEAN, addr, size, true); +#else + return -ENOTSUP; +#endif +} + +int cache_instr_invd_range(void *addr, size_t size) +{ + return _cache_checks(NRF_ICACHE, K_NRF_CACHE_INVD, addr, size, true); +} + +int cache_instr_flush_and_invd_range(void *addr, size_t size) +{ +#if NRF_CACHE_HAS_TASK_FLUSH + return _cache_checks(NRF_ICACHE, K_NRF_CACHE_FLUSH, addr, size, true); +#else + return -ENOTSUP; +#endif +} + +#else + +void cache_instr_enable(void) +{ + /* Nothing */ +} + +void cache_instr_disable(void) +{ + /* Nothing */ +} + +int cache_instr_flush_all(void) +{ + return -ENOTSUP; +} + +int cache_instr_invd_all(void) +{ + return -ENOTSUP; +} + +int cache_instr_flush_and_invd_all(void) +{ + return -ENOTSUP; +} + +int cache_instr_flush_range(void *addr, size_t size) +{ + return -ENOTSUP; +} + +int cache_instr_invd_range(void *addr, size_t size) +{ + return -ENOTSUP; +} + +int cache_instr_flush_and_invd_range(void *addr, size_t size) +{ + return -ENOTSUP; +} + +#endif /* NRF_ICACHE */ From a47efab18d29ecb73ac8f251000382eb1ec01a34 Mon Sep 17 00:00:00 2001 From: Witold Lukasik Date: Mon, 11 Dec 2023 17:44:16 +0100 Subject: [PATCH 1173/1623] [nrf fromtree] scripts: west_commands: runners: nrf_common: add support for nRF54L Add support for new Nordic family in west commands. Signed-off-by: Witold Lukasik (cherry picked from commit 13abdcccb3f81d1f0299246b298b74b984e8f74a) --- scripts/west_commands/runners/nrf_common.py | 4 +++- scripts/west_commands/runners/nrfjprog.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/west_commands/runners/nrf_common.py b/scripts/west_commands/runners/nrf_common.py index 2ff51d7e85d..788021c6191 100644 --- a/scripts/west_commands/runners/nrf_common.py +++ b/scripts/west_commands/runners/nrf_common.py @@ -59,7 +59,7 @@ def dev_id_help(cls) -> str: @classmethod def do_add_parser(cls, parser): parser.add_argument('--nrf-family', - choices=['NRF51', 'NRF52', 'NRF53', 'NRF91'], + choices=['NRF51', 'NRF52', 'NRF53', 'NRF54L', 'NRF91'], help='''MCU family; still accepted for compatibility only''') parser.add_argument('--softreset', required=False, @@ -161,6 +161,8 @@ def ensure_family(self): self.family = 'NRF52_FAMILY' elif self.build_conf.getboolean('CONFIG_SOC_SERIES_NRF53X'): self.family = 'NRF53_FAMILY' + elif self.build_conf.getboolean('CONFIG_SOC_SERIES_NRF54LX'): + self.family = 'NRF54L_FAMILY' elif self.build_conf.getboolean('CONFIG_SOC_SERIES_NRF91X'): self.family = 'NRF91_FAMILY' else: diff --git a/scripts/west_commands/runners/nrfjprog.py b/scripts/west_commands/runners/nrfjprog.py index 8762ce0e740..a28681ae6a5 100644 --- a/scripts/west_commands/runners/nrfjprog.py +++ b/scripts/west_commands/runners/nrfjprog.py @@ -46,7 +46,7 @@ def do_exec_op(self, op, force=False): # Translate the op families = {'NRF51_FAMILY': 'NRF51', 'NRF52_FAMILY': 'NRF52', - 'NRF53_FAMILY': 'NRF53', 'NRF91_FAMILY': 'NRF91'} + 'NRF53_FAMILY': 'NRF53', 'NRF54L_FAMILY': 'NRF54L', 'NRF91_FAMILY': 'NRF91'} cores = {'NRFDL_DEVICE_CORE_APPLICATION': 'CP_APPLICATION', 'NRFDL_DEVICE_CORE_NETWORK': 'CP_NETWORK'} From cd00d9b92c50731de56bd30f23b531c56bca2ee6 Mon Sep 17 00:00:00 2001 From: Witold Lukasik Date: Tue, 12 Dec 2023 10:39:07 +0100 Subject: [PATCH 1174/1623] [nrf fromtree] tests: arch: arm: arm: align tests to nRF54L15 Changed _ISR_OFFSET to be 28 as specified in OPS. Removed console ISR. Signed-off-by: Witold Lukasik (cherry picked from commit cac2990c04d6ea9c63031c7ef3c4ab830dedcb68) --- .../src/arm_irq_vector_table.c | 120 +++++------------- 1 file changed, 35 insertions(+), 85 deletions(-) diff --git a/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c b/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c index 7d793066109..f18c30dac9a 100644 --- a/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c +++ b/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c @@ -16,66 +16,22 @@ */ #define _ISR_OFFSET 0 -#if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) -/* The customized solution for nRF51X-based and nRF52X-based - * platforms requires that the POWER_CLOCK_IRQn line equals 0. - */ -BUILD_ASSERT(POWER_CLOCK_IRQn == 0, - "POWER_CLOCK_IRQn != 0. Consider rework manual vector table."); - -/* The customized solution for nRF51X-based and nRF52X-based - * platforms requires that the RTC1 IRQ line equals 17. - */ -BUILD_ASSERT(RTC1_IRQn == 17, - "RTC1_IRQn != 17. Consider rework manual vector table."); - +#if defined(CONFIG_SOC_FAMILY_NRF) #undef _ISR_OFFSET -#if !defined(CONFIG_BOARD_QEMU_CORTEX_M0) -/* Interrupt line 0 is used by POWER_CLOCK */ -#define _ISR_OFFSET 1 +#if defined(CONFIG_BOARD_QEMU_CORTEX_M0) +/* For the nRF51-based QEMU Cortex-M0 platform, the first set of consecutive + * implemented interrupts that can be used by this test starts right after + * the TIMER0 IRQ line, which is used by the system timer. + */ +#define _ISR_OFFSET (TIMER0_IRQn + 1) +#elif defined(CONFIG_SOC_SERIES_NRF54LX) +/* For nRF54L Series, use SWI00-02 interrupt lines. */ +#define _ISR_OFFSET SWI00_IRQn #else -/* The customized solution for nRF51-based QEMU Cortex-M0 platform - * requires that the TIMER0 IRQ line equals 8. - */ -BUILD_ASSERT(TIMER0_IRQn == 8, - "TIMER0_IRQn != 8. Consider rework manual vector table."); -/* Interrupt lines 9-11 is the first set of consecutive interrupts implemented - * in QEMU Cortex M0. - */ -#define _ISR_OFFSET 9 - +/* For other nRF targets, use TIMER0-2 interrupt lines. */ +#define _ISR_OFFSET TIMER0_IRQn #endif - -#elif defined(CONFIG_SOC_SERIES_NRF53X) || defined(CONFIG_SOC_SERIES_NRF91X) -/* The customized solution for nRF91X-based and nRF53X-based - * platforms requires that the POWER_CLOCK_IRQn line equals 5. - */ -BUILD_ASSERT(CLOCK_POWER_IRQn == 5, - "POWER_CLOCK_IRQn != 5." - "Consider rework manual vector table."); - -#if !defined(CONFIG_SOC_NRF5340_CPUNET) -/* The customized solution for nRF91X-based platforms - * requires that the RTC1 IRQ line equals 21. - */ -BUILD_ASSERT(RTC1_IRQn == 21, - "RTC1_IRQn != 21. Consider rework manual vector table."); - -#else /* CONFIG_SOC_NRF5340_CPUNET */ -/* The customized solution for nRF5340_CPUNET - * requires that the RTC1 IRQ line equals 22. - */ -BUILD_ASSERT(RTC1_IRQn == 22, - "RTC1_IRQn != 22. Consider rework manual vector table."); -#endif -#undef _ISR_OFFSET -/* Interrupt lines 8-10 is the first set of consecutive interrupts implemented - * in nRF9160 SOC. - */ -#define _ISR_OFFSET 8 - -#endif /* CONFIG_SOC_SERIES_NRF52X */ - +#endif /* CONFIG_SOC_FAMILY_NRF */ struct k_sem sem[3]; @@ -182,40 +138,34 @@ typedef void (*vth)(void); /* Vector Table Handler */ * * Note: qemu_cortex_m0 uses TIMER0 to implement system timer. */ -void rtc_nrf_isr(void); void nrfx_power_clock_irq_handler(void); #if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) +#define POWER_CLOCK_IRQ_NUM POWER_CLOCK_IRQn +#else +#define POWER_CLOCK_IRQ_NUM CLOCK_POWER_IRQn +#endif + #if defined(CONFIG_BOARD_QEMU_CORTEX_M0) void timer0_nrf_isr(void); -vth __irq_vector_table _irq_vector_table[] = { - nrfx_power_clock_irq_handler, 0, 0, 0, 0, 0, 0, 0, - timer0_nrf_isr, isr0, isr1, isr2 -}; -#else -vth __irq_vector_table _irq_vector_table[] = { - nrfx_power_clock_irq_handler, - isr0, isr1, isr2, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - rtc_nrf_isr -}; -#endif /* CONFIG_BOARD_QEMU_CORTEX_M0 */ -#elif defined(CONFIG_SOC_SERIES_NRF53X) || defined(CONFIG_SOC_SERIES_NRF91X) -#ifndef CONFIG_SOC_NRF5340_CPUNET -vth __irq_vector_table _irq_vector_table[] = { - 0, 0, 0, 0, 0, nrfx_power_clock_irq_handler, 0, 0, - isr0, isr1, isr2, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - rtc_nrf_isr -}; +#define TIMER_IRQ_HANDLER timer0_nrf_isr +#define TIMER_IRQ_NUM TIMER0_IRQn +#elif defined(CONFIG_SOC_SERIES_NRF54LX) +void nrfx_grtc_irq_handler(void); +#define TIMER_IRQ_HANDLER nrfx_grtc_irq_handler +#define TIMER_IRQ_NUM GRTC_0_IRQn #else -vth __irq_vector_table _irq_vector_table[] = { - 0, 0, 0, 0, 0, nrfx_power_clock_irq_handler, 0, 0, - isr0, isr1, isr2, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - rtc_nrf_isr -}; -#endif +void rtc_nrf_isr(void); +#define TIMER_IRQ_HANDLER rtc_nrf_isr +#define TIMER_IRQ_NUM RTC1_IRQn #endif + +#define IRQ_VECTOR_TABLE_SIZE (MAX(POWER_CLOCK_IRQ_NUM, MAX(TIMER_IRQ_NUM, _ISR_OFFSET + 2)) + 1) + +vth __irq_vector_table _irq_vector_table[IRQ_VECTOR_TABLE_SIZE] = { + [POWER_CLOCK_IRQ_NUM] = nrfx_power_clock_irq_handler, + [TIMER_IRQ_NUM] = TIMER_IRQ_HANDLER, + [_ISR_OFFSET] = isr0, isr1, isr2, +}; #elif defined(CONFIG_SOC_SERIES_CC13X2_CC26X2) || defined(CONFIG_SOC_SERIES_CC13X2X7_CC26X2X7) /* TI CC13x2/CC26x2 based platforms also employ a Hardware RTC peripheral * to implement the Kernel system timer, instead of the ARM Cortex-M From 0c6cdd39c2da00f7c73014b6462e2db097ca7b8c Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Tue, 23 Jan 2024 12:53:53 +0100 Subject: [PATCH 1175/1623] [nrf fromtree] tests: drivers: add overlay files for nRF54L15 Add nRF54L15 overlay files for driver tests that need them. Signed-off-by: Magdalena Pastula (cherry picked from commit d8203d2e1f4917447757dfabd92f286ac51021a1) --- .../nrf54l15pdk_nrf54l15_cpuapp.overlay | 21 +++++++++ .../nrf54l15pdk_nrf54l15_cpuapp.overlay | 30 ++++++++++++ .../nrf54l15pdk_nrf54l15_cpuapp.overlay | 30 ++++++++++++ .../nrf54l15pdk_nrf54l15_cpuapp.overlay | 46 +++++++++++++++++++ .../nrf54l15pdk_nrf54l15_cpuapp.overlay | 36 +++++++++++++++ .../nrf54l15pdk_nrf54l15_cpuapp.overlay | 43 +++++++++++++++++ .../nrf54l15pdk_nrf54l15_cpuapp.overlay | 36 +++++++++++++++ .../nrf54l15pdk_nrf54l15_cpuapp.overlay | 9 ++++ 8 files changed, 251 insertions(+) create mode 100644 tests/drivers/gpio/gpio_basic_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay create mode 100644 tests/drivers/i2s/i2s_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay create mode 100644 tests/drivers/i2s/i2s_speed/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay create mode 100644 tests/drivers/spi/spi_loopback/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay create mode 100644 tests/drivers/uart/uart_async_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay create mode 100644 tests/drivers/uart/uart_mix_fifo_poll/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay create mode 100644 tests/drivers/uart/uart_pm/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay create mode 100644 tests/drivers/watchdog/wdt_basic_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay diff --git a/tests/drivers/gpio/gpio_basic_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay b/tests/drivers/gpio/gpio_basic_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000..97702240047 --- /dev/null +++ b/tests/drivers/gpio/gpio_basic_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + + / { + resources { + compatible = "test-gpio-basic-api"; + out-gpios = <&gpio1 10 0>; + in-gpios = <&gpio1 11 0>; + }; +}; + +&gpiote20 { + status = "okay"; +}; + +&gpio1 { + status = "okay"; +}; diff --git a/tests/drivers/i2s/i2s_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay b/tests/drivers/i2s/i2s_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000..8b82825a0f2 --- /dev/null +++ b/tests/drivers/i2s/i2s_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* i2s-node0 is the transmitter/receiver */ + +/ { + aliases { + i2s-node0 = &i2s20; + }; +}; + +&pinctrl { + i2s20_default_alt: i2s20_default_alt { + group1 { + psels = , + , + , + ; + }; + }; +}; + +&i2s20 { + status = "okay"; + pinctrl-0 = <&i2s20_default_alt>; + pinctrl-names = "default"; +}; diff --git a/tests/drivers/i2s/i2s_speed/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay b/tests/drivers/i2s/i2s_speed/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000..8b82825a0f2 --- /dev/null +++ b/tests/drivers/i2s/i2s_speed/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* i2s-node0 is the transmitter/receiver */ + +/ { + aliases { + i2s-node0 = &i2s20; + }; +}; + +&pinctrl { + i2s20_default_alt: i2s20_default_alt { + group1 { + psels = , + , + , + ; + }; + }; +}; + +&i2s20 { + status = "okay"; + pinctrl-0 = <&i2s20_default_alt>; + pinctrl-names = "default"; +}; diff --git a/tests/drivers/spi/spi_loopback/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay b/tests/drivers/spi/spi_loopback/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000..f2e84b72f9b --- /dev/null +++ b/tests/drivers/spi/spi_loopback/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&pinctrl { + spi00_default: spi00_default { + group1 { + psels = , + , + ; + }; + }; + + spi00_sleep: spi00_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; +}; + +&spi00 { + status = "okay"; + pinctrl-0 = <&spi00_default>; + pinctrl-1 = <&spi00_sleep>; + pinctrl-names = "default", "sleep"; + overrun-character = <0x00>; + slow@0 { + compatible = "test-spi-loopback-slow"; + reg = <0>; + spi-max-frequency = ; + }; + fast@0 { + compatible = "test-spi-loopback-fast"; + reg = <0>; + spi-max-frequency = ; + }; +}; + +&gpio2 { + status = "okay"; +}; diff --git a/tests/drivers/uart/uart_async_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay b/tests/drivers/uart/uart_async_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000..033aab401ac --- /dev/null +++ b/tests/drivers/uart/uart_async_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&pinctrl { + uart21_default: uart21_default { + group1 { + psels = , + ; + }; + }; + + uart21_sleep: uart21_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; +}; + +/ { + chosen { + zephyr,console = &uart20; + }; +}; + +dut: &uart21 { + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&uart21_default>; + pinctrl-1 = <&uart21_sleep>; + pinctrl-names = "default", "sleep"; +}; diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000..945b8628e7a --- /dev/null +++ b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&pinctrl { + uart21_default: uart21_default { + group1 { + psels = , + , + , + ; + }; + }; + + uart21_sleep: uart21_sleep { + group1 { + psels = , + , + , + ; + low-power-enable; + }; + }; +}; + +dut: &uart21 { + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&uart21_default>; + pinctrl-1 = <&uart21_sleep>; + pinctrl-names = "default", "sleep"; + hw-flow-control; +}; + +counter_dev: &timer00 { + status = "okay"; +}; + +&grtc { + interrupts = <228 2>; +}; diff --git a/tests/drivers/uart/uart_pm/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay b/tests/drivers/uart/uart_pm/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000..033aab401ac --- /dev/null +++ b/tests/drivers/uart/uart_pm/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&pinctrl { + uart21_default: uart21_default { + group1 { + psels = , + ; + }; + }; + + uart21_sleep: uart21_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; +}; + +/ { + chosen { + zephyr,console = &uart20; + }; +}; + +dut: &uart21 { + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&uart21_default>; + pinctrl-1 = <&uart21_sleep>; + pinctrl-names = "default", "sleep"; +}; diff --git a/tests/drivers/watchdog/wdt_basic_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay b/tests/drivers/watchdog/wdt_basic_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000..aa2789dd45e --- /dev/null +++ b/tests/drivers/watchdog/wdt_basic_api/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&wdt30 { + status = "okay"; +}; From 353b582a0fa5a6d6558e023630cb703652187679 Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Tue, 23 Jan 2024 14:42:22 +0100 Subject: [PATCH 1176/1623] [nrf fromtree] samples: add overlay files for nRF54L15 Add nRF54L15 overlays to samples that needed them. Signed-off-by: Magdalena Pastula (cherry picked from commit 361a5a11aa2ccb1f997b0de78b21eb6c3d94fb70) --- .../nrf54l15pdk_nrf54l15_cpuapp.overlay | 8 ++++ .../nrf54l15pdk_nrf54l15_cpuapp.overlay | 43 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 samples/drivers/watchdog/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay create mode 100644 samples/sensor/qdec/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay diff --git a/samples/drivers/watchdog/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay b/samples/drivers/watchdog/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000..66157d79fb3 --- /dev/null +++ b/samples/drivers/watchdog/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay @@ -0,0 +1,8 @@ +/* + * Copyright 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +&wdt30 { + status = "okay"; +}; diff --git a/samples/sensor/qdec/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay b/samples/sensor/qdec/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay new file mode 100644 index 00000000000..3d872a2071b --- /dev/null +++ b/samples/sensor/qdec/boards/nrf54l15pdk_nrf54l15_cpuapp.overlay @@ -0,0 +1,43 @@ +/* + * Copyright 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + aliases { + qdec0 = &qdec20; + qenca = &phase_a; + qencb = &phase_b; + }; + + encoder-emulate { + compatible = "gpio-leds"; + phase_a: phase_a { + gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>; + }; + phase_b: phase_b { + gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>; + }; + }; +}; + +&pinctrl { + qdec_pinctrl: qdec_pinctrl { + group1 { + psels = , + ; + }; + }; +}; + +&gpio1 { + status = "okay"; +}; + +&qdec20 { + status = "okay"; + pinctrl-0 = <&qdec_pinctrl>; + pinctrl-names = "default"; + steps = <120>; + led-pre = <500>; +}; From 47e402dd4afa48668b44a6b2bcba7b4631b96753 Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Tue, 9 Jan 2024 15:27:01 +0100 Subject: [PATCH 1177/1623] [nrf fromtree] drivers: hwinfo: update to be aligned to nRF54L15 Update hwinfo driver to be aligned to nRF54L15. Signed-off-by: Magdalena Pastula (cherry picked from commit 5a32e6e21c2270641ba834e33470ff845afba437) --- drivers/hwinfo/hwinfo_nrf.c | 60 ++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/drivers/hwinfo/hwinfo_nrf.c b/drivers/hwinfo/hwinfo_nrf.c index 2a79f1d0c0d..4375cf05b2f 100644 --- a/drivers/hwinfo/hwinfo_nrf.c +++ b/drivers/hwinfo/hwinfo_nrf.c @@ -58,22 +58,56 @@ int z_impl_hwinfo_get_reset_cause(uint32_t *cause) if (reason & NRFX_RESET_REASON_DIF_MASK) { flags |= RESET_DEBUG; } + if (reason & NRFX_RESET_REASON_SREQ_MASK) { + flags |= RESET_SOFTWARE; + } -#if !NRF_POWER_HAS_RESETREAS +#if NRFX_RESET_REASON_HAS_CTRLAP if (reason & NRFX_RESET_REASON_CTRLAP_MASK) { flags |= RESET_DEBUG; } - if (reason & NRFX_RESET_REASON_DOG0_MASK) { - flags |= RESET_WATCHDOG; +#endif +#if NRFX_RESET_REASON_HAS_LPCOMP + if (reason & NRFX_RESET_REASON_LPCOMP_MASK) { + flags |= RESET_LOW_POWER_WAKE; + } +#endif +#if NRFX_RESET_REASON_HAS_NFC + if (reason & NRFX_RESET_REASON_NFC_MASK) { + flags |= RESET_LOW_POWER_WAKE; + } +#endif +#if NRFX_RESET_REASON_HAS_VBUS + if (reason & NRFX_RESET_REASON_VBUS_MASK) { + flags |= RESET_POR; + } +#endif +#if NRFX_RESET_REASON_HAS_CTRLAPSOFT + if (reason & NRFX_RESET_REASON_CTRLAPSOFT_MASK) { + flags |= RESET_DEBUG; + } +#endif +#if NRFX_RESET_REASON_HAS_CTRLAPHARD + if (reason & NRFX_RESET_REASON_CTRLAPHARD_MASK) { + flags |= RESET_DEBUG; + } +#endif +#if NRFX_RESET_REASON_HAS_CTRLAPPIN + if (reason & NRFX_RESET_REASON_CTRLAPPIN_MASK) { + flags |= RESET_DEBUG; } +#endif +#if !NRF_POWER_HAS_RESETREAS if (reason & NRFX_RESET_REASON_DOG1_MASK) { flags |= RESET_WATCHDOG; } - if (reason & NRFX_RESETREAS_SREQ_MASK) { - flags |= RESET_SOFTWARE; +#endif +#if NRFX_RESET_REASON_HAS_GRTC + if (reason & NRFX_RESET_REASON_GRTC_MASK) { + flags |= RESET_CLOCK; } - -#if NRF_RESET_HAS_NETWORK +#endif +#if NRFX_RESET_REASON_HAS_NETWORK if (reason & NRFX_RESET_REASON_LSREQ_MASK) { flags |= RESET_SOFTWARE; } @@ -87,10 +121,14 @@ int z_impl_hwinfo_get_reset_cause(uint32_t *cause) flags |= RESET_DEBUG; } #endif - -#else - if (reason & NRFX_RESET_REASON_SREQ_MASK) { - flags |= RESET_SOFTWARE; +#if defined(NRFX_RESET_REASON_TAMPC_MASK) + if (reason & NRFX_RESET_REASON_TAMPC_MASK) { + flags |= RESET_SECURITY; + } +#endif +#if defined(NRFX_RESET_REASON_SECTAMPER_MASK) + if (reason & NRFX_RESET_REASON_SECTAMPER_MASK) { + flags |= RESET_SECURITY; } #endif From 3fea81732e92a899f5aaa704f75bcd83032f30a6 Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Tue, 16 Jan 2024 17:24:22 +0100 Subject: [PATCH 1178/1623] [nrf fromtree] soc: arm: nordic_nrf: align soc_secure.h to nRF54L In nRF54L15 FICR can be accessed also from non-secure code, so it does not have NRF_FICR_S defined. Signed-off-by: Magdalena Pastula (cherry picked from commit e4aebf9cea50e26c666aa69b9de4a802b9bcc6dc) --- soc/arm/nordic_nrf/common/soc_secure.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soc/arm/nordic_nrf/common/soc_secure.h b/soc/arm/nordic_nrf/common/soc_secure.h index 948f38547aa..d38d66ab488 100644 --- a/soc/arm/nordic_nrf/common/soc_secure.h +++ b/soc/arm/nordic_nrf/common/soc_secure.h @@ -59,7 +59,7 @@ static inline void soc_secure_gpio_pin_mcu_select(uint32_t pin_number, #if defined(CONFIG_SOC_HFXO_CAP_INTERNAL) static inline uint32_t soc_secure_read_xosc32mtrim(void) { - return NRF_FICR_S->XOSC32MTRIM; + return NRF_FICR->XOSC32MTRIM; } #endif /* defined(CONFIG_SOC_HFXO_CAP_INTERNAL) */ From 6751caf4f67d9fc8cff31a107360db8da5d52ab1 Mon Sep 17 00:00:00 2001 From: Magdalena Pastula Date: Tue, 30 Jan 2024 10:40:15 +0100 Subject: [PATCH 1179/1623] [nrf fromtree] tests: lib: cpp: exclude nRF54L15 Exclude nRF54L15 from possible targets as its HAL is incompatible with C++98. Signed-off-by: Magdalena Pastula (cherry picked from commit d7d254140d02ef30821262853e46c794f7b515e5) --- tests/lib/cpp/cxx/testcase.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/lib/cpp/cxx/testcase.yaml b/tests/lib/cpp/cxx/testcase.yaml index 77d1b06dbb2..cbdaacf714c 100644 --- a/tests/lib/cpp/cxx/testcase.yaml +++ b/tests/lib/cpp/cxx/testcase.yaml @@ -34,6 +34,8 @@ tests: # -std=c++98) cpp.main.cpp98: arch_exclude: posix + # Exclude nRF54L15 as its HAL is not compatible with C++98. + platform_exclude: nrf54l15pdk_nrf54l15_cpuapp build_only: true extra_configs: - CONFIG_STD_CPP98=y From 11ebed1212a667337a8baf835ff455d7faac0903 Mon Sep 17 00:00:00 2001 From: Jeremy Bettis Date: Wed, 20 Dec 2023 22:36:20 +0000 Subject: [PATCH 1180/1623] [nrf fromtree] tests: Add unittest for gpio_ite_it8xxx2_v2 Add a unittest for 100% of the lines in gpio_ite_it8xxx2_v2. The test fakes the registers by overriding the ECREG macro to call a function provided by the test. Does not test the code guarded by CONFIG_SOC_IT8XXX2_GPIO_GROUP_K_L_DEFAULT_PULL_DOWN Bug #66401 Signed-off-by: Jeremy Bettis (cherry picked from commit 6c567d489974933f152a532a7e9400b8f6b9bc5d) --- .../gpio/gpio_ite_it8xxx2_v2/CMakeLists.txt | 23 + .../drivers/gpio/gpio_ite_it8xxx2_v2/Kconfig | 12 + .../boards/native_sim.overlay | 45 ++ .../include/chip_chipregs.h | 20 + .../include/zephyr/arch/cpu.h | 16 + .../drivers/gpio/gpio_ite_it8xxx2_v2/prj.conf | 9 + .../gpio/gpio_ite_it8xxx2_v2/src/main.c | 460 ++++++++++++++++++ .../gpio/gpio_ite_it8xxx2_v2/testcase.yaml | 14 + 8 files changed, 599 insertions(+) create mode 100644 tests/drivers/gpio/gpio_ite_it8xxx2_v2/CMakeLists.txt create mode 100644 tests/drivers/gpio/gpio_ite_it8xxx2_v2/Kconfig create mode 100644 tests/drivers/gpio/gpio_ite_it8xxx2_v2/boards/native_sim.overlay create mode 100644 tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/chip_chipregs.h create mode 100644 tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/zephyr/arch/cpu.h create mode 100644 tests/drivers/gpio/gpio_ite_it8xxx2_v2/prj.conf create mode 100644 tests/drivers/gpio/gpio_ite_it8xxx2_v2/src/main.c create mode 100644 tests/drivers/gpio/gpio_ite_it8xxx2_v2/testcase.yaml diff --git a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/CMakeLists.txt b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/CMakeLists.txt new file mode 100644 index 00000000000..bf01055ffc3 --- /dev/null +++ b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright 2023 The ChromiumOS Authors +# +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(gpio_ite_it8xxx2_v2) + +target_include_directories(app PRIVATE + include +) + +zephyr_include_directories( + include + ${ZEPHYR_BASE}/soc/riscv/riscv-ite/common + ${ZEPHYR_BASE}/soc/riscv/riscv-ite/it8xxx2 +) + +target_sources(app + PRIVATE + src/main.c +) diff --git a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/Kconfig b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/Kconfig new file mode 100644 index 00000000000..bb5e43e8e20 --- /dev/null +++ b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/Kconfig @@ -0,0 +1,12 @@ +# Copyright 2023 The ChromiumOS Authors +# +# SPDX-License-Identifier: Apache-2.0 + +source "Kconfig.zephyr" + +config SOC_IT8XXX2_GPIO_GROUP_K_L_DEFAULT_PULL_DOWN + bool + default n +config HAS_ITE_INTC + bool + default y diff --git a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/boards/native_sim.overlay b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/boards/native_sim.overlay new file mode 100644 index 00000000000..7f22c83ffb1 --- /dev/null +++ b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/boards/native_sim.overlay @@ -0,0 +1,45 @@ +/* + * Copyright 2023 The ChromiumOS Authors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +/ { + intc: interrupt-controller@f03f00 { + compatible = "vnd,intc"; + #address-cells = <0>; + #interrupt-cells = <2>; + interrupt-controller; + reg = <0x00f03f00 0x0100>; + }; + + gpioa: gpio@f01601 { + compatible = "ite,it8xxx2-gpio-v2"; + reg = <0x00f01601 1 /* GPDR (set) */ + 0x00f01618 1 /* GPDMR (get) */ + 0x00f01630 1 /* GPOTR */ + 0x00f01648 1 /* P18SCR */ + 0x00f01660 8>; /* GPCR */ + ngpios = <8>; + gpio-controller; + interrupts = <9 IRQ_TYPE_LEVEL_HIGH + 2 IRQ_TYPE_LEVEL_HIGH + 3 IRQ_TYPE_LEVEL_HIGH + 4 IRQ_TYPE_LEVEL_HIGH + 5 IRQ_TYPE_LEVEL_HIGH + 6 IRQ_TYPE_LEVEL_HIGH + 7 IRQ_TYPE_LEVEL_HIGH + 8 IRQ_TYPE_LEVEL_HIGH>; + interrupt-parent = <&intc>; + wuc-base = <0xf01b20 0xf01b20 0xf01b20 0xf01b1c + 0xf01b1c 0xf01b1c 0xf01b1c 0xf01b24>; + wuc-mask = ; + has-volt-sel = <1 1 1 1 1 1 1 1>; + #gpio-cells = <2>; + }; +}; diff --git a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/chip_chipregs.h b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/chip_chipregs.h new file mode 100644 index 00000000000..3372a845aa9 --- /dev/null +++ b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/chip_chipregs.h @@ -0,0 +1,20 @@ +/* + * Copyright 2023 The ChromiumOS Authors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include <../soc/riscv/riscv-ite/common/chip_chipregs.h> + +/* + * Macros for emulated hardware registers access. + */ +#undef ECREG +#undef ECREG_u16 +#undef ECREG_u32 +#define ECREG(x) (*((volatile unsigned char *)fake_ecreg((intptr_t)x))) +#define ECREG_u16(x) (*((volatile unsigned short *)fake_ecreg((intptr_t)x))) +#define ECREG_u32(x) (*((volatile unsigned long *)fake_ecreg((intptr_t)x))) + +unsigned int *fake_ecreg(intptr_t r); +uint8_t ite_intc_get_irq_num(void); diff --git a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/zephyr/arch/cpu.h b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/zephyr/arch/cpu.h new file mode 100644 index 00000000000..ab921224676 --- /dev/null +++ b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/zephyr/arch/cpu.h @@ -0,0 +1,16 @@ +/* + * Copyright 2023 The ChromiumOS Authors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +int arch_irq_connect_dynamic(unsigned int irq, unsigned int priority, + void (*routine)(const void *parameter), + const void *parameter, uint32_t flags); +int arch_irq_disconnect_dynamic(unsigned int irq, unsigned int priority, + void (*routine)(const void *parameter), + const void *parameter, uint32_t flags); +typedef struct z_thread_stack_element k_thread_stack_t; diff --git a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/prj.conf b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/prj.conf new file mode 100644 index 00000000000..cf7d90e583c --- /dev/null +++ b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/prj.conf @@ -0,0 +1,9 @@ +# Copyright 2023 The ChromiumOS Authors +# +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_ZTEST=y +CONFIG_GPIO_ITE_IT8XXX2_V2=y +CONFIG_GPIO=y +CONFIG_DYNAMIC_INTERRUPTS=y +CONFIG_GPIO_GET_CONFIG=y diff --git a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/src/main.c b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/src/main.c new file mode 100644 index 00000000000..4272fbe42f9 --- /dev/null +++ b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/src/main.c @@ -0,0 +1,460 @@ +/* + * Copyright 2023 The ChromiumOS Authors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#define MY_GPIO DT_NODELABEL(gpioa) + +const struct device *const gpio_dev = DEVICE_DT_GET(MY_GPIO); +static struct { + uint8_t fake; + uint8_t gpdmr; + uint8_t gpdr; + uint8_t gpotr; + uint8_t p18scr; + uint8_t wuemr, wuesr, wubemr; + uint8_t gpcr[DT_REG_SIZE_BY_IDX(MY_GPIO, 4)]; + bool clear_gpcr_before_read; +} registers; +static int callback_called; +static struct gpio_callback callback_struct; + +/* These values must match what is set in the dts overlay. */ +#define TEST_PIN 1 +#define TEST_IRQ DT_IRQ_BY_IDX(MY_GPIO, TEST_PIN, irq) +#define TEST_MASK DT_PROP_BY_IDX(MY_GPIO, wuc_mask, TEST_PIN) + +DEFINE_FFF_GLOBALS; + +uint8_t ite_intc_get_irq_num(void) +{ + return posix_get_current_irq(); +} + +unsigned int *fake_ecreg(intptr_t r) +{ + switch (r) { + case DT_REG_ADDR_BY_IDX(MY_GPIO, 0): /* GPDR */ + return (unsigned int *)®isters.gpdr; + case DT_REG_ADDR_BY_IDX(MY_GPIO, 1): /* GPDMR */ + return (unsigned int *)®isters.gpdmr; + case DT_REG_ADDR_BY_IDX(MY_GPIO, 2): /* GPOTR */ + return (unsigned int *)®isters.gpotr; + case DT_REG_ADDR_BY_IDX(MY_GPIO, 3): /* P18SCR */ + return (unsigned int *)®isters.p18scr; + case DT_PROP_BY_IDX(MY_GPIO, wuc_base, TEST_PIN): + return (unsigned int *)®isters.wuemr; + case DT_PROP_BY_IDX(MY_GPIO, wuc_base, TEST_PIN) + 1: + return (unsigned int *)®isters.wuesr; + case DT_PROP_BY_IDX(MY_GPIO, wuc_base, TEST_PIN) + 3: + return (unsigned int *)®isters.wubemr; + } + if (r >= DT_REG_ADDR_BY_IDX(MY_GPIO, 4) && + r < DT_REG_ADDR_BY_IDX(MY_GPIO, 4) + DT_REG_SIZE_BY_IDX(MY_GPIO, 4)) { + if (registers.clear_gpcr_before_read) { + registers.gpcr[r - DT_REG_ADDR_BY_IDX(MY_GPIO, 4)] = 0; + } + return (unsigned int *)®isters.gpcr[r - DT_REG_ADDR_BY_IDX(MY_GPIO, 4)]; + } + zassert_unreachable("Register access: %x", r); + return (unsigned int *)®isters.fake; +} + +static void callback(const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins) +{ + callback_called++; + zexpect_equal(pins, BIT(TEST_PIN)); +} + +static void before_test(void *fixture) +{ + callback_called = 0; + memset(®isters, 0, sizeof(registers)); +} + +static void after_test(void *fixture) +{ + if (callback_struct.handler != NULL) { + zassert_ok(gpio_remove_callback(gpio_dev, &callback_struct)); + } + callback_struct.handler = NULL; +} + +ZTEST_SUITE(gpio_ite_it8xxx2_v2, NULL, NULL, before_test, after_test, NULL); + +ZTEST(gpio_ite_it8xxx2_v2, test_get_active_high) +{ + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | GPIO_ACTIVE_HIGH)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_INPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + registers.gpdmr = (uint8_t)~BIT(TEST_PIN); + zassert_false(gpio_pin_get(gpio_dev, TEST_PIN)); + registers.gpdmr = BIT(TEST_PIN); + zassert_true(gpio_pin_get(gpio_dev, TEST_PIN)); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_get_active_low) +{ + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | GPIO_ACTIVE_LOW)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_INPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + registers.gpdmr = (uint8_t)~BIT(TEST_PIN); + zassert_true(gpio_pin_get(gpio_dev, TEST_PIN)); + registers.gpdmr = BIT(TEST_PIN); + zassert_false(gpio_pin_get(gpio_dev, TEST_PIN)); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_interrupt_edge_rising) +{ + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | GPIO_ACTIVE_HIGH)); + + gpio_init_callback(&callback_struct, &callback, BIT(TEST_PIN)); + zassert_ok(gpio_add_callback(gpio_dev, &callback_struct)); + zassert_ok(gpio_pin_interrupt_configure(gpio_dev, TEST_PIN, GPIO_INT_EDGE_TO_ACTIVE)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_INPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + zexpect_equal(registers.wubemr, 0, "wubemr=%x", registers.wubemr); + zexpect_equal(registers.wuemr, 0, "wuemr=%x", registers.wuemr); + zexpect_equal(registers.wuesr, TEST_MASK, "wuesr=%x", registers.wuesr); + registers.wuesr = 0; + + registers.gpdmr = BIT(TEST_PIN); + /* Mock the hardware interrupt. */ + posix_sw_set_pending_IRQ(TEST_IRQ); + k_sleep(K_MSEC(100)); + zassert_equal(callback_called, 1, "callback_called=%d", callback_called); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_interrupt_enable_disable) +{ + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | GPIO_ACTIVE_HIGH)); + + gpio_init_callback(&callback_struct, &callback, BIT(TEST_PIN)); + zassert_ok(gpio_add_callback(gpio_dev, &callback_struct)); + zassert_ok(gpio_pin_interrupt_configure(gpio_dev, TEST_PIN, GPIO_INT_EDGE_TO_ACTIVE)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_INPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + zexpect_equal(registers.wubemr, 0, "wubemr=%x", registers.wubemr); + zexpect_equal(registers.wuemr, 0, "wuemr=%x", registers.wuemr); + zexpect_equal(registers.wuesr, TEST_MASK, "wuesr=%x", registers.wuesr); + registers.wuesr = 0; + + registers.gpdmr = BIT(TEST_PIN); + /* Mock the hardware interrupt. */ + posix_sw_set_pending_IRQ(TEST_IRQ); + k_sleep(K_MSEC(100)); + zassert_equal(callback_called, 1, "callback_called=%d", callback_called); + registers.gpdmr = 0; + + zassert_ok(gpio_pin_interrupt_configure(gpio_dev, TEST_PIN, GPIO_INT_MODE_DISABLED)); + registers.gpdmr = BIT(TEST_PIN); + /* Mock the hardware interrupt, should be ignored */ + posix_sw_set_pending_IRQ(TEST_IRQ); + k_sleep(K_MSEC(100)); + zassert_equal(callback_called, 1, "callback_called=%d", callback_called); + /* Clear the missed interrupt */ + posix_sw_clear_pending_IRQ(TEST_IRQ); + registers.gpdmr = 0; + + zassert_ok(gpio_pin_interrupt_configure(gpio_dev, TEST_PIN, GPIO_INT_EDGE_TO_ACTIVE)); + registers.gpdmr = BIT(TEST_PIN); + /* Mock the hardware interrupt */ + posix_sw_set_pending_IRQ(TEST_IRQ); + k_sleep(K_MSEC(100)); + zassert_equal(callback_called, 2, "callback_called=%d", callback_called); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_interrupt_edge_falling) +{ + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | GPIO_ACTIVE_HIGH)); + + gpio_init_callback(&callback_struct, &callback, BIT(TEST_PIN)); + zassert_ok(gpio_add_callback(gpio_dev, &callback_struct)); + zassert_ok(gpio_pin_interrupt_configure(gpio_dev, TEST_PIN, GPIO_INT_EDGE_TO_INACTIVE)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_INPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + zexpect_equal(registers.wubemr, 0, "wubemr=%x", registers.wubemr); + zexpect_equal(registers.wuemr, TEST_MASK, "wuemr=%x", registers.wuemr); + zexpect_equal(registers.wuesr, TEST_MASK, "wuesr=%x", registers.wuesr); + registers.wuesr = 0; + + registers.gpdmr = (uint8_t)~BIT(TEST_PIN); + /* Mock the hardware interrupt. */ + posix_sw_set_pending_IRQ(TEST_IRQ); + k_sleep(K_MSEC(100)); + zassert_equal(callback_called, 1, "callback_called=%d", callback_called); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_interrupt_edge_both) +{ + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | GPIO_ACTIVE_HIGH)); + + gpio_init_callback(&callback_struct, &callback, BIT(TEST_PIN)); + zassert_ok(gpio_add_callback(gpio_dev, &callback_struct)); + zassert_ok(gpio_pin_interrupt_configure(gpio_dev, TEST_PIN, GPIO_INT_EDGE_BOTH)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_INPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + zexpect_equal(registers.wubemr, TEST_MASK, "wubemr=%x", registers.wubemr); + zexpect_equal(registers.wuemr, TEST_MASK, "wuemr=%x", registers.wuemr); + zexpect_equal(registers.wuesr, TEST_MASK, "wuesr=%x", registers.wuesr); + registers.wuesr = 0; + + registers.gpdmr = BIT(TEST_PIN); + /* Mock the hardware interrupt. */ + posix_sw_set_pending_IRQ(TEST_IRQ); + k_sleep(K_MSEC(100)); + zassert_equal(callback_called, 1, "callback_called=%d", callback_called); + registers.gpdmr &= ~BIT(TEST_PIN); + /* Mock the hardware interrupt. */ + posix_sw_set_pending_IRQ(TEST_IRQ); + k_sleep(K_MSEC(100)); + zassert_equal(callback_called, 2, "callback_called=%d", callback_called); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_interrupt_level_active) +{ + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | GPIO_ACTIVE_HIGH)); + zassert_equal(gpio_pin_interrupt_configure(gpio_dev, TEST_PIN, GPIO_INT_LEVEL_ACTIVE), + -ENOTSUP); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_INPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + zexpect_equal(registers.wubemr, 0, "wubemr=%x", registers.wubemr); + zexpect_equal(registers.wuemr, 0, "wuemr=%x", registers.wuemr); + zexpect_equal(registers.wuesr, 0, "wuesr=%x", registers.wuesr); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_interrupt_level_inactive) +{ + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | GPIO_ACTIVE_HIGH)); + zassert_equal(gpio_pin_interrupt_configure(gpio_dev, TEST_PIN, GPIO_INT_LEVEL_INACTIVE), + -ENOTSUP); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_INPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + zexpect_equal(registers.wubemr, 0, "wubemr=%x", registers.wubemr); + zexpect_equal(registers.wuemr, 0, "wuemr=%x", registers.wuemr); + zexpect_equal(registers.wuesr, 0, "wuesr=%x", registers.wuesr); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_set_active_high) +{ + gpio_flags_t flags; + + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_OUTPUT_INACTIVE | GPIO_ACTIVE_HIGH)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_OUTPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + + zexpect_equal(registers.gpdr, 0, "gpdr=%x", registers.gpdr); + zassert_ok(gpio_pin_set(gpio_dev, TEST_PIN, true)); + zexpect_equal(registers.gpdr, BIT(TEST_PIN), "gpdr=%x", registers.gpdr); + zassert_ok(gpio_pin_set(gpio_dev, TEST_PIN, false)); + zexpect_equal(registers.gpdr, 0, "gpdr=%x", registers.gpdr); + zassert_ok(gpio_port_toggle_bits(gpio_dev, BIT(TEST_PIN))); + zexpect_equal(registers.gpdr, BIT(TEST_PIN), "gpdr=%x", registers.gpdr); + registers.gpdr = 0; + zassert_ok(gpio_port_set_masked(gpio_dev, BIT(TEST_PIN), 255)); + zexpect_equal(registers.gpdr, BIT(TEST_PIN), "gpdr=%x", registers.gpdr); + registers.gpdr = 255; + zassert_ok(gpio_port_set_masked(gpio_dev, BIT(TEST_PIN), 0)); + zexpect_equal(registers.gpdr, (uint8_t)~BIT(TEST_PIN), "gpdr=%x", registers.gpdr); + + registers.gpdr = BIT(TEST_PIN); + zassert_ok(gpio_pin_get_config(gpio_dev, TEST_PIN, &flags)); + zexpect_equal(flags, GPIO_OUTPUT_HIGH, "flags=%x", flags); + registers.gpdr = 0; + zassert_ok(gpio_pin_get_config(gpio_dev, TEST_PIN, &flags)); + zexpect_equal(flags, GPIO_OUTPUT_LOW, "flags=%x", flags); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_set_active_low) +{ + gpio_flags_t flags; + + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_OUTPUT_INACTIVE | GPIO_ACTIVE_LOW)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_OUTPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + + zexpect_equal(registers.gpdr, BIT(TEST_PIN), "gpdr=%x", registers.gpdr); + zassert_ok(gpio_pin_set(gpio_dev, TEST_PIN, true)); + zexpect_equal(registers.gpdr, 0, "gpdr=%x", registers.gpdr); + zassert_ok(gpio_pin_set(gpio_dev, TEST_PIN, false)); + zexpect_equal(registers.gpdr, BIT(TEST_PIN), "gpdr=%x", registers.gpdr); + zassert_ok(gpio_port_toggle_bits(gpio_dev, BIT(TEST_PIN))); + zexpect_equal(registers.gpdr, 0, "gpdr=%x", registers.gpdr); + registers.gpdr = 255; + zassert_ok(gpio_port_set_masked(gpio_dev, BIT(TEST_PIN), 255)); + zexpect_equal(registers.gpdr, (uint8_t)~BIT(TEST_PIN), "gpdr=%x", registers.gpdr); + registers.gpdr = 0; + zassert_ok(gpio_port_set_masked(gpio_dev, BIT(TEST_PIN), 0)); + zexpect_equal(registers.gpdr, BIT(TEST_PIN), "gpdr=%x", registers.gpdr); + + registers.gpdr = 0; + zassert_ok(gpio_pin_get_config(gpio_dev, TEST_PIN, &flags)); + zexpect_equal(flags, GPIO_OUTPUT_LOW, "flags=%x", flags); + registers.gpdr = BIT(TEST_PIN); + zassert_ok(gpio_pin_get_config(gpio_dev, TEST_PIN, &flags)); + zexpect_equal(flags, GPIO_OUTPUT_HIGH, "flags=%x", flags); +} + +/* The next few tests just verify that the registers are set as expected on configure. */ + +ZTEST(gpio_ite_it8xxx2_v2, test_open_source) +{ + zassert_true(device_is_ready(gpio_dev)); + zassert_equal(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_OPEN_SOURCE), -ENOTSUP); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], 0, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_open_drain_output) +{ + gpio_flags_t flags; + + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_OUTPUT | GPIO_OPEN_DRAIN)); + zexpect_equal(registers.gpotr, BIT(TEST_PIN), "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_OUTPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + + zassert_ok(gpio_pin_get_config(gpio_dev, TEST_PIN, &flags)); + zexpect_equal(flags, GPIO_OUTPUT_LOW | GPIO_OPEN_DRAIN, "flags=%x", flags); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_pull_up_input) +{ + gpio_flags_t flags; + + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | GPIO_PULL_UP)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], + GPCR_PORT_PIN_MODE_INPUT | GPCR_PORT_PIN_MODE_PULLUP, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + + zassert_ok(gpio_pin_get_config(gpio_dev, TEST_PIN, &flags)); + zexpect_equal(flags, GPIO_INPUT | GPIO_PULL_UP, "flags=%x", flags); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_pull_down_input) +{ + gpio_flags_t flags; + + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | GPIO_PULL_DOWN)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], + GPCR_PORT_PIN_MODE_INPUT | GPCR_PORT_PIN_MODE_PULLDOWN, "gpcr[%d]=%x", + TEST_PIN, registers.gpcr[TEST_PIN]); + + zassert_ok(gpio_pin_get_config(gpio_dev, TEST_PIN, &flags)); + zexpect_equal(flags, GPIO_INPUT | GPIO_PULL_DOWN, "flags=%x", flags); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_disconnected_tristate_supported) +{ + gpio_flags_t flags; + + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_DISCONNECTED)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_TRISTATE, "gpcr[%d]=%x", + TEST_PIN, registers.gpcr[TEST_PIN]); + + zassert_ok(gpio_pin_get_config(gpio_dev, TEST_PIN, &flags)); + zexpect_equal(flags, GPIO_PULL_UP | GPIO_PULL_DOWN | GPIO_INPUT | IT8XXX2_GPIO_VOLTAGE_3P3, + "flags=%x", flags); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_disconnected_tristate_unsupported) +{ + registers.clear_gpcr_before_read = true; + zassert_true(device_is_ready(gpio_dev)); + zassert_equal(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_DISCONNECTED), -ENOTSUP); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_INPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_input_1P8V) +{ + gpio_flags_t flags; + + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | IT8XXX2_GPIO_VOLTAGE_1P8)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, BIT(TEST_PIN)); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_INPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + + zassert_ok(gpio_pin_get_config(gpio_dev, TEST_PIN, &flags)); + zexpect_equal(flags, GPIO_INPUT | IT8XXX2_GPIO_VOLTAGE_1P8, "flags=%x", flags); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_input_3P3V) +{ + gpio_flags_t flags; + + zassert_true(device_is_ready(gpio_dev)); + zassert_ok(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | IT8XXX2_GPIO_VOLTAGE_3P3)); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], GPCR_PORT_PIN_MODE_INPUT, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); + + zassert_ok(gpio_pin_get_config(gpio_dev, TEST_PIN, &flags)); + zexpect_equal(flags, GPIO_INPUT | IT8XXX2_GPIO_VOLTAGE_3P3, "flags=%x", flags); +} + +ZTEST(gpio_ite_it8xxx2_v2, test_input_5V) +{ + zassert_true(device_is_ready(gpio_dev)); + zassert_equal(gpio_pin_configure(gpio_dev, TEST_PIN, GPIO_INPUT | IT8XXX2_GPIO_VOLTAGE_5P0), + -EINVAL); + zexpect_equal(registers.gpotr, 0, "gpotr=%x", registers.gpotr); + zexpect_equal(registers.p18scr, 0); + zexpect_equal(registers.gpcr[TEST_PIN], 0, "gpcr[%d]=%x", TEST_PIN, + registers.gpcr[TEST_PIN]); +} diff --git a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/testcase.yaml b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/testcase.yaml new file mode 100644 index 00000000000..67cc43b474b --- /dev/null +++ b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/testcase.yaml @@ -0,0 +1,14 @@ +# Copyright 2023 The ChromiumOS Authors +# +# SPDX-License-Identifier: Apache-2.0 + +tests: + gpio.gpio_ite_it8xxx2_v2: + tags: + - drivers + - gpio + depends_on: gpio + platform_allow: + - native_sim + integration_platforms: + - native_sim From 2812a3b24d1a18b0f9b9bc2d6e614fde991f7e65 Mon Sep 17 00:00:00 2001 From: Conor Paxton Date: Mon, 4 Dec 2023 23:59:00 +0000 Subject: [PATCH 1181/1623] [nrf fromtree] boards: riscv: introduce support for Beagleboard BeagleV-Fire The BeagleV-Fire is a SBC powered by Microchip's PolarFire SoC MPFS025T. Signed-off-by: Conor Paxton (cherry picked from commit f0495d4d472f5852906318bdf93582af07b3c12d) --- boards/riscv/beaglev_fire/Kconfig.board | 9 ++ boards/riscv/beaglev_fire/Kconfig.defconfig | 6 ++ boards/riscv/beaglev_fire/beaglev_fire.dts | 33 +++++++ boards/riscv/beaglev_fire/beaglev_fire.yaml | 12 +++ .../riscv/beaglev_fire/beaglev_fire_defconfig | 18 ++++ .../BeagleV-Fire-Front-Annotated-768x432.webp | Bin 0 -> 42568 bytes .../beaglev_fire/doc/img/board-booting.png | Bin 0 -> 16583 bytes boards/riscv/beaglev_fire/doc/index.rst | 85 ++++++++++++++++++ 8 files changed, 163 insertions(+) create mode 100644 boards/riscv/beaglev_fire/Kconfig.board create mode 100644 boards/riscv/beaglev_fire/Kconfig.defconfig create mode 100644 boards/riscv/beaglev_fire/beaglev_fire.dts create mode 100644 boards/riscv/beaglev_fire/beaglev_fire.yaml create mode 100644 boards/riscv/beaglev_fire/beaglev_fire_defconfig create mode 100644 boards/riscv/beaglev_fire/doc/img/BeagleV-Fire-Front-Annotated-768x432.webp create mode 100644 boards/riscv/beaglev_fire/doc/img/board-booting.png create mode 100644 boards/riscv/beaglev_fire/doc/index.rst diff --git a/boards/riscv/beaglev_fire/Kconfig.board b/boards/riscv/beaglev_fire/Kconfig.board new file mode 100644 index 00000000000..1984bb05c09 --- /dev/null +++ b/boards/riscv/beaglev_fire/Kconfig.board @@ -0,0 +1,9 @@ +# Copyright (c) 2023 Microchip Technology Inc +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_BEAGLEV_FIRE + bool "Beagleboard BeagleV-Fire" + depends on SOC_MPFS + select 64BIT + select SCHED_IPI_SUPPORTED + select CPU_HAS_FPU_DOUBLE_PRECISION diff --git a/boards/riscv/beaglev_fire/Kconfig.defconfig b/boards/riscv/beaglev_fire/Kconfig.defconfig new file mode 100644 index 00000000000..df89660bcb6 --- /dev/null +++ b/boards/riscv/beaglev_fire/Kconfig.defconfig @@ -0,0 +1,6 @@ +# Copyright (c) 2023 Microchip Technology Inc +# SPDX-License-Identifier: Apache-2.0 + +config BOARD + default "beaglev_fire" + depends on BOARD_BEAGLEV_FIRE diff --git a/boards/riscv/beaglev_fire/beaglev_fire.dts b/boards/riscv/beaglev_fire/beaglev_fire.dts new file mode 100644 index 00000000000..df956f5c8f2 --- /dev/null +++ b/boards/riscv/beaglev_fire/beaglev_fire.dts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Microchip Technology Inc + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include +#include + +/ { + model = "BeagleV-Fire"; + compatible = "beagle,beaglev-fire", "microchip,mpfs"; + aliases { + }; + + chosen { + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + zephyr,sram = &sram1; + }; +}; + +&uart0 { + status = "okay"; + current-speed = <115200>; + clock-frequency = <150000000>; +}; + +&gpio2 { + status = "okay"; +}; diff --git a/boards/riscv/beaglev_fire/beaglev_fire.yaml b/boards/riscv/beaglev_fire/beaglev_fire.yaml new file mode 100644 index 00000000000..64d34b454f8 --- /dev/null +++ b/boards/riscv/beaglev_fire/beaglev_fire.yaml @@ -0,0 +1,12 @@ +identifier: beaglev_fire +name: Beagleboard BeagleV-Fire +type: mcu +arch: riscv64 +toolchain: + - zephyr +ram: 3840 +testing: + ignore_tags: + - net + - bluetooth +vendor: beagle diff --git a/boards/riscv/beaglev_fire/beaglev_fire_defconfig b/boards/riscv/beaglev_fire/beaglev_fire_defconfig new file mode 100644 index 00000000000..a60ed8c1691 --- /dev/null +++ b/boards/riscv/beaglev_fire/beaglev_fire_defconfig @@ -0,0 +1,18 @@ +# Copyright (c) 2023 Microchip Technology Inc +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_RISCV64_MIV=y +CONFIG_SOC_MPFS=y +CONFIG_MPFS_HAL=n +CONFIG_BASE64=y +CONFIG_INCLUDE_RESET_VECTOR=y +CONFIG_BOARD_BEAGLEV_FIRE=y +CONFIG_CONSOLE=y +CONFIG_SERIAL=y +CONFIG_UART_CONSOLE=y +CONFIG_RISCV_SOC_INTERRUPT_INIT=y +CONFIG_RISCV_HAS_PLIC=y +CONFIG_XIP=n +CONFIG_INIT_STACKS=y +CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 +CONFIG_FPU=n diff --git a/boards/riscv/beaglev_fire/doc/img/BeagleV-Fire-Front-Annotated-768x432.webp b/boards/riscv/beaglev_fire/doc/img/BeagleV-Fire-Front-Annotated-768x432.webp new file mode 100644 index 0000000000000000000000000000000000000000..a4ba6b0d98e9e985397ab938b9c56f50fd3111f9 GIT binary patch literal 42568 zcmV)mK%T!+Nk&FMrT_p}MM6+kP&gnorT_qt1OlA_DgXnp0X|6}jYOiNArv{Ss3-)4 zrtTLU=9eHlT(jQWeoL`FQS_(iKfQk4f0Fls0|L}e~|D)KK#Q(_hpXYD- zzv6!@K4^ca|FQmS{RhH->VM?F?*Ezn_WA_=rTw4&$M|pZ-wD6z{^9$${@MRG@{{0K z^k49Q`+v!P|NOoGuKl+6RsF;Lf9;?A?~qUHKjgpi`&xhF|NriX{!{+H|Nn7s=>O~g z{(A6!=6o>!b^oLLkN=0^)BShi>QA|N1UN`xXC_{U@ov%)aM-Q~S61&-VY~e{g>0|0Vwi{9pO+ z+P_ZzF#m)8SNCuIugFK{Kg@r?e{}u3{~h~*_6_tO_&>@2xbUIdKihxT|0(Pd>vz&W z+W&fv_k;C+^B?p7#D4010RJuioBoIVFYTB3pa1{!KJEXD z|14i8qAUUCEH`vTfE?&-fZVhzDEp!;0p=_>V`#`O9Y>1|-4S39F=4x+ zEC4I(3K0>TXv2`=vGu(S8e)!nF=~diB=_-2S|@2*H}W<^uH9t3a{cSk_t4-%zq!`2A``jRv80YLn)m5aZZRUw~5 z(H}gMq_78=u-(xV%-==rp!nyqcc-id%v|cbK-Gn*JESMIBrLysSD;P!-OdSxv49GO zb^~o2vi6UbTxSOmsE1-e^!*wZCOA4Hl)04^BENV)D&TCC%$=s9HZ$jvbd~_~78|-8 zK*$RiOXSi2eBz|SW)&amLgeuwaCvnnXx{^cjQOIAoF~lezc}jRww&Fm6^)z`QtB-; z6p7`oFvJZxFPmvR74KACw}qfmWFjKkU{?fmf(MHY-4S39F=4tA6O$qWSN0DCGi>Uk40er`AsUBymYH##kNPG)UJ+yh~=ZYGq0Uh90f)awyq>>M;GPUGDBWqQld@JG&kmr`>%Y2skBx6kTi?;n)50Iq8y zpe`L#U!C8HKZxvVNNnVg1J%6|BOCazFH2*h)F-O&POl`{6+d+X%Lx_aKu{f{ox{(U zC192hy(YlFI?wef_RlIo8-#3^N%Rt4(bcL+ZJu$nulGZ7B#&0h9ly$JbD!2Zy0~4| zvRNp3Fsai(=UD|uiw)foU=J}Tx3EhO3y;t`GoN}2tH83yMKx+By(z!_GR~M=!lPAW zz88(LIWyz_(2d=Si)i`ZAQY(#s`5oMwziO!X?0JFBq}3?8ih+9laSsklyV4p2cX9< zDI^VjBJo8d3hy%|OQZ16=Er+$iML7NJ_;NnJB>S! znB=>Dx_U?~JD9ND(G~#f6V}qF>{b(z{7R&|hu5~!_-q2lY)Zu;m@2^d`NC7~g`BSb zl-NlBo%+lr-wrGlt`E5kjG>ip9~;0^s&V^@GT-qztH`8U_DWGPZfIBMsx3VY@a)<86-)I z7>ONq9Wc(M+3buqWB4XicA!7Z>0OgU&tIog{qFL}4II(%bIq$w5Q$4h$wV+`G~!}FG&gX-lPbHu{sAesrc_-gnACW-g-TqyKt4S*qT+EZ zbyGs-1>=E!+XTGy=WE9YPo7E9;AeSZJJoR|x~5bbXBRw!w+jyF=|?buZh2D_q&7K# zGHUSJlU#*cLP0h0CUlf~!Uh**;DHEeZe|9>Ij|%$rpZFxGp~ui>cC48VI_y0IjdI2 zsgG5o6~4b+-7Di;*7M?_S%JVDzM=S2=zJrnw=L``v$J$i=R*=-E-TurSJx^rzd&>6 zb)P(sxmW4KUwt!Ru0)dgvbuy3vR(tH(L>fj{+U!4oC0ek+EbLXfQRAJSFxMuDpp^8 zKFrH!P&#g2G0b z@H?eh%dDqc=A~s0h%lpIH+}tU^uj}tw67P}gN^SX0vvANgS3F~^<{w(mrvsfg^>8T zf(cnu2R9RYmnR`(lz2bWrmW&7l0X8rQUcQP1EaiGVbrnJP6x$ zL?$HUo|U=MX=Vx)O)R@*xr@%XzIR#k!&B}PkUl zLkOWpw*a&%N0U?50&8**0AzY2w@lK1P2nek8{`0aBmy*Wc|SUh;}lQNBS zr1W#->!F7oN;dR)7UF?gtK!};1@rAv*XN&ctEPP7dG7%I5LmdJ1lDZu{Bpx#e3xhu zy?dK0WuA{Ne1BC&5Fak!$@YM+-uY3sTt<5+Le;5{x+F6Avb(w)#9qG>e8VRxh@=&g z^XZunS>`|mBp!+&2?xlF)$>rJKRSBiecHTL@>z6ErW3*RI3e89H4Ee&< z*KqK~dV5_FU=J#@x2+`Y+R;+Dx&p29w}^4=vLTk^nb*J>wSO&~7DY{3gT8Rpa2nt_ zv2{Q^;fHo8uPz`fAo3+|ce_Z8A99lU(<~FcLL29C%j-Wb15|c&#Jr^Mn>OASIpK1) z`c<#fVqtv4OV}YY`-78>&mp+5D+x>1OIpb-DH&Xv%+6RYclg2}- zAorl;YwHr(uw~=kE%1@L*H&l-P&u9}B_*H=wx;tx1N|`wxUr$O{Ql1%x{ZDIUe3J>Po40~_R$ z6j7x5lNG<{IidN<-qd;7r&%X!K0Q`G$Uj`Lq8^78yUmAqXm6x$v-CwE|I`g8&&wYRE~(g9DjDr^DBmjgPiGsDziZt^u%%iuWG}|jjv)$uFI`90+b)_pJ_gCq z-q884$~c)DHdIr{Yxkk)+4Ny?7Cl@tC`G?mV8R^|{uPTU(pUq`SZ?gKIa`il-7aBBo25$)^qwqKO5Gu@I*W~1Z-FEoN$PC1%K-;rnrxrx<%Y=X>_d?-NPwJ zkYjT`UlXVEgdM2=rYZj*`+Uc6C^*ATT=MReIIpJ+UQkRjipscK$-s$zG3l0ns$jRc z#h}cF-;5)JI*v<=xzc}r${Z*Zn5%I{}|H7NdZ^#j-x$-gfQwXh^z35yW}P4DRL(@PU&>iI^amg3NeEo?+V|Y)_n3!*GLmL zLj)DCsc@j#Tjd1N<&mqab2*%c(T@b&l6o#3&rGNk+UMt6o}H6e@E!~>*GSg!Oc4|; zY}T0o91+}L-7*=bksp_CCSe9))3Reu2yMBi7`-=A=iKTmZX>$-U-v$aFsW)O%(tKh zsZj7(7E?)TIA(rEo`m_15M^W8(%qZqs`jbWAP+T&CH#-^^|!sT#04w?<}5dKMSwh@ zO-l$zf;W)HP4DFI*8x0;q}qKJtc-Jq3=NKkM12uaDbUvhGX%~NI>Pn6C0Zf_IoJyD zzTq+U*`6`?y@79ZzhEsGdG5OR)ByU|&}mi{A=Vt;7V8pVJ- z#fI*PwB~I2c`RLs(8MA3v@4%E)|g#fdLIwhOpDETiQ2x;=9KYN2O4?yd~VqngX4bCEtbTl^v{8 zsZWJ(;AQwv-xe|I;^YHN%+wYy8ORda4{KebCo}6@7A%NBspIRudMhqeSRNU%G z%d{^9^FR=%q5C(39bfPmEGugV~>pMO~J@ytw?%hj^p&@heMGf9mxLeN3^6PPn zyY0}Vs)0TkiaM{-{;GaBwkMRQE^_#j zZNNs@(EJE`V$>K+;|M)H)UI=JlJoKo2w|wB--{v!Ff}Db4uen<9&Mm18kT@0Cju#t zGfTm~m0q9Pn%PX5A_*OuVZuiF(PbU8+mC2FM*#+YxI1G!)t!`crsqte`-~XB25KRzK&|p_PK>uL3VClKVib5O zn3SO43gu8L=+a)HcSYB(!x~#tq@n1edN2ii!8XAFNtlafvrJKyt6rgc#px4Ew59z& zWC(gexoRfFkCI3?YGRgz`ThBfmpE3njrpQ`SzO$`2ty3VH#PxH0)T-y)pT5rzN0Q- z|L%?w-p5{18x@>;YU`mwqCkK;r3>o1^C{NoG2V-J;3HeWkBn&@+|a)nWWmVc+?%^+ z&1r8or>`@-Iqsw*P2Jdj)c$-95j=270#%)+$M;Iuxzsp;ss6JpM6bL?Gt<*ENd@53 zo}ZS@3j=I3`#Kri#?81dEXrZesUM#3&#A=z*}Y@%cX7M@aH1PsU8K`Ib88c>QxkiV zVr{u?WvMdRGtKE;`6BA3a1$pAGZPvi703jS8~ zW!q&iJnfK8i%{cZS6j_U42S)>_JLDu;Bf4t-kI>!CmBFd%mixU`T}o{-etEiU~trq z*H!&8?%bUQ)78vY>x+Y!Y$nd4Bzc)UfPURqUzoi#FLANW+oJ-~b!DQS2sj|&^`RV_ zde?^%YT1895!u_gfA(*wg3C?%Dx+Z`{1oni-yQQTa3?7pO@n-y>fMgJozgd~T7l^B zu#)hCUbJ`kaBff>(FNrE2raozZa?v@C=gNCmtQ#@31(XRqGbnGS{c;UmhM)0IOJ|D zmh4wbQd69+6^zBG>khqm7NBNDv2fI0ZfTV)09`~=f?7}c?#38@QLMSU3PW2}k%fL+ z#=TNZRHEI7i1H6e#+n(`lhlzwlmHCIO12KS#Q!GaqMc>3Ie>Kf_)x*Psmx+$}yOiOyGR3Za$i5Fu zY@kBWw-ojop+3A@GtG_UQ3ntCn4H!;;>l_Hn)nu~_9voutgCIlB0EE=2*rB#>YYUU z;ncZ4O9*n+DU>i$l#0H8BuV6RA90UJxcf*7hqAuoWWub!auj$^WV#-ztq5$xZH+g7 zXioS|$3{<#4qQA@k52Ontu}&XWg!Ei6T1v3o&<-NZ5LW#>6i)`HMjD6saqZ6&1~Vt zd@p5g1luaAkSIvPYJm--r#F2@yWYh28#l0M?4{h$sL_IrbmEtPR!51ArYr&(g@q)2 zJe63-@$Xzl8vMPLs$LRv^<<;pYnFm?mGHj|ZTb;PP~O7#^LTkQaHoRw4t%n* zr*Cqu?cM|l?dhFqiUW*~#z(1U@ezU=%nXwSg4jZV78T1H&VBZqTqy>9Jybp4eN#rT zz2fR(I`7S}(_B##yVHAbML;-*N+EZ^_(1R~tP$mSVV{wTV0pgL_JMrk ze1W`efCZj?A!=MO#P`E@JF@hyS#i-`VNgF)o#NcnfqVufqWRf(+t|IUEe|u9^f7#g z81c1%bJ^?plcYBE@#%z`N+T}kdv23$sUY-nlugD3WR-ul1bjCtXjJv`IDW_rL=nCc z*w6?NN_Q5_py4W#Zq>hb%%66oLuIrSLw^4=cdj}e*vinU96LCMz?W*VG$E|Bhi7Ot z^~_>Ri$jxvLK1&@@(_w2mS16jYzyJz!qk)gpgkg3;y&mx)eF`Xl2@Z^UinAx|{=(PR z5-@;xAWX1p`o%2c5Va^IcI@>dJ)Y@+>p@_iKMe@UYeaIHVHURsa}UI&s+XUOk#d9W@0JoWAYP`~qMHo+>fO0`J%b z{7u8@E!b>yCyXq`8Y`}58TB}(@}fHAJrj-`-$G|Mo5tD8_h8ORo}2>kY`m(J57Y=M zgyNXNK&GcfBR0A!ia+hOa6t?LdmSe@d@Jc6n|Ok~(HJlilXS*@>-S2jK*8&8RBoHg zUZ3yaKzu++zF@UbG+p1pA91g>x`LY9MU=x~8_DkUO>Ol-mj{-4C&0FGFS~_h%zUHA zCqG+V;J4i6=}j7wIgpCvHK2Og%U_c%1EqH!?_)qN_#cM;l|a};%G#8`M1*&)bJl6( zYI?nd0Uwqdk!CaSRyINoN|CyHA9#=n>@|rL?@a()gi$VmPS0h-%a$m~2J@$TsQsA} z2>6jWDWgwzJs19xAIJBRm$l9X{!iLYWHT0`(2jvyiUeaw8tvq&Y zg&V9PP#hw%(-qjz?mj6Bbhp<@o5yJfcWNXxXp1byCbU@Ybq#mR^I@W8tj#gR=i0yp zC^L;ZT4wA?C(4K7&kpzOcnmMaTsL>1HXjDmbpeS#ah0u7LQY|Qot~gz+ z6}>ZX1Aoqs=9bl%gilEdnzb%130w78)ED2b^-X0E;sD0|yys)}`yfTo50;Zoj3gJG z#xUmPN*$Lx$Yt^#3Wy8B*~-q+7H!Pynv^DY_U;C4e>?%M1%Vl?eswYjSjm^7-sr(z zq_;4qFu@zTk4{WBeb)G}Z^LqDA@yo^QQ=i7gORMO=N4-bSC|F?RU$9puw9&kW#705 zzB|A(HPm-UrJK4?llKA!?yn*m_YdL6@VR|zHUStw_RCgR&HolkkkiN}N(7yMgo(c&RZ#UdE-2D-fqi;_~J-hhlHUOv!+9RkAJ}^iZkZcD>>f zQ)wke-(dDsK4m^KgV5Pz@rwJq<`&x3s8s5+$$VuhwhkDjElXWODxrON;_-~*`V}+K zf+mHy&Egm5Qv<7H=A zzT%~4==p&_%&#IQiQbRlwC+c17$|&fpou1}0io3bn8O8hOHmlsRXyzP@|%xIG+vr zpT@{FQmQSd3A)@0aM)do55fqa#FK*l?-D1#O)l*Hb=LrM4s_PH_o^Hq=omZuX(h~J z_s>O6o+Hi`qF#XC!FR=kpcs_h>b5*~CJ|C|oG9~aDjb{ymzFdkh}F2BcyB{puecPr z1B@8HugVKT}j7MOFQRy*NOrXJGx={|aBa$RR+A$ZA2RFb6EOsP z+2L5dPy)SS*<_U?)1RX|dKHO)*=cgtj+^RAk7-*t*ne{wYSn_UdHEiO4oDfQ*?vxL zVgS&bgDL9LTFU82@}Pfril$pg?*bJ7v?!s2J&`kHajm%ZXqeURQ6<_stUJF^!^{WE zQ)KU_N~m7$|Lp#mui>(F#U}9^hg&5bK2pYKPM-*wq)e=o?#HmZ0QiW(w<8I1R-~TJ z0DtftaozD`XcenmxDxB``DrFl6MSss9fsphQK+G0G(y2}mvq`YNAz^9N|>vC&iipL zF$T0*=MuSP-sfD&`o>?oP}VRxLX~Qb5#&3L(lqQR-i1Nji(&LM4r%PbErNdKZ>>Ne zvK~hz$bcJk*NS|438quY&Ll`ttlsXWYwG0;8*^W4O-5w<6A2r*qOX})W2u4+k z%-pmM6xaPfVZ}{RmA!s4;@eAQ zaPY5;Av5fsi-)|BLvgZ0oYp+Vgwj|DDVP!p98)OBiN@@3;`v7R^%}rj zW79mxI~*f7I+sf>!8=kVp*9~%y_X_3tSbUjF-w2H%@L=nk3R*c+R=vE)wn}`nA~JF z3{CWL;t&RAN=h6l>DD1w=$Xe9kPG%8xeI5{YYT2Ar_dvka#alyu3}>f6AGF5gEzv4 zH}BCAc493N{HkYs^&>8~p7I&!qycPnN#jI0B2KmkwPH0Hf9aq*!eF==1R z=2VOswoO=5Ynwe_Flqve-N^Ic@IqA4O(k{aKd)kmg%CsZr*DYh<;*?;byO{DxC>-k zp1zsOj8JfLJt`gVuj9DrwV*wxGu<(-2V&f9)9z7B<&%I^3Yq~)?)N@;^)*l#J7H@Q0|H&OQP$i@6*UOb1elQi{~!orbKYAM4%>TeU+&<%V(Fr z$urKH7$|_7q0Sn)kl5sMt;)p#HS~fMgM)Lpe|7efR~Geu?uAt0H>({B^aSs_FtlxYl;_tYWO}h^BmsG+Sl3u|_{A#UV=aN;E_@h&G5V0uGv)dN_P2!3Adyrd@mJPAd|Co>f6gAaL`#pgwz?2s7ZEwIwf~dP*J|r}CK#H70kr_Wy=%5#dUNDbrhwa2p;aF8w zrM@9KmKL7nSmLwX48eTjww2$Qh)_!NS{8a9Z>*h@g6(Z1hY)!`oA z=Ikz|2Jr6-t;9prXu(GA*T?UJIT;_%x2NiyAA714KKA9*n!za`Dek*H3U^;`-qJ6i z>GT#Ym{fA4NQM8|0kO4NtF$Sk-L45N^ro6m;2fSRyd7{@p1zJ`UWo25;~uQxjgZN+ zMJ;E9-BBl~bQ7ncb%G2Xkz>Kc5_E`#ck=V={9aad17lejB#ZRI5abNHB-OtdUkHQ? z=nsGA-_D6qPt8GtAB7Y*L)@4*mw&Pk@Jny%0dvZ0j%epgLvxVhI&uEJ3=h$ z64%T@r=HVId0D*XRuAA0(AwN%G#u088T@WbkC$m2j`(wkHdO7fCp{Y@hFi|exrP$N zx6?I={N4u|OYSw=u^3bsiuVAH(h8EnBybib6QzJwJh@+a6qZ+wbGos(M^3#-Uzw(7 zjHCnRg?*KO(#ak?=AzmxN9r&>UXRR>5#=(U@c$2jn$sZ2y7Fhjb$bm*DUuVB|1t|)VjBfu->Vh{=!mJeuQCrSn?rf@H8G}qmyLgw?j z)z4>HpeZVx@rSFQiJkZtw8=eev@{EI9pW;)y}?D8mFtA7)E={p0ZSwlA!|>Omz6qk zl(OmiM3CYYr+IYkN?MAgryn1byUnl1O@|F;!&>2bbt+qnS3oPkT0rGN7VMXmv}?&? zInW?S!x{&rW-)BMf9N|B9~!t|{V_w{dDyMNYv8giXc%!lIlJeC4}WPQawjW-$7gAj z)#F7X_JFq-m%u0QySh-Qg=WSQ!hs`~AKYB+Fqgv+@^JI>JKQzegyUjrIm>b&2CytS zV*K^V7`BKqd}8f6zxuJ5FXBq={`nuLQXKZhg=a8`6iTYW+Zexw^0Wa5PSk^&DW_j3 ztJl5XBug#8c+)6%&0{g0f&p|(v+)OUf%G-%PDjmY?~5y!htZ&T092wXymVChjLoFu zVfv7esCgHz=iP?aPdaO7<{KY2V5uAFkeq1VdpkD`;n1HsS@ukE{6MQf({~ifX~E&Q zWsiN%C{QjjU^m{>T2t$CZ1{*6U1Rtb{27j)E-q;<3CZS zH7jq*Kl>D0x>SKt$X+}JY<0SCVA=WG0a*3)Y*$GZ0<_mVw6tNH94)1{OnFNXA?|Lk z*ZC`aS+QE{plv7`<(3I;1S+6jeBTP4fe6R(>VjIi-CEnxj7;9`A)B?CSJ}aiFwi2u z%n;f{-o%&yPt<%$*8@Iz=A^0xfTxK{X{ck&95z`Ul2Vi>*fIFF`ae1g_QZRLb{bLBa>aPzTcZ1=0o&q-!sZ zjA`}Nz`4|FAkK2xh1dZwDd1pb#xnAvvyyIAOG`qv7z?vU4EI@!cv4mAU=r==c_7k*vocQi=PIDJ@Hwa}~C@RzVSOB`C6 zfrfk5HepH$Yb}>ahgMQB4$#98Jss`(2}=r$AnRIV%+^7AF+?Qlzv=@RkV2LUz&NZ= z80~$EmZz7qP0fxgMR#fTMN%8O6=q5JJ)t;ucPcS*c!9CD4<5?!44V)I^jvWyag&8t zZx&w&Bf3U*Bt_T<)6-w=sF95X@a28j@TUcW6g-hrkq&z{FK?q(8YCZRo}beZSWpSE z@iW}QVPA#(+W+2(wd(K3X*cni%HyeOQk=KyeZsKJeMJ$Jw$fNR!3Zp-Rg=Iud!Rv9 zHnu1BGO;T~C%y1ExbI7Qqo*q;-17b_Hpsy&?zTKo$;8+^*i)L`+=mv^(&Ym1w~EL^ ze_s~vO|-Hr`XZLUe7CeM#xS|CrT|+CHGiC8*0aDCBJB5W8JOut6-!p78)SGnEM7n6 z>52?(WpP(@<|PNV^YZ~n_bcLLKEZJ3ti-bu#zb4egy2PP0`&Zs+3H7^0K88ix#RJi zq*UM`Je$vj%UqX@ z9&xXxihJjj#Hh=A{@m0@Joe^Gy#BEnK1a$}*WdL}0FI@`$RO^Cg8XK`E)OCbf!)cs~ z?0aSf?`3b{JNH!yIizO75psYP9)(^QXmk%o5e>)PfVe5J$*iclydlkpV=8fEK7;3f zQn)D{ngJc9vJTGa@^+?(q~?s~R&6in14xQW;l*_{iwmeaMZvrq6oG~`dlOGtk5|9P zn}v{ka{iCp?~KViBstuG_vzGQI_sh_bxItCa#=ELaYY=zvBnZy41E#I9pGm9a!Nkn z192TE4m&U=hcK)sNVluaAbg@x^kLKa8Nkb*ZUw=nUU_g$!}J_*(Pe+-MJ|&pd`4R2 z`c@7mR7znqZ*azc>G22|IKY^T!l-B>Uw7j+oHUeAY3f(N)JLmz8(@@UV>F}fh>BBi zaeiwN50>97Ki@9qP1&w;s}mHi5*npyzX9!24U>LdefIfi}|p(Si^l@ z)f1_jl2=fmEZj;<7~T$nlg+M8xi)1I3`z_=74ezmu2+g94i3!ua>ZhSiVREFeCtwo zM|-8qo2#Kqq*QqL@1K^C^{Xh9A-X{6PGqB3!kYHnJA2|X^U%Y5VZG9d)=YEIsWo;L z$RNFNR!7q5oz@}cF|4lw(QsMpwTQDhvt-W{`YIZDlqoo1O9?<_!BF7v=zn z;EUW06F66hDsL^Y1gn$}g%9R{4;Z4ey8XAmDwlBAl+C22k6L^+BEe5A?6)hG9#-bb24wf=s{G}o6pLR7N0DedY?SY5ZWmqeEphm?* z{=fkd(nm377~cq?rBqn~$PC0pP#naaa^OAX7y7_=2xGiGle)!4U(G0hAKXhQ)3pUBTRNW>3_!~9s4-OT~EmL z^o<3(yiI~_KQK72jJ?8Q@aWCnpB>0dfiO=#wEbO3zd6(g+C4MGrwzBdVl>_`Ni*1K z4!HuPtnXjVEmg_?mf7i3FMHrk#C@beHRc!v4b3B~F|V~4Xr00$2=;Uq%jJUi&2Fp9 zeZcv@Md+kK*A1BWLEu)yO}n0>Gbbe&y@S-S3Q{)DN;=nq#DA$!$;sD}%j87#y*|}F z6_&Ezhmm(N$vzNK$TrhIGZhf)bI|N_c~B?Dc5dH04W+!~FiBmj*&{n(0V4A!7|w*E zIclE=gYA~^89Rhc&0E4RIdGREt5J_G_pwCoV z*>#nBJ}-yG_|A=u*$57I2h#oTnR zWizfiv|VY+g?q3t%CCU^V7Fy`PyHb50zg3NnM>63TnM&A?&4IW`q(DN!hvrDh>10R zhfpv`OPz=$_SiiN?!u}XAtaw&_Tv%~ZBA6+c#X1e6m=Sx;WR)bNH;*uB&Sok^{;f; zm397I(5ouWN$gg}9oEQBd;=~b-D=X^otXvKRE;B|gc7Z@Npd8P<&bk731T)&6W{X? z828e(Ya8Dl@?aq{B2&(?W8yp=$F`u zGT2R$e-konAPzl06$Px7ABnJus+?u&FlNZ(@=msNb&+7ds^n}at)T<{H z*86}592uuc>jK(-$XVz^ z-7*5*6vh=`FKM^gVS5@;Na?f6A8OtuXO|){IryMf>om{i@n=fy|2$Iy(A|8q%0QSX zHNZI^7gC9{Q}koINj|pz2tQ>WrSKIjD{t0aInXe-k{g3>aS7=#Y!F<)B8M~tiTUbR zkg`6MYy&uKzr2m04Gb01Cg&1!^9^8?9<1+6+1Eq4laO#h1oTm>h)YP|Jq|a(2E;uX zz$cin`(lEwznw(20F3Sra?p}cYdf#mvv$U%Yo1%GE@FCfSs(lIX+@XU#q1X`4Ldx5 z3MhkZP}CZb9}A)l5hu90$I;nLdW##42DVC}hV4wX?mJU$#VjG4{b&p1^-))=Nx??% zoj~bH@O)SE!KDn}F;7nn9wYmbVhv^GzHMt8|2gT`jsO4y z_x06u`HP2u9e9RwGy;PAO=7TOxF`hRJliA`t5&K2B>$$!y8UaB(w9?&Ac;g0rxc&J zWx3oo67(s(L@W`FHZwHW%<0MPdRX8xKqx9VPI=n~zmrUdNs_~4^sYJRS>`QC%=0fp zxW;@R>vljyzc}q^Mcuo$zy9=MxAVJRlJ?aeP|jtVec1m3VpJ|8H)P2BR{PwnJXB1d z0wf@~%lb>k*>3~un_wZ{$WS`OFMcQHzpoPzI4~RHIRqnJtsn>ktroR?;~)VLFG46v z1yV^#m-|}Kh>O-B9$W55soxKipz1|j-!R6$BNL6yb*S`~G{66OIU;lqoi+8iZ zXb@Ye<|#fQLUFN9k&xD8V1t!c*`J&&4{V*a3C}O~76Cyx?yw|wQO9A~*-6LtfQPONqn+0i9qVq?6h zdW`}*$w%pcWSBh&f{h=O_0M8}uZtdT|Axh63}L!)Zl=ujIuA#-vk7#5PI6N46&!T^ zMwn&WtTl6=V3xEt;UyV04znYINO)k`8)KhL)f#9lM1n^}+>Nd)!}4a@+D7uzO8-Ex z$~=BgwBT6tm0Cr!*u>nbM%pc>s!oL{=Oq1@q8^E#j@1fP)02ncF>)OB#}l~TM>{4> zCSsK+-}Nv@q>h+Oex5+L+y_tuiHT-}?aCWF#FaDiM<~AVmhqYjjbwsSa*~R6?r^T~ zC_`Se8FrL9aDr-tQu%R6yegPT8pp;BHZ0cEAjR`dW)zECN5F3lyMff$1bQWM7Nn&n zhzIxgyUfpdW1lbNAbnLQuB7QZ9CW_WSpo`=K%N(+od0Kf3=uR|W(NnKIe3!|uT<3; zCJCRi2Z?r+(Va>T1JYr8G{g#aq&`Wfp97YL1@hcpwXYJRLWJ2DBf{&gb9)&PGGI*# z7Ef@n@)apVSD0?Z$6_&s|GYT7EA6Jbo;q4`VyVp$f*R+13@8j$*SY*7l#=S)_qyL- zkL<1m-39*lZEB{XX#ITv2EfGk+z2f&dO?b-7kyHc$PRX)FP;O`qYj+wbOdzj>`gTH zg2H;{mK*7II z(ix}{$MrjK$}BVBo7DJ<67&c&AlGhs66qq7wG4?zo>aQAa%9AeFy2C}M#Zu6TwciO zi~-{d%L%45u;8NnOo?X*!f;8ssNnjmIfLv8)J$;b)k*N!9X42U=GamT4fp@Bhu2BJ zU9n31Q>RUnkzk1^hqNpFlMtLkSFk@(ynwDk2ID_+$tg9~fha%!?qj8!PIRRHWIi$xjx9=TFHE35D&_JM@GZ;ULW>&Bwpazgjv zQf*3kb0|f-kdx$v9nKYu0|Rs?c6U{LDHIlf%Mfjj*v2h77&atG^dFt>8-X!(zeVO0l&&&9Y{@Ifk+Mx60y-A z;^yhZZ$-PE!JM=7S`(DNHmj zboPER(8!w3Ki{-2vJH^dG@Whb621|pcQT`6x9|Kn75*$at>@Q>*b6Udc@yyU%IIi{9>lpc*NC{9tJ<+R~r8? zljRwNy*JhqT!`W989B$Xl_946(zg3jDM0*N^}D}qx>u78ayX-#EHP*K_U`$p|Co%dUqB2O+`cH+nU*UKMjfDG>LIlHK zv40&<6f8r4R<{ht|3d=u+r#hx}I%5t$|Q+8dS#U8Yy-g7^{}f2e=68{6UZHq8VJO7z4y? zW}5(F!y|h^@%QJ>U+~Z4h1Da0@I^NHc)s%fC9BE^H90&M{RWS^M6#1HmF`1|J~#?d zY(+T-qLfoW!8kwu4_>X?BcGekJ7@UnC1Ni__OrYra$Z zSR?f4Gzy@O>!NajXphsV5Nl;2e79FOYo-{W`0`)enP7T>^4w}Snkv>iP(!=XjjYrR|;GAiwb$MzOU zF1K=@R`ElyH$8gOyH!SYVC|bLqK*3VK^G>!y!d}SH7fV#q!)@%?LZ`WtFnOzBUF~O z>FYtu@D0G5IOG|RO^SEmd`U7-1r8y<^!xn&%rj?S} zoI(!fnoZ9o^S(A6uO~)TJxz56^qYECk{f!D9P0_$rcxel6#=}RmUS`FwG>>Ps568= zEWHozuLb^Pa+tO7j{~}_(!Q4dgSr6)FH?%r-YJvHyqv9pW@&dae?DMa_4n2wNPT3S z)T&AL#Q=^)YB1p@uJ--7{~4!2`B_rf)L+-pWn+n<1NRqriXkioCC(GD%S9r2n? zlrBNNI*BdOm=J*g`!-ddu+RNzgJr=ib_ADC$33vl%!+gu_6f&gcp9xM$*SB8p9pTo z%B~#P05d?$zq0-S0X7t6|KL1D4+IR8hV+#hVEo-j;0vl7hBBGWY8s#lMMUmUt_Oy>`|4h zGxyWNDpmPbc-y$0?W4sCA@VZNDNHpt;9*HH>KAGav(W=+kvE$oZtBRQ^Iyc2S*K7< z!>^?|g5Sa2(*px54@`-K|KRFxV5y~^UZE$Di^+?r5x^xlDOgklrDCELF(Bg%mb3m1 zZ2`PJ8%D`br@>Sy1{|-Jz57!0bd`5!Vv3)wMH@G!p__5oY43;6m7LV`PhI4N??ZDljKc0B4hr>NO+tIo+<|XEg8SRhCV#6RS zM7c%zk!q}9%`}(=29w2iPml~aitlw-_Y^ZZfoBY;XGP~hH7tOc6dfb9C|n{CjyKVn z4(O7@r$qS3b3Kl;gCyOxB`-h4(VrIt=}(c^M^mdClGY@#^jQodkmAsOK?RYV)%(2! zZ4mGwzrrCP6f@O)PI~CD1`3v71U4nd4O{~MiU2D;$cS-BOUaJ^7)H8~WYs7&ttO>I z8Slz)H~r0W+z9BM8t|Vi^#SXh-2z#ErbeWvK&CZ+Zi_KZOT~XHophC$v#C>5D?%() zYlA2zFf`ONSOfT|#uJhOwJMU%`dokJI^25>KH6ATbVPwh>1^CBf({9za-2$H!;H4={r zsC;JL6|!bFA3N9zBElD$wwp;`D5Jp(#6-FM!yNTACQOU)_W9`x3-OKS z4Dvy@Ie=TO(XcjlEtvBmAlQCkMp*2hT=kjSBV(J=AklJ<$sY&%-LPCM0wiv4d$ zJhI$!__9qn|WQz&aL(pwRqa$aj>iZ6JX(l8Ng${p?&KJ23>>q2Xyh8&AJBjFS zs|&3=_J~Nf*>tdm@sEwXRpCbGoHGMhflbySH?^fqqBMfG^h%}~UN!H^w@ON2)n4v7 zTEYHD(=B}sL2s#42kp)@08DFC>E&NLx6$v9-}4|9Zt?DiLV7dbM?JRn>*D0&8Dt$! zwpv#dIO-^Jh%cQNP-95AODZ9cM=x*Zg3F09$bTnzlm44cJ*=tecO3U&OK(FfROeILE-uinl0X+f^Ny&IFo{bxG*R(Y?Aq4M_`X)@J&^uyat6X98yho0 zdW4aEwX8wiELjN`+VK{A8N%mFzI6(v+spUrCf_vCb?6*Wmerg*^wz*_TinT{Lp+m+ zPbPkywpNzWl%=sS1{`jCg}{CZ-w6qxbI|_^4EF)bbZnbt+fwW5w-xL(KM`!-=uA(^ zCBM2HIS^4ArKYJE3+YVo<6KvOhPX#l4&oJau^oEk_)-B1xN`1mAb35!roO=)&DxAf z*zFe+VA`@Lu#^LvCc?|S4C8VFAL3WK1_9YDl3Xh-!gk726eXVFGh2RBEof_U)DxMZ zT1a*RejQ@JDN-*_QB3;fp(TPEtd>& z`HblPQ(q{3tZIH3V(Ofu+FRr8Ai56{x&_6d=B6Gv*k^z=t!x!WS`TsS4$2)}AU&ou zZ0>wOrC>}QP%)UBJrXY_c1#Y~Gm0lIw&_(0$!a>`?L@@|nVg;oA}PGR)-E1Y!U$&` z%V@l@39lC=hGZ1|MQVv0L~pTOr|VBaQ@Om;-^Aivb5|RH4(qa>bN9^Vefc8XVCfVDbsELNsI8Q(ImwTG%p6(-@3P zz|ot*`N$s?ir~5EDOnZEXTd!ssl10+!J3S|nIkDxoSpe_en*w(06TEXQX`ws`l%Z6 z$GeOHfG1MEkwu;{F{RtbeG8H-Bde)z5Zop~6a7|c-oV3``J{)Kuw9xVUoyUImydIE zbOGyGa`R^Yd;2DuX;Tf|`AgyWweB=4c8w4oKsH5p|xdcCRiq6 zb1yx5#T>v!+ZdzLw=ar~Yrj^qYx?+XDbzL6KD7GWZ8pkrpgz1=w^(y0eL-G30Cf-7U_@$IcD)reV&*QjPj2ZE3=25d%^-woj(9Uj^ z=%2J@_~eJ4PB%L`T0Kw}^%{QSCsu3?jl(6>bRT(Lb*&Sw&~eB-P^XU6Sp)+JP%EjO zu}xOn!z5wc`OE&p0C+em|`|ybDa3R<2xrYX0L=RWH~U?V9O%v=lqL?-Y82D_l2)r?}(J z8v@+yxnNx}8>@7IH2`+7FY15(IYYC(>gXeCa@)I%h|zR4%W)(8yScu1DlwYF>LQ#1 z`sS!wH1QRWi)J%mmN0i2Kg698Fw|Y2@?uTH1O$IxMqkco(!yiL^dTM+t%DOj zO*v#F2~BG$%d#hHa7WgwPx z?#B6JYcl#>PCp2jPg78UqHZCYP650#Vo?@r#tlrd>l4|22`@&-4-AC4 z_W6J;ZV!%#$zisXt$$qbD7?0gtiCc~Hij}Vwg^UJcP(-rt+t7PNVw{U^)c2Rk`#@0 z`h5Zxi}RB+K&t=s6#DLj(K+WE@dC$jl5O7qe&)_8Vzz5xIqxY&qy_Ebaoifp1cn_d zX}sxc^U9v^-Kl`2MG~(^>dmnhYUhkWLq|WuMC~mUtIPH#x!D)<{L_)-x+vCzn9V*j z?HveUeyN;v5dKYmzo7P(>n9|<%xRbLJkS&&xVYSYRhb5`YcID4)zj& z+d6^*VKBZ#Nv~5?dy~QbcIld9!oB_6yKsR0Q|R2iIa?5fi7vJ#lK+)eny<+x?s;$~ zva?r6{y)pMg3CI7nHu9Qj9Yz$1z#PrW|IIKpJcg-d6(UZY0VJQe^f7|9EX^1mh+I3 zD-}L16H_$dHRgMR%!J@O)9uMWc*R0V%HjF}LuRfTrH%g@`0b_+JLUTM*PoRqm)Mf$pg+B zj6txh=nrAB{wK;pxtyya`@nMF?NO9alx1-ia)juGWW2cJkmTE})mjnUN^Am(D+5Lt zJe2T9Pl;V|5An+}fSprfE@!{!YQd>}#X%N3!=;}HVp_#{+Ezv8U(l*RG# z=2spnrwu^6I6=l;1w6H35R ziP8G=Lu!NHSN-`{XRAap4`<+IQ;ofUdt4Rd?PrU^@;#kUWdO1;CQ%67`gC~KI5psT zELIm1&7`uVbA#W8hnno?QV-?)z#fi6Kt32wN^H5k+R%>6-daKxLGH5R`!HAmml{02 z59#X!uQ(hFg{|vd$yC`8z075;nSv-+t$%rG;c>`%g;9y5XJ?=&yzU>Irl$xUe$k zv0eS6>G6|x1tBR$B8@w{Rx!waX@3lqlY?*_ZuAu`fWGyPg^#3-Iz7Qlc|PWRW*?RQbSYS&foA zE4&vXX-~vM!aJrUnK2gS(l^!?AttSDm;xV=YUxo!{p>=*fZYPH0IwzLA!SCK&q;9p z3f1+LY!SH5_7)eOW-C?$Yi4@i`Iya10nI3Ve5J(%9llX}pNID6h^oJmouT7owCln# zW9Iv(C{R0j3C=sy943C?@lG)JGPLO>63z_nwTU!GU@8gao2$TF2{-#nrMT^j`IfbU zCX|WfZ&Wr%S=Zee0o!PUE3}gk<;`pJ1be1Qh*B4aPkxgBXjkHl33&%1;oY`*2GEDU zGyWjivV6E;6Xv<1wis`o3hcXKg7(rOiTb3br^4d9+v>G2z})yNemcS))5K{>7RK}^ zHm|~*axE2aFkl`LBNCahGoR{9R^Z7R1D>pnX&_iqG$V?F)a$p0vCUm7b7oJ@(XGY`732o3&n-bY32t{W5GNt;gHIqd-u`I9nTc= zY8zkl+bptn z9mESZZLzPd{xLXeJ(@4%SwiBey@HM|%H(BL?1 z7NhDw-k)SMJ<5?^6Tb^89mcu{52UcE^l7J6}&5Cy`hA-k9nEpQ%;X985d6bw8Ryp;d!gua^JF$*~OV50z z2HUTH=ApKIWc`rO$U(ic=Hi(X&)w+llKW{dWc{*#Hw#0w09S9*!2Ix4;j%mifMXOAy5x zd2wMo(?}b)LDK^#)4<8=JF+rg7POM&dvq{yqBe*w@6J5JJoz>XxLo5kVF$ zDJ+9i=2>Sva!E!%-Opc6LhMkzKmY(ig2+P$<>gdzGC(B{KyLF(BdAXuo9c|Ye35$9CSNqsJYbv~+ z#DNy359PfMzi*|Zs05(fM`iy!`dEFC?dm{U?1yyLPe(@bO)87PF>ErSmPt<3<(m%&guh}82z@0)Y0 z!MKi`$!qX(^T}wYaAZ#C(AJ^VXXA*&>nLRb4Zf`%l}~rk;2oB7X|XY!07D_!R*3eO zSD2lEkz2=}`#Qv2E#flk?c1=6;jP)1Ff&9@6p_g8?z?=9M1qZ;%n9eN^qrCB9GNok z`rS2NjxqfW1!|%YI!OL1c0V53n1e%dIP065c2JTQ15B|V+Zp;792-s{?kvZ z5R~}x0sio>hP6DGw?(imB(hmM=2?E0*Ooy^rWC^j3CbyMr-|pNRzf=c7A&fbJmZ>x zgsnw4jp~xdVAUb=2y$eyyDx}S!x;)M7UNR|f?cRxIR@0rej`#GRukO&BKHcsX znZVK|C>2@aoS3Uc5)C*la+j&0nfAM<(H#606(|t7#ATmW9)uKz)6>#M% zuD9laPZEeANIGJmgO+?$bX`GILDt%Wq=!Y1M<2?^(tDKys6*EQtN!i4*A^j90ceH= z;WhTc6*kTfQm$2gE|GBQjTK*`Iiu07QdLjb;AdjrF*ze&Xp93f%N`)4qBmxz9-^vMNNX- z0BCi{?0tgj*U)&}f_D8GVQAkOP8YB_4mHQs6*vG9$=*7sjtmeD52QCQ%xl-^XG$7M zHRZP9qw@@~B5!}ZkK<4yzK>RY97XLZSb)T0P_O7X9j{I@Ei4i%620hc(>7+L{qFjM z@~ORq^YIq29@HSSkqkBbb`b*de(9`jW!UX6lO6++WF*nI`&Rxr?&E&bwa$DeO%=9K zD>zXV(ME_N&=(#uvS{_G9&ckG!hbvJ-r?ymXzS;-dori)2+-{jNUwL#;^l(hek|ua?R8yO7;nwcz8r@ za|Y$z6~5-4V{GWuj=6b%0l-+9XiHytu3Oa*4;6_X-2&c((hSO(DY=8A2s3d2U!zJ3v{H(Gx>^*Q zt{skdZE4OmP>=A)03QMC3|;oPIXCY9N(NKxr-bWGjNXkwIbFWm3^jkmI;!hHeBGA50-c;Hg)+96&@oe_ z_-DyLQ*0`sq%_H}93I@TYYqmnlzMutJ_Sj0A6sN}T9NhG<;b<4I->fXECen^h{=gZ zNWC;Istza#oP#5yGl~*fC0(-KCvXV`$V4$C$PmgP*S)_=xk*a5u$97^uvB4Dfc6F* zo5h)0qv&%qszwEBU@L$@8Ze9HoF^$nvk1;Q(z(lh z?ij7rvegGG>Co*ho<2ch*MF7L=*5+5#LPbg%EqqEJ`T$usC7eIy{CUI(J5j{VKd6V z8}h!zkLMN`Rv`Y(1R^O)HsM>SdZs>wG)17x7e!N4`d(9_f4rNqX{IV-qqy^Rz^e6agoHFiA?igS$ejvbF^nC7sBBi78wS)lpI! zWR`;_m^l*E)}$ANQt1M*%2_e_WG6+Fiz2=Sd;=Wp+Q8#V7*~ox>PJMpXI-o%eBd*@mSOaLr5xITSDX5*U+XCTpcxGaVBO(#a`79)?9 zSY(Z+IT{e2q?A(3$1SIghjyJMD~Zpi^)Ac|#KZ1AwS=H~aki*=kX9ad(kX%Ng;NeO z5H(eWHmYKON#w5%;kdUPey}=~!)0b>mpB{rlVwSLkmoV>YZ&&6)2gxfcU7J!&| zzamSK8^7p-_4`U4#aMcCelUpzT1v1-@gm*ZA*C?>%waKki>3j#<)L==vCNcbMZIN+ zysa!sR``U<_t?sU>&ts+R?m|3Mcd1x>H8-5xoA>g1N&f(p?bT?AwV?&es(%@B|o-#4%0wnu>6=t1F^;8Kl4`8XoKjZ>Y z9=CYg4^iB=MB95p1yZ*+5)y803^lWLOky5j9~Lm%Lo@Ry|~x2g|0u z?aP=`#<<_o9NjNY1%V+@3D_ANSNS(@{b@aR8Vzk=PItBBYQAJ)BH=?qWETZ#a&4c2 zMee_qC!nRh^NHhV{UY;`KvrZKumLc=@J9HnV`qO4%2JU`wsB59|L(!uxtT|&pny|i zIB+ImGlKQpo0wk_6?u%3+G;Io;Eb-SvhDZlut(2-~AYeXC_{;Ab=& z#MMjes~|$!3XA)ghp|um9yI37{e_gMs}+^Ep7-2Y{_@If=aAC|-GvjzmD#c!4~h5a z;+=J{6lnS4I|lTzsLd3mDnWv*(5_;m?D3ww^aQsQA8JQ=$Z7EK9F}9c=C*ua zRL?-E+5L?Zh@H@O`ik6!x|pn&1}H&B1l>JND4G&k%PW~k8=7T|Ql1bbBL0f%Om5Vk zVl+6HCjmJ|T5125Hn$V)n~dtP8?un~vh|VrKaPV}n`n;@SbX_3kPPR$guqA&C6b}W zmR0fk=mVmEOx)o}iR8SxNtF~u9L9cYM`>^@Sk^ck%rp$f z3&-MhaRrkNfzh1OAx?800UhL{@Y4VOu!Do0iOZ=ffyf{2;qJIhE0G<1zfIprwWRlO zDdwn8N3)9mU*YfB0&Ti_jkEBvK&)XV;p~tq_P~Y=;BB@`oK1 z{<-BRb-iqB$|em`A5f&*1yh1Pr%Ku~iD+QoO-+ecamL051H}`XVcIOK8uisbZP1-K zAT@yUxG7(1p^=itN09-ee3&>1tytG&Vc9))EQ51hQCXd^4}CbUu%X0UpALI!klGF! zoVKC| zb&Hv}n+ZIlk&1u|I64yrF-=PU@CAq~?(c}ZUQOdvH5l1=M#ikMtsuj|*-`WjFe$q~ zD!pM0@y~O@&W$L(s`WtDy-orwq8fF-^+61qN(2Ez)vbeL#2kI1s(pV(CD{>)o0-c~ z_;PcUccx4Vkmb}EqW|&vY_h%ML@cSIr;qD&{@;w~l;B_x4O3hVV>pX*CLt7T+gAGH zq0FFuA_Y*x+Nt0P2Q284**A?9cHKBo*^Y_i4bfyX)3N1Fu}Z{hZ5$-J?sUEHx|LyP z`*TcXMUcLU!&Qd#7`GzuvYi9j{kzQo3Ifr4K-U=Ocz|RV8rfx_}kGEf7P4ToRc+R;{EF9qjGD%0`%mXhH@8Iyaz(|}m452`7;wYCLubqQGL zQ85Ww^sagL4fb-c7L0)v{?8f9fi+) zug=X@%U+U_+%o@rjlxWj9NAF-Y0VMDgjr<7_&ImmM*3`L$KLrOxr5FkDGGdam3hSqctJ7T*&NNdlTe@dh7sdf*=nxh4PK+X(FlZ)Y~Mm^K{k;_qnv-NZvu zH_4n-mAGon%570<3CUDlm=!js{U{;Unaws2XpGK+7(s zayTN82-1+B+sWWq!E-039+^Os9ofEi1n?dzJgn8RVsT?r@f*vI!d%{HrS%<@hno_0Daks z8dEUA5StHisF|ZGaE@a?H!x6Q-*aY)3-3q0u#dKOH!+A3yq)1X9#hUZl z6_#xp&R&)DQS}taa`3chn<5>Qb0en6YQn@q6@xxf&>1zw788 zm81edM#2nY4szy}(%e=A^_$N>W!J_3d%;5IH5=KIBdVdgJl?5q`CaB>m-5%DbDZjl zJb!;P!X0oOsLAmileZAA8e#SiTRW> z;U-HPQdi?1kl0i&(FWOeXA!EAMbQS!1*lF&FdoyKEF3cegX;pd_?ho`>$hdF7V}gC zB)@0%XT5v-$(x#LIDsV*KB$2*B{)I!rz)$V{G;Q+V&M_dYHH&erRgnyH>GvF(A}!@ zE?K7HN_l+oOC@4y}lD$bvq8nfqrH4xyJ_L?{tFGq<}!6gAaMz3M8-i1GU`LO~LV$gG7 zHb^EvGIwB(bz*v5m>(9!3Xrdwf89Pp5-~oDeJ~lInJvgNIsmGqM41U^5C-gDKMgCCsbc;ME{&$ctTOWpM99Tl zVjVZ;J9*FfsAMwEabisXa?A~>q4xa|>!n_QL|tEQrsXG>MF)ett3y3^nHnStHE}SeNrTtQIj*gq3~HDRmXZf&Gn(CR#tF$KTO%HcvM}z}J23_?MMl$p=dopW*CQ36Ugp;c16yWh9xbBn55(rM@l5V+5 zcNL*_caF*yk(Q;K2V|DR%1p7#SGdi~5urb>SG$=_o?Es2SfoOEw-~dgQ{+3=oCFO| zXY}}CTN9U0^#DZ-q>rae2>6hWGjS5ilNMuEuno(7w$lbG*=)K%MQK!CP*)Y&6FPqkG&~)sBJPUQi;!IN%!b`Z-2hHXd?f<@{ z&jZ?7r)cvhyuf>y+-)~7&L}#a`F+rt)lH=)dMkRhuK>ROdcJou?cg5ZuLSeH1!M#d zDeX{1f=xQW%RdtdFt>HhOAV*{RvCMi#vunSw`%l<*QBKz0{5 zI!}mXJ2J435LWX++~=aGI5|_E*2h&aluU$#5mT>IAixI2 z2`k8i=H)In2>-FZbhEzaFNjy1WA!~fwi)|RthHh7qtLEgv@e&dpKnGlZshce?DLa3O zC_ig1*izO#D9i=qf}4Rc_mykF!v%peaT3@U4b}=c_S_q97dhbAJ{~MP*uPFWVOu6dThi4Obut|+ld{?ttTvcnYX@dR9MI}Y+6}@JQ9~Mb-~er~+!OAC zvU%Mowc5*ynTwb>&Hr0B&EH8M;?fB?osx8Xzt4CsJ~uVto+E&D5V9GbL6&jGq5Z=4 z^I36gS$R(jaBA+AUjI}@LOafI$HSe_t#H^dH^9vK>EOCx^V+jwc?ve4uJrlzsx`Cf@f3q)@PKT=8XMsl*LOq<`5)HiJcD zgC>tMefMh_O|h(As!~?&%#TwU++n3YY6)?*(PbjU8bN+KY_IzBW=o`R{aQF(%L!@p zl9abfl~SrK*)&!aVY7zek)3vG?ZMIkfd-^bR0fDoecG167r{2=qN<0}7;fW!@s5GI z*oux+_xjk50ijWaks7hGX zcy2gGd>Ez6bKg9xgK%ns(!3gi;9%mKfR$ z*Gn*P_cMv(irS_w`=aPD)Y*^#2pR}s&c`jRlA;M=spUj58ZVB@PKU)QqcO1kU_5Z^ zafy5`CL}AHS`PSoo69A=v$s0XM|ePF`$zX>kTq$(WVg?v=-E{jF3B_^~D!M2V| zORis2SDLzGEoHQ~P76LvVI;7H#IpdH=d}1HlUrbS;Kz)q;(VOY{`MK3HI~`7++rh{ zo*V(mG)^UUDw>d1F73^s_=@(3rgn7-YbyEyN&r>6Rd|;R`iyni>OHWb4_=_xj#{_r+~ zz2DVT8T4<8qjc?7g6}L^nDN)7v~VyRBGqFQPXv#2H>c3yv(5YKKv>A1+i}qBAv+xv{;{m-T7RsZtNlIHw+mKM!~le+bz@tl)aFThI3Nz z#q95t*q4*&h*PC&|3Yla9aG^Cghee=%|Iw%O&R)x35 z99+328f9*8oQu{UO$WM91YD1wauPb&wzFXv3Hsv!?_cNGX$p!auHqdrFQxv_KE z^C^$O*Bku=b$@Ui)4qYTSsPLs|yyiKA79-?fQhR=2azG(i6{3zo-tGug` zDc;~$W}r5&?(%TZE*l6j0B1dfA~|Toq8O@1*{|Xwe{+4~`CYSzLbl&DAs*?C7yOh; zuSPzu%66TOn|mIXHR|%V>CB)*?Nd* zfQD}aE3_33FeM=VTqGHi*3YUAFkt*M6=MjR9?K&?DMB-=Da_PSHTx8UgrFsaTP zyo+R>w=TT7?~EZx&Fs14Mr(;b?)&p@%ms|S&eb#sk(%;NeGX;jSpds^atC9FcHN$0 z-|)zsNr`kyps;6f3b*fZuhc(#3#d({wNufb9^bLb%kHj#7D$7NT)En)b@g;gO+>p) zkj3_1Z~{aRic|m{L7eYHA~Fp25}}+RJDVyt@>9@X`{P@g#;YR8#*3|Y?Sp=bG^RKv=7a zsRU+@d3R%CS+-kohGb`KZ%{`WBqsNO1TP6lEKg)#wdy=74-2hu^!{jAjs`47VoghR zdh==|)yB7$B$Y~?ck!MbaQEn$l~juuTXgBMWf){Z@IQgzsTAa^e7w1kuI0 zHU_t`D}*M3tD6vnKm8LVr2dMN(_5>0WIBR!qY=j^M&tb&~>Ut>UTb4;Z zMCt3H2$dibWTM%mZ@&^saJKnNUw`&RMuc-Ezpv$*=0a5j+t(hpjIinLfJtB+z@gUI zVOHS8YJ{pfO#RpN{S}oxeyi%MDO>@MK@?Ec9u8FWaB_7AA+Y~`X1X^~iA3#R!Q)^| zeT_k;R@CyE2#A8zdQ-tOhtjezlCL~~Bx{ip|^YFb88 zkabqz-Q66BfqP+krPD&4-+4Yz0(}Zzp!?ieQ` zO^GP^87Y^d+l{#(M`RK7aAzYsE*gfjQQY|5mUVU6Dp+~6$QJGj1sPTL)+~545l&+= zoO|&*j@8Gs^QGpu?C0dU5F*w9dDB(vQ4?3aBCb|oh}ws*c#}UoRvxSTweKBbwY5yw zCPm)i+cy+g$ecLqvM|+DH91YnYGrAjSMDsx^f+2SvW-k{CszATg-DTc608tw@DIoX zq%83yjWn)__cvIM{6@5_)wJK|l(kUztwkdvP$U)Q>@n$@J`UG4jM0yMzQTvE z?Nyq5)TsiS|KN*E+q-^H;LfHX6hHKve9fn@x|v$#pVhJVV1@{P&EhIu;VI2_Mo@xQ zK6(F*tWTH(l9h*R-Oqm(u`aXg(x!9e1F<4!bk%~rPp?Opgb!9FEgXRx{@1>?ziPG$a zNP2>HP|>WH>K}wKT8cf6{hB<@_B({I%<1>yZhF3oLIzDZu_iBIc{xi|V(aA~bIxct zJTYr|V)U8YX~d=H_jHz3Ws0ksOLTShA$I6OX{+48T+X``{;-H!M@a?5EUUZPtv}1b zHQH?7L!aTOmN@Crd>gM{Rk0)-mEa(Ky#u)Oc-mEQh!{b=3+H05#-DfN!NlpJ1vuVL^9l+** zaSL=c&=MWeoy!MxK;v{^@ zt&CrP;P4Ifus&Xl(kko6=?A)>dHab$boUE!e~wc&XS%7H}%(zT{>c2e2O zo)1+75OeHERkz(JIj*Xg4WOT33V7(DnDgwz8P$K}aMY!mhr$ex%^cAR0k3J2*b`|1zT3x7D?=PYp)?W;iYW}B^oN=<4xu^DH$Tlv-co(l-*Un zPoG+mkNQ9ML#twN474c%KY%eHG5kcaId^a)xF(7&#ZBAo-i9DilCgOFt|5$if86lS zT?cMF;8~E&JY@i80jR&;ShU}YCwY?a)fKnNodiDLNlTH&Cp;P zQ6dflEIW;Og~@ytO^pzx#ozxBa7`od6i`f|a?7&SNwsO1WQ?bi6iOnyl@30=EAI-Q z0FfsnjXOU>~#$)mJSiG*l0%FE&E2$gf)Sg6|nLxM9`NhPJp#{jlj znt*N$6K^4v?lkC(x~)Ohh1O;(|mec<2-cN25(5C-AqPvb99l$$na4t9O_QG(|(j zeIi}=ySL`P6ljyW5$oa5Nhb+59OB@Qy!CD>@MmC1jlRbFt)`OkvZL?-m3_VAXtTe4 znFffE)ypCMjmn-pNI;${spGlml>^CQD8moSqreOzO8 z(HjJ{$*Jk_IONOC{;}TC=<|1n@2nZLZ>1{9aESF3O-qbun2mL|g2()&kZ6>!*1(Rv zi3dK)Nfey{t37|~!`7P4vEueWV}^nTa|b2d<_<;&P*O~c=6)f@(W~iC_;*(FU_nd% zzY{7dt#`kD4?5x^sF!69iP0lln7D1H+^A{|n*wkl|plUk?1n^OgsVK@sCnWxs??kz9m=uDHWb6!*z`x?pf!i=hWCy zEPQT=Eh~2hmDuqUCv7Nkhg4bqqL{!;GdK*g%%;IGz!h{djfHR3!esFbxa!4{Fx)2F zgLtW-F|;!}CiRssfF~y72f*>pnoBf5W05Uu$owG;A{3ae5R^AK$JpLJa&4ws4eF(P zObz{ua{)BV7dTf?LzNPPfX)u6PjumCiAQN(fNJDFRmv|zU0YDK)0!vYnSwZJr)&A&zT|vFS!FEiL;n2|7m>F9XxN%!__)T3?4ZQ@ecG|WD)Bi)KR(O5O|!FqlCyY>Q3jS6TzOU z6+MX3nL{!wk}-0@R#SC4r@wx1-5fbZ!N$tCj&4ns5s^PdH^2Y(JS>|BJtWkY2D8(I z#ol{&GO+ANrGhaVymxh-2$`;Pw5rY}wOu_}I%dxlEqLE_#SC&$-U`)V z_SEAI;N^#OD33DOH=$!S`$>j1#vI59GO-+FK2srstD=fxFErkpbgLqmdHLLkGUG#L z9uuuv3_Dus_J(){!z=lDsQ)qhM`>q8Pr@c31xyTbc-vE93)UKs z%c0Z?>|9ZO?ZpjqfL$MJ$&P|s$oDW~Zy6gE%}u5w2~W+;j1Xkgfmd&&)kCZ?G4HJW zvhpg>LMfk*qux+Ul<8ceiqBU$C?>b7;4g2mlphE6;iXxQ%1xh%tlm(Glpx2Qe^Z=Mqk}&LExXM)p%mM z=P^Jl?V&$`Rk9S6d_n(W-HQx(yporU042a`@;tJz8(2a*$WQ6Tho6dtVn$jXRl|wN z)xXr)4EhupB9v<5KtlutH;sWf@2S7U)@lw)UOWf>SrL^*-9H~pj9JADq)}`OpF~`) zBCXn03-U1Asa_nx;~x%3~+tk;@C!}v5qme8Ba zBlM8b!{GgUsES?6)6a18Z}PGfWz19{-!{JEu|X$fKlE#-V0E|Hu{#ymrm}S)1T`{I=EExx&&73zB1i)erB3@1rriKAaq`#IU+egc! zfc zYDp@8F6bg=&BNbdA=v{CJ-W#`g?^So`f&Gq)Ekx1#G-6z!LHTYrj!PRqXT4Sf%*6- zBMqq~9sarZ`2%@5bIDWW&XEGJfdZ69ZX2^BHc>_G7v{A{Gs{Wy{zwVtKPZcXb?lf; zQ{_C+1_<`|B<^I=vY2+E-mdnshJO{Jz!2Ch)7wisYo!D^*(F4rhNk~_J_Q{imx&Sk zN)Fe3Bz2*=1-~))es@|#60b+p?ZDT6kM&#~L)AYQ8(|^lHTxvg#w4B0h}vz5PtXw( zN}*(VpXq7pfAT|IBY&hdt3I3l9I5*uhE2;qfc>Q&YZc@Q0!J85j$k}s`cP}sauvT$_?1sPqj2{YA&`MqPaNJw0)-n<<-vSV# zn^lQ*KuP^!Z-QB!h|fnqip7j^7>P_Xdc#C5bngpHC~f1SLy_nc9V=#>7YSuuge4}> zj+WXsRU$zO_yquj1}l?02S-kPJ&#EJf_;Pw$ z3vG)lb0B0Oo+CYFf>HZ;^PnKchMuq$3TGke>7mglbNN|$MlU_`XR1auw{LfkFvB? zyQgJ2#Gh%kwsexenFE>%qMX=UBMc&k-WD_+y!LS9TTCU#ufhmP|3>oeEiBK92)*=| zu6TX19NOz%RxCFgr12Jav6T986zrEYGrDs-q653$B$Oi6zwk+CQv*K}M1_^iYZ(eL z{+j6W9k95>d1O)P^`lo)fly&5a8@h*E5sDK8s~Pksb3(eDooBpC}*8Qm!#n(De0Ak zQs-e&xKH0~;!p6_O}otxP4TR!2cMj?s(}z>PV5GO+5BsGpbuJl_BSWQG$#Zzelm7q z%?K1$)glsPq}ZE_o+d37zp17`E9alPN_ttryg7YgHP2EzO2l&OGV)@;hRlcr$6P_v+52ocrGd`a&QK- z)Cv%+9g?RL>-;nhiOq66u80oQa>X>9asBg0M2g`-gfTalDla1aYQR;r(AmAf(mScc zcNPqRkQ}~zn#i0JO%+j$0j0IQi=eXjh>FX(%c^YK7N4de01`0j@938c57#bHn#po* z9wm3`Y8v&l@~(>(iyI43b#M4n=jX&$sF5%4e~$;EdK^@SN<;x-E254Q46UKY>_8AD z<^(B7u#5xowzy@Qx`P=hi>#MmJBKLk?#?)D2tG(n1ldw_WlVdyX^kz z7*NT~2El3wgAMqQA)sD-&;_>n3@etDH2~^fZ;6TXQd^CELUR=%>xDlMR;&EG7p|6G z>TE1aLCEsR9Y?~kZxv;=-Cm*K?J8MhvL{zVSK@}j-nM6Qu8nBp@;YX04qTch3QnYh z?6*GbK$*)-d!#t_WZDK0a^F8tGQt9P6f#wpms^m#60Y|Xx;7gTXsJR{?Nv`10|o;iB6Z!*SHV-ZB{~E5?!r0+^-) zGn^L#^=@|Ce>iILNTvVIpYBVT>4qF3Jml~{G`h@wB7>Yo^kS6Y3Z&r|r#%8&8$`ov zT2`!h^+3fh$_lkS`c1`+f$mis8n1K{*lH=DZzcwpC++q!cviKS1%=YaA;&)w@sO+L zYa#s;arJNiEE8i0po=?%r@eFH)mDy}pYMPIUe6dF@>=uy5iX5p(Zj9SN9^30i1`wJ z>JhgSlB){s2>_TL-sUGOj{6N-Twc-XZTL4nn4GqodsfPwl=&rgUEDt+K9)5cK>G-F zL%i){66-mQ3}>j|w&!XY?FM2Cc2h`JR`ed(6QC)irZRbkaOYM|cIRcU6`eWn4?p@-EGxM}jtUEsj45L>W`GYE9|(P7RSn}w@~?zFCXCihcHPf` z^J3{+v{9Sw_|5*>NX{D3ovDSf>mYEAYoXiSn?L6WhoVcN)VX!K$&w7@ z9Vt1A6?LcdzuiM*>*{Vp`Scr;*z7W9lYMCzHGq!P!wKkdl>wh%|6?c!o@+eX4Y*CT zuitAHy11w*7vo$el%YOVw!=k>js>CdzJZcI$*R&;UN0Mqns17!s6$iXDu63~nv4&J;!UTvxFf(@g$I=_v zDV?!cqd!&p(k+i9xF!BM6@va-V8Q>s8A8VcHlgPn(7j^-im!N)2_~Qui7<)kMVj{` zmi0HLfLl6NFBiZAAtw-_gD}2K_6J24Mfo{xRwREtzJ9b2gr(1ZdFLY&Zt&qaE~#}} zMeO-hVjF(A9)EmxD;+a*M?u5mg#x5GxOYBtAU%{4rr7w3$G> z3uyysUcq@sWk_rwC9x+uh?ZL4Gj(B>-taC}6yDy~62&`LlXy(FIcxdu^I=-TWha(% z0Y9v++WVYLfk5VAI!gSw(kefnUTn;0?XPJKpr3<3ZN?P$Ml>BP+F&SM#mTSENa5*p zzdz+)sBx2Ynvgd579isvZ{N!0w33bik!@jvILIiPGe%R5FHs01S744}0sd zFGih?<04cdcHAXOMKX|zlTF35jH=P=ac zZbUnc9f?%BL0{Q4TWs(v-67iwB_kUzqTcppG*a*daM&fp^~(=+ke@3>SGs|s$Ce!m zk-9E1BH#}TTT1LnmM{w0hk<$EaRUq?ZmXX2e3#N5mZX($q}VpMm1fCz)N^FeXOj(f zAXZ8mxSr1@Z|2k8NcPH55cJHqb!e#!ohj(fxzvf0mk}sPwbWVBv+Lm8q&A}@1H^Zy zWT2phkF>nr4>qsR^^yb`%`b}kTY=n!xaJwtT#aVbnQovP8pL;F)8lsIAOH!V@&aJ_ zUN^bk!gsqK?{OPm0yw#+t7A|w;J?XWeA9Hza5uy0q`4vO}pvJ2urFu;3MicWe zuA5K;38l*F->_M;CI$DR);l$;n(X48XFZd+Q1XZEBUFOALdGl2MNe=&r-o`}_=`?M zhv5rP5$|dDB)9S}ZW{s9KcDvjiW;p3HIAObs&4!)jIGea>oQHCdTkTYA?m$Biu^3; z_$~A;Lui-&?U>h%Kdk1km}VbfVl09>D>bxCHKH0cvQeM` zKDUpOw3%kliNi?zZ$Toas#bW-fqFBLE=KnL+OYsb31~};eF}iAT0@ZE9zMQqbrD|FV~<$?97}WZw7e5jw8dk7**4xLLBGGCdssez&w|+)p$;L5 z#)*{XKSVsEZSvpyv`M$O!iCX4=i5Xu)UUE#E4ri314aJmd%b?KYh2&={5{s`b?GQ* zi5c>iS}Nb%{@sTL;m(73RHX@C;cr@A1?LYzvV+`!3P0k^1{+t>k_A9D4Qu6Iy2U&W zQS`WYP88Ib?qUG|4q*i~_H8|6Y()*Ye`yV{4HXZ%SGJ5leTv4N`Vzz3K9^>j?m|wF z!to2R6WPFL(&~p6A2v&3W=$kG)&D{lqn%?WSL#&vJKJi{E{k4=J=^}JO*igTJoZ@7s`MtoJ1Y08KoLhPWY)}Sa51Y~{h%H~ zxRa8vcqN3HX)1W4R1yG+5>H$!mzkb=`U+=1#MK5-Lu4g)#T-QI>39`ztkPtDu62GD zqx_jahPnD!FV@Vl0<6-_Q4?b-o=o?h)scKGv~2#p^moV*T%_+fIG-tWy+7oIxL=(-Om}BFQ5&^z;U|*rEnQQ6 zPt~u5b;uj2a)Xd|I6rT$N2&jzoVPXfp*x^HzP)A}^y60g#v4))W z*6CDR&(i+G29m_RTyG7Td0%}~+c-l|IORMJXd_9waypWaz%a3&uvFVv zNiK-6vaXUPEOgAU3`l8zgolI6g57^D%vv`h&}H;Ax9)-WAk-cDvV=zzL6dlz#`HlK zDcn6M0&(YsrY06po#&$JI0jxdi}`>Sx}kipV8A-ac!;ExmUX@=M(fn{rUQ;@_g~f9 zox~p^B=~2!^zcim0{;zHF1x2_ji;{q^B+H4s}e*yM9((&Z@ifvd$N(V9Z0@9PlTE5 zSrzFe*O!ZW!WE*-Pk4GBSM%DTPxkc#ercDf}EDYl|Yxg^7k`2^+onn(aHb=KZAwi(9a7SGM)`=X@?onUGN^ zK#hdq{NLGo zSFbt|krax;B$(mue@qlP0rnVA;4Swq?UqD}e#h_UAn_#OYaPtmGV^^_epbGuiQCyc z<+fn8?@(+Z8I;g~;!BH4ZbgQ} zc8w@nlz!TDO9RQU{PFB4&k}I$ADR;d;v;JAtl~Q+c<*!VGjhT+{y%ySgQH2Pn5#pox$DiO)1S$>N#fvQHzCCt6)(L(3 zk0yBSyXRM^%CJ)-GGR;Uncu6Y`KGlmaAkp=-c3IR@yXTT&^-Z{Zma59ou?z?Qmdo< z52~tPviy_17EVONv8*VXDX@?%st8{;?lH{gm12qfyJqHn&LulkZToC?aB>`ag!tat4g9wbb5N^&HiLxsLy+_Blr=;pq-|!&8U>h!e zAWqn>d+!+W<(6s+>y!WhV<{-1{FLTVyv$$l0EWPb8OVh;E3!+ixpZH0C>n{0_$IXB z+aTvPO#RAm9LxXHC**zw`M+q^v;0$j6s9ekElLX5u>$8cd$F1Di~=s)k{5LszJt1Z zk_^W?l*KCqF?$KVIGy$b8e@RO_TNgVBCN7v&~I*#S+bB;NXiZwa!frP>gXMD*UY;D01h~6tG*^f-QFzafAB2fZod+PhwZ+D(lRMi@~9{-r)sXrDL5w zI9uTkj~K9T$eYYW5M%R4eBSI}%K23CLKB3)L%mZ){VJGE{P-p9`)L)}@TF8E_p`ZL zNpsMOIrADyH| z>Vi5{Z}NlWVBf)SitW(=LyrAY3J6;N#qBvaEFn%qodbz*WI`fF&b z#X3fmrDZk3E7Yfbj0y8gdu@8k^6i8B8Jb}G0F_5(sp~uw8nTQ2x^oG;CYV$ev3R2dUHbRjfHJlc|+Ivbt;hhbd>li6b#0` ztXzD*0gsi?BFwqyYSF~SM-wnH*4c07i)mQb8iaBoDK!jXu~Z>a@cFJ(7O1Wk(+wO~4b7(O?qhcB*!VMqeFjhNp+i~y_+px6`xCus zT}WMWF9LNzw2n_&b&!#McQ~8k1LXiKj=COL*J=G~W0s?eJP(^~tnk^tk6l1uV@GCKrNTZ5GER+rpOXGwiC`!nP#-m1`C>Cw5Y zH{td|gX|*aXtZsS`2LuqZ{ssgP&yC&!_FdhI!nJ(a|dqylNa^R|F{lD;$*Ecz3JIo z2)>&FJ>B^Q)MP%9qTpctFxJh-ffw-(`>>u|=Z-QLTyCYR5CwbWX}z32bhVXwu51 za|9q++o=;4pNT;&aB^<$<0HhO@CWI_o-XM%z{*uf>Z4r<8ztuK7o@e$X23BuQXLq2 zr`Wg_cJ_43)jUByW39AL-2(4Ehly#ElA_lmQ7!G`s6zX!f$^K(A8~y6Vu6aJ<)`rg zCL)IJrp8O>{MS1gsnUMg1lUD?eYOE?rv6H!#Iyv{sES0x@mSbJL{$D;6mAAJ?9VU_ ztux7=B>aa}kqM{j?n3=|i}cQAc$aRA3g?^{vd(M*mptCgZ(BL-0QkkcUxN7UYFI`# z0kuXWu|1X1Uug03mDP6IVG!gPe#Z=;*!D%-i7`d#< z*yigl^ku`FB_^N*qgl;e+RWHCd8&-Wg}rytnu%))n6U*6ODeZa@%t~x&HT7@oCiP$ z;zB47WmX=-W-q*R&5CDjG!pck7kGFX3A}SXX{=gW#-dVsi`JA_d~s6-X$su{aVcUR zmPT45Sp!m|K-IA1KX5PvuZvnWglAL{UKW9)SQ6&k^#`Ec02&BPRWT_5; zTWO{67gd`mJ%3O}-m+4Xh&s->nJrR7Jp)9sq>~8+ZZn4{<rLV9{KfRM?3HlHbsi#r7tWonzZWEBoN)raT+yLX zLIT%tqt*WZ zEs-L+P0SCz5@Scdn_vu*H;O+~yqB@_hL}WfX%_f<%aJ6)L%?F|tP}wPNRz|5LG8`GJ(R$zl2>Ry*x`+BPo2;a*;>g|?3`YPbZ_duTBCK=Tl8Yxo ze5`8s1J>%fLL-`zJp+ymQxQ;!X4!8$C}r>Ry=QebZHw1;@8r|Pajc!Gxx{C}<%4zX zXs?marhy`NdHl~s>ODiI)P!T-TvJoJ=AKmU?~B~5d;cK)CSifne0x_qae_PQgO+8!dVw5p0`P;wY3G|&v zSyt=A{l{jDX@<3MKxRVPCyoj74B^S(bTIPD{4(cIAI@k8WHe>-hg*uZgCkG|*Nw@x z6XEZ?7*&>CTQ#N7e?RA}m%@nwP_QZ=(LUSLm7@FQd^G06CsyDj-eu<<26PF{;Vt=T zp`b9Od}ea+!sVOt5lb$#bX`$V#~v|95jl~@tDGO`_4l3~W zHe9S^!M!`kX;^6Xv*2)}g0*Ir;YojFxC~hhB_;WubAiDy&*}M~00N+TU`eqVqpTwy zp@iGnG!G@Im#UKpwY=PaUK3@+lUem=5|%+?Jd#QDNdH?3S%Y2BH`Lfudk$s0omz&5 zXv()%p0{m8`VuxwhudcKpW{kQW$s$2VS)v zBAexo!ZH(m3ELqtCLg<~8bTB46_g{_LM?pKD^56dtoDi{B?LoHOc>|W0t&JG50Bs- z3L=2DM^vsC1pb%23h*UT#p;d5=4t>JIs8ReArwdZzJqofP8Mk4vte6k_8_PkGL_j% zfb_(Vq&U0*DlB#A&NT$2yOv_J0!S6a3^@s4iMZz65QP(SmQKKuqJ`VoyM($JB>Bg z!XRz&Qr>#SXfv%N{X^tSXd9Z z?%H*a@7?{r2c%fI`}5?ZqMLrYkxF8g$rE0UhPjV2>N?rD- z?+6_9KHvROSjovH`YNt(X=Q12WmsIyhQf;*@Mj8GSl%55rgnc@SSxam<^HzbJi?Fs z+xU$8lK7v$E$TO{|MnOCtoh*YC!etLAOCIaU`Z4FZH)i(js9=r`~Cl~+~~9HEQPnq zYf^ZCpjW&QRcFvlN!HP6>nN@cwH?gq;A$oClhsg{jl%lMD1FMp6nv@8@yr)Ist4qi zPst&rbr)LO>9uKdv5sgRrNU}g&))vr0$ngX5tr#Zj9?NC!SMA-{M=mO~H(sXOZFF=&+MDQaBd@&lwY2}3 zuTR}9dVtmQ`(RNJnq0y-@8&IHK8%1ly87(i!pkZtR7Gu$v%youQ2WQz#k1?y(fHo; z4s342YeNS2i)j+W?q#u`oc8d79MR#_QE?DRm{8a2f@{T>v*ehT!e{*FMAeHOxqu## zMw;bLaCV|bm7&jpeVNDe?MY9k+cyk6*Tb14ed`Y*0L>B00gSTAx5vK|W77DZ>iSmN ze4MM%G>%o&S)MyNi!HrXULW=G$e81N6BoD8@zK#b*B73U?ibbsm~9BotElRVA5x2I z^FwT4a{R_5^c*a|Ac2R4$(1Yxhd-VC9SE>KT<`?Z}_)M^&aLKKNkXsm{LjK8!yFG5 zhf+XA83MDV=pgb&SCpXHAG#%hRzOH4&63ZNjc$U*#A}Jqf{zU;3=0%xEp4|Jg}?nY z@JtuZPY~e%n$I6EU+$~RGnJpKja20X|H~tNl#SvEPj>V^N0b zoa=Reg=ScS5cSnWye;_ITh|QOYf9Fjyx? z^IN?O|JoV1d}F1B4y$CfE_abB$b#X*Ut%w68Lz@5?N(?ZN~qW$#u;ssGy3(B&qt

L|hW3iC1Md|@mzDQAsw%U5E<2FI>MDxn%tOPw~z2uD1vhYZiC#2)G2Vyk5> zgK`o87H14NA2j>I^HKe}Q1GJeYe;TJP6FyYznTwd zRlv?|Zb`h<+158|GqIWMxYZJ*ZU=^~6zSFDpWzrMDL*Kz3|I%!ym(S}O9MV<-@!j~ z)71)qhUPaSVzUG01%w>N88zkGmE{NzbxNb zRY9I`aev7hrO*#sGo|~#-*TFmij7=dPvopb0d&fwZ{r%s0Cv|H{o^Mkv(Cb4jD$Rd z0SqBu_1{C~!KtGoecXoZI8+V4%V*@_SZ~yfaOH$c)V~@T)>s}jGIc-V?9km1>Nxk4 z$k0jAFFwaIDvTDXb-jLKx?NCrX9?ENBj&vdX!E(X9|ytb2$Y5{+kGzpKWuwP@NETSugan+}yZB>SccT(za1Fo=t}??_)%r1eBo5l}SV%b^Ur`e+A|kUFUo z&3`MOOiMzrY1C)VVg9AwtAS&4<&a9aYbpdftJ0;3i3#v4P-zgh%;nXnG`g{b3pRQ*@s;JKTvn=Dz}Hrf8~{N5*931W zKM>+E2-LcIo_%t!&V1MtV?Quf}t!b#R_j&=X!)vgqRh(9Q#y3_KxOR_GabOa_tvMTO+PlihIE)RbA= zDUtdpwV*|b8H|=p<7p$5L2`ZOMnir?G8cu)Qgl$eai7Pk7=n3Zee9BOx+#${@?&Fs zo{)ZffXO)Q9KE#xe6n5T=ET9c!P-Y{K@NMUaJde7mwt!WTVaOXG6y!#6Z-8W7KE&R zHgrB6fzF1O=KR%5oW*C$IvR|DZu%I)oqRI$OyBnu}IIS+^(^;wDomh z-A@R?KWh~(E4hw|klGqHa;=|eH_gND1>Jt%?g}3?t;{w~8ZUHPBh59OBflgatz4|PyO=%DVTFTMo2H=*o~FyFO}Bg}>1-D^hAjY7NNqmswXKJM*elG*vEa$~brMqqJK zg!NeebDZ)|*~(314l~UuR~@gh)nh~vyB8S0e2;83rZLAnRCM}rr_d{O@eaap{!~}$ zb}Zuhx_wIW(^c}5uSULEDin8?f?gRI>GW?thd%-glAHhu)&R@O#C!89m4{UZz83|P zTx&Lg2(`JmiR1)P(#G@7Ilx;a=Gt~KKYqwOhAkwy%kKp zk)%^DCHugXBHAZuEXe%zPnq6u|C#mva3ov7Qim-X1FQNdj#9)g+ZcIjAH!9zKl}k+ zso}3KJ=L?Qk#f^yCeU%OO~aIc@Emdc#28)?8646HaGu6#A( zz`t{aLEv=Ka3yBCdk4(`+(oCyS?E|WGa+peEjNNI|Im1d#hEV^OqWL#28t)$tVQu@ z-M7+?>SZ9Ey0{QfQW?-nr!o}EIqo?((leFetS3s+Athx7-v{Erf^Lw<+dga7^1aNq zW(YqGYS99a@ydGEHiPy9D+Pd*elyU*eQ(N@M#6F+MSmjv_|=x}l&ONddx&)YYrdKF z2l{E0U<)g<*fKj+ABrbzKE0`1ygVXYo4RlByrDsu%b8#xbSaTRl4Erg%`$dc4BSd> z@|=;RJEVb|YPuXxPW>zz$HxH_-R{9tSV4OoE9`I2U};kj z;oGSj>dQ9&--{*Y9gX#)Y4b=zs5(t+snd$;$`7CKm=o=g)=xJcnS%T_JqJ-?8f5$A zyrGkeeHz7x-6L2-g5_b8b%Og-T+h`jmfKwaeu1jN?~e|w#KyIGATvBOje8kCO$wpKt&?xBejl9V0l+C-gameGfT^w? ztCeTg5s|ZNbw-6`{?jXl-0)v3BD7-*G=?9A@{Rx9L692x(n!OHdSJQ z0z$8TetRb&S!aFG9>W4JI+K;n&QMT9Zeed%leJX+YQf7qb1tFu^*;zUBU-%zx#2vD|wRi?p+C9&45*`9`g^Xq!Ze;%EFmS_ek_GTf zo?bqY3F7unS_~f%V|i#Gn8^>F(f6>wRxsxhAxx5q9`1$Zv|XR7eDDtx?hIs*<`ki` z-7e_{&)@FIaVMtCUp?~M%;Bsx1l#V0upsSlV7F^QljHM!WS8;U4-L|S&7%j}+dmy| zn2(V;fx6NkL>v6@m5#SxUZv%SiC*WWU5*q7cH3z@5wvrIJ0nqr8AzH9d;(WspoASp zyh_9UiT2vfMEKr$bo^%uZj9Ze$H_?xXAzsRLRg?r`FSm_ zfNDAE`n~%$2fM-0*FqyB&H!Iqou(z7YGI1^M@HxQRK;hdHCR#YLk@Os>g#66hYZ;+ zb5U2pLgO$|wXdp8hhq&+Q&U+)iR#pG)|C3f&LDCBjV`XhXA$AywLA5waUr_I)2C^r zyqm>Tb-tWmNM4v#D}9M?%QDF`ilENFZifSo;=SPpSs6 zpIu$A8BqYY#b2)NP^N)^hjRbeFW1B&v@n?~?iaD8&x6Cy4;EF81v}H)c?e+W7Ra+2XKnP~~;UPG^dF6Ss2{ zN01-FuKw01Q6rQlr{orMiGkVSI_}yVc^+5U-{_xmjlf|ZS93Kq_qXlsFXemN5uYz+ zUYzh`0X3FC?e`pNN^VYqprm2j$p>RKO{P+m2MmRk&!plqF6=gj-YuiPL8E|NPxTWk zw?1PK=g&I6o*nU(7mIM%nxpKe6gp}AR;uv{ZVyHy)HrZS59=sGp5s+GDx%O*K=ox* zd)`}F|I=a^b5J8+uHA^Szi_GT1SYPuwZZ3bTJ@cx#87c@jv? zmouXi)!r>n${uxQozUab(N9Cy&m?aTLn9dlS}z^7ENKGr`IueLE>-7*uM4jgEZxGx zWo`UrH-`EiIs^tPuKl*|ON{sQgyk!Q7^%Lc2txM{lsd7iL(fxw)|jk>6k|fXWx2{a- zM(l@$E7B*#<2QRP=j-s=i+)#$adRNzxrXE)ndjThI z{tAFf>F-NvSqN+%vpy!q)qYSyNRUUGGjH-k&!}RM)64{YtgX3;dEZDX6MCz6y28 zlL*}MEN{B;t`m*fqkIj4E!T6le_;A4C0ZlY4oOs;X_X7Z#*U7^nvIl#leCHTNJ)M= z_LX!MjG-i>Ox!k+kuen^)Vein+zbpEn}SwAd8fVl8Z(~+Szu_9-aK)o=4s}?0)`kZG|5K~jvWaM|7V^;Dx}l@DBo9>_76u1y z%e?K>%aimNY?sQydMM1%*vw@Os3inKP+QIoRP1R%JeOUmBh8Vqq&B9{I#Vtn7xJ`t>$gt`1@O-_^$O*o#er)oLImcBKWgacPq$PT- zn|iyU)=|i@#Jp{!LJzd)PS=!8C7cNaJ*T_S`*boIo?bFc5<#v9*h8Rb;DfCh4L+vjq(0l_=9G zhyQkj;MY2(T*OzHU_umT=_BK|A~JR}=m{96q0m!c27qp~5#A+*Bn?p0>B%!Y9bj=B zn%k6KKCK$PQ0czWT*o~Bj9Ug(>;K_?`V+jyu%Fn9p^bGkTUm6=Gn*6M?n-4cbH)x7 zrmIZJvgxjU7Nok*cN+Jo_;x`+4dlTLWWGBzW+t1Q-tU>(AP#mQuJ$IkQc<}d8h&;l zx;a#BL!Hd`ddfRuxgko>NQ9n(vrjRrgimr=KNAe;Q65N(7?fV-eKmPC+_~B=7=V-dkxSWi~&O-!xY$mM(ki zKln)!Shu!qN?0UY0}xBA%g9mjVRoNHeook)V<&$#p1{Ev){YiJJh>1bV|X6iLljH< z6zOr;hoiQKcc|^SzBIHME#R1GhV%wEcpCR}zk?I2_T#$)j*L8iyBJof2dZvV1hC9+ z0|=%Z$jN~(YhNa(W!gl={&?nJTPAx=k}DC*0T2!Fp^A?x7uU@Qnn9t6HG6VQ1dq;1 zZ!hl4Ki^&M9jiwiXH;QFi?*EZ?+&T6Bx?y~0%ys`Dm?zFdr0(2S<0L~?-pBioV~N% zY!(3o4w^}EN7yUO!hM%)6>}s595F56$}?^VwV3~U($58ftcS*xu*?rHh$&gEuEM+f z)&_T#p2pouxY}8o(h@PeBMDs7Dfo_1;Mc8m+eBp6q~_;wn$N*hm?5-i @7=|-LM zr3>l$nLK54R*`B(PBE| zek=+r{Tr_clL<#%Oj=}e7WFJWZJD_fWr6Wj___@< z;NKUm9F7*w16l)0GlcFO&qBk4Qg13FQ=U4OzqZZv+?9 z_>^PY%G8KPN_F177JVTn@CrPru@&b-E5fo`QOAhjaa z6turndnzQc3C|HG;2Z6WSufN;RV0=0b=q(0K6ae8ygALg@g2B3`T6s?oz5V8Xan+{ zi<`+Zr<*gA9(+?f(vx8qUlH;+KJT=A7KByepomurC+0ROSsNyoMnmZ$BC zvPDN5hH6lKYTBS%i&Vwzkdic;2t0w0XKt*4UOe3Fr=F5LT6qf?-yUch*Y+x!=Ok5&N=+m)vG_NCI%Qh{D984=0yVV4jC&QmDICb(@;tBk*#_|2V z9V+b5DS`KjiUC)eRbih?lX3+-pO@|f0HswlW=GR}X?1dmQ+snOEjwe$wNBT8A0yfx zcdd6LL2Pm}d+3^Kbq93ybt!b4&}Xf35!ZXHyvwPgnnp77CtspbhwsDwNK6Ee{ZvUk zhk}3CfK{%CiG7jv=_L`_$>sWM!v0#pbn#-ncw&dBEkZN3e%`r zPU9}%9R=l|Zs@Jw=AnGvpS3z8F<0aIVkaHxZq{gUiFl#8-}$iX+bwR~L2~4I*0rlU zG_ge4`+R#W>u7@qNSF624+^T*P4FY})%)i#R1IAd;_Ah>Ay0u zSgF~I7?zL`6=bVZYdKxon_e|!JR#@Z&Kj-ec4X?EYlByU{1#j-FH&H$sp!}CjkV02 zlDRYUn>Jpd^-kiLeG5s#HQK`^|GLVKFm~Ye^{T(GD&#kaqnSlLu(2WN+L=i&hGmq}Pz4?Xx-q}=+FT=`yh&DWmzy(S zWYsF%cu?a?1cRAiXg(7O1Kt<&cK08yWzY@4$dRxWx-4x+Fnaif3B;#m?9b|(MdznP zWo0==1aUPnhp@jItv;OP*g|}Qk`czDk9XVam0N6{kh*m%&(382^&^yP>u{-lQYEc= z$2=n-H%NMPs(CTmCNDHOpf;g((|F_>l$mx2?~M?cZW+*8-faXCZW?zSriCK%d+(6V z<%y#>6HC*QvpE8Z-pDV!oJa3W+*-B9(-zxW4X9k7KcSet%ST?hxsXhfbs60}oKvEp z4`{{$Ftlb=$Dr(Tjjj;DpLs~X2eF1Noo5J@S*!XYy%og0W!2mxIXH`5jS>}i@ug&pP^=K6>MI?K`G`z1~b!wb~>8*XTRLff1;!`FrXAs+ou=Mx$c>O`fvwl zo@Gi%9SQ8MXBYXsdlyH@=cZ)t0@sH2jfNLiI&!4ZatX=;4Sh#z4}T<7nGTbAnV6ZGndoibeMtqdb1aNwj_g--`fE^O-QYrb~pAi>zZ!UN4Uc*%#3|@1#;_bZj%#1 z+c~I$>3-)iyU(sP%Tfnx-B?IU^f^C(o4*Vofa$PCx4E1h z3No}i1Rf({RbAXm${R72CiflgkQg2$Dc}?B@>p9XcY*D-!-846JZQmuI}_}-i%~QBOJMJQ}xEPwC}Too_-Y67WQR-@yv|$`rrqLLUXlI z>)tpzyS#||bOlne%G2VpjBqRH0@&K`Q-!m!bW)3+{@P%pZ2;|RmSk8_)4#jE8s6gu zo4r`}wSj2`ww6Bc~H zpO9WHE(|hYE!e$Yh0`wkk9SyoRI`f{)uS0RC)Tz1(l{_XIZMoGjtqO8S!`E%4+fu^ zuf2+qEvqg5diUlaAlRhHF|OHlD9h?Df2-R08sI(G{Y1Oh^GU-QPT*LYBC(sL24|K4 zO92{aK6sF+6E&FpZ+7tnUO{X*8H|Hu`F7F7u}#Vwggl;jRM@d3g4wNQNC0^ZfhQk7 z2~wky*C>fSoEYzE3>^C6sJ+1#yLBSRH6m2ep1wzYRiWdT9~e+^4VUxrS>34}wAX&r ze0==jD)$jVgpU$I8~AoL%tPqw77pC_0&co|I^EFW?QGW6IVhG!KgnLrb!P&N<3IkG z0R3cxto7vQgZQ;$4a4snJ<-=$1p~GQ}2X@>JP_bPVOmfsvmLb@k*ix z(8!YvBf!R#lvE|SET*HdI3t**a8T73b?oYP⋙=X0LB2ORQzinB28xAnvHAh*hpb zP%7K#9E|Bsxi2={c7g4*Z=CP&W2IaX3Y!hO=lFhi!^z5}h{d`D(gR^my)K5epO#Ce zIR1gH1n78by{as%x;Be@m!p)1CpMNUOu^F`x5|?Z=&GahX?f^rfW%=MGs42=h7Sw$ z4)KltSkIdx(tpu&2m6p49HMWK^$!PL;Cy@wMtfGWbJte+;T@srXBM_&8df>A<9w0f z=WpN6cS>2pW&RMIp5C#e#tCPbe;9{ZF6QGCQ2e;WSeg(qgvQ<4!5*4w2>$8hZPmUz zCW__l_}bRv(a7}m%ht%TahU|RZ|?}JeO)A~u4=|XDv)Lb@qTI{=vK6~Nb zk*YWe*2bJ*6mu0e_dz$D9aQbUraHw-C`SaIRJC|k_(PFD_vf~lzY&Y(@vPo;RjULf(;gT|A6TZzzAoknds+zmKNR|I{QA+TCSX@Ihe;Ho?`<$=r zmXPA=v*XycgRGb=jFN%l>;cs(9xtT%=<3gqSh{p<+ki@sBnz3WxsS54jFI>9($KGV zCvx_;$IRnKHY##+!~Z4s_@3bMNO6ntA$GrJ>5qjdux#rdW_9cqA;N+Ln(A>>@&hx- z)C2t_Z#l&z|J?aaN-|mG>qt>kY@E}z$WE>;Nbbt%kXO{Dyj`TOk_N?%hUSYs% zgT)*M{=MI_=t2^tVB?BG+lD?o-PRwTBh+=!IbV44-*g{aJ%MOLoy(KIk|{50*W3`1 z+#T*kln_1Cb11DjD_t&ib@uCvr*m(5@JO8oahPAiBzlnvWLYCp2Q7Z&QnF^k2F?he zC_|>aYD=g6dX*n_1TzRN&B|~5G?;Q)E|bx;y%+_oBx`<)Gq_mYx$+ELi|O=~*ON&t zNB)SQgkjxQlObW9D!MFQx$Zr-$*7(Z!)inMkb`+R{W!?p$ zCW{Ll2B_kwr!6n1WHM4vE+HQ;Vm+C9%|5A7xLdBD5&_`<^+<2ds2i>t!a1Q~YKynY zcF_)TsD?1BhhgLV5(Ig^uJhbMOiv(#Uo)>%1V$~`iac>=bQfMl3)FmayZq$dz{}21 z@ITQUo*H@_s`L&LUvM2AjS2#dL^yOsBw4iQTD*UVr1(hx(Gb>P@o1@{k~9h?#dWlD zki{(jHlWql`Fd0DA<^f%$7s2Pi*F1lvp2uq4%bN;Wc**#+A@sry5Fjc()-Q2C7nmd zof5m;dRmHKJC}q&^%Q5P@N0r7-G#8U^`T*NL*(=cW4;Z5-p}?yOpj${A>_gW zds8KgNO;JMt6&OoyY}!{_>)_|?n(2R92M49gKYOZo{4LN#za!Js6++y+p>M}tL^xy z%=7I!3~342{}vi_C>DeCmc8t)1`>weMTh^;2BMr|beH>B=;<@uv+$VX;LB4`lQ=rU z>u4kkCY{f*XGH$YGk}u36Z19q8N+MZ=YOQZuG6CVO;J&}201(xKO^t*iw;)>(4#YT zJ@s0GAwij(o`>6*O@}uO!ivglbTqS86Xy_k&F0@JHTGtZ_y+WUJ9%sajHZmvK+EA# z$@i;8Mf^BpWy*>^Z1_l<5dp!rpyk=9(m$y&%p(m5T~i~>M4C!0WCNd}{={qB1w5#|Ri+y?!x-MzOw&%B zg%;oWt%^pD8u51&n})@83({U6byYO-bS0tdL*YRuQuaFs>rsCF95*zTLqEBDt+u|Zmrv^*HzG=W4VM*qZ=!W7uO1WmlFMKSFQg^ zF3OPO{`Daqx`Dd)^NtxM%^BrklY=@rRI3gp+r*97W0~WS_*Ej@%Ehyy$wGRgpNdN; z2_ivt%m++D`U`sccNDY)6#759NB%n*6D<=St`WC%bqF9kl^x|O&38;m(|Y|X&1n6pmIr7@BwJ>PF#`_=}FRG3B;@!YtMbweDj%@-iLiyWO8lu8{=dZVtBK zs@5wo3Y1RN;f^`D&frk)9sX7> z1y9bPC8ao-j)z-BuIlYqx5+b&IP}e8#Dn1e%3tHIhbHH$AwPB=eBx zQ9s|74u;WdY0%=uhR1av-&Bow4k>X1?LWV1`Stk>lzXcianKcXN!0kKZK`~w2^JBR+)~-#SLbW=3-&s;g~+a0JwEx zm`X=as3Ji}pBLBjmzw=OSUHTo?xre})nF~pr2Y6!j%2CtZqGSU6e*44i8Dum6!;yi%*FrP#5eBf zLw5uU9ni*IF|n;D)q&r683yCBO9GqEO$7=xTrdI>!ow338?L9G%~ZQcD8yd%4*Qa%|CqSUABpEj@p%q0lbGiR(eEM z)$wk1g9ZnBb}1CtDQF}okLXnogvoQDecol{FoZ+M=jO8SqGtaa zCDCXz^)(!438I;6cUc6-5IL3;ZRmLU{+Zl3uYjmU_I5faSs$^Fl8&V4>Ciby&rFqr zsb-u%fDIC@9kosCg6{TPFzOtIEra*qU|3`G1!dhD$Tp2zuGfaAH&wm5n#~azH~+%C zh9TMPO`iRIss)3)myvf>2G+11`-qGs(!e?h z0&k9UogY<0w(SK1PMTQ`^ExZN`t5KU8v;!guN)U%`-*xv#f5TJBaB-~{U7JK^2Y_u zKT2uk-(6`b4otXo#eOPA7LxOfAYym$>sjPC`l9yskLL!P4P{@Ay}kMU$G(O`+Ka+X zVYkQKtyyo+LN7TXLSMHtCqhO|8(s zE~JU)$jsVc`_T>3|!GS^E>Lid$mQ)h|* zcNQ|gXAE3I*ApG-#KonvTVdK!E3-jA+}?-z%r<fNM8XL` z^IxL`-YzXTj6a;IQ>w>$@?>}7oyJNq58WT_jNki4|6TC!$w^eOZq3-{|9Es#^}P3| zS7W<7QN#CB^7_`VTmI)U?5pas8;8iaT%hfyimH>uJsHYt!`-C4iC7Vpv5g(kq(9dj zr`}bnI1v3`9h_KqxV-*$_4L{H9RI>@^?!C!dj5*wZ{&{oPX)}+2US8k=Y)8sc6VPW zuL@kmR@dK+M;lDt@aJw=ZypW4Ac<%tD4PgwN24mTDgJ)yt^Z!<|53qAdq(^sm?y%5w~ zP%233R`nH<^Ut(3Jt}REe-n&2JwtR~wIKuNKXEE}8Tu-8q~t$#G~+%P0`)a|@>pj` zbD#CDKHd7AWEsJvPHoGD24-db8Y*hs4{6w!u>MV(7kj-byB75`#C;F^9vw{@c`#>; z=eFFY>M$>OzP;M5zobcunr_)<(eB>sy>&gdtAfzUMh{nb-2S5T1)04I>2q27x8Ue| zCeLXm9FKBCzmzuHi`RE^%TZ(}tiu*y&e~1Vuvmk&LCcRXIN zkkA;$%XaKtmes?0X1=CZyL`4^8E0Jx_zOx7#r??kK%Z79!%2d*fWL z3hJId1PQ4Cn+}Ct!a=IT!nfVy6BY0cLV}56_w8JxhZw=16GbbJtX38UY=SZs2|>L$ z!xYnHow$-)5j*qq0W5@m2oRCU*hi>&My31ZM2<7tR-BEW@;6akCfg+mzpIaLh5uR~ zC^#MQyDQ<*-C5{*mJ+l$+zwr-v)RXvk@ugI9o>*a3)=7X(z`0!8!TRm3h-NAA+xqX zel%hD2@v<+5E|SU1huEOrbevf^p=~XPgC8rwevu@1W+xgth|GZ%V6TW;~Ki)8$&xi z(39EI_`ii=Kil>XpUSCbB0d26p4f*4nv&$p8@$&M>Ng)e=25`3oVbOEI>Hc8f`54F zcJ*}V$NKM4&7|Iu8geq2;&bzVoxP*)9UuQp(35@eqPGlLI@)yp0a>?fL`(R0VS0OY z=;nt9=8T8--Z7^4;M%(mmF#OK?Gon{Jlk7{G@|e1XM#jh&w28v*3YDjyxC>m$B4I6 zi_l{(Qu<#cV)IuzD&8q*24pw(6t7zDG$s_Mx+KrTc6vdD{NEAAbDQm}9&i6%cOKNj zbcAOqs~;_wtMqMoEIUUV*f^M+r>r9{vfGp1SuaUjTG@>x#$PdV!LK<&apcjU4w9q* z`}w;?%;f2M?|N=wzUEVw2HI{KxWnA-H)1q+B%HTC4ff*Xx*jig9vpQSTYPuWYVMWR zr11K$-_V&^B#x}PP``K;F(0Sx6pCqbk**=RbPHOUq4tZT^mDyVzU358Lebm4f3Buh z^gM#Xe)l1_VnA5Hd6;Hh$zlgdp&heb>F|1@_D91F8?tDUp$X&Wo*dFdV`gI@?HDsXeK6Ud?IYuJo>XU+IQ#dnnBiHS8>-9%1WHAO z^z>$|tp~EiPuFm}=sC##MVv-CC_c#!3jgshbF}O$z1cmH_9bCF2zx2NzKDLn9j-%-i zBHa0a{C@Cr_bJ<*^SajFqBW&ik^*{krTS*$3#>F&fpmz5{ zqjBJmlVGLpC+0X8zsnCD|LV4#Xr(~&+bK;S^J56*z-DpmW_ZCH2(j;5Z*O@1n@Yod zP$113+bY}{73h3ERHj=Q5>~>*aT-S>&Q35}6Kg8(Ra-J=I^SMIOGQ zV+lb7%%QcEW03Um*^*I=yWg*+@$ra_GS6$ zsjOv@*1*{+X@rjSoo%xV(A3^}H8}Rn9MAXa&JH?lSFIui-=d)I$*<~v98r3p^>k=f zi}j21lgW(bb~Q6=voU7tgZ43Fj&#%`N20JvjZr_Z|Yo+B=-`YvBLr`0`@cM>QxIkS8GGLvBW_i zp$UZbtyoyUmm&WqJ}u949B&3Wzywj}igD)vb>H#E=2ygYgB=~1!WCMs1wT%@v2n@o z7Es$?9!nd^Zu{^aqMH~KngmnvjyqaY1ICKF(QFvPL~4_a_-7CObuT-_DYIal^H4@jV!{3h(lHa7S@dnN7?b zmcFJ#4kB$;U3;6jxIAsObZ?-KF7vD%gnubJZ0$GzveS-#ThwWB%nDdd*j?uXr04n{ zF8iTChw8~-i~y{6Kt<`COBt``wn1V-NVCA0U+e3i(ibW zzahSyWPg0O!cfBT;~m~9vQRHO7q2LUAGt&7xIvD;p(rcMeiR=~C;hjMTeFJ%zF#Lc z4r&~4Mua#xHk_>uGka5GmS06JtE*S8d2v^Rem7x`E2N`>;G*6Ss#jY!mO(mqRp132 z1-uf5Bb)kvI((P&S2xm9?-}^s+ToFP{ny9*4EpE4>%oJ0h0gv$D_EtH^;0{p*McprRw|9z_6>nGV01Ap|ZB&RN0E&cw>{{T@Zh8O?< literal 0 HcmV?d00001 diff --git a/boards/riscv/beaglev_fire/doc/index.rst b/boards/riscv/beaglev_fire/doc/index.rst new file mode 100644 index 00000000000..88808145c9b --- /dev/null +++ b/boards/riscv/beaglev_fire/doc/index.rst @@ -0,0 +1,85 @@ +.. _beaglev_fire: + +BeagleV®-Fire +############# + +Overview +******** + +BeagleV®-Fire is a revolutionary single-board computer (SBC) powered by the Microchip’s +PolarFire® MPFS025T 5x core RISC-V System on Chip (SoC) with FPGA fabric. BeagleV®-Fire opens up new +horizons for developers, tinkerers, and the open-source community to explore the vast potential of +RISC-V architecture and FPGA technology. It has the same P8 & P9 cape header pins as BeagleBone +Black allowing you to stack your favorite BeagleBone cape on top to expand it’s capability. +Built around the powerful and energy-efficient RISC-V instruction set architecture (ISA) along with +its versatile FPGA fabric, BeagleV®-Fire SBC offers unparalleled opportunities for developers, +hobbyists, and researchers to explore and experiment with RISC-V technology. + +.. image:: img/BeagleV-Fire-Front-Annotated-768x432.webp + :align: center + :alt: beaglev_fire + +Building +======== + +Applications for the ``beaglev_fire`` board configuration can be built as usual: + +.. zephyr-app-commands:: + :zephyr-app: samples/hello_world + :board: beaglev_fire + :goals: build + +Debugging +========= + +In order to upload the application to the device, you'll need OpenOCD and GDB +with RISC-V support. +You can get them as a part of SoftConsole SDK. +Download and installation instructions can be found on +`Microchip's SoftConsole website +`_. + +You will also require a Debugger such as Microchip's FlashPro5/6. + +Connect to BeagleV-Fire UART debug port using a 3.3v USB to UART bridge. +Now you can run ``tio `` in a terminal window to access the UART debug port connection. Once you +are connected properly you can press the Reset button which will show you a progress bar like: + +.. image:: img/board-booting.png + :align: center + :alt: beaglev_fire + +Once you see that progress bar on your screen you can start pressing any button (0-9/a-z) which +will interrupt the Hart Software Services from booting its payload. + +With the necessary tools installed, you can connect to the board using OpenOCD. +from a different terminal, run: + +.. code-block:: bash + + /openocd/bin/openocd --file \ + /openocd/share/openocd/scripts/board/microsemi-riscv.cfg + + +Leave it running, and in a different terminal, use GDB to upload the binary to +the board. You can use the RISC-V GDB from the Zephyr SDK. +launch GDB: + +.. code-block:: bash + + /riscv64-zephyr-elf/bin/riscv64-zephyr-elf-gdb + + + +Here is the GDB terminal command to connect to the device +and load the binary: + +.. code-block:: bash + + set arch riscv:rv64 + set mem inaccessible-by-default off + file + target extended-remote localhost:3333 + load + break main + continue From c69028760cda83bad337c9acecda745e1a15b359 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Sat, 23 Dec 2023 17:35:24 +0800 Subject: [PATCH 1182/1623] [nrf fromtree] soc: riscv: add support for Renode Virt RISCV32 SoC Add a beef-ed up version of Renode's `riscv_virt` SoC Signed-off-by: Yong Cong Sin (cherry picked from commit c328a38a94962cc64325b525fad8013331291e35) --- .../renode_virt/CMakeLists.txt | 6 +++ .../renode_virt/Kconfig.defconfig.series | 48 +++++++++++++++++++ .../renode_virt/Kconfig.series | 9 ++++ .../riscv-privileged/renode_virt/Kconfig.soc | 19 ++++++++ soc/riscv/riscv-privileged/renode_virt/soc.h | 12 +++++ 5 files changed, 94 insertions(+) create mode 100644 soc/riscv/riscv-privileged/renode_virt/CMakeLists.txt create mode 100644 soc/riscv/riscv-privileged/renode_virt/Kconfig.defconfig.series create mode 100644 soc/riscv/riscv-privileged/renode_virt/Kconfig.series create mode 100644 soc/riscv/riscv-privileged/renode_virt/Kconfig.soc create mode 100644 soc/riscv/riscv-privileged/renode_virt/soc.h diff --git a/soc/riscv/riscv-privileged/renode_virt/CMakeLists.txt b/soc/riscv/riscv-privileged/renode_virt/CMakeLists.txt new file mode 100644 index 00000000000..56d36b84ec8 --- /dev/null +++ b/soc/riscv/riscv-privileged/renode_virt/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (c) 2023 Meta +# SPDX-License-Identifier: Apache-2.0 + +zephyr_sources() + +set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "") diff --git a/soc/riscv/riscv-privileged/renode_virt/Kconfig.defconfig.series b/soc/riscv/riscv-privileged/renode_virt/Kconfig.defconfig.series new file mode 100644 index 00000000000..09adc3d00e8 --- /dev/null +++ b/soc/riscv/riscv-privileged/renode_virt/Kconfig.defconfig.series @@ -0,0 +1,48 @@ +# Copyright (c) 2023 Meta +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_RISCV32_VIRTUAL_RENODE + +config SOC_SERIES + default "renode_virt" + +config SYS_CLOCK_HW_CYCLES_PER_SEC + default 4000000 + +config RISCV_SOC_INTERRUPT_INIT + default y + +config RISCV_HAS_CPU_IDLE + default y + +config RISCV_HAS_PLIC + default y + +config RISCV_GP + default y + +config 1ST_LEVEL_INTERRUPT_BITS + default 4 + +config NUM_2ND_LEVEL_AGGREGATORS + default 2 + +config 2ND_LEVEL_INTERRUPT_BITS + default 11 + +config 2ND_LVL_ISR_TBL_OFFSET + default 12 + +config 2ND_LVL_INTR_00_OFFSET + default 11 + +config 2ND_LVL_INTR_01_OFFSET + default 4 + +config MAX_IRQ_PER_AGGREGATOR + default 1023 + +config NUM_IRQS + default 2058 + +endif # SOC_SERIES_RISCV32_VIRTUAL_RENODE diff --git a/soc/riscv/riscv-privileged/renode_virt/Kconfig.series b/soc/riscv/riscv-privileged/renode_virt/Kconfig.series new file mode 100644 index 00000000000..22e27cf38b4 --- /dev/null +++ b/soc/riscv/riscv-privileged/renode_virt/Kconfig.series @@ -0,0 +1,9 @@ +# Copyright (c) 2023 Meta +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_RISCV32_VIRTUAL_RENODE + bool "Renode RISC-V32 Virtual SoC implementation" + select RISCV + select SOC_FAMILY_RISCV_PRIVILEGED + help + Enable support for Renode RISC-V Virtual diff --git a/soc/riscv/riscv-privileged/renode_virt/Kconfig.soc b/soc/riscv/riscv-privileged/renode_virt/Kconfig.soc new file mode 100644 index 00000000000..d123e797229 --- /dev/null +++ b/soc/riscv/riscv-privileged/renode_virt/Kconfig.soc @@ -0,0 +1,19 @@ +# Copyright (c) 2023 Meta +# SPDX-License-Identifier: Apache-2.0 + +choice + prompt "Renode RISCV32 Virtual system implementation" + depends on SOC_SERIES_RISCV32_VIRTUAL_RENODE + +config SOC_RISCV32_VIRTUAL_RENODE + bool "Renode RISCV32 Virtual system implementation" + select ATOMIC_OPERATIONS_BUILTIN + select INCLUDE_RESET_VECTOR + select RISCV_ISA_RV32I + select RISCV_ISA_EXT_M + select RISCV_ISA_EXT_A + select RISCV_ISA_EXT_C + select RISCV_ISA_EXT_ZICSR + select RISCV_ISA_EXT_ZIFENCEI + +endchoice diff --git a/soc/riscv/riscv-privileged/renode_virt/soc.h b/soc/riscv/riscv-privileged/renode_virt/soc.h new file mode 100644 index 00000000000..c82e16f1613 --- /dev/null +++ b/soc/riscv/riscv-privileged/renode_virt/soc.h @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2023 Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __RISCV32_RENODE_SOC_H_ +#define __RISCV32_RENODE_SOC_H_ + +#include + +#endif /* __RISCV32_RENODE_SOC_H_ */ From 1f4042263729e6b5d6145fd7fd687ead84838389 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Sat, 23 Dec 2023 17:36:07 +0800 Subject: [PATCH 1183/1623] [nrf fromtree] boards: riscv: add RISCV32 Virtual board made with Renode The RISCV32 Virtual board is a virtual platform made with Renode as an alternative to QEMU. Contrary to QEMU, the peripherals of this platform can be easily configured by editing the `riscv32_virtual.repl` script and the devicetree files accordingly, this allows certain hardware configurations that only exist in proprietary boards/SoCs to be tested in upstream CI. Added another entry for this board to the excluded platform in `kernel.timer.timer` test. Signed-off-by: Yong Cong Sin (cherry picked from commit 7fac758bdb33ad893af25cc27126da0a5bee3e9c) --- boards/riscv/riscv32_virtual/Kconfig.board | 6 ++ .../riscv/riscv32_virtual/Kconfig.defconfig | 6 ++ boards/riscv/riscv32_virtual/board.cmake | 6 ++ boards/riscv/riscv32_virtual/doc/index.rst | 56 +++++++++++++++++++ .../riscv/riscv32_virtual/riscv32_virtual.dts | 25 +++++++++ .../riscv32_virtual/riscv32_virtual.yaml | 16 ++++++ .../riscv32_virtual/riscv32_virtual_defconfig | 14 +++++ .../support/riscv32_virtual.repl | 33 +++++++++++ .../support/riscv32_virtual.resc | 17 ++++++ 9 files changed, 179 insertions(+) create mode 100644 boards/riscv/riscv32_virtual/Kconfig.board create mode 100644 boards/riscv/riscv32_virtual/Kconfig.defconfig create mode 100644 boards/riscv/riscv32_virtual/board.cmake create mode 100644 boards/riscv/riscv32_virtual/doc/index.rst create mode 100644 boards/riscv/riscv32_virtual/riscv32_virtual.dts create mode 100644 boards/riscv/riscv32_virtual/riscv32_virtual.yaml create mode 100644 boards/riscv/riscv32_virtual/riscv32_virtual_defconfig create mode 100644 boards/riscv/riscv32_virtual/support/riscv32_virtual.repl create mode 100644 boards/riscv/riscv32_virtual/support/riscv32_virtual.resc diff --git a/boards/riscv/riscv32_virtual/Kconfig.board b/boards/riscv/riscv32_virtual/Kconfig.board new file mode 100644 index 00000000000..c8722acb384 --- /dev/null +++ b/boards/riscv/riscv32_virtual/Kconfig.board @@ -0,0 +1,6 @@ +# Copyright (c) 2023 Meta +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_RISCV32_VIRTUAL + bool "riscv32_virtual" + depends on SOC_RISCV32_VIRTUAL_RENODE diff --git a/boards/riscv/riscv32_virtual/Kconfig.defconfig b/boards/riscv/riscv32_virtual/Kconfig.defconfig new file mode 100644 index 00000000000..840b10fd594 --- /dev/null +++ b/boards/riscv/riscv32_virtual/Kconfig.defconfig @@ -0,0 +1,6 @@ +# Copyright (c) 2023 Meta +# SPDX-License-Identifier: Apache-2.0 + +config BOARD + default "riscv32_virtual" + depends on BOARD_RISCV32_VIRTUAL diff --git a/boards/riscv/riscv32_virtual/board.cmake b/boards/riscv/riscv32_virtual/board.cmake new file mode 100644 index 00000000000..cc177a69ce9 --- /dev/null +++ b/boards/riscv/riscv32_virtual/board.cmake @@ -0,0 +1,6 @@ +# Copyright (c) 2023 Meta +# SPDX-License-Identifier: Apache-2.0 + +set(SUPPORTED_EMU_PLATFORMS renode) +set(RENODE_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/support/riscv32_virtual.resc) +set(RENODE_UART sysbus.uart0) diff --git a/boards/riscv/riscv32_virtual/doc/index.rst b/boards/riscv/riscv32_virtual/doc/index.rst new file mode 100644 index 00000000000..a53384f5331 --- /dev/null +++ b/boards/riscv/riscv32_virtual/doc/index.rst @@ -0,0 +1,56 @@ +.. _riscv32-virtual: + +RISCV32 Virtual +############### + +Overview +******** + +The RISCV32 Virtual board is a virtual platform made with Renode as an alternative to QEMU. +Contrary to QEMU, the peripherals of this platform can be easily configured by editing the +``riscv32_virtual.repl`` script and the devicetree files accordingly, this allows certain hardware +configurations that only exist in proprietary boards/SoCs to be tested in upstream CI. + +Programming and debugging +************************* + +Building +======== + +Applications for the ``riscv32_virtual`` board configuration can be built as usual +(see :ref:`build_an_application`): + +.. zephyr-app-commands:: + :board: riscv32_virtual + :goals: build + +Flashing +======== + +While this board is emulated and you can't "flash" it, you can use this +configuration to run basic Zephyr applications and kernel tests in the Renode +emulated environment. For example, with the :zephyr:code-sample:`synchronization` sample: + +.. zephyr-app-commands:: + :zephyr-app: samples/synchronization + :host-os: unix + :board: riscv32_virtual + :goals: run + +This will build an image with the synchronization sample app, boot it using +Renode, and display the following console output: + +.. code-block:: console + + *** Booting Zephyr OS build zephyr-v3.5.0-1511-g56f73bde0fb0 *** + thread_a: Hello World from cpu 0 on riscv32_virtual! + thread_b: Hello World from cpu 0 on riscv32_virtual! + thread_a: Hello World from cpu 0 on riscv32_virtual! + thread_b: Hello World from cpu 0 on riscv32_virtual! + +Exit Renode by pressing :kbd:`CTRL+C`. + +Debugging +========= + +Refer to the detailed overview about :ref:`application_debugging`. diff --git a/boards/riscv/riscv32_virtual/riscv32_virtual.dts b/boards/riscv/riscv32_virtual/riscv32_virtual.dts new file mode 100644 index 00000000000..326b9757518 --- /dev/null +++ b/boards/riscv/riscv32_virtual/riscv32_virtual.dts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; + +#include + +/ { + model = "Renode RISCV32 Virtual target"; + compatible = "renode,riscv32-virtual"; + + chosen { + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + zephyr,flash = &flash0; + zephyr,sram = &sram0; + }; +}; + +&uart0 { + status = "okay"; +}; diff --git a/boards/riscv/riscv32_virtual/riscv32_virtual.yaml b/boards/riscv/riscv32_virtual/riscv32_virtual.yaml new file mode 100644 index 00000000000..11cefb035df --- /dev/null +++ b/boards/riscv/riscv32_virtual/riscv32_virtual.yaml @@ -0,0 +1,16 @@ +identifier: riscv32_virtual +name: Renode RISC-V 32-bit Virtual Board +type: mcu +arch: riscv32 +toolchain: + - zephyr +ram: 4096 +flash: 4096 +simulation: renode +simulation_exec: renode +testing: + ignore_tags: + - net + - bluetooth +supported: + - uart diff --git a/boards/riscv/riscv32_virtual/riscv32_virtual_defconfig b/boards/riscv/riscv32_virtual/riscv32_virtual_defconfig new file mode 100644 index 00000000000..a905f99da2e --- /dev/null +++ b/boards/riscv/riscv32_virtual/riscv32_virtual_defconfig @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Meta +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_RISCV32_VIRTUAL_RENODE=y +CONFIG_SOC_RISCV32_VIRTUAL_RENODE=y +CONFIG_BOARD_RISCV32_VIRTUAL=y +CONFIG_CONSOLE=y +CONFIG_SERIAL=y +CONFIG_UART_CONSOLE=y +CONFIG_GPIO=n +CONFIG_XIP=y + +# Workaround for incorrect SYS_CLOCK_HW_CYCLES_PER_SEC +CONFIG_SYS_CLOCK_TICKS_PER_SEC=100 diff --git a/boards/riscv/riscv32_virtual/support/riscv32_virtual.repl b/boards/riscv/riscv32_virtual/support/riscv32_virtual.repl new file mode 100644 index 00000000000..e0df808631b --- /dev/null +++ b/boards/riscv/riscv32_virtual/support/riscv32_virtual.repl @@ -0,0 +1,33 @@ +// Copyright (c) 2023 Meta +// SPDX-License-Identifier: Apache-2.0 + +flash: Memory.MappedMemory @ sysbus 0x80000000 + size: 0x400000 + +ddr: Memory.MappedMemory @ sysbus 0x80400000 + size: 0x400000 + +uart0: UART.NS16550 @ sysbus 0x10000000 + IRQ -> plic0@10 + +uart1: UART.NS16550 @ sysbus 0x10000100 + IRQ -> plic1@10 + +cpu: CPU.RiscV32 @ sysbus + cpuType: "rv32imac_zicsr_zifencei" + privilegeArchitecture: PrivilegeArchitecture.Priv1_10 + timeProvider: clint + +plic0: IRQControllers.PlatformLevelInterruptController @ sysbus 0x0C000000 + 0 -> cpu@11 + numberOfSources: 1023 + numberOfContexts: 1 + +plic1: IRQControllers.PlatformLevelInterruptController @ sysbus 0x08000000 + 0 -> cpu@4 + numberOfSources: 1023 + numberOfContexts: 1 + +clint: IRQControllers.CoreLevelInterruptor @ sysbus 0x02000000 + [0,1] -> cpu@[3,7] + frequency: 4000000 diff --git a/boards/riscv/riscv32_virtual/support/riscv32_virtual.resc b/boards/riscv/riscv32_virtual/support/riscv32_virtual.resc new file mode 100644 index 00000000000..87e327287b6 --- /dev/null +++ b/boards/riscv/riscv32_virtual/support/riscv32_virtual.resc @@ -0,0 +1,17 @@ +:name: RISCV32-Virtual +:description: This script is prepared to run Zephyr on a Renode RISCV32 board. + +$name?="RISCV32-Virtual" + +using sysbus +mach create $name +machine LoadPlatformDescription $ORIGIN/riscv32_virtual.repl + +showAnalyzer uart0 +cpu PerformanceInMips 4 + +macro reset +""" + sysbus LoadELF $bin +""" +runMacro $reset From 37c830845c9c6fdc2a5449eabeb9c505902ae574 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 12:17:30 +0100 Subject: [PATCH 1184/1623] [nrf fromtree] soc: riscv: move privileged code to common folder Add a new riscv/common directory where to store common code between SoCs, e.g. those implementing the privileged spec. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 6443c50bd04d4f11900b48fed80726ed0bc969f6) --- soc/riscv/CMakeLists.txt | 2 ++ soc/riscv/common/CMakeLists.txt | 1 + soc/riscv/common/Kconfig | 4 +++ .../riscv-privileged}/CMakeLists.txt | 0 soc/riscv/common/riscv-privileged/Kconfig | 36 +++++++++++++++++++ .../common => common/riscv-privileged}/idle.c | 0 .../riscv-privileged}/nuclei/nuclei_csr.h | 0 .../riscv-privileged}/soc_common.h | 0 .../riscv-privileged}/soc_common_irq.c | 0 .../riscv-privileged}/soc_irq.S | 0 .../riscv-privileged}/vector.S | 0 soc/riscv/litex-vexriscv/CMakeLists.txt | 4 +-- soc/riscv/litex-vexriscv/soc.h | 2 +- soc/riscv/riscv-privileged/CMakeLists.txt | 1 - soc/riscv/riscv-privileged/Kconfig | 34 ------------------ 15 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 soc/riscv/common/CMakeLists.txt create mode 100644 soc/riscv/common/Kconfig rename soc/riscv/{riscv-privileged/common => common/riscv-privileged}/CMakeLists.txt (100%) create mode 100644 soc/riscv/common/riscv-privileged/Kconfig rename soc/riscv/{riscv-privileged/common => common/riscv-privileged}/idle.c (100%) rename soc/riscv/{riscv-privileged/common => common/riscv-privileged}/nuclei/nuclei_csr.h (100%) rename soc/riscv/{riscv-privileged/common => common/riscv-privileged}/soc_common.h (100%) rename soc/riscv/{riscv-privileged/common => common/riscv-privileged}/soc_common_irq.c (100%) rename soc/riscv/{riscv-privileged/common => common/riscv-privileged}/soc_irq.S (100%) rename soc/riscv/{riscv-privileged/common => common/riscv-privileged}/vector.S (100%) diff --git a/soc/riscv/CMakeLists.txt b/soc/riscv/CMakeLists.txt index b826da926ca..79d115704b2 100644 --- a/soc/riscv/CMakeLists.txt +++ b/soc/riscv/CMakeLists.txt @@ -1,5 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 +add_subdirectory(common) + if(SOC_FAMILY) add_subdirectory(${SOC_FAMILY}) else() diff --git a/soc/riscv/common/CMakeLists.txt b/soc/riscv/common/CMakeLists.txt new file mode 100644 index 00000000000..9102b32a45f --- /dev/null +++ b/soc/riscv/common/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory_ifdef(CONFIG_SOC_FAMILY_RISCV_PRIVILEGED riscv-privileged) diff --git a/soc/riscv/common/Kconfig b/soc/riscv/common/Kconfig new file mode 100644 index 00000000000..91f2c5cf80a --- /dev/null +++ b/soc/riscv/common/Kconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 +# +source "soc/riscv/common/riscv-privileged/Kconfig" diff --git a/soc/riscv/riscv-privileged/common/CMakeLists.txt b/soc/riscv/common/riscv-privileged/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/common/CMakeLists.txt rename to soc/riscv/common/riscv-privileged/CMakeLists.txt diff --git a/soc/riscv/common/riscv-privileged/Kconfig b/soc/riscv/common/riscv-privileged/Kconfig new file mode 100644 index 00000000000..6bc12b46c5a --- /dev/null +++ b/soc/riscv/common/riscv-privileged/Kconfig @@ -0,0 +1,36 @@ +# Configuration options for riscv SOCs supporting the riscv privileged +# architecture specification + +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FAMILY_RISCV_PRIVILEGE + bool + select DEPRECATED + +config SOC_FAMILY_RISCV_PRIVILEGED + bool + select ARCH_HAS_RAMFUNC_SUPPORT if XIP + +config SOC_FAMILY + string + default "riscv-privileged" + depends on SOC_FAMILY_RISCV_PRIVILEGED + +config RISCV_HAS_PLIC + bool "Does the SOC provide support for a Platform Level Interrupt Controller (PLIC)" + depends on SOC_FAMILY_RISCV_PRIVILEGED + help + Does the SOC provide support for a Platform Level Interrupt Controller (PLIC). + +config RISCV_HAS_CLIC + bool "Does the SOC provide support for a Core-Local Interrupt Controller (CLIC)" + depends on SOC_FAMILY_RISCV_PRIVILEGED + help + Does the SOC provide support for a Core-Local Interrupt Controller (CLIC). + +config RISCV_VECTORED_MODE + bool "Should the SOC use vectored mode" + depends on SOC_FAMILY_RISCV_PRIVILEGED + help + Should the SOC use vectored mode. diff --git a/soc/riscv/riscv-privileged/common/idle.c b/soc/riscv/common/riscv-privileged/idle.c similarity index 100% rename from soc/riscv/riscv-privileged/common/idle.c rename to soc/riscv/common/riscv-privileged/idle.c diff --git a/soc/riscv/riscv-privileged/common/nuclei/nuclei_csr.h b/soc/riscv/common/riscv-privileged/nuclei/nuclei_csr.h similarity index 100% rename from soc/riscv/riscv-privileged/common/nuclei/nuclei_csr.h rename to soc/riscv/common/riscv-privileged/nuclei/nuclei_csr.h diff --git a/soc/riscv/riscv-privileged/common/soc_common.h b/soc/riscv/common/riscv-privileged/soc_common.h similarity index 100% rename from soc/riscv/riscv-privileged/common/soc_common.h rename to soc/riscv/common/riscv-privileged/soc_common.h diff --git a/soc/riscv/riscv-privileged/common/soc_common_irq.c b/soc/riscv/common/riscv-privileged/soc_common_irq.c similarity index 100% rename from soc/riscv/riscv-privileged/common/soc_common_irq.c rename to soc/riscv/common/riscv-privileged/soc_common_irq.c diff --git a/soc/riscv/riscv-privileged/common/soc_irq.S b/soc/riscv/common/riscv-privileged/soc_irq.S similarity index 100% rename from soc/riscv/riscv-privileged/common/soc_irq.S rename to soc/riscv/common/riscv-privileged/soc_irq.S diff --git a/soc/riscv/riscv-privileged/common/vector.S b/soc/riscv/common/riscv-privileged/vector.S similarity index 100% rename from soc/riscv/riscv-privileged/common/vector.S rename to soc/riscv/common/riscv-privileged/vector.S diff --git a/soc/riscv/litex-vexriscv/CMakeLists.txt b/soc/riscv/litex-vexriscv/CMakeLists.txt index 9d100ea0e2a..98386f6b57a 100644 --- a/soc/riscv/litex-vexriscv/CMakeLists.txt +++ b/soc/riscv/litex-vexriscv/CMakeLists.txt @@ -5,8 +5,8 @@ # zephyr_sources( - ../riscv-privileged/common/soc_irq.S - ../riscv-privileged/common/vector.S + ../common/riscv-privileged/soc_irq.S + ../common/riscv-privileged/vector.S ) set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "") diff --git a/soc/riscv/litex-vexriscv/soc.h b/soc/riscv/litex-vexriscv/soc.h index b738deec771..b3521b51e8e 100644 --- a/soc/riscv/litex-vexriscv/soc.h +++ b/soc/riscv/litex-vexriscv/soc.h @@ -7,7 +7,7 @@ #ifndef __RISCV32_LITEX_VEXRISCV_SOC_H_ #define __RISCV32_LITEX_VEXRISCV_SOC_H_ -#include "../riscv-privileged/common/soc_common.h" +#include "../common/riscv-privileged/soc_common.h" #include #include diff --git a/soc/riscv/riscv-privileged/CMakeLists.txt b/soc/riscv/riscv-privileged/CMakeLists.txt index c5f97039eb7..226f3bd626f 100644 --- a/soc/riscv/riscv-privileged/CMakeLists.txt +++ b/soc/riscv/riscv-privileged/CMakeLists.txt @@ -1,4 +1,3 @@ # SPDX-License-Identifier: Apache-2.0 -add_subdirectory(common) add_subdirectory(${SOC_SERIES}) diff --git a/soc/riscv/riscv-privileged/Kconfig b/soc/riscv/riscv-privileged/Kconfig index abbeeac242b..b0700dd3440 100644 --- a/soc/riscv/riscv-privileged/Kconfig +++ b/soc/riscv/riscv-privileged/Kconfig @@ -1,38 +1,4 @@ -# Configuration options for riscv SOCs supporting the riscv privileged -# architecture specification - # Copyright (c) 2017 Jean-Paul Etienne # SPDX-License-Identifier: Apache-2.0 -config SOC_FAMILY_RISCV_PRIVILEGE - bool - select DEPRECATED - -config SOC_FAMILY_RISCV_PRIVILEGED - bool - select ARCH_HAS_RAMFUNC_SUPPORT if XIP - -config SOC_FAMILY - string - default "riscv-privileged" - depends on SOC_FAMILY_RISCV_PRIVILEGED - -config RISCV_HAS_PLIC - bool "Does the SOC provide support for a Platform Level Interrupt Controller (PLIC)" - depends on SOC_FAMILY_RISCV_PRIVILEGED - help - Does the SOC provide support for a Platform Level Interrupt Controller (PLIC). - -config RISCV_HAS_CLIC - bool "Does the SOC provide support for a Core-Local Interrupt Controller (CLIC)" - depends on SOC_FAMILY_RISCV_PRIVILEGED - help - Does the SOC provide support for a Core-Local Interrupt Controller (CLIC). - -config RISCV_VECTORED_MODE - bool "Should the SOC use vectored mode" - depends on SOC_FAMILY_RISCV_PRIVILEGED - help - Should the SOC use vectored mode. - source "soc/riscv/riscv-privileged/*/Kconfig.soc" From 9cf4288b0a6f74899019febc0624a5ab51960a3d Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 12:20:19 +0100 Subject: [PATCH 1185/1623] [nrf fromtree] soc: riscv: gd32vf103: move nuclei CSR header The header is common to all Nuclei based cores (not strictly related to RISCV privileged spec). Since only GD32VF103 uses a Nuclei core, move the file to its SoC folder. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 9a35ad858c6d32a25e36c6244f9ab709c9b279d0) --- soc/riscv/riscv-privileged/gd32vf103/entry.S | 3 ++- .../nuclei => riscv-privileged/gd32vf103}/nuclei_csr.h | 0 2 files changed, 2 insertions(+), 1 deletion(-) rename soc/riscv/{common/riscv-privileged/nuclei => riscv-privileged/gd32vf103}/nuclei_csr.h (100%) diff --git a/soc/riscv/riscv-privileged/gd32vf103/entry.S b/soc/riscv/riscv-privileged/gd32vf103/entry.S index 5f8af0d691f..41cc6cc686b 100644 --- a/soc/riscv/riscv-privileged/gd32vf103/entry.S +++ b/soc/riscv/riscv-privileged/gd32vf103/entry.S @@ -4,9 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include "nuclei_csr.h" + #include #include -#include GTEXT(__nuclei_start) SECTION_FUNC(vectors, __nuclei_start) diff --git a/soc/riscv/common/riscv-privileged/nuclei/nuclei_csr.h b/soc/riscv/riscv-privileged/gd32vf103/nuclei_csr.h similarity index 100% rename from soc/riscv/common/riscv-privileged/nuclei/nuclei_csr.h rename to soc/riscv/riscv-privileged/gd32vf103/nuclei_csr.h From 6f160c4135b705cabd34aa196b6e348375eec5f1 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 12:39:36 +0100 Subject: [PATCH 1186/1623] [nrf fromtree] arch: riscv: introduce RISCV_PRIVILEGED Introduce a new arch level Kconfig option to signal the implementation of the RISCV Privileged ISA spec. This replaces SOC_FAMILY_RISCV_PRIVILEGED, because this is not a SoC specific property, nor a SoC family. Note that the SoC family naming scheme will be fixed in upcoming commits. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 0106e8d14c34f3dcd75e8858d01d904375076a34) --- arch/riscv/Kconfig | 8 +++++++- drivers/interrupt_controller/intc_plic.c | 4 ++-- include/zephyr/arch/riscv/arch.h | 2 +- soc/riscv/common/CMakeLists.txt | 2 +- soc/riscv/common/riscv-privileged/Kconfig | 17 ++++------------- .../riscv-privileged/andes_v5/Kconfig.series | 2 +- .../efinix-sapphire/Kconfig.series | 2 +- .../riscv-privileged/gd32vf103/Kconfig.series | 2 +- soc/riscv/riscv-privileged/miv/Kconfig.series | 2 +- soc/riscv/riscv-privileged/mpfs/Kconfig.series | 2 +- .../riscv-privileged/neorv32/Kconfig.series | 2 +- soc/riscv/riscv-privileged/niosv/Kconfig.series | 2 +- .../riscv-privileged/opentitan/Kconfig.series | 2 +- .../sifive-freedom/Kconfig.series | 2 +- .../starfive_jh71xx/Kconfig.series | 2 +- .../riscv-privileged/telink_b91/Kconfig.series | 2 +- soc/riscv/riscv-privileged/virt/Kconfig.series | 2 +- tests/kernel/gen_isr_table/testcase.yaml | 8 ++++---- 18 files changed, 31 insertions(+), 34 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index a1cefcbdf43..80249670d09 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -47,6 +47,12 @@ config INCLUDE_RESET_VECTOR Include the reset vector stub, which initializes the stack and prepares for running C code. +config RISCV_PRIVILEGED + bool + select ARCH_HAS_RAMFUNC_SUPPORT if XIP + help + Option selected by SoCs implementing the RISC-V privileged ISA. + config RISCV_SOC_HAS_ISR_STACKING bool depends on !USERSPACE @@ -333,7 +339,7 @@ config RISCV_TRAP_HANDLER_ALIGNMENT The minimum alignment is 4 bytes according to the Spec. config GEN_IRQ_VECTOR_TABLE - select RISCV_VECTORED_MODE if SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_VECTORED_MODE if RISCV_PRIVILEGED config ARCH_HAS_SINGLE_THREAD_SUPPORT default y if !SMP diff --git a/drivers/interrupt_controller/intc_plic.c b/drivers/interrupt_controller/intc_plic.c index 51ce1769396..211a6f11041 100644 --- a/drivers/interrupt_controller/intc_plic.c +++ b/drivers/interrupt_controller/intc_plic.c @@ -135,7 +135,7 @@ static int riscv_plic_is_edge_irq(const struct device *dev, uint32_t local_irq) * @brief Enable a riscv PLIC-specific interrupt line * * This routine enables a RISCV PLIC-specific interrupt line. - * riscv_plic_irq_enable is called by SOC_FAMILY_RISCV_PRIVILEGED + * riscv_plic_irq_enable is called by RISCV_PRIVILEGED * arch_irq_enable function to enable external interrupts for * IRQS level == 2, whenever CONFIG_RISCV_HAS_PLIC variable is set. * @@ -161,7 +161,7 @@ void riscv_plic_irq_enable(uint32_t irq) * @brief Disable a riscv PLIC-specific interrupt line * * This routine disables a RISCV PLIC-specific interrupt line. - * riscv_plic_irq_disable is called by SOC_FAMILY_RISCV_PRIVILEGED + * riscv_plic_irq_disable is called by RISCV_PRIVILEGED * arch_irq_disable function to disable external interrupts, for * IRQS level == 2, whenever CONFIG_RISCV_HAS_PLIC variable is set. * diff --git a/include/zephyr/arch/riscv/arch.h b/include/zephyr/arch/riscv/arch.h index 99bccb74a08..1ab509c162e 100644 --- a/include/zephyr/arch/riscv/arch.h +++ b/include/zephyr/arch/riscv/arch.h @@ -300,7 +300,7 @@ static inline uint64_t arch_k_cycle_get_64(void) #endif /*_ASMLANGUAGE */ -#if defined(CONFIG_SOC_FAMILY_RISCV_PRIVILEGED) +#if defined(CONFIG_RISCV_PRIVILEGED) #include #endif diff --git a/soc/riscv/common/CMakeLists.txt b/soc/riscv/common/CMakeLists.txt index 9102b32a45f..91ef5c975b9 100644 --- a/soc/riscv/common/CMakeLists.txt +++ b/soc/riscv/common/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory_ifdef(CONFIG_SOC_FAMILY_RISCV_PRIVILEGED riscv-privileged) +add_subdirectory_ifdef(CONFIG_RISCV_PRIVILEGED riscv-privileged) diff --git a/soc/riscv/common/riscv-privileged/Kconfig b/soc/riscv/common/riscv-privileged/Kconfig index 6bc12b46c5a..526dea4bbfb 100644 --- a/soc/riscv/common/riscv-privileged/Kconfig +++ b/soc/riscv/common/riscv-privileged/Kconfig @@ -4,33 +4,24 @@ # Copyright (c) 2017 Jean-Paul Etienne # SPDX-License-Identifier: Apache-2.0 -config SOC_FAMILY_RISCV_PRIVILEGE - bool - select DEPRECATED - -config SOC_FAMILY_RISCV_PRIVILEGED - bool - select ARCH_HAS_RAMFUNC_SUPPORT if XIP - config SOC_FAMILY string - default "riscv-privileged" - depends on SOC_FAMILY_RISCV_PRIVILEGED + default "riscv-privileged" if RISCV_PRIVILEGED config RISCV_HAS_PLIC bool "Does the SOC provide support for a Platform Level Interrupt Controller (PLIC)" - depends on SOC_FAMILY_RISCV_PRIVILEGED + depends on RISCV_PRIVILEGED help Does the SOC provide support for a Platform Level Interrupt Controller (PLIC). config RISCV_HAS_CLIC bool "Does the SOC provide support for a Core-Local Interrupt Controller (CLIC)" - depends on SOC_FAMILY_RISCV_PRIVILEGED + depends on RISCV_PRIVILEGED help Does the SOC provide support for a Core-Local Interrupt Controller (CLIC). config RISCV_VECTORED_MODE bool "Should the SOC use vectored mode" - depends on SOC_FAMILY_RISCV_PRIVILEGED + depends on RISCV_PRIVILEGED help Should the SOC use vectored mode. diff --git a/soc/riscv/riscv-privileged/andes_v5/Kconfig.series b/soc/riscv/riscv-privileged/andes_v5/Kconfig.series index 9a99711b04c..a85c521492b 100644 --- a/soc/riscv/riscv-privileged/andes_v5/Kconfig.series +++ b/soc/riscv/riscv-privileged/andes_v5/Kconfig.series @@ -4,6 +4,6 @@ config SOC_SERIES_RISCV_ANDES_V5 bool "Andes V5 SoC Series Implementation" select RISCV - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED help Enable support for Andes V5 SoC Series diff --git a/soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.series b/soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.series index 8505cf1318a..421d81a7e33 100644 --- a/soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.series +++ b/soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.series @@ -4,6 +4,6 @@ config SOC_SERIES_EFINIX_SAPPHIRE bool "Efinix Sapphire SOC implementation" select RISCV - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED help Enable support for Efinix Sapphire SOC implementation diff --git a/soc/riscv/riscv-privileged/gd32vf103/Kconfig.series b/soc/riscv/riscv-privileged/gd32vf103/Kconfig.series index 3922bf19bdd..79bb3690743 100644 --- a/soc/riscv/riscv-privileged/gd32vf103/Kconfig.series +++ b/soc/riscv/riscv-privileged/gd32vf103/Kconfig.series @@ -6,7 +6,7 @@ config SOC_SERIES_GD32VF103 bool "GigaDevice GD32VF103 series SoC implementation" select RISCV - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED select ATOMIC_OPERATIONS_C select INCLUDE_RESET_VECTOR select BUILD_OUTPUT_HEX diff --git a/soc/riscv/riscv-privileged/miv/Kconfig.series b/soc/riscv/riscv-privileged/miv/Kconfig.series index 00a6f129f9f..017de686a94 100644 --- a/soc/riscv/riscv-privileged/miv/Kconfig.series +++ b/soc/riscv/riscv-privileged/miv/Kconfig.series @@ -6,6 +6,6 @@ config SOC_SERIES_RISCV32_MIV bool "Microchip Mi-V implementation" select RISCV - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED help Enable support for Microchip Mi-V diff --git a/soc/riscv/riscv-privileged/mpfs/Kconfig.series b/soc/riscv/riscv-privileged/mpfs/Kconfig.series index ca37731f192..3b30cd15365 100644 --- a/soc/riscv/riscv-privileged/mpfs/Kconfig.series +++ b/soc/riscv/riscv-privileged/mpfs/Kconfig.series @@ -6,6 +6,6 @@ config SOC_SERIES_RISCV64_MIV bool "Microchip RV64 implementation" select RISCV - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED help Enable support for Microchip RISCV 64bit diff --git a/soc/riscv/riscv-privileged/neorv32/Kconfig.series b/soc/riscv/riscv-privileged/neorv32/Kconfig.series index 98c7f34024d..0f8f9ca8fd4 100644 --- a/soc/riscv/riscv-privileged/neorv32/Kconfig.series +++ b/soc/riscv/riscv-privileged/neorv32/Kconfig.series @@ -9,7 +9,7 @@ config SOC_SERIES_NEORV32 select RISCV_ISA_EXT_A select RISCV_ISA_EXT_ZICSR select RISCV_ISA_EXT_ZIFENCEI - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED help Enable support for the NEORV32 Processor (SoC). diff --git a/soc/riscv/riscv-privileged/niosv/Kconfig.series b/soc/riscv/riscv-privileged/niosv/Kconfig.series index 7de17cf2db0..104f5a48352 100644 --- a/soc/riscv/riscv-privileged/niosv/Kconfig.series +++ b/soc/riscv/riscv-privileged/niosv/Kconfig.series @@ -4,6 +4,6 @@ config SOC_SERIES_NIOSV bool "INTEL FPGA NIOSV" select RISCV - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED help Enable support for the INTEL FPGA NIOSV. diff --git a/soc/riscv/riscv-privileged/opentitan/Kconfig.series b/soc/riscv/riscv-privileged/opentitan/Kconfig.series index f8bbc2840fe..b516e6d8092 100644 --- a/soc/riscv/riscv-privileged/opentitan/Kconfig.series +++ b/soc/riscv/riscv-privileged/opentitan/Kconfig.series @@ -4,7 +4,7 @@ config SOC_SERIES_RISCV_OPENTITAN bool "OpenTitan implementation" select RISCV - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED # OpenTitan Ibex core mtvec mode is read-only / forced to vectored mode. select RISCV_VECTORED_MODE select GEN_IRQ_VECTOR_TABLE diff --git a/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.series b/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.series index 523f6a4ffe9..a24b4812c28 100644 --- a/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.series +++ b/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.series @@ -6,6 +6,6 @@ config SOC_SERIES_RISCV_SIFIVE_FREEDOM bool "SiFive Freedom SOC implementation" select RISCV - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED help Enable support for SiFive Freedom SOC diff --git a/soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.series b/soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.series index b360f78b77b..19cedcefe27 100644 --- a/soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.series +++ b/soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.series @@ -4,6 +4,6 @@ config SOC_SERIES_STARFIVE_JH71XX bool "Starfive JH71XX series" select RISCV - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED help Enable support for Starfive JH71XX SoC Series. diff --git a/soc/riscv/riscv-privileged/telink_b91/Kconfig.series b/soc/riscv/riscv-privileged/telink_b91/Kconfig.series index a966dfe447b..cce6011ce68 100644 --- a/soc/riscv/riscv-privileged/telink_b91/Kconfig.series +++ b/soc/riscv/riscv-privileged/telink_b91/Kconfig.series @@ -10,7 +10,7 @@ config SOC_SERIES_RISCV_TELINK_B91 select RISCV_ISA_EXT_C select RISCV_ISA_EXT_ZICSR select RISCV_ISA_EXT_ZIFENCEI - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED select HAS_TELINK_DRIVERS help Enable support for Telink B91 SoC diff --git a/soc/riscv/riscv-privileged/virt/Kconfig.series b/soc/riscv/riscv-privileged/virt/Kconfig.series index e9846764f6b..44ec681a308 100644 --- a/soc/riscv/riscv-privileged/virt/Kconfig.series +++ b/soc/riscv/riscv-privileged/virt/Kconfig.series @@ -4,4 +4,4 @@ config SOC_SERIES_RISCV_VIRT bool "QEMU RISC-V VirtIO Board" select RISCV - select SOC_FAMILY_RISCV_PRIVILEGED + select RISCV_PRIVILEGED diff --git a/tests/kernel/gen_isr_table/testcase.yaml b/tests/kernel/gen_isr_table/testcase.yaml index cd8c95e2584..4ee3ad00ac9 100644 --- a/tests/kernel/gen_isr_table/testcase.yaml +++ b/tests/kernel/gen_isr_table/testcase.yaml @@ -53,7 +53,7 @@ tests: platform_exclude: - m2gl025_miv - adp_xc7k_ae350 - filter: CONFIG_SOC_FAMILY_RISCV_PRIVILEGED + filter: CONFIG_RISCV_PRIVILEGED extra_configs: - CONFIG_GEN_IRQ_VECTOR_TABLE=y arch.interrupt.gen_isr_table.riscv_no_direct: @@ -61,18 +61,18 @@ tests: arch_allow: - riscv32 - riscv64 - filter: CONFIG_SOC_FAMILY_RISCV_PRIVILEGED + filter: CONFIG_RISCV_PRIVILEGED extra_configs: - CONFIG_GEN_IRQ_VECTOR_TABLE=n arch.interrupt.gen_isr_table.bit_shift_2nd_level: platform_allow: qemu_riscv32 - filter: CONFIG_SOC_FAMILY_RISCV_PRIVILEGED + filter: CONFIG_RISCV_PRIVILEGED extra_configs: - CONFIG_1ST_LEVEL_INTERRUPT_BITS=10 - CONFIG_2ND_LEVEL_INTERRUPT_BITS=10 arch.interrupt.gen_isr_table.bit_shift_3rd_level: platform_allow: qemu_riscv32 - filter: CONFIG_SOC_FAMILY_RISCV_PRIVILEGED + filter: CONFIG_RISCV_PRIVILEGED extra_configs: - CONFIG_MULTI_LEVEL_INTERRUPTS=y - CONFIG_2ND_LEVEL_INTERRUPTS=y From 69b5551bf88f4f30cc766ffcc5d1a15b6a3b8588 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 14:02:24 +0100 Subject: [PATCH 1187/1623] [nrf fromtree] soc: riscv: introduce temporary RISCV_PRIVILEGED_STANDALONE So that SoCs can be ported outside of riscv-privileged folder, setting their own family name. This will be removed once all SoCs are ported. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit d8c0cc2e3502da55338c5563feb8b4bebe193d5e) --- soc/riscv/common/riscv-privileged/Kconfig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/soc/riscv/common/riscv-privileged/Kconfig b/soc/riscv/common/riscv-privileged/Kconfig index 526dea4bbfb..de064842604 100644 --- a/soc/riscv/common/riscv-privileged/Kconfig +++ b/soc/riscv/common/riscv-privileged/Kconfig @@ -4,9 +4,12 @@ # Copyright (c) 2017 Jean-Paul Etienne # SPDX-License-Identifier: Apache-2.0 +config RISCV_PRIVILEGED_STANDALONE + bool + config SOC_FAMILY string - default "riscv-privileged" if RISCV_PRIVILEGED + default "riscv-privileged" if RISCV_PRIVILEGED && !RISCV_PRIVILEGED_STANDALONE config RISCV_HAS_PLIC bool "Does the SOC provide support for a Platform Level Interrupt Controller (PLIC)" From a8ac61d44bef8a27180e5810827c77ce669c170f Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 14:00:12 +0100 Subject: [PATCH 1188/1623] [nrf fromtree] soc: riscv: telink_b91: reorganize SoC folder Reorganize following the hierarchy found in the vendor website [1]: - SoC Family: Telink TLSR - SoC series: TLSR951X - SoC: TLSR9518 Also split out from riscv-privileged folder. Note that B91 was the name of a starter kit [2]. [1]: http://wiki.telink-semi.cn/wiki/chip-series/TLSR951x-Series/ [2]: https://wiki.telink-semi.cn/wiki/Hardware/ B91_Generic_Starter_Kit_Hardware_Guide/ Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 72e52a06aa474917443e522963429448d2d780b8) --- boards/riscv/tlsr9518adk80d/Kconfig.board | 2 +- .../tlsr9518adk80d/tlsr9518adk80d_defconfig | 4 +- .../riscv-privileged/telink_b91/Kconfig.soc | 40 ------------------- soc/riscv/telink_tlsr/CMakeLists.txt | 4 ++ soc/riscv/telink_tlsr/Kconfig | 15 +++++++ soc/riscv/telink_tlsr/Kconfig.defconfig | 4 ++ soc/riscv/telink_tlsr/Kconfig.soc | 4 ++ .../tlsr951x}/CMakeLists.txt | 0 .../tlsr951x}/Kconfig.defconfig.series | 8 ++-- .../tlsr951x/Kconfig.defconfig.tlsr9518 | 5 +++ .../tlsr951x}/Kconfig.series | 11 +++-- soc/riscv/telink_tlsr/tlsr951x/Kconfig.soc | 23 +++++++++++ .../tlsr951x}/init.ld | 0 .../tlsr951x}/linker.ld | 0 .../tlsr951x}/pinctrl_soc.h | 0 .../telink_b91 => telink_tlsr/tlsr951x}/soc.c | 0 .../telink_b91 => telink_tlsr/tlsr951x}/soc.h | 0 .../tlsr951x}/soc_context.h | 0 .../tlsr951x}/soc_irq.S | 0 .../tlsr951x}/soc_offsets.h | 0 .../tlsr951x}/start.S | 0 21 files changed, 71 insertions(+), 49 deletions(-) delete mode 100644 soc/riscv/riscv-privileged/telink_b91/Kconfig.soc create mode 100644 soc/riscv/telink_tlsr/CMakeLists.txt create mode 100644 soc/riscv/telink_tlsr/Kconfig create mode 100644 soc/riscv/telink_tlsr/Kconfig.defconfig create mode 100644 soc/riscv/telink_tlsr/Kconfig.soc rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/CMakeLists.txt (100%) rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/Kconfig.defconfig.series (81%) create mode 100644 soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.tlsr9518 rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/Kconfig.series (55%) create mode 100644 soc/riscv/telink_tlsr/tlsr951x/Kconfig.soc rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/init.ld (100%) rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/linker.ld (100%) rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/pinctrl_soc.h (100%) rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/soc.c (100%) rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/soc.h (100%) rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/soc_context.h (100%) rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/soc_irq.S (100%) rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/soc_offsets.h (100%) rename soc/riscv/{riscv-privileged/telink_b91 => telink_tlsr/tlsr951x}/start.S (100%) diff --git a/boards/riscv/tlsr9518adk80d/Kconfig.board b/boards/riscv/tlsr9518adk80d/Kconfig.board index bd36cb0e481..971b34dc13b 100644 --- a/boards/riscv/tlsr9518adk80d/Kconfig.board +++ b/boards/riscv/tlsr9518adk80d/Kconfig.board @@ -3,4 +3,4 @@ config BOARD_TLSR9518ADK80D bool "Telink B91 Platform" - depends on SOC_RISCV_TELINK_B91 + depends on SOC_TELINK_TLSR9518 diff --git a/boards/riscv/tlsr9518adk80d/tlsr9518adk80d_defconfig b/boards/riscv/tlsr9518adk80d/tlsr9518adk80d_defconfig index fe5cfbe8c2e..c4cfdfea718 100644 --- a/boards/riscv/tlsr9518adk80d/tlsr9518adk80d_defconfig +++ b/boards/riscv/tlsr9518adk80d/tlsr9518adk80d_defconfig @@ -1,8 +1,8 @@ # Copyright (c) 2021 Telink Semiconductor # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV_TELINK_B91=y -CONFIG_SOC_RISCV_TELINK_B91=y +CONFIG_SOC_SERIES_TELINK_TLSR951X=y +CONFIG_SOC_TELINK_TLSR9518=y CONFIG_BOARD_TLSR9518ADK80D=y CONFIG_GPIO=y CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 diff --git a/soc/riscv/riscv-privileged/telink_b91/Kconfig.soc b/soc/riscv/riscv-privileged/telink_b91/Kconfig.soc deleted file mode 100644 index 3f4f96c332e..00000000000 --- a/soc/riscv/riscv-privileged/telink_b91/Kconfig.soc +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (c) 2021 Telink Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -choice -prompt "CPU Architecture of SoC" -depends on SOC_SERIES_RISCV_TELINK_B91 - -config B91_CPU_RISCV32 - bool "RISCV32 CPU Architecture" - select RISCV_ISA_RV32I - select RISCV_ISA_EXT_M - select RISCV_ISA_EXT_A - select RISCV_ISA_EXT_C - select RISCV_ISA_EXT_ZICSR - select RISCV_ISA_EXT_ZIFENCEI - -endchoice - -config TELINK_B91_HWDSP - bool "Support Hardware DSP" - select RISCV_SOC_CONTEXT_SAVE - depends on SOC_SERIES_RISCV_TELINK_B91 - -config TELINK_B91_PFT_ARCH - bool "Support performance throttling" - default y - select RISCV_SOC_CONTEXT_SAVE - depends on SOC_SERIES_RISCV_TELINK_B91 - -choice -prompt "Telink B91 SoC implementation" -depends on SOC_SERIES_RISCV_TELINK_B91 - -config SOC_RISCV_TELINK_B91 - bool "Telink B91 SoC implementation" - select ATOMIC_OPERATIONS_BUILTIN - select CPU_HAS_FPU - select INCLUDE_RESET_VECTOR - -endchoice diff --git a/soc/riscv/telink_tlsr/CMakeLists.txt b/soc/riscv/telink_tlsr/CMakeLists.txt new file mode 100644 index 00000000000..69b2926358e --- /dev/null +++ b/soc/riscv/telink_tlsr/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(${SOC_SERIES}) diff --git a/soc/riscv/telink_tlsr/Kconfig b/soc/riscv/telink_tlsr/Kconfig new file mode 100644 index 00000000000..144751311ba --- /dev/null +++ b/soc/riscv/telink_tlsr/Kconfig @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FAMILY_TELINK_TLSR + bool + +if SOC_FAMILY_TELINK_TLSR + +config SOC_FAMILY + string + default "telink_tlsr" + +source "soc/riscv/telink_tlsr/*/Kconfig.soc" + +endif # SOC_FAMILY_TELINK_TLSR diff --git a/soc/riscv/telink_tlsr/Kconfig.defconfig b/soc/riscv/telink_tlsr/Kconfig.defconfig new file mode 100644 index 00000000000..04a888381fa --- /dev/null +++ b/soc/riscv/telink_tlsr/Kconfig.defconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/telink_tlsr/*/Kconfig.defconfig.series" diff --git a/soc/riscv/telink_tlsr/Kconfig.soc b/soc/riscv/telink_tlsr/Kconfig.soc new file mode 100644 index 00000000000..db09c69d1f4 --- /dev/null +++ b/soc/riscv/telink_tlsr/Kconfig.soc @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/telink_tlsr/*/Kconfig.series" diff --git a/soc/riscv/riscv-privileged/telink_b91/CMakeLists.txt b/soc/riscv/telink_tlsr/tlsr951x/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/telink_b91/CMakeLists.txt rename to soc/riscv/telink_tlsr/tlsr951x/CMakeLists.txt diff --git a/soc/riscv/riscv-privileged/telink_b91/Kconfig.defconfig.series b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series similarity index 81% rename from soc/riscv/riscv-privileged/telink_b91/Kconfig.defconfig.series rename to soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series index 986b6240750..23a78c9f0da 100644 --- a/soc/riscv/riscv-privileged/telink_b91/Kconfig.defconfig.series +++ b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series @@ -1,11 +1,11 @@ # Copyright (c) 2021 Telink Semiconductor # SPDX-License-Identifier: Apache-2.0 -if SOC_SERIES_RISCV_TELINK_B91 +if SOC_SERIES_TELINK_TLSR951X config SOC_SERIES string - default "telink_b91" + default "tlsr951x" config SYS_CLOCK_HW_CYCLES_PER_SEC int @@ -56,4 +56,6 @@ config 2ND_LVL_INTR_00_OFFSET config HAS_FLASH_LOAD_OFFSET default y if BOOTLOADER_MCUBOOT -endif # SOC_SERIES_RISCV_TELINK_B91 +source "soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.tlsr*" + +endif # SOC_SERIES_TELINK_TLSR951X diff --git a/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.tlsr9518 b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.tlsr9518 new file mode 100644 index 00000000000..4ffdebdaf6b --- /dev/null +++ b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.tlsr9518 @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC + default "tlsr9518" if SOC_TELINK_TLSR9518 diff --git a/soc/riscv/riscv-privileged/telink_b91/Kconfig.series b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.series similarity index 55% rename from soc/riscv/riscv-privileged/telink_b91/Kconfig.series rename to soc/riscv/telink_tlsr/tlsr951x/Kconfig.series index cce6011ce68..e074a53e11b 100644 --- a/soc/riscv/riscv-privileged/telink_b91/Kconfig.series +++ b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.series @@ -1,8 +1,8 @@ # Copyright (c) 2021 Telink Semiconductor # SPDX-License-Identifier: Apache-2.0 -config SOC_SERIES_RISCV_TELINK_B91 - bool "Telink B91 SoC Implementation" +config SOC_SERIES_TELINK_TLSR951X + bool "Telink TLSR951X" select RISCV select RISCV_ISA_RV32I select RISCV_ISA_EXT_M @@ -12,5 +12,10 @@ config SOC_SERIES_RISCV_TELINK_B91 select RISCV_ISA_EXT_ZIFENCEI select RISCV_PRIVILEGED select HAS_TELINK_DRIVERS + select ATOMIC_OPERATIONS_BUILTIN + select CPU_HAS_FPU + select INCLUDE_RESET_VECTOR + select SOC_FAMILY_TELINK_TLSR + select RISCV_PRIVILEGED_STANDALONE help - Enable support for Telink B91 SoC + Enable support for Telink TLSR951X diff --git a/soc/riscv/telink_tlsr/tlsr951x/Kconfig.soc b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.soc new file mode 100644 index 00000000000..2abc12cc58c --- /dev/null +++ b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.soc @@ -0,0 +1,23 @@ +# Copyright (c) 2021 Telink Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_TELINK_TLSR951X + +choice + prompt "Telink TLSR951X SoC implementation" + +config SOC_TELINK_TLSR9518 + bool "Telink TLSR9518" + +endchoice + +config TELINK_B91_HWDSP + bool "Support Hardware DSP" + select RISCV_SOC_CONTEXT_SAVE + +config TELINK_B91_PFT_ARCH + bool "Support performance throttling" + default y + select RISCV_SOC_CONTEXT_SAVE + +endif # SOC_SERIES_TELINK_TLSR951X diff --git a/soc/riscv/riscv-privileged/telink_b91/init.ld b/soc/riscv/telink_tlsr/tlsr951x/init.ld similarity index 100% rename from soc/riscv/riscv-privileged/telink_b91/init.ld rename to soc/riscv/telink_tlsr/tlsr951x/init.ld diff --git a/soc/riscv/riscv-privileged/telink_b91/linker.ld b/soc/riscv/telink_tlsr/tlsr951x/linker.ld similarity index 100% rename from soc/riscv/riscv-privileged/telink_b91/linker.ld rename to soc/riscv/telink_tlsr/tlsr951x/linker.ld diff --git a/soc/riscv/riscv-privileged/telink_b91/pinctrl_soc.h b/soc/riscv/telink_tlsr/tlsr951x/pinctrl_soc.h similarity index 100% rename from soc/riscv/riscv-privileged/telink_b91/pinctrl_soc.h rename to soc/riscv/telink_tlsr/tlsr951x/pinctrl_soc.h diff --git a/soc/riscv/riscv-privileged/telink_b91/soc.c b/soc/riscv/telink_tlsr/tlsr951x/soc.c similarity index 100% rename from soc/riscv/riscv-privileged/telink_b91/soc.c rename to soc/riscv/telink_tlsr/tlsr951x/soc.c diff --git a/soc/riscv/riscv-privileged/telink_b91/soc.h b/soc/riscv/telink_tlsr/tlsr951x/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/telink_b91/soc.h rename to soc/riscv/telink_tlsr/tlsr951x/soc.h diff --git a/soc/riscv/riscv-privileged/telink_b91/soc_context.h b/soc/riscv/telink_tlsr/tlsr951x/soc_context.h similarity index 100% rename from soc/riscv/riscv-privileged/telink_b91/soc_context.h rename to soc/riscv/telink_tlsr/tlsr951x/soc_context.h diff --git a/soc/riscv/riscv-privileged/telink_b91/soc_irq.S b/soc/riscv/telink_tlsr/tlsr951x/soc_irq.S similarity index 100% rename from soc/riscv/riscv-privileged/telink_b91/soc_irq.S rename to soc/riscv/telink_tlsr/tlsr951x/soc_irq.S diff --git a/soc/riscv/riscv-privileged/telink_b91/soc_offsets.h b/soc/riscv/telink_tlsr/tlsr951x/soc_offsets.h similarity index 100% rename from soc/riscv/riscv-privileged/telink_b91/soc_offsets.h rename to soc/riscv/telink_tlsr/tlsr951x/soc_offsets.h diff --git a/soc/riscv/riscv-privileged/telink_b91/start.S b/soc/riscv/telink_tlsr/tlsr951x/start.S similarity index 100% rename from soc/riscv/riscv-privileged/telink_b91/start.S rename to soc/riscv/telink_tlsr/tlsr951x/start.S From 8dc0338a3a585d0d6012b8045572af067f312aa5 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 14:14:00 +0100 Subject: [PATCH 1189/1623] [nrf fromtree] soc: riscv: gd32vf103: reorganize SoC folder Move things out from riscv-privileged, and create the new RISC-V GD32 family. New family folder follows the _ naming convention. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 5a98d87335a2db818259dd71f84b4a9e8df052a2) --- MAINTAINERS.yml | 2 +- soc/riscv/gd_gd32/CMakeLists.txt | 4 ++++ soc/riscv/gd_gd32/Kconfig | 15 +++++++++++++++ soc/riscv/gd_gd32/Kconfig.defconfig | 4 ++++ soc/riscv/gd_gd32/Kconfig.soc | 4 ++++ .../gd32vf103/CMakeLists.txt | 0 .../gd32vf103/Kconfig.defconfig.gd32vf103 | 0 .../gd32vf103/Kconfig.defconfig.series | 2 +- .../gd32vf103/Kconfig.series | 3 ++- .../gd32vf103/Kconfig.soc | 0 .../gd32vf103/entry.S | 0 .../gd32vf103/gd32_regs.h | 0 .../gd32vf103/nuclei_csr.h | 0 .../gd32vf103/pinctrl_soc.h | 0 .../{riscv-privileged => gd_gd32}/gd32vf103/soc.c | 0 .../{riscv-privileged => gd_gd32}/gd32vf103/soc.h | 0 16 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 soc/riscv/gd_gd32/CMakeLists.txt create mode 100644 soc/riscv/gd_gd32/Kconfig create mode 100644 soc/riscv/gd_gd32/Kconfig.defconfig create mode 100644 soc/riscv/gd_gd32/Kconfig.soc rename soc/riscv/{riscv-privileged => gd_gd32}/gd32vf103/CMakeLists.txt (100%) rename soc/riscv/{riscv-privileged => gd_gd32}/gd32vf103/Kconfig.defconfig.gd32vf103 (100%) rename soc/riscv/{riscv-privileged => gd_gd32}/gd32vf103/Kconfig.defconfig.series (72%) rename soc/riscv/{riscv-privileged => gd_gd32}/gd32vf103/Kconfig.series (89%) rename soc/riscv/{riscv-privileged => gd_gd32}/gd32vf103/Kconfig.soc (100%) rename soc/riscv/{riscv-privileged => gd_gd32}/gd32vf103/entry.S (100%) rename soc/riscv/{riscv-privileged => gd_gd32}/gd32vf103/gd32_regs.h (100%) rename soc/riscv/{riscv-privileged => gd_gd32}/gd32vf103/nuclei_csr.h (100%) rename soc/riscv/{riscv-privileged => gd_gd32}/gd32vf103/pinctrl_soc.h (100%) rename soc/riscv/{riscv-privileged => gd_gd32}/gd32vf103/soc.c (100%) rename soc/riscv/{riscv-privileged => gd_gd32}/gd32vf103/soc.h (100%) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index a36838cd65d..255f6cefa2c 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -2472,7 +2472,7 @@ GD32 Platforms: - dts/*/gigadevice/ - dts/bindings/*/*gd32* - soc/arm/gigadevice/ - - soc/riscv/riscv-privileged/gd32vf103/ + - soc/riscv/gd_gd32/ - scripts/west_commands/*/*gd32* labels: - "platform: GD32" diff --git a/soc/riscv/gd_gd32/CMakeLists.txt b/soc/riscv/gd_gd32/CMakeLists.txt new file mode 100644 index 00000000000..69b2926358e --- /dev/null +++ b/soc/riscv/gd_gd32/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(${SOC_SERIES}) diff --git a/soc/riscv/gd_gd32/Kconfig b/soc/riscv/gd_gd32/Kconfig new file mode 100644 index 00000000000..46f2dd0b1d6 --- /dev/null +++ b/soc/riscv/gd_gd32/Kconfig @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FAMILY_GD32 + bool + +if SOC_FAMILY_GD32 + +config SOC_FAMILY + string + default "gd_gd32" + +source "soc/riscv/gd_gd32/*/Kconfig.soc" + +endif # SOC_FAMILY_GIGADEVICE_GD32 diff --git a/soc/riscv/gd_gd32/Kconfig.defconfig b/soc/riscv/gd_gd32/Kconfig.defconfig new file mode 100644 index 00000000000..2be284db7ea --- /dev/null +++ b/soc/riscv/gd_gd32/Kconfig.defconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/gd_gd32/*/Kconfig.defconfig.series" diff --git a/soc/riscv/gd_gd32/Kconfig.soc b/soc/riscv/gd_gd32/Kconfig.soc new file mode 100644 index 00000000000..09d7d5d627e --- /dev/null +++ b/soc/riscv/gd_gd32/Kconfig.soc @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/gd_gd32/*/Kconfig.series" diff --git a/soc/riscv/riscv-privileged/gd32vf103/CMakeLists.txt b/soc/riscv/gd_gd32/gd32vf103/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/gd32vf103/CMakeLists.txt rename to soc/riscv/gd_gd32/gd32vf103/CMakeLists.txt diff --git a/soc/riscv/riscv-privileged/gd32vf103/Kconfig.defconfig.gd32vf103 b/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 similarity index 100% rename from soc/riscv/riscv-privileged/gd32vf103/Kconfig.defconfig.gd32vf103 rename to soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 diff --git a/soc/riscv/riscv-privileged/gd32vf103/Kconfig.defconfig.series b/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.series similarity index 72% rename from soc/riscv/riscv-privileged/gd32vf103/Kconfig.defconfig.series rename to soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.series index 061b53b2514..17ab7a87c39 100644 --- a/soc/riscv/riscv-privileged/gd32vf103/Kconfig.defconfig.series +++ b/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.series @@ -3,7 +3,7 @@ if SOC_SERIES_GD32VF103 -source "soc/riscv/riscv-privileged/gd32vf103/Kconfig.defconfig.gd32vf103*" +source "soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103*" config SOC_SERIES default "gd32vf103" diff --git a/soc/riscv/riscv-privileged/gd32vf103/Kconfig.series b/soc/riscv/gd_gd32/gd32vf103/Kconfig.series similarity index 89% rename from soc/riscv/riscv-privileged/gd32vf103/Kconfig.series rename to soc/riscv/gd_gd32/gd32vf103/Kconfig.series index 79bb3690743..b0b86db7c02 100644 --- a/soc/riscv/riscv-privileged/gd32vf103/Kconfig.series +++ b/soc/riscv/gd_gd32/gd32vf103/Kconfig.series @@ -15,6 +15,7 @@ config SOC_SERIES_GD32VF103 select GD32_HAS_IRC_40K select HAS_GD32_HAL select RISCV_HAS_CLIC - + select SOC_FAMILY_GD32 + select RISCV_PRIVILEGED_STANDALONE help Enable support for GigaDevice GD32VF1 series SoC diff --git a/soc/riscv/riscv-privileged/gd32vf103/Kconfig.soc b/soc/riscv/gd_gd32/gd32vf103/Kconfig.soc similarity index 100% rename from soc/riscv/riscv-privileged/gd32vf103/Kconfig.soc rename to soc/riscv/gd_gd32/gd32vf103/Kconfig.soc diff --git a/soc/riscv/riscv-privileged/gd32vf103/entry.S b/soc/riscv/gd_gd32/gd32vf103/entry.S similarity index 100% rename from soc/riscv/riscv-privileged/gd32vf103/entry.S rename to soc/riscv/gd_gd32/gd32vf103/entry.S diff --git a/soc/riscv/riscv-privileged/gd32vf103/gd32_regs.h b/soc/riscv/gd_gd32/gd32vf103/gd32_regs.h similarity index 100% rename from soc/riscv/riscv-privileged/gd32vf103/gd32_regs.h rename to soc/riscv/gd_gd32/gd32vf103/gd32_regs.h diff --git a/soc/riscv/riscv-privileged/gd32vf103/nuclei_csr.h b/soc/riscv/gd_gd32/gd32vf103/nuclei_csr.h similarity index 100% rename from soc/riscv/riscv-privileged/gd32vf103/nuclei_csr.h rename to soc/riscv/gd_gd32/gd32vf103/nuclei_csr.h diff --git a/soc/riscv/riscv-privileged/gd32vf103/pinctrl_soc.h b/soc/riscv/gd_gd32/gd32vf103/pinctrl_soc.h similarity index 100% rename from soc/riscv/riscv-privileged/gd32vf103/pinctrl_soc.h rename to soc/riscv/gd_gd32/gd32vf103/pinctrl_soc.h diff --git a/soc/riscv/riscv-privileged/gd32vf103/soc.c b/soc/riscv/gd_gd32/gd32vf103/soc.c similarity index 100% rename from soc/riscv/riscv-privileged/gd32vf103/soc.c rename to soc/riscv/gd_gd32/gd32vf103/soc.c diff --git a/soc/riscv/riscv-privileged/gd32vf103/soc.h b/soc/riscv/gd_gd32/gd32vf103/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/gd32vf103/soc.h rename to soc/riscv/gd_gd32/gd32vf103/soc.h From 13dbdb2dd7a1de4cdeab1ed987ca0bdf1e52c942 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 15:15:05 +0100 Subject: [PATCH 1190/1623] [nrf fromtree] soc: riscv: starfive_jh71xx: reorganize SoC folder Move it out from RISC-V privileged folder, and create a standalone family. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 87f3b072922fe3f5f6e55f090e6abd3d155cbf0e) --- soc/riscv/starfive_jh71xx/CMakeLists.txt | 4 ++++ soc/riscv/starfive_jh71xx/Kconfig | 15 +++++++++++++++ soc/riscv/starfive_jh71xx/Kconfig.defconfig | 4 ++++ soc/riscv/starfive_jh71xx/Kconfig.soc | 4 ++++ .../jh71xx}/CMakeLists.txt | 0 .../jh71xx/Kconfig.defconfig.jh7100 | 5 +++++ .../jh71xx}/Kconfig.defconfig.series | 4 +++- .../jh71xx}/Kconfig.series | 1 + .../jh71xx}/Kconfig.soc | 0 .../jh71xx}/soc.h | 0 10 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 soc/riscv/starfive_jh71xx/CMakeLists.txt create mode 100644 soc/riscv/starfive_jh71xx/Kconfig create mode 100644 soc/riscv/starfive_jh71xx/Kconfig.defconfig create mode 100644 soc/riscv/starfive_jh71xx/Kconfig.soc rename soc/riscv/{riscv-privileged/starfive_jh71xx => starfive_jh71xx/jh71xx}/CMakeLists.txt (100%) create mode 100644 soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.jh7100 rename soc/riscv/{riscv-privileged/starfive_jh71xx => starfive_jh71xx/jh71xx}/Kconfig.defconfig.series (84%) rename soc/riscv/{riscv-privileged/starfive_jh71xx => starfive_jh71xx/jh71xx}/Kconfig.series (88%) rename soc/riscv/{riscv-privileged/starfive_jh71xx => starfive_jh71xx/jh71xx}/Kconfig.soc (100%) rename soc/riscv/{riscv-privileged/starfive_jh71xx => starfive_jh71xx/jh71xx}/soc.h (100%) diff --git a/soc/riscv/starfive_jh71xx/CMakeLists.txt b/soc/riscv/starfive_jh71xx/CMakeLists.txt new file mode 100644 index 00000000000..69b2926358e --- /dev/null +++ b/soc/riscv/starfive_jh71xx/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(${SOC_SERIES}) diff --git a/soc/riscv/starfive_jh71xx/Kconfig b/soc/riscv/starfive_jh71xx/Kconfig new file mode 100644 index 00000000000..65694c07eff --- /dev/null +++ b/soc/riscv/starfive_jh71xx/Kconfig @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FAMILY_STARFIVE_JH71XX + bool + +if SOC_FAMILY_STARFIVE_JH71XX + +config SOC_FAMILY + string + default "starfive_jh71xx" + +source "soc/riscv/starfive_jh71xx/*/Kconfig.soc" + +endif # SOC_FAMILY_STARFIVE_JH71XX diff --git a/soc/riscv/starfive_jh71xx/Kconfig.defconfig b/soc/riscv/starfive_jh71xx/Kconfig.defconfig new file mode 100644 index 00000000000..b399e38b340 --- /dev/null +++ b/soc/riscv/starfive_jh71xx/Kconfig.defconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/starfive_jh71xx/*/Kconfig.defconfig.series" diff --git a/soc/riscv/starfive_jh71xx/Kconfig.soc b/soc/riscv/starfive_jh71xx/Kconfig.soc new file mode 100644 index 00000000000..1ff54faa970 --- /dev/null +++ b/soc/riscv/starfive_jh71xx/Kconfig.soc @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/starfive_jh71xx/*/Kconfig.series" diff --git a/soc/riscv/riscv-privileged/starfive_jh71xx/CMakeLists.txt b/soc/riscv/starfive_jh71xx/jh71xx/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/starfive_jh71xx/CMakeLists.txt rename to soc/riscv/starfive_jh71xx/jh71xx/CMakeLists.txt diff --git a/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.jh7100 b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.jh7100 new file mode 100644 index 00000000000..6f38d61dd4e --- /dev/null +++ b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.jh7100 @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC + default "jh7100" if SOC_JH7100 diff --git a/soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.defconfig.series b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series similarity index 84% rename from soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.defconfig.series rename to soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series index c488c614b7d..77436b593e1 100644 --- a/soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.defconfig.series +++ b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series @@ -4,7 +4,7 @@ if SOC_SERIES_STARFIVE_JH71XX config SOC_SERIES - default "starfive_jh71xx" + default "jh71xx" config SYS_CLOCK_HW_CYCLES_PER_SEC default 6250000 @@ -30,4 +30,6 @@ config 2ND_LVL_INTR_00_OFFSET config NUM_IRQS default 139 +source "soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.jh71*" + endif diff --git a/soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.series b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series similarity index 88% rename from soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.series rename to soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series index 19cedcefe27..d70cff1c63d 100644 --- a/soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.series +++ b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series @@ -5,5 +5,6 @@ config SOC_SERIES_STARFIVE_JH71XX bool "Starfive JH71XX series" select RISCV select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE help Enable support for Starfive JH71XX SoC Series. diff --git a/soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.soc b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.soc similarity index 100% rename from soc/riscv/riscv-privileged/starfive_jh71xx/Kconfig.soc rename to soc/riscv/starfive_jh71xx/jh71xx/Kconfig.soc diff --git a/soc/riscv/riscv-privileged/starfive_jh71xx/soc.h b/soc/riscv/starfive_jh71xx/jh71xx/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/starfive_jh71xx/soc.h rename to soc/riscv/starfive_jh71xx/jh71xx/soc.h From e49c07725f1b8bbce00b2406b2630ba13b75e176 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 15:25:56 +0100 Subject: [PATCH 1191/1623] [nrf fromtree] soc: riscv: andes_v5: reorganize SoC folder Split out from riscv-privileged folder, and create a new family. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 8027689392f6ba835906efe56296094bf49e3aa8) --- boards/riscv/adp_xc7k_ae350/Kconfig.board | 2 +- .../riscv/adp_xc7k_ae350/adp_xc7k_ae350_defconfig | 4 ++-- drivers/hwinfo/Kconfig | 2 +- soc/riscv/andes_v5/CMakeLists.txt | 4 ++++ soc/riscv/andes_v5/Kconfig | 15 +++++++++++++++ soc/riscv/andes_v5/Kconfig.defconfig | 4 ++++ soc/riscv/andes_v5/Kconfig.soc | 4 ++++ .../andes_v5 => andes_v5/ae350}/CMakeLists.txt | 6 +++--- .../ae350}/Kconfig.defconfig.ae350 | 4 ++-- .../ae350}/Kconfig.defconfig.series | 8 ++++---- soc/riscv/andes_v5/ae350/Kconfig.series | 11 +++++++++++ .../andes_v5 => andes_v5/ae350}/Kconfig.soc | 8 ++++---- .../ae350}/common_linker/execit.ld | 0 .../ae350}/common_linker/init.ld | 0 .../ae350}/common_linker/ram_start_nonzero.ld | 0 .../andes_v5 => andes_v5/ae350}/l2_cache.c | 0 .../andes_v5/ae350/linker.ld | 0 .../andes_v5 => andes_v5/ae350}/pma.c | 0 .../{riscv-privileged => }/andes_v5/ae350/soc.h | 0 .../andes_v5 => andes_v5/ae350}/soc_context.h | 0 .../andes_v5 => andes_v5/ae350}/soc_irq.S | 0 .../andes_v5 => andes_v5/ae350}/soc_offsets.h | 0 .../andes_v5 => andes_v5/ae350}/soc_v5.h | 0 .../andes_v5 => andes_v5/ae350}/start.S | 0 .../riscv-privileged/andes_v5/Kconfig.series | 9 --------- 25 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 soc/riscv/andes_v5/CMakeLists.txt create mode 100644 soc/riscv/andes_v5/Kconfig create mode 100644 soc/riscv/andes_v5/Kconfig.defconfig create mode 100644 soc/riscv/andes_v5/Kconfig.soc rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/CMakeLists.txt (82%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/Kconfig.defconfig.ae350 (88%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/Kconfig.defconfig.series (83%) create mode 100644 soc/riscv/andes_v5/ae350/Kconfig.series rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/Kconfig.soc (95%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/common_linker/execit.ld (100%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/common_linker/init.ld (100%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/common_linker/ram_start_nonzero.ld (100%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/l2_cache.c (100%) rename soc/riscv/{riscv-privileged => }/andes_v5/ae350/linker.ld (100%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/pma.c (100%) rename soc/riscv/{riscv-privileged => }/andes_v5/ae350/soc.h (100%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/soc_context.h (100%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/soc_irq.S (100%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/soc_offsets.h (100%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/soc_v5.h (100%) rename soc/riscv/{riscv-privileged/andes_v5 => andes_v5/ae350}/start.S (100%) delete mode 100644 soc/riscv/riscv-privileged/andes_v5/Kconfig.series diff --git a/boards/riscv/adp_xc7k_ae350/Kconfig.board b/boards/riscv/adp_xc7k_ae350/Kconfig.board index 085eb9696a8..5b58e01fbfd 100644 --- a/boards/riscv/adp_xc7k_ae350/Kconfig.board +++ b/boards/riscv/adp_xc7k_ae350/Kconfig.board @@ -3,4 +3,4 @@ config BOARD_ADP_XC7K_AE350 bool "Andes ADP-XC7K AE350 Platform" - depends on SOC_RISCV_ANDES_AE350 + depends on SOC_ANDES_AE350 diff --git a/boards/riscv/adp_xc7k_ae350/adp_xc7k_ae350_defconfig b/boards/riscv/adp_xc7k_ae350/adp_xc7k_ae350_defconfig index 3f7f1f727c6..edbe7118c64 100644 --- a/boards/riscv/adp_xc7k_ae350/adp_xc7k_ae350_defconfig +++ b/boards/riscv/adp_xc7k_ae350/adp_xc7k_ae350_defconfig @@ -1,5 +1,5 @@ -CONFIG_SOC_SERIES_RISCV_ANDES_V5=y -CONFIG_SOC_RISCV_ANDES_AE350=y +CONFIG_SOC_SERIES_ANDES_AE350=y +CONFIG_SOC_ANDES_AE350=y CONFIG_BOARD_ADP_XC7K_AE350=y CONFIG_XIP=n CONFIG_CONSOLE=y diff --git a/drivers/hwinfo/Kconfig b/drivers/hwinfo/Kconfig index 7c4cc7f0805..4bf9e462318 100644 --- a/drivers/hwinfo/Kconfig +++ b/drivers/hwinfo/Kconfig @@ -181,7 +181,7 @@ config HWINFO_GECKO config HWINFO_ANDES bool "Andes system ID" default y - depends on SOC_SERIES_RISCV_ANDES_V5 + depends on SOC_FAMILY_ANDES_V5 help Enable Andes hwinfo driver diff --git a/soc/riscv/andes_v5/CMakeLists.txt b/soc/riscv/andes_v5/CMakeLists.txt new file mode 100644 index 00000000000..69b2926358e --- /dev/null +++ b/soc/riscv/andes_v5/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(${SOC_SERIES}) diff --git a/soc/riscv/andes_v5/Kconfig b/soc/riscv/andes_v5/Kconfig new file mode 100644 index 00000000000..f3c78ab7f81 --- /dev/null +++ b/soc/riscv/andes_v5/Kconfig @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FAMILY_ANDES_V5 + bool + +if SOC_FAMILY_ANDES_V5 + +config SOC_FAMILY + string + default "andes_v5" + +source "soc/riscv/andes_v5/*/Kconfig.soc" + +endif # SOC_FAMILY_ANDES_V5 diff --git a/soc/riscv/andes_v5/Kconfig.defconfig b/soc/riscv/andes_v5/Kconfig.defconfig new file mode 100644 index 00000000000..6213f28d2cb --- /dev/null +++ b/soc/riscv/andes_v5/Kconfig.defconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/andes_v5/*/Kconfig.defconfig.series" diff --git a/soc/riscv/andes_v5/Kconfig.soc b/soc/riscv/andes_v5/Kconfig.soc new file mode 100644 index 00000000000..9efb4781934 --- /dev/null +++ b/soc/riscv/andes_v5/Kconfig.soc @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/andes_v5/*/Kconfig.series" diff --git a/soc/riscv/riscv-privileged/andes_v5/CMakeLists.txt b/soc/riscv/andes_v5/ae350/CMakeLists.txt similarity index 82% rename from soc/riscv/riscv-privileged/andes_v5/CMakeLists.txt rename to soc/riscv/andes_v5/ae350/CMakeLists.txt index 21268312347..b8eac026dfb 100644 --- a/soc/riscv/riscv-privileged/andes_v5/CMakeLists.txt +++ b/soc/riscv/andes_v5/ae350/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 -zephyr_include_directories(${CONFIG_SOC}) +zephyr_include_directories(.) zephyr_sources( start.S @@ -24,6 +24,6 @@ if(CONFIG_SOC_ANDES_V5_EXECIT) zephyr_ld_options(-Wl,--mexecit) endif() -if(CONFIG_SOC_RISCV_ANDES_AE350) - set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/ae350/linker.ld CACHE INTERNAL "") +if(CONFIG_SOC_ANDES_AE350) + set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld CACHE INTERNAL "") endif() diff --git a/soc/riscv/riscv-privileged/andes_v5/Kconfig.defconfig.ae350 b/soc/riscv/andes_v5/ae350/Kconfig.defconfig.ae350 similarity index 88% rename from soc/riscv/riscv-privileged/andes_v5/Kconfig.defconfig.ae350 rename to soc/riscv/andes_v5/ae350/Kconfig.defconfig.ae350 index 5d652057a38..fee73684b71 100644 --- a/soc/riscv/riscv-privileged/andes_v5/Kconfig.defconfig.ae350 +++ b/soc/riscv/andes_v5/ae350/Kconfig.defconfig.ae350 @@ -1,7 +1,7 @@ # Copyright (c) 2021 Andes Technology Corporation # SPDX-License-Identifier: Apache-2.0 -if SOC_RISCV_ANDES_AE350 +if SOC_ANDES_AE350 config SOC default "ae350" @@ -25,4 +25,4 @@ config MP_MAX_NUM_CPUS default 1 range 1 8 -endif # SOC_RISCV_ANDES_AE350 +endif # SOC_ANDES_AE350 diff --git a/soc/riscv/riscv-privileged/andes_v5/Kconfig.defconfig.series b/soc/riscv/andes_v5/ae350/Kconfig.defconfig.series similarity index 83% rename from soc/riscv/riscv-privileged/andes_v5/Kconfig.defconfig.series rename to soc/riscv/andes_v5/ae350/Kconfig.defconfig.series index c6436807825..7bd679e5f45 100644 --- a/soc/riscv/riscv-privileged/andes_v5/Kconfig.defconfig.series +++ b/soc/riscv/andes_v5/ae350/Kconfig.defconfig.series @@ -1,15 +1,15 @@ # Copyright (c) 2021 Andes Technology Corporation # SPDX-License-Identifier: Apache-2.0 -if SOC_SERIES_RISCV_ANDES_V5 +if SOC_SERIES_ANDES_AE350 # Kconfig picks the first default with a satisfied condition. # SoC defaults should be parsed before SoC Series defaults, because SoCs usually # overrides SoC Series values. -source "soc/riscv/riscv-privileged/andes_v5/Kconfig.defconfig.ae*" +source "soc/riscv/andes_v5/ae350/Kconfig.defconfig.ae*" config SOC_SERIES - default "andes_v5" + default "ae350" config SYS_CLOCK_HW_CYCLES_PER_SEC default 60000000 @@ -45,4 +45,4 @@ config MAX_IRQ_PER_AGGREGATOR config NUM_IRQS default 64 -endif # SOC_SERIES_RISCV_ANDES_V5 +endif # SOC_SERIES_ANDES_AE350 diff --git a/soc/riscv/andes_v5/ae350/Kconfig.series b/soc/riscv/andes_v5/ae350/Kconfig.series new file mode 100644 index 00000000000..4eb9557f92f --- /dev/null +++ b/soc/riscv/andes_v5/ae350/Kconfig.series @@ -0,0 +1,11 @@ +# Copyright (c) 2021 Andes Technology Corporation +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_ANDES_AE350 + bool "Andes V5 AE350 SoC Series Implementation" + select RISCV + select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE + select SOC_FAMILY_ANDES_V5 + help + Enable support for Andes V5 AE350 SoC Series diff --git a/soc/riscv/riscv-privileged/andes_v5/Kconfig.soc b/soc/riscv/andes_v5/ae350/Kconfig.soc similarity index 95% rename from soc/riscv/riscv-privileged/andes_v5/Kconfig.soc rename to soc/riscv/andes_v5/ae350/Kconfig.soc index 19f215e2c5a..1731cc08f51 100644 --- a/soc/riscv/riscv-privileged/andes_v5/Kconfig.soc +++ b/soc/riscv/andes_v5/ae350/Kconfig.soc @@ -3,9 +3,9 @@ choice prompt "Andes V5 SoC Selection" -depends on SOC_SERIES_RISCV_ANDES_V5 +depends on SOC_SERIES_ANDES_AE350 -config SOC_RISCV_ANDES_AE350 +config SOC_ANDES_AE350 bool "Andes AE350 SoC implementation" select ATOMIC_OPERATIONS_BUILTIN select INCLUDE_RESET_VECTOR @@ -18,7 +18,7 @@ config SOC_RISCV_ANDES_AE350 endchoice -if SOC_SERIES_RISCV_ANDES_V5 +if SOC_SERIES_ANDES_AE350 choice prompt "Base CPU ISA options" @@ -121,4 +121,4 @@ config SOC_ANDES_V5_IOCP between cache and external non-caching master, such as DMA controller. -endif # SOC_SERIES_RISCV_ANDES_V5 +endif # SOC_SERIES_ANDES_AE350 diff --git a/soc/riscv/riscv-privileged/andes_v5/common_linker/execit.ld b/soc/riscv/andes_v5/ae350/common_linker/execit.ld similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/common_linker/execit.ld rename to soc/riscv/andes_v5/ae350/common_linker/execit.ld diff --git a/soc/riscv/riscv-privileged/andes_v5/common_linker/init.ld b/soc/riscv/andes_v5/ae350/common_linker/init.ld similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/common_linker/init.ld rename to soc/riscv/andes_v5/ae350/common_linker/init.ld diff --git a/soc/riscv/riscv-privileged/andes_v5/common_linker/ram_start_nonzero.ld b/soc/riscv/andes_v5/ae350/common_linker/ram_start_nonzero.ld similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/common_linker/ram_start_nonzero.ld rename to soc/riscv/andes_v5/ae350/common_linker/ram_start_nonzero.ld diff --git a/soc/riscv/riscv-privileged/andes_v5/l2_cache.c b/soc/riscv/andes_v5/ae350/l2_cache.c similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/l2_cache.c rename to soc/riscv/andes_v5/ae350/l2_cache.c diff --git a/soc/riscv/riscv-privileged/andes_v5/ae350/linker.ld b/soc/riscv/andes_v5/ae350/linker.ld similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/ae350/linker.ld rename to soc/riscv/andes_v5/ae350/linker.ld diff --git a/soc/riscv/riscv-privileged/andes_v5/pma.c b/soc/riscv/andes_v5/ae350/pma.c similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/pma.c rename to soc/riscv/andes_v5/ae350/pma.c diff --git a/soc/riscv/riscv-privileged/andes_v5/ae350/soc.h b/soc/riscv/andes_v5/ae350/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/ae350/soc.h rename to soc/riscv/andes_v5/ae350/soc.h diff --git a/soc/riscv/riscv-privileged/andes_v5/soc_context.h b/soc/riscv/andes_v5/ae350/soc_context.h similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/soc_context.h rename to soc/riscv/andes_v5/ae350/soc_context.h diff --git a/soc/riscv/riscv-privileged/andes_v5/soc_irq.S b/soc/riscv/andes_v5/ae350/soc_irq.S similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/soc_irq.S rename to soc/riscv/andes_v5/ae350/soc_irq.S diff --git a/soc/riscv/riscv-privileged/andes_v5/soc_offsets.h b/soc/riscv/andes_v5/ae350/soc_offsets.h similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/soc_offsets.h rename to soc/riscv/andes_v5/ae350/soc_offsets.h diff --git a/soc/riscv/riscv-privileged/andes_v5/soc_v5.h b/soc/riscv/andes_v5/ae350/soc_v5.h similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/soc_v5.h rename to soc/riscv/andes_v5/ae350/soc_v5.h diff --git a/soc/riscv/riscv-privileged/andes_v5/start.S b/soc/riscv/andes_v5/ae350/start.S similarity index 100% rename from soc/riscv/riscv-privileged/andes_v5/start.S rename to soc/riscv/andes_v5/ae350/start.S diff --git a/soc/riscv/riscv-privileged/andes_v5/Kconfig.series b/soc/riscv/riscv-privileged/andes_v5/Kconfig.series deleted file mode 100644 index a85c521492b..00000000000 --- a/soc/riscv/riscv-privileged/andes_v5/Kconfig.series +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2021 Andes Technology Corporation -# SPDX-License-Identifier: Apache-2.0 - -config SOC_SERIES_RISCV_ANDES_V5 - bool "Andes V5 SoC Series Implementation" - select RISCV - select RISCV_PRIVILEGED - help - Enable support for Andes V5 SoC Series From c0174179b7a7679bd3c9ad9c0132df6990fa27fd Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 15:36:49 +0100 Subject: [PATCH 1192/1623] [nrf fromtree] soc: riscv: ite: reorganize SoC folder Follow the vendor structure [1]: - Family: ITE Embedded Controller SoCs - Series: IT8XXX2 - SoCs: IT81202BX, IT81202CX, etc. [1]: https://www.ite.com.tw/en/product/category?cid=1 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 4a0d880350b84d22789a37c942a567c6036e8aca) --- MAINTAINERS.yml | 2 +- boards/riscv/it82xx2_evb/it82xx2_evb_defconfig | 2 +- boards/riscv/it8xxx2_evb/it8xxx2_evb_defconfig | 2 +- soc/riscv/{riscv-ite => ite_ec}/CMakeLists.txt | 0 soc/riscv/ite_ec/Kconfig | 17 +++++++++++++++++ .../{riscv-ite => ite_ec}/Kconfig.defconfig | 2 +- soc/riscv/{riscv-ite => ite_ec}/Kconfig.soc | 2 +- .../{riscv-ite => ite_ec}/common/CMakeLists.txt | 0 .../{riscv-ite => ite_ec}/common/check_regs.c | 0 .../common/chip_chipregs.h | 0 .../{riscv-ite => ite_ec}/common/pinctrl_soc.h | 0 soc/riscv/{riscv-ite => ite_ec}/common/policy.c | 0 soc/riscv/{riscv-ite => ite_ec}/common/power.c | 0 .../{riscv-ite => ite_ec}/common/soc_common.h | 0 .../common/soc_common_irq.c | 0 soc/riscv/{riscv-ite => ite_ec}/common/soc_dt.h | 0 .../{riscv-ite => ite_ec}/common/soc_espi.h | 0 .../{riscv-ite => ite_ec}/common/soc_irq.S | 0 soc/riscv/{riscv-ite => ite_ec}/common/vector.S | 0 .../it8xxx2/CMakeLists.txt | 0 .../it8xxx2/Kconfig.defconfig.it81202bx | 0 .../it8xxx2/Kconfig.defconfig.it81202cx | 0 .../it8xxx2/Kconfig.defconfig.it81302bx | 0 .../it8xxx2/Kconfig.defconfig.it81302cx | 0 .../it8xxx2/Kconfig.defconfig.it82002aw | 0 .../it8xxx2/Kconfig.defconfig.it82202ax | 0 .../it8xxx2/Kconfig.defconfig.it82302ax | 0 .../it8xxx2/Kconfig.defconfig.series | 6 +++--- .../it8xxx2/Kconfig.series | 4 ++-- .../{riscv-ite => ite_ec}/it8xxx2/Kconfig.soc | 2 +- .../it8xxx2/__arithmetic.S | 0 soc/riscv/{riscv-ite => ite_ec}/it8xxx2/ilm.c | 0 soc/riscv/{riscv-ite => ite_ec}/it8xxx2/ilm.h | 0 .../{riscv-ite => ite_ec}/it8xxx2/linker.ld | 0 soc/riscv/{riscv-ite => ite_ec}/it8xxx2/soc.c | 0 soc/riscv/{riscv-ite => ite_ec}/it8xxx2/soc.h | 0 soc/riscv/riscv-ite/Kconfig | 14 -------------- .../gpio/gpio_ite_it8xxx2_v2/CMakeLists.txt | 4 ++-- .../gpio_ite_it8xxx2_v2/include/chip_chipregs.h | 2 +- 39 files changed, 31 insertions(+), 28 deletions(-) rename soc/riscv/{riscv-ite => ite_ec}/CMakeLists.txt (100%) create mode 100644 soc/riscv/ite_ec/Kconfig rename soc/riscv/{riscv-ite => ite_ec}/Kconfig.defconfig (63%) rename soc/riscv/{riscv-ite => ite_ec}/Kconfig.soc (68%) rename soc/riscv/{riscv-ite => ite_ec}/common/CMakeLists.txt (100%) rename soc/riscv/{riscv-ite => ite_ec}/common/check_regs.c (100%) rename soc/riscv/{riscv-ite => ite_ec}/common/chip_chipregs.h (100%) rename soc/riscv/{riscv-ite => ite_ec}/common/pinctrl_soc.h (100%) rename soc/riscv/{riscv-ite => ite_ec}/common/policy.c (100%) rename soc/riscv/{riscv-ite => ite_ec}/common/power.c (100%) rename soc/riscv/{riscv-ite => ite_ec}/common/soc_common.h (100%) rename soc/riscv/{riscv-ite => ite_ec}/common/soc_common_irq.c (100%) rename soc/riscv/{riscv-ite => ite_ec}/common/soc_dt.h (100%) rename soc/riscv/{riscv-ite => ite_ec}/common/soc_espi.h (100%) rename soc/riscv/{riscv-ite => ite_ec}/common/soc_irq.S (100%) rename soc/riscv/{riscv-ite => ite_ec}/common/vector.S (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/CMakeLists.txt (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/Kconfig.defconfig.it81202bx (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/Kconfig.defconfig.it81202cx (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/Kconfig.defconfig.it81302bx (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/Kconfig.defconfig.it81302cx (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/Kconfig.defconfig.it82002aw (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/Kconfig.defconfig.it82202ax (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/Kconfig.defconfig.it82302ax (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/Kconfig.defconfig.series (87%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/Kconfig.series (86%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/Kconfig.soc (99%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/__arithmetic.S (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/ilm.c (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/ilm.h (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/linker.ld (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/soc.c (100%) rename soc/riscv/{riscv-ite => ite_ec}/it8xxx2/soc.h (100%) delete mode 100644 soc/riscv/riscv-ite/Kconfig diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 255f6cefa2c..d7623c89137 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -2850,7 +2850,7 @@ ITE Platforms: - drivers/*/*it8xxx2*.c - dts/bindings/*/*ite* - dts/riscv/ite/ - - soc/riscv/riscv-ite/ + - soc/riscv/ite_ec/ labels: - "platform: ITE" diff --git a/boards/riscv/it82xx2_evb/it82xx2_evb_defconfig b/boards/riscv/it82xx2_evb/it82xx2_evb_defconfig index f082e4a7bad..6866e3f633b 100644 --- a/boards/riscv/it82xx2_evb/it82xx2_evb_defconfig +++ b/boards/riscv/it82xx2_evb/it82xx2_evb_defconfig @@ -1,7 +1,7 @@ # Copyright (c) 2023 ITE Corporation. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV32_IT8XXX2=y +CONFIG_SOC_SERIES_ITE_IT8XXX2=y CONFIG_SOC_IT8XXX2=y CONFIG_SOC_IT82202_AX=y CONFIG_BOARD_IT82XX2_EVB=y diff --git a/boards/riscv/it8xxx2_evb/it8xxx2_evb_defconfig b/boards/riscv/it8xxx2_evb/it8xxx2_evb_defconfig index 21967527f8e..38a44d6f8f3 100644 --- a/boards/riscv/it8xxx2_evb/it8xxx2_evb_defconfig +++ b/boards/riscv/it8xxx2_evb/it8xxx2_evb_defconfig @@ -1,7 +1,7 @@ # Copyright (c) 2020 ITE Corporation. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV32_IT8XXX2=y +CONFIG_SOC_SERIES_ITE_IT8XXX2=y CONFIG_SOC_IT8XXX2=y CONFIG_BOARD_IT8XXX2_EVB=y CONFIG_BOOT_DELAY=1 diff --git a/soc/riscv/riscv-ite/CMakeLists.txt b/soc/riscv/ite_ec/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-ite/CMakeLists.txt rename to soc/riscv/ite_ec/CMakeLists.txt diff --git a/soc/riscv/ite_ec/Kconfig b/soc/riscv/ite_ec/Kconfig new file mode 100644 index 00000000000..54628029a4e --- /dev/null +++ b/soc/riscv/ite_ec/Kconfig @@ -0,0 +1,17 @@ +# Copyright (c) 2020 ITE Corporation. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FAMILY_ITE_EC + bool + help + ITE Embedded Controller SoC family + +if SOC_FAMILY_ITE_EC + +config SOC_FAMILY + string + default "ite_ec" + +source "soc/riscv/ite_ec/*/Kconfig.soc" + +endif # SOC_FAMILY_ITE_EC diff --git a/soc/riscv/riscv-ite/Kconfig.defconfig b/soc/riscv/ite_ec/Kconfig.defconfig similarity index 63% rename from soc/riscv/riscv-ite/Kconfig.defconfig rename to soc/riscv/ite_ec/Kconfig.defconfig index ae18beac098..8994f47abd9 100644 --- a/soc/riscv/riscv-ite/Kconfig.defconfig +++ b/soc/riscv/ite_ec/Kconfig.defconfig @@ -1,4 +1,4 @@ # Copyright (c) 2020 ITE Corporation. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 -source "soc/riscv/riscv-ite/*/Kconfig.defconfig.series" +source "soc/riscv/ite_ec/*/Kconfig.defconfig.series" diff --git a/soc/riscv/riscv-ite/Kconfig.soc b/soc/riscv/ite_ec/Kconfig.soc similarity index 68% rename from soc/riscv/riscv-ite/Kconfig.soc rename to soc/riscv/ite_ec/Kconfig.soc index 925edb1543c..13f951c0466 100644 --- a/soc/riscv/riscv-ite/Kconfig.soc +++ b/soc/riscv/ite_ec/Kconfig.soc @@ -1,4 +1,4 @@ # Copyright (c) 2020 ITE Corporation. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 -source "soc/riscv/riscv-ite/*/Kconfig.series" +source "soc/riscv/ite_ec/*/Kconfig.series" diff --git a/soc/riscv/riscv-ite/common/CMakeLists.txt b/soc/riscv/ite_ec/common/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-ite/common/CMakeLists.txt rename to soc/riscv/ite_ec/common/CMakeLists.txt diff --git a/soc/riscv/riscv-ite/common/check_regs.c b/soc/riscv/ite_ec/common/check_regs.c similarity index 100% rename from soc/riscv/riscv-ite/common/check_regs.c rename to soc/riscv/ite_ec/common/check_regs.c diff --git a/soc/riscv/riscv-ite/common/chip_chipregs.h b/soc/riscv/ite_ec/common/chip_chipregs.h similarity index 100% rename from soc/riscv/riscv-ite/common/chip_chipregs.h rename to soc/riscv/ite_ec/common/chip_chipregs.h diff --git a/soc/riscv/riscv-ite/common/pinctrl_soc.h b/soc/riscv/ite_ec/common/pinctrl_soc.h similarity index 100% rename from soc/riscv/riscv-ite/common/pinctrl_soc.h rename to soc/riscv/ite_ec/common/pinctrl_soc.h diff --git a/soc/riscv/riscv-ite/common/policy.c b/soc/riscv/ite_ec/common/policy.c similarity index 100% rename from soc/riscv/riscv-ite/common/policy.c rename to soc/riscv/ite_ec/common/policy.c diff --git a/soc/riscv/riscv-ite/common/power.c b/soc/riscv/ite_ec/common/power.c similarity index 100% rename from soc/riscv/riscv-ite/common/power.c rename to soc/riscv/ite_ec/common/power.c diff --git a/soc/riscv/riscv-ite/common/soc_common.h b/soc/riscv/ite_ec/common/soc_common.h similarity index 100% rename from soc/riscv/riscv-ite/common/soc_common.h rename to soc/riscv/ite_ec/common/soc_common.h diff --git a/soc/riscv/riscv-ite/common/soc_common_irq.c b/soc/riscv/ite_ec/common/soc_common_irq.c similarity index 100% rename from soc/riscv/riscv-ite/common/soc_common_irq.c rename to soc/riscv/ite_ec/common/soc_common_irq.c diff --git a/soc/riscv/riscv-ite/common/soc_dt.h b/soc/riscv/ite_ec/common/soc_dt.h similarity index 100% rename from soc/riscv/riscv-ite/common/soc_dt.h rename to soc/riscv/ite_ec/common/soc_dt.h diff --git a/soc/riscv/riscv-ite/common/soc_espi.h b/soc/riscv/ite_ec/common/soc_espi.h similarity index 100% rename from soc/riscv/riscv-ite/common/soc_espi.h rename to soc/riscv/ite_ec/common/soc_espi.h diff --git a/soc/riscv/riscv-ite/common/soc_irq.S b/soc/riscv/ite_ec/common/soc_irq.S similarity index 100% rename from soc/riscv/riscv-ite/common/soc_irq.S rename to soc/riscv/ite_ec/common/soc_irq.S diff --git a/soc/riscv/riscv-ite/common/vector.S b/soc/riscv/ite_ec/common/vector.S similarity index 100% rename from soc/riscv/riscv-ite/common/vector.S rename to soc/riscv/ite_ec/common/vector.S diff --git a/soc/riscv/riscv-ite/it8xxx2/CMakeLists.txt b/soc/riscv/ite_ec/it8xxx2/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/CMakeLists.txt rename to soc/riscv/ite_ec/it8xxx2/CMakeLists.txt diff --git a/soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it81202bx b/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it81202bx similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it81202bx rename to soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it81202bx diff --git a/soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it81202cx b/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it81202cx similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it81202cx rename to soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it81202cx diff --git a/soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it81302bx b/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it81302bx similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it81302bx rename to soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it81302bx diff --git a/soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it81302cx b/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it81302cx similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it81302cx rename to soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it81302cx diff --git a/soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it82002aw b/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it82002aw similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it82002aw rename to soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it82002aw diff --git a/soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it82202ax b/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it82202ax similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it82202ax rename to soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it82202ax diff --git a/soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it82302ax b/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it82302ax similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it82302ax rename to soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it82302ax diff --git a/soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.series b/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.series similarity index 87% rename from soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.series rename to soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.series index 4e6b7c18cca..7c5bc0ee897 100644 --- a/soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.series +++ b/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.series @@ -1,7 +1,7 @@ # Copyright (c) 2020 ITE Corporation. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 -if SOC_SERIES_RISCV32_IT8XXX2 +if SOC_SERIES_ITE_IT8XXX2 config SOC_SERIES default "it8xxx2" @@ -57,6 +57,6 @@ config GEN_SW_ISR_TABLE config RISCV_SOC_INTERRUPT_INIT default y -source "soc/riscv/riscv-ite/it8xxx2/Kconfig.defconfig.it8*" +source "soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.it8*" -endif # SOC_SERIES_RISCV32_IT8XXX2 +endif # SOC_SERIES_ITE_IT8XXX2 diff --git a/soc/riscv/riscv-ite/it8xxx2/Kconfig.series b/soc/riscv/ite_ec/it8xxx2/Kconfig.series similarity index 86% rename from soc/riscv/riscv-ite/it8xxx2/Kconfig.series rename to soc/riscv/ite_ec/it8xxx2/Kconfig.series index ebed0fcd120..265bf855f12 100644 --- a/soc/riscv/riscv-ite/it8xxx2/Kconfig.series +++ b/soc/riscv/ite_ec/it8xxx2/Kconfig.series @@ -1,13 +1,13 @@ # Copyright (c) 2020 ITE Corporation. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 -config SOC_SERIES_RISCV32_IT8XXX2 +config SOC_SERIES_ITE_IT8XXX2 bool "ITE IT8XXX2 implementation" #depends on RISCV # RV32IAFC is an uncommon configuration which is not supported by # default in most toolchains, causing link-time errors. select CPU_HAS_FPU if "$(ZEPHYR_TOOLCHAIN_VARIANT)" != "zephyr" || RISCV_ISA_EXT_M - select SOC_FAMILY_RISCV_ITE + select SOC_FAMILY_ITE_EC select HAS_PM help Enable support for ITE IT8XXX2 diff --git a/soc/riscv/riscv-ite/it8xxx2/Kconfig.soc b/soc/riscv/ite_ec/it8xxx2/Kconfig.soc similarity index 99% rename from soc/riscv/riscv-ite/it8xxx2/Kconfig.soc rename to soc/riscv/ite_ec/it8xxx2/Kconfig.soc index 38525449f89..800a2a9dafd 100644 --- a/soc/riscv/riscv-ite/it8xxx2/Kconfig.soc +++ b/soc/riscv/ite_ec/it8xxx2/Kconfig.soc @@ -3,7 +3,7 @@ choice prompt "ITE IT8XXX2 system implementation" -depends on SOC_SERIES_RISCV32_IT8XXX2 +depends on SOC_SERIES_ITE_IT8XXX2 config SOC_IT8XXX2 bool "ITE IT8XXX2 system implementation" diff --git a/soc/riscv/riscv-ite/it8xxx2/__arithmetic.S b/soc/riscv/ite_ec/it8xxx2/__arithmetic.S similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/__arithmetic.S rename to soc/riscv/ite_ec/it8xxx2/__arithmetic.S diff --git a/soc/riscv/riscv-ite/it8xxx2/ilm.c b/soc/riscv/ite_ec/it8xxx2/ilm.c similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/ilm.c rename to soc/riscv/ite_ec/it8xxx2/ilm.c diff --git a/soc/riscv/riscv-ite/it8xxx2/ilm.h b/soc/riscv/ite_ec/it8xxx2/ilm.h similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/ilm.h rename to soc/riscv/ite_ec/it8xxx2/ilm.h diff --git a/soc/riscv/riscv-ite/it8xxx2/linker.ld b/soc/riscv/ite_ec/it8xxx2/linker.ld similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/linker.ld rename to soc/riscv/ite_ec/it8xxx2/linker.ld diff --git a/soc/riscv/riscv-ite/it8xxx2/soc.c b/soc/riscv/ite_ec/it8xxx2/soc.c similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/soc.c rename to soc/riscv/ite_ec/it8xxx2/soc.c diff --git a/soc/riscv/riscv-ite/it8xxx2/soc.h b/soc/riscv/ite_ec/it8xxx2/soc.h similarity index 100% rename from soc/riscv/riscv-ite/it8xxx2/soc.h rename to soc/riscv/ite_ec/it8xxx2/soc.h diff --git a/soc/riscv/riscv-ite/Kconfig b/soc/riscv/riscv-ite/Kconfig deleted file mode 100644 index f25c53d1ffb..00000000000 --- a/soc/riscv/riscv-ite/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2020 ITE Corporation. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -config SOC_FAMILY_RISCV_ITE - bool - help - omit prompt to signify a "hidden" option - -config SOC_FAMILY - string - default "riscv-ite" - depends on SOC_FAMILY_RISCV_ITE - -source "soc/riscv/riscv-ite/*/Kconfig.soc" diff --git a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/CMakeLists.txt b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/CMakeLists.txt index bf01055ffc3..1079605a2b4 100644 --- a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/CMakeLists.txt +++ b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/CMakeLists.txt @@ -13,8 +13,8 @@ target_include_directories(app PRIVATE zephyr_include_directories( include - ${ZEPHYR_BASE}/soc/riscv/riscv-ite/common - ${ZEPHYR_BASE}/soc/riscv/riscv-ite/it8xxx2 + ${ZEPHYR_BASE}/soc/riscv/ite_ec/common + ${ZEPHYR_BASE}/soc/riscv/ite_ec/it8xxx2 ) target_sources(app diff --git a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/chip_chipregs.h b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/chip_chipregs.h index 3372a845aa9..d3c1f7c827e 100644 --- a/tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/chip_chipregs.h +++ b/tests/drivers/gpio/gpio_ite_it8xxx2_v2/include/chip_chipregs.h @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include <../soc/riscv/riscv-ite/common/chip_chipregs.h> +#include <../soc/riscv/ite_ec/common/chip_chipregs.h> /* * Macros for emulated hardware registers access. From d64f09a6a52abeeef13f5b7dd3cd90eb2dcfea2d Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 15:40:52 +0100 Subject: [PATCH 1193/1623] [nrf fromtree] soc: riscv: s/litex-vexriscv/litex_vexriscv To be consistent with other SoCs in the same folder. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 7a44806a53e74b7720382298afcd502dd5912782) --- soc/riscv/{litex-vexriscv => litex_vexriscv}/CMakeLists.txt | 0 soc/riscv/{litex-vexriscv => litex_vexriscv}/Kconfig.defconfig | 2 +- soc/riscv/{litex-vexriscv => litex_vexriscv}/Kconfig.soc | 0 soc/riscv/{litex-vexriscv => litex_vexriscv}/soc.h | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename soc/riscv/{litex-vexriscv => litex_vexriscv}/CMakeLists.txt (100%) rename soc/riscv/{litex-vexriscv => litex_vexriscv}/Kconfig.defconfig (92%) rename soc/riscv/{litex-vexriscv => litex_vexriscv}/Kconfig.soc (100%) rename soc/riscv/{litex-vexriscv => litex_vexriscv}/soc.h (100%) diff --git a/soc/riscv/litex-vexriscv/CMakeLists.txt b/soc/riscv/litex_vexriscv/CMakeLists.txt similarity index 100% rename from soc/riscv/litex-vexriscv/CMakeLists.txt rename to soc/riscv/litex_vexriscv/CMakeLists.txt diff --git a/soc/riscv/litex-vexriscv/Kconfig.defconfig b/soc/riscv/litex_vexriscv/Kconfig.defconfig similarity index 92% rename from soc/riscv/litex-vexriscv/Kconfig.defconfig rename to soc/riscv/litex_vexriscv/Kconfig.defconfig index 9447948b567..3efdf200ee7 100644 --- a/soc/riscv/litex-vexriscv/Kconfig.defconfig +++ b/soc/riscv/litex_vexriscv/Kconfig.defconfig @@ -4,7 +4,7 @@ if SOC_RISCV32_LITEX_VEXRISCV config SOC - default "litex-vexriscv" + default "litex_vexriscv" config SYS_CLOCK_HW_CYCLES_PER_SEC default 100000000 diff --git a/soc/riscv/litex-vexriscv/Kconfig.soc b/soc/riscv/litex_vexriscv/Kconfig.soc similarity index 100% rename from soc/riscv/litex-vexriscv/Kconfig.soc rename to soc/riscv/litex_vexriscv/Kconfig.soc diff --git a/soc/riscv/litex-vexriscv/soc.h b/soc/riscv/litex_vexriscv/soc.h similarity index 100% rename from soc/riscv/litex-vexriscv/soc.h rename to soc/riscv/litex_vexriscv/soc.h From a6b1be1a2db484ed1aaf8f4378653e76c71ee6a6 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 15:50:51 +0100 Subject: [PATCH 1194/1623] [nrf fromtree] soc: riscv: neorv32: reorganize SoC folder Move out of riscv-privileged and convert to a standalone SoC. Note that the family/series structure has been dropped in favor of a single SoC (what NEORV32 seems to be). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit b7b19b8b05d23406358d721f325715fccb39f330) --- boards/riscv/neorv32/Kconfig.board | 2 +- boards/riscv/neorv32/neorv32_defconfig | 2 +- .../neorv32/CMakeLists.txt | 0 .../Kconfig.defconfig} | 6 ++-- .../Kconfig.series => neorv32/Kconfig.soc} | 27 +++++++++++++++- .../{riscv-privileged => }/neorv32/linker.ld | 0 .../{riscv-privileged => }/neorv32/reset.S | 0 .../{riscv-privileged => }/neorv32/soc.c | 0 .../{riscv-privileged => }/neorv32/soc.h | 0 .../{riscv-privileged => }/neorv32/soc_irq.S | 0 .../riscv-privileged/neorv32/Kconfig.soc | 32 ------------------- 11 files changed, 31 insertions(+), 38 deletions(-) rename soc/riscv/{riscv-privileged => }/neorv32/CMakeLists.txt (100%) rename soc/riscv/{riscv-privileged/neorv32/Kconfig.defconfig.series => neorv32/Kconfig.defconfig} (88%) rename soc/riscv/{riscv-privileged/neorv32/Kconfig.series => neorv32/Kconfig.soc} (56%) rename soc/riscv/{riscv-privileged => }/neorv32/linker.ld (100%) rename soc/riscv/{riscv-privileged => }/neorv32/reset.S (100%) rename soc/riscv/{riscv-privileged => }/neorv32/soc.c (100%) rename soc/riscv/{riscv-privileged => }/neorv32/soc.h (100%) rename soc/riscv/{riscv-privileged => }/neorv32/soc_irq.S (100%) delete mode 100644 soc/riscv/riscv-privileged/neorv32/Kconfig.soc diff --git a/boards/riscv/neorv32/Kconfig.board b/boards/riscv/neorv32/Kconfig.board index eee37f4a8c3..6d85ebb2e40 100644 --- a/boards/riscv/neorv32/Kconfig.board +++ b/boards/riscv/neorv32/Kconfig.board @@ -3,4 +3,4 @@ config BOARD_NEORV32 bool "NEORV32 Processor (SoC)" - depends on SOC_SERIES_NEORV32 + depends on SOC_NEORV32 diff --git a/boards/riscv/neorv32/neorv32_defconfig b/boards/riscv/neorv32/neorv32_defconfig index 17e9b8038ce..7dc8a74ffff 100644 --- a/boards/riscv/neorv32/neorv32_defconfig +++ b/boards/riscv/neorv32/neorv32_defconfig @@ -1,7 +1,7 @@ # Copyright (c) 2021 Henrik Brix Andersen # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_NEORV32=y +CONFIG_SOC_NEORV32=y CONFIG_SOC_NEORV32_ISA_C=y CONFIG_BOARD_NEORV32=y CONFIG_SERIAL=y diff --git a/soc/riscv/riscv-privileged/neorv32/CMakeLists.txt b/soc/riscv/neorv32/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/neorv32/CMakeLists.txt rename to soc/riscv/neorv32/CMakeLists.txt diff --git a/soc/riscv/riscv-privileged/neorv32/Kconfig.defconfig.series b/soc/riscv/neorv32/Kconfig.defconfig similarity index 88% rename from soc/riscv/riscv-privileged/neorv32/Kconfig.defconfig.series rename to soc/riscv/neorv32/Kconfig.defconfig index 11bd7ef7d33..86aed551f5d 100644 --- a/soc/riscv/riscv-privileged/neorv32/Kconfig.defconfig.series +++ b/soc/riscv/neorv32/Kconfig.defconfig @@ -1,9 +1,9 @@ # Copyright (c) 2021 Henrik Brix Andersen # SPDX-License-Identifier: Apache-2.0 -if SOC_SERIES_NEORV32 +if SOC_NEORV32 -config SOC_SERIES +config SOC default "neorv32" config SYS_CLOCK_HW_CYCLES_PER_SEC @@ -29,4 +29,4 @@ config ENTROPY_INIT_PRIORITY default 55 depends on ENTROPY_GENERATOR -endif # SOC_SERIES_NEORV32 +endif # SOC_NEORV32 diff --git a/soc/riscv/riscv-privileged/neorv32/Kconfig.series b/soc/riscv/neorv32/Kconfig.soc similarity index 56% rename from soc/riscv/riscv-privileged/neorv32/Kconfig.series rename to soc/riscv/neorv32/Kconfig.soc index 0f8f9ca8fd4..f07bba96574 100644 --- a/soc/riscv/riscv-privileged/neorv32/Kconfig.series +++ b/soc/riscv/neorv32/Kconfig.soc @@ -1,7 +1,7 @@ # Copyright (c) 2021 Henrik Brix Andersen # SPDX-License-Identifier: Apache-2.0 -config SOC_SERIES_NEORV32 +config SOC_NEORV32 bool "NEORV32 Processor" select RISCV select RISCV_ISA_RV32I @@ -10,6 +10,7 @@ config SOC_SERIES_NEORV32 select RISCV_ISA_EXT_ZICSR select RISCV_ISA_EXT_ZIFENCEI select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE help Enable support for the NEORV32 Processor (SoC). @@ -24,3 +25,27 @@ config SOC_SERIES_NEORV32 - E (Embedded, only 16 integer registers) - Zbb (Basic Bit Manipulation) - Zfinx (Floating Point in Integer Registers) + +if SOC_NEORV32 + +config SOC_NEORV32_V1_8_6 + bool "v1.8.6" + # NEORV32 RISC-V ISA A extension implements only LR/SC, not AMO + select ATOMIC_OPERATIONS_C + +config SOC_NEORV32_VERSION + hex + default 0x01080600 if SOC_NEORV32_V1_8_6 + help + The targeted NEORV32 version as BCD-coded number. The format is + identical to that of the NEORV32 Machine implementation ID (mimpid) + register. + +config SOC_NEORV32_ISA_C + bool "RISC-V ISA Extension \"C\"" + select RISCV_ISA_EXT_C + help + Enable this if the NEORV32 CPU implementation supports the RISC-V ISA + "C" extension (Compressed Instructions). + +endif # SOC_NEORV32 diff --git a/soc/riscv/riscv-privileged/neorv32/linker.ld b/soc/riscv/neorv32/linker.ld similarity index 100% rename from soc/riscv/riscv-privileged/neorv32/linker.ld rename to soc/riscv/neorv32/linker.ld diff --git a/soc/riscv/riscv-privileged/neorv32/reset.S b/soc/riscv/neorv32/reset.S similarity index 100% rename from soc/riscv/riscv-privileged/neorv32/reset.S rename to soc/riscv/neorv32/reset.S diff --git a/soc/riscv/riscv-privileged/neorv32/soc.c b/soc/riscv/neorv32/soc.c similarity index 100% rename from soc/riscv/riscv-privileged/neorv32/soc.c rename to soc/riscv/neorv32/soc.c diff --git a/soc/riscv/riscv-privileged/neorv32/soc.h b/soc/riscv/neorv32/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/neorv32/soc.h rename to soc/riscv/neorv32/soc.h diff --git a/soc/riscv/riscv-privileged/neorv32/soc_irq.S b/soc/riscv/neorv32/soc_irq.S similarity index 100% rename from soc/riscv/riscv-privileged/neorv32/soc_irq.S rename to soc/riscv/neorv32/soc_irq.S diff --git a/soc/riscv/riscv-privileged/neorv32/Kconfig.soc b/soc/riscv/riscv-privileged/neorv32/Kconfig.soc deleted file mode 100644 index 93c9da8cc3d..00000000000 --- a/soc/riscv/riscv-privileged/neorv32/Kconfig.soc +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (c) 2021 Henrik Brix Andersen -# SPDX-License-Identifier: Apache-2.0 - -choice - prompt "NEORV32 Version" - depends on SOC_SERIES_NEORV32 - -config SOC_NEORV32_V1_8_6 - bool "v1.8.6" - # NEORV32 RISC-V ISA A extension implements only LR/SC, not AMO - select ATOMIC_OPERATIONS_C - -endchoice - -if SOC_SERIES_NEORV32 - -config SOC_NEORV32_VERSION - hex - default 0x01080600 if SOC_NEORV32_V1_8_6 - help - The targeted NEORV32 version as BCD-coded number. The format is - identical to that of the NEORV32 Machine implementation ID (mimpid) - register. - -config SOC_NEORV32_ISA_C - bool "RISC-V ISA Extension \"C\"" - select RISCV_ISA_EXT_C - help - Enable this if the NEORV32 CPU implementation supports the RISC-V ISA - "C" extension (Compressed Instructions). - -endif # SOC_SERIES_NEORV32 From bea9968589b410489829c758ad5a7309c154800a Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 15:57:37 +0100 Subject: [PATCH 1195/1623] [nrf fromtree] soc: riscv: virt: reorganize SoC folder Move out of riscv-privileged, and convert to single SoC (no family/series). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 7da6342dff4a3ff62de02e15a8c9959bef7d46a1) --- boards/riscv/qemu_riscv32/qemu_riscv32_defconfig | 1 - boards/riscv/qemu_riscv32/qemu_riscv32_smp_defconfig | 1 - boards/riscv/qemu_riscv32e/qemu_riscv32e_defconfig | 1 - boards/riscv/qemu_riscv64/qemu_riscv64_defconfig | 1 - boards/riscv/qemu_riscv64/qemu_riscv64_smp_defconfig | 1 - soc/riscv/riscv-privileged/virt/Kconfig.series | 7 ------- soc/riscv/{riscv-privileged => }/virt/CMakeLists.txt | 0 .../Kconfig.defconfig.series => virt/Kconfig.defconfig} | 4 ++-- soc/riscv/{riscv-privileged => }/virt/Kconfig.soc | 9 +++------ soc/riscv/{riscv-privileged => }/virt/soc.c | 0 soc/riscv/{riscv-privileged => }/virt/soc.h | 0 11 files changed, 5 insertions(+), 20 deletions(-) delete mode 100644 soc/riscv/riscv-privileged/virt/Kconfig.series rename soc/riscv/{riscv-privileged => }/virt/CMakeLists.txt (100%) rename soc/riscv/{riscv-privileged/virt/Kconfig.defconfig.series => virt/Kconfig.defconfig} (91%) rename soc/riscv/{riscv-privileged => }/virt/Kconfig.soc (75%) rename soc/riscv/{riscv-privileged => }/virt/soc.c (100%) rename soc/riscv/{riscv-privileged => }/virt/soc.h (100%) diff --git a/boards/riscv/qemu_riscv32/qemu_riscv32_defconfig b/boards/riscv/qemu_riscv32/qemu_riscv32_defconfig index f50d82dcb76..946e679a6e8 100644 --- a/boards/riscv/qemu_riscv32/qemu_riscv32_defconfig +++ b/boards/riscv/qemu_riscv32/qemu_riscv32_defconfig @@ -1,6 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV_VIRT=y CONFIG_SOC_RISCV_VIRT=y CONFIG_BOARD_QEMU_RISCV32=y CONFIG_CONSOLE=y diff --git a/boards/riscv/qemu_riscv32/qemu_riscv32_smp_defconfig b/boards/riscv/qemu_riscv32/qemu_riscv32_smp_defconfig index eef7d03e356..90f87ef6b98 100644 --- a/boards/riscv/qemu_riscv32/qemu_riscv32_smp_defconfig +++ b/boards/riscv/qemu_riscv32/qemu_riscv32_smp_defconfig @@ -1,6 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV_VIRT=y CONFIG_SOC_RISCV_VIRT=y CONFIG_BOARD_QEMU_RISCV32_SMP=y CONFIG_CONSOLE=y diff --git a/boards/riscv/qemu_riscv32e/qemu_riscv32e_defconfig b/boards/riscv/qemu_riscv32e/qemu_riscv32e_defconfig index ef4d6273cfb..1f1c46acb10 100644 --- a/boards/riscv/qemu_riscv32e/qemu_riscv32e_defconfig +++ b/boards/riscv/qemu_riscv32e/qemu_riscv32e_defconfig @@ -1,6 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV_VIRT=y CONFIG_SOC_RISCV_VIRT=y CONFIG_BOARD_QEMU_RISCV32E=y CONFIG_CONSOLE=y diff --git a/boards/riscv/qemu_riscv64/qemu_riscv64_defconfig b/boards/riscv/qemu_riscv64/qemu_riscv64_defconfig index 6f51da3c592..6bfc46ac907 100644 --- a/boards/riscv/qemu_riscv64/qemu_riscv64_defconfig +++ b/boards/riscv/qemu_riscv64/qemu_riscv64_defconfig @@ -1,6 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV_VIRT=y CONFIG_SOC_RISCV_VIRT=y CONFIG_BOARD_QEMU_RISCV64=y CONFIG_PRIVILEGED_STACK_SIZE=2048 diff --git a/boards/riscv/qemu_riscv64/qemu_riscv64_smp_defconfig b/boards/riscv/qemu_riscv64/qemu_riscv64_smp_defconfig index 78b5b74de9a..265d84a1ded 100644 --- a/boards/riscv/qemu_riscv64/qemu_riscv64_smp_defconfig +++ b/boards/riscv/qemu_riscv64/qemu_riscv64_smp_defconfig @@ -1,6 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV_VIRT=y CONFIG_SOC_RISCV_VIRT=y CONFIG_BOARD_QEMU_RISCV64_SMP=y CONFIG_PRIVILEGED_STACK_SIZE=2048 diff --git a/soc/riscv/riscv-privileged/virt/Kconfig.series b/soc/riscv/riscv-privileged/virt/Kconfig.series deleted file mode 100644 index 44ec681a308..00000000000 --- a/soc/riscv/riscv-privileged/virt/Kconfig.series +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2020 Cobham Gaisler AB -# SPDX-License-Identifier: Apache-2.0 - -config SOC_SERIES_RISCV_VIRT - bool "QEMU RISC-V VirtIO Board" - select RISCV - select RISCV_PRIVILEGED diff --git a/soc/riscv/riscv-privileged/virt/CMakeLists.txt b/soc/riscv/virt/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/virt/CMakeLists.txt rename to soc/riscv/virt/CMakeLists.txt diff --git a/soc/riscv/riscv-privileged/virt/Kconfig.defconfig.series b/soc/riscv/virt/Kconfig.defconfig similarity index 91% rename from soc/riscv/riscv-privileged/virt/Kconfig.defconfig.series rename to soc/riscv/virt/Kconfig.defconfig index 231d4519d67..9773586e922 100644 --- a/soc/riscv/riscv-privileged/virt/Kconfig.defconfig.series +++ b/soc/riscv/virt/Kconfig.defconfig @@ -1,9 +1,9 @@ # Copyright (c) 2020 Cobham Gaisler AB # SPDX-License-Identifier: Apache-2.0 -if SOC_SERIES_RISCV_VIRT +if SOC_RISCV_VIRT -config SOC_SERIES +config SOC default "virt" config SYS_CLOCK_HW_CYCLES_PER_SEC diff --git a/soc/riscv/riscv-privileged/virt/Kconfig.soc b/soc/riscv/virt/Kconfig.soc similarity index 75% rename from soc/riscv/riscv-privileged/virt/Kconfig.soc rename to soc/riscv/virt/Kconfig.soc index 35a2853eb50..fb615005b0a 100644 --- a/soc/riscv/riscv-privileged/virt/Kconfig.soc +++ b/soc/riscv/virt/Kconfig.soc @@ -1,10 +1,6 @@ # Copyright (c) 2020 Cobham Gaisler AB # SPDX-License-Identifier: Apache-2.0 -choice - prompt "QEMU RISC-V VirtIO Board" - depends on SOC_SERIES_RISCV_VIRT - config SOC_RISCV_VIRT bool "QEMU RISC-V VirtIO Board" select ATOMIC_OPERATIONS_BUILTIN @@ -12,5 +8,6 @@ config SOC_RISCV_VIRT select RISCV_ISA_EXT_M select RISCV_ISA_EXT_A select RISCV_ISA_EXT_C - -endchoice + select RISCV + select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE diff --git a/soc/riscv/riscv-privileged/virt/soc.c b/soc/riscv/virt/soc.c similarity index 100% rename from soc/riscv/riscv-privileged/virt/soc.c rename to soc/riscv/virt/soc.c diff --git a/soc/riscv/riscv-privileged/virt/soc.h b/soc/riscv/virt/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/virt/soc.h rename to soc/riscv/virt/soc.h From c9cf4960df274f909610f607015e6404961d71ee Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 16:04:26 +0100 Subject: [PATCH 1196/1623] [nrf fromtree] soc: riscv: efinix-sapphire: reorganize SoC folder Move things out from riscv-privileged, and convert to single SoC. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 4c4beabecc3cb4eb80aae32e590a2fe21c84bd6a) --- boards/riscv/titanium_ti60_f225/Kconfig.board | 2 +- .../titanium_ti60_f225/titanium_ti60_f225_defconfig | 2 +- .../CMakeLists.txt | 0 .../Kconfig.defconfig} | 8 ++++---- .../efinix-sapphire => efinix_sapphire}/Kconfig.soc | 11 ++++------- .../efinix-sapphire => efinix_sapphire}/soc.h | 0 .../riscv-privileged/efinix-sapphire/Kconfig.series | 9 --------- 7 files changed, 10 insertions(+), 22 deletions(-) rename soc/riscv/{riscv-privileged/efinix-sapphire => efinix_sapphire}/CMakeLists.txt (100%) rename soc/riscv/{riscv-privileged/efinix-sapphire/Kconfig.defconfig.series => efinix_sapphire/Kconfig.defconfig} (74%) rename soc/riscv/{riscv-privileged/efinix-sapphire => efinix_sapphire}/Kconfig.soc (72%) rename soc/riscv/{riscv-privileged/efinix-sapphire => efinix_sapphire}/soc.h (100%) delete mode 100644 soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.series diff --git a/boards/riscv/titanium_ti60_f225/Kconfig.board b/boards/riscv/titanium_ti60_f225/Kconfig.board index d6ed41ffc79..bac70816b20 100644 --- a/boards/riscv/titanium_ti60_f225/Kconfig.board +++ b/boards/riscv/titanium_ti60_f225/Kconfig.board @@ -3,4 +3,4 @@ config BOARD_TITANIUM_TI60_F225 bool "Board with Efinix Sapphire riscv SoC" - depends on SOC_SERIES_EFINIX_SAPPHIRE + depends on SOC_EFINIX_SAPPHIRE diff --git a/boards/riscv/titanium_ti60_f225/titanium_ti60_f225_defconfig b/boards/riscv/titanium_ti60_f225/titanium_ti60_f225_defconfig index 096980b864e..0608a8e8953 100644 --- a/boards/riscv/titanium_ti60_f225/titanium_ti60_f225_defconfig +++ b/boards/riscv/titanium_ti60_f225/titanium_ti60_f225_defconfig @@ -1,7 +1,7 @@ # Copyright (c) 2023 Efinix Inc. # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_EFINIX_SAPPHIRE=y +CONFIG_SOC_EFINIX_SAPPHIRE=y CONFIG_BOARD_TITANIUM_TI60_F225=y CONFIG_CONSOLE=y CONFIG_SERIAL=y diff --git a/soc/riscv/riscv-privileged/efinix-sapphire/CMakeLists.txt b/soc/riscv/efinix_sapphire/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/efinix-sapphire/CMakeLists.txt rename to soc/riscv/efinix_sapphire/CMakeLists.txt diff --git a/soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.defconfig.series b/soc/riscv/efinix_sapphire/Kconfig.defconfig similarity index 74% rename from soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.defconfig.series rename to soc/riscv/efinix_sapphire/Kconfig.defconfig index 233428931a3..5424bca7baf 100644 --- a/soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.defconfig.series +++ b/soc/riscv/efinix_sapphire/Kconfig.defconfig @@ -1,10 +1,10 @@ # Copyright (c) 2023 Efinix Inc. # SPDX-License-Identifier: Apache-2.0 -if SOC_SERIES_EFINIX_SAPPHIRE +if SOC_EFINIX_SAPPHIRE -config SOC_SERIES - default "efinix-sapphire" +config SOC + default "efinix_sapphire" config SYS_CLOCK_HW_CYCLES_PER_SEC default 100000000 @@ -27,4 +27,4 @@ config NUM_IRQS config 2ND_LVL_INTR_00_OFFSET default 11 -endif # SOC_SERIES_EFINIX_SAPPHIRE +endif # SOC_EFINIX_SAPPHIRE diff --git a/soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.soc b/soc/riscv/efinix_sapphire/Kconfig.soc similarity index 72% rename from soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.soc rename to soc/riscv/efinix_sapphire/Kconfig.soc index dba8491b8bd..2cc5f3ba361 100644 --- a/soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.soc +++ b/soc/riscv/efinix_sapphire/Kconfig.soc @@ -1,11 +1,7 @@ # Copyright (c) 2023 Efinix Inc. # SPDX-License-Identifier: Apache-2.0 -choice - prompt "Efinix SoC selection" - depends on SOC_SERIES_EFINIX_SAPPHIRE - -config SOC_RISCV32_EFINIX_SAPPHIRE +config SOC_EFINIX_SAPPHIRE bool "Efinix Sapphire VexRiscv system implementation" select ATOMIC_OPERATIONS_BUILTIN select INCLUDE_RESET_VECTOR @@ -14,5 +10,6 @@ config SOC_RISCV32_EFINIX_SAPPHIRE select RISCV_ISA_EXT_A select RISCV_ISA_EXT_ZICSR select RISCV_ISA_EXT_ZIFENCEI - -endchoice + select RISCV + select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE diff --git a/soc/riscv/riscv-privileged/efinix-sapphire/soc.h b/soc/riscv/efinix_sapphire/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/efinix-sapphire/soc.h rename to soc/riscv/efinix_sapphire/soc.h diff --git a/soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.series b/soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.series deleted file mode 100644 index 421d81a7e33..00000000000 --- a/soc/riscv/riscv-privileged/efinix-sapphire/Kconfig.series +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2023 Efinix Inc. -# SPDX-License-Identifier: Apache-2.0 - -config SOC_SERIES_EFINIX_SAPPHIRE - bool "Efinix Sapphire SOC implementation" - select RISCV - select RISCV_PRIVILEGED - help - Enable support for Efinix Sapphire SOC implementation From 448985fca20ff183aab51ad29271056d8091a877 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 16:43:52 +0100 Subject: [PATCH 1197/1623] [nrf fromtree] soc: riscv: miv/mpfs: reorganize SoC folder Merge both series into a new family: microchip_miv [1], moving them out of riscv-privileged. Updated naming to stay closer to what vendor announces on their website. [1]: https://www.microchip.com/en-us/products/fpgas-and-plds/ fpga-and-soc-design-tools/mi-v Signed-off-by: Gerard Marull-Paretas (cherry picked from commit b2b86556a7a381d6f776f1a682ac2b347b20acf9) --- boards/riscv/beaglev_fire/Kconfig.board | 2 +- boards/riscv/beaglev_fire/beaglev_fire_defconfig | 4 ++-- boards/riscv/m2gl025_miv/Kconfig.board | 2 +- boards/riscv/m2gl025_miv/m2gl025_miv_defconfig | 4 ++-- boards/riscv/mpfs_icicle/Kconfig.board | 2 +- boards/riscv/mpfs_icicle/mpfs_icicle_defconfig | 4 ++-- soc/riscv/microchip_miv/CMakeLists.txt | 4 ++++ soc/riscv/microchip_miv/Kconfig | 15 +++++++++++++++ soc/riscv/microchip_miv/Kconfig.defconfig | 4 ++++ soc/riscv/microchip_miv/Kconfig.soc | 4 ++++ .../miv/CMakeLists.txt | 0 .../miv/Kconfig.defconfig.series | 4 ++-- .../miv/Kconfig.series | 4 +++- .../miv/Kconfig.soc | 4 ++-- .../{riscv-privileged => microchip_miv}/miv/soc.h | 0 .../polarfire}/CMakeLists.txt | 0 .../polarfire}/Kconfig.defconfig.series | 6 +++--- .../polarfire}/Kconfig.series | 4 +++- .../mpfs => microchip_miv/polarfire}/Kconfig.soc | 6 +++--- .../mpfs => microchip_miv/polarfire}/soc.h | 0 20 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 soc/riscv/microchip_miv/CMakeLists.txt create mode 100644 soc/riscv/microchip_miv/Kconfig create mode 100644 soc/riscv/microchip_miv/Kconfig.defconfig create mode 100644 soc/riscv/microchip_miv/Kconfig.soc rename soc/riscv/{riscv-privileged => microchip_miv}/miv/CMakeLists.txt (100%) rename soc/riscv/{riscv-privileged => microchip_miv}/miv/Kconfig.defconfig.series (88%) rename soc/riscv/{riscv-privileged => microchip_miv}/miv/Kconfig.series (72%) rename soc/riscv/{riscv-privileged => microchip_miv}/miv/Kconfig.soc (88%) rename soc/riscv/{riscv-privileged => microchip_miv}/miv/soc.h (100%) rename soc/riscv/{riscv-privileged/mpfs => microchip_miv/polarfire}/CMakeLists.txt (100%) rename soc/riscv/{riscv-privileged/mpfs => microchip_miv/polarfire}/Kconfig.defconfig.series (89%) rename soc/riscv/{riscv-privileged/mpfs => microchip_miv/polarfire}/Kconfig.series (71%) rename soc/riscv/{riscv-privileged/mpfs => microchip_miv/polarfire}/Kconfig.soc (89%) rename soc/riscv/{riscv-privileged/mpfs => microchip_miv/polarfire}/soc.h (100%) diff --git a/boards/riscv/beaglev_fire/Kconfig.board b/boards/riscv/beaglev_fire/Kconfig.board index 1984bb05c09..55b59d4ac92 100644 --- a/boards/riscv/beaglev_fire/Kconfig.board +++ b/boards/riscv/beaglev_fire/Kconfig.board @@ -3,7 +3,7 @@ config BOARD_BEAGLEV_FIRE bool "Beagleboard BeagleV-Fire" - depends on SOC_MPFS + depends on SOC_POLARFIRE select 64BIT select SCHED_IPI_SUPPORTED select CPU_HAS_FPU_DOUBLE_PRECISION diff --git a/boards/riscv/beaglev_fire/beaglev_fire_defconfig b/boards/riscv/beaglev_fire/beaglev_fire_defconfig index a60ed8c1691..3b264d6c288 100644 --- a/boards/riscv/beaglev_fire/beaglev_fire_defconfig +++ b/boards/riscv/beaglev_fire/beaglev_fire_defconfig @@ -1,8 +1,8 @@ # Copyright (c) 2023 Microchip Technology Inc # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV64_MIV=y -CONFIG_SOC_MPFS=y +CONFIG_SOC_SERIES_POLARFIRE=y +CONFIG_SOC_POLARFIRE=y CONFIG_MPFS_HAL=n CONFIG_BASE64=y CONFIG_INCLUDE_RESET_VECTOR=y diff --git a/boards/riscv/m2gl025_miv/Kconfig.board b/boards/riscv/m2gl025_miv/Kconfig.board index 51c2f9d8de3..9f81fad406f 100644 --- a/boards/riscv/m2gl025_miv/Kconfig.board +++ b/boards/riscv/m2gl025_miv/Kconfig.board @@ -2,4 +2,4 @@ config BOARD_M2GL025_MIV bool "Microchip M2GL025 IGLOO2 dev board with Mi-V CPU" - depends on SOC_RISCV32_MIV + depends on SOC_MIV diff --git a/boards/riscv/m2gl025_miv/m2gl025_miv_defconfig b/boards/riscv/m2gl025_miv/m2gl025_miv_defconfig index 8c944a10a74..e33765680d5 100644 --- a/boards/riscv/m2gl025_miv/m2gl025_miv_defconfig +++ b/boards/riscv/m2gl025_miv/m2gl025_miv_defconfig @@ -1,7 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV32_MIV=y -CONFIG_SOC_RISCV32_MIV=y +CONFIG_SOC_SERIES_MIV=y +CONFIG_SOC_MIV=y CONFIG_BOARD_M2GL025_MIV=y CONFIG_CONSOLE=y CONFIG_SERIAL=y diff --git a/boards/riscv/mpfs_icicle/Kconfig.board b/boards/riscv/mpfs_icicle/Kconfig.board index 297f4ce4bc7..e772b82d7f5 100644 --- a/boards/riscv/mpfs_icicle/Kconfig.board +++ b/boards/riscv/mpfs_icicle/Kconfig.board @@ -3,7 +3,7 @@ config BOARD_MPFS_ICICLE bool "Microchip PolarFire SoC ICICLE kit" - depends on SOC_MPFS + depends on SOC_POLARFIRE select 64BIT select SCHED_IPI_SUPPORTED select CPU_HAS_FPU_DOUBLE_PRECISION diff --git a/boards/riscv/mpfs_icicle/mpfs_icicle_defconfig b/boards/riscv/mpfs_icicle/mpfs_icicle_defconfig index 5c41649cb3e..00b44f7a6d5 100644 --- a/boards/riscv/mpfs_icicle/mpfs_icicle_defconfig +++ b/boards/riscv/mpfs_icicle/mpfs_icicle_defconfig @@ -1,8 +1,8 @@ # Copyright (c) 2020-2021 Microchip Technology Inc # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV64_MIV=y -CONFIG_SOC_MPFS=y +CONFIG_SOC_SERIES_POLARFIRE=y +CONFIG_SOC_POLARFIRE=y CONFIG_MPFS_HAL=n CONFIG_BASE64=y CONFIG_INCLUDE_RESET_VECTOR=y diff --git a/soc/riscv/microchip_miv/CMakeLists.txt b/soc/riscv/microchip_miv/CMakeLists.txt new file mode 100644 index 00000000000..69b2926358e --- /dev/null +++ b/soc/riscv/microchip_miv/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(${SOC_SERIES}) diff --git a/soc/riscv/microchip_miv/Kconfig b/soc/riscv/microchip_miv/Kconfig new file mode 100644 index 00000000000..46616636aa1 --- /dev/null +++ b/soc/riscv/microchip_miv/Kconfig @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FAMILY_MICROCHIP_MIV + bool + +if SOC_FAMILY_MICROCHIP_MIV + +config SOC_FAMILY + string + default "microchip_miv" + +source "soc/riscv/microchip_miv/*/Kconfig.soc" + +endif # SOC_FAMILY_MICROCHIP_MIV diff --git a/soc/riscv/microchip_miv/Kconfig.defconfig b/soc/riscv/microchip_miv/Kconfig.defconfig new file mode 100644 index 00000000000..2fe508bddba --- /dev/null +++ b/soc/riscv/microchip_miv/Kconfig.defconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/microchip_miv/*/Kconfig.defconfig.series" diff --git a/soc/riscv/microchip_miv/Kconfig.soc b/soc/riscv/microchip_miv/Kconfig.soc new file mode 100644 index 00000000000..8677f1ba448 --- /dev/null +++ b/soc/riscv/microchip_miv/Kconfig.soc @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/microchip_miv/*/Kconfig.series" diff --git a/soc/riscv/riscv-privileged/miv/CMakeLists.txt b/soc/riscv/microchip_miv/miv/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/miv/CMakeLists.txt rename to soc/riscv/microchip_miv/miv/CMakeLists.txt diff --git a/soc/riscv/riscv-privileged/miv/Kconfig.defconfig.series b/soc/riscv/microchip_miv/miv/Kconfig.defconfig.series similarity index 88% rename from soc/riscv/riscv-privileged/miv/Kconfig.defconfig.series rename to soc/riscv/microchip_miv/miv/Kconfig.defconfig.series index 81b224ed397..ef161321a5b 100644 --- a/soc/riscv/riscv-privileged/miv/Kconfig.defconfig.series +++ b/soc/riscv/microchip_miv/miv/Kconfig.defconfig.series @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 -if SOC_SERIES_RISCV32_MIV +if SOC_SERIES_MIV config SOC_SERIES default "miv" @@ -32,4 +32,4 @@ config MAX_IRQ_PER_AGGREGATOR config NUM_IRQS default 42 -endif # SOC_SERIES_RISCV32_MIV +endif # SOC_SERIES_MIV diff --git a/soc/riscv/riscv-privileged/miv/Kconfig.series b/soc/riscv/microchip_miv/miv/Kconfig.series similarity index 72% rename from soc/riscv/riscv-privileged/miv/Kconfig.series rename to soc/riscv/microchip_miv/miv/Kconfig.series index 017de686a94..20430e6d0f9 100644 --- a/soc/riscv/riscv-privileged/miv/Kconfig.series +++ b/soc/riscv/microchip_miv/miv/Kconfig.series @@ -3,9 +3,11 @@ # Copyright (c) 2018 Antmicro # SPDX-License-Identifier: Apache-2.0 -config SOC_SERIES_RISCV32_MIV +config SOC_SERIES_MIV bool "Microchip Mi-V implementation" + select SOC_FAMILY_MICROCHIP_MIV select RISCV select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE help Enable support for Microchip Mi-V diff --git a/soc/riscv/riscv-privileged/miv/Kconfig.soc b/soc/riscv/microchip_miv/miv/Kconfig.soc similarity index 88% rename from soc/riscv/riscv-privileged/miv/Kconfig.soc rename to soc/riscv/microchip_miv/miv/Kconfig.soc index 189abb6879c..0a48c2e0524 100644 --- a/soc/riscv/riscv-privileged/miv/Kconfig.soc +++ b/soc/riscv/microchip_miv/miv/Kconfig.soc @@ -5,9 +5,9 @@ choice prompt "Microchip Mi-V system implementation" - depends on SOC_SERIES_RISCV32_MIV + depends on SOC_SERIES_MIV -config SOC_RISCV32_MIV +config SOC_MIV bool "Microchip Mi-V system implementation" select ATOMIC_OPERATIONS_BUILTIN select INCLUDE_RESET_VECTOR diff --git a/soc/riscv/riscv-privileged/miv/soc.h b/soc/riscv/microchip_miv/miv/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/miv/soc.h rename to soc/riscv/microchip_miv/miv/soc.h diff --git a/soc/riscv/riscv-privileged/mpfs/CMakeLists.txt b/soc/riscv/microchip_miv/polarfire/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/mpfs/CMakeLists.txt rename to soc/riscv/microchip_miv/polarfire/CMakeLists.txt diff --git a/soc/riscv/riscv-privileged/mpfs/Kconfig.defconfig.series b/soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series similarity index 89% rename from soc/riscv/riscv-privileged/mpfs/Kconfig.defconfig.series rename to soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series index fb9f6d2d3af..0e5629927ae 100644 --- a/soc/riscv/riscv-privileged/mpfs/Kconfig.defconfig.series +++ b/soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series @@ -1,10 +1,10 @@ # Copyright (c) 2020-2021 Microchip Technology Inc # SPDX-License-Identifier: Apache-2.0 -if SOC_SERIES_RISCV64_MIV +if SOC_SERIES_POLARFIRE config SOC_SERIES - default "mpfs" + default "polarfire" # MPFS should be configured so that the mtimer clock is 1MHz independent of the CPU clock... @@ -38,4 +38,4 @@ config NUM_IRQS # config NO_OPTIMIZATIONS # default y -endif # SOC_SERIES_RISCV64_MIV +endif # SOC_SERIES_POLARFIRE diff --git a/soc/riscv/riscv-privileged/mpfs/Kconfig.series b/soc/riscv/microchip_miv/polarfire/Kconfig.series similarity index 71% rename from soc/riscv/riscv-privileged/mpfs/Kconfig.series rename to soc/riscv/microchip_miv/polarfire/Kconfig.series index 3b30cd15365..4bbceaee745 100644 --- a/soc/riscv/riscv-privileged/mpfs/Kconfig.series +++ b/soc/riscv/microchip_miv/polarfire/Kconfig.series @@ -3,9 +3,11 @@ # Copyright (c) 2018 Antmicro # SPDX-License-Identifier: Apache-2.0 -config SOC_SERIES_RISCV64_MIV +config SOC_SERIES_POLARFIRE bool "Microchip RV64 implementation" + select SOC_FAMILY_MICROCHIP_MIV select RISCV select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE help Enable support for Microchip RISCV 64bit diff --git a/soc/riscv/riscv-privileged/mpfs/Kconfig.soc b/soc/riscv/microchip_miv/polarfire/Kconfig.soc similarity index 89% rename from soc/riscv/riscv-privileged/mpfs/Kconfig.soc rename to soc/riscv/microchip_miv/polarfire/Kconfig.soc index 7f20dc703c2..101e8b4d029 100644 --- a/soc/riscv/riscv-privileged/mpfs/Kconfig.soc +++ b/soc/riscv/microchip_miv/polarfire/Kconfig.soc @@ -5,9 +5,9 @@ choice prompt "Microchip Polarfire SOC implementation" - depends on SOC_SERIES_RISCV64_MIV + depends on SOC_SERIES_POLARFIRE -config SOC_MPFS +config SOC_POLARFIRE bool "Microchip MPFS system implementation" select ATOMIC_OPERATIONS_BUILTIN select RISCV_GP @@ -25,6 +25,6 @@ config SOC_MPFS endchoice config MPFS_HAL - depends on SOC_MPFS + depends on SOC_POLARFIRE bool "Microchip Polarfire SOC hardware abstracton layer" select HAS_MPFS_HAL diff --git a/soc/riscv/riscv-privileged/mpfs/soc.h b/soc/riscv/microchip_miv/polarfire/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/mpfs/soc.h rename to soc/riscv/microchip_miv/polarfire/soc.h From 36ce51fee3661211976ea2e205a4d85fc5bf2499 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 17:26:25 +0100 Subject: [PATCH 1198/1623] [nrf fromtree] soc: riscv: sifive-freedom: reorganize SoC folder Reorganized as follows: - Created a new SiFive Freedom family - Created 3 new series: E300/E500/E700 - Created Socs within each series (e.g. E340) Also moved out of riscv-privileged folder. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 38a44e683eaa92c642b5aaa59fe3f10a3ac28941) --- boards/riscv/hifive1/Kconfig.board | 2 +- boards/riscv/hifive1/hifive1_defconfig | 4 +- boards/riscv/hifive1_revb/Kconfig.board | 2 +- .../riscv/hifive1_revb/hifive1_revb_defconfig | 4 +- boards/riscv/hifive_unleashed/Kconfig.board | 2 +- .../hifive_unleashed_defconfig | 4 +- boards/riscv/hifive_unmatched/Kconfig.board | 2 +- .../hifive_unmatched_defconfig | 4 +- boards/riscv/qemu_riscv32/Kconfig.board | 2 +- .../qemu_riscv32/qemu_riscv32_xip_defconfig | 4 +- .../sparkfun_red_v_things_plus/Kconfig.board | 2 +- .../sparkfun_red_v_things_plus_defconfig | 4 +- .../sifive-freedom/CMakeLists.txt | 8 ---- .../sifive-freedom/Kconfig.series | 11 ----- .../sifive-freedom/Kconfig.soc | 44 ------------------- soc/riscv/sifive_freedom/CMakeLists.txt | 5 +++ soc/riscv/sifive_freedom/Kconfig | 15 +++++++ soc/riscv/sifive_freedom/Kconfig.defconfig | 4 ++ soc/riscv/sifive_freedom/Kconfig.soc | 4 ++ .../sifive_freedom/common/CMakeLists.txt | 3 ++ .../common}/pinctrl_soc.h | 0 soc/riscv/sifive_freedom/e300/CMakeLists.txt | 5 +++ .../e300/Kconfig.defconfig.e340 | 5 +++ .../e300}/Kconfig.defconfig.series | 9 ++-- soc/riscv/sifive_freedom/e300/Kconfig.series | 13 ++++++ soc/riscv/sifive_freedom/e300/Kconfig.soc | 20 +++++++++ .../e300/clock.c} | 2 +- .../e300/prci.h} | 0 .../e300}/soc.h | 27 ++---------- soc/riscv/sifive_freedom/u500/CMakeLists.txt | 5 +++ .../u500/Kconfig.defconfig.series | 38 ++++++++++++++++ .../u500/Kconfig.defconfig.u540 | 5 +++ soc/riscv/sifive_freedom/u500/Kconfig.series | 13 ++++++ soc/riscv/sifive_freedom/u500/Kconfig.soc | 22 ++++++++++ .../u500/clock.c} | 2 +- .../u500/prci.h} | 0 soc/riscv/sifive_freedom/u500/soc.h | 32 ++++++++++++++ soc/riscv/sifive_freedom/u700/CMakeLists.txt | 5 +++ .../u700/Kconfig.defconfig.series | 38 ++++++++++++++++ .../u700/Kconfig.defconfig.u740 | 5 +++ soc/riscv/sifive_freedom/u700/Kconfig.series | 13 ++++++ soc/riscv/sifive_freedom/u700/Kconfig.soc | 22 ++++++++++ .../u700/clock.c} | 2 +- .../u700/prci.h} | 0 soc/riscv/sifive_freedom/u700/soc.h | 26 +++++++++++ 45 files changed, 328 insertions(+), 111 deletions(-) delete mode 100644 soc/riscv/riscv-privileged/sifive-freedom/CMakeLists.txt delete mode 100644 soc/riscv/riscv-privileged/sifive-freedom/Kconfig.series delete mode 100644 soc/riscv/riscv-privileged/sifive-freedom/Kconfig.soc create mode 100644 soc/riscv/sifive_freedom/CMakeLists.txt create mode 100644 soc/riscv/sifive_freedom/Kconfig create mode 100644 soc/riscv/sifive_freedom/Kconfig.defconfig create mode 100644 soc/riscv/sifive_freedom/Kconfig.soc create mode 100644 soc/riscv/sifive_freedom/common/CMakeLists.txt rename soc/riscv/{riscv-privileged/sifive-freedom => sifive_freedom/common}/pinctrl_soc.h (100%) create mode 100644 soc/riscv/sifive_freedom/e300/CMakeLists.txt create mode 100644 soc/riscv/sifive_freedom/e300/Kconfig.defconfig.e340 rename soc/riscv/{riscv-privileged/sifive-freedom => sifive_freedom/e300}/Kconfig.defconfig.series (65%) create mode 100644 soc/riscv/sifive_freedom/e300/Kconfig.series create mode 100644 soc/riscv/sifive_freedom/e300/Kconfig.soc rename soc/riscv/{riscv-privileged/sifive-freedom/fe310_clock.c => sifive_freedom/e300/clock.c} (98%) rename soc/riscv/{riscv-privileged/sifive-freedom/fe310_prci.h => sifive_freedom/e300/prci.h} (100%) rename soc/riscv/{riscv-privileged/sifive-freedom => sifive_freedom/e300}/soc.h (52%) create mode 100644 soc/riscv/sifive_freedom/u500/CMakeLists.txt create mode 100644 soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series create mode 100644 soc/riscv/sifive_freedom/u500/Kconfig.defconfig.u540 create mode 100644 soc/riscv/sifive_freedom/u500/Kconfig.series create mode 100644 soc/riscv/sifive_freedom/u500/Kconfig.soc rename soc/riscv/{riscv-privileged/sifive-freedom/fu540_clock.c => sifive_freedom/u500/clock.c} (97%) rename soc/riscv/{riscv-privileged/sifive-freedom/fu540_prci.h => sifive_freedom/u500/prci.h} (100%) create mode 100644 soc/riscv/sifive_freedom/u500/soc.h create mode 100644 soc/riscv/sifive_freedom/u700/CMakeLists.txt create mode 100644 soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series create mode 100644 soc/riscv/sifive_freedom/u700/Kconfig.defconfig.u740 create mode 100644 soc/riscv/sifive_freedom/u700/Kconfig.series create mode 100644 soc/riscv/sifive_freedom/u700/Kconfig.soc rename soc/riscv/{riscv-privileged/sifive-freedom/fu740_clock.c => sifive_freedom/u700/clock.c} (99%) rename soc/riscv/{riscv-privileged/sifive-freedom/fu740_prci.h => sifive_freedom/u700/prci.h} (100%) create mode 100644 soc/riscv/sifive_freedom/u700/soc.h diff --git a/boards/riscv/hifive1/Kconfig.board b/boards/riscv/hifive1/Kconfig.board index b5b32649441..d2f40472f24 100644 --- a/boards/riscv/hifive1/Kconfig.board +++ b/boards/riscv/hifive1/Kconfig.board @@ -2,4 +2,4 @@ config BOARD_HIFIVE1 bool "HiFive1 target" - depends on SOC_RISCV_SIFIVE_FREEDOM + depends on SOC_SIFIVE_FREEDOM_E340 diff --git a/boards/riscv/hifive1/hifive1_defconfig b/boards/riscv/hifive1/hifive1_defconfig index d37ded2bb25..8e4e8e21c1a 100644 --- a/boards/riscv/hifive1/hifive1_defconfig +++ b/boards/riscv/hifive1/hifive1_defconfig @@ -1,7 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV_SIFIVE_FREEDOM=y -CONFIG_SOC_RISCV_SIFIVE_FREEDOM=y +CONFIG_SOC_SERIES_SIFIVE_FREEDOM_E300=y +CONFIG_SOC_SIFIVE_FREEDOM_E340=y CONFIG_BOARD_HIFIVE1=y CONFIG_CONSOLE=y CONFIG_SERIAL=y diff --git a/boards/riscv/hifive1_revb/Kconfig.board b/boards/riscv/hifive1_revb/Kconfig.board index d4c5b99ce72..b0bf1edd156 100644 --- a/boards/riscv/hifive1_revb/Kconfig.board +++ b/boards/riscv/hifive1_revb/Kconfig.board @@ -3,4 +3,4 @@ config BOARD_HIFIVE1_REVB bool "HiFive1 Rev B target" - depends on SOC_RISCV_SIFIVE_FREEDOM + depends on SOC_SIFIVE_FREEDOM_E340 diff --git a/boards/riscv/hifive1_revb/hifive1_revb_defconfig b/boards/riscv/hifive1_revb/hifive1_revb_defconfig index 4f691bd9435..b2119eecae9 100644 --- a/boards/riscv/hifive1_revb/hifive1_revb_defconfig +++ b/boards/riscv/hifive1_revb/hifive1_revb_defconfig @@ -1,5 +1,5 @@ -CONFIG_SOC_SERIES_RISCV_SIFIVE_FREEDOM=y -CONFIG_SOC_RISCV_SIFIVE_FREEDOM=y +CONFIG_SOC_SERIES_SIFIVE_FREEDOM_E300=y +CONFIG_SOC_SIFIVE_FREEDOM_E340=y CONFIG_BOARD_HIFIVE1_REVB=y CONFIG_GPIO=y CONFIG_PINCTRL=y diff --git a/boards/riscv/hifive_unleashed/Kconfig.board b/boards/riscv/hifive_unleashed/Kconfig.board index 4766e0ea792..f6c623e9928 100644 --- a/boards/riscv/hifive_unleashed/Kconfig.board +++ b/boards/riscv/hifive_unleashed/Kconfig.board @@ -3,4 +3,4 @@ config BOARD_HIFIVE_UNLEASHED bool "HiFive Unleashed target" - depends on SOC_RISCV_SIFIVE_FU540 + depends on SOC_SIFIVE_FREEDOM_U540 diff --git a/boards/riscv/hifive_unleashed/hifive_unleashed_defconfig b/boards/riscv/hifive_unleashed/hifive_unleashed_defconfig index 15c9e60d552..51d324d457d 100644 --- a/boards/riscv/hifive_unleashed/hifive_unleashed_defconfig +++ b/boards/riscv/hifive_unleashed/hifive_unleashed_defconfig @@ -1,5 +1,5 @@ -CONFIG_SOC_SERIES_RISCV_SIFIVE_FREEDOM=y -CONFIG_SOC_RISCV_SIFIVE_FU540=y +CONFIG_SOC_SERIES_SIFIVE_FREEDOM_U500=y +CONFIG_SOC_SIFIVE_FREEDOM_U540=y CONFIG_BOARD_HIFIVE_UNLEASHED=y CONFIG_CONSOLE=y CONFIG_GPIO=y diff --git a/boards/riscv/hifive_unmatched/Kconfig.board b/boards/riscv/hifive_unmatched/Kconfig.board index cf6ac1c8392..bb303cc3aac 100644 --- a/boards/riscv/hifive_unmatched/Kconfig.board +++ b/boards/riscv/hifive_unmatched/Kconfig.board @@ -3,4 +3,4 @@ config BOARD_HIFIVE_UNMATCHED bool "HiFive Unmatched target" - depends on SOC_RISCV_SIFIVE_FU740 + depends on SOC_SIFIVE_FREEDOM_U740 diff --git a/boards/riscv/hifive_unmatched/hifive_unmatched_defconfig b/boards/riscv/hifive_unmatched/hifive_unmatched_defconfig index 654fdc1bf2a..be13ed10358 100644 --- a/boards/riscv/hifive_unmatched/hifive_unmatched_defconfig +++ b/boards/riscv/hifive_unmatched/hifive_unmatched_defconfig @@ -1,5 +1,5 @@ -CONFIG_SOC_SERIES_RISCV_SIFIVE_FREEDOM=y -CONFIG_SOC_RISCV_SIFIVE_FU740=y +CONFIG_SOC_SERIES_SIFIVE_FREEDOM_U700=y +CONFIG_SOC_SIFIVE_FREEDOM_U740=y CONFIG_BOARD_HIFIVE_UNMATCHED=y CONFIG_CONSOLE=y CONFIG_SERIAL=y diff --git a/boards/riscv/qemu_riscv32/Kconfig.board b/boards/riscv/qemu_riscv32/Kconfig.board index 989fa13b453..7c94b59455c 100644 --- a/boards/riscv/qemu_riscv32/Kconfig.board +++ b/boards/riscv/qemu_riscv32/Kconfig.board @@ -22,7 +22,7 @@ config BOARD_QEMU_RISCV32_SMP config BOARD_QEMU_RISCV32_XIP bool "QEMU RISCV32 XIP target" - depends on SOC_RISCV_SIFIVE_FREEDOM + depends on SOC_SIFIVE_FREEDOM_E340 select QEMU_TARGET select HAS_COVERAGE_SUPPORT select CPU_HAS_FPU diff --git a/boards/riscv/qemu_riscv32/qemu_riscv32_xip_defconfig b/boards/riscv/qemu_riscv32/qemu_riscv32_xip_defconfig index 2cd0b2cbecb..948fa909a08 100644 --- a/boards/riscv/qemu_riscv32/qemu_riscv32_xip_defconfig +++ b/boards/riscv/qemu_riscv32/qemu_riscv32_xip_defconfig @@ -1,7 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV_SIFIVE_FREEDOM=y -CONFIG_SOC_RISCV_SIFIVE_FREEDOM=y +CONFIG_SOC_SERIES_SIFIVE_FREEDOM_E300=y +CONFIG_SOC_SIFIVE_FREEDOM_E340=y CONFIG_BOARD_QEMU_RISCV32_XIP=y CONFIG_CONSOLE=y CONFIG_SERIAL=y diff --git a/boards/riscv/sparkfun_red_v_things_plus/Kconfig.board b/boards/riscv/sparkfun_red_v_things_plus/Kconfig.board index 34f852dc0ec..cc9e7b4f935 100644 --- a/boards/riscv/sparkfun_red_v_things_plus/Kconfig.board +++ b/boards/riscv/sparkfun_red_v_things_plus/Kconfig.board @@ -3,4 +3,4 @@ config BOARD_SPARKFUN_RED_V_THINGS_PLUS bool "SparkFun RED-V Things Plus board" - depends on SOC_RISCV_SIFIVE_FREEDOM + depends on SOC_SIFIVE_FREEDOM_E340 diff --git a/boards/riscv/sparkfun_red_v_things_plus/sparkfun_red_v_things_plus_defconfig b/boards/riscv/sparkfun_red_v_things_plus/sparkfun_red_v_things_plus_defconfig index de3d18bcfde..8cf24ffbe09 100644 --- a/boards/riscv/sparkfun_red_v_things_plus/sparkfun_red_v_things_plus_defconfig +++ b/boards/riscv/sparkfun_red_v_things_plus/sparkfun_red_v_things_plus_defconfig @@ -1,8 +1,8 @@ # Copyright (c) 2022 TOKITA Hiroshi # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV_SIFIVE_FREEDOM=y -CONFIG_SOC_RISCV_SIFIVE_FREEDOM=y +CONFIG_SOC_SERIES_SIFIVE_FREEDOM_E300=y +CONFIG_SOC_SIFIVE_FREEDOM_E340=y CONFIG_BOARD_SPARKFUN_RED_V_THINGS_PLUS=y CONFIG_GPIO=y CONFIG_PINCTRL=y diff --git a/soc/riscv/riscv-privileged/sifive-freedom/CMakeLists.txt b/soc/riscv/riscv-privileged/sifive-freedom/CMakeLists.txt deleted file mode 100644 index ff4cc56d739..00000000000 --- a/soc/riscv/riscv-privileged/sifive-freedom/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -zephyr_sources() -zephyr_sources_ifdef(CONFIG_SOC_RISCV_SIFIVE_FREEDOM fe310_clock.c) -zephyr_sources_ifdef(CONFIG_SOC_RISCV_SIFIVE_FU540 fu540_clock.c) -zephyr_sources_ifdef(CONFIG_SOC_RISCV_SIFIVE_FU740 fu740_clock.c) - -set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "") diff --git a/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.series b/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.series deleted file mode 100644 index a24b4812c28..00000000000 --- a/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.series +++ /dev/null @@ -1,11 +0,0 @@ -# RISCV_SIFIVE_FREEDOM SOC implementation - -# Copyright (c) 2017 Jean-Paul Etienne -# SPDX-License-Identifier: Apache-2.0 - -config SOC_SERIES_RISCV_SIFIVE_FREEDOM - bool "SiFive Freedom SOC implementation" - select RISCV - select RISCV_PRIVILEGED - help - Enable support for SiFive Freedom SOC diff --git a/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.soc b/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.soc deleted file mode 100644 index 7840f8a09ba..00000000000 --- a/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.soc +++ /dev/null @@ -1,44 +0,0 @@ -# RISCV_SIFIVE_FREEDOM SOC configuration options - -# Copyright (c) 2017 Jean-Paul Etienne -# SPDX-License-Identifier: Apache-2.0 - -choice - prompt "SiFive Freedom SOC implementation" - depends on SOC_SERIES_RISCV_SIFIVE_FREEDOM - -config SOC_RISCV_SIFIVE_FREEDOM - bool "SiFive Freedom SOC implementation" - select ATOMIC_OPERATIONS_C - select INCLUDE_RESET_VECTOR - select RISCV_ISA_RV32I - select RISCV_ISA_EXT_M - select RISCV_ISA_EXT_A - select RISCV_ISA_EXT_ZICSR - select RISCV_ISA_EXT_ZIFENCEI - -config SOC_RISCV_SIFIVE_FU540 - bool "SiFive Freedom U540 SOC implementation" - select ATOMIC_OPERATIONS_C - select INCLUDE_RESET_VECTOR - select 64BIT - select RISCV_ISA_RV64I - select RISCV_ISA_EXT_M - select RISCV_ISA_EXT_A - select RISCV_ISA_EXT_C - select RISCV_ISA_EXT_ZICSR - select RISCV_ISA_EXT_ZIFENCEI - -config SOC_RISCV_SIFIVE_FU740 - bool "SiFive Freedom U740 SOC implementation" - select ATOMIC_OPERATIONS_C - select INCLUDE_RESET_VECTOR - select 64BIT - select RISCV_ISA_RV64I - select RISCV_ISA_EXT_M - select RISCV_ISA_EXT_A - select RISCV_ISA_EXT_C - select RISCV_ISA_EXT_ZICSR - select RISCV_ISA_EXT_ZIFENCEI - -endchoice diff --git a/soc/riscv/sifive_freedom/CMakeLists.txt b/soc/riscv/sifive_freedom/CMakeLists.txt new file mode 100644 index 00000000000..6a5b10545ff --- /dev/null +++ b/soc/riscv/sifive_freedom/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(common) +add_subdirectory(${SOC_SERIES}) diff --git a/soc/riscv/sifive_freedom/Kconfig b/soc/riscv/sifive_freedom/Kconfig new file mode 100644 index 00000000000..0fed11158af --- /dev/null +++ b/soc/riscv/sifive_freedom/Kconfig @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FAMILY_SIFIVE_FREEDOM + bool + +if SOC_FAMILY_SIFIVE_FREEDOM + +config SOC_FAMILY + string + default "sifive_freedom" + +source "soc/riscv/sifive_freedom/*/Kconfig.soc" + +endif # SOC_FAMILY_SIFIVE_FREEDOM diff --git a/soc/riscv/sifive_freedom/Kconfig.defconfig b/soc/riscv/sifive_freedom/Kconfig.defconfig new file mode 100644 index 00000000000..5adf8fc437e --- /dev/null +++ b/soc/riscv/sifive_freedom/Kconfig.defconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/sifive_freedom/*/Kconfig.defconfig.series" diff --git a/soc/riscv/sifive_freedom/Kconfig.soc b/soc/riscv/sifive_freedom/Kconfig.soc new file mode 100644 index 00000000000..54274defd91 --- /dev/null +++ b/soc/riscv/sifive_freedom/Kconfig.soc @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/sifive_freedom/*/Kconfig.series" diff --git a/soc/riscv/sifive_freedom/common/CMakeLists.txt b/soc/riscv/sifive_freedom/common/CMakeLists.txt new file mode 100644 index 00000000000..f75aec6b311 --- /dev/null +++ b/soc/riscv/sifive_freedom/common/CMakeLists.txt @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_include_directories(.) diff --git a/soc/riscv/riscv-privileged/sifive-freedom/pinctrl_soc.h b/soc/riscv/sifive_freedom/common/pinctrl_soc.h similarity index 100% rename from soc/riscv/riscv-privileged/sifive-freedom/pinctrl_soc.h rename to soc/riscv/sifive_freedom/common/pinctrl_soc.h diff --git a/soc/riscv/sifive_freedom/e300/CMakeLists.txt b/soc/riscv/sifive_freedom/e300/CMakeLists.txt new file mode 100644 index 00000000000..baf01a6b047 --- /dev/null +++ b/soc/riscv/sifive_freedom/e300/CMakeLists.txt @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_sources(clock.c) + +set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "") diff --git a/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.e340 b/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.e340 new file mode 100644 index 00000000000..cb0131f1427 --- /dev/null +++ b/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.e340 @@ -0,0 +1,5 @@ +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +config SOC + default "e340" if SOC_SIFIVE_FREEDOM_E340 diff --git a/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.defconfig.series b/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series similarity index 65% rename from soc/riscv/riscv-privileged/sifive-freedom/Kconfig.defconfig.series rename to soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series index 0c3cd541773..b2f16e5261d 100644 --- a/soc/riscv/riscv-privileged/sifive-freedom/Kconfig.defconfig.series +++ b/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series @@ -1,9 +1,10 @@ +# Copyright (c) 2017 Jean-Paul Etienne # SPDX-License-Identifier: Apache-2.0 -if SOC_SERIES_RISCV_SIFIVE_FREEDOM +if SOC_SERIES_SIFIVE_FREEDOM_E300 config SOC_SERIES - default "sifive-freedom" + default "e300" config SYS_CLOCK_HW_CYCLES_PER_SEC default 32768 @@ -32,4 +33,6 @@ config MAX_IRQ_PER_AGGREGATOR config NUM_IRQS default 64 -endif # SOC_SERIES_RISCV_SIFIVE_FREEDOM +source "soc/riscv/sifive_freedom/e300/Kconfig.defconfig.e*" + +endif # SOC_SERIES_SIFIVE_FREEDOM_E300 diff --git a/soc/riscv/sifive_freedom/e300/Kconfig.series b/soc/riscv/sifive_freedom/e300/Kconfig.series new file mode 100644 index 00000000000..066f8909d53 --- /dev/null +++ b/soc/riscv/sifive_freedom/e300/Kconfig.series @@ -0,0 +1,13 @@ +# RISCV_SIFIVE_FREEDOM SOC implementation + +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_SIFIVE_FREEDOM_E300 + bool "SiFive Freedom E300 SOC implementation" + select RISCV + select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE + select SOC_FAMILY_SIFIVE_FREEDOM + help + Enable support for SiFive Freedom FE300 SOC diff --git a/soc/riscv/sifive_freedom/e300/Kconfig.soc b/soc/riscv/sifive_freedom/e300/Kconfig.soc new file mode 100644 index 00000000000..e53b84c0890 --- /dev/null +++ b/soc/riscv/sifive_freedom/e300/Kconfig.soc @@ -0,0 +1,20 @@ +# RISCV_SIFIVE_FREEDOM SOC configuration options + +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +choice + prompt "SiFive Freedom SOC implementation" + depends on SOC_SERIES_SIFIVE_FREEDOM_E300 + +config SOC_SIFIVE_FREEDOM_E340 + bool "SiFive Freedom SOC implementation" + select ATOMIC_OPERATIONS_C + select INCLUDE_RESET_VECTOR + select RISCV_ISA_RV32I + select RISCV_ISA_EXT_M + select RISCV_ISA_EXT_A + select RISCV_ISA_EXT_ZICSR + select RISCV_ISA_EXT_ZIFENCEI + +endchoice diff --git a/soc/riscv/riscv-privileged/sifive-freedom/fe310_clock.c b/soc/riscv/sifive_freedom/e300/clock.c similarity index 98% rename from soc/riscv/riscv-privileged/sifive-freedom/fe310_clock.c rename to soc/riscv/sifive_freedom/e300/clock.c index 0b642f3e8b2..8fde8121db9 100644 --- a/soc/riscv/riscv-privileged/sifive-freedom/fe310_clock.c +++ b/soc/riscv/sifive_freedom/e300/clock.c @@ -7,7 +7,7 @@ #include #include -#include "fe310_prci.h" +#include "prci.h" #define CORECLK_HZ (DT_PROP(DT_NODELABEL(coreclk), clock_frequency)) BUILD_ASSERT(DT_PROP(DT_NODELABEL(tlclk), clock_div) == 1, diff --git a/soc/riscv/riscv-privileged/sifive-freedom/fe310_prci.h b/soc/riscv/sifive_freedom/e300/prci.h similarity index 100% rename from soc/riscv/riscv-privileged/sifive-freedom/fe310_prci.h rename to soc/riscv/sifive_freedom/e300/prci.h diff --git a/soc/riscv/riscv-privileged/sifive-freedom/soc.h b/soc/riscv/sifive_freedom/e300/soc.h similarity index 52% rename from soc/riscv/riscv-privileged/sifive-freedom/soc.h rename to soc/riscv/sifive_freedom/e300/soc.h index 958891a9d6a..c83f5f322b6 100644 --- a/soc/riscv/riscv-privileged/sifive-freedom/soc.h +++ b/soc/riscv/sifive_freedom/e300/soc.h @@ -8,30 +8,17 @@ * @file SoC configuration macros for the SiFive Freedom processor */ -#ifndef __RISCV_SIFIVE_FREEDOM_SOC_H_ -#define __RISCV_SIFIVE_FREEDOM_SOC_H_ +#ifndef __RISCV_SIFIVE_FREEDOM_FE300_SOC_H_ +#define __RISCV_SIFIVE_FREEDOM_FE300_SOC_H_ #include -#if defined(CONFIG_SOC_RISCV_SIFIVE_FREEDOM) /* PINMUX MAX PINS */ #define SIFIVE_PINMUX_PINS 32 /* Clock controller. */ #define PRCI_BASE_ADDR 0x10008000 -#elif defined(CONFIG_SOC_RISCV_SIFIVE_FU540) || defined(CONFIG_SOC_RISCV_SIFIVE_FU740) - -/* Clock controller. */ -#define PRCI_BASE_ADDR 0x10000000 - -/* PINMUX MAX PINS */ -#define SIFIVE_PINMUX_PINS 16 - -#endif - -#if defined(CONFIG_SOC_RISCV_SIFIVE_FREEDOM) || defined(CONFIG_SOC_RISCV_SIFIVE_FU540) - /* * On FE310 and FU540, peripherals such as SPI, UART, I2C and PWM are clocked * by TLCLK, which is derived from CORECLK. @@ -42,12 +29,4 @@ #define SIFIVE_PERIPHERAL_CLOCK_FREQUENCY \ (SIFIVE_TLCLK_BASE_FREQUENCY / SIFIVE_TLCLK_DIVIDER) -#elif defined(CONFIG_SOC_RISCV_SIFIVE_FU740) - -/* On FU740, peripherals are clocked by PCLK. */ -#define SIFIVE_PERIPHERAL_CLOCK_FREQUENCY \ - DT_PROP(DT_NODELABEL(pclk), clock_frequency) - -#endif - -#endif /* __RISCV_SIFIVE_FREEDOM_SOC_H_ */ +#endif /* __RISCV_SIFIVE_FREEDOM_FE300_SOC_H_ */ diff --git a/soc/riscv/sifive_freedom/u500/CMakeLists.txt b/soc/riscv/sifive_freedom/u500/CMakeLists.txt new file mode 100644 index 00000000000..baf01a6b047 --- /dev/null +++ b/soc/riscv/sifive_freedom/u500/CMakeLists.txt @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_sources(clock.c) + +set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "") diff --git a/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series b/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series new file mode 100644 index 00000000000..d6b94678686 --- /dev/null +++ b/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series @@ -0,0 +1,38 @@ +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_SIFIVE_FREEDOM_U500 + +config SOC_SERIES + default "u500" + +config SYS_CLOCK_HW_CYCLES_PER_SEC + default 32768 + +config RISCV_SOC_INTERRUPT_INIT + default y + +config RISCV_HAS_CPU_IDLE + default y + +config RISCV_HAS_PLIC + default y + +config RISCV_GP + default y + +config 2ND_LVL_ISR_TBL_OFFSET + default 12 + +config 2ND_LVL_INTR_00_OFFSET + default 11 + +config MAX_IRQ_PER_AGGREGATOR + default 52 + +config NUM_IRQS + default 64 + +source "soc/riscv/sifive_freedom/u500/Kconfig.defconfig.u*" + +endif # SOC_SERIES_SIFIVE_FREEDOM_U500 diff --git a/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.u540 b/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.u540 new file mode 100644 index 00000000000..f559f5914b3 --- /dev/null +++ b/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.u540 @@ -0,0 +1,5 @@ +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +config SOC + default "u540" if SOC_SIFIVE_FREEDOM_U540 diff --git a/soc/riscv/sifive_freedom/u500/Kconfig.series b/soc/riscv/sifive_freedom/u500/Kconfig.series new file mode 100644 index 00000000000..963a265f383 --- /dev/null +++ b/soc/riscv/sifive_freedom/u500/Kconfig.series @@ -0,0 +1,13 @@ +# RISCV_SIFIVE_FREEDOM SOC implementation + +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_SIFIVE_FREEDOM_U500 + bool "SiFive Freedom U500 SOC implementation" + select RISCV + select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE + select SOC_FAMILY_SIFIVE_FREEDOM + help + Enable support for SiFive Freedom U500 SOC diff --git a/soc/riscv/sifive_freedom/u500/Kconfig.soc b/soc/riscv/sifive_freedom/u500/Kconfig.soc new file mode 100644 index 00000000000..0a88ccf8cc1 --- /dev/null +++ b/soc/riscv/sifive_freedom/u500/Kconfig.soc @@ -0,0 +1,22 @@ +# RISCV_SIFIVE_FREEDOM SOC configuration options + +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +choice + prompt "SiFive Freedom SOC implementation" + depends on SOC_SERIES_SIFIVE_FREEDOM_U500 + +config SOC_SIFIVE_FREEDOM_U540 + bool "SiFive Freedom U540 SOC implementation" + select ATOMIC_OPERATIONS_C + select INCLUDE_RESET_VECTOR + select 64BIT + select RISCV_ISA_RV64I + select RISCV_ISA_EXT_M + select RISCV_ISA_EXT_A + select RISCV_ISA_EXT_C + select RISCV_ISA_EXT_ZICSR + select RISCV_ISA_EXT_ZIFENCEI + +endchoice diff --git a/soc/riscv/riscv-privileged/sifive-freedom/fu540_clock.c b/soc/riscv/sifive_freedom/u500/clock.c similarity index 97% rename from soc/riscv/riscv-privileged/sifive-freedom/fu540_clock.c rename to soc/riscv/sifive_freedom/u500/clock.c index bc68a502f59..87929892f77 100644 --- a/soc/riscv/riscv-privileged/sifive-freedom/fu540_clock.c +++ b/soc/riscv/sifive_freedom/u500/clock.c @@ -7,7 +7,7 @@ #include #include #include -#include "fu540_prci.h" +#include "prci.h" BUILD_ASSERT(MHZ(1000) == DT_PROP(DT_NODELABEL(coreclk), clock_frequency), "Unsupported CORECLK frequency"); diff --git a/soc/riscv/riscv-privileged/sifive-freedom/fu540_prci.h b/soc/riscv/sifive_freedom/u500/prci.h similarity index 100% rename from soc/riscv/riscv-privileged/sifive-freedom/fu540_prci.h rename to soc/riscv/sifive_freedom/u500/prci.h diff --git a/soc/riscv/sifive_freedom/u500/soc.h b/soc/riscv/sifive_freedom/u500/soc.h new file mode 100644 index 00000000000..ed367950278 --- /dev/null +++ b/soc/riscv/sifive_freedom/u500/soc.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017 Jean-Paul Etienne + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file SoC configuration macros for the SiFive Freedom processor + */ + +#ifndef __RISCV_SIFIVE_FREEDOM_U500_SOC_H_ +#define __RISCV_SIFIVE_FREEDOM_U500_SOC_H_ + +#include + +/* Clock controller. */ +#define PRCI_BASE_ADDR 0x10000000 + +/* PINMUX MAX PINS */ +#define SIFIVE_PINMUX_PINS 16 + +/* + * On FE310 and FU540, peripherals such as SPI, UART, I2C and PWM are clocked + * by TLCLK, which is derived from CORECLK. + */ +#define SIFIVE_TLCLK_BASE_FREQUENCY \ + DT_PROP_BY_PHANDLE_IDX(DT_NODELABEL(tlclk), clocks, 0, clock_frequency) +#define SIFIVE_TLCLK_DIVIDER DT_PROP(DT_NODELABEL(tlclk), clock_div) +#define SIFIVE_PERIPHERAL_CLOCK_FREQUENCY \ + (SIFIVE_TLCLK_BASE_FREQUENCY / SIFIVE_TLCLK_DIVIDER) + +#endif /* __RISCV_SIFIVE_FREEDOM_U500_SOC_H_ */ diff --git a/soc/riscv/sifive_freedom/u700/CMakeLists.txt b/soc/riscv/sifive_freedom/u700/CMakeLists.txt new file mode 100644 index 00000000000..baf01a6b047 --- /dev/null +++ b/soc/riscv/sifive_freedom/u700/CMakeLists.txt @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_sources(clock.c) + +set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "") diff --git a/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series b/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series new file mode 100644 index 00000000000..347ac14b551 --- /dev/null +++ b/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series @@ -0,0 +1,38 @@ +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_SIFIVE_FREEDOM_U700 + +config SOC_SERIES + default "u700" + +config SYS_CLOCK_HW_CYCLES_PER_SEC + default 32768 + +config RISCV_SOC_INTERRUPT_INIT + default y + +config RISCV_HAS_CPU_IDLE + default y + +config RISCV_HAS_PLIC + default y + +config RISCV_GP + default y + +config 2ND_LVL_ISR_TBL_OFFSET + default 12 + +config 2ND_LVL_INTR_00_OFFSET + default 11 + +config MAX_IRQ_PER_AGGREGATOR + default 52 + +config NUM_IRQS + default 64 + +source "soc/riscv/sifive_freedom/u700/Kconfig.defconfig.u*" + +endif # SOC_SERIES_SIFIVE_FREEDOM_U700 diff --git a/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.u740 b/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.u740 new file mode 100644 index 00000000000..ca935f772eb --- /dev/null +++ b/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.u740 @@ -0,0 +1,5 @@ +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +config SOC + default "u740" if SOC_SIFIVE_FREEDOM_U740 diff --git a/soc/riscv/sifive_freedom/u700/Kconfig.series b/soc/riscv/sifive_freedom/u700/Kconfig.series new file mode 100644 index 00000000000..b4ca38697f8 --- /dev/null +++ b/soc/riscv/sifive_freedom/u700/Kconfig.series @@ -0,0 +1,13 @@ +# RISCV_SIFIVE_FREEDOM SOC implementation + +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_SIFIVE_FREEDOM_U700 + bool "SiFive Freedom SOC U700 implementation" + select RISCV + select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE + select SOC_FAMILY_SIFIVE_FREEDOM + help + Enable support for SiFive Freedom U700 SOC diff --git a/soc/riscv/sifive_freedom/u700/Kconfig.soc b/soc/riscv/sifive_freedom/u700/Kconfig.soc new file mode 100644 index 00000000000..1eec9b4bb17 --- /dev/null +++ b/soc/riscv/sifive_freedom/u700/Kconfig.soc @@ -0,0 +1,22 @@ +# RISCV_SIFIVE_FREEDOM SOC configuration options + +# Copyright (c) 2017 Jean-Paul Etienne +# SPDX-License-Identifier: Apache-2.0 + +choice + prompt "SiFive Freedom SOC implementation" + depends on SOC_SERIES_SIFIVE_FREEDOM_U700 + +config SOC_SIFIVE_FREEDOM_U740 + bool "SiFive Freedom U740 SOC implementation" + select ATOMIC_OPERATIONS_C + select INCLUDE_RESET_VECTOR + select 64BIT + select RISCV_ISA_RV64I + select RISCV_ISA_EXT_M + select RISCV_ISA_EXT_A + select RISCV_ISA_EXT_C + select RISCV_ISA_EXT_ZICSR + select RISCV_ISA_EXT_ZIFENCEI + +endchoice diff --git a/soc/riscv/riscv-privileged/sifive-freedom/fu740_clock.c b/soc/riscv/sifive_freedom/u700/clock.c similarity index 99% rename from soc/riscv/riscv-privileged/sifive-freedom/fu740_clock.c rename to soc/riscv/sifive_freedom/u700/clock.c index e6bbee93689..5c3fa567343 100644 --- a/soc/riscv/riscv-privileged/sifive-freedom/fu740_clock.c +++ b/soc/riscv/sifive_freedom/u700/clock.c @@ -8,7 +8,7 @@ #include #include -#include "fu740_prci.h" +#include "prci.h" BUILD_ASSERT(MHZ(1000) == DT_PROP(DT_NODELABEL(coreclk), clock_frequency), "Unsupported CORECLK frequency"); diff --git a/soc/riscv/riscv-privileged/sifive-freedom/fu740_prci.h b/soc/riscv/sifive_freedom/u700/prci.h similarity index 100% rename from soc/riscv/riscv-privileged/sifive-freedom/fu740_prci.h rename to soc/riscv/sifive_freedom/u700/prci.h diff --git a/soc/riscv/sifive_freedom/u700/soc.h b/soc/riscv/sifive_freedom/u700/soc.h new file mode 100644 index 00000000000..91aac61afdd --- /dev/null +++ b/soc/riscv/sifive_freedom/u700/soc.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017 Jean-Paul Etienne + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file SoC configuration macros for the SiFive Freedom processor + */ + +#ifndef __RISCV_SIFIVE_FREEDOM_U700_SOC_H_ +#define __RISCV_SIFIVE_FREEDOM_U700_SOC_H_ + +#include + +/* Clock controller. */ +#define PRCI_BASE_ADDR 0x10000000 + +/* PINMUX MAX PINS */ +#define SIFIVE_PINMUX_PINS 16 + +/* On FU740, peripherals are clocked by PCLK. */ +#define SIFIVE_PERIPHERAL_CLOCK_FREQUENCY \ + DT_PROP(DT_NODELABEL(pclk), clock_frequency) + +#endif /* __RISCV_SIFIVE_FREEDOM_U700_SOC_H_ */ From 821879ccab8c320f778dd1435091b104faa23840 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 17:30:23 +0100 Subject: [PATCH 1199/1623] [nrf fromtree] soc: riscv: opentitan: reorganize SoC folder Remove from riscv-privileged, and create a standalone SoC. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit b5fb00bdc87588607940d2af053866d04d11d423) --- boards/riscv/opentitan_earlgrey/Kconfig.board | 2 +- .../opentitan_earlgrey_defconfig | 3 +-- .../opentitan/CMakeLists.txt | 0 .../Kconfig.defconfig} | 6 +++--- .../{riscv-privileged => }/opentitan/Kconfig.soc | 14 +++++++------- .../{riscv-privileged => }/opentitan/rom_header.S | 0 .../{riscv-privileged => }/opentitan/rom_header.ld | 0 soc/riscv/{riscv-privileged => }/opentitan/soc.c | 0 soc/riscv/{riscv-privileged => }/opentitan/soc.h | 0 .../riscv-privileged/opentitan/Kconfig.series | 12 ------------ 10 files changed, 12 insertions(+), 25 deletions(-) rename soc/riscv/{riscv-privileged => }/opentitan/CMakeLists.txt (100%) rename soc/riscv/{riscv-privileged/opentitan/Kconfig.defconfig.series => opentitan/Kconfig.defconfig} (83%) rename soc/riscv/{riscv-privileged => }/opentitan/Kconfig.soc (63%) rename soc/riscv/{riscv-privileged => }/opentitan/rom_header.S (100%) rename soc/riscv/{riscv-privileged => }/opentitan/rom_header.ld (100%) rename soc/riscv/{riscv-privileged => }/opentitan/soc.c (100%) rename soc/riscv/{riscv-privileged => }/opentitan/soc.h (100%) delete mode 100644 soc/riscv/riscv-privileged/opentitan/Kconfig.series diff --git a/boards/riscv/opentitan_earlgrey/Kconfig.board b/boards/riscv/opentitan_earlgrey/Kconfig.board index ec7f735b442..544c02b1b2a 100644 --- a/boards/riscv/opentitan_earlgrey/Kconfig.board +++ b/boards/riscv/opentitan_earlgrey/Kconfig.board @@ -3,4 +3,4 @@ config BOARD_OPENTITAN_EARLGREY bool "OpenTitan Earl Grey Target" - depends on SOC_RISCV_OPENTITAN + depends on SOC_OPENTITAN diff --git a/boards/riscv/opentitan_earlgrey/opentitan_earlgrey_defconfig b/boards/riscv/opentitan_earlgrey/opentitan_earlgrey_defconfig index 79299c3892f..886e439b88a 100644 --- a/boards/riscv/opentitan_earlgrey/opentitan_earlgrey_defconfig +++ b/boards/riscv/opentitan_earlgrey/opentitan_earlgrey_defconfig @@ -1,8 +1,7 @@ # Copyright (c) 2023 by Rivos Inc. # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV_OPENTITAN=y -CONFIG_SOC_RISCV_OPENTITAN=y +CONFIG_SOC_OPENTITAN=y CONFIG_BOARD_OPENTITAN_EARLGREY=y CONFIG_XIP=y CONFIG_SERIAL=y diff --git a/soc/riscv/riscv-privileged/opentitan/CMakeLists.txt b/soc/riscv/opentitan/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/opentitan/CMakeLists.txt rename to soc/riscv/opentitan/CMakeLists.txt diff --git a/soc/riscv/riscv-privileged/opentitan/Kconfig.defconfig.series b/soc/riscv/opentitan/Kconfig.defconfig similarity index 83% rename from soc/riscv/riscv-privileged/opentitan/Kconfig.defconfig.series rename to soc/riscv/opentitan/Kconfig.defconfig index c9e7f8396a0..cc27b7ffd6b 100644 --- a/soc/riscv/riscv-privileged/opentitan/Kconfig.defconfig.series +++ b/soc/riscv/opentitan/Kconfig.defconfig @@ -1,9 +1,9 @@ # Copyright (c) 2023 Rivos Inc. # SPDX-License-Identifier: Apache-2.0 -if SOC_SERIES_RISCV_OPENTITAN +if SOC_OPENTITAN -config SOC_SERIES +config SOC default "opentitan" config SYS_CLOCK_HW_CYCLES_PER_SEC @@ -30,4 +30,4 @@ config 2ND_LVL_INTR_00_OFFSET config NUM_IRQS default 217 -endif # SOC_SERIES_RISCV_OPENTITAN +endif # SOC_OPENTITAN diff --git a/soc/riscv/riscv-privileged/opentitan/Kconfig.soc b/soc/riscv/opentitan/Kconfig.soc similarity index 63% rename from soc/riscv/riscv-privileged/opentitan/Kconfig.soc rename to soc/riscv/opentitan/Kconfig.soc index 098b1844e52..b482afce469 100644 --- a/soc/riscv/riscv-privileged/opentitan/Kconfig.soc +++ b/soc/riscv/opentitan/Kconfig.soc @@ -1,11 +1,7 @@ # Copyright (c) 2023 Rivos Inc. # SPDX-License-Identifier: Apache-2.0 -choice - prompt "OpenTitan implementation" - depends on SOC_SERIES_RISCV_OPENTITAN - -config SOC_RISCV_OPENTITAN +config SOC_OPENTITAN bool "OpenTitan implementation" select ATOMIC_OPERATIONS_C select INCLUDE_RESET_VECTOR @@ -18,5 +14,9 @@ config SOC_RISCV_OPENTITAN select RISCV_ISA_EXT_ZBB select RISCV_ISA_EXT_ZBC select RISCV_ISA_EXT_ZBS - -endchoice + select RISCV + select RISCV_PRIVILEGED + # OpenTitan Ibex core mtvec mode is read-only / forced to vectored mode. + select RISCV_VECTORED_MODE + select GEN_IRQ_VECTOR_TABLE + select RISCV_PRIVILEGED_STANDALONE diff --git a/soc/riscv/riscv-privileged/opentitan/rom_header.S b/soc/riscv/opentitan/rom_header.S similarity index 100% rename from soc/riscv/riscv-privileged/opentitan/rom_header.S rename to soc/riscv/opentitan/rom_header.S diff --git a/soc/riscv/riscv-privileged/opentitan/rom_header.ld b/soc/riscv/opentitan/rom_header.ld similarity index 100% rename from soc/riscv/riscv-privileged/opentitan/rom_header.ld rename to soc/riscv/opentitan/rom_header.ld diff --git a/soc/riscv/riscv-privileged/opentitan/soc.c b/soc/riscv/opentitan/soc.c similarity index 100% rename from soc/riscv/riscv-privileged/opentitan/soc.c rename to soc/riscv/opentitan/soc.c diff --git a/soc/riscv/riscv-privileged/opentitan/soc.h b/soc/riscv/opentitan/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/opentitan/soc.h rename to soc/riscv/opentitan/soc.h diff --git a/soc/riscv/riscv-privileged/opentitan/Kconfig.series b/soc/riscv/riscv-privileged/opentitan/Kconfig.series deleted file mode 100644 index b516e6d8092..00000000000 --- a/soc/riscv/riscv-privileged/opentitan/Kconfig.series +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2023 Rivos Inc. -# SPDX-License-Identifier: Apache-2.0 - -config SOC_SERIES_RISCV_OPENTITAN - bool "OpenTitan implementation" - select RISCV - select RISCV_PRIVILEGED - # OpenTitan Ibex core mtvec mode is read-only / forced to vectored mode. - select RISCV_VECTORED_MODE - select GEN_IRQ_VECTOR_TABLE - help - Enable support for OpenTitan From ccb9ae80dc6fb9a6e8c1d9048e5c2f3561f2d639 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 17:36:53 +0100 Subject: [PATCH 1200/1623] [nrf fromtree] soc: riscv: niosv: reorganize SoC folder Move out of riscv-privileged, create new family for it. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 8729a782f96eaa2d673517048dd1afef0513ffd2) --- .../CMakeLists.txt | 1 + soc/riscv/intel_niosv/Kconfig | 15 +++++++++++++++ soc/riscv/intel_niosv/Kconfig.defconfig | 4 ++++ soc/riscv/intel_niosv/Kconfig.soc | 4 ++++ .../niosv/CMakeLists.txt | 0 .../niosv/Kconfig.defconfig.series | 2 +- .../niosv/Kconfig.series | 2 ++ .../niosv/Kconfig.soc | 0 .../niosv/linker.ld | 0 .../{riscv-privileged => intel_niosv}/niosv/soc.h | 0 soc/riscv/riscv-privileged/Kconfig | 4 ---- soc/riscv/riscv-privileged/Kconfig.defconfig | 6 ------ soc/riscv/riscv-privileged/Kconfig.soc | 6 ------ 13 files changed, 27 insertions(+), 17 deletions(-) rename soc/riscv/{riscv-privileged => intel_niosv}/CMakeLists.txt (62%) create mode 100644 soc/riscv/intel_niosv/Kconfig create mode 100644 soc/riscv/intel_niosv/Kconfig.defconfig create mode 100644 soc/riscv/intel_niosv/Kconfig.soc rename soc/riscv/{riscv-privileged => intel_niosv}/niosv/CMakeLists.txt (100%) rename soc/riscv/{riscv-privileged => intel_niosv}/niosv/Kconfig.defconfig.series (94%) rename soc/riscv/{riscv-privileged => intel_niosv}/niosv/Kconfig.series (76%) rename soc/riscv/{riscv-privileged => intel_niosv}/niosv/Kconfig.soc (100%) rename soc/riscv/{riscv-privileged => intel_niosv}/niosv/linker.ld (100%) rename soc/riscv/{riscv-privileged => intel_niosv}/niosv/soc.h (100%) delete mode 100644 soc/riscv/riscv-privileged/Kconfig delete mode 100644 soc/riscv/riscv-privileged/Kconfig.defconfig delete mode 100644 soc/riscv/riscv-privileged/Kconfig.soc diff --git a/soc/riscv/riscv-privileged/CMakeLists.txt b/soc/riscv/intel_niosv/CMakeLists.txt similarity index 62% rename from soc/riscv/riscv-privileged/CMakeLists.txt rename to soc/riscv/intel_niosv/CMakeLists.txt index 226f3bd626f..69b2926358e 100644 --- a/soc/riscv/riscv-privileged/CMakeLists.txt +++ b/soc/riscv/intel_niosv/CMakeLists.txt @@ -1,3 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor # SPDX-License-Identifier: Apache-2.0 add_subdirectory(${SOC_SERIES}) diff --git a/soc/riscv/intel_niosv/Kconfig b/soc/riscv/intel_niosv/Kconfig new file mode 100644 index 00000000000..b841d19c922 --- /dev/null +++ b/soc/riscv/intel_niosv/Kconfig @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FAMILY_INTEL_NIOSV + bool + +if SOC_FAMILY_INTEL_NIOSV + +config SOC_FAMILY + string + default "intel_niosv" + +source "soc/riscv/intel_niosv/*/Kconfig.soc" + +endif # SOC_FAMILY_INTEL_NIOSV diff --git a/soc/riscv/intel_niosv/Kconfig.defconfig b/soc/riscv/intel_niosv/Kconfig.defconfig new file mode 100644 index 00000000000..2afa0f7e0e6 --- /dev/null +++ b/soc/riscv/intel_niosv/Kconfig.defconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/intel_niosv/*/Kconfig.defconfig.series" diff --git a/soc/riscv/intel_niosv/Kconfig.soc b/soc/riscv/intel_niosv/Kconfig.soc new file mode 100644 index 00000000000..8567429c61f --- /dev/null +++ b/soc/riscv/intel_niosv/Kconfig.soc @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/intel_niosv/*/Kconfig.series" diff --git a/soc/riscv/riscv-privileged/niosv/CMakeLists.txt b/soc/riscv/intel_niosv/niosv/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/niosv/CMakeLists.txt rename to soc/riscv/intel_niosv/niosv/CMakeLists.txt diff --git a/soc/riscv/riscv-privileged/niosv/Kconfig.defconfig.series b/soc/riscv/intel_niosv/niosv/Kconfig.defconfig.series similarity index 94% rename from soc/riscv/riscv-privileged/niosv/Kconfig.defconfig.series rename to soc/riscv/intel_niosv/niosv/Kconfig.defconfig.series index 532a67959d2..8e8ea255202 100644 --- a/soc/riscv/riscv-privileged/niosv/Kconfig.defconfig.series +++ b/soc/riscv/intel_niosv/niosv/Kconfig.defconfig.series @@ -21,4 +21,4 @@ config RISCV_GP config RISCV_SOC_INTERRUPT_INIT default y -endif # SOC_SERIES_NIOSV +endif # SOC_NIOSV diff --git a/soc/riscv/riscv-privileged/niosv/Kconfig.series b/soc/riscv/intel_niosv/niosv/Kconfig.series similarity index 76% rename from soc/riscv/riscv-privileged/niosv/Kconfig.series rename to soc/riscv/intel_niosv/niosv/Kconfig.series index 104f5a48352..b8edc073916 100644 --- a/soc/riscv/riscv-privileged/niosv/Kconfig.series +++ b/soc/riscv/intel_niosv/niosv/Kconfig.series @@ -5,5 +5,7 @@ config SOC_SERIES_NIOSV bool "INTEL FPGA NIOSV" select RISCV select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE + select SOC_FAMILY_INTEL_NIOSV help Enable support for the INTEL FPGA NIOSV. diff --git a/soc/riscv/riscv-privileged/niosv/Kconfig.soc b/soc/riscv/intel_niosv/niosv/Kconfig.soc similarity index 100% rename from soc/riscv/riscv-privileged/niosv/Kconfig.soc rename to soc/riscv/intel_niosv/niosv/Kconfig.soc diff --git a/soc/riscv/riscv-privileged/niosv/linker.ld b/soc/riscv/intel_niosv/niosv/linker.ld similarity index 100% rename from soc/riscv/riscv-privileged/niosv/linker.ld rename to soc/riscv/intel_niosv/niosv/linker.ld diff --git a/soc/riscv/riscv-privileged/niosv/soc.h b/soc/riscv/intel_niosv/niosv/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/niosv/soc.h rename to soc/riscv/intel_niosv/niosv/soc.h diff --git a/soc/riscv/riscv-privileged/Kconfig b/soc/riscv/riscv-privileged/Kconfig deleted file mode 100644 index b0700dd3440..00000000000 --- a/soc/riscv/riscv-privileged/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# Copyright (c) 2017 Jean-Paul Etienne -# SPDX-License-Identifier: Apache-2.0 - -source "soc/riscv/riscv-privileged/*/Kconfig.soc" diff --git a/soc/riscv/riscv-privileged/Kconfig.defconfig b/soc/riscv/riscv-privileged/Kconfig.defconfig deleted file mode 100644 index 6793d72a385..00000000000 --- a/soc/riscv/riscv-privileged/Kconfig.defconfig +++ /dev/null @@ -1,6 +0,0 @@ -# riscv SOC family supporting the riscv privileged architecture spec - -# Copyright (c) 2017 Jean-Paul Etienne -# SPDX-License-Identifier: Apache-2.0 - -source "soc/riscv/riscv-privileged/*/Kconfig.defconfig.series" diff --git a/soc/riscv/riscv-privileged/Kconfig.soc b/soc/riscv/riscv-privileged/Kconfig.soc deleted file mode 100644 index 14d141223e0..00000000000 --- a/soc/riscv/riscv-privileged/Kconfig.soc +++ /dev/null @@ -1,6 +0,0 @@ -# riscv SOC series supporting the riscv privileged architecture spec - -# Copyright (c) 2017 Jean-Paul Etienne -# SPDX-License-Identifier: Apache-2.0 - -source "soc/riscv/riscv-privileged/*/Kconfig.series" From 2ba07f2e7af19338f6fff5d296b1829f1ff2ffc6 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 8 Jan 2024 14:13:06 +0100 Subject: [PATCH 1201/1623] [nrf fromtree] soc: riscv: renove_virt: reorganize SoC folder Move out from riscv-privileged, and convert to a standalone SoC. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 724a967c1a170f181e4fccb974fb22127fb0d75a) --- boards/riscv/riscv32_virtual/riscv32_virtual_defconfig | 1 - .../{riscv-privileged => }/renode_virt/CMakeLists.txt | 0 .../Kconfig.defconfig} | 6 +++--- soc/riscv/{riscv-privileged => }/renode_virt/Kconfig.soc | 9 +++------ soc/riscv/{riscv-privileged => }/renode_virt/soc.h | 0 soc/riscv/riscv-privileged/renode_virt/Kconfig.series | 9 --------- 6 files changed, 6 insertions(+), 19 deletions(-) rename soc/riscv/{riscv-privileged => }/renode_virt/CMakeLists.txt (100%) rename soc/riscv/{riscv-privileged/renode_virt/Kconfig.defconfig.series => renode_virt/Kconfig.defconfig} (86%) rename soc/riscv/{riscv-privileged => }/renode_virt/Kconfig.soc (75%) rename soc/riscv/{riscv-privileged => }/renode_virt/soc.h (100%) delete mode 100644 soc/riscv/riscv-privileged/renode_virt/Kconfig.series diff --git a/boards/riscv/riscv32_virtual/riscv32_virtual_defconfig b/boards/riscv/riscv32_virtual/riscv32_virtual_defconfig index a905f99da2e..4dcad0a7ea1 100644 --- a/boards/riscv/riscv32_virtual/riscv32_virtual_defconfig +++ b/boards/riscv/riscv32_virtual/riscv32_virtual_defconfig @@ -1,7 +1,6 @@ # Copyright (c) 2023 Meta # SPDX-License-Identifier: Apache-2.0 -CONFIG_SOC_SERIES_RISCV32_VIRTUAL_RENODE=y CONFIG_SOC_RISCV32_VIRTUAL_RENODE=y CONFIG_BOARD_RISCV32_VIRTUAL=y CONFIG_CONSOLE=y diff --git a/soc/riscv/riscv-privileged/renode_virt/CMakeLists.txt b/soc/riscv/renode_virt/CMakeLists.txt similarity index 100% rename from soc/riscv/riscv-privileged/renode_virt/CMakeLists.txt rename to soc/riscv/renode_virt/CMakeLists.txt diff --git a/soc/riscv/riscv-privileged/renode_virt/Kconfig.defconfig.series b/soc/riscv/renode_virt/Kconfig.defconfig similarity index 86% rename from soc/riscv/riscv-privileged/renode_virt/Kconfig.defconfig.series rename to soc/riscv/renode_virt/Kconfig.defconfig index 09adc3d00e8..89e226edbb1 100644 --- a/soc/riscv/riscv-privileged/renode_virt/Kconfig.defconfig.series +++ b/soc/riscv/renode_virt/Kconfig.defconfig @@ -1,9 +1,9 @@ # Copyright (c) 2023 Meta # SPDX-License-Identifier: Apache-2.0 -if SOC_SERIES_RISCV32_VIRTUAL_RENODE +if SOC_RISCV32_VIRTUAL_RENODE -config SOC_SERIES +config SOC default "renode_virt" config SYS_CLOCK_HW_CYCLES_PER_SEC @@ -45,4 +45,4 @@ config MAX_IRQ_PER_AGGREGATOR config NUM_IRQS default 2058 -endif # SOC_SERIES_RISCV32_VIRTUAL_RENODE +endif # SOC_RISCV32_VIRTUAL_RENODE diff --git a/soc/riscv/riscv-privileged/renode_virt/Kconfig.soc b/soc/riscv/renode_virt/Kconfig.soc similarity index 75% rename from soc/riscv/riscv-privileged/renode_virt/Kconfig.soc rename to soc/riscv/renode_virt/Kconfig.soc index d123e797229..3e8af25099f 100644 --- a/soc/riscv/riscv-privileged/renode_virt/Kconfig.soc +++ b/soc/riscv/renode_virt/Kconfig.soc @@ -1,12 +1,11 @@ # Copyright (c) 2023 Meta # SPDX-License-Identifier: Apache-2.0 -choice - prompt "Renode RISCV32 Virtual system implementation" - depends on SOC_SERIES_RISCV32_VIRTUAL_RENODE - config SOC_RISCV32_VIRTUAL_RENODE bool "Renode RISCV32 Virtual system implementation" + select RISCV + select RISCV_PRIVILEGED + select RISCV_PRIVILEGED_STANDALONE select ATOMIC_OPERATIONS_BUILTIN select INCLUDE_RESET_VECTOR select RISCV_ISA_RV32I @@ -15,5 +14,3 @@ config SOC_RISCV32_VIRTUAL_RENODE select RISCV_ISA_EXT_C select RISCV_ISA_EXT_ZICSR select RISCV_ISA_EXT_ZIFENCEI - -endchoice diff --git a/soc/riscv/riscv-privileged/renode_virt/soc.h b/soc/riscv/renode_virt/soc.h similarity index 100% rename from soc/riscv/riscv-privileged/renode_virt/soc.h rename to soc/riscv/renode_virt/soc.h diff --git a/soc/riscv/riscv-privileged/renode_virt/Kconfig.series b/soc/riscv/riscv-privileged/renode_virt/Kconfig.series deleted file mode 100644 index 22e27cf38b4..00000000000 --- a/soc/riscv/riscv-privileged/renode_virt/Kconfig.series +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2023 Meta -# SPDX-License-Identifier: Apache-2.0 - -config SOC_SERIES_RISCV32_VIRTUAL_RENODE - bool "Renode RISC-V32 Virtual SoC implementation" - select RISCV - select SOC_FAMILY_RISCV_PRIVILEGED - help - Enable support for Renode RISC-V Virtual From dfd6d6bd0522713ede8d3c0ab534e438f211aef5 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 3 Jan 2024 17:39:38 +0100 Subject: [PATCH 1202/1623] [nrf fromtree] soc: riscv: drop RISCV_PRIVILEGED_STANDALONE This option is no longer needed, all SoCs have been moved out from soc/riscv/riscv-privileged folder. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 14ff171411901b994f2761a76af4baf17bcdab7b) --- soc/riscv/andes_v5/ae350/Kconfig.series | 1 - soc/riscv/common/riscv-privileged/Kconfig | 7 ------- soc/riscv/efinix_sapphire/Kconfig.soc | 1 - soc/riscv/gd_gd32/gd32vf103/Kconfig.series | 1 - soc/riscv/intel_niosv/niosv/Kconfig.series | 1 - soc/riscv/microchip_miv/miv/Kconfig.series | 1 - soc/riscv/microchip_miv/polarfire/Kconfig.series | 1 - soc/riscv/neorv32/Kconfig.soc | 1 - soc/riscv/opentitan/Kconfig.soc | 1 - soc/riscv/renode_virt/Kconfig.soc | 1 - soc/riscv/sifive_freedom/e300/Kconfig.series | 1 - soc/riscv/sifive_freedom/u500/Kconfig.series | 1 - soc/riscv/sifive_freedom/u700/Kconfig.series | 1 - soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series | 1 - soc/riscv/telink_tlsr/tlsr951x/Kconfig.series | 1 - soc/riscv/virt/Kconfig.soc | 1 - 16 files changed, 22 deletions(-) diff --git a/soc/riscv/andes_v5/ae350/Kconfig.series b/soc/riscv/andes_v5/ae350/Kconfig.series index 4eb9557f92f..ebf68f7a3aa 100644 --- a/soc/riscv/andes_v5/ae350/Kconfig.series +++ b/soc/riscv/andes_v5/ae350/Kconfig.series @@ -5,7 +5,6 @@ config SOC_SERIES_ANDES_AE350 bool "Andes V5 AE350 SoC Series Implementation" select RISCV select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE select SOC_FAMILY_ANDES_V5 help Enable support for Andes V5 AE350 SoC Series diff --git a/soc/riscv/common/riscv-privileged/Kconfig b/soc/riscv/common/riscv-privileged/Kconfig index de064842604..a4a8da0bf1f 100644 --- a/soc/riscv/common/riscv-privileged/Kconfig +++ b/soc/riscv/common/riscv-privileged/Kconfig @@ -4,13 +4,6 @@ # Copyright (c) 2017 Jean-Paul Etienne # SPDX-License-Identifier: Apache-2.0 -config RISCV_PRIVILEGED_STANDALONE - bool - -config SOC_FAMILY - string - default "riscv-privileged" if RISCV_PRIVILEGED && !RISCV_PRIVILEGED_STANDALONE - config RISCV_HAS_PLIC bool "Does the SOC provide support for a Platform Level Interrupt Controller (PLIC)" depends on RISCV_PRIVILEGED diff --git a/soc/riscv/efinix_sapphire/Kconfig.soc b/soc/riscv/efinix_sapphire/Kconfig.soc index 2cc5f3ba361..bf57d9cc541 100644 --- a/soc/riscv/efinix_sapphire/Kconfig.soc +++ b/soc/riscv/efinix_sapphire/Kconfig.soc @@ -12,4 +12,3 @@ config SOC_EFINIX_SAPPHIRE select RISCV_ISA_EXT_ZIFENCEI select RISCV select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE diff --git a/soc/riscv/gd_gd32/gd32vf103/Kconfig.series b/soc/riscv/gd_gd32/gd32vf103/Kconfig.series index b0b86db7c02..e50567e0798 100644 --- a/soc/riscv/gd_gd32/gd32vf103/Kconfig.series +++ b/soc/riscv/gd_gd32/gd32vf103/Kconfig.series @@ -16,6 +16,5 @@ config SOC_SERIES_GD32VF103 select HAS_GD32_HAL select RISCV_HAS_CLIC select SOC_FAMILY_GD32 - select RISCV_PRIVILEGED_STANDALONE help Enable support for GigaDevice GD32VF1 series SoC diff --git a/soc/riscv/intel_niosv/niosv/Kconfig.series b/soc/riscv/intel_niosv/niosv/Kconfig.series index b8edc073916..9d7aa492692 100644 --- a/soc/riscv/intel_niosv/niosv/Kconfig.series +++ b/soc/riscv/intel_niosv/niosv/Kconfig.series @@ -5,7 +5,6 @@ config SOC_SERIES_NIOSV bool "INTEL FPGA NIOSV" select RISCV select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE select SOC_FAMILY_INTEL_NIOSV help Enable support for the INTEL FPGA NIOSV. diff --git a/soc/riscv/microchip_miv/miv/Kconfig.series b/soc/riscv/microchip_miv/miv/Kconfig.series index 20430e6d0f9..2989876c0e0 100644 --- a/soc/riscv/microchip_miv/miv/Kconfig.series +++ b/soc/riscv/microchip_miv/miv/Kconfig.series @@ -8,6 +8,5 @@ config SOC_SERIES_MIV select SOC_FAMILY_MICROCHIP_MIV select RISCV select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE help Enable support for Microchip Mi-V diff --git a/soc/riscv/microchip_miv/polarfire/Kconfig.series b/soc/riscv/microchip_miv/polarfire/Kconfig.series index 4bbceaee745..9001efc2858 100644 --- a/soc/riscv/microchip_miv/polarfire/Kconfig.series +++ b/soc/riscv/microchip_miv/polarfire/Kconfig.series @@ -8,6 +8,5 @@ config SOC_SERIES_POLARFIRE select SOC_FAMILY_MICROCHIP_MIV select RISCV select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE help Enable support for Microchip RISCV 64bit diff --git a/soc/riscv/neorv32/Kconfig.soc b/soc/riscv/neorv32/Kconfig.soc index f07bba96574..3155d1b7c31 100644 --- a/soc/riscv/neorv32/Kconfig.soc +++ b/soc/riscv/neorv32/Kconfig.soc @@ -10,7 +10,6 @@ config SOC_NEORV32 select RISCV_ISA_EXT_ZICSR select RISCV_ISA_EXT_ZIFENCEI select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE help Enable support for the NEORV32 Processor (SoC). diff --git a/soc/riscv/opentitan/Kconfig.soc b/soc/riscv/opentitan/Kconfig.soc index b482afce469..8270fde110d 100644 --- a/soc/riscv/opentitan/Kconfig.soc +++ b/soc/riscv/opentitan/Kconfig.soc @@ -19,4 +19,3 @@ config SOC_OPENTITAN # OpenTitan Ibex core mtvec mode is read-only / forced to vectored mode. select RISCV_VECTORED_MODE select GEN_IRQ_VECTOR_TABLE - select RISCV_PRIVILEGED_STANDALONE diff --git a/soc/riscv/renode_virt/Kconfig.soc b/soc/riscv/renode_virt/Kconfig.soc index 3e8af25099f..5aae660880a 100644 --- a/soc/riscv/renode_virt/Kconfig.soc +++ b/soc/riscv/renode_virt/Kconfig.soc @@ -5,7 +5,6 @@ config SOC_RISCV32_VIRTUAL_RENODE bool "Renode RISCV32 Virtual system implementation" select RISCV select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE select ATOMIC_OPERATIONS_BUILTIN select INCLUDE_RESET_VECTOR select RISCV_ISA_RV32I diff --git a/soc/riscv/sifive_freedom/e300/Kconfig.series b/soc/riscv/sifive_freedom/e300/Kconfig.series index 066f8909d53..47ae89e6d4c 100644 --- a/soc/riscv/sifive_freedom/e300/Kconfig.series +++ b/soc/riscv/sifive_freedom/e300/Kconfig.series @@ -7,7 +7,6 @@ config SOC_SERIES_SIFIVE_FREEDOM_E300 bool "SiFive Freedom E300 SOC implementation" select RISCV select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE select SOC_FAMILY_SIFIVE_FREEDOM help Enable support for SiFive Freedom FE300 SOC diff --git a/soc/riscv/sifive_freedom/u500/Kconfig.series b/soc/riscv/sifive_freedom/u500/Kconfig.series index 963a265f383..a576dfbc6f7 100644 --- a/soc/riscv/sifive_freedom/u500/Kconfig.series +++ b/soc/riscv/sifive_freedom/u500/Kconfig.series @@ -7,7 +7,6 @@ config SOC_SERIES_SIFIVE_FREEDOM_U500 bool "SiFive Freedom U500 SOC implementation" select RISCV select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE select SOC_FAMILY_SIFIVE_FREEDOM help Enable support for SiFive Freedom U500 SOC diff --git a/soc/riscv/sifive_freedom/u700/Kconfig.series b/soc/riscv/sifive_freedom/u700/Kconfig.series index b4ca38697f8..613844703c7 100644 --- a/soc/riscv/sifive_freedom/u700/Kconfig.series +++ b/soc/riscv/sifive_freedom/u700/Kconfig.series @@ -7,7 +7,6 @@ config SOC_SERIES_SIFIVE_FREEDOM_U700 bool "SiFive Freedom SOC U700 implementation" select RISCV select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE select SOC_FAMILY_SIFIVE_FREEDOM help Enable support for SiFive Freedom U700 SOC diff --git a/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series index d70cff1c63d..19cedcefe27 100644 --- a/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series +++ b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series @@ -5,6 +5,5 @@ config SOC_SERIES_STARFIVE_JH71XX bool "Starfive JH71XX series" select RISCV select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE help Enable support for Starfive JH71XX SoC Series. diff --git a/soc/riscv/telink_tlsr/tlsr951x/Kconfig.series b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.series index e074a53e11b..5ad3053725e 100644 --- a/soc/riscv/telink_tlsr/tlsr951x/Kconfig.series +++ b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.series @@ -16,6 +16,5 @@ config SOC_SERIES_TELINK_TLSR951X select CPU_HAS_FPU select INCLUDE_RESET_VECTOR select SOC_FAMILY_TELINK_TLSR - select RISCV_PRIVILEGED_STANDALONE help Enable support for Telink TLSR951X diff --git a/soc/riscv/virt/Kconfig.soc b/soc/riscv/virt/Kconfig.soc index fb615005b0a..9a9168f5a8c 100644 --- a/soc/riscv/virt/Kconfig.soc +++ b/soc/riscv/virt/Kconfig.soc @@ -10,4 +10,3 @@ config SOC_RISCV_VIRT select RISCV_ISA_EXT_C select RISCV select RISCV_PRIVILEGED - select RISCV_PRIVILEGED_STANDALONE From 1d4e70e7eb1816cb24d342b376017cd2496e007c Mon Sep 17 00:00:00 2001 From: Chen Xingyu Date: Sun, 26 Nov 2023 13:08:45 +0800 Subject: [PATCH 1203/1623] [nrf fromtree] soc: riscv: privileged: efinix-sapphire: Enable CONFIG_RISCV_HAS_CPU_IDLE In an earlier commit, the riscv-privileged level implementation of `arch_cpu_idle()` is not included unless `CONFIG_RISCV_HAS_CPU_IDLE` is enabled. This commit ensures the option is enabled on all the existing CPUs, thereby maintaining the existing behavior. Signed-off-by: Chen Xingyu (cherry picked from commit 3f7e73416de99bdc35819e0af394ed9dc74e2a2a) --- soc/riscv/efinix_sapphire/Kconfig.defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/soc/riscv/efinix_sapphire/Kconfig.defconfig b/soc/riscv/efinix_sapphire/Kconfig.defconfig index 5424bca7baf..7018c0f11fb 100644 --- a/soc/riscv/efinix_sapphire/Kconfig.defconfig +++ b/soc/riscv/efinix_sapphire/Kconfig.defconfig @@ -11,6 +11,7 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_HAS_CPU_IDLE bool + default y config RISCV_SOC_INTERRUPT_INIT bool From f1267f855e15141fb43c3e4a4e5a9cdaa692f807 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 12:54:55 +0100 Subject: [PATCH 1204/1623] [nrf fromtree] arch: riscv: idle: trace idle and call wfi While going to idle may require SoC specific implementations, provide a more sensible default implementation. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 5fb6e267f629dedb8382da6bcad8018b1bb8930a) --- arch/riscv/core/cpu_idle.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/riscv/core/cpu_idle.c b/arch/riscv/core/cpu_idle.c index 0c7f5f3dac7..0d8e4fedeb2 100644 --- a/arch/riscv/core/cpu_idle.c +++ b/arch/riscv/core/cpu_idle.c @@ -5,24 +5,18 @@ */ #include - -/* - * In RISC-V there is no conventional way to handle CPU power save. - * Each RISC-V SOC handles it in its own way. - * Hence, by default, arch_cpu_idle and arch_cpu_atomic_idle functions just - * unlock interrupts and return to the caller, without issuing any CPU power - * saving instruction. - * - * Nonetheless, define the default arch_cpu_idle and arch_cpu_atomic_idle - * functions as weak functions, so that they can be replaced at the SOC-level. - */ +#include void __weak arch_cpu_idle(void) { + sys_trace_idle(); irq_unlock(MSTATUS_IEN); + __asm__ volatile("wfi"); } void __weak arch_cpu_atomic_idle(unsigned int key) { + sys_trace_idle(); irq_unlock(key); + __asm__ volatile("wfi"); } From 44bd379ddbea148f0057f6cae8ba83a37a983303 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 12:56:27 +0100 Subject: [PATCH 1205/1623] [nrf fromtree] soc: riscv: espressif_esp32: use arch idle It is equivalent to the provided custom implementation. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 1dbcef9d3c98dc84148572d91600a4a87e69cc93) --- .../espressif_esp32/esp32c3/CMakeLists.txt | 1 - soc/riscv/espressif_esp32/esp32c3/idle.c | 27 ------------------- 2 files changed, 28 deletions(-) delete mode 100644 soc/riscv/espressif_esp32/esp32c3/idle.c diff --git a/soc/riscv/espressif_esp32/esp32c3/CMakeLists.txt b/soc/riscv/espressif_esp32/esp32c3/CMakeLists.txt index e97f71751ef..d6772eacbfc 100644 --- a/soc/riscv/espressif_esp32/esp32c3/CMakeLists.txt +++ b/soc/riscv/espressif_esp32/esp32c3/CMakeLists.txt @@ -1,7 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_sources( - idle.c vectors.S soc_irq.S soc_irq.c diff --git a/soc/riscv/espressif_esp32/esp32c3/idle.c b/soc/riscv/espressif_esp32/esp32c3/idle.c deleted file mode 100644 index 1bfb2832187..00000000000 --- a/soc/riscv/espressif_esp32/esp32c3/idle.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -/** - * @brief Power save idle routine - * - * This function will be called by the kernel idle loop or possibly within - * an implementation of _pm_save_idle in the kernel when the - * '_pm_save_flag' variable is non-zero. - */ -void arch_cpu_idle(void) -{ - /* curiously it arrives here with the interrupts masked - * so umask it before wait for an event - */ - arch_irq_unlock(MSTATUS_IEN); - - /* Wait for interrupt */ - __asm__ volatile("wfi"); -} From 4a6f191b29bb7e174570204dcba12a1d892cdabb Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 12:57:35 +0100 Subject: [PATCH 1206/1623] [nrf fromtree] soc: riscv: riscv-privileged: remove redundant idle implementation Default RISC-V arch level implementation is equivalent. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 7631e0ddfaa9ff2f286fb11983cbab2db510f900) --- soc/riscv/common/riscv-privileged/idle.c | 53 ------------------------ 1 file changed, 53 deletions(-) delete mode 100644 soc/riscv/common/riscv-privileged/idle.c diff --git a/soc/riscv/common/riscv-privileged/idle.c b/soc/riscv/common/riscv-privileged/idle.c deleted file mode 100644 index e61ce72b280..00000000000 --- a/soc/riscv/common/riscv-privileged/idle.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2017 Jean-Paul Etienne - * Contributors: 2018 Antmicro - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include - -static ALWAYS_INLINE void riscv_idle(unsigned int key) -{ - sys_trace_idle(); - /* unlock interrupts */ - irq_unlock(key); - - /* Wait for interrupt */ - __asm__ volatile("wfi"); -} - -/** - * @brief Power save idle routine - * - * This function will be called by the kernel idle loop or possibly within - * an implementation of _pm_save_idle in the kernel when the - * '_pm_save_flag' variable is non-zero. - */ -void arch_cpu_idle(void) -{ - riscv_idle(MSTATUS_IEN); -} - -/** - * @brief Atomically re-enable interrupts and enter low power mode - * - * INTERNAL - * The requirements for arch_cpu_atomic_idle() are as follows: - * 1) The enablement of interrupts and entering a low-power mode needs to be - * atomic, i.e. there should be no period of time where interrupts are - * enabled before the processor enters a low-power mode. See the comments - * in k_lifo_get(), for example, of the race condition that - * occurs if this requirement is not met. - * - * 2) After waking up from the low-power mode, the interrupt lockout state - * must be restored as indicated in the 'imask' input parameter. - */ -void arch_cpu_atomic_idle(unsigned int key) -{ - riscv_idle(key); -} From b1f37d65806ffb636e4a06fd08726f7a89f9fea5 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 13:05:28 +0100 Subject: [PATCH 1207/1623] [nrf fromtree] arch: riscv: drop RISCV_HAS_CPU_IDLE Because it was exclusively used by the "common" RISC-V privileged code to build CPU idle routines that are now handled by arch level code. Also, all platforms defaulted to "y", making it pointless in practice. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit f885763b507a29431c5b6dbdb44a410ec88c76bf) --- arch/riscv/Kconfig | 5 ----- soc/riscv/andes_v5/ae350/Kconfig.defconfig.series | 3 --- soc/riscv/efinix_sapphire/Kconfig.defconfig | 4 ---- soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 | 3 --- soc/riscv/intel_niosv/niosv/Kconfig.defconfig.series | 3 --- soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.series | 3 --- soc/riscv/litex_vexriscv/Kconfig.defconfig | 3 --- soc/riscv/microchip_miv/miv/Kconfig.defconfig.series | 3 --- soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series | 3 --- soc/riscv/neorv32/Kconfig.defconfig | 3 --- soc/riscv/opentitan/Kconfig.defconfig | 3 --- soc/riscv/renode_virt/Kconfig.defconfig | 3 --- soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series | 3 --- soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series | 3 --- soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series | 3 --- soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series | 3 --- soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series | 4 ---- soc/riscv/virt/Kconfig.defconfig | 3 --- tests/kernel/context/src/main.c | 7 +++---- 19 files changed, 3 insertions(+), 62 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 80249670d09..60d33b18071 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -174,11 +174,6 @@ config RISCV_GENERIC_TOOLCHAIN Allow SOCs that have custom extended riscv ISA to still compile with generic riscv32 toolchain. -config RISCV_HAS_CPU_IDLE - bool "Does SOC has CPU IDLE instruction" - help - Does SOC has CPU IDLE instruction - config GEN_ISR_TABLES default y diff --git a/soc/riscv/andes_v5/ae350/Kconfig.defconfig.series b/soc/riscv/andes_v5/ae350/Kconfig.defconfig.series index 7bd679e5f45..699e54e66b8 100644 --- a/soc/riscv/andes_v5/ae350/Kconfig.defconfig.series +++ b/soc/riscv/andes_v5/ae350/Kconfig.defconfig.series @@ -24,9 +24,6 @@ config RISCV_GENERIC_TOOLCHAIN config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_CPU_IDLE - default y - config RISCV_HAS_PLIC default y diff --git a/soc/riscv/efinix_sapphire/Kconfig.defconfig b/soc/riscv/efinix_sapphire/Kconfig.defconfig index 7018c0f11fb..08e2c851a21 100644 --- a/soc/riscv/efinix_sapphire/Kconfig.defconfig +++ b/soc/riscv/efinix_sapphire/Kconfig.defconfig @@ -9,10 +9,6 @@ config SOC config SYS_CLOCK_HW_CYCLES_PER_SEC default 100000000 -config RISCV_HAS_CPU_IDLE - bool - default y - config RISCV_SOC_INTERRUPT_INIT bool default y diff --git a/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 b/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 index 1e93f2703b2..4d65e4c43cd 100644 --- a/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 +++ b/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 @@ -20,9 +20,6 @@ config RISCV_SOC_MCAUSE_EXCEPTION_MASK config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_CPU_IDLE - default y - config RISCV_GP default y diff --git a/soc/riscv/intel_niosv/niosv/Kconfig.defconfig.series b/soc/riscv/intel_niosv/niosv/Kconfig.defconfig.series index 8e8ea255202..15e98314c89 100644 --- a/soc/riscv/intel_niosv/niosv/Kconfig.defconfig.series +++ b/soc/riscv/intel_niosv/niosv/Kconfig.defconfig.series @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config NUM_IRQS # Platform interrupts IRQs index start from index 16 default 32 -config RISCV_HAS_CPU_IDLE - default y - config RISCV_GP default y diff --git a/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.series b/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.series index 7c5bc0ee897..0ed7358b631 100644 --- a/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.series +++ b/soc/riscv/ite_ec/it8xxx2/Kconfig.defconfig.series @@ -22,9 +22,6 @@ config UART_NS16550_WA_ISR_REENABLE_INTERRUPT default y depends on UART_NS16550 -config RISCV_HAS_CPU_IDLE - default y - config FLASH_INIT_PRIORITY default 0 diff --git a/soc/riscv/litex_vexriscv/Kconfig.defconfig b/soc/riscv/litex_vexriscv/Kconfig.defconfig index 3efdf200ee7..f3e4c7cc79c 100644 --- a/soc/riscv/litex_vexriscv/Kconfig.defconfig +++ b/soc/riscv/litex_vexriscv/Kconfig.defconfig @@ -9,9 +9,6 @@ config SOC config SYS_CLOCK_HW_CYCLES_PER_SEC default 100000000 -config RISCV_HAS_CPU_IDLE - bool - config RISCV_HAS_PLIC bool diff --git a/soc/riscv/microchip_miv/miv/Kconfig.defconfig.series b/soc/riscv/microchip_miv/miv/Kconfig.defconfig.series index ef161321a5b..fc5aaa7c186 100644 --- a/soc/riscv/microchip_miv/miv/Kconfig.defconfig.series +++ b/soc/riscv/microchip_miv/miv/Kconfig.defconfig.series @@ -11,9 +11,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_CPU_IDLE - default y - config RISCV_HAS_PLIC default y diff --git a/soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series b/soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series index 0e5629927ae..f41ae867153 100644 --- a/soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series +++ b/soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series @@ -14,9 +14,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_CPU_IDLE - default y - config RISCV_HAS_PLIC default y diff --git a/soc/riscv/neorv32/Kconfig.defconfig b/soc/riscv/neorv32/Kconfig.defconfig index 86aed551f5d..bc37ea74727 100644 --- a/soc/riscv/neorv32/Kconfig.defconfig +++ b/soc/riscv/neorv32/Kconfig.defconfig @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config NUM_IRQS default 32 -config RISCV_HAS_CPU_IDLE - default y - config RISCV_GP default y diff --git a/soc/riscv/opentitan/Kconfig.defconfig b/soc/riscv/opentitan/Kconfig.defconfig index cc27b7ffd6b..4ec6bffc4e7 100644 --- a/soc/riscv/opentitan/Kconfig.defconfig +++ b/soc/riscv/opentitan/Kconfig.defconfig @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_CPU_IDLE - default y - config RISCV_HAS_PLIC default y diff --git a/soc/riscv/renode_virt/Kconfig.defconfig b/soc/riscv/renode_virt/Kconfig.defconfig index 89e226edbb1..5d2cd649b0b 100644 --- a/soc/riscv/renode_virt/Kconfig.defconfig +++ b/soc/riscv/renode_virt/Kconfig.defconfig @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_CPU_IDLE - default y - config RISCV_HAS_PLIC default y diff --git a/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series b/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series index b2f16e5261d..661fe4ba1eb 100644 --- a/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series +++ b/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_CPU_IDLE - default y - config RISCV_HAS_PLIC default y diff --git a/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series b/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series index d6b94678686..3db750cb1a6 100644 --- a/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series +++ b/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_CPU_IDLE - default y - config RISCV_HAS_PLIC default y diff --git a/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series b/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series index 347ac14b551..83165d58870 100644 --- a/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series +++ b/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_CPU_IDLE - default y - config RISCV_HAS_PLIC default y diff --git a/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series index 77436b593e1..2dc45e1f347 100644 --- a/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series +++ b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_CPU_IDLE - default y - config RISCV_HAS_PLIC default y diff --git a/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series index 23a78c9f0da..5b62959858e 100644 --- a/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series +++ b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series @@ -15,10 +15,6 @@ config RISCV_SOC_INTERRUPT_INIT bool default y -config RISCV_HAS_CPU_IDLE - bool - default y - config RISCV_HAS_PLIC bool default y diff --git a/soc/riscv/virt/Kconfig.defconfig b/soc/riscv/virt/Kconfig.defconfig index 9773586e922..e0982bc185b 100644 --- a/soc/riscv/virt/Kconfig.defconfig +++ b/soc/riscv/virt/Kconfig.defconfig @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_CPU_IDLE - default y - config RISCV_HAS_PLIC default y diff --git a/tests/kernel/context/src/main.c b/tests/kernel/context/src/main.c index 2e3ad1a36c9..a138e012280 100644 --- a/tests/kernel/context/src/main.c +++ b/tests/kernel/context/src/main.c @@ -72,11 +72,10 @@ extern const int32_t z_sys_timer_irq_for_test; #endif -/* Cortex-M1, Nios II, and RISCV without CONFIG_RISCV_HAS_CPU_IDLE - * do have a power saving instruction, so k_cpu_idle() returns immediately +/* Cortex-M1 and Nios II do have a power saving instruction, so k_cpu_idle() + * returns immediately */ -#if !defined(CONFIG_CPU_CORTEX_M1) && !defined(CONFIG_NIOS2) && \ - (!defined(CONFIG_RISCV) || defined(CONFIG_RISCV_HAS_CPU_IDLE)) +#if !defined(CONFIG_CPU_CORTEX_M1) && !defined(CONFIG_NIOS2) #define HAS_POWERSAVE_INSTRUCTION #endif From 8d3c0379e09ca9afd962109afc3c61becfa9e93d Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Wed, 13 Dec 2023 12:53:49 -0500 Subject: [PATCH 1208/1623] [nrf fromtree] arch: introduce arch_smp_init Introduce a new arch interface for intializing smp. Signed-off-by: Anas Nashif (cherry picked from commit 37f427a5c728855767bd77291f58f078ad4d0a4b) --- arch/arc/core/arc_smp.c | 5 ++--- arch/arm/core/cortex_a_r/smp.c | 4 ++-- arch/arm64/core/prep_c.c | 1 + arch/arm64/core/smp.c | 4 ++-- arch/riscv/core/smp.c | 5 ++--- arch/x86/core/intel64/irq.c | 6 +++++- arch/x86/core/prep_c.c | 2 +- include/zephyr/sys/arch_interface.h | 3 +++ 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/arc/core/arc_smp.c b/arch/arc/core/arc_smp.c index 9fb43c41152..1aa61be53f0 100644 --- a/arch/arc/core/arc_smp.c +++ b/arch/arc/core/arc_smp.c @@ -145,7 +145,7 @@ void arch_sched_ipi(void) } } -static int arc_smp_init(void) +int arch_smp_init(void) { struct arc_connect_bcr bcr; @@ -188,6 +188,5 @@ static int arc_smp_init(void) return 0; } - -SYS_INIT(arc_smp_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); +SYS_INIT(arch_smp_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); #endif diff --git a/arch/arm/core/cortex_a_r/smp.c b/arch/arm/core/cortex_a_r/smp.c index 2aeb36c1735..c17f2fa048f 100644 --- a/arch/arm/core/cortex_a_r/smp.c +++ b/arch/arm/core/cortex_a_r/smp.c @@ -245,7 +245,7 @@ void arch_sched_ipi(void) broadcast_ipi(SGI_SCHED_IPI); } -static int arm_smp_init(void) +int arch_smp_init(void) { cpu_map[0] = MPIDR_TO_CORE(GET_MPIDR()); @@ -259,6 +259,6 @@ static int arm_smp_init(void) return 0; } -SYS_INIT(arm_smp_init, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); +SYS_INIT(arch_smp_init, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); #endif diff --git a/arch/arm64/core/prep_c.c b/arch/arm64/core/prep_c.c index c12d5e7d1c4..510476d2ef7 100644 --- a/arch/arm64/core/prep_c.c +++ b/arch/arm64/core/prep_c.c @@ -69,6 +69,7 @@ void z_arm64_prep_c(void) CODE_UNREACHABLE; } + #if CONFIG_MP_MAX_NUM_CPUS > 1 extern FUNC_NORETURN void z_arm64_secondary_start(void); void z_arm64_secondary_prep_c(void) diff --git a/arch/arm64/core/smp.c b/arch/arm64/core/smp.c index e67032eb2a4..043e07eb305 100644 --- a/arch/arm64/core/smp.c +++ b/arch/arm64/core/smp.c @@ -279,7 +279,7 @@ void arch_spin_relax(void) } #endif -static int arm64_smp_init(void) +int arch_smp_init(void) { cpu_map[0] = MPIDR_TO_CORE(GET_MPIDR()); @@ -302,6 +302,6 @@ static int arm64_smp_init(void) return 0; } -SYS_INIT(arm64_smp_init, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); +SYS_INIT(arch_smp_init, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); #endif diff --git a/arch/riscv/core/smp.c b/arch/riscv/core/smp.c index 6154450e58d..3294f9006f3 100644 --- a/arch/riscv/core/smp.c +++ b/arch/riscv/core/smp.c @@ -151,7 +151,7 @@ void arch_spin_relax(void) } #endif -static int riscv_smp_init(void) +int arch_smp_init(void) { IRQ_CONNECT(RISCV_MACHINE_SOFT_IRQ, 0, ipi_handler, NULL, 0); @@ -159,6 +159,5 @@ static int riscv_smp_init(void) return 0; } - -SYS_INIT(riscv_smp_init, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); +SYS_INIT(arch_smp_init, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); #endif /* CONFIG_SMP */ diff --git a/arch/x86/core/intel64/irq.c b/arch/x86/core/intel64/irq.c index a7304271746..09b1961585c 100644 --- a/arch/x86/core/intel64/irq.c +++ b/arch/x86/core/intel64/irq.c @@ -14,6 +14,7 @@ #include #include #include +#include LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); @@ -154,7 +155,7 @@ void arch_irq_offload(irq_offload_routine_t routine, const void *parameter) #if defined(CONFIG_SMP) -void z_x86_ipi_setup(void) +int arch_smp_init(void) { /* * z_sched_ipi() doesn't have the same signature as a typical ISR, so @@ -166,8 +167,11 @@ void z_x86_ipi_setup(void) /* TLB shootdown handling */ x86_irq_funcs[CONFIG_TLB_IPI_VECTOR - IV_IRQS] = z_x86_tlb_ipi; + return 0; } +SYS_INIT(arch_smp_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); + /* * it is not clear exactly how/where/why to abstract this, as it * assumes the use of a local APIC (but there's no other mechanism). diff --git a/arch/x86/core/prep_c.c b/arch/x86/core/prep_c.c index ee095efe33d..8f7618495a9 100644 --- a/arch/x86/core/prep_c.c +++ b/arch/x86/core/prep_c.c @@ -74,7 +74,7 @@ FUNC_NORETURN void z_x86_prep_c(void *arg) #endif #if defined(CONFIG_SMP) - z_x86_ipi_setup(); + arch_smp_init(); #endif z_cstart(); diff --git a/include/zephyr/sys/arch_interface.h b/include/zephyr/sys/arch_interface.h index e694bce55cc..722bacd76d5 100644 --- a/include/zephyr/sys/arch_interface.h +++ b/include/zephyr/sys/arch_interface.h @@ -495,6 +495,9 @@ static inline uint32_t arch_proc_id(void); */ void arch_sched_ipi(void); + +int arch_smp_init(void); + #endif /* CONFIG_SMP */ /** From d8562de468436950c76ae4dac0a71cfed8033559 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Wed, 13 Dec 2023 13:23:56 -0500 Subject: [PATCH 1209/1623] [nrf fromtree] arch: ipi_handler -> sched_ipi_handler unifiy naming for ipi handler call and use the same signature everywhere. Signed-off-by: Anas Nashif (cherry picked from commit 17080d0215c906082f6b669d0f762241c50739eb) --- arch/riscv/core/smp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/riscv/core/smp.c b/arch/riscv/core/smp.c index 3294f9006f3..4e9cdb55f48 100644 --- a/arch/riscv/core/smp.c +++ b/arch/riscv/core/smp.c @@ -104,7 +104,7 @@ void z_riscv_flush_fpu_ipi(unsigned int cpu) } #endif -static void ipi_handler(const void *unused) +static void sched_ipi_handler(const void *unused) { ARG_UNUSED(unused); @@ -154,7 +154,7 @@ void arch_spin_relax(void) int arch_smp_init(void) { - IRQ_CONNECT(RISCV_MACHINE_SOFT_IRQ, 0, ipi_handler, NULL, 0); + IRQ_CONNECT(RISCV_MACHINE_SOFT_IRQ, 0, sched_ipi_handler, NULL, 0); irq_enable(RISCV_MACHINE_SOFT_IRQ); return 0; From 7714efd77be6352889afb4d7ebd21f516cc47f2f Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 15:38:15 +0100 Subject: [PATCH 1210/1623] [nrf fromtree] arch: riscv: define some RISC-V exception codes As defined in Table 3.6 of "The RISC-V Instruction Set Manual, Volume II: Privileged Architecture". Delete all spread definitions of the same, weirdly prefixed with "SOC". Signed-off-by: Gerard Marull-Paretas (cherry picked from commit fcbfe74df1a52a92c9f10d8aedb0f9199d92dbbf) --- arch/riscv/core/isr.S | 9 +++++---- include/zephyr/arch/riscv/irq.h | 15 ++++++++++++--- soc/riscv/common/riscv-privileged/soc_common.h | 4 ---- soc/riscv/espressif_esp32/esp32c3/soc.h | 5 +---- soc/riscv/ite_ec/common/soc_common.h | 3 --- soc/riscv/openisa_rv32m1/soc_ri5cy.h | 2 -- soc/riscv/openisa_rv32m1/soc_zero_riscy.h | 3 --- 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/arch/riscv/core/isr.S b/arch/riscv/core/isr.S index c36679ae6db..a4db1ff053b 100644 --- a/arch/riscv/core/isr.S +++ b/arch/riscv/core/isr.S @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "asm_macros.inc" @@ -298,18 +299,18 @@ no_fp: /* increment _current->arch.exception_depth */ and t0, t0, t2 /* - * If mcause == SOC_MCAUSE_ECALL_EXP, handle system call from + * If mcause == RISCV_EXC_ECALLM, handle system call from * kernel thread. */ - li t1, SOC_MCAUSE_ECALL_EXP + li t1, RISCV_EXC_ECALLM beq t0, t1, is_kernel_syscall #ifdef CONFIG_USERSPACE /* - * If mcause == SOC_MCAUSE_USER_ECALL_EXP, handle system call + * If mcause == RISCV_EXC_ECALLU, handle system call * for user mode thread. */ - li t1, SOC_MCAUSE_USER_ECALL_EXP + li t1, RISCV_EXC_ECALLU beq t0, t1, is_user_syscall #endif /* CONFIG_USERSPACE */ diff --git a/include/zephyr/arch/riscv/irq.h b/include/zephyr/arch/riscv/irq.h index 77c0d4057aa..2e3e813872e 100644 --- a/include/zephyr/arch/riscv/irq.h +++ b/include/zephyr/arch/riscv/irq.h @@ -14,16 +14,25 @@ #ifndef ZEPHYR_INCLUDE_ARCH_RISCV_IRQ_H_ #define ZEPHYR_INCLUDE_ARCH_RISCV_IRQ_H_ -#ifndef _ASMLANGUAGE - #ifdef __cplusplus extern "C" { #endif +#ifndef _ASMLANGUAGE #include #include #include #include +#endif /* !_ASMLANGUAGE */ + +/* Exceptions 0-15 (MCAUSE interrupt=0) */ + +/* Environment Call from U-mode */ +#define RISCV_EXC_ECALLU 8 +/** Environment Call from M-mode */ +#define RISCV_EXC_ECALLM 11 + +#ifndef _ASMLANGUAGE extern void arch_irq_enable(unsigned int irq); extern void arch_irq_disable(unsigned int irq); @@ -102,10 +111,10 @@ static inline void arch_isr_direct_footer(int swap) } \ static inline int name##_body(void) +#endif /* _ASMLANGUAGE */ #ifdef __cplusplus } #endif -#endif /* _ASMLANGUAGE */ #endif /* ZEPHYR_INCLUDE_ARCH_RISCV_IRQ_H_ */ diff --git a/soc/riscv/common/riscv-privileged/soc_common.h b/soc/riscv/common/riscv-privileged/soc_common.h index 79f458924c6..27eed85c684 100644 --- a/soc/riscv/common/riscv-privileged/soc_common.h +++ b/soc/riscv/common/riscv-privileged/soc_common.h @@ -16,10 +16,6 @@ #define RISCV_MACHINE_SOFT_IRQ 3 /* Machine Software Interrupt */ #define RISCV_MACHINE_EXT_IRQ 11 /* Machine External Interrupt */ -/* ECALL Exception numbers */ -#define SOC_MCAUSE_ECALL_EXP 11 /* Machine ECALL instruction */ -#define SOC_MCAUSE_USER_ECALL_EXP 8 /* User ECALL instruction */ - /* SOC-specific MCAUSE bitfields */ #ifdef CONFIG_64BIT /* Interrupt Mask */ diff --git a/soc/riscv/espressif_esp32/esp32c3/soc.h b/soc/riscv/espressif_esp32/esp32c3/soc.h index a3709819abc..4d8904c5b2a 100644 --- a/soc/riscv/espressif_esp32/esp32c3/soc.h +++ b/soc/riscv/espressif_esp32/esp32c3/soc.h @@ -21,12 +21,9 @@ #define RISCV_MACHINE_TIMER_IRQ 7 /* Machine Timer Interrupt */ #define RISCV_MACHINE_EXT_IRQ 11 /* Machine External Interrupt */ -/* ECALL Exception numbers */ -#define SOC_MCAUSE_ECALL_EXP 11 /* Machine ECALL instruction */ -#define SOC_MCAUSE_USER_ECALL_EXP 8 /* User ECALL instruction */ - /* Interrupt Mask */ #define SOC_MCAUSE_IRQ_MASK (1 << 31) + /* Exception code Mask */ #define SOC_MCAUSE_EXP_MASK 0x7FFFFFFF diff --git a/soc/riscv/ite_ec/common/soc_common.h b/soc/riscv/ite_ec/common/soc_common.h index 5b981783164..0504118199a 100644 --- a/soc/riscv/ite_ec/common/soc_common.h +++ b/soc/riscv/ite_ec/common/soc_common.h @@ -22,9 +22,6 @@ /* Exception code Mask */ #define SOC_MCAUSE_EXP_MASK 0x7FFFFFFF -/* Exception code of environment call from M-mode */ -#define SOC_MCAUSE_ECALL_EXP 11 - #ifndef _ASMLANGUAGE #ifdef CONFIG_HAS_ITE_INTC diff --git a/soc/riscv/openisa_rv32m1/soc_ri5cy.h b/soc/riscv/openisa_rv32m1/soc_ri5cy.h index 27ebcbe6f35..12a001defba 100644 --- a/soc/riscv/openisa_rv32m1/soc_ri5cy.h +++ b/soc/riscv/openisa_rv32m1/soc_ri5cy.h @@ -55,6 +55,4 @@ */ #define SOC_MCAUSE_EXP_MASK 0x1F -/* The ecall exception number. This is a standard value. */ -#define SOC_MCAUSE_ECALL_EXP 11 #endif /* SOC_RISCV32_OPENISA_RV32M1_SOC_RI5CY_H_ */ diff --git a/soc/riscv/openisa_rv32m1/soc_zero_riscy.h b/soc/riscv/openisa_rv32m1/soc_zero_riscy.h index d5fa48297f7..4453b3665f6 100644 --- a/soc/riscv/openisa_rv32m1/soc_zero_riscy.h +++ b/soc/riscv/openisa_rv32m1/soc_zero_riscy.h @@ -43,7 +43,4 @@ */ #define SOC_MCAUSE_EXP_MASK 0x1F -/* The ecall exception number. This is a standard value. */ -#define SOC_MCAUSE_ECALL_EXP 11 - #endif /* SOC_RISCV32_OPENISA_RV32M1_SOC_ZERO_RISCY_H_ */ From 66f9e1e7be188e61f3b3d3a2e028e9a897675d68 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 13:39:29 +0100 Subject: [PATCH 1211/1623] [nrf fromtree] soc: riscv: cleanup usage/definition of MCAUSE IRQ flag The MCAUSE register has the "Interrupt" flag defined defined at XLEN-1 position (31 for 32-bit, 63 for 64-bit). This is not an SoC specific option, and there's no need to expose it publicly. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit a364420b30f96df97cc7a50b4674eaee6ce2e918) --- include/zephyr/arch/riscv/irq.h | 6 ++++++ soc/riscv/common/riscv-privileged/soc_common.h | 9 --------- soc/riscv/common/riscv-privileged/soc_irq.S | 4 ++-- soc/riscv/espressif_esp32/esp32c3/soc.h | 3 --- soc/riscv/ite_ec/common/soc_common.h | 3 --- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/include/zephyr/arch/riscv/irq.h b/include/zephyr/arch/riscv/irq.h index 2e3e813872e..f0b1f88642d 100644 --- a/include/zephyr/arch/riscv/irq.h +++ b/include/zephyr/arch/riscv/irq.h @@ -32,6 +32,12 @@ extern "C" { /** Environment Call from M-mode */ #define RISCV_EXC_ECALLM 11 +#ifdef CONFIG_64BIT +#define RISCV_MCAUSE_IRQ_BIT (1 << 63) +#else +#define RISCV_MCAUSE_IRQ_BIT (1 << 31) +#endif + #ifndef _ASMLANGUAGE extern void arch_irq_enable(unsigned int irq); diff --git a/soc/riscv/common/riscv-privileged/soc_common.h b/soc/riscv/common/riscv-privileged/soc_common.h index 27eed85c684..8b993c8a946 100644 --- a/soc/riscv/common/riscv-privileged/soc_common.h +++ b/soc/riscv/common/riscv-privileged/soc_common.h @@ -16,15 +16,6 @@ #define RISCV_MACHINE_SOFT_IRQ 3 /* Machine Software Interrupt */ #define RISCV_MACHINE_EXT_IRQ 11 /* Machine External Interrupt */ -/* SOC-specific MCAUSE bitfields */ -#ifdef CONFIG_64BIT -/* Interrupt Mask */ -#define SOC_MCAUSE_IRQ_MASK (1 << 63) -#else -/* Interrupt Mask */ -#define SOC_MCAUSE_IRQ_MASK (1 << 31) -#endif - /* Exception code Mask */ #define SOC_MCAUSE_EXP_MASK CONFIG_RISCV_SOC_MCAUSE_EXCEPTION_MASK diff --git a/soc/riscv/common/riscv-privileged/soc_irq.S b/soc/riscv/common/riscv-privileged/soc_irq.S index 73fc24431d5..377edbf600d 100644 --- a/soc/riscv/common/riscv-privileged/soc_irq.S +++ b/soc/riscv/common/riscv-privileged/soc_irq.S @@ -12,7 +12,7 @@ #include #include #include -#include +#include /* * __soc_handle_irq is defined as .weak to allow re-implementation by @@ -48,7 +48,7 @@ WTEXT(__soc_is_irq) SECTION_FUNC(exception.other, __soc_is_irq) /* Read mcause and check if interrupt bit is set */ csrr t0, mcause - li t1, SOC_MCAUSE_IRQ_MASK + li t1, RISCV_MCAUSE_IRQ_BIT and t0, t0, t1 /* If interrupt bit is not set, return with 0 */ diff --git a/soc/riscv/espressif_esp32/esp32c3/soc.h b/soc/riscv/espressif_esp32/esp32c3/soc.h index 4d8904c5b2a..6f6c9263da2 100644 --- a/soc/riscv/espressif_esp32/esp32c3/soc.h +++ b/soc/riscv/espressif_esp32/esp32c3/soc.h @@ -21,9 +21,6 @@ #define RISCV_MACHINE_TIMER_IRQ 7 /* Machine Timer Interrupt */ #define RISCV_MACHINE_EXT_IRQ 11 /* Machine External Interrupt */ -/* Interrupt Mask */ -#define SOC_MCAUSE_IRQ_MASK (1 << 31) - /* Exception code Mask */ #define SOC_MCAUSE_EXP_MASK 0x7FFFFFFF diff --git a/soc/riscv/ite_ec/common/soc_common.h b/soc/riscv/ite_ec/common/soc_common.h index 0504118199a..b50f16df0fb 100644 --- a/soc/riscv/ite_ec/common/soc_common.h +++ b/soc/riscv/ite_ec/common/soc_common.h @@ -16,9 +16,6 @@ /* SOC-specific MCAUSE bitfields */ -/* Interrupt Mask. 1 (interrupt) or 0 (exception) */ -#define SOC_MCAUSE_IRQ_MASK BIT(31) - /* Exception code Mask */ #define SOC_MCAUSE_EXP_MASK 0x7FFFFFFF From 3df1eadf7e1cf8d712d938bcb6c39eed009ae7d6 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 15:50:18 +0100 Subject: [PATCH 1212/1623] [nrf fromtree] soc: riscv: gd32vf103: simplify MCAUSE exception mask handling The exception mask needs to cover MCAUSE bits 11:0, there's no need to overengineer this setting using DT properties. Ref. https://doc.nucleisys.com/nuclei_spec/isa/core_csr.html#mcause Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 6edb0624d8549339ed08dfeb19fe471be556d3ff) --- dts/bindings/cpu/nuclei,bumblebee.yaml | 6 ------ dts/riscv/gigadevice/gd32vf103.dtsi | 1 - soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 | 2 +- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/dts/bindings/cpu/nuclei,bumblebee.yaml b/dts/bindings/cpu/nuclei,bumblebee.yaml index 8c9dfc7d35d..96eebcd0fb8 100644 --- a/dts/bindings/cpu/nuclei,bumblebee.yaml +++ b/dts/bindings/cpu/nuclei,bumblebee.yaml @@ -6,9 +6,3 @@ description: Nuclei Bumblebee RISC-V Core compatible: "nuclei,bumblebee" include: riscv,cpus.yaml - -properties: - mcause-exception-mask: - type: int - required: true - description: Specify the bits to use for exception code in mcause register. diff --git a/dts/riscv/gigadevice/gd32vf103.dtsi b/dts/riscv/gigadevice/gd32vf103.dtsi index c9f37db5180..b52aee61fbc 100644 --- a/dts/riscv/gigadevice/gd32vf103.dtsi +++ b/dts/riscv/gigadevice/gd32vf103.dtsi @@ -23,7 +23,6 @@ cpu: cpu@0 { clock-frequency = ; - mcause-exception-mask = <0x7ff>; compatible = "nuclei,bumblebee"; riscv,isa = "rv32imac_zicsr_zifencei"; reg = <0>; diff --git a/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 b/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 index 4d65e4c43cd..ade07b45635 100644 --- a/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 +++ b/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 @@ -15,7 +15,7 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC default 27000000 config RISCV_SOC_MCAUSE_EXCEPTION_MASK - default $(dt_node_int_prop_hex,/cpus/cpu@0,mcause-exception-mask) + default 0xFFF config RISCV_SOC_INTERRUPT_INIT default y From d6a51f75244642b5afc4e152c19b2536b5f01f2e Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 15:53:24 +0100 Subject: [PATCH 1213/1623] [nrf fromtree] arch: riscv: remove SOC from RISCV_SOC_MCAUSE_EXCEPTION_MASK Just to stay consistent with other RISC-V related settings. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit ee6097795855c8752d2060f8cb5a5cad0d7b7dd3) --- arch/riscv/Kconfig | 2 +- soc/riscv/common/riscv-privileged/soc_common.h | 2 +- soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 60d33b18071..1c5defbacaf 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -159,7 +159,7 @@ config RISCV_SOC_INTERRUPT_INIT Enable SOC-based interrupt initialization (call soc_interrupt_init, within _IntLibInit when enabled) -config RISCV_SOC_MCAUSE_EXCEPTION_MASK +config RISCV_MCAUSE_EXCEPTION_MASK hex default 0x7FFFFFFFFFFFFFFF if 64BIT default 0x7FFFFFFF diff --git a/soc/riscv/common/riscv-privileged/soc_common.h b/soc/riscv/common/riscv-privileged/soc_common.h index 8b993c8a946..6e75d4acf06 100644 --- a/soc/riscv/common/riscv-privileged/soc_common.h +++ b/soc/riscv/common/riscv-privileged/soc_common.h @@ -17,7 +17,7 @@ #define RISCV_MACHINE_EXT_IRQ 11 /* Machine External Interrupt */ /* Exception code Mask */ -#define SOC_MCAUSE_EXP_MASK CONFIG_RISCV_SOC_MCAUSE_EXCEPTION_MASK +#define SOC_MCAUSE_EXP_MASK CONFIG_RISCV_MCAUSE_EXCEPTION_MASK #ifndef _ASMLANGUAGE diff --git a/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 b/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 index ade07b45635..0da92e80e36 100644 --- a/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 +++ b/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 @@ -14,7 +14,7 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC # The CPU frequency is set to the maximum value of 108MHz by default. default 27000000 -config RISCV_SOC_MCAUSE_EXCEPTION_MASK +config RISCV_MCAUSE_EXCEPTION_MASK default 0xFFF config RISCV_SOC_INTERRUPT_INIT From 326c5229ff4931933cb3e4e44560df2af356cff5 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 16:11:51 +0100 Subject: [PATCH 1214/1623] [nrf fromtree] arch: riscv: use CONFIG_RISCV_MCAUSE_EXCEPTION_MASK Instead of custom SOC_MCAUSE_EXP_MASK definition. Note that SoCs selecting RISCV_PRIVILEGED already used such config indirectly (see changes in soc_common.h). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 452a2f67cdac4d076a481f584d0f7d658e806cde) --- arch/riscv/core/fatal.c | 2 +- arch/riscv/core/irq_manage.c | 2 +- arch/riscv/core/isr.S | 4 ++-- include/zephyr/arch/riscv/irq.h | 2 +- soc/riscv/common/riscv-privileged/soc_common.h | 3 --- soc/riscv/espressif_esp32/esp32c3/soc.h | 3 --- soc/riscv/ite_ec/common/soc_common.h | 5 ----- soc/riscv/openisa_rv32m1/Kconfig.defconfig | 3 +++ soc/riscv/openisa_rv32m1/soc_ri5cy.h | 15 --------------- soc/riscv/openisa_rv32m1/soc_zero_riscy.h | 15 --------------- 10 files changed, 8 insertions(+), 46 deletions(-) diff --git a/arch/riscv/core/fatal.c b/arch/riscv/core/fatal.c index 171497ff0ca..6e8831f1026 100644 --- a/arch/riscv/core/fatal.c +++ b/arch/riscv/core/fatal.c @@ -167,7 +167,7 @@ void _Fault(z_arch_esf_t *esf) __asm__ volatile("csrr %0, mtval" : "=r" (mtval)); #endif - mcause &= SOC_MCAUSE_EXP_MASK; + mcause &= CONFIG_RISCV_MCAUSE_EXCEPTION_MASK; LOG_ERR(""); LOG_ERR(" mcause: %ld, %s", mcause, cause_str(mcause)); #ifndef CONFIG_SOC_OPENISA_RV32M1_RISCV32 diff --git a/arch/riscv/core/irq_manage.c b/arch/riscv/core/irq_manage.c index e0ef1374bf1..6ed5781c731 100644 --- a/arch/riscv/core/irq_manage.c +++ b/arch/riscv/core/irq_manage.c @@ -20,7 +20,7 @@ FUNC_NORETURN void z_irq_spurious(const void *unused) mcause = csr_read(mcause); - mcause &= SOC_MCAUSE_EXP_MASK; + mcause &= CONFIG_RISCV_MCAUSE_EXCEPTION_MASK; LOG_ERR("Spurious interrupt detected! IRQ: %ld", mcause); #if defined(CONFIG_RISCV_HAS_PLIC) diff --git a/arch/riscv/core/isr.S b/arch/riscv/core/isr.S index a4db1ff053b..558d2a41fbe 100644 --- a/arch/riscv/core/isr.S +++ b/arch/riscv/core/isr.S @@ -295,7 +295,7 @@ no_fp: /* increment _current->arch.exception_depth */ * to report the exception. */ csrr t0, mcause - li t2, SOC_MCAUSE_EXP_MASK + li t2, CONFIG_RISCV_MCAUSE_EXCEPTION_MASK and t0, t0, t2 /* @@ -528,7 +528,7 @@ on_irq_stack: /* Get IRQ causing interrupt */ csrr a0, mcause - li t0, SOC_MCAUSE_EXP_MASK + li t0, CONFIG_RISCV_MCAUSE_EXCEPTION_MASK and a0, a0, t0 /* diff --git a/include/zephyr/arch/riscv/irq.h b/include/zephyr/arch/riscv/irq.h index f0b1f88642d..d4dfd54d92a 100644 --- a/include/zephyr/arch/riscv/irq.h +++ b/include/zephyr/arch/riscv/irq.h @@ -91,7 +91,7 @@ static inline void arch_isr_direct_footer(int swap) /* Get the IRQ number */ __asm__ volatile("csrr %0, mcause" : "=r" (mcause)); - mcause &= SOC_MCAUSE_EXP_MASK; + mcause &= CONFIG_RISCV_MCAUSE_EXCEPTION_MASK; /* Clear the pending IRQ */ __soc_handle_irq(mcause); diff --git a/soc/riscv/common/riscv-privileged/soc_common.h b/soc/riscv/common/riscv-privileged/soc_common.h index 6e75d4acf06..01a6b783850 100644 --- a/soc/riscv/common/riscv-privileged/soc_common.h +++ b/soc/riscv/common/riscv-privileged/soc_common.h @@ -16,9 +16,6 @@ #define RISCV_MACHINE_SOFT_IRQ 3 /* Machine Software Interrupt */ #define RISCV_MACHINE_EXT_IRQ 11 /* Machine External Interrupt */ -/* Exception code Mask */ -#define SOC_MCAUSE_EXP_MASK CONFIG_RISCV_MCAUSE_EXCEPTION_MASK - #ifndef _ASMLANGUAGE #include diff --git a/soc/riscv/espressif_esp32/esp32c3/soc.h b/soc/riscv/espressif_esp32/esp32c3/soc.h index 6f6c9263da2..8076f2ae045 100644 --- a/soc/riscv/espressif_esp32/esp32c3/soc.h +++ b/soc/riscv/espressif_esp32/esp32c3/soc.h @@ -21,9 +21,6 @@ #define RISCV_MACHINE_TIMER_IRQ 7 /* Machine Timer Interrupt */ #define RISCV_MACHINE_EXT_IRQ 11 /* Machine External Interrupt */ -/* Exception code Mask */ -#define SOC_MCAUSE_EXP_MASK 0x7FFFFFFF - #ifndef _ASMLANGUAGE void __esp_platform_start(void); diff --git a/soc/riscv/ite_ec/common/soc_common.h b/soc/riscv/ite_ec/common/soc_common.h index b50f16df0fb..b7e0cdd5e55 100644 --- a/soc/riscv/ite_ec/common/soc_common.h +++ b/soc/riscv/ite_ec/common/soc_common.h @@ -14,11 +14,6 @@ #include "chip_chipregs.h" -/* SOC-specific MCAUSE bitfields */ - -/* Exception code Mask */ -#define SOC_MCAUSE_EXP_MASK 0x7FFFFFFF - #ifndef _ASMLANGUAGE #ifdef CONFIG_HAS_ITE_INTC diff --git a/soc/riscv/openisa_rv32m1/Kconfig.defconfig b/soc/riscv/openisa_rv32m1/Kconfig.defconfig index 3976c9940c5..52d652a061e 100644 --- a/soc/riscv/openisa_rv32m1/Kconfig.defconfig +++ b/soc/riscv/openisa_rv32m1/Kconfig.defconfig @@ -33,6 +33,9 @@ config RISCV_SOC_OFFSETS config RISCV_SOC_INTERRUPT_INIT default y +config RISCV_MCAUSE_EXCEPTION_MASK + default 0x1F + # We need to disable the watchdog out of reset, as it's enabled by # default. Use the WDOG_INIT hook for doing that. config WDOG_INIT diff --git a/soc/riscv/openisa_rv32m1/soc_ri5cy.h b/soc/riscv/openisa_rv32m1/soc_ri5cy.h index 12a001defba..d9158935e08 100644 --- a/soc/riscv/openisa_rv32m1/soc_ri5cy.h +++ b/soc/riscv/openisa_rv32m1/soc_ri5cy.h @@ -40,19 +40,4 @@ #define RI5CY_PRIVLV 0xC10 #define RI5CY_MHARTID 0xF14 -/* - * Map from SoC-specific configuration to generic Zephyr macros. - * - * These are expected by the code in arch/, and must be provided for - * the kernel to work (or even build at all). - * - * Some of these may also apply to ZERO-RISCY; needs investigation. - */ - -/* - * Exception code mask. Use of the bottom five bits is a subset of - * what the standard allocates (which is XLEN-1 bits). - */ -#define SOC_MCAUSE_EXP_MASK 0x1F - #endif /* SOC_RISCV32_OPENISA_RV32M1_SOC_RI5CY_H_ */ diff --git a/soc/riscv/openisa_rv32m1/soc_zero_riscy.h b/soc/riscv/openisa_rv32m1/soc_zero_riscy.h index 4453b3665f6..43cd144823a 100644 --- a/soc/riscv/openisa_rv32m1/soc_zero_riscy.h +++ b/soc/riscv/openisa_rv32m1/soc_zero_riscy.h @@ -28,19 +28,4 @@ #define ZERO_RISCY_PCMR 0x7A1U #define ZERO_RISCY_MHARTID 0xF14U -/* - * Map from SoC-specific configuration to generic Zephyr macros. - * - * These are expected by the code in arch/, and must be provided for - * the kernel to work (or even build at all). - * - * Some of these may also apply to ZERO-RISCY; needs investigation. - */ - -/* - * Exception code mask. Use of the bottom five bits is a subset of - * what the standard allocates (which is XLEN-1 bits). - */ -#define SOC_MCAUSE_EXP_MASK 0x1F - #endif /* SOC_RISCV32_OPENISA_RV32M1_SOC_ZERO_RISCY_H_ */ From 41738f5a2962ba98a74a970ff0d31f811656532b Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 16:25:05 +0100 Subject: [PATCH 1215/1623] [nrf fromtree] arch: riscv: define RISC_IRQ_MSOFT/MEXT Instead of relying on spread definitions within SoC files. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit c725c91d951874726392b60c4fd8137ca9d6b920) --- arch/riscv/core/irq_manage.c | 2 +- arch/riscv/core/smp.c | 7 ++++--- drivers/interrupt_controller/intc_swerv_pic.c | 5 +++-- drivers/interrupt_controller/intc_vexriscv_litex.c | 5 +++-- drivers/mbox/mbox_andes_plic_sw.c | 4 ++-- include/zephyr/arch/riscv/irq.h | 7 +++++++ soc/riscv/common/riscv-privileged/soc_common.h | 4 ---- soc/riscv/espressif_esp32/esp32c3/soc.h | 5 ----- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/arch/riscv/core/irq_manage.c b/arch/riscv/core/irq_manage.c index 6ed5781c731..f3e0cc09ab1 100644 --- a/arch/riscv/core/irq_manage.c +++ b/arch/riscv/core/irq_manage.c @@ -24,7 +24,7 @@ FUNC_NORETURN void z_irq_spurious(const void *unused) LOG_ERR("Spurious interrupt detected! IRQ: %ld", mcause); #if defined(CONFIG_RISCV_HAS_PLIC) - if (mcause == RISCV_MACHINE_EXT_IRQ) { + if (mcause == RISCV_IRQ_MEXT) { unsigned int save_irq = riscv_plic_get_irq(); const struct device *save_dev = riscv_plic_get_dev(); diff --git a/arch/riscv/core/smp.c b/arch/riscv/core/smp.c index 4e9cdb55f48..b0c2b98de81 100644 --- a/arch/riscv/core/smp.c +++ b/arch/riscv/core/smp.c @@ -9,6 +9,7 @@ #include #include #include +#include #include volatile struct { @@ -67,7 +68,7 @@ void z_riscv_secondary_cpu_init(int hartid) z_riscv_pmp_init(); #endif #ifdef CONFIG_SMP - irq_enable(RISCV_MACHINE_SOFT_IRQ); + irq_enable(RISCV_IRQ_MSOFT); #endif riscv_cpu_init[cpu_num].fn(riscv_cpu_init[cpu_num].arg); } @@ -154,8 +155,8 @@ void arch_spin_relax(void) int arch_smp_init(void) { - IRQ_CONNECT(RISCV_MACHINE_SOFT_IRQ, 0, sched_ipi_handler, NULL, 0); - irq_enable(RISCV_MACHINE_SOFT_IRQ); + IRQ_CONNECT(RISCV_IRQ_MSOFT, 0, sched_ipi_handler, NULL, 0); + irq_enable(RISCV_IRQ_MSOFT); return 0; } diff --git a/drivers/interrupt_controller/intc_swerv_pic.c b/drivers/interrupt_controller/intc_swerv_pic.c index 5c52ab49614..96eb248d27c 100644 --- a/drivers/interrupt_controller/intc_swerv_pic.c +++ b/drivers/interrupt_controller/intc_swerv_pic.c @@ -15,6 +15,7 @@ #include #include #include +#include #define SWERV_PIC_MAX_NUM CONFIG_NUM_IRQS #define SWERV_PIC_MAX_ID (SWERV_PIC_MAX_NUM + RISCV_MAX_GENERIC_IRQ) @@ -176,14 +177,14 @@ static int swerv_pic_init(const struct device *dev) __asm__ swerv_pic_writecsr(meicurpl, 0); /* Setup IRQ handler for SweRV PIC driver */ - IRQ_CONNECT(RISCV_MACHINE_EXT_IRQ, + IRQ_CONNECT(RISCV_IRQ_MEXT, 0, swerv_pic_irq_handler, NULL, 0); /* Enable IRQ for SweRV PIC driver */ - irq_enable(RISCV_MACHINE_EXT_IRQ); + irq_enable(RISCV_IRQ_MEXT); return 0; } diff --git a/drivers/interrupt_controller/intc_vexriscv_litex.c b/drivers/interrupt_controller/intc_vexriscv_litex.c index efec4d2478e..2d5d2233ab2 100644 --- a/drivers/interrupt_controller/intc_vexriscv_litex.c +++ b/drivers/interrupt_controller/intc_vexriscv_litex.c @@ -11,6 +11,7 @@ #include #include #include +#include #define IRQ_MASK DT_INST_REG_ADDR_BY_NAME(0, irq_mask) #define IRQ_PENDING DT_INST_REG_ADDR_BY_NAME(0, irq_pending) @@ -122,9 +123,9 @@ int arch_irq_is_enabled(unsigned int irq) static int vexriscv_litex_irq_init(const struct device *dev) { __asm__ volatile ("csrrs x0, mie, %0" - :: "r"(1 << RISCV_MACHINE_EXT_IRQ)); + :: "r"(1 << RISCV_IRQ_MEXT)); vexriscv_litex_irq_setie(1); - IRQ_CONNECT(RISCV_MACHINE_EXT_IRQ, 0, vexriscv_litex_irq_handler, + IRQ_CONNECT(RISCV_IRQ_MEXT, 0, vexriscv_litex_irq_handler, NULL, 0); return 0; diff --git a/drivers/mbox/mbox_andes_plic_sw.c b/drivers/mbox/mbox_andes_plic_sw.c index bc01da73a30..e2c287ae216 100644 --- a/drivers/mbox/mbox_andes_plic_sw.c +++ b/drivers/mbox/mbox_andes_plic_sw.c @@ -199,11 +199,11 @@ static void andes_plic_sw_irq_handler(const struct device *dev) static int mbox_andes_init(const struct device *dev) { /* Setup IRQ handler for PLIC SW driver */ - IRQ_CONNECT(RISCV_MACHINE_SOFT_IRQ, 1, + IRQ_CONNECT(RISCV_IRQ_MSOFT, 1, andes_plic_sw_irq_handler, DEVICE_DT_INST_GET(0), 0); #ifndef CONFIG_SMP - irq_enable(RISCV_MACHINE_SOFT_IRQ); + irq_enable(RISCV_IRQ_MSOFT); #endif return 0; } diff --git a/include/zephyr/arch/riscv/irq.h b/include/zephyr/arch/riscv/irq.h index d4dfd54d92a..84d3a4949a9 100644 --- a/include/zephyr/arch/riscv/irq.h +++ b/include/zephyr/arch/riscv/irq.h @@ -32,6 +32,13 @@ extern "C" { /** Environment Call from M-mode */ #define RISCV_EXC_ECALLM 11 +/* IRQs 0-15 (MCAUSE interrupt=1) */ + +/** Machine Software Interrupt */ +#define RISCV_IRQ_MSOFT 3 +/** Machine External Interrupt */ +#define RISCV_IRQ_MEXT 11 + #ifdef CONFIG_64BIT #define RISCV_MCAUSE_IRQ_BIT (1 << 63) #else diff --git a/soc/riscv/common/riscv-privileged/soc_common.h b/soc/riscv/common/riscv-privileged/soc_common.h index 01a6b783850..bf9600ab880 100644 --- a/soc/riscv/common/riscv-privileged/soc_common.h +++ b/soc/riscv/common/riscv-privileged/soc_common.h @@ -12,10 +12,6 @@ #ifndef __SOC_COMMON_H_ #define __SOC_COMMON_H_ -/* IRQ numbers */ -#define RISCV_MACHINE_SOFT_IRQ 3 /* Machine Software Interrupt */ -#define RISCV_MACHINE_EXT_IRQ 11 /* Machine External Interrupt */ - #ifndef _ASMLANGUAGE #include diff --git a/soc/riscv/espressif_esp32/esp32c3/soc.h b/soc/riscv/espressif_esp32/esp32c3/soc.h index 8076f2ae045..68fb6fdb1ce 100644 --- a/soc/riscv/espressif_esp32/esp32c3/soc.h +++ b/soc/riscv/espressif_esp32/esp32c3/soc.h @@ -16,11 +16,6 @@ #include "esp32c3/clk.h" #endif -/* IRQ numbers */ -#define RISCV_MACHINE_SOFT_IRQ 3 /* Machine Software Interrupt */ -#define RISCV_MACHINE_TIMER_IRQ 7 /* Machine Timer Interrupt */ -#define RISCV_MACHINE_EXT_IRQ 11 /* Machine External Interrupt */ - #ifndef _ASMLANGUAGE void __esp_platform_start(void); From 52e484037e39eb0cbe7d00e5d338bddbd16b5255 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 16:33:19 +0100 Subject: [PATCH 1216/1623] [nrf fromtree] arch: riscv: define local soc_interrupt_init prototypes Instead of relying on messy soc.h files which are included via a fragile chain of includes. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 0addc80d102175f40acb40c8a80101a6ff5d4913) --- arch/riscv/core/prep_c.c | 4 ++++ arch/riscv/core/smp.c | 4 ++++ soc/riscv/common/riscv-privileged/soc_common.h | 4 ---- soc/riscv/ite_ec/it8xxx2/soc.h | 4 ---- soc/riscv/openisa_rv32m1/soc.h | 2 -- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/arch/riscv/core/prep_c.c b/arch/riscv/core/prep_c.c index 8b9b118b24c..b486b4949d8 100644 --- a/arch/riscv/core/prep_c.c +++ b/arch/riscv/core/prep_c.c @@ -20,6 +20,10 @@ #include #include +#if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT) +void soc_interrupt_init(void); +#endif + /** * * @brief Prepare to and run C code diff --git a/arch/riscv/core/smp.c b/arch/riscv/core/smp.c index b0c2b98de81..928edb63d8f 100644 --- a/arch/riscv/core/smp.c +++ b/arch/riscv/core/smp.c @@ -23,6 +23,10 @@ volatile void *riscv_cpu_sp; extern void __start(void); +#if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT) +void soc_interrupt_init(void); +#endif + void arch_start_cpu(int cpu_num, k_thread_stack_t *stack, int sz, arch_cpustart_t fn, void *arg) { diff --git a/soc/riscv/common/riscv-privileged/soc_common.h b/soc/riscv/common/riscv-privileged/soc_common.h index bf9600ab880..f8f1c13cb59 100644 --- a/soc/riscv/common/riscv-privileged/soc_common.h +++ b/soc/riscv/common/riscv-privileged/soc_common.h @@ -17,10 +17,6 @@ #include #include -#if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT) -void soc_interrupt_init(void); -#endif - #endif /* !_ASMLANGUAGE */ #endif /* __SOC_COMMON_H_ */ diff --git a/soc/riscv/ite_ec/it8xxx2/soc.h b/soc/riscv/ite_ec/it8xxx2/soc.h index bc790768369..ea9d30d11fc 100644 --- a/soc/riscv/ite_ec/it8xxx2/soc.h +++ b/soc/riscv/ite_ec/it8xxx2/soc.h @@ -25,8 +25,4 @@ COND_CODE_1(DT_NODE_EXISTS(DT_INST(1, ite_it8xxx2_usbpd)), (2), (1)) */ #define SOC_USBPD_ITE_ACTIVE_PORT_COUNT DT_NUM_INST_STATUS_OKAY(ite_it8xxx2_usbpd) -#ifndef _ASMLANGUAGE -void soc_interrupt_init(void); -#endif - #endif /* __RISCV_ITE_SOC_H_ */ diff --git a/soc/riscv/openisa_rv32m1/soc.h b/soc/riscv/openisa_rv32m1/soc.h index 1b2643d0b66..75011d36283 100644 --- a/soc/riscv/openisa_rv32m1/soc.h +++ b/soc/riscv/openisa_rv32m1/soc.h @@ -94,8 +94,6 @@ static inline uint32_t rv32m1_intmux_line(unsigned int irq) return ((irq >> 8) & 0xff) - 1; } -void soc_interrupt_init(void); - #endif /* !_ASMLANGUAGE */ #if defined(CONFIG_SOC_OPENISA_RV32M1_RI5CY) From b39a1a74bfcce36b130f78f0aa079f48f43ad2e5 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 11 Jan 2024 10:42:51 +0100 Subject: [PATCH 1217/1623] [nrf fromtree] arch: riscv: irq_manage: add missing PLIC header Module uses RISC-V PLIC interrupt controller API without including the necessary headers. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 6252e8576c94a4ad7549d4c6180a3e0d3c8eb3a8) --- arch/riscv/core/irq_manage.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/riscv/core/irq_manage.c b/arch/riscv/core/irq_manage.c index f3e0cc09ab1..f95b099a4da 100644 --- a/arch/riscv/core/irq_manage.c +++ b/arch/riscv/core/irq_manage.c @@ -10,6 +10,10 @@ #include #include +#ifdef CONFIG_RISCV_HAS_PLIC +#include +#endif + LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); FUNC_NORETURN void z_irq_spurious(const void *unused) From 69388c7268d91c5e1ebf280c36a05bd2b741c11c Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 11 Jan 2024 11:31:24 +0100 Subject: [PATCH 1218/1623] [nrf fromtree] drivers: gpio: sifive: add missing PLIC header Driver is using the PLIC API without including the right header. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 36069b6c9aeb4971955fd2850457b6cdc42e9039) --- drivers/gpio/gpio_sifive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpio_sifive.c b/drivers/gpio/gpio_sifive.c index 77703f25707..a412fdd1528 100644 --- a/drivers/gpio/gpio_sifive.c +++ b/drivers/gpio/gpio_sifive.c @@ -18,7 +18,7 @@ #include #include #include - +#include #include typedef void (*sifive_cfg_func_t)(void); From 637e8eafcb3a32cd507e2ec2dfb8a5319ef3eeb4 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 11 Jan 2024 13:35:47 +0100 Subject: [PATCH 1219/1623] [nrf fromtree] drivers: gpio: b91: add missing PLIC header Driver is using the RISC-V PLIC interrupt controller without including the necessary headers. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 992f25b0c929cad7c1e26ef7cec72ae7823e396d) --- drivers/gpio/gpio_b91.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpio_b91.c b/drivers/gpio/gpio_b91.c index bc73f9db9f5..4c4c14dc909 100644 --- a/drivers/gpio/gpio_b91.c +++ b/drivers/gpio/gpio_b91.c @@ -10,6 +10,7 @@ #include #include #include +#include /* Driver dts compatibility: telink,b91_gpio */ From bbcb4f1e16c968e246bbc2ef59cf3fd64df69338 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 11 Jan 2024 20:00:37 +0100 Subject: [PATCH 1220/1623] [nrf fromtree] drivers: ieee802154: b91: add missing PLIC include Driver was using RISC-V PLIC API without including the necessary headers. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 87bb281a9f8692c8755edb58353085f6b7b4c3be) --- drivers/ieee802154/ieee802154_b91.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/ieee802154/ieee802154_b91.c b/drivers/ieee802154/ieee802154_b91.c index 0557c533944..0897b2b54df 100644 --- a/drivers/ieee802154/ieee802154_b91.c +++ b/drivers/ieee802154/ieee802154_b91.c @@ -26,6 +26,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #endif +#include + #include "ieee802154_b91.h" From 61e57d1d73bf7c68f1663ac90855af02adb27c53 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Fri, 12 Jan 2024 12:30:17 +0100 Subject: [PATCH 1221/1623] [nrf fromtree] drivers: serial: b91: add missing RISC-V PLIC header Driver was using PLIC without including necessary headers. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 3ed16b38e555a5b17469578b69e479e8434cd257) --- drivers/serial/uart_b91.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/serial/uart_b91.c b/drivers/serial/uart_b91.c index cb2d7ebd190..e2502f4fd9b 100644 --- a/drivers/serial/uart_b91.c +++ b/drivers/serial/uart_b91.c @@ -11,6 +11,7 @@ #include #include #include +#include /* Driver dts compatibility: telink,b91_uart */ From 593dad9bf06a597b3c8ed13f4d9d7da787eb3c1e Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 10 Jan 2024 16:38:50 +0100 Subject: [PATCH 1222/1623] [nrf fromtree] soc: riscv: riscv-privileged: drop soc_common.h The header file is no longer needed. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 6876f9eea1acce965be5ba8f7f786ee232e49029) --- soc/riscv/andes_v5/ae350/soc.h | 2 -- .../common/riscv-privileged/soc_common.h | 22 ------------------- soc/riscv/efinix_sapphire/soc.h | 1 - soc/riscv/gd_gd32/gd32vf103/soc.h | 2 -- soc/riscv/intel_niosv/niosv/soc.h | 1 - soc/riscv/litex_vexriscv/soc.h | 1 - soc/riscv/microchip_miv/miv/soc.h | 2 -- soc/riscv/microchip_miv/polarfire/soc.h | 1 - soc/riscv/neorv32/soc.h | 2 -- soc/riscv/opentitan/soc.h | 1 - soc/riscv/renode_virt/soc.h | 2 -- soc/riscv/sifive_freedom/e300/soc.h | 2 -- soc/riscv/sifive_freedom/u500/soc.h | 2 -- soc/riscv/sifive_freedom/u700/soc.h | 2 -- soc/riscv/starfive_jh71xx/jh71xx/soc.h | 2 -- soc/riscv/telink_tlsr/tlsr951x/soc.h | 2 -- soc/riscv/virt/soc.h | 2 -- 17 files changed, 49 deletions(-) delete mode 100644 soc/riscv/common/riscv-privileged/soc_common.h diff --git a/soc/riscv/andes_v5/ae350/soc.h b/soc/riscv/andes_v5/ae350/soc.h index 95ea7486fd3..fd3a9e63c0d 100644 --- a/soc/riscv/andes_v5/ae350/soc.h +++ b/soc/riscv/andes_v5/ae350/soc.h @@ -11,8 +11,6 @@ #ifndef __RISCV_ANDES_AE350_SOC_H_ #define __RISCV_ANDES_AE350_SOC_H_ -#include - /* Include CSRs available for Andes V5 SoCs */ #include "soc_v5.h" diff --git a/soc/riscv/common/riscv-privileged/soc_common.h b/soc/riscv/common/riscv-privileged/soc_common.h deleted file mode 100644 index f8f1c13cb59..00000000000 --- a/soc/riscv/common/riscv-privileged/soc_common.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2017 Jean-Paul Etienne - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file configuration macros for riscv SOCs supporting the riscv - * privileged architecture specification - */ - -#ifndef __SOC_COMMON_H_ -#define __SOC_COMMON_H_ - -#ifndef _ASMLANGUAGE - -#include -#include - -#endif /* !_ASMLANGUAGE */ - -#endif /* __SOC_COMMON_H_ */ diff --git a/soc/riscv/efinix_sapphire/soc.h b/soc/riscv/efinix_sapphire/soc.h index 1d566e2f293..5530af16729 100644 --- a/soc/riscv/efinix_sapphire/soc.h +++ b/soc/riscv/efinix_sapphire/soc.h @@ -7,7 +7,6 @@ #ifndef __RISCV32_EFINIX_SAPPHIRE_SOC_H_ #define __RISCV32_EFINIX_SAPPHIRE_SOC_H_ -#include "soc_common.h" #include #include diff --git a/soc/riscv/gd_gd32/gd32vf103/soc.h b/soc/riscv/gd_gd32/gd32vf103/soc.h index 14cdd6b733c..ad2add6fa80 100644 --- a/soc/riscv/gd_gd32/gd32vf103/soc.h +++ b/soc/riscv/gd_gd32/gd32vf103/soc.h @@ -11,6 +11,4 @@ #ifndef RISCV_GD32VF103_SOC_H_ #define RISCV_GD32VF103_SOC_H_ -#include - #endif /* RISCV_GD32VF103_SOC_H */ diff --git a/soc/riscv/intel_niosv/niosv/soc.h b/soc/riscv/intel_niosv/niosv/soc.h index 8c10fec4540..87458c91dff 100644 --- a/soc/riscv/intel_niosv/niosv/soc.h +++ b/soc/riscv/intel_niosv/niosv/soc.h @@ -7,7 +7,6 @@ #ifndef RISCV_INTEL_FPGA_NIOSV_H #define RISCV_INTEL_FPGA_NIOSV_H -#include #include #endif /* RISCV_INTEL_FPGA_NIOSV_H */ diff --git a/soc/riscv/litex_vexriscv/soc.h b/soc/riscv/litex_vexriscv/soc.h index b3521b51e8e..4334be4ec1c 100644 --- a/soc/riscv/litex_vexriscv/soc.h +++ b/soc/riscv/litex_vexriscv/soc.h @@ -7,7 +7,6 @@ #ifndef __RISCV32_LITEX_VEXRISCV_SOC_H_ #define __RISCV32_LITEX_VEXRISCV_SOC_H_ -#include "../common/riscv-privileged/soc_common.h" #include #include diff --git a/soc/riscv/microchip_miv/miv/soc.h b/soc/riscv/microchip_miv/miv/soc.h index 1608c9e6773..c5827ceed21 100644 --- a/soc/riscv/microchip_miv/miv/soc.h +++ b/soc/riscv/microchip_miv/miv/soc.h @@ -4,8 +4,6 @@ #ifndef __RISCV32_MIV_SOC_H_ #define __RISCV32_MIV_SOC_H_ -#include - /* UART Configuration */ #define MIV_UART_0_LINECFG 0x1 diff --git a/soc/riscv/microchip_miv/polarfire/soc.h b/soc/riscv/microchip_miv/polarfire/soc.h index d6a7d2d2e37..f12bea7d533 100644 --- a/soc/riscv/microchip_miv/polarfire/soc.h +++ b/soc/riscv/microchip_miv/polarfire/soc.h @@ -6,7 +6,6 @@ #ifndef __RISCV64_MPFS_SOC_H_ #define __RISCV64_MPFS_SOC_H_ -#include #include diff --git a/soc/riscv/neorv32/soc.h b/soc/riscv/neorv32/soc.h index a1e721923a4..a97daa0fc15 100644 --- a/soc/riscv/neorv32/soc.h +++ b/soc/riscv/neorv32/soc.h @@ -7,8 +7,6 @@ #ifndef RISCV_NEORV32_SOC_H #define RISCV_NEORV32_SOC_H -#include - /* System information (SYSINFO) register offsets */ #define NEORV32_SYSINFO_CLK 0x00U #define NEORV32_SYSINFO_CPU 0x04U diff --git a/soc/riscv/opentitan/soc.h b/soc/riscv/opentitan/soc.h index 13bb5c43b54..c7f75beb877 100644 --- a/soc/riscv/opentitan/soc.h +++ b/soc/riscv/opentitan/soc.h @@ -7,7 +7,6 @@ #ifndef __RISCV_OPENTITAN_SOC_H_ #define __RISCV_OPENTITAN_SOC_H_ -#include #include /* OpenTitan power management regs. */ diff --git a/soc/riscv/renode_virt/soc.h b/soc/riscv/renode_virt/soc.h index c82e16f1613..3edef49c88c 100644 --- a/soc/riscv/renode_virt/soc.h +++ b/soc/riscv/renode_virt/soc.h @@ -7,6 +7,4 @@ #ifndef __RISCV32_RENODE_SOC_H_ #define __RISCV32_RENODE_SOC_H_ -#include - #endif /* __RISCV32_RENODE_SOC_H_ */ diff --git a/soc/riscv/sifive_freedom/e300/soc.h b/soc/riscv/sifive_freedom/e300/soc.h index c83f5f322b6..3c29efb2a71 100644 --- a/soc/riscv/sifive_freedom/e300/soc.h +++ b/soc/riscv/sifive_freedom/e300/soc.h @@ -11,8 +11,6 @@ #ifndef __RISCV_SIFIVE_FREEDOM_FE300_SOC_H_ #define __RISCV_SIFIVE_FREEDOM_FE300_SOC_H_ -#include - /* PINMUX MAX PINS */ #define SIFIVE_PINMUX_PINS 32 diff --git a/soc/riscv/sifive_freedom/u500/soc.h b/soc/riscv/sifive_freedom/u500/soc.h index ed367950278..1e18850787b 100644 --- a/soc/riscv/sifive_freedom/u500/soc.h +++ b/soc/riscv/sifive_freedom/u500/soc.h @@ -11,8 +11,6 @@ #ifndef __RISCV_SIFIVE_FREEDOM_U500_SOC_H_ #define __RISCV_SIFIVE_FREEDOM_U500_SOC_H_ -#include - /* Clock controller. */ #define PRCI_BASE_ADDR 0x10000000 diff --git a/soc/riscv/sifive_freedom/u700/soc.h b/soc/riscv/sifive_freedom/u700/soc.h index 91aac61afdd..2f15ba3b1cb 100644 --- a/soc/riscv/sifive_freedom/u700/soc.h +++ b/soc/riscv/sifive_freedom/u700/soc.h @@ -11,8 +11,6 @@ #ifndef __RISCV_SIFIVE_FREEDOM_U700_SOC_H_ #define __RISCV_SIFIVE_FREEDOM_U700_SOC_H_ -#include - /* Clock controller. */ #define PRCI_BASE_ADDR 0x10000000 diff --git a/soc/riscv/starfive_jh71xx/jh71xx/soc.h b/soc/riscv/starfive_jh71xx/jh71xx/soc.h index 796f07201d9..df3559c96e3 100644 --- a/soc/riscv/starfive_jh71xx/jh71xx/soc.h +++ b/soc/riscv/starfive_jh71xx/jh71xx/soc.h @@ -7,6 +7,4 @@ #ifndef __RISCV_VIRT_SOC_H_ #define __RISCV_VIRT_SOC_H_ -#include - #endif diff --git a/soc/riscv/telink_tlsr/tlsr951x/soc.h b/soc/riscv/telink_tlsr/tlsr951x/soc.h index a46b4c620c7..6acfd63dd02 100644 --- a/soc/riscv/telink_tlsr/tlsr951x/soc.h +++ b/soc/riscv/telink_tlsr/tlsr951x/soc.h @@ -7,6 +7,4 @@ #ifndef RISCV_TELINK_B91_SOC_H #define RISCV_TELINK_B91_SOC_H -#include - #endif /* RISCV_TELINK_B91_SOC_H */ diff --git a/soc/riscv/virt/soc.h b/soc/riscv/virt/soc.h index 8fd5e2108ce..d821c4653e6 100644 --- a/soc/riscv/virt/soc.h +++ b/soc/riscv/virt/soc.h @@ -7,8 +7,6 @@ #ifndef __RISCV_VIRT_SOC_H_ #define __RISCV_VIRT_SOC_H_ -#include - #define SIFIVE_SYSCON_TEST 0x00100000 #define RISCV_MSIP_BASE 0x02000000 From a13732cc5088f56629abb421beef0f1a91265cde Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 18 Jan 2024 15:25:29 +0100 Subject: [PATCH 1223/1623] [nrf fromtree] arch: riscv: offsets: fix header race condition It looks like some soc_offsets.h files need to be included before kernel_offsets, otherwise there are some header race conditions due to the infamous soc.h. This problem is exposed if all soc.h are removed from RISC-V arch header files (see the upcoming commits). It can be reproduced by building rv32m1_vega_ri5cy board after applying all the patches in this series (excluding this one, of course). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 7af4f7eb8a2ca9cd2eb3e5b2d2c74f31d2b2263e) --- arch/riscv/core/offsets/offsets.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/core/offsets/offsets.c b/arch/riscv/core/offsets/offsets.c index 7730138a376..96982341b1a 100644 --- a/arch/riscv/core/offsets/offsets.c +++ b/arch/riscv/core/offsets/offsets.c @@ -16,7 +16,6 @@ #include #include #include -#include #ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE #include @@ -25,6 +24,8 @@ #include #endif +#include + /* struct _callee_saved member offsets */ GEN_OFFSET_SYM(_callee_saved_t, sp); GEN_OFFSET_SYM(_callee_saved_t, ra); From 5a328d5f8a3acee0c1d64e531af12e881ad34d98 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Tue, 16 Jan 2024 14:54:01 +0100 Subject: [PATCH 1224/1623] [nrf fromtree] arch: riscv: smp: define MSIP_BASE Instead of relying on definitions included indirectly. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit a5ded8aa9f75851931f1eb321a0e19790eb3181f) --- arch/riscv/core/smp.c | 3 ++- soc/riscv/microchip_miv/polarfire/soc.h | 3 --- soc/riscv/virt/soc.h | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/riscv/core/smp.c b/arch/riscv/core/smp.c index 928edb63d8f..99f67f57ecc 100644 --- a/arch/riscv/core/smp.c +++ b/arch/riscv/core/smp.c @@ -79,7 +79,8 @@ void z_riscv_secondary_cpu_init(int hartid) #ifdef CONFIG_SMP -#define MSIP(hartid) ((volatile uint32_t *)RISCV_MSIP_BASE)[hartid] +#define MSIP_BASE 0x2000000UL +#define MSIP(hartid) ((volatile uint32_t *)MSIP_BASE)[hartid] static atomic_val_t cpu_pending_ipi[CONFIG_MP_MAX_NUM_CPUS]; #define IPI_SCHED 0 diff --git a/soc/riscv/microchip_miv/polarfire/soc.h b/soc/riscv/microchip_miv/polarfire/soc.h index f12bea7d533..3bcb9569c6e 100644 --- a/soc/riscv/microchip_miv/polarfire/soc.h +++ b/soc/riscv/microchip_miv/polarfire/soc.h @@ -8,7 +8,4 @@ #include - -#define RISCV_MSIP_BASE 0x02000000 - #endif /* __RISCV64_MPFS_SOC_H_ */ diff --git a/soc/riscv/virt/soc.h b/soc/riscv/virt/soc.h index d821c4653e6..8aa4238010c 100644 --- a/soc/riscv/virt/soc.h +++ b/soc/riscv/virt/soc.h @@ -8,6 +8,5 @@ #define __RISCV_VIRT_SOC_H_ #define SIFIVE_SYSCON_TEST 0x00100000 -#define RISCV_MSIP_BASE 0x02000000 #endif From 0dd01f0067c19eedb2dc3b9a2f59ca118734a46d Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Tue, 16 Jan 2024 15:55:41 +0100 Subject: [PATCH 1225/1623] [nrf fromtree] soc: riscv: make RISCV_HAS_(C|P)LIC promptless These options are meant to be selected by SoC series supporting (C|P)LIC. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 2dcbb0ee3fbbc738f94c1ccea9761b42ee8b5b39) --- soc/riscv/andes_v5/ae350/Kconfig.defconfig.series | 3 --- soc/riscv/andes_v5/ae350/Kconfig.series | 1 + soc/riscv/common/riscv-privileged/Kconfig | 4 ++-- soc/riscv/efinix_sapphire/Kconfig.defconfig | 4 ---- soc/riscv/efinix_sapphire/Kconfig.soc | 1 + soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 | 3 --- soc/riscv/litex_vexriscv/Kconfig.defconfig | 3 --- soc/riscv/microchip_miv/miv/Kconfig.defconfig.series | 3 --- soc/riscv/microchip_miv/miv/Kconfig.series | 1 + soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series | 3 --- soc/riscv/microchip_miv/polarfire/Kconfig.series | 1 + soc/riscv/opentitan/Kconfig.defconfig | 3 --- soc/riscv/opentitan/Kconfig.soc | 1 + soc/riscv/renode_virt/Kconfig.defconfig | 3 --- soc/riscv/renode_virt/Kconfig.soc | 1 + soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series | 3 --- soc/riscv/sifive_freedom/e300/Kconfig.series | 1 + soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series | 3 --- soc/riscv/sifive_freedom/u500/Kconfig.series | 1 + soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series | 3 --- soc/riscv/sifive_freedom/u700/Kconfig.series | 1 + soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series | 3 --- soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series | 1 + soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series | 4 ---- soc/riscv/telink_tlsr/tlsr951x/Kconfig.series | 1 + soc/riscv/virt/Kconfig.defconfig | 3 --- soc/riscv/virt/Kconfig.soc | 1 + 27 files changed, 14 insertions(+), 46 deletions(-) diff --git a/soc/riscv/andes_v5/ae350/Kconfig.defconfig.series b/soc/riscv/andes_v5/ae350/Kconfig.defconfig.series index 699e54e66b8..7b9bbc3eadb 100644 --- a/soc/riscv/andes_v5/ae350/Kconfig.defconfig.series +++ b/soc/riscv/andes_v5/ae350/Kconfig.defconfig.series @@ -24,9 +24,6 @@ config RISCV_GENERIC_TOOLCHAIN config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_PLIC - default y - config RISCV_GP default y diff --git a/soc/riscv/andes_v5/ae350/Kconfig.series b/soc/riscv/andes_v5/ae350/Kconfig.series index ebf68f7a3aa..c2e9b40bfb7 100644 --- a/soc/riscv/andes_v5/ae350/Kconfig.series +++ b/soc/riscv/andes_v5/ae350/Kconfig.series @@ -5,6 +5,7 @@ config SOC_SERIES_ANDES_AE350 bool "Andes V5 AE350 SoC Series Implementation" select RISCV select RISCV_PRIVILEGED + select RISCV_HAS_PLIC select SOC_FAMILY_ANDES_V5 help Enable support for Andes V5 AE350 SoC Series diff --git a/soc/riscv/common/riscv-privileged/Kconfig b/soc/riscv/common/riscv-privileged/Kconfig index a4a8da0bf1f..016919c4661 100644 --- a/soc/riscv/common/riscv-privileged/Kconfig +++ b/soc/riscv/common/riscv-privileged/Kconfig @@ -5,13 +5,13 @@ # SPDX-License-Identifier: Apache-2.0 config RISCV_HAS_PLIC - bool "Does the SOC provide support for a Platform Level Interrupt Controller (PLIC)" + bool depends on RISCV_PRIVILEGED help Does the SOC provide support for a Platform Level Interrupt Controller (PLIC). config RISCV_HAS_CLIC - bool "Does the SOC provide support for a Core-Local Interrupt Controller (CLIC)" + bool depends on RISCV_PRIVILEGED help Does the SOC provide support for a Core-Local Interrupt Controller (CLIC). diff --git a/soc/riscv/efinix_sapphire/Kconfig.defconfig b/soc/riscv/efinix_sapphire/Kconfig.defconfig index 08e2c851a21..95a33b4ab82 100644 --- a/soc/riscv/efinix_sapphire/Kconfig.defconfig +++ b/soc/riscv/efinix_sapphire/Kconfig.defconfig @@ -13,10 +13,6 @@ config RISCV_SOC_INTERRUPT_INIT bool default y -config RISCV_HAS_PLIC - bool - default y - config NUM_IRQS int default 36 diff --git a/soc/riscv/efinix_sapphire/Kconfig.soc b/soc/riscv/efinix_sapphire/Kconfig.soc index bf57d9cc541..4bad3b5cb79 100644 --- a/soc/riscv/efinix_sapphire/Kconfig.soc +++ b/soc/riscv/efinix_sapphire/Kconfig.soc @@ -12,3 +12,4 @@ config SOC_EFINIX_SAPPHIRE select RISCV_ISA_EXT_ZIFENCEI select RISCV select RISCV_PRIVILEGED + select RISCV_HAS_PLIC diff --git a/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 b/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 index 0da92e80e36..94af3ff773c 100644 --- a/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 +++ b/soc/riscv/gd_gd32/gd32vf103/Kconfig.defconfig.gd32vf103 @@ -23,9 +23,6 @@ config RISCV_SOC_INTERRUPT_INIT config RISCV_GP default y -config RISCV_HAS_PLIC - default n - config NUM_IRQS default 87 if NUCLEI_ECLIC default 16 if !NUCLEI_ECLIC diff --git a/soc/riscv/litex_vexriscv/Kconfig.defconfig b/soc/riscv/litex_vexriscv/Kconfig.defconfig index f3e4c7cc79c..0088420459f 100644 --- a/soc/riscv/litex_vexriscv/Kconfig.defconfig +++ b/soc/riscv/litex_vexriscv/Kconfig.defconfig @@ -9,9 +9,6 @@ config SOC config SYS_CLOCK_HW_CYCLES_PER_SEC default 100000000 -config RISCV_HAS_PLIC - bool - config NUM_IRQS default 12 diff --git a/soc/riscv/microchip_miv/miv/Kconfig.defconfig.series b/soc/riscv/microchip_miv/miv/Kconfig.defconfig.series index fc5aaa7c186..35f4365b02b 100644 --- a/soc/riscv/microchip_miv/miv/Kconfig.defconfig.series +++ b/soc/riscv/microchip_miv/miv/Kconfig.defconfig.series @@ -11,9 +11,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_PLIC - default y - config RISCV_GP default y diff --git a/soc/riscv/microchip_miv/miv/Kconfig.series b/soc/riscv/microchip_miv/miv/Kconfig.series index 2989876c0e0..9f348619624 100644 --- a/soc/riscv/microchip_miv/miv/Kconfig.series +++ b/soc/riscv/microchip_miv/miv/Kconfig.series @@ -8,5 +8,6 @@ config SOC_SERIES_MIV select SOC_FAMILY_MICROCHIP_MIV select RISCV select RISCV_PRIVILEGED + select RISCV_HAS_PLIC help Enable support for Microchip Mi-V diff --git a/soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series b/soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series index f41ae867153..5a3f113c13e 100644 --- a/soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series +++ b/soc/riscv/microchip_miv/polarfire/Kconfig.defconfig.series @@ -14,9 +14,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_PLIC - default y - config RISCV_GP default y diff --git a/soc/riscv/microchip_miv/polarfire/Kconfig.series b/soc/riscv/microchip_miv/polarfire/Kconfig.series index 9001efc2858..59ec4dbdd7a 100644 --- a/soc/riscv/microchip_miv/polarfire/Kconfig.series +++ b/soc/riscv/microchip_miv/polarfire/Kconfig.series @@ -8,5 +8,6 @@ config SOC_SERIES_POLARFIRE select SOC_FAMILY_MICROCHIP_MIV select RISCV select RISCV_PRIVILEGED + select RISCV_HAS_PLIC help Enable support for Microchip RISCV 64bit diff --git a/soc/riscv/opentitan/Kconfig.defconfig b/soc/riscv/opentitan/Kconfig.defconfig index 4ec6bffc4e7..19a72fc70bd 100644 --- a/soc/riscv/opentitan/Kconfig.defconfig +++ b/soc/riscv/opentitan/Kconfig.defconfig @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_PLIC - default y - config RISCV_GP default y diff --git a/soc/riscv/opentitan/Kconfig.soc b/soc/riscv/opentitan/Kconfig.soc index 8270fde110d..c76cfe013b1 100644 --- a/soc/riscv/opentitan/Kconfig.soc +++ b/soc/riscv/opentitan/Kconfig.soc @@ -16,6 +16,7 @@ config SOC_OPENTITAN select RISCV_ISA_EXT_ZBS select RISCV select RISCV_PRIVILEGED + select RISCV_HAS_PLIC # OpenTitan Ibex core mtvec mode is read-only / forced to vectored mode. select RISCV_VECTORED_MODE select GEN_IRQ_VECTOR_TABLE diff --git a/soc/riscv/renode_virt/Kconfig.defconfig b/soc/riscv/renode_virt/Kconfig.defconfig index 5d2cd649b0b..fab59719595 100644 --- a/soc/riscv/renode_virt/Kconfig.defconfig +++ b/soc/riscv/renode_virt/Kconfig.defconfig @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_PLIC - default y - config RISCV_GP default y diff --git a/soc/riscv/renode_virt/Kconfig.soc b/soc/riscv/renode_virt/Kconfig.soc index 5aae660880a..ba42c40c28d 100644 --- a/soc/riscv/renode_virt/Kconfig.soc +++ b/soc/riscv/renode_virt/Kconfig.soc @@ -13,3 +13,4 @@ config SOC_RISCV32_VIRTUAL_RENODE select RISCV_ISA_EXT_C select RISCV_ISA_EXT_ZICSR select RISCV_ISA_EXT_ZIFENCEI + select RISCV_HAS_PLIC diff --git a/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series b/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series index 661fe4ba1eb..eaa43e68e70 100644 --- a/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series +++ b/soc/riscv/sifive_freedom/e300/Kconfig.defconfig.series @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_PLIC - default y - config RISCV_GP default y diff --git a/soc/riscv/sifive_freedom/e300/Kconfig.series b/soc/riscv/sifive_freedom/e300/Kconfig.series index 47ae89e6d4c..81634da000d 100644 --- a/soc/riscv/sifive_freedom/e300/Kconfig.series +++ b/soc/riscv/sifive_freedom/e300/Kconfig.series @@ -7,6 +7,7 @@ config SOC_SERIES_SIFIVE_FREEDOM_E300 bool "SiFive Freedom E300 SOC implementation" select RISCV select RISCV_PRIVILEGED + select RISCV_HAS_PLIC select SOC_FAMILY_SIFIVE_FREEDOM help Enable support for SiFive Freedom FE300 SOC diff --git a/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series b/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series index 3db750cb1a6..d306b60252a 100644 --- a/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series +++ b/soc/riscv/sifive_freedom/u500/Kconfig.defconfig.series @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_PLIC - default y - config RISCV_GP default y diff --git a/soc/riscv/sifive_freedom/u500/Kconfig.series b/soc/riscv/sifive_freedom/u500/Kconfig.series index a576dfbc6f7..7335a1a5293 100644 --- a/soc/riscv/sifive_freedom/u500/Kconfig.series +++ b/soc/riscv/sifive_freedom/u500/Kconfig.series @@ -7,6 +7,7 @@ config SOC_SERIES_SIFIVE_FREEDOM_U500 bool "SiFive Freedom U500 SOC implementation" select RISCV select RISCV_PRIVILEGED + select RISCV_HAS_PLIC select SOC_FAMILY_SIFIVE_FREEDOM help Enable support for SiFive Freedom U500 SOC diff --git a/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series b/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series index 83165d58870..a0e730d608f 100644 --- a/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series +++ b/soc/riscv/sifive_freedom/u700/Kconfig.defconfig.series @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_PLIC - default y - config RISCV_GP default y diff --git a/soc/riscv/sifive_freedom/u700/Kconfig.series b/soc/riscv/sifive_freedom/u700/Kconfig.series index 613844703c7..04bdc1fb9b2 100644 --- a/soc/riscv/sifive_freedom/u700/Kconfig.series +++ b/soc/riscv/sifive_freedom/u700/Kconfig.series @@ -7,6 +7,7 @@ config SOC_SERIES_SIFIVE_FREEDOM_U700 bool "SiFive Freedom SOC U700 implementation" select RISCV select RISCV_PRIVILEGED + select RISCV_HAS_PLIC select SOC_FAMILY_SIFIVE_FREEDOM help Enable support for SiFive Freedom U700 SOC diff --git a/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series index 2dc45e1f347..0f058cb6c25 100644 --- a/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series +++ b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.defconfig.series @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_PLIC - default y - config RISCV_GP default y diff --git a/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series index 19cedcefe27..f392a5d1f97 100644 --- a/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series +++ b/soc/riscv/starfive_jh71xx/jh71xx/Kconfig.series @@ -5,5 +5,6 @@ config SOC_SERIES_STARFIVE_JH71XX bool "Starfive JH71XX series" select RISCV select RISCV_PRIVILEGED + select RISCV_HAS_PLIC help Enable support for Starfive JH71XX SoC Series. diff --git a/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series index 5b62959858e..2b72ad9960c 100644 --- a/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series +++ b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.defconfig.series @@ -15,10 +15,6 @@ config RISCV_SOC_INTERRUPT_INIT bool default y -config RISCV_HAS_PLIC - bool - default y - config RISCV_GP bool default y diff --git a/soc/riscv/telink_tlsr/tlsr951x/Kconfig.series b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.series index 5ad3053725e..5d5fc3226e5 100644 --- a/soc/riscv/telink_tlsr/tlsr951x/Kconfig.series +++ b/soc/riscv/telink_tlsr/tlsr951x/Kconfig.series @@ -11,6 +11,7 @@ config SOC_SERIES_TELINK_TLSR951X select RISCV_ISA_EXT_ZICSR select RISCV_ISA_EXT_ZIFENCEI select RISCV_PRIVILEGED + select RISCV_HAS_PLIC select HAS_TELINK_DRIVERS select ATOMIC_OPERATIONS_BUILTIN select CPU_HAS_FPU diff --git a/soc/riscv/virt/Kconfig.defconfig b/soc/riscv/virt/Kconfig.defconfig index e0982bc185b..bed5ff8bec7 100644 --- a/soc/riscv/virt/Kconfig.defconfig +++ b/soc/riscv/virt/Kconfig.defconfig @@ -12,9 +12,6 @@ config SYS_CLOCK_HW_CYCLES_PER_SEC config RISCV_SOC_INTERRUPT_INIT default y -config RISCV_HAS_PLIC - default y - config RISCV_GP default y diff --git a/soc/riscv/virt/Kconfig.soc b/soc/riscv/virt/Kconfig.soc index 9a9168f5a8c..59e553a9d7b 100644 --- a/soc/riscv/virt/Kconfig.soc +++ b/soc/riscv/virt/Kconfig.soc @@ -10,3 +10,4 @@ config SOC_RISCV_VIRT select RISCV_ISA_EXT_C select RISCV select RISCV_PRIVILEGED + select RISCV_HAS_PLIC From 73a3223830a478cf5f9a23710bb1fc9544812553 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Tue, 16 Jan 2024 16:01:41 +0100 Subject: [PATCH 1226/1623] [nrf fromtree] arch: riscv: add RISCV_HAS_(C|P)LIC from soc/riscv Because these are general RISC-V options, not soc specific. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 49e2bc69a2fc5a8cbb2873d4a35fd416a38ee84d) --- arch/riscv/Kconfig | 12 ++++++++++++ soc/riscv/common/riscv-privileged/Kconfig | 12 ------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 1c5defbacaf..708c529f237 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -153,6 +153,18 @@ config RISCV_SOC_OFFSETS in offsets.h. The last one should not end in a semicolon. See gen_offset.h for more details. +config RISCV_HAS_PLIC + bool + depends on RISCV_PRIVILEGED + help + Does the SOC provide support for a Platform Level Interrupt Controller (PLIC). + +config RISCV_HAS_CLIC + bool + depends on RISCV_PRIVILEGED + help + Does the SOC provide support for a Core-Local Interrupt Controller (CLIC). + config RISCV_SOC_INTERRUPT_INIT bool "SOC-based interrupt initialization" help diff --git a/soc/riscv/common/riscv-privileged/Kconfig b/soc/riscv/common/riscv-privileged/Kconfig index 016919c4661..10c2e37712b 100644 --- a/soc/riscv/common/riscv-privileged/Kconfig +++ b/soc/riscv/common/riscv-privileged/Kconfig @@ -4,18 +4,6 @@ # Copyright (c) 2017 Jean-Paul Etienne # SPDX-License-Identifier: Apache-2.0 -config RISCV_HAS_PLIC - bool - depends on RISCV_PRIVILEGED - help - Does the SOC provide support for a Platform Level Interrupt Controller (PLIC). - -config RISCV_HAS_CLIC - bool - depends on RISCV_PRIVILEGED - help - Does the SOC provide support for a Core-Local Interrupt Controller (CLIC). - config RISCV_VECTORED_MODE bool "Should the SOC use vectored mode" depends on RISCV_PRIVILEGED From 2001c6ababf44c171e8f2debc619cfcc2f9fd5de Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Tue, 16 Jan 2024 16:31:26 +0100 Subject: [PATCH 1227/1623] [nrf fromtree] arch: riscv: make __soc_is_irq optional It looks like all SoCs in tree check if an exception comes from an IRQ the same way, so let's provide a common logic by default, still customizable if the SoC selects RISCV_SOC_ISR_CHECK. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 68799d507da32fde0459c6abffba33182ba73f2f) --- arch/riscv/Kconfig | 7 ++++++ arch/riscv/core/isr.S | 13 +++++++--- include/zephyr/arch/riscv/irq.h | 6 +++-- soc/riscv/common/riscv-privileged/soc_irq.S | 27 --------------------- soc/riscv/espressif_esp32/esp32c3/soc_irq.S | 6 ----- soc/riscv/ite_ec/common/soc_irq.S | 18 -------------- soc/riscv/openisa_rv32m1/soc_irq.S | 10 -------- 7 files changed, 21 insertions(+), 66 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 708c529f237..a816d1c5501 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -165,6 +165,13 @@ config RISCV_HAS_CLIC help Does the SOC provide support for a Core-Local Interrupt Controller (CLIC). +config RISCV_SOC_EXCEPTION_FROM_IRQ + bool + help + Option selected by SoCs that require a custom mechanism to check if + an exception is the result of an interrupt or not. If selected, + __soc_is_irq() needs to be implemented by the SoC. + config RISCV_SOC_INTERRUPT_INIT bool "SOC-based interrupt initialization" help diff --git a/arch/riscv/core/isr.S b/arch/riscv/core/isr.S index 558d2a41fbe..982e6777b36 100644 --- a/arch/riscv/core/isr.S +++ b/arch/riscv/core/isr.S @@ -51,7 +51,9 @@ /* imports */ GDATA(_sw_isr_table) +#ifdef CONFIG_RISCV_SOC_EXCEPTION_FROM_IRQ GTEXT(__soc_is_irq) +#endif GTEXT(__soc_handle_irq) GTEXT(_Fault) #ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE @@ -91,7 +93,8 @@ GTEXT(_isr_wrapper) * what standard behavior is defined). Hence, the arch level code expects * the following functions to be provided at the SOC level: * - * - __soc_is_irq: decide if we're handling an interrupt or an exception + * - __soc_is_irq (optional): decide if we're handling an interrupt or an + exception * - __soc_handle_irq: handle SoC-specific details for a pending IRQ * (e.g. clear a pending bit in a SoC-specific register) * @@ -284,10 +287,14 @@ no_fp: /* increment _current->arch.exception_depth */ * function (that needs to be implemented by each SOC). The result is * returned via register a0 (1: interrupt, 0 exception) */ +#ifdef CONFIG_RISCV_SOC_EXCEPTION_FROM_IRQ jal ra, __soc_is_irq - - /* If a0 != 0, jump to is_interrupt */ bnez a0, is_interrupt +#else + csrr t0, mcause + srli t0, t0, RISCV_MCAUSE_IRQ_POS + bnez t0, is_interrupt +#endif /* * If the exception is the result of an ECALL, check whether to diff --git a/include/zephyr/arch/riscv/irq.h b/include/zephyr/arch/riscv/irq.h index 84d3a4949a9..c0db9a6687d 100644 --- a/include/zephyr/arch/riscv/irq.h +++ b/include/zephyr/arch/riscv/irq.h @@ -40,9 +40,11 @@ extern "C" { #define RISCV_IRQ_MEXT 11 #ifdef CONFIG_64BIT -#define RISCV_MCAUSE_IRQ_BIT (1 << 63) +#define RISCV_MCAUSE_IRQ_POS 63U +#define RISCV_MCAUSE_IRQ_BIT BIT64(RISCV_MCAUSE_IRQ_POS) #else -#define RISCV_MCAUSE_IRQ_BIT (1 << 31) +#define RISCV_MCAUSE_IRQ_POS 31U +#define RISCV_MCAUSE_IRQ_BIT BIT(RISCV_MCAUSE_IRQ_POS) #endif #ifndef _ASMLANGUAGE diff --git a/soc/riscv/common/riscv-privileged/soc_irq.S b/soc/riscv/common/riscv-privileged/soc_irq.S index 377edbf600d..acf7e724aea 100644 --- a/soc/riscv/common/riscv-privileged/soc_irq.S +++ b/soc/riscv/common/riscv-privileged/soc_irq.S @@ -32,30 +32,3 @@ SECTION_FUNC(exception.other, __soc_handle_irq) /* Return */ ret - -/* - * __soc_is_irq is defined as .weak to allow re-implementation by - * SOCs that do not truly follow the riscv privilege specification. - */ -WTEXT(__soc_is_irq) - -/* - * SOC-specific function to determine if the exception is the result of a - * an interrupt or an exception - * return 1 (interrupt) or 0 (exception) - * - */ -SECTION_FUNC(exception.other, __soc_is_irq) - /* Read mcause and check if interrupt bit is set */ - csrr t0, mcause - li t1, RISCV_MCAUSE_IRQ_BIT - and t0, t0, t1 - - /* If interrupt bit is not set, return with 0 */ - addi a0, x0, 0 - beqz t0, not_interrupt - addi a0, a0, 1 - -not_interrupt: - /* return */ - ret diff --git a/soc/riscv/espressif_esp32/esp32c3/soc_irq.S b/soc/riscv/espressif_esp32/esp32c3/soc_irq.S index c1ad164c153..6ce11ae6a81 100644 --- a/soc/riscv/espressif_esp32/esp32c3/soc_irq.S +++ b/soc/riscv/espressif_esp32/esp32c3/soc_irq.S @@ -7,15 +7,9 @@ #include /* Exports */ -GTEXT(__soc_is_irq) GTEXT(__soc_handle_irq) GTEXT(soc_intr_get_next_source) -SECTION_FUNC(exception.other, __soc_is_irq) - csrr a0, mcause - srli a0, a0, 31 - ret - SECTION_FUNC(exception.other, __soc_handle_irq) addi sp, sp,-4 sw ra, 0x00(sp) diff --git a/soc/riscv/ite_ec/common/soc_irq.S b/soc/riscv/ite_ec/common/soc_irq.S index a412ca6a796..ceb0f3afecb 100644 --- a/soc/riscv/ite_ec/common/soc_irq.S +++ b/soc/riscv/ite_ec/common/soc_irq.S @@ -25,21 +25,3 @@ GTEXT(__soc_handle_irq) */ SECTION_FUNC(exception.other, __soc_handle_irq) j get_irq - -/* - * __soc_is_irq is defined as .weak to allow re-implementation by - * SOCs that does not truely follow the riscv privilege specification. - */ -WTEXT(__soc_is_irq) - -/* - * SOC-specific function to determine if the exception is the result of a - * an interrupt or an exception - * return 1 (interrupt) or 0 (exception) - * - */ -SECTION_FUNC(exception.other, __soc_is_irq) - /* Read mcause and check if interrupt bit (bit 31) is set */ - csrr a0, mcause - srli a0, a0, 31 - ret diff --git a/soc/riscv/openisa_rv32m1/soc_irq.S b/soc/riscv/openisa_rv32m1/soc_irq.S index 23222ea2c70..d3059d2bd28 100644 --- a/soc/riscv/openisa_rv32m1/soc_irq.S +++ b/soc/riscv/openisa_rv32m1/soc_irq.S @@ -10,22 +10,12 @@ #include /* Exports */ -GTEXT(__soc_is_irq) GTEXT(__soc_handle_irq) #ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE GTEXT(__soc_save_context) GTEXT(__soc_restore_context) #endif -/* - * Whether we're in an IRQ is bog-standard RISC-V on this SoC: - * yes if the top mcause bit is set, otherwise no. - */ -SECTION_FUNC(exception.other, __soc_is_irq) - csrr a0, mcause - srli a0, a0, 31 - ret - /* * With a0 == irq_num, this is equivalent to: * From 7f26bed98ed7f3d4acc37cafe0d17b57b2680125 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 25 Jan 2024 16:59:40 +0100 Subject: [PATCH 1228/1623] [nrf fromtree] dts: bindings: nordic,nrf-ficr: move to misc folder It's not related to ARM. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 6ec2dbf8ee3d7ed66bc7a1f5cbaeb599a58cf229) --- dts/bindings/{arm => misc}/nordic,nrf-ficr.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dts/bindings/{arm => misc}/nordic,nrf-ficr.yaml (100%) diff --git a/dts/bindings/arm/nordic,nrf-ficr.yaml b/dts/bindings/misc/nordic,nrf-ficr.yaml similarity index 100% rename from dts/bindings/arm/nordic,nrf-ficr.yaml rename to dts/bindings/misc/nordic,nrf-ficr.yaml From 35a86dd63583fdc6cc6fbc83cf18ff647f27f74f Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 20 Nov 2023 23:34:32 +0100 Subject: [PATCH 1229/1623] [nrf fromtree] dts: bindings: arm: nordic,nrf-ficr: add #nordic,ficr-cells Add a new #nordic,ficr-cells property, so that we can specify a FICR offset in a phandle-array, e.g. nordic,ficrs = <&ficr 0xff>; Signed-off-by: Gerard Marull-Paretas (cherry picked from commit ed0fc03f677b5cc5552c477b0f288cb4a77aa4e9) --- dts/arm/nordic/nrf51822.dtsi | 1 + dts/arm/nordic/nrf52805.dtsi | 1 + dts/arm/nordic/nrf52810.dtsi | 1 + dts/arm/nordic/nrf52811.dtsi | 1 + dts/arm/nordic/nrf52820.dtsi | 1 + dts/arm/nordic/nrf52832.dtsi | 1 + dts/arm/nordic/nrf52833.dtsi | 1 + dts/arm/nordic/nrf52840.dtsi | 1 + dts/arm/nordic/nrf5340_cpuapp.dtsi | 1 + dts/arm/nordic/nrf5340_cpunet.dtsi | 1 + dts/arm/nordic/nrf54l15_cpuapp.dtsi | 1 + dts/arm/nordic/nrf91.dtsi | 1 + dts/bindings/misc/nordic,nrf-ficr.yaml | 8 ++++++++ 13 files changed, 20 insertions(+) diff --git a/dts/arm/nordic/nrf51822.dtsi b/dts/arm/nordic/nrf51822.dtsi index 020711a7e7f..499140a0fb8 100644 --- a/dts/arm/nordic/nrf51822.dtsi +++ b/dts/arm/nordic/nrf51822.dtsi @@ -24,6 +24,7 @@ ficr: ficr@10000000 { compatible = "nordic,nrf-ficr"; reg = <0x10000000 0x1000>; + #nordic,ficr-cells = <1>; status = "okay"; }; diff --git a/dts/arm/nordic/nrf52805.dtsi b/dts/arm/nordic/nrf52805.dtsi index a54e8eca9c6..c8839897f3c 100644 --- a/dts/arm/nordic/nrf52805.dtsi +++ b/dts/arm/nordic/nrf52805.dtsi @@ -28,6 +28,7 @@ ficr: ficr@10000000 { compatible = "nordic,nrf-ficr"; reg = <0x10000000 0x1000>; + #nordic,ficr-cells = <1>; status = "okay"; }; diff --git a/dts/arm/nordic/nrf52810.dtsi b/dts/arm/nordic/nrf52810.dtsi index ce5a2bce779..cd2543ce511 100644 --- a/dts/arm/nordic/nrf52810.dtsi +++ b/dts/arm/nordic/nrf52810.dtsi @@ -32,6 +32,7 @@ ficr: ficr@10000000 { compatible = "nordic,nrf-ficr"; reg = <0x10000000 0x1000>; + #nordic,ficr-cells = <1>; status = "okay"; }; diff --git a/dts/arm/nordic/nrf52811.dtsi b/dts/arm/nordic/nrf52811.dtsi index 9c9a3fa6b77..4034b4958e7 100644 --- a/dts/arm/nordic/nrf52811.dtsi +++ b/dts/arm/nordic/nrf52811.dtsi @@ -36,6 +36,7 @@ ficr: ficr@10000000 { compatible = "nordic,nrf-ficr"; reg = <0x10000000 0x1000>; + #nordic,ficr-cells = <1>; status = "okay"; }; diff --git a/dts/arm/nordic/nrf52820.dtsi b/dts/arm/nordic/nrf52820.dtsi index c210a7c23aa..c702cd45227 100644 --- a/dts/arm/nordic/nrf52820.dtsi +++ b/dts/arm/nordic/nrf52820.dtsi @@ -37,6 +37,7 @@ ficr: ficr@10000000 { compatible = "nordic,nrf-ficr"; reg = <0x10000000 0x1000>; + #nordic,ficr-cells = <1>; status = "okay"; }; diff --git a/dts/arm/nordic/nrf52832.dtsi b/dts/arm/nordic/nrf52832.dtsi index 2e1fd68946b..d3fb288f449 100644 --- a/dts/arm/nordic/nrf52832.dtsi +++ b/dts/arm/nordic/nrf52832.dtsi @@ -32,6 +32,7 @@ ficr: ficr@10000000 { compatible = "nordic,nrf-ficr"; reg = <0x10000000 0x1000>; + #nordic,ficr-cells = <1>; status = "okay"; }; diff --git a/dts/arm/nordic/nrf52833.dtsi b/dts/arm/nordic/nrf52833.dtsi index d55f0f6df9e..9ba7a85ad4a 100644 --- a/dts/arm/nordic/nrf52833.dtsi +++ b/dts/arm/nordic/nrf52833.dtsi @@ -36,6 +36,7 @@ ficr: ficr@10000000 { compatible = "nordic,nrf-ficr"; reg = <0x10000000 0x1000>; + #nordic,ficr-cells = <1>; status = "okay"; }; diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index 2082f16c32a..34199473dc2 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -32,6 +32,7 @@ ficr: ficr@10000000 { compatible = "nordic,nrf-ficr"; reg = <0x10000000 0x1000>; + #nordic,ficr-cells = <1>; status = "okay"; }; diff --git a/dts/arm/nordic/nrf5340_cpuapp.dtsi b/dts/arm/nordic/nrf5340_cpuapp.dtsi index 9f122b36f85..ace10fdfe50 100644 --- a/dts/arm/nordic/nrf5340_cpuapp.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp.dtsi @@ -41,6 +41,7 @@ ficr: ficr@ff0000 { compatible = "nordic,nrf-ficr"; reg = <0xff0000 0x1000>; + #nordic,ficr-cells = <1>; status = "okay"; }; diff --git a/dts/arm/nordic/nrf5340_cpunet.dtsi b/dts/arm/nordic/nrf5340_cpunet.dtsi index d930cf603c0..ae819dfb64f 100644 --- a/dts/arm/nordic/nrf5340_cpunet.dtsi +++ b/dts/arm/nordic/nrf5340_cpunet.dtsi @@ -35,6 +35,7 @@ ficr: ficr@1ff0000 { compatible = "nordic,nrf-ficr"; reg = <0x01ff0000 0x1000>; + #nordic,ficr-cells = <1>; status = "okay"; }; diff --git a/dts/arm/nordic/nrf54l15_cpuapp.dtsi b/dts/arm/nordic/nrf54l15_cpuapp.dtsi index 7e90c8b1213..df4ccc52294 100644 --- a/dts/arm/nordic/nrf54l15_cpuapp.dtsi +++ b/dts/arm/nordic/nrf54l15_cpuapp.dtsi @@ -51,6 +51,7 @@ ficr: ficr@ffc000 { compatible = "nordic,nrf-ficr"; reg = <0xffc000 0x1000>; + #nordic,ficr-cells = <1>; }; sram0: memory@20000000 { diff --git a/dts/arm/nordic/nrf91.dtsi b/dts/arm/nordic/nrf91.dtsi index 2b2fb57850d..9b7336041ba 100644 --- a/dts/arm/nordic/nrf91.dtsi +++ b/dts/arm/nordic/nrf91.dtsi @@ -93,6 +93,7 @@ ficr: ficr@ff0000 { compatible = "nordic,nrf-ficr"; reg = <0xff0000 0x1000>; + #nordic,ficr-cells = <1>; status = "okay"; }; diff --git a/dts/bindings/misc/nordic,nrf-ficr.yaml b/dts/bindings/misc/nordic,nrf-ficr.yaml index bea0762573e..ca199c24f07 100644 --- a/dts/bindings/misc/nordic,nrf-ficr.yaml +++ b/dts/bindings/misc/nordic,nrf-ficr.yaml @@ -7,3 +7,11 @@ include: base.yaml properties: reg: required: true + + "#nordic,ficr-cells": + type: int + required: true + const: 1 + +nordic,ficr-cells: + - offset From 85a97f550ff5a2687864a53487629e175179d75e Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 25 Jan 2024 17:06:24 +0100 Subject: [PATCH 1230/1623] [nrf fromtree] dts: bindings: misc: add nordic-nrf-ficr-client So that FICR clients can include this file instead of redefining FICR properties every time. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit e57ad265fb4fd9f2fcd1237b8ee7897245b62fcd) --- dts/bindings/misc/nordic-nrf-ficr-client.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 dts/bindings/misc/nordic-nrf-ficr-client.yaml diff --git a/dts/bindings/misc/nordic-nrf-ficr-client.yaml b/dts/bindings/misc/nordic-nrf-ficr-client.yaml new file mode 100644 index 00000000000..06a1e727f3f --- /dev/null +++ b/dts/bindings/misc/nordic-nrf-ficr-client.yaml @@ -0,0 +1,14 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +properties: + nordic,ficrs: + type: phandle-array + description: | + FICR entries, e.g. <&ficr OFFSET>. Available offsets (or FICR entries) are + available at . + + nordic,ficr-names: + type: string-array + description: | + Names of each nordic,ficrs entry. From c5c0ce7ca4c7205b84b585b319636f88e8f7a044 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 29 Jan 2024 16:09:25 +0100 Subject: [PATCH 1231/1623] [nrf fromtree] scripts: west: runners: nrf: fix UICR check uicr_ranges dictionary entries did not contain the `_FAMILY` suffix, now used by self.family variable, resulting in an always false check. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit ec9dc5d73997a5f80e379bfe188384639a87dfc5) --- scripts/west_commands/runners/nrf_common.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/west_commands/runners/nrf_common.py b/scripts/west_commands/runners/nrf_common.py index 788021c6191..93871d831ee 100644 --- a/scripts/west_commands/runners/nrf_common.py +++ b/scripts/west_commands/runners/nrf_common.py @@ -178,9 +178,9 @@ def hex_has_uicr_content(self): # A map from SoCs which need this check to their UICR address # ranges. If self.family isn't in here, do nothing. uicr_ranges = { - 'NRF53': ((0x00FF8000, 0x00FF8800), - (0x01FF8000, 0x01FF8800)), - 'NRF91': ((0x00FF8000, 0x00FF8800),), + 'NRF53_FAMILY': ((0x00FF8000, 0x00FF8800), + (0x01FF8000, 0x01FF8800)), + 'NRF91_FAMILY': ((0x00FF8000, 0x00FF8800),), } if self.family not in uicr_ranges: From a75a5b4011e52d1006fb05c6ad38e1cbad11ab30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 9 Jan 2024 16:16:27 +0100 Subject: [PATCH 1232/1623] [nrf fromtree] soc: arm: nordic_nrf: Clean up and unify a bit cmake code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consistently use `zephyr_library*` cmake functions for all nRF Series and set the Cortex-M linker script in a common place for all of them. Remove no longer needed include directories. Signed-off-by: Andrzej Głąbek (cherry picked from commit eb78b719148016a0852f0d43163663cd24330baa) --- soc/arm/nordic_nrf/CMakeLists.txt | 4 +++- soc/arm/nordic_nrf/common/CMakeLists.txt | 5 ++++- soc/arm/nordic_nrf/nrf51/CMakeLists.txt | 13 +------------ soc/arm/nordic_nrf/nrf52/CMakeLists.txt | 13 +------------ soc/arm/nordic_nrf/nrf53/CMakeLists.txt | 10 ++-------- soc/arm/nordic_nrf/nrf54l/CMakeLists.txt | 4 +--- soc/arm/nordic_nrf/nrf91/CMakeLists.txt | 6 +----- 7 files changed, 13 insertions(+), 42 deletions(-) diff --git a/soc/arm/nordic_nrf/CMakeLists.txt b/soc/arm/nordic_nrf/CMakeLists.txt index 3b097d73569..bd7725404b8 100644 --- a/soc/arm/nordic_nrf/CMakeLists.txt +++ b/soc/arm/nordic_nrf/CMakeLists.txt @@ -1,9 +1,11 @@ # SPDX-License-Identifier: Apache-2.0 +zephyr_library() + add_subdirectory(${SOC_SERIES}) add_subdirectory(common) -zephyr_sources( +zephyr_library_sources( validate_base_addresses.c validate_enabled_instances.c ) diff --git a/soc/arm/nordic_nrf/common/CMakeLists.txt b/soc/arm/nordic_nrf/common/CMakeLists.txt index eb074dd0548..c894615a700 100644 --- a/soc/arm/nordic_nrf/common/CMakeLists.txt +++ b/soc/arm/nordic_nrf/common/CMakeLists.txt @@ -3,10 +3,13 @@ zephyr_library_sources_ifdef(CONFIG_SOC_FAMILY_NRF soc_nrf_common.S) zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c) + zephyr_include_directories(.) +set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") + if (CONFIG_TFM_PARTITION_PLATFORM) - zephyr_sources(soc_secure.c) + zephyr_library_sources(soc_secure.c) zephyr_library_include_directories( $/install/interface/include ) diff --git a/soc/arm/nordic_nrf/nrf51/CMakeLists.txt b/soc/arm/nordic_nrf/nrf51/CMakeLists.txt index 44d139e422a..35d47fb252b 100644 --- a/soc/arm/nordic_nrf/nrf51/CMakeLists.txt +++ b/soc/arm/nordic_nrf/nrf51/CMakeLists.txt @@ -1,14 +1,3 @@ # SPDX-License-Identifier: Apache-2.0 -zephyr_library() - -zephyr_library_sources( - soc.c - ) - -zephyr_library_include_directories( - ${ZEPHYR_BASE}/kernel/include - ${ZEPHYR_BASE}/arch/arm/include - ) - -set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") +zephyr_library_sources(soc.c) diff --git a/soc/arm/nordic_nrf/nrf52/CMakeLists.txt b/soc/arm/nordic_nrf/nrf52/CMakeLists.txt index 04e255a3eb1..1b7d4d5257a 100644 --- a/soc/arm/nordic_nrf/nrf52/CMakeLists.txt +++ b/soc/arm/nordic_nrf/nrf52/CMakeLists.txt @@ -1,15 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 -zephyr_library() - -zephyr_library_sources( - soc.c - ) - -zephyr_library_include_directories( - ${ZEPHYR_BASE}/kernel/include - ${ZEPHYR_BASE}/arch/arm/include - ) +zephyr_library_sources(soc.c) if(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 AND CONFIG_SPI_NRFX_SPIM) message(WARNING "Both SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 and an NRF SPIM driver are enabled, therefore PAN 58 will apply if RXD.MAXCNT == 1 and TXD.MAXCNT <= 1") @@ -22,5 +13,3 @@ if(CONFIG_SOC_NRF52832) endif() endif() endif() - -set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") diff --git a/soc/arm/nordic_nrf/nrf53/CMakeLists.txt b/soc/arm/nordic_nrf/nrf53/CMakeLists.txt index b4e82f52c28..be275df68f5 100644 --- a/soc/arm/nordic_nrf/nrf53/CMakeLists.txt +++ b/soc/arm/nordic_nrf/nrf53/CMakeLists.txt @@ -1,12 +1,8 @@ # SPDX-License-Identifier: Apache-2.0 -zephyr_sources( - soc.c - ) +zephyr_library_sources(soc.c) -zephyr_library_sources_ifdef(CONFIG_NRF53_SYNC_RTC - sync_rtc.c - ) +zephyr_library_sources_ifdef(CONFIG_NRF53_SYNC_RTC sync_rtc.c) if (CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND_NEEDED AND NOT CONFIG_SYS_CLOCK_EXISTS) @@ -19,5 +15,3 @@ if (CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND_NEEDED AND At your own risk, you can suppress this warning by setting CONFIG_SOC_NRF53_ANOMALY_160_WORKAROUND_NEEDED=n.") endif() - -set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") diff --git a/soc/arm/nordic_nrf/nrf54l/CMakeLists.txt b/soc/arm/nordic_nrf/nrf54l/CMakeLists.txt index 914aad289ef..33036acce8f 100644 --- a/soc/arm/nordic_nrf/nrf54l/CMakeLists.txt +++ b/soc/arm/nordic_nrf/nrf54l/CMakeLists.txt @@ -1,12 +1,10 @@ # Copyright (c) 2024 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -zephyr_sources( +zephyr_library_sources( soc.c ../validate_rram_partitions.c) -set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") - if (CONFIG_ELV_GRTC_LFXO_ALLOWED) message(WARNING "WARNING! ELV mode feature is EXPERIMENTAL and may brick your device!") endif() diff --git a/soc/arm/nordic_nrf/nrf91/CMakeLists.txt b/soc/arm/nordic_nrf/nrf91/CMakeLists.txt index 7424bb9f7b9..35d47fb252b 100644 --- a/soc/arm/nordic_nrf/nrf91/CMakeLists.txt +++ b/soc/arm/nordic_nrf/nrf91/CMakeLists.txt @@ -1,7 +1,3 @@ # SPDX-License-Identifier: Apache-2.0 -zephyr_sources( - soc.c - ) - -set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") +zephyr_library_sources(soc.c) From 6d1328d7c316c4e38db23c40601d764d1e925606 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 21 Dec 2023 14:07:17 +0100 Subject: [PATCH 1233/1623] [nrf fromtree] boards nrf5*_bsim: Provide more common headers Provide some more common headers some nRF drivers expect. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 572ba26b1fcc46dd943a90e37c1d04168242a4bf) --- boards/posix/nrf_bsim/board_soc.h | 1 + boards/posix/nrf_bsim/soc/pinctrl_soc.h | 13 +++++++++++++ boards/posix/nrf_bsim/soc/soc_nrf_common.h | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 boards/posix/nrf_bsim/soc/pinctrl_soc.h create mode 100644 boards/posix/nrf_bsim/soc/soc_nrf_common.h diff --git a/boards/posix/nrf_bsim/board_soc.h b/boards/posix/nrf_bsim/board_soc.h index 1b7e7a85c0c..d75a187aa61 100644 --- a/boards/posix/nrf_bsim/board_soc.h +++ b/boards/posix/nrf_bsim/board_soc.h @@ -29,6 +29,7 @@ #include #include #include "cmsis.h" +#include "soc_nrf_common.h" #if defined(CONFIG_BOARD_NRF52_BSIM) #define OFFLOAD_SW_IRQ SWI0_EGU0_IRQn diff --git a/boards/posix/nrf_bsim/soc/pinctrl_soc.h b/boards/posix/nrf_bsim/soc/pinctrl_soc.h new file mode 100644 index 00000000000..08252b57fee --- /dev/null +++ b/boards/posix/nrf_bsim/soc/pinctrl_soc.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef BOARDS_POSIX_NRF_BSIM_SOC_PINCTRL_SOC_H +#define BOARDS_POSIX_NRF_BSIM_SOC_PINCTRL_SOC_H + +/* We reuse the real SOC's header: */ +#include "../soc/arm/nordic_nrf/common/pinctrl_soc.h" + +#endif /* BOARDS_POSIX_NRF_BSIM_SOC_PINCTRL_SOC_H */ diff --git a/boards/posix/nrf_bsim/soc/soc_nrf_common.h b/boards/posix/nrf_bsim/soc/soc_nrf_common.h new file mode 100644 index 00000000000..a77778de653 --- /dev/null +++ b/boards/posix/nrf_bsim/soc/soc_nrf_common.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef BOARDS_POSIX_NRF_BSIM_SOC_SOC_NRF_COMMON_H +#define BOARDS_POSIX_NRF_BSIM_SOC_SOC_NRF_COMMON_H + +/* We reuse the real SOC's header: */ +#include "../soc/arm/nordic_nrf/common/soc_nrf_common.h" + +#endif /* BOARDS_POSIX_NRF_BSIM_SOC_SOC_NRF_COMMON_H */ From 1714c2ea47fd4669a9bcbfa96a333d2dcd009bea Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Tue, 16 Jan 2024 15:22:23 +0100 Subject: [PATCH 1234/1623] [nrf fromtree] arch: riscv: remode redundant soc.h includes They are just not needed. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit e7cc2fafb49c1b760bdd85ebf2bc67c53b30c031) --- include/zephyr/arch/riscv/arch.h | 1 - include/zephyr/arch/riscv/common/linker.ld | 1 - include/zephyr/arch/riscv/irq.h | 1 - 3 files changed, 3 deletions(-) diff --git a/include/zephyr/arch/riscv/arch.h b/include/zephyr/arch/riscv/arch.h index 1ab509c162e..bbde28bdfbe 100644 --- a/include/zephyr/arch/riscv/arch.h +++ b/include/zephyr/arch/riscv/arch.h @@ -26,7 +26,6 @@ #endif /* CONFIG_USERSPACE */ #include #include -#include #include #include #include diff --git a/include/zephyr/arch/riscv/common/linker.ld b/include/zephyr/arch/riscv/common/linker.ld index eb5c4782441..128f823c4df 100644 --- a/include/zephyr/arch/riscv/common/linker.ld +++ b/include/zephyr/arch/riscv/common/linker.ld @@ -11,7 +11,6 @@ * Generic Linker script for the riscv platform */ -#include #include #include diff --git a/include/zephyr/arch/riscv/irq.h b/include/zephyr/arch/riscv/irq.h index c0db9a6687d..fa4b3989f05 100644 --- a/include/zephyr/arch/riscv/irq.h +++ b/include/zephyr/arch/riscv/irq.h @@ -22,7 +22,6 @@ extern "C" { #include #include #include -#include #endif /* !_ASMLANGUAGE */ /* Exceptions 0-15 (MCAUSE interrupt=0) */ From 8f65f56adce8086eff1c2ae34d5f9facba49bf88 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Fri, 19 Jan 2024 10:10:08 +0100 Subject: [PATCH 1235/1623] [nrf fromtree] dts: Move nrf_common.dtsi to the common directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... so that it can be included by ARM and RISC-V cores. For the same reason, SysTick can no longer be disabled in this common file. Signed-off-by: Grzegorz Swiderski Signed-off-by: Andrzej Głąbek (cherry picked from commit 3cfa2296a6aed2e326166d521a3fd1978abb29a9) --- dts/arm/nordic/nrf51822.dtsi | 2 +- dts/arm/nordic/nrf52805.dtsi | 7 ++++++- dts/arm/nordic/nrf52810.dtsi | 7 ++++++- dts/arm/nordic/nrf52811.dtsi | 7 ++++++- dts/arm/nordic/nrf52820.dtsi | 7 ++++++- dts/arm/nordic/nrf52832.dtsi | 7 ++++++- dts/arm/nordic/nrf52833.dtsi | 7 ++++++- dts/arm/nordic/nrf52840.dtsi | 7 ++++++- dts/arm/nordic/nrf5340_cpuapp.dtsi | 7 ++++++- dts/arm/nordic/nrf5340_cpuappns.dtsi | 7 ++++++- dts/arm/nordic/nrf5340_cpunet.dtsi | 7 ++++++- dts/arm/nordic/nrf54l_common.dtsi | 2 +- dts/arm/nordic/nrf91.dtsi | 7 ++++++- dts/arm/nordic/nrf91ns.dtsi | 7 ++++++- dts/{arm => common}/nordic/nrf_common.dtsi | 8 -------- 15 files changed, 74 insertions(+), 22 deletions(-) rename dts/{arm => common}/nordic/nrf_common.dtsi (86%) diff --git a/dts/arm/nordic/nrf51822.dtsi b/dts/arm/nordic/nrf51822.dtsi index 499140a0fb8..b64de1d4985 100644 --- a/dts/arm/nordic/nrf51822.dtsi +++ b/dts/arm/nordic/nrf51822.dtsi @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: Apache-2.0 */ #include -#include "nrf_common.dtsi" +#include / { chosen { diff --git a/dts/arm/nordic/nrf52805.dtsi b/dts/arm/nordic/nrf52805.dtsi index c8839897f3c..c5a184d5e28 100644 --- a/dts/arm/nordic/nrf52805.dtsi +++ b/dts/arm/nordic/nrf52805.dtsi @@ -5,7 +5,7 @@ */ #include -#include "nrf_common.dtsi" +#include / { chosen { @@ -321,3 +321,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf52810.dtsi b/dts/arm/nordic/nrf52810.dtsi index cd2543ce511..1ca4a9ea378 100644 --- a/dts/arm/nordic/nrf52810.dtsi +++ b/dts/arm/nordic/nrf52810.dtsi @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: Apache-2.0 */ #include -#include "nrf_common.dtsi" +#include / { chosen { @@ -347,3 +347,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf52811.dtsi b/dts/arm/nordic/nrf52811.dtsi index 4034b4958e7..63b85676587 100644 --- a/dts/arm/nordic/nrf52811.dtsi +++ b/dts/arm/nordic/nrf52811.dtsi @@ -5,7 +5,7 @@ */ #include -#include "nrf_common.dtsi" +#include / { chosen { @@ -382,3 +382,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf52820.dtsi b/dts/arm/nordic/nrf52820.dtsi index c702cd45227..f93e449b0b2 100644 --- a/dts/arm/nordic/nrf52820.dtsi +++ b/dts/arm/nordic/nrf52820.dtsi @@ -5,7 +5,7 @@ */ #include -#include "nrf_common.dtsi" +#include / { @@ -399,3 +399,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf52832.dtsi b/dts/arm/nordic/nrf52832.dtsi index d3fb288f449..ed5a21b9935 100644 --- a/dts/arm/nordic/nrf52832.dtsi +++ b/dts/arm/nordic/nrf52832.dtsi @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: Apache-2.0 */ #include -#include "nrf_common.dtsi" +#include / { chosen { @@ -475,3 +475,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf52833.dtsi b/dts/arm/nordic/nrf52833.dtsi index 9ba7a85ad4a..5ac9cb2d2f8 100644 --- a/dts/arm/nordic/nrf52833.dtsi +++ b/dts/arm/nordic/nrf52833.dtsi @@ -5,7 +5,7 @@ */ #include -#include "nrf_common.dtsi" +#include / { chosen { @@ -543,3 +543,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index 34199473dc2..8efe49a3c91 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: Apache-2.0 */ #include -#include "nrf_common.dtsi" +#include / { chosen { @@ -555,3 +555,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf5340_cpuapp.dtsi b/dts/arm/nordic/nrf5340_cpuapp.dtsi index ace10fdfe50..d48f0ce62dc 100644 --- a/dts/arm/nordic/nrf5340_cpuapp.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp.dtsi @@ -5,7 +5,7 @@ */ #include -#include "nrf_common.dtsi" +#include / { cpus { @@ -115,3 +115,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf5340_cpuappns.dtsi b/dts/arm/nordic/nrf5340_cpuappns.dtsi index aa97c337067..6df1be54b34 100644 --- a/dts/arm/nordic/nrf5340_cpuappns.dtsi +++ b/dts/arm/nordic/nrf5340_cpuappns.dtsi @@ -7,7 +7,7 @@ /* .dtsi header for nRF5340 CPUAPP (Application MCU), Non-Secure domain */ #include -#include "nrf_common.dtsi" +#include / { cpus { @@ -77,3 +77,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf5340_cpunet.dtsi b/dts/arm/nordic/nrf5340_cpunet.dtsi index ae819dfb64f..8a95b3e9985 100644 --- a/dts/arm/nordic/nrf5340_cpunet.dtsi +++ b/dts/arm/nordic/nrf5340_cpunet.dtsi @@ -5,7 +5,7 @@ */ #include -#include "nrf_common.dtsi" +#include / { chosen { @@ -351,3 +351,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf54l_common.dtsi b/dts/arm/nordic/nrf54l_common.dtsi index 4fb7768bd3f..415f2471174 100644 --- a/dts/arm/nordic/nrf54l_common.dtsi +++ b/dts/arm/nordic/nrf54l_common.dtsi @@ -5,7 +5,7 @@ */ #include -#include "nrf_common.dtsi" +#include / { soc { diff --git a/dts/arm/nordic/nrf91.dtsi b/dts/arm/nordic/nrf91.dtsi index 9b7336041ba..e65ce04a004 100644 --- a/dts/arm/nordic/nrf91.dtsi +++ b/dts/arm/nordic/nrf91.dtsi @@ -5,7 +5,7 @@ */ #include -#include "nrf_common.dtsi" +#include / { cpus { @@ -108,3 +108,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf91ns.dtsi b/dts/arm/nordic/nrf91ns.dtsi index 23af6ebe37f..c692873981b 100644 --- a/dts/arm/nordic/nrf91ns.dtsi +++ b/dts/arm/nordic/nrf91ns.dtsi @@ -5,7 +5,7 @@ */ #include -#include "nrf_common.dtsi" +#include / { cpus { @@ -69,3 +69,8 @@ &nvic { arm,num-irq-priority-bits = <3>; }; + +&systick { + /* Use RTC for system clock, instead of SysTick. */ + status = "disabled"; +}; diff --git a/dts/arm/nordic/nrf_common.dtsi b/dts/common/nordic/nrf_common.dtsi similarity index 86% rename from dts/arm/nordic/nrf_common.dtsi rename to dts/common/nordic/nrf_common.dtsi index 8aec8dd0c89..f09557b23de 100644 --- a/dts/arm/nordic/nrf_common.dtsi +++ b/dts/common/nordic/nrf_common.dtsi @@ -43,11 +43,3 @@ #pwm-cells = <3>; }; }; - -&systick { - /* - * Nordic SoCs rely by default on the RTC for system clock - * implementation, so the SysTick node is not to be enabled. - */ - status = "disabled"; -}; From 3c7e9dcfa5520864634d8b8763caa6a66bc00913 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 24 Jan 2024 15:58:47 +0100 Subject: [PATCH 1236/1623] [nrf fromtree] dt-bindings: misc: add nordic,nrf-ficr helper definitions Add definitions to access all FICR fields in the nRF54H20 EngA SoC. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 928dbb58c2c4a9d3283a6856e3728b6a77f4e22e) --- .../misc/nordic-nrf-ficr-nrf54h20-enga.h | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 include/zephyr/dt-bindings/misc/nordic-nrf-ficr-nrf54h20-enga.h diff --git a/include/zephyr/dt-bindings/misc/nordic-nrf-ficr-nrf54h20-enga.h b/include/zephyr/dt-bindings/misc/nordic-nrf-ficr-nrf54h20-enga.h new file mode 100644 index 00000000000..60b788a3516 --- /dev/null +++ b/include/zephyr/dt-bindings/misc/nordic-nrf-ficr-nrf54h20-enga.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +/* autogenerated using Nordic HAL utils/gen_offsets.py script */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_MISC_NORDIC_NRF_FICR_NRF54H20_ENGA_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_MISC_NORDIC_NRF_FICR_NRF54H20_ENGA_H_ + +#define NRF_FICR_BLE_ADDRTYPE 0x00CU +#define NRF_FICR_BLE_ADDR_0 0x010U +#define NRF_FICR_BLE_ADDR_1 0x014U +#define NRF_FICR_BLE_ER_0 0x018U +#define NRF_FICR_BLE_ER_1 0x01CU +#define NRF_FICR_BLE_ER_2 0x020U +#define NRF_FICR_BLE_ER_3 0x024U +#define NRF_FICR_BLE_IR_0 0x028U +#define NRF_FICR_BLE_IR_1 0x02CU +#define NRF_FICR_BLE_IR_2 0x030U +#define NRF_FICR_BLE_IR_3 0x034U +#define NRF_FICR_NFC_TAGHEADER_0 0x040U +#define NRF_FICR_NFC_TAGHEADER_1 0x044U +#define NRF_FICR_NFC_TAGHEADER_2 0x048U +#define NRF_FICR_NFC_TAGHEADER_3 0x04CU +#define NRF_FICR_INFO_CONFIGID 0x050U +#define NRF_FICR_INFO_PART 0x054U +#define NRF_FICR_INFO_VARIANT 0x058U +#define NRF_FICR_INFO_PACKAGE 0x05CU +#define NRF_FICR_INFO_RAM 0x060U +#define NRF_FICR_INFO_MRAM 0x064U +#define NRF_FICR_INFO_CODEPAGESIZE 0x068U +#define NRF_FICR_INFO_CODESIZE 0x06CU +#define NRF_FICR_INFO_DEVICETYPE 0x070U +#define NRF_FICR_TRIM_GLOBAL_SAADC_CALVREF 0x384U +#define NRF_FICR_TRIM_GLOBAL_SAADC_CALGAIN_0 0x388U +#define NRF_FICR_TRIM_GLOBAL_SAADC_CALGAIN_1 0x38CU +#define NRF_FICR_TRIM_GLOBAL_SAADC_CALGAIN_2 0x390U +#define NRF_FICR_TRIM_GLOBAL_SAADC_CALOFFSET 0x394U +#define NRF_FICR_TRIM_GLOBAL_SAADC_LINCALCOEFF_0 0x398U +#define NRF_FICR_TRIM_GLOBAL_SAADC_LINCALCOEFF_1 0x39CU +#define NRF_FICR_TRIM_GLOBAL_SAADC_LINCALCOEFF_2 0x3A0U +#define NRF_FICR_TRIM_GLOBAL_SAADC_LINCALCOEFF_3 0x3A4U +#define NRF_FICR_TRIM_GLOBAL_SAADC_LINCALCOEFF_4 0x3A8U +#define NRF_FICR_TRIM_GLOBAL_SAADC_LINCALCOEFF_5 0x3ACU +#define NRF_FICR_TRIM_GLOBAL_SAADC_CALIREF 0x3B0U +#define NRF_FICR_TRIM_GLOBAL_SAADC_CALVREFTC 0x3B4U +#define NRF_FICR_TRIM_GLOBAL_NFCT_BIASCFG 0x3BCU +#define NRF_FICR_TRIM_GLOBAL_CANPLL_TRIM_CTUNE 0x3C0U +#define NRF_FICR_TRIM_GLOBAL_COMP_REFTRIM 0x3D0U +#define NRF_FICR_TRIM_GLOBAL_COMP_RCALTRIM 0x3D4U +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_VSUP 0x3D8U +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_COARSE_0 0x3DCU +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_COARSE_1 0x3E0U +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_COARSE_2 0x3E4U +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_COARSE_3 0x3E8U +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_COARSE_4 0x3ECU +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_COARSE_5 0x3F0U +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_FINE_0 0x3F4U +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_FINE_1 0x3F8U +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_FINE_2 0x3FCU +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_FINE_3 0x400U +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_FINE_4 0x404U +#define NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_FINE_5 0x408U +#define NRF_FICR_TRIM_APPLICATION_MEMCONF_BLOCKTYPE_0_TRIM 0x40CU +#define NRF_FICR_TRIM_APPLICATION_MEMCONF_BLOCKTYPE_1_TRIM 0x410U +#define NRF_FICR_TRIM_APPLICATION_MEMCONF_BLOCKTYPE_2_TRIM 0x414U +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_VSUP 0x418U +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_COARSE_0 0x41CU +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_COARSE_1 0x420U +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_COARSE_2 0x424U +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_COARSE_3 0x428U +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_COARSE_4 0x42CU +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_COARSE_5 0x430U +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_FINE_0 0x434U +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_FINE_1 0x438U +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_FINE_2 0x43CU +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_FINE_3 0x440U +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_FINE_4 0x444U +#define NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_FINE_5 0x448U +#define NRF_FICR_TRIM_RADIOCORE_MEMCONF_BLOCKTYPE_0_TRIM 0x44CU +#define NRF_FICR_TRIM_RADIOCORE_MEMCONF_BLOCKTYPE_1_TRIM 0x450U +#define NRF_FICR_TRIM_RADIOCORE_MEMCONF_BLOCKTYPE_2_TRIM 0x454U +#define NRF_FICR_TRIM_RADIOCORE_RADIO_SPHYNXANA_FSCTRL0 0x458U +#define NRF_FICR_TRIM_RADIOCORE_RADIO_SPHYNXANA_FSCTRL1 0x45CU +#define NRF_FICR_TRIM_RADIOCORE_RADIO_SPHYNXANA_FSCTRL2 0x460U +#define NRF_FICR_TRIM_RADIOCORE_RADIO_SPHYNXANA_RXCTRL 0x464U +#define NRF_FICR_TRIM_RADIOCORE_RADIO_SPHYNXANA_OVRRXTRIMCODE 0x468U +#define NRF_FICR_TRIM_RADIOCORE_RADIO_RXAGC_CALIBRATION 0x46CU +#define NRF_FICR_TRIM_RADIOCORE_RADIO_PVTTOT 0x470U +#define NRF_FICR_TRIM_RADIOCORE_RADIO_KDTC 0x474U +#define NRF_FICR_TRIM_RADIOCORE_RADIO_TXHFGAIN 0x478U +#define NRF_FICR_TRIM_RADIOCORE_RADIO_PVTTOFIX 0x47CU +#define NRF_FICR_TRIM_RADIOCORE_RADIO_LOOPGAIN 0x480U + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_MISC_NORDIC_NRF_FICR_NRF54H20_ENGA_H_ */ From 56f6642d5f46d67cda96b6d5187dc6c65ce705b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 31 Jan 2024 18:10:55 +0100 Subject: [PATCH 1237/1623] [nrf fromtree] dts: Add and extend Nordic bindings needed for nRF54H20 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a set of bindings that will be used in the nRF54H20 SoC definition. Extend the existing GPIOTE binding with properties needed for this SoC. Also do a tiny clean-up in the bindings added recently for nRF54L15 (HFXO and LFXO). Signed-off-by: Grzegorz Swiderski Signed-off-by: Gerard Marull-Paretas Signed-off-by: Andrzej Głąbek (cherry picked from commit 6bce7898291b86d8d5b1ea929e49fd7bd7a3988e) --- dts/bindings/arm/nordic,nrf-uicr-v2.yaml | 26 ++++++ dts/bindings/clock/nordic,nrf-hfxo.yaml | 2 +- dts/bindings/clock/nordic,nrf-hsfll.yaml | 65 ++++++++++++++ dts/bindings/clock/nordic,nrf-lfxo.yaml | 2 +- dts/bindings/cpu/nordic,vpr.yaml | 18 ++++ dts/bindings/gpio/nordic,nrf-gpiote.yaml | 4 +- .../interrupt-controller/nordic,nrf-clic.yaml | 19 ++++ dts/bindings/mtd/nordic,mram.yaml | 12 +++ dts/bindings/mtd/nordic,owned-partitions.yaml | 89 +++++++++++++++++++ .../reserved-memory/nordic,owned-memory.yaml | 46 ++++++++++ .../riscv/nordic,nrf-vpr-coprocessor.yaml | 29 ++++++ 11 files changed, 309 insertions(+), 3 deletions(-) create mode 100644 dts/bindings/arm/nordic,nrf-uicr-v2.yaml create mode 100644 dts/bindings/clock/nordic,nrf-hsfll.yaml create mode 100644 dts/bindings/cpu/nordic,vpr.yaml create mode 100644 dts/bindings/interrupt-controller/nordic,nrf-clic.yaml create mode 100644 dts/bindings/mtd/nordic,mram.yaml create mode 100644 dts/bindings/mtd/nordic,owned-partitions.yaml create mode 100644 dts/bindings/reserved-memory/nordic,owned-memory.yaml create mode 100644 dts/bindings/riscv/nordic,nrf-vpr-coprocessor.yaml diff --git a/dts/bindings/arm/nordic,nrf-uicr-v2.yaml b/dts/bindings/arm/nordic,nrf-uicr-v2.yaml new file mode 100644 index 00000000000..f509fdf4061 --- /dev/null +++ b/dts/bindings/arm/nordic,nrf-uicr-v2.yaml @@ -0,0 +1,26 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: Nordic UICR v2 (User Information Configuration Registers) + +compatible: "nordic,nrf-uicr-v2" + +include: base.yaml + +properties: + reg: + required: true + + domain: + type: int + required: true + description: | + Domain ID of the domain associated with this UICR instance. Must be unique + across all UICR instances in the system. + + ptr-ext-uicr: + type: phandle + required: true + description: | + Handle of a memory region reserved to contain an Extended UICR instance. + The address of that node will be stored in the UICR.PTREXTUICR register. diff --git a/dts/bindings/clock/nordic,nrf-hfxo.yaml b/dts/bindings/clock/nordic,nrf-hfxo.yaml index dc99c67e5cc..cd82e1c34d3 100644 --- a/dts/bindings/clock/nordic,nrf-hfxo.yaml +++ b/dts/bindings/clock/nordic,nrf-hfxo.yaml @@ -5,7 +5,7 @@ description: Nordic nRF high-frequency crystal oscillator compatible: "nordic,nrf-hfxo" -include: [fixed-clock.yaml] +include: fixed-clock.yaml properties: clock-frequency: diff --git a/dts/bindings/clock/nordic,nrf-hsfll.yaml b/dts/bindings/clock/nordic,nrf-hsfll.yaml new file mode 100644 index 00000000000..3614d80870f --- /dev/null +++ b/dts/bindings/clock/nordic,nrf-hsfll.yaml @@ -0,0 +1,65 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + Nordic nRF HSFLL + + The HSFLL mixed-mode IP generates several clock frequencies in the range from + 64 MHz to 400 MHz (in steps of 16 MHz). + + Usage example: + + hsfll: clock@deadbeef { + compatible = "nordic,nrf-hsfll"; + reg = <0xdeadbeef 0x1000>; + clocks = <&fll16m>; + clock-frequency = ; + nordic,ficrs = <&ficr NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_VSUP>, + <&ficr NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_COARSE_0>, + <&ficr NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_FINE_0>; + nordic,ficr-names = "vsup", "coarse", "fine"; + }; + + Required FICR entries are for VSUP, COARSE and FINE trim values. + +compatible: "nordic,nrf-hsfll" + +include: [base.yaml, fixed-clock.yaml, nordic-nrf-ficr-client.yaml] + +properties: + reg: + required: true + + clocks: + required: true + + clock-frequency: + enum: + - 64000000 + - 80000000 + - 96000000 + - 112000000 + - 128000000 + - 144000000 + - 160000000 + - 176000000 + - 192000000 + - 208000000 + - 224000000 + - 240000000 + - 256000000 + - 272000000 + - 288000000 + - 304000000 + - 320000000 + - 336000000 + - 352000000 + - 368000000 + - 384000000 + - 400000000 + + nordic,ficrs: + required: true + + nordic,ficr-names: + required: true diff --git a/dts/bindings/clock/nordic,nrf-lfxo.yaml b/dts/bindings/clock/nordic,nrf-lfxo.yaml index f0090ff4a81..328c374769c 100644 --- a/dts/bindings/clock/nordic,nrf-lfxo.yaml +++ b/dts/bindings/clock/nordic,nrf-lfxo.yaml @@ -5,7 +5,7 @@ description: Nordic nRF low-frequency crystal oscillator compatible: "nordic,nrf-lfxo" -include: [fixed-clock.yaml] +include: fixed-clock.yaml properties: clock-frequency: diff --git a/dts/bindings/cpu/nordic,vpr.yaml b/dts/bindings/cpu/nordic,vpr.yaml new file mode 100644 index 00000000000..11146f89c51 --- /dev/null +++ b/dts/bindings/cpu/nordic,vpr.yaml @@ -0,0 +1,18 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: Nordic Semiconductor RISC-V VPR CPU + +compatible: "nordic,vpr" + +include: riscv,cpus.yaml + +properties: + nordic,bus-width: + type: int + enum: + - 32 + - 64 + required: true + description: + Bus width of the CPU. diff --git a/dts/bindings/gpio/nordic,nrf-gpiote.yaml b/dts/bindings/gpio/nordic,nrf-gpiote.yaml index cefc3385afe..4bb09574e9b 100644 --- a/dts/bindings/gpio/nordic,nrf-gpiote.yaml +++ b/dts/bindings/gpio/nordic,nrf-gpiote.yaml @@ -5,7 +5,9 @@ description: NRF5 GPIOTE node compatible: "nordic,nrf-gpiote" -include: base.yaml +include: + - base.yaml + - nordic,split-channels.yaml properties: reg: diff --git a/dts/bindings/interrupt-controller/nordic,nrf-clic.yaml b/dts/bindings/interrupt-controller/nordic,nrf-clic.yaml new file mode 100644 index 00000000000..f570e668ea5 --- /dev/null +++ b/dts/bindings/interrupt-controller/nordic,nrf-clic.yaml @@ -0,0 +1,19 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: Nordic VPR CLIC + +compatible: "nordic,nrf-clic" + +include: [interrupt-controller.yaml, base.yaml] + +properties: + reg: + required: true + + "#interrupt-cells": + const: 2 + +interrupt-cells: + - irq + - priority diff --git a/dts/bindings/mtd/nordic,mram.yaml b/dts/bindings/mtd/nordic,mram.yaml new file mode 100644 index 00000000000..dac7d14305d --- /dev/null +++ b/dts/bindings/mtd/nordic,mram.yaml @@ -0,0 +1,12 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: Nordic MRAM + +compatible: nordic,mram + +include: soc-nv-flash.yaml + +properties: + reg: + required: true diff --git a/dts/bindings/mtd/nordic,owned-partitions.yaml b/dts/bindings/mtd/nordic,owned-partitions.yaml new file mode 100644 index 00000000000..bf42c13346a --- /dev/null +++ b/dts/bindings/mtd/nordic,owned-partitions.yaml @@ -0,0 +1,89 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + Nordic Owned Partitions + + Memory partition table with permission attributes common to its partitions. + This is a special case of the Nordic Owned Memory binding. + + Every compatible node is expected to be a child of a memory node, where the + listed partitions belong. + + A single memory node can contain multiple partition tables, each with a + different set of permissions. For each such table, the smallest memory region + spanning the contained partitions will be recorded in the UICR. These regions + are allowed to contain gaps between the partitions, but this is discouraged. + + Example: + + mram1x: mram@e000000 { + compatible = "nordic,mram"; + reg = <0xe000000 0x200000>; + ... + + rx-partitions { + compatible = "nordic,owned-partitions"; + perm-read; + perm-execute; + #address-cells = <1>; + #size-cells = <1>; + + slot0_partition: partition@c0000 { + label = "image-0"; + reg = <0xc0000 0x40000>; + }; + }; + + rw-partitions { + compatible = "nordic,owned-partitions"; + perm-read; + perm-write; + #address-cells = <1>; + #size-cells = <1>; + + slot1_partition: partition@100000 { + label = "image-1"; + reg = <0x100000 0x50000>; + }; + storage_partition: partition@150000 { + label = "storage"; + reg = <0x150000 0x6000>; + }; + }; + }; + + From this example, two memory regions will be inferred: + + - 0x0E0C0000--0x0E100000, with read & execute permissions, containing the + partition labeled "image-0". + - 0x0E100000--0x0E156000, with read & write permissions, containing the + partitions labeled "image-1" and "storage". + +compatible: "nordic,owned-partitions" + +include: + - name: nordic,owned-memory.yaml + property-blocklist: + - reg + +properties: + "#address-cells": + required: true + + "#size-cells": + required: true + +child-binding: + description: | + Partitions in the table are defined as subnodes. Each partition must have a + size and an offset relative to the base address of the parent memory node. + + include: + - name: base.yaml + property-blocklist: + - compatible + + properties: + reg: + required: true diff --git a/dts/bindings/reserved-memory/nordic,owned-memory.yaml b/dts/bindings/reserved-memory/nordic,owned-memory.yaml new file mode 100644 index 00000000000..9b13c965ac8 --- /dev/null +++ b/dts/bindings/reserved-memory/nordic,owned-memory.yaml @@ -0,0 +1,46 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + Nordic Owned Memory + + Memory region with permission attributes. Each enabled region of this kind + will be recorded in the UICR of the compiled domain. Memory ownership and + access is then configured for the domain at boot time, based on the UICR. + +compatible: "nordic,owned-memory" + +include: base.yaml + +properties: + reg: + required: true + + owner-id: + type: int + description: | + Owner ID of the domain that will own this memory region. If not defined, + the ownership will default to the domain being compiled. + + Note: owner ID is not the same as domain ID; see the product specification + for details. + + perm-read: + type: boolean + description: Owner has read access to the region. + + perm-write: + type: boolean + description: Owner has write access to the region. + + perm-execute: + type: boolean + description: Owner can execute code from the region. + + perm-secure: + type: boolean + description: Owner has secure-only access to the region. + + non-secure-callable: + type: boolean + description: Memory region is used for non-secure-callable code. diff --git a/dts/bindings/riscv/nordic,nrf-vpr-coprocessor.yaml b/dts/bindings/riscv/nordic,nrf-vpr-coprocessor.yaml new file mode 100644 index 00000000000..6be94dce25d --- /dev/null +++ b/dts/bindings/riscv/nordic,nrf-vpr-coprocessor.yaml @@ -0,0 +1,29 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +compatible: "nordic,nrf-vpr-coprocessor" + +description: | + VPR coprocessor + + VPR is a RISC-V CPU implementation. VPR instances are exposed to other CPUs as + peripherals. + +include: base.yaml + +properties: + cpu: + type: int + description: | + Processor ID of the VPR core. + + execution-memory: + type: phandle + required: true + description: | + Memory area from which the VPR core will execute. + + source-memory: + type: phandle + description: | + Memory area or partition from which the VPR code will be loaded. From bdecfda0b9e9dfcf8595987848dbc60e6b818217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 31 Jan 2024 18:22:59 +0100 Subject: [PATCH 1238/1623] [nrf fromtree] dts: Add initial support for nRF54H20 EngA SoC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add definition of the nRF54H20 SoC revision EngA with its Application, Radio, and Peripheral Processor (PPR) cores and basic peripherals: GRTC, GPIOs, GPIOTE, and UARTs. Signed-off-by: Grzegorz Swiderski Signed-off-by: Gerard Marull-Paretas Signed-off-by: Andrzej Głąbek (cherry picked from commit 50d56c9503cfcd1c75d83f095d04c8b221d9076f) --- dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi | 38 +++ dts/arm/nordic/nrf54h20_enga_cpurad.dtsi | 38 +++ dts/common/nordic/nrf54h20_enga.dtsi | 310 +++++++++++++++++++++ dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi | 35 +++ 4 files changed, 421 insertions(+) create mode 100644 dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi create mode 100644 dts/arm/nordic/nrf54h20_enga_cpurad.dtsi create mode 100644 dts/common/nordic/nrf54h20_enga.dtsi create mode 100644 dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi diff --git a/dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi b/dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi new file mode 100644 index 00000000000..f51528d5733 --- /dev/null +++ b/dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +cpu: &cpuapp {}; +systick: &cpuapp_systick {}; +nvic: &cpuapp_nvic {}; + +/delete-node/ &cpuppr; +/delete-node/ &cpurad; +/delete-node/ &cpurad_peripherals; +/delete-node/ &cpurad_ppb; +/delete-node/ &cpurad_ram0; + +/ { + soc { + compatible = "simple-bus"; + interrupt-parent = <&cpuapp_nvic>; + ranges; + }; +}; + +&cpuapp_ppb { + compatible = "simple-bus"; + ranges; +}; + +&gpiote130 { + interrupts = <105 NRF_DEFAULT_IRQ_PRIORITY>; +}; + +&grtc { + interrupts = <109 NRF_DEFAULT_IRQ_PRIORITY>; +}; diff --git a/dts/arm/nordic/nrf54h20_enga_cpurad.dtsi b/dts/arm/nordic/nrf54h20_enga_cpurad.dtsi new file mode 100644 index 00000000000..cb2767381da --- /dev/null +++ b/dts/arm/nordic/nrf54h20_enga_cpurad.dtsi @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +cpu: &cpurad {}; +systick: &cpurad_systick {}; +nvic: &cpurad_nvic {}; + +/delete-node/ &cpuapp; +/delete-node/ &cpuapp_peripherals; +/delete-node/ &cpuapp_ppb; +/delete-node/ &cpuapp_ram0; +/delete-node/ &cpuppr; + +/ { + soc { + compatible = "simple-bus"; + interrupt-parent = <&cpurad_nvic>; + ranges; + }; +}; + +&cpurad_ppb { + compatible = "simple-bus"; + ranges; +}; + +&gpiote130 { + interrupts = <105 NRF_DEFAULT_IRQ_PRIORITY>; +}; + +&grtc { + interrupts = <109 NRF_DEFAULT_IRQ_PRIORITY>; +}; diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi new file mode 100644 index 00000000000..1b8f7b6f9e8 --- /dev/null +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +/delete-node/ &sw_pwm; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpuapp: cpu@2 { + compatible = "arm,cortex-m33"; + reg = <2>; + device_type = "cpu"; + clock-frequency = ; + }; + + cpurad: cpu@3 { + compatible = "arm,cortex-m33"; + reg = <3>; + device_type = "cpu"; + clock-frequency = ; + }; + + cpuppr: cpu@d { + compatible = "nordic,vpr"; + reg = <13>; + device_type = "cpu"; + clock-frequency = ; + riscv,isa = "rv32emc"; + nordic,bus-width = <32>; + }; + }; + + reserved-memory { + #address-cells = <1>; + #size-cells = <1>; + + cpurad_uicr_ext: memory@e1ff000 { + reg = <0xe1ff000 DT_SIZE_K(2)>; + }; + + cpuapp_uicr_ext: memory@e1ff800 { + reg = <0xe1ff800 DT_SIZE_K(2)>; + }; + }; + + clocks { + fll16m: fll16m { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = ; + }; + }; + + soc { + #address-cells = <1>; + #size-cells = <1>; + + mram1x: mram@e000000 { + compatible = "nordic,mram"; + reg = <0xe000000 DT_SIZE_K(2048)>; + write-block-size = <16>; + }; + + cpuapp_uicr: uicr@fff8000 { + compatible = "nordic,nrf-uicr-v2"; + reg = <0xfff8000 DT_SIZE_K(2)>; + domain = <2>; + ptr-ext-uicr = <&cpuapp_uicr_ext>; + }; + + cpurad_uicr: uicr@fffa000 { + compatible = "nordic,nrf-uicr-v2"; + reg = <0xfffa000 DT_SIZE_K(2)>; + domain = <3>; + ptr-ext-uicr = <&cpurad_uicr_ext>; + }; + + ficr: ficr@fffe000 { + compatible = "nordic,nrf-ficr"; + reg = <0xfffe000 DT_SIZE_K(2)>; + #nordic,ficr-cells = <1>; + }; + + cpuapp_ram0: sram@22000000 { + compatible = "mmio-sram"; + reg = <0x22000000 DT_SIZE_K(32)>; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x22000000 0x8000>; + }; + + cpurad_ram0: sram@23000000 { + compatible = "mmio-sram"; + reg = <0x23000000 DT_SIZE_K(64)>; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x23000000 0x10000>; + }; + + cpuapp_peripherals: peripheral@52000000 { + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x52000000 0x1000000>; + + cpuapp_hsfll: clock@d000 { + compatible = "nordic,nrf-hsfll"; + #clock-cells = <0>; + reg = <0xd000 0x1000>; + clocks = <&fll16m>; + clock-frequency = ; + nordic,ficrs = + <&ficr NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_VSUP>, + <&ficr NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_COARSE_0>, + <&ficr NRF_FICR_TRIM_APPLICATION_HSFLL_TRIM_FINE_0>; + nordic,ficr-names = "vsup", "coarse", "fine"; + }; + }; + + cpurad_peripherals: peripheral@53000000 { + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x53000000 0x1000000>; + + cpurad_hsfll: clock@d000 { + compatible = "nordic,nrf-hsfll"; + #clock-cells = <0>; + reg = <0xd000 0x1000>; + clocks = <&fll16m>; + clock-frequency = ; + nordic,ficrs = + <&ficr NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_VSUP>, + <&ficr NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_COARSE_1>, + <&ficr NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_FINE_1>; + nordic,ficr-names = "vsup", "coarse", "fine"; + }; + }; + + global_peripherals: peripheral@5f000000 { + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x5f000000 0x1000000>; + + cpuppr_vpr: vpr@908000 { + compatible = "nordic,nrf-vpr-coprocessor"; + reg = <0x908000 0x1000>; + status = "disabled"; + cpu = <13>; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x908000 0x4000>; + + cpuppr_clic: interrupt-controller@1000 { + compatible = "nordic,nrf-clic"; + reg = <0x1000 0x3000>; + status = "disabled"; + #interrupt-cells = <2>; + interrupt-controller; + #address-cells = <1>; + }; + }; + + gpiote130: gpiote@934000 { + compatible = "nordic,nrf-gpiote"; + reg = <0x934000 0x1000>; + status = "disabled"; + instance = <130>; + }; + + gpio0: gpio@938000 { + compatible = "nordic,nrf-gpio"; + reg = <0x938000 0x200>; + status = "disabled"; + #gpio-cells = <2>; + gpio-controller; + gpiote-instance = <&gpiote130>; + ngpios = <12>; + port = <0>; + }; + + gpio1: gpio@938200 { + compatible = "nordic,nrf-gpio"; + reg = <0x938200 0x200>; + status = "disabled"; + #gpio-cells = <2>; + gpio-controller; + gpiote-instance = <&gpiote130>; + ngpios = <12>; + port = <1>; + }; + + gpio2: gpio@938400 { + compatible = "nordic,nrf-gpio"; + reg = <0x938400 0x200>; + status = "disabled"; + #gpio-cells = <2>; + gpio-controller; + gpiote-instance = <&gpiote130>; + ngpios = <12>; + port = <2>; + }; + + gpio6: gpio@938c00 { + compatible = "nordic,nrf-gpio"; + reg = <0x938c00 0x200>; + status = "disabled"; + #gpio-cells = <2>; + gpio-controller; + ngpios = <14>; + port = <6>; + }; + + gpio7: gpio@938e00 { + compatible = "nordic,nrf-gpio"; + reg = <0x938e00 0x200>; + status = "disabled"; + #gpio-cells = <2>; + gpio-controller; + ngpios = <8>; + port = <7>; + }; + + gpio9: gpio@939200 { + compatible = "nordic,nrf-gpio"; + reg = <0x939200 0x200>; + status = "disabled"; + #gpio-cells = <2>; + gpio-controller; + gpiote-instance = <&gpiote130>; + ngpios = <6>; + port = <9>; + }; + + grtc: grtc@99c000 { + compatible = "nordic,nrf-grtc"; + reg = <0x99c000 0x1000>; + status = "disabled"; + cc-num = <16>; + }; + + uart135: uart@9c6000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9c6000 0x1000>; + status = "disabled"; + current-speed = <115200>; + interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + uart136: uart@9d5000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9d5000 0x1000>; + status = "disabled"; + current-speed = <115200>; + interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; + }; + }; + }; + + cpuapp_ppb: cpuapp-ppb-bus { + #address-cells = <1>; + #size-cells = <1>; + + cpuapp_systick: timer@e000e010 { + compatible = "arm,armv8m-systick"; + reg = <0xe000e010 0x10>; + status = "disabled"; + }; + + cpuapp_nvic: interrupt-controller@e000e100 { + compatible = "arm,v8m-nvic"; + reg = <0xe000e100 0xc00>; + arm,num-irq-priority-bits = <3>; + #interrupt-cells = <2>; + interrupt-controller; + #address-cells = <1>; + }; + }; + + cpurad_ppb: cpurad-ppb-bus { + #address-cells = <1>; + #size-cells = <1>; + + cpurad_systick: timer@e000e010 { + compatible = "arm,armv8m-systick"; + reg = <0xe000e010 0x10>; + status = "disabled"; + }; + + cpurad_nvic: interrupt-controller@e000e100 { + compatible = "arm,v8m-nvic"; + reg = <0xe000e100 0xc00>; + arm,num-irq-priority-bits = <3>; + #interrupt-cells = <2>; + interrupt-controller; + #address-cells = <1>; + }; + }; +}; diff --git a/dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi b/dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi new file mode 100644 index 00000000000..d42a815a4b2 --- /dev/null +++ b/dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +cpu: &cpuppr {}; +clic: &cpuppr_clic {}; + +/delete-node/ &cpuapp; +/delete-node/ &cpuapp_peripherals; +/delete-node/ &cpuapp_ppb; +/delete-node/ &cpuapp_ram0; +/delete-node/ &cpurad; +/delete-node/ &cpurad_peripherals; +/delete-node/ &cpurad_ppb; +/delete-node/ &cpurad_ram0; + +/ { + soc { + compatible = "simple-bus"; + interrupt-parent = <&cpuppr_clic>; + ranges; + }; +}; + +&gpiote130 { + interrupts = <104 NRF_DEFAULT_IRQ_PRIORITY>; +}; + +&grtc { + interrupts = <108 NRF_DEFAULT_IRQ_PRIORITY>; +}; From 02298edda42fa45f0d576d2aaf4831efbfb8ed35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 31 Jan 2024 18:34:10 +0100 Subject: [PATCH 1239/1623] [nrf fromtree] modules: hal_nordic: nrfx_glue: Include cmsis_core_m_defaults.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... to cover missing __ICACHE_PRESENT and __DCACHE_PRESENT symbols that should be defined in MDK files. Signed-off-by: Andrzej Głąbek (cherry picked from commit 2efd34bda32febd07d9618ebb0683a445d3abb62) --- modules/hal_nordic/nrfx/nrfx_glue.h | 7 +++++++ soc/arm/nordic_nrf/nrf54l/soc.h | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/hal_nordic/nrfx/nrfx_glue.h b/modules/hal_nordic/nrfx/nrfx_glue.h index 2257ea879a3..851cb8a9614 100644 --- a/modules/hal_nordic/nrfx/nrfx_glue.h +++ b/modules/hal_nordic/nrfx/nrfx_glue.h @@ -7,6 +7,13 @@ #ifndef NRFX_GLUE_H__ #define NRFX_GLUE_H__ +#if defined(CONFIG_CPU_CORTEX_M) +/* Workaround for missing __ICACHE_PRESENT and __DCACHE_PRESENT symbols in MDK + * SoC definitions. To be removed when this is fixed. + */ +#include +#endif + #include #include #include diff --git a/soc/arm/nordic_nrf/nrf54l/soc.h b/soc/arm/nordic_nrf/nrf54l/soc.h index 721e9336989..b775fa9d0f3 100644 --- a/soc/arm/nordic_nrf/nrf54l/soc.h +++ b/soc/arm/nordic_nrf/nrf54l/soc.h @@ -11,8 +11,6 @@ #ifndef _NORDICSEMI_NRF54L_SOC_H_ #define _NORDICSEMI_NRF54L_SOC_H_ -#define __ICACHE_PRESENT 1 - #include #define FLASH_PAGE_ERASE_MAX_TIME_US 8000UL From 48ca22f1d90cd11b43ee74b0afa8f368b4b7154b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Thu, 1 Feb 2024 09:40:57 +0100 Subject: [PATCH 1240/1623] [nrf fromtree] modules: hal_nordic: Use common nrfx_config section for GRTC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move code that prepares `NRFX_CONFIG_GRTC_*` definitions based on information from devicetree from the nRF54L15 nrfx_config header to the global one, so that the code can be used by nRF54H20, too. The checks that validate owned-channels and child-owned-channels DT properties are moved to the nrf_grtc_timer driver so that the global nrfx_config is not polluted unnecessarily. The default values in nrfx_config_nrf54l15_enga_application.h are restored to those from the corresponding template file. Signed-off-by: Andrzej Głąbek (cherry picked from commit 139b97a64af4414963cbe5de1f0fea3bc7a4f969) --- drivers/timer/nrf_grtc_timer.c | 14 ++++++- modules/hal_nordic/nrfx/nrfx_config.h | 21 ++++++++++ .../nrfx_config_nrf54l15_enga_application.h | 38 ++++++------------- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/drivers/timer/nrf_grtc_timer.c b/drivers/timer/nrf_grtc_timer.c index dc6ac410905..a706c04bae0 100644 --- a/drivers/timer/nrf_grtc_timer.c +++ b/drivers/timer/nrf_grtc_timer.c @@ -13,6 +13,18 @@ #include #include +#define GRTC_NODE DT_NODELABEL(grtc) + +/* Ensure that GRTC properties in devicetree are defined correctly. */ +#if !DT_NODE_HAS_PROP(GRTC_NODE, owned_channels) +#error GRTC owned-channels DT property is not defined +#endif +#define OWNED_CHANNELS_MASK NRFX_CONFIG_GRTC_MASK_DT(owned_channels) +#define CHILD_OWNED_CHANNELS_MASK NRFX_CONFIG_GRTC_MASK_DT(child_owned_channels) +#if ((OWNED_CHANNELS_MASK | CHILD_OWNED_CHANNELS_MASK) != OWNED_CHANNELS_MASK) +#error GRTC child-owned-channels DT property must be a subset of owned-channels +#endif + #define CHAN_COUNT NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS #define EXT_CHAN_COUNT (CHAN_COUNT - 1) /* The reset value of waketime is 1, which doesn't seem to work. @@ -22,8 +34,6 @@ #define WAKETIME (4) #define TIMEOUT (WAKETIME + 1) -#define GRTC_NODE DT_NODELABEL(grtc) - #ifndef GRTC_SYSCOUNTERL_VALUE_Msk #define GRTC_SYSCOUNTERL_VALUE_Msk GRTC_SYSCOUNTER_SYSCOUNTERL_VALUE_Msk #endif diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 543329b4a30..d315fd2622c 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -675,6 +675,27 @@ #define NRF_PERIPH(P) P##_S #endif +/* If the GRTC system timer driver is to be used, prepare definitions required + * by the nrfx_grtc driver (NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK and + * NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS) based on information from devicetree. + */ +#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_grtc) +#define NRFX_CONFIG_BIT_DT(node_id, prop, idx) \ + BIT(DT_PROP_BY_IDX(node_id, prop, idx)) +#define NRFX_CONFIG_GRTC_MASK_DT(prop) \ + (COND_CODE_1(DT_NODE_HAS_PROP(DT_INST(0, nordic_nrf_grtc), prop), \ + (DT_FOREACH_PROP_ELEM_SEP(DT_INST(0, nordic_nrf_grtc), prop, \ + NRFX_CONFIG_BIT_DT, (|))), \ + (0))) + +#define NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK \ + (NRFX_CONFIG_GRTC_MASK_DT(owned_channels) & \ + ~NRFX_CONFIG_GRTC_MASK_DT(child_owned_channels)) +#define NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS \ + (DT_PROP_LEN_OR(DT_INST(0, nordic_nrf_grtc), owned_channels, 0) - \ + DT_PROP_LEN_OR(DT_INST(0, nordic_nrf_grtc), child_owned_channels, 0)) +#endif /* DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_grtc) */ + #include #if defined(NRF51) #include diff --git a/modules/hal_nordic/nrfx/nrfx_config_nrf54l15_enga_application.h b/modules/hal_nordic/nrfx/nrfx_config_nrf54l15_enga_application.h index 46b0aa0eff7..a694a07955d 100644 --- a/modules/hal_nordic/nrfx/nrfx_config_nrf54l15_enga_application.h +++ b/modules/hal_nordic/nrfx/nrfx_config_nrf54l15_enga_application.h @@ -249,37 +249,21 @@ #define NRFX_GRTC_ENABLED 0 #endif +/** + * @brief NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS + * + * Integer value. + */ +#ifndef NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS +#define NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS 11 +#endif + /** * @brief GRTC CC channels ownership mask. */ #ifndef NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK -#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_grtc) -#if DT_NODE_HAS_PROP(DT_INST(0, nordic_nrf_grtc), owned_channels) -#define NRFX_CONFIG_BIT_DT(node_id, prop, idx) \ - BIT(DT_PROP_BY_IDX(node_id, prop, idx)) -#define NRFX_CONFIG_GRTC_MASK_DT(prop) \ - (COND_CODE_1(DT_NODE_HAS_PROP(DT_INST(0, nordic_nrf_grtc), prop), \ - (DT_FOREACH_PROP_ELEM_SEP(DT_INST(0, nordic_nrf_grtc), prop, \ - NRFX_CONFIG_BIT_DT, (|))), \ - (0))) - -#define NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK \ - (NRFX_CONFIG_GRTC_MASK_DT(owned_channels) & \ - ~NRFX_CONFIG_GRTC_MASK_DT(child_owned_channels)) -#define NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS \ - (DT_PROP_LEN_OR(DT_INST(0, nordic_nrf_grtc), owned_channels, 0) - \ - DT_PROP_LEN_OR(DT_INST(0, nordic_nrf_grtc), child_owned_channels, 0)) - -#if ((NRFX_CONFIG_GRTC_MASK_DT(owned_channels) | \ - NRFX_CONFIG_GRTC_MASK_DT(child_owned_channels)) != NRFX_CONFIG_GRTC_MASK_DT(owned_channels)) -#error "`child-owned-channels` property must be a subset of `owned-channels` property" -#endif -#else -#error "property `owned-channels` does not exist" -#endif /* DT_NODE_HAS_PROP(DT_INST(0, nordic_nrf_grtc), owned_channels) */ -#endif /* DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_grtc) */ - -#endif /* NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK */ +#define NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK 0x000007ff +#endif /** * @brief NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY From 664240c23d847784f2a6956ba3f33d7729c02222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 23 Jan 2024 17:54:21 +0100 Subject: [PATCH 1241/1623] [nrf fromtree] soc: nordic: Add initial support for nRF54H20 EngA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add nrfx and Kconfig related infrastructure plus SoC initialization code to allow building for nRF54H20 targets (Application and Radio cores). Signed-off-by: Gerard Marull-Paretas Signed-off-by: Andrzej Głąbek (cherry picked from commit abb0934deffa16d6a11dd58559faaf2984f90285) --- modules/hal_nordic/nrfx/CMakeLists.txt | 6 + modules/hal_nordic/nrfx/nrfx_config.h | 4 + .../nrfx_config_nrf54h20_enga_application.h | 1935 ++++++++++++++++ .../nrfx_config_nrf54h20_enga_radiocore.h | 2016 +++++++++++++++++ soc/arm/nordic_nrf/Kconfig | 1 + soc/arm/nordic_nrf/Kconfig.defconfig | 2 +- soc/arm/nordic_nrf/nrf54h/CMakeLists.txt | 7 + .../nrf54h/Kconfig.defconfig.nrf54h20_cpuapp | 14 + .../nrf54h/Kconfig.defconfig.nrf54h20_cpurad | 14 + .../nrf54h/Kconfig.defconfig.series | 16 + soc/arm/nordic_nrf/nrf54h/Kconfig.series | 16 + soc/arm/nordic_nrf/nrf54h/Kconfig.soc | 37 + soc/arm/nordic_nrf/nrf54h/align.ld | 10 + soc/arm/nordic_nrf/nrf54h/soc.c | 104 + soc/arm/nordic_nrf/nrf54h/soc.h | 12 + 15 files changed, 4193 insertions(+), 1 deletion(-) create mode 100644 modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_application.h create mode 100644 modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_radiocore.h create mode 100644 soc/arm/nordic_nrf/nrf54h/CMakeLists.txt create mode 100644 soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpuapp create mode 100644 soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpurad create mode 100644 soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.series create mode 100644 soc/arm/nordic_nrf/nrf54h/Kconfig.series create mode 100644 soc/arm/nordic_nrf/nrf54h/Kconfig.soc create mode 100644 soc/arm/nordic_nrf/nrf54h/align.ld create mode 100644 soc/arm/nordic_nrf/nrf54h/soc.c create mode 100644 soc/arm/nordic_nrf/nrf54h/soc.h diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index 20740683a44..f2ddea1a23a 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -36,6 +36,11 @@ zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L15_ENGA_CPUAPP NRF_APPLICATION zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9120 NRF9120_XXAA) zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9160 NRF9160_XXAA) +zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54H20_ENGA_CPUAPP NRF54H20_ENGA_XXAA + NRF_APPLICATION) +zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54H20_ENGA_CPURAD NRF54H20_ENGA_XXAA + NRF_RADIOCORE) + zephyr_compile_definitions_ifdef(CONFIG_NRF_APPROTECT_LOCK ENABLE_APPROTECT) zephyr_compile_definitions_ifdef(CONFIG_NRF_APPROTECT_USER_HANDLING @@ -66,6 +71,7 @@ zephyr_library_sources_ifdef(CONFIG_SOC_NRF52833 ${MDK_DIR}/system_nrf5283 zephyr_library_sources_ifdef(CONFIG_SOC_NRF52840 ${MDK_DIR}/system_nrf52840.c) zephyr_library_sources_ifdef(CONFIG_SOC_NRF5340_CPUAPP ${MDK_DIR}/system_nrf5340_application.c) zephyr_library_sources_ifdef(CONFIG_SOC_NRF5340_CPUNET ${MDK_DIR}/system_nrf5340_network.c) +zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF54HX ${MDK_DIR}/system_nrf54h.c) zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF54LX ${MDK_DIR}/system_nrf54l.c) zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF91X ${MDK_DIR}/system_nrf91.c) diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index d315fd2622c..215eff5bfcd 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -717,6 +717,10 @@ #include #elif defined(NRF5340_XXAA_NETWORK) #include +#elif defined(NRF54H20_ENGA_XXAA) && defined(NRF_APPLICATION) + #include +#elif defined(NRF54H20_ENGA_XXAA) && defined(NRF_RADIOCORE) + #include #elif defined(NRF9120_XXAA) || defined(NRF9160_XXAA) #include #elif defined(NRF54L15_ENGA_XXAA) && defined(NRF_APPLICATION) diff --git a/modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_application.h b/modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_application.h new file mode 100644 index 00000000000..e6c79341b9a --- /dev/null +++ b/modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_application.h @@ -0,0 +1,1935 @@ +/* + * Copyright (c) 2024, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef NRFX_CONFIG_NRF54H20_ENGA_APPLICATION_H__ +#define NRFX_CONFIG_NRF54H20_ENGA_APPLICATION_H__ + +#ifndef NRFX_CONFIG_H__ +#error "This file should not be included directly. Include nrfx_config.h instead." +#endif + + +/** + * @brief NRFX_DEFAULT_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_DEFAULT_IRQ_PRIORITY +#define NRFX_DEFAULT_IRQ_PRIORITY 7 +#endif + +/** + * @brief NRFX_BELLBOARD_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_BELLBOARD_ENABLED +#define NRFX_BELLBOARD_ENABLED 0 +#endif + +/** + * @brief NRFX_BELLBOARD_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_BELLBOARD_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_BELLBOARD_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_BELLBOARD0_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_BELLBOARD0_ENABLED +#define NRFX_BELLBOARD0_ENABLED 0 +#endif + +/** + * @brief NRFX_BELLBOARD1_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_BELLBOARD1_ENABLED +#define NRFX_BELLBOARD1_ENABLED 0 +#endif + +/** + * @brief NRFX_BELLBOARD2_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_BELLBOARD2_ENABLED +#define NRFX_BELLBOARD2_ENABLED 0 +#endif + +/** + * @brief NRFX_BELLBOARD3_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_BELLBOARD3_ENABLED +#define NRFX_BELLBOARD3_ENABLED 0 +#endif + +/** + * @brief NRFX_COMP_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_COMP_ENABLED +#define NRFX_COMP_ENABLED 0 +#endif + +/** + * @brief NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_COMP_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_COMP_CONFIG_LOG_ENABLED +#define NRFX_COMP_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_COMP_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_COMP_CONFIG_LOG_LEVEL +#define NRFX_COMP_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_DPPI_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_DPPI_ENABLED +#define NRFX_DPPI_ENABLED 0 +#endif + +/** + * @brief NRFX_DPPI_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_DPPI_CONFIG_LOG_ENABLED +#define NRFX_DPPI_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_DPPI_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_DPPI_CONFIG_LOG_LEVEL +#define NRFX_DPPI_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_DPPI120_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI120_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI120_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000f0 +#endif + +/** + * @brief NRFX_DPPI130_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI130_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI130_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000ff +#endif + +/** + * @brief NRFX_DPPI131_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI131_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI131_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_DPPI132_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI132_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI132_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_DPPI133_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI133_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI133_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000001e +#endif + +/** + * @brief NRFX_DPPI134_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI134_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI134_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000020 +#endif + +/** + * @brief NRFX_DPPI135_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI135_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI135_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000040 +#endif + +/** + * @brief NRFX_DPPI136_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI136_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI136_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000081 +#endif + +/** + * @brief NRFX_DPPI120_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI120_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI120_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000000f +#endif + +/** + * @brief NRFX_DPPI130_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI130_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI130_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000ff +#endif + +/** + * @brief NRFX_DPPI131_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI131_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI131_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000ff +#endif + +/** + * @brief NRFX_DPPI132_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI132_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI132_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_DPPI133_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI133_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI133_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000e1 +#endif + +/** + * @brief NRFX_DPPI134_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI134_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI134_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000df +#endif + +/** + * @brief NRFX_DPPI135_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI135_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI135_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000bf +#endif + +/** + * @brief NRFX_DPPI136_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI136_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI136_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000007e +#endif + +/** + * @brief NRFX_GPIOTE_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GPIOTE_ENABLED +#define NRFX_GPIOTE_ENABLED 0 +#endif + +/** + * @brief NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS + * + * Integer value. Minimum: 0. Maximum: 15. + */ +#ifndef NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS +#define NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS 1 +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GPIOTE_CONFIG_LOG_ENABLED +#define NRFX_GPIOTE_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_GPIOTE_CONFIG_LOG_LEVEL +#define NRFX_GPIOTE_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_GPIOTE130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GPIOTE130_ENABLED +#define NRFX_GPIOTE130_ENABLED 0 +#endif + +/** + * @brief NRFX_GRTC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GRTC_ENABLED +#define NRFX_GRTC_ENABLED 0 +#endif + +/** + * @brief NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS + * + * Integer value. + */ +#ifndef NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS +#define NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS 4 +#endif + +/** + * @brief NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK + */ +#ifndef NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK +#define NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK 0x000000f0 +#endif + +/** + * @brief NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_GRTC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GRTC_CONFIG_LOG_ENABLED +#define NRFX_GRTC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_GRTC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_GRTC_CONFIG_LOG_LEVEL +#define NRFX_GRTC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_I2S_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S_ENABLED +#define NRFX_I2S_ENABLED 0 +#endif + +/** + * @brief NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_I2S_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S_CONFIG_LOG_ENABLED +#define NRFX_I2S_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_I2S_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_I2S_CONFIG_LOG_LEVEL +#define NRFX_I2S_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_I2S130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S130_ENABLED +#define NRFX_I2S130_ENABLED 0 +#endif + +/** + * @brief NRFX_I2S131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S131_ENABLED +#define NRFX_I2S131_ENABLED 0 +#endif + +/** + * @brief NRFX_IPCT_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000003 +#endif + +/** + * @brief NRFX_IPCT120_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT120_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT120_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_IPCT130_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT130_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT130_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000000c +#endif + +/** + * @brief NRFX_IPCT_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000000c +#endif + +/** + * @brief NRFX_IPCT120_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT120_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT120_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_IPCT130_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT130_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT130_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000003 +#endif + +/** + * @brief NRFX_LPCOMP_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_LPCOMP_ENABLED +#define NRFX_LPCOMP_ENABLED 0 +#endif + +/** + * @brief NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_LPCOMP_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_LPCOMP_CONFIG_LOG_ENABLED +#define NRFX_LPCOMP_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_LPCOMP_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_LPCOMP_CONFIG_LOG_LEVEL +#define NRFX_LPCOMP_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_MVDMA_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_MVDMA_ENABLED +#define NRFX_MVDMA_ENABLED 0 +#endif + +/** + * @brief NRFX_NFCT_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_NFCT_ENABLED +#define NRFX_NFCT_ENABLED 0 +#endif + +/** + * @brief NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID - Timer instance used for workarounds in the driver. + * + * Integer value. Minimum: 0. Maximum: 5. + */ +#ifndef NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID +#define NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID 0 +#endif + +/** + * @brief NRFX_NFCT_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_NFCT_CONFIG_LOG_ENABLED +#define NRFX_NFCT_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_NFCT_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_NFCT_CONFIG_LOG_LEVEL +#define NRFX_NFCT_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PDM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PDM_ENABLED +#define NRFX_PDM_ENABLED 0 +#endif + +/** + * @brief NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_PDM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PDM_CONFIG_LOG_ENABLED +#define NRFX_PDM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PDM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PDM_CONFIG_LOG_LEVEL +#define NRFX_PDM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PRS_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_ENABLED +#define NRFX_PRS_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_CONFIG_LOG_ENABLED +#define NRFX_PRS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PRS_CONFIG_LOG_LEVEL +#define NRFX_PRS_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PRS_BOX_0_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_0_ENABLED +#define NRFX_PRS_BOX_0_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_1_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_1_ENABLED +#define NRFX_PRS_BOX_1_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_2_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_2_ENABLED +#define NRFX_PRS_BOX_2_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_3_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_3_ENABLED +#define NRFX_PRS_BOX_3_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_4_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_4_ENABLED +#define NRFX_PRS_BOX_4_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_5_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_5_ENABLED +#define NRFX_PRS_BOX_5_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_6_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_6_ENABLED +#define NRFX_PRS_BOX_6_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_7_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_7_ENABLED +#define NRFX_PRS_BOX_7_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_8_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_8_ENABLED +#define NRFX_PRS_BOX_8_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_9_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_9_ENABLED +#define NRFX_PRS_BOX_9_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM_ENABLED +#define NRFX_PWM_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_PWM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM_CONFIG_LOG_ENABLED +#define NRFX_PWM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PWM_CONFIG_LOG_LEVEL +#define NRFX_PWM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PWM120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM120_ENABLED +#define NRFX_PWM120_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM130_ENABLED +#define NRFX_PWM130_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM131_ENABLED +#define NRFX_PWM131_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM132_ENABLED +#define NRFX_PWM132_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM133_ENABLED +#define NRFX_PWM133_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC_ENABLED +#define NRFX_QDEC_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_QDEC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC_CONFIG_LOG_ENABLED +#define NRFX_QDEC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_QDEC_CONFIG_LOG_LEVEL +#define NRFX_QDEC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_QDEC130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC130_ENABLED +#define NRFX_QDEC130_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC131_ENABLED +#define NRFX_QDEC131_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC_ENABLED +#define NRFX_RTC_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_RTC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC_CONFIG_LOG_ENABLED +#define NRFX_RTC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_RTC_CONFIG_LOG_LEVEL +#define NRFX_RTC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_RTC130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC130_ENABLED +#define NRFX_RTC130_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC131_ENABLED +#define NRFX_RTC131_ENABLED 0 +#endif + +/** + * @brief NRFX_SAADC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SAADC_ENABLED +#define NRFX_SAADC_ENABLED 0 +#endif + +/** + * @brief NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_SAADC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SAADC_CONFIG_LOG_ENABLED +#define NRFX_SAADC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SAADC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SAADC_CONFIG_LOG_LEVEL +#define NRFX_SAADC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_SPIM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM_ENABLED +#define NRFX_SPIM_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_SPIM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM_CONFIG_LOG_ENABLED +#define NRFX_SPIM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SPIM_CONFIG_LOG_LEVEL +#define NRFX_SPIM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_SPIM120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM120_ENABLED +#define NRFX_SPIM120_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM121_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM121_ENABLED +#define NRFX_SPIM121_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM130_ENABLED +#define NRFX_SPIM130_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM131_ENABLED +#define NRFX_SPIM131_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM132_ENABLED +#define NRFX_SPIM132_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM133_ENABLED +#define NRFX_SPIM133_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM134_ENABLED +#define NRFX_SPIM134_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM135_ENABLED +#define NRFX_SPIM135_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM136_ENABLED +#define NRFX_SPIM136_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM137_ENABLED +#define NRFX_SPIM137_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS_ENABLED +#define NRFX_SPIS_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_SPIS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS_CONFIG_LOG_ENABLED +#define NRFX_SPIS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SPIS_CONFIG_LOG_LEVEL +#define NRFX_SPIS_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_SPIS120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS120_ENABLED +#define NRFX_SPIS120_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS130_ENABLED +#define NRFX_SPIS130_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS131_ENABLED +#define NRFX_SPIS131_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS132_ENABLED +#define NRFX_SPIS132_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS133_ENABLED +#define NRFX_SPIS133_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS134_ENABLED +#define NRFX_SPIS134_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS135_ENABLED +#define NRFX_SPIS135_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS136_ENABLED +#define NRFX_SPIS136_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS137_ENABLED +#define NRFX_SPIS137_ENABLED 0 +#endif + +/** + * @brief NRFX_SYSTICK_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SYSTICK_ENABLED +#define NRFX_SYSTICK_ENABLED 0 +#endif + +/** + * @brief NRFX_TEMP_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TEMP_ENABLED +#define NRFX_TEMP_ENABLED 0 +#endif + +/** + * @brief NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TEMP_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TEMP_CONFIG_LOG_ENABLED +#define NRFX_TEMP_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TEMP_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TEMP_CONFIG_LOG_LEVEL +#define NRFX_TEMP_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TIMER_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER_ENABLED +#define NRFX_TIMER_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TIMER_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER_CONFIG_LOG_ENABLED +#define NRFX_TIMER_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TIMER_CONFIG_LOG_LEVEL +#define NRFX_TIMER_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TIMER120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER120_ENABLED +#define NRFX_TIMER120_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER121_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER121_ENABLED +#define NRFX_TIMER121_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER130_ENABLED +#define NRFX_TIMER130_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER131_ENABLED +#define NRFX_TIMER131_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER132_ENABLED +#define NRFX_TIMER132_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER133_ENABLED +#define NRFX_TIMER133_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER134_ENABLED +#define NRFX_TIMER134_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER135_ENABLED +#define NRFX_TIMER135_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER136_ENABLED +#define NRFX_TIMER136_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER137_ENABLED +#define NRFX_TIMER137_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM_ENABLED +#define NRFX_TWIM_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TWIM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM_CONFIG_LOG_ENABLED +#define NRFX_TWIM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TWIM_CONFIG_LOG_LEVEL +#define NRFX_TWIM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TWIM130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM130_ENABLED +#define NRFX_TWIM130_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM131_ENABLED +#define NRFX_TWIM131_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM132_ENABLED +#define NRFX_TWIM132_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM133_ENABLED +#define NRFX_TWIM133_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM134_ENABLED +#define NRFX_TWIM134_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM135_ENABLED +#define NRFX_TWIM135_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM136_ENABLED +#define NRFX_TWIM136_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM137_ENABLED +#define NRFX_TWIM137_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_ENABLED +#define NRFX_TWIS_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TWIS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_CONFIG_LOG_ENABLED +#define NRFX_TWIS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY - Assume that any instance + * would be initialized only once. + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY +#define NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY 0 +#endif + +/** + * @brief NRFX_TWIS_NO_SYNC_MODE - Remove support for synchronous mode. + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_NO_SYNC_MODE +#define NRFX_TWIS_NO_SYNC_MODE 0 +#endif + +/** + * @brief NRFX_TWIS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TWIS_CONFIG_LOG_LEVEL +#define NRFX_TWIS_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TWIS130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS130_ENABLED +#define NRFX_TWIS130_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS131_ENABLED +#define NRFX_TWIS131_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS132_ENABLED +#define NRFX_TWIS132_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS133_ENABLED +#define NRFX_TWIS133_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS134_ENABLED +#define NRFX_TWIS134_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS135_ENABLED +#define NRFX_TWIS135_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS136_ENABLED +#define NRFX_TWIS136_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS137_ENABLED +#define NRFX_TWIS137_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_ENABLED +#define NRFX_UARTE_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG - If enabled, support for + * configuring GPIO pins is removed from the driver + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG +#define NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG - If enabled, support for + * configuring PSEL registers is removed from the driver + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG +#define NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_TX_LINK - If enabled, driver supports linking + * of TX transfers. + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_TX_LINK +#define NRFX_UARTE_CONFIG_TX_LINK 1 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_RX_CACHE_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_RX_CACHE_ENABLED +#define NRFX_UARTE_CONFIG_RX_CACHE_ENABLED 1 +#endif + +/** + * @brief NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_UARTE_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_LOG_ENABLED +#define NRFX_UARTE_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_UARTE_CONFIG_LOG_LEVEL +#define NRFX_UARTE_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_UARTE120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE120_ENABLED +#define NRFX_UARTE120_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE130_ENABLED +#define NRFX_UARTE130_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE131_ENABLED +#define NRFX_UARTE131_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE132_ENABLED +#define NRFX_UARTE132_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE133_ENABLED +#define NRFX_UARTE133_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE134_ENABLED +#define NRFX_UARTE134_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE135_ENABLED +#define NRFX_UARTE135_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE136_ENABLED +#define NRFX_UARTE136_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE137_ENABLED +#define NRFX_UARTE137_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT_ENABLED +#define NRFX_WDT_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_WDT_CONFIG_NO_IRQ - Remove WDT IRQ handling from WDT driver + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT_CONFIG_NO_IRQ +#define NRFX_WDT_CONFIG_NO_IRQ 0 +#endif + +/** + * @brief NRFX_WDT_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT_CONFIG_LOG_ENABLED +#define NRFX_WDT_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_WDT_CONFIG_LOG_LEVEL +#define NRFX_WDT_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_WDT010_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT010_ENABLED +#define NRFX_WDT010_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT011_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT011_ENABLED +#define NRFX_WDT011_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT131_ENABLED +#define NRFX_WDT131_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT132_ENABLED +#define NRFX_WDT132_ENABLED 0 +#endif + +#endif /* NRFX_CONFIG_NRF54H20_ENGA_APPLICATION_H__ */ diff --git a/modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_radiocore.h b/modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_radiocore.h new file mode 100644 index 00000000000..7b9a1c4b733 --- /dev/null +++ b/modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_radiocore.h @@ -0,0 +1,2016 @@ +/* + * Copyright (c) 2024, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef NRFX_CONFIG_NRF54H20_ENGA_RADIOCORE_H__ +#define NRFX_CONFIG_NRF54H20_ENGA_RADIOCORE_H__ + +#ifndef NRFX_CONFIG_H__ +#error "This file should not be included directly. Include nrfx_config.h instead." +#endif + +/** + * @brief NRFX_DEFAULT_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_DEFAULT_IRQ_PRIORITY +#define NRFX_DEFAULT_IRQ_PRIORITY 7 +#endif + +/** + * @brief NRFX_BELLBOARD_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_BELLBOARD_ENABLED +#define NRFX_BELLBOARD_ENABLED 0 +#endif + +/** + * @brief NRFX_BELLBOARD_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_BELLBOARD_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_BELLBOARD_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_BELLBOARD0_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_BELLBOARD0_ENABLED +#define NRFX_BELLBOARD0_ENABLED 0 +#endif + +/** + * @brief NRFX_BELLBOARD1_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_BELLBOARD1_ENABLED +#define NRFX_BELLBOARD1_ENABLED 0 +#endif + +/** + * @brief NRFX_BELLBOARD2_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_BELLBOARD2_ENABLED +#define NRFX_BELLBOARD2_ENABLED 0 +#endif + +/** + * @brief NRFX_BELLBOARD3_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_BELLBOARD3_ENABLED +#define NRFX_BELLBOARD3_ENABLED 0 +#endif + +/** + * @brief NRFX_COMP_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_COMP_ENABLED +#define NRFX_COMP_ENABLED 0 +#endif + +/** + * @brief NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_COMP_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_COMP_CONFIG_LOG_ENABLED +#define NRFX_COMP_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_COMP_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_COMP_CONFIG_LOG_LEVEL +#define NRFX_COMP_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_DPPI_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_DPPI_ENABLED +#define NRFX_DPPI_ENABLED 0 +#endif + +/** + * @brief NRFX_DPPI_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_DPPI_CONFIG_LOG_ENABLED +#define NRFX_DPPI_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_DPPI_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_DPPI_CONFIG_LOG_LEVEL +#define NRFX_DPPI_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_DPPI020_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI020_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI020_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000003 +#endif + +/** + * @brief NRFX_DPPI030_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI030_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI030_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000003 +#endif + +/** + * @brief NRFX_DPPI120_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI120_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI120_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000f0 +#endif + +/** + * @brief NRFX_DPPI130_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI130_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI130_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000ff +#endif + +/** + * @brief NRFX_DPPI131_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI131_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI131_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_DPPI132_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI132_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI132_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_DPPI133_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI133_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI133_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000001e +#endif + +/** + * @brief NRFX_DPPI134_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI134_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI134_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000020 +#endif + +/** + * @brief NRFX_DPPI135_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI135_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI135_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000040 +#endif + +/** + * @brief NRFX_DPPI136_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI136_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI136_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000081 +#endif + +/** + * @brief NRFX_DPPI020_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI020_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI020_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000000c +#endif + +/** + * @brief NRFX_DPPI030_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI030_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI030_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000000c +#endif + +/** + * @brief NRFX_DPPI120_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI120_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI120_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000000f +#endif + +/** + * @brief NRFX_DPPI130_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI130_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI130_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000ff +#endif + +/** + * @brief NRFX_DPPI131_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI131_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI131_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000ff +#endif + +/** + * @brief NRFX_DPPI132_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI132_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI132_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_DPPI133_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI133_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI133_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000e1 +#endif + +/** + * @brief NRFX_DPPI134_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI134_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI134_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000df +#endif + +/** + * @brief NRFX_DPPI135_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI135_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI135_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000bf +#endif + +/** + * @brief NRFX_DPPI136_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI136_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI136_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000007e +#endif + +/** + * @brief NRFX_EGU_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_EGU_ENABLED +#define NRFX_EGU_ENABLED 0 +#endif + +/** + * @brief NRFX_EGU_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_EGU_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_EGU_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_EGU020_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_EGU020_ENABLED +#define NRFX_EGU020_ENABLED 0 +#endif + +/** + * @brief NRFX_GPIOTE_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GPIOTE_ENABLED +#define NRFX_GPIOTE_ENABLED 0 +#endif + +/** + * @brief NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS + * + * Integer value. Minimum: 0. Maximum: 15. + */ +#ifndef NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS +#define NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS 1 +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GPIOTE_CONFIG_LOG_ENABLED +#define NRFX_GPIOTE_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_GPIOTE_CONFIG_LOG_LEVEL +#define NRFX_GPIOTE_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_GPIOTE130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GPIOTE130_ENABLED +#define NRFX_GPIOTE130_ENABLED 0 +#endif + +/** + * @brief NRFX_GRTC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GRTC_ENABLED +#define NRFX_GRTC_ENABLED 0 +#endif + +/** + * @brief NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS + * + * Integer value. + */ +#ifndef NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS +#define NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS 4 +#endif + +/** + * @brief NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK + */ +#ifndef NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK +#define NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK 0x00000f00 +#endif + +/** + * @brief NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_GRTC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GRTC_CONFIG_LOG_ENABLED +#define NRFX_GRTC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_GRTC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_GRTC_CONFIG_LOG_LEVEL +#define NRFX_GRTC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_I2S_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S_ENABLED +#define NRFX_I2S_ENABLED 0 +#endif + +/** + * @brief NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_I2S_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S_CONFIG_LOG_ENABLED +#define NRFX_I2S_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_I2S_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_I2S_CONFIG_LOG_LEVEL +#define NRFX_I2S_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_I2S130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S130_ENABLED +#define NRFX_I2S130_ENABLED 0 +#endif + +/** + * @brief NRFX_I2S131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S131_ENABLED +#define NRFX_I2S131_ENABLED 0 +#endif + +/** + * @brief NRFX_IPCT_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000030 +#endif + +/** + * @brief NRFX_IPCT120_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT120_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT120_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_IPCT130_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT130_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT130_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000000c +#endif + +/** + * @brief NRFX_IPCT_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000c0 +#endif + +/** + * @brief NRFX_IPCT120_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT120_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT120_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_IPCT130_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT130_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT130_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000003 +#endif + +/** + * @brief NRFX_LPCOMP_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_LPCOMP_ENABLED +#define NRFX_LPCOMP_ENABLED 0 +#endif + +/** + * @brief NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_LPCOMP_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_LPCOMP_CONFIG_LOG_ENABLED +#define NRFX_LPCOMP_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_LPCOMP_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_LPCOMP_CONFIG_LOG_LEVEL +#define NRFX_LPCOMP_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_MVDMA_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_MVDMA_ENABLED +#define NRFX_MVDMA_ENABLED 0 +#endif + +/** + * @brief NRFX_NFCT_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_NFCT_ENABLED +#define NRFX_NFCT_ENABLED 0 +#endif + +/** + * @brief NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID - Timer instance used for workarounds in the driver. + * + * Integer value. Minimum: 0. Maximum: 5. + */ +#ifndef NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID +#define NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID 0 +#endif + +/** + * @brief NRFX_NFCT_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_NFCT_CONFIG_LOG_ENABLED +#define NRFX_NFCT_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_NFCT_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_NFCT_CONFIG_LOG_LEVEL +#define NRFX_NFCT_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PDM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PDM_ENABLED +#define NRFX_PDM_ENABLED 0 +#endif + +/** + * @brief NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_PDM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PDM_CONFIG_LOG_ENABLED +#define NRFX_PDM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PDM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PDM_CONFIG_LOG_LEVEL +#define NRFX_PDM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PRS_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_ENABLED +#define NRFX_PRS_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_CONFIG_LOG_ENABLED +#define NRFX_PRS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PRS_CONFIG_LOG_LEVEL +#define NRFX_PRS_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PRS_BOX_0_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_0_ENABLED +#define NRFX_PRS_BOX_0_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_1_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_1_ENABLED +#define NRFX_PRS_BOX_1_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_2_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_2_ENABLED +#define NRFX_PRS_BOX_2_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_3_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_3_ENABLED +#define NRFX_PRS_BOX_3_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_4_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_4_ENABLED +#define NRFX_PRS_BOX_4_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_5_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_5_ENABLED +#define NRFX_PRS_BOX_5_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_6_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_6_ENABLED +#define NRFX_PRS_BOX_6_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_7_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_7_ENABLED +#define NRFX_PRS_BOX_7_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_8_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_8_ENABLED +#define NRFX_PRS_BOX_8_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_9_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_9_ENABLED +#define NRFX_PRS_BOX_9_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM_ENABLED +#define NRFX_PWM_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_PWM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM_CONFIG_LOG_ENABLED +#define NRFX_PWM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PWM_CONFIG_LOG_LEVEL +#define NRFX_PWM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PWM120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM120_ENABLED +#define NRFX_PWM120_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM130_ENABLED +#define NRFX_PWM130_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM131_ENABLED +#define NRFX_PWM131_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM132_ENABLED +#define NRFX_PWM132_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM133_ENABLED +#define NRFX_PWM133_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC_ENABLED +#define NRFX_QDEC_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_QDEC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC_CONFIG_LOG_ENABLED +#define NRFX_QDEC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_QDEC_CONFIG_LOG_LEVEL +#define NRFX_QDEC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_QDEC130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC130_ENABLED +#define NRFX_QDEC130_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC131_ENABLED +#define NRFX_QDEC131_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC_ENABLED +#define NRFX_RTC_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_RTC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC_CONFIG_LOG_ENABLED +#define NRFX_RTC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_RTC_CONFIG_LOG_LEVEL +#define NRFX_RTC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_RTC130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC130_ENABLED +#define NRFX_RTC130_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC131_ENABLED +#define NRFX_RTC131_ENABLED 0 +#endif + +/** + * @brief NRFX_SAADC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SAADC_ENABLED +#define NRFX_SAADC_ENABLED 0 +#endif + +/** + * @brief NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_SAADC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SAADC_CONFIG_LOG_ENABLED +#define NRFX_SAADC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SAADC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SAADC_CONFIG_LOG_LEVEL +#define NRFX_SAADC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_SPIM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM_ENABLED +#define NRFX_SPIM_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_SPIM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM_CONFIG_LOG_ENABLED +#define NRFX_SPIM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SPIM_CONFIG_LOG_LEVEL +#define NRFX_SPIM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_SPIM120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM120_ENABLED +#define NRFX_SPIM120_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM121_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM121_ENABLED +#define NRFX_SPIM121_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM130_ENABLED +#define NRFX_SPIM130_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM131_ENABLED +#define NRFX_SPIM131_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM132_ENABLED +#define NRFX_SPIM132_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM133_ENABLED +#define NRFX_SPIM133_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM134_ENABLED +#define NRFX_SPIM134_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM135_ENABLED +#define NRFX_SPIM135_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM136_ENABLED +#define NRFX_SPIM136_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM137_ENABLED +#define NRFX_SPIM137_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS_ENABLED +#define NRFX_SPIS_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_SPIS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS_CONFIG_LOG_ENABLED +#define NRFX_SPIS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SPIS_CONFIG_LOG_LEVEL +#define NRFX_SPIS_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_SPIS120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS120_ENABLED +#define NRFX_SPIS120_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS130_ENABLED +#define NRFX_SPIS130_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS131_ENABLED +#define NRFX_SPIS131_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS132_ENABLED +#define NRFX_SPIS132_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS133_ENABLED +#define NRFX_SPIS133_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS134_ENABLED +#define NRFX_SPIS134_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS135_ENABLED +#define NRFX_SPIS135_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS136_ENABLED +#define NRFX_SPIS136_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS137_ENABLED +#define NRFX_SPIS137_ENABLED 0 +#endif + +/** + * @brief NRFX_SYSTICK_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SYSTICK_ENABLED +#define NRFX_SYSTICK_ENABLED 0 +#endif + +/** + * @brief NRFX_TEMP_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TEMP_ENABLED +#define NRFX_TEMP_ENABLED 0 +#endif + +/** + * @brief NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TEMP_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TEMP_CONFIG_LOG_ENABLED +#define NRFX_TEMP_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TEMP_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TEMP_CONFIG_LOG_LEVEL +#define NRFX_TEMP_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TIMER_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER_ENABLED +#define NRFX_TIMER_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TIMER_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER_CONFIG_LOG_ENABLED +#define NRFX_TIMER_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TIMER_CONFIG_LOG_LEVEL +#define NRFX_TIMER_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TIMER020_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER020_ENABLED +#define NRFX_TIMER020_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER021_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER021_ENABLED +#define NRFX_TIMER021_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER022_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER022_ENABLED +#define NRFX_TIMER022_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER120_ENABLED +#define NRFX_TIMER120_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER121_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER121_ENABLED +#define NRFX_TIMER121_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER130_ENABLED +#define NRFX_TIMER130_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER131_ENABLED +#define NRFX_TIMER131_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER132_ENABLED +#define NRFX_TIMER132_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER133_ENABLED +#define NRFX_TIMER133_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER134_ENABLED +#define NRFX_TIMER134_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER135_ENABLED +#define NRFX_TIMER135_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER136_ENABLED +#define NRFX_TIMER136_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER137_ENABLED +#define NRFX_TIMER137_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM_ENABLED +#define NRFX_TWIM_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TWIM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM_CONFIG_LOG_ENABLED +#define NRFX_TWIM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TWIM_CONFIG_LOG_LEVEL +#define NRFX_TWIM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TWIM130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM130_ENABLED +#define NRFX_TWIM130_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM131_ENABLED +#define NRFX_TWIM131_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM132_ENABLED +#define NRFX_TWIM132_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM133_ENABLED +#define NRFX_TWIM133_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM134_ENABLED +#define NRFX_TWIM134_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM135_ENABLED +#define NRFX_TWIM135_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM136_ENABLED +#define NRFX_TWIM136_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM137_ENABLED +#define NRFX_TWIM137_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_ENABLED +#define NRFX_TWIS_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TWIS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_CONFIG_LOG_ENABLED +#define NRFX_TWIS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY - Assume that any instance + * would be initialized only once. + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY +#define NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY 0 +#endif + +/** + * @brief NRFX_TWIS_NO_SYNC_MODE - Remove support for synchronous mode. + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_NO_SYNC_MODE +#define NRFX_TWIS_NO_SYNC_MODE 0 +#endif + +/** + * @brief NRFX_TWIS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TWIS_CONFIG_LOG_LEVEL +#define NRFX_TWIS_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TWIS130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS130_ENABLED +#define NRFX_TWIS130_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS131_ENABLED +#define NRFX_TWIS131_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS132_ENABLED +#define NRFX_TWIS132_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS133_ENABLED +#define NRFX_TWIS133_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS134_ENABLED +#define NRFX_TWIS134_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS135_ENABLED +#define NRFX_TWIS135_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS136_ENABLED +#define NRFX_TWIS136_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS137_ENABLED +#define NRFX_TWIS137_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_ENABLED +#define NRFX_UARTE_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG - If enabled, support for + * configuring GPIO pins is removed from the driver + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG +#define NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG - If enabled, support for + * configuring PSEL registers is removed from the driver + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG +#define NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_TX_LINK - If enabled, driver supports linking + * of TX transfers. + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_TX_LINK +#define NRFX_UARTE_CONFIG_TX_LINK 1 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_RX_CACHE_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_RX_CACHE_ENABLED +#define NRFX_UARTE_CONFIG_RX_CACHE_ENABLED 1 +#endif + +/** + * @brief NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_UARTE_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_LOG_ENABLED +#define NRFX_UARTE_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_UARTE_CONFIG_LOG_LEVEL +#define NRFX_UARTE_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_UARTE120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE120_ENABLED +#define NRFX_UARTE120_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE130_ENABLED +#define NRFX_UARTE130_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE131_ENABLED +#define NRFX_UARTE131_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE132_ENABLED +#define NRFX_UARTE132_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE133_ENABLED +#define NRFX_UARTE133_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE134_ENABLED +#define NRFX_UARTE134_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE135_ENABLED +#define NRFX_UARTE135_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE136_ENABLED +#define NRFX_UARTE136_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE137_ENABLED +#define NRFX_UARTE137_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT_ENABLED +#define NRFX_WDT_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 7. + */ +#ifndef NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_WDT_CONFIG_NO_IRQ - Remove WDT IRQ handling from WDT driver + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT_CONFIG_NO_IRQ +#define NRFX_WDT_CONFIG_NO_IRQ 0 +#endif + +/** + * @brief NRFX_WDT_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT_CONFIG_LOG_ENABLED +#define NRFX_WDT_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_WDT_CONFIG_LOG_LEVEL +#define NRFX_WDT_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_WDT010_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT010_ENABLED +#define NRFX_WDT010_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT011_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT011_ENABLED +#define NRFX_WDT011_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT131_ENABLED +#define NRFX_WDT131_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT132_ENABLED +#define NRFX_WDT132_ENABLED 0 +#endif + +#endif /* NRFX_CONFIG_NRF54H20_ENGA_RADIOCORE_H__ */ diff --git a/soc/arm/nordic_nrf/Kconfig b/soc/arm/nordic_nrf/Kconfig index 0372492cd7d..69d83ae5e9b 100644 --- a/soc/arm/nordic_nrf/Kconfig +++ b/soc/arm/nordic_nrf/Kconfig @@ -18,6 +18,7 @@ source "soc/arm/nordic_nrf/*/Kconfig.soc" config NRF_SOC_SECURE_SUPPORTED def_bool !TRUSTED_EXECUTION_NONSECURE || (BUILD_WITH_TFM && TFM_PARTITION_PLATFORM) + depends on !SOC_SERIES_NRF54HX help Hidden function to indicate that that the soc_secure functions are available. diff --git a/soc/arm/nordic_nrf/Kconfig.defconfig b/soc/arm/nordic_nrf/Kconfig.defconfig index 879217a92fe..ad3c97443ff 100644 --- a/soc/arm/nordic_nrf/Kconfig.defconfig +++ b/soc/arm/nordic_nrf/Kconfig.defconfig @@ -11,7 +11,7 @@ source "soc/arm/nordic_nrf/*/Kconfig.defconfig.series" if SYS_CLOCK_EXISTS config CLOCK_CONTROL - default y + default y if !SOC_SERIES_NRF54HX endif # SYS_CLOCK_EXISTS diff --git a/soc/arm/nordic_nrf/nrf54h/CMakeLists.txt b/soc/arm/nordic_nrf/nrf54h/CMakeLists.txt new file mode 100644 index 00000000000..8b4df42fa55 --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54h/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library_sources(soc.c) + +# Ensure that image size aligns with 16 bytes so that MRAMC finalizes all writes +# for the image correctly +zephyr_linker_sources(SECTIONS SORT_KEY zzz_place_align_at_end align.ld) diff --git a/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpuapp b/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpuapp new file mode 100644 index 00000000000..eb56b8c369e --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpuapp @@ -0,0 +1,14 @@ +# Nordic Semiconductor nRF54H20 Application MCU + +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_NRF54H20_ENGA_CPUAPP + +config SOC + default "nrf54h20_enga_cpuapp" + +config NUM_IRQS + default 471 + +endif # SOC_NRF54H20_ENGA_CPUAPP diff --git a/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpurad b/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpurad new file mode 100644 index 00000000000..f63b9437775 --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpurad @@ -0,0 +1,14 @@ +# Nordic Semiconductor nRF54H20 Radio MCU + +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_NRF54H20_ENGA_CPURAD + +config SOC + default "nrf54h20_enga_cpurad" + +config NUM_IRQS + default 471 + +endif # SOC_NRF54H20_ENGA_CPURAD diff --git a/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.series b/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.series new file mode 100644 index 00000000000..ddc902d213e --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.series @@ -0,0 +1,16 @@ +# Nordic Semiconductor nRF54H MCU line + +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_NRF54HX + +rsource "Kconfig.defconfig.nrf54h*" + +config SOC_SERIES + default "nrf54h" + +config CACHE_NRF_CACHE + default y if EXTERNAL_CACHE + +endif # SOC_SERIES_NRF54HX diff --git a/soc/arm/nordic_nrf/nrf54h/Kconfig.series b/soc/arm/nordic_nrf/nrf54h/Kconfig.series new file mode 100644 index 00000000000..0b896f477ac --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54h/Kconfig.series @@ -0,0 +1,16 @@ +# Nordic Semiconductor nRF54H MCU line + +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_NRF54HX + bool "Nordic Semiconductor nRF54H series MCU" + select ARM + select ARMV8_M_DSP + select CPU_CORTEX_M33 + select SOC_FAMILY_NRF + select HAS_NRFX + select HAS_NORDIC_DRIVERS + select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE + help + Enable support for nRF54H MCU series diff --git a/soc/arm/nordic_nrf/nrf54h/Kconfig.soc b/soc/arm/nordic_nrf/nrf54h/Kconfig.soc new file mode 100644 index 00000000000..9c065e79eaf --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54h/Kconfig.soc @@ -0,0 +1,37 @@ +# Nordic Semiconductor nRF54H MCU line + +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_NRF54H20 + bool "nRF54H20" + depends on SOC_SERIES_NRF54HX + +if SOC_NRF54H20 + +choice + prompt "nRF54H20 MCU Selection" + +config SOC_NRF54H20_ENGA_CPUAPP + bool "nRF54H20 ENGA CPUAPP" + select CPU_HAS_ARM_MPU + select CPU_HAS_ARM_SAU + select CPU_HAS_DCACHE + select CPU_HAS_ICACHE + select CPU_HAS_FPU + +config SOC_NRF54H20_ENGA_CPURAD + bool "nRF54H20 ENGA CPURAD" + select CPU_HAS_ARM_MPU + select CPU_HAS_ARM_SAU + select CPU_HAS_DCACHE + select CPU_HAS_ICACHE + select CPU_HAS_FPU + +endchoice + +config NRF_ENABLE_ICACHE + bool "Instruction cache (I-Cache)" + default y + +endif # SOC_NRF54H20 diff --git a/soc/arm/nordic_nrf/nrf54h/align.ld b/soc/arm/nordic_nrf/nrf54h/align.ld new file mode 100644 index 00000000000..0905aa7f7bc --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54h/align.ld @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA. + * SPDX-License-Identifier: Apache-2.0 + */ + +SECTION_PROLOGUE(.align16,,) +{ + . = (ALIGN(16) > 0 ? ALIGN(16) : 16) - 1; + BYTE(0); +} GROUP_LINK_IN(ROMABLE_REGION) diff --git a/soc/arm/nordic_nrf/nrf54h/soc.c b/soc/arm/nordic_nrf/nrf54h/soc.c new file mode 100644 index 00000000000..9fefd414152 --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54h/soc.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL); + +#if defined(NRF_APPLICATION) +#define HSFLL_NODE DT_NODELABEL(cpuapp_hsfll) +#elif defined(NRF_RADIOCORE) +#define HSFLL_NODE DT_NODELABEL(cpurad_hsfll) +#endif + +#define FICR_ADDR_GET(node_id, name) \ + DT_REG_ADDR(DT_PHANDLE_BY_NAME(node_id, nordic_ficrs, name)) + \ + DT_PHA_BY_NAME(node_id, nordic_ficrs, name, offset) + +static void power_domain_init(void) +{ + /* + * Set: + * - LRCCONF010.POWERON.MAIN: 1 + * - LRCCONF010.POWERON.ACT: 1 + * - LRCCONF010.RETAIN.MAIN: 1 + * - LRCCONF010.RETAIN.ACT: 1 + * + * This is done here at boot so that when the idle routine will hit + * WFI the power domain will be correctly retained. + */ + + nrf_lrcconf_poweron_force_set(NRF_LRCCONF010, NRF_LRCCONF_POWER_MAIN, true); + nrf_lrcconf_poweron_force_set(NRF_LRCCONF010, NRF_LRCCONF_POWER_DOMAIN_0, true); + + nrf_lrcconf_retain_set(NRF_LRCCONF010, NRF_LRCCONF_POWER_MAIN, true); + nrf_lrcconf_retain_set(NRF_LRCCONF010, NRF_LRCCONF_POWER_DOMAIN_0, true); + +#if defined(CONFIG_SOC_NRF54H20_ENGA_CPUAPP) + nrf_lrcconf_poweron_force_set(NRF_LRCCONF000, NRF_LRCCONF_POWER_DOMAIN_0, true); +#endif +} + +static int trim_hsfll(void) +{ + NRF_HSFLL_Type *hsfll = (NRF_HSFLL_Type *)DT_REG_ADDR(HSFLL_NODE); + nrf_hsfll_trim_t trim = { + .vsup = sys_read32(FICR_ADDR_GET(HSFLL_NODE, vsup)), + .coarse = sys_read32(FICR_ADDR_GET(HSFLL_NODE, coarse)), + .fine = sys_read32(FICR_ADDR_GET(HSFLL_NODE, fine)) + }; + + LOG_DBG("Trim: HSFLL VSUP: 0x%.8x", trim.vsup); + LOG_DBG("Trim: HSFLL COARSE: 0x%.8x", trim.coarse); + LOG_DBG("Trim: HSFLL FINE: 0x%.8x", trim.fine); + + nrf_hsfll_clkctrl_mult_set(hsfll, + DT_PROP(HSFLL_NODE, clock_frequency) / + DT_PROP(DT_CLOCKS_CTLR(HSFLL_NODE), clock_frequency)); + nrf_hsfll_trim_set(hsfll, &trim); + + nrf_hsfll_task_trigger(hsfll, NRF_HSFLL_TASK_FREQ_CHANGE); +#if defined(CONFIG_SOC_NRF54H20_ENGA_CPUAPP) || defined(CONFIG_SOC_NRF54H20_ENGA_CPURAD) + /* In this HW revision, HSFLL task frequency change needs to be + * triggered additional time to take effect. + */ + nrf_hsfll_task_trigger(hsfll, NRF_HSFLL_TASK_FREQ_CHANGE); +#endif + + LOG_DBG("NRF_HSFLL->TRIM.VSUP = %d", hsfll->TRIM.VSUP); + LOG_DBG("NRF_HSFLL->TRIM.COARSE = %d", hsfll->TRIM.COARSE); + LOG_DBG("NRF_HSFLL->TRIM.FINE = %d", hsfll->TRIM.FINE); + + return 0; +} + +static int nordicsemi_nrf54h_init(void) +{ +#if defined(CONFIG_NRF_ENABLE_ICACHE) + sys_cache_instr_enable(); +#endif + + power_domain_init(); + + trim_hsfll(); + + return 0; +} + +void arch_busy_wait(uint32_t time_us) +{ + nrfx_coredep_delay_us(time_us); +} + +SYS_INIT(nordicsemi_nrf54h_init, PRE_KERNEL_1, 0); diff --git a/soc/arm/nordic_nrf/nrf54h/soc.h b/soc/arm/nordic_nrf/nrf54h/soc.h new file mode 100644 index 00000000000..9a44ab24982 --- /dev/null +++ b/soc/arm/nordic_nrf/nrf54h/soc.h @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef SOC_ARM_NORDIC_NRF_NRF54H_SOC_H_ +#define SOC_ARM_NORDIC_NRF_NRF54H_SOC_H_ + +#include + +#endif /* SOC_ARM_NORDIC_NRF_NRF54H_SOC_H_ */ From bc8908a9e992b6307192c60a22fb3da82b4bacdc Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Tue, 30 Jan 2024 14:30:20 +0100 Subject: [PATCH 1242/1623] [nrf fromtree] modules: hal_nordic: Set SOC_SVD_FILE This CMake variable contains a path to a CMSIS-SVD file from nRF MDK, which describes the selected Nordic SoC. Initially, this will be used as an argument to nrf-regtool. Signed-off-by: Grzegorz Swiderski (cherry picked from commit 7740bcf670595cbf83d6c9f59159da7b7b057cb6) --- modules/hal_nordic/nrfx/CMakeLists.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index f2ddea1a23a..cd8392e118f 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -154,3 +154,25 @@ zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54LX_SKIP_CLOCK_CONFIG NRF_SKIP_C if(CONFIG_SOC_SERIES_NRF54LX AND CONFIG_NRFX_DPPI) zephyr_library_sources(${HELPERS_DIR}/nrfx_gppi_dppi_ppib_lumos.c) endif() + +# Get the SVD file for the current SoC +macro(mdk_svd_ifdef feature_toggle filename) + if(${feature_toggle}) + set(SOC_SVD_FILE ${MDK_DIR}/${filename} CACHE FILEPATH "Path to a CMSIS-SVD file") + endif() +endmacro() + +mdk_svd_ifdef(CONFIG_SOC_SERIES_NRF51X nrf51.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF52805 nrf52805.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF52810 nrf52810.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF52811 nrf52811.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF52820 nrf52820.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF52832 nrf52.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF52833 nrf52833.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF52840 nrf52840.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF5340_CPUAPP nrf5340_application.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF5340_CPUNET nrf5340_network.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF54H20_ENGA_CPUAPP nrf54h20_enga_application.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF54H20_ENGA_CPURAD nrf54h20_enga_radiocore.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF9120 nrf9120.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF9160 nrf9160.svd) From 0ac354d30303149bc6482fdea8b9f562bb9d8f36 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Tue, 30 Jan 2024 14:30:20 +0100 Subject: [PATCH 1243/1623] [nrf fromtree] modules: hal_nordic: Integrate nrf-regtool nrf-regtool is a Python utility from Nordic Semiconductor, which is used for generating binary files with register values for given peripherals. It sources the descriptions of peripheral registers from CMSIS-SVD files (typically ones bundled with nRF MDK). For some peripherals, such as UICR, nrf-regtool supports parsing values from devicetree as well, based on the bindings already found in Zephyr. Currently, this tool is not submitted as a script to Zephyr, but it can be installed from PyPI. Having nrf-regtool installed is recommended when working with nRF54H20. Booting the Application or Radiocore CPU requires flashing not only its firmware, but also its respective UICR instance. On this SoC, the UICR is used to assign ownership of global hardware resources, including memory and peripherals, to individual cores. The Zephyr build system can call nrf-regtool to generate the UICR based on devicetree, to reflect the boot-time hardware configuration required for a given application. The generated `uicr.hex` is then merged with `zephyr.hex`, so that they can be flashed together using west. The build system integration takes the form of a CMake package, which includes a version check and reusable components; over time, some of these components can be reused by sysbuild. This package is located in the `hal_nordic` module, because it depends on the `SOC_SVD_FILE` CMake variable, which is defined there as well. Signed-off-by: Grzegorz Swiderski (cherry picked from commit be8b2663c6cd52b6d263de93e9ea1d92d6a5d215) --- modules/hal_nordic/CMakeLists.txt | 16 +++++++ modules/hal_nordic/Kconfig | 1 + modules/hal_nordic/Kconfig.nrf_regtool | 36 ++++++++++++++ .../nrf-regtool/nrf-regtoolConfig.cmake | 48 +++++++++++++++++++ .../nrf-regtoolConfigVersion.cmake | 32 +++++++++++++ .../nrf54h/Kconfig.defconfig.nrf54h20_cpuapp | 3 ++ .../nrf54h/Kconfig.defconfig.nrf54h20_cpurad | 3 ++ 7 files changed, 139 insertions(+) create mode 100644 modules/hal_nordic/Kconfig.nrf_regtool create mode 100644 modules/hal_nordic/nrf-regtool/nrf-regtoolConfig.cmake create mode 100644 modules/hal_nordic/nrf-regtool/nrf-regtoolConfigVersion.cmake diff --git a/modules/hal_nordic/CMakeLists.txt b/modules/hal_nordic/CMakeLists.txt index 693400aba76..6f5364ac8de 100644 --- a/modules/hal_nordic/CMakeLists.txt +++ b/modules/hal_nordic/CMakeLists.txt @@ -6,3 +6,19 @@ if (CONFIG_NRF_802154_RADIO_DRIVER OR CONFIG_NRF_802154_SERIALIZATION) endif (CONFIG_NRF_802154_RADIO_DRIVER OR CONFIG_NRF_802154_SERIALIZATION) add_subdirectory_ifdef(CONFIG_HAS_NRFX nrfx) + +if(CONFIG_NRF_REGTOOL_GENERATE_UICR) + list(APPEND nrf_regtool_components GENERATE:UICR) +endif() +if(DEFINED nrf_regtool_components) + find_package(nrf-regtool 5.0.1 + COMPONENTS ${nrf_regtool_components} + PATHS ${CMAKE_CURRENT_LIST_DIR}/nrf-regtool + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_PACKAGE_REGISTRY + NO_CMAKE_SYSTEM_PATH + NO_CMAKE_SYSTEM_PACKAGE_REGISTRY + ) +endif() diff --git a/modules/hal_nordic/Kconfig b/modules/hal_nordic/Kconfig index 6f77bbea427..c9cc93e9329 100644 --- a/modules/hal_nordic/Kconfig +++ b/modules/hal_nordic/Kconfig @@ -236,3 +236,4 @@ endif # NRF_802154_RADIO_DRIVER || NRF_802154_SERIALIZATION endmenu # HAS_NORDIC_DRIVERS rsource "nrfx/Kconfig" +rsource "Kconfig.nrf_regtool" diff --git a/modules/hal_nordic/Kconfig.nrf_regtool b/modules/hal_nordic/Kconfig.nrf_regtool new file mode 100644 index 00000000000..81659bcf0bb --- /dev/null +++ b/modules/hal_nordic/Kconfig.nrf_regtool @@ -0,0 +1,36 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +menu "nrf-regtool options" + depends on SOC_SERIES_NRF54HX + +config NRF_REGTOOL_GENERATE_UICR + bool "Generate UICR" + help + Generate a UICR hex based on devicetree contents using nrf-regtool. + CPU domains that require UICR allocation aren't bootable without it + being programmed alongside the firmware. + +config NRF_REGTOOL_VERBOSITY + int "Verbosity level of console output" + range 0 3 + default 0 + help + Level of verbose output that nrf-regtool will print to the console. + + 0. Only critical information and warnings. + 1. Print a pretty, human-readable representation of a peripheral's + configuration. This is recommended for inspecting register values. + 2. Print extra details for debugging purposes, such as memory maps of + the peripheral configurations, but in a less readable format. + 3. Print even more details, which are typically only useful for + nrf-regtool developers. + +config NRF_REGTOOL_EXTRA_GENERATE_ARGS + string "Extra arguments to 'nrf-regtool generate'" + help + List of additional arguments to every nrf-regtool invocation used for + generating hex files. Example value: "--fill all --fill-byte 0xff". + Run "nrf-regtool generate -h" to see all of the available options. + +endmenu diff --git a/modules/hal_nordic/nrf-regtool/nrf-regtoolConfig.cmake b/modules/hal_nordic/nrf-regtool/nrf-regtoolConfig.cmake new file mode 100644 index 00000000000..d057c735e3f --- /dev/null +++ b/modules/hal_nordic/nrf-regtool/nrf-regtoolConfig.cmake @@ -0,0 +1,48 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +function(nrf_regtool_generate_hex_from_dts peripheral) + string(TOLOWER "${peripheral}.hex" generated_hex_name) + string(TOLOWER "${peripheral}_merged.hex" merged_hex_name) + + # Prepare common argument sub-lists. + string(REPEAT "-v;" ${CONFIG_NRF_REGTOOL_VERBOSITY} verbosity) + list(TRANSFORM CACHED_DTS_ROOT_BINDINGS PREPEND "--bindings-dir;" OUTPUT_VARIABLE bindings_dirs) + separate_arguments(extra_args UNIX_COMMAND "${CONFIG_NRF_REGTOOL_EXTRA_GENERATE_ARGS}") + + set(generated_hex_file ${PROJECT_BINARY_DIR}/${generated_hex_name}) + execute_process( + COMMAND ${NRF_REGTOOL} ${verbosity} generate + --peripheral ${peripheral} + --svd-file ${SOC_SVD_FILE} + --dts-file ${ZEPHYR_DTS} + ${bindings_dirs} + --output-file ${generated_hex_file} + ${extra_args} + WORKING_DIRECTORY ${APPLICATION_SOURCE_DIR} + COMMAND_ERROR_IS_FATAL ANY + ) + message(STATUS "Generated ${peripheral} hex file: ${generated_hex_file}") + + set(merged_hex_file ${PROJECT_BINARY_DIR}/${merged_hex_name}) + set_property(GLOBAL APPEND PROPERTY extra_post_build_commands + COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/mergehex.py + -o ${merged_hex_file} + ${generated_hex_file} + ${PROJECT_BINARY_DIR}/${KERNEL_HEX_NAME} + ) + set_property(TARGET runners_yaml_props_target PROPERTY hex_file ${merged_hex_file}) +endfunction() + + +foreach(component IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS) + string(REGEX MATCH "(^.*):(.*$)" match ${component}) + set(operation "${CMAKE_MATCH_1}") + set(peripheral "${CMAKE_MATCH_2}") + + if(operation STREQUAL "GENERATE") + nrf_regtool_generate_hex_from_dts(${peripheral}) + else() + message(FATAL_ERROR "Unrecognized package component: \"${component}\"") + endif() +endforeach() diff --git a/modules/hal_nordic/nrf-regtool/nrf-regtoolConfigVersion.cmake b/modules/hal_nordic/nrf-regtool/nrf-regtoolConfigVersion.cmake new file mode 100644 index 00000000000..e147d1b0532 --- /dev/null +++ b/modules/hal_nordic/nrf-regtool/nrf-regtoolConfigVersion.cmake @@ -0,0 +1,32 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +find_program(NRF_REGTOOL nrf-regtool) + +if(NRF_REGTOOL) + execute_process( + COMMAND ${NRF_REGTOOL} --version + OUTPUT_VARIABLE version + RESULT_VARIABLE result + ) + + if(result EQUAL 0 AND version MATCHES "version ([0-9]+[.][0-9]+[.][0-9]+)") + set(PACKAGE_VERSION ${CMAKE_MATCH_1}) + if(PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if(PACKAGE_VERSION VERSION_EQUAL PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + endif() + + message(STATUS + "Found nrf-regtool (found suitable version \"${PACKAGE_VERSION}\", " + "minimum required is \"${PACKAGE_FIND_VERSION}\")" + ) + return() + endif() + endif() +endif() + +# We only get here if we don't pass the version check. +set(PACKAGE_VERSION_UNSUITABLE TRUE) +set(NRF_REGTOOL NRF_REGTOOL-NOTFOUND CACHE INTERNAL "Path to a program") diff --git a/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpuapp b/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpuapp index eb56b8c369e..d90f87c0b89 100644 --- a/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpuapp +++ b/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpuapp @@ -11,4 +11,7 @@ config SOC config NUM_IRQS default 471 +config NRF_REGTOOL_GENERATE_UICR + default y + endif # SOC_NRF54H20_ENGA_CPUAPP diff --git a/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpurad b/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpurad index f63b9437775..6aae8c3a105 100644 --- a/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpurad +++ b/soc/arm/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_cpurad @@ -11,4 +11,7 @@ config SOC config NUM_IRQS default 471 +config NRF_REGTOOL_GENERATE_UICR + default y + endif # SOC_NRF54H20_ENGA_CPURAD From f5cec5f5dd7d2b77fc5934edb5a683a8815308c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 31 Jan 2024 15:20:20 +0100 Subject: [PATCH 1244/1623] [nrf fromtree] drivers: serial: Kconfig.nrfx: Filter out options unsupported on nRF54H20 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On nRF54H20, only the new shim can be used and the enhanced poll out cannot be enabled since there is no DPPI support for this SoC yet. Signed-off-by: Andrzej Głąbek (cherry picked from commit 784688a511fdfb493289b41e8253163e41fb29b6) --- drivers/serial/Kconfig.nrfx | 3 +-- drivers/serial/Kconfig.nrfx_uart_instance | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/serial/Kconfig.nrfx b/drivers/serial/Kconfig.nrfx index 8995b6b9fbf..4ea38e7b996 100644 --- a/drivers/serial/Kconfig.nrfx +++ b/drivers/serial/Kconfig.nrfx @@ -31,8 +31,7 @@ config UART_NRFX_UARTE config UART_NRFX_UARTE_LEGACY_SHIM bool "Legacy UARTE shim" depends on UART_NRFX_UARTE - # NRF54L15 need new UARTE driver - depends on !SOC_SERIES_NRF54LX + depends on !SOC_SERIES_NRF54LX && !SOC_SERIES_NRF54HX # New shim takes more ROM. Until it is fixed use legacy shim. default y diff --git a/drivers/serial/Kconfig.nrfx_uart_instance b/drivers/serial/Kconfig.nrfx_uart_instance index 718631a4d09..9e992ca9737 100644 --- a/drivers/serial/Kconfig.nrfx_uart_instance +++ b/drivers/serial/Kconfig.nrfx_uart_instance @@ -23,6 +23,7 @@ config UART_$(nrfx_uart_num)_ENHANCED_POLL_OUT depends on !SOC_SERIES_NRF54LX default y depends on HAS_HW_NRF_UARTE$(nrfx_uart_num) + depends on HAS_HW_NRF_PPI || HAS_HW_NRF_DPPIC select NRFX_PPI if HAS_HW_NRF_PPI select NRFX_DPPI if HAS_HW_NRF_DPPIC help From 3a07b53476431a1cc3ddfaa9e7666512535c0db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Fri, 19 Jan 2024 11:51:41 +0100 Subject: [PATCH 1245/1623] [nrf fromtree] drivers: serial: nrfx: Allow new UARTE instances to be used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend Kconfig definitions and nrfx_config translations so that UARTE instances that are available in nRF54H20 can be used. Signed-off-by: Andrzej Głąbek (cherry picked from commit 976de4edbe57b000e5a6fb8239733fe51b45ae60) --- drivers/serial/Kconfig.nrfx | 45 ++++++++++++++++++++ modules/hal_nordic/nrfx/Kconfig | 45 ++++++++++++++++++++ modules/hal_nordic/nrfx/nrfx_config.h | 27 ++++++++++++ soc/arm/nordic_nrf/Kconfig.peripherals | 27 ++++++++++++ soc/arm/nordic_nrf/validate_base_addresses.c | 9 ++++ 5 files changed, 153 insertions(+) diff --git a/drivers/serial/Kconfig.nrfx b/drivers/serial/Kconfig.nrfx index 4ea38e7b996..158731404e6 100644 --- a/drivers/serial/Kconfig.nrfx +++ b/drivers/serial/Kconfig.nrfx @@ -90,6 +90,51 @@ nrfx_uart_num = 30 rsource "Kconfig.nrfx_uart_instance" endif +if HAS_HW_NRF_UARTE120 +nrfx_uart_num = 120 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE130 +nrfx_uart_num = 130 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE131 +nrfx_uart_num = 131 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE132 +nrfx_uart_num = 132 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE133 +nrfx_uart_num = 133 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE134 +nrfx_uart_num = 134 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE135 +nrfx_uart_num = 135 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE136 +nrfx_uart_num = 136 +rsource "Kconfig.nrfx_uart_instance" +endif + +if HAS_HW_NRF_UARTE137 +nrfx_uart_num = 137 +rsource "Kconfig.nrfx_uart_instance" +endif + config NRFX_TIMER0 default y depends on UART_0_NRF_HW_ASYNC_TIMER = 0 \ diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index d4efbb7cac8..ee1bd76b52f 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -637,6 +637,51 @@ config NRFX_UARTE30 depends on $(dt_nodelabel_has_compat,uart30,$(DT_COMPAT_NORDIC_NRF_UARTE)) select NRFX_UARTE +config NRFX_UARTE120 + bool "UARTE120 driver instance" + depends on $(dt_nodelabel_has_compat,uart120,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE130 + bool "UARTE130 driver instance" + depends on $(dt_nodelabel_has_compat,uart130,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE131 + bool "UARTE131 driver instance" + depends on $(dt_nodelabel_has_compat,uart131,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE132 + bool "UARTE132 driver instance" + depends on $(dt_nodelabel_has_compat,uart132,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE133 + bool "UARTE133 driver instance" + depends on $(dt_nodelabel_has_compat,uart133,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE134 + bool "UARTE134 driver instance" + depends on $(dt_nodelabel_has_compat,uart134,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE135 + bool "UARTE135 driver instance" + depends on $(dt_nodelabel_has_compat,uart135,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE136 + bool "UARTE136 driver instance" + depends on $(dt_nodelabel_has_compat,uart136,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + +config NRFX_UARTE137 + bool "UARTE137 driver instance" + depends on $(dt_nodelabel_has_compat,uart137,$(DT_COMPAT_NORDIC_NRF_UARTE)) + select NRFX_UARTE + config NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG bool "UARTE GPIO configuration support" depends on NRFX_UARTE diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 215eff5bfcd..be2f5599f78 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -606,6 +606,33 @@ #ifdef CONFIG_NRFX_UARTE30 #define NRFX_UARTE30_ENABLED 1 #endif +#ifdef CONFIG_NRFX_UARTE120 +#define NRFX_UARTE120_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE130 +#define NRFX_UARTE130_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE131 +#define NRFX_UARTE131_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE132 +#define NRFX_UARTE132_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE133 +#define NRFX_UARTE133_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE134 +#define NRFX_UARTE134_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE135 +#define NRFX_UARTE135_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE136 +#define NRFX_UARTE136_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_UARTE137 +#define NRFX_UARTE137_ENABLED 1 +#endif #ifdef CONFIG_NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG #define NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG 1 #endif diff --git a/soc/arm/nordic_nrf/Kconfig.peripherals b/soc/arm/nordic_nrf/Kconfig.peripherals index 0dc47fe516c..b8b1198ca02 100644 --- a/soc/arm/nordic_nrf/Kconfig.peripherals +++ b/soc/arm/nordic_nrf/Kconfig.peripherals @@ -440,6 +440,33 @@ config HAS_HW_NRF_UARTE22 config HAS_HW_NRF_UARTE30 def_bool $(dt_nodelabel_enabled_with_compat,uart30,$(DT_COMPAT_NORDIC_NRF_UARTE)) +config HAS_HW_NRF_UARTE120 + def_bool $(dt_nodelabel_enabled_with_compat,uart120,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE130 + def_bool $(dt_nodelabel_enabled_with_compat,uart130,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE131 + def_bool $(dt_nodelabel_enabled_with_compat,uart131,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE132 + def_bool $(dt_nodelabel_enabled_with_compat,uart132,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE133 + def_bool $(dt_nodelabel_enabled_with_compat,uart133,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE134 + def_bool $(dt_nodelabel_enabled_with_compat,uart134,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE135 + def_bool $(dt_nodelabel_enabled_with_compat,uart135,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE136 + def_bool $(dt_nodelabel_enabled_with_compat,uart136,$(DT_COMPAT_NORDIC_NRF_UARTE)) + +config HAS_HW_NRF_UARTE137 + def_bool $(dt_nodelabel_enabled_with_compat,uart137,$(DT_COMPAT_NORDIC_NRF_UARTE)) + config HAS_HW_NRF_USBD def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_USBD)) diff --git a/soc/arm/nordic_nrf/validate_base_addresses.c b/soc/arm/nordic_nrf/validate_base_addresses.c index 9daa820efa9..28ec231b132 100644 --- a/soc/arm/nordic_nrf/validate_base_addresses.c +++ b/soc/arm/nordic_nrf/validate_base_addresses.c @@ -214,6 +214,15 @@ CHECK_DT_REG(uart20, NRF_UARTE20); CHECK_DT_REG(uart21, NRF_UARTE21); CHECK_DT_REG(uart22, NRF_UARTE22); CHECK_DT_REG(uart30, NRF_UARTE30); +CHECK_DT_REG(uart120, NRF_UARTE120); +CHECK_DT_REG(uart130, NRF_UARTE130); +CHECK_DT_REG(uart131, NRF_UARTE131); +CHECK_DT_REG(uart132, NRF_UARTE132); +CHECK_DT_REG(uart133, NRF_UARTE133); +CHECK_DT_REG(uart134, NRF_UARTE134); +CHECK_DT_REG(uart135, NRF_UARTE135); +CHECK_DT_REG(uart136, NRF_UARTE136); +CHECK_DT_REG(uart137, NRF_UARTE137); CHECK_DT_REG(uicr, NRF_UICR); CHECK_DT_REG(usbd, NRF_USBD); CHECK_DT_REG(usbreg, NRF_USBREGULATOR); From fceaaea0d7c613ecccb94c2b8011da09d7a98e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 31 Jan 2024 15:30:27 +0100 Subject: [PATCH 1246/1623] [nrf fromtree] drivers: timer: nrf_grtc_timer: Add dependency on nRF clock control MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... in the related parts, so that the driver can be used on nRF54H20 where the clock control is not present yet. Signed-off-by: Andrzej Głąbek (cherry picked from commit bb065262bc8ea42ab56eda1d4e142b2e9c0ec617) --- drivers/timer/nrf_grtc_timer.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/timer/nrf_grtc_timer.c b/drivers/timer/nrf_grtc_timer.c index a706c04bae0..8ac357864cc 100644 --- a/drivers/timer/nrf_grtc_timer.c +++ b/drivers/timer/nrf_grtc_timer.c @@ -7,7 +7,9 @@ #include #include #include +#if defined(CONFIG_CLOCK_CONTROL_NRF) #include +#endif #include #include #include @@ -521,6 +523,7 @@ static int sys_clock_driver_init(void) system_timeout_set(CYC_PER_TICK); } +#if defined(CONFIG_CLOCK_CONTROL_NRF) static const enum nrf_lfclk_start_mode mode = IS_ENABLED(CONFIG_SYSTEM_CLOCK_NO_WAIT) ? CLOCK_CONTROL_NRF_LF_START_NOWAIT @@ -529,6 +532,7 @@ static int sys_clock_driver_init(void) : CLOCK_CONTROL_NRF_LF_START_STABLE); z_nrf_clock_control_lf_on(mode); +#endif return 0; } From a254d89aa6d97b3c55d8d8974ec41b1ee73aa0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 31 Jan 2024 13:05:36 +0100 Subject: [PATCH 1247/1623] [nrf fromtree] tests: arm_irq_vector_table: Add special handling for nRF54H20 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Different set of IRQ lines need to be used for this SoC and the CLOCK IRQ is not to be installed in the vector table. Signed-off-by: Andrzej Głąbek (cherry picked from commit c50c4130a012ea7ceca2b4400173fe4db68f0f42) --- .../arm/arm_irq_vector_table/src/arm_irq_vector_table.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c b/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c index f18c30dac9a..61679107103 100644 --- a/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c +++ b/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c @@ -27,6 +27,9 @@ #elif defined(CONFIG_SOC_SERIES_NRF54LX) /* For nRF54L Series, use SWI00-02 interrupt lines. */ #define _ISR_OFFSET SWI00_IRQn +#elif defined(CONFIG_SOC_SERIES_NRF54HX) +/* For nRF54H Series, use BELLBOARD_0-2 interrupt lines. */ +#define _ISR_OFFSET BELLBOARD_0_IRQn #else /* For other nRF targets, use TIMER0-2 interrupt lines. */ #define _ISR_OFFSET TIMER0_IRQn @@ -141,6 +144,8 @@ typedef void (*vth)(void); /* Vector Table Handler */ void nrfx_power_clock_irq_handler(void); #if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) #define POWER_CLOCK_IRQ_NUM POWER_CLOCK_IRQn +#elif defined(CONFIG_SOC_SERIES_NRF54HX) +#define POWER_CLOCK_IRQ_NUM -1 /* not needed */ #else #define POWER_CLOCK_IRQ_NUM CLOCK_POWER_IRQn #endif @@ -149,7 +154,7 @@ void nrfx_power_clock_irq_handler(void); void timer0_nrf_isr(void); #define TIMER_IRQ_HANDLER timer0_nrf_isr #define TIMER_IRQ_NUM TIMER0_IRQn -#elif defined(CONFIG_SOC_SERIES_NRF54LX) +#elif defined(CONFIG_SOC_SERIES_NRF54LX) || defined(CONFIG_SOC_SERIES_NRF54HX) void nrfx_grtc_irq_handler(void); #define TIMER_IRQ_HANDLER nrfx_grtc_irq_handler #define TIMER_IRQ_NUM GRTC_0_IRQn @@ -162,7 +167,9 @@ void rtc_nrf_isr(void); #define IRQ_VECTOR_TABLE_SIZE (MAX(POWER_CLOCK_IRQ_NUM, MAX(TIMER_IRQ_NUM, _ISR_OFFSET + 2)) + 1) vth __irq_vector_table _irq_vector_table[IRQ_VECTOR_TABLE_SIZE] = { +#if (POWER_CLOCK_IRQ_NUM != -1) [POWER_CLOCK_IRQ_NUM] = nrfx_power_clock_irq_handler, +#endif [TIMER_IRQ_NUM] = TIMER_IRQ_HANDLER, [_ISR_OFFSET] = isr0, isr1, isr2, }; From 7dc7df419c99d2da221a548248bc093fcf126654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Thu, 1 Feb 2024 09:10:52 +0100 Subject: [PATCH 1248/1623] [nrf fromtree] dts: nordic: Include input-event-codes.h from nrf_common.dtsi MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... so that there is no need to include that header individually for every added board based on an nRF SoC. Signed-off-by: Andrzej Głąbek (cherry picked from commit 1606f65972bea823bea8bbad181d8610c064bc71) --- dts/common/nordic/nrf_common.dtsi | 1 + 1 file changed, 1 insertion(+) diff --git a/dts/common/nordic/nrf_common.dtsi b/dts/common/nordic/nrf_common.dtsi index f09557b23de..cb2df6bcccd 100644 --- a/dts/common/nordic/nrf_common.dtsi +++ b/dts/common/nordic/nrf_common.dtsi @@ -8,6 +8,7 @@ #include #include #include +#include #include #include From b28169ebb247c6f9eaaff44d993d8527d1fb9f73 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 29 Jan 2024 16:13:27 +0100 Subject: [PATCH 1249/1623] [nrf fromtree] scripts: west: runners: nrfjprog: add option to not erase On some new SoCs, the erase option is not required, so introduce a new option that doesn't set any erase mode. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit b2c8f7680d1ad3cdb308c0a45c2c30f61d2c87e3) --- scripts/west_commands/runners/nrfjprog.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/west_commands/runners/nrfjprog.py b/scripts/west_commands/runners/nrfjprog.py index a28681ae6a5..15f147a4d87 100644 --- a/scripts/west_commands/runners/nrfjprog.py +++ b/scripts/west_commands/runners/nrfjprog.py @@ -69,6 +69,8 @@ def do_exec_op(self, op, force=False): cmd.append('--sectorerase') elif erase == 'ERASE_PAGES_INCLUDING_UICR': cmd.append('--sectoranduicrerase') + elif erase == 'NO_ERASE': + pass else: raise RuntimeError(f'Invalid erase mode: {erase}') From 54fa6aee2c806a6578b667e3959a37b9324f64a9 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 29 Jan 2024 16:15:03 +0100 Subject: [PATCH 1250/1623] [nrf fromtree] scripts: west: runners: nrfjprog: add erasepage op Add a new operation that allows erasing pages. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit a99b5ca01b2e3d641e61c8a7f0b98e44e5cd42b5) --- scripts/west_commands/runners/nrfjprog.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/west_commands/runners/nrfjprog.py b/scripts/west_commands/runners/nrfjprog.py index 15f147a4d87..c1eebd32914 100644 --- a/scripts/west_commands/runners/nrfjprog.py +++ b/scripts/west_commands/runners/nrfjprog.py @@ -87,6 +87,9 @@ def do_exec_op(self, op, force=False): cmd.append('--reset') if _op['option'] == 'RESET_PIN': cmd.append('--pinreset') + elif op_type == 'erasepage': + cmd.append('--erasepage') + cmd.append(f"0x{_op['page']:08x}") else: raise RuntimeError(f'Invalid operation: {op_type}') From 308ac2fe5dcdc58c1cecfd37367cce6ec853090e Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 29 Jan 2024 16:19:30 +0100 Subject: [PATCH 1251/1623] [nrf fromtree] scripts: west: runners: nrfjprog: add basic support for nRF54H series Add basic support to flash application and/or radio core for nRF54H series. Note that features like merged hexes present in nRF53 series is not supported. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 6b987d31922d870b91b3530153243e2b4787be44) --- scripts/west_commands/runners/nrf_common.py | 63 +++++++++++++++------ scripts/west_commands/runners/nrfjprog.py | 6 +- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/scripts/west_commands/runners/nrf_common.py b/scripts/west_commands/runners/nrf_common.py index 93871d831ee..76662c72ea9 100644 --- a/scripts/west_commands/runners/nrf_common.py +++ b/scripts/west_commands/runners/nrf_common.py @@ -24,11 +24,26 @@ ErrNotAvailableBecauseProtection = 24 ErrVerify = 25 +UICR_RANGES = { + 'NRF53_FAMILY': { + 'NRFDL_DEVICE_CORE_APPLICATION': (0x00FF8000, 0x00FF8800), + 'NRFDL_DEVICE_CORE_NETWORK': (0x01FF8000, 0x01FF8800), + }, + 'NRF54H_FAMILY': { + 'NRFDL_DEVICE_CORE_APPLICATION': (0x0FFF8000, 0x0FFF8800), + 'NRFDL_DEVICE_CORE_NETWORK': (0x0FFFA000, 0x0FFFA800), + }, + 'NRF91_FAMILY': { + 'NRFDL_DEVICE_CORE_APPLICATION': (0x00FF8000, 0x00FF8800), + } +} + class NrfBinaryRunner(ZephyrBinaryRunner): '''Runner front-end base class for nrf tools.''' def __init__(self, cfg, family, softreset, dev_id, erase=False, - reset=True, tool_opt=[], force=False, recover=False): + reset=True, tool_opt=[], force=False, recover=False, + erase_all_uicrs=False): super().__init__(cfg) self.hex_ = cfg.hex_file if family and not family.endswith('_FAMILY'): @@ -40,6 +55,7 @@ def __init__(self, cfg, family, softreset, dev_id, erase=False, self.reset = bool(reset) self.force = force self.recover = bool(recover) + self.erase_all_uicrs = bool(erase_all_uicrs) self.tool_opt = [] for opts in [shlex.split(opt) for opt in tool_opt]: @@ -59,7 +75,8 @@ def dev_id_help(cls) -> str: @classmethod def do_add_parser(cls, parser): parser.add_argument('--nrf-family', - choices=['NRF51', 'NRF52', 'NRF53', 'NRF54L', 'NRF91'], + choices=['NRF51', 'NRF52', 'NRF53', 'NRF54L', + 'NRF54H', 'NRF91'], help='''MCU family; still accepted for compatibility only''') parser.add_argument('--softreset', required=False, @@ -75,6 +92,11 @@ def do_add_parser(cls, parser): help='''erase all user available non-volatile memory and disable read back protection before flashing (erases flash for both cores on nRF53)''') + parser.add_argument('--erase-all-uicrs', required=False, + action='store_true', + help='''Erase all UICR registers before flashing + (nRF54H only). When not set, only UICR registers + present in the hex file will be erased.''') parser.set_defaults(reset=True) @@ -163,6 +185,8 @@ def ensure_family(self): self.family = 'NRF53_FAMILY' elif self.build_conf.getboolean('CONFIG_SOC_SERIES_NRF54LX'): self.family = 'NRF54L_FAMILY' + elif self.build_conf.getboolean('CONFIG_SOC_SERIES_NRF54HX'): + self.family = 'NRF54H_FAMILY' elif self.build_conf.getboolean('CONFIG_SOC_SERIES_NRF91X'): self.family = 'NRF91_FAMILY' else: @@ -174,21 +198,15 @@ def hex_refers_region(self, region_start, region_end): return True return False - def hex_has_uicr_content(self): - # A map from SoCs which need this check to their UICR address - # ranges. If self.family isn't in here, do nothing. - uicr_ranges = { - 'NRF53_FAMILY': ((0x00FF8000, 0x00FF8800), - (0x01FF8000, 0x01FF8800)), - 'NRF91_FAMILY': ((0x00FF8000, 0x00FF8800),), - } + def hex_get_uicrs(self): + hex_uicrs = {} - if self.family not in uicr_ranges: - return + if self.family in UICR_RANGES: + for uicr_core, uicr_range in UICR_RANGES[self.family].items(): + if self.hex_refers_region(*uicr_range): + hex_uicrs[uicr_core] = uicr_range - for region_start, region_end in uicr_ranges[self.family]: - if self.hex_refers_region(region_start, region_end): - return True + return hex_uicrs def flush(self, force=False): try: @@ -213,7 +231,7 @@ def flush(self, force=False): # If there are data in the UICR region it is likely that the # verify failed du to the UICR not been erased before, so giving # a warning here will hopefully enhance UX. - if self.hex_has_uicr_content(): + if self.hex_get_uicrs(): self.logger.warning( 'The hex file contains data placed in the UICR, which ' 'may require a full erase before reprogramming. Run ' @@ -266,11 +284,24 @@ def program_hex(self): if self.family == 'NRF53_FAMILY': # nRF53 requires special treatment due to the extra coprocessor. self.program_hex_nrf53(erase_arg, qspi_erase_opt) + elif self.family == 'NRF54H_FAMILY': + self.program_hex_nrf54h() else: self.op_program(self.hex_, erase_arg, qspi_erase_opt, defer=True) self.flush(force=False) + def program_hex_nrf54h(self): + if self.erase_all_uicrs: + uicrs = UICR_RANGES['NRF54H_FAMILY'] + else: + uicrs = self.hex_get_uicrs() + + for uicr_core, range in uicrs.items(): + self.exec_op('erasepage', defer=True, core=uicr_core, page=range[0]) + + self.op_program(self.hex_, 'NO_ERASE', None, defer=True) + def program_hex_nrf53(self, erase_arg, qspi_erase_opt): # program_hex() helper for nRF53. diff --git a/scripts/west_commands/runners/nrfjprog.py b/scripts/west_commands/runners/nrfjprog.py index c1eebd32914..723080d56c3 100644 --- a/scripts/west_commands/runners/nrfjprog.py +++ b/scripts/west_commands/runners/nrfjprog.py @@ -32,7 +32,8 @@ def do_create(cls, cfg, args): args.dev_id, erase=args.erase, reset=args.reset, tool_opt=args.tool_opt, force=args.force, - recover=args.recover) + recover=args.recover, + erase_all_uicrs=args.erase_all_uicrs) def do_get_boards(self): snrs = self.check_output(['nrfjprog', '--ids']) @@ -46,7 +47,8 @@ def do_exec_op(self, op, force=False): # Translate the op families = {'NRF51_FAMILY': 'NRF51', 'NRF52_FAMILY': 'NRF52', - 'NRF53_FAMILY': 'NRF53', 'NRF54L_FAMILY': 'NRF54L', 'NRF91_FAMILY': 'NRF91'} + 'NRF53_FAMILY': 'NRF53', 'NRF54L_FAMILY': 'NRF54L', + 'NRF54H_FAMILY': 'NRF54H', 'NRF91_FAMILY': 'NRF91'} cores = {'NRFDL_DEVICE_CORE_APPLICATION': 'CP_APPLICATION', 'NRFDL_DEVICE_CORE_NETWORK': 'CP_NETWORK'} From 05bf13a4d2d3b9d742f552b9a40d7461bd8b0805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 23 Jan 2024 17:54:45 +0100 Subject: [PATCH 1252/1623] [nrf fromtree] boards: arm: Add initial support for nRF54H20 PDK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add targets that allows building for the Application and Radio cores in the nRF54H20 SoC on the nRF54H20 PDK board. Signed-off-by: Grzegorz Swiderski Signed-off-by: Gerard Marull-Paretas Signed-off-by: Andrzej Głąbek (cherry picked from commit 38520a93d3f0e11ee54e9ae326d8139bd17e8ac0) --- boards/arm/nrf54h20pdk_nrf54h20/Kconfig.board | 10 ++ .../nrf54h20pdk_nrf54h20/Kconfig.defconfig | 14 ++ boards/arm/nrf54h20pdk_nrf54h20/board.cmake | 3 + .../doc/img/nrf54h20pdk_nrf54h20.webp | Bin 0 -> 27232 bytes boards/arm/nrf54h20pdk_nrf54h20/doc/index.rst | 148 ++++++++++++++++++ .../nrf54h20pdk_nrf54h20-memory_map.dtsi | 79 ++++++++++ .../nrf54h20pdk_nrf54h20-pinctrl.dtsi | 53 +++++++ .../nrf54h20pdk_nrf54h20_cpuapp.dts | 137 ++++++++++++++++ .../nrf54h20pdk_nrf54h20_cpuapp.yaml | 15 ++ .../nrf54h20pdk_nrf54h20_cpuapp_defconfig | 33 ++++ .../nrf54h20pdk_nrf54h20_cpurad.dts | 58 +++++++ .../nrf54h20pdk_nrf54h20_cpurad.yaml | 15 ++ .../nrf54h20pdk_nrf54h20_cpurad_defconfig | 30 ++++ 13 files changed, 595 insertions(+) create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/Kconfig.board create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/Kconfig.defconfig create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/board.cmake create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/doc/img/nrf54h20pdk_nrf54h20.webp create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/doc/index.rst create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-pinctrl.dtsi create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.yaml create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp_defconfig create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.yaml create mode 100644 boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad_defconfig diff --git a/boards/arm/nrf54h20pdk_nrf54h20/Kconfig.board b/boards/arm/nrf54h20pdk_nrf54h20/Kconfig.board new file mode 100644 index 00000000000..b76cfce6800 --- /dev/null +++ b/boards/arm/nrf54h20pdk_nrf54h20/Kconfig.board @@ -0,0 +1,10 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_NRF54H20PDK_NRF54H20_CPUAPP + bool "nRF54H20 PDK nRF54H20 Application MCU" + depends on SOC_NRF54H20_ENGA_CPUAPP + +config BOARD_NRF54H20PDK_NRF54H20_CPURAD + bool "nRF54H20 PDK nRF54H20 Radio MCU" + depends on SOC_NRF54H20_ENGA_CPURAD diff --git a/boards/arm/nrf54h20pdk_nrf54h20/Kconfig.defconfig b/boards/arm/nrf54h20pdk_nrf54h20/Kconfig.defconfig new file mode 100644 index 00000000000..954276ec829 --- /dev/null +++ b/boards/arm/nrf54h20pdk_nrf54h20/Kconfig.defconfig @@ -0,0 +1,14 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config BOARD + default "nrf54h20pdk_nrf54h20_cpuapp" if BOARD_NRF54H20PDK_NRF54H20_CPUAPP + default "nrf54h20pdk_nrf54h20_cpurad" if BOARD_NRF54H20PDK_NRF54H20_CPURAD + +if BOARD_NRF54H20PDK_NRF54H20_CPUAPP || BOARD_NRF54H20PDK_NRF54H20_CPURAD + +# Data cache is disabled due to a HW issue in the EngA SoC revision. +config DCACHE + default n + +endif # BOARD_NRF54H20PDK_NRF54H20_CPUAPP || BOARD_NRF54H20PDK_NRF54H20_CPURAD diff --git a/boards/arm/nrf54h20pdk_nrf54h20/board.cmake b/boards/arm/nrf54h20pdk_nrf54h20/board.cmake new file mode 100644 index 00000000000..4c63f1dd05e --- /dev/null +++ b/boards/arm/nrf54h20pdk_nrf54h20/board.cmake @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: Apache-2.0 + +include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) diff --git a/boards/arm/nrf54h20pdk_nrf54h20/doc/img/nrf54h20pdk_nrf54h20.webp b/boards/arm/nrf54h20pdk_nrf54h20/doc/img/nrf54h20pdk_nrf54h20.webp new file mode 100644 index 0000000000000000000000000000000000000000..bcda6b0732b3acefe24e83332692e8ae898d47b4 GIT binary patch literal 27232 zcmV(sK<&R$Nk&FkY5)LNMM6+kP&il$000000001Q0stKW09H^qAmnKP05D|%odGIv z0v-WAkv^G7C8MIFs<#_f`^Tyu{XVb1!~f~^1^a#KxBm0?$KBueKTr?yzxRD)|MGwT|LO39{#*Y? z|NsC01K+xSonO6Q4IkwH^m@#H=j+tz7wmud-%B0?{y+QA?r)yHJUxT_SMGoKKW`kl z_1&qL&c6bG5BukzfAhb|en2ZGY47uKWM|&)k22Kj|Op|7*S3zsvvi{~yuM z*Z#sCHT^9R#aYszQ6T%hXv25?9kP{cS8-sRRn~HZN_VFXGV_7VrZsBY0)EkU@d%ZP zDO{TD=THao;x*IxY4#c%C(_1A-lkL*4UEJII+fEPN{Tm_c_=izGlI;`lSSSfQ&t9l zr!I}oC4w&O?eX&8`wfx=cGKmU^0F!HK1YUGbmK>s5-#N>dX$p2G$E`oDFWY!)i+## zd~+uIv%gtK<6x(}ETEzWU-?>~k@tVdC6*nRFigE{`(T}MwKtOqR%7*Jtn+!K>=}cb zbyvmBmyR(sqMS!NVOh7e3k|ou*deS&v`)jorS3@ymUpRq1A$;uo)9%LD^< zh=}Us5mBoS+gPPc*@)d!vMnORyv7#TFtjumnwldw|J8g^k}rN8I9I*5DbpyQ`|mW( zD+G^|`+*4Ja?x^ts{$+3v)S2UM7^`AiNaS;hd9;seAUMqr+9D-8iCaJ_ij5YqzeYm zI=hf_SF}=<&P~E_P4XzSt$8bfx~@R`qEzV$K)U)jmsdPI=-Kbr&3$RqA{CHeX%vWE}L zq}8~4%$5>tvzCXYthxOrQlB!E9>%Pmj!kqXJhftBHWw@-rTspQU5+AM(!&Gu^m?H8R+r9W|7OPb$( zYDC_gB~1y#f%h}(abst_&Om9KRYgE%lnRKl(gCV(4Cj+GXI6+P>vOLZSr~r-@iJ*Z{Y+qy3{$w(C-Ucc4h zv9!P&vpEx0kT__~G=X4!;tK#)8*>t-N>>N`?NPs_X%-or-`*+KI4Y3$!)&tPBEAx4 zYatLe>3vUy6~2>cH6@kvW&ZSF$7@@ev{kO-PLQl?{=crSVuUvGUW^Th(=(JgBjeZ0 z;)88URvX0eAKkhTubh_R^qf$wc_SZF*vuky=$h&e)nkc+_IS0l7^SZGP1IpCWnjyB zpawTHE%E)vx@Q+{4nc;Kwm|5M8gK0az z71Ld7vyjEYF=th7=^J$&EJ~Ed1a%(NV#SMvy}v3i79?kpY76T{5W3iL)1Jq2c%`v( zwk`3GjAO|q{2?cl+T{OnW?fT>qO6++?{`kSH!jMqAXzvyBaLUQjxE#F8&xIy^Y)D# zC@H_5Z{&b#;#I~3fJGDAvH1)$@!vy}4A~h3`!;s&=@h0_pMF84pZ@O*J@Tz)N%6N! zROKOkZ8eLWk*l!(13)c>wWQ!|(NS9G-1q23b0tK3-a)c<2;XUB=Pe$ZeR*7QkqH^7 z*VrmOSjt3)60pVtn9Tui({4DuO&TOo$XthUv*tuzA=r|m=BOPPcRbvBR;h%~n@%OU zLIMVSbvOIQK@!2KqR>g9`Ddud83VY3NS;%GqCwTJs-_9=5dwV&0Y6teSdh;9vyyGi z0=We0p!o*?js{=;5aV2%J`T^dIlsLu@a|?-@nam-0ES{-*s|Jr{zhoat=OeHF}7%34UQ6FI8SaIA1OAW~jJ9Pc;uW32%OwwPOVSw9Cr^O%soLQel;5n--6nirp9 z_|-k_VQmU7)DR*DJG8X>JjF$(d)vp%HKfV%*q2&9gpxUXjVMeL?e}W#C+igTu|z&j z7mPj*8p6t40Pxb!^~=p``t}Q_585gJeE}`m*@f!{-w3WIbjC`9Gvuf(BmUN+U=`;THq{Xavb@z$ zyZ^aK1}HInId#{m!&1i3&B*+IeEIeE%h;vMdJ0JsNLcEIhu?uKomXy6*VR8giG2jT zu|f+Z*=f7AN#%9b!j&RzE94h;U#LzF^S%Cpz@^t;iScjLPA1wvGq!1RmBO0wQ;|BS zWx%qB8MI5O$#Y@Kw(&7T-YkCP>Yq@Nr}C9YC(0>|Z6O%Osa-y&Raic5Qt*Ni64Ru1 zwMJC=YisyI%9*fZ#2*3(i;<#9ib1D!3|Bu19y7YXimF65wrKsuLK$yqh+5UI-UVnk zH0+}t>U!R}UJ__UE@xzz7%gov`WDi3hmbnH_zsp$vo~gn#rG$5gWzgwWAuRTdKKw{ zMduHokK=vhZ2B|Kh^d?ijGOxst1#hv4&(oNzqCQY?r^N;I0Z6I6cJH!4yjMgb{F1z z%C7w(JwiMdJ=B2MnvEVE2||zzWM)m*t!vfJjOj6-G_^;j!{YmaPy_1|+(zBs z*i81H?~5W*Qkb90GH7oS|Kc&nasWqVdoSK-3}i;#s#5br%W=WRF2T{rOHB05zB0=+ z0V_yxt$G99+O3$HHl=+rq{cRojAO`4%X{MN23V!fR}9LzUnAn73ne> zPgOXA{**J8^y7&^SWH?|S@Jgtm91Ui%qHsvUMu6^GC{b7&peXC#aGSe0pJeC6A3T? z{`8#BZ5?p7{dSb@IVt~BaRa`7lxF99Dm8<73C;^CAnL|g-t?8qX%ORlH<@gsgebT@ zN<`mk-QVA{cC0S!-FWh%SJ)p#@m-2vv-1nVce?2Ns)WFdzt_*3!gojBHQk<*mylRW zYr}$X4s=OUV9txH^r>|74HP7eR9dt4f#ftC+yCP83)Zzx+nCdRxazNs1R=rv_K*9# zAQe4r(=SCI$O%4e3te9%Y51uh8I~Q;X&-No^U0Jy_W}Q}UDhN9dEotk6Vo*}_CI0| zX36tA-3SzaxiFf}xBX9L<&@;-?qwL*?mWKlKp!W5_W#lg&QS!i-`Tt$FbX#dH z;`^{4jTMsXRE)fiz`|xHcDLrMv!b@f&^dyxhw*8e#?O_AZZwHozPbR*lB6pp5x;el z8AXZd<;6O1{1kR))iMwn62g&*x8>8L6dfvKs)F0k(2!F)^fMV5Sq<)0lfhK88)-P2 z!?Q_Uqh|)v1;47?OkIDg@ zaSj4MQaO%ZKAq{RQF{iI3j*xNEtvbd@Wx5^`!sE-b&rT zsQz`zy4f1s;zaIaWk#MKcvLFk{w>bmdN9a6m1i@%PUp3>l-WG05DD#8QL3>;=3YQ! zen{XB`5-d}G52gZ`DaspS#{{5#am0f-SFQ5M-|F!Nqyt^|2;?tlyAV#IZ*-AI4gyn zIyIHu#E3WS-eMIT2#Ij~@KsX|Wm5cFlh8~;vN1f4&-lfzOzrvtV1SfD6}S!~gnwnG zPURmT{w*F~N>ehBA8Wi+p5cw*!=m#i&ab4WHJIYk+%wlmyaL;TIoPH;u{5LjiN~&} zkes=zmF~|9&kN`)jMNkVF;pXd%RKdXlMe`k+KGJLE%X)OcZ)qtzOf&-pn*EjiJnU( z0dsC4`Xh^FnPnkyK$TGk!mg?f0AEPXHIk}ok=`MYW&3ik-VH~GB_?`*adTL00z-0u z`D(CtB0^<3$afjF;UD)3@crO2tnbx855onX!q13kp5|6vCD zcDzPoPEmcfin7a1WJ}l$ACGUg7qe&&GG;zi%OTD85h_7Z+meLOerw&cA*=9?odO(E zL()JqK~(Z{J50(|rqdr;r9Rp8BM8Cm)dM0Cs7MMN(E|g0YJKPOem~P zD-nQ4nfM2hE99CazCnnN51GO%itIW6$g)7vd_l%uPFNNw*BL)Py5$K%dCe(n%DGWl za27H9|B@tCeQZr%FL#tTCD)Gl20tS=7);1Kk=wggPNb}f zk*`&NF;Sd5ih3l#l=<^zI64rO$bqe_HAErlLcU5s)JORWPv0mCrVRp%;r3$twB^3B zdux$6{KHOkH(=u^O|-%t&m46{O50M_(&*dec+h$=VaUl(blK*L47HSVN>{MZJ-O0Z?!UZ2VNK5)kjilN+q28AX z9kVtbgu)9}(iT(Rvgj8vZ@?U~_gCb)!0mQn$xu2QF_-US?aEG~MB^IJK$67L;LiyR zQ22quWB~v`7Kx%aV6M{TvBaI}0d}#`e}e^K-d859f0+k7HJ(YYfdz-g_$Gm|8u~M< z?W$>?4q&)yh4B4cnIggu(O$=XgEhXJ1)*urcplQLiv^?yzc+;_8w;O&)lS_J+Ib^J zY~PWbh2}h*<%Ew?Kg1-mp<>pOlK~q~?E!yQ^AYfxYVTFw8CHyG zfX^kR9u>}l`LYfwF!rS;h#Yx1uraqn{u}+-+&Gf|ov$Fx=FcUey#YD%IVu0n!Xz0gwsT5acjwL0klt@REZ-Q?jgYYDVtzNe^y}Z$bvy?SnZ2xiJ)7;P z>`v(zw?j!<8)4Dq>%9jSX6dbV7jT^oUIQu0Q?Qsv)j3H)n~RYbDAP*#nQbGOvOriw zI@pP)EN*xT?}$VwYtgpW?q%v>nv)ui2!>N1wtRN$ftd&ccxzV_7A0g-ba4QV@nZdc z*}c2S;{1)ZdSOaPyPFOE7{8Z)jzTf=;L8IIRfxeA)^yH&1CJ?z9EC%81a6u?z2sT2 zyEYiM48bul<7V-?W(RjVX))jSPcDt@rNI&K2pQYtM5YE;O;Mp9N{QwA ztZI_~nuQ!*v_{30cGph$-=^9^+xB~|Ea9EqmpQ8$v)~T^x_RQw*@Qg>wpf4Scgy5Qm-iJo$#K7 zI?SQ9IhY{Zi^@I`w5dbATKNd@ZTz+9MdB_*kmy6N&yEhd{HS(yr9L)MJF}$P^V zxNmr&l`9X{spN=;|K&h7>|%KVcfLJ|TOIV9U&!hOU036Gm*AoNZ|>Xgc$65Oedseq z3!4KcigwSe_Oi^tZ{@sTQ|3*x5iUTpnUwC$JbpUVhldI*hoer zj_*FnL;EMUO}NkH0CFGw3R=b3FkOTWMYWdLl?dozvU`K{_~ie+IJcRlpjUnWuRwU5 z{4SRbS5uyc9bGps=Py1Mzo#2aPHl1lAw2uA=lEpukj~H(89kPPZrlIXTB(Ko;I-%{18 zPOpR-j8sxZ$V5gG*y221Wt19=6_X>HS5@wj11nX9HH8{dfTVDxu0D6t$S;j@^jvCW z!olT+(Zvn-?*8sRIJixwOMm%>+96cQ$r&7p2HN3sEpiIa)n1p_LQUN#@x)N5ng3-> zHSWNB?9c&8*GpMZrs#J7olsbbGN)>(`ZT7kY;LKuJJ5jp5rIY|%f#-~=NWQYm)~li zqg;bftvGJ@Vr?Ybr`ymNO#J2xUE4dS^s`D`nyEqdV=D`et7hMS%INSqQFv{Q0{ zM+bU3YxhPx!|Tn~pW`!Fs&*qV7aqo~+(b%Pt zJr~{_6hzg)aU;sF`i^$O zKe5zwh*!h$jo%8YO=HA6Y0qMChzNf;Z*G}8TQ&++YQgwW#IpWCd|v4z6u#)tHr`;9 z3Z~d-7JrO!{HK0q%pzIlzA6?-v@LA{-8CglV`Vzxv5GV=nnxE6d|DoUnUaKEEQWQo zCsHo_lfAe1o5&w@O25m;6@4=lkYh#91(jZS5~OE8WiL=3zYE+!C7{>=5F4XtJS*W3 z)wDCMtrnaif)d1w+p?o)!?@|#+^)*koobI{Nv_~nIbpz#C3!*7)?5L^{s$^-{A5mh z-X9kl-RD*8l&zLsB}sjS>XgGfWh%I;MKOxoBMIu2tD8osePcxJa-|c|vnPlBtqDj0 z4tGz(mV;Yq)Yu&b$bl0sqAT;HF_;7VkmJ^H-0$YW&-0>wEMtzzqKh%IO}j2Zc+em5 z>GauvL;0{kdnpPw9&dQLh*xFG57}we?|-t`raj;6)U-k>K%VH1V;|YbSL%quLB(J+ zklCSUN8=)_@%vFO7PAL?5}ZXKavcOs@3Cb=l;_hL;}*LJb7u+f1r6dS_Dk}`j$C44 zm(F;3wUhkMk?W^PjX>ApHU{%t1%mkD9u_RcUy-gZqlWDXT9z{yrO@ksgVaKQ`Gs=j zj9qr-;Aov`Kfo{;6+%47ZTn#x(pP%ZeI-nFdp7C)-t87)PmH&Umalwgg@rxr36<`Y z;k7gayCe->lHn2eIBDq_>^ zlFJngySy4vFeM7%*XkwF@AHW+JG0AV1yJk7?B}|HR0P>lJ6ZHIjK?|~=u!wR zZQo^uxH6SY!2R}_Yr?#6h(L#2f*t zP_+=a#R&1tm8AZFr_(g;Gv#M+RsW#|kV$fx^91Ofd6$~MC8tx^6ITU&lMONq!qZCM zTn+M-ZX}@P5a*H<=5H_UV%_BTf<=lW=^=B3c`7?r#&$v?x#{f3UV8wCf($Y-PKyDP z^r7FzxO=k7K)r0RmkX(W^sp0n{5S6X7*F*NxqGkZd(Pz2KS`lk^z7VPo6BQtk{DWqm&yGZi{ zV)#}3Fr=3Yao*l6Gup{6PGLQz;j@hdduqGRIBPMHlC^GwJTB}jV65Tlw0;RcibHe1 z<{oh*+!ItduzbCNz#DcXnl(73^^3LhQ^vBeV_hO+?GJ7A&AY9SOEVBLo6XIN{MNjo zv1X%5ZGzz8&hso|plf{X&@ifuUwMG+FTbbvDG6Ka1_?xJdx6xrQ!>pqRG*Umej&n=AO?86T(8%U8=Lih19_GgXyCOV zV-P`;y+d{(ylfaGtAB5I{vB&-3H=@lle)VoCL3w@-H?0MuspM%+xHVsBunIze8dvo zSR+w6bY^Jm=d#*|NulZc$GZNwS_cn$5+nry=JJ=CSiCMUX~+Rxq?8xfx^f)#k1^n{ zu8p+pxnRL#^GvmUvBTE^Ab@M@AIA$14ZVdWRS0ZqHT+h8#$8bpVIrQ#hx0M9 z9-OlvAcJaeria$VW;ujxk(NokEOVe%FC#onSD85yP*(eHb*gUI{tZsevZ_lPS2toO zgCdJFww-RrvHDpFhz&hysu3|3#)bnC>_%p?H>P6KB*vGHht8Tk`?Wd_fZVvvEW-;h z!Ep588D?(~g-Q6;IWW$_?R_D${2;R@t*C{dP%U z0@9Up(bA7EkNd!W`IU>kD*^-2CCx2M(;| zp4XV#eeeI%(Eir%o8W|J^J_&Kje0eDh8>_n5k*}^6odIY7m-ADyx9S?D#fj^-`eDd z{6!(Ftp;a{K_eIXtb$sR0Fx2&7KcQ-Iup@|{Z#`W3p zpJH@4g^C1S&-SsxuD5oy>cBfXjf)1;k0L11`}epol(tlO;5Mt)@|`VFi-c%tzoWE-Zp>fKB=T^3XJ>qt8XK_25APWndGefr#C_;$(~jMXS% z-8@*u+_~`JN+~<)#mkY<2Tr;aLU*8gs48ZL$B*mW%;xg#7ud+JY+Y@>a4JVR6&R$S zqpgzfW9}Un-bHGKm+V(dzoZ<+?Ig<5OM#KyAdCTv_pVB^<#BxgrMjC@`!=OlyV}=& zA~Q`j>78q}E4ggkM5mUz^dm?Wue`sKL0fsd-n`BrF#$m)&yCN@B^cmm(NRB;NarC> z*T^M-i6k7*7Q&@?QfxQXJPj{Ef>0hHD%HBhNF;Sr-2_>SL3ry7t?*#*(C3Rk_YAB0`?&@i{RVFeI^U;0}4j0Ej;7UO(2XgZM`1 zQ^3xNA3YLg)grUg2jMMUw49ViK@kWR-?x*!Q3LVqJzk@`awvM_7?)&#Jq0p7$e4t) z_gU7$La{k}pgvT0J9uM9>LySuXo=N2m{MigR2!dWh1*-3Ib)uUX{8qCV}XU&^gx4) zh|&5f+jGsp9-#kDXcq^g>D|>OD)_3d#p;X7O}dEE7_i!u@1WpY=G9Wc(xEXAm(64L zAWvVH2>Twg98`B+q1qAqwHaf>xqp~y(KQ^^dGJ+OXehr<_dU-JP!fsGOBnQdtHlo2 z9y-QPF%vqHCypnIl@wzVk_MfSSN+ zJN(`Vd@J6)A3{TW$K|vW22`l6~2ZA2Y{nIJQVHA2AVguRVjTDAg^C(J!3s}Z8 z+7iX2X%m13LpNl3aBn{})%z!|61O%gwb|z?u#>>F#GfYL$aX}IBxQ$!zQ0@jG0lcf zm4tMh{EXJ*Ii;$`IWpI z<1epa3{=CAlD#c3Siq4$`LAgyS|tzcPUNTPd+<%Rges7^6A598WL7X(0R>=@~j zHV|xmX1P&VDm1w9pyFk`;0L@y!R0mhh}Mqh)IZO3Bw5+Wv;1F{iDZw7eHrrr9aXce zwIBfE>(0Zkn4Id&)=j^hD;oS1W5@i#E50&$v%P(1I&lM$;)#h*#g*dTQ1;HPYKsOh zwA_o>Y~cI`(YU3xy@DojtK~LQr!Kb$Wr^D34Fis#f_F6WfYCGxY(xe7k6EdJL?a4< zV)%h_0MSRz`XDOY6wZb%1S${Drg771P~Jgor3nW49tSx;&!EYWH`7e)N+H;m_!mmC=V|Kq^B1ZRk_L#dh7_3Ov32?U@e!*w1APB+>Ggzsxa z$~|qq+yt}STSQm6TB4tXQ#RJk41+yRLR}^fZ%vJH7-a?NJyqZ=nZlh|(V{lCG(y5PG!Pz0ga)V1U2k}^6+a4xX0kn;!u(QD^`6n5>p&N z)q6tik+t{#1_`+g_FXCL+9SQW$m(vd=rQfzIL;NgybvI?5`@_zYM%w~?|b@GUBT(!~m;WRo#C6hHQ@X5w;I6g0)%e>M$ zS%Xq6o|x7$CY-Ag6yG)_I0O)1ya6z4EPX@Ug=xAKjY@%}O&u3gGhcQdPq7;Z!5Y*U zUo0B_J*P~0B}Het-iixTjHExMlobl@sL=xTUB(^HgkDm?n;?x#%r+f_nLCqGjM$$%n7tl7+o=Rh2926#KzsQ?hzP*?lS= zSvblAU`b#I1hfhu-&$6i#xThk|8N19{FTPkm)S|Kn)S&|!}gzvUHzWdf-TFI2^O@> zbaV}Oh7u9XJ1u8J+(bl#aep=SWk6|(oOQ2RMaX`6xC@#8Wh{ybI|xMT3FQWp9LBP! zwsu9`3A5UEnpV~ppRE=EVD?zIqD zi=Q1Q;L#7YWMw3_X9i1%rv7hfncX&QM8mghyaJ|WeNy>?0&fIP9Gqo}CSncZ$+xny zF&g(Z4inYGAyDA`Jh!TmPRW~PrxxIZ8)GzN@||=7denUduMA!{UweGLZ6M;6jX`u(m}n?BPw zp7(PmFOx)V4TB`uaFJWS$UZN)?*8%BY;H`gI$S`lGaR=yF!QkYq63|^-n>}T*SAD7 z`<9y3T@bW4IjEDb6v}92r`VUn3ItlC(XBdV^CoY0=K2bbku6~EPCLfFW0$CWInUmf z(xyNQd;lokaOPboaAVxivIvsdIrhte>?i}^DqE}(qq7;Ly{%KkZkn^Noml*ky11ML z@B58I(o=+YVZ}%Ti6(jGZ@?Iiy?zy~vW7&5CGWnu77mqqUP-@^Ef`Oe4nD561t4|J)>WTAWeAtxreKDRxuJ+Li*jhkCHNB7(1R4wDks#UI z4n5`(w72#LU_lB;h|Goev4&qbM^j~);~m?QZEEZ~6EAPR>QSgR`ozV~1Lw3qvT6u$ z5}S2O3V7OB8=-H&qge5Oc?7?$bEq?{4Z*&T9xJFlt27`o#tmiz@S9#%`f9v^)s-A z+s4|lxHkzN&tg~)#11dEg!@)IW}{Z%?=I|fBdsX2CTdeeY`99`5AcXmCLbWt6(5D6 z4-9vYK`Sf5X+;pnd(6=NnA*JO;%*NE)E_RCur9eh$C3t z7qZqw0gYxC>Lo_r^-y`#`!hgB#FXX_US&+-2*(WcTMnb#@bPv5 z{$)|wnK1^LQ+8S(MAsXRo5H)Q%H<6HD9AY?>opn2Zy_}CYScPg(4Xg#&Xe9KcL{1NGuB1;vHP0~Xsrcf;2Bdy(6XC#9 zkqn?K7ya`(gRsA4rvDn$`bL_68;zWHg1JHxp0ah+klacJWegH_K50JPt53X$1k|-D zluJYDq4YCiOUA_3VV5Dz1D`V60dufOonH&d7n`*qxdDHllg>30(YoDY(PR>NHROcTCTpB= zpJsVS+ip#<3L>7pUv_F79pimKgXloIqb8ZrTid9cUCY#sL!MwXe>nwvxmFu}=~QYo z21m#^fvTSIkE3k0(EWh2z)r4kry>2qnxxn_1XlMB`QFHX%&m^zFHq0=&gMu(W8dwn zTXi>8g>4hH^us-YVQ$H2XM19sLKO?qt=**zf|mXG_L$?O{C-C1CQgGN*6r6k&DNmE z;clq2ay>Rf!e;S=$YS_sDQKKrX9?$E&DoX(|F?Lxdk{X;v!IUZRdz!43qh)a`?qdt z@W75Zj_SY(7DDxjICf_KC-P)?qUoQs6E0!svimPIhj4l}pu7C5{nc+yIip2LQ3&k$cAcasX=T@eu(HkcL|fS)k@W**pITdy zzfi`hS8>e|2O=`wtc>J(;}PYx%_PC4I}HV8_~|LOrvqiLCY*Lra+qOXV1_OwB|Rk2 zA7{QPX}Tydhu*-m$_MzozD_n?lMy&pR(o??LgD~*t;L&AZ4<6A>oLzr+QkDX^YkXh zx~ohy!XhTJOuV8w#{t&*$_vkn^_#*NKj~gFv};1{0=3i(3DMD|nz21uM@6?UMf~9x zU78U0YYw~>IkDSLpC|{K*dtY(;67-@qn0T*KWRF;{Un*pcw!0Zu1U7nv-3bRo&tJh zM9f5G755j-*J79?jqNy0>5AMiL{GbVrNRq|ViXXBubfA^_h-M{P(V|*n-N;4q0qE{ znJUS{G-TLkRiML=KZV@RPR7q-s(w+(C=nx7aRX%cPdQ?B>%tg65bCQ zQ~rZHt7f3$>~nZj7!e#^RZ+RY88C)9;DNTC)t>?->AX{mMsom5PTKwV_qxm5k1)n; zZ@x(`hFwA$IwS%UwdHAMx@4ifSpM(vn89$zZtz)dXcpY7OhDz75GZzXxNy$53c!)q z9wqSQj_KYl3du=I6W#1%?0jvOl(lITW@eYjg>JK;&ytMJWa;^!rQ3#wvDs`wc*&$d*D9GI# z90SSv=^Mb4yloqYSi~^8<7Y|bDAFG0i+=|d&fBSS>8#W|UC{M#5Fp1Z+ZM&wtNtoc zK1k6UqwL+k7Zzs-O^n#55#jcKvx=k*478(y zhj)soOt9XzVBKr)l)o5J=S^wSPz{3Sex=N@B{^pyOwsfWF~o#^V6ho`f@%TLNn&LVz5X_xBOR%vEcPyO*L)!$E0Hms(mL}e40XNIwUUD>b;h0u;FidkK5p3J z4{OxfJQoh~(OEM~XEz?n@(?Z*UYgo0(GPr61hX6gwf=oWIZ^Wj%ij{tsz52bfxm8# zc7vBT;r|AVwoTmdzfi2X<`3t>*s!y^wN5bQ4u*PL=KB7^TFg=NYPt&MS~x827~-9D zXLA4LA;jcbeTFv7@JsXanQ|79pHv&iygfJKx52Q`Sh7~MW&F-vz*~w;+3{nUxxDfb z6=F)ED4I~YG{~t57E?%pX)isUME_Fo+m``xL;YsH$IISb?qJ38++q+!6YJDQ5z4IC zfWwXRdAY5>Nm!%@_9;fF38O&w(<}en7-TIkZu+X_NMH18XB+T}_rgyqEcc`(A9G!k z@3<;=6FXoKWDB;@M#+7){{m?+xEquLM!4j`p4TYJK3K?v%o7&Vf}PEp4M-0fFw79G z6zooEEf;#+?Of3EecMDwbbNT+i8y}pFr5M7?F5BeG2=xq_Qy%%wokBji1RA{h;=L) z7M@mMqaX3GskS(sBrc!RSWCLuS=!Z?OQ;7lC%4nldVHk%i$&`n4TO)O6+}-t1rjC4 zqX&p81bB@PYAUn*yMO)S!u!BLdNYbS<8Df^FJP$#7qG^>wx{X7(J&l@XsTUkHMWs89Xt;ro5?DUn}>$e6m$2@&Shlk-7~D7O52Pt0WR;ZeE1M1 zdiEkgY@PIr=Z#Z%16k+2kjCuDF{6n~7!XHCH-f16=jnPCs=`@p{Tqdf{)O6(ZLtho zpKvnbU31JRS9TY5UrmA~%1OVMnL@S@1q<=&hjH2s4>n`hAPW@x(Yw)k-=Cw3p+N26 zAoN=kQH*7*P&FcktczYONK3}EWJjOdD#juacZ{3!Zu?z&qxr~nJSZ0nLMJ;s^8XtD z2bkw~=r`r`%SyE~o*{FOeMJd-9s;d3@RJ?nx z7_v=Bx-N3F`m6y~`o^LQ)`Qc{(Sti8LQXJdq(g5JUrSX;8R#(EP2h0kZae zoHp82VkRbYl&&WM0Ze=Z7^T3dg!RxfO;BcR*p`DF*bXPBrrag9QaJWE!mmJ|xTDC} z*|qb{y2F+|&2~xe8eIgI{5$NcSfN^O1+MO98A<6S%YUfK*s&KObA}QZ!Lz;kuHj+f4ROmzt%2_q86P z#6~TUWXpkoC{#pv?}6TFF%CcDXSndS8aL-lILAMVe}+wJxXjpv?s}V%vJZ}V-VGWe zGqAEAML>@s6JHrAIaNo#&_-s(7DGtDj(L}z`iJ-2lqU{8zJII~Rx?|qF4B*^wmSNZ zZAGQv^fE6|t3*42BD3gI)snVAs0c?vW|f@cxtRA}$ydnpn2Y~Ur-{#rZk%F%!7jt{l}`O>35J|iqNAZNlcluqoV=p0xg&@ zhCp6{>;#2T)nhZOzU-cOnzSo|A1;HD&;@&fufFrb?>UGmqUF5UR36Jizs%$%qyWo_ zAKcqX>Pk^KM5~=q<4L*ze@DwF=?nb1T?@A{^NT`J#q>Ja;U`CY0pNO0pS1=-Tv);g z>_%Ibv{=-ZE??}$6K)m3%0LYUBU+Q@^$a$JqZWy6>p6`AQ6R!6ErEHk-C-6R1fJyV zehqbBSr_i;G^%vn6fq<=+2fa|Wy}Pd-83OXZXL!V@CcaFrpbNws@NL(I7Iw;p#Fx$ zR1j_E(;TNrAI=j(eBH@N;mkuryzmi9vV}q|`tj%J?(a1c09LMj*xWmkJ+VDLghPUMe33bcyrHV>v~-7f-3h!?}*#v z3ZX|VwP{1Wj@U1WO^Pk1eV3sA;L?=hZx%r9Nz>VJV7cIy_W(oRIRLA;Md>vFoNM{T4Q2HM_Ev$s~Qsn;f)1QRc%`F|0De| zdiJt3VHpLE7ulbz%!uu4Sgt_(@Ubu1>>_p{MHCrbE+8A}i6tO?2hqIE%2y;Qp~ea= zPBDYLj9C8-k&+#JsD3jqw;D#+bR-5lf-ylU!ZlmJgjx#wRzDz=SLOWSN>{er^z$Y2 znm&&h!|iUU<+R2Jo_FPU8Vs<2*$Ks03J7LWjjil`myqIs&tkQ*hxz>R+Z zXhXT~I3qfhfzFsx&<<9KxEO*4IAyFyZJT*C&8Qj#`6`Np>qGb>wIIpIEOo41)*hc# z#3$E;$`i^4tHv`ojq3Ygl!dVQ5Th*7O`JG3w);!_a}fb&LVFnV0;UL8uDBukf}t}@ zvD;g>yN>nm@N>OAo0Dcx8ix7r>9j~%UCSj7j5A}5SIiiTMzwkFt~2mHP#xLgmA7m2 zZv7quKC7VtOOyr&*50y}u5S`M#ufQ@V?i$=@QW;`00DNylEcp@a7 zlW9Ye9+XS`Zv%P3pvZyndTxW0iLG6R89t-*{SnK22J?@W6V^@wG(7SxD`{ptS#M8; zO(QF63*MC)u~C*$OI-;L$O+ns@R} zjxlumh^oaIisFFx@rGkOkF=_4I~aE&hDQGJc~k-)ML5_GUK%-ZFn0vu|zDFC0-D716cj5Mn_9mPJeua&XwE<2lvDH+su*IpyJfp~7e#)O`r1}7l zR~+0?PV`&o9(z*+1|D=Gt;kmSf5$|YH!~P{D)}XQdD?n7mH}7lTv^G_5_j%v=#vk* zBF%;D;V75cfAKDa9Ky6!e;X-#V(;`gBGWTVmuW!nIR?lBF^mH!)IXtNZ{Vq`{zYbl zn67J_{2;e`5MXy%^{)fSN}v->DYg);7|f3Cd%aubw5DDi^t$soO(#;2d}-qS zUUPB(^*Ls`Mg-1*NfFnj()QA{=bSxo-*U0!%f(;c0Qcq(!t~a@0$?pH1_A?}Kge9t zBq)CZw=-T@jyP&#$2HxiBx7y1x+;Oio1di}WAR=?)T9(`hJorx3=1 z7h)lfH-xn-iL)9#%NAk*R8d0~fj6@L1m-YVX~Okyw7Qz!<-$0QO>UvYIieb@0dxpd z3P2w~Vc=~>MJDrxm?$uXp*fo~H8b5x-Tf`l7K3pwL1uO8^06I& zr7^W#yxbE%<0qzTYvY*J%y^ec@2>#0k+sP;YA?**O?!YN7y%G^TT}~-?+w=1Y)g+x zl^(ObODmd`iO>2A#$}ZB;5hzC1@_*UsVQ=HC#xreFjdOYTkG}dH;9Wl_|r!-n);k) zdWkLr?5L#OzDachyqkyzJo=wmxEbQxTR{HA2xYhUHTtsseb28TBXABd0TBE4Z%>KF z_oau~64jMT045a0H(x>}CX1}QT1`&GA1@2(mHQ;tzGonsHOvmttIXw10(Y+~G-m!% zKM;TlN^D|PkhG|!7;K2FyPl32xU#2kIn*R66lGwpHz7(wvZIuU;1x5IAef3zL(;-Y zo>=#`W{nJwq`{6Y&x_#Z1=mj-%Qk|YAY6l5r4w4V4v1TowrcJ*Qndr>T5N)yrw0jD zOC+p2#2HOA4jB|Z zhdm48o#{AvZOyFTWY?lew4nm>KX>LZ-rD^4hwRun_twdfnzfWJ-S8TWIJzgt#g2B1 z9wWd`t&NkXp=W7D&2Ep>Zloz+?sCU%T|V{dxk19JCINQ1QtFP!kbQ8}aqm#ZBp zieN@o8_x00u{=hYLF1aYofoY?S*_hGkvDYA?Ydw?F zFty4U5M>{R4HjvB=!OA~V%We)d8A4LT#0NULxQBsdMm{q4uNr6gtmv2jwaV7ns^t3 zWy8eFrACDyM-;sHX|Cv$ucuaY%I8nTPMq7?5#{)Y4mnwS){AmHXi$+|c>4|jiqv99nP*F3 zUp@>CXq6ohTQ@YGSF63yF|4`0802!vC5J5C@d5*9?rw@Ob8}_V)#gl89+5(g*fL7Uvj{_Rb_Wh8b-C4&ttd$RU92|M z`x?1U0HjeZgtwLm%&@lh-jP3=7EsO8bOP~?dmOm9S^nXT3O!NCn(;M-b|E^aY0ttb zkf`j?|G~S6ofwdSg1KbqmrTAjPbv6di(LdzBKyz6YCg8e!l%MxDyF}+YZ*S1)UztlpmHtS^Dgnb`gM~B)#DaCvu|z)J^GGl zN|mk*V=2GiqgJN-y*i8T@yN(XG5aqmT$ z9Bd`2{i?A^%Sumzb^BR-GV!}j^PLp*a}PVxc}u&USN9Q;nh>=SgE=d@HB$DKu2${$ zk`Az?(a)hZ6iY2RP9PJl9&~>q3H#oBsG6sGXBf zrC0fy|1K8*iM^36jvumMY()?6d`+d&-*36B?I%cuK-&h#UIBW;VQL`5ZcU>rU9cW z*UiHi6b>u@?B%69tETpE*_O~cUDdnDrVuP#KJ~}G+Nta($jMO&3x*_a;`D5 z%z&}*DeREg_I4mnU)AI8WzH60o3mbk6M^M%s28gjPEx3F-wt0TKPc-4z2C2Pny!OEfM& z{SqE_U}pl6M6~>xDA`L3w^zI+f@L_t5$~D9w?_!_H7f02atl)z%FP4#KKjnzC6lk?tR0o+L#=Fho(0*#x zIXgLyWaLB4pw^^MA;1?fPfX&+(oXf0uvwQpDej}5qk1S|i^?EDTAo;jnC;tgC8I{( z#N!9U&9zorsq0?v&wqNLjfARkZ{1pfq?X#L%3;8{BJDYJ$<;qKm^`NTiN-{%rQE*J z{IkJBH;qK711NdHc9=US$9G}OWHp*-J75*S1du`!A?y|wux8W(#i>FSEC>@yNH|1W z!8ItEC0m=cet?Xc)AZIN zv5kJc?$oviQn(pvZQ~QTPb&4jo1Isa>;s=~-RP#c+PRu74$ja8S9FqXZU=6wctfGF z=shij1v(~$$Oe{L5-_pGi`3m*^=+Ggo?1a`pOs{>K3v^2lkbuDw>>v^_0{FBPEMUF z>&V!I3*2H|ZHFASFh~StF&@X2jwPxY=Fq1N{URvcvY|>bQP}bT4OL&RclvmwPHcec zl%CkPrM|0NML@I9^;toXy-@Y-Fx5bHMZ`*9}qf0CP#WanRIwy;clK0ar zz*iB@mna^3H}5A=sP6E*Zmq)t+9G&3`XTx~s%O*Ip#_cje#y~h2&Wv~SJp0Gu;C?g z5heJF61IlamdA9}2RuS(vJ2Pu$ccFpl3rlYRXAE_Tj;zQeWhg49W(2ovlo}oLeJ0d zkBE-I`Quq1*S9J;5J=wHL?y^HtDiLO;km04X2t>=G3Vr(0giKT$b{3~qG}k46hp!3 zsxMeaZh7Rc!xte^$vQfxC_VquvJjgU4uBGtxFhVf5qzi=KG)W!Cyp0t_pPVnaG**q zuiEpw6A)$MC~_$0ssP@@vd9s{i?f;9QjD~!x%7|ik$SJ7;EV>)^_g^+s&09dSGvhl z>#^+RGyUxhfLk`W@4D7mX~1NGlh2Y5wwQxs3Xi2-!EmEaUq&$i30C{wk)XPasx0rS zeCU*p98z2iPZNmFpu%S*QWobJ9j;^4z~RpN!^`58&}oc<>5X?HdV0Kx>(lU|>twx{dpG_!lO*)|b9#M}JUF9W$bqy3 z<-a^P8-6xV#_3p_LUoFg$P$=xoGa*OFsr3E;%k$Wzk=85*3_ofO+xULrv};7ZHc1k zwyCg>-xG2QRov$Z_nQ=FWo*xVs5(;+@#r7?T8AZ?9pOu6K4Kk?S1%a+EiNx&lk!+CqNkPcT+`dB+>5tZT%j<Ts91u>cHElNLL|>t6`nD|0Rv8%PcD2c`DYb8(B% zY-9UDfm9ElY-;D~)<(jJ0Ol4WuKfHbcp8g8A$^f*fVp^mxEoH8KBum5C3dI49x|Jj zn~p@x@v{^&^I8!i^ad-TnWrxziWzJt17Ogd9u8fIZAKo7Cy$9|Z86u4{Sgl=aZjh4 zlNaN-c9mda0Pd_@Z(X%4uU7}5-1UsEDxnD9_LlSPhI(<((puQ}jL#mBC4Lo?0XNpn z-o86n31O|#=G?fR74$kX5=tmgHuOK2Hir4bh6R};+2e%nnSEmP4tUvQ#g0s$6@C9% z!u5sbjgGaU4P>V_YLsg&7BubdB*KD^8q^So6snGX4fkrFfej0h5x@~<@gQGiPy+ci z%X<4ytF*0@qgKp3LjiJnEhquQM_~?RbW<;VK)U`OCbMn1G}+mMS`ygia~|xIRDS=WJCP%QbID3>v?9dgeiB<||5XsEQO*%C zcM1e&E4So84(^V@Jgs0jaYK#u@y(;drdt82Jtja02hE}3V-=$&p({*$XIkrt_%2Wb zYjKeekiKbukWGq^jnCZgI?im_3zmw$x3(E>zokza(B2g&LD#iMC&NP`$p{v%$`J1#DW_Xr3o&P%tK^J~8Il^(Qw>*b(Yp zT*$ob*Ktqy=%yml9q8|70Rj<&UsbExmeaumwc?0+)V`?BPN%(Mpv0j)xW+zozg}0M zzO0=J%JfH)u5CV|qJ9_Y0GJG3SAP|G;Syg><_CRt9S$2iphYK$+mtMctHcXQ1qIq>Y4I`>*C?w_n7>U$TRlr__7*X_C zH1l!bX)36_RG;PWhL0Q=5@uXW8|kZIim=eG+Emg$WGJh`B8J{-9qt~CsXFF9w8bJ0 zCSIs#K491h=t%(ysg1sC*jz>}c4En32nz=RsO&6b%RriWN9TXy|1)85U#S(ESfB8L z&CFGd@xp%9G33B&f1K-`rXDoFj&XU5?WEoeXj$59s2b?s8k z=ONT{_VuiGefx=}rt*Y(f?l@F3&cEu^3V7Than9xgPw`MaG{L5OVem0n-@LgDl2RC za1pNG{>vhVXQ=)$+d__=0+8O{z4*Us>l+g5;Te zs69Z(V6Y<5zUX%@u)f>!g+9$a!OR|))Ura04`=mt586Vl#L!PQdK*eMTYn6V1{nrI z0FY2t==EJMnsJl&Vdy(R|D3#42R12!xy|~(!hm(cjvcxH00CtDLD$Ewt3g^?SG12F zvtpb+3{g+Ngx8F(Qi|p{A-PT{sQ%p(7kHj%DT$*t-2V#k3#oZQN;=u_7Q@0`r2pH+gBz6swQ~Z)rFiO5 zU4!mZzCea@G1^Mfo^g5J#!)Lb6(4<-pJsd_sXZM+bMRyHInfe(}L$G#B$f2X7_gc_Wz0`M<12xCR2Gv(16fTri z971@n)%{~VN`w!%sr?HB8pTc%8T==Uh4I6>duX-OAOg}Dnpa`8#OBWHmWj_DsY35{ zhjGb*E#Rsb13IXTQ*adl=;?M03<&zZxtU`5d2~U0Oa1z(#gIYk<`;tRa`Ule!sN4r z-YvQ-u?sAX#s+=o2Qiwx`iBSm?uFrbP3~TN*U^HH-jO)`!R}y)P`Ilvo{e)wk+K5pd%-K(93?AAO7Q z{ z+M6JA(CqeEuOlDfwL(kgn=SjBU|0u6GpB;=KoI)7a%JT$I(Hm7n4x@Oh<6vhh^%J< zTsG9iRI(qfKYj;RC6aMLCuLwik8}~)T&iN=Bo86|TT>>>KLY{`gEkuBSbM1B531rc z0NYj$tId{AsPJoKU`14Guj(t#volrwiSxfxZGpT*q^O0b_LhjIHR1JD+qMfuH&JTSSQojJrHiG- zCj1N=f;DMSnoQ^eK|vOzWQ000FF7&vMTpszA;c068v<=z9s z2HG(PJG@EvGpmchb)3Rr)GcH%Rh>xd{!GzoNr||tin>vbA4sL=AUraA_ecZPpHSr^ zlf8f+WskMrRSZY-)=-yRaN6L?}^NO_c|&5by>CG49#YHdi#~K zrt0M#kWz7e?2bxGG!mjWCkVStvcjP6rct?5maE*{NTpeqpQ>`8m-R;Z${_i^TuOGf8op*_Xr3m9XU>R7;k0blj!ShlR+>0C{7$U@ zV*h|pLKs#I&oDq8*p%N$h9kQFDNB=sCkt&JpJT`Q-zmc(9y+>9mb{D#%OJ`i{kSnY3AN}7<{AQ>7pQ#`V{x!3N z5jF_@Ooc-)i9Zcos9b1iOMvIuM-r1Qi20*1U9a`|vem!M$Bszxg%k92usgs`37ZPN znvdz$(BvwdUPuhUWY(~^SYPp~W`9lJ$-;3!LUXLGRa<=<7j6$((N=lasIg)eu2VIN zZM8)R>S_e@IJ6sX@~;uOe9);@w>*}DJdGFKi|GdUTq6pCv%E#H=>JxS1F`6O?S9yu%fV9Scd^B4jY zQlC9RJ&yco)#-rO2CZ%aG{3L#&W8o{)uoeD7v-(zuUh{qZkV8RzWTy^DW2i6QLch9 zZ233BnnbmSsn8ryvrJeZyVNNP&|efR*Y6$Vo^w>Azwi5S>*YXNpdMj6idRx-=fPF7 zhhDZ?+q;btDEbA??Ft{4iKrgi7E!o`q&{y8wH*Q4MgFTO_*_T{C42!o&5Oj*Zo>Kc zt5hS%`xP#-9v~Z7KxCOxqQQy;Z+m?#oLRi+7y*O1X zfry2HyWl934q2eFwa({}fA{ZwxSUP|W;~}AKRCM8@Ga^3w zRRE|_8+O{*S<9{6H}|@4-8Dn;24Y)gF$DY-fJE7w- zHM<$yRPfS@5c?PBg#6w}%~2wuP0e-D^sk`}QL2vpf`ek4Eb7U$$jqeTr-cYcvS+<4 zw;bQcfa&IK zd+q7XvyG#{M$P8KF#A3+SIDLLKr6gz>7dBj^)W>6VGuW)5le!P#%zX#^lGQ1*!plw zq|TmchIo!8l3SG}7!;JRz4`48xeE*}#G-SnN{m$zc7N|MZ8cNd_tVBkiGylMXhiIS%3e5n` zB#_QM!SN-4SK#0%DA;TGb_XIr=v$Jx%y9_wg(*9nW9-#UK^}7{0hIMB`hgdD-=zNm zl_{;M(x%>yqq~Ofy29$o=AAB5^U|1I3T6=ww?PpCg`96t1PL?B{G?Ej625gBf6BIO z;!4)12ltK3?OI7|Dzy}aF{K{-I zR?cAUNk-8!XXH{04dWemXTjZ~6W)Gl%ko*p=)}yvb_@SJ67?OBuS0$M#L9+*k3FS%>eT59X{iROEPwz(W}#q&0x|i+Q2WK!?c}N= z1_fm9ss0kFlo_Fr1i~fpT&e2H9bYI^JXin}De#O5Jd!fmgAGurA8#|HLdiS1_B?bM zB^UYiD?)UR)TNX@7VDtzmjkupr87f0CqFpI!&z}}r+q$p0J5!KQLgS9A=(|}YP1H< zT;`oU!h-;AVe@c^ud8Ip|+$il}po#6??=%)lCdSuIU99aF%)bbURj9QEL}QZm z*B#rxPO{zk&t&rIFnc^uv%Rk6e9y9B+!wo!KvA$ew4%gOevJHwI@VhVGx_{#_&rh$fhM%XWEB)DstnVvI|iA3ZfYcl`2 zB*e|guVf*^w^RrHw(VIRWv-Wkm@15n;ttbzh0Wzc$hnRZT^Y1oF&{ zIE8?g!4VXGP>l*d)vy6H!$o4=B85hx3T4)sMk!V36nZbXI>s-oJo<5?D%^2I^EwHt zJypczl#$yr(D3~B+${+gKg`v9Iz|=BJi=Fs{RCc1m3jRA#gcy*x^YN{0cagH(OU*{ zCXE37GF>(K;kdq*jSsxGfehKv40er;kcIETft%^*RoCtSmjlC{w;d~IALp%U0AiD; z<#6rltA44gB^hzVMqL)B%GK-FXO0&YoyMko?Y38L=SisWc`82q9KQ- zMV=op;`9nI9wk)f+fo$Y}yDrlVJ>U|d>MTZW}zl&22fUfHzuM~087f(u>CGxAI z+#J`lfLg9>o&wLoyl(j{-qR`ez<4j&?Kdav!^%I*P&(Tq~QjVq4q z>Jat5kt0PeNGns@TyUb}R2UQh00004%9rC15?<5O4Wtg1P7}FxP0xXs8C-P!`RLLuM z+AD#+U)aw-9GQ8t4wpAM>^O4smyH+E{P5C4c{*UqQO8&Iu|LO85}^)F;u%bracM|?d_`q16RwtytCw`t__27Uc-=G@$` ziNMu15-b?jZu6;`C%feZpNXvDKNCgVO%h;@oC(gFB;l%(qa#LY`Zy|_16<~^j@8r} zvmms3KN^>|YAzqBtn34I>ps1;)bG%?q6kd|rW79|(sShsy%G6#be=~tfjt*y4;h(2 zzR!InryGgEy#TIHS3(*pK6BEDhXB~VE?~mk46&?=5%d<3gjk6ni$f1dM^cU?A^FGP zzoY@aSAKXV-dUBh%oQ`K5967$&EybidTzApYc&qRD1A?PWeA|SM2peYR2j04$B(c? z^u1Z8D5|^%a+CM;Vahun2|cRqV1nK`5; + status = "disabled"; + perm-read; + perm-write; + perm-execute; + }; + + ram3x_dma_region: memory@2fc07000 { + compatible = "nordic,owned-memory"; + reg = <0x2fc07000 DT_SIZE_K(4)>; + status = "disabled"; + perm-read; + perm-write; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x2fc07000 0x1000>; + + cpuapp_dma_region: memory@680 { + compatible = "zephyr,memory-region"; + reg = <0x680 DT_SIZE_K(2)>; + status = "disabled"; + #memory-region-cells = <0>; + zephyr,memory-region = "DMA_RAM3x_APP"; + }; + + cpurad_dma_region: memory@e80 { + compatible = "zephyr,memory-region"; + reg = <0xe80 0x80>; + status = "disabled"; + #memory-region-cells = <0>; + zephyr,memory-region = "DMA_RAM3x_RAD"; + }; + }; + }; +}; + +&mram1x { + cpurad_rx_partitions: cpurad-rx-partitions { + compatible = "nordic,owned-partitions", "fixed-partitions"; + status = "disabled"; + perm-read; + perm-execute; + perm-secure; + #address-cells = <1>; + #size-cells = <1>; + + cpurad_slot0_partition: partition@66000 { + reg = <0x66000 DT_SIZE_K(256)>; + }; + }; + + cpuapp_rx_partitions: cpuapp-rx-partitions { + compatible = "nordic,owned-partitions", "fixed-partitions"; + status = "disabled"; + perm-read; + perm-execute; + perm-secure; + #address-cells = <1>; + #size-cells = <1>; + + cpuapp_slot0_partition: partition@a6000 { + reg = <0xa6000 DT_SIZE_K(512)>; + }; + + cpuppr_code_partition: partition@126000 { + reg = <0x126000 DT_SIZE_K(28)>; + }; + }; +}; diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-pinctrl.dtsi b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-pinctrl.dtsi new file mode 100644 index 00000000000..d3b79120322 --- /dev/null +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-pinctrl.dtsi @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&pinctrl { + /omit-if-no-ref/ uart135_default: uart135_default { + group1 { + psels = , + ; + }; + + group2 { + bias-pull-up; + psels = , + ; + }; + }; + + /omit-if-no-ref/ uart135_sleep: uart135_sleep { + group1 { + low-power-enable; + psels = , + , + , + ; + }; + }; + + /omit-if-no-ref/ uart136_default: uart136_default { + group1 { + psels = , + ; + }; + + group2 { + bias-pull-up; + psels = , + ; + }; + }; + + /omit-if-no-ref/ uart136_sleep: uart136_sleep { + group1 { + low-power-enable; + psels = , + , + , + ; + }; + }; +}; diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts new file mode 100644 index 00000000000..359c1f84307 --- /dev/null +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; + +#include +#include "nrf54h20pdk_nrf54h20-memory_map.dtsi" +#include "nrf54h20pdk_nrf54h20-pinctrl.dtsi" + +/ { + compatible = "nordic,nrf54h20pdk_nrf54h20-cpuapp"; + model = "Nordic nRF54H20 PDK nRF54H20 Application MCU"; + + chosen { + zephyr,console = &uart136; + zephyr,code-partition = &cpuapp_slot0_partition; + zephyr,flash = &mram1x; + zephyr,sram = &cpuapp_ram0; + }; + + aliases { + led0 = &led0; + led1 = &led1; + led2 = &led2; + led3 = &led3; + sw0 = &button0; + sw1 = &button1; + sw2 = &button2; + sw3 = &button3; + }; + + buttons { + compatible = "gpio-keys"; + + button0: button_0 { + gpios = <&gpio0 8 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 0"; + zephyr,code = ; + }; + + button1: button_1 { + gpios = <&gpio0 9 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 1"; + zephyr,code = ; + }; + + button2: button_2 { + gpios = <&gpio0 10 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 2"; + zephyr,code = ; + }; + + button3: button_3 { + gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button 3"; + zephyr,code = ; + }; + }; + + leds { + compatible = "gpio-leds"; + + led0: led_0 { + gpios = <&gpio9 0 GPIO_ACTIVE_HIGH>; + label = "Green LED 0"; + }; + + led1: led_1 { + gpios = <&gpio9 1 GPIO_ACTIVE_HIGH>; + label = "Green LED 1"; + }; + + led2: led_2 { + gpios = <&gpio9 2 GPIO_ACTIVE_HIGH>; + label = "Green LED 2"; + }; + + led3: led_3 { + gpios = <&gpio9 3 GPIO_ACTIVE_HIGH>; + label = "Green LED 3"; + }; + }; +}; + +&ram3x_dma_region { + status = "okay"; +}; + +&cpuapp_dma_region { + status = "okay"; +}; + +&cpuapp_rx_partitions { + status = "okay"; +}; + +&cpuppr_vpr { + source-memory = <&cpuppr_code_partition>; + execution-memory = <&cpuppr_ram3x_region>; +}; + +&gpiote130 { + status = "okay"; + owned-channels = <0 1 2 3 4 5 6 7>; +}; + +&gpio0 { + status = "okay"; +}; + +&gpio9 { + status = "okay"; +}; + +&grtc { + status = "okay"; + child-owned-channels = <5 6>; + nonsecure-channels = <5 6>; + owned-channels = <4 5 6>; +}; + +&uart135 { + pinctrl-0 = <&uart135_default>; + pinctrl-1 = <&uart135_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&uart136 { + status = "okay"; + memory-regions = <&cpuapp_dma_region>; + pinctrl-0 = <&uart136_default>; + pinctrl-1 = <&uart136_sleep>; + pinctrl-names = "default", "sleep"; +}; diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.yaml b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.yaml new file mode 100644 index 00000000000..a364c2863d3 --- /dev/null +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.yaml @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +identifier: nrf54h20pdk_nrf54h20_cpuapp +name: nRF54H20-PDK-nRF54H20-Application +type: mcu +arch: arm +toolchain: + - gnuarmemb + - xtools + - zephyr +ram: 32 +flash: 368 +supported: + - gpio diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp_defconfig b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp_defconfig new file mode 100644 index 00000000000..1f7ef38a7fc --- /dev/null +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp_defconfig @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_NRF54HX=y +CONFIG_SOC_NRF54H20=y +CONFIG_SOC_NRF54H20_ENGA_CPUAPP=y +CONFIG_BOARD_NRF54H20PDK_NRF54H20_CPUAPP=y + +CONFIG_USE_DT_CODE_PARTITION=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# Enable hardware stack protection +CONFIG_HW_STACK_PROTECTION=y + +# MPU-based null-pointer dereferencing detection cannot be applied +# as the (0x0 - 0x400) region is unmapped for this target. +CONFIG_NULL_POINTER_EXCEPTION_DETECTION_NONE=y + +# Enable cache +CONFIG_CACHE_MANAGEMENT=y +CONFIG_EXTERNAL_CACHE=y + +# Enable GPIO +CONFIG_GPIO=y + +# Enable UART driver +CONFIG_SERIAL=y + +# Enable console +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts new file mode 100644 index 00000000000..02213d88645 --- /dev/null +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; + +#include +#include "nrf54h20pdk_nrf54h20-memory_map.dtsi" +#include "nrf54h20pdk_nrf54h20-pinctrl.dtsi" + +/ { + compatible = "nordic,nrf54h20pdk_nrf54h20-cpurad"; + model = "Nordic nRF54H20 PDK nRF54H20 Radio MCU"; + + chosen { + zephyr,console = &uart135; + zephyr,code-partition = &cpurad_slot0_partition; + zephyr,flash = &mram1x; + zephyr,sram = &cpurad_ram0; + }; +}; + +&ram3x_dma_region { + status = "okay"; +}; + +&cpurad_dma_region { + status = "okay"; +}; + +&cpurad_rx_partitions { + status = "okay"; +}; + +&grtc { + status = "okay"; + child-owned-channels = <8 9 10 11 12>; + interrupts = <109 NRF_DEFAULT_IRQ_PRIORITY>, + <108 NRF_DEFAULT_IRQ_PRIORITY>; + nonsecure-channels = <8 9 10 11 12>; + owned-channels = <7 8 9 10 11 12 13 14>; +}; + +&uart135 { + status = "okay"; + memory-regions = <&cpurad_dma_region>; + pinctrl-0 = <&uart135_default>; + pinctrl-1 = <&uart135_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&uart136 { + pinctrl-0 = <&uart136_default>; + pinctrl-1 = <&uart136_sleep>; + pinctrl-names = "default", "sleep"; +}; diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.yaml b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.yaml new file mode 100644 index 00000000000..d1c8548d07d --- /dev/null +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.yaml @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +identifier: nrf54h20pdk_nrf54h20_cpurad +name: nRF54H20-PDK-nRF54H20-Radio +type: mcu +arch: arm +toolchain: + - gnuarmemb + - xtools + - zephyr +ram: 32 +flash: 368 +supported: + - gpio diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad_defconfig b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad_defconfig new file mode 100644 index 00000000000..254d8656e61 --- /dev/null +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad_defconfig @@ -0,0 +1,30 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_NRF54HX=y +CONFIG_SOC_NRF54H20=y +CONFIG_SOC_NRF54H20_ENGA_CPURAD=y +CONFIG_BOARD_NRF54H20PDK_NRF54H20_CPURAD=y + +CONFIG_USE_DT_CODE_PARTITION=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# Enable hardware stack protection +CONFIG_HW_STACK_PROTECTION=y + +# MPU-based null-pointer dereferencing detection cannot be applied +# as the (0x0 - 0x400) region is unmapped for this target. +CONFIG_NULL_POINTER_EXCEPTION_DETECTION_NONE=y + +# Enable cache +CONFIG_CACHE_MANAGEMENT=y +CONFIG_EXTERNAL_CACHE=y + +# Enable UART driver +CONFIG_SERIAL=y + +# Enable console +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y From 6c5a7ba4cd796e99a9d0ed828c992e45e946c366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 31 Jan 2024 15:37:12 +0100 Subject: [PATCH 1253/1623] [nrf fromtree] tests: lib: cpp: Exclude cpp98 test on nRF54H20 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to nRF54L15, the MDK files in HAL for this SoC are not compatible with C++98, so currently the test cannot be performed on this SoC. Signed-off-by: Andrzej Głąbek (cherry picked from commit 00566d64fa901cbd7725068f6ff82ee0f0fffc16) --- tests/lib/cpp/cxx/testcase.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/lib/cpp/cxx/testcase.yaml b/tests/lib/cpp/cxx/testcase.yaml index cbdaacf714c..d1a7235a84c 100644 --- a/tests/lib/cpp/cxx/testcase.yaml +++ b/tests/lib/cpp/cxx/testcase.yaml @@ -34,8 +34,11 @@ tests: # -std=c++98) cpp.main.cpp98: arch_exclude: posix - # Exclude nRF54L15 as its HAL is not compatible with C++98. - platform_exclude: nrf54l15pdk_nrf54l15_cpuapp + # Exclude nRF54L15 and nRF54H20 as Nordic HAL is not compatible with C++98. + platform_exclude: + - nrf54l15pdk_nrf54l15_cpuapp + - nrf54h20pdk_nrf54h20_cpuapp + - nrf54h20pdk_nrf54h20_cpurad build_only: true extra_configs: - CONFIG_STD_CPP98=y From 566c717fc028cb4cd4bad8f0c925e9c2137f5207 Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Wed, 4 Oct 2023 13:46:54 -0400 Subject: [PATCH 1254/1623] [nrf fromtree] iterable_sections: define iterable_named_alternate variant Add STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE() for structures ordered by name in a custom section. Signed-off-by: Christopher Friedt (cherry picked from commit 903f6281ace3f58adc96d26d04cbae212c3968bb) --- include/zephyr/sys/iterable_sections.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/zephyr/sys/iterable_sections.h b/include/zephyr/sys/iterable_sections.h index fe1976363ca..3ec4af5e9a0 100644 --- a/include/zephyr/sys/iterable_sections.h +++ b/include/zephyr/sys/iterable_sections.h @@ -234,6 +234,16 @@ extern "C" { #define STRUCT_SECTION_ITERABLE_NAMED(struct_type, name, varname) \ TYPE_SECTION_ITERABLE(struct struct_type, varname, struct_type, name) +/** + * @brief Defines a new element for an iterable section with a custom name, + * placed in a custom section. + * + * The name can be used to customize how iterable section entries are sorted. + * @see STRUCT_SECTION_ITERABLE_NAMED() + */ +#define STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE(struct_type, secname, name, varname) \ + TYPE_SECTION_ITERABLE(struct struct_type, varname, secname, name) + /** * @brief Iterate over a specified iterable section (alternate). * From 5ccd0f365eeac4b335b3a30a95b9ed61a92c87fd Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Wed, 4 Oct 2023 13:40:29 -0400 Subject: [PATCH 1255/1623] [nrf fromtree] tests: misc: iterable_sections: add named alternate tests Add tests for the newly added STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE(). This type of section should be iterated with STRUCT_SECTION_FOREACH_ALTERNATE(). Signed-off-by: Christopher Friedt (cherry picked from commit 28dccf236b2e34ad8567db2bf708f472e02ce8ee) --- tests/misc/iterable_sections/CMakeLists.txt | 2 ++ tests/misc/iterable_sections/sections-ram.ld | 1 + tests/misc/iterable_sections/sections-rom.ld | 1 + tests/misc/iterable_sections/src/main.c | 24 ++++++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/tests/misc/iterable_sections/CMakeLists.txt b/tests/misc/iterable_sections/CMakeLists.txt index 24472eb8574..1a187eace6d 100644 --- a/tests/misc/iterable_sections/CMakeLists.txt +++ b/tests/misc/iterable_sections/CMakeLists.txt @@ -12,9 +12,11 @@ zephyr_iterable_section(NAME test_ram GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} zephyr_iterable_section(NAME test_ram2 GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) zephyr_iterable_section(NAME test_ram_named GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) zephyr_iterable_section(NAME test_ram_numeric NUMERIC GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +zephyr_iterable_section(NAME ramn_alt GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) zephyr_linker_sources(SECTIONS sections-rom.ld) zephyr_iterable_section(NAME test_rom KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) zephyr_iterable_section(NAME test_rom2 KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) zephyr_iterable_section(NAME test_rom_named KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) zephyr_iterable_section(NAME test_rom_numeric NUMERIC KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) +zephyr_iterable_section(NAME romn_alt KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) diff --git a/tests/misc/iterable_sections/sections-ram.ld b/tests/misc/iterable_sections/sections-ram.ld index c7c86a8d97c..96454fb282d 100644 --- a/tests/misc/iterable_sections/sections-ram.ld +++ b/tests/misc/iterable_sections/sections-ram.ld @@ -4,3 +4,4 @@ ITERABLE_SECTION_RAM(test_ram, 4) ITERABLE_SECTION_RAM(test_ram2, 4) ITERABLE_SECTION_RAM(test_ram_named, 4) ITERABLE_SECTION_RAM_NUMERIC(test_ram_numeric, 4) +ITERABLE_SECTION_RAM(ramn_alt, 4) diff --git a/tests/misc/iterable_sections/sections-rom.ld b/tests/misc/iterable_sections/sections-rom.ld index c837cbfbc4b..525c480c7bf 100644 --- a/tests/misc/iterable_sections/sections-rom.ld +++ b/tests/misc/iterable_sections/sections-rom.ld @@ -4,3 +4,4 @@ ITERABLE_SECTION_ROM(test_rom, 4) ITERABLE_SECTION_ROM(test_rom2, 4) ITERABLE_SECTION_ROM(test_rom_named, 4) ITERABLE_SECTION_ROM_NUMERIC(test_rom_numeric, 4) +ITERABLE_SECTION_ROM(romn_alt, 4) diff --git a/tests/misc/iterable_sections/src/main.c b/tests/misc/iterable_sections/src/main.c index e5d697b8a80..a2dde51bd23 100644 --- a/tests/misc/iterable_sections/src/main.c +++ b/tests/misc/iterable_sections/src/main.c @@ -44,6 +44,12 @@ const STRUCT_SECTION_ITERABLE(test_ram_numeric, ramn_10) = {0x03}; const STRUCT_SECTION_ITERABLE(test_ram_numeric, ramn_11) = {0x04}; const STRUCT_SECTION_ITERABLE(test_ram_numeric, ramn_3) = {0x02}; +#define NAMED_ALT_EXPECT 0x4273 + +/* alternate naming */ +const STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE(test_ram_named, ramn_alt, R, ramn_42) = {0x42}; +const STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE(test_ram_named, ramn_alt, W, ramn_73) = {0x73}; + /** * * @brief Test iterable in read write section. @@ -89,6 +95,13 @@ ZTEST(iterable_sections, test_ram) } zassert_equal(out, RAM_EXPECT, "Check value incorrect (got: 0x%x)", out); + + out = 0; + STRUCT_SECTION_FOREACH_ALTERNATE(ramn_alt, test_ram_named, t) { + out = (out << 8) | t->i; + } + + zassert_equal(out, NAMED_ALT_EXPECT, "Check value incorrect (got: 0x%x)", out); } struct test_rom { @@ -126,6 +139,10 @@ const STRUCT_SECTION_ITERABLE(test_rom_numeric, romn_10) = {0x30}; const STRUCT_SECTION_ITERABLE(test_rom_numeric, romn_11) = {0x40}; const STRUCT_SECTION_ITERABLE(test_rom_numeric, romn_3) = {0x20}; +/* alternate naming */ +const STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE(test_rom_named, romn_alt, R, romn_73) = {0x73}; +const STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE(test_rom_named, romn_alt, O, romn_42) = {0x42}; + /** * * @brief Test iterable in read only section. @@ -161,6 +178,13 @@ ZTEST(iterable_sections, test_rom) } zassert_equal(out, ROM_EXPECT, "Check value incorrect (got: 0x%x)", out); + + out = 0; + STRUCT_SECTION_FOREACH_ALTERNATE(romn_alt, test_rom_named, t) { + out = (out << 8) | t->i; + } + + zassert_equal(out, NAMED_ALT_EXPECT, "Check value incorrect (got: 0x%x)", out); } ZTEST_SUITE(iterable_sections, NULL, NULL, NULL, NULL, NULL); From c18e8542d823008c96ffd4039e73e7af8b2ca48d Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Fri, 22 Sep 2023 15:08:11 -0400 Subject: [PATCH 1256/1623] [nrf fromtree] device: support for mutable devices Add support for mutable devices. Mutable devices are those which can be modified after declaration, in-place, in kernel mode. In order for a device to be mutable, the following must be true * `CONFIG_DEVICE_MUTABLE` must be y-selected * the Devicetree bindings for the device must include `mutable.yaml` * the Devicetree node must include the `zephyr,mutable` property Signed-off-by: Christopher Friedt (cherry picked from commit afc59112a96c884abf39100b06e89bde4effea29) --- cmake/linker_script/common/common-ram.cmake | 4 +++ dts/bindings/base/mutable.yaml | 13 +++++++ include/zephyr/device.h | 40 ++++++++++++--------- include/zephyr/init.h | 18 +++++++++- include/zephyr/linker/common-ram.ld | 4 +++ kernel/Kconfig | 7 ++++ 6 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 dts/bindings/base/mutable.yaml diff --git a/cmake/linker_script/common/common-ram.cmake b/cmake/linker_script/common/common-ram.cmake index a116977ce8c..7e639043bce 100644 --- a/cmake/linker_script/common/common-ram.cmake +++ b/cmake/linker_script/common/common-ram.cmake @@ -128,3 +128,7 @@ if(CONFIG_USB_HOST_STACK) zephyr_iterable_section(NAME usbh_contex GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) zephyr_iterable_section(NAME usbh_class_data GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) endif() + +if(CONFIG_DEVICE_MUTABLE) + zephyr_iterable_section(NAME device_mutable GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) +endif() diff --git a/dts/bindings/base/mutable.yaml b/dts/bindings/base/mutable.yaml new file mode 100644 index 00000000000..0e2d1cad3b0 --- /dev/null +++ b/dts/bindings/base/mutable.yaml @@ -0,0 +1,13 @@ +# Copyright (c) 2023, Meta +# SPDX-License-Identifier: Apache-2.0 + +# Properties for Mutable devices + +properties: + zephyr,mutable: + type: boolean + description: | + True iff the device structure may be mutated. + + Inherit this binding for devices that are runtime-modifiable, in-place. + This places the device structure into SRAM rather than Flash. diff --git a/include/zephyr/device.h b/include/zephyr/device.h index 630a059c155..77c0537ffdf 100644 --- a/include/zephyr/device.h +++ b/include/zephyr/device.h @@ -41,6 +41,10 @@ extern "C" { */ #define Z_DEVICE_DEPS_ENDS INT16_MAX +/** @brief Determine if a DT node is mutable */ +#define Z_DEVICE_IS_MUTABLE(node_id) \ + COND_CODE_1(IS_ENABLED(CONFIG_DEVICE_MUTABLE), (DT_PROP(node_id, zephyr_mutable)), (0)) + /** @endcond */ /** @@ -924,12 +928,13 @@ static inline bool z_impl_device_is_ready(const struct device *dev) * @param api Reference to device API. * @param ... Optional dependencies, manually specified. */ -#define Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, pm, data, config, level, \ - prio, api, state, deps) \ - COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \ - const STRUCT_SECTION_ITERABLE_NAMED(device, \ - Z_DEVICE_SECTION_NAME(level, prio), \ - DEVICE_NAME_GET(dev_id)) = \ +#define Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, pm, data, config, level, prio, api, state, \ + deps) \ + COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \ + COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), (const)) \ + STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE( \ + device, COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (device_mutable), (device)), \ + Z_DEVICE_SECTION_NAME(level, prio), DEVICE_NAME_GET(dev_id)) = \ Z_DEVICE_INIT(name, pm, data, config, api, state, deps) /* deprecated device initialization levels */ @@ -961,15 +966,15 @@ static inline bool z_impl_device_is_ready(const struct device *dev) * @param level Initialization level. * @param prio Initialization priority. */ -#define Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, init_fn_, level, prio) \ - Z_DEVICE_LEVEL_CHECK_DEPRECATED_LEVEL(level) \ - \ - static const Z_DECL_ALIGN(struct init_entry) __used __noasan \ - Z_INIT_ENTRY_SECTION(level, prio, \ - Z_DEVICE_INIT_SUB_PRIO(node_id)) \ - Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \ - .init_fn = {.dev = (init_fn_)}, \ - .dev = &DEVICE_NAME_GET(dev_id), \ +#define Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, init_fn_, level, prio) \ + Z_DEVICE_LEVEL_CHECK_DEPRECATED_LEVEL(level) \ + \ + static const Z_DECL_ALIGN(struct init_entry) __used __noasan Z_INIT_ENTRY_SECTION( \ + level, prio, Z_DEVICE_INIT_SUB_PRIO(node_id)) \ + Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \ + .init_fn = {COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (.dev_rw), (.dev)) = \ + (init_fn_)}, \ + .dev = &DEVICE_NAME_GET(dev_id), \ } /** @@ -1015,8 +1020,9 @@ static inline bool z_impl_device_is_ready(const struct device *dev) * don't have a corresponding @ref device allocated. There's no way to figure * that out until after we've built the zephyr image, though. */ -#define Z_MAYBE_DEVICE_DECLARE_INTERNAL(node_id) \ - extern const struct device DEVICE_DT_NAME_GET(node_id); +#define Z_MAYBE_DEVICE_DECLARE_INTERNAL(node_id) \ + extern COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), \ + (const)) struct device DEVICE_DT_NAME_GET(node_id); DT_FOREACH_STATUS_OKAY_NODE(Z_MAYBE_DEVICE_DECLARE_INTERNAL) diff --git a/include/zephyr/init.h b/include/zephyr/init.h index 9b0d2993d62..7882b207b8d 100644 --- a/include/zephyr/init.h +++ b/include/zephyr/init.h @@ -73,6 +73,17 @@ union init_function { * @retval -errno If device initialization fails. */ int (*dev)(const struct device *dev); +#ifdef CONFIG_DEVICE_MUTABLE + /** + * Device initialization function (rw). + * + * @param dev Device instance. + * + * @retval 0 On success + * @retval -errno If device initialization fails. + */ + int (*dev_rw)(struct device *dev); +#endif }; /** @@ -96,7 +107,12 @@ struct init_entry { * If the init entry belongs to a device, this fields stores a * reference to it, otherwise it is set to NULL. */ - const struct device *dev; + union { + const struct device *dev; +#ifdef CONFIG_DEVICE_MUTABLE + struct device *dev_rw; +#endif + }; }; /** @cond INTERNAL_HIDDEN */ diff --git a/include/zephyr/linker/common-ram.ld b/include/zephyr/linker/common-ram.ld index c03351abf98..7bb6e55f1c1 100644 --- a/include/zephyr/linker/common-ram.ld +++ b/include/zephyr/linker/common-ram.ld @@ -137,6 +137,10 @@ ITERABLE_SECTION_RAM(zbus_channel_observation_mask, 1) #endif /* CONFIG_ZBUS */ +#if defined(CONFIG_DEVICE_MUTABLE) + ITERABLE_SECTION_RAM(device_mutable, 4) +#endif + #ifdef CONFIG_USERSPACE _static_kernel_objects_end = .; #endif diff --git a/kernel/Kconfig b/kernel/Kconfig index 6280e80a400..d5e737e7655 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -1260,6 +1260,13 @@ config DEVICE_DEPS_DYNAMIC Option that makes it possible to manipulate device dependencies at runtime. +config DEVICE_MUTABLE + bool "Mutable devices [EXPERIMENTAL]" + select EXPERIMENTAL + help + Support mutable devices. Mutable devices are instantiated in SRAM + instead of Flash and are runtime modifiable in kernel mode. + endmenu rsource "Kconfig.vm" From 5e3875f0752dd5fb0c129551ceb13e73ae9ede5d Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Fri, 22 Sep 2023 15:26:11 -0400 Subject: [PATCH 1257/1623] [nrf fromtree] drivers: misc: devmux: a device multiplexer pseudo-device The Device Multiplexer (devmux) is a pseudo-device that can be used to select between multiple included sub-devices. It is experimental, but its current use is in system remediation. Take for example, the scenario where the system console and log subsystem both have the uart backend enabled. The case may arise, where the chosen backing uart could be an abstraction of another very high-bandwidth bus - such as a PCIe BAR, a UDP socket, or even even just memory. If the "service" (for lack of a better term) that backs this abstract "uart" experiences an error, it is of critical importance to be able to switch the system console, uart log backend, or whatever to another uart (semi-transparently) in order to bring up a shell, continue to view system logs, or even just support user console I/O. Signed-off-by: Christopher Friedt (cherry picked from commit 37e19451ec2d8cf3e48edb6c8bf9333cb796ab6c) --- drivers/misc/CMakeLists.txt | 1 + drivers/misc/Kconfig | 1 + drivers/misc/devmux/CMakeLists.txt | 10 ++ drivers/misc/devmux/Kconfig | 23 +++ drivers/misc/devmux/devmux.c | 179 ++++++++++++++++++++ dts/bindings/misc/zephyr,devmux.yaml | 33 ++++ include/zephyr/drivers/misc/devmux/devmux.h | 90 ++++++++++ 7 files changed, 337 insertions(+) create mode 100644 drivers/misc/devmux/CMakeLists.txt create mode 100644 drivers/misc/devmux/Kconfig create mode 100644 drivers/misc/devmux/devmux.c create mode 100644 dts/bindings/misc/zephyr,devmux.yaml create mode 100644 include/zephyr/drivers/misc/devmux/devmux.h diff --git a/drivers/misc/CMakeLists.txt b/drivers/misc/CMakeLists.txt index 863f839184e..6c4ec2384d9 100644 --- a/drivers/misc/CMakeLists.txt +++ b/drivers/misc/CMakeLists.txt @@ -6,3 +6,4 @@ add_subdirectory_ifdef(CONFIG_GROVE_LCD_RGB grove_lcd_rgb) add_subdirectory_ifdef(CONFIG_PIO_RPI_PICO pio_rpi_pico) add_subdirectory_ifdef(CONFIG_NXP_S32_EMIOS nxp_s32_emios) add_subdirectory_ifdef(CONFIG_TIMEAWARE_GPIO timeaware_gpio) +add_subdirectory_ifdef(CONFIG_DEVMUX devmux) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 66d83fc693d..52c77b4c7ec 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -10,5 +10,6 @@ source "drivers/misc/grove_lcd_rgb/Kconfig" source "drivers/misc/pio_rpi_pico/Kconfig" source "drivers/misc/nxp_s32_emios/Kconfig" source "drivers/misc/timeaware_gpio/Kconfig" +source "drivers/misc/devmux/Kconfig" endmenu diff --git a/drivers/misc/devmux/CMakeLists.txt b/drivers/misc/devmux/CMakeLists.txt new file mode 100644 index 00000000000..94f74ea57ce --- /dev/null +++ b/drivers/misc/devmux/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2023, Meta +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() + +zephyr_syscall_header( + ${ZEPHYR_BASE}/include/zephyr/drivers/misc/devmux/devmux.h +) + +zephyr_library_sources(devmux.c) diff --git a/drivers/misc/devmux/Kconfig b/drivers/misc/devmux/Kconfig new file mode 100644 index 00000000000..4f848b4e06c --- /dev/null +++ b/drivers/misc/devmux/Kconfig @@ -0,0 +1,23 @@ +# Copyright (c) 2023, Meta +# SPDX-License-Identifier: Apache-2.0 + +config DEVMUX + bool "Device Multiplexer (devmux) [EXPERIMENTAL]" + depends on DT_HAS_ZEPHYR_DEVMUX_ENABLED + depends on DEVICE_MUTABLE + select EXPERIMENTAL + help + Devmux is a pseudo-device that operates as a device switch. It allows + software to select the data, config, and api from a number of linked + devices. + +if DEVMUX + +config DEVMUX_INIT_PRIORITY + int "Devmux init priority" + default 51 + help + Init priority for the devmux driver. It must be + greater than the priority of the initially selected muxed device. + +endif diff --git a/drivers/misc/devmux/devmux.c b/drivers/misc/devmux/devmux.c new file mode 100644 index 00000000000..653236f903d --- /dev/null +++ b/drivers/misc/devmux/devmux.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2023, Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT zephyr_devmux + +#include +#include +#include +#include + +struct devmux_config { + const struct device **devs; + const size_t n_devs; +}; + +struct devmux_data { + struct k_spinlock lock; + size_t selected; +}; + +/* The number of devmux devices */ +#define N DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) + +static const struct device *devmux_devices[N]; +static const struct devmux_config *devmux_configs[N]; +static struct devmux_data *devmux_datas[N]; + +static bool devmux_device_is_valid(const struct device *dev) +{ + for (size_t i = 0; i < N; ++i) { + if (dev == devmux_devices[i]) { + return true; + } + } + + return false; +} + +static size_t devmux_inst_get(const struct device *dev) +{ + for (size_t i = 0; i < N; i++) { + if (dev == devmux_devices[i]) { + return i; + } + } + + return SIZE_MAX; +} + +const struct devmux_config *devmux_config_get(const struct device *dev) +{ + for (size_t i = 0; i < N; i++) { + if (dev == devmux_devices[i]) { + return devmux_configs[i]; + } + } + + return NULL; +} + +struct devmux_data *devmux_data_get(const struct device *dev) +{ + for (size_t i = 0; i < N; i++) { + if (dev == devmux_devices[i]) { + return devmux_datas[i]; + } + } + + return NULL; +} + +ssize_t z_impl_devmux_select_get(const struct device *dev) +{ + ssize_t index; + struct devmux_data *const data = devmux_data_get(dev); + + if (!devmux_device_is_valid(dev)) { + return -EINVAL; + } + + K_SPINLOCK(&data->lock) + { + index = data->selected; + } + + return index; +} + +#ifdef CONFIG_USERSPACE +ssize_t z_vrfy_devmux_select_get(const struct device *dev) +{ + return z_impl_devmux_select_get(dev); +} +#include +#endif + +int z_impl_devmux_select_set(struct device *dev, size_t index) +{ + struct devmux_data *const data = devmux_data_get(dev); + const struct devmux_config *config = devmux_config_get(dev); + + if (!devmux_device_is_valid(dev) || index >= config->n_devs) { + return -EINVAL; + } + + if (!device_is_ready(config->devs[index])) { + return -ENODEV; + } + + K_SPINLOCK(&data->lock) + { + *dev = *config->devs[index]; + data->selected = index; + } + + return 0; +} + +#ifdef CONFIG_USERSPACE +int z_vrfy_devmux_select_set(struct device *dev, size_t index) +{ + return z_impl_devmux_select_set(dev, index); +} +#include +#endif + +static int devmux_init(struct device *const dev) +{ + size_t inst = devmux_inst_get(dev); + struct devmux_data *const data = dev->data; + const struct devmux_config *config = dev->config; + size_t sel = data->selected; + + devmux_configs[inst] = config; + devmux_datas[inst] = data; + + if (!device_is_ready(config->devs[sel])) { + return -ENODEV; + } + + *dev = *config->devs[sel]; + + return 0; +} + +#define DEVMUX_PHANDLE_TO_DEVICE(node_id, prop, idx) \ + DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)) + +#define DEVMUX_PHANDLE_DEVICES(_n) \ + DT_INST_FOREACH_PROP_ELEM_SEP(_n, devices, DEVMUX_PHANDLE_TO_DEVICE, (,)) + +#define DEVMUX_SELECTED(_n) DT_INST_PROP(_n, selected) + +#define DEVMUX_DEFINE(_n) \ + BUILD_ASSERT(DT_INST_PROP_OR(_n, zephyr_mutable, 0), \ + "devmux nodes must contain the 'zephyr,mutable' property"); \ + BUILD_ASSERT(DT_INST_PROP_LEN(_n, devices) > 0, "devices array must have non-zero size"); \ + BUILD_ASSERT(DEVMUX_SELECTED(_n) >= 0, "selected must be > 0"); \ + BUILD_ASSERT(DEVMUX_SELECTED(_n) < DT_INST_PROP_LEN(_n, devices), \ + "selected must be within bounds of devices phandle array"); \ + static const struct device *demux_devs_##_n[] = {DEVMUX_PHANDLE_DEVICES(_n)}; \ + static const struct devmux_config devmux_config_##_n = { \ + .devs = demux_devs_##_n, \ + .n_devs = DT_INST_PROP_LEN(_n, devices), \ + }; \ + static struct devmux_data devmux_data_##_n = { \ + .selected = DEVMUX_SELECTED(_n), \ + }; \ + \ + DEVICE_DT_INST_DEFINE(_n, devmux_init, NULL, &devmux_data_##_n, &devmux_config_##_n, \ + PRE_KERNEL_1, CONFIG_DEVMUX_INIT_PRIORITY, NULL); + +DT_INST_FOREACH_STATUS_OKAY(DEVMUX_DEFINE) + +#define DEVMUX_DEVICE_GET(_n) DEVICE_DT_INST_GET(_n), +static const struct device *devmux_devices[] = {DT_INST_FOREACH_STATUS_OKAY(DEVMUX_DEVICE_GET)}; diff --git a/dts/bindings/misc/zephyr,devmux.yaml b/dts/bindings/misc/zephyr,devmux.yaml new file mode 100644 index 00000000000..744daaca120 --- /dev/null +++ b/dts/bindings/misc/zephyr,devmux.yaml @@ -0,0 +1,33 @@ +# Copyright (c) 2023, Meta +# SPDX-License-Identifier: Apache-2.0 + +description: Generic Device Multiplexer + +compatible: "zephyr,devmux" + +include: [base.yaml, mutable.yaml] + +properties: + + devices: + type: phandles + required: true + description: | + Devices to be multiplexed. + + selected: + type: int + default: 0 + description: | + Initial multiplexer selection. + + This must be in the range [0, N-1], where N is the length of the + 'devices' phandle list. + + If unspecified, the default selection is zero in order to ensure that + the multiplexer is ready for use (i.e. one of the [0, N-1] multiplexed + devices is selected). Zero is, necessarily, the only possible valid + default value since the phandle list must have length >= 1. + + Note: Specifying a value of 'selected' outside the range [0, N-1] + results in a compile-time error. diff --git a/include/zephyr/drivers/misc/devmux/devmux.h b/include/zephyr/drivers/misc/devmux/devmux.h new file mode 100644 index 00000000000..1772d719d96 --- /dev/null +++ b/include/zephyr/drivers/misc/devmux/devmux.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023, Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Public APIs for the Device Multiplexer driver + */ + +#ifndef INCLUDE_ZEPHYR_DRIVERS_MISC_DEVMUX_H_ +#define INCLUDE_ZEPHYR_DRIVERS_MISC_DEVMUX_H_ + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Devmux Driver APIs + * @defgroup demux_interface Devmux Driver APIs + * @ingroup misc_interfaces + * + * @details + * Devmux operates as a device multiplexer, forwarding the characteristics of + * the selected device. + * + * ``` + * +----------+ +----------+ + * | devmux | | devmux | + * | | | | + * dev0 | | dev0 | | + * +----------> \ | +----------> | + * | \ | | | + * dev1 | \ | dev0 dev1 | | dev2 + * +----------> O +----------> +----------> O +----------> + * | | | / | + * dev2 | | dev2 | / | + * +----------> | +----------> / | + * | | | | + * | | | | + * | | | | + * +-----^----+ +-----^----+ + * | | + * select == 0 | select == 2 | + * +--------------+ +---------------+ + * ``` + * @{ + */ + +/** + * @brief Get the current selection of a devmux device. + * + * Return the index of the currently selected device. + * + * @param dev the devmux device + * @return The index (>= 0) of the currently active multiplexed device on success + * @retval -EINVAL If @p dev is invalid + */ +__syscall ssize_t devmux_select_get(const struct device *dev); + +/** + * @brief Set the selection of a devmux device. + * + * Select the device at @p index. + * + * @param[in] dev the devmux device + * @param index the index representing the desired selection + * @retval 0 On success + * @retval -EINVAL If @p dev is invalid + * @retval -ENODEV If the multiplexed device at @p index is not ready + */ +__syscall int devmux_select_set(struct device *dev, size_t index); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#include + +#endif /* INCLUDE_ZEPHYR_DRIVERS_MISC_DEVMUX_H_ */ From 92e2ba15bdf9265155cabcafa4bcb11d3d14ad04 Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Fri, 22 Sep 2023 15:36:43 -0400 Subject: [PATCH 1258/1623] [nrf fromtree] tests: drivers: console: add console_switching test This testsuite exercises a number of things. Namely * `mutable` devices (i.e. those backed in SRAM) * `uart_emul` support for interrupt mode (receive only) * `devmux` capabilities of multiplexing several uarts * switching the system console between several uart backends Testing Done: ``` west build -p auto -b qemu_riscv64 -t run \ tests/drivers/console_switching/ ... *** Booting Zephyr OS build zephyr-v3.4.0-3988-gaaefb2d764ea *** Running TESTSUITE console_switching ================================================================ START - test_read read "Hello, uart_emul0!" from uart_emul0 read "Hello, uart_emul1!" from uart_emul1 read "Hello, uart_emul0!" from uart_emul0 read "Hello, uart_emul1!" from uart_emul1 PASS - test_read in 0.005 seconds ================================================================ START - test_write wrote "Hello, uart_emul0!" to uart_emul0 wrote "Hello, uart_emul1!" to uart_emul1 wrote "Hello, uart_emul0!" to uart_emul0 wrote "Hello, uart_emul1!" to uart_emul1 PASS - test_write in 0.003 seconds ================================================================ TESTSUITE console_switching succeeded ------ TESTSUITE SUMMARY START ------ SUITE PASS - 100.00% [console_switching]: pass = 2, fail = 0,... - PASS - [console_switching.test_read] duration = 0.005 seconds - PASS - [console_switching.test_write] duration = 0.003 seconds ------ TESTSUITE SUMMARY END ------ =============================================================== PROJECT EXECUTION SUCCESSFUL ``` Signed-off-by: Christopher Friedt (cherry picked from commit b13ec704d0dcb3cb2d99f8c7236b4baa13833639) --- .../drivers/console_switching/CMakeLists.txt | 9 ++ .../boards/qemu_riscv64.overlay | 39 ++++++ tests/drivers/console_switching/prj.conf | 9 ++ tests/drivers/console_switching/src/main.c | 124 ++++++++++++++++++ tests/drivers/console_switching/testcase.yaml | 16 +++ 5 files changed, 197 insertions(+) create mode 100644 tests/drivers/console_switching/CMakeLists.txt create mode 100644 tests/drivers/console_switching/boards/qemu_riscv64.overlay create mode 100644 tests/drivers/console_switching/prj.conf create mode 100644 tests/drivers/console_switching/src/main.c create mode 100644 tests/drivers/console_switching/testcase.yaml diff --git a/tests/drivers/console_switching/CMakeLists.txt b/tests/drivers/console_switching/CMakeLists.txt new file mode 100644 index 00000000000..3ba70cc081e --- /dev/null +++ b/tests/drivers/console_switching/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(uart_console_switching) + +target_sources(app PRIVATE + src/main.c + ) diff --git a/tests/drivers/console_switching/boards/qemu_riscv64.overlay b/tests/drivers/console_switching/boards/qemu_riscv64.overlay new file mode 100644 index 00000000000..47bd7945189 --- /dev/null +++ b/tests/drivers/console_switching/boards/qemu_riscv64.overlay @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023, Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,console = &devmux0; + zephyr,shell_uart = &devmux0; + }; + + euart0: uart_emul0 { + compatible = "zephyr,uart-emul"; + current-speed = <0>; + status = "okay"; + }; + + euart1: uart_emul1 { + compatible = "zephyr,uart-emul"; + current-speed = <0>; + status = "okay"; + }; + + devmux0: dev_mux_0 { + compatible = "zephyr,devmux"; + devices = <&uart0 &euart0 &euart1>; + zephyr,mutable; + status = "okay"; + }; + + devmux1: dev_mux_1 { + compatible = "zephyr,devmux"; + devices = <&uart0 &euart0 &euart1>; + zephyr,mutable; + selected = <2>; + status = "okay"; + }; +}; diff --git a/tests/drivers/console_switching/prj.conf b/tests/drivers/console_switching/prj.conf new file mode 100644 index 00000000000..fcdd67928c4 --- /dev/null +++ b/tests/drivers/console_switching/prj.conf @@ -0,0 +1,9 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_SERIAL=y +CONFIG_CONSOLE=y +CONFIG_CONSOLE_SUBSYS=y +CONFIG_CONSOLE_GETLINE=y +CONFIG_DEVICE_MUTABLE=y +CONFIG_DEVMUX=y +CONFIG_UART_EMUL=y diff --git a/tests/drivers/console_switching/src/main.c b/tests/drivers/console_switching/src/main.c new file mode 100644 index 00000000000..95cde150c9b --- /dev/null +++ b/tests/drivers/console_switching/src/main.c @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2023, Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#define BUF_SIZE 32 + +/* array of const struct device* */ +#define PHANDLE_TO_DEVICE(node_id, prop, idx) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)) +static const struct device *devs[] = { + DT_FOREACH_PROP_ELEM_SEP(DT_NODELABEL(devmux0), devices, PHANDLE_TO_DEVICE, (,))}; + +/* array of names, e.g. "euart0" */ +#define PHANDLE_TO_NAME(node_id, prop, idx) DT_NODE_FULL_NAME(DT_PHANDLE_BY_IDX(node_id, prop, idx)) +static const char *const name[] = { + DT_FOREACH_PROP_ELEM_SEP(DT_NODELABEL(devmux0), devices, PHANDLE_TO_NAME, (,))}; + +/* array of greetings, e.g. "Hello, euart0!" */ +#define PHANDLE_TO_TEXT(node_id, prop, idx) \ + "Hello, " DT_NODE_FULL_NAME(DT_PHANDLE_BY_IDX(node_id, prop, idx)) "!" +static const char *const text[] = { + DT_FOREACH_PROP_ELEM_SEP(DT_NODELABEL(devmux0), devices, PHANDLE_TO_TEXT, (,))}; + +ZTEST(console_switching, test_write) +{ + size_t normal_uart = DT_PROP(DT_NODELABEL(devmux0), selected); + struct device *const devmux_dev = DEVICE_DT_GET(DT_NODELABEL(devmux0)); + + /* for each uart_emul device */ + for (size_t i = 0, j = 0, N = ARRAY_SIZE(devs); i < 2 * N; i++, j++, j %= N) { + if (j == normal_uart) { + /* skip testing non-emul uart */ + continue; + } + + int ret[4]; + char buf[BUF_SIZE] = {0}; + + /* write text[j] to dev[j] */ + ret[0] = devmux_select_set(devmux_dev, j); + printk("%s", text[j]); + ret[1] = uart_emul_get_tx_data(devs[j], buf, ARRAY_SIZE(buf)); + ret[2] = devmux_select_set(devmux_dev, normal_uart); + + zassert_ok(ret[0], "Failed to select devmux %zu", j); + zassert_ok(ret[2], "Switching back to selection %zu failed", normal_uart); + + /* verify that text[j] was written to dev[j] */ + TC_PRINT("wrote '%s' to %s\n", buf, name[j]); + + zassert_equal(ret[1], strlen(text[j]), "Only wrote %zu/%zu bytes of '%s'", + ret[1], strlen(text[j]), text[j]); + zassert_equal(0, strcmp(text[j], buf), "Strings '%s' and '%s' do not match", + text[j], buf); + } +} + +ZTEST(console_switching, test_read) +{ + size_t normal_uart = DT_PROP(DT_NODELABEL(devmux0), selected); + struct device *const devmux_dev = DEVICE_DT_GET(DT_NODELABEL(devmux0)); + + /* for each uart_emul device */ + for (size_t i = 0, j = 0, N = ARRAY_SIZE(devs); i < 2 * N; i++, j++, j %= N) { + if (j == normal_uart) { + /* skip testing non-emul uart */ + continue; + } + + int ret[4]; + char buf[BUF_SIZE] = {0}; + + /* read text[j] from dev[j] */ + ret[0] = devmux_select_set(devmux_dev, j); + console_getline_init(); + ret[1] = uart_emul_put_rx_data(devs[j], (uint8_t *)text[j], strlen(text[j])); + ret[3] = uart_emul_put_rx_data(devs[j], "\n", 1); + snprintf(buf, BUF_SIZE, "%s", console_getline()); + ret[2] = devmux_select_set(devmux_dev, normal_uart); + + zassert_ok(ret[0], "Failed to select devmux %zu", j); + zassert_ok(ret[2], "Switching back to selection %zu failed", normal_uart); + + /* verify that text[j] was written to dev[j] */ + TC_PRINT("read '%s' from %s\n", buf, name[j]); + + zassert_equal(ret[1], strlen(text[j]), "Only put %zu/%zu bytes of '%s'", + ret[1], strlen(text[j]), text[j]); + zassert_equal(0, strcmp(text[j], buf), "Strings '%s' and '%s' do not match", + text[j], buf); + } +} + +static void *setup(void) +{ + size_t selected = DT_PROP(DT_NODELABEL(devmux1), selected); + struct device *const devmux_dev = DEVICE_DT_GET(DT_NODELABEL(devmux1)); + + /* ensure that non-default initial selection via DT works */ + zassert_equal(devmux_select_get(devmux_dev), selected); + + return NULL; +} + +static void before(void *arg) +{ + struct device *const devmux_dev = DEVICE_DT_GET(DT_NODELABEL(devmux0)); + + zassert_ok(devmux_select_set(devmux_dev, 0)); + zassert_ok(devmux_select_get(devmux_dev)); + + for (size_t i = 1; i < ARRAY_SIZE(devs); ++i) { + uart_emul_flush_tx_data(devs[i]); + } +} + +ZTEST_SUITE(console_switching, NULL, setup, before, NULL, NULL); diff --git a/tests/drivers/console_switching/testcase.yaml b/tests/drivers/console_switching/testcase.yaml new file mode 100644 index 00000000000..0d24b5e596e --- /dev/null +++ b/tests/drivers/console_switching/testcase.yaml @@ -0,0 +1,16 @@ +common: + tags: + - drivers + - console + - emul + platform_allow: + - qemu_riscv64 + integration_platforms: + - qemu_riscv64 + +tests: + drivers.console_switching: {} + drivers.console_switching.user: + tags: userspace + extra_configs: + - CONFIG_USERSPACE=y From 301dbb2f4f817882c0cfe8b32d226ee0e34e8571 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Wed, 29 Nov 2023 10:32:41 +0000 Subject: [PATCH 1259/1623] [nrf fromtree] device: add braces around dev/dev_rw initializer The init_entry struct got modified to add a union with a non const dev pointer in afc59112a9. Some old compiler (such as GCC 4) seems to require a pair of brackets to correctly initialize the field in the union. Add those brackets to the initializers in device.h and init.h to maintain compatibility. Signed-off-by: Fabio Baltieri (cherry picked from commit 153f38a412f87aa652a1857ab83df2f4f9746326) --- include/zephyr/device.h | 5 ++++- include/zephyr/init.h | 5 +---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/zephyr/device.h b/include/zephyr/device.h index 77c0537ffdf..c55958924ff 100644 --- a/include/zephyr/device.h +++ b/include/zephyr/device.h @@ -974,7 +974,10 @@ static inline bool z_impl_device_is_ready(const struct device *dev) Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \ .init_fn = {COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (.dev_rw), (.dev)) = \ (init_fn_)}, \ - .dev = &DEVICE_NAME_GET(dev_id), \ + { \ + COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (.dev_rw), (.dev)) = \ + &DEVICE_NAME_GET(dev_id), \ + }, \ } /** diff --git a/include/zephyr/init.h b/include/zephyr/init.h index 7882b207b8d..78ec454f27c 100644 --- a/include/zephyr/init.h +++ b/include/zephyr/init.h @@ -205,10 +205,7 @@ struct init_entry { #define SYS_INIT_NAMED(name, init_fn_, level, prio) \ static const Z_DECL_ALIGN(struct init_entry) \ Z_INIT_ENTRY_SECTION(level, prio, 0) __used __noasan \ - Z_INIT_ENTRY_NAME(name) = { \ - .init_fn = {.sys = (init_fn_)}, \ - .dev = NULL, \ - } + Z_INIT_ENTRY_NAME(name) = {.init_fn = {.sys = (init_fn_)}} /** @} */ From 22792ced4d19d97c88bbeb7f31e79fb294af96d6 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 31 Jan 2024 13:21:10 +0100 Subject: [PATCH 1260/1623] [nrf fromtree] drivers: misc: nordic_vpr_launcher: initial version Add a custom driver that takes care of loading and launching RISC-V VPR cores found on the new nRF54 SoCs. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit d1468b8484af50053b29b2fd673d577623979324) --- drivers/misc/CMakeLists.txt | 1 + drivers/misc/Kconfig | 1 + .../misc/nordic_vpr_launcher/CMakeLists.txt | 5 ++ drivers/misc/nordic_vpr_launcher/Kconfig | 24 +++++++ .../nordic_vpr_launcher/nordic_vpr_launcher.c | 71 +++++++++++++++++++ 5 files changed, 102 insertions(+) create mode 100644 drivers/misc/nordic_vpr_launcher/CMakeLists.txt create mode 100644 drivers/misc/nordic_vpr_launcher/Kconfig create mode 100644 drivers/misc/nordic_vpr_launcher/nordic_vpr_launcher.c diff --git a/drivers/misc/CMakeLists.txt b/drivers/misc/CMakeLists.txt index 6c4ec2384d9..c23bdb185de 100644 --- a/drivers/misc/CMakeLists.txt +++ b/drivers/misc/CMakeLists.txt @@ -7,3 +7,4 @@ add_subdirectory_ifdef(CONFIG_PIO_RPI_PICO pio_rpi_pico) add_subdirectory_ifdef(CONFIG_NXP_S32_EMIOS nxp_s32_emios) add_subdirectory_ifdef(CONFIG_TIMEAWARE_GPIO timeaware_gpio) add_subdirectory_ifdef(CONFIG_DEVMUX devmux) +add_subdirectory_ifdef(CONFIG_NORDIC_VPR_LAUNCHER nordic_vpr_launcher) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 52c77b4c7ec..3511b8b6fd4 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -11,5 +11,6 @@ source "drivers/misc/pio_rpi_pico/Kconfig" source "drivers/misc/nxp_s32_emios/Kconfig" source "drivers/misc/timeaware_gpio/Kconfig" source "drivers/misc/devmux/Kconfig" +source "drivers/misc/nordic_vpr_launcher/Kconfig" endmenu diff --git a/drivers/misc/nordic_vpr_launcher/CMakeLists.txt b/drivers/misc/nordic_vpr_launcher/CMakeLists.txt new file mode 100644 index 00000000000..70c84e84217 --- /dev/null +++ b/drivers/misc/nordic_vpr_launcher/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() +zephyr_library_sources(nordic_vpr_launcher.c) diff --git a/drivers/misc/nordic_vpr_launcher/Kconfig b/drivers/misc/nordic_vpr_launcher/Kconfig new file mode 100644 index 00000000000..57605e505f2 --- /dev/null +++ b/drivers/misc/nordic_vpr_launcher/Kconfig @@ -0,0 +1,24 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config NORDIC_VPR_LAUNCHER + bool "Nordic VPR coprocessor launcher" + default y + depends on DT_HAS_NORDIC_NRF_VPR_COPROCESSOR_ENABLED + help + When enabled, the VPR coprocessors will be automatically launched + during system initialization. + +if NORDIC_VPR_LAUNCHER + +module = NORDIC_VPR_LAUNCHER +module-str = Nordic VPR Launcher +source "subsys/logging/Kconfig.template.log_config" + +config NORDIC_VPR_LAUNCHER_INIT_PRIORITY + int "Nordic VPR coprocessor launcher init priority" + default KERNEL_INIT_PRIORITY_DEVICE + help + The init priority of the VPR coprocessor launcher. + +endif # NORDIC_VPR_LAUNCHER diff --git a/drivers/misc/nordic_vpr_launcher/nordic_vpr_launcher.c b/drivers/misc/nordic_vpr_launcher/nordic_vpr_launcher.c new file mode 100644 index 00000000000..161465ba02c --- /dev/null +++ b/drivers/misc/nordic_vpr_launcher/nordic_vpr_launcher.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT nordic_nrf_vpr_coprocessor + +#include + +#include +#include +#include +#include +#include + +#include + +LOG_MODULE_REGISTER(nordic_vpr_launcher, CONFIG_NORDIC_VPR_LAUNCHER_LOG_LEVEL); + +struct nordic_vpr_launcher_config { + NRF_VPR_Type *vpr; + uintptr_t exec_addr; +#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(source_memory) + uintptr_t src_addr; + size_t src_size; +#endif +}; + +static int nordic_vpr_launcher_init(const struct device *dev) +{ + const struct nordic_vpr_launcher_config *config = dev->config; + +#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(source_memory) + if (config->src_size > 0U) { + LOG_DBG("Loading VPR (%p) from %p to %p (%zu bytes)", config->vpr, + (void *)config->src_addr, (void *)config->exec_addr, config->src_size); + memcpy((void *)config->exec_addr, (void *)config->src_addr, config->src_size); + } +#endif + + LOG_DBG("Launching VPR (%p) from %p", config->vpr, (void *)config->exec_addr); + nrf_vpr_initpc_set(config->vpr, config->exec_addr); + nrf_vpr_cpurun_set(config->vpr, true); + + return 0; +} + +/* obtain VPR source address either from memory or partition */ +#define VPR_SRC_ADDR(node_id) \ + (DT_REG_ADDR(node_id) + \ + COND_CODE_0(DT_FIXED_PARTITION_EXISTS(node_id), (0), (DT_REG_ADDR(DT_GPARENT(node_id))))) + +#define NORDIC_VPR_LAUNCHER_DEFINE(inst) \ + COND_CODE_1(DT_NODE_HAS_PROP(inst, source_memory), \ + (BUILD_ASSERT((DT_REG_SIZE(DT_INST_PHANDLE(inst, execution_memory)) == \ + DT_REG_SIZE(DT_INST_PHANDLE(inst, source_memory))), \ + "Source/execution memory sizes mismatch");), \ + ()) \ + \ + static const struct nordic_vpr_launcher_config config##inst = { \ + .vpr = (NRF_VPR_Type *)DT_INST_REG_ADDR(inst), \ + .exec_addr = DT_REG_ADDR(DT_INST_PHANDLE(inst, execution_memory)), \ + COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, source_memory), \ + (.src_addr = VPR_SRC_ADDR(DT_INST_PHANDLE(inst, source_memory)), \ + .src_size = DT_REG_SIZE(DT_INST_PHANDLE(inst, source_memory)),), \ + ())}; \ + \ + DEVICE_DT_INST_DEFINE(inst, nordic_vpr_launcher_init, NULL, NULL, &config##inst, \ + POST_KERNEL, CONFIG_NORDIC_VPR_LAUNCHER_INIT_PRIORITY, NULL); + +DT_INST_FOREACH_STATUS_OKAY(NORDIC_VPR_LAUNCHER_DEFINE) From 38c3336cc7bd672d03e5265f1aa068694edd51d7 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 1 Feb 2024 15:14:53 +0100 Subject: [PATCH 1261/1623] [nrf fromtree] snippets: add nordic-ppr Add a new snippet that allows to build any application with the capability to boot the PPR core found in some nRF54 SoCs. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 245da8aae65b2abdaa2654c63dc22994de64ee08) --- snippets/nordic-ppr/README.rst | 10 ++++++++++ .../boards/nrf54h20pdk_nrf54h20_cpuapp.overlay | 12 ++++++++++++ snippets/nordic-ppr/nordic-ppr.overlay | 8 ++++++++ snippets/nordic-ppr/snippet.yml | 8 ++++++++ 4 files changed, 38 insertions(+) create mode 100644 snippets/nordic-ppr/README.rst create mode 100644 snippets/nordic-ppr/boards/nrf54h20pdk_nrf54h20_cpuapp.overlay create mode 100644 snippets/nordic-ppr/nordic-ppr.overlay create mode 100644 snippets/nordic-ppr/snippet.yml diff --git a/snippets/nordic-ppr/README.rst b/snippets/nordic-ppr/README.rst new file mode 100644 index 00000000000..36eb74d193f --- /dev/null +++ b/snippets/nordic-ppr/README.rst @@ -0,0 +1,10 @@ +.. _nordic-ppr: + +Nordic PPR snippet (nordic-ppr) +############################### + +Overview +******** + +This snippet allows users to build Zephyr with the capability to boot Nordic PPR +(Peripheral Processor) from another core. diff --git a/snippets/nordic-ppr/boards/nrf54h20pdk_nrf54h20_cpuapp.overlay b/snippets/nordic-ppr/boards/nrf54h20pdk_nrf54h20_cpuapp.overlay new file mode 100644 index 00000000000..75128f42a13 --- /dev/null +++ b/snippets/nordic-ppr/boards/nrf54h20pdk_nrf54h20_cpuapp.overlay @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * SPDX-License-Identifier: Apache-2.0 + */ + +&cpuppr_ram3x_region { + status = "okay"; +}; + +&uart135 { + status = "reserved"; +}; diff --git a/snippets/nordic-ppr/nordic-ppr.overlay b/snippets/nordic-ppr/nordic-ppr.overlay new file mode 100644 index 00000000000..e33885fc10d --- /dev/null +++ b/snippets/nordic-ppr/nordic-ppr.overlay @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * SPDX-License-Identifier: Apache-2.0 + */ + +&cpuppr_vpr { + status = "okay"; +}; diff --git a/snippets/nordic-ppr/snippet.yml b/snippets/nordic-ppr/snippet.yml new file mode 100644 index 00000000000..9e1f20bb757 --- /dev/null +++ b/snippets/nordic-ppr/snippet.yml @@ -0,0 +1,8 @@ +name: nordic-ppr +append: + EXTRA_DTC_OVERLAY_FILE: nordic-ppr.overlay + +boards: + nrf54h20pdk_nrf54h20_cpuapp: + append: + EXTRA_DTC_OVERLAY_FILE: boards/nrf54h20pdk_nrf54h20_cpuapp.overlay From 902f8bde1cbeaffcb5b1bed68a12bfcbf8ff0ce2 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 31 Jan 2024 20:16:21 +0100 Subject: [PATCH 1262/1623] [nrf fromtree] drivers: serial: nrfx_uarte2: drop soc.h As it is not required (e.g. RISC-V nRF54H port does not provide soc.h) Signed-off-by: Gerard Marull-Paretas (cherry picked from commit d230542f1d0e94f10cf817f6b4c9a99b49927259) --- drivers/serial/uart_nrfx_uarte2.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/serial/uart_nrfx_uarte2.c b/drivers/serial/uart_nrfx_uarte2.c index c27f33c7284..bfc770f1399 100644 --- a/drivers/serial/uart_nrfx_uarte2.c +++ b/drivers/serial/uart_nrfx_uarte2.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include From 6733ed1418125be94189844c2dcddb1b0a894bf1 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 31 Jan 2024 20:15:20 +0100 Subject: [PATCH 1263/1623] [nrf fromtree] modules: hal_nordic: add configuration for nRF54H PPR core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add nrfx configuration file to make the nrfx HAL work for nRF54H PPR core. Signed-off-by: Gerard Marull-Paretas Signed-off-by: Andrzej Głąbek (cherry picked from commit 270ae630368781b58701f76ee1559391d83f1d39) --- modules/hal_nordic/nrfx/nrfx_config.h | 2 + .../nrfx/nrfx_config_nrf54h20_enga_ppr.h | 1855 +++++++++++++++++ modules/hal_nordic/nrfx/nrfx_glue.h | 23 +- 3 files changed, 1877 insertions(+), 3 deletions(-) create mode 100644 modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_ppr.h diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index be2f5599f78..26d662be39d 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -748,6 +748,8 @@ #include #elif defined(NRF54H20_ENGA_XXAA) && defined(NRF_RADIOCORE) #include +#elif defined(NRF54H20_ENGA_XXAA) && defined(NRF_PPR) + #include #elif defined(NRF9120_XXAA) || defined(NRF9160_XXAA) #include #elif defined(NRF54L15_ENGA_XXAA) && defined(NRF_APPLICATION) diff --git a/modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_ppr.h b/modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_ppr.h new file mode 100644 index 00000000000..369fe18a81f --- /dev/null +++ b/modules/hal_nordic/nrfx/nrfx_config_nrf54h20_enga_ppr.h @@ -0,0 +1,1855 @@ +/* + * Copyright (c) 2024, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef NRFX_CONFIG_NRF54H20_ENGA_PPR_H__ +#define NRFX_CONFIG_NRF54H20_ENGA_PPR_H__ + +#ifndef NRFX_CONFIG_H__ +#error "This file should not be included directly. Include nrfx_config.h instead." +#endif + + +/** + * @brief NRFX_DEFAULT_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_DEFAULT_IRQ_PRIORITY +#define NRFX_DEFAULT_IRQ_PRIORITY 3 +#endif + +/** + * @brief NRFX_COMP_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_COMP_ENABLED +#define NRFX_COMP_ENABLED 0 +#endif + +/** + * @brief NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_COMP_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_COMP_CONFIG_LOG_ENABLED +#define NRFX_COMP_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_COMP_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_COMP_CONFIG_LOG_LEVEL +#define NRFX_COMP_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_DPPI_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_DPPI_ENABLED +#define NRFX_DPPI_ENABLED 0 +#endif + +/** + * @brief NRFX_DPPI_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_DPPI_CONFIG_LOG_ENABLED +#define NRFX_DPPI_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_DPPI_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_DPPI_CONFIG_LOG_LEVEL +#define NRFX_DPPI_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_DPPI120_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI120_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI120_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000030 +#endif + +/** + * @brief NRFX_DPPI130_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI130_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI130_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000ff +#endif + +/** + * @brief NRFX_DPPI131_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI131_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI131_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_DPPI132_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI132_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI132_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_DPPI133_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI133_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI133_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000001e +#endif + +/** + * @brief NRFX_DPPI134_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI134_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI134_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000020 +#endif + +/** + * @brief NRFX_DPPI135_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI135_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI135_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000040 +#endif + +/** + * @brief NRFX_DPPI136_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI136_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI136_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000081 +#endif + +/** + * @brief NRFX_DPPI120_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI120_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI120_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000000c +#endif + +/** + * @brief NRFX_DPPI130_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI130_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI130_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000ff +#endif + +/** + * @brief NRFX_DPPI131_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI131_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI131_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000ff +#endif + +/** + * @brief NRFX_DPPI132_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI132_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI132_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_DPPI133_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI133_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI133_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000e1 +#endif + +/** + * @brief NRFX_DPPI134_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI134_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI134_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000df +#endif + +/** + * @brief NRFX_DPPI135_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI135_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI135_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x000000bf +#endif + +/** + * @brief NRFX_DPPI136_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_DPPI136_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_DPPI136_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000007e +#endif + +/** + * @brief NRFX_GPIOTE_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GPIOTE_ENABLED +#define NRFX_GPIOTE_ENABLED 0 +#endif + +/** + * @brief NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS + * + * Integer value. Minimum: 0. Maximum: 15. + */ +#ifndef NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS +#define NRFX_GPIOTE_CONFIG_NUM_OF_EVT_HANDLERS 1 +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GPIOTE_CONFIG_LOG_ENABLED +#define NRFX_GPIOTE_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_GPIOTE_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_GPIOTE_CONFIG_LOG_LEVEL +#define NRFX_GPIOTE_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_GPIOTE130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GPIOTE130_ENABLED +#define NRFX_GPIOTE130_ENABLED 0 +#endif + +/** + * @brief NRFX_GRTC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GRTC_ENABLED +#define NRFX_GRTC_ENABLED 0 +#endif + +/** + * @brief NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS + * + * Integer value. + */ +#ifndef NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS +#define NRFX_GRTC_CONFIG_NUM_OF_CC_CHANNELS 2 +#endif + +/** + * @brief NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK + */ +#ifndef NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK +#define NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK 0x000000c0 +#endif + +/** + * @brief NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_GRTC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_GRTC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_GRTC_CONFIG_LOG_ENABLED +#define NRFX_GRTC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_GRTC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_GRTC_CONFIG_LOG_LEVEL +#define NRFX_GRTC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_I2S_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S_ENABLED +#define NRFX_I2S_ENABLED 0 +#endif + +/** + * @brief NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_I2S_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S_CONFIG_LOG_ENABLED +#define NRFX_I2S_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_I2S_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_I2S_CONFIG_LOG_LEVEL +#define NRFX_I2S_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_I2S130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S130_ENABLED +#define NRFX_I2S130_ENABLED 0 +#endif + +/** + * @brief NRFX_I2S131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_I2S131_ENABLED +#define NRFX_I2S131_ENABLED 0 +#endif + +/** + * @brief NRFX_IPCT_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_IPCT120_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT120_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT120_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_IPCT130_PUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT130_PUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT130_PUB_CONFIG_ALLOWED_CHANNELS_MASK 0x0000000c +#endif + +/** + * @brief NRFX_IPCT_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_IPCT120_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT120_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT120_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0 +#endif + +/** + * @brief NRFX_IPCT130_SUB_CONFIG_ALLOWED_CHANNELS_MASK + */ +#ifndef NRFX_IPCT130_SUB_CONFIG_ALLOWED_CHANNELS_MASK +#define NRFX_IPCT130_SUB_CONFIG_ALLOWED_CHANNELS_MASK 0x00000003 +#endif + +/** + * @brief NRFX_LPCOMP_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_LPCOMP_ENABLED +#define NRFX_LPCOMP_ENABLED 0 +#endif + +/** + * @brief NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_LPCOMP_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_LPCOMP_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_LPCOMP_CONFIG_LOG_ENABLED +#define NRFX_LPCOMP_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_LPCOMP_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_LPCOMP_CONFIG_LOG_LEVEL +#define NRFX_LPCOMP_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_NFCT_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_NFCT_ENABLED +#define NRFX_NFCT_ENABLED 0 +#endif + +/** + * @brief NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_NFCT_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID - Timer instance used for + * workarounds in the driver. + * + * Integer value. Minimum: 0. Maximum: 5. + */ +#ifndef NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID +#define NRFX_NFCT_CONFIG_TIMER_INSTANCE_ID 0 +#endif + +/** + * @brief NRFX_NFCT_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_NFCT_CONFIG_LOG_ENABLED +#define NRFX_NFCT_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_NFCT_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_NFCT_CONFIG_LOG_LEVEL +#define NRFX_NFCT_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PDM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PDM_ENABLED +#define NRFX_PDM_ENABLED 0 +#endif + +/** + * @brief NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_PDM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_PDM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PDM_CONFIG_LOG_ENABLED +#define NRFX_PDM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PDM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PDM_CONFIG_LOG_LEVEL +#define NRFX_PDM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PRS_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_ENABLED +#define NRFX_PRS_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_CONFIG_LOG_ENABLED +#define NRFX_PRS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PRS_CONFIG_LOG_LEVEL +#define NRFX_PRS_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PRS_BOX_0_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_0_ENABLED +#define NRFX_PRS_BOX_0_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_1_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_1_ENABLED +#define NRFX_PRS_BOX_1_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_2_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_2_ENABLED +#define NRFX_PRS_BOX_2_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_3_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_3_ENABLED +#define NRFX_PRS_BOX_3_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_4_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_4_ENABLED +#define NRFX_PRS_BOX_4_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_5_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_5_ENABLED +#define NRFX_PRS_BOX_5_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_6_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_6_ENABLED +#define NRFX_PRS_BOX_6_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_7_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_7_ENABLED +#define NRFX_PRS_BOX_7_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_8_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_8_ENABLED +#define NRFX_PRS_BOX_8_ENABLED 0 +#endif + +/** + * @brief NRFX_PRS_BOX_9_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PRS_BOX_9_ENABLED +#define NRFX_PRS_BOX_9_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM_ENABLED +#define NRFX_PWM_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_PWM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM_CONFIG_LOG_ENABLED +#define NRFX_PWM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_PWM_CONFIG_LOG_LEVEL +#define NRFX_PWM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_PWM120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM120_ENABLED +#define NRFX_PWM120_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM130_ENABLED +#define NRFX_PWM130_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM131_ENABLED +#define NRFX_PWM131_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM132_ENABLED +#define NRFX_PWM132_ENABLED 0 +#endif + +/** + * @brief NRFX_PWM133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_PWM133_ENABLED +#define NRFX_PWM133_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC_ENABLED +#define NRFX_QDEC_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_QDEC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_QDEC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC_CONFIG_LOG_ENABLED +#define NRFX_QDEC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_QDEC_CONFIG_LOG_LEVEL +#define NRFX_QDEC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_QDEC130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC130_ENABLED +#define NRFX_QDEC130_ENABLED 0 +#endif + +/** + * @brief NRFX_QDEC131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_QDEC131_ENABLED +#define NRFX_QDEC131_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC_ENABLED +#define NRFX_RTC_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_RTC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC_CONFIG_LOG_ENABLED +#define NRFX_RTC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_RTC_CONFIG_LOG_LEVEL +#define NRFX_RTC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_RTC130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC130_ENABLED +#define NRFX_RTC130_ENABLED 0 +#endif + +/** + * @brief NRFX_RTC131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_RTC131_ENABLED +#define NRFX_RTC131_ENABLED 0 +#endif + +/** + * @brief NRFX_SAADC_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SAADC_ENABLED +#define NRFX_SAADC_ENABLED 0 +#endif + +/** + * @brief NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SAADC_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_SAADC_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SAADC_CONFIG_LOG_ENABLED +#define NRFX_SAADC_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SAADC_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SAADC_CONFIG_LOG_LEVEL +#define NRFX_SAADC_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_SPIM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM_ENABLED +#define NRFX_SPIM_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_SPIM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM_CONFIG_LOG_ENABLED +#define NRFX_SPIM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SPIM_CONFIG_LOG_LEVEL +#define NRFX_SPIM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_SPIM120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM120_ENABLED +#define NRFX_SPIM120_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM121_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM121_ENABLED +#define NRFX_SPIM121_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM130_ENABLED +#define NRFX_SPIM130_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM131_ENABLED +#define NRFX_SPIM131_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM132_ENABLED +#define NRFX_SPIM132_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM133_ENABLED +#define NRFX_SPIM133_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM134_ENABLED +#define NRFX_SPIM134_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM135_ENABLED +#define NRFX_SPIM135_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM136_ENABLED +#define NRFX_SPIM136_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIM137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIM137_ENABLED +#define NRFX_SPIM137_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS_ENABLED +#define NRFX_SPIS_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_SPIS_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_SPIS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS_CONFIG_LOG_ENABLED +#define NRFX_SPIS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_SPIS_CONFIG_LOG_LEVEL +#define NRFX_SPIS_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_SPIS120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS120_ENABLED +#define NRFX_SPIS120_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS130_ENABLED +#define NRFX_SPIS130_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS131_ENABLED +#define NRFX_SPIS131_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS132_ENABLED +#define NRFX_SPIS132_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS133_ENABLED +#define NRFX_SPIS133_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS134_ENABLED +#define NRFX_SPIS134_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS135_ENABLED +#define NRFX_SPIS135_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS136_ENABLED +#define NRFX_SPIS136_ENABLED 0 +#endif + +/** + * @brief NRFX_SPIS137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_SPIS137_ENABLED +#define NRFX_SPIS137_ENABLED 0 +#endif + +/** + * @brief NRFX_TEMP_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TEMP_ENABLED +#define NRFX_TEMP_ENABLED 0 +#endif + +/** + * @brief NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TEMP_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TEMP_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TEMP_CONFIG_LOG_ENABLED +#define NRFX_TEMP_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TEMP_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TEMP_CONFIG_LOG_LEVEL +#define NRFX_TEMP_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TIMER_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER_ENABLED +#define NRFX_TIMER_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TIMER_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER_CONFIG_LOG_ENABLED +#define NRFX_TIMER_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TIMER_CONFIG_LOG_LEVEL +#define NRFX_TIMER_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TIMER120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER120_ENABLED +#define NRFX_TIMER120_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER121_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER121_ENABLED +#define NRFX_TIMER121_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER130_ENABLED +#define NRFX_TIMER130_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER131_ENABLED +#define NRFX_TIMER131_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER132_ENABLED +#define NRFX_TIMER132_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER133_ENABLED +#define NRFX_TIMER133_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER134_ENABLED +#define NRFX_TIMER134_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER135_ENABLED +#define NRFX_TIMER135_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER136_ENABLED +#define NRFX_TIMER136_ENABLED 0 +#endif + +/** + * @brief NRFX_TIMER137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TIMER137_ENABLED +#define NRFX_TIMER137_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM_ENABLED +#define NRFX_TWIM_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TWIM_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM_CONFIG_LOG_ENABLED +#define NRFX_TWIM_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TWIM_CONFIG_LOG_LEVEL +#define NRFX_TWIM_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TWIM130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM130_ENABLED +#define NRFX_TWIM130_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM131_ENABLED +#define NRFX_TWIM131_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM132_ENABLED +#define NRFX_TWIM132_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM133_ENABLED +#define NRFX_TWIM133_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM134_ENABLED +#define NRFX_TWIM134_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM135_ENABLED +#define NRFX_TWIM135_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM136_ENABLED +#define NRFX_TWIM136_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIM137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIM137_ENABLED +#define NRFX_TWIM137_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_ENABLED +#define NRFX_TWIS_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_TWIS_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_CONFIG_LOG_ENABLED +#define NRFX_TWIS_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY - Assume that any instance + * would be initialized only once. + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY +#define NRFX_TWIS_ASSUME_INIT_AFTER_RESET_ONLY 0 +#endif + +/** + * @brief NRFX_TWIS_NO_SYNC_MODE - Remove support for synchronous mode. + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS_NO_SYNC_MODE +#define NRFX_TWIS_NO_SYNC_MODE 0 +#endif + +/** + * @brief NRFX_TWIS_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_TWIS_CONFIG_LOG_LEVEL +#define NRFX_TWIS_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_TWIS130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS130_ENABLED +#define NRFX_TWIS130_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS131_ENABLED +#define NRFX_TWIS131_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS132_ENABLED +#define NRFX_TWIS132_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS133_ENABLED +#define NRFX_TWIS133_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS134_ENABLED +#define NRFX_TWIS134_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS135_ENABLED +#define NRFX_TWIS135_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS136_ENABLED +#define NRFX_TWIS136_ENABLED 0 +#endif + +/** + * @brief NRFX_TWIS137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_TWIS137_ENABLED +#define NRFX_TWIS137_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_ENABLED +#define NRFX_UARTE_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG - If enabled, support for + * configuring GPIO pins is removed from the driver + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG +#define NRFX_UARTE_CONFIG_SKIP_GPIO_CONFIG 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG - If enabled, support for + * configuring PSEL registers is removed from the driver + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG +#define NRFX_UARTE_CONFIG_SKIP_PSEL_CONFIG 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_TX_LINK - If enabled, driver supports linking of TX + * transfers. + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_TX_LINK +#define NRFX_UARTE_CONFIG_TX_LINK 1 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_RX_CACHE_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_RX_CACHE_ENABLED +#define NRFX_UARTE_CONFIG_RX_CACHE_ENABLED 1 +#endif + +/** + * @brief NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_UARTE_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE_CONFIG_LOG_ENABLED +#define NRFX_UARTE_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_UARTE_CONFIG_LOG_LEVEL +#define NRFX_UARTE_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_UARTE120_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE120_ENABLED +#define NRFX_UARTE120_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE130_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE130_ENABLED +#define NRFX_UARTE130_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE131_ENABLED +#define NRFX_UARTE131_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE132_ENABLED +#define NRFX_UARTE132_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE133_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE133_ENABLED +#define NRFX_UARTE133_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE134_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE134_ENABLED +#define NRFX_UARTE134_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE135_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE135_ENABLED +#define NRFX_UARTE135_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE136_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE136_ENABLED +#define NRFX_UARTE136_ENABLED 0 +#endif + +/** + * @brief NRFX_UARTE137_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_UARTE137_ENABLED +#define NRFX_UARTE137_ENABLED 0 +#endif + +/** + * @brief NRFX_VEVIF_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_VEVIF_ENABLED +#define NRFX_VEVIF_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT_ENABLED +#define NRFX_WDT_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY + * + * Integer value. Minimum: 0. Maximum: 3. + */ +#ifndef NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY NRFX_DEFAULT_IRQ_PRIORITY +#endif + +/** + * @brief NRFX_WDT_CONFIG_NO_IRQ - Remove WDT IRQ handling from WDT driver + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT_CONFIG_NO_IRQ +#define NRFX_WDT_CONFIG_NO_IRQ 0 +#endif + +/** + * @brief NRFX_WDT_CONFIG_LOG_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT_CONFIG_LOG_ENABLED +#define NRFX_WDT_CONFIG_LOG_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT_CONFIG_LOG_LEVEL + * + * Integer value. + * Supported values: + * - Off = 0 + * - Error = 1 + * - Warning = 2 + * - Info = 3 + * - Debug = 4 + */ +#ifndef NRFX_WDT_CONFIG_LOG_LEVEL +#define NRFX_WDT_CONFIG_LOG_LEVEL 3 +#endif + +/** + * @brief NRFX_WDT131_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT131_ENABLED +#define NRFX_WDT131_ENABLED 0 +#endif + +/** + * @brief NRFX_WDT132_ENABLED + * + * Boolean. Accepted values: 0 and 1. + */ +#ifndef NRFX_WDT132_ENABLED +#define NRFX_WDT132_ENABLED 0 +#endif + +#endif /* NRFX_CONFIG_NRF54H20_ENGA_PPR_H__ */ diff --git a/modules/hal_nordic/nrfx/nrfx_glue.h b/modules/hal_nordic/nrfx/nrfx_glue.h index 851cb8a9614..0edda440112 100644 --- a/modules/hal_nordic/nrfx/nrfx_glue.h +++ b/modules/hal_nordic/nrfx/nrfx_glue.h @@ -42,6 +42,11 @@ extern "C" { #define NRFX_ASSERT(expression) __ASSERT_NO_MSG(expression) #endif +#if defined(CONFIG_RISCV) +/* included here due to dependency on NRFX_ASSERT definition */ +#include +#endif + /** * @brief Macro for placing a compile time assertion. * @@ -91,14 +96,22 @@ extern "C" { * * @param irq_number IRQ number. */ -#define NRFX_IRQ_PENDING_SET(irq_number) NVIC_SetPendingIRQ(irq_number) +#if defined(CONFIG_RISCV) +#define NRFX_IRQ_PENDING_SET(irq_number) nrf_vpr_clic_int_pending_set(NRF_VPRCLIC, irq_number) +#else +#define NRFX_IRQ_PENDING_SET(irq_number) NVIC_SetPendingIRQ(irq_number) +#endif /** * @brief Macro for clearing the pending status of a specific IRQ. * * @param irq_number IRQ number. */ -#define NRFX_IRQ_PENDING_CLEAR(irq_number) NVIC_ClearPendingIRQ(irq_number) +#if defined(CONFIG_RISCV) +#define NRFX_IRQ_PENDING_CLEAR(irq_number) nrf_vpr_clic_int_pending_clear(NRF_VPRCLIC, irq_number) +#else +#define NRFX_IRQ_PENDING_CLEAR(irq_number) NVIC_ClearPendingIRQ(irq_number) +#endif /** * @brief Macro for checking the pending status of a specific IRQ. @@ -106,7 +119,11 @@ extern "C" { * @retval true If the IRQ is pending. * @retval false Otherwise. */ -#define NRFX_IRQ_IS_PENDING(irq_number) (NVIC_GetPendingIRQ(irq_number) == 1) +#if defined(CONFIG_RISCV) +#define NRFX_IRQ_IS_PENDING(irq_number) nrf_vpr_clic_int_pending_check(NRF_VPRCLIC, irq_number) +#else +#define NRFX_IRQ_IS_PENDING(irq_number) (NVIC_GetPendingIRQ(irq_number) == 1) +#endif /** @brief Macro for entering into a critical section. */ #define NRFX_CRITICAL_SECTION_ENTER() { unsigned int irq_lock_key = irq_lock(); From 784a08fadedbbaf3600ba87dac79e1ef205638f0 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 1 Feb 2024 10:25:18 +0100 Subject: [PATCH 1264/1623] [nrf fromtree] scripts: kconfig: functions: add dt_chosen_partition_addr_int|hex dt_chosen_partition_addr_int|hex allow obtaining the absolute address of a partition, which is the result of the grandparent node address plus the partition node address. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 018cf08d8dbcfb3d2da2d2f26e067e3a8e92ba0e) --- scripts/kconfig/kconfigfunctions.py | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/scripts/kconfig/kconfigfunctions.py b/scripts/kconfig/kconfigfunctions.py index 621ec3cb3a8..754a312ebb7 100644 --- a/scripts/kconfig/kconfigfunctions.py +++ b/scripts/kconfig/kconfigfunctions.py @@ -309,6 +309,48 @@ def dt_chosen_reg(kconf, name, chosen, index=0, unit=None): return hex(_dt_chosen_reg_addr(kconf, chosen, index, unit)) +def _dt_chosen_partition_addr(kconf, chosen, index=0, unit=None): + """ + This function takes a 'chosen' property and treats that property as a path + to an EDT node. If it finds an EDT node, it will look to see if that + node has a register, and if that node has a grandparent that has a register + at the given 'index'. The addition of both addresses will be returned, if + not, we return 0. + + The function will divide the value based on 'unit': + None No division + 'k' or 'K' divide by 1024 (1 << 10) + 'm' or 'M' divide by 1,048,576 (1 << 20) + 'g' or 'G' divide by 1,073,741,824 (1 << 30) + 'kb' or 'Kb' divide by 8192 (1 << 13) + 'mb' or 'Mb' divide by 8,388,608 (1 << 23) + 'gb' or 'Gb' divide by 8,589,934,592 (1 << 33) + """ + if doc_mode or edt is None: + return 0 + + node = edt.chosen_node(chosen) + if not node: + return 0 + + p_node = node.parent + if not p_node: + return 0 + + return _node_reg_addr(p_node.parent, index, unit) + _node_reg_addr(node, 0, unit) + + +def dt_chosen_partition_addr(kconf, name, chosen, index=0, unit=None): + """ + This function just routes to the proper function and converts + the result to either a string int or string hex value. + """ + if name == "dt_chosen_partition_addr_int": + return str(_dt_chosen_partition_addr(kconf, chosen, index, unit)) + if name == "dt_chosen_partition_addr_hex": + return hex(_dt_chosen_partition_addr(kconf, chosen, index, unit)) + + def _dt_node_reg_addr(kconf, path, index=0, unit=None): """ This function takes a 'path' and looks for an EDT node at that path. If it @@ -806,5 +848,7 @@ def shields_list_contains(kconf, _, shield): "dt_node_parent": (dt_node_parent, 1, 1), "dt_nodelabel_array_prop_has_val": (dt_nodelabel_array_prop_has_val, 3, 3), "dt_gpio_hogs_enabled": (dt_gpio_hogs_enabled, 0, 0), + "dt_chosen_partition_addr_int": (dt_chosen_partition_addr, 1, 3), + "dt_chosen_partition_addr_hex": (dt_chosen_partition_addr, 1, 3), "shields_list_contains": (shields_list_contains, 1, 1), } From 4b9cb331f97c42d3f08043f4d6b70456e18b0e77 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 1 Feb 2024 10:40:53 +0100 Subject: [PATCH 1265/1623] [nrf fromtree] soc: common: nordic_nrf: move pinctrl_soc.h to a common dir Because both, RISC-V and ARM cores share the same pinctrl driver. The top level common folder will disappear with the introduction of HWMv2, where multi-arch SoCs will be well supported. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit d7dc942382a2c05539c14f8df32d5756fd88a9a2) --- boards/posix/nrf_bsim/soc/pinctrl_soc.h | 2 +- soc/CMakeLists.txt | 2 ++ soc/common/CMakeLists.txt | 4 ++++ soc/common/nordic_nrf/CMakeLists.txt | 4 ++++ .../nordic_nrf/common => common/nordic_nrf}/pinctrl_soc.h | 0 5 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 soc/common/CMakeLists.txt create mode 100644 soc/common/nordic_nrf/CMakeLists.txt rename soc/{arm/nordic_nrf/common => common/nordic_nrf}/pinctrl_soc.h (100%) diff --git a/boards/posix/nrf_bsim/soc/pinctrl_soc.h b/boards/posix/nrf_bsim/soc/pinctrl_soc.h index 08252b57fee..f0be0443d5b 100644 --- a/boards/posix/nrf_bsim/soc/pinctrl_soc.h +++ b/boards/posix/nrf_bsim/soc/pinctrl_soc.h @@ -8,6 +8,6 @@ #define BOARDS_POSIX_NRF_BSIM_SOC_PINCTRL_SOC_H /* We reuse the real SOC's header: */ -#include "../soc/arm/nordic_nrf/common/pinctrl_soc.h" +#include "../soc/common/nordic_nrf/pinctrl_soc.h" #endif /* BOARDS_POSIX_NRF_BSIM_SOC_PINCTRL_SOC_H */ diff --git a/soc/CMakeLists.txt b/soc/CMakeLists.txt index 6706168281e..d55bd63f496 100644 --- a/soc/CMakeLists.txt +++ b/soc/CMakeLists.txt @@ -9,6 +9,8 @@ if(_SOC_IS_IN_TREE) endif() unset(_SOC_IS_IN_TREE) +add_subdirectory(common) + if(EXISTS ${SOC_DIR}/${ARCH}/CMakeLists.txt) add_subdirectory(${SOC_DIR}/${ARCH} soc/${ARCH}) else() diff --git a/soc/common/CMakeLists.txt b/soc/common/CMakeLists.txt new file mode 100644 index 00000000000..d9abad218cd --- /dev/null +++ b/soc/common/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory_ifdef(CONFIG_SOC_FAMILY_NRF nordic_nrf) diff --git a/soc/common/nordic_nrf/CMakeLists.txt b/soc/common/nordic_nrf/CMakeLists.txt new file mode 100644 index 00000000000..6f397a07fab --- /dev/null +++ b/soc/common/nordic_nrf/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +zephyr_include_directories(.) diff --git a/soc/arm/nordic_nrf/common/pinctrl_soc.h b/soc/common/nordic_nrf/pinctrl_soc.h similarity index 100% rename from soc/arm/nordic_nrf/common/pinctrl_soc.h rename to soc/common/nordic_nrf/pinctrl_soc.h From dcba645f74cfd3e8e5df00f964151df9a7133089 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 1 Feb 2024 10:44:47 +0100 Subject: [PATCH 1266/1623] [nrf fromtree] soc: arm: nordic_nrf: move Kconfig.peripherals to common folder Because RISC-V cores also need to include this file, so it is no longer ARM specific. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 1a6b88608e10b6f2dde0c99077d32a63f9337a0b) --- boards/posix/nrf_bsim/Kconfig | 2 +- soc/arm/nordic_nrf/Kconfig | 2 +- soc/{arm => common}/nordic_nrf/Kconfig.peripherals | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename soc/{arm => common}/nordic_nrf/Kconfig.peripherals (100%) diff --git a/boards/posix/nrf_bsim/Kconfig b/boards/posix/nrf_bsim/Kconfig index 7d67c44d284..d85b497f671 100644 --- a/boards/posix/nrf_bsim/Kconfig +++ b/boards/posix/nrf_bsim/Kconfig @@ -6,7 +6,7 @@ if SOC_SERIES_BSIM_NRFXX # used by Nordic SoCs, so to make the symbols defined in this file available for # the simulated nrf5x_bsim boards, which use the POSIX architecture, the file # must be read also from here. -source "soc/arm/nordic_nrf/Kconfig.peripherals" +source "soc/common/nordic_nrf/Kconfig.peripherals" endif # SOC_SERIES_BSIM_NRFXX diff --git a/soc/arm/nordic_nrf/Kconfig b/soc/arm/nordic_nrf/Kconfig index 69d83ae5e9b..ba0c9d4b164 100644 --- a/soc/arm/nordic_nrf/Kconfig +++ b/soc/arm/nordic_nrf/Kconfig @@ -13,7 +13,7 @@ config SOC_FAMILY string default "nordic_nrf" -source "soc/arm/nordic_nrf/Kconfig.peripherals" +source "soc/common/nordic_nrf/Kconfig.peripherals" source "soc/arm/nordic_nrf/*/Kconfig.soc" config NRF_SOC_SECURE_SUPPORTED diff --git a/soc/arm/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals similarity index 100% rename from soc/arm/nordic_nrf/Kconfig.peripherals rename to soc/common/nordic_nrf/Kconfig.peripherals From 6b31b5aa424d763051d7a47b69702f10a437542d Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 31 Jan 2024 19:46:00 +0100 Subject: [PATCH 1267/1623] [nrf fromtree] soc: riscv: nordic_nrf: add initial support for VPR core Add initial support for the VPR RISC-V core found in the new nRF54 SoCs. Signed-off-by: Carlo Caione Signed-off-by: Gerard Marull-Paretas (cherry picked from commit ba16e3dd13e5d16d038c816defebad62ef8249a1) --- soc/riscv/nordic_nrf/CMakeLists.txt | 4 + soc/riscv/nordic_nrf/Kconfig | 15 +++ soc/riscv/nordic_nrf/Kconfig.defconfig | 8 ++ soc/riscv/nordic_nrf/common/CMakeLists.txt | 4 + soc/riscv/nordic_nrf/common/Kconfig | 4 + soc/riscv/nordic_nrf/common/Kconfig.defconfig | 8 ++ .../nordic_nrf/common/vpr/CMakeLists.txt | 9 ++ soc/riscv/nordic_nrf/common/vpr/Kconfig | 18 +++ .../nordic_nrf/common/vpr/Kconfig.defconfig | 27 ++++ soc/riscv/nordic_nrf/common/vpr/soc_context.h | 12 ++ soc/riscv/nordic_nrf/common/vpr/soc_irq.S | 30 +++++ soc/riscv/nordic_nrf/common/vpr/soc_irq.c | 26 ++++ .../nordic_nrf/common/vpr/soc_isr_stacking.h | 118 ++++++++++++++++++ soc/riscv/nordic_nrf/common/vpr/soc_offsets.h | 11 ++ soc/riscv/nordic_nrf/common/vpr/vector.S | 28 +++++ 15 files changed, 322 insertions(+) create mode 100644 soc/riscv/nordic_nrf/CMakeLists.txt create mode 100644 soc/riscv/nordic_nrf/Kconfig create mode 100644 soc/riscv/nordic_nrf/Kconfig.defconfig create mode 100644 soc/riscv/nordic_nrf/common/CMakeLists.txt create mode 100644 soc/riscv/nordic_nrf/common/Kconfig create mode 100644 soc/riscv/nordic_nrf/common/Kconfig.defconfig create mode 100644 soc/riscv/nordic_nrf/common/vpr/CMakeLists.txt create mode 100644 soc/riscv/nordic_nrf/common/vpr/Kconfig create mode 100644 soc/riscv/nordic_nrf/common/vpr/Kconfig.defconfig create mode 100644 soc/riscv/nordic_nrf/common/vpr/soc_context.h create mode 100644 soc/riscv/nordic_nrf/common/vpr/soc_irq.S create mode 100644 soc/riscv/nordic_nrf/common/vpr/soc_irq.c create mode 100644 soc/riscv/nordic_nrf/common/vpr/soc_isr_stacking.h create mode 100644 soc/riscv/nordic_nrf/common/vpr/soc_offsets.h create mode 100644 soc/riscv/nordic_nrf/common/vpr/vector.S diff --git a/soc/riscv/nordic_nrf/CMakeLists.txt b/soc/riscv/nordic_nrf/CMakeLists.txt new file mode 100644 index 00000000000..91bd222e147 --- /dev/null +++ b/soc/riscv/nordic_nrf/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(common) diff --git a/soc/riscv/nordic_nrf/Kconfig b/soc/riscv/nordic_nrf/Kconfig new file mode 100644 index 00000000000..3f17bea1756 --- /dev/null +++ b/soc/riscv/nordic_nrf/Kconfig @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FAMILY_NRF + bool + +if SOC_FAMILY_NRF + +config SOC_FAMILY + string + default "nordic_nrf" + +source "soc/riscv/nordic_nrf/common/Kconfig" + +endif # SOC_FAMILY_NRF diff --git a/soc/riscv/nordic_nrf/Kconfig.defconfig b/soc/riscv/nordic_nrf/Kconfig.defconfig new file mode 100644 index 00000000000..a6d85ac846a --- /dev/null +++ b/soc/riscv/nordic_nrf/Kconfig.defconfig @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_FAMILY_NRF + +source "soc/riscv/nordic_nrf/common/Kconfig.defconfig" + +endif # SOC_FAMILY_NRF diff --git a/soc/riscv/nordic_nrf/common/CMakeLists.txt b/soc/riscv/nordic_nrf/common/CMakeLists.txt new file mode 100644 index 00000000000..806a295ea22 --- /dev/null +++ b/soc/riscv/nordic_nrf/common/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory_ifdef(CONFIG_RISCV_CORE_NORDIC_VPR vpr) diff --git a/soc/riscv/nordic_nrf/common/Kconfig b/soc/riscv/nordic_nrf/common/Kconfig new file mode 100644 index 00000000000..610689ecc6d --- /dev/null +++ b/soc/riscv/nordic_nrf/common/Kconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/nordic_nrf/common/vpr/Kconfig" diff --git a/soc/riscv/nordic_nrf/common/Kconfig.defconfig b/soc/riscv/nordic_nrf/common/Kconfig.defconfig new file mode 100644 index 00000000000..9beb943edb8 --- /dev/null +++ b/soc/riscv/nordic_nrf/common/Kconfig.defconfig @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if RISCV_CORE_NORDIC_VPR + +source "soc/riscv/nordic_nrf/common/vpr/Kconfig.defconfig" + +endif # RISCV_CORE_NORDIC_VPR diff --git a/soc/riscv/nordic_nrf/common/vpr/CMakeLists.txt b/soc/riscv/nordic_nrf/common/vpr/CMakeLists.txt new file mode 100644 index 00000000000..e0331bb8e0b --- /dev/null +++ b/soc/riscv/nordic_nrf/common/vpr/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +zephyr_include_directories(.) + +zephyr_library() +zephyr_library_sources(soc_irq.S soc_irq.c vector.S) + +set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "") diff --git a/soc/riscv/nordic_nrf/common/vpr/Kconfig b/soc/riscv/nordic_nrf/common/vpr/Kconfig new file mode 100644 index 00000000000..40a7d199c0c --- /dev/null +++ b/soc/riscv/nordic_nrf/common/vpr/Kconfig @@ -0,0 +1,18 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config RISCV_CORE_NORDIC_VPR + bool "RISC-V Nordic VPR core" + default y + depends on DT_HAS_NORDIC_VPR_ENABLED + depends on RISCV + select ATOMIC_OPERATIONS_C + select RISCV_ISA_RV32E + select RISCV_ISA_EXT_M + select RISCV_ISA_EXT_C + select RISCV_ISA_EXT_ZICSR + select RISCV_ISA_EXT_ZIFENCEI + select RISCV_SOC_HAS_ISR_STACKING + select RISCV_SOC_CONTEXT_SAVE + help + Enable support for the RISC-V Nordic VPR core. diff --git a/soc/riscv/nordic_nrf/common/vpr/Kconfig.defconfig b/soc/riscv/nordic_nrf/common/vpr/Kconfig.defconfig new file mode 100644 index 00000000000..f0014455b3a --- /dev/null +++ b/soc/riscv/nordic_nrf/common/vpr/Kconfig.defconfig @@ -0,0 +1,27 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CPU_PATH := $(dt_nodelabel_path,cpu) +CPU_ID := $(dt_node_reg_addr_int,$(CPU_PATH)) + +config RV_BOOT_HART + default $(CPU_ID) + +config RISCV_MCAUSE_EXCEPTION_MASK + default 0xFFF + +config RISCV_RESERVED_IRQ_ISR_TABLES_OFFSET + default 16 + +config GEN_IRQ_VECTOR_TABLE + default y + +choice IRQ_VECTOR_TABLE_TYPE + default IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS +endchoice + +config ARCH_SW_ISR_TABLE_ALIGN + default 64 + +config RISCV_ALWAYS_SWITCH_THROUGH_ECALL + default y if MULTITHREADING diff --git a/soc/riscv/nordic_nrf/common/vpr/soc_context.h b/soc/riscv/nordic_nrf/common/vpr/soc_context.h new file mode 100644 index 00000000000..8cd0d1e5094 --- /dev/null +++ b/soc/riscv/nordic_nrf/common/vpr/soc_context.h @@ -0,0 +1,12 @@ +/* + * Copyright (C) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_CONTEXT_H_ +#define SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_CONTEXT_H_ + +#define SOC_ESF_MEMBERS unsigned long minttresh +#define SOC_ESF_INIT 0 + +#endif /* SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_CONTEXT_H_ */ diff --git a/soc/riscv/nordic_nrf/common/vpr/soc_irq.S b/soc/riscv/nordic_nrf/common/vpr/soc_irq.S new file mode 100644 index 00000000000..0e9db48d9b4 --- /dev/null +++ b/soc/riscv/nordic_nrf/common/vpr/soc_irq.S @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* Exports */ +GTEXT(__soc_handle_irq) +GTEXT(__soc_save_context) +GTEXT(__soc_restore_context) + +/* + * No need to clear anything, pending bit is cleared by HW. + */ +SECTION_FUNC(exception.other, __soc_handle_irq) + ret + +SECTION_FUNC(exception.other, __soc_save_context) + csrr t0, 0x347 + sw t0, __soc_esf_t_minttresh_OFFSET(a0) + + ret + +SECTION_FUNC(exception.other, __soc_restore_context) + lw t0, __soc_esf_t_minttresh_OFFSET(a0) + csrw 0x347, t0 + + ret diff --git a/soc/riscv/nordic_nrf/common/vpr/soc_irq.c b/soc/riscv/nordic_nrf/common/vpr/soc_irq.c new file mode 100644 index 00000000000..88655f6efa0 --- /dev/null +++ b/soc/riscv/nordic_nrf/common/vpr/soc_irq.c @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +void arch_irq_enable(unsigned int irq) +{ + nrf_vpr_clic_int_enable_set(NRF_VPRCLIC, irq, true); +} + +void arch_irq_disable(unsigned int irq) +{ + nrf_vpr_clic_int_enable_set(NRF_VPRCLIC, irq, false); +} + +void arch_irq_priority_set(unsigned int irq, unsigned int prio) +{ + nrf_vpr_clic_int_priority_set(NRF_VPRCLIC, irq, prio); +} + +int arch_irq_is_enabled(unsigned int irq) +{ + return nrf_vpr_clic_int_enable_check(NRF_VPRCLIC, irq); +} diff --git a/soc/riscv/nordic_nrf/common/vpr/soc_isr_stacking.h b/soc/riscv/nordic_nrf/common/vpr/soc_isr_stacking.h new file mode 100644 index 00000000000..d5b139111d0 --- /dev/null +++ b/soc/riscv/nordic_nrf/common/vpr/soc_isr_stacking.h @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_ISR_STACKING_H_ +#define SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_ISR_STACKING_H_ + +#include + +#if !defined(_ASMLANGUAGE) + +#include + +#define VPR_CPU DT_INST(0, nordic_vpr) + +#if DT_PROP(VPR_CPU, nordic_bus_width) == 64 + +#define SOC_ISR_STACKING_ESF_DECLARE \ + struct __esf { \ + unsigned long s0; \ + unsigned long mstatus; \ + unsigned long tp; \ + struct soc_esf soc_context; \ + \ + unsigned long t2; \ + unsigned long ra; \ + unsigned long t0; \ + unsigned long t1; \ + unsigned long a4; \ + unsigned long a5; \ + unsigned long a2; \ + unsigned long a3; \ + unsigned long a0; \ + unsigned long a1; \ + unsigned long mepc; \ + unsigned long _mcause; \ + } __aligned(16); + +#else /* DT_PROP(VPR_CPU, nordic_bus_width) == 32 */ + +#define SOC_ISR_STACKING_ESF_DECLARE \ + struct __esf { \ + unsigned long s0; \ + unsigned long mstatus; \ + unsigned long tp; \ + struct soc_esf soc_context; \ + \ + unsigned long ra; \ + unsigned long t2; \ + unsigned long t1; \ + unsigned long t0; \ + unsigned long a5; \ + unsigned long a4; \ + unsigned long a3; \ + unsigned long a2; \ + unsigned long a1; \ + unsigned long a0; \ + unsigned long mepc; \ + unsigned long _mcause; \ + } __aligned(16); + +#endif /* DT_PROP(VPR_CPU, nordic_bus_width) == 64 */ + +#else /* _ASMLANGUAGE */ + +/* + * Size of the HW managed part of the ESF: + * sizeof(_mcause) + sizeof(_mepc) + */ +#define ESF_HW_SIZEOF (0x8) + +/* + * Size of the SW managed part of the ESF in case of exception + */ +#define ESF_SW_EXC_SIZEOF (__z_arch_esf_t_SIZEOF - ESF_HW_SIZEOF) + +/* + * Size of the SW managed part of the ESF in case of interrupt + * sizeof(__padding) + ... + sizeof(soc_context) + */ +#define ESF_SW_IRQ_SIZEOF (0x10) + +#define SOC_ISR_SW_STACKING \ + csrw mscratch, t0; \ + \ + csrr t0, mcause; \ + srli t0, t0, RISCV_MCAUSE_IRQ_POS; \ + bnez t0, stacking_is_interrupt; \ + \ + csrrw t0, mscratch, zero; \ + \ + addi sp, sp, -ESF_SW_EXC_SIZEOF; \ + DO_CALLER_SAVED(sr); \ + j stacking_keep_going; \ + \ +stacking_is_interrupt: \ + addi sp, sp, -ESF_SW_IRQ_SIZEOF; \ + \ +stacking_keep_going: + +#define SOC_ISR_SW_UNSTACKING \ + csrr t0, mcause; \ + srli t0, t0, RISCV_MCAUSE_IRQ_POS; \ + bnez t0, unstacking_is_interrupt; \ + \ + DO_CALLER_SAVED(lr); \ + addi sp, sp, ESF_SW_EXC_SIZEOF; \ + j unstacking_keep_going; \ + \ +unstacking_is_interrupt: \ + addi sp, sp, ESF_SW_IRQ_SIZEOF; \ + \ +unstacking_keep_going: + +#endif /* _ASMLANGUAGE */ + +#endif /* SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_ISR_STACKING_H_ */ diff --git a/soc/riscv/nordic_nrf/common/vpr/soc_offsets.h b/soc/riscv/nordic_nrf/common/vpr/soc_offsets.h new file mode 100644 index 00000000000..92d91044e1a --- /dev/null +++ b/soc/riscv/nordic_nrf/common/vpr/soc_offsets.h @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_OFFSETS_H_ +#define SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_OFFSETS_H_ + +#define GEN_SOC_OFFSET_SYMS() GEN_OFFSET_SYM(soc_esf_t, minttresh) + +#endif /* SOC_RISCV_NORDIC_NRF_COMMON_VPR_SOC_OFFSETS_H_ */ diff --git a/soc/riscv/nordic_nrf/common/vpr/vector.S b/soc/riscv/nordic_nrf/common/vpr/vector.S new file mode 100644 index 00000000000..b8c6d97170c --- /dev/null +++ b/soc/riscv/nordic_nrf/common/vpr/vector.S @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/* Imports */ +GTEXT(__initialize) + +/* Exports */ +GTEXT(__start) + +SECTION_FUNC(vectors, __start) + /* Set mtvec.base (mtvec.mode is RO, no need to mask it). */ + la t0, _isr_wrapper + csrw mtvec, t0 + + /* Set mtvt. */ + la t0, _irq_vector_table + csrw 0x307, t0 + + /* Enable mstatus.mie */ + li t0, 0x1888 + csrw mstatus, t0 + + /* Call into Zephyr initialization. */ + tail __initialize From b60fd105ee36ab8b91e860d61eaae1a29ca81386 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 1 Feb 2024 10:36:27 +0100 Subject: [PATCH 1268/1623] [nrf fromtree] soc: riscv: nordic_nrf: nrf54h: introduce PPR support Add support for the nRF54H PPR (Peripheral Processor), based on the VPR RISC-V core. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 426bbf5649a93aba5d42bf1087178b992e5e3409) --- modules/hal_nordic/nrfx/CMakeLists.txt | 3 +++ soc/riscv/nordic_nrf/CMakeLists.txt | 1 + soc/riscv/nordic_nrf/Kconfig | 3 +++ soc/riscv/nordic_nrf/Kconfig.defconfig | 8 ++++++++ soc/riscv/nordic_nrf/Kconfig.soc | 4 ++++ soc/riscv/nordic_nrf/nrf54h/CMakeLists.txt | 6 ++++++ .../Kconfig.defconfig.nrf54h20_enga_cpuppr | 15 +++++++++++++++ .../nrf54h/Kconfig.defconfig.series | 19 +++++++++++++++++++ soc/riscv/nordic_nrf/nrf54h/Kconfig.series | 10 ++++++++++ soc/riscv/nordic_nrf/nrf54h/Kconfig.soc | 19 +++++++++++++++++++ soc/riscv/nordic_nrf/nrf54h/align.ld | 10 ++++++++++ 11 files changed, 98 insertions(+) create mode 100644 soc/riscv/nordic_nrf/Kconfig.soc create mode 100644 soc/riscv/nordic_nrf/nrf54h/CMakeLists.txt create mode 100644 soc/riscv/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_enga_cpuppr create mode 100644 soc/riscv/nordic_nrf/nrf54h/Kconfig.defconfig.series create mode 100644 soc/riscv/nordic_nrf/nrf54h/Kconfig.series create mode 100644 soc/riscv/nordic_nrf/nrf54h/Kconfig.soc create mode 100644 soc/riscv/nordic_nrf/nrf54h/align.ld diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index cd8392e118f..ffd2e9aebc1 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -40,6 +40,8 @@ zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54H20_ENGA_CPUAPP NRF54H20_ENGA_X NRF_APPLICATION) zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54H20_ENGA_CPURAD NRF54H20_ENGA_XXAA NRF_RADIOCORE) +zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54H20_ENGA_CPUPPR NRF54H20_ENGA_XXAA + NRF_PPR) zephyr_compile_definitions_ifdef(CONFIG_NRF_APPROTECT_LOCK ENABLE_APPROTECT) @@ -173,6 +175,7 @@ mdk_svd_ifdef(CONFIG_SOC_NRF52840 nrf52840.svd) mdk_svd_ifdef(CONFIG_SOC_NRF5340_CPUAPP nrf5340_application.svd) mdk_svd_ifdef(CONFIG_SOC_NRF5340_CPUNET nrf5340_network.svd) mdk_svd_ifdef(CONFIG_SOC_NRF54H20_ENGA_CPUAPP nrf54h20_enga_application.svd) +mdk_svd_ifdef(CONFIG_SOC_NRF54H20_ENGA_CPUPPR nrf54h20_enga_ppr.svd) mdk_svd_ifdef(CONFIG_SOC_NRF54H20_ENGA_CPURAD nrf54h20_enga_radiocore.svd) mdk_svd_ifdef(CONFIG_SOC_NRF9120 nrf9120.svd) mdk_svd_ifdef(CONFIG_SOC_NRF9160 nrf9160.svd) diff --git a/soc/riscv/nordic_nrf/CMakeLists.txt b/soc/riscv/nordic_nrf/CMakeLists.txt index 91bd222e147..6a5b10545ff 100644 --- a/soc/riscv/nordic_nrf/CMakeLists.txt +++ b/soc/riscv/nordic_nrf/CMakeLists.txt @@ -2,3 +2,4 @@ # SPDX-License-Identifier: Apache-2.0 add_subdirectory(common) +add_subdirectory(${SOC_SERIES}) diff --git a/soc/riscv/nordic_nrf/Kconfig b/soc/riscv/nordic_nrf/Kconfig index 3f17bea1756..a39db4671d5 100644 --- a/soc/riscv/nordic_nrf/Kconfig +++ b/soc/riscv/nordic_nrf/Kconfig @@ -12,4 +12,7 @@ config SOC_FAMILY source "soc/riscv/nordic_nrf/common/Kconfig" +source "soc/common/nordic_nrf/Kconfig.peripherals" +source "soc/riscv/nordic_nrf/*/Kconfig.soc" + endif # SOC_FAMILY_NRF diff --git a/soc/riscv/nordic_nrf/Kconfig.defconfig b/soc/riscv/nordic_nrf/Kconfig.defconfig index a6d85ac846a..cc3ec954985 100644 --- a/soc/riscv/nordic_nrf/Kconfig.defconfig +++ b/soc/riscv/nordic_nrf/Kconfig.defconfig @@ -3,6 +3,14 @@ if SOC_FAMILY_NRF +source "soc/riscv/nordic_nrf/*/Kconfig.defconfig.series" source "soc/riscv/nordic_nrf/common/Kconfig.defconfig" +config BUILD_OUTPUT_HEX + default y + +config SYS_CLOCK_HW_CYCLES_PER_SEC + default 1000000 if NRF_GRTC_TIMER + default 32768 if NRF_RTC_TIMER + endif # SOC_FAMILY_NRF diff --git a/soc/riscv/nordic_nrf/Kconfig.soc b/soc/riscv/nordic_nrf/Kconfig.soc new file mode 100644 index 00000000000..593d6f91769 --- /dev/null +++ b/soc/riscv/nordic_nrf/Kconfig.soc @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "soc/riscv/nordic_nrf/*/Kconfig.series" diff --git a/soc/riscv/nordic_nrf/nrf54h/CMakeLists.txt b/soc/riscv/nordic_nrf/nrf54h/CMakeLists.txt new file mode 100644 index 00000000000..5b37b3a54d8 --- /dev/null +++ b/soc/riscv/nordic_nrf/nrf54h/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (c) 2024 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +# Ensure that image size aligns with 16 bytes so that MRAMC finalizes all writes +# for the image correctly +zephyr_linker_sources(SECTIONS SORT_KEY zzz_place_align_at_end align.ld) diff --git a/soc/riscv/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_enga_cpuppr b/soc/riscv/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_enga_cpuppr new file mode 100644 index 00000000000..a36d24c72ae --- /dev/null +++ b/soc/riscv/nordic_nrf/nrf54h/Kconfig.defconfig.nrf54h20_enga_cpuppr @@ -0,0 +1,15 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_NRF54H20_ENGA_CPUPPR + +config SOC + default "nrf54h20_enga_cpuppr" + +config NUM_IRQS + default 496 + +config SYS_CLOCK_TICKS_PER_SEC + default 1000 + +endif # SOC_NRF54H20_ENGA_CPUPPR diff --git a/soc/riscv/nordic_nrf/nrf54h/Kconfig.defconfig.series b/soc/riscv/nordic_nrf/nrf54h/Kconfig.defconfig.series new file mode 100644 index 00000000000..0f827fbe96b --- /dev/null +++ b/soc/riscv/nordic_nrf/nrf54h/Kconfig.defconfig.series @@ -0,0 +1,19 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_NRF54HX + +rsource "Kconfig.defconfig.nrf54h*" + +config SOC_SERIES + default "nrf54h" + +DT_CHOSEN_Z_SRAM = zephyr,sram +DT_CHOSEN_Z_CODE = zephyr,code-partition + +config BUILD_OUTPUT_ADJUST_LMA + depends on !XIP + default "$(dt_chosen_partition_addr_hex,$(DT_CHOSEN_Z_CODE)) - \ + $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_SRAM))" + +endif # SOC_SERIES_NRF54HX diff --git a/soc/riscv/nordic_nrf/nrf54h/Kconfig.series b/soc/riscv/nordic_nrf/nrf54h/Kconfig.series new file mode 100644 index 00000000000..acb85b5623a --- /dev/null +++ b/soc/riscv/nordic_nrf/nrf54h/Kconfig.series @@ -0,0 +1,10 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_NRF54HX + bool "Nordic Semiconductor nRF54H series MCU" + select SOC_FAMILY_NRF + select HAS_NRFX + select HAS_NORDIC_DRIVERS + help + Enable support for nRF54H MCU series diff --git a/soc/riscv/nordic_nrf/nrf54h/Kconfig.soc b/soc/riscv/nordic_nrf/nrf54h/Kconfig.soc new file mode 100644 index 00000000000..17a6dd667c6 --- /dev/null +++ b/soc/riscv/nordic_nrf/nrf54h/Kconfig.soc @@ -0,0 +1,19 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config SOC_NRF54H20 + bool "nRF54H20" + depends on SOC_SERIES_NRF54HX + +if SOC_NRF54H20 + +choice + prompt "nRF54Hx MCU Selection" + +config SOC_NRF54H20_ENGA_CPUPPR + bool "nRF54H20 ENGA CPUPPR" + select RISCV + +endchoice + +endif # SOC_NRF54H20 diff --git a/soc/riscv/nordic_nrf/nrf54h/align.ld b/soc/riscv/nordic_nrf/nrf54h/align.ld new file mode 100644 index 00000000000..0905aa7f7bc --- /dev/null +++ b/soc/riscv/nordic_nrf/nrf54h/align.ld @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA. + * SPDX-License-Identifier: Apache-2.0 + */ + +SECTION_PROLOGUE(.align16,,) +{ + . = (ALIGN(16) > 0 ? ALIGN(16) : 16) - 1; + BYTE(0); +} GROUP_LINK_IN(ROMABLE_REGION) From e9d353d3df4d028966a85d41b255ae04c32d5841 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 31 Jan 2024 19:47:33 +0100 Subject: [PATCH 1269/1623] [nrf fromtree] boards: riscv: add nrf54h20pdk_nrf54h20_cpuppr Add a board that allows to build for the nRF54H20 PPR RISC-V core. Signed-off-by: Grzegorz Swiderski Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 117194ae22b16faa54716701f3f949d643e10d68) --- .../riscv/nrf54h20pdk_nrf54h20/Kconfig.board | 6 +++ .../nrf54h20pdk_nrf54h20/Kconfig.defconfig | 6 +++ boards/riscv/nrf54h20pdk_nrf54h20/board.cmake | 3 ++ .../nrf54h20pdk_nrf54h20_cpuppr.dts | 43 +++++++++++++++++++ .../nrf54h20pdk_nrf54h20_cpuppr.yaml | 13 ++++++ .../nrf54h20pdk_nrf54h20_cpuppr_defconfig | 14 ++++++ .../nrf54h20pdk_nrf54h20/pre_dt_board.cmake | 7 +++ 7 files changed, 92 insertions(+) create mode 100644 boards/riscv/nrf54h20pdk_nrf54h20/Kconfig.board create mode 100644 boards/riscv/nrf54h20pdk_nrf54h20/Kconfig.defconfig create mode 100644 boards/riscv/nrf54h20pdk_nrf54h20/board.cmake create mode 100644 boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts create mode 100644 boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.yaml create mode 100644 boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr_defconfig create mode 100644 boards/riscv/nrf54h20pdk_nrf54h20/pre_dt_board.cmake diff --git a/boards/riscv/nrf54h20pdk_nrf54h20/Kconfig.board b/boards/riscv/nrf54h20pdk_nrf54h20/Kconfig.board new file mode 100644 index 00000000000..9bbbba60dd4 --- /dev/null +++ b/boards/riscv/nrf54h20pdk_nrf54h20/Kconfig.board @@ -0,0 +1,6 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_NRF54H20PDK_NRF54H20_CPUPPR + bool "nRF54H20 PDK nRF54H20 PPR MCU" + depends on SOC_NRF54H20_ENGA_CPUPPR diff --git a/boards/riscv/nrf54h20pdk_nrf54h20/Kconfig.defconfig b/boards/riscv/nrf54h20pdk_nrf54h20/Kconfig.defconfig new file mode 100644 index 00000000000..256976d6519 --- /dev/null +++ b/boards/riscv/nrf54h20pdk_nrf54h20/Kconfig.defconfig @@ -0,0 +1,6 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config BOARD + default "nrf54h20pdk_nrf54h20_cpuppr" + depends on BOARD_NRF54H20PDK_NRF54H20_CPUPPR diff --git a/boards/riscv/nrf54h20pdk_nrf54h20/board.cmake b/boards/riscv/nrf54h20pdk_nrf54h20/board.cmake new file mode 100644 index 00000000000..4c63f1dd05e --- /dev/null +++ b/boards/riscv/nrf54h20pdk_nrf54h20/board.cmake @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: Apache-2.0 + +include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) diff --git a/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts new file mode 100644 index 00000000000..83aface6f5c --- /dev/null +++ b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; + +#include +#include "nrf54h20pdk_nrf54h20-memory_map.dtsi" +#include "nrf54h20pdk_nrf54h20-pinctrl.dtsi" + +/ { + compatible = "nordic,nrf54h20pdk_nrf54h20-cpuppr"; + model = "Nordic nRF54H20 PDK nRF54H20 Peripheral Processor MCU"; + #address-cells = <1>; + #size-cells = <1>; + + chosen { + zephyr,console = &uart135; + zephyr,code-partition = &cpuppr_code_partition; + zephyr,flash = &mram1x; + zephyr,sram = &cpuppr_ram3x_region; + }; +}; + +&grtc { + status = "okay"; + owned-channels = <5>; +}; + +&uart135 { + status = "okay"; + pinctrl-0 = <&uart135_default>; + pinctrl-1 = <&uart135_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&uart136 { + pinctrl-0 = <&uart136_default>; + pinctrl-1 = <&uart136_sleep>; + pinctrl-names = "default", "sleep"; +}; diff --git a/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.yaml b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.yaml new file mode 100644 index 00000000000..274be865c36 --- /dev/null +++ b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.yaml @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +identifier: nrf54h20pdk_nrf54h20_cpuppr +name: nRF54H20-PDK-nRF54H20-PPR +type: mcu +arch: riscv +toolchain: + - zephyr +ram: 28 +flash: 28 +supported: + - gpio diff --git a/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr_defconfig b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr_defconfig new file mode 100644 index 00000000000..fb3dca2266d --- /dev/null +++ b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr_defconfig @@ -0,0 +1,14 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_NRF54HX=y +CONFIG_SOC_NRF54H20=y +CONFIG_SOC_NRF54H20_ENGA_CPUPPR=y +CONFIG_BOARD_NRF54H20PDK_NRF54H20_CPUPPR=y + +CONFIG_XIP=n + +CONFIG_SERIAL=y + +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y diff --git a/boards/riscv/nrf54h20pdk_nrf54h20/pre_dt_board.cmake b/boards/riscv/nrf54h20pdk_nrf54h20/pre_dt_board.cmake new file mode 100644 index 00000000000..5e0fecebdc8 --- /dev/null +++ b/boards/riscv/nrf54h20pdk_nrf54h20/pre_dt_board.cmake @@ -0,0 +1,7 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +# Allow common DTS files to be included from the other board directory. +# To be removed after HWMv2 (#51831), once both directories can be merged into one. +string(REGEX REPLACE "/riscv/(.*$)" "/arm/\\1" BOARD_DIR_ARM "${BOARD_DIR}") +list(APPEND DTS_EXTRA_CPPFLAGS -isystem "${BOARD_DIR_ARM}") From 6749d9b377f45f0b92d2cc2a3c514d7a417c05f1 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Tue, 6 Feb 2024 15:05:08 +0100 Subject: [PATCH 1270/1623] [nrf fromtree] drivers: console: uart_mux: fix incorrect usage of configuration API First, the API ops are available only if CONFIG_UART_USE_RUNTIME_CONFIGURE=y, but the driver was not guarding the code. Also, according to the API specs, these functions are optional, and the interface already returns -ENOSYS if they are not implemented. To solve both problems, just drop the dummy implementation. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit b548a73e79cdfce64d6ffc85cfeaf95fdf35acd1) --- drivers/console/uart_mux.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/drivers/console/uart_mux.c b/drivers/console/uart_mux.c index ca445a1f5b7..8ade93ef0bb 100644 --- a/drivers/console/uart_mux.c +++ b/drivers/console/uart_mux.c @@ -481,24 +481,6 @@ static int uart_mux_err_check(const struct device *dev) return -ENOTSUP; } -static int uart_mux_configure(const struct device *dev, - const struct uart_config *cfg) -{ - ARG_UNUSED(dev); - ARG_UNUSED(cfg); - - return -ENOTSUP; -} - -static int uart_mux_config_get(const struct device *dev, - struct uart_config *cfg) -{ - ARG_UNUSED(dev); - ARG_UNUSED(cfg); - - return -ENOTSUP; -} - static int uart_mux_fifo_fill(const struct device *dev, const uint8_t *tx_data, int len) { @@ -714,8 +696,6 @@ static struct uart_mux_driver_api uart_mux_driver_api = { .uart_api.poll_in = uart_mux_poll_in, .uart_api.poll_out = uart_mux_poll_out, .uart_api.err_check = uart_mux_err_check, - .uart_api.configure = uart_mux_configure, - .uart_api.config_get = uart_mux_config_get, .uart_api.fifo_fill = uart_mux_fifo_fill, .uart_api.fifo_read = uart_mux_fifo_read, .uart_api.irq_tx_enable = uart_mux_irq_tx_enable, From ba520c3278ae12aa94c26ce851bf2c04ec69408e Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 7 Feb 2024 13:04:15 +0100 Subject: [PATCH 1271/1623] [nrf fromtree] dts: arm: nordic: nrf54l15: add missing easydma-maxcnt-bits Unlike SPI nodes, I2C nodes (i2c20, i2c21, i2c22 and i2c30) did not have this required property. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit bf4a021fba16885f87d53f220b9289a064f889ef) --- dts/arm/nordic/nrf54l15_cpuapp_peripherals.dtsi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dts/arm/nordic/nrf54l15_cpuapp_peripherals.dtsi b/dts/arm/nordic/nrf54l15_cpuapp_peripherals.dtsi index 786c21ab215..485d85829a4 100644 --- a/dts/arm/nordic/nrf54l15_cpuapp_peripherals.dtsi +++ b/dts/arm/nordic/nrf54l15_cpuapp_peripherals.dtsi @@ -106,6 +106,7 @@ i2c20: i2c@c6000 { reg = <0xc6000 0x1000>; clock-frequency = ; interrupts = <198 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -140,6 +141,7 @@ i2c21: i2c@c7000 { reg = <0xc7000 0x1000>; clock-frequency = ; interrupts = <199 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -174,6 +176,7 @@ i2c22: i2c@c8000 { reg = <0xc8000 0x1000>; clock-frequency = ; interrupts = <200 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -344,6 +347,7 @@ i2c30: i2c@104000 { reg = <0x104000 0x1000>; clock-frequency = ; interrupts = <260 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <16>; status = "disabled"; }; From 2a88dad0458cf2fd4f9f62ffe3c464fbd6db9919 Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Wed, 7 Feb 2024 11:57:33 +0100 Subject: [PATCH 1272/1623] [nrf fromtree] Revert "drivers: ieee802154: nrf: cache radio channel" This reverts commit 780b12854c11f10f6b3e4b21ae02eaa1b2965736. "drivers: ieee802154: nrf: cache radio channel" Implementation affected RCP devices in openthread as MAC layer does not call `Receive()` functions after transmit is done. Additionally, after sending a frame to a new channel (for example while discovery operation), radio switches to RX state immediately after TX, but continues to listen on old channel for about 5ms, until MAC layer calls `Receive` operation, forcing to change the channel. Signed-off-by: Maciej Baczmanski (cherry picked from commit dbe74b3299f1e247db8c33491ad932e1681c0efa) --- drivers/ieee802154/ieee802154_nrf5.c | 18 ++---------------- drivers/ieee802154/ieee802154_nrf5.h | 3 --- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index 553d71188e9..1831a5b4a6a 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -255,8 +255,6 @@ static int nrf5_cca(const struct device *dev) { struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev); - nrf_802154_channel_set(nrf5_data.channel); - if (!nrf_802154_cca()) { LOG_DBG("CCA failed"); return -EBUSY; @@ -282,7 +280,7 @@ static int nrf5_set_channel(const struct device *dev, uint16_t channel) return channel < 11 ? -ENOTSUP : -EINVAL; } - nrf5_data.channel = channel; + nrf_802154_channel_set(channel); return 0; } @@ -295,8 +293,6 @@ static int nrf5_energy_scan_start(const struct device *dev, ARG_UNUSED(dev); - nrf_802154_channel_set(nrf5_data.channel); - if (nrf5_data.energy_scan_done == NULL) { nrf5_data.energy_scan_done = done_cb; @@ -462,10 +458,6 @@ static bool nrf5_tx_immediate(struct net_pkt *pkt, uint8_t *payload, bool cca) .use_metadata_value = true, .power = nrf5_data.txpwr, }, - .tx_channel = { - .use_metadata_value = true, - .channel = nrf5_data.channel, - }, }; return nrf_802154_transmit_raw(payload, &metadata); @@ -483,10 +475,6 @@ static bool nrf5_tx_csma_ca(struct net_pkt *pkt, uint8_t *payload) .use_metadata_value = true, .power = nrf5_data.txpwr, }, - .tx_channel = { - .use_metadata_value = true, - .channel = nrf5_data.channel, - }, }; return nrf_802154_transmit_csma_ca_raw(payload, &metadata); @@ -526,7 +514,7 @@ static bool nrf5_tx_at(struct nrf5_802154_data *nrf5_radio, struct net_pkt *pkt, .dynamic_data_is_set = net_pkt_ieee802154_mac_hdr_rdy(pkt), }, .cca = cca, - .channel = nrf5_data.channel, + .channel = nrf_802154_channel_get(), .tx_power = { .use_metadata_value = true, .power = nrf5_data.txpwr, @@ -668,7 +656,6 @@ static int nrf5_start(const struct device *dev) ARG_UNUSED(dev); nrf_802154_tx_power_set(nrf5_data.txpwr); - nrf_802154_channel_set(nrf5_data.channel); if (!nrf_802154_receive()) { LOG_ERR("Failed to enter receive state"); @@ -713,7 +700,6 @@ static int nrf5_continuous_carrier(const struct device *dev) ARG_UNUSED(dev); nrf_802154_tx_power_set(nrf5_data.txpwr); - nrf_802154_channel_set(nrf5_data.channel); if (!nrf_802154_continuous_carrier()) { LOG_ERR("Failed to enter continuous carrier state"); diff --git a/drivers/ieee802154/ieee802154_nrf5.h b/drivers/ieee802154/ieee802154_nrf5.h index 0d4d9c9accf..b1c95548210 100644 --- a/drivers/ieee802154/ieee802154_nrf5.h +++ b/drivers/ieee802154/ieee802154_nrf5.h @@ -100,9 +100,6 @@ struct nrf5_802154_data { /* The TX power in dBm. */ int8_t txpwr; - /* The radio channel. */ - uint8_t channel; - #if defined(CONFIG_NRF_802154_SER_HOST) && defined(CONFIG_IEEE802154_CSL_ENDPOINT) /* The last configured value of CSL period in units of 10 symbols. */ uint32_t csl_period; From d2d7e710544d094bf45d480b209d91a1134502f1 Mon Sep 17 00:00:00 2001 From: Alexander Svensen Date: Wed, 7 Feb 2024 08:47:01 +0100 Subject: [PATCH 1273/1623] [nrf fromtree] Bluetooth: Host: Send status for terminated directed adv - Fix bug where status was only sent for legacy adv Signed-off-by: Alexander Svensen (cherry picked from commit 199487be54246436f0bd75aa9965927db7623f85) Signed-off-by: Alexander Svensen --- subsys/bluetooth/host/adv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/host/adv.c b/subsys/bluetooth/host/adv.c index 7134e6fa89a..734c835a841 100644 --- a/subsys/bluetooth/host/adv.c +++ b/subsys/bluetooth/host/adv.c @@ -2185,11 +2185,10 @@ void bt_hci_le_adv_set_terminated(struct net_buf *buf) if (evt->status && IS_ENABLED(CONFIG_BT_PERIPHERAL) && atomic_test_bit(adv->flags, BT_ADV_CONNECTABLE)) { - /* Only set status for legacy advertising API. - * This will call connected callback for high duty cycle + /* This will call connected callback for high duty cycle * directed advertiser timeout. */ - le_adv_stop_free_conn(adv, adv == bt_dev.adv ? evt->status : 0); + le_adv_stop_free_conn(adv, evt->status); } if (IS_ENABLED(CONFIG_BT_CONN) && !evt->status) { From 278144be7db76913170fe241bb9d83e46b0ddc47 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 8 Jan 2024 15:08:26 +0100 Subject: [PATCH 1274/1623] [nrf fromtree] manifest: Update nrf hw models to latest * Update the HW models module to c744f2c762aad79e59bd7e99002f2fcab0a2f288 Including the following: * docs: UART: several minor fixes * UART(E): Add peripherals and connect to (D)PPI Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 85d3ad11179cdc4bf030659e1d413215f1c6b866) Signed-off-by: Ivan Iushkov --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 2697b445524..821824a5936 100644 --- a/west.yml +++ b/west.yml @@ -295,7 +295,7 @@ manifest: groups: - tools - name: nrf_hw_models - revision: 9b985ea6bc237b6ae06f48eb228f2ac7f6e3b96b + revision: c744f2c762aad79e59bd7e99002f2fcab0a2f288 path: modules/bsim_hw_models/nrf_hw_models - name: open-amp revision: 214f9fc1539f8e5937c0474cb6ee29b6dcb2d4b8 From 1e49447b9fe2d444500dbb90ae0ab82c7dd0fb3d Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 11 Jan 2024 13:52:24 +0100 Subject: [PATCH 1275/1623] [nrf fromtree] manifest: Update nrf hw models to latest * Update the HW models module to a08acc7d3a853f890df2bf82167c02ab2153ffe7 Including the following: * a08acc7 UART(E): Duty cycle warnings due to Rx while Rx Off * aa1f38d UART(E): FIFO backend Minor bugfix * 8b0819f UART(E): Add Loopback backend * bc648f2 UART(E): Update RTS pin level as soon as the conf is changed * b39e448 UART(E): Detect receiver opening mid frame Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 992c04c471edc0ea63a4f572cf72b2195ef6a99b) Signed-off-by: Ivan Iushkov --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 821824a5936..c72b0910b99 100644 --- a/west.yml +++ b/west.yml @@ -295,7 +295,7 @@ manifest: groups: - tools - name: nrf_hw_models - revision: c744f2c762aad79e59bd7e99002f2fcab0a2f288 + revision: a08acc7d3a853f890df2bf82167c02ab2153ffe7 path: modules/bsim_hw_models/nrf_hw_models - name: open-amp revision: 214f9fc1539f8e5937c0474cb6ee29b6dcb2d4b8 From 4d36dfa4a889ff688faea10990ff1faa3e8e9e05 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 16 Jan 2024 17:48:10 +0100 Subject: [PATCH 1276/1623] [nrf fromtree] manifest: Update nrf hw models to latest * Update the HW models module to 6b6ae3652c92c95edd945dce6ad9ef9892aab89b Including the following: * 6b6ae36 UART: Minor optimization * afe84c1 fake timer: Minor speed optimization for nrf52 * a5a4dfd RTC: Fix counter value when CLEAR after STOP Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 33d4b6d1482c7ba2cf97a037b2a8dde260547379) Signed-off-by: Ivan Iushkov --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index c72b0910b99..a8c1f512b68 100644 --- a/west.yml +++ b/west.yml @@ -295,7 +295,7 @@ manifest: groups: - tools - name: nrf_hw_models - revision: a08acc7d3a853f890df2bf82167c02ab2153ffe7 + revision: 6b6ae3652c92c95edd945dce6ad9ef9892aab89b path: modules/bsim_hw_models/nrf_hw_models - name: open-amp revision: 214f9fc1539f8e5937c0474cb6ee29b6dcb2d4b8 From 3bdb32e0ab7409197e4e3a3afc42871038904be1 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 18 Jan 2024 13:52:52 +0100 Subject: [PATCH 1277/1623] [nrf fromtree] manifest: Update nrf hw models to latest * Update the HW models module to d17c9d749c817d2522468fa3c0eee3705feb8951 Including the following: * d17c9d7 UART: Bugfix: Support STARTRX while Rx is stopping * d982e76 UART: Minor bugfix: Fix 2 warning messages * eda7af9 UART: Bugfix: Handle task STOPTX while stopping * b8ea63b UART: BugFix: Support STARTTx even if Tx is not Off * c0d28cc nrf_common: Add replacement for nrf_dma_accessible_check() * feb91bb nrfx_common replacement: nrfx_get_irq_number() Add missing peri * c95d9af Makefile: By default lets build both 52833 and 5340 targets * cf41110 UART: FIFO backend: Check for failure of fcntl Signed-off-by: Alberto Escolar Piedras (cherry picked from commit c9d489d38b0cd25f35d5e33c03144c90204600d0) Signed-off-by: Ivan Iushkov --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index a8c1f512b68..c0f729f7fe7 100644 --- a/west.yml +++ b/west.yml @@ -295,7 +295,7 @@ manifest: groups: - tools - name: nrf_hw_models - revision: 6b6ae3652c92c95edd945dce6ad9ef9892aab89b + revision: d17c9d749c817d2522468fa3c0eee3705feb8951 path: modules/bsim_hw_models/nrf_hw_models - name: open-amp revision: 214f9fc1539f8e5937c0474cb6ee29b6dcb2d4b8 From 7e22d688b57cd3b85b293fe8995bc593d761c4f9 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 6 Feb 2024 17:40:53 +0100 Subject: [PATCH 1278/1623] [nrf fromtree] manifest: Update nrf hw models to latest * Update the HW models module to 52d0b4b7b7431d8da6222cc3b17a8afdcb099baf Including the following: * 52d0b4b UART: FIFO backend: Do not error out if other side disconnects Rx * 3582b68 UART: FIFO backend: Avoid possible race * 414f160 AAR: Fix UBSAN warnings * 24f5d3d PPI: Fix UBSAN warning Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 189d4d4b069d78de1f17b4179229ca00d4d80789) Signed-off-by: Ivan Iushkov --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index c0f729f7fe7..7ce69358f52 100644 --- a/west.yml +++ b/west.yml @@ -295,7 +295,7 @@ manifest: groups: - tools - name: nrf_hw_models - revision: d17c9d749c817d2522468fa3c0eee3705feb8951 + revision: 52d0b4b7b7431d8da6222cc3b17a8afdcb099baf path: modules/bsim_hw_models/nrf_hw_models - name: open-amp revision: 214f9fc1539f8e5937c0474cb6ee29b6dcb2d4b8 From 4c9479b079d2edce2e5dd1d53a6c0006a31dcc1f Mon Sep 17 00:00:00 2001 From: Ivan Iushkov Date: Tue, 6 Feb 2024 13:08:30 +0100 Subject: [PATCH 1279/1623] [nrf fromtree] Bluetooth: Fixing UBSAN warning in CTE field parsing in adv.c/scan.c during local testling, UBSAN reported the following warnings: - bluetooth/host/adv.c:2067:19: runtime error: shift exponent 255 is too large for 32-bit type 'long unsigned int' - bluetooth/host/scan.c:828:18: runtime error: shift exponent 255 is too large for 32-bit type 'long unsigned int' It turned out that we can't use BIT() macro directly on bt_hci_evt_le_per_advertising_report::cte_type field. According to Core Spec, `cte_type = 0xFF` corresponds to `No contstant tone extension`. Added separate function to convert CTE bit field from HCI format to bt_df_cte_type Signed-off-by: Ivan Iushkov (cherry picked from commit b1e9f86378c1c2f591aa2d6882da9a1a8ca4ac78) Signed-off-by: Ivan Iushkov --- subsys/bluetooth/host/adv.c | 2 +- subsys/bluetooth/host/hci_core.c | 16 ++++++++++++++++ subsys/bluetooth/host/hci_core.h | 9 ++++++++- subsys/bluetooth/host/scan.c | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/host/adv.c b/subsys/bluetooth/host/adv.c index 734c835a841..7a312d5e05c 100644 --- a/subsys/bluetooth/host/adv.c +++ b/subsys/bluetooth/host/adv.c @@ -2064,7 +2064,7 @@ void bt_hci_le_per_adv_response_report(struct net_buf *buf) response = net_buf_pull_mem(buf, sizeof(struct bt_hci_evt_le_per_adv_response)); info.tx_power = response->tx_power; info.rssi = response->rssi; - info.cte_type = BIT(response->cte_type); + info.cte_type = bt_get_df_cte_type(response->cte_type); info.response_slot = response->response_slot; if (buf->len < response->data_length) { diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index b37cd45e1ae..ee1c822d9f9 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -422,6 +422,22 @@ uint8_t bt_get_phy(uint8_t hci_phy) } } +int bt_get_df_cte_type(uint8_t hci_cte_type) +{ + switch (hci_cte_type) { + case BT_HCI_LE_AOA_CTE: + return BT_DF_CTE_TYPE_AOA; + case BT_HCI_LE_AOD_CTE_1US: + return BT_DF_CTE_TYPE_AOD_1US; + case BT_HCI_LE_AOD_CTE_2US: + return BT_DF_CTE_TYPE_AOD_2US; + case BT_HCI_LE_NO_CTE: + return BT_DF_CTE_TYPE_NONE; + default: + return BT_DF_CTE_TYPE_NONE; + } +} + #if defined(CONFIG_BT_CONN_TX) static void hci_num_completed_packets(struct net_buf *buf) { diff --git a/subsys/bluetooth/host/hci_core.h b/subsys/bluetooth/host/hci_core.h index ce4fc5a9b63..1a3c06414a0 100644 --- a/subsys/bluetooth/host/hci_core.h +++ b/subsys/bluetooth/host/hci_core.h @@ -434,7 +434,14 @@ int bt_le_set_data_len(struct bt_conn *conn, uint16_t tx_octets, uint16_t tx_tim int bt_le_set_phy(struct bt_conn *conn, uint8_t all_phys, uint8_t pref_tx_phy, uint8_t pref_rx_phy, uint8_t phy_opts); uint8_t bt_get_phy(uint8_t hci_phy); - +/** + * @brief Convert CTE type value from HCI format to @ref bt_df_cte_type format. + * + * @param hci_cte_type CTE type in an HCI format. + * + * @return CTE type (@ref bt_df_cte_type). + */ +int bt_get_df_cte_type(uint8_t hci_cte_type); int bt_le_scan_update(bool fast_scan); int bt_le_create_conn(const struct bt_conn *conn); diff --git a/subsys/bluetooth/host/scan.c b/subsys/bluetooth/host/scan.c index 168d7f6ead3..0b61305e2c3 100644 --- a/subsys/bluetooth/host/scan.c +++ b/subsys/bluetooth/host/scan.c @@ -825,7 +825,7 @@ static void bt_hci_le_per_adv_report_common(struct net_buf *buf) info.tx_power = evt->tx_power; info.rssi = evt->rssi; - info.cte_type = BIT(evt->cte_type); + info.cte_type = bt_get_df_cte_type(evt->cte_type); info.addr = &per_adv_sync->addr; info.sid = per_adv_sync->sid; From 2ef9e28a442e35fdb47d0225d782943cc3db01a4 Mon Sep 17 00:00:00 2001 From: Ivan Iushkov Date: Mon, 5 Feb 2024 16:30:36 +0100 Subject: [PATCH 1280/1623] [nrf fromtree] Bluetooth: fixing UBSAN warnings related to Codec Configuration During local testing with UBSAN enabled, warning was reported: bluetooth/host/iso.c:237:2: runtime error: null pointer passed as argument 2, which is declared to never be null It turned out that when datapath doesn't contain codec information, cc_len is 0 and cc is NULL In order to avoid UB, now we call memcpy only when cp->codec_config_len > 0 Signed-off-by: Ivan Iushkov (cherry picked from commit e8d090011b6fa9d7e37e05dd03eb457e801b2e97) Signed-off-by: Ivan Iushkov --- subsys/bluetooth/host/iso.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/host/iso.c b/subsys/bluetooth/host/iso.c index 4d6366ead67..05b5cc2f613 100644 --- a/subsys/bluetooth/host/iso.c +++ b/subsys/bluetooth/host/iso.c @@ -233,9 +233,10 @@ static int hci_le_setup_iso_data_path(const struct bt_conn *iso, uint8_t dir, cp->codec_id.vs_codec_id = sys_cpu_to_le16(path->vid); sys_put_le24(path->delay, cp->controller_delay); cp->codec_config_len = path->cc_len; - cc = net_buf_add(buf, cp->codec_config_len); - memcpy(cc, path->cc, cp->codec_config_len); - + cc = net_buf_add(buf, path->cc_len); + if (path->cc_len) { + memcpy(cc, path->cc, path->cc_len); + } err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SETUP_ISO_PATH, buf, &rsp); if (err) { return err; From e9bb83320a4cd303135203fae18136a71e87f26e Mon Sep 17 00:00:00 2001 From: Ivan Iushkov Date: Tue, 6 Feb 2024 09:34:16 +0100 Subject: [PATCH 1281/1623] [nrf fromtree] Bluetooth: fixing null-pointer dereference in l2cap channel destroyer During local testing with UBSAN enabled, warning was reported: bluetooth/host/l2cap.c:980:25: runtime error: member access within null pointer of type 'struct k_work_q' It turned out that le_chan->rtx_work.queue can be NULL. Since null-pointer dereference is a UB, additional check was added to ensure we don't access `le_chan->rtx_work.queue->thread` when `le_chan->rtx_work.queue == NULL` The same changes applied to l2cap_br.c Signed-off-by: Ivan Iushkov (cherry picked from commit a3cbf8e2aca97548c9a7380c76b8bf8e0161006a) Signed-off-by: Ivan Iushkov --- subsys/bluetooth/host/l2cap.c | 4 +++- subsys/bluetooth/host/l2cap_br.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index e6fbe2144f8..b8faa1efcae 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -977,7 +977,9 @@ static void l2cap_chan_destroy(struct bt_l2cap_chan *chan) * In the case where we are in the context of executing the rtx_work * item, we don't sync as it will deadlock the workqueue. */ - if (k_current_get() != &le_chan->rtx_work.queue->thread) { + struct k_work_q *rtx_work_queue = le_chan->rtx_work.queue; + + if (rtx_work_queue == NULL || k_current_get() != &rtx_work_queue->thread) { k_work_cancel_delayable_sync(&le_chan->rtx_work, &le_chan->rtx_sync); } else { k_work_cancel_delayable(&le_chan->rtx_work); diff --git a/subsys/bluetooth/host/l2cap_br.c b/subsys/bluetooth/host/l2cap_br.c index e9a10ff8d72..3a33ff293c6 100644 --- a/subsys/bluetooth/host/l2cap_br.c +++ b/subsys/bluetooth/host/l2cap_br.c @@ -165,7 +165,9 @@ static void l2cap_br_chan_destroy(struct bt_l2cap_chan *chan) * In the case where we are in the context of executing the rtx_work * item, we don't sync as it will deadlock the workqueue. */ - if (k_current_get() != &br_chan->rtx_work.queue->thread) { + struct k_work_q *rtx_work_queue = br_chan->rtx_work.queue; + + if (rtx_work_queue == NULL || k_current_get() != &rtx_work_queue->thread) { k_work_cancel_delayable_sync(&br_chan->rtx_work, &br_chan->rtx_sync); } else { k_work_cancel_delayable(&br_chan->rtx_work); From 3a4daeda7027aa1e3224175f3353c92ddcb614d4 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 16 Jan 2024 14:44:53 +0100 Subject: [PATCH 1282/1623] [nrf fromtree] Bluetooth: Mesh: Fix processing SegAcks to wrong destination MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not process SegAcks which were not targeted to the node. They were rejected in the next if statement always, but generated the annyoing warning "No matching TX context for ack". Signed-off-by: Pavel Vasilyev (cherry picked from commit 7a41a9d864cdd00bda521d09662ecf4fcfa6f2a5) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/transport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/transport.c b/subsys/bluetooth/mesh/transport.c index 47e8492a901..a0364dceb25 100644 --- a/subsys/bluetooth/mesh/transport.c +++ b/subsys/bluetooth/mesh/transport.c @@ -869,6 +869,8 @@ static int trans_ack(struct bt_mesh_net_rx *rx, uint8_t hdr, /* Best effort - we don't have enough info for true SeqAuth */ *seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_RX(rx), seq_zero); return 0; + } else if (!rx->local_match) { + return 0; } ack = net_buf_simple_pull_be32(buf); @@ -969,7 +971,7 @@ static int ctl_recv(struct bt_mesh_net_rx *rx, uint8_t hdr, return bt_mesh_hb_recv(rx, buf); } - /* Only acks and heartbeats may need processing without local_match */ + /* Only acks for friendship and heartbeats may need processing without local_match */ if (!rx->local_match) { return 0; } From 6bc6ab47474ab774903d5fa9df9ca4458a9e5b75 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Wed, 29 Nov 2023 13:28:08 +0100 Subject: [PATCH 1283/1623] [nrf fromtree] Bluetooth: Mesh: Drop explicit support for Bluetooth Mesh 1.0.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bluetooth Mesh Protocol 1.1 is backward compatible with Bluetooth Mesh Profile 1.0.1, therefore the stack can still be qualified for 1.0.1 if needed. But explicit support for both versions requires additional maintenance efforts and doubles the CI time. To make the stack qualifiable for 1.0.1, the one needs to remove Private Beacons reception and compile out SHA256 algorithm support. What is changed: - Removed `CONFIG_BT_MESH_V1d1` option. - Removed `transport_legacy.c` which was using 1.0.1 implementation. The new transport layer has new SaR logic that should still be possible to qualify for 1.0.1. - Removed the legacy transport Kconfig options. They are superseded by the new transport Kconfig options. - Tester app: `overlay-mesh-v1d1.conf` is merged into `overlay-mesh.conf`. - Removed BabbleSim tests for 1.0.1. - Updated documentation. Signed-off-by: Pavel Vasilyev (cherry picked from commit 981c79b7ce9377cebbab89ac1770ee922061db58) Signed-off-by: Alperen Şener --- doc/connectivity/bluetooth/api/mesh.rst | 5 +- .../bluetooth/api/mesh/access.rst | 9 - .../bluetooth/api/mesh/sar_cfg.rst | 56 +- doc/releases/migration-guide-3.6.rst | 19 + doc/releases/release-notes-3.6.rst | 1 + include/zephyr/bluetooth/mesh/main.h | 4 - subsys/bluetooth/mesh/CMakeLists.txt | 7 +- subsys/bluetooth/mesh/Kconfig | 62 +- subsys/bluetooth/mesh/access.c | 3 +- subsys/bluetooth/mesh/beacon.c | 6 - subsys/bluetooth/mesh/net.c | 5 - subsys/bluetooth/mesh/subnet.h | 2 - subsys/bluetooth/mesh/transport_legacy.c | 1656 ----------------- tests/bluetooth/mesh/blob_io_flash/prj.conf | 1 - .../mesh_shell/proxy_solicitation.conf | 1 - tests/bluetooth/tester/overlay-mesh-v1d1.conf | 30 - tests/bluetooth/tester/overlay-mesh.conf | 29 + tests/bluetooth/tester/testcase.yaml | 10 - tests/bsim/bluetooth/mesh/CMakeLists.txt | 45 +- tests/bsim/bluetooth/mesh/compile.sh | 21 +- tests/bsim/bluetooth/mesh/overlay_pst.conf | 3 - tests/bsim/bluetooth/mesh/prj.conf | 28 +- tests/bsim/bluetooth/mesh/prj_mesh1d1.conf | 73 - tests/bsim/bluetooth/mesh/src/main.c | 17 +- tests/bsim/bluetooth/mesh/src/test_beacon.c | 17 +- .../bsim/bluetooth/mesh/src/test_provision.c | 4 - .../bluetooth/mesh/src/test_replay_cache.c | 4 - .../bsim/bluetooth/mesh/src/test_transport.c | 2 - .../tests_scripts/access/access_cancel.sh | 5 - .../tests_scripts/access/access_ext_sub.sh | 5 - .../access/access_ext_sub_cap.sh | 4 - .../tests_scripts/access/access_period.sh | 5 - .../access/access_period_delayable.sh | 5 - .../tests_scripts/access/access_transmit.sh | 5 - .../access/access_transmit_delayable.sh | 5 - .../tests_scripts/advertiser/proxy_mixin.sh | 5 - .../tests_scripts/advertiser/random_order.sh | 4 - .../tests_scripts/advertiser/reverse_order.sh | 4 - .../tests_scripts/advertiser/send_order.sh | 4 - .../tests_scripts/advertiser/tx_cb_multi.sh | 4 - .../tests_scripts/advertiser/tx_cb_single.sh | 4 - .../mesh/tests_scripts/beacon/beacon_cache.sh | 6 - .../tests_scripts/beacon/beacon_interval.sh | 6 - .../mesh/tests_scripts/beacon/invalid.sh | 6 - .../mesh/tests_scripts/beacon/iv_update.sh | 6 - .../mesh/tests_scripts/beacon/key_refresh.sh | 6 - .../mesh/tests_scripts/beacon/kr_old_key.sh | 6 - .../tests_scripts/beacon/multiple_netkeys.sh | 6 - .../blob_mdls/blob_cli_broadcast_basic.sh | 2 - .../blob_mdls/blob_cli_broadcast_trans.sh | 2 - .../blob_mdls/blob_cli_broadcast_unicast.sh | 2 - .../blob_cli_broadcast_unicast_seq.sh | 2 - .../blob_mdls/blob_cli_caps_all_rsp.sh | 2 - .../blob_mdls/blob_cli_caps_cancelled.sh | 2 - .../blob_mdls/blob_cli_caps_no_rsp.sh | 2 - .../blob_mdls/blob_cli_caps_partial_rsp.sh | 2 - .../blob_mdls/blob_cli_friend.sh | 2 - .../blob_mdls/blob_cli_no_rsp_block.sh | 2 - .../blob_mdls/blob_cli_no_rsp_xfer.sh | 2 - .../blob_mdls/blob_cli_persistent_transfer.sh | 2 - .../blob_cli_persistent_transfer_pull.sh | 2 - .../blob_mdls/blob_cli_trans_complete_pull.sh | 2 - .../blob_mdls/blob_cli_trans_complete_push.sh | 2 - .../blob_mdls/blob_cli_trans_resume_pull.sh | 2 - .../blob_mdls/blob_cli_trans_resume_push.sh | 2 - .../blob_mdls/blob_srv_persistence.sh | 12 - .../comp_data/cdp1_encode_decode.sh | 2 - .../dfu/dfu_cli_all_targets_lost_on_apply.sh | 2 - .../dfu_cli_all_targets_lost_on_caps_get.sh | 2 - .../dfu_cli_all_targets_lost_on_metadata.sh | 2 - .../dfu_cli_all_targets_lost_on_update_get.sh | 2 - .../dfu/dfu_cli_all_targets_lost_on_verify.sh | 2 - .../dfu/dfu_cli_persistent_transfer.sh | 2 - .../tests_scripts/dfu/dfu_dist_self_update.sh | 2 - .../dfu/dfu_dist_self_update_mult_targets.sh | 2 - .../mesh/tests_scripts/dfu/dfu_mixed.sh | 2 - .../mesh/tests_scripts/dfu/dfu_mixed_fail.sh | 2 - .../mesh/tests_scripts/dfu/dfu_slot.sh | 2 - .../tests_scripts/dfu/dfu_slot_idempotency.sh | 2 - .../tests_scripts/dfu/dfu_slot_reservation.sh | 2 - .../tests_scripts/dfu/dfu_srv_persistence.sh | 14 - .../tests_scripts/friendship/establish.sh | 6 - .../friendship/establish_multi.sh | 10 - .../tests_scripts/friendship/lpn_disable.sh | 6 - .../tests_scripts/friendship/lpn_loopback.sh | 6 - .../friendship/lpn_terminate_cb.sh | 6 - .../mesh/tests_scripts/friendship/msg_frnd.sh | 6 - .../tests_scripts/friendship/msg_group.sh | 7 - .../mesh/tests_scripts/friendship/msg_mesh.sh | 7 - .../friendship/msg_mesh_low_lat.sh | 8 - .../friendship/msg_va_collision.sh | 6 - .../mesh/tests_scripts/friendship/overflow.sh | 6 - .../mesh/tests_scripts/friendship/poll.sh | 6 - .../tests_scripts/friendship/re-establish.sh | 6 - .../tests_scripts/heartbeat/sub_cb_api_all.sh | 7 - .../heartbeat/sub_cb_api_unicast.sh | 7 - .../tests_scripts/iv_index/iv_deferring.sh | 4 - .../tests_scripts/iv_index/iv_recovery.sh | 4 - .../mesh/tests_scripts/iv_index/iv_update.sh | 4 - .../large_comp_data/get_comp0_data_split.sh | 2 - .../get_comp0_data_split_dfu.sh | 2 - .../large_comp_data/get_comp128_data_split.sh | 2 - .../get_comp128_data_split_dfu.sh | 2 - .../large_comp_data/get_comp129_data_split.sh | 2 - .../get_comp129_data_split_dfu.sh | 2 - .../large_comp_data/get_comp130_data_split.sh | 2 - .../get_comp130_data_split_dfu.sh | 2 - .../large_comp_data/get_comp1_data_split.sh | 2 - .../get_comp1_data_split_dfu.sh | 2 - .../large_comp_data/get_comp2_data_split.sh | 2 - .../get_comp2_data_split_dfu.sh | 2 - .../large_comp_data/get_comp_data_max_sdu.sh | 2 - .../large_comp_data/get_metadata_max_sdu.sh | 2 - .../large_comp_data/get_metadata_split.sh | 2 - .../op_agg/full_status_msg_list.sh | 2 - .../mesh/tests_scripts/op_agg/loopback.sh | 2 - .../mesh/tests_scripts/op_agg/model_coex.sh | 2 - .../mesh/tests_scripts/persistence/access.sh | 35 - .../mesh/tests_scripts/persistence/cfg.sh | 24 - .../tests_scripts/persistence/provisioning.sh | 10 - .../persistence/reprovisioning.sh | 14 - .../priv_beacon/priv_beacon_adv.sh | 2 - .../priv_beacon/priv_beacon_cache.sh | 2 - .../priv_beacon/priv_beacon_interleave.sh | 2 - .../priv_beacon/priv_beacon_invalid.sh | 2 - .../priv_beacon/priv_beacon_ivu.sh | 2 - .../priv_beacon_ivu_long_interval.sh | 2 - .../priv_beacon/priv_beacon_kr.sh | 2 - .../priv_beacon_kr_long_interval.sh | 2 - .../priv_beacon/priv_proxy_gatt.sh | 2 - .../priv_beacon/priv_proxy_net_id.sh | 2 - .../priv_beacon/priv_proxy_net_id_multi.sh | 2 - .../priv_beacon/priv_proxy_node_id.sh | 2 - .../proxy_adv_multi_subnet_coex.sh | 2 - .../provision/ivu_flag_one_duration.sh | 4 - .../provision/ivu_flag_zero_duration.sh | 4 - .../tests_scripts/provision/pb_adv_multi.sh | 8 - .../tests_scripts/provision/pb_adv_no_oob.sh | 6 - .../provision/pb_adv_oob_auth_ib_pk.sh | 5 - .../pb_adv_oob_auth_ignore_oob_pk.sh | 5 - .../provision/pb_adv_oob_auth_oob_pk.sh | 5 - .../provision/pb_adv_reprovision.sh | 6 - .../pb_remote_client_server_same_dev.sh | 2 - .../provision/pb_remote_nppi_robustness.sh | 2 - .../provision/pb_remote_parallel.sh | 2 - .../provision/pb_remote_pst_ncrp.sh | 6 - .../provision/pb_remote_reprovision.sh | 2 - .../provision/pb_remote_timeout.sh | 2 - .../replay_cache/replay_attack.sh | 14 - .../tests_scripts/replay_cache/rpl_frag.sh | 13 - .../sar/sar_cfg_persistent_storage.sh | 2 - .../tests_scripts/sar/slow_transfer_test.sh | 2 - .../mesh/tests_scripts/sar/stress_test.sh | 2 - .../tests_scripts/scanner/invalid_ad_type.sh | 6 - .../scanner/wrong_packet_length.sh | 6 - .../suspend/gatt_suspend_disable_resume.sh | 31 + .../suspend/gatt_suspend_resume.sh | 31 + .../suspend/suspend_disable_resume.sh | 28 + .../tests_scripts/suspend/suspend_resume.sh | 27 + .../mesh/tests_scripts/transport/fixed.sh | 4 - .../mesh/tests_scripts/transport/group.sh | 4 - .../mesh/tests_scripts/transport/loopback.sh | 4 - .../tests_scripts/transport/loopback_group.sh | 4 - .../transport/loopback_group_low_lat.sh | 5 - .../mesh/tests_scripts/transport/seg_block.sh | 4 - .../tests_scripts/transport/seg_concurrent.sh | 4 - .../mesh/tests_scripts/transport/seg_fail.sh | 4 - .../mesh/tests_scripts/transport/seg_ivu.sh | 4 - .../mesh/tests_scripts/transport/unicast.sh | 4 - .../transport/unicast_low_lat.sh | 5 - .../tests_scripts/transport/unknown_app.sh | 4 - .../mesh/tests_scripts/transport/va.sh | 4 - .../tests_scripts/transport/va_collision.sh | 4 - 173 files changed, 236 insertions(+), 2609 deletions(-) delete mode 100644 subsys/bluetooth/mesh/transport_legacy.c delete mode 100644 tests/bluetooth/tester/overlay-mesh-v1d1.conf delete mode 100644 tests/bsim/bluetooth/mesh/prj_mesh1d1.conf create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/suspend/gatt_suspend_disable_resume.sh create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/suspend/gatt_suspend_resume.sh create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/suspend/suspend_disable_resume.sh create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/suspend/suspend_resume.sh diff --git a/doc/connectivity/bluetooth/api/mesh.rst b/doc/connectivity/bluetooth/api/mesh.rst index f234ff7cedc..358ba3dc62e 100644 --- a/doc/connectivity/bluetooth/api/mesh.rst +++ b/doc/connectivity/bluetooth/api/mesh.rst @@ -5,10 +5,7 @@ Bluetooth Mesh Profile The Bluetooth Mesh profile adds secure wireless multi-hop communication for Bluetooth Low Energy. This module implements the -`Bluetooth Mesh Profile Specification v1.0.1 `_. - -Implementation of the `Bluetooth Mesh Protocol Specification v1.1 `_ -is in experimental state. +`Bluetooth Mesh Protocol Specification v1.1 `_. Read more about Bluetooth Mesh on the `Bluetooth SIG Website `_. diff --git a/doc/connectivity/bluetooth/api/mesh/access.rst b/doc/connectivity/bluetooth/api/mesh/access.rst index cb02028b697..7af8ca7ec68 100644 --- a/doc/connectivity/bluetooth/api/mesh/access.rst +++ b/doc/connectivity/bluetooth/api/mesh/access.rst @@ -168,15 +168,6 @@ needs to be stored. Composition Data ================ -.. note:: - - The implementation of the Bluetooth Mesh Protocol Specification version 1.1 - is currently in an experimental state. For Bluetooth Mesh Profile Specification - version 1.0.1, only Composition Data Page 0 is supported. Users that are developing - for Bluetooth Mesh Profile Specification version 1.0.1 may therefore disregard all - parts of the following section mentioning the :ref:`bluetooth_mesh_lcd_srv` - model and Composition Data Pages 1, 2, 128, 129 and 130. - The Composition Data provides information about a mesh device. A device's Composition Data holds information about the elements on the device, the models that it supports, and other features. The Composition diff --git a/doc/connectivity/bluetooth/api/mesh/sar_cfg.rst b/doc/connectivity/bluetooth/api/mesh/sar_cfg.rst index 4f3354945c9..76bd0330a98 100644 --- a/doc/connectivity/bluetooth/api/mesh/sar_cfg.rst +++ b/doc/connectivity/bluetooth/api/mesh/sar_cfg.rst @@ -43,36 +43,8 @@ Keep this in mind when defining the size of the buffers. SAR does not impose extra overhead on the access layer payload per segment. -Intervals, timers and retransmission counters -********************************************* - -The current stable stack implementation allows you to configure the following SAR behavior. - -When sending a segmented message to a unicast address, the unacknowledged segments are repeated -the :kconfig:option:`CONFIG_BT_MESH_TX_SEG_RETRANS_COUNT` number of times before the transmission -is considered as failed. The same option configures a number of retransmissions to a group or -virtual address, but the transmission always succeedes after retransmitting all segments the -configured number of times. - -The timeout between each retransmission to a unicast address is configured by the Kconfig option -:kconfig:option:`CONFIG_BT_MESH_TX_SEG_RETRANS_TIMEOUT_UNICAST`. The timeout between each -retransmission to a group or a virtual address is configured by the Kconfig option -:kconfig:option:`CONFIG_BT_MESH_TX_SEG_RETRANS_TIMEOUT_GROUP`. - -The time before sending a Segment Acknowledgment message is controlled by the Kconfig options -:kconfig:option:`CONFIG_BT_MESH_SEG_ACK_BASE_TIMEOUT`, -:kconfig:option:`CONFIG_BT_MESH_SEG_ACK_PER_HOP_TIMEOUT` and -:kconfig:option:`CONFIG_BT_MESH_SEG_ACK_PER_SEGMENT_TIMEOUT`, and is defined as: - -.. math:: - \begin{aligned} - \max(&\mathtt{CONFIG\_BT\_MESH\_SEG\_ACK\_BASE\_TIMEOUT} \\ - &+ \text{TTL} \times \mathtt{CONFIG\_BT\_MESH\_SEG\_ACK\_PER\_HOP\_TIMEOUT} \\ - &+ \text{number of un-acked segments} \times \mathtt{CONFIG\_BT\_MESH\_SEG\_ACK\_PER\_SEGMENT\_TIMEOUT} , 400) - \end{aligned} - Segmentation and reassembly (SAR) Configuration models -====================================================== +****************************************************** With Bluetooth Mesh Protocol Specification version 1.1, it became possible to configure SAR behavior, such as intervals, timers and retransmission counters, over a mesh network using SAR @@ -139,7 +111,7 @@ of the `SAR Acknowledgment Retransmissions Count`_ state. .. _bt_mesh_sar_cfg_states: SAR states -========== +********** There are two states defined related to segmentation and reassembly: @@ -168,7 +140,7 @@ the following states: * SAR Receiver Segment Interval Step SAR Segment Interval Step -------------------------- +========================= SAR Segment Interval Step state holds a value that controls the interval between transmissions of segments of a segmented message. The interval is measured in milliseconds. @@ -182,7 +154,7 @@ value. Segment transmission interval is then calculated using the following form SAR Unicast Retransmissions Count ---------------------------------- +================================= SAR Unicast Retransmissions Count holds a value that defines the maximum number of retransmissions of a segmented message to a unicast destination. Use the @@ -190,7 +162,7 @@ of a segmented message to a unicast destination. Use the value for this state. SAR Unicast Retransmissions Without Progress Count --------------------------------------------------- +================================================== This state holds a value that defines the maximum number of retransmissions of a segmented message to a unicast address that will be sent if no acknowledgment was received during the timeout, or if @@ -199,7 +171,7 @@ an acknowledgment with already confirmed segments was received. Use the Kconfig of retransmissions. SAR Unicast Retransmissions Interval Step ------------------------------------------ +========================================= The value of this state controls the interval step used for delaying the retransmissions of unacknowledged segments of a segmented message to a unicast address. The interval step is measured @@ -214,7 +186,7 @@ default value. This value is then used to calculate the interval step using the SAR Unicast Retransmissions Interval Increment ----------------------------------------------- +============================================== SAR Unicast Retransmissions Interval Increment holds a value that controls the interval increment used for delaying the retransmissions of unacknowledged segments of a segmented message to a unicast @@ -230,7 +202,7 @@ formula: SAR Multicast Retransmissions Count ------------------------------------ +=================================== The state holds a value that controls the total number of retransmissions of a segmented message to a multicast address. Use the Kconfig option @@ -238,7 +210,7 @@ a multicast address. Use the Kconfig option retransmissions. SAR Multicast Retransmissions Interval Step -------------------------------------------- +=========================================== This state holds a value that controls the interval between retransmissions of all segments in a segmented message to a multicast address. The interval is measured in milliseconds. @@ -252,7 +224,7 @@ default value that is used to calculate the interval using the following formula SAR Discard Timeout -------------------- +=================== The value of this state defines the time in seconds that the lower transport layer waits after receiving segments of a segmented message before discarding that segmented message. Use the Kconfig @@ -265,7 +237,7 @@ timeout will be calculated using the following formula: SAR Acknowledgment Delay Increment ----------------------------------- +================================== This state holds a value that controls the delay increment of an interval used for delaying the transmission of an acknowledgment message after receiving a new segment. The increment is measured @@ -276,7 +248,7 @@ value. The increment value is calculated to be :math:`\verb|CONFIG_BT_MESH_SAR_RX_ACK_DELAY_INC| + 1.5`. SAR Segments Threshold ----------------------- +====================== SAR Segments Threshold state holds a value that defines a threshold in number of segments of a segmented message for acknowledgment retransmissions. Use the Kconfig option @@ -287,7 +259,7 @@ additionally retransmit every acknowledgment message the number of times given b :kconfig:option:`CONFIG_BT_MESH_SAR_RX_ACK_RETRANS_COUNT`. SAR Acknowledgment Retransmissions Count ----------------------------------------- +======================================== The SAR Acknowledgment Retransmissions Count state controls the number of retransmissions of Segment Acknowledgment messages sent by the lower transport layer. It gives the total number of @@ -300,7 +272,7 @@ value for this state. The maximum number of transmissions of a Segment Acknowle :math:`\verb|CONFIG_BT_MESH_SAR_RX_ACK_RETRANS_COUNT| + 1`. SAR Receiver Segment Interval Step ----------------------------------- +================================== The SAR Receiver Segment Interval Step defines the segments reception interval step used for delaying the transmission of an acknowledgment message after receiving a new segment. The interval diff --git a/doc/releases/migration-guide-3.6.rst b/doc/releases/migration-guide-3.6.rst index c4cb37eaf94..8428e2a4645 100644 --- a/doc/releases/migration-guide-3.6.rst +++ b/doc/releases/migration-guide-3.6.rst @@ -135,6 +135,25 @@ Bluetooth * Deprecated :kconfig:option:`CONFIG_BT_MESH_PROV_DEVICE`. This option is replaced by new option :kconfig:option:`CONFIG_BT_MESH_PROVISIONEE` to be aligned with Mesh Protocol Specification v1.1, section 5.4. (:github:`64252`) + * Removed the ``CONFIG_BT_MESH_V1d1`` Kconfig option. + * Removed the ``CONFIG_BT_MESH_TX_SEG_RETRANS_COUNT``, + ``CONFIG_BT_MESH_TX_SEG_RETRANS_TIMEOUT_UNICAST``, + ``CONFIG_BT_MESH_TX_SEG_RETRANS_TIMEOUT_GROUP``, ``CONFIG_BT_MESH_SEG_ACK_BASE_TIMEOUT``, + ``CONFIG_BT_MESH_SEG_ACK_PER_HOP_TIMEOUT``, ``BT_MESH_SEG_ACK_PER_SEGMENT_TIMEOUT`` + Kconfig options. They are superseded by the + :kconfig:option:`CONFIG_BT_MESH_SAR_TX_SEG_INT_STEP`, + :kconfig:option:`CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_COUNT`, + :kconfig:option:`CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_WITHOUT_PROG_COUNT`, + :kconfig:option:`CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_INT_STEP`, + :kconfig:option:`CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_INT_INC`, + :kconfig:option:`CONFIG_BT_MESH_SAR_TX_MULTICAST_RETRANS_COUNT`, + :kconfig:option:`CONFIG_BT_MESH_SAR_TX_MULTICAST_RETRANS_INT`, + :kconfig:option:`CONFIG_BT_MESH_SAR_RX_SEG_THRESHOLD`, + :kconfig:option:`CONFIG_BT_MESH_SAR_RX_ACK_DELAY_INC`, + :kconfig:option:`CONFIG_BT_MESH_SAR_RX_SEG_INT_STEP`, + :kconfig:option:`CONFIG_BT_MESH_SAR_RX_DISCARD_TIMEOUT`, + :kconfig:option:`CONFIG_BT_MESH_SAR_RX_ACK_RETRANS_COUNT` Kconfig options. + LoRaWAN ======= diff --git a/doc/releases/release-notes-3.6.rst b/doc/releases/release-notes-3.6.rst index f4d813432b1..31dcb4c8dcd 100644 --- a/doc/releases/release-notes-3.6.rst +++ b/doc/releases/release-notes-3.6.rst @@ -56,6 +56,7 @@ Bluetooth the transmitted responses on the Access layer. The functionality is enabled by the :kconfig:option:`CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG` Kconfig option. + * The Bluetooth Mesh Protocol 1.1 is now supported by default. * Controller diff --git a/include/zephyr/bluetooth/mesh/main.h b/include/zephyr/bluetooth/mesh/main.h index a213e8ce22c..1622ccebbd8 100644 --- a/include/zephyr/bluetooth/mesh/main.h +++ b/include/zephyr/bluetooth/mesh/main.h @@ -783,7 +783,6 @@ struct bt_mesh_snb { uint64_t auth_val; }; -#if defined(CONFIG_BT_MESH_V1d1) struct bt_mesh_prb { /** Random */ uint8_t random[13]; @@ -797,7 +796,6 @@ struct bt_mesh_prb { /** Authentication tag */ uint64_t auth_tag; }; -#endif /** Beacon callback functions. */ struct bt_mesh_beacon_cb { @@ -810,7 +808,6 @@ struct bt_mesh_beacon_cb { */ void (*snb_received)(const struct bt_mesh_snb *snb); -#if defined(CONFIG_BT_MESH_V1d1) /** @brief Private Beacon received. * * This callback notifies the application that Private Beacon @@ -819,7 +816,6 @@ struct bt_mesh_beacon_cb { * @param prb Structure describing received Private Beacon */ void (*priv_received)(const struct bt_mesh_prb *prb); -#endif }; /** diff --git a/subsys/bluetooth/mesh/CMakeLists.txt b/subsys/bluetooth/mesh/CMakeLists.txt index fe4444b28ab..5d4f41ce7f7 100644 --- a/subsys/bluetooth/mesh/CMakeLists.txt +++ b/subsys/bluetooth/mesh/CMakeLists.txt @@ -18,14 +18,9 @@ zephyr_library_sources_ifdef(CONFIG_BT_MESH cfg_srv.c health_srv.c va.c + transport.c ) -if (CONFIG_BT_MESH_V1d1) - zephyr_library_sources(transport.c) -else() - zephyr_library_sources(transport_legacy.c) -endif() - zephyr_library_sources_ifdef(CONFIG_BT_MESH_ADV_LEGACY adv_legacy.c) zephyr_library_sources_ifdef(CONFIG_BT_MESH_ADV_EXT adv_ext.c) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 555aac45bc0..0f38a2e3ba0 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -512,56 +512,6 @@ config BT_MESH_TX_SEG_MAX which leaves 56 bytes for application layer data using a 4-byte MIC and 52 bytes using an 8-byte MIC. -if !BT_MESH_V1d1 - -config BT_MESH_TX_SEG_RETRANS_COUNT - int "Transport message segment retransmit attempts" - default 4 - range 1 8 - help - Maximum number of transport message segment retransmit attempts - for outgoing segment message. - -config BT_MESH_TX_SEG_RETRANS_TIMEOUT_UNICAST - int "Transport message segment retransmit interval for unicast messages" - default 400 - range 200 500 - help - Maximum time of retransmit segment message to unicast address. - -config BT_MESH_TX_SEG_RETRANS_TIMEOUT_GROUP - int "Transport message segment retransmit interval for group messages" - default 50 - range 20 200 - help - Maximum time of retransmit segment message to group address. - -config BT_MESH_SEG_ACK_BASE_TIMEOUT - int "SegAck transmission base timeout" - default 150 - range 150 400 - help - Defines a base timeout for the acknowledgment timer used to delay - transmission of the Segmented Acknowledgment message. - -config BT_MESH_SEG_ACK_PER_HOP_TIMEOUT - int "SegAck transmission timeout per hop" - default 50 - range 50 250 - help - Defines an additional per-hop timeout for the acknowledgment timer - used to delay transmission of the Segmented Acknowledgment message. - -config BT_MESH_SEG_ACK_PER_SEGMENT_TIMEOUT - int "SegAck transmission timeout per segment not yet received" - default 0 - range 0 100 - help - Defines an additional timeout for the acknowledgment timer for every - segment not yet received. - -endif # !BT_MESH_V1d1 - endmenu # Transport SAR configuration config BT_MESH_DEFAULT_TTL @@ -1112,21 +1062,13 @@ config BT_MESH_FRIEND_ADV_LATENCY endif # BT_MESH_FRIEND -menuconfig BT_MESH_V1d1 - bool "Bluetooth Mesh v1.1 support" - help - This option enables Bluetooth Mesh v1.1 support. Bluetooth Mesh v1.1 - is backward compatible with v1.0.1. - config BT_MESH_ECDH_P256_CMAC_AES128_AES_CCM - bool "Support CMAC AES128 for OOB authentication" if BT_MESH_V1d1 + bool "Support CMAC AES128 for OOB authentication" depends on BT_MESH_PROV default y help Enable this option to support CMAC AES128 for OOB authentication. -if BT_MESH_V1d1 - config BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM bool "Support HMAC SHA256 for OOB authentication" depends on BT_MESH_PROV @@ -1696,8 +1638,6 @@ config BT_MESH_SAR_RX_ACK_RETRANS_COUNT endmenu -endif # BT_MESH_V1d1 - menu "Capabilities" config BT_MESH_SUBNET_COUNT diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 23fbb8e82c2..4ff80333187 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -2380,7 +2380,6 @@ size_t bt_mesh_comp_page_size(uint8_t page) int bt_mesh_comp_store(void) { -#if IS_ENABLED(CONFIG_BT_MESH_V1d1) NET_BUF_SIMPLE_DEFINE(buf, CONFIG_BT_MESH_COMP_PST_BUF_SIZE); int err; @@ -2410,7 +2409,7 @@ int bt_mesh_comp_store(void) LOG_DBG("Stored CDP%d", comp_data_pages[i].page); } -#endif + return 0; } diff --git a/subsys/bluetooth/mesh/beacon.c b/subsys/bluetooth/mesh/beacon.c index ef337f9f510..6eb2c9be3a7 100644 --- a/subsys/bluetooth/mesh/beacon.c +++ b/subsys/bluetooth/mesh/beacon.c @@ -528,7 +528,6 @@ static bool secure_beacon_authenticate(struct bt_mesh_subnet *sub, void *cb_data return false; } -#if defined(CONFIG_BT_MESH_V1d1) static bool priv_beacon_decrypt(struct bt_mesh_subnet *sub, void *cb_data) { struct beacon_params *params = cb_data; @@ -567,7 +566,6 @@ static bool priv_beacon_decrypt(struct bt_mesh_subnet *sub, void *cb_data) return false; } -#endif static void net_beacon_register(struct bt_mesh_beacon *beacon, bool priv) { @@ -658,7 +656,6 @@ static void secure_beacon_recv(struct net_buf_simple *buf) net_beacon_resolve(¶ms, secure_beacon_authenticate); } -#if defined(CONFIG_BT_MESH_V1d1) static void private_beacon_recv(struct net_buf_simple *buf) { struct beacon_params params; @@ -675,7 +672,6 @@ static void private_beacon_recv(struct net_buf_simple *buf) net_beacon_resolve(¶ms, priv_beacon_decrypt); } -#endif void bt_mesh_beacon_recv(struct net_buf_simple *buf) { @@ -699,9 +695,7 @@ void bt_mesh_beacon_recv(struct net_buf_simple *buf) secure_beacon_recv(buf); break; case BEACON_TYPE_PRIVATE: -#if defined(CONFIG_BT_MESH_V1d1) private_beacon_recv(buf); -#endif break; default: LOG_WRN("Unknown beacon type 0x%02x", type); diff --git a/subsys/bluetooth/mesh/net.c b/subsys/bluetooth/mesh/net.c index 943a5e83c23..07c6f1aa18a 100644 --- a/subsys/bluetooth/mesh/net.c +++ b/subsys/bluetooth/mesh/net.c @@ -35,10 +35,7 @@ #include "prov.h" #include "cfg.h" #include "statistic.h" - -#ifdef CONFIG_BT_MESH_V1d1 #include "sar_cfg_internal.h" -#endif #define LOG_LEVEL CONFIG_BT_MESH_NET_LOG_LEVEL #include @@ -84,10 +81,8 @@ static uint16_t msg_cache_next; /* Singleton network context (the implementation only supports one) */ struct bt_mesh_net bt_mesh = { .local_queue = SYS_SLIST_STATIC_INIT(&bt_mesh.local_queue), -#ifdef CONFIG_BT_MESH_V1d1 .sar_tx = BT_MESH_SAR_TX_INIT, .sar_rx = BT_MESH_SAR_RX_INIT, -#endif #if defined(CONFIG_BT_MESH_PRIV_BEACONS) .priv_beacon_int = 0x3c, diff --git a/subsys/bluetooth/mesh/subnet.h b/subsys/bluetooth/mesh/subnet.h index f19b1d2abea..e04f9855b66 100644 --- a/subsys/bluetooth/mesh/subnet.h +++ b/subsys/bluetooth/mesh/subnet.h @@ -76,9 +76,7 @@ struct bt_mesh_subnet { struct bt_mesh_key identity; /* IdentityKey */ #endif struct bt_mesh_key beacon; /* BeaconKey */ -#if defined(CONFIG_BT_MESH_V1d1) struct bt_mesh_key priv_beacon; /* PrivateBeaconKey */ -#endif } keys[2]; #if defined(CONFIG_BT_MESH_PROXY_SOLICITATION) bool sol_tx; diff --git a/subsys/bluetooth/mesh/transport_legacy.c b/subsys/bluetooth/mesh/transport_legacy.c deleted file mode 100644 index 1a826db4ac4..00000000000 --- a/subsys/bluetooth/mesh/transport_legacy.c +++ /dev/null @@ -1,1656 +0,0 @@ -/* - * Copyright (c) 2017 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include "common/bt_str.h" - -#include "host/testing.h" - -#include "crypto.h" -#include "mesh.h" -#include "net.h" -#include "app_keys.h" -#include "lpn.h" -#include "rpl.h" -#include "friend.h" -#include "access.h" -#include "foundation.h" -#include "settings.h" -#include "heartbeat.h" -#include "transport.h" -#include "va.h" - -#define LOG_LEVEL CONFIG_BT_MESH_TRANS_LOG_LEVEL -#include -LOG_MODULE_REGISTER(bt_mesh_transport); - -#define AID_MASK ((uint8_t)(BIT_MASK(6))) - -#define SEG(data) ((data)[0] >> 7) -#define AKF(data) (((data)[0] >> 6) & 0x01) -#define AID(data) ((data)[0] & AID_MASK) -#define ASZMIC(data) (((data)[1] >> 7) & 1) - -#define APP_MIC_LEN(aszmic) ((aszmic) ? BT_MESH_MIC_LONG : BT_MESH_MIC_SHORT) - -#define UNSEG_HDR(akf, aid) ((akf << 6) | (aid & AID_MASK)) -#define SEG_HDR(akf, aid) (UNSEG_HDR(akf, aid) | 0x80) - -#define BLOCK_COMPLETE(seg_n) (uint32_t)(((uint64_t)1 << (seg_n + 1)) - 1) - -#define SEQ_AUTH(iv_index, seq) (((uint64_t)iv_index) << 24 | (uint64_t)seq) - -/* Number of retransmit attempts (after the initial transmit) per segment */ -#define SEG_RETRANSMIT_ATTEMPTS CONFIG_BT_MESH_TX_SEG_RETRANS_COUNT - -/* "This timer shall be set to a minimum of 200 + 50 * TTL milliseconds.". - * We use 400 since 300 is a common send duration for standard HCI, and we - * need to have a timeout that's bigger than that. - */ -#define SEG_RETRANSMIT_TIMEOUT_UNICAST(tx) \ - (CONFIG_BT_MESH_TX_SEG_RETRANS_TIMEOUT_UNICAST + 50 * (tx)->ttl) - -/* When sending to a group, the messages are not acknowledged, and there's no - * reason to delay the repetitions significantly. Delaying by more than 0 ms - * to avoid flooding the network. - */ -#define SEG_RETRANSMIT_TIMEOUT_GROUP CONFIG_BT_MESH_TX_SEG_RETRANS_TIMEOUT_GROUP - -#define SEG_RETRANSMIT_TIMEOUT(tx) \ - (BT_MESH_ADDR_IS_UNICAST(tx->dst) ? \ - SEG_RETRANSMIT_TIMEOUT_UNICAST(tx) : \ - SEG_RETRANSMIT_TIMEOUT_GROUP) -/* How long to wait for available buffers before giving up */ -#define BUF_TIMEOUT K_NO_WAIT - -static struct seg_tx { - struct bt_mesh_subnet *sub; - void *seg[BT_MESH_TX_SEG_MAX]; - uint64_t seq_auth; - uint16_t src; - uint16_t dst; - uint16_t ack_src; - uint16_t len; - uint8_t hdr; - uint8_t xmit; - uint8_t seg_n; /* Last segment index */ - uint8_t seg_o; /* Segment being sent */ - uint8_t nack_count; /* Number of unacked segs */ - uint8_t attempts; /* Remaining tx attempts */ - uint8_t ttl; /* Transmitted TTL value */ - uint8_t blocked:1, /* Blocked by ongoing tx */ - ctl:1, /* Control packet */ - aszmic:1, /* MIC size */ - started:1, /* Start cb called */ - friend_cred:1, /* Using Friend credentials */ - seg_send_started:1; /* Used to check if seg_send_start cb is called */ - const struct bt_mesh_send_cb *cb; - void *cb_data; - struct k_work_delayable retransmit; /* Retransmit timer */ -} seg_tx[CONFIG_BT_MESH_TX_SEG_MSG_COUNT]; - -static struct seg_rx { - struct bt_mesh_subnet *sub; - void *seg[BT_MESH_RX_SEG_MAX]; - uint64_t seq_auth; - uint16_t src; - uint16_t dst; - uint16_t len; - uint8_t hdr; - uint8_t seg_n:5, - ctl:1, - in_use:1, - obo:1; - uint8_t ttl; - uint32_t block; - uint32_t last; - struct k_work_delayable ack; -} seg_rx[CONFIG_BT_MESH_RX_SEG_MSG_COUNT]; - -K_MEM_SLAB_DEFINE(segs, BT_MESH_APP_SEG_SDU_MAX, CONFIG_BT_MESH_SEG_BUFS, 4); - -static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, - const struct bt_mesh_send_cb *cb, void *cb_data, - const uint8_t *ctl_op) -{ - struct bt_mesh_adv *adv; - - adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, - tx->xmit, BUF_TIMEOUT); - if (!adv) { - LOG_ERR("Out of network advs"); - return -ENOBUFS; - } - - net_buf_simple_reserve(&adv->b, BT_MESH_NET_HDR_LEN); - - if (ctl_op) { - net_buf_simple_add_u8(&adv->b, TRANS_CTL_HDR(*ctl_op, 0)); - } else if (BT_MESH_IS_DEV_KEY(tx->ctx->app_idx)) { - net_buf_simple_add_u8(&adv->b, UNSEG_HDR(0, 0)); - } else { - net_buf_simple_add_u8(&adv->b, UNSEG_HDR(1, tx->aid)); - } - - net_buf_simple_add_mem(&adv->b, sdu->data, sdu->len); - - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { - if (!bt_mesh_friend_queue_has_space(tx->sub->net_idx, - tx->src, tx->ctx->addr, - NULL, 1)) { - if (BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { - LOG_ERR("Not enough space in Friend Queue"); - bt_mesh_adv_unref(adv); - return -ENOBUFS; - } - - LOG_WRN("No space in Friend Queue"); - goto send; - } - - if (bt_mesh_friend_enqueue_tx(tx, BT_MESH_FRIEND_PDU_SINGLE, - NULL, 1, &adv->b) && - BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { - /* PDUs for a specific Friend should only go - * out through the Friend Queue. - */ - bt_mesh_adv_unref(adv); - send_cb_finalize(cb, cb_data); - return 0; - } - } - -send: - return bt_mesh_net_send(tx, adv, cb, cb_data); -} - -static inline uint8_t seg_len(bool ctl) -{ - if (ctl) { - return BT_MESH_CTL_SEG_SDU_MAX; - } else { - return BT_MESH_APP_SEG_SDU_MAX; - } -} - -bool bt_mesh_tx_in_progress(void) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(seg_tx); i++) { - if (seg_tx[i].nack_count) { - return true; - } - } - - return false; -} - -static void seg_tx_done(struct seg_tx *tx, uint8_t seg_idx) -{ - k_mem_slab_free(&segs, (void *)tx->seg[seg_idx]); - tx->seg[seg_idx] = NULL; - tx->nack_count--; -} - -static bool seg_tx_blocks(struct seg_tx *tx, uint16_t src, uint16_t dst) -{ - return (tx->src == src) && (tx->dst == dst); -} - -static void seg_tx_unblock_check(struct seg_tx *tx) -{ - struct seg_tx *blocked = NULL; - int i; - - /* Unblock the first blocked tx with the same params. */ - for (i = 0; i < ARRAY_SIZE(seg_tx); ++i) { - if (&seg_tx[i] != tx && - seg_tx[i].blocked && - seg_tx_blocks(tx, seg_tx[i].src, seg_tx[i].dst) && - (!blocked || seg_tx[i].seq_auth < blocked->seq_auth)) { - blocked = &seg_tx[i]; - } - } - - if (blocked) { - LOG_DBG("Unblocked 0x%04x", (uint16_t)(blocked->seq_auth & TRANS_SEQ_ZERO_MASK)); - blocked->blocked = false; - k_work_reschedule(&blocked->retransmit, K_NO_WAIT); - } -} - -static void seg_tx_reset(struct seg_tx *tx) -{ - int i; - - /* If this call fails, the handler will exit early, as nack_count is 0. */ - (void)k_work_cancel_delayable(&tx->retransmit); - - tx->cb = NULL; - tx->cb_data = NULL; - tx->seq_auth = 0U; - tx->sub = NULL; - tx->src = BT_MESH_ADDR_UNASSIGNED; - tx->dst = BT_MESH_ADDR_UNASSIGNED; - tx->ack_src = BT_MESH_ADDR_UNASSIGNED; - tx->blocked = false; - - for (i = 0; i <= tx->seg_n && tx->nack_count; i++) { - if (!tx->seg[i]) { - continue; - } - - seg_tx_done(tx, i); - } - - tx->nack_count = 0; - tx->seg_send_started = 0; - - if (atomic_test_and_clear_bit(bt_mesh.flags, BT_MESH_IVU_PENDING)) { - LOG_DBG("Proceeding with pending IV Update"); - /* bt_mesh_net_iv_update() will re-enable the flag if this - * wasn't the only transfer. - */ - bt_mesh_net_iv_update(bt_mesh.iv_index, false); - } -} - -static inline void seg_tx_complete(struct seg_tx *tx, int err) -{ - const struct bt_mesh_send_cb *cb = tx->cb; - void *cb_data = tx->cb_data; - - seg_tx_unblock_check(tx); - - seg_tx_reset(tx); - - if (cb && cb->end) { - cb->end(err, cb_data); - } -} - -static void schedule_retransmit(struct seg_tx *tx) -{ - if (!tx->nack_count) { - return; - } - - LOG_DBG(""); - - /* If we haven't gone through all the segments for this attempt yet, - * (likely because of a buffer allocation failure or because we - * called this from inside bt_mesh_net_send), we should continue the - * retransmit immediately, as we just freed up a tx buffer. - */ - k_work_reschedule(&tx->retransmit, K_NO_WAIT); -} - -static void seg_send_start(uint16_t duration, int err, void *user_data) -{ - struct seg_tx *tx = user_data; - - if (!tx->started && tx->cb && tx->cb->start) { - tx->cb->start(duration, err, tx->cb_data); - tx->started = 1U; - } - - tx->seg_send_started = 1U; - - /* If there's an error in transmitting the 'sent' callback will never - * be called. Make sure that we kick the retransmit timer also in this - * case since otherwise we risk the transmission of becoming stale. - */ - if (err) { - schedule_retransmit(tx); - } -} - -static void seg_sent(int err, void *user_data) -{ - struct seg_tx *tx = user_data; - - if (!tx->seg_send_started) { - return; - } - - schedule_retransmit(tx); -} - -static const struct bt_mesh_send_cb seg_sent_cb = { - .start = seg_send_start, - .end = seg_sent, -}; - -static void seg_tx_buf_build(struct seg_tx *tx, uint8_t seg_o, - struct net_buf_simple *buf) -{ - uint16_t seq_zero = tx->seq_auth & TRANS_SEQ_ZERO_MASK; - uint8_t len = MIN(seg_len(tx->ctl), tx->len - (seg_len(tx->ctl) * seg_o)); - - net_buf_simple_add_u8(buf, tx->hdr); - net_buf_simple_add_u8(buf, (tx->aszmic << 7) | seq_zero >> 6); - net_buf_simple_add_u8(buf, (((seq_zero & 0x3f) << 2) | (seg_o >> 3))); - net_buf_simple_add_u8(buf, ((seg_o & 0x07) << 5) | tx->seg_n); - net_buf_simple_add_mem(buf, tx->seg[seg_o], len); -} - -static void seg_tx_send_unacked(struct seg_tx *tx) -{ - if (!tx->nack_count) { - return; - } - - struct bt_mesh_msg_ctx ctx = { - .net_idx = tx->sub->net_idx, - /* App idx only used by network to detect control messages: */ - .app_idx = (tx->ctl ? BT_MESH_KEY_UNUSED : 0), - .addr = tx->dst, - .send_rel = true, - .send_ttl = tx->ttl, - }; - struct bt_mesh_net_tx net_tx = { - .sub = tx->sub, - .ctx = &ctx, - .src = tx->src, - .xmit = tx->xmit, - .friend_cred = tx->friend_cred, - .aid = tx->hdr & AID_MASK, - }; - - if (!tx->attempts) { - if (BT_MESH_ADDR_IS_UNICAST(tx->dst)) { - LOG_ERR("Ran out of retransmit attempts"); - seg_tx_complete(tx, -ETIMEDOUT); - } else { - /* Segmented sending to groups doesn't have acks, so - * running out of attempts is the expected behavior. - */ - seg_tx_complete(tx, 0); - } - - return; - } - - LOG_DBG("SeqZero: 0x%04x Attempts: %u", (uint16_t)(tx->seq_auth & TRANS_SEQ_ZERO_MASK), - tx->attempts); - - while (tx->seg_o <= tx->seg_n) { - struct bt_mesh_adv *seg; - int err; - - if (!tx->seg[tx->seg_o]) { - /* Move on to the next segment */ - tx->seg_o++; - continue; - } - - seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, - tx->xmit, BUF_TIMEOUT); - if (!seg) { - LOG_DBG("Allocating segment failed"); - goto end; - } - - net_buf_simple_reserve(&seg->b, BT_MESH_NET_HDR_LEN); - seg_tx_buf_build(tx, tx->seg_o, &seg->b); - - LOG_DBG("Sending %u/%u", tx->seg_o, tx->seg_n); - - err = bt_mesh_net_send(&net_tx, seg, &seg_sent_cb, tx); - if (err) { - LOG_DBG("Sending segment failed"); - goto end; - } - - /* Move on to the next segment */ - tx->seg_o++; - - return; - } - - tx->seg_o = 0U; - tx->attempts--; - -end: - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) && - bt_mesh_lpn_established() && !bt_mesh_has_addr(ctx.addr)) { - bt_mesh_lpn_poll(); - } - - k_work_reschedule(&tx->retransmit, K_MSEC(SEG_RETRANSMIT_TIMEOUT(tx))); -} - -static void seg_retransmit(struct k_work *work) -{ - struct k_work_delayable *dwork = k_work_delayable_from_work(work); - struct seg_tx *tx = CONTAINER_OF(dwork, struct seg_tx, retransmit); - - seg_tx_send_unacked(tx); -} - -static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, - const struct bt_mesh_send_cb *cb, void *cb_data, - uint8_t *ctl_op) -{ - bool blocked = false; - struct seg_tx *tx; - uint8_t seg_o; - int i; - - LOG_DBG("src 0x%04x dst 0x%04x app_idx 0x%04x aszmic %u sdu_len %u", net_tx->src, - net_tx->ctx->addr, net_tx->ctx->app_idx, net_tx->aszmic, sdu->len); - - for (tx = NULL, i = 0; i < ARRAY_SIZE(seg_tx); i++) { - if (seg_tx[i].nack_count) { - blocked |= seg_tx_blocks(&seg_tx[i], net_tx->src, - net_tx->ctx->addr); - } else if (!tx) { - tx = &seg_tx[i]; - } - } - - if (!tx) { - LOG_ERR("No multi-segment message contexts available"); - return -EBUSY; - } - - if (ctl_op) { - tx->hdr = TRANS_CTL_HDR(*ctl_op, 1); - } else if (BT_MESH_IS_DEV_KEY(net_tx->ctx->app_idx)) { - tx->hdr = SEG_HDR(0, 0); - } else { - tx->hdr = SEG_HDR(1, net_tx->aid); - } - - tx->src = net_tx->src; - tx->dst = net_tx->ctx->addr; - tx->seg_n = (sdu->len - 1) / seg_len(!!ctl_op); - tx->seg_o = 0; - tx->len = sdu->len; - tx->nack_count = tx->seg_n + 1; - tx->seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_TX, bt_mesh.seq); - tx->sub = net_tx->sub; - tx->cb = cb; - tx->cb_data = cb_data; - tx->attempts = SEG_RETRANSMIT_ATTEMPTS; - tx->xmit = net_tx->xmit; - tx->aszmic = net_tx->aszmic; - tx->friend_cred = net_tx->friend_cred; - tx->blocked = blocked; - tx->started = 0; - tx->seg_send_started = 0; - tx->ctl = !!ctl_op; - tx->ttl = net_tx->ctx->send_ttl; - - LOG_DBG("SeqZero 0x%04x (segs: %u)", (uint16_t)(tx->seq_auth & TRANS_SEQ_ZERO_MASK), - tx->nack_count); - - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && - !bt_mesh_friend_queue_has_space(tx->sub->net_idx, net_tx->src, - tx->dst, &tx->seq_auth, - tx->seg_n + 1) && - BT_MESH_ADDR_IS_UNICAST(tx->dst)) { - LOG_ERR("Not enough space in Friend Queue for %u segments", tx->seg_n + 1); - seg_tx_reset(tx); - return -ENOBUFS; - } - - for (seg_o = 0U; sdu->len; seg_o++) { - void *buf; - uint16_t len; - int err; - - err = k_mem_slab_alloc(&segs, &buf, BUF_TIMEOUT); - if (err) { - LOG_ERR("Out of segment buffers"); - seg_tx_reset(tx); - return -ENOBUFS; - } - - len = MIN(sdu->len, seg_len(!!ctl_op)); - memcpy(buf, net_buf_simple_pull_mem(sdu, len), len); - - LOG_DBG("seg %u: %s", seg_o, bt_hex(buf, len)); - - tx->seg[seg_o] = buf; - - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { - enum bt_mesh_friend_pdu_type type; - - NET_BUF_SIMPLE_DEFINE(seg, 16); - seg_tx_buf_build(tx, seg_o, &seg); - - if (seg_o == tx->seg_n) { - type = BT_MESH_FRIEND_PDU_COMPLETE; - } else { - type = BT_MESH_FRIEND_PDU_PARTIAL; - } - - if (bt_mesh_friend_enqueue_tx( - net_tx, type, ctl_op ? NULL : &tx->seq_auth, - tx->seg_n + 1, &seg) && - BT_MESH_ADDR_IS_UNICAST(net_tx->ctx->addr)) { - /* PDUs for a specific Friend should only go - * out through the Friend Queue. - */ - k_mem_slab_free(&segs, buf); - tx->seg[seg_o] = NULL; - } - - } - - } - - /* This can happen if segments only went into the Friend Queue */ - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && !tx->seg[0]) { - seg_tx_reset(tx); - - /* If there was a callback notify sending immediately since - * there's no other way to track this (at least currently) - * with the Friend Queue. - */ - send_cb_finalize(cb, cb_data); - return 0; - } - - if (blocked) { - /* Move the sequence number, so we don't end up creating - * another segmented transmission with the same SeqZero while - * this one is blocked. - */ - bt_mesh_next_seq(); - LOG_DBG("Blocked."); - return 0; - } - - seg_tx_send_unacked(tx); - - return 0; -} - -static int trans_encrypt(const struct bt_mesh_net_tx *tx, const struct bt_mesh_key *key, - struct net_buf_simple *msg) -{ - struct bt_mesh_app_crypto_ctx crypto = { - .dev_key = BT_MESH_IS_DEV_KEY(tx->ctx->app_idx), - .aszmic = tx->aszmic, - .src = tx->src, - .dst = tx->ctx->addr, - .seq_num = bt_mesh.seq, - .iv_index = BT_MESH_NET_IVI_TX, - }; - - if (BT_MESH_ADDR_IS_VIRTUAL(tx->ctx->addr)) { - crypto.ad = tx->ctx->uuid; - if (crypto.ad == NULL) { - return -ENOENT; - } - } - - return bt_mesh_app_encrypt(key, &crypto, msg); -} - -int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, - const struct bt_mesh_send_cb *cb, void *cb_data) -{ - const struct bt_mesh_key *key; - uint8_t aid; - int err; - - if (msg->len < 1) { - LOG_ERR("Zero-length SDU not allowed"); - return -EINVAL; - } - - if (msg->len > BT_MESH_TX_SDU_MAX - BT_MESH_MIC_SHORT) { - LOG_ERR("Message too big: %u", msg->len); - return -EMSGSIZE; - } - - if (net_buf_simple_tailroom(msg) < BT_MESH_MIC_SHORT) { - LOG_ERR("Insufficient tailroom for Transport MIC"); - return -EINVAL; - } - - if (tx->ctx->send_ttl == BT_MESH_TTL_DEFAULT) { - tx->ctx->send_ttl = bt_mesh_default_ttl_get(); - } else if (tx->ctx->send_ttl > BT_MESH_TTL_MAX) { - LOG_ERR("TTL too large (max 127)"); - return -EINVAL; - } - - if (msg->len > BT_MESH_SDU_UNSEG_MAX) { - tx->ctx->send_rel = true; - } - - if (tx->ctx->addr == BT_MESH_ADDR_UNASSIGNED || - (!BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr) && - BT_MESH_IS_DEV_KEY(tx->ctx->app_idx))) { - LOG_ERR("Invalid destination address"); - return -EINVAL; - } - - err = bt_mesh_keys_resolve(tx->ctx, &tx->sub, &key, &aid); - if (err) { - return err; - } - - LOG_DBG("net_idx 0x%04x app_idx 0x%04x dst 0x%04x", tx->sub->net_idx, tx->ctx->app_idx, - tx->ctx->addr); - LOG_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len)); - - tx->xmit = bt_mesh_net_transmit_get(); - tx->aid = aid; - - if (!tx->ctx->send_rel || net_buf_simple_tailroom(msg) < 8) { - tx->aszmic = 0U; - } else { - tx->aszmic = 1U; - } - - err = trans_encrypt(tx, key, msg); - if (err) { - return err; - } - - if (tx->ctx->send_rel) { - err = send_seg(tx, msg, cb, cb_data, NULL); - } else { - err = send_unseg(tx, msg, cb, cb_data, NULL); - } - - return err; -} - -static void seg_rx_assemble(struct seg_rx *rx, struct net_buf_simple *buf, - uint8_t aszmic) -{ - int i; - - net_buf_simple_reset(buf); - - for (i = 0; i <= rx->seg_n; i++) { - net_buf_simple_add_mem(buf, rx->seg[i], - MIN(seg_len(rx->ctl), - rx->len - (i * seg_len(rx->ctl)))); - } - - /* Adjust the length to not contain the MIC at the end */ - if (!rx->ctl) { - buf->len -= APP_MIC_LEN(aszmic); - } -} - -struct decrypt_ctx { - struct bt_mesh_app_crypto_ctx crypto; - struct net_buf_simple *buf; - struct net_buf_simple *sdu; - struct seg_rx *seg; -}; - -static int sdu_try_decrypt(struct bt_mesh_net_rx *rx, const struct bt_mesh_key *key, - void *cb_data) -{ - struct decrypt_ctx *ctx = cb_data; - int err; - - ctx->crypto.ad = NULL; - - do { - if (ctx->seg) { - seg_rx_assemble(ctx->seg, ctx->buf, ctx->crypto.aszmic); - } - - if (BT_MESH_ADDR_IS_VIRTUAL(rx->ctx.recv_dst)) { - ctx->crypto.ad = bt_mesh_va_uuid_get(rx->ctx.recv_dst, ctx->crypto.ad, - NULL); - - if (!ctx->crypto.ad) { - return -ENOENT; - } - } - - net_buf_simple_reset(ctx->sdu); - - err = bt_mesh_app_decrypt(key, &ctx->crypto, ctx->buf, ctx->sdu); - } while (err && ctx->crypto.ad != NULL); - - if (!err && BT_MESH_ADDR_IS_VIRTUAL(rx->ctx.recv_dst)) { - rx->ctx.uuid = ctx->crypto.ad; - } - - return err; -} - -static int sdu_recv(struct bt_mesh_net_rx *rx, uint8_t hdr, uint8_t aszmic, - struct net_buf_simple *buf, struct net_buf_simple *sdu, - struct seg_rx *seg) -{ - struct decrypt_ctx ctx = { - .crypto = { - .dev_key = !AKF(&hdr), - .aszmic = aszmic, - .src = rx->ctx.addr, - .dst = rx->ctx.recv_dst, - .seq_num = seg ? (seg->seq_auth & 0xffffff) : rx->seq, - .iv_index = BT_MESH_NET_IVI_RX(rx), - }, - .buf = buf, - .sdu = sdu, - .seg = seg, - }; - - LOG_DBG("AKF %u AID 0x%02x", !ctx.crypto.dev_key, AID(&hdr)); - - if (!rx->local_match) { - return 0; - } - - rx->ctx.app_idx = bt_mesh_app_key_find(ctx.crypto.dev_key, AID(&hdr), - rx, sdu_try_decrypt, &ctx); - if (rx->ctx.app_idx == BT_MESH_KEY_UNUSED) { - LOG_DBG("No matching AppKey"); - return 0; - } - - LOG_DBG("Decrypted (AppIdx: 0x%03x)", rx->ctx.app_idx); - - bt_mesh_model_recv(&rx->ctx, sdu); - - return 0; -} - -static struct seg_tx *seg_tx_lookup(uint16_t seq_zero, uint8_t obo, uint16_t addr) -{ - struct seg_tx *tx; - int i; - - for (i = 0; i < ARRAY_SIZE(seg_tx); i++) { - tx = &seg_tx[i]; - - if ((tx->seq_auth & TRANS_SEQ_ZERO_MASK) != seq_zero) { - continue; - } - - if (tx->dst == addr) { - return tx; - } - - /* If the expected remote address doesn't match, - * but the OBO flag is set and this is the first - * acknowledgment, assume it's a Friend that's - * responding and therefore accept the message. - */ - if (obo && (tx->nack_count == tx->seg_n + 1 || tx->ack_src == addr)) { - tx->ack_src = addr; - return tx; - } - } - - return NULL; -} - -static int trans_ack(struct bt_mesh_net_rx *rx, uint8_t hdr, - struct net_buf_simple *buf, uint64_t *seq_auth) -{ - struct seg_tx *tx; - unsigned int bit; - uint32_t ack; - uint16_t seq_zero; - uint8_t obo; - - if (buf->len < 6) { - LOG_ERR("Too short ack message"); - return -EINVAL; - } - - seq_zero = net_buf_simple_pull_be16(buf); - obo = seq_zero >> 15; - seq_zero = (seq_zero >> 2) & TRANS_SEQ_ZERO_MASK; - - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && rx->friend_match) { - LOG_DBG("Ack for LPN 0x%04x of this Friend", rx->ctx.recv_dst); - /* Best effort - we don't have enough info for true SeqAuth */ - *seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_RX(rx), seq_zero); - return 0; - } - - ack = net_buf_simple_pull_be32(buf); - - LOG_DBG("OBO %u seq_zero 0x%04x ack 0x%08x", obo, seq_zero, ack); - - tx = seg_tx_lookup(seq_zero, obo, rx->ctx.addr); - if (!tx) { - LOG_WRN("No matching TX context for ack"); - return -EINVAL; - } - - if (!BT_MESH_ADDR_IS_UNICAST(tx->dst)) { - LOG_ERR("Received ack for group seg"); - return -EINVAL; - } - - *seq_auth = tx->seq_auth; - - if (!ack) { - LOG_WRN("SDU canceled"); - seg_tx_complete(tx, -ECANCELED); - return 0; - } - - if (find_msb_set(ack) - 1 > tx->seg_n) { - LOG_ERR("Too large segment number in ack"); - return -EINVAL; - } - - while ((bit = find_lsb_set(ack))) { - if (tx->seg[bit - 1]) { - LOG_DBG("seg %u/%u acked", bit - 1, tx->seg_n); - seg_tx_done(tx, bit - 1); - } - - ack &= ~BIT(bit - 1); - } - - if (tx->nack_count) { - /* According to MshPRFv1.0.1: 3.5.3.3, we should reset the retransmit timer and - * retransmit immediately when receiving a valid ack message. Don't reset the - * retransmit timer if we didn't finish sending segments. - */ - if (tx->seg_o == 0) { - k_work_reschedule(&tx->retransmit, K_NO_WAIT); - } - } else { - LOG_DBG("SDU TX complete"); - seg_tx_complete(tx, 0); - } - - return 0; -} - -static int ctl_recv(struct bt_mesh_net_rx *rx, uint8_t hdr, - struct net_buf_simple *buf, uint64_t *seq_auth) -{ - uint8_t ctl_op = TRANS_CTL_OP(&hdr); - - LOG_DBG("OpCode 0x%02x len %u", ctl_op, buf->len); - - switch (ctl_op) { - case TRANS_CTL_OP_ACK: - return trans_ack(rx, hdr, buf, seq_auth); - case TRANS_CTL_OP_HEARTBEAT: - return bt_mesh_hb_recv(rx, buf); - } - - /* Only acks and heartbeats may need processing without local_match */ - if (!rx->local_match) { - return 0; - } - - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && !bt_mesh_lpn_established()) { - switch (ctl_op) { - case TRANS_CTL_OP_FRIEND_POLL: - return bt_mesh_friend_poll(rx, buf); - case TRANS_CTL_OP_FRIEND_REQ: - return bt_mesh_friend_req(rx, buf); - case TRANS_CTL_OP_FRIEND_CLEAR: - return bt_mesh_friend_clear(rx, buf); - case TRANS_CTL_OP_FRIEND_CLEAR_CFM: - return bt_mesh_friend_clear_cfm(rx, buf); - case TRANS_CTL_OP_FRIEND_SUB_ADD: - return bt_mesh_friend_sub_add(rx, buf); - case TRANS_CTL_OP_FRIEND_SUB_REM: - return bt_mesh_friend_sub_rem(rx, buf); - } - } - -#if defined(CONFIG_BT_MESH_LOW_POWER) - if (ctl_op == TRANS_CTL_OP_FRIEND_OFFER) { - return bt_mesh_lpn_friend_offer(rx, buf); - } - - if (rx->ctx.addr == bt_mesh.lpn.frnd) { - if (ctl_op == TRANS_CTL_OP_FRIEND_CLEAR_CFM) { - return bt_mesh_lpn_friend_clear_cfm(rx, buf); - } - - if (!rx->friend_cred) { - LOG_WRN("Message from friend with wrong credentials"); - return -EINVAL; - } - - switch (ctl_op) { - case TRANS_CTL_OP_FRIEND_UPDATE: - return bt_mesh_lpn_friend_update(rx, buf); - case TRANS_CTL_OP_FRIEND_SUB_CFM: - return bt_mesh_lpn_friend_sub_cfm(rx, buf); - } - } -#endif /* CONFIG_BT_MESH_LOW_POWER */ - - LOG_WRN("Unhandled TransOpCode 0x%02x", ctl_op); - - return -ENOENT; -} - -static int trans_unseg(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx, - uint64_t *seq_auth) -{ - NET_BUF_SIMPLE_DEFINE_STATIC(sdu, BT_MESH_SDU_UNSEG_MAX); - uint8_t hdr; - - LOG_DBG("AFK %u AID 0x%02x", AKF(buf->data), AID(buf->data)); - - if (buf->len < 1) { - LOG_ERR("Too small unsegmented PDU"); - return -EINVAL; - } - - if (bt_mesh_rpl_check(rx, NULL)) { - LOG_WRN("Replay: src 0x%04x dst 0x%04x seq 0x%06x", rx->ctx.addr, rx->ctx.recv_dst, - rx->seq); - return -EINVAL; - } - - hdr = net_buf_simple_pull_u8(buf); - - if (rx->ctl) { - return ctl_recv(rx, hdr, buf, seq_auth); - } - - if (buf->len < 1 + APP_MIC_LEN(0)) { - LOG_ERR("Too short SDU + MIC"); - return -EINVAL; - } - - /* Adjust the length to not contain the MIC at the end */ - buf->len -= APP_MIC_LEN(0); - - return sdu_recv(rx, hdr, 0, buf, &sdu, NULL); -} - -static inline int32_t ack_timeout(struct seg_rx *rx) -{ - int32_t to; - uint8_t ttl; - - if (rx->ttl == BT_MESH_TTL_DEFAULT) { - ttl = bt_mesh_default_ttl_get(); - } else { - ttl = rx->ttl; - } - - /* The acknowledgment timer shall be set to a minimum of - * 150 + 50 * TTL milliseconds. - */ - to = CONFIG_BT_MESH_SEG_ACK_BASE_TIMEOUT + - (ttl * (int32_t)CONFIG_BT_MESH_SEG_ACK_PER_HOP_TIMEOUT); - - /* Add timeout for evenry not yet received segment. */ - to += ((rx->seg_n + 1) - POPCOUNT(rx->block)) * - (int32_t)CONFIG_BT_MESH_SEG_ACK_PER_SEGMENT_TIMEOUT; - - /* Make sure we don't send more frequently than the duration for - * each packet (default is 400ms). - */ - return MAX(to, 400); -} - -int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, uint8_t ctl_op, void *data, - size_t data_len, - const struct bt_mesh_send_cb *cb, void *cb_data) -{ - struct net_buf_simple buf; - - if (tx->ctx->send_ttl == BT_MESH_TTL_DEFAULT) { - tx->ctx->send_ttl = bt_mesh_default_ttl_get(); - } else if (tx->ctx->send_ttl > BT_MESH_TTL_MAX) { - LOG_ERR("TTL too large (max 127)"); - return -EINVAL; - } - - net_buf_simple_init_with_data(&buf, data, data_len); - - if (data_len > BT_MESH_SDU_UNSEG_MAX) { - tx->ctx->send_rel = true; - } - - tx->ctx->app_idx = BT_MESH_KEY_UNUSED; - - if (tx->ctx->addr == BT_MESH_ADDR_UNASSIGNED || - BT_MESH_ADDR_IS_VIRTUAL(tx->ctx->addr)) { - LOG_ERR("Invalid destination address"); - return -EINVAL; - } - - LOG_DBG("src 0x%04x dst 0x%04x ttl 0x%02x ctl 0x%02x", tx->src, tx->ctx->addr, - tx->ctx->send_ttl, ctl_op); - LOG_DBG("len %zu: %s", data_len, bt_hex(data, data_len)); - - if (tx->ctx->send_rel) { - return send_seg(tx, &buf, cb, cb_data, &ctl_op); - } else { - return send_unseg(tx, &buf, cb, cb_data, &ctl_op); - } -} - -static int send_ack(struct bt_mesh_subnet *sub, uint16_t src, uint16_t dst, - uint8_t ttl, uint64_t *seq_auth, uint32_t block, uint8_t obo) -{ - struct bt_mesh_msg_ctx ctx = { - .net_idx = sub->net_idx, - .app_idx = BT_MESH_KEY_UNUSED, - .addr = dst, - .send_ttl = ttl, - }; - struct bt_mesh_net_tx tx = { - .sub = sub, - .ctx = &ctx, - .src = obo ? bt_mesh_primary_addr() : src, - .xmit = bt_mesh_net_transmit_get(), - }; - uint16_t seq_zero = *seq_auth & TRANS_SEQ_ZERO_MASK; - uint8_t buf[6]; - - LOG_DBG("SeqZero 0x%04x Block 0x%08x OBO %u", seq_zero, block, obo); - - if (bt_mesh_lpn_established() && !bt_mesh_has_addr(ctx.addr)) { - LOG_WRN("Not sending ack when LPN is enabled"); - return 0; - } - - /* This can happen if the segmented message was destined for a group - * or virtual address. - */ - if (!BT_MESH_ADDR_IS_UNICAST(src)) { - LOG_DBG("Not sending ack for non-unicast address"); - return 0; - } - - sys_put_be16(((seq_zero << 2) & 0x7ffc) | (obo << 15), buf); - sys_put_be32(block, &buf[2]); - - return bt_mesh_ctl_send(&tx, TRANS_CTL_OP_ACK, buf, sizeof(buf), - NULL, NULL); -} - -static void seg_rx_reset(struct seg_rx *rx, bool full_reset) -{ - int i; - - LOG_DBG("rx %p", rx); - - /* If this fails, the handler will exit early on the next execution, as - * it checks rx->in_use. - */ - (void)k_work_cancel_delayable(&rx->ack); - - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && rx->obo && - rx->block != BLOCK_COMPLETE(rx->seg_n)) { - LOG_WRN("Clearing incomplete buffers from Friend queue"); - bt_mesh_friend_clear_incomplete(rx->sub, rx->src, rx->dst, - &rx->seq_auth); - } - - for (i = 0; i <= rx->seg_n; i++) { - if (!rx->seg[i]) { - continue; - } - - k_mem_slab_free(&segs, rx->seg[i]); - rx->seg[i] = NULL; - } - - rx->in_use = 0U; - - /* We don't always reset these values since we need to be able to - * send an ack if we receive a segment after we've already received - * the full SDU. - */ - if (full_reset) { - rx->seq_auth = 0U; - rx->sub = NULL; - rx->src = BT_MESH_ADDR_UNASSIGNED; - rx->dst = BT_MESH_ADDR_UNASSIGNED; - } -} - -static void seg_ack(struct k_work *work) -{ - struct k_work_delayable *dwork = k_work_delayable_from_work(work); - struct seg_rx *rx = CONTAINER_OF(dwork, struct seg_rx, ack); - int32_t timeout; - - if (!rx->in_use || rx->block == BLOCK_COMPLETE(rx->seg_n)) { - /* Cancellation of this timer may have failed. If it fails as - * part of seg_reset, in_use will be false. - * If it fails as part of the processing of a fully received - * SDU, the ack is already being sent from the receive handler, - * and the timer based ack sending can be ignored. - */ - return; - } - - LOG_DBG("rx %p", rx); - - if (k_uptime_get_32() - rx->last > (60 * MSEC_PER_SEC)) { - LOG_WRN("Incomplete timer expired"); - seg_rx_reset(rx, false); - - if (IS_ENABLED(CONFIG_BT_TESTING)) { - bt_test_mesh_trans_incomp_timer_exp(); - } - - return; - } - - send_ack(rx->sub, rx->dst, rx->src, rx->ttl, &rx->seq_auth, - rx->block, rx->obo); - - timeout = ack_timeout(rx); - k_work_schedule(&rx->ack, K_MSEC(timeout)); -} - -static inline bool sdu_len_is_ok(bool ctl, uint8_t seg_n) -{ - return (seg_n < BT_MESH_RX_SEG_MAX); -} - -static struct seg_rx *seg_rx_find(struct bt_mesh_net_rx *net_rx, - const uint64_t *seq_auth) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(seg_rx); i++) { - struct seg_rx *rx = &seg_rx[i]; - - if (rx->src != net_rx->ctx.addr || - rx->dst != net_rx->ctx.recv_dst) { - continue; - } - - /* Return newer RX context in addition to an exact match, so - * the calling function can properly discard an old SeqAuth. - */ - if (rx->seq_auth >= *seq_auth) { - return rx; - } - - if (rx->in_use) { - LOG_WRN("Duplicate SDU from src 0x%04x", net_rx->ctx.addr); - - /* Clear out the old context since the sender - * has apparently started sending a new SDU. - */ - seg_rx_reset(rx, true); - - /* Return non-match so caller can re-allocate */ - return NULL; - } - } - - return NULL; -} - -static bool seg_rx_is_valid(struct seg_rx *rx, struct bt_mesh_net_rx *net_rx, - const uint8_t *hdr, uint8_t seg_n) -{ - if (rx->hdr != *hdr || rx->seg_n != seg_n) { - LOG_ERR("Invalid segment for ongoing session"); - return false; - } - - if (rx->src != net_rx->ctx.addr || rx->dst != net_rx->ctx.recv_dst) { - LOG_ERR("Invalid source or destination for segment"); - return false; - } - - if (rx->ctl != net_rx->ctl) { - LOG_ERR("Inconsistent CTL in segment"); - return false; - } - - return true; -} - -static struct seg_rx *seg_rx_alloc(struct bt_mesh_net_rx *net_rx, - const uint8_t *hdr, const uint64_t *seq_auth, - uint8_t seg_n) -{ - int i; - - /* No race condition on this check, as this function only executes in - * the collaborative Bluetooth rx thread: - */ - if (k_mem_slab_num_free_get(&segs) < 1) { - LOG_WRN("Not enough segments for incoming message"); - return NULL; - } - - for (i = 0; i < ARRAY_SIZE(seg_rx); i++) { - struct seg_rx *rx = &seg_rx[i]; - - if (rx->in_use) { - continue; - } - - rx->in_use = 1U; - rx->sub = net_rx->sub; - rx->ctl = net_rx->ctl; - rx->seq_auth = *seq_auth; - rx->seg_n = seg_n; - rx->hdr = *hdr; - rx->ttl = net_rx->ctx.send_ttl; - rx->src = net_rx->ctx.addr; - rx->dst = net_rx->ctx.recv_dst; - rx->block = 0U; - - LOG_DBG("New RX context. Block Complete 0x%08x", BLOCK_COMPLETE(seg_n)); - - return rx; - } - - return NULL; -} - -static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx, - enum bt_mesh_friend_pdu_type *pdu_type, uint64_t *seq_auth, - uint8_t *seg_count) -{ - struct bt_mesh_rpl *rpl = NULL; - struct seg_rx *rx; - uint8_t *hdr = buf->data; - uint16_t seq_zero; - uint32_t auth_seqnum; - uint8_t seg_n; - uint8_t seg_o; - int err; - - if (buf->len < 5) { - LOG_ERR("Too short segmented message (len %u)", buf->len); - return -EINVAL; - } - - if (bt_mesh_rpl_check(net_rx, &rpl)) { - LOG_WRN("Replay: src 0x%04x dst 0x%04x seq 0x%06x", net_rx->ctx.addr, - net_rx->ctx.recv_dst, net_rx->seq); - return -EINVAL; - } - - LOG_DBG("ASZMIC %u AKF %u AID 0x%02x", ASZMIC(hdr), AKF(hdr), AID(hdr)); - - net_buf_simple_pull(buf, 1); - - seq_zero = net_buf_simple_pull_be16(buf); - seg_o = (seq_zero & 0x03) << 3; - seq_zero = (seq_zero >> 2) & TRANS_SEQ_ZERO_MASK; - seg_n = net_buf_simple_pull_u8(buf); - seg_o |= seg_n >> 5; - seg_n &= 0x1f; - - LOG_DBG("SeqZero 0x%04x SegO %u SegN %u", seq_zero, seg_o, seg_n); - - if (seg_o > seg_n) { - LOG_ERR("SegO greater than SegN (%u > %u)", seg_o, seg_n); - return -EINVAL; - } - - /* According to MshPRFv1.0.1: - * "The SeqAuth is composed of the IV Index and the sequence number - * (SEQ) of the first segment" - * - * Therefore we need to calculate very first SEQ in order to find - * seqAuth. We can calculate as below: - * - * SEQ(0) = SEQ(n) - (delta between seqZero and SEQ(n) by looking into - * 14 least significant bits of SEQ(n)) - * - * Mentioned delta shall be >= 0, if it is not then seq_auth will - * be broken and it will be verified by the code below. - */ - *seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_RX(net_rx), - (net_rx->seq - - ((((net_rx->seq & BIT_MASK(14)) - seq_zero)) & - BIT_MASK(13)))); - auth_seqnum = *seq_auth & BIT_MASK(24); - *seg_count = seg_n + 1; - - /* Look for old RX sessions */ - rx = seg_rx_find(net_rx, seq_auth); - if (rx) { - /* Discard old SeqAuth packet */ - if (rx->seq_auth > *seq_auth) { - LOG_WRN("Ignoring old SeqAuth"); - return -EINVAL; - } - - if (!seg_rx_is_valid(rx, net_rx, hdr, seg_n)) { - return -EINVAL; - } - - if (rx->in_use) { - LOG_DBG("Existing RX context. Block 0x%08x", rx->block); - goto found_rx; - } - - if (rx->block == BLOCK_COMPLETE(rx->seg_n)) { - LOG_DBG("Got segment for already complete SDU"); - - send_ack(net_rx->sub, net_rx->ctx.recv_dst, - net_rx->ctx.addr, net_rx->ctx.send_ttl, - seq_auth, rx->block, rx->obo); - - if (rpl) { - bt_mesh_rpl_update(rpl, net_rx); - } - - return -EALREADY; - } - - /* We ignore instead of sending block ack 0 since the - * ack timer is always smaller than the incomplete - * timer, i.e. the sender is misbehaving. - */ - LOG_WRN("Got segment for canceled SDU"); - return -EINVAL; - } - - /* Bail out early if we're not ready to receive such a large SDU */ - if (!sdu_len_is_ok(net_rx->ctl, seg_n)) { - LOG_ERR("Too big incoming SDU length"); - send_ack(net_rx->sub, net_rx->ctx.recv_dst, net_rx->ctx.addr, - net_rx->ctx.send_ttl, seq_auth, 0, - net_rx->friend_match); - return -EMSGSIZE; - } - - /* Verify early that there will be space in the Friend Queue(s) in - * case this message is destined to an LPN of ours. - */ - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && - net_rx->friend_match && !net_rx->local_match && - !bt_mesh_friend_queue_has_space(net_rx->sub->net_idx, - net_rx->ctx.addr, - net_rx->ctx.recv_dst, seq_auth, - *seg_count)) { - LOG_ERR("No space in Friend Queue for %u segments", *seg_count); - send_ack(net_rx->sub, net_rx->ctx.recv_dst, net_rx->ctx.addr, - net_rx->ctx.send_ttl, seq_auth, 0, - net_rx->friend_match); - return -ENOBUFS; - } - - /* Keep track of the received SeqAuth values received from this address - * and discard segmented messages that are not newer, as described in - * MshPRFv1.0.1: 3.5.3.4. - * - * The logic on the first segmented receive is a bit special, since the - * initial value of rpl->seg is 0, which would normally fail the - * comparison check with auth_seqnum: - * - If this is the first time we receive from this source, rpl->src - * will be 0, and we can skip this check. - * - If this is the first time we receive from this source on the new IV - * index, rpl->old_iv will be set, and the check is also skipped. - * - If this is the first segmented message on the new IV index, but we - * have received an unsegmented message already, the unsegmented - * message will have reset rpl->seg to 0, and this message's SeqAuth - * cannot be zero. - */ - if (rpl && rpl->src && auth_seqnum <= rpl->seg && - (!rpl->old_iv || net_rx->old_iv)) { - LOG_WRN("Ignoring old SeqAuth 0x%06x", auth_seqnum); - return -EALREADY; - } - - /* Look for free slot for a new RX session */ - rx = seg_rx_alloc(net_rx, hdr, seq_auth, seg_n); - if (!rx) { - /* Warn but don't cancel since the existing slots will - * eventually be freed up and we'll be able to process - * this one. - */ - LOG_WRN("No free slots for new incoming segmented messages"); - return -ENOMEM; - } - - rx->obo = net_rx->friend_match; - -found_rx: - if (BIT(seg_o) & rx->block) { - LOG_DBG("Received already received fragment"); - return -EALREADY; - } - - /* All segments, except the last one, must either have 8 bytes of - * payload (for 64bit Net MIC) or 12 bytes of payload (for 32bit - * Net MIC). - */ - if (seg_o == seg_n) { - /* Set the expected final buffer length */ - rx->len = seg_n * seg_len(rx->ctl) + buf->len; - LOG_DBG("Target len %u * %u + %u = %u", seg_n, seg_len(rx->ctl), buf->len, rx->len); - - if (rx->len > BT_MESH_RX_SDU_MAX) { - LOG_ERR("Too large SDU len"); - send_ack(net_rx->sub, net_rx->ctx.recv_dst, - net_rx->ctx.addr, net_rx->ctx.send_ttl, - seq_auth, 0, rx->obo); - seg_rx_reset(rx, true); - return -EMSGSIZE; - } - } else { - if (buf->len != seg_len(rx->ctl)) { - LOG_ERR("Incorrect segment size for message type"); - return -EINVAL; - } - } - - /* Reset the Incomplete Timer */ - rx->last = k_uptime_get_32(); - - if (!bt_mesh_lpn_established()) { - int32_t timeout = ack_timeout(rx); - /* Should only start ack timer if it isn't running already: */ - k_work_schedule(&rx->ack, K_MSEC(timeout)); - } - - /* Allocated segment here */ - err = k_mem_slab_alloc(&segs, &rx->seg[seg_o], K_NO_WAIT); - if (err) { - LOG_WRN("Unable allocate buffer for Seg %u", seg_o); - return -ENOBUFS; - } - - memcpy(rx->seg[seg_o], buf->data, buf->len); - - LOG_DBG("Received %u/%u", seg_o, seg_n); - - /* Mark segment as received */ - rx->block |= BIT(seg_o); - - if (rx->block != BLOCK_COMPLETE(seg_n)) { - *pdu_type = BT_MESH_FRIEND_PDU_PARTIAL; - return 0; - } - - LOG_DBG("Complete SDU"); - - if (rpl) { - bt_mesh_rpl_update(rpl, net_rx); - /* Update the seg, unless it has already been surpassed: - * This needs to happen after rpl_update to ensure that the IV - * update reset logic inside rpl_update doesn't overwrite the - * change. - */ - rpl->seg = MAX(rpl->seg, auth_seqnum); - } - - *pdu_type = BT_MESH_FRIEND_PDU_COMPLETE; - - /* If this fails, the work handler will either exit early because the - * block is fully received, or rx->in_use is false. - */ - (void)k_work_cancel_delayable(&rx->ack); - send_ack(net_rx->sub, net_rx->ctx.recv_dst, net_rx->ctx.addr, - net_rx->ctx.send_ttl, seq_auth, rx->block, rx->obo); - - if (net_rx->ctl) { - NET_BUF_SIMPLE_DEFINE(sdu, BT_MESH_RX_CTL_MAX); - seg_rx_assemble(rx, &sdu, 0U); - err = ctl_recv(net_rx, *hdr, &sdu, seq_auth); - } else if (rx->len < 1 + APP_MIC_LEN(ASZMIC(hdr))) { - LOG_ERR("Too short SDU + MIC"); - err = -EINVAL; - } else { - NET_BUF_SIMPLE_DEFINE_STATIC(seg_buf, BT_MESH_RX_SDU_MAX); - struct net_buf_simple sdu; - - /* Decrypting in place to avoid creating two assembly buffers. - * We'll reassemble the buffer from the segments before each - * decryption attempt. - */ - net_buf_simple_init(&seg_buf, 0); - net_buf_simple_init_with_data( - &sdu, seg_buf.data, rx->len - APP_MIC_LEN(ASZMIC(hdr))); - - err = sdu_recv(net_rx, *hdr, ASZMIC(hdr), &seg_buf, &sdu, rx); - } - - seg_rx_reset(rx, false); - - return err; -} - -int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx) -{ - uint64_t seq_auth = TRANS_SEQ_AUTH_NVAL; - enum bt_mesh_friend_pdu_type pdu_type = BT_MESH_FRIEND_PDU_SINGLE; - struct net_buf_simple_state state; - uint8_t seg_count = 0; - int err; - - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { - rx->friend_match = bt_mesh_friend_match(rx->sub->net_idx, - rx->ctx.recv_dst); - } else { - rx->friend_match = false; - } - - LOG_DBG("src 0x%04x dst 0x%04x seq 0x%08x friend_match %u", rx->ctx.addr, rx->ctx.recv_dst, - rx->seq, rx->friend_match); - - /* Remove network headers */ - net_buf_simple_pull(buf, BT_MESH_NET_HDR_LEN); - - LOG_DBG("Payload %s", bt_hex(buf->data, buf->len)); - - if (IS_ENABLED(CONFIG_BT_TESTING)) { - bt_test_mesh_net_recv(rx->ctx.recv_ttl, rx->ctl, rx->ctx.addr, - rx->ctx.recv_dst, buf->data, buf->len); - } - - /* If LPN mode is enabled messages are only accepted when we've - * requested the Friend to send them. The messages must also - * be encrypted using the Friend Credentials. - */ - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) && - bt_mesh_lpn_established() && rx->net_if == BT_MESH_NET_IF_ADV && - (!bt_mesh_lpn_waiting_update() || !rx->friend_cred)) { - LOG_WRN("Ignoring unexpected message in Low Power mode"); - return -EAGAIN; - } - - /* Save the app-level state so the buffer can later be placed in - * the Friend Queue. - */ - net_buf_simple_save(buf, &state); - - if (SEG(buf->data)) { - /* Segmented messages must match a local element or an - * LPN of this Friend. - */ - if (!rx->local_match && !rx->friend_match) { - return 0; - } - - err = trans_seg(buf, rx, &pdu_type, &seq_auth, &seg_count); - } else { - seg_count = 1; - err = trans_unseg(buf, rx, &seq_auth); - } - - /* Notify LPN state machine so a Friend Poll will be sent. */ - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { - bt_mesh_lpn_msg_received(rx); - } - - net_buf_simple_restore(buf, &state); - - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && rx->friend_match && !err) { - if (seq_auth == TRANS_SEQ_AUTH_NVAL) { - bt_mesh_friend_enqueue_rx(rx, pdu_type, NULL, - seg_count, buf); - } else { - bt_mesh_friend_enqueue_rx(rx, pdu_type, &seq_auth, - seg_count, buf); - } - } - - return err; -} - -void bt_mesh_rx_reset(void) -{ - int i; - - LOG_DBG(""); - - for (i = 0; i < ARRAY_SIZE(seg_rx); i++) { - seg_rx_reset(&seg_rx[i], true); - } -} - -void bt_mesh_trans_reset(void) -{ - int i; - - bt_mesh_rx_reset(); - - LOG_DBG(""); - - for (i = 0; i < ARRAY_SIZE(seg_tx); i++) { - seg_tx_reset(&seg_tx[i]); - } - - bt_mesh_rpl_clear(); - bt_mesh_va_clear(); -} - -void bt_mesh_trans_init(void) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(seg_tx); i++) { - k_work_init_delayable(&seg_tx[i].retransmit, seg_retransmit); - } - - for (i = 0; i < ARRAY_SIZE(seg_rx); i++) { - k_work_init_delayable(&seg_rx[i].ack, seg_ack); - } -} diff --git a/tests/bluetooth/mesh/blob_io_flash/prj.conf b/tests/bluetooth/mesh/blob_io_flash/prj.conf index 2a0e98421fa..1e7864aa05d 100644 --- a/tests/bluetooth/mesh/blob_io_flash/prj.conf +++ b/tests/bluetooth/mesh/blob_io_flash/prj.conf @@ -15,7 +15,6 @@ CONFIG_BT_NO_DRIVER=y CONFIG_BT_OBSERVER=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_MESH=y -CONFIG_BT_MESH_V1d1=y CONFIG_BT_MESH_BLOB_SRV=y CONFIG_BT_MESH_BLOB_CLI=y CONFIG_BT_MESH_BLOB_IO_FLASH=y diff --git a/tests/bluetooth/mesh_shell/proxy_solicitation.conf b/tests/bluetooth/mesh_shell/proxy_solicitation.conf index f900d743516..51e50c07a01 100644 --- a/tests/bluetooth/mesh_shell/proxy_solicitation.conf +++ b/tests/bluetooth/mesh_shell/proxy_solicitation.conf @@ -1,4 +1,3 @@ -CONFIG_BT_MESH_V1d1=y CONFIG_BT_CENTRAL=y CONFIG_BT_MESH_PROXY_CLIENT=y CONFIG_BT_MESH_PROXY_SOLICITATION=y diff --git a/tests/bluetooth/tester/overlay-mesh-v1d1.conf b/tests/bluetooth/tester/overlay-mesh-v1d1.conf deleted file mode 100644 index 52045ce34df..00000000000 --- a/tests/bluetooth/tester/overlay-mesh-v1d1.conf +++ /dev/null @@ -1,30 +0,0 @@ -CONFIG_ENTROPY_GENERATOR=y - -CONFIG_BT_MESH_V1d1=y -CONFIG_BT_MESH_OP_AGG_CLI=y -CONFIG_BT_MESH_OP_AGG_SRV=y -# PTS requires more key slots. -# First one is implicitly taken by Device Key. -CONFIG_BT_MESH_MODEL_KEY_COUNT=3 -CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y -CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y -CONFIG_BT_MESH_SAR_CFG_SRV=y -CONFIG_BT_MESH_SAR_CFG_CLI=y -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_RPR_SRV=y -CONFIG_BT_MESH_RPR_CLI=y -CONFIG_BT_MESH_RPR_AD_TYPES_MAX=2 -CONFIG_BT_MESH_BLOB_CLI=y -CONFIG_BT_MESH_DFU_CLI=y -CONFIG_BT_MESH_BLOB_SRV=y -CONFIG_BT_MESH_DFU_SRV=y -CONFIG_BT_MESH_DFD_SRV=y -CONFIG_BT_MESH_DFU_SLOT_CNT=2 -CONFIG_BT_MESH_PRIV_BEACONS=y -CONFIG_BT_MESH_PRIV_BEACON_SRV=y -CONFIG_BT_MESH_PRIV_BEACON_CLI=y -CONFIG_BT_MESH_OD_PRIV_PROXY_SRV=y -CONFIG_BT_MESH_MODEL_EXTENSIONS=y -CONFIG_BT_MESH_COMP_PAGE_1=y -CONFIG_BT_MESH_COMP_PAGE_2=y -CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf index 840af06c1c0..9fded71f792 100644 --- a/tests/bluetooth/tester/overlay-mesh.conf +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -1,3 +1,5 @@ +CONFIG_ENTROPY_GENERATOR=y + CONFIG_BT_MESH=y CONFIG_BT_MESH_RELAY=y CONFIG_BT_MESH_PB_ADV=y @@ -23,3 +25,30 @@ CONFIG_BT_MESH_CDB_NODE_COUNT=3 CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y CONFIG_BT_MESH_MSG_CACHE_SIZE=10 CONFIG_BT_MESH_PROXY_CLIENT=y +CONFIG_BT_MESH_OP_AGG_CLI=y +CONFIG_BT_MESH_OP_AGG_SRV=y +# PTS requires more key slots. +# First one is implicitly taken by Device Key. +CONFIG_BT_MESH_MODEL_KEY_COUNT=3 +CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y +CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y +CONFIG_BT_MESH_SAR_CFG_SRV=y +CONFIG_BT_MESH_SAR_CFG_CLI=y +CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 +CONFIG_BT_MESH_RPR_SRV=y +CONFIG_BT_MESH_RPR_CLI=y +CONFIG_BT_MESH_RPR_AD_TYPES_MAX=2 +CONFIG_BT_MESH_BLOB_CLI=y +CONFIG_BT_MESH_DFU_CLI=y +CONFIG_BT_MESH_BLOB_SRV=y +CONFIG_BT_MESH_DFU_SRV=y +CONFIG_BT_MESH_DFD_SRV=y +CONFIG_BT_MESH_DFU_SLOT_CNT=2 +CONFIG_BT_MESH_PRIV_BEACONS=y +CONFIG_BT_MESH_PRIV_BEACON_SRV=y +CONFIG_BT_MESH_PRIV_BEACON_CLI=y +CONFIG_BT_MESH_OD_PRIV_PROXY_SRV=y +CONFIG_BT_MESH_MODEL_EXTENSIONS=y +CONFIG_BT_MESH_COMP_PAGE_1=y +CONFIG_BT_MESH_COMP_PAGE_2=y +CONFIG_SETTINGS=y diff --git a/tests/bluetooth/tester/testcase.yaml b/tests/bluetooth/tester/testcase.yaml index 8c36291b30f..37c7ab3193d 100644 --- a/tests/bluetooth/tester/testcase.yaml +++ b/tests/bluetooth/tester/testcase.yaml @@ -28,13 +28,3 @@ tests: extra_args: OVERLAY_CONFIG="overlay-mesh.conf" tags: bluetooth harness: bluetooth - bluetooth.general.tester_mesh_v1d1: - build_only: true - platform_allow: - - qemu_x86 - - native_posix - - native_sim - - nrf52840dk_nrf52840 - extra_args: OVERLAY_CONFIG="overlay-mesh.conf;overlay-mesh-v1d1.conf" - tags: bluetooth - harness: bluetooth diff --git a/tests/bsim/bluetooth/mesh/CMakeLists.txt b/tests/bsim/bluetooth/mesh/CMakeLists.txt index 44c72dd9cbb..17bcb3f208f 100644 --- a/tests/bsim/bluetooth/mesh/CMakeLists.txt +++ b/tests/bsim/bluetooth/mesh/CMakeLists.txt @@ -9,30 +9,21 @@ target_sources(app PRIVATE src/main.c src/mesh_test.c src/friendship_common.c + src/gatt_common.c + src/dfu_blob_common.c ) -if(CONFIG_BT_MESH_V1d1) - target_sources(app PRIVATE - src/dfu_blob_common.c - ) -endif() - if(CONFIG_SETTINGS) target_sources(app PRIVATE src/test_persistence.c src/test_replay_cache.c src/test_provision.c - ) - - if(CONFIG_BT_MESH_V1d1) - target_sources(app PRIVATE - src/test_dfu.c - src/test_blob.c - src/test_sar.c - src/test_lcd.c - ) - endif() + src/test_dfu.c + src/test_blob.c + src/test_sar.c + src/test_lcd.c +) if(CONFIG_BT_MESH_USES_MBEDTLS_PSA) target_sources(app PRIVATE @@ -45,13 +36,9 @@ elseif(CONFIG_BT_MESH_GATT_PROXY) target_sources(app PRIVATE src/test_advertiser.c - ) - - if(CONFIG_BT_MESH_V1d1) - target_sources(app PRIVATE + src/test_suspend.c src/test_beacon.c - ) - endif() + ) elseif(CONFIG_BT_CTLR_LOW_LAT) @@ -72,17 +59,13 @@ else() src/test_access.c src/test_iv_index.c src/test_advertiser.c + src/test_suspend.c + src/test_blob.c + src/test_op_agg.c + src/test_sar.c + src/test_cdp1.c ) - if(CONFIG_BT_MESH_V1d1) - target_sources(app PRIVATE - src/test_blob.c - src/test_op_agg.c - src/test_sar.c - src/test_cdp1.c - ) - endif() - endif() zephyr_include_directories( diff --git a/tests/bsim/bluetooth/mesh/compile.sh b/tests/bsim/bluetooth/mesh/compile.sh index de9b4bd6af0..06557ef0ebb 100755 --- a/tests/bsim/bluetooth/mesh/compile.sh +++ b/tests/bsim/bluetooth/mesh/compile.sh @@ -18,22 +18,13 @@ mkdir -p ${WORK_DIR} source ${ZEPHYR_BASE}/tests/bsim/compile.source app=tests/bsim/bluetooth/mesh compile -app=tests/bsim/bluetooth/mesh conf_overlay=overlay_low_lat.conf compile app=tests/bsim/bluetooth/mesh conf_overlay=overlay_pst.conf compile app=tests/bsim/bluetooth/mesh conf_overlay=overlay_gatt.conf compile -app=tests/bsim/bluetooth/mesh conf_file=prj_mesh1d1.conf compile -app=tests/bsim/bluetooth/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay=overlay_pst.conf compile -app=tests/bsim/bluetooth/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay=overlay_gatt.conf compile -app=tests/bsim/bluetooth/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay=overlay_low_lat.conf compile -app=tests/bsim/bluetooth/mesh conf_file=prj_mesh1d1.conf conf_overlay=overlay_psa.conf compile -app=tests/bsim/bluetooth/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay="overlay_pst.conf;overlay_psa.conf" compile -app=tests/bsim/bluetooth/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay="overlay_gatt.conf;overlay_psa.conf" compile -app=tests/bsim/bluetooth/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay="overlay_low_lat.conf;overlay_psa.conf" compile +app=tests/bsim/bluetooth/mesh conf_overlay=overlay_low_lat.conf compile +app=tests/bsim/bluetooth/mesh conf_overlay=overlay_psa.conf compile +app=tests/bsim/bluetooth/mesh conf_overlay="overlay_pst.conf;overlay_psa.conf" compile +app=tests/bsim/bluetooth/mesh conf_overlay="overlay_gatt.conf;overlay_psa.conf" compile +app=tests/bsim/bluetooth/mesh conf_overlay="overlay_low_lat.conf;overlay_psa.conf" compile +app=tests/bsim/bluetooth/mesh conf_overlay="overlay_gatt.conf;overlay_low_lat.conf" compile wait_for_background_jobs diff --git a/tests/bsim/bluetooth/mesh/overlay_pst.conf b/tests/bsim/bluetooth/mesh/overlay_pst.conf index 6730b9ee233..e02c0ec2b93 100644 --- a/tests/bsim/bluetooth/mesh/overlay_pst.conf +++ b/tests/bsim/bluetooth/mesh/overlay_pst.conf @@ -18,7 +18,4 @@ CONFIG_BT_MESH_SUBNET_COUNT=2 CONFIG_BT_MESH_SEQ_STORE_RATE=1 CONFIG_BT_MESH_RPL_STORE_TIMEOUT=1 CONFIG_BT_MESH_STORE_TIMEOUT=1 -CONFIG_BT_MESH_TX_SEG_RETRANS_COUNT=1 -CONFIG_BT_MESH_TX_SEG_RETRANS_TIMEOUT_UNICAST=200 -CONFIG_BT_MESH_SEG_ACK_BASE_TIMEOUT=400 CONFIG_BT_MESH_COMP_PST_BUF_SIZE=600 diff --git a/tests/bsim/bluetooth/mesh/prj.conf b/tests/bsim/bluetooth/mesh/prj.conf index e9c719de6d7..1c343bb512f 100644 --- a/tests/bsim/bluetooth/mesh/prj.conf +++ b/tests/bsim/bluetooth/mesh/prj.conf @@ -19,11 +19,12 @@ CONFIG_BT_CTLR_PRIVACY=n CONFIG_BT_MESH=y CONFIG_BT_MESH_LOG_LEVEL_DBG=y CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_ADV_BUF_COUNT=32 +CONFIG_BT_MESH_ADV_BUF_COUNT=64 CONFIG_BT_MESH_TX_SEG_MAX=32 CONFIG_BT_MESH_RX_SEG_MAX=32 CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 CONFIG_BT_MESH_RX_SEG_MSG_COUNT=10 +CONFIG_BT_MESH_SEG_BUFS=100 CONFIG_BT_MESH_CFG_CLI=y CONFIG_BT_MESH_MODEL_GROUP_COUNT=3 CONFIG_BT_MESH_LOW_POWER=y @@ -43,4 +44,29 @@ CONFIG_BT_MESH_CDB_NODE_COUNT=4 CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y CONFIG_BT_MESH_MODEL_EXTENSIONS=y CONFIG_BT_MESH_SUBNET_COUNT=5 +CONFIG_BT_MESH_SAR_CFG_CLI=y +CONFIG_BT_MESH_SAR_CFG_SRV=y +CONFIG_BT_MESH_BLOB_SRV=y +CONFIG_BT_MESH_BLOB_CLI=y +CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MIN=256 +CONFIG_BT_MESH_RPR_CLI=y +CONFIG_BT_MESH_RPR_SRV=y +CONFIG_BT_MESH_OP_AGG_CLI=y +CONFIG_BT_MESH_OP_AGG_SRV=y +CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y +CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y +CONFIG_BT_MESH_DFU_SRV=y +CONFIG_BT_MESH_DFU_CLI=y +CONFIG_BT_MESH_DFD_SRV=y +CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD=y +CONFIG_BT_MESH_DFU_SLOT_CNT=4 +CONFIG_BT_MESH_PRIV_BEACON_SRV=y +CONFIG_BT_MESH_PRIV_BEACON_CLI=y +CONFIG_BT_MESH_OD_PRIV_PROXY_SRV=y +CONFIG_BT_MESH_OD_PRIV_PROXY_CLI=y +CONFIG_BT_MESH_COMP_PAGE_1=y +CONFIG_BT_MESH_COMP_PAGE_2=y CONFIG_BT_TESTING=y + +# Needed for RPR tests due to huge amount of retransmitted messages +CONFIG_BT_MESH_MSG_CACHE_SIZE=64 diff --git a/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf b/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf deleted file mode 100644 index fd0c953226b..00000000000 --- a/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf +++ /dev/null @@ -1,73 +0,0 @@ -CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_ASSERT=y -CONFIG_SYS_CLOCK_TICKS_PER_SEC=32768 - -# Bluetooth configuration -CONFIG_BT=y -CONFIG_LOG=y -CONFIG_BT_PRIVACY=n -CONFIG_BT_COMPANY_ID=0x0059 -CONFIG_BT_DEVICE_NAME="Mesh test" -CONFIG_BT_OBSERVER=y -CONFIG_BT_BROADCASTER=y - -# Disable unused Bluetooth features -CONFIG_BT_CTLR_DUP_FILTER_LEN=0 -CONFIG_BT_CTLR_PRIVACY=n - -# Bluetooth Mesh configuration -CONFIG_BT_MESH=y -CONFIG_BT_MESH_V1d1=y -CONFIG_BT_MESH_LOG_LEVEL_DBG=y -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_ADV_BUF_COUNT=64 -CONFIG_BT_MESH_TX_SEG_MAX=32 -CONFIG_BT_MESH_RX_SEG_MAX=32 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_RX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_SEG_BUFS=100 -CONFIG_BT_MESH_CFG_CLI=y -CONFIG_BT_MESH_MODEL_GROUP_COUNT=3 -CONFIG_BT_MESH_LOW_POWER=y -CONFIG_BT_MESH_LPN_AUTO=n -CONFIG_BT_MESH_FRIEND=y -CONFIG_BT_MESH_FRIEND_ENABLED=n -CONFIG_BT_MESH_FRIEND_LPN_COUNT=5 -CONFIG_BT_MESH_APP_KEY_COUNT=2 -CONFIG_BT_MESH_MODEL_KEY_COUNT=2 -CONFIG_BT_MESH_LABEL_COUNT=3 -CONFIG_BT_MESH_IV_UPDATE_TEST=y -CONFIG_BT_MESH_PB_ADV=y -CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_PROVISIONEE=y -CONFIG_BT_MESH_CDB=y -CONFIG_BT_MESH_CDB_NODE_COUNT=4 -CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y -CONFIG_BT_MESH_MODEL_EXTENSIONS=y -CONFIG_BT_MESH_SUBNET_COUNT=5 -CONFIG_BT_MESH_SAR_CFG_CLI=y -CONFIG_BT_MESH_SAR_CFG_SRV=y -CONFIG_BT_MESH_BLOB_SRV=y -CONFIG_BT_MESH_BLOB_CLI=y -CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MIN=256 -CONFIG_BT_MESH_RPR_CLI=y -CONFIG_BT_MESH_RPR_SRV=y -CONFIG_BT_MESH_OP_AGG_CLI=y -CONFIG_BT_MESH_OP_AGG_SRV=y -CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y -CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y -CONFIG_BT_MESH_DFU_SRV=y -CONFIG_BT_MESH_DFU_CLI=y -CONFIG_BT_MESH_DFD_SRV=y -CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD=y -CONFIG_BT_MESH_DFU_SLOT_CNT=4 -CONFIG_BT_MESH_PRIV_BEACON_SRV=y -CONFIG_BT_MESH_PRIV_BEACON_CLI=y -CONFIG_BT_MESH_OD_PRIV_PROXY_SRV=y -CONFIG_BT_MESH_OD_PRIV_PROXY_CLI=y -CONFIG_BT_MESH_COMP_PAGE_1=y -CONFIG_BT_MESH_COMP_PAGE_2=y -CONFIG_BT_TESTING=y - -# Needed for RPR tests due to huge amount of retransmitted messages -CONFIG_BT_MESH_MSG_CACHE_SIZE=64 diff --git a/tests/bsim/bluetooth/mesh/src/main.c b/tests/bsim/bluetooth/mesh/src/main.c index 127e52faa49..a3dfb59373f 100644 --- a/tests/bsim/bluetooth/mesh/src/main.c +++ b/tests/bsim/bluetooth/mesh/src/main.c @@ -11,18 +11,14 @@ extern struct bst_test_list *test_persistence_install(struct bst_test_list *tests); extern struct bst_test_list *test_rpc_install(struct bst_test_list *tests); extern struct bst_test_list *test_provision_pst_install(struct bst_test_list *tests); -#if defined(CONFIG_BT_MESH_V1d1) extern struct bst_test_list *test_dfu_install(struct bst_test_list *test); extern struct bst_test_list *test_blob_pst_install(struct bst_test_list *test); extern struct bst_test_list *test_lcd_install(struct bst_test_list *test); extern struct bst_test_list *test_sar_pst_install(struct bst_test_list *test); -#endif /* defined(CONFIG_BT_MESH_V1d1) */ #elif defined(CONFIG_BT_MESH_GATT_PROXY) extern struct bst_test_list *test_adv_install(struct bst_test_list *test); -#if defined(CONFIG_BT_MESH_V1d1) +extern struct bst_test_list *test_suspend_install(struct bst_test_list *test); extern struct bst_test_list *test_beacon_install(struct bst_test_list *tests); -#endif /* defined(CONFIG_BT_MESH_V1d1) */ - #elif defined(CONFIG_BT_CTLR_LOW_LAT) extern struct bst_test_list *test_transport_install(struct bst_test_list *tests); extern struct bst_test_list *test_friendship_install(struct bst_test_list *tests); @@ -36,30 +32,26 @@ extern struct bst_test_list *test_heartbeat_install(struct bst_test_list *test); extern struct bst_test_list *test_access_install(struct bst_test_list *test); extern struct bst_test_list *test_ivi_install(struct bst_test_list *test); extern struct bst_test_list *test_adv_install(struct bst_test_list *test); -#if defined(CONFIG_BT_MESH_V1d1) +extern struct bst_test_list *test_suspend_install(struct bst_test_list *test); extern struct bst_test_list *test_blob_install(struct bst_test_list *test); extern struct bst_test_list *test_op_agg_install(struct bst_test_list *test); extern struct bst_test_list *test_sar_install(struct bst_test_list *test); extern struct bst_test_list *test_cdp1_install(struct bst_test_list *test); -#endif /* defined(CONFIG_BT_MESH_V1d1) */ #endif bst_test_install_t test_installers[] = { #if defined(CONFIG_SETTINGS) test_persistence_install, test_rpc_install, -#if defined(CONFIG_BT_MESH_V1d1) test_provision_pst_install, test_dfu_install, test_blob_pst_install, test_lcd_install, test_sar_pst_install, -#endif /* defined(CONFIG_BT_MESH_V1d1) */ #elif defined(CONFIG_BT_MESH_GATT_PROXY) test_adv_install, -#if defined(CONFIG_BT_MESH_V1d1) + test_suspend_install, test_beacon_install, -#endif /* defined(CONFIG_BT_MESH_V1d1) */ #elif defined(CONFIG_BT_CTLR_LOW_LAT) test_transport_install, test_friendship_install, @@ -73,12 +65,11 @@ bst_test_install_t test_installers[] = { test_access_install, test_ivi_install, test_adv_install, -#if defined(CONFIG_BT_MESH_V1d1) + test_suspend_install, test_blob_install, test_op_agg_install, test_sar_install, test_cdp1_install, -#endif /* defined(CONFIG_BT_MESH_V1d1) */ #endif NULL }; diff --git a/tests/bsim/bluetooth/mesh/src/test_beacon.c b/tests/bsim/bluetooth/mesh/src/test_beacon.c index e5f7d515da7..7a74123cb0f 100644 --- a/tests/bsim/bluetooth/mesh/src/test_beacon.c +++ b/tests/bsim/bluetooth/mesh/src/test_beacon.c @@ -27,9 +27,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); #define BEACON_INTERVAL 10 /*seconds*/ #define BEACON_TYPE_SECURE 0x01 -#if CONFIG_BT_MESH_V1d1 #define BEACON_TYPE_PRIVATE 0x02 -#endif static uint8_t test_net_key_2[16] = { 0xca, 0x11, 0xab, 0x1e }; static struct { @@ -71,7 +69,6 @@ BT_MESH_BEACON_CB_DEFINE(snb) = { /* Setting for scanner defining what beacon is expected next, SNB as default */ static uint8_t expected_beacon = BEACON_TYPE_SECURE; -#if CONFIG_BT_MESH_V1d1 static struct bt_mesh_cfg_cli cfg_cli; static struct bt_mesh_priv_beacon_cli priv_beacon_cli; @@ -99,7 +96,6 @@ static uint8_t last_random[13]; static bt_addr_le_t last_beacon_adv_addr; static struct bt_mesh_key priv_beacon_key; -#endif /* CONFIG_BT_MESH_V1d1 */ static int random_interval; @@ -330,13 +326,11 @@ static struct k_sem observer_sem; static struct { uint8_t flags; uint32_t iv_index; -#if CONFIG_BT_MESH_V1d1 uint8_t random[13]; uint64_t pp_hash; uint64_t pp_random; uint64_t net_id; bt_addr_le_t adv_addr; -#endif bool (*process_cb)(const uint8_t *net_id, void *ctx); void *user_ctx; } beacon; @@ -364,7 +358,6 @@ static void beacon_scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_ty net_id = net_buf_simple_pull_mem(buf, 8); beacon.iv_index = net_buf_simple_pull_be32(buf); } -#if CONFIG_BT_MESH_V1d1 else if (expected_beacon == BEACON_TYPE_PRIVATE) { uint8_t private_beacon_data[5]; @@ -377,7 +370,7 @@ static void beacon_scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_ty beacon.flags = private_beacon_data[0]; beacon.iv_index = sys_get_be32(&private_beacon_data[1]); } -#endif + if (!beacon.process_cb || beacon.process_cb(net_id, beacon.user_ctx)) { k_sem_give(&observer_sem); } @@ -1064,8 +1057,6 @@ static void test_tx_beacon_cache(void) PASS(); } -#if CONFIG_BT_MESH_V1d1 - typedef void (*priv_beacon_cb)(const struct bt_mesh_prb *prb); static priv_beacon_cb priv_beacon_cb_ptr; @@ -2196,8 +2187,6 @@ static void test_rx_priv_gatt_proxy(void) #endif -#endif /* CONFIG_BT_MESH_V1d1 */ - #define TEST_CASE(role, name, description) \ { \ .test_id = "beacon_" #role "_" #name, \ @@ -2216,7 +2205,6 @@ static const struct bst_test_instance test_beacon[] = { TEST_CASE(tx, multiple_netkeys, "Beacon: multiple Net Keys"), TEST_CASE(tx, secure_beacon_interval, "Beacon: send secure beacons"), TEST_CASE(tx, beacon_cache, "Beacon: advertise duplicate SNBs"), -#if CONFIG_BT_MESH_V1d1 TEST_CASE(tx, priv_on_iv_update, "Private Beacon: send on IV update"), TEST_CASE(tx, priv_on_key_refresh, "Private Beacon: send on Key Refresh"), TEST_CASE(tx, priv_adv, "Private Beacon: advertise Private Beacons"), @@ -2230,7 +2218,6 @@ static const struct bst_test_instance test_beacon[] = { TEST_CASE(tx, priv_gatt_proxy, "Private Proxy: Send Private Beacons over GATT"), TEST_CASE(tx, proxy_adv_multi_subnet_coex, "Proxy Adv: Multi subnet coex proxy adv"), TEST_CASE(tx, proxy_adv_solicit_trigger, "Proxy Adv: Trigger Solicitation"), -#endif #endif TEST_CASE(rx, on_iv_update, "Beacon: receive with IV update flag"), @@ -2240,7 +2227,6 @@ static const struct bst_test_instance test_beacon[] = { TEST_CASE(rx, multiple_netkeys, "Beacon: multiple Net Keys"), TEST_CASE(rx, secure_beacon_interval, "Beacon: receive and send secure beacons"), TEST_CASE(rx, beacon_cache, "Beacon: receive duplicate SNBs"), -#if CONFIG_BT_MESH_V1d1 TEST_CASE(rx, priv_adv, "Private Beacon: verify random regeneration"), TEST_CASE(rx, priv_invalid, "Private Beacon: receive invalid beacons"), TEST_CASE(rx, priv_interleave, "Private Beacon: interleaved with SNB"), @@ -2251,7 +2237,6 @@ static const struct bst_test_instance test_beacon[] = { TEST_CASE(rx, priv_multi_net_id, "Private Proxy: scan for multiple Net ID"), TEST_CASE(rx, priv_gatt_proxy, "Private Proxy: Receive Private Beacons over GATT"), TEST_CASE(rx, proxy_adv_multi_subnet_coex, "Proxy Adv: Multi subnet coex proxy adv"), -#endif #endif BSTEST_END_MARKER }; diff --git a/tests/bsim/bluetooth/mesh/src/test_provision.c b/tests/bsim/bluetooth/mesh/src/test_provision.c index 3d0e8010c75..789de47837b 100644 --- a/tests/bsim/bluetooth/mesh/src/test_provision.c +++ b/tests/bsim/bluetooth/mesh/src/test_provision.c @@ -52,11 +52,9 @@ enum test_flags { static uint8_t static_key1[] = {0x6E, 0x6F, 0x72, 0x64, 0x69, 0x63, 0x5F, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x5F, 0x31}; static uint8_t static_key2[] = {0x6E, 0x6F, 0x72, 0x64, 0x69, 0x63, 0x5F}; -#if IS_ENABLED(CONFIG_BT_MESH_V1d1) static uint8_t static_key3[] = {0x45, 0x6E, 0x68, 0x61, 0x6E, 0x63, 0x65, 0x64, 0x20, 0x70, 0x72, 0x6F, 0x76, 0x69, 0x73, 0x69, 0x6F, 0x6E, 0x69, 0x6E, 0x67, 0x20, 0x73, 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x4F, 0x4F, 0x42}; -#endif static uint8_t private_key_be[32]; static uint8_t public_key_be[64]; @@ -72,9 +70,7 @@ static struct oob_auth_test_vector_s { {NULL, 0, 0, 0, 0, 0}, {static_key1, sizeof(static_key1), 0, 0, 0, 0}, {static_key2, sizeof(static_key2), 0, 0, 0, 0}, -#if IS_ENABLED(CONFIG_BT_MESH_V1d1) {static_key3, sizeof(static_key3), 0, 0, 0, 0}, -#endif {NULL, 0, 3, BT_MESH_BLINK, 0, 0}, {NULL, 0, 5, BT_MESH_BEEP, 0, 0}, {NULL, 0, 6, BT_MESH_VIBRATE, 0, 0}, diff --git a/tests/bsim/bluetooth/mesh/src/test_replay_cache.c b/tests/bsim/bluetooth/mesh/src/test_replay_cache.c index 68dc52a7b5d..57d605fb97a 100644 --- a/tests/bsim/bluetooth/mesh/src/test_replay_cache.c +++ b/tests/bsim/bluetooth/mesh/src/test_replay_cache.c @@ -78,7 +78,6 @@ static void rx_ended(uint8_t *data, size_t len) static void tx_sar_conf(void) { -#ifdef CONFIG_BT_MESH_V1d1 /* Reconfigure SAR Transmitter state so that the transport layer doesn't * retransmit. */ @@ -97,12 +96,10 @@ static void tx_sar_conf(void) #else bt_mesh.sar_tx = tx_set; #endif -#endif } static void rx_sar_conf(void) { -#ifdef CONFIG_BT_MESH_V1d1 /* Reconfigure SAR Receiver state so that the transport layer does * generate Segmented Acks as rarely as possible. */ @@ -119,7 +116,6 @@ static void rx_sar_conf(void) #else bt_mesh.sar_rx = rx_set; #endif -#endif } static void test_tx_immediate_replay_attack(void) diff --git a/tests/bsim/bluetooth/mesh/src/test_transport.c b/tests/bsim/bluetooth/mesh/src/test_transport.c index 05026f6dcf7..309681ceafe 100644 --- a/tests/bsim/bluetooth/mesh/src/test_transport.c +++ b/tests/bsim/bluetooth/mesh/src/test_transport.c @@ -94,7 +94,6 @@ static void async_send_end(int err, void *data) static void rx_sar_conf(void) { -#ifdef CONFIG_BT_MESH_V1d1 /* Reconfigure SAR Receiver state so that the transport layer does * generate Segmented Acks as rarely as possible. */ @@ -111,7 +110,6 @@ static void rx_sar_conf(void) #else bt_mesh.sar_rx = rx_set; #endif -#endif } static const struct bt_mesh_send_cb async_send_cb = { diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_cancel.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_cancel.sh index 6a56a084c60..85b76062b60 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_cancel.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_cancel.sh @@ -7,11 +7,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_access_publication_cancel \ access_tx_cancel access_rx_cancel -conf=prj_mesh1d1_conf -RunTest mesh_access_publication_cancel_1d1 \ - access_tx_cancel access_rx_cancel - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_access_publication_cancel_psa \ access_tx_cancel access_rx_cancel diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub.sh index 862291b4c76..66caf516bb2 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub.sh @@ -7,11 +7,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_access_extended_model_subs \ access_tx_ext_model access_sub_ext_model -conf=prj_mesh1d1_conf -RunTest mesh_access_extended_model_subs_1d1 \ - access_tx_ext_model access_sub_ext_model - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_access_extended_model_subs_psa \ access_tx_ext_model access_sub_ext_model diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub_cap.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub_cap.sh index 2a4f9ccc247..91576f34aa0 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub_cap.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub_cap.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_access_extended_model_subs_cap access_sub_capacity_ext_model -conf=prj_mesh1d1_conf -RunTest mesh_access_extended_model_subs_cap_1d1 access_sub_capacity_ext_model - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_access_extended_model_subs_cap_psa access_sub_capacity_ext_model diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period.sh index d2bb07c6de7..f2e72085ac7 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period.sh @@ -7,11 +7,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_access_per_pub \ access_tx_period access_rx_period -conf=prj_mesh1d1_conf -RunTest mesh_access_per_pub_1d1 \ - access_tx_period access_rx_period - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_access_per_pub_psa \ access_tx_period access_rx_period diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period_delayable.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period_delayable.sh index 5ecd4a061de..0148026fc6f 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period_delayable.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period_delayable.sh @@ -7,11 +7,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_access_pub_period_delayable_retr \ access_tx_period_delayable access_rx_period_delayable -conf=prj_mesh1d1_conf -RunTest mesh_access_pub_period_delayable_retr_1d1 \ - access_tx_period_delayable access_rx_period_delayable - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_access_pub_period_delayable_retr_psa \ access_tx_period_delayable access_rx_period_delayable diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit.sh index c2f4a27ddbd..0a0ec47da15 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit.sh @@ -7,11 +7,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_access_pub_retr \ access_tx_transmit access_rx_transmit -conf=prj_mesh1d1_conf -RunTest mesh_access_pub_retr_1d1 \ - access_tx_transmit access_rx_transmit - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_access_pub_retr_psa \ access_tx_period access_rx_period diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh index 0e966288db0..2dba89f2d76 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit_delayable.sh @@ -7,11 +7,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_access_pub_transmit_delayable_retr \ access_tx_transmit_delayable access_rx_transmit_delayable -conf=prj_mesh1d1_conf -RunTest mesh_access_pub_transmit_delayable_retr_1d1 \ - access_tx_transmit_delayable access_rx_transmit_delayable - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_access_pub_transmit_delayable_retr_psa \ access_tx_transmit_delayable access_rx_transmit_delayable diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/proxy_mixin.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/proxy_mixin.sh index 86255277277..6c49d03fe9f 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/proxy_mixin.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/proxy_mixin.sh @@ -21,10 +21,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh overlay=overlay_gatt_conf RunTest mesh_adv_proxy_mixin adv_tx_proxy_mixin adv_rx_proxy_mixin -conf=prj_mesh1d1_conf -overlay=overlay_gatt_conf -RunTest mesh_adv_proxy_mixin_1d1 adv_tx_proxy_mixin adv_rx_proxy_mixin - -conf=prj_mesh1d1_conf overlay="overlay_gatt_conf_overlay_psa_conf" RunTest mesh_adv_proxy_mixin_psa adv_tx_proxy_mixin adv_rx_proxy_mixin diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/random_order.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/random_order.sh index 8cfe0f9366a..a171ffd60f3 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/random_order.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/random_order.sh @@ -7,9 +7,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # test buffer management by filling buffers and sending them in random order. RunTest mesh_adv_random_order adv_tx_random_order adv_rx_random_order -conf=prj_mesh1d1_conf -RunTest mesh_adv_random_order_1d1 adv_tx_random_order adv_rx_random_order - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_adv_random_order_psa adv_tx_random_order adv_rx_random_order diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/reverse_order.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/reverse_order.sh index 96b30394f12..2b047138109 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/reverse_order.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/reverse_order.sh @@ -7,9 +7,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # test buffer management by filling all the buffer and sending them in reversed order. RunTest mesh_adv_reverse_order adv_tx_reverse_order adv_rx_receive_order -conf=prj_mesh1d1_conf -RunTest mesh_adv_reverse_order_1d1 adv_tx_reverse_order adv_rx_receive_order - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_adv_reverse_order_psa adv_tx_reverse_order adv_rx_receive_order diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/send_order.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/send_order.sh index e208bf54579..a9e8d1ea861 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/send_order.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/send_order.sh @@ -7,9 +7,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # test buffer management by filling all the buffer and sending them all in order. RunTest mesh_adv_send_order adv_tx_send_order adv_rx_receive_order -conf=prj_mesh1d1_conf -RunTest mesh_adv_send_order_1d1 adv_tx_send_order adv_rx_receive_order - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_adv_send_order_psa adv_tx_send_order adv_rx_receive_order diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_multi.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_multi.sh index 28827c872f8..4ca2838ddf9 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_multi.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_multi.sh @@ -7,9 +7,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # test tx callbacks sequence for multiple advs RunTest mesh_adv_tx_cb_multi adv_tx_cb_multi -conf=prj_mesh1d1_conf -RunTest mesh_adv_tx_cb_multi_1d1 adv_tx_cb_multi - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_adv_tx_cb_multi_psa adv_tx_cb_multi diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_single.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_single.sh index edf4ba0996b..a2b1ad0e961 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_single.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_single.sh @@ -7,9 +7,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # test tx callbacks parameters and xmit sequence for single adv RunTest mesh_adv_tx_cb_single adv_tx_cb_single adv_rx_xmit -conf=prj_mesh1d1_conf -RunTest mesh_adv_tx_cb_single_1d1 adv_tx_cb_single adv_rx_xmit - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_adv_tx_cb_single_psa adv_tx_cb_single adv_rx_xmit diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/beacon_cache.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/beacon_cache.sh index c0f741e9aae..ab43e2b74db 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/beacon_cache.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/beacon_cache.sh @@ -15,12 +15,6 @@ RunTest mesh_beacon_cache \ beacon_tx_beacon_cache \ beacon_rx_beacon_cache -conf=prj_mesh1d1_conf -RunTest mesh_beacon_cache \ - beacon_tx_beacon_cache \ - beacon_rx_beacon_cache - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_beacon_cache \ beacon_tx_beacon_cache \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/beacon_interval.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/beacon_interval.sh index ec70eb2f02c..a671c90d668 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/beacon_interval.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/beacon_interval.sh @@ -22,12 +22,6 @@ RunTest mesh_beacon_interval \ beacon_tx_secure_beacon_interval \ beacon_rx_secure_beacon_interval -conf=prj_mesh1d1_conf -RunTest mesh_beacon_interval_1d1 \ - beacon_tx_secure_beacon_interval \ - beacon_rx_secure_beacon_interval - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_beacon_interval_psa \ beacon_tx_secure_beacon_interval \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/invalid.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/invalid.sh index ccce8c3a1f5..96d5b0a0f6b 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/invalid.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/invalid.sh @@ -8,12 +8,6 @@ RunTest mesh_beacon_invalid \ beacon_tx_invalid \ beacon_rx_invalid -conf=prj_mesh1d1_conf -RunTest mesh_beacon_invalid_1d1 \ - beacon_tx_invalid \ - beacon_rx_invalid - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_beacon_invalid_psa \ beacon_tx_invalid \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/iv_update.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/iv_update.sh index 64225fd9cf5..d719aef86bc 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/iv_update.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/iv_update.sh @@ -8,12 +8,6 @@ RunTest mesh_beacon_on_iv_update \ beacon_tx_on_iv_update \ beacon_rx_on_iv_update -conf=prj_mesh1d1_conf -RunTest mesh_beacon_on_iv_update_1d1 \ - beacon_tx_on_iv_update \ - beacon_rx_on_iv_update - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_beacon_on_iv_update_psa \ beacon_tx_on_iv_update \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/key_refresh.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/key_refresh.sh index 00f82704718..9223d7d1d29 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/key_refresh.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/key_refresh.sh @@ -8,12 +8,6 @@ RunTest mesh_beacon_on_key_refresh \ beacon_tx_on_key_refresh \ beacon_rx_on_key_refresh -conf=prj_mesh1d1_conf -RunTest mesh_beacon_on_key_refresh_1d1 \ - beacon_tx_on_key_refresh \ - beacon_rx_on_key_refresh - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_beacon_on_key_refresh_psa \ beacon_tx_on_key_refresh \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/kr_old_key.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/kr_old_key.sh index 3d6b151a068..ecd83e415a9 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/kr_old_key.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/kr_old_key.sh @@ -8,12 +8,6 @@ RunTest mesh_beacon_kr_old_key \ beacon_tx_kr_old_key \ beacon_rx_kr_old_key -conf=prj_mesh1d1_conf -RunTest mesh_beacon_kr_old_key_1d1 \ - beacon_tx_kr_old_key \ - beacon_rx_kr_old_key - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_beacon_kr_old_key_psa \ beacon_tx_kr_old_key \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/multiple_netkeys.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/multiple_netkeys.sh index 677e4227669..a8c154f5204 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/beacon/multiple_netkeys.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/multiple_netkeys.sh @@ -8,12 +8,6 @@ RunTest mesh_beacon_multiple_netkeys \ beacon_tx_multiple_netkeys \ beacon_rx_multiple_netkeys -conf=prj_mesh1d1_conf -RunTest mesh_beacon_multiple_netkeys_1d1 \ - beacon_tx_multiple_netkeys \ - beacon_rx_multiple_netkeys - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_beacon_multiple_netkeys_psa \ beacon_tx_multiple_netkeys \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_basic.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_basic.sh index 6f1ec61ad27..d8665ac4cfd 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_basic.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_basic.sh @@ -4,9 +4,7 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh -conf=prj_mesh1d1_conf RunTest blob_broadcast_basic blob_cli_broadcast_basic -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_broadcast_basic_psa blob_cli_broadcast_basic diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_trans.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_trans.sh index d5d0f60d1ce..25198e70a38 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_trans.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_trans.sh @@ -4,9 +4,7 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh -conf=prj_mesh1d1_conf RunTest blob_broadcast_trans blob_cli_broadcast_trans -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_broadcast_trans_psa blob_cli_broadcast_trans diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_unicast.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_unicast.sh index ee86ce33cfa..654753e2188 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_unicast.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_unicast.sh @@ -4,9 +4,7 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh -conf=prj_mesh1d1_conf RunTest blob_broadcast_unicast blob_cli_broadcast_unicast -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_broadcast_unicast_psa blob_cli_broadcast_unicast diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_unicast_seq.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_unicast_seq.sh index c356122145c..cb569fdc3b4 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_unicast_seq.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast_unicast_seq.sh @@ -4,9 +4,7 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh -conf=prj_mesh1d1_conf RunTest blob_broadcast_unicast_seq blob_cli_broadcast_unicast_seq -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_broadcast_unicast_seq_psa blob_cli_broadcast_unicast_seq diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_all_rsp.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_all_rsp.sh index bc2aa351987..d7f54a34d22 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_all_rsp.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_all_rsp.sh @@ -5,11 +5,9 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf RunTest blob_caps_all_rsp \ blob_cli_caps_all_rsp blob_srv_caps_standard blob_srv_caps_standard -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_caps_all_rsp_psa \ blob_cli_caps_all_rsp blob_srv_caps_standard blob_srv_caps_standard diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_cancelled.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_cancelled.sh index 3e1bd343a70..e287dcbd9fc 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_cancelled.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_cancelled.sh @@ -5,11 +5,9 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # The test instance seqence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf RunTest blob_caps_cancelled \ blob_cli_caps_cancelled blob_srv_caps_standard -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_caps_cancelled_psa \ blob_cli_caps_cancelled blob_srv_caps_standard diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_no_rsp.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_no_rsp.sh index e53864f8be4..e5ee44b5a08 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_no_rsp.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_no_rsp.sh @@ -5,11 +5,9 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf RunTest blob_caps_no_rsp \ blob_cli_caps_no_rsp blob_srv_caps_no_rsp blob_srv_caps_no_rsp -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_caps_no_rsp_psa \ blob_cli_caps_no_rsp blob_srv_caps_no_rsp blob_srv_caps_no_rsp diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_partial_rsp.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_partial_rsp.sh index 9a1675bd279..2da51b0e37e 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_partial_rsp.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps_partial_rsp.sh @@ -5,11 +5,9 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf RunTest blob_caps_partial_rsp \ blob_cli_caps_partial_rsp blob_srv_caps_standard blob_srv_caps_no_rsp -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_caps_partial_rsp_psa \ blob_cli_caps_partial_rsp blob_srv_caps_standard blob_srv_caps_no_rsp diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_friend.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_friend.sh index 1c2bde7a109..0e82cf8df11 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_friend.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_friend.sh @@ -7,7 +7,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Establish multiple different friendships concurrently. Perform BLOB transfer with BLOB Client # on friend node and BLOB Server on LPNs. # Note: The number of LPNs must match CONFIG_BT_MESH_FRIEND_LPN_COUNT. -conf=prj_mesh1d1_conf RunTest blob_transfer_lpn \ blob_cli_friend_pull \ blob_srv_lpn_pull \ @@ -16,7 +15,6 @@ RunTest blob_transfer_lpn \ blob_srv_lpn_pull \ blob_srv_lpn_pull -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_transfer_lpn_psa \ blob_cli_friend_pull \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp_block.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp_block.sh index 73728d1f141..a30a54f79ff 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp_block.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp_block.sh @@ -4,13 +4,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh -conf=prj_mesh1d1_conf RunTest blob_no_rsp_block_get \ blob_cli_fail_on_no_rsp \ blob_srv_fail_on_block_get \ blob_srv_fail_on_block_get -- -argstest msg-fail-type=0 -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_no_rsp_block_get_psa \ blob_cli_fail_on_no_rsp \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp_xfer.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp_xfer.sh index 4137deba007..4ecc650aa8f 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp_xfer.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp_xfer.sh @@ -4,13 +4,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh -conf=prj_mesh1d1_conf RunTest blob_no_rsp_xfer_get \ blob_cli_fail_on_no_rsp \ blob_srv_fail_on_xfer_get \ blob_srv_fail_on_xfer_get -- -argstest msg-fail-type=1 -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_no_rsp_xfer_get_psa \ blob_cli_fail_on_no_rsp \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh index e5bb421af14..a7cfdac206d 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh @@ -5,7 +5,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf RunTest blob_fail \ blob_cli_fail_on_persistency \ blob_srv_fail_on_block_start\ @@ -13,7 +12,6 @@ RunTest blob_fail \ blob_srv_fail_on_xfer_get \ blob_srv_fail_on_nothing -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_fail_psa \ blob_cli_fail_on_persistency \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh index 8ead73c4ec7..11bafde8fbc 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh @@ -5,13 +5,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test that BLOB Client continues BLOB Transfer after one target timed out while sending chunks. -conf=prj_mesh1d1_conf RunTest blob_pst_pull \ blob_cli_trans_persistency_pull \ blob_srv_trans_persistency_pull \ blob_srv_trans_persistency_pull -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_pst_pull_psa \ blob_cli_trans_persistency_pull \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh index fdb1a8020e1..2e89819bb1f 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh @@ -5,13 +5,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test that BLOB Transfer completes successfully in Pull mode -conf=prj_mesh1d1_conf RunTest blob_success_pull blob_cli_trans_complete \ blob_srv_trans_complete blob_srv_trans_complete \ blob_srv_trans_complete blob_srv_trans_complete \ -- -argstest use-pull-mode=1 -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_success_pull_psa blob_cli_trans_complete \ blob_srv_trans_complete blob_srv_trans_complete \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh index 5345eab11e8..9695d1bb941 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh @@ -5,12 +5,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test that BLOB Transfer completes successfully in Push mode -conf=prj_mesh1d1_conf RunTest blob_success_push blob_cli_trans_complete \ blob_srv_trans_complete blob_srv_trans_complete \ blob_srv_trans_complete blob_srv_trans_complete -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_success_push_psa blob_cli_trans_complete \ blob_srv_trans_complete blob_srv_trans_complete \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh index 5b05446694b..4459c4419b4 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh @@ -5,11 +5,9 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test that BLOB Client can resume a suspended BLOB Transfer in Pull mode -conf=prj_mesh1d1_conf RunTest blob_resume_pull \ blob_cli_trans_resume blob_srv_trans_resume -- -argstest use-pull-mode=1 -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_resume_pull_psa \ blob_cli_trans_resume blob_srv_trans_resume -- -argstest use-pull-mode=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh index 01150c8b0eb..2bbc627b05c 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh @@ -5,9 +5,7 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test that BLOB Client can resume a suspended BLOB Transfer in Push mode -conf=prj_mesh1d1_conf RunTest blob_resume_push blob_cli_trans_resume blob_srv_trans_resume -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest blob_resume_push_psa blob_cli_trans_resume blob_srv_trans_resume diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_srv_persistence.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_srv_persistence.sh index 8c59c82da6f..9973a82dc49 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_srv_persistence.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_srv_persistence.sh @@ -10,65 +10,53 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Tests with -flash_rm clean up stored settings after them # to run tests with -flash_erase correctly. # Test cases are designed to be run using single target. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash blob_recover_phase \ blob_cli_stop -flash_erase blob_srv_stop -flash_erase -- -argstest expected-phase=1 -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash blob_recover_phase \ blob_cli_stop blob_srv_stop -- -argstest expected-phase=2 -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash blob_recover_phase \ blob_cli_stop blob_srv_stop -- -argstest expected-phase=3 -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash blob_recover_phase \ blob_cli_stop -flash_rm blob_srv_stop -flash_rm -- -argstest expected-phase=4 # Test reaching suspended state and continuation after reboot on new procedure. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash blob_recover_phase \ blob_cli_stop -flash_erase blob_srv_stop -flash_erase -- -argstest expected-phase=5 -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash blob_recover_phase \ blob_cli_stop -flash_rm blob_srv_stop -flash_rm -- -argstest expected-phase=4 # The same test but with PSA crypto -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash blob_recover_phase_psa \ blob_cli_stop -flash_erase blob_srv_stop -flash_erase -- -argstest expected-phase=1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash blob_recover_phase_psa \ blob_cli_stop blob_srv_stop -- -argstest expected-phase=2 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash blob_recover_phase_psa \ blob_cli_stop blob_srv_stop -- -argstest expected-phase=3 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash blob_recover_phase_psa \ blob_cli_stop -flash_rm blob_srv_stop -flash_rm -- -argstest expected-phase=4 # Test reaching suspended state and continuation after reboot on new procedure. -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash blob_recover_phase_psa \ blob_cli_stop -flash_erase blob_srv_stop -flash_erase -- -argstest expected-phase=5 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash blob_recover_phase_psa \ blob_cli_stop -flash_rm blob_srv_stop -flash_rm -- -argstest expected-phase=4 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/comp_data/cdp1_encode_decode.sh b/tests/bsim/bluetooth/mesh/tests_scripts/comp_data/cdp1_encode_decode.sh index e4f99e80d5d..d2a3c5de696 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/comp_data/cdp1_encode_decode.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/comp_data/cdp1_encode_decode.sh @@ -13,11 +13,9 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 0. Provisioning and setup. # 1. Configuration client requests the node's CDP1. # 2. The received CDP1 is compared to a hardcoded version. -conf=prj_mesh1d1_conf RunTest mesh_cdp1_test \ cdp1_node_data_comparison -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_cdp1_test_psa \ cdp1_node_data_comparison diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_apply.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_apply.sh index f612119bdee..4f87fb10fef 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_apply.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_apply.sh @@ -8,7 +8,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # callback is called when all targets are lost at this step. # The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_all_tgts_lost_on_apply \ dfu_cli_all_targets_lost_on_apply \ @@ -17,7 +16,6 @@ RunTest dfu_all_tgts_lost_on_apply \ dfu_target_fail_on_apply \ -- -argstest targets=3 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_all_tgts_lost_on_apply_psa \ dfu_cli_all_targets_lost_on_apply \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_caps_get.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_caps_get.sh index 36dcf8f24ae..572445e4779 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_caps_get.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_caps_get.sh @@ -8,7 +8,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # and `ended` callback is called when all targets are lost at this step. # The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_all_tgts_lost_on_caps_get \ dfu_cli_all_targets_lost_on_caps_get \ @@ -17,7 +16,6 @@ RunTest dfu_all_tgts_lost_on_caps_get \ dfu_target_fail_on_caps_get \ -- -argstest targets=3 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_all_tgts_lost_on_caps_get_psa \ dfu_cli_all_targets_lost_on_caps_get \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_metadata.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_metadata.sh index eacb921a214..e4fbe146dcd 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_metadata.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_metadata.sh @@ -8,7 +8,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # called when all targets are lost at this step. # The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_all_tgts_lost_on_metadata \ dfu_cli_all_targets_lost_on_metadata \ @@ -17,7 +16,6 @@ RunTest dfu_all_tgts_lost_on_metadata \ dfu_target_fail_on_metadata \ -- -argstest targets=3 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_all_tgts_lost_on_metadata_psa \ dfu_cli_all_targets_lost_on_metadata \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_update_get.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_update_get.sh index f6c53482834..7b96161eccd 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_update_get.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_update_get.sh @@ -8,7 +8,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Firmware Update Get message and `ended` callback is called when all targets are lost at this step. # The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_all_tgts_lost_on_update_get \ dfu_cli_all_targets_lost_on_update_get \ @@ -17,7 +16,6 @@ RunTest dfu_all_tgts_lost_on_update_get \ dfu_target_fail_on_update_get \ -- -argstest targets=3 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_all_tgts_lost_on_update_get_psa \ dfu_cli_all_targets_lost_on_update_get \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_verify.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_verify.sh index 929ab93b81e..5daedaca71d 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_verify.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_all_targets_lost_on_verify.sh @@ -8,7 +8,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # callback is called when all targets are lost at this step. # The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_all_tgts_lost_on_verify \ dfu_cli_all_targets_lost_on_verify \ @@ -17,7 +16,6 @@ RunTest dfu_all_tgts_lost_on_verify \ dfu_target_fail_on_verify \ -- -argstest targets=3 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_all_tgts_lost_on_verify_psa \ dfu_cli_all_targets_lost_on_verify \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh index bcc98df48b5..2ff4a696639 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh @@ -5,7 +5,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_persistency \ dfu_cli_fail_on_persistency \ @@ -16,7 +15,6 @@ RunTest dfu_persistency \ dfu_target_fail_on_apply \ dfu_target_fail_on_nothing -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_persistency_psa \ dfu_cli_fail_on_persistency \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update.sh index 64f33013e74..5c00349f24e 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update.sh @@ -4,10 +4,8 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_self_update dfu_dist_dfu_self_update -- -argstest targets=1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_self_update_psa dfu_dist_dfu_self_update -- -argstest targets=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh index af7acb10723..42087f1ad13 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh @@ -4,12 +4,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_self_update_no_change \ dfu_dist_dfu_self_update dfu_target_dfu_no_change -- -argstest targets=2 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_self_update_no_change_psa \ dfu_dist_dfu_self_update dfu_target_dfu_no_change -- -argstest targets=2 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed.sh index bcac2cbba5b..1c5ff82d8fb 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed.sh @@ -5,12 +5,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test DFU with all variants of firmware effect -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_mixed dfu_dist_dfu dfu_target_dfu_unprov dfu_target_dfu_no_change \ dfu_target_dfu_new_comp_rpr dfu_target_dfu_new_comp_no_rpr -- -argstest targets=4 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_mixed_psa dfu_dist_dfu dfu_target_dfu_unprov dfu_target_dfu_no_change \ dfu_target_dfu_new_comp_rpr dfu_target_dfu_new_comp_no_rpr -- -argstest targets=4 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed_fail.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed_fail.sh index c5f67e2521e..3382e458b2e 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed_fail.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed_fail.sh @@ -5,13 +5,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test that confirm step fails with all variants of firmware effect -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_mixed_fail dfu_dist_dfu dfu_target_dfu_unprov dfu_target_dfu_no_change \ dfu_target_dfu_new_comp_rpr dfu_target_dfu_new_comp_no_rpr -- -argstest targets=4 \ fail-confirm=1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_mixed_fail_psa dfu_dist_dfu dfu_target_dfu_unprov dfu_target_dfu_no_change \ dfu_target_dfu_new_comp_rpr dfu_target_dfu_new_comp_no_rpr -- -argstest targets=4 \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot.sh index c187d8cfbff..587908c6497 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot.sh @@ -11,7 +11,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # and verifies they do not exist. # - Fourth test is rebooted device that verifies if removing all slots also removed them # from storage. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash dfu_slot dfu_dist_dfu_slot_create -flash_erase @@ -21,7 +20,6 @@ RunTestFlash dfu_slot dfu_dist_dfu_slot_delete_all RunTestFlash dfu_slot dfu_dist_dfu_slot_check_delete_all -flash_rm -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash dfu_slot_psa dfu_dist_dfu_slot_create -flash_erase diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh index 3f18f1a2651..abce47dba13 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_idempotency.sh @@ -5,10 +5,8 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test DFU Slot API. This test tests that the APIs are idempotent. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_slot_idempotency dfu_dist_dfu_slot_idempotency -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_slot_idempotency_psa dfu_dist_dfu_slot_idempotency diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh index ddd7d0123f5..0ce234116b2 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot_reservation.sh @@ -5,10 +5,8 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test DFU Slot API. This test tests slot reservation APIs. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest dfu_slot_reservation dfu_dist_dfu_slot_reservation -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest dfu_slot_reservation_psa dfu_dist_dfu_slot_reservation diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_srv_persistence.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_srv_persistence.sh index 6ed7099c987..b18a949b43d 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_srv_persistence.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_srv_persistence.sh @@ -13,32 +13,27 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # image index were loaded correctly. # Test cases are designed to be run using single target. `dfu_cli_stop` test case in recovery part # plays dummy role, and is there to keep order of settings files being loaded. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash dfu_dist_recover_phase \ dfu_cli_stop -flash_erase dfu_target_dfu_stop -flash_erase \ -- -argstest recover=0 expected-phase=2 -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash dfu_dist_recover_phase \ dfu_cli_stop dfu_target_dfu_stop \ -- -argstest recover=1 expected-phase=3 -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash dfu_dist_recover_phase \ dfu_cli_stop dfu_target_dfu_stop \ -- -argstest recover=1 expected-phase=4 -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash dfu_dist_recover_phase \ dfu_cli_stop dfu_target_dfu_stop \ -- -argstest recover=1 expected-phase=6 # Use phase `BT_MESH_DFU_PHASE_APPLY_SUCCESS` as marker to bring whole procedure to an end -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash dfu_dist_recover_phase \ dfu_cli_stop -flash_rm dfu_target_dfu_stop -flash_rm \ @@ -46,45 +41,38 @@ RunTestFlash dfu_dist_recover_phase \ # To test recovery from Verify Fail begin new distribution that will end there, # reboot devices and continue to Applying. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash dfu_dist_recover_phase \ dfu_cli_stop -flash_erase dfu_target_dfu_stop -flash_erase \ -- -argstest recover=0 expected-phase=5 -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash dfu_dist_recover_phase \ dfu_cli_stop -flash_rm dfu_target_dfu_stop -flash_rm \ -- -argstest recover=1 expected-phase=6 # The same test but with PSA crypto -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash dfu_dist_recover_phase_psa \ dfu_cli_stop -flash_erase dfu_target_dfu_stop -flash_erase \ -- -argstest recover=0 expected-phase=2 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash dfu_dist_recover_phase_psa \ dfu_cli_stop dfu_target_dfu_stop \ -- -argstest recover=1 expected-phase=3 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash dfu_dist_recover_phase_psa \ dfu_cli_stop dfu_target_dfu_stop \ -- -argstest recover=1 expected-phase=4 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash dfu_dist_recover_phase_psa \ dfu_cli_stop dfu_target_dfu_stop \ -- -argstest recover=1 expected-phase=6 # Use phase `BT_MESH_DFU_PHASE_APPLY_SUCCESS` as marker to bring whole procedure to an end -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash dfu_dist_recover_phase_psa \ dfu_cli_stop -flash_rm dfu_target_dfu_stop -flash_rm \ @@ -92,13 +80,11 @@ RunTestFlash dfu_dist_recover_phase_psa \ # To test recovery from Verify Fail begin new distribution that will end there, # reboot devices and continue to Applying. -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash dfu_dist_recover_phase_psa \ dfu_cli_stop -flash_erase dfu_target_dfu_stop -flash_erase \ -- -argstest recover=0 expected-phase=5 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash dfu_dist_recover_phase_psa \ dfu_cli_stop -flash_rm dfu_target_dfu_stop -flash_rm \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish.sh index b89ad3af2c7..d1082fa9f29 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish.sh @@ -9,12 +9,6 @@ RunTest mesh_friendship_est \ friendship_friend_est \ friendship_lpn_est -conf=prj_mesh1d1_conf -RunTest mesh_friendship_est_1d1 \ - friendship_friend_est \ - friendship_lpn_est - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_friendship_est_psa \ friendship_friend_est \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish_multi.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish_multi.sh index 725ddae596e..32e4752123d 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish_multi.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish_multi.sh @@ -14,16 +14,6 @@ RunTest mesh_friendship_est_multi \ friendship_lpn_est \ friendship_lpn_est -conf=prj_mesh1d1_conf -RunTest mesh_friendship_est_multi_1d1 \ - friendship_friend_est_multi \ - friendship_lpn_est \ - friendship_lpn_est \ - friendship_lpn_est \ - friendship_lpn_est \ - friendship_lpn_est - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_friendship_est_multi_psa \ friendship_friend_est_multi \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_disable.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_disable.sh index be22829d615..f8e24e51a3b 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_disable.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_disable.sh @@ -16,12 +16,6 @@ RunTest mesh_lpn_disable_check \ friendship_friend_no_est \ friendship_lpn_disable -conf=prj_mesh1d1_conf -RunTest mesh_lpn_disable_check_1d1 \ - friendship_friend_no_est \ - friendship_lpn_disable - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_lpn_disable_check_psa \ friendship_friend_no_est \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_loopback.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_loopback.sh index 676b6b81ccc..7c42d7912ff 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_loopback.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_loopback.sh @@ -9,12 +9,6 @@ RunTest mesh_friendship_lpn_loopback \ friendship_lpn_loopback \ friendship_friend_est -conf=prj_mesh1d1_conf -RunTest mesh_friendship_lpn_loopback_1d1 \ - friendship_lpn_loopback \ - friendship_friend_est - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_friendship_lpn_loopback_psa \ friendship_lpn_loopback \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_terminate_cb.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_terminate_cb.sh index 75163076af4..e51fec31dd2 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_terminate_cb.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_terminate_cb.sh @@ -14,12 +14,6 @@ RunTest mesh_lpn_terminate_cb_check \ friendship_friend_est \ friendship_lpn_term_cb_check -conf=prj_mesh1d1_conf -RunTest mesh_lpn_terminate_cb_check_1d1 \ - friendship_friend_est \ - friendship_lpn_term_cb_check - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_lpn_terminate_cb_check_psa \ friendship_friend_est \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_frnd.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_frnd.sh index 94d6224da5b..2329ed289eb 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_frnd.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_frnd.sh @@ -9,12 +9,6 @@ RunTest mesh_friendship_msg_frnd \ friendship_friend_msg \ friendship_lpn_msg_frnd -conf=prj_mesh1d1_conf -RunTest mesh_friendship_msg_frnd_1d1 \ - friendship_friend_msg \ - friendship_lpn_msg_frnd - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_friendship_msg_frnd_psa \ friendship_friend_msg \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_group.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_group.sh index 6e7287b00ff..d6de655ba5b 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_group.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_group.sh @@ -10,13 +10,6 @@ RunTest mesh_friendship_msg_group \ friendship_other_group \ friendship_friend_group -conf=prj_mesh1d1_conf -RunTest mesh_friendship_msg_group_1d1 \ - friendship_lpn_group \ - friendship_other_group \ - friendship_friend_group - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_friendship_msg_group_psa \ friendship_lpn_group \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh.sh index 072e427d72a..f05261bb258 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh.sh @@ -10,13 +10,6 @@ RunTest mesh_friendship_msg_mesh \ friendship_other_msg \ friendship_friend_est -conf=prj_mesh1d1_conf -RunTest mesh_friendship_msg_mesh_1d1 \ - friendship_lpn_msg_mesh \ - friendship_other_msg \ - friendship_friend_est - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_friendship_msg_mesh_psa \ friendship_lpn_msg_mesh \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh index d659281e4e9..3352d5812e6 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh @@ -11,14 +11,6 @@ RunTest mesh_friendship_msg_mesh_low_lat \ friendship_other_msg \ friendship_friend_est -conf=prj_mesh1d1_conf -overlay=overlay_low_lat_conf -RunTest mesh_friendship_msg_mesh_low_lat_1d1 \ - friendship_lpn_msg_mesh \ - friendship_other_msg \ - friendship_friend_est - -conf=prj_mesh1d1_conf overlay="overlay_low_lat_conf_overlay_psa_conf" RunTest mesh_friendship_msg_mesh_low_lat_psa \ friendship_lpn_msg_mesh \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_va_collision.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_va_collision.sh index 360095d2e5f..3ec9cd29162 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_va_collision.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_va_collision.sh @@ -24,12 +24,6 @@ RunTest mesh_friendship_msg_va_collision \ friendship_lpn_va_collision \ friendship_friend_va_collision -conf=prj_mesh1d1_conf -RunTest mesh_friendship_msg_va_collision_1d1 \ - friendship_lpn_va_collision \ - friendship_friend_va_collision - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_friendship_msg_va_collision_psa \ friendship_lpn_va_collision \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/overflow.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/overflow.sh index d717be60292..90398fb4d8a 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/overflow.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/overflow.sh @@ -9,12 +9,6 @@ RunTest mesh_friendship_overflow \ friendship_friend_overflow \ friendship_lpn_overflow -conf=prj_mesh1d1_conf -RunTest mesh_friendship_overflow_1d1 \ - friendship_friend_overflow \ - friendship_lpn_overflow - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_friendship_overflow_psa \ friendship_friend_overflow \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/poll.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/poll.sh index 90e744a7001..328050ba39e 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/poll.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/poll.sh @@ -9,12 +9,6 @@ RunTest mesh_friendship_poll \ friendship_friend_est \ friendship_lpn_poll -conf=prj_mesh1d1_conf -RunTest mesh_friendship_poll_1d1 \ - friendship_friend_est \ - friendship_lpn_poll - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_friendship_poll_psa \ friendship_friend_est \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/re-establish.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/re-establish.sh index 10abb4413ea..27b3e07e5f6 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/friendship/re-establish.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/re-establish.sh @@ -9,12 +9,6 @@ RunTest mesh_friendship_re_est \ friendship_friend_est \ friendship_lpn_re_est -conf=prj_mesh1d1_conf -RunTest mesh_friendship_re_est_1d1 \ - friendship_friend_est \ - friendship_lpn_re_est - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_friendship_re_est_psa \ friendship_friend_est \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh b/tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh index eef25d08cf2..5bef1473a07 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh @@ -10,13 +10,6 @@ RunTest mesh_heartbeat_sub_cb_api_all \ heartbeat_publish_all \ heartbeat_subscribe_all -conf=prj_mesh1d1_conf -RunTest mesh_heartbeat_sub_cb_api_all_1d1 \ - heartbeat_publish_all \ - heartbeat_publish_all \ - heartbeat_subscribe_all - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_heartbeat_sub_cb_api_all_psa \ heartbeat_publish_all \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh b/tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh index fc0660e5676..93b1e2ffe9f 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh @@ -10,13 +10,6 @@ RunTest mesh_heartbeat_sub_cb_api_unicast \ heartbeat_publish_unicast \ heartbeat_subscribe_unicast -conf=prj_mesh1d1_conf -RunTest mesh_heartbeat_sub_cb_api_unicast_1d1 \ - heartbeat_publish_unicast \ - heartbeat_publish_unicast \ - heartbeat_subscribe_unicast - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_heartbeat_sub_cb_api_unicast_psa \ heartbeat_publish_unicast \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_deferring.sh b/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_deferring.sh index cdf39dac438..6696b28ae00 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_deferring.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_deferring.sh @@ -7,9 +7,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # test deferring of the IV index update procedure RunTest mesh_ivi_deferring ivi_ivu_deferring -conf=prj_mesh1d1_conf -RunTest mesh_ivi_deferring_1d1 ivi_ivu_deferring - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_ivi_deferring_psa ivi_ivu_deferring diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_recovery.sh b/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_recovery.sh index 39514bf39e6..a827f9b3abf 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_recovery.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_recovery.sh @@ -7,9 +7,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # test IV index recovery procedure RunTest mesh_ivi_recovery ivi_ivu_recovery -conf=prj_mesh1d1_conf -RunTest mesh_ivi_recovery_1d1 ivi_ivu_recovery - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_ivi_recovery_psa ivi_ivu_recovery diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_update.sh b/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_update.sh index ee2b6b20000..f2f652012b8 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_update.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_update.sh @@ -7,9 +7,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # test IV index update procedure RunTest mesh_ivi_update ivi_ivu_normal -conf=prj_mesh1d1_conf -RunTest mesh_ivi_update_1d1 ivi_ivu_normal - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_ivi_update_psa ivi_ivu_normal diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp0_data_split.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp0_data_split.sh index d65326b3d7f..dcaba598a57 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp0_data_split.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp0_data_split.sh @@ -19,12 +19,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp0_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=0 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp0_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=0 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp0_data_split_dfu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp0_data_split_dfu.sh index 6a65a2492ed..004a5224961 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp0_data_split_dfu.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp0_data_split_dfu.sh @@ -20,13 +20,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp0_data_split_dfu \ lcd_srv_comp_data_status_respond \ lcd_cli_split_comp_data_request -- -argstest page=0 comp-changed-mode=1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp0_data_split_dfu \ lcd_srv_comp_data_status_respond \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp128_data_split.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp128_data_split.sh index 77d4a1737a5..f88db1b7391 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp128_data_split.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp128_data_split.sh @@ -19,12 +19,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp128_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=128 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp128_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=128 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp128_data_split_dfu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp128_data_split_dfu.sh index 9abdfd00dd7..084125c79a4 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp128_data_split_dfu.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp128_data_split_dfu.sh @@ -20,13 +20,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp128_data_split_dfu \ lcd_srv_comp_data_status_respond \ lcd_cli_split_comp_data_request -- -argstest page=128 comp-changed-mode=1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp128_data_split_dfu \ lcd_srv_comp_data_status_respond \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp129_data_split.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp129_data_split.sh index fba1760cb36..ab46d32048f 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp129_data_split.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp129_data_split.sh @@ -19,12 +19,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp129_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=129 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp129_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=129 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp129_data_split_dfu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp129_data_split_dfu.sh index 282c3425c81..179c052e0ef 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp129_data_split_dfu.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp129_data_split_dfu.sh @@ -20,13 +20,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp129_data_split_dfu \ lcd_srv_comp_data_status_respond \ lcd_cli_split_comp_data_request -- -argstest page=129 comp-changed-mode=1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp129_data_split_dfu \ lcd_srv_comp_data_status_respond \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp130_data_split.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp130_data_split.sh index e3e8f2bad85..eb25353581b 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp130_data_split.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp130_data_split.sh @@ -19,12 +19,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp130_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=130 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp130_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=130 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp130_data_split_dfu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp130_data_split_dfu.sh index 5daf32c54c0..a667f53abc8 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp130_data_split_dfu.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp130_data_split_dfu.sh @@ -20,13 +20,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp130_data_split_dfu \ lcd_srv_comp_data_status_respond \ lcd_cli_split_comp_data_request -- -argstest page=130 comp-changed-mode=1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp130_data_split_dfu \ lcd_srv_comp_data_status_respond \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp1_data_split.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp1_data_split.sh index bc24a9c9bf9..06312cf558b 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp1_data_split.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp1_data_split.sh @@ -19,12 +19,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp1_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp1_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp1_data_split_dfu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp1_data_split_dfu.sh index 59383bb18f1..61f19ea3dcc 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp1_data_split_dfu.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp1_data_split_dfu.sh @@ -20,13 +20,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp1_data_split_dfu \ lcd_srv_comp_data_status_respond \ lcd_cli_split_comp_data_request -- -argstest page=1 comp-changed-mode=1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp1_data_split_dfu \ lcd_srv_comp_data_status_respond \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp2_data_split.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp2_data_split.sh index 53def43d5a0..3da45434ee1 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp2_data_split.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp2_data_split.sh @@ -19,12 +19,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp2_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=2 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp2_data_split \ lcd_srv_comp_data_status_respond lcd_cli_split_comp_data_request -- -argstest page=2 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp2_data_split_dfu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp2_data_split_dfu.sh index f314f00d6ef..8ad929f1374 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp2_data_split_dfu.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp2_data_split_dfu.sh @@ -20,13 +20,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # comp data with correspending bytes in local comp data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_comp2_data_split_dfu \ lcd_srv_comp_data_status_respond \ lcd_cli_split_comp_data_request -- -argstest page=2 comp-changed-mode=1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_comp2_data_split_dfu \ lcd_srv_comp_data_status_respond \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh index b050037ccf0..71a692fa22c 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh @@ -14,12 +14,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 3. When server status arrive, remove status field data and compare received # comp data with local comp data and assure that the received message length # is 378 bytes (380 bytes access payload). -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_max_access_payload \ lcd_cli_max_sdu_comp_data_request lcd_srv_comp_data_status_respond -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_max_access_payload_psa \ lcd_cli_max_sdu_comp_data_request lcd_srv_comp_data_status_respond diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh index 9b0be5ea20f..ef0f5712526 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh @@ -15,12 +15,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # is 378 bytes (380 bytes access payload). # 4. Remove status field data and compare received metadata with # local metadata data. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_max_metadata_access_payload \ lcd_cli_max_sdu_metadata_request lcd_srv_metadata_status_respond -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_max_metadata_access_payload_psa \ lcd_cli_max_sdu_metadata_request lcd_srv_metadata_status_respond diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_split.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_split.sh index 0e29e7d4219..38e43f88601 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_split.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_split.sh @@ -18,12 +18,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # received metadata with corresponding bytes in local data. # 6. Client merges the two samples and checks that the collected data is # correctly merged, continuous, and matches its local metadata. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTest mesh_lcd_test_split_metadata \ lcd_cli_split_metadata_request lcd_srv_metadata_status_respond -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_lcd_test_split_metadata_psa \ lcd_cli_split_metadata_request lcd_srv_metadata_status_respond diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/full_status_msg_list.sh b/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/full_status_msg_list.sh index fb60110ad7b..7a226017470 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/full_status_msg_list.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/full_status_msg_list.sh @@ -22,11 +22,9 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 6. The client keeps track of the number of received status messages. When X messages have been # received, the client pass if the sequence of received status messages corresponds to the order # in which the messages were sent, or the test fails. -conf=prj_mesh1d1_conf RunTest mesh_op_agg_test_max_access_payload \ op_agg_cli_max_len_sequence_msg_send op_agg_srv_max_len_status_msg_send -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_op_agg_test_max_access_payload_psa \ op_agg_cli_max_len_sequence_msg_send op_agg_srv_max_len_status_msg_send diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/loopback.sh b/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/loopback.sh index 3a4720bdaf4..7d2c7eec7d2 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/loopback.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/loopback.sh @@ -12,11 +12,9 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 2. The device starts sending the sequence on loopback. # 3. The device verifies that the sequence is correctly received by the server model. # 4. The device confirms that the client model received all status messages. -conf=prj_mesh1d1_conf RunTest mesh_op_agg_model_coex_loopback \ op_agg_dut_model_coex_loopback -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_op_agg_model_coex_loopback \ op_agg_dut_model_coex_loopback diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/model_coex.sh b/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/model_coex.sh index 08fcdf9f41e..928abd666f9 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/model_coex.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/model_coex.sh @@ -21,11 +21,9 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # aggregated sequence from the DUT device is correctly received. # 5. Finally, the DUT device waits and confirms that it received all status messages # related to its own aggregated sequence from the cli device. -conf=prj_mesh1d1_conf RunTest mesh_op_agg_model_coex \ op_agg_tester_model_coex op_agg_dut_model_coex -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_op_agg_model_coex \ op_agg_tester_model_coex op_agg_dut_model_coex diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/persistence/access.sh b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/access.sh index 0392430adba..cf9ec54faec 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/persistence/access.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/access.sh @@ -31,60 +31,25 @@ overlay=overlay_pst_conf RunTestFlash mesh_pst_access_data_check persistence_access_data_load -flash_rm \ -- -argstest access-cfg=not-configured -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_access_data_check_1d1 persistence_access_data_save -flash_erase - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_access_data_check_1d1 persistence_access_data_load \ - -- -argstest access-cfg=configured - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_access_data_check_1d1 persistence_access_sub_overwrite \ - -- -argstest access-cfg=configured - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_access_data_check_1d1 persistence_access_data_load \ - -- -argstest access-cfg=new-subs - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_access_data_check_1d1 persistence_access_data_remove \ - -- -argstest access-cfg=new-subs - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_access_data_check_1d1 persistence_access_data_load -flash_rm \ - -- -argstest access-cfg=not-configured - -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_access_data_check_psa persistence_access_data_save -flash_erase -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_access_data_check_psa persistence_access_data_load \ -- -argstest access-cfg=configured -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_access_data_check_psa persistence_access_sub_overwrite \ -- -argstest access-cfg=configured -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_access_data_check_psa persistence_access_data_load \ -- -argstest access-cfg=new-subs -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_access_data_check_psa persistence_access_data_remove \ -- -argstest access-cfg=new-subs -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_access_data_check_psa persistence_access_data_load -flash_rm \ -- -argstest access-cfg=not-configured diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/persistence/cfg.sh b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/cfg.sh index bb3074905a9..f9655ef7462 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/persistence/cfg.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/cfg.sh @@ -24,42 +24,18 @@ overlay=overlay_pst_conf RunTestFlash mesh_pst_cfg_check persistence_cfg_load -flash_rm \ -- -argstest stack-cfg=1 -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_cfg_check_1d1 persistence_cfg_save -flash_erase \ - -- -argstest stack-cfg=0 - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_cfg_check_1d1 persistence_cfg_load -flash_rm \ - -- -argstest stack-cfg=0 - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_cfg_check_1d1 persistence_cfg_save -flash_erase \ - -- -argstest stack-cfg=1 - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_cfg_check_1d1 persistence_cfg_load -flash_rm \ - -- -argstest stack-cfg=1 - -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_cfg_check_psa persistence_cfg_save -flash_erase \ -- -argstest stack-cfg=0 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_cfg_check_psa persistence_cfg_load -flash_rm \ -- -argstest stack-cfg=0 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_cfg_check_psa persistence_cfg_save -flash_erase \ -- -argstest stack-cfg=1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_cfg_check_psa persistence_cfg_load -flash_rm \ -- -argstest stack-cfg=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/persistence/provisioning.sh b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/provisioning.sh index f1e0591ef13..8dc7baa3e9d 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/persistence/provisioning.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/provisioning.sh @@ -16,18 +16,8 @@ RunTestFlash mesh_pst_prov_data_check persistence_provisioning_data_save -flash_ overlay=overlay_pst_conf RunTestFlash mesh_pst_prov_data_check persistence_provisioning_data_load -flash_rm -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_prov_data_check_1d1 persistence_provisioning_data_save -flash_erase - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTestFlash mesh_pst_prov_data_check_1d1 persistence_provisioning_data_load -flash_rm - -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_prov_data_check_psa persistence_provisioning_data_save -flash_erase -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_pst_prov_data_check_psa persistence_provisioning_data_load -flash_rm diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/persistence/reprovisioning.sh b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/reprovisioning.sh index 922b4c8a513..511c04f766f 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/persistence/reprovisioning.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/reprovisioning.sh @@ -20,25 +20,11 @@ RunTest mesh_pst_repr persistence_reprovisioning_device \ -flash=../results/mesh_pst_repr/flash.bin -flash_rm \ persistence_reprovisioning_provisioner -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_repr_1d1 persistence_reprovisioning_device \ - -flash=../results/mesh_pst_repr_1d1/flash.bin -flash_erase \ - persistence_reprovisioning_provisioner - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_repr_1d1 persistence_reprovisioning_device \ - -flash=../results/mesh_pst_repr_1d1/flash.bin -flash_rm \ - persistence_reprovisioning_provisioner - -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_pst_repr_psa persistence_reprovisioning_device \ -flash=../results/mesh_pst_repr_psa/flash.bin -flash_erase \ persistence_reprovisioning_provisioner -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_pst_repr_psa persistence_reprovisioning_device \ -flash=../results/mesh_pst_repr_psa/flash.bin -flash_rm \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_adv.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_adv.sh index 48724dd7fbd..36c322a54da 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_adv.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_adv.sh @@ -6,9 +6,7 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test Private Beacon advertising on node supporting relay feature. # Test Random value changes for different Random intervals (10s, 0 - on every beacon, 30s). -conf=prj_mesh1d1_conf RunTest mesh_priv_beacon_adv beacon_rx_priv_adv beacon_tx_priv_adv -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_priv_beacon_adv_psa beacon_rx_priv_adv beacon_tx_priv_adv diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_cache.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_cache.sh index 0cb5cdaea0a..46a460c7ec7 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_cache.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_cache.sh @@ -12,12 +12,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 2. TX device sends a secondary private beacons to the RX device, marking the end of the test. # 3. RX device verifies that only one of the two identical beacons was processed. -conf=prj_mesh1d1_conf RunTest mesh_priv_beacon_cache \ beacon_tx_priv_beacon_cache \ beacon_rx_priv_beacon_cache -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_priv_beacon_cache \ beacon_tx_priv_beacon_cache \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_interleave.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_interleave.sh index 6d574a72c73..cda94a89d93 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_interleave.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_interleave.sh @@ -15,9 +15,7 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # - PRB is disabled, SNB enabled: second SNB is advertised # - KR is initiated, third SNB is advertised with new flags (IVU + KR) # - PRB is enabled, SNB is disabled. Third PRB is advertised -conf=prj_mesh1d1_conf RunTest mesh_priv_beacon_interleave beacon_rx_priv_interleave beacon_tx_priv_interleave -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_priv_beacon_interleave_psa beacon_rx_priv_interleave beacon_tx_priv_interleave diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_invalid.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_invalid.sh index b1983284a51..028ba0eabff 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_invalid.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_invalid.sh @@ -5,9 +5,7 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test if Private Beacons with invalid data do not affect device -conf=prj_mesh1d1_conf RunTest mesh_priv_beacon_invalid beacon_rx_priv_invalid beacon_tx_priv_invalid -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_priv_beacon_invalid_psa beacon_rx_priv_invalid beacon_tx_priv_invalid diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_ivu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_ivu.sh index bb9a591fcb0..32232573305 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_ivu.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_ivu.sh @@ -5,13 +5,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test Private Beacon advertising during IV Update procedure -conf=prj_mesh1d1_conf RunTest mesh_priv_beacon_on_iv_update \ beacon_rx_on_iv_update \ beacon_tx_priv_on_iv_update \ -- -argstest rand-int=1 -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_priv_beacon_on_iv_update_psa \ beacon_rx_on_iv_update \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_ivu_long_interval.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_ivu_long_interval.sh index ad0d11dbc96..d44ba297a0e 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_ivu_long_interval.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_ivu_long_interval.sh @@ -7,13 +7,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test Private Beacon advertising during IV Update procedure, with long Random Interval set. # Random value is expected to change before Random Interval is reached due to # Flags field change. -conf=prj_mesh1d1_conf RunTest mesh_priv_beacon_on_iv_update_long_interval \ beacon_rx_on_iv_update \ beacon_tx_priv_on_iv_update \ -- -argstest rand-int=3 -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_priv_beacon_on_iv_update_long_interval_psa \ beacon_rx_on_iv_update \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_kr.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_kr.sh index eaf6338684f..59fe95658c2 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_kr.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_kr.sh @@ -5,13 +5,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test Private Beacon advertising during Key Refresh procedure -conf=prj_mesh1d1_conf RunTest mesh_priv_beacon_on_key_refresh \ beacon_rx_on_key_refresh \ beacon_tx_priv_on_key_refresh \ -- -argstest rand-int=1 -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_priv_beacon_on_key_refresh_psa \ beacon_rx_on_key_refresh \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_kr_long_interval.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_kr_long_interval.sh index cc5722e4432..b0ec45b3f1d 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_kr_long_interval.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_beacon_kr_long_interval.sh @@ -7,13 +7,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test Private Beacon advertising during Key Refresh procedure, with long Random Interval set. # Random value is expected to change before Random Interval is reached due to # Flags field change. -conf=prj_mesh1d1_conf RunTest mesh_priv_beacon_on_key_refresh_long_interval \ beacon_rx_on_key_refresh \ beacon_tx_priv_on_key_refresh \ -- -argstest rand-int=3 -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_priv_beacon_on_key_refresh_long_interval_psa \ beacon_rx_on_key_refresh \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_gatt.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_gatt.sh index a1b9ea7d8d6..8080b6ec70f 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_gatt.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_gatt.sh @@ -17,13 +17,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 4. Both TX and RX device verifies that the IV index has been updated. # This proves that the RX device (Proxy CLI) successfully received # a Private beacon over the GATT connection -conf=prj_mesh1d1_conf overlay=overlay_gatt_conf RunTest mesh_priv_proxy_gatt_priv_beacon \ beacon_tx_priv_gatt_proxy \ beacon_rx_priv_gatt_proxy -conf=prj_mesh1d1_conf overlay=overlay_gatt_conf_overlay_psa_conf RunTest mesh_priv_proxy_gatt_priv_beacon \ beacon_tx_priv_gatt_proxy \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_net_id.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_net_id.sh index 02fcf03c001..a431cdd9f6b 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_net_id.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_net_id.sh @@ -18,13 +18,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 5. Test passes if the random field of the two Private Net ID advertisements # are NOT equal. -conf=prj_mesh1d1_conf overlay=overlay_gatt_conf RunTest mesh_priv_proxy_net_id \ beacon_tx_priv_net_id \ beacon_rx_priv_net_id -conf=prj_mesh1d1_conf overlay=overlay_gatt_conf_overlay_psa_conf RunTest mesh_priv_proxy_net_id \ beacon_tx_priv_net_id \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_net_id_multi.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_net_id_multi.sh index 9d89b5af36c..cffb5adbeb0 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_net_id_multi.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_net_id_multi.sh @@ -15,13 +15,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # advertisemen from each of the networks within the given time # limit. -conf=prj_mesh1d1_conf overlay=overlay_gatt_conf RunTest mesh_priv_proxy_net_id_multi \ beacon_tx_priv_multi_net_id \ beacon_rx_priv_multi_net_id -conf=prj_mesh1d1_conf overlay=overlay_gatt_conf_overlay_psa_conf RunTest mesh_priv_proxy_net_id_multi \ beacon_tx_priv_multi_net_id \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_node_id.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_node_id.sh index 2aff351bd78..2557c9c1506 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_node_id.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_node_id.sh @@ -23,13 +23,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 5. Test passes if the random field of the two Private Node ID advertisements # are NOT equal. -conf=prj_mesh1d1_conf overlay=overlay_gatt_conf RunTest mesh_priv_proxy_node_id \ beacon_tx_priv_node_id \ beacon_rx_priv_node_id -conf=prj_mesh1d1_conf overlay=overlay_gatt_conf_overlay_psa_conf RunTest mesh_priv_proxy_node_id \ beacon_tx_priv_node_id \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh index 42863a13458..0a3b5771bfd 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/proxy_adv_multi_subnet_coex.sh @@ -43,14 +43,12 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # to the adv medium again. -conf=prj_mesh1d1_conf overlay=overlay_gatt_conf RunTest proxy_adv_multi_subnet_coex \ beacon_tx_proxy_adv_multi_subnet_coex \ beacon_rx_proxy_adv_multi_subnet_coex \ beacon_tx_proxy_adv_solicit_trigger -conf=prj_mesh1d1_conf overlay=overlay_gatt_conf_overlay_psa_conf RunTest proxy_adv_multi_subnet_coex \ beacon_tx_proxy_adv_multi_subnet_coex \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_one_duration.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_one_duration.sh index 168c2620212..36c996269cf 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_one_duration.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_one_duration.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_prov_iv_update_one_duration prov_provisioner_iv_update_flag_one -conf=prj_mesh1d1_conf -RunTest mesh_prov_iv_update_one_duration_1d1 prov_provisioner_iv_update_flag_one - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_iv_update_one_duration_psa prov_provisioner_iv_update_flag_one diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh index 07165b31c1d..cb3294950f8 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_prov_iv_update_zero_duration prov_provisioner_iv_update_flag_zero -conf=prj_mesh1d1_conf -RunTest mesh_prov_iv_update_zero_duration_1d1 prov_provisioner_iv_update_flag_zero - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_iv_update_zero_duration_psa prov_provisioner_iv_update_flag_zero diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_multi.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_multi.sh index 7d8dfbe6388..61bbbcc1a27 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_multi.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_multi.sh @@ -13,14 +13,6 @@ RunTest mesh_prov_pb_adv_multi \ prov_device_pb_adv_no_oob \ prov_device_pb_adv_no_oob -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_multi_1d1 \ - prov_provisioner_pb_adv_multi \ - prov_device_pb_adv_no_oob \ - prov_device_pb_adv_no_oob \ - prov_device_pb_adv_no_oob - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_multi_psa \ prov_provisioner_pb_adv_multi \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_no_oob.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_no_oob.sh index bfcb8540ae1..91bde356f2b 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_no_oob.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_no_oob.sh @@ -8,12 +8,6 @@ RunTest mesh_prov_pb_adv_on_oob \ prov_device_pb_adv_no_oob \ prov_provisioner_pb_adv_no_oob -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_on_oob_1d1 \ - prov_device_pb_adv_no_oob \ - prov_provisioner_pb_adv_no_oob - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_on_oob_psa \ prov_device_pb_adv_no_oob \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh index 22d197a0adc..ef8e07f7c80 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh @@ -8,11 +8,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_prov_pb_adv_oob_auth \ prov_device_pb_adv_oob_auth prov_provisioner_pb_adv_oob_auth -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_oob_auth_1d1 \ - prov_device_pb_adv_oob_auth prov_provisioner_pb_adv_oob_auth - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_oob_auth_psa \ prov_device_pb_adv_oob_auth prov_provisioner_pb_adv_oob_auth diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh index 5459997e547..8df3c6a4bf6 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh @@ -9,11 +9,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_prov_pb_adv_device_w_oob_pk_prvnr_wt_pk \ prov_device_pb_adv_oob_public_key prov_provisioner_pb_adv_oob_auth_no_oob_public_key -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_device_w_oob_pk_prvnr_wt_pk_1d1 \ - prov_device_pb_adv_oob_public_key prov_provisioner_pb_adv_oob_auth_no_oob_public_key - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_device_w_oob_pk_prvnr_wt_pk_psa \ prov_device_pb_adv_oob_public_key prov_provisioner_pb_adv_oob_auth_no_oob_public_key diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh index b8ab3a5d899..d24e5afccd4 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh @@ -8,11 +8,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_prov_pb_adv_oob_public_key \ prov_device_pb_adv_oob_public_key prov_provisioner_pb_adv_oob_public_key -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_oob_public_key_1d1 \ - prov_device_pb_adv_oob_public_key prov_provisioner_pb_adv_oob_public_key - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_oob_public_key_psa \ prov_device_pb_adv_oob_public_key prov_provisioner_pb_adv_oob_public_key diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_reprovision.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_reprovision.sh index 9c70514a093..0e3b84e3138 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_reprovision.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_reprovision.sh @@ -8,12 +8,6 @@ RunTest mesh_prov_pb_adv_repr \ prov_device_pb_adv_reprovision \ prov_provisioner_pb_adv_reprovision -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_repr_1d1 \ - prov_device_pb_adv_reprovision \ - prov_provisioner_pb_adv_reprovision - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_repr_psa \ prov_device_pb_adv_reprovision \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh index 33de74370e1..9175a9ac015 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_client_server_same_dev.sh @@ -20,12 +20,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # composition refresh procedure on it self with local RPR client and server. # 7. The first device (prov_device_pb_remote_client_server_same_dev) execute # address refresh procedure on it self with local RPR client and server. -conf=prj_mesh1d1_conf RunTest mesh_prov_pb_remote_client_server_same_dev \ prov_device_pb_remote_client_server_same_dev \ prov_device_pb_remote_server_same_dev -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_pb_remote_client_server_same_dev \ prov_device_pb_remote_client_server_same_dev \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh index d707fdb6d6c..a59cf04aef4 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh @@ -13,13 +13,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 4. Execute composition refresh procedure 3 times for the third device. # 5. Execute address refresh procedure 3 times for the third device. # (Step 3-5 is executed without sending a node reset message) -conf=prj_mesh1d1_conf RunTest mesh_prov_pb_remote_nppi_robustness \ prov_provisioner_pb_remote_client_nppi_robustness \ prov_device_pb_remote_server_unproved \ prov_device_pb_remote_server_nppi_robustness -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_pb_remote_nppi_robustness_psa \ prov_provisioner_pb_remote_client_nppi_robustness \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh index 2c3394381cd..6ecb3292193 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh @@ -11,14 +11,12 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 4. The provisioner scans for an unprovisioned device idx 3 through the node with RPR server; # 5. The provisioner checks scanning and provisioning succeeded; # 6. The provisioner provisions an unprovisioned device idx 3 through the node with RPR server; -conf=prj_mesh1d1_conf RunTest mesh_prov_pb_remote_parallel \ prov_provisioner_pb_remote_client_parallel \ prov_device_pb_remote_server_unproved \ prov_device_pb_adv_no_oob \ prov_device_pb_adv_no_oob -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_pb_remote_parallel_psa \ prov_provisioner_pb_remote_client_parallel \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh index ed5f619b310..2bba5147d8f 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh @@ -31,7 +31,6 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # - verify that the device is not re-provisioned again. # Step 1 -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash mesh_prov_pst_pb_remote_ncrp \ prov_provisioner_pb_remote_client_ncrp_provision -flash_erase \ @@ -39,7 +38,6 @@ RunTestFlash mesh_prov_pst_pb_remote_ncrp \ prov_device_pb_remote_server_ncrp_prepare -flash_erase # Step 2 -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash mesh_prov_pst_pb_remote_ncrp \ prov_provisioner_pb_remote_client_ncrp \ @@ -47,7 +45,6 @@ RunTestFlash mesh_prov_pst_pb_remote_ncrp \ prov_device_pb_remote_server_ncrp # Step 3 -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash mesh_prov_pst_pb_remote_ncrp \ prov_provisioner_pb_remote_client_ncrp_second_time -flash_rm \ @@ -56,7 +53,6 @@ RunTestFlash mesh_prov_pst_pb_remote_ncrp \ # The same test but with PSA crypto # Step 1 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_prov_pst_pb_remote_ncrp_psa \ prov_provisioner_pb_remote_client_ncrp_provision -flash_erase \ @@ -64,7 +60,6 @@ RunTestFlash mesh_prov_pst_pb_remote_ncrp_psa \ prov_device_pb_remote_server_ncrp_prepare -flash_erase # Step 2 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_prov_pst_pb_remote_ncrp_psa \ prov_provisioner_pb_remote_client_ncrp \ @@ -72,7 +67,6 @@ RunTestFlash mesh_prov_pst_pb_remote_ncrp_psa \ prov_device_pb_remote_server_ncrp # Step 3 -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash mesh_prov_pst_pb_remote_ncrp_psa \ prov_provisioner_pb_remote_client_ncrp_second_time -flash_rm \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_reprovision.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_reprovision.sh index a49cbcd7ca9..1a2ae89d655 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_reprovision.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_reprovision.sh @@ -12,13 +12,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 5. The provisioner configures the health server on the recently provisioned device and sends Node # Reset; # 6. Repeat steps 3-5 multiple times. -conf=prj_mesh1d1_conf RunTest mesh_prov_pb_remote_reprovision \ prov_provisioner_pb_remote_client_reprovision \ prov_device_pb_remote_server_unproved \ prov_device_pb_adv_reprovision -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_pb_remote_reprovision_psa \ prov_provisioner_pb_remote_client_reprovision \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_timeout.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_timeout.sh index 8ef61c2666b..7feba542c44 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_timeout.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_timeout.sh @@ -24,13 +24,11 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 11. 3rd device opens provisioning link. # 12. 2nd device stops communicating with either devices. # 13. After 60s RPR timeout is reached on 1st device. RPR Client closes provisioning link. -conf=prj_mesh1d1_conf RunTest mesh_prov_pb_remote_provisioning_timeout \ prov_provisioner_pb_remote_client_provision_timeout \ prov_device_pb_remote_server_unproved_unresponsive \ prov_device_unresponsive -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_prov_pb_remote_provisioning_timeout_psa \ prov_provisioner_pb_remote_client_provision_timeout \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/replay_attack.sh b/tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/replay_attack.sh index 50387776dfb..d09e014bd0e 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/replay_attack.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/replay_attack.sh @@ -14,25 +14,11 @@ RunTest mesh_replay_attack \ rpc_tx_power_replay_attack \ rpc_rx_power_replay_attack -flash=../results/mesh_replay_attack/flash.bin -flash_rm -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_replay_attack_1d1 \ - rpc_tx_immediate_replay_attack \ - rpc_rx_immediate_replay_attack -flash=../results/mesh_replay_attack_1d1/flash.bin -flash_erase - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_replay_attack_1d1 \ - rpc_tx_power_replay_attack \ - rpc_rx_power_replay_attack -flash=../results/mesh_replay_attack_1d1/flash.bin -flash_rm - -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_replay_attack_psa \ rpc_tx_immediate_replay_attack \ rpc_rx_immediate_replay_attack -flash=../results/mesh_replay_attack_psa/flash.bin -flash_erase -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_replay_attack_psa \ rpc_tx_power_replay_attack \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/rpl_frag.sh b/tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/rpl_frag.sh index 8c7a7866eb3..7212b567a24 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/rpl_frag.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/rpl_frag.sh @@ -21,24 +21,11 @@ overlay=overlay_pst_conf RunTest mesh_replay_fragmentation \ rpc_rx_reboot_after_defrag -flash=../results/mesh_replay_fragmentation/flash.bin -flash_rm -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_replay_fragmentation_1d1 \ - rpc_rx_rpl_frag -flash=../results/mesh_replay_fragmentation_1d1/flash.bin -flash_erase \ - rpc_tx_rpl_frag - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_replay_fragmentation_1d1 \ - rpc_rx_reboot_after_defrag -flash=../results/mesh_replay_fragmentation_1d1/flash.bin -flash_rm - -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_replay_fragmentation_psa \ rpc_rx_rpl_frag -flash=../results/mesh_replay_fragmentation_psa/flash.bin -flash_erase \ rpc_tx_rpl_frag -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTest mesh_replay_fragmentation_psa \ rpc_rx_reboot_after_defrag -flash=../results/mesh_replay_fragmentation_psa/flash.bin -flash_rm diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/sar/sar_cfg_persistent_storage.sh b/tests/bsim/bluetooth/mesh/tests_scripts/sar/sar_cfg_persistent_storage.sh index dc27c4dceda..0e67d5ab4d5 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/sar/sar_cfg_persistent_storage.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/sar/sar_cfg_persistent_storage.sh @@ -8,12 +8,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Tests must be added in sequence. # First test sets SAR TX/RX configuration. # Second test restores it from flash and checks if configuration persisted. -conf=prj_mesh1d1_conf overlay=overlay_pst_conf RunTestFlash sar_persistence sar_srv_cfg_store -flash_erase RunTestFlash sar_persistence sar_srv_cfg_restore -flash_rm -conf=prj_mesh1d1_conf overlay="overlay_pst_conf_overlay_psa_conf" RunTestFlash sar_persistence_psa sar_srv_cfg_store -flash_erase RunTestFlash sar_persistence_psa sar_srv_cfg_restore -flash_rm diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/sar/slow_transfer_test.sh b/tests/bsim/bluetooth/mesh/tests_scripts/sar/slow_transfer_test.sh index a022c23c3f4..db8f8f9dc21 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/sar/slow_transfer_test.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/sar/slow_transfer_test.sh @@ -14,11 +14,9 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 4. The Client sends a Get-message with a maximum length SDU, targeting the server. # 5. The Server responds with a maximum length SDU Status-message. # 6. The test passes when the Client successfully receives the Status response. -conf=prj_mesh1d1_conf RunTest sar_slow_test \ sar_cli_max_len_sdu_slow_send sar_srv_max_len_sdu_slow_receive -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest sar_slow_test_psa \ sar_cli_max_len_sdu_slow_send sar_srv_max_len_sdu_slow_receive diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/sar/stress_test.sh b/tests/bsim/bluetooth/mesh/tests_scripts/sar/stress_test.sh index 89707adf031..34b05446702 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/sar/stress_test.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/sar/stress_test.sh @@ -13,11 +13,9 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # 4. The Client sends a Get-message with a maximum length SDU, targeting the server. # 5. The Server responds with a maximum length SDU Status-message. # 6. The test passes when the Client successfully receives the Status response. -conf=prj_mesh1d1_conf RunTest sar_test \ sar_cli_max_len_sdu_send sar_srv_max_len_sdu_receive -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest sar_test_psa \ sar_cli_max_len_sdu_send sar_srv_max_len_sdu_receive diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/scanner/invalid_ad_type.sh b/tests/bsim/bluetooth/mesh/tests_scripts/scanner/invalid_ad_type.sh index 9199ac69da8..c46088c5a15 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/scanner/invalid_ad_type.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/scanner/invalid_ad_type.sh @@ -8,12 +8,6 @@ RunTest mesh_scanner_invalid_ad_type \ scanner_tx_invalid_ad_type \ scanner_rx_invalid_packet -conf=prj_mesh1d1_conf -RunTest mesh_scanner_invalid_ad_type_1d1 \ - scanner_tx_invalid_ad_type \ - scanner_rx_invalid_packet - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_scanner_invalid_ad_type_psa \ scanner_tx_invalid_ad_type \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/scanner/wrong_packet_length.sh b/tests/bsim/bluetooth/mesh/tests_scripts/scanner/wrong_packet_length.sh index 8f0919058ed..80f8cacca83 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/scanner/wrong_packet_length.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/scanner/wrong_packet_length.sh @@ -8,12 +8,6 @@ RunTest mesh_scanner_wrong_packet_length \ scanner_tx_wrong_packet_length \ scanner_rx_invalid_packet -conf=prj_mesh1d1_conf -RunTest mesh_scanner_wrong_packet_length_1d1 \ - scanner_tx_wrong_packet_length \ - scanner_rx_invalid_packet - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_scanner_wrong_packet_length_psa \ scanner_tx_wrong_packet_length \ diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/suspend/gatt_suspend_disable_resume.sh b/tests/bsim/bluetooth/mesh/tests_scripts/suspend/gatt_suspend_disable_resume.sh new file mode 100755 index 00000000000..711f92f4007 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/suspend/gatt_suspend_disable_resume.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test that GATT advertisement is stopped when suspending Mesh and disabling +# Bluetooth, and that it is started again when Bluetooth is re-enabled and Mesh is resumed. +# +# Test procedure: +# 0. DUT (Device 0) initializes the Mesh stack, and starts provisioning procedure using +# bt_mesh_prov_enable(BT_MESH_PROV_GATT). +# 1. Tester (Device 1) observes PB-GATT advs, and will fail the test if the expected +# amount of advs is not received. +# 2. DUT is provisioned, and Tester observes GATT proxy advs. +# 3. DUT notifies the Tester that it will be suspended, and Tester observes for advs after a +# brief delay. Receiving an adv while DUT is suspended will cause the test to fail. +# 4. After a delay, the DUT resumes and notifies the Tester, which checks that the +# advertising resumes. + +overlay=overlay_gatt_conf +RunTest mesh_gatt_suspend_disable_resume \ + suspend_dut_gatt_suspend_disable_resume suspend_tester_gatt + +overlay="overlay_gatt_conf_overlay_low_lat_conf" +RunTest mesh_gatt_suspend_disable_resume_low_lat \ + suspend_dut_gatt_suspend_disable_resume suspend_tester_gatt + +overlay="overlay_gatt_conf_overlay_psa_conf" +RunTest mesh_gatt_suspend_disable_resume_psa \ + suspend_dut_gatt_suspend_disable_resume suspend_tester_gatt diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/suspend/gatt_suspend_resume.sh b/tests/bsim/bluetooth/mesh/tests_scripts/suspend/gatt_suspend_resume.sh new file mode 100755 index 00000000000..f0e4fb23502 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/suspend/gatt_suspend_resume.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test that GATT advertisement is stopped when suspending Mesh, and that it is started again +# when Mesh is resumed. +# +# Test procedure: +# 0. DUT (Device 0) initializes the Mesh stack, and starts provisioning procedure using +# bt_mesh_prov_enable(BT_MESH_PROV_GATT). +# 1. Tester (Device 1) observes PB-GATT advs, and will fail the test if the expected +# amount of advs is not received. +# 2. DUT is provisioned, and Tester observes GATT proxy advs. +# 3. DUT notifies the Tester that it will be suspended, and Tester observes for advs after a +# brief delay. Receiving an adv while DUT is suspended will cause the test to fail. +# 4. After a delay, the DUT resumes and notifies the Tester, which checks that the +# advertising resumes. + +overlay=overlay_gatt_conf +RunTest mesh_gatt_suspend_resume \ + suspend_dut_gatt_suspend_resume suspend_tester_gatt + +overlay="overlay_gatt_conf_overlay_low_lat_conf" +RunTest mesh_gatt_suspend_resume_low_lat \ + suspend_dut_gatt_suspend_resume suspend_tester_gatt + +overlay="overlay_gatt_conf_overlay_psa_conf" +RunTest mesh_gatt_suspend_resume_psa \ + suspend_dut_gatt_suspend_resume suspend_tester_gatt diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/suspend/suspend_disable_resume.sh b/tests/bsim/bluetooth/mesh/tests_scripts/suspend/suspend_disable_resume.sh new file mode 100755 index 00000000000..bfe42e15c16 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/suspend/suspend_disable_resume.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test that periodic publication is stopped when suspending Mesh and disabling +# Bluetooth, and that it is started again when Bluetooth is re-enabled and Mesh is resumed. +# The test will fail under two conditions; if no publication is received while +# Mesh is enabled, or if a publication is received while Mesh is suspended. +# +# Test procedure: +# 0. Provisioning and setup. +# 1. Start publication. +# 2. Suspend Mesh and disable Bluetooth, checking that publication stops. +# 3. Enable Bluetooth and resume Mesh a specified time after suspension. +# Check that publication resumes. + +RunTest mesh_suspend_disable_resume \ + suspend_dut_suspend_disable_resume suspend_tester_pub + +overlay=overlay_low_lat_conf +RunTest mesh_suspend_disable_resume_low_lat \ + suspend_dut_suspend_disable_resume suspend_tester_pub + +overlay=overlay_psa_conf +RunTest mesh_suspend_disable_resume_psa \ + suspend_dut_suspend_disable_resume suspend_tester_pub diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/suspend/suspend_resume.sh b/tests/bsim/bluetooth/mesh/tests_scripts/suspend/suspend_resume.sh new file mode 100755 index 00000000000..31d151201a8 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/suspend/suspend_resume.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test that periodic publication is stopped when suspending Mesh, and that it +# is started again when Mesh is resumed. The test will fail under two +# conditions; if no publication is received while Mesh is enabled, +# or if a publication is received while Mesh is suspended. +# +# Test procedure: +# 0. Provisioning and setup. +# 1. Start publication. +# 2. Suspend Mesh, checking that publication stops. +# 3. Resume Mesh a specified time after suspension. Check that publication resumes. + +RunTest mesh_suspend_resume \ + suspend_dut_suspend_resume suspend_tester_pub + +overlay=overlay_low_lat_conf +RunTest mesh_suspend_resume_low_lat \ + suspend_dut_suspend_resume suspend_tester_pub + +overlay=overlay_psa_conf +RunTest mesh_suspend_resume_psa \ + suspend_dut_suspend_resume suspend_tester_pub diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/fixed.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/fixed.sh index d4b86d2f98a..f4d0cfc0cac 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/fixed.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/fixed.sh @@ -15,9 +15,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # model; RunTest mesh_transport_fixed transport_tx_fixed transport_rx_fixed -conf=prj_mesh1d1_conf -RunTest mesh_transport_fixed_1d1 transport_tx_fixed transport_rx_fixed - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_transport_fixed_1d1 transport_tx_fixed transport_rx_fixed diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/group.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/group.sh index d85d7cf8604..7b7c6a559fc 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/group.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/group.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_transport_group transport_tx_group transport_rx_group -conf=prj_mesh1d1_conf -RunTest mesh_transport_group_1d1 transport_tx_group transport_rx_group - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_transport_group_psa transport_tx_group transport_rx_group diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback.sh index 9cc1fb33041..e2812efda23 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest transport_loopback transport_tx_loopback transport_rx_none -conf=prj_mesh1d1_conf -RunTest transport_loopback_1d1 transport_tx_loopback transport_rx_none - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest transport_loopback_psa transport_tx_loopback transport_rx_none diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group.sh index 3be2bb24367..38b6c8dd906 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_transport_loopback_group transport_tx_loopback_group transport_rx_group -conf=prj_mesh1d1_conf -RunTest mesh_transport_loopback_group_1d1 transport_tx_loopback_group transport_rx_group - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_transport_loopback_group_psa transport_tx_loopback_group transport_rx_group diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group_low_lat.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group_low_lat.sh index 63829e012a5..3972edd3034 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group_low_lat.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group_low_lat.sh @@ -7,10 +7,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh overlay=overlay_low_lat_conf RunTest mesh_transport_loopback_group_low_lat transport_tx_loopback_group transport_rx_group -conf=prj_mesh1d1_conf -overlay=overlay_low_lat_conf -RunTest mesh_transport_loopback_group_low_lat_1d1 transport_tx_loopback_group transport_rx_group - -conf=prj_mesh1d1_conf overlay="overlay_low_lat_conf_overlay_psa_conf" RunTest mesh_transport_loopback_group_low_lat_psa transport_tx_loopback_group transport_rx_group diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_block.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_block.sh index 21a56f37478..788d3eeebdf 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_block.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_block.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_transport_seg_block transport_tx_seg_block transport_rx_seg_block -conf=prj_mesh1d1_conf -RunTest mesh_transport_seg_block_1d1 transport_tx_seg_block transport_rx_seg_block - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_transport_seg_block_psa transport_tx_seg_block transport_rx_seg_block diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_concurrent.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_concurrent.sh index 40ba38aae12..d07c90c8d22 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_concurrent.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_concurrent.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_transport_seg_concurrent transport_tx_seg_concurrent transport_rx_seg_concurrent -conf=prj_mesh1d1_conf -RunTest mesh_transport_seg_concurrent_1d1 transport_tx_seg_concurrent transport_rx_seg_concurrent - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_transport_seg_concurrent_psa transport_tx_seg_concurrent transport_rx_seg_concurrent diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_fail.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_fail.sh index ca650ede1f4..72639370b93 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_fail.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_fail.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_transport_seg_fail transport_tx_seg_fail -conf=prj_mesh1d1_conf -RunTest mesh_transport_seg_fail_1d1 transport_tx_seg_fail - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_transport_seg_fail_psa transport_tx_seg_fail diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_ivu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_ivu.sh index 9268e42029e..0ef30273341 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_ivu.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_ivu.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_transport_seg_ivu transport_tx_seg_ivu transport_rx_seg_ivu -conf=prj_mesh1d1_conf -RunTest mesh_transport_seg_ivu_1d1 transport_tx_seg_ivu transport_rx_seg_ivu - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_transport_seg_ivu_psa transport_tx_seg_ivu transport_rx_seg_ivu diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast.sh index a107a86146c..c91397f4f4b 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_transport_unicast transport_tx_unicast transport_rx_unicast -conf=prj_mesh1d1_conf -RunTest mesh_transport_unicast_1d1 transport_tx_unicast transport_rx_unicast - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_transport_unicast_psa transport_tx_unicast transport_rx_unicast diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast_low_lat.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast_low_lat.sh index cbfc8ea5ce7..981347a3385 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast_low_lat.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast_low_lat.sh @@ -7,10 +7,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh overlay=overlay_low_lat_conf RunTest mesh_transport_unicast_low_lat transport_tx_unicast transport_rx_unicast -conf=prj_mesh1d1_conf -overlay=overlay_low_lat_conf -RunTest mesh_transport_unicast_low_lat_1d1 transport_tx_unicast transport_rx_unicast - -conf=prj_mesh1d1_conf overlay="overlay_low_lat_conf_overlay_psa_conf" RunTest mesh_transport_unicast_low_lat_psa transport_tx_unicast transport_rx_unicast diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/unknown_app.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/unknown_app.sh index 2a1b2741b60..6f077ee0c8b 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/unknown_app.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/unknown_app.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_transport_unknown_app transport_tx_unknown_app transport_rx_none -conf=prj_mesh1d1_conf -RunTest mesh_transport_unknown_app_1d1 transport_tx_unknown_app transport_rx_none - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_transport_unknown_app_psa transport_tx_unknown_app transport_rx_none diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/va.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/va.sh index 698bd164485..4336a2aa042 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/va.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/va.sh @@ -6,9 +6,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_transport_va transport_tx_va transport_rx_va -conf=prj_mesh1d1_conf -RunTest mesh_transport_va_1d1 transport_tx_va transport_rx_va - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_transport_va_psa transport_tx_va transport_rx_va diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/transport/va_collision.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/va_collision.sh index 631c43790ef..dbcc3c64bc7 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/transport/va_collision.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/transport/va_collision.sh @@ -7,9 +7,5 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test transmission to virtual addresses with collision RunTest mesh_transport_va_collision transport_tx_va_collision transport_rx_va_collision -conf=prj_mesh1d1_conf -RunTest mesh_transport_va_collision_1d1 transport_tx_va_collision transport_rx_va_collision - -conf=prj_mesh1d1_conf overlay=overlay_psa_conf RunTest mesh_transport_va_collision_psa transport_tx_va_collision transport_rx_va_collision From 6ef5422dbd7c77555b162b2e26146a1e50d80cf6 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:44:24 +0100 Subject: [PATCH 1284/1623] [nrf fromtree] Bluetooth: Mesh: Move mesh-1.1 transport sar configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move mesh 1.1 transport sar configuration under transport menu Signed-off-by: Pavel Vasilyev (cherry picked from commit 6060dfbc7fef9d81cfe887c7ed1230b2621015d0) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 244 +++++++++++++++++----------------- 1 file changed, 120 insertions(+), 124 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 0f38a2e3ba0..d3c3397a63d 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -512,6 +512,126 @@ config BT_MESH_TX_SEG_MAX which leaves 56 bytes for application layer data using a 4-byte MIC and 52 bytes using an 8-byte MIC. +config BT_MESH_SAR_TX_SEG_INT_STEP + hex "Interval between sending two consecutive segments" + range 0x00 0x0F + default 0x05 + help + This value controls the interval between sending two consecutive + segments in a segmented message. The interval is measured in + milliseconds and calculated using the following formula: + (CONFIG_BT_MESH_SAR_TX_SEG_INT_STEP + 1) * 10 ms. + +config BT_MESH_SAR_TX_UNICAST_RETRANS_COUNT + hex "Maximum number of retransmissions to unicast address" + range 0x00 0x0F + default 0x02 + help + This value controls the maximum number of retransmissions of a + segmented message to a unicast address before giving up the transfer. + +config BT_MESH_SAR_TX_UNICAST_RETRANS_WITHOUT_PROG_COUNT + hex "Maximum number of retransmissions without progress to a unicast address" + range 0x00 0x0F + default 0x02 + help + This value defines the maximum number of retransmissions of a + segmented message to a unicast address that the stack will send if no + acknowledgment was received during timeout, or if an + acknowledgment with already confirmed segments was received. + +config BT_MESH_SAR_TX_UNICAST_RETRANS_INT_STEP + hex "Retransmissions interval step of missing segments to unicast address" + range 0x00 0x0F + default 0x07 + help + This value controls the interval step used for delaying the + retransmissions of unacknowledged segments of a segmented message to + a unicast address. The interval step is measured in milliseconds and + calculated using the following formula: + (CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_INT_STEP + 1) * 25 ms. + +config BT_MESH_SAR_TX_UNICAST_RETRANS_INT_INC + hex "Retransmissions interval increment of missing segments to unicast address" + range 0x00 0x0F + default 0x01 + help + This value controls the interval increment used for delaying the + retransmissions of unacknowledged segments of a segmented message to + a unicast address. The increment is measured in milliseconds and + calculated using the following formula: + (CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_INT_INC + 1) * 25 ms. + +config BT_MESH_SAR_TX_MULTICAST_RETRANS_COUNT + hex "Total number of retransmissions to multicast address" + range 0x00 0x0F + default 0x02 + help + This value controls the total number of retransmissions of a segmented + message to a multicast address. + +config BT_MESH_SAR_TX_MULTICAST_RETRANS_INT + hex "Interval between retransmissions to multicast address" + range 0x00 0x0F + default 0x09 + help + This value controls the interval between retransmissions of all + segments in a segmented message to a multicast address. The + interval is measured in milliseconds and calculated using the + following formula: + (CONFIG_BT_MESH_SAR_TX_MULTICAST_RETRANS_INT + 1) * 25 ms. + +config BT_MESH_SAR_RX_SEG_THRESHOLD + hex "Acknowledgments retransmission threshold" + range 0x00 0x1F + default 0x03 + help + This value defines a threshold in number of segments of a segmented + message for acknowledgment retransmissions. When the number of + segments of a segmented message is above this threshold, the stack + will additionally retransmit every acknowledgment message the + number of times given by value of CONFIG_BT_MESH_SAR_RX_ACK_RETRANS_COUNT. + +config BT_MESH_SAR_RX_ACK_DELAY_INC + hex "Acknowledgment delay increment" + range 0x00 0x07 + default 0x01 + help + This value controls the delay increment of an interval used for + delaying the transmission of an acknowledgment message after + receiving a new segment. The increment is measured in segments + and calculated using the following formula: + CONFIG_BT_MESH_SAR_RX_ACK_DELAY_INC + 1.5. + +config BT_MESH_SAR_RX_SEG_INT_STEP + hex "Segments reception interval step" + range 0x00 0x0F + default 0x05 + help + This value defines the segments reception interval step used for + delaying the transmission of an acknowledgment message after + receiving a new segmnet. The interval is measured in milliseconds + and calculated using the following formula: + (CONFIG_BT_MESH_SAR_RX_SEG_INT_STEP + 1) * 10 ms + +config BT_MESH_SAR_RX_DISCARD_TIMEOUT + hex "Discard timeout for reception of a segmented message" + range 0x00 0x0F + default 0x01 + help + This value defines the time since the last successfully received + segment before giving up the reception of a segmented message. + +config BT_MESH_SAR_RX_ACK_RETRANS_COUNT + hex "Total number of acknowledgment message retransmission" + range 0x00 0x03 + default 0x00 + help + This value defines the total number of retranmissions of an + acknowledgment message that the stack will additionally send when the + size of segments in a segmented message is above the + CONFIG_BT_MESH_SAR_RX_SEG_THRESHOLD value. + endmenu # Transport SAR configuration config BT_MESH_DEFAULT_TTL @@ -1514,130 +1634,6 @@ config BT_MESH_SOL_PDU_RPL_CLI_TIMEOUT for a response message to arrive. This value can be changed at runtime using @ref bt_mesh_sol_pdu_rpl_cli_timeout_set. -menu "Transport SAR configuration" - -config BT_MESH_SAR_TX_SEG_INT_STEP - hex "Interval between sending two consecutive segments" - range 0x00 0x0F - default 0x05 - help - This value controls the interval between sending two consecutive - segments in a segmented message. The interval is measured in - milliseconds and calculated using the following formula: - (CONFIG_BT_MESH_SAR_TX_SEG_INT_STEP + 1) * 10 ms. - -config BT_MESH_SAR_TX_UNICAST_RETRANS_COUNT - hex "Maximum number of retransmissions to unicast address" - range 0x00 0x0F - default 0x02 - help - This value controls the maximum number of retransmissions of a - segmented message to a unicast address before giving up the transfer. - -config BT_MESH_SAR_TX_UNICAST_RETRANS_WITHOUT_PROG_COUNT - hex "Maximum number of retransmissions without progress to a unicast address" - range 0x00 0x0F - default 0x02 - help - This value defines the maximum number of retransmissions of a - segmented message to a unicast address that the stack will send if no - acknowledgment was received during timeout, or if an - acknowledgment with already confirmed segments was received. - -config BT_MESH_SAR_TX_UNICAST_RETRANS_INT_STEP - hex "Retransmissions interval step of missing segments to unicast address" - range 0x00 0x0F - default 0x07 - help - This value controls the interval step used for delaying the - retransmissions of unacknowledged segments of a segmented message to - a unicast address. The interval step is measured in milliseconds and - calculated using the following formula: - (CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_INT_STEP + 1) * 25 ms. - -config BT_MESH_SAR_TX_UNICAST_RETRANS_INT_INC - hex "Retransmissions interval increment of missing segments to unicast address" - range 0x00 0x0F - default 0x01 - help - This value controls the interval increment used for delaying the - retransmissions of unacknowledged segments of a segmented message to - a unicast address. The increment is measured in milliseconds and - calculated using the following formula: - (CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_INT_INC + 1) * 25 ms. - -config BT_MESH_SAR_TX_MULTICAST_RETRANS_COUNT - hex "Total number of retransmissions to multicast address" - range 0x00 0x0F - default 0x02 - help - This value controls the total number of retransmissions of a segmented - message to a multicast address. - -config BT_MESH_SAR_TX_MULTICAST_RETRANS_INT - hex "Interval between retransmissions to multicast address" - range 0x00 0x0F - default 0x09 - help - This value controls the interval between retransmissions of all - segments in a segmented message to a multicast address. The - interval is measured in milliseconds and calculated using the - following formula: - (CONFIG_BT_MESH_SAR_TX_MULTICAST_RETRANS_INT + 1) * 25 ms. - -config BT_MESH_SAR_RX_SEG_THRESHOLD - hex "Acknowledgments retransmission threshold" - range 0x00 0x1F - default 0x03 - help - This value defines a threshold in number of segments of a segmented - message for acknowledgment retransmissions. When the number of - segments of a segmented message is above this threshold, the stack - will additionally retransmit every acknowledgment message the - number of times given by value of CONFIG_BT_MESH_SAR_RX_ACK_RETRANS_COUNT. - -config BT_MESH_SAR_RX_ACK_DELAY_INC - hex "Acknowledgment delay increment" - range 0x00 0x07 - default 0x01 - help - This value controls the delay increment of an interval used for - delaying the transmission of an acknowledgment message after - receiving a new segment. The increment is measured in segments - and calculated using the following formula: - CONFIG_BT_MESH_SAR_RX_ACK_DELAY_INC + 1.5. - -config BT_MESH_SAR_RX_SEG_INT_STEP - hex "Segments reception interval step" - range 0x00 0x0F - default 0x05 - help - This value defines the segments reception interval step used for - delaying the transmission of an acknowledgment message after - receiving a new segmnet. The interval is measured in milliseconds - and calculated using the following formula: - (CONFIG_BT_MESH_SAR_RX_SEG_INT_STEP + 1) * 10 ms - -config BT_MESH_SAR_RX_DISCARD_TIMEOUT - hex "Discard timeout for reception of a segmented message" - range 0x00 0x0F - default 0x01 - help - This value defines the time since the last successfully received - segment before giving up the reception of a segmented message. - -config BT_MESH_SAR_RX_ACK_RETRANS_COUNT - hex "Total number of acknowledgment message retransmission" - range 0x00 0x03 - default 0x00 - help - This value defines the total number of retranmissions of an - acknowledgment message that the stack will additionally send when the - size of segments in a segmented message is above the - CONFIG_BT_MESH_SAR_RX_SEG_THRESHOLD value. - -endmenu - menu "Capabilities" config BT_MESH_SUBNET_COUNT From c67094ab46a6ee93467e127d6e3d8fbdd2c3869b Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:46:27 +0100 Subject: [PATCH 1285/1623] =?UTF-8?q?[nrf=20fromtree]=C2=A0Bluetooth:=20Me?= =?UTF-8?q?sh:=20Move=20provisioning=201.1=20Kconfig=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move provisioning 1.1 Kconfig options to the provisioning menu. Signed-off-by: Pavel Vasilyev (cherry picked from commit b94b9c7759fefe5dfe424554afa87d65b32bfd73) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index d3c3397a63d..df16e0696af 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -289,6 +289,24 @@ config BT_MESH_PROV_OOB_PUBLIC_KEY help Enable this option if public key is to be exchanged via Out of Band (OOB) technology. +config BT_MESH_ECDH_P256_CMAC_AES128_AES_CCM + bool "Support CMAC AES128 for OOB authentication" + depends on BT_MESH_PROV + default y + help + Enable this option to support CMAC AES128 for OOB authentication. + +config BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM + bool "Support HMAC SHA256 for OOB authentication" + depends on BT_MESH_PROV + default y + help + Enable this option to support HMAC SHA256 for OOB authentication. + +config BT_MESH_OOB_AUTH_REQUIRED + bool "OOB authentication mandates to use HMAC SHA256" + depends on BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM + config BT_MESH_PROVISIONER bool "Provisioner support" depends on BT_MESH_CDB @@ -1182,24 +1200,6 @@ config BT_MESH_FRIEND_ADV_LATENCY endif # BT_MESH_FRIEND -config BT_MESH_ECDH_P256_CMAC_AES128_AES_CCM - bool "Support CMAC AES128 for OOB authentication" - depends on BT_MESH_PROV - default y - help - Enable this option to support CMAC AES128 for OOB authentication. - -config BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM - bool "Support HMAC SHA256 for OOB authentication" - depends on BT_MESH_PROV - default y - help - Enable this option to support HMAC SHA256 for OOB authentication. - -config BT_MESH_OOB_AUTH_REQUIRED - bool "OOB authentication mandates to use HMAC SHA256" - depends on BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM - menuconfig BT_MESH_BLOB_SRV bool "Support for BLOB Transfer Server model" help From a5d294d77beaabc33d99a86491339ebcf35b7081 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:48:07 +0100 Subject: [PATCH 1286/1623] [nrf fromtree] Bluetooth: Mesh: Move CDP 1.1 Kconfig options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move CDP 1.1 Kconfig options to the access layer menu. Signed-off-by: Pavel Vasilyev (cherry picked from commit dcdbb4bceb2dff4d80adb34ec38686483796e40f) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 62 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index df16e0696af..8cf91f60221 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -710,6 +710,37 @@ config BT_MESH_MODEL_EXTENSIONS Enable support for the model extension concept, allowing the Access layer to know about mesh model relationships. +config BT_MESH_COMP_PAGE_1 + bool "Support for Composition Data Page 1" + depends on BT_MESH_MODEL_EXTENSIONS + help + Enable support for Composition Data Page 1. + +config BT_MESH_MODEL_EXTENSION_LIST_SIZE + int "Model extensions list size" + depends on BT_MESH_COMP_PAGE_1 + range 0 255 + default 10 + help + This option specifies how many models relations can be saved. + Equals to the number of `bt_mesh_model_extend` and `bt_mesh_model_correspond` calls. + This information is used to construct Composition Data Page 1. + +config BT_MESH_COMP_PAGE_2 + bool "Support for Composition Data Page 2" + help + Enable support for Composition Data Page 2. + +config BT_MESH_COMP_PST_BUF_SIZE + int "Composition Data Page persistence buffer size" + default 100 + help + Stack allocated buffer used to temporarily hold Composition + Data Pages during flash operations. Should reflect the size + of the largest Composition Data Page present in the application. + Note that this buffer should still be large enough to restore previously stored + pages after a performed device firmware update. + config BT_MESH_LABEL_NO_RECOVER bool "[DEPRECATED] Don't recover Label UUIDs from groups address subscription list" select DEPRECATED @@ -1530,37 +1561,6 @@ config BT_MESH_PRIV_BEACON_CLI endif # BT_MESH_PRIV_BEACONS -config BT_MESH_COMP_PST_BUF_SIZE - int "Composition Data Page persistence buffer size" - default 100 - help - Stack allocated buffer used to temporarily hold Composition - Data Pages during flash operations. Should reflect the size - of the largest Composition Data Page present in the application. - Note that this buffer should still be large enough to restore previously stored - pages after a performed device firmware update. - -config BT_MESH_COMP_PAGE_1 - bool "Support for Composition Data Page 1" - depends on BT_MESH_MODEL_EXTENSIONS - help - Enable support for Composition Data Page 1. - -config BT_MESH_COMP_PAGE_2 - bool "Support for Composition Data Page 2" - help - Enable support for Composition Data Page 2. - -config BT_MESH_MODEL_EXTENSION_LIST_SIZE - int "Model extensions list size" - depends on BT_MESH_COMP_PAGE_1 - range 0 255 - default 10 - help - This option specifies how many models relations can be saved. - Equals to the number of `bt_mesh_model_extend` and `bt_mesh_model_correspond` calls. - This information is used to construct Composition Data Page 1. - config BT_MESH_SOLICITATION bool From b0bf2220c609a3d47fcb9bb59fa009998141cd38 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:50:38 +0100 Subject: [PATCH 1287/1623] [nrf fromtree] Bluetooth: Mesh: Move MBT models Kconfig options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move MBT models Kconfig options under the models menu. Signed-off-by: Pavel Vasilyev (cherry picked from commit 11986a29d848d2b6cb082bf2dc9e7bf05aac8f3a) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 210 +++++++++++++++++----------------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 8cf91f60221..55cea1faa65 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -849,6 +849,111 @@ config BT_MESH_HEALTH_CLI_TIMEOUT endif # BT_MESH_HEALTH_CLI +menuconfig BT_MESH_BLOB_SRV + bool "Support for BLOB Transfer Server model" + help + Enable the Binary Large Object (BLOB) Transfer Server model. + +if BT_MESH_BLOB_SRV + +config BT_MESH_BLOB_SRV_PULL_REQ_COUNT + int "Number of chunks to request for each pull" + default 4 + range 1 16 + help + In Pull mode (Pull BLOB Transfer Mode), the BLOB Transfer Server + requests a fixed number of chunks from the Client. Use this option to + control the chunk count in the request. If the BLOB Transfer Server + is instantiated on a Low Power node, the pull request count will be + trimmed to not overflow the Friend queue. + +config BT_MESH_BLOB_SIZE_MAX + int "Largest BLOB size in bytes" + default 524288 + range 1 3257617792 + help + The maximum object size a BLOB Transfer Server can receive. + +config BT_MESH_BLOB_BLOCK_SIZE_MIN + int "Minimum block size" + default 4096 + range 64 1048576 # 2^6 - 2^20 + help + Minimum acceptable block size in a BLOB transfer. The transfer block + size will be some number that is a power of two, and is between block + size min and block size max. If no such number exists, a compile + time warning will be issued. + +config BT_MESH_BLOB_BLOCK_SIZE_MAX + int "Maximum block size" + default 4096 + range BT_MESH_BLOB_BLOCK_SIZE_MIN 1048576 + help + Maximum acceptable block size in a BLOB transfer. The transfer block + size will be some number that is a power of two, and is between block + size min and block size max. If no such number exists, a compile + time warning will be issued. + +config BT_MESH_BLOB_REPORT_TIMEOUT + int "Partial Block Report interval in Pull mode" + default 10 + range 1 31 + help + The timer value that Pull BLOB Transfer Server uses to report missed chunks. + +endif # BT_MESH_BLOB_SRV + +menuconfig BT_MESH_BLOB_CLI + bool "Support for BLOB Transfer Client model" + help + Enable the Binary Large Object (BLOB) Transfer Client model. + +if BT_MESH_BLOB_CLI + +config BT_MESH_BLOB_CLI_BLOCK_RETRIES + int "Number of retries per block" + default 5 + help + Controls the number of times the client will attempt to resend missing + chunks to the BLOB receivers for every block. + +endif + +menu "BLOB models common configuration" + visible if BT_MESH_BLOB_SRV || BT_MESH_BLOB_CLI + +config BT_MESH_BLOB_CHUNK_COUNT_MAX + int "Maximum chunk count per block" + default 256 + range 1 2992 + help + A BLOB transfer contains several blocks. Each block is made up of + several chunks. This option controls the maximum chunk count per + block. + +endmenu + +config BT_MESH_BLOB_IO_FLASH + bool "BLOB flash stream" + default y + depends on BT_MESH_BLOB_SRV || BT_MESH_BLOB_CLI + depends on FLASH_MAP + help + Enable the BLOB flash stream for reading and writing BLOBs directly to + and from flash. + +config BT_MESH_DFU_SRV + bool "Support for Firmware Update Server model" + depends on BT_MESH_BLOB_SRV + help + Enable the Firmware Update Server model. + +config BT_MESH_DFU_CLI + bool "Support for Firmware Update Client model" + depends on BT_MESH_BLOB_CLI + help + Enable the Firmware Update Client model. + endmenu # Models menu "Proxy" @@ -1231,111 +1336,6 @@ config BT_MESH_FRIEND_ADV_LATENCY endif # BT_MESH_FRIEND -menuconfig BT_MESH_BLOB_SRV - bool "Support for BLOB Transfer Server model" - help - Enable the Binary Large Object (BLOB) Transfer Server model. - -if BT_MESH_BLOB_SRV - -config BT_MESH_BLOB_SRV_PULL_REQ_COUNT - int "Number of chunks to request for each pull" - default 4 - range 1 16 - help - In Pull mode (Pull BLOB Transfer Mode), the BLOB Transfer Server - requests a fixed number of chunks from the Client. Use this option to - control the chunk count in the request. If the BLOB Transfer Server - is instantiated on a Low Power node, the pull request count will be - trimmed to not overflow the Friend queue. - -config BT_MESH_BLOB_SIZE_MAX - int "Largest BLOB size in bytes" - default 524288 - range 1 3257617792 - help - The maximum object size a BLOB Transfer Server can receive. - -config BT_MESH_BLOB_BLOCK_SIZE_MIN - int "Minimum block size" - default 4096 - range 64 1048576 # 2^6 - 2^20 - help - Minimum acceptable block size in a BLOB transfer. The transfer block - size will be some number that is a power of two, and is between block - size min and block size max. If no such number exists, a compile - time warning will be issued. - -config BT_MESH_BLOB_BLOCK_SIZE_MAX - int "Maximum block size" - default 4096 - range BT_MESH_BLOB_BLOCK_SIZE_MIN 1048576 - help - Maximum acceptable block size in a BLOB transfer. The transfer block - size will be some number that is a power of two, and is between block - size min and block size max. If no such number exists, a compile - time warning will be issued. - -config BT_MESH_BLOB_REPORT_TIMEOUT - int "Partial Block Report interval in Pull mode" - default 10 - range 1 31 - help - The timer value that Pull BLOB Transfer Server uses to report missed chunks. - -endif # BT_MESH_BLOB_SRV - -menuconfig BT_MESH_BLOB_CLI - bool "Support for BLOB Transfer Client model" - help - Enable the Binary Large Object (BLOB) Transfer Client model. - -if BT_MESH_BLOB_CLI - -config BT_MESH_BLOB_CLI_BLOCK_RETRIES - int "Number of retries per block" - default 5 - help - Controls the number of times the client will attempt to resend missing - chunks to the BLOB receivers for every block. - -endif - -menu "BLOB models common configuration" - visible if BT_MESH_BLOB_SRV || BT_MESH_BLOB_CLI - -config BT_MESH_BLOB_CHUNK_COUNT_MAX - int "Maximum chunk count per block" - default 256 - range 1 2992 - help - A BLOB transfer contains several blocks. Each block is made up of - several chunks. This option controls the maximum chunk count per - block. - -endmenu - -config BT_MESH_BLOB_IO_FLASH - bool "BLOB flash stream" - default y - depends on BT_MESH_BLOB_SRV || BT_MESH_BLOB_CLI - depends on FLASH_MAP - help - Enable the BLOB flash stream for reading and writing BLOBs directly to - and from flash. - -config BT_MESH_DFU_SRV - bool "Support for Firmware Update Server model" - depends on BT_MESH_BLOB_SRV - help - Enable the Firmware Update Server model. - -config BT_MESH_DFU_CLI - bool "Support for Firmware Update Client model" - depends on BT_MESH_BLOB_CLI - help - Enable the Firmware Update Client model. - menu "Firmware Update model configuration" visible if BT_MESH_DFU_SRV || BT_MESH_DFU_CLI From f939aa5332dd07a4127982ecdb9a1797abd0c177 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:51:29 +0100 Subject: [PATCH 1288/1623] [nrf fromtree] Bluetooth: Mesh: Move DFU models Kconfig options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move DFU models Kconfig options under the models menu. Signed-off-by: Pavel Vasilyev (cherry picked from commit c2299e21206a54aa1234e2566d1f1572fdaa422a) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 190 +++++++++++++++++----------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 55cea1faa65..a86bb076839 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -954,6 +954,101 @@ config BT_MESH_DFU_CLI help Enable the Firmware Update Client model. +menu "Firmware Update model configuration" + visible if BT_MESH_DFU_SRV || BT_MESH_DFU_CLI + +config BT_MESH_DFU_FWID_MAXLEN + int "DFU FWID max length" + default 16 + range 0 106 + help + This value defines the maximum length of an image's firmware ID. + +config BT_MESH_DFU_METADATA_MAXLEN + int "DFU metadata max length" + default 32 + range 18 255 if BT_MESH_DFU_METADATA + range 0 255 + help + This value defines the maximum length of an image's metadata. + +config BT_MESH_DFU_METADATA + bool "Support for the default metadata format" + help + This option adds a set of functions that can be used to encode and decode a firmware + metadata using the format defined in the Bluetooth Mesh DFU subsystem. + +config BT_MESH_DFU_URI_MAXLEN + int "DFU URI max length" + default 32 + range 0 255 + help + This value defines the maximum length of an image's URI, not including + a string terminator. + +endmenu # Firmware Update model configuration + +menuconfig BT_MESH_DFU_SLOTS + bool "Firmware image slot manager" + default y if BT_MESH_DFU_CLI + help + Enable the DFU image slot manager, for managing firmware distribution slots + for the Firmware Update Client model. + +if BT_MESH_DFU_SLOTS + +config BT_MESH_DFU_SLOT_CNT + int "Number of firmware image slots" + default 1 + range 1 32767 + help + This value defines the number of firmware slots the DFU image slot manager + can keep simultaneously. + +endif + +menuconfig BT_MESH_DFD_SRV + bool "Support for Firmware Distribution Server model" + depends on BT_MESH_BLOB_SRV + depends on BT_MESH_DFU_CLI + help + Enable the Firmware Distribution Server model. + +if BT_MESH_DFD_SRV + +config BT_MESH_DFD_SRV_SLOT_MAX_SIZE + int "Largest DFU image that can be stored" + default BT_MESH_BLOB_SIZE_MAX + range 0 BT_MESH_BLOB_SIZE_MAX + help + This value defines the largest DFU image a single slot can store. + +config BT_MESH_DFD_SRV_SLOT_SPACE + int "Total DFU image storage space" + default BT_MESH_DFD_SRV_SLOT_MAX_SIZE + range 0 4294967295 + help + This value defines the total storage space dedicated to storing DFU + images on the Firmware Distribution Server. + +config BT_MESH_DFD_SRV_TARGETS_MAX + int "Maximum Target node count" + default 8 + range 1 65535 + help + This value defines the maximum number of Target nodes the Firmware + Distribution Server can target simultaneously. + +config BT_MESH_DFD_SRV_OOB_UPLOAD + bool "Support for DFU image OOB upload" + help + This enables support for OOB upload of firmware images for + distribution. This makes several callbacks and use of the init + macro BT_MESH_DFD_SRV_INIT_OOB mandatory. See the API documentation + for bt_mesh_dfd_srv_cb for details about the mandatory callbacks. + +endif + endmenu # Models menu "Proxy" @@ -1336,101 +1431,6 @@ config BT_MESH_FRIEND_ADV_LATENCY endif # BT_MESH_FRIEND -menu "Firmware Update model configuration" - visible if BT_MESH_DFU_SRV || BT_MESH_DFU_CLI - -config BT_MESH_DFU_FWID_MAXLEN - int "DFU FWID max length" - default 16 - range 0 106 - help - This value defines the maximum length of an image's firmware ID. - -config BT_MESH_DFU_METADATA_MAXLEN - int "DFU metadata max length" - default 32 - range 18 255 if BT_MESH_DFU_METADATA - range 0 255 - help - This value defines the maximum length of an image's metadata. - -config BT_MESH_DFU_METADATA - bool "Support for the default metadata format" - help - This option adds a set of functions that can be used to encode and decode a firmware - metadata using the format defined in the Bluetooth Mesh DFU subsystem. - -config BT_MESH_DFU_URI_MAXLEN - int "DFU URI max length" - default 32 - range 0 255 - help - This value defines the maximum length of an image's URI, not including - a string terminator. - -endmenu - -menuconfig BT_MESH_DFU_SLOTS - bool "Firmware image slot manager" - default y if BT_MESH_DFU_CLI - help - Enable the DFU image slot manager, for managing firmware distribution slots - for the Firmware Update Client model. - -if BT_MESH_DFU_SLOTS - -config BT_MESH_DFU_SLOT_CNT - int "Number of firmware image slots" - default 1 - range 1 32767 - help - This value defines the number of firmware slots the DFU image slot manager - can keep simultaneously. - -endif - -menuconfig BT_MESH_DFD_SRV - bool "Support for Firmware Distribution Server model" - depends on BT_MESH_BLOB_SRV - depends on BT_MESH_DFU_CLI - help - Enable the Firmware Distribution Server model. - -if BT_MESH_DFD_SRV - -config BT_MESH_DFD_SRV_SLOT_MAX_SIZE - int "Largest DFU image that can be stored" - default BT_MESH_BLOB_SIZE_MAX - range 0 BT_MESH_BLOB_SIZE_MAX - help - This value defines the largest DFU image a single slot can store. - -config BT_MESH_DFD_SRV_SLOT_SPACE - int "Total DFU image storage space" - default BT_MESH_DFD_SRV_SLOT_MAX_SIZE - range 0 4294967295 - help - This value defines the total storage space dedicated to storing DFU - images on the Firmware Distribution Server. - -config BT_MESH_DFD_SRV_TARGETS_MAX - int "Maximum Target node count" - default 8 - range 1 65535 - help - This value defines the maximum number of Target nodes the Firmware - Distribution Server can target simultaneously. - -config BT_MESH_DFD_SRV_OOB_UPLOAD - bool "Support for DFU image OOB upload" - help - This enables support for OOB upload of firmware images for - distribution. This makes several callbacks and use of the init - macro BT_MESH_DFD_SRV_INIT_OOB mandatory. See the API documentation - for bt_mesh_dfd_srv_cb for details about the mandatory callbacks. - -endif - config BT_MESH_RPR_SRV bool "Support for Remote Provisioning Server model" help From bcc463dbb4903f234c8949c5409cef85cb1cd4c8 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:52:20 +0100 Subject: [PATCH 1289/1623] [nrf fromtree] Bluetooth: Mesh: Move RPR models Kconfig options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move RPR models Kconfig options under the models menu. Signed-off-by: Pavel Vasilyev (cherry picked from commit f89effbe755e06d9b8dab83cbda8473e4b739902) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 95 ++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index a86bb076839..95a7d468f83 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1049,6 +1049,54 @@ config BT_MESH_DFD_SRV_OOB_UPLOAD endif +config BT_MESH_RPR_SRV + bool "Support for Remote Provisioning Server model" + help + The Remote Provisioning Server is the proxy for a provisioning + process, allowing provisioners to tunnel their provisioning + messages through the mesh to the Remote Provisioning Server, which + communicates directly with the unprovisioned node. + +config BT_MESH_RPR_CLI + bool "Support for Remote Provisioning Client model" + depends on BT_MESH_PROVISIONER + help + The Remote Provisioning Client is instantiated on the provisioner + node, and allows provisioning of new devices through the mesh network + by tunnelling provisioning messages to a Remote Provisioning Server. + +menu "Remote Provisioning configuration" + visible if BT_MESH_RPR_SRV || BT_MESH_RPR_CLI + +config BT_MESH_RPR_AD_TYPES_MAX + int "Max AD types in extended scanning" + default 1 + range 1 16 + help + During extended scanning, the Remote Provisioning Server can include + a set of AD types in the scan reports, collected from the + unprovisioned device's advertisement data. This option controls + the highest number of AD types a single server can scan for, and a + Client can request. + +config BT_MESH_RPR_SRV_SCANNED_ITEMS_MAX + int "Max scannable unprovisioned devices for Remote Provisioning Server" + default 4 + range 4 255 + help + Max number of unique unprovisioned devices a single Remote + Provisioning Server can hold. + +config BT_MESH_RPR_SRV_AD_DATA_MAX + int "Max additional advertisement data to report" + default 31 + range 3 255 + help + Buffer size for the additional advertisement data reported during + extended scanning. + +endmenu # Remote Provisioning configuration + endmenu # Models menu "Proxy" @@ -1431,53 +1479,6 @@ config BT_MESH_FRIEND_ADV_LATENCY endif # BT_MESH_FRIEND -config BT_MESH_RPR_SRV - bool "Support for Remote Provisioning Server model" - help - The Remote Provisioning Server is the proxy for a provisioning - process, allowing provisioners to tunnel their provisioning - messages through the mesh to the Remote Provisioning Server, which - communicates directly with the unprovisioned node. - -config BT_MESH_RPR_CLI - bool "Support for Remote Provisioning Client model" - depends on BT_MESH_PROVISIONER - help - The Remote Provisioning Client is instantiated on the provisioner - node, and allows provisioning of new devices through the mesh network - by tunnelling provisioning messages to a Remote Provisioning Server. - -menu "Remote Provisioning configuration" - visible if BT_MESH_RPR_SRV || BT_MESH_RPR_CLI - -config BT_MESH_RPR_AD_TYPES_MAX - int "Max AD types in extended scanning" - default 1 - range 1 16 - help - During extended scanning, the Remote Provisioning Server can include - a set of AD types in the scan reports, collected from the - unprovisioned device's advertisement data. This option controls - the highest number of AD types a single server can scan for, and a - Client can request. - -config BT_MESH_RPR_SRV_SCANNED_ITEMS_MAX - int "Max scannable unprovisioned devices for Remote Provisioning Server" - default 4 - range 4 255 - help - Max number of unique unprovisioned devices a single Remote - Provisioning Server can hold. - -config BT_MESH_RPR_SRV_AD_DATA_MAX - int "Max additional advertisement data to report" - default 31 - range 3 255 - help - Buffer size for the additional advertisement data reported during - extended scanning. -endmenu - config BT_MESH_SAR_CFG bool From b7e7d148f7850dd772316b76111190216393e47c Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:53:04 +0100 Subject: [PATCH 1290/1623] [nrf fromtree] Bluetooth: Mesh: Move SAR models Kconfig options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move SAR models Kconfig options under the models menu. Signed-off-by: Pavel Vasilyev (cherry picked from commit 5b0a1bb165b8f822f6bc5b75a44f986aa8dfd3f1) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 95a7d468f83..28316764852 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1097,6 +1097,21 @@ config BT_MESH_RPR_SRV_AD_DATA_MAX endmenu # Remote Provisioning configuration +config BT_MESH_SAR_CFG + bool + +config BT_MESH_SAR_CFG_SRV + bool "Support for SAR Configuration Server model" + select BT_MESH_SAR_CFG + help + Enable support for the SAR configuration server model. + +config BT_MESH_SAR_CFG_CLI + bool "Support for SAR Configuration Client Model" + select BT_MESH_SAR_CFG + help + Enable support for the SAR configuration client model. + endmenu # Models menu "Proxy" @@ -1479,21 +1494,6 @@ config BT_MESH_FRIEND_ADV_LATENCY endif # BT_MESH_FRIEND -config BT_MESH_SAR_CFG - bool - -config BT_MESH_SAR_CFG_SRV - bool "Support for SAR Configuration Server model" - select BT_MESH_SAR_CFG - help - Enable support for the SAR configuration server model. - -config BT_MESH_SAR_CFG_CLI - bool "Support for SAR Configuration Client Model" - select BT_MESH_SAR_CFG - help - Enable support for the SAR configuration client model. - config BT_MESH_OP_AGG bool From 99d5b7513896c05291652abfa6f1690bca38a37e Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:53:41 +0100 Subject: [PATCH 1291/1623] [nrf fromtree] Bluetooth: Mesh: Move OpAgg models Kconfig options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move OpAgg models Kconfig options under the models menu. Signed-off-by: Pavel Vasilyev (cherry picked from commit 5156f78386efabecef54150b5dc5803c2541e1a7) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 64 +++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 28316764852..7f405a0b97d 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1112,6 +1112,38 @@ config BT_MESH_SAR_CFG_CLI help Enable support for the SAR configuration client model. +config BT_MESH_OP_AGG + bool + +config BT_MESH_OP_AGG_SRV + bool "Support for Opcode Aggregator Server Model" + select BT_MESH_OP_AGG + help + Enable support for the Opcode Aggregator Server model. + +config BT_MESH_OP_AGG_CLI + bool "Support for Opcode Aggregator Client Model" + select BT_MESH_OP_AGG + help + Enable support for the Opcode Aggregator Client model. + +if BT_MESH_OP_AGG_CLI + +config BT_MESH_OP_AGG_CLI_TIMEOUT + int "Opcodes Aggregator Client model timeout in milliseconds" + default 10000 + help + This timeout controls how long Opcodes Aggregator Client waits + for a response message to arrive. This value can be changed at + runtime using @ref bt_mesh_op_agg_cli_timeout_set. + +endif # BT_MESH_OP_AGG_CLI + +config BT_MESH_LARGE_COMP_DATA_SRV + bool "Support for Large Composition Data Server Model" + help + Enable support for the Large Composition Data Server model. + endmenu # Models menu "Proxy" @@ -1494,38 +1526,6 @@ config BT_MESH_FRIEND_ADV_LATENCY endif # BT_MESH_FRIEND -config BT_MESH_OP_AGG - bool - -config BT_MESH_OP_AGG_SRV - bool "Support for Opcode Aggregator Server Model" - select BT_MESH_OP_AGG - help - Enable support for the Opcode Aggregator Server model. - -config BT_MESH_OP_AGG_CLI - bool "Support for Opcode Aggregator Client Model" - select BT_MESH_OP_AGG - help - Enable support for the Opcode Aggregator Client model. - -if BT_MESH_OP_AGG_CLI - -config BT_MESH_OP_AGG_CLI_TIMEOUT - int "Opcodes Aggregator Client model timeout in milliseconds" - default 10000 - help - This timeout controls how long Opcodes Aggregator Client waits - for a response message to arrive. This value can be changed at - runtime using @ref bt_mesh_op_agg_cli_timeout_set. - -endif # BT_MESH_OP_AGG_CLI - -config BT_MESH_LARGE_COMP_DATA_SRV - bool "Support for Large Composition Data Server Model" - help - Enable support for the Large Composition Data Server model. - if BT_MESH_LARGE_COMP_DATA_SRV config BT_MESH_MODELS_METADATA_PAGE_LEN From 858988e8ae024aa3144e77f168bc3af2763a233c Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:54:31 +0100 Subject: [PATCH 1292/1623] [nrf fromtree] Bluetooth: Mesh: Move LCD models Kconfig options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move LCD models Kconfig options under the models menu. Signed-off-by: Pavel Vasilyev (cherry picked from commit 84febe83a9e37e4a47dba9e334865208849ec3bb) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 7f405a0b97d..96dc0153794 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1144,6 +1144,22 @@ config BT_MESH_LARGE_COMP_DATA_SRV help Enable support for the Large Composition Data Server model. +if BT_MESH_LARGE_COMP_DATA_SRV + +config BT_MESH_MODELS_METADATA_PAGE_LEN + int "Maximum length of the Models Metadata Page" + default 150 + help + This value is the combined total metadata length for + all models on the device. + +endif # BT_MESH_LARGE_COMP_DATA_SRV + +config BT_MESH_LARGE_COMP_DATA_CLI + bool "Support for Large Composition Data Client model" + help + Enable support for the Large Composition Data Client model. + endmenu # Models menu "Proxy" @@ -1526,22 +1542,6 @@ config BT_MESH_FRIEND_ADV_LATENCY endif # BT_MESH_FRIEND -if BT_MESH_LARGE_COMP_DATA_SRV - -config BT_MESH_MODELS_METADATA_PAGE_LEN - int "Maximum length of the Models Metadata Page" - default 150 - help - This value is the combined total metadata length for - all models on the device. - -endif # BT_MESH_LARGE_COMP_DATA_SRV - -config BT_MESH_LARGE_COMP_DATA_CLI - bool "Support for Large Composition Data Client model" - help - Enable support for the Large Composition Data Client model. - config BT_MESH_PRIV_BEACONS bool "Support for private beacons" default y From 7f59f5ec5693fce145d530829230c306f3c7a9be Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:55:06 +0100 Subject: [PATCH 1293/1623] [nrf fromtree] Bluetooth: Mesh: Move PRB models Kconfig options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move PRB models Kconfig options under the models menu. Signed-off-by: Pavel Vasilyev (cherry picked from commit 168af2324d21ff1db187996e5484081ee94e5791) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 40 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 96dc0153794..8c84465c6a0 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1160,6 +1160,26 @@ config BT_MESH_LARGE_COMP_DATA_CLI help Enable support for the Large Composition Data Client model. +config BT_MESH_PRIV_BEACONS + bool "Support for private beacons" + default y + help + Enable support for private beacons. + +if BT_MESH_PRIV_BEACONS + +config BT_MESH_PRIV_BEACON_SRV + bool "Support for Private Beacon Server Model" + help + Enable support for the Private Beacon Server model. + +config BT_MESH_PRIV_BEACON_CLI + bool "Support for Private Beacon Client Model" + help + Enable support for the Private Beacon Client model. + +endif # BT_MESH_PRIV_BEACONS + endmenu # Models menu "Proxy" @@ -1542,26 +1562,6 @@ config BT_MESH_FRIEND_ADV_LATENCY endif # BT_MESH_FRIEND -config BT_MESH_PRIV_BEACONS - bool "Support for private beacons" - default y - help - Enable support for private beacons. - -if BT_MESH_PRIV_BEACONS - -config BT_MESH_PRIV_BEACON_SRV - bool "Support for Private Beacon Server Model" - help - Enable support for the Private Beacon Server model. - -config BT_MESH_PRIV_BEACON_CLI - bool "Support for Private Beacon Client Model" - help - Enable support for the Private Beacon Client model. - -endif # BT_MESH_PRIV_BEACONS - config BT_MESH_SOLICITATION bool From 23fa37872b170bd11c8dd25dd10dc8089ea1309f Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:56:32 +0100 Subject: [PATCH 1294/1623] [nrf fromtree] Bluetooth: Mesh: Move OdProxy models Kconfig options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move OdProxy models Kconfig options under the models menu. Signed-off-by: Pavel Vasilyev (cherry picked from commit 343fa6d04439abc220d96e759165da9b750ab064) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 110 +++++++++++++++++----------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 8c84465c6a0..89e905f4f0c 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1180,6 +1180,61 @@ config BT_MESH_PRIV_BEACON_CLI endif # BT_MESH_PRIV_BEACONS +config BT_MESH_OD_PRIV_PROXY_CLI + bool "Support for On-Demand Private Proxy Client model" + help + On-Demand Private Proxy Client allows to configure and check the state + of On-Demand Private Proxy Servers. The state determines if the peers will + advertise the Private Network Identity type after receiving a Solicitation PDU. + + +config BT_MESH_OD_PRIV_PROXY_CLI_TIMEOUT + int "Solicitation PDU RPL Configuration Client model timeout in milliseconds" + default 5000 + depends on BT_MESH_OD_PRIV_PROXY_CLI + help + This timeout controls how long the On-Demand Private Proxy Client waits + for a response message to arrive. This value can be changed at runtime + using @ref bt_mesh_od_priv_proxy_cli_timeout_set. + +config BT_MESH_OD_PRIV_PROXY_SRV + bool "Support for On-Demand Private Proxy Server model" + depends on BT_MESH_PRIV_BEACON_SRV + select BT_MESH_SOLICITATION + help + The On-Demand Private Proxy Server is used to support configuration of + advertising with Private Network Identity type of a node. + When enabled, the Solicitation PDU RPL Configuration Server model is also enabled. + +config BT_MESH_PROXY_SRPL_SIZE + int "Size of solicitation replay protection list (SRPL)" + depends on BT_MESH_OD_PRIV_PROXY_SRV + default 10 + range 1 255 + help + Size of SRPL. The list is used to determine if a received Solicitation PDU + is valid. It is valid when the SSRC field value of the received Solicitation PDU + is stored in the SRPL and the SSEQ field value is bigger than the corresponding + stored SSEQ value, or if the SSRC was not stored in the RPL and the SRPL still has + space for new entries. + +config BT_MESH_SOL_PDU_RPL_CLI + bool "Support for Solicitation PDU RPL Configuration Client model" + help + The Solicitation PDU RPL Configuration Client is used to support the + functionality of removing addresses from the solicitation replay + protection list (SRPL) of a node that supports the Solicitation + PDU RPL Configuration Server model. + +config BT_MESH_SOL_PDU_RPL_CLI_TIMEOUT + int "Solicitation PDU RPL Configuration Client model timeout in milliseconds" + default 5000 + depends on BT_MESH_SOL_PDU_RPL_CLI + help + This timeout controls how long Solicitation PDU RPL Configuration Client waits + for a response message to arrive. This value can be changed at runtime + using @ref bt_mesh_sol_pdu_rpl_cli_timeout_set. + endmenu # Models menu "Proxy" @@ -1580,61 +1635,6 @@ config BT_MESH_SOL_ADV_XMIT How many times Solicitation PDU advertisements will be repeated. 0 means that there will be 1 transmission without retransmissions. -config BT_MESH_OD_PRIV_PROXY_CLI - bool "Support for On-Demand Private Proxy Client model" - help - On-Demand Private Proxy Client allows to configure and check the state - of On-Demand Private Proxy Servers. The state determines if the peers will - advertise the Private Network Identity type after receiving a Solicitation PDU. - - -config BT_MESH_OD_PRIV_PROXY_CLI_TIMEOUT - int "Solicitation PDU RPL Configuration Client model timeout in milliseconds" - default 5000 - depends on BT_MESH_OD_PRIV_PROXY_CLI - help - This timeout controls how long the On-Demand Private Proxy Client waits - for a response message to arrive. This value can be changed at runtime - using @ref bt_mesh_od_priv_proxy_cli_timeout_set. - -config BT_MESH_OD_PRIV_PROXY_SRV - bool "Support for On-Demand Private Proxy Server model" - depends on BT_MESH_PRIV_BEACON_SRV - select BT_MESH_SOLICITATION - help - The On-Demand Private Proxy Server is used to support configuration of - advertising with Private Network Identity type of a node. - When enabled, the Solicitation PDU RPL Configuration Server model is also enabled. - -config BT_MESH_PROXY_SRPL_SIZE - int "Size of solicitation replay protection list (SRPL)" - depends on BT_MESH_OD_PRIV_PROXY_SRV - default 10 - range 1 255 - help - Size of SRPL. The list is used to determine if a received Solicitation PDU - is valid. It is valid when the SSRC field value of the received Solicitation PDU - is stored in the SRPL and the SSEQ field value is bigger than the corresponding - stored SSEQ value, or if the SSRC was not stored in the RPL and the SRPL still has - space for new entries. - -config BT_MESH_SOL_PDU_RPL_CLI - bool "Support for Solicitation PDU RPL Configuration Client model" - help - The Solicitation PDU RPL Configuration Client is used to support the - functionality of removing addresses from the solicitation replay - protection list (SRPL) of a node that supports the Solicitation - PDU RPL Configuration Server model. - -config BT_MESH_SOL_PDU_RPL_CLI_TIMEOUT - int "Solicitation PDU RPL Configuration Client model timeout in milliseconds" - default 5000 - depends on BT_MESH_SOL_PDU_RPL_CLI - help - This timeout controls how long Solicitation PDU RPL Configuration Client waits - for a response message to arrive. This value can be changed at runtime - using @ref bt_mesh_sol_pdu_rpl_cli_timeout_set. - menu "Capabilities" config BT_MESH_SUBNET_COUNT From e5501fa91a2ff5dba2b0f43d6baf7370bba6a355 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 15:57:17 +0100 Subject: [PATCH 1295/1623] [nrf fromtree] Bluetooth: Mesh: Move Solicitation Kconfig options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move Solicitation Kconfig options under the models menu. Signed-off-by: Pavel Vasilyev (cherry picked from commit bb75d1f8130faefff8775d513f4c23af8fe922b1) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 89e905f4f0c..63d10e8f6d4 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1299,6 +1299,24 @@ config BT_MESH_PROXY_CLIENT i.e. the ability to act as a proxy between a Mesh GATT Service and a Mesh network. +config BT_MESH_SOLICITATION + bool + +config BT_MESH_PROXY_SOLICITATION + bool "Proxy solicitation feature" + select BT_MESH_SOLICITATION + help + This option enables support for sending Solicitation PDUs. + +config BT_MESH_SOL_ADV_XMIT + int "Solicitation PDU retransmission count" + depends on BT_MESH_PROXY_SOLICITATION + range 0 10 + default 2 + help + How many times Solicitation PDU advertisements will be repeated. 0 means that there will be + 1 transmission without retransmissions. + endmenu # Proxy choice BT_MESH_CRYPTO_LIB @@ -1617,24 +1635,6 @@ config BT_MESH_FRIEND_ADV_LATENCY endif # BT_MESH_FRIEND -config BT_MESH_SOLICITATION - bool - -config BT_MESH_PROXY_SOLICITATION - bool "Proxy solicitation feature" - select BT_MESH_SOLICITATION - help - This option enables support for sending Solicitation PDUs. - -config BT_MESH_SOL_ADV_XMIT - int "Solicitation PDU retransmission count" - depends on BT_MESH_PROXY_SOLICITATION - range 0 10 - default 2 - help - How many times Solicitation PDU advertisements will be repeated. 0 means that there will be - 1 transmission without retransmissions. - menu "Capabilities" config BT_MESH_SUBNET_COUNT From 1e7d45fe707c2c7bde31579e4a85bd720487d084 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 14 Dec 2023 16:01:00 +0100 Subject: [PATCH 1296/1623] [nrf fromtree] Bluetooth: Mesh: Move beacons Kconfiguration under separate submenu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Collect beacons Kconfiguration under own submenu. Signed-off-by: Pavel Vasilyev (cherry picked from commit 83b7513937e03507230bdb35d59275f63fbb47d6) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/Kconfig | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 63d10e8f6d4..e0b4761232c 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1160,12 +1160,6 @@ config BT_MESH_LARGE_COMP_DATA_CLI help Enable support for the Large Composition Data Client model. -config BT_MESH_PRIV_BEACONS - bool "Support for private beacons" - default y - help - Enable support for private beacons. - if BT_MESH_PRIV_BEACONS config BT_MESH_PRIV_BEACON_SRV @@ -1388,6 +1382,8 @@ config BT_MESH_PSA_KEY_ID_USER_MIN_OFFSET endif # BT_MESH_USES_MBEDTLS_PSA || BT_MESH_USES_TFM_PSA +menu "Beacons" + config BT_MESH_BEACON_ENABLED bool "Secure network beacon enabled" default y @@ -1395,6 +1391,14 @@ config BT_MESH_BEACON_ENABLED Controls whether the Secure network beacon feature is enabled by default. Can be changed through runtime configuration. +config BT_MESH_PRIV_BEACONS + bool "Support for private beacons" + default y + help + Enable support for private beacons. + +endmenu # Beacons + menu "IV Index & Sequence number" config BT_MESH_IV_UPDATE_TEST From 74bfee1fc5eec7d32cd438d7ccd21b388291fe4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Thu, 18 Jan 2024 14:01:37 +0100 Subject: [PATCH 1297/1623] [nrf fromtree] Bluetooth: Mesh: Add artificial beacon delay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After removing 20ms in advertiser, all subnetwork beacons are sent as high dense packet of frames with minimal distance between them. That might cause collisions if beacon interval on devices will coincide. This commit adds an artificial delay between each subnet advertsing beacons. Signed-off-by: Anders Storrø (cherry picked from commit 93a6ee501ae01bd480eda1151a681aa1f76d84d7) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/beacon.c | 78 ++++++++++++++++----- tests/bsim/bluetooth/mesh/src/test_beacon.c | 22 +++--- 2 files changed, 76 insertions(+), 24 deletions(-) diff --git a/subsys/bluetooth/mesh/beacon.c b/subsys/bluetooth/mesh/beacon.c index 6eb2c9be3a7..cdd5862330e 100644 --- a/subsys/bluetooth/mesh/beacon.c +++ b/subsys/bluetooth/mesh/beacon.c @@ -40,6 +40,8 @@ LOG_MODULE_REGISTER(bt_mesh_beacon); #define PROV_XMIT BT_MESH_TRANSMIT(0, 20) static struct k_work_delayable beacon_timer; +static struct bt_mesh_subnet *beacon_send_sub_curr; + #if defined(CONFIG_BT_MESH_PRIV_BEACONS) static struct { /** @@ -111,13 +113,26 @@ void bt_mesh_beacon_cache_clear(struct bt_mesh_subnet *sub) #endif } +static void beacon_start(uint16_t duration, int err, void *user_data) +{ + if (err) { + LOG_ERR("Failed to send beacon: err %d", err); + if (beacon_send_sub_curr) { + k_work_reschedule(&beacon_timer, K_NO_WAIT); + } + } +} + static void beacon_complete(int err, void *user_data) { struct bt_mesh_beacon *beacon = user_data; LOG_DBG("err %d", err); - beacon->sent = k_uptime_get_32(); + + if (beacon_send_sub_curr) { + k_work_reschedule(&beacon_timer, K_MSEC(20)); + } } static int secure_beacon_create(struct bt_mesh_subnet *sub, @@ -247,11 +262,12 @@ static bool secure_beacon_is_running(void) atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_INITIATOR); } -static bool net_beacon_send(struct bt_mesh_subnet *sub, struct bt_mesh_beacon *beacon, - void *cb_data, int (*beacon_create)(struct bt_mesh_subnet *sub, - struct net_buf_simple *buf)) +static int net_beacon_send(struct bt_mesh_subnet *sub, struct bt_mesh_beacon *beacon, + int (*beacon_create)(struct bt_mesh_subnet *sub, + struct net_buf_simple *buf)) { static const struct bt_mesh_send_cb send_cb = { + .start = beacon_start, .end = beacon_complete, }; uint32_t now = k_uptime_get_32(); @@ -267,14 +283,14 @@ static bool net_beacon_send(struct bt_mesh_subnet *sub, struct bt_mesh_beacon *b if (time_diff < (600 * MSEC_PER_SEC) && (time_diff < BEACON_THRESHOLD(beacon) || time_since_last_recv < (10 * MSEC_PER_SEC))) { - return false; + return -ENOMSG; } adv = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, PROV_XMIT, K_NO_WAIT); if (!adv) { LOG_ERR("Unable to allocate beacon adv"); - return true; /* Bail out */ + return -ENOMEM; /* Bail out */ } err = beacon_create(sub, &adv->b); @@ -284,12 +300,12 @@ static bool net_beacon_send(struct bt_mesh_subnet *sub, struct bt_mesh_beacon *b bt_mesh_adv_unref(adv); - return err != 0; + return err; } -static bool net_beacon_for_subnet_send(struct bt_mesh_subnet *sub, void *cb_data) +static int net_beacon_for_subnet_send(struct bt_mesh_subnet *sub) { - bool res = true; + int err = -ENOMSG; struct { struct bt_mesh_beacon *beacon; @@ -315,14 +331,14 @@ static bool net_beacon_for_subnet_send(struct bt_mesh_subnet *sub, void *cb_data continue; } - res = net_beacon_send(sub, beacons[i].beacon, cb_data, beacons[i].create_fn); - if (res) { + err = net_beacon_send(sub, beacons[i].beacon, beacons[i].create_fn); + if (err < 0) { /* Bail out */ break; } } - return res; + return err; } static int unprovisioned_beacon_send(void) @@ -449,6 +465,30 @@ static bool net_beacon_is_running(void) (bt_mesh_priv_beacon_get() == BT_MESH_FEATURE_ENABLED); } +static bool beacons_send_next(void) +{ + int err; + struct bt_mesh_subnet *sub_first = bt_mesh_subnet_next(NULL); + struct bt_mesh_subnet *sub_next; + + do { + sub_next = bt_mesh_subnet_next(beacon_send_sub_curr); + if (sub_next == sub_first && beacon_send_sub_curr != NULL) { + beacon_send_sub_curr = NULL; + return false; + } + + beacon_send_sub_curr = sub_next; + err = net_beacon_for_subnet_send(beacon_send_sub_curr); + if (err < 0 && (err != -ENOMSG)) { + LOG_ERR("Failed to advertise subnet %d: err %d", + beacon_send_sub_curr->net_idx, err); + } + } while (err); + + return true; +} + static void beacon_send(struct k_work *work) { LOG_DBG(""); @@ -458,10 +498,14 @@ static void beacon_send(struct k_work *work) return; } - update_beacon_observation(); - (void)bt_mesh_subnet_find(net_beacon_for_subnet_send, NULL); + if (!beacon_send_sub_curr) { + update_beacon_observation(); + } + + if (!beacons_send_next()) { + k_work_schedule(&beacon_timer, PROVISIONED_INTERVAL); + } - k_work_schedule(&beacon_timer, PROVISIONED_INTERVAL); return; } @@ -473,7 +517,6 @@ static void beacon_send(struct k_work *work) k_work_schedule(&beacon_timer, K_SECONDS(CONFIG_BT_MESH_UNPROV_BEACON_INT)); } - } static bool auth_match(struct bt_mesh_subnet_keys *keys, @@ -757,6 +800,7 @@ void bt_mesh_beacon_ivu_initiator(bool enable) * still have to implement an early exit mechanism, so we might as well * just use this every time. */ + beacon_send_sub_curr = NULL; k_work_schedule(&beacon_timer, K_NO_WAIT); } @@ -779,11 +823,13 @@ void bt_mesh_beacon_enable(void) bt_mesh_subnet_foreach(subnet_beacon_enable); } + beacon_send_sub_curr = NULL; k_work_reschedule(&beacon_timer, K_NO_WAIT); } void bt_mesh_beacon_disable(void) { /* If this fails, we'll do an early exit in the work handler. */ + beacon_send_sub_curr = NULL; (void)k_work_cancel_delayable(&beacon_timer); } diff --git a/tests/bsim/bluetooth/mesh/src/test_beacon.c b/tests/bsim/bluetooth/mesh/src/test_beacon.c index 7a74123cb0f..869dbd4965f 100644 --- a/tests/bsim/bluetooth/mesh/src/test_beacon.c +++ b/tests/bsim/bluetooth/mesh/src/test_beacon.c @@ -507,8 +507,11 @@ static void corrupted_beacon_test(const uint8_t *offsets, } /* Now the beacon payload is valid and it shall trigger IV Update on the node. It shall also - * increase the beacon interval. + * increase the beacon interval. We delay the outgoing beacon for a couple of seconds to + * avoid near perfect syncing with the beacon interval cycle of the device we just received + * a beacon from. */ + k_sleep(K_SECONDS(3)); send_beacon(buf); /* The beacon interval shall be changed and the node shall skip transmission of the next @@ -1365,7 +1368,7 @@ static void test_tx_priv_interleave(void) struct bt_mesh_subnet *sub; - bt_mesh_test_cfg_set(NULL, BEACON_INTERVAL_WAIT_TIME); + bt_mesh_test_cfg_set(NULL, WAIT_TIME); bt_mesh_device_setup(&prov, &prb_comp); provision(&tx_cfg); @@ -1398,6 +1401,8 @@ static void test_tx_priv_interleave(void) k_sleep(K_SECONDS(BEACON_INTERVAL + 5)); toggle_priv_beacon(tx_cfg.addr, 0); + /* Small delay to let beacons complete before subnet update is applied */ + k_sleep(K_MSEC(20)); status = bt_mesh_subnet_update(BT_MESH_KEY_PRIMARY, net_key_new); ASSERT_TRUE(status == STATUS_SUCCESS); @@ -1423,7 +1428,7 @@ static void test_rx_priv_interleave(void) int err; bool same_random = false; - bt_mesh_test_cfg_set(&rx_cfg, BEACON_INTERVAL_WAIT_TIME); + bt_mesh_test_cfg_set(&rx_cfg, WAIT_TIME); bt_mesh_crypto_init(); k_sem_init(&observer_sem, 0, 1); @@ -1898,9 +1903,10 @@ static void proxy_adv_confirm_evt(struct expected_proxy_adv_evt *exp_evts, uint8 for (int i = 0; i < cnt; i++) { if (exp_evts[i].evt_cnt) { - LOG_ERR("Missing %d expected %s events in period %llums-%llums", + LOG_ERR("Missing %d expected %s idx %d events in period %llums-%llums", exp_evts[i].evt_cnt, proxy_adv_str[exp_evts[i].evt_type], - exp_evts[i].time.after, exp_evts[i].time.before); + exp_evts[i].net_idx, exp_evts[i].time.after, + exp_evts[i].time.before); missing_evts = true; } } @@ -2029,13 +2035,13 @@ static void test_rx_proxy_adv_multi_subnet_coex(void) * is advertised by this subnet, and that the two others * continues to advertise NET_ID. */ - {.evt_type = BEACON_TYPE_NET_ID, .net_idx = 0, .evt_cnt = 17, + {.evt_type = BEACON_TYPE_NET_ID, .net_idx = 0, .evt_cnt = 16, .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_2, .before = PROXY_ADV_MULTI_CHECKPOINT_3}}, - {.evt_type = BEACON_TYPE_NODE_ID, .net_idx = 1, .evt_cnt = 17, + {.evt_type = BEACON_TYPE_NODE_ID, .net_idx = 1, .evt_cnt = 16, .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_2, .before = PROXY_ADV_MULTI_CHECKPOINT_3}}, - {.evt_type = BEACON_TYPE_NET_ID, .net_idx = 2, .evt_cnt = 17, + {.evt_type = BEACON_TYPE_NET_ID, .net_idx = 2, .evt_cnt = 16, .time = {.after = PROXY_ADV_MULTI_CHECKPOINT_2, .before = PROXY_ADV_MULTI_CHECKPOINT_3}}, From a3fe63240749bf6f442c66a7f9dc7ee04a1e60fb Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Mon, 22 Jan 2024 14:40:38 +0100 Subject: [PATCH 1298/1623] [nrf fromtree] Bluetooth: Mesh: Call bt_mesh_send_cb.end cb by the end of adv MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, the bt_mesh_send_cb.end callback was called when all references to the adv were removed. If an implementation kept more references to the adv buffer after calling `bt_mesh_adv_send`, the end callback would not be called when the advertiser finished advertising this adv. With this change, the end callback is always called by the advertiser when the advertisement is finished regardless of the number of references. This allows an implementation to keep the adv buffer for the future use. As an example, pb_adv.c keeps advs for retransmission. Signed-off-by: Pavel Vasilyev (cherry picked from commit 9af051e3499fccdb1898748d2afd8dcd06d013f2) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/adv.c | 4 +--- subsys/bluetooth/mesh/adv.h | 1 + subsys/bluetooth/mesh/adv_ext.c | 5 +++++ subsys/bluetooth/mesh/adv_legacy.c | 4 ++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index 00e2a4aa7bb..d51f0946b85 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -76,7 +76,7 @@ void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv_ctx * } } -static void bt_mesh_adv_send_end(int err, struct bt_mesh_adv_ctx const *ctx) +void bt_mesh_adv_send_end(int err, struct bt_mesh_adv_ctx const *ctx) { if (ctx->started && ctx->cb && ctx->cb->end) { ctx->cb->end(err, ctx->cb_data); @@ -136,7 +136,6 @@ void bt_mesh_adv_unref(struct bt_mesh_adv *adv) } struct k_mem_slab *slab = &local_adv_pool; - struct bt_mesh_adv_ctx ctx = adv->ctx; #if defined(CONFIG_BT_MESH_RELAY) if (adv->ctx.tag == BT_MESH_ADV_TAG_RELAY) { @@ -151,7 +150,6 @@ void bt_mesh_adv_unref(struct bt_mesh_adv *adv) #endif k_mem_slab_free(slab, (void *)adv); - bt_mesh_adv_send_end(0, &ctx); } struct bt_mesh_adv *bt_mesh_adv_create(enum bt_mesh_adv_type type, diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index 0c936a1aa52..e79d082862a 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -76,6 +76,7 @@ struct bt_mesh_adv *bt_mesh_adv_create(enum bt_mesh_adv_type type, void bt_mesh_adv_send(struct bt_mesh_adv *adv, const struct bt_mesh_send_cb *cb, void *cb_data); +void bt_mesh_adv_send_end(int err, struct bt_mesh_adv_ctx const *ctx); struct bt_mesh_adv *bt_mesh_adv_get(k_timeout_t timeout); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index c30a3a2b9bc..01fa1808f58 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -284,7 +284,12 @@ static void send_pending_adv(struct k_work *work) atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START); if (ext_adv->adv) { + struct bt_mesh_adv_ctx ctx = ext_adv->adv->ctx; + + ext_adv->adv->ctx.started = 0; bt_mesh_adv_unref(ext_adv->adv); + bt_mesh_adv_send_end(0, &ctx); + ext_adv->adv = NULL; } diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index d4003e497bb..135f444b9b4 100644 --- a/subsys/bluetooth/mesh/adv_legacy.c +++ b/subsys/bluetooth/mesh/adv_legacy.c @@ -182,7 +182,11 @@ static void adv_thread(void *p1, void *p2, void *p3) adv_send(adv); } + struct bt_mesh_adv_ctx ctx = adv->ctx; + + adv->ctx.started = 0; bt_mesh_adv_unref(adv); + bt_mesh_adv_send_end(0, &ctx); /* Give other threads a chance to run */ k_yield(); From 9ad707761b1a781a4dbe48074966d20e09e89066 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Mon, 22 Jan 2024 14:49:19 +0100 Subject: [PATCH 1299/1623] [nrf fromtree] Bluetooth: Mesh: Add error code for bt_mesh_adv_terminate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return error code to let an implementation know if the adv was actually stopped (was scheduled) or not. Signed-off-by: Pavel Vasilyev (cherry picked from commit fcfc99a21d25b38aad036937f6aabef244390644) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/adv.h | 2 +- subsys/bluetooth/mesh/adv_ext.c | 10 ++++++---- subsys/bluetooth/mesh/adv_legacy.c | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index e79d082862a..6595badc9f9 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -101,7 +101,7 @@ void bt_mesh_adv_local_ready(void); void bt_mesh_adv_relay_ready(void); -void bt_mesh_adv_terminate(struct bt_mesh_adv *adv); +int bt_mesh_adv_terminate(struct bt_mesh_adv *adv); void bt_mesh_adv_friend_ready(void); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 01fa1808f58..67709a221ba 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -395,7 +395,7 @@ void bt_mesh_adv_friend_ready(void) } } -void bt_mesh_adv_terminate(struct bt_mesh_adv *adv) +int bt_mesh_adv_terminate(struct bt_mesh_adv *adv) { int err; @@ -407,13 +407,13 @@ void bt_mesh_adv_terminate(struct bt_mesh_adv *adv) } if (!atomic_test_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) { - return; + return 0; } err = bt_le_ext_adv_stop(ext_adv->instance); if (err) { LOG_ERR("Failed to stop adv %d", err); - return; + return err; } /* Do not call `cb:end`, since this user action */ @@ -423,8 +423,10 @@ void bt_mesh_adv_terminate(struct bt_mesh_adv *adv) k_work_submit(&ext_adv->work); - return; + return 0; } + + return -EINVAL; } void bt_mesh_adv_init(void) diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index 135f444b9b4..867c91bbf8e 100644 --- a/subsys/bluetooth/mesh/adv_legacy.c +++ b/subsys/bluetooth/mesh/adv_legacy.c @@ -214,9 +214,11 @@ void bt_mesh_adv_gatt_update(void) bt_mesh_adv_get_cancel(); } -void bt_mesh_adv_terminate(struct bt_mesh_adv *adv) +int bt_mesh_adv_terminate(struct bt_mesh_adv *adv) { ARG_UNUSED(adv); + + return 0; } void bt_mesh_adv_init(void) From ef91b0264dabaebf984be44bd1f0a8ec8539d110 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Mon, 22 Jan 2024 14:50:19 +0100 Subject: [PATCH 1300/1623] [nrf fromtree] Bluetooth: Mesh: Send provisioning PDUs with randomized delay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This implements the following statement from the section 5.3.3: Each Generic Provisioning PDU shall be sent after a random delay between 20 and 50 milliseconds. Signed-off-by: Pavel Vasilyev (cherry picked from commit 54c048989d343ecfd1a8dd00ce9993cbd11685d8) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/pb_adv.c | 224 +++++++++++++++++++++++++-------- 1 file changed, 174 insertions(+), 50 deletions(-) diff --git a/subsys/bluetooth/mesh/pb_adv.c b/subsys/bluetooth/mesh/pb_adv.c index f723ff48c14..c5c56b1e5b0 100644 --- a/subsys/bluetooth/mesh/pb_adv.c +++ b/subsys/bluetooth/mesh/pb_adv.c @@ -67,6 +67,8 @@ enum { ADV_LINK_INVALID, /* Error occurred during provisioning */ ADV_ACK_PENDING, /* An acknowledgment is being sent */ ADV_PROVISIONER, /* The link was opened as provisioner */ + ADV_LINK_ACK_SENDING, /* Link Ack tx was scheduled but not finished. */ + ADV_SENDING, /* Sending any PDU */ ADV_NUM_FLAGS, }; @@ -100,15 +102,30 @@ struct pb_adv { /* Transaction timeout in seconds */ uint8_t timeout; - /* Pending outgoing adv(s) */ + /* Pending outgoing adv(s) (Link Open, Gen Trans Start and Gen Trans Cont) */ struct bt_mesh_adv *adv[3]; + /* Index of the next adv to be sent */ + int next; + prov_bearer_send_complete_t cb; void *cb_data; /* Retransmit timer */ struct k_work_delayable retransmit; + + /* Unacked adv buffers (Link Ack, Link Close and Gen Trans Ack). Array size is + * hardcoded to 2 allowing to send Gen Trans Ack and Link Close at the same time. + */ + struct unacked_adv_ctx { + struct bt_mesh_adv *adv; + prov_bearer_send_complete_t cb; + void *cb_data; + } unacked[2]; + + /* Last sent unacked[] buffer */ + int last_unacked; } tx; /* Protocol timeout */ @@ -132,28 +149,124 @@ static void link_close(struct prov_rx *rx, struct net_buf_simple *buf); static void prov_link_close(enum prov_bearer_link_status status); static void close_link(enum prov_bearer_link_status status); -static void buf_sent(int err, void *user_data) +static void tx_work_handler(struct k_work *work); +static K_WORK_DELAYABLE_DEFINE(tx_work, tx_work_handler); + +static void tx_schedule(void) { - enum prov_bearer_link_status reason = (enum prov_bearer_link_status)(int)user_data; + uint16_t random_delay; - if (atomic_test_and_clear_bit(link.flags, ADV_LINK_CLOSING)) { - close_link(reason); + if (atomic_test_bit(link.flags, ADV_SENDING)) { + LOG_DBG("Another tx is in progress"); return; } + + (void)bt_rand(&random_delay, sizeof(random_delay)); + random_delay = 20 + (random_delay % 30); + + LOG_DBG("Next PDU delayed by %ums", random_delay); + + (void)k_work_schedule(&tx_work, K_MSEC(random_delay)); +} + +static int send_unacked(struct bt_mesh_adv *adv, prov_bearer_send_complete_t cb, + void *cb_data) +{ + for (int i = 0; i < ARRAY_SIZE(link.tx.unacked); i++) { + if (link.tx.unacked[i].adv != NULL) { + continue; + } + + link.tx.unacked[i].adv = adv; + link.tx.unacked[i].cb = cb; + link.tx.unacked[i].cb_data = cb_data; + + tx_schedule(); + + return 0; + } + + LOG_WRN("No memory to send unacked PDU: %s", bt_hex(adv->b.data, adv->b.len)); + return -ENOMEM; +} + +static void send_reliable(void) +{ + /* Dropping next tx adv index to start transmission from the first adv buffer. */ + link.tx.next = 0; + + tx_schedule(); +} + +static void delayed_adv_send_end(int err, void *user_data) +{ + bool unacked = (bool)user_data; + struct unacked_adv_ctx *unacked_adv = &link.tx.unacked[link.tx.last_unacked]; + + if (unacked && unacked_adv->adv != NULL) { + if (unacked_adv->cb) { + unacked_adv->cb(err, unacked_adv->cb_data); + } + + bt_mesh_adv_unref(unacked_adv->adv); + unacked_adv->adv = NULL; + } + + atomic_clear_bit(link.flags, ADV_SENDING); + tx_schedule(); } -static void buf_start(uint16_t duration, int err, void *user_data) +static void delayed_adv_send_start(uint16_t duration, int err, void *user_data) { if (err) { - buf_sent(err, user_data); + delayed_adv_send_end(err, user_data); } } -static struct bt_mesh_send_cb buf_sent_cb = { - .start = buf_start, - .end = buf_sent, +static const struct bt_mesh_send_cb delayed_adv_send_cb = { + .start = delayed_adv_send_start, + .end = delayed_adv_send_end, }; +static void tx_work_handler(struct k_work *work) +{ + int i; + + /* Send Link Ack, Link Close and Gen Trans Ack first. */ + for (i = 0; i < ARRAY_SIZE(link.tx.unacked); i++) { + int idx = (i + link.tx.last_unacked) % ARRAY_SIZE(link.tx.unacked); + struct unacked_adv_ctx *unacked = &link.tx.unacked[idx]; + + if (!unacked->adv) { + continue; + } + + atomic_set_bit(link.flags, ADV_SENDING); + bt_mesh_adv_send(unacked->adv, &delayed_adv_send_cb, (void *)true); + + link.tx.last_unacked = idx; + + return; + } + + /* Send Trans Start, Trans Cont and Link Open */ + if (link.tx.next >= ARRAY_SIZE(link.tx.adv) || link.tx.adv[link.tx.next] == NULL) { + LOG_DBG("All PDUs were sent"); + return; + } + + atomic_set_bit(link.flags, ADV_SENDING); + bt_mesh_adv_send(link.tx.adv[link.tx.next], &delayed_adv_send_cb, (void *)false); + + link.tx.next++; + + if (link.tx.next == ARRAY_SIZE(link.tx.adv) || link.tx.adv[link.tx.next] == NULL) { + /* All ack-able PDUs are sent. Now we can run the retransmit timer. */ + LOG_DBG("Starting retransmit timer"); + k_work_reschedule(&link.tx.retransmit, RETRANSMIT_TIMEOUT); + } +} + static uint8_t last_seg(uint16_t len) { if (len <= START_PAYLOAD_MAX) { @@ -168,9 +281,11 @@ static uint8_t last_seg(uint16_t len) static void free_segments(void) { int i; + bool canceled = false; for (i = 0; i < ARRAY_SIZE(link.tx.adv); i++) { struct bt_mesh_adv *adv = link.tx.adv[i]; + int err; if (!adv) { break; @@ -180,14 +295,23 @@ static void free_segments(void) /* Terminate active adv */ if (adv->ctx.busy == 0U) { - bt_mesh_adv_terminate(adv); + err = bt_mesh_adv_terminate(adv); + if (err == 0) { + canceled = true; + } } else { /* Mark as canceled */ adv->ctx.busy = 0U; + canceled = true; } bt_mesh_adv_unref(adv); } + + if (canceled) { + atomic_clear_bit(link.flags, ADV_SENDING); + tx_schedule(); + } } static uint8_t next_transaction_id(uint8_t id) @@ -268,7 +392,7 @@ static struct bt_mesh_adv *adv_create(uint8_t retransmits) return adv; } -static void ack_complete(uint16_t duration, int err, void *user_data) +static void ack_complete(int err, void *user_data) { LOG_DBG("xact 0x%x complete", (uint8_t)link.tx.pending_ack); atomic_clear_bit(link.flags, ADV_ACK_PENDING); @@ -323,12 +447,9 @@ static void protocol_timeout(struct k_work *work) static void gen_prov_ack_send(uint8_t xact_id) { - static const struct bt_mesh_send_cb cb = { - .start = ack_complete, - }; - const struct bt_mesh_send_cb *complete; struct bt_mesh_adv *adv; bool pending = atomic_test_and_set_bit(link.flags, ADV_ACK_PENDING); + int err; LOG_DBG("xact_id 0x%x", xact_id); @@ -343,19 +464,18 @@ static void gen_prov_ack_send(uint8_t xact_id) return; } - if (pending) { - complete = NULL; - } else { + if (!pending) { link.tx.pending_ack = xact_id; - complete = &cb; } net_buf_simple_add_be32(&adv->b, link.id); net_buf_simple_add_u8(&adv->b, xact_id); net_buf_simple_add_u8(&adv->b, GPC_ACK); - bt_mesh_adv_send(adv, complete, NULL); - bt_mesh_adv_unref(adv); + err = send_unacked(adv, pending ? NULL : ack_complete, NULL); + if (err) { + atomic_clear_bit(link.flags, ADV_ACK_PENDING); + } } static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf) @@ -591,29 +711,6 @@ static void gen_prov_recv(struct prov_rx *rx, struct net_buf_simple *buf) * TX ******************************************************************************/ -static void send_reliable(void) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(link.tx.adv); i++) { - struct bt_mesh_adv *adv = link.tx.adv[i]; - - if (!adv) { - break; - } - - if (adv->ctx.busy) { - continue; - } - - LOG_DBG("%u bytes: %s", adv->b.len, bt_hex(adv->b.data, adv->b.len)); - - bt_mesh_adv_send(adv, NULL, NULL); - } - - k_work_reschedule(&link.tx.retransmit, RETRANSMIT_TIMEOUT); -} - static void prov_retransmit(struct k_work *work) { LOG_DBG(""); @@ -669,8 +766,22 @@ static int bearer_ctl_send(struct bt_mesh_adv *adv) return 0; } +static void buf_sent(int err, void *user_data) +{ + enum prov_bearer_link_status reason = (enum prov_bearer_link_status)(int)user_data; + + atomic_clear_bit(link.flags, ADV_LINK_ACK_SENDING); + + if (atomic_test_and_clear_bit(link.flags, ADV_LINK_CLOSING)) { + close_link(reason); + return; + } +} + static int bearer_ctl_send_unacked(struct bt_mesh_adv *adv, void *user_data) { + int err; + if (!adv) { return -ENOMEM; } @@ -678,10 +789,12 @@ static int bearer_ctl_send_unacked(struct bt_mesh_adv *adv, void *user_data) prov_clear_tx(); k_work_reschedule(&link.prot_timer, bt_mesh_prov_protocol_timeout_get()); - bt_mesh_adv_send(adv, &buf_sent_cb, user_data); - bt_mesh_adv_unref(adv); + err = send_unacked(adv, &buf_sent, user_data); + if (err) { + bt_mesh_adv_unref(adv); + } - return 0; + return err; } static int prov_send_adv(struct net_buf_simple *msg, @@ -772,8 +885,13 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf) return; } - LOG_DBG("Resending link ack"); + if (atomic_test_bit(link.flags, ADV_LINK_ACK_SENDING)) { + LOG_DBG("Still sending Link Ack"); + return; + } + /* Ignore errors, message will be attempted again if we keep receiving link open: */ + atomic_set_bit(link.flags, ADV_LINK_ACK_SENDING); (void)bearer_ctl_send_unacked( ctl_adv_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK), (void *)PROV_BEARER_LINK_STATUS_SUCCESS); @@ -789,6 +907,7 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf) atomic_set_bit(link.flags, ADV_LINK_ACTIVE); net_buf_simple_reset(link.rx.buf); + atomic_set_bit(link.flags, ADV_LINK_ACK_SENDING); err = bearer_ctl_send_unacked( ctl_adv_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK), (void *)PROV_BEARER_LINK_STATUS_SUCCESS); @@ -923,6 +1042,8 @@ static int prov_link_accept(const struct prov_bearer_cb *cb, void *cb_data) static void prov_link_close(enum prov_bearer_link_status status) { + int err; + if (atomic_test_and_set_bit(link.flags, ADV_LINK_CLOSING)) { return; } @@ -934,9 +1055,12 @@ static void prov_link_close(enum prov_bearer_link_status status) */ link.tx.timeout = CLOSING_TIMEOUT; /* Ignore errors, the link will time out eventually if this doesn't get sent */ - bearer_ctl_send_unacked( + err = bearer_ctl_send_unacked( ctl_adv_create(LINK_CLOSE, &status, 1, RETRANSMITS_LINK_CLOSE), (void *)status); + if (err) { + close_link(status); + } } void bt_mesh_pb_adv_init(void) From b722252e766abd738257540a7f30cab4ef41633e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stine=20=C3=85kredalen?= Date: Wed, 31 Jan 2024 04:03:52 -0800 Subject: [PATCH 1301/1623] [nrf fromtree] Bluetooth: Mesh: fix SRPL always accepting sol pdus with sseq 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated logic in srpl_entry_save. Signed-off-by: Stine Åkredalen (cherry picked from commit a1b9f0a7d6b3844a7836d993ae45b6790577d57a) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/solicitation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/solicitation.c b/subsys/bluetooth/mesh/solicitation.c index 642abfd87f1..a2872daecb0 100644 --- a/subsys/bluetooth/mesh/solicitation.c +++ b/subsys/bluetooth/mesh/solicitation.c @@ -65,7 +65,7 @@ static int srpl_entry_save(struct bt_mesh_subnet *sub, uint32_t sseq, uint16_t s entry = srpl_find_by_addr(ssrc); if (entry) { - if (entry->sseq >= sseq && sseq != 0) { + if (entry->sseq >= sseq) { LOG_WRN("Higher or equal SSEQ already saved for this SSRC"); return -EALREADY; } From db6e332e4704d2fd700fac7cc9463ff2c142b814 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Mon, 5 Feb 2024 13:07:18 +0100 Subject: [PATCH 1302/1623] [nrf fromtree] Bluetooth: Mesh: Reset solicitation settings before calling reset cb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trigger erasing solicitation settings before calling `bt_mesh_settings_store_pending` and `bt_mesh_prov.reset` callback. The `bt_mesh_settings_store_pending` flushes every settings that is pending to be erased. The `bt_mesh_prov.reset` callback must be called as the last step because a user is free to do anything from this callback including rebooting or reprovisioning the device. Signed-off-by: Pavel Vasilyev (cherry picked from commit e495876db6900a4b64d82825f795454b2b507a5d) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index 1b80233cec1..77ca15b2d61 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -401,6 +401,10 @@ void bt_mesh_reset(void) bt_mesh_comp_unprovision(); + if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION)) { + bt_mesh_sol_reset(); + } + if (IS_ENABLED(CONFIG_BT_SETTINGS)) { bt_mesh_settings_store_pending(); } @@ -408,10 +412,6 @@ void bt_mesh_reset(void) if (IS_ENABLED(CONFIG_BT_MESH_PROV)) { bt_mesh_prov_reset(); } - - if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION)) { - bt_mesh_sol_reset(); - } } bool bt_mesh_is_provisioned(void) From 491c33f2bd4e5191dc96efb1643d7f3b39c4ab70 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Mon, 5 Feb 2024 16:15:41 +0100 Subject: [PATCH 1303/1623] [nrf fromtree] Bluetooth: Mesh: Fix solicitation PDU tx dep on proxy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If `CONFIG_BT_MESH_GATT_SERVER` is disabled or the advertising set doesn't support proxy adv, the solicitation PDU will not be sent. However, solicitation PDU transmission doesn't depend on the proxy feature of the device it sends. Therefore, solicatation PDU should be sent regradless of `CONFIG_BT_MESH_GATT_SERVER` option and advertiser tag. Signed-off-by: Pavel Vasilyev (cherry picked from commit 548851ac7a530f20cadab680000282f1e3c697c5) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/adv_ext.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 67709a221ba..2df2cbb4597 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -317,13 +317,13 @@ static void send_pending_adv(struct k_work *work) } } - if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || - !(ext_adv->tags & BT_MESH_ADV_TAG_BIT_PROXY)) { + if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && + !bt_mesh_sol_send()) { return; } - if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && - !bt_mesh_sol_send()) { + if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || + !(ext_adv->tags & BT_MESH_ADV_TAG_BIT_PROXY)) { return; } From aa7858fc7a11bbb9419d45c748fedb76c2f57abe Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 1 Feb 2024 23:04:30 +0100 Subject: [PATCH 1304/1623] [nrf fromtree] Bluetooth: Mesh: Warn if trying to send adv while suspended MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will warn if any of the mesh module will try to send anything while the stack is suspended. Not clear what to do here as both advertisers (legacy and ext) behaves differently. The legacy advertiser has a thread which is stopped after the `bt_mesh_adv_disable` call and any sent advs after suspending the stack will stay in the pool until the advertiser is resumed. The extended advertiser will schedule its work, but then fail because `ext_adv->instance` value is NULL, but will call `bt_mesh_send_cb.start` with error `-ENODEV`. What to do with these 2 behaviors is unclear at the moment. Ideally none of the mesh stack modules should call `bt_mesh_adv_send` after the stack was suspended, so if this warning appears, the faulty module wasn't stopped properly and this should be fixed. If not to add the adv to the pool, then it kind of gets lost as the implementation probably expects one of `bt_mesh_send_cb` callbacks which will never be called. Leaving the warning until clear customer request comes. Signed-off-by: Pavel Vasilyev (cherry picked from commit 9171ee24da8f0042c6f96cac21daeb283f29b521) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/adv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index d51f0946b85..d9b191120d1 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -257,6 +257,10 @@ void bt_mesh_adv_send(struct bt_mesh_adv *adv, const struct bt_mesh_send_cb *cb, LOG_DBG("type 0x%02x len %u: %s", adv->ctx.type, adv->b.len, bt_hex(adv->b.data, adv->b.len)); + if (atomic_test_bit(bt_mesh.flags, BT_MESH_SUSPENDED)) { + LOG_WRN("Sending advertisement while suspended"); + } + adv->ctx.cb = cb; adv->ctx.cb_data = cb_data; adv->ctx.busy = 1U; From f64ac7ad2b66abaa44d615af28f0f04fabf828fa Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 8 Feb 2024 14:47:24 +0100 Subject: [PATCH 1305/1623] [nrf fromtree] Bluetooth: Mesh: Disable randomization in DFD model for canceling update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Disable randomization in the access layer when cancelling update in the distribution server model. This is needed because the server sends 2 messages in a row and the gets reordered by the access layer randomization feature making DFU/SR/FD/BV-43-C test to fail. This fixes DFU/SR/FD/BV-43-C test. Signed-off-by: Pavel Vasilyev (cherry picked from commit 44f86b81a3134ad6d9ac8d71c33c5880572cf8f8) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/dfd_srv.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 54184acd9b8..e765f2d5d7b 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -1148,6 +1148,14 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_cancel(struct bt_mesh_dfd_srv *srv, return BT_MESH_DFD_ERR_INTERNAL; } + if (prev_phase == BT_MESH_DFD_PHASE_APPLYING_UPDATE && ctx) { + /* Disable randomization for the Firmware Distribution State message to avoid + * reordering when Firmware Distribution Server sends 2 messages in a row when + * cancelling the update (see section 6.2.3.10 of MshDFUv1.0). + */ + ctx->rnd_delay = false; + } + if (ctx != NULL) { status_rsp(srv, ctx, BT_MESH_DFD_SUCCESS); } From 91f4f5af6aea0e653ef18d71dc85261e1633678f Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 8 Feb 2024 14:49:21 +0100 Subject: [PATCH 1306/1623] [nrf fromtree] Bluetooth: Mesh: Disable randomization on Link Close in RPR server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Disable randomization at the access layer in the Remote Provisioning server when sending Link Stauts message as a responce on Link Close message and then sending Link Report message right after it. Because of the randomization, the report message is sent before the status message which makes MESH/SR/RPR/PDU/BV-03-C test to fail. This fixes MESH/SR/RPR/PDU/BV-03-C test. Signed-off-by: Pavel Vasilyev (cherry picked from commit 0ea8cef97afe7b45719a2e181867e21f316d9347) Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/rpr_srv.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subsys/bluetooth/mesh/rpr_srv.c b/subsys/bluetooth/mesh/rpr_srv.c index e97df35f28f..ac3fd190880 100644 --- a/subsys/bluetooth/mesh/rpr_srv.c +++ b/subsys/bluetooth/mesh/rpr_srv.c @@ -968,6 +968,12 @@ static int handle_link_close(const struct bt_mesh_model *mod, struct bt_mesh_msg * which will be used in the link report when the link is fully closed. */ + /* Disable randomization for the Remote Provisioning Link Status message to avoid reordering + * of it with the Remote Provisioning Link Report message that shall be sent in a sequence + * when closing an active link (see section 4.4.5.5.3.3 of MshPRTv1.1). + */ + ctx->rnd_delay = false; + link_status_send(ctx, BT_MESH_RPR_SUCCESS); link_close(BT_MESH_RPR_ERR_LINK_CLOSED_BY_CLIENT, reason); From e325adbe0d71625323a5e9d8cedfa979491558c4 Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Wed, 17 Jan 2024 14:02:34 +0200 Subject: [PATCH 1307/1623] [nrf fromtree] net: lwm2m: Allow send operations when sleeping Add new kconfig CONFIG_LWM2M_QUEUE_MODE_NO_MSG_BUFFERING. When enabled and device is sleeping, Reqistration Update message is skipped and messages from send operation and notifications are sent right away. Reqistration update message is also skipped when lwm2m_engine resumes from pause state. Signed-off-by: Juha Ylinen (cherry picked from commit 9eee8d2be594a23eca102e21790e2d6db65ec2de) --- subsys/net/lib/lwm2m/Kconfig | 7 +++++++ subsys/net/lib/lwm2m/lwm2m_engine.c | 1 + subsys/net/lib/lwm2m/lwm2m_message_handling.c | 7 +++++++ subsys/net/lib/lwm2m/lwm2m_rd_client.c | 7 ++++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/lwm2m/Kconfig b/subsys/net/lib/lwm2m/Kconfig index 1e5a7ac8f6a..33a093308df 100644 --- a/subsys/net/lib/lwm2m/Kconfig +++ b/subsys/net/lib/lwm2m/Kconfig @@ -110,6 +110,13 @@ config LWM2M_QUEUE_MODE_UPTIME defaults to 93 seconds, see RFC 7252), it does not forbid other values though. +config LWM2M_QUEUE_MODE_NO_MSG_BUFFERING + bool "Disable buffering notifications and messages on queue mode" + select EXPERIMENTAL + help + Messages are sent right away instead of waiting for next registration update. + This might not be supported on all servers. + config LWM2M_TLS_SESSION_CACHING bool "TLS session caching" help diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index e08bb4ca17e..60ea1bdb794 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -244,6 +244,7 @@ int lwm2m_push_queued_buffers(struct lwm2m_ctx *client_ctx) break; } msg = SYS_SLIST_CONTAINER(msg_node, msg, node); + msg->pending->t0 = k_uptime_get(); sys_slist_append(&msg->ctx->pending_sends, &msg->node); } #endif diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 480c64372e8..19a2e1ccdd0 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -726,6 +726,13 @@ int lwm2m_information_interface_send(struct lwm2m_message *msg) return ret; } + if (IS_ENABLED(CONFIG_LWM2M_QUEUE_MODE_NO_MSG_BUFFERING)) { + sys_slist_append(&msg->ctx->pending_sends, &msg->node); + lwm2m_engine_wake_up(); + lwm2m_engine_connection_resume(msg->ctx); + return 0; + } + if (msg->ctx->buffer_client_messages) { sys_slist_append(&msg->ctx->queued_messages, &msg->node); lwm2m_engine_wake_up(); diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.c b/subsys/net/lib/lwm2m/lwm2m_rd_client.c index 95b576cb1c6..22ce51e5248 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.c +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.c @@ -1726,7 +1726,12 @@ int lwm2m_rd_client_connection_resume(struct lwm2m_ctx *client_ctx) IS_ENABLED(CONFIG_LWM2M_RD_CLIENT_LISTEN_AT_IDLE)) || !IS_ENABLED(CONFIG_LWM2M_DTLS_SUPPORT)) { client.engine_state = ENGINE_REGISTRATION_DONE; - client.trigger_update = true; + if (IS_ENABLED(CONFIG_LWM2M_QUEUE_MODE_NO_MSG_BUFFERING)) { + /* Force online for a short period */ + engine_update_tx_time(); + } else { + client.trigger_update = true; + } } else { client.engine_state = ENGINE_DO_REGISTRATION; } From 1e73fb82453c95c536aa491a4a78d4bb3a4786aa Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Mon, 22 Jan 2024 14:35:45 +0200 Subject: [PATCH 1308/1623] [nrf fromtree] net: lwm2m: Fix segfault on failed bootstrap If bootstrap fails, RD client will call lwm2m_engine_stop() which will close the context. The socket loop, however still contains a call to hint_socket_state(context, NULL) which has a null pointer now. Fix the segfault by allowing nullpointer on hint_socket_state(). Signed-off-by: Seppo Takalo (cherry picked from commit bf872870eab5177e2eb2700e5ebfde8e41a0a6d1) --- subsys/net/lib/lwm2m/lwm2m_engine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 60ea1bdb794..bad54c521d7 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -645,7 +645,7 @@ static int64_t check_notifications(struct lwm2m_ctx *ctx, const int64_t timestam */ static void hint_socket_state(struct lwm2m_ctx *ctx, struct lwm2m_message *ongoing_tx) { - if (!ctx->set_socket_state) { + if (!ctx || !ctx->set_socket_state) { return; } From 307f3191775d8390a35239ac9b6f9c2c92045ccf Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 25 Jan 2024 16:35:29 +0200 Subject: [PATCH 1309/1623] [nrf fromtree] net: lwm2m: Use CID_SUPPORTED instead of CID_ENABLED When ENABLED flag is used, we generate 32 byte DTLS Connection Identifier and include that in our DTLS Client HELO. This has no benefit as client only has one connection toward the server, it does not need any identification. When SUPPORTED flag is used, we just include zero length Connection Identifier in the handshake, which tell server that we support Connection Identifier and server can generate one for it. We then use the CID in the packets that we send towards server, but response packets don't contain any CID. This gives all the benefit of CID as server is able to identify us even when NAT mapping have changed. Signed-off-by: Seppo Takalo (cherry picked from commit 992936300bf684806ca02022399224a2030ad4e9) --- subsys/net/lib/lwm2m/lwm2m_engine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index bad54c521d7..55f23f77692 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -1060,7 +1060,7 @@ int lwm2m_set_default_sockopt(struct lwm2m_ctx *ctx) } if (IS_ENABLED(CONFIG_LWM2M_DTLS_CID)) { /* Enable CID */ - int cid = TLS_DTLS_CID_ENABLED; + int cid = TLS_DTLS_CID_SUPPORTED; ret = zsock_setsockopt(ctx->sock_fd, SOL_TLS, TLS_DTLS_CID, &cid, sizeof(cid)); From acb2e8c364292eeda394760fb470e24537d033c3 Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Thu, 18 Jan 2024 09:55:02 +0200 Subject: [PATCH 1310/1623] [nrf fromtree] tests: lwm2m: Update lwm2m_engine tests Fix lwm2m_message initialization. Pending struct was NULL. Signed-off-by: Juha Ylinen (cherry picked from commit c84dc7ee2ed6211eae7ec33abdbe5472fd5bf621) --- tests/net/lib/lwm2m/lwm2m_engine/src/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/net/lib/lwm2m/lwm2m_engine/src/main.c b/tests/net/lib/lwm2m/lwm2m_engine/src/main.c index 5d80f5d1049..7078fbebe6d 100644 --- a/tests/net/lib/lwm2m/lwm2m_engine/src/main.c +++ b/tests/net/lib/lwm2m/lwm2m_engine/src/main.c @@ -260,11 +260,13 @@ ZTEST(lwm2m_engine, test_push_queued_buffers) int ret; struct lwm2m_ctx ctx; struct lwm2m_message msg; + struct coap_pending pending; (void)memset(&ctx, 0x0, sizeof(ctx)); sys_slist_init(&ctx.queued_messages); msg.ctx = &ctx; + msg.pending = &pending; sys_slist_append(&ctx.queued_messages, &msg.node); ret = lwm2m_push_queued_buffers(&ctx); zassert_equal(ret, 0); @@ -391,6 +393,7 @@ ZTEST(lwm2m_engine, test_socket_send) int ret; struct lwm2m_ctx ctx; struct lwm2m_message msg; + struct coap_pending pending; (void)memset(&ctx, 0x0, sizeof(ctx)); @@ -398,6 +401,7 @@ ZTEST(lwm2m_engine, test_socket_send) ctx.sock_fd = -1; sys_slist_init(&ctx.queued_messages); msg.ctx = &ctx; + msg.pending = &pending; msg.type = COAP_TYPE_CON; sys_slist_append(&ctx.queued_messages, &msg.node); From 258a846cfb5d1cb8100d19dc67653c37b451033d Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Fri, 9 Feb 2024 12:28:15 +0100 Subject: [PATCH 1311/1623] [nrf fromtree] manifest: Update hal_nordic revision Updated hal_nordic fixes APPROTECT handling on nRF91 target, as well as fixes missing alignment of nrfx samples to modified API of the GPIOTE driver. Signed-off-by: Nikodem Kastelik (cherry picked from commit ba44a8663492e43349b82b0db62eeb334e2f1877) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 7ce69358f52..65c1c5a0837 100644 --- a/west.yml +++ b/west.yml @@ -183,7 +183,7 @@ manifest: groups: - hal - name: hal_nordic - revision: b55cfbbf0221d709560c2e438beef66842ada272 + revision: dce8519f7da37b0a745237679fd3f88250b495ff path: modules/hal/nordic groups: - hal From adde9221c022503fcf5011e8f2c6a71a884dfe92 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 5 Feb 2024 15:58:16 +0100 Subject: [PATCH 1312/1623] [nrf fromtree] Bluetooth: CAP: Fix uninitialized values in broadcast start When CONFIG_BT_ISO_TEST_PARAMS is enabled then the bt_bap_broadcast_source_param in bt_cap_initiator_broadcast_audio_create had uninitialized values. A general and future proof solution for this is to simply initialize the entire struct to 0. Signed-off-by: Emil Gydesen (cherry picked from commit f4b83415d6f39389eab3c4120d21ae2174c9740f) --- subsys/bluetooth/audio/cap_initiator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/audio/cap_initiator.c b/subsys/bluetooth/audio/cap_initiator.c index 46b39afcb41..3b8ee2fc3f2 100644 --- a/subsys/bluetooth/audio/cap_initiator.c +++ b/subsys/bluetooth/audio/cap_initiator.c @@ -192,7 +192,7 @@ int bt_cap_initiator_broadcast_audio_create( bap_subgroup_params[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT]; struct bt_bap_broadcast_source_stream_param bap_stream_params[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT]; - struct bt_bap_broadcast_source_param bap_create_param; + struct bt_bap_broadcast_source_param bap_create_param = {0}; CHECKIF(param == NULL) { LOG_DBG("param is NULL"); From c35cf22f87b5aceac52f574fbef6b0654b09d8f8 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 5 Feb 2024 15:46:22 +0100 Subject: [PATCH 1313/1623] [nrf fromtree] Bluetooth: BAP: Broadcast source enabling state transition fix Since we may go from enabling to qos-configured state if the call to bt_iso_big_create fails, that is a valid transition. If bt_iso_big_create currently fails, then the source ends in a state where it cannot be recovered. Signed-off-by: Emil Gydesen (cherry picked from commit 590d3e1114d09d2967929f6cc6897566948f2d3e) --- subsys/bluetooth/audio/bap_broadcast_source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/audio/bap_broadcast_source.c b/subsys/bluetooth/audio/bap_broadcast_source.c index 33fd1f0e17d..61ef7a1fe29 100644 --- a/subsys/bluetooth/audio/bap_broadcast_source.c +++ b/subsys/bluetooth/audio/bap_broadcast_source.c @@ -86,7 +86,7 @@ static void broadcast_source_set_ep_state(struct bt_bap_ep *ep, uint8_t state) } break; case BT_BAP_EP_STATE_ENABLING: - if (state != BT_BAP_EP_STATE_STREAMING) { + if (state != BT_BAP_EP_STATE_STREAMING && state != BT_BAP_EP_STATE_QOS_CONFIGURED) { LOG_DBG("Invalid broadcast sync endpoint state transition"); return; } From 617d3fb299da8cfcc4edbcb529b94a6fd51fea8c Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 1 Feb 2024 15:50:32 +0100 Subject: [PATCH 1314/1623] [nrf fromtree] Bluetooth: BAP: Do not send PA term request on local remove If the receive state is locally removed, then we should not request permission from the application, as that is implicit when removing the source locally. Signed-off-by: Emil Gydesen (cherry picked from commit 764352608676bac4caa1bb69c74ee9bacfa63a88) --- subsys/bluetooth/audio/bap_scan_delegator.c | 5 +++-- tests/bsim/bluetooth/audio/src/bap_scan_delegator_test.c | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/audio/bap_scan_delegator.c b/subsys/bluetooth/audio/bap_scan_delegator.c index 3cef96bd1b8..41f77391a68 100644 --- a/subsys/bluetooth/audio/bap_scan_delegator.c +++ b/subsys/bluetooth/audio/bap_scan_delegator.c @@ -863,8 +863,9 @@ static int scan_delegator_rem_src(struct bt_conn *conn, state = &internal_state->state; - if (state->pa_sync_state == BT_BAP_PA_STATE_INFO_REQ || - state->pa_sync_state == BT_BAP_PA_STATE_SYNCED) { + /* If conn == NULL then it's a local operation and we do not need to ask the application */ + if (conn != NULL && (state->pa_sync_state == BT_BAP_PA_STATE_INFO_REQ || + state->pa_sync_state == BT_BAP_PA_STATE_SYNCED)) { int err; /* Terminate PA sync */ diff --git a/tests/bsim/bluetooth/audio/src/bap_scan_delegator_test.c b/tests/bsim/bluetooth/audio/src/bap_scan_delegator_test.c index 8827a06bc93..81d3ed7ec2b 100644 --- a/tests/bsim/bluetooth/audio/src/bap_scan_delegator_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_scan_delegator_test.c @@ -616,6 +616,13 @@ static void remove_all_sources(void) printk("[%zu]: Source removed with id %u\n", i, state->src_id); + + printk("Terminating PA sync\n"); + err = pa_sync_term(state); + if (err) { + FAIL("[%zu]: PA sync term failed (err %d)\n", err); + return; + } } } } From 64350aec6d4d8d8c558978900981b7ec470c744b Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 1 Feb 2024 15:47:03 +0100 Subject: [PATCH 1315/1623] [nrf fromtree] Bluetooth: BAP: Stop broadcast sink from removing receive state The receive state may be added by the broadcast sink if not added by the application, but even in that case when the broadcast sink is deleted, we should not remove the receive state, as the receive state may still container information about the PA sync that has a lifetime not coupled with the broadcast sink. Signed-off-by: Emil Gydesen (cherry picked from commit 43bc3200faf5b3afe0b1c61883da37c14e38b115) --- subsys/bluetooth/audio/bap_broadcast_sink.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/subsys/bluetooth/audio/bap_broadcast_sink.c b/subsys/bluetooth/audio/bap_broadcast_sink.c index aa4bc08f761..ceafaf6389c 100644 --- a/subsys/bluetooth/audio/bap_broadcast_sink.c +++ b/subsys/bluetooth/audio/bap_broadcast_sink.c @@ -798,17 +798,6 @@ static void broadcast_sink_cleanup_streams(struct bt_bap_broadcast_sink *sink) static void broadcast_sink_cleanup(struct bt_bap_broadcast_sink *sink) { - if (atomic_test_bit(sink->flags, - BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID)) { - int err; - - err = bt_bap_scan_delegator_rem_src(sink->bass_src_id); - if (err != 0) { - /* This is likely due to the receive state been removed */ - LOG_DBG("Could not remove Receive State for sink %p: %d", sink, err); - } - } - if (sink->stream_count > 0U) { broadcast_sink_cleanup_streams(sink); } From e43120c251f8eec50381ab85d826204719059c7a Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 25 Jan 2024 09:18:52 +0100 Subject: [PATCH 1316/1623] [nrf fromtree] Bluetooth: BAP: client: Add support for source ASEs disconnects When the CIS of a source ASE disconnects, the server shall put it into the QoS Configured state, which is not really part of the state machine for source ASEs, but more like a hidden bonus state change. The state machine handler in the unicast client has been updated to support this state change. Signed-off-by: Emil Gydesen (cherry picked from commit b173c21d9c310c044198a10d52d937e54c2528d2) --- subsys/bluetooth/audio/bap_unicast_client.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index 36938129773..45523e003d4 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -1016,6 +1016,8 @@ static void unicast_client_ep_set_status(struct bt_bap_ep *ep, struct net_buf_si case BT_BAP_EP_STATE_CODEC_CONFIGURED: /* or 0x02 (QoS Configured) */ case BT_BAP_EP_STATE_QOS_CONFIGURED: + /* or 0x04 (Streaming) if there is a disconnect */ + case BT_BAP_EP_STATE_STREAMING: /* or 0x05 (Disabling) */ case BT_BAP_EP_STATE_DISABLING: break; From a48cd2d332771553e39c90d8f0ac74c30fa422b2 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 22 Jan 2024 08:47:27 +0100 Subject: [PATCH 1317/1623] [nrf fromtree] Bluetooth: BAP: Add missing reset of client on disconnected If we disconnect in the middle of e.g. a discovery, then client-busy (and other values) were not correctly reset, which effectively rendered the client useless. Signed-off-by: Emil Gydesen (cherry picked from commit 8b8569e1da447978bc44e57d085f750415fe3efa) --- subsys/bluetooth/audio/bap_unicast_client.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index 45523e003d4..7cbde2464c2 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -2055,6 +2055,7 @@ static void unicast_client_reset(struct bt_bap_ep *ep, uint8_t reason) static void unicast_client_ep_reset(struct bt_conn *conn, uint8_t reason) { + struct unicast_client *client; uint8_t index; LOG_DBG("conn %p", conn); @@ -2076,6 +2077,11 @@ static void unicast_client_ep_reset(struct bt_conn *conn, uint8_t reason) unicast_client_reset(ep, reason); } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 */ + + client = &uni_cli_insts[index]; + client->busy = false; + client->dir = 0U; + reset_att_buf(client); } static void bt_audio_codec_qos_to_cig_param(struct bt_iso_cig_param *cig_param, From fc4e559df38a0d201bb2b94bf622457a5c5652f6 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 12 Jan 2024 11:32:30 +0100 Subject: [PATCH 1318/1623] [nrf fromtree] Bluetooth: Audio: Fix off-by-one error in codec.c:ltv_set_val The function did not move data correctly when increasing or decreasing the size of a value that was not the last value in the LTV array. Added a few tests to verify the fix, using the CCID list as the main way of verifying it. Signed-off-by: Emil Gydesen (cherry picked from commit 68f8c8ff29d0c72d77acb1db7dc66ad669731965) --- subsys/bluetooth/audio/codec.c | 4 +- tests/bluetooth/audio/codec/src/main.c | 111 ++++++++++++++++++++++++- 2 files changed, 112 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/audio/codec.c b/subsys/bluetooth/audio/codec.c index 38b1ef7d22b..e376b71d1c3 100644 --- a/subsys/bluetooth/audio/codec.c +++ b/subsys/bluetooth/audio/codec.c @@ -162,8 +162,8 @@ static int ltv_set_val(struct net_buf_simple *buf, uint8_t type, const uint8_t * if (value + value_len == buf->data + buf->len) { data_len_to_move = 0U; } else { - old_next_data_start = value + value_len + 1; - new_next_data_start = value + data_len + 1; + old_next_data_start = value + value_len; + new_next_data_start = value + data_len; data_len_to_move = buf->len - (old_next_data_start - buf->data); } diff --git a/tests/bluetooth/audio/codec/src/main.c b/tests/bluetooth/audio/codec/src/main.c index 386ef40e7f7..3b909e4582f 100644 --- a/tests/bluetooth/audio/codec/src/main.c +++ b/tests/bluetooth/audio/codec/src/main.c @@ -57,6 +57,26 @@ ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_get_freq) zassert_equal(ret, 0x03, "unexpected return value %d", ret); } +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_set_val_new) +{ + struct bt_bap_lc3_preset preset = BT_BAP_LC3_UNICAST_PRESET_16_2_1( + BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); + const uint8_t frame_blocks = 0x02; + int ret; + + /* Frame blocks are not part of the preset, so we can use that to test adding a new type to + * the config + */ + ret = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&preset.codec_cfg, false); + zassert_equal(ret, -ENODATA, "Unexpected return value %d", ret); + + ret = bt_audio_codec_cfg_set_frame_blocks_per_sdu(&preset.codec_cfg, frame_blocks); + zassert_true(ret > 0, "Unexpected return value %d", ret); + + ret = bt_audio_codec_cfg_get_frame_blocks_per_sdu(&preset.codec_cfg, false); + zassert_equal(ret, frame_blocks, "Unexpected return value %d", ret); +} + ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_set_freq) { struct bt_bap_lc3_preset preset = BT_BAP_LC3_UNICAST_PRESET_16_2_1( @@ -371,7 +391,7 @@ ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_ccid_list) zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data)); } -ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_ccid_list) +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_ccid_list_shorter) { const uint8_t expected_data[] = {0x05, 0x10, 0x15}; const uint8_t new_expected_data[] = {0x25, 0x30}; @@ -394,6 +414,95 @@ ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_ccid_list) zassert_mem_equal(new_expected_data, ccid_list, ARRAY_SIZE(new_expected_data)); } +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_ccid_list_longer) +{ + const uint8_t expected_data[] = {0x05, 0x10, 0x15}; + const uint8_t new_expected_data[] = {0x25, 0x30, 0x35, 0x40}; + struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG( + BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, + {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15)}); + const uint8_t *ccid_list; + int ret; + + ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list); + zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); + zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data)); + + ret = bt_audio_codec_cfg_meta_set_ccid_list(&codec_cfg, new_expected_data, + ARRAY_SIZE(new_expected_data)); + zassert_true(ret > 0, "Unexpected return value %d", ret); + + ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list); + zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret); + zassert_mem_equal(new_expected_data, ccid_list, ARRAY_SIZE(new_expected_data)); +} + +/* Providing multiple BT_AUDIO_CODEC_DATA to BT_AUDIO_CODEC_CFG without packing it in a macro + * cause compile issue, so define a macro to denote 2 types of data for the ccid_list_first tests + */ +#define DOUBLE_CFG_DATA \ + { \ + BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, 0x05, 0x10, 0x15), \ + BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING, \ + BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE) \ + } + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_ccid_list_first_shorter) +{ + const uint8_t expected_data[] = {0x05, 0x10, 0x15}; + const uint8_t new_expected_data[] = {0x25, 0x30}; + struct bt_audio_codec_cfg codec_cfg = + BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, DOUBLE_CFG_DATA); + const uint8_t *ccid_list; + int ret; + + ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list); + zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); + zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data)); + + ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg); + zassert_equal(ret, 0x07, "Unexpected return value %d", ret); + + ret = bt_audio_codec_cfg_meta_set_ccid_list(&codec_cfg, new_expected_data, + ARRAY_SIZE(new_expected_data)); + zassert_true(ret > 0, "Unexpected return value %d", ret); + + ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list); + zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret); + zassert_mem_equal(new_expected_data, ccid_list, ARRAY_SIZE(new_expected_data)); + + ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg); + zassert_equal(ret, 0x07, "Unexpected return value %d", ret); +} + +ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_ccid_list_first_longer) +{ + const uint8_t expected_data[] = {0x05, 0x10, 0x15}; + const uint8_t new_expected_data[] = {0x25, 0x30, 0x35, 0x40}; + struct bt_audio_codec_cfg codec_cfg = + BT_AUDIO_CODEC_CFG(BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, DOUBLE_CFG_DATA); + const uint8_t *ccid_list; + int ret; + + ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list); + zassert_equal(ret, ARRAY_SIZE(expected_data), "Unexpected return value %d", ret); + zassert_mem_equal(expected_data, ccid_list, ARRAY_SIZE(expected_data)); + + ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg); + zassert_equal(ret, 0x07, "Unexpected return value %d", ret); + + ret = bt_audio_codec_cfg_meta_set_ccid_list(&codec_cfg, new_expected_data, + ARRAY_SIZE(new_expected_data)); + zassert_true(ret > 0, "Unexpected return value %d", ret); + + ret = bt_audio_codec_cfg_meta_get_ccid_list(&codec_cfg, &ccid_list); + zassert_equal(ret, ARRAY_SIZE(new_expected_data), "Unexpected return value %d", ret); + zassert_mem_equal(new_expected_data, ccid_list, ARRAY_SIZE(new_expected_data)); + + ret = bt_audio_codec_cfg_meta_get_parental_rating(&codec_cfg); + zassert_equal(ret, 0x07, "Unexpected return value %d", ret); +} + ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_get_parental_rating) { const struct bt_audio_codec_cfg codec_cfg = From 390f21f4660ba71279d97230f84b26bcb24549a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Rist=20Sk=C3=B8ien?= Date: Mon, 29 Jan 2024 16:49:25 +0100 Subject: [PATCH 1319/1623] [nrf fromtree] Bluetooth: Audio: Moved seq_num check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moved seq_num check to after bt_iso_chan_send. This prevents WRN prints if ISO send fails. Signed-off-by: Kristoffer Rist Skøien (cherry picked from commit ace435d0d17015bf97a07264c5f02a2cf64ed504) --- subsys/bluetooth/audio/bap_stream.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/audio/bap_stream.c b/subsys/bluetooth/audio/bap_stream.c index d6df9524e14..fd38a90371c 100644 --- a/subsys/bluetooth/audio/bap_stream.c +++ b/subsys/bluetooth/audio/bap_stream.c @@ -245,6 +245,7 @@ static bool bt_bap_stream_can_send(const struct bt_bap_stream *stream) int bt_bap_stream_send(struct bt_bap_stream *stream, struct net_buf *buf, uint16_t seq_num, uint32_t ts) { + int ret; struct bt_bap_ep *ep; if (stream == NULL || stream->ep == NULL) { @@ -265,6 +266,12 @@ int bt_bap_stream_send(struct bt_bap_stream *stream, struct net_buf *buf, return -EBADMSG; } + ret = bt_iso_chan_send(bt_bap_stream_iso_chan_get(stream), + buf, seq_num, ts); + if (ret) { + return ret; + } + #if defined(CONFIG_BT_BAP_DEBUG_STREAM_SEQ_NUM) if (stream->_prev_seq_num != 0U && seq_num != 0U && (stream->_prev_seq_num + 1U) != seq_num) { @@ -277,8 +284,7 @@ int bt_bap_stream_send(struct bt_bap_stream *stream, struct net_buf *buf, /* TODO: Add checks for broadcast sink */ - return bt_iso_chan_send(bt_bap_stream_iso_chan_get(stream), - buf, seq_num, ts); + return ret; } int bt_bap_stream_get_tx_sync(struct bt_bap_stream *stream, struct bt_iso_tx_info *info) From 79389295d6135633e458107cd76be8e8819a695e Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Tue, 21 Nov 2023 12:45:10 +0100 Subject: [PATCH 1320/1623] [nrf fromtree] Bluetooth: audio: ascs: Remove spurious error message This removes spurious error message printed when CIS has been disconnected and it was not used by any of the endpoints. This case is valid and may happen on Connection Timeout when the controller reports ACL Disconnection first. When the CIS Disconnection is reported after, the ASE is already in idle state and the referenece to CIS has been already removed (on ACL disconnection). Fixes: #64896 Signed-off-by: Mariusz Skamra (cherry picked from commit b37307927523ac4a38b4e81c50baebff37b8b5c5) --- subsys/bluetooth/audio/ascs.c | 1 - 1 file changed, 1 deletion(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 1709bc452d8..4127b1a4ce4 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -945,7 +945,6 @@ static void ascs_iso_disconnected(struct bt_iso_chan *chan, uint8_t reason) struct bt_bap_iso *iso = CONTAINER_OF(chan, struct bt_bap_iso, chan); if (iso->rx.ep == NULL && iso->tx.ep == NULL) { - LOG_ERR("iso %p not bound with ep", chan); return; } From e5a2ebaad073aa01d1da37053e6ce5cbc3d67424 Mon Sep 17 00:00:00 2001 From: Magdalena Kasenberg Date: Wed, 20 Dec 2023 16:47:34 +0100 Subject: [PATCH 1321/1623] [nrf fromtree] bluetooth: audio: broadcast: Fix missing update of meta_len The length of the updated metadata was not updated. Fixes the CAP/INI/BST/BV-13-C test case. Signed-off-by: Magdalena Kasenberg (cherry picked from commit e05d964b461ea6d1df846bf54dab464232ece6e2) --- subsys/bluetooth/audio/bap_broadcast_source.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/bluetooth/audio/bap_broadcast_source.c b/subsys/bluetooth/audio/bap_broadcast_source.c index 61ef7a1fe29..132578470d7 100644 --- a/subsys/bluetooth/audio/bap_broadcast_source.c +++ b/subsys/bluetooth/audio/bap_broadcast_source.c @@ -938,6 +938,7 @@ int bt_bap_broadcast_source_update_metadata(struct bt_bap_broadcast_source *sour SYS_SLIST_FOR_EACH_CONTAINER(&source->subgroups, subgroup, _node) { memset(subgroup->codec_cfg->meta, 0, sizeof(subgroup->codec_cfg->meta)); memcpy(subgroup->codec_cfg->meta, meta, meta_len); + subgroup->codec_cfg->meta_len = meta_len; } return 0; From 8afed95b636fa443639e05f0c491b6e04d1de1e0 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 2 Jan 2024 14:55:00 +0100 Subject: [PATCH 1322/1623] [nrf fromtree] Bluetooth: Audio: Fix len check in ltv_set_val The length check in ltv_set_val did not consider the size of the length or type fields. Signed-off-by: Emil Gydesen (cherry picked from commit 234b322dc306a1c936161e4107370dcf5c9cb59e) --- subsys/bluetooth/audio/codec.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/audio/codec.c b/subsys/bluetooth/audio/codec.c index e376b71d1c3..3f5f2b56629 100644 --- a/subsys/bluetooth/audio/codec.c +++ b/subsys/bluetooth/audio/codec.c @@ -142,6 +142,8 @@ static bool parse_cb(struct bt_data *data, void *user_data) static int ltv_set_val(struct net_buf_simple *buf, uint8_t type, const uint8_t *data, size_t data_len) { + size_t new_buf_len; + for (uint16_t i = 0U; i < buf->len;) { uint8_t *len = &buf->data[i++]; const uint8_t data_type = buf->data[i++]; @@ -207,11 +209,12 @@ static int ltv_set_val(struct net_buf_simple *buf, uint8_t type, const uint8_t * } /* If we reach here, we did not find the data in the buffer, so we simply add it */ - if ((buf->len + data_len) <= buf->size) { - net_buf_simple_add_u8(buf, data_len + sizeof(type)); - net_buf_simple_add_u8(buf, type); + new_buf_len = buf->len + 1 /* len */ + sizeof(type) + data_len; + if (new_buf_len <= buf->size) { + net_buf_simple_add_u8(buf, data_len + sizeof(type)); /* len */ + net_buf_simple_add_u8(buf, type); /* type */ if (data_len > 0) { - net_buf_simple_add_mem(buf, data, data_len); + net_buf_simple_add_mem(buf, data, data_len); /* value */ } } else { LOG_DBG("Cannot fit data_len %zu in codec_cfg with len %u and size %u", data_len, From 617f2d3fc477a6e11863e2edae3f98b4e4ba533e Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 3 Jan 2024 09:58:07 +0100 Subject: [PATCH 1323/1623] [nrf fromtree] Bluetooth: BAP: Fix uninitialized variable in source_reconfig The stream_in_subgroup variable in bt_bap_broadcast_source_reconfig may have been uninitialized. Signed-off-by: Emil Gydesen (cherry picked from commit f4cbf403e8238109fd5b00add8e5dee4114aeb61) --- subsys/bluetooth/audio/bap_broadcast_source.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/audio/bap_broadcast_source.c b/subsys/bluetooth/audio/bap_broadcast_source.c index 132578470d7..2167366c7e1 100644 --- a/subsys/bluetooth/audio/bap_broadcast_source.c +++ b/subsys/bluetooth/audio/bap_broadcast_source.c @@ -788,7 +788,7 @@ int bt_bap_broadcast_source_reconfig(struct bt_bap_broadcast_source *source, for (size_t i = 0U; i < subgroup_param->params_count; i++) { struct bt_bap_stream *subgroup_stream; struct bt_bap_stream *param_stream; - bool stream_in_subgroup; + bool stream_in_subgroup = false; param_stream = subgroup_param->params[i].stream; From 43ce6c74715ba933ff6866bab323bbcbf2a3f4a3 Mon Sep 17 00:00:00 2001 From: Adam Cavender Date: Mon, 27 Nov 2023 10:55:45 +0000 Subject: [PATCH 1324/1623] [nrf fromtree] Bluetooth: Host: Fix bt_le_set_chan_map Allow the channel map to be set when periodic advertising or acting as an ISO source. Signed-off-by: Adam Cavender (cherry picked from commit ad485866b083f470c01e1b07575866423a00dc45) --- subsys/bluetooth/host/hci_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index ee1c822d9f9..dbb79f3ecdd 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -4326,7 +4326,7 @@ int bt_le_set_chan_map(uint8_t chan_map[5]) struct bt_hci_cp_le_set_host_chan_classif *cp; struct net_buf *buf; - if (!IS_ENABLED(CONFIG_BT_CENTRAL)) { + if (!(IS_ENABLED(CONFIG_BT_CENTRAL) || IS_ENABLED(CONFIG_BT_BROADCASTER))) { return -ENOTSUP; } From ff855dc9516a0a02341165379ba86f2ddc17447d Mon Sep 17 00:00:00 2001 From: Adam Cavender Date: Mon, 27 Nov 2023 12:39:15 +0000 Subject: [PATCH 1325/1623] [nrf fromtree] Bluetooth: Shell: Fix cmd_chan_map Allow the channel map to be set when periodic advertising or acting as an ISO source. Signed-off-by: Adam Cavender (cherry picked from commit ac4f9a6962e17cf1e34b7238aec44b6f7b0f1417) --- subsys/bluetooth/shell/bt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index 4e0111fa757..ac1d78c44df 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -4286,7 +4286,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds, SHELL_CMD_ARG(phy-update, NULL, " [rx_phy] [s2] [s8]", cmd_conn_phy_update, 2, 3), #endif -#if defined(CONFIG_BT_CENTRAL) +#if defined(CONFIG_BT_CENTRAL) || defined(CONFIG_BT_BROADCASTER) SHELL_CMD_ARG(channel-map, NULL, " (36-0)", cmd_chan_map, 2, 1), #endif /* CONFIG_BT_CENTRAL */ From 5c8e8e21b020d19eb1e05c186dd576ab71d83ce9 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Thu, 25 Jan 2024 11:14:44 +0100 Subject: [PATCH 1326/1623] [nrf fromtree] net: dhcpv4_server: Improve address pool range validation Not only check if the address pool belongs to the same subnet as the server, but also that it does not overlap with the server address - otherwise the server might end up assigning its own address. Signed-off-by: Robert Lubos (cherry picked from commit a147ac9a47dee34f16ebd26a3d0af59afbb7cb39) --- subsys/net/lib/dhcpv4/dhcpv4_server.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/subsys/net/lib/dhcpv4/dhcpv4_server.c b/subsys/net/lib/dhcpv4/dhcpv4_server.c index 714d036ddde..5940c8ca207 100644 --- a/subsys/net/lib/dhcpv4/dhcpv4_server.c +++ b/subsys/net/lib/dhcpv4/dhcpv4_server.c @@ -1224,6 +1224,13 @@ int net_dhcpv4_server_start(struct net_if *iface, struct in_addr *base_addr) return -EINVAL; } + if ((htonl(server_addr->s_addr) >= htonl(base_addr->s_addr)) && + (htonl(server_addr->s_addr) < + htonl(base_addr->s_addr) + CONFIG_NET_DHCPV4_SERVER_ADDR_COUNT)) { + LOG_ERR("Address pool overlaps with server address."); + return -EINVAL; + } + netmask = net_if_ipv4_get_netmask(iface); if (net_ipv4_is_addr_unspecified(&netmask)) { LOG_ERR("Failed to obtain subnet mask."); From f0a7caf91fbfa3b9479390743bbb485c20c07c9e Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Fri, 26 Jan 2024 14:39:22 +0100 Subject: [PATCH 1327/1623] [nrf fromtree] net: dhcpv4_server: Implement ICMP probing of offered addresses DHCPv4 server will send an ICMP probe (echo request) for the requested address before replying with DHCP Offer, unless probing is disabled in Kconfig. Signed-off-by: Robert Lubos (cherry picked from commit 3c76ff9a8c41d217bf6c28d930f2620cb5cd26a2) --- subsys/net/lib/dhcpv4/Kconfig | 8 + subsys/net/lib/dhcpv4/dhcpv4_server.c | 251 ++++++++++++++++++++++++-- 2 files changed, 241 insertions(+), 18 deletions(-) diff --git a/subsys/net/lib/dhcpv4/Kconfig b/subsys/net/lib/dhcpv4/Kconfig index 801d536a5a1..8ae65344f31 100644 --- a/subsys/net/lib/dhcpv4/Kconfig +++ b/subsys/net/lib/dhcpv4/Kconfig @@ -43,4 +43,12 @@ config NET_DHCPV4_SERVER_ADDR_LEASE_TIME The lease time determines when the IPv4 address lease expires if the client does not renew it. +config NET_DHCPV4_SERVER_ICMP_PROBE_TIMEOUT + int "Timeout for ICMP probes sent by the server (miliseconds)" + default 1000 + help + DHCPv4 server will probe the offered IP address (send ICMP echo + request) and wait for the time specific by this config before offering + the address. If set to 0, ICMP probing will be disabled. + endif # NET_DHCPV4_SERVER diff --git a/subsys/net/lib/dhcpv4/dhcpv4_server.c b/subsys/net/lib/dhcpv4/dhcpv4_server.c index 5940c8ca207..e683fdf5f0e 100644 --- a/subsys/net/lib/dhcpv4/dhcpv4_server.c +++ b/subsys/net/lib/dhcpv4/dhcpv4_server.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -31,10 +32,29 @@ LOG_MODULE_REGISTER(net_dhcpv4_server, CONFIG_NET_DHCPV4_SERVER_LOG_LEVEL); #define DHCPV4_OPTIONS_CLIENT_ID_MIN_SIZE 2 #define ADDRESS_RESERVED_TIMEOUT K_SECONDS(5) +#define ADDRESS_PROBE_TIMEOUT K_MSEC(CONFIG_NET_DHCPV4_SERVER_ICMP_PROBE_TIMEOUT) + +#if (CONFIG_NET_DHCPV4_SERVER_ICMP_PROBE_TIMEOUT > 0) +#define DHCPV4_SERVER_ICMP_PROBE 1 +#endif /* RFC 1497 [17] */ static const uint8_t magic_cookie[4] = { 0x63, 0x82, 0x53, 0x63 }; +#define DHCPV4_MAX_PARAMETERS_REQUEST_LEN 16 + +struct dhcpv4_parameter_request_list { + uint8_t list[DHCPV4_MAX_PARAMETERS_REQUEST_LEN]; + uint8_t count; +}; + +struct dhcpv4_server_probe_ctx { + struct net_icmp_ctx icmp_ctx; + struct dhcp_msg discovery; + struct dhcpv4_parameter_request_list params; + struct dhcpv4_addr_slot *slot; +}; + struct dhcpv4_server_ctx { struct net_if *iface; int sock; @@ -42,19 +62,15 @@ struct dhcpv4_server_ctx { struct dhcpv4_addr_slot addr_pool[CONFIG_NET_DHCPV4_SERVER_ADDR_COUNT]; struct in_addr server_addr; struct in_addr netmask; +#if defined(DHCPV4_SERVER_ICMP_PROBE) + struct dhcpv4_server_probe_ctx probe_ctx; +#endif }; static struct dhcpv4_server_ctx server_ctx[CONFIG_NET_DHCPV4_SERVER_INSTANCES]; static struct zsock_pollfd fds[CONFIG_NET_DHCPV4_SERVER_INSTANCES]; static K_MUTEX_DEFINE(server_lock); -#define DHCPV4_MAX_PARAMETERS_REQUEST_LEN 16 - -struct dhcpv4_parameter_request_list { - uint8_t list[DHCPV4_MAX_PARAMETERS_REQUEST_LEN]; - uint8_t count; -}; - static void dhcpv4_server_timeout_recalc(struct dhcpv4_server_ctx *ctx) { k_timepoint_t next = sys_timepoint_calc(K_FOREVER); @@ -667,6 +683,167 @@ static uint32_t dhcpv4_get_lease_time(uint8_t *options, uint8_t optlen) return CONFIG_NET_DHCPV4_SERVER_ADDR_LEASE_TIME; } +#if defined(DHCPV4_SERVER_ICMP_PROBE) +static int dhcpv4_probe_address(struct dhcpv4_server_ctx *ctx, + struct dhcpv4_addr_slot *slot) +{ + struct sockaddr_in dest_addr = { + .sin_family = AF_INET, + .sin_addr = slot->addr, + }; + int ret; + + ret = net_icmp_send_echo_request(&ctx->probe_ctx.icmp_ctx, ctx->iface, + (struct sockaddr *)&dest_addr, + NULL, ctx); + if (ret < 0) { + LOG_ERR("Failed to send ICMP probe"); + } + + return ret; +} + +static int echo_reply_handler(struct net_icmp_ctx *icmp_ctx, + struct net_pkt *pkt, + struct net_icmp_ip_hdr *ip_hdr, + struct net_icmp_hdr *icmp_hdr, + void *user_data) +{ + struct dhcpv4_server_ctx *ctx = user_data; + struct dhcpv4_server_probe_ctx *probe_ctx = &ctx->probe_ctx; + struct dhcpv4_addr_slot *new_slot = NULL; + struct in_addr peer_addr; + + ARG_UNUSED(icmp_ctx); + ARG_UNUSED(pkt); + ARG_UNUSED(ip_hdr); + ARG_UNUSED(icmp_hdr); + + k_mutex_lock(&server_lock, K_FOREVER); + + if (probe_ctx->slot == NULL) { + goto out; + } + + if (ip_hdr->family != AF_INET) { + goto out; + } + + net_ipv4_addr_copy_raw((uint8_t *)&peer_addr, ip_hdr->ipv4->src); + if (!net_ipv4_addr_cmp(&peer_addr, &probe_ctx->slot->addr)) { + goto out; + } + + LOG_DBG("Got ICMP probe response, blocking address %s", + net_sprint_ipv4_addr(&probe_ctx->slot->addr)); + + probe_ctx->slot->state = DHCPV4_SERVER_ADDR_DECLINED; + + /* Try to find next free address */ + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; + + if (slot->state == DHCPV4_SERVER_ADDR_FREE) { + new_slot = slot; + break; + } + } + + if (new_slot == NULL) { + LOG_DBG("No more free addresses to assign, ICMP probing stopped"); + probe_ctx->slot = NULL; + dhcpv4_server_timeout_recalc(ctx); + goto out; + } + + if (dhcpv4_probe_address(ctx, new_slot) < 0) { + probe_ctx->slot = NULL; + dhcpv4_server_timeout_recalc(ctx); + goto out; + } + + new_slot->state = DHCPV4_SERVER_ADDR_RESERVED; + new_slot->expiry = sys_timepoint_calc(ADDRESS_PROBE_TIMEOUT); + new_slot->client_id.len = probe_ctx->slot->client_id.len; + memcpy(new_slot->client_id.buf, probe_ctx->slot->client_id.buf, + new_slot->client_id.len); + new_slot->lease_time = probe_ctx->slot->lease_time; + + probe_ctx->slot = new_slot; + + dhcpv4_server_timeout_recalc(ctx); + +out: + k_mutex_unlock(&server_lock); + + return 0; +} + +static int dhcpv4_server_probing_init(struct dhcpv4_server_ctx *ctx) +{ + return net_icmp_init_ctx(&ctx->probe_ctx.icmp_ctx, + NET_ICMPV4_ECHO_REPLY, 0, + echo_reply_handler); +} + +static void dhcpv4_server_probing_deinit(struct dhcpv4_server_ctx *ctx) +{ + (void)net_icmp_cleanup_ctx(&ctx->probe_ctx.icmp_ctx); +} + +static int dhcpv4_server_probe_setup(struct dhcpv4_server_ctx *ctx, + struct dhcpv4_addr_slot *slot, + struct dhcp_msg *msg, + struct dhcpv4_parameter_request_list *params) +{ + int ret; + + if (ctx->probe_ctx.slot != NULL) { + return -EBUSY; + } + + ret = dhcpv4_probe_address(ctx, slot); + if (ret < 0) { + return ret; + } + + ctx->probe_ctx.slot = slot; + ctx->probe_ctx.discovery = *msg; + ctx->probe_ctx.params = *params; + + return 0; +} + +static void dhcpv4_server_probe_timeout(struct dhcpv4_server_ctx *ctx, + struct dhcpv4_addr_slot *slot) +{ + /* Probe timer expired, send offer. */ + ctx->probe_ctx.slot = NULL; + + (void)net_arp_clear_pending(ctx->iface, &slot->addr); + + if (dhcpv4_send_offer(ctx, &ctx->probe_ctx.discovery, &slot->addr, + slot->lease_time, &ctx->probe_ctx.params) < 0) { + slot->state = DHCPV4_SERVER_ADDR_FREE; + return; + } + + slot->expiry = sys_timepoint_calc(ADDRESS_RESERVED_TIMEOUT); +} + +static bool dhcpv4_server_is_slot_probed(struct dhcpv4_server_ctx *ctx, + struct dhcpv4_addr_slot *slot) +{ + return (ctx->probe_ctx.slot == slot); +} +#else /* defined(DHCPV4_SERVER_ICMP_PROBE) */ +#define dhcpv4_server_probing_init(...) (0) +#define dhcpv4_server_probing_deinit(...) +#define dhcpv4_server_probe_setup(...) (-ENOTSUP) +#define dhcpv4_server_probe_timeout(...) +#define dhcpv4_server_is_slot_probed(...) (false) +#endif /* defined(DHCPV4_SERVER_ICMP_PROBE) */ + static void dhcpv4_handle_discover(struct dhcpv4_server_ctx *ctx, struct dhcp_msg *msg, uint8_t *options, uint8_t optlen) @@ -674,6 +851,7 @@ static void dhcpv4_handle_discover(struct dhcpv4_server_ctx *ctx, struct dhcpv4_parameter_request_list params = { 0 }; struct dhcpv4_addr_slot *selected = NULL; struct dhcpv4_client_id client_id; + bool probe = false; int ret; ret = dhcpv4_get_client_id(msg, options, optlen, &client_id); @@ -696,6 +874,12 @@ static void dhcpv4_handle_discover(struct dhcpv4_server_ctx *ctx, slot->client_id.len == client_id.len && memcmp(slot->client_id.buf, client_id.buf, client_id.len) == 0) { + if (slot->state == DHCPV4_SERVER_ADDR_RESERVED && + dhcpv4_server_is_slot_probed(ctx, slot)) { + LOG_DBG("ICMP probing in progress, ignore Discovery"); + return; + } + /* Got match in current bindings. */ selected = slot; break; @@ -720,6 +904,7 @@ static void dhcpv4_handle_discover(struct dhcpv4_server_ctx *ctx, slot->state == DHCPV4_SERVER_ADDR_FREE) { /* Requested address is free. */ selected = slot; + probe = true; break; } } @@ -742,6 +927,7 @@ static void dhcpv4_handle_discover(struct dhcpv4_server_ctx *ctx, if (slot->state == DHCPV4_SERVER_ADDR_FREE) { /* Requested address is free. */ selected = slot; + probe = true; break; } } @@ -752,9 +938,26 @@ static void dhcpv4_handle_discover(struct dhcpv4_server_ctx *ctx, } else { uint32_t lease_time = dhcpv4_get_lease_time(options, optlen); - if (dhcpv4_send_offer(ctx, msg, &selected->addr, lease_time, - ¶ms) < 0) { - return; + if (IS_ENABLED(DHCPV4_SERVER_ICMP_PROBE) && probe) { + if (dhcpv4_server_probe_setup(ctx, selected, + msg, ¶ms) < 0) { + /* Probing context already in use or failed to + * send probe, ignore Discovery for now and wait + * for retransmission. + */ + return; + } + + selected->expiry = + sys_timepoint_calc(ADDRESS_PROBE_TIMEOUT); + } else { + if (dhcpv4_send_offer(ctx, msg, &selected->addr, + lease_time, ¶ms) < 0) { + return; + } + + selected->expiry = + sys_timepoint_calc(ADDRESS_RESERVED_TIMEOUT); } LOG_DBG("DHCPv4 processing Discover - reserved %s", @@ -764,7 +967,6 @@ static void dhcpv4_handle_discover(struct dhcpv4_server_ctx *ctx, selected->client_id.len = client_id.len; memcpy(selected->client_id.buf, client_id.buf, client_id.len); selected->lease_time = lease_time; - selected->expiry = sys_timepoint_calc(ADDRESS_RESERVED_TIMEOUT); dhcpv4_server_timeout_recalc(ctx); } } @@ -1061,15 +1263,18 @@ static void dhcpv4_server_timeout(struct k_work *work) struct dhcpv4_server_ctx *ctx = CONTAINER_OF(dwork, struct dhcpv4_server_ctx, timeout_work); - k_mutex_lock(&server_lock, K_FOREVER); for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; - if (slot->state == DHCPV4_SERVER_ADDR_RESERVED || - slot->state == DHCPV4_SERVER_ADDR_ALLOCATED) { - if (sys_timepoint_expired(slot->expiry)) { + if ((slot->state == DHCPV4_SERVER_ADDR_RESERVED || + slot->state == DHCPV4_SERVER_ADDR_ALLOCATED) && + sys_timepoint_expired(slot->expiry)) { + if (slot->state == DHCPV4_SERVER_ADDR_RESERVED && + dhcpv4_server_is_slot_probed(ctx, slot)) { + dhcpv4_server_probe_timeout(ctx, slot); + } else { LOG_DBG("Address %s expired", net_sprint_ipv4_addr(&slot->addr)); slot->state = DHCPV4_SERVER_ADDR_FREE; @@ -1310,19 +1515,28 @@ int net_dhcpv4_server_start(struct net_if *iface, struct in_addr *base_addr) &server_ctx[slot].addr_pool[i].addr)); } + ret = dhcpv4_server_probing_init(&server_ctx[slot]); + if (ret < 0) { + LOG_ERR("Failed to register probe handler, %d", ret); + goto cleanup; + } + ret = net_socket_service_register(&dhcpv4_server, fds, ARRAY_SIZE(fds), NULL); if (ret < 0) { LOG_ERR("Failed to register socket service, %d", ret); - memset(&server_ctx[slot], 0, sizeof(server_ctx[slot])); - fds[slot].fd = -1; - goto error; + dhcpv4_server_probing_deinit(&server_ctx[slot]); + goto cleanup; } k_mutex_unlock(&server_lock); return 0; +cleanup: + memset(&server_ctx[slot], 0, sizeof(server_ctx[slot])); + fds[slot].fd = -1; + error: if (sock >= 0) { (void)zsock_close(sock); @@ -1361,6 +1575,7 @@ int net_dhcpv4_server_stop(struct net_if *iface) fds[slot].fd = -1; (void)zsock_close(server_ctx[slot].sock); + dhcpv4_server_probing_deinit(&server_ctx[slot]); k_work_cancel_delayable_sync(&server_ctx[slot].timeout_work, &sync); memset(&server_ctx[slot], 0, sizeof(server_ctx[slot])); From e57e9eade53f08e5e74cfc1dd704cd10a57f7a28 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Mon, 12 Feb 2024 09:46:48 +0100 Subject: [PATCH 1328/1623] [nrf fromlist] net: dhcpv4_server: Improve declined addresses management Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68848 In case conflict is detected (either due to receiving Decline message or due to ICMP probe getting reply), the conflicting address becomes blocked for further use. Although the RFC is not specific about how long should the address be blocked, it make sense to implement some fallback mechanisms to reuse blocked addresses in the server, otherwise, after longer period of operation, it may run out of usable address. This commit adds a timeout for declined addresses, so that by default the address is marked back as "free" after 24 hrs (default lease time). It also implements a mechanism, which allows to re-use the oldest declined entry in case the server runs out of fresh addresses to assign. Signed-off-by: Robert Lubos --- subsys/net/lib/dhcpv4/Kconfig | 11 +++++++++ subsys/net/lib/dhcpv4/dhcpv4_server.c | 34 +++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/dhcpv4/Kconfig b/subsys/net/lib/dhcpv4/Kconfig index 8ae65344f31..c8ca410d39c 100644 --- a/subsys/net/lib/dhcpv4/Kconfig +++ b/subsys/net/lib/dhcpv4/Kconfig @@ -43,6 +43,17 @@ config NET_DHCPV4_SERVER_ADDR_LEASE_TIME The lease time determines when the IPv4 address lease expires if the client does not renew it. +config NET_DHCPV4_SERVER_ADDR_DECLINE_TIME + int "The time IPv4 addresses remains blocked after conflict detection (seconds)" + default 86400 + help + In case IPv4 address becomes blocked (either because of receiving + Decline message or due to ICMP probe detecting conflict), the address + can no longer be assigned. This timeout specifies how long the address + remains in the Declined state. + Note, that the server may try to reuse the oldest declined address in + case it runs out of free addresses to assign. + config NET_DHCPV4_SERVER_ICMP_PROBE_TIMEOUT int "Timeout for ICMP probes sent by the server (miliseconds)" default 1000 diff --git a/subsys/net/lib/dhcpv4/dhcpv4_server.c b/subsys/net/lib/dhcpv4/dhcpv4_server.c index e683fdf5f0e..fdaab75c950 100644 --- a/subsys/net/lib/dhcpv4/dhcpv4_server.c +++ b/subsys/net/lib/dhcpv4/dhcpv4_server.c @@ -33,6 +33,7 @@ LOG_MODULE_REGISTER(net_dhcpv4_server, CONFIG_NET_DHCPV4_SERVER_LOG_LEVEL); #define ADDRESS_RESERVED_TIMEOUT K_SECONDS(5) #define ADDRESS_PROBE_TIMEOUT K_MSEC(CONFIG_NET_DHCPV4_SERVER_ICMP_PROBE_TIMEOUT) +#define ADDRESS_DECLINED_TIMEOUT K_SECONDS(CONFIG_NET_DHCPV4_SERVER_ADDR_DECLINE_TIME) #if (CONFIG_NET_DHCPV4_SERVER_ICMP_PROBE_TIMEOUT > 0) #define DHCPV4_SERVER_ICMP_PROBE 1 @@ -80,7 +81,8 @@ static void dhcpv4_server_timeout_recalc(struct dhcpv4_server_ctx *ctx) struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; if (slot->state == DHCPV4_SERVER_ADDR_RESERVED || - slot->state == DHCPV4_SERVER_ADDR_ALLOCATED) { + slot->state == DHCPV4_SERVER_ADDR_ALLOCATED || + slot->state == DHCPV4_SERVER_ADDR_DECLINED) { if (sys_timepoint_cmp(slot->expiry, next) < 0) { next = slot->expiry; } @@ -738,6 +740,7 @@ static int echo_reply_handler(struct net_icmp_ctx *icmp_ctx, net_sprint_ipv4_addr(&probe_ctx->slot->addr)); probe_ctx->slot->state = DHCPV4_SERVER_ADDR_DECLINED; + probe_ctx->slot->expiry = sys_timepoint_calc(ADDRESS_DECLINED_TIMEOUT); /* Try to find next free address */ for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { @@ -933,6 +936,27 @@ static void dhcpv4_handle_discover(struct dhcpv4_server_ctx *ctx, } } + /* In case no free address slot was found, as a last resort, try to + * reuse the oldest declined entry, if present. + */ + if (selected == NULL) { + for (int i = 0; i < ARRAY_SIZE(ctx->addr_pool); i++) { + struct dhcpv4_addr_slot *slot = &ctx->addr_pool[i]; + + if (slot->state != DHCPV4_SERVER_ADDR_DECLINED) { + continue; + } + + /* Find first to expire (oldest) entry. */ + if ((selected == NULL) || + (sys_timepoint_cmp(slot->expiry, + selected->expiry) < 0)) { + selected = slot; + probe = true; + } + } + } + if (selected == NULL) { LOG_ERR("No free address found in address pool"); } else { @@ -1190,7 +1214,8 @@ static void dhcpv4_handle_decline(struct dhcpv4_server_ctx *ctx, (slot->state == DHCPV4_SERVER_ADDR_RESERVED || slot->state == DHCPV4_SERVER_ADDR_ALLOCATED)) { slot->state = DHCPV4_SERVER_ADDR_DECLINED; - slot->expiry = sys_timepoint_calc(K_FOREVER); + slot->expiry = + sys_timepoint_calc(ADDRESS_DECLINED_TIMEOUT); dhcpv4_server_timeout_recalc(ctx); break; } @@ -1280,6 +1305,11 @@ static void dhcpv4_server_timeout(struct k_work *work) slot->state = DHCPV4_SERVER_ADDR_FREE; } } + + if (slot->state == DHCPV4_SERVER_ADDR_DECLINED && + sys_timepoint_expired(slot->expiry)) { + slot->state = DHCPV4_SERVER_ADDR_FREE; + } } dhcpv4_server_timeout_recalc(ctx); From 352bf882873d9666c88d693296ce778ff1aa44ec Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Mon, 12 Feb 2024 11:06:26 +0100 Subject: [PATCH 1329/1623] [nrf fromlist] net: dhcpv4_server: Apply range limits for Kconfig options Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68848 Apply ranges to DHCPv4 server timeout Kconfig options, so that it cannot be set to a negative value by mistake. Signed-off-by: Robert Lubos --- subsys/net/lib/dhcpv4/Kconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/subsys/net/lib/dhcpv4/Kconfig b/subsys/net/lib/dhcpv4/Kconfig index c8ca410d39c..34125b6066c 100644 --- a/subsys/net/lib/dhcpv4/Kconfig +++ b/subsys/net/lib/dhcpv4/Kconfig @@ -37,6 +37,7 @@ config NET_DHCPV4_SERVER_ADDR_COUNT config NET_DHCPV4_SERVER_ADDR_LEASE_TIME int "Lease time for IPv4 addresses assigned by the server (seconds)" + range 0 4294967295 default 86400 help Lease time in seconds for IPv4 addresses assigned by the server. @@ -45,6 +46,7 @@ config NET_DHCPV4_SERVER_ADDR_LEASE_TIME config NET_DHCPV4_SERVER_ADDR_DECLINE_TIME int "The time IPv4 addresses remains blocked after conflict detection (seconds)" + range 0 4294967295 default 86400 help In case IPv4 address becomes blocked (either because of receiving @@ -56,6 +58,7 @@ config NET_DHCPV4_SERVER_ADDR_DECLINE_TIME config NET_DHCPV4_SERVER_ICMP_PROBE_TIMEOUT int "Timeout for ICMP probes sent by the server (miliseconds)" + range 0 60000 default 1000 help DHCPv4 server will probe the offered IP address (send ICMP echo From 1dae63f6d3867609aa682628a810846710f93e65 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 16 Jan 2024 16:53:53 +0200 Subject: [PATCH 1330/1623] [nrf fromtree] net: zperf: Convert TCP receiver to use socket services Use socket services API for TCP receiver. Signed-off-by: Jukka Rissanen (cherry picked from commit 07823f771049bd64809b4c8b24854a0c116cab2b) --- subsys/net/lib/zperf/Kconfig | 1 + subsys/net/lib/zperf/zperf_common.c | 1 - subsys/net/lib/zperf/zperf_internal.h | 1 - subsys/net/lib/zperf/zperf_tcp_receiver.c | 302 +++++++++++----------- 4 files changed, 157 insertions(+), 148 deletions(-) diff --git a/subsys/net/lib/zperf/Kconfig b/subsys/net/lib/zperf/Kconfig index 204144a805b..0cb637f376e 100644 --- a/subsys/net/lib/zperf/Kconfig +++ b/subsys/net/lib/zperf/Kconfig @@ -5,6 +5,7 @@ menuconfig NET_ZPERF bool "zperf shell utility" select NET_CONTEXT_RCVTIMEO if NET_NATIVE_UDP + select NET_SOCKETS_SERVICE help This option enables zperf shell utility, which allows to generate network traffic and evaluate network bandwidth. diff --git a/subsys/net/lib/zperf/zperf_common.c b/subsys/net/lib/zperf/zperf_common.c index 4bc675ed45e..3a2674dc05c 100644 --- a/subsys/net/lib/zperf/zperf_common.c +++ b/subsys/net/lib/zperf/zperf_common.c @@ -223,7 +223,6 @@ static int zperf_init(void) zperf_udp_uploader_init(); zperf_tcp_uploader_init(); zperf_udp_receiver_init(); - zperf_tcp_receiver_init(); zperf_session_init(); diff --git a/subsys/net/lib/zperf/zperf_internal.h b/subsys/net/lib/zperf/zperf_internal.h index 592424a9446..6fdb545cdd2 100644 --- a/subsys/net/lib/zperf/zperf_internal.h +++ b/subsys/net/lib/zperf/zperf_internal.h @@ -104,7 +104,6 @@ void zperf_async_work_submit(struct k_work *work); void zperf_udp_uploader_init(void); void zperf_tcp_uploader_init(void); void zperf_udp_receiver_init(void); -void zperf_tcp_receiver_init(void); void zperf_shell_init(void); diff --git a/subsys/net/lib/zperf/zperf_tcp_receiver.c b/subsys/net/lib/zperf/zperf_tcp_receiver.c index 344d34fe98c..c782124e36b 100644 --- a/subsys/net/lib/zperf/zperf_tcp_receiver.c +++ b/subsys/net/lib/zperf/zperf_tcp_receiver.c @@ -14,6 +14,7 @@ LOG_MODULE_DECLARE(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL); #include #include +#include #include #include "zperf_internal.h" @@ -23,23 +24,11 @@ LOG_MODULE_DECLARE(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL); #define NET_LOG_ENABLED 1 #include "net_private.h" -#if defined(CONFIG_NET_TC_THREAD_COOPERATIVE) -#define TCP_RECEIVER_THREAD_PRIORITY K_PRIO_COOP(8) -#else -#define TCP_RECEIVER_THREAD_PRIORITY K_PRIO_PREEMPT(8) -#endif - -#define TCP_RECEIVER_STACK_SIZE 2048 - #define SOCK_ID_IPV4_LISTEN 0 #define SOCK_ID_IPV6_LISTEN 1 #define SOCK_ID_MAX (CONFIG_NET_ZPERF_MAX_SESSIONS + 2) #define TCP_RECEIVER_BUF_SIZE 1500 -#define POLL_TIMEOUT_MS 100 - -static K_THREAD_STACK_DEFINE(tcp_receiver_stack_area, TCP_RECEIVER_STACK_SIZE); -static struct k_thread tcp_receiver_thread_data; static zperf_callback tcp_session_cb; static void *tcp_user_data; @@ -49,6 +38,14 @@ static uint16_t tcp_server_port; static struct sockaddr tcp_server_addr; static K_SEM_DEFINE(tcp_server_run, 0, 1); +static struct zsock_pollfd fds[SOCK_ID_MAX]; +static struct sockaddr sock_addr[SOCK_ID_MAX]; + +static void tcp_svc_handler(struct k_work *work); + +NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(svc_tcp, NULL, tcp_svc_handler, + SOCK_ID_MAX); + static void tcp_received(const struct sockaddr *addr, size_t datalen) { struct session *session; @@ -99,6 +96,143 @@ static void tcp_received(const struct sockaddr *addr, size_t datalen) } } +static void tcp_session_error_report(void) +{ + if (tcp_session_cb != NULL) { + tcp_session_cb(ZPERF_SESSION_ERROR, NULL, tcp_user_data); + } +} + +static int tcp_recv_data(struct net_socket_service_event *pev) +{ + static uint8_t buf[TCP_RECEIVER_BUF_SIZE]; + int i, ret = 0; + int family, sock; + struct sockaddr addr_incoming_conn; + socklen_t optlen = sizeof(int); + socklen_t addrlen = sizeof(struct sockaddr); + + if (tcp_server_stop) { + ret = -ENOENT; + goto cleanup; + } + + if ((pev->event.revents & ZSOCK_POLLERR) || + (pev->event.revents & ZSOCK_POLLNVAL)) { + (void)zsock_getsockopt(pev->event.fd, SOL_SOCKET, + SO_DOMAIN, &family, &optlen); + NET_ERR("TCP receiver IPv%d socket error", + family == AF_INET ? 4 : 6); + goto error; + } + + if (!(pev->event.revents & ZSOCK_POLLIN)) { + return 0; + } + + /* What is the index to first accepted socket */ + i = SOCK_ID_IPV6_LISTEN + 1; + + /* Check first if we need to accept a connection */ + if (fds[SOCK_ID_IPV4_LISTEN].fd == pev->event.fd || + fds[SOCK_ID_IPV6_LISTEN].fd == pev->event.fd) { + sock = zsock_accept(pev->event.fd, + &addr_incoming_conn, + &addrlen); + if (sock < 0) { + (void)zsock_getsockopt(pev->event.fd, SOL_SOCKET, + SO_DOMAIN, &family, &optlen); + NET_ERR("TCP receiver IPv%d accept error", + family == AF_INET ? 4 : 6); + goto error; + } + + for (; i < SOCK_ID_MAX; i++) { + if (fds[i].fd < 0) { + break; + } + } + + if (i == SOCK_ID_MAX) { + /* Too many connections. */ + NET_ERR("Dropping TCP connection, reached maximum limit."); + zsock_close(sock); + } else { + fds[i].fd = sock; + fds[i].events = ZSOCK_POLLIN; + memcpy(&sock_addr[i], &addr_incoming_conn, addrlen); + + (void)net_socket_service_register(&svc_tcp, fds, + ARRAY_SIZE(fds), + NULL); + } + + } else { + ret = zsock_recv(pev->event.fd, buf, sizeof(buf), 0); + if (ret < 0) { + (void)zsock_getsockopt(pev->event.fd, SOL_SOCKET, + SO_DOMAIN, &family, &optlen); + NET_ERR("recv failed on IPv%d socket (%d)", + family == AF_INET ? 4 : 6, + errno); + tcp_session_error_report(); + /* This will close the zperf session */ + ret = 0; + } + + for (; i < SOCK_ID_MAX; i++) { + if (fds[i].fd == pev->event.fd) { + break; + } + } + + if (i == SOCK_ID_MAX) { + NET_ERR("Descriptor %d not found.", pev->event.fd); + } else { + tcp_received(&sock_addr[i], ret); + if (ret == 0) { + zsock_close(fds[i].fd); + fds[i].fd = -1; + memset(&sock_addr[i], 0, sizeof(struct sockaddr)); + + (void)net_socket_service_register(&svc_tcp, fds, + ARRAY_SIZE(fds), + NULL); + } + } + } + + return ret; + +error: + tcp_session_error_report(); + +cleanup: + for (i = 0; i < ARRAY_SIZE(fds); i++) { + if (fds[i].fd >= 0) { + zsock_close(fds[i].fd); + fds[i].fd = -1; + memset(&sock_addr[i], 0, sizeof(struct sockaddr)); + } + } + + (void)net_socket_service_unregister(&svc_tcp); + + return ret; +} + +static void tcp_svc_handler(struct k_work *work) +{ + struct net_socket_service_event *pev = + CONTAINER_OF(work, struct net_socket_service_event, work); + int ret; + + ret = tcp_recv_data(pev); + if (ret < 0) { + (void)net_socket_service_unregister(&svc_tcp); + } +} + static int tcp_bind_listen_connection(struct zsock_pollfd *pollfd, struct sockaddr *address) { @@ -114,14 +248,14 @@ static int tcp_bind_listen_connection(struct zsock_pollfd *pollfd, ret = zsock_bind(pollfd->fd, address, sizeof(*address)); if (ret < 0) { NET_ERR("Cannot bind IPv%d TCP port %d (%d)", - (address->sa_family == AF_INET ? 4 : 6), port, errno); + address->sa_family == AF_INET ? 4 : 6, port, errno); goto out; } ret = zsock_listen(pollfd->fd, 1); if (ret < 0) { NET_ERR("Cannot listen IPv%d TCP (%d)", - (address->sa_family == AF_INET ? 4 : 6), errno); + address->sa_family == AF_INET ? 4 : 6, errno); goto out; } @@ -131,18 +265,8 @@ static int tcp_bind_listen_connection(struct zsock_pollfd *pollfd, return ret; } -static void tcp_session_error_report(void) +static void zperf_tcp_receiver_init(void) { - if (tcp_session_cb != NULL) { - tcp_session_cb(ZPERF_SESSION_ERROR, NULL, tcp_user_data); - } -} - -static void tcp_server_session(void) -{ - static uint8_t buf[TCP_RECEIVER_BUF_SIZE]; - static struct zsock_pollfd fds[SOCK_ID_MAX]; - static struct sockaddr sock_addr[SOCK_ID_MAX]; int ret; for (int i = 0; i < ARRAY_SIZE(fds); i++) { @@ -243,130 +367,14 @@ static void tcp_server_session(void) NET_INFO("Listening on port %d", tcp_server_port); - while (true) { - ret = zsock_poll(fds, ARRAY_SIZE(fds), POLL_TIMEOUT_MS); - if (ret < 0) { - NET_ERR("TCP receiver poll error (%d)", errno); - goto error; - } - - if (tcp_server_stop) { - goto cleanup; - } - - if (ret == 0) { - continue; - } - - for (int i = 0; i < ARRAY_SIZE(fds); i++) { - if ((fds[i].revents & ZSOCK_POLLERR) || - (fds[i].revents & ZSOCK_POLLNVAL)) { - NET_ERR("TCP receiver IPv%d socket error", - (sock_addr[i].sa_family == AF_INET - ? 4 : 6)); - goto error; - } - - if (!(fds[i].revents & ZSOCK_POLLIN)) { - continue; - } - - if ((i >= SOCK_ID_IPV4_LISTEN) && (i <= SOCK_ID_IPV6_LISTEN)) { - int j = SOCK_ID_IPV6_LISTEN + 1; - struct sockaddr addr_incoming_conn; - socklen_t addrlen = sizeof(struct sockaddr); - int sock = zsock_accept(fds[i].fd, - &addr_incoming_conn, - &addrlen); - - if (sock < 0) { - NET_ERR("TCP receiver IPv%d accept error", - (sock_addr[i].sa_family == AF_INET - ? 4 : 6)); - goto error; - } - - for (; j < SOCK_ID_MAX; j++) { - if (fds[j].fd < 0) { - break; - } - } - - if (j == SOCK_ID_MAX) { - /* Too many connections. */ - NET_ERR("Dropping TCP connection, reached maximum limit."); - zsock_close(sock); - } else { - fds[j].fd = sock; - fds[j].events = ZSOCK_POLLIN; - memcpy(&sock_addr[j], - &addr_incoming_conn, - addrlen); - } - } else if ((i > SOCK_ID_IPV6_LISTEN) && (i < SOCK_ID_MAX)) { - ret = zsock_recv(fds[i].fd, buf, sizeof(buf), 0); - if (ret < 0) { - NET_ERR("recv failed on IPv%d socket (%d)", - (sock_addr[i].sa_family == AF_INET - ? 4 : 6), - errno); - tcp_session_error_report(); - /* This will close the zperf session */ - ret = 0; - } - - tcp_received(&sock_addr[i], ret); - - if (ret == 0) { - zsock_close(fds[i].fd); - fds[i].fd = -1; - memset(&sock_addr[i], 0, - sizeof(struct sockaddr)); - } - } else { - goto error; - } - } + ret = net_socket_service_register(&svc_tcp, fds, + ARRAY_SIZE(fds), NULL); + if (ret < 0) { + LOG_ERR("Cannot register socket service handler (%d)", ret); } error: - tcp_session_error_report(); - -cleanup: - for (int i = 0; i < ARRAY_SIZE(fds); i++) { - if (fds[i].fd >= 0) { - zsock_close(fds[i].fd); - memset(&sock_addr[i], 0, sizeof(struct sockaddr)); - } - } -} - -void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3) -{ - ARG_UNUSED(ptr1); - ARG_UNUSED(ptr2); - ARG_UNUSED(ptr3); - - while (true) { - k_sem_take(&tcp_server_run, K_FOREVER); - - tcp_server_session(); - - tcp_server_running = false; - } -} - -void zperf_tcp_receiver_init(void) -{ - k_thread_create(&tcp_receiver_thread_data, - tcp_receiver_stack_area, - K_THREAD_STACK_SIZEOF(tcp_receiver_stack_area), - tcp_receiver_thread, - NULL, NULL, NULL, - TCP_RECEIVER_THREAD_PRIORITY, - IS_ENABLED(CONFIG_USERSPACE) ? K_USER | - K_INHERIT_PERMS : 0, - K_NO_WAIT); + return; } int zperf_tcp_download(const struct zperf_download_params *param, @@ -387,6 +395,8 @@ int zperf_tcp_download(const struct zperf_download_params *param, tcp_server_stop = false; memcpy(&tcp_server_addr, ¶m->addr, sizeof(struct sockaddr)); + zperf_tcp_receiver_init(); + k_sem_give(&tcp_server_run); return 0; From 2d0354b2a4ad8221a2445dd130a64b5bdd90995c Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 17 Jan 2024 14:57:43 +0200 Subject: [PATCH 1331/1623] [nrf fromtree] net: zperf: Convert UDP receiver to use socket services Use socket services API for UDP receiver. Signed-off-by: Jukka Rissanen (cherry picked from commit 1e8cbd5d43fc108ec4be8eebe653e62f842e0def) --- subsys/net/lib/zperf/zperf_common.c | 1 - subsys/net/lib/zperf/zperf_internal.h | 1 - subsys/net/lib/zperf/zperf_udp_receiver.c | 177 +++++++++++----------- 3 files changed, 86 insertions(+), 93 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_common.c b/subsys/net/lib/zperf/zperf_common.c index 3a2674dc05c..89224b691ca 100644 --- a/subsys/net/lib/zperf/zperf_common.c +++ b/subsys/net/lib/zperf/zperf_common.c @@ -222,7 +222,6 @@ static int zperf_init(void) zperf_udp_uploader_init(); zperf_tcp_uploader_init(); - zperf_udp_receiver_init(); zperf_session_init(); diff --git a/subsys/net/lib/zperf/zperf_internal.h b/subsys/net/lib/zperf/zperf_internal.h index 6fdb545cdd2..b8cdb84cbbf 100644 --- a/subsys/net/lib/zperf/zperf_internal.h +++ b/subsys/net/lib/zperf/zperf_internal.h @@ -103,7 +103,6 @@ uint32_t zperf_packet_duration(uint32_t packet_size, uint32_t rate_in_kbps); void zperf_async_work_submit(struct k_work *work); void zperf_udp_uploader_init(void); void zperf_tcp_uploader_init(void); -void zperf_udp_receiver_init(void); void zperf_shell_init(void); diff --git a/subsys/net/lib/zperf/zperf_udp_receiver.c b/subsys/net/lib/zperf/zperf_udp_receiver.c index 75a0b35b234..ba44590c621 100644 --- a/subsys/net/lib/zperf/zperf_udp_receiver.c +++ b/subsys/net/lib/zperf/zperf_udp_receiver.c @@ -13,6 +13,7 @@ LOG_MODULE_DECLARE(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL); #include #include +#include #include #include "zperf_internal.h" @@ -25,14 +26,6 @@ LOG_MODULE_DECLARE(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL); static struct sockaddr_in6 *in6_addr_my; static struct sockaddr_in *in4_addr_my; -#if defined(CONFIG_NET_TC_THREAD_COOPERATIVE) -#define UDP_RECEIVER_THREAD_PRIORITY K_PRIO_COOP(8) -#else -#define UDP_RECEIVER_THREAD_PRIORITY K_PRIO_PREEMPT(8) -#endif - -#define UDP_RECEIVER_STACK_SIZE 2048 - #define SOCK_ID_IPV4 0 #define SOCK_ID_IPV6 1 #define SOCK_ID_MAX 2 @@ -40,9 +33,6 @@ static struct sockaddr_in *in4_addr_my; #define UDP_RECEIVER_BUF_SIZE 1500 #define POLL_TIMEOUT_MS 100 -static K_THREAD_STACK_DEFINE(udp_receiver_stack_area, UDP_RECEIVER_STACK_SIZE); -static struct k_thread udp_receiver_thread_data; - static zperf_callback udp_session_cb; static void *udp_user_data; static bool udp_server_running; @@ -51,6 +41,13 @@ static uint16_t udp_server_port; static struct sockaddr udp_server_addr; static K_SEM_DEFINE(udp_server_run, 0, 1); +struct zsock_pollfd fds[SOCK_ID_MAX] = { 0 }; + +static void udp_svc_handler(struct k_work *work); + +NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC(svc_udp, NULL, udp_svc_handler, + SOCK_ID_MAX); + static inline void build_reply(struct zperf_udp_datagram *hdr, struct zperf_server_hdr *stat, uint8_t *buf) @@ -230,10 +227,79 @@ static void udp_received(int sock, const struct sockaddr *addr, uint8_t *data, } } -static void udp_server_session(void) +static int udp_recv_data(struct net_socket_service_event *pev) { static uint8_t buf[UDP_RECEIVER_BUF_SIZE]; - struct zsock_pollfd fds[SOCK_ID_MAX] = { 0 }; + int i, ret = 0; + int family; + struct sockaddr addr; + socklen_t optlen = sizeof(int); + socklen_t addrlen = sizeof(addr); + + if (udp_server_stop) { + ret = -ENOENT; + goto cleanup; + } + + if ((pev->event.revents & ZSOCK_POLLERR) || + (pev->event.revents & ZSOCK_POLLNVAL)) { + (void)zsock_getsockopt(pev->event.fd, SOL_SOCKET, + SO_DOMAIN, &family, &optlen); + NET_ERR("UDP receiver IPv%d socket error", + family == AF_INET ? 4 : 6); + goto error; + } + + if (!(pev->event.revents & ZSOCK_POLLIN)) { + return 0; + } + + ret = zsock_recvfrom(pev->event.fd, buf, sizeof(buf), 0, + &addr, &addrlen); + if (ret < 0) { + (void)zsock_getsockopt(pev->event.fd, SOL_SOCKET, + SO_DOMAIN, &family, &optlen); + NET_ERR("recv failed on IPv%d socket (%d)", + family == AF_INET ? 4 : 6, errno); + goto error; + } + + udp_received(pev->event.fd, &addr, buf, ret); + + return ret; + +error: + if (udp_session_cb != NULL) { + udp_session_cb(ZPERF_SESSION_ERROR, NULL, udp_user_data); + } + +cleanup: + for (i = 0; i < ARRAY_SIZE(fds); i++) { + if (fds[i].fd >= 0) { + zsock_close(fds[i].fd); + fds[i].fd = -1; + } + } + + (void)net_socket_service_unregister(&svc_udp); + + return ret; +} + +static void udp_svc_handler(struct k_work *work) +{ + struct net_socket_service_event *pev = + CONTAINER_OF(work, struct net_socket_service_event, work); + int ret; + + ret = udp_recv_data(pev); + if (ret < 0) { + (void)net_socket_service_unregister(&svc_udp); + } +} + +static void zperf_udp_receiver_init(void) +{ int ret; for (int i = 0; i < ARRAY_SIZE(fds); i++) { @@ -341,87 +407,14 @@ static void udp_server_session(void) NET_INFO("Listening on port %d", udp_server_port); - while (true) { - ret = zsock_poll(fds, ARRAY_SIZE(fds), POLL_TIMEOUT_MS); - if (ret < 0) { - NET_ERR("UDP receiver poll error (%d)", errno); - goto error; - } - - if (udp_server_stop) { - goto cleanup; - } - - if (ret == 0) { - continue; - } - - for (int i = 0; i < ARRAY_SIZE(fds); i++) { - struct sockaddr addr; - socklen_t addrlen = sizeof(addr); - - if ((fds[i].revents & ZSOCK_POLLERR) || - (fds[i].revents & ZSOCK_POLLNVAL)) { - NET_ERR("UDP receiver IPv%d socket error", - (i == SOCK_ID_IPV4) ? 4 : 6); - goto error; - } - - if (!(fds[i].revents & ZSOCK_POLLIN)) { - continue; - } - - ret = zsock_recvfrom(fds[i].fd, buf, sizeof(buf), 0, - &addr, &addrlen); - if (ret < 0) { - NET_ERR("recv failed on IPv%d socket (%d)", - (i == SOCK_ID_IPV4) ? 4 : 6, errno); - goto error; - } - - udp_received(fds[i].fd, &addr, buf, ret); - } + ret = net_socket_service_register(&svc_udp, fds, + ARRAY_SIZE(fds), NULL); + if (ret < 0) { + LOG_ERR("Cannot register socket service handler (%d)", ret); } error: - if (udp_session_cb != NULL) { - udp_session_cb(ZPERF_SESSION_ERROR, NULL, udp_user_data); - } - -cleanup: - for (int i = 0; i < ARRAY_SIZE(fds); i++) { - if (fds[i].fd >= 0) { - zsock_close(fds[i].fd); - } - } -} - -static void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3) -{ - ARG_UNUSED(ptr1); - ARG_UNUSED(ptr2); - ARG_UNUSED(ptr3); - - while (true) { - k_sem_take(&udp_server_run, K_FOREVER); - - udp_server_session(); - - udp_server_running = false; - } -} - -void zperf_udp_receiver_init(void) -{ - k_thread_create(&udp_receiver_thread_data, - udp_receiver_stack_area, - K_THREAD_STACK_SIZEOF(udp_receiver_stack_area), - udp_receiver_thread, - NULL, NULL, NULL, - UDP_RECEIVER_THREAD_PRIORITY, - IS_ENABLED(CONFIG_USERSPACE) ? K_USER | - K_INHERIT_PERMS : 0, - K_NO_WAIT); + return; } int zperf_udp_download(const struct zperf_download_params *param, @@ -442,6 +435,8 @@ int zperf_udp_download(const struct zperf_download_params *param, udp_server_stop = false; memcpy(&udp_server_addr, ¶m->addr, sizeof(struct sockaddr)); + zperf_udp_receiver_init(); + k_sem_give(&udp_server_run); return 0; From f2bbad75158a76dbc497d2b2cbbc48771f678818 Mon Sep 17 00:00:00 2001 From: Fengming Ye Date: Sun, 21 Jan 2024 16:49:20 +0900 Subject: [PATCH 1332/1623] [nrf fromtree] net: zperf: fix the calculation ratio between mbps, kbps and bps The ratio between mbps and kbps, kbps and bps should be 1000, instead of 1024, as common sense. The wrong ratio will decrease the Zperf throughput result. Signed-off-by: Fengming Ye (cherry picked from commit f61a0cb1fa5de524ade69e241d9737173b49d947) --- subsys/net/lib/zperf/zperf_shell.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_shell.c b/subsys/net/lib/zperf/zperf_shell.c index 444cf125c31..2c30c1e33e3 100644 --- a/subsys/net/lib/zperf/zperf_shell.c +++ b/subsys/net/lib/zperf/zperf_shell.c @@ -76,9 +76,9 @@ static struct in_addr shell_ipv4; const uint32_t TIME_US[] = { 60 * 1000 * 1000, 1000 * 1000, 1000, 0 }; const char *TIME_US_UNIT[] = { "m", "s", "ms", "us" }; -const uint32_t KBPS[] = { 1024, 0 }; +const uint32_t KBPS[] = { 1000, 0 }; const char *KBPS_UNIT[] = { "Mbps", "Kbps" }; -const uint32_t K[] = { 1024 * 1024, 1024, 0 }; +const uint32_t K[] = { 1000 * 1000, 1000, 0 }; const char *K_UNIT[] = { "M", "K", "" }; static void print_number(const struct shell *sh, uint32_t value, @@ -308,7 +308,7 @@ static void udp_session_cb(enum zperf_status status, rate_in_kbps = (uint32_t) (((uint64_t)result->total_len * 8ULL * (uint64_t)USEC_PER_SEC) / - ((uint64_t)result->time_in_us * 1024ULL)); + ((uint64_t)result->time_in_us * 1000ULL)); } else { rate_in_kbps = 0U; } @@ -408,7 +408,7 @@ static void shell_udp_upload_print_stats(const struct shell *sh, rate_in_kbps = (uint32_t) (((uint64_t)results->total_len * (uint64_t)8 * (uint64_t)USEC_PER_SEC) / - ((uint64_t)results->time_in_us * 1024U)); + ((uint64_t)results->time_in_us * 1000U)); } else { rate_in_kbps = 0U; } @@ -418,7 +418,7 @@ static void shell_udp_upload_print_stats(const struct shell *sh, (((uint64_t)results->nb_packets_sent * (uint64_t)results->packet_size * (uint64_t)8 * (uint64_t)USEC_PER_SEC) / - ((uint64_t)results->client_time_in_us * 1024U)); + ((uint64_t)results->client_time_in_us * 1000U)); } else { client_rate_in_kbps = 0U; } @@ -474,7 +474,7 @@ static void shell_tcp_upload_print_stats(const struct shell *sh, (((uint64_t)results->nb_packets_sent * (uint64_t)results->packet_size * (uint64_t)8 * (uint64_t)USEC_PER_SEC) / - ((uint64_t)results->client_time_in_us * 1024U)); + ((uint64_t)results->client_time_in_us * 1000U)); } else { client_rate_in_kbps = 0U; } @@ -884,7 +884,7 @@ static int shell_cmd_upload(const struct shell *sh, size_t argc, if (argc > 5) { param.rate_kbps = - (parse_number(argv[start + 5], K, K_UNIT) + 1023) / 1024; + (parse_number(argv[start + 5], K, K_UNIT) + 999) / 1000; } else { param.rate_kbps = 10U; } @@ -1035,7 +1035,7 @@ static int shell_cmd_upload2(const struct shell *sh, size_t argc, if (argc > 4) { param.rate_kbps = - (parse_number(argv[start + 4], K, K_UNIT) + 1023) / 1024; + (parse_number(argv[start + 4], K, K_UNIT) + 999) / 1000; } else { param.rate_kbps = 10U; } @@ -1108,7 +1108,7 @@ static void tcp_session_cb(enum zperf_status status, rate_in_kbps = (uint32_t) (((uint64_t)result->total_len * 8ULL * (uint64_t)USEC_PER_SEC) / - ((uint64_t)result->time_in_us * 1024ULL)); + ((uint64_t)result->time_in_us * 1000ULL)); } else { rate_in_kbps = 0U; } From 1ff0c29f0c3d19cb9bc52a15bc9ab8b4ee19de81 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 31 Jan 2024 15:33:27 +0100 Subject: [PATCH 1333/1623] [nrf fromtree] net: zperf: Fix UDP receiver start/stop operation This commit fixes restarting of UDP receiver service, along with some other minor cleanups: * The core issue was udp_server_running flag not being cleared when service was stopped. Fix this by introducing udp_receiver_cleanup() which does all of the required cleanups when receiver service is stopped. The function is called either when the application stopped the service with zperf_udp_download_stop(), or when the service was stopped due to error. * net_socket_service_unregister() was not called on zperf_udp_download_stop(), but only from the service callback - that would not work in case there's no active communication. * at the same time, net_socket_service_unregister() would be called from the service callback in case of errors. Fix this, by making udp_recv_data() only return an error, and let the service callback to do the cleanup. * Remove no longer used udp_server_run semaphore * Remove udp_server_stop - with socket services it seems no longer needed. * zperf_udp_receiver_init() now returns an error, so that we don't mark the service as running in case of socket/services error. Signed-off-by: Robert Lubos (cherry picked from commit 139bc4e87e7c219fc9dc9b04a34a8cea13bb164e) --- subsys/net/lib/zperf/zperf_udp_receiver.c | 72 ++++++++++++++--------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_udp_receiver.c b/subsys/net/lib/zperf/zperf_udp_receiver.c index ba44590c621..64f489ed8dc 100644 --- a/subsys/net/lib/zperf/zperf_udp_receiver.c +++ b/subsys/net/lib/zperf/zperf_udp_receiver.c @@ -36,10 +36,8 @@ static struct sockaddr_in *in4_addr_my; static zperf_callback udp_session_cb; static void *udp_user_data; static bool udp_server_running; -static bool udp_server_stop; static uint16_t udp_server_port; static struct sockaddr udp_server_addr; -static K_SEM_DEFINE(udp_server_run, 0, 1); struct zsock_pollfd fds[SOCK_ID_MAX] = { 0 }; @@ -227,26 +225,45 @@ static void udp_received(int sock, const struct sockaddr *addr, uint8_t *data, } } +static void udp_receiver_cleanup(void) +{ + int i; + + (void)net_socket_service_unregister(&svc_udp); + + for (i = 0; i < ARRAY_SIZE(fds); i++) { + if (fds[i].fd >= 0) { + zsock_close(fds[i].fd); + fds[i].fd = -1; + } + } + + udp_server_running = false; + udp_session_cb = NULL; +} + static int udp_recv_data(struct net_socket_service_event *pev) { static uint8_t buf[UDP_RECEIVER_BUF_SIZE]; - int i, ret = 0; - int family; + int ret = 0; + int family, sock_error; struct sockaddr addr; socklen_t optlen = sizeof(int); socklen_t addrlen = sizeof(addr); - if (udp_server_stop) { - ret = -ENOENT; - goto cleanup; + if (!udp_server_running) { + return -ENOENT; } if ((pev->event.revents & ZSOCK_POLLERR) || (pev->event.revents & ZSOCK_POLLNVAL)) { (void)zsock_getsockopt(pev->event.fd, SOL_SOCKET, SO_DOMAIN, &family, &optlen); - NET_ERR("UDP receiver IPv%d socket error", - family == AF_INET ? 4 : 6); + (void)zsock_getsockopt(pev->event.fd, SOL_SOCKET, + SO_ERROR, &sock_error, &optlen); + NET_ERR("UDP receiver IPv%d socket error (%d)", + family == AF_INET ? 4 : 6, sock_error); + ret = -sock_error; goto error; } @@ -257,10 +274,11 @@ static int udp_recv_data(struct net_socket_service_event *pev) ret = zsock_recvfrom(pev->event.fd, buf, sizeof(buf), 0, &addr, &addrlen); if (ret < 0) { + ret = -errno; (void)zsock_getsockopt(pev->event.fd, SOL_SOCKET, SO_DOMAIN, &family, &optlen); NET_ERR("recv failed on IPv%d socket (%d)", - family == AF_INET ? 4 : 6, errno); + family == AF_INET ? 4 : 6, -ret); goto error; } @@ -273,16 +291,6 @@ static int udp_recv_data(struct net_socket_service_event *pev) udp_session_cb(ZPERF_SESSION_ERROR, NULL, udp_user_data); } -cleanup: - for (i = 0; i < ARRAY_SIZE(fds); i++) { - if (fds[i].fd >= 0) { - zsock_close(fds[i].fd); - fds[i].fd = -1; - } - } - - (void)net_socket_service_unregister(&svc_udp); - return ret; } @@ -294,11 +302,11 @@ static void udp_svc_handler(struct k_work *work) ret = udp_recv_data(pev); if (ret < 0) { - (void)net_socket_service_unregister(&svc_udp); + udp_receiver_cleanup(); } } -static void zperf_udp_receiver_init(void) +static int zperf_udp_receiver_init(void) { int ret; @@ -314,6 +322,7 @@ static void zperf_udp_receiver_init(void) fds[SOCK_ID_IPV4].fd = zsock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (fds[SOCK_ID_IPV4].fd < 0) { + ret = -errno; NET_ERR("Cannot create IPv4 network socket."); goto error; } @@ -362,6 +371,7 @@ static void zperf_udp_receiver_init(void) fds[SOCK_ID_IPV6].fd = zsock_socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); if (fds[SOCK_ID_IPV6].fd < 0) { + ret = -errno; NET_ERR("Cannot create IPv4 network socket."); goto error; } @@ -414,12 +424,15 @@ static void zperf_udp_receiver_init(void) } error: - return; + + return ret; } int zperf_udp_download(const struct zperf_download_params *param, zperf_callback callback, void *user_data) { + int ret; + if (param == NULL || callback == NULL) { return -EINVAL; } @@ -431,13 +444,15 @@ int zperf_udp_download(const struct zperf_download_params *param, udp_session_cb = callback; udp_user_data = user_data; udp_server_port = param->port; - udp_server_running = true; - udp_server_stop = false; memcpy(&udp_server_addr, ¶m->addr, sizeof(struct sockaddr)); - zperf_udp_receiver_init(); + ret = zperf_udp_receiver_init(); + if (ret < 0) { + udp_receiver_cleanup(); + return ret; + } - k_sem_give(&udp_server_run); + udp_server_running = true; return 0; } @@ -448,8 +463,7 @@ int zperf_udp_download_stop(void) return -EALREADY; } - udp_server_stop = true; - udp_session_cb = NULL; + udp_receiver_cleanup(); return 0; } From 6e23a9d89a2e80bbb5618715e99abf76d602ae9e Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 31 Jan 2024 15:58:20 +0100 Subject: [PATCH 1334/1623] [nrf fromtree] net: zperf: Fix TCP receiver start/stop operation The issues found for UDP receiver were also identified for TCP receiver, this commit applies practically the same set of changes as in case of UDP. Signed-off-by: Robert Lubos (cherry picked from commit 4ce03520264d7bd135eb5eccf4fabe060e78e9ae) --- subsys/net/lib/zperf/zperf_tcp_receiver.c | 73 +++++++++++++---------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_tcp_receiver.c b/subsys/net/lib/zperf/zperf_tcp_receiver.c index c782124e36b..09624dd07b7 100644 --- a/subsys/net/lib/zperf/zperf_tcp_receiver.c +++ b/subsys/net/lib/zperf/zperf_tcp_receiver.c @@ -33,10 +33,8 @@ LOG_MODULE_DECLARE(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL); static zperf_callback tcp_session_cb; static void *tcp_user_data; static bool tcp_server_running; -static bool tcp_server_stop; static uint16_t tcp_server_port; static struct sockaddr tcp_server_addr; -static K_SEM_DEFINE(tcp_server_run, 0, 1); static struct zsock_pollfd fds[SOCK_ID_MAX]; static struct sockaddr sock_addr[SOCK_ID_MAX]; @@ -103,26 +101,46 @@ static void tcp_session_error_report(void) } } +static void tcp_receiver_cleanup(void) +{ + int i; + + (void)net_socket_service_unregister(&svc_tcp); + + for (i = 0; i < ARRAY_SIZE(fds); i++) { + if (fds[i].fd >= 0) { + zsock_close(fds[i].fd); + fds[i].fd = -1; + memset(&sock_addr[i], 0, sizeof(struct sockaddr)); + } + } + + tcp_server_running = false; + tcp_session_cb = NULL; +} + static int tcp_recv_data(struct net_socket_service_event *pev) { static uint8_t buf[TCP_RECEIVER_BUF_SIZE]; int i, ret = 0; - int family, sock; + int family, sock, sock_error; struct sockaddr addr_incoming_conn; socklen_t optlen = sizeof(int); socklen_t addrlen = sizeof(struct sockaddr); - if (tcp_server_stop) { - ret = -ENOENT; - goto cleanup; + if (!tcp_server_running) { + return -ENOENT; } if ((pev->event.revents & ZSOCK_POLLERR) || (pev->event.revents & ZSOCK_POLLNVAL)) { (void)zsock_getsockopt(pev->event.fd, SOL_SOCKET, SO_DOMAIN, &family, &optlen); - NET_ERR("TCP receiver IPv%d socket error", - family == AF_INET ? 4 : 6); + (void)zsock_getsockopt(pev->event.fd, SOL_SOCKET, + SO_ERROR, &sock_error, &optlen); + NET_ERR("TCP receiver IPv%d socket error (%d)", + family == AF_INET ? 4 : 6, sock_error); + ret = -sock_error; goto error; } @@ -140,10 +158,11 @@ static int tcp_recv_data(struct net_socket_service_event *pev) &addr_incoming_conn, &addrlen); if (sock < 0) { + ret = -errno; (void)zsock_getsockopt(pev->event.fd, SOL_SOCKET, SO_DOMAIN, &family, &optlen); - NET_ERR("TCP receiver IPv%d accept error", - family == AF_INET ? 4 : 6); + NET_ERR("TCP receiver IPv%d accept error (%d)", + family == AF_INET ? 4 : 6, ret); goto error; } @@ -207,17 +226,6 @@ static int tcp_recv_data(struct net_socket_service_event *pev) error: tcp_session_error_report(); -cleanup: - for (i = 0; i < ARRAY_SIZE(fds); i++) { - if (fds[i].fd >= 0) { - zsock_close(fds[i].fd); - fds[i].fd = -1; - memset(&sock_addr[i], 0, sizeof(struct sockaddr)); - } - } - - (void)net_socket_service_unregister(&svc_tcp); - return ret; } @@ -229,7 +237,7 @@ static void tcp_svc_handler(struct k_work *work) ret = tcp_recv_data(pev); if (ret < 0) { - (void)net_socket_service_unregister(&svc_tcp); + tcp_receiver_cleanup(); } } @@ -265,7 +273,7 @@ static int tcp_bind_listen_connection(struct zsock_pollfd *pollfd, return ret; } -static void zperf_tcp_receiver_init(void) +static int zperf_tcp_receiver_init(void) { int ret; @@ -280,6 +288,7 @@ static void zperf_tcp_receiver_init(void) fds[SOCK_ID_IPV4_LISTEN].fd = zsock_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fds[SOCK_ID_IPV4_LISTEN].fd < 0) { + ret = -errno; NET_ERR("Cannot create IPv4 network socket."); goto error; } @@ -325,6 +334,7 @@ static void zperf_tcp_receiver_init(void) fds[SOCK_ID_IPV6_LISTEN].fd = zsock_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); if (fds[SOCK_ID_IPV6_LISTEN].fd < 0) { + ret = -errno; NET_ERR("Cannot create IPv6 network socket."); goto error; } @@ -374,12 +384,14 @@ static void zperf_tcp_receiver_init(void) } error: - return; + return ret; } int zperf_tcp_download(const struct zperf_download_params *param, zperf_callback callback, void *user_data) { + int ret; + if (param == NULL || callback == NULL) { return -EINVAL; } @@ -391,13 +403,15 @@ int zperf_tcp_download(const struct zperf_download_params *param, tcp_session_cb = callback; tcp_user_data = user_data; tcp_server_port = param->port; - tcp_server_running = true; - tcp_server_stop = false; memcpy(&tcp_server_addr, ¶m->addr, sizeof(struct sockaddr)); - zperf_tcp_receiver_init(); + ret = zperf_tcp_receiver_init(); + if (ret < 0) { + tcp_receiver_cleanup(); + return ret; + } - k_sem_give(&tcp_server_run); + tcp_server_running = true; return 0; } @@ -408,8 +422,7 @@ int zperf_tcp_download_stop(void) return -EALREADY; } - tcp_server_stop = true; - tcp_session_cb = NULL; + tcp_receiver_cleanup(); return 0; } From aca817354edd91b57c7cc1cd9362d7d63ea3b5be Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 31 Jan 2024 16:17:45 +0100 Subject: [PATCH 1335/1623] [nrf fromtree] net: zperf: Fix session leak In case zperf session was aborted by the user (by for instance stopping it from shell), or practically in case of any other communication-related error, the zperf session could end up in a state other than NULL or COMPLETED, with no way to recover. This made the session no longer usable and eventually could lead to zperf being not able to start a new session anymore. Fix this by introducing zperf_session_reset() function, which resets the session state back to defaults. The function is called when the zperf receiver service is stopped. Signed-off-by: Robert Lubos (cherry picked from commit 68bc981c523d085f5a705cfae63b95fc6b5015ca) --- subsys/net/lib/zperf/zperf_session.c | 23 ++++++++++++++++++----- subsys/net/lib/zperf/zperf_session.h | 2 ++ subsys/net/lib/zperf/zperf_tcp_receiver.c | 2 ++ subsys/net/lib/zperf/zperf_udp_receiver.c | 2 ++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_session.c b/subsys/net/lib/zperf/zperf_session.c index 3b72367e179..6fff4abf9cc 100644 --- a/subsys/net/lib/zperf/zperf_session.c +++ b/subsys/net/lib/zperf/zperf_session.c @@ -102,14 +102,27 @@ void zperf_reset_session_stats(struct session *session) session->last_transit_time = 0; } -void zperf_session_init(void) +void zperf_session_reset(enum session_proto proto) { int i, j; + if (proto >= SESSION_PROTO_END) { + return; + } + + i = (int)proto; + + for (j = 0; j < SESSION_MAX; j++) { + sessions[i][j].state = STATE_NULL; + zperf_reset_session_stats(&(sessions[i][j])); + } +} + +void zperf_session_init(void) +{ + int i; + for (i = 0; i < SESSION_PROTO_END; i++) { - for (j = 0; j < SESSION_MAX; j++) { - sessions[i][j].state = STATE_NULL; - zperf_reset_session_stats(&(sessions[i][j])); - } + zperf_session_reset(i); } } diff --git a/subsys/net/lib/zperf/zperf_session.h b/subsys/net/lib/zperf/zperf_session.h index ea28dec2c60..f01bc66b71a 100644 --- a/subsys/net/lib/zperf/zperf_session.h +++ b/subsys/net/lib/zperf/zperf_session.h @@ -58,5 +58,7 @@ struct session *get_session(const struct sockaddr *addr, enum session_proto proto); void zperf_session_init(void); void zperf_reset_session_stats(struct session *session); +/* Reset all sessions for a given protocol. */ +void zperf_session_reset(enum session_proto proto); #endif /* __ZPERF_SESSION_H */ diff --git a/subsys/net/lib/zperf/zperf_tcp_receiver.c b/subsys/net/lib/zperf/zperf_tcp_receiver.c index 09624dd07b7..3efd3ff630b 100644 --- a/subsys/net/lib/zperf/zperf_tcp_receiver.c +++ b/subsys/net/lib/zperf/zperf_tcp_receiver.c @@ -117,6 +117,8 @@ static void tcp_receiver_cleanup(void) tcp_server_running = false; tcp_session_cb = NULL; + + zperf_session_reset(SESSION_TCP); } static int tcp_recv_data(struct net_socket_service_event *pev) diff --git a/subsys/net/lib/zperf/zperf_udp_receiver.c b/subsys/net/lib/zperf/zperf_udp_receiver.c index 64f489ed8dc..ae1ac063300 100644 --- a/subsys/net/lib/zperf/zperf_udp_receiver.c +++ b/subsys/net/lib/zperf/zperf_udp_receiver.c @@ -240,6 +240,8 @@ static void udp_receiver_cleanup(void) udp_server_running = false; udp_session_cb = NULL; + + zperf_session_reset(SESSION_UDP); } static int udp_recv_data(struct net_socket_service_event *pev) From ff5ebf0f5b8d641a893392d6dc949e6a2ec193e6 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Thu, 7 Dec 2023 18:26:01 +0100 Subject: [PATCH 1336/1623] [nrf fromtree] manifest: TF-M v2.0.0 update Update TF-M to version 2.0.0 including MbedTLS to v3.5.0 TF-M-Tests to v2.0.0 PSA-Arch_Tests to v23.06_API1.5_ADAC_EAC Signed-off-by: Markus Swarowsky (cherry picked from commit 917bec37d0849932c122d355ded690697a5bf812) Signed-off-by: Markus Swarowsky --- submanifests/optional.yaml | 4 ++-- west.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/submanifests/optional.yaml b/submanifests/optional.yaml index 54b3d77c0cb..00b0408c454 100644 --- a/submanifests/optional.yaml +++ b/submanifests/optional.yaml @@ -28,7 +28,7 @@ manifest: groups: - optional - name: psa-arch-tests - revision: 6a17330e0dfb5f319730f974d5b05f7b7f04757b + revision: 2cadb02a72eacda7042505dcbdd492371e8ce024 path: modules/tee/tf-m/psa-arch-tests remote: upstream groups: @@ -40,7 +40,7 @@ manifest: groups: - optional - name: tf-m-tests - revision: a878426da78fbd1486dfc29d6c6b82be4ee79e72 + revision: 08a3158f0623a4205608a52d880b17ae394e31d2 path: modules/tee/tf-m/tf-m-tests remote: upstream groups: diff --git a/west.yml b/west.yml index 65c1c5a0837..200690b6f3e 100644 --- a/west.yml +++ b/west.yml @@ -277,7 +277,7 @@ manifest: revision: 7c61a4cec26402d20c845c95dcad0e39dcd319f8 path: modules/lib/gui/lvgl - name: mbedtls - revision: 7053083b0cff8462464e3cbb826e87852fc03da6 + revision: 66ed2279d6222056af172c188eaf4dcfed481032 path: modules/crypto/mbedtls groups: - crypto @@ -322,7 +322,7 @@ manifest: groups: - crypto - name: trusted-firmware-m - revision: 33c0f47bcb19721a5c33e6fe1eee9225d00bb5bc + revision: 58d0b5367f0fada9dbaddad1e08e302aeb044863 path: modules/tee/tf-m/trusted-firmware-m groups: - tee From 4a539ee50b453d83624a5ad595ee41602f90e26c Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Fri, 8 Dec 2023 10:45:07 +0100 Subject: [PATCH 1337/1623] [nrf fromtree] modules: mbedtls: Sort base src Sort the list of source files for the mbedTLSBase library Signed-off-by: Markus Swarowsky (cherry picked from commit e53485c012e6b7cae1762bb41ea9d4cda0c05cd3) Signed-off-by: Markus Swarowsky --- modules/mbedtls/CMakeLists.txt | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/mbedtls/CMakeLists.txt b/modules/mbedtls/CMakeLists.txt index c1c8e076b83..1fd0cb5365e 100644 --- a/modules/mbedtls/CMakeLists.txt +++ b/modules/mbedtls/CMakeLists.txt @@ -28,30 +28,24 @@ zephyr_interface_library_named(mbedTLS) # Base mbed TLS files list(APPEND mbedtls_base_src + ${ZEPHYR_CURRENT_MODULE_DIR}/library/aes.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/aesni.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/aria.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/asn1parse.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/asn1write.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/base64.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/bignum.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/bignum_core.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/bignum_mod.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/bignum_mod_raw.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/nist_kw.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/oid.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/padlock.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/platform.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/platform_util.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/version.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/constant_time.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/aes.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/aesni.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/aria.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/bignum_mod.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/bignum.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/camellia.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ccm.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/chacha20.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/chachapoly.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/cipher.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/cipher_wrap.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/cipher.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/cmac.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/constant_time.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ctr_drbg.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/debug.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/des.c @@ -59,10 +53,10 @@ zephyr_interface_library_named(mbedTLS) ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecdh.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecdsa.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecjpake.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecp.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecp_curves.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/entropy.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecp.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/entropy_poll.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/entropy.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/error.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/gcm.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/hash_info.c @@ -70,11 +64,16 @@ zephyr_interface_library_named(mbedTLS) ${ZEPHYR_CURRENT_MODULE_DIR}/library/hmac_drbg.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/lmots.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/lms.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/md5.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/md.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/md5.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/memory_buffer_alloc.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/mps_reader.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/mps_trace.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/nist_kw.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/oid.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/padlock.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/platform_util.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/platform.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/poly1305.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ripemd160.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/rsa_alt_helpers.c @@ -85,6 +84,7 @@ zephyr_interface_library_named(mbedTLS) ${ZEPHYR_CURRENT_MODULE_DIR}/library/threading.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/timing.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/version_features.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/version.c zephyr_init.c ) From d277d2d4a47ab965ede843b4b417e3c955bf41c2 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Fri, 8 Dec 2023 10:48:28 +0100 Subject: [PATCH 1338/1623] [nrf fromtree] modules: mbedtls: Adapt source list to 3.5.0 remove hash_info.c and add ecp_curves_new.c Signed-off-by: Markus Swarowsky (cherry picked from commit 85ecdd70e4b35d63f942fc87165aa4da732ab5ea) Signed-off-by: Markus Swarowsky --- modules/mbedtls/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mbedtls/CMakeLists.txt b/modules/mbedtls/CMakeLists.txt index 1fd0cb5365e..3a2402e6a0c 100644 --- a/modules/mbedtls/CMakeLists.txt +++ b/modules/mbedtls/CMakeLists.txt @@ -53,13 +53,13 @@ zephyr_interface_library_named(mbedTLS) ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecdh.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecdsa.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecjpake.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecp_curves_new.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecp_curves.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ecp.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/entropy_poll.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/entropy.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/error.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/gcm.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/hash_info.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/hkdf.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/hmac_drbg.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/lmots.c From 4601e0d8969e62357e3dc478e969b536a2b76803 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Fri, 8 Dec 2023 13:34:48 +0100 Subject: [PATCH 1339/1623] [nrf fromtree] modules: tf-m: nrf5340_cpuapp: Change to cpuarch.cmake The preload.cmake was renamed to cpuarch.cmake in TF-M so change Signed-off-by: Markus Swarowsky (cherry picked from commit 21098acdec4bbec304a89caf5a969857059139e6) Signed-off-by: Markus Swarowsky --- .../nordic_nrf/nrf5340_cpuapp/{preload.cmake => cpuarch.cmake} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/{preload.cmake => cpuarch.cmake} (60%) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/preload.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/cpuarch.cmake similarity index 60% rename from modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/preload.cmake rename to modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/cpuarch.cmake index d9bd226eb65..903b23e4cc6 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/preload.cmake +++ b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/cpuarch.cmake @@ -4,4 +4,4 @@ # SPDX-License-Identifier: Apache-2.0 # -include(platform/ext/target/nordic_nrf/common/nrf5340/preload.cmake) +include(platform/ext/target/nordic_nrf/common/nrf5340/cpuarch.cmake) From f4469995f182b370f202078738beaa9912f67cd3 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Fri, 8 Dec 2023 13:35:11 +0100 Subject: [PATCH 1340/1623] [nrf fromtree] modules: tf-m: nrf9120: Change to cpuarch.cmake The preload.cmake was renamed to cpuarch.cmake in TF-M so change Signed-off-by: Markus Swarowsky (cherry picked from commit 132bfc45b7bfc5baefb02cc3d3c0dc51b7622838) Signed-off-by: Markus Swarowsky --- .../nordic_nrf/nrf9120/{preload.cmake => cpuarch.cmake} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename modules/trusted-firmware-m/nordic_nrf/nrf9120/{preload.cmake => cpuarch.cmake} (60%) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/preload.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9120/cpuarch.cmake similarity index 60% rename from modules/trusted-firmware-m/nordic_nrf/nrf9120/preload.cmake rename to modules/trusted-firmware-m/nordic_nrf/nrf9120/cpuarch.cmake index 4b3c6ee79ab..b34a8ddab1a 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9120/preload.cmake +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9120/cpuarch.cmake @@ -4,4 +4,4 @@ # SPDX-License-Identifier: Apache-2.0 # -include(platform/ext/target/nordic_nrf/common/nrf9120/preload.cmake) +include(platform/ext/target/nordic_nrf/common/nrf9120/cpuarch.cmake) From adf06e7beab0b50fdd665b7dff65e193efd85742 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Fri, 8 Dec 2023 13:35:33 +0100 Subject: [PATCH 1341/1623] [nrf fromtree] modules: tf-m: nrf9160: Change to cpuarch.cmake The preload.cmake was renamed to cpuarch.cmake in TF-M so change Signed-off-by: Markus Swarowsky (cherry picked from commit 78fd53fae796aee3fd6087b0ac6ef86c8284ee6f) Signed-off-by: Markus Swarowsky --- .../nordic_nrf/nrf9160/{preload.cmake => cpuarch.cmake} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename modules/trusted-firmware-m/nordic_nrf/nrf9160/{preload.cmake => cpuarch.cmake} (60%) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/preload.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9160/cpuarch.cmake similarity index 60% rename from modules/trusted-firmware-m/nordic_nrf/nrf9160/preload.cmake rename to modules/trusted-firmware-m/nordic_nrf/nrf9160/cpuarch.cmake index 364480a6f7f..228252f0147 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9160/preload.cmake +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9160/cpuarch.cmake @@ -4,4 +4,4 @@ # SPDX-License-Identifier: Apache-2.0 # -include(platform/ext/target/nordic_nrf/common/nrf9160/preload.cmake) +include(platform/ext/target/nordic_nrf/common/nrf9160/cpuarch.cmake) From 60c0c534e1adbcd9b692c41bb6dcfdf85da7197f Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Fri, 8 Dec 2023 14:03:30 +0100 Subject: [PATCH 1342/1623] [nrf fromtree] tf-m: Change NS include path for TF-M 2.0.0 The place where TF-M places its non-secure api header files has changed Therefore changing it for for all applications that use it. Signed-off-by: Markus Swarowsky (cherry picked from commit 11175c3ad3111f2bfb92084289f17f24207ed544) Signed-off-by: Markus Swarowsky --- boards/arm/bl5340_dvk/CMakeLists.txt | 2 +- boards/arm/nrf5340_audio_dk_nrf5340/CMakeLists.txt | 2 +- boards/arm/nrf5340dk_nrf5340/CMakeLists.txt | 2 +- drivers/entropy/CMakeLists.txt | 2 +- modules/uoscore-uedhoc/CMakeLists.txt | 2 +- samples/bluetooth/mesh/CMakeLists.txt | 2 +- samples/bluetooth/mesh_demo/CMakeLists.txt | 2 +- samples/bluetooth/mesh_provisioner/CMakeLists.txt | 2 +- samples/drivers/counter/alarm/CMakeLists.txt | 2 +- samples/subsys/usb/mass/CMakeLists.txt | 2 +- samples/tfm_integration/psa_crypto/CMakeLists.txt | 2 +- .../tfm_integration/psa_protected_storage/CMakeLists.txt | 2 +- samples/tfm_integration/tfm_ipc/CMakeLists.txt | 2 +- samples/tfm_integration/tfm_psa_test/CMakeLists.txt | 2 +- samples/tfm_integration/tfm_secure_partition/CMakeLists.txt | 2 +- soc/arm/nordic_nrf/common/CMakeLists.txt | 2 +- subsys/bluetooth/mesh/CMakeLists.txt | 2 +- subsys/net/lib/tls_credentials/CMakeLists.txt | 6 ++++++ tests/arch/arm/arm_thread_swap_tz/CMakeLists.txt | 2 +- 19 files changed, 24 insertions(+), 18 deletions(-) diff --git a/boards/arm/bl5340_dvk/CMakeLists.txt b/boards/arm/bl5340_dvk/CMakeLists.txt index 541334195dd..863c8bb599e 100644 --- a/boards/arm/bl5340_dvk/CMakeLists.txt +++ b/boards/arm/bl5340_dvk/CMakeLists.txt @@ -9,7 +9,7 @@ zephyr_library_sources(bl5340_dvk_cpunet_reset.c) if (CONFIG_BUILD_WITH_TFM) zephyr_library_include_directories( - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/CMakeLists.txt b/boards/arm/nrf5340_audio_dk_nrf5340/CMakeLists.txt index c950fd91724..fa1c1ba14d9 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/CMakeLists.txt +++ b/boards/arm/nrf5340_audio_dk_nrf5340/CMakeLists.txt @@ -8,7 +8,7 @@ if ((CONFIG_BOARD_NRF5340_AUDIO_DK_NRF5340_CPUAPP OR CONFIG_BOARD_NRF5340_AUDIO_ if (CONFIG_BUILD_WITH_TFM) zephyr_library_include_directories( - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/boards/arm/nrf5340dk_nrf5340/CMakeLists.txt b/boards/arm/nrf5340dk_nrf5340/CMakeLists.txt index 8ba3238c40b..5128462d70c 100644 --- a/boards/arm/nrf5340dk_nrf5340/CMakeLists.txt +++ b/boards/arm/nrf5340dk_nrf5340/CMakeLists.txt @@ -8,7 +8,7 @@ zephyr_library_sources(nrf5340_cpunet_reset.c) if (CONFIG_BUILD_WITH_TFM) zephyr_library_include_directories( - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/drivers/entropy/CMakeLists.txt b/drivers/entropy/CMakeLists.txt index 99184f3b1e5..7ca87d60944 100644 --- a/drivers/entropy/CMakeLists.txt +++ b/drivers/entropy/CMakeLists.txt @@ -28,6 +28,6 @@ zephyr_library_sources_ifdef(CONFIG_ENTROPY_PSA_CRYPTO_RNG entropy_psa_crypt if (CONFIG_BUILD_WITH_TFM) target_include_directories(${ZEPHYR_CURRENT_LIBRARY} PRIVATE - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/modules/uoscore-uedhoc/CMakeLists.txt b/modules/uoscore-uedhoc/CMakeLists.txt index e23ad7da2e6..aaf842e392c 100644 --- a/modules/uoscore-uedhoc/CMakeLists.txt +++ b/modules/uoscore-uedhoc/CMakeLists.txt @@ -29,7 +29,7 @@ if (CONFIG_UOSCORE OR CONFIG_UEDHOC) if (CONFIG_BUILD_WITH_TFM) zephyr_library_include_directories( - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/samples/bluetooth/mesh/CMakeLists.txt b/samples/bluetooth/mesh/CMakeLists.txt index 6ee28b12d48..74734eb84b4 100644 --- a/samples/bluetooth/mesh/CMakeLists.txt +++ b/samples/bluetooth/mesh/CMakeLists.txt @@ -16,6 +16,6 @@ endif() if (CONFIG_BUILD_WITH_TFM) target_include_directories(app PRIVATE - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/samples/bluetooth/mesh_demo/CMakeLists.txt b/samples/bluetooth/mesh_demo/CMakeLists.txt index 07736d6c12e..f5d347ab373 100644 --- a/samples/bluetooth/mesh_demo/CMakeLists.txt +++ b/samples/bluetooth/mesh_demo/CMakeLists.txt @@ -15,6 +15,6 @@ endif() if (CONFIG_BUILD_WITH_TFM) target_include_directories(app PRIVATE - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/samples/bluetooth/mesh_provisioner/CMakeLists.txt b/samples/bluetooth/mesh_provisioner/CMakeLists.txt index 7b22bd0fe14..aefe3628ba8 100644 --- a/samples/bluetooth/mesh_provisioner/CMakeLists.txt +++ b/samples/bluetooth/mesh_provisioner/CMakeLists.txt @@ -10,6 +10,6 @@ target_sources(app PRIVATE src/main.c) if (CONFIG_BUILD_WITH_TFM) target_include_directories(app PRIVATE - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/samples/drivers/counter/alarm/CMakeLists.txt b/samples/drivers/counter/alarm/CMakeLists.txt index eadc9e99e67..747c2b27ebd 100644 --- a/samples/drivers/counter/alarm/CMakeLists.txt +++ b/samples/drivers/counter/alarm/CMakeLists.txt @@ -9,6 +9,6 @@ target_sources(app PRIVATE ${app_sources}) if(CONFIG_BUILD_WITH_TFM) target_include_directories(app PRIVATE - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/samples/subsys/usb/mass/CMakeLists.txt b/samples/subsys/usb/mass/CMakeLists.txt index ef71596104d..2ac19d9b016 100644 --- a/samples/subsys/usb/mass/CMakeLists.txt +++ b/samples/subsys/usb/mass/CMakeLists.txt @@ -15,6 +15,6 @@ target_sources(app PRIVATE ${app_sources}) if(CONFIG_BUILD_WITH_TFM) target_include_directories(app PRIVATE - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/samples/tfm_integration/psa_crypto/CMakeLists.txt b/samples/tfm_integration/psa_crypto/CMakeLists.txt index 17339b470b8..f8ef1eca23f 100644 --- a/samples/tfm_integration/psa_crypto/CMakeLists.txt +++ b/samples/tfm_integration/psa_crypto/CMakeLists.txt @@ -16,7 +16,7 @@ target_sources(app PRIVATE src/util_app_log.c) target_sources(app PRIVATE src/util_sformat.c) target_include_directories(app PRIVATE - $/install/interface/include + $/api_ns/interface/include ) # In TF-M, default value of CRYPTO_ENGINE_BUF_SIZE is 0x2080. It causes diff --git a/samples/tfm_integration/psa_protected_storage/CMakeLists.txt b/samples/tfm_integration/psa_protected_storage/CMakeLists.txt index bbb8a2041fd..dfb0169eda6 100644 --- a/samples/tfm_integration/psa_protected_storage/CMakeLists.txt +++ b/samples/tfm_integration/psa_protected_storage/CMakeLists.txt @@ -13,5 +13,5 @@ project(protected_storage) target_sources(app PRIVATE src/main.c) target_include_directories(app PRIVATE - $/install/interface/include + $/api_ns/interface/include ) diff --git a/samples/tfm_integration/tfm_ipc/CMakeLists.txt b/samples/tfm_integration/tfm_ipc/CMakeLists.txt index f11b67af843..896af7bfbda 100644 --- a/samples/tfm_integration/tfm_ipc/CMakeLists.txt +++ b/samples/tfm_integration/tfm_ipc/CMakeLists.txt @@ -9,5 +9,5 @@ project(tfm_ipc) target_sources(app PRIVATE src/main.c) target_include_directories(app PRIVATE - $/install/interface/include + $/api_ns/interface/include ) diff --git a/samples/tfm_integration/tfm_psa_test/CMakeLists.txt b/samples/tfm_integration/tfm_psa_test/CMakeLists.txt index 9dcbf12ae64..7692ea3dfd1 100644 --- a/samples/tfm_integration/tfm_psa_test/CMakeLists.txt +++ b/samples/tfm_integration/tfm_psa_test/CMakeLists.txt @@ -13,5 +13,5 @@ project(tfm_psa_storage_test) target_sources(app PRIVATE src/main.c) target_include_directories(app PRIVATE - $/install/interface/include + $/api_ns/interface/include ) diff --git a/samples/tfm_integration/tfm_secure_partition/CMakeLists.txt b/samples/tfm_integration/tfm_secure_partition/CMakeLists.txt index 69901f73928..beadae9230a 100644 --- a/samples/tfm_integration/tfm_secure_partition/CMakeLists.txt +++ b/samples/tfm_integration/tfm_secure_partition/CMakeLists.txt @@ -28,7 +28,7 @@ target_sources(app PRIVATE ) target_include_directories(app PRIVATE - $/install/interface/include + $/api_ns/interface/include ) target_compile_definitions(app diff --git a/soc/arm/nordic_nrf/common/CMakeLists.txt b/soc/arm/nordic_nrf/common/CMakeLists.txt index c894615a700..ea05f3d369e 100644 --- a/soc/arm/nordic_nrf/common/CMakeLists.txt +++ b/soc/arm/nordic_nrf/common/CMakeLists.txt @@ -11,6 +11,6 @@ set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/li if (CONFIG_TFM_PARTITION_PLATFORM) zephyr_library_sources(soc_secure.c) zephyr_library_include_directories( - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/subsys/bluetooth/mesh/CMakeLists.txt b/subsys/bluetooth/mesh/CMakeLists.txt index 5d4f41ce7f7..c628fb6d9db 100644 --- a/subsys/bluetooth/mesh/CMakeLists.txt +++ b/subsys/bluetooth/mesh/CMakeLists.txt @@ -129,6 +129,6 @@ zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) if (CONFIG_BUILD_WITH_TFM) target_include_directories(${ZEPHYR_CURRENT_LIBRARY} PRIVATE - $/install/interface/include + $/api_ns/interface/include ) endif() diff --git a/subsys/net/lib/tls_credentials/CMakeLists.txt b/subsys/net/lib/tls_credentials/CMakeLists.txt index 490a558953d..5a80bed58a6 100644 --- a/subsys/net/lib/tls_credentials/CMakeLists.txt +++ b/subsys/net/lib/tls_credentials/CMakeLists.txt @@ -15,3 +15,9 @@ zephyr_library_sources_ifdef(CONFIG_TLS_CREDENTIALS_SHELL ) zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS) + +if (CONFIG_TLS_CREDENTIALS_BACKEND_PROTECTED_STORAGE AND CONFIG_BUILD_WITH_TFM) + target_include_directories(${ZEPHYR_CURRENT_LIBRARY} PRIVATE + $/api_ns/interface/include + ) +endif() diff --git a/tests/arch/arm/arm_thread_swap_tz/CMakeLists.txt b/tests/arch/arm/arm_thread_swap_tz/CMakeLists.txt index 93e91deafcb..10ee1786e16 100644 --- a/tests/arch/arm/arm_thread_swap_tz/CMakeLists.txt +++ b/tests/arch/arm/arm_thread_swap_tz/CMakeLists.txt @@ -14,6 +14,6 @@ target_sources(app PRIVATE ${app_sources}) if (CONFIG_BUILD_WITH_TFM) target_include_directories(app PRIVATE - $/install/interface/include + $/api_ns/interface/include ) endif() From 5691f379873872198379bd516222c7830780cc8f Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Fri, 8 Dec 2023 14:12:07 +0100 Subject: [PATCH 1343/1623] [nrf fromtree] modules: tf-m: Remove platform_ns target The platform_ns library is no longer build with the split build anymore so removing it. Signed-off-by: Markus Swarowsky (cherry picked from commit 8b257c058da9249ecce580beed8516b274bf44a0) Signed-off-by: Markus Swarowsky --- modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt index 41dca2f15a9..d5bc57ac5d9 100644 --- a/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt +++ b/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt @@ -36,14 +36,6 @@ target_include_directories(platform_s ${board_includes} ) -target_include_directories(platform_ns - PUBLIC - include - include/util - ${partition_includes} - ${board_includes} -) - if(BL2) target_include_directories(platform_bl2 PUBLIC From 85025b0c329f2e89b697882ee909d5ce76473d2b Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 8 Dec 2023 15:16:35 +0100 Subject: [PATCH 1344/1623] [nrf fromtree] modules: Update source, lib and include path for TF-M interface files Update source lib and include path for TF-M interface files. Signed-off-by: Joakim Andersson Signed-off-by: Markus Swarowsky (cherry picked from commit a14f42a817a3b9a412bf1669ae4134054131b210) Signed-off-by: Markus Swarowsky --- boards/arm/b_u585i_iot02a/CMakeLists.txt | 2 +- boards/arm/b_u585i_iot02a/doc/index.rst | 4 +-- boards/arm/nucleo_l552ze_q/CMakeLists.txt | 2 +- .../nucleo_l552ze_q/doc/nucleol552ze_q.rst | 2 +- boards/arm/nucleo_u575zi_q/doc/index.rst | 2 +- boards/arm/nucleo_u5a5zj_q/CMakeLists.txt | 2 +- boards/arm/nucleo_u5a5zj_q/doc/index.rst | 2 +- boards/arm/stm32l562e_dk/CMakeLists.txt | 2 +- boards/arm/stm32l562e_dk/doc/index.rst | 2 +- modules/trusted-firmware-m/CMakeLists.txt | 25 ++++++++----------- 10 files changed, 21 insertions(+), 24 deletions(-) diff --git a/boards/arm/b_u585i_iot02a/CMakeLists.txt b/boards/arm/b_u585i_iot02a/CMakeLists.txt index dde73804665..f6ca91f1a73 100644 --- a/boards/arm/b_u585i_iot02a/CMakeLists.txt +++ b/boards/arm/b_u585i_iot02a/CMakeLists.txt @@ -10,6 +10,6 @@ endif() if(CONFIG_BUILD_WITH_TFM) set_property(GLOBAL APPEND PROPERTY extra_post_build_commands #Execute post build script postbuild.sh - COMMAND $/postbuild.sh ${COMPILER_FULL_PATH} + COMMAND $/api_ns/postbuild.sh ${COMPILER_FULL_PATH} ) endif() diff --git a/boards/arm/b_u585i_iot02a/doc/index.rst b/boards/arm/b_u585i_iot02a/doc/index.rst index 3c794b4de79..5512a95f16d 100644 --- a/boards/arm/b_u585i_iot02a/doc/index.rst +++ b/boards/arm/b_u585i_iot02a/doc/index.rst @@ -346,14 +346,14 @@ can be generated using ``b_u585i_iot02a_ns`` as build target. $ west build -b b_u585i_iot02a_ns path/to/source/directory -Note: When building the ``*_ns`` image with TF-M, ``build/tfm/postbuild.sh`` bash script +Note: When building the ``*_ns`` image with TF-M, ``build/tfm/api_ns/postbuild.sh`` bash script is run automatically in a post-build step to make some required flash layout changes. Once the build is completed, run the following script to initialize the option bytes. .. code-block:: bash - $ build/tfm/regression.sh + $ build/tfm/api_ns/regression.sh Finally, to flash the board, run: diff --git a/boards/arm/nucleo_l552ze_q/CMakeLists.txt b/boards/arm/nucleo_l552ze_q/CMakeLists.txt index d170d283e99..260ecca2707 100644 --- a/boards/arm/nucleo_l552ze_q/CMakeLists.txt +++ b/boards/arm/nucleo_l552ze_q/CMakeLists.txt @@ -10,6 +10,6 @@ endif() if (CONFIG_BUILD_WITH_TFM) set_property(GLOBAL APPEND PROPERTY extra_post_build_commands #Execute post build script postbuild.sh - COMMAND $/postbuild.sh ${COMPILER_FULL_PATH} + COMMAND $/api_ns/postbuild.sh ${COMPILER_FULL_PATH} ) endif() diff --git a/boards/arm/nucleo_l552ze_q/doc/nucleol552ze_q.rst b/boards/arm/nucleo_l552ze_q/doc/nucleol552ze_q.rst index 51675477af4..fbf77de1c44 100644 --- a/boards/arm/nucleo_l552ze_q/doc/nucleol552ze_q.rst +++ b/boards/arm/nucleo_l552ze_q/doc/nucleol552ze_q.rst @@ -338,7 +338,7 @@ can be generated using ``nucleo_l552ze_q_ns`` as build target. $ west build -b nucleo_l552ze_q_ns path/to/source/directory -Note: When building the ``*_ns`` image with TF-M, ``build/tfm/postbuild.sh`` bash script +Note: When building the ``*_ns`` image with TF-M, ``build/tfm/api_ns/postbuild.sh`` bash script is run automatically in a post-build step to make some required flash layout changes. Once the build is completed, run the following script to initialize the option bytes. diff --git a/boards/arm/nucleo_u575zi_q/doc/index.rst b/boards/arm/nucleo_u575zi_q/doc/index.rst index 0de2c364ecf..e7035dd497a 100644 --- a/boards/arm/nucleo_u575zi_q/doc/index.rst +++ b/boards/arm/nucleo_u575zi_q/doc/index.rst @@ -308,7 +308,7 @@ can be generated using ``nucleo_u575zi_q_ns`` as build target. $ west build -b nucleo_u575zi_q_ns path/to/source/directory -Note: When building the ``*_ns`` image with TF-M, ``build/tfm/postbuild.sh`` bash script +Note: When building the ``*_ns`` image with TF-M, ``build/tfm/api_ns/postbuild.sh`` bash script is run automatically in a post-build step to make some required flash layout changes. Once the build is completed, run the following script to initialize the option bytes. diff --git a/boards/arm/nucleo_u5a5zj_q/CMakeLists.txt b/boards/arm/nucleo_u5a5zj_q/CMakeLists.txt index c79a4b7b4e7..7c2da293e20 100644 --- a/boards/arm/nucleo_u5a5zj_q/CMakeLists.txt +++ b/boards/arm/nucleo_u5a5zj_q/CMakeLists.txt @@ -9,6 +9,6 @@ endif() if(CONFIG_BUILD_WITH_TFM) set_property(GLOBAL APPEND PROPERTY extra_post_build_commands #Execute post build script postbuild.sh - COMMAND $/postbuild.sh ${COMPILER_FULL_PATH} + COMMAND $/api_ns/postbuild.sh ${COMPILER_FULL_PATH} ) endif() diff --git a/boards/arm/nucleo_u5a5zj_q/doc/index.rst b/boards/arm/nucleo_u5a5zj_q/doc/index.rst index f877be5c168..154dbd32579 100644 --- a/boards/arm/nucleo_u5a5zj_q/doc/index.rst +++ b/boards/arm/nucleo_u5a5zj_q/doc/index.rst @@ -342,7 +342,7 @@ can be generated using ``nucleo_u5a5zj_q_ns`` as build target. $ west build -b nucleo_u5a5zj_q_ns path/to/source/directory -Note: When building the ``*_ns`` image with TF-M, ``build/tfm/postbuild.sh`` bash script +Note: When building the ``*_ns`` image with TF-M, ``build/tfm/api_ns/postbuild.sh`` bash script is run automatically in a post-build step to make some required flash layout changes. Once the build is completed, run the following script to initialize the option bytes. diff --git a/boards/arm/stm32l562e_dk/CMakeLists.txt b/boards/arm/stm32l562e_dk/CMakeLists.txt index dde73804665..f6ca91f1a73 100644 --- a/boards/arm/stm32l562e_dk/CMakeLists.txt +++ b/boards/arm/stm32l562e_dk/CMakeLists.txt @@ -10,6 +10,6 @@ endif() if(CONFIG_BUILD_WITH_TFM) set_property(GLOBAL APPEND PROPERTY extra_post_build_commands #Execute post build script postbuild.sh - COMMAND $/postbuild.sh ${COMPILER_FULL_PATH} + COMMAND $/api_ns/postbuild.sh ${COMPILER_FULL_PATH} ) endif() diff --git a/boards/arm/stm32l562e_dk/doc/index.rst b/boards/arm/stm32l562e_dk/doc/index.rst index 5a4f5845617..0eb2aa7630c 100644 --- a/boards/arm/stm32l562e_dk/doc/index.rst +++ b/boards/arm/stm32l562e_dk/doc/index.rst @@ -340,7 +340,7 @@ can be generated using ``stm32l562e_dk_ns`` as build target. $ west build -b stm32l562e_dk_ns path/to/source/directory -Note: When building the ``*_ns`` image with TF-M, ``build/tfm/postbuild.sh`` bash script +Note: When building the ``*_ns`` image with TF-M, ``build/tfm/api_ns/postbuild.sh`` bash script is run automatically in a post-build step to make some required flash layout changes. Once the build is completed, run the following script to initialize the option bytes. diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index ad1109d849b..8cc546883d0 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -181,11 +181,12 @@ if (CONFIG_BUILD_WITH_TFM) set(TFM_TEST_REPO_PATH ${ZEPHYR_CURRENT_MODULE_DIR}/../tf-m-tests) set(PSA_ARCH_TESTS_PATH ${ZEPHYR_CURRENT_MODULE_DIR}/../psa-arch-tests) - set(VENEERS_FILE ${TFM_BINARY_DIR}/secure_fw/s_veneers.o) + set(TFM_INTERFACE_SOURCE_DIR ${TFM_BINARY_DIR}/api_ns/interface/src) + set(TFM_INTERFACE_INCLUDE_DIR ${TFM_BINARY_DIR}/api_ns/interface/include) + set(TFM_INTERFACE_LIB_DIR ${TFM_BINARY_DIR}/api_ns/interface/lib) + set(TFM_API_NS_PATH ${TFM_BINARY_DIR}/tf-m-tests/app/libtfm_api_ns.a) set(PLATFORM_NS_FILE ${TFM_BINARY_DIR}/platform/ns/libplatform_ns.a) - set(TFM_GENERATED_INCLUDES ${TFM_BINARY_DIR}/generated/interface/include) - set(TFM_INTERFACE_SOURCE_DIR ${TFM_BINARY_DIR}/install/interface/src) if (TFM_PSA_TEST_SUITE) set(PSA_TEST_VAL_FILE ${TFM_BINARY_DIR}/tf-m-tests/app/psa_api_tests/val/val_nspe.a) @@ -213,9 +214,7 @@ if (CONFIG_BUILD_WITH_TFM) set(TFM_S_NS_SIGNED_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_s_ns_signed.bin) set(BUILD_BYPRODUCTS - ${VENEERS_FILE} ${TFM_API_NS_PATH} - ${TFM_GENERATED_INCLUDES}/psa_manifest/sid.h ${PSA_TEST_VAL_FILE} ${PSA_TEST_PAL_FILE} ${PSA_TEST_COMBINE_FILE} @@ -232,13 +231,15 @@ if (CONFIG_BUILD_WITH_TFM) ${TFM_NS_SIGNED_BIN_FILE} ${TFM_S_NS_SIGNED_BIN_FILE} + ${TFM_INTERFACE_LIB_DIR}/s_veneers.o + ${TFM_INTERFACE_SOURCE_DIR}/tfm_attest_api.c ${TFM_INTERFACE_SOURCE_DIR}/tfm_crypto_api.c ${TFM_INTERFACE_SOURCE_DIR}/tfm_fwu_api.c ${TFM_INTERFACE_SOURCE_DIR}/tfm_its_api.c ${TFM_INTERFACE_SOURCE_DIR}/tfm_platform_api.c ${TFM_INTERFACE_SOURCE_DIR}/tfm_ps_api.c - ${TFM_INTERFACE_SOURCE_DIR}/tfm_psa_ns_api.c + ${TFM_INTERFACE_SOURCE_DIR}/tfm_tz_psa_ns_api.c # Specific to nordic_nrf platform ${TFM_INTERFACE_SOURCE_DIR}/tfm_ioctl_core_ns_api.c @@ -433,7 +434,7 @@ if (CONFIG_BUILD_WITH_TFM) zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_INITIAL_ATTESTATION ${TFM_INTERFACE_SOURCE_DIR}/tfm_attest_api.c) zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_FIRMWARE_UPDATE ${TFM_INTERFACE_SOURCE_DIR}/tfm_fwu_api.c) - zephyr_library_sources(${TFM_INTERFACE_SOURCE_DIR}/tfm_psa_ns_api.c) + zephyr_library_sources(${TFM_INTERFACE_SOURCE_DIR}/tfm_tz_psa_ns_api.c) if(CONFIG_SOC_FAMILY_NRF) zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_PLATFORM ${TFM_INTERFACE_SOURCE_DIR}/tfm_ioctl_core_ns_api.c) @@ -446,17 +447,13 @@ if (CONFIG_BUILD_WITH_TFM) ) endif() - zephyr_include_directories( - ${TFM_GENERATED_INCLUDES} - ) - target_include_directories(tfm_api PRIVATE - ${TFM_BINARY_DIR}/install/interface/include - ${TFM_BINARY_DIR}/install/interface/include/crypto_keys + ${TFM_INTERFACE_INCLUDE_DIR} + ${TFM_INTERFACE_INCLUDE_DIR}/crypto_keys ) zephyr_library_link_libraries( - ${VENEERS_FILE} + ${TFM_INTERFACE_LIB_DIR}/s_veneers.o ) # To ensure that generated include files are created before they are used. From d4c928c9061b52f36d2b6314d7970e7e8edc26c5 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 8 Dec 2023 15:17:10 +0100 Subject: [PATCH 1345/1623] [nrf fromtree] tfm: Use PSA error codes instead of TFM error codes The TFM error codes are no longer in the interface headers. All TF-M functions return PSA status codes, so use this here as well. Signed-off-by: Joakim Andersson Signed-off-by: Markus Swarowsky (cherry picked from commit d931dded119f3fcbc7352ca0b580e3fdfd1fe296) Signed-off-by: Markus Swarowsky --- modules/trusted-firmware-m/interface/interface.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/trusted-firmware-m/interface/interface.c b/modules/trusted-firmware-m/interface/interface.c index ad0ed1abdfe..d949a9dc027 100644 --- a/modules/trusted-firmware-m/interface/interface.c +++ b/modules/trusted-firmware-m/interface/interface.c @@ -35,7 +35,7 @@ int32_t tfm_ns_interface_dispatch(veneer_fn fn, if (!is_pre_kernel) { /* TF-M request protected by NS lock */ if (k_mutex_lock(&tfm_mutex, K_FOREVER) != 0) { - return (int32_t)TFM_ERROR_GENERIC; + return (int32_t)PSA_ERROR_GENERIC_ERROR; } #if !defined(CONFIG_ARM_NONSECURE_PREEMPTIBLE_SECURE_CALLS) @@ -79,7 +79,7 @@ uint32_t tfm_ns_interface_init(void) * The static K_MUTEX_DEFINE handles mutex initialization, * so this function may be implemented as no-op. */ - return TFM_SUCCESS; + return PSA_SUCCESS; } @@ -90,7 +90,7 @@ uint32_t tfm_ns_interface_init(void) static int ns_interface_init(void) { - __ASSERT(tfm_ns_interface_init() == TFM_SUCCESS, + __ASSERT(tfm_ns_interface_init() == PSA_SUCCESS, "TF-M NS interface init failed"); return 0; From b139d4fea0a9f325ef2e1891f016a824aed9c58f Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 8 Dec 2023 15:18:21 +0100 Subject: [PATCH 1346/1623] [nrf fromtree] tfm: nordic_nrf: Remove include of tfm_api.h, update install path Update install path of tfm_ioctl_api.h, remove include of tfm_api.h Signed-off-by: Joakim Andersson Signed-off-by: Markus Swarowsky (cherry picked from commit f5eecd500d46a62a32f360bc42d082bd8cd7640c) Signed-off-by: Markus Swarowsky --- modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt | 2 +- modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h | 1 - samples/tfm_integration/tfm_ipc/src/main.c | 1 - .../tfm_secure_partition/dummy_partition/dummy_partition.c | 1 - .../tfm_integration/tfm_secure_partition/src/dummy_partition.h | 2 -- 5 files changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt index d5bc57ac5d9..39aa2199b47 100644 --- a/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt +++ b/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt @@ -48,7 +48,7 @@ endif() if (TFM_PARTITION_PLATFORM) install(FILES include/tfm_ioctl_api.h - DESTINATION ${TFM_INSTALL_PATH}/interface/include) + DESTINATION ${INSTALL_INTERFACE_INC_DIR}) endif() #========================= tfm_spm ============================================# diff --git a/modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h b/modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h index c6c36ee927f..3fade10525a 100644 --- a/modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h +++ b/modules/trusted-firmware-m/nordic_nrf/include/tfm_ioctl_api.h @@ -9,7 +9,6 @@ #include #include -#include #include /* Include core IOCTL services */ diff --git a/samples/tfm_integration/tfm_ipc/src/main.c b/samples/tfm_integration/tfm_ipc/src/main.c index 7179705cbe3..133c7203b0e 100644 --- a/samples/tfm_integration/tfm_ipc/src/main.c +++ b/samples/tfm_integration/tfm_ipc/src/main.c @@ -7,7 +7,6 @@ #include #include -#include "tfm_api.h" #include "tfm_ns_interface.h" #ifdef TFM_PSA_API #include "psa_manifest/sid.h" diff --git a/samples/tfm_integration/tfm_secure_partition/dummy_partition/dummy_partition.c b/samples/tfm_integration/tfm_secure_partition/dummy_partition/dummy_partition.c index 6519723058c..d618868ddbf 100644 --- a/samples/tfm_integration/tfm_secure_partition/dummy_partition/dummy_partition.c +++ b/samples/tfm_integration/tfm_secure_partition/dummy_partition/dummy_partition.c @@ -7,7 +7,6 @@ #include #include #include -#include "tfm_api.h" #include "psa/service.h" #include "psa_manifest/tfm_dummy_partition.h" diff --git a/samples/tfm_integration/tfm_secure_partition/src/dummy_partition.h b/samples/tfm_integration/tfm_secure_partition/src/dummy_partition.h index b31ce897d27..7ca52b3c5c4 100644 --- a/samples/tfm_integration/tfm_secure_partition/src/dummy_partition.h +++ b/samples/tfm_integration/tfm_secure_partition/src/dummy_partition.h @@ -4,8 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "tfm_api.h" - psa_status_t dp_secret_digest(uint32_t secret_index, void *p_digest, size_t digest_size); From da6042c528658181550370e5c375338b43fe44aa Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Mon, 11 Dec 2023 13:33:35 +0100 Subject: [PATCH 1347/1623] [nrf fromtree] modules: mbedtls: Rename of psa_crypto_driver_wrappers psa_crypto_driver_wrappers.c got changed to psa_crypto_driver_wrappers_no_static.c Signed-off-by: Markus Swarowsky (cherry picked from commit fbee1c61ed3f927c04a939f8a1ff9662c98f3c6c) Signed-off-by: Markus Swarowsky --- modules/mbedtls/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mbedtls/CMakeLists.txt b/modules/mbedtls/CMakeLists.txt index 3a2402e6a0c..111bf53cf21 100644 --- a/modules/mbedtls/CMakeLists.txt +++ b/modules/mbedtls/CMakeLists.txt @@ -114,7 +114,7 @@ zephyr_interface_library_named(mbedTLS) list(APPEND crypto_source ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_aead.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_cipher.c - ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_driver_wrappers.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_driver_wrappers_no_static.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_ecp.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_hash.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_mac.c From 175564c0f3a79efef10b9ceb78ecb66d432bdb2c Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Mon, 11 Dec 2023 17:27:32 +0100 Subject: [PATCH 1348/1623] [nrf fromtree] modules: mbedtls: Add a mbedtls_ms_time implementation MbedTLS 3.5.0 requires a implementation of mbedtls_ms_time giving a time in ms for TLS 1.3 Therefor adding an alternative implementation using zephyrs k_uptime_get Signed-off-by: Markus Swarowsky (cherry picked from commit dc7613865dc52b33d56a898ee27d8b0423ada6f0) Signed-off-by: Markus Swarowsky --- modules/mbedtls/configs/config-mini-tls1_1.h | 1 + modules/mbedtls/configs/config-no-entropy.h | 1 + modules/mbedtls/configs/config-suite-b.h | 1 + modules/mbedtls/configs/config-tls-generic.h | 1 + modules/mbedtls/zephyr_init.c | 8 ++++++++ tests/subsys/jwt/src/tls_config/user-tls-conf.h | 1 + 6 files changed, 13 insertions(+) diff --git a/modules/mbedtls/configs/config-mini-tls1_1.h b/modules/mbedtls/configs/config-mini-tls1_1.h index 2bce8647caf..da8bf795c1d 100644 --- a/modules/mbedtls/configs/config-mini-tls1_1.h +++ b/modules/mbedtls/configs/config-mini-tls1_1.h @@ -59,6 +59,7 @@ /* System support */ #define MBEDTLS_HAVE_ASM #define MBEDTLS_HAVE_TIME +#define MBEDTLS_PLATFORM_MS_TIME_ALT /* mbed TLS feature support */ #define MBEDTLS_CIPHER_MODE_CBC diff --git a/modules/mbedtls/configs/config-no-entropy.h b/modules/mbedtls/configs/config-no-entropy.h index b5295bf1fb7..b3406a394b4 100644 --- a/modules/mbedtls/configs/config-no-entropy.h +++ b/modules/mbedtls/configs/config-no-entropy.h @@ -62,6 +62,7 @@ /* System support */ #define MBEDTLS_HAVE_ASM #define MBEDTLS_HAVE_TIME +#define MBEDTLS_PLATFORM_MS_TIME_ALT /* mbed TLS feature support */ #define MBEDTLS_CIPHER_MODE_CBC diff --git a/modules/mbedtls/configs/config-suite-b.h b/modules/mbedtls/configs/config-suite-b.h index 6f2cc963bd1..7468f763358 100644 --- a/modules/mbedtls/configs/config-suite-b.h +++ b/modules/mbedtls/configs/config-suite-b.h @@ -66,6 +66,7 @@ /* System support */ #define MBEDTLS_HAVE_ASM #define MBEDTLS_HAVE_TIME +#define MBEDTLS_PLATFORM_MS_TIME_ALT /* mbed TLS feature support */ #define MBEDTLS_ECP_DP_SECP256R1_ENABLED diff --git a/modules/mbedtls/configs/config-tls-generic.h b/modules/mbedtls/configs/config-tls-generic.h index ab4a9610732..7874d0ab029 100644 --- a/modules/mbedtls/configs/config-tls-generic.h +++ b/modules/mbedtls/configs/config-tls-generic.h @@ -37,6 +37,7 @@ #if defined(CONFIG_MBEDTLS_HAVE_TIME_DATE) #define MBEDTLS_HAVE_TIME #define MBEDTLS_HAVE_TIME_DATE +#define MBEDTLS_PLATFORM_MS_TIME_ALT #endif #if defined(CONFIG_MBEDTLS_TEST) diff --git a/modules/mbedtls/zephyr_init.c b/modules/mbedtls/zephyr_init.c index 3329c3b9c8d..49c9ffc8aff 100644 --- a/modules/mbedtls/zephyr_init.c +++ b/modules/mbedtls/zephyr_init.c @@ -15,6 +15,8 @@ #include #include #include +#include + #include @@ -107,3 +109,9 @@ int mbedtls_init(void) { return _mbedtls_init(); } + +/* TLS 1.3 ticket lifetime needs a timing interface */ +mbedtls_ms_time_t mbedtls_ms_time(void) +{ + return (mbedtls_ms_time_t)k_uptime_get(); +} diff --git a/tests/subsys/jwt/src/tls_config/user-tls-conf.h b/tests/subsys/jwt/src/tls_config/user-tls-conf.h index 035f2b062ec..0d95ee80ac0 100644 --- a/tests/subsys/jwt/src/tls_config/user-tls-conf.h +++ b/tests/subsys/jwt/src/tls_config/user-tls-conf.h @@ -3,3 +3,4 @@ #define MBEDTLS_HAVE_TIME #define MBEDTLS_HAVE_TIME_DATE #define MBEDTLS_PLATFORM_TIME_ALT +#define MBEDTLS_PLATFORM_MS_TIME_ALT From a8400a927fc44e50cb9e8f9c5bdf0bc0d4f78a48 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Mon, 11 Dec 2023 21:52:07 +0100 Subject: [PATCH 1349/1623] [nrf fromtree] modules: mbedtls: Use TF-M PSA API headers Use TF-M PSA API headers when compiling with TF-M enabled. Fixes: #43249 Signed-off-by: Joakim Andersson Signed-off-by: Markus Swarowsky (cherry picked from commit 3398c987439eb06a8dcb8f27adc5d010dca2604c) Signed-off-by: Markus Swarowsky --- modules/mbedtls/CMakeLists.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/mbedtls/CMakeLists.txt b/modules/mbedtls/CMakeLists.txt index 111bf53cf21..c0b17419a1c 100644 --- a/modules/mbedtls/CMakeLists.txt +++ b/modules/mbedtls/CMakeLists.txt @@ -16,6 +16,12 @@ zephyr_interface_library_named(mbedTLS) MBEDTLS_CONFIG_FILE="${CONFIG_MBEDTLS_CFG_FILE}" ) + if (CONFIG_BUILD_WITH_TFM) + target_include_directories(mbedTLS INTERFACE + $/api_ns/interface/include + ) + endif() + # Add regular includes target_include_directories(mbedTLS INTERFACE ${ZEPHYR_CURRENT_MODULE_DIR}/include @@ -110,7 +116,7 @@ zephyr_interface_library_named(mbedTLS) zephyr_library_named(mbedTLSCrypto) - if (CONFIG_MBEDTLS_PSA_CRYPTO_C) + if (CONFIG_MBEDTLS_PSA_CRYPTO_C AND NOT CONFIG_BUILD_WITH_TFM) list(APPEND crypto_source ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_aead.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_cipher.c @@ -122,11 +128,6 @@ zephyr_interface_library_named(mbedTLS) ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_se.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_storage.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_its_file.c - ) - endif() - - if (NOT CONFIG_BUILD_WITH_TFM) - list(APPEND crypto_source ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_client.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_crypto_slot_management.c From 2bb1039e58d0cf817a00ac7736bb3ce0b2c9c843 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Wed, 13 Dec 2023 16:31:32 +0100 Subject: [PATCH 1350/1623] [nrf fromtree] sample: tfm_secure_partition: Change tfm_partition_defs to tfm_config The target tfm_partition_defs got removed and tfm_config gets used now so updating it Signed-off-by: Markus Swarowsky (cherry picked from commit e8eeecddcf7d7b442106b92087696d837a2aa619) Signed-off-by: Markus Swarowsky --- .../tfm_secure_partition/dummy_partition/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/tfm_integration/tfm_secure_partition/dummy_partition/CMakeLists.txt b/samples/tfm_integration/tfm_secure_partition/dummy_partition/CMakeLists.txt index 0e335a73028..013332ccb1a 100644 --- a/samples/tfm_integration/tfm_secure_partition/dummy_partition/CMakeLists.txt +++ b/samples/tfm_integration/tfm_secure_partition/dummy_partition/CMakeLists.txt @@ -50,7 +50,7 @@ target_link_libraries(tfm_partitions tfm_app_rot_partition_dp ) -target_compile_definitions(tfm_partition_defs +target_compile_definitions(tfm_config INTERFACE TFM_PARTITION_DUMMY_PARTITION ) From 856a6108754e29b7fef672ab9cf6cfadb185571d Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 14 Dec 2023 12:47:13 +0100 Subject: [PATCH 1351/1623] [nrf fromtree] tfm: Add NS build support for zephyr out-of-tree nordic_nrf platform. Add build of the NS application in the zephyr defined out-of-tree board support for the nordic_nrf platform. Signed-off-by: Joakim Andersson Signed-off-by: Markus Swarowsky (cherry picked from commit 6c927490d0fc0ebc488e09c84b01ef7f924e1827) Signed-off-by: Markus Swarowsky --- .../nordic_nrf/CMakeLists.txt | 16 ++++--- .../nordic_nrf/nrf5340_cpuapp/CMakeLists.txt | 8 +++- .../nordic_nrf/nrf5340_cpuapp/config.cmake | 3 +- .../nordic_nrf/nrf5340_cpuapp/cpuarch.cmake | 4 +- .../nrf5340_cpuapp/ns/cpuarch_ns.cmake | 10 ++++ .../nordic_nrf/nrf9120/CMakeLists.txt | 11 ++++- .../nordic_nrf/nrf9120/config.cmake | 3 +- .../nordic_nrf/nrf9120/cpuarch.cmake | 3 +- .../nordic_nrf/nrf9120/ns/cpuarch_ns.cmake | 10 ++++ .../nordic_nrf/nrf9160/CMakeLists.txt | 11 ++++- .../nordic_nrf/nrf9160/config.cmake | 3 +- .../nordic_nrf/nrf9160/cpuarch.cmake | 4 +- .../nordic_nrf/nrf9160/ns/cpuarch_ns.cmake | 10 ++++ .../nordic_nrf/ns/CMakeLists.txt | 46 +++++++++++++++++++ 14 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/ns/cpuarch_ns.cmake create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9120/ns/cpuarch_ns.cmake create mode 100644 modules/trusted-firmware-m/nordic_nrf/nrf9160/ns/cpuarch_ns.cmake create mode 100644 modules/trusted-firmware-m/nordic_nrf/ns/CMakeLists.txt diff --git a/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt index 39aa2199b47..d75b34a8109 100644 --- a/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt +++ b/modules/trusted-firmware-m/nordic_nrf/CMakeLists.txt @@ -46,14 +46,18 @@ if(BL2) ) endif() +target_sources(tfm_spm + PRIVATE + src/tfm_hal_platform.c +) + if (TFM_PARTITION_PLATFORM) install(FILES include/tfm_ioctl_api.h + include/device_cfg.h + include/RTE_Device.h + include/tfm_ioctl_api.h DESTINATION ${INSTALL_INTERFACE_INC_DIR}) endif() -#========================= tfm_spm ============================================# - -target_sources(tfm_spm - PRIVATE - src/tfm_hal_platform.c -) +install(FILES ns/CMakeLists.txt + DESTINATION ${INSTALL_PLATFORM_NS_DIR}) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt index 279ea385996..35338d542d7 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt +++ b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt @@ -5,8 +5,14 @@ # set(NRF_BOARD_SELECTED True) -set(NRF_SOC_VARIANT nrf5340) add_subdirectory(${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/nrf5340 nrf5340) add_subdirectory(.. common) + +install(FILES ${CMAKE_CURRENT_LIST_DIR}/ns/cpuarch_ns.cmake + DESTINATION ${INSTALL_PLATFORM_NS_DIR} + RENAME cpuarch.cmake) + +install(FILES config.cmake + DESTINATION ${INSTALL_PLATFORM_NS_DIR}) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake index b3e5d74181c..ae50a4846dd 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake +++ b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/config.cmake @@ -4,5 +4,6 @@ # SPDX-License-Identifier: Apache-2.0 # -set(PLATFORM_PATH platform/ext/target/nordic_nrf/) +set(NRF_SOC_VARIANT nrf5340 CACHE STRING "nRF SoC Variant") + include(${PLATFORM_PATH}/common/nrf5340/config.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/cpuarch.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/cpuarch.cmake index 903b23e4cc6..f19d7f43c67 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/cpuarch.cmake +++ b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/cpuarch.cmake @@ -4,4 +4,6 @@ # SPDX-License-Identifier: Apache-2.0 # -include(platform/ext/target/nordic_nrf/common/nrf5340/cpuarch.cmake) +set(PLATFORM_PATH platform/ext/target/nordic_nrf) + +include(${PLATFORM_PATH}/common/nrf5340/cpuarch.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/ns/cpuarch_ns.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/ns/cpuarch_ns.cmake new file mode 100644 index 00000000000..077e88bd37b --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/ns/cpuarch_ns.cmake @@ -0,0 +1,10 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +set(PLATFORM_DIR ${CMAKE_CURRENT_LIST_DIR}) +set(PLATFORM_PATH ${CMAKE_CURRENT_LIST_DIR}) + +include(${CMAKE_CURRENT_LIST_DIR}/common/nrf5340/cpuarch.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt index a84c6fd9fd5..fe2c161200d 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt @@ -5,8 +5,17 @@ # set(NRF_BOARD_SELECTED True) -set(NRF_SOC_VARIANT nrf91) add_subdirectory(${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/nrf91 nrf91) add_subdirectory(.. common) + +install(FILES ${CMAKE_CURRENT_LIST_DIR}/ns/cpuarch_ns.cmake + DESTINATION ${INSTALL_PLATFORM_NS_DIR} + RENAME cpuarch.cmake) + +install(FILES ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/nrf9120/cpuarch.cmake + DESTINATION ${INSTALL_PLATFORM_NS_DIR}/common/nrf9120) + +install(FILES config.cmake + DESTINATION ${INSTALL_PLATFORM_NS_DIR}) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake index 3f58e7b89eb..e858eda3a27 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9120/config.cmake @@ -4,5 +4,6 @@ # SPDX-License-Identifier: Apache-2.0 # -set(PLATFORM_PATH platform/ext/target/nordic_nrf/) +set(NRF_SOC_VARIANT nrf91 CACHE STRING "nRF SoC Variant") + include(${PLATFORM_PATH}/common/nrf91/config.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/cpuarch.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9120/cpuarch.cmake index b34a8ddab1a..9f0886c7a51 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9120/cpuarch.cmake +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9120/cpuarch.cmake @@ -3,5 +3,6 @@ # # SPDX-License-Identifier: Apache-2.0 # +set(PLATFORM_PATH platform/ext/target/nordic_nrf) -include(platform/ext/target/nordic_nrf/common/nrf9120/cpuarch.cmake) +include(${PLATFORM_PATH}/common/nrf9120/cpuarch.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/ns/cpuarch_ns.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9120/ns/cpuarch_ns.cmake new file mode 100644 index 00000000000..c53d684d7e8 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9120/ns/cpuarch_ns.cmake @@ -0,0 +1,10 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +set(PLATFORM_DIR ${CMAKE_CURRENT_LIST_DIR}) +set(PLATFORM_PATH ${CMAKE_CURRENT_LIST_DIR}) + +include(${CMAKE_CURRENT_LIST_DIR}/common/nrf9120/cpuarch.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt index a84c6fd9fd5..ba840c6c8d1 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt @@ -5,8 +5,17 @@ # set(NRF_BOARD_SELECTED True) -set(NRF_SOC_VARIANT nrf91) add_subdirectory(${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/nrf91 nrf91) add_subdirectory(.. common) + +install(FILES ${CMAKE_CURRENT_LIST_DIR}/ns/cpuarch_ns.cmake + DESTINATION ${INSTALL_PLATFORM_NS_DIR} + RENAME cpuarch.cmake) + +install(FILES ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/common/nrf9160/cpuarch.cmake + DESTINATION ${INSTALL_PLATFORM_NS_DIR}/common/nrf9160) + +install(FILES config.cmake + DESTINATION ${INSTALL_PLATFORM_NS_DIR}) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake index 3f58e7b89eb..e858eda3a27 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9160/config.cmake @@ -4,5 +4,6 @@ # SPDX-License-Identifier: Apache-2.0 # -set(PLATFORM_PATH platform/ext/target/nordic_nrf/) +set(NRF_SOC_VARIANT nrf91 CACHE STRING "nRF SoC Variant") + include(${PLATFORM_PATH}/common/nrf91/config.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/cpuarch.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9160/cpuarch.cmake index 228252f0147..f728014d3f7 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9160/cpuarch.cmake +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9160/cpuarch.cmake @@ -4,4 +4,6 @@ # SPDX-License-Identifier: Apache-2.0 # -include(platform/ext/target/nordic_nrf/common/nrf9160/cpuarch.cmake) +set(PLATFORM_PATH platform/ext/target/nordic_nrf) + +include(${PLATFORM_PATH}/common/nrf9160/cpuarch.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/ns/cpuarch_ns.cmake b/modules/trusted-firmware-m/nordic_nrf/nrf9160/ns/cpuarch_ns.cmake new file mode 100644 index 00000000000..902e7fe7ef4 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9160/ns/cpuarch_ns.cmake @@ -0,0 +1,10 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +set(PLATFORM_DIR ${CMAKE_CURRENT_LIST_DIR}) +set(PLATFORM_PATH ${CMAKE_CURRENT_LIST_DIR}) + +include(${CMAKE_CURRENT_LIST_DIR}/common/nrf9160/cpuarch.cmake) diff --git a/modules/trusted-firmware-m/nordic_nrf/ns/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/ns/CMakeLists.txt new file mode 100644 index 00000000000..5bb8cb5bd94 --- /dev/null +++ b/modules/trusted-firmware-m/nordic_nrf/ns/CMakeLists.txt @@ -0,0 +1,46 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA. +# +# SPDX-License-Identifier: Apache-2.0 +# + +cmake_policy(SET CMP0076 NEW) +set(CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}) +set(NRF_BOARD_SELECTED True) + +add_library(platform_ns STATIC) + +set(partition_includes + ${CMAKE_CURRENT_LIST_DIR}/common/${NRF_SOC_VARIANT}/partition + ${CMAKE_BINARY_DIR}/../zephyr/include/generated +) + +set(board_includes + ${CMAKE_BINARY_DIR}/../zephyr/misc/generated/syscalls_links/include + ${ZEPHYR_BASE}/include +) + +target_include_directories(platform_region_defs + INTERFACE + ${partition_includes} +) + +target_include_directories(platform_ns + PUBLIC + ${partition_includes} + ${board_includes} +) + +# Get the value of HAL_NORDIC_PATH +include(${CMAKE_CURRENT_LIST_DIR}/common/core/config_nordic_nrf_spe.cmake) +add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/common/${NRF_SOC_VARIANT} ${NRF_SOC_VARIANT}) + +target_include_directories(platform_ns + PUBLIC + ${CMAKE_CURRENT_LIST_DIR} +) + +target_link_libraries(platform_ns + PUBLIC + platform_region_defs +) From 665488340d1e3b3201d62a413be1d1e583bdd94c Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 14 Dec 2023 11:05:49 +0100 Subject: [PATCH 1352/1623] [nrf fromtree] tfm: Remove TFM_BUILD_NS and update TFM_USE_NS_APP for NS build folder TF-M no longer builds the NS app, but exports build files to api_ns folder and expects the user to build the rest themselves. Remove the option to build the NS app, and update the TFM_USE_NS_APP to look for an output hex file in the tfm_ns folder. Signed-off-by: Joakim Andersson Signed-off-by: Markus Swarowsky (cherry picked from commit f49cbf13ca8ff389bcf857eba542b2bb250a8545) Signed-off-by: Markus Swarowsky --- modules/trusted-firmware-m/CMakeLists.txt | 41 +++++-------------- modules/trusted-firmware-m/Kconfig.tfm | 11 ----- samples/tfm_integration/tfm_psa_test/prj.conf | 1 - .../tfm_regression_test/prj.conf | 1 - 4 files changed, 10 insertions(+), 44 deletions(-) diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index 8cc546883d0..26109bef223 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -51,11 +51,6 @@ if (CONFIG_BUILD_WITH_TFM) else() list(APPEND TFM_CMAKE_ARGS -DBL2=FALSE) endif() - if (CONFIG_TFM_BUILD_NS) - list(APPEND TFM_CMAKE_ARGS -DNS=TRUE) - else() - list(APPEND TFM_CMAKE_ARGS -DNS=FALSE) - endif() if (CONFIG_TFM_ISOLATION_LEVEL) list(APPEND TFM_CMAKE_ARGS -DTFM_ISOLATION_LEVEL=${CONFIG_TFM_ISOLATION_LEVEL}) endif() @@ -185,9 +180,6 @@ if (CONFIG_BUILD_WITH_TFM) set(TFM_INTERFACE_INCLUDE_DIR ${TFM_BINARY_DIR}/api_ns/interface/include) set(TFM_INTERFACE_LIB_DIR ${TFM_BINARY_DIR}/api_ns/interface/lib) - set(TFM_API_NS_PATH ${TFM_BINARY_DIR}/tf-m-tests/app/libtfm_api_ns.a) - set(PLATFORM_NS_FILE ${TFM_BINARY_DIR}/platform/ns/libplatform_ns.a) - if (TFM_PSA_TEST_SUITE) set(PSA_TEST_VAL_FILE ${TFM_BINARY_DIR}/tf-m-tests/app/psa_api_tests/val/val_nspe.a) set(PSA_TEST_PAL_FILE ${TFM_BINARY_DIR}/tf-m-tests/app/psa_api_tests/platform/pal_nspe.a) @@ -208,27 +200,22 @@ if (CONFIG_BUILD_WITH_TFM) set(TFM_S_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_s.bin) set(TFM_S_HEX_FILE ${TFM_BINARY_DIR}/bin/tfm_s.hex) set(TFM_NS_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_ns.bin) - set(TFM_NS_HEX_FILE ${TFM_BINARY_DIR}/bin/tfm_ns.hex) + set(TFM_NS_HEX_FILE ${CMAKE_BINARY_DIR}/tfm_ns/bin/tfm_ns.hex) set(TFM_S_SIGNED_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_s_signed.bin) set(TFM_NS_SIGNED_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_ns_signed.bin) set(TFM_S_NS_SIGNED_BIN_FILE ${TFM_BINARY_DIR}/bin/tfm_s_ns_signed.bin) set(BUILD_BYPRODUCTS - ${TFM_API_NS_PATH} ${PSA_TEST_VAL_FILE} ${PSA_TEST_PAL_FILE} ${PSA_TEST_COMBINE_FILE} - ${PLATFORM_NS_FILE} ${BL2_ELF_FILE} ${BL2_BIN_FILE} ${BL2_HEX_FILE} ${TFM_S_ELF_FILE} ${TFM_S_BIN_FILE} ${TFM_S_HEX_FILE} - ${TFM_NS_BIN_FILE} - ${TFM_NS_HEX_FILE} ${TFM_S_SIGNED_BIN_FILE} - ${TFM_NS_SIGNED_BIN_FILE} ${TFM_S_NS_SIGNED_BIN_FILE} ${TFM_INTERFACE_LIB_DIR}/s_veneers.o @@ -426,25 +413,17 @@ if (CONFIG_BUILD_WITH_TFM) ) endif() - if(NOT CONFIG_TFM_BUILD_NS) - zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_PLATFORM ${TFM_INTERFACE_SOURCE_DIR}/tfm_platform_api.c) - zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_PROTECTED_STORAGE ${TFM_INTERFACE_SOURCE_DIR}/tfm_ps_api.c) - zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_INTERNAL_TRUSTED_STORAGE ${TFM_INTERFACE_SOURCE_DIR}/tfm_its_api.c) - zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_CRYPTO ${TFM_INTERFACE_SOURCE_DIR}/tfm_crypto_api.c) - zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_INITIAL_ATTESTATION ${TFM_INTERFACE_SOURCE_DIR}/tfm_attest_api.c) - zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_FIRMWARE_UPDATE ${TFM_INTERFACE_SOURCE_DIR}/tfm_fwu_api.c) - - zephyr_library_sources(${TFM_INTERFACE_SOURCE_DIR}/tfm_tz_psa_ns_api.c) + zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_PLATFORM ${TFM_INTERFACE_SOURCE_DIR}/tfm_platform_api.c) + zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_PROTECTED_STORAGE ${TFM_INTERFACE_SOURCE_DIR}/tfm_ps_api.c) + zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_INTERNAL_TRUSTED_STORAGE ${TFM_INTERFACE_SOURCE_DIR}/tfm_its_api.c) + zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_CRYPTO ${TFM_INTERFACE_SOURCE_DIR}/tfm_crypto_api.c) + zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_INITIAL_ATTESTATION ${TFM_INTERFACE_SOURCE_DIR}/tfm_attest_api.c) + zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_FIRMWARE_UPDATE ${TFM_INTERFACE_SOURCE_DIR}/tfm_fwu_api.c) - if(CONFIG_SOC_FAMILY_NRF) - zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_PLATFORM ${TFM_INTERFACE_SOURCE_DIR}/tfm_ioctl_core_ns_api.c) - endif() + zephyr_library_sources(${TFM_INTERFACE_SOURCE_DIR}/tfm_tz_psa_ns_api.c) - else() - zephyr_library_link_libraries( - ${PLATFORM_NS_FILE} - ${TFM_API_NS_PATH} - ) + if(CONFIG_SOC_FAMILY_NRF) + zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_PLATFORM ${TFM_INTERFACE_SOURCE_DIR}/tfm_ioctl_core_ns_api.c) endif() target_include_directories(tfm_api PRIVATE diff --git a/modules/trusted-firmware-m/Kconfig.tfm b/modules/trusted-firmware-m/Kconfig.tfm index a0d71328540..f8285da53d6 100644 --- a/modules/trusted-firmware-m/Kconfig.tfm +++ b/modules/trusted-firmware-m/Kconfig.tfm @@ -226,19 +226,8 @@ config TFM_BL2 TFM is designed to run with MCUboot in a certain configuration. This config adds MCUboot to the build - built via TFM's build system. -config TFM_BUILD_NS - bool "Build the TF-M Non-Secure application and libraries" - help - Instruct the TF-M build system to build the TF-M Non-Secure - application and libraries. - - This option is intended for testing purposes only, since this is the - easiest way to build the TF-M regression tests application and test - support libraries in the zephyr build system. - config TFM_USE_NS_APP bool "Use the TF-M Non-Secure application" - depends on TFM_BUILD_NS help The TF-M build system can produce multiple executable files. The main one is the TF-M secure firmware. Optionally the TF-M diff --git a/samples/tfm_integration/tfm_psa_test/prj.conf b/samples/tfm_integration/tfm_psa_test/prj.conf index 3ceca574528..aa35a6c27db 100644 --- a/samples/tfm_integration/tfm_psa_test/prj.conf +++ b/samples/tfm_integration/tfm_psa_test/prj.conf @@ -5,7 +5,6 @@ # CONFIG_BUILD_WITH_TFM=y -CONFIG_TFM_BUILD_NS=y CONFIG_TFM_PROFILE_TYPE_NOT_SET=y CONFIG_QEMU_ICOUNT_SHIFT=1 diff --git a/samples/tfm_integration/tfm_regression_test/prj.conf b/samples/tfm_integration/tfm_regression_test/prj.conf index 6817a7f717b..0a6573f811c 100644 --- a/samples/tfm_integration/tfm_regression_test/prj.conf +++ b/samples/tfm_integration/tfm_regression_test/prj.conf @@ -6,7 +6,6 @@ CONFIG_BUILD_WITH_TFM=y CONFIG_TFM_PROFILE_TYPE_NOT_SET=y -CONFIG_TFM_BUILD_NS=y CONFIG_TFM_USE_NS_APP=y CONFIG_TFM_REGRESSION_S=y CONFIG_TFM_REGRESSION_NS=y From fec869599ef608f2d8b7ed0674fc9cedaf274d39 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 14 Dec 2023 13:13:50 +0100 Subject: [PATCH 1353/1623] [nrf fromtree] tfm: Update TF-M regression tests sample to build NS app Update the TF-M regression tests sample to build the NS app in the tf-m-tests repository as an external project. The regression tests need to provide test configurations to both TF-M an NS app. Duplicate configuration done in the spe/CMakeLists.txt to configure TF-M image for the regression tests. Signed-off-by: Joakim Andersson Signed-off-by: Markus Swarowsky (cherry picked from commit f48467a2a61799b457750758ceeb3a393b841eda) Signed-off-by: Markus Swarowsky --- modules/trusted-firmware-m/CMakeLists.txt | 2 + .../tfm_regression_test/CMakeLists.txt | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index 26109bef223..dc9827db830 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -40,9 +40,11 @@ if (CONFIG_BUILD_WITH_TFM) endif() if (CONFIG_TFM_REGRESSION_S) list(APPEND TFM_CMAKE_ARGS -DTEST_S=ON) + list(APPEND TFM_CMAKE_ARGS -DTFM_S_REG_TEST:BOOL=ON) endif() if (CONFIG_TFM_REGRESSION_NS) list(APPEND TFM_CMAKE_ARGS -DTEST_NS=ON) + list(APPEND TFM_CMAKE_ARGS -DTFM_NS_REG_TEST:BOOL=ON) endif() if (CONFIG_TFM_BL2) list(APPEND TFM_CMAKE_ARGS -DBL2=TRUE) diff --git a/samples/tfm_integration/tfm_regression_test/CMakeLists.txt b/samples/tfm_integration/tfm_regression_test/CMakeLists.txt index 5f34b1c0b26..571bf986206 100644 --- a/samples/tfm_integration/tfm_regression_test/CMakeLists.txt +++ b/samples/tfm_integration/tfm_regression_test/CMakeLists.txt @@ -11,3 +11,51 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(tfm_regression_test) target_sources(app PRIVATE src/main.c) + +get_target_property(TFM_BINARY_DIR tfm TFM_BINARY_DIR) +get_target_property(TFM_NS_BIN_FILE tfm TFM_NS_BIN_FILE) +get_target_property(TFM_NS_HEX_FILE tfm TFM_NS_HEX_FILE) +get_target_property(TFM_NS_SIGNED_BIN_FILE tfm TFM_NS_SIGNED_BIN_FILE) + +set(TFM_TEST_REPO_PATH ${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/../tf-m-tests) + +set(TFM_TEST_DIR "${TFM_TEST_REPO_PATH}/tests_reg/test/secure_regression") +set(TFM_TEST_CONFIG_FILE "${TFM_TEST_REPO_PATH}/tests_reg/test/config/config.cmake") + +set_property(TARGET zephyr_property_target + APPEND PROPERTY TFM_CMAKE_OPTIONS + -DCONFIG_TFM_TEST_DIR=${TFM_TEST_DIR} +) + +set_property(TARGET zephyr_property_target + APPEND PROPERTY TFM_CMAKE_OPTIONS + -DCONFIG_TFM_TEST_CONFIG_FILE=${TFM_TEST_CONFIG_FILE} +) + +include(ExternalProject) + +ExternalProject_Add(tfm_regression_test_app + SOURCE_DIR ${TFM_TEST_REPO_PATH}/tests_reg + BINARY_DIR ${PROJECT_BINARY_DIR}/tfm_ns + CONFIGURE_COMMAND + ${CMAKE_COMMAND} + -G ${CMAKE_GENERATOR} + -S ${TFM_TEST_REPO_PATH}/tests_reg + -B ${PROJECT_BINARY_DIR}/tfm_ns + -DCONFIG_SPE_PATH=${TFM_BINARY_DIR}/api_ns + -DTFM_TOOLCHAIN_FILE=cmake/toolchain_ns_GNUARM.cmake + -DQCBOR_PATH${QCBOR_PATH_TYPE}=${CONFIG_TFM_QCBOR_PATH} + -DCMAKE_BUILD_TYPE=RelWithDebInfo + BUILD_COMMAND ${CMAKE_COMMAND} --build . + INSTALL_COMMAND "" + BUILD_ALWAYS True + USES_TERMINAL_BUILD True + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/tfm_ns + DEPENDS tfm + BUILD_BYPRODUCTS + ${TFM_NS_HEX_FILE} + ${TFM_NS_BIN_FILE} + ${TFM_NS_SIGNED_BIN_FILE} +) + +add_dependencies(app tfm_regression_test_app) From 5c33a8712401f1a57790ca86d130a512b6bfa1ca Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Thu, 14 Dec 2023 18:01:59 +0100 Subject: [PATCH 1354/1623] [nrf fromtree] modules: tf-m: Remove building of PSA arch tests This removed the CMake code that builds the TF-M arch tests within the TF-M CMakeFile. It will be moved to the tfm_integration/tfm_psa_test sample CMakeFile. Signed-off-by: Markus Swarowsky (cherry picked from commit cac7f4058ff3668b67fdb2c972ee9bb2fee1bfb5) Signed-off-by: Markus Swarowsky --- modules/trusted-firmware-m/CMakeLists.txt | 61 ------------------- .../src/zephyr_tfm_psa_test.c | 19 ------ 2 files changed, 80 deletions(-) delete mode 100644 modules/trusted-firmware-m/src/zephyr_tfm_psa_test.c diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index dc9827db830..2ee282905e6 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -65,20 +65,6 @@ if (CONFIG_BUILD_WITH_TFM) if (CONFIG_TFM_PROFILE) list(APPEND TFM_CMAKE_ARGS -DTFM_PROFILE=${CONFIG_TFM_PROFILE}) endif() - if (CONFIG_TFM_PSA_TEST_CRYPTO) - set(TFM_PSA_TEST_SUITE CRYPTO) - elseif (CONFIG_TFM_PSA_TEST_PROTECTED_STORAGE) - set(TFM_PSA_TEST_SUITE PROTECTED_STORAGE) - elseif (CONFIG_TFM_PSA_TEST_INTERNAL_TRUSTED_STORAGE) - set(TFM_PSA_TEST_SUITE INTERNAL_TRUSTED_STORAGE) - elseif (CONFIG_TFM_PSA_TEST_STORAGE) - set(TFM_PSA_TEST_SUITE STORAGE) - elseif (CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION) - set(TFM_PSA_TEST_SUITE INITIAL_ATTESTATION) - endif() - if (DEFINED TFM_PSA_TEST_SUITE) - list(APPEND TFM_CMAKE_ARGS -DTEST_PSA_API=${TFM_PSA_TEST_SUITE}) - endif() if (CONFIG_TFM_CMAKE_BUILD_TYPE_RELEASE) set(TFM_CMAKE_BUILD_TYPE "Release") elseif (CONFIG_TFM_CMAKE_BUILD_TYPE_MINSIZEREL) @@ -182,17 +168,6 @@ if (CONFIG_BUILD_WITH_TFM) set(TFM_INTERFACE_INCLUDE_DIR ${TFM_BINARY_DIR}/api_ns/interface/include) set(TFM_INTERFACE_LIB_DIR ${TFM_BINARY_DIR}/api_ns/interface/lib) - if (TFM_PSA_TEST_SUITE) - set(PSA_TEST_VAL_FILE ${TFM_BINARY_DIR}/tf-m-tests/app/psa_api_tests/val/val_nspe.a) - set(PSA_TEST_PAL_FILE ${TFM_BINARY_DIR}/tf-m-tests/app/psa_api_tests/platform/pal_nspe.a) - set(COMBINE_DIR_STORAGE storage) - set(COMBINE_DIR_PROTECTED_STORAGE storage) - set(COMBINE_DIR_INTERNAL_TRUSTED_STORAGE storage) - set(COMBINE_DIR_CRYPTO crypto) - set(COMBINE_DIR_INITIAL_ATTESTATION initial_attestation) - set(PSA_TEST_COMBINE_FILE ${TFM_BINARY_DIR}/tf-m-tests/app/psa_api_tests/dev_apis/${COMBINE_DIR_${TFM_PSA_TEST_SUITE}}/test_combine.a) - endif() - if(CONFIG_TFM_BL2) set(BL2_ELF_FILE ${TFM_BINARY_DIR}/bin/bl2.elf) set(BL2_BIN_FILE ${TFM_BINARY_DIR}/bin/bl2.bin) @@ -253,26 +228,6 @@ if (CONFIG_BUILD_WITH_TFM) message(FATAL_ERROR "Unsupported ZEPHYR_TOOLCHAIN_VARIANT: ${ZEPHYR_TOOLCHAIN_VARIANT}") endif() - if (CONFIG_TFM_PARTITION_INITIAL_ATTESTATION AND CONFIG_TFM_QCBOR_PATH STREQUAL "") - # TODO: Remove this when QCBOR licensing issues w/t_cose have been resolved, - # or only allow it when 'QCBOR_PATH' is set to a local path where QCBOR has - # been manually downloaded by the user before starting the build. - message(FATAL_ERROR "CONFIG_TFM_PARTITION_INITIAL_ATTESTATION is not available " - "with TF-M 1.7.0 due to licensing issues with a dependent library. This " - "restriction will be removed once licensing issues have been resolved." - ) - endif() - - if (CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION AND CONFIG_TFM_QCBOR_PATH STREQUAL "") - # TODO: Remove this when QCBOR licensing issues w/t_cose have been resolved, - # or only allow it when 'QCBOR_PATH' is set to a local path where QCBOR has - # been manually downloaded by the user before starting the build. - message(FATAL_ERROR "CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION is not available " - "with TF-M 1.7.0 due to licensing issues with a dependent library. This " - "restriction will be removed once licensing issues have been resolved." - ) - endif() - if (CONFIG_TFM_QCBOR_PATH STREQUAL "DOWNLOAD") # Change CMake cache type to string to avoid QCBOR_PATH=/absolute/path/DOWNLOAD being set. set(QCBOR_PATH_TYPE ":STRING") @@ -296,13 +251,6 @@ if (CONFIG_BUILD_WITH_TFM) list(APPEND TFM_CMAKE_ARGS -DMCUBOOT_DATA_SHARING=ON) endif() - if(TFM_PSA_TEST_SUITE) - list(APPEND TFM_CMAKE_ARGS - -DPSA_TOOLCHAIN_FILE=${CMAKE_CURRENT_LIST_DIR}/psa/GNUARM.cmake - -DTOOLCHAIN=INHERIT - ) - endif() - if(CONFIG_FPU AND CONFIG_FP_HARDABI) list(APPEND TFM_CMAKE_ARGS -DCONFIG_TFM_ENABLE_FP=ON) # Note: This is not a cmake option in TF-M. @@ -405,15 +353,6 @@ if (CONFIG_BUILD_WITH_TFM) if (CONFIG_TFM_PARTITION_PLATFORM AND NOT CONFIG_TFM_PARTITION_PLATFORM_CUSTOM_REBOOT) zephyr_library_sources(src/reboot.c) endif() - zephyr_library_sources_ifndef(CONFIG_TFM_PSA_TEST_NONE src/zephyr_tfm_psa_test.c) - - if (TFM_PSA_TEST_SUITE) - zephyr_library_link_libraries( - ${PSA_TEST_VAL_FILE} - ${PSA_TEST_PAL_FILE} - ${PSA_TEST_COMBINE_FILE} - ) - endif() zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_PLATFORM ${TFM_INTERFACE_SOURCE_DIR}/tfm_platform_api.c) zephyr_library_sources_ifdef(CONFIG_TFM_PARTITION_PROTECTED_STORAGE ${TFM_INTERFACE_SOURCE_DIR}/tfm_ps_api.c) diff --git a/modules/trusted-firmware-m/src/zephyr_tfm_psa_test.c b/modules/trusted-firmware-m/src/zephyr_tfm_psa_test.c deleted file mode 100644 index d7d68f9db67..00000000000 --- a/modules/trusted-firmware-m/src/zephyr_tfm_psa_test.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -/** - * \brief This symbol is the entry point provided by the PSA API compliance - * test libraries - */ -extern void val_entry(void); - - -void psa_test(void) -{ - val_entry(); -} From 218bb94a8fda694530bccad0f308ae143362baba Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Thu, 14 Dec 2023 18:04:20 +0100 Subject: [PATCH 1355/1623] [nrf fromtree] samples: tfm_psa_test: Adapt to TF-M split build The sample now builds the psa-arch-tests itself and doesn't rely anymore on the TF-M module CMakeFile. Additionally it will not run the zephyr main.c anymore but therefore only uses the tf-m non-secure application. Signed-off-by: Markus Swarowsky (cherry picked from commit ad9cdf06c4c3021ddaad8721d4621acc9d1d9dec) Signed-off-by: Markus Swarowsky --- .../nordic_nrf/nrf5340_cpuapp/CMakeLists.txt | 5 + .../nordic_nrf/nrf9120/CMakeLists.txt | 4 + .../nordic_nrf/nrf9160/CMakeLists.txt | 4 + .../tfm_psa_test/CMakeLists.txt | 99 ++++++++++++++++++- samples/tfm_integration/tfm_psa_test/prj.conf | 2 + .../tfm_integration/tfm_psa_test/src/main.c | 12 +-- 6 files changed, 114 insertions(+), 12 deletions(-) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt index 35338d542d7..b74620fe2d5 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt +++ b/modules/trusted-firmware-m/nordic_nrf/nrf5340_cpuapp/CMakeLists.txt @@ -16,3 +16,8 @@ install(FILES ${CMAKE_CURRENT_LIST_DIR}/ns/cpuarch_ns.cmake install(FILES config.cmake DESTINATION ${INSTALL_PLATFORM_NS_DIR}) + +install(DIRECTORY ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/nrf5340dk_nrf5340_cpuapp/tests + + DESTINATION ${INSTALL_PLATFORM_NS_DIR} +) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt index fe2c161200d..64fff7cdb86 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9120/CMakeLists.txt @@ -19,3 +19,7 @@ install(FILES ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordi install(FILES config.cmake DESTINATION ${INSTALL_PLATFORM_NS_DIR}) + +install(DIRECTORY ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/nrf9161dk_nrf9161/tests + + DESTINATION ${INSTALL_PLATFORM_NS_DIR}) diff --git a/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt b/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt index ba840c6c8d1..aa2ef831031 100644 --- a/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt +++ b/modules/trusted-firmware-m/nordic_nrf/nrf9160/CMakeLists.txt @@ -19,3 +19,7 @@ install(FILES ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordi install(FILES config.cmake DESTINATION ${INSTALL_PLATFORM_NS_DIR}) + +install(DIRECTORY ${Trusted\ Firmware\ M_SOURCE_DIR}/platform/ext/target/nordic_nrf/nrf9160dk_nrf9160/tests + + DESTINATION ${INSTALL_PLATFORM_NS_DIR}) diff --git a/samples/tfm_integration/tfm_psa_test/CMakeLists.txt b/samples/tfm_integration/tfm_psa_test/CMakeLists.txt index 7692ea3dfd1..0d11c021627 100644 --- a/samples/tfm_integration/tfm_psa_test/CMakeLists.txt +++ b/samples/tfm_integration/tfm_psa_test/CMakeLists.txt @@ -8,10 +8,103 @@ cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(tfm_psa_storage_test) +project(tfm_psa_arch_test) target_sources(app PRIVATE src/main.c) -target_include_directories(app PRIVATE - $/api_ns/interface/include +get_target_property(TFM_BINARY_DIR tfm TFM_BINARY_DIR) +get_target_property(TFM_NS_BIN_FILE tfm TFM_NS_BIN_FILE) +get_target_property(TFM_NS_HEX_FILE tfm TFM_NS_HEX_FILE) +get_target_property(TFM_NS_SIGNED_BIN_FILE tfm TFM_NS_SIGNED_BIN_FILE) + +get_target_property(TFM_TOOLCHAIN_PATH tfm TFM_TOOLCHAIN_PATH) +get_target_property(TFM_TOOLCHAIN_PREFIX tfm TFM_TOOLCHAIN_PREFIX) +get_target_property(TFM_TOOLCHAIN_NS_FILE tfm TFM_TOOLCHAIN_NS_FILE) + +set(TFM_TEST_REPO_PATH ${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/../tf-m-tests) +set(TFM_PSA_ARCHTEST_REPO_PATH ${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/../psa-arch-tests) + +if (CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION AND CONFIG_TFM_QCBOR_PATH STREQUAL "") +# TODO: Remove this when QCBOR licensing issues w/t_cose have been resolved, +# or only allow it when 'QCBOR_PATH' is set to a local path where QCBOR has +# been manually downloaded by the user before starting the build. +message(FATAL_ERROR "CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION is not available " + "with TF-M 2.0.0 due to licensing issues with a dependent library. This " + "restriction will be removed once licensing issues have been resolved." + ) +endif() + + +set(TFM_TEST_DIR "${TFM_TEST_REPO_PATH}/tests_psa_arch/spe/partitions") +set(PSA_ARCH_TESTS_CONFIG_FILE "${TFM_TEST_REPO_PATH}/tests_psa_arch/spe/config/config_test_psa_api.cmake") +if (CONFIG_TFM_PSA_TEST_CRYPTO) +set(TFM_PSA_TEST_SUITE CRYPTO) +elseif (CONFIG_TFM_PSA_TEST_PROTECTED_STORAGE) +set(TFM_PSA_TEST_SUITE PROTECTED_STORAGE) +elseif (CONFIG_TFM_PSA_TEST_INTERNAL_TRUSTED_STORAGE) +set(TFM_PSA_TEST_SUITE INTERNAL_TRUSTED_STORAGE) +elseif (CONFIG_TFM_PSA_TEST_STORAGE) +set(TFM_PSA_TEST_SUITE STORAGE) +elseif (CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION) +set(TFM_PSA_TEST_SUITE INITIAL_ATTESTATION) +endif() + +if (NOT DEFINED TFM_PSA_TEST_SUITE) + message(FATAL_ERROR "Please define witch test suite to run: + CONFIG_TFM_PSA_TEST_CRYPTO + CONFIG_TFM_PSA_TEST_PROTECTED_STORAGE + CONFIG_TFM_PSA_TEST_STORAGE + CONFIG_TFM_PSA_TEST_INITIAL_ATTESTATION") +endif() +set(TEST_PSA_API "${TFM_PSA_TEST_SUITE}") + +set_property(TARGET zephyr_property_target + APPEND PROPERTY TFM_CMAKE_OPTIONS + -DPSA_ARCH_TESTS_PATH=${TFM_PSA_ARCHTEST_REPO_PATH} +) + +set_property(TARGET zephyr_property_target + APPEND PROPERTY TFM_CMAKE_OPTIONS + -DCONFIG_TFM_TEST_DIR=${TFM_TEST_DIR} ) + +set_property(TARGET zephyr_property_target + APPEND PROPERTY TFM_CMAKE_OPTIONS + -DCONFIG_PSA_ARCH_TESTS_CONFIG_FILE=${PSA_ARCH_TESTS_CONFIG_FILE} +) + +set_property(TARGET zephyr_property_target + APPEND PROPERTY TFM_CMAKE_OPTIONS + -DTEST_PSA_API=${TEST_PSA_API} +) + +include(ExternalProject) + +ExternalProject_Add(tfm_psa_arch_test_app + SOURCE_DIR ${TFM_TEST_REPO_PATH}/tests_psa_arch + BINARY_DIR ${PROJECT_BINARY_DIR}/tfm_ns + CONFIGURE_COMMAND + ${CMAKE_COMMAND} + -G ${CMAKE_GENERATOR} + -S ${TFM_TEST_REPO_PATH}/tests_psa_arch + -B ${PROJECT_BINARY_DIR}/tfm_ns + -DCROSS_COMPILE=${TFM_TOOLCHAIN_PATH}/${TFM_TOOLCHAIN_PREFIX} + -DPSA_TOOLCHAIN_FILE=${TFM_BINARY_DIR}/api_ns/cmake/${TFM_TOOLCHAIN_NS_FILE} + -DCONFIG_SPE_PATH=${TFM_BINARY_DIR}/api_ns + -DTFM_TOOLCHAIN_FILE=cmake/${TFM_TOOLCHAIN_NS_FILE} + -DQCBOR_PATH${QCBOR_PATH_TYPE}=${CONFIG_TFM_QCBOR_PATH} + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DTEST_PSA_API=${TEST_PSA_API} + BUILD_COMMAND ${CMAKE_COMMAND} --build . + INSTALL_COMMAND "" + BUILD_ALWAYS True + USES_TERMINAL_BUILD True + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/tfm_ns + DEPENDS tfm + BUILD_BYPRODUCTS + ${TFM_NS_HEX_FILE} + ${TFM_NS_BIN_FILE} + ${TFM_NS_SIGNED_BIN_FILE} +) + +add_dependencies(app tfm_psa_arch_test_app) diff --git a/samples/tfm_integration/tfm_psa_test/prj.conf b/samples/tfm_integration/tfm_psa_test/prj.conf index aa35a6c27db..bab1254229d 100644 --- a/samples/tfm_integration/tfm_psa_test/prj.conf +++ b/samples/tfm_integration/tfm_psa_test/prj.conf @@ -6,7 +6,9 @@ CONFIG_BUILD_WITH_TFM=y CONFIG_TFM_PROFILE_TYPE_NOT_SET=y +CONFIG_TFM_USE_NS_APP=y CONFIG_QEMU_ICOUNT_SHIFT=1 + # Needed for CRYPTO and INITIAL_ATTESTATION CONFIG_MAIN_STACK_SIZE=4096 diff --git a/samples/tfm_integration/tfm_psa_test/src/main.c b/samples/tfm_integration/tfm_psa_test/src/main.c index 232fc505cfd..9d2809fe269 100644 --- a/samples/tfm_integration/tfm_psa_test/src/main.c +++ b/samples/tfm_integration/tfm_psa_test/src/main.c @@ -1,21 +1,15 @@ /* - * Copyright (c) 2021 Nordic Semiconductor ASA. + * Copyright (c) 2023 Nordic Semiconductor ASA. * * SPDX-License-Identifier: Apache-2.0 */ #include -/* Run the PSA test suite */ -void psa_test(void); - int main(void) { -#ifdef CONFIG_TFM_PSA_TEST_NONE - #error "No PSA test suite set. Use Kconfig to enable a test suite.\n" -#else - psa_test(); -#endif + printk("Should not be printed, expected TF-M's NS application to be run instead.\n"); + k_panic(); for (;;) { } From e19049aad109e2f0ba3a9b3c31db04fea475e5ca Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Fri, 15 Dec 2023 10:33:50 +0100 Subject: [PATCH 1356/1623] [nrf fromtree] tfm: Provide properties for selected TF-M toolchain for NS application Provide properties for selected TF-M toolchain so that the NS application will use the same toolchain as TF-M. Signed-off-by: Joakim Andersson Signed-off-by: Markus Swarowsky (cherry picked from commit 3a830433be49df2ddd2e30feac5ce494f9537026) Signed-off-by: Markus Swarowsky --- modules/trusted-firmware-m/CMakeLists.txt | 7 +++++++ samples/tfm_integration/tfm_regression_test/CMakeLists.txt | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index 2ee282905e6..a9036495add 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -228,6 +228,8 @@ if (CONFIG_BUILD_WITH_TFM) message(FATAL_ERROR "Unsupported ZEPHYR_TOOLCHAIN_VARIANT: ${ZEPHYR_TOOLCHAIN_VARIANT}") endif() + string(REPLACE "toolchain" "toolchain_ns" TFM_TOOLCHAIN_NS_FILE ${TFM_TOOLCHAIN_FILE}) + if (CONFIG_TFM_QCBOR_PATH STREQUAL "DOWNLOAD") # Change CMake cache type to string to avoid QCBOR_PATH=/absolute/path/DOWNLOAD being set. set(QCBOR_PATH_TYPE ":STRING") @@ -317,6 +319,11 @@ if (CONFIG_BUILD_WITH_TFM) # This is the root of all TFM build artifacts. set_target_properties(tfm PROPERTIES TFM_BINARY_DIR ${TFM_BINARY_DIR}) + # Set TFM toolchain properties on 'tfm' + set_target_properties(tfm PROPERTIES TFM_TOOLCHAIN_NS_FILE ${TFM_TOOLCHAIN_NS_FILE}) + set_target_properties(tfm PROPERTIES TFM_TOOLCHAIN_PREFIX ${TFM_TOOLCHAIN_PREFIX}) + set_target_properties(tfm PROPERTIES TFM_TOOLCHAIN_PATH ${TFM_TOOLCHAIN_PATH}) + # Set BL2 (MCUboot) executable file paths as target properties on 'tfm' # These files are produced by the TFM build system. if(CONFIG_TFM_BL2) diff --git a/samples/tfm_integration/tfm_regression_test/CMakeLists.txt b/samples/tfm_integration/tfm_regression_test/CMakeLists.txt index 571bf986206..b86eebc4a81 100644 --- a/samples/tfm_integration/tfm_regression_test/CMakeLists.txt +++ b/samples/tfm_integration/tfm_regression_test/CMakeLists.txt @@ -17,6 +17,10 @@ get_target_property(TFM_NS_BIN_FILE tfm TFM_NS_BIN_FILE) get_target_property(TFM_NS_HEX_FILE tfm TFM_NS_HEX_FILE) get_target_property(TFM_NS_SIGNED_BIN_FILE tfm TFM_NS_SIGNED_BIN_FILE) +get_target_property(TFM_TOOLCHAIN_PATH tfm TFM_TOOLCHAIN_PATH) +get_target_property(TFM_TOOLCHAIN_PREFIX tfm TFM_TOOLCHAIN_PREFIX) +get_target_property(TFM_TOOLCHAIN_NS_FILE tfm TFM_TOOLCHAIN_NS_FILE) + set(TFM_TEST_REPO_PATH ${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/../tf-m-tests) set(TFM_TEST_DIR "${TFM_TEST_REPO_PATH}/tests_reg/test/secure_regression") @@ -43,7 +47,8 @@ ExternalProject_Add(tfm_regression_test_app -S ${TFM_TEST_REPO_PATH}/tests_reg -B ${PROJECT_BINARY_DIR}/tfm_ns -DCONFIG_SPE_PATH=${TFM_BINARY_DIR}/api_ns - -DTFM_TOOLCHAIN_FILE=cmake/toolchain_ns_GNUARM.cmake + -DTFM_TOOLCHAIN_FILE=cmake/${TFM_TOOLCHAIN_NS_FILE} + -DCROSS_COMPILE=${TFM_TOOLCHAIN_PATH}/${TFM_TOOLCHAIN_PREFIX} -DQCBOR_PATH${QCBOR_PATH_TYPE}=${CONFIG_TFM_QCBOR_PATH} -DCMAKE_BUILD_TYPE=RelWithDebInfo BUILD_COMMAND ${CMAKE_COMMAND} --build . From 30ef63cee29387d6484082780ff112d296fd37e2 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Mon, 22 Jan 2024 12:28:47 +0100 Subject: [PATCH 1357/1623] [nrf fromtree] modules: tf-m: Remove TFM_TEST_REPO_PATH TF-M 2.0.0 doesn't use the TFM_TEST_REPO_PATH anymore so removing it. Signed-off-by: Markus Swarowsky (cherry picked from commit 8e16b36c18a94b9509b8ca1f5f33188d8ae488a8) Signed-off-by: Markus Swarowsky --- modules/trusted-firmware-m/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index a9036495add..1fcffaa49b4 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -161,7 +161,6 @@ if (CONFIG_BUILD_WITH_TFM) set(TFM_BINARY_DIR ${CMAKE_BINARY_DIR}/tfm) - set(TFM_TEST_REPO_PATH ${ZEPHYR_CURRENT_MODULE_DIR}/../tf-m-tests) set(PSA_ARCH_TESTS_PATH ${ZEPHYR_CURRENT_MODULE_DIR}/../psa-arch-tests) set(TFM_INTERFACE_SOURCE_DIR ${TFM_BINARY_DIR}/api_ns/interface/src) @@ -280,7 +279,6 @@ if (CONFIG_BUILD_WITH_TFM) ${TFM_CMAKE_ARGS} $> -DMBEDCRYPTO_PATH=$>,$,${ZEPHYR_MBEDTLS_MODULE_DIR}> - -DTFM_TEST_REPO_PATH=${TFM_TEST_REPO_PATH} -DPSA_ARCH_TESTS_PATH=${PSA_ARCH_TESTS_PATH} ${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR} WORKING_DIRECTORY ${TFM_BINARY_DIR} From 89b5ce8b44abc743a62194365adf43444bd74aec Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Mon, 22 Jan 2024 13:28:35 +0100 Subject: [PATCH 1358/1623] [nrf fromtree] modules: tf-m: Remove QCBOR path from build QCBOR is only needed by the TF-M tests, as they are not build separately due to the TF-M split build. If we still set it there is a CMake build warning. Signed-off-by: Markus Swarowsky (cherry picked from commit 75fc64969dd08d2949d248f27651cc5aa27857e3) Signed-off-by: Markus Swarowsky --- modules/trusted-firmware-m/CMakeLists.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index 1fcffaa49b4..ea057498d2d 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -229,14 +229,6 @@ if (CONFIG_BUILD_WITH_TFM) string(REPLACE "toolchain" "toolchain_ns" TFM_TOOLCHAIN_NS_FILE ${TFM_TOOLCHAIN_FILE}) - if (CONFIG_TFM_QCBOR_PATH STREQUAL "DOWNLOAD") - # Change CMake cache type to string to avoid QCBOR_PATH=/absolute/path/DOWNLOAD being set. - set(QCBOR_PATH_TYPE ":STRING") - endif() - # Always set QCBOR_PATH, this will make sure that we don't automatically download this - # dependency in the TF-M build system and it will fail when set to an invalid value. - list(APPEND TFM_CMAKE_ARGS -DQCBOR_PATH${QCBOR_PATH_TYPE}=${CONFIG_TFM_QCBOR_PATH}) - if(CONFIG_BOARD_LPCXPRESSO55S69_CPU0) # Supply path to NXP HAL sources used for TF-M build set(TFM_PLATFORM_NXP_HAL_FILE_PATH ${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/platform/ext/target/nxp/) From b2750e2bc91a6e56be98cacacaeb088eb5a2ed19 Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Mon, 22 Jan 2024 14:05:52 +0100 Subject: [PATCH 1359/1623] [nrf fromtree] modules: tf-m: Rename crypto modules to ENABLED The TF-M crypto modules got renames from CRYPTO_XXX_MODULE_DISABLED to CRYPTO_XXX_MODULE_ENABLED Therefore also re naming it in zephyr build integration. Signed-off-by: Markus Swarowsky (cherry picked from commit 49c7f43561e8dcad06df696cb4da65536ad5330f) Signed-off-by: Markus Swarowsky --- modules/trusted-firmware-m/CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index ea057498d2d..2bba4a45c6d 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -152,11 +152,8 @@ if (CONFIG_BUILD_WITH_TFM) foreach(module ${TFM_CRYPTO_MODULES}) if (CONFIG_TFM_${module}_ENABLED) # list(APPEND TFM_ENABLED_CRYPTO_MODULES_ARG ${module}) - set(val "FALSE") - else() - set(val "TRUE") + list(APPEND TFM_CMAKE_ARGS -D${module}_ENABLED=True) endif() - list(APPEND TFM_CMAKE_ARGS -D${module}_DISABLED=${val}) endforeach() set(TFM_BINARY_DIR ${CMAKE_BINARY_DIR}/tfm) From d284b1840048b55b3928465d501e8ed4a6d58097 Mon Sep 17 00:00:00 2001 From: Georgios Vasilakis Date: Thu, 25 Jan 2024 15:38:22 +0100 Subject: [PATCH 1360/1623] [nrf noup] mbedtls: Add PSA_WANT Kconfigs for key types The new Oberon PSA core (1.2.0) uses new PSA_WANT symbols for the ECC and RSA keys. This adds these new Kconfigs without removing the old ones to avoid necessary changes in the configuration of an application. Signed-off-by: Georgios Vasilakis Signed-off-by: Markus Swarowsky --- modules/mbedtls/Kconfig.psa | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 9bfb1c9ee07..6501a07a230 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -133,6 +133,40 @@ config PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY help Elliptic curve public key. + +config PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT + bool "PSA ECC import key pair support" + default y if PSA_WANT_KEY_TYPE_ECC_KEY_PAIR + select PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY + help + Elliptic curve key pair: import for both the private and public key. + +config PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT + bool "PSA ECC export key pair support" + default y if PSA_WANT_KEY_TYPE_ECC_KEY_PAIR + select PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY + help + Elliptic curve key pair: export for both the private and public key. + +config PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE + bool "PSA ECC generate key pair support" + default y if PSA_WANT_KEY_TYPE_ECC_KEY_PAIR + select PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY + help + Elliptic curve key pair: generate for both the private and public key. + +config PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC + bool + default y + depends on PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT || \ + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT || \ + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE + +config PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE + bool + default y + depends on PSA_WANT_KEY_TYPE_ECC_KEY_PAIR + config PSA_WANT_KEY_TYPE_RSA_KEY_PAIR bool "PSA RSA key pair type support" select PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY @@ -144,6 +178,34 @@ config PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY help RSA public key. +config PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT + bool "PSA RSA key pair import key" + default y if PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + select PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + help + RSA key pair: import key for both the private and public key. + +config PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT + bool "PSA RSA key pair export key" + default y if PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + select PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + help + RSA key pair: export key for both the private and public key. + +config PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE + bool "PSA RSA key pair generate key" + default y if PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + select PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + help + RSA key pair: key generation for both the private and public key. + +config PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC + bool + default y + depends on PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT || \ + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT || \ + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE + config PSA_WANT_KEY_TYPE_DH_KEY_PAIR bool "PSA DH key pair type support" select PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY From 746b326eb0caf9c2227e2a9e7aa3479dffea19ca Mon Sep 17 00:00:00 2001 From: Markus Swarowsky Date: Wed, 7 Feb 2024 12:27:48 +0100 Subject: [PATCH 1361/1623] [nrf noup] mbedtls: Add PSA_WANT dependencies to TLS12 algorithm PSA_WANT_ALG_TLS12_PRF and PSA_WANT_ALG_TLS12_PSK_TO_MS rely on HMAC so They should have PSA_WANT_ALG_HMAC as dependency PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS uses SHA-256 so should have PSA_WANT_ALG_SHA_256 as dependency noup as these algorithms don't exist upstream Signed-off-by: Markus Swarowsky --- modules/mbedtls/Kconfig.psa | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index 6501a07a230..e92c0f6ee06 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -498,14 +498,17 @@ config PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 config PSA_WANT_ALG_TLS12_PRF bool prompt "PSA PRF support (TLS1.2)" if !PSA_PROMPTLESS + depends on PSA_WANT_ALG_HMAC config PSA_WANT_ALG_TLS12_PSK_TO_MS bool prompt "PSA TLS 1.2 PSK to MS support" if !PSA_PROMPTLESS + depends on PSA_WANT_ALG_HMAC config PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS bool prompt "PSA TLS 1.2 EC J-PAKE to PMS support" if !PSA_PROMPTLESS + depends on PSA_WANT_ALG_SHA_256 endmenu # PSA Key derivation support From 357dfb7b0e76683231fca51f4634a852f3db48a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Mon, 12 Feb 2024 15:40:17 +0100 Subject: [PATCH 1362/1623] [nrf noup] modules: mbedtls: Disable configurations in Kconfig.tls-generic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixup! [nrf noup] modules: mbedtls: Disable configurations in Kconfig.tls-generic Signed-off-by: Sebastian Bøe Signed-off-by: Markus Swarowsky --- modules/mbedtls/configs/config-tls-generic.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/mbedtls/configs/config-tls-generic.h b/modules/mbedtls/configs/config-tls-generic.h index 7874d0ab029..2d1b53c54fd 100644 --- a/modules/mbedtls/configs/config-tls-generic.h +++ b/modules/mbedtls/configs/config-tls-generic.h @@ -502,8 +502,4 @@ #include "mbedtls/check_config.h" #endif -#if defined(CONFIG_NRF_CC3XX_PLATFORM) -#define MBEDTLS_PLATFORM_ZEROIZE_ALT -#endif - #endif /* MBEDTLS_CONFIG_H */ From 0887fba02af3d0058ce427690785413924a9864c Mon Sep 17 00:00:00 2001 From: Georgios Vasilakis Date: Mon, 12 Feb 2024 14:29:21 +0100 Subject: [PATCH 1363/1623] Revert "[nrf noup] modules: mbedtls: Use psa_util.c only with non-nRF" This reverts commit 5bb619da835338caa595cdfb90453e8f833effaa. Signed-off-by: Georgios Vasilakis Signed-off-by: Markus Swarowsky --- modules/mbedtls/CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/mbedtls/CMakeLists.txt b/modules/mbedtls/CMakeLists.txt index c0b17419a1c..929ea17ecea 100644 --- a/modules/mbedtls/CMakeLists.txt +++ b/modules/mbedtls/CMakeLists.txt @@ -81,6 +81,7 @@ zephyr_interface_library_named(mbedTLS) ${ZEPHYR_CURRENT_MODULE_DIR}/library/platform_util.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/platform.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/poly1305.c + ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_util.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/ripemd160.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/rsa_alt_helpers.c ${ZEPHYR_CURRENT_MODULE_DIR}/library/rsa.c @@ -94,10 +95,6 @@ zephyr_interface_library_named(mbedTLS) zephyr_init.c ) - if (NOT DEFINED ZEPHYR_NRF_MODULE_DIR) - list(APPEND mbedtls_base_src ${ZEPHYR_CURRENT_MODULE_DIR}/library/psa_util.c) - endif() - zephyr_library_sources(${mbedtls_base_src}) zephyr_library_sources_ifdef(CONFIG_MBEDTLS_DEBUG debug.c) From 962eb7320fdb76ffe265d8bab7330ad472cb6f28 Mon Sep 17 00:00:00 2001 From: Georgios Vasilakis Date: Mon, 12 Feb 2024 14:30:23 +0100 Subject: [PATCH 1364/1623] [nrf noup] modules: mbedtls: Add include folders We moved the header files in sdk-mbedtls from the library folder to the include/library folder. This was done to avoid issues when building MbedTLS with the nrf_security module and the Oberon PSA core. The Oberon PSA core provides a subset of these header files and since they are included with quotes we cannot have them in the same directory. This change make the needed adaptions in CMake for the applications that don't use nrf_security. Signed-off-by: Georgios Vasilakis Signed-off-by: Markus Swarowsky --- modules/mbedtls/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/mbedtls/CMakeLists.txt b/modules/mbedtls/CMakeLists.txt index 929ea17ecea..a6277f654b5 100644 --- a/modules/mbedtls/CMakeLists.txt +++ b/modules/mbedtls/CMakeLists.txt @@ -25,6 +25,8 @@ zephyr_interface_library_named(mbedTLS) # Add regular includes target_include_directories(mbedTLS INTERFACE ${ZEPHYR_CURRENT_MODULE_DIR}/include + ${ZEPHYR_CURRENT_MODULE_DIR}/include/library + ${ZEPHYR_CURRENT_MODULE_DIR}/library configs include ) From a8dec43b92d373e00bc33ef957c0c7bc5f6989d1 Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Tue, 19 Dec 2023 15:28:24 +0100 Subject: [PATCH 1365/1623] [nrf fromlist] scripts: Allow using quarantine mechanism with test_plan.py script In twister, applying quarantine is a part of apply_filters() function. However, this function is not called when --load-test is used. Therefore, if one wants to use quarantines in combination with dynamic scope from the test_plan.py script, one has to pass such info through the script. Signed-off-by: Maciej Perkowski Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/66659 --- scripts/ci/test_plan.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/ci/test_plan.py b/scripts/ci/test_plan.py index a2ba406d8ce..26227d570aa 100755 --- a/scripts/ci/test_plan.py +++ b/scripts/ci/test_plan.py @@ -95,7 +95,7 @@ def __repr__(self): class Filters: def __init__(self, modified_files, ignore_path, alt_tags, testsuite_root, - pull_request=False, platforms=[], detailed_test_id=True): + pull_request=False, platforms=[], detailed_test_id=True, quarantine_list=None): self.modified_files = modified_files self.testsuite_root = testsuite_root self.resolved_files = [] @@ -108,6 +108,7 @@ def __init__(self, modified_files, ignore_path, alt_tags, testsuite_root, self.detailed_test_id = detailed_test_id self.ignore_path = ignore_path self.tag_cfg_file = alt_tags + self.quarantine_list = quarantine_list def process(self): self.find_modules() @@ -128,6 +129,9 @@ def get_plan(self, options, integration=False, use_testsuite_root=True): cmd+=["-T", root] if integration: cmd.append("--integration") + if self.quarantine_list: + for q in self.quarantine_list: + cmd += ["--quarantine-list", q] logging.info(" ".join(cmd)) _ = subprocess.call(cmd) @@ -415,6 +419,12 @@ def parse_args(): "testcase.yaml files under here will be processed. May be " "called multiple times. Defaults to the 'samples/' and " "'tests/' directories at the base of the Zephyr tree.") + parser.add_argument( + "--quarantine-list", action="append", metavar="FILENAME", + help="Load list of test scenarios under quarantine. The entries in " + "the file need to correspond to the test scenarios names as in " + "corresponding tests .yaml files. These scenarios " + "will be skipped with quarantine as the reason.") # Include paths in names by default. parser.set_defaults(detailed_test_id=True) @@ -443,7 +453,7 @@ def parse_args(): print("=========") f = Filters(files, args.ignore_path, args.alt_tags, args.testsuite_root, - args.pull_request, args.platform, args.detailed_test_id) + args.pull_request, args.platform, args.detailed_test_id, args.quarantine_list) f.process() # remove dupes and filtered cases From 8cd3e479cb0036748361e284da6bd02a9dd8657d Mon Sep 17 00:00:00 2001 From: Adam Kondraciuk Date: Fri, 16 Feb 2024 09:29:06 +0100 Subject: [PATCH 1366/1623] [nrf fromlist] modules: hal_nordic: nrfx: Fix DPPI support for nRF54L15 Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69079 Add required dppic interconnect files for nRF54L15. Signed-off-by: Adam Kondraciuk --- modules/hal_nordic/nrfx/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/hal_nordic/nrfx/CMakeLists.txt b/modules/hal_nordic/nrfx/CMakeLists.txt index ffd2e9aebc1..71d57814f36 100644 --- a/modules/hal_nordic/nrfx/CMakeLists.txt +++ b/modules/hal_nordic/nrfx/CMakeLists.txt @@ -155,6 +155,7 @@ zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54LX_SKIP_CLOCK_CONFIG NRF_SKIP_C if(CONFIG_SOC_SERIES_NRF54LX AND CONFIG_NRFX_DPPI) zephyr_library_sources(${HELPERS_DIR}/nrfx_gppi_dppi_ppib_lumos.c) + zephyr_library_sources(${NRFX_DIR}/soc/interconnect/dppic_ppib/nrfx_interconnect_dppic_ppib.c) endif() # Get the SVD file for the current SoC From 321387bc4e61b025d861f7d6df08d7e692125e9d Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Fri, 2 Feb 2024 13:56:23 +0100 Subject: [PATCH 1367/1623] [nrf fromtree] ipc: Drain pending work items before deregistering endpoint The work item will attempt to dereference pointers that have been nulled by the backend. To avoid that, wait until all items currently on the queue have been processed. The symptom is a busfault on ARM, and is "fixed" by adding a `k_msleep(1)` right before `ipc_service_deregister_endpoint()`. This will in effect do the same thing as this patch, and allow the scheduler to run the work item on the ipc workqueue. Signed-off-by: Jonathan Rico (cherry picked from commit f24a01e6d1e6804af9ae3fd81850e798076027ff) --- subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c b/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c index dcbff7b360c..5478ece7ee3 100644 --- a/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c +++ b/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c @@ -456,6 +456,7 @@ static int deregister_ept(const struct device *instance, void *token) { struct backend_data_t *data = instance->data; struct ipc_rpmsg_ept *rpmsg_ept; + static struct k_work_sync sync; /* Instance is not ready */ if (atomic_get(&data->state) != STATE_INITED) { @@ -469,6 +470,13 @@ static int deregister_ept(const struct device *instance, void *token) return -ENOENT; } + /* Drain pending work items before tearing down channel. + * + * Note: `k_work_flush` Faults on Cortex-M33 with "illegal use of EPSR" + * if `sync` is not declared static. + */ + k_work_flush(&data->mbox_work, &sync); + rpmsg_destroy_ept(&rpmsg_ept->ep); memset(rpmsg_ept, 0, sizeof(struct ipc_rpmsg_ept)); From 0eae7f0ce51df8a1f2ddb4e0d959d4ccf835a467 Mon Sep 17 00:00:00 2001 From: Aleksander Wasaznik Date: Mon, 12 Feb 2024 16:52:37 +0100 Subject: [PATCH 1368/1623] [nrf fromtree] Bluetooth: Correct `bt_att_create_rsp_pdu` reservation when EATT is enabled When EATT is enabled, bt_att_create_rsp_pdu used to reserve headroom for the SDU header even when responding on the UATT bearer. That subtracted from the room for the ATT payload in the buffers. The remaining buffer size was insufficient to create a PDU of ATT MTU size, since the exchanged local MTU is calculated the with the assumption that the SDU header is not present. This broke the ATT MTU promise, and e.g. our read response will have two bytes fewer than promised. This caused a failure in PTS. The new bt_att_create_rsp_pdu pays attention to the bearer type and only allocates the SDU header on EATT bearers. Signed-off-by: Aleksander Wasaznik (cherry picked from commit 98409830a2738a9a4ed766d52d62b4c07f5609d6) --- subsys/bluetooth/host/att.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index 44862f5bf25..f8e924852e3 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -3007,13 +3007,40 @@ struct net_buf *bt_att_create_pdu(struct bt_conn *conn, uint8_t op, size_t len) struct net_buf *bt_att_create_rsp_pdu(struct bt_att_chan *chan, uint8_t op, size_t len) { - if (len + sizeof(op) > bt_att_mtu(chan)) { - LOG_WRN("ATT channel %p MTU too small for RSP (%u < %u)", - chan, bt_att_mtu(chan), len + sizeof(op)); + size_t headroom; + struct bt_att_hdr *hdr; + struct bt_att_tx_meta_data *data; + struct net_buf *buf; + + ARG_UNUSED(len); + + buf = bt_l2cap_create_pdu_timeout(NULL, 0, BT_ATT_TIMEOUT); + if (!buf) { + LOG_ERR("Unable to allocate buffer for op 0x%02x", op); return NULL; } - return bt_att_chan_create_pdu(chan, op, len); + headroom = BT_L2CAP_BUF_SIZE(0); + + if (bt_att_is_enhanced(chan)) { + headroom += BT_L2CAP_SDU_HDR_SIZE; + } + + net_buf_reserve(buf, headroom); + + data = tx_meta_data_alloc(BT_ATT_TIMEOUT); + if (!data) { + LOG_WRN("Unable to allocate ATT TX meta"); + net_buf_unref(buf); + return NULL; + } + data->att_chan = chan; + bt_att_tx_meta_data(buf) = data; + + hdr = net_buf_add(buf, sizeof(*hdr)); + hdr->code = op; + + return buf; } static void att_reset(struct bt_att *att) From 6d99243f99bd081acf9865bcaf8f7d35b1293682 Mon Sep 17 00:00:00 2001 From: Juha Ylinen Date: Fri, 19 Jan 2024 15:26:33 +0200 Subject: [PATCH 1369/1623] [nrf noup] samples: lwm2m_client: Add support for nRF91x and nRF700x Add support for nRF91x and nRF700x by providing overlay configuration files. Signed-off-by: Juha Ylinen --- samples/net/lwm2m_client/overlay-nrf700x.conf | 68 +++++++++++++++++++ samples/net/lwm2m_client/overlay-nrf91x.conf | 53 +++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 samples/net/lwm2m_client/overlay-nrf700x.conf create mode 100644 samples/net/lwm2m_client/overlay-nrf91x.conf diff --git a/samples/net/lwm2m_client/overlay-nrf700x.conf b/samples/net/lwm2m_client/overlay-nrf700x.conf new file mode 100644 index 00000000000..2409886fe42 --- /dev/null +++ b/samples/net/lwm2m_client/overlay-nrf700x.conf @@ -0,0 +1,68 @@ +# General +CONFIG_MAIN_STACK_SIZE=4096 +CONFIG_ENTROPY_GENERATOR=y +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 + +# Wi-Fi +CONFIG_WIFI=y +CONFIG_WIFI_NRF700X=y +CONFIG_WIFI_MGMT_EXT=y +CONFIG_NRF_WIFI_IF_AUTO_START=n + +# Credentials +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="" + +# WPA +CONFIG_WPA_SUPP=y +CONFIG_WPA_SUPP_LOG_LEVEL_ERR=y + +CONFIG_NET_NATIVE=y +CONFIG_NET_L2_ETHERNET=y +CONFIG_NET_UDP=y +CONFIG_NET_SOCKETS=y +CONFIG_NET_SOCKETS_OFFLOAD=n +CONFIG_NET_BUF_RX_COUNT=18 +CONFIG_NET_BUF_TX_COUNT=18 +CONFIG_NET_DEFAULT_IF_WIFI=y + +# DNS +CONFIG_DNS_RESOLVER=y + +# DHCPv4 +CONFIG_NET_DHCPV4=y +CONFIG_NET_CONFIG_AUTO_INIT=n +CONFIG_NET_CONFIG_NEED_IPV6=n +CONFIG_NET_CONFIG_NEED_IPV4=n + +# Connection manager +CONFIG_NET_CONNECTION_MANAGER=y + +# Zephyr NET Connection Manager Connectivity layer. +CONFIG_L2_WIFI_CONNECTIVITY=y +CONFIG_L2_WIFI_CONNECTIVITY_AUTO_DOWN=n +CONFIG_L2_WIFI_CONNECTIVITY_AUTO_CONNECT=n + +CONFIG_LWM2M_APP_ID="nrf700x" +CONFIG_LWM2M_APP_SERVER="coaps://leshan.eclipseprojects.io:5684" +CONFIG_LWM2M_DNS_SUPPORT=y + +# Enable DTLS support +CONFIG_LWM2M_DTLS_SUPPORT=y +CONFIG_LWM2M_TLS_SESSION_CACHING=y + +# TLS networking +CONFIG_NET_SOCKETS_ENABLE_DTLS=y +CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=4 +CONFIG_NET_SOCKETS_SOCKOPT_TLS=y + +# nRF Security +CONFIG_NRF_SECURITY=y + +# mbedTLS +CONFIG_MBEDTLS=y +CONFIG_MBEDTLS_ENABLE_HEAP=y +CONFIG_MBEDTLS_HEAP_SIZE=120000 +CONFIG_MBEDTLS_RSA_C=y diff --git a/samples/net/lwm2m_client/overlay-nrf91x.conf b/samples/net/lwm2m_client/overlay-nrf91x.conf new file mode 100644 index 00000000000..9597791c10e --- /dev/null +++ b/samples/net/lwm2m_client/overlay-nrf91x.conf @@ -0,0 +1,53 @@ +# Configuration file for nRF91x +# This file is merged with prj.conf in the application folder, and options +# set here will take precedence if they are present in both files. + +# General +CONFIG_MAIN_STACK_SIZE=4096 + +CONFIG_NET_SOCKETS=y +CONFIG_NET_NATIVE=y +CONFIG_NET_SOCKETS_OFFLOAD=y + +CONFIG_NET_CONFIG_MY_IPV6_ADDR="" +CONFIG_NET_CONFIG_PEER_IPV6_ADDR="" +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_CONFIG_MY_IPV4_GW="" + +CONFIG_NET_CONFIG_NEED_IPV6=n +CONFIG_NET_CONFIG_NEED_IPV4=n +CONFIG_NET_CONFIG_AUTO_INIT=n + +# Modem related configurations +CONFIG_NRF_MODEM_LIB_NET_IF=y +CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_DOWN=n +CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_CONNECT=n +CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_START=n +CONFIG_NRF_MODEM_LIB_ON_FAULT_APPLICATION_SPECIFIC=y + +CONFIG_LTE_LINK_CONTROL_LOG_LEVEL_DBG=n +CONFIG_NRF_MODEM_LIB_NET_IF_LOG_LEVEL_DBG=n + +# Disable Duplicate Address Detection (DAD) +# due to not being properly implemented for offloaded interfaces. +CONFIG_NET_IPV6_NBR_CACHE=n +CONFIG_NET_IPV6_MLD=n + +# Zephyr NET Connection Manager and Connectivity layer. +CONFIG_NET_CONNECTION_MANAGER=y +CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=1024 + +CONFIG_LWM2M_APP_ID="nrf91x" +CONFIG_LWM2M_APP_SERVER="coaps://leshan.eclipseprojects.io:5684" +CONFIG_LWM2M_DNS_SUPPORT=y + +## Enable DTLS support +CONFIG_LWM2M_DTLS_SUPPORT=y +CONFIG_LWM2M_TLS_SESSION_CACHING=y +CONFIG_LWM2M_DTLS_CID=y +CONFIG_TLS_CREDENTIALS=y + +## Crypto +CONFIG_OBERON_BACKEND=y +CONFIG_NORDIC_SECURITY_BACKEND=y +CONFIG_MBEDTLS_SHA256_C=y From 815560169829ee2cb7b4aaf89c6e677554402cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Thu, 18 Jan 2024 12:27:56 +0100 Subject: [PATCH 1370/1623] [nrf fromtree] drivers: i2s_nrfx: Generate master clock if pin is connected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The driver uses pinctrl to configure pins instead of nrfx I2S API. Check whether MCK pin was actually connected by pinctrl instead of comparing nrfx_cfg.mck_pin that is always NRF_I2S_PIN_NOT_CONNECTED. This makes it possible for nRF I2S to provide master clock even when operating in I2S Slave mode. Signed-off-by: Tomasz Moń (cherry picked from commit 76e12a33d94bf72d1351171cec1875c64ec93f0c) --- drivers/i2s/i2s_nrfx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/i2s/i2s_nrfx.c b/drivers/i2s/i2s_nrfx.c index e1b3684c4f7..3c5af08e592 100644 --- a/drivers/i2s/i2s_nrfx.c +++ b/drivers/i2s/i2s_nrfx.c @@ -501,7 +501,8 @@ static int i2s_nrfx_configure(const struct device *dev, enum i2s_dir dir, * the MCK output is used), find a suitable clock configuration for it. */ if (nrfx_cfg.mode == NRF_I2S_MODE_MASTER || - nrfx_cfg.mck_pin != NRF_I2S_PIN_NOT_CONNECTED) { + (nrf_i2s_mck_pin_get(drv_cfg->i2s.p_reg) & I2S_PSEL_MCK_CONNECT_Msk) + == I2S_PSEL_MCK_CONNECT_Connected << I2S_PSEL_MCK_CONNECT_Pos) { find_suitable_clock(drv_cfg, &nrfx_cfg, i2s_cfg); /* Unless the PCLK32M source is used with the HFINT oscillator * (which is always available without any additional actions), From ca8cca2745e437d110f673ffece3e90ae4b634a9 Mon Sep 17 00:00:00 2001 From: Adam Wojasinski Date: Thu, 5 Oct 2023 09:09:30 +0200 Subject: [PATCH 1371/1623] [nrf fromtree] drivers: spi: spi_nrfx_spim: Include nrf_clock.h only for nRF5340 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CLOCK HAL header is only needed for nRF5340 SoC. It's used when user wants to configure SPIM instance to 32 Mbps. The HAL checks if is running at 128 MHz as only then 32 Mbps is supported. Signed-off-by: Adam Wojasinski (cherry picked from commit e6bcc986bf2aef30936c4d9c518673ae3cfdfa1a) Signed-off-by: Andrzej Głąbek --- drivers/spi/spi_nrfx_spim.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index fb89f096cca..2b7407ed56c 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -11,8 +11,10 @@ #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 #include #endif -#include +#ifdef CONFIG_SOC_NRF5340_CPUAPP #include +#endif +#include #include #include From 35ca365d5e0eff92254058b3b68cb164c3d44502 Mon Sep 17 00:00:00 2001 From: Adam Wojasinski Date: Thu, 5 Oct 2023 09:15:24 +0200 Subject: [PATCH 1372/1623] [nrf fromtree] drivers: spi: spi_nrfx_spim: Add additional symbol check for frequency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some targets may not have `NRF_SPIM_HAS_32_MHZ_FREQ` or `NRF_SPIM_HAS_16_MHZ_FREQ` symbols but have `NRF_SPIM_HAS_PRESCALER` symbol defined. The symbol informs that target supports 32 MHz and 16 MHz frequencies for SPIM instances. Signed-off-by: Adam Wojasinski (cherry picked from commit 058eebe4797a1ba17a6a9cc2d3a449dddcfce6de) Signed-off-by: Andrzej Głąbek --- drivers/spi/spi_nrfx_spim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index 2b7407ed56c..20aae46b8db 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -71,9 +71,9 @@ static inline uint32_t get_nrf_spim_frequency(uint32_t frequency) { /* Get the highest supported frequency not exceeding the requested one. */ - if (frequency >= MHZ(32) && NRF_SPIM_HAS_32_MHZ_FREQ) { + if (frequency >= MHZ(32) && (NRF_SPIM_HAS_32_MHZ_FREQ || NRF_SPIM_HAS_PRESCALER)) { return MHZ(32); - } else if (frequency >= MHZ(16) && NRF_SPIM_HAS_16_MHZ_FREQ) { + } else if (frequency >= MHZ(16) && (NRF_SPIM_HAS_16_MHZ_FREQ || NRF_SPIM_HAS_PRESCALER)) { return MHZ(16); } else if (frequency >= MHZ(8)) { return MHZ(8); From 0eb931d0ca5844340da7b7dda585c6df8e6ab6bb Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 25 Aug 2023 18:27:52 +0530 Subject: [PATCH 1373/1623] [nrf fromtree] drivers: spi: spi_nrfx_spim: Use generic macro for RAM address check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of assuming only RAM is accessible by EasyDMA, use the generic DMA accessible function. Signed-off-by: Chaitanya Tata (cherry picked from commit 2c0f121727456f01422833b5e7b3ef2a29976a45) Signed-off-by: Andrzej Głąbek --- drivers/spi/spi_nrfx_spim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index 20aae46b8db..acd99264099 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -315,7 +315,8 @@ static void transfer_next_chunk(const struct device *dev) nrfx_err_t result; const uint8_t *tx_buf = ctx->tx_buf; #if (CONFIG_SPI_NRFX_RAM_BUFFER_SIZE > 0) - if (spi_context_tx_buf_on(ctx) && !nrfx_is_in_ram(tx_buf)) { + if (spi_context_tx_buf_on(ctx) && + !nrf_dma_accessible_check(&dev_config->spim.p_reg, tx_buf)) { if (chunk_len > CONFIG_SPI_NRFX_RAM_BUFFER_SIZE) { chunk_len = CONFIG_SPI_NRFX_RAM_BUFFER_SIZE; } From 373db5da8cfeb9469b4bcfb537ff8411f5ed9ca1 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Fri, 25 Aug 2023 17:45:17 +0530 Subject: [PATCH 1374/1623] [nrf fromtree] drivers: spim: Move the length check to beginning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This check has to be done independent of whether RAM is used for buffers or not and depends on device maximum length property. Signed-off-by: Chaitanya Tata (cherry picked from commit 0a1eff8d97f88546d07d4f0715628ffe0f06aaf6) Signed-off-by: Andrzej Głąbek --- drivers/spi/spi_nrfx_spim.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index acd99264099..8a325097caa 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -314,6 +314,11 @@ static void transfer_next_chunk(const struct device *dev) nrfx_spim_xfer_desc_t xfer; nrfx_err_t result; const uint8_t *tx_buf = ctx->tx_buf; + + if (chunk_len > dev_config->max_chunk_len) { + chunk_len = dev_config->max_chunk_len; + } + #if (CONFIG_SPI_NRFX_RAM_BUFFER_SIZE > 0) if (spi_context_tx_buf_on(ctx) && !nrf_dma_accessible_check(&dev_config->spim.p_reg, tx_buf)) { @@ -325,10 +330,6 @@ static void transfer_next_chunk(const struct device *dev) tx_buf = dev_data->buffer; } #endif - if (chunk_len > dev_config->max_chunk_len) { - chunk_len = dev_config->max_chunk_len; - } - dev_data->chunk_len = chunk_len; xfer.p_tx_buffer = tx_buf; From 0a25c054187e9848f5020b94488ad9d46b8259ba Mon Sep 17 00:00:00 2001 From: Marcin Szymczyk Date: Fri, 11 Mar 2022 12:26:24 +0100 Subject: [PATCH 1375/1623] [nrf fromtree] drivers: spi: nrfx: add dependency to PPI for PAN 58 on nRF52832 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While enabling workaround for PAN 58 the PPI driver is used. This requires the nrfx PPI driver to be enabled thus CONFIG_NRFX_PPI Kconfig symbol needs to be set. Jira: NRFX-1616 Signed-off-by: Marcin Szymczyk (cherry picked from commit 2a38230a31c6ef6333444578bc7b5c7e6aad6c52) Signed-off-by: Andrzej Głąbek --- drivers/spi/Kconfig.nrfx | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/spi/Kconfig.nrfx b/drivers/spi/Kconfig.nrfx index c185efa9f8f..611bad822b2 100644 --- a/drivers/spi/Kconfig.nrfx +++ b/drivers/spi/Kconfig.nrfx @@ -54,6 +54,7 @@ config SPI_NRFX_SPIS config SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 depends on SOC_NRF52832 + select NRFX_PPI bool "Allow enabling the SPIM driver despite PAN 58" help Allow enabling the nRF SPI Master with EasyDMA, despite From 74f5e087ed0f60e61d95cfd9bfe15a449af80769 Mon Sep 17 00:00:00 2001 From: Adam Wojasinski Date: Fri, 22 Oct 2021 16:40:18 +0200 Subject: [PATCH 1376/1623] [nrf fromtree] drivers: spi: spi_nrfx_spim: Add support for RX buffer from RAM region MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds support for RX buffer placed by a linker in memory region defined in SPIM devicetree node. The buffer is placed in memory region defined as devicetree node. The memory region node's reference is then stored in `memory-regions` property of SPIM node. Added build time assertion to check if `CONFIG_SPI_NRFX_RAM_BUFFER_SIZE` Kconfig symbol has value greater than 0 when given SPIM node has `memory-region` property. Signed-off-by: Adam Wojasinski (cherry picked from commit ae75a8f73a583967354987be682d9c88c1cad6f5) Signed-off-by: Andrzej Głąbek --- drivers/spi/spi_nrfx_spim.c | 45 +++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index 8a325097caa..95b737d6cf5 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -41,8 +41,9 @@ struct spi_nrfx_data { size_t chunk_len; bool busy; bool initialized; -#if SPI_BUFFER_IN_RAM - uint8_t *buffer; +#ifdef SPI_BUFFER_IN_RAM + uint8_t *tx_buffer; + uint8_t *rx_buffer; #endif #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 bool anomaly_58_workaround_active; @@ -314,27 +315,40 @@ static void transfer_next_chunk(const struct device *dev) nrfx_spim_xfer_desc_t xfer; nrfx_err_t result; const uint8_t *tx_buf = ctx->tx_buf; + uint8_t *rx_buf = ctx->rx_buf; if (chunk_len > dev_config->max_chunk_len) { chunk_len = dev_config->max_chunk_len; } -#if (CONFIG_SPI_NRFX_RAM_BUFFER_SIZE > 0) +#ifdef SPI_BUFFER_IN_RAM if (spi_context_tx_buf_on(ctx) && !nrf_dma_accessible_check(&dev_config->spim.p_reg, tx_buf)) { + if (chunk_len > CONFIG_SPI_NRFX_RAM_BUFFER_SIZE) { chunk_len = CONFIG_SPI_NRFX_RAM_BUFFER_SIZE; } - memcpy(dev_data->buffer, tx_buf, chunk_len); - tx_buf = dev_data->buffer; + memcpy(dev_data->tx_buffer, tx_buf, chunk_len); + tx_buf = dev_data->tx_buffer; + } + + if (spi_context_rx_buf_on(ctx) && + !nrf_dma_accessible_check(&dev_config->spim.p_reg, rx_buf)) { + + if (chunk_len > CONFIG_SPI_NRFX_RAM_BUFFER_SIZE) { + chunk_len = CONFIG_SPI_NRFX_RAM_BUFFER_SIZE; + } + + rx_buf = dev_data->rx_buffer; } #endif + dev_data->chunk_len = chunk_len; xfer.p_tx_buffer = tx_buf; xfer.tx_length = spi_context_tx_buf_on(ctx) ? chunk_len : 0; - xfer.p_rx_buffer = ctx->rx_buf; + xfer.p_rx_buffer = rx_buf; xfer.rx_length = spi_context_rx_buf_on(ctx) ? chunk_len : 0; #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 @@ -378,6 +392,15 @@ static void event_handler(const nrfx_spim_evt_t *p_event, void *p_context) #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 anomaly_58_workaround_clear(dev_data); +#endif +#ifdef SPI_BUFFER_IN_RAM + if (spi_context_rx_buf_on(&dev_data->ctx) && + p_event->xfer_desc.p_rx_buffer != NULL && + p_event->xfer_desc.p_rx_buffer != dev_data->ctx.rx_buf) { + (void)memcpy(dev_data->ctx.rx_buf, + dev_data->rx_buffer, + dev_data->chunk_len); + } #endif spi_context_update_tx(&dev_data->ctx, 1, dev_data->chunk_len); spi_context_update_rx(&dev_data->ctx, 1, dev_data->chunk_len); @@ -606,7 +629,10 @@ static int spi_nrfx_init(const struct device *dev) nrfx_isr, nrfx_spim_##idx##_irq_handler, 0); \ } \ IF_ENABLED(SPI_BUFFER_IN_RAM, \ - (static uint8_t spim_##idx##_buffer \ + (static uint8_t spim_##idx##_tx_buffer \ + [CONFIG_SPI_NRFX_RAM_BUFFER_SIZE] \ + SPIM_MEMORY_SECTION(idx); \ + static uint8_t spim_##idx##_rx_buffer \ [CONFIG_SPI_NRFX_RAM_BUFFER_SIZE] \ SPIM_MEMORY_SECTION(idx);)) \ static struct spi_nrfx_data spi_##idx##_data = { \ @@ -614,7 +640,8 @@ static int spi_nrfx_init(const struct device *dev) SPI_CONTEXT_INIT_SYNC(spi_##idx##_data, ctx), \ SPI_CONTEXT_CS_GPIOS_INITIALIZE(SPIM(idx), ctx) \ IF_ENABLED(SPI_BUFFER_IN_RAM, \ - (.buffer = spim_##idx##_buffer,)) \ + (.tx_buffer = spim_##idx##_tx_buffer, \ + .rx_buffer = spim_##idx##_rx_buffer,)) \ .dev = DEVICE_DT_GET(SPIM(idx)), \ .busy = false, \ }; \ @@ -643,7 +670,7 @@ static int spi_nrfx_init(const struct device *dev) WAKE_PIN_NOT_USED), \ .wake_gpiote = WAKE_GPIOTE_INSTANCE(SPIM(idx)), \ }; \ - BUILD_ASSERT(!DT_NODE_HAS_PROP(SPIM(idx), wake_gpios) || \ + BUILD_ASSERT(!SPIM_HAS_PROP(idx, wake_gpios) || \ !(DT_GPIO_FLAGS(SPIM(idx), wake_gpios) & GPIO_ACTIVE_LOW),\ "WAKE line must be configured as active high"); \ PM_DEVICE_DT_DEFINE(SPIM(idx), spim_nrfx_pm_action); \ From dbefe6d8e0e9e78a80afed834bb8f97320953d3a Mon Sep 17 00:00:00 2001 From: Adam Wojasinski Date: Thu, 16 Nov 2023 12:22:08 +0100 Subject: [PATCH 1377/1623] [nrf fromtree] drivers: spi: nrfx: Update doc for RAM_BUFFER_SIZE Kconfig symbol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update documentation for SPI_NRFX_RAM_BUFFER_SIZE Kconfig symbol to reflect new usage of it. Now the symbol specifies size of RX buffer. The change introducing support for RX buffer placed by a linker in memory region defined in SPIM devicetree node is in a parent commit of that one. Signed-off-by: Adam Wojasinski (cherry picked from commit c88b492842b3021efeb42dd181406c9b30c07c44) Signed-off-by: Andrzej Głąbek --- drivers/spi/Kconfig.nrfx | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/spi/Kconfig.nrfx b/drivers/spi/Kconfig.nrfx index 611bad822b2..0ee1c03065b 100644 --- a/drivers/spi/Kconfig.nrfx +++ b/drivers/spi/Kconfig.nrfx @@ -75,14 +75,20 @@ config SPI_NRFX_RAM_BUFFER_SIZE default 8 depends on SPI_NRFX_SPIM help - SPIM peripherals cannot transmit data directly from flash. Therefore, - a buffer in RAM needs to be provided for each instance of SPI driver - using SPIM peripheral, so that the driver can copy there a chunk of - data from flash and transmit it. - The size is specified in bytes. A size of 0 means that this feature - should be disabled, and the application must then take care of not - supplying buffers located in flash to the driver, otherwise such - transfers will fail. + Because of using EasyDMA, SPIM peripherals cannot use transmit and + receive buffers from all memory locations. They are restricted to + buffers located in certain RAM memories only. Therefore, each SPIM + driver instance needs to use an intermediate local RAM buffer, + to transfer data in chunks not exceeding the size of that buffer, + and to copy those chunks between the local buffer and the one + specified in the transfer request if the latter is not accessible + by EasyDMA. + + This option specifies the size in bytes of such local RAM buffers + for both TX and RX paths. A size of 0 means that this feature should + be disabled and the driver user must take care of not making transfer + requests with buffers not accessible by EasyDMA since such transfers + will fail. config SPI_NRFX_WAKE_TIMEOUT_US int "Maximum time to wait for SPI slave to wake up" From a5fc368218367bf8524e66da20db133678a57556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 28 Nov 2023 13:05:59 +0100 Subject: [PATCH 1378/1623] [nrf fromtree] soc: nrf53: Add implementation of workaround for anomaly 168 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the already available in the tree mechanism of adding assembly instructions right after WFI/WFE to implement the workaround for nRF5340 anomaly 168 (replace the 4 NOP solution used on the network core as it turned out to be insufficient) and provide two related Kconfig options so that users are able to adjust the workaround to their actual needs (disable it entirely or use it in the extended version). Signed-off-by: Andrzej Głąbek (cherry picked from commit 23e15c480ac85ae450fc99e9a75cf04e3f188931) --- soc/arm/nordic_nrf/nrf53/Kconfig.soc | 22 +++++++++++++++++++++- soc/arm/nordic_nrf/nrf53/soc_cpu_idle.h | 10 ++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index f72ae5ab004..b3ca2661675 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -12,13 +12,14 @@ config SOC_NRF5340_CPUAPP select HAS_POWEROFF select SOC_COMPATIBLE_NRF5340_CPUAPP imply SOC_NRF53_RTC_PRETICK + imply SOC_NRF53_ANOMALY_168_WORKAROUND config SOC_NRF5340_CPUNET bool - select ARM_ON_EXIT_CPU_IDLE select SOC_COMPATIBLE_NRF5340_CPUNET imply SOC_NRF53_ANOMALY_160_WORKAROUND_NEEDED imply SOC_NRF53_RTC_PRETICK if !WDT_NRFX + imply SOC_NRF53_ANOMALY_168_WORKAROUND choice prompt "nRF53x MCU Selection" @@ -79,6 +80,25 @@ config SOC_NRF53_RTC_PRETICK_IPC_CH_TO_NET endif +config SOC_NRF53_ANOMALY_168_WORKAROUND + bool "Workaround for nRF5340 anomaly 168" + select ARM_ON_EXIT_CPU_IDLE + help + Indicates that the workaround for the anomaly 168 that affects + the nRF5340 SoC should be applied. + The workaround involves execution of 8 NOP instructions when the CPU + exist its idle state (when the WFI/WFE instruction returns) and it is + enabled by default for both the application and network core. + +config SOC_NRF53_ANOMALY_168_WORKAROUND_FOR_EXECUTION_FROM_RAM + bool "Extend the workaround to execution at 128 MHz from RAM" + depends on SOC_NRF53_ANOMALY_168_WORKAROUND && SOC_NRF5340_CPUAPP + help + Indicates that the anomaly 168 workaround is to be extended to cover + also a specific case when the WFI/WFE instruction is executed at 128 + MHz from RAM. Then, 26 instead of 8 NOP instructions needs to be + executed after WFI/WFE. This extension is not enabled by default. + if SOC_NRF5340_CPUAPP config SOC_DCDC_NRF53X_APP diff --git a/soc/arm/nordic_nrf/nrf53/soc_cpu_idle.h b/soc/arm/nordic_nrf/nrf53/soc_cpu_idle.h index b6cd92ca092..dcb0c73d068 100644 --- a/soc/arm/nordic_nrf/nrf53/soc_cpu_idle.h +++ b/soc/arm/nordic_nrf/nrf53/soc_cpu_idle.h @@ -11,10 +11,16 @@ #if defined(_ASMLANGUAGE) +#if defined(CONFIG_SOC_NRF53_ANOMALY_168_WORKAROUND_FOR_EXECUTION_FROM_RAM) #define SOC_ON_EXIT_CPU_IDLE \ + .rept 26 \ nop; \ + .endr +#elif defined(CONFIG_SOC_NRF53_ANOMALY_168_WORKAROUND) +#define SOC_ON_EXIT_CPU_IDLE \ + .rept 8 \ nop; \ - nop; \ - nop; + .endr +#endif #endif /* _ASMLANGUAGE */ From 415c01affc316187ed9e4f4b1a3212a55c5465de Mon Sep 17 00:00:00 2001 From: Ben Wolsieffer Date: Sat, 30 Dec 2023 15:45:44 -0500 Subject: [PATCH 1379/1623] [nrf fromtree] soc: nrf53: fix building anomaly 168 workaround MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With GCC 12.3 and binutils 2.40, the build fails with: <...>/zephyr/arch/arm/core/cortex_m/cpu_idle.S: Assembler messages: <...>/zephyr/arch/arm/core/cortex_m/cpu_idle.S:51: Error: junk at end of line, first unrecognized character is `n' <...>/zephyr/arch/arm/core/cortex_m/cpu_idle.S:133: Info: macro invoked from here Because the SOC_ON_EXIT_CPU_IDLE macro puts all the statements on a single line, there must be a semicolon after .rept Signed-off-by: Ben Wolsieffer (cherry picked from commit 37352d3d2993f02b26b027b1a3bde11ab2254319) Signed-off-by: Andrzej Głąbek --- soc/arm/nordic_nrf/nrf53/soc_cpu_idle.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/soc/arm/nordic_nrf/nrf53/soc_cpu_idle.h b/soc/arm/nordic_nrf/nrf53/soc_cpu_idle.h index dcb0c73d068..c02c9451419 100644 --- a/soc/arm/nordic_nrf/nrf53/soc_cpu_idle.h +++ b/soc/arm/nordic_nrf/nrf53/soc_cpu_idle.h @@ -13,12 +13,12 @@ #if defined(CONFIG_SOC_NRF53_ANOMALY_168_WORKAROUND_FOR_EXECUTION_FROM_RAM) #define SOC_ON_EXIT_CPU_IDLE \ - .rept 26 \ + .rept 26; \ nop; \ .endr #elif defined(CONFIG_SOC_NRF53_ANOMALY_168_WORKAROUND) #define SOC_ON_EXIT_CPU_IDLE \ - .rept 8 \ + .rept 8; \ nop; \ .endr #endif From d5ea3dcf3e232ec785d4d6dd3633843ee3b79cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Fri, 5 Jan 2024 10:26:59 +0100 Subject: [PATCH 1380/1623] [nrf fromtree] drivers: spi: nrfx: Deactivate CS from thread context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... so that it is possible to use a GPIO expander pin as the CS line. Communication with the expander may involve an operation that cannot be done from the interrupt context (e.g. an I2C transaction). Signed-off-by: Andrzej Głąbek (cherry picked from commit db4344b6591c8a0477d15ebd892a5ccd1d13b1b9) --- drivers/spi/spi_nrfx_spi.c | 4 ++-- drivers/spi/spi_nrfx_spim.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi_nrfx_spi.c b/drivers/spi/spi_nrfx_spi.c index 04d7853d11d..752132fb248 100644 --- a/drivers/spi/spi_nrfx_spi.c +++ b/drivers/spi/spi_nrfx_spi.c @@ -161,8 +161,6 @@ static void finish_transaction(const struct device *dev, int error) struct spi_nrfx_data *dev_data = dev->data; struct spi_context *ctx = &dev_data->ctx; - spi_context_cs_control(ctx, false); - LOG_DBG("Transaction finished with status %d", error); spi_context_complete(ctx, dev, error); @@ -277,6 +275,8 @@ static int transceive(const struct device *dev, /* Clean up the driver state. */ k_sem_reset(&dev_data->ctx.sync); } + + spi_context_cs_control(&dev_data->ctx, false); } spi_context_release(&dev_data->ctx, error); diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index 95b737d6cf5..08012b389c5 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -294,8 +294,6 @@ static void finish_transaction(const struct device *dev, int error) struct spi_nrfx_data *dev_data = dev->data; struct spi_context *ctx = &dev_data->ctx; - spi_context_cs_control(ctx, false); - LOG_DBG("Transaction finished with status %d", error); spi_context_complete(ctx, dev, error); @@ -470,6 +468,8 @@ static int transceive(const struct device *dev, anomaly_58_workaround_clear(dev_data); #endif } + + spi_context_cs_control(&dev_data->ctx, false); } spi_context_release(&dev_data->ctx, error); From bc2740c37c5587c6450d059cdd7d7309451c6cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Wed, 31 Jan 2024 08:11:21 +0100 Subject: [PATCH 1381/1623] [nrf fromtree] drivers: serial: Fix async to interrupt driven adaptation layer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whenever UART_RX_DISABLED event is received module attempts to re-enable receiver since in interrupt driven API receiver is always on. However, it is possible that there is no free buffers and in that case attempt to enable the receiver will fail with -EBUSY. That scenario shall be accepted since the receiver will be re-enabled when at least one buffer will be freed. Given that, -EBUSY return shall be accepted (no assert) and number of pending RX buffer requests shall be reset only on successful enabling. Signed-off-by: Krzysztof Chruściński (cherry picked from commit f6ecad20a1e7ee3c52116cd46c93ac72eccdd3c8) Signed-off-by: Andrzej Głąbek --- drivers/serial/uart_async_to_irq.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/serial/uart_async_to_irq.c b/drivers/serial/uart_async_to_irq.c index 209e8d4f205..e18536449f3 100644 --- a/drivers/serial/uart_async_to_irq.c +++ b/drivers/serial/uart_async_to_irq.c @@ -105,12 +105,15 @@ static void on_rx_buf_req(const struct device *dev, static void on_rx_dis(const struct device *dev, struct uart_async_to_irq_data *data) { if (data->flags & A2I_RX_ENABLE) { - data->rx.pending_buf_req = 0; + int err; - int err = try_rx_enable(dev, data); + err = try_rx_enable(dev, data); + if (err == 0) { + data->rx.pending_buf_req = 0; + } LOG_INST_DBG(get_config(dev)->log, "Reenabling RX from RX_DISABLED (err:%d)", err); - __ASSERT_NO_MSG(err >= 0); + __ASSERT((err >= 0) || (err == -EBUSY), "err: %d", err); return; } From 4d8b300173376e216e6857785bf9bd37d59099f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Tue, 6 Feb 2024 13:15:34 +0100 Subject: [PATCH 1382/1623] [nrf fromtree] drivers: serial: nrfx_uarte: Fix misbehavior due to preemption MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UART_RX_RDY event can be generated from UARTE interrupt or k_timer handler. When ENDRX event occurs then k_timer is stopped (it can be restarted if there is another buffer provided). However, if UARTE interrupt priority is higher than k_timer priority (RTC is used underneath) then k_timer handler may still be executed later. K_timer notifies new bytes based on RXDRDY HW event which is counter by the TIMER (using PPI). It may happen that RXDRDY event arrives due to byte received into RX FIFO but since there is not buffer provided it stays in that FIFO. Given all this, it was possible that RX_RDY event was reported from ENDRX UARTE event, timer was stopped but because UARTE interrupt had higher priority timer handler is executed after UARTE interrupt is handled. In timer handler TIMER counter reports more bytes and calls UART_RX_RDY event with null buffer and non-zero amount of bytes. Fixed by generating UART_RX_RDY event only if RX buffer is not null. Signed-off-by: Krzysztof Chruściński (cherry picked from commit 5db338c035fc3cb246e09ba2d2290369a17d9661) Signed-off-by: Andrzej Głąbek --- drivers/serial/uart_nrfx_uarte.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index 3a62057a47a..6e1ecfadfd8 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -1043,9 +1043,11 @@ static void rx_timeout(struct k_timer *timer) (data->async->rx_timeout_left < data->async->rx_timeout_slab)) { /* rx_timeout us elapsed since last receiving */ - notify_uart_rx_rdy(dev, len); - data->async->rx_offset += len; - data->async->rx_total_user_byte_cnt += len; + if (data->async->rx_buf != NULL) { + notify_uart_rx_rdy(dev, len); + data->async->rx_offset += len; + data->async->rx_total_user_byte_cnt += len; + } } else { data->async->rx_timeout_left -= data->async->rx_timeout_slab; From e6cfb46b441ff1fc57658ee55656ed5b00ab088f Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 23 Jan 2024 21:46:24 +0530 Subject: [PATCH 1383/1623] [nrf fromtree] wifi: shell: Remove duplicate argument count checks Now that we are using the shell macro to enforce argument count check, both mandatory and optional arguments, these additions checks are unnecessary. Signed-off-by: Chaitanya Tata (cherry picked from commit c07d6483044f63a57ea26b65405793d5fa8f5c95) --- subsys/net/l2/wifi/wifi_shell.c | 46 +++++---------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 2b131d4e0fb..823f389decb 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -450,12 +450,6 @@ static int __wifi_args_to_params(size_t argc, char *argv[], char *endptr; int idx = 1; - if (argc < 1) { - print(context.sh, SHELL_WARNING, - "SSID not specified\n"); - return -EINVAL; - } - /* Defaults */ params->band = WIFI_FREQ_BAND_UNKNOWN; params->channel = WIFI_CHANNEL_ANY; @@ -1082,12 +1076,6 @@ static int cmd_wifi_twt_setup_quick(const struct shell *sh, size_t argc, context.sh = sh; - if (argc != 3) { - shell_fprintf(sh, SHELL_WARNING, "Invalid number of arguments\n"); - shell_help(sh); - return -ENOEXEC; - } - /* Sensible defaults */ params.operation = WIFI_TWT_SETUP; params.negotiation_type = WIFI_TWT_INDIVIDUAL; @@ -1136,12 +1124,6 @@ static int cmd_wifi_twt_setup(const struct shell *sh, size_t argc, context.sh = sh; - if (argc != 12) { - shell_fprintf(sh, SHELL_WARNING, "Invalid number of arguments\n"); - shell_help(sh); - return -ENOEXEC; - } - params.operation = WIFI_TWT_SETUP; if (!parse_number(sh, &value, argv[idx++], WIFI_TWT_INDIVIDUAL, @@ -1227,12 +1209,6 @@ static int cmd_wifi_twt_teardown(const struct shell *sh, size_t argc, context.sh = sh; int idx = 1; - if (argc != 5) { - shell_fprintf(sh, SHELL_WARNING, "Invalid number of arguments\n"); - shell_help(sh); - return -ENOEXEC; - } - params.operation = WIFI_TWT_TEARDOWN; if (!parse_number(sh, &value, argv[idx++], WIFI_TWT_INDIVIDUAL, @@ -1705,13 +1681,8 @@ static int cmd_wifi_channel(const struct shell *sh, size_t argc, char *argv[]) int ret; bool do_channel_oper = true; - if (argc > 1) { - channel_info.oper = WIFI_MGMT_SET; - parse_channel_args_to_params(sh, argc, argv, &channel_info, &do_channel_oper); - } else { - shell_fprintf(sh, SHELL_ERROR, "Invalid number of arguments\n"); - return -EINVAL; - } + channel_info.oper = WIFI_MGMT_SET; + parse_channel_args_to_params(sh, argc, argv, &channel_info, &do_channel_oper); if (do_channel_oper) { /* @@ -1827,13 +1798,8 @@ static int cmd_wifi_packet_filter(const struct shell *sh, size_t argc, char *arg int ret; bool do_filter_oper = true; - if (argc > 1) { - packet_filter.oper = WIFI_MGMT_SET; - parse_filter_args_to_params(sh, argc, argv, &packet_filter, &do_filter_oper); - } else { - shell_fprintf(sh, SHELL_ERROR, "Invalid number of arguments\n"); - return -EINVAL; - } + packet_filter.oper = WIFI_MGMT_SET; + parse_filter_args_to_params(sh, argc, argv, &packet_filter, &do_filter_oper); if (do_filter_oper) { /* @@ -2015,7 +1981,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "Set operation example for interface index 1 - set data+management frame filter\n" "wifi packet_filter -i1 -md.\n", cmd_wifi_packet_filter, - 1, 8), + 2, 8), SHELL_CMD_ARG(channel, NULL, "wifi channel setting\n" "This command is used to set the channel when\n" "monitor or TX-Injection mode is enabled\n" @@ -2029,7 +1995,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, "Set operation example for interface index 1 (setting channel 5)\n" "wifi -i1 -c5.\n", cmd_wifi_channel, - 1, 4), + 2, 4), SHELL_CMD_ARG(ps_timeout, NULL, " - PS inactivity timer(in ms).\n", From c66ca8573640c3b7ef986e776beda0736b0d4fd4 Mon Sep 17 00:00:00 2001 From: Sandip Dalvi Date: Sat, 20 Jan 2024 10:25:47 +0530 Subject: [PATCH 1384/1623] [nrf fromtree] net: wifi: add wifi driver version API Add command to query to WiFi driver/firmware revision. The API is expected to return the firmware revision and driver version as a string, and can be used by the user to determine what revision of the WiFi driver is in use. Signed-off-by: Sandip Dalvi (cherry picked from commit 4c7eb600c694a46b0039970ba0bd0ebe3992cd81) --- include/zephyr/net/wifi_mgmt.h | 28 ++++++++++++++++++++++++++++ subsys/net/l2/wifi/wifi_mgmt.c | 16 ++++++++++++++++ subsys/net/l2/wifi/wifi_shell.c | 24 ++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 982184a103b..c287db650cb 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -83,6 +83,8 @@ enum net_request_wifi_cmd { NET_REQUEST_WIFI_CMD_CHANNEL, /** Disconnect a STA from AP */ NET_REQUEST_WIFI_CMD_AP_STA_DISCONNECT, + /** Get Wi-Fi driver and Firmware versions */ + NET_REQUEST_WIFI_CMD_VERSION, NET_REQUEST_WIFI_CMD_MAX }; @@ -165,6 +167,11 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL); NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_STA_DISCONNECT); +#define NET_REQUEST_WIFI_VERSION \ + (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_VERSION) + +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_VERSION); + /** Wi-Fi management events */ enum net_event_wifi_cmd { /** Scan results available */ @@ -236,6 +243,14 @@ enum net_event_wifi_cmd { #define NET_EVENT_WIFI_AP_STA_DISCONNECTED \ (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED) +/** Wi-Fi version */ +struct wifi_version { + /** Driver version */ + const char *drv_version; + /** Firmware version */ + const char *fw_version; +}; + /** * @brief Wi-Fi structure to uniquely identify a band-channel pair */ @@ -824,6 +839,19 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*channel)(const struct device *dev, struct wifi_channel_info *channel); + /** Get Version of WiFi driver and Firmware + * + * The driver that implements the get_version function must not use stack to allocate the + * version information pointers that are returned as params struct members. + * The version pointer parameters should point to a static memory either in ROM (preferred) + * or in RAM. + * + * @param dev Pointer to the device structure for the driver instance + * @param params Version parameters + * + * @return 0 if ok, < 0 if error + */ + int (*get_version)(const struct device *dev, struct wifi_version *params); }; /** Wi-Fi management offload API */ diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 2cfe8e25d89..bc844016fa5 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -703,6 +703,22 @@ static int wifi_channel(uint32_t mgmt_request, struct net_if *iface, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL, wifi_channel); +static int wifi_get_version(uint32_t mgmt_request, struct net_if *iface, + void *data, size_t len) +{ + const struct device *dev = net_if_get_device(iface); + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); + struct wifi_version *ver_params = data; + + if (wifi_mgmt_api == NULL || wifi_mgmt_api->get_version == NULL) { + return -ENOTSUP; + } + + return wifi_mgmt_api->get_version(dev, ver_params); +} + +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_VERSION, wifi_get_version); + #ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface, struct wifi_raw_scan_result *raw_scan_result) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 823f389decb..829f0dc96da 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -1848,6 +1848,27 @@ static int cmd_wifi_packet_filter(const struct shell *sh, size_t argc, char *arg return 0; } +static int cmd_wifi_version(const struct shell *sh, size_t argc, char *argv[]) +{ + struct net_if *iface = net_if_get_first_wifi(); + struct wifi_version version = {0}; + + if (argc > 1) { + shell_fprintf(sh, SHELL_WARNING, "Invalid number of arguments\n"); + return -ENOEXEC; + } + + if (net_mgmt(NET_REQUEST_WIFI_VERSION, iface, &version, sizeof(version))) { + shell_fprintf(sh, SHELL_WARNING, "Failed to get Wi-Fi versions\n"); + return -ENOEXEC; + } + + shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi Driver Version: %s\n", version.drv_version); + shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi Firmware Version: %s\n", version.fw_version); + + return 0; +} + SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n", @@ -1901,6 +1922,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops, ); SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands, + SHELL_CMD_ARG(version, NULL, "Print Wi-Fi Driver and Firmware versions\n", + cmd_wifi_version, + 1, 0), SHELL_CMD(ap, &wifi_cmd_ap, "Access Point mode commands.\n", NULL), SHELL_CMD_ARG(connect, NULL, "Connect to a Wi-Fi AP\n" From a63cb57fd0affde5e55e51d0be690a89fa9eaa76 Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Sat, 27 Jan 2024 16:58:45 +0700 Subject: [PATCH 1385/1623] [nrf fromtree] wifi: shell: introduce local 'sh' variable This commit introduces a local variable 'sh' to store 'context.sh' for use with the 'shell_fprintf' function. By doing so, we avoid the repeated dereferencing of 'context.sh', thereby reducing the code footprint. Signed-off-by: Pisit Sawangvonganan (cherry picked from commit a8a39231e7acc28a0ac92111ac46977482227707) --- subsys/net/l2/wifi/wifi_shell.c | 80 ++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 829f0dc96da..1bda0e1610d 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -184,11 +184,12 @@ static void handle_wifi_raw_scan_result(struct net_mgmt_event_callback *cb) int rssi; int i = 0; uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + const struct shell *sh = context.sh; scan_result++; if (scan_result == 1U) { - print(context.sh, SHELL_NORMAL, + print(sh, SHELL_NORMAL, "\n%-4s | %-13s | %-4s | %-15s | %-15s | %-32s\n", "Num", "Channel (Band)", "RSSI", "BSSID", "Frame length", "Frame Body"); } @@ -197,7 +198,7 @@ static void handle_wifi_raw_scan_result(struct net_mgmt_event_callback *cb) channel = wifi_freq_to_channel(raw->frequency); band = wifi_freq_to_band(raw->frequency); - print(context.sh, SHELL_NORMAL, "%-4d | %-4u (%-6s) | %-4d | %s | %-4d ", + print(sh, SHELL_NORMAL, "%-4d | %-4u (%-6s) | %-4d | %s | %-4d ", scan_result, channel, wifi_band_txt(band), @@ -206,10 +207,10 @@ static void handle_wifi_raw_scan_result(struct net_mgmt_event_callback *cb) sizeof(mac_string_buf)), raw->frame_length); for (i = 0; i < 32; i++) { - print(context.sh, SHELL_NORMAL, "%02X ", *(raw->data + i)); + print(sh, SHELL_NORMAL, "%02X ", *(raw->data + i)); } - print(context.sh, SHELL_NORMAL, "\n"); + print(sh, SHELL_NORMAL, "\n"); } #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ @@ -217,12 +218,13 @@ static void handle_wifi_scan_done(struct net_mgmt_event_callback *cb) { const struct wifi_status *status = (const struct wifi_status *)cb->info; + const struct shell *sh = context.sh; if (status->status) { - print(context.sh, SHELL_WARNING, + print(sh, SHELL_WARNING, "Scan request failed (%d)\n", status->status); } else { - print(context.sh, SHELL_NORMAL, "Scan request done\n"); + print(sh, SHELL_NORMAL, "Scan request done\n"); } scan_result = 0U; @@ -266,47 +268,50 @@ static void print_twt_params(uint8_t dialog_token, uint8_t flow_id, bool trigger, uint32_t twt_wake_interval, uint64_t twt_interval) { - print(context.sh, SHELL_NORMAL, "TWT Dialog token: %d\n", + const struct shell *sh = context.sh; + + print(sh, SHELL_NORMAL, "TWT Dialog token: %d\n", dialog_token); - print(context.sh, SHELL_NORMAL, "TWT flow ID: %d\n", + print(sh, SHELL_NORMAL, "TWT flow ID: %d\n", flow_id); - print(context.sh, SHELL_NORMAL, "TWT negotiation type: %s\n", + print(sh, SHELL_NORMAL, "TWT negotiation type: %s\n", wifi_twt_negotiation_type_txt(negotiation_type)); - print(context.sh, SHELL_NORMAL, "TWT responder: %s\n", + print(sh, SHELL_NORMAL, "TWT responder: %s\n", responder ? "true" : "false"); - print(context.sh, SHELL_NORMAL, "TWT implicit: %s\n", + print(sh, SHELL_NORMAL, "TWT implicit: %s\n", implicit ? "true" : "false"); - print(context.sh, SHELL_NORMAL, "TWT announce: %s\n", + print(sh, SHELL_NORMAL, "TWT announce: %s\n", announce ? "true" : "false"); - print(context.sh, SHELL_NORMAL, "TWT trigger: %s\n", + print(sh, SHELL_NORMAL, "TWT trigger: %s\n", trigger ? "true" : "false"); - print(context.sh, SHELL_NORMAL, "TWT wake interval: %d us\n", + print(sh, SHELL_NORMAL, "TWT wake interval: %d us\n", twt_wake_interval); - print(context.sh, SHELL_NORMAL, "TWT interval: %lld us\n", + print(sh, SHELL_NORMAL, "TWT interval: %lld us\n", twt_interval); - print(context.sh, SHELL_NORMAL, "========================\n"); + print(sh, SHELL_NORMAL, "========================\n"); } static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) { const struct wifi_twt_params *resp = (const struct wifi_twt_params *)cb->info; + const struct shell *sh = context.sh; if (resp->operation == WIFI_TWT_TEARDOWN) { if (resp->teardown_status == WIFI_TWT_TEARDOWN_SUCCESS) { - print(context.sh, SHELL_NORMAL, "TWT teardown succeeded for flow ID %d\n", + print(sh, SHELL_NORMAL, "TWT teardown succeeded for flow ID %d\n", resp->flow_id); } else { - print(context.sh, SHELL_NORMAL, "TWT teardown failed for flow ID %d\n", + print(sh, SHELL_NORMAL, "TWT teardown failed for flow ID %d\n", resp->flow_id); } return; } if (resp->resp_status == WIFI_TWT_RESP_RECEIVED) { - print(context.sh, SHELL_NORMAL, "TWT response: %s\n", + print(sh, SHELL_NORMAL, "TWT response: %s\n", wifi_twt_setup_cmd_txt(resp->setup_cmd)); - print(context.sh, SHELL_NORMAL, "== TWT negotiated parameters ==\n"); + print(sh, SHELL_NORMAL, "== TWT negotiated parameters ==\n"); print_twt_params(resp->dialog_token, resp->flow_id, resp->negotiation_type, @@ -317,7 +322,7 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) resp->setup.twt_wake_interval, resp->setup.twt_interval); } else { - print(context.sh, SHELL_NORMAL, "TWT response timed out\n"); + print(sh, SHELL_NORMAL, "TWT response timed out\n"); } } @@ -325,12 +330,13 @@ static void handle_wifi_ap_enable_result(struct net_mgmt_event_callback *cb) { const struct wifi_status *status = (const struct wifi_status *)cb->info; + const struct shell *sh = context.sh; if (status->status) { - print(context.sh, SHELL_WARNING, + print(sh, SHELL_WARNING, "AP enable request failed (%d)\n", status->status); } else { - print(context.sh, SHELL_NORMAL, "AP enabled\n"); + print(sh, SHELL_NORMAL, "AP enabled\n"); } } @@ -338,12 +344,13 @@ static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb) { const struct wifi_status *status = (const struct wifi_status *)cb->info; + const struct shell *sh = context.sh; if (status->status) { - print(context.sh, SHELL_WARNING, + print(sh, SHELL_WARNING, "AP disable request failed (%d)\n", status->status); } else { - print(context.sh, SHELL_NORMAL, "AP disabled\n"); + print(sh, SHELL_NORMAL, "AP disabled\n"); } k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); @@ -355,10 +362,11 @@ static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) { const struct wifi_ap_sta_info *sta_info = (const struct wifi_ap_sta_info *)cb->info; + const struct shell *sh = context.sh; uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; int i; - print(context.sh, SHELL_NORMAL, "Station connected: %s\n", + print(sh, SHELL_NORMAL, "Station connected: %s\n", net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, mac_string_buf, sizeof(mac_string_buf))); @@ -371,7 +379,7 @@ static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) } } if (i == CONFIG_WIFI_SHELL_MAX_AP_STA) { - print(context.sh, SHELL_WARNING, "No space to store station info: " + print(sh, SHELL_WARNING, "No space to store station info: " "Increase CONFIG_WIFI_SHELL_MAX_AP_STA\n"); } k_mutex_unlock(&wifi_ap_sta_list_lock); @@ -381,9 +389,10 @@ static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb) { const struct wifi_ap_sta_info *sta_info = (const struct wifi_ap_sta_info *)cb->info; + const struct shell *sh = context.sh; uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; - print(context.sh, SHELL_NORMAL, "Station disconnected: %s\n", + print(sh, SHELL_NORMAL, "Station disconnected: %s\n", net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, mac_string_buf, sizeof(mac_string_buf))); @@ -449,6 +458,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[], { char *endptr; int idx = 1; + const struct shell *sh = context.sh; /* Defaults */ params->band = WIFI_FREQ_BAND_UNKNOWN; @@ -459,7 +469,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[], params->ssid = argv[0]; params->ssid_length = strlen(params->ssid); if (params->ssid_length > WIFI_SSID_MAX_LEN) { - print(context.sh, SHELL_WARNING, + print(sh, SHELL_WARNING, "SSID too long (max %d characters)\n", WIFI_SSID_MAX_LEN); return -EINVAL; @@ -477,7 +487,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[], size_t offset = 0; if (*endptr != '\0') { - print(context.sh, SHELL_ERROR, + print(sh, SHELL_ERROR, "Failed to parse channel: %s: endp: %s, err: %s\n", argv[idx], endptr, @@ -520,7 +530,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[], band ? "," : "", wifi_band_txt(all_bands[band])); if (offset >= sizeof(bands_str)) { - print(context.sh, SHELL_ERROR, + print(sh, SHELL_ERROR, "Failed to parse channel: %s: " "band string too long\n", argv[idx]); @@ -535,7 +545,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[], } if (!found) { - print(context.sh, SHELL_ERROR, + print(sh, SHELL_ERROR, "Invalid channel: %ld, checked bands: %s\n", channel, bands_str); @@ -571,7 +581,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[], if (security == WIFI_SECURITY_TYPE_NONE || security == WIFI_SECURITY_TYPE_WPA_PSK) { - print(context.sh, SHELL_ERROR, + print(sh, SHELL_ERROR, "MFP not supported for security type %s\n", wifi_security_txt(security)); return -EINVAL; @@ -589,7 +599,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[], params->psk_length > WIFI_PSK_MAX_LEN) || (params->security == WIFI_SECURITY_TYPE_SAE && params->psk_length > WIFI_SAE_PSWD_MAX_LEN)) { - print(context.sh, SHELL_ERROR, + print(sh, SHELL_ERROR, "Invalid PSK length (%d) for security type %s\n", params->psk_length, wifi_security_txt(params->security)); @@ -969,7 +979,7 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) config.twt_flows[i].trigger, config.twt_flows[i].twt_wake_interval, config.twt_flows[i].twt_interval); - shell_fprintf(context.sh, SHELL_NORMAL, + shell_fprintf(sh, SHELL_NORMAL, "TWT Wake ahead duration : %d us\n", config.twt_flows[i].twt_wake_ahead_duration); } From 69e85ccd9fa312dc8bbef0559ab1924a06d4d915 Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Sat, 27 Jan 2024 23:27:18 +0700 Subject: [PATCH 1386/1623] [nrf fromtree] wifi: shell: move "scan_result" variable into context struct Moved 'scan_result' from a standalone variable into the 'context' struct to enhance code optimization. Signed-off-by: Pisit Sawangvonganan (cherry picked from commit 10939c7a02120e91dc8743ee135a593e0707bd1f) --- subsys/net/l2/wifi/wifi_shell.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 1bda0e1610d..a181315d8c1 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -52,6 +52,7 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); static struct { const struct shell *sh; + uint32_t scan_result; union { struct { @@ -64,8 +65,6 @@ static struct { }; } context; -static uint32_t scan_result; - static struct net_mgmt_event_callback wifi_shell_mgmt_cb; static struct wifi_reg_chan_info chan_info[MAX_REG_CHAN_NUM]; @@ -117,9 +116,9 @@ static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb) (const struct wifi_scan_result *)cb->info; uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; - scan_result++; + context.scan_result++; - if (scan_result == 1U) { + if (context.scan_result == 1U) { print(context.sh, SHELL_NORMAL, "\n%-4s | %-32s %-5s | %-13s | %-4s | %-15s | %-17s | %-8s\n", "Num", "SSID", "(len)", "Chan (Band)", "RSSI", "Security", "BSSID", "MFP"); @@ -127,7 +126,7 @@ static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb) print(context.sh, SHELL_NORMAL, "%-4d | %-32s %-5u | %-4u (%-6s) | %-4d | %-15s | %-17s | %-8s\n", - scan_result, entry->ssid, entry->ssid_length, entry->channel, + context.scan_result, entry->ssid, entry->ssid_length, entry->channel, wifi_band_txt(entry->band), entry->rssi, wifi_security_txt(entry->security), @@ -186,9 +185,9 @@ static void handle_wifi_raw_scan_result(struct net_mgmt_event_callback *cb) uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; const struct shell *sh = context.sh; - scan_result++; + context.scan_result++; - if (scan_result == 1U) { + if (context.scan_result == 1U) { print(sh, SHELL_NORMAL, "\n%-4s | %-13s | %-4s | %-15s | %-15s | %-32s\n", "Num", "Channel (Band)", "RSSI", "BSSID", "Frame length", "Frame Body"); @@ -199,7 +198,7 @@ static void handle_wifi_raw_scan_result(struct net_mgmt_event_callback *cb) band = wifi_freq_to_band(raw->frequency); print(sh, SHELL_NORMAL, "%-4d | %-4u (%-6s) | %-4d | %s | %-4d ", - scan_result, + context.scan_result, channel, wifi_band_txt(band), rssi, @@ -227,7 +226,7 @@ static void handle_wifi_scan_done(struct net_mgmt_event_callback *cb) print(sh, SHELL_NORMAL, "Scan request done\n"); } - scan_result = 0U; + context.scan_result = 0U; } static void handle_wifi_connect_result(struct net_mgmt_event_callback *cb) @@ -2058,7 +2057,7 @@ static int wifi_shell_init(void) context.sh = NULL; context.all = 0U; - scan_result = 0U; + context.scan_result = 0U; net_mgmt_init_event_callback(&wifi_shell_mgmt_cb, wifi_mgmt_event_handler, From 61568b94461cb3e8cc3935c2fb63ead40845be08 Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Sun, 28 Jan 2024 00:21:43 +0700 Subject: [PATCH 1387/1623] [nrf fromtree] wifi: shell: refactor to use PR(...) from "net_shell_private.h" Replaced direct shell_fprintf calls with PR, PR_ERROR, PR_INFO and PR_WARNING macros. This change simplifies the code by using predefined macros. Signed-off-by: Pisit Sawangvonganan (cherry picked from commit 81342132fb9e5950016a255a160e3d8cef8ef459) --- subsys/net/l2/wifi/CMakeLists.txt | 3 + subsys/net/l2/wifi/wifi_shell.c | 486 ++++++++++++++---------------- 2 files changed, 224 insertions(+), 265 deletions(-) diff --git a/subsys/net/l2/wifi/CMakeLists.txt b/subsys/net/l2/wifi/CMakeLists.txt index 445eb56c0a7..aaf825599f0 100644 --- a/subsys/net/l2/wifi/CMakeLists.txt +++ b/subsys/net/l2/wifi/CMakeLists.txt @@ -2,6 +2,9 @@ zephyr_library() zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/net/ip) +zephyr_library_include_directories_ifdef( + CONFIG_NET_L2_WIFI_SHELL ${ZEPHYR_BASE}/subsys/net/lib/shell + ) zephyr_library_compile_definitions_ifdef( CONFIG_NEWLIB_LIBC __LINUX_ERRNO_EXTENSIONS__ ) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index a181315d8c1..bfaa35c9a71 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -27,13 +27,13 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF); #include #include -#include "net_private.h" +#include "net_shell_private.h" #define WIFI_SHELL_MODULE "wifi" #define WIFI_SHELL_MGMT_EVENTS_COMMON (NET_EVENT_WIFI_SCAN_DONE |\ NET_EVENT_WIFI_CONNECT_RESULT |\ - NET_EVENT_WIFI_DISCONNECT_RESULT | \ + NET_EVENT_WIFI_DISCONNECT_RESULT |\ NET_EVENT_WIFI_TWT |\ NET_EVENT_WIFI_RAW_SCAN_RESULT |\ NET_EVENT_WIFI_AP_ENABLE_RESULT |\ @@ -57,9 +57,9 @@ static struct { union { struct { - uint8_t connecting : 1; - uint8_t disconnecting : 1; - uint8_t _unused : 6; + uint8_t connecting: 1; + uint8_t disconnecting: 1; + uint8_t _unused: 6; }; uint8_t all; }; @@ -163,9 +163,9 @@ static enum wifi_frequency_bands wifi_freq_to_band(int frequency) { enum wifi_frequency_bands band = WIFI_FREQ_BAND_2_4_GHZ; - if ((frequency >= 2401) && (frequency <= 2495)) { + if ((frequency >= 2401) && (frequency <= 2495)) { band = WIFI_FREQ_BAND_2_4_GHZ; - } else if ((frequency >= 5170) && (frequency <= 5895)) { + } else if ((frequency >= 5170) && (frequency <= 5895)) { band = WIFI_FREQ_BAND_5_GHZ; } else { band = WIFI_FREQ_BAND_6_GHZ; @@ -452,8 +452,8 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb, } static int __wifi_args_to_params(size_t argc, char *argv[], - struct wifi_connect_req_params *params, - enum wifi_iface_mode iface_mode) + struct wifi_connect_req_params *params, + enum wifi_iface_mode iface_mode) { char *endptr; int idx = 1; @@ -508,14 +508,14 @@ static int __wifi_args_to_params(size_t argc, char *argv[], params->band = WIFI_FREQ_BAND_6_GHZ; break; default: - print(context.sh, SHELL_ERROR, + print(sh, SHELL_ERROR, "Invalid band: %ld\n", channel); return -EINVAL; } } } else { if (channel < 0) { - print(context.sh, SHELL_ERROR, + print(sh, SHELL_ERROR, "Invalid channel: %ld\n", channel); return -EINVAL; } @@ -524,10 +524,10 @@ static int __wifi_args_to_params(size_t argc, char *argv[], if (channel > 0) { for (band = 0; band < ARRAY_SIZE(all_bands); band++) { offset += snprintf(bands_str + offset, - sizeof(bands_str) - offset, - "%s%s", - band ? "," : "", - wifi_band_txt(all_bands[band])); + sizeof(bands_str) - offset, + "%s%s", + band ? "," : "", + wifi_band_txt(all_bands[band])); if (offset >= sizeof(bands_str)) { print(sh, SHELL_ERROR, "Failed to parse channel: %s: " @@ -546,8 +546,8 @@ static int __wifi_args_to_params(size_t argc, char *argv[], if (!found) { print(sh, SHELL_ERROR, "Invalid channel: %ld, checked bands: %s\n", - channel, - bands_str); + channel, + bands_str); return -EINVAL; } @@ -606,7 +606,6 @@ static int __wifi_args_to_params(size_t argc, char *argv[], } } - return 0; } @@ -626,14 +625,13 @@ static int cmd_wifi_connect(const struct shell *sh, size_t argc, if (net_mgmt(NET_REQUEST_WIFI_CONNECT, iface, &cnx_params, sizeof(struct wifi_connect_req_params))) { - shell_fprintf(sh, SHELL_WARNING, - "Connection request failed\n"); + PR_WARNING("Connection request failed\n"); context.connecting = false; return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "Connection requested\n"); + PR("Connection requested\n"); return 0; } @@ -653,23 +651,18 @@ static int cmd_wifi_disconnect(const struct shell *sh, size_t argc, context.disconnecting = false; if (status == -EALREADY) { - shell_fprintf(sh, SHELL_INFO, - "Already disconnected\n"); + PR_INFO("Already disconnected\n"); } else { - shell_fprintf(sh, SHELL_WARNING, - "Disconnect request failed\n"); + PR_WARNING("Disconnect request failed\n"); return -ENOEXEC; } } else { - shell_fprintf(sh, SHELL_NORMAL, - "Disconnect requested\n"); + PR("Disconnect requested\n"); } return 0; } - - static int wifi_scan_args_to_params(const struct shell *sh, size_t argc, char *argv[], @@ -702,7 +695,7 @@ static int wifi_scan_args_to_params(const struct shell *sh, } else if (!strncasecmp(optarg, "active", 6)) { params->scan_type = WIFI_SCAN_TYPE_ACTIVE; } else { - shell_fprintf(sh, SHELL_ERROR, "Invalid scan type %s\n", optarg); + PR_ERROR("Invalid scan type %s\n", optarg); return -ENOEXEC; } @@ -710,7 +703,7 @@ static int wifi_scan_args_to_params(const struct shell *sh, break; case 'b': if (wifi_utils_parse_scan_bands(optarg, ¶ms->bands)) { - shell_fprintf(sh, SHELL_ERROR, "Invalid band value(s)\n"); + PR_ERROR("Invalid band value(s)\n"); return -ENOEXEC; } @@ -720,7 +713,7 @@ static int wifi_scan_args_to_params(const struct shell *sh, val = atoi(optarg); if ((val < 5) || (val > 1000)) { - shell_fprintf(sh, SHELL_ERROR, "Invalid dwell_time_active val\n"); + PR_ERROR("Invalid dwell_time_active val\n"); return -ENOEXEC; } @@ -731,7 +724,7 @@ static int wifi_scan_args_to_params(const struct shell *sh, val = atoi(optarg); if ((val < 10) || (val > 1000)) { - shell_fprintf(sh, SHELL_ERROR, "Invalid dwell_time_passive val\n"); + PR_ERROR("Invalid dwell_time_passive val\n"); return -ENOEXEC; } @@ -742,7 +735,7 @@ static int wifi_scan_args_to_params(const struct shell *sh, if (wifi_utils_parse_scan_ssids(optarg, params->ssids, ARRAY_SIZE(params->ssids))) { - shell_fprintf(sh, SHELL_ERROR, "Invalid SSID(s)\n"); + PR_ERROR("Invalid SSID(s)\n"); return -ENOEXEC; } @@ -752,7 +745,7 @@ static int wifi_scan_args_to_params(const struct shell *sh, val = atoi(optarg); if ((val < 0) || (val > 65535)) { - shell_fprintf(sh, SHELL_ERROR, "Invalid max_bss val\n"); + PR_ERROR("Invalid max_bss val\n"); return -ENOEXEC; } @@ -763,9 +756,7 @@ static int wifi_scan_args_to_params(const struct shell *sh, if (wifi_utils_parse_scan_chan(optarg, params->band_chan, ARRAY_SIZE(params->band_chan))) { - shell_fprintf(sh, - SHELL_ERROR, - "Invalid band or channel value(s)\n"); + PR_ERROR("Invalid band or channel value(s)\n"); return -ENOEXEC; } @@ -778,8 +769,8 @@ static int wifi_scan_args_to_params(const struct shell *sh, break; case '?': default: - shell_fprintf(sh, SHELL_ERROR, "Invalid option or option usage: %s\n", - argv[opt_index + 1]); + PR_ERROR("Invalid option or option usage: %s\n", + argv[opt_index + 1]); return -ENOEXEC; } } @@ -803,23 +794,23 @@ static int cmd_wifi_scan(const struct shell *sh, size_t argc, char *argv[]) shell_help(sh); return -ENOEXEC; } else if (!opt_num) { - shell_fprintf(sh, SHELL_WARNING, "No valid option(s) found\n"); + PR_WARNING("No valid option(s) found\n"); do_scan = false; } } if (do_scan) { if (net_mgmt(NET_REQUEST_WIFI_SCAN, iface, ¶ms, sizeof(params))) { - shell_fprintf(sh, SHELL_WARNING, "Scan request failed\n"); + PR_WARNING("Scan request failed\n"); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "Scan requested\n"); + PR("Scan requested\n"); return 0; } - shell_fprintf(sh, SHELL_WARNING, "Scan not initiated\n"); + PR_WARNING("Scan not initiated\n"); return -ENOEXEC; } @@ -831,43 +822,37 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[]) context.sh = sh; if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &status, - sizeof(struct wifi_iface_status))) { - shell_fprintf(sh, SHELL_WARNING, "Status request failed\n"); + sizeof(struct wifi_iface_status))) { + PR_WARNING("Status request failed\n"); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "Status: successful\n"); - shell_fprintf(sh, SHELL_NORMAL, "==================\n"); - shell_fprintf(sh, SHELL_NORMAL, "State: %s\n", wifi_state_txt(status.state)); + PR("Status: successful\n"); + PR("==================\n"); + PR("State: %s\n", wifi_state_txt(status.state)); if (status.state >= WIFI_STATE_ASSOCIATED) { uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; - shell_fprintf(sh, SHELL_NORMAL, "Interface Mode: %s\n", - wifi_mode_txt(status.iface_mode)); - shell_fprintf(sh, SHELL_NORMAL, "Link Mode: %s\n", - wifi_link_mode_txt(status.link_mode)); - shell_fprintf(sh, SHELL_NORMAL, "SSID: %.32s\n", status.ssid); - shell_fprintf(sh, SHELL_NORMAL, "BSSID: %s\n", - net_sprint_ll_addr_buf(status.bssid, + PR("Interface Mode: %s\n", wifi_mode_txt(status.iface_mode)); + PR("Link Mode: %s\n", wifi_link_mode_txt(status.link_mode)); + PR("SSID: %.32s\n", status.ssid); + PR("BSSID: %s\n", + net_sprint_ll_addr_buf(status.bssid, WIFI_MAC_ADDR_LEN, mac_string_buf, - sizeof(mac_string_buf)) - ); - shell_fprintf(sh, SHELL_NORMAL, "Band: %s\n", - wifi_band_txt(status.band)); - shell_fprintf(sh, SHELL_NORMAL, "Channel: %d\n", status.channel); - shell_fprintf(sh, SHELL_NORMAL, "Security: %s\n", - wifi_security_txt(status.security)); - shell_fprintf(sh, SHELL_NORMAL, "MFP: %s\n", - wifi_mfp_txt(status.mfp)); + sizeof(mac_string_buf))); + PR("Band: %s\n", wifi_band_txt(status.band)); + PR("Channel: %d\n", status.channel); + PR("Security: %s\n", wifi_security_txt(status.security)); + PR("MFP: %s\n", wifi_mfp_txt(status.mfp)); if (status.iface_mode == WIFI_MODE_INFRA) { - shell_fprintf(sh, SHELL_NORMAL, "RSSI: %d\n", status.rssi); + PR("RSSI: %d\n", status.rssi); } - shell_fprintf(sh, SHELL_NORMAL, "Beacon Interval: %d\n", status.beacon_interval); - shell_fprintf(sh, SHELL_NORMAL, "DTIM: %d\n", status.dtim_period); - shell_fprintf(sh, SHELL_NORMAL, "TWT: %s\n", - status.twt_capable ? "Supported" : "Not supported"); + PR("Beacon Interval: %d\n", status.beacon_interval); + PR("DTIM: %d\n", status.dtim_period); + PR("TWT: %s\n", + status.twt_capable ? "Supported" : "Not supported"); } return 0; @@ -876,24 +861,23 @@ static int cmd_wifi_status(const struct shell *sh, size_t argc, char *argv[]) #if defined(CONFIG_NET_STATISTICS_WIFI) && \ defined(CONFIG_NET_STATISTICS_USER_API) static void print_wifi_stats(struct net_if *iface, struct net_stats_wifi *data, - const struct shell *sh) + const struct shell *sh) { - shell_fprintf(sh, SHELL_NORMAL, "Statistics for Wi-Fi interface %p [%d]\n", iface, - net_if_get_by_iface(iface)); - - shell_fprintf(sh, SHELL_NORMAL, "Bytes received : %u\n", data->bytes.received); - shell_fprintf(sh, SHELL_NORMAL, "Bytes sent : %u\n", data->bytes.sent); - shell_fprintf(sh, SHELL_NORMAL, "Packets received : %u\n", data->pkts.rx); - shell_fprintf(sh, SHELL_NORMAL, "Packets sent : %u\n", data->pkts.tx); - shell_fprintf(sh, SHELL_NORMAL, "Receive errors : %u\n", data->errors.rx); - shell_fprintf(sh, SHELL_NORMAL, "Send errors : %u\n", data->errors.tx); - shell_fprintf(sh, SHELL_NORMAL, "Bcast received : %u\n", data->broadcast.rx); - shell_fprintf(sh, SHELL_NORMAL, "Bcast sent : %u\n", data->broadcast.tx); - shell_fprintf(sh, SHELL_NORMAL, "Mcast received : %u\n", data->multicast.rx); - shell_fprintf(sh, SHELL_NORMAL, "Mcast sent : %u\n", data->multicast.tx); - shell_fprintf(sh, SHELL_NORMAL, "Beacons received : %u\n", data->sta_mgmt.beacons_rx); - shell_fprintf(sh, SHELL_NORMAL, "Beacons missed : %u\n", - data->sta_mgmt.beacons_miss); + PR("Statistics for Wi-Fi interface %p [%d]\n", iface, + net_if_get_by_iface(iface)); + + PR("Bytes received : %u\n", data->bytes.received); + PR("Bytes sent : %u\n", data->bytes.sent); + PR("Packets received : %u\n", data->pkts.rx); + PR("Packets sent : %u\n", data->pkts.tx); + PR("Receive errors : %u\n", data->errors.rx); + PR("Send errors : %u\n", data->errors.tx); + PR("Bcast received : %u\n", data->broadcast.rx); + PR("Bcast sent : %u\n", data->broadcast.tx); + PR("Mcast received : %u\n", data->multicast.rx); + PR("Mcast sent : %u\n", data->multicast.tx); + PR("Beacons received : %u\n", data->sta_mgmt.beacons_rx); + PR("Beacons missed : %u\n", data->sta_mgmt.beacons_miss); } #endif /* CONFIG_NET_STATISTICS_WIFI && CONFIG_NET_STATISTICS_USER_API */ @@ -914,7 +898,7 @@ static int cmd_wifi_stats(const struct shell *sh, size_t argc, char *argv[]) ARG_UNUSED(argc); ARG_UNUSED(argv); - shell_fprintf(sh, SHELL_INFO, "Set %s to enable %s support.\n", + PR_INFO("Set %s to enable %s support.\n", "CONFIG_NET_STATISTICS_WIFI and CONFIG_NET_STATISTICS_USER_API", "statistics"); #endif /* CONFIG_NET_STATISTICS_WIFI && CONFIG_NET_STATISTICS_USER_API */ @@ -930,7 +914,7 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) context.sh = sh; if (argc > 2) { - shell_fprintf(sh, SHELL_WARNING, "Invalid number of arguments\n"); + PR_WARNING("Invalid number of arguments\n"); return -ENOEXEC; } @@ -939,33 +923,32 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) if (net_mgmt(NET_REQUEST_WIFI_PS_CONFIG, iface, &config, sizeof(config))) { - shell_fprintf(sh, SHELL_WARNING, "Failed to get PS config\n"); + PR_WARNING("Failed to get PS config\n"); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "PS status: %s\n", - wifi_ps_txt(config.ps_params.enabled)); + PR("PS status: %s\n", + wifi_ps_txt(config.ps_params.enabled)); if (config.ps_params.enabled) { - shell_fprintf(sh, SHELL_NORMAL, "PS mode: %s\n", - wifi_ps_mode_txt(config.ps_params.mode)); + PR("PS mode: %s\n", + wifi_ps_mode_txt(config.ps_params.mode)); } - shell_fprintf(sh, SHELL_NORMAL, "PS listen_interval: %d\n", - config.ps_params.listen_interval); + PR("PS listen_interval: %d\n", + config.ps_params.listen_interval); - shell_fprintf(sh, SHELL_NORMAL, "PS wake up mode: %s\n", - config.ps_params.wakeup_mode ? "Listen interval" : "DTIM"); + PR("PS wake up mode: %s\n", + config.ps_params.wakeup_mode ? "Listen interval" : "DTIM"); if (config.ps_params.timeout_ms) { - shell_fprintf(sh, SHELL_NORMAL, "PS timeout: %d ms\n", - config.ps_params.timeout_ms); + PR("PS timeout: %d ms\n", + config.ps_params.timeout_ms); } else { - shell_fprintf(sh, SHELL_NORMAL, "PS timeout: disabled\n"); + PR("PS timeout: disabled\n"); } - if (config.num_twt_flows == 0) { - shell_fprintf(sh, SHELL_NORMAL, "No TWT flows\n"); + PR("No TWT flows\n"); } else { for (int i = 0; i < config.num_twt_flows; i++) { print_twt_params( @@ -978,9 +961,8 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) config.twt_flows[i].trigger, config.twt_flows[i].twt_wake_interval, config.twt_flows[i].twt_interval); - shell_fprintf(sh, SHELL_NORMAL, - "TWT Wake ahead duration : %d us\n", - config.twt_flows[i].twt_wake_ahead_duration); + PR("TWT Wake ahead duration : %d us\n", + config.twt_flows[i].twt_wake_ahead_duration); } } return 0; @@ -991,21 +973,20 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) } else if (!strncasecmp(argv[1], "off", 3)) { params.enabled = WIFI_PS_DISABLED; } else { - shell_fprintf(sh, SHELL_WARNING, "Invalid argument\n"); + PR_WARNING("Invalid argument\n"); return -ENOEXEC; } params.type = WIFI_PS_PARAM_STATE; if (net_mgmt(NET_REQUEST_WIFI_PS, iface, ¶ms, sizeof(params))) { - shell_fprintf(sh, SHELL_WARNING, - "PS %s failed. Reason: %s\n", - params.enabled ? "enable" : "disable", - wifi_ps_get_config_err_code_str(params.fail_reason)); + PR_WARNING("PS %s failed. Reason: %s\n", + params.enabled ? "enable" : "disable", + wifi_ps_get_config_err_code_str(params.fail_reason)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "%s\n", wifi_ps_txt(params.enabled)); + PR("%s\n", wifi_ps_txt(params.enabled)); return 0; } @@ -1022,20 +1003,20 @@ static int cmd_wifi_ps_mode(const struct shell *sh, size_t argc, char *argv[]) } else if (!strncasecmp(argv[1], "WMM", 3)) { params.mode = WIFI_PS_MODE_WMM; } else { - shell_fprintf(sh, SHELL_WARNING, "Invalid PS mode\n"); + PR_WARNING("Invalid PS mode\n"); return -ENOEXEC; } params.type = WIFI_PS_PARAM_MODE; if (net_mgmt(NET_REQUEST_WIFI_PS, iface, ¶ms, sizeof(params))) { - shell_fprintf(sh, SHELL_WARNING, "%s failed Reason : %s\n", - wifi_ps_mode_txt(params.mode), - wifi_ps_get_config_err_code_str(params.fail_reason)); + PR_WARNING("%s failed Reason : %s\n", + wifi_ps_mode_txt(params.mode), + wifi_ps_get_config_err_code_str(params.fail_reason)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "%s\n", wifi_ps_mode_txt(params.mode)); + PR("%s\n", wifi_ps_mode_txt(params.mode)); return 0; } @@ -1060,23 +1041,22 @@ static int cmd_wifi_ps_timeout(const struct shell *sh, size_t argc, char *argv[] params.type = WIFI_PS_PARAM_TIMEOUT; if (net_mgmt(NET_REQUEST_WIFI_PS, iface, ¶ms, sizeof(params))) { - shell_fprintf(sh, SHELL_WARNING, - "Setting PS timeout failed. Reason : %s\n", - wifi_ps_get_config_err_code_str(params.fail_reason)); + PR_WARNING("Setting PS timeout failed. Reason : %s\n", + wifi_ps_get_config_err_code_str(params.fail_reason)); return -ENOEXEC; } if (params.timeout_ms) { - shell_fprintf(sh, SHELL_NORMAL, "PS timeout: %d ms\n", params.timeout_ms); + PR("PS timeout: %d ms\n", params.timeout_ms); } else { - shell_fprintf(sh, SHELL_NORMAL, "PS timeout: disabled\n"); + PR("PS timeout: disabled\n"); } return 0; } static int cmd_wifi_twt_setup_quick(const struct shell *sh, size_t argc, - char *argv[]) + char *argv[]) { struct net_if *iface = net_if_get_first_wifi(); struct wifi_twt_params params = { 0 }; @@ -1107,22 +1087,21 @@ static int cmd_wifi_twt_setup_quick(const struct shell *sh, size_t argc, params.setup.twt_interval = (uint64_t)value; if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { - shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n", - wifi_twt_operation_txt(params.operation), - wifi_twt_negotiation_type_txt(params.negotiation_type), - wifi_twt_get_err_code_str(params.fail_reason)); + PR_WARNING("%s with %s failed, reason : %s\n", + wifi_twt_operation_txt(params.operation), + wifi_twt_negotiation_type_txt(params.negotiation_type), + wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s with dg: %d, flow_id: %d requested\n", - wifi_twt_operation_txt(params.operation), - params.dialog_token, params.flow_id); + PR("TWT operation %s with dg: %d, flow_id: %d requested\n", + wifi_twt_operation_txt(params.operation), + params.dialog_token, params.flow_id); return 0; } - static int cmd_wifi_twt_setup(const struct shell *sh, size_t argc, char *argv[]) { @@ -1193,23 +1172,23 @@ static int cmd_wifi_twt_setup(const struct shell *sh, size_t argc, params.setup.twt_wake_ahead_duration = (uint32_t)value; if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { - shell_fprintf(sh, SHELL_WARNING, "%s with %s failed. reason : %s\n", - wifi_twt_operation_txt(params.operation), - wifi_twt_negotiation_type_txt(params.negotiation_type), - wifi_twt_get_err_code_str(params.fail_reason)); + PR_WARNING("%s with %s failed. reason : %s\n", + wifi_twt_operation_txt(params.operation), + wifi_twt_negotiation_type_txt(params.negotiation_type), + wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s with dg: %d, flow_id: %d requested\n", - wifi_twt_operation_txt(params.operation), - params.dialog_token, params.flow_id); + PR("TWT operation %s with dg: %d, flow_id: %d requested\n", + wifi_twt_operation_txt(params.operation), + params.dialog_token, params.flow_id); return 0; } static int cmd_wifi_twt_teardown(const struct shell *sh, size_t argc, - char *argv[]) + char *argv[]) { struct net_if *iface = net_if_get_first_wifi(); struct wifi_twt_params params = { 0 }; @@ -1243,23 +1222,23 @@ static int cmd_wifi_twt_teardown(const struct shell *sh, size_t argc, params.flow_id = (uint8_t)value; if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { - shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n", - wifi_twt_operation_txt(params.operation), - wifi_twt_negotiation_type_txt(params.negotiation_type), - wifi_twt_get_err_code_str(params.fail_reason)); + PR_WARNING("%s with %s failed, reason : %s\n", + wifi_twt_operation_txt(params.operation), + wifi_twt_negotiation_type_txt(params.negotiation_type), + wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s with dg: %d, flow_id: %d success\n", - wifi_twt_operation_txt(params.operation), - params.dialog_token, params.flow_id); + PR("TWT operation %s with dg: %d, flow_id: %d success\n", + wifi_twt_operation_txt(params.operation), + params.dialog_token, params.flow_id); return 0; } static int cmd_wifi_twt_teardown_all(const struct shell *sh, size_t argc, - char *argv[]) + char *argv[]) { struct net_if *iface = net_if_get_first_wifi(); struct wifi_twt_params params = { 0 }; @@ -1270,16 +1249,16 @@ static int cmd_wifi_twt_teardown_all(const struct shell *sh, size_t argc, params.teardown.teardown_all = 1; if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { - shell_fprintf(sh, SHELL_WARNING, "%s with %s failed, reason : %s\n", - wifi_twt_operation_txt(params.operation), - wifi_twt_negotiation_type_txt(params.negotiation_type), - wifi_twt_get_err_code_str(params.fail_reason)); + PR_WARNING("%s with %s failed, reason : %s\n", + wifi_twt_operation_txt(params.operation), + wifi_twt_negotiation_type_txt(params.negotiation_type), + wifi_twt_get_err_code_str(params.fail_reason)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "TWT operation %s all flows success\n", - wifi_twt_operation_txt(params.operation)); + PR("TWT operation %s all flows success\n", + wifi_twt_operation_txt(params.operation)); return 0; } @@ -1300,13 +1279,13 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc, k_mutex_init(&wifi_ap_sta_list_lock); ret = net_mgmt(NET_REQUEST_WIFI_AP_ENABLE, iface, &cnx_params, - sizeof(struct wifi_connect_req_params)); + sizeof(struct wifi_connect_req_params)); if (ret) { - shell_fprintf(sh, SHELL_WARNING, "AP mode enable failed: %s\n", strerror(-ret)); + PR_WARNING("AP mode enable failed: %s\n", strerror(-ret)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "AP mode enable requested\n"); + PR("AP mode enable requested\n"); return 0; } @@ -1319,11 +1298,11 @@ static int cmd_wifi_ap_disable(const struct shell *sh, size_t argc, ret = net_mgmt(NET_REQUEST_WIFI_AP_DISABLE, iface, NULL, 0); if (ret) { - shell_fprintf(sh, SHELL_WARNING, "AP mode disable failed: %s\n", strerror(-ret)); + PR_WARNING("AP mode disable failed: %s\n", strerror(-ret)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "AP mode disable requested\n"); + PR("AP mode disable requested\n"); return 0; } @@ -1335,8 +1314,8 @@ static int cmd_wifi_ap_stations(const struct shell *sh, size_t argc, ARG_UNUSED(argv); ARG_UNUSED(argc); - shell_fprintf(sh, SHELL_NORMAL, "AP stations:\n"); - shell_fprintf(sh, SHELL_NORMAL, "============\n"); + PR("AP stations:\n"); + PR("============\n"); k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); for (int i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { @@ -1349,21 +1328,21 @@ static int cmd_wifi_ap_stations(const struct shell *sh, size_t argc, sta = &sta_list[i].sta_info; - shell_fprintf(sh, SHELL_NORMAL, "Station %zu:\n", id++); - shell_fprintf(sh, SHELL_NORMAL, "==========\n"); - shell_fprintf(sh, SHELL_NORMAL, "MAC: %s\n", - net_sprint_ll_addr_buf(sta->mac, - WIFI_MAC_ADDR_LEN, - mac_string_buf, - sizeof(mac_string_buf))); - shell_fprintf(sh, SHELL_NORMAL, "Link mode: %s\n", - wifi_link_mode_txt(sta->link_mode)); - shell_fprintf(sh, SHELL_NORMAL, "TWT: %s\n", - sta->twt_capable ? "Supported" : "Not supported"); + PR("Station %zu:\n", id++); + PR("==========\n"); + PR("MAC: %s\n", + net_sprint_ll_addr_buf(sta->mac, + WIFI_MAC_ADDR_LEN, + mac_string_buf, + sizeof(mac_string_buf))); + PR("Link mode: %s\n", + wifi_link_mode_txt(sta->link_mode)); + PR("TWT: %s\n", + sta->twt_capable ? "Supported" : "Not supported"); } if (id == 1) { - shell_fprintf(sh, SHELL_NORMAL, "No stations connected\n"); + PR("No stations connected\n"); } k_mutex_unlock(&wifi_ap_sta_list_lock); @@ -1384,18 +1363,18 @@ static int cmd_wifi_ap_sta_disconnect(const struct shell *sh, size_t argc, } if (net_bytes_from_str(mac, sizeof(mac), argv[1]) < 0) { - shell_fprintf(sh, SHELL_WARNING, "Invalid MAC address\n"); + PR_WARNING("Invalid MAC address\n"); return -ENOEXEC; } ret = net_mgmt(NET_REQUEST_WIFI_AP_STA_DISCONNECT, iface, mac, sizeof(mac)); if (ret) { - shell_fprintf(sh, SHELL_WARNING, "AP station disconnect failed: %s\n", - strerror(-ret)); + PR_WARNING("AP station disconnect failed: %s\n", + strerror(-ret)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "AP station disconnect requested\n"); + PR("AP station disconnect requested\n"); return 0; } @@ -1412,8 +1391,7 @@ static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc, } else if (argc >= 2 && argc <= 3) { regd.oper = WIFI_MGMT_SET; if (strlen(argv[1]) != 2) { - shell_fprintf(sh, SHELL_WARNING, - "Invalid reg domain: Length should be two letters/digits\n"); + PR_WARNING("Invalid reg domain: Length should be two letters/digits\n"); return -ENOEXEC; } @@ -1421,8 +1399,7 @@ static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc, if (((argv[1][0] < 'A' || argv[1][0] > 'Z') || (argv[1][1] < 'A' || argv[1][1] > 'Z')) && (argv[1][0] != '0' || argv[1][1] != '0')) { - shell_fprintf(sh, SHELL_WARNING, "Invalid reg domain %c%c\n", argv[1][0], - argv[1][1]); + PR_WARNING("Invalid reg domain %c%c\n", argv[1][0], argv[1][1]); return -ENOEXEC; } regd.country_code[0] = argv[1][0]; @@ -1432,7 +1409,7 @@ static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc, if (strncmp(argv[2], "-f", 2) == 0) { regd.force = true; } else { - shell_fprintf(sh, SHELL_WARNING, "Invalid option %s\n", argv[2]); + PR_WARNING("Invalid option %s\n", argv[2]); return -ENOEXEC; } } @@ -1444,30 +1421,28 @@ static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc, ret = net_mgmt(NET_REQUEST_WIFI_REG_DOMAIN, iface, ®d, sizeof(regd)); if (ret) { - shell_fprintf(sh, SHELL_WARNING, "Cannot %s Regulatory domain: %d\n", - regd.oper == WIFI_MGMT_GET ? "get" : "set", ret); + PR_WARNING("Cannot %s Regulatory domain: %d\n", + regd.oper == WIFI_MGMT_GET ? "get" : "set", ret); return -ENOEXEC; } if (regd.oper == WIFI_MGMT_GET) { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi Regulatory domain is: %c%c\n", - regd.country_code[0], regd.country_code[1]); - shell_fprintf(sh, SHELL_NORMAL, - "\t

\t\t" - "\t\t\n"); + PR("Wi-Fi Regulatory domain is: %c%c\n", + regd.country_code[0], regd.country_code[1]); + PR("\t
\t\t" + "\t\t\n"); for (chan_idx = 0; chan_idx < regd.num_channels; chan_idx++) { - shell_fprintf(sh, SHELL_NORMAL, - " %d\t\t\t\%d\t\t\t\%s\t\t\t%d\t\t\t%s\t\t\t\t%s\n", - wifi_freq_to_channel(chan_info[chan_idx].center_frequency), - chan_info[chan_idx].center_frequency, - chan_info[chan_idx].supported ? "y" : "n", - chan_info[chan_idx].max_power, - chan_info[chan_idx].passive_only ? "y" : "n", - chan_info[chan_idx].dfs ? "y" : "n"); + PR(" %d\t\t\t\%d\t\t\t\%s\t\t\t%d\t\t\t%s\t\t\t\t%s\n", + wifi_freq_to_channel(chan_info[chan_idx].center_frequency), + chan_info[chan_idx].center_frequency, + chan_info[chan_idx].supported ? "y" : "n", + chan_info[chan_idx].max_power, + chan_info[chan_idx].passive_only ? "y" : "n", + chan_info[chan_idx].dfs ? "y" : "n"); } } else { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi Regulatory domain set to: %c%c\n", - regd.country_code[0], regd.country_code[1]); + PR("Wi-Fi Regulatory domain set to: %c%c\n", + regd.country_code[0], regd.country_code[1]); } return 0; @@ -1493,21 +1468,17 @@ static int cmd_wifi_listen_interval(const struct shell *sh, size_t argc, char *a if (net_mgmt(NET_REQUEST_WIFI_PS, iface, ¶ms, sizeof(params))) { if (params.fail_reason == WIFI_PS_PARAM_LISTEN_INTERVAL_RANGE_INVALID) { - shell_fprintf(sh, SHELL_WARNING, - "Setting listen interval failed. Reason :%s\n", - wifi_ps_get_config_err_code_str(params.fail_reason)); - shell_fprintf(sh, SHELL_WARNING, - "Hardware support valid range : 3 - 65535\n"); - } else { - shell_fprintf(sh, SHELL_WARNING, - "Setting listen interval failed. Reason :%s\n", - wifi_ps_get_config_err_code_str(params.fail_reason)); + PR_WARNING("Setting listen interval failed. Reason :%s\n", + wifi_ps_get_config_err_code_str(params.fail_reason)); + PR_WARNING("Hardware support valid range : 3 - 65535\n"); + } else { + PR_WARNING("Setting listen interval failed. Reason :%s\n", + wifi_ps_get_config_err_code_str(params.fail_reason)); } return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, - "Listen interval %hu\n", params.listen_interval); + PR("Listen interval %hu\n", params.listen_interval); return 0; } @@ -1524,24 +1495,21 @@ static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *ar } else if (!strncasecmp(argv[1], "listen_interval", 15)) { params.wakeup_mode = WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL; } else { - shell_fprintf(sh, SHELL_WARNING, "Invalid argument\n"); - shell_fprintf(sh, SHELL_INFO, - "Valid argument : / \n"); + PR_WARNING("Invalid argument\n"); + PR_INFO("Valid argument : / \n"); return -ENOEXEC; } params.type = WIFI_PS_PARAM_WAKEUP_MODE; if (net_mgmt(NET_REQUEST_WIFI_PS, iface, ¶ms, sizeof(params))) { - shell_fprintf(sh, SHELL_WARNING, - "Setting PS wake up mode to %s failed..Reason :%s\n", - params.wakeup_mode ? "Listen interval" : "DTIM interval", - wifi_ps_get_config_err_code_str(params.fail_reason)); + PR_WARNING("Setting PS wake up mode to %s failed..Reason :%s\n", + params.wakeup_mode ? "Listen interval" : "DTIM interval", + wifi_ps_get_config_err_code_str(params.fail_reason)); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "%s\n", - wifi_ps_wakeup_mode_txt(params.wakeup_mode)); + PR("%s\n", wifi_ps_wakeup_mode_txt(params.wakeup_mode)); return 0; } @@ -1604,7 +1572,7 @@ static int cmd_wifi_mode(const struct shell *sh, size_t argc, char *argv[]) mode_info.oper = WIFI_MGMT_SET; parse_mode_args_to_params(sh, argc, argv, &mode_info, &do_mode_oper); } else { - shell_fprintf(sh, SHELL_ERROR, "Invalid number of arguments\n"); + PR_ERROR("Invalid number of arguments\n"); return -EINVAL; } @@ -1615,17 +1583,15 @@ static int cmd_wifi_mode(const struct shell *sh, size_t argc, char *argv[]) if (mode_info.if_index == 0) { iface = net_if_get_first_wifi(); if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find the default wifi interface\n"); + PR_ERROR("Cannot find the default wifi interface\n"); return -ENOEXEC; } mode_info.if_index = net_if_get_by_iface(iface); } else { iface = net_if_get_by_index(mode_info.if_index); if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find interface for if_index %d\n", - mode_info.if_index); + PR_ERROR("Cannot find interface for if_index %d\n", + mode_info.if_index); return -ENOEXEC; } } @@ -1633,16 +1599,15 @@ static int cmd_wifi_mode(const struct shell *sh, size_t argc, char *argv[]) ret = net_mgmt(NET_REQUEST_WIFI_MODE, iface, &mode_info, sizeof(mode_info)); if (ret) { - shell_fprintf(sh, SHELL_ERROR, "mode %s operation failed with reason %d\n", - mode_info.oper == WIFI_MGMT_GET ? "get" : "set", ret); + PR_ERROR("mode %s operation failed with reason %d\n", + mode_info.oper == WIFI_MGMT_GET ? "get" : "set", ret); return -ENOEXEC; } if (mode_info.oper == WIFI_MGMT_GET) { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi current mode is %x\n", - mode_info.mode); + PR("Wi-Fi current mode is %x\n", mode_info.mode); } else { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi mode set to %x\n", mode_info.mode); + PR("Wi-Fi mode set to %x\n", mode_info.mode); } } return 0; @@ -1661,7 +1626,7 @@ void parse_channel_args_to_params(const struct shell *sh, int argc, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; - while ((opt = getopt_long(argc, argv, "i:c:gh", long_options, &option_index)) != -1) { + while ((opt = getopt_long(argc, argv, "i:c:gh", long_options, &option_index)) != -1) { switch (opt) { case 'c': channel->channel = (uint16_t)atoi(optarg); @@ -1704,17 +1669,15 @@ static int cmd_wifi_channel(const struct shell *sh, size_t argc, char *argv[]) if (channel_info.if_index == 0) { iface = net_if_get_first_wifi(); if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find the default wifi interface\n"); + PR_ERROR("Cannot find the default wifi interface\n"); return -ENOEXEC; } channel_info.if_index = net_if_get_by_iface(iface); } else { iface = net_if_get_by_index(channel_info.if_index); if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find interface for if_index %d\n", - channel_info.if_index); + PR_ERROR("Cannot find interface for if_index %d\n", + channel_info.if_index); return -ENOEXEC; } } @@ -1722,28 +1685,24 @@ static int cmd_wifi_channel(const struct shell *sh, size_t argc, char *argv[]) if (channel_info.oper == WIFI_MGMT_SET) { if ((channel_info.channel < WIFI_CHANNEL_MIN) || (channel_info.channel > WIFI_CHANNEL_MAX)) { - shell_fprintf(sh, SHELL_ERROR, - "Invalid channel number. Range is (1-233)\n"); + PR_ERROR("Invalid channel number. Range is (1-233)\n"); return -ENOEXEC; } } - ret = net_mgmt(NET_REQUEST_WIFI_CHANNEL, iface, - &channel_info, sizeof(channel_info)); + ret = net_mgmt(NET_REQUEST_WIFI_CHANNEL, iface, &channel_info, + sizeof(channel_info)); if (ret) { - shell_fprintf(sh, SHELL_ERROR, - "channel %s operation failed with reason %d\n", - channel_info.oper == WIFI_MGMT_GET ? "get" : "set", ret); + PR_ERROR("channel %s operation failed with reason %d\n", + channel_info.oper == WIFI_MGMT_GET ? "get" : "set", ret); return -ENOEXEC; } if (channel_info.oper == WIFI_MGMT_GET) { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi current channel is: %d\n", - channel_info.channel); + PR("Wi-Fi current channel is: %d\n", channel_info.channel); } else { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi channel set to %d\n", - channel_info.channel); + PR("Wi-Fi channel set to %d\n", channel_info.channel); } } return 0; @@ -1766,7 +1725,7 @@ void parse_filter_args_to_params(const struct shell *sh, int argc, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; - while ((opt = getopt_long(argc, argv, "i:b:amcdgh", long_options, &option_index)) != -1) { + while ((opt = getopt_long(argc, argv, "i:b:amcdgh", long_options, &option_index)) != -1) { switch (opt) { case 'a': filter->filter |= WIFI_PACKET_FILTER_ALL; @@ -1821,37 +1780,34 @@ static int cmd_wifi_packet_filter(const struct shell *sh, size_t argc, char *arg if (packet_filter.if_index == 0) { iface = net_if_get_first_wifi(); if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find the default wifi interface\n"); + PR_ERROR("Cannot find the default wifi interface\n"); return -ENOEXEC; } packet_filter.if_index = net_if_get_by_iface(iface); } else { iface = net_if_get_by_index(packet_filter.if_index); if (iface == NULL) { - shell_fprintf(sh, SHELL_ERROR, - "Cannot find interface for if_index %d\n", - packet_filter.if_index); + PR_ERROR("Cannot find interface for if_index %d\n", + packet_filter.if_index); return -ENOEXEC; } } - ret = net_mgmt(NET_REQUEST_WIFI_PACKET_FILTER, iface, - &packet_filter, sizeof(packet_filter)); + ret = net_mgmt(NET_REQUEST_WIFI_PACKET_FILTER, iface, &packet_filter, + sizeof(packet_filter)); if (ret) { - shell_fprintf(sh, SHELL_ERROR, - "Wi-Fi packet filter %s operation failed with reason %d\n", - packet_filter.oper == WIFI_MGMT_GET ? "get" : "set", ret); + PR_ERROR("Wi-Fi packet filter %s operation failed with reason %d\n", + packet_filter.oper == WIFI_MGMT_GET ? "get" : "set", ret); return -ENOEXEC; } if (packet_filter.oper == WIFI_MGMT_GET) { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi current mode packet filter is %d\n", - packet_filter.filter); + PR("Wi-Fi current mode packet filter is %d\n", + packet_filter.filter); } else { - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi mode packet filter set to %d\n", - packet_filter.filter); + PR("Wi-Fi mode packet filter set to %d\n", + packet_filter.filter); } } return 0; @@ -1863,17 +1819,17 @@ static int cmd_wifi_version(const struct shell *sh, size_t argc, char *argv[]) struct wifi_version version = {0}; if (argc > 1) { - shell_fprintf(sh, SHELL_WARNING, "Invalid number of arguments\n"); + PR_WARNING("Invalid number of arguments\n"); return -ENOEXEC; } if (net_mgmt(NET_REQUEST_WIFI_VERSION, iface, &version, sizeof(version))) { - shell_fprintf(sh, SHELL_WARNING, "Failed to get Wi-Fi versions\n"); + PR_WARNING("Failed to get Wi-Fi versions\n"); return -ENOEXEC; } - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi Driver Version: %s\n", version.drv_version); - shell_fprintf(sh, SHELL_NORMAL, "Wi-Fi Firmware Version: %s\n", version.fw_version); + PR("Wi-Fi Driver Version: %s\n", version.drv_version); + PR("Wi-Fi Firmware Version: %s\n", version.fw_version); return 0; } From 9e1de3d954561a372926ec00423a519e888fd9dd Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Wed, 31 Jan 2024 21:37:07 +0700 Subject: [PATCH 1388/1623] [nrf fromtree] wifi: shell: replace print(...) with PR(...) Additionally, replace the local print(sh, level, fmt, ...) macros with PR, PR_ERROR, and PR_WARNING macros. Then remove the print(sh, level, fmt, ...) macros. Signed-off-by: Pisit Sawangvonganan (cherry picked from commit 055ac615427fd55fa347cd1744280734e730a42a) --- subsys/net/l2/wifi/wifi_shell.c | 193 ++++++++++++++------------------ 1 file changed, 86 insertions(+), 107 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index bfaa35c9a71..304f1748bfe 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -75,15 +75,6 @@ struct wifi_ap_sta_node { }; static struct wifi_ap_sta_node sta_list[CONFIG_WIFI_SHELL_MAX_AP_STA]; -#define print(sh, level, fmt, ...) \ - do { \ - if (sh) { \ - shell_fprintf(sh, level, fmt, ##__VA_ARGS__); \ - } else { \ - printk(fmt, ##__VA_ARGS__); \ - } \ - } while (false) - static bool parse_number(const struct shell *sh, long *param, char *str, long min, long max) { char *endptr; @@ -98,12 +89,12 @@ static bool parse_number(const struct shell *sh, long *param, char *str, long mi } if (*endptr != '\0') { - print(sh, SHELL_ERROR, "Invalid number: %s", str_tmp); + PR_ERROR("Invalid number: %s", str_tmp); return false; } if ((num) < (min) || (num) > (max)) { - print(sh, SHELL_WARNING, "Value out of range: %s, (%ld-%ld)", str_tmp, min, max); + PR_WARNING("Value out of range: %s, (%ld-%ld)", str_tmp, min, max); return false; } *param = num; @@ -115,26 +106,25 @@ static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb) const struct wifi_scan_result *entry = (const struct wifi_scan_result *)cb->info; uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; + const struct shell *sh = context.sh; context.scan_result++; if (context.scan_result == 1U) { - print(context.sh, SHELL_NORMAL, - "\n%-4s | %-32s %-5s | %-13s | %-4s | %-15s | %-17s | %-8s\n", - "Num", "SSID", "(len)", "Chan (Band)", "RSSI", "Security", "BSSID", "MFP"); - } - - print(context.sh, SHELL_NORMAL, - "%-4d | %-32s %-5u | %-4u (%-6s) | %-4d | %-15s | %-17s | %-8s\n", - context.scan_result, entry->ssid, entry->ssid_length, entry->channel, - wifi_band_txt(entry->band), - entry->rssi, - wifi_security_txt(entry->security), - ((entry->mac_length) ? - net_sprint_ll_addr_buf(entry->mac, WIFI_MAC_ADDR_LEN, - mac_string_buf, - sizeof(mac_string_buf)) : ""), - wifi_mfp_txt(entry->mfp)); + PR("\n%-4s | %-32s %-5s | %-13s | %-4s | %-15s | %-17s | %-8s\n", + "Num", "SSID", "(len)", "Chan (Band)", "RSSI", "Security", "BSSID", "MFP"); + } + + PR("%-4d | %-32s %-5u | %-4u (%-6s) | %-4d | %-15s | %-17s | %-8s\n", + context.scan_result, entry->ssid, entry->ssid_length, entry->channel, + wifi_band_txt(entry->band), + entry->rssi, + wifi_security_txt(entry->security), + ((entry->mac_length) ? + net_sprint_ll_addr_buf(entry->mac, WIFI_MAC_ADDR_LEN, + mac_string_buf, + sizeof(mac_string_buf)) : ""), + wifi_mfp_txt(entry->mfp)); } static int wifi_freq_to_channel(int frequency) @@ -188,28 +178,27 @@ static void handle_wifi_raw_scan_result(struct net_mgmt_event_callback *cb) context.scan_result++; if (context.scan_result == 1U) { - print(sh, SHELL_NORMAL, - "\n%-4s | %-13s | %-4s | %-15s | %-15s | %-32s\n", - "Num", "Channel (Band)", "RSSI", "BSSID", "Frame length", "Frame Body"); + PR("\n%-4s | %-13s | %-4s | %-15s | %-15s | %-32s\n", + "Num", "Channel (Band)", "RSSI", "BSSID", "Frame length", "Frame Body"); } rssi = raw->rssi; channel = wifi_freq_to_channel(raw->frequency); band = wifi_freq_to_band(raw->frequency); - print(sh, SHELL_NORMAL, "%-4d | %-4u (%-6s) | %-4d | %s | %-4d ", - context.scan_result, - channel, - wifi_band_txt(band), - rssi, - net_sprint_ll_addr_buf(raw->data + 10, WIFI_MAC_ADDR_LEN, mac_string_buf, - sizeof(mac_string_buf)), raw->frame_length); + PR("%-4d | %-4u (%-6s) | %-4d | %s | %-4d ", + context.scan_result, + channel, + wifi_band_txt(band), + rssi, + net_sprint_ll_addr_buf(raw->data + 10, WIFI_MAC_ADDR_LEN, mac_string_buf, + sizeof(mac_string_buf)), raw->frame_length); for (i = 0; i < 32; i++) { - print(sh, SHELL_NORMAL, "%02X ", *(raw->data + i)); + PR("%02X ", *(raw->data + i)); } - print(sh, SHELL_NORMAL, "\n"); + PR("\n"); } #endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */ @@ -220,10 +209,9 @@ static void handle_wifi_scan_done(struct net_mgmt_event_callback *cb) const struct shell *sh = context.sh; if (status->status) { - print(sh, SHELL_WARNING, - "Scan request failed (%d)\n", status->status); + PR_WARNING("Scan request failed (%d)\n", status->status); } else { - print(sh, SHELL_NORMAL, "Scan request done\n"); + PR("Scan request done\n"); } context.scan_result = 0U; @@ -233,12 +221,12 @@ static void handle_wifi_connect_result(struct net_mgmt_event_callback *cb) { const struct wifi_status *status = (const struct wifi_status *) cb->info; + const struct shell *sh = context.sh; if (status->status) { - print(context.sh, SHELL_WARNING, - "Connection request failed (%d)\n", status->status); + PR_WARNING("Connection request failed (%d)\n", status->status); } else { - print(context.sh, SHELL_NORMAL, "Connected\n"); + PR("Connected\n"); } context.connecting = false; @@ -248,16 +236,17 @@ static void handle_wifi_disconnect_result(struct net_mgmt_event_callback *cb) { const struct wifi_status *status = (const struct wifi_status *) cb->info; + const struct shell *sh = context.sh; if (context.disconnecting) { - print(context.sh, - status->status ? SHELL_WARNING : SHELL_NORMAL, - "Disconnection request %s (%d)\n", - status->status ? "failed" : "done", - status->status); + if (status->status) { + PR_WARNING("Disconnection request failed (%d)\n", status->status); + } else { + PR("Disconnection request done (%d)\n", status->status); + } context.disconnecting = false; } else { - print(context.sh, SHELL_NORMAL, "Disconnected\n"); + PR("Disconnected\n"); } } @@ -269,25 +258,25 @@ static void print_twt_params(uint8_t dialog_token, uint8_t flow_id, { const struct shell *sh = context.sh; - print(sh, SHELL_NORMAL, "TWT Dialog token: %d\n", + PR("TWT Dialog token: %d\n", dialog_token); - print(sh, SHELL_NORMAL, "TWT flow ID: %d\n", + PR("TWT flow ID: %d\n", flow_id); - print(sh, SHELL_NORMAL, "TWT negotiation type: %s\n", + PR("TWT negotiation type: %s\n", wifi_twt_negotiation_type_txt(negotiation_type)); - print(sh, SHELL_NORMAL, "TWT responder: %s\n", + PR("TWT responder: %s\n", responder ? "true" : "false"); - print(sh, SHELL_NORMAL, "TWT implicit: %s\n", + PR("TWT implicit: %s\n", implicit ? "true" : "false"); - print(sh, SHELL_NORMAL, "TWT announce: %s\n", + PR("TWT announce: %s\n", announce ? "true" : "false"); - print(sh, SHELL_NORMAL, "TWT trigger: %s\n", + PR("TWT trigger: %s\n", trigger ? "true" : "false"); - print(sh, SHELL_NORMAL, "TWT wake interval: %d us\n", + PR("TWT wake interval: %d us\n", twt_wake_interval); - print(sh, SHELL_NORMAL, "TWT interval: %lld us\n", + PR("TWT interval: %lld us\n", twt_interval); - print(sh, SHELL_NORMAL, "========================\n"); + PR("========================\n"); } static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) @@ -298,19 +287,19 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) if (resp->operation == WIFI_TWT_TEARDOWN) { if (resp->teardown_status == WIFI_TWT_TEARDOWN_SUCCESS) { - print(sh, SHELL_NORMAL, "TWT teardown succeeded for flow ID %d\n", + PR("TWT teardown succeeded for flow ID %d\n", resp->flow_id); } else { - print(sh, SHELL_NORMAL, "TWT teardown failed for flow ID %d\n", + PR("TWT teardown failed for flow ID %d\n", resp->flow_id); } return; } if (resp->resp_status == WIFI_TWT_RESP_RECEIVED) { - print(sh, SHELL_NORMAL, "TWT response: %s\n", + PR("TWT response: %s\n", wifi_twt_setup_cmd_txt(resp->setup_cmd)); - print(sh, SHELL_NORMAL, "== TWT negotiated parameters ==\n"); + PR("== TWT negotiated parameters ==\n"); print_twt_params(resp->dialog_token, resp->flow_id, resp->negotiation_type, @@ -321,7 +310,7 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) resp->setup.twt_wake_interval, resp->setup.twt_interval); } else { - print(sh, SHELL_NORMAL, "TWT response timed out\n"); + PR("TWT response timed out\n"); } } @@ -332,10 +321,9 @@ static void handle_wifi_ap_enable_result(struct net_mgmt_event_callback *cb) const struct shell *sh = context.sh; if (status->status) { - print(sh, SHELL_WARNING, - "AP enable request failed (%d)\n", status->status); + PR_WARNING("AP enable request failed (%d)\n", status->status); } else { - print(sh, SHELL_NORMAL, "AP enabled\n"); + PR("AP enabled\n"); } } @@ -346,10 +334,9 @@ static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb) const struct shell *sh = context.sh; if (status->status) { - print(sh, SHELL_WARNING, - "AP disable request failed (%d)\n", status->status); + PR_WARNING("AP disable request failed (%d)\n", status->status); } else { - print(sh, SHELL_NORMAL, "AP disabled\n"); + PR("AP disabled\n"); } k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); @@ -365,9 +352,9 @@ static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; int i; - print(sh, SHELL_NORMAL, "Station connected: %s\n", - net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, - mac_string_buf, sizeof(mac_string_buf))); + PR("Station connected: %s\n", + net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, + mac_string_buf, sizeof(mac_string_buf))); k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); for (i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { @@ -378,8 +365,8 @@ static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb) } } if (i == CONFIG_WIFI_SHELL_MAX_AP_STA) { - print(sh, SHELL_WARNING, "No space to store station info: " - "Increase CONFIG_WIFI_SHELL_MAX_AP_STA\n"); + PR_WARNING("No space to store station info: " + "Increase CONFIG_WIFI_SHELL_MAX_AP_STA\n"); } k_mutex_unlock(&wifi_ap_sta_list_lock); } @@ -391,9 +378,9 @@ static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb) const struct shell *sh = context.sh; uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; - print(sh, SHELL_NORMAL, "Station disconnected: %s\n", - net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, - mac_string_buf, sizeof(mac_string_buf))); + PR("Station disconnected: %s\n", + net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN, + mac_string_buf, sizeof(mac_string_buf))); k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER); for (int i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) { @@ -468,9 +455,8 @@ static int __wifi_args_to_params(size_t argc, char *argv[], params->ssid = argv[0]; params->ssid_length = strlen(params->ssid); if (params->ssid_length > WIFI_SSID_MAX_LEN) { - print(sh, SHELL_WARNING, - "SSID too long (max %d characters)\n", - WIFI_SSID_MAX_LEN); + PR_WARNING("SSID too long (max %d characters)\n", + WIFI_SSID_MAX_LEN); return -EINVAL; } @@ -486,11 +472,10 @@ static int __wifi_args_to_params(size_t argc, char *argv[], size_t offset = 0; if (*endptr != '\0') { - print(sh, SHELL_ERROR, - "Failed to parse channel: %s: endp: %s, err: %s\n", - argv[idx], - endptr, - strerror(errno)); + PR_ERROR("Failed to parse channel: %s: endp: %s, err: %s\n", + argv[idx], + endptr, + strerror(errno)); return -EINVAL; } @@ -508,15 +493,13 @@ static int __wifi_args_to_params(size_t argc, char *argv[], params->band = WIFI_FREQ_BAND_6_GHZ; break; default: - print(sh, SHELL_ERROR, - "Invalid band: %ld\n", channel); + PR_ERROR("Invalid band: %ld\n", channel); return -EINVAL; } } } else { if (channel < 0) { - print(sh, SHELL_ERROR, - "Invalid channel: %ld\n", channel); + PR_ERROR("Invalid channel: %ld\n", channel); return -EINVAL; } } @@ -529,10 +512,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[], band ? "," : "", wifi_band_txt(all_bands[band])); if (offset >= sizeof(bands_str)) { - print(sh, SHELL_ERROR, - "Failed to parse channel: %s: " - "band string too long\n", - argv[idx]); + PR_ERROR("Failed to parse channel: %s: " + "band string too long\n", + argv[idx]); return -EINVAL; } @@ -544,10 +526,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[], } if (!found) { - print(sh, SHELL_ERROR, - "Invalid channel: %ld, checked bands: %s\n", - channel, - bands_str); + PR_ERROR("Invalid channel: %ld, checked bands: %s\n", + channel, + bands_str); return -EINVAL; } @@ -580,9 +561,8 @@ static int __wifi_args_to_params(size_t argc, char *argv[], if (security == WIFI_SECURITY_TYPE_NONE || security == WIFI_SECURITY_TYPE_WPA_PSK) { - print(sh, SHELL_ERROR, - "MFP not supported for security type %s\n", - wifi_security_txt(security)); + PR_ERROR("MFP not supported for security type %s\n", + wifi_security_txt(security)); return -EINVAL; } @@ -598,10 +578,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[], params->psk_length > WIFI_PSK_MAX_LEN) || (params->security == WIFI_SECURITY_TYPE_SAE && params->psk_length > WIFI_SAE_PSWD_MAX_LEN)) { - print(sh, SHELL_ERROR, - "Invalid PSK length (%d) for security type %s\n", - params->psk_length, - wifi_security_txt(params->security)); + PR_ERROR("Invalid PSK length (%d) for security type %s\n", + params->psk_length, + wifi_security_txt(params->security)); return -EINVAL; } } From ea1fd932d014b49f27482463ce291b5697df9b38 Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Tue, 6 Feb 2024 14:03:43 +0530 Subject: [PATCH 1389/1623] [nrf fromtree] net: l2: wifi: Fix Print of SSID in WIFI scan result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WIFI scan result shows junk character in SSID because of the length of ssid is maximum(32 character) which leads to buffer overflow. It required one character for null terminator ‘\0’. Signed-off-by: Kapil Bhatt (cherry picked from commit 2207fedbc81720d50b67a70a463da4387acf3e18) --- subsys/net/l2/wifi/wifi_shell.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 304f1748bfe..71f3cec7c10 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -107,6 +107,7 @@ static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb) (const struct wifi_scan_result *)cb->info; uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")]; const struct shell *sh = context.sh; + uint8_t ssid_print[WIFI_SSID_MAX_LEN + 1]; context.scan_result++; @@ -115,8 +116,11 @@ static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb) "Num", "SSID", "(len)", "Chan (Band)", "RSSI", "Security", "BSSID", "MFP"); } + strncpy(ssid_print, entry->ssid, sizeof(ssid_print) - 1); + ssid_print[sizeof(ssid_print) - 1] = '\0'; + PR("%-4d | %-32s %-5u | %-4u (%-6s) | %-4d | %-15s | %-17s | %-8s\n", - context.scan_result, entry->ssid, entry->ssid_length, entry->channel, + context.scan_result, ssid_print, entry->ssid_length, entry->channel, wifi_band_txt(entry->band), entry->rssi, wifi_security_txt(entry->security), From 314da392dfc6fe699cefb1069c3305ab4c959784 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 20 Nov 2023 15:54:07 +0100 Subject: [PATCH 1390/1623] [nrf fromtree] tests/subsys/modem/*: Switch to native_sim Enable all these tests which run in native_posix in native_sim And add native_sim as default test platform Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 13b7557fe10b037ced8aa5cdac2d064bb1c45ca5) --- tests/subsys/modem/backends/tty/testcase.yaml | 6 +++++- tests/subsys/modem/modem_chat/testcase.yaml | 6 +++++- tests/subsys/modem/modem_cmux/testcase.yaml | 6 +++++- tests/subsys/modem/modem_ppp/testcase.yaml | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/subsys/modem/backends/tty/testcase.yaml b/tests/subsys/modem/backends/tty/testcase.yaml index 11f78b1d641..28d3c3d4aa2 100644 --- a/tests/subsys/modem/backends/tty/testcase.yaml +++ b/tests/subsys/modem/backends/tty/testcase.yaml @@ -5,4 +5,8 @@ tests: modem.backends.tty: tags: modem_backend_tty harness: ztest - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim + integration_platforms: + - native_sim diff --git a/tests/subsys/modem/modem_chat/testcase.yaml b/tests/subsys/modem/modem_chat/testcase.yaml index 8716d7f0d17..2b8723428ea 100644 --- a/tests/subsys/modem/modem_chat/testcase.yaml +++ b/tests/subsys/modem/modem_chat/testcase.yaml @@ -5,4 +5,8 @@ tests: modem.modem_chat: tags: modem_chat harness: ztest - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim + integration_platforms: + - native_sim diff --git a/tests/subsys/modem/modem_cmux/testcase.yaml b/tests/subsys/modem/modem_cmux/testcase.yaml index c7d1f53a085..fd89a3f5656 100644 --- a/tests/subsys/modem/modem_cmux/testcase.yaml +++ b/tests/subsys/modem/modem_cmux/testcase.yaml @@ -5,4 +5,8 @@ tests: modem.modem_cmux: tags: modem_cmux harness: ztest - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim + integration_platforms: + - native_sim diff --git a/tests/subsys/modem/modem_ppp/testcase.yaml b/tests/subsys/modem/modem_ppp/testcase.yaml index 0b3fef701f3..7e0937ea144 100644 --- a/tests/subsys/modem/modem_ppp/testcase.yaml +++ b/tests/subsys/modem/modem_ppp/testcase.yaml @@ -5,4 +5,8 @@ tests: modem.modem_ppp: tags: modem_ppp harness: ztest - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim + integration_platforms: + - native_sim From ea0825757952d9788fbaf62e3ddc9355efe5bc60 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 23 Nov 2023 18:23:34 +0100 Subject: [PATCH 1391/1623] [nrf fromtree] tests/drivers/build_all/*: Switch to native_sim Enable all these tests which run in native_posix in native_sim, Switch from native_posix to native_sim as default test platform And switch native_posix overlays to native_sim. Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 7b1813e9dcfb36b6472eb979fd11995729597619) --- .../adc/boards/{native_posix.overlay => native_sim.overlay} | 0 .../boards/{native_posix_64.overlay => native_sim_64.overlay} | 2 +- tests/drivers/build_all/adc/testcase.yaml | 4 ++-- tests/drivers/build_all/charger/testcase.yaml | 4 +++- tests/drivers/build_all/dac/testcase.yaml | 4 +++- tests/drivers/build_all/fpga/testcase.yaml | 4 +++- tests/drivers/build_all/ieee802154/testcase.yaml | 4 +++- tests/drivers/build_all/input/testcase.yaml | 4 +++- tests/drivers/build_all/mfd/testcase.yaml | 4 +++- tests/drivers/build_all/modem/testcase.yaml | 2 ++ tests/drivers/build_all/regulator/testcase.yaml | 4 +++- tests/drivers/build_all/video/testcase.yaml | 4 +++- 12 files changed, 29 insertions(+), 11 deletions(-) rename tests/drivers/build_all/adc/boards/{native_posix.overlay => native_sim.overlay} (100%) rename tests/drivers/build_all/adc/boards/{native_posix_64.overlay => native_sim_64.overlay} (74%) diff --git a/tests/drivers/build_all/adc/boards/native_posix.overlay b/tests/drivers/build_all/adc/boards/native_sim.overlay similarity index 100% rename from tests/drivers/build_all/adc/boards/native_posix.overlay rename to tests/drivers/build_all/adc/boards/native_sim.overlay diff --git a/tests/drivers/build_all/adc/boards/native_posix_64.overlay b/tests/drivers/build_all/adc/boards/native_sim_64.overlay similarity index 74% rename from tests/drivers/build_all/adc/boards/native_posix_64.overlay rename to tests/drivers/build_all/adc/boards/native_sim_64.overlay index b5655714d89..16e56822d5f 100644 --- a/tests/drivers/build_all/adc/boards/native_posix_64.overlay +++ b/tests/drivers/build_all/adc/boards/native_sim_64.overlay @@ -3,4 +3,4 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "native_posix.overlay" +#include "native_sim.overlay" diff --git a/tests/drivers/build_all/adc/testcase.yaml b/tests/drivers/build_all/adc/testcase.yaml index a8102364b60..3b8995e1769 100644 --- a/tests/drivers/build_all/adc/testcase.yaml +++ b/tests/drivers/build_all/adc/testcase.yaml @@ -7,8 +7,8 @@ tests: drivers.adc.build: # will cover I2C, SPI, and emul based drivers platform_allow: - - native_posix - - native_posix_64 + - native_sim + - native_sim_64 extra_args: "CONFIG_GPIO=y" drivers.adc.cc32xx.build: platform_allow: cc3220sf_launchxl diff --git a/tests/drivers/build_all/charger/testcase.yaml b/tests/drivers/build_all/charger/testcase.yaml index f2005d9f238..0a29ccc7b39 100644 --- a/tests/drivers/build_all/charger/testcase.yaml +++ b/tests/drivers/build_all/charger/testcase.yaml @@ -7,4 +7,6 @@ tests: - drivers - charger build_only: true - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim diff --git a/tests/drivers/build_all/dac/testcase.yaml b/tests/drivers/build_all/dac/testcase.yaml index 12252b8661f..a298ded77b4 100644 --- a/tests/drivers/build_all/dac/testcase.yaml +++ b/tests/drivers/build_all/dac/testcase.yaml @@ -6,7 +6,9 @@ common: tests: drivers.dac.build: # will cover I2C, SPI based drivers - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim extra_args: "CONFIG_GPIO=y" drivers.dac.mcux.build: platform_allow: frdm_k22f diff --git a/tests/drivers/build_all/fpga/testcase.yaml b/tests/drivers/build_all/fpga/testcase.yaml index 33cccf76dde..ad0d3e8123e 100644 --- a/tests/drivers/build_all/fpga/testcase.yaml +++ b/tests/drivers/build_all/fpga/testcase.yaml @@ -2,7 +2,9 @@ common: tags: - drivers - sensors - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim build_only: true tests: drivers.fpga.build: diff --git a/tests/drivers/build_all/ieee802154/testcase.yaml b/tests/drivers/build_all/ieee802154/testcase.yaml index fd9fb07e062..399f3fac3cf 100644 --- a/tests/drivers/build_all/ieee802154/testcase.yaml +++ b/tests/drivers/build_all/ieee802154/testcase.yaml @@ -5,7 +5,9 @@ common: build_only: true tests: ieee802154.build.external: - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim ieee802154.build.cc13xx_cc26xx: platform_allow: cc1352r_sensortag ieee802154.build.kw41z: diff --git a/tests/drivers/build_all/input/testcase.yaml b/tests/drivers/build_all/input/testcase.yaml index 32fe44b883f..80a60399464 100644 --- a/tests/drivers/build_all/input/testcase.yaml +++ b/tests/drivers/build_all/input/testcase.yaml @@ -3,7 +3,9 @@ common: - drivers - input build_only: true - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim tests: drivers.input.default: {} diff --git a/tests/drivers/build_all/mfd/testcase.yaml b/tests/drivers/build_all/mfd/testcase.yaml index 80864481bdf..126fdb40e55 100644 --- a/tests/drivers/build_all/mfd/testcase.yaml +++ b/tests/drivers/build_all/mfd/testcase.yaml @@ -5,4 +5,6 @@ common: - mfd tests: drivers.mfd.build: - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim diff --git a/tests/drivers/build_all/modem/testcase.yaml b/tests/drivers/build_all/modem/testcase.yaml index 89abfbd79df..25c338b9fda 100644 --- a/tests/drivers/build_all/modem/testcase.yaml +++ b/tests/drivers/build_all/modem/testcase.yaml @@ -79,6 +79,8 @@ tests: platform_allow: - native_posix_64 - native_posix + - native_sim_64 + - native_sim - qemu_x86 - qemu_x86_64 min_ram: 36 diff --git a/tests/drivers/build_all/regulator/testcase.yaml b/tests/drivers/build_all/regulator/testcase.yaml index c5dbda1913f..8214a2ca33a 100644 --- a/tests/drivers/build_all/regulator/testcase.yaml +++ b/tests/drivers/build_all/regulator/testcase.yaml @@ -5,4 +5,6 @@ tests: drivers.regulator.build: tags: drivers regulator build_only: true - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim diff --git a/tests/drivers/build_all/video/testcase.yaml b/tests/drivers/build_all/video/testcase.yaml index 22595c7be54..08dd430da73 100644 --- a/tests/drivers/build_all/video/testcase.yaml +++ b/tests/drivers/build_all/video/testcase.yaml @@ -5,7 +5,9 @@ common: - video tests: drivers.video.build: - platform_allow: native_posix + platform_allow: + - native_posix + - native_sim min_ram: 32 depends_on: - gpio From f713a797ef07b1c8294b456d6826cc8d94e2f959 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Sat, 23 Sep 2023 13:41:34 +0100 Subject: [PATCH 1392/1623] [nrf fromtree] drivers: gnss: add a generic NMEA GNSS driver Add a generic NMEA GNSS driver. Signed-off-by: Fabio Baltieri (cherry picked from commit d14066b061b0aeb0834473c0d991009388591656) --- drivers/gnss/CMakeLists.txt | 1 + drivers/gnss/Kconfig | 1 + drivers/gnss/Kconfig.generic | 26 ++++ drivers/gnss/gnss_nmea_generic.c | 176 +++++++++++++++++++++++ dts/bindings/gnss/gnss-nmea-generic.yaml | 32 +++++ 5 files changed, 236 insertions(+) create mode 100644 drivers/gnss/Kconfig.generic create mode 100644 drivers/gnss/gnss_nmea_generic.c create mode 100644 dts/bindings/gnss/gnss-nmea-generic.yaml diff --git a/drivers/gnss/CMakeLists.txt b/drivers/gnss/CMakeLists.txt index 6c24df4903e..cfa5c6ed210 100644 --- a/drivers/gnss/CMakeLists.txt +++ b/drivers/gnss/CMakeLists.txt @@ -7,4 +7,5 @@ zephyr_library_sources_ifdef(CONFIG_GNSS_DUMP gnss_dump.c) zephyr_library_sources_ifdef(CONFIG_GNSS_PARSE gnss_parse.c) zephyr_library_sources_ifdef(CONFIG_GNSS_NMEA0183 gnss_nmea0183.c) zephyr_library_sources_ifdef(CONFIG_GNSS_NMEA0183_MATCH gnss_nmea0183_match.c) +zephyr_library_sources_ifdef(CONFIG_GNSS_NMEA_GENERIC gnss_nmea_generic.c) zephyr_library_sources_ifdef(CONFIG_GNSS_QUECTEL_LCX6G gnss_quectel_lcx6g.c) diff --git a/drivers/gnss/Kconfig b/drivers/gnss/Kconfig index 5bdc0f530d8..2ff552940a3 100644 --- a/drivers/gnss/Kconfig +++ b/drivers/gnss/Kconfig @@ -64,6 +64,7 @@ module = GNSS module-str = gnss source "subsys/logging/Kconfig.template.log_config" +rsource "Kconfig.generic" rsource "Kconfig.quectel_lcx6g" endif diff --git a/drivers/gnss/Kconfig.generic b/drivers/gnss/Kconfig.generic new file mode 100644 index 00000000000..47fbd4a7c6c --- /dev/null +++ b/drivers/gnss/Kconfig.generic @@ -0,0 +1,26 @@ +# Copyright 2023 Google LLC +# SPDX-License-Identifier: Apache-2.0 + +config GNSS_NMEA_GENERIC + bool "Generic GNSS NMEA device" + default y + depends on GNSS + depends on DT_HAS_GNSS_NMEA_GENERIC_ENABLED + select MODEM_MODULES + select MODEM_BACKEND_UART + select MODEM_CHAT + select GNSS_PARSE + select GNSS_NMEA0183 + select GNSS_NMEA0183_MATCH + help + Generic NMEA based GNSS device. + +config GNSS_NMEA_GENERIC_SATELLITES_COUNT + int "Maximum satellite count" + depends on GNSS_SATELLITES + default 24 + help + Maximum number of satellite that the driver that can be decoded from + the GNSS device. This does not affect the number of devices that the + device is actually tracking, just how many of those can be reported + in the satellites callback. diff --git a/drivers/gnss/gnss_nmea_generic.c b/drivers/gnss/gnss_nmea_generic.c new file mode 100644 index 00000000000..d24ee2b034d --- /dev/null +++ b/drivers/gnss/gnss_nmea_generic.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2023 Trackunit Corporation + * Copyright (c) 2023 Bjarki Arge Andreasen + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#include "gnss_publish.h" +#include "gnss_nmea0183.h" +#include "gnss_nmea0183_match.h" +#include "gnss_parse.h" + +#include +LOG_MODULE_REGISTER(gnss_nmea_generic, CONFIG_GNSS_LOG_LEVEL); + +#define DT_DRV_COMPAT gnss_nmea_generic + +#define UART_RECV_BUF_SZ 128 +#define CHAT_RECV_BUF_SZ 256 +#define CHAT_ARGV_SZ 32 + +struct gnss_nmea_generic_config { + const struct device *uart; + uint16_t nmea_timeout_ms; +}; + +struct gnss_nmea_generic_data { + struct gnss_nmea0183_match_data match_data; +#if CONFIG_GNSS_SATELLITES + struct gnss_satellite satellites[CONFIG_GNSS_NMEA_GENERIC_SATELLITES_COUNT]; +#endif + + /* UART backend */ + struct modem_pipe *uart_pipe; + struct modem_backend_uart uart_backend; + uint8_t uart_backend_receive_buf[UART_RECV_BUF_SZ]; + + /* Modem chat */ + struct modem_chat chat; + uint8_t chat_receive_buf[CHAT_RECV_BUF_SZ]; + uint8_t *chat_argv[CHAT_ARGV_SZ]; + + struct k_spinlock lock; +}; + +MODEM_CHAT_MATCHES_DEFINE(unsol_matches, + MODEM_CHAT_MATCH_WILDCARD("$??GGA,", ",*", gnss_nmea0183_match_gga_callback), + MODEM_CHAT_MATCH_WILDCARD("$??RMC,", ",*", gnss_nmea0183_match_rmc_callback), +#if CONFIG_GNSS_SATELLITES + MODEM_CHAT_MATCH_WILDCARD("$??GSV,", ",*", gnss_nmea0183_match_gsv_callback), +#endif +); + +static int gnss_nmea_generic_resume(const struct device *dev) +{ + struct gnss_nmea_generic_data *data = dev->data; + int ret; + + ret = modem_pipe_open(data->uart_pipe); + if (ret < 0) { + return ret; + } + + ret = modem_chat_attach(&data->chat, data->uart_pipe); + if (ret < 0) { + modem_pipe_close(data->uart_pipe); + return ret; + } + + return ret; +} + +static struct gnss_driver_api gnss_api = { +}; + +static int gnss_nmea_generic_init_nmea0183_match(const struct device *dev) +{ + const struct gnss_nmea_generic_config *cfg = dev->config; + struct gnss_nmea_generic_data *data = dev->data; + + const struct gnss_nmea0183_match_config match_config = { + .gnss = dev, +#if CONFIG_GNSS_SATELLITES + .satellites = data->satellites, + .satellites_size = ARRAY_SIZE(data->satellites), +#endif + .timeout_ms = cfg->nmea_timeout_ms, + }; + + return gnss_nmea0183_match_init(&data->match_data, &match_config); +} + +static void gnss_nmea_generic_init_pipe(const struct device *dev) +{ + const struct gnss_nmea_generic_config *cfg = dev->config; + struct gnss_nmea_generic_data *data = dev->data; + + const struct modem_backend_uart_config uart_backend_config = { + .uart = cfg->uart, + .receive_buf = data->uart_backend_receive_buf, + .receive_buf_size = sizeof(data->uart_backend_receive_buf), + }; + + data->uart_pipe = modem_backend_uart_init(&data->uart_backend, &uart_backend_config); +} + +static uint8_t gnss_nmea_generic_char_delimiter[] = {'\r', '\n'}; + +static int gnss_nmea_generic_init_chat(const struct device *dev) +{ + struct gnss_nmea_generic_data *data = dev->data; + + const struct modem_chat_config chat_config = { + .user_data = data, + .receive_buf = data->chat_receive_buf, + .receive_buf_size = sizeof(data->chat_receive_buf), + .delimiter = gnss_nmea_generic_char_delimiter, + .delimiter_size = ARRAY_SIZE(gnss_nmea_generic_char_delimiter), + .filter = NULL, + .filter_size = 0, + .argv = data->chat_argv, + .argv_size = ARRAY_SIZE(data->chat_argv), + .unsol_matches = unsol_matches, + .unsol_matches_size = ARRAY_SIZE(unsol_matches), + .process_timeout = K_MSEC(2), + }; + + return modem_chat_init(&data->chat, &chat_config); +} + +static int gnss_nmea_generic_init(const struct device *dev) +{ + int ret; + + ret = gnss_nmea_generic_init_nmea0183_match(dev); + if (ret < 0) { + return ret; + } + + gnss_nmea_generic_init_pipe(dev); + + ret = gnss_nmea_generic_init_chat(dev); + if (ret < 0) { + return ret; + } + + ret = gnss_nmea_generic_resume(dev); + if (ret < 0) { + return ret; + } + + return 0; +} + +#define GNSS_NMEA_GENERIC(inst) \ + static struct gnss_nmea_generic_config gnss_nmea_generic_cfg_##inst = { \ + .uart = DEVICE_DT_GET(DT_INST_BUS(inst)), \ + .nmea_timeout_ms = DT_INST_PROP(inst, nmea_timeout_ms), \ + }; \ + \ + static struct gnss_nmea_generic_data gnss_nmea_generic_data_##inst; \ + \ + DEVICE_DT_INST_DEFINE(inst, gnss_nmea_generic_init, NULL, \ + &gnss_nmea_generic_data_##inst, \ + &gnss_nmea_generic_cfg_##inst, \ + POST_KERNEL, CONFIG_GNSS_INIT_PRIORITY, &gnss_api); + +DT_INST_FOREACH_STATUS_OKAY(GNSS_NMEA_GENERIC) diff --git a/dts/bindings/gnss/gnss-nmea-generic.yaml b/dts/bindings/gnss/gnss-nmea-generic.yaml new file mode 100644 index 00000000000..4be7bde1186 --- /dev/null +++ b/dts/bindings/gnss/gnss-nmea-generic.yaml @@ -0,0 +1,32 @@ +# Copyright 2023 Google LLC +# SPDX-License-Identifier: Apache-2.0 + +description: | + Generic GNSS NMEA receiver + + Implement a generic NMEA based GNSS device. + + Example configuration: + + &uart0 { + current-speed = <9600>; + ... + gnss: gnss-nmea-generic { + compatible = "gnss-nmea-generic"; + }; + }; + +compatible: "gnss-nmea-generic" + +include: + - uart-device.yaml + +properties: + nmea-timeout-ms: + type: int + default: 500 + description: | + Synchronization timeout for NMEA sentences. The NMEA parser is expecting + to receive a GGA and RMC sentences within this time frame to publish a + location data. Set accordingly to the UART datarate and location + reporting frequency. Defaults to 500ms if unspecified. From 8ba71023376cc99eb357f213feb5343c8fc0269c Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Wed, 22 Nov 2023 23:13:18 +0000 Subject: [PATCH 1393/1623] [nrf fromtree] test: add a gnss build_all test Add a generic test for GNSS devices. Signed-off-by: Fabio Baltieri (cherry picked from commit 407e9a4c74d610f57a1e1b54d3a9f5adf724495d) --- MAINTAINERS.yml | 1 + tests/drivers/build_all/gnss/CMakeLists.txt | 8 ++++++++ tests/drivers/build_all/gnss/app.overlay | 22 +++++++++++++++++++++ tests/drivers/build_all/gnss/prj.conf | 3 +++ tests/drivers/build_all/gnss/src/main.c | 10 ++++++++++ tests/drivers/build_all/gnss/testcase.yaml | 8 ++++++++ 6 files changed, 52 insertions(+) create mode 100644 tests/drivers/build_all/gnss/CMakeLists.txt create mode 100644 tests/drivers/build_all/gnss/app.overlay create mode 100644 tests/drivers/build_all/gnss/prj.conf create mode 100644 tests/drivers/build_all/gnss/src/main.c create mode 100644 tests/drivers/build_all/gnss/testcase.yaml diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index d7623c89137..5e3fb9a9a2e 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -1099,6 +1099,7 @@ Release Notes: - doc/hardware/peripherals/gnss.rst - drivers/gnss/ - include/zephyr/drivers/gnss.h + - tests/drivers/build_all/gnss/ - tests/drivers/gnss/ labels: - "area: GNSS" diff --git a/tests/drivers/build_all/gnss/CMakeLists.txt b/tests/drivers/build_all/gnss/CMakeLists.txt new file mode 100644 index 00000000000..518596a02f7 --- /dev/null +++ b/tests/drivers/build_all/gnss/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(build_all) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/drivers/build_all/gnss/app.overlay b/tests/drivers/build_all/gnss/app.overlay new file mode 100644 index 00000000000..1d43fa61525 --- /dev/null +++ b/tests/drivers/build_all/gnss/app.overlay @@ -0,0 +1,22 @@ +/* + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + test { + #address-cells = <1>; + #size-cells = <1>; + + test_uart: uart@0 { + compatible = "vnd,serial"; + reg = <0x0 0x1000>; + status = "okay"; + + gnss: gnss-nmea-generic { + compatible = "gnss-nmea-generic"; + }; + }; + }; +}; diff --git a/tests/drivers/build_all/gnss/prj.conf b/tests/drivers/build_all/gnss/prj.conf new file mode 100644 index 00000000000..945eb0df717 --- /dev/null +++ b/tests/drivers/build_all/gnss/prj.conf @@ -0,0 +1,3 @@ +CONFIG_SERIAL=y +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_GNSS=y diff --git a/tests/drivers/build_all/gnss/src/main.c b/tests/drivers/build_all/gnss/src/main.c new file mode 100644 index 00000000000..ccbdca6d36b --- /dev/null +++ b/tests/drivers/build_all/gnss/src/main.c @@ -0,0 +1,10 @@ +/* + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +int main(void) +{ + return 0; +} diff --git a/tests/drivers/build_all/gnss/testcase.yaml b/tests/drivers/build_all/gnss/testcase.yaml new file mode 100644 index 00000000000..faaec12c745 --- /dev/null +++ b/tests/drivers/build_all/gnss/testcase.yaml @@ -0,0 +1,8 @@ +common: + tags: + - drivers + - gnss + build_only: true + platform_allow: native_sim +tests: + drivers.gnss.default: {} From 670c5cfb5010fba56f99b5208cfd29da6dddfd3a Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Wed, 22 Nov 2023 23:20:52 +0000 Subject: [PATCH 1394/1623] [nrf fromtree] drivers: gnss: use absolute values for signed fractionals Printing fractionals currently put the sign on integer values on the fractional part, for example: longitude : -6.-207483333 Run an extra abs to get rid of the sign there for latitude, longitude and altitude, compute the sign separately so it works for numbers between -1 and 0 as well. Signed-off-by: Fabio Baltieri (cherry picked from commit 96b9bd472068a80c727febbc87c553b168f91299) --- drivers/gnss/gnss_dump.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/gnss/gnss_dump.c b/drivers/gnss/gnss_dump.c index 1946d65ea2e..f87b64a4946 100644 --- a/drivers/gnss/gnss_dump.c +++ b/drivers/gnss/gnss_dump.c @@ -5,6 +5,7 @@ */ #include "gnss_dump.h" +#include #include #include @@ -94,20 +95,22 @@ int gnss_dump_info(char *str, uint16_t strsize, const struct gnss_info *info) int gnss_dump_nav_data(char *str, uint16_t strsize, const struct navigation_data *nav_data) { int ret; - int32_t altitude_int; - int32_t altitude_fraction; - const char *fmt = "navigation_data: {latitude: %lli.%lli, longitude : %lli.%lli, " - "bearing %u.%u, speed %u.%u, altitude: %i.%i}"; - - altitude_int = nav_data->altitude / 1000; - altitude_fraction = nav_data->altitude % 1000; - altitude_fraction = (altitude_fraction < 0) ? -altitude_fraction : altitude_fraction; - - ret = snprintk(str, strsize, fmt, nav_data->latitude / 1000000000, - nav_data->latitude % 1000000000, nav_data->longitude / 1000000000, - nav_data->longitude % 1000000000, nav_data->bearing / 1000, - nav_data->bearing % 1000, nav_data->speed / 1000, nav_data->speed % 1000, - altitude_int, altitude_fraction); + const char *fmt = "navigation_data: {latitude: %s%lli.%09lli, longitude : %s%lli.%09lli, " + "bearing %u.%03u, speed %u.%03u, altitude: %s%i.%03i}"; + char *lat_sign = nav_data->latitude < 0 ? "-" : ""; + char *lon_sign = nav_data->longitude < 0 ? "-" : ""; + char *alt_sign = nav_data->altitude < 0 ? "-" : ""; + + ret = snprintk(str, strsize, fmt, + lat_sign, + llabs(nav_data->latitude) / 1000000000, + llabs(nav_data->latitude) % 1000000000, + lon_sign, + llabs(nav_data->longitude) / 1000000000, + llabs(nav_data->longitude) % 1000000000, + nav_data->bearing / 1000, nav_data->bearing % 1000, + nav_data->speed / 1000, nav_data->speed % 1000, + alt_sign, abs(nav_data->altitude) / 1000, abs(nav_data->altitude) % 1000); return (strsize < ret) ? -ENOMEM : 0; } From 1dd9a7934396159c0c920e02b5bc3cb2ac01268a Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Sun, 26 Nov 2023 15:35:04 +0000 Subject: [PATCH 1395/1623] [nrf fromtree] drivers: gnss: move gnss_publish.h in include/ Move gnss_publish.h in include/ so that out of tree drivers and tests can use it. Signed-off-by: Fabio Baltieri (cherry picked from commit f9ab0503069ab7456ed11df0c5af4c013482663f) --- MAINTAINERS.yml | 1 + drivers/gnss/gnss_nmea0183_match.c | 2 +- drivers/gnss/gnss_nmea_generic.c | 2 +- drivers/gnss/gnss_publish.c | 2 +- drivers/gnss/gnss_quectel_lcx6g.c | 2 +- {drivers => include/zephyr/drivers}/gnss/gnss_publish.h | 0 6 files changed, 5 insertions(+), 4 deletions(-) rename {drivers => include/zephyr/drivers}/gnss/gnss_publish.h (100%) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 5e3fb9a9a2e..c6f75fd234d 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -1099,6 +1099,7 @@ Release Notes: - doc/hardware/peripherals/gnss.rst - drivers/gnss/ - include/zephyr/drivers/gnss.h + - include/zephyr/drivers/gnss/ - tests/drivers/build_all/gnss/ - tests/drivers/gnss/ labels: diff --git a/drivers/gnss/gnss_nmea0183_match.c b/drivers/gnss/gnss_nmea0183_match.c index 3fe3b159fdb..2b971937c8d 100644 --- a/drivers/gnss/gnss_nmea0183_match.c +++ b/drivers/gnss/gnss_nmea0183_match.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include @@ -11,7 +12,6 @@ #include "gnss_nmea0183.h" #include "gnss_nmea0183_match.h" -#include "gnss_publish.h" static bool gnss_nmea0183_match_timed_out(struct gnss_nmea0183_match_data *data) { diff --git a/drivers/gnss/gnss_nmea_generic.c b/drivers/gnss/gnss_nmea_generic.c index d24ee2b034d..0e7611ba495 100644 --- a/drivers/gnss/gnss_nmea_generic.c +++ b/drivers/gnss/gnss_nmea_generic.c @@ -7,13 +7,13 @@ */ #include +#include #include #include #include #include #include -#include "gnss_publish.h" #include "gnss_nmea0183.h" #include "gnss_nmea0183_match.h" #include "gnss_parse.h" diff --git a/drivers/gnss/gnss_publish.c b/drivers/gnss/gnss_publish.c index 98e3a2e5e19..7ddfa5e09fe 100644 --- a/drivers/gnss/gnss_publish.c +++ b/drivers/gnss/gnss_publish.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "gnss_publish.h" +#include #include #include diff --git a/drivers/gnss/gnss_quectel_lcx6g.c b/drivers/gnss/gnss_quectel_lcx6g.c index 0ca7f5203ac..9565d46cdfb 100644 --- a/drivers/gnss/gnss_quectel_lcx6g.c +++ b/drivers/gnss/gnss_quectel_lcx6g.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -14,7 +15,6 @@ #include #include -#include "gnss_publish.h" #include "gnss_nmea0183.h" #include "gnss_nmea0183_match.h" #include "gnss_parse.h" diff --git a/drivers/gnss/gnss_publish.h b/include/zephyr/drivers/gnss/gnss_publish.h similarity index 100% rename from drivers/gnss/gnss_publish.h rename to include/zephyr/drivers/gnss/gnss_publish.h From d931e8844a8fb97c19ea8b5c17ac20bb4e2bf476 Mon Sep 17 00:00:00 2001 From: Emil Lindqvist Date: Thu, 9 Nov 2023 14:09:57 +0100 Subject: [PATCH 1396/1623] [nrf fromtree] modem: modem_cellular: add PAP authentication support Some modems or networks require PAP authentication for successful LCP handshake. Tested on U-blox SARA-R5 with zephyr,gsm-ppp. Signed-off-by: Emil Lindqvist (cherry picked from commit 79c2fafe6a6beac219462213b2f96d6fcc39437e) --- drivers/modem/Kconfig.cellular | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/modem/Kconfig.cellular b/drivers/modem/Kconfig.cellular index 7817fb599e3..72e6a74acbb 100644 --- a/drivers/modem/Kconfig.cellular +++ b/drivers/modem/Kconfig.cellular @@ -11,6 +11,7 @@ config MODEM_CELLULAR select MODEM_BACKEND_UART select RING_BUFFER select NET_L2_PPP_OPTION_MRU + select NET_L2_PPP_PAP depends on (DT_HAS_QUECTEL_BG95_ENABLED || DT_HAS_ZEPHYR_GSM_PPP_ENABLED || \ DT_HAS_SIMCOM_SIM7080_ENABLED || DT_HAS_U_BLOX_SARA_R4_ENABLED || \ DT_HAS_SWIR_HL7800_ENABLED || DT_HAS_TELIT_ME910G1_ENABLED || \ From 26d9f102455a501fb2be6d7f808c99a2e43a0563 Mon Sep 17 00:00:00 2001 From: Emil Lindqvist Date: Mon, 4 Dec 2023 10:25:09 +0100 Subject: [PATCH 1397/1623] [nrf fromtree] modem: modem_cellular: add U-blox SARA-R5 as modem U-blox SARA-R4 already exists but the behavior is different, requiring a separate driver instance. For instance, R5 autostarts, so this commit also adds support for skipping power on pulse. Signed-off-by: Emil Lindqvist (cherry picked from commit 1cd7c55af9758f336d5ed1b453ef61970c1cd125) --- drivers/modem/Kconfig.cellular | 4 +- drivers/modem/modem_cellular.c | 84 ++++++++++++++++++++++++++ dts/bindings/modem/u-blox,sara-r5.yaml | 15 +++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 dts/bindings/modem/u-blox,sara-r5.yaml diff --git a/drivers/modem/Kconfig.cellular b/drivers/modem/Kconfig.cellular index 72e6a74acbb..0460cda8d96 100644 --- a/drivers/modem/Kconfig.cellular +++ b/drivers/modem/Kconfig.cellular @@ -14,8 +14,8 @@ config MODEM_CELLULAR select NET_L2_PPP_PAP depends on (DT_HAS_QUECTEL_BG95_ENABLED || DT_HAS_ZEPHYR_GSM_PPP_ENABLED || \ DT_HAS_SIMCOM_SIM7080_ENABLED || DT_HAS_U_BLOX_SARA_R4_ENABLED || \ - DT_HAS_SWIR_HL7800_ENABLED || DT_HAS_TELIT_ME910G1_ENABLED || \ - DT_HAS_QUECTEL_EG25_G_ENABLED) + DT_HAS_U_BLOX_SARA_R5_ENABLED || DT_HAS_SWIR_HL7800_ENABLED || \ + DT_HAS_TELIT_ME910G1_ENABLED || DT_HAS_QUECTEL_EG25_G_ENABLED) help This driver uses the generic 3gpp AT commands, along with the standard protocols CMUX and PPP, to configure diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index c3b97f0b618..a038da1805e 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -114,6 +114,7 @@ struct modem_cellular_config { const uint16_t reset_pulse_duration_ms; const uint16_t startup_time_ms; const uint16_t shutdown_time_ms; + const bool autostarts; const struct modem_chat_script *init_chat_script; const struct modem_chat_script *dial_chat_script; const struct modem_chat_script *periodic_chat_script; @@ -444,6 +445,11 @@ static void modem_cellular_idle_event_handler(struct modem_cellular_data *data, switch (evt) { case MODEM_CELLULAR_EVENT_RESUME: + if (config->autostarts) { + modem_cellular_enter_state(data, MODEM_CELLULAR_STATE_AWAIT_POWER_ON); + break; + } + if (modem_cellular_gpio_is_enabled(&config->power_gpio)) { modem_cellular_enter_state(data, MODEM_CELLULAR_STATE_POWER_ON_PULSE); break; @@ -1538,6 +1544,51 @@ MODEM_CHAT_SCRIPT_DEFINE(u_blox_sara_r4_periodic_chat_script, modem_cellular_chat_callback_handler, 4); #endif +#if DT_HAS_COMPAT_STATUS_OKAY(u_blox_sara_r5) +MODEM_CHAT_SCRIPT_CMDS_DEFINE(u_blox_sara_r5_init_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP_NONE("AT", 100), + MODEM_CHAT_SCRIPT_CMD_RESP_NONE("AT", 100), + MODEM_CHAT_SCRIPT_CMD_RESP_NONE("AT", 100), + MODEM_CHAT_SCRIPT_CMD_RESP_NONE("AT", 100), + MODEM_CHAT_SCRIPT_CMD_RESP("ATE0", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CFUN=4", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CMEE=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CREG=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGSN", imei_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMM", cgmm_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CMUX=0,0,5,127", ok_match)); + +MODEM_CHAT_SCRIPT_DEFINE(u_blox_sara_r5_init_chat_script, u_blox_sara_r5_init_chat_script_cmds, + abort_matches, modem_cellular_chat_callback_handler, 10); + +MODEM_CHAT_SCRIPT_CMDS_DEFINE(u_blox_sara_r5_dial_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP_MULT("AT+CGACT=0,1", allow_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGDCONT=1,\"IP\"," + "\""CONFIG_MODEM_CELLULAR_APN"\"", + ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CFUN=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP_NONE("ATD*99***1#", 0),); + +MODEM_CHAT_SCRIPT_DEFINE(u_blox_sara_r5_dial_chat_script, u_blox_sara_r5_dial_chat_script_cmds, + dial_abort_matches, modem_cellular_chat_callback_handler, 10); + +MODEM_CHAT_SCRIPT_CMDS_DEFINE(u_blox_sara_r5_periodic_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG?", ok_match)); + +MODEM_CHAT_SCRIPT_DEFINE(u_blox_sara_r5_periodic_chat_script, + u_blox_sara_r5_periodic_chat_script_cmds, abort_matches, + modem_cellular_chat_callback_handler, 4); +#endif + #if DT_HAS_COMPAT_STATUS_OKAY(swir_hl7800) MODEM_CHAT_SCRIPT_CMDS_DEFINE(swir_hl7800_init_chat_script_cmds, MODEM_CHAT_SCRIPT_CMD_RESP_NONE("AT", 100), @@ -1778,6 +1829,35 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, &MODEM_CELLULAR_INST_NAME(data, inst), \ &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, NULL); +#define MODEM_CELLULAR_DEVICE_U_BLOX_SARA_R5(inst) \ + MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ + \ + static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \ + .chat_delimiter = {'\r'}, \ + .chat_filter = {'\n'}, \ + .ppp = &MODEM_CELLULAR_INST_NAME(ppp, inst), \ + }; \ + \ + static struct modem_cellular_config MODEM_CELLULAR_INST_NAME(config, inst) = { \ + .uart = DEVICE_DT_GET(DT_INST_BUS(inst)), \ + .power_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, mdm_power_gpios, {}), \ + .reset_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, mdm_reset_gpios, {}), \ + .autostarts = true, \ + .power_pulse_duration_ms = 1500, \ + .reset_pulse_duration_ms = 100, \ + .startup_time_ms = 1500, \ + .shutdown_time_ms = 13000, \ + .init_chat_script = &u_blox_sara_r5_init_chat_script, \ + .dial_chat_script = &u_blox_sara_r5_dial_chat_script, \ + .periodic_chat_script = &u_blox_sara_r5_periodic_chat_script, \ + }; \ + \ + PM_DEVICE_DT_INST_DEFINE(inst, modem_cellular_pm_action); \ + \ + DEVICE_DT_INST_DEFINE(inst, modem_cellular_init, PM_DEVICE_DT_INST_GET(inst), \ + &MODEM_CELLULAR_INST_NAME(data, inst), \ + &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, NULL); + #define MODEM_CELLULAR_DEVICE_SWIR_HL7800(inst) \ MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ \ @@ -1854,6 +1934,10 @@ DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_SIMCOM_SIM7080) DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_U_BLOX_SARA_R4) #undef DT_DRV_COMPAT +#define DT_DRV_COMPAT u_blox_sara_r5 +DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_U_BLOX_SARA_R5) +#undef DT_DRV_COMPAT + #define DT_DRV_COMPAT swir_hl7800 DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_SWIR_HL7800) #undef DT_DRV_COMPAT diff --git a/dts/bindings/modem/u-blox,sara-r5.yaml b/dts/bindings/modem/u-blox,sara-r5.yaml new file mode 100644 index 00000000000..af6c3318fd0 --- /dev/null +++ b/dts/bindings/modem/u-blox,sara-r5.yaml @@ -0,0 +1,15 @@ +# Copyright (c) 2023 Emil Lindqvist +# SPDX-License-Identifier: Apache-2.0 + +description: u-blox SARA-R5 modem + +compatible: "u-blox,sara-r5" + +include: uart-device.yaml + +properties: + mdm-power-gpios: + type: phandle-array + + mdm-reset-gpios: + type: phandle-array From 256ffa99b6cdab1d04de0a41337b8547fe141473 Mon Sep 17 00:00:00 2001 From: Juha Heiskanen Date: Wed, 29 Nov 2023 17:51:11 +0200 Subject: [PATCH 1398/1623] [nrf fromtree] modem: modem_cmux: Support modem CMUX DCE role Added missing command and message handling for use existing modem cmux for DCE role. DCE CMUX connection can be now initialized from DTE side. Signed-off-by: Juha Heiskanen (cherry picked from commit 093efc444d65a6477688b5884915be5151fc62f1) --- subsys/modem/modem_cmux.c | 108 ++++++++++++++++++++++++++++++++++---- 1 file changed, 99 insertions(+), 9 deletions(-) diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index 9c95e124fc2..29ff41c1ca7 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -340,9 +340,11 @@ static void modem_cmux_acknowledge_received_frame(struct modem_cmux *cmux) } } -static void modem_cmux_on_msc_command(struct modem_cmux *cmux) +static void modem_cmux_on_msc_command(struct modem_cmux *cmux, struct modem_cmux_command *command) { - modem_cmux_acknowledge_received_frame(cmux); + if (command->type.cr) { + modem_cmux_acknowledge_received_frame(cmux); + } } static void modem_cmux_on_fcon_command(struct modem_cmux *cmux) @@ -361,17 +363,27 @@ static void modem_cmux_on_fcoff_command(struct modem_cmux *cmux) modem_cmux_acknowledge_received_frame(cmux); } -static void modem_cmux_on_cld_command(struct modem_cmux *cmux) +static void modem_cmux_on_cld_command(struct modem_cmux *cmux, struct modem_cmux_command *command) { - if (cmux->state != MODEM_CMUX_STATE_DISCONNECTING) { + if (command->type.cr) { + modem_cmux_acknowledge_received_frame(cmux); + } + + if (cmux->state != MODEM_CMUX_STATE_DISCONNECTING && + cmux->state != MODEM_CMUX_STATE_CONNECTED) { LOG_WRN("Unexpected close down"); + return; + } + + if (cmux->state == MODEM_CMUX_STATE_DISCONNECTING) { + k_work_cancel_delayable(&cmux->disconnect_work); } cmux->state = MODEM_CMUX_STATE_DISCONNECTED; k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER); cmux->flow_control_on = false; k_mutex_unlock(&cmux->transmit_rb_lock); - k_work_cancel_delayable(&cmux->disconnect_work); + modem_cmux_raise_event(cmux, MODEM_CMUX_EVENT_DISCONNECTED); k_event_clear(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT); k_event_post(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT); @@ -381,7 +393,6 @@ static void modem_cmux_on_control_frame_ua(struct modem_cmux *cmux) { if (cmux->state != MODEM_CMUX_STATE_CONNECTING) { LOG_DBG("Unexpected UA frame"); - return; } @@ -414,11 +425,11 @@ static void modem_cmux_on_control_frame_uih(struct modem_cmux *cmux) switch (command->type.value) { case MODEM_CMUX_COMMAND_CLD: - modem_cmux_on_cld_command(cmux); + modem_cmux_on_cld_command(cmux, command); break; case MODEM_CMUX_COMMAND_MSC: - modem_cmux_on_msc_command(cmux); + modem_cmux_on_msc_command(cmux, command); break; case MODEM_CMUX_COMMAND_FCON: @@ -435,6 +446,40 @@ static void modem_cmux_on_control_frame_uih(struct modem_cmux *cmux) } } +static void modem_cmux_connect_response_transmit(struct modem_cmux *cmux) +{ + struct modem_cmux_frame frame = { + .dlci_address = cmux->frame.dlci_address, + .cr = cmux->frame.cr, + .pf = cmux->frame.pf, + .type = MODEM_CMUX_FRAME_TYPE_UA, + .data = NULL, + .data_len = 0, + }; + + LOG_DBG("SABM/DISC request state send ack"); + modem_cmux_transmit_cmd_frame(cmux, &frame); +} + +static void modem_cmux_on_control_frame_sabm(struct modem_cmux *cmux) +{ + modem_cmux_connect_response_transmit(cmux); + + if ((cmux->state == MODEM_CMUX_STATE_CONNECTED) || + (cmux->state == MODEM_CMUX_STATE_DISCONNECTING)) { + LOG_DBG("Connect request not accepted"); + return; + } + + cmux->state = MODEM_CMUX_STATE_CONNECTED; + k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER); + cmux->flow_control_on = true; + k_mutex_unlock(&cmux->transmit_rb_lock); + modem_cmux_raise_event(cmux, MODEM_CMUX_EVENT_CONNECTED); + k_event_clear(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT); + k_event_post(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT); +} + static void modem_cmux_on_control_frame(struct modem_cmux *cmux) { modem_cmux_log_received_frame(&cmux->frame); @@ -448,6 +493,10 @@ static void modem_cmux_on_control_frame(struct modem_cmux *cmux) modem_cmux_on_control_frame_uih(cmux); break; + case MODEM_CMUX_FRAME_TYPE_SABM: + modem_cmux_on_control_frame_sabm(cmux); + break; + default: LOG_WRN("Unknown %s frame type", "control"); break; @@ -509,6 +558,39 @@ static void modem_cmux_on_dlci_frame_uih(struct modem_cmux_dlci *dlci) modem_pipe_notify_receive_ready(&dlci->pipe); } +static void modem_cmux_on_dlci_frame_sabm(struct modem_cmux_dlci *dlci) +{ + struct modem_cmux *cmux = dlci->cmux; + + modem_cmux_connect_response_transmit(cmux); + + if (dlci->state == MODEM_CMUX_DLCI_STATE_OPEN) { + LOG_DBG("Unexpected SABM frame"); + return; + } + + dlci->state = MODEM_CMUX_DLCI_STATE_OPEN; + modem_pipe_notify_opened(&dlci->pipe); + k_mutex_lock(&dlci->receive_rb_lock, K_FOREVER); + ring_buf_reset(&dlci->receive_rb); + k_mutex_unlock(&dlci->receive_rb_lock); +} + +static void modem_cmux_on_dlci_frame_disc(struct modem_cmux_dlci *dlci) +{ + struct modem_cmux *cmux = dlci->cmux; + + modem_cmux_connect_response_transmit(cmux); + + if (dlci->state != MODEM_CMUX_DLCI_STATE_OPEN) { + LOG_DBG("Unexpected Disc frame"); + return; + } + + dlci->state = MODEM_CMUX_DLCI_STATE_CLOSED; + modem_pipe_notify_closed(&dlci->pipe); +} + static void modem_cmux_on_dlci_frame(struct modem_cmux *cmux) { struct modem_cmux_dlci *dlci; @@ -532,6 +614,14 @@ static void modem_cmux_on_dlci_frame(struct modem_cmux *cmux) modem_cmux_on_dlci_frame_uih(dlci); break; + case MODEM_CMUX_FRAME_TYPE_SABM: + modem_cmux_on_dlci_frame_sabm(dlci); + break; + + case MODEM_CMUX_FRAME_TYPE_DISC: + modem_cmux_on_dlci_frame_disc(dlci); + break; + default: LOG_WRN("Unknown %s frame type", "DLCI"); break; @@ -996,6 +1086,7 @@ void modem_cmux_init(struct modem_cmux *cmux, const struct modem_cmux_config *co k_work_init_delayable(&cmux->connect_work, modem_cmux_connect_handler); k_work_init_delayable(&cmux->disconnect_work, modem_cmux_disconnect_handler); k_event_init(&cmux->event); + k_event_clear(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT); k_event_post(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT); } @@ -1071,7 +1162,6 @@ int modem_cmux_disconnect(struct modem_cmux *cmux) if (ret < 0) { return ret; } - if (k_event_wait(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT, false, MODEM_CMUX_T2_TIMEOUT) == 0) { return -EAGAIN; From 8dcf22f4992d5c1d509e96b78454d46956a1269d Mon Sep 17 00:00:00 2001 From: Juha Heiskanen Date: Wed, 29 Nov 2023 17:47:55 +0200 Subject: [PATCH 1399/1623] [nrf fromtree] tests: modem: Modem backend mock update Added possibility for link 2 modem mock instance for validating P2P communication without any data stubbing. Signed-off-by: Juha Heiskanen (cherry picked from commit 6943cd497c8e0e81816364f6570641d367172da4) --- tests/subsys/modem/mock/modem_backend_mock.c | 15 +++++++++++++++ tests/subsys/modem/mock/modem_backend_mock.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/tests/subsys/modem/mock/modem_backend_mock.c b/tests/subsys/modem/mock/modem_backend_mock.c index 55c5679f35f..0a12fc43674 100644 --- a/tests/subsys/modem/mock/modem_backend_mock.c +++ b/tests/subsys/modem/mock/modem_backend_mock.c @@ -42,6 +42,15 @@ static int modem_backend_mock_transmit(void *data, const uint8_t *buf, size_t si int ret; size = (mock->limit < size) ? mock->limit : size; + + if (mock->bridge) { + struct modem_backend_mock *t_mock = mock->bridge; + + ret = ring_buf_put(&t_mock->rx_rb, buf, size); + k_work_submit(&t_mock->received_work_item.work); + return ret; + } + ret = ring_buf_put(&mock->tx_rb, buf, size); if (modem_backend_mock_update(mock, buf, size)) { modem_backend_mock_put(mock, mock->transaction->put, @@ -130,3 +139,9 @@ void modem_backend_mock_prime(struct modem_backend_mock *mock, mock->transaction = transaction; mock->transaction_match_cnt = 0; } + +void modem_backend_mock_bridge(struct modem_backend_mock *mock_a, struct modem_backend_mock *mock_b) +{ + mock_a->bridge = mock_b; + mock_b->bridge = mock_a; +} diff --git a/tests/subsys/modem/mock/modem_backend_mock.h b/tests/subsys/modem/mock/modem_backend_mock.h index 1c221963aa8..7d9ad11bf41 100644 --- a/tests/subsys/modem/mock/modem_backend_mock.h +++ b/tests/subsys/modem/mock/modem_backend_mock.h @@ -41,6 +41,8 @@ struct modem_backend_mock { /* Max allowed read/write size */ size_t limit; + /* Mock Brige pair */ + struct modem_backend_mock *bridge; }; struct modem_backend_mock_config { @@ -63,4 +65,7 @@ void modem_backend_mock_put(struct modem_backend_mock *mock, const uint8_t *buf, void modem_backend_mock_prime(struct modem_backend_mock *mock, const struct modem_backend_mock_transaction *transaction); +void modem_backend_mock_bridge(struct modem_backend_mock *mock_a, + struct modem_backend_mock *mock_b); + #endif /* ZEPHYR_DRIVERS_MODEM_MODEM_PIPE_MOCK */ From 018a26c48cfcb5a5d384c66686313eff65c86377 Mon Sep 17 00:00:00 2001 From: Juha Heiskanen Date: Wed, 29 Nov 2023 17:43:05 +0200 Subject: [PATCH 1400/1623] [nrf fromtree] tests: mode: Modem CMUX DTE / DCE test Added unite test for for validate modem CMUX DTE & DCE role communication together. Signed-off-by: Juha Heiskanen (cherry picked from commit 34d4e503745b7f2b6b572f9c994d7140214c6847) --- .../modem/modem_cmux_pair/CMakeLists.txt | 9 + tests/subsys/modem/modem_cmux_pair/prj.conf | 9 + tests/subsys/modem/modem_cmux_pair/src/main.c | 596 ++++++++++++++++++ .../modem/modem_cmux_pair/testcase.yaml | 8 + 4 files changed, 622 insertions(+) create mode 100644 tests/subsys/modem/modem_cmux_pair/CMakeLists.txt create mode 100644 tests/subsys/modem/modem_cmux_pair/prj.conf create mode 100644 tests/subsys/modem/modem_cmux_pair/src/main.c create mode 100644 tests/subsys/modem/modem_cmux_pair/testcase.yaml diff --git a/tests/subsys/modem/modem_cmux_pair/CMakeLists.txt b/tests/subsys/modem/modem_cmux_pair/CMakeLists.txt new file mode 100644 index 00000000000..00efcc5695b --- /dev/null +++ b/tests/subsys/modem/modem_cmux_pair/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(modem_cmux_pair_test) + +target_sources(app PRIVATE src/main.c ../mock/modem_backend_mock.c) +target_include_directories(app PRIVATE ../mock) diff --git a/tests/subsys/modem/modem_cmux_pair/prj.conf b/tests/subsys/modem/modem_cmux_pair/prj.conf new file mode 100644 index 00000000000..bf21fcb42ac --- /dev/null +++ b/tests/subsys/modem/modem_cmux_pair/prj.conf @@ -0,0 +1,9 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_NO_OPTIMIZATIONS=y + +CONFIG_MODEM_MODULES=y +CONFIG_MODEM_CMUX=y + +CONFIG_ZTEST=y diff --git a/tests/subsys/modem/modem_cmux_pair/src/main.c b/tests/subsys/modem/modem_cmux_pair/src/main.c new file mode 100644 index 00000000000..6c38fd7e98b --- /dev/null +++ b/tests/subsys/modem/modem_cmux_pair/src/main.c @@ -0,0 +1,596 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include + +/* CMUX state flags */ +#define EVENT_CMUX_CONNECTED BIT(0) +#define EVENT_CMUX_DLCI1_OPEN BIT(1) +#define EVENT_CMUX_DLCI2_OPEN BIT(2) +#define EVENT_CMUX_DLCI1_CLOSED BIT(3) +#define EVENT_CMUX_DLCI2_CLOSED BIT(4) +#define EVENT_CMUX_DISCONNECTED BIT(5) +#define EVENT_CMUX_DLCI1_RX_DATA BIT(6) +#define EVENT_CMUX_DLCI2_RX_DATA BIT(7) + +/* CMUX DTE variables */ +static struct modem_cmux cmux_dte; +static uint8_t cmux_receive_buf[127]; +static uint8_t cmux_transmit_buf[149]; +static struct modem_cmux_dlci dlci1; +static struct modem_cmux_dlci dlci2; +static struct modem_pipe *dlci1_pipe; +static struct modem_pipe *dlci2_pipe; + +/* CMUX DCE variables */ +static struct modem_cmux cmux_dce; +static uint8_t cmux_receive_buf_dce[127]; +static uint8_t cmux_transmit_buf_dce[149]; +static struct modem_cmux_dlci dlci1_dce; +static struct modem_cmux_dlci dlci2_dce; +static struct modem_pipe *dlci1_pipe_dce; +static struct modem_pipe *dlci2_pipe_dce; + +/* DTE & DCE Event */ +static struct k_event cmux_event_dte; +static struct k_event cmux_event_dce; + +/* Backend MOCK */ +static struct modem_backend_mock bus_mock_dte; +static struct modem_backend_mock bus_mock_dce; +static uint8_t bus_mock_rx_buf[2048]; +static uint8_t bus_mock_tx_buf[2048]; +static uint8_t bus_mock_rx_buf_dce[2048]; +static uint8_t bus_mock_tx_buf_dce[2048]; +static struct modem_pipe *bus_mock_pipe; +static struct modem_pipe *bus_mock_pipe_dce; + +static uint8_t dlci1_receive_buf[127]; +static uint8_t dlci2_receive_buf[127]; +static uint8_t dlci1_receive_buf_dce[127]; +static uint8_t dlci2_receive_buf_dce[127]; + +static uint8_t buffer1[2048]; +static uint8_t buffer2[2048]; + +static void test_dlci1_pipe_cb(struct modem_pipe *pipe, enum modem_pipe_event event, + void *user_data) +{ + switch (event) { + case MODEM_PIPE_EVENT_OPENED: + k_event_post(&cmux_event_dte, EVENT_CMUX_DLCI1_OPEN); + break; + + case MODEM_PIPE_EVENT_CLOSED: + k_event_post(&cmux_event_dte, EVENT_CMUX_DLCI1_CLOSED); + break; + + case MODEM_PIPE_EVENT_RECEIVE_READY: + k_event_post(&cmux_event_dte, EVENT_CMUX_DLCI1_RX_DATA); + break; + + default: + break; + } +} + +static void test_dlci2_pipe_cb(struct modem_pipe *pipe, enum modem_pipe_event event, + void *user_data) +{ + switch (event) { + case MODEM_PIPE_EVENT_OPENED: + k_event_post(&cmux_event_dte, EVENT_CMUX_DLCI2_OPEN); + break; + + case MODEM_PIPE_EVENT_CLOSED: + k_event_post(&cmux_event_dte, EVENT_CMUX_DLCI2_CLOSED); + break; + case MODEM_PIPE_EVENT_RECEIVE_READY: + k_event_post(&cmux_event_dte, EVENT_CMUX_DLCI2_RX_DATA); + break; + + default: + break; + } +} + +static void test_dlci1_pipe_cb_dce(struct modem_pipe *pipe, enum modem_pipe_event event, + void *user_data) +{ + switch (event) { + case MODEM_PIPE_EVENT_OPENED: + k_event_post(&cmux_event_dce, EVENT_CMUX_DLCI1_OPEN); + break; + + case MODEM_PIPE_EVENT_CLOSED: + k_event_post(&cmux_event_dce, EVENT_CMUX_DLCI1_CLOSED); + break; + + case MODEM_PIPE_EVENT_RECEIVE_READY: + k_event_post(&cmux_event_dce, EVENT_CMUX_DLCI1_RX_DATA); + break; + + default: + break; + } +} + +static void test_dlci2_pipe_cb_dce(struct modem_pipe *pipe, enum modem_pipe_event event, + void *user_data) +{ + switch (event) { + case MODEM_PIPE_EVENT_OPENED: + k_event_post(&cmux_event_dce, EVENT_CMUX_DLCI2_OPEN); + break; + + case MODEM_PIPE_EVENT_CLOSED: + k_event_post(&cmux_event_dce, EVENT_CMUX_DLCI2_CLOSED); + break; + case MODEM_PIPE_EVENT_RECEIVE_READY: + k_event_post(&cmux_event_dce, EVENT_CMUX_DLCI2_RX_DATA); + break; + + default: + break; + } +} + +/*************************************************************************************************/ +/* DLCI2 AT CMUX frames */ +/*************************************************************************************************/ +static uint8_t cmux_frame_data_dlci2_at_cgdcont[] = { + 0x41, 0x54, 0x2B, 0x43, 0x47, 0x44, 0x43, 0x4F, 0x4E, 0x54, 0x3D, + 0x31, 0x2C, 0x22, 0x49, 0x50, 0x22, 0x2C, 0x22, 0x74, 0x72, 0x61, + 0x63, 0x6B, 0x75, 0x6E, 0x69, 0x74, 0x2E, 0x6D, 0x32, 0x6D, 0x22}; + +static uint8_t cmux_frame_data_dlci2_at_newline[] = {0x0D, 0x0A}; + +/*************************************************************************************************/ +/* DLCI1 AT CMUX frames */ +/*************************************************************************************************/ +static uint8_t cmux_frame_data_dlci1_at_at[] = {0x41, 0x54}; + +static uint8_t cmux_frame_data_dlci1_at_newline[] = {0x0D, 0x0A}; + +/*************************************************************************************************/ +/* DLCI2 PPP CMUX frames */ +/*************************************************************************************************/ +static uint8_t cmux_frame_data_dlci2_ppp_52[] = { + 0x7E, 0xFF, 0x7D, 0x23, 0xC0, 0x21, 0x7D, 0x21, 0x7D, 0x20, 0x7D, 0x20, 0x7D, + 0x38, 0x7D, 0x22, 0x7D, 0x26, 0x7D, 0x20, 0x7D, 0x20, 0x7D, 0x20, 0x7D, 0x20, + 0x7D, 0x23, 0x7D, 0x24, 0xC0, 0x23, 0x7D, 0x25, 0x7D, 0x26, 0x53, 0x96, 0x7D, + 0x38, 0xAA, 0x7D, 0x27, 0x7D, 0x22, 0x7D, 0x28, 0x7D, 0x22, 0xD5, 0xA8, 0x7E}; + +static uint8_t cmux_frame_data_dlci2_ppp_18[] = {0x7E, 0xFF, 0x7D, 0x23, 0xC0, 0x21, + 0x7D, 0x22, 0x7D, 0x21, 0x7D, 0x20, + 0x7D, 0x24, 0x7D, 0x3C, 0x90, 0x7E}; + +static void test_cmux_ctrl_cb(struct modem_cmux *cmux, enum modem_cmux_event event, void *user_data) +{ + if (event == MODEM_CMUX_EVENT_CONNECTED) { + k_event_post(&cmux_event_dte, EVENT_CMUX_CONNECTED); + return; + } + + if (event == MODEM_CMUX_EVENT_DISCONNECTED) { + k_event_post(&cmux_event_dte, EVENT_CMUX_DISCONNECTED); + return; + } +} + +static void test_cmux_ctrl_cb_dce(struct modem_cmux *cmux, enum modem_cmux_event event, + void *user_data) +{ + if (event == MODEM_CMUX_EVENT_CONNECTED) { + k_event_post(&cmux_event_dce, EVENT_CMUX_CONNECTED); + return; + } + + if (event == MODEM_CMUX_EVENT_DISCONNECTED) { + k_event_post(&cmux_event_dce, EVENT_CMUX_DISCONNECTED); + return; + } +} + +static void cmux_dte_init(void) +{ + struct modem_cmux_dlci_config dlci1_config = { + .dlci_address = 1, + .receive_buf = dlci1_receive_buf, + .receive_buf_size = sizeof(dlci1_receive_buf), + }; + + struct modem_cmux_dlci_config dlci2_config = { + .dlci_address = 2, + .receive_buf = dlci2_receive_buf, + .receive_buf_size = sizeof(dlci2_receive_buf), + }; + + struct modem_cmux_config cmux_config = { + .callback = test_cmux_ctrl_cb, + .user_data = NULL, + .receive_buf = cmux_receive_buf, + .receive_buf_size = sizeof(cmux_receive_buf), + .transmit_buf = cmux_transmit_buf, + .transmit_buf_size = ARRAY_SIZE(cmux_transmit_buf), + }; + + const struct modem_backend_mock_config bus_mock_config = { + .rx_buf = bus_mock_rx_buf, + .rx_buf_size = sizeof(bus_mock_rx_buf), + .tx_buf = bus_mock_tx_buf, + .tx_buf_size = sizeof(bus_mock_tx_buf), + .limit = 32, + }; + + modem_cmux_init(&cmux_dte, &cmux_config); + dlci1_pipe = modem_cmux_dlci_init(&cmux_dte, &dlci1, &dlci1_config); + dlci2_pipe = modem_cmux_dlci_init(&cmux_dte, &dlci2, &dlci2_config); + /* Init Backend DTE */ + bus_mock_pipe = modem_backend_mock_init(&bus_mock_dte, &bus_mock_config); + __ASSERT_NO_MSG(modem_pipe_open(bus_mock_pipe) == 0); + __ASSERT_NO_MSG(modem_cmux_attach(&cmux_dte, bus_mock_pipe) == 0); + modem_pipe_attach(dlci1_pipe, test_dlci1_pipe_cb, NULL); + modem_pipe_attach(dlci2_pipe, test_dlci2_pipe_cb, NULL); +} + +static void cmux_dce_init(void) +{ + struct modem_cmux_dlci_config dlci1_config = { + .dlci_address = 1, + .receive_buf = dlci1_receive_buf_dce, + .receive_buf_size = sizeof(dlci1_receive_buf_dce), + }; + + struct modem_cmux_dlci_config dlci2_config = { + .dlci_address = 2, + .receive_buf = dlci2_receive_buf_dce, + .receive_buf_size = sizeof(dlci2_receive_buf_dce), + }; + + struct modem_cmux_config cmux_config_dce = { + .callback = test_cmux_ctrl_cb_dce, + .user_data = NULL, + .receive_buf = cmux_receive_buf_dce, + .receive_buf_size = sizeof(cmux_receive_buf_dce), + .transmit_buf = cmux_transmit_buf_dce, + .transmit_buf_size = ARRAY_SIZE(cmux_transmit_buf_dce), + }; + + const struct modem_backend_mock_config bus_mock_config = { + .rx_buf = bus_mock_rx_buf_dce, + .rx_buf_size = sizeof(bus_mock_rx_buf_dce), + .tx_buf = bus_mock_tx_buf_dce, + .tx_buf_size = sizeof(bus_mock_tx_buf_dce), + .limit = 32, + }; + + modem_cmux_init(&cmux_dce, &cmux_config_dce); + dlci1_pipe_dce = modem_cmux_dlci_init(&cmux_dce, &dlci1_dce, &dlci1_config); + dlci2_pipe_dce = modem_cmux_dlci_init(&cmux_dce, &dlci2_dce, &dlci2_config); + /* Init Backend DCE */ + bus_mock_pipe_dce = modem_backend_mock_init(&bus_mock_dce, &bus_mock_config); + __ASSERT_NO_MSG(modem_pipe_open(bus_mock_pipe_dce) == 0); + __ASSERT_NO_MSG(modem_cmux_attach(&cmux_dce, bus_mock_pipe_dce) == 0); + modem_pipe_attach(dlci1_pipe_dce, test_dlci1_pipe_cb_dce, NULL); + modem_pipe_attach(dlci2_pipe_dce, test_dlci2_pipe_cb_dce, NULL); +} + +static void *test_setup(void) +{ + uint32_t events; + + /* Init Event mask's */ + k_event_init(&cmux_event_dte); + k_event_init(&cmux_event_dce); + + /* Init CMUX, Pipe and Backend instances */ + cmux_dte_init(); + cmux_dce_init(); + + /* Create MOCK bridge */ + modem_backend_mock_bridge(&bus_mock_dte, &bus_mock_dce); + + /* Connect CMUX by DTE */ + __ASSERT_NO_MSG(modem_cmux_connect_async(&cmux_dte) == 0); + events = k_event_wait(&cmux_event_dte, EVENT_CMUX_CONNECTED, false, K_MSEC(100)); + __ASSERT_NO_MSG((events & EVENT_CMUX_CONNECTED)); + events = k_event_wait(&cmux_event_dce, EVENT_CMUX_CONNECTED, false, K_MSEC(100)); + __ASSERT_NO_MSG((events & EVENT_CMUX_CONNECTED)); + + /* Open DLCI channels init by DTE */ + __ASSERT_NO_MSG(modem_pipe_open_async(dlci1_pipe) == 0); + events = k_event_wait(&cmux_event_dte, EVENT_CMUX_DLCI1_OPEN, false, K_MSEC(100)); + __ASSERT_NO_MSG((events & EVENT_CMUX_DLCI1_OPEN)); + events = k_event_wait(&cmux_event_dce, EVENT_CMUX_DLCI1_OPEN, false, K_MSEC(100)); + __ASSERT_NO_MSG((events & EVENT_CMUX_DLCI1_OPEN)); + + __ASSERT_NO_MSG(modem_pipe_open_async(dlci2_pipe) == 0); + events = k_event_wait(&cmux_event_dte, EVENT_CMUX_DLCI2_OPEN, false, K_MSEC(100)); + __ASSERT_NO_MSG((events & EVENT_CMUX_DLCI2_OPEN)); + events = k_event_wait(&cmux_event_dce, EVENT_CMUX_DLCI2_OPEN, false, K_MSEC(100)); + __ASSERT_NO_MSG((events & EVENT_CMUX_DLCI2_OPEN)); + + return NULL; +} + +static void test_before(void *f) +{ + /* Reset events */ + k_event_clear(&cmux_event_dte, UINT32_MAX); + k_event_clear(&cmux_event_dce, UINT32_MAX); + + /* Reset mock pipes */ + modem_backend_mock_reset(&bus_mock_dte); + modem_backend_mock_reset(&bus_mock_dce); +} + +ZTEST(modem_cmux_pair, test_modem_cmux_dce_receive_dlci2_at) +{ + int ret; + uint32_t events; + + modem_pipe_transmit(dlci2_pipe, cmux_frame_data_dlci2_at_cgdcont, + sizeof(cmux_frame_data_dlci2_at_cgdcont)); + + modem_pipe_transmit(dlci2_pipe, cmux_frame_data_dlci2_at_newline, + sizeof(cmux_frame_data_dlci2_at_newline)); + + k_msleep(100); + + events = k_event_wait(&cmux_event_dce, EVENT_CMUX_DLCI2_RX_DATA, false, K_MSEC(100)); + zassert_true((events & EVENT_CMUX_DLCI2_RX_DATA), "DLCI2 dce not rx data"); + + ret = modem_pipe_receive(dlci2_pipe_dce, buffer2, sizeof(buffer2)); + zassert_true(ret == (sizeof(cmux_frame_data_dlci2_at_cgdcont) + + sizeof(cmux_frame_data_dlci2_at_newline)), + "Incorrect number of bytes received"); + + zassert_true(memcmp(buffer2, cmux_frame_data_dlci2_at_cgdcont, + sizeof(cmux_frame_data_dlci2_at_cgdcont)) == 0, + "Incorrect data received"); + + zassert_true(memcmp(&buffer2[sizeof(cmux_frame_data_dlci2_at_cgdcont)], + cmux_frame_data_dlci2_at_newline, + sizeof(cmux_frame_data_dlci2_at_newline)) == 0, + "Incorrect data received"); +} + +ZTEST(modem_cmux_pair, test_modem_cmux_dce_receive_dlci1_at) +{ + int ret; + uint32_t events; + + modem_pipe_transmit(dlci1_pipe, cmux_frame_data_dlci1_at_at, + sizeof(cmux_frame_data_dlci1_at_at)); + modem_pipe_transmit(dlci1_pipe, cmux_frame_data_dlci1_at_newline, + sizeof(cmux_frame_data_dlci1_at_newline)); + + k_msleep(100); + + events = k_event_wait(&cmux_event_dce, EVENT_CMUX_DLCI1_RX_DATA, false, K_MSEC(100)); + zassert_true((events & EVENT_CMUX_DLCI1_RX_DATA), "DLCI1 dce not rx data"); + + ret = modem_pipe_receive(dlci1_pipe_dce, buffer1, sizeof(buffer1)); + zassert_true(ret == (sizeof(cmux_frame_data_dlci1_at_at) + + sizeof(cmux_frame_data_dlci1_at_newline)), + "Incorrect number of bytes received"); + + zassert_true(memcmp(buffer1, cmux_frame_data_dlci1_at_at, + sizeof(cmux_frame_data_dlci1_at_at)) == 0, + "Incorrect data received"); + + zassert_true(memcmp(&buffer1[sizeof(cmux_frame_data_dlci1_at_at)], + cmux_frame_data_dlci1_at_newline, + sizeof(cmux_frame_data_dlci1_at_newline)) == 0, + "Incorrect data received"); +} + +ZTEST(modem_cmux_pair, test_modem_cmux_dce_receive_dlci2_ppp) +{ + int ret; + + uint32_t events; + + modem_pipe_transmit(dlci2_pipe, cmux_frame_data_dlci2_ppp_52, + sizeof(cmux_frame_data_dlci2_ppp_52)); + modem_pipe_transmit(dlci2_pipe, cmux_frame_data_dlci2_ppp_18, + sizeof(cmux_frame_data_dlci2_ppp_18)); + + k_msleep(100); + + events = k_event_wait(&cmux_event_dce, EVENT_CMUX_DLCI2_RX_DATA, false, K_MSEC(100)); + zassert_true((events & EVENT_CMUX_DLCI2_RX_DATA), "DLCI2 dce not rx data"); + + ret = modem_pipe_receive(dlci2_pipe_dce, buffer2, sizeof(buffer2)); + zassert_true(ret == (sizeof(cmux_frame_data_dlci2_ppp_52) + + sizeof(cmux_frame_data_dlci2_ppp_18)), + "Incorrect number of bytes received"); + + zassert_true(memcmp(buffer2, cmux_frame_data_dlci2_ppp_52, + sizeof(cmux_frame_data_dlci2_ppp_52)) == 0, + "Incorrect data received"); + + zassert_true(memcmp(&buffer2[sizeof(cmux_frame_data_dlci2_ppp_52)], + cmux_frame_data_dlci2_ppp_18, + sizeof(cmux_frame_data_dlci2_ppp_18)) == 0, + "Incorrect data received"); +} + +ZTEST(modem_cmux_pair, test_modem_cmux_dce_transmit_dlci2_ppp) +{ + int ret; + uint32_t events; + + ret = modem_pipe_transmit(dlci2_pipe_dce, cmux_frame_data_dlci2_ppp_52, + sizeof(cmux_frame_data_dlci2_ppp_52)); + + zassert_true(ret == sizeof(cmux_frame_data_dlci2_ppp_52), "Failed to send DLCI2 PPP 52 %d", + ret); + ret = modem_pipe_transmit(dlci2_pipe_dce, cmux_frame_data_dlci2_ppp_18, + sizeof(cmux_frame_data_dlci2_ppp_18)); + + zassert_true(ret == sizeof(cmux_frame_data_dlci2_ppp_18), "Failed to send DLCI2 PPP 18"); + + k_msleep(100); + + events = k_event_wait(&cmux_event_dte, EVENT_CMUX_DLCI2_RX_DATA, false, K_MSEC(100)); + zassert_true((events & EVENT_CMUX_DLCI2_RX_DATA), "DLCI2 dce not rx data"); + + ret = modem_pipe_receive(dlci2_pipe, buffer2, sizeof(buffer2)); + zassert_true(ret == (sizeof(cmux_frame_data_dlci2_ppp_52) + + sizeof(cmux_frame_data_dlci2_ppp_18)), + "Incorrect number of bytes received"); + + zassert_true(memcmp(buffer2, cmux_frame_data_dlci2_ppp_52, + sizeof(cmux_frame_data_dlci2_ppp_52)) == 0, + "Incorrect data received"); + + zassert_true(memcmp(&buffer2[sizeof(cmux_frame_data_dlci2_ppp_52)], + cmux_frame_data_dlci2_ppp_18, + sizeof(cmux_frame_data_dlci2_ppp_18)) == 0, + "Incorrect data received"); +} + +ZTEST(modem_cmux_pair, test_modem_cmux_dlci1_close_open) +{ + uint32_t events; + + /* Close DLCI1 */ + zassert_true(modem_pipe_close_async(dlci1_pipe) == 0, "Failed to close DLCI1 pipe"); + k_msleep(100); + events = k_event_wait_all(&cmux_event_dte, (EVENT_CMUX_DLCI1_CLOSED), false, K_MSEC(100)); + + zassert_true((events & EVENT_CMUX_DLCI1_CLOSED), "DLCI1 not closed as expected"); + events = k_event_wait_all(&cmux_event_dce, (EVENT_CMUX_DLCI1_CLOSED), false, K_MSEC(100)); + + zassert_true((events & EVENT_CMUX_DLCI1_CLOSED), "DLCI1 not closed as expected"); + + /* Open DLCI1 */ + zassert_true(modem_pipe_open_async(dlci1_pipe) == 0, "Failed to open DLCI1 pipe"); + + k_msleep(100); + + events = k_event_wait_all(&cmux_event_dte, (EVENT_CMUX_DLCI1_OPEN), false, K_MSEC(100)); + + zassert_true((events & EVENT_CMUX_DLCI1_OPEN), "DLCI1 not opened as expected"); + events = k_event_wait_all(&cmux_event_dce, (EVENT_CMUX_DLCI1_OPEN), false, K_MSEC(100)); + + zassert_true((events & EVENT_CMUX_DLCI1_OPEN), "DLCI1 not opened as expected"); +} + +ZTEST(modem_cmux_pair, test_modem_cmux_disconnect_connect) +{ + uint32_t events; + + /* Disconnect CMUX */ + zassert_true(modem_pipe_close_async(dlci1_pipe) == 0, "Failed to close DLCI1"); + zassert_true(modem_pipe_close_async(dlci2_pipe) == 0, "Failed to close DLCI2"); + k_msleep(100); + + events = k_event_wait_all(&cmux_event_dte, + (EVENT_CMUX_DLCI1_CLOSED | EVENT_CMUX_DLCI2_CLOSED), false, + K_MSEC(100)); + + zassert_true((events & EVENT_CMUX_DLCI1_CLOSED), "Failed to close DLCI1"); + zassert_true((events & EVENT_CMUX_DLCI2_CLOSED), "Failed to close DLCI2"); + + /* Discard CMUX DLCI DISC commands */ + modem_backend_mock_reset(&bus_mock_dte); + zassert_true(modem_cmux_disconnect_async(&cmux_dte) == 0, "Failed to disconnect CMUX"); + + k_msleep(100); + + events = k_event_wait_all(&cmux_event_dte, (EVENT_CMUX_DISCONNECTED), false, K_MSEC(100)); + zassert_true((events & EVENT_CMUX_DISCONNECTED), "Failed to disconnect CMUX"); + + /* Reconnect CMUX */ + zassert_true(modem_cmux_connect_async(&cmux_dte) == 0, "Failed to connect CMUX"); + + k_msleep(100); + + events = k_event_wait_all(&cmux_event_dte, (EVENT_CMUX_CONNECTED), false, K_MSEC(100)); + zassert_true((events & EVENT_CMUX_CONNECTED), "Failed to connect CMUX"); + + /* Open DLCI1 */ + zassert_true(modem_pipe_open_async(dlci1_pipe) == 0, "Failed to open DLCI1 pipe"); + + k_msleep(100); + + events = k_event_wait_all(&cmux_event_dte, (EVENT_CMUX_DLCI1_OPEN), false, K_MSEC(100)); + + zassert_true((events & EVENT_CMUX_DLCI1_OPEN), "DLCI1 not opened as expected"); + + /* Open DLCI2 */ + zassert_true(modem_pipe_open_async(dlci2_pipe) == 0, "Failed to open DLCI2 pipe"); + + k_msleep(100); + + events = k_event_wait_all(&cmux_event_dte, (EVENT_CMUX_DLCI2_OPEN), false, K_MSEC(100)); + + zassert_true((events & EVENT_CMUX_DLCI2_OPEN), "DLCI1 not opened as expected"); +} + +ZTEST(modem_cmux_pair, test_modem_cmux_disconnect_connect_sync) +{ + uint32_t events; + + zassert_true(modem_pipe_close(dlci1_pipe) == 0, "Failed to close DLCI1"); + zassert_true(modem_pipe_close(dlci2_pipe) == 0, "Failed to close DLCI2"); + events = k_event_wait_all(&cmux_event_dce, + (EVENT_CMUX_DLCI1_CLOSED | EVENT_CMUX_DLCI2_CLOSED), false, + K_MSEC(100)); + zassert_true((events & EVENT_CMUX_DLCI1_CLOSED), "DCE DLCI1 not closed as expected"); + zassert_true((events & EVENT_CMUX_DLCI2_CLOSED), "DCE DLCI2 not closed as expected"); + + zassert_true(modem_cmux_disconnect(&cmux_dte) == 0, "Failed to disconnect CMUX"); + zassert_true(modem_cmux_disconnect(&cmux_dte) == -EALREADY, + "Should already be disconnected"); + zassert_true(modem_cmux_disconnect(&cmux_dce) == -EALREADY, + "Should already be disconnected"); + + k_msleep(100); + + zassert_true(modem_cmux_connect(&cmux_dte) == 0, "Failed to connect CMUX"); + zassert_true(modem_cmux_connect(&cmux_dte) == -EALREADY, "Should already be connected"); + zassert_true(modem_cmux_connect(&cmux_dce) == -EALREADY, "Should already be connected"); + + zassert_true(modem_pipe_open(dlci1_pipe) == 0, "Failed to open DLCI1 pipe"); + zassert_true(modem_pipe_open(dlci2_pipe) == 0, "Failed to open DLCI2 pipe"); + events = k_event_wait_all(&cmux_event_dce, (EVENT_CMUX_DLCI1_OPEN | EVENT_CMUX_DLCI2_OPEN), + false, K_MSEC(100)); + zassert_true((events & EVENT_CMUX_DLCI1_OPEN), "DCE DLCI1 not open as expected"); + zassert_true((events & EVENT_CMUX_DLCI2_OPEN), "DCE DLCI2 not open as expected"); +} + +ZTEST(modem_cmux_pair, test_modem_cmux_dlci_close_open_sync) +{ + uint32_t events; + + zassert_true(modem_pipe_close(dlci1_pipe) == 0, "Failed to close DLCI1"); + zassert_true(modem_pipe_close(dlci2_pipe) == 0, "Failed to close DLCI2"); + + events = k_event_wait_all(&cmux_event_dce, + (EVENT_CMUX_DLCI1_CLOSED | EVENT_CMUX_DLCI2_CLOSED), false, + K_MSEC(100)); + zassert_true((events & EVENT_CMUX_DLCI1_CLOSED), "DCE DLCI1 not closed as expected"); + zassert_true((events & EVENT_CMUX_DLCI2_CLOSED), "DCE DLCI2 not closed as expected"); + + zassert_true(modem_pipe_open(dlci1_pipe) == 0, "Failed to open DLCI1 pipe"); + zassert_true(modem_pipe_open(dlci2_pipe) == 0, "Failed to open DLCI2 pipe"); + /* Verify DCE side channels are open also */ + events = k_event_wait_all(&cmux_event_dce, (EVENT_CMUX_DLCI1_OPEN | EVENT_CMUX_DLCI2_OPEN), + false, K_MSEC(100)); + zassert_true((events & EVENT_CMUX_DLCI1_OPEN), "DCE DLCI1 not open as expected"); + zassert_true((events & EVENT_CMUX_DLCI2_OPEN), "DCE DLCI2 not open as expected"); +} + +ZTEST_SUITE(modem_cmux_pair, NULL, test_setup, test_before, NULL, NULL); diff --git a/tests/subsys/modem/modem_cmux_pair/testcase.yaml b/tests/subsys/modem/modem_cmux_pair/testcase.yaml new file mode 100644 index 00000000000..9d0cdf33420 --- /dev/null +++ b/tests/subsys/modem/modem_cmux_pair/testcase.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +tests: + modem.modem_cmux_pair: + tags: modem_cmux + harness: ztest + platform_allow: native_sim From d93c2baa7f08f14b75050ed37f170ece69714c88 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Sun, 29 Oct 2023 10:00:28 +0100 Subject: [PATCH 1401/1623] [nrf fromtree] drivers: Add cellular API for network configuration Adds two APIs which allow for configuring the cellular network configuration of a cellular network device. like a cellular modem. The first allows for configuring which access technology to use, and optionally, which bands to use. The second allows for getting all supported access technologies are supported, and which bands for each tech are supported. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit ad011695aba725f6c5887981529e12d101d968a6) --- include/zephyr/drivers/cellular.h | 101 ++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 include/zephyr/drivers/cellular.h diff --git a/include/zephyr/drivers/cellular.h b/include/zephyr/drivers/cellular.h new file mode 100644 index 00000000000..303e5237e84 --- /dev/null +++ b/include/zephyr/drivers/cellular.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2023 Bjarki Arge Andreasen + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file drivers/cellular.h + * @brief Public cellular network API + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_ +#define ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_ + +/** + * @brief Cellular interface + * @defgroup cellular_interface Cellular Interface + * @ingroup io_interfaces + * @{ + */ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Cellular access technologies */ +enum cellular_access_technology { + CELLULAR_ACCESS_TECHNOLOGY_GSM = 0, + CELLULAR_ACCESS_TECHNOLOGY_GPRS, + CELLULAR_ACCESS_TECHNOLOGY_UMTS, + CELLULAR_ACCESS_TECHNOLOGY_EDGE, + CELLULAR_ACCESS_TECHNOLOGY_LTE, + CELLULAR_ACCESS_TECHNOLOGY_LTE_CAT_M1, + CELLULAR_ACCESS_TECHNOLOGY_LTE_CAT_M2, + CELLULAR_ACCESS_TECHNOLOGY_NB_IOT, +}; + +/** Cellular network structure */ +struct cellular_network { + /** Cellular access technology */ + enum cellular_access_technology technology; + /** + * List of bands, as defined by the specified cellular access technology, + * to enables. All supported bands are enabled if none are provided. + */ + uint16_t *bands; + /** Size of bands */ + uint16_t size; +}; + +/** + * @brief Configure cellular networks for the device + * + * @details Cellular network devices support at least one cellular access technology. + * Each cellular access technology defines a set of bands, of which the cellular device + * will support all or a subset of. + * + * The cellular device can only use one cellular network technology at a time. It must + * exclusively use the cellular network configurations provided, and will prioritize + * the cellular network configurations in the order they are provided in case there are + * multiple (the first cellular network configuration has the highest priority). + * + * @param dev Cellular network device instance. + * @param networks List of cellular network configurations to apply. + * @param size Size of list of cellular network configurations. + * + * @retval 0 if successful. + * @retval -EINVAL if any provided cellular network configuration is invalid or unsupported. + * @retval -ENOTSUP if API is not supported by cellular network device. + * @retval Negative errno-code otherwise. + */ +int cellular_configure_networks(const struct device *dev, const struct cellular_network *networks, + uint8_t size); + +/** + * @brief Get supported cellular networks for the device + * + * @param dev Cellular network device instance + * @param networks Pointer to list of supported cellular network configurations. + * @param size Size of list of cellular network configurations. + * + * @retval 0 if successful. + * @retval -ENOTSUP if API is not supported by cellular network device. + * @retval Negative errno-code otherwise. + */ +int cellular_get_supported_networks(const struct device *dev, + const struct cellular_network **networks, uint8_t *size); + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif /* ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_ */ From 57304f06779d3697af68c37f5e692a2af94c5e14 Mon Sep 17 00:00:00 2001 From: Lucas Denefle Date: Mon, 6 Nov 2023 16:32:01 +0000 Subject: [PATCH 1402/1623] [nrf fromtree] drivers: cellular: add signal and modem_info API Implement modem info pulling using the init and periodic chat scripts Signed-off-by: Lucas Denefle (cherry picked from commit d1ba79a070d6939d0bf52fe4f9faf2ad3d89a4f4) --- drivers/modem/modem_cellular.c | 231 ++++++++++++++++++++++++++---- include/zephyr/drivers/cellular.h | 53 +++++++ 2 files changed, 259 insertions(+), 25 deletions(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index a038da1805e..ad1bb920cd5 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,13 @@ LOG_MODULE_REGISTER(modem_cellular, CONFIG_MODEM_LOG_LEVEL); #define MODEM_CELLULAR_PERIODIC_SCRIPT_TIMEOUT \ K_MSEC(CONFIG_MODEM_CELLULAR_PERIODIC_SCRIPT_MS) +#define MODEM_CELLULAR_DATA_IMEI_LEN (15) +#define MODEM_CELLULAR_DATA_MODEL_ID_LEN (64) +#define MODEM_CELLULAR_DATA_IMSI_LEN (22) +#define MODEM_CELLULAR_DATA_ICCID_LEN (22) +#define MODEM_CELLULAR_DATA_MANUFACTURER_LEN (64) +#define MODEM_CELLULAR_DATA_FW_VERSION_LEN (64) + enum modem_cellular_state { MODEM_CELLULAR_STATE_IDLE = 0, MODEM_CELLULAR_STATE_RESET_PULSE, @@ -83,11 +91,16 @@ struct modem_cellular_data { uint8_t *chat_argv[32]; /* Status */ - uint8_t imei[15]; - uint8_t hwinfo[64]; uint8_t registration_status_gsm; uint8_t registration_status_gprs; uint8_t registration_status_lte; + int8_t rssi; + uint8_t imei[MODEM_CELLULAR_DATA_IMEI_LEN]; + uint8_t model_id[MODEM_CELLULAR_DATA_MODEL_ID_LEN]; + uint8_t imsi[MODEM_CELLULAR_DATA_IMSI_LEN]; + uint8_t iccid[MODEM_CELLULAR_DATA_ICCID_LEN]; + uint8_t manufacturer[MODEM_CELLULAR_DATA_MANUFACTURER_LEN]; + uint8_t fw_version[MODEM_CELLULAR_DATA_FW_VERSION_LEN]; /* PPP */ struct modem_ppp *ppp; @@ -118,6 +131,7 @@ struct modem_cellular_config { const struct modem_chat_script *init_chat_script; const struct modem_chat_script *dial_chat_script; const struct modem_chat_script *periodic_chat_script; + const struct modem_chat_script *get_signal_chat_script; }; static const char *modem_cellular_state_str(enum modem_cellular_state state) @@ -276,16 +290,34 @@ static void modem_cellular_chat_on_imei(struct modem_chat *chat, char **argv, ui return; } - if (strlen(argv[1]) != 15) { + strncpy(data->imei, argv[1], sizeof(data->imei)); +} + +static void modem_cellular_chat_on_cgmm(struct modem_chat *chat, char **argv, uint16_t argc, + void *user_data) +{ + struct modem_cellular_data *data = (struct modem_cellular_data *)user_data; + + if (argc != 2) { return; } - for (uint8_t i = 0; i < 15; i++) { - data->imei[i] = argv[1][i] - '0'; + strncpy(data->model_id, argv[1], sizeof(data->model_id)); +} + +static void modem_cellular_chat_on_cgmi(struct modem_chat *chat, char **argv, uint16_t argc, + void *user_data) +{ + struct modem_cellular_data *data = (struct modem_cellular_data *)user_data; + + if (argc != 2) { + return; } + + strncpy(data->manufacturer, argv[1], sizeof(data->manufacturer)); } -static void modem_cellular_chat_on_cgmm(struct modem_chat *chat, char **argv, uint16_t argc, +static void modem_cellular_chat_on_cgmr(struct modem_chat *chat, char **argv, uint16_t argc, void *user_data) { struct modem_cellular_data *data = (struct modem_cellular_data *)user_data; @@ -294,7 +326,50 @@ static void modem_cellular_chat_on_cgmm(struct modem_chat *chat, char **argv, ui return; } - strncpy(data->hwinfo, argv[1], sizeof(data->hwinfo) - 1); + strncpy(data->fw_version, argv[1], sizeof(data->fw_version)); +} + +static void modem_cellular_chat_on_csq(struct modem_chat *chat, char **argv, uint16_t argc, + void *user_data) +{ + uint8_t rssi; + + /* AT+CSQ returns a response +CSQ: , where: + * - rssi is a integer from 0 to 31 whose values describes a signal strength + * between -113 dBm for 0 and -51dbM for 31 or unknown for 99 + * - ber is an integer from 0 to 7 that describes the error rate, it can also + * be 99 for an unknown error rate + */ + struct modem_cellular_data *data = (struct modem_cellular_data *)user_data; + + if (argc != 3) { + return; + } + + /* Read rssi */ + rssi = atoi(argv[1]); + + if (rssi == 99) { + return; + } + + data->rssi = (-113 + (2 * rssi)); +} + +static void modem_cellular_chat_on_imsi(struct modem_chat *chat, char **argv, uint16_t argc, + void *user_data) +{ + struct modem_cellular_data *data = (struct modem_cellular_data *)user_data; + + strncpy(data->imsi, (char *)argv[1], sizeof(data->imsi)); +} + +static void modem_cellular_chat_on_iccid(struct modem_chat *chat, char **argv, uint16_t argc, + void *user_data) +{ + struct modem_cellular_data *data = (struct modem_cellular_data *)user_data; + + strncpy(data->iccid, (char *)argv[1], sizeof(data->iccid)); } static bool modem_cellular_is_registered(struct modem_cellular_data *data) @@ -346,6 +421,11 @@ MODEM_CHAT_MATCHES_DEFINE(allow_match, MODEM_CHAT_MATCH_DEFINE(imei_match, "", "", modem_cellular_chat_on_imei); MODEM_CHAT_MATCH_DEFINE(cgmm_match, "", "", modem_cellular_chat_on_cgmm); +MODEM_CHAT_MATCH_DEFINE(csq_match, "+CSQ: ", ",", modem_cellular_chat_on_csq); +MODEM_CHAT_MATCH_DEFINE(cimi_match, "", "", modem_cellular_chat_on_imsi); +MODEM_CHAT_MATCH_DEFINE(ccid_match, "+QCCID: ", "", modem_cellular_chat_on_iccid); +MODEM_CHAT_MATCH_DEFINE(cgmi_match, "", "", modem_cellular_chat_on_cgmi); +MODEM_CHAT_MATCH_DEFINE(cgmr_match, "", "", modem_cellular_chat_on_cgmr); MODEM_CHAT_MATCHES_DEFINE(unsol_matches, MODEM_CHAT_MATCH("+CREG: ", ",", modem_cellular_chat_on_cxreg), @@ -1336,6 +1416,14 @@ MODEM_CHAT_SCRIPT_CMDS_DEFINE(quectel_bg95_init_chat_script_cmds, MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMM", cgmm_match), MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMI", cgmi_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMR", cgmr_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CIMI", cimi_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+QCCID", ccid_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP_NONE("AT+CMUX=0,0,5,127", 300)); MODEM_CHAT_SCRIPT_DEFINE(quectel_bg95_init_chat_script, quectel_bg95_init_chat_script_cmds, @@ -1355,29 +1443,45 @@ MODEM_CHAT_SCRIPT_DEFINE(quectel_bg95_dial_chat_script, quectel_bg95_dial_chat_s MODEM_CHAT_SCRIPT_CMDS_DEFINE(quectel_bg95_periodic_chat_script_cmds, MODEM_CHAT_SCRIPT_CMD_RESP("AT+CREG?", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG?", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG?", ok_match)); + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CSQ", csq_match)); MODEM_CHAT_SCRIPT_DEFINE(quectel_bg95_periodic_chat_script, quectel_bg95_periodic_chat_script_cmds, abort_matches, modem_cellular_chat_callback_handler, 4); + +MODEM_CHAT_SCRIPT_CMDS_DEFINE(quectel_bg95_get_signal_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CSQ", csq_match)); + +MODEM_CHAT_SCRIPT_DEFINE(quectel_bg95_get_signal_chat_script, + quectel_bg95_get_signal_chat_script_cmds, abort_matches, + modem_cellular_chat_callback_handler, 4); #endif #if DT_HAS_COMPAT_STATUS_OKAY(quectel_eg25_g) -MODEM_CHAT_SCRIPT_CMDS_DEFINE(quectel_eg25_g_init_chat_script_cmds, - MODEM_CHAT_SCRIPT_CMD_RESP("ATE0", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CFUN=4", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CMEE=1", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CREG=1", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG=1", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG=1", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CREG?", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG?", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG?", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGSN", imei_match), - MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMM", cgmm_match), - MODEM_CHAT_SCRIPT_CMD_RESP_NONE("AT+CMUX=0,0,5,127,10,3,30,10,2", - 100)); +MODEM_CHAT_SCRIPT_CMDS_DEFINE( + quectel_eg25_g_init_chat_script_cmds, MODEM_CHAT_SCRIPT_CMD_RESP("ATE0", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CFUN=4", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CMEE=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CREG=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGSN", imei_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMM", cgmm_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMI", cgmi_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMR", cgmr_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CIMI", cimi_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+QCCID", ccid_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP_NONE("AT+CMUX=0,0,5,127,10,3,30,10,2", 100)); MODEM_CHAT_SCRIPT_DEFINE(quectel_eg25_g_init_chat_script, quectel_eg25_g_init_chat_script_cmds, abort_matches, modem_cellular_chat_callback_handler, 10); @@ -1396,11 +1500,19 @@ MODEM_CHAT_SCRIPT_DEFINE(quectel_eg25_g_dial_chat_script, quectel_eg25_g_dial_ch MODEM_CHAT_SCRIPT_CMDS_DEFINE(quectel_eg25_g_periodic_chat_script_cmds, MODEM_CHAT_SCRIPT_CMD_RESP("AT+CREG?", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG?", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG?", ok_match)); + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CSQ", csq_match)); MODEM_CHAT_SCRIPT_DEFINE(quectel_eg25_g_periodic_chat_script, quectel_eg25_g_periodic_chat_script_cmds, abort_matches, modem_cellular_chat_callback_handler, 4); + +MODEM_CHAT_SCRIPT_CMDS_DEFINE(quectel_eg25_g_get_signal_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CSQ", csq_match)); + +MODEM_CHAT_SCRIPT_DEFINE(quectel_eg25_g_get_signal_chat_script, + quectel_eg25_g_get_signal_chat_script_cmds, abort_matches, + modem_cellular_chat_callback_handler, 4); #endif #if DT_HAS_COMPAT_STATUS_OKAY(zephyr_gsm_ppp) @@ -1708,7 +1820,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, .shutdown_time_ms = 5000, \ .init_chat_script = &quectel_bg95_init_chat_script, \ .dial_chat_script = &quectel_bg95_dial_chat_script, \ - .periodic_chat_script = &quectel_bg95_periodic_chat_script, \ + .periodic_chat_script = &_CONCAT(DT_DRV_COMPAT, _periodic_chat_script), \ + .get_signal_chat_script = &_CONCAT(DT_DRV_COMPAT, _get_signal_chat_script), \ }; \ \ PM_DEVICE_DT_INST_DEFINE(inst, modem_cellular_pm_action); \ @@ -1737,6 +1850,7 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, .init_chat_script = &quectel_eg25_g_init_chat_script, \ .dial_chat_script = &quectel_eg25_g_dial_chat_script, \ .periodic_chat_script = &_CONCAT(DT_DRV_COMPAT, _periodic_chat_script), \ + .get_signal_chat_script = &_CONCAT(DT_DRV_COMPAT, _get_signal_chat_script), \ }; \ \ PM_DEVICE_DT_INST_DEFINE(inst, modem_cellular_pm_action); \ @@ -1945,3 +2059,70 @@ DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_SWIR_HL7800) #define DT_DRV_COMPAT telit_me910g1 DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_TELIT_ME910G1) #undef DT_DRV_COMPAT + +int cellular_get_modem_info(const struct device *dev, enum cellular_modem_info_type type, + char *info, size_t size) +{ + int ret = 0; + struct modem_cellular_data *data = (struct modem_cellular_data *)dev->data; + + switch (type) { + case CELLULAR_MODEM_INFO_IMEI: + strncpy(info, &data->imei[0], MIN(size, sizeof(data->imei))); + break; + case CELLULAR_MODEM_INFO_SIM_IMSI: + strncpy(info, &data->imsi[0], MIN(size, sizeof(data->imsi))); + break; + case CELLULAR_MODEM_INFO_SIM_ICCID: + strncpy(info, &data->iccid[0], MIN(size, sizeof(data->iccid))); + break; + case CELLULAR_MODEM_INFO_MANUFACTURER: + strncpy(info, &data->manufacturer[0], MIN(size, sizeof(data->manufacturer))); + break; + case CELLULAR_MODEM_INFO_FW_VERSION: + strncpy(info, &data->fw_version[0], MIN(size, sizeof(data->fw_version))); + break; + case CELLULAR_MODEM_INFO_MODEL_ID: + strncpy(info, &data->model_id[0], MIN(size, sizeof(data->model_id))); + break; + default: + ret = -ENODATA; + break; + } + + return ret; +} + +int cellular_get_signal(const struct device *dev, const enum cellular_signal_type type, + int16_t *value) +{ + int ret; + struct modem_cellular_data *data = (struct modem_cellular_data *)dev->data; + const struct modem_cellular_config *config = (struct modem_cellular_config *)dev->config; + + if (config->get_signal_chat_script == NULL) { + return -ENOTSUP; + } + + if ((data->state != MODEM_CELLULAR_STATE_AWAIT_REGISTERED) && + (data->state != MODEM_CELLULAR_STATE_CARRIER_ON)) { + return -ENODATA; + } + + ret = modem_chat_run_script(&data->chat, config->get_signal_chat_script); + if (ret != 0) { + return ret; + } + + switch (type) { + case CELLULAR_SIGNAL_RSSI: { + *value = data->rssi; + } break; + case CELLULAR_SIGNAL_RSRP: + return -ENOTSUP; + case CELLULAR_SIGNAL_RSRQ: + return -ENOTSUP; + } + + return ret; +} diff --git a/include/zephyr/drivers/cellular.h b/include/zephyr/drivers/cellular.h index 303e5237e84..83135967123 100644 --- a/include/zephyr/drivers/cellular.h +++ b/include/zephyr/drivers/cellular.h @@ -52,6 +52,28 @@ struct cellular_network { uint16_t size; }; +enum cellular_signal_type { + CELLULAR_SIGNAL_RSSI, + CELLULAR_SIGNAL_RSRP, + CELLULAR_SIGNAL_RSRQ, +}; + +/** Cellular modem info type */ +enum cellular_modem_info_type { + /** International Mobile Equipment Identity */ + CELLULAR_MODEM_INFO_IMEI, + /** Modem model ID */ + CELLULAR_MODEM_INFO_MODEL_ID, + /** Modem manufacturer */ + CELLULAR_MODEM_INFO_MANUFACTURER, + /** Modem fw version */ + CELLULAR_MODEM_INFO_FW_VERSION, + /** International Mobile Subscriber Identity */ + CELLULAR_MODEM_INFO_SIM_IMSI, + /** Integrated Circuit Card Identification Number (SIM) */ + CELLULAR_MODEM_INFO_SIM_ICCID, +}; + /** * @brief Configure cellular networks for the device * @@ -90,6 +112,37 @@ int cellular_configure_networks(const struct device *dev, const struct cellular_ int cellular_get_supported_networks(const struct device *dev, const struct cellular_network **networks, uint8_t *size); +/** + * @brief Get signal for the device + * + * @param dev Cellular network device instance + * @param type Type of the signal information requested + * @param value Signal strength destination (one of RSSI, RSRP, RSRQ) + * + * @retval 0 if successful. + * @retval -ENOTSUP if API is not supported by cellular network device. + * @retval -ENODATA if device is not in a state where signal can be polled + * @retval Negative errno-code otherwise. + */ +int cellular_get_signal(const struct device *dev, const enum cellular_signal_type type, + int16_t *value); + +/** + * @brief Get modem info for the device + * + * @param dev Cellular network device instance + * @param type Type of the modem info requested + * @param info Info string destination + * @param size Info string size + * + * @retval 0 if successful. + * @retval -ENOTSUP if API is not supported by cellular network device. + * @retval -ENODATA if modem does not provide info requested + * @retval Negative errno-code from chat module otherwise. + */ +int cellular_get_modem_info(const struct device *dev, const enum cellular_modem_info_type type, + char *info, size_t size); + #ifdef __cplusplus } #endif From e4c7fef4599f80bd2394330a11c57902f34ab73e Mon Sep 17 00:00:00 2001 From: Alessio Lei Date: Tue, 12 Dec 2023 14:28:20 +0100 Subject: [PATCH 1403/1623] [nrf fromtree] drivers: modem: remove dependency of modem_socket Fixed Kconfig to remove dependency between modem_socket and modem_context, the two do not depend on each other and should be possible to use independently Signed-off-by: Alessio Lei (cherry picked from commit 733b81d2c79fe17ca993ce9875f6790f7b756459) --- drivers/modem/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/modem/Kconfig b/drivers/modem/Kconfig index c233d5db821..02e3557918f 100644 --- a/drivers/modem/Kconfig +++ b/drivers/modem/Kconfig @@ -142,6 +142,8 @@ config MODEM_CMD_HANDLER_MAX_PARAM_COUNT of the match_buf (match_buf_len) field as it needs to be large enough to hold a single line of data (ending with /r). +endif # MODEM_CONTEXT + config MODEM_SOCKET bool "Generic modem socket support layer" help @@ -165,8 +167,6 @@ config MODEM_SOCKET_PACKET_COUNT these values are organized into "packets". This setting limits the maximum number of packet sizes the socket can keep track of. -endif # MODEM_CONTEXT - config MODEM_SHELL bool "Modem shell utilities" select SHELL From a3dd7a71cb4e1e7f56ac3143fda767819e939ff8 Mon Sep 17 00:00:00 2001 From: Lucas Denefle Date: Tue, 19 Dec 2023 15:20:01 +0000 Subject: [PATCH 1404/1623] [nrf fromtree] drivers: cellular: add ldenefle to copyright Add Lucas Denefle to copyright of the cellular API. Signed-off-by: Lucas Denefle (cherry picked from commit a5e5c1d00aa19138e7c88430e5e95a8dacdeada2) --- include/zephyr/drivers/cellular.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/zephyr/drivers/cellular.h b/include/zephyr/drivers/cellular.h index 83135967123..445cd83857c 100644 --- a/include/zephyr/drivers/cellular.h +++ b/include/zephyr/drivers/cellular.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2023 Bjarki Arge Andreasen + * Copyright (c) 2023 Lucas Denefle * * SPDX-License-Identifier: Apache-2.0 */ From 58de2e316c4726de422f79770623e959c002dff9 Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Fri, 29 Dec 2023 11:23:38 +0200 Subject: [PATCH 1405/1623] [nrf fromtree] modem: cmux: fix frame data length encoding In cases where the data is bigger than 127 bytes, the first bit of the second byte of the data length field used to always be set. This is wrong as according to the 3GPP 27.010 spec only the first bit of the first byte is the EA bit; all the others denote the data length. Signed-off-by: Tomi Fontanilles (cherry picked from commit 6564e8b756c95d3cc5b5e473d5b6b27d31c6cdb2) --- subsys/modem/modem_cmux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index 29ff41c1ca7..3ace00d6583 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -232,7 +232,7 @@ static uint16_t modem_cmux_transmit_frame(struct modem_cmux *cmux, byte = data_len << 1; fcs = crc8(&byte, 1, MODEM_CMUX_FCS_POLYNOMIAL, fcs, true); ring_buf_put(&cmux->transmit_rb, &byte, 1); - byte = 0x01 | (data_len >> 7); + byte = data_len >> 7; ring_buf_put(&cmux->transmit_rb, &byte, 1); } else { byte = 0x01 | (data_len << 1); From 361f49fb816f127641df59214b46fb99b7984721 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 29 Dec 2023 10:44:28 +0100 Subject: [PATCH 1406/1623] [nrf fromtree] modem: cellular: Restructure cellular API to fit device driver model The current cellular API header is not written to conform with the device driver model. This commit fixes that. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 6f55309659ed8fd5d96d7ecf4819a7987e43bd23) --- include/zephyr/drivers/cellular.h | 100 +++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 8 deletions(-) diff --git a/include/zephyr/drivers/cellular.h b/include/zephyr/drivers/cellular.h index 445cd83857c..b4202d81b0a 100644 --- a/include/zephyr/drivers/cellular.h +++ b/include/zephyr/drivers/cellular.h @@ -53,6 +53,7 @@ struct cellular_network { uint16_t size; }; +/** Cellular signal type */ enum cellular_signal_type { CELLULAR_SIGNAL_RSSI, CELLULAR_SIGNAL_RSRP, @@ -75,6 +76,33 @@ enum cellular_modem_info_type { CELLULAR_MODEM_INFO_SIM_ICCID, }; +/** API for configuring networks */ +typedef int (*cellular_api_configure_networks)(const struct device *dev, + const struct cellular_network *networks, + uint8_t size); + +/** API for getting supported networks */ +typedef int (*cellular_api_get_supported_networks)(const struct device *dev, + const struct cellular_network **networks, + uint8_t *size); + +/** API for getting network signal strength */ +typedef int (*cellular_api_get_signal)(const struct device *dev, + const enum cellular_signal_type type, int16_t *value); + +/** API for getting modem information */ +typedef int (*cellular_api_get_modem_info)(const struct device *dev, + const enum cellular_modem_info_type type, + char *info, size_t size); + +/** Cellular driver API */ +__subsystem struct cellular_driver_api { + cellular_api_configure_networks configure_networks; + cellular_api_get_supported_networks get_supported_networks; + cellular_api_get_signal get_signal; + cellular_api_get_modem_info get_modem_info; +}; + /** * @brief Configure cellular networks for the device * @@ -96,8 +124,21 @@ enum cellular_modem_info_type { * @retval -ENOTSUP if API is not supported by cellular network device. * @retval Negative errno-code otherwise. */ -int cellular_configure_networks(const struct device *dev, const struct cellular_network *networks, - uint8_t size); +__syscall int cellular_configure_networks(const struct device *dev, + const struct cellular_network *networks, uint8_t size); + +static inline int z_impl_cellular_configure_networks(const struct device *dev, + const struct cellular_network *networks, + uint8_t size) +{ + const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api; + + if (api->configure_networks == NULL) { + return -ENOTSUP; + } + + return api->configure_networks(dev, networks, size); +} /** * @brief Get supported cellular networks for the device @@ -110,8 +151,22 @@ int cellular_configure_networks(const struct device *dev, const struct cellular_ * @retval -ENOTSUP if API is not supported by cellular network device. * @retval Negative errno-code otherwise. */ -int cellular_get_supported_networks(const struct device *dev, - const struct cellular_network **networks, uint8_t *size); +__syscall int cellular_get_supported_networks(const struct device *dev, + const struct cellular_network **networks, + uint8_t *size); + +static inline int z_impl_cellular_get_supported_networks(const struct device *dev, + const struct cellular_network **networks, + uint8_t *size) +{ + const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api; + + if (api->get_supported_networks == NULL) { + return -ENOTSUP; + } + + return api->get_supported_networks(dev, networks, size); +} /** * @brief Get signal for the device @@ -125,8 +180,21 @@ int cellular_get_supported_networks(const struct device *dev, * @retval -ENODATA if device is not in a state where signal can be polled * @retval Negative errno-code otherwise. */ -int cellular_get_signal(const struct device *dev, const enum cellular_signal_type type, - int16_t *value); +__syscall int cellular_get_signal(const struct device *dev, const enum cellular_signal_type type, + int16_t *value); + +static inline int z_impl_cellular_get_signal(const struct device *dev, + const enum cellular_signal_type type, + int16_t *value) +{ + const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api; + + if (api->get_signal == NULL) { + return -ENOTSUP; + } + + return api->get_signal(dev, type, value); +} /** * @brief Get modem info for the device @@ -141,8 +209,22 @@ int cellular_get_signal(const struct device *dev, const enum cellular_signal_typ * @retval -ENODATA if modem does not provide info requested * @retval Negative errno-code from chat module otherwise. */ -int cellular_get_modem_info(const struct device *dev, const enum cellular_modem_info_type type, - char *info, size_t size); +__syscall int cellular_get_modem_info(const struct device *dev, + const enum cellular_modem_info_type type, + char *info, size_t size); + +static inline int z_impl_cellular_get_modem_info(const struct device *dev, + const enum cellular_modem_info_type type, + char *info, size_t size) +{ + const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api; + + if (api->get_modem_info == NULL) { + return -ENOTSUP; + } + + return api->get_modem_info(dev, type, info, size); +} #ifdef __cplusplus } @@ -152,4 +234,6 @@ int cellular_get_modem_info(const struct device *dev, const enum cellular_modem_ * @} */ +#include + #endif /* ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_ */ From d07ec775c0cd3c34014cd591cbaf385171d40460 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 29 Dec 2023 10:48:44 +0100 Subject: [PATCH 1407/1623] [nrf fromtree] modem: modem_cellular: Update driver to implement cellular API Move the implementations of the cellular API in modem_cellular.c to an cellular_driver_structure, and implement this API structure withing the device drivers. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit f9491034bec762be4d99bdb798f758514502075a) --- drivers/modem/modem_cellular.c | 165 ++++++++++++++++-------------- include/zephyr/drivers/cellular.h | 46 +++------ 2 files changed, 104 insertions(+), 107 deletions(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index ad1bb920cd5..ea39cecabaf 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -1263,6 +1263,80 @@ static void modem_cellular_cmux_handler(struct modem_cmux *cmux, enum modem_cmux } } +static int modem_cellular_get_signal(const struct device *dev, + const enum cellular_signal_type type, + int16_t *value) +{ + int ret; + struct modem_cellular_data *data = (struct modem_cellular_data *)dev->data; + const struct modem_cellular_config *config = (struct modem_cellular_config *)dev->config; + + if (config->get_signal_chat_script == NULL) { + return -ENOTSUP; + } + + if ((data->state != MODEM_CELLULAR_STATE_AWAIT_REGISTERED) && + (data->state != MODEM_CELLULAR_STATE_CARRIER_ON)) { + return -ENODATA; + } + + ret = modem_chat_run_script(&data->chat, config->get_signal_chat_script); + if (ret != 0) { + return ret; + } + + switch (type) { + case CELLULAR_SIGNAL_RSSI: { + *value = data->rssi; + } break; + case CELLULAR_SIGNAL_RSRP: + return -ENOTSUP; + case CELLULAR_SIGNAL_RSRQ: + return -ENOTSUP; + } + + return ret; +} + +static int modem_cellular_get_modem_info(const struct device *dev, + enum cellular_modem_info_type type, + char *info, size_t size) +{ + int ret = 0; + struct modem_cellular_data *data = (struct modem_cellular_data *)dev->data; + + switch (type) { + case CELLULAR_MODEM_INFO_IMEI: + strncpy(info, &data->imei[0], MIN(size, sizeof(data->imei))); + break; + case CELLULAR_MODEM_INFO_SIM_IMSI: + strncpy(info, &data->imsi[0], MIN(size, sizeof(data->imsi))); + break; + case CELLULAR_MODEM_INFO_SIM_ICCID: + strncpy(info, &data->iccid[0], MIN(size, sizeof(data->iccid))); + break; + case CELLULAR_MODEM_INFO_MANUFACTURER: + strncpy(info, &data->manufacturer[0], MIN(size, sizeof(data->manufacturer))); + break; + case CELLULAR_MODEM_INFO_FW_VERSION: + strncpy(info, &data->fw_version[0], MIN(size, sizeof(data->fw_version))); + break; + case CELLULAR_MODEM_INFO_MODEL_ID: + strncpy(info, &data->model_id[0], MIN(size, sizeof(data->model_id))); + break; + default: + ret = -ENODATA; + break; + } + + return ret; +} + +const static struct cellular_driver_api modem_cellular_api = { + .get_signal = modem_cellular_get_signal, + .get_modem_info = modem_cellular_get_modem_info, +}; + #ifdef CONFIG_PM_DEVICE static int modem_cellular_pm_action(const struct device *dev, enum pm_device_action action) { @@ -1828,7 +1902,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, \ DEVICE_DT_INST_DEFINE(inst, modem_cellular_init, PM_DEVICE_DT_INST_GET(inst), \ &MODEM_CELLULAR_INST_NAME(data, inst), \ - &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, NULL); + &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, \ + &modem_cellular_api); #define MODEM_CELLULAR_DEVICE_QUECTEL_EG25_G(inst) \ MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ @@ -1857,7 +1932,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, \ DEVICE_DT_INST_DEFINE(inst, modem_cellular_init, PM_DEVICE_DT_INST_GET(inst), \ &MODEM_CELLULAR_INST_NAME(data, inst), \ - &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, NULL); + &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, \ + &modem_cellular_api); #define MODEM_CELLULAR_DEVICE_GSM_PPP(inst) \ MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ @@ -1885,7 +1961,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, \ DEVICE_DT_INST_DEFINE(inst, modem_cellular_init, PM_DEVICE_DT_INST_GET(inst), \ &MODEM_CELLULAR_INST_NAME(data, inst), \ - &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, NULL); + &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, \ + &modem_cellular_api); #define MODEM_CELLULAR_DEVICE_SIMCOM_SIM7080(inst) \ MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ @@ -1913,7 +1990,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, \ DEVICE_DT_INST_DEFINE(inst, modem_cellular_init, PM_DEVICE_DT_INST_GET(inst), \ &MODEM_CELLULAR_INST_NAME(data, inst), \ - &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, NULL); + &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, \ + &modem_cellular_api); #define MODEM_CELLULAR_DEVICE_U_BLOX_SARA_R4(inst) \ MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ @@ -1941,7 +2019,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, \ DEVICE_DT_INST_DEFINE(inst, modem_cellular_init, PM_DEVICE_DT_INST_GET(inst), \ &MODEM_CELLULAR_INST_NAME(data, inst), \ - &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, NULL); + &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, \ + &modem_cellular_api); #define MODEM_CELLULAR_DEVICE_U_BLOX_SARA_R5(inst) \ MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ @@ -1970,7 +2049,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, \ DEVICE_DT_INST_DEFINE(inst, modem_cellular_init, PM_DEVICE_DT_INST_GET(inst), \ &MODEM_CELLULAR_INST_NAME(data, inst), \ - &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, NULL); + &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, \ + &modem_cellular_api); #define MODEM_CELLULAR_DEVICE_SWIR_HL7800(inst) \ MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ @@ -1998,7 +2078,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, \ DEVICE_DT_INST_DEFINE(inst, modem_cellular_init, PM_DEVICE_DT_INST_GET(inst), \ &MODEM_CELLULAR_INST_NAME(data, inst), \ - &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, NULL); + &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, \ + &modem_cellular_api); #define MODEM_CELLULAR_DEVICE_TELIT_ME910G1(inst) \ MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ @@ -2026,7 +2107,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, \ DEVICE_DT_INST_DEFINE(inst, modem_cellular_init, PM_DEVICE_DT_INST_GET(inst), \ &MODEM_CELLULAR_INST_NAME(data, inst), \ - &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, NULL); + &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, \ + &modem_cellular_api); #define DT_DRV_COMPAT quectel_bg95 DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_QUECTEL_BG95) @@ -2059,70 +2141,3 @@ DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_SWIR_HL7800) #define DT_DRV_COMPAT telit_me910g1 DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_TELIT_ME910G1) #undef DT_DRV_COMPAT - -int cellular_get_modem_info(const struct device *dev, enum cellular_modem_info_type type, - char *info, size_t size) -{ - int ret = 0; - struct modem_cellular_data *data = (struct modem_cellular_data *)dev->data; - - switch (type) { - case CELLULAR_MODEM_INFO_IMEI: - strncpy(info, &data->imei[0], MIN(size, sizeof(data->imei))); - break; - case CELLULAR_MODEM_INFO_SIM_IMSI: - strncpy(info, &data->imsi[0], MIN(size, sizeof(data->imsi))); - break; - case CELLULAR_MODEM_INFO_SIM_ICCID: - strncpy(info, &data->iccid[0], MIN(size, sizeof(data->iccid))); - break; - case CELLULAR_MODEM_INFO_MANUFACTURER: - strncpy(info, &data->manufacturer[0], MIN(size, sizeof(data->manufacturer))); - break; - case CELLULAR_MODEM_INFO_FW_VERSION: - strncpy(info, &data->fw_version[0], MIN(size, sizeof(data->fw_version))); - break; - case CELLULAR_MODEM_INFO_MODEL_ID: - strncpy(info, &data->model_id[0], MIN(size, sizeof(data->model_id))); - break; - default: - ret = -ENODATA; - break; - } - - return ret; -} - -int cellular_get_signal(const struct device *dev, const enum cellular_signal_type type, - int16_t *value) -{ - int ret; - struct modem_cellular_data *data = (struct modem_cellular_data *)dev->data; - const struct modem_cellular_config *config = (struct modem_cellular_config *)dev->config; - - if (config->get_signal_chat_script == NULL) { - return -ENOTSUP; - } - - if ((data->state != MODEM_CELLULAR_STATE_AWAIT_REGISTERED) && - (data->state != MODEM_CELLULAR_STATE_CARRIER_ON)) { - return -ENODATA; - } - - ret = modem_chat_run_script(&data->chat, config->get_signal_chat_script); - if (ret != 0) { - return ret; - } - - switch (type) { - case CELLULAR_SIGNAL_RSSI: { - *value = data->rssi; - } break; - case CELLULAR_SIGNAL_RSRP: - return -ENOTSUP; - case CELLULAR_SIGNAL_RSRQ: - return -ENOTSUP; - } - - return ret; -} diff --git a/include/zephyr/drivers/cellular.h b/include/zephyr/drivers/cellular.h index b4202d81b0a..fba05e6e440 100644 --- a/include/zephyr/drivers/cellular.h +++ b/include/zephyr/drivers/cellular.h @@ -124,17 +124,13 @@ __subsystem struct cellular_driver_api { * @retval -ENOTSUP if API is not supported by cellular network device. * @retval Negative errno-code otherwise. */ -__syscall int cellular_configure_networks(const struct device *dev, - const struct cellular_network *networks, uint8_t size); - -static inline int z_impl_cellular_configure_networks(const struct device *dev, - const struct cellular_network *networks, - uint8_t size) +static inline int cellular_configure_networks(const struct device *dev, + const struct cellular_network *networks, uint8_t size) { const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api; if (api->configure_networks == NULL) { - return -ENOTSUP; + return -ENOSYS; } return api->configure_networks(dev, networks, size); @@ -151,18 +147,14 @@ static inline int z_impl_cellular_configure_networks(const struct device *dev, * @retval -ENOTSUP if API is not supported by cellular network device. * @retval Negative errno-code otherwise. */ -__syscall int cellular_get_supported_networks(const struct device *dev, - const struct cellular_network **networks, - uint8_t *size); - -static inline int z_impl_cellular_get_supported_networks(const struct device *dev, - const struct cellular_network **networks, - uint8_t *size) +static inline int cellular_get_supported_networks(const struct device *dev, + const struct cellular_network **networks, + uint8_t *size) { const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api; if (api->get_supported_networks == NULL) { - return -ENOTSUP; + return -ENOSYS; } return api->get_supported_networks(dev, networks, size); @@ -180,17 +172,13 @@ static inline int z_impl_cellular_get_supported_networks(const struct device *de * @retval -ENODATA if device is not in a state where signal can be polled * @retval Negative errno-code otherwise. */ -__syscall int cellular_get_signal(const struct device *dev, const enum cellular_signal_type type, - int16_t *value); - -static inline int z_impl_cellular_get_signal(const struct device *dev, - const enum cellular_signal_type type, - int16_t *value) +static inline int cellular_get_signal(const struct device *dev, + const enum cellular_signal_type type, int16_t *value) { const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api; if (api->get_signal == NULL) { - return -ENOTSUP; + return -ENOSYS; } return api->get_signal(dev, type, value); @@ -209,18 +197,14 @@ static inline int z_impl_cellular_get_signal(const struct device *dev, * @retval -ENODATA if modem does not provide info requested * @retval Negative errno-code from chat module otherwise. */ -__syscall int cellular_get_modem_info(const struct device *dev, - const enum cellular_modem_info_type type, - char *info, size_t size); - -static inline int z_impl_cellular_get_modem_info(const struct device *dev, - const enum cellular_modem_info_type type, - char *info, size_t size) +static inline int cellular_get_modem_info(const struct device *dev, + const enum cellular_modem_info_type type, char *info, + size_t size) { const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api; if (api->get_modem_info == NULL) { - return -ENOTSUP; + return -ENOSYS; } return api->get_modem_info(dev, type, info, size); @@ -234,6 +218,4 @@ static inline int z_impl_cellular_get_modem_info(const struct device *dev, * @} */ -#include - #endif /* ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_ */ From e6ded9416de862472aa961954b2d91d79970e4c5 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 29 Dec 2023 13:02:48 +0100 Subject: [PATCH 1408/1623] [nrf fromtree] modem: modem_cellular: Rework cellular_get_signal implementation The modem_cellular.c driver now uses a common script to get signal strenght, which is run on demand. This is more efficient than polling it, and simpler since every modem doesn't have to define their own variant of the script. Additionally, the CSQ handler now stores the "raw" rssi value returned from AT+CSQ to be parsed by the cellular_modem_get_signal implementation. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 572c5e6d5a6a10f7c5cf9f7313626b6f89453d6f) --- drivers/modem/modem_cellular.c | 107 ++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 49 deletions(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index ea39cecabaf..78958bdec2c 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -94,7 +94,7 @@ struct modem_cellular_data { uint8_t registration_status_gsm; uint8_t registration_status_gprs; uint8_t registration_status_lte; - int8_t rssi; + uint8_t rssi; uint8_t imei[MODEM_CELLULAR_DATA_IMEI_LEN]; uint8_t model_id[MODEM_CELLULAR_DATA_MODEL_ID_LEN]; uint8_t imsi[MODEM_CELLULAR_DATA_IMSI_LEN]; @@ -131,7 +131,6 @@ struct modem_cellular_config { const struct modem_chat_script *init_chat_script; const struct modem_chat_script *dial_chat_script; const struct modem_chat_script *periodic_chat_script; - const struct modem_chat_script *get_signal_chat_script; }; static const char *modem_cellular_state_str(enum modem_cellular_state state) @@ -332,28 +331,13 @@ static void modem_cellular_chat_on_cgmr(struct modem_chat *chat, char **argv, ui static void modem_cellular_chat_on_csq(struct modem_chat *chat, char **argv, uint16_t argc, void *user_data) { - uint8_t rssi; - - /* AT+CSQ returns a response +CSQ: , where: - * - rssi is a integer from 0 to 31 whose values describes a signal strength - * between -113 dBm for 0 and -51dbM for 31 or unknown for 99 - * - ber is an integer from 0 to 7 that describes the error rate, it can also - * be 99 for an unknown error rate - */ struct modem_cellular_data *data = (struct modem_cellular_data *)user_data; if (argc != 3) { return; } - /* Read rssi */ - rssi = atoi(argv[1]); - - if (rssi == 99) { - return; - } - - data->rssi = (-113 + (2 * rssi)); + data->rssi = (uint8_t)atoi(argv[1]); } static void modem_cellular_chat_on_imsi(struct modem_chat *chat, char **argv, uint16_t argc, @@ -1263,36 +1247,78 @@ static void modem_cellular_cmux_handler(struct modem_cmux *cmux, enum modem_cmux } } +MODEM_CHAT_SCRIPT_CMDS_DEFINE(get_signal_csq_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CSQ", csq_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match)); + +MODEM_CHAT_SCRIPT_DEFINE(get_signal_csq_chat_script, get_signal_csq_chat_script_cmds, + abort_matches, modem_cellular_chat_callback_handler, 2); + +static inline int modem_cellular_csq_parse_rssi(uint8_t rssi, int16_t *value) +{ + /* AT+CSQ returns a response +CSQ: , where: + * - rssi is a integer from 0 to 31 whose values describes a signal strength + * between -113 dBm for 0 and -51dbM for 31 or unknown for 99 + * - ber is an integer from 0 to 7 that describes the error rate, it can also + * be 99 for an unknown error rate + */ + if (rssi == 99) { + return -EINVAL; + } + + *value = (int16_t)(-113 + (2 * rssi)); + return 0; +} + static int modem_cellular_get_signal(const struct device *dev, const enum cellular_signal_type type, int16_t *value) { - int ret; + int ret = -ENOTSUP; struct modem_cellular_data *data = (struct modem_cellular_data *)dev->data; - const struct modem_cellular_config *config = (struct modem_cellular_config *)dev->config; - - if (config->get_signal_chat_script == NULL) { - return -ENOTSUP; - } if ((data->state != MODEM_CELLULAR_STATE_AWAIT_REGISTERED) && (data->state != MODEM_CELLULAR_STATE_CARRIER_ON)) { return -ENODATA; } - ret = modem_chat_run_script(&data->chat, config->get_signal_chat_script); - if (ret != 0) { + /* Run chat script */ + switch (type) { + case CELLULAR_SIGNAL_RSSI: + ret = modem_chat_run_script(&data->chat, &get_signal_csq_chat_script); + break; + + case CELLULAR_SIGNAL_RSRP: + case CELLULAR_SIGNAL_RSRQ: + /* TODO: Run CESQ script */ + ret = -ENOTSUP; + break; + + default: + ret = -ENOTSUP; + break; + } + + /* Verify chat script ran successfully */ + if (ret < 0) { return ret; } + /* Parse received value */ switch (type) { - case CELLULAR_SIGNAL_RSSI: { - *value = data->rssi; - } break; + case CELLULAR_SIGNAL_RSSI: + ret = modem_cellular_csq_parse_rssi(data->rssi, value); + break; + case CELLULAR_SIGNAL_RSRP: - return -ENOTSUP; case CELLULAR_SIGNAL_RSRQ: - return -ENOTSUP; + /* TODO: Validate and set values */ + ret = -ENODATA; + break; + + default: + ret = -ENOTSUP; + break; } return ret; @@ -1517,19 +1543,11 @@ MODEM_CHAT_SCRIPT_DEFINE(quectel_bg95_dial_chat_script, quectel_bg95_dial_chat_s MODEM_CHAT_SCRIPT_CMDS_DEFINE(quectel_bg95_periodic_chat_script_cmds, MODEM_CHAT_SCRIPT_CMD_RESP("AT+CREG?", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG?", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG?", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CSQ", csq_match)); + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG?", ok_match)); MODEM_CHAT_SCRIPT_DEFINE(quectel_bg95_periodic_chat_script, quectel_bg95_periodic_chat_script_cmds, abort_matches, modem_cellular_chat_callback_handler, 4); - -MODEM_CHAT_SCRIPT_CMDS_DEFINE(quectel_bg95_get_signal_chat_script_cmds, - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CSQ", csq_match)); - -MODEM_CHAT_SCRIPT_DEFINE(quectel_bg95_get_signal_chat_script, - quectel_bg95_get_signal_chat_script_cmds, abort_matches, - modem_cellular_chat_callback_handler, 4); #endif #if DT_HAS_COMPAT_STATUS_OKAY(quectel_eg25_g) @@ -1580,13 +1598,6 @@ MODEM_CHAT_SCRIPT_CMDS_DEFINE(quectel_eg25_g_periodic_chat_script_cmds, MODEM_CHAT_SCRIPT_DEFINE(quectel_eg25_g_periodic_chat_script, quectel_eg25_g_periodic_chat_script_cmds, abort_matches, modem_cellular_chat_callback_handler, 4); - -MODEM_CHAT_SCRIPT_CMDS_DEFINE(quectel_eg25_g_get_signal_chat_script_cmds, - MODEM_CHAT_SCRIPT_CMD_RESP("AT+CSQ", csq_match)); - -MODEM_CHAT_SCRIPT_DEFINE(quectel_eg25_g_get_signal_chat_script, - quectel_eg25_g_get_signal_chat_script_cmds, abort_matches, - modem_cellular_chat_callback_handler, 4); #endif #if DT_HAS_COMPAT_STATUS_OKAY(zephyr_gsm_ppp) @@ -1895,7 +1906,6 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, .init_chat_script = &quectel_bg95_init_chat_script, \ .dial_chat_script = &quectel_bg95_dial_chat_script, \ .periodic_chat_script = &_CONCAT(DT_DRV_COMPAT, _periodic_chat_script), \ - .get_signal_chat_script = &_CONCAT(DT_DRV_COMPAT, _get_signal_chat_script), \ }; \ \ PM_DEVICE_DT_INST_DEFINE(inst, modem_cellular_pm_action); \ @@ -1925,7 +1935,6 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, .init_chat_script = &quectel_eg25_g_init_chat_script, \ .dial_chat_script = &quectel_eg25_g_dial_chat_script, \ .periodic_chat_script = &_CONCAT(DT_DRV_COMPAT, _periodic_chat_script), \ - .get_signal_chat_script = &_CONCAT(DT_DRV_COMPAT, _get_signal_chat_script), \ }; \ \ PM_DEVICE_DT_INST_DEFINE(inst, modem_cellular_pm_action); \ From 8fdf4874aac9e4bb1bd0ac6f7494ce197b98461f Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 29 Dec 2023 13:33:24 +0100 Subject: [PATCH 1409/1623] [nrf fromtree] modem: modem_cellular.c: Remove non standard QCCID handler The QCCID handler is Quectel specific and as such may not be part of the modem cellular driver which only supports commands defined in 3GPP TS 27.007 Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 1ee092673a13c1f74da932c6ca27fc634304d118) --- drivers/modem/modem_cellular.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index 78958bdec2c..16530edde6c 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -348,14 +348,6 @@ static void modem_cellular_chat_on_imsi(struct modem_chat *chat, char **argv, ui strncpy(data->imsi, (char *)argv[1], sizeof(data->imsi)); } -static void modem_cellular_chat_on_iccid(struct modem_chat *chat, char **argv, uint16_t argc, - void *user_data) -{ - struct modem_cellular_data *data = (struct modem_cellular_data *)user_data; - - strncpy(data->iccid, (char *)argv[1], sizeof(data->iccid)); -} - static bool modem_cellular_is_registered(struct modem_cellular_data *data) { return (data->registration_status_gsm == 1) @@ -407,7 +399,6 @@ MODEM_CHAT_MATCH_DEFINE(imei_match, "", "", modem_cellular_chat_on_imei); MODEM_CHAT_MATCH_DEFINE(cgmm_match, "", "", modem_cellular_chat_on_cgmm); MODEM_CHAT_MATCH_DEFINE(csq_match, "+CSQ: ", ",", modem_cellular_chat_on_csq); MODEM_CHAT_MATCH_DEFINE(cimi_match, "", "", modem_cellular_chat_on_imsi); -MODEM_CHAT_MATCH_DEFINE(ccid_match, "+QCCID: ", "", modem_cellular_chat_on_iccid); MODEM_CHAT_MATCH_DEFINE(cgmi_match, "", "", modem_cellular_chat_on_cgmi); MODEM_CHAT_MATCH_DEFINE(cgmr_match, "", "", modem_cellular_chat_on_cgmr); @@ -1338,9 +1329,6 @@ static int modem_cellular_get_modem_info(const struct device *dev, case CELLULAR_MODEM_INFO_SIM_IMSI: strncpy(info, &data->imsi[0], MIN(size, sizeof(data->imsi))); break; - case CELLULAR_MODEM_INFO_SIM_ICCID: - strncpy(info, &data->iccid[0], MIN(size, sizeof(data->iccid))); - break; case CELLULAR_MODEM_INFO_MANUFACTURER: strncpy(info, &data->manufacturer[0], MIN(size, sizeof(data->manufacturer))); break; @@ -1522,8 +1510,6 @@ MODEM_CHAT_SCRIPT_CMDS_DEFINE(quectel_bg95_init_chat_script_cmds, MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP("AT+CIMI", cimi_match), MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+QCCID", ccid_match), - MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP_NONE("AT+CMUX=0,0,5,127", 300)); MODEM_CHAT_SCRIPT_DEFINE(quectel_bg95_init_chat_script, quectel_bg95_init_chat_script_cmds, @@ -1571,8 +1557,6 @@ MODEM_CHAT_SCRIPT_CMDS_DEFINE( MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP("AT+CIMI", cimi_match), MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), - MODEM_CHAT_SCRIPT_CMD_RESP("AT+QCCID", ccid_match), - MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP_NONE("AT+CMUX=0,0,5,127,10,3,30,10,2", 100)); MODEM_CHAT_SCRIPT_DEFINE(quectel_eg25_g_init_chat_script, quectel_eg25_g_init_chat_script_cmds, From dc270c2815d564f882cf271e563ddb51decf5f5b Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 25 Dec 2023 09:26:47 +0100 Subject: [PATCH 1410/1623] [nrf fromtree] modem: chat: Patch invalid dereference The chat module contains an array of three lists of matches, one of which are static, two of which are contained within the currently running script. The current match, which is an object stored in one of the three lists, is stored in its own pointer in the chat module context. A memory error occurs when the script is stopped, while the chat module is using one of the matches stored withing the script. This commit clears the match pointer when the script is stopped if the match is stored within the script. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 3ebe8142945e53828c1a6c91f4b134adece4af33) --- subsys/modem/modem_chat.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/subsys/modem/modem_chat.c b/subsys/modem/modem_chat.c index 0ab1175f980..7cf7692c514 100644 --- a/subsys/modem/modem_chat.c +++ b/subsys/modem/modem_chat.c @@ -60,7 +60,7 @@ static void modem_chat_log_received_command(struct modem_chat *chat) static void modem_chat_script_stop(struct modem_chat *chat, enum modem_chat_script_result result) { - if (!chat || !chat->script) { + if ((chat == NULL) || (chat->script == NULL)) { return; } @@ -78,6 +78,14 @@ static void modem_chat_script_stop(struct modem_chat *chat, enum modem_chat_scri chat->script->callback(chat, result, chat->user_data); } + /* Clear parse_match in case it is stored in the script being stopped */ + if ((chat->parse_match != NULL) && + ((chat->parse_match_type == MODEM_CHAT_MATCHES_INDEX_ABORT) || + (chat->parse_match_type == MODEM_CHAT_MATCHES_INDEX_RESPONSE))) { + chat->parse_match = NULL; + chat->parse_match_len = 0; + } + /* Clear reference to script */ chat->script = NULL; @@ -822,4 +830,8 @@ void modem_chat_release(struct modem_chat *chat) chat->parse_match = NULL; chat->parse_match_len = 0; chat->parse_arg_len = 0; + chat->matches[MODEM_CHAT_MATCHES_INDEX_ABORT] = NULL; + chat->matches_size[MODEM_CHAT_MATCHES_INDEX_ABORT] = 0; + chat->matches[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = NULL; + chat->matches_size[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = 0; } From 47b99cf2c8201bc592e5ce467f2ac4ccc2150614 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 6 Dec 2023 18:22:28 +0100 Subject: [PATCH 1411/1623] [nrf fromtree] modem: cmux: Patch resync mechanism The CMUX resync mechanism can get stuck between states MODEM_CMUX_RECEIVE_STATE_RESYNC_0 and MODEM_CMUX_RECEIVE_STATE_RESYNC_1 if the resync flags, which are sent only once in state MODEM_CMUX_RECEIVE_STATE_SOF, are not responded to, or the response is lost. This patch ensures resync flags are sent from states MODEM_CMUX_RECEIVE_STATE_SOF, MODEM_CMUX_RECEIVE_STATE_RESYNC_1 and MODEM_CMUX_RECEIVE_STATE_RESYNC_2 if its determined that the resync flags are not being responded to. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 48fa603da37e6161c299af52bccad6165222548f) --- subsys/modem/modem_cmux.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index 3ace00d6583..7f40fa6e95d 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -638,10 +638,16 @@ static void modem_cmux_on_frame(struct modem_cmux *cmux) modem_cmux_on_dlci_frame(cmux); } +static void modem_cmux_transmit_resync(struct modem_cmux *cmux) +{ + static const uint8_t resync[3] = {0xF9, 0xF9, 0xF9}; + + modem_pipe_transmit(cmux->pipe, resync, sizeof(resync)); +} + static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t byte) { uint8_t fcs; - static const uint8_t resync[3] = {0xF9, 0xF9, 0xF9}; switch (cmux->receive_state) { case MODEM_CMUX_RECEIVE_STATE_SOF: @@ -650,10 +656,7 @@ static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t by break; } - /* Send resync flags */ - modem_pipe_transmit(cmux->pipe, resync, sizeof(resync)); - - /* Await resync flags */ + modem_cmux_transmit_resync(cmux); cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_0; break; @@ -668,6 +671,7 @@ static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t by if (byte == 0xF9) { cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_2; } else { + modem_cmux_transmit_resync(cmux); cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_0; } @@ -677,6 +681,7 @@ static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t by if (byte == 0xF9) { cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_3; } else { + modem_cmux_transmit_resync(cmux); cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_0; } From dfe74143f488f25728336a26169f596391608e68 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 4 Jan 2024 13:32:35 +0100 Subject: [PATCH 1412/1623] [nrf fromtree] modem: cmux: Add DLCI receive buffer overrun LOG WRN DLCI receive buffer may overrun if data is not processed fast enough. This error was not reported before this patch, resulting in unexplained missing bytes. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit b3971d01129676f566ab813f2cb34ffbfb12d8d1) --- subsys/modem/modem_cmux.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index 7f40fa6e95d..258f969c498 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -546,6 +546,7 @@ static void modem_cmux_on_dlci_frame_ua(struct modem_cmux_dlci *dlci) static void modem_cmux_on_dlci_frame_uih(struct modem_cmux_dlci *dlci) { struct modem_cmux *cmux = dlci->cmux; + uint32_t written; if (dlci->state != MODEM_CMUX_DLCI_STATE_OPEN) { LOG_DBG("Unexpected UIH frame"); @@ -553,8 +554,11 @@ static void modem_cmux_on_dlci_frame_uih(struct modem_cmux_dlci *dlci) } k_mutex_lock(&dlci->receive_rb_lock, K_FOREVER); - ring_buf_put(&dlci->receive_rb, cmux->frame.data, cmux->frame.data_len); + written = ring_buf_put(&dlci->receive_rb, cmux->frame.data, cmux->frame.data_len); k_mutex_unlock(&dlci->receive_rb_lock); + if (written != cmux->frame.data_len) { + LOG_WRN("DLCI %u receive buffer overrun", dlci->dlci_address); + } modem_pipe_notify_receive_ready(&dlci->pipe); } From 5c15715bdb6eda6fa995e5365c9fa39b23b98018 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Tue, 9 Jan 2024 15:13:57 +0100 Subject: [PATCH 1413/1623] [nrf fromtree] modem: cmux: Simplify resync mechanism Some modems don't start sending resync flags as described in 3G TS 27.010 V2.0.0 5.2.5, which results in the CMUX being stuck in resync mode for said modems. This patch simplifies the resync mechanism to simply drop invalid frames, and wait for atleast two consequtive frame flags (stop+start). Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 3debfc8c8d4d224d92be35786fd9774f6030580a) --- include/zephyr/modem/cmux.h | 5 +--- subsys/modem/modem_cmux.c | 46 +++++++------------------------------ 2 files changed, 9 insertions(+), 42 deletions(-) diff --git a/include/zephyr/modem/cmux.h b/include/zephyr/modem/cmux.h index 4562cb544d9..58959d6136b 100644 --- a/include/zephyr/modem/cmux.h +++ b/include/zephyr/modem/cmux.h @@ -63,10 +63,7 @@ enum modem_cmux_state { enum modem_cmux_receive_state { MODEM_CMUX_RECEIVE_STATE_SOF = 0, - MODEM_CMUX_RECEIVE_STATE_RESYNC_0, - MODEM_CMUX_RECEIVE_STATE_RESYNC_1, - MODEM_CMUX_RECEIVE_STATE_RESYNC_2, - MODEM_CMUX_RECEIVE_STATE_RESYNC_3, + MODEM_CMUX_RECEIVE_STATE_RESYNC, MODEM_CMUX_RECEIVE_STATE_ADDRESS, MODEM_CMUX_RECEIVE_STATE_ADDRESS_CONT, MODEM_CMUX_RECEIVE_STATE_CONTROL, diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index 258f969c498..472d1a7149a 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -642,13 +642,6 @@ static void modem_cmux_on_frame(struct modem_cmux *cmux) modem_cmux_on_dlci_frame(cmux); } -static void modem_cmux_transmit_resync(struct modem_cmux *cmux) -{ - static const uint8_t resync[3] = {0xF9, 0xF9, 0xF9}; - - modem_pipe_transmit(cmux->pipe, resync, sizeof(resync)); -} - static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t byte) { uint8_t fcs; @@ -656,46 +649,23 @@ static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t by switch (cmux->receive_state) { case MODEM_CMUX_RECEIVE_STATE_SOF: if (byte == 0xF9) { - cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_ADDRESS; + cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC; break; } - modem_cmux_transmit_resync(cmux); - cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_0; - break; - - case MODEM_CMUX_RECEIVE_STATE_RESYNC_0: - if (byte == 0xF9) { - cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_1; - } - - break; - - case MODEM_CMUX_RECEIVE_STATE_RESYNC_1: - if (byte == 0xF9) { - cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_2; - } else { - modem_cmux_transmit_resync(cmux); - cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_0; - } - break; - case MODEM_CMUX_RECEIVE_STATE_RESYNC_2: - if (byte == 0xF9) { - cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_3; - } else { - modem_cmux_transmit_resync(cmux); - cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_0; - } - - break; - - case MODEM_CMUX_RECEIVE_STATE_RESYNC_3: + case MODEM_CMUX_RECEIVE_STATE_RESYNC: + /* + * Allow any number of consequtive flags (0xF9). + * 0xF9 could also be a valid address field for DLCI 62. + */ if (byte == 0xF9) { break; } + __fallthrough; + case MODEM_CMUX_RECEIVE_STATE_ADDRESS: /* Initialize */ cmux->receive_buf_len = 0; From 242758ddf41eddac4f8fe4b0fabcf5fe17de13a4 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 10 Jan 2024 17:55:33 +0100 Subject: [PATCH 1414/1623] [nrf fromtree] tests: subsys: modem: cmux: Update resync unit test Update the unit test to expect the new simplified resync behavior, and validate that new resync is working. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 7d7f7aaf03fd0728d298dce22c20cb3098c3d0aa) --- tests/subsys/modem/modem_cmux/src/main.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/subsys/modem/modem_cmux/src/main.c b/tests/subsys/modem/modem_cmux/src/main.c index 9df6837efc5..d601eeb1446 100644 --- a/tests/subsys/modem/modem_cmux/src/main.c +++ b/tests/subsys/modem/modem_cmux/src/main.c @@ -144,8 +144,6 @@ static uint8_t cmux_frame_data_dlci1_at_newline[] = {0x0D, 0x0A}; /*************************************************************************************************/ static uint8_t cmux_frame_dlci1_at_at_desync[] = {0x41, 0x54, 0x30, 0xF9}; -static uint8_t cmux_frame_resync[] = {0xF9, 0xF9, 0xF9}; - /*************************************************************************************************/ /* DLCI2 PPP CMUX frames */ /*************************************************************************************************/ @@ -401,15 +399,6 @@ ZTEST(modem_cmux, test_modem_cmux_resync) modem_backend_mock_put(&bus_mock, cmux_frame_dlci1_at_at_desync, sizeof(cmux_frame_dlci1_at_at_desync)); - - k_msleep(100); - - ret = modem_backend_mock_get(&bus_mock, buffer1, sizeof(buffer1)); - zassert_true(ret == sizeof(cmux_frame_resync), "Expected resync flags to be sent to bus"); - zassert_true(memcmp(buffer1, cmux_frame_resync, sizeof(cmux_frame_resync)) == 0, - "Expected resync flags to be sent to bus"); - - modem_backend_mock_put(&bus_mock, cmux_frame_resync, sizeof(cmux_frame_resync)); modem_backend_mock_put(&bus_mock, cmux_frame_dlci1_at_at, sizeof(cmux_frame_dlci1_at_at)); modem_backend_mock_put(&bus_mock, cmux_frame_dlci1_at_newline, sizeof(cmux_frame_dlci1_at_newline)); From 27c617380c172c2c382fca49f2ef4332f42c46c6 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 22 Nov 2023 06:59:44 +0100 Subject: [PATCH 1415/1623] [nrf fromtree] modem: pipe: Add TRANSMIT_IDLE event Add transmit idle event to modem_pipe_event enum. This will allow modules to await transmit idle before trying to transmit more data, instead of blindly calling modem_pipe_transmit in a loop until all data has been accepted. This will reduce the time spent trying to transmit data while the backend is blocked. Similarly to the RECEIVE_READY event, backends will call modem_pipe_notify_transmit_idle() to indicate that transmit is idle, and the TRANSMIT_IDLE event will be reinvoked when the modem pipe is attached to synchronize the state of the pipe with the user of it. Additionally, the TRANSMIT_IDLE event is also invoked when the modem is opened to further help synchronization with the user of the pipe. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 516af3cb8432fd8fde2b10b8f7e78486d51b69d4) --- include/zephyr/modem/pipe.h | 13 ++++++++++++- subsys/modem/modem_pipe.c | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/zephyr/modem/pipe.h b/include/zephyr/modem/pipe.h index abf8d74918e..a741a94a34c 100644 --- a/include/zephyr/modem/pipe.h +++ b/include/zephyr/modem/pipe.h @@ -25,6 +25,7 @@ extern "C" { enum modem_pipe_event { MODEM_PIPE_EVENT_OPENED = 0, MODEM_PIPE_EVENT_RECEIVE_READY, + MODEM_PIPE_EVENT_TRANSMIT_IDLE, MODEM_PIPE_EVENT_CLOSED, }; @@ -73,7 +74,8 @@ struct modem_pipe { enum modem_pipe_state state; struct k_mutex lock; struct k_condvar condvar; - bool receive_ready_pending; + uint8_t receive_ready_pending : 1; + uint8_t transmit_idle_pending : 1; }; /** @@ -213,6 +215,15 @@ void modem_pipe_notify_closed(struct modem_pipe *pipe); */ void modem_pipe_notify_receive_ready(struct modem_pipe *pipe); +/** + * @brief Notify user of pipe that pipe has no more data to transmit + * + * @param pipe Pipe instance + * + * @note Invoked from instance which initialized the pipe instance + */ +void modem_pipe_notify_transmit_idle(struct modem_pipe *pipe); + /** * @endcond */ diff --git a/subsys/modem/modem_pipe.c b/subsys/modem/modem_pipe.c index 01bdac50d3a..b0088fdefed 100644 --- a/subsys/modem/modem_pipe.c +++ b/subsys/modem/modem_pipe.c @@ -21,6 +21,7 @@ void modem_pipe_init(struct modem_pipe *pipe, void *data, struct modem_pipe_api pipe->user_data = NULL; pipe->state = MODEM_PIPE_STATE_CLOSED; pipe->receive_ready_pending = false; + pipe->transmit_idle_pending = true; k_mutex_init(&pipe->lock); k_condvar_init(&pipe->condvar); @@ -82,6 +83,10 @@ void modem_pipe_attach(struct modem_pipe *pipe, modem_pipe_api_callback callback pipe->callback(pipe, MODEM_PIPE_EVENT_RECEIVE_READY, pipe->user_data); } + if (pipe->transmit_idle_pending && (pipe->callback != NULL)) { + pipe->callback(pipe, MODEM_PIPE_EVENT_TRANSMIT_IDLE, pipe->user_data); + } + k_mutex_unlock(&pipe->lock); } @@ -97,6 +102,7 @@ int modem_pipe_transmit(struct modem_pipe *pipe, const uint8_t *buf, size_t size } ret = pipe->api->transmit(pipe->data, buf, size); + pipe->transmit_idle_pending = false; k_mutex_unlock(&pipe->lock); return ret; } @@ -179,6 +185,7 @@ void modem_pipe_notify_opened(struct modem_pipe *pipe) if (pipe->callback != NULL) { pipe->callback(pipe, MODEM_PIPE_EVENT_OPENED, pipe->user_data); + pipe->callback(pipe, MODEM_PIPE_EVENT_TRANSMIT_IDLE, pipe->user_data); } k_condvar_signal(&pipe->condvar); @@ -190,6 +197,7 @@ void modem_pipe_notify_closed(struct modem_pipe *pipe) k_mutex_lock(&pipe->lock, K_FOREVER); pipe->state = MODEM_PIPE_STATE_CLOSED; pipe->receive_ready_pending = false; + pipe->transmit_idle_pending = true; if (pipe->callback != NULL) { pipe->callback(pipe, MODEM_PIPE_EVENT_CLOSED, pipe->user_data); @@ -211,3 +219,16 @@ void modem_pipe_notify_receive_ready(struct modem_pipe *pipe) k_mutex_unlock(&pipe->lock); } + +void modem_pipe_notify_transmit_idle(struct modem_pipe *pipe) +{ + k_mutex_lock(&pipe->lock, K_FOREVER); + + pipe->transmit_idle_pending = true; + + if (pipe->callback != NULL) { + pipe->callback(pipe, MODEM_PIPE_EVENT_TRANSMIT_IDLE, pipe->user_data); + } + + k_mutex_unlock(&pipe->lock); +} From 86431c23d1cd59fc8cd8e040f1a1af62b554ed27 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 22 Nov 2023 07:30:12 +0100 Subject: [PATCH 1416/1623] [nrf fromtree] modem: backend: uart: Implement transmit idle event Make async and interrupt driven UART backends notify transmit idle when transmit is idle. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 8c6a9ee594acdf300636dd30f86fd05fe16fb03f) --- include/zephyr/modem/backend/uart.h | 1 + subsys/modem/backends/modem_backend_uart.c | 9 +++++++++ subsys/modem/backends/modem_backend_uart_async.c | 2 ++ subsys/modem/backends/modem_backend_uart_isr.c | 1 + 4 files changed, 13 insertions(+) diff --git a/include/zephyr/modem/backend/uart.h b/include/zephyr/modem/backend/uart.h index 0ddef4df734..5f9f99370a0 100644 --- a/include/zephyr/modem/backend/uart.h +++ b/include/zephyr/modem/backend/uart.h @@ -43,6 +43,7 @@ struct modem_backend_uart { const struct device *uart; struct modem_pipe pipe; struct k_work receive_ready_work; + struct k_work transmit_idle_work; union { struct modem_backend_uart_isr isr; diff --git a/subsys/modem/backends/modem_backend_uart.c b/subsys/modem/backends/modem_backend_uart.c index b4b0b81c291..a8348b0b8a0 100644 --- a/subsys/modem/backends/modem_backend_uart.c +++ b/subsys/modem/backends/modem_backend_uart.c @@ -22,6 +22,14 @@ static void modem_backend_uart_receive_ready_handler(struct k_work *item) modem_pipe_notify_receive_ready(&backend->pipe); } +static void modem_backend_uart_transmit_idle_handler(struct k_work *item) +{ + struct modem_backend_uart *backend = + CONTAINER_OF(item, struct modem_backend_uart, transmit_idle_work); + + modem_pipe_notify_transmit_idle(&backend->pipe); +} + struct modem_pipe *modem_backend_uart_init(struct modem_backend_uart *backend, const struct modem_backend_uart_config *config) { @@ -35,6 +43,7 @@ struct modem_pipe *modem_backend_uart_init(struct modem_backend_uart *backend, memset(backend, 0x00, sizeof(*backend)); backend->uart = config->uart; k_work_init(&backend->receive_ready_work, modem_backend_uart_receive_ready_handler); + k_work_init(&backend->transmit_idle_work, modem_backend_uart_transmit_idle_handler); #ifdef CONFIG_MODEM_BACKEND_UART_ASYNC if (modem_backend_uart_async_is_supported(backend)) { diff --git a/subsys/modem/backends/modem_backend_uart_async.c b/subsys/modem/backends/modem_backend_uart_async.c index bd18edbd2f5..47148a77f77 100644 --- a/subsys/modem/backends/modem_backend_uart_async.c +++ b/subsys/modem/backends/modem_backend_uart_async.c @@ -44,6 +44,7 @@ static void modem_backend_uart_async_event_handler(const struct device *dev, case UART_TX_DONE: atomic_clear_bit(&backend->async.state, MODEM_BACKEND_UART_ASYNC_STATE_TRANSMITTING_BIT); + k_work_submit(&backend->transmit_idle_work); break; @@ -51,6 +52,7 @@ static void modem_backend_uart_async_event_handler(const struct device *dev, LOG_WRN("Transmit aborted"); atomic_clear_bit(&backend->async.state, MODEM_BACKEND_UART_ASYNC_STATE_TRANSMITTING_BIT); + k_work_submit(&backend->transmit_idle_work); break; diff --git a/subsys/modem/backends/modem_backend_uart_isr.c b/subsys/modem/backends/modem_backend_uart_isr.c index 7c88cb4673c..8a7075e3519 100644 --- a/subsys/modem/backends/modem_backend_uart_isr.c +++ b/subsys/modem/backends/modem_backend_uart_isr.c @@ -56,6 +56,7 @@ static void modem_backend_uart_isr_irq_handler_transmit_ready(struct modem_backe if (ring_buf_is_empty(&backend->isr.transmit_rb) == true) { uart_irq_tx_disable(backend->uart); + k_work_submit(&backend->transmit_idle_work); return; } From 7fb5794f6795de91f3677c39cd1f03ea0ffd912b Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 22 Nov 2023 07:33:38 +0100 Subject: [PATCH 1417/1623] [nrf fromtree] modem: backend: tty: Implement transmit idle event Implement transmit idle notification for TTY backend. Since TTY has an "infinite" transmit buffer, we invoke transmit idle immediately after writing the data to the TTY file. The test suite for the TTY backend has been updated to match the new behavior. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 4d99c69e4aa818c1407789e4e21dfa9102cb533b) --- subsys/modem/backends/modem_backend_tty.c | 5 ++++- tests/subsys/modem/backends/tty/src/main.c | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/subsys/modem/backends/modem_backend_tty.c b/subsys/modem/backends/modem_backend_tty.c index b8864fc3d91..8375183be48 100644 --- a/subsys/modem/backends/modem_backend_tty.c +++ b/subsys/modem/backends/modem_backend_tty.c @@ -73,8 +73,11 @@ static int modem_backend_tty_open(void *data) static int modem_backend_tty_transmit(void *data, const uint8_t *buf, size_t size) { struct modem_backend_tty *backend = (struct modem_backend_tty *)data; + int ret; - return write(backend->tty_fd, buf, size); + ret = write(backend->tty_fd, buf, size); + modem_pipe_notify_transmit_idle(&backend->pipe); + return ret; } static int modem_backend_tty_receive(void *data, uint8_t *buf, size_t size) diff --git a/tests/subsys/modem/backends/tty/src/main.c b/tests/subsys/modem/backends/tty/src/main.c index 49a1841486a..96ebdb2763d 100644 --- a/tests/subsys/modem/backends/tty/src/main.c +++ b/tests/subsys/modem/backends/tty/src/main.c @@ -22,7 +22,8 @@ #define TEST_MODEM_BACKEND_TTY_PIPE_EVENT_OPENED_BIT (0) #define TEST_MODEM_BACKEND_TTY_PIPE_EVENT_RRDY_BIT (1) -#define TEST_MODEM_BACKEND_TTY_PIPE_EVENT_CLOSED_BIT (2) +#define TEST_MODEM_BACKEND_TTY_PIPE_EVENT_TIDLE_BIT (2) +#define TEST_MODEM_BACKEND_TTY_PIPE_EVENT_CLOSED_BIT (3) #define TEST_MODEM_BACKEND_TTY_OP_DELAY (K_MSEC(1000)) @@ -72,6 +73,10 @@ static void modem_pipe_callback_handler(struct modem_pipe *pipe, enum modem_pipe atomic_set_bit(&tty_pipe_events, TEST_MODEM_BACKEND_TTY_PIPE_EVENT_RRDY_BIT); break; + case MODEM_PIPE_EVENT_TRANSMIT_IDLE: + atomic_set_bit(&tty_pipe_events, TEST_MODEM_BACKEND_TTY_PIPE_EVENT_TIDLE_BIT); + break; + case MODEM_PIPE_EVENT_CLOSED: atomic_set_bit(&tty_pipe_events, TEST_MODEM_BACKEND_TTY_PIPE_EVENT_CLOSED_BIT); break; @@ -122,9 +127,13 @@ static void test_modem_backend_tty_teardown(void *f) /*************************************************************************************************/ ZTEST(modem_backend_tty_suite, test_close_open) { + bool result; + zassert_ok(modem_pipe_close(tty_pipe), "Failed to close pipe"); zassert_ok(modem_pipe_close(tty_pipe), "Pipe should already be closed"); zassert_ok(modem_pipe_open(tty_pipe), "Failed to open pipe"); + result = atomic_test_bit(&tty_pipe_events, TEST_MODEM_BACKEND_TTY_PIPE_EVENT_TIDLE_BIT); + zassert_true(result, "Transmit idle event should be set"); zassert_ok(modem_pipe_open(tty_pipe), "Pipe should already be open"); } @@ -172,12 +181,19 @@ ZTEST(modem_backend_tty_suite, test_transmit) { int ret; char msg[] = "Test me buddy 2"; + bool result; + + result = atomic_test_bit(&tty_pipe_events, TEST_MODEM_BACKEND_TTY_PIPE_EVENT_TIDLE_BIT); + zassert_false(result, "Transmit idle event should not be set"); ret = modem_pipe_transmit(tty_pipe, msg, sizeof(msg)); zassert_true(ret == sizeof(msg), "Failed to transmit using pipe"); k_sleep(TEST_MODEM_BACKEND_TTY_OP_DELAY); + result = atomic_test_bit(&tty_pipe_events, TEST_MODEM_BACKEND_TTY_PIPE_EVENT_TIDLE_BIT); + zassert_true(result, "Transmit idle event should be set"); + ret = read(primary_fd, buffer1, sizeof(buffer1)); zassert_true(ret == sizeof(msg), "Read incorrect number of bytes"); ret = memcmp(msg, buffer1, sizeof(msg)); From 49b54ccf858d5e8f85ca7263e46da0209a12c4e1 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 23 Nov 2023 11:15:09 +0100 Subject: [PATCH 1418/1623] [nrf fromtree] modem: pipe: Add test suite Add test suite for the modem_pipe module. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 9176e5c5681d3cafc6087c29d52017fe134ccde8) --- tests/subsys/modem/modem_pipe/CMakeLists.txt | 8 + tests/subsys/modem/modem_pipe/prj.conf | 8 + tests/subsys/modem/modem_pipe/src/main.c | 401 +++++++++++++++++++ tests/subsys/modem/modem_pipe/testcase.yaml | 8 + 4 files changed, 425 insertions(+) create mode 100644 tests/subsys/modem/modem_pipe/CMakeLists.txt create mode 100644 tests/subsys/modem/modem_pipe/prj.conf create mode 100644 tests/subsys/modem/modem_pipe/src/main.c create mode 100644 tests/subsys/modem/modem_pipe/testcase.yaml diff --git a/tests/subsys/modem/modem_pipe/CMakeLists.txt b/tests/subsys/modem/modem_pipe/CMakeLists.txt new file mode 100644 index 00000000000..9d160a67720 --- /dev/null +++ b/tests/subsys/modem/modem_pipe/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright (c) 2023 Trackunit Corporation +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(modem_pipe_test) + +target_sources(app PRIVATE src/main.c) diff --git a/tests/subsys/modem/modem_pipe/prj.conf b/tests/subsys/modem/modem_pipe/prj.conf new file mode 100644 index 00000000000..ab3228738b9 --- /dev/null +++ b/tests/subsys/modem/modem_pipe/prj.conf @@ -0,0 +1,8 @@ +# Copyright (c) 2023 Trackunit Corporation +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_NO_OPTIMIZATIONS=y +CONFIG_MODEM_MODULES=y +CONFIG_MODEM_PIPE=y +CONFIG_EVENTS=y +CONFIG_ZTEST=y diff --git a/tests/subsys/modem/modem_pipe/src/main.c b/tests/subsys/modem/modem_pipe/src/main.c new file mode 100644 index 00000000000..07cc93decfe --- /dev/null +++ b/tests/subsys/modem/modem_pipe/src/main.c @@ -0,0 +1,401 @@ +/* + * Copyright (c) 2023 Trackunit Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/*************************************************************************************************/ +/* Dependencies */ +/*************************************************************************************************/ +#include +#include +#include +#include +#include + +#define TEST_MODEM_PIPE_EVENT_OPENED_BIT 0 +#define TEST_MODEM_PIPE_EVENT_TRANSMIT_IDLE_BIT 1 +#define TEST_MODEM_PIPE_EVENT_RECEIVE_READY_BIT 2 +#define TEST_MODEM_PIPE_EVENT_CLOSED_BIT 3 +#define TEST_MODEM_PIPE_NOTIFY_TIMEOUT K_MSEC(10) +#define TEST_MODEM_PIPE_WAIT_TIMEOUT K_MSEC(20) + +/*************************************************************************************************/ +/* Fake modem_pipe backend */ +/*************************************************************************************************/ +struct modem_backend_fake { + struct modem_pipe pipe; + + struct k_work_delayable opened_dwork; + struct k_work_delayable transmit_idle_dwork; + struct k_work_delayable closed_dwork; + + const uint8_t *transmit_buffer; + size_t transmit_buffer_size; + + uint8_t *receive_buffer; + size_t receive_buffer_size; + + uint8_t synchronous : 1; + uint8_t open_called : 1; + uint8_t transmit_called : 1; + uint8_t receive_called : 1; + uint8_t close_called : 1; +}; + +static void modem_backend_fake_opened_handler(struct k_work *item) +{ + struct k_work_delayable *dwork = k_work_delayable_from_work(item); + struct modem_backend_fake *backend = + CONTAINER_OF(dwork, struct modem_backend_fake, opened_dwork); + + modem_pipe_notify_opened(&backend->pipe); +} + +static int modem_backend_fake_open(void *data) +{ + struct modem_backend_fake *backend = data; + + backend->open_called = true; + + if (backend->synchronous) { + modem_pipe_notify_opened(&backend->pipe); + } else { + k_work_schedule(&backend->opened_dwork, TEST_MODEM_PIPE_NOTIFY_TIMEOUT); + } + + return 0; +} + +static void modem_backend_fake_transmit_idle_handler(struct k_work *item) +{ + struct k_work_delayable *dwork = k_work_delayable_from_work(item); + struct modem_backend_fake *backend = + CONTAINER_OF(dwork, struct modem_backend_fake, transmit_idle_dwork); + + modem_pipe_notify_transmit_idle(&backend->pipe); +} + +static int modem_backend_fake_transmit(void *data, const uint8_t *buf, size_t size) +{ + struct modem_backend_fake *backend = data; + + backend->transmit_called = true; + backend->transmit_buffer = buf; + backend->transmit_buffer_size = size; + + if (backend->synchronous) { + modem_pipe_notify_transmit_idle(&backend->pipe); + } else { + k_work_schedule(&backend->transmit_idle_dwork, TEST_MODEM_PIPE_NOTIFY_TIMEOUT); + } + + return size; +} + +static int modem_backend_fake_receive(void *data, uint8_t *buf, size_t size) +{ + struct modem_backend_fake *backend = data; + + backend->receive_called = true; + backend->receive_buffer = buf; + backend->receive_buffer_size = size; + return size; +} + +static void modem_backend_fake_closed_handler(struct k_work *item) +{ + struct k_work_delayable *dwork = k_work_delayable_from_work(item); + struct modem_backend_fake *backend = + CONTAINER_OF(dwork, struct modem_backend_fake, closed_dwork); + + modem_pipe_notify_closed(&backend->pipe); +} + +static int modem_backend_fake_close(void *data) +{ + struct modem_backend_fake *backend = data; + + backend->close_called = true; + + if (backend->synchronous) { + modem_pipe_notify_closed(&backend->pipe); + } else { + k_work_schedule(&backend->closed_dwork, TEST_MODEM_PIPE_NOTIFY_TIMEOUT); + } + + return 0; +} + +static struct modem_pipe_api modem_backend_fake_api = { + .open = modem_backend_fake_open, + .transmit = modem_backend_fake_transmit, + .receive = modem_backend_fake_receive, + .close = modem_backend_fake_close, +}; + +static struct modem_pipe *modem_backend_fake_init(struct modem_backend_fake *backend) +{ + k_work_init_delayable(&backend->opened_dwork, + modem_backend_fake_opened_handler); + k_work_init_delayable(&backend->transmit_idle_dwork, + modem_backend_fake_transmit_idle_handler); + k_work_init_delayable(&backend->closed_dwork, + modem_backend_fake_closed_handler); + + modem_pipe_init(&backend->pipe, backend, &modem_backend_fake_api); + return &backend->pipe; +} + +static void modem_backend_fake_reset(struct modem_backend_fake *backend) +{ + backend->transmit_buffer = NULL; + backend->transmit_buffer_size = 0; + backend->receive_buffer = NULL; + backend->transmit_buffer_size = 0; + backend->open_called = false; + backend->transmit_called = false; + backend->receive_called = false; + backend->close_called = false; +} + +static void modem_backend_fake_set_sync(struct modem_backend_fake *backend, bool sync) +{ + backend->synchronous = sync; +} + +/*************************************************************************************************/ +/* Instances */ +/*************************************************************************************************/ +static struct modem_backend_fake test_backend; +static struct modem_pipe *test_pipe; +static uint32_t test_user_data; +static atomic_t test_state; +static uint8_t test_buffer[4]; +static size_t test_buffer_size = sizeof(test_buffer); + +/*************************************************************************************************/ +/* Callbacks */ +/*************************************************************************************************/ +static void modem_pipe_fake_handler(struct modem_pipe *pipe, enum modem_pipe_event event, + void *user_data) +{ + __ASSERT(pipe == test_pipe, "Incorrect pipe provided with callback"); + __ASSERT(user_data == (void *)&test_user_data, "Incorrect user data ptr"); + + switch (event) { + case MODEM_PIPE_EVENT_OPENED: + atomic_set_bit(&test_state, TEST_MODEM_PIPE_EVENT_OPENED_BIT); + break; + + case MODEM_PIPE_EVENT_RECEIVE_READY: + atomic_set_bit(&test_state, TEST_MODEM_PIPE_EVENT_RECEIVE_READY_BIT); + break; + + case MODEM_PIPE_EVENT_TRANSMIT_IDLE: + atomic_set_bit(&test_state, TEST_MODEM_PIPE_EVENT_TRANSMIT_IDLE_BIT); + break; + + case MODEM_PIPE_EVENT_CLOSED: + atomic_set_bit(&test_state, TEST_MODEM_PIPE_EVENT_CLOSED_BIT); + break; + } +} + +static void test_reset(void) +{ + modem_backend_fake_reset(&test_backend); + atomic_set(&test_state, 0); +} + +static void *modem_backend_fake_setup(void) +{ + test_pipe = modem_backend_fake_init(&test_backend); + return NULL; +} + +static void modem_backend_fake_before(void *f) +{ + modem_backend_fake_set_sync(&test_backend, false); + modem_pipe_attach(test_pipe, modem_pipe_fake_handler, &test_user_data); + test_reset(); +} + +static void modem_backend_fake_after(void *f) +{ + __ASSERT(modem_pipe_close(test_pipe) == 0, "Failed to close pipe"); + modem_pipe_release(test_pipe); +} + +/* Opening pipe shall raise events OPENED and TRANSMIT_IDLE */ +static void test_pipe_open(void) +{ + zassert_ok(modem_pipe_open(test_pipe), "Failed to open pipe"); + zassert_true(test_backend.open_called, "open was not called"); + zassert_equal(atomic_get(&test_state), + BIT(TEST_MODEM_PIPE_EVENT_OPENED_BIT) | + BIT(TEST_MODEM_PIPE_EVENT_TRANSMIT_IDLE_BIT), + "Unexpected state %u", atomic_get(&test_state)); +} + +/* Re-opening pipe shall have no effect */ +static void test_pipe_reopen(void) +{ + zassert_ok(modem_pipe_open(test_pipe), "Failed to re-open pipe"); + zassert_false(test_backend.open_called, "open was called"); + zassert_equal(atomic_get(&test_state), 0, + "Unexpected state %u", atomic_get(&test_state)); +} + +/* Closing pipe shall raise event CLOSED */ +static void test_pipe_close(void) +{ + zassert_ok(modem_pipe_close(test_pipe), "Failed to close pipe"); + zassert_true(test_backend.close_called, "close was not called"); + zassert_equal(atomic_get(&test_state), BIT(TEST_MODEM_PIPE_EVENT_CLOSED_BIT), + "Unexpected state %u", atomic_get(&test_state)); +} + +/* Re-closing pipe shall have no effect */ +static void test_pipe_reclose(void) +{ + zassert_ok(modem_pipe_close(test_pipe), "Failed to re-close pipe"); + zassert_false(test_backend.close_called, "close was called"); + zassert_equal(atomic_get(&test_state), 0, + "Unexpected state %u", atomic_get(&test_state)); +} + +static void test_pipe_async_transmit(void) +{ + zassert_equal(modem_pipe_transmit(test_pipe, test_buffer, test_buffer_size), + test_buffer_size, "Failed to transmit"); + zassert_true(test_backend.transmit_called, "transmit was not called"); + zassert_equal(test_backend.transmit_buffer, test_buffer, "Incorrect buffer"); + zassert_equal(test_backend.transmit_buffer_size, test_buffer_size, + "Incorrect buffer size"); + zassert_equal(atomic_get(&test_state), 0, "Unexpected state %u", + atomic_get(&test_state)); + k_sleep(TEST_MODEM_PIPE_WAIT_TIMEOUT); + zassert_equal(atomic_get(&test_state), BIT(TEST_MODEM_PIPE_EVENT_TRANSMIT_IDLE_BIT), + "Unexpected state %u", atomic_get(&test_state)); +} + +static void test_pipe_sync_transmit(void) +{ + zassert_equal(modem_pipe_transmit(test_pipe, test_buffer, test_buffer_size), + test_buffer_size, "Failed to transmit"); + zassert_true(test_backend.transmit_called, "transmit was not called"); + zassert_equal(test_backend.transmit_buffer, test_buffer, "Incorrect buffer"); + zassert_equal(test_backend.transmit_buffer_size, test_buffer_size, + "Incorrect buffer size"); + zassert_equal(atomic_get(&test_state), BIT(TEST_MODEM_PIPE_EVENT_TRANSMIT_IDLE_BIT), + "Unexpected state %u", atomic_get(&test_state)); +} + +static void test_pipe_attach_receive_not_ready_transmit_idle(void) +{ + modem_pipe_attach(test_pipe, modem_pipe_fake_handler, &test_user_data); + zassert_equal(atomic_get(&test_state), BIT(TEST_MODEM_PIPE_EVENT_TRANSMIT_IDLE_BIT), + "Unexpected state %u", atomic_get(&test_state)); +} + +static void test_pipe_attach_receive_ready_transmit_idle(void) +{ + modem_pipe_attach(test_pipe, modem_pipe_fake_handler, &test_user_data); + zassert_equal(atomic_get(&test_state), + BIT(TEST_MODEM_PIPE_EVENT_TRANSMIT_IDLE_BIT) | + BIT(TEST_MODEM_PIPE_EVENT_RECEIVE_READY_BIT), + "Unexpected state %u", atomic_get(&test_state)); +} + +static void test_pipe_receive(void) +{ + zassert_equal(modem_pipe_receive(test_pipe, test_buffer, test_buffer_size), + test_buffer_size, "Failed to receive"); + zassert_true(test_backend.receive_called, "receive was not called"); + zassert_equal(test_backend.receive_buffer, test_buffer, "Incorrect buffer"); + zassert_equal(test_backend.receive_buffer_size, test_buffer_size, + "Incorrect buffer size"); + zassert_equal(atomic_get(&test_state), 0, "Unexpected state %u", + atomic_get(&test_state)); +} + +static void test_pipe_notify_receive_ready(void) +{ + modem_pipe_notify_receive_ready(test_pipe); + zassert_equal(atomic_get(&test_state), BIT(TEST_MODEM_PIPE_EVENT_RECEIVE_READY_BIT), + "Unexpected state %u", atomic_get(&test_state)); +} + +ZTEST(modem_pipe, test_async_open_close) +{ + test_pipe_open(); + test_reset(); + test_pipe_reopen(); + test_reset(); + test_pipe_close(); + test_reset(); + test_pipe_reclose(); +} + +ZTEST(modem_pipe, test_sync_open_close) +{ + modem_backend_fake_set_sync(&test_backend, true); + test_pipe_open(); + test_reset(); + test_pipe_reopen(); + test_reset(); + test_pipe_close(); + test_reset(); + test_pipe_reclose(); +} + +ZTEST(modem_pipe, test_async_transmit) +{ + test_pipe_open(); + test_reset(); + test_pipe_async_transmit(); +} + +ZTEST(modem_pipe, test_sync_transmit) +{ + modem_backend_fake_set_sync(&test_backend, true); + test_pipe_open(); + test_reset(); + test_pipe_sync_transmit(); +} + +ZTEST(modem_pipe, test_attach) +{ + test_pipe_open(); + + /* + * Attaching pipe shall reinvoke TRANSMIT IDLE, but not RECEIVE READY as + * receive is not ready. + */ + test_reset(); + test_pipe_attach_receive_not_ready_transmit_idle(); + + /* + * Notify receive ready and expect receive ready to be re-invoked every + * time the pipe is attached to. + */ + test_reset(); + test_pipe_notify_receive_ready(); + test_reset(); + test_pipe_attach_receive_ready_transmit_idle(); + test_reset(); + test_pipe_attach_receive_ready_transmit_idle(); + + /* + * Receiving data from the pipe shall clear the receive ready state, stopping + * the invocation of receive ready on attach. + */ + test_reset(); + test_pipe_receive(); + test_reset(); + test_pipe_attach_receive_not_ready_transmit_idle(); +} + +ZTEST_SUITE(modem_pipe, NULL, modem_backend_fake_setup, modem_backend_fake_before, + modem_backend_fake_after, NULL); diff --git a/tests/subsys/modem/modem_pipe/testcase.yaml b/tests/subsys/modem/modem_pipe/testcase.yaml new file mode 100644 index 00000000000..39a8c8e6c2c --- /dev/null +++ b/tests/subsys/modem/modem_pipe/testcase.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2023 Trackunit Corporation +# SPDX-License-Identifier: Apache-2.0 + +tests: + modem.modem_pipe: + tags: modem_pipe + harness: ztest + platform_allow: native_sim From 97a72e72ef8021988c21d83e87eb1870d4c814c6 Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Tue, 2 Jan 2024 22:53:57 +0700 Subject: [PATCH 1419/1623] [nrf fromtree] modem: modem_cmux: optimize modem_cmux_transmit_frame to save ROM This optimization aggregates frame headers before adding to the ring buffer and computes the FCS of the frame header in one operation. This approach improves execution efficiency and reduces memory footprint. This code adjustment aligns with the changes proposed in https://github.com/zephyrproject-rtos/zephyr/pull/67062. Signed-off-by: Pisit Sawangvonganan (cherry picked from commit 1270bce4d84b6146aae7ffbe07579aa4a85ebf27) --- subsys/modem/modem_cmux.c | 46 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index 472d1a7149a..dc7c3915566 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -205,57 +205,55 @@ static void modem_cmux_bus_callback(struct modem_pipe *pipe, enum modem_pipe_eve static uint16_t modem_cmux_transmit_frame(struct modem_cmux *cmux, const struct modem_cmux_frame *frame) { - uint8_t byte; + uint8_t buf[MODEM_CMUX_FRAME_SIZE_MAX]; uint8_t fcs; uint16_t space; uint16_t data_len; + uint16_t buf_idx; space = ring_buf_space_get(&cmux->transmit_rb) - MODEM_CMUX_FRAME_SIZE_MAX; data_len = (space < frame->data_len) ? space : frame->data_len; /* SOF */ - byte = 0xF9; - ring_buf_put(&cmux->transmit_rb, &byte, 1); + buf[0] = 0xF9; /* DLCI Address (Max 63) */ - byte = 0x01 | (frame->cr << 1) | (frame->dlci_address << 2); - fcs = crc8(&byte, 1, MODEM_CMUX_FCS_POLYNOMIAL, MODEM_CMUX_FCS_INIT_VALUE, true); - ring_buf_put(&cmux->transmit_rb, &byte, 1); + buf[1] = 0x01 | (frame->cr << 1) | (frame->dlci_address << 2); /* Frame type and poll/final */ - byte = frame->type | (frame->pf << 4); - fcs = crc8(&byte, 1, MODEM_CMUX_FCS_POLYNOMIAL, fcs, true); - ring_buf_put(&cmux->transmit_rb, &byte, 1); + buf[2] = frame->type | (frame->pf << 4); /* Data length */ if (data_len > 127) { - byte = data_len << 1; - fcs = crc8(&byte, 1, MODEM_CMUX_FCS_POLYNOMIAL, fcs, true); - ring_buf_put(&cmux->transmit_rb, &byte, 1); - byte = data_len >> 7; - ring_buf_put(&cmux->transmit_rb, &byte, 1); + buf[3] = data_len << 1; + buf[4] = data_len >> 7; + buf_idx = 5; } else { - byte = 0x01 | (data_len << 1); - ring_buf_put(&cmux->transmit_rb, &byte, 1); + buf[3] = 0x01 | (data_len << 1); + buf_idx = 4; } + /* Compute FCS for the header (exclude SOF) */ + fcs = crc8(&buf[1], (buf_idx - 1), MODEM_CMUX_FCS_POLYNOMIAL, MODEM_CMUX_FCS_INIT_VALUE, + true); + /* FCS final */ if (frame->type == MODEM_CMUX_FRAME_TYPE_UIH) { - fcs = 0xFF - crc8(&byte, 1, MODEM_CMUX_FCS_POLYNOMIAL, fcs, true); + fcs = 0xFF - fcs; } else { - fcs = crc8(&byte, 1, MODEM_CMUX_FCS_POLYNOMIAL, fcs, true); fcs = 0xFF - crc8(frame->data, data_len, MODEM_CMUX_FCS_POLYNOMIAL, fcs, true); } + /* Frame header */ + ring_buf_put(&cmux->transmit_rb, buf, buf_idx); + /* Data */ ring_buf_put(&cmux->transmit_rb, frame->data, data_len); - /* FCS */ - ring_buf_put(&cmux->transmit_rb, &fcs, 1); - - /* EOF */ - byte = 0xF9; - ring_buf_put(&cmux->transmit_rb, &byte, 1); + /* FCS and EOF will be put on the same call */ + buf[0] = fcs; + buf[1] = 0xF9; + ring_buf_put(&cmux->transmit_rb, buf, 2); k_work_schedule(&cmux->transmit_work, K_NO_WAIT); return data_len; } From c183d3ef9694f2cb0ebcfbff8715388004d63d2a Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Thu, 11 Jan 2024 13:12:00 +0100 Subject: [PATCH 1420/1623] [nrf fromtree] modem: chat: Start waiting for response after request is sent This PR makes the modem_chat wait until a chat script chat request has been sent before accepting responses to said request. This helps ensure that an unsolicitet response is not mistaken for a response to a request, which is especially problematic if the chat script chat is using an any match. For example, start chat script sending AT+CGMI, expecting the modem name as a response followed by OK > start script, waiting for response immediately > start sending "AT+CGMI" > receive "+CEREG 1,0" while sending > script accepts "+CEREG 1,0" as the response to "AT+CGMI" > "AT+CGMI" sent > receive "QUECTEL BG95" > receive "OK" script handler got "+CEREG 1,0" instead of "QUECTEL BG95" After this PR: > start script > start sending AT+CGMI > receive "+CEREG 1,0" while sending > "AT+CGMI" sent > start waiting for response > receive "QUECTEL BG95" > script accepts "QUECTEL BG95" as response to "AT+CGMI" > receive "OK" Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 7c9f2872e17d168cf28c6e77dd5fcb71b892c33d) --- subsys/modem/modem_chat.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/subsys/modem/modem_chat.c b/subsys/modem/modem_chat.c index 7cf7692c514..f3857bcfbc3 100644 --- a/subsys/modem/modem_chat.c +++ b/subsys/modem/modem_chat.c @@ -95,8 +95,10 @@ static void modem_chat_script_stop(struct modem_chat *chat, enum modem_chat_scri chat->matches[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = NULL; chat->matches_size[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = 0; - /* Cancel timeout work */ + /* Cancel work */ k_work_cancel_delayable(&chat->script_timeout_work); + k_work_cancel_delayable(&chat->script_send_work); + k_work_cancel_delayable(&chat->script_send_timeout_work); /* Clear script running state */ atomic_clear_bit(&chat->script_state, MODEM_CHAT_SCRIPT_STATE_RUNNING_BIT); @@ -118,6 +120,21 @@ static void modem_chat_script_send(struct modem_chat *chat) k_work_schedule(&chat->script_send_work, K_NO_WAIT); } +static void modem_chat_script_set_response_matches(struct modem_chat *chat) +{ + const struct modem_chat_script_chat *script_chat = + &chat->script->script_chats[chat->script_chat_it]; + + chat->matches[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = script_chat->response_matches; + chat->matches_size[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = script_chat->response_matches_size; +} + +static void modem_chat_script_clear_response_matches(struct modem_chat *chat) +{ + chat->matches[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = NULL; + chat->matches_size[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = 0; +} + static void modem_chat_script_next(struct modem_chat *chat, bool initial) { const struct modem_chat_script_chat *script_chat; @@ -142,14 +159,13 @@ static void modem_chat_script_next(struct modem_chat *chat, bool initial) script_chat = &chat->script->script_chats[chat->script_chat_it]; - /* Set response command handlers */ - chat->matches[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = script_chat->response_matches; - chat->matches_size[MODEM_CHAT_MATCHES_INDEX_RESPONSE] = script_chat->response_matches_size; - - /* Check if work must be sent */ + /* Check if request must be sent */ if (script_chat->request_size > 0) { LOG_DBG("sending: %.*s", script_chat->request_size, script_chat->request); + modem_chat_script_clear_response_matches(chat); modem_chat_script_send(chat); + } else { + modem_chat_script_set_response_matches(chat); } } @@ -322,6 +338,8 @@ static void modem_chat_script_send_handler(struct k_work *item) } else { k_work_schedule(&chat->script_send_timeout_work, K_MSEC(timeout)); } + } else { + modem_chat_script_set_response_matches(chat); } } From 05222f38816ac0e3a195ec04fc05ada95aff3f90 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 12 Jan 2024 11:31:14 +0100 Subject: [PATCH 1421/1623] [nrf fromtree] tests: modem: pipe: mock: Implement TRANSMIT_IDLE event Implements TRANSMIT_IDLE event notification for mock modem_pipe. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 325bc953a89d79ca71b6f8b59ea320bbf78fa656) --- tests/subsys/modem/mock/modem_backend_mock.c | 24 ++++++++++++++------ tests/subsys/modem/mock/modem_backend_mock.h | 10 ++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/subsys/modem/mock/modem_backend_mock.c b/tests/subsys/modem/mock/modem_backend_mock.c index 0a12fc43674..5b7b47c0eb4 100644 --- a/tests/subsys/modem/mock/modem_backend_mock.c +++ b/tests/subsys/modem/mock/modem_backend_mock.c @@ -47,7 +47,8 @@ static int modem_backend_mock_transmit(void *data, const uint8_t *buf, size_t si struct modem_backend_mock *t_mock = mock->bridge; ret = ring_buf_put(&t_mock->rx_rb, buf, size); - k_work_submit(&t_mock->received_work_item.work); + k_work_submit(&t_mock->receive_ready_work); + k_work_submit(&mock->transmit_idle_work); return ret; } @@ -59,6 +60,7 @@ static int modem_backend_mock_transmit(void *data, const uint8_t *buf, size_t si mock->transaction = NULL; } + k_work_submit(&mock->transmit_idle_work); return ret; } @@ -85,14 +87,22 @@ struct modem_pipe_api modem_backend_mock_api = { .close = modem_backend_mock_close, }; -static void modem_backend_mock_received_handler(struct k_work *item) +static void modem_backend_mock_receive_ready_handler(struct k_work *item) { - struct modem_backend_mock_work *mock_work_item = (struct modem_backend_mock_work *)item; - struct modem_backend_mock *mock = mock_work_item->mock; + struct modem_backend_mock *mock = + CONTAINER_OF(item, struct modem_backend_mock, receive_ready_work); modem_pipe_notify_receive_ready(&mock->pipe); } +static void modem_backend_mock_transmit_idle_handler(struct k_work *item) +{ + struct modem_backend_mock *mock = + CONTAINER_OF(item, struct modem_backend_mock, transmit_idle_work); + + modem_pipe_notify_transmit_idle(&mock->pipe); +} + struct modem_pipe *modem_backend_mock_init(struct modem_backend_mock *mock, const struct modem_backend_mock_config *config) { @@ -100,8 +110,8 @@ struct modem_pipe *modem_backend_mock_init(struct modem_backend_mock *mock, ring_buf_init(&mock->rx_rb, config->rx_buf_size, config->rx_buf); ring_buf_init(&mock->tx_rb, config->tx_buf_size, config->tx_buf); - mock->received_work_item.mock = mock; - k_work_init(&mock->received_work_item.work, modem_backend_mock_received_handler); + k_work_init(&mock->receive_ready_work, modem_backend_mock_receive_ready_handler); + k_work_init(&mock->transmit_idle_work, modem_backend_mock_transmit_idle_handler); mock->limit = config->limit; modem_pipe_init(&mock->pipe, mock, &modem_backend_mock_api); return &mock->pipe; @@ -130,7 +140,7 @@ void modem_backend_mock_put(struct modem_backend_mock *mock, const uint8_t *buf, __ASSERT(ring_buf_put(&mock->rx_rb, buf, size) == size, "Mock buffer capacity exceeded"); - k_work_submit(&mock->received_work_item.work); + k_work_submit(&mock->receive_ready_work); } void modem_backend_mock_prime(struct modem_backend_mock *mock, diff --git a/tests/subsys/modem/mock/modem_backend_mock.h b/tests/subsys/modem/mock/modem_backend_mock.h index 7d9ad11bf41..56a5b585cb1 100644 --- a/tests/subsys/modem/mock/modem_backend_mock.h +++ b/tests/subsys/modem/mock/modem_backend_mock.h @@ -11,13 +11,6 @@ #ifndef ZEPHYR_DRIVERS_MODEM_MODEM_PIPE_MOCK #define ZEPHYR_DRIVERS_MODEM_MODEM_PIPE_MOCK -struct modem_backend_mock; - -struct modem_backend_mock_work { - struct k_work work; - struct modem_backend_mock *mock; -}; - struct modem_backend_mock_transaction { /* Get data which will trigger put */ const uint8_t *get; @@ -34,7 +27,8 @@ struct modem_backend_mock { struct ring_buf rx_rb; struct ring_buf tx_rb; - struct modem_backend_mock_work received_work_item; + struct k_work receive_ready_work; + struct k_work transmit_idle_work; const struct modem_backend_mock_transaction *transaction; size_t transaction_match_cnt; From 30e3637d54852f2c31db5374167db25380653030 Mon Sep 17 00:00:00 2001 From: Emil Lindqvist Date: Thu, 4 Jan 2024 10:21:07 +0100 Subject: [PATCH 1422/1623] [nrf fromtree] modem_cellular: add RSRP & RSRQ to U-blox SARA-R5 modem This commit implements parsing of the CESQ extended signal quality AT command, extracting RSRP and RSRQ which is relevant for LTE connections. It's used in the U-blox SARA-R5 modem instance. Furthermore, the IMEI, IMSI is extracted in the same modem. Signed-off-by: Emil Lindqvist (cherry picked from commit 342e10b0b80504c3b119e36994be2ea0659e9326) --- drivers/modem/modem_cellular.c | 78 +++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 6 deletions(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index 16530edde6c..d1f3a69c94e 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -33,6 +33,16 @@ LOG_MODULE_REGISTER(modem_cellular, CONFIG_MODEM_LOG_LEVEL); #define MODEM_CELLULAR_DATA_MANUFACTURER_LEN (64) #define MODEM_CELLULAR_DATA_FW_VERSION_LEN (64) +/* Magic constants */ +#define CSQ_RSSI_UNKNOWN (99) +#define CESQ_RSRP_UNKNOWN (255) +#define CESQ_RSRQ_UNKNOWN (255) + +/* Magic numbers to units conversions */ +#define CSQ_RSSI_TO_DB(v) (-113 + (2 * (rssi))) +#define CESQ_RSRP_TO_DB(v) (-140 + (v)) +#define CESQ_RSRQ_TO_DB(v) (-20 + ((v) / 2)) + enum modem_cellular_state { MODEM_CELLULAR_STATE_IDLE = 0, MODEM_CELLULAR_STATE_RESET_PULSE, @@ -95,6 +105,8 @@ struct modem_cellular_data { uint8_t registration_status_gprs; uint8_t registration_status_lte; uint8_t rssi; + uint8_t rsrp; + uint8_t rsrq; uint8_t imei[MODEM_CELLULAR_DATA_IMEI_LEN]; uint8_t model_id[MODEM_CELLULAR_DATA_MODEL_ID_LEN]; uint8_t imsi[MODEM_CELLULAR_DATA_IMSI_LEN]; @@ -340,6 +352,19 @@ static void modem_cellular_chat_on_csq(struct modem_chat *chat, char **argv, uin data->rssi = (uint8_t)atoi(argv[1]); } +static void modem_cellular_chat_on_cesq(struct modem_chat *chat, char **argv, uint16_t argc, + void *user_data) +{ + struct modem_cellular_data *data = (struct modem_cellular_data *)user_data; + + if (argc != 7) { + return; + } + + data->rsrq = (uint8_t)atoi(argv[5]); + data->rsrp = (uint8_t)atoi(argv[6]); +} + static void modem_cellular_chat_on_imsi(struct modem_chat *chat, char **argv, uint16_t argc, void *user_data) { @@ -398,6 +423,7 @@ MODEM_CHAT_MATCHES_DEFINE(allow_match, MODEM_CHAT_MATCH_DEFINE(imei_match, "", "", modem_cellular_chat_on_imei); MODEM_CHAT_MATCH_DEFINE(cgmm_match, "", "", modem_cellular_chat_on_cgmm); MODEM_CHAT_MATCH_DEFINE(csq_match, "+CSQ: ", ",", modem_cellular_chat_on_csq); +MODEM_CHAT_MATCH_DEFINE(cesq_match, "+CESQ: ", ",", modem_cellular_chat_on_cesq); MODEM_CHAT_MATCH_DEFINE(cimi_match, "", "", modem_cellular_chat_on_imsi); MODEM_CHAT_MATCH_DEFINE(cgmi_match, "", "", modem_cellular_chat_on_cgmi); MODEM_CHAT_MATCH_DEFINE(cgmr_match, "", "", modem_cellular_chat_on_cgmr); @@ -1253,11 +1279,44 @@ static inline int modem_cellular_csq_parse_rssi(uint8_t rssi, int16_t *value) * - ber is an integer from 0 to 7 that describes the error rate, it can also * be 99 for an unknown error rate */ - if (rssi == 99) { + if (rssi == CSQ_RSSI_UNKNOWN) { + return -EINVAL; + } + + *value = (int16_t)CSQ_RSSI_TO_DB(rssi); + return 0; +} + +MODEM_CHAT_SCRIPT_CMDS_DEFINE(get_signal_cesq_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CESQ", cesq_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match)); + +MODEM_CHAT_SCRIPT_DEFINE(get_signal_cesq_chat_script, get_signal_cesq_chat_script_cmds, + abort_matches, modem_cellular_chat_callback_handler, 2); + +/* AT+CESQ returns a response +CESQ: ,,,,, where: + * - rsrq is a integer from 0 to 34 whose values describes the Reference Signal Receive + * Quality between -20 dB for 0 and -3 dB for 34 (0.5 dB steps), or unknown for 255 + * - rsrp is an integer from 0 to 97 that describes the Reference Signal Receive Power + * between -140 dBm for 0 and -44 dBm for 97 (1 dBm steps), or unknown for 255 + */ +static inline int modem_cellular_cesq_parse_rsrp(uint8_t rsrp, int16_t *value) +{ + if (rsrp == CESQ_RSRP_UNKNOWN) { + return -EINVAL; + } + + *value = (int16_t)CESQ_RSRP_TO_DB(rsrp); + return 0; +} + +static inline int modem_cellular_cesq_parse_rsrq(uint8_t rsrq, int16_t *value) +{ + if (rsrq == CESQ_RSRQ_UNKNOWN) { return -EINVAL; } - *value = (int16_t)(-113 + (2 * rssi)); + *value = (int16_t)CESQ_RSRQ_TO_DB(rsrq); return 0; } @@ -1281,8 +1340,7 @@ static int modem_cellular_get_signal(const struct device *dev, case CELLULAR_SIGNAL_RSRP: case CELLULAR_SIGNAL_RSRQ: - /* TODO: Run CESQ script */ - ret = -ENOTSUP; + ret = modem_chat_run_script(&data->chat, &get_signal_cesq_chat_script); break; default: @@ -1302,9 +1360,11 @@ static int modem_cellular_get_signal(const struct device *dev, break; case CELLULAR_SIGNAL_RSRP: + ret = modem_cellular_cesq_parse_rsrp(data->rsrp, value); + break; + case CELLULAR_SIGNAL_RSRQ: - /* TODO: Validate and set values */ - ret = -ENODATA; + ret = modem_cellular_cesq_parse_rsrq(data->rsrq, value); break; default: @@ -1744,6 +1804,12 @@ MODEM_CHAT_SCRIPT_CMDS_DEFINE(u_blox_sara_r5_init_chat_script_cmds, MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMM", cgmm_match), MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMI", cgmi_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMR", cgmr_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CIMI", cimi_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), MODEM_CHAT_SCRIPT_CMD_RESP("AT+CMUX=0,0,5,127", ok_match)); MODEM_CHAT_SCRIPT_DEFINE(u_blox_sara_r5_init_chat_script, u_blox_sara_r5_init_chat_script_cmds, From 54f90a7c27056211eb1e1e2730e0fb03f16728d0 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 24 Nov 2023 14:47:59 +0100 Subject: [PATCH 1423/1623] [nrf fromtree] modem: cmux: Implement TRANSMIT_IDLE event Implement transmit idle event both for transmitting data to the bus, and for the individual DLCI channels. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit c1146278536ccf135695004b24eb8242add74b75) --- subsys/modem/modem_cmux.c | 58 ++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index dc7c3915566..13a153b8533 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -197,8 +197,17 @@ static void modem_cmux_bus_callback(struct modem_pipe *pipe, enum modem_pipe_eve { struct modem_cmux *cmux = (struct modem_cmux *)user_data; - if (event == MODEM_PIPE_EVENT_RECEIVE_READY) { + switch (event) { + case MODEM_PIPE_EVENT_RECEIVE_READY: k_work_schedule(&cmux->receive_work, K_NO_WAIT); + break; + + case MODEM_PIPE_EVENT_TRANSMIT_IDLE: + k_work_schedule(&cmux->transmit_work, K_NO_WAIT); + break; + + default: + break; } } @@ -833,6 +842,17 @@ static void modem_cmux_receive_handler(struct k_work *item) k_work_schedule(&cmux->receive_work, K_NO_WAIT); } +static void modem_cmux_dlci_notify_transmit_idle(struct modem_cmux *cmux) +{ + sys_snode_t *node; + struct modem_cmux_dlci *dlci; + + SYS_SLIST_FOR_EACH_NODE(&cmux->dlcis, node) { + dlci = (struct modem_cmux_dlci *)node; + modem_pipe_notify_transmit_idle(&dlci->pipe); + } +} + static void modem_cmux_transmit_handler(struct k_work *item) { struct k_work_delayable *dwork = k_work_delayable_from_work(item); @@ -840,31 +860,37 @@ static void modem_cmux_transmit_handler(struct k_work *item) uint8_t *reserved; uint32_t reserved_size; int ret; + bool transmit_rb_empty; k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER); - /* Reserve data to transmit from transmit ring buffer */ - reserved_size = ring_buf_get_claim(&cmux->transmit_rb, &reserved, UINT32_MAX); + while (true) { + transmit_rb_empty = ring_buf_is_empty(&cmux->transmit_rb); - /* Transmit reserved data */ - ret = modem_pipe_transmit(cmux->pipe, reserved, reserved_size); - if (ret < 1) { - ring_buf_get_finish(&cmux->transmit_rb, 0); - k_mutex_unlock(&cmux->transmit_rb_lock); - k_work_schedule(&cmux->transmit_work, K_NO_WAIT); + if (transmit_rb_empty) { + break; + } - return; - } + reserved_size = ring_buf_get_claim(&cmux->transmit_rb, &reserved, UINT32_MAX); - /* Release remaining reserved data */ - ring_buf_get_finish(&cmux->transmit_rb, ret); + ret = modem_pipe_transmit(cmux->pipe, reserved, reserved_size); + if (ret < 0) { + ring_buf_get_finish(&cmux->transmit_rb, 0); + break; + } - /* Resubmit transmit work if data remains */ - if (ring_buf_is_empty(&cmux->transmit_rb) == false) { - k_work_schedule(&cmux->transmit_work, K_NO_WAIT); + ring_buf_get_finish(&cmux->transmit_rb, (uint32_t)ret); + + if (ret == 0) { + break; + } } k_mutex_unlock(&cmux->transmit_rb_lock); + + if (transmit_rb_empty) { + modem_cmux_dlci_notify_transmit_idle(cmux); + } } static void modem_cmux_connect_handler(struct k_work *item) From 914e33b692d891ba3197602195a4ddf259168f63 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 24 Nov 2023 16:09:40 +0100 Subject: [PATCH 1424/1623] [nrf fromtree] tests: modem: cmux: Implement TRANSMIT_IDLE into test suite Use transmit idle event to synchronize with data transmitted through DLCI pipes to test TRANSMIT_IDLE implementation. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 358f1ff93404d081b8f07c9faacb81097ce09346) --- subsys/modem/modem_cmux.c | 2 +- tests/subsys/modem/modem_cmux/src/main.c | 61 ++++++++++++++++++++---- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index 13a153b8533..16dc60b7219 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -881,7 +881,7 @@ static void modem_cmux_transmit_handler(struct k_work *item) ring_buf_get_finish(&cmux->transmit_rb, (uint32_t)ret); - if (ret == 0) { + if (ret < reserved_size) { break; } } diff --git a/tests/subsys/modem/modem_cmux/src/main.c b/tests/subsys/modem/modem_cmux/src/main.c index d601eeb1446..b08cf26b5af 100644 --- a/tests/subsys/modem/modem_cmux/src/main.c +++ b/tests/subsys/modem/modem_cmux/src/main.c @@ -17,12 +17,16 @@ /*************************************************************************************************/ /* Definitions */ /*************************************************************************************************/ -#define EVENT_CMUX_CONNECTED BIT(0) -#define EVENT_CMUX_DLCI1_OPEN BIT(1) -#define EVENT_CMUX_DLCI2_OPEN BIT(2) -#define EVENT_CMUX_DLCI1_CLOSED BIT(3) -#define EVENT_CMUX_DLCI2_CLOSED BIT(4) -#define EVENT_CMUX_DISCONNECTED BIT(5) +#define EVENT_CMUX_CONNECTED BIT(0) +#define EVENT_CMUX_DLCI1_OPEN BIT(1) +#define EVENT_CMUX_DLCI2_OPEN BIT(2) +#define EVENT_CMUX_DLCI1_RECEIVE_READY BIT(3) +#define EVENT_CMUX_DLCI1_TRANSMIT_IDLE BIT(4) +#define EVENT_CMUX_DLCI2_RECEIVE_READY BIT(5) +#define EVENT_CMUX_DLCI2_TRANSMIT_IDLE BIT(6) +#define EVENT_CMUX_DLCI1_CLOSED BIT(7) +#define EVENT_CMUX_DLCI2_CLOSED BIT(8) +#define EVENT_CMUX_DISCONNECTED BIT(9) /*************************************************************************************************/ /* Instances */ @@ -59,6 +63,14 @@ static void test_modem_dlci1_pipe_callback(struct modem_pipe *pipe, enum modem_p k_event_post(&cmux_event, EVENT_CMUX_DLCI1_OPEN); break; + case MODEM_PIPE_EVENT_RECEIVE_READY: + k_event_post(&cmux_event, EVENT_CMUX_DLCI1_RECEIVE_READY); + break; + + case MODEM_PIPE_EVENT_TRANSMIT_IDLE: + k_event_post(&cmux_event, EVENT_CMUX_DLCI1_TRANSMIT_IDLE); + break; + case MODEM_PIPE_EVENT_CLOSED: k_event_post(&cmux_event, EVENT_CMUX_DLCI1_CLOSED); break; @@ -76,6 +88,14 @@ static void test_modem_dlci2_pipe_callback(struct modem_pipe *pipe, enum modem_p k_event_post(&cmux_event, EVENT_CMUX_DLCI2_OPEN); break; + case MODEM_PIPE_EVENT_RECEIVE_READY: + k_event_post(&cmux_event, EVENT_CMUX_DLCI2_RECEIVE_READY); + break; + + case MODEM_PIPE_EVENT_TRANSMIT_IDLE: + k_event_post(&cmux_event, EVENT_CMUX_DLCI2_TRANSMIT_IDLE); + break; + case MODEM_PIPE_EVENT_CLOSED: k_event_post(&cmux_event, EVENT_CMUX_DLCI2_CLOSED); break; @@ -300,6 +320,7 @@ static void test_modem_cmux_before(void *f) ZTEST(modem_cmux, test_modem_cmux_receive_dlci2_at) { int ret; + uint32_t events; modem_backend_mock_put(&bus_mock, cmux_frame_dlci2_at_cgdcont, sizeof(cmux_frame_dlci2_at_cgdcont)); @@ -309,6 +330,10 @@ ZTEST(modem_cmux, test_modem_cmux_receive_dlci2_at) k_msleep(100); + events = k_event_test(&cmux_event, EVENT_CMUX_DLCI2_RECEIVE_READY); + zassert_equal(events, EVENT_CMUX_DLCI2_RECEIVE_READY, + "Receive ready event not received for DLCI2 pipe"); + ret = modem_pipe_receive(dlci2_pipe, buffer2, sizeof(buffer2)); zassert_true(ret == (sizeof(cmux_frame_data_dlci2_at_cgdcont) + sizeof(cmux_frame_data_dlci2_at_newline)), @@ -327,6 +352,7 @@ ZTEST(modem_cmux, test_modem_cmux_receive_dlci2_at) ZTEST(modem_cmux, test_modem_cmux_receive_dlci1_at) { int ret; + uint32_t events; modem_backend_mock_put(&bus_mock, cmux_frame_dlci1_at_at, sizeof(cmux_frame_dlci1_at_at)); modem_backend_mock_put(&bus_mock, cmux_frame_dlci1_at_newline, @@ -334,6 +360,10 @@ ZTEST(modem_cmux, test_modem_cmux_receive_dlci1_at) k_msleep(100); + events = k_event_test(&cmux_event, EVENT_CMUX_DLCI1_RECEIVE_READY); + zassert_equal(events, EVENT_CMUX_DLCI1_RECEIVE_READY, + "Receive ready event not received for DLCI1 pipe"); + ret = modem_pipe_receive(dlci1_pipe, buffer1, sizeof(buffer1)); zassert_true(ret == (sizeof(cmux_frame_data_dlci1_at_at) + sizeof(cmux_frame_data_dlci1_at_newline)), @@ -352,12 +382,17 @@ ZTEST(modem_cmux, test_modem_cmux_receive_dlci1_at) ZTEST(modem_cmux, test_modem_cmux_receive_dlci2_ppp) { int ret; + uint32_t events; modem_backend_mock_put(&bus_mock, cmux_frame_dlci2_ppp_52, sizeof(cmux_frame_dlci2_ppp_52)); modem_backend_mock_put(&bus_mock, cmux_frame_dlci2_ppp_18, sizeof(cmux_frame_dlci2_ppp_18)); k_msleep(100); + events = k_event_test(&cmux_event, EVENT_CMUX_DLCI2_RECEIVE_READY); + zassert_equal(events, EVENT_CMUX_DLCI2_RECEIVE_READY, + "Receive ready event not received for DLCI2 pipe"); + ret = modem_pipe_receive(dlci2_pipe, buffer2, sizeof(buffer2)); zassert_true(ret == (sizeof(cmux_frame_data_dlci2_ppp_52) + sizeof(cmux_frame_data_dlci2_ppp_18)), @@ -376,17 +411,25 @@ ZTEST(modem_cmux, test_modem_cmux_receive_dlci2_ppp) ZTEST(modem_cmux, test_modem_cmux_transmit_dlci2_ppp) { int ret; + uint32_t events; ret = modem_pipe_transmit(dlci2_pipe, cmux_frame_data_dlci2_ppp_52, sizeof(cmux_frame_data_dlci2_ppp_52)); - zassert_true(ret == sizeof(cmux_frame_data_dlci2_ppp_52), "Failed to send DLCI2 PPP 52"); + + events = k_event_wait(&cmux_event, EVENT_CMUX_DLCI2_TRANSMIT_IDLE, false, K_MSEC(200)); + zassert_equal(events, EVENT_CMUX_DLCI2_TRANSMIT_IDLE, + "Transmit idle event not received for DLCI2 pipe"); + + k_event_clear(&cmux_event, EVENT_CMUX_DLCI2_TRANSMIT_IDLE); + ret = modem_pipe_transmit(dlci2_pipe, cmux_frame_data_dlci2_ppp_18, sizeof(cmux_frame_data_dlci2_ppp_18)); - zassert_true(ret == sizeof(cmux_frame_data_dlci2_ppp_18), "Failed to send DLCI2 PPP 18"); - k_msleep(100); + events = k_event_wait(&cmux_event, EVENT_CMUX_DLCI2_TRANSMIT_IDLE, false, K_MSEC(200)); + zassert_equal(events, EVENT_CMUX_DLCI2_TRANSMIT_IDLE, + "Transmit idle event not received for DLCI2 pipe"); ret = modem_backend_mock_get(&bus_mock, buffer2, sizeof(buffer2)); zassert_true(ret == (sizeof(cmux_frame_dlci2_ppp_52) + sizeof(cmux_frame_dlci2_ppp_18)), From 9a1cd2cbbb47f17fb4be8cfba87b7758029ee5c6 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Tue, 16 Jan 2024 14:37:01 +0100 Subject: [PATCH 1425/1623] [nrf fromtree] drivers: gnss: match: Change RMC/GGA sync from timeout to UTC Change the synchronization of RMC and GGA NMEA messages from a timeout to matching their UTC timestamps. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 1bc8490c6ccb67391ddd28c8fd3a569b859bd7e5) --- drivers/gnss/gnss_nmea0183_match.c | 58 ++++++++++++------------ drivers/gnss/gnss_nmea0183_match.h | 10 ++-- drivers/gnss/gnss_nmea_generic.c | 4 -- drivers/gnss/gnss_quectel_lcx6g.c | 1 - dts/bindings/gnss/gnss-nmea-generic.yaml | 10 ---- 5 files changed, 31 insertions(+), 52 deletions(-) diff --git a/drivers/gnss/gnss_nmea0183_match.c b/drivers/gnss/gnss_nmea0183_match.c index 2b971937c8d..cd82c552ee4 100644 --- a/drivers/gnss/gnss_nmea0183_match.c +++ b/drivers/gnss/gnss_nmea0183_match.c @@ -10,16 +10,22 @@ #include +#include "gnss_parse.h" #include "gnss_nmea0183.h" #include "gnss_nmea0183_match.h" -static bool gnss_nmea0183_match_timed_out(struct gnss_nmea0183_match_data *data) +static int gnss_nmea0183_match_parse_utc(char **argv, uint16_t argc, uint32_t *utc) { - int64_t delta; + int64_t i64; - delta = k_uptime_delta(&data->timestamp); - data->timestamp = k_uptime_get(); - return ((uint16_t)delta) > data->timeout_ms; + if ((gnss_parse_dec_to_milli(argv[1], &i64) < 0) || + (i64 < 0) || + (i64 > UINT32_MAX)) { + return -EINVAL; + } + + *utc = (uint32_t)i64; + return 0; } #if CONFIG_GNSS_SATELLITES @@ -30,10 +36,15 @@ static void gnss_nmea0183_match_reset_gsv(struct gnss_nmea0183_match_data *data) } #endif -static void gnss_nmea0183_match_reset(struct gnss_nmea0183_match_data *data) +static void gnss_nmea0183_match_publish(struct gnss_nmea0183_match_data *data) { - data->gga_received = false; - data->rmc_received = false; + if ((data->gga_utc == 0) || (data->rmc_utc == 0)) { + return; + } + + if (data->gga_utc == data->rmc_utc) { + gnss_publish_data(data->gnss, &data->data); + } } void gnss_nmea0183_match_gga_callback(struct modem_chat *chat, char **argv, uint16_t argc, @@ -41,19 +52,15 @@ void gnss_nmea0183_match_gga_callback(struct modem_chat *chat, char **argv, uint { struct gnss_nmea0183_match_data *data = user_data; - if (gnss_nmea0183_match_timed_out(data)) { - gnss_nmea0183_match_reset(data); - } - if (gnss_nmea0183_parse_gga((const char **)argv, argc, &data->data) < 0) { return; } - data->gga_received = true; - - if (data->gga_received && data->rmc_received) { - gnss_publish_data(data->gnss, &data->data); + if (gnss_nmea0183_match_parse_utc(argv, argc, &data->gga_utc) < 0) { + return; } + + gnss_nmea0183_match_publish(data); } void gnss_nmea0183_match_rmc_callback(struct modem_chat *chat, char **argv, uint16_t argc, @@ -61,19 +68,15 @@ void gnss_nmea0183_match_rmc_callback(struct modem_chat *chat, char **argv, uint { struct gnss_nmea0183_match_data *data = user_data; - if (gnss_nmea0183_match_timed_out(data)) { - gnss_nmea0183_match_reset(data); - } - if (gnss_nmea0183_parse_rmc((const char **)argv, argc, &data->data) < 0) { return; } - data->rmc_received = true; - - if (data->gga_received && data->rmc_received) { - gnss_publish_data(data->gnss, &data->data); + if (gnss_nmea0183_match_parse_utc(argv, argc, &data->rmc_utc) < 0) { + return; } + + gnss_nmea0183_match_publish(data); } #if CONFIG_GNSS_SATELLITES @@ -84,10 +87,6 @@ void gnss_nmea0183_match_gsv_callback(struct modem_chat *chat, char **argv, uint struct gnss_nmea0183_gsv_header header; int ret; - if (gnss_nmea0183_match_timed_out(data)) { - gnss_nmea0183_match_reset(data); - } - if (gnss_nmea0183_parse_gsv_header((const char **)argv, argc, &header) < 0) { return; } @@ -124,7 +123,7 @@ int gnss_nmea0183_match_init(struct gnss_nmea0183_match_data *data, const struct gnss_nmea0183_match_config *config) { __ASSERT(data != NULL, "data argument must be provided"); - __ASSERT(config != NULL, "data argument must be provided"); + __ASSERT(config != NULL, "config argument must be provided"); memset(data, 0, sizeof(struct gnss_nmea0183_match_data)); data->gnss = config->gnss; @@ -132,6 +131,5 @@ int gnss_nmea0183_match_init(struct gnss_nmea0183_match_data *data, data->satellites = config->satellites; data->satellites_size = config->satellites_size; #endif - data->timeout_ms = config->timeout_ms; return 0; } diff --git a/drivers/gnss/gnss_nmea0183_match.h b/drivers/gnss/gnss_nmea0183_match.h index 65104e1dc8a..28ed395320b 100644 --- a/drivers/gnss/gnss_nmea0183_match.h +++ b/drivers/gnss/gnss_nmea0183_match.h @@ -49,11 +49,9 @@ struct gnss_nmea0183_match_data { uint16_t satellites_size; uint16_t satellites_length; #endif - int64_t timestamp; - uint16_t timeout_ms; - uint8_t gga_received : 1; - uint8_t rmc_received : 1; - uint8_t gsv_message_number : 6; + uint32_t gga_utc; + uint32_t rmc_utc; + uint8_t gsv_message_number; }; /** GNSS NMEA0183 match configuration structure */ @@ -66,8 +64,6 @@ struct gnss_nmea0183_match_config { /** Number of elements in buffer for parsed satellites */ uint16_t satellites_size; #endif - /** The maximum time from the first to the last NMEA0183 message of a fix */ - uint16_t timeout_ms; }; /** diff --git a/drivers/gnss/gnss_nmea_generic.c b/drivers/gnss/gnss_nmea_generic.c index 0e7611ba495..6d9adfb6990 100644 --- a/drivers/gnss/gnss_nmea_generic.c +++ b/drivers/gnss/gnss_nmea_generic.c @@ -29,7 +29,6 @@ LOG_MODULE_REGISTER(gnss_nmea_generic, CONFIG_GNSS_LOG_LEVEL); struct gnss_nmea_generic_config { const struct device *uart; - uint16_t nmea_timeout_ms; }; struct gnss_nmea_generic_data { @@ -83,7 +82,6 @@ static struct gnss_driver_api gnss_api = { static int gnss_nmea_generic_init_nmea0183_match(const struct device *dev) { - const struct gnss_nmea_generic_config *cfg = dev->config; struct gnss_nmea_generic_data *data = dev->data; const struct gnss_nmea0183_match_config match_config = { @@ -92,7 +90,6 @@ static int gnss_nmea_generic_init_nmea0183_match(const struct device *dev) .satellites = data->satellites, .satellites_size = ARRAY_SIZE(data->satellites), #endif - .timeout_ms = cfg->nmea_timeout_ms, }; return gnss_nmea0183_match_init(&data->match_data, &match_config); @@ -163,7 +160,6 @@ static int gnss_nmea_generic_init(const struct device *dev) #define GNSS_NMEA_GENERIC(inst) \ static struct gnss_nmea_generic_config gnss_nmea_generic_cfg_##inst = { \ .uart = DEVICE_DT_GET(DT_INST_BUS(inst)), \ - .nmea_timeout_ms = DT_INST_PROP(inst, nmea_timeout_ms), \ }; \ \ static struct gnss_nmea_generic_data gnss_nmea_generic_data_##inst; \ diff --git a/drivers/gnss/gnss_quectel_lcx6g.c b/drivers/gnss/gnss_quectel_lcx6g.c index 9565d46cdfb..f7b29b4640d 100644 --- a/drivers/gnss/gnss_quectel_lcx6g.c +++ b/drivers/gnss/gnss_quectel_lcx6g.c @@ -649,7 +649,6 @@ static int quectel_lcx6g_init_nmea0183_match(const struct device *dev) .satellites = data->satellites, .satellites_size = ARRAY_SIZE(data->satellites), #endif - .timeout_ms = 50, }; return gnss_nmea0183_match_init(&data->match_data, &config); diff --git a/dts/bindings/gnss/gnss-nmea-generic.yaml b/dts/bindings/gnss/gnss-nmea-generic.yaml index 4be7bde1186..a3887995e10 100644 --- a/dts/bindings/gnss/gnss-nmea-generic.yaml +++ b/dts/bindings/gnss/gnss-nmea-generic.yaml @@ -20,13 +20,3 @@ compatible: "gnss-nmea-generic" include: - uart-device.yaml - -properties: - nmea-timeout-ms: - type: int - default: 500 - description: | - Synchronization timeout for NMEA sentences. The NMEA parser is expecting - to receive a GGA and RMC sentences within this time frame to publish a - location data. Set accordingly to the UART datarate and location - reporting frequency. Defaults to 500ms if unspecified. From 985a4fb0b68c38fe4d5e0470ac43e6dacb57c5fb Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 27 Nov 2023 15:09:01 +0100 Subject: [PATCH 1426/1623] [nrf fromtree] modem: ppp: Implement TRANSMIT_IDLE event Implement TRANSMIT_IDLE event for modem_ppp module. This addition optimizes the sys workque CPU time when performing a throughput test from 36% to 5%, while only reducing the throughput by 12%. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit a9779eca400e67e2eebfc1f774eb4186efdc7a96) --- subsys/modem/modem_ppp.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/subsys/modem/modem_ppp.c b/subsys/modem/modem_ppp.c index 476926f4db3..1d47542f24a 100644 --- a/subsys/modem/modem_ppp.c +++ b/subsys/modem/modem_ppp.c @@ -314,8 +314,17 @@ static void modem_ppp_pipe_callback(struct modem_pipe *pipe, enum modem_pipe_eve { struct modem_ppp *ppp = (struct modem_ppp *)user_data; - if (event == MODEM_PIPE_EVENT_RECEIVE_READY) { + switch (event) { + case MODEM_PIPE_EVENT_RECEIVE_READY: k_work_submit(&ppp->process_work); + break; + + case MODEM_PIPE_EVENT_TRANSMIT_IDLE: + k_work_submit(&ppp->send_work); + break; + + default: + break; } } @@ -351,22 +360,20 @@ static void modem_ppp_send_handler(struct k_work *item) } } - reserved_size = ring_buf_get_claim(&ppp->transmit_rb, &reserved, UINT32_MAX); - if (reserved_size == 0) { - ring_buf_get_finish(&ppp->transmit_rb, 0); - return; - } + while (!ring_buf_is_empty(&ppp->transmit_rb)) { + reserved_size = ring_buf_get_claim(&ppp->transmit_rb, &reserved, UINT32_MAX); + + ret = modem_pipe_transmit(ppp->pipe, reserved, reserved_size); + if (ret < 0) { + ring_buf_get_finish(&ppp->transmit_rb, 0); + break; + } - ret = modem_pipe_transmit(ppp->pipe, reserved, reserved_size); - if (ret < 0) { - ring_buf_get_finish(&ppp->transmit_rb, 0); - } else { ring_buf_get_finish(&ppp->transmit_rb, (uint32_t)ret); - } - /* Resubmit send work if data remains */ - if ((ring_buf_is_empty(&ppp->transmit_rb) == false) || (ppp->tx_pkt != NULL)) { - k_work_submit(&ppp->send_work); + if (ret < reserved_size) { + break; + } } } From 8b904adc1559cd5a166d9cf04cd024a5b68cf6e9 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 19 Jan 2024 09:03:26 +0100 Subject: [PATCH 1427/1623] [nrf fromtree] tests: build_all: modem: Remove net tag and clean up Remove the net tag, allowing the modem driver tests to be built for PRs, and limit the scope of the test suite to only build for select emulated 32 and 64 bit boards. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 140a510030ef5cfc1feca9fc44249a2d2373cc01) --- .../build_all/modem/modem_cellular.conf | 6 +- .../drivers/build_all/modem/modem_esp_at.conf | 5 +- tests/drivers/build_all/modem/modem_gsm.conf | 5 +- .../build_all/modem/modem_gsm_mux.conf | 11 ++ .../modem/{modem.conf => modem_hl7800.conf} | 6 +- .../build_all/modem/modem_quectel_bg9x.conf | 6 +- .../build_all/modem/modem_simcom_sim7080.conf | 7 +- .../build_all/modem/modem_ublox_sara.conf | 6 +- tests/drivers/build_all/modem/prj.conf | 3 - tests/drivers/build_all/modem/testcase.yaml | 137 ++++++++---------- 10 files changed, 88 insertions(+), 104 deletions(-) create mode 100644 tests/drivers/build_all/modem/modem_gsm_mux.conf rename tests/drivers/build_all/modem/{modem.conf => modem_hl7800.conf} (79%) delete mode 100644 tests/drivers/build_all/modem/prj.conf diff --git a/tests/drivers/build_all/modem/modem_cellular.conf b/tests/drivers/build_all/modem/modem_cellular.conf index 3366fcf32d4..4582216f772 100644 --- a/tests/drivers/build_all/modem/modem_cellular.conf +++ b/tests/drivers/build_all/modem/modem_cellular.conf @@ -1,10 +1,8 @@ -CONFIG_TEST=y -CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_GPIO=y CONFIG_SERIAL=y +CONFIG_MODEM=y CONFIG_NETWORKING=y CONFIG_NET_L2_PPP=y -CONFIG_MODEM=y CONFIG_PM_DEVICE=y CONFIG_MODEM_CELLULAR=y CONFIG_UART_ASYNC_API=y -CONFIG_GPIO=y diff --git a/tests/drivers/build_all/modem/modem_esp_at.conf b/tests/drivers/build_all/modem/modem_esp_at.conf index 01d4b62ba50..6ba79c82653 100644 --- a/tests/drivers/build_all/modem/modem_esp_at.conf +++ b/tests/drivers/build_all/modem/modem_esp_at.conf @@ -1,7 +1,6 @@ -CONFIG_TEST=y -CONFIG_TEST_RANDOM_GENERATOR=y -CONFIG_SERIAL=y CONFIG_GPIO=y +CONFIG_SERIAL=y +CONFIG_MODEM=y CONFIG_NETWORKING=y CONFIG_NET_SOCKETS=y CONFIG_NET_IPV4=y diff --git a/tests/drivers/build_all/modem/modem_gsm.conf b/tests/drivers/build_all/modem/modem_gsm.conf index a7c4e492bc3..dd5b37afb9e 100644 --- a/tests/drivers/build_all/modem/modem_gsm.conf +++ b/tests/drivers/build_all/modem/modem_gsm.conf @@ -1,10 +1,9 @@ -CONFIG_TEST=y -CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_GPIO=y CONFIG_SERIAL=y +CONFIG_MODEM=y CONFIG_NETWORKING=y CONFIG_NET_IPV4=y CONFIG_NET_DRIVERS=y CONFIG_NET_PPP=y CONFIG_NET_L2_PPP=y -CONFIG_MODEM=y CONFIG_MODEM_GSM_PPP=y diff --git a/tests/drivers/build_all/modem/modem_gsm_mux.conf b/tests/drivers/build_all/modem/modem_gsm_mux.conf new file mode 100644 index 00000000000..952ace2466d --- /dev/null +++ b/tests/drivers/build_all/modem/modem_gsm_mux.conf @@ -0,0 +1,11 @@ +CONFIG_GPIO=y +CONFIG_SERIAL=y +CONFIG_MODEM=y +CONFIG_NETWORKING=y +CONFIG_NET_IPV4=y +CONFIG_NET_DRIVERS=y +CONFIG_NET_PPP=y +CONFIG_NET_L2_PPP=y +CONFIG_MODEM_GSM_PPP=y +CONFIG_GSM_MUX=y +CONFIG_UART_MUX=y diff --git a/tests/drivers/build_all/modem/modem.conf b/tests/drivers/build_all/modem/modem_hl7800.conf similarity index 79% rename from tests/drivers/build_all/modem/modem.conf rename to tests/drivers/build_all/modem/modem_hl7800.conf index 0143f6fcd7f..5cc44bb71ea 100644 --- a/tests/drivers/build_all/modem/modem.conf +++ b/tests/drivers/build_all/modem/modem_hl7800.conf @@ -1,10 +1,8 @@ -CONFIG_TEST=y -CONFIG_TEST_RANDOM_GENERATOR=y -CONFIG_TEST_USERSPACE=y +CONFIG_GPIO=y CONFIG_SERIAL=y +CONFIG_MODEM=y CONFIG_NETWORKING=y CONFIG_NET_IPV4=y -CONFIG_MODEM=y CONFIG_MODEM_HL7800=y CONFIG_MODEM_HL7800_FW_UPDATE=y CONFIG_MODEM_HL7800_SET_APN_NAME_ON_STARTUP=y diff --git a/tests/drivers/build_all/modem/modem_quectel_bg9x.conf b/tests/drivers/build_all/modem/modem_quectel_bg9x.conf index 9fb71bbe412..f868a0ef77a 100644 --- a/tests/drivers/build_all/modem/modem_quectel_bg9x.conf +++ b/tests/drivers/build_all/modem/modem_quectel_bg9x.conf @@ -1,9 +1,7 @@ -CONFIG_TEST=y -CONFIG_TEST_RANDOM_GENERATOR=y -CONFIG_SERIAL=y CONFIG_GPIO=y +CONFIG_SERIAL=y +CONFIG_MODEM=y CONFIG_NETWORKING=y CONFIG_NET_SOCKETS=y -CONFIG_MODEM=y CONFIG_MODEM_QUECTEL_BG9X=y CONFIG_MODEM_QUECTEL_BG9X_APN="hologram" diff --git a/tests/drivers/build_all/modem/modem_simcom_sim7080.conf b/tests/drivers/build_all/modem/modem_simcom_sim7080.conf index dc4645a2455..b6f1530f8a2 100644 --- a/tests/drivers/build_all/modem/modem_simcom_sim7080.conf +++ b/tests/drivers/build_all/modem/modem_simcom_sim7080.conf @@ -1,8 +1,7 @@ -CONFIG_TEST=y -CONFIG_TEST_RANDOM_GENERATOR=y -CONFIG_SERIAL=y CONFIG_GPIO=y +CONFIG_SERIAL=y +CONFIG_MODEM=y CONFIG_NETWORKING=y +CONFIG_GPIO=y CONFIG_NET_SOCKETS=y -CONFIG_MODEM=y CONFIG_MODEM_SIM7080=y diff --git a/tests/drivers/build_all/modem/modem_ublox_sara.conf b/tests/drivers/build_all/modem/modem_ublox_sara.conf index 21e61c8ec54..8cef947f051 100644 --- a/tests/drivers/build_all/modem/modem_ublox_sara.conf +++ b/tests/drivers/build_all/modem/modem_ublox_sara.conf @@ -1,8 +1,6 @@ -CONFIG_TEST=y -CONFIG_TEST_RANDOM_GENERATOR=y -CONFIG_SERIAL=y CONFIG_GPIO=y +CONFIG_SERIAL=y +CONFIG_MODEM=y CONFIG_NETWORKING=y CONFIG_NET_SOCKETS=y -CONFIG_MODEM=y CONFIG_MODEM_UBLOX_SARA=y diff --git a/tests/drivers/build_all/modem/prj.conf b/tests/drivers/build_all/modem/prj.conf deleted file mode 100644 index bb5ccbec1ba..00000000000 --- a/tests/drivers/build_all/modem/prj.conf +++ /dev/null @@ -1,3 +0,0 @@ -CONFIG_TEST=y -CONFIG_TEST_USERSPACE=y -CONFIG_SERIAL=y diff --git a/tests/drivers/build_all/modem/testcase.yaml b/tests/drivers/build_all/modem/testcase.yaml index 25c338b9fda..303e0ee44e8 100644 --- a/tests/drivers/build_all/modem/testcase.yaml +++ b/tests/drivers/build_all/modem/testcase.yaml @@ -1,86 +1,73 @@ common: build_only: true - tags: - - drivers - - net - - modem + platform_allow: + - native_sim + - native_sim_64 + - qemu_x86 + - qemu_x86_64 + tests: - drivers.modem.build: - extra_args: CONF_FILE=modem.conf - platform_exclude: - - serpente - - particle_boron - - rak5010_nrf52840 - - litex_vexriscv - - ip_k66f - min_ram: 68 - min_flash: 115 - drivers.modem.ublox_sara.build: + drivers.modem.modem_hl7800.interrupt_driven.build: + extra_args: CONF_FILE=modem_hl7800.conf + extra_configs: + - CONFIG_UART_INTERRUPT_DRIVEN=y + drivers.modem.modem_hl7800.async.build: + extra_args: CONF_FILE=modem_hl7800.conf + extra_configs: + - CONFIG_UART_ASYNC_API=y + drivers.modem.modem_ublox_sara.interrupt_driven.build: extra_args: CONF_FILE=modem_ublox_sara.conf - platform_exclude: - - serpente - - pinnacle_100_dvk - - litex_vexriscv - - ip_k66f - - mg100 - drivers.modem.simcom_sim7080.build: - extra_args: CONF_FILE=modem_simcom_sim7080.conf - platform_exclude: - - serpente - - pinnacle_100_dvk - - litex_vexriscv - - ip_k66f - - mg100 - drivers.modem.quectel_bg9x.build: + extra_configs: + - CONFIG_UART_INTERRUPT_DRIVEN=y + drivers.modem.modem_ublox_sara.async.build: + extra_args: CONF_FILE=modem_ublox_sara.conf + extra_configs: + - CONFIG_UART_ASYNC_API=y + drivers.modem.modem_quectel_bg9x.interrupt_driven.build: extra_args: CONF_FILE=modem_quectel_bg9x.conf - platform_exclude: - - serpente - - pinnacle_100_dvk - - litex_vexriscv - - ip_k66f - - mg100 - min_ram: 36 - drivers.modem.gsm.build: + extra_configs: + - CONFIG_UART_INTERRUPT_DRIVEN=y + drivers.modem.modem_quectel_bg9x.async.build: + extra_args: CONF_FILE=modem_quectel_bg9x.conf + extra_configs: + - CONFIG_UART_ASYNC_API=y + drivers.modem.modem_gsm.interrupt_driven.build: extra_args: CONF_FILE=modem_gsm.conf - platform_exclude: - - serpente - - particle_boron - - rak5010_nrf52840 - - litex_vexriscv - - ip_k66f - min_ram: 36 - drivers.modem.gsm_mux.build: + extra_configs: + - CONFIG_UART_INTERRUPT_DRIVEN=y + drivers.modem.modem_gsm.async.build: extra_args: CONF_FILE=modem_gsm.conf - platform_exclude: - - serpente - - particle_boron - - rak5010_nrf52840 - - litex_vexriscv - - ip_k66f - min_ram: 36 - extra_configs: - - CONFIG_GSM_MUX=y - - CONFIG_UART_MUX=y - drivers.modem.esp_at.build: + extra_configs: + - CONFIG_UART_ASYNC_API=y + drivers.modem.modem_gsm_mux.interrupt_driven.build: + extra_args: CONF_FILE=modem_gsm_mux.conf + extra_configs: + - CONFIG_UART_INTERRUPT_DRIVEN=y + drivers.modem.modem_gsm_mux.async.build: + extra_args: CONF_FILE=modem_gsm_mux.conf + extra_configs: + - CONFIG_UART_ASYNC_API=y + drivers.modem.modem_esp_at.interrupt_driven.build: extra_args: CONF_FILE=modem_esp_at.conf - platform_exclude: - - ip_k66f - - cy8cproto_062_4343w - filter: CONFIG_SERIAL - min_ram: 36 - drivers.modem.esp_at.async.build: + extra_configs: + - CONFIG_UART_INTERRUPT_DRIVEN=y + drivers.modem.modem_esp_at.async.build: extra_args: CONF_FILE=modem_esp_at.conf - filter: CONFIG_SERIAL and CONFIG_QEMU_TARGET - min_ram: 36 extra_configs: - - CONFIG_MODEM_IFACE_UART_ASYNC=y - drivers.modem.modem_cellular.build: + - CONFIG_UART_ASYNC_API=y + drivers.modem.modem_cellular.interrupt_driven.build: + extra_args: CONF_FILE=modem_cellular.conf + extra_configs: + - CONFIG_UART_INTERRUPT_DRIVEN=y + drivers.modem.modem_cellular.async.build: extra_args: CONF_FILE=modem_cellular.conf - platform_allow: - - native_posix_64 - - native_posix - - native_sim_64 - - native_sim - - qemu_x86 - - qemu_x86_64 - min_ram: 36 + extra_configs: + - CONFIG_UART_ASYNC_API=y + drivers.modem.modem_simcom_sim7080.interrupt_driven.build: + extra_args: CONF_FILE=modem_simcom_sim7080.conf + extra_configs: + - CONFIG_UART_INTERRUPT_DRIVEN=y + drivers.modem.modem_simcom_sim7080.async.build: + extra_args: CONF_FILE=modem_simcom_sim7080.conf + extra_configs: + - CONFIG_UART_ASYNC_API=y From 40489905c63a629e83e4ec440706849ece242320 Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Mon, 22 Jan 2024 15:33:13 +0700 Subject: [PATCH 1428/1623] [nrf fromtree] drivers: gnss: quectel_lcx6g: fix compilation error when CONFIG_PM_DEVICE=y Fixes a compilation error in quectel_lcx6g driver when CONFIG_PM_DEVICE=y. Corrects the function call in quectel_lcx6g_suspend from 'modem_chat_run_script_run' to 'modem_chat_run_script'. Signed-off-by: Pisit Sawangvonganan (cherry picked from commit 78faf5eb8e5c1f79dc7afd3183a4d969b3b7b146) --- drivers/gnss/gnss_quectel_lcx6g.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gnss/gnss_quectel_lcx6g.c b/drivers/gnss/gnss_quectel_lcx6g.c index f7b29b4640d..61d39140a9a 100644 --- a/drivers/gnss/gnss_quectel_lcx6g.c +++ b/drivers/gnss/gnss_quectel_lcx6g.c @@ -211,7 +211,7 @@ static int quectel_lcx6g_suspend(const struct device *dev) struct quectel_lcx6g_data *data = dev->data; int ret; - ret = modem_chat_run_script_run(&data->chat, &suspend_script); + ret = modem_chat_run_script(&data->chat, &suspend_script); if (ret < 0) { modem_pipe_close(data->uart_pipe); } From 65fecdaf9f29d3043064f42da0d153c8241435b5 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 15 Jan 2024 10:19:29 +0100 Subject: [PATCH 1429/1623] [nrf fromtree] modem: chat: remove receive and transmit timeouts Remove receive and transmit timeouts which are no longer useful as the RECEIVE_READY and TRANSMIT_IDLE events will be used to efficiently manage timeouts between transmit/receive calls. Then update the the in-tree drivers using the modem_chat module to omit the process timeout parameter. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 27b0d4e3fee2f56413757e13a3fcd522e9447921) --- drivers/gnss/gnss_nmea_generic.c | 1 - drivers/gnss/gnss_quectel_lcx6g.c | 1 - drivers/modem/modem_cellular.c | 1 - include/zephyr/modem/chat.h | 7 ++---- subsys/modem/modem_chat.c | 27 +++++++++++------------- tests/subsys/modem/modem_chat/src/main.c | 1 - 6 files changed, 14 insertions(+), 24 deletions(-) diff --git a/drivers/gnss/gnss_nmea_generic.c b/drivers/gnss/gnss_nmea_generic.c index 6d9adfb6990..2f23f4d7353 100644 --- a/drivers/gnss/gnss_nmea_generic.c +++ b/drivers/gnss/gnss_nmea_generic.c @@ -127,7 +127,6 @@ static int gnss_nmea_generic_init_chat(const struct device *dev) .argv_size = ARRAY_SIZE(data->chat_argv), .unsol_matches = unsol_matches, .unsol_matches_size = ARRAY_SIZE(unsol_matches), - .process_timeout = K_MSEC(2), }; return modem_chat_init(&data->chat, &chat_config); diff --git a/drivers/gnss/gnss_quectel_lcx6g.c b/drivers/gnss/gnss_quectel_lcx6g.c index 61d39140a9a..9c706e237a3 100644 --- a/drivers/gnss/gnss_quectel_lcx6g.c +++ b/drivers/gnss/gnss_quectel_lcx6g.c @@ -686,7 +686,6 @@ static int quectel_lcx6g_init_chat(const struct device *dev) .argv_size = ARRAY_SIZE(data->chat_argv), .unsol_matches = unsol_matches, .unsol_matches_size = ARRAY_SIZE(unsol_matches), - .process_timeout = K_MSEC(2), }; return modem_chat_init(&data->chat, &chat_config); diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index d1f3a69c94e..8aca855f55b 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -1520,7 +1520,6 @@ static int modem_cellular_init(const struct device *dev) .argv_size = ARRAY_SIZE(data->chat_argv), .unsol_matches = unsol_matches, .unsol_matches_size = ARRAY_SIZE(unsol_matches), - .process_timeout = K_MSEC(2), }; modem_chat_init(&data->chat, &chat_config); diff --git a/include/zephyr/modem/chat.h b/include/zephyr/modem/chat.h index d46ffc7c24a..7079cb8c61d 100644 --- a/include/zephyr/modem/chat.h +++ b/include/zephyr/modem/chat.h @@ -242,7 +242,7 @@ struct modem_chat { /* Script sending */ uint16_t script_send_request_pos; uint16_t script_send_delimiter_pos; - struct k_work_delayable script_send_work; + struct k_work script_send_work; struct k_work_delayable script_send_timeout_work; /* Match parsing */ @@ -252,8 +252,7 @@ struct modem_chat { uint16_t parse_match_type; /* Process received data */ - struct k_work_delayable process_work; - k_timeout_t process_timeout; + struct k_work receive_work; }; /** @@ -282,8 +281,6 @@ struct modem_chat_config { const struct modem_chat_match *unsol_matches; /** Elements in array of unsolicited matches */ uint16_t unsol_matches_size; - /** Delay from receive ready event to pipe receive occurs */ - k_timeout_t process_timeout; }; /** diff --git a/subsys/modem/modem_chat.c b/subsys/modem/modem_chat.c index f3857bcfbc3..99cf9bdbfa6 100644 --- a/subsys/modem/modem_chat.c +++ b/subsys/modem/modem_chat.c @@ -97,7 +97,7 @@ static void modem_chat_script_stop(struct modem_chat *chat, enum modem_chat_scri /* Cancel work */ k_work_cancel_delayable(&chat->script_timeout_work); - k_work_cancel_delayable(&chat->script_send_work); + k_work_cancel(&chat->script_send_work); k_work_cancel_delayable(&chat->script_send_timeout_work); /* Clear script running state */ @@ -117,7 +117,7 @@ static void modem_chat_script_send(struct modem_chat *chat) chat->script_send_delimiter_pos = 0; /* Schedule script send work */ - k_work_schedule(&chat->script_send_work, K_NO_WAIT); + k_work_submit(&chat->script_send_work); } static void modem_chat_script_set_response_matches(struct modem_chat *chat) @@ -308,8 +308,7 @@ static uint16_t modem_chat_script_chat_get_send_timeout(struct modem_chat *chat) static void modem_chat_script_send_handler(struct k_work *item) { - struct k_work_delayable *dwork = k_work_delayable_from_work(item); - struct modem_chat *chat = CONTAINER_OF(dwork, struct modem_chat, script_send_work); + struct modem_chat *chat = CONTAINER_OF(item, struct modem_chat, script_send_work); uint16_t timeout; /* Validate script running */ @@ -319,13 +318,13 @@ static void modem_chat_script_send_handler(struct k_work *item) /* Send request */ if (modem_chat_script_send_request(chat) == false) { - k_work_schedule(&chat->script_send_work, chat->process_timeout); + k_work_submit(&chat->script_send_work); return; } /* Send delimiter */ if (modem_chat_script_send_delimiter(chat) == false) { - k_work_schedule(&chat->script_send_work, chat->process_timeout); + k_work_submit(&chat->script_send_work); return; } @@ -687,8 +686,7 @@ static void modem_chat_process_bytes(struct modem_chat *chat) static void modem_chat_process_handler(struct k_work *item) { - struct k_work_delayable *dwork = k_work_delayable_from_work(item); - struct modem_chat *chat = CONTAINER_OF(dwork, struct modem_chat, process_work); + struct modem_chat *chat = CONTAINER_OF(item, struct modem_chat, receive_work); int ret; /* Fill work buffer */ @@ -702,7 +700,7 @@ static void modem_chat_process_handler(struct k_work *item) /* Process data */ modem_chat_process_bytes(chat); - k_work_schedule(&chat->process_work, K_NO_WAIT); + k_work_submit(&chat->receive_work); } static void modem_chat_pipe_callback(struct modem_pipe *pipe, enum modem_pipe_event event, @@ -711,7 +709,7 @@ static void modem_chat_pipe_callback(struct modem_pipe *pipe, enum modem_pipe_ev struct modem_chat *chat = (struct modem_chat *)user_data; if (event == MODEM_PIPE_EVENT_RECEIVE_READY) { - k_work_schedule(&chat->process_work, chat->process_timeout); + k_work_submit(&chat->receive_work); } } @@ -741,14 +739,13 @@ int modem_chat_init(struct modem_chat *chat, const struct modem_chat_config *con chat->filter_size = config->filter_size; chat->matches[MODEM_CHAT_MATCHES_INDEX_UNSOL] = config->unsol_matches; chat->matches_size[MODEM_CHAT_MATCHES_INDEX_UNSOL] = config->unsol_matches_size; - chat->process_timeout = config->process_timeout; atomic_set(&chat->script_state, 0); k_sem_init(&chat->script_stopped_sem, 0, 1); - k_work_init_delayable(&chat->process_work, modem_chat_process_handler); + k_work_init(&chat->receive_work, modem_chat_process_handler); k_work_init(&chat->script_run_work, modem_chat_script_run_handler); k_work_init_delayable(&chat->script_timeout_work, modem_chat_script_timeout_handler); k_work_init(&chat->script_abort_work, modem_chat_script_abort_handler); - k_work_init_delayable(&chat->script_send_work, modem_chat_script_send_handler); + k_work_init(&chat->script_send_work, modem_chat_script_send_handler); k_work_init_delayable(&chat->script_send_timeout_work, modem_chat_script_send_timeout_handler); @@ -831,8 +828,8 @@ void modem_chat_release(struct modem_chat *chat) k_work_cancel_sync(&chat->script_run_work, &sync); k_work_cancel_sync(&chat->script_abort_work, &sync); - k_work_cancel_delayable_sync(&chat->process_work, &sync); - k_work_cancel_delayable_sync(&chat->script_send_work, &sync); + k_work_cancel_sync(&chat->receive_work, &sync); + k_work_cancel_sync(&chat->script_send_work, &sync); chat->pipe = NULL; chat->receive_buf_len = 0; diff --git a/tests/subsys/modem/modem_chat/src/main.c b/tests/subsys/modem/modem_chat/src/main.c index 3f1ef57754d..f9a37ecc6cc 100644 --- a/tests/subsys/modem/modem_chat/src/main.c +++ b/tests/subsys/modem/modem_chat/src/main.c @@ -254,7 +254,6 @@ static void *test_modem_chat_setup(void) .argv_size = ARRAY_SIZE(cmd_argv), .unsol_matches = unsol_matches, .unsol_matches_size = ARRAY_SIZE(unsol_matches), - .process_timeout = K_MSEC(2), }; zassert(modem_chat_init(&cmd, &cmd_config) == 0, "Failed to init modem CMD"); From 79b90e6ca8dd2d5e1ed6f24ef4b74119c0f314c3 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 15 Jan 2024 14:29:48 +0100 Subject: [PATCH 1430/1623] [nrf fromtree] modem: chat: Implement TRANSMIT_IDLE event Refactors modem chat module to use TRANSMIT_IDLE event instead of polling when transmitting, cleaning up the transmit handler by combining duplicate code and using an internal state instead of multiple iterators to track send state. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit d801e697ddd1b0a3ae3df14f66c1d3a8f646d79b) --- include/zephyr/modem/chat.h | 4 +- subsys/modem/modem_chat.c | 153 ++++++++++++++++-------------------- 2 files changed, 71 insertions(+), 86 deletions(-) diff --git a/include/zephyr/modem/chat.h b/include/zephyr/modem/chat.h index 7079cb8c61d..28a2bc6bf9f 100644 --- a/include/zephyr/modem/chat.h +++ b/include/zephyr/modem/chat.h @@ -240,8 +240,8 @@ struct modem_chat { struct k_sem script_stopped_sem; /* Script sending */ - uint16_t script_send_request_pos; - uint16_t script_send_delimiter_pos; + enum modem_chat_script_send_state script_send_state; + uint16_t script_send_pos; struct k_work script_send_work; struct k_work_delayable script_send_timeout_work; diff --git a/subsys/modem/modem_chat.c b/subsys/modem/modem_chat.c index 99cf9bdbfa6..b2d63b05e9e 100644 --- a/subsys/modem/modem_chat.c +++ b/subsys/modem/modem_chat.c @@ -110,13 +110,16 @@ static void modem_chat_script_stop(struct modem_chat *chat, enum modem_chat_scri k_sem_give(&chat->script_stopped_sem); } -static void modem_chat_script_send(struct modem_chat *chat) +static void modem_chat_set_script_send_state(struct modem_chat *chat, + enum modem_chat_script_send_state state) { - /* Initialize script send work */ - chat->script_send_request_pos = 0; - chat->script_send_delimiter_pos = 0; + chat->script_send_pos = 0; + chat->script_send_state = state; +} - /* Schedule script send work */ +static void modem_chat_script_send(struct modem_chat *chat) +{ + modem_chat_set_script_send_state(chat, MODEM_CHAT_SCRIPT_SEND_STATE_REQUEST); k_work_submit(&chat->script_send_work); } @@ -219,91 +222,58 @@ static void modem_chat_script_abort_handler(struct k_work *item) modem_chat_script_stop(chat, MODEM_CHAT_SCRIPT_RESULT_ABORT); } -static bool modem_chat_script_send_request(struct modem_chat *chat) +static bool modem_chat_script_chat_is_no_response(struct modem_chat *chat) { const struct modem_chat_script_chat *script_chat = &chat->script->script_chats[chat->script_chat_it]; - uint8_t *script_chat_request_start; - uint16_t script_chat_request_remaining; - int ret; - - /* Validate data to send */ - if (script_chat->request_size == chat->script_send_request_pos) { - return true; - } - - script_chat_request_start = (uint8_t *)&script_chat->request[chat->script_send_request_pos]; - script_chat_request_remaining = script_chat->request_size - chat->script_send_request_pos; - - /* Send data through pipe */ - ret = modem_pipe_transmit(chat->pipe, script_chat_request_start, - script_chat_request_remaining); - - /* Validate transmit successful */ - if (ret < 1) { - return false; - } - - /* Update script send position */ - chat->script_send_request_pos += (uint16_t)ret; + return (script_chat->response_matches_size == 0) ? true : false; +} - /* Check if data remains */ - if (chat->script_send_request_pos < script_chat->request_size) { - return false; - } +static uint16_t modem_chat_script_chat_get_send_timeout(struct modem_chat *chat) +{ + const struct modem_chat_script_chat *script_chat = + &chat->script->script_chats[chat->script_chat_it]; - return true; + return script_chat->timeout; } -static bool modem_chat_script_send_delimiter(struct modem_chat *chat) +/* Returns true when request part has been sent */ +static bool modem_chat_send_script_request_part(struct modem_chat *chat) { - uint8_t *script_chat_delimiter_start; - uint8_t script_chat_delimiter_remaining; - int ret; + const struct modem_chat_script_chat *script_chat = + &chat->script->script_chats[chat->script_chat_it]; - /* Validate data to send */ - if (chat->delimiter_size == chat->script_send_delimiter_pos) { - return true; - } + uint8_t *request_part; + uint16_t request_size; + uint16_t request_part_size; + int ret; - script_chat_delimiter_start = (uint8_t *)&chat->delimiter[chat->script_send_delimiter_pos]; - script_chat_delimiter_remaining = chat->delimiter_size - chat->script_send_delimiter_pos; + switch (chat->script_send_state) { + case MODEM_CHAT_SCRIPT_SEND_STATE_REQUEST: + request_part = (uint8_t *)(&script_chat->request[chat->script_send_pos]); + request_size = script_chat->request_size; + break; - /* Send data through pipe */ - ret = modem_pipe_transmit(chat->pipe, script_chat_delimiter_start, - script_chat_delimiter_remaining); + case MODEM_CHAT_SCRIPT_SEND_STATE_DELIMITER: + request_part = (uint8_t *)(&chat->delimiter[chat->script_send_pos]); + request_size = chat->delimiter_size; + break; - /* Validate transmit successful */ - if (ret < 1) { + default: return false; } - /* Update script send position */ - chat->script_send_delimiter_pos += (uint8_t)ret; - - /* Check if data remains */ - if (chat->script_send_delimiter_pos < chat->delimiter_size) { + request_part_size = request_size - chat->script_send_pos; + ret = modem_pipe_transmit(chat->pipe, request_part, request_part_size); + if (ret < 1) { return false; } - return true; -} - -static bool modem_chat_script_chat_is_no_response(struct modem_chat *chat) -{ - const struct modem_chat_script_chat *script_chat = - &chat->script->script_chats[chat->script_chat_it]; - - return (script_chat->response_matches_size == 0) ? true : false; -} + chat->script_send_pos += (uint16_t)ret; -static uint16_t modem_chat_script_chat_get_send_timeout(struct modem_chat *chat) -{ - const struct modem_chat_script_chat *script_chat = - &chat->script->script_chats[chat->script_chat_it]; - - return script_chat->timeout; + /* Return true if all data was sent */ + return request_size <= chat->script_send_pos; } static void modem_chat_script_send_handler(struct k_work *item) @@ -311,27 +281,33 @@ static void modem_chat_script_send_handler(struct k_work *item) struct modem_chat *chat = CONTAINER_OF(item, struct modem_chat, script_send_work); uint16_t timeout; - /* Validate script running */ if (chat->script == NULL) { return; } - /* Send request */ - if (modem_chat_script_send_request(chat) == false) { - k_work_submit(&chat->script_send_work); + switch (chat->script_send_state) { + case MODEM_CHAT_SCRIPT_SEND_STATE_IDLE: return; - } - /* Send delimiter */ - if (modem_chat_script_send_delimiter(chat) == false) { - k_work_submit(&chat->script_send_work); - return; + case MODEM_CHAT_SCRIPT_SEND_STATE_REQUEST: + if (!modem_chat_send_script_request_part(chat)) { + return; + } + + modem_chat_set_script_send_state(chat, MODEM_CHAT_SCRIPT_SEND_STATE_DELIMITER); + __fallthrough; + + case MODEM_CHAT_SCRIPT_SEND_STATE_DELIMITER: + if (!modem_chat_send_script_request_part(chat)) { + return; + } + + modem_chat_set_script_send_state(chat, MODEM_CHAT_SCRIPT_SEND_STATE_IDLE); + break; } - /* Check if script command is no response */ if (modem_chat_script_chat_is_no_response(chat)) { timeout = modem_chat_script_chat_get_send_timeout(chat); - if (timeout == 0) { modem_chat_script_next(chat, false); } else { @@ -708,8 +684,17 @@ static void modem_chat_pipe_callback(struct modem_pipe *pipe, enum modem_pipe_ev { struct modem_chat *chat = (struct modem_chat *)user_data; - if (event == MODEM_PIPE_EVENT_RECEIVE_READY) { + switch (event) { + case MODEM_PIPE_EVENT_RECEIVE_READY: k_work_submit(&chat->receive_work); + break; + + case MODEM_PIPE_EVENT_TRANSMIT_IDLE: + k_work_submit(&chat->script_send_work); + break; + + default: + break; } } @@ -840,8 +825,8 @@ void modem_chat_release(struct modem_chat *chat) atomic_set(&chat->script_state, 0); chat->script_result = MODEM_CHAT_SCRIPT_RESULT_ABORT; k_sem_reset(&chat->script_stopped_sem); - chat->script_send_request_pos = 0; - chat->script_send_delimiter_pos = 0; + chat->script_send_state = MODEM_CHAT_SCRIPT_SEND_STATE_IDLE; + chat->script_send_pos = 0; chat->parse_match = NULL; chat->parse_match_len = 0; chat->parse_arg_len = 0; From ee6ff8ebb13606f4e913e7a0b60b6f41ff579d9e Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 28 Dec 2023 17:31:10 +0100 Subject: [PATCH 1431/1623] [nrf fromtree] tests modem/backends/tty: Define _XOPEN_SOURCE This test uses functions which are extensions to the C library. Let's explicity select one of the extensions which includes it instead of relaying on somebody having set it for this file somewhere else. (Note this test is exclusive to native targets) Signed-off-by: Alberto Escolar Piedras (cherry picked from commit 68c3a9ba4618698233578469c07fb35f0fa41841) --- tests/subsys/modem/backends/tty/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/subsys/modem/backends/tty/CMakeLists.txt b/tests/subsys/modem/backends/tty/CMakeLists.txt index e692be0de90..44597d8ae95 100644 --- a/tests/subsys/modem/backends/tty/CMakeLists.txt +++ b/tests/subsys/modem/backends/tty/CMakeLists.txt @@ -6,3 +6,4 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(modem_backend_tty_test) target_sources(app PRIVATE src/main.c) +target_compile_definitions(app PRIVATE _XOPEN_SOURCE=600) From 299d77ecd474917c74062f1287b30c18dcb71214 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 24 Jan 2024 08:48:30 +0100 Subject: [PATCH 1432/1623] [nrf fromtree] drivers: gnss: lcx6g: Remove left over from testing The k_msleep() removed with this has no utility. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit a9ffd91294fc8d0cc29c20136bd2e986daa86af6) --- drivers/gnss/gnss_quectel_lcx6g.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/gnss/gnss_quectel_lcx6g.c b/drivers/gnss/gnss_quectel_lcx6g.c index 9c706e237a3..8ab3b26a6d9 100644 --- a/drivers/gnss/gnss_quectel_lcx6g.c +++ b/drivers/gnss/gnss_quectel_lcx6g.c @@ -195,8 +195,6 @@ static int quectel_lcx6g_resume(const struct device *dev) return ret; } - k_msleep(1000); - ret = quectel_lcx6g_configure_pps(dev); if (ret < 0) { modem_pipe_close(data->uart_pipe); From 66ac3d1a00b00acc63b07ac8138fb8a7a4e980ce Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 24 Jan 2024 09:06:26 +0100 Subject: [PATCH 1433/1623] [nrf fromtree] drivers: gnss: lcx7g: Refactor power management The implementation of power management did not account for being on a power domain when initializing, and handling being powered on and off at runtime. The GNSS requires time to start up, which it always does when powered on, before accepting commands. It also requires time after resuming and suspending before accepting commands. This commit implements this timeout, and improves logging to make the power management more transparent, and removes some redundant parenthesis for better readability. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 59b9a86f30af343c16bc2f7b35d328fe91e5e718) --- drivers/gnss/gnss_quectel_lcx6g.c | 91 +++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 24 deletions(-) diff --git a/drivers/gnss/gnss_quectel_lcx6g.c b/drivers/gnss/gnss_quectel_lcx6g.c index 8ab3b26a6d9..30919f963ac 100644 --- a/drivers/gnss/gnss_quectel_lcx6g.c +++ b/drivers/gnss/gnss_quectel_lcx6g.c @@ -22,20 +22,18 @@ #include LOG_MODULE_REGISTER(quectel_lcx6g, CONFIG_GNSS_LOG_LEVEL); -#define QUECTEL_LCX6G_STARTUP_DELAY (K_MSEC(300U)) -#define QUECTEL_LCX6G_STATE_CHANGE_DELAY_MSEC (300LL) -#define QUECTEL_LCX6G_PAIR_TIMEOUT (K_SECONDS(11)) -#define QUECTEL_LCX6G_SCRIPT_TIMEOUT_S (10U) +#define QUECTEL_LCX6G_PM_TIMEOUT_MS 500U +#define QUECTEL_LCX6G_SCRIPT_TIMEOUT_S 10U -#define QUECTEL_LCX6G_PAIR_NAV_MODE_STATIONARY (4) -#define QUECTEL_LCX6G_PAIR_NAV_MODE_FITNESS (1) -#define QUECTEL_LCX6G_PAIR_NAV_MODE_NORMAL (0) -#define QUECTEL_LCX6G_PAIR_NAV_MODE_DRONE (5) +#define QUECTEL_LCX6G_PAIR_NAV_MODE_STATIONARY 4 +#define QUECTEL_LCX6G_PAIR_NAV_MODE_FITNESS 1 +#define QUECTEL_LCX6G_PAIR_NAV_MODE_NORMAL 0 +#define QUECTEL_LCX6G_PAIR_NAV_MODE_DRONE 5 -#define QUECTEL_LCX6G_PAIR_PPS_MODE_DISABLED (0) -#define QUECTEL_LCX6G_PAIR_PPS_MODE_ENABLED (4) -#define QUECTEL_LCX6G_PAIR_PPS_MODE_ENABLED_AFTER_LOCK (1) -#define QUECTEL_LCX6G_PAIR_PPS_MODE_ENABLED_WHILE_LOCKED (2) +#define QUECTEL_LCX6G_PAIR_PPS_MODE_DISABLED 0 +#define QUECTEL_LCX6G_PAIR_PPS_MODE_ENABLED 4 +#define QUECTEL_LCX6G_PAIR_PPS_MODE_ENABLED_AFTER_LOCK 1 +#define QUECTEL_LCX6G_PAIR_PPS_MODE_ENABLED_WHILE_LOCKED 2 struct quectel_lcx6g_config { const struct device *uart; @@ -77,6 +75,7 @@ struct quectel_lcx6g_data { }; struct k_spinlock lock; + k_timeout_t pm_timeout; }; #define MODEM_CHAT_SCRIPT_NO_ABORT_DEFINE(_sym, _script_chats, _callback, _timeout) \ @@ -173,33 +172,60 @@ static int quectel_lcx6g_configure_pps(const struct device *dev) return modem_chat_run_script(&data->chat, &data->dynamic_script); } +static void quectel_lcx6g_pm_changed(const struct device *dev) +{ + struct quectel_lcx6g_data *data = dev->data; + uint32_t pm_ready_at_ms; + + pm_ready_at_ms = k_uptime_get() + QUECTEL_LCX6G_PM_TIMEOUT_MS; + data->pm_timeout = K_TIMEOUT_ABS_MS(pm_ready_at_ms); +} + +static void quectel_lcx6g_await_pm_ready(const struct device *dev) +{ + struct quectel_lcx6g_data *data = dev->data; + + LOG_INF("Waiting until PM ready"); + k_sleep(data->pm_timeout); +} + static int quectel_lcx6g_resume(const struct device *dev) { struct quectel_lcx6g_data *data = dev->data; int ret; + LOG_INF("Resuming"); + + quectel_lcx6g_await_pm_ready(dev); + ret = modem_pipe_open(data->uart_pipe); if (ret < 0) { + LOG_ERR("Failed to open pipe"); return ret; } ret = modem_chat_attach(&data->chat, data->uart_pipe); if (ret < 0) { + LOG_ERR("Failed to attach chat"); modem_pipe_close(data->uart_pipe); return ret; } ret = modem_chat_run_script(&data->chat, &resume_script); if (ret < 0) { + LOG_ERR("Failed to initialize GNSS"); modem_pipe_close(data->uart_pipe); return ret; } ret = quectel_lcx6g_configure_pps(dev); if (ret < 0) { + LOG_ERR("Failed to configure PPS"); modem_pipe_close(data->uart_pipe); + return ret; } + LOG_INF("Resumed"); return ret; } @@ -209,18 +235,32 @@ static int quectel_lcx6g_suspend(const struct device *dev) struct quectel_lcx6g_data *data = dev->data; int ret; + LOG_INF("Suspending"); + + quectel_lcx6g_await_pm_ready(dev); + ret = modem_chat_run_script(&data->chat, &suspend_script); if (ret < 0) { + LOG_ERR("Failed to suspend GNSS"); modem_pipe_close(data->uart_pipe); + return ret; } + LOG_INF("Suspended"); return ret; } +static void quectel_lcx6g_turn_on(const struct device *dev) +{ + LOG_INF("Powered on"); +} + static int quectel_lcx6g_turn_off(const struct device *dev) { struct quectel_lcx6g_data *data = dev->data; + LOG_INF("Powered off"); + return modem_pipe_close(data->uart_pipe); } @@ -242,6 +282,7 @@ static int quectel_lcx6g_pm_action(const struct device *dev, enum pm_device_acti break; case PM_DEVICE_ACTION_TURN_ON: + quectel_lcx6g_turn_on(dev); ret = 0; break; @@ -253,6 +294,8 @@ static int quectel_lcx6g_pm_action(const struct device *dev, enum pm_device_acti break; } + quectel_lcx6g_pm_changed(dev); + k_spin_unlock(&data->lock, key); return ret; } @@ -717,7 +760,6 @@ static int quectel_lcx6g_init(const struct device *dev) { int ret; - LOG_INF("Initializing Quectel LCX6G"); ret = quectel_lcx6g_init_nmea0183_match(dev); if (ret < 0) { return ret; @@ -732,18 +774,19 @@ static int quectel_lcx6g_init(const struct device *dev) quectel_lcx6g_init_dynamic_script(dev); -#ifdef CONFIG_PM_DEVICE_RUNTIME - pm_device_init_suspended(dev); -#else - LOG_INF("Resuming Quectel LCX6G"); - ret = quectel_lcx6g_resume(dev); - if (ret < 0) { - LOG_ERR("Failed to resume Quectel LCX6G"); - return ret; + quectel_lcx6g_pm_changed(dev); + + if (pm_device_is_powered(dev)) { + ret = quectel_lcx6g_resume(dev); + if (ret < 0) { + return ret; + } + quectel_lcx6g_pm_changed(dev); + } else { + pm_device_init_off(dev); } -#endif - LOG_INF("Quectel LCX6G initialized"); - return 0; + + return pm_device_runtime_enable(dev); } #define LCX6G_INST_NAME(inst, name) \ From 98a6793b39341c383e8dc72703ce66195d6dd34f Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 24 Jan 2024 10:16:09 +0100 Subject: [PATCH 1434/1623] [nrf fromtree] drivers: gnss: lcx7g: Close pipe on suspend The pipe should be closed when suspended, both to save ressources and to flush it. Without flushing the pipe, the driver may fail to either resume or suspend the GNSS as the chat module starts processing old data, which can contain acks to commands, breaking the scripts. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 41240f9fb1074ec4cf7d486a86b8062e2a7e39ed) --- drivers/gnss/gnss_quectel_lcx6g.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gnss/gnss_quectel_lcx6g.c b/drivers/gnss/gnss_quectel_lcx6g.c index 30919f963ac..ee15a573ffe 100644 --- a/drivers/gnss/gnss_quectel_lcx6g.c +++ b/drivers/gnss/gnss_quectel_lcx6g.c @@ -242,11 +242,11 @@ static int quectel_lcx6g_suspend(const struct device *dev) ret = modem_chat_run_script(&data->chat, &suspend_script); if (ret < 0) { LOG_ERR("Failed to suspend GNSS"); - modem_pipe_close(data->uart_pipe); - return ret; + } else { + LOG_INF("Suspended"); } - LOG_INF("Suspended"); + modem_pipe_close(data->uart_pipe); return ret; } From d6aa22362121fc7d2d7ab34dcb29a97e9f1768a0 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 24 Jan 2024 10:39:29 +0100 Subject: [PATCH 1435/1623] [nrf fromtree] drivers: gnss: lcx7g: Add Kconfigs for configurable buffers Added Kconfigs to define the size of: - UART backend receive buffer - UART backend transmit buffer - Satellites array size and increased the UART RX buffer size a default to 256 as 128 is just on the edge of to small at a baudrate of 115200. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 98d95851c6778e86fca22dec3314fcd756ae25a9) --- drivers/gnss/Kconfig.quectel_lcx6g | 20 ++++++++++++++++++++ drivers/gnss/gnss_quectel_lcx6g.c | 6 +++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/gnss/Kconfig.quectel_lcx6g b/drivers/gnss/Kconfig.quectel_lcx6g index 6736015aed7..3036f76d05b 100644 --- a/drivers/gnss/Kconfig.quectel_lcx6g +++ b/drivers/gnss/Kconfig.quectel_lcx6g @@ -15,3 +15,23 @@ config GNSS_QUECTEL_LCX6G select GNSS_NMEA0183_MATCH help Enable quectel LCX6G series GNSS modem driver. + +if GNSS_QUECTEL_LCX6G + +config GNSS_QUECTEL_LCX6G_UART_RX_BUF_SIZE + int "Size of UART backend receive buffer" + default 256 + +config GNSS_QUECTEL_LCX6G_UART_TX_BUF_SIZE + int "Size of UART backend transmit buffer" + default 64 + +if GNSS_SATELLITES + +config GNSS_QUECTEL_LCX6G_SAT_ARRAY_SIZE + int "Size of GNSS satellites array" + default 24 + +endif # GNSS_SATELLITES + +endif # GNSS_QUECTEL_LCX6G diff --git a/drivers/gnss/gnss_quectel_lcx6g.c b/drivers/gnss/gnss_quectel_lcx6g.c index ee15a573ffe..09fa8fd8e4a 100644 --- a/drivers/gnss/gnss_quectel_lcx6g.c +++ b/drivers/gnss/gnss_quectel_lcx6g.c @@ -44,14 +44,14 @@ struct quectel_lcx6g_config { struct quectel_lcx6g_data { struct gnss_nmea0183_match_data match_data; #if CONFIG_GNSS_SATELLITES - struct gnss_satellite satellites[24]; + struct gnss_satellite satellites[CONFIG_GNSS_QUECTEL_LCX6G_SAT_ARRAY_SIZE]; #endif /* UART backend */ struct modem_pipe *uart_pipe; struct modem_backend_uart uart_backend; - uint8_t uart_backend_receive_buf[128]; - uint8_t uart_backend_transmit_buf[64]; + uint8_t uart_backend_receive_buf[CONFIG_GNSS_QUECTEL_LCX6G_UART_RX_BUF_SIZE]; + uint8_t uart_backend_transmit_buf[CONFIG_GNSS_QUECTEL_LCX6G_UART_TX_BUF_SIZE]; /* Modem chat */ struct modem_chat chat; From 4c676acc03dd7daaa24b11a549e9b81fb70b6f1f Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sat, 27 Jan 2024 13:15:39 +1000 Subject: [PATCH 1436/1623] [nrf fromtree] tests: build_all: modem: test compilation with connectivity Ensure WiFi modems still build with the `CONNECTIVITY_WIFI_MGMT` connectivity backend enabled. Signed-off-by: Jordan Yates (cherry picked from commit 651ffb1d0687e2b197110f8aa7c92c42dee21a47) --- tests/drivers/build_all/modem/modem_esp_at.conf | 2 ++ tests/drivers/build_all/modem/src/main.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/tests/drivers/build_all/modem/modem_esp_at.conf b/tests/drivers/build_all/modem/modem_esp_at.conf index 6ba79c82653..e24bee337af 100644 --- a/tests/drivers/build_all/modem/modem_esp_at.conf +++ b/tests/drivers/build_all/modem/modem_esp_at.conf @@ -5,3 +5,5 @@ CONFIG_NETWORKING=y CONFIG_NET_SOCKETS=y CONFIG_NET_IPV4=y CONFIG_WIFI=y +CONFIG_NET_CONNECTION_MANAGER=y +CONFIG_NET_CONNECTION_MANAGER_CONNECTIVITY_WIFI_MGMT=y diff --git a/tests/drivers/build_all/modem/src/main.c b/tests/drivers/build_all/modem/src/main.c index 90b910a7799..527f64e3f1e 100644 --- a/tests/drivers/build_all/modem/src/main.c +++ b/tests/drivers/build_all/modem/src/main.c @@ -8,3 +8,15 @@ int main(void) { return 0; } + +#ifdef CONFIG_CONNECTIVITY_WIFI_MGMT_APPLICATION + +#include +#include + +/* Bind L2 connectity APIs. */ +static struct conn_mgr_conn_api conn_api = { 0 }; + +CONN_MGR_CONN_DEFINE(CONNECTIVITY_WIFI_MGMT, &conn_api); + +#endif /* CONFIG_CONNECTIVITY_WIFI_MGMT_APPLICATION */ From 007da96aa26d29396e2360806b90a3a7d708b233 Mon Sep 17 00:00:00 2001 From: Parthiban Nallathambi Date: Mon, 5 Feb 2024 16:15:18 +0530 Subject: [PATCH 1437/1623] [nrf fromtree] modem: change log level of events prints to debug info level is printed always to console and it's noisy. Change to debug level, which can be enabled with CONFIG_MODEM_MODULES_LOG_LEVEL_DBG Signed-off-by: Parthiban Nallathambi (cherry picked from commit fd85021718d1dfbac8d8d4c477f3ba2a0a9226eb) --- drivers/modem/modem_cellular.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index 8aca855f55b..996a1e838c4 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -445,13 +445,13 @@ MODEM_CHAT_MATCHES_DEFINE(dial_abort_matches, static void modem_cellular_log_state_changed(enum modem_cellular_state last_state, enum modem_cellular_state new_state) { - LOG_INF("switch from %s to %s", modem_cellular_state_str(last_state), + LOG_DBG("switch from %s to %s", modem_cellular_state_str(last_state), modem_cellular_state_str(new_state)); } static void modem_cellular_log_event(enum modem_cellular_event evt) { - LOG_INF("event %s", modem_cellular_event_str(evt)); + LOG_DBG("event %s", modem_cellular_event_str(evt)); } static void modem_cellular_start_timer(struct modem_cellular_data *data, k_timeout_t timeout) From 30f01a55bf61892924b51da112aeafcd134e1598 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 12 Feb 2024 17:10:19 +0100 Subject: [PATCH 1438/1623] [nrf fromtree] modem: modem_cellular: CID 338164 strncpy() passed incorrect size Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit adcdf64a0f3f05151ad88425ac707420a96926ca) --- drivers/modem/modem_cellular.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index 996a1e838c4..217f2b3ff2d 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -337,7 +337,7 @@ static void modem_cellular_chat_on_cgmr(struct modem_chat *chat, char **argv, ui return; } - strncpy(data->fw_version, argv[1], sizeof(data->fw_version)); + strncpy(data->fw_version, argv[1], sizeof(data->fw_version) - 1); } static void modem_cellular_chat_on_csq(struct modem_chat *chat, char **argv, uint16_t argc, From 0074fed59ad645c84eaf1769676265a8e175908c Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 12 Feb 2024 17:11:42 +0100 Subject: [PATCH 1439/1623] [nrf fromtree] modem: modem_cellular: CID 338140 incorrect size passed to strncpy Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit ae951f5f0215b8b8c57a5fed97d773770e7ed16f) --- drivers/modem/modem_cellular.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index 217f2b3ff2d..c3912c119c3 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -325,7 +325,7 @@ static void modem_cellular_chat_on_cgmi(struct modem_chat *chat, char **argv, ui return; } - strncpy(data->manufacturer, argv[1], sizeof(data->manufacturer)); + strncpy(data->manufacturer, argv[1], sizeof(data->manufacturer) - 1); } static void modem_cellular_chat_on_cgmr(struct modem_chat *chat, char **argv, uint16_t argc, From 907b6b929ced39b6243ca81c979762792d4f2e4b Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 12 Feb 2024 17:12:26 +0100 Subject: [PATCH 1440/1623] [nrf fromtree] modem: modem_cellular: CID 338115 incorrect size passed to strncpy() Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 08a51bae89c6f552363f31a152912819e099021b) --- drivers/modem/modem_cellular.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index c3912c119c3..6ef6d125ea9 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -313,7 +313,7 @@ static void modem_cellular_chat_on_cgmm(struct modem_chat *chat, char **argv, ui return; } - strncpy(data->model_id, argv[1], sizeof(data->model_id)); + strncpy(data->model_id, argv[1], sizeof(data->model_id) - 1); } static void modem_cellular_chat_on_cgmi(struct modem_chat *chat, char **argv, uint16_t argc, From 7b07143975ad8abf6cb39cc7fd5838d3cf53a40b Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 12 Feb 2024 17:13:07 +0100 Subject: [PATCH 1441/1623] [nrf fromtree] modem: modem_cellular: CID 338073 incorrect size passed to strncpy() Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit b668296a50a17132cc911fac3009ef8ee01652d2) --- drivers/modem/modem_cellular.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index 6ef6d125ea9..36596c6447e 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -301,7 +301,7 @@ static void modem_cellular_chat_on_imei(struct modem_chat *chat, char **argv, ui return; } - strncpy(data->imei, argv[1], sizeof(data->imei)); + strncpy(data->imei, argv[1], sizeof(data->imei) - 1); } static void modem_cellular_chat_on_cgmm(struct modem_chat *chat, char **argv, uint16_t argc, From 9d1143390287ed92444046c59bf70f8b689d0e49 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 12 Feb 2024 17:14:00 +0100 Subject: [PATCH 1442/1623] [nrf fromtree] modem: modem_cellular: CID 338067 incorrect size passed to strncpy() Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 080d51bb367836b73021fdd7ade3e2c4c54a0435) --- drivers/modem/modem_cellular.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index 36596c6447e..f5e099cd08c 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -370,7 +370,7 @@ static void modem_cellular_chat_on_imsi(struct modem_chat *chat, char **argv, ui { struct modem_cellular_data *data = (struct modem_cellular_data *)user_data; - strncpy(data->imsi, (char *)argv[1], sizeof(data->imsi)); + strncpy(data->imsi, argv[1], sizeof(data->imsi) - 1); } static bool modem_cellular_is_registered(struct modem_cellular_data *data) From 5e495c448230b2597987ac7cdd264d8e8bc9722c Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Mon, 29 Jan 2024 11:41:56 +0200 Subject: [PATCH 1443/1623] [nrf fromlist] modem: small improvements Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68206 Changes include: - Improving handling of frames for unconfigured DLCIs. - Adding logs and outputting error codes in failure cases. - Adding warnings to not reuse buffers. - Fixing comments. Signed-off-by: Tomi Fontanilles --- include/zephyr/modem/pipe.h | 20 ++++++++------- .../modem/backends/modem_backend_uart_async.c | 5 ++-- subsys/modem/modem_cmux.c | 25 ++++++++++++------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/include/zephyr/modem/pipe.h b/include/zephyr/modem/pipe.h index a741a94a34c..70a37302273 100644 --- a/include/zephyr/modem/pipe.h +++ b/include/zephyr/modem/pipe.h @@ -130,25 +130,27 @@ void modem_pipe_attach(struct modem_pipe *pipe, modem_pipe_api_callback callback * @brief Transmit data through pipe * * @param pipe Pipe to transmit through - * @param buf Destination for reveived data - * @param size Capacity of destination for recevied data + * @param buf Data to transmit + * @param size Number of bytes to transmit * - * @return Number of bytes placed in pipe + * @retval Number of bytes placed in pipe + * @retval -EPERM if pipe is closed + * @retval -errno code on error * * @warning This call must be non-blocking */ int modem_pipe_transmit(struct modem_pipe *pipe, const uint8_t *buf, size_t size); /** - * @brief Reveive data through pipe + * @brief Receive data through pipe * * @param pipe Pipe to receive from - * @param buf Destination for reveived data - * @param size Capacity of destination for recevied data + * @param buf Destination for received data; must not be already in use in a modem module. + * @param size Capacity of destination for received data * - * @return Number of bytes received from pipe if any - * @return -EPERM if pipe is closed - * @return -errno code on error + * @retval Number of bytes received from pipe + * @retval -EPERM if pipe is closed + * @retval -errno code on error * * @warning This call must be non-blocking */ diff --git a/subsys/modem/backends/modem_backend_uart_async.c b/subsys/modem/backends/modem_backend_uart_async.c index 47148a77f77..0aa88ccd48c 100644 --- a/subsys/modem/backends/modem_backend_uart_async.c +++ b/subsys/modem/backends/modem_backend_uart_async.c @@ -185,8 +185,9 @@ static int modem_backend_uart_async_transmit(void *data, const uint8_t *buf, siz ret = uart_tx(backend->uart, backend->async.transmit_buf, bytes_to_transmit, CONFIG_MODEM_BACKEND_UART_ASYNC_TRANSMIT_TIMEOUT_MS * 1000L); - if (ret < 0) { - LOG_WRN("Failed to start async transmit"); + if (ret != 0) { + LOG_ERR("Failed to %s %u bytes. (%d)", + "start async transmit for", bytes_to_transmit, ret); return ret; } diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index 16dc60b7219..6f9f10c04a6 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -564,7 +564,8 @@ static void modem_cmux_on_dlci_frame_uih(struct modem_cmux_dlci *dlci) written = ring_buf_put(&dlci->receive_rb, cmux->frame.data, cmux->frame.data_len); k_mutex_unlock(&dlci->receive_rb_lock); if (written != cmux->frame.data_len) { - LOG_WRN("DLCI %u receive buffer overrun", dlci->dlci_address); + LOG_WRN("DLCI %u receive buffer overrun (dropped %u out of %u bytes)", + dlci->dlci_address, cmux->frame.data_len - written, cmux->frame.data_len); } modem_pipe_notify_receive_ready(&dlci->pipe); } @@ -606,16 +607,15 @@ static void modem_cmux_on_dlci_frame(struct modem_cmux *cmux) { struct modem_cmux_dlci *dlci; - dlci = modem_cmux_find_dlci(cmux); + modem_cmux_log_received_frame(&cmux->frame); + dlci = modem_cmux_find_dlci(cmux); if (dlci == NULL) { - LOG_WRN("Could not find DLCI: %u", cmux->frame.dlci_address); - + LOG_WRN("Ignoring frame intended for unconfigured DLCI %u.", + cmux->frame.dlci_address); return; } - modem_cmux_log_received_frame(&cmux->frame); - switch (cmux->frame.type) { case MODEM_CMUX_FRAME_TYPE_UA: modem_cmux_on_dlci_frame_ua(dlci); @@ -643,10 +643,9 @@ static void modem_cmux_on_frame(struct modem_cmux *cmux) { if (cmux->frame.dlci_address == 0) { modem_cmux_on_control_frame(cmux); - return; + } else { + modem_cmux_on_dlci_frame(cmux); } - - modem_cmux_on_dlci_frame(cmux); } static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t byte) @@ -830,6 +829,9 @@ static void modem_cmux_receive_handler(struct k_work *item) /* Receive data from pipe */ ret = modem_pipe_receive(cmux->pipe, buf, sizeof(buf)); if (ret < 1) { + if (ret < 0) { + LOG_ERR("Pipe receiving error: %d", ret); + } return; } @@ -876,12 +878,17 @@ static void modem_cmux_transmit_handler(struct k_work *item) ret = modem_pipe_transmit(cmux->pipe, reserved, reserved_size); if (ret < 0) { ring_buf_get_finish(&cmux->transmit_rb, 0); + if (ret != -EPERM) { + LOG_ERR("Failed to %s %u bytes. (%d)", + "transmit", reserved_size, ret); + } break; } ring_buf_get_finish(&cmux->transmit_rb, (uint32_t)ret); if (ret < reserved_size) { + LOG_DBG("Transmitted only %u out of %u bytes at once.", ret, reserved_size); break; } } From 8017cad4e529c965afc0c747e342e17ba44c254f Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Tue, 6 Feb 2024 12:51:46 +0200 Subject: [PATCH 1444/1623] [nrf fromlist] modem: backends: use CONFIG_MODEM_MODULES_LOG_LEVEL Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68651 This makes the modem backends use the log level set for the modem modules instead of the default one. Signed-off-by: Tomi Fontanilles --- subsys/modem/backends/modem_backend_tty.c | 2 +- subsys/modem/backends/modem_backend_uart.c | 2 +- subsys/modem/backends/modem_backend_uart_async.c | 2 +- subsys/modem/backends/modem_backend_uart_isr.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/modem/backends/modem_backend_tty.c b/subsys/modem/backends/modem_backend_tty.c index 8375183be48..e511150ae9d 100644 --- a/subsys/modem/backends/modem_backend_tty.c +++ b/subsys/modem/backends/modem_backend_tty.c @@ -7,7 +7,7 @@ #include #include -LOG_MODULE_REGISTER(modem_backend_tty); +LOG_MODULE_REGISTER(modem_backend_tty, CONFIG_MODEM_MODULES_LOG_LEVEL); #include #include diff --git a/subsys/modem/backends/modem_backend_uart.c b/subsys/modem/backends/modem_backend_uart.c index a8348b0b8a0..b77a7331899 100644 --- a/subsys/modem/backends/modem_backend_uart.c +++ b/subsys/modem/backends/modem_backend_uart.c @@ -10,7 +10,7 @@ #include #include -LOG_MODULE_REGISTER(modem_backend_uart); +LOG_MODULE_REGISTER(modem_backend_uart, CONFIG_MODEM_MODULES_LOG_LEVEL); #include diff --git a/subsys/modem/backends/modem_backend_uart_async.c b/subsys/modem/backends/modem_backend_uart_async.c index 0aa88ccd48c..107f5e4290e 100644 --- a/subsys/modem/backends/modem_backend_uart_async.c +++ b/subsys/modem/backends/modem_backend_uart_async.c @@ -7,7 +7,7 @@ #include "modem_backend_uart_async.h" #include -LOG_MODULE_DECLARE(modem_backend_uart); +LOG_MODULE_DECLARE(modem_backend_uart, CONFIG_MODEM_MODULES_LOG_LEVEL); #include #include diff --git a/subsys/modem/backends/modem_backend_uart_isr.c b/subsys/modem/backends/modem_backend_uart_isr.c index 8a7075e3519..9eed7913496 100644 --- a/subsys/modem/backends/modem_backend_uart_isr.c +++ b/subsys/modem/backends/modem_backend_uart_isr.c @@ -7,7 +7,7 @@ #include "modem_backend_uart_isr.h" #include -LOG_MODULE_DECLARE(modem_backend_uart); +LOG_MODULE_DECLARE(modem_backend_uart, CONFIG_MODEM_MODULES_LOG_LEVEL); #include From 8b32ec35dc133c67c110bfa0eea63724a8780018 Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Tue, 6 Feb 2024 15:42:11 +0200 Subject: [PATCH 1445/1623] [nrf fromlist] modem: ppp: fix crash when attaching to a pipe Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68651 modem_pipe_attach() can send events before returning, which could provoke a crash as ppp->pipe, still NULL at that time, could be used either in receiving (if the pipe had some data pending) or in sending (if the PPP module had already been attached and had some data to send in its transmit buffer). ppp->pipe is now set before modem_pipe_attach(). Also, the ATTACHED_BIT is now set only after having actually attached. And finally, the send_work is now scheduled on PIPE_EVENT_OPENED so that data is flushed when the (closed) attached pipe is opened. Signed-off-by: Tomi Fontanilles --- subsys/modem/modem_ppp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/subsys/modem/modem_ppp.c b/subsys/modem/modem_ppp.c index 1d47542f24a..dffa4f68dbf 100644 --- a/subsys/modem/modem_ppp.c +++ b/subsys/modem/modem_ppp.c @@ -319,6 +319,7 @@ static void modem_ppp_pipe_callback(struct modem_pipe *pipe, enum modem_pipe_eve k_work_submit(&ppp->process_work); break; + case MODEM_PIPE_EVENT_OPENED: case MODEM_PIPE_EVENT_TRANSMIT_IDLE: k_work_submit(&ppp->send_work); break; @@ -467,12 +468,14 @@ const struct ppp_api modem_ppp_ppp_api = { int modem_ppp_attach(struct modem_ppp *ppp, struct modem_pipe *pipe) { - if (atomic_test_and_set_bit(&ppp->state, MODEM_PPP_STATE_ATTACHED_BIT) == true) { + if (atomic_test_bit(&ppp->state, MODEM_PPP_STATE_ATTACHED_BIT) == true) { return 0; } - modem_pipe_attach(pipe, modem_ppp_pipe_callback, ppp); ppp->pipe = pipe; + modem_pipe_attach(pipe, modem_ppp_pipe_callback, ppp); + + atomic_set_bit(&ppp->state, MODEM_PPP_STATE_ATTACHED_BIT); return 0; } From 6fa0378cef081f48548ffc7916d45e5fa484550c Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 14 Feb 2024 05:42:22 +0200 Subject: [PATCH 1446/1623] [nrf fromlist] modem: ppp: fix receiving of successive frames when one 0x7E is omitted Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68651 The SOF delimiter byte may be omitted when a frame follows another that just ended with that byte. The parsing used to expect that second delimiter anyway, which resulted in PPP frames going missing. As an additional improvement, dropped bytes as well as the length of received frames are now (debug) logged. Signed-off-by: Tomi Fontanilles --- subsys/modem/modem_ppp.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/subsys/modem/modem_ppp.c b/subsys/modem/modem_ppp.c index dffa4f68dbf..91085317d99 100644 --- a/subsys/modem/modem_ppp.c +++ b/subsys/modem/modem_ppp.c @@ -192,40 +192,45 @@ static uint8_t modem_ppp_wrap_net_pkt_byte(struct modem_ppp *ppp) return 0; } +static bool modem_ppp_is_byte_expected(uint8_t byte, uint8_t expected_byte) +{ + if (byte == expected_byte) { + return true; + } + LOG_DBG("Dropping byte 0x%02hhx because 0x%02hhx was expected.", byte, expected_byte); + return false; +} + static void modem_ppp_process_received_byte(struct modem_ppp *ppp, uint8_t byte) { switch (ppp->receive_state) { case MODEM_PPP_RECEIVE_STATE_HDR_SOF: - if (byte == MODEM_PPP_CODE_DELIMITER) { + if (modem_ppp_is_byte_expected(byte, MODEM_PPP_CODE_DELIMITER)) { ppp->receive_state = MODEM_PPP_RECEIVE_STATE_HDR_FF; } - break; case MODEM_PPP_RECEIVE_STATE_HDR_FF: if (byte == MODEM_PPP_CODE_DELIMITER) { break; } - - if (byte == 0xFF) { + if (modem_ppp_is_byte_expected(byte, 0xFF)) { ppp->receive_state = MODEM_PPP_RECEIVE_STATE_HDR_7D; } else { ppp->receive_state = MODEM_PPP_RECEIVE_STATE_HDR_SOF; } - break; case MODEM_PPP_RECEIVE_STATE_HDR_7D: - if (byte == MODEM_PPP_CODE_ESCAPE) { + if (modem_ppp_is_byte_expected(byte, MODEM_PPP_CODE_ESCAPE)) { ppp->receive_state = MODEM_PPP_RECEIVE_STATE_HDR_23; } else { ppp->receive_state = MODEM_PPP_RECEIVE_STATE_HDR_SOF; } - break; case MODEM_PPP_RECEIVE_STATE_HDR_23: - if (byte == 0x23) { + if (modem_ppp_is_byte_expected(byte, 0x23)) { ppp->rx_pkt = net_pkt_rx_alloc_with_buffer(ppp->iface, CONFIG_MODEM_PPP_NET_BUF_FRAG_SIZE, AF_UNSPEC, 0, K_NO_WAIT); @@ -238,7 +243,6 @@ static void modem_ppp_process_received_byte(struct modem_ppp *ppp, uint8_t byte) LOG_DBG("Receiving PPP frame"); ppp->receive_state = MODEM_PPP_RECEIVE_STATE_WRITING; net_pkt_cursor_init(ppp->rx_pkt); - } else { ppp->receive_state = MODEM_PPP_RECEIVE_STATE_HDR_SOF; } @@ -247,11 +251,10 @@ static void modem_ppp_process_received_byte(struct modem_ppp *ppp, uint8_t byte) case MODEM_PPP_RECEIVE_STATE_WRITING: if (byte == MODEM_PPP_CODE_DELIMITER) { - LOG_DBG("Received PPP frame"); + LOG_DBG("Received PPP frame (len %zu)", net_pkt_get_len(ppp->rx_pkt)); /* Remove FCS */ net_pkt_remove_tail(ppp->rx_pkt, MODEM_PPP_FRAME_TAIL_SIZE); - net_pkt_cursor_init(ppp->rx_pkt); net_pkt_set_ppp(ppp->rx_pkt, true); if (net_recv_data(ppp->iface, ppp->rx_pkt) < 0) { @@ -260,7 +263,8 @@ static void modem_ppp_process_received_byte(struct modem_ppp *ppp, uint8_t byte) } ppp->rx_pkt = NULL; - ppp->receive_state = MODEM_PPP_RECEIVE_STATE_HDR_SOF; + /* Skip SOF because the delimiter may be omitted for successive frames. */ + ppp->receive_state = MODEM_PPP_RECEIVE_STATE_HDR_FF; break; } From 6ae16aac09d717957a4a2e39c5569bc8293b22d9 Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 14 Feb 2024 05:42:38 +0200 Subject: [PATCH 1447/1623] [nrf fromlist] modem: backend: uart_async: improve logging on UART_TX_ABORTED Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68651 Only log if the abort is not self-triggered, and also print the number of bytes sent. Signed-off-by: Tomi Fontanilles --- .../modem/backends/modem_backend_uart_async.c | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/subsys/modem/backends/modem_backend_uart_async.c b/subsys/modem/backends/modem_backend_uart_async.c index 107f5e4290e..29107198c2f 100644 --- a/subsys/modem/backends/modem_backend_uart_async.c +++ b/subsys/modem/backends/modem_backend_uart_async.c @@ -12,12 +12,15 @@ LOG_MODULE_DECLARE(modem_backend_uart, CONFIG_MODEM_MODULES_LOG_LEVEL); #include #include -#define MODEM_BACKEND_UART_ASYNC_STATE_TRANSMITTING_BIT (0) -#define MODEM_BACKEND_UART_ASYNC_STATE_RECEIVING_BIT (1) -#define MODEM_BACKEND_UART_ASYNC_STATE_RX_BUF0_USED_BIT (2) -#define MODEM_BACKEND_UART_ASYNC_STATE_RX_BUF1_USED_BIT (3) +enum { + MODEM_BACKEND_UART_ASYNC_STATE_TRANSMITTING_BIT, + MODEM_BACKEND_UART_ASYNC_STATE_RECEIVING_BIT, + MODEM_BACKEND_UART_ASYNC_STATE_RX_BUF0_USED_BIT, + MODEM_BACKEND_UART_ASYNC_STATE_RX_BUF1_USED_BIT, + MODEM_BACKEND_UART_ASYNC_STATE_OPEN_BIT, +}; -static bool modem_backend_uart_async_is_closed(struct modem_backend_uart *backend) +static bool modem_backend_uart_async_is_uart_stopped(struct modem_backend_uart *backend) { if (!atomic_test_bit(&backend->async.state, MODEM_BACKEND_UART_ASYNC_STATE_TRANSMITTING_BIT) && @@ -33,6 +36,12 @@ static bool modem_backend_uart_async_is_closed(struct modem_backend_uart *backen return false; } +static bool modem_backend_uart_async_is_open(struct modem_backend_uart *backend) +{ + return atomic_test_bit(&backend->async.state, + MODEM_BACKEND_UART_ASYNC_STATE_OPEN_BIT); +} + static void modem_backend_uart_async_event_handler(const struct device *dev, struct uart_event *evt, void *user_data) { @@ -49,7 +58,9 @@ static void modem_backend_uart_async_event_handler(const struct device *dev, break; case UART_TX_ABORTED: - LOG_WRN("Transmit aborted"); + if (modem_backend_uart_async_is_open(backend)) { + LOG_WRN("Transmit aborted (%zu sent)", evt->data.tx.len); + } atomic_clear_bit(&backend->async.state, MODEM_BACKEND_UART_ASYNC_STATE_TRANSMITTING_BIT); k_work_submit(&backend->transmit_idle_work); @@ -124,7 +135,7 @@ static void modem_backend_uart_async_event_handler(const struct device *dev, break; } - if (modem_backend_uart_async_is_closed(backend)) { + if (modem_backend_uart_async_is_uart_stopped(backend)) { k_work_submit(&backend->async.rx_disabled_work); } } @@ -155,6 +166,8 @@ static int modem_backend_uart_async_open(void *data) atomic_set_bit(&backend->async.state, MODEM_BACKEND_UART_ASYNC_STATE_RECEIVING_BIT); + atomic_set_bit(&backend->async.state, + MODEM_BACKEND_UART_ASYNC_STATE_OPEN_BIT); modem_pipe_notify_opened(&backend->pipe); return 0; @@ -217,6 +230,7 @@ static int modem_backend_uart_async_close(void *data) { struct modem_backend_uart *backend = (struct modem_backend_uart *)data; + atomic_clear_bit(&backend->async.state, MODEM_BACKEND_UART_ASYNC_STATE_OPEN_BIT); uart_tx_abort(backend->uart); uart_rx_disable(backend->uart); return 0; From 8b3d940fb4f4283bd39893da146c5f3f2ab26e87 Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 14 Feb 2024 06:08:26 +0200 Subject: [PATCH 1448/1623] [nrf fromlist] modem: cmux: improve handling of receive buffer overrun Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68651 This allows to properly drop single CMUX frames that are too big to fit in the receive buffer, keeping track of where they end so that following frames are received correctly regardless of the data contents. Signed-off-by: Tomi Fontanilles --- subsys/modem/modem_cmux.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index 6f9f10c04a6..67190934c45 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -221,7 +221,7 @@ static uint16_t modem_cmux_transmit_frame(struct modem_cmux *cmux, uint16_t buf_idx; space = ring_buf_space_get(&cmux->transmit_rb) - MODEM_CMUX_FRAME_SIZE_MAX; - data_len = (space < frame->data_len) ? space : frame->data_len; + data_len = MIN(space, frame->data_len); /* SOF */ buf[0] = 0xF9; @@ -746,28 +746,27 @@ static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t by case MODEM_CMUX_RECEIVE_STATE_DATA: /* Copy byte to data */ - cmux->receive_buf[cmux->receive_buf_len] = byte; + if (cmux->receive_buf_len < cmux->receive_buf_size) { + cmux->receive_buf[cmux->receive_buf_len] = byte; + } cmux->receive_buf_len++; /* Check if datalen reached */ if (cmux->frame.data_len == cmux->receive_buf_len) { /* Await FCS */ cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_FCS; - break; } - /* Check if receive buffer overrun */ - if (cmux->receive_buf_len == cmux->receive_buf_size) { - LOG_WRN("Receive buf overrun"); + break; - /* Drop frame */ - cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_EOF; + case MODEM_CMUX_RECEIVE_STATE_FCS: + if (cmux->receive_buf_len > cmux->receive_buf_size) { + LOG_WRN("Receive buffer overrun (%u > %u)", + cmux->receive_buf_len, cmux->receive_buf_size); + cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_DROP; break; } - break; - - case MODEM_CMUX_RECEIVE_STATE_FCS: /* Compute FCS */ if (cmux->frame.type == MODEM_CMUX_FRAME_TYPE_UIH) { fcs = 0xFF - crc8(cmux->frame_header, cmux->frame_header_len, From 6e0bea15c4f56c811c9d30f826d53aca137793a6 Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 14 Feb 2024 06:09:57 +0200 Subject: [PATCH 1449/1623] [nrf fromlist] modem: chat: fix init assert Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68651 Use the proper variable. Signed-off-by: Tomi Fontanilles --- subsys/modem/modem_chat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/modem/modem_chat.c b/subsys/modem/modem_chat.c index b2d63b05e9e..c689ff2e0ab 100644 --- a/subsys/modem/modem_chat.c +++ b/subsys/modem/modem_chat.c @@ -708,7 +708,7 @@ int modem_chat_init(struct modem_chat *chat, const struct modem_chat_config *con __ASSERT_NO_MSG(config->argv_size > 0); __ASSERT_NO_MSG(config->delimiter != NULL); __ASSERT_NO_MSG(config->delimiter_size > 0); - __ASSERT_NO_MSG(!((config->filter == NULL) && (config->filter > 0))); + __ASSERT_NO_MSG(!((config->filter == NULL) && (config->filter_size > 0))); __ASSERT_NO_MSG(!((config->unsol_matches == NULL) && (config->unsol_matches_size > 0))); memset(chat, 0x00, sizeof(*chat)); From 82f7e2300acc1602c8276fdcb4056fce63a2f9a0 Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 14 Feb 2024 06:36:29 +0200 Subject: [PATCH 1450/1623] [nrf fromlist] modem: pipe: add warning to synchronous pipe open/close functions Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68651 This might be useful to those not familiar with how they work. Signed-off-by: Tomi Fontanilles --- include/zephyr/modem/pipe.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/zephyr/modem/pipe.h b/include/zephyr/modem/pipe.h index 70a37302273..60e877e44a3 100644 --- a/include/zephyr/modem/pipe.h +++ b/include/zephyr/modem/pipe.h @@ -98,6 +98,10 @@ void modem_pipe_init(struct modem_pipe *pipe, void *data, struct modem_pipe_api * * @retval 0 if pipe was successfully opened or was already open * @retval -errno code otherwise + * + * @warning Be cautious when using this synchronous version of the call. + * It may block the calling thread, which in the case of the system workqueue + * can result in a deadlock until this call times out waiting for the pipe to be open. */ int modem_pipe_open(struct modem_pipe *pipe); @@ -170,6 +174,10 @@ void modem_pipe_release(struct modem_pipe *pipe); * * @retval 0 if pipe open was called closed or pipe was already closed * @retval -errno code otherwise + * + * @warning Be cautious when using this synchronous version of the call. + * It may block the calling thread, which in the case of the system workqueue + * can result in a deadlock until this call times out waiting for the pipe to be closed. */ int modem_pipe_close(struct modem_pipe *pipe); From b6577fd6ff96da8853a5b193a31801e996ff143c Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 14 Feb 2024 07:24:26 +0200 Subject: [PATCH 1451/1623] [nrf fromlist] drivers: modem_cellular: allow variable length chat delimiter and filter Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68981 To allow for differences between modems. Signed-off-by: Tomi Fontanilles --- drivers/modem/modem_cellular.c | 46 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index f5e099cd08c..35b05602a74 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -96,8 +96,8 @@ struct modem_cellular_data { /* Modem chat */ struct modem_chat chat; uint8_t chat_receive_buf[128]; - uint8_t chat_delimiter[1]; - uint8_t chat_filter[1]; + uint8_t *chat_delimiter; + uint8_t *chat_filter; uint8_t *chat_argv[32]; /* Status */ @@ -424,9 +424,9 @@ MODEM_CHAT_MATCH_DEFINE(imei_match, "", "", modem_cellular_chat_on_imei); MODEM_CHAT_MATCH_DEFINE(cgmm_match, "", "", modem_cellular_chat_on_cgmm); MODEM_CHAT_MATCH_DEFINE(csq_match, "+CSQ: ", ",", modem_cellular_chat_on_csq); MODEM_CHAT_MATCH_DEFINE(cesq_match, "+CESQ: ", ",", modem_cellular_chat_on_cesq); -MODEM_CHAT_MATCH_DEFINE(cimi_match, "", "", modem_cellular_chat_on_imsi); -MODEM_CHAT_MATCH_DEFINE(cgmi_match, "", "", modem_cellular_chat_on_cgmi); -MODEM_CHAT_MATCH_DEFINE(cgmr_match, "", "", modem_cellular_chat_on_cgmr); +MODEM_CHAT_MATCH_DEFINE(cimi_match __maybe_unused, "", "", modem_cellular_chat_on_imsi); +MODEM_CHAT_MATCH_DEFINE(cgmi_match __maybe_unused, "", "", modem_cellular_chat_on_cgmi); +MODEM_CHAT_MATCH_DEFINE(cgmr_match __maybe_unused, "", "", modem_cellular_chat_on_cgmr); MODEM_CHAT_MATCHES_DEFINE(unsol_matches, MODEM_CHAT_MATCH("+CREG: ", ",", modem_cellular_chat_on_cxreg), @@ -1513,9 +1513,9 @@ static int modem_cellular_init(const struct device *dev) .receive_buf = data->chat_receive_buf, .receive_buf_size = ARRAY_SIZE(data->chat_receive_buf), .delimiter = data->chat_delimiter, - .delimiter_size = ARRAY_SIZE(data->chat_delimiter), + .delimiter_size = strlen(data->chat_delimiter), .filter = data->chat_filter, - .filter_size = ARRAY_SIZE(data->chat_filter), + .filter_size = strlen(data->chat_filter), .argv = data->chat_argv, .argv_size = ARRAY_SIZE(data->chat_argv), .unsol_matches = unsol_matches, @@ -1939,8 +1939,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ \ static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \ - .chat_delimiter = {'\r'}, \ - .chat_filter = {'\n'}, \ + .chat_delimiter = "\r", \ + .chat_filter = "\n", \ .ppp = &MODEM_CELLULAR_INST_NAME(ppp, inst), \ }; \ \ @@ -1968,8 +1968,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ \ static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \ - .chat_delimiter = {'\r'}, \ - .chat_filter = {'\n'}, \ + .chat_delimiter = "\r", \ + .chat_filter = "\n", \ .ppp = &MODEM_CELLULAR_INST_NAME(ppp, inst), \ }; \ \ @@ -1997,8 +1997,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ \ static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \ - .chat_delimiter = {'\r'}, \ - .chat_filter = {'\n'}, \ + .chat_delimiter = "\r", \ + .chat_filter = "\n", \ .ppp = &MODEM_CELLULAR_INST_NAME(ppp, inst), \ }; \ \ @@ -2026,8 +2026,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ \ static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \ - .chat_delimiter = {'\r'}, \ - .chat_filter = {'\n'}, \ + .chat_delimiter = "\r", \ + .chat_filter = "\n", \ .ppp = &MODEM_CELLULAR_INST_NAME(ppp, inst), \ }; \ \ @@ -2055,8 +2055,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ \ static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \ - .chat_delimiter = {'\r'}, \ - .chat_filter = {'\n'}, \ + .chat_delimiter = "\r", \ + .chat_filter = "\n", \ .ppp = &MODEM_CELLULAR_INST_NAME(ppp, inst), \ }; \ \ @@ -2084,8 +2084,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ \ static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \ - .chat_delimiter = {'\r'}, \ - .chat_filter = {'\n'}, \ + .chat_delimiter = "\r", \ + .chat_filter = "\n", \ .ppp = &MODEM_CELLULAR_INST_NAME(ppp, inst), \ }; \ \ @@ -2114,8 +2114,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ \ static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \ - .chat_delimiter = {'\r'}, \ - .chat_filter = {'\n'}, \ + .chat_delimiter = "\r", \ + .chat_filter = "\n", \ .ppp = &MODEM_CELLULAR_INST_NAME(ppp, inst), \ }; \ \ @@ -2143,8 +2143,8 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \ \ static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \ - .chat_delimiter = {'\r'}, \ - .chat_filter = {'\n'}, \ + .chat_delimiter = "\r", \ + .chat_filter = "\n", \ .ppp = &MODEM_CELLULAR_INST_NAME(ppp, inst), \ }; \ \ From 6b2f8b1939e1028c5bf808901709429ca4d10361 Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 14 Feb 2024 08:12:34 +0200 Subject: [PATCH 1452/1623] [nrf fromlist] drivers: modem_cellular: make the buffer sizes configurable Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68981 To allow fine tuning and accommodate modem differences. Signed-off-by: Tomi Fontanilles --- drivers/modem/Kconfig.cellular | 14 ++++++++++++++ drivers/modem/modem_cellular.c | 15 ++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/drivers/modem/Kconfig.cellular b/drivers/modem/Kconfig.cellular index 0460cda8d96..599a8a61138 100644 --- a/drivers/modem/Kconfig.cellular +++ b/drivers/modem/Kconfig.cellular @@ -36,4 +36,18 @@ config MODEM_CELLULAR_PERIODIC_SCRIPT_MS int "Periodic script interval in milliseconds" default 2000 +config MODEM_CELLULAR_UART_BUFFER_SIZES + int "The UART receive and transmit buffer sizes in bytes." + default 512 + +config MODEM_CELLULAR_CMUX_MAX_FRAME_SIZE + int "The maximum CMUX frame size in bytes." + default 128 + help + This value affects the size of buffers used to receive and transmit CMUX frames. + +config MODEM_CELLULAR_CHAT_BUFFER_SIZES + int "The size of the buffers used for the chat scripts in bytes." + default 128 + endif diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index 35b05602a74..63430d45c1a 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -79,23 +79,24 @@ struct modem_cellular_data { /* UART backend */ struct modem_pipe *uart_pipe; struct modem_backend_uart uart_backend; - uint8_t uart_backend_receive_buf[512]; - uint8_t uart_backend_transmit_buf[512]; + uint8_t uart_backend_receive_buf[CONFIG_MODEM_CELLULAR_UART_BUFFER_SIZES]; + uint8_t uart_backend_transmit_buf[CONFIG_MODEM_CELLULAR_UART_BUFFER_SIZES]; /* CMUX */ struct modem_cmux cmux; - uint8_t cmux_receive_buf[128]; - uint8_t cmux_transmit_buf[256]; + uint8_t cmux_receive_buf[CONFIG_MODEM_CELLULAR_CMUX_MAX_FRAME_SIZE]; + uint8_t cmux_transmit_buf[2 * CONFIG_MODEM_CELLULAR_CMUX_MAX_FRAME_SIZE]; struct modem_cmux_dlci dlci1; struct modem_cmux_dlci dlci2; struct modem_pipe *dlci1_pipe; struct modem_pipe *dlci2_pipe; - uint8_t dlci1_receive_buf[128]; - uint8_t dlci2_receive_buf[256]; + uint8_t dlci1_receive_buf[CONFIG_MODEM_CELLULAR_CMUX_MAX_FRAME_SIZE]; + /* DLCI 2 is only used for chat scripts. */ + uint8_t dlci2_receive_buf[CONFIG_MODEM_CELLULAR_CHAT_BUFFER_SIZES]; /* Modem chat */ struct modem_chat chat; - uint8_t chat_receive_buf[128]; + uint8_t chat_receive_buf[CONFIG_MODEM_CELLULAR_CHAT_BUFFER_SIZES]; uint8_t *chat_delimiter; uint8_t *chat_filter; uint8_t *chat_argv[32]; From 278f8b8e2ec347a5381165f4a533e6bbc28308ef Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 14 Feb 2024 08:43:10 +0200 Subject: [PATCH 1453/1623] [nrf fromlist] samples: net: cellular_modem: small improvements Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68981 - It now uses the first PPP network interface instead of the default network interface. - Logs are added/improved. - Potentially unused modem_chat matches are declared as such to suppress compiler warnings. Signed-off-by: Tomi Fontanilles --- samples/net/cellular_modem/README.rst | 2 +- samples/net/cellular_modem/src/main.c | 63 ++++++++++++++++----------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/samples/net/cellular_modem/README.rst b/samples/net/cellular_modem/README.rst index 384d8b3bef5..b845b2e37d8 100644 --- a/samples/net/cellular_modem/README.rst +++ b/samples/net/cellular_modem/README.rst @@ -18,7 +18,7 @@ Notes This sample uses the devicetree alias modem to identify the modem instance to use. The sample also presumes that -the modem driver creates the only network interface. +the modem driver creates the only PPP network interface. Setup ***** diff --git a/samples/net/cellular_modem/src/main.c b/samples/net/cellular_modem/src/main.c index 95e1c45f160..543f8d6d711 100644 --- a/samples/net/cellular_modem/src/main.c +++ b/samples/net/cellular_modem/src/main.c @@ -83,7 +83,7 @@ static int sample_dns_request(void) return 0; } -int sample_echo_packet(struct sockaddr *ai_addr, socklen_t ai_addrlen) +int sample_echo_packet(struct sockaddr *ai_addr, socklen_t ai_addrlen, uint16_t *port) { int ret; int socket_fd; @@ -96,22 +96,16 @@ int sample_echo_packet(struct sockaddr *ai_addr, socklen_t ai_addrlen) socket_fd = zsock_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (socket_fd < 0) { - printk("Failed to open socket\n"); + printk("Failed to open socket (%d)\n", errno); return -1; } printk("Socket opened\n"); - if (ai_addr->sa_family == AF_INET) { - net_sin(ai_addr)->sin_port = htons(SAMPLE_TEST_ENDPOINT_UDP_ECHO_PORT); - } else if (ai_addr->sa_family == AF_INET6) { - net_sin6(ai_addr)->sin6_port = htons(SAMPLE_TEST_ENDPOINT_UDP_ECHO_PORT); - } else { - printk("Unsupported address family\n"); - return -1; - } + *port = htons(SAMPLE_TEST_ENDPOINT_UDP_ECHO_PORT); for (uint32_t i = 0; i < SAMPLE_TEST_ECHO_PACKETS; i++) { + printk("Sending echo packet\n"); send_start_ms = k_uptime_get_32(); ret = zsock_sendto(socket_fd, sample_test_packet, sizeof(sample_test_packet), 0, @@ -122,6 +116,7 @@ int sample_echo_packet(struct sockaddr *ai_addr, socklen_t ai_addrlen) continue; } + printk("Receiving echoed packet"); ret = zsock_recv(socket_fd, sample_recv_buffer, sizeof(sample_recv_buffer), 0); if (ret != sizeof(sample_test_packet)) { printk("Echoed sample test packet has incorrect size\n"); @@ -160,7 +155,7 @@ int sample_echo_packet(struct sockaddr *ai_addr, socklen_t ai_addrlen) } -int sample_transmit_packets(struct sockaddr *ai_addr, socklen_t ai_addrlen) +int sample_transmit_packets(struct sockaddr *ai_addr, socklen_t ai_addrlen, uint16_t *port) { int ret; int socket_fd; @@ -180,14 +175,7 @@ int sample_transmit_packets(struct sockaddr *ai_addr, socklen_t ai_addrlen) printk("Socket opened\n"); - if (ai_addr->sa_family == AF_INET) { - net_sin(ai_addr)->sin_port = htons(SAMPLE_TEST_ENDPOINT_UDP_RECEIVE_PORT); - } else if (ai_addr->sa_family == AF_INET6) { - net_sin6(ai_addr)->sin6_port = htons(SAMPLE_TEST_ENDPOINT_UDP_RECEIVE_PORT); - } else { - printk("Unsupported address family\n"); - return -1; - } + *port = htons(SAMPLE_TEST_ENDPOINT_UDP_RECEIVE_PORT); printk("Sending %u packets\n", SAMPLE_TEST_TRANSMIT_PACKETS); send_start_ms = k_uptime_get_32(); @@ -232,7 +220,9 @@ int sample_transmit_packets(struct sockaddr *ai_addr, socklen_t ai_addrlen) int main(void) { + struct net_if *const iface = net_if_get_first_by_type(&NET_L2_GET_NAME(PPP)); uint32_t raised_event; + uint16_t *port; const void *info; size_t info_len; int ret; @@ -243,14 +233,14 @@ int main(void) pm_device_action_run(modem, PM_DEVICE_ACTION_RESUME); printk("Bring up network interface\n"); - ret = net_if_up(net_if_get_default()); + ret = net_if_up(iface); if (ret < 0) { printk("Failed to bring up network interface\n"); return -1; } printk("Waiting for L4 connected\n"); - ret = net_mgmt_event_wait_on_iface(net_if_get_default(), + ret = net_mgmt_event_wait_on_iface(iface, NET_EVENT_L4_CONNECTED, &raised_event, &info, &info_len, K_SECONDS(120)); @@ -260,7 +250,7 @@ int main(void) } printk("Waiting for DNS server added\n"); - ret = net_mgmt_event_wait_on_iface(net_if_get_default(), + ret = net_mgmt_event_wait_on_iface(iface, NET_EVENT_DNS_SERVER_ADD, &raised_event, &info, &info_len, K_SECONDS(10)); @@ -271,8 +261,29 @@ int main(void) return -1; } + { + char ip_str[INET6_ADDRSTRLEN]; + const void *src; + + switch (sample_test_dns_addrinfo.ai_addr.sa_family) { + case AF_INET: + src = &net_sin(&sample_test_dns_addrinfo.ai_addr)->sin_addr; + port = &net_sin(&sample_test_dns_addrinfo.ai_addr)->sin_port; + break; + case AF_INET6: + src = &net_sin6(&sample_test_dns_addrinfo.ai_addr)->sin6_addr; + port = &net_sin6(&sample_test_dns_addrinfo.ai_addr)->sin6_port; + break; + default: + printk("Unsupported address family\n"); + return -1; + } + inet_ntop(sample_test_dns_addrinfo.ai_addr.sa_family, src, ip_str, sizeof(ip_str)); + printk("Resolved to %s\n", ip_str); + } + ret = sample_echo_packet(&sample_test_dns_addrinfo.ai_addr, - sample_test_dns_addrinfo.ai_addrlen); + sample_test_dns_addrinfo.ai_addrlen, port); if (ret < 0) { printk("Failed to send echo\n"); @@ -280,7 +291,7 @@ int main(void) } ret = sample_transmit_packets(&sample_test_dns_addrinfo.ai_addr, - sample_test_dns_addrinfo.ai_addrlen); + sample_test_dns_addrinfo.ai_addrlen, port); if (ret < 0) { printk("Failed to send packets\n"); @@ -295,6 +306,8 @@ int main(void) } pm_device_action_run(modem, PM_DEVICE_ACTION_RESUME); + + printk("Waiting for L4 connected\n"); ret = net_mgmt_event_wait_on_iface(net_if_get_default(), NET_EVENT_L4_CONNECTED, &raised_event, &info, &info_len, K_SECONDS(60)); @@ -305,7 +318,7 @@ int main(void) } ret = sample_echo_packet(&sample_test_dns_addrinfo.ai_addr, - sample_test_dns_addrinfo.ai_addrlen); + sample_test_dns_addrinfo.ai_addrlen, port); if (ret < 0) { printk("Failed to send echo after restart\n"); From f41b357a25cc302f9c2bcd37fb7976306f04f027 Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 14 Feb 2024 10:27:55 +0200 Subject: [PATCH 1454/1623] [nrf fromlist] drivers: modem_cellular: add nRF91 series (w/ SLM) Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68981 The nRF91 series devices, when running the Serial LTE Modem (SLM) application starting with nRF Connect SDK 2.6.0, can now be used as standalone modems via the generic modem_cellular driver. A configuration to run the cellular_modem sample on the nRF9160 DK (plugged in to another nRF91 series device running SLM) is provided. Signed-off-by: Tomi Fontanilles --- drivers/modem/Kconfig.cellular | 3 +- drivers/modem/modem_cellular.c | 67 +++++++++++++++++++ dts/bindings/modem/nordic,nrf91-slm.yaml | 9 +++ .../boards/nrf9160dk_nrf9160_ns.conf | 16 +++++ .../boards/nrf9160dk_nrf9160_ns.overlay | 34 ++++++++++ tests/drivers/build_all/modem/uart.dtsi | 6 ++ 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 dts/bindings/modem/nordic,nrf91-slm.yaml create mode 100644 samples/net/cellular_modem/boards/nrf9160dk_nrf9160_ns.conf create mode 100644 samples/net/cellular_modem/boards/nrf9160dk_nrf9160_ns.overlay diff --git a/drivers/modem/Kconfig.cellular b/drivers/modem/Kconfig.cellular index 599a8a61138..aacf4449d28 100644 --- a/drivers/modem/Kconfig.cellular +++ b/drivers/modem/Kconfig.cellular @@ -15,7 +15,8 @@ config MODEM_CELLULAR depends on (DT_HAS_QUECTEL_BG95_ENABLED || DT_HAS_ZEPHYR_GSM_PPP_ENABLED || \ DT_HAS_SIMCOM_SIM7080_ENABLED || DT_HAS_U_BLOX_SARA_R4_ENABLED || \ DT_HAS_U_BLOX_SARA_R5_ENABLED || DT_HAS_SWIR_HL7800_ENABLED || \ - DT_HAS_TELIT_ME910G1_ENABLED || DT_HAS_QUECTEL_EG25_G_ENABLED) + DT_HAS_TELIT_ME910G1_ENABLED || DT_HAS_QUECTEL_EG25_G_ENABLED || \ + DT_HAS_NORDIC_NRF91_SLM_ENABLED) help This driver uses the generic 3gpp AT commands, along with the standard protocols CMUX and PPP, to configure diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index 63430d45c1a..ed4e998fec3 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -1933,6 +1933,41 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, modem_cellular_chat_callback_handler, 4); #endif +#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf91_slm) +MODEM_CHAT_SCRIPT_CMDS_DEFINE(nordic_nrf91_slm_init_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP_MULT("AT", allow_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CMEE=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG?", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGSN", imei_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMM", cgmm_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMI", cgmi_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGMR", cgmr_match), + MODEM_CHAT_SCRIPT_CMD_RESP("", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT#XCMUX=1", ok_match)); + +MODEM_CHAT_SCRIPT_DEFINE(nordic_nrf91_slm_init_chat_script, nordic_nrf91_slm_init_chat_script_cmds, + abort_matches, modem_cellular_chat_callback_handler, 10); + +MODEM_CHAT_SCRIPT_CMDS_DEFINE(nordic_nrf91_slm_dial_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CFUN=4", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CFUN=1", ok_match), + MODEM_CHAT_SCRIPT_CMD_RESP("AT#XCMUX=2", ok_match)); + +MODEM_CHAT_SCRIPT_DEFINE(nordic_nrf91_slm_dial_chat_script, nordic_nrf91_slm_dial_chat_script_cmds, + dial_abort_matches, modem_cellular_chat_callback_handler, 10); + +MODEM_CHAT_SCRIPT_CMDS_DEFINE(nordic_nrf91_slm_periodic_chat_script_cmds, + MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG?", ok_match)); + +MODEM_CHAT_SCRIPT_DEFINE(nordic_nrf91_slm_periodic_chat_script, + nordic_nrf91_slm_periodic_chat_script_cmds, abort_matches, + modem_cellular_chat_callback_handler, 4); +#endif + #define MODEM_CELLULAR_INST_NAME(name, inst) \ _CONCAT(_CONCAT(_CONCAT(name, _), DT_DRV_COMPAT), inst) @@ -2169,6 +2204,34 @@ MODEM_CHAT_SCRIPT_DEFINE(telit_me910g1_periodic_chat_script, &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, \ &modem_cellular_api); +#define MODEM_CELLULAR_DEVICE_NORDIC_NRF91_SLM(inst) \ + MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 1500); \ + \ + static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \ + .chat_delimiter = "\r\n", \ + .ppp = &MODEM_CELLULAR_INST_NAME(ppp, inst), \ + }; \ + \ + static struct modem_cellular_config MODEM_CELLULAR_INST_NAME(config, inst) = { \ + .uart = DEVICE_DT_GET(DT_INST_BUS(inst)), \ + .power_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, mdm_power_gpios, {}), \ + .reset_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, mdm_reset_gpios, {}), \ + .power_pulse_duration_ms = 100, \ + .reset_pulse_duration_ms = 100, \ + .startup_time_ms = 2000, \ + .shutdown_time_ms = 3000, \ + .init_chat_script = &nordic_nrf91_slm_init_chat_script, \ + .dial_chat_script = &nordic_nrf91_slm_dial_chat_script, \ + .periodic_chat_script = &nordic_nrf91_slm_periodic_chat_script, \ + }; \ + \ + PM_DEVICE_DT_INST_DEFINE(inst, modem_cellular_pm_action); \ + \ + DEVICE_DT_INST_DEFINE(inst, modem_cellular_init, PM_DEVICE_DT_INST_GET(inst), \ + &MODEM_CELLULAR_INST_NAME(data, inst), \ + &MODEM_CELLULAR_INST_NAME(config, inst), POST_KERNEL, 99, \ + &modem_cellular_api); + #define DT_DRV_COMPAT quectel_bg95 DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_QUECTEL_BG95) #undef DT_DRV_COMPAT @@ -2200,3 +2263,7 @@ DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_SWIR_HL7800) #define DT_DRV_COMPAT telit_me910g1 DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_TELIT_ME910G1) #undef DT_DRV_COMPAT + +#define DT_DRV_COMPAT nordic_nrf91_slm +DT_INST_FOREACH_STATUS_OKAY(MODEM_CELLULAR_DEVICE_NORDIC_NRF91_SLM) +#undef DT_DRV_COMPAT diff --git a/dts/bindings/modem/nordic,nrf91-slm.yaml b/dts/bindings/modem/nordic,nrf91-slm.yaml new file mode 100644 index 00000000000..3f06696197d --- /dev/null +++ b/dts/bindings/modem/nordic,nrf91-slm.yaml @@ -0,0 +1,9 @@ +description: Nordic nRF91 series running the Serial LTE Modem application + +compatible: "nordic,nrf91-slm" + +include: uart-device.yaml + +properties: + mdm-power-gpios: + type: phandle-array diff --git a/samples/net/cellular_modem/boards/nrf9160dk_nrf9160_ns.conf b/samples/net/cellular_modem/boards/nrf9160dk_nrf9160_ns.conf new file mode 100644 index 00000000000..441a5395ca1 --- /dev/null +++ b/samples/net/cellular_modem/boards/nrf9160dk_nrf9160_ns.conf @@ -0,0 +1,16 @@ +CONFIG_UART_ASYNC_API=y + +# Align with the Serial LTE Modem (SLM) application. +CONFIG_MODEM_CELLULAR_CMUX_MAX_FRAME_SIZE=1500 +CONFIG_MODEM_CELLULAR_UART_BUFFER_SIZES=1500 + +# Allow large UART TXs to go through @115200. +CONFIG_MODEM_BACKEND_UART_ASYNC_TRANSMIT_TIMEOUT_MS=200 + +# Prevent sockets getting offloaded to the modem. +CONFIG_NET_SOCKETS_OFFLOAD=n + +# Print logs and printk() output on uart0. +CONFIG_LOG=y +CONFIG_LOG_BACKEND_UART=y +CONFIG_MODEM_LOG_LEVEL_DBG=y diff --git a/samples/net/cellular_modem/boards/nrf9160dk_nrf9160_ns.overlay b/samples/net/cellular_modem/boards/nrf9160dk_nrf9160_ns.overlay new file mode 100644 index 00000000000..44ce80601a1 --- /dev/null +++ b/samples/net/cellular_modem/boards/nrf9160dk_nrf9160_ns.overlay @@ -0,0 +1,34 @@ +/ { + aliases { + modem = &modem; + }; +}; + +&uart1 { + compatible = "nordic,nrf-uarte"; + current-speed = <115200>; + hw-flow-control; + status = "okay"; + + pinctrl-0 = <&uart1_default_alt>; + + modem: modem { + compatible = "nordic,nrf91-slm"; + status = "okay"; + mdm-power-gpios = <&gpio0 20 GPIO_ACTIVE_LOW>; + }; +}; + +&pinctrl { + uart1_default_alt: uart1_default_alt { + group1 { + psels = ; + bias-pull-up; + }; + group2 { + psels = , + , + ; + }; + }; +}; diff --git a/tests/drivers/build_all/modem/uart.dtsi b/tests/drivers/build_all/modem/uart.dtsi index 3d649a2ff60..08da2c325d3 100644 --- a/tests/drivers/build_all/modem/uart.dtsi +++ b/tests/drivers/build_all/modem/uart.dtsi @@ -70,3 +70,9 @@ test_telit_me910g1: telit_me910g1 { test_esp_at: esp_at { compatible = "espressif,esp-at"; }; + +test_nordic_nrf91_slm: nordic_nrf91_slm { + compatible = "nordic,nrf91-slm"; + + mdm-power-gpios = <&test_gpio 0 0>; +}; From 2c8d14ac87245a4fb15b6ccaee659e3205e67f65 Mon Sep 17 00:00:00 2001 From: Rubin Gerritsen Date: Mon, 12 Feb 2024 14:20:43 +0100 Subject: [PATCH 1455/1623] [nrf fromlist] samples: Bluetooth: Only connect to devices with rssi below -50 When the Bluetooth central samples in an open air environment it is very likely that there are multiple devices nearby with a received signal strength stronger than -70 dBm. To avoid connecting to the wrong device, make the check stricter. For tests using those samples, the NtNcable attenuation is changed from the default 60 dBm to 40 dBm to satisfy the new requirement. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68870 Signed-off-by: Rubin Gerritsen --- samples/bluetooth/central/src/main.c | 2 +- samples/bluetooth/central_gatt_write/src/central_gatt_write.c | 2 +- samples/bluetooth/central_iso/src/main.c | 2 +- samples/bluetooth/central_multilink/src/central_multilink.c | 2 +- samples/bluetooth/mtu_update/central/src/central_mtu_update.c | 2 +- samples/bluetooth/unicast_audio_client/src/main.c | 2 +- .../unicast_audio_client/tests_scripts/unicast_client.sh | 2 +- .../bsim/bluetooth/host/att/mtu_update/test_scripts/run_test.sh | 2 +- tests/bsim/bluetooth/ll/multiple_id/tests_scripts/multiple.sh | 2 +- tests/bsim/bluetooth/ll/throughput/tests_scripts/gatt_write.sh | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/samples/bluetooth/central/src/main.c b/samples/bluetooth/central/src/main.c index 0c88f647539..e6305ea70b6 100644 --- a/samples/bluetooth/central/src/main.c +++ b/samples/bluetooth/central/src/main.c @@ -43,7 +43,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, printk("Device found: %s (RSSI %d)\n", addr_str, rssi); /* connect only to devices in close proximity */ - if (rssi < -70) { + if (rssi < -50) { return; } diff --git a/samples/bluetooth/central_gatt_write/src/central_gatt_write.c b/samples/bluetooth/central_gatt_write/src/central_gatt_write.c index 385877ec280..fada73d9d94 100644 --- a/samples/bluetooth/central_gatt_write/src/central_gatt_write.c +++ b/samples/bluetooth/central_gatt_write/src/central_gatt_write.c @@ -35,7 +35,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, } /* connect only to devices in close proximity */ - if (rssi < -70) { + if (rssi < -50) { return; } diff --git a/samples/bluetooth/central_iso/src/main.c b/samples/bluetooth/central_iso/src/main.c index a0062fcfa73..20c848cb121 100644 --- a/samples/bluetooth/central_iso/src/main.c +++ b/samples/bluetooth/central_iso/src/main.c @@ -99,7 +99,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, printk("Device found: %s (RSSI %d)\n", addr_str, rssi); /* connect only to devices in close proximity */ - if (rssi < -70) { + if (rssi < -50) { return; } diff --git a/samples/bluetooth/central_multilink/src/central_multilink.c b/samples/bluetooth/central_multilink/src/central_multilink.c index ea9afbb977c..197021efe97 100644 --- a/samples/bluetooth/central_multilink/src/central_multilink.c +++ b/samples/bluetooth/central_multilink/src/central_multilink.c @@ -70,7 +70,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, printk("Device found: %s (RSSI %d)\n", addr_str, rssi); /* connect only to devices in close proximity */ - if (rssi < -70) { + if (rssi < -50) { return; } diff --git a/samples/bluetooth/mtu_update/central/src/central_mtu_update.c b/samples/bluetooth/mtu_update/central/src/central_mtu_update.c index 046446882dc..9db4b507d3c 100644 --- a/samples/bluetooth/mtu_update/central/src/central_mtu_update.c +++ b/samples/bluetooth/mtu_update/central/src/central_mtu_update.c @@ -131,7 +131,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, printk("Device found: %s (RSSI %d)\n", addr_str, rssi); /* connect only to devices in close proximity */ - if (rssi < -70) { + if (rssi < -50) { return; } diff --git a/samples/bluetooth/unicast_audio_client/src/main.c b/samples/bluetooth/unicast_audio_client/src/main.c index 3953bee99f0..974d4f825f8 100644 --- a/samples/bluetooth/unicast_audio_client/src/main.c +++ b/samples/bluetooth/unicast_audio_client/src/main.c @@ -480,7 +480,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, printk("Device found: %s (RSSI %d)\n", addr_str, rssi); /* connect only to devices in close proximity */ - if (rssi < -70) { + if (rssi < -50) { return; } diff --git a/tests/bsim/bluetooth/audio_samples/unicast_audio_client/tests_scripts/unicast_client.sh b/tests/bsim/bluetooth/audio_samples/unicast_audio_client/tests_scripts/unicast_client.sh index cc92cda1328..6387b68af7f 100755 --- a/tests/bsim/bluetooth/audio_samples/unicast_audio_client/tests_scripts/unicast_client.sh +++ b/tests/bsim/bluetooth/audio_samples/unicast_audio_client/tests_scripts/unicast_client.sh @@ -24,6 +24,6 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_samples_unicast_audio_client_pr -testid=unicast_client Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=20e6 $@ + -D=2 -sim_length=20e6 $@ -argschannel -at=40 wait_for_background_jobs #Wait for all programs in background and return != 0 if any fails diff --git a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/run_test.sh b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/run_test.sh index 087aa9385d4..255f6f4f9fa 100755 --- a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/run_test.sh +++ b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/run_test.sh @@ -21,6 +21,6 @@ Execute "$peripheral_exe" \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -RealEncryption=1 Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ + -D=2 -sim_length=60e6 $@ -argschannel -at=40 wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/multiple_id/tests_scripts/multiple.sh b/tests/bsim/bluetooth/ll/multiple_id/tests_scripts/multiple.sh index 1bdd2874916..cfbac8c313f 100755 --- a/tests/bsim/bluetooth/ll/multiple_id/tests_scripts/multiple.sh +++ b/tests/bsim/bluetooth/ll/multiple_id/tests_scripts/multiple.sh @@ -18,6 +18,6 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_multiple_id_prj_conf\ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=4500e6 $@ + -D=2 -sim_length=4500e6 $@ -argschannel -at=40 wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/throughput/tests_scripts/gatt_write.sh b/tests/bsim/bluetooth/ll/throughput/tests_scripts/gatt_write.sh index df82f924fb8..64a3dabac3b 100755 --- a/tests/bsim/bluetooth/ll/throughput/tests_scripts/gatt_write.sh +++ b/tests/bsim/bluetooth/ll/throughput/tests_scripts/gatt_write.sh @@ -17,6 +17,6 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_throughput_prj_conf\ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ + -D=2 -sim_length=60e6 $@ -argschannel -at=40 wait_for_background_jobs From b1980edde9dd32c5decc5c281c7afb5c10a24fce Mon Sep 17 00:00:00 2001 From: Rubin Gerritsen Date: Mon, 12 Feb 2024 14:25:53 +0100 Subject: [PATCH 1456/1623] [nrf fromlist] samples: bluetooth: central_iso: Remove the CONFIG_BT_SMP=y Some SoCs in the nRF52 series do not support encrypting and decrypting isochronous channels packets. To make it easier to get started with the central_iso sample, we want to turn of SMP by default. Without this config, the sample still serves its purpose. Encrypting the isochronous channel is as simple as enabling BT_SMP. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68870 Signed-off-by: Rubin Gerritsen --- samples/bluetooth/central_iso/prj.conf | 8 -------- 1 file changed, 8 deletions(-) diff --git a/samples/bluetooth/central_iso/prj.conf b/samples/bluetooth/central_iso/prj.conf index ab5a202401f..81264161a5c 100644 --- a/samples/bluetooth/central_iso/prj.conf +++ b/samples/bluetooth/central_iso/prj.conf @@ -1,11 +1,3 @@ CONFIG_BT=y CONFIG_LOG=y CONFIG_BT_ISO_CENTRAL=y -CONFIG_BT_SMP=y - -CONFIG_BT_KEYS_OVERWRITE_OLDEST=y -CONFIG_BT_SETTINGS=y -CONFIG_FLASH=y -CONFIG_FLASH_MAP=y -CONFIG_NVS=y -CONFIG_SETTINGS=y From eb59f8d92c7a3aedbf33fcbefb25665da5128a73 Mon Sep 17 00:00:00 2001 From: Rubin Gerritsen Date: Mon, 12 Feb 2024 14:29:42 +0100 Subject: [PATCH 1457/1623] [nrf fromlist] samples: bluetooth: iso: Extend sample documentation Extend the sample documentation for the central and peripheral iso samples so that they become easier to get started with. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68870 Signed-off-by: Rubin Gerritsen --- samples/bluetooth/central_iso/README.rst | 31 ++++++++++--- samples/bluetooth/peripheral_iso/README.rst | 48 +++++++++++++++++++-- 2 files changed, 68 insertions(+), 11 deletions(-) diff --git a/samples/bluetooth/central_iso/README.rst b/samples/bluetooth/central_iso/README.rst index 4965ea96b3b..13e6f56d778 100644 --- a/samples/bluetooth/central_iso/README.rst +++ b/samples/bluetooth/central_iso/README.rst @@ -6,12 +6,12 @@ Bluetooth: Central ISO Overview ******** -Application demonstrating a connected isochronous channel functional as the -central role, by scanning for peripheral devices and establishing a connection -to the first one with a strong enough signal. -The application then attempts to setup a connected isochronous channel and -starts sending data. +This sample demonstrates how to use an isochronous channel as a central. +The sample scans for a peripheral, establishes a connection, and sets up a connected isochronous channel to it. +Once the isochronous channel is connected, isochronous data is transferred to the peer device every 10 milliseconds. +It is recommended to run this sample together with the :ref:`Bluetooth: Peripheral ISO ` sample. +To run the sample with an encrypted isochronous channel, enable :kconfig:option:`CONFIG_BT_SMP`. Requirements ************ @@ -19,11 +19,28 @@ Requirements * BlueZ running on the host, or * A board with Bluetooth Low Energy 5.2 support * A Bluetooth Controller and board that supports setting - CONFIG_BT_CTLR_CENTRAL_ISO=y + :kconfig:option:`CONFIG_BT_CTLR_CENTRAL_ISO`. Building and Running ******************** This sample can be found under :zephyr_file:`samples/bluetooth/central_iso` in the Zephyr tree. -See :ref:`bluetooth samples section ` for details. +1. Start the application. + In the terminal window, check that it is scanning for other devices. + + Bluetooth initialized + Scanning successfully started + Device found: D3:3A:5D:F5:73:33 (random) (RSSI -78) + Device found: 70:7B:F4:2B:76:AD (random) (RSSI -68) + Device found: 65:CF:20:0D:CB:9D (random) (RSSI -82) + +2. Observe that the device connects. + + Connected: 65:CF:20:0D:CB:9D (random) + +3. Observe that the ISO channel is connected + + ISO Channel 0x200048f8 connected + +See :ref:`bluetooth samples section ` for more details. diff --git a/samples/bluetooth/peripheral_iso/README.rst b/samples/bluetooth/peripheral_iso/README.rst index 4d5d8c1b576..d877cf3a98f 100644 --- a/samples/bluetooth/peripheral_iso/README.rst +++ b/samples/bluetooth/peripheral_iso/README.rst @@ -6,9 +6,10 @@ Bluetooth: Peripheral ISO Overview ******** -Similar to the :ref:`Peripheral ` sample, except that this application enables -support for connected isochronous (ISO) channels. - +This sample demonstrates how to use isochronous channels as a peripheral. +The sample starts advertising, waits for a central to connect to it and set up an isochronous channel. +Once the isochronous channel is set up, received isochronous data is printed out. +It is recommended to run this sample together with the :ref:`Bluetooth: Central ISO ` sample. Requirements ************ @@ -23,4 +24,43 @@ Building and Running This sample can be found under :zephyr_file:`samples/bluetooth/peripheral_iso` in the Zephyr tree. -See :ref:`bluetooth samples section ` for details. +1. Start the application. + In the terminal window, check that it is advertising. + + Bluetooth initialized + Advertising successfully started + +2. Observe that the central device connects and sets up an isochronous channel. + + Connected E8:DC:8D:B3:47:69 (random) + Incoming request from 0x20002260 + ISO Channel 0x20000698 connected + +3. Observe that incoming data is printed. + + Incoming data channel 0x20000698 len 1 + 00 + Incoming data channel 0x20000698 len 2 + 0001 + Incoming data channel 0x20000698 len 3 + 000102 + Incoming data channel 0x20000698 len 4 + 00010203 + Incoming data channel 0x20000698 len 5 + 0001020304 + Incoming data channel 0x20000698 len 6 + 000102030405 + Incoming data channel 0x20000698 len 7 + 000102...040506 + Incoming data channel 0x20000698 len 8 + 000102...050607 + Incoming data channel 0x20000698 len 9 + 000102...060708 + Incoming data channel 0x20000698 len 10 + 000102...070809 + Incoming data channel 0x20000698 len 11 + 000102...08090a + Incoming data channel 0x20000698 len 12 + 000102...090a0b + +See :ref:`bluetooth samples section ` for more details. From 3edb81c23e2fa3076bce0cac4278f119f99dc0b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Fri, 19 Jan 2024 09:11:18 +0100 Subject: [PATCH 1458/1623] [nrf fromtree] west.yml: Update uoscore-edhoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit from 2.2.1 to 3.0.2 Signed-off-by: Øyvind Rønningstad (cherry picked from commit 33c84d8af063586fd280882add96951a309fa03e) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 200690b6f3e..898783ecdba 100644 --- a/west.yml +++ b/west.yml @@ -332,7 +332,7 @@ manifest: groups: - tee - name: uoscore-uedhoc - revision: 5fe2cb613bd7e4590bd1b00c2adf181ac0229379 + revision: 5024d8c98b3864c6698f0195a53e19c484bc8cd3 path: modules/lib/uoscore-uedhoc - name: zcbor revision: 67fd8bb88d3136738661fa8bb5f9989103f4599e From 9293021b1c06e63fe04874d95ef3388dc92400a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Wed, 10 Jan 2024 09:09:41 +0100 Subject: [PATCH 1459/1623] [nrf fromtree] west.yml: Update zcbor to 0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit as well as uoscore-uedhoc and MCUboot Highlights of zcbor 0.8.0: - Add support for unordered maps - Performance improvements - Naming improvements for generated code - Bugfixes Update MCUboot and uoscore-uedhoc to bring in changes related to zcbor 0.8.0. Signed-off-by: Øyvind Rønningstad (cherry picked from commit 0786e523da4b247dd8f60cbb5da4aea2f954a021) --- west.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/west.yml b/west.yml index 898783ecdba..18e4ba0ab58 100644 --- a/west.yml +++ b/west.yml @@ -282,7 +282,7 @@ manifest: groups: - crypto - name: mcuboot - revision: 0c0470e294dcfb52aab92299356a5f3caa0aa52b + revision: f09e205b1e4a8d2bc3f50dffa7960d6ccd14df59 path: bootloader/mcuboot - name: mipi-sys-t path: modules/debug/mipi-sys-t @@ -332,10 +332,10 @@ manifest: groups: - tee - name: uoscore-uedhoc - revision: 5024d8c98b3864c6698f0195a53e19c484bc8cd3 + revision: 150f4eb2955eaf36ac0f9519d4f4f58d5ade5740 path: modules/lib/uoscore-uedhoc - name: zcbor - revision: 67fd8bb88d3136738661fa8bb5f9989103f4599e + revision: dbe20afd00b3ddd6956f4b47f5df202bb49a8707 path: modules/lib/zcbor self: From 73ddbd6e1030cf333d27322d6c7cb261a62dc608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Wed, 24 Jan 2024 15:20:57 +0100 Subject: [PATCH 1460/1623] [nrf fromtree] scripts: requirements-extra.txt: Update zcbor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit from 0.6.0 to 0.8.0 If people are using the zcbor script for code generation, it needs to be at the latest version Signed-off-by: Øyvind Rønningstad (cherry picked from commit 5d95776514df12a9dbfc239dd05f05e78ed461ed) --- scripts/requirements-extras.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/requirements-extras.txt b/scripts/requirements-extras.txt index f210f069de9..99fa4f16cf4 100644 --- a/scripts/requirements-extras.txt +++ b/scripts/requirements-extras.txt @@ -32,4 +32,4 @@ PyGithub graphviz # used to generate CBOR encoders and decoders, e.g. lwm2m_senml_cbor. -zcbor>=0.6.0 +zcbor>=0.8.0 From e458adad772684fe0ff5de48d25f8771ad419fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Thu, 11 Jan 2024 14:18:21 +0100 Subject: [PATCH 1461/1623] [nrf fromtree] modules: zcbor: Add config CONFIG_ZCBOR_MAX_STR_LEN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For use with zcbor_tstr_put_term() which needs a maximum string length. Signed-off-by: Øyvind Rønningstad (cherry picked from commit ea4c12df8229519961b27aa6b4af4e5205cfe27e) --- modules/zcbor/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/zcbor/Kconfig b/modules/zcbor/Kconfig index 1b3fd15d5e3..655fb2ed2a8 100644 --- a/modules/zcbor/Kconfig +++ b/modules/zcbor/Kconfig @@ -33,4 +33,11 @@ config ZCBOR_ASSERT config ZCBOR_BIG_ENDIAN def_bool BIG_ENDIAN +config ZCBOR_MAX_STR_LEN + int "Default max length when calling zcbor_tstr_put_term()" + default 256 + help + This can be manually used if no other value is readily available, but + using this is discouraged. + endif # ZCBOR From b85a6b635d997f37bf5f546aaa2fbc007e35b88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Wed, 10 Jan 2024 10:00:53 +0100 Subject: [PATCH 1462/1623] [nrf fromtree] lwm2m: Adapt to zcbor 0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Regenerate from CDDL, update patch, fix references in code. Signed-off-by: Øyvind Rønningstad (cherry picked from commit 1bbb0a9ddb40f1c7ca5af66b19f3cb279fa2aa65) --- subsys/net/lib/lwm2m/lwm2m_rw_cbor.c | 22 +- subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c | 144 +++++----- subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch | 218 +++++---------- .../net/lib/lwm2m/lwm2m_senml_cbor_decode.c | 220 ++++++++------- .../net/lib/lwm2m/lwm2m_senml_cbor_decode.h | 2 +- .../net/lib/lwm2m/lwm2m_senml_cbor_encode.c | 254 ++++++++++-------- .../net/lib/lwm2m/lwm2m_senml_cbor_encode.h | 2 +- subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h | 116 ++++---- 8 files changed, 465 insertions(+), 513 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_cbor.c b/subsys/net/lib/lwm2m/lwm2m_rw_cbor.c index daa37d3b4ba..3b35d579569 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rw_cbor.c +++ b/subsys/net/lib/lwm2m/lwm2m_rw_cbor.c @@ -66,7 +66,7 @@ static int put_time(struct lwm2m_output_context *out, struct lwm2m_obj_path *pat ZCBOR_STATE_E(states, 0, CPKT_BUF_W_PTR(out->out_cpkt), CPKT_BUF_W_SIZE(out->out_cpkt), 1); /* Are tags required? V1.1 leaves this unspecified but some servers require tags */ - ret = zcbor_tag_encode(states, ZCBOR_TAG_TIME_TSTR); + ret = zcbor_tag_put(states, ZCBOR_TAG_TIME_TSTR); if (!ret) { LOG_ERR("unable to encode date/time string tag"); @@ -77,7 +77,7 @@ static int put_time(struct lwm2m_output_context *out, struct lwm2m_obj_path *pat out->out_cpkt->offset += tag_sz; - ret = zcbor_tstr_put_term(states, time_str); + ret = zcbor_tstr_put_term(states, time_str, sizeof(time_str)); if (!ret) { LOG_ERR("unable to encode date/time string"); return -ENOMEM; @@ -232,7 +232,7 @@ static int put_objlnk(struct lwm2m_output_context *out, struct lwm2m_obj_path *p static int get_s64(struct lwm2m_input_context *in, int64_t *value) { - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_int64_decode(states, value)) { LOG_WRN("unable to decode a 64-bit integer value"); @@ -248,7 +248,7 @@ static int get_s64(struct lwm2m_input_context *in, int64_t *value) static int get_s32(struct lwm2m_input_context *in, int32_t *value) { - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_int32_decode(states, value)) { LOG_WRN("unable to decode a 32-bit integer value, err: %d", @@ -265,7 +265,7 @@ static int get_s32(struct lwm2m_input_context *in, int32_t *value) static int get_float(struct lwm2m_input_context *in, double *value) { - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_float_decode(states, value)) { LOG_ERR("unable to decode a floating-point value"); @@ -284,7 +284,7 @@ static int get_string(struct lwm2m_input_context *in, uint8_t *value, size_t buf struct zcbor_string hndl; int len; - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_tstr_decode(states, &hndl)) { LOG_WRN("unable to decode a string"); @@ -313,7 +313,7 @@ static int get_time_string(struct lwm2m_input_context *in, int64_t *value) char time_str[sizeof("4294967295")] = { 0 }; struct zcbor_string hndl = { .value = time_str, .len = sizeof(time_str) - 1 }; - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_tstr_decode(states, &hndl)) { return -EBADMSG; @@ -331,7 +331,7 @@ static int get_time_string(struct lwm2m_input_context *in, int64_t *value) */ static int get_time_numerical(struct lwm2m_input_context *in, int64_t *value) { - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_int64_decode(states, value)) { LOG_WRN("unable to decode seconds since Epoch"); @@ -350,7 +350,7 @@ static int get_time(struct lwm2m_input_context *in, time_t *value) bool success; int64_t temp64; - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); success = zcbor_tag_decode(states, &tag); @@ -400,7 +400,7 @@ static int get_time(struct lwm2m_input_context *in, time_t *value) static int get_bool(struct lwm2m_input_context *in, bool *value) { - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_bool_decode(states, value)) { LOG_WRN("unable to decode a boolean value"); @@ -420,7 +420,7 @@ static int get_opaque(struct lwm2m_input_context *in, uint8_t *value, size_t buf struct zcbor_string_fragment hndl = { 0 }; int ret; - ZCBOR_STATE_D(states, 1, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 1, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); /* Get the CBOR header only on first read. */ if (opaque->remaining == 0) { diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c index dd963aa0583..6c20024bbde 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c +++ b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c @@ -81,12 +81,12 @@ K_MUTEX_DEFINE(fd_mtx); #define GET_CBOR_FD_NAME(fd) ((fd)->names[(fd)->name_cnt]) /* Get the current record */ #define GET_CBOR_FD_REC(fd) \ - &((fd)->input._lwm2m_senml__record[(fd)->input._lwm2m_senml__record_count]) + &((fd)->input.lwm2m_senml_record_m[(fd)->input.lwm2m_senml_record_m_count]) /* Get a record */ -#define GET_IN_FD_REC_I(fd, i) &((fd)->dcd._lwm2m_senml__record[i]) +#define GET_IN_FD_REC_I(fd, i) &((fd)->dcd.lwm2m_senml_record_m[i]) /* Consume the current record */ #define CONSUME_CBOR_FD_REC(fd) \ - &((fd)->input._lwm2m_senml__record[(fd)->input._lwm2m_senml__record_count++]) + &((fd)->input.lwm2m_senml_record_m[(fd)->input.lwm2m_senml_record_m_count++]) /* Get CBOR output formatter data */ #define LWM2M_OFD_CBOR(octx) ((struct cbor_out_fmt_data *)engine_get_out_user_data(octx)) @@ -131,7 +131,7 @@ static int fmt_range_check(struct cbor_out_fmt_data *fd) { if (fd->name_cnt >= CONFIG_LWM2M_RW_SENML_CBOR_RECORDS || fd->objlnk_cnt >= CONFIG_LWM2M_RW_SENML_CBOR_RECORDS || - fd->input._lwm2m_senml__record_count >= CONFIG_LWM2M_RW_SENML_CBOR_RECORDS) { + fd->input.lwm2m_senml_record_m_count >= CONFIG_LWM2M_RW_SENML_CBOR_RECORDS) { LOG_ERR("CONFIG_LWM2M_RW_SENML_CBOR_RECORDS too small"); return -ENOMEM; } @@ -161,9 +161,9 @@ static int put_basename(struct lwm2m_output_context *out, struct lwm2m_obj_path /* Tell CBOR encoder where to find the name */ struct record *record = GET_CBOR_FD_REC(fd); - record->_record_bn._record_bn.value = basename; - record->_record_bn._record_bn.len = len; - record->_record_bn_present = 1; + record->record_bn.record_bn.value = basename; + record->record_bn.record_bn.len = len; + record->record_bn_present = 1; if ((len < sizeof("/0/0") - 1) || (len >= SENML_MAX_NAME_SIZE)) { __ASSERT_NO_MSG(false); @@ -190,7 +190,7 @@ static int put_end(struct lwm2m_output_context *out, struct lwm2m_obj_path *path size_t len; struct lwm2m_senml *input = &(LWM2M_OFD_CBOR(out)->input); - if (!input->_lwm2m_senml__record_count) { + if (!input->lwm2m_senml_record_m_count) { len = put_empty_array(out); return len; @@ -258,9 +258,9 @@ static int put_begin_r(struct lwm2m_output_context *out, struct lwm2m_obj_path * /* Tell CBOR encoder where to find the name */ struct record *record = GET_CBOR_FD_REC(fd); - record->_record_n._record_n.value = name; - record->_record_n._record_n.len = len; - record->_record_n_present = 1; + record->record_n.record_n.value = name; + record->record_n.record_n.len = len; + record->record_n_present = 1; /* Makes possible to use same slot for storing r/ri name combination. * No need to increase the name count if an existing name has been used @@ -287,12 +287,12 @@ static int put_data_timestamp(struct lwm2m_output_context *out, time_t value) out_record = GET_CBOR_FD_REC(fd); if (fd->basetime) { - out_record->_record_t._record_t = value - fd->basetime; - out_record->_record_t_present = 1; + out_record->record_t.record_t = value - fd->basetime; + out_record->record_t_present = 1; } else { fd->basetime = value; - out_record->_record_bt._record_bt = value; - out_record->_record_bt_present = 1; + out_record->record_bt.record_bt = value; + out_record->record_bt_present = 1; } return 0; @@ -332,9 +332,9 @@ static int put_begin_ri(struct lwm2m_output_context *out, struct lwm2m_obj_path } /* Tell CBOR encoder where to find the name */ - record->_record_n._record_n.value = name; - record->_record_n._record_n.len = len; - record->_record_n_present = 1; + record->record_n.record_n.value = name; + record->record_n.record_n.len = len; + record->record_n_present = 1; /* No need to increase the name count if an existing name has been used */ if (name == GET_CBOR_FD_NAME(fd)) { @@ -353,7 +353,7 @@ static int put_name_nth_ri(struct lwm2m_output_context *out, struct lwm2m_obj_pa /* With the first ri the resource name (and ri name) are already in place*/ if (path->res_inst_id > 0) { ret = put_begin_ri(out, path); - } else if (record && record->_record_t_present) { + } else if (record && record->record_t_present) { /* Name need to be add for each time serialized record */ ret = put_begin_r(out, path); } @@ -372,9 +372,9 @@ static int put_value(struct lwm2m_output_context *out, struct lwm2m_obj_path *pa struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vi; - record->_record_union._union_vi = value; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vi_c; + record->record_union.union_vi = value; + record->record_union_present = 1; return 0; } @@ -410,9 +410,9 @@ static int put_time(struct lwm2m_output_context *out, struct lwm2m_obj_path *pat struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vi; - record->_record_union._union_vi = (int64_t)value; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vi_c; + record->record_union.union_vi = (int64_t)value; + record->record_union_present = 1; return 0; } @@ -428,9 +428,9 @@ static int put_float(struct lwm2m_output_context *out, struct lwm2m_obj_path *pa struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vf; - record->_record_union._union_vf = *value; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vf_c; + record->record_union.union_vf = *value; + record->record_union_present = 1; return 0; } @@ -447,10 +447,10 @@ static int put_string(struct lwm2m_output_context *out, struct lwm2m_obj_path *p struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vs; - record->_record_union._union_vs.value = buf; - record->_record_union._union_vs.len = buflen; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vs_c; + record->record_union.union_vs.value = buf; + record->record_union.union_vs.len = buflen; + record->record_union_present = 1; return 0; } @@ -466,9 +466,9 @@ static int put_bool(struct lwm2m_output_context *out, struct lwm2m_obj_path *pat struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vb; - record->_record_union._union_vb = value; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vb_c; + record->record_union.union_vb = value; + record->record_union_present = 1; return 0; } @@ -485,10 +485,10 @@ static int put_opaque(struct lwm2m_output_context *out, struct lwm2m_obj_path *p struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vd; - record->_record_union._union_vd.value = buf; - record->_record_union._union_vd.len = buflen; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vd_c; + record->record_union.union_vd.value = buf; + record->record_union.union_vd.len = buflen; + record->record_union_present = 1; return 0; } @@ -522,10 +522,10 @@ static int put_objlnk(struct lwm2m_output_context *out, struct lwm2m_obj_path *p struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vlo; - record->_record_union._union_vlo.value = objlink_buf; - record->_record_union._union_vlo.len = objlnk_len; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vlo_c; + record->record_union.union_vlo.value = objlink_buf; + record->record_union.union_vlo.len = objlnk_len; + record->record_union_present = 1; fd->objlnk_cnt++; @@ -548,14 +548,14 @@ static int get_opaque(struct lwm2m_input_context *in, return -EINVAL; } - opaque->len = fd->current->_record_union._union_vd.len; + opaque->len = fd->current->record_union.union_vd.len; if (buflen < opaque->len) { LOG_DBG("Write opaque failed, no buffer space"); return -ENOMEM; } - dest = memcpy(value, fd->current->_record_union._union_vd.value, opaque->len); + dest = memcpy(value, fd->current->record_union.union_vd.value, opaque->len); *last_block = true; } else { LOG_DBG("Blockwise transfer not supported with SenML CBOR"); @@ -574,7 +574,7 @@ static int get_s32(struct lwm2m_input_context *in, int32_t *value) return -EINVAL; } - *value = fd->current->_record_union._union_vi; + *value = fd->current->record_union.union_vi; fd->current = NULL; return 0; @@ -589,7 +589,7 @@ static int get_s64(struct lwm2m_input_context *in, int64_t *value) return -EINVAL; } - *value = fd->current->_record_union._union_vi; + *value = fd->current->record_union.union_vi; fd->current = NULL; return 0; @@ -615,7 +615,7 @@ static int get_float(struct lwm2m_input_context *in, double *value) return -EINVAL; } - *value = fd->current->_record_union._union_vf; + *value = fd->current->record_union.union_vf; fd->current = NULL; return 0; @@ -631,9 +631,9 @@ static int get_string(struct lwm2m_input_context *in, uint8_t *buf, size_t bufle return -EINVAL; } - len = MIN(buflen-1, fd->current->_record_union._union_vs.len); + len = MIN(buflen-1, fd->current->record_union.union_vs.len); - memcpy(buf, fd->current->_record_union._union_vs.value, len); + memcpy(buf, fd->current->record_union.union_vs.value, len); buf[len] = '\0'; fd->current = NULL; @@ -698,7 +698,7 @@ static int get_bool(struct lwm2m_input_context *in, bool *value) return -EINVAL; } - *value = fd->current->_record_union._union_vb; + *value = fd->current->record_union.union_vb; fd->current = NULL; return 0; @@ -727,9 +727,9 @@ static int do_write_op_item(struct lwm2m_message *msg, struct record *rec) } /* If there's no name then the basename forms the path */ - if (rec->_record_n_present) { - len = MIN(sizeof(name) - 1, rec->_record_n._record_n.len); - snprintk(name, len + 1, "%s", rec->_record_n._record_n.value); + if (rec->record_n_present) { + len = MIN(sizeof(name) - 1, rec->record_n.record_n.len); + snprintk(name, len + 1, "%s", rec->record_n.record_n.value); } /* Form fully qualified path name */ @@ -853,29 +853,29 @@ static uint8_t parse_composite_read_paths(struct lwm2m_message *msg, msg->in.offset += isize; - for (int idx = 0; idx < fd->dcd._lwm2m_senml__record_count; idx++) { + for (int idx = 0; idx < fd->dcd.lwm2m_senml_record_m_count; idx++) { /* Where to find the basenames and names */ struct record *record = GET_IN_FD_REC_I(fd, idx); /* Set null terminated effective basename */ - if (record->_record_bn_present) { - len = MIN(sizeof(basename)-1, record->_record_bn._record_bn.len); - snprintk(basename, len + 1, "%s", record->_record_bn._record_bn.value); + if (record->record_bn_present) { + len = MIN(sizeof(basename)-1, record->record_bn.record_bn.len); + snprintk(basename, len + 1, "%s", record->record_bn.record_bn.value); basename[len] = '\0'; } /* Best effort with read, skip if no proper name is available */ - if (!record->_record_n_present) { + if (!record->record_n_present) { if (strcmp(basename, "") == 0) { continue; } } /* Set null terminated name */ - if (record->_record_n_present) { - len = MIN(sizeof(name)-1, record->_record_n._record_n.len); - snprintk(name, len + 1, "%s", record->_record_n._record_n.value); + if (record->record_n_present) { + len = MIN(sizeof(name)-1, record->record_n.record_n.len); + snprintk(name, len + 1, "%s", record->record_n.record_n.value); name[len] = '\0'; } @@ -979,30 +979,30 @@ int do_write_op_senml_cbor(struct lwm2m_message *msg) msg->in.offset += decoded_sz; - for (int idx = 0; idx < fd->dcd._lwm2m_senml__record_count; idx++) { + for (int idx = 0; idx < fd->dcd.lwm2m_senml_record_m_count; idx++) { - struct record *rec = &fd->dcd._lwm2m_senml__record[idx]; + struct record *rec = &fd->dcd.lwm2m_senml_record_m[idx]; /* Basename applies for current and succeeding records */ - if (rec->_record_bn_present) { + if (rec->record_bn_present) { int len = MIN(sizeof(fd->basename) - 1, - rec->_record_bn._record_bn.len); + rec->record_bn.record_bn.len); - snprintk(fd->basename, len + 1, "%s", rec->_record_bn._record_bn.value); + snprintk(fd->basename, len + 1, "%s", rec->record_bn.record_bn.value); goto write; } /* Keys' lexicographic order differ from the default */ - for (int jdx = 0; jdx < rec->_record__key_value_pair_count; jdx++) { + for (int jdx = 0; jdx < rec->record_key_value_pair_m_count; jdx++) { struct key_value_pair *kvp = - &(rec->_record__key_value_pair[jdx]._record__key_value_pair); + &(rec->record_key_value_pair_m[jdx].record_key_value_pair_m); - if (kvp->_key_value_pair_key == lwm2m_senml_cbor_key_bn) { + if (kvp->key_value_pair_key == lwm2m_senml_cbor_key_bn) { int len = MIN(sizeof(fd->basename) - 1, - kvp->_key_value_pair._value_tstr.len); + kvp->key_value_pair.value_tstr.len); snprintk(fd->basename, len + 1, "%s", - kvp->_key_value_pair._value_tstr.value); + kvp->key_value_pair.value_tstr.value); break; } } diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch b/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch index 48b984aafac..81ec06bab8b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch @@ -1,94 +1,59 @@ diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c -index f97f0ebb2d..1c1233d616 100644 +index c12f477cce..f41b81275d 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ -@@ -15,9 +15,6 @@ - #include "zcbor_decode.h" +@@ -16,10 +16,6 @@ #include "lwm2m_senml_cbor_decode.h" + #include "zcbor_print.h" -#if DEFAULT_MAX_QTY != 99 -#error "The type file was generated with a different default_max_qty than this file" -#endif - +- static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *result); static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *result); -@@ -52,7 +49,7 @@ static bool decode_repeated_record_bt( - - bool tmp_result = ((((zcbor_int32_expect(state, (-3)))) - && (zcbor_int64_decode(state, (&(*result)._record_bt))) -- && ((((*result)._record_bt >= -9223372036854775807LL) -+ && ((((*result)._record_bt >= INT64_MIN) - && ((*result)._record_bt <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); - - if (!tmp_result) -@@ -82,7 +79,7 @@ static bool decode_repeated_record_t( - - bool tmp_result = ((((zcbor_uint32_expect(state, (6)))) - && (zcbor_int64_decode(state, (&(*result)._record_t))) -- && ((((*result)._record_t >= -9223372036854775807LL) -+ && ((((*result)._record_t >= INT64_MIN) - && ((*result)._record_t <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); - - if (!tmp_result) -@@ -100,7 +97,7 @@ static bool decode_repeated_record_union( - - bool tmp_result = (((zcbor_union_start_code(state) && (int_res = (((((zcbor_uint32_expect_union(state, (2)))) - && (zcbor_int64_decode(state, (&(*result)._union_vi))) -- && ((((*result)._union_vi >= -9223372036854775807LL) -+ && ((((*result)._union_vi >= INT64_MIN) - && ((*result)._union_vi <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) && (((*result)._record_union_choice = _union_vi), true)) - || ((((zcbor_uint32_expect_union(state, (2)))) - && (zcbor_float_decode(state, (&(*result)._union_vf)))) && (((*result)._record_union_choice = _union_vf), true)) -@@ -128,7 +125,7 @@ static bool decode_value( - bool tmp_result = (((zcbor_union_start_code(state) && (int_res = ((((zcbor_tstr_decode(state, (&(*result)._value_tstr)))) && (((*result)._value_choice = _value_tstr), true)) - || (((zcbor_bstr_decode(state, (&(*result)._value_bstr)))) && (((*result)._value_choice = _value_bstr), true)) - || (((zcbor_int64_decode(state, (&(*result)._value_int))) -- && ((((*result)._value_int >= -9223372036854775807LL) -+ && ((((*result)._value_int >= INT64_MIN) - && ((*result)._value_int <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) && (((*result)._value_choice = _value_int), true)) - || (((zcbor_float_decode(state, (&(*result)._value_float)))) && (((*result)._value_choice = _value_float), true)) - || (((zcbor_bool_decode(state, (&(*result)._value_bool)))) && (((*result)._value_choice = _value_bool), true))), zcbor_union_end_code(state), int_res)))); -@@ -176,7 +173,7 @@ static bool decode_record( - && zcbor_present_decode(&((*result)._record_n_present), (zcbor_decoder_t *)decode_repeated_record_n, state, (&(*result)._record_n)) - && zcbor_present_decode(&((*result)._record_t_present), (zcbor_decoder_t *)decode_repeated_record_t, state, (&(*result)._record_t)) - && zcbor_present_decode(&((*result)._record_union_present), (zcbor_decoder_t *)decode_repeated_record_union, state, (&(*result)._record_union)) -- && zcbor_multi_decode(0, 5, &(*result)._record__key_value_pair_count, (zcbor_decoder_t *)decode_repeated_record__key_value_pair, state, (&(*result)._record__key_value_pair), sizeof(struct record__key_value_pair))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); -+ && zcbor_multi_decode(0, ZCBOR_ARRAY_SIZE(result->_record__key_value_pair), &(*result)._record__key_value_pair_count, (zcbor_decoder_t *)decode_repeated_record__key_value_pair, state, (&(*result)._record__key_value_pair), sizeof(struct record__key_value_pair))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); - - if (!tmp_result) - zcbor_trace(); -@@ -189,7 +186,7 @@ static bool decode_lwm2m_senml( + static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *result); +@@ -209,7 +205,7 @@ static bool decode_record( + && zcbor_present_decode(&((*result).record_n_present), (zcbor_decoder_t *)decode_repeated_record_n, state, (&(*result).record_n)) + && zcbor_present_decode(&((*result).record_t_present), (zcbor_decoder_t *)decode_repeated_record_t, state, (&(*result).record_t)) + && zcbor_present_decode(&((*result).record_union_present), (zcbor_decoder_t *)decode_repeated_record_union, state, (&(*result).record_union)) +- && zcbor_multi_decode(0, 5, &(*result).record_key_value_pair_m_count, (zcbor_decoder_t *)decode_repeated_record_key_value_pair_m, state, (&(*result).record_key_value_pair_m), sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); ++ && zcbor_multi_decode(0, ZCBOR_ARRAY_SIZE(result->record_key_value_pair_m), &(*result).record_key_value_pair_m_count, (zcbor_decoder_t *)decode_repeated_record_key_value_pair_m, state, (&(*result).record_key_value_pair_m), sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); + + if (!tmp_result) { + zcbor_trace_file(state); +@@ -226,7 +222,7 @@ static bool decode_lwm2m_senml( { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); -- bool tmp_result = (((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, 99, &(*result)._lwm2m_senml__record_count, (zcbor_decoder_t *)decode_record, state, (&(*result)._lwm2m_senml__record), sizeof(struct record))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); -+ bool tmp_result = (((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, ZCBOR_ARRAY_SIZE(result->_lwm2m_senml__record), &(*result)._lwm2m_senml__record_count, (zcbor_decoder_t *)decode_record, state, (&(*result)._lwm2m_senml__record), sizeof(struct record))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); +- bool tmp_result = (((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, 99, &(*result).lwm2m_senml_record_m_count, (zcbor_decoder_t *)decode_record, state, (&(*result).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); ++ bool tmp_result = (((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, ZCBOR_ARRAY_SIZE(result->lwm2m_senml_record_m), &(*result).lwm2m_senml_record_m_count, (zcbor_decoder_t *)decode_record, state, (&(*result).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); - if (!tmp_result) - zcbor_trace(); + if (!tmp_result) { + zcbor_trace_file(state); diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h -index cb5d5c9695..7db7ed0591 100644 +index a36f8782c6..b913fb78e9 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ -@@ -21,10 +21,6 @@ +@@ -21,11 +21,6 @@ extern "C" { #endif @@ -96,25 +61,26 @@ index cb5d5c9695..7db7ed0591 100644 -#error "The type file was generated with a different default_max_qty than this file" -#endif - - +- int cbor_decode_lwm2m_senml( - const uint8_t *payload, size_t payload_len, + const uint8_t *payload, size_t payload_len, + struct lwm2m_senml *result, diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c -index 982cfca6c3..afdc6a32f7 100644 +index 94926c531f..5521917853 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ -@@ -15,10 +15,6 @@ - #include "zcbor_encode.h" +@@ -16,10 +16,6 @@ #include "lwm2m_senml_cbor_encode.h" + #include "zcbor_print.h" -#if DEFAULT_MAX_QTY != 99 -#error "The type file was generated with a different default_max_qty than this file" @@ -123,80 +89,44 @@ index 982cfca6c3..afdc6a32f7 100644 static bool encode_repeated_record_bn(zcbor_state_t *state, const struct record_bn *input); static bool encode_repeated_record_bt(zcbor_state_t *state, const struct record_bt *input); static bool encode_repeated_record_n(zcbor_state_t *state, const struct record_n *input); -@@ -51,7 +47,7 @@ static bool encode_repeated_record_bt( - zcbor_print("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_int32_put(state, (-3)))) -- && ((((*input)._record_bt >= -9223372036854775807LL) -+ && ((((*input)._record_bt >= INT64_MIN) - && ((*input)._record_bt <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_int64_encode(state, (&(*input)._record_bt))))); - -@@ -81,7 +77,7 @@ static bool encode_repeated_record_t( - zcbor_print("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (6)))) -- && ((((*input)._record_t >= -9223372036854775807LL) -+ && ((((*input)._record_t >= INT64_MIN) - && ((*input)._record_t <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_int64_encode(state, (&(*input)._record_t))))); - -@@ -98,7 +94,7 @@ static bool encode_repeated_record_union( - struct zcbor_string tmp_str; - - bool tmp_result = (((((*input)._record_union_choice == _union_vi) ? (((zcbor_uint32_put(state, (2)))) -- && ((((*input)._union_vi >= -9223372036854775807LL) -+ && ((((*input)._union_vi >= INT64_MIN) - && ((*input)._union_vi <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_int64_encode(state, (&(*input)._union_vi)))) - : (((*input)._record_union_choice == _union_vf) ? (((zcbor_uint32_put(state, (2)))) -@@ -126,7 +122,7 @@ static bool encode_value( - - bool tmp_result = (((((*input)._value_choice == _value_tstr) ? ((zcbor_tstr_encode(state, (&(*input)._value_tstr)))) - : (((*input)._value_choice == _value_bstr) ? ((zcbor_bstr_encode(state, (&(*input)._value_bstr)))) -- : (((*input)._value_choice == _value_int) ? (((((*input)._value_int >= -9223372036854775807LL) -+ : (((*input)._value_choice == _value_int) ? (((((*input)._value_int >= INT64_MIN) - && ((*input)._value_int <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_int64_encode(state, (&(*input)._value_int)))) - : (((*input)._value_choice == _value_float) ? ((zcbor_float64_encode(state, (&(*input)._value_float)))) -@@ -171,12 +167,12 @@ static bool encode_record( +@@ -204,12 +200,12 @@ static bool encode_record( { - zcbor_print("%s\r\n", __func__); - -- bool tmp_result = (((zcbor_map_start_encode(state, 10) && ((zcbor_present_encode(&((*input)._record_bn_present), (zcbor_encoder_t *)encode_repeated_record_bn, state, (&(*input)._record_bn)) -+ bool tmp_result = (((zcbor_map_start_encode(state, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair)) && ((zcbor_present_encode(&((*input)._record_bn_present), (zcbor_encoder_t *)encode_repeated_record_bn, state, (&(*input)._record_bn)) - && zcbor_present_encode(&((*input)._record_bt_present), (zcbor_encoder_t *)encode_repeated_record_bt, state, (&(*input)._record_bt)) - && zcbor_present_encode(&((*input)._record_n_present), (zcbor_encoder_t *)encode_repeated_record_n, state, (&(*input)._record_n)) - && zcbor_present_encode(&((*input)._record_t_present), (zcbor_encoder_t *)encode_repeated_record_t, state, (&(*input)._record_t)) - && zcbor_present_encode(&((*input)._record_union_present), (zcbor_encoder_t *)encode_repeated_record_union, state, (&(*input)._record_union)) -- && zcbor_multi_encode_minmax(0, 5, &(*input)._record__key_value_pair_count, (zcbor_encoder_t *)encode_repeated_record__key_value_pair, state, (&(*input)._record__key_value_pair), sizeof(struct record__key_value_pair))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 10)))); -+ && zcbor_multi_encode_minmax(0, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair), &(*input)._record__key_value_pair_count, (zcbor_encoder_t *)encode_repeated_record__key_value_pair, state, (&(*input)._record__key_value_pair), sizeof(struct record__key_value_pair))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair))))); - - if (!tmp_result) - zcbor_trace(); -@@ -189,7 +185,7 @@ static bool encode_lwm2m_senml( + zcbor_log("%s\r\n", __func__); + +- bool tmp_result = (((zcbor_map_start_encode(state, 10) && (((!(*input).record_bn_present || encode_repeated_record_bn(state, (&(*input).record_bn))) ++ bool tmp_result = (((zcbor_map_start_encode(state, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m)) && (((!(*input).record_bn_present || encode_repeated_record_bn(state, (&(*input).record_bn))) + && (!(*input).record_bt_present || encode_repeated_record_bt(state, (&(*input).record_bt))) + && (!(*input).record_n_present || encode_repeated_record_n(state, (&(*input).record_n))) + && (!(*input).record_t_present || encode_repeated_record_t(state, (&(*input).record_t))) + && (!(*input).record_union_present || encode_repeated_record_union(state, (&(*input).record_union))) +- && zcbor_multi_encode_minmax(0, 5, &(*input).record_key_value_pair_m_count, (zcbor_encoder_t *)encode_repeated_record_key_value_pair_m, state, (&(*input).record_key_value_pair_m), sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 10)))); ++ && zcbor_multi_encode_minmax(0, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m), &(*input).record_key_value_pair_m_count, (zcbor_encoder_t *)encode_repeated_record_key_value_pair_m, state, (&(*input).record_key_value_pair_m), sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m))))); + + if (!tmp_result) { + zcbor_trace_file(state); +@@ -226,7 +222,7 @@ static bool encode_lwm2m_senml( { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); -- bool tmp_result = (((zcbor_list_start_encode(state, 99) && ((zcbor_multi_encode_minmax(1, 99, &(*input)._lwm2m_senml__record_count, (zcbor_encoder_t *)encode_record, state, (&(*input)._lwm2m_senml__record), sizeof(struct record))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 99)))); -+ bool tmp_result = (((zcbor_list_start_encode(state, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record)) && ((zcbor_multi_encode_minmax(1, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record), &(*input)._lwm2m_senml__record_count, (zcbor_encoder_t *)encode_record, state, (&(*input)._lwm2m_senml__record), sizeof(struct record))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record))))); +- bool tmp_result = (((zcbor_list_start_encode(state, 99) && ((zcbor_multi_encode_minmax(1, 99, &(*input).lwm2m_senml_record_m_count, (zcbor_encoder_t *)encode_record, state, (&(*input).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 99)))); ++ bool tmp_result = (((zcbor_list_start_encode(state, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m)) && ((zcbor_multi_encode_minmax(1, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m), &(*input).lwm2m_senml_record_m_count, (zcbor_encoder_t *)encode_record, state, (&(*input).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m))))); - if (!tmp_result) - zcbor_trace(); + if (!tmp_result) { + zcbor_trace_file(state); diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h -index b6c54afde5..cbc32e540c 100644 +index df2f0ac6a1..8fa1eedb2b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ -@@ -21,10 +21,6 @@ +@@ -21,11 +21,6 @@ extern "C" { #endif @@ -204,26 +134,36 @@ index b6c54afde5..cbc32e540c 100644 -#error "The type file was generated with a different default_max_qty than this file" -#endif - - +- int cbor_encode_lwm2m_senml( - uint8_t *payload, size_t payload_len, + uint8_t *payload, size_t payload_len, + const struct lwm2m_senml *input, diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h -index e12f33636e..f709086a5c 100644 +index 77649036ef..f0a2958072 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ -@@ -20,6 +20,18 @@ +@@ -20,14 +20,18 @@ extern "C" { #endif +-/** Which value for --default-max-qty this file was created with. +- * +- * The define is used in the other generated file to do a build-time +- * compatibility check. +- * +- * See `zcbor --help` for more information about --default-max-qty +- */ +-#define DEFAULT_MAX_QTY 99 ++ +enum lwm2m_senml_cbor_key { + lwm2m_senml_cbor_key_bn = -2, + lwm2m_senml_cbor_key_bt = -3, @@ -235,25 +175,15 @@ index e12f33636e..f709086a5c 100644 + lwm2m_senml_cbor_key_vb = 4, + lwm2m_senml_cbor_key_vd = 8, +}; -+ - /** Which value for --default-max-qty this file was created with. - * - * The define is used in the other generated file to do a build-time -@@ -27,7 +39,7 @@ extern "C" { - * - * See `zcbor --help` for more information about --default-max-qty - */ --#define DEFAULT_MAX_QTY 99 -+#define DEFAULT_MAX_QTY CONFIG_LWM2M_RW_SENML_CBOR_RECORDS struct record_bn { - struct zcbor_string _record_bn; -@@ -118,7 +130,7 @@ struct record { + struct zcbor_string record_bn; +@@ -118,7 +122,7 @@ struct record { }; struct lwm2m_senml { -- struct record _lwm2m_senml__record[99]; -+ struct record _lwm2m_senml__record[DEFAULT_MAX_QTY]; - size_t _lwm2m_senml__record_count; +- struct record lwm2m_senml_record_m[99]; ++ struct record lwm2m_senml_record_m[CONFIG_LWM2M_RW_SENML_CBOR_RECORDS]; + size_t lwm2m_senml_record_m_count; }; diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c index a75aee02120..3906d476cac 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ @@ -14,28 +14,32 @@ #include #include "zcbor_decode.h" #include "lwm2m_senml_cbor_decode.h" +#include "zcbor_print.h" static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *result); static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *result); static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *result); static bool decode_repeated_record_t(zcbor_state_t *state, struct record_t *result); -static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_ *result); -static bool decode_value(zcbor_state_t *state, struct value_ *result); +static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_r *result); +static bool decode_value(zcbor_state_t *state, struct value_r *result); static bool decode_key_value_pair(zcbor_state_t *state, struct key_value_pair *result); -static bool decode_repeated_record__key_value_pair(zcbor_state_t *state, - struct record__key_value_pair *result); +static bool decode_repeated_record_key_value_pair_m(zcbor_state_t *state, + struct record_key_value_pair_m *result); static bool decode_record(zcbor_state_t *state, struct record *result); static bool decode_lwm2m_senml(zcbor_state_t *state, struct lwm2m_senml *result); static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_int32_expect(state, (-2)))) && - (zcbor_tstr_decode(state, (&(*result)._record_bn))))); + (zcbor_tstr_decode(state, (&(*result).record_bn))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -43,16 +47,19 @@ static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *re static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_int32_expect(state, (-3)))) && - (zcbor_int64_decode(state, (&(*result)._record_bt))) && - ((((*result)._record_bt >= INT64_MIN) && ((*result)._record_bt <= INT64_MAX)) || + (zcbor_int64_decode(state, (&(*result).record_bt))) && + ((((*result).record_bt >= INT64_MIN) && ((*result).record_bt <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -60,13 +67,16 @@ static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *re static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_uint32_expect(state, (0)))) && - (zcbor_tstr_decode(state, (&(*result)._record_n))))); + (zcbor_tstr_decode(state, (&(*result).record_n))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -74,86 +84,94 @@ static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *resu static bool decode_repeated_record_t(zcbor_state_t *state, struct record_t *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_uint32_expect(state, (6)))) && - (zcbor_int64_decode(state, (&(*result)._record_t))) && - ((((*result)._record_t >= INT64_MIN) && ((*result)._record_t <= INT64_MAX)) || + (zcbor_int64_decode(state, (&(*result).record_t))) && + ((((*result).record_t >= INT64_MIN) && ((*result).record_t <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_ *result) +static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_r *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); struct zcbor_string tmp_str; bool int_res; bool tmp_result = (((zcbor_union_start_code(state) && (int_res = (((((zcbor_uint32_expect_union(state, (2)))) && - (zcbor_int64_decode(state, (&(*result)._union_vi))) && - ((((*result)._union_vi >= INT64_MIN) && - ((*result)._union_vi <= INT64_MAX)) || + (zcbor_int64_decode(state, (&(*result).union_vi))) && + ((((*result).union_vi >= INT64_MIN) && + ((*result).union_vi <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) && - (((*result)._record_union_choice = _union_vi), true)) || + (((*result).record_union_choice = union_vi_c), true)) || ((((zcbor_uint32_expect_union(state, (2)))) && - (zcbor_float_decode(state, (&(*result)._union_vf)))) && - (((*result)._record_union_choice = _union_vf), true)) || + (zcbor_float_decode(state, (&(*result).union_vf)))) && + (((*result).record_union_choice = union_vf_c), true)) || ((((zcbor_uint32_expect_union(state, (3)))) && - (zcbor_tstr_decode(state, (&(*result)._union_vs)))) && - (((*result)._record_union_choice = _union_vs), true)) || + (zcbor_tstr_decode(state, (&(*result).union_vs)))) && + (((*result).record_union_choice = union_vs_c), true)) || ((((zcbor_uint32_expect_union(state, (4)))) && - (zcbor_bool_decode(state, (&(*result)._union_vb)))) && - (((*result)._record_union_choice = _union_vb), true)) || + (zcbor_bool_decode(state, (&(*result).union_vb)))) && + (((*result).record_union_choice = union_vb_c), true)) || ((((zcbor_uint32_expect_union(state, (8)))) && - (zcbor_bstr_decode(state, (&(*result)._union_vd)))) && - (((*result)._record_union_choice = _union_vd), true)) || + (zcbor_bstr_decode(state, (&(*result).union_vd)))) && + (((*result).record_union_choice = union_vd_c), true)) || (zcbor_union_elem_code(state) && ((((zcbor_tstr_expect( state, ((tmp_str.value = (uint8_t *)"vlo", tmp_str.len = sizeof("vlo") - 1, &tmp_str))))) && - (zcbor_tstr_decode(state, (&(*result)._union_vlo)))) && - (((*result)._record_union_choice = _union_vlo), true)))), + (zcbor_tstr_decode(state, (&(*result).union_vlo)))) && + (((*result).record_union_choice = union_vlo_c), true)))), zcbor_union_end_code(state), int_res)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool decode_value(zcbor_state_t *state, struct value_ *result) +static bool decode_value(zcbor_state_t *state, struct value_r *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool int_res; - bool tmp_result = - (((zcbor_union_start_code(state) && - (int_res = ((((zcbor_tstr_decode(state, (&(*result)._value_tstr)))) && - (((*result)._value_choice = _value_tstr), true)) || - (((zcbor_bstr_decode(state, (&(*result)._value_bstr)))) && - (((*result)._value_choice = _value_bstr), true)) || - (((zcbor_int64_decode(state, (&(*result)._value_int))) && - ((((*result)._value_int >= INT64_MIN) && - ((*result)._value_int <= INT64_MAX)) || - (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) && - (((*result)._value_choice = _value_int), true)) || - (((zcbor_float_decode(state, (&(*result)._value_float)))) && - (((*result)._value_choice = _value_float), true)) || - (((zcbor_bool_decode(state, (&(*result)._value_bool)))) && - (((*result)._value_choice = _value_bool), true))), - zcbor_union_end_code(state), int_res)))); + bool tmp_result = (((zcbor_union_start_code(state) && + (int_res = ((((zcbor_tstr_decode(state, (&(*result).value_tstr)))) && + (((*result).value_choice = value_tstr_c), true)) || + (((zcbor_bstr_decode(state, (&(*result).value_bstr)))) && + (((*result).value_choice = value_bstr_c), true)) || + (((zcbor_int64_decode(state, (&(*result).value_int))) && + ((((*result).value_int >= INT64_MIN) && + ((*result).value_int <= INT64_MAX)) || + (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) && + (((*result).value_choice = value_int_c), true)) || + (((zcbor_float_decode(state, (&(*result).value_float)))) && + (((*result).value_choice = value_float_c), true)) || + (((zcbor_bool_decode(state, (&(*result).value_bool)))) && + (((*result).value_choice = value_bool_c), true))), + zcbor_union_end_code(state), int_res)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -161,27 +179,33 @@ static bool decode_value(zcbor_state_t *state, struct value_ *result) static bool decode_key_value_pair(zcbor_state_t *state, struct key_value_pair *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); - bool tmp_result = ((((zcbor_int32_decode(state, (&(*result)._key_value_pair_key)))) && - (decode_value(state, (&(*result)._key_value_pair))))); + bool tmp_result = ((((zcbor_int32_decode(state, (&(*result).key_value_pair_key)))) && + (decode_value(state, (&(*result).key_value_pair))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool decode_repeated_record__key_value_pair(zcbor_state_t *state, - struct record__key_value_pair *result) +static bool decode_repeated_record_key_value_pair_m(zcbor_state_t *state, + struct record_key_value_pair_m *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); - bool tmp_result = (((decode_key_value_pair(state, (&(*result)._record__key_value_pair))))); + bool tmp_result = (((decode_key_value_pair(state, (&(*result).record_key_value_pair_m))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -189,35 +213,38 @@ static bool decode_repeated_record__key_value_pair(zcbor_state_t *state, static bool decode_record(zcbor_state_t *state, struct record *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = (((zcbor_map_start_decode(state) && - ((zcbor_present_decode(&((*result)._record_bn_present), + ((zcbor_present_decode(&((*result).record_bn_present), (zcbor_decoder_t *)decode_repeated_record_bn, state, - (&(*result)._record_bn)) && - zcbor_present_decode(&((*result)._record_bt_present), + (&(*result).record_bn)) && + zcbor_present_decode(&((*result).record_bt_present), (zcbor_decoder_t *)decode_repeated_record_bt, state, - (&(*result)._record_bt)) && - zcbor_present_decode(&((*result)._record_n_present), + (&(*result).record_bt)) && + zcbor_present_decode(&((*result).record_n_present), (zcbor_decoder_t *)decode_repeated_record_n, state, - (&(*result)._record_n)) && - zcbor_present_decode(&((*result)._record_t_present), + (&(*result).record_n)) && + zcbor_present_decode(&((*result).record_t_present), (zcbor_decoder_t *)decode_repeated_record_t, state, - (&(*result)._record_t)) && - zcbor_present_decode(&((*result)._record_union_present), + (&(*result).record_t)) && + zcbor_present_decode(&((*result).record_union_present), (zcbor_decoder_t *)decode_repeated_record_union, state, - (&(*result)._record_union)) && - zcbor_multi_decode(0, ZCBOR_ARRAY_SIZE(result->_record__key_value_pair), - &(*result)._record__key_value_pair_count, - (zcbor_decoder_t *)decode_repeated_record__key_value_pair, - state, (&(*result)._record__key_value_pair), - sizeof(struct record__key_value_pair))) || + (&(*result).record_union)) && + zcbor_multi_decode(0, ZCBOR_ARRAY_SIZE(result->record_key_value_pair_m), + &(*result).record_key_value_pair_m_count, + (zcbor_decoder_t *)decode_repeated_record_key_value_pair_m, + state, (&(*result).record_key_value_pair_m), + sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -225,19 +252,22 @@ static bool decode_record(zcbor_state_t *state, struct record *result) static bool decode_lwm2m_senml(zcbor_state_t *state, struct lwm2m_senml *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = (((zcbor_list_start_decode(state) && ((zcbor_multi_decode( - 1, ZCBOR_ARRAY_SIZE(result->_lwm2m_senml__record), - &(*result)._lwm2m_senml__record_count, (zcbor_decoder_t *)decode_record, - state, (&(*result)._lwm2m_senml__record), sizeof(struct record))) || + 1, ZCBOR_ARRAY_SIZE(result->lwm2m_senml_record_m), + &(*result).lwm2m_senml_record_m_count, (zcbor_decoder_t *)decode_record, + state, (&(*result).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -248,19 +278,7 @@ int cbor_decode_lwm2m_senml(const uint8_t *payload, size_t payload_len, struct l { zcbor_state_t states[5]; - zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1); - - bool ret = decode_lwm2m_senml(states, result); - - if (ret && (payload_len_out != NULL)) { - *payload_len_out = MIN(payload_len, (size_t)states[0].payload - (size_t)payload); - } - - if (!ret) { - int err = zcbor_pop_error(states); - - zcbor_print("Return error: %d\r\n", err); - return (err == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : err; - } - return ZCBOR_SUCCESS; + return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, + (zcbor_decoder_t *)decode_lwm2m_senml, + sizeof(states) / sizeof(zcbor_state_t), 1); } diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h index a8ae779b6a1..b47b79de615 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c index 74c9310941b..9cf4f3457c6 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ @@ -14,28 +14,32 @@ #include #include "zcbor_encode.h" #include "lwm2m_senml_cbor_encode.h" +#include "zcbor_print.h" static bool encode_repeated_record_bn(zcbor_state_t *state, const struct record_bn *input); static bool encode_repeated_record_bt(zcbor_state_t *state, const struct record_bt *input); static bool encode_repeated_record_n(zcbor_state_t *state, const struct record_n *input); static bool encode_repeated_record_t(zcbor_state_t *state, const struct record_t *input); -static bool encode_repeated_record_union(zcbor_state_t *state, const struct record_union_ *input); -static bool encode_value(zcbor_state_t *state, const struct value_ *input); +static bool encode_repeated_record_union(zcbor_state_t *state, const struct record_union_r *input); +static bool encode_value(zcbor_state_t *state, const struct value_r *input); static bool encode_key_value_pair(zcbor_state_t *state, const struct key_value_pair *input); -static bool encode_repeated_record__key_value_pair(zcbor_state_t *state, - const struct record__key_value_pair *input); +static bool encode_repeated_record_key_value_pair_m(zcbor_state_t *state, + const struct record_key_value_pair_m *input); static bool encode_record(zcbor_state_t *state, const struct record *input); static bool encode_lwm2m_senml(zcbor_state_t *state, const struct lwm2m_senml *input); static bool encode_repeated_record_bn(zcbor_state_t *state, const struct record_bn *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_int32_put(state, (-2)))) && - (zcbor_tstr_encode(state, (&(*input)._record_bn))))); + (zcbor_tstr_encode(state, (&(*input).record_bn))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -43,16 +47,19 @@ static bool encode_repeated_record_bn(zcbor_state_t *state, const struct record_ static bool encode_repeated_record_bt(zcbor_state_t *state, const struct record_bt *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_int32_put(state, (-3)))) && - ((((*input)._record_bt >= INT64_MIN) && ((*input)._record_bt <= INT64_MAX)) || + ((((*input).record_bt >= INT64_MIN) && ((*input).record_bt <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) && - (zcbor_int64_encode(state, (&(*input)._record_bt))))); + (zcbor_int64_encode(state, (&(*input).record_bt))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -60,13 +67,16 @@ static bool encode_repeated_record_bt(zcbor_state_t *state, const struct record_ static bool encode_repeated_record_n(zcbor_state_t *state, const struct record_n *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_uint32_put(state, (0)))) && - (zcbor_tstr_encode(state, (&(*input)._record_n))))); + (zcbor_tstr_encode(state, (&(*input).record_n))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -74,81 +84,98 @@ static bool encode_repeated_record_n(zcbor_state_t *state, const struct record_n static bool encode_repeated_record_t(zcbor_state_t *state, const struct record_t *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_uint32_put(state, (6)))) && - ((((*input)._record_t >= INT64_MIN) && ((*input)._record_t <= INT64_MAX)) || + ((((*input).record_t >= INT64_MIN) && ((*input).record_t <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) && - (zcbor_int64_encode(state, (&(*input)._record_t))))); + (zcbor_int64_encode(state, (&(*input).record_t))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool encode_repeated_record_union(zcbor_state_t *state, const struct record_union_ *input) +static bool encode_repeated_record_union(zcbor_state_t *state, const struct record_union_r *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); struct zcbor_string tmp_str; bool tmp_result = ((( - ((*input)._record_union_choice == _union_vi) + ((*input).record_union_choice == union_vi_c) ? (((zcbor_uint32_put(state, (2)))) && - ((((*input)._union_vi >= INT64_MIN) && - ((*input)._union_vi <= INT64_MAX)) || + ((((*input).union_vi >= INT64_MIN) && + ((*input).union_vi <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) && - (zcbor_int64_encode(state, (&(*input)._union_vi)))) - : (((*input)._record_union_choice == _union_vf) - ? (((zcbor_uint32_put(state, (2)))) && - (zcbor_float64_encode(state, (&(*input)._union_vf)))) - : (((*input)._record_union_choice == _union_vs) - ? (((zcbor_uint32_put(state, (3)))) && - (zcbor_tstr_encode(state, (&(*input)._union_vs)))) - : (((*input)._record_union_choice == _union_vb) - ? (((zcbor_uint32_put(state, (4)))) && - (zcbor_bool_encode(state, (&(*input)._union_vb)))) - : (((*input)._record_union_choice == _union_vd) - ? (((zcbor_uint32_put(state, (8)))) && - (zcbor_bstr_encode(state, (&(*input)._union_vd)))) - : (((*input)._record_union_choice == _union_vlo) - ? (((zcbor_tstr_encode(state, ((tmp_str.value = (uint8_t *)"vlo", - tmp_str.len = sizeof("vlo") - 1, - &tmp_str))))) && - (zcbor_tstr_encode(state, (&(*input)._union_vlo)))) - : false)))))))); + (zcbor_int64_encode(state, (&(*input).union_vi)))) + : (((*input).record_union_choice == union_vf_c) + ? (((zcbor_uint32_put(state, (2)))) && + (zcbor_float64_encode(state, (&(*input).union_vf)))) + : (((*input).record_union_choice == union_vs_c) + ? (((zcbor_uint32_put(state, (3)))) && + (zcbor_tstr_encode(state, (&(*input).union_vs)))) + : (((*input).record_union_choice == union_vb_c) + ? (((zcbor_uint32_put(state, (4)))) && + (zcbor_bool_encode(state, (&(*input).union_vb)))) + : (((*input).record_union_choice == union_vd_c) + ? (((zcbor_uint32_put(state, (8)))) && + (zcbor_bstr_encode(state, (&(*input).union_vd)))) + : (((*input).record_union_choice == union_vlo_c) + ? (((zcbor_tstr_encode( + state, + ((tmp_str.value = (uint8_t *)"vlo", + tmp_str.len = sizeof("vlo") - 1, + &tmp_str))))) && + (zcbor_tstr_encode( + state, + (&(*input).union_vlo)))) + : false)))))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool encode_value(zcbor_state_t *state, const struct value_ *input) +static bool encode_value(zcbor_state_t *state, const struct value_r *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((( - ((*input)._value_choice == _value_tstr) - ? ((zcbor_tstr_encode(state, (&(*input)._value_tstr)))) - : (((*input)._value_choice == _value_bstr) - ? ((zcbor_bstr_encode(state, (&(*input)._value_bstr)))) - : (((*input)._value_choice == _value_int) - ? (((((*input)._value_int >= INT64_MIN) && - ((*input)._value_int <= INT64_MAX)) || - (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) && - (zcbor_int64_encode(state, (&(*input)._value_int)))) - : (((*input)._value_choice == _value_float) - ? ((zcbor_float64_encode(state, (&(*input)._value_float)))) - : (((*input)._value_choice == _value_bool) - ? ((zcbor_bool_encode(state, (&(*input)._value_bool)))) - : false))))))); + ((*input).value_choice == value_tstr_c) + ? ((zcbor_tstr_encode(state, (&(*input).value_tstr)))) + : (((*input).value_choice == value_bstr_c) + ? ((zcbor_bstr_encode(state, (&(*input).value_bstr)))) + : (((*input).value_choice == value_int_c) + ? (((((*input).value_int >= INT64_MIN) && + ((*input).value_int <= INT64_MAX)) || + (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), + false)) && + (zcbor_int64_encode(state, (&(*input).value_int)))) + : (((*input).value_choice == value_float_c) + ? ((zcbor_float64_encode( + state, (&(*input).value_float)))) + : (((*input).value_choice == value_bool_c) + ? ((zcbor_bool_encode( + state, + (&(*input).value_bool)))) + : false))))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -156,27 +183,33 @@ static bool encode_value(zcbor_state_t *state, const struct value_ *input) static bool encode_key_value_pair(zcbor_state_t *state, const struct key_value_pair *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); - bool tmp_result = ((((zcbor_int32_encode(state, (&(*input)._key_value_pair_key)))) && - (encode_value(state, (&(*input)._key_value_pair))))); + bool tmp_result = ((((zcbor_int32_encode(state, (&(*input).key_value_pair_key)))) && + (encode_value(state, (&(*input).key_value_pair))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool encode_repeated_record__key_value_pair(zcbor_state_t *state, - const struct record__key_value_pair *input) +static bool encode_repeated_record_key_value_pair_m(zcbor_state_t *state, + const struct record_key_value_pair_m *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); - bool tmp_result = (((encode_key_value_pair(state, (&(*input)._record__key_value_pair))))); + bool tmp_result = (((encode_key_value_pair(state, (&(*input).record_key_value_pair_m))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -184,36 +217,34 @@ static bool encode_repeated_record__key_value_pair(zcbor_state_t *state, static bool encode_record(zcbor_state_t *state, const struct record *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = (( - (zcbor_map_start_encode(state, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair)) && - ((zcbor_present_encode(&((*input)._record_bn_present), - (zcbor_encoder_t *)encode_repeated_record_bn, state, - (&(*input)._record_bn)) && - zcbor_present_encode(&((*input)._record_bt_present), - (zcbor_encoder_t *)encode_repeated_record_bt, state, - (&(*input)._record_bt)) && - zcbor_present_encode(&((*input)._record_n_present), - (zcbor_encoder_t *)encode_repeated_record_n, state, - (&(*input)._record_n)) && - zcbor_present_encode(&((*input)._record_t_present), - (zcbor_encoder_t *)encode_repeated_record_t, state, - (&(*input)._record_t)) && - zcbor_present_encode(&((*input)._record_union_present), - (zcbor_encoder_t *)encode_repeated_record_union, state, - (&(*input)._record_union)) && + (zcbor_map_start_encode(state, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m)) && + (((!(*input).record_bn_present || + encode_repeated_record_bn(state, (&(*input).record_bn))) && + (!(*input).record_bt_present || + encode_repeated_record_bt(state, (&(*input).record_bt))) && + (!(*input).record_n_present || + encode_repeated_record_n(state, (&(*input).record_n))) && + (!(*input).record_t_present || + encode_repeated_record_t(state, (&(*input).record_t))) && + (!(*input).record_union_present || + encode_repeated_record_union(state, (&(*input).record_union))) && zcbor_multi_encode_minmax( - 0, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair), - &(*input)._record__key_value_pair_count, - (zcbor_encoder_t *)encode_repeated_record__key_value_pair, state, - (&(*input)._record__key_value_pair), - sizeof(struct record__key_value_pair))) || + 0, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m), + &(*input).record_key_value_pair_m_count, + (zcbor_encoder_t *)encode_repeated_record_key_value_pair_m, state, + (&(*input).record_key_value_pair_m), + sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_encode(state), false)) && - zcbor_map_end_encode(state, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair))))); + zcbor_map_end_encode(state, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -221,19 +252,22 @@ static bool encode_record(zcbor_state_t *state, const struct record *input) static bool encode_lwm2m_senml(zcbor_state_t *state, const struct lwm2m_senml *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = - (((zcbor_list_start_encode(state, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record)) && + (((zcbor_list_start_encode(state, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m)) && ((zcbor_multi_encode_minmax( - 1, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record), - &(*input)._lwm2m_senml__record_count, (zcbor_encoder_t *)encode_record, - state, (&(*input)._lwm2m_senml__record), sizeof(struct record))) || + 1, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m), + &(*input).lwm2m_senml_record_m_count, (zcbor_encoder_t *)encode_record, + state, (&(*input).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_encode(state), false)) && - zcbor_list_end_encode(state, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record))))); + zcbor_list_end_encode(state, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -244,19 +278,7 @@ int cbor_encode_lwm2m_senml(uint8_t *payload, size_t payload_len, const struct l { zcbor_state_t states[5]; - zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1); - - bool ret = encode_lwm2m_senml(states, input); - - if (ret && (payload_len_out != NULL)) { - *payload_len_out = MIN(payload_len, (size_t)states[0].payload - (size_t)payload); - } - - if (!ret) { - int err = zcbor_pop_error(states); - - zcbor_print("Return error: %d\r\n", err); - return (err == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : err; - } - return ZCBOR_SUCCESS; + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_lwm2m_senml, + sizeof(states) / sizeof(zcbor_state_t), 1); } diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h index 05d2664c2a0..49ce5c55159 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h index f1b86bb60b0..4c41385ba4b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ @@ -32,115 +32,97 @@ enum lwm2m_senml_cbor_key { lwm2m_senml_cbor_key_vd = 8, }; -/** Which value for --default-max-qty this file was created with. - * - * The define is used in the other generated file to do a build-time - * compatibility check. - * - * See `zcbor --help` for more information about --default-max-qty - */ -#define DEFAULT_MAX_QTY CONFIG_LWM2M_RW_SENML_CBOR_RECORDS - struct record_bn { - struct zcbor_string _record_bn; + struct zcbor_string record_bn; }; struct record_bt { - int64_t _record_bt; + int64_t record_bt; }; struct record_n { - struct zcbor_string _record_n; + struct zcbor_string record_n; }; struct record_t { - int64_t _record_t; + int64_t record_t; }; -/* The union members and enum members have the same names. - * This is intentional so we need to ignore -Wshadow to avoid - * compiler complaining about them. - */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wshadow" - -struct record_union_ { +struct record_union_r { union { struct { - int64_t _union_vi; + int64_t union_vi; }; struct { - double _union_vf; + double union_vf; }; struct { - struct zcbor_string _union_vs; + struct zcbor_string union_vs; }; struct { - bool _union_vb; + bool union_vb; }; struct { - struct zcbor_string _union_vd; + struct zcbor_string union_vd; }; struct { - struct zcbor_string _union_vlo; + struct zcbor_string union_vlo; }; }; enum { - _union_vi, - _union_vf, - _union_vs, - _union_vb, - _union_vd, - _union_vlo, - } _record_union_choice; + union_vi_c, + union_vf_c, + union_vs_c, + union_vb_c, + union_vd_c, + union_vlo_c, + } record_union_choice; }; -struct value_ { +struct value_r { union { - struct zcbor_string _value_tstr; - struct zcbor_string _value_bstr; - int64_t _value_int; - double _value_float; - bool _value_bool; + struct zcbor_string value_tstr; + struct zcbor_string value_bstr; + int64_t value_int; + double value_float; + bool value_bool; }; enum { - _value_tstr, - _value_bstr, - _value_int, - _value_float, - _value_bool, - } _value_choice; + value_tstr_c, + value_bstr_c, + value_int_c, + value_float_c, + value_bool_c, + } value_choice; }; -#pragma GCC diagnostic pop - struct key_value_pair { - int32_t _key_value_pair_key; - struct value_ _key_value_pair; + int32_t key_value_pair_key; + struct value_r key_value_pair; }; -struct record__key_value_pair { - struct key_value_pair _record__key_value_pair; +struct record_key_value_pair_m { + struct key_value_pair record_key_value_pair_m; }; struct record { - struct record_bn _record_bn; - bool _record_bn_present; - struct record_bt _record_bt; - bool _record_bt_present; - struct record_n _record_n; - bool _record_n_present; - struct record_t _record_t; - bool _record_t_present; - struct record_union_ _record_union; - bool _record_union_present; - struct record__key_value_pair _record__key_value_pair[5]; - size_t _record__key_value_pair_count; + struct record_bn record_bn; + bool record_bn_present; + struct record_bt record_bt; + bool record_bt_present; + struct record_n record_n; + bool record_n_present; + struct record_t record_t; + bool record_t_present; + struct record_union_r record_union; + bool record_union_present; + struct record_key_value_pair_m record_key_value_pair_m[5]; + size_t record_key_value_pair_m_count; }; struct lwm2m_senml { - struct record _lwm2m_senml__record[DEFAULT_MAX_QTY]; - size_t _lwm2m_senml__record_count; + struct record lwm2m_senml_record_m[CONFIG_LWM2M_RW_SENML_CBOR_RECORDS]; + size_t lwm2m_senml_record_m_count; }; #ifdef __cplusplus From 0014f3dc4dda0142561b6495fc9213a4eacf8c27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Wed, 10 Jan 2024 14:39:42 +0100 Subject: [PATCH 1463/1623] [nrf fromtree] mgmt: Adapt to API changes in zcbor 0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zcbor_new_state and zcbor_tstr_put_term Signed-off-by: Øyvind Rønningstad (cherry picked from commit 527af809f88166725ae1ac432851d0e81e97e56d) --- include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h | 3 ++- subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c | 2 +- subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c | 4 ++-- .../mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c | 6 +++--- subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c | 2 +- .../mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c | 7 ++++--- subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig | 9 ++++++--- subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c | 5 +++-- subsys/mgmt/mcumgr/smp/src/smp.c | 4 ++-- 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h b/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h index 0b12ccdb684..ba63c136f50 100644 --- a/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h +++ b/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h @@ -45,11 +45,12 @@ void os_mgmt_client_init(struct os_mgmt_client *client, struct smp_client_object * * @param client OS mgmt client object * @param echo_string Echo string + * @param max_len Max length of @p echo_string * * @return 0 on success. * @return @ref mcumgr_err_t code on failure. */ -int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string); +int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string, size_t max_len); /** * @brief Send SMP Reset command. diff --git a/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c b/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c index 3458c3d6f8b..ae75aea9140 100644 --- a/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c @@ -783,7 +783,7 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt) } ok &= zcbor_tstr_put_lit(zse, "type") && - zcbor_tstr_put_term(zse, type_arr); + zcbor_tstr_put_term(zse, type_arr, sizeof(type_arr)); if (off != 0) { ok &= zcbor_tstr_put_lit(zse, "off") && diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c index 61515c14655..edfe26e452f 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c @@ -443,11 +443,11 @@ static bool img_mgmt_state_encode_slot(zcbor_state_t *zse, uint32_t slot, int st ok = zcbor_tstr_put_lit(zse, "<\?\?\?>"); } else { vers_str[sizeof(vers_str) - 1] = '\0'; - ok = zcbor_tstr_put_term(zse, vers_str); + ok = zcbor_tstr_put_term(zse, vers_str, sizeof(vers_str)); } } - ok = ok && zcbor_tstr_put_term(zse, "hash") && + ok = ok && zcbor_tstr_put_lit(zse, "hash") && zcbor_bstr_encode(zse, &zhash) && ZCBOR_ENCODE_FLAG(zse, "bootable", !(flags & IMAGE_F_NON_BOOTABLE)) && ZCBOR_ENCODE_FLAG(zse, "pending", state_flags & REPORT_SLOT_PENDING) && diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c b/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c index 9ab8ee02dcd..b8cbc38b275 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c @@ -74,7 +74,7 @@ static int image_state_res_fn(struct net_buf *nb, void *user_data) goto out; } - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_start_decode(zsd); if (!ok) { @@ -201,7 +201,7 @@ static int image_upload_res_fn(struct net_buf *nb, void *user_data) goto end; } - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0); rc = zcbor_map_decode_bulk(zsd, upload_res_decode, ARRAY_SIZE(upload_res_decode), &decoded); if (rc || image_upload_buf->image_upload_offset == SIZE_MAX) { @@ -233,7 +233,7 @@ static int erase_res_fn(struct net_buf *nb, void *user_data) goto end; } - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0); rc = zcbor_map_decode_bulk(zsd, upload_res_decode, ARRAY_SIZE(upload_res_decode), &decoded); if (rc) { diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c b/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c index 13de45f02a9..d5244cb07d8 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c @@ -207,7 +207,7 @@ os_mgmt_taskstat_encode_thread_name(zcbor_state_t *zse, int idx, snprintf(thread_name, sizeof(thread_name) - 1, "%d", idx); thread_name[sizeof(thread_name) - 1] = 0; - return zcbor_tstr_put_term(zse, thread_name); + return zcbor_tstr_put_term(zse, thread_name, sizeof(thread_name)); } #endif diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c b/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c index 2bd804494c4..0bd174d1c97 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c +++ b/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c @@ -104,7 +104,7 @@ static int echo_res_fn(struct net_buf *nb, void *user_data) } /* Init ZCOR decoder state */ - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, echo_response, ARRAY_SIZE(echo_response), &decoded) == 0; @@ -119,7 +119,7 @@ static int echo_res_fn(struct net_buf *nb, void *user_data) return rc; } -int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string) +int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string, size_t max_len) { struct net_buf *nb; int rc; @@ -138,7 +138,8 @@ int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string) zcbor_new_encode_state(zse, ARRAY_SIZE(zse), nb->data + nb->len, net_buf_tailroom(nb), 0); ok = zcbor_map_start_encode(zse, 2) && - zcbor_tstr_put_lit(zse, "d") && zcbor_tstr_put_term(zse, echo_string) && + zcbor_tstr_put_lit(zse, "d") && + zcbor_tstr_put_term(zse, echo_string, max_len) && zcbor_map_end_encode(zse, 2); if (!ok) { diff --git a/subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig b/subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig index 757d290d10d..1ab882c33ee 100644 --- a/subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig +++ b/subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig @@ -28,9 +28,12 @@ config MCUMGR_GRP_STAT_MAX_NAME_LEN depends on MCUMGR_GRP_STAT help Limits the maximum stat group name length in MCUmgr requests, in bytes. - A buffer of this size gets allocated on the stack during handling of all - stat read commands. If a stat group's name exceeds this limit, it will - be impossible to retrieve its values with a stat show command. + For stat group names. a buffer of this size gets allocated on the stack + during handling of all stat read commands. If a stat group's name + exceeds this limit, it will be impossible to retrieve its values with + a stat show command. + For stat names s_name and snm_name, this is the maximum length when + encoding the name to cbor. module = MCUMGR_GRP_STAT module-str = mcumgr_grp_stat diff --git a/subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c b/subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c index 4740073cf01..29e546bdb86 100644 --- a/subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c @@ -110,7 +110,7 @@ stat_mgmt_foreach_entry(zcbor_state_t *zse, const char *group_name, stat_mgmt_fo static int stat_mgmt_cb_encode(zcbor_state_t *zse, struct stat_mgmt_entry *entry) { - bool ok = zcbor_tstr_put_term(zse, entry->name) && + bool ok = zcbor_tstr_put_term(zse, entry->name, CONFIG_MCUMGR_GRP_STAT_MAX_NAME_LEN) && zcbor_uint32_put(zse, entry->value); return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE; @@ -215,7 +215,8 @@ stat_mgmt_list(struct smp_streamer *ctxt) do { cur = stats_group_get_next(cur); if (cur != NULL) { - ok = zcbor_tstr_put_term(zse, cur->s_name); + ok = zcbor_tstr_put_term(zse, cur->s_name, + CONFIG_MCUMGR_GRP_STAT_MAX_NAME_LEN); } } while (ok && cur != NULL); diff --git a/subsys/mgmt/mcumgr/smp/src/smp.c b/subsys/mgmt/mcumgr/smp/src/smp.c index a97beebddaa..902979d9faf 100644 --- a/subsys/mgmt/mcumgr/smp/src/smp.c +++ b/subsys/mgmt/mcumgr/smp/src/smp.c @@ -53,7 +53,7 @@ static void cbor_nb_reader_init(struct cbor_nb_reader *cnr, struct net_buf *nb) { cnr->nb = nb; zcbor_new_decode_state(cnr->zs, ARRAY_SIZE(cnr->zs), nb->data, - nb->len, 1); + nb->len, 1, NULL, 0); } static void cbor_nb_writer_init(struct cbor_nb_writer *cnw, struct net_buf *nb) @@ -125,7 +125,7 @@ static int smp_build_err_rsp(struct smp_streamer *streamer, const struct smp_hdr #ifdef CONFIG_MCUMGR_SMP_VERBOSE_ERR_RESPONSE if (ok && rc_rsn != NULL) { ok = zcbor_tstr_put_lit(zsp, "rsn") && - zcbor_tstr_put_term(zsp, rc_rsn); + zcbor_tstr_put_term(zsp, rc_rsn, CONFIG_ZCBOR_MAX_STR_LEN); } #else ARG_UNUSED(rc_rsn); From f4cd3d3c14b4d8d3738409a29246fa6fa0af1292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Wed, 10 Jan 2024 14:39:42 +0100 Subject: [PATCH 1464/1623] [nrf fromtree] tests: mgmt: Adapt to API changes in zcbor 0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zcbor_new_state and zcbor_tstr_put_term Signed-off-by: Øyvind Rønningstad (cherry picked from commit 223b4c372f3af02e55980526256482d2a8b3e70b) --- .../cb_notifications/src/smp_test_util.c | 2 +- .../mcumgr/fs_mgmt_hash_supported/src/main.c | 2 +- .../mcumgr/mcumgr_client/src/img_gr_stub.c | 11 +++-- .../mgmt/mcumgr/mcumgr_client/src/main.c | 4 +- .../mcumgr/mcumgr_client/src/os_gr_stub.c | 3 +- .../mgmt/mcumgr/os_mgmt_datetime/src/main.c | 44 +++++++++---------- .../os_mgmt_datetime/src/smp_test_util.c | 6 +-- .../mgmt/mcumgr/os_mgmt_info/src/build_date.c | 4 +- .../mgmt/mcumgr/os_mgmt_info/src/limited.c | 6 +-- .../mgmt/mcumgr/os_mgmt_info/src/main.c | 44 +++++++++---------- .../mcumgr/os_mgmt_info/src/smp_test_util.c | 2 +- .../mgmt/mcumgr/settings_mgmt/src/main.c | 14 +++--- .../mcumgr/settings_mgmt/src/smp_test_util.c | 18 ++++---- .../subsys/mgmt/mcumgr/smp_version/src/main.c | 6 +-- .../mcumgr/smp_version/src/smp_test_util.c | 2 +- .../subsys/mgmt/mcumgr/zcbor_bulk/src/main.c | 22 +++++----- 16 files changed, 97 insertions(+), 93 deletions(-) diff --git a/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c index a20f948f30b..270f232af77 100644 --- a/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c @@ -29,7 +29,7 @@ bool create_mcumgr_format_packet(zcbor_state_t *zse, uint8_t *buffer, uint8_t *o ok = zcbor_map_start_encode(zse, 2) && zcbor_tstr_put_lit(zse, "d") && - zcbor_tstr_put_term(zse, "some test data") && + zcbor_tstr_put_lit(zse, "some test data") && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); diff --git a/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c b/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c index a5cafef589d..30575172a84 100644 --- a/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c +++ b/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c @@ -97,7 +97,7 @@ ZTEST(fs_mgmt_hash_supported, test_supported) /* Search expected type array for this type and update details */ zcbor_new_decode_state(state, 10, &nb->data[sizeof(struct smp_hdr)], - (nb->len - sizeof(struct smp_hdr)), 1); + (nb->len - sizeof(struct smp_hdr)), 1, NULL, 0); ok = zcbor_map_start_decode(state); diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c index aea03935fe6..9b12fd7b2b0 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c @@ -120,9 +120,10 @@ void img_read_response(int count) zcbor_tstr_put_lit(zse, "slot") && zcbor_uint32_put(zse, image_dummy_info[i].slot_num) && zcbor_tstr_put_lit(zse, "version") && - zcbor_tstr_put_term(zse, image_dummy_info[i].version) && + zcbor_tstr_put_term(zse, image_dummy_info[i].version, + sizeof(image_dummy_info[i].version)) && - zcbor_tstr_put_term(zse, "hash") && + zcbor_tstr_put_lit(zse, "hash") && zcbor_bstr_encode_ptr(zse, image_dummy_info[i].hash, IMG_MGMT_DATA_SHA_LEN) && ZCBOR_ENCODE_FLAG(zse, "bootable", image_dummy_info[i].flags.bootable) && ZCBOR_ENCODE_FLAG(zse, "pending", image_dummy_info[i].flags.pending) && @@ -180,7 +181,8 @@ void img_state_write_verify(struct net_buf *nb) ZCBOR_MAP_DECODE_KEY_DECODER("hash", zcbor_bstr_decode, &hash) }; - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1, + NULL, 0); decoded = 0; /* Init buffer values */ @@ -231,7 +233,8 @@ void img_upload_init_verify(struct net_buf *nb) ZCBOR_MAP_DECODE_KEY_DECODER("sha", zcbor_bstr_decode, &sha) }; - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1, + NULL, 0); decoded = 0; /* Init buffer values */ diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c index bf70f178fe7..c724c72c2cc 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c @@ -225,12 +225,12 @@ ZTEST(mcumgr_client, test_os_echo) smp_stub_set_rx_data_verify(NULL); smp_client_send_status_stub(MGMT_ERR_EOK); /* Test timeout */ - rc = os_mgmt_client_echo(&os_client, os_echo_test); + rc = os_mgmt_client_echo(&os_client, os_echo_test, sizeof(os_echo_test)); zassert_equal(MGMT_ERR_ETIMEOUT, rc, "Expected to receive %d response %d", MGMT_ERR_ETIMEOUT, rc); /* Test successfully operation */ smp_stub_set_rx_data_verify(os_echo_verify); - rc = os_mgmt_client_echo(&os_client, os_echo_test); + rc = os_mgmt_client_echo(&os_client, os_echo_test, sizeof(os_echo_test)); zassert_equal(MGMT_ERR_EOK, rc, "Expected to receive %d response %d", MGMT_ERR_EOK, rc); } diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c index 888f00dba38..c7196874556 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c @@ -81,7 +81,8 @@ void os_echo_verify(struct net_buf *nb) ZCBOR_MAP_DECODE_KEY_DECODER("d", zcbor_tstr_decode, &echo_data) }; - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1, + NULL, 0); echo_data.len = 0; rc = zcbor_map_decode_bulk(zsd, list_res_decode, ARRAY_SIZE(list_res_decode), &decoded); diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c index c387c3b4812..05adb1d6de4 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c @@ -191,7 +191,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_get_not_set_v1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -253,7 +253,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_get_not_set_v2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -318,7 +318,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -365,7 +365,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -428,7 +428,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -475,7 +475,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -538,7 +538,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_3) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -585,7 +585,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_3) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -648,7 +648,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -695,7 +695,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -760,7 +760,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -807,7 +807,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -872,7 +872,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_3) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -919,7 +919,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_3) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -984,7 +984,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1030,7 +1030,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1098,7 +1098,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1144,7 +1144,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1225,7 +1225,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1287,7 +1287,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1357,7 +1357,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1418,7 +1418,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c index 927089c3ee3..d2b969999cd 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c @@ -49,9 +49,9 @@ bool create_mcumgr_datetime_set_packet_str(zcbor_state_t *zse, bool version2, co uint8_t *buffer, uint8_t *output_buffer, uint16_t *buffer_size) { - bool ok = zcbor_map_start_encode(zse, 2) && - zcbor_tstr_put_lit(zse, "datetime") && - zcbor_tstr_put_term(zse, data) && + bool ok = zcbor_map_start_encode(zse, 2) && + zcbor_tstr_put_lit(zse, "datetime") && + zcbor_tstr_put_term(zse, data, CONFIG_ZCBOR_MAX_STR_LEN) && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c index 4af977895c3..5674e338dfa 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c @@ -121,7 +121,7 @@ ZTEST(os_mgmt_info_build_date, test_info_build_date_1_build_date) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -197,7 +197,7 @@ ZTEST(os_mgmt_info_build_date, test_info_build_date_2_all) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c index f8899734351..613402e1624 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c @@ -81,7 +81,7 @@ ZTEST(os_mgmt_info_limited, test_info_1_kernel_name) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -147,7 +147,7 @@ ZTEST(os_mgmt_info_limited, test_info_2_all) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); /* Ensure only an error is received */ ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -155,7 +155,7 @@ ZTEST(os_mgmt_info_limited, test_info_2_all) zassert_true(ok, "Expected decode to be successful\n"); zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n"); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c index 8ffc2a354b8..6e8cc61098d 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c @@ -338,7 +338,7 @@ ZTEST(os_mgmt_info, test_info_2_kernel_name) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -399,7 +399,7 @@ ZTEST(os_mgmt_info, test_info_3_node_name) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -461,7 +461,7 @@ ZTEST(os_mgmt_info, test_info_4_kernel_release) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -523,7 +523,7 @@ ZTEST(os_mgmt_info, test_info_5_kernel_version) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -584,7 +584,7 @@ ZTEST(os_mgmt_info, test_info_6_machine) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -645,7 +645,7 @@ ZTEST(os_mgmt_info, test_info_7_processor) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -706,7 +706,7 @@ ZTEST(os_mgmt_info, test_info_8_platform) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -778,7 +778,7 @@ ZTEST(os_mgmt_info, test_info_9_os) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -839,7 +839,7 @@ ZTEST(os_mgmt_info, test_info_10_all) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -914,7 +914,7 @@ ZTEST(os_mgmt_info, test_info_11_multi_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -979,7 +979,7 @@ ZTEST(os_mgmt_info, test_info_12_multi_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1051,7 +1051,7 @@ ZTEST(os_mgmt_info, test_info_13_invalid_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); /* Ensure only an error is received */ ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1059,7 +1059,7 @@ ZTEST(os_mgmt_info, test_info_13_invalid_1) zassert_true(ok, "Expected decode to be successful\n"); zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n"); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); @@ -1122,7 +1122,7 @@ ZTEST(os_mgmt_info, test_info_14_invalid_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); /* Ensure only an error is received */ ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1130,7 +1130,7 @@ ZTEST(os_mgmt_info, test_info_14_invalid_2) zassert_true(ok, "Expected decode to be successful\n"); zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n"); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); @@ -1199,7 +1199,7 @@ ZTEST(os_mgmt_info_custom_os, test_info_os_custom) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1260,7 +1260,7 @@ ZTEST(os_mgmt_info_custom_os_disabled, test_info_os_custom_disabled) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1333,7 +1333,7 @@ ZTEST(os_mgmt_info_custom_cmd, test_info_cmd_custom) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1399,14 +1399,14 @@ ZTEST(os_mgmt_info_custom_cmd_disabled, test_info_cmd_custom_disabled) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n"); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); @@ -1468,14 +1468,14 @@ ZTEST(os_mgmt_info_custom_cmd_disabled_verify, test_info_cmd_custom_disabled) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n"); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c index c1dcded0ff6..b76ac1ad623 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c @@ -31,7 +31,7 @@ bool create_mcumgr_format_packet(zcbor_state_t *zse, const uint8_t *format, uint ok = zcbor_map_start_encode(zse, 2) && zcbor_tstr_put_lit(zse, "format") && - zcbor_tstr_put_term(zse, format) && + zcbor_tstr_put_term(zse, format, CONFIG_ZCBOR_MAX_STR_LEN) && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); diff --git a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c index 745fa333790..869a4f750d9 100644 --- a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c +++ b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c @@ -487,7 +487,7 @@ ZTEST(settings_mgmt, test_set_read) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -590,7 +590,7 @@ ZTEST(settings_mgmt, test_read_max_size) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 2, "Expected to receive 2 decoded zcbor elements"); @@ -745,7 +745,7 @@ ZTEST(settings_mgmt, test_set_disallowed) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element"); @@ -875,7 +875,7 @@ ZTEST(settings_mgmt, test_set_disallowed) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element"); @@ -1147,7 +1147,7 @@ ZTEST(settings_mgmt, test_delete) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element"); @@ -1274,7 +1274,7 @@ ZTEST(settings_mgmt, test_delete) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element"); @@ -1519,7 +1519,7 @@ ZTEST(settings_mgmt, test_delete) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element"); diff --git a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c index 63b91151797..dcabd0d08c3 100644 --- a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c @@ -31,7 +31,7 @@ bool create_settings_mgmt_read_packet(zcbor_state_t *zse, uint8_t *buffer, uint8 ok = zcbor_map_start_encode(zse, 2) && zcbor_tstr_put_lit(zse, "name") && - zcbor_tstr_put_term(zse, name) && + zcbor_tstr_put_term(zse, name, CONFIG_ZCBOR_MAX_STR_LEN) && (max_size == 0 || (zcbor_tstr_put_lit(zse, "max_size") && zcbor_uint32_put(zse, max_size))) && zcbor_map_end_encode(zse, 2); @@ -51,11 +51,11 @@ bool create_settings_mgmt_write_packet(zcbor_state_t *zse, uint8_t *buffer, uint { bool ok; - ok = zcbor_map_start_encode(zse, 2) && - zcbor_tstr_put_lit(zse, "name") && - zcbor_tstr_put_term(zse, name) && - zcbor_tstr_put_lit(zse, "val") && - zcbor_bstr_encode_ptr(zse, val, val_size) && + ok = zcbor_map_start_encode(zse, 2) && + zcbor_tstr_put_lit(zse, "name") && + zcbor_tstr_put_term(zse, name, CONFIG_ZCBOR_MAX_STR_LEN) && + zcbor_tstr_put_lit(zse, "val") && + zcbor_bstr_encode_ptr(zse, val, val_size) && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); @@ -72,9 +72,9 @@ bool create_settings_mgmt_delete_packet(zcbor_state_t *zse, uint8_t *buffer, { bool ok; - ok = zcbor_map_start_encode(zse, 2) && - zcbor_tstr_put_lit(zse, "name") && - zcbor_tstr_put_term(zse, name) && + ok = zcbor_map_start_encode(zse, 2) && + zcbor_tstr_put_lit(zse, "name") && + zcbor_tstr_put_term(zse, name, CONFIG_ZCBOR_MAX_STR_LEN) && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); diff --git a/tests/subsys/mgmt/mcumgr/smp_version/src/main.c b/tests/subsys/mgmt/mcumgr/smp_version/src/main.c index 8676678336e..ed596ae964e 100644 --- a/tests/subsys/mgmt/mcumgr/smp_version/src/main.c +++ b/tests/subsys/mgmt/mcumgr/smp_version/src/main.c @@ -155,7 +155,7 @@ ZTEST(smp_version, test_legacy_command) zassert_equal(smp_header->nh_version, LEGACY_VERSION, "Expected response header version mismatch"); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -242,7 +242,7 @@ ZTEST(smp_version, test_current_command) zassert_equal(smp_header->nh_version, CURRENT_VERSION, "Expected response header version mismatch"); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -328,7 +328,7 @@ ZTEST(smp_version, test_new_command) zassert_equal(smp_header->nh_version, CURRENT_VERSION, "Expected response header version mismatch"); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); diff --git a/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c index e93ad69ff2a..96d97a6b6fa 100644 --- a/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c @@ -32,7 +32,7 @@ bool create_mcumgr_format_packet(zcbor_state_t *zse, const uint8_t *format, uint ok = zcbor_map_start_encode(zse, 2) && zcbor_tstr_put_lit(zse, "format") && - zcbor_tstr_put_term(zse, format) && + zcbor_tstr_put_term(zse, format, CONFIG_ZCBOR_MAX_STR_LEN) && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); diff --git a/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c b/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c index e50dc8fe51f..b1d3d79b30a 100644 --- a/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c +++ b/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c @@ -60,7 +60,7 @@ ZTEST(zcbor_bulk, test_correct) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -101,7 +101,7 @@ ZTEST(zcbor_bulk, test_correct_out_of_order) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -140,7 +140,7 @@ ZTEST(zcbor_bulk, test_not_map) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -175,7 +175,7 @@ ZTEST(zcbor_bulk, test_bad_type) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -211,7 +211,7 @@ ZTEST(zcbor_bulk, test_bad_type_2) zcbor_tstr_put_lit(zsd, "bool val") && zcbor_true_put(zsd) && zcbor_map_end_encode(zsd, 10); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -252,7 +252,7 @@ ZTEST(zcbor_bulk, test_bad_type_encoded) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -287,7 +287,7 @@ ZTEST(zcbor_bulk, test_duplicate) zcbor_tstr_put_lit(zsd, "hello") && zcbor_tstr_put_lit(zsd, "world") && zcbor_map_end_encode(zsd, 10); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -366,7 +366,7 @@ ZTEST(zcbor_bulk, test_map_in_map_correct) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -445,7 +445,7 @@ ZTEST(zcbor_bulk, test_map_in_map_bad) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -486,7 +486,7 @@ ZTEST(zcbor_bulk, test_key_found) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -528,7 +528,7 @@ ZTEST(zcbor_bulk, test_reset) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); From 5a0e16d090126266dd5fa2d07b9cf01b51aa339a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Fri, 26 Jan 2024 13:27:12 +0100 Subject: [PATCH 1465/1623] [nrf fromtree] west.yml: Update zcbor from 0.8.0 to 0.8.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Brings a few improvements and bugfixes, most notably: - Adds a forward declaration of strnlen() - Adds a ZCBOR_VERSION macro Signed-off-by: Øyvind Rønningstad (cherry picked from commit 8396bf0d9843439dfa558f2d391ed60c71c378fd) --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 18e4ba0ab58..03a830da77c 100644 --- a/west.yml +++ b/west.yml @@ -335,7 +335,7 @@ manifest: revision: 150f4eb2955eaf36ac0f9519d4f4f58d5ade5740 path: modules/lib/uoscore-uedhoc - name: zcbor - revision: dbe20afd00b3ddd6956f4b47f5df202bb49a8707 + revision: d3093b5684f62268c7f27f8a5079f166772619de path: modules/lib/zcbor self: From c5c7fb3967905dcaef1035ac8d5b234176a2cc0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Fri, 26 Jan 2024 15:17:44 +0100 Subject: [PATCH 1466/1623] [nrf fromtree] lwm2m: Regenerate zcbor files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit with zcbor 0.8.1 Signed-off-by: Øyvind Rønningstad (cherry picked from commit 3ad47d214a7d5b5af233060413e92e97a21b13e4) --- subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch | 10 +++++----- subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c | 2 +- subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h | 2 +- subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c | 2 +- subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h | 2 +- subsys/net/lib/lwm2m/lwm2m_senml_cbor_regenerate.sh | 2 +- subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch b/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch index 81ec06bab8b..41bb3f0a5d4 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch @@ -5,7 +5,7 @@ index c12f477cce..f41b81275d 100644 @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.8.0 + * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 @@ -47,7 +47,7 @@ index a36f8782c6..b913fb78e9 100644 @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.8.0 + * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 @@ -72,7 +72,7 @@ index 94926c531f..5521917853 100644 @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.8.0 + * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 @@ -120,7 +120,7 @@ index df2f0ac6a1..8fa1eedb2b 100644 @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.8.0 + * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 @@ -145,7 +145,7 @@ index 77649036ef..f0a2958072 100644 @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.8.0 + * Generated using zcbor version 0.8.1 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c index 3906d476cac..28b0265b9cc 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.8.0 + * Generated using zcbor version 0.8.1 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h index b47b79de615..4e1fdeb66a2 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.8.0 + * Generated using zcbor version 0.8.1 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c index 9cf4f3457c6..14ec7431e5b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.8.0 + * Generated using zcbor version 0.8.1 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h index 49ce5c55159..fc08ead18d4 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.8.0 + * Generated using zcbor version 0.8.1 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_regenerate.sh b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_regenerate.sh index 448a9020862..cf293d7b579 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_regenerate.sh +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_regenerate.sh @@ -12,7 +12,7 @@ SPDX-License-Identifier: Apache-2.0 git add -A git commit -s -m"pre-patch" -git apply lwm2m_senml_cbor.patch +git apply --reject lwm2m_senml_cbor.patch clang-format -i \ lwm2m_senml_cbor_decode.c lwm2m_senml_cbor_decode.h \ diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h index 4c41385ba4b..dbb5a368551 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.8.0 + * Generated using zcbor version 0.8.1 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ From 166f0c03cc452794c6446e7482a78e835fb435e2 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Fri, 23 Jun 2023 13:11:20 +0200 Subject: [PATCH 1467/1623] [nrf fromlist] drivers: Add flash driver for RRAM Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68309 Added a simple driver for RRAM. It is implemented as a flash driver, because the "RRAM eFlash" macro obeys flash-like constraints. Although users are not required to erase before write. Signed-off-by: Jakub Zymelka --- drivers/flash/CMakeLists.txt | 1 + drivers/flash/Kconfig | 2 + drivers/flash/Kconfig.nrf_rram | 38 ++++ drivers/flash/soc_flash_nrf_rram.c | 180 ++++++++++++++++++ .../nordic,rram-controller.yaml | 16 ++ 5 files changed, 237 insertions(+) create mode 100644 drivers/flash/Kconfig.nrf_rram create mode 100644 drivers/flash/soc_flash_nrf_rram.c create mode 100644 dts/bindings/flash_controller/nordic,rram-controller.yaml diff --git a/drivers/flash/CMakeLists.txt b/drivers/flash/CMakeLists.txt index 4a02268a2b4..7426b43b089 100644 --- a/drivers/flash/CMakeLists.txt +++ b/drivers/flash/CMakeLists.txt @@ -118,3 +118,4 @@ zephyr_library_sources_ifdef(CONFIG_FLASH_SHELL flash_shell.c) zephyr_library_sources_ifdef(CONFIG_FLASH_JESD216 jesd216.c) zephyr_library_sources_ifdef(CONFIG_FLASH_INFINEON_CAT1 flash_ifx_cat1.c) zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_NUMAKER soc_flash_numaker.c) +zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_NRF_RRAM soc_flash_nrf_rram.c) diff --git a/drivers/flash/Kconfig b/drivers/flash/Kconfig index 698190e7780..03d4d07a193 100644 --- a/drivers/flash/Kconfig +++ b/drivers/flash/Kconfig @@ -160,4 +160,6 @@ source "drivers/flash/Kconfig.andes" source "drivers/flash/Kconfig.ambiq" +source "drivers/flash/Kconfig.nrf_rram" + endif # FLASH diff --git a/drivers/flash/Kconfig.nrf_rram b/drivers/flash/Kconfig.nrf_rram new file mode 100644 index 00000000000..6d100dabab6 --- /dev/null +++ b/drivers/flash/Kconfig.nrf_rram @@ -0,0 +1,38 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +menuconfig SOC_FLASH_NRF_RRAM + bool "Nordic Semiconductor flash driver for nRF RRAM" + default y + depends on DT_HAS_NORDIC_RRAM_CONTROLLER_ENABLED + select FLASH_HAS_DRIVER_ENABLED + select FLASH_HAS_PAGE_LAYOUT + select FLASH_NRF_FORCE_ALT + select MPU_ALLOW_FLASH_WRITE if ARM_MPU + help + Enables Nordic Semiconductor flash driver for nRF RRAM controllers. + The entire contiguous block of RRAM gets logically divided into pages, + but partial erase is always supported. + +if SOC_FLASH_NRF_RRAM + +config NRF_RRAM_WRITE_BUFFER_SIZE + int "Internal write-buffer size" + default 0 + range 0 32 + help + Number of 128-bit words. + Maximum buffer size can be configured to the value of 32 (128-bit words). + Set 0 to disable write-buffer. + +config NRF_RRAM_READYNEXT_TIMEOUT_VALUE + int "Preload timeout value for waiting for a next write in RRAMC clock cycles" + default 128 + range 0 4095 + help + Set 0 to disable ready next timeout counter. + +endif # SOC_FLASH_NRF_RRAM diff --git a/drivers/flash/soc_flash_nrf_rram.c b/drivers/flash/soc_flash_nrf_rram.c new file mode 100644 index 00000000000..76a855b9787 --- /dev/null +++ b/drivers/flash/soc_flash_nrf_rram.c @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT nordic_rram_controller + +#include +#include +#include +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(flash_nrf_rram, CONFIG_FLASH_LOG_LEVEL); + +#define RRAM DT_INST(0, soc_nv_flash) + +#define RRAM_START DT_REG_ADDR(RRAM) +#define RRAM_SIZE DT_REG_SIZE(RRAM) + +#define RRAM_WORD_SIZE 4 + +#define PAGE_SIZE DT_PROP(RRAM, erase_block_size) +#define PAGE_COUNT ((RRAM_SIZE) / (PAGE_SIZE)) + +#define ERASE_VALUE 0xFF + +#if CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE > 0 +#define WRITE_BUFFER_ENABLE 1 +#define WRITE_BUFFER_SIZE CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE +#define WRITE_LINE_SIZE 16 /* In bytes, one line is 128 bits. */ +#else +#define WRITE_BUFFER_ENABLE 0 +#define WRITE_BUFFER_SIZE 0 +#define WRITE_LINE_SIZE RRAM_WORD_SIZE +#endif + +static inline bool is_within_bounds(off_t addr, size_t len, off_t boundary_start, + size_t boundary_size) +{ + return (addr >= boundary_start && (addr < (boundary_start + boundary_size)) && + (len <= (boundary_start + boundary_size - addr))); +} + +#if WRITE_BUFFER_ENABLE +static void commit_changes(size_t len) +{ + if (nrf_rramc_empty_buffer_check(NRF_RRAMC)) { + /* The internal write-buffer has been committed to RRAM and is now empty. */ + return; + } + + if ((len % (WRITE_LINE_SIZE * WRITE_BUFFER_SIZE)) == 0) { + /* Our last operation was buffer size-aligned, so we're done. */ + return; + } + + nrf_rramc_task_trigger(NRF_RRAMC, NRF_RRAMC_TASK_COMMIT_WRITEBUF); + + barrier_dmem_fence_full(); +} +#endif + +static int rram_write(const struct device *dev, off_t addr, const void *data, size_t len) +{ + ARG_UNUSED(dev); + + if (!is_within_bounds(addr, len, 0, RRAM_SIZE)) { + return -EINVAL; + } + addr += RRAM_START; + + LOG_DBG("Write: %p:%zu", (void *)addr, len); + + nrf_rramc_config_t config = {.mode_write = true, .write_buff_size = WRITE_BUFFER_SIZE}; + + nrf_rramc_config_set(NRF_RRAMC, &config); + + if (data) { + memcpy((void *)addr, data, len); + } else { + memset((void *)addr, ERASE_VALUE, len); + } + + barrier_dmem_fence_full(); /* Barrier following our last write. */ + +#if WRITE_BUFFER_ENABLE + commit_changes(len); +#endif + + config.mode_write = false; + nrf_rramc_config_set(NRF_RRAMC, &config); + + return 0; +} + +static int flash_nrf_rram_read(const struct device *dev, off_t addr, void *data, size_t len) +{ + ARG_UNUSED(dev); + + if (!is_within_bounds(addr, len, 0, RRAM_SIZE)) { + return -EINVAL; + } + addr += RRAM_START; + + memcpy(data, (void *)addr, len); + + return 0; +} + +static int flash_nrf_rram_write(const struct device *dev, off_t addr, const void *data, size_t len) +{ + return rram_write(dev, addr, data, len); +} + +static int flash_nrf_rram_erase(const struct device *dev, off_t addr, size_t len) +{ + return rram_write(dev, addr, NULL, len); +} + +static const struct flash_parameters *flash_nrf_rram_get_parameters(const struct device *dev) +{ + ARG_UNUSED(dev); + + static const struct flash_parameters parameters = { + .write_block_size = WRITE_LINE_SIZE, + .erase_value = ERASE_VALUE, + }; + + return ¶meters; +} + +#if defined(CONFIG_FLASH_PAGE_LAYOUT) +static void flash_nrf_rram_page_layout(const struct device *dev, + const struct flash_pages_layout **layout, + size_t *layout_size) +{ + ARG_UNUSED(dev); + + static const struct flash_pages_layout pages_layout = { + .pages_count = PAGE_COUNT, + .pages_size = PAGE_SIZE, + }; + + *layout = &pages_layout; + *layout_size = 1; +} +#endif + +static const struct flash_driver_api flash_nrf_rram_api = { + .read = flash_nrf_rram_read, + .write = flash_nrf_rram_write, + .erase = flash_nrf_rram_erase, + .get_parameters = flash_nrf_rram_get_parameters, +#if defined(CONFIG_FLASH_PAGE_LAYOUT) + .page_layout = flash_nrf_rram_page_layout, +#endif +}; + +static int flash_nrf_rram_init(const struct device *dev) +{ + ARG_UNUSED(dev); + +#if CONFIG_NRF_RRAM_READYNEXT_TIMEOUT_VALUE > 0 + nrf_rramc_ready_next_timeout_t params = { + .value = CONFIG_NRF_RRAM_READYNEXT_TIMEOUT_VALUE, + .enable = true, + }; + nrf_rramc_ready_next_timeout_set(NRF_RRAMC, ¶ms); +#endif + + return 0; +} + +DEVICE_DT_INST_DEFINE(0, flash_nrf_rram_init, NULL, NULL, NULL, POST_KERNEL, + CONFIG_FLASH_INIT_PRIORITY, &flash_nrf_rram_api); diff --git a/dts/bindings/flash_controller/nordic,rram-controller.yaml b/dts/bindings/flash_controller/nordic,rram-controller.yaml new file mode 100644 index 00000000000..be764127f09 --- /dev/null +++ b/dts/bindings/flash_controller/nordic,rram-controller.yaml @@ -0,0 +1,16 @@ +# +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-4-Clause +# + +description: | + Nordic RRAMC (Resistive random access memory controller) + + The resistive random access memory controller (RRAMC) is used for writing + the internal RRAM memory, the secure information configuration registers (SICR), + and the user information configuration registers (UICR). + +compatible: "nordic,rram-controller" + +include: base.yaml From 54f071c8064eea36938ffd66952bc15848d2cd58 Mon Sep 17 00:00:00 2001 From: Andrzej Puzdrowski Date: Thu, 10 Aug 2023 15:33:30 +0200 Subject: [PATCH 1468/1623] [nrf fromlist] drivers/flash: add radio synchronization to RRAM Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68309 Added synchronization with BLE radio operation to the RRAM flash driver. The implementation is using framework which is already provided for nrf52's flash driver. Additional added resource locking mechanism while driver does writing which solves mutual exclusion write access problem. Signed-off-by: Andrzej Puzdrowski Signed-off-by: Jakub Zymelka --- drivers/flash/Kconfig.nrf_rram | 25 +++++ drivers/flash/soc_flash_nrf_rram.c | 142 ++++++++++++++++++++++++++--- 2 files changed, 154 insertions(+), 13 deletions(-) diff --git a/drivers/flash/Kconfig.nrf_rram b/drivers/flash/Kconfig.nrf_rram index 6d100dabab6..f6e3ccc6416 100644 --- a/drivers/flash/Kconfig.nrf_rram +++ b/drivers/flash/Kconfig.nrf_rram @@ -35,4 +35,29 @@ config NRF_RRAM_READYNEXT_TIMEOUT_VALUE help Set 0 to disable ready next timeout counter. +choice SOC_FLASH_NRF_RADIO_SYNC_CHOICE + prompt "Nordic nRFx flash driver synchronization" + default SOC_FLASH_NRF_RADIO_SYNC_TICKER if BT_LL_SW_SPLIT + default SOC_FLASH_NRF_RADIO_SYNC_NONE + help + synchronization between flash memory driver and radio. + +config SOC_FLASH_NRF_RADIO_SYNC_TICKER + bool "Nordic nRFx flash driver synchronized with radio" + depends on BT_LL_SW_SPLIT + help + Enable synchronization between flash memory driver and radio using + BLE LL controller ticker API. + +config SOC_FLASH_NRF_RADIO_SYNC_NONE + bool "none" + help + disable synchronization between flash memory driver and radio. +endchoice + +config SOC_FLASH_NRF_TIMEOUT_MULTIPLIER + int + depends on !SOC_FLASH_NRF_RADIO_SYNC_NONE + default 1 + endif # SOC_FLASH_NRF_RRAM diff --git a/drivers/flash/soc_flash_nrf_rram.c b/drivers/flash/soc_flash_nrf_rram.c index 76a855b9787..64780fc3013 100644 --- a/drivers/flash/soc_flash_nrf_rram.c +++ b/drivers/flash/soc_flash_nrf_rram.c @@ -15,6 +15,8 @@ #include #include +#include + LOG_MODULE_REGISTER(flash_nrf_rram, CONFIG_FLASH_LOG_LEVEL); #define RRAM DT_INST(0, soc_nv_flash) @@ -29,6 +31,11 @@ LOG_MODULE_REGISTER(flash_nrf_rram, CONFIG_FLASH_LOG_LEVEL); #define ERASE_VALUE 0xFF +static struct k_sem sem_lock; +#define SYNC_INIT() k_sem_init(&sem_lock, 1, 1) +#define SYNC_LOCK() k_sem_take(&sem_lock, K_FOREVER) +#define SYNC_UNLOCK() k_sem_give(&sem_lock) + #if CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE > 0 #define WRITE_BUFFER_ENABLE 1 #define WRITE_BUFFER_SIZE CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE @@ -39,6 +46,20 @@ LOG_MODULE_REGISTER(flash_nrf_rram, CONFIG_FLASH_LOG_LEVEL); #define WRITE_LINE_SIZE RRAM_WORD_SIZE #endif +#ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE +#define FLASH_SLOT_WRITE 5000 + +#if WRITE_BUFFER_ENABLE +#define RRAM_MAX_WRITE_BUFFER (WRITE_BUFFER_SIZE * WRITE_LINE_SIZE) +#else +#define RRAM_MAX_WRITE_BUFFER (WRITE_LINE_SIZE * 32) +#endif + +static int write_op(void *context); /* instance of flash_op_handler_t */ +static int write_synchronously(off_t addr, const void *data, size_t len); + +#endif /* !CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE */ + static inline bool is_within_bounds(off_t addr, size_t len, off_t boundary_start, size_t boundary_size) { @@ -65,17 +86,8 @@ static void commit_changes(size_t len) } #endif -static int rram_write(const struct device *dev, off_t addr, const void *data, size_t len) +static void rram_write(off_t addr, const void *data, size_t len) { - ARG_UNUSED(dev); - - if (!is_within_bounds(addr, len, 0, RRAM_SIZE)) { - return -EINVAL; - } - addr += RRAM_START; - - LOG_DBG("Write: %p:%zu", (void *)addr, len); - nrf_rramc_config_t config = {.mode_write = true, .write_buff_size = WRITE_BUFFER_SIZE}; nrf_rramc_config_set(NRF_RRAMC, &config); @@ -94,8 +106,102 @@ static int rram_write(const struct device *dev, off_t addr, const void *data, si config.mode_write = false; nrf_rramc_config_set(NRF_RRAMC, &config); +} - return 0; +#ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE +static void shift_write_context(uint32_t shift, struct flash_context *w_ctx) +{ + w_ctx->flash_addr += shift; + + /* NULL data_addr => erase emulation request*/ + if (w_ctx->data_addr) { + w_ctx->data_addr += shift; + } + + w_ctx->len -= shift; +} + +static int write_op(void *context) +{ + struct flash_context *w_ctx = context; + size_t len; + + uint32_t i = 0U; + + if (w_ctx->enable_time_limit) { + nrf_flash_sync_get_timestamp_begin(); + } + + while (w_ctx->len > 0) { + if (RRAM_MAX_WRITE_BUFFER < w_ctx->len) { + len = (RRAM_MAX_WRITE_BUFFER < w_ctx->len) ? RRAM_MAX_WRITE_BUFFER + : w_ctx->len; + } + + rram_write(w_ctx->flash_addr, (const void *)w_ctx->data_addr, len); + + shift_write_context(sizeof(uint32_t), w_ctx); + + if (w_ctx->len > 0) { + i++; + + if (w_ctx->enable_time_limit) { + if (nrf_flash_sync_check_time_limit(i)) { + return FLASH_OP_ONGOING; + } + } + } + } + + return FLASH_OP_DONE; +} + +static int write_synchronously(off_t addr, const void *data, size_t len) +{ + struct flash_context context = { + .data_addr = (uint32_t)data, + .flash_addr = addr, + .len = len, + .enable_time_limit = 1 /* enable time limit */ + }; + + struct flash_op_desc flash_op_desc = {.handler = write_op, .context = &context}; + + nrf_flash_sync_set_context(FLASH_SLOT_WRITE); + return nrf_flash_sync_exe(&flash_op_desc); +} + +#endif /* !CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE */ + +static int flash_nrf_write(off_t addr, const void *data, size_t len) +{ + int ret = 0; + + if (!is_within_bounds(addr, len, 0, RRAM_SIZE)) { + return -EINVAL; + } + addr += RRAM_START; + + if (!len) { + return 0; + } + + LOG_DBG("Write: %p:%zu", (void *)addr, len); + + SYNC_LOCK(); + +#ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE + if (nrf_flash_sync_is_required()) { + ret = write_synchronously(addr, data, len); + } else +#endif /* !CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE */ + { + rram_write(addr, data, len); + } + + SYNC_UNLOCK(); + + return ret; } static int flash_nrf_rram_read(const struct device *dev, off_t addr, void *data, size_t len) @@ -114,12 +220,16 @@ static int flash_nrf_rram_read(const struct device *dev, off_t addr, void *data, static int flash_nrf_rram_write(const struct device *dev, off_t addr, const void *data, size_t len) { - return rram_write(dev, addr, data, len); + ARG_UNUSED(dev); + + return flash_nrf_write(addr, data, len); } static int flash_nrf_rram_erase(const struct device *dev, off_t addr, size_t len) { - return rram_write(dev, addr, NULL, len); + ARG_UNUSED(dev); + + return flash_nrf_write(addr, NULL, len); } static const struct flash_parameters *flash_nrf_rram_get_parameters(const struct device *dev) @@ -165,6 +275,12 @@ static int flash_nrf_rram_init(const struct device *dev) { ARG_UNUSED(dev); + SYNC_INIT(); + +#ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE + nrf_flash_sync_init(); +#endif /* !CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE */ + #if CONFIG_NRF_RRAM_READYNEXT_TIMEOUT_VALUE > 0 nrf_rramc_ready_next_timeout_t params = { .value = CONFIG_NRF_RRAM_READYNEXT_TIMEOUT_VALUE, From 2e5653202b8ba503ff5b99612ef5601ff4301b30 Mon Sep 17 00:00:00 2001 From: Andrzej Puzdrowski Date: Thu, 7 Sep 2023 20:29:16 +0200 Subject: [PATCH 1469/1623] [nrf fromlist] drivers/flash: fix nRF RRAM write-length issue while MPSL in use Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68309 When radio-synchronization was on (CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE=n) context of writing was shifted by 4 instead of write-length (this caused redundant, self-shortening writes to the same block.) write-len was unset when requested write len was less than RRAM_MAX_WRITE_BUFFER. Signed-off-by: Andrzej Puzdrowski Signed-off-by: Jakub Zymelka --- drivers/flash/soc_flash_nrf_rram.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/flash/soc_flash_nrf_rram.c b/drivers/flash/soc_flash_nrf_rram.c index 64780fc3013..8c97285319f 100644 --- a/drivers/flash/soc_flash_nrf_rram.c +++ b/drivers/flash/soc_flash_nrf_rram.c @@ -133,14 +133,11 @@ static int write_op(void *context) } while (w_ctx->len > 0) { - if (RRAM_MAX_WRITE_BUFFER < w_ctx->len) { - len = (RRAM_MAX_WRITE_BUFFER < w_ctx->len) ? RRAM_MAX_WRITE_BUFFER - : w_ctx->len; - } + len = (RRAM_MAX_WRITE_BUFFER < w_ctx->len) ? RRAM_MAX_WRITE_BUFFER : w_ctx->len; rram_write(w_ctx->flash_addr, (const void *)w_ctx->data_addr, len); - shift_write_context(sizeof(uint32_t), w_ctx); + shift_write_context(len, w_ctx); if (w_ctx->len > 0) { i++; From eb33cf1ffbda3885e72271008a66721bba1d7cc1 Mon Sep 17 00:00:00 2001 From: Andrzej Puzdrowski Date: Tue, 26 Sep 2023 17:02:10 +0200 Subject: [PATCH 1470/1623] [nrf fromlist] drivers/flash/rram: set to use up to 512 B burst writes by default Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68309 Now RRAMC is set to use up to 512 B burst writes by default as most time effective. Requested slot time was changed to 8000 us for that case, as this is required in order to hold the longest write operation. Drivers differs slot duration depending on configured RRAMC buffers count (CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE). Signed-off-by: Andrzej Puzdrowski --- drivers/flash/Kconfig.nrf_rram | 1 + drivers/flash/soc_flash_nrf_rram.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/flash/Kconfig.nrf_rram b/drivers/flash/Kconfig.nrf_rram index f6e3ccc6416..3ec7005acde 100644 --- a/drivers/flash/Kconfig.nrf_rram +++ b/drivers/flash/Kconfig.nrf_rram @@ -21,6 +21,7 @@ if SOC_FLASH_NRF_RRAM config NRF_RRAM_WRITE_BUFFER_SIZE int "Internal write-buffer size" + default 32 if !SOC_FLASH_NRF_RADIO_SYNC_NONE default 0 range 0 32 help diff --git a/drivers/flash/soc_flash_nrf_rram.c b/drivers/flash/soc_flash_nrf_rram.c index 8c97285319f..44ce514cda8 100644 --- a/drivers/flash/soc_flash_nrf_rram.c +++ b/drivers/flash/soc_flash_nrf_rram.c @@ -47,7 +47,18 @@ static struct k_sem sem_lock; #endif #ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE -#define FLASH_SLOT_WRITE 5000 + +#if (WRITE_BUFFER_SIZE < 2) +#define FLASH_SLOT_WRITE 500 +#elif (WRITE_BUFFER_SIZE < 4) +#define FLASH_SLOT_WRITE 1000 +#elif (WRITE_BUFFER_SIZE < 9) +#define FLASH_SLOT_WRITE 2000 +#elif (WRITE_BUFFER_SIZE < 17) +#define FLASH_SLOT_WRITE 4000 +#else +#define FLASH_SLOT_WRITE 8000 /* longest write takes 7107 us */ +#endif #if WRITE_BUFFER_ENABLE #define RRAM_MAX_WRITE_BUFFER (WRITE_BUFFER_SIZE * WRITE_LINE_SIZE) From ff4fea43b026f16392ec4e9ad458593974980caf Mon Sep 17 00:00:00 2001 From: Pierce Lowe Date: Fri, 10 Nov 2023 09:23:49 +0100 Subject: [PATCH 1471/1623] [nrf fromlist] drivers: flash: rram: Make rram flash timeout multiplier user selectable Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68309 Make flash timeout multiplier user selectable for rram flash driver Signed-off-by: Pierce Lowe --- drivers/flash/Kconfig.nrf_rram | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/flash/Kconfig.nrf_rram b/drivers/flash/Kconfig.nrf_rram index 3ec7005acde..68efde1ab30 100644 --- a/drivers/flash/Kconfig.nrf_rram +++ b/drivers/flash/Kconfig.nrf_rram @@ -57,8 +57,13 @@ config SOC_FLASH_NRF_RADIO_SYNC_NONE endchoice config SOC_FLASH_NRF_TIMEOUT_MULTIPLIER - int + int "Multiplier for flash operation timeouts [x0.1]" depends on !SOC_FLASH_NRF_RADIO_SYNC_NONE default 1 + help + This is a multiplier that will be divided by 10 that is applied + to the flash erase and write operations timeout. The base for + the multiplication would allow erasing all nRF flash pages in + blocking mode. endif # SOC_FLASH_NRF_RRAM From 76bc861882642baa4d49b8d83184f19e50851712 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Tue, 6 Feb 2024 22:01:14 +0100 Subject: [PATCH 1472/1623] [nrf fromlist] drivers: flash: rram: minor driver code changes Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68309 Minor changes to standardize the driver code. Signed-off-by: Jakub Zymelka Signed-off-by: Andrzej Puzdrowski --- drivers/flash/soc_flash_nrf_rram.c | 75 ++++++++++++++++-------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/drivers/flash/soc_flash_nrf_rram.c b/drivers/flash/soc_flash_nrf_rram.c index 44ce514cda8..369ff61c556 100644 --- a/drivers/flash/soc_flash_nrf_rram.c +++ b/drivers/flash/soc_flash_nrf_rram.c @@ -24,12 +24,11 @@ LOG_MODULE_REGISTER(flash_nrf_rram, CONFIG_FLASH_LOG_LEVEL); #define RRAM_START DT_REG_ADDR(RRAM) #define RRAM_SIZE DT_REG_SIZE(RRAM) -#define RRAM_WORD_SIZE 4 - #define PAGE_SIZE DT_PROP(RRAM, erase_block_size) #define PAGE_COUNT ((RRAM_SIZE) / (PAGE_SIZE)) -#define ERASE_VALUE 0xFF +#define WRITE_BLOCK_SIZE_FROM_DT DT_PROP(RRAM, write_block_size) +#define ERASE_VALUE 0xFF static struct k_sem sem_lock; #define SYNC_INIT() k_sem_init(&sem_lock, 1, 1) @@ -37,13 +36,20 @@ static struct k_sem sem_lock; #define SYNC_UNLOCK() k_sem_give(&sem_lock) #if CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE > 0 -#define WRITE_BUFFER_ENABLE 1 -#define WRITE_BUFFER_SIZE CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE -#define WRITE_LINE_SIZE 16 /* In bytes, one line is 128 bits. */ +#define WRITE_BUFFER_ENABLE 1 +#define WRITE_BUFFER_SIZE CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE +#define WRITE_LINE_SIZE 16 /* In bytes, one line is 128 bits. */ +#define WRITE_BUFFER_MAX_SIZE (WRITE_BUFFER_SIZE * WRITE_LINE_SIZE) +BUILD_ASSERT((PAGE_SIZE % (WRITE_LINE_SIZE) == 0), "erase-block-size must be a multiple of 16"); +BUILD_ASSERT((WRITE_BLOCK_SIZE_FROM_DT % (WRITE_LINE_SIZE) == 0), + "if NRF_RRAM_WRITE_BUFFER_SIZE > 0, then write-block-size must be a multiple of 16"); #else -#define WRITE_BUFFER_ENABLE 0 -#define WRITE_BUFFER_SIZE 0 -#define WRITE_LINE_SIZE RRAM_WORD_SIZE +#define WRITE_BUFFER_ENABLE 0 +#define WRITE_BUFFER_SIZE 0 +#define WRITE_LINE_SIZE WRITE_BLOCK_SIZE_FROM_DT +#define WRITE_BUFFER_MAX_SIZE 16 /* In bytes, one line is 128 bits. */ +BUILD_ASSERT((PAGE_SIZE % (WRITE_LINE_SIZE) == 0), + "erase-block-size must be a multiple of write-block-size"); #endif #ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE @@ -60,12 +66,6 @@ static struct k_sem sem_lock; #define FLASH_SLOT_WRITE 8000 /* longest write takes 7107 us */ #endif -#if WRITE_BUFFER_ENABLE -#define RRAM_MAX_WRITE_BUFFER (WRITE_BUFFER_SIZE * WRITE_LINE_SIZE) -#else -#define RRAM_MAX_WRITE_BUFFER (WRITE_LINE_SIZE * 32) -#endif - static int write_op(void *context); /* instance of flash_op_handler_t */ static int write_synchronously(off_t addr, const void *data, size_t len); @@ -86,7 +86,7 @@ static void commit_changes(size_t len) return; } - if ((len % (WRITE_LINE_SIZE * WRITE_BUFFER_SIZE)) == 0) { + if ((len % (WRITE_BUFFER_MAX_SIZE)) == 0) { /* Our last operation was buffer size-aligned, so we're done. */ return; } @@ -144,7 +144,7 @@ static int write_op(void *context) } while (w_ctx->len > 0) { - len = (RRAM_MAX_WRITE_BUFFER < w_ctx->len) ? RRAM_MAX_WRITE_BUFFER : w_ctx->len; + len = (w_ctx->len > WRITE_BUFFER_MAX_SIZE) ? WRITE_BUFFER_MAX_SIZE : w_ctx->len; rram_write(w_ctx->flash_addr, (const void *)w_ctx->data_addr, len); @@ -181,7 +181,7 @@ static int write_synchronously(off_t addr, const void *data, size_t len) #endif /* !CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE */ -static int flash_nrf_write(off_t addr, const void *data, size_t len) +static int nrf_write(off_t addr, const void *data, size_t len) { int ret = 0; @@ -212,7 +212,7 @@ static int flash_nrf_write(off_t addr, const void *data, size_t len) return ret; } -static int flash_nrf_rram_read(const struct device *dev, off_t addr, void *data, size_t len) +static int nrf_rram_read(const struct device *dev, off_t addr, void *data, size_t len) { ARG_UNUSED(dev); @@ -226,21 +226,25 @@ static int flash_nrf_rram_read(const struct device *dev, off_t addr, void *data, return 0; } -static int flash_nrf_rram_write(const struct device *dev, off_t addr, const void *data, size_t len) +static int nrf_rram_write(const struct device *dev, off_t addr, const void *data, size_t len) { ARG_UNUSED(dev); - return flash_nrf_write(addr, data, len); + if (data == NULL) { + return -EINVAL; + } + + return nrf_write(addr, data, len); } -static int flash_nrf_rram_erase(const struct device *dev, off_t addr, size_t len) +static int nrf_rram_erase(const struct device *dev, off_t addr, size_t len) { ARG_UNUSED(dev); - return flash_nrf_write(addr, NULL, len); + return nrf_write(addr, NULL, len); } -static const struct flash_parameters *flash_nrf_rram_get_parameters(const struct device *dev) +static const struct flash_parameters *nrf_rram_get_parameters(const struct device *dev) { ARG_UNUSED(dev); @@ -253,9 +257,8 @@ static const struct flash_parameters *flash_nrf_rram_get_parameters(const struct } #if defined(CONFIG_FLASH_PAGE_LAYOUT) -static void flash_nrf_rram_page_layout(const struct device *dev, - const struct flash_pages_layout **layout, - size_t *layout_size) +static void nrf_rram_page_layout(const struct device *dev, const struct flash_pages_layout **layout, + size_t *layout_size) { ARG_UNUSED(dev); @@ -269,17 +272,17 @@ static void flash_nrf_rram_page_layout(const struct device *dev, } #endif -static const struct flash_driver_api flash_nrf_rram_api = { - .read = flash_nrf_rram_read, - .write = flash_nrf_rram_write, - .erase = flash_nrf_rram_erase, - .get_parameters = flash_nrf_rram_get_parameters, +static const struct flash_driver_api nrf_rram_api = { + .read = nrf_rram_read, + .write = nrf_rram_write, + .erase = nrf_rram_erase, + .get_parameters = nrf_rram_get_parameters, #if defined(CONFIG_FLASH_PAGE_LAYOUT) - .page_layout = flash_nrf_rram_page_layout, + .page_layout = nrf_rram_page_layout, #endif }; -static int flash_nrf_rram_init(const struct device *dev) +static int nrf_rram_init(const struct device *dev) { ARG_UNUSED(dev); @@ -300,5 +303,5 @@ static int flash_nrf_rram_init(const struct device *dev) return 0; } -DEVICE_DT_INST_DEFINE(0, flash_nrf_rram_init, NULL, NULL, NULL, POST_KERNEL, - CONFIG_FLASH_INIT_PRIORITY, &flash_nrf_rram_api); +DEVICE_DT_INST_DEFINE(0, nrf_rram_init, NULL, NULL, NULL, POST_KERNEL, CONFIG_FLASH_INIT_PRIORITY, + &nrf_rram_api); From 1d09dda4feb77fa36549cd32cf88dd13d0abeb4e Mon Sep 17 00:00:00 2001 From: Mateusz Michalek Date: Wed, 31 Jan 2024 10:25:08 +0100 Subject: [PATCH 1473/1623] [nrf fromlist] drivers: flash: rram singlethreading support Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68309 Adds conditional usage of locking mechanisms to allow building without multithreading. Signed-off-by: Mateusz Michalek --- drivers/flash/soc_flash_nrf_rram.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/flash/soc_flash_nrf_rram.c b/drivers/flash/soc_flash_nrf_rram.c index 369ff61c556..4930eb31697 100644 --- a/drivers/flash/soc_flash_nrf_rram.c +++ b/drivers/flash/soc_flash_nrf_rram.c @@ -30,10 +30,16 @@ LOG_MODULE_REGISTER(flash_nrf_rram, CONFIG_FLASH_LOG_LEVEL); #define WRITE_BLOCK_SIZE_FROM_DT DT_PROP(RRAM, write_block_size) #define ERASE_VALUE 0xFF +#ifdef CONFIG_MULTITHREADING static struct k_sem sem_lock; #define SYNC_INIT() k_sem_init(&sem_lock, 1, 1) #define SYNC_LOCK() k_sem_take(&sem_lock, K_FOREVER) #define SYNC_UNLOCK() k_sem_give(&sem_lock) +#else +#define SYNC_INIT() +#define SYNC_LOCK() +#define SYNC_UNLOCK() +#endif /* CONFIG_MULTITHREADING */ #if CONFIG_NRF_RRAM_WRITE_BUFFER_SIZE > 0 #define WRITE_BUFFER_ENABLE 1 From 7bb927f7c0cddc52a643678225fd5b50e63306fd Mon Sep 17 00:00:00 2001 From: Guojun Wang Date: Mon, 19 Feb 2024 12:55:47 +0100 Subject: [PATCH 1474/1623] [nrf noup] test-spec: descope samples and tests from many CIs Descope samples and tests from many CIs, since the majority are not affecting the functionality of protocols and applications. Samples that may affect the overall performance and functionality, should be enabled specifically. Signed-off-by: Guojun Wang --- .github/test-spec.yml | 54 ++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index 1d3e04fe75b..ead2ab8bb2a 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -35,7 +35,7 @@ - "include/net/socket_ncs.h" - "subsys/testsuite/ztest/**/*" -"CI-lwm2m-test": +"CI-lwm2m-test": null # Not necessary to run tests on changes to this repo. "CI-boot-dfu-test": @@ -66,16 +66,7 @@ - any: - "include/zephyr/bluetooth/**/*" - "!include/zephyr/bluetooth/mesh/**/*" - - any: - - "samples/bluetooth/**/*" - - "!samples/bluetooth/mesh/**/*" - - "!samples/bluetooth/mesh_demo/**/*" - - "!samples/bluetooth/mesh_provisioner/**/*" - - any: - - "tests/bluetooth/**/*" - - "!tests/bluetooth/mesh/**/*" - - "!tests/bluetooth/mesh_shell/**/*" - - "!tests/bluetooth/audio/**/*" + - "samples/bluetooth/hci_rpc/**/*" "CI-mesh-test": - "subsys/bluetooth/mesh/**/*" @@ -126,7 +117,10 @@ - "subsys/tracing/**/*" "CI-desktop-test": - - "**/*" + - any: + - "**/*" + - "!samples/bluetooth/**/*" + - "!tests/bluetooth/**/*" "CI-crypto-test": - "boards/arm/nrf52840dk_nrf52840/**/*" @@ -141,10 +135,16 @@ - "modules/mbedtls/**/*" "CI-fem-test": - - "**/*" + - any: + - "**/*" + - "!samples/bluetooth/**/*" + - "!tests/bluetooth/**/*" "CI-rs-test": - - "**/*" + - any: + - "**/*" + - "!samples/bluetooth/**/*" + - "!tests/bluetooth/**/*" "CI-thread-test": - "include/zephyr/net/**/*" @@ -156,7 +156,10 @@ - "subsys/settings/**/*" "CI-nfc-test": - - "**/*" + - any: + - "**/*" + - "!samples/bluetooth/**/*" + - "!tests/bluetooth/**/*" "CI-matter-test": - "include/dfu/**/*" @@ -167,20 +170,29 @@ - "subsys/net/**/*" - "subsys/mgmt/mcumgr/**/*" - "drivers/net/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" + - "samples/bluetooth/hci_rpc/**/*" - any: - "subsys/bluetooth/**/*" - "!subsys/bluetooth/mesh/**/*" - "!subsys/bluetooth/audio/**/*" "CI-find-my-test": - - "**/*" + - any: + - "**/*" + - "!samples/bluetooth/**/*" + - "!tests/bluetooth/**/*" "CI-gazell-test": - - "**/*" + - any: + - "**/*" + - "!samples/bluetooth/**/*" + - "!tests/bluetooth/**/*" "CI-rpc-test": - - "**/*" + - any: + - "**/*" + - "!samples/bluetooth/**/*" + - "!tests/bluetooth/**/*" "CI-modemshell-test": - "include/net/**/*" @@ -228,7 +240,7 @@ - "subsys/dfu/**/*" - "subsys/settings/**/*" - "subsys/mgmt/mcumgr/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" + - "samples/bluetooth/hci_rpc/**/*" - any: - "subsys/bluetooth/**/*" - "!subsys/bluetooth/mesh/**/*" @@ -243,7 +255,7 @@ - "drivers/watchdog/**/*" - "include/dfu/**/*" - "include/mgmt/mcumgr/**/*" - - "samples/bluetooth/hci_rpmsg/**/*" + - "samples/bluetooth/hci_rpc/**/*" - "soc/arm/nordic_nrf/**/*" - "subsys/bluetooth/audio/**/*" - "subsys/bluetooth/host/**/*" From 2f370d3e143b026dbe2d8c7c3530053acbade78b Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:05:02 +0100 Subject: [PATCH 1475/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: current-speed needs to be set by boards This is a setting that depends on the board or application, so it should not be part of SoC definition files. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit cb709dd5776538001310ac5b4bb9699ee63f58c9) --- boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts | 2 ++ boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts | 2 ++ .../riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts | 2 ++ dts/common/nordic/nrf54h20_enga.dtsi | 2 -- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts index 359c1f84307..5fb345ec808 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts @@ -123,6 +123,7 @@ }; &uart135 { + current-speed = <115200>; pinctrl-0 = <&uart135_default>; pinctrl-1 = <&uart135_sleep>; pinctrl-names = "default", "sleep"; @@ -131,6 +132,7 @@ &uart136 { status = "okay"; memory-regions = <&cpuapp_dma_region>; + current-speed = <115200>; pinctrl-0 = <&uart136_default>; pinctrl-1 = <&uart136_sleep>; pinctrl-names = "default", "sleep"; diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts index 02213d88645..a7d142b06c4 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts @@ -46,12 +46,14 @@ &uart135 { status = "okay"; memory-regions = <&cpurad_dma_region>; + current-speed = <115200>; pinctrl-0 = <&uart135_default>; pinctrl-1 = <&uart135_sleep>; pinctrl-names = "default", "sleep"; }; &uart136 { + current-speed = <115200>; pinctrl-0 = <&uart136_default>; pinctrl-1 = <&uart136_sleep>; pinctrl-names = "default", "sleep"; diff --git a/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts index 83aface6f5c..3c74e7c88d4 100644 --- a/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts +++ b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts @@ -31,12 +31,14 @@ &uart135 { status = "okay"; + current-speed = <115200>; pinctrl-0 = <&uart135_default>; pinctrl-1 = <&uart135_sleep>; pinctrl-names = "default", "sleep"; }; &uart136 { + current-speed = <115200>; pinctrl-0 = <&uart136_default>; pinctrl-1 = <&uart136_sleep>; pinctrl-names = "default", "sleep"; diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 1b8f7b6f9e8..af751c4344b 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -254,7 +254,6 @@ compatible = "nordic,nrf-uarte"; reg = <0x9c6000 0x1000>; status = "disabled"; - current-speed = <115200>; interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; }; @@ -262,7 +261,6 @@ compatible = "nordic,nrf-uarte"; reg = <0x9d5000 0x1000>; status = "disabled"; - current-speed = <115200>; interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; }; }; From 447b80d72932043158e13a74172a7b465fdb0c4d Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:02:54 +0100 Subject: [PATCH 1476/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add missing UARTE nodes Add missing UARTE nodes. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit ca52e7f3da2d5389af381acab48e00040d8d92a8) --- dts/common/nordic/nrf54h20_enga.dtsi | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index af751c4344b..97dcb222746 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -153,6 +153,13 @@ #size-cells = <1>; ranges = <0x0 0x5f000000 0x1000000>; + uart120: uart@8e5000 { + compatible = "nordic,nrf-uarte"; + reg = <0x8e5000 0x1000>; + status = "disabled"; + interrupts = <229 NRF_DEFAULT_IRQ_PRIORITY>; + }; + cpuppr_vpr: vpr@908000 { compatible = "nordic,nrf-vpr-coprocessor"; reg = <0x908000 0x1000>; @@ -250,6 +257,41 @@ cc-num = <16>; }; + uart130: uart@9a5000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9a5000 0x1000>; + status = "disabled"; + interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + uart131: uart@9a6000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9a6000 0x1000>; + status = "disabled"; + interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + uart132: uart@9b5000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9b5000 0x1000>; + status = "disabled"; + interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + uart133: uart@9b6000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9b6000 0x1000>; + status = "disabled"; + interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + uart134: uart@9c5000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9c5000 0x1000>; + status = "disabled"; + interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; + }; + uart135: uart@9c6000 { compatible = "nordic,nrf-uarte"; reg = <0x9c6000 0x1000>; @@ -263,6 +305,13 @@ status = "disabled"; interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; }; + + uart137: uart@9d6000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9d6000 0x1000>; + status = "disabled"; + interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>; + }; }; }; From c23385cf9f222f139bf3dc39f0fc9ea30eba1129 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 14:56:50 +0100 Subject: [PATCH 1477/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add TIMER nodes Add nodes for TIMER peripherals (Timer/Counter). Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 42a86c4b9d74ac47c8869f37d51e4759efb72199) --- dts/common/nordic/nrf54h20_enga.dtsi | 130 +++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 97dcb222746..0dfdac7434f 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -146,6 +146,36 @@ <&ficr NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_FINE_1>; nordic,ficr-names = "vsup", "coarse", "fine"; }; + + timer020: timer@28000 { + compatible = "nordic,nrf-timer"; + reg = <0x28000 0x1000>; + status = "disabled"; + cc-num = <8>; + interrupts = <40 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer021: timer@29000 { + compatible = "nordic,nrf-timer"; + reg = <0x29000 0x1000>; + status = "disabled"; + cc-num = <8>; + interrupts = <41 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer022: timer@2a000 { + compatible = "nordic,nrf-timer"; + reg = <0x2a000 0x1000>; + status = "disabled"; + cc-num = <8>; + interrupts = <42 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; }; global_peripherals: peripheral@5f000000 { @@ -153,6 +183,26 @@ #size-cells = <1>; ranges = <0x0 0x5f000000 0x1000000>; + timer120: timer@8e2000 { + compatible = "nordic,nrf-timer"; + reg = <0x8e2000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <226 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer121: timer@8e3000 { + compatible = "nordic,nrf-timer"; + reg = <0x8e3000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <227 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + uart120: uart@8e5000 { compatible = "nordic,nrf-uarte"; reg = <0x8e5000 0x1000>; @@ -257,6 +307,26 @@ cc-num = <16>; }; + timer130: timer@9a2000 { + compatible = "nordic,nrf-timer"; + reg = <0x9a2000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <418 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer131: timer@9a3000 { + compatible = "nordic,nrf-timer"; + reg = <0x9a3000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <419 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + uart130: uart@9a5000 { compatible = "nordic,nrf-uarte"; reg = <0x9a5000 0x1000>; @@ -271,6 +341,26 @@ interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; }; + timer132: timer@9b2000 { + compatible = "nordic,nrf-timer"; + reg = <0x9b2000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <434 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer133: timer@9b3000 { + compatible = "nordic,nrf-timer"; + reg = <0x9b3000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <435 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + uart132: uart@9b5000 { compatible = "nordic,nrf-uarte"; reg = <0x9b5000 0x1000>; @@ -285,6 +375,26 @@ interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; }; + timer134: timer@9c2000 { + compatible = "nordic,nrf-timer"; + reg = <0x9c2000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <450 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer135: timer@9c3000 { + compatible = "nordic,nrf-timer"; + reg = <0x9c3000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <451 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + uart134: uart@9c5000 { compatible = "nordic,nrf-uarte"; reg = <0x9c5000 0x1000>; @@ -306,6 +416,26 @@ interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; }; + timer136: timer@9d2000 { + compatible = "nordic,nrf-timer"; + reg = <0x9d2000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <466 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer137: timer@9d3000 { + compatible = "nordic,nrf-timer"; + reg = <0x9d3000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <467 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + uart137: uart@9d6000 { compatible = "nordic,nrf-uarte"; reg = <0x9d6000 0x1000>; From e9b925c45856a4afa79ae0b2c6464715f636a726 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:54:16 +0100 Subject: [PATCH 1478/1623] [nrf fromlist] modules: hal_nordic: add support for TIMER020-022|120-121|130-137 Add new HAL glue Kconfig options so that new TIMER instances can be used. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 8e684f8411809048452509a36b4df874d7cfcd68) --- modules/hal_nordic/nrfx/Kconfig | 65 +++++++++++++++++++++++++++ modules/hal_nordic/nrfx/nrfx_config.h | 39 ++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index ee1bd76b52f..784a2087139 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -457,6 +457,71 @@ config NRFX_TIMER24 depends on $(dt_nodelabel_has_compat,timer24,$(DT_COMPAT_NORDIC_NRF_TIMER)) select NRFX_TIMER +config NRFX_TIMER020 + bool "TIMER020 driver instance" + depends on $(dt_nodelabel_has_compat,timer020,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER021 + bool "TIMER021 driver instance" + depends on $(dt_nodelabel_has_compat,timer021,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER022 + bool "TIMER022 driver instance" + depends on $(dt_nodelabel_has_compat,timer022,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER120 + bool "TIMER120 driver instance" + depends on $(dt_nodelabel_has_compat,timer120,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER121 + bool "TIMER121 driver instance" + depends on $(dt_nodelabel_has_compat,timer121,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER130 + bool "TIMER130 driver instance" + depends on $(dt_nodelabel_has_compat,timer130,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER131 + bool "TIMER131 driver instance" + depends on $(dt_nodelabel_has_compat,timer131,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER132 + bool "TIMER132 driver instance" + depends on $(dt_nodelabel_has_compat,timer132,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER133 + bool "TIMER133 driver instance" + depends on $(dt_nodelabel_has_compat,timer133,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER134 + bool "TIMER134 driver instance" + depends on $(dt_nodelabel_has_compat,timer134,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER135 + bool "TIMER135 driver instance" + depends on $(dt_nodelabel_has_compat,timer135,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER136 + bool "TIMER136 driver instance" + depends on $(dt_nodelabel_has_compat,timer136,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER137 + bool "TIMER137 driver instance" + depends on $(dt_nodelabel_has_compat,timer137,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + config NRFX_TWI bool diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 26d662be39d..20facba229c 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -472,6 +472,45 @@ #ifdef CONFIG_NRFX_TIMER24 #define NRFX_TIMER24_ENABLED 1 #endif +#ifdef CONFIG_NRFX_TIMER020 +#define NRFX_TIMER020_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER021 +#define NRFX_TIMER021_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER022 +#define NRFX_TIMER022_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER120 +#define NRFX_TIMER120_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER121 +#define NRFX_TIMER121_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER130 +#define NRFX_TIMER130_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER131 +#define NRFX_TIMER131_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER132 +#define NRFX_TIMER132_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER133 +#define NRFX_TIMER133_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER134 +#define NRFX_TIMER134_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER135 +#define NRFX_TIMER135_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER136 +#define NRFX_TIMER136_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER137 +#define NRFX_TIMER137_ENABLED 1 +#endif #ifdef CONFIG_NRFX_TWI #define NRFX_TWI_ENABLED 1 From 5781d09392323b3d0d4e5b8a54f3a408190b5b40 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:56:59 +0100 Subject: [PATCH 1479/1623] [nrf fromlist] soc: nordic_nrf: add support for TIMER020-022|120-121|130-137 Add new Kconfig options so that new TIMER instances can be used. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit f42f2888a875ea31916af0cb5208487f31305a81) --- soc/common/nordic_nrf/Kconfig.peripherals | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index b8b1198ca02..710d9d4582d 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -341,6 +341,45 @@ config HAS_HW_NRF_TIMER23 config HAS_HW_NRF_TIMER24 def_bool $(dt_nodelabel_enabled_with_compat,timer24,$(DT_COMPAT_NORDIC_NRF_TIMER)) +config HAS_HW_NRF_TIMER020 + def_bool $(dt_nodelabel_enabled_with_compat,timer020,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER021 + def_bool $(dt_nodelabel_enabled_with_compat,timer021,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER022 + def_bool $(dt_nodelabel_enabled_with_compat,timer022,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER120 + def_bool $(dt_nodelabel_enabled_with_compat,timer120,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER121 + def_bool $(dt_nodelabel_enabled_with_compat,timer121,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER130 + def_bool $(dt_nodelabel_enabled_with_compat,timer130,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER131 + def_bool $(dt_nodelabel_enabled_with_compat,timer131,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER132 + def_bool $(dt_nodelabel_enabled_with_compat,timer132,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER133 + def_bool $(dt_nodelabel_enabled_with_compat,timer133,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER134 + def_bool $(dt_nodelabel_enabled_with_compat,timer134,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER135 + def_bool $(dt_nodelabel_enabled_with_compat,timer135,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER136 + def_bool $(dt_nodelabel_enabled_with_compat,timer136,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER137 + def_bool $(dt_nodelabel_enabled_with_compat,timer137,$(DT_COMPAT_NORDIC_NRF_TIMER)) + config HAS_HW_NRF_TWI0 def_bool $(dt_nodelabel_enabled_with_compat,i2c0,$(DT_COMPAT_NORDIC_NRF_TWI)) From a2bbfa1ba37f977b2ed2a90e51cecc00b566ef9c Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 14:58:55 +0100 Subject: [PATCH 1480/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add RTC nodes Add RTC (Real Time Counter) node. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 781ea18e0046c771c304a10e969bcb6f7fa302c7) --- dts/common/nordic/nrf54h20_enga.dtsi | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 0dfdac7434f..2c4cfea5044 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -176,6 +176,16 @@ max-bit-width = <32>; prescaler = <0>; }; + + rtc: rtc@2b000 { + compatible = "nordic,nrf-rtc"; + reg = <0x2b000 0x1000>; + status = "disabled"; + cc-num = <4>; + clock-frequency = <32768>; + interrupts = <43 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <1>; + }; }; global_peripherals: peripheral@5f000000 { @@ -229,6 +239,26 @@ }; }; + rtc130: rtc@928000 { + compatible = "nordic,nrf-rtc"; + reg = <0x928000 0x1000>; + status = "disabled"; + cc-num = <4>; + clock-frequency = <32768>; + interrupts = <296 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <1>; + }; + + rtc131: rtc@929000 { + compatible = "nordic,nrf-rtc"; + reg = <0x929000 0x1000>; + status = "disabled"; + cc-num = <4>; + clock-frequency = <32768>; + interrupts = <297 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <1>; + }; + gpiote130: gpiote@934000 { compatible = "nordic,nrf-gpiote"; reg = <0x934000 0x1000>; From 6563e52c2390019e6fc9e6a545e681bcdd769f40 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:14:56 +0100 Subject: [PATCH 1481/1623] [nrf fromlist] modules: hal_nordic: add support for RTC130-131 Add new HAL glue Kconfig options for RTC130-131. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 0eb3e1dd40e19c1722267d51e996a01882af8c38) --- modules/hal_nordic/nrfx/Kconfig | 10 ++++++++++ modules/hal_nordic/nrfx/nrfx_config.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 784a2087139..34dbb43f3d4 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -238,6 +238,16 @@ config NRFX_RTC2 depends on $(dt_nodelabel_has_compat,rtc2,$(DT_COMPAT_NORDIC_NRF_RTC)) select NRFX_RTC +config NRFX_RTC130 + bool "RTC130 driver instance" + depends on $(dt_nodelabel_has_compat,rtc130,$(DT_COMPAT_NORDIC_NRF_RTC)) + select NRFX_RTC + +config NRFX_RTC131 + bool "RTC131 driver instance" + depends on $(dt_nodelabel_has_compat,rtc131,$(DT_COMPAT_NORDIC_NRF_RTC)) + select NRFX_RTC + config NRFX_SAADC bool "SAADC driver" depends on $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_SAADC)) diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 20facba229c..0f52cd17cf2 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -299,6 +299,12 @@ #ifdef CONFIG_NRFX_RTC2 #define NRFX_RTC2_ENABLED 1 #endif +#ifdef CONFIG_NRFX_RTC130 +#define NRFX_RTC130_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_RTC131 +#define NRFX_RTC131_ENABLED 1 +#endif #ifdef CONFIG_NRFX_SAADC #define NRFX_SAADC_ENABLED 1 From 9ae5728d47b191dcc3bd9a6d7febfd78cc4f8e42 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:15:42 +0100 Subject: [PATCH 1482/1623] [nrf fromlist] soc: nordic_nrf: add support for RTC130-131 Add new Kconfig options for RTC130-131 so that the new instances can be used. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 2f15c5f81d1b2f8a682d39f9b79e1fe801522263) --- soc/common/nordic_nrf/Kconfig.peripherals | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index 710d9d4582d..b3e0ae2d130 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -197,6 +197,12 @@ config HAS_HW_NRF_RTC1 config HAS_HW_NRF_RTC2 def_bool $(dt_nodelabel_enabled_with_compat,rtc2,$(DT_COMPAT_NORDIC_NRF_RTC)) +config HAS_HW_NRF_RTC130 + def_bool $(dt_nodelabel_enabled_with_compat,rtc130,$(DT_COMPAT_NORDIC_NRF_RTC)) + +config HAS_HW_NRF_RTC131 + def_bool $(dt_nodelabel_enabled_with_compat,rtc131,$(DT_COMPAT_NORDIC_NRF_RTC)) + config HAS_HW_NRF_SAADC def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_SAADC)) From 0d6239cb154cb8dc72d80a2d5cbdb70de62a5d0c Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:12:05 +0100 Subject: [PATCH 1483/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add SPIM nodes Add SPIM (SPI with EasyDMA) nodes. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit b8d8d64115eb89e02b283a0a5a28afa23156c933) --- dts/common/nordic/nrf54h20_enga.dtsi | 110 +++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 2c4cfea5044..caaf430de70 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -220,6 +220,28 @@ interrupts = <229 NRF_DEFAULT_IRQ_PRIORITY>; }; + spi120: spi@8e6000 { + compatible = "nordic,nrf-spim"; + reg = <0x8e6000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <230 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + + spi121: spi@8e7000 { + compatible = "nordic,nrf-spim"; + reg = <0x8e7000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <231 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + cpuppr_vpr: vpr@908000 { compatible = "nordic,nrf-vpr-coprocessor"; reg = <0x908000 0x1000>; @@ -357,6 +379,17 @@ prescaler = <0>; }; + spi130: spi@9a5000 { + compatible = "nordic,nrf-spim"; + reg = <0x9a5000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart130: uart@9a5000 { compatible = "nordic,nrf-uarte"; reg = <0x9a5000 0x1000>; @@ -364,6 +397,17 @@ interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; }; + spi131: spi@9a6000 { + compatible = "nordic,nrf-spim"; + reg = <0x9a6000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart131: uart@9a6000 { compatible = "nordic,nrf-uarte"; reg = <0x9a6000 0x1000>; @@ -391,6 +435,17 @@ prescaler = <0>; }; + spi132: spi@9b5000 { + compatible = "nordic,nrf-spim"; + reg = <0x9b5000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart132: uart@9b5000 { compatible = "nordic,nrf-uarte"; reg = <0x9b5000 0x1000>; @@ -398,6 +453,17 @@ interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; }; + spi133: spi@9b6000 { + compatible = "nordic,nrf-spim"; + reg = <0x9b6000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart133: uart@9b6000 { compatible = "nordic,nrf-uarte"; reg = <0x9b6000 0x1000>; @@ -425,6 +491,17 @@ prescaler = <0>; }; + spi134: spi@9c5000 { + compatible = "nordic,nrf-spim"; + reg = <0x9c5000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart134: uart@9c5000 { compatible = "nordic,nrf-uarte"; reg = <0x9c5000 0x1000>; @@ -432,6 +509,17 @@ interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; }; + spi135: spi@9c6000 { + compatible = "nordic,nrf-spim"; + reg = <0x9c6000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart135: uart@9c6000 { compatible = "nordic,nrf-uarte"; reg = <0x9c6000 0x1000>; @@ -439,6 +527,17 @@ interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; }; + spi136: spi@9d5000 { + compatible = "nordic,nrf-spim"; + reg = <0x9d5000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart136: uart@9d5000 { compatible = "nordic,nrf-uarte"; reg = <0x9d5000 0x1000>; @@ -466,6 +565,17 @@ prescaler = <0>; }; + spi137: spi@9d6000 { + compatible = "nordic,nrf-spim"; + reg = <0x9d6000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart137: uart@9d6000 { compatible = "nordic,nrf-uarte"; reg = <0x9d6000 0x1000>; From 6c3ea1189e0bf27ded544204a500bcad39c92f3d Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:22:09 +0100 Subject: [PATCH 1484/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add TWIM nodes Add nodes for I2C/TWIM. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 3e551c3be7fcbfbe353197adc9855671c80d7874) --- dts/common/nordic/nrf54h20_enga.dtsi | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index caaf430de70..5965390bb49 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -379,6 +379,15 @@ prescaler = <0>; }; + i2c130: i2c@9a5000 { + compatible = "nordic,nrf-twim"; + reg = <0x9a5000 0x1000>; + status = "disabled"; + interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi130: spi@9a5000 { compatible = "nordic,nrf-spim"; reg = <0x9a5000 0x1000>; @@ -397,6 +406,15 @@ interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; }; + i2c131: i2c@9a6000 { + compatible = "nordic,nrf-twim"; + reg = <0x9a6000 0x1000>; + status = "disabled"; + interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi131: spi@9a6000 { compatible = "nordic,nrf-spim"; reg = <0x9a6000 0x1000>; @@ -435,6 +453,15 @@ prescaler = <0>; }; + i2c132: i2c@9b5000 { + compatible = "nordic,nrf-twim"; + reg = <0x9b5000 0x1000>; + status = "disabled"; + interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi132: spi@9b5000 { compatible = "nordic,nrf-spim"; reg = <0x9b5000 0x1000>; @@ -453,6 +480,15 @@ interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; }; + i2c133: i2c@9b6000 { + compatible = "nordic,nrf-twim"; + reg = <0x9b6000 0x1000>; + status = "disabled"; + interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi133: spi@9b6000 { compatible = "nordic,nrf-spim"; reg = <0x9b6000 0x1000>; @@ -491,6 +527,15 @@ prescaler = <0>; }; + i2c134: i2c@9c5000 { + compatible = "nordic,nrf-twim"; + reg = <0x9c5000 0x1000>; + status = "disabled"; + interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi134: spi@9c5000 { compatible = "nordic,nrf-spim"; reg = <0x9c5000 0x1000>; @@ -509,6 +554,15 @@ interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; }; + i2c135: i2c@9c6000 { + compatible = "nordic,nrf-twim"; + reg = <0x9c6000 0x1000>; + status = "disabled"; + interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi135: spi@9c6000 { compatible = "nordic,nrf-spim"; reg = <0x9c6000 0x1000>; @@ -527,6 +581,15 @@ interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; }; + i2c136: i2c@9d5000 { + compatible = "nordic,nrf-twim"; + reg = <0x9d5000 0x1000>; + status = "disabled"; + interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi136: spi@9d5000 { compatible = "nordic,nrf-spim"; reg = <0x9d5000 0x1000>; @@ -565,6 +628,15 @@ prescaler = <0>; }; + i2c137: i2c@9d6000 { + compatible = "nordic,nrf-twim"; + reg = <0x9d6000 0x1000>; + status = "disabled"; + interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi137: spi@9d6000 { compatible = "nordic,nrf-spim"; reg = <0x9d6000 0x1000>; From ed3108ab02cfcbca6df9c05408d4639fbbd2ea10 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:24:16 +0100 Subject: [PATCH 1485/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add QDEC nodes Add nodes for QDEC (Quadrature Decoder). Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 6d48f4628091900ba102fa60efc7525117607fe4) --- dts/common/nordic/nrf54h20_enga.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 5965390bb49..010c0021a88 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,6 +352,20 @@ port = <9>; }; + qdec130: qdec@994000 { + compatible = "nordic,nrf-qdec"; + reg = <0x994000 0x1000>; + status = "disabled"; + interrupts = <404 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + qdec131: qdec@995000 { + compatible = "nordic,nrf-qdec"; + reg = <0x995000 0x1000>; + status = "disabled"; + interrupts = <405 NRF_DEFAULT_IRQ_PRIORITY>; + }; + grtc: grtc@99c000 { compatible = "nordic,nrf-grtc"; reg = <0x99c000 0x1000>; From 9e06e58a82b5f59d8e0f23e60c4c1b53472f76af Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:25:11 +0100 Subject: [PATCH 1486/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add NFCT node Add node for the NFCT (Near Field Connect Tag) peripheral. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 79bbc551ffb4d438257003970de60b53d0200359) --- dts/common/nordic/nrf54h20_enga.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 010c0021a88..e7a0c1ddd19 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,6 +352,13 @@ port = <9>; }; + nfct: nfct@985000 { + compatible = "nordic,nrf-nfct"; + reg = <0x985000 0x1000>; + status = "disabled"; + interrupts = <389 NRF_DEFAULT_IRQ_PRIORITY>; + }; + qdec130: qdec@994000 { compatible = "nordic,nrf-qdec"; reg = <0x994000 0x1000>; From 17b3ace31c236d43acd9f9474994e8cf45c8df1b Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:26:19 +0100 Subject: [PATCH 1487/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add TEMP node Add nodes for the TEMP (temperature sensor) peripheral. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit f6a3452b262842a219940f5e7b90e69a8e1fb9cb) --- dts/common/nordic/nrf54h20_enga.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index e7a0c1ddd19..e65abbf961f 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,6 +352,13 @@ port = <9>; }; + temp: temperature-sensor@984000 { + compatible = "nordic,nrf-temp"; + reg = <0x984000 0x1000>; + interrupts = <388 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; + }; + nfct: nfct@985000 { compatible = "nordic,nrf-nfct"; reg = <0x985000 0x1000>; From f87d675c67c1eeb456bcf42e3e777dff345ef5f9 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:31:04 +0100 Subject: [PATCH 1488/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add COMP node Add node for COMP (comparator). Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit f19cd55a4a899ed5810077cbf1655fbfb0d11208) --- dts/common/nordic/nrf54h20_enga.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index e65abbf961f..cf67efd889f 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,6 +352,14 @@ port = <9>; }; + comp: comparator@983000 { + compatible = "nordic,nrf-comp"; + reg = <0x983000 0x1000>; + status = "disabled"; + interrupts = <387 NRF_DEFAULT_IRQ_PRIORITY>; + #io-channel-cells = <1>; + }; + temp: temperature-sensor@984000 { compatible = "nordic,nrf-temp"; reg = <0x984000 0x1000>; From 503e08d3036c3f144e6dd38fe4e445da7b8e3882 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:37:02 +0100 Subject: [PATCH 1489/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add EGU node Add node for EGU (Event Generator Unit). Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit ce88cdf490183210b5fa8590b4e9431b7dd7201a) --- dts/common/nordic/nrf54h20_enga.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index cf67efd889f..1e1054fc4b8 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -147,6 +147,13 @@ nordic,ficr-names = "vsup", "coarse", "fine"; }; + egu020: egu@25000 { + compatible = "nordic,nrf-egu"; + reg = <0x25000 0x1000>; + status = "disabled"; + interrupts = <37 NRF_DEFAULT_IRQ_PRIORITY>; + }; + timer020: timer@28000 { compatible = "nordic,nrf-timer"; reg = <0x28000 0x1000>; From b193f186e19996e409fe3c5f4c09fa2154711890 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:17:29 +0100 Subject: [PATCH 1490/1623] [nrf fromlist] modules: hal_nordic: add support for EGU020 Add HAL glue code to support EGU020. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit c81b07ff33d978ab8995b0713c71de0ab572f446) --- modules/hal_nordic/nrfx/Kconfig | 5 +++++ modules/hal_nordic/nrfx/nrfx_config.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 34dbb43f3d4..88b19159730 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -62,6 +62,11 @@ config NRFX_EGU5 depends on $(dt_nodelabel_has_compat,egu5,$(DT_COMPAT_NORDIC_NRF_EGU)) select NRFX_EGU +config NRFX_EGU020 + bool "EGU020 driver instance" + depends on $(dt_nodelabel_has_compat,egu020,$(DT_COMPAT_NORDIC_NRF_EGU)) + select NRFX_EGU + config NRFX_GPIOTE bool diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 0f52cd17cf2..5ec7b137703 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -108,6 +108,9 @@ #ifdef CONFIG_NRFX_EGU5 #define NRFX_EGU5_ENABLED 1 #endif +#ifdef CONFIG_NRFX_EGU020 +#define NRFX_EGU020_ENABLED 1 +#endif #ifdef CONFIG_NRFX_GRTC #define NRFX_GRTC_ENABLED 1 From cc7ad5c313473c6a8c90af8c2bc07b98de8d216e Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:18:23 +0100 Subject: [PATCH 1491/1623] [nrf fromlist] soc: nordic_nrf: add support for EGU020 Add support for EGU020. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit fc9d5d7842495baba23276368816ed559b3965c7) --- soc/common/nordic_nrf/Kconfig.peripherals | 3 +++ 1 file changed, 3 insertions(+) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index b3e0ae2d130..2b77cf0b849 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -65,6 +65,9 @@ config HAS_HW_NRF_EGU4 config HAS_HW_NRF_EGU5 def_bool $(dt_nodelabel_enabled_with_compat,egu5,$(DT_COMPAT_NORDIC_NRF_EGU)) +config HAS_HW_NRF_EGU020 + def_bool $(dt_nodelabel_enabled_with_compat,egu020,$(DT_COMPAT_NORDIC_NRF_EGU)) + config HAS_HW_NRF_GPIO0 def_bool $(dt_nodelabel_enabled_with_compat,gpio0,$(DT_COMPAT_NORDIC_NRF_GPIO)) From 409eaad0a6e2453cb9378a183a30f5647540ee0a Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:38:13 +0100 Subject: [PATCH 1492/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add RADIO node Add node for the RADIO. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit c3fa1ff455a9f3c0c24fe3cd8fc0676ea04d1dca) --- dts/common/nordic/nrf54h20_enga.dtsi | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 1e1054fc4b8..5476b28a920 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -193,6 +193,22 @@ interrupts = <43 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <1>; }; + + radio: radio@2c000 { + compatible = "nordic,nrf-radio"; + reg = <0x2c000 0x1000>; + status = "disabled"; + ble-2mbps-supported; + ble-coded-phy-supported; + dfe-supported; + ieee802154-supported; + interrupts = <44 NRF_DEFAULT_IRQ_PRIORITY>; + + cpurad_ieee802154: ieee802154 { + compatible = "nordic,nrf-ieee802154"; + status = "disabled"; + }; + }; }; global_peripherals: peripheral@5f000000 { From 207dce17040701862ae577ef7a08c80a2477b6d7 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:39:25 +0100 Subject: [PATCH 1493/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add ECB node Add node for ECB (AES electronic codebook mode encryption). Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 8976960b89a6233aaf0b293506f795eaf65c087c) --- dts/common/nordic/nrf54h20_enga.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 5476b28a920..96f6c0120a8 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -209,6 +209,13 @@ status = "disabled"; }; }; + + ecb030: ecb@3b000 { + compatible = "nordic,nrf-ecb"; + reg = <0x3b000 0x1000>; + interrupts = <59 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; + }; }; global_peripherals: peripheral@5f000000 { From 6a071a2cb11c26b1b4c89da57cbb459beca6753a Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:42:15 +0100 Subject: [PATCH 1494/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add WDT nodes Add nodes for WDT (Watchdog Timer). Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit a0ec7aa18e2fcb0a2d3a65e18f35057b00d2f435) --- dts/common/nordic/nrf54h20_enga.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 96f6c0120a8..6683d5c155a 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -311,6 +311,20 @@ prescaler = <1>; }; + wdt131: watchdog@92b000 { + compatible = "nordic,nrf-wdt"; + reg = <0x92b000 0x1000>; + status = "disabled"; + interrupts = <299 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + wdt132: watchdog@92c000 { + compatible = "nordic,nrf-wdt"; + reg = <0x92c000 0x1000>; + status = "disabled"; + interrupts = <300 NRF_DEFAULT_IRQ_PRIORITY>; + }; + gpiote130: gpiote@934000 { compatible = "nordic,nrf-gpiote"; reg = <0x934000 0x1000>; From d4f7cb27ad3e35ed5607b665d7628976f59bc7ae Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:24:27 +0100 Subject: [PATCH 1495/1623] [nrf fromlist] modules: hal_nordic: add support for WDT131-132 Add HAL glue code to support WDT131-132. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 7c99d99d2de9e5de46567638c26c3bf53c76d913) --- modules/hal_nordic/nrfx/Kconfig | 10 ++++++++++ modules/hal_nordic/nrfx/nrfx_config.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 88b19159730..a511af42e17 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -815,6 +815,16 @@ config NRFX_WDT130 depends on $(dt_nodelabel_has_compat,wdt130,$(DT_COMPAT_NORDIC_NRF_WDT)) select NRFX_WDT +config NRFX_WDT131 + bool "WDT131 driver instance" + depends on $(dt_nodelabel_has_compat,wdt131,$(DT_COMPAT_NORDIC_NRF_WDT)) + select NRFX_WDT + +config NRFX_WDT132 + bool "WDT132 driver instance" + depends on $(dt_nodelabel_has_compat,wdt132,$(DT_COMPAT_NORDIC_NRF_WDT)) + select NRFX_WDT + menu "Peripheral Resource Sharing module" config NRFX_PRS diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 5ec7b137703..5ebc243541e 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -722,6 +722,12 @@ #ifdef CONFIG_NRFX_WDT130 #define NRFX_WDT130_ENABLED 1 #endif +#ifdef CONFIG_NRFX_WDT131 +#define NRFX_WDT131_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_WDT132 +#define NRFX_WDT132_ENABLED 1 +#endif #ifdef CONFIG_NRF52_ANOMALY_109_WORKAROUND #define NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 1 From 14727994bc9288091d8a236221a977f6e42e74aa Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:25:01 +0100 Subject: [PATCH 1496/1623] [nrf fromlist] soc: nordic_nrf: add support for WDT131-132 Add new Kconfig options to select WDT131-132. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit a5997c224c04efd87586e8863bc635419ed4cbb5) --- soc/common/nordic_nrf/Kconfig.peripherals | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index 2b77cf0b849..8326294f606 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -538,3 +538,9 @@ config HAS_HW_NRF_WDT31 config HAS_HW_NRF_WDT130 def_bool $(dt_nodelabel_enabled_with_compat,wdt130,$(DT_COMPAT_NORDIC_NRF_WDT)) + +config HAS_HW_NRF_WDT131 + def_bool $(dt_nodelabel_enabled_with_compat,wdt131,$(DT_COMPAT_NORDIC_NRF_WDT)) + +config HAS_HW_NRF_WDT132 + def_bool $(dt_nodelabel_enabled_with_compat,wdt132,$(DT_COMPAT_NORDIC_NRF_WDT)) From 88f1d4fca1dbe5b319d8c6eab16835c61778d184 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:20:18 +0100 Subject: [PATCH 1497/1623] [nrf fromlist] soc: nordic_nrf: add missing GRTC Kconfig option Add missing option to select GRTC. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69201 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit e201c6cee9762707f58bdca4d75683fb1ad1919e) --- soc/common/nordic_nrf/Kconfig.peripherals | 3 +++ 1 file changed, 3 insertions(+) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index 8326294f606..a6b62428626 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -92,6 +92,9 @@ config HAS_HW_NRF_GPIOTE130 config HAS_HW_NRF_GPIOTE131 def_bool $(dt_nodelabel_enabled_with_compat,gpiote131,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) +config HAS_HW_NRF_GRTC + def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_GRTC)) + config HAS_HW_NRF_I2S0 def_bool $(dt_nodelabel_enabled_with_compat,i2s0,$(DT_COMPAT_NORDIC_NRF_I2S)) From 9568c08251ee2fa29520ebe998762b72ccec4ecd Mon Sep 17 00:00:00 2001 From: Piotr Kosycarz Date: Thu, 22 Feb 2024 15:04:28 +0100 Subject: [PATCH 1498/1623] [nrf noup] testspec: Add Low Level specification Testing drivers. Signed-off-by: Piotr Kosycarz --- .github/test-spec.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/test-spec.yml b/.github/test-spec.yml index ead2ab8bb2a..d9dcf1280f1 100644 --- a/.github/test-spec.yml +++ b/.github/test-spec.yml @@ -276,3 +276,22 @@ - "drivers/regulator/regulator_shell.c" - "drivers/gpio/gpio_shell.c" - "drivers/sensor/sensor_shell.c" + +"CI-test-low-level": + - "dts/**/*" + - "include/zephyr/**/*" + - "tests/arch/**/*" + - "arch/**/*" + - "tests/kernel/**/*" + - "kernel/**/*" + - "tests/drivers/**/*" + - "drivers/**/*" + - "samples/subsys/settings/**/*" + - "subsys/settings/**/*" + - "samples/subsys/logging/**/*" + - "subsys/logging/**/*" + - "samples/sensor/**/*" + - "samples/hello_world/**/*" + - "samples/synchronization/**/*" + - "samples/drivers/watchdog/**/*" + - "modules/hal_nordic/**/*" From d0effecc0cbcce1fc40659577237265ce1817ae3 Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Thu, 22 Feb 2024 17:28:58 +0530 Subject: [PATCH 1499/1623] [nrf fromlist] net: ensure the sh is valid before call shell_printf It is possible that the `sh` was not set before use. This change adds a NULL check for `sh` in the following macros: PR, PR_SHELL, PR_ERROR, PR_INFO, and PR_WARNING. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/68812 Signed-off-by: Kapil Bhatt --- subsys/net/lib/shell/net_shell_private.h | 40 ++++++++++++++++++------ 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/subsys/net/lib/shell/net_shell_private.h b/subsys/net/lib/shell/net_shell_private.h index 8b5566022d9..6d70d321f60 100644 --- a/subsys/net/lib/shell/net_shell_private.h +++ b/subsys/net/lib/shell/net_shell_private.h @@ -8,20 +8,40 @@ #include #include -#define PR(fmt, ...) \ - shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__) +#define PR(fmt, ...) \ + do { \ + if (sh) { \ + shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__); \ + } \ + } while (false) -#define PR_SHELL(sh, fmt, ...) \ - shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__) +#define PR_SHELL(sh, fmt, ...) \ + do { \ + if (sh) { \ + shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__); \ + } \ + } while (false) -#define PR_ERROR(fmt, ...) \ - shell_fprintf(sh, SHELL_ERROR, fmt, ##__VA_ARGS__) +#define PR_ERROR(fmt, ...) \ + do { \ + if (sh) { \ + shell_fprintf(sh, SHELL_ERROR, fmt, ##__VA_ARGS__); \ + } \ + } while (false) -#define PR_INFO(fmt, ...) \ - shell_fprintf(sh, SHELL_INFO, fmt, ##__VA_ARGS__) +#define PR_INFO(fmt, ...) \ + do { \ + if (sh) { \ + shell_fprintf(sh, SHELL_INFO, fmt, ##__VA_ARGS__); \ + } \ + } while (false) -#define PR_WARNING(fmt, ...) \ - shell_fprintf(sh, SHELL_WARNING, fmt, ##__VA_ARGS__) +#define PR_WARNING(fmt, ...) \ + do { \ + if (sh) { \ + shell_fprintf(sh, SHELL_WARNING, fmt, ##__VA_ARGS__); \ + } \ + } while (false) #include "net_private.h" #include "../ip/ipv6.h" From 577ef433310216cbc4acd38be0724f0821ffa520 Mon Sep 17 00:00:00 2001 From: Rubin Gerritsen Date: Tue, 20 Feb 2024 15:05:57 +0100 Subject: [PATCH 1500/1623] [nrf fromlist] Bluetooth: Controller: Remove experimental from LE Set Host Feature Out-of-tree controllers do not necessarily mark the LE Set Host Feature command as experimantal. Add an additional entry to solve this like done for other ISO entries. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69245 Signed-off-by: Rubin Gerritsen --- subsys/bluetooth/controller/Kconfig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 077c8e4f6f5..91f4f08c15c 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -813,11 +813,14 @@ config BT_CTLR_SYNC_ISO_PDU_LEN_MAX endif # BT_CTLR_ADV_EXT config BT_CTLR_SET_HOST_FEATURE - bool "LE Set Host Feature Command [EXPERIMENTAL]" - select EXPERIMENTAL + bool "LE Set Host Feature Command" if !BT_LL_SW_SPLIT help Enables optional LE Set Host Feature Command +config BT_CTLR_SET_HOST_FEATURE + bool "LE Set Host Feature Command (Split Link Layer) [EXPERIMENTAL]" if BT_LL_SW_SPLIT + select EXPERIMENTAL if BT_LL_SW_SPLIT + config BT_CTLR_CENTRAL_ISO bool "LE Connected Isochronous Stream Central" if !BT_LL_SW_SPLIT depends on BT_CTLR_CENTRAL_ISO_SUPPORT && BT_CENTRAL From 73c45775c314af2b0c1c8ee4837caafa6439c166 Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 21 Feb 2024 13:21:30 +0200 Subject: [PATCH 1501/1623] [nrf fromlist] modem: backends: uart_async: log the number of bytes dropped Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69288 When a receive buffer overrun happens. Signed-off-by: Tomi Fontanilles --- subsys/modem/backends/modem_backend_uart_async.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/modem/backends/modem_backend_uart_async.c b/subsys/modem/backends/modem_backend_uart_async.c index 29107198c2f..0fa3684780e 100644 --- a/subsys/modem/backends/modem_backend_uart_async.c +++ b/subsys/modem/backends/modem_backend_uart_async.c @@ -114,7 +114,8 @@ static void modem_backend_uart_async_event_handler(const struct device *dev, if (received < evt->data.rx.len) { ring_buf_reset(&backend->async.receive_rb); k_spin_unlock(&backend->async.receive_rb_lock, key); - LOG_WRN("Receive buffer overrun"); + LOG_WRN("Receive buffer overrun (%u/%u dropped)", + evt->data.rx.len - received, evt->data.rx.len); break; } From f7718c38852467bb30095015c92222ddaddd57d5 Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 21 Feb 2024 13:27:31 +0200 Subject: [PATCH 1502/1623] [nrf fromlist] drivers: modem_cellular: fine tune nRF91's shutdown_time Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69288 A shutdown lasting more than 5 seconds was experienced. Signed-off-by: Tomi Fontanilles --- drivers/modem/modem_cellular.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/modem/modem_cellular.c b/drivers/modem/modem_cellular.c index ed4e998fec3..276c9d38f7b 100644 --- a/drivers/modem/modem_cellular.c +++ b/drivers/modem/modem_cellular.c @@ -2219,7 +2219,7 @@ MODEM_CHAT_SCRIPT_DEFINE(nordic_nrf91_slm_periodic_chat_script, .power_pulse_duration_ms = 100, \ .reset_pulse_duration_ms = 100, \ .startup_time_ms = 2000, \ - .shutdown_time_ms = 3000, \ + .shutdown_time_ms = 10000, \ .init_chat_script = &nordic_nrf91_slm_init_chat_script, \ .dial_chat_script = &nordic_nrf91_slm_dial_chat_script, \ .periodic_chat_script = &nordic_nrf91_slm_periodic_chat_script, \ From 86d6106f9c3836bd97ddd6bd82d9e1964641fa7f Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Wed, 21 Feb 2024 13:36:22 +0200 Subject: [PATCH 1503/1623] [nrf fromlist] samples: net: cellular_modem: small fixes/improvements Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69288 - A small delay is added after the post-restart L4_CONNECTED event is received to prevent trying to send packets too quickly. Otherwise the first packet would not get sent and the sample would hang on recv(). - Some logs and function parameters are fixed. Signed-off-by: Tomi Fontanilles --- samples/net/cellular_modem/prj.conf | 4 +++ samples/net/cellular_modem/src/main.c | 39 ++++++++++++++------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/samples/net/cellular_modem/prj.conf b/samples/net/cellular_modem/prj.conf index 52d0ca26bde..ab44ca9528e 100644 --- a/samples/net/cellular_modem/prj.conf +++ b/samples/net/cellular_modem/prj.conf @@ -22,3 +22,7 @@ CONFIG_NET_CONNECTION_MANAGER=y CONFIG_MODEM=y CONFIG_PM_DEVICE=y CONFIG_MODEM_CELLULAR=y + +# Logging +CONFIG_MODEM_MODULES_LOG_LEVEL_DBG=y +#CONFIG_MODEM_CMUX_LOG_LEVEL_DBG=y diff --git a/samples/net/cellular_modem/src/main.c b/samples/net/cellular_modem/src/main.c index 543f8d6d711..422b19b3c34 100644 --- a/samples/net/cellular_modem/src/main.c +++ b/samples/net/cellular_modem/src/main.c @@ -116,7 +116,7 @@ int sample_echo_packet(struct sockaddr *ai_addr, socklen_t ai_addrlen, uint16_t continue; } - printk("Receiving echoed packet"); + printk("Receiving echoed packet\n"); ret = zsock_recv(socket_fd, sample_recv_buffer, sizeof(sample_recv_buffer), 0); if (ret != sizeof(sample_test_packet)) { printk("Echoed sample test packet has incorrect size\n"); @@ -137,10 +137,10 @@ int sample_echo_packet(struct sockaddr *ai_addr, socklen_t ai_addrlen, uint16_t printk("Echo transmit time %ums\n", echo_received_ms - send_start_ms); } - printk("Successfully sent %u packets of %u packets\n", packets_sent, + printk("Successfully sent and received %u of %u packets\n", packets_sent, SAMPLE_TEST_ECHO_PACKETS); - printk("Average time per echo: %u ms\n", + printk("Average time per successful echo: %u ms\n", accumulated_ms / packets_sent); printk("Close UDP socket\n"); @@ -221,10 +221,7 @@ int sample_transmit_packets(struct sockaddr *ai_addr, socklen_t ai_addrlen, uint int main(void) { struct net_if *const iface = net_if_get_first_by_type(&NET_L2_GET_NAME(PPP)); - uint32_t raised_event; uint16_t *port; - const void *info; - size_t info_len; int ret; init_sample_test_packet(); @@ -240,9 +237,8 @@ int main(void) } printk("Waiting for L4 connected\n"); - ret = net_mgmt_event_wait_on_iface(iface, - NET_EVENT_L4_CONNECTED, &raised_event, &info, - &info_len, K_SECONDS(120)); + ret = net_mgmt_event_wait_on_iface(iface, NET_EVENT_L4_CONNECTED, NULL, NULL, NULL, + K_SECONDS(120)); if (ret != 0) { printk("L4 was not connected in time\n"); @@ -250,9 +246,12 @@ int main(void) } printk("Waiting for DNS server added\n"); - ret = net_mgmt_event_wait_on_iface(iface, - NET_EVENT_DNS_SERVER_ADD, &raised_event, &info, - &info_len, K_SECONDS(10)); + ret = net_mgmt_event_wait_on_iface(iface, NET_EVENT_DNS_SERVER_ADD, NULL, NULL, NULL, + K_SECONDS(10)); + if (ret) { + printk("DNS server was not added in time\n"); + return -1; + } printk("Performing DNS lookup of %s\n", SAMPLE_TEST_ENDPOINT_HOSTNAME); ret = sample_dns_request(); @@ -286,7 +285,7 @@ int main(void) sample_test_dns_addrinfo.ai_addrlen, port); if (ret < 0) { - printk("Failed to send echo\n"); + printk("Failed to send echos\n"); return -1; } @@ -308,24 +307,26 @@ int main(void) pm_device_action_run(modem, PM_DEVICE_ACTION_RESUME); printk("Waiting for L4 connected\n"); - ret = net_mgmt_event_wait_on_iface(net_if_get_default(), - NET_EVENT_L4_CONNECTED, &raised_event, &info, - &info_len, K_SECONDS(60)); - + ret = net_mgmt_event_wait_on_iface(iface, NET_EVENT_L4_CONNECTED, NULL, NULL, NULL, + K_SECONDS(60)); if (ret != 0) { printk("L4 was not connected in time\n"); return -1; } + printk("L4 connected\n"); + + /* Wait a bit to avoid (unsuccessfully) trying to send the first echo packet too quickly. */ + k_sleep(K_SECONDS(1)); ret = sample_echo_packet(&sample_test_dns_addrinfo.ai_addr, sample_test_dns_addrinfo.ai_addrlen, port); if (ret < 0) { - printk("Failed to send echo after restart\n"); + printk("Failed to send echos after restart\n"); return -1; } - ret = net_if_down(net_if_get_default()); + ret = net_if_down(iface); if (ret < 0) { printk("Failed to bring down network interface\n"); return -1; From 40a147896ec6e679ee96fbc9c16328054326d75e Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Thu, 22 Feb 2024 14:54:45 +0200 Subject: [PATCH 1504/1623] [nrf fromlist] samples: net: cellular_modem: add nRF9160 DK's nRF52840 Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69288 The added configuration files allow the sample to be run on the nRF52840 present on the nRF9160 DK with the nRF9160 (running SLM) being the modem and communication happening through pins that are routed internally between the two. Signed-off-by: Tomi Fontanilles --- .../boards/nrf9160dk_nrf52840.conf | 13 +++++++++++++ .../boards/nrf9160dk_nrf52840.overlay | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 samples/net/cellular_modem/boards/nrf9160dk_nrf52840.conf create mode 100644 samples/net/cellular_modem/boards/nrf9160dk_nrf52840.overlay diff --git a/samples/net/cellular_modem/boards/nrf9160dk_nrf52840.conf b/samples/net/cellular_modem/boards/nrf9160dk_nrf52840.conf new file mode 100644 index 00000000000..2af3b6d2a41 --- /dev/null +++ b/samples/net/cellular_modem/boards/nrf9160dk_nrf52840.conf @@ -0,0 +1,13 @@ +CONFIG_UART_ASYNC_API=y + +# Align with the Serial LTE Modem (SLM) application. +CONFIG_MODEM_CELLULAR_CMUX_MAX_FRAME_SIZE=1500 +CONFIG_MODEM_CELLULAR_UART_BUFFER_SIZES=1500 + +# Allow large UART TXs to go through @115200. +CONFIG_MODEM_BACKEND_UART_ASYNC_TRANSMIT_TIMEOUT_MS=200 + +# Print logs and printk() output on uart0. +CONFIG_LOG=y +CONFIG_LOG_BACKEND_UART=y +CONFIG_MODEM_LOG_LEVEL_DBG=y diff --git a/samples/net/cellular_modem/boards/nrf9160dk_nrf52840.overlay b/samples/net/cellular_modem/boards/nrf9160dk_nrf52840.overlay new file mode 100644 index 00000000000..c639ec8b305 --- /dev/null +++ b/samples/net/cellular_modem/boards/nrf9160dk_nrf52840.overlay @@ -0,0 +1,18 @@ +#include + +/ { + aliases { + modem = &modem; + }; +}; + +&uart1 { + current-speed = <115200>; + hw-flow-control; + + modem: modem { + compatible = "nordic,nrf91-slm"; + status = "okay"; + mdm-power-gpios = <&interface_to_nrf9160 4 GPIO_ACTIVE_LOW>; + }; +}; From 2977baaec1238116c8fb8ae76757afc173e1dc07 Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Thu, 22 Feb 2024 13:42:14 +0100 Subject: [PATCH 1505/1623] [nrf fromlist] drivers: sensor: adxl367: fix trigger support The adxl367_trigger.c file was missing a DT_COMPAT definition, which resulted in the driver config structs being misaligned between the driver source files. This is fixed here. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69339 Signed-off-by: Maximilian Deubel (cherry picked from commit b7a83778dff35a6c94b20509453d31ef0caaabb7) --- drivers/sensor/adxl367/adxl367_trigger.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/sensor/adxl367/adxl367_trigger.c b/drivers/sensor/adxl367/adxl367_trigger.c index 4e86d466343..534bd07324e 100644 --- a/drivers/sensor/adxl367/adxl367_trigger.c +++ b/drivers/sensor/adxl367/adxl367_trigger.c @@ -4,6 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#define DT_DRV_COMPAT adi_adxl367 + #include #include #include From 86bf8d3d8b6033acba65d17933cf1091a552c1b0 Mon Sep 17 00:00:00 2001 From: Jui-Chou Chung Date: Fri, 16 Feb 2024 22:05:31 +0800 Subject: [PATCH 1506/1623] [nrf fromlist] boards: added arduino pins to nrf5340 audio DK network core Added arduino pin definition for nRF5340 audio DK network core, so we can use nrf21540-ek easily with SDC. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69085 Signed-off-by: Jui-Chou Chung (cherry picked from commit 5a29acce05deffa81087b732091638413b5a2271) Signed-off-by: Jui-Chou Chung --- ...f5340_audio_dk_nrf5340_cpunet-pinctrl.dtsi | 17 ++++++++ .../nrf5340_audio_dk_nrf5340_cpunet.dts | 40 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet-pinctrl.dtsi b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet-pinctrl.dtsi index ada32e709ac..6804c040d12 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet-pinctrl.dtsi +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet-pinctrl.dtsi @@ -26,4 +26,21 @@ }; }; + spi0_default: spi0_default { + group1 { + psels = , + , + ; + }; + }; + + spi0_sleep: spi0_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; + }; diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet.dts b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet.dts index 16aa4179fa9..22a05cac020 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet.dts +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet.dts @@ -24,6 +24,46 @@ zephyr,code-partition = &slot0_partition; watchdog0 = &wdt0; }; + + arduino_header: connector { + compatible = "arduino-header-r3"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &gpio0 4 0>, /* A0 */ + <1 0 &gpio0 5 0>, /* A1 */ + <2 0 &gpio0 6 0>, /* A2 */ + <3 0 &gpio0 7 0>, /* A3 */ + <4 0 &gpio0 25 0>, /* A4 */ + <5 0 &gpio0 26 0>, /* A5 */ + <6 0 &gpio1 9 0>, /* D0 */ + <7 0 &gpio1 8 0>, /* D1 */ + <8 0 &gpio0 31 0>, /* D2 */ + <9 0 &gpio1 0 0>, /* D3 */ + <10 0 &gpio1 1 0>, /* D4 */ + <11 0 &gpio1 14 0>, /* D5 */ + <12 0 &gpio1 7 0>, /* D6 */ + <13 0 &gpio1 11 0>, /* D7 */ + <14 0 &gpio1 10 0>, /* D8 */ + <15 0 &gpio1 13 0>, /* D9 */ + <16 0 &gpio1 12 0>, /* D10 */ + <17 0 &gpio0 9 0>, /* D11 */ + <18 0 &gpio0 10 0>, /* D12 */ + <19 0 &gpio0 8 0>, /* D13 */ + <20 0 &gpio1 2 0>, /* D14 */ + <21 0 &gpio1 3 0>; /* D15 */ + }; + +}; + +arduino_spi: &spi0 { + compatible = "nordic,nrf-spim"; + /* Cannot be used together with uart0. */ + /* status = "okay"; */ + cs-gpios = <&arduino_header 16 GPIO_ACTIVE_LOW>; /* D10 */ + pinctrl-0 = <&spi0_default>; + pinctrl-1 = <&spi0_sleep>; + pinctrl-names = "default", "sleep"; }; &gpiote { From 17d9e0f7bdfda0a4c88e6ba880d2b0a7314c6cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Ciupis?= Date: Fri, 23 Feb 2024 13:13:10 +0100 Subject: [PATCH 1507/1623] [nrf fromlist] drivers: ieee802154: gracefully handle invalid Ack timestamp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The nRF IEEE 802.15.4 driver might report a received Ack frame with invalid timestamp, if the timestamp could not have been taken. The upper layers are not prepared to handle such a case as they expect that for a received frame, the timestamp is always present and valid. This commit detects this situation and handles it gracefully by reporting the transmission as failed as if no Ack was received. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69388 Signed-off-by: Jędrzej Ciupis --- drivers/ieee802154/ieee802154_nrf5.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index 1831a5b4a6a..80435f06fba 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -387,6 +387,17 @@ static int handle_ack(struct nrf5_802154_data *nrf5_radio) struct net_pkt *ack_pkt; int err = 0; +#if defined(CONFIG_NET_PKT_TIMESTAMP) + if (nrf5_radio->ack_frame.time == NRF_802154_NO_TIMESTAMP) { + /* Ack timestamp is invalid and cannot be used by the upper layer. + * Report the transmission as failed as if the Ack was not received at all. + */ + LOG_WRN("Invalid ACK timestamp."); + err = -ENOMSG; + goto free_nrf_ack; + } +#endif + if (IS_ENABLED(CONFIG_IEEE802154_NRF5_FCS_IN_LENGTH)) { ack_len = nrf5_radio->ack_frame.psdu[0]; } else { @@ -1130,8 +1141,14 @@ void nrf_802154_transmitted_raw(uint8_t *frame, nrf5_data.ack_frame.lqi = metadata->data.transmitted.lqi; #if defined(CONFIG_NET_PKT_TIMESTAMP) - nrf5_data.ack_frame.time = nrf_802154_timestamp_end_to_phr_convert( - metadata->data.transmitted.time, nrf5_data.ack_frame.psdu[0]); + if (metadata->data.transmitted.time == NRF_802154_NO_TIMESTAMP) { + /* Ack timestamp is invalid. Keep this value to detect it when handling Ack + */ + nrf5_data.ack_frame.time = NRF_802154_NO_TIMESTAMP; + } else { + nrf5_data.ack_frame.time = nrf_802154_timestamp_end_to_phr_convert( + metadata->data.transmitted.time, nrf5_data.ack_frame.psdu[0]); + } #endif } From 51cdc6d42099cb1b76bdb91fff439f15ea2c64e2 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Fri, 26 Jan 2024 11:18:09 +0100 Subject: [PATCH 1508/1623] [nrf fromtree] version: export tweak version in version.h The commit export TWEAK version to code through version.h. This aligns the symbols available in code with those available in CMake and Kconfig. The new define is available for both KERNEL, APP, and custom version types (such as MCUBOOT). Signed-off-by: Torsten Rasmussen (cherry picked from commit 738999e191297c737fda647b5ba73e9897a581a8) --- doc/build/version/index.rst | 2 ++ version.h.in | 1 + 2 files changed, 3 insertions(+) diff --git a/doc/build/version/index.rst b/doc/build/version/index.rst index 8d169a85bf5..ef702c7ac2c 100644 --- a/doc/build/version/index.rst +++ b/doc/build/version/index.rst @@ -91,6 +91,8 @@ following defines are available: +--------------------+-------------------+------------------------------------------------------+-------------------------+ | APP_PATCHLEVEL | Numerical | ``PATCHLEVEL`` | 3 | +--------------------+-------------------+------------------------------------------------------+-------------------------+ +| APP_VERSION_TWEAK | Numerical | ``VERSION_TWEAK`` | 4 | ++--------------------+-------------------+------------------------------------------------------+-------------------------+ | APP_VERSION_STRING | String (quoted) | ``VERSION_MAJOR``, |br| | "1.2.3-unstable" | | | | ``VERSION_MINOR``, |br| | | | | | ``PATCHLEVEL``, |br| | | diff --git a/version.h.in b/version.h.in index c60fb721804..476d97eabbb 100644 --- a/version.h.in +++ b/version.h.in @@ -14,6 +14,7 @@ #define @VERSION_TYPE@_VERSION_MAJOR @@VERSION_TYPE@_VERSION_MAJOR@ #define @VERSION_TYPE@_VERSION_MINOR @@VERSION_TYPE@_VERSION_MINOR@ #define @VERSION_TYPE@_PATCHLEVEL @@VERSION_TYPE@_PATCHLEVEL@ +#define @VERSION_TYPE@_TWEAK @@VERSION_TYPE@_VERSION_TWEAK@ #define @VERSION_TYPE@_VERSION_STRING "@@VERSION_TYPE@_VERSION_STRING@" #define @BUILD_VERSION_NAME@ @@BUILD_VERSION_NAME@@ From ed9ae51ea224e89ba4ec7beda3881c0d9be83f2b Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Fri, 26 Jan 2024 12:19:29 +0100 Subject: [PATCH 1509/1623] [nrf fromtree] version: cmake: kconfig: introduce extra _VERSION__STRING Fixes: #68360 This commit introduces _VERSION_TWEAK_STRING which includes the tweak field in the string, but without the extra version. This format is used by MCUboot / imgtool, and thus makes it easier to align code to the format used by MCUboot. This commit also introduces _VERSION_EXTENDED_STRING which includes the tweak field in the string in addition to the extra version field. The new defines / variables is available in code, CMake, and Kconfig, and it defined for KERNEL, APP, and custom types, such as MCUBOOT. Signed-off-by: Torsten Rasmussen Signed-off-by: Jamie McCrae (cherry picked from commit a306397818d2644e5b2a5222bf5cc3a4a81da0d4) --- cmake/modules/kconfig.cmake | 2 + cmake/modules/version.cmake | 14 ++- doc/build/version/index.rst | 174 +++++++++++++++++++++--------------- version.h.in | 16 ++-- 4 files changed, 123 insertions(+), 83 deletions(-) diff --git a/cmake/modules/kconfig.cmake b/cmake/modules/kconfig.cmake index 1a78b3ebd02..51dd9a0bed0 100644 --- a/cmake/modules/kconfig.cmake +++ b/cmake/modules/kconfig.cmake @@ -133,6 +133,8 @@ set(COMMON_KCONFIG_ENV_SETTINGS srctree=${ZEPHYR_BASE} KERNELVERSION=${KERNELVERSION} APPVERSION=${APP_VERSION_STRING} + APP_VERSION_EXTENDED_STRING=${APP_VERSION_EXTENDED_STRING} + APP_VERSION_TWEAK_STRING=${APP_VERSION_TWEAK_STRING} CONFIG_=${KCONFIG_NAMESPACE}_ KCONFIG_CONFIG=${DOTCONFIG} # Set environment variables so that Kconfig can prune Kconfig source diff --git a/cmake/modules/version.cmake b/cmake/modules/version.cmake index 49d172871e7..4c80c5fcdc9 100644 --- a/cmake/modules/version.cmake +++ b/cmake/modules/version.cmake @@ -11,8 +11,10 @@ # # Outputs with examples:: # -# PROJECT_VERSION 1.14.99.07 -# KERNEL_VERSION_STRING "1.14.99-extraver" +# PROJECT_VERSION 1.14.99.07 +# KERNEL_VERSION_STRING "1.14.99-extraver" +# KERNEL_VERSION_EXTENDED_STRING "1.14.99-extraver+7" +# KERNEL_VERSION_TWEAK_STRING "1.14.99+7" # # KERNEL_VERSION_MAJOR 1 # KERNEL_VERSION_MINOR 14 @@ -62,9 +64,9 @@ foreach(type file IN ZIP_LISTS VERSION_TYPE VERSION_FILE) string(REGEX MATCH "EXTRAVERSION = ([a-z0-9]*)" _ ${ver}) set(${type}_VERSION_EXTRA ${CMAKE_MATCH_1}) - # Temporary convenience variable + # Temporary convenience variables set(${type}_VERSION_WITHOUT_TWEAK ${${type}_VERSION_MAJOR}.${${type}_VERSION_MINOR}.${${type}_PATCHLEVEL}) - + set(${type}_VERSION_WITH_TWEAK ${${type}_VERSION_MAJOR}.${${type}_VERSION_MINOR}.${${type}_PATCHLEVEL}+${${type}_VERSION_TWEAK}) set(MAJOR ${${type}_VERSION_MAJOR}) # Temporary convenience variable set(MINOR ${${type}_VERSION_MINOR}) # Temporary convenience variable @@ -82,6 +84,8 @@ foreach(type file IN ZIP_LISTS VERSION_TYPE VERSION_FILE) else() set(${type}_VERSION_STRING "${${type}_VERSION_WITHOUT_TWEAK}") endif() + set(${type}_VERSION_TWEAK_STRING "${${type}_VERSION_WITH_TWEAK}") + set(${type}_VERSION_EXTENDED_STRING "${${type}_VERSION_STRING}+${${type}_VERSION_TWEAK}") if(type STREQUAL KERNEL) set(PROJECT_VERSION_MAJOR ${${type}_VERSION_MAJOR}) @@ -118,5 +122,7 @@ foreach(type file IN ZIP_LISTS VERSION_TYPE VERSION_FILE) unset(MAJOR) unset(MINOR) unset(PATCH) + unset(TWEAK) unset(${type}_VERSION_WITHOUT_TWEAK) + unset(${type}_VERSION_WITH_TWEAK) endforeach() diff --git a/doc/build/version/index.rst b/doc/build/version/index.rst index ef702c7ac2c..2106a65e169 100644 --- a/doc/build/version/index.rst +++ b/doc/build/version/index.rst @@ -73,87 +73,120 @@ To use the version information in application code, the version file must be inc fields can be freely used. The include file name is :file:`app_version.h` (no path is needed), the following defines are available: -+--------------------+-------------------+------------------------------------------------------+-------------------------+ -| Define | Type | Field(s) | Example | -+--------------------+-------------------+------------------------------------------------------+-------------------------+ -| APPVERSION | Numerical | ``VERSION_MAJOR`` (left shifted by 24 bits), |br| | 0x1020304 | -| | | ``VERSION_MINOR`` (left shifted by 16 bits), |br| | | -| | | ``PATCHLEVEL`` (left shifted by 8 bits), |br| | | -| | | ``VERSION_TWEAK`` | | -+--------------------+-------------------+------------------------------------------------------+-------------------------+ -| APP_VERSION_NUMBER | Numerical | ``VERSION_MAJOR`` (left shifted by 16 bits), |br| | 0x10203 | -| | | ``VERSION_MINOR`` (left shifted by 8 bits), |br| | | -| | | ``PATCHLEVEL`` | | -+--------------------+-------------------+------------------------------------------------------+-------------------------+ -| APP_VERSION_MAJOR | Numerical | ``VERSION_MAJOR`` | 1 | -+--------------------+-------------------+------------------------------------------------------+-------------------------+ -| APP_VERSION_MINOR | Numerical | ``VERSION_MINOR`` | 2 | -+--------------------+-------------------+------------------------------------------------------+-------------------------+ -| APP_PATCHLEVEL | Numerical | ``PATCHLEVEL`` | 3 | -+--------------------+-------------------+------------------------------------------------------+-------------------------+ -| APP_VERSION_TWEAK | Numerical | ``VERSION_TWEAK`` | 4 | -+--------------------+-------------------+------------------------------------------------------+-------------------------+ -| APP_VERSION_STRING | String (quoted) | ``VERSION_MAJOR``, |br| | "1.2.3-unstable" | -| | | ``VERSION_MINOR``, |br| | | -| | | ``PATCHLEVEL``, |br| | | -| | | ``EXTRAVERSION`` |br| | | -+--------------------+-------------------+------------------------------------------------------+-------------------------+ -| APP_BUILD_VERSION | String (unquoted) | None (value of ``git describe --abbrev=12 --always`` | v3.3.0-18-g2c85d9224fca | -| | | from application repository) | | -+--------------------+-------------------+------------------------------------------------------+-------------------------+ ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ +| Define | Type | Field(s) | Example | ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ +| APPVERSION | Numerical | ``VERSION_MAJOR`` (left shifted by 24 bits), |br| | 0x1020304 | +| | | ``VERSION_MINOR`` (left shifted by 16 bits), |br| | | +| | | ``PATCHLEVEL`` (left shifted by 8 bits), |br| | | +| | | ``VERSION_TWEAK`` | | ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ +| APP_VERSION_NUMBER | Numerical | ``VERSION_MAJOR`` (left shifted by 16 bits), |br| | 0x10203 | +| | | ``VERSION_MINOR`` (left shifted by 8 bits), |br| | | +| | | ``PATCHLEVEL`` | | ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ +| APP_VERSION_MAJOR | Numerical | ``VERSION_MAJOR`` | 1 | ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ +| APP_VERSION_MINOR | Numerical | ``VERSION_MINOR`` | 2 | ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ +| APP_PATCHLEVEL | Numerical | ``PATCHLEVEL`` | 3 | ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ +| APP_VERSION_TWEAK | Numerical | ``VERSION_TWEAK`` | 4 | ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ +| APP_VERSION_STRING | String (quoted) | ``VERSION_MAJOR``, |br| | "1.2.3-unstable" | +| | | ``VERSION_MINOR``, |br| | | +| | | ``PATCHLEVEL``, |br| | | +| | | ``EXTRAVERSION`` |br| | | ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ +| APP_VERSION_EXTENDED_STRING | String (quoted) | ``VERSION_MAJOR``, |br| | "1.2.3-unstable+4" | +| | | ``VERSION_MINOR``, |br| | | +| | | ``PATCHLEVEL``, |br| | | +| | | ``EXTRAVERSION`` |br| | | +| | | ``VERSION_TWEAK`` |br| | | ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ +| APP_VERSION_TWEAK_STRING | String (quoted) | ``VERSION_MAJOR``, |br| | "1.2.3+4" | +| | | ``VERSION_MINOR``, |br| | | +| | | ``PATCHLEVEL``, |br| | | +| | | ``VERSION_TWEAK`` |br| | | ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ +| APP_BUILD_VERSION | String (unquoted) | None (value of ``git describe --abbrev=12 --always`` | v3.3.0-18-g2c85d9224fca | +| | | from application repository) | | ++-----------------------------+-------------------+------------------------------------------------------+-------------------------+ Use in Kconfig ============== The following variables are available for usage in Kconfig files: -+------------------+-----------+-------------------------+----------------+ -| Variable | Type | Field(s) | Example | -+------------------+-----------+-------------------------+----------------+ -| $(VERSION_MAJOR) | Numerical | ``VERSION_MAJOR`` | 1 | -+------------------+-----------+-------------------------+----------------+ -| $(VERSION_MINOR) | Numerical | ``VERSION_MINOR`` | 2 | -+------------------+-----------+-------------------------+----------------+ -| $(PATCHLEVEL) | Numerical | ``PATCHLEVEL`` | 3 | -+------------------+-----------+-------------------------+----------------+ -| $(VERSION_TWEAK) | Numerical | ``VERSION_TWEAK`` | 4 | -+------------------+-----------+-------------------------+----------------+ -| $(APPVERSION) | String | ``VERSION_MAJOR``, |br| | 1.2.3-unstable | -| | | ``VERSION_MINOR``, |br| | | -| | | ``PATCHLEVEL``, |br| | | -| | | ``EXTRAVERSION`` | | -+------------------+-----------+-------------------------+----------------+ ++--------------------------------+-----------+--------------------------+------------------+ +| Variable | Type | Field(s) | Example | ++--------------------------------+-----------+--------------------------+------------------+ +| $(VERSION_MAJOR) | Numerical | ``VERSION_MAJOR`` | 1 | ++--------------------------------+-----------+--------------------------+------------------+ +| $(VERSION_MINOR) | Numerical | ``VERSION_MINOR`` | 2 | ++--------------------------------+-----------+--------------------------+------------------+ +| $(PATCHLEVEL) | Numerical | ``PATCHLEVEL`` | 3 | ++--------------------------------+-----------+--------------------------+------------------+ +| $(VERSION_TWEAK) | Numerical | ``VERSION_TWEAK`` | 4 | ++--------------------------------+-----------+--------------------------+------------------+ +| $(APPVERSION) | String | ``VERSION_MAJOR``, |br| | 1.2.3-unstable | +| | | ``VERSION_MINOR``, |br| | | +| | | ``PATCHLEVEL``, |br| | | +| | | ``EXTRAVERSION`` | | ++--------------------------------+-----------+--------------------------+------------------+ +| $(APP_VERSION_EXTENDED_STRING) | String | ``VERSION_MAJOR``, |br| | 1.2.3-unstable+4 | +| | | ``VERSION_MINOR``, |br| | | +| | | ``PATCHLEVEL``, |br| | | +| | | ``EXTRAVERSION``, |br| | | +| | | ``VERSION_TWEAK`` | | ++--------------------------------+-----------+--------------------------+------------------+ +| $(APP_VERSION_TWEAK_STRING) | String | ``VERSION_MAJOR``, |br| | 1.2.3+4 | +| | | ``VERSION_MINOR``, |br| | | +| | | ``PATCHLEVEL``, |br| | | +| | | ``VERSION_TWEAK`` | | ++--------------------------------+-----------+--------------------------+------------------+ Use in CMake ============ The following variable are available for usage in CMake files: -+--------------------+-----------------+---------------------------------------------------+----------------+ -| Variable | Type | Field(s) | Example | -+--------------------+-----------------+---------------------------------------------------+----------------+ -| APPVERSION | Numerical (hex) | ``VERSION_MAJOR`` (left shifted by 24 bits), |br| | 0x1020304 | -| | | ``VERSION_MINOR`` (left shifted by 16 bits), |br| | | -| | | ``PATCHLEVEL`` (left shifted by 8 bits), |br| | | -| | | ``VERSION_TWEAK`` | | -+--------------------+-----------------+---------------------------------------------------+----------------+ -| APP_VERSION_NUMBER | Numerical (hex) | ``VERSION_MAJOR`` (left shifted by 16 bits), |br| | 0x10203 | -| | | ``VERSION_MINOR`` (left shifted by 8 bits), |br| | | -| | | ``PATCHLEVEL`` | | -+--------------------+-----------------+---------------------------------------------------+----------------+ -| APP_VERSION_MAJOR | Numerical | ``VERSION_MAJOR`` | 1 | -+--------------------+-----------------+---------------------------------------------------+----------------+ -| APP_VERSION_MINOR | Numerical | ``VERSION_MINOR`` | 2 | -+--------------------+-----------------+---------------------------------------------------+----------------+ -| APP_PATCHLEVEL | Numerical | ``PATCHLEVEL`` | 3 | -+--------------------+-----------------+---------------------------------------------------+----------------+ -| APP_VERSION_TWEAK | Numerical | ``VERSION_TWEAK`` | 4 | -+--------------------+-----------------+---------------------------------------------------+----------------+ -| APP_VERSION_STRING | String | ``VERSION_MAJOR``, |br| | 1.2.3-unstable | -| | | ``VERSION_MINOR``, |br| | | -| | | ``PATCHLEVEL``, |br| | | -| | | ``EXTRAVERSION`` | | -+--------------------+-----------------+---------------------------------------------------+----------------+ ++-----------------------------+-----------------+---------------------------------------------------+------------------+ +| Variable | Type | Field(s) | Example | ++-----------------------------+-----------------+---------------------------------------------------+------------------+ +| APPVERSION | Numerical (hex) | ``VERSION_MAJOR`` (left shifted by 24 bits), |br| | 0x1020304 | +| | | ``VERSION_MINOR`` (left shifted by 16 bits), |br| | | +| | | ``PATCHLEVEL`` (left shifted by 8 bits), |br| | | +| | | ``VERSION_TWEAK`` | | ++-----------------------------+-----------------+---------------------------------------------------+------------------+ +| APP_VERSION_NUMBER | Numerical (hex) | ``VERSION_MAJOR`` (left shifted by 16 bits), |br| | 0x10203 | +| | | ``VERSION_MINOR`` (left shifted by 8 bits), |br| | | +| | | ``PATCHLEVEL`` | | ++-----------------------------+-----------------+---------------------------------------------------+------------------+ +| APP_VERSION_MAJOR | Numerical | ``VERSION_MAJOR`` | 1 | ++-----------------------------+-----------------+---------------------------------------------------+------------------+ +| APP_VERSION_MINOR | Numerical | ``VERSION_MINOR`` | 2 | ++-----------------------------+-----------------+---------------------------------------------------+------------------+ +| APP_PATCHLEVEL | Numerical | ``PATCHLEVEL`` | 3 | ++-----------------------------+-----------------+---------------------------------------------------+------------------+ +| APP_VERSION_TWEAK | Numerical | ``VERSION_TWEAK`` | 4 | ++-----------------------------+-----------------+---------------------------------------------------+------------------+ +| APP_VERSION_STRING | String | ``VERSION_MAJOR``, |br| | 1.2.3-unstable | +| | | ``VERSION_MINOR``, |br| | | +| | | ``PATCHLEVEL``, |br| | | +| | | ``EXTRAVERSION`` | | ++-----------------------------+-----------------+---------------------------------------------------+------------------+ +| APP_VERSION_EXTENDED_STRING | String | ``VERSION_MAJOR``, |br| | 1.2.3-unstable+4 | +| | | ``VERSION_MINOR``, |br| | | +| | | ``PATCHLEVEL``, |br| | | +| | | ``EXTRAVERSION``, |br| | | +| | | ``VERSION_TWEAK`` | | ++-----------------------------+-----------------+---------------------------------------------------+------------------+ +| APP_VERSION_TWEAK_STRING | String | ``VERSION_MAJOR``, |br| | 1.2.3+4 | +| | | ``VERSION_MINOR``, |br| | | +| | | ``PATCHLEVEL``, |br| | | +| | | ``VERSION_TWEAK`` | | ++-----------------------------+-----------------+---------------------------------------------------+------------------+ Use in MCUboot-supported applications ===================================== @@ -161,6 +194,3 @@ Use in MCUboot-supported applications No additional configuration needs to be done to the target application so long as it is configured to support MCUboot and a signed image is generated, the version information will be automatically included in the image data. - -The format used for signing is ``VERSION_MAJOR`` . ``VERSION_MINOR`` . ``PATCHLEVEL``, the tweak -version field is not currently used. diff --git a/version.h.in b/version.h.in index 476d97eabbb..bfb2eb3edb7 100644 --- a/version.h.in +++ b/version.h.in @@ -9,13 +9,15 @@ #cmakedefine ZEPHYR_VERSION_CODE @ZEPHYR_VERSION_CODE@ #cmakedefine ZEPHYR_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) -#define @VERSION_TYPE@VERSION @@VERSION_TYPE@VERSION@ -#define @VERSION_TYPE@_VERSION_NUMBER @@VERSION_TYPE@_VERSION_NUMBER@ -#define @VERSION_TYPE@_VERSION_MAJOR @@VERSION_TYPE@_VERSION_MAJOR@ -#define @VERSION_TYPE@_VERSION_MINOR @@VERSION_TYPE@_VERSION_MINOR@ -#define @VERSION_TYPE@_PATCHLEVEL @@VERSION_TYPE@_PATCHLEVEL@ -#define @VERSION_TYPE@_TWEAK @@VERSION_TYPE@_VERSION_TWEAK@ -#define @VERSION_TYPE@_VERSION_STRING "@@VERSION_TYPE@_VERSION_STRING@" +#define @VERSION_TYPE@VERSION @@VERSION_TYPE@VERSION@ +#define @VERSION_TYPE@_VERSION_NUMBER @@VERSION_TYPE@_VERSION_NUMBER@ +#define @VERSION_TYPE@_VERSION_MAJOR @@VERSION_TYPE@_VERSION_MAJOR@ +#define @VERSION_TYPE@_VERSION_MINOR @@VERSION_TYPE@_VERSION_MINOR@ +#define @VERSION_TYPE@_PATCHLEVEL @@VERSION_TYPE@_PATCHLEVEL@ +#define @VERSION_TYPE@_TWEAK @@VERSION_TYPE@_VERSION_TWEAK@ +#define @VERSION_TYPE@_VERSION_STRING "@@VERSION_TYPE@_VERSION_STRING@" +#define @VERSION_TYPE@_VERSION_EXTENDED_STRING "@@VERSION_TYPE@_VERSION_EXTENDED_STRING@" +#define @VERSION_TYPE@_VERSION_TWEAK_STRING "@@VERSION_TYPE@_VERSION_TWEAK_STRING@" #define @BUILD_VERSION_NAME@ @@BUILD_VERSION_NAME@@ @@VERSION_TYPE@_VERSION_CUSTOMIZATION@ From f3f276dd2ecad981a2abf1d87c3d3d0b2e9d5373 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 1 Feb 2024 08:24:59 +0000 Subject: [PATCH 1510/1623] [nrf fromtree] mcuboot: Use tweak version string Replaces the default with a shorter variable of equal value Signed-off-by: Jamie McCrae (cherry picked from commit 835d78ec59e185705238acc46cfaaefaa1ea7024) --- modules/Kconfig.mcuboot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Kconfig.mcuboot b/modules/Kconfig.mcuboot index 8df4bde8829..4849b456f22 100644 --- a/modules/Kconfig.mcuboot +++ b/modules/Kconfig.mcuboot @@ -103,7 +103,7 @@ config MCUBOOT_ENCRYPTION_KEY_FILE config MCUBOOT_IMGTOOL_SIGN_VERSION string "Version to pass to imgtool when signing" - default "$(VERSION_MAJOR).$(VERSION_MINOR).$(PATCHLEVEL)+$(VERSION_TWEAK)" if "$(VERSION_MAJOR)" != "" + default "$(APP_VERSION_TWEAK_STRING)" if "$(VERSION_MAJOR)" != "" default "0.0.0+0" help When signing with imgtool then this setting will be passed as version From fa9c0f3f38643f716bc708a0dbe629daae5ee99e Mon Sep 17 00:00:00 2001 From: Georgios Vasilakis Date: Tue, 20 Feb 2024 13:27:08 +0100 Subject: [PATCH 1511/1623] [nrf fromlist] dts: Add uicr nfct_pins_as_gpios prop on 5340_ns Add a uicr node for the NRF5340 non-secure target. The UICR is mapped as secure only so the non-secure app doesn't have access to it but we still want to configure the nfct_pins_as_gpios property the same way for both secure and non-secure targets. The uicr option in the non-secure target doesn't have the register property since it is not usable. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69337 Ref: NCSDK-24437 Signed-off-by: Georgios Vasilakis --- dts/arm/nordic/nrf5340_cpuappns.dtsi | 5 +++++ .../arm/nordic,nrf-uicr-config-only.yaml | 17 +++++++++++++++++ soc/arm/nordic_nrf/validate_base_addresses.c | 5 ++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 dts/bindings/arm/nordic,nrf-uicr-config-only.yaml diff --git a/dts/arm/nordic/nrf5340_cpuappns.dtsi b/dts/arm/nordic/nrf5340_cpuappns.dtsi index 6df1be54b34..232c80d7119 100644 --- a/dts/arm/nordic/nrf5340_cpuappns.dtsi +++ b/dts/arm/nordic/nrf5340_cpuappns.dtsi @@ -72,6 +72,11 @@ compatible = "zephyr,psa-crypto-rng"; status = "okay"; }; + + uicr: uicr { + compatible = "nordic,nrf-uicr-config-only"; + status = "okay"; + }; }; &nvic { diff --git a/dts/bindings/arm/nordic,nrf-uicr-config-only.yaml b/dts/bindings/arm/nordic,nrf-uicr-config-only.yaml new file mode 100644 index 00000000000..20f7370e445 --- /dev/null +++ b/dts/bindings/arm/nordic,nrf-uicr-config-only.yaml @@ -0,0 +1,17 @@ +description: Nordic UICR (User Information Configuration Registers) for configuration purposes only + +compatible: "nordic,nrf-uicr-config-only" + +include: base.yaml + +properties: + nfct-pins-as-gpios: + type: boolean + description: | + When enabled this property will configure pins dedicated to NFCT + peripheral as regular GPIOs. + + NFC pins in nRF5340: P0.02 and P0.03 + + This setting, once applied, can only be unset by erasing the UICR + registers. Refer to the reference manual for more details. diff --git a/soc/arm/nordic_nrf/validate_base_addresses.c b/soc/arm/nordic_nrf/validate_base_addresses.c index 28ec231b132..cf22fe95ae9 100644 --- a/soc/arm/nordic_nrf/validate_base_addresses.c +++ b/soc/arm/nordic_nrf/validate_base_addresses.c @@ -223,7 +223,6 @@ CHECK_DT_REG(uart134, NRF_UARTE134); CHECK_DT_REG(uart135, NRF_UARTE135); CHECK_DT_REG(uart136, NRF_UARTE136); CHECK_DT_REG(uart137, NRF_UARTE137); -CHECK_DT_REG(uicr, NRF_UICR); CHECK_DT_REG(usbd, NRF_USBD); CHECK_DT_REG(usbreg, NRF_USBREGULATOR); CHECK_DT_REG(vmc, NRF_VMC); @@ -233,6 +232,10 @@ CHECK_DT_REG(wdt1, NRF_WDT1); CHECK_DT_REG(wdt30, NRF_WDT30); CHECK_DT_REG(wdt31, NRF_WDT31); +#if defined(NRF_UICR) +CHECK_DT_REG(uicr, NRF_UICR); +#endif + /* nRF51/nRF52-specific addresses */ #if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) CHECK_DT_REG(gpregret1, NRF_POWER_GPREGRET1); From e88d540cfc964c156a56cf2d074a415f0376a22d Mon Sep 17 00:00:00 2001 From: Kyra Lengfeld Date: Thu, 20 Jul 2023 10:29:53 +0200 Subject: [PATCH 1512/1623] [nrf fromtree] Bluetooth: Controller: Add nRF54x Tx Power Kconfig This commit adds tx power config options for nRF54Hx and nrf54Lx SoCs, as well as the new radio defines. Signed-off-by: Kyra Lengfeld (cherry picked from commit 83926830cf89fc57f53e1fe3d1b7bb53beaa557e) Signed-off-by: Kyra Lengfeld --- subsys/bluetooth/controller/Kconfig | 72 ++++++++++++++----- .../nordic/hal/nrf5/radio/radio_nrf5_txp.h | 18 ++++- 2 files changed, 73 insertions(+), 17 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 91f4f08c15c..a7b2c1a74f1 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -256,92 +256,126 @@ choice BT_CTLR_TX_PWR The value set here represents the actual default power level fed to the antenna. +config BT_CTLR_TX_PWR_PLUS_10 + bool "+10 dBm" + depends on SOC_SERIES_NRF54HX + +config BT_CTLR_TX_PWR_PLUS_9 + bool "+9 dBm" + depends on SOC_SERIES_NRF54HX + config BT_CTLR_TX_PWR_PLUS_8 bool "+8 dBm" - depends on HAS_HW_NRF_RADIO_TX_PWR_HIGH + depends on HAS_HW_NRF_RADIO_TX_PWR_HIGH || SOC_SERIES_NRF54HX || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_PLUS_7 bool "+7 dBm" - depends on HAS_HW_NRF_RADIO_TX_PWR_HIGH + depends on HAS_HW_NRF_RADIO_TX_PWR_HIGH || SOC_SERIES_NRF54HX || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_PLUS_6 bool "+6 dBm" - depends on HAS_HW_NRF_RADIO_TX_PWR_HIGH + depends on HAS_HW_NRF_RADIO_TX_PWR_HIGH || SOC_SERIES_NRF54HX || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_PLUS_5 bool "+5 dBm" - depends on HAS_HW_NRF_RADIO_TX_PWR_HIGH + depends on HAS_HW_NRF_RADIO_TX_PWR_HIGH || SOC_SERIES_NRF54HX || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_PLUS_4 bool "+4 dBm" - depends on SOC_SERIES_NRF51X || SOC_COMPATIBLE_NRF52X + depends on SOC_SERIES_NRF51X || SOC_COMPATIBLE_NRF52X || SOC_SERIES_NRF54HX || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_PLUS_3 bool "+3 dBm" - depends on SOC_COMPATIBLE_NRF52X || SOC_SERIES_NRF53X + depends on SOC_COMPATIBLE_NRF52X || SOC_SERIES_NRF53X || SOC_SERIES_NRF54HX || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_PLUS_2 bool "+2 dBm" - depends on HAS_HW_NRF_RADIO_TX_PWR_HIGH || SOC_SERIES_NRF53X + depends on HAS_HW_NRF_RADIO_TX_PWR_HIGH || SOC_SERIES_NRF53X || SOC_SERIES_NRF54HX || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_PLUS_1 bool "+1 dBm" - depends on SOC_SERIES_NRF53X + depends on SOC_SERIES_NRF53X || SOC_SERIES_NRF54HX || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_0 bool "0 dBm" config BT_CTLR_TX_PWR_MINUS_1 bool "-1 dBm" - depends on SOC_SERIES_NRF53X + depends on SOC_SERIES_NRF53X || SOC_SERIES_NRF54HX || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_MINUS_2 bool "-2 dBm" - depends on SOC_SERIES_NRF53X + depends on SOC_SERIES_NRF53X || SOC_SERIES_NRF54HX || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_MINUS_3 bool "-3 dBm" - depends on SOC_SERIES_NRF53X + depends on SOC_SERIES_NRF53X || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_MINUS_4 bool "-4 dBm" config BT_CTLR_TX_PWR_MINUS_5 bool "-5 dBm" - depends on SOC_SERIES_NRF53X + depends on SOC_SERIES_NRF53X || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_MINUS_6 bool "-6 dBm" - depends on SOC_SERIES_NRF53X + depends on SOC_SERIES_NRF53X || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_MINUS_7 bool "-7 dBm" - depends on SOC_SERIES_NRF53X + depends on SOC_SERIES_NRF53X || SOC_SERIES_NRF54LX config BT_CTLR_TX_PWR_MINUS_8 bool "-8 dBm" +config BT_CTLR_TX_PWR_MINUS_9 + bool "-9 dBm" + depends on SOC_SERIES_NRF54LX + +config BT_CTLR_TX_PWR_MINUS_10 + bool "-10 dBm" + depends on SOC_SERIES_NRF54LX + config BT_CTLR_TX_PWR_MINUS_12 bool "-12 dBm" +config BT_CTLR_TX_PWR_MINUS_14 + bool "-14 dBm" + depends on SOC_SERIES_NRF54LX + config BT_CTLR_TX_PWR_MINUS_16 bool "-16 dBm" config BT_CTLR_TX_PWR_MINUS_20 bool "-20 dBm" +config BT_CTLR_TX_PWR_MINUS_26 + bool "-26 dBm" + depends on SOC_SERIES_NRF54LX + config BT_CTLR_TX_PWR_MINUS_30 bool "-30 dBm" - depends on SOC_SERIES_NRF51X + depends on SOC_SERIES_NRF51X || SOC_SERIES_NRF54HX config BT_CTLR_TX_PWR_MINUS_40 bool "-40 dBm" - depends on SOC_COMPATIBLE_NRF52X || SOC_SERIES_NRF53X + depends on SOC_COMPATIBLE_NRF52X || SOC_SERIES_NRF53X || SOC_SERIES_NRF54HX || SOC_SERIES_NRF54LX + +config BT_CTLR_TX_PWR_MINUS_46 + bool "-46 dBm" + depends on SOC_SERIES_NRF54LX + +config BT_CTLR_TX_PWR_MINUS_70 + bool "-70 dBm" + depends on SOC_SERIES_NRF54HX endchoice config BT_CTLR_TX_PWR_DBM int + default 10 if BT_CTLR_TX_PWR_PLUS_10 + default 9 if BT_CTLR_TX_PWR_PLUS_9 default 8 if BT_CTLR_TX_PWR_PLUS_8 default 7 if BT_CTLR_TX_PWR_PLUS_7 default 6 if BT_CTLR_TX_PWR_PLUS_6 @@ -359,11 +393,17 @@ config BT_CTLR_TX_PWR_DBM default -6 if BT_CTLR_TX_PWR_MINUS_6 default -7 if BT_CTLR_TX_PWR_MINUS_7 default -8 if BT_CTLR_TX_PWR_MINUS_8 + default -9 if BT_CTLR_TX_PWR_MINUS_9 + default -10 if BT_CTLR_TX_PWR_MINUS_10 default -12 if BT_CTLR_TX_PWR_MINUS_12 + default -14 if BT_CTLR_TX_PWR_MINUS_14 default -16 if BT_CTLR_TX_PWR_MINUS_16 default -20 if BT_CTLR_TX_PWR_MINUS_20 + default -26 if BT_CTLR_TX_PWR_MINUS_26 default -30 if BT_CTLR_TX_PWR_MINUS_30 default -40 if BT_CTLR_TX_PWR_MINUS_40 + default -46 if BT_CTLR_TX_PWR_MINUS_46 + default -70 if BT_CTLR_TX_PWR_MINUS_70 config BT_CTLR_TX_PWR_ANTENNA int "Set TX power (dBm)" diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_txp.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_txp.h index 2eb772f20cc..c3bb09fd1b3 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_txp.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_txp.h @@ -4,7 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -#if defined(CONFIG_BT_CTLR_TX_PWR_PLUS_8) +#if defined(CONFIG_BT_CTLR_TX_PWR_PLUS_10) +#define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Pos10dBm +#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_9) +#define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Pos9dBm +#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_8) #define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Pos8dBm #elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_7) #define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Pos7dBm @@ -38,14 +42,26 @@ #define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg7dBm #elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_8) #define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg8dBm +#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_9) +#define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg9dBm +#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_10) +#define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg10dBm #elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_12) #define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg12dBm +#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_14) +#define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg14dBm #elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_16) #define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg16dBm #elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_20) #define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg20dBm +#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_26) +#define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg26dBm #elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_30) #define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg30dBm #elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_40) #define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg40dBm +#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_46) +#define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg46dBm +#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_70) +#define RADIO_TXP_DEFAULT RADIO_TXPOWER_TXPOWER_Neg70dBm #endif From ae7b70acfa48e748d7d76fd07a439f0cf4907a35 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Tue, 27 Feb 2024 10:11:14 +0000 Subject: [PATCH 1513/1623] Revert "[nrf fromlist] dts: Add uicr nfct_pins_as_gpios prop on 5340_ns" This reverts commit fa9c0f3f38643f716bc708a0dbe629daae5ee99e. Signed-off-by: Jamie McCrae --- dts/arm/nordic/nrf5340_cpuappns.dtsi | 5 ----- .../arm/nordic,nrf-uicr-config-only.yaml | 17 ----------------- soc/arm/nordic_nrf/validate_base_addresses.c | 5 +---- 3 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 dts/bindings/arm/nordic,nrf-uicr-config-only.yaml diff --git a/dts/arm/nordic/nrf5340_cpuappns.dtsi b/dts/arm/nordic/nrf5340_cpuappns.dtsi index 232c80d7119..6df1be54b34 100644 --- a/dts/arm/nordic/nrf5340_cpuappns.dtsi +++ b/dts/arm/nordic/nrf5340_cpuappns.dtsi @@ -72,11 +72,6 @@ compatible = "zephyr,psa-crypto-rng"; status = "okay"; }; - - uicr: uicr { - compatible = "nordic,nrf-uicr-config-only"; - status = "okay"; - }; }; &nvic { diff --git a/dts/bindings/arm/nordic,nrf-uicr-config-only.yaml b/dts/bindings/arm/nordic,nrf-uicr-config-only.yaml deleted file mode 100644 index 20f7370e445..00000000000 --- a/dts/bindings/arm/nordic,nrf-uicr-config-only.yaml +++ /dev/null @@ -1,17 +0,0 @@ -description: Nordic UICR (User Information Configuration Registers) for configuration purposes only - -compatible: "nordic,nrf-uicr-config-only" - -include: base.yaml - -properties: - nfct-pins-as-gpios: - type: boolean - description: | - When enabled this property will configure pins dedicated to NFCT - peripheral as regular GPIOs. - - NFC pins in nRF5340: P0.02 and P0.03 - - This setting, once applied, can only be unset by erasing the UICR - registers. Refer to the reference manual for more details. diff --git a/soc/arm/nordic_nrf/validate_base_addresses.c b/soc/arm/nordic_nrf/validate_base_addresses.c index cf22fe95ae9..28ec231b132 100644 --- a/soc/arm/nordic_nrf/validate_base_addresses.c +++ b/soc/arm/nordic_nrf/validate_base_addresses.c @@ -223,6 +223,7 @@ CHECK_DT_REG(uart134, NRF_UARTE134); CHECK_DT_REG(uart135, NRF_UARTE135); CHECK_DT_REG(uart136, NRF_UARTE136); CHECK_DT_REG(uart137, NRF_UARTE137); +CHECK_DT_REG(uicr, NRF_UICR); CHECK_DT_REG(usbd, NRF_USBD); CHECK_DT_REG(usbreg, NRF_USBREGULATOR); CHECK_DT_REG(vmc, NRF_VMC); @@ -232,10 +233,6 @@ CHECK_DT_REG(wdt1, NRF_WDT1); CHECK_DT_REG(wdt30, NRF_WDT30); CHECK_DT_REG(wdt31, NRF_WDT31); -#if defined(NRF_UICR) -CHECK_DT_REG(uicr, NRF_UICR); -#endif - /* nRF51/nRF52-specific addresses */ #if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) CHECK_DT_REG(gpregret1, NRF_POWER_GPREGRET1); From c5acff5307b657be641a67fe7c3a6a0a35fdf457 Mon Sep 17 00:00:00 2001 From: Bernt Johan Damslora Date: Thu, 22 Feb 2024 13:04:37 +0100 Subject: [PATCH 1514/1623] [nrf fromtree] drivers: mfd: npm6001: set SWREADY Sets SWREADY in MFD initialization, so that hysteresis mode can be used. Signed-off-by: Bernt Johan Damslora (cherry picked from commit 73d56dea6603bf54d2c989da0b57b1de4d907946) --- drivers/mfd/mfd_npm6001.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/mfd/mfd_npm6001.c b/drivers/mfd/mfd_npm6001.c index 1a077791816..b03b10b4cba 100644 --- a/drivers/mfd/mfd_npm6001.c +++ b/drivers/mfd/mfd_npm6001.c @@ -11,6 +11,7 @@ #include /* nPM6001 registers */ +#define NPM6001_SWREADY 0x01U #define NPM6001_BUCK3SELDAC 0x44U #define NPM6001_BUCKMODEPADCONF 0x4EU #define NPM6001_PADDRIVESTRENGTH 0x53U @@ -60,6 +61,12 @@ static int mfd_npm6001_init(const struct device *dev) return ret; } + /* Enable switching to hysteresis mode */ + ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_SWREADY, 1U); + if (ret < 0) { + return ret; + } + return 0; } From 22f769089b5b1ae03ef0688deaf1637bca47e6ae Mon Sep 17 00:00:00 2001 From: Emanuele Di Santo Date: Fri, 16 Feb 2024 13:22:43 +0100 Subject: [PATCH 1515/1623] [nrf noup] include: net: add NCS extensions fixup! [nrf noup] include: net: add NCS extensions Add SO_KEEPOPEN socket option. Add SO_RAI socket option, deprecate the old ones. Signed-off-by: Emanuele Di Santo --- include/zephyr/net/socket_ncs.h | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/include/zephyr/net/socket_ncs.h b/include/zephyr/net/socket_ncs.h index a80e1ddc238..0023cd9bd48 100644 --- a/include/zephyr/net/socket_ncs.h +++ b/include/zephyr/net/socket_ncs.h @@ -71,32 +71,86 @@ extern "C" { /** sockopt: enable sending data as part of exceptional events */ #define SO_EXCEPTIONAL_DATA 33 +/** sockopt: Keep socket open when its PDN connection is lost + * or the device is put into flight mode. + */ +#define SO_KEEPOPEN 34 /** sockopt: bind to PDN */ #define SO_BINDTOPDN 40 /** sockopt: Release Assistance Indication feature: This will indicate that the * application will not send any more data. + * + * @note This socket option requires the socket to be connected. + * + * @deprecated use @ref SO_RAI with value @ref RAI_NO_DATA instead. */ #define SO_RAI_NO_DATA 50 /** sockopt: Release Assistance Indication feature: This will indicate that the * next call to send/sendto will be the last one for some time. + * + * @deprecated use @ref SO_RAI with value @ref RAI_LAST instead. */ #define SO_RAI_LAST 51 /** sockopt: Release Assistance Indication feature: This will indicate that * after the next call to send/sendto, the application is expecting to receive * one more data packet before this socket will not be used again for some time. + * + * @deprecated use @ref SO_RAI with value @ref RAI_ONE_RESP instead. */ #define SO_RAI_ONE_RESP 52 /** sockopt: Release Assistance Indication feature: If a client application * expects to use the socket more it can indicate that by setting this socket * option before the next send call which will keep the network up longer. + * + * @deprecated use @ref SO_RAI with value @ref RAI_ONGOING instead. */ #define SO_RAI_ONGOING 53 /** sockopt: Release Assistance Indication feature: If a server application * expects to use the socket more it can indicate that by setting this socket * option before the next send call. + * + * @deprecated use @ref SO_RAI with value @ref RAI_WAIT_MORE instead. */ #define SO_RAI_WAIT_MORE 54 +/** sockopt: Release assistance indication (RAI). + * The option accepts an integer, indicating the type of RAI. + * Accepted values for the option are: @ref RAI_NO_DATA, @ref RAI_LAST, @ref RAI_ONE_RESP, + * @ref RAI_ONGOING, @ref RAI_WAIT_MORE. + */ +#define SO_RAI 61 + +/** Release assistance indication (RAI). + * Indicate that the application does not intend to send more data. + * This applies immediately and lets the modem exit connected mode more + * quickly. + * + * @note This requires the socket to be connected. + */ +#define RAI_NO_DATA 1 +/** Release assistance indication (RAI). + * Indicate that the application does not intend to send more data + * after the next call to send() or sendto(). + * This lets the modem exit connected mode more quickly after sending the data. + */ +#define RAI_LAST 2 +/** Release assistance indication (RAI). + * Indicate that the application is expecting to receive just one data packet + * after the next call to send() or sendto(). + * This lets the modem exit connected mode more quickly after having received the data. + */ +#define RAI_ONE_RESP 3 +/** Release assistance indication (RAI). + * Indicate that the socket is in active use by a client application. + * This lets the modem stay in connected mode longer. + */ +#define RAI_ONGOING 4 +/** Release assistance indication (RAI). + * Indicate that the socket is in active use by a server application. + * This lets the modem stay in connected mode longer. + */ +#define RAI_WAIT_MORE 5 + /* NCS specific IPPROTO_ALL level socket options */ /** IPv4 and IPv6 protocol level (pseudo-val) for nRF sockets. */ From 0644eb74774ea26ec7e96a2ef73003af9b3900a2 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Wed, 10 Jan 2024 12:23:11 +0100 Subject: [PATCH 1516/1623] [nrf fromtree] arch: isr_tables: Add __used attribute to int_list_header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds missing __used attribute it int_list_header, preventing it from being optimized out. Signed-off-by: Radosław Koppel (cherry picked from commit 717c5835d6df56f58e114fb9e4548d963332a87d) --- arch/common/isr_tables.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/common/isr_tables.c b/arch/common/isr_tables.c index 0311f81f252..9677c92683d 100644 --- a/arch/common/isr_tables.c +++ b/arch/common/isr_tables.c @@ -21,7 +21,7 @@ struct int_list_header { * header of the initList section, which is used by gen_isr_tables.py to create * the vector and sw isr tables, */ -Z_GENERIC_SECTION(.irq_info) struct int_list_header _iheader = { +Z_GENERIC_SECTION(.irq_info) __used struct int_list_header _iheader = { .table_size = IRQ_TABLE_SIZE, .offset = CONFIG_GEN_IRQ_START_VECTOR, }; From d7af1ded08730084eebb22e48e8ba35ca4ba7b71 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Wed, 6 Dec 2023 13:14:18 +0800 Subject: [PATCH 1517/1623] [nrf fromtree] scripts: build: gen_isr_tables: fix calculation of THIRD_LVL_INTERRUPTS The calculation of `THIRD_LVL_INTERRUPTS` bitmask in the `update_masks()` function is wrong, the number of bits to shift should be the sum of the first two levels. Signed-off-by: Yong Cong Sin (cherry picked from commit 56570cc8c164b524f3eded011c153fe49441974b) --- scripts/build/gen_isr_tables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build/gen_isr_tables.py b/scripts/build/gen_isr_tables.py index cd329f85551..314b56604ec 100755 --- a/scripts/build/gen_isr_tables.py +++ b/scripts/build/gen_isr_tables.py @@ -287,7 +287,7 @@ def update_masks(): FIRST_LVL_INTERRUPTS = bit_mask(INTERRUPT_BITS[0]) SECND_LVL_INTERRUPTS = bit_mask(INTERRUPT_BITS[1]) << INTERRUPT_BITS[0] - THIRD_LVL_INTERRUPTS = bit_mask(INTERRUPT_BITS[2]) << INTERRUPT_BITS[0] + INTERRUPT_BITS[2] + THIRD_LVL_INTERRUPTS = bit_mask(INTERRUPT_BITS[2]) << INTERRUPT_BITS[0] + INTERRUPT_BITS[1] def main(): parse_args() From 0328516feda62f61af7cde750738563f601b7a18 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Wed, 6 Dec 2023 13:17:55 +0800 Subject: [PATCH 1518/1623] [nrf fromtree] scripts: build: gen_isr_tables: change naming of bitmask variables Rename the bitmask variables from `*_LVL_INTERRUPTS` to `INTERRUPT_LVL_BITMASK[]` array to be consistent with `INTERRUPT_BITS`, making it easier to loop over the bitmasks. Signed-off-by: Yong Cong Sin (cherry picked from commit b4db285c1fde9dcd287c1f0b084b7c6eaa691bfe) --- scripts/build/gen_isr_tables.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/scripts/build/gen_isr_tables.py b/scripts/build/gen_isr_tables.py index 314b56604ec..ea14b0ebf52 100755 --- a/scripts/build/gen_isr_tables.py +++ b/scripts/build/gen_isr_tables.py @@ -23,9 +23,7 @@ # into 1 line which then goes into the 1st level) # 0x00FF0000 - represents the 3rd level (i.e. the interrupts funnel # into 1 line which then goes into the 2nd level) -FIRST_LVL_INTERRUPTS = 0x000000FF -SECND_LVL_INTERRUPTS = 0x0000FF00 -THIRD_LVL_INTERRUPTS = 0x00FF0000 +INTERRUPT_LVL_BITMASK = [0x000000FF, 0x0000FF00, 0x00FF0000] INTERRUPT_BITS = [8, 8, 8] @@ -278,16 +276,12 @@ def bit_mask(bits): return mask def update_masks(): - global FIRST_LVL_INTERRUPTS - global SECND_LVL_INTERRUPTS - global THIRD_LVL_INTERRUPTS - if sum(INTERRUPT_BITS) > 32: raise ValueError("Too many interrupt bits") - FIRST_LVL_INTERRUPTS = bit_mask(INTERRUPT_BITS[0]) - SECND_LVL_INTERRUPTS = bit_mask(INTERRUPT_BITS[1]) << INTERRUPT_BITS[0] - THIRD_LVL_INTERRUPTS = bit_mask(INTERRUPT_BITS[2]) << INTERRUPT_BITS[0] + INTERRUPT_BITS[1] + INTERRUPT_LVL_BITMASK[0] = bit_mask(INTERRUPT_BITS[0]) + INTERRUPT_LVL_BITMASK[1] = bit_mask(INTERRUPT_BITS[1]) << INTERRUPT_BITS[0] + INTERRUPT_LVL_BITMASK[2] = bit_mask(INTERRUPT_BITS[2]) << INTERRUPT_BITS[0] + INTERRUPT_BITS[1] def main(): parse_args() @@ -377,9 +371,9 @@ def main(): else: # Figure out third level interrupt position debug('IRQ = ' + hex(irq)) - irq3 = (irq & THIRD_LVL_INTERRUPTS) >> INTERRUPT_BITS[0] + INTERRUPT_BITS[1] - irq2 = (irq & SECND_LVL_INTERRUPTS) >> INTERRUPT_BITS[0] - irq1 = irq & FIRST_LVL_INTERRUPTS + irq3 = (irq & INTERRUPT_LVL_BITMASK[2]) >> INTERRUPT_BITS[0] + INTERRUPT_BITS[1] + irq2 = (irq & INTERRUPT_LVL_BITMASK[1]) >> INTERRUPT_BITS[0] + irq1 = irq & INTERRUPT_LVL_BITMASK[0] if irq3: irq_parent = irq2 From 2bb8cbddc56696fa0d0b68c9caccbe8021fd80c0 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Wed, 6 Dec 2023 13:21:33 +0800 Subject: [PATCH 1519/1623] [nrf fromtree] scripts: build: gen_isr_tables: add some debug prints Add some debug prints for the interrupts bits and bitmasks in each level. Signed-off-by: Yong Cong Sin (cherry picked from commit 0884a33ee3da3c20e6416039e0ec71927020f06a) --- scripts/build/gen_isr_tables.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/build/gen_isr_tables.py b/scripts/build/gen_isr_tables.py index ea14b0ebf52..13c9d79b0b3 100755 --- a/scripts/build/gen_isr_tables.py +++ b/scripts/build/gen_isr_tables.py @@ -283,6 +283,12 @@ def update_masks(): INTERRUPT_LVL_BITMASK[1] = bit_mask(INTERRUPT_BITS[1]) << INTERRUPT_BITS[0] INTERRUPT_LVL_BITMASK[2] = bit_mask(INTERRUPT_BITS[2]) << INTERRUPT_BITS[0] + INTERRUPT_BITS[1] + debug("Level Bits Bitmask") + debug("----------------------------") + for i in range(3): + bitmask_str = "0x" + format(INTERRUPT_LVL_BITMASK[i], '08X') + debug(f"{i + 1:>5} {INTERRUPT_BITS[i]:>7} {bitmask_str:>14}") + def main(): parse_args() From 1864665cd403eebc29a5f1efaf67f6ac54d2ed94 Mon Sep 17 00:00:00 2001 From: Greter Raffael Date: Tue, 14 Nov 2023 15:54:27 +0000 Subject: [PATCH 1520/1623] [nrf fromtree] gen_isr_tables: Add meaningful error message When using direct isrs, a vector table is needed. However, if none is present , i.e. `CONFIG_GEN_IRQ_VECTOR_TABLE=n`, this script failed. The given error message was not helpful (`'NoneType' has no len()`). This change makes it clearer, where to look for the problem. Signed-off-by: Greter Raffael (cherry picked from commit 7bcd0699e6c42217567d5297271fe3ca1b13aba7) --- scripts/build/gen_isr_tables.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/build/gen_isr_tables.py b/scripts/build/gen_isr_tables.py index 13c9d79b0b3..08ab9cc148c 100755 --- a/scripts/build/gen_isr_tables.py +++ b/scripts/build/gen_isr_tables.py @@ -358,6 +358,10 @@ def main(): for irq, flags, func, param in intlist["interrupts"]: if flags & ISR_FLAG_DIRECT: + if not vt: + error("Direct Interrupt %d declared with parameter 0x%x " + "but no vector table in use" + % (irq, param)) if param != 0: error("Direct irq %d declared, but has non-NULL parameter" % irq) From 46070a4423b549a36a90e26453322760c754474e Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Thu, 4 Jan 2024 00:56:37 +0800 Subject: [PATCH 1521/1623] [nrf fromtree] gen_isr_tables: print index number at the end of each entry as comment Make it easier to debug by printing the index number at the end, this is especially helpful when there's a lot of interrupts. Before: ```c /* build/zephyr/isr_tables.c */ {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, ``` After: ```c /* build/zephyr/isr_tables.c */ {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 0 */ {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 1 */ {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 2 */ {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 3 */ {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 4 */ {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 5 */ {(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 6 */ ``` Signed-off-by: Yong Cong Sin (cherry picked from commit 89fb8f8b9887aeb47f4503fd7a09e168928f9ee2) --- scripts/build/gen_isr_tables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build/gen_isr_tables.py b/scripts/build/gen_isr_tables.py index 08ab9cc148c..e257074e55b 100755 --- a/scripts/build/gen_isr_tables.py +++ b/scripts/build/gen_isr_tables.py @@ -250,7 +250,7 @@ def write_source_file(fp, vt, swt, intlist, syms, shared): fp.write("\t/* Level 3 interrupts start here (offset: {}) */\n". format(level3_offset)) - fp.write("\t{{(const void *){0}, (ISR){1}}},\n".format(param, func_as_string)) + fp.write("\t{{(const void *){0}, (ISR){1}}}, /* {2} */\n".format(param, func_as_string, i)) fp.write("};\n") def get_symbols(obj): From c6400ed6e895a0a7e821121493cb35825fb0f13f Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Mon, 30 Oct 2023 16:23:58 +0100 Subject: [PATCH 1522/1623] [nrf fromtree] scripts: gen_isr_tables: Code cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit cleans up the gen_isr_tables code for better clarity and easier modification. Changes include: - Separate functions to load intList section. - Replace spurious handlers in internal data with None. Now it is the output generator work to choose right function. - All the work to generate vt and swt separated into its own functions. - Remove the need for internal shared array - all the information is here in swt array. - The update_masks function - more functionality moved here. - Simplify bit_mask function. Signed-off-by: Radosław Koppel (cherry picked from commit 4360acb27ea2c28c7db555a6be02c0da74d8b6fd) --- scripts/build/gen_isr_tables.py | 364 ++++++++++++++++++-------------- 1 file changed, 207 insertions(+), 157 deletions(-) diff --git a/scripts/build/gen_isr_tables.py b/scripts/build/gen_isr_tables.py index e257074e55b..41fc20957a6 100755 --- a/scripts/build/gen_isr_tables.py +++ b/scripts/build/gen_isr_tables.py @@ -2,6 +2,7 @@ # # Copyright (c) 2017 Intel Corporation # Copyright (c) 2018 Foundries.io +# Copyright (c) 2023 Nordic Semiconductor NA # # SPDX-License-Identifier: Apache-2.0 # @@ -27,6 +28,13 @@ INTERRUPT_BITS = [8, 8, 8] +swt_spurious_handler = "((uintptr_t)&z_irq_spurious)" +swt_shared_handler = "((uintptr_t)&z_shared_isr)" +vt_spurious_handler = "z_irq_spurious" +vt_irq_handler = "_isr_wrapper" +vt_default_handler = None + + def debug(text): if args.debug: sys.stdout.write(os.path.basename(sys.argv[0]) + ": " + text + "\n") @@ -40,7 +48,7 @@ def endian_prefix(): else: return "<" -def read_intlist(elfobj, syms, snames): +def read_intlist(intlist_data, syms): """read a binary file containing the contents of the kernel's .intList section. This is an instance of a header created by include/zephyr/linker/intlist.ld: @@ -64,37 +72,25 @@ def read_intlist(elfobj, syms, snames): const void *param; }; """ - intList_sect = None intlist = {} - prefix = endian_prefix() + # Extract header and the rest of the data intlist_header_fmt = prefix + "II" + header_sz = struct.calcsize(intlist_header_fmt) + header_raw = struct.unpack_from(intlist_header_fmt, intlist_data, 0) + debug(str(header_raw)) + + intlist["num_vectors"] = header_raw[0] + intlist["offset"] = header_raw[1] + intdata = intlist_data[header_sz:] + + # Extract information about interrupts if "CONFIG_64BIT" in syms: intlist_entry_fmt = prefix + "iiQQ" else: intlist_entry_fmt = prefix + "iiII" - for sname in snames: - intList_sect = elfobj.get_section_by_name(sname) - if intList_sect is not None: - debug("Found intlist section: \"{}\"".format(sname)) - break - - if intList_sect is None: - error("Cannot find the intlist section!") - - intdata = intList_sect.data() - - header_sz = struct.calcsize(intlist_header_fmt) - header = struct.unpack_from(intlist_header_fmt, intdata, 0) - intdata = intdata[header_sz:] - - debug(str(header)) - - intlist["num_vectors"] = header[0] - intlist["offset"] = header[1] - intlist["interrupts"] = [i for i in struct.iter_unpack(intlist_entry_fmt, intdata)] @@ -108,32 +104,6 @@ def read_intlist(elfobj, syms, snames): return intlist - -def parse_args(): - global args - - parser = argparse.ArgumentParser(description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter, allow_abbrev=False) - - parser.add_argument("-e", "--big-endian", action="store_true", - help="Target encodes data in big-endian format (little endian is " - "the default)") - parser.add_argument("-d", "--debug", action="store_true", - help="Print additional debugging information") - parser.add_argument("-o", "--output-source", required=True, - help="Output source file") - parser.add_argument("-k", "--kernel", required=True, - help="Zephyr kernel image") - parser.add_argument("-s", "--sw-isr-table", action="store_true", - help="Generate SW ISR table") - parser.add_argument("-V", "--vector-table", action="store_true", - help="Generate vector table") - parser.add_argument("-i", "--intlist-section", action="append", required=True, - help="The name of the section to search for the interrupt data. " - "This is accumulative argument. The first section found would be used.") - - args = parser.parse_args() - source_assembly_header = """ #ifndef ARCH_IRQ_VECTOR_JUMP_CODE #error "ARCH_IRQ_VECTOR_JUMP_CODE not defined" @@ -153,6 +123,9 @@ def write_code_irq_vector_table(fp, vt, nv, syms): for i in range(nv): func = vt[i] + if func is None: + func = vt_default_handler + if isinstance(func, int): func_as_string = get_symbol_from_addr(syms, func) else: @@ -166,10 +139,13 @@ def write_address_irq_vector_table(fp, vt, nv): for i in range(nv): func = vt[i] + if func is None: + func = vt_default_handler + if isinstance(func, int): - fp.write("\t{},\n".format(vt[i])) + fp.write("\t{},\n".format(func)) else: - fp.write("\t((uintptr_t)&{}),\n".format(vt[i])) + fp.write("\t((uintptr_t)&{}),\n".format(func)) fp.write("};\n") @@ -184,15 +160,19 @@ def write_address_irq_vector_table(fp, vt, nv): typedef void (* ISR)(const void *); """ -def write_shared_table(fp, shared, nv): +def write_shared_table(fp, swt, nv): fp.write("struct z_shared_isr_table_entry __shared_sw_isr_table" " z_shared_sw_isr_table[%d] = {\n" % nv) for i in range(nv): - client_num = shared[i][1] - client_list = shared[i][0] + if swt[i] is None: + client_num = 0 + client_list = None + else: + client_num = len(swt[i]) + client_list = swt[i] - if not client_num: + if client_num <= 1: fp.write("\t{ },\n") else: fp.write(f"\t{{ .client_num = {client_num}, .clients = {{ ") @@ -207,13 +187,13 @@ def write_shared_table(fp, shared, nv): fp.write("};\n") -def write_source_file(fp, vt, swt, intlist, syms, shared): +def write_source_file(fp, vt, swt, intlist, syms): fp.write(source_header) nv = intlist["num_vectors"] if "CONFIG_SHARED_INTERRUPTS" in syms: - write_shared_table(fp, shared, nv) + write_shared_table(fp, swt, nv) if vt: if "CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS" in syms: @@ -233,11 +213,19 @@ def write_source_file(fp, vt, swt, intlist, syms, shared): level3_offset = syms.get("CONFIG_3RD_LVL_ISR_TBL_OFFSET") for i in range(nv): - param = "{0:#x}".format(swt[i][0]) - func = swt[i][1] - - if isinstance (func, str) and "z_shared_isr" in func: + if len(swt[i]) == 0: + # Not used interrupt + param = "0x0" + func = swt_spurious_handler + elif len(swt[i]) == 1: + # Single interrupt + param = "{0:#x}".format(swt[i][0][0]) + func = swt[i][0][1] + else: + # Shared interrupt param = "&z_shared_sw_isr_table[{0}]".format(i) + func = swt_shared_handler + if isinstance(func, int): func_as_string = "{0:#x}".format(func) else: @@ -253,14 +241,6 @@ def write_source_file(fp, vt, swt, intlist, syms, shared): fp.write("\t{{(const void *){0}, (ISR){1}}}, /* {2} */\n".format(param, func_as_string, i)) fp.write("};\n") -def get_symbols(obj): - for section in obj.iter_sections(): - if isinstance(section, SymbolTableSection): - return {sym.name: sym.entry.st_value - for sym in section.iter_symbols()} - - error("Could not find symbol table") - def getindex(irq, irq_aggregator_pos): try: return irq_aggregator_pos.index(irq) @@ -270,32 +250,9 @@ def getindex(irq, irq_aggregator_pos): " Recheck interrupt configuration.") def bit_mask(bits): - mask = 0 - for _ in range(0, bits): - mask = (mask << 1) | 1 - return mask - -def update_masks(): - if sum(INTERRUPT_BITS) > 32: - raise ValueError("Too many interrupt bits") - - INTERRUPT_LVL_BITMASK[0] = bit_mask(INTERRUPT_BITS[0]) - INTERRUPT_LVL_BITMASK[1] = bit_mask(INTERRUPT_BITS[1]) << INTERRUPT_BITS[0] - INTERRUPT_LVL_BITMASK[2] = bit_mask(INTERRUPT_BITS[2]) << INTERRUPT_BITS[0] + INTERRUPT_BITS[1] + return (1 << bits) - 1 - debug("Level Bits Bitmask") - debug("----------------------------") - for i in range(3): - bitmask_str = "0x" + format(INTERRUPT_LVL_BITMASK[i], '08X') - debug(f"{i + 1:>5} {INTERRUPT_BITS[i]:>7} {bitmask_str:>14}") - -def main(): - parse_args() - - with open(args.kernel, "rb") as fp: - kernel = ELFFile(fp) - syms = get_symbols(kernel) - intlist = read_intlist(kernel, syms, args.intlist_section) +def update_masks(syms): if "CONFIG_MULTI_LEVEL_INTERRUPTS" in syms: max_irq_per = syms["CONFIG_MAX_IRQ_PER_AGGREGATOR"] @@ -303,59 +260,98 @@ def main(): INTERRUPT_BITS[0] = syms["CONFIG_1ST_LEVEL_INTERRUPT_BITS"] INTERRUPT_BITS[1] = syms["CONFIG_2ND_LEVEL_INTERRUPT_BITS"] INTERRUPT_BITS[2] = syms["CONFIG_3RD_LEVEL_INTERRUPT_BITS"] - update_masks() - if "CONFIG_2ND_LEVEL_INTERRUPTS" in syms: - num_aggregators = syms["CONFIG_NUM_2ND_LEVEL_AGGREGATORS"] - irq2_baseoffset = syms["CONFIG_2ND_LVL_ISR_TBL_OFFSET"] - list_2nd_lvl_offsets = [syms['CONFIG_2ND_LVL_INTR_{}_OFFSET'. - format(str(i).zfill(2))] for i in - range(num_aggregators)] + if sum(INTERRUPT_BITS) > 32: + raise ValueError("Too many interrupt bits") - debug('2nd level offsets: {}'.format(list_2nd_lvl_offsets)) + INTERRUPT_LVL_BITMASK[0] = bit_mask(INTERRUPT_BITS[0]) + INTERRUPT_LVL_BITMASK[1] = bit_mask(INTERRUPT_BITS[1]) << INTERRUPT_BITS[0] + INTERRUPT_LVL_BITMASK[2] = bit_mask(INTERRUPT_BITS[2]) << INTERRUPT_BITS[0] + INTERRUPT_BITS[1] - if "CONFIG_3RD_LEVEL_INTERRUPTS" in syms: - num_aggregators = syms["CONFIG_NUM_3RD_LEVEL_AGGREGATORS"] - irq3_baseoffset = syms["CONFIG_3RD_LVL_ISR_TBL_OFFSET"] - list_3rd_lvl_offsets = [syms['CONFIG_3RD_LVL_INTR_{}_OFFSET'. - format(str(i).zfill(2))] for i in - range(num_aggregators)] + debug("Level Bits Bitmask") + debug("----------------------------") + for i in range(3): + bitmask_str = "0x" + format(INTERRUPT_LVL_BITMASK[i], '08X') + debug(f"{i + 1:>5} {INTERRUPT_BITS[i]:>7} {bitmask_str:>14}") - debug('3rd level offsets: {}'.format(list_3rd_lvl_offsets)) +def update_vt_default_handler(): + """Update the vt default handler based on parsed arguments. + + The default vt handler would be different depending on the fact if we have sw_isr_table. + If we have it - the default handler would lead to common handler. + If we do not - the default handler would be spurious handler + + The result is writen into vt_default_handler variable. + """ + global vt_default_handler + + if args.sw_isr_table: + vt_default_handler = vt_irq_handler + else: + vt_default_handler = vt_spurious_handler +def parse_intlist(intlist, syms): + """All the intlist data are parsed into swt and vt arrays. + + The vt array is prepared for hardware interrupt table. + Every entry in the selected position would contain None or the name of the function pointer + (address or string). + + The swt is a little more complex. At every position it would contain an array of parameter and + function pointer pairs. If CONFIG_SHARED_INTERRUPTS is enabled there may be more than 1 entry. + If empty array is placed on selected position - it means that the application does not implement + this interrupt. + + Parameters: + - intlist: The preprocessed list of intlist section content (see read_intlist) + - syms: Symbols + + Return: + vt, swt - parsed vt and swt arrays (see function description above) + """ nvec = intlist["num_vectors"] offset = intlist["offset"] if nvec > pow(2, 15): raise ValueError('nvec is too large, check endianness.') - swt_spurious_handler = "((uintptr_t)&z_irq_spurious)" - swt_shared_handler = "((uintptr_t)&z_shared_isr)" - vt_spurious_handler = "z_irq_spurious" - vt_irq_handler = "_isr_wrapper" - debug('offset is ' + str(offset)) debug('num_vectors is ' + str(nvec)) # Set default entries in both tables + if not(args.sw_isr_table or args.vector_table): + error("one or both of -s or -V needs to be specified on command line") + if args.vector_table: + vt = [None for i in range(nvec)] + else: + vt = None if args.sw_isr_table: - # All vectors just jump to the common vt_irq_handler. If some entries - # are used for direct interrupts, they will be replaced later. - if args.vector_table: - vt = [vt_irq_handler for i in range(nvec)] - else: - vt = None - # Default to spurious interrupt handler. Configured interrupts - # will replace these entries. - swt = [(0, swt_spurious_handler) for i in range(nvec)] - shared = [([], 0) for i in range(nvec)] + swt = [[] for i in range(nvec)] else: - if args.vector_table: - vt = [vt_spurious_handler for i in range(nvec)] - else: - error("one or both of -s or -V needs to be specified on command line") swt = None + # Gather info about multi level interrupts if enabled + if "CONFIG_MULTI_LEVEL_INTERRUPTS" in syms: + max_irq_per = syms["CONFIG_MAX_IRQ_PER_AGGREGATOR"] + + if "CONFIG_2ND_LEVEL_INTERRUPTS" in syms: + num_aggregators = syms["CONFIG_NUM_2ND_LEVEL_AGGREGATORS"] + irq2_baseoffset = syms["CONFIG_2ND_LVL_ISR_TBL_OFFSET"] + list_2nd_lvl_offsets = [syms['CONFIG_2ND_LVL_INTR_{}_OFFSET'. + format(str(i).zfill(2))] for i in + range(num_aggregators)] + + debug('2nd level offsets: {}'.format(list_2nd_lvl_offsets)) + + if "CONFIG_3RD_LEVEL_INTERRUPTS" in syms: + num_aggregators = syms["CONFIG_NUM_3RD_LEVEL_AGGREGATORS"] + irq3_baseoffset = syms["CONFIG_3RD_LVL_ISR_TBL_OFFSET"] + list_3rd_lvl_offsets = [syms['CONFIG_3RD_LVL_INTR_{}_OFFSET'. + format(str(i).zfill(2))] for i in + range(num_aggregators)] + + debug('3rd level offsets: {}'.format(list_3rd_lvl_offsets)) + # Process intlist and write to the tables created for irq, flags, func, param in intlist["interrupts"]: if flags & ISR_FLAG_DIRECT: if not vt: @@ -381,13 +377,12 @@ def main(): else: # Figure out third level interrupt position debug('IRQ = ' + hex(irq)) - irq3 = (irq & INTERRUPT_LVL_BITMASK[2]) >> INTERRUPT_BITS[0] + INTERRUPT_BITS[1] - irq2 = (irq & INTERRUPT_LVL_BITMASK[1]) >> INTERRUPT_BITS[0] + irq3 = (irq & INTERRUPT_LVL_BITMASK[2]) >> (INTERRUPT_BITS[0] + INTERRUPT_BITS[1]) + irq2 = (irq & INTERRUPT_LVL_BITMASK[1]) >> (INTERRUPT_BITS[0]) irq1 = irq & INTERRUPT_LVL_BITMASK[0] if irq3: - irq_parent = irq2 - list_index = getindex(irq_parent, list_3rd_lvl_offsets) + list_index = getindex(irq2, list_3rd_lvl_offsets) irq3_pos = irq3_baseoffset + max_irq_per*list_index + irq3 - 1 debug('IRQ_level = 3') debug('IRQ_Indx = ' + str(irq3)) @@ -396,8 +391,7 @@ def main(): # Figure out second level interrupt position elif irq2: - irq_parent = irq1 - list_index = getindex(irq_parent, list_2nd_lvl_offsets) + list_index = getindex(irq1, list_2nd_lvl_offsets) irq2_pos = irq2_baseoffset + max_irq_per*list_index + irq2 - 1 debug('IRQ_level = 2') debug('IRQ_Indx = ' + str(irq2)) @@ -415,36 +409,92 @@ def main(): error("IRQ %d (offset=%d) exceeds the maximum of %d" % (table_index, offset, len(swt) - 1)) if "CONFIG_SHARED_INTERRUPTS" in syms: - if swt[table_index] != (0, swt_spurious_handler): - # check client limit - if syms["CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS"] == shared[table_index][1]: - error(f"Reached shared interrupt client limit. Maybe increase" + lst = swt[table_index] + if (param, func) in lst: + error("Attempting to register the same ISR/arg pair twice.") + if len(lst) >= syms["CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS"]: + error(f"Reached shared interrupt client limit. Maybe increase" + f" CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS?") - lst = shared[table_index][0] - delta_size = 1 - if not shared[table_index][1]: - lst.append(swt[table_index]) - # note: the argument will be fixed when writing the ISR table - # to isr_table.c - swt[table_index] = (0, swt_shared_handler) - delta_size += 1 - if (param, func) in lst: - error("Attempting to register the same ISR/arg pair twice.") - lst.append((param, func)) - shared[table_index] = (lst, shared[table_index][1] + delta_size) - else: - swt[table_index] = (param, func) else: - if swt[table_index] != (0, swt_spurious_handler): + if len(swt[table_index]) > 0: error(f"multiple registrations at table_index {table_index} for irq {irq} (0x{irq:x})" - + f"\nExisting handler 0x{swt[table_index][1]:x}, new handler 0x{func:x}" + + f"\nExisting handler 0x{swt[table_index][0][1]:x}, new handler 0x{func:x}" + "\nHas IRQ_CONNECT or IRQ_DIRECT_CONNECT accidentally been invoked on the same irq multiple times?" ) - else: - swt[table_index] = (param, func) + swt[table_index].append((param, func)) + + return vt, swt + +def get_symbols(obj): + for section in obj.iter_sections(): + if isinstance(section, SymbolTableSection): + return {sym.name: sym.entry.st_value + for sym in section.iter_symbols()} + + error("Could not find symbol table") + +def read_intList_sect(elfobj, snames): + """ + Load the raw intList section data in a form of byte array. + """ + intList_sect = None + + for sname in snames: + intList_sect = elfobj.get_section_by_name(sname) + if intList_sect is not None: + debug("Found intlist section: \"{}\"".format(sname)) + break + + if intList_sect is None: + error("Cannot find the intlist section!") + + intdata = intList_sect.data() + + return intdata + +def parse_args(): + global args + + parser = argparse.ArgumentParser(description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter, allow_abbrev=False) + + parser.add_argument("-e", "--big-endian", action="store_true", + help="Target encodes data in big-endian format (little endian is " + "the default)") + parser.add_argument("-d", "--debug", action="store_true", + help="Print additional debugging information") + parser.add_argument("-o", "--output-source", required=True, + help="Output source file") + parser.add_argument("-k", "--kernel", required=True, + help="Zephyr kernel image") + parser.add_argument("-s", "--sw-isr-table", action="store_true", + help="Generate SW ISR table") + parser.add_argument("-V", "--vector-table", action="store_true", + help="Generate vector table") + parser.add_argument("-i", "--intlist-section", action="append", required=True, + help="The name of the section to search for the interrupt data. " + "This is accumulative argument. The first section found would be used.") + + args = parser.parse_args() + +def main(): + """ + All the input data are parsed to vt + """ + parse_args() + + with open(args.kernel, "rb") as fp: + kernel = ELFFile(fp) + syms = get_symbols(kernel) + intlist_data = read_intList_sect(kernel, args.intlist_section) + intlist = read_intlist(intlist_data, syms) + + update_masks(syms) + update_vt_default_handler() + vt, swt = parse_intlist(intlist, syms) with open(args.output_source, "w") as fp: - write_source_file(fp, vt, swt, intlist, syms, shared) + write_source_file(fp, vt, swt, intlist, syms) if __name__ == "__main__": main() From 34d26ee38bec4b8444661de8eb2fc02ab8de9056 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Thu, 9 Nov 2023 09:41:43 +0100 Subject: [PATCH 1523/1623] [nrf fromtree] scripts: gen_isr_tables: Break code into classes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit breaks the code into functional classes. This way the functionality is visibly splitted into functional parts and it is easier to replace the specific parser part to implement new code generators. There is also common functionality to handle multi level interrupts moved to configuration class. Signed-off-by: Radosław Koppel (cherry picked from commit 568cced14fabe686b01ceea3884a488ca4213fb4) --- scripts/build/gen_isr_tables.py | 826 ++++++++++++++++++-------------- 1 file changed, 456 insertions(+), 370 deletions(-) diff --git a/scripts/build/gen_isr_tables.py b/scripts/build/gen_isr_tables.py index 41fc20957a6..3032d1e30c9 100755 --- a/scripts/build/gen_isr_tables.py +++ b/scripts/build/gen_isr_tables.py @@ -14,142 +14,227 @@ from elftools.elf.elffile import ELFFile from elftools.elf.sections import SymbolTableSection -ISR_FLAG_DIRECT = 1 << 0 - -# The below few hardware independent magic numbers represent various -# levels of interrupts in a multi-level interrupt system. -# 0x000000FF - represents the 1st level (i.e. the interrupts -# that directly go to the processor). -# 0x0000FF00 - represents the 2nd level (i.e. the interrupts funnel -# into 1 line which then goes into the 1st level) -# 0x00FF0000 - represents the 3rd level (i.e. the interrupts funnel -# into 1 line which then goes into the 2nd level) -INTERRUPT_LVL_BITMASK = [0x000000FF, 0x0000FF00, 0x00FF0000] - -INTERRUPT_BITS = [8, 8, 8] - -swt_spurious_handler = "((uintptr_t)&z_irq_spurious)" -swt_shared_handler = "((uintptr_t)&z_shared_isr)" -vt_spurious_handler = "z_irq_spurious" -vt_irq_handler = "_isr_wrapper" -vt_default_handler = None - - -def debug(text): - if args.debug: - sys.stdout.write(os.path.basename(sys.argv[0]) + ": " + text + "\n") - -def error(text): - sys.exit(os.path.basename(sys.argv[0]) + ": error: " + text + "\n") - -def endian_prefix(): - if args.big_endian: - return ">" - else: - return "<" - -def read_intlist(intlist_data, syms): - """read a binary file containing the contents of the kernel's .intList - section. This is an instance of a header created by - include/zephyr/linker/intlist.ld: - - struct { - uint32_t num_vectors; <- typically CONFIG_NUM_IRQS - struct _isr_list isrs[]; <- Usually of smaller size than num_vectors - } - - Followed by instances of struct _isr_list created by IRQ_CONNECT() - calls: - - struct _isr_list { - /** IRQ line number */ - int32_t irq; - /** Flags for this IRQ, see ISR_FLAG_* definitions */ - int32_t flags; - /** ISR to call */ - void *func; - /** Parameter for non-direct IRQs */ - const void *param; - }; - """ - intlist = {} - prefix = endian_prefix() - - # Extract header and the rest of the data - intlist_header_fmt = prefix + "II" - header_sz = struct.calcsize(intlist_header_fmt) - header_raw = struct.unpack_from(intlist_header_fmt, intlist_data, 0) - debug(str(header_raw)) - intlist["num_vectors"] = header_raw[0] - intlist["offset"] = header_raw[1] - intdata = intlist_data[header_sz:] +class gen_isr_log: - # Extract information about interrupts - if "CONFIG_64BIT" in syms: - intlist_entry_fmt = prefix + "iiQQ" - else: - intlist_entry_fmt = prefix + "iiII" + def __init__(self, debug = False): + self.__debug = debug - intlist["interrupts"] = [i for i in - struct.iter_unpack(intlist_entry_fmt, intdata)] + def debug(self, text): + """Print debug message if debugging is enabled. - debug("Configured interrupt routing") - debug("handler irq flags param") - debug("--------------------------") + Note - this function requires config global variable to be initialized. + """ + if self.__debug: + sys.stdout.write(os.path.basename(sys.argv[0]) + ": " + text + "\n") - for irq in intlist["interrupts"]: - debug("{0:<10} {1:<3} {2:<3} {3}".format( - hex(irq[2]), irq[0], irq[1], hex(irq[3]))) + @staticmethod + def error(text): + sys.exit(os.path.basename(sys.argv[0]) + ": error: " + text + "\n") - return intlist - -source_assembly_header = """ -#ifndef ARCH_IRQ_VECTOR_JUMP_CODE -#error "ARCH_IRQ_VECTOR_JUMP_CODE not defined" -#endif -""" + def set_debug(self, state): + self.__debug = state -def get_symbol_from_addr(syms, addr): - for key, value in syms.items(): - if addr == value: - return key - return None -def write_code_irq_vector_table(fp, vt, nv, syms): - fp.write(source_assembly_header) +log = gen_isr_log() - fp.write("void __irq_vector_table __attribute__((naked)) _irq_vector_table(void) {\n") - for i in range(nv): - func = vt[i] - if func is None: - func = vt_default_handler - - if isinstance(func, int): - func_as_string = get_symbol_from_addr(syms, func) +class gen_isr_config: + """All the constants and configuration gathered in single class for readability. + """ + # Constants + __ISR_FLAG_DIRECT = 1 << 0 + __swt_spurious_handler = "((uintptr_t)&z_irq_spurious)" + __swt_shared_handler = "((uintptr_t)&z_shared_isr)" + __vt_spurious_handler = "z_irq_spurious" + __vt_irq_handler = "_isr_wrapper" + + @staticmethod + def __bm(bits): + return (1 << bits) - 1 + + def __init__(self, args, syms, log): + """Initialize the configuration object. + + The configuration object initialization takes only arguments as a parameter. + This is done to allow debug function work as soon as possible. + """ + # Store the arguments required for work + self.__args = args + self.__syms = syms + self.__log = log + + # Select the default interrupt vector handler + if self.args.sw_isr_table: + self.__vt_default_handler = self.__vt_irq_handler else: - func_as_string = func - - fp.write("\t__asm(ARCH_IRQ_VECTOR_JUMP_CODE({}));\n".format(func_as_string)) - fp.write("}\n") - -def write_address_irq_vector_table(fp, vt, nv): - fp.write("uintptr_t __irq_vector_table _irq_vector_table[%d] = {\n" % nv) - for i in range(nv): - func = vt[i] - - if func is None: - func = vt_default_handler - - if isinstance(func, int): - fp.write("\t{},\n".format(func)) + self.__vt_default_handler = self.__vt_spurious_handler + # Calculate interrupt bits + self.__int_bits = [8, 8, 8] + # The below few hardware independent magic numbers represent various + # levels of interrupts in a multi-level interrupt system. + # 0x000000FF - represents the 1st level (i.e. the interrupts + # that directly go to the processor). + # 0x0000FF00 - represents the 2nd level (i.e. the interrupts funnel + # into 1 line which then goes into the 1st level) + # 0x00FF0000 - represents the 3rd level (i.e. the interrupts funnel + # into 1 line which then goes into the 2nd level) + self.__int_lvl_masks = [0x000000FF, 0x0000FF00, 0x00FF0000] + + self.__irq2_baseoffset = None + self.__irq3_baseoffset = None + self.__irq2_offsets = None + self.__irq3_offsets = None + + if self.check_multi_level_interrupts(): + self.__max_irq_per = self.get_sym("CONFIG_MAX_IRQ_PER_AGGREGATOR") + + self.__int_bits[0] = self.get_sym("CONFIG_1ST_LEVEL_INTERRUPT_BITS") + self.__int_bits[1] = self.get_sym("CONFIG_2ND_LEVEL_INTERRUPT_BITS") + self.__int_bits[2] = self.get_sym("CONFIG_3RD_LEVEL_INTERRUPT_BITS") + + if sum(self.int_bits) > 32: + raise ValueError("Too many interrupt bits") + + self.__int_lvl_masks[0] = self.__bm(self.int_bits[0]) + self.__int_lvl_masks[1] = self.__bm(self.int_bits[1]) << self.int_bits[0] + self.__int_lvl_masks[2] = self.__bm(self.int_bits[2]) << (self.int_bits[0] + self.int_bits[1]) + + self.__log.debug("Level Bits Bitmask") + self.__log.debug("----------------------------") + for i in range(3): + bitmask_str = "0x" + format(self.__int_lvl_masks[i], '08X') + self.__log.debug(f"{i + 1:>5} {self.__int_bits[i]:>7} {bitmask_str:>14}") + + if self.check_sym("CONFIG_2ND_LEVEL_INTERRUPTS"): + num_aggregators = self.get_sym("CONFIG_NUM_2ND_LEVEL_AGGREGATORS") + self.__irq2_baseoffset = self.get_sym("CONFIG_2ND_LVL_ISR_TBL_OFFSET") + self.__irq2_offsets = [self.get_sym('CONFIG_2ND_LVL_INTR_{}_OFFSET'. + format(str(i).zfill(2))) for i in + range(num_aggregators)] + + self.__log.debug('2nd level offsets: {}'.format(self.__irq2_offsets)) + + if self.check_sym("CONFIG_3RD_LEVEL_INTERRUPTS"): + num_aggregators = self.get_sym("CONFIG_NUM_3RD_LEVEL_AGGREGATORS") + self.__irq3_baseoffset = self.get_sym("CONFIG_3RD_LVL_ISR_TBL_OFFSET") + self.__irq3_offsets = [self.get_sym('CONFIG_3RD_LVL_INTR_{}_OFFSET'. + format(str(i).zfill(2))) for i in + range(num_aggregators)] + + self.__log.debug('3rd level offsets: {}'.format(self.__irq3_offsets)) + + @property + def args(self): + return self.__args + + @property + def swt_spurious_handler(self): + return self.__swt_spurious_handler + + @property + def swt_shared_handler(self): + return self.__swt_shared_handler + + @property + def vt_default_handler(self): + return self.__vt_default_handler + + @property + def int_bits(self): + return self.__int_bits + + @property + def int_lvl_masks(self): + return self.__int_lvl_masks + + def endian_prefix(self): + if self.args.big_endian: + return ">" else: - fp.write("\t((uintptr_t)&{}),\n".format(func)) - - fp.write("};\n") - -source_header = """ + return "<" + + def get_irq_baseoffset(self, lvl): + if lvl == 2: + return self.__irq2_baseoffset + if lvl == 3: + return self.__irq3_baseoffset + self.__log.error("Unsupported irq level: {}".format(lvl)) + + def get_irq_index(self, irq, lvl): + if lvl == 2: + offsets = self.__irq2_offsets + elif lvl == 3: + offsets = self.__irq3_offsets + else: + self.__log.error("Unsupported irq level: {}".format(lvl)) + try: + return offsets.index(irq) + except ValueError: + self.__log.error("IRQ {} not present in parent offsets ({}). ". + format(irq, offsets) + + " Recheck interrupt configuration.") + + def get_swt_table_index(self, offset, irq): + if not self.check_multi_level_interrupts(): + return irq - offset + # Calculate index for multi level interrupts + self.__log.debug('IRQ = ' + hex(irq)) + irq3 = (irq & self.int_lvl_masks[2]) >> (self.int_bits[0] + self.int_bits[1]) + irq2 = (irq & self.int_lvl_masks[1]) >> (self.int_bits[0]) + irq1 = irq & self.int_lvl_masks[0] + # Figure out third level interrupt position + if irq3: + list_index = self.get_irq_index(irq2, 3) + irq3_pos = self.get_irq_baseoffset(3) + self.__max_irq_per * list_index + irq3 - 1 + self.__log.debug('IRQ_level = 3') + self.__log.debug('IRQ_Indx = ' + str(irq3)) + self.__log.debug('IRQ_Pos = ' + str(irq3_pos)) + return irq3_pos - offset + # Figure out second level interrupt position + if irq2: + list_index = self.get_irq_index(irq1, 2) + irq2_pos = self.get_irq_baseoffset(2) + self.__max_irq_per * list_index + irq2 - 1 + self.__log.debug('IRQ_level = 2') + self.__log.debug('IRQ_Indx = ' + str(irq2)) + self.__log.debug('IRQ_Pos = ' + str(irq2_pos)) + return irq2_pos - offset + # Figure out first level interrupt position + self.__log.debug('IRQ_level = 1') + self.__log.debug('IRQ_Indx = ' + str(irq1)) + self.__log.debug('IRQ_Pos = ' + str(irq1)) + return irq1 - offset + + def get_intlist_snames(self): + return self.args.intlist_section + + def test_isr_direct(self, flags): + return flags & self.__ISR_FLAG_DIRECT + + def get_sym_from_addr(self, addr): + for key, value in self.__syms.items(): + if addr == value: + return key + return None + + def get_sym(self, name): + return self.__syms.get(name) + + def check_sym(self, name): + return name in self.__syms + + def check_multi_level_interrupts(self): + return self.check_sym("CONFIG_MULTI_LEVEL_INTERRUPTS") + + def check_shared_interrupts(self): + return self.check_sym("CONFIG_SHARED_INTERRUPTS") + + def check_64b(self): + return self.check_sym("CONFIG_64BIT") + + +class gen_isr_parser: + source_header = """ /* AUTO-GENERATED by gen_isr_tables.py, do not edit! */ #include @@ -160,270 +245,276 @@ def write_address_irq_vector_table(fp, vt, nv): typedef void (* ISR)(const void *); """ -def write_shared_table(fp, swt, nv): - fp.write("struct z_shared_isr_table_entry __shared_sw_isr_table" - " z_shared_sw_isr_table[%d] = {\n" % nv) + source_assembly_header = """ +#ifndef ARCH_IRQ_VECTOR_JUMP_CODE +#error "ARCH_IRQ_VECTOR_JUMP_CODE not defined" +#endif +""" - for i in range(nv): - if swt[i] is None: - client_num = 0 - client_list = None + def __init__(self, intlist_data, config, log): + """Initialize the parser. + + The function prepares parser to work. + Parameters: + - intlist_data: The binnary data from intlist section + - config: The configuration object + - log: The logging object, has to have error and debug methods + """ + self.__config = config + self.__log = log + intlist = self.__read_intlist(intlist_data) + self.__vt, self.__swt, self.__nv = self.__parse_intlist(intlist) + + def __read_intlist(self, intlist_data): + """read a binary file containing the contents of the kernel's .intList + section. This is an instance of a header created by + include/zephyr/linker/intlist.ld: + + struct { + uint32_t num_vectors; <- typically CONFIG_NUM_IRQS + struct _isr_list isrs[]; <- Usually of smaller size than num_vectors + } + + Followed by instances of struct _isr_list created by IRQ_CONNECT() + calls: + + struct _isr_list { + /** IRQ line number */ + int32_t irq; + /** Flags for this IRQ, see ISR_FLAG_* definitions */ + int32_t flags; + /** ISR to call */ + void *func; + /** Parameter for non-direct IRQs */ + const void *param; + }; + """ + intlist = {} + prefix = self.__config.endian_prefix() + + # Extract header and the rest of the data + intlist_header_fmt = prefix + "II" + header_sz = struct.calcsize(intlist_header_fmt) + header_raw = struct.unpack_from(intlist_header_fmt, intlist_data, 0) + self.__log.debug(str(header_raw)) + + intlist["num_vectors"] = header_raw[0] + intlist["offset"] = header_raw[1] + intdata = intlist_data[header_sz:] + + # Extract information about interrupts + if self.__config.check_64b(): + intlist_entry_fmt = prefix + "iiQQ" else: - client_num = len(swt[i]) - client_list = swt[i] + intlist_entry_fmt = prefix + "iiII" - if client_num <= 1: - fp.write("\t{ },\n") - else: - fp.write(f"\t{{ .client_num = {client_num}, .clients = {{ ") - for j in range(0, client_num): - routine = client_list[j][1] - arg = client_list[j][0] + intlist["interrupts"] = [i for i in + struct.iter_unpack(intlist_entry_fmt, intdata)] + + self.__log.debug("Configured interrupt routing") + self.__log.debug("handler irq flags param") + self.__log.debug("--------------------------") + + for irq in intlist["interrupts"]: + self.__log.debug("{0:<10} {1:<3} {2:<3} {3}".format( + hex(irq[2]), irq[0], irq[1], hex(irq[3]))) - fp.write(f"{{ .isr = (ISR){ hex(routine) if isinstance(routine, int) else routine }, " - f".arg = (const void *){hex(arg)} }},") + return intlist - fp.write(" },\n},\n") + def __parse_intlist(self, intlist): + """All the intlist data are parsed into swt and vt arrays. - fp.write("};\n") + The vt array is prepared for hardware interrupt table. + Every entry in the selected position would contain None or the name of the function pointer + (address or string). -def write_source_file(fp, vt, swt, intlist, syms): - fp.write(source_header) + The swt is a little more complex. At every position it would contain an array of parameter and + function pointer pairs. If CONFIG_SHARED_INTERRUPTS is enabled there may be more than 1 entry. + If empty array is placed on selected position - it means that the application does not implement + this interrupt. - nv = intlist["num_vectors"] + Parameters: + - intlist: The preprocessed list of intlist section content (see read_intlist) - if "CONFIG_SHARED_INTERRUPTS" in syms: - write_shared_table(fp, swt, nv) + Return: + vt, swt - parsed vt and swt arrays (see function description above) + """ + nvec = intlist["num_vectors"] + offset = intlist["offset"] - if vt: - if "CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS" in syms: - write_address_irq_vector_table(fp, vt, nv) - elif "CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_CODE" in syms: - write_code_irq_vector_table(fp, vt, nv, syms) + if nvec > pow(2, 15): + raise ValueError('nvec is too large, check endianness.') + + self.__log.debug('offset is ' + str(offset)) + self.__log.debug('num_vectors is ' + str(nvec)) + + # Set default entries in both tables + if not(self.__config.args.sw_isr_table or self.__config.args.vector_table): + self.__log.error("one or both of -s or -V needs to be specified on command line") + if self.__config.args.vector_table: + vt = [None for i in range(nvec)] else: - error("CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_{ADDRESS,CODE} not set") - - if not swt: - return - - fp.write("struct _isr_table_entry __sw_isr_table _sw_isr_table[%d] = {\n" - % nv) - - level2_offset = syms.get("CONFIG_2ND_LVL_ISR_TBL_OFFSET") - level3_offset = syms.get("CONFIG_3RD_LVL_ISR_TBL_OFFSET") - - for i in range(nv): - if len(swt[i]) == 0: - # Not used interrupt - param = "0x0" - func = swt_spurious_handler - elif len(swt[i]) == 1: - # Single interrupt - param = "{0:#x}".format(swt[i][0][0]) - func = swt[i][0][1] + vt = None + if self.__config.args.sw_isr_table: + swt = [[] for i in range(nvec)] else: - # Shared interrupt - param = "&z_shared_sw_isr_table[{0}]".format(i) - func = swt_shared_handler + swt = None - if isinstance(func, int): - func_as_string = "{0:#x}".format(func) - else: - func_as_string = func + # Process intlist and write to the tables created + for irq, flags, func, param in intlist["interrupts"]: + if not vt: + error("Direct Interrupt %d declared with parameter 0x%x " + "but no vector table in use" + % (irq, param)) + if self.__config.test_isr_direct(flags): + if param != 0: + self.__log.error("Direct irq %d declared, but has non-NULL parameter" + % irq) + if not 0 <= irq - offset < len(vt): + self.__log.error("IRQ %d (offset=%d) exceeds the maximum of %d" % + (irq - offset, offset, len(vt) - 1)) + vt[irq - offset] = func + else: + # Regular interrupt + if not swt: + self.__log.error("Regular Interrupt %d declared with parameter 0x%x " + "but no SW ISR_TABLE in use" + % (irq, param)) + + table_index = self.__config.get_swt_table_index(offset, irq) + + if not 0 <= table_index < len(swt): + self.__log.error("IRQ %d (offset=%d) exceeds the maximum of %d" % + (table_index, offset, len(swt) - 1)) + if self.__config.check_shared_interrupts(): + lst = swt[table_index] + if (param, func) in lst: + self.__log.error("Attempting to register the same ISR/arg pair twice.") + if len(lst) >= self.__config.get_sym("CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS"): + self.__log.error(f"Reached shared interrupt client limit. Maybe increase" + + f" CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS?") + else: + if len(swt[table_index]) > 0: + self.__log.error(f"multiple registrations at table_index {table_index} for irq {irq} (0x{irq:x})" + + f"\nExisting handler 0x{swt[table_index][0][1]:x}, new handler 0x{func:x}" + + "\nHas IRQ_CONNECT or IRQ_DIRECT_CONNECT accidentally been invoked on the same irq multiple times?" + ) + swt[table_index].append((param, func)) - if level2_offset is not None and i == level2_offset: - fp.write("\t/* Level 2 interrupts start here (offset: {}) */\n". - format(level2_offset)) - if level3_offset is not None and i == level3_offset: - fp.write("\t/* Level 3 interrupts start here (offset: {}) */\n". - format(level3_offset)) + return vt, swt, nvec - fp.write("\t{{(const void *){0}, (ISR){1}}}, /* {2} */\n".format(param, func_as_string, i)) - fp.write("};\n") + def __write_code_irq_vector_table(self, fp): + fp.write(self.source_assembly_header) -def getindex(irq, irq_aggregator_pos): - try: - return irq_aggregator_pos.index(irq) - except ValueError: - error("IRQ {} not present in parent offsets ({}). ". - format(irq, irq_aggregator_pos) + - " Recheck interrupt configuration.") + fp.write("void __irq_vector_table __attribute__((naked)) _irq_vector_table(void) {\n") + for i in range(self.__nv): + func = self.__vt[i] -def bit_mask(bits): - return (1 << bits) - 1 + if func is None: + func = self.__config.vt_default_handler -def update_masks(syms): + if isinstance(func, int): + func_as_string = self.__config.get_sym_from_addr(func) + else: + func_as_string = func - if "CONFIG_MULTI_LEVEL_INTERRUPTS" in syms: - max_irq_per = syms["CONFIG_MAX_IRQ_PER_AGGREGATOR"] + fp.write("\t__asm(ARCH_IRQ_VECTOR_JUMP_CODE({}));\n".format(func_as_string)) + fp.write("}\n") - INTERRUPT_BITS[0] = syms["CONFIG_1ST_LEVEL_INTERRUPT_BITS"] - INTERRUPT_BITS[1] = syms["CONFIG_2ND_LEVEL_INTERRUPT_BITS"] - INTERRUPT_BITS[2] = syms["CONFIG_3RD_LEVEL_INTERRUPT_BITS"] + def __write_address_irq_vector_table(self, fp): + fp.write("uintptr_t __irq_vector_table _irq_vector_table[%d] = {\n" % self.__nv) + for i in range(self.__nv): + func = self.__vt[i] - if sum(INTERRUPT_BITS) > 32: - raise ValueError("Too many interrupt bits") + if func is None: + func = self.__config.vt_default_handler - INTERRUPT_LVL_BITMASK[0] = bit_mask(INTERRUPT_BITS[0]) - INTERRUPT_LVL_BITMASK[1] = bit_mask(INTERRUPT_BITS[1]) << INTERRUPT_BITS[0] - INTERRUPT_LVL_BITMASK[2] = bit_mask(INTERRUPT_BITS[2]) << INTERRUPT_BITS[0] + INTERRUPT_BITS[1] + if isinstance(func, int): + fp.write("\t{},\n".format(func)) + else: + fp.write("\t((uintptr_t)&{}),\n".format(func)) - debug("Level Bits Bitmask") - debug("----------------------------") - for i in range(3): - bitmask_str = "0x" + format(INTERRUPT_LVL_BITMASK[i], '08X') - debug(f"{i + 1:>5} {INTERRUPT_BITS[i]:>7} {bitmask_str:>14}") + fp.write("};\n") -def update_vt_default_handler(): - """Update the vt default handler based on parsed arguments. + def __write_shared_table(self, fp): + fp.write("struct z_shared_isr_table_entry __shared_sw_isr_table" + " z_shared_sw_isr_table[%d] = {\n" % self.__nv) - The default vt handler would be different depending on the fact if we have sw_isr_table. - If we have it - the default handler would lead to common handler. - If we do not - the default handler would be spurious handler + for i in range(self.__nv): + if self.__swt[i] is None: + client_num = 0 + client_list = None + else: + client_num = len(self.__swt[i]) + client_list = self.__swt[i] - The result is writen into vt_default_handler variable. - """ - global vt_default_handler + if client_num <= 1: + fp.write("\t{ },\n") + else: + fp.write(f"\t{{ .client_num = {client_num}, .clients = {{ ") + for j in range(0, client_num): + routine = client_list[j][1] + arg = client_list[j][0] - if args.sw_isr_table: - vt_default_handler = vt_irq_handler - else: - vt_default_handler = vt_spurious_handler + fp.write(f"{{ .isr = (ISR){ hex(routine) if isinstance(routine, int) else routine }, " + f".arg = (const void *){hex(arg)} }},") -def parse_intlist(intlist, syms): - """All the intlist data are parsed into swt and vt arrays. + fp.write(" },\n},\n") - The vt array is prepared for hardware interrupt table. - Every entry in the selected position would contain None or the name of the function pointer - (address or string). + fp.write("};\n") - The swt is a little more complex. At every position it would contain an array of parameter and - function pointer pairs. If CONFIG_SHARED_INTERRUPTS is enabled there may be more than 1 entry. - If empty array is placed on selected position - it means that the application does not implement - this interrupt. + def write_source(self, fp): + fp.write(self.source_header) - Parameters: - - intlist: The preprocessed list of intlist section content (see read_intlist) - - syms: Symbols + if self.__config.check_shared_interrupts(): + self.__write_shared_table(fp) - Return: - vt, swt - parsed vt and swt arrays (see function description above) - """ - nvec = intlist["num_vectors"] - offset = intlist["offset"] - - if nvec > pow(2, 15): - raise ValueError('nvec is too large, check endianness.') - - debug('offset is ' + str(offset)) - debug('num_vectors is ' + str(nvec)) - - # Set default entries in both tables - if not(args.sw_isr_table or args.vector_table): - error("one or both of -s or -V needs to be specified on command line") - if args.vector_table: - vt = [None for i in range(nvec)] - else: - vt = None - if args.sw_isr_table: - swt = [[] for i in range(nvec)] - else: - swt = None - - # Gather info about multi level interrupts if enabled - if "CONFIG_MULTI_LEVEL_INTERRUPTS" in syms: - max_irq_per = syms["CONFIG_MAX_IRQ_PER_AGGREGATOR"] - - if "CONFIG_2ND_LEVEL_INTERRUPTS" in syms: - num_aggregators = syms["CONFIG_NUM_2ND_LEVEL_AGGREGATORS"] - irq2_baseoffset = syms["CONFIG_2ND_LVL_ISR_TBL_OFFSET"] - list_2nd_lvl_offsets = [syms['CONFIG_2ND_LVL_INTR_{}_OFFSET'. - format(str(i).zfill(2))] for i in - range(num_aggregators)] - - debug('2nd level offsets: {}'.format(list_2nd_lvl_offsets)) - - if "CONFIG_3RD_LEVEL_INTERRUPTS" in syms: - num_aggregators = syms["CONFIG_NUM_3RD_LEVEL_AGGREGATORS"] - irq3_baseoffset = syms["CONFIG_3RD_LVL_ISR_TBL_OFFSET"] - list_3rd_lvl_offsets = [syms['CONFIG_3RD_LVL_INTR_{}_OFFSET'. - format(str(i).zfill(2))] for i in - range(num_aggregators)] - - debug('3rd level offsets: {}'.format(list_3rd_lvl_offsets)) - # Process intlist and write to the tables created - for irq, flags, func, param in intlist["interrupts"]: - if flags & ISR_FLAG_DIRECT: - if not vt: - error("Direct Interrupt %d declared with parameter 0x%x " - "but no vector table in use" - % (irq, param)) - if param != 0: - error("Direct irq %d declared, but has non-NULL parameter" - % irq) - if not 0 <= irq - offset < len(vt): - error("IRQ %d (offset=%d) exceeds the maximum of %d" % - (irq - offset, offset, len(vt) - 1)) - vt[irq - offset] = func - else: - # Regular interrupt - if not swt: - error("Regular Interrupt %d declared with parameter 0x%x " - "but no SW ISR_TABLE in use" - % (irq, param)) - - if not "CONFIG_MULTI_LEVEL_INTERRUPTS" in syms: - table_index = irq - offset + if self.__vt: + if self.__config.check_sym("CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS"): + self.__write_address_irq_vector_table(fp) + elif self.__config.check_sym("CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_CODE"): + self.__write_code_irq_vector_table(fp) else: - # Figure out third level interrupt position - debug('IRQ = ' + hex(irq)) - irq3 = (irq & INTERRUPT_LVL_BITMASK[2]) >> (INTERRUPT_BITS[0] + INTERRUPT_BITS[1]) - irq2 = (irq & INTERRUPT_LVL_BITMASK[1]) >> (INTERRUPT_BITS[0]) - irq1 = irq & INTERRUPT_LVL_BITMASK[0] - - if irq3: - list_index = getindex(irq2, list_3rd_lvl_offsets) - irq3_pos = irq3_baseoffset + max_irq_per*list_index + irq3 - 1 - debug('IRQ_level = 3') - debug('IRQ_Indx = ' + str(irq3)) - debug('IRQ_Pos = ' + str(irq3_pos)) - table_index = irq3_pos - offset - - # Figure out second level interrupt position - elif irq2: - list_index = getindex(irq1, list_2nd_lvl_offsets) - irq2_pos = irq2_baseoffset + max_irq_per*list_index + irq2 - 1 - debug('IRQ_level = 2') - debug('IRQ_Indx = ' + str(irq2)) - debug('IRQ_Pos = ' + str(irq2_pos)) - table_index = irq2_pos - offset - - # Figure out first level interrupt position - else: - debug('IRQ_level = 1') - debug('IRQ_Indx = ' + str(irq1)) - debug('IRQ_Pos = ' + str(irq1)) - table_index = irq1 - offset - - if not 0 <= table_index < len(swt): - error("IRQ %d (offset=%d) exceeds the maximum of %d" % - (table_index, offset, len(swt) - 1)) - if "CONFIG_SHARED_INTERRUPTS" in syms: - lst = swt[table_index] - if (param, func) in lst: - error("Attempting to register the same ISR/arg pair twice.") - if len(lst) >= syms["CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS"]: - error(f"Reached shared interrupt client limit. Maybe increase" - + f" CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS?") + self.__log.error("CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_{ADDRESS,CODE} not set") + + if not self.__swt: + return + + fp.write("struct _isr_table_entry __sw_isr_table _sw_isr_table[%d] = {\n" + % self.__nv) + + level2_offset = self.__config.get_irq_baseoffset(2) + level3_offset = self.__config.get_irq_baseoffset(3) + + for i in range(self.__nv): + if len(self.__swt[i]) == 0: + # Not used interrupt + param = "0x0" + func = self.__config.swt_spurious_handler + elif len(self.__swt[i]) == 1: + # Single interrupt + param = "{0:#x}".format(self.__swt[i][0][0]) + func = self.__swt[i][0][1] + else: + # Shared interrupt + param = "&z_shared_sw_isr_table[{0}]".format(i) + func = self.__config.swt_shared_handler + + if isinstance(func, int): + func_as_string = "{0:#x}".format(func) else: - if len(swt[table_index]) > 0: - error(f"multiple registrations at table_index {table_index} for irq {irq} (0x{irq:x})" - + f"\nExisting handler 0x{swt[table_index][0][1]:x}, new handler 0x{func:x}" - + "\nHas IRQ_CONNECT or IRQ_DIRECT_CONNECT accidentally been invoked on the same irq multiple times?" - ) - swt[table_index].append((param, func)) + func_as_string = func + + if level2_offset is not None and i == level2_offset: + fp.write("\t/* Level 2 interrupts start here (offset: {}) */\n". + format(level2_offset)) + if level3_offset is not None and i == level3_offset: + fp.write("\t/* Level 3 interrupts start here (offset: {}) */\n". + format(level3_offset)) + + fp.write("\t{{(const void *){0}, (ISR){1}}}, /* {2} */\n".format(param, func_as_string, i)) + fp.write("};\n") - return vt, swt def get_symbols(obj): for section in obj.iter_sections(): @@ -431,7 +522,7 @@ def get_symbols(obj): return {sym.name: sym.entry.st_value for sym in section.iter_symbols()} - error("Could not find symbol table") + log.error("Could not find symbol table") def read_intList_sect(elfobj, snames): """ @@ -442,19 +533,17 @@ def read_intList_sect(elfobj, snames): for sname in snames: intList_sect = elfobj.get_section_by_name(sname) if intList_sect is not None: - debug("Found intlist section: \"{}\"".format(sname)) + log.debug("Found intlist section: \"{}\"".format(sname)) break if intList_sect is None: - error("Cannot find the intlist section!") + log.error("Cannot find the intlist section!") intdata = intList_sect.data() return intdata def parse_args(): - global args - parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, allow_abbrev=False) @@ -475,26 +564,23 @@ def parse_args(): help="The name of the section to search for the interrupt data. " "This is accumulative argument. The first section found would be used.") - args = parser.parse_args() + return parser.parse_args() def main(): - """ - All the input data are parsed to vt - """ - parse_args() + args = parse_args() + # Configure logging as soon as possible + log.set_debug(args.debug) with open(args.kernel, "rb") as fp: kernel = ELFFile(fp) - syms = get_symbols(kernel) - intlist_data = read_intList_sect(kernel, args.intlist_section) - intlist = read_intlist(intlist_data, syms) + config = gen_isr_config(args, get_symbols(kernel), log) + intlist_data = read_intList_sect(kernel, config.get_intlist_snames()) - update_masks(syms) - update_vt_default_handler() - vt, swt = parse_intlist(intlist, syms) + parser = gen_isr_parser(intlist_data, config, log) with open(args.output_source, "w") as fp: - write_source_file(fp, vt, swt, intlist, syms) + parser.write_source(fp) + if __name__ == "__main__": main() From 308d52c158f099b9dae396395937b8357f3b25ea Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Wed, 31 Jan 2024 22:50:24 +0100 Subject: [PATCH 1524/1623] [nrf fromtree] arch: sw_isr_table: Update shared interrupts structures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates the definition of z_shared_isr_table_entry to use _isr_table_entry instead of specially created z_shared_isr_client. Signed-off-by: Radosław Koppel (cherry picked from commit b0c83f328c2bc62c1bade3e77da083a00ce36102) --- arch/common/shared_irq.c | 12 ++++++------ doc/kernel/services/interrupts.rst | 11 +---------- include/zephyr/sw_isr_table.h | 7 +------ tests/kernel/interrupt/src/test_shared_irq.h | 2 +- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/arch/common/shared_irq.c b/arch/common/shared_irq.c index 68641cb2bb0..a05e78002ce 100644 --- a/arch/common/shared_irq.c +++ b/arch/common/shared_irq.c @@ -20,7 +20,7 @@ void z_shared_isr(const void *data) { size_t i; const struct z_shared_isr_table_entry *entry; - const struct z_shared_isr_client *client; + const struct _isr_table_entry *client; entry = data; @@ -42,7 +42,7 @@ void z_isr_install(unsigned int irq, void (*routine)(const void *), { struct z_shared_isr_table_entry *shared_entry; struct _isr_table_entry *entry; - struct z_shared_isr_client *client; + struct _isr_table_entry *client; unsigned int table_idx; int i; k_spinlock_key_t key; @@ -103,10 +103,10 @@ void z_isr_install(unsigned int irq, void (*routine)(const void *), k_spin_unlock(&lock, key); } -static void swap_client_data(struct z_shared_isr_client *a, - struct z_shared_isr_client *b) +static void swap_client_data(struct _isr_table_entry *a, + struct _isr_table_entry *b) { - struct z_shared_isr_client tmp; + struct _isr_table_entry tmp; tmp.arg = a->arg; tmp.isr = a->isr; @@ -162,7 +162,7 @@ int z_isr_uninstall(unsigned int irq, { struct z_shared_isr_table_entry *shared_entry; struct _isr_table_entry *entry; - struct z_shared_isr_client *client; + struct _isr_table_entry *client; unsigned int table_idx; size_t i; k_spinlock_key_t key; diff --git a/doc/kernel/services/interrupts.rst b/doc/kernel/services/interrupts.rst index 849e614a562..44f0805edb0 100644 --- a/doc/kernel/services/interrupts.rst +++ b/doc/kernel/services/interrupts.rst @@ -549,7 +549,7 @@ This is an array of struct z_shared_isr_table_entry: .. code-block:: c struct z_shared_isr_table_entry { - struct z_shared_isr_client clients[CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS]; + struct _isr_table_entry clients[CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS]; size_t client_num; }; @@ -558,15 +558,6 @@ lines. Whenever an interrupt line becomes shared, c:func:`z_shared_isr` will replace the currently registered ISR in _sw_isr_table. This special ISR will iterate through the list of registered clients and invoke the ISRs. -The definition for struct z_shared_isr_client is as follows: - -.. code-block:: c - - struct z_shared_isr_client { - void (*isr)(const void *arg); - const void *arg; - }; - x86 Details ----------- diff --git a/include/zephyr/sw_isr_table.h b/include/zephyr/sw_isr_table.h index f43efafad49..fc094b887ba 100644 --- a/include/zephyr/sw_isr_table.h +++ b/include/zephyr/sw_isr_table.h @@ -69,13 +69,8 @@ struct _isr_list { }; #ifdef CONFIG_SHARED_INTERRUPTS -struct z_shared_isr_client { - void (*isr)(const void *arg); - const void *arg; -}; - struct z_shared_isr_table_entry { - struct z_shared_isr_client clients[CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS]; + struct _isr_table_entry clients[CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS]; size_t client_num; }; diff --git a/tests/kernel/interrupt/src/test_shared_irq.h b/tests/kernel/interrupt/src/test_shared_irq.h index fd3c4c4a624..5ddd50a16e1 100644 --- a/tests/kernel/interrupt/src/test_shared_irq.h +++ b/tests/kernel/interrupt/src/test_shared_irq.h @@ -41,7 +41,7 @@ static inline bool client_exists_at_index(void (*routine)(const void *arg), { size_t i; struct z_shared_isr_table_entry *shared_entry; - struct z_shared_isr_client *client; + struct _isr_table_entry *client; shared_entry = &z_shared_sw_isr_table[irq]; From 920b24369620af175f3d5f8cf2d2a99222eea9b0 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Sat, 2 Dec 2023 23:09:11 +0100 Subject: [PATCH 1525/1623] [nrf fromtree] scripts: build: gen_isr_tables: Implement local ISR generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit moves all the functionality related to the current interrupt parser into gen_isr_tables_parser_carrays.py file. The new parser file gen_isr_tables_parser_local.py file is implemented with the new parser that. Additional information added to the generated interrupt header that contains data required by the new parser. Signed-off-by: Radosław Koppel (cherry picked from commit 0ae48ecb58da5ab8c3e942aa02b28ac4d604afbe) --- CMakeLists.txt | 3 +- arch/common/isr_tables.c | 12 + scripts/build/gen_isr_tables.py | 332 +++------------- .../build/gen_isr_tables_parser_carrays.py | 292 ++++++++++++++ scripts/build/gen_isr_tables_parser_local.py | 375 ++++++++++++++++++ 5 files changed, 726 insertions(+), 288 deletions(-) create mode 100644 scripts/build/gen_isr_tables_parser_carrays.py create mode 100644 scripts/build/gen_isr_tables_parser_local.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 97bcd98d0d7..4292e06e211 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1226,10 +1226,11 @@ if(CONFIG_GEN_ISR_TABLES) # isr_tables.c is generated from ${ZEPHYR_LINK_STAGE_EXECUTABLE} by # gen_isr_tables.py add_custom_command( - OUTPUT isr_tables.c + OUTPUT isr_tables.c isr_tables_vt.ld isr_tables_swi.ld COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/gen_isr_tables.py --output-source isr_tables.c + --linker-output-files isr_tables_vt.ld isr_tables_swi.ld --kernel $ --intlist-section .intList --intlist-section intList diff --git a/arch/common/isr_tables.c b/arch/common/isr_tables.c index 9677c92683d..050597b7b1d 100644 --- a/arch/common/isr_tables.c +++ b/arch/common/isr_tables.c @@ -15,6 +15,11 @@ struct int_list_header { uint32_t table_size; uint32_t offset; +#if IS_ENABLED(CONFIG_ISR_TABLES_LOCAL_DECLARATION) + uint32_t swi_table_entry_size; + uint32_t shared_isr_table_entry_size; + uint32_t shared_isr_client_num_offset; +#endif /* IS_ENABLED(CONFIG_ISR_TABLES_LOCAL_DECLARATION) */ }; /* These values are not included in the resulting binary, but instead form the @@ -24,6 +29,13 @@ struct int_list_header { Z_GENERIC_SECTION(.irq_info) __used struct int_list_header _iheader = { .table_size = IRQ_TABLE_SIZE, .offset = CONFIG_GEN_IRQ_START_VECTOR, +#if IS_ENABLED(CONFIG_ISR_TABLES_LOCAL_DECLARATION) + .swi_table_entry_size = sizeof(struct _isr_table_entry), +#if IS_ENABLED(CONFIG_SHARED_INTERRUPTS) + .shared_isr_table_entry_size = sizeof(struct z_shared_isr_table_entry), + .shared_isr_client_num_offset = offsetof(struct z_shared_isr_table_entry, client_num), +#endif /* IS_ENABLED(CONFIG_SHARED_INTERRUPTS) */ +#endif /* IS_ENABLED(CONFIG_ISR_TABLES_LOCAL_DECLARATION) */ }; /* These are placeholder tables. They will be replaced by the real tables diff --git a/scripts/build/gen_isr_tables.py b/scripts/build/gen_isr_tables.py index 3032d1e30c9..84812d708e8 100755 --- a/scripts/build/gen_isr_tables.py +++ b/scripts/build/gen_isr_tables.py @@ -8,9 +8,9 @@ # import argparse -import struct import sys import os +import importlib from elftools.elf.elffile import ELFFile from elftools.elf.sections import SymbolTableSection @@ -44,10 +44,13 @@ class gen_isr_config: """ # Constants __ISR_FLAG_DIRECT = 1 << 0 - __swt_spurious_handler = "((uintptr_t)&z_irq_spurious)" - __swt_shared_handler = "((uintptr_t)&z_shared_isr)" + __swt_spurious_handler = "z_irq_spurious" + __swt_shared_handler = "z_shared_isr" __vt_spurious_handler = "z_irq_spurious" __vt_irq_handler = "_isr_wrapper" + __shared_array_name = "z_shared_sw_isr_table" + __sw_isr_array_name = "_sw_isr_table" + __irq_vector_array_name = "_irq_vector_table" @staticmethod def __bm(bits): @@ -140,6 +143,18 @@ def swt_shared_handler(self): def vt_default_handler(self): return self.__vt_default_handler + @property + def shared_array_name(self): + return self.__shared_array_name + + @property + def sw_isr_array_name(self): + return self.__sw_isr_array_name + + @property + def irq_vector_array_name(self): + return self.__irq_vector_array_name + @property def int_bits(self): return self.__int_bits @@ -233,289 +248,6 @@ def check_64b(self): return self.check_sym("CONFIG_64BIT") -class gen_isr_parser: - source_header = """ -/* AUTO-GENERATED by gen_isr_tables.py, do not edit! */ - -#include -#include -#include -#include - -typedef void (* ISR)(const void *); -""" - - source_assembly_header = """ -#ifndef ARCH_IRQ_VECTOR_JUMP_CODE -#error "ARCH_IRQ_VECTOR_JUMP_CODE not defined" -#endif -""" - - def __init__(self, intlist_data, config, log): - """Initialize the parser. - - The function prepares parser to work. - Parameters: - - intlist_data: The binnary data from intlist section - - config: The configuration object - - log: The logging object, has to have error and debug methods - """ - self.__config = config - self.__log = log - intlist = self.__read_intlist(intlist_data) - self.__vt, self.__swt, self.__nv = self.__parse_intlist(intlist) - - def __read_intlist(self, intlist_data): - """read a binary file containing the contents of the kernel's .intList - section. This is an instance of a header created by - include/zephyr/linker/intlist.ld: - - struct { - uint32_t num_vectors; <- typically CONFIG_NUM_IRQS - struct _isr_list isrs[]; <- Usually of smaller size than num_vectors - } - - Followed by instances of struct _isr_list created by IRQ_CONNECT() - calls: - - struct _isr_list { - /** IRQ line number */ - int32_t irq; - /** Flags for this IRQ, see ISR_FLAG_* definitions */ - int32_t flags; - /** ISR to call */ - void *func; - /** Parameter for non-direct IRQs */ - const void *param; - }; - """ - intlist = {} - prefix = self.__config.endian_prefix() - - # Extract header and the rest of the data - intlist_header_fmt = prefix + "II" - header_sz = struct.calcsize(intlist_header_fmt) - header_raw = struct.unpack_from(intlist_header_fmt, intlist_data, 0) - self.__log.debug(str(header_raw)) - - intlist["num_vectors"] = header_raw[0] - intlist["offset"] = header_raw[1] - intdata = intlist_data[header_sz:] - - # Extract information about interrupts - if self.__config.check_64b(): - intlist_entry_fmt = prefix + "iiQQ" - else: - intlist_entry_fmt = prefix + "iiII" - - intlist["interrupts"] = [i for i in - struct.iter_unpack(intlist_entry_fmt, intdata)] - - self.__log.debug("Configured interrupt routing") - self.__log.debug("handler irq flags param") - self.__log.debug("--------------------------") - - for irq in intlist["interrupts"]: - self.__log.debug("{0:<10} {1:<3} {2:<3} {3}".format( - hex(irq[2]), irq[0], irq[1], hex(irq[3]))) - - return intlist - - def __parse_intlist(self, intlist): - """All the intlist data are parsed into swt and vt arrays. - - The vt array is prepared for hardware interrupt table. - Every entry in the selected position would contain None or the name of the function pointer - (address or string). - - The swt is a little more complex. At every position it would contain an array of parameter and - function pointer pairs. If CONFIG_SHARED_INTERRUPTS is enabled there may be more than 1 entry. - If empty array is placed on selected position - it means that the application does not implement - this interrupt. - - Parameters: - - intlist: The preprocessed list of intlist section content (see read_intlist) - - Return: - vt, swt - parsed vt and swt arrays (see function description above) - """ - nvec = intlist["num_vectors"] - offset = intlist["offset"] - - if nvec > pow(2, 15): - raise ValueError('nvec is too large, check endianness.') - - self.__log.debug('offset is ' + str(offset)) - self.__log.debug('num_vectors is ' + str(nvec)) - - # Set default entries in both tables - if not(self.__config.args.sw_isr_table or self.__config.args.vector_table): - self.__log.error("one or both of -s or -V needs to be specified on command line") - if self.__config.args.vector_table: - vt = [None for i in range(nvec)] - else: - vt = None - if self.__config.args.sw_isr_table: - swt = [[] for i in range(nvec)] - else: - swt = None - - # Process intlist and write to the tables created - for irq, flags, func, param in intlist["interrupts"]: - if not vt: - error("Direct Interrupt %d declared with parameter 0x%x " - "but no vector table in use" - % (irq, param)) - if self.__config.test_isr_direct(flags): - if param != 0: - self.__log.error("Direct irq %d declared, but has non-NULL parameter" - % irq) - if not 0 <= irq - offset < len(vt): - self.__log.error("IRQ %d (offset=%d) exceeds the maximum of %d" % - (irq - offset, offset, len(vt) - 1)) - vt[irq - offset] = func - else: - # Regular interrupt - if not swt: - self.__log.error("Regular Interrupt %d declared with parameter 0x%x " - "but no SW ISR_TABLE in use" - % (irq, param)) - - table_index = self.__config.get_swt_table_index(offset, irq) - - if not 0 <= table_index < len(swt): - self.__log.error("IRQ %d (offset=%d) exceeds the maximum of %d" % - (table_index, offset, len(swt) - 1)) - if self.__config.check_shared_interrupts(): - lst = swt[table_index] - if (param, func) in lst: - self.__log.error("Attempting to register the same ISR/arg pair twice.") - if len(lst) >= self.__config.get_sym("CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS"): - self.__log.error(f"Reached shared interrupt client limit. Maybe increase" - + f" CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS?") - else: - if len(swt[table_index]) > 0: - self.__log.error(f"multiple registrations at table_index {table_index} for irq {irq} (0x{irq:x})" - + f"\nExisting handler 0x{swt[table_index][0][1]:x}, new handler 0x{func:x}" - + "\nHas IRQ_CONNECT or IRQ_DIRECT_CONNECT accidentally been invoked on the same irq multiple times?" - ) - swt[table_index].append((param, func)) - - return vt, swt, nvec - - def __write_code_irq_vector_table(self, fp): - fp.write(self.source_assembly_header) - - fp.write("void __irq_vector_table __attribute__((naked)) _irq_vector_table(void) {\n") - for i in range(self.__nv): - func = self.__vt[i] - - if func is None: - func = self.__config.vt_default_handler - - if isinstance(func, int): - func_as_string = self.__config.get_sym_from_addr(func) - else: - func_as_string = func - - fp.write("\t__asm(ARCH_IRQ_VECTOR_JUMP_CODE({}));\n".format(func_as_string)) - fp.write("}\n") - - def __write_address_irq_vector_table(self, fp): - fp.write("uintptr_t __irq_vector_table _irq_vector_table[%d] = {\n" % self.__nv) - for i in range(self.__nv): - func = self.__vt[i] - - if func is None: - func = self.__config.vt_default_handler - - if isinstance(func, int): - fp.write("\t{},\n".format(func)) - else: - fp.write("\t((uintptr_t)&{}),\n".format(func)) - - fp.write("};\n") - - def __write_shared_table(self, fp): - fp.write("struct z_shared_isr_table_entry __shared_sw_isr_table" - " z_shared_sw_isr_table[%d] = {\n" % self.__nv) - - for i in range(self.__nv): - if self.__swt[i] is None: - client_num = 0 - client_list = None - else: - client_num = len(self.__swt[i]) - client_list = self.__swt[i] - - if client_num <= 1: - fp.write("\t{ },\n") - else: - fp.write(f"\t{{ .client_num = {client_num}, .clients = {{ ") - for j in range(0, client_num): - routine = client_list[j][1] - arg = client_list[j][0] - - fp.write(f"{{ .isr = (ISR){ hex(routine) if isinstance(routine, int) else routine }, " - f".arg = (const void *){hex(arg)} }},") - - fp.write(" },\n},\n") - - fp.write("};\n") - - def write_source(self, fp): - fp.write(self.source_header) - - if self.__config.check_shared_interrupts(): - self.__write_shared_table(fp) - - if self.__vt: - if self.__config.check_sym("CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS"): - self.__write_address_irq_vector_table(fp) - elif self.__config.check_sym("CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_CODE"): - self.__write_code_irq_vector_table(fp) - else: - self.__log.error("CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_{ADDRESS,CODE} not set") - - if not self.__swt: - return - - fp.write("struct _isr_table_entry __sw_isr_table _sw_isr_table[%d] = {\n" - % self.__nv) - - level2_offset = self.__config.get_irq_baseoffset(2) - level3_offset = self.__config.get_irq_baseoffset(3) - - for i in range(self.__nv): - if len(self.__swt[i]) == 0: - # Not used interrupt - param = "0x0" - func = self.__config.swt_spurious_handler - elif len(self.__swt[i]) == 1: - # Single interrupt - param = "{0:#x}".format(self.__swt[i][0][0]) - func = self.__swt[i][0][1] - else: - # Shared interrupt - param = "&z_shared_sw_isr_table[{0}]".format(i) - func = self.__config.swt_shared_handler - - if isinstance(func, int): - func_as_string = "{0:#x}".format(func) - else: - func_as_string = func - - if level2_offset is not None and i == level2_offset: - fp.write("\t/* Level 2 interrupts start here (offset: {}) */\n". - format(level2_offset)) - if level3_offset is not None and i == level3_offset: - fp.write("\t/* Level 3 interrupts start here (offset: {}) */\n". - format(level3_offset)) - - fp.write("\t{{(const void *){0}, (ISR){1}}}, /* {2} */\n".format(param, func_as_string, i)) - fp.write("};\n") - - def get_symbols(obj): for section in obj.iter_sections(): if isinstance(section, SymbolTableSection): @@ -554,6 +286,12 @@ def parse_args(): help="Print additional debugging information") parser.add_argument("-o", "--output-source", required=True, help="Output source file") + parser.add_argument("-l", "--linker-output-files", + nargs=2, + metavar=("vector_table_link", "software_interrupt_link"), + help="Output linker files. " + "Used only if CONFIG_ISR_TABLES_LOCAL_DECLARATION is enabled. " + "In other case empty file would be generated.") parser.add_argument("-k", "--kernel", required=True, help="Zephyr kernel image") parser.add_argument("-s", "--sw-isr-table", action="store_true", @@ -576,11 +314,31 @@ def main(): config = gen_isr_config(args, get_symbols(kernel), log) intlist_data = read_intList_sect(kernel, config.get_intlist_snames()) - parser = gen_isr_parser(intlist_data, config, log) + if config.check_sym("CONFIG_ISR_TABLES_LOCAL_DECLARATION"): + sys.stdout.write( + "Warning: The EXPERIMENTAL ISR_TABLES_LOCAL_DECLARATION feature selected\n") + parser_module = importlib.import_module('gen_isr_tables_parser_local') + parser = parser_module.gen_isr_parser(intlist_data, config, log) + else: + parser_module = importlib.import_module('gen_isr_tables_parser_carrays') + parser = parser_module.gen_isr_parser(intlist_data, config, log) with open(args.output_source, "w") as fp: parser.write_source(fp) + if args.linker_output_files is not None: + with open(args.linker_output_files[0], "w") as fp_vt, \ + open(args.linker_output_files[1], "w") as fp_swi: + if hasattr(parser, 'write_linker_vt'): + parser.write_linker_vt(fp_vt) + else: + log.debug("Chosen parser does not support vector table linker file") + fp_vt.write('/* Empty */\n') + if hasattr(parser, 'write_linker_swi'): + parser.write_linker_swi(fp_swi) + else: + log.debug("Chosen parser does not support software interrupt linker file") + fp_swi.write('/* Empty */\n') if __name__ == "__main__": main() diff --git a/scripts/build/gen_isr_tables_parser_carrays.py b/scripts/build/gen_isr_tables_parser_carrays.py new file mode 100644 index 00000000000..e13ef19c1f8 --- /dev/null +++ b/scripts/build/gen_isr_tables_parser_carrays.py @@ -0,0 +1,292 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2017 Intel Corporation +# Copyright (c) 2018 Foundries.io +# Copyright (c) 2023 Nordic Semiconductor NA +# +# SPDX-License-Identifier: Apache-2.0 +# + +import struct + +class gen_isr_parser: + source_header = """ +/* AUTO-GENERATED by gen_isr_tables.py, do not edit! */ + +#include +#include +#include +#include + +typedef void (* ISR)(const void *); +""" + + source_assembly_header = """ +#ifndef ARCH_IRQ_VECTOR_JUMP_CODE +#error "ARCH_IRQ_VECTOR_JUMP_CODE not defined" +#endif +""" + + def __init__(self, intlist_data, config, log): + """Initialize the parser. + + The function prepares parser to work. + Parameters: + - intlist_data: The binnary data from intlist section + - config: The configuration object + - log: The logging object, has to have error and debug methods + """ + self.__config = config + self.__log = log + intlist = self.__read_intlist(intlist_data) + self.__vt, self.__swt, self.__nv = self.__parse_intlist(intlist) + + def __read_intlist(self, intlist_data): + """read a binary file containing the contents of the kernel's .intList + section. This is an instance of a header created by + include/zephyr/linker/intlist.ld: + + struct { + uint32_t num_vectors; <- typically CONFIG_NUM_IRQS + struct _isr_list isrs[]; <- Usually of smaller size than num_vectors + } + + Followed by instances of struct _isr_list created by IRQ_CONNECT() + calls: + + struct _isr_list { + /** IRQ line number */ + int32_t irq; + /** Flags for this IRQ, see ISR_FLAG_* definitions */ + int32_t flags; + /** ISR to call */ + void *func; + /** Parameter for non-direct IRQs */ + const void *param; + }; + """ + intlist = {} + prefix = self.__config.endian_prefix() + + # Extract header and the rest of the data + intlist_header_fmt = prefix + "II" + header_sz = struct.calcsize(intlist_header_fmt) + header_raw = struct.unpack_from(intlist_header_fmt, intlist_data, 0) + self.__log.debug(str(header_raw)) + + intlist["num_vectors"] = header_raw[0] + intlist["offset"] = header_raw[1] + intdata = intlist_data[header_sz:] + + # Extract information about interrupts + if self.__config.check_64b(): + intlist_entry_fmt = prefix + "iiQQ" + else: + intlist_entry_fmt = prefix + "iiII" + + intlist["interrupts"] = [i for i in + struct.iter_unpack(intlist_entry_fmt, intdata)] + + self.__log.debug("Configured interrupt routing") + self.__log.debug("handler irq flags param") + self.__log.debug("--------------------------") + + for irq in intlist["interrupts"]: + self.__log.debug("{0:<10} {1:<3} {2:<3} {3}".format( + hex(irq[2]), irq[0], irq[1], hex(irq[3]))) + + return intlist + + def __parse_intlist(self, intlist): + """All the intlist data are parsed into swt and vt arrays. + + The vt array is prepared for hardware interrupt table. + Every entry in the selected position would contain None or the name of the function pointer + (address or string). + + The swt is a little more complex. At every position it would contain an array of parameter and + function pointer pairs. If CONFIG_SHARED_INTERRUPTS is enabled there may be more than 1 entry. + If empty array is placed on selected position - it means that the application does not implement + this interrupt. + + Parameters: + - intlist: The preprocessed list of intlist section content (see read_intlist) + + Return: + vt, swt - parsed vt and swt arrays (see function description above) + """ + nvec = intlist["num_vectors"] + offset = intlist["offset"] + + if nvec > pow(2, 15): + raise ValueError('nvec is too large, check endianness.') + + self.__log.debug('offset is ' + str(offset)) + self.__log.debug('num_vectors is ' + str(nvec)) + + # Set default entries in both tables + if not(self.__config.args.sw_isr_table or self.__config.args.vector_table): + self.__log.error("one or both of -s or -V needs to be specified on command line") + if self.__config.args.vector_table: + vt = [None for i in range(nvec)] + else: + vt = None + if self.__config.args.sw_isr_table: + swt = [[] for i in range(nvec)] + else: + swt = None + + # Process intlist and write to the tables created + for irq, flags, func, param in intlist["interrupts"]: + if self.__config.test_isr_direct(flags): + if not vt: + self.__log.error("Direct Interrupt %d declared with parameter 0x%x " + "but no vector table in use" + % (irq, param)) + if param != 0: + self.__log.error("Direct irq %d declared, but has non-NULL parameter" + % irq) + if not 0 <= irq - offset < len(vt): + self.__log.error("IRQ %d (offset=%d) exceeds the maximum of %d" + % (irq - offset, offset, len(vt) - 1)) + vt[irq - offset] = func + else: + # Regular interrupt + if not swt: + self.__log.error("Regular Interrupt %d declared with parameter 0x%x " + "but no SW ISR_TABLE in use" + % (irq, param)) + + table_index = self.__config.get_swt_table_index(offset, irq) + + if not 0 <= table_index < len(swt): + self.__log.error("IRQ %d (offset=%d) exceeds the maximum of %d" % + (table_index, offset, len(swt) - 1)) + if self.__config.check_shared_interrupts(): + lst = swt[table_index] + if (param, func) in lst: + self.__log.error("Attempting to register the same ISR/arg pair twice.") + if len(lst) >= self.__config.get_sym("CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS"): + self.__log.error(f"Reached shared interrupt client limit. Maybe increase" + + f" CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS?") + else: + if len(swt[table_index]) > 0: + self.__log.error(f"multiple registrations at table_index {table_index} for irq {irq} (0x{irq:x})" + + f"\nExisting handler 0x{swt[table_index][0][1]:x}, new handler 0x{func:x}" + + "\nHas IRQ_CONNECT or IRQ_DIRECT_CONNECT accidentally been invoked on the same irq multiple times?" + ) + swt[table_index].append((param, func)) + + return vt, swt, nvec + + def __write_code_irq_vector_table(self, fp): + fp.write(self.source_assembly_header) + + fp.write("void __irq_vector_table __attribute__((naked)) _irq_vector_table(void) {\n") + for i in range(self.__nv): + func = self.__vt[i] + + if func is None: + func = self.__config.vt_default_handler + + if isinstance(func, int): + func_as_string = self.__config.get_sym_from_addr(func) + else: + func_as_string = func + + fp.write("\t__asm(ARCH_IRQ_VECTOR_JUMP_CODE({}));\n".format(func_as_string)) + fp.write("}\n") + + def __write_address_irq_vector_table(self, fp): + fp.write("uintptr_t __irq_vector_table _irq_vector_table[%d] = {\n" % self.__nv) + for i in range(self.__nv): + func = self.__vt[i] + + if func is None: + func = self.__config.vt_default_handler + + if isinstance(func, int): + fp.write("\t{},\n".format(func)) + else: + fp.write("\t((uintptr_t)&{}),\n".format(func)) + + fp.write("};\n") + + def __write_shared_table(self, fp): + fp.write("struct z_shared_isr_table_entry __shared_sw_isr_table" + " z_shared_sw_isr_table[%d] = {\n" % self.__nv) + + for i in range(self.__nv): + if self.__swt[i] is None: + client_num = 0 + client_list = None + else: + client_num = len(self.__swt[i]) + client_list = self.__swt[i] + + if client_num <= 1: + fp.write("\t{ },\n") + else: + fp.write(f"\t{{ .client_num = {client_num}, .clients = {{ ") + for j in range(0, client_num): + routine = client_list[j][1] + arg = client_list[j][0] + + fp.write(f"{{ .isr = (ISR){ hex(routine) if isinstance(routine, int) else routine }, " + f".arg = (const void *){hex(arg)} }},") + + fp.write(" },\n},\n") + + fp.write("};\n") + + def write_source(self, fp): + fp.write(self.source_header) + + if self.__config.check_shared_interrupts(): + self.__write_shared_table(fp) + + if self.__vt: + if self.__config.check_sym("CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS"): + self.__write_address_irq_vector_table(fp) + elif self.__config.check_sym("CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_CODE"): + self.__write_code_irq_vector_table(fp) + else: + self.__log.error("CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_{ADDRESS,CODE} not set") + + if not self.__swt: + return + + fp.write("struct _isr_table_entry __sw_isr_table _sw_isr_table[%d] = {\n" + % self.__nv) + + level2_offset = self.__config.get_irq_baseoffset(2) + level3_offset = self.__config.get_irq_baseoffset(3) + + for i in range(self.__nv): + if len(self.__swt[i]) == 0: + # Not used interrupt + param = "0x0" + func = self.__config.swt_spurious_handler + elif len(self.__swt[i]) == 1: + # Single interrupt + param = "{0:#x}".format(self.__swt[i][0][0]) + func = self.__swt[i][0][1] + else: + # Shared interrupt + param = "&z_shared_sw_isr_table[{0}]".format(i) + func = self.__config.swt_shared_handler + + if isinstance(func, int): + func_as_string = "{0:#x}".format(func) + else: + func_as_string = func + + if level2_offset is not None and i == level2_offset: + fp.write("\t/* Level 2 interrupts start here (offset: {}) */\n". + format(level2_offset)) + if level3_offset is not None and i == level3_offset: + fp.write("\t/* Level 3 interrupts start here (offset: {}) */\n". + format(level3_offset)) + + fp.write("\t{{(const void *){0}, (ISR){1}}}, /* {2} */\n".format(param, func_as_string, i)) + fp.write("};\n") diff --git a/scripts/build/gen_isr_tables_parser_local.py b/scripts/build/gen_isr_tables_parser_local.py new file mode 100644 index 00000000000..91bd4a65471 --- /dev/null +++ b/scripts/build/gen_isr_tables_parser_local.py @@ -0,0 +1,375 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2017 Intel Corporation +# Copyright (c) 2018 Foundries.io +# Copyright (c) 2023 Nordic Semiconductor NA +# +# SPDX-License-Identifier: Apache-2.0 +# + +import struct + +class gen_isr_parser: + source_header = """ +/* AUTO-GENERATED by gen_isr_tables.py, do not edit! */ + +#include +#include +#include +#include + +""" + + shared_isr_table_header = """ + +/* For this parser to work, we have to be sure that shared interrupts table entry + * and the normal isr table entry have exactly the same layout + */ +BUILD_ASSERT(sizeof(struct _isr_table_entry) + == + sizeof(struct z_shared_isr_table_entry), + "Shared ISR and ISR table entries layout do not match"); +BUILD_ASSERT(offsetof(struct _isr_table_entry, arg) + == + offsetof(struct z_shared_isr_table_entry, arg), + "Shared ISR and ISR table entries layout do not match"); +BUILD_ASSERT(offsetof(struct _isr_table_entry, isr) + == + offsetof(struct z_shared_isr_table_entry, isr), + "Shared ISR and ISR table entries layout do not match"); + +""" + + def __init__(self, intlist_data, config, log): + """Initialize the parser. + + The function prepares parser to work. + Parameters: + - intlist_data: The binnary data from intlist section + - config: The configuration object + - log: The logging object, has to have error and debug methods + """ + self.__config = config + self.__log = log + intlist = self.__read_intlist(intlist_data) + self.__vt, self.__swt, self.__nv, header = self.__parse_intlist(intlist) + self.__swi_table_entry_size = header["swi_table_entry_size"] + self.__shared_isr_table_entry_size = header["shared_isr_table_entry_size"] + self.__shared_isr_client_num_offset = header["shared_isr_client_num_offset"] + + def __read_intlist(self, intlist_data): + """read an intList section from the elf file. + This is version 2 of a header created by include/zephyr/linker/intlist.ld: + + struct { + uint32_t num_vectors; <- typically CONFIG_NUM_IRQS + uint8_t stream[]; <- the stream with the interrupt data + }; + + The stream is contained from variable length records in a form: + + struct _isr_list_sname { + /** IRQ line number */ + int32_t irq; + /** Flags for this IRQ, see ISR_FLAG_* definitions */ + int32_t flags; + /** The section name */ + const char sname[]; + }; + + The flexible array member here (sname) contains the name of the section where the structure + with interrupt data is located. + It is always Null-terminated string thus we have to search through the input data for the + structure end. + + """ + intlist = {} + prefix = self.__config.endian_prefix() + + # Extract header and the rest of the data + intlist_header_fmt = prefix + "IIIII" + header_sz = struct.calcsize(intlist_header_fmt) + header_raw = struct.unpack_from(intlist_header_fmt, intlist_data, 0) + self.__log.debug(str(header_raw)) + + intlist["num_vectors"] = header_raw[0] + intlist["offset"] = header_raw[1] + intlist["swi_table_entry_size"] = header_raw[2] + intlist["shared_isr_table_entry_size"] = header_raw[3] + intlist["shared_isr_client_num_offset"] = header_raw[4] + + intdata = intlist_data[header_sz:] + + # Extract information about interrupts + intlist_entry_fmt = prefix + "ii" + entry_sz = struct.calcsize(intlist_entry_fmt) + intlist["interrupts"] = [] + + while len(intdata) > entry_sz: + entry_raw = struct.unpack_from(intlist_entry_fmt, intdata, 0) + intdata = intdata[entry_sz:] + null_idx = intdata.find(0) + if null_idx < 0: + self.__log.error("Cannot find sname null termination at IRQ{}".format(entry_raw[0])) + bname = intdata[:null_idx] + # Next structure starts with 4B alignment + next_idx = null_idx + 1 + next_idx = (next_idx + 3) & ~3 + intdata = intdata[next_idx:] + sname = bname.decode() + intlist["interrupts"].append([entry_raw[0], entry_raw[1], sname]) + self.__log.debug("Unpacked IRQ{}, flags: {}, sname: \"{}\"\n".format( + entry_raw[0], entry_raw[1], sname)) + + # If any data left at the end - it has to be all the way 0 - this is just a check + if (len(intdata) and not all([d == 0 for d in intdata])): + self.__log.error("Non-zero data found at the end of the intList data.\n") + + self.__log.debug("Configured interrupt routing with linker") + self.__log.debug("irq flags sname") + self.__log.debug("--------------------------") + + for irq in intlist["interrupts"]: + self.__log.debug("{0:<3} {1:<5} {2}".format( + hex(irq[0]), irq[1], irq[2])) + + return intlist + + def __parse_intlist(self, intlist): + """All the intlist data are parsed into swt and vt arrays. + + The vt array is prepared for hardware interrupt table. + Every entry in the selected position would contain None or the name of the function pointer + (address or string). + + The swt is a little more complex. At every position it would contain an array of parameter and + function pointer pairs. If CONFIG_SHARED_INTERRUPTS is enabled there may be more than 1 entry. + If empty array is placed on selected position - it means that the application does not implement + this interrupt. + + Parameters: + - intlist: The preprocessed list of intlist section content (see read_intlist) + + Return: + vt, swt - parsed vt and swt arrays (see function description above) + """ + nvec = intlist["num_vectors"] + offset = intlist["offset"] + header = { + "swi_table_entry_size": intlist["swi_table_entry_size"], + "shared_isr_table_entry_size": intlist["shared_isr_table_entry_size"], + "shared_isr_client_num_offset": intlist["shared_isr_client_num_offset"] + } + + if nvec > pow(2, 15): + raise ValueError('nvec is too large, check endianness.') + + self.__log.debug('offset is ' + str(offset)) + self.__log.debug('num_vectors is ' + str(nvec)) + + # Set default entries in both tables + if not(self.__config.args.sw_isr_table or self.__config.args.vector_table): + self.__log.error("one or both of -s or -V needs to be specified on command line") + if self.__config.args.vector_table: + vt = [None for i in range(nvec)] + else: + vt = None + if self.__config.args.sw_isr_table: + swt = [[] for i in range(nvec)] + else: + swt = None + + # Process intlist and write to the tables created + for irq, flags, sname in intlist["interrupts"]: + if self.__config.test_isr_direct(flags): + if not 0 <= irq - offset < len(vt): + self.__log.error("IRQ %d (offset=%d) exceeds the maximum of %d" % + (irq - offset, offset, len(vt) - 1)) + vt[irq - offset] = sname + else: + # Regular interrupt + if not swt: + self.__log.error("Regular Interrupt %d declared with section name %s " + "but no SW ISR_TABLE in use" + % (irq, sname)) + + table_index = self.__config.get_swt_table_index(offset, irq) + + if not 0 <= table_index < len(swt): + self.__log.error("IRQ %d (offset=%d) exceeds the maximum of %d" % + (table_index, offset, len(swt) - 1)) + # Check if the given section name does not repeat outside of current interrupt + for i in range(nvec): + if i == irq: + continue + if sname in swt[i]: + self.__log.error(("Attempting to register the same section name \"{}\"for" + + "different interrupts: {} and {}").format(sname, i, irq)) + if self.__config.check_shared_interrupts(): + lst = swt[table_index] + if len(lst) >= self.__config.get_sym("CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS"): + self.__log.error(f"Reached shared interrupt client limit. Maybe increase" + + f" CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS?") + else: + if len(swt[table_index]) > 0: + self.__log.error(f"multiple registrations at table_index {table_index} for irq {irq} (0x{irq:x})" + + f"\nExisting section {swt[table_index]}, new section {sname}" + + "\nHas IRQ_CONNECT or IRQ_DIRECT_CONNECT accidentally been invoked on the same irq multiple times?" + ) + swt[table_index].append(sname) + + return vt, swt, nvec, header + + @staticmethod + def __irq_spurious_section(irq): + return '.irq_spurious.0x{:x}'.format(irq) + + @staticmethod + def __isr_generated_section(irq): + return '.isr_generated.0x{:x}'.format(irq) + + @staticmethod + def __shared_entry_section(irq, ent): + return '.isr_shared.0x{:x}_0x{:x}'.format(irq, ent) + + @staticmethod + def __shared_client_num_section(irq): + return '.isr_shared.0x{:x}_client_num'.format(irq) + + def __isr_spurious_entry(self, irq): + return '_Z_ISR_TABLE_ENTRY({irq}, {func}, NULL, "{sect}");'.format( + irq = irq, + func = self.__config.swt_spurious_handler, + sect = self.__isr_generated_section(irq) + ) + + def __isr_shared_entry(self, irq): + return '_Z_ISR_TABLE_ENTRY({irq}, {func}, {arg}, "{sect}");'.format( + irq = irq, + arg = '&{}[{}]'.format(self.__config.shared_array_name, irq), + func = self.__config.swt_shared_handler, + sect = self.__isr_generated_section(irq) + ) + + def __irq_spurious_entry(self, irq): + return '_Z_ISR_DIRECT_TABLE_ENTRY({irq}, {func}, "{sect}");'.format( + irq = irq, + func = self.__config.vt_default_handler, + sect = self.__irq_spurious_section(irq) + ) + + def __write_isr_handlers(self, fp): + for i in range(self.__nv): + if len(self.__swt[i]) <= 0: + fp.write(self.__isr_spurious_entry(i) + '\n') + elif len(self.__swt[i]) > 1: + # Connect to shared handlers + fp.write(self.__isr_shared_entry(i) + '\n') + else: + fp.write('/* ISR: {} implemented in app in "{}" section. */\n'.format( + i, self.__swt[i][0])) + + def __write_irq_handlers(self, fp): + for i in range(self.__nv): + if self.__vt[i] is None: + fp.write(self.__irq_spurious_entry(i) + '\n') + else: + fp.write('/* ISR: {} implemented in app. */\n'.format(i)) + + def __write_shared_handlers(self, fp): + fp.write("extern struct z_shared_isr_table_entry " + "{}[{}];\n".format(self.__config.shared_array_name, self.__nv)) + + shared_cnt = self.__config.get_sym('CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS') + for i in range(self.__nv): + swt_len = len(self.__swt[i]) + for j in range(shared_cnt): + if (swt_len <= 1) or (swt_len <= j): + # Add all unused entry + fp.write('static Z_DECL_ALIGN(struct _isr_table_entry)\n' + + '\tZ_GENERIC_SECTION({})\n'.format(self.__shared_entry_section(i, j)) + + '\t__used isr_shared_empty_entry_0x{:x}_0x{:x} = {{\n'.format(i, j) + + '\t\t.arg = (const void *)NULL,\n' + + '\t\t.isr = (void (*)(const void *))(void *)0\n' + + '};\n' + ) + else: + # Add information about entry implemented by application + fp.write('/* Shared isr {} entry {} implemented in "{}" section*/\n'.format( + i, j, self.__swt[i][j])) + + # Add information about clients count + fp.write(('static size_t Z_GENERIC_SECTION({}) __used\n' + + 'isr_shared_client_num_0x{:x} = {};\n\n').format( + self.__shared_client_num_section(i), + i, + 0 if swt_len < 2 else swt_len) + ) + + def write_source(self, fp): + fp.write(self.source_header) + + if self.__vt: + self.__write_irq_handlers(fp) + + if not self.__swt: + return + + if self.__config.check_shared_interrupts(): + self.__write_shared_handlers(fp) + + self.__write_isr_handlers(fp) + + def __write_linker_irq(self, fp): + fp.write('{} = .;\n'.format(self.__config.irq_vector_array_name)) + for i in range(self.__nv): + if self.__vt[i] is None: + sname = self.__irq_spurious_section(i) + else: + sname = self.__vt[i] + fp.write('KEEP(*("{}"))\n'.format(sname)) + + def __write_linker_shared(self, fp): + fp.write(". = ALIGN({});\n".format(self.__shared_isr_table_entry_size)) + fp.write('{} = .;\n'.format(self.__config.shared_array_name)) + shared_cnt = self.__config.get_sym('CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS') + client_num_pads = self.__shared_isr_client_num_offset - \ + shared_cnt * self.__swi_table_entry_size + if client_num_pads < 0: + self.__log.error("Invalid __shared_isr_client_num_offset header value") + for i in range(self.__nv): + swt_len = len(self.__swt[i]) + # Add all entries + for j in range(shared_cnt): + if (swt_len <= 1) or (swt_len <= j): + fp.write('KEEP(*("{}"))\n'.format(self.__shared_entry_section(i, j))) + else: + sname = self.__swt[i][j] + if (j != 0) and (sname in self.__swt[i][0:j]): + fp.write('/* Repetition of "{}" section */\n'.format(sname)) + else: + fp.write('KEEP(*("{}"))\n'.format(sname)) + fp.write('. = . + {};\n'.format(client_num_pads)) + fp.write('KEEP(*("{}"))\n'.format(self.__shared_client_num_section(i))) + fp.write(". = ALIGN({});\n".format(self.__shared_isr_table_entry_size)) + + def __write_linker_isr(self, fp): + fp.write(". = ALIGN({});\n".format(self.__swi_table_entry_size)) + fp.write('{} = .;\n'.format(self.__config.sw_isr_array_name)) + for i in range(self.__nv): + if (len(self.__swt[i])) == 1: + sname = self.__swt[i][0] + else: + sname = self.__isr_generated_section(i) + fp.write('KEEP(*("{}"))\n'.format(sname)) + + def write_linker_vt(self, fp): + if self.__vt: + self.__write_linker_irq(fp) + + def write_linker_swi(self, fp): + if self.__swt: + self.__write_linker_isr(fp) + + if self.__config.check_shared_interrupts(): + self.__write_linker_shared(fp) From 47a5ad2d459a021d02ead1ab2a694dd401dbbd06 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Tue, 17 Oct 2023 17:41:17 +0200 Subject: [PATCH 1526/1623] [nrf fromtree] arch: sw_isr_table: Implement local interrupt table entry creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit implements the possibility to locally create an interrupt table entry. This changes the way interrput table is created, now it should not be created as an source file but rather it would be constructed by the linker. Signed-off-by: Radosław Koppel (cherry picked from commit 13638a03519db634c519a6511b9719f6d6f6b674) --- arch/Kconfig | 23 +++++++ include/zephyr/sw_isr_table.h | 114 ++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 5e3b96f414d..5c0ad5f49d9 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -391,6 +391,29 @@ config NOCACHE_MEMORY menu "Interrupt Configuration" +config ISR_TABLES_LOCAL_DECLARATION_SUPPORTED + bool + default y + # Userspace is currently not supported + depends on !USERSPACE + # List of currently supported architectures + depends on ARM || ARM64 + # List of currently supported toolchains + depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr" || "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "gnuarmemb" + +config ISR_TABLES_LOCAL_DECLARATION + bool "ISR tables created locally and placed by linker [EXPERIMENTAL]" + depends on ISR_TABLES_LOCAL_DECLARATION_SUPPORTED + select EXPERIMENTAL + help + Enable new scheme of interrupt tables generation. + This is totally different generator that would create tables entries locally + where the IRQ_CONNECT macro is called and then use the linker script to position it + in the right place in memory. + The most important advantage of such approach is that the generated interrupt tables + are LTO compatible. + The drawback is that the support on the architecture port is required. + config DYNAMIC_INTERRUPTS bool "Installation of IRQs at runtime" help diff --git a/include/zephyr/sw_isr_table.h b/include/zephyr/sw_isr_table.h index fc094b887ba..7b1bfddb2cb 100644 --- a/include/zephyr/sw_isr_table.h +++ b/include/zephyr/sw_isr_table.h @@ -18,6 +18,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -56,6 +57,9 @@ struct _irq_parent_entry { * uses it to create the IRQ vector table and the _sw_isr_table. * * More discussion in include/linker/intlist.ld + * + * This is a version used when CONFIG_ISR_TABLES_LOCAL_DECLARATION is disabled. + * See _isr_list_sname used otherwise. */ struct _isr_list { /** IRQ line number */ @@ -68,6 +72,24 @@ struct _isr_list { const void *param; }; +/* + * Data structure created in a special binary .intlist section for each + * configured interrupt. gen_isr_tables.py pulls this out of the binary and + * uses it to create linker script chunks that would place interrupt table entries + * in the right place in the memory. + * + * This is a version used when CONFIG_ISR_TABLES_LOCAL_DECLARATION is enabled. + * See _isr_list used otherwise. + */ +struct _isr_list_sname { + /** IRQ line number */ + int32_t irq; + /** Flags for this IRQ, see ISR_FLAG_* definitions */ + int32_t flags; + /** The section name */ + const char sname[]; +}; + #ifdef CONFIG_SHARED_INTERRUPTS struct z_shared_isr_table_entry { struct _isr_table_entry clients[CONFIG_SHARED_IRQ_MAX_NUM_CLIENTS]; @@ -85,6 +107,90 @@ extern struct z_shared_isr_table_entry z_shared_sw_isr_table[]; #define _MK_ISR_NAME(x, y) __MK_ISR_NAME(x, y) #define __MK_ISR_NAME(x, y) __isr_ ## x ## _irq_ ## y + +#if IS_ENABLED(CONFIG_ISR_TABLES_LOCAL_DECLARATION) + +#define _MK_ISR_ELEMENT_NAME(func, id) __MK_ISR_ELEMENT_NAME(func, id) +#define __MK_ISR_ELEMENT_NAME(func, id) __isr_table_entry_ ## func ## _irq_ ## id + +#define _MK_IRQ_ELEMENT_NAME(func, id) __MK_ISR_ELEMENT_NAME(func, id) +#define __MK_IRQ_ELEMENT_NAME(func, id) __irq_table_entry_ ## func ## _irq_ ## id + +#define _MK_ISR_SECTION_NAME(prefix, file, counter) \ + "." Z_STRINGIFY(prefix)"."file"." Z_STRINGIFY(counter) + +#define _MK_ISR_ELEMENT_SECTION(counter) _MK_ISR_SECTION_NAME(irq, __FILE__, counter) +#define _MK_IRQ_ELEMENT_SECTION(counter) _MK_ISR_SECTION_NAME(isr, __FILE__, counter) + +/* Separated macro to create ISR table entry only. + * Used by Z_ISR_DECLARE and ISR tables generation script. + */ +#define _Z_ISR_TABLE_ENTRY(irq, func, param, sect) \ + static Z_DECL_ALIGN(struct _isr_table_entry) \ + __attribute__((section(sect))) \ + __used _MK_ISR_ELEMENT_NAME(func, __COUNTER__) = { \ + .arg = (const void *)(param), \ + .isr = (void (*)(const void *))(void *)(func) \ + } + +#define Z_ISR_DECLARE_C(irq, flags, func, param, counter) \ + _Z_ISR_DECLARE_C(irq, flags, func, param, counter) + +#define _Z_ISR_DECLARE_C(irq, flags, func, param, counter) \ + _Z_ISR_TABLE_ENTRY(irq, func, param, _MK_ISR_ELEMENT_SECTION(counter)); \ + static struct _isr_list_sname Z_GENERIC_SECTION(.intList) \ + __used _MK_ISR_NAME(func, counter) = \ + {irq, flags, _MK_ISR_ELEMENT_SECTION(counter)} + +/* Create an entry for _isr_table to be then placed by the linker. + * An instance of struct _isr_list which gets put in the .intList + * section is created with the name of the section where _isr_table entry is placed to be then + * used by isr generation script to create linker script chunk. + */ +#define Z_ISR_DECLARE(irq, flags, func, param) \ + BUILD_ASSERT(((flags) & ISR_FLAG_DIRECT) == 0, "Use Z_ISR_DECLARE_DIRECT macro"); \ + Z_ISR_DECLARE_C(irq, flags, func, param, __COUNTER__) + + +/* Separated macro to create ISR Direct table entry only. + * Used by Z_ISR_DECLARE_DIRECT and ISR tables generation script. + */ +#define _Z_ISR_DIRECT_TABLE_ENTRY(irq, func, sect) \ + COND_CODE_1(CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS, ( \ + static Z_DECL_ALIGN(uintptr_t) \ + __attribute__((section(sect))) \ + __used _MK_IRQ_ELEMENT_NAME(func, __COUNTER__) = ((uintptr_t)(func)); \ + ), ( \ + static void __attribute__((section(sect))) __attribute__((naked)) \ + __used _MK_IRQ_ELEMENT_NAME(func, __COUNTER__)(void) { \ + __asm(ARCH_IRQ_VECTOR_JUMP_CODE(func)); \ + } \ + )) + +#define Z_ISR_DECLARE_DIRECT_C(irq, flags, func, counter) \ + _Z_ISR_DECLARE_DIRECT_C(irq, flags, func, counter) + +#define _Z_ISR_DECLARE_DIRECT_C(irq, flags, func, counter) \ + _Z_ISR_DIRECT_TABLE_ENTRY(irq, func, _MK_IRQ_ELEMENT_SECTION(counter)); \ + static struct _isr_list_sname Z_GENERIC_SECTION(.intList) \ + __used _MK_ISR_NAME(func, counter) = { \ + irq, \ + ISR_FLAG_DIRECT | (flags), \ + _MK_IRQ_ELEMENT_SECTION(counter)} + +/* Create an entry to irq table and place it in specific section which name is then placed + * in an instance of struct _isr_list to be then used by the isr generation script to create + * the linker script chunks. + */ +#define Z_ISR_DECLARE_DIRECT(irq, flags, func) \ + BUILD_ASSERT(IS_ENABLED(CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS) || \ + IS_ENABLED(CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_CODE), \ + "CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_{ADDRESS,CODE} not set"); \ + Z_ISR_DECLARE_DIRECT_C(irq, flags, func, __COUNTER__) + + +#else /* IS_ENABLED(CONFIG_ISR_TABLES_LOCAL_DECLARATION) */ + /* Create an instance of struct _isr_list which gets put in the .intList * section. This gets consumed by gen_isr_tables.py which creates the vector * and/or SW ISR tables. @@ -94,6 +200,14 @@ extern struct z_shared_isr_table_entry z_shared_sw_isr_table[]; __used _MK_ISR_NAME(func, __COUNTER__) = \ {irq, flags, (void *)&func, (const void *)param} +/* The version of the Z_ISR_DECLARE that should be used for direct ISR declaration. + * It is here for the API match the version with CONFIG_ISR_TABLES_LOCAL_DECLARATION enabled. + */ +#define Z_ISR_DECLARE_DIRECT(irq, flags, func) \ + Z_ISR_DECLARE(irq, ISR_FLAG_DIRECT | (flags), func, NULL) + +#endif + #define IRQ_TABLE_SIZE (CONFIG_NUM_IRQS - CONFIG_GEN_IRQ_START_VECTOR) #ifdef CONFIG_DYNAMIC_INTERRUPTS From f63cccafdc4d3fee81dc80a5f088e90a20f083db Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Thu, 1 Feb 2024 16:34:55 +0100 Subject: [PATCH 1527/1623] [nrf fromtree] doc: kernel: interrupts: Description of the local isr declaration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a documentation about the new parser of the interrupt vectors tables that is using linker to construct the arrays with all the runtime required data. Signed-off-by: Radosław Koppel (cherry picked from commit 19bb21ef6d95a850f598822c7d4a872f8f127a9a) --- doc/kernel/services/interrupts.rst | 120 ++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 3 deletions(-) diff --git a/doc/kernel/services/interrupts.rst b/doc/kernel/services/interrupts.rst index 44f0805edb0..7af101a40d1 100644 --- a/doc/kernel/services/interrupts.rst +++ b/doc/kernel/services/interrupts.rst @@ -457,6 +457,38 @@ Interrupt tables are set up at build time using some special build tools. The details laid out here apply to all architectures except x86, which are covered in the `x86 Details`_ section below. +The invocation of :c:macro:`IRQ_CONNECT` will declare an instance of +struct _isr_list wich is placed in a special .intList section. +This section is placed in compiled code on precompilation stages only. +It is meant to be used by Zephyr script to generate interrupt tables +and is removed from the final build. +The script implements different parsers to process the data from .intList section +and produce the required output. + +The default parser generates C arrays filled with arguments and interrupt +handlers in a form of addresses directly taken from .intList section entries. +It works with all the architectures and compillers (with the exception mentioned above). +The limitation of this parser is the fact that after the arrays are generated +it is expected for the code not to relocate. +Any relocation on this stage may lead to the situation where the entry in the interrupt array +is no longer pointing to the function that was expected. +It means that this parser, being more compatible is limiting us from using Link Time Optimization. + +The local isr declaration parser uses different approach to construct +the same arrays at binnary level. +All the entries to the arrays are declared and defined locally, +directly in the file where :c:macro:`IRQ_CONNECT` is used. +They are placed in a section with the unique, synthetized name. +The name of the section is then placed in .intList section and it is used to create linker script +to properly place the created entry in the right place in the memory. +This parser is now limited to the supported architectures and toolchains but in reward it keeps +the information about object relations for linker thus allowing the Link Time Optimization. + +Implementation using C arrays +----------------------------- + +This is the default configuration available for all Zephyr supported architectures. + Any invocation of :c:macro:`IRQ_CONNECT` will declare an instance of struct _isr_list which is placed in a special .intList section: @@ -500,7 +532,7 @@ do not support the notion of interrupt priority, in which case the priority argument is ignored. Vector Table ------------- +~~~~~~~~~~~~ A vector table is generated when :kconfig:option:`CONFIG_GEN_IRQ_VECTOR_TABLE` is enabled. This data structure is used natively by the CPU and is simply an array of function pointers, where each element n corresponds to the IRQ handler @@ -527,7 +559,7 @@ CONFIG_GEN_IRQ_START_VECTOR needs to be set to properly offset the indices in the table. SW ISR Table ------------- +~~~~~~~~~~~~ This is an array of struct _isr_table_entry: .. code-block:: c @@ -542,7 +574,7 @@ argument and execute it. The active IRQ line is looked up in an interrupt controller register and used to index this table. Shared SW ISR Table -------------------- +~~~~~~~~~~~~~~~~~~~ This is an array of struct z_shared_isr_table_entry: @@ -558,6 +590,88 @@ lines. Whenever an interrupt line becomes shared, c:func:`z_shared_isr` will replace the currently registered ISR in _sw_isr_table. This special ISR will iterate through the list of registered clients and invoke the ISRs. +Implementation using linker script +---------------------------------- + +This way of prepare and parse .isrList section to implement interrupt vectors arrays +is called local isr declaration. +The name comes from the fact that all the entries to the arrays that would create +interrupt vectors are created locally in place of invocation of :c:macro:`IRQ_CONNECT` macro. +Then automatically generated linker scripts are used to place it in the right place in the memory. + +This option requires enabling by the choose of :kconfig:option:`ISR_TABLES_LOCAL_DECLARATION`. +If this configuration is supported by the used architecture and toolchaing the +:kconfig:option:`ISR_TABLES_LOCAL_DECLARATION_SUPPORTED` is set. +See defails of this option for the information about currently supported configurations. + +Any invocation of :c:macro:`IRQ_CONNECT` or `IRQ_DIRECT_CONNECT` will declare an instance of struct +_isr_list_sname which is placde in a special .intList section: + +.. code-block:: c + + struct _isr_list_sname { + /** IRQ line number */ + int32_t irq; + /** Flags for this IRQ, see ISR_FLAG_* definitions */ + int32_t flags; + /** The section name */ + const char sname[]; + }; + +Note that the section name is placed in flexible array member. +It means that the size of the initialized structure will warry depending on the +structure name length. +The whole entry is used by the script during the build of the application +and has all the information needed for proper interrupt placement. + +Beside of the _isr_list_sname the :c:macro:`IRQ_CONNECT` macro generates an entry +that would be the part of the interrupt array: + +.. code-block:: c + + struct _isr_table_entry { + const void *arg; + void (*isr)(const void *); + }; + +This array is placed in a section with the name saved in _isr_list_sname structure. + +The values created by :c:macro:`IRQ_DIRECT_CONNECT` macro depends on the architecture. +It can be changed to variable that points to a interrupt handler: + +.. code-block:: c + + static uintptr_t = ((uintptr_t)func); + +Or to actuall naked function that implements a jump to the interrupt handler: + +.. code-block:: c + + static void (void) + { + __asm(ARCH_IRQ_VECTOR_JUMP_CODE(func)); + } + +Simillar like for :c:macro:`IRQ_CONNECT`, the created variable or function is placed +in a section, saved in _isr_list_sname section. + +Files generated by the script +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The interrupt tables generator script creates 3 files: +isr_tables.c, isr_tables_swi.ld, and isr_tables_vt.ld. + +The isr_tables.c will contain all the structures for interrupts, direct interrupts and +shared interrupts (if enabled). This file implements only all the structures that +are not implemented by the application, leaving a comment where the interrupt +not implemented here can be found. + +Then two linker files are used. The isr_tables_vt.ld file is included in place +where the interrupt vectors are required to be placed in the selected architecture. +The isr_tables_swi.ld file describes the placement of the software interrupt table +elements. The separated file is required as it might be placed in writable on nonwritable +section, depending on the current configuration. + x86 Details ----------- From d700c2ed505fb92826e3447266db0210ccbb4718 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Fri, 22 Dec 2023 14:44:15 +0100 Subject: [PATCH 1528/1623] [nrf fromtree] arch: irq: Use Z_ISR_DECLARE_DIRECT for direct ISR declaration. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit changes the way how ARCH_IRQ_DIRECT_CONNECT is defined. Now it uses Z_ISR_DECLARE_DIRECT internally. That is a requirement for local isr declaration. Signed-off-by: Radosław Koppel (cherry picked from commit 8174c7e049414747ad9077a6da5c608ad0ef61c6) --- include/zephyr/arch/arc/v2/irq.h | 2 +- include/zephyr/arch/arm/irq.h | 2 +- include/zephyr/arch/riscv/irq.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/zephyr/arch/arc/v2/irq.h b/include/zephyr/arch/arc/v2/irq.h index e0b42549597..45b9d138857 100644 --- a/include/zephyr/arch/arc/v2/irq.h +++ b/include/zephyr/arch/arc/v2/irq.h @@ -77,7 +77,7 @@ extern void z_irq_priority_set(unsigned int irq, unsigned int prio, */ #define ARCH_IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p) \ { \ - Z_ISR_DECLARE(irq_p, ISR_FLAG_DIRECT, isr_p, NULL); \ + Z_ISR_DECLARE_DIRECT(irq_p, ISR_FLAG_DIRECT, isr_p); \ BUILD_ASSERT(priority_p || !IS_ENABLED(CONFIG_ARC_FIRQ) || \ (IS_ENABLED(CONFIG_ARC_FIRQ_STACK) && \ !IS_ENABLED(CONFIG_ARC_STACK_CHECKING)), \ diff --git a/include/zephyr/arch/arm/irq.h b/include/zephyr/arch/arm/irq.h index 357c91a83ae..143b8e54179 100644 --- a/include/zephyr/arch/arm/irq.h +++ b/include/zephyr/arch/arm/irq.h @@ -127,7 +127,7 @@ extern void z_arm_interrupt_init(void); BUILD_ASSERT(IS_ENABLED(CONFIG_ZERO_LATENCY_IRQS) || !(flags_p & IRQ_ZERO_LATENCY), \ "ZLI interrupt registered but feature is disabled"); \ _CHECK_PRIO(priority_p, flags_p) \ - Z_ISR_DECLARE(irq_p, ISR_FLAG_DIRECT, isr_p, NULL); \ + Z_ISR_DECLARE_DIRECT(irq_p, ISR_FLAG_DIRECT, isr_p); \ z_arm_irq_priority_set(irq_p, priority_p, flags_p); \ } diff --git a/include/zephyr/arch/riscv/irq.h b/include/zephyr/arch/riscv/irq.h index fa4b3989f05..d067ccfca23 100644 --- a/include/zephyr/arch/riscv/irq.h +++ b/include/zephyr/arch/riscv/irq.h @@ -69,8 +69,8 @@ extern void z_riscv_irq_priority_set(unsigned int irq, #define ARCH_IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p) \ { \ - Z_ISR_DECLARE(irq_p + CONFIG_RISCV_RESERVED_IRQ_ISR_TABLES_OFFSET, \ - ISR_FLAG_DIRECT, isr_p, NULL); \ + Z_ISR_DECLARE_DIRECT(irq_p + CONFIG_RISCV_RESERVED_IRQ_ISR_TABLES_OFFSET, \ + ISR_FLAG_DIRECT, isr_p); \ } #define ARCH_ISR_DIRECT_HEADER() arch_isr_direct_header() From 7c7b018f5a65c10f6184eeee1115ed59c2829108 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Tue, 19 Dec 2023 16:54:18 +0100 Subject: [PATCH 1529/1623] [nrf fromtree] arch: arm: Update to support local ISR declaration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates the arm and arm64 architecture files to support the new ISR handlers creation parser. Signed-off-by: Radosław Koppel (cherry picked from commit 1ff24b34ebe568a5d606928af69914de946b9762) --- arch/arm/core/CMakeLists.txt | 8 ++++++++ arch/arm/core/swi_tables.ld | 8 ++++++++ arch/arm/core/vector_table.ld | 4 ++++ arch/arm64/core/CMakeLists.txt | 8 ++++++++ arch/arm64/core/swi_tables.ld | 8 ++++++++ arch/common/CMakeLists.txt | 5 +++++ include/zephyr/arch/arm64/scripts/linker.ld | 5 ++++- include/zephyr/linker/irq-vector-table-section.ld | 2 ++ include/zephyr/linker/isr-local-drop-unused.ld | 9 +++++++++ 9 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 arch/arm/core/swi_tables.ld create mode 100644 arch/arm64/core/swi_tables.ld create mode 100644 include/zephyr/linker/isr-local-drop-unused.ld diff --git a/arch/arm/core/CMakeLists.txt b/arch/arm/core/CMakeLists.txt index 1b4fa58eae5..680e21fdb59 100644 --- a/arch/arm/core/CMakeLists.txt +++ b/arch/arm/core/CMakeLists.txt @@ -34,3 +34,11 @@ else() zephyr_linker_sources(ROM_START SORT_KEY 0x0vectors vector_table.ld) zephyr_linker_sources(ROM_START SORT_KEY 0x1vectors cortex_m/vector_table_pad.ld) endif() + +if(CONFIG_GEN_SW_ISR_TABLE) + if(CONFIG_DYNAMIC_INTERRUPTS) + zephyr_linker_sources(RWDATA swi_tables.ld) + else() + zephyr_linker_sources(RODATA swi_tables.ld) + endif() +endif() diff --git a/arch/arm/core/swi_tables.ld b/arch/arm/core/swi_tables.ld new file mode 100644 index 00000000000..c6ca94604dd --- /dev/null +++ b/arch/arm/core/swi_tables.ld @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#if LINKER_ZEPHYR_FINAL +INCLUDE zephyr/isr_tables_swi.ld +#endif diff --git a/arch/arm/core/vector_table.ld b/arch/arm/core/vector_table.ld index 615067dbf74..58210afdcbc 100644 --- a/arch/arm/core/vector_table.ld +++ b/arch/arm/core/vector_table.ld @@ -51,6 +51,10 @@ _vector_start = .; KEEP(*(.exc_vector_table)) KEEP(*(".exc_vector_table.*")) +#if LINKER_ZEPHYR_FINAL && CONFIG_ISR_TABLES_LOCAL_DECLARATION +INCLUDE zephyr/isr_tables_vt.ld +#else KEEP(*(.vectors)) +#endif _vector_end = .; diff --git a/arch/arm64/core/CMakeLists.txt b/arch/arm64/core/CMakeLists.txt index 1804556c1a7..05e4be8c0ea 100644 --- a/arch/arm64/core/CMakeLists.txt +++ b/arch/arm64/core/CMakeLists.txt @@ -55,3 +55,11 @@ if(CMAKE_C_COMPILER_ID STREQUAL "GNU") endif() add_subdirectory_ifdef(CONFIG_XEN xen) + +if(CONFIG_GEN_SW_ISR_TABLE) + if(CONFIG_DYNAMIC_INTERRUPTS) + zephyr_linker_sources(RWDATA swi_tables.ld) + else() + zephyr_linker_sources(RODATA swi_tables.ld) + endif() +endif() diff --git a/arch/arm64/core/swi_tables.ld b/arch/arm64/core/swi_tables.ld new file mode 100644 index 00000000000..c6ca94604dd --- /dev/null +++ b/arch/arm64/core/swi_tables.ld @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#if LINKER_ZEPHYR_FINAL +INCLUDE zephyr/isr_tables_swi.ld +#endif diff --git a/arch/common/CMakeLists.txt b/arch/common/CMakeLists.txt index 1a89ba9c13a..409c378f620 100644 --- a/arch/common/CMakeLists.txt +++ b/arch/common/CMakeLists.txt @@ -39,6 +39,11 @@ zephyr_linker_sources_ifdef(CONFIG_GEN_ISR_TABLES ${ZEPHYR_BASE}/include/zephyr/linker/intlist.ld ) +zephyr_linker_sources_ifdef(CONFIG_ISR_TABLES_LOCAL_DECLARATION + SECTIONS + ${ZEPHYR_BASE}/include/zephyr/linker/isr-local-drop-unused.ld +) + zephyr_linker_sources_ifdef(CONFIG_GEN_IRQ_VECTOR_TABLE ROM_START SORT_KEY 0x0vectors diff --git a/include/zephyr/arch/arm64/scripts/linker.ld b/include/zephyr/arch/arm64/scripts/linker.ld index fa08b730304..d2a0d32d581 100644 --- a/include/zephyr/arch/arm64/scripts/linker.ld +++ b/include/zephyr/arch/arm64/scripts/linker.ld @@ -105,8 +105,11 @@ SECTIONS KEEP(*(.exc_vector_table)) KEEP(*(".exc_vector_table.*")) +#if LINKER_ZEPHYR_FINAL && CONFIG_ISR_TABLES_LOCAL_DECLARATION + INCLUDE zephyr/isr_tables_vt.ld +#else KEEP(*(.vectors)) - +#endif _vector_end = .; *(.text) diff --git a/include/zephyr/linker/irq-vector-table-section.ld b/include/zephyr/linker/irq-vector-table-section.ld index 17c483db98f..141eee4d28d 100644 --- a/include/zephyr/linker/irq-vector-table-section.ld +++ b/include/zephyr/linker/irq-vector-table-section.ld @@ -1,7 +1,9 @@ /* SPDX-License-Identifier: Apache-2.0 */ +#if !(LINKER_ZEPHYR_FINAL && CONFIG_ISR_TABLES_LOCAL_DECLARATION) . = ALIGN(CONFIG_ARCH_IRQ_VECTOR_TABLE_ALIGN); KEEP(*(_IRQ_VECTOR_TABLE_SECTION_SYMS)) +#endif /* * Some ARM platforms require this symbol to be placed after the IRQ vector diff --git a/include/zephyr/linker/isr-local-drop-unused.ld b/include/zephyr/linker/isr-local-drop-unused.ld new file mode 100644 index 00000000000..9b6e1272413 --- /dev/null +++ b/include/zephyr/linker/isr-local-drop-unused.ld @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#if LINKER_ZEPHYR_FINAL && CONFIG_ISR_TABLES_LOCAL_DECLARATION +/DISCARD/ : +{ + KEEP(*(.vectors)) + KEEP(*(_IRQ_VECTOR_TABLE_SECTION_SYMS)) +} +#endif From d7c4d9845907dca72bbfd9c1b00a906f655b2145 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Thu, 4 Jan 2024 13:41:27 +0100 Subject: [PATCH 1530/1623] [nrf fromtree] arch: arm: Upgrade IDT_LIST memory section size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make IDT_LIST section bigger to fit bigger interrupt description. Note: This section would be removed from final build. Signed-off-by: Radosław Koppel (cherry picked from commit 664319f9efc933ee0d3cc4e331b95d1bafe3ba58) --- include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld | 2 +- include/zephyr/arch/arm/cortex_m/scripts/linker.ld | 2 +- include/zephyr/arch/arm64/scripts/linker.ld | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld b/include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld index a27dd55a8cf..f8b117e9193 100644 --- a/include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld +++ b/include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld @@ -81,7 +81,7 @@ MEMORY RAM (wx) : ORIGIN = RAM_ADDR, LENGTH = RAM_SIZE LINKER_DT_REGIONS() /* Used by and documented in include/linker/intlist.ld */ - IDT_LIST (wx) : ORIGIN = 0xFFFFF7FF, LENGTH = 2K + IDT_LIST (wx) : ORIGIN = 0xFFFF8000, LENGTH = 32K } ENTRY(CONFIG_KERNEL_ENTRY) diff --git a/include/zephyr/arch/arm/cortex_m/scripts/linker.ld b/include/zephyr/arch/arm/cortex_m/scripts/linker.ld index 5050c778627..cbe4a2781e4 100644 --- a/include/zephyr/arch/arm/cortex_m/scripts/linker.ld +++ b/include/zephyr/arch/arm/cortex_m/scripts/linker.ld @@ -132,7 +132,7 @@ MEMORY #endif LINKER_DT_REGIONS() /* Used by and documented in include/linker/intlist.ld */ - IDT_LIST (wx) : ORIGIN = 0xFFFFF7FF, LENGTH = 2K + IDT_LIST (wx) : ORIGIN = 0xFFFF7FFF, LENGTH = 32K } ENTRY(CONFIG_KERNEL_ENTRY) diff --git a/include/zephyr/arch/arm64/scripts/linker.ld b/include/zephyr/arch/arm64/scripts/linker.ld index d2a0d32d581..beea11a68dd 100644 --- a/include/zephyr/arch/arm64/scripts/linker.ld +++ b/include/zephyr/arch/arm64/scripts/linker.ld @@ -61,7 +61,7 @@ MEMORY FLASH (rx) : ORIGIN = ROM_ADDR, LENGTH = ROM_SIZE RAM (wx) : ORIGIN = RAM_ADDR, LENGTH = RAM_SIZE /* Used by and documented in include/linker/intlist.ld */ - IDT_LIST (wx) : ORIGIN = 0xFFFFF7FF, LENGTH = 2K + IDT_LIST (wx) : ORIGIN = 0xFFFF8000, LENGTH = 32K } ENTRY(CONFIG_KERNEL_ENTRY) From 9af6008b1d86f7188d65a22c3a3109fd96f330ce Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Fri, 22 Dec 2023 14:45:18 +0100 Subject: [PATCH 1531/1623] [nrf fromtree] bluetooth: nordic: lll: Use direct ISR when applicable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates nordic lll controller to use IRQ_DIRECT_CONNECT where applicable instead of using IRQ_CONNECT with ISR_FLAG_DIRECT. Signed-off-by: Radosław Koppel (cherry picked from commit 8f98b8b574bdce4c930a7b2a2e2c78764940b6dd) --- subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index db8f25a374c..cde5f5befc9 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -191,8 +191,13 @@ int lll_init(void) radio_nrf5_isr, IRQ_CONNECT_FLAGS); IRQ_CONNECT(RTC0_IRQn, CONFIG_BT_CTLR_ULL_HIGH_PRIO, rtc0_nrf5_isr, NULL, 0); +#if defined(CONFIG_BT_CTLR_ZLI) + IRQ_DIRECT_CONNECT(HAL_SWI_RADIO_IRQ, CONFIG_BT_CTLR_LLL_PRIO, + swi_lll_nrf5_isr, IRQ_CONNECT_FLAGS); +#else IRQ_CONNECT(HAL_SWI_RADIO_IRQ, CONFIG_BT_CTLR_LLL_PRIO, swi_lll_nrf5_isr, NULL, IRQ_CONNECT_FLAGS); +#endif #if defined(CONFIG_BT_CTLR_LOW_LAT) || \ (CONFIG_BT_CTLR_ULL_HIGH_PRIO != CONFIG_BT_CTLR_ULL_LOW_PRIO) IRQ_CONNECT(HAL_SWI_JOB_IRQ, CONFIG_BT_CTLR_ULL_LOW_PRIO, From 79a403a01ae1711fb7f6c9522c9a00707d49bc2d Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Mon, 8 Jan 2024 14:50:30 +0100 Subject: [PATCH 1532/1623] [nrf fromtree] tests: kernel: gen_isr_table: Add tests for local ISR tables declaration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds configurations to test local ISR tables declaration. Signed-off-by: Radosław Koppel (cherry picked from commit 3799b9368955f0299cd4ab68946b8a548ac9746f) --- tests/kernel/gen_isr_table/testcase.yaml | 27 +++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/kernel/gen_isr_table/testcase.yaml b/tests/kernel/gen_isr_table/testcase.yaml index 4ee3ad00ac9..eb8babe3635 100644 --- a/tests/kernel/gen_isr_table/testcase.yaml +++ b/tests/kernel/gen_isr_table/testcase.yaml @@ -4,12 +4,12 @@ common: - interrupt - isr_table tests: - arch.interrupt.gen_isr_table.arm_baseline: + arch.interrupt.gen_isr_table.arm_baseline: &arm-baseline platform_allow: qemu_cortex_m3 filter: CONFIG_GEN_ISR_TABLES and CONFIG_ARMV6_M_ARMV8_M_BASELINE extra_configs: - CONFIG_NULL_POINTER_EXCEPTION_DETECTION_NONE=y - arch.interrupt.gen_isr_table.arm_baseline.linker_generator: + arch.interrupt.gen_isr_table.arm_baseline.linker_generator: &arm-baseline-linker-generator platform_allow: qemu_cortex_m3 filter: CONFIG_GEN_ISR_TABLES and CONFIG_ARMV6_M_ARMV8_M_BASELINE tags: @@ -17,7 +17,7 @@ tests: extra_configs: - CONFIG_NULL_POINTER_EXCEPTION_DETECTION_NONE=y - CONFIG_CMAKE_LINKER_GENERATOR=y - arch.interrupt.gen_isr_table.arm_mainline: + arch.interrupt.gen_isr_table.arm_mainline: &arm-mainline platform_allow: qemu_cortex_m3 platform_exclude: - stmf103_mini @@ -40,6 +40,27 @@ tests: - CONFIG_GEN_ISR_TABLES=n - CONFIG_NULL_POINTER_EXCEPTION_DETECTION_NONE=y build_only: true + + arch.interrupt.gen_isr_table_local.arm_baseline: + <<: *arm-baseline + filter: CONFIG_GEN_ISR_TABLES and CONFIG_ARMV6_M_ARMV8_M_BASELINE and not CONFIG_USERSPACE + extra_configs: + - CONFIG_NULL_POINTER_EXCEPTION_DETECTION_NONE=y + - CONFIG_ISR_TABLES_LOCAL_DECLARATION=y + arch.interrupt.gen_isr_table_local.arm_baseline.linker_generator: + <<: *arm-baseline-linker-generator + filter: CONFIG_GEN_ISR_TABLES and CONFIG_ARMV6_M_ARMV8_M_BASELINE and not CONFIG_USERSPACE + extra_configs: + - CONFIG_NULL_POINTER_EXCEPTION_DETECTION_NONE=y + - CONFIG_CMAKE_LINKER_GENERATOR=y + - CONFIG_ISR_TABLES_LOCAL_DECLARATION=y + arch.interrupt.gen_isr_table_local.arm_mainline: + <<: *arm-mainline + filter: CONFIG_GEN_ISR_TABLES and CONFIG_ARMV6_M_ARMV8_M_BASELINE and not CONFIG_USERSPACE + extra_configs: + - CONFIG_NULL_POINTER_EXCEPTION_DETECTION_NONE=y + - CONFIG_ISR_TABLES_LOCAL_DECLARATION=y + arch.interrupt.gen_isr_table.arc: arch_allow: arc filter: CONFIG_RGF_NUM_BANKS > 1 From 2989942eec23ab4936350c1777eba64bc9861ff5 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Tue, 30 Jan 2024 12:32:32 +0100 Subject: [PATCH 1533/1623] [nrf fromtree] buildsystem: Add an option to enable LTO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds option to enable Link Time Optimization. Signed-off-by: Radosław Koppel (cherry picked from commit 26c8776c70ea00773f1c9e9947c38ffe8719233c) --- CMakeLists.txt | 9 +++++++++ Kconfig.zephyr | 7 +++++++ cmake/bintools/gnu/target.cmake | 9 +++++++-- cmake/compiler/gcc/compiler_flags.cmake | 3 +++ cmake/linker/ld/linker_flags.cmake | 2 ++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4292e06e211..5bb1774d020 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,6 +213,11 @@ endif() # Apply the final optimization flag(s) zephyr_compile_options(${OPTIMIZATION_FLAG}) +if(CONFIG_LTO) + add_compile_options($) + add_link_options($) +endif() + # @Intent: Obtain compiler specific flags related to C++ that are not influenced by kconfig zephyr_compile_options($<$:$>) @@ -803,6 +808,10 @@ target_include_directories(${OFFSETS_LIB} PRIVATE kernel/include ${ARCH_DIR}/${ARCH}/include ) + +# Make sure that LTO will never be enabled when compiling offsets.c +set_source_files_properties(${OFFSETS_C_PATH} PROPERTIES COMPILE_OPTIONS $) + target_link_libraries(${OFFSETS_LIB} zephyr_interface) add_dependencies(zephyr_interface ${SYSCALL_LIST_H_TARGET} diff --git a/Kconfig.zephyr b/Kconfig.zephyr index c484898206b..848ce58da7e 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -417,6 +417,13 @@ config NO_OPTIMIZATIONS default stack sizes in order to avoid stack overflows. endchoice +config LTO + bool "Link Time Optimization [EXPERIMENTAL]" + depends on !(GEN_ISR_TABLES || GEN_IRQ_VECTOR_TABLE) || ISR_TABLES_LOCAL_DECLARATION + select EXPERIMENTAL + help + This option enables Link Time Optimization. + config COMPILER_WARNINGS_AS_ERRORS bool "Treat warnings as errors" help diff --git a/cmake/bintools/gnu/target.cmake b/cmake/bintools/gnu/target.cmake index 86c66b4825c..612f6de79b2 100644 --- a/cmake/bintools/gnu/target.cmake +++ b/cmake/bintools/gnu/target.cmake @@ -5,8 +5,13 @@ find_program(CMAKE_OBJCOPY ${CROSS_COMPILE}objcopy PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) find_program(CMAKE_OBJDUMP ${CROSS_COMPILE}objdump PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) find_program(CMAKE_AS ${CROSS_COMPILE}as PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) -find_program(CMAKE_AR ${CROSS_COMPILE}ar PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) -find_program(CMAKE_RANLIB ${CROSS_COMPILE}ranlib PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) +if(CONFIG_LTO) + find_program(CMAKE_AR ${CROSS_COMPILE}gcc-ar PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) + find_program(CMAKE_RANLIB ${CROSS_COMPILE}gcc-ranlib PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) +else() + find_program(CMAKE_AR ${CROSS_COMPILE}ar PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) + find_program(CMAKE_RANLIB ${CROSS_COMPILE}ranlib PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) +endif() find_program(CMAKE_READELF ${CROSS_COMPILE}readelf PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) find_program(CMAKE_NM ${CROSS_COMPILE}nm PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) find_program(CMAKE_STRIP ${CROSS_COMPILE}strip PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index 5b1dbde49c6..8e79d32387f 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -21,6 +21,9 @@ endif() set_compiler_property(PROPERTY optimization_speed -O2) set_compiler_property(PROPERTY optimization_size -Os) +set_compiler_property(PROPERTY optimization_lto -flto) +set_compiler_property(PROPERTY prohibit_lto -fno-lto) + ####################################################### # This section covers flags related to warning levels # ####################################################### diff --git a/cmake/linker/ld/linker_flags.cmake b/cmake/linker/ld/linker_flags.cmake index 8209f4dfbdc..5660b410760 100644 --- a/cmake/linker/ld/linker_flags.cmake +++ b/cmake/linker/ld/linker_flags.cmake @@ -12,6 +12,8 @@ endif() set_property(TARGET linker PROPERTY partial_linking "-r") +set_property(TARGET linker PROPERTY lto_arguments -flto -fno-ipa-sra -ffunction-sections -fdata-sections) + # Some linker flags might not be purely ld specific, but a combination of # linker and compiler, such as: # --coverage for clang From 526699525cd894551176dd5739fcffcadf389747 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Tue, 30 Jan 2024 13:15:36 +0100 Subject: [PATCH 1534/1623] [nrf fromtree] tests: kernel: common: Enable tests with LTO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit enables some kernel tests with Link Time Optimization enabled. Signed-off-by: Radosław Koppel (cherry picked from commit 53becb05bfa1d383b0497a0422761fd53e9ead24) --- tests/kernel/common/testcase.yaml | 7 +++++++ tests/kernel/interrupt/testcase.yaml | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/kernel/common/testcase.yaml b/tests/kernel/common/testcase.yaml index 721d4bb9c3d..ae9c39c8fb5 100644 --- a/tests/kernel/common/testcase.yaml +++ b/tests/kernel/common/testcase.yaml @@ -43,3 +43,10 @@ tests: tags: picolibc extra_configs: - CONFIG_PICOLIBC=y + kernel.common.lto: + filter: CONFIG_ISR_TABLES_LOCAL_DECLARATION_SUPPORTED + tags: lto + extra_configs: + - CONFIG_TEST_USERSPACE=n + - CONFIG_ISR_TABLES_LOCAL_DECLARATION=y + - CONFIG_LTO=y diff --git a/tests/kernel/interrupt/testcase.yaml b/tests/kernel/interrupt/testcase.yaml index cbe58c65e47..47cbba93e0d 100644 --- a/tests/kernel/interrupt/testcase.yaml +++ b/tests/kernel/interrupt/testcase.yaml @@ -52,3 +52,23 @@ tests: extra_configs: - CONFIG_SHARED_INTERRUPTS=y filter: not CONFIG_TRUSTED_EXECUTION_NONSECURE + arch.shared_interrupt.lto: + # excluded because of failures during test_prevent_interruption + platform_exclude: qemu_cortex_m0 + arch_exclude: + # same as above, #22956 + - nios2 + # test needs 2 working interrupt lines + - xtensa + # TODO: make test work on this arch + - mips + tags: + - kernel + - interrupt + - lto + extra_configs: + - CONFIG_SHARED_INTERRUPTS=y + - CONFIG_TEST_USERSPACE=n + - CONFIG_ISR_TABLES_LOCAL_DECLARATION=y + - CONFIG_LTO=y + filter: not CONFIG_TRUSTED_EXECUTION_NONSECURE and CONFIG_ISR_TABLES_LOCAL_DECLARATION_SUPPORTED From d80235af2f65498ec3192a6768ea21d6b5f874e1 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Mon, 5 Feb 2024 10:28:06 +0100 Subject: [PATCH 1535/1623] [nrf fromtree] arch: arm, arm64: Disable swi_tables.ld file when not required MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit removes the need of swi_tables.ld file if the ISR table generator is not configured to use it. Signed-off-by: Radosław Koppel (cherry picked from commit adaacefc2032721c510e91d3ac8b50251c95300c) --- arch/arm/core/swi_tables.ld | 2 +- arch/arm/core/vector_table.ld | 2 +- arch/arm64/core/swi_tables.ld | 2 +- include/zephyr/arch/arm64/scripts/linker.ld | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/core/swi_tables.ld b/arch/arm/core/swi_tables.ld index c6ca94604dd..a06e851e52e 100644 --- a/arch/arm/core/swi_tables.ld +++ b/arch/arm/core/swi_tables.ld @@ -3,6 +3,6 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#if LINKER_ZEPHYR_FINAL +#if LINKER_ZEPHYR_FINAL && defined(CONFIG_ISR_TABLES_LOCAL_DECLARATION) INCLUDE zephyr/isr_tables_swi.ld #endif diff --git a/arch/arm/core/vector_table.ld b/arch/arm/core/vector_table.ld index 58210afdcbc..a5af58fe6de 100644 --- a/arch/arm/core/vector_table.ld +++ b/arch/arm/core/vector_table.ld @@ -51,7 +51,7 @@ _vector_start = .; KEEP(*(.exc_vector_table)) KEEP(*(".exc_vector_table.*")) -#if LINKER_ZEPHYR_FINAL && CONFIG_ISR_TABLES_LOCAL_DECLARATION +#if LINKER_ZEPHYR_FINAL && defined(CONFIG_ISR_TABLES_LOCAL_DECLARATION) INCLUDE zephyr/isr_tables_vt.ld #else KEEP(*(.vectors)) diff --git a/arch/arm64/core/swi_tables.ld b/arch/arm64/core/swi_tables.ld index c6ca94604dd..a06e851e52e 100644 --- a/arch/arm64/core/swi_tables.ld +++ b/arch/arm64/core/swi_tables.ld @@ -3,6 +3,6 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#if LINKER_ZEPHYR_FINAL +#if LINKER_ZEPHYR_FINAL && defined(CONFIG_ISR_TABLES_LOCAL_DECLARATION) INCLUDE zephyr/isr_tables_swi.ld #endif diff --git a/include/zephyr/arch/arm64/scripts/linker.ld b/include/zephyr/arch/arm64/scripts/linker.ld index beea11a68dd..18f973e7968 100644 --- a/include/zephyr/arch/arm64/scripts/linker.ld +++ b/include/zephyr/arch/arm64/scripts/linker.ld @@ -105,7 +105,7 @@ SECTIONS KEEP(*(.exc_vector_table)) KEEP(*(".exc_vector_table.*")) -#if LINKER_ZEPHYR_FINAL && CONFIG_ISR_TABLES_LOCAL_DECLARATION +#if LINKER_ZEPHYR_FINAL && defined(CONFIG_ISR_TABLES_LOCAL_DECLARATION) INCLUDE zephyr/isr_tables_vt.ld #else KEEP(*(.vectors)) From efdefefc2bc5b9255576301cb06adfa38f04ebb1 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Mon, 5 Feb 2024 10:59:22 +0100 Subject: [PATCH 1536/1623] [nrf fromtree] arch: arm, arm64: Remove zephyr prefix from linker includes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fix removes the zephyr/ prefix from linker included files. With this prefix the build works only for Ninja and not for other build tools. Linking in Zephyr / CMake: - Ninja invokes linking directly from . - Make invokes linking form /zephyr. The linker default uses cwd for looking up INCLUDE directives if not found in list of includes. Zephyr always adds /zephyr as link include using CMake, and this is passed to ld as -L/zephyr therefore using INCLUDE isr_tables_swi.ld ensures it will be correctly found in all cases. Signed-off-by: Radosław Koppel (cherry picked from commit 08070fbf1f4ca15956a7aef104a131ec5924462c) --- arch/arm/core/swi_tables.ld | 2 +- arch/arm/core/vector_table.ld | 2 +- arch/arm64/core/swi_tables.ld | 2 +- include/zephyr/arch/arm64/scripts/linker.ld | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/core/swi_tables.ld b/arch/arm/core/swi_tables.ld index a06e851e52e..a5dd3eaf652 100644 --- a/arch/arm/core/swi_tables.ld +++ b/arch/arm/core/swi_tables.ld @@ -4,5 +4,5 @@ * SPDX-License-Identifier: Apache-2.0 */ #if LINKER_ZEPHYR_FINAL && defined(CONFIG_ISR_TABLES_LOCAL_DECLARATION) -INCLUDE zephyr/isr_tables_swi.ld +INCLUDE isr_tables_swi.ld #endif diff --git a/arch/arm/core/vector_table.ld b/arch/arm/core/vector_table.ld index a5af58fe6de..463e389de9f 100644 --- a/arch/arm/core/vector_table.ld +++ b/arch/arm/core/vector_table.ld @@ -52,7 +52,7 @@ KEEP(*(.exc_vector_table)) KEEP(*(".exc_vector_table.*")) #if LINKER_ZEPHYR_FINAL && defined(CONFIG_ISR_TABLES_LOCAL_DECLARATION) -INCLUDE zephyr/isr_tables_vt.ld +INCLUDE isr_tables_vt.ld #else KEEP(*(.vectors)) #endif diff --git a/arch/arm64/core/swi_tables.ld b/arch/arm64/core/swi_tables.ld index a06e851e52e..a5dd3eaf652 100644 --- a/arch/arm64/core/swi_tables.ld +++ b/arch/arm64/core/swi_tables.ld @@ -4,5 +4,5 @@ * SPDX-License-Identifier: Apache-2.0 */ #if LINKER_ZEPHYR_FINAL && defined(CONFIG_ISR_TABLES_LOCAL_DECLARATION) -INCLUDE zephyr/isr_tables_swi.ld +INCLUDE isr_tables_swi.ld #endif diff --git a/include/zephyr/arch/arm64/scripts/linker.ld b/include/zephyr/arch/arm64/scripts/linker.ld index 18f973e7968..ad7832f16ec 100644 --- a/include/zephyr/arch/arm64/scripts/linker.ld +++ b/include/zephyr/arch/arm64/scripts/linker.ld @@ -106,7 +106,7 @@ SECTIONS KEEP(*(".exc_vector_table.*")) #if LINKER_ZEPHYR_FINAL && defined(CONFIG_ISR_TABLES_LOCAL_DECLARATION) - INCLUDE zephyr/isr_tables_vt.ld + INCLUDE isr_tables_vt.ld #else KEEP(*(.vectors)) #endif From 460c80b23eb6c63a57c093dc69c9e18356da538b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1537/1623] Revert "[nrf fromlist] soc: nordic_nrf: add missing GRTC Kconfig option" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 88f1d4fca1dbe5b319d8c6eab16835c61778d184. Signed-off-by: Andrzej Głąbek --- soc/common/nordic_nrf/Kconfig.peripherals | 3 --- 1 file changed, 3 deletions(-) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index a6b62428626..8326294f606 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -92,9 +92,6 @@ config HAS_HW_NRF_GPIOTE130 config HAS_HW_NRF_GPIOTE131 def_bool $(dt_nodelabel_enabled_with_compat,gpiote131,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) -config HAS_HW_NRF_GRTC - def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_GRTC)) - config HAS_HW_NRF_I2S0 def_bool $(dt_nodelabel_enabled_with_compat,i2s0,$(DT_COMPAT_NORDIC_NRF_I2S)) From 0d54e2eb54ac4f1648cf0247c767fd1acc456328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1538/1623] Revert "[nrf fromlist] soc: nordic_nrf: add support for WDT131-132" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 14727994bc9288091d8a236221a977f6e42e74aa. Signed-off-by: Andrzej Głąbek --- soc/common/nordic_nrf/Kconfig.peripherals | 6 ------ 1 file changed, 6 deletions(-) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index 8326294f606..2b77cf0b849 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -538,9 +538,3 @@ config HAS_HW_NRF_WDT31 config HAS_HW_NRF_WDT130 def_bool $(dt_nodelabel_enabled_with_compat,wdt130,$(DT_COMPAT_NORDIC_NRF_WDT)) - -config HAS_HW_NRF_WDT131 - def_bool $(dt_nodelabel_enabled_with_compat,wdt131,$(DT_COMPAT_NORDIC_NRF_WDT)) - -config HAS_HW_NRF_WDT132 - def_bool $(dt_nodelabel_enabled_with_compat,wdt132,$(DT_COMPAT_NORDIC_NRF_WDT)) From 16502f77aca077be224011d65deb188c9568c603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1539/1623] Revert "[nrf fromlist] modules: hal_nordic: add support for WDT131-132" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d4f7cb27ad3e35ed5607b665d7628976f59bc7ae. Signed-off-by: Andrzej Głąbek --- modules/hal_nordic/nrfx/Kconfig | 10 ---------- modules/hal_nordic/nrfx/nrfx_config.h | 6 ------ 2 files changed, 16 deletions(-) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index a511af42e17..88b19159730 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -815,16 +815,6 @@ config NRFX_WDT130 depends on $(dt_nodelabel_has_compat,wdt130,$(DT_COMPAT_NORDIC_NRF_WDT)) select NRFX_WDT -config NRFX_WDT131 - bool "WDT131 driver instance" - depends on $(dt_nodelabel_has_compat,wdt131,$(DT_COMPAT_NORDIC_NRF_WDT)) - select NRFX_WDT - -config NRFX_WDT132 - bool "WDT132 driver instance" - depends on $(dt_nodelabel_has_compat,wdt132,$(DT_COMPAT_NORDIC_NRF_WDT)) - select NRFX_WDT - menu "Peripheral Resource Sharing module" config NRFX_PRS diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 5ebc243541e..5ec7b137703 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -722,12 +722,6 @@ #ifdef CONFIG_NRFX_WDT130 #define NRFX_WDT130_ENABLED 1 #endif -#ifdef CONFIG_NRFX_WDT131 -#define NRFX_WDT131_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_WDT132 -#define NRFX_WDT132_ENABLED 1 -#endif #ifdef CONFIG_NRF52_ANOMALY_109_WORKAROUND #define NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 1 From e4b558a65c0724ea9896fcf90c8d80035acf3929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1540/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add WDT nodes" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 6a071a2cb11c26b1b4c89da57cbb459beca6753a. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 6683d5c155a..96f6c0120a8 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -311,20 +311,6 @@ prescaler = <1>; }; - wdt131: watchdog@92b000 { - compatible = "nordic,nrf-wdt"; - reg = <0x92b000 0x1000>; - status = "disabled"; - interrupts = <299 NRF_DEFAULT_IRQ_PRIORITY>; - }; - - wdt132: watchdog@92c000 { - compatible = "nordic,nrf-wdt"; - reg = <0x92c000 0x1000>; - status = "disabled"; - interrupts = <300 NRF_DEFAULT_IRQ_PRIORITY>; - }; - gpiote130: gpiote@934000 { compatible = "nordic,nrf-gpiote"; reg = <0x934000 0x1000>; From 615444631e3f241c1107f83137738f55e737d017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1541/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add ECB node" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 207dce17040701862ae577ef7a08c80a2477b6d7. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 7 ------- 1 file changed, 7 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 96f6c0120a8..5476b28a920 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -209,13 +209,6 @@ status = "disabled"; }; }; - - ecb030: ecb@3b000 { - compatible = "nordic,nrf-ecb"; - reg = <0x3b000 0x1000>; - interrupts = <59 NRF_DEFAULT_IRQ_PRIORITY>; - status = "disabled"; - }; }; global_peripherals: peripheral@5f000000 { From d01f03c2665ac880331051617cb11c364638fdbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1542/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add RADIO node" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 409eaad0a6e2453cb9378a183a30f5647540ee0a. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 5476b28a920..1e1054fc4b8 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -193,22 +193,6 @@ interrupts = <43 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <1>; }; - - radio: radio@2c000 { - compatible = "nordic,nrf-radio"; - reg = <0x2c000 0x1000>; - status = "disabled"; - ble-2mbps-supported; - ble-coded-phy-supported; - dfe-supported; - ieee802154-supported; - interrupts = <44 NRF_DEFAULT_IRQ_PRIORITY>; - - cpurad_ieee802154: ieee802154 { - compatible = "nordic,nrf-ieee802154"; - status = "disabled"; - }; - }; }; global_peripherals: peripheral@5f000000 { From 92693e3b4b52f6a2d4844282fc8fadfa7630e689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1543/1623] Revert "[nrf fromlist] soc: nordic_nrf: add support for EGU020" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit cc7ad5c313473c6a8c90af8c2bc07b98de8d216e. Signed-off-by: Andrzej Głąbek --- soc/common/nordic_nrf/Kconfig.peripherals | 3 --- 1 file changed, 3 deletions(-) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index 2b77cf0b849..b3e0ae2d130 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -65,9 +65,6 @@ config HAS_HW_NRF_EGU4 config HAS_HW_NRF_EGU5 def_bool $(dt_nodelabel_enabled_with_compat,egu5,$(DT_COMPAT_NORDIC_NRF_EGU)) -config HAS_HW_NRF_EGU020 - def_bool $(dt_nodelabel_enabled_with_compat,egu020,$(DT_COMPAT_NORDIC_NRF_EGU)) - config HAS_HW_NRF_GPIO0 def_bool $(dt_nodelabel_enabled_with_compat,gpio0,$(DT_COMPAT_NORDIC_NRF_GPIO)) From 165222fe4e00c60f32d794e54944d0417609cea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1544/1623] Revert "[nrf fromlist] modules: hal_nordic: add support for EGU020" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b193f186e19996e409fe3c5f4c09fa2154711890. Signed-off-by: Andrzej Głąbek --- modules/hal_nordic/nrfx/Kconfig | 5 ----- modules/hal_nordic/nrfx/nrfx_config.h | 3 --- 2 files changed, 8 deletions(-) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 88b19159730..34dbb43f3d4 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -62,11 +62,6 @@ config NRFX_EGU5 depends on $(dt_nodelabel_has_compat,egu5,$(DT_COMPAT_NORDIC_NRF_EGU)) select NRFX_EGU -config NRFX_EGU020 - bool "EGU020 driver instance" - depends on $(dt_nodelabel_has_compat,egu020,$(DT_COMPAT_NORDIC_NRF_EGU)) - select NRFX_EGU - config NRFX_GPIOTE bool diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 5ec7b137703..0f52cd17cf2 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -108,9 +108,6 @@ #ifdef CONFIG_NRFX_EGU5 #define NRFX_EGU5_ENABLED 1 #endif -#ifdef CONFIG_NRFX_EGU020 -#define NRFX_EGU020_ENABLED 1 -#endif #ifdef CONFIG_NRFX_GRTC #define NRFX_GRTC_ENABLED 1 From d746c78ac036a79d0c0e6c157d64aa7318c5aeba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1545/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add EGU node" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 503e08d3036c3f144e6dd38fe4e445da7b8e3882. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 7 ------- 1 file changed, 7 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 1e1054fc4b8..cf67efd889f 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -147,13 +147,6 @@ nordic,ficr-names = "vsup", "coarse", "fine"; }; - egu020: egu@25000 { - compatible = "nordic,nrf-egu"; - reg = <0x25000 0x1000>; - status = "disabled"; - interrupts = <37 NRF_DEFAULT_IRQ_PRIORITY>; - }; - timer020: timer@28000 { compatible = "nordic,nrf-timer"; reg = <0x28000 0x1000>; From 7e123b0ff9ecb1bb851806dc6fcaaea0df9c0a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1546/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add COMP node" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f87d675c67c1eeb456bcf42e3e777dff345ef5f9. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 8 -------- 1 file changed, 8 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index cf67efd889f..e65abbf961f 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,14 +352,6 @@ port = <9>; }; - comp: comparator@983000 { - compatible = "nordic,nrf-comp"; - reg = <0x983000 0x1000>; - status = "disabled"; - interrupts = <387 NRF_DEFAULT_IRQ_PRIORITY>; - #io-channel-cells = <1>; - }; - temp: temperature-sensor@984000 { compatible = "nordic,nrf-temp"; reg = <0x984000 0x1000>; From ec4aacf2d34dd05b8652543f8be5be7001ba2f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1547/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add TEMP node" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 17b3ace31c236d43acd9f9474994e8cf45c8df1b. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 7 ------- 1 file changed, 7 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index e65abbf961f..e7a0c1ddd19 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,13 +352,6 @@ port = <9>; }; - temp: temperature-sensor@984000 { - compatible = "nordic,nrf-temp"; - reg = <0x984000 0x1000>; - interrupts = <388 NRF_DEFAULT_IRQ_PRIORITY>; - status = "disabled"; - }; - nfct: nfct@985000 { compatible = "nordic,nrf-nfct"; reg = <0x985000 0x1000>; From cabfb2dea211d15e573fc0b1497935ca6a9ccaf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1548/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add NFCT node" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9e06e58a82b5f59d8e0f23e60c4c1b53472f76af. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 7 ------- 1 file changed, 7 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index e7a0c1ddd19..010c0021a88 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,13 +352,6 @@ port = <9>; }; - nfct: nfct@985000 { - compatible = "nordic,nrf-nfct"; - reg = <0x985000 0x1000>; - status = "disabled"; - interrupts = <389 NRF_DEFAULT_IRQ_PRIORITY>; - }; - qdec130: qdec@994000 { compatible = "nordic,nrf-qdec"; reg = <0x994000 0x1000>; From 37a3115f39dfc863e6003f6eec613be79c84c604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1549/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add QDEC nodes" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit ed3108ab02cfcbca6df9c05408d4639fbbd2ea10. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 010c0021a88..5965390bb49 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,20 +352,6 @@ port = <9>; }; - qdec130: qdec@994000 { - compatible = "nordic,nrf-qdec"; - reg = <0x994000 0x1000>; - status = "disabled"; - interrupts = <404 NRF_DEFAULT_IRQ_PRIORITY>; - }; - - qdec131: qdec@995000 { - compatible = "nordic,nrf-qdec"; - reg = <0x995000 0x1000>; - status = "disabled"; - interrupts = <405 NRF_DEFAULT_IRQ_PRIORITY>; - }; - grtc: grtc@99c000 { compatible = "nordic,nrf-grtc"; reg = <0x99c000 0x1000>; From 353599069858661a85e4ec10ba8e35f14e56ed51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1550/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add TWIM nodes" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 6c3ea1189e0bf27ded544204a500bcad39c92f3d. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 72 ---------------------------- 1 file changed, 72 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 5965390bb49..caaf430de70 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -379,15 +379,6 @@ prescaler = <0>; }; - i2c130: i2c@9a5000 { - compatible = "nordic,nrf-twim"; - reg = <0x9a5000 0x1000>; - status = "disabled"; - interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; - #address-cells = <1>; - #size-cells = <0>; - }; - spi130: spi@9a5000 { compatible = "nordic,nrf-spim"; reg = <0x9a5000 0x1000>; @@ -406,15 +397,6 @@ interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; }; - i2c131: i2c@9a6000 { - compatible = "nordic,nrf-twim"; - reg = <0x9a6000 0x1000>; - status = "disabled"; - interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; - #address-cells = <1>; - #size-cells = <0>; - }; - spi131: spi@9a6000 { compatible = "nordic,nrf-spim"; reg = <0x9a6000 0x1000>; @@ -453,15 +435,6 @@ prescaler = <0>; }; - i2c132: i2c@9b5000 { - compatible = "nordic,nrf-twim"; - reg = <0x9b5000 0x1000>; - status = "disabled"; - interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; - #address-cells = <1>; - #size-cells = <0>; - }; - spi132: spi@9b5000 { compatible = "nordic,nrf-spim"; reg = <0x9b5000 0x1000>; @@ -480,15 +453,6 @@ interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; }; - i2c133: i2c@9b6000 { - compatible = "nordic,nrf-twim"; - reg = <0x9b6000 0x1000>; - status = "disabled"; - interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; - #address-cells = <1>; - #size-cells = <0>; - }; - spi133: spi@9b6000 { compatible = "nordic,nrf-spim"; reg = <0x9b6000 0x1000>; @@ -527,15 +491,6 @@ prescaler = <0>; }; - i2c134: i2c@9c5000 { - compatible = "nordic,nrf-twim"; - reg = <0x9c5000 0x1000>; - status = "disabled"; - interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; - #address-cells = <1>; - #size-cells = <0>; - }; - spi134: spi@9c5000 { compatible = "nordic,nrf-spim"; reg = <0x9c5000 0x1000>; @@ -554,15 +509,6 @@ interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; }; - i2c135: i2c@9c6000 { - compatible = "nordic,nrf-twim"; - reg = <0x9c6000 0x1000>; - status = "disabled"; - interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; - #address-cells = <1>; - #size-cells = <0>; - }; - spi135: spi@9c6000 { compatible = "nordic,nrf-spim"; reg = <0x9c6000 0x1000>; @@ -581,15 +527,6 @@ interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; }; - i2c136: i2c@9d5000 { - compatible = "nordic,nrf-twim"; - reg = <0x9d5000 0x1000>; - status = "disabled"; - interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; - #address-cells = <1>; - #size-cells = <0>; - }; - spi136: spi@9d5000 { compatible = "nordic,nrf-spim"; reg = <0x9d5000 0x1000>; @@ -628,15 +565,6 @@ prescaler = <0>; }; - i2c137: i2c@9d6000 { - compatible = "nordic,nrf-twim"; - reg = <0x9d6000 0x1000>; - status = "disabled"; - interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>; - #address-cells = <1>; - #size-cells = <0>; - }; - spi137: spi@9d6000 { compatible = "nordic,nrf-spim"; reg = <0x9d6000 0x1000>; From 3c056a22f9ade2777bd67573861424c3b76f576a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1551/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add SPIM nodes" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 0d6239cb154cb8dc72d80a2d5cbdb70de62a5d0c. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 110 --------------------------- 1 file changed, 110 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index caaf430de70..2c4cfea5044 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -220,28 +220,6 @@ interrupts = <229 NRF_DEFAULT_IRQ_PRIORITY>; }; - spi120: spi@8e6000 { - compatible = "nordic,nrf-spim"; - reg = <0x8e6000 0x1000>; - status = "disabled"; - easydma-maxcnt-bits = <15>; - interrupts = <230 NRF_DEFAULT_IRQ_PRIORITY>; - max-frequency = ; - #address-cells = <1>; - #size-cells = <0>; - }; - - spi121: spi@8e7000 { - compatible = "nordic,nrf-spim"; - reg = <0x8e7000 0x1000>; - status = "disabled"; - easydma-maxcnt-bits = <15>; - interrupts = <231 NRF_DEFAULT_IRQ_PRIORITY>; - max-frequency = ; - #address-cells = <1>; - #size-cells = <0>; - }; - cpuppr_vpr: vpr@908000 { compatible = "nordic,nrf-vpr-coprocessor"; reg = <0x908000 0x1000>; @@ -379,17 +357,6 @@ prescaler = <0>; }; - spi130: spi@9a5000 { - compatible = "nordic,nrf-spim"; - reg = <0x9a5000 0x1000>; - status = "disabled"; - easydma-maxcnt-bits = <15>; - interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; - max-frequency = ; - #address-cells = <1>; - #size-cells = <0>; - }; - uart130: uart@9a5000 { compatible = "nordic,nrf-uarte"; reg = <0x9a5000 0x1000>; @@ -397,17 +364,6 @@ interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; }; - spi131: spi@9a6000 { - compatible = "nordic,nrf-spim"; - reg = <0x9a6000 0x1000>; - status = "disabled"; - easydma-maxcnt-bits = <15>; - interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; - max-frequency = ; - #address-cells = <1>; - #size-cells = <0>; - }; - uart131: uart@9a6000 { compatible = "nordic,nrf-uarte"; reg = <0x9a6000 0x1000>; @@ -435,17 +391,6 @@ prescaler = <0>; }; - spi132: spi@9b5000 { - compatible = "nordic,nrf-spim"; - reg = <0x9b5000 0x1000>; - status = "disabled"; - easydma-maxcnt-bits = <15>; - interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; - max-frequency = ; - #address-cells = <1>; - #size-cells = <0>; - }; - uart132: uart@9b5000 { compatible = "nordic,nrf-uarte"; reg = <0x9b5000 0x1000>; @@ -453,17 +398,6 @@ interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; }; - spi133: spi@9b6000 { - compatible = "nordic,nrf-spim"; - reg = <0x9b6000 0x1000>; - status = "disabled"; - easydma-maxcnt-bits = <15>; - interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; - max-frequency = ; - #address-cells = <1>; - #size-cells = <0>; - }; - uart133: uart@9b6000 { compatible = "nordic,nrf-uarte"; reg = <0x9b6000 0x1000>; @@ -491,17 +425,6 @@ prescaler = <0>; }; - spi134: spi@9c5000 { - compatible = "nordic,nrf-spim"; - reg = <0x9c5000 0x1000>; - status = "disabled"; - easydma-maxcnt-bits = <15>; - interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; - max-frequency = ; - #address-cells = <1>; - #size-cells = <0>; - }; - uart134: uart@9c5000 { compatible = "nordic,nrf-uarte"; reg = <0x9c5000 0x1000>; @@ -509,17 +432,6 @@ interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; }; - spi135: spi@9c6000 { - compatible = "nordic,nrf-spim"; - reg = <0x9c6000 0x1000>; - status = "disabled"; - easydma-maxcnt-bits = <15>; - interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; - max-frequency = ; - #address-cells = <1>; - #size-cells = <0>; - }; - uart135: uart@9c6000 { compatible = "nordic,nrf-uarte"; reg = <0x9c6000 0x1000>; @@ -527,17 +439,6 @@ interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; }; - spi136: spi@9d5000 { - compatible = "nordic,nrf-spim"; - reg = <0x9d5000 0x1000>; - status = "disabled"; - easydma-maxcnt-bits = <15>; - interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; - max-frequency = ; - #address-cells = <1>; - #size-cells = <0>; - }; - uart136: uart@9d5000 { compatible = "nordic,nrf-uarte"; reg = <0x9d5000 0x1000>; @@ -565,17 +466,6 @@ prescaler = <0>; }; - spi137: spi@9d6000 { - compatible = "nordic,nrf-spim"; - reg = <0x9d6000 0x1000>; - status = "disabled"; - easydma-maxcnt-bits = <15>; - interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>; - max-frequency = ; - #address-cells = <1>; - #size-cells = <0>; - }; - uart137: uart@9d6000 { compatible = "nordic,nrf-uarte"; reg = <0x9d6000 0x1000>; From 2bb1634b09313e6ef62e7f8aa0c78f459b1ed141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1552/1623] Revert "[nrf fromlist] soc: nordic_nrf: add support for RTC130-131" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9ae5728d47b191dcc3bd9a6d7febfd78cc4f8e42. Signed-off-by: Andrzej Głąbek --- soc/common/nordic_nrf/Kconfig.peripherals | 6 ------ 1 file changed, 6 deletions(-) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index b3e0ae2d130..710d9d4582d 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -197,12 +197,6 @@ config HAS_HW_NRF_RTC1 config HAS_HW_NRF_RTC2 def_bool $(dt_nodelabel_enabled_with_compat,rtc2,$(DT_COMPAT_NORDIC_NRF_RTC)) -config HAS_HW_NRF_RTC130 - def_bool $(dt_nodelabel_enabled_with_compat,rtc130,$(DT_COMPAT_NORDIC_NRF_RTC)) - -config HAS_HW_NRF_RTC131 - def_bool $(dt_nodelabel_enabled_with_compat,rtc131,$(DT_COMPAT_NORDIC_NRF_RTC)) - config HAS_HW_NRF_SAADC def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_SAADC)) From 01032d874c4c5c8914ee9fc9fa14bf9a8457247d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1553/1623] Revert "[nrf fromlist] modules: hal_nordic: add support for RTC130-131" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 6563e52c2390019e6fc9e6a545e681bcdd769f40. Signed-off-by: Andrzej Głąbek --- modules/hal_nordic/nrfx/Kconfig | 10 ---------- modules/hal_nordic/nrfx/nrfx_config.h | 6 ------ 2 files changed, 16 deletions(-) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 34dbb43f3d4..784a2087139 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -238,16 +238,6 @@ config NRFX_RTC2 depends on $(dt_nodelabel_has_compat,rtc2,$(DT_COMPAT_NORDIC_NRF_RTC)) select NRFX_RTC -config NRFX_RTC130 - bool "RTC130 driver instance" - depends on $(dt_nodelabel_has_compat,rtc130,$(DT_COMPAT_NORDIC_NRF_RTC)) - select NRFX_RTC - -config NRFX_RTC131 - bool "RTC131 driver instance" - depends on $(dt_nodelabel_has_compat,rtc131,$(DT_COMPAT_NORDIC_NRF_RTC)) - select NRFX_RTC - config NRFX_SAADC bool "SAADC driver" depends on $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_SAADC)) diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 0f52cd17cf2..20facba229c 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -299,12 +299,6 @@ #ifdef CONFIG_NRFX_RTC2 #define NRFX_RTC2_ENABLED 1 #endif -#ifdef CONFIG_NRFX_RTC130 -#define NRFX_RTC130_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_RTC131 -#define NRFX_RTC131_ENABLED 1 -#endif #ifdef CONFIG_NRFX_SAADC #define NRFX_SAADC_ENABLED 1 From 01d90df7fc62479e7578b10668c96a3daebd7ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1554/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add RTC nodes" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a2bbfa1ba37f977b2ed2a90e51cecc00b566ef9c. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 30 ---------------------------- 1 file changed, 30 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 2c4cfea5044..0dfdac7434f 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -176,16 +176,6 @@ max-bit-width = <32>; prescaler = <0>; }; - - rtc: rtc@2b000 { - compatible = "nordic,nrf-rtc"; - reg = <0x2b000 0x1000>; - status = "disabled"; - cc-num = <4>; - clock-frequency = <32768>; - interrupts = <43 NRF_DEFAULT_IRQ_PRIORITY>; - prescaler = <1>; - }; }; global_peripherals: peripheral@5f000000 { @@ -239,26 +229,6 @@ }; }; - rtc130: rtc@928000 { - compatible = "nordic,nrf-rtc"; - reg = <0x928000 0x1000>; - status = "disabled"; - cc-num = <4>; - clock-frequency = <32768>; - interrupts = <296 NRF_DEFAULT_IRQ_PRIORITY>; - prescaler = <1>; - }; - - rtc131: rtc@929000 { - compatible = "nordic,nrf-rtc"; - reg = <0x929000 0x1000>; - status = "disabled"; - cc-num = <4>; - clock-frequency = <32768>; - interrupts = <297 NRF_DEFAULT_IRQ_PRIORITY>; - prescaler = <1>; - }; - gpiote130: gpiote@934000 { compatible = "nordic,nrf-gpiote"; reg = <0x934000 0x1000>; From 217b23f7ab3a5ea78d30a24fa6bd87b8ff67bde0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1555/1623] Revert "[nrf fromlist] soc: nordic_nrf: add support for TIMER020-022|120-121|130-137" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 5781d09392323b3d0d4e5b8a54f3a408190b5b40. Signed-off-by: Andrzej Głąbek --- soc/common/nordic_nrf/Kconfig.peripherals | 39 ----------------------- 1 file changed, 39 deletions(-) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index 710d9d4582d..b8b1198ca02 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -341,45 +341,6 @@ config HAS_HW_NRF_TIMER23 config HAS_HW_NRF_TIMER24 def_bool $(dt_nodelabel_enabled_with_compat,timer24,$(DT_COMPAT_NORDIC_NRF_TIMER)) -config HAS_HW_NRF_TIMER020 - def_bool $(dt_nodelabel_enabled_with_compat,timer020,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER021 - def_bool $(dt_nodelabel_enabled_with_compat,timer021,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER022 - def_bool $(dt_nodelabel_enabled_with_compat,timer022,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER120 - def_bool $(dt_nodelabel_enabled_with_compat,timer120,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER121 - def_bool $(dt_nodelabel_enabled_with_compat,timer121,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER130 - def_bool $(dt_nodelabel_enabled_with_compat,timer130,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER131 - def_bool $(dt_nodelabel_enabled_with_compat,timer131,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER132 - def_bool $(dt_nodelabel_enabled_with_compat,timer132,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER133 - def_bool $(dt_nodelabel_enabled_with_compat,timer133,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER134 - def_bool $(dt_nodelabel_enabled_with_compat,timer134,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER135 - def_bool $(dt_nodelabel_enabled_with_compat,timer135,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER136 - def_bool $(dt_nodelabel_enabled_with_compat,timer136,$(DT_COMPAT_NORDIC_NRF_TIMER)) - -config HAS_HW_NRF_TIMER137 - def_bool $(dt_nodelabel_enabled_with_compat,timer137,$(DT_COMPAT_NORDIC_NRF_TIMER)) - config HAS_HW_NRF_TWI0 def_bool $(dt_nodelabel_enabled_with_compat,i2c0,$(DT_COMPAT_NORDIC_NRF_TWI)) From c56b50d46e9c65758c32222f7dc9342a85568ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:17 +0100 Subject: [PATCH 1556/1623] Revert "[nrf fromlist] modules: hal_nordic: add support for TIMER020-022|120-121|130-137" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit e9b925c45856a4afa79ae0b2c6464715f636a726. Signed-off-by: Andrzej Głąbek --- modules/hal_nordic/nrfx/Kconfig | 65 --------------------------- modules/hal_nordic/nrfx/nrfx_config.h | 39 ---------------- 2 files changed, 104 deletions(-) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 784a2087139..ee1bd76b52f 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -457,71 +457,6 @@ config NRFX_TIMER24 depends on $(dt_nodelabel_has_compat,timer24,$(DT_COMPAT_NORDIC_NRF_TIMER)) select NRFX_TIMER -config NRFX_TIMER020 - bool "TIMER020 driver instance" - depends on $(dt_nodelabel_has_compat,timer020,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER021 - bool "TIMER021 driver instance" - depends on $(dt_nodelabel_has_compat,timer021,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER022 - bool "TIMER022 driver instance" - depends on $(dt_nodelabel_has_compat,timer022,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER120 - bool "TIMER120 driver instance" - depends on $(dt_nodelabel_has_compat,timer120,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER121 - bool "TIMER121 driver instance" - depends on $(dt_nodelabel_has_compat,timer121,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER130 - bool "TIMER130 driver instance" - depends on $(dt_nodelabel_has_compat,timer130,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER131 - bool "TIMER131 driver instance" - depends on $(dt_nodelabel_has_compat,timer131,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER132 - bool "TIMER132 driver instance" - depends on $(dt_nodelabel_has_compat,timer132,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER133 - bool "TIMER133 driver instance" - depends on $(dt_nodelabel_has_compat,timer133,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER134 - bool "TIMER134 driver instance" - depends on $(dt_nodelabel_has_compat,timer134,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER135 - bool "TIMER135 driver instance" - depends on $(dt_nodelabel_has_compat,timer135,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER136 - bool "TIMER136 driver instance" - depends on $(dt_nodelabel_has_compat,timer136,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - -config NRFX_TIMER137 - bool "TIMER137 driver instance" - depends on $(dt_nodelabel_has_compat,timer137,$(DT_COMPAT_NORDIC_NRF_TIMER)) - select NRFX_TIMER - config NRFX_TWI bool diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 20facba229c..26d662be39d 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -472,45 +472,6 @@ #ifdef CONFIG_NRFX_TIMER24 #define NRFX_TIMER24_ENABLED 1 #endif -#ifdef CONFIG_NRFX_TIMER020 -#define NRFX_TIMER020_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER021 -#define NRFX_TIMER021_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER022 -#define NRFX_TIMER022_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER120 -#define NRFX_TIMER120_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER121 -#define NRFX_TIMER121_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER130 -#define NRFX_TIMER130_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER131 -#define NRFX_TIMER131_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER132 -#define NRFX_TIMER132_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER133 -#define NRFX_TIMER133_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER134 -#define NRFX_TIMER134_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER135 -#define NRFX_TIMER135_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER136 -#define NRFX_TIMER136_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_TIMER137 -#define NRFX_TIMER137_ENABLED 1 -#endif #ifdef CONFIG_NRFX_TWI #define NRFX_TWI_ENABLED 1 From 276d99470362aeba1329db040582321b44f07420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:18 +0100 Subject: [PATCH 1557/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add TIMER nodes" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c23385cf9f222f139bf3dc39f0fc9ea30eba1129. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 130 --------------------------- 1 file changed, 130 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 0dfdac7434f..97dcb222746 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -146,36 +146,6 @@ <&ficr NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_FINE_1>; nordic,ficr-names = "vsup", "coarse", "fine"; }; - - timer020: timer@28000 { - compatible = "nordic,nrf-timer"; - reg = <0x28000 0x1000>; - status = "disabled"; - cc-num = <8>; - interrupts = <40 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - - timer021: timer@29000 { - compatible = "nordic,nrf-timer"; - reg = <0x29000 0x1000>; - status = "disabled"; - cc-num = <8>; - interrupts = <41 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - - timer022: timer@2a000 { - compatible = "nordic,nrf-timer"; - reg = <0x2a000 0x1000>; - status = "disabled"; - cc-num = <8>; - interrupts = <42 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; }; global_peripherals: peripheral@5f000000 { @@ -183,26 +153,6 @@ #size-cells = <1>; ranges = <0x0 0x5f000000 0x1000000>; - timer120: timer@8e2000 { - compatible = "nordic,nrf-timer"; - reg = <0x8e2000 0x1000>; - status = "disabled"; - cc-num = <6>; - interrupts = <226 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - - timer121: timer@8e3000 { - compatible = "nordic,nrf-timer"; - reg = <0x8e3000 0x1000>; - status = "disabled"; - cc-num = <6>; - interrupts = <227 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - uart120: uart@8e5000 { compatible = "nordic,nrf-uarte"; reg = <0x8e5000 0x1000>; @@ -307,26 +257,6 @@ cc-num = <16>; }; - timer130: timer@9a2000 { - compatible = "nordic,nrf-timer"; - reg = <0x9a2000 0x1000>; - status = "disabled"; - cc-num = <6>; - interrupts = <418 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - - timer131: timer@9a3000 { - compatible = "nordic,nrf-timer"; - reg = <0x9a3000 0x1000>; - status = "disabled"; - cc-num = <6>; - interrupts = <419 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - uart130: uart@9a5000 { compatible = "nordic,nrf-uarte"; reg = <0x9a5000 0x1000>; @@ -341,26 +271,6 @@ interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; }; - timer132: timer@9b2000 { - compatible = "nordic,nrf-timer"; - reg = <0x9b2000 0x1000>; - status = "disabled"; - cc-num = <6>; - interrupts = <434 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - - timer133: timer@9b3000 { - compatible = "nordic,nrf-timer"; - reg = <0x9b3000 0x1000>; - status = "disabled"; - cc-num = <6>; - interrupts = <435 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - uart132: uart@9b5000 { compatible = "nordic,nrf-uarte"; reg = <0x9b5000 0x1000>; @@ -375,26 +285,6 @@ interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; }; - timer134: timer@9c2000 { - compatible = "nordic,nrf-timer"; - reg = <0x9c2000 0x1000>; - status = "disabled"; - cc-num = <6>; - interrupts = <450 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - - timer135: timer@9c3000 { - compatible = "nordic,nrf-timer"; - reg = <0x9c3000 0x1000>; - status = "disabled"; - cc-num = <6>; - interrupts = <451 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - uart134: uart@9c5000 { compatible = "nordic,nrf-uarte"; reg = <0x9c5000 0x1000>; @@ -416,26 +306,6 @@ interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; }; - timer136: timer@9d2000 { - compatible = "nordic,nrf-timer"; - reg = <0x9d2000 0x1000>; - status = "disabled"; - cc-num = <6>; - interrupts = <466 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - - timer137: timer@9d3000 { - compatible = "nordic,nrf-timer"; - reg = <0x9d3000 0x1000>; - status = "disabled"; - cc-num = <6>; - interrupts = <467 NRF_DEFAULT_IRQ_PRIORITY>; - max-bit-width = <32>; - prescaler = <0>; - }; - uart137: uart@9d6000 { compatible = "nordic,nrf-uarte"; reg = <0x9d6000 0x1000>; From ca1fff405bd20903ce2beed73a2ba40392af64d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:18 +0100 Subject: [PATCH 1558/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: add missing UARTE nodes" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 447b80d72932043158e13a74172a7b465fdb0c4d. Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 49 ---------------------------- 1 file changed, 49 deletions(-) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 97dcb222746..af751c4344b 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -153,13 +153,6 @@ #size-cells = <1>; ranges = <0x0 0x5f000000 0x1000000>; - uart120: uart@8e5000 { - compatible = "nordic,nrf-uarte"; - reg = <0x8e5000 0x1000>; - status = "disabled"; - interrupts = <229 NRF_DEFAULT_IRQ_PRIORITY>; - }; - cpuppr_vpr: vpr@908000 { compatible = "nordic,nrf-vpr-coprocessor"; reg = <0x908000 0x1000>; @@ -257,41 +250,6 @@ cc-num = <16>; }; - uart130: uart@9a5000 { - compatible = "nordic,nrf-uarte"; - reg = <0x9a5000 0x1000>; - status = "disabled"; - interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; - }; - - uart131: uart@9a6000 { - compatible = "nordic,nrf-uarte"; - reg = <0x9a6000 0x1000>; - status = "disabled"; - interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; - }; - - uart132: uart@9b5000 { - compatible = "nordic,nrf-uarte"; - reg = <0x9b5000 0x1000>; - status = "disabled"; - interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; - }; - - uart133: uart@9b6000 { - compatible = "nordic,nrf-uarte"; - reg = <0x9b6000 0x1000>; - status = "disabled"; - interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; - }; - - uart134: uart@9c5000 { - compatible = "nordic,nrf-uarte"; - reg = <0x9c5000 0x1000>; - status = "disabled"; - interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; - }; - uart135: uart@9c6000 { compatible = "nordic,nrf-uarte"; reg = <0x9c6000 0x1000>; @@ -305,13 +263,6 @@ status = "disabled"; interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; }; - - uart137: uart@9d6000 { - compatible = "nordic,nrf-uarte"; - reg = <0x9d6000 0x1000>; - status = "disabled"; - interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>; - }; }; }; From 8330025b7634226acb41d578f4829b375b3552c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 27 Feb 2024 15:32:18 +0100 Subject: [PATCH 1559/1623] Revert "[nrf fromlist] dts: nordic: nrf54h20_enga: current-speed needs to be set by boards" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 2f370d3e143b026dbe2d8c7c3530053acbade78b. Signed-off-by: Andrzej Głąbek --- boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts | 2 -- boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts | 2 -- .../riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts | 2 -- dts/common/nordic/nrf54h20_enga.dtsi | 2 ++ 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts index 5fb345ec808..359c1f84307 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts @@ -123,7 +123,6 @@ }; &uart135 { - current-speed = <115200>; pinctrl-0 = <&uart135_default>; pinctrl-1 = <&uart135_sleep>; pinctrl-names = "default", "sleep"; @@ -132,7 +131,6 @@ &uart136 { status = "okay"; memory-regions = <&cpuapp_dma_region>; - current-speed = <115200>; pinctrl-0 = <&uart136_default>; pinctrl-1 = <&uart136_sleep>; pinctrl-names = "default", "sleep"; diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts index a7d142b06c4..02213d88645 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts @@ -46,14 +46,12 @@ &uart135 { status = "okay"; memory-regions = <&cpurad_dma_region>; - current-speed = <115200>; pinctrl-0 = <&uart135_default>; pinctrl-1 = <&uart135_sleep>; pinctrl-names = "default", "sleep"; }; &uart136 { - current-speed = <115200>; pinctrl-0 = <&uart136_default>; pinctrl-1 = <&uart136_sleep>; pinctrl-names = "default", "sleep"; diff --git a/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts index 3c74e7c88d4..83aface6f5c 100644 --- a/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts +++ b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts @@ -31,14 +31,12 @@ &uart135 { status = "okay"; - current-speed = <115200>; pinctrl-0 = <&uart135_default>; pinctrl-1 = <&uart135_sleep>; pinctrl-names = "default", "sleep"; }; &uart136 { - current-speed = <115200>; pinctrl-0 = <&uart136_default>; pinctrl-1 = <&uart136_sleep>; pinctrl-names = "default", "sleep"; diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index af751c4344b..1b8f7b6f9e8 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -254,6 +254,7 @@ compatible = "nordic,nrf-uarte"; reg = <0x9c6000 0x1000>; status = "disabled"; + current-speed = <115200>; interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; }; @@ -261,6 +262,7 @@ compatible = "nordic,nrf-uarte"; reg = <0x9d5000 0x1000>; status = "disabled"; + current-speed = <115200>; interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; }; }; From ff9acf5d7de51089fab4ea54122e24f2b72df716 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:05:02 +0100 Subject: [PATCH 1560/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: current-speed needs to be set by boards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a setting that depends on the board or application, so it should not be part of SoC definition files. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 04025d87db5e8e51fef531e1f312a73eb8e6e346) Signed-off-by: Andrzej Głąbek --- boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts | 2 ++ boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts | 2 ++ .../riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts | 2 ++ dts/common/nordic/nrf54h20_enga.dtsi | 2 -- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts index 359c1f84307..5fb345ec808 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts @@ -123,6 +123,7 @@ }; &uart135 { + current-speed = <115200>; pinctrl-0 = <&uart135_default>; pinctrl-1 = <&uart135_sleep>; pinctrl-names = "default", "sleep"; @@ -131,6 +132,7 @@ &uart136 { status = "okay"; memory-regions = <&cpuapp_dma_region>; + current-speed = <115200>; pinctrl-0 = <&uart136_default>; pinctrl-1 = <&uart136_sleep>; pinctrl-names = "default", "sleep"; diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts index 02213d88645..a7d142b06c4 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts @@ -46,12 +46,14 @@ &uart135 { status = "okay"; memory-regions = <&cpurad_dma_region>; + current-speed = <115200>; pinctrl-0 = <&uart135_default>; pinctrl-1 = <&uart135_sleep>; pinctrl-names = "default", "sleep"; }; &uart136 { + current-speed = <115200>; pinctrl-0 = <&uart136_default>; pinctrl-1 = <&uart136_sleep>; pinctrl-names = "default", "sleep"; diff --git a/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts index 83aface6f5c..3c74e7c88d4 100644 --- a/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts +++ b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr.dts @@ -31,12 +31,14 @@ &uart135 { status = "okay"; + current-speed = <115200>; pinctrl-0 = <&uart135_default>; pinctrl-1 = <&uart135_sleep>; pinctrl-names = "default", "sleep"; }; &uart136 { + current-speed = <115200>; pinctrl-0 = <&uart136_default>; pinctrl-1 = <&uart136_sleep>; pinctrl-names = "default", "sleep"; diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 1b8f7b6f9e8..af751c4344b 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -254,7 +254,6 @@ compatible = "nordic,nrf-uarte"; reg = <0x9c6000 0x1000>; status = "disabled"; - current-speed = <115200>; interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; }; @@ -262,7 +261,6 @@ compatible = "nordic,nrf-uarte"; reg = <0x9d5000 0x1000>; status = "disabled"; - current-speed = <115200>; interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; }; }; From 4ca348d278e0922f360be0a88fe56594907327be Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:02:54 +0100 Subject: [PATCH 1561/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add missing UARTE nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add missing UARTE nodes. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 5adbac51abf4e1d33a4d7bc897e5f3ac9b56f948) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index af751c4344b..97dcb222746 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -153,6 +153,13 @@ #size-cells = <1>; ranges = <0x0 0x5f000000 0x1000000>; + uart120: uart@8e5000 { + compatible = "nordic,nrf-uarte"; + reg = <0x8e5000 0x1000>; + status = "disabled"; + interrupts = <229 NRF_DEFAULT_IRQ_PRIORITY>; + }; + cpuppr_vpr: vpr@908000 { compatible = "nordic,nrf-vpr-coprocessor"; reg = <0x908000 0x1000>; @@ -250,6 +257,41 @@ cc-num = <16>; }; + uart130: uart@9a5000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9a5000 0x1000>; + status = "disabled"; + interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + uart131: uart@9a6000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9a6000 0x1000>; + status = "disabled"; + interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + uart132: uart@9b5000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9b5000 0x1000>; + status = "disabled"; + interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + uart133: uart@9b6000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9b6000 0x1000>; + status = "disabled"; + interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + uart134: uart@9c5000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9c5000 0x1000>; + status = "disabled"; + interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; + }; + uart135: uart@9c6000 { compatible = "nordic,nrf-uarte"; reg = <0x9c6000 0x1000>; @@ -263,6 +305,13 @@ status = "disabled"; interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; }; + + uart137: uart@9d6000 { + compatible = "nordic,nrf-uarte"; + reg = <0x9d6000 0x1000>; + status = "disabled"; + interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>; + }; }; }; From 86dc192be6f4d6030af05aacb7c553e4cf56a4c0 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 14:56:50 +0100 Subject: [PATCH 1562/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add TIMER nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add nodes for TIMER peripherals (Timer/Counter). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 083bf7e5495136cf4d6a2073656d927772bda945) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 130 +++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 97dcb222746..6d27042cb6b 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -146,6 +146,36 @@ <&ficr NRF_FICR_TRIM_RADIOCORE_HSFLL_TRIM_FINE_1>; nordic,ficr-names = "vsup", "coarse", "fine"; }; + + timer020: timer@28000 { + compatible = "nordic,nrf-timer"; + reg = <0x28000 0x1000>; + status = "disabled"; + cc-num = <8>; + interrupts = <40 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer021: timer@29000 { + compatible = "nordic,nrf-timer"; + reg = <0x29000 0x1000>; + status = "disabled"; + cc-num = <8>; + interrupts = <41 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer022: timer@2a000 { + compatible = "nordic,nrf-timer"; + reg = <0x2a000 0x1000>; + status = "disabled"; + cc-num = <8>; + interrupts = <42 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; }; global_peripherals: peripheral@5f000000 { @@ -153,6 +183,26 @@ #size-cells = <1>; ranges = <0x0 0x5f000000 0x1000000>; + timer120: timer@8e2000 { + compatible = "nordic,nrf-timer"; + reg = <0x8e2000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <226 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer121: timer@8e3000 { + compatible = "nordic,nrf-timer"; + reg = <0x8e3000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <227 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + uart120: uart@8e5000 { compatible = "nordic,nrf-uarte"; reg = <0x8e5000 0x1000>; @@ -257,6 +307,26 @@ cc-num = <16>; }; + timer130: timer@9a2000 { + compatible = "nordic,nrf-timer"; + reg = <0x9a2000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <418 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer131: timer@9a3000 { + compatible = "nordic,nrf-timer"; + reg = <0x9a3000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <419 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + uart130: uart@9a5000 { compatible = "nordic,nrf-uarte"; reg = <0x9a5000 0x1000>; @@ -271,6 +341,26 @@ interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; }; + timer132: timer@9b2000 { + compatible = "nordic,nrf-timer"; + reg = <0x9b2000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <434 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer133: timer@9b3000 { + compatible = "nordic,nrf-timer"; + reg = <0x9b3000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <435 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + uart132: uart@9b5000 { compatible = "nordic,nrf-uarte"; reg = <0x9b5000 0x1000>; @@ -285,6 +375,26 @@ interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; }; + timer134: timer@9c2000 { + compatible = "nordic,nrf-timer"; + reg = <0x9c2000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <450 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer135: timer@9c3000 { + compatible = "nordic,nrf-timer"; + reg = <0x9c3000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <451 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + uart134: uart@9c5000 { compatible = "nordic,nrf-uarte"; reg = <0x9c5000 0x1000>; @@ -299,6 +409,26 @@ interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; }; + timer136: timer@9d2000 { + compatible = "nordic,nrf-timer"; + reg = <0x9d2000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <466 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + + timer137: timer@9d3000 { + compatible = "nordic,nrf-timer"; + reg = <0x9d3000 0x1000>; + status = "disabled"; + cc-num = <6>; + interrupts = <467 NRF_DEFAULT_IRQ_PRIORITY>; + max-bit-width = <32>; + prescaler = <0>; + }; + uart136: uart@9d5000 { compatible = "nordic,nrf-uarte"; reg = <0x9d5000 0x1000>; From 8c65cb77e54a4b96174e5c64d69b4c64178bbde0 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:54:16 +0100 Subject: [PATCH 1563/1623] [nrf fromtree] modules: hal_nordic: add support for TIMER020-022|120-121|130-137 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new HAL glue Kconfig options so that new TIMER instances can be used. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 7dd985338255e1c3c9219454d53e0da663d009e0) Signed-off-by: Andrzej Głąbek --- modules/hal_nordic/nrfx/Kconfig | 65 +++++++++++++++++++++++++++ modules/hal_nordic/nrfx/nrfx_config.h | 39 ++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index ee1bd76b52f..784a2087139 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -457,6 +457,71 @@ config NRFX_TIMER24 depends on $(dt_nodelabel_has_compat,timer24,$(DT_COMPAT_NORDIC_NRF_TIMER)) select NRFX_TIMER +config NRFX_TIMER020 + bool "TIMER020 driver instance" + depends on $(dt_nodelabel_has_compat,timer020,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER021 + bool "TIMER021 driver instance" + depends on $(dt_nodelabel_has_compat,timer021,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER022 + bool "TIMER022 driver instance" + depends on $(dt_nodelabel_has_compat,timer022,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER120 + bool "TIMER120 driver instance" + depends on $(dt_nodelabel_has_compat,timer120,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER121 + bool "TIMER121 driver instance" + depends on $(dt_nodelabel_has_compat,timer121,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER130 + bool "TIMER130 driver instance" + depends on $(dt_nodelabel_has_compat,timer130,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER131 + bool "TIMER131 driver instance" + depends on $(dt_nodelabel_has_compat,timer131,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER132 + bool "TIMER132 driver instance" + depends on $(dt_nodelabel_has_compat,timer132,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER133 + bool "TIMER133 driver instance" + depends on $(dt_nodelabel_has_compat,timer133,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER134 + bool "TIMER134 driver instance" + depends on $(dt_nodelabel_has_compat,timer134,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER135 + bool "TIMER135 driver instance" + depends on $(dt_nodelabel_has_compat,timer135,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER136 + bool "TIMER136 driver instance" + depends on $(dt_nodelabel_has_compat,timer136,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + +config NRFX_TIMER137 + bool "TIMER137 driver instance" + depends on $(dt_nodelabel_has_compat,timer137,$(DT_COMPAT_NORDIC_NRF_TIMER)) + select NRFX_TIMER + config NRFX_TWI bool diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 26d662be39d..20facba229c 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -472,6 +472,45 @@ #ifdef CONFIG_NRFX_TIMER24 #define NRFX_TIMER24_ENABLED 1 #endif +#ifdef CONFIG_NRFX_TIMER020 +#define NRFX_TIMER020_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER021 +#define NRFX_TIMER021_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER022 +#define NRFX_TIMER022_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER120 +#define NRFX_TIMER120_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER121 +#define NRFX_TIMER121_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER130 +#define NRFX_TIMER130_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER131 +#define NRFX_TIMER131_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER132 +#define NRFX_TIMER132_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER133 +#define NRFX_TIMER133_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER134 +#define NRFX_TIMER134_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER135 +#define NRFX_TIMER135_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER136 +#define NRFX_TIMER136_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_TIMER137 +#define NRFX_TIMER137_ENABLED 1 +#endif #ifdef CONFIG_NRFX_TWI #define NRFX_TWI_ENABLED 1 From 2c870baff32a358cc78473e042eee478d5de4742 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:56:59 +0100 Subject: [PATCH 1564/1623] [nrf fromtree] soc: nordic_nrf: add support for TIMER020-022|120-121|130-137 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new Kconfig options so that new TIMER instances can be used. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 07d961c1124a46e3bd2429f567909aaaa12c631c) Signed-off-by: Andrzej Głąbek --- soc/common/nordic_nrf/Kconfig.peripherals | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index b8b1198ca02..710d9d4582d 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -341,6 +341,45 @@ config HAS_HW_NRF_TIMER23 config HAS_HW_NRF_TIMER24 def_bool $(dt_nodelabel_enabled_with_compat,timer24,$(DT_COMPAT_NORDIC_NRF_TIMER)) +config HAS_HW_NRF_TIMER020 + def_bool $(dt_nodelabel_enabled_with_compat,timer020,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER021 + def_bool $(dt_nodelabel_enabled_with_compat,timer021,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER022 + def_bool $(dt_nodelabel_enabled_with_compat,timer022,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER120 + def_bool $(dt_nodelabel_enabled_with_compat,timer120,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER121 + def_bool $(dt_nodelabel_enabled_with_compat,timer121,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER130 + def_bool $(dt_nodelabel_enabled_with_compat,timer130,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER131 + def_bool $(dt_nodelabel_enabled_with_compat,timer131,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER132 + def_bool $(dt_nodelabel_enabled_with_compat,timer132,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER133 + def_bool $(dt_nodelabel_enabled_with_compat,timer133,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER134 + def_bool $(dt_nodelabel_enabled_with_compat,timer134,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER135 + def_bool $(dt_nodelabel_enabled_with_compat,timer135,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER136 + def_bool $(dt_nodelabel_enabled_with_compat,timer136,$(DT_COMPAT_NORDIC_NRF_TIMER)) + +config HAS_HW_NRF_TIMER137 + def_bool $(dt_nodelabel_enabled_with_compat,timer137,$(DT_COMPAT_NORDIC_NRF_TIMER)) + config HAS_HW_NRF_TWI0 def_bool $(dt_nodelabel_enabled_with_compat,i2c0,$(DT_COMPAT_NORDIC_NRF_TWI)) From 67417f138709cd6ab7b1026122e97b7a23ed0ae8 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 14:58:55 +0100 Subject: [PATCH 1565/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add RTC nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add RTC (Real Time Counter) node. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 35fecb731a1b40f1fd8f7c5fa0a9ada83421164c) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 6d27042cb6b..b8341c257e2 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -176,6 +176,16 @@ max-bit-width = <32>; prescaler = <0>; }; + + rtc: rtc@2b000 { + compatible = "nordic,nrf-rtc"; + reg = <0x2b000 0x1000>; + status = "disabled"; + cc-num = <4>; + clock-frequency = <32768>; + interrupts = <43 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <1>; + }; }; global_peripherals: peripheral@5f000000 { @@ -229,6 +239,26 @@ }; }; + rtc130: rtc@928000 { + compatible = "nordic,nrf-rtc"; + reg = <0x928000 0x1000>; + status = "disabled"; + cc-num = <4>; + clock-frequency = <32768>; + interrupts = <296 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <1>; + }; + + rtc131: rtc@929000 { + compatible = "nordic,nrf-rtc"; + reg = <0x929000 0x1000>; + status = "disabled"; + cc-num = <4>; + clock-frequency = <32768>; + interrupts = <297 NRF_DEFAULT_IRQ_PRIORITY>; + prescaler = <1>; + }; + gpiote130: gpiote@934000 { compatible = "nordic,nrf-gpiote"; reg = <0x934000 0x1000>; From e41fccdef97d30cdfd8232445bce716b3c4d803b Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:14:56 +0100 Subject: [PATCH 1566/1623] [nrf fromtree] modules: hal_nordic: add support for RTC130-131 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new HAL glue Kconfig options for RTC130-131. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 3dd2b0d8b3da9a3650078b535b31b0c28a73d071) Signed-off-by: Andrzej Głąbek --- modules/hal_nordic/nrfx/Kconfig | 10 ++++++++++ modules/hal_nordic/nrfx/nrfx_config.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 784a2087139..34dbb43f3d4 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -238,6 +238,16 @@ config NRFX_RTC2 depends on $(dt_nodelabel_has_compat,rtc2,$(DT_COMPAT_NORDIC_NRF_RTC)) select NRFX_RTC +config NRFX_RTC130 + bool "RTC130 driver instance" + depends on $(dt_nodelabel_has_compat,rtc130,$(DT_COMPAT_NORDIC_NRF_RTC)) + select NRFX_RTC + +config NRFX_RTC131 + bool "RTC131 driver instance" + depends on $(dt_nodelabel_has_compat,rtc131,$(DT_COMPAT_NORDIC_NRF_RTC)) + select NRFX_RTC + config NRFX_SAADC bool "SAADC driver" depends on $(dt_has_compat,$(DT_COMPAT_NORDIC_NRF_SAADC)) diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 20facba229c..0f52cd17cf2 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -299,6 +299,12 @@ #ifdef CONFIG_NRFX_RTC2 #define NRFX_RTC2_ENABLED 1 #endif +#ifdef CONFIG_NRFX_RTC130 +#define NRFX_RTC130_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_RTC131 +#define NRFX_RTC131_ENABLED 1 +#endif #ifdef CONFIG_NRFX_SAADC #define NRFX_SAADC_ENABLED 1 From a46ad87180076f78e23764b1af8b698471d328b4 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:15:42 +0100 Subject: [PATCH 1567/1623] [nrf fromtree] soc: nordic_nrf: add support for RTC130-131 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new Kconfig options for RTC130-131 so that the new instances can be used. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit f77b30fa1762f3173b2cb3de09d524d327921e5a) Signed-off-by: Andrzej Głąbek --- soc/common/nordic_nrf/Kconfig.peripherals | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index 710d9d4582d..b3e0ae2d130 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -197,6 +197,12 @@ config HAS_HW_NRF_RTC1 config HAS_HW_NRF_RTC2 def_bool $(dt_nodelabel_enabled_with_compat,rtc2,$(DT_COMPAT_NORDIC_NRF_RTC)) +config HAS_HW_NRF_RTC130 + def_bool $(dt_nodelabel_enabled_with_compat,rtc130,$(DT_COMPAT_NORDIC_NRF_RTC)) + +config HAS_HW_NRF_RTC131 + def_bool $(dt_nodelabel_enabled_with_compat,rtc131,$(DT_COMPAT_NORDIC_NRF_RTC)) + config HAS_HW_NRF_SAADC def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_SAADC)) From 8aa62327d9109f0809258fe744cdeb03f9ec4e14 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:12:05 +0100 Subject: [PATCH 1568/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add SPIM nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add SPIM (SPI with EasyDMA) nodes. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit e5ef767ab2016a608627b7d01e440b11b6cdb0fd) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 110 +++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index b8341c257e2..b762c5c7f91 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -220,6 +220,28 @@ interrupts = <229 NRF_DEFAULT_IRQ_PRIORITY>; }; + spi120: spi@8e6000 { + compatible = "nordic,nrf-spim"; + reg = <0x8e6000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <230 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + + spi121: spi@8e7000 { + compatible = "nordic,nrf-spim"; + reg = <0x8e7000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <231 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + cpuppr_vpr: vpr@908000 { compatible = "nordic,nrf-vpr-coprocessor"; reg = <0x908000 0x1000>; @@ -357,6 +379,17 @@ prescaler = <0>; }; + spi130: spi@9a5000 { + compatible = "nordic,nrf-spim"; + reg = <0x9a5000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart130: uart@9a5000 { compatible = "nordic,nrf-uarte"; reg = <0x9a5000 0x1000>; @@ -364,6 +397,17 @@ interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; }; + spi131: spi@9a6000 { + compatible = "nordic,nrf-spim"; + reg = <0x9a6000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart131: uart@9a6000 { compatible = "nordic,nrf-uarte"; reg = <0x9a6000 0x1000>; @@ -391,6 +435,17 @@ prescaler = <0>; }; + spi132: spi@9b5000 { + compatible = "nordic,nrf-spim"; + reg = <0x9b5000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart132: uart@9b5000 { compatible = "nordic,nrf-uarte"; reg = <0x9b5000 0x1000>; @@ -398,6 +453,17 @@ interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; }; + spi133: spi@9b6000 { + compatible = "nordic,nrf-spim"; + reg = <0x9b6000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart133: uart@9b6000 { compatible = "nordic,nrf-uarte"; reg = <0x9b6000 0x1000>; @@ -425,6 +491,17 @@ prescaler = <0>; }; + spi134: spi@9c5000 { + compatible = "nordic,nrf-spim"; + reg = <0x9c5000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart134: uart@9c5000 { compatible = "nordic,nrf-uarte"; reg = <0x9c5000 0x1000>; @@ -432,6 +509,17 @@ interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; }; + spi135: spi@9c6000 { + compatible = "nordic,nrf-spim"; + reg = <0x9c6000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart135: uart@9c6000 { compatible = "nordic,nrf-uarte"; reg = <0x9c6000 0x1000>; @@ -459,6 +547,17 @@ prescaler = <0>; }; + spi136: spi@9d5000 { + compatible = "nordic,nrf-spim"; + reg = <0x9d5000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart136: uart@9d5000 { compatible = "nordic,nrf-uarte"; reg = <0x9d5000 0x1000>; @@ -466,6 +565,17 @@ interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; }; + spi137: spi@9d6000 { + compatible = "nordic,nrf-spim"; + reg = <0x9d6000 0x1000>; + status = "disabled"; + easydma-maxcnt-bits = <15>; + interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>; + max-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + }; + uart137: uart@9d6000 { compatible = "nordic,nrf-uarte"; reg = <0x9d6000 0x1000>; From e8794fc883893a79d7016aff8f5b7e6bc9fff185 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:22:09 +0100 Subject: [PATCH 1569/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add TWIM nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add nodes for I2C/TWIM. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 010519c8e3d9234ca841291517bb159d9ebebd42) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index b762c5c7f91..20ec8466ee5 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -379,6 +379,16 @@ prescaler = <0>; }; + i2c130: i2c@9a5000 { + compatible = "nordic,nrf-twim"; + reg = <0x9a5000 0x1000>; + status = "disabled"; + interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <15>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi130: spi@9a5000 { compatible = "nordic,nrf-spim"; reg = <0x9a5000 0x1000>; @@ -397,6 +407,16 @@ interrupts = <421 NRF_DEFAULT_IRQ_PRIORITY>; }; + i2c131: i2c@9a6000 { + compatible = "nordic,nrf-twim"; + reg = <0x9a6000 0x1000>; + status = "disabled"; + interrupts = <422 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <15>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi131: spi@9a6000 { compatible = "nordic,nrf-spim"; reg = <0x9a6000 0x1000>; @@ -435,6 +455,16 @@ prescaler = <0>; }; + i2c132: i2c@9b5000 { + compatible = "nordic,nrf-twim"; + reg = <0x9b5000 0x1000>; + status = "disabled"; + interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <15>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi132: spi@9b5000 { compatible = "nordic,nrf-spim"; reg = <0x9b5000 0x1000>; @@ -453,6 +483,16 @@ interrupts = <437 NRF_DEFAULT_IRQ_PRIORITY>; }; + i2c133: i2c@9b6000 { + compatible = "nordic,nrf-twim"; + reg = <0x9b6000 0x1000>; + status = "disabled"; + interrupts = <438 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <15>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi133: spi@9b6000 { compatible = "nordic,nrf-spim"; reg = <0x9b6000 0x1000>; @@ -491,6 +531,16 @@ prescaler = <0>; }; + i2c134: i2c@9c5000 { + compatible = "nordic,nrf-twim"; + reg = <0x9c5000 0x1000>; + status = "disabled"; + interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <15>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi134: spi@9c5000 { compatible = "nordic,nrf-spim"; reg = <0x9c5000 0x1000>; @@ -509,6 +559,16 @@ interrupts = <453 NRF_DEFAULT_IRQ_PRIORITY>; }; + i2c135: i2c@9c6000 { + compatible = "nordic,nrf-twim"; + reg = <0x9c6000 0x1000>; + status = "disabled"; + interrupts = <454 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <15>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi135: spi@9c6000 { compatible = "nordic,nrf-spim"; reg = <0x9c6000 0x1000>; @@ -547,6 +607,16 @@ prescaler = <0>; }; + i2c136: i2c@9d5000 { + compatible = "nordic,nrf-twim"; + reg = <0x9d5000 0x1000>; + status = "disabled"; + interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <15>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi136: spi@9d5000 { compatible = "nordic,nrf-spim"; reg = <0x9d5000 0x1000>; @@ -565,6 +635,16 @@ interrupts = <469 NRF_DEFAULT_IRQ_PRIORITY>; }; + i2c137: i2c@9d6000 { + compatible = "nordic,nrf-twim"; + reg = <0x9d6000 0x1000>; + status = "disabled"; + interrupts = <470 NRF_DEFAULT_IRQ_PRIORITY>; + easydma-maxcnt-bits = <15>; + #address-cells = <1>; + #size-cells = <0>; + }; + spi137: spi@9d6000 { compatible = "nordic,nrf-spim"; reg = <0x9d6000 0x1000>; From 0cfd5a585ec4efec2ba77f42e6af3e8ba6f7e436 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:24:16 +0100 Subject: [PATCH 1570/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add QDEC nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add nodes for QDEC (Quadrature Decoder). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 720719cf80ba19625eef8f9e37bb5e73e1736c5b) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 20ec8466ee5..0e586962b0f 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,6 +352,20 @@ port = <9>; }; + qdec130: qdec@994000 { + compatible = "nordic,nrf-qdec"; + reg = <0x994000 0x1000>; + status = "disabled"; + interrupts = <404 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + qdec131: qdec@995000 { + compatible = "nordic,nrf-qdec"; + reg = <0x995000 0x1000>; + status = "disabled"; + interrupts = <405 NRF_DEFAULT_IRQ_PRIORITY>; + }; + grtc: grtc@99c000 { compatible = "nordic,nrf-grtc"; reg = <0x99c000 0x1000>; From 99e686563223c705f8e0ac3385e76da85817eb86 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:25:11 +0100 Subject: [PATCH 1571/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add NFCT node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add node for the NFCT (Near Field Connect Tag) peripheral. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 735ee4c83ab34ea76322a6cf4f0aa14e5e36e62b) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 0e586962b0f..817c346e066 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,6 +352,13 @@ port = <9>; }; + nfct: nfct@985000 { + compatible = "nordic,nrf-nfct"; + reg = <0x985000 0x1000>; + status = "disabled"; + interrupts = <389 NRF_DEFAULT_IRQ_PRIORITY>; + }; + qdec130: qdec@994000 { compatible = "nordic,nrf-qdec"; reg = <0x994000 0x1000>; From edbdb319c8c058da799301ed72c42765282b779c Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:26:19 +0100 Subject: [PATCH 1572/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add TEMP node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add nodes for the TEMP (temperature sensor) peripheral. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit f1a352d00f951f060437d4ec7dce9bfda4b69544) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 817c346e066..6999a52278e 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,6 +352,13 @@ port = <9>; }; + temp: temperature-sensor@984000 { + compatible = "nordic,nrf-temp"; + reg = <0x984000 0x1000>; + interrupts = <388 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; + }; + nfct: nfct@985000 { compatible = "nordic,nrf-nfct"; reg = <0x985000 0x1000>; From 7a5873a94d2f597e0b705362ead819de3881f647 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:31:04 +0100 Subject: [PATCH 1573/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add COMP node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add node for COMP (comparator). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 9c6f47d7860face9bf26c9570705da168b8bf854) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 6999a52278e..d6208a3f2d7 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -352,6 +352,14 @@ port = <9>; }; + comp: comparator@983000 { + compatible = "nordic,nrf-comp"; + reg = <0x983000 0x1000>; + status = "disabled"; + interrupts = <387 NRF_DEFAULT_IRQ_PRIORITY>; + #io-channel-cells = <1>; + }; + temp: temperature-sensor@984000 { compatible = "nordic,nrf-temp"; reg = <0x984000 0x1000>; From d94e17813f169b8d51e24d9daf072a48c0f51950 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:37:02 +0100 Subject: [PATCH 1574/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add EGU node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add node for EGU (Event Generator Unit). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit bc53031824b38b860b7716a3da8cb80d8bbdbab6) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index d6208a3f2d7..e3010a1de58 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -147,6 +147,13 @@ nordic,ficr-names = "vsup", "coarse", "fine"; }; + egu020: egu@25000 { + compatible = "nordic,nrf-egu"; + reg = <0x25000 0x1000>; + status = "disabled"; + interrupts = <37 NRF_DEFAULT_IRQ_PRIORITY>; + }; + timer020: timer@28000 { compatible = "nordic,nrf-timer"; reg = <0x28000 0x1000>; From d4e36bec63b5a0dd33b38ae3b3f60279bc4dd4d5 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:17:29 +0100 Subject: [PATCH 1575/1623] [nrf fromtree] modules: hal_nordic: add support for EGU020 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add HAL glue code to support EGU020. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 01b43074ab2451a5e17d770c4d62d8d3bba781e5) Signed-off-by: Andrzej Głąbek --- modules/hal_nordic/nrfx/Kconfig | 5 +++++ modules/hal_nordic/nrfx/nrfx_config.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 34dbb43f3d4..88b19159730 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -62,6 +62,11 @@ config NRFX_EGU5 depends on $(dt_nodelabel_has_compat,egu5,$(DT_COMPAT_NORDIC_NRF_EGU)) select NRFX_EGU +config NRFX_EGU020 + bool "EGU020 driver instance" + depends on $(dt_nodelabel_has_compat,egu020,$(DT_COMPAT_NORDIC_NRF_EGU)) + select NRFX_EGU + config NRFX_GPIOTE bool diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 0f52cd17cf2..5ec7b137703 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -108,6 +108,9 @@ #ifdef CONFIG_NRFX_EGU5 #define NRFX_EGU5_ENABLED 1 #endif +#ifdef CONFIG_NRFX_EGU020 +#define NRFX_EGU020_ENABLED 1 +#endif #ifdef CONFIG_NRFX_GRTC #define NRFX_GRTC_ENABLED 1 From 7782e88dc2912e2d7d975aee3391ec9d6481955f Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:18:23 +0100 Subject: [PATCH 1576/1623] [nrf fromtree] soc: nordic_nrf: add support for EGU020 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for EGU020. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 0cb51de315049a8cdb82d955f9961fae909cfd47) Signed-off-by: Andrzej Głąbek --- soc/common/nordic_nrf/Kconfig.peripherals | 3 +++ 1 file changed, 3 insertions(+) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index b3e0ae2d130..2b77cf0b849 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -65,6 +65,9 @@ config HAS_HW_NRF_EGU4 config HAS_HW_NRF_EGU5 def_bool $(dt_nodelabel_enabled_with_compat,egu5,$(DT_COMPAT_NORDIC_NRF_EGU)) +config HAS_HW_NRF_EGU020 + def_bool $(dt_nodelabel_enabled_with_compat,egu020,$(DT_COMPAT_NORDIC_NRF_EGU)) + config HAS_HW_NRF_GPIO0 def_bool $(dt_nodelabel_enabled_with_compat,gpio0,$(DT_COMPAT_NORDIC_NRF_GPIO)) From 7a6f0f979e5403459aa2fac762f2a8d2d669c705 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:38:13 +0100 Subject: [PATCH 1577/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add RADIO node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add node for the RADIO. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit d33e5fc7afb98a5648627d65e8c507d5d6a24d06) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index e3010a1de58..b08a8ee6cb3 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -193,6 +193,22 @@ interrupts = <43 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <1>; }; + + radio: radio@2c000 { + compatible = "nordic,nrf-radio"; + reg = <0x2c000 0x1000>; + status = "disabled"; + ble-2mbps-supported; + ble-coded-phy-supported; + dfe-supported; + ieee802154-supported; + interrupts = <44 NRF_DEFAULT_IRQ_PRIORITY>; + + cpurad_ieee802154: ieee802154 { + compatible = "nordic,nrf-ieee802154"; + status = "disabled"; + }; + }; }; global_peripherals: peripheral@5f000000 { From 59460ab14a9beadc2c1209db5877d53f599c3556 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:39:25 +0100 Subject: [PATCH 1578/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add ECB node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add node for ECB (AES electronic codebook mode encryption). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 4db40601dd7f0b98a48f3e6072bf44643a4ea3db) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index b08a8ee6cb3..980546bcf00 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -209,6 +209,13 @@ status = "disabled"; }; }; + + ecb030: ecb@3b000 { + compatible = "nordic,nrf-ecb"; + reg = <0x3b000 0x1000>; + interrupts = <59 NRF_DEFAULT_IRQ_PRIORITY>; + status = "disabled"; + }; }; global_peripherals: peripheral@5f000000 { From dd4209b756794b77a6cc8fbf94193fb08b578d3e Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 15:42:15 +0100 Subject: [PATCH 1579/1623] [nrf fromtree] dts: nordic: nrf54h20_enga: add WDT nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add nodes for WDT (Watchdog Timer). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 30c77786e5390133a1a675e03c2cfde7dd846938) Signed-off-by: Andrzej Głąbek --- dts/common/nordic/nrf54h20_enga.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 980546bcf00..5a9af57801c 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -311,6 +311,20 @@ prescaler = <1>; }; + wdt131: watchdog@92b000 { + compatible = "nordic,nrf-wdt"; + reg = <0x92b000 0x1000>; + status = "disabled"; + interrupts = <299 NRF_DEFAULT_IRQ_PRIORITY>; + }; + + wdt132: watchdog@92c000 { + compatible = "nordic,nrf-wdt"; + reg = <0x92c000 0x1000>; + status = "disabled"; + interrupts = <300 NRF_DEFAULT_IRQ_PRIORITY>; + }; + gpiote130: gpiote@934000 { compatible = "nordic,nrf-gpiote"; reg = <0x934000 0x1000>; From 4652b914d62ae9d02cd6ecafbc4e0dd4946def9c Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:24:27 +0100 Subject: [PATCH 1580/1623] [nrf fromtree] modules: hal_nordic: add support for WDT131-132 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add HAL glue code to support WDT131-132. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit c57ec6f07ab7e8cd18ccc1396782c906acb47281) Signed-off-by: Andrzej Głąbek --- modules/hal_nordic/nrfx/Kconfig | 10 ++++++++++ modules/hal_nordic/nrfx/nrfx_config.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 88b19159730..a511af42e17 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -815,6 +815,16 @@ config NRFX_WDT130 depends on $(dt_nodelabel_has_compat,wdt130,$(DT_COMPAT_NORDIC_NRF_WDT)) select NRFX_WDT +config NRFX_WDT131 + bool "WDT131 driver instance" + depends on $(dt_nodelabel_has_compat,wdt131,$(DT_COMPAT_NORDIC_NRF_WDT)) + select NRFX_WDT + +config NRFX_WDT132 + bool "WDT132 driver instance" + depends on $(dt_nodelabel_has_compat,wdt132,$(DT_COMPAT_NORDIC_NRF_WDT)) + select NRFX_WDT + menu "Peripheral Resource Sharing module" config NRFX_PRS diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 5ec7b137703..5ebc243541e 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -722,6 +722,12 @@ #ifdef CONFIG_NRFX_WDT130 #define NRFX_WDT130_ENABLED 1 #endif +#ifdef CONFIG_NRFX_WDT131 +#define NRFX_WDT131_ENABLED 1 +#endif +#ifdef CONFIG_NRFX_WDT132 +#define NRFX_WDT132_ENABLED 1 +#endif #ifdef CONFIG_NRF52_ANOMALY_109_WORKAROUND #define NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 1 From 38cfef4e5b9f006259a4c837929650d560e6a78d Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:25:01 +0100 Subject: [PATCH 1581/1623] [nrf fromtree] soc: nordic_nrf: add support for WDT131-132 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new Kconfig options to select WDT131-132. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 1453008f6fe77540eec54c002188a828e0274489) Signed-off-by: Andrzej Głąbek --- soc/common/nordic_nrf/Kconfig.peripherals | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index 2b77cf0b849..8326294f606 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -538,3 +538,9 @@ config HAS_HW_NRF_WDT31 config HAS_HW_NRF_WDT130 def_bool $(dt_nodelabel_enabled_with_compat,wdt130,$(DT_COMPAT_NORDIC_NRF_WDT)) + +config HAS_HW_NRF_WDT131 + def_bool $(dt_nodelabel_enabled_with_compat,wdt131,$(DT_COMPAT_NORDIC_NRF_WDT)) + +config HAS_HW_NRF_WDT132 + def_bool $(dt_nodelabel_enabled_with_compat,wdt132,$(DT_COMPAT_NORDIC_NRF_WDT)) From ab0d6af736b634de495b9e599f46ccfa272b85bb Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 19 Feb 2024 16:20:18 +0100 Subject: [PATCH 1582/1623] [nrf fromtree] soc: nordic_nrf: add missing GRTC Kconfig option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add missing option to select GRTC. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 349c06ebc5e7c7be7b39a57106ab989b590738f1) Signed-off-by: Andrzej Głąbek --- soc/common/nordic_nrf/Kconfig.peripherals | 3 +++ 1 file changed, 3 insertions(+) diff --git a/soc/common/nordic_nrf/Kconfig.peripherals b/soc/common/nordic_nrf/Kconfig.peripherals index 8326294f606..a6b62428626 100644 --- a/soc/common/nordic_nrf/Kconfig.peripherals +++ b/soc/common/nordic_nrf/Kconfig.peripherals @@ -92,6 +92,9 @@ config HAS_HW_NRF_GPIOTE130 config HAS_HW_NRF_GPIOTE131 def_bool $(dt_nodelabel_enabled_with_compat,gpiote131,$(DT_COMPAT_NORDIC_NRF_GPIOTE)) +config HAS_HW_NRF_GRTC + def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF_GRTC)) + config HAS_HW_NRF_I2S0 def_bool $(dt_nodelabel_enabled_with_compat,i2s0,$(DT_COMPAT_NORDIC_NRF_I2S)) From 76b0463a5a4b8b44cb4c82e5906711d18ae439db Mon Sep 17 00:00:00 2001 From: Georgios Vasilakis Date: Wed, 21 Feb 2024 17:22:51 +0100 Subject: [PATCH 1583/1623] [nrf noup] modules: mbedtls: Add new PAKE Kconfigs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds new Kconfigs used by the Oberon PSA core. Noup since the Oberon PSA core is Nordic only code. Ref: NCSDK-26057 Signed-off-by: Georgios Vasilakis Signed-off-by: Markus Swarowsky Signed-off-by: Frank Audun Kvamtrø --- modules/mbedtls/Kconfig.psa | 96 +++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/modules/mbedtls/Kconfig.psa b/modules/mbedtls/Kconfig.psa index e92c0f6ee06..b4d72801300 100644 --- a/modules/mbedtls/Kconfig.psa +++ b/modules/mbedtls/Kconfig.psa @@ -217,6 +217,83 @@ config PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY help Finite-field Diffie-Hellman public key. +config PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR_IMPORT + bool "SPAKE2P key pair import support" + default y if PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR + select PSA_WANT_KEY_TYPE_SPAKE2P_PUBLIC_KEY + help + SPAKE2P key pair: import key for both the private and public key. + +config PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR_EXPORT + bool "SPAKE2P key pair export support" + default y if PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR + select PSA_WANT_KEY_TYPE_SPAKE2P_PUBLIC_KEY + help + SPAKE2P key pair: export key for both the private and public key. + +config PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR_DERIVE + bool "SPAKE2P key pair derive support" + default y if PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR + select PSA_WANT_KEY_TYPE_SPAKE2P_PUBLIC_KEY + help + SPAKE2P key pair: derive key for both the private and public key. + +config PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR_BASIC + bool + default y + depends on PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR_IMPORT || \ + PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR_EXPORT || \ + PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR_DERIVE + +config PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR + bool "SPAKE2P key pair support" + select PSA_WANT_KEY_TYPE_SPAKE2P_PUBLIC_KEY + help + SPAKE2P key pair: both the private and public key. + +config PSA_WANT_KEY_TYPE_SPAKE2P_PUBLIC_KEY + bool "SPAKE2P public key support" + help + SPAKE2P public key. + +config PSA_WANT_KEY_TYPE_SRP_KEY_PAIR_IMPORT + bool "SRP key pair import support" + default y if PSA_WANT_KEY_TYPE_SRP_KEY_PAIR + select PSA_WANT_KEY_TYPE_SRP_PUBLIC_KEY + help + SRP key pair: import key for both the private and public key. + +config PSA_WANT_KEY_TYPE_SRP_KEY_PAIR_EXPORT + bool "SRP key pair export support" + default y if PSA_WANT_KEY_TYPE_SRP_KEY_PAIR + select PSA_WANT_KEY_TYPE_SRP_PUBLIC_KEY + help + SRP key pair: export key for both the private and public key. + +config PSA_WANT_KEY_TYPE_SRP_KEY_PAIR_DERIVE + bool "SRP key pair derive support" + default y if PSA_WANT_KEY_TYPE_SRP_KEY_PAIR + select PSA_WANT_KEY_TYPE_SRP_PUBLIC_KEY + help + SRP key pair: derive key for both the private and public key. + +config PSA_WANT_KEY_TYPE_SRP_KEY_PAIR_BASIC + bool + default y + depends on PSA_WANT_KEY_TYPE_SRP_KEY_PAIR_IMPORT || \ + PSA_WANT_KEY_TYPE_SRP_KEY_PAIR_EXPORT || \ + PSA_WANT_KEY_TYPE_SRP_KEY_PAIR_DERIVE + +config PSA_WANT_KEY_TYPE_SRP_PUBLIC_KEY + bool "SRP public key support" + help + SRP public key. + +config PSA_WANT_KEY_TYPE_SRP_KEY_PAIR + bool "SRP public key support" + help + SRP public key. + endmenu # PSA Key type support menu "PSA AEAD support" @@ -735,16 +812,29 @@ config PSA_WANT_ALG_JPAKE prompt "PSA EC J-PAKE support" if !PSA_PROMPTLESS select EXPERIMENTAL if !NET_L2_OPENTHREAD -config PSA_WANT_ALG_SPAKE2P +config PSA_WANT_ALG_SPAKE2P_HMAC bool - prompt "PSA SPAKE2+ support" if !PSA_PROMPTLESS - select EXPERIMENTAL if !CHIP + prompt "PSA SPAKE2+ HMAC support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SPAKE2P_CMAC + bool + prompt "PSA SPAKE2+ CMAC support" if !PSA_PROMPTLESS + +config PSA_WANT_ALG_SPAKE2P_MATTER + bool + prompt "PSA SPAKE2+ MATTER support" if !PSA_PROMPTLESS config PSA_WANT_ALG_SRP_6 bool prompt "PSA SRP-6 support" if !PSA_PROMPTLESS select EXPERIMENTAL +config PSA_WANT_ALG_SRP_PASSWORD_HASH + bool + prompt "PSA SRP password hash support" if !PSA_PROMPTLESS + select EXPERIMENTAL + + config PSA_WANT_ALG_PURE_EDDSA bool prompt "PSA PURE_EDDSA support" if !PSA_PROMPTLESS From c4fb0723bde01a328fd1218cf8970451ca2a3630 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 17 Jan 2024 10:15:04 +0200 Subject: [PATCH 1584/1623] [nrf fromtree] net: socket: Allow user to tweak service dispatcher thread priority User is able to tweak the socket service dispatcher thread priority in order to get better performance from the system if needed. By default the dispatcher thread runs in lowest application thread priority (K_LOWEST_APPLICATION_THREAD_PRIO). Signed-off-by: Jukka Rissanen (cherry picked from commit 84ff0e8cdfa985b325d4e1004df6484ae1fa6fa0) Signed-off-by: Robert Lubos --- subsys/net/lib/sockets/Kconfig | 21 +++++++++++++++++++++ subsys/net/lib/sockets/sockets_service.c | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/sockets/Kconfig b/subsys/net/lib/sockets/Kconfig index 35750dd3583..4d6c091b749 100644 --- a/subsys/net/lib/sockets/Kconfig +++ b/subsys/net/lib/sockets/Kconfig @@ -86,6 +86,27 @@ config NET_SOCKETS_SERVICE system needs as multiple services can be activated at the same time depending on network configuration. +config NET_SOCKETS_SERVICE_THREAD_PRIO + int "Priority of the socket service dispatcher thread" + default NUM_PREEMPT_PRIORITIES + depends on NET_SOCKETS_SERVICE + help + Set the priority of the socket service dispatcher thread. This handler + polls the sockets and either places the triggered socket to work queue + for asynchronous handlers, or calls the user supplied callback directly + for synchronous handlers. + The value should be selected carefully because if this thread priority + is too high, the work queue handlers might not be able to run if using + asynchronous handlers that are called via a work queue. + + Note that >= 0 value means preemptive thread priority, the lowest + value is NUM_PREEMPT_PRIORITIES. + Highest preemptive thread priority is 0. + Lowest cooperative thread priority is -1. + Highest cooperative thread priority is -NUM_COOP_PRIORITIES. + Make sure the priority is lower than workqueue priority so that + we never block the workqueue handler. + config NET_SOCKETS_SERVICE_STACK_SIZE int "Stack size for the thread handling socket services" default 2400 if NET_DHCPV4_SERVER diff --git a/subsys/net/lib/sockets/sockets_service.c b/subsys/net/lib/sockets/sockets_service.c index d253ece629c..2863de005ea 100644 --- a/subsys/net/lib/sockets/sockets_service.c +++ b/subsys/net/lib/sockets/sockets_service.c @@ -279,7 +279,9 @@ static void socket_service_thread(void) K_THREAD_DEFINE(socket_service_monitor, CONFIG_NET_SOCKETS_SERVICE_STACK_SIZE, socket_service_thread, NULL, NULL, NULL, - K_LOWEST_APPLICATION_THREAD_PRIO, 0, 0); + CLAMP(CONFIG_NET_SOCKETS_SERVICE_THREAD_PRIO, + K_HIGHEST_APPLICATION_THREAD_PRIO, + K_LOWEST_APPLICATION_THREAD_PRIO), 0, 0); static int init_socket_service(void) { From bd9efc686964e110b5857ef71abc001bef837018 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 17 Jan 2024 18:45:09 +0200 Subject: [PATCH 1585/1623] [nrf fromtree] net: socket: Change the printf modifier to print size_t correctly The argument is size_t, so change the printf modifier to %zd to avoid warning prints. Signed-off-by: Jukka Rissanen (cherry picked from commit 5a933299bbfe33f32a78a2e0f6e730b60bd0f18f) Signed-off-by: Robert Lubos --- subsys/net/lib/sockets/sockets_service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/lib/sockets/sockets_service.c b/subsys/net/lib/sockets/sockets_service.c index 2863de005ea..19efef93add 100644 --- a/subsys/net/lib/sockets/sockets_service.c +++ b/subsys/net/lib/sockets/sockets_service.c @@ -196,7 +196,7 @@ static void socket_service_thread(void) if ((count + 1) > ARRAY_SIZE(ctx.events)) { NET_WARN("You have %d services to monitor but " - "%d poll entries configured.", + "%zd poll entries configured.", count + 1, ARRAY_SIZE(ctx.events)); NET_WARN("Consider increasing value of %s to %d", "CONFIG_NET_SOCKETS_POLL_MAX", count + 1); From 48639d90925c68694c73299a8f4123a8c84b77f5 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Mon, 29 Jan 2024 13:31:25 +0200 Subject: [PATCH 1586/1623] [nrf fromtree] net: socket: Start service thread from initialization function We cannot always start the service monitor thread statically because the static threads are started after the application level. This means that when config library wants to start dhcpv4 server which uses socket services, there would be a deadlock. Simplest solution is to start the service thread directly from socket service init function. Signed-off-by: Jukka Rissanen (cherry picked from commit b03c3c0c48c0771c4bf0141dde7380429c41f2f4) Signed-off-by: Robert Lubos --- subsys/net/lib/sockets/sockets_service.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/subsys/net/lib/sockets/sockets_service.c b/subsys/net/lib/sockets/sockets_service.c index 19efef93add..4c9270af116 100644 --- a/subsys/net/lib/sockets/sockets_service.c +++ b/subsys/net/lib/sockets/sockets_service.c @@ -277,15 +277,23 @@ static void socket_service_thread(void) k_condvar_broadcast(&wait_start); } -K_THREAD_DEFINE(socket_service_monitor, CONFIG_NET_SOCKETS_SERVICE_STACK_SIZE, - socket_service_thread, NULL, NULL, NULL, - CLAMP(CONFIG_NET_SOCKETS_SERVICE_THREAD_PRIO, - K_HIGHEST_APPLICATION_THREAD_PRIO, - K_LOWEST_APPLICATION_THREAD_PRIO), 0, 0); - static int init_socket_service(void) { - k_thread_name_set(socket_service_monitor, "net_socket_service"); + k_tid_t ssm; + static struct k_thread service_thread; + + static K_THREAD_STACK_DEFINE(service_thread_stack, + CONFIG_NET_SOCKETS_SERVICE_STACK_SIZE); + + ssm = k_thread_create(&service_thread, + service_thread_stack, + K_THREAD_STACK_SIZEOF(service_thread_stack), + (k_thread_entry_t)socket_service_thread, NULL, NULL, NULL, + CLAMP(CONFIG_NET_SOCKETS_SERVICE_THREAD_PRIO, + K_HIGHEST_APPLICATION_THREAD_PRIO, + K_LOWEST_APPLICATION_THREAD_PRIO), 0, K_NO_WAIT); + + k_thread_name_set(ssm, "net_socket_service"); return 0; } From 461eb711814da02a0eea14f06b42515758205aa8 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 20 Feb 2024 13:50:48 +0200 Subject: [PATCH 1587/1623] [nrf fromtree] net: sockets: Do not start service thread if too little resources If the CONFIG_NET_SOCKETS_POLL_MAX is smaller than what is needed for the socket service API to work properly, then we should not start the service thread as the service API cannot work and might cause memory overwrite in ctx.events[] array. Fixes #69233 Signed-off-by: Jukka Rissanen (cherry picked from commit ea189d5aeee1bfa728ecbc7818baa68d03d2a377) Signed-off-by: Robert Lubos --- subsys/net/lib/sockets/sockets_service.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/subsys/net/lib/sockets/sockets_service.c b/subsys/net/lib/sockets/sockets_service.c index 4c9270af116..89b653d31e5 100644 --- a/subsys/net/lib/sockets/sockets_service.c +++ b/subsys/net/lib/sockets/sockets_service.c @@ -195,11 +195,12 @@ static void socket_service_thread(void) } if ((count + 1) > ARRAY_SIZE(ctx.events)) { - NET_WARN("You have %d services to monitor but " - "%zd poll entries configured.", - count + 1, ARRAY_SIZE(ctx.events)); - NET_WARN("Consider increasing value of %s to %d", - "CONFIG_NET_SOCKETS_POLL_MAX", count + 1); + NET_ERR("You have %d services to monitor but " + "%zd poll entries configured.", + count + 1, ARRAY_SIZE(ctx.events)); + NET_ERR("Please increase value of %s to at least %d", + "CONFIG_NET_SOCKETS_POLL_MAX", count + 1); + goto fail; } NET_DBG("Monitoring %d socket entries", count); From 0a1854bb2c1eba17490d1c82ba1f749a5745fc1e Mon Sep 17 00:00:00 2001 From: Herman Berget Date: Tue, 27 Feb 2024 09:29:38 +0100 Subject: [PATCH 1588/1623] [nrf fromtree] Bluetooth: hci: Add hw variant definitions for nrf54H/L Assign new numbers for new soc series and update string conversion function. Signed-off-by: Herman Berget (cherry picked from commit 9135de7a66940f651a38f6117082eec36e3281b3) Signed-off-by: Herman Berget --- include/zephyr/bluetooth/hci_vs.h | 2 ++ subsys/bluetooth/controller/hci/nordic/hci_vendor.h | 4 ++++ subsys/bluetooth/host/hci_core.c | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/zephyr/bluetooth/hci_vs.h b/include/zephyr/bluetooth/hci_vs.h index aea92846e56..3561e20e9aa 100644 --- a/include/zephyr/bluetooth/hci_vs.h +++ b/include/zephyr/bluetooth/hci_vs.h @@ -47,6 +47,8 @@ extern "C" { #define BT_HCI_VS_HW_VAR_NORDIC_NRF51X 0x0001 #define BT_HCI_VS_HW_VAR_NORDIC_NRF52X 0x0002 #define BT_HCI_VS_HW_VAR_NORDIC_NRF53X 0x0003 +#define BT_HCI_VS_HW_VAR_NORDIC_NRF54HX 0x0004 +#define BT_HCI_VS_HW_VAR_NORDIC_NRF54LX 0x0005 #define BT_HCI_VS_FW_VAR_STANDARD_CTLR 0x0001 #define BT_HCI_VS_FW_VAR_VS_CTLR 0x0002 diff --git a/subsys/bluetooth/controller/hci/nordic/hci_vendor.h b/subsys/bluetooth/controller/hci/nordic/hci_vendor.h index bea7004f9c9..ecbe8968476 100644 --- a/subsys/bluetooth/controller/hci/nordic/hci_vendor.h +++ b/subsys/bluetooth/controller/hci/nordic/hci_vendor.h @@ -12,6 +12,10 @@ #define BT_HCI_VS_HW_VAR BT_HCI_VS_HW_VAR_NORDIC_NRF52X #elif defined(CONFIG_SOC_COMPATIBLE_NRF53X) #define BT_HCI_VS_HW_VAR BT_HCI_VS_HW_VAR_NORDIC_NRF53X +#elif defined(CONFIG_SOC_SERIES_NRF54HX) +#define BT_HCI_VS_HW_VAR BT_HCI_VS_HW_VAR_NORDIC_NRF54HX +#elif defined(CONFIG_SOC_SERIES_NRF54LX) +#define BT_HCI_VS_HW_VAR BT_HCI_VS_HW_VAR_NORDIC_NRF54LX #endif #else #define BT_HCI_VS_HW_PLAT 0 diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index dbb79f3ecdd..9b72e5548bc 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -3558,7 +3558,7 @@ static const char *vs_hw_platform(uint16_t platform) static const char *vs_hw_variant(uint16_t platform, uint16_t variant) { static const char * const nordic_str[] = { - "reserved", "nRF51x", "nRF52x", "nRF53x" + "reserved", "nRF51x", "nRF52x", "nRF53x", "nRF54Hx", "nRF54Lx" }; if (platform != BT_HCI_VS_HW_PLAT_NORDIC) { From 7735bc6d171ab2fe6590ab47171f5decdbe2ddfd Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Mon, 19 Feb 2024 11:26:12 +0100 Subject: [PATCH 1589/1623] [nrf fromtree] Bluetooth: Mesh: Enable CDP1 by default CDP1 is mandatory to qualify a mesh device for mesh protocol v1.1. The dependency on BT_MESH_MODEL_EXTENSIONS is removed because if a node contains only base models (for example Generic OnOff Server), this API will consume extra RAM bytes which won't be used. Signed-off-by: Pavel Vasilyev (cherry picked from commit e30b7a84bc421dc16e87c47deab1921186604830) Signed-off-by: Pavel Vasilyev --- subsys/bluetooth/mesh/Kconfig | 3 ++- subsys/bluetooth/mesh/access.c | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index e0b4761232c..ce845e995fd 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -712,7 +712,7 @@ config BT_MESH_MODEL_EXTENSIONS config BT_MESH_COMP_PAGE_1 bool "Support for Composition Data Page 1" - depends on BT_MESH_MODEL_EXTENSIONS + default y help Enable support for Composition Data Page 1. @@ -720,6 +720,7 @@ config BT_MESH_MODEL_EXTENSION_LIST_SIZE int "Model extensions list size" depends on BT_MESH_COMP_PAGE_1 range 0 255 + default 0 if !BT_MESH_MODEL_EXTENSIONS default 10 help This option specifies how many models relations can be saved. diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 4ff80333187..328ec0dd281 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -1066,13 +1066,13 @@ int bt_mesh_comp_register(const struct bt_mesh_comp *comp) err = 0; - if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { + if (MOD_REL_LIST_SIZE > 0) { memset(mod_rel_list, 0, sizeof(mod_rel_list)); } bt_mesh_model_foreach(mod_init, &err); - if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { + if (MOD_REL_LIST_SIZE > 0) { int i; MOD_REL_LIST_FOR_EACH(i) { @@ -1744,7 +1744,8 @@ static int mod_rel_register(const struct bt_mesh_model *base, return 0; } } - LOG_ERR("Failed to extend"); + + LOG_ERR("CONFIG_BT_MESH_MODEL_EXTENSION_LIST_SIZE is too small"); return -ENOMEM; } @@ -1784,8 +1785,11 @@ int bt_mesh_model_extend(const struct bt_mesh_model *extending_mod, } register_extension: - if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { + if (MOD_REL_LIST_SIZE > 0) { return mod_rel_register(base_mod, extending_mod, RELATION_TYPE_EXT); + } else if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { + LOG_ERR("CONFIG_BT_MESH_MODEL_EXTENSION_LIST_SIZE is too small"); + return -ENOMEM; } return 0; @@ -1797,7 +1801,7 @@ int bt_mesh_model_correspond(const struct bt_mesh_model *corresponding_mod, int i, err; uint8_t cor_id = 0; - if (!IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { + if (MOD_REL_LIST_SIZE == 0) { return -ENOTSUP; } From d2a11c2c29080669187bb77b1d658821cd1986e9 Mon Sep 17 00:00:00 2001 From: Kamil Piszczek Date: Tue, 7 Nov 2023 12:27:25 +0100 Subject: [PATCH 1590/1623] [nrf fromtree] settings: nvs: improve the name ID metadata handling on delete operation Improved the updates to the name ID metadata (NVS_NAMECNT_ID) item in the Settings NVS backend implementation. The improvements should make the implementation more robust in handling edge cases such as: power downs, resets or a case in which the storage partition is full. In the last case, the NVS backend could return an ENOSPC error in the context of the settings_delete API. This change also fixes this issue. Signed-off-by: Kamil Piszczek (cherry picked from commit 1ab08634f2799556e924cc8c7f70a60cd292ed4e) Signed-off-by: Pavel Vasilyev --- subsys/settings/src/settings_nvs.c | 59 ++++++++++++++++++------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/subsys/settings/src/settings_nvs.c b/subsys/settings/src/settings_nvs.c index 8e5bfbf3767..f1e53bfad22 100644 --- a/subsys/settings/src/settings_nvs.c +++ b/subsys/settings/src/settings_nvs.c @@ -147,6 +147,17 @@ static int settings_nvs_load(struct settings_store *cs, &buf, sizeof(buf)); if ((rc1 <= 0) && (rc2 <= 0)) { + /* Settings largest ID in use is invalid due to + * reset, power failure or partition overflow. + * Decrement it and check the next ID in subsequent + * iteration. + */ + if (name_id == cf->last_name_id) { + cf->last_name_id--; + nvs_write(&cf->cf_nvs, NVS_NAMECNT_ID, + &cf->last_name_id, sizeof(uint16_t)); + } + continue; } @@ -156,13 +167,15 @@ static int settings_nvs_load(struct settings_store *cs, * or deleted. Clean dirty entries to make space for * future settings item. */ + nvs_delete(&cf->cf_nvs, name_id); + nvs_delete(&cf->cf_nvs, name_id + NVS_NAME_ID_OFFSET); + if (name_id == cf->last_name_id) { cf->last_name_id--; nvs_write(&cf->cf_nvs, NVS_NAMECNT_ID, &cf->last_name_id, sizeof(uint16_t)); } - nvs_delete(&cf->cf_nvs, name_id); - nvs_delete(&cf->cf_nvs, name_id + NVS_NAME_ID_OFFSET); + continue; } @@ -254,6 +267,16 @@ static int settings_nvs_save(struct settings_store *cs, const char *name, return 0; } + rc = nvs_delete(&cf->cf_nvs, name_id); + if (rc >= 0) { + rc = nvs_delete(&cf->cf_nvs, name_id + + NVS_NAME_ID_OFFSET); + } + + if (rc < 0) { + return rc; + } + if (name_id == cf->last_name_id) { cf->last_name_id--; rc = nvs_write(&cf->cf_nvs, NVS_NAMECNT_ID, @@ -266,17 +289,6 @@ static int settings_nvs_save(struct settings_store *cs, const char *name, } } - rc = nvs_delete(&cf->cf_nvs, name_id); - - if (rc >= 0) { - rc = nvs_delete(&cf->cf_nvs, name_id + - NVS_NAME_ID_OFFSET); - } - - if (rc < 0) { - return rc; - } - return 0; } @@ -285,6 +297,16 @@ static int settings_nvs_save(struct settings_store *cs, const char *name, return -ENOMEM; } + /* update the last_name_id and write to flash if required*/ + if (write_name_id > cf->last_name_id) { + cf->last_name_id = write_name_id; + rc = nvs_write(&cf->cf_nvs, NVS_NAMECNT_ID, &cf->last_name_id, + sizeof(uint16_t)); + if (rc < 0) { + return rc; + } + } + /* write the value */ rc = nvs_write(&cf->cf_nvs, write_name_id + NVS_NAME_ID_OFFSET, value, val_len); @@ -300,17 +322,6 @@ static int settings_nvs_save(struct settings_store *cs, const char *name, } } - /* update the last_name_id and write to flash if required*/ - if (write_name_id > cf->last_name_id) { - cf->last_name_id = write_name_id; - rc = nvs_write(&cf->cf_nvs, NVS_NAMECNT_ID, &cf->last_name_id, - sizeof(uint16_t)); - } - - if (rc < 0) { - return rc; - } - return 0; } From db40a0187d5ba025a23fac055517adac3ad46474 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Mon, 12 Feb 2024 13:18:23 +0100 Subject: [PATCH 1591/1623] [nrf fromtree] settings: NVS: add entry into cache after writing Settings NVS adds entry into Settings NVS cache after writing it into flash. Previously, the entry was added into cache only on the second writing attempt that caused very huge timing despite cache was enabled since it was still empty. Signed-off-by: Aleksandr Khromykh (cherry picked from commit 6bb5076a2125e2446cf23e34139841cf320f2c40) Signed-off-by: Pavel Vasilyev --- subsys/settings/src/settings_nvs.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/subsys/settings/src/settings_nvs.c b/subsys/settings/src/settings_nvs.c index f1e53bfad22..c6efa6cb289 100644 --- a/subsys/settings/src/settings_nvs.c +++ b/subsys/settings/src/settings_nvs.c @@ -216,10 +216,13 @@ static int settings_nvs_save(struct settings_store *cs, const char *name, delete = ((value == NULL) || (val_len == 0)); #if CONFIG_SETTINGS_NVS_NAME_CACHE + bool name_in_cache = false; + name_id = settings_nvs_cache_match(cf, name, rdname, sizeof(rdname)); if (name_id != NVS_NAMECNT_ID) { write_name_id = name_id; write_name = false; + name_in_cache = true; goto found; } #endif @@ -251,9 +254,6 @@ static int settings_nvs_save(struct settings_store *cs, const char *name, } if (!delete) { -#if CONFIG_SETTINGS_NVS_NAME_CACHE - settings_nvs_cache_add(cf, name, name_id); -#endif write_name_id = name_id; write_name = false; } @@ -322,6 +322,12 @@ static int settings_nvs_save(struct settings_store *cs, const char *name, } } +#if CONFIG_SETTINGS_NVS_NAME_CACHE + if (!name_in_cache) { + settings_nvs_cache_add(cf, name, write_name_id); + } +#endif + return 0; } From 083222106e98fb886c82e1b71760c06396dc62fa Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 15 Feb 2024 21:37:53 +0100 Subject: [PATCH 1592/1623] [nrf fromtree] settings: nvs: Fix first write issue with cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: When the setting nvs cache is disabled and `settings_nvs_save` is called, the function reads all stored setting name entries from NVS until either finds the desired setting name entry or reaches the last stored setting name entry. With the settings nvs cache enabled, `settings_nvs_save` runs through the cached setting name entries first. If the cached entry matches with the desired one, it immediately writes the new setting value to NVS that corresponds to the cached setting name entry. However, if the setting name entry is not found in the cache (which is the case for a new entry), `settings_nvs_save` reads all stored setting name entries from NVS again. This means that even if the number of stored entries in the settings is less than the cache size, for each new setting entry to be stored `settings_nvs_save` will first run through the cache, then read all stored setting name entries from NVS and only then will pick the next free name id for this new setting name entry and will finally store the new setting entry. This makes the cache ineffiсient for every new entry to be stored even when the cache size is always able to keep all setting entries that will be stored in NVS. Use-case: In the Bluetooth mesh there is a Replay Protection List which keeps sequence numbers of all nodes it received messages from. The RPL is stored persistently in NVS. The setting name entry is the source address of the node and the setting value entry is the sequence number. The common use case is when RPL is quite big (for example, 255 entries). With the current settings nvs cache implementation, every time the node stores a new RPL entry in settings (which is the first received message from a particular source address), `settings_nvs_save` will always check the cache first, then also read all stored entries in NVS and only then will figure out that this is a new entry. With every new RPL entry to be stored this search time increases. This behavior results in much worse performance in comparison with when the corresponding entry was already stored. E.g. on nRF52840, with bare minimal mesh stack configuration, when the cache is bigger than number of stored entries or close to it, storing of 255 RPL entries takes ~25 seconds. The time of subsequent store of 255 RPL entires is ~2 seconds with the cache. Solution: This commit improves the behavior of the first write by bypassing the reading from NVS if the following conditions are met: 1. `settings_nvs_load` was called, 2. the cache was not overflowed (bigger than the number of stored entries). As long as these 2 conditiones are met, it is safe to skip reading from NVS, pick the next free name id and write the value immediately. Signed-off-by: Pavel Vasilyev (cherry picked from commit a35bb6608d4029ccdc9c7fc42113018b142f8ba7) Signed-off-by: Pavel Vasilyev --- .../settings/include/settings/settings_nvs.h | 2 ++ subsys/settings/src/settings_nvs.c | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/subsys/settings/include/settings/settings_nvs.h b/subsys/settings/include/settings/settings_nvs.h index ce34e192c24..6db576da631 100644 --- a/subsys/settings/include/settings/settings_nvs.h +++ b/subsys/settings/include/settings/settings_nvs.h @@ -45,6 +45,8 @@ struct settings_nvs { } cache[CONFIG_SETTINGS_NVS_NAME_CACHE_SIZE]; uint16_t cache_next; + uint16_t cache_total; + bool loaded; #endif }; diff --git a/subsys/settings/src/settings_nvs.c b/subsys/settings/src/settings_nvs.c index c6efa6cb289..6764c7587a3 100644 --- a/subsys/settings/src/settings_nvs.c +++ b/subsys/settings/src/settings_nvs.c @@ -74,6 +74,8 @@ int settings_nvs_dst(struct settings_nvs *cf) } #if CONFIG_SETTINGS_NVS_NAME_CACHE +#define SETTINGS_NVS_CACHE_OVFL(cf) ((cf)->cache_total > ARRAY_SIZE((cf)->cache)) + static void settings_nvs_cache_add(struct settings_nvs *cf, const char *name, uint16_t name_id) { @@ -129,12 +131,22 @@ static int settings_nvs_load(struct settings_store *cs, ssize_t rc1, rc2; uint16_t name_id = NVS_NAMECNT_ID; +#if CONFIG_SETTINGS_NVS_NAME_CACHE + uint16_t cached = 0; + + cf->loaded = false; +#endif + name_id = cf->last_name_id + 1; while (1) { name_id--; if (name_id == NVS_NAMECNT_ID) { +#if CONFIG_SETTINGS_NVS_NAME_CACHE + cf->loaded = true; + cf->cache_total = cached; +#endif break; } @@ -186,6 +198,7 @@ static int settings_nvs_load(struct settings_store *cs, #if CONFIG_SETTINGS_NVS_NAME_CACHE settings_nvs_cache_add(cf, name, name_id); + cached++; #endif ret = settings_call_set_handler( @@ -231,6 +244,13 @@ static int settings_nvs_save(struct settings_store *cs, const char *name, write_name_id = cf->last_name_id + 1; write_name = true; +#if CONFIG_SETTINGS_NVS_NAME_CACHE + /* We can skip reading NVS if we know that the cache wasn't overflowed. */ + if (cf->loaded && !SETTINGS_NVS_CACHE_OVFL(cf)) { + goto found; + } +#endif + while (1) { name_id--; if (name_id == NVS_NAMECNT_ID) { @@ -325,6 +345,9 @@ static int settings_nvs_save(struct settings_store *cs, const char *name, #if CONFIG_SETTINGS_NVS_NAME_CACHE if (!name_in_cache) { settings_nvs_cache_add(cf, name, write_name_id); + if (cf->loaded && !SETTINGS_NVS_CACHE_OVFL(cf)) { + cf->cache_total++; + } } #endif From 20fd0a0d5bd3daa1c33a70a5acd78d60f1c7316e Mon Sep 17 00:00:00 2001 From: Kapil Bhatt Date: Wed, 28 Feb 2024 15:51:50 +0530 Subject: [PATCH 1593/1623] Revert "[nrf fromlist] net: ensure the sh is valid before call shell_printf" This reverts commit d0effecc0cbcce1fc40659577237265ce1817ae3. Signed-off-by: Kapil Bhatt --- subsys/net/lib/shell/net_shell_private.h | 40 ++++++------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/subsys/net/lib/shell/net_shell_private.h b/subsys/net/lib/shell/net_shell_private.h index 6d70d321f60..8b5566022d9 100644 --- a/subsys/net/lib/shell/net_shell_private.h +++ b/subsys/net/lib/shell/net_shell_private.h @@ -8,40 +8,20 @@ #include #include -#define PR(fmt, ...) \ - do { \ - if (sh) { \ - shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__); \ - } \ - } while (false) +#define PR(fmt, ...) \ + shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__) -#define PR_SHELL(sh, fmt, ...) \ - do { \ - if (sh) { \ - shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__); \ - } \ - } while (false) +#define PR_SHELL(sh, fmt, ...) \ + shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__) -#define PR_ERROR(fmt, ...) \ - do { \ - if (sh) { \ - shell_fprintf(sh, SHELL_ERROR, fmt, ##__VA_ARGS__); \ - } \ - } while (false) +#define PR_ERROR(fmt, ...) \ + shell_fprintf(sh, SHELL_ERROR, fmt, ##__VA_ARGS__) -#define PR_INFO(fmt, ...) \ - do { \ - if (sh) { \ - shell_fprintf(sh, SHELL_INFO, fmt, ##__VA_ARGS__); \ - } \ - } while (false) +#define PR_INFO(fmt, ...) \ + shell_fprintf(sh, SHELL_INFO, fmt, ##__VA_ARGS__) -#define PR_WARNING(fmt, ...) \ - do { \ - if (sh) { \ - shell_fprintf(sh, SHELL_WARNING, fmt, ##__VA_ARGS__); \ - } \ - } while (false) +#define PR_WARNING(fmt, ...) \ + shell_fprintf(sh, SHELL_WARNING, fmt, ##__VA_ARGS__) #include "net_private.h" #include "../ip/ipv6.h" From e4827fba2254402b99a7be249974de4e0acbcba1 Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Fri, 9 Feb 2024 21:03:47 +0700 Subject: [PATCH 1594/1623] [nrf fromtree] net: shell: ensure the shell `sh` is valid before call shell_printf It is possible that the `sh` was not set before use. This change adds a NULL check for `sh` in the following macros: PR, PR_SHELL, PR_ERROR, PR_INFO, and PR_WARNING. In case `sh` is NULL, the above macros will call `printk` instead. Fixes #68793 Signed-off-by: Pisit Sawangvonganan (cherry picked from commit 7b8a9e1818f75a2a61ea40537a9d4299eb3225a6) Signed-off-by: Kapil Bhatt --- subsys/net/lib/shell/net_shell_private.h | 50 +++++++++++++++++++----- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/subsys/net/lib/shell/net_shell_private.h b/subsys/net/lib/shell/net_shell_private.h index 8b5566022d9..076bfd63d33 100644 --- a/subsys/net/lib/shell/net_shell_private.h +++ b/subsys/net/lib/shell/net_shell_private.h @@ -8,20 +8,50 @@ #include #include -#define PR(fmt, ...) \ - shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__) +#define PR(fmt, ...) \ + do { \ + if (sh) { \ + shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__); \ + } else { \ + printk(fmt, ##__VA_ARGS__); \ + } \ + } while (false) -#define PR_SHELL(sh, fmt, ...) \ - shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__) +#define PR_SHELL(sh, fmt, ...) \ + do { \ + if (sh) { \ + shell_fprintf(sh, SHELL_NORMAL, fmt, ##__VA_ARGS__); \ + } else { \ + printk(fmt, ##__VA_ARGS__); \ + } \ + } while (false) -#define PR_ERROR(fmt, ...) \ - shell_fprintf(sh, SHELL_ERROR, fmt, ##__VA_ARGS__) +#define PR_ERROR(fmt, ...) \ + do { \ + if (sh) { \ + shell_fprintf(sh, SHELL_ERROR, fmt, ##__VA_ARGS__); \ + } else { \ + printk(fmt, ##__VA_ARGS__); \ + } \ + } while (false) -#define PR_INFO(fmt, ...) \ - shell_fprintf(sh, SHELL_INFO, fmt, ##__VA_ARGS__) +#define PR_INFO(fmt, ...) \ + do { \ + if (sh) { \ + shell_fprintf(sh, SHELL_INFO, fmt, ##__VA_ARGS__); \ + } else { \ + printk(fmt, ##__VA_ARGS__); \ + } \ + } while (false) -#define PR_WARNING(fmt, ...) \ - shell_fprintf(sh, SHELL_WARNING, fmt, ##__VA_ARGS__) +#define PR_WARNING(fmt, ...) \ + do { \ + if (sh) { \ + shell_fprintf(sh, SHELL_WARNING, fmt, ##__VA_ARGS__); \ + } else { \ + printk(fmt, ##__VA_ARGS__); \ + } \ + } while (false) #include "net_private.h" #include "../ip/ipv6.h" From fc7d362601fe4c0581b111e79bbba6d6b8a9fecb Mon Sep 17 00:00:00 2001 From: Tomas Galbicka Date: Thu, 21 Dec 2023 14:15:22 +0000 Subject: [PATCH 1595/1623] [nrf fromtree] samples: mbox: Add support for NXP RT boards This commit adds mbox sample support for these NXP boards: - MIMXRT1160-EVK - MIMXRT1170-EVK - MIMXRT1170-EVKB Signed-off-by: Tomas Galbicka (cherry picked from commit d161d05e3390c373d532887e9e36eaa5e4663c19) --- samples/drivers/mbox/CMakeLists.txt | 11 +++++ samples/drivers/mbox/Kconfig | 11 +++++ samples/drivers/mbox/Kconfig.sysbuild | 4 ++ .../mbox/boards/mimxrt1160_evk_cm7.conf | 3 ++ .../mbox/boards/mimxrt1160_evk_cm7.overlay | 29 +++++++++++ .../mbox/boards/mimxrt1170_evk_cm7.conf | 3 ++ .../mbox/boards/mimxrt1170_evk_cm7.overlay | 29 +++++++++++ .../mbox/boards/mimxrt1170_evkb_cm7.conf | 3 ++ .../mbox/boards/mimxrt1170_evkb_cm7.overlay | 29 +++++++++++ samples/drivers/mbox/remote/CMakeLists.txt | 4 ++ .../remote/boards/mimxrt1160_evk_cm4.conf | 4 ++ .../remote/boards/mimxrt1160_evk_cm4.overlay | 48 ++++++++++++++++++ .../remote/boards/mimxrt1170_evk_cm4.conf | 4 ++ .../remote/boards/mimxrt1170_evk_cm4.overlay | 48 ++++++++++++++++++ .../remote/boards/mimxrt1170_evkb_cm4.conf | 4 ++ .../remote/boards/mimxrt1170_evkb_cm4.overlay | 49 +++++++++++++++++++ samples/drivers/mbox/sample.yaml | 13 ++++- samples/drivers/mbox/sysbuild.cmake | 12 +++++ 18 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 samples/drivers/mbox/Kconfig create mode 100644 samples/drivers/mbox/boards/mimxrt1160_evk_cm7.conf create mode 100644 samples/drivers/mbox/boards/mimxrt1160_evk_cm7.overlay create mode 100644 samples/drivers/mbox/boards/mimxrt1170_evk_cm7.conf create mode 100644 samples/drivers/mbox/boards/mimxrt1170_evk_cm7.overlay create mode 100644 samples/drivers/mbox/boards/mimxrt1170_evkb_cm7.conf create mode 100644 samples/drivers/mbox/boards/mimxrt1170_evkb_cm7.overlay create mode 100644 samples/drivers/mbox/remote/boards/mimxrt1160_evk_cm4.conf create mode 100644 samples/drivers/mbox/remote/boards/mimxrt1160_evk_cm4.overlay create mode 100644 samples/drivers/mbox/remote/boards/mimxrt1170_evk_cm4.conf create mode 100644 samples/drivers/mbox/remote/boards/mimxrt1170_evk_cm4.overlay create mode 100644 samples/drivers/mbox/remote/boards/mimxrt1170_evkb_cm4.conf create mode 100644 samples/drivers/mbox/remote/boards/mimxrt1170_evkb_cm4.overlay diff --git a/samples/drivers/mbox/CMakeLists.txt b/samples/drivers/mbox/CMakeLists.txt index e65d44f0048..4344f4f3ce9 100644 --- a/samples/drivers/mbox/CMakeLists.txt +++ b/samples/drivers/mbox/CMakeLists.txt @@ -1,5 +1,6 @@ # # Copyright (c) 2021 Carlo Caione +# Copyright 2023 NXP # # SPDX-License-Identifier: Apache-2.0 # @@ -8,9 +9,14 @@ cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/../remote/zephyr) + if(("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpuapp") OR ("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp") OR ("${BOARD}" STREQUAL "adp_xc7k_ae350") OR + ("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7") OR + ("${BOARD}" STREQUAL "mimxrt1170_evk_cm7") OR + ("${BOARD}" STREQUAL "mimxrt1160_evk_cm7") OR ("${BOARD}" STREQUAL "mimxrt595_evk_cm33")) message(STATUS "${BOARD} compile as Main in this sample") else() @@ -21,4 +27,9 @@ project(mbox_ipc) enable_language(C ASM) +if(CONFIG_INCLUDE_REMOTE_DIR) + target_include_directories(zephyr_interface + INTERFACE ${REMOTE_ZEPHYR_DIR}/include/public) +endif() + target_sources(app PRIVATE src/main.c) diff --git a/samples/drivers/mbox/Kconfig b/samples/drivers/mbox/Kconfig new file mode 100644 index 00000000000..3837c49b6e9 --- /dev/null +++ b/samples/drivers/mbox/Kconfig @@ -0,0 +1,11 @@ +# Copyright 2023 NXP +# +# SPDX-License-Identifier: Apache-2.0 + +source "Kconfig.zephyr" + +config INCLUDE_REMOTE_DIR + bool "Include remote core header directory" + help + Include remote build header files. Can be used if primary image + needs to be aware of size or base address of secondary image diff --git a/samples/drivers/mbox/Kconfig.sysbuild b/samples/drivers/mbox/Kconfig.sysbuild index 46ffe3e12ae..f472576df82 100644 --- a/samples/drivers/mbox/Kconfig.sysbuild +++ b/samples/drivers/mbox/Kconfig.sysbuild @@ -1,4 +1,5 @@ # Copyright 2023 Nordic Semiconductor ASA +# Copyright 2023 NXP # # SPDX-License-Identifier: Apache-2.0 @@ -10,3 +11,6 @@ string default "nrf5340bsim_nrf5340_cpunet" if $(BOARD) = "nrf5340bsim_nrf5340_cpuapp" default "adp_xc7k_ae350" if $(BOARD) = "adp_xc7k_ae350" default "nrf5340dk_nrf5340_cpunet" if $(BOARD) = "mimxrt595_evk_cm33" + default "mimxrt1170_evkb_cm4" if $(BOARD) = "mimxrt1170_evkb_cm7" + default "mimxrt1170_evk_cm4" if $(BOARD) = "mimxrt1170_evk_cm7" + default "mimxrt1160_evk_cm4" if $(BOARD) = "mimxrt1160_evk_cm7" diff --git a/samples/drivers/mbox/boards/mimxrt1160_evk_cm7.conf b/samples/drivers/mbox/boards/mimxrt1160_evk_cm7.conf new file mode 100644 index 00000000000..583b4950360 --- /dev/null +++ b/samples/drivers/mbox/boards/mimxrt1160_evk_cm7.conf @@ -0,0 +1,3 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_INCLUDE_REMOTE_DIR=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/samples/drivers/mbox/boards/mimxrt1160_evk_cm7.overlay b/samples/drivers/mbox/boards/mimxrt1160_evk_cm7.overlay new file mode 100644 index 00000000000..942f67ba6a9 --- /dev/null +++ b/samples/drivers/mbox/boards/mimxrt1160_evk_cm7.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2023 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c48000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c48000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c48000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/samples/drivers/mbox/boards/mimxrt1170_evk_cm7.conf b/samples/drivers/mbox/boards/mimxrt1170_evk_cm7.conf new file mode 100644 index 00000000000..583b4950360 --- /dev/null +++ b/samples/drivers/mbox/boards/mimxrt1170_evk_cm7.conf @@ -0,0 +1,3 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_INCLUDE_REMOTE_DIR=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/samples/drivers/mbox/boards/mimxrt1170_evk_cm7.overlay b/samples/drivers/mbox/boards/mimxrt1170_evk_cm7.overlay new file mode 100644 index 00000000000..942f67ba6a9 --- /dev/null +++ b/samples/drivers/mbox/boards/mimxrt1170_evk_cm7.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2023 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c48000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c48000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c48000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/samples/drivers/mbox/boards/mimxrt1170_evkb_cm7.conf b/samples/drivers/mbox/boards/mimxrt1170_evkb_cm7.conf new file mode 100644 index 00000000000..0dfb100ed70 --- /dev/null +++ b/samples/drivers/mbox/boards/mimxrt1170_evkb_cm7.conf @@ -0,0 +1,3 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_SECOND_CORE_MCUX=y +CONFIG_INCLUDE_REMOTE_DIR=y diff --git a/samples/drivers/mbox/boards/mimxrt1170_evkb_cm7.overlay b/samples/drivers/mbox/boards/mimxrt1170_evkb_cm7.overlay new file mode 100644 index 00000000000..942f67ba6a9 --- /dev/null +++ b/samples/drivers/mbox/boards/mimxrt1170_evkb_cm7.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2023 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c48000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c48000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c48000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/samples/drivers/mbox/remote/CMakeLists.txt b/samples/drivers/mbox/remote/CMakeLists.txt index 3aee2d96482..e7db9b8cadf 100644 --- a/samples/drivers/mbox/remote/CMakeLists.txt +++ b/samples/drivers/mbox/remote/CMakeLists.txt @@ -1,5 +1,6 @@ # # Copyright (c) 2021 Carlo Caione +# Copyright 2023 NXP # # SPDX-License-Identifier: Apache-2.0 # @@ -10,6 +11,9 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) if(("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet") OR ("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpunet") OR + ("${BOARD}" STREQUAL "mimxrt1170_evkb_cm4") OR + ("${BOARD}" STREQUAL "mimxrt1170_evk_cm4") OR + ("${BOARD}" STREQUAL "mimxrt1160_evk_cm4") OR ("${BOARD}" STREQUAL "adp_xc7k_ae350")) message(STATUS "${BOARD} compile as remote in this sample") else() diff --git a/samples/drivers/mbox/remote/boards/mimxrt1160_evk_cm4.conf b/samples/drivers/mbox/remote/boards/mimxrt1160_evk_cm4.conf new file mode 100644 index 00000000000..0d36a72aec6 --- /dev/null +++ b/samples/drivers/mbox/remote/boards/mimxrt1160_evk_cm4.conf @@ -0,0 +1,4 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_BUILD_OUTPUT_INFO_HEADER=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/samples/drivers/mbox/remote/boards/mimxrt1160_evk_cm4.overlay b/samples/drivers/mbox/remote/boards/mimxrt1160_evk_cm4.overlay new file mode 100644 index 00000000000..cc05e9b96c1 --- /dev/null +++ b/samples/drivers/mbox/remote/boards/mimxrt1160_evk_cm4.overlay @@ -0,0 +1,48 @@ +/* + * Copyright 2023 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,flash = &ocram; + zephyr,console = &lpuart1; + zephyr,shell-uart = &lpuart1; + + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /delete-node/ gpt@400f0000; + + /* Replace GPT2 with another GPT kernel timer */ + gpt2_hw_timer:gpt@400f0000 { + compatible = "nxp,gpt-hw-timer"; + reg = <0x400f0000 0x4000>; + interrupts = <120 0>; + status = "okay"; + }; + + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c4c000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c4c000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c4c000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; + +/* Disable primary GPT timer */ +&gpt_hw_timer { + status = "disabled"; +}; diff --git a/samples/drivers/mbox/remote/boards/mimxrt1170_evk_cm4.conf b/samples/drivers/mbox/remote/boards/mimxrt1170_evk_cm4.conf new file mode 100644 index 00000000000..0d36a72aec6 --- /dev/null +++ b/samples/drivers/mbox/remote/boards/mimxrt1170_evk_cm4.conf @@ -0,0 +1,4 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_BUILD_OUTPUT_INFO_HEADER=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/samples/drivers/mbox/remote/boards/mimxrt1170_evk_cm4.overlay b/samples/drivers/mbox/remote/boards/mimxrt1170_evk_cm4.overlay new file mode 100644 index 00000000000..cc05e9b96c1 --- /dev/null +++ b/samples/drivers/mbox/remote/boards/mimxrt1170_evk_cm4.overlay @@ -0,0 +1,48 @@ +/* + * Copyright 2023 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,flash = &ocram; + zephyr,console = &lpuart1; + zephyr,shell-uart = &lpuart1; + + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /delete-node/ gpt@400f0000; + + /* Replace GPT2 with another GPT kernel timer */ + gpt2_hw_timer:gpt@400f0000 { + compatible = "nxp,gpt-hw-timer"; + reg = <0x400f0000 0x4000>; + interrupts = <120 0>; + status = "okay"; + }; + + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c4c000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c4c000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c4c000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; + +/* Disable primary GPT timer */ +&gpt_hw_timer { + status = "disabled"; +}; diff --git a/samples/drivers/mbox/remote/boards/mimxrt1170_evkb_cm4.conf b/samples/drivers/mbox/remote/boards/mimxrt1170_evkb_cm4.conf new file mode 100644 index 00000000000..0d36a72aec6 --- /dev/null +++ b/samples/drivers/mbox/remote/boards/mimxrt1170_evkb_cm4.conf @@ -0,0 +1,4 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_BUILD_OUTPUT_INFO_HEADER=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/samples/drivers/mbox/remote/boards/mimxrt1170_evkb_cm4.overlay b/samples/drivers/mbox/remote/boards/mimxrt1170_evkb_cm4.overlay new file mode 100644 index 00000000000..392141712a9 --- /dev/null +++ b/samples/drivers/mbox/remote/boards/mimxrt1170_evkb_cm4.overlay @@ -0,0 +1,49 @@ +/* + * Copyright 2023 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,flash = &ocram; + zephyr,console = &lpuart1; + zephyr,shell-uart = &lpuart1; + + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /delete-node/ gpt@400f0000; + + /* Replace GPT2 with another GPT kernel timer */ + gpt2_hw_timer:gpt@400f0000 { + compatible = "nxp,gpt-hw-timer"; + reg = <0x400f0000 0x4000>; + interrupts = <120 0>; + status = "okay"; + }; + + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c4c000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c4c000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c4c000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; + +}; + +/* Disable primary GPT timer */ +&gpt_hw_timer { + status = "disabled"; +}; diff --git a/samples/drivers/mbox/sample.yaml b/samples/drivers/mbox/sample.yaml index f7aa8953ea1..e8015cf7c25 100644 --- a/samples/drivers/mbox/sample.yaml +++ b/samples/drivers/mbox/sample.yaml @@ -9,9 +9,20 @@ tests: - nrf5340dk_nrf5340_cpuapp - adp_xc7k_ae350 - mimxrt595_evk_cm33 + - mimxrt1170_evkb_cm7 + - mimxrt1170_evk_cm7 + - mimxrt1160_evk_cm7 integration_platforms: - nrf5340dk_nrf5340_cpuapp - harness: remote + harness: console + harness_config: + type: multi_line + ordered: false + regex: + - "Ping \\(on channel 0\\)" + - "Pong \\(on channel 0\\)" + - "Ping \\(on channel 1\\)" + - "Pong \\(on channel 1\\)" sample.drivers.mbox.simu: platform_allow: - nrf5340bsim_nrf5340_cpuapp diff --git a/samples/drivers/mbox/sysbuild.cmake b/samples/drivers/mbox/sysbuild.cmake index a8dfb8ebdf4..7a5d32d4c74 100644 --- a/samples/drivers/mbox/sysbuild.cmake +++ b/samples/drivers/mbox/sysbuild.cmake @@ -1,4 +1,5 @@ # Copyright (c) 2023 Nordic Semiconductor ASA +# Copyright 2023 NXP # SPDX-License-Identifier: Apache-2.0 if("${SB_CONFIG_REMOTE_BOARD}" STREQUAL "") @@ -18,3 +19,14 @@ ExternalZephyrProject_Add( native_simulator_set_child_images(${DEFAULT_IMAGE} ${REMOTE_APP}) native_simulator_set_final_executable(${DEFAULT_IMAGE}) + +if ("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7" OR + "${BOARD}" STREQUAL "mimxrt1170_evk_cm7" OR + "${BOARD}" STREQUAL "mimxrt1160_evk_cm7" + ) + # For these NXP boards the main core application is dependent on + # 'zephyr_image_info.h' generated by remote application. + + # Let's build the remote application first + add_dependencies(${DEFAULT_IMAGE} ${REMOTE_APP}) +endif() From 6d7dc5e730dde6fc1aa91819a3e6c44d1fe109f6 Mon Sep 17 00:00:00 2001 From: Tomas Galbicka Date: Fri, 12 Jan 2024 15:48:59 +0100 Subject: [PATCH 1596/1623] [nrf fromtree] samples: mbox: Add mbox sample with data transfer This commits add mbox sample which supports transfering of 4 bytes of data between cores. Signed-off-by: Tomas Galbicka (cherry picked from commit e776051cadfd9d723be6cbebeb2a41d2f94aec6a) --- samples/drivers/mbox_data/CMakeLists.txt | 29 ++++++ samples/drivers/mbox_data/Kconfig | 11 +++ samples/drivers/mbox_data/Kconfig.sysbuild | 11 +++ samples/drivers/mbox_data/README.rst | 95 +++++++++++++++++++ .../mbox_data/boards/mimxrt1160_evk_cm7.conf | 3 + .../boards/mimxrt1160_evk_cm7.overlay | 29 ++++++ .../mbox_data/boards/mimxrt1170_evk_cm7.conf | 3 + .../boards/mimxrt1170_evk_cm7.overlay | 29 ++++++ .../mbox_data/boards/mimxrt1170_evkb_cm7.conf | 3 + .../boards/mimxrt1170_evkb_cm7.overlay | 29 ++++++ samples/drivers/mbox_data/prj.conf | 2 + .../drivers/mbox_data/remote/CMakeLists.txt | 20 ++++ .../remote/boards/mimxrt1160_evk_cm4.conf | 4 + .../remote/boards/mimxrt1160_evk_cm4.overlay | 54 +++++++++++ .../remote/boards/mimxrt1170_evk_cm4.conf | 4 + .../remote/boards/mimxrt1170_evk_cm4.overlay | 54 +++++++++++ .../remote/boards/mimxrt1170_evkb_cm4.conf | 4 + .../remote/boards/mimxrt1170_evkb_cm4.overlay | 55 +++++++++++ samples/drivers/mbox_data/remote/prj.conf | 2 + samples/drivers/mbox_data/remote/src/main.c | 75 +++++++++++++++ samples/drivers/mbox_data/sample.yaml | 27 ++++++ samples/drivers/mbox_data/src/main.c | 74 +++++++++++++++ samples/drivers/mbox_data/sysbuild.cmake | 28 ++++++ 23 files changed, 645 insertions(+) create mode 100644 samples/drivers/mbox_data/CMakeLists.txt create mode 100644 samples/drivers/mbox_data/Kconfig create mode 100644 samples/drivers/mbox_data/Kconfig.sysbuild create mode 100644 samples/drivers/mbox_data/README.rst create mode 100644 samples/drivers/mbox_data/boards/mimxrt1160_evk_cm7.conf create mode 100644 samples/drivers/mbox_data/boards/mimxrt1160_evk_cm7.overlay create mode 100644 samples/drivers/mbox_data/boards/mimxrt1170_evk_cm7.conf create mode 100644 samples/drivers/mbox_data/boards/mimxrt1170_evk_cm7.overlay create mode 100644 samples/drivers/mbox_data/boards/mimxrt1170_evkb_cm7.conf create mode 100644 samples/drivers/mbox_data/boards/mimxrt1170_evkb_cm7.overlay create mode 100644 samples/drivers/mbox_data/prj.conf create mode 100644 samples/drivers/mbox_data/remote/CMakeLists.txt create mode 100644 samples/drivers/mbox_data/remote/boards/mimxrt1160_evk_cm4.conf create mode 100644 samples/drivers/mbox_data/remote/boards/mimxrt1160_evk_cm4.overlay create mode 100644 samples/drivers/mbox_data/remote/boards/mimxrt1170_evk_cm4.conf create mode 100644 samples/drivers/mbox_data/remote/boards/mimxrt1170_evk_cm4.overlay create mode 100644 samples/drivers/mbox_data/remote/boards/mimxrt1170_evkb_cm4.conf create mode 100644 samples/drivers/mbox_data/remote/boards/mimxrt1170_evkb_cm4.overlay create mode 100644 samples/drivers/mbox_data/remote/prj.conf create mode 100644 samples/drivers/mbox_data/remote/src/main.c create mode 100644 samples/drivers/mbox_data/sample.yaml create mode 100644 samples/drivers/mbox_data/src/main.c create mode 100644 samples/drivers/mbox_data/sysbuild.cmake diff --git a/samples/drivers/mbox_data/CMakeLists.txt b/samples/drivers/mbox_data/CMakeLists.txt new file mode 100644 index 00000000000..a67552bf52e --- /dev/null +++ b/samples/drivers/mbox_data/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright 2024 NXP +# +# SPDX-License-Identifier: Apache-2.0 +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/../remote/zephyr) + +if(("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7") OR + ("${BOARD}" STREQUAL "mimxrt1170_evk_cm7") OR + ("${BOARD}" STREQUAL "mimxrt1160_evk_cm7")) + message(STATUS "${BOARD} compile as Main in this sample") +else() + message(FATAL_ERROR "${BOARD} is not supported for this sample") +endif() + +project(mbox_data_ipc) + +enable_language(C ASM) + +if(CONFIG_INCLUDE_REMOTE_DIR) + target_include_directories(zephyr_interface + INTERFACE ${REMOTE_ZEPHYR_DIR}/include/public) +endif() + +target_sources(app PRIVATE src/main.c) diff --git a/samples/drivers/mbox_data/Kconfig b/samples/drivers/mbox_data/Kconfig new file mode 100644 index 00000000000..ee3874c39f9 --- /dev/null +++ b/samples/drivers/mbox_data/Kconfig @@ -0,0 +1,11 @@ +# Copyright 2024 NXP +# +# SPDX-License-Identifier: Apache-2.0 + +source "Kconfig.zephyr" + +config INCLUDE_REMOTE_DIR + bool "Include remote core header directory" + help + Include remote build header files. Can be used if primary image + needs to be aware of size or base address of secondary image diff --git a/samples/drivers/mbox_data/Kconfig.sysbuild b/samples/drivers/mbox_data/Kconfig.sysbuild new file mode 100644 index 00000000000..e355713e714 --- /dev/null +++ b/samples/drivers/mbox_data/Kconfig.sysbuild @@ -0,0 +1,11 @@ +# Copyright 2024 NXP +# +# SPDX-License-Identifier: Apache-2.0 + +source "share/sysbuild/Kconfig" + +config REMOTE_BOARD +string + default "mimxrt1170_evkb_cm4" if $(BOARD) = "mimxrt1170_evkb_cm7" + default "mimxrt1170_evk_cm4" if $(BOARD) = "mimxrt1170_evk_cm7" + default "mimxrt1160_evk_cm4" if $(BOARD) = "mimxrt1160_evk_cm7" diff --git a/samples/drivers/mbox_data/README.rst b/samples/drivers/mbox_data/README.rst new file mode 100644 index 00000000000..3ead1ec3b87 --- /dev/null +++ b/samples/drivers/mbox_data/README.rst @@ -0,0 +1,95 @@ +.. zephyr:code-sample:: mbox_data + :name: MBOX Data + :relevant-api: mbox_interface + + Perform inter-processor mailbox communication using the MBOX API with data. + +Overview +******** + +This sample demonstrates how to use the :ref:`MBOX API ` in data transfer mode. +It can be used only with mbox driver which supports data transfer mode. + +Sample will ping-pong 4 bytes of data between two cores via two mbox channels. +After each core receives data, it increments it by one and sends it back to other core. + +Building and Running +******************** + +The sample can be built and executed on boards supporting MBOX with data transfer mode. + +Building the application for mimxrt1160_evk_cm7 +=============================================== + +.. zephyr-app-commands:: + :zephyr-app: samples/drivers/mbox_data/ + :board: mimxrt1160_evk_cm7 + :goals: debug + :west-args: --sysbuild + +Building the application for mimxrt1170_evk_cm7 +=============================================== + +.. zephyr-app-commands:: + :zephyr-app: samples/drivers/mbox_data/ + :board: mimxrt1170_evk_cm7 + :goals: debug + :west-args: --sysbuild + +Building the application for mimxrt1170_evkb_cm7 +================================================ + +.. zephyr-app-commands:: + :zephyr-app: samples/drivers/mbox_data/ + :board: mimxrt1170_evkb_cm7 + :goals: debug + :west-args: --sysbuild + +Sample Output +============= + +Open a serial terminal (minicom, putty, etc.) and connect the board with the +following settings: + +- Speed: 115200 +- Data: 8 bits +- Parity: None +- Stop bits: 1 + +Reset the board and the following message will appear on the corresponding +serial port, one is the main core another is the remote core: + +.. code-block:: console + + *** Booting Zephyr OS build zephyr-v3.5.0-4051-g12f4f4dc8679 *** + mbox_data Client demo started + Client send (on channel 3) value: 0 + Client received (on channel 2) value: 1 + Client send (on channel 3) value: 2 + Client received (on channel 2) value: 3 + Client send (on channel 3) value: 4 + ... + Client received (on channel 2) value: 95 + Client send (on channel 3) value: 96 + Client received (on channel 2) value: 97 + Client send (on channel 3) value: 98 + Client received (on channel 2) value: 99 + mbox_data Client demo ended + + +.. code-block:: console + + *** Booting Zephyr OS build zephyr-v3.5.0-4051-g12f4f4dc8679 *** + mbox_data Server demo started + Server receive (on channel 3) value: 0 + Server send (on channel 2) value: 1 + Server receive (on channel 3) value: 2 + Server send (on channel 2) value: 3 + Server receive (on channel 3) value: 4 + ... + Server send (on channel 2) value: 95 + Server receive (on channel 3) value: 96 + Server send (on channel 2) value: 97 + Server receive (on channel 3) value: 98 + Server send (on channel 2) value: 99 + mbox_data Server demo ended. diff --git a/samples/drivers/mbox_data/boards/mimxrt1160_evk_cm7.conf b/samples/drivers/mbox_data/boards/mimxrt1160_evk_cm7.conf new file mode 100644 index 00000000000..583b4950360 --- /dev/null +++ b/samples/drivers/mbox_data/boards/mimxrt1160_evk_cm7.conf @@ -0,0 +1,3 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_INCLUDE_REMOTE_DIR=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/samples/drivers/mbox_data/boards/mimxrt1160_evk_cm7.overlay b/samples/drivers/mbox_data/boards/mimxrt1160_evk_cm7.overlay new file mode 100644 index 00000000000..870b9928faf --- /dev/null +++ b/samples/drivers/mbox_data/boards/mimxrt1160_evk_cm7.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c48000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c48000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c48000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/samples/drivers/mbox_data/boards/mimxrt1170_evk_cm7.conf b/samples/drivers/mbox_data/boards/mimxrt1170_evk_cm7.conf new file mode 100644 index 00000000000..583b4950360 --- /dev/null +++ b/samples/drivers/mbox_data/boards/mimxrt1170_evk_cm7.conf @@ -0,0 +1,3 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_INCLUDE_REMOTE_DIR=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/samples/drivers/mbox_data/boards/mimxrt1170_evk_cm7.overlay b/samples/drivers/mbox_data/boards/mimxrt1170_evk_cm7.overlay new file mode 100644 index 00000000000..870b9928faf --- /dev/null +++ b/samples/drivers/mbox_data/boards/mimxrt1170_evk_cm7.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c48000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c48000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c48000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/samples/drivers/mbox_data/boards/mimxrt1170_evkb_cm7.conf b/samples/drivers/mbox_data/boards/mimxrt1170_evkb_cm7.conf new file mode 100644 index 00000000000..0dfb100ed70 --- /dev/null +++ b/samples/drivers/mbox_data/boards/mimxrt1170_evkb_cm7.conf @@ -0,0 +1,3 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_SECOND_CORE_MCUX=y +CONFIG_INCLUDE_REMOTE_DIR=y diff --git a/samples/drivers/mbox_data/boards/mimxrt1170_evkb_cm7.overlay b/samples/drivers/mbox_data/boards/mimxrt1170_evkb_cm7.overlay new file mode 100644 index 00000000000..870b9928faf --- /dev/null +++ b/samples/drivers/mbox_data/boards/mimxrt1170_evkb_cm7.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c48000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c48000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c48000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/samples/drivers/mbox_data/prj.conf b/samples/drivers/mbox_data/prj.conf new file mode 100644 index 00000000000..293e2834f25 --- /dev/null +++ b/samples/drivers/mbox_data/prj.conf @@ -0,0 +1,2 @@ +CONFIG_PRINTK=y +CONFIG_MBOX=y diff --git a/samples/drivers/mbox_data/remote/CMakeLists.txt b/samples/drivers/mbox_data/remote/CMakeLists.txt new file mode 100644 index 00000000000..31f6db9b641 --- /dev/null +++ b/samples/drivers/mbox_data/remote/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright 2024 NXP +# +# SPDX-License-Identifier: Apache-2.0 +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +if(("${BOARD}" STREQUAL "mimxrt1170_evkb_cm4") OR + ("${BOARD}" STREQUAL "mimxrt1170_evk_cm4") OR + ("${BOARD}" STREQUAL "mimxrt1160_evk_cm4")) + message(STATUS "${BOARD} compile as remote in this sample") +else() + message(FATAL_ERROR "${BOARD} is not supported for this sample") +endif() + +project(mbox_data_ipc_remote) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/drivers/mbox_data/remote/boards/mimxrt1160_evk_cm4.conf b/samples/drivers/mbox_data/remote/boards/mimxrt1160_evk_cm4.conf new file mode 100644 index 00000000000..0d36a72aec6 --- /dev/null +++ b/samples/drivers/mbox_data/remote/boards/mimxrt1160_evk_cm4.conf @@ -0,0 +1,4 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_BUILD_OUTPUT_INFO_HEADER=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/samples/drivers/mbox_data/remote/boards/mimxrt1160_evk_cm4.overlay b/samples/drivers/mbox_data/remote/boards/mimxrt1160_evk_cm4.overlay new file mode 100644 index 00000000000..3f6115b9c58 --- /dev/null +++ b/samples/drivers/mbox_data/remote/boards/mimxrt1160_evk_cm4.overlay @@ -0,0 +1,54 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,flash = &ocram; + zephyr,console = &lpuart2; + zephyr,shell-uart = &lpuart2; + + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /delete-node/ gpt@400f0000; + + /* Replace GPT2 with another GPT kernel timer */ + gpt2_hw_timer:gpt@400f0000 { + compatible = "nxp,gpt-hw-timer"; + reg = <0x400f0000 0x4000>; + interrupts = <120 0>; + status = "okay"; + }; + + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c4c000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c4c000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c4c000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; + +/* Enable secondary LPUART */ +&lpuart2 { + status = "okay"; + current-speed = <115200>; +}; + +/* Disable primary GPT timer */ +&gpt_hw_timer { + status = "disabled"; +}; diff --git a/samples/drivers/mbox_data/remote/boards/mimxrt1170_evk_cm4.conf b/samples/drivers/mbox_data/remote/boards/mimxrt1170_evk_cm4.conf new file mode 100644 index 00000000000..0d36a72aec6 --- /dev/null +++ b/samples/drivers/mbox_data/remote/boards/mimxrt1170_evk_cm4.conf @@ -0,0 +1,4 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_BUILD_OUTPUT_INFO_HEADER=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/samples/drivers/mbox_data/remote/boards/mimxrt1170_evk_cm4.overlay b/samples/drivers/mbox_data/remote/boards/mimxrt1170_evk_cm4.overlay new file mode 100644 index 00000000000..3f6115b9c58 --- /dev/null +++ b/samples/drivers/mbox_data/remote/boards/mimxrt1170_evk_cm4.overlay @@ -0,0 +1,54 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,flash = &ocram; + zephyr,console = &lpuart2; + zephyr,shell-uart = &lpuart2; + + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /delete-node/ gpt@400f0000; + + /* Replace GPT2 with another GPT kernel timer */ + gpt2_hw_timer:gpt@400f0000 { + compatible = "nxp,gpt-hw-timer"; + reg = <0x400f0000 0x4000>; + interrupts = <120 0>; + status = "okay"; + }; + + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c4c000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c4c000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c4c000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; + +/* Enable secondary LPUART */ +&lpuart2 { + status = "okay"; + current-speed = <115200>; +}; + +/* Disable primary GPT timer */ +&gpt_hw_timer { + status = "disabled"; +}; diff --git a/samples/drivers/mbox_data/remote/boards/mimxrt1170_evkb_cm4.conf b/samples/drivers/mbox_data/remote/boards/mimxrt1170_evkb_cm4.conf new file mode 100644 index 00000000000..0d36a72aec6 --- /dev/null +++ b/samples/drivers/mbox_data/remote/boards/mimxrt1170_evkb_cm4.conf @@ -0,0 +1,4 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_BUILD_OUTPUT_INFO_HEADER=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/samples/drivers/mbox_data/remote/boards/mimxrt1170_evkb_cm4.overlay b/samples/drivers/mbox_data/remote/boards/mimxrt1170_evkb_cm4.overlay new file mode 100644 index 00000000000..e3576826702 --- /dev/null +++ b/samples/drivers/mbox_data/remote/boards/mimxrt1170_evkb_cm4.overlay @@ -0,0 +1,55 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,flash = &ocram; + zephyr,console = &lpuart2; + zephyr,shell-uart = &lpuart2; + + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /delete-node/ gpt@400f0000; + + /* Replace GPT2 with another GPT kernel timer */ + gpt2_hw_timer:gpt@400f0000 { + compatible = "nxp,gpt-hw-timer"; + reg = <0x400f0000 0x4000>; + interrupts = <120 0>; + status = "okay"; + }; + + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c4c000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c4c000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c4c000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; + +}; + +/* Enable secondary LPUART */ +&lpuart2 { + status = "okay"; + current-speed = <115200>; +}; + +/* Disable primary GPT timer */ +&gpt_hw_timer { + status = "disabled"; +}; diff --git a/samples/drivers/mbox_data/remote/prj.conf b/samples/drivers/mbox_data/remote/prj.conf new file mode 100644 index 00000000000..473e4280601 --- /dev/null +++ b/samples/drivers/mbox_data/remote/prj.conf @@ -0,0 +1,2 @@ +CONFIG_STDOUT_CONSOLE=n +CONFIG_MBOX=y diff --git a/samples/drivers/mbox_data/remote/src/main.c b/samples/drivers/mbox_data/remote/src/main.c new file mode 100644 index 00000000000..9fccf155c23 --- /dev/null +++ b/samples/drivers/mbox_data/remote/src/main.c @@ -0,0 +1,75 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +static K_SEM_DEFINE(g_mbox_data_rx_sem, 0, 1); + +static uint32_t g_mbox_received_data; +static uint32_t g_mbox_received_channel; + +#define TX_ID (2) +#define RX_ID (3) + +static void callback(const struct device *dev, uint32_t channel, void *user_data, + struct mbox_msg *data) +{ + memcpy(&g_mbox_received_data, data->data, data->size); + g_mbox_received_channel = channel; + + k_sem_give(&g_mbox_data_rx_sem); +} + +int main(void) +{ + struct mbox_channel tx_channel; + struct mbox_channel rx_channel; + const struct device *dev; + struct mbox_msg msg = {0}; + uint32_t message = 0; + + printk("mbox_data Server demo started\n"); + + dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); + + mbox_init_channel(&tx_channel, dev, TX_ID); + mbox_init_channel(&rx_channel, dev, RX_ID); + + if (mbox_register_callback(&rx_channel, callback, NULL)) { + printk("mbox_register_callback() error\n"); + return 0; + } + + if (mbox_set_enabled(&rx_channel, 1)) { + printk("mbox_set_enable() error\n"); + return 0; + } + + while (message < 99) { + k_sem_take(&g_mbox_data_rx_sem, K_FOREVER); + message = g_mbox_received_data; + + printk("Server receive (on channel %d) value: %d\n", g_mbox_received_channel, + g_mbox_received_data); + + message++; + + msg.data = &message; + msg.size = 4; + + printk("Server send (on channel %d) value: %d\n", tx_channel.id, message); + if (mbox_send(&tx_channel, &msg) < 0) { + printk("mbox_send() error\n"); + return 0; + } + } + + printk("mbox_data Server demo ended.\n"); + return 0; +} diff --git a/samples/drivers/mbox_data/sample.yaml b/samples/drivers/mbox_data/sample.yaml new file mode 100644 index 00000000000..5484233b2e8 --- /dev/null +++ b/samples/drivers/mbox_data/sample.yaml @@ -0,0 +1,27 @@ +sample: + name: MBOX Data IPC sample +common: + sysbuild: true + tags: mbox +tests: + sample.drivers.mbox_data.real_hw: + platform_allow: + - mimxrt1170_evkb_cm7 + - mimxrt1170_evk_cm7 + - mimxrt1160_evk_cm7 + integration_platforms: + - mimxrt1160_evk_cm7 + harness: console + harness_config: + type: multi_line + ordered: false + regex: + - "Client received \\(on channel 2\\) value: 1" + - "Client send \\(on channel 3\\) value: 2" + - "Client received \\(on channel 2\\) value: 3" + - "Client send \\(on channel 3\\) value: 4" + - "Client received \\(on channel 2\\) value: 41" + - "Client send \\(on channel 3\\) value: 42" + - "Client received \\(on channel 2\\) value: 97" + - "Client send \\(on channel 3\\) value: 98" + - "Client received \\(on channel 2\\) value: 99" diff --git a/samples/drivers/mbox_data/src/main.c b/samples/drivers/mbox_data/src/main.c new file mode 100644 index 00000000000..27c29b07554 --- /dev/null +++ b/samples/drivers/mbox_data/src/main.c @@ -0,0 +1,74 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +static K_SEM_DEFINE(g_mbox_data_rx_sem, 0, 1); + +static uint32_t g_mbox_received_data; +static uint32_t g_mbox_received_channel; + +#define TX_ID (3) +#define RX_ID (2) + +static void callback(const struct device *dev, uint32_t channel, void *user_data, + struct mbox_msg *data) +{ + memcpy(&g_mbox_received_data, data->data, data->size); + g_mbox_received_channel = channel; + + k_sem_give(&g_mbox_data_rx_sem); +} + +int main(void) +{ + struct mbox_channel tx_channel; + struct mbox_channel rx_channel; + const struct device *dev; + struct mbox_msg msg = {0}; + uint32_t message = 0; + + printk("mbox_data Client demo started\n"); + + dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); + + mbox_init_channel(&tx_channel, dev, TX_ID); + mbox_init_channel(&rx_channel, dev, RX_ID); + + if (mbox_register_callback(&rx_channel, callback, NULL)) { + printk("mbox_register_callback() error\n"); + return 0; + } + + if (mbox_set_enabled(&rx_channel, 1)) { + printk("mbox_set_enable() error\n"); + return 0; + } + + while (message < 100) { + msg.data = &message; + msg.size = 4; + + printk("Client send (on channel %d) value: %d\n", tx_channel.id, message); + if (mbox_send(&tx_channel, &msg) < 0) { + printk("mbox_send() error\n"); + return 0; + } + + k_sem_take(&g_mbox_data_rx_sem, K_FOREVER); + message = g_mbox_received_data; + + printk("Client received (on channel %d) value: %d\n", g_mbox_received_channel, + message); + message++; + } + + printk("mbox_data Client demo ended\n"); + return 0; +} diff --git a/samples/drivers/mbox_data/sysbuild.cmake b/samples/drivers/mbox_data/sysbuild.cmake new file mode 100644 index 00000000000..5c536a6229a --- /dev/null +++ b/samples/drivers/mbox_data/sysbuild.cmake @@ -0,0 +1,28 @@ +# Copyright 2024 NXP +# +# SPDX-License-Identifier: Apache-2.0 + +if("${SB_CONFIG_REMOTE_BOARD}" STREQUAL "") + message(FATAL_ERROR + "Target ${BOARD} not supported for this sample. " + "There is no remote board selected in Kconfig.sysbuild") +endif() + +set(REMOTE_APP remote) + +ExternalZephyrProject_Add( + APPLICATION ${REMOTE_APP} + SOURCE_DIR ${APP_DIR}/${REMOTE_APP} + BOARD ${SB_CONFIG_REMOTE_BOARD} +) + +if ("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7" OR + "${BOARD}" STREQUAL "mimxrt1170_evk_cm7" OR + "${BOARD}" STREQUAL "mimxrt1160_evk_cm7" + ) + # For these NXP boards the main core application is dependent on + # 'zephyr_image_info.h' generated by remote application. + + # Let's build the remote application first + add_dependencies(${DEFAULT_IMAGE} ${REMOTE_APP}) +endif() From 8cad9dc1dddb9574546458ce516c999ca662c4cd Mon Sep 17 00:00:00 2001 From: Tomas Galbicka Date: Fri, 12 Jan 2024 15:50:35 +0100 Subject: [PATCH 1597/1623] [nrf fromtree] tests: mbox: Add test for mbox with data transfer This commit adds extended test for mbox driver with data transfer to verify correct mbox functionality. Signed-off-by: Tomas Galbicka (cherry picked from commit 554f2ba08e13f48571c3b91c824b4be41c4848b6) --- tests/drivers/mbox/mbox_data/CMakeLists.txt | 29 +++ tests/drivers/mbox/mbox_data/Kconfig | 11 ++ tests/drivers/mbox/mbox_data/Kconfig.sysbuild | 11 ++ .../mbox_data/boards/mimxrt1160_evk_cm7.conf | 3 + .../boards/mimxrt1160_evk_cm7.overlay | 29 +++ .../mbox_data/boards/mimxrt1170_evk_cm7.conf | 3 + .../boards/mimxrt1170_evk_cm7.overlay | 29 +++ .../mbox_data/boards/mimxrt1170_evkb_cm7.conf | 3 + .../boards/mimxrt1170_evkb_cm7.overlay | 29 +++ tests/drivers/mbox/mbox_data/prj.conf | 3 + .../mbox/mbox_data/remote/CMakeLists.txt | 20 ++ .../remote/boards/mimxrt1160_evk_cm4.conf | 4 + .../remote/boards/mimxrt1160_evk_cm4.overlay | 54 +++++ .../remote/boards/mimxrt1170_evk_cm4.conf | 4 + .../remote/boards/mimxrt1170_evk_cm4.overlay | 54 +++++ .../remote/boards/mimxrt1170_evkb_cm4.conf | 4 + .../remote/boards/mimxrt1170_evkb_cm4.overlay | 55 ++++++ tests/drivers/mbox/mbox_data/remote/prj.conf | 3 + .../drivers/mbox/mbox_data/remote/src/main.c | 91 +++++++++ tests/drivers/mbox/mbox_data/src/main.c | 184 ++++++++++++++++++ tests/drivers/mbox/mbox_data/sysbuild.cmake | 28 +++ tests/drivers/mbox/mbox_data/testcase.yaml | 12 ++ 22 files changed, 663 insertions(+) create mode 100644 tests/drivers/mbox/mbox_data/CMakeLists.txt create mode 100644 tests/drivers/mbox/mbox_data/Kconfig create mode 100644 tests/drivers/mbox/mbox_data/Kconfig.sysbuild create mode 100644 tests/drivers/mbox/mbox_data/boards/mimxrt1160_evk_cm7.conf create mode 100644 tests/drivers/mbox/mbox_data/boards/mimxrt1160_evk_cm7.overlay create mode 100644 tests/drivers/mbox/mbox_data/boards/mimxrt1170_evk_cm7.conf create mode 100644 tests/drivers/mbox/mbox_data/boards/mimxrt1170_evk_cm7.overlay create mode 100644 tests/drivers/mbox/mbox_data/boards/mimxrt1170_evkb_cm7.conf create mode 100644 tests/drivers/mbox/mbox_data/boards/mimxrt1170_evkb_cm7.overlay create mode 100644 tests/drivers/mbox/mbox_data/prj.conf create mode 100644 tests/drivers/mbox/mbox_data/remote/CMakeLists.txt create mode 100644 tests/drivers/mbox/mbox_data/remote/boards/mimxrt1160_evk_cm4.conf create mode 100644 tests/drivers/mbox/mbox_data/remote/boards/mimxrt1160_evk_cm4.overlay create mode 100644 tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evk_cm4.conf create mode 100644 tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evk_cm4.overlay create mode 100644 tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evkb_cm4.conf create mode 100644 tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evkb_cm4.overlay create mode 100644 tests/drivers/mbox/mbox_data/remote/prj.conf create mode 100644 tests/drivers/mbox/mbox_data/remote/src/main.c create mode 100644 tests/drivers/mbox/mbox_data/src/main.c create mode 100644 tests/drivers/mbox/mbox_data/sysbuild.cmake create mode 100644 tests/drivers/mbox/mbox_data/testcase.yaml diff --git a/tests/drivers/mbox/mbox_data/CMakeLists.txt b/tests/drivers/mbox/mbox_data/CMakeLists.txt new file mode 100644 index 00000000000..a67552bf52e --- /dev/null +++ b/tests/drivers/mbox/mbox_data/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright 2024 NXP +# +# SPDX-License-Identifier: Apache-2.0 +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/../remote/zephyr) + +if(("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7") OR + ("${BOARD}" STREQUAL "mimxrt1170_evk_cm7") OR + ("${BOARD}" STREQUAL "mimxrt1160_evk_cm7")) + message(STATUS "${BOARD} compile as Main in this sample") +else() + message(FATAL_ERROR "${BOARD} is not supported for this sample") +endif() + +project(mbox_data_ipc) + +enable_language(C ASM) + +if(CONFIG_INCLUDE_REMOTE_DIR) + target_include_directories(zephyr_interface + INTERFACE ${REMOTE_ZEPHYR_DIR}/include/public) +endif() + +target_sources(app PRIVATE src/main.c) diff --git a/tests/drivers/mbox/mbox_data/Kconfig b/tests/drivers/mbox/mbox_data/Kconfig new file mode 100644 index 00000000000..ee3874c39f9 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/Kconfig @@ -0,0 +1,11 @@ +# Copyright 2024 NXP +# +# SPDX-License-Identifier: Apache-2.0 + +source "Kconfig.zephyr" + +config INCLUDE_REMOTE_DIR + bool "Include remote core header directory" + help + Include remote build header files. Can be used if primary image + needs to be aware of size or base address of secondary image diff --git a/tests/drivers/mbox/mbox_data/Kconfig.sysbuild b/tests/drivers/mbox/mbox_data/Kconfig.sysbuild new file mode 100644 index 00000000000..e355713e714 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/Kconfig.sysbuild @@ -0,0 +1,11 @@ +# Copyright 2024 NXP +# +# SPDX-License-Identifier: Apache-2.0 + +source "share/sysbuild/Kconfig" + +config REMOTE_BOARD +string + default "mimxrt1170_evkb_cm4" if $(BOARD) = "mimxrt1170_evkb_cm7" + default "mimxrt1170_evk_cm4" if $(BOARD) = "mimxrt1170_evk_cm7" + default "mimxrt1160_evk_cm4" if $(BOARD) = "mimxrt1160_evk_cm7" diff --git a/tests/drivers/mbox/mbox_data/boards/mimxrt1160_evk_cm7.conf b/tests/drivers/mbox/mbox_data/boards/mimxrt1160_evk_cm7.conf new file mode 100644 index 00000000000..583b4950360 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/boards/mimxrt1160_evk_cm7.conf @@ -0,0 +1,3 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_INCLUDE_REMOTE_DIR=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/tests/drivers/mbox/mbox_data/boards/mimxrt1160_evk_cm7.overlay b/tests/drivers/mbox/mbox_data/boards/mimxrt1160_evk_cm7.overlay new file mode 100644 index 00000000000..870b9928faf --- /dev/null +++ b/tests/drivers/mbox/mbox_data/boards/mimxrt1160_evk_cm7.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c48000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c48000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c48000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evk_cm7.conf b/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evk_cm7.conf new file mode 100644 index 00000000000..583b4950360 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evk_cm7.conf @@ -0,0 +1,3 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_INCLUDE_REMOTE_DIR=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evk_cm7.overlay b/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evk_cm7.overlay new file mode 100644 index 00000000000..870b9928faf --- /dev/null +++ b/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evk_cm7.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c48000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c48000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c48000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evkb_cm7.conf b/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evkb_cm7.conf new file mode 100644 index 00000000000..0dfb100ed70 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evkb_cm7.conf @@ -0,0 +1,3 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_SECOND_CORE_MCUX=y +CONFIG_INCLUDE_REMOTE_DIR=y diff --git a/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evkb_cm7.overlay b/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evkb_cm7.overlay new file mode 100644 index 00000000000..870b9928faf --- /dev/null +++ b/tests/drivers/mbox/mbox_data/boards/mimxrt1170_evkb_cm7.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c48000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c48000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c48000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/tests/drivers/mbox/mbox_data/prj.conf b/tests/drivers/mbox/mbox_data/prj.conf new file mode 100644 index 00000000000..c4c2b474a7d --- /dev/null +++ b/tests/drivers/mbox/mbox_data/prj.conf @@ -0,0 +1,3 @@ +CONFIG_PRINTK=y +CONFIG_MBOX=y +CONFIG_ZTEST=y diff --git a/tests/drivers/mbox/mbox_data/remote/CMakeLists.txt b/tests/drivers/mbox/mbox_data/remote/CMakeLists.txt new file mode 100644 index 00000000000..31f6db9b641 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/remote/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright 2024 NXP +# +# SPDX-License-Identifier: Apache-2.0 +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +if(("${BOARD}" STREQUAL "mimxrt1170_evkb_cm4") OR + ("${BOARD}" STREQUAL "mimxrt1170_evk_cm4") OR + ("${BOARD}" STREQUAL "mimxrt1160_evk_cm4")) + message(STATUS "${BOARD} compile as remote in this sample") +else() + message(FATAL_ERROR "${BOARD} is not supported for this sample") +endif() + +project(mbox_data_ipc_remote) + +target_sources(app PRIVATE src/main.c) diff --git a/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1160_evk_cm4.conf b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1160_evk_cm4.conf new file mode 100644 index 00000000000..0d36a72aec6 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1160_evk_cm4.conf @@ -0,0 +1,4 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_BUILD_OUTPUT_INFO_HEADER=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1160_evk_cm4.overlay b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1160_evk_cm4.overlay new file mode 100644 index 00000000000..3f6115b9c58 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1160_evk_cm4.overlay @@ -0,0 +1,54 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,flash = &ocram; + zephyr,console = &lpuart2; + zephyr,shell-uart = &lpuart2; + + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /delete-node/ gpt@400f0000; + + /* Replace GPT2 with another GPT kernel timer */ + gpt2_hw_timer:gpt@400f0000 { + compatible = "nxp,gpt-hw-timer"; + reg = <0x400f0000 0x4000>; + interrupts = <120 0>; + status = "okay"; + }; + + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c4c000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c4c000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c4c000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; + +/* Enable secondary LPUART */ +&lpuart2 { + status = "okay"; + current-speed = <115200>; +}; + +/* Disable primary GPT timer */ +&gpt_hw_timer { + status = "disabled"; +}; diff --git a/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evk_cm4.conf b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evk_cm4.conf new file mode 100644 index 00000000000..0d36a72aec6 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evk_cm4.conf @@ -0,0 +1,4 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_BUILD_OUTPUT_INFO_HEADER=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evk_cm4.overlay b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evk_cm4.overlay new file mode 100644 index 00000000000..3f6115b9c58 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evk_cm4.overlay @@ -0,0 +1,54 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,flash = &ocram; + zephyr,console = &lpuart2; + zephyr,shell-uart = &lpuart2; + + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /delete-node/ gpt@400f0000; + + /* Replace GPT2 with another GPT kernel timer */ + gpt2_hw_timer:gpt@400f0000 { + compatible = "nxp,gpt-hw-timer"; + reg = <0x400f0000 0x4000>; + interrupts = <120 0>; + status = "okay"; + }; + + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c4c000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c4c000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c4c000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; + +/* Enable secondary LPUART */ +&lpuart2 { + status = "okay"; + current-speed = <115200>; +}; + +/* Disable primary GPT timer */ +&gpt_hw_timer { + status = "disabled"; +}; diff --git a/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evkb_cm4.conf b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evkb_cm4.conf new file mode 100644 index 00000000000..0d36a72aec6 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evkb_cm4.conf @@ -0,0 +1,4 @@ +CONFIG_MBOX_NXP_IMX_MU=y +CONFIG_BUILD_OUTPUT_INFO_HEADER=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_SECOND_CORE_MCUX=y diff --git a/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evkb_cm4.overlay b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evkb_cm4.overlay new file mode 100644 index 00000000000..e3576826702 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/remote/boards/mimxrt1170_evkb_cm4.overlay @@ -0,0 +1,55 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,flash = &ocram; + zephyr,console = &lpuart2; + zephyr,shell-uart = &lpuart2; + + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /delete-node/ gpt@400f0000; + + /* Replace GPT2 with another GPT kernel timer */ + gpt2_hw_timer:gpt@400f0000 { + compatible = "nxp,gpt-hw-timer"; + reg = <0x400f0000 0x4000>; + interrupts = <120 0>; + status = "okay"; + }; + + /* Delete IPM Driver node nxp,imx-mu */ + /delete-node/ mailbox@40c4c000; + + /* Attach MBOX driver to MU Unit */ + mbox:mbox@40c4c000 { + compatible = "nxp,mbox-imx-mu"; + reg = <0x40c4c000 0x4000>; + interrupts = <118 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; + +}; + +/* Enable secondary LPUART */ +&lpuart2 { + status = "okay"; + current-speed = <115200>; +}; + +/* Disable primary GPT timer */ +&gpt_hw_timer { + status = "disabled"; +}; diff --git a/tests/drivers/mbox/mbox_data/remote/prj.conf b/tests/drivers/mbox/mbox_data/remote/prj.conf new file mode 100644 index 00000000000..f2859becbe9 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/remote/prj.conf @@ -0,0 +1,3 @@ +CONFIG_STDOUT_CONSOLE=n +CONFIG_MBOX=y +# CONFIG_NO_OPTIMIZATIONS=y diff --git a/tests/drivers/mbox/mbox_data/remote/src/main.c b/tests/drivers/mbox/mbox_data/remote/src/main.c new file mode 100644 index 00000000000..7bbc1c2efd0 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/remote/src/main.c @@ -0,0 +1,91 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +static K_SEM_DEFINE(g_mbox_data_rx_sem, 0, 1); + +static uint32_t g_mbox_received_data; +static uint32_t g_mbox_received_channel; + +#define TX_ID0 (2) +#define RX_ID0 (3) +#define TX_ID1 (0) +#define RX_ID1 (1) +#define TX_ID2 (3) +#define RX_ID2 (2) +#define TX_ID3 (1) +#define RX_ID3 (0) + +#define CHANNELS_TO_TEST (4) +#define TX_CHANNEL_INDEX (0) +#define RX_CHANNEL_INDEX (1) +const static uint32_t TEST_CHANNELS[CHANNELS_TO_TEST][2] = { + {TX_ID0, RX_ID0}, {TX_ID1, RX_ID1}, {TX_ID2, RX_ID2}, {TX_ID3, RX_ID3}}; + +static void callback(const struct device *dev, uint32_t channel, void *user_data, + struct mbox_msg *data) +{ + if (data != NULL) { + memcpy(&g_mbox_received_data, data->data, data->size); + g_mbox_received_channel = channel; + } + + k_sem_give(&g_mbox_data_rx_sem); +} + +int main(void) +{ + struct mbox_channel tx_channel; + struct mbox_channel rx_channel; + const struct device *dev; + struct mbox_msg msg = {0}; + uint32_t message = 0; + + dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); + + for (int i_test_channel = 0; i_test_channel < CHANNELS_TO_TEST; i_test_channel++) { + mbox_init_channel(&tx_channel, dev, + TEST_CHANNELS[i_test_channel][TX_CHANNEL_INDEX]); + mbox_init_channel(&rx_channel, dev, + TEST_CHANNELS[i_test_channel][RX_CHANNEL_INDEX]); + + if (mbox_register_callback(&rx_channel, callback, NULL)) { + printk("mbox_register_callback() error\n"); + return 0; + } + + if (mbox_set_enabled(&rx_channel, 1)) { + printk("mbox_set_enable() error\n"); + return 0; + } + + int test_count = 0; + + while (test_count < 100) { + test_count++; + + k_sem_take(&g_mbox_data_rx_sem, K_FOREVER); + message = g_mbox_received_data; + + message++; + + msg.data = &message; + msg.size = 4; + + if (mbox_send(&tx_channel, &msg) < 0) { + printk("mbox_send() error\n"); + return 0; + } + } + + /* Disable current rx channel after channel loop */ + mbox_set_enabled(&rx_channel, 0); + } +} diff --git a/tests/drivers/mbox/mbox_data/src/main.c b/tests/drivers/mbox/mbox_data/src/main.c new file mode 100644 index 00000000000..1cdfb0ca43e --- /dev/null +++ b/tests/drivers/mbox/mbox_data/src/main.c @@ -0,0 +1,184 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include + +static K_SEM_DEFINE(g_mbox_data_rx_sem, 0, 1); + +static uint32_t g_mbox_received_data; +static uint32_t g_mbox_expected_data; +static uint32_t g_mbox_received_channel; +static uint32_t g_mbox_expected_channel; + +static bool g_received_size_error; +static size_t g_received_size; + +static struct mbox_channel g_tx_channel; +static struct mbox_channel g_rx_channel; + +#define TX_ID0 (3) +#define RX_ID0 (2) +#define TX_ID1 (1) +#define RX_ID1 (0) +#define TX_ID2 (2) +#define RX_ID2 (3) +#define TX_ID3 (0) +#define RX_ID3 (1) + +#define CHANNELS_TO_TEST (4) +#define TX_CHANNEL_INDEX (0) +#define RX_CHANNEL_INDEX (1) +const static uint32_t TEST_CHANNELS[CHANNELS_TO_TEST][2] = { + {TX_ID0, RX_ID0}, {TX_ID1, RX_ID1}, {TX_ID2, RX_ID2}, {TX_ID3, RX_ID3}}; +static uint32_t current_channel_index; + +static void callback(const struct device *dev, uint32_t channel, void *user_data, + struct mbox_msg *data) +{ + /* Handle the case if received invalid size */ + if (data->size > sizeof(g_mbox_received_data)) { + g_received_size_error = true; + g_received_size = data->size; + } else { + memcpy(&g_mbox_received_data, data->data, data->size); + } + + g_mbox_received_channel = channel; + + k_sem_give(&g_mbox_data_rx_sem); +} + +static void mbox_data_tests_before(void *f) +{ + zassert_false(current_channel_index >= CHANNELS_TO_TEST, "Channel to test is out of range"); + + const struct device *dev; + int ret_val = 0; + + dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); + + mbox_init_channel(&g_tx_channel, dev, + TEST_CHANNELS[current_channel_index][TX_CHANNEL_INDEX]); + mbox_init_channel(&g_rx_channel, dev, + TEST_CHANNELS[current_channel_index][RX_CHANNEL_INDEX]); + + ret_val = mbox_register_callback(&g_rx_channel, callback, NULL); + zassert_false(ret_val != 0, "mbox failed to register callback. ret_val", ret_val); + + ret_val = mbox_set_enabled(&g_rx_channel, 1); + zassert_false(ret_val != 0, "mbox failed to enable mbox. ret_val: %d", ret_val); +} + +static void mbox_data_tests_after(void *f) +{ + /* Disable channel after test end */ + int ret_val = mbox_set_enabled(&g_rx_channel, 0); + + zassert_false(ret_val != 0, "mbox failed to disable mbox. ret_val: %d", ret_val); + + /* Increment current channel index to its prepared for next test */ + current_channel_index++; +} + +static void mbox_test(const uint32_t data) +{ + struct mbox_msg msg = {0}; + uint32_t test_data = data; + int test_count = 0; + int ret_val = 0; + + while (test_count < 100) { + /* Main core prepare test data */ + msg.data = &test_data; + msg.size = 4; + + /* Main core send test data */ + ret_val = mbox_send(&g_tx_channel, &msg); + zassert_false(ret_val < 0, "mbox failed to send. ret_val: %d", ret_val); + + /* Expect next received data will be incremented by one */ + g_mbox_expected_data = test_data; + g_mbox_expected_data++; + + k_sem_take(&g_mbox_data_rx_sem, K_FOREVER); + + if (g_received_size_error) { + zassert_false(1, "mbox received invalid size in callback: %d", + g_received_size); + } + + test_data = g_mbox_received_data; + + /* Main core check received data */ + zassert_equal(g_mbox_expected_data, test_data, + "Received test_data does not match!: Expected: %08X, Got: %08X", + g_mbox_expected_data, test_data); + + /* Expect reception of data on current RX channel */ + g_mbox_expected_channel = TEST_CHANNELS[current_channel_index][RX_CHANNEL_INDEX]; + zassert_equal(g_mbox_expected_channel, g_mbox_received_channel, + "Received channel does not match!: Expected: %d, Got: %d", + g_mbox_expected_channel, g_mbox_received_channel); + + /* Increment for next send */ + test_data++; + test_count++; + } +} + +/** + * @brief MBOX Data transfer by ping pong for first set of channels + * + * This test verifies that the data transfer via MBOX. + * Main core will transfer test data to remote core. + * Remote core will increment data by one and transfer it back to Main core. + * Main core will check that data it sent to remote core was incremented by one. + * Main core will again increment test data by one, send it to remote core and repeat 100 times. + */ +ZTEST(mbox_data_tests, test_ping_pong_1) +{ + mbox_test(0xADADADAD); +} + +/** + * @brief MBOX Data transfer by ping pong for second set of channels + * + * Description same as for test_ping_pong_1 + * + */ +ZTEST(mbox_data_tests, test_ping_pong_2) +{ + mbox_test(0xDADADADA); +} + +/** + * @brief MBOX Data transfer by ping pong for third set of channels + * + * Description same as for test_ping_pong_1 + * + */ +ZTEST(mbox_data_tests, test_ping_pong_3) +{ + mbox_test(0xADADADAD); +} + +/** + * @brief MBOX Data transfer by ping pong for forth set of channels + * + * Description same as for test_ping_pong_1 + * + */ +ZTEST(mbox_data_tests, test_ping_pong_4) +{ + mbox_test(0xDADADADA); +} + +ZTEST_SUITE(mbox_data_tests, NULL, NULL, mbox_data_tests_before, mbox_data_tests_after, NULL); diff --git a/tests/drivers/mbox/mbox_data/sysbuild.cmake b/tests/drivers/mbox/mbox_data/sysbuild.cmake new file mode 100644 index 00000000000..5c536a6229a --- /dev/null +++ b/tests/drivers/mbox/mbox_data/sysbuild.cmake @@ -0,0 +1,28 @@ +# Copyright 2024 NXP +# +# SPDX-License-Identifier: Apache-2.0 + +if("${SB_CONFIG_REMOTE_BOARD}" STREQUAL "") + message(FATAL_ERROR + "Target ${BOARD} not supported for this sample. " + "There is no remote board selected in Kconfig.sysbuild") +endif() + +set(REMOTE_APP remote) + +ExternalZephyrProject_Add( + APPLICATION ${REMOTE_APP} + SOURCE_DIR ${APP_DIR}/${REMOTE_APP} + BOARD ${SB_CONFIG_REMOTE_BOARD} +) + +if ("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7" OR + "${BOARD}" STREQUAL "mimxrt1170_evk_cm7" OR + "${BOARD}" STREQUAL "mimxrt1160_evk_cm7" + ) + # For these NXP boards the main core application is dependent on + # 'zephyr_image_info.h' generated by remote application. + + # Let's build the remote application first + add_dependencies(${DEFAULT_IMAGE} ${REMOTE_APP}) +endif() diff --git a/tests/drivers/mbox/mbox_data/testcase.yaml b/tests/drivers/mbox/mbox_data/testcase.yaml new file mode 100644 index 00000000000..d4890ff7c55 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/testcase.yaml @@ -0,0 +1,12 @@ +tests: + drivers.mbox_data: + tags: + - drivers + - mbox + sysbuild: true + platform_allow: + - mimxrt1170_evkb_cm7 + - mimxrt1170_evk_cm7 + - mimxrt1160_evk_cm7 + integration_platforms: + - mimxrt1170_evkb_cm7 From 3f18688c6bcbdadef2400bde65419abd5f05cf63 Mon Sep 17 00:00:00 2001 From: Tomas Galbicka Date: Tue, 30 Jan 2024 17:12:34 +0100 Subject: [PATCH 1598/1623] [nrf fromtree] samples: tests: mbox: Add lpcpresso55s69 support This commit adds support for NXP board LPCXpresso55S69 for mbox. - samples/drivers/mbox/ - mbox signaling mode - samples/drivers/mbox_data/ - mbox data transfer mode - tests/drivers/mbox/mbox_data/ - mbox test to verify functionality. **NOTE**: manually fixed west.yml conflict to avoid pulling multiple non-relevant NXP HAL updates. Signed-off-by: Tomas Galbicka (cherry picked from commit 73d6c336cad7e6fd739ab397dabbe5748d274a82) --- samples/drivers/mbox/CMakeLists.txt | 5 ++- samples/drivers/mbox/Kconfig.sysbuild | 3 +- .../mbox/boards/lpcxpresso55s69_cpu0.conf | 3 ++ .../mbox/boards/lpcxpresso55s69_cpu0.overlay | 29 +++++++++++++ samples/drivers/mbox/remote/CMakeLists.txt | 3 +- .../remote/boards/lpcxpresso55s69_cpu1.conf | 10 +++++ .../boards/lpcxpresso55s69_cpu1.overlay | 43 +++++++++++++++++++ samples/drivers/mbox/sample.yaml | 1 + samples/drivers/mbox/sysbuild.cmake | 5 ++- samples/drivers/mbox_data/CMakeLists.txt | 3 +- samples/drivers/mbox_data/Kconfig.sysbuild | 1 + samples/drivers/mbox_data/README.rst | 11 ++++- .../boards/lpcxpresso55s69_cpu0.conf | 3 ++ .../boards/lpcxpresso55s69_cpu0.overlay | 29 +++++++++++++ .../drivers/mbox_data/remote/CMakeLists.txt | 3 +- .../remote/boards/lpcxpresso55s69_cpu1.conf | 3 ++ .../boards/lpcxpresso55s69_cpu1.overlay | 29 +++++++++++++ samples/drivers/mbox_data/remote/src/main.c | 10 ++++- samples/drivers/mbox_data/sample.yaml | 2 + samples/drivers/mbox_data/src/main.c | 10 ++++- tests/drivers/mbox/mbox_data/CMakeLists.txt | 3 +- tests/drivers/mbox/mbox_data/Kconfig.sysbuild | 1 + .../boards/lpcxpresso55s69_cpu0.conf | 3 ++ .../boards/lpcxpresso55s69_cpu0.overlay | 29 +++++++++++++ .../mbox/mbox_data/remote/CMakeLists.txt | 3 +- .../remote/boards/lpcxpresso55s69_cpu1.conf | 3 ++ .../boards/lpcxpresso55s69_cpu1.overlay | 29 +++++++++++++ .../drivers/mbox/mbox_data/remote/src/main.c | 10 ++++- tests/drivers/mbox/mbox_data/src/main.c | 19 ++++++-- tests/drivers/mbox/mbox_data/testcase.yaml | 2 + west.yml | 2 +- 31 files changed, 292 insertions(+), 18 deletions(-) create mode 100644 samples/drivers/mbox/boards/lpcxpresso55s69_cpu0.conf create mode 100644 samples/drivers/mbox/boards/lpcxpresso55s69_cpu0.overlay create mode 100644 samples/drivers/mbox/remote/boards/lpcxpresso55s69_cpu1.conf create mode 100644 samples/drivers/mbox/remote/boards/lpcxpresso55s69_cpu1.overlay create mode 100644 samples/drivers/mbox_data/boards/lpcxpresso55s69_cpu0.conf create mode 100644 samples/drivers/mbox_data/boards/lpcxpresso55s69_cpu0.overlay create mode 100644 samples/drivers/mbox_data/remote/boards/lpcxpresso55s69_cpu1.conf create mode 100644 samples/drivers/mbox_data/remote/boards/lpcxpresso55s69_cpu1.overlay create mode 100644 tests/drivers/mbox/mbox_data/boards/lpcxpresso55s69_cpu0.conf create mode 100644 tests/drivers/mbox/mbox_data/boards/lpcxpresso55s69_cpu0.overlay create mode 100644 tests/drivers/mbox/mbox_data/remote/boards/lpcxpresso55s69_cpu1.conf create mode 100644 tests/drivers/mbox/mbox_data/remote/boards/lpcxpresso55s69_cpu1.overlay diff --git a/samples/drivers/mbox/CMakeLists.txt b/samples/drivers/mbox/CMakeLists.txt index 4344f4f3ce9..ca6513822a8 100644 --- a/samples/drivers/mbox/CMakeLists.txt +++ b/samples/drivers/mbox/CMakeLists.txt @@ -1,6 +1,6 @@ # # Copyright (c) 2021 Carlo Caione -# Copyright 2023 NXP +# Copyright 2023-2024 NXP # # SPDX-License-Identifier: Apache-2.0 # @@ -17,7 +17,8 @@ if(("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpuapp") OR ("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7") OR ("${BOARD}" STREQUAL "mimxrt1170_evk_cm7") OR ("${BOARD}" STREQUAL "mimxrt1160_evk_cm7") OR - ("${BOARD}" STREQUAL "mimxrt595_evk_cm33")) + ("${BOARD}" STREQUAL "mimxrt595_evk_cm33") OR + ("${BOARD}" STREQUAL "lpcxpresso55s69_cpu0")) message(STATUS "${BOARD} compile as Main in this sample") else() message(FATAL_ERROR "${BOARD} is not supported for this sample") diff --git a/samples/drivers/mbox/Kconfig.sysbuild b/samples/drivers/mbox/Kconfig.sysbuild index f472576df82..20903872c34 100644 --- a/samples/drivers/mbox/Kconfig.sysbuild +++ b/samples/drivers/mbox/Kconfig.sysbuild @@ -1,5 +1,5 @@ # Copyright 2023 Nordic Semiconductor ASA -# Copyright 2023 NXP +# Copyright 2023-2024 NXP # # SPDX-License-Identifier: Apache-2.0 @@ -14,3 +14,4 @@ string default "mimxrt1170_evkb_cm4" if $(BOARD) = "mimxrt1170_evkb_cm7" default "mimxrt1170_evk_cm4" if $(BOARD) = "mimxrt1170_evk_cm7" default "mimxrt1160_evk_cm4" if $(BOARD) = "mimxrt1160_evk_cm7" + default "lpcxpresso55s69_cpu1" if $(BOARD) = "lpcxpresso55s69_cpu0" diff --git a/samples/drivers/mbox/boards/lpcxpresso55s69_cpu0.conf b/samples/drivers/mbox/boards/lpcxpresso55s69_cpu0.conf new file mode 100644 index 00000000000..5077d775881 --- /dev/null +++ b/samples/drivers/mbox/boards/lpcxpresso55s69_cpu0.conf @@ -0,0 +1,3 @@ +CONFIG_SECOND_CORE_MCUX=y +CONFIG_MBOX_NXP_MAILBOX=y +CONFIG_BUILD_OUTPUT_HEX=y diff --git a/samples/drivers/mbox/boards/lpcxpresso55s69_cpu0.overlay b/samples/drivers/mbox/boards/lpcxpresso55s69_cpu0.overlay new file mode 100644 index 00000000000..b5919c4fd72 --- /dev/null +++ b/samples/drivers/mbox/boards/lpcxpresso55s69_cpu0.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,lpc-mailbox */ + /delete-node/ mailbox@8b000; + + /* Attach MBOX driver to Mailbox Unit */ + mbox:mailbox0@5008b000 { + compatible = "nxp,mbox-mailbox"; + reg = <0x5008b000 0xEC>; + interrupts = <31 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/samples/drivers/mbox/remote/CMakeLists.txt b/samples/drivers/mbox/remote/CMakeLists.txt index e7db9b8cadf..2c7c8fff29e 100644 --- a/samples/drivers/mbox/remote/CMakeLists.txt +++ b/samples/drivers/mbox/remote/CMakeLists.txt @@ -1,6 +1,6 @@ # # Copyright (c) 2021 Carlo Caione -# Copyright 2023 NXP +# Copyright 2023-2024 NXP # # SPDX-License-Identifier: Apache-2.0 # @@ -14,6 +14,7 @@ if(("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet") OR ("${BOARD}" STREQUAL "mimxrt1170_evkb_cm4") OR ("${BOARD}" STREQUAL "mimxrt1170_evk_cm4") OR ("${BOARD}" STREQUAL "mimxrt1160_evk_cm4") OR + ("${BOARD}" STREQUAL "lpcxpresso55s69_cpu1") OR ("${BOARD}" STREQUAL "adp_xc7k_ae350")) message(STATUS "${BOARD} compile as remote in this sample") else() diff --git a/samples/drivers/mbox/remote/boards/lpcxpresso55s69_cpu1.conf b/samples/drivers/mbox/remote/boards/lpcxpresso55s69_cpu1.conf new file mode 100644 index 00000000000..b499f5da051 --- /dev/null +++ b/samples/drivers/mbox/remote/boards/lpcxpresso55s69_cpu1.conf @@ -0,0 +1,10 @@ +CONFIG_SECOND_CORE_MCUX=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_MBOX_NXP_MAILBOX=y + +# For purpose of sample enable UART Console on CPU1 +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y +CONFIG_SERIAL=y +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_CLOCK_CONTROL=y diff --git a/samples/drivers/mbox/remote/boards/lpcxpresso55s69_cpu1.overlay b/samples/drivers/mbox/remote/boards/lpcxpresso55s69_cpu1.overlay new file mode 100644 index 00000000000..36e6f0ff267 --- /dev/null +++ b/samples/drivers/mbox/remote/boards/lpcxpresso55s69_cpu1.overlay @@ -0,0 +1,43 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + zephyr,console = &flexcomm0; + zephyr,shell-uart = &flexcomm0; + }; + + soc { + /* Delete IPM Driver node nxp,lpc-mailbox */ + /delete-node/ mailbox@8b000; + + /* Attach MBOX driver to Mailbox Unit */ + mbox:mbox@5008b000 { + compatible = "nxp,mbox-mailbox"; + reg = <0x5008b000 0xEC>; + interrupts = <31 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; + +&flexcomm0 { + status = "okay"; +}; + +&dma0 { + status = "okay"; +}; + +&syscon { + status = "okay"; +}; diff --git a/samples/drivers/mbox/sample.yaml b/samples/drivers/mbox/sample.yaml index e8015cf7c25..d646b241e9e 100644 --- a/samples/drivers/mbox/sample.yaml +++ b/samples/drivers/mbox/sample.yaml @@ -12,6 +12,7 @@ tests: - mimxrt1170_evkb_cm7 - mimxrt1170_evk_cm7 - mimxrt1160_evk_cm7 + - lpcxpresso55s69_cpu0 integration_platforms: - nrf5340dk_nrf5340_cpuapp harness: console diff --git a/samples/drivers/mbox/sysbuild.cmake b/samples/drivers/mbox/sysbuild.cmake index 7a5d32d4c74..063f6157ddb 100644 --- a/samples/drivers/mbox/sysbuild.cmake +++ b/samples/drivers/mbox/sysbuild.cmake @@ -1,5 +1,5 @@ # Copyright (c) 2023 Nordic Semiconductor ASA -# Copyright 2023 NXP +# Copyright 2023-2024 NXP # SPDX-License-Identifier: Apache-2.0 if("${SB_CONFIG_REMOTE_BOARD}" STREQUAL "") @@ -22,7 +22,8 @@ native_simulator_set_final_executable(${DEFAULT_IMAGE}) if ("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7" OR "${BOARD}" STREQUAL "mimxrt1170_evk_cm7" OR - "${BOARD}" STREQUAL "mimxrt1160_evk_cm7" + "${BOARD}" STREQUAL "mimxrt1160_evk_cm7" OR + "${BOARD}" STREQUAL "lpcxpresso55s69_cpu0" ) # For these NXP boards the main core application is dependent on # 'zephyr_image_info.h' generated by remote application. diff --git a/samples/drivers/mbox_data/CMakeLists.txt b/samples/drivers/mbox_data/CMakeLists.txt index a67552bf52e..a410ac3d214 100644 --- a/samples/drivers/mbox_data/CMakeLists.txt +++ b/samples/drivers/mbox_data/CMakeLists.txt @@ -11,7 +11,8 @@ set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/../remote/zephyr) if(("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7") OR ("${BOARD}" STREQUAL "mimxrt1170_evk_cm7") OR - ("${BOARD}" STREQUAL "mimxrt1160_evk_cm7")) + ("${BOARD}" STREQUAL "mimxrt1160_evk_cm7") OR + ("${BOARD}" STREQUAL "lpcxpresso55s69_cpu0")) message(STATUS "${BOARD} compile as Main in this sample") else() message(FATAL_ERROR "${BOARD} is not supported for this sample") diff --git a/samples/drivers/mbox_data/Kconfig.sysbuild b/samples/drivers/mbox_data/Kconfig.sysbuild index e355713e714..2ddab228177 100644 --- a/samples/drivers/mbox_data/Kconfig.sysbuild +++ b/samples/drivers/mbox_data/Kconfig.sysbuild @@ -9,3 +9,4 @@ string default "mimxrt1170_evkb_cm4" if $(BOARD) = "mimxrt1170_evkb_cm7" default "mimxrt1170_evk_cm4" if $(BOARD) = "mimxrt1170_evk_cm7" default "mimxrt1160_evk_cm4" if $(BOARD) = "mimxrt1160_evk_cm7" + default "lpcxpresso55s69_cpu1" if $(BOARD) = "lpcxpresso55s69_cpu0" diff --git a/samples/drivers/mbox_data/README.rst b/samples/drivers/mbox_data/README.rst index 3ead1ec3b87..1f8b1615f8e 100644 --- a/samples/drivers/mbox_data/README.rst +++ b/samples/drivers/mbox_data/README.rst @@ -10,7 +10,7 @@ Overview This sample demonstrates how to use the :ref:`MBOX API ` in data transfer mode. It can be used only with mbox driver which supports data transfer mode. -Sample will ping-pong 4 bytes of data between two cores via two mbox channels. +Sample will ping-pong up to 4 bytes of data between two cores via two mbox channels. After each core receives data, it increments it by one and sends it back to other core. Building and Running @@ -45,6 +45,15 @@ Building the application for mimxrt1170_evkb_cm7 :goals: debug :west-args: --sysbuild +Building the application for lpcxpresso55s69_cpu1 +================================================= + +.. zephyr-app-commands:: + :zephyr-app: samples/drivers/mbox_data/ + :board: lpcxpresso55s69_cpu1 + :goals: debug + :west-args: --sysbuild + Sample Output ============= diff --git a/samples/drivers/mbox_data/boards/lpcxpresso55s69_cpu0.conf b/samples/drivers/mbox_data/boards/lpcxpresso55s69_cpu0.conf new file mode 100644 index 00000000000..5077d775881 --- /dev/null +++ b/samples/drivers/mbox_data/boards/lpcxpresso55s69_cpu0.conf @@ -0,0 +1,3 @@ +CONFIG_SECOND_CORE_MCUX=y +CONFIG_MBOX_NXP_MAILBOX=y +CONFIG_BUILD_OUTPUT_HEX=y diff --git a/samples/drivers/mbox_data/boards/lpcxpresso55s69_cpu0.overlay b/samples/drivers/mbox_data/boards/lpcxpresso55s69_cpu0.overlay new file mode 100644 index 00000000000..b5919c4fd72 --- /dev/null +++ b/samples/drivers/mbox_data/boards/lpcxpresso55s69_cpu0.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,lpc-mailbox */ + /delete-node/ mailbox@8b000; + + /* Attach MBOX driver to Mailbox Unit */ + mbox:mailbox0@5008b000 { + compatible = "nxp,mbox-mailbox"; + reg = <0x5008b000 0xEC>; + interrupts = <31 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/samples/drivers/mbox_data/remote/CMakeLists.txt b/samples/drivers/mbox_data/remote/CMakeLists.txt index 31f6db9b641..47e1cae8628 100644 --- a/samples/drivers/mbox_data/remote/CMakeLists.txt +++ b/samples/drivers/mbox_data/remote/CMakeLists.txt @@ -9,7 +9,8 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) if(("${BOARD}" STREQUAL "mimxrt1170_evkb_cm4") OR ("${BOARD}" STREQUAL "mimxrt1170_evk_cm4") OR - ("${BOARD}" STREQUAL "mimxrt1160_evk_cm4")) + ("${BOARD}" STREQUAL "mimxrt1160_evk_cm4") OR + ("${BOARD}" STREQUAL "lpcxpresso55s69_cpu1")) message(STATUS "${BOARD} compile as remote in this sample") else() message(FATAL_ERROR "${BOARD} is not supported for this sample") diff --git a/samples/drivers/mbox_data/remote/boards/lpcxpresso55s69_cpu1.conf b/samples/drivers/mbox_data/remote/boards/lpcxpresso55s69_cpu1.conf new file mode 100644 index 00000000000..14ed92ba8f4 --- /dev/null +++ b/samples/drivers/mbox_data/remote/boards/lpcxpresso55s69_cpu1.conf @@ -0,0 +1,3 @@ +CONFIG_SECOND_CORE_MCUX=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_MBOX_NXP_MAILBOX=y diff --git a/samples/drivers/mbox_data/remote/boards/lpcxpresso55s69_cpu1.overlay b/samples/drivers/mbox_data/remote/boards/lpcxpresso55s69_cpu1.overlay new file mode 100644 index 00000000000..96bd5aa1c3a --- /dev/null +++ b/samples/drivers/mbox_data/remote/boards/lpcxpresso55s69_cpu1.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,lpc-mailbox */ + /delete-node/ mailbox@8b000; + + /* Attach MBOX driver to Mailbox Unit */ + mbox:mbox@5008b000 { + compatible = "nxp,mbox-mailbox"; + reg = <0x5008b000 0xEC>; + interrupts = <31 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/samples/drivers/mbox_data/remote/src/main.c b/samples/drivers/mbox_data/remote/src/main.c index 9fccf155c23..0f3ad77a4d0 100644 --- a/samples/drivers/mbox_data/remote/src/main.c +++ b/samples/drivers/mbox_data/remote/src/main.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -41,6 +42,13 @@ int main(void) mbox_init_channel(&tx_channel, dev, TX_ID); mbox_init_channel(&rx_channel, dev, RX_ID); + const int max_transfer_size_bytes = mbox_mtu_get(dev); + /* Sample currently supports only transfer size up to 4 bytes */ + if ((max_transfer_size_bytes <= 0) || (max_transfer_size_bytes > 4)) { + printk("mbox_mtu_get() error\n"); + return 0; + } + if (mbox_register_callback(&rx_channel, callback, NULL)) { printk("mbox_register_callback() error\n"); return 0; @@ -61,7 +69,7 @@ int main(void) message++; msg.data = &message; - msg.size = 4; + msg.size = max_transfer_size_bytes; printk("Server send (on channel %d) value: %d\n", tx_channel.id, message); if (mbox_send(&tx_channel, &msg) < 0) { diff --git a/samples/drivers/mbox_data/sample.yaml b/samples/drivers/mbox_data/sample.yaml index 5484233b2e8..b4a1e23a9bc 100644 --- a/samples/drivers/mbox_data/sample.yaml +++ b/samples/drivers/mbox_data/sample.yaml @@ -9,8 +9,10 @@ tests: - mimxrt1170_evkb_cm7 - mimxrt1170_evk_cm7 - mimxrt1160_evk_cm7 + - lpcxpresso55s69_cpu0 integration_platforms: - mimxrt1160_evk_cm7 + - lpcxpresso55s69_cpu0 harness: console harness_config: type: multi_line diff --git a/samples/drivers/mbox_data/src/main.c b/samples/drivers/mbox_data/src/main.c index 27c29b07554..85df24940c4 100644 --- a/samples/drivers/mbox_data/src/main.c +++ b/samples/drivers/mbox_data/src/main.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -41,6 +42,13 @@ int main(void) mbox_init_channel(&tx_channel, dev, TX_ID); mbox_init_channel(&rx_channel, dev, RX_ID); + const int max_transfer_size_bytes = mbox_mtu_get(dev); + /* Sample currently supports only transfer size up to 4 bytes */ + if ((max_transfer_size_bytes < 0) || (max_transfer_size_bytes > 4)) { + printk("mbox_mtu_get() error\n"); + return 0; + } + if (mbox_register_callback(&rx_channel, callback, NULL)) { printk("mbox_register_callback() error\n"); return 0; @@ -53,7 +61,7 @@ int main(void) while (message < 100) { msg.data = &message; - msg.size = 4; + msg.size = max_transfer_size_bytes; printk("Client send (on channel %d) value: %d\n", tx_channel.id, message); if (mbox_send(&tx_channel, &msg) < 0) { diff --git a/tests/drivers/mbox/mbox_data/CMakeLists.txt b/tests/drivers/mbox/mbox_data/CMakeLists.txt index a67552bf52e..a410ac3d214 100644 --- a/tests/drivers/mbox/mbox_data/CMakeLists.txt +++ b/tests/drivers/mbox/mbox_data/CMakeLists.txt @@ -11,7 +11,8 @@ set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/../remote/zephyr) if(("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7") OR ("${BOARD}" STREQUAL "mimxrt1170_evk_cm7") OR - ("${BOARD}" STREQUAL "mimxrt1160_evk_cm7")) + ("${BOARD}" STREQUAL "mimxrt1160_evk_cm7") OR + ("${BOARD}" STREQUAL "lpcxpresso55s69_cpu0")) message(STATUS "${BOARD} compile as Main in this sample") else() message(FATAL_ERROR "${BOARD} is not supported for this sample") diff --git a/tests/drivers/mbox/mbox_data/Kconfig.sysbuild b/tests/drivers/mbox/mbox_data/Kconfig.sysbuild index e355713e714..2ddab228177 100644 --- a/tests/drivers/mbox/mbox_data/Kconfig.sysbuild +++ b/tests/drivers/mbox/mbox_data/Kconfig.sysbuild @@ -9,3 +9,4 @@ string default "mimxrt1170_evkb_cm4" if $(BOARD) = "mimxrt1170_evkb_cm7" default "mimxrt1170_evk_cm4" if $(BOARD) = "mimxrt1170_evk_cm7" default "mimxrt1160_evk_cm4" if $(BOARD) = "mimxrt1160_evk_cm7" + default "lpcxpresso55s69_cpu1" if $(BOARD) = "lpcxpresso55s69_cpu0" diff --git a/tests/drivers/mbox/mbox_data/boards/lpcxpresso55s69_cpu0.conf b/tests/drivers/mbox/mbox_data/boards/lpcxpresso55s69_cpu0.conf new file mode 100644 index 00000000000..5077d775881 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/boards/lpcxpresso55s69_cpu0.conf @@ -0,0 +1,3 @@ +CONFIG_SECOND_CORE_MCUX=y +CONFIG_MBOX_NXP_MAILBOX=y +CONFIG_BUILD_OUTPUT_HEX=y diff --git a/tests/drivers/mbox/mbox_data/boards/lpcxpresso55s69_cpu0.overlay b/tests/drivers/mbox/mbox_data/boards/lpcxpresso55s69_cpu0.overlay new file mode 100644 index 00000000000..b5919c4fd72 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/boards/lpcxpresso55s69_cpu0.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,lpc-mailbox */ + /delete-node/ mailbox@8b000; + + /* Attach MBOX driver to Mailbox Unit */ + mbox:mailbox0@5008b000 { + compatible = "nxp,mbox-mailbox"; + reg = <0x5008b000 0xEC>; + interrupts = <31 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/tests/drivers/mbox/mbox_data/remote/CMakeLists.txt b/tests/drivers/mbox/mbox_data/remote/CMakeLists.txt index 31f6db9b641..47e1cae8628 100644 --- a/tests/drivers/mbox/mbox_data/remote/CMakeLists.txt +++ b/tests/drivers/mbox/mbox_data/remote/CMakeLists.txt @@ -9,7 +9,8 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) if(("${BOARD}" STREQUAL "mimxrt1170_evkb_cm4") OR ("${BOARD}" STREQUAL "mimxrt1170_evk_cm4") OR - ("${BOARD}" STREQUAL "mimxrt1160_evk_cm4")) + ("${BOARD}" STREQUAL "mimxrt1160_evk_cm4") OR + ("${BOARD}" STREQUAL "lpcxpresso55s69_cpu1")) message(STATUS "${BOARD} compile as remote in this sample") else() message(FATAL_ERROR "${BOARD} is not supported for this sample") diff --git a/tests/drivers/mbox/mbox_data/remote/boards/lpcxpresso55s69_cpu1.conf b/tests/drivers/mbox/mbox_data/remote/boards/lpcxpresso55s69_cpu1.conf new file mode 100644 index 00000000000..14ed92ba8f4 --- /dev/null +++ b/tests/drivers/mbox/mbox_data/remote/boards/lpcxpresso55s69_cpu1.conf @@ -0,0 +1,3 @@ +CONFIG_SECOND_CORE_MCUX=y +CONFIG_BUILD_OUTPUT_HEX=y +CONFIG_MBOX_NXP_MAILBOX=y diff --git a/tests/drivers/mbox/mbox_data/remote/boards/lpcxpresso55s69_cpu1.overlay b/tests/drivers/mbox/mbox_data/remote/boards/lpcxpresso55s69_cpu1.overlay new file mode 100644 index 00000000000..96bd5aa1c3a --- /dev/null +++ b/tests/drivers/mbox/mbox_data/remote/boards/lpcxpresso55s69_cpu1.overlay @@ -0,0 +1,29 @@ +/* + * Copyright 2024 NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* Delete ipc chosen property where old IPM mailbox driver bellow is + * configured. + */ + /delete-property/ zephyr,ipc; + }; + + soc { + /* Delete IPM Driver node nxp,lpc-mailbox */ + /delete-node/ mailbox@8b000; + + /* Attach MBOX driver to Mailbox Unit */ + mbox:mbox@5008b000 { + compatible = "nxp,mbox-mailbox"; + reg = <0x5008b000 0xEC>; + interrupts = <31 0>; + rx-channels = <4>; + #mbox-cells = <1>; + status = "okay"; + }; + }; +}; diff --git a/tests/drivers/mbox/mbox_data/remote/src/main.c b/tests/drivers/mbox/mbox_data/remote/src/main.c index 7bbc1c2efd0..d9eba4d3b7c 100644 --- a/tests/drivers/mbox/mbox_data/remote/src/main.c +++ b/tests/drivers/mbox/mbox_data/remote/src/main.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -50,6 +51,13 @@ int main(void) dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); + const int max_transfer_size_bytes = mbox_mtu_get(dev); + /* Sample currently supports only transfer size up to 4 bytes */ + if ((max_transfer_size_bytes <= 0) || (max_transfer_size_bytes > 4)) { + printk("mbox_mtu_get() error\n"); + return 0; + } + for (int i_test_channel = 0; i_test_channel < CHANNELS_TO_TEST; i_test_channel++) { mbox_init_channel(&tx_channel, dev, TEST_CHANNELS[i_test_channel][TX_CHANNEL_INDEX]); @@ -77,7 +85,7 @@ int main(void) message++; msg.data = &message; - msg.size = 4; + msg.size = max_transfer_size_bytes; if (mbox_send(&tx_channel, &msg) < 0) { printk("mbox_send() error\n"); diff --git a/tests/drivers/mbox/mbox_data/src/main.c b/tests/drivers/mbox/mbox_data/src/main.c index 1cdfb0ca43e..82cce00ae7f 100644 --- a/tests/drivers/mbox/mbox_data/src/main.c +++ b/tests/drivers/mbox/mbox_data/src/main.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -20,6 +21,7 @@ static uint32_t g_mbox_expected_channel; static bool g_received_size_error; static size_t g_received_size; +static int g_max_transfer_size_bytes; static struct mbox_channel g_tx_channel; static struct mbox_channel g_rx_channel; @@ -65,6 +67,14 @@ static void mbox_data_tests_before(void *f) dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); + g_max_transfer_size_bytes = mbox_mtu_get(dev); + /* Test currently supports only transfer size up to 4 bytes */ + if ((g_max_transfer_size_bytes < 0) || (g_max_transfer_size_bytes > 4)) { + printk("mbox_mtu_get() error\n"); + zassert_false(1, "mbox invalid maximum transfer unit: %d", + g_max_transfer_size_bytes); + } + mbox_init_channel(&g_tx_channel, dev, TEST_CHANNELS[current_channel_index][TX_CHANNEL_INDEX]); mbox_init_channel(&g_rx_channel, dev, @@ -98,14 +108,17 @@ static void mbox_test(const uint32_t data) while (test_count < 100) { /* Main core prepare test data */ msg.data = &test_data; - msg.size = 4; + msg.size = g_max_transfer_size_bytes; /* Main core send test data */ ret_val = mbox_send(&g_tx_channel, &msg); zassert_false(ret_val < 0, "mbox failed to send. ret_val: %d", ret_val); - /* Expect next received data will be incremented by one */ - g_mbox_expected_data = test_data; + /* Expect next received data will be incremented by one. + * And based on Maximum Transfer Unit determine expected data. + * Currently supported MTU's are 1, 2, 3, and 4 bytes. + */ + g_mbox_expected_data = test_data & ~(0xFFFFFFFF << (g_max_transfer_size_bytes * 8)); g_mbox_expected_data++; k_sem_take(&g_mbox_data_rx_sem, K_FOREVER); diff --git a/tests/drivers/mbox/mbox_data/testcase.yaml b/tests/drivers/mbox/mbox_data/testcase.yaml index d4890ff7c55..72aff63ac3a 100644 --- a/tests/drivers/mbox/mbox_data/testcase.yaml +++ b/tests/drivers/mbox/mbox_data/testcase.yaml @@ -8,5 +8,7 @@ tests: - mimxrt1170_evkb_cm7 - mimxrt1170_evk_cm7 - mimxrt1160_evk_cm7 + - lpcxpresso55s69_cpu0 integration_platforms: - mimxrt1170_evkb_cm7 + - lpcxpresso55s69_cpu0 diff --git a/west.yml b/west.yml index 03a830da77c..68a87e6cf76 100644 --- a/west.yml +++ b/west.yml @@ -193,7 +193,7 @@ manifest: groups: - hal - name: hal_nxp - revision: 69046233b7a7fac3138ae4dd5bcf6158e82529bb + revision: 0463d6aa0de62761fb9ae56e3521c61b0e490374 path: modules/hal/nxp groups: - hal From 0cfeb7b92687134eda3d5e63abfbd7e0f065a2bd Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Fri, 16 Feb 2024 10:34:25 -0600 Subject: [PATCH 1599/1623] [nrf fromtree] samples: drivers: mbox: remove mimxrt595_evk_cm33 Remove mimxrt595_evk_cm33 from the MBOX sample. Although this SOC has support for both cores, there is no support in tree for booting the secondary core from the primary one, so this sample cannot run on hardware. Fixes #69092 Signed-off-by: Daniel DeGrasse (cherry picked from commit 39ea8ac87ab0a01f6c8ff0b2717ab5036d71793b) --- samples/drivers/mbox/CMakeLists.txt | 1 - samples/drivers/mbox/Kconfig.sysbuild | 1 - samples/drivers/mbox/boards/mimxrt595_evk_cm33.conf | 1 - samples/drivers/mbox/sample.yaml | 1 - 4 files changed, 4 deletions(-) delete mode 100644 samples/drivers/mbox/boards/mimxrt595_evk_cm33.conf diff --git a/samples/drivers/mbox/CMakeLists.txt b/samples/drivers/mbox/CMakeLists.txt index ca6513822a8..ec79db9deed 100644 --- a/samples/drivers/mbox/CMakeLists.txt +++ b/samples/drivers/mbox/CMakeLists.txt @@ -17,7 +17,6 @@ if(("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpuapp") OR ("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7") OR ("${BOARD}" STREQUAL "mimxrt1170_evk_cm7") OR ("${BOARD}" STREQUAL "mimxrt1160_evk_cm7") OR - ("${BOARD}" STREQUAL "mimxrt595_evk_cm33") OR ("${BOARD}" STREQUAL "lpcxpresso55s69_cpu0")) message(STATUS "${BOARD} compile as Main in this sample") else() diff --git a/samples/drivers/mbox/Kconfig.sysbuild b/samples/drivers/mbox/Kconfig.sysbuild index 20903872c34..a17dd56ee55 100644 --- a/samples/drivers/mbox/Kconfig.sysbuild +++ b/samples/drivers/mbox/Kconfig.sysbuild @@ -10,7 +10,6 @@ string default "nrf5340dk_nrf5340_cpunet" if $(BOARD) = "nrf5340dk_nrf5340_cpuapp" default "nrf5340bsim_nrf5340_cpunet" if $(BOARD) = "nrf5340bsim_nrf5340_cpuapp" default "adp_xc7k_ae350" if $(BOARD) = "adp_xc7k_ae350" - default "nrf5340dk_nrf5340_cpunet" if $(BOARD) = "mimxrt595_evk_cm33" default "mimxrt1170_evkb_cm4" if $(BOARD) = "mimxrt1170_evkb_cm7" default "mimxrt1170_evk_cm4" if $(BOARD) = "mimxrt1170_evk_cm7" default "mimxrt1160_evk_cm4" if $(BOARD) = "mimxrt1160_evk_cm7" diff --git a/samples/drivers/mbox/boards/mimxrt595_evk_cm33.conf b/samples/drivers/mbox/boards/mimxrt595_evk_cm33.conf deleted file mode 100644 index b01ff58e024..00000000000 --- a/samples/drivers/mbox/boards/mimxrt595_evk_cm33.conf +++ /dev/null @@ -1 +0,0 @@ -CONFIG_MBOX_NXP_IMX_MU=y diff --git a/samples/drivers/mbox/sample.yaml b/samples/drivers/mbox/sample.yaml index d646b241e9e..e38deda55d3 100644 --- a/samples/drivers/mbox/sample.yaml +++ b/samples/drivers/mbox/sample.yaml @@ -8,7 +8,6 @@ tests: platform_allow: - nrf5340dk_nrf5340_cpuapp - adp_xc7k_ae350 - - mimxrt595_evk_cm33 - mimxrt1170_evkb_cm7 - mimxrt1170_evk_cm7 - mimxrt1160_evk_cm7 From 836f29ace3721ea01dec8b8f8f205fd17b6ef336 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Wed, 1 Nov 2023 09:55:59 +0000 Subject: [PATCH 1600/1623] [nrf fromtree] cmake: linker: arm: Fix missing flash load size use Fixes a mismatch between the cmake and ld linker scripts whereby the cmake script was missing using the flash load size Kconfig option (if it was said), which would result in images far larger than they should have allowed to be Signed-off-by: Jamie McCrae (cherry picked from commit 5031da95c6abf7f40a43286c946abbe2f65f2ce1) --- cmake/linker_script/arm/linker.cmake | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cmake/linker_script/arm/linker.cmake b/cmake/linker_script/arm/linker.cmake index 0c7310ab905..3610260afaf 100644 --- a/cmake/linker_script/arm/linker.cmake +++ b/cmake/linker_script/arm/linker.cmake @@ -16,10 +16,17 @@ math(EXPR FLASH_ADDR OUTPUT_FORMAT HEXADECIMAL ) -math(EXPR FLASH_SIZE - "(${CONFIG_FLASH_SIZE} + 0) * 1024 - (${CONFIG_FLASH_LOAD_OFFSET} + 0)" - OUTPUT_FORMAT HEXADECIMAL -) +if(CONFIG_FLASH_LOAD_SIZE GREATER 0) + math(EXPR FLASH_SIZE + "(${CONFIG_FLASH_LOAD_SIZE} + 0)" + OUTPUT_FORMAT HEXADECIMAL + ) +else() + math(EXPR FLASH_SIZE + "(${CONFIG_FLASH_SIZE} + 0) * 1024 - (${CONFIG_FLASH_LOAD_OFFSET} + 0)" + OUTPUT_FORMAT HEXADECIMAL + ) +endif() set(RAM_ADDR ${CONFIG_SRAM_BASE_ADDRESS}) math(EXPR RAM_SIZE "(${CONFIG_SRAM_SIZE} + 0) * 1024" OUTPUT_FORMAT HEXADECIMAL) From 5187db6427f6610d69333219789d70f48b92042a Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 30 Oct 2023 17:17:40 +0000 Subject: [PATCH 1601/1623] [nrf fromtree] linker: Add flash end ROM offset Reduces the size of an image in the linker script by using the ROM end offset Kconfig value Signed-off-by: Jamie McCrae (cherry picked from commit 2522a7856682ffff7965164c91aae53618d7c4b7) --- cmake/linker_script/arm/linker.cmake | 4 ++-- include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld | 10 ++++++++-- include/zephyr/arch/arm/cortex_m/scripts/linker.ld | 10 ++++++++-- include/zephyr/arch/arm64/scripts/linker.ld | 10 ++++++++-- include/zephyr/arch/nios2/linker.ld | 7 ++++++- include/zephyr/arch/riscv/common/linker.ld | 12 +++++++++--- include/zephyr/arch/x86/memory.ld | 8 +++++++- 7 files changed, 48 insertions(+), 13 deletions(-) diff --git a/cmake/linker_script/arm/linker.cmake b/cmake/linker_script/arm/linker.cmake index 3610260afaf..332d44b2435 100644 --- a/cmake/linker_script/arm/linker.cmake +++ b/cmake/linker_script/arm/linker.cmake @@ -18,12 +18,12 @@ math(EXPR FLASH_ADDR if(CONFIG_FLASH_LOAD_SIZE GREATER 0) math(EXPR FLASH_SIZE - "(${CONFIG_FLASH_LOAD_SIZE} + 0)" + "(${CONFIG_FLASH_LOAD_SIZE} + 0) - (${CONFIG_ROM_END_OFFSET} + 0)" OUTPUT_FORMAT HEXADECIMAL ) else() math(EXPR FLASH_SIZE - "(${CONFIG_FLASH_SIZE} + 0) * 1024 - (${CONFIG_FLASH_LOAD_OFFSET} + 0)" + "(${CONFIG_FLASH_SIZE} + 0) * 1024 - (${CONFIG_FLASH_LOAD_OFFSET} + 0) - (${CONFIG_ROM_END_OFFSET} + 0)" OUTPUT_FORMAT HEXADECIMAL ) endif() diff --git a/include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld b/include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld index f8b117e9193..a28209c1b43 100644 --- a/include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld +++ b/include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld @@ -32,10 +32,16 @@ #define ROM_ADDR (CONFIG_FLASH_BASE_ADDRESS + CONFIG_FLASH_LOAD_OFFSET) #endif +#if defined(CONFIG_ROM_END_OFFSET) +#define ROM_END_OFFSET CONFIG_ROM_END_OFFSET +#else +#define ROM_END_OFFSET 0 +#endif + #if CONFIG_FLASH_LOAD_SIZE > 0 - #define ROM_SIZE CONFIG_FLASH_LOAD_SIZE + #define ROM_SIZE (CONFIG_FLASH_LOAD_SIZE - ROM_END_OFFSET) #else - #define ROM_SIZE (CONFIG_FLASH_SIZE*1K - CONFIG_FLASH_LOAD_OFFSET) + #define ROM_SIZE (CONFIG_FLASH_SIZE*1K - CONFIG_FLASH_LOAD_OFFSET - ROM_END_OFFSET) #endif #if defined(CONFIG_XIP) diff --git a/include/zephyr/arch/arm/cortex_m/scripts/linker.ld b/include/zephyr/arch/arm/cortex_m/scripts/linker.ld index cbe4a2781e4..25a48d11252 100644 --- a/include/zephyr/arch/arm/cortex_m/scripts/linker.ld +++ b/include/zephyr/arch/arm/cortex_m/scripts/linker.ld @@ -61,10 +61,16 @@ _image_1_primary_slot_id = PM_S1_ID; #define ROM_ADDR (CONFIG_FLASH_BASE_ADDRESS + CONFIG_FLASH_LOAD_OFFSET) #endif +#if defined(CONFIG_ROM_END_OFFSET) +#define ROM_END_OFFSET CONFIG_ROM_END_OFFSET +#else +#define ROM_END_OFFSET 0 +#endif + #if CONFIG_FLASH_LOAD_SIZE > 0 -#define ROM_SIZE CONFIG_FLASH_LOAD_SIZE +#define ROM_SIZE (CONFIG_FLASH_LOAD_SIZE - ROM_END_OFFSET) #else -#define ROM_SIZE (CONFIG_FLASH_SIZE * 1024 - CONFIG_FLASH_LOAD_OFFSET) +#define ROM_SIZE (CONFIG_FLASH_SIZE * 1024 - CONFIG_FLASH_LOAD_OFFSET - ROM_END_OFFSET) #endif #if defined(CONFIG_XIP) diff --git a/include/zephyr/arch/arm64/scripts/linker.ld b/include/zephyr/arch/arm64/scripts/linker.ld index ad7832f16ec..5a8e1404a98 100644 --- a/include/zephyr/arch/arm64/scripts/linker.ld +++ b/include/zephyr/arch/arm64/scripts/linker.ld @@ -31,10 +31,16 @@ #define ROM_ADDR (CONFIG_FLASH_BASE_ADDRESS + CONFIG_FLASH_LOAD_OFFSET) #endif +#if defined(CONFIG_ROM_END_OFFSET) +#define ROM_END_OFFSET CONFIG_ROM_END_OFFSET +#else +#define ROM_END_OFFSET 0 +#endif + #if CONFIG_FLASH_LOAD_SIZE > 0 - #define ROM_SIZE CONFIG_FLASH_LOAD_SIZE + #define ROM_SIZE (CONFIG_FLASH_LOAD_SIZE - ROM_END_OFFSET) #else - #define ROM_SIZE (CONFIG_FLASH_SIZE * 1K - CONFIG_FLASH_LOAD_OFFSET) + #define ROM_SIZE (CONFIG_FLASH_SIZE * 1K - CONFIG_FLASH_LOAD_OFFSET - ROM_END_OFFSET) #endif #define RAM_SIZE (CONFIG_SRAM_SIZE * 1K) diff --git a/include/zephyr/arch/nios2/linker.ld b/include/zephyr/arch/nios2/linker.ld index 6958533eaf6..f7ba64088fc 100644 --- a/include/zephyr/arch/nios2/linker.ld +++ b/include/zephyr/arch/nios2/linker.ld @@ -39,6 +39,11 @@ * the exception vector is in RAM */ +#if defined(CONFIG_ROM_END_OFFSET) +#define ROM_END_OFFSET CONFIG_ROM_END_OFFSET +#else +#define ROM_END_OFFSET 0 +#endif #ifdef CONFIG_XIP #define ROMABLE_REGION FLASH @@ -54,7 +59,7 @@ ASSERT(_RESET_VECTOR == _ROM_ADDR, "Reset vector not at beginning of ROM!") MEMORY { RESET (rx) : ORIGIN = _RESET_VECTOR, LENGTH = 0x20 - FLASH (rx) : ORIGIN = _RESET_VECTOR + 0x20 , LENGTH = (_ROM_SIZE - 0x20) + FLASH (rx) : ORIGIN = _RESET_VECTOR + 0x20 , LENGTH = (_ROM_SIZE - 0x20 - ROM_END_OFFSET) RAM (wx) : ORIGIN = _EXC_VECTOR, LENGTH = _RAM_SIZE - (_EXC_VECTOR - _RAM_ADDR) /* Used by and documented in include/linker/intlist.ld */ IDT_LIST (wx) : ORIGIN = 0xFFFFF7FF, LENGTH = 2K diff --git a/include/zephyr/arch/riscv/common/linker.ld b/include/zephyr/arch/riscv/common/linker.ld index 128f823c4df..e9ac6d32d86 100644 --- a/include/zephyr/arch/riscv/common/linker.ld +++ b/include/zephyr/arch/riscv/common/linker.ld @@ -29,6 +29,12 @@ #define _EXCEPTION_SECTION_NAME exceptions #define _RESET_SECTION_NAME reset +#if defined(CONFIG_ROM_END_OFFSET) +#define ROM_END_OFFSET CONFIG_ROM_END_OFFSET +#else +#define ROM_END_OFFSET 0 +#endif + #ifdef CONFIG_XIP #if DT_NODE_HAS_COMPAT_STATUS(DT_CHOSEN(zephyr_flash), soc_nv_flash, okay) #ifdef CONFIG_FLASH_LOAD_OFFSET @@ -37,7 +43,7 @@ #else /* !CONFIG_FLASH_LOAD_OFFSET */ #define ROM_BASE DT_REG_ADDR(DT_CHOSEN(zephyr_flash)) #endif /* CONFIG_FLASH_LOAD_OFFSET */ -#define ROM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_flash)) +#define ROM_SIZE (DT_REG_SIZE(DT_CHOSEN(zephyr_flash)) - ROM_END_OFFSET) #elif DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_flash), jedec_spi_nor) /* For jedec,spi-nor we expect the spi controller to memory map the flash * and for that mapping to be the second register property of the spi @@ -45,11 +51,11 @@ */ #define SPI_CTRL DT_PARENT(DT_CHOSEN(zephyr_flash)) #define ROM_BASE DT_REG_ADDR_BY_IDX(SPI_CTRL, 1) -#define ROM_SIZE DT_REG_SIZE_BY_IDX(SPI_CTRL, 1) +#define ROM_SIZE (DT_REG_SIZE_BY_IDX(SPI_CTRL, 1) - ROM_END_OFFSET) #endif #else /* CONFIG_XIP */ #define ROM_BASE CONFIG_SRAM_BASE_ADDRESS -#define ROM_SIZE KB(CONFIG_SRAM_SIZE) +#define ROM_SIZE (KB(CONFIG_SRAM_SIZE) - ROM_END_OFFSET) #endif /* CONFIG_XIP */ #define RAM_BASE CONFIG_SRAM_BASE_ADDRESS diff --git a/include/zephyr/arch/x86/memory.ld b/include/zephyr/arch/x86/memory.ld index 72b400dd079..c9ede2b9d23 100644 --- a/include/zephyr/arch/x86/memory.ld +++ b/include/zephyr/arch/x86/memory.ld @@ -50,12 +50,18 @@ /* "kernel RAM" for linker VMA allocations starts at the offset */ +#if defined(CONFIG_ROM_END_OFFSET) +#define ROM_END_OFFSET CONFIG_ROM_END_OFFSET +#else +#define ROM_END_OFFSET 0 +#endif + #ifdef CONFIG_XIP /* "ROM" is flash, we leave rodata and text there and just copy in data. * Board-level DTS must specify a flash region that doesn't overlap with * sram0, so that DT_PHYS_LOAD_ADDR is set. */ - #define FLASH_ROM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_flash)) + #define FLASH_ROM_SIZE (DT_REG_SIZE(DT_CHOSEN(zephyr_flash)) - ROM_END_OFFSET) #define PHYS_LOAD_ADDR DT_REG_ADDR(DT_CHOSEN(zephyr_flash)) #else /* Physical RAM location where the kernel image is loaded */ From 74b40a2328f4c6865067681e89f88926e34be698 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Fri, 2 Feb 2024 10:57:12 +0100 Subject: [PATCH 1602/1623] [nrf fromtree] riscv: linker: Fallback to Kconfig when defining ROM region With `CONFIG_XIP=y`, this linker script would derive the ROM region from the chosen `zephyr,flash` DT node with "soc-nv-flash" or "jedec,spi-nor" as its compatible. If the node was absent or had a different compatible, then linking would fail with: undefined symbol `ROM_BASE' referenced in expression Fix this by using `CONFIG_FLASH_BASE_ADDRESS` and `CONFIG_FLASH_SIZE` for ROM base and size respectively. The existing DT logic is preserved for compatibility with out-of-tree boards, so the flash Kconfigs serve as a mere fallback. In addition, use `CONFIG_FLASH_LOAD_OFFSET` and `CONFIG_FLASH_LOAD_SIZE` if defined, to align with some other architectures' linker scripts. For the existing in-tree RISC-V boards, this should not make a difference. The alternative would've been making sure that all boards and SoCs have the relevant Kconfigs set, and only using those in the linker script. The downside is that `CONFIG_FLASH_SIZE` is given in units of 1 KiB, while some existing boards - hifive1_revb, sparkfun_red_v_things_plus - have more granular flash sizes, which would've been rounded down. Signed-off-by: Grzegorz Swiderski (cherry picked from commit e5d14c682136832652c74b2c054c91e203b04950) --- include/zephyr/arch/riscv/common/linker.ld | 33 +++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/include/zephyr/arch/riscv/common/linker.ld b/include/zephyr/arch/riscv/common/linker.ld index e9ac6d32d86..3245012731d 100644 --- a/include/zephyr/arch/riscv/common/linker.ld +++ b/include/zephyr/arch/riscv/common/linker.ld @@ -35,24 +35,43 @@ #define ROM_END_OFFSET 0 #endif +#if defined(CONFIG_FLASH_LOAD_OFFSET) +#define FLASH_LOAD_OFFSET CONFIG_FLASH_LOAD_OFFSET +#else +#define FLASH_LOAD_OFFSET 0 +#endif + #ifdef CONFIG_XIP + +#if CONFIG_FLASH_LOAD_SIZE > 0 +#define ROM_SIZE (CONFIG_FLASH_LOAD_SIZE - ROM_END_OFFSET) +#endif + #if DT_NODE_HAS_COMPAT_STATUS(DT_CHOSEN(zephyr_flash), soc_nv_flash, okay) -#ifdef CONFIG_FLASH_LOAD_OFFSET -#define ROM_BASE (DT_REG_ADDR(DT_CHOSEN(zephyr_flash)) + \ - CONFIG_FLASH_LOAD_OFFSET) -#else /* !CONFIG_FLASH_LOAD_OFFSET */ -#define ROM_BASE DT_REG_ADDR(DT_CHOSEN(zephyr_flash)) -#endif /* CONFIG_FLASH_LOAD_OFFSET */ +#define ROM_BASE (DT_REG_ADDR(DT_CHOSEN(zephyr_flash)) + FLASH_LOAD_OFFSET) +#ifndef ROM_SIZE #define ROM_SIZE (DT_REG_SIZE(DT_CHOSEN(zephyr_flash)) - ROM_END_OFFSET) +#endif + #elif DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_flash), jedec_spi_nor) /* For jedec,spi-nor we expect the spi controller to memory map the flash * and for that mapping to be the second register property of the spi * controller. */ #define SPI_CTRL DT_PARENT(DT_CHOSEN(zephyr_flash)) -#define ROM_BASE DT_REG_ADDR_BY_IDX(SPI_CTRL, 1) +#define ROM_BASE (DT_REG_ADDR_BY_IDX(SPI_CTRL, 1) + FLASH_LOAD_OFFSET) +#ifndef ROM_SIZE #define ROM_SIZE (DT_REG_SIZE_BY_IDX(SPI_CTRL, 1) - ROM_END_OFFSET) #endif + +#else /* Use Kconfig to cover the remaining cases */ +#define ROM_BASE (CONFIG_FLASH_BASE_ADDRESS + FLASH_LOAD_OFFSET) +#ifndef ROM_SIZE +#define ROM_SIZE (CONFIG_FLASH_SIZE * 1024 - FLASH_LOAD_OFFSET - ROM_END_OFFSET) +#endif + +#endif /* DT_NODE_HAS_COMPAT_STATUS */ + #else /* CONFIG_XIP */ #define ROM_BASE CONFIG_SRAM_BASE_ADDRESS #define ROM_SIZE (KB(CONFIG_SRAM_SIZE) - ROM_END_OFFSET) From 915121647d215ba55f01ad210fd49a363bfa6298 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 26 Feb 2024 17:41:58 +0100 Subject: [PATCH 1603/1623] [nrf fromtree] drivers: misc: nordic_vpr_launcher: fix address handling When CONFIG_XIP=y, execution address may come from a partition, so its absolute address is needed. Fix code by using VPR_ADDR() macro in all cases: execution and source addresses. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit f0b975032a68c2da38c34f01b836edb5e9e62b12) --- drivers/misc/nordic_vpr_launcher/nordic_vpr_launcher.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/misc/nordic_vpr_launcher/nordic_vpr_launcher.c b/drivers/misc/nordic_vpr_launcher/nordic_vpr_launcher.c index 161465ba02c..64d4969081b 100644 --- a/drivers/misc/nordic_vpr_launcher/nordic_vpr_launcher.c +++ b/drivers/misc/nordic_vpr_launcher/nordic_vpr_launcher.c @@ -45,8 +45,8 @@ static int nordic_vpr_launcher_init(const struct device *dev) return 0; } -/* obtain VPR source address either from memory or partition */ -#define VPR_SRC_ADDR(node_id) \ +/* obtain VPR address either from memory or partition */ +#define VPR_ADDR(node_id) \ (DT_REG_ADDR(node_id) + \ COND_CODE_0(DT_FIXED_PARTITION_EXISTS(node_id), (0), (DT_REG_ADDR(DT_GPARENT(node_id))))) @@ -59,9 +59,9 @@ static int nordic_vpr_launcher_init(const struct device *dev) \ static const struct nordic_vpr_launcher_config config##inst = { \ .vpr = (NRF_VPR_Type *)DT_INST_REG_ADDR(inst), \ - .exec_addr = DT_REG_ADDR(DT_INST_PHANDLE(inst, execution_memory)), \ + .exec_addr = VPR_ADDR(DT_INST_PHANDLE(inst, execution_memory)), \ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, source_memory), \ - (.src_addr = VPR_SRC_ADDR(DT_INST_PHANDLE(inst, source_memory)), \ + (.src_addr = VPR_ADDR(DT_INST_PHANDLE(inst, source_memory)), \ .src_size = DT_REG_SIZE(DT_INST_PHANDLE(inst, source_memory)),), \ ())}; \ \ From 70d2749bb097f42c790a24d8092a0b3e260bdf14 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 26 Feb 2024 17:50:12 +0100 Subject: [PATCH 1604/1623] [nrf fromtree] soc: riscv: nordic_nrf: vpr: select HAS_FLASH_LOAD_OFFSET if XIP This option is required to enable usage of DT partitions, used when CONFIG_XIP=y. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 43f97710af81a9e551e12979dc9c44ed770009ba) --- soc/riscv/nordic_nrf/common/vpr/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/soc/riscv/nordic_nrf/common/vpr/Kconfig b/soc/riscv/nordic_nrf/common/vpr/Kconfig index 40a7d199c0c..3750716a713 100644 --- a/soc/riscv/nordic_nrf/common/vpr/Kconfig +++ b/soc/riscv/nordic_nrf/common/vpr/Kconfig @@ -14,5 +14,6 @@ config RISCV_CORE_NORDIC_VPR select RISCV_ISA_EXT_ZIFENCEI select RISCV_SOC_HAS_ISR_STACKING select RISCV_SOC_CONTEXT_SAVE + select HAS_FLASH_LOAD_OFFSET if XIP help Enable support for the RISC-V Nordic VPR core. From 9ed9a149bac7a11558c1258701d7e5c46e3a539a Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 26 Feb 2024 18:04:39 +0100 Subject: [PATCH 1605/1623] [nrf fromtree] boards: nrf54h20pdk_nrf54h20: use XIP for PPR The amount of RAM owned by PPR core is quite limited, making it difficult to fit many samples. Instead, use execution in place and increase its code partition from 28K to 64K (as now it doesn't have to match RAM size). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit d1e59cf39f16d45f936a1df14a18e3ba92763791) --- .../nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi | 2 +- .../arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts | 3 +-- .../nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr_defconfig | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi index 00f28fad9f1..cb5a4fe0b0c 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi @@ -73,7 +73,7 @@ }; cpuppr_code_partition: partition@126000 { - reg = <0x126000 DT_SIZE_K(28)>; + reg = <0x126000 DT_SIZE_K(64)>; }; }; }; diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts index 5fb345ec808..8500d22a924 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts @@ -98,8 +98,7 @@ }; &cpuppr_vpr { - source-memory = <&cpuppr_code_partition>; - execution-memory = <&cpuppr_ram3x_region>; + execution-memory = <&cpuppr_code_partition>; }; &gpiote130 { diff --git a/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr_defconfig b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr_defconfig index fb3dca2266d..112140693ef 100644 --- a/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr_defconfig +++ b/boards/riscv/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuppr_defconfig @@ -6,7 +6,7 @@ CONFIG_SOC_NRF54H20=y CONFIG_SOC_NRF54H20_ENGA_CPUPPR=y CONFIG_BOARD_NRF54H20PDK_NRF54H20_CPUPPR=y -CONFIG_XIP=n +CONFIG_USE_DT_CODE_PARTITION=y CONFIG_SERIAL=y From 76c8a0ad9d875c62f20713ba85fc8f4ef5635743 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 26 Feb 2024 18:03:09 +0100 Subject: [PATCH 1606/1623] [nrf fromtree] snippets: add snippet to boot Nordic PPR core from RAM Add a new snippet that allows booting PPR core found in some Nordic SoCs, configuring it with CONFIG_XIP=n. Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 75839ea4ad58127febff768310734d0898623071) --- snippets/nordic-ppr-ram/README.rst | 11 +++++++++++ .../boards/nrf54h20pdk_nrf54h20_cpuapp.overlay | 16 ++++++++++++++++ snippets/nordic-ppr-ram/nordic-ppr-ram.overlay | 15 +++++++++++++++ snippets/nordic-ppr-ram/snippet.yml | 8 ++++++++ 4 files changed, 50 insertions(+) create mode 100644 snippets/nordic-ppr-ram/README.rst create mode 100644 snippets/nordic-ppr-ram/boards/nrf54h20pdk_nrf54h20_cpuapp.overlay create mode 100644 snippets/nordic-ppr-ram/nordic-ppr-ram.overlay create mode 100644 snippets/nordic-ppr-ram/snippet.yml diff --git a/snippets/nordic-ppr-ram/README.rst b/snippets/nordic-ppr-ram/README.rst new file mode 100644 index 00000000000..501e5073357 --- /dev/null +++ b/snippets/nordic-ppr-ram/README.rst @@ -0,0 +1,11 @@ +.. _nordic-ppr-ram: + +Nordic boot PPR snippet with execution from RAM (nordic-ppr-ram) +################################################################ + +Overview +******** + +This snippet allows users to build Zephyr with the capability to boot Nordic PPR +(Peripheral Processor) from another core. PPR code is executed from RAM. Note +that PPR image must be built with :kconfig:option:`CONFIG_XIP` disabled. diff --git a/snippets/nordic-ppr-ram/boards/nrf54h20pdk_nrf54h20_cpuapp.overlay b/snippets/nordic-ppr-ram/boards/nrf54h20pdk_nrf54h20_cpuapp.overlay new file mode 100644 index 00000000000..5597c886b85 --- /dev/null +++ b/snippets/nordic-ppr-ram/boards/nrf54h20pdk_nrf54h20_cpuapp.overlay @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * SPDX-License-Identifier: Apache-2.0 + */ + +&cpuppr_ram3x_region { + status = "okay"; +}; + +&cpuppr_vpr { + execution-memory = <&cpuppr_ram3x_region>; +}; + +&uart135 { + status = "reserved"; +}; diff --git a/snippets/nordic-ppr-ram/nordic-ppr-ram.overlay b/snippets/nordic-ppr-ram/nordic-ppr-ram.overlay new file mode 100644 index 00000000000..e69c3a0d2bf --- /dev/null +++ b/snippets/nordic-ppr-ram/nordic-ppr-ram.overlay @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor + * SPDX-License-Identifier: Apache-2.0 + */ + +/* code is sourced from cpuppr code partition */ +&cpuppr_vpr { + status = "okay"; + source-memory = <&cpuppr_code_partition>; +}; + +/* code partition size must match RAM size */ +&cpuppr_code_partition { + reg = <0x126000 DT_SIZE_K(28)>; +}; diff --git a/snippets/nordic-ppr-ram/snippet.yml b/snippets/nordic-ppr-ram/snippet.yml new file mode 100644 index 00000000000..0d6039af2e5 --- /dev/null +++ b/snippets/nordic-ppr-ram/snippet.yml @@ -0,0 +1,8 @@ +name: nordic-ppr-ram +append: + EXTRA_DTC_OVERLAY_FILE: nordic-ppr-ram.overlay + +boards: + nrf54h20pdk_nrf54h20_cpuapp: + append: + EXTRA_DTC_OVERLAY_FILE: boards/nrf54h20pdk_nrf54h20_cpuapp.overlay From 91c24f8538b0f3a6f0d200e406da23ba8d458bf2 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Tue, 27 Feb 2024 14:03:42 +0100 Subject: [PATCH 1607/1623] [nrf fromtree] modules: hal_nordic: require nrf-regtool 5.1.0 This new version is required to handle the upcoming IPC-related DT structure (i.e. BELLBOARD/VEVIF). Signed-off-by: Gerard Marull-Paretas (cherry picked from commit afdddf1d22b7bbb1521061d4ebb3f96906f6ee48) --- modules/hal_nordic/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/hal_nordic/CMakeLists.txt b/modules/hal_nordic/CMakeLists.txt index 6f5364ac8de..c4a7134935c 100644 --- a/modules/hal_nordic/CMakeLists.txt +++ b/modules/hal_nordic/CMakeLists.txt @@ -11,7 +11,7 @@ if(CONFIG_NRF_REGTOOL_GENERATE_UICR) list(APPEND nrf_regtool_components GENERATE:UICR) endif() if(DEFINED nrf_regtool_components) - find_package(nrf-regtool 5.0.1 + find_package(nrf-regtool 5.1.0 COMPONENTS ${nrf_regtool_components} PATHS ${CMAKE_CURRENT_LIST_DIR}/nrf-regtool NO_CMAKE_PATH From 039f5ba892274a7faeeccd94f59393f3985f6872 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 21 Feb 2024 16:12:50 +0100 Subject: [PATCH 1608/1623] [nrf fromlist] dts: bindings: mbox: add nordic,nrf-vevif-local|remote Add a new binding for Nordic VEVIF (VPR Event Interface) (local and remote modes). Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 965c91ed503d83a6f5eb778b85fe65b5984a53e8) --- .../mbox/nordic,nrf-vevif-common.yaml | 18 +++++++++++ dts/bindings/mbox/nordic,nrf-vevif-local.yaml | 32 +++++++++++++++++++ .../mbox/nordic,nrf-vevif-remote.yaml | 29 +++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 dts/bindings/mbox/nordic,nrf-vevif-common.yaml create mode 100644 dts/bindings/mbox/nordic,nrf-vevif-local.yaml create mode 100644 dts/bindings/mbox/nordic,nrf-vevif-remote.yaml diff --git a/dts/bindings/mbox/nordic,nrf-vevif-common.yaml b/dts/bindings/mbox/nordic,nrf-vevif-common.yaml new file mode 100644 index 00000000000..b7cb15457f6 --- /dev/null +++ b/dts/bindings/mbox/nordic,nrf-vevif-common.yaml @@ -0,0 +1,18 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +include: mailbox-controller.yaml + +properties: + nordic,tasks: + type: int + required: true + description: Number of tasks supported by the VEVIF instance. + + nordic,tasks-mask: + type: int + required: true + description: Mask of tasks supported by the VEVIF instance. + +mbox-cells: + - channel diff --git a/dts/bindings/mbox/nordic,nrf-vevif-local.yaml b/dts/bindings/mbox/nordic,nrf-vevif-local.yaml new file mode 100644 index 00000000000..5d23cfdcf1e --- /dev/null +++ b/dts/bindings/mbox/nordic,nrf-vevif-local.yaml @@ -0,0 +1,32 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + Nordic VEVIF (VPR Event Interface) - Local + + VEVIF is an event interface for VPR, allowing connection to the domain's DPPI + system. VEVIF can also generate IRQs to other CPUs. + + Example definition: + + cpuppr: cpu@d { + ... + cpuppr_vevif_local: mailbox { + compatible = "nordic,nrf-vevif-local"; + interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>, + <1 NRF_DEFAULT_IRQ_PRIORITY>, + ... + ; + #mbox-cells = <1>; + nordic,tasks = <16>; + nordic,tasks-mask: <0xfffffff0>; + }; + }; + +compatible: "nordic,nrf-vevif-local" + +include: [base.yaml, "nordic,nrf-vevif-common.yaml"] + +properties: + interrupts: + required: true diff --git a/dts/bindings/mbox/nordic,nrf-vevif-remote.yaml b/dts/bindings/mbox/nordic,nrf-vevif-remote.yaml new file mode 100644 index 00000000000..07522fed99d --- /dev/null +++ b/dts/bindings/mbox/nordic,nrf-vevif-remote.yaml @@ -0,0 +1,29 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + Nordic VEVIF (VPR Event Interface) - Remote + + VEVIF is an event interface for VPR, allowing connection to the domain's DPPI + system. VEVIF can also generate IRQs to other CPUs. + + Example definition: + + cpuppr_vpr: vpr@deadbeef{ + ... + cpuppr_vevif_remote: mailbox@0 { + compatible = "nordic,nrf-vevif-remote"; + reg = <0x0 0x1000>; + #mbox-cells = <1>; + nordic,tasks = <16>; + nordic,tasks-mask: <0xfffffff0>; + }; + }; + +compatible: "nordic,nrf-vevif-remote" + +include: [base.yaml, "nordic,nrf-vevif-common.yaml"] + +properties: + reg: + required: true From 5e4c2d4d07b37decd11a2bd069cc6dc7f09fa0a1 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 21 Feb 2024 16:13:59 +0100 Subject: [PATCH 1609/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add PPR VEVIF nodes Add a new nodes for PPR's VEVIF. In app cores, VEVIF registers are part of the VPR peripheral, so it is exposed as a child node (since it requires its own properties, eg #mbox-cells). In VPR, it's a CPU child since it's not a memory-mapped peripheral, but used with CSRs. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit f21612445a720f0fe89e0a0996f67e02138e0f4a) --- dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi | 2 ++ dts/arm/nordic/nrf54h20_enga_cpurad.dtsi | 2 ++ dts/common/nordic/nrf54h20_enga.dtsi | 34 ++++++++++++++++++++++ dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi | 1 + 4 files changed, 39 insertions(+) diff --git a/dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi b/dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi index f51528d5733..de75e482bc0 100644 --- a/dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi +++ b/dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi @@ -10,6 +10,8 @@ cpu: &cpuapp {}; systick: &cpuapp_systick {}; nvic: &cpuapp_nvic {}; +cpuppr_vevif: &cpuppr_vevif_remote {}; + /delete-node/ &cpuppr; /delete-node/ &cpurad; /delete-node/ &cpurad_peripherals; diff --git a/dts/arm/nordic/nrf54h20_enga_cpurad.dtsi b/dts/arm/nordic/nrf54h20_enga_cpurad.dtsi index cb2767381da..744003d9225 100644 --- a/dts/arm/nordic/nrf54h20_enga_cpurad.dtsi +++ b/dts/arm/nordic/nrf54h20_enga_cpurad.dtsi @@ -10,6 +10,8 @@ cpu: &cpurad {}; systick: &cpurad_systick {}; nvic: &cpurad_nvic {}; +cpuppr_vevif: &cpuppr_vevif_remote {}; + /delete-node/ &cpuapp; /delete-node/ &cpuapp_peripherals; /delete-node/ &cpuapp_ppb; diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index 5a9af57801c..b9ac3d7d0bf 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -40,6 +40,31 @@ clock-frequency = ; riscv,isa = "rv32emc"; nordic,bus-width = <32>; + + cpuppr_vevif_local: mailbox { + compatible = "nordic,nrf-vevif-local"; + status = "disabled"; + interrupt-parent = <&cpuppr_clic>; + interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>, + <1 NRF_DEFAULT_IRQ_PRIORITY>, + <2 NRF_DEFAULT_IRQ_PRIORITY>, + <3 NRF_DEFAULT_IRQ_PRIORITY>, + <4 NRF_DEFAULT_IRQ_PRIORITY>, + <5 NRF_DEFAULT_IRQ_PRIORITY>, + <6 NRF_DEFAULT_IRQ_PRIORITY>, + <7 NRF_DEFAULT_IRQ_PRIORITY>, + <8 NRF_DEFAULT_IRQ_PRIORITY>, + <9 NRF_DEFAULT_IRQ_PRIORITY>, + <10 NRF_DEFAULT_IRQ_PRIORITY>, + <11 NRF_DEFAULT_IRQ_PRIORITY>, + <12 NRF_DEFAULT_IRQ_PRIORITY>, + <13 NRF_DEFAULT_IRQ_PRIORITY>, + <14 NRF_DEFAULT_IRQ_PRIORITY>, + <15 NRF_DEFAULT_IRQ_PRIORITY>; + #mbox-cells = <1>; + nordic,tasks = <16>; + nordic,tasks-mask = <0xfffffff0>; + }; }; }; @@ -281,6 +306,15 @@ #size-cells = <1>; ranges = <0x0 0x908000 0x4000>; + cpuppr_vevif_remote: mailbox@0 { + compatible = "nordic,nrf-vevif-remote"; + reg = <0x0 0x1000>; + status = "disabled"; + #mbox-cells = <1>; + nordic,tasks = <16>; + nordic,tasks-mask = <0xfffffff0>; + }; + cpuppr_clic: interrupt-controller@1000 { compatible = "nordic,nrf-clic"; reg = <0x1000 0x3000>; diff --git a/dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi b/dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi index d42a815a4b2..97457b1266c 100644 --- a/dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi +++ b/dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi @@ -8,6 +8,7 @@ cpu: &cpuppr {}; clic: &cpuppr_clic {}; +vevif: &cpuppr_vevif_local {}; /delete-node/ &cpuapp; /delete-node/ &cpuapp_peripherals; From 851de7e087d0aae184299f46f0f128e95dc16ec6 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 21 Feb 2024 17:33:24 +0100 Subject: [PATCH 1610/1623] [nrf fromlist] drivers: misc: nordic_vpr_launcher: initialize earlier Set driver to initialize at early POST_KERNEL, so that we make sure other future dependencies priorities (eg VEVIF) do not conflict. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 3e8ea343878acabdf163d1a084cef61f8e077ed5) --- drivers/misc/nordic_vpr_launcher/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/misc/nordic_vpr_launcher/Kconfig b/drivers/misc/nordic_vpr_launcher/Kconfig index 57605e505f2..6aeabcd251c 100644 --- a/drivers/misc/nordic_vpr_launcher/Kconfig +++ b/drivers/misc/nordic_vpr_launcher/Kconfig @@ -17,7 +17,7 @@ source "subsys/logging/Kconfig.template.log_config" config NORDIC_VPR_LAUNCHER_INIT_PRIORITY int "Nordic VPR coprocessor launcher init priority" - default KERNEL_INIT_PRIORITY_DEVICE + default 0 help The init priority of the VPR coprocessor launcher. From 942d10d274917268909d4d1714e50e39b973cfe3 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 21 Feb 2024 16:16:58 +0100 Subject: [PATCH 1611/1623] [nrf fromlist] drivers: mbox: add initial driver for nRF VEVIF Add a mailbox driver for VEVIF. The driver can be built in either 'local' or 'remote' configuration. This depends on the existence of the 'interrupts' property, which signals that the instance is managed locally. VEVIF is, as expected, always managed by a VPR core. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 16807ea1c8a6e2c719e43370b6b645539dc72933) --- drivers/mbox/CMakeLists.txt | 2 + drivers/mbox/Kconfig | 1 + drivers/mbox/Kconfig.nrf_vevif | 16 ++++ drivers/mbox/mbox_nrf_vevif_local.c | 123 +++++++++++++++++++++++++++ drivers/mbox/mbox_nrf_vevif_remote.c | 76 +++++++++++++++++ 5 files changed, 218 insertions(+) create mode 100644 drivers/mbox/Kconfig.nrf_vevif create mode 100644 drivers/mbox/mbox_nrf_vevif_local.c create mode 100644 drivers/mbox/mbox_nrf_vevif_remote.c diff --git a/drivers/mbox/CMakeLists.txt b/drivers/mbox/CMakeLists.txt index b81a3bb679f..6ecbfa5e7ed 100644 --- a/drivers/mbox/CMakeLists.txt +++ b/drivers/mbox/CMakeLists.txt @@ -9,3 +9,5 @@ zephyr_library_sources_ifdef(CONFIG_MBOX_NRFX_IPC mbox_nrfx_ipc.c) zephyr_library_sources_ifdef(CONFIG_MBOX_NXP_S32_MRU mbox_nxp_s32_mru.c) zephyr_library_sources_ifdef(CONFIG_MBOX_NXP_IMX_MU mbox_nxp_imx_mu.c) zephyr_library_sources_ifdef(CONFIG_MBOX_ANDES_PLIC_SW mbox_andes_plic_sw.c) +zephyr_library_sources_ifdef(CONFIG_MBOX_NRF_VEVIF_LOCAL mbox_nrf_vevif_local.c) +zephyr_library_sources_ifdef(CONFIG_MBOX_NRF_VEVIF_REMOTE mbox_nrf_vevif_remote.c) diff --git a/drivers/mbox/Kconfig b/drivers/mbox/Kconfig index 0668c9aab8b..711e6637c4e 100644 --- a/drivers/mbox/Kconfig +++ b/drivers/mbox/Kconfig @@ -15,6 +15,7 @@ source "drivers/mbox/Kconfig.nrfx" source "drivers/mbox/Kconfig.nxp_s32" source "drivers/mbox/Kconfig.nxp_imx" source "drivers/mbox/Kconfig.andes" +source "drivers/mbox/Kconfig.nrf_vevif" config MBOX_INIT_PRIORITY int "MBOX init priority" diff --git a/drivers/mbox/Kconfig.nrf_vevif b/drivers/mbox/Kconfig.nrf_vevif new file mode 100644 index 00000000000..4abb0ef8241 --- /dev/null +++ b/drivers/mbox/Kconfig.nrf_vevif @@ -0,0 +1,16 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config MBOX_NRF_VEVIF_LOCAL + bool "nRF VEVIF local driver" + depends on DT_HAS_NORDIC_NRF_VEVIF_LOCAL_ENABLED + default y + help + Mailbox driver for local Nordic nRF VEVIF (VPR Event Interface) + +config MBOX_NRF_VEVIF_REMOTE + bool "nRF VEVIF remote driver" + depends on DT_HAS_NORDIC_NRF_VEVIF_REMOTE_ENABLED + default y + help + Mailbox driver for remote Nordic nRF VEVIF (VPR Event Interface) diff --git a/drivers/mbox/mbox_nrf_vevif_local.c b/drivers/mbox/mbox_nrf_vevif_local.c new file mode 100644 index 00000000000..31b89e1e6fb --- /dev/null +++ b/drivers/mbox/mbox_nrf_vevif_local.c @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT nordic_nrf_vevif_local + +#include +#include + +#include +#include +#include + +#define VEVIF_TASKS_NUM DT_INST_PROP(0, nordic_tasks) +#define VEVIF_TASKS_MASK DT_INST_PROP(0, nordic_tasks_mask) + +BUILD_ASSERT(VEVIF_TASKS_NUM <= VPR_TASKS_TRIGGER_MaxCount, "Number of tasks exceeds maximum"); +BUILD_ASSERT(VEVIF_TASKS_NUM == DT_NUM_IRQS(DT_DRV_INST(0)), "# IRQs != # tasks"); + +/* callbacks */ +struct mbox_vevif_local_cbs { + mbox_callback_t cb[VEVIF_TASKS_NUM]; + void *user_data[VEVIF_TASKS_NUM]; + uint32_t enabled_mask; +}; + +static struct mbox_vevif_local_cbs cbs; + +/* IRQ list */ +#define VEVIF_IRQN(idx, _) DT_INST_IRQ_BY_IDX(0, idx, irq) + +static const uint8_t vevif_irqs[VEVIF_TASKS_NUM] = { + LISTIFY(DT_NUM_IRQS(DT_DRV_INST(0)), VEVIF_IRQN, (,)) +}; + +static void vevif_local_isr(const void *parameter) +{ + uint8_t id = *(uint8_t *)parameter; + + nrf_vpr_csr_vevif_tasks_clear(BIT(id)); + + if (cbs.cb[id] != NULL) { + cbs.cb[id](DEVICE_DT_INST_GET(0), id, cbs.user_data[id], NULL); + } +} + +static inline bool vevif_local_is_task_valid(uint32_t id) +{ + return (id < VEVIF_TASKS_NUM) && ((VEVIF_TASKS_MASK & BIT(id)) != 0U); +} + +static uint32_t vevif_local_max_channels_get(const struct device *dev) +{ + ARG_UNUSED(dev); + + return VEVIF_TASKS_NUM; +} + +static int vevif_local_register_callback(const struct device *dev, uint32_t id, mbox_callback_t cb, + void *user_data) +{ + ARG_UNUSED(dev); + + if (!vevif_local_is_task_valid(id)) { + return -EINVAL; + } + + cbs.cb[id] = cb; + cbs.user_data[id] = user_data; + + return 0; +} + +static int vevif_local_set_enabled(const struct device *dev, uint32_t id, bool enable) +{ + ARG_UNUSED(dev); + + if (!vevif_local_is_task_valid(id)) { + return -EINVAL; + } + + if (enable) { + if ((cbs.enabled_mask & BIT(id)) != 0U) { + return -EALREADY; + } + + cbs.enabled_mask |= BIT(id); + irq_enable(vevif_irqs[id]); + } else { + if ((cbs.enabled_mask & BIT(id)) == 0U) { + return -EALREADY; + } + + cbs.enabled_mask &= ~BIT(id); + irq_disable(vevif_irqs[id]); + } + + return 0; +} + +static const struct mbox_driver_api vevif_local_driver_api = { + .max_channels_get = vevif_local_max_channels_get, + .register_callback = vevif_local_register_callback, + .set_enabled = vevif_local_set_enabled, +}; + +#define VEVIF_IRQ_CONNECT(idx, _) \ + IRQ_CONNECT(DT_INST_IRQ_BY_IDX(0, idx, irq), DT_INST_IRQ_BY_IDX(0, idx, priority), \ + vevif_local_isr, &vevif_irqs[idx], 0) + +static int vevif_local_init(const struct device *dev) +{ + nrf_vpr_csr_rtperiph_enable_set(true); + nrf_vpr_csr_vevif_tasks_clear(NRF_VPR_TASK_TRIGGER_ALL_MASK); + + LISTIFY(DT_NUM_IRQS(DT_DRV_INST(0)), VEVIF_IRQ_CONNECT, (;)); + + return 0; +} + +DEVICE_DT_INST_DEFINE(0, vevif_local_init, NULL, NULL, NULL, POST_KERNEL, CONFIG_MBOX_INIT_PRIORITY, + &vevif_local_driver_api); diff --git a/drivers/mbox/mbox_nrf_vevif_remote.c b/drivers/mbox/mbox_nrf_vevif_remote.c new file mode 100644 index 00000000000..cb5d7c507c5 --- /dev/null +++ b/drivers/mbox/mbox_nrf_vevif_remote.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT nordic_nrf_vevif_remote + +#include +#include + +#include + +struct mbox_vevif_remote_conf { + NRF_VPR_Type *vpr; + uint32_t tasks_mask; + uint8_t tasks; +}; + +static inline bool vevif_remote_is_task_valid(const struct device *dev, uint32_t id) +{ + const struct mbox_vevif_remote_conf *config = dev->config; + + return (id < config->tasks) && ((config->tasks_mask & BIT(id)) != 0U); +} + +static int vevif_remote_send(const struct device *dev, uint32_t id, const struct mbox_msg *msg) +{ + const struct mbox_vevif_remote_conf *config = dev->config; + + if (!vevif_remote_is_task_valid(dev, id)) { + return -EINVAL; + } + + if (msg != NULL) { + return -ENOTSUP; + } + + nrfy_vpr_task_trigger(config->vpr, nrfy_vpr_trigger_task_get(id)); + + return 0; +} + +static int vevif_remote_mtu_get(const struct device *dev) +{ + ARG_UNUSED(dev); + + return 0; +} + +static uint32_t vevif_remote_max_channels_get(const struct device *dev) +{ + const struct mbox_vevif_remote_conf *config = dev->config; + + return config->tasks; +} + +static const struct mbox_driver_api vevif_remote_driver_api = { + .send = vevif_remote_send, + .mtu_get = vevif_remote_mtu_get, + .max_channels_get = vevif_remote_max_channels_get, +}; + +#define VEVIF_REMOTE_DEFINE(inst) \ + BUILD_ASSERT(DT_INST_PROP(inst, nordic_tasks) <= VPR_TASKS_TRIGGER_MaxCount, \ + "Number of tasks exceeds maximum"); \ + \ + static const struct mbox_vevif_remote_conf conf##inst = { \ + .vpr = (NRF_VPR_Type *)DT_INST_REG_ADDR(inst), \ + .tasks = DT_INST_PROP(inst, nordic_tasks), \ + .tasks_mask = DT_INST_PROP(inst, nordic_tasks_mask), \ + }; \ + \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, NULL, &conf##inst, POST_KERNEL, \ + CONFIG_MBOX_INIT_PRIORITY, &vevif_remote_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(VEVIF_REMOTE_DEFINE) From a1701713c22ad32b4345ee19e958f24d46e4e599 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 21 Feb 2024 17:42:14 +0100 Subject: [PATCH 1612/1623] [nrf fromlist] samples: drivers: mbox: allow to configure RX/TX channels By adding Kconfig options for both samples. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 253593c966f339e7aebbdbbbb8126963f3529ebe) --- samples/drivers/mbox/Kconfig | 13 +++++++++++++ samples/drivers/mbox/remote/Kconfig | 17 +++++++++++++++++ samples/drivers/mbox/remote/src/main.c | 7 ++----- samples/drivers/mbox/src/main.c | 7 ++----- 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 samples/drivers/mbox/remote/Kconfig diff --git a/samples/drivers/mbox/Kconfig b/samples/drivers/mbox/Kconfig index 3837c49b6e9..79dd2d09689 100644 --- a/samples/drivers/mbox/Kconfig +++ b/samples/drivers/mbox/Kconfig @@ -9,3 +9,16 @@ config INCLUDE_REMOTE_DIR help Include remote build header files. Can be used if primary image needs to be aware of size or base address of secondary image + +config TX_CHANNEL_ID + int "Channel ID for TX" + default 1 + help + Channel ID for TX + + +config RX_CHANNEL_ID + int "Channel ID for RX" + default 0 + help + Channel ID for RX diff --git a/samples/drivers/mbox/remote/Kconfig b/samples/drivers/mbox/remote/Kconfig new file mode 100644 index 00000000000..a8897e4aab0 --- /dev/null +++ b/samples/drivers/mbox/remote/Kconfig @@ -0,0 +1,17 @@ +# Copyright 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "Kconfig.zephyr" + +config TX_CHANNEL_ID + int "Channel ID for TX" + default 0 + help + Channel ID for TX + + +config RX_CHANNEL_ID + int "Channel ID for RX" + default 1 + help + Channel ID for RX diff --git a/samples/drivers/mbox/remote/src/main.c b/samples/drivers/mbox/remote/src/main.c index 89039e3b277..a256ed21daa 100644 --- a/samples/drivers/mbox/remote/src/main.c +++ b/samples/drivers/mbox/remote/src/main.c @@ -9,9 +9,6 @@ #include #include -#define TX_ID (0) -#define RX_ID (1) - static void callback(const struct device *dev, uint32_t channel, void *user_data, struct mbox_msg *data) { @@ -28,8 +25,8 @@ int main(void) dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); - mbox_init_channel(&tx_channel, dev, TX_ID); - mbox_init_channel(&rx_channel, dev, RX_ID); + mbox_init_channel(&tx_channel, dev, CONFIG_TX_CHANNEL_ID); + mbox_init_channel(&rx_channel, dev, CONFIG_RX_CHANNEL_ID); if (mbox_register_callback(&rx_channel, callback, NULL)) { printk("mbox_register_callback() error\n"); diff --git a/samples/drivers/mbox/src/main.c b/samples/drivers/mbox/src/main.c index d6c79729b4f..bfe28443f95 100644 --- a/samples/drivers/mbox/src/main.c +++ b/samples/drivers/mbox/src/main.c @@ -9,9 +9,6 @@ #include #include -#define TX_ID (1) -#define RX_ID (0) - static void callback(const struct device *dev, uint32_t channel, void *user_data, struct mbox_msg *data) { @@ -28,8 +25,8 @@ int main(void) dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); - mbox_init_channel(&tx_channel, dev, TX_ID); - mbox_init_channel(&rx_channel, dev, RX_ID); + mbox_init_channel(&tx_channel, dev, CONFIG_TX_CHANNEL_ID); + mbox_init_channel(&rx_channel, dev, CONFIG_RX_CHANNEL_ID); if (mbox_register_callback(&rx_channel, callback, NULL)) { printk("mbox_register_callback() error\n"); From 20f4571b37cf92b6558eb81551401fd5c6f97105 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 21 Feb 2024 17:48:59 +0100 Subject: [PATCH 1613/1623] [nrf fromlist] samples: drivers: mbox: allow to enable RX/TX This can be useful to provide multiple setups, eg unidirectional ping-pong. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 5cb43795d8082be70e4a18f90e66c50122f3c293) --- samples/drivers/mbox/Kconfig | 13 +++++++++++++ samples/drivers/mbox/remote/Kconfig | 13 +++++++++++++ samples/drivers/mbox/remote/src/main.c | 20 +++++++++++++++++--- samples/drivers/mbox/src/main.c | 15 ++++++++++++--- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/samples/drivers/mbox/Kconfig b/samples/drivers/mbox/Kconfig index 79dd2d09689..3af6e740bfc 100644 --- a/samples/drivers/mbox/Kconfig +++ b/samples/drivers/mbox/Kconfig @@ -10,15 +10,28 @@ config INCLUDE_REMOTE_DIR Include remote build header files. Can be used if primary image needs to be aware of size or base address of secondary image +config TX_ENABLED + bool "TX enabled" + default y + help + Enable TX + config TX_CHANNEL_ID int "Channel ID for TX" default 1 + depends on TX_ENABLED help Channel ID for TX +config RX_ENABLED + bool "RX enabled" + default y + help + Enable RX config RX_CHANNEL_ID int "Channel ID for RX" + depends on RX_ENABLED default 0 help Channel ID for RX diff --git a/samples/drivers/mbox/remote/Kconfig b/samples/drivers/mbox/remote/Kconfig index a8897e4aab0..7edb8574359 100644 --- a/samples/drivers/mbox/remote/Kconfig +++ b/samples/drivers/mbox/remote/Kconfig @@ -3,15 +3,28 @@ source "Kconfig.zephyr" +config TX_ENABLED + bool "TX enabled" + default y + help + Enable TX + config TX_CHANNEL_ID int "Channel ID for TX" default 0 + depends on TX_ENABLED help Channel ID for TX +config RX_ENABLED + bool "RX enabled" + default y + help + Enable RX config RX_CHANNEL_ID int "Channel ID for RX" + depends on RX_ENABLED default 1 help Channel ID for RX diff --git a/samples/drivers/mbox/remote/src/main.c b/samples/drivers/mbox/remote/src/main.c index a256ed21daa..31665951172 100644 --- a/samples/drivers/mbox/remote/src/main.c +++ b/samples/drivers/mbox/remote/src/main.c @@ -9,23 +9,29 @@ #include #include +#if !defined(CONFIG_RX_ENABLED) && !defined(CONFIG_TX_ENABLED) +#error "At least one of CONFIG_RX_ENABLED or CONFIG_TX_ENABLED must be set" +#endif + +#ifdef CONFIG_RX_ENABLED static void callback(const struct device *dev, uint32_t channel, void *user_data, struct mbox_msg *data) { printk("Pong (on channel %d)\n", channel); } +#endif /* CONFIG_RX_ENABLED */ int main(void) { - struct mbox_channel tx_channel; - struct mbox_channel rx_channel; const struct device *dev; printk("Hello from NET\n"); dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); - mbox_init_channel(&tx_channel, dev, CONFIG_TX_CHANNEL_ID); +#ifdef CONFIG_RX_ENABLED + struct mbox_channel rx_channel; + mbox_init_channel(&rx_channel, dev, CONFIG_RX_CHANNEL_ID); if (mbox_register_callback(&rx_channel, callback, NULL)) { @@ -37,6 +43,12 @@ int main(void) printk("mbox_set_enable() error\n"); return 0; } +#endif /* CONFIG_RX_ENABLED */ + +#ifdef CONFIG_TX_ENABLED + struct mbox_channel tx_channel; + + mbox_init_channel(&tx_channel, dev, CONFIG_TX_CHANNEL_ID); while (1) { @@ -49,5 +61,7 @@ int main(void) k_sleep(K_MSEC(3000)); } +#endif /* CONFIG_TX_ENABLED */ + return 0; } diff --git a/samples/drivers/mbox/src/main.c b/samples/drivers/mbox/src/main.c index bfe28443f95..cea34afb29a 100644 --- a/samples/drivers/mbox/src/main.c +++ b/samples/drivers/mbox/src/main.c @@ -9,23 +9,25 @@ #include #include +#ifdef CONFIG_RX_ENABLED static void callback(const struct device *dev, uint32_t channel, void *user_data, struct mbox_msg *data) { printk("Pong (on channel %d)\n", channel); } +#endif int main(void) { - struct mbox_channel tx_channel; - struct mbox_channel rx_channel; const struct device *dev; printk("Hello from APP\n"); dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); - mbox_init_channel(&tx_channel, dev, CONFIG_TX_CHANNEL_ID); +#ifdef CONFIG_RX_ENABLED + struct mbox_channel rx_channel; + mbox_init_channel(&rx_channel, dev, CONFIG_RX_CHANNEL_ID); if (mbox_register_callback(&rx_channel, callback, NULL)) { @@ -37,6 +39,12 @@ int main(void) printk("mbox_set_enable() error\n"); return 0; } +#endif /* CONFIG_RX_ENABLED */ + +#ifdef CONFIG_TX_ENABLED + struct mbox_channel tx_channel; + + mbox_init_channel(&tx_channel, dev, CONFIG_TX_CHANNEL_ID); while (1) { k_sleep(K_MSEC(2000)); @@ -48,5 +56,6 @@ int main(void) return 0; } } +#endif /* CONFIG_TX_ENABLED */ return 0; } From 56cc531bd5ba1ea1f22e726f9cbd9b72247cc8fb Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 21 Feb 2024 17:59:22 +0100 Subject: [PATCH 1614/1623] [nrf fromlist] samples: drivers: mbox: misc cleanups/enhancements - Include cleanup - s/NET/REMOTE (remote core may have nothing to do with NET) - Improved error reporting Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit cf67d54ed49d896112a285044a12a28b7dfacff0) --- samples/drivers/mbox/remote/src/main.c | 26 +++++++++++++------------- samples/drivers/mbox/src/main.c | 23 ++++++++++++----------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/samples/drivers/mbox/remote/src/main.c b/samples/drivers/mbox/remote/src/main.c index 31665951172..1ca832a697c 100644 --- a/samples/drivers/mbox/remote/src/main.c +++ b/samples/drivers/mbox/remote/src/main.c @@ -4,10 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include #include #include +#include #if !defined(CONFIG_RX_ENABLED) && !defined(CONFIG_TX_ENABLED) #error "At least one of CONFIG_RX_ENABLED or CONFIG_TX_ENABLED must be set" @@ -23,24 +22,25 @@ static void callback(const struct device *dev, uint32_t channel, int main(void) { - const struct device *dev; + int ret; + const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); - printk("Hello from NET\n"); - - dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); + printk("Hello from REMOTE\n"); #ifdef CONFIG_RX_ENABLED struct mbox_channel rx_channel; mbox_init_channel(&rx_channel, dev, CONFIG_RX_CHANNEL_ID); - if (mbox_register_callback(&rx_channel, callback, NULL)) { - printk("mbox_register_callback() error\n"); + ret = mbox_register_callback(&rx_channel, callback, NULL); + if (ret < 0) { + printk("Could not register callback (%d)\n", ret); return 0; } - if (mbox_set_enabled(&rx_channel, 1)) { - printk("mbox_set_enable() error\n"); + ret = mbox_set_enabled(&rx_channel, true); + if (ret < 0) { + printk("Could not enable RX channel %d (%d)\n", rx_channel.id, ret); return 0; } #endif /* CONFIG_RX_ENABLED */ @@ -51,11 +51,11 @@ int main(void) mbox_init_channel(&tx_channel, dev, CONFIG_TX_CHANNEL_ID); while (1) { - printk("Ping (on channel %d)\n", tx_channel.id); - if (mbox_send(&tx_channel, NULL) < 0) { - printk("mbox_send() error\n"); + ret = mbox_send(&tx_channel, NULL); + if (ret < 0) { + printk("Could not send (%d)\n", ret); return 0; } diff --git a/samples/drivers/mbox/src/main.c b/samples/drivers/mbox/src/main.c index cea34afb29a..d4dd21d342f 100644 --- a/samples/drivers/mbox/src/main.c +++ b/samples/drivers/mbox/src/main.c @@ -4,10 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include #include #include +#include #ifdef CONFIG_RX_ENABLED static void callback(const struct device *dev, uint32_t channel, @@ -19,24 +18,25 @@ static void callback(const struct device *dev, uint32_t channel, int main(void) { - const struct device *dev; + int ret; + const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); printk("Hello from APP\n"); - dev = DEVICE_DT_GET(DT_NODELABEL(mbox)); - #ifdef CONFIG_RX_ENABLED struct mbox_channel rx_channel; mbox_init_channel(&rx_channel, dev, CONFIG_RX_CHANNEL_ID); - if (mbox_register_callback(&rx_channel, callback, NULL)) { - printk("mbox_register_callback() error\n"); + ret = mbox_register_callback(&rx_channel, callback, NULL); + if (ret < 0) { + printk("Could not register callback (%d)\n", ret); return 0; } - if (mbox_set_enabled(&rx_channel, 1)) { - printk("mbox_set_enable() error\n"); + ret = mbox_set_enabled(&rx_channel, true); + if (ret < 0) { + printk("Could not enable RX channel %d (%d)\n", rx_channel.id, ret); return 0; } #endif /* CONFIG_RX_ENABLED */ @@ -51,8 +51,9 @@ int main(void) printk("Ping (on channel %d)\n", tx_channel.id); - if (mbox_send(&tx_channel, NULL) < 0) { - printk("mbox_send() error\n"); + ret = mbox_send(&tx_channel, NULL); + if (ret < 0) { + printk("Could not send (%d)\n", ret); return 0; } } From 9a44e174184da1ee67f9ec24c143fb3b90c78be7 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 21 Feb 2024 17:36:43 +0100 Subject: [PATCH 1615/1623] [nrf fromlist] samples: drivers: mbox: add support for nRF VEVIF Add support for nRF VEVIF. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit f2b887b5b8f8207072e599f4b6963e9a55b07f86) --- samples/drivers/mbox/CMakeLists.txt | 3 ++- samples/drivers/mbox/Kconfig.sysbuild | 1 + .../nrf54h20pdk_nrf54h20_cpuapp_vevif.conf | 2 ++ .../nrf54h20pdk_nrf54h20_cpuapp_vevif.overlay | 8 +++++++ samples/drivers/mbox/remote/CMakeLists.txt | 3 ++- .../nrf54h20pdk_nrf54h20_cpuppr_vevif.conf | 2 ++ .../nrf54h20pdk_nrf54h20_cpuppr_vevif.overlay | 8 +++++++ samples/drivers/mbox/sample.yaml | 21 +++++++++++++++++++ 8 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_vevif.conf create mode 100644 samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_vevif.overlay create mode 100644 samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_vevif.conf create mode 100644 samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_vevif.overlay diff --git a/samples/drivers/mbox/CMakeLists.txt b/samples/drivers/mbox/CMakeLists.txt index ec79db9deed..c69621c2496 100644 --- a/samples/drivers/mbox/CMakeLists.txt +++ b/samples/drivers/mbox/CMakeLists.txt @@ -17,7 +17,8 @@ if(("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpuapp") OR ("${BOARD}" STREQUAL "mimxrt1170_evkb_cm7") OR ("${BOARD}" STREQUAL "mimxrt1170_evk_cm7") OR ("${BOARD}" STREQUAL "mimxrt1160_evk_cm7") OR - ("${BOARD}" STREQUAL "lpcxpresso55s69_cpu0")) + ("${BOARD}" STREQUAL "lpcxpresso55s69_cpu0") OR + ("${BOARD}" STREQUAL "nrf54h20pdk_nrf54h20_cpuapp")) message(STATUS "${BOARD} compile as Main in this sample") else() message(FATAL_ERROR "${BOARD} is not supported for this sample") diff --git a/samples/drivers/mbox/Kconfig.sysbuild b/samples/drivers/mbox/Kconfig.sysbuild index a17dd56ee55..aca48b8ead3 100644 --- a/samples/drivers/mbox/Kconfig.sysbuild +++ b/samples/drivers/mbox/Kconfig.sysbuild @@ -14,3 +14,4 @@ string default "mimxrt1170_evk_cm4" if $(BOARD) = "mimxrt1170_evk_cm7" default "mimxrt1160_evk_cm4" if $(BOARD) = "mimxrt1160_evk_cm7" default "lpcxpresso55s69_cpu1" if $(BOARD) = "lpcxpresso55s69_cpu0" + default "nrf54h20pdk_nrf54h20_cpuppr" if $(BOARD) = "nrf54h20pdk_nrf54h20_cpuapp" diff --git a/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_vevif.conf b/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_vevif.conf new file mode 100644 index 00000000000..d8d66e9812d --- /dev/null +++ b/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_vevif.conf @@ -0,0 +1,2 @@ +CONFIG_RX_ENABLED=n +CONFIG_TX_CHANNEL_ID=4 diff --git a/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_vevif.overlay b/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_vevif.overlay new file mode 100644 index 00000000000..ed631f04cc3 --- /dev/null +++ b/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_vevif.overlay @@ -0,0 +1,8 @@ +/* + * Copyright 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +mbox: &cpuppr_vevif { + status = "okay"; +}; diff --git a/samples/drivers/mbox/remote/CMakeLists.txt b/samples/drivers/mbox/remote/CMakeLists.txt index 2c7c8fff29e..cb024cb6112 100644 --- a/samples/drivers/mbox/remote/CMakeLists.txt +++ b/samples/drivers/mbox/remote/CMakeLists.txt @@ -15,7 +15,8 @@ if(("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet") OR ("${BOARD}" STREQUAL "mimxrt1170_evk_cm4") OR ("${BOARD}" STREQUAL "mimxrt1160_evk_cm4") OR ("${BOARD}" STREQUAL "lpcxpresso55s69_cpu1") OR - ("${BOARD}" STREQUAL "adp_xc7k_ae350")) + ("${BOARD}" STREQUAL "adp_xc7k_ae350") OR + ("${BOARD}" STREQUAL "nrf54h20pdk_nrf54h20_cpuppr")) message(STATUS "${BOARD} compile as remote in this sample") else() message(FATAL_ERROR "${BOARD} is not supported for this sample") diff --git a/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_vevif.conf b/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_vevif.conf new file mode 100644 index 00000000000..19e03b75c63 --- /dev/null +++ b/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_vevif.conf @@ -0,0 +1,2 @@ +CONFIG_TX_ENABLED=n +CONFIG_RX_CHANNEL_ID=4 diff --git a/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_vevif.overlay b/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_vevif.overlay new file mode 100644 index 00000000000..c765b35022c --- /dev/null +++ b/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_vevif.overlay @@ -0,0 +1,8 @@ +/* + * Copyright 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +mbox: &vevif { + status = "okay"; +}; diff --git a/samples/drivers/mbox/sample.yaml b/samples/drivers/mbox/sample.yaml index e38deda55d3..8c85a8d5150 100644 --- a/samples/drivers/mbox/sample.yaml +++ b/samples/drivers/mbox/sample.yaml @@ -23,6 +23,27 @@ tests: - "Pong \\(on channel 0\\)" - "Ping \\(on channel 1\\)" - "Pong \\(on channel 1\\)" + + sample.drivers.mbox.nrf54h20_vevif: + platform_allow: + - nrf54h20pdk_nrf54h20_cpuapp + integration_platforms: + - nrf54h20pdk_nrf54h20_cpuapp + extra_args: + mbox_SNIPPET=nordic-ppr + mbox_EXTRA_CONF_FILE=boards/nrf54h20pdk_nrf54h20_cpuapp_vevif.conf + mbox_DTC_OVERLAY_FILE=boards/nrf54h20pdk_nrf54h20_cpuapp_vevif.overlay + remote_EXTRA_CONF_FILE=boards/nrf54h20pdk_nrf54h20_cpuppr_vevif.conf + remote_DTC_OVERLAY_FILE=boards/nrf54h20pdk_nrf54h20_cpuppr_vevif.overlay + sysbuild: true + harness: console + harness_config: + type: multi_line + ordered: false + regex: + - "Ping \\(on channel 4\\)" + - "Pong \\(on channel 4\\)" + sample.drivers.mbox.simu: platform_allow: - nrf5340bsim_nrf5340_cpuapp From 10563e2ffaed381c3f593fac7df98ef0bb8d3a41 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 22 Feb 2024 16:23:08 +0100 Subject: [PATCH 1616/1623] [nrf fromlist] dts: bindings: mbox: add nordic,nrf-bellboard-local|remote Add new bindings to describe the BELLBOARD peripheral in its two _programming modes_ local or remote. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit fc76661da25e408d6580f10d3efdc5cfcceb85cf) --- .../mbox/nordic,nrf-bellboard-common.yaml | 11 +++++ .../mbox/nordic,nrf-bellboard-local.yaml | 43 +++++++++++++++++++ .../mbox/nordic,nrf-bellboard-remote.yaml | 22 ++++++++++ 3 files changed, 76 insertions(+) create mode 100644 dts/bindings/mbox/nordic,nrf-bellboard-common.yaml create mode 100644 dts/bindings/mbox/nordic,nrf-bellboard-local.yaml create mode 100644 dts/bindings/mbox/nordic,nrf-bellboard-remote.yaml diff --git a/dts/bindings/mbox/nordic,nrf-bellboard-common.yaml b/dts/bindings/mbox/nordic,nrf-bellboard-common.yaml new file mode 100644 index 00000000000..0d1d0bc26e2 --- /dev/null +++ b/dts/bindings/mbox/nordic,nrf-bellboard-common.yaml @@ -0,0 +1,11 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +include: [base.yaml, "mailbox-controller.yaml"] + +properties: + reg: + required: true + +mbox-cells: + - channel diff --git a/dts/bindings/mbox/nordic,nrf-bellboard-local.yaml b/dts/bindings/mbox/nordic,nrf-bellboard-local.yaml new file mode 100644 index 00000000000..5c1709987cc --- /dev/null +++ b/dts/bindings/mbox/nordic,nrf-bellboard-local.yaml @@ -0,0 +1,43 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + Nordic BELLBOARD + + BELLBOARD provides support for inter-domain software signaling. It implements + a set of tasks and events intended for signaling within an interprocessor + communication (IPC) framework. When used in local mode, the BELLBOARD + instance is used to receive events triggered by other remote cores. + + Example definition: + + bellboard: mailbox@deadbeef { + compatible = "nordic,nrf-bellboard-local"; + reg = <0xdeadbeef 0x1000>; + interrupts = <98 NRF_DEFAULT_IRQ_PRIORITY>, + <99 NRF_DEFAULT_IRQ_PRIORITY>; + interrupt-names = "irq2", "irq3"; + nordic,interrupt-mapping = <0x0000000f 2>, <0x000000f0 3>; + #mbox-cells = <1>; + }; + +compatible: "nordic,nrf-bellboard-local" + +include: "nordic,nrf-bellboard-common.yaml" + +properties: + interrupts: + required: true + + interrupt-names: + required: true + + nordic,interrupt-mapping: + type: array + required: true + description: | + Set of interrupt mapping pairs. Each pair consists of a bitmask and an + interrupt identifier. The bitmask is used to indicate which of the 32 + possible events are mapped to the given interrupt. For example, given + <0x0000000f 2>, the first four events are mapped to interrupt 2 + (irq2). diff --git a/dts/bindings/mbox/nordic,nrf-bellboard-remote.yaml b/dts/bindings/mbox/nordic,nrf-bellboard-remote.yaml new file mode 100644 index 00000000000..ae17fc916a1 --- /dev/null +++ b/dts/bindings/mbox/nordic,nrf-bellboard-remote.yaml @@ -0,0 +1,22 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + Nordic BELLBOARD + + BELLBOARD provides support for inter-domain software signaling. It implements + a set of tasks and events intended for signaling within an interprocessor + communication (IPC) framework. When used in remote mode, the BELLBOARD + instance is used to trigger events to another core. + + Example definition: + + bellboard: mailbox@deadbeef { + compatible = "nordic,nrf-bellboard-remote"; + reg = <0xdeadbeef 0x1000>; + #mbox-cells = <1>; + }; + +compatible: "nordic,nrf-bellboard-remote" + +include: "nordic,nrf-bellboard-common.yaml" From 831c6b056dfbc412aea0c2d824c44ec11a2a8db4 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 22 Feb 2024 16:24:14 +0100 Subject: [PATCH 1617/1623] [nrf fromlist] dts: nordic: nrf54h20_enga: add BELLBOARD nodes Add nodes for APP/RAD BELLBOARD peripherals. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 19dca26c3c2801123b6c4e7e9d7915dba4f4ccce) --- dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi | 12 ++++++++++++ dts/arm/nordic/nrf54h20_enga_cpurad.dtsi | 12 ++++++++++++ dts/common/nordic/nrf54h20_enga.dtsi | 18 ++++++++++++++++++ dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi | 12 ++++++++++++ 4 files changed, 54 insertions(+) diff --git a/dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi b/dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi index de75e482bc0..38b77956a78 100644 --- a/dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi +++ b/dts/arm/nordic/nrf54h20_enga_cpuapp.dtsi @@ -31,6 +31,18 @@ cpuppr_vevif: &cpuppr_vevif_remote {}; ranges; }; +&cpusec_bellboard { + compatible = "nordic,nrf-bellboard-remote"; +}; + +&cpuapp_bellboard { + compatible = "nordic,nrf-bellboard-local"; +}; + +&cpurad_bellboard { + compatible = "nordic,nrf-bellboard-remote"; +}; + &gpiote130 { interrupts = <105 NRF_DEFAULT_IRQ_PRIORITY>; }; diff --git a/dts/arm/nordic/nrf54h20_enga_cpurad.dtsi b/dts/arm/nordic/nrf54h20_enga_cpurad.dtsi index 744003d9225..f7245c6c238 100644 --- a/dts/arm/nordic/nrf54h20_enga_cpurad.dtsi +++ b/dts/arm/nordic/nrf54h20_enga_cpurad.dtsi @@ -31,6 +31,18 @@ cpuppr_vevif: &cpuppr_vevif_remote {}; ranges; }; +&cpusec_bellboard { + compatible = "nordic,nrf-bellboard-remote"; +}; + +&cpuapp_bellboard { + compatible = "nordic,nrf-bellboard-remote"; +}; + +&cpurad_bellboard { + compatible = "nordic,nrf-bellboard-local"; +}; + &gpiote130 { interrupts = <105 NRF_DEFAULT_IRQ_PRIORITY>; }; diff --git a/dts/common/nordic/nrf54h20_enga.dtsi b/dts/common/nordic/nrf54h20_enga.dtsi index b9ac3d7d0bf..610fbd81587 100644 --- a/dts/common/nordic/nrf54h20_enga.dtsi +++ b/dts/common/nordic/nrf54h20_enga.dtsi @@ -248,6 +248,24 @@ #size-cells = <1>; ranges = <0x0 0x5f000000 0x1000000>; + cpusec_bellboard: mailbox@99000 { + reg = <0x99000 0x1000>; + status = "disabled"; + #mbox-cells = <1>; + }; + + cpuapp_bellboard: mailbox@9a000 { + reg = <0x9a000 0x1000>; + status = "disabled"; + #mbox-cells = <1>; + }; + + cpurad_bellboard: mailbox@9b000 { + reg = <0x9b000 0x1000>; + status = "disabled"; + #mbox-cells = <1>; + }; + timer120: timer@8e2000 { compatible = "nordic,nrf-timer"; reg = <0x8e2000 0x1000>; diff --git a/dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi b/dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi index 97457b1266c..3bcc2e286ab 100644 --- a/dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi +++ b/dts/riscv/nordic/nrf54h20_enga_cpuppr.dtsi @@ -27,6 +27,18 @@ vevif: &cpuppr_vevif_local {}; }; }; +&cpusec_bellboard { + compatible = "nordic,nrf-bellboard-remote"; +}; + +&cpuapp_bellboard { + compatible = "nordic,nrf-bellboard-remote"; +}; + +&cpurad_bellboard { + compatible = "nordic,nrf-bellboard-remote"; +}; + &gpiote130 { interrupts = <104 NRF_DEFAULT_IRQ_PRIORITY>; }; From 4ff2b8ae813cfeac39548ee5467433996fe8e89b Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 22 Feb 2024 16:26:00 +0100 Subject: [PATCH 1618/1623] [nrf fromlist] drivers: mbox: nrf_bellboard: add initial driver Add a new driver for nRF BELLBOARD peripheral, in both local and remote modes. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit c0d4e0294cbf35a0a14e3a5726a8f1f01689876e) --- drivers/mbox/CMakeLists.txt | 2 + drivers/mbox/Kconfig | 1 + drivers/mbox/Kconfig.nrf_bellboard | 16 +++ drivers/mbox/mbox_nrf_bellboard_local.c | 169 +++++++++++++++++++++++ drivers/mbox/mbox_nrf_bellboard_remote.c | 62 +++++++++ 5 files changed, 250 insertions(+) create mode 100644 drivers/mbox/Kconfig.nrf_bellboard create mode 100644 drivers/mbox/mbox_nrf_bellboard_local.c create mode 100644 drivers/mbox/mbox_nrf_bellboard_remote.c diff --git a/drivers/mbox/CMakeLists.txt b/drivers/mbox/CMakeLists.txt index 6ecbfa5e7ed..476e131f00b 100644 --- a/drivers/mbox/CMakeLists.txt +++ b/drivers/mbox/CMakeLists.txt @@ -11,3 +11,5 @@ zephyr_library_sources_ifdef(CONFIG_MBOX_NXP_IMX_MU mbox_nxp_imx_mu.c) zephyr_library_sources_ifdef(CONFIG_MBOX_ANDES_PLIC_SW mbox_andes_plic_sw.c) zephyr_library_sources_ifdef(CONFIG_MBOX_NRF_VEVIF_LOCAL mbox_nrf_vevif_local.c) zephyr_library_sources_ifdef(CONFIG_MBOX_NRF_VEVIF_REMOTE mbox_nrf_vevif_remote.c) +zephyr_library_sources_ifdef(CONFIG_MBOX_NRF_BELLBOARD_LOCAL mbox_nrf_bellboard_local.c) +zephyr_library_sources_ifdef(CONFIG_MBOX_NRF_BELLBOARD_REMOTE mbox_nrf_bellboard_remote.c) diff --git a/drivers/mbox/Kconfig b/drivers/mbox/Kconfig index 711e6637c4e..eb138dca145 100644 --- a/drivers/mbox/Kconfig +++ b/drivers/mbox/Kconfig @@ -16,6 +16,7 @@ source "drivers/mbox/Kconfig.nxp_s32" source "drivers/mbox/Kconfig.nxp_imx" source "drivers/mbox/Kconfig.andes" source "drivers/mbox/Kconfig.nrf_vevif" +source "drivers/mbox/Kconfig.nrf_bellboard" config MBOX_INIT_PRIORITY int "MBOX init priority" diff --git a/drivers/mbox/Kconfig.nrf_bellboard b/drivers/mbox/Kconfig.nrf_bellboard new file mode 100644 index 00000000000..45233122bd5 --- /dev/null +++ b/drivers/mbox/Kconfig.nrf_bellboard @@ -0,0 +1,16 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config MBOX_NRF_BELLBOARD_LOCAL + bool "nRF BELLBOARD local driver" + depends on DT_HAS_NORDIC_NRF_BELLBOARD_LOCAL_ENABLED + default y + help + Mailbox driver for local Nordic nRF BELLBOARD + +config MBOX_NRF_BELLBOARD_REMOTE + bool "nRF BELLBOARD remote driver" + depends on DT_HAS_NORDIC_NRF_BELLBOARD_REMOTE_ENABLED + default y + help + Mailbox driver for remote Nordic nRF BELLBOARD diff --git a/drivers/mbox/mbox_nrf_bellboard_local.c b/drivers/mbox/mbox_nrf_bellboard_local.c new file mode 100644 index 00000000000..99d05351aaa --- /dev/null +++ b/drivers/mbox/mbox_nrf_bellboard_local.c @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT nordic_nrf_bellboard_local + +#include +#include +#include + +#include + +#define BELLBOARD_NUM_IRQS 4U + +BUILD_ASSERT(DT_NUM_IRQS(DT_DRV_INST(0)) <= BELLBOARD_NUM_IRQS, "# interrupt exceeds maximum"); + +BUILD_ASSERT((DT_INST_PROP_LEN(0, nordic_interrupt_mapping) % 2) == 0, + "# interrupt mappings not specified in pairs"); + +/* BELLBOARD event mappings */ +#define EVT_MAPPING_ITEM(idx) DT_INST_PROP_BY_IDX(0, nordic_interrupt_mapping, idx) +#define BELLBOARD_GET_EVT_MAPPING(idx, _) \ + COND_CODE_1( \ + DT_INST_PROP_HAS_IDX(0, nordic_interrupt_mapping, UTIL_INC(UTIL_X2(idx))), \ + ([EVT_MAPPING_ITEM(UTIL_INC(UTIL_X2(idx)))] = EVT_MAPPING_ITEM(UTIL_X2(idx)),), \ + ()) + +static const uint32_t evt_mappings[BELLBOARD_NUM_IRQS] = { + LISTIFY(DT_NUM_IRQS(DT_DRV_INST(0)), BELLBOARD_GET_EVT_MAPPING, ())}; + +/* BELLBOARD instance */ +static NRF_BELLBOARD_Type *bellboard = (NRF_BELLBOARD_Type *)DT_INST_REG_ADDR(0); + +/* BELLBOARD runtime resources */ +static mbox_callback_t cbs[NRF_BELLBOARD_EVENTS_TRIGGERED_COUNT]; +static void *cbs_ctx[NRF_BELLBOARD_EVENTS_TRIGGERED_COUNT]; +static uint32_t evt_enabled_masks[BELLBOARD_NUM_IRQS]; + +static void bellboard_local_isr(const void *parameter) +{ + uint8_t irq_idx = (uint8_t)(uintptr_t)parameter; + uint32_t int_pend; + + int_pend = nrf_bellboard_int_pending_get(bellboard, irq_idx); + + for (uint8_t i = 0U; i < NRF_BELLBOARD_EVENTS_TRIGGERED_COUNT; i++) { + nrf_bellboard_event_t event = nrf_bellboard_triggered_event_get(i); + + if (nrf_bellboard_event_check(bellboard, event)) { + nrf_bellboard_event_clear(bellboard, event); + } + + if ((int_pend & BIT(i)) != 0U) { + if (cbs[i] != NULL) { + cbs[i](DEVICE_DT_INST_GET(0), i, cbs_ctx[i], NULL); + } + } + } +} + +static uint32_t bellboard_local_max_channels_get(const struct device *dev) +{ + ARG_UNUSED(dev); + + return NRF_BELLBOARD_EVENTS_TRIGGERED_COUNT; +} + +static int bellboard_local_register_callback(const struct device *dev, uint32_t id, + mbox_callback_t cb, void *user_data) +{ + ARG_UNUSED(dev); + + if (id >= NRF_BELLBOARD_EVENTS_TRIGGERED_COUNT) { + return -EINVAL; + } + + cbs[id] = cb; + cbs_ctx[id] = user_data; + + return 0; +} + +static int bellboard_local_set_enabled(const struct device *dev, uint32_t id, bool enable) +{ + bool valid_found = false; + + ARG_UNUSED(dev); + + if (id >= NRF_BELLBOARD_EVENTS_TRIGGERED_COUNT) { + return -EINVAL; + } + + for (uint8_t i = 0U; i < BELLBOARD_NUM_IRQS; i++) { + uint32_t *evt_enabled_mask; + + if ((evt_mappings[i] == 0U) || ((evt_mappings[i] & BIT(id)) == 0U)) { + continue; + } + + valid_found = true; + evt_enabled_mask = &evt_enabled_masks[i]; + + if (enable) { + if ((*evt_enabled_mask & BIT(id)) != 0U) { + return -EALREADY; + } + + *evt_enabled_mask |= BIT(id); + nrf_bellboard_int_enable(bellboard, i, BIT(id)); + } else { + if ((*evt_enabled_mask & BIT(id)) == 0U) { + return -EALREADY; + } + + *evt_enabled_mask &= ~BIT(id); + nrf_bellboard_int_disable(bellboard, i, BIT(id)); + } + } + + if (!valid_found) { + return -EINVAL; + } + + return 0; +} + +static const struct mbox_driver_api bellboard_local_driver_api = { + .max_channels_get = bellboard_local_max_channels_get, + .register_callback = bellboard_local_register_callback, + .set_enabled = bellboard_local_set_enabled, +}; + +#define BELLBOARD_IRQ_CONFIGURE(name, idx) \ + COND_CODE_1(DT_INST_IRQ_HAS_NAME(0, name), \ + (IRQ_CONNECT(DT_INST_IRQ_BY_NAME(0, name, irq), \ + DT_INST_IRQ_BY_NAME(0, name, priority), bellboard_local_isr, \ + (const void *)idx, 0); \ + irq_enable(DT_INST_IRQ_BY_NAME(0, name, irq));), \ + ()) + +static int bellboard_local_init(const struct device *dev) +{ + uint32_t evt_all_mappings = + evt_mappings[0] | evt_mappings[1] | evt_mappings[2] | evt_mappings[3]; + + ARG_UNUSED(dev); + + nrf_bellboard_int_disable(bellboard, 0, evt_mappings[0]); + nrf_bellboard_int_disable(bellboard, 1, evt_mappings[1]); + nrf_bellboard_int_disable(bellboard, 2, evt_mappings[2]); + nrf_bellboard_int_disable(bellboard, 3, evt_mappings[3]); + + for (uint8_t i = 0U; i < NRF_BELLBOARD_EVENTS_TRIGGERED_COUNT; i++) { + if ((evt_all_mappings & BIT(i)) != 0U) { + nrf_bellboard_event_clear(bellboard, nrf_bellboard_triggered_event_get(i)); + } + } + + BELLBOARD_IRQ_CONFIGURE(irq0, 0); + BELLBOARD_IRQ_CONFIGURE(irq1, 1); + BELLBOARD_IRQ_CONFIGURE(irq2, 2); + BELLBOARD_IRQ_CONFIGURE(irq3, 3); + + return 0; +} + +DEVICE_DT_INST_DEFINE(0, bellboard_local_init, NULL, NULL, NULL, POST_KERNEL, + CONFIG_MBOX_INIT_PRIORITY, &bellboard_local_driver_api); diff --git a/drivers/mbox/mbox_nrf_bellboard_remote.c b/drivers/mbox/mbox_nrf_bellboard_remote.c new file mode 100644 index 00000000000..c362522c0bf --- /dev/null +++ b/drivers/mbox/mbox_nrf_bellboard_remote.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT nordic_nrf_bellboard_remote + +#include +#include + +#include + +struct mbox_bellboard_remote_conf { + NRF_BELLBOARD_Type *bellboard; +}; + +static int bellboard_remote_send(const struct device *dev, uint32_t id, const struct mbox_msg *msg) +{ + const struct mbox_bellboard_remote_conf *config = dev->config; + + if (id >= BELLBOARD_TASKS_TRIGGER_MaxCount) { + return -EINVAL; + } + + if (msg != NULL) { + return -ENOTSUP; + } + + nrfy_bellboard_task_trigger(config->bellboard, nrf_bellboard_trigger_task_get(id)); + + return 0; +} + +static int bellboard_remote_mtu_get(const struct device *dev) +{ + ARG_UNUSED(dev); + + return 0; +} + +static uint32_t bellboard_remote_max_channels_get(const struct device *dev) +{ + ARG_UNUSED(dev); + + return BELLBOARD_TASKS_TRIGGER_MaxCount; +} + +static const struct mbox_driver_api bellboard_remote_driver_api = { + .send = bellboard_remote_send, + .mtu_get = bellboard_remote_mtu_get, + .max_channels_get = bellboard_remote_max_channels_get, +}; + +#define BELLBOARD_REMOTE_DEFINE(inst) \ + static const struct mbox_bellboard_remote_conf conf##inst = { \ + .bellboard = (NRF_BELLBOARD_Type *)DT_INST_REG_ADDR(inst), \ + }; \ + \ + DEVICE_DT_INST_DEFINE(inst, NULL, NULL, NULL, &conf##inst, POST_KERNEL, \ + CONFIG_MBOX_INIT_PRIORITY, &bellboard_remote_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(BELLBOARD_REMOTE_DEFINE) From e669f365bc1c0b638ee5533b5051705ca9335e9b Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 22 Feb 2024 16:22:21 +0100 Subject: [PATCH 1619/1623] [nrf fromlist] samples: drivers: mbox: add support for nRF BELLBOARD Add support for testing BELLBOARD between cpuapp (local) and cpuppr (remote). Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 8787b05200fca7cef7c741122a20df2157940219) --- ...nrf54h20pdk_nrf54h20_cpuapp_bellboard.conf | 1 + ...54h20pdk_nrf54h20_cpuapp_bellboard.overlay | 9 +++++++++ ...nrf54h20pdk_nrf54h20_cpuppr_bellboard.conf | 1 + ...54h20pdk_nrf54h20_cpuppr_bellboard.overlay | 8 ++++++++ samples/drivers/mbox/sample.yaml | 20 +++++++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_bellboard.conf create mode 100644 samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_bellboard.overlay create mode 100644 samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_bellboard.conf create mode 100644 samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_bellboard.overlay diff --git a/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_bellboard.conf b/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_bellboard.conf new file mode 100644 index 00000000000..0b6bc73d6bc --- /dev/null +++ b/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_bellboard.conf @@ -0,0 +1 @@ +CONFIG_TX_ENABLED=n diff --git a/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_bellboard.overlay b/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_bellboard.overlay new file mode 100644 index 00000000000..3ea007cce55 --- /dev/null +++ b/samples/drivers/mbox/boards/nrf54h20pdk_nrf54h20_cpuapp_bellboard.overlay @@ -0,0 +1,9 @@ +/* + * Copyright 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +mbox: &cpuapp_bellboard { + nordic,interrupt-mapping = <0x00000001 0>; + status = "okay"; +}; diff --git a/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_bellboard.conf b/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_bellboard.conf new file mode 100644 index 00000000000..4596bc3a757 --- /dev/null +++ b/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_bellboard.conf @@ -0,0 +1 @@ +CONFIG_RX_ENABLED=n diff --git a/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_bellboard.overlay b/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_bellboard.overlay new file mode 100644 index 00000000000..5f0cfe2261d --- /dev/null +++ b/samples/drivers/mbox/remote/boards/nrf54h20pdk_nrf54h20_cpuppr_bellboard.overlay @@ -0,0 +1,8 @@ +/* + * Copyright 2024 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +mbox: &cpuapp_bellboard { + status = "okay"; +}; diff --git a/samples/drivers/mbox/sample.yaml b/samples/drivers/mbox/sample.yaml index 8c85a8d5150..b386b9d2b4b 100644 --- a/samples/drivers/mbox/sample.yaml +++ b/samples/drivers/mbox/sample.yaml @@ -44,6 +44,26 @@ tests: - "Ping \\(on channel 4\\)" - "Pong \\(on channel 4\\)" + sample.drivers.mbox.nrf54h20_bellboard: + platform_allow: + - nrf54h20pdk_nrf54h20_cpuapp + integration_platforms: + - nrf54h20pdk_nrf54h20_cpuapp + extra_args: + mbox_SNIPPET=nordic-ppr + mbox_EXTRA_CONF_FILE=boards/nrf54h20pdk_nrf54h20_cpuapp_bellboard.conf + mbox_DTC_OVERLAY_FILE=boards/nrf54h20pdk_nrf54h20_cpuapp_bellboard.overlay + remote_EXTRA_CONF_FILE=boards/nrf54h20pdk_nrf54h20_cpuppr_bellboard.conf + remote_DTC_OVERLAY_FILE=boards/nrf54h20pdk_nrf54h20_cpuppr_bellboard.overlay + sysbuild: true + harness: console + harness_config: + type: multi_line + ordered: false + regex: + - "Ping \\(on channel 0\\)" + - "Pong \\(on channel 0\\)" + sample.drivers.mbox.simu: platform_allow: - nrf5340bsim_nrf5340_cpuapp From be8c07b147df6e0ac4a0472b83381b5709caf600 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 26 Feb 2024 20:40:00 +0100 Subject: [PATCH 1620/1623] [nrf fromlist] boards: nrf54h20pdk_nrf54h20: add default bellboard interrupt lines Provide a default configuration for the used bellboard interrupt lines. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69303 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit d4b3648837a453b6108e20b064a0ebf301dc2d0a) --- .../arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts | 5 +++++ .../arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts index 8500d22a924..6b96858df5f 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpuapp.dts @@ -136,3 +136,8 @@ pinctrl-1 = <&uart136_sleep>; pinctrl-names = "default", "sleep"; }; + +&cpuapp_bellboard { + interrupts = <96 NRF_DEFAULT_IRQ_PRIORITY>; + interrupt-names = "irq0"; +}; diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts index a7d142b06c4..ac2d98d9e75 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20_cpurad.dts @@ -58,3 +58,8 @@ pinctrl-1 = <&uart136_sleep>; pinctrl-names = "default", "sleep"; }; + +&cpurad_bellboard { + interrupts = <96 NRF_DEFAULT_IRQ_PRIORITY>; + interrupt-names = "irq0"; +}; From b6f24afed09803c7566da055643f125fff084f09 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 26 Feb 2024 21:07:47 +0100 Subject: [PATCH 1621/1623] [nrf fromlist] boards: nrf54h20pdk_nrf54h20: add cpuapp/cpuppr shared memory Add shared memory for APP<->PPR, used for IPC. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69487 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 40655660b22ce0a7f8e7c67a1c4c31798505731a) --- .../nrf54h20pdk_nrf54h20-memory_map.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi index cb5a4fe0b0c..ac524936e4a 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi @@ -25,6 +25,14 @@ #size-cells = <1>; ranges = <0x0 0x2fc07000 0x1000>; + cpuapp_cpuppr_ipc_shm: memory@0 { + reg = <0x0 0x340>; + }; + + cpuppr_cpuapp_ipc_shm: memory@340 { + reg = <0x340 0x340>; + }; + cpuapp_dma_region: memory@680 { compatible = "zephyr,memory-region"; reg = <0x680 DT_SIZE_K(2)>; From 0fa93fad62c1cf6fb1f4c0f8fa30afcb0dbe50aa Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 26 Feb 2024 22:51:47 +0100 Subject: [PATCH 1622/1623] [nrf fromlist] boards: nrf54h20pdk: add APP<->RADIO shared memory regions Add memory regions shared between APP and RADIO cores. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/69487 Signed-off-by: Gerard Marull-Paretas (cherry picked from commit 34583f1bdd77a17a3bf63d6002134b5537d80df1) --- .../nrf54h20pdk_nrf54h20-memory_map.dtsi | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi index ac524936e4a..8caa7734e6f 100644 --- a/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi +++ b/boards/arm/nrf54h20pdk_nrf54h20/nrf54h20pdk_nrf54h20-memory_map.dtsi @@ -6,6 +6,25 @@ / { reserved-memory { + cpuapp_cpurad_ram0x_region: memory@2f0bf000 { + compatible = "nordic,owned-memory"; + reg = <0x2f0bf000 DT_SIZE_K(4)>; + status = "disabled"; + perm-read; + perm-write; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x2f0bf000 0x1000>; + + cpuapp_cpurad_ipc_shm: memory@0 { + reg = <0x0 DT_SIZE_K(2)>; + }; + + cpurad_cpuapp_ipc_shm: memory@800 { + reg = <0x800 DT_SIZE_K(2)>; + }; + }; + cpuppr_ram3x_region: memory@2fc00000 { compatible = "nordic,owned-memory"; reg = <0x2fc00000 DT_SIZE_K(28)>; From 472ef2a0de0dae0f19524e5c30abfb51721d5dd0 Mon Sep 17 00:00:00 2001 From: Kamil Gawor Date: Fri, 31 Mar 2023 14:07:10 +0200 Subject: [PATCH 1623/1623] [nrf fromtree] bindings: net: nfct: Utilize EasyDMA property This adds additional memory region property to NFCT peripheral. This is not mandatory property, it adds possibility to user to specify memory region for DMA transfer. If it is not set then data buffer is placed in default RAM with other data. Signed-off-by: Kamil Gawor Signed-off-by: Dominik Chat (cherry picked from commit edf80447c9dab288ec4ce310f74d7d8e42132fcb) --- dts/bindings/net/wireless/nordic,nrf-nfct.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dts/bindings/net/wireless/nordic,nrf-nfct.yaml b/dts/bindings/net/wireless/nordic,nrf-nfct.yaml index 5f0691300d3..6ef31ef4c2c 100644 --- a/dts/bindings/net/wireless/nordic,nrf-nfct.yaml +++ b/dts/bindings/net/wireless/nordic,nrf-nfct.yaml @@ -5,7 +5,7 @@ description: Nordic nRF family NFCT (Near Field Communication Tag) compatible: "nordic,nrf-nfct" -include: base.yaml +include: [base.yaml, memory-region.yaml] properties: reg: